Skip to content

Commit f2e5973

Browse files
committed
NFSD: De-duplicate the svc_fill_write_vector() call sites
All three call sites do the same thing. I'm struggling with this a bit, however. struct xdr_buf is an XDR layer object and unmarshaling a WRITE payload is clearly a task intended to be done by the proc and xdr functions, not by VFS. This feels vaguely like a layering violation. Signed-off-by: Chuck Lever <[email protected]>
1 parent 2a48f3a commit f2e5973

File tree

7 files changed

+54
-36
lines changed

7 files changed

+54
-36
lines changed

fs/nfsd/nfs3proc.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ nfsd3_proc_write(struct svc_rqst *rqstp)
220220
struct nfsd3_writeargs *argp = rqstp->rq_argp;
221221
struct nfsd3_writeres *resp = rqstp->rq_resp;
222222
unsigned long cnt = argp->len;
223-
unsigned int nvecs;
224223

225224
dprintk("nfsd: WRITE(3) %s %d bytes at %Lu%s\n",
226225
SVCFH_fmt(&argp->fh),
@@ -235,10 +234,8 @@ nfsd3_proc_write(struct svc_rqst *rqstp)
235234

236235
fh_copy(&resp->fh, &argp->fh);
237236
resp->committed = argp->stable;
238-
nvecs = svc_fill_write_vector(rqstp, &argp->payload);
239-
240237
resp->status = nfsd_write(rqstp, &resp->fh, argp->offset,
241-
rqstp->rq_vec, nvecs, &cnt,
238+
&argp->payload, &cnt,
242239
resp->committed, resp->verf);
243240
resp->count = cnt;
244241
resp->status = nfsd3_map_status(resp->status);

fs/nfsd/nfs4proc.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,6 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
12161216
struct nfsd_file *nf = NULL;
12171217
__be32 status = nfs_ok;
12181218
unsigned long cnt;
1219-
int nvecs;
12201219

12211220
if (write->wr_offset > (u64)OFFSET_MAX ||
12221221
write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX)
@@ -1231,12 +1230,9 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
12311230
return status;
12321231

12331232
write->wr_how_written = write->wr_stable_how;
1234-
1235-
nvecs = svc_fill_write_vector(rqstp, &write->wr_payload);
1236-
12371233
status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf,
1238-
write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
1239-
write->wr_how_written,
1234+
write->wr_offset, &write->wr_payload,
1235+
&cnt, write->wr_how_written,
12401236
(__be32 *)write->wr_verifier.data);
12411237
nfsd_file_put(nf);
12421238

fs/nfsd/nfsproc.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,14 @@ nfsd_proc_write(struct svc_rqst *rqstp)
251251
struct nfsd_writeargs *argp = rqstp->rq_argp;
252252
struct nfsd_attrstat *resp = rqstp->rq_resp;
253253
unsigned long cnt = argp->len;
254-
unsigned int nvecs;
255254

256255
dprintk("nfsd: WRITE %s %u bytes at %d\n",
257256
SVCFH_fmt(&argp->fh),
258257
argp->len, argp->offset);
259258

260-
nvecs = svc_fill_write_vector(rqstp, &argp->payload);
261-
262-
resp->status = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh),
263-
argp->offset, rqstp->rq_vec, nvecs,
264-
&cnt, NFS_DATA_SYNC, NULL);
259+
fh_copy(&resp->fh, &argp->fh);
260+
resp->status = nfsd_write(rqstp, &resp->fh, argp->offset,
261+
&argp->payload, &cnt, NFS_DATA_SYNC, NULL);
265262
if (resp->status == nfs_ok)
266263
resp->status = fh_getattr(&resp->fh, &resp->stat);
267264
else if (resp->status == nfserr_jukebox)

fs/nfsd/vfs.c

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,11 +1143,27 @@ static int wait_for_concurrent_writes(struct file *file)
11431143
return err;
11441144
}
11451145

1146+
/**
1147+
* nfsd_vfs_write - write data to an already-open file
1148+
* @rqstp: RPC execution context
1149+
* @fhp: File handle of file to write into
1150+
* @nf: An open file matching @fhp
1151+
* @offset: Byte offset of start
1152+
* @payload: xdr_buf containing the write payload
1153+
* @cnt: IN: number of bytes to write, OUT: number of bytes actually written
1154+
* @stable: An NFS stable_how value
1155+
* @verf: NFS WRITE verifier
1156+
*
1157+
* Upon return, caller must invoke fh_put on @fhp.
1158+
*
1159+
* Return values:
1160+
* An nfsstat value in network byte order.
1161+
*/
11461162
__be32
1147-
nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,
1148-
loff_t offset, struct kvec *vec, int vlen,
1149-
unsigned long *cnt, int stable,
1150-
__be32 *verf)
1163+
nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
1164+
struct nfsd_file *nf, loff_t offset,
1165+
const struct xdr_buf *payload, unsigned long *cnt,
1166+
int stable, __be32 *verf)
11511167
{
11521168
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
11531169
struct file *file = nf->nf_file;
@@ -1162,6 +1178,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,
11621178
unsigned int pflags = current->flags;
11631179
rwf_t flags = 0;
11641180
bool restore_flags = false;
1181+
unsigned int nvecs;
11651182

11661183
trace_nfsd_write_opened(rqstp, fhp, offset, *cnt);
11671184

@@ -1189,7 +1206,8 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,
11891206
if (stable && !fhp->fh_use_wgather)
11901207
flags |= RWF_SYNC;
11911208

1192-
iov_iter_kvec(&iter, ITER_SOURCE, vec, vlen, *cnt);
1209+
nvecs = svc_fill_write_vector(rqstp, payload);
1210+
iov_iter_kvec(&iter, ITER_SOURCE, rqstp->rq_vec, nvecs, *cnt);
11931211
since = READ_ONCE(file->f_wb_err);
11941212
if (verf)
11951213
nfsd_copy_write_verifier(verf, nn);
@@ -1289,14 +1307,24 @@ __be32 nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
12891307
return err;
12901308
}
12911309

1292-
/*
1293-
* Write data to a file.
1294-
* The stable flag requests synchronous writes.
1295-
* N.B. After this call fhp needs an fh_put
1310+
/**
1311+
* nfsd_write - open a file and write data to it
1312+
* @rqstp: RPC execution context
1313+
* @fhp: File handle of file to write into; nfsd_write() may modify it
1314+
* @offset: Byte offset of start
1315+
* @payload: xdr_buf containing the write payload
1316+
* @cnt: IN: number of bytes to write, OUT: number of bytes actually written
1317+
* @stable: An NFS stable_how value
1318+
* @verf: NFS WRITE verifier
1319+
*
1320+
* Upon return, caller must invoke fh_put on @fhp.
1321+
*
1322+
* Return values:
1323+
* An nfsstat value in network byte order.
12961324
*/
12971325
__be32
12981326
nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
1299-
struct kvec *vec, int vlen, unsigned long *cnt, int stable,
1327+
const struct xdr_buf *payload, unsigned long *cnt, int stable,
13001328
__be32 *verf)
13011329
{
13021330
struct nfsd_file *nf;
@@ -1308,8 +1336,8 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
13081336
if (err)
13091337
goto out;
13101338

1311-
err = nfsd_vfs_write(rqstp, fhp, nf, offset, vec,
1312-
vlen, cnt, stable, verf);
1339+
err = nfsd_vfs_write(rqstp, fhp, nf, offset, payload, cnt,
1340+
stable, verf);
13131341
nfsd_file_put(nf);
13141342
out:
13151343
trace_nfsd_write_done(rqstp, fhp, offset, *cnt);

fs/nfsd/vfs.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ bool nfsd_read_splice_ok(struct svc_rqst *rqstp);
128128
__be32 nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
129129
loff_t offset, unsigned long *count,
130130
u32 *eof);
131-
__be32 nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t,
132-
struct kvec *, int, unsigned long *,
133-
int stable, __be32 *verf);
131+
__be32 nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
132+
loff_t offset, const struct xdr_buf *payload,
133+
unsigned long *cnt, int stable, __be32 *verf);
134134
__be32 nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
135135
struct nfsd_file *nf, loff_t offset,
136-
struct kvec *vec, int vlen, unsigned long *cnt,
137-
int stable, __be32 *verf);
136+
const struct xdr_buf *payload,
137+
unsigned long *cnt, int stable, __be32 *verf);
138138
__be32 nfsd_readlink(struct svc_rqst *, struct svc_fh *,
139139
char *, int *);
140140
__be32 nfsd_symlink(struct svc_rqst *, struct svc_fh *,

include/linux/sunrpc/svc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ int svc_encode_result_payload(struct svc_rqst *rqstp,
471471
unsigned int offset,
472472
unsigned int length);
473473
unsigned int svc_fill_write_vector(struct svc_rqst *rqstp,
474-
struct xdr_buf *payload);
474+
const struct xdr_buf *payload);
475475
char *svc_fill_symlink_pathname(struct svc_rqst *rqstp,
476476
struct kvec *first, void *p,
477477
size_t total);

net/sunrpc/svc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,10 +1727,10 @@ EXPORT_SYMBOL_GPL(svc_encode_result_payload);
17271727
* Fills in rqstp::rq_vec, and returns the number of elements.
17281728
*/
17291729
unsigned int svc_fill_write_vector(struct svc_rqst *rqstp,
1730-
struct xdr_buf *payload)
1730+
const struct xdr_buf *payload)
17311731
{
1732+
const struct kvec *first = payload->head;
17321733
struct page **pages = payload->pages;
1733-
struct kvec *first = payload->head;
17341734
struct kvec *vec = rqstp->rq_vec;
17351735
size_t total = payload->len;
17361736
unsigned int i;

0 commit comments

Comments
 (0)