Skip to content

Commit 7fe2a71

Browse files
neilbrownchucklever
authored andcommitted
NFSD: introduce struct nfsd_attrs
The attributes that nfsd might want to set on a file include 'struct iattr' as well as an ACL and security label. The latter two are passed around quite separately from the first, in part because they are only needed for NFSv4. This leads to some clumsiness in the code, such as the attributes NOT being set in nfsd_create_setattr(). We need to keep the directory locked until all attributes are set to ensure the file is never visibile without all its attributes. This need combined with the inconsistent handling of attributes leads to more clumsiness. As a first step towards tidying this up, introduce 'struct nfsd_attrs'. This is passed (by reference) to vfs.c functions that work with attributes, and is assembled by the various nfs*proc functions which call them. As yet only iattr is included, but future patches will expand this. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 876c553 commit 7fe2a71

File tree

6 files changed

+71
-30
lines changed

6 files changed

+71
-30
lines changed

fs/nfsd/nfs3proc.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ nfsd3_proc_setattr(struct svc_rqst *rqstp)
6767
{
6868
struct nfsd3_sattrargs *argp = rqstp->rq_argp;
6969
struct nfsd3_attrstat *resp = rqstp->rq_resp;
70+
struct nfsd_attrs attrs = {
71+
.na_iattr = &argp->attrs,
72+
};
7073

7174
dprintk("nfsd: SETATTR(3) %s\n",
7275
SVCFH_fmt(&argp->fh));
7376

7477
fh_copy(&resp->fh, &argp->fh);
75-
resp->status = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,
78+
resp->status = nfsd_setattr(rqstp, &resp->fh, &attrs,
7679
argp->check_guard, argp->guardtime);
7780
return rpc_success;
7881
}
@@ -233,6 +236,9 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
233236
{
234237
struct iattr *iap = &argp->attrs;
235238
struct dentry *parent, *child;
239+
struct nfsd_attrs attrs = {
240+
.na_iattr = iap,
241+
};
236242
__u32 v_mtime, v_atime;
237243
struct inode *inode;
238244
__be32 status;
@@ -331,7 +337,7 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
331337
}
332338

333339
set_attr:
334-
status = nfsd_create_setattr(rqstp, fhp, resfhp, iap);
340+
status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs);
335341

336342
out:
337343
fh_unlock(fhp);
@@ -368,6 +374,9 @@ nfsd3_proc_mkdir(struct svc_rqst *rqstp)
368374
{
369375
struct nfsd3_createargs *argp = rqstp->rq_argp;
370376
struct nfsd3_diropres *resp = rqstp->rq_resp;
377+
struct nfsd_attrs attrs = {
378+
.na_iattr = &argp->attrs,
379+
};
371380

372381
dprintk("nfsd: MKDIR(3) %s %.*s\n",
373382
SVCFH_fmt(&argp->fh),
@@ -378,7 +387,7 @@ nfsd3_proc_mkdir(struct svc_rqst *rqstp)
378387
fh_copy(&resp->dirfh, &argp->fh);
379388
fh_init(&resp->fh, NFS3_FHSIZE);
380389
resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
381-
&argp->attrs, S_IFDIR, 0, &resp->fh);
390+
&attrs, S_IFDIR, 0, &resp->fh);
382391
fh_unlock(&resp->dirfh);
383392
return rpc_success;
384393
}
@@ -428,6 +437,9 @@ nfsd3_proc_mknod(struct svc_rqst *rqstp)
428437
{
429438
struct nfsd3_mknodargs *argp = rqstp->rq_argp;
430439
struct nfsd3_diropres *resp = rqstp->rq_resp;
440+
struct nfsd_attrs attrs = {
441+
.na_iattr = &argp->attrs,
442+
};
431443
int type;
432444
dev_t rdev = 0;
433445

@@ -453,7 +465,7 @@ nfsd3_proc_mknod(struct svc_rqst *rqstp)
453465

454466
type = nfs3_ftypes[argp->ftype];
455467
resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
456-
&argp->attrs, type, rdev, &resp->fh);
468+
&attrs, type, rdev, &resp->fh);
457469
fh_unlock(&resp->dirfh);
458470
out:
459471
return rpc_success;

fs/nfsd/nfs4proc.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
286286
struct svc_fh *resfhp, struct nfsd4_open *open)
287287
{
288288
struct iattr *iap = &open->op_iattr;
289+
struct nfsd_attrs attrs = {
290+
.na_iattr = iap,
291+
};
289292
struct dentry *parent, *child;
290293
__u32 v_mtime, v_atime;
291294
struct inode *inode;
@@ -404,7 +407,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
404407
}
405408

406409
set_attr:
407-
status = nfsd_create_setattr(rqstp, fhp, resfhp, iap);
410+
status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs);
408411

409412
out:
410413
fh_unlock(fhp);
@@ -787,6 +790,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
787790
union nfsd4_op_u *u)
788791
{
789792
struct nfsd4_create *create = &u->create;
793+
struct nfsd_attrs attrs = {
794+
.na_iattr = &create->cr_iattr,
795+
};
790796
struct svc_fh resfh;
791797
__be32 status;
792798
dev_t rdev;
@@ -818,7 +824,7 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
818824
goto out_umask;
819825
status = nfsd_create(rqstp, &cstate->current_fh,
820826
create->cr_name, create->cr_namelen,
821-
&create->cr_iattr, S_IFBLK, rdev, &resfh);
827+
&attrs, S_IFBLK, rdev, &resfh);
822828
break;
823829

824830
case NF4CHR:
@@ -829,26 +835,26 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
829835
goto out_umask;
830836
status = nfsd_create(rqstp, &cstate->current_fh,
831837
create->cr_name, create->cr_namelen,
832-
&create->cr_iattr, S_IFCHR, rdev, &resfh);
838+
&attrs, S_IFCHR, rdev, &resfh);
833839
break;
834840

835841
case NF4SOCK:
836842
status = nfsd_create(rqstp, &cstate->current_fh,
837843
create->cr_name, create->cr_namelen,
838-
&create->cr_iattr, S_IFSOCK, 0, &resfh);
844+
&attrs, S_IFSOCK, 0, &resfh);
839845
break;
840846

841847
case NF4FIFO:
842848
status = nfsd_create(rqstp, &cstate->current_fh,
843849
create->cr_name, create->cr_namelen,
844-
&create->cr_iattr, S_IFIFO, 0, &resfh);
850+
&attrs, S_IFIFO, 0, &resfh);
845851
break;
846852

847853
case NF4DIR:
848854
create->cr_iattr.ia_valid &= ~ATTR_SIZE;
849855
status = nfsd_create(rqstp, &cstate->current_fh,
850856
create->cr_name, create->cr_namelen,
851-
&create->cr_iattr, S_IFDIR, 0, &resfh);
857+
&attrs, S_IFDIR, 0, &resfh);
852858
break;
853859

854860
default:
@@ -1142,6 +1148,9 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
11421148
union nfsd4_op_u *u)
11431149
{
11441150
struct nfsd4_setattr *setattr = &u->setattr;
1151+
struct nfsd_attrs attrs = {
1152+
.na_iattr = &setattr->sa_iattr,
1153+
};
11451154
__be32 status = nfs_ok;
11461155
int err;
11471156

@@ -1174,7 +1183,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
11741183
&setattr->sa_label);
11751184
if (status)
11761185
goto out;
1177-
status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
1186+
status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
11781187
0, (time64_t)0);
11791188
out:
11801189
fh_drop_write(&cstate->current_fh);

fs/nfsd/nfs4state.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5060,11 +5060,14 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,
50605060
.ia_valid = ATTR_SIZE,
50615061
.ia_size = 0,
50625062
};
5063+
struct nfsd_attrs attrs = {
5064+
.na_iattr = &iattr,
5065+
};
50635066
if (!open->op_truncate)
50645067
return 0;
50655068
if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
50665069
return nfserr_inval;
5067-
return nfsd_setattr(rqstp, fh, &iattr, 0, (time64_t)0);
5070+
return nfsd_setattr(rqstp, fh, &attrs, 0, (time64_t)0);
50685071
}
50695072

50705073
static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,

fs/nfsd/nfsproc.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ nfsd_proc_setattr(struct svc_rqst *rqstp)
5151
struct nfsd_sattrargs *argp = rqstp->rq_argp;
5252
struct nfsd_attrstat *resp = rqstp->rq_resp;
5353
struct iattr *iap = &argp->attrs;
54+
struct nfsd_attrs attrs = {
55+
.na_iattr = iap,
56+
};
5457
struct svc_fh *fhp;
5558

5659
dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
@@ -100,7 +103,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp)
100103
}
101104
}
102105

103-
resp->status = nfsd_setattr(rqstp, fhp, iap, 0, (time64_t)0);
106+
resp->status = nfsd_setattr(rqstp, fhp, &attrs, 0, (time64_t)0);
104107
if (resp->status != nfs_ok)
105108
goto out;
106109

@@ -260,6 +263,9 @@ nfsd_proc_create(struct svc_rqst *rqstp)
260263
svc_fh *dirfhp = &argp->fh;
261264
svc_fh *newfhp = &resp->fh;
262265
struct iattr *attr = &argp->attrs;
266+
struct nfsd_attrs attrs = {
267+
.na_iattr = attr,
268+
};
263269
struct inode *inode;
264270
struct dentry *dchild;
265271
int type, mode;
@@ -385,7 +391,7 @@ nfsd_proc_create(struct svc_rqst *rqstp)
385391
if (!inode) {
386392
/* File doesn't exist. Create it and set attrs */
387393
resp->status = nfsd_create_locked(rqstp, dirfhp, argp->name,
388-
argp->len, attr, type, rdev,
394+
argp->len, &attrs, type, rdev,
389395
newfhp);
390396
} else if (type == S_IFREG) {
391397
dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
@@ -396,7 +402,7 @@ nfsd_proc_create(struct svc_rqst *rqstp)
396402
*/
397403
attr->ia_valid &= ATTR_SIZE;
398404
if (attr->ia_valid)
399-
resp->status = nfsd_setattr(rqstp, newfhp, attr, 0,
405+
resp->status = nfsd_setattr(rqstp, newfhp, &attrs, 0,
400406
(time64_t)0);
401407
}
402408

@@ -511,6 +517,9 @@ nfsd_proc_mkdir(struct svc_rqst *rqstp)
511517
{
512518
struct nfsd_createargs *argp = rqstp->rq_argp;
513519
struct nfsd_diropres *resp = rqstp->rq_resp;
520+
struct nfsd_attrs attrs = {
521+
.na_iattr = &argp->attrs,
522+
};
514523

515524
dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
516525

@@ -522,7 +531,7 @@ nfsd_proc_mkdir(struct svc_rqst *rqstp)
522531
argp->attrs.ia_valid &= ~ATTR_SIZE;
523532
fh_init(&resp->fh, NFS_FHSIZE);
524533
resp->status = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
525-
&argp->attrs, S_IFDIR, 0, &resp->fh);
534+
&attrs, S_IFDIR, 0, &resp->fh);
526535
fh_put(&argp->fh);
527536
if (resp->status != nfs_ok)
528537
goto out;

fs/nfsd/vfs.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,13 @@ nfsd_get_write_access(struct svc_rqst *rqstp, struct svc_fh *fhp,
349349
* Set various file attributes. After this call fhp needs an fh_put.
350350
*/
351351
__be32
352-
nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
352+
nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
353+
struct nfsd_attrs *attr,
353354
int check_guard, time64_t guardtime)
354355
{
355356
struct dentry *dentry;
356357
struct inode *inode;
358+
struct iattr *iap = attr->na_iattr;
357359
int accmode = NFSD_MAY_SATTR;
358360
umode_t ftype = 0;
359361
__be32 err;
@@ -1202,14 +1204,15 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, u64 offset,
12021204
* @rqstp: RPC transaction being executed
12031205
* @fhp: NFS filehandle of parent directory
12041206
* @resfhp: NFS filehandle of new object
1205-
* @iap: requested attributes of new object
1207+
* @attrs: requested attributes of new object
12061208
*
12071209
* Returns nfs_ok on success, or an nfsstat in network byte order.
12081210
*/
12091211
__be32
12101212
nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
1211-
struct svc_fh *resfhp, struct iattr *iap)
1213+
struct svc_fh *resfhp, struct nfsd_attrs *attrs)
12121214
{
1215+
struct iattr *iap = attrs->na_iattr;
12131216
__be32 status;
12141217

12151218
/*
@@ -1230,7 +1233,7 @@ nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
12301233
* if the attributes have not changed.
12311234
*/
12321235
if (iap->ia_valid)
1233-
status = nfsd_setattr(rqstp, resfhp, iap, 0, (time64_t)0);
1236+
status = nfsd_setattr(rqstp, resfhp, attrs, 0, (time64_t)0);
12341237
else
12351238
status = nfserrno(commit_metadata(resfhp));
12361239

@@ -1269,11 +1272,12 @@ nfsd_check_ignore_resizing(struct iattr *iap)
12691272
/* The parent directory should already be locked: */
12701273
__be32
12711274
nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,
1272-
char *fname, int flen, struct iattr *iap,
1273-
int type, dev_t rdev, struct svc_fh *resfhp)
1275+
char *fname, int flen, struct nfsd_attrs *attrs,
1276+
int type, dev_t rdev, struct svc_fh *resfhp)
12741277
{
12751278
struct dentry *dentry, *dchild;
12761279
struct inode *dirp;
1280+
struct iattr *iap = attrs->na_iattr;
12771281
__be32 err;
12781282
int host_err;
12791283

@@ -1347,7 +1351,7 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,
13471351
if (host_err < 0)
13481352
goto out_nfserr;
13491353

1350-
err = nfsd_create_setattr(rqstp, fhp, resfhp, iap);
1354+
err = nfsd_create_setattr(rqstp, fhp, resfhp, attrs);
13511355

13521356
out:
13531357
dput(dchild);
@@ -1366,8 +1370,8 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,
13661370
*/
13671371
__be32
13681372
nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1369-
char *fname, int flen, struct iattr *iap,
1370-
int type, dev_t rdev, struct svc_fh *resfhp)
1373+
char *fname, int flen, struct nfsd_attrs *attrs,
1374+
int type, dev_t rdev, struct svc_fh *resfhp)
13711375
{
13721376
struct dentry *dentry, *dchild = NULL;
13731377
__be32 err;
@@ -1399,7 +1403,7 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
13991403
dput(dchild);
14001404
if (err)
14011405
return err;
1402-
return nfsd_create_locked(rqstp, fhp, fname, flen, iap, type,
1406+
return nfsd_create_locked(rqstp, fhp, fname, flen, attrs, type,
14031407
rdev, resfhp);
14041408
}
14051409

fs/nfsd/vfs.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ struct nfsd_file;
4242
typedef int (*nfsd_filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
4343

4444
/* nfsd/vfs.c */
45+
struct nfsd_attrs {
46+
struct iattr *na_iattr; /* input */
47+
};
48+
4549
int nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
4650
struct svc_export **expp);
4751
__be32 nfsd_lookup(struct svc_rqst *, struct svc_fh *,
@@ -50,7 +54,7 @@ __be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *,
5054
const char *, unsigned int,
5155
struct svc_export **, struct dentry **);
5256
__be32 nfsd_setattr(struct svc_rqst *, struct svc_fh *,
53-
struct iattr *, int, time64_t);
57+
struct nfsd_attrs *, int, time64_t);
5458
int nfsd_mountpoint(struct dentry *, struct svc_export *);
5559
#ifdef CONFIG_NFSD_V4
5660
__be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *,
@@ -63,14 +67,14 @@ __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp,
6367
u64 count, bool sync);
6468
#endif /* CONFIG_NFSD_V4 */
6569
__be32 nfsd_create_locked(struct svc_rqst *, struct svc_fh *,
66-
char *name, int len, struct iattr *attrs,
70+
char *name, int len, struct nfsd_attrs *attrs,
6771
int type, dev_t rdev, struct svc_fh *res);
6872
__be32 nfsd_create(struct svc_rqst *, struct svc_fh *,
69-
char *name, int len, struct iattr *attrs,
73+
char *name, int len, struct nfsd_attrs *attrs,
7074
int type, dev_t rdev, struct svc_fh *res);
7175
__be32 nfsd_access(struct svc_rqst *, struct svc_fh *, u32 *, u32 *);
7276
__be32 nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
73-
struct svc_fh *resfhp, struct iattr *iap);
77+
struct svc_fh *resfhp, struct nfsd_attrs *iap);
7478
__be32 nfsd_commit(struct svc_rqst *rqst, struct svc_fh *fhp,
7579
u64 offset, u32 count, __be32 *verf);
7680
#ifdef CONFIG_NFSD_V4

0 commit comments

Comments
 (0)