Skip to content

Commit fbd2a05

Browse files
committed
NFSv4.2: Rework scratch handling for READ_PLUS
Instead of using a tiny, static scratch buffer, we should use a kmalloc()-ed buffer that is allocated when checking for read plus usage. This lets us use the buffer before decoding any part of the READ_PLUS operation instead of setting it right before segment decoding, meaning it should be a little more robust. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent e025f0a commit fbd2a05

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

fs/nfs/nfs42xdr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,6 @@ static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
11221122
uint32_t segments;
11231123
struct read_plus_segment *segs;
11241124
int status, i;
1125-
char scratch_buf[16];
11261125
__be32 *p;
11271126

11281127
status = decode_op_hdr(xdr, OP_READ_PLUS);
@@ -1143,7 +1142,6 @@ static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
11431142
if (!segs)
11441143
return -ENOMEM;
11451144

1146-
xdr_set_scratch_buffer(xdr, &scratch_buf, sizeof(scratch_buf));
11471145
status = -EIO;
11481146
for (i = 0; i < segments; i++) {
11491147
status = decode_read_plus_segment(xdr, &segs[i]);
@@ -1348,6 +1346,8 @@ static int nfs4_xdr_dec_read_plus(struct rpc_rqst *rqstp,
13481346
struct compound_hdr hdr;
13491347
int status;
13501348

1349+
xdr_set_scratch_buffer(xdr, res->scratch, sizeof(res->scratch));
1350+
13511351
status = decode_compound_hdr(xdr, &hdr);
13521352
if (status)
13531353
goto out;

fs/nfs/nfs4proc.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5439,6 +5439,8 @@ static bool nfs4_read_plus_not_supported(struct rpc_task *task,
54395439

54405440
static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
54415441
{
5442+
if (hdr->res.scratch)
5443+
kfree(hdr->res.scratch);
54425444
if (!nfs4_sequence_done(task, &hdr->res.seq_res))
54435445
return -EAGAIN;
54445446
if (nfs4_read_stateid_changed(task, &hdr->args))
@@ -5452,17 +5454,22 @@ static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
54525454
}
54535455

54545456
#if defined CONFIG_NFS_V4_2 && defined CONFIG_NFS_V4_2_READ_PLUS
5455-
static void nfs42_read_plus_support(struct nfs_pgio_header *hdr,
5457+
static bool nfs42_read_plus_support(struct nfs_pgio_header *hdr,
54565458
struct rpc_message *msg)
54575459
{
54585460
/* Note: We don't use READ_PLUS with pNFS yet */
5459-
if (nfs_server_capable(hdr->inode, NFS_CAP_READ_PLUS) && !hdr->ds_clp)
5461+
if (nfs_server_capable(hdr->inode, NFS_CAP_READ_PLUS) && !hdr->ds_clp) {
54605462
msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS];
5463+
hdr->res.scratch = kmalloc(32, GFP_KERNEL);
5464+
return hdr->res.scratch != NULL;
5465+
}
5466+
return false;
54615467
}
54625468
#else
5463-
static void nfs42_read_plus_support(struct nfs_pgio_header *hdr,
5469+
static bool nfs42_read_plus_support(struct nfs_pgio_header *hdr,
54645470
struct rpc_message *msg)
54655471
{
5472+
return false;
54665473
}
54675474
#endif /* CONFIG_NFS_V4_2 */
54685475

@@ -5472,8 +5479,8 @@ static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr,
54725479
hdr->timestamp = jiffies;
54735480
if (!hdr->pgio_done_cb)
54745481
hdr->pgio_done_cb = nfs4_read_done_cb;
5475-
msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
5476-
nfs42_read_plus_support(hdr, msg);
5482+
if (!nfs42_read_plus_support(hdr, msg))
5483+
msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
54775484
nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0);
54785485
}
54795486

include/linux/nfs_xdr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ struct nfs_pgio_res {
670670
struct {
671671
unsigned int replen; /* used by read */
672672
int eof; /* used by read */
673+
void * scratch; /* used by read */
673674
};
674675
struct {
675676
struct nfs_writeverf * verf; /* used by write */

0 commit comments

Comments
 (0)