Skip to content

Commit 4ac7249

Browse files
Christoph HellwigAl Viro
authored andcommitted
nfsd: use get_acl and ->set_acl
Remove the boilerplate code to marshall and unmarhall ACL objects into xattrs and operate on the posix_acl objects directly. Also move all the ACL handling code into nfs?acl.c where it belongs. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent feda821 commit 4ac7249

File tree

7 files changed

+173
-347
lines changed

7 files changed

+173
-347
lines changed

fs/nfsd/acl.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
#ifndef LINUX_NFS4_ACL_H
3636
#define LINUX_NFS4_ACL_H
3737

38-
#include <linux/posix_acl.h>
38+
struct nfs4_acl;
39+
struct svc_fh;
40+
struct svc_rqst;
3941

4042
/* Maximum ACL we'll accept from client; chosen (somewhat arbitrarily) to
4143
* fit in a page: */
@@ -45,13 +47,9 @@ struct nfs4_acl *nfs4_acl_new(int);
4547
int nfs4_acl_get_whotype(char *, u32);
4648
int nfs4_acl_write_who(int who, char *p);
4749

48-
#define NFS4_ACL_TYPE_DEFAULT 0x01
49-
#define NFS4_ACL_DIR 0x02
50-
#define NFS4_ACL_OWNER 0x04
51-
52-
struct nfs4_acl *nfs4_acl_posix_to_nfsv4(struct posix_acl *,
53-
struct posix_acl *, unsigned int flags);
54-
int nfs4_acl_nfsv4_to_posix(struct nfs4_acl *, struct posix_acl **,
55-
struct posix_acl **, unsigned int flags);
50+
int nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry,
51+
struct nfs4_acl **acl);
52+
__be32 nfsd4_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
53+
struct nfs4_acl *acl);
5654

5755
#endif /* LINUX_NFS4_ACL_H */

fs/nfsd/nfs2acl.c

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ nfsacld_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
3030
static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
3131
struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
3232
{
33-
svc_fh *fh;
3433
struct posix_acl *acl;
34+
struct inode *inode;
35+
svc_fh *fh;
3536
__be32 nfserr = 0;
3637

3738
dprintk("nfsd: GETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
@@ -41,6 +42,8 @@ static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
4142
if (nfserr)
4243
RETURN_STATUS(nfserr);
4344

45+
inode = fh->fh_dentry->d_inode;
46+
4447
if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
4548
RETURN_STATUS(nfserr_inval);
4649
resp->mask = argp->mask;
@@ -50,39 +53,24 @@ static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
5053
goto fail;
5154

5255
if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
53-
acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
56+
acl = get_acl(inode, ACL_TYPE_ACCESS);
5457
if (IS_ERR(acl)) {
55-
int err = PTR_ERR(acl);
56-
57-
if (err == -ENODATA || err == -EOPNOTSUPP)
58-
acl = NULL;
59-
else {
60-
nfserr = nfserrno(err);
61-
goto fail;
62-
}
58+
nfserr = nfserrno(PTR_ERR(acl));
59+
goto fail;
6360
}
6461
if (acl == NULL) {
6562
/* Solaris returns the inode's minimum ACL. */
66-
67-
struct inode *inode = fh->fh_dentry->d_inode;
6863
acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
6964
}
7065
resp->acl_access = acl;
7166
}
7267
if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
7368
/* Check how Solaris handles requests for the Default ACL
7469
of a non-directory! */
75-
76-
acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
70+
acl = get_acl(inode, ACL_TYPE_DEFAULT);
7771
if (IS_ERR(acl)) {
78-
int err = PTR_ERR(acl);
79-
80-
if (err == -ENODATA || err == -EOPNOTSUPP)
81-
acl = NULL;
82-
else {
83-
nfserr = nfserrno(err);
84-
goto fail;
85-
}
72+
nfserr = nfserrno(PTR_ERR(acl));
73+
goto fail;
8674
}
8775
resp->acl_default = acl;
8876
}
@@ -103,31 +91,51 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst * rqstp,
10391
struct nfsd3_setaclargs *argp,
10492
struct nfsd_attrstat *resp)
10593
{
94+
struct inode *inode;
10695
svc_fh *fh;
10796
__be32 nfserr = 0;
97+
int error;
10898

10999
dprintk("nfsd: SETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
110100

111101
fh = fh_copy(&resp->fh, &argp->fh);
112102
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
103+
if (nfserr)
104+
goto out;
113105

114-
if (!nfserr) {
115-
nfserr = nfserrno( nfsd_set_posix_acl(
116-
fh, ACL_TYPE_ACCESS, argp->acl_access) );
117-
}
118-
if (!nfserr) {
119-
nfserr = nfserrno( nfsd_set_posix_acl(
120-
fh, ACL_TYPE_DEFAULT, argp->acl_default) );
121-
}
122-
if (!nfserr) {
123-
nfserr = fh_getattr(fh, &resp->stat);
106+
inode = fh->fh_dentry->d_inode;
107+
if (!IS_POSIXACL(inode) || !inode->i_op->set_acl) {
108+
error = -EOPNOTSUPP;
109+
goto out_errno;
124110
}
125111

112+
error = fh_want_write(fh);
113+
if (error)
114+
goto out_errno;
115+
116+
error = inode->i_op->set_acl(inode, argp->acl_access, ACL_TYPE_ACCESS);
117+
if (error)
118+
goto out_drop_write;
119+
error = inode->i_op->set_acl(inode, argp->acl_default,
120+
ACL_TYPE_DEFAULT);
121+
if (error)
122+
goto out_drop_write;
123+
124+
fh_drop_write(fh);
125+
126+
nfserr = fh_getattr(fh, &resp->stat);
127+
128+
out:
126129
/* argp->acl_{access,default} may have been allocated in
127130
nfssvc_decode_setaclargs. */
128131
posix_acl_release(argp->acl_access);
129132
posix_acl_release(argp->acl_default);
130133
return nfserr;
134+
out_drop_write:
135+
fh_drop_write(fh);
136+
out_errno:
137+
nfserr = nfserrno(error);
138+
goto out;
131139
}
132140

133141
/*

fs/nfsd/nfs3acl.c

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,53 +29,41 @@ nfsd3_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
2929
static __be32 nfsd3_proc_getacl(struct svc_rqst * rqstp,
3030
struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
3131
{
32-
svc_fh *fh;
3332
struct posix_acl *acl;
33+
struct inode *inode;
34+
svc_fh *fh;
3435
__be32 nfserr = 0;
3536

3637
fh = fh_copy(&resp->fh, &argp->fh);
3738
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
3839
if (nfserr)
3940
RETURN_STATUS(nfserr);
4041

42+
inode = fh->fh_dentry->d_inode;
43+
4144
if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
4245
RETURN_STATUS(nfserr_inval);
4346
resp->mask = argp->mask;
4447

4548
if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
46-
acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
49+
acl = get_acl(inode, ACL_TYPE_ACCESS);
4750
if (IS_ERR(acl)) {
48-
int err = PTR_ERR(acl);
49-
50-
if (err == -ENODATA || err == -EOPNOTSUPP)
51-
acl = NULL;
52-
else {
53-
nfserr = nfserrno(err);
54-
goto fail;
55-
}
51+
nfserr = nfserrno(PTR_ERR(acl));
52+
goto fail;
5653
}
5754
if (acl == NULL) {
5855
/* Solaris returns the inode's minimum ACL. */
59-
60-
struct inode *inode = fh->fh_dentry->d_inode;
6156
acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
6257
}
6358
resp->acl_access = acl;
6459
}
6560
if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
6661
/* Check how Solaris handles requests for the Default ACL
6762
of a non-directory! */
68-
69-
acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
63+
acl = get_acl(inode, ACL_TYPE_DEFAULT);
7064
if (IS_ERR(acl)) {
71-
int err = PTR_ERR(acl);
72-
73-
if (err == -ENODATA || err == -EOPNOTSUPP)
74-
acl = NULL;
75-
else {
76-
nfserr = nfserrno(err);
77-
goto fail;
78-
}
65+
nfserr = nfserrno(PTR_ERR(acl));
66+
goto fail;
7967
}
8068
resp->acl_default = acl;
8169
}
@@ -96,21 +84,37 @@ static __be32 nfsd3_proc_setacl(struct svc_rqst * rqstp,
9684
struct nfsd3_setaclargs *argp,
9785
struct nfsd3_attrstat *resp)
9886
{
87+
struct inode *inode;
9988
svc_fh *fh;
10089
__be32 nfserr = 0;
90+
int error;
10191

10292
fh = fh_copy(&resp->fh, &argp->fh);
10393
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
94+
if (nfserr)
95+
goto out;
10496

105-
if (!nfserr) {
106-
nfserr = nfserrno( nfsd_set_posix_acl(
107-
fh, ACL_TYPE_ACCESS, argp->acl_access) );
108-
}
109-
if (!nfserr) {
110-
nfserr = nfserrno( nfsd_set_posix_acl(
111-
fh, ACL_TYPE_DEFAULT, argp->acl_default) );
97+
inode = fh->fh_dentry->d_inode;
98+
if (!IS_POSIXACL(inode) || !inode->i_op->set_acl) {
99+
error = -EOPNOTSUPP;
100+
goto out_errno;
112101
}
113102

103+
error = fh_want_write(fh);
104+
if (error)
105+
goto out_errno;
106+
107+
error = inode->i_op->set_acl(inode, argp->acl_access, ACL_TYPE_ACCESS);
108+
if (error)
109+
goto out_drop_write;
110+
error = inode->i_op->set_acl(inode, argp->acl_default,
111+
ACL_TYPE_DEFAULT);
112+
113+
out_drop_write:
114+
fh_drop_write(fh);
115+
out_errno:
116+
nfserr = nfserrno(error);
117+
out:
114118
/* argp->acl_{access,default} may have been allocated in
115119
nfs3svc_decode_setaclargs. */
116120
posix_acl_release(argp->acl_access);

0 commit comments

Comments
 (0)