aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/nfs3acl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/nfs3acl.c')
-rw-r--r--fs/nfs/nfs3acl.c295
1 files changed, 52 insertions, 243 deletions
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index 4a1aafba6a20..871d6eda8dba 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -10,179 +10,7 @@
10 10
11#define NFSDBG_FACILITY NFSDBG_PROC 11#define NFSDBG_FACILITY NFSDBG_PROC
12 12
13ssize_t nfs3_listxattr(struct dentry *dentry, char *buffer, size_t size) 13struct posix_acl *nfs3_get_acl(struct inode *inode, int type)
14{
15 struct inode *inode = dentry->d_inode;
16 struct posix_acl *acl;
17 int pos=0, len=0;
18
19# define output(s) do { \
20 if (pos + sizeof(s) <= size) { \
21 memcpy(buffer + pos, s, sizeof(s)); \
22 pos += sizeof(s); \
23 } \
24 len += sizeof(s); \
25 } while(0)
26
27 acl = nfs3_proc_getacl(inode, ACL_TYPE_ACCESS);
28 if (IS_ERR(acl))
29 return PTR_ERR(acl);
30 if (acl) {
31 output("system.posix_acl_access");
32 posix_acl_release(acl);
33 }
34
35 if (S_ISDIR(inode->i_mode)) {
36 acl = nfs3_proc_getacl(inode, ACL_TYPE_DEFAULT);
37 if (IS_ERR(acl))
38 return PTR_ERR(acl);
39 if (acl) {
40 output("system.posix_acl_default");
41 posix_acl_release(acl);
42 }
43 }
44
45# undef output
46
47 if (!buffer || len <= size)
48 return len;
49 return -ERANGE;
50}
51
52ssize_t nfs3_getxattr(struct dentry *dentry, const char *name,
53 void *buffer, size_t size)
54{
55 struct inode *inode = dentry->d_inode;
56 struct posix_acl *acl;
57 int type, error = 0;
58
59 if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
60 type = ACL_TYPE_ACCESS;
61 else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
62 type = ACL_TYPE_DEFAULT;
63 else
64 return -EOPNOTSUPP;
65
66 acl = nfs3_proc_getacl(inode, type);
67 if (IS_ERR(acl))
68 return PTR_ERR(acl);
69 else if (acl) {
70 if (type == ACL_TYPE_ACCESS && acl->a_count == 0)
71 error = -ENODATA;
72 else
73 error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
74 posix_acl_release(acl);
75 } else
76 error = -ENODATA;
77
78 return error;
79}
80
81int nfs3_setxattr(struct dentry *dentry, const char *name,
82 const void *value, size_t size, int flags)
83{
84 struct inode *inode = dentry->d_inode;
85 struct posix_acl *acl;
86 int type, error;
87
88 if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
89 type = ACL_TYPE_ACCESS;
90 else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
91 type = ACL_TYPE_DEFAULT;
92 else
93 return -EOPNOTSUPP;
94
95 acl = posix_acl_from_xattr(&init_user_ns, value, size);
96 if (IS_ERR(acl))
97 return PTR_ERR(acl);
98 error = nfs3_proc_setacl(inode, type, acl);
99 posix_acl_release(acl);
100
101 return error;
102}
103
104int nfs3_removexattr(struct dentry *dentry, const char *name)
105{
106 struct inode *inode = dentry->d_inode;
107 int type;
108
109 if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
110 type = ACL_TYPE_ACCESS;
111 else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
112 type = ACL_TYPE_DEFAULT;
113 else
114 return -EOPNOTSUPP;
115
116 return nfs3_proc_setacl(inode, type, NULL);
117}
118
119static void __nfs3_forget_cached_acls(struct nfs_inode *nfsi)
120{
121 if (!IS_ERR(nfsi->acl_access)) {
122 posix_acl_release(nfsi->acl_access);
123 nfsi->acl_access = ERR_PTR(-EAGAIN);
124 }
125 if (!IS_ERR(nfsi->acl_default)) {
126 posix_acl_release(nfsi->acl_default);
127 nfsi->acl_default = ERR_PTR(-EAGAIN);
128 }
129}
130
131void nfs3_forget_cached_acls(struct inode *inode)
132{
133 dprintk("NFS: nfs3_forget_cached_acls(%s/%ld)\n", inode->i_sb->s_id,
134 inode->i_ino);
135 spin_lock(&inode->i_lock);
136 __nfs3_forget_cached_acls(NFS_I(inode));
137 spin_unlock(&inode->i_lock);
138}
139
140static struct posix_acl *nfs3_get_cached_acl(struct inode *inode, int type)
141{
142 struct nfs_inode *nfsi = NFS_I(inode);
143 struct posix_acl *acl = ERR_PTR(-EINVAL);
144
145 spin_lock(&inode->i_lock);
146 switch(type) {
147 case ACL_TYPE_ACCESS:
148 acl = nfsi->acl_access;
149 break;
150
151 case ACL_TYPE_DEFAULT:
152 acl = nfsi->acl_default;
153 break;
154
155 default:
156 goto out;
157 }
158 if (IS_ERR(acl))
159 acl = ERR_PTR(-EAGAIN);
160 else
161 acl = posix_acl_dup(acl);
162out:
163 spin_unlock(&inode->i_lock);
164 dprintk("NFS: nfs3_get_cached_acl(%s/%ld, %d) = %p\n", inode->i_sb->s_id,
165 inode->i_ino, type, acl);
166 return acl;
167}
168
169static void nfs3_cache_acls(struct inode *inode, struct posix_acl *acl,
170 struct posix_acl *dfacl)
171{
172 struct nfs_inode *nfsi = NFS_I(inode);
173
174 dprintk("nfs3_cache_acls(%s/%ld, %p, %p)\n", inode->i_sb->s_id,
175 inode->i_ino, acl, dfacl);
176 spin_lock(&inode->i_lock);
177 __nfs3_forget_cached_acls(NFS_I(inode));
178 if (!IS_ERR(acl))
179 nfsi->acl_access = posix_acl_dup(acl);
180 if (!IS_ERR(dfacl))
181 nfsi->acl_default = posix_acl_dup(dfacl);
182 spin_unlock(&inode->i_lock);
183}
184
185struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
186{ 14{
187 struct nfs_server *server = NFS_SERVER(inode); 15 struct nfs_server *server = NFS_SERVER(inode);
188 struct page *pages[NFSACL_MAXPAGES] = { }; 16 struct page *pages[NFSACL_MAXPAGES] = { };
@@ -198,7 +26,6 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
198 .rpc_argp = &args, 26 .rpc_argp = &args,
199 .rpc_resp = &res, 27 .rpc_resp = &res,
200 }; 28 };
201 struct posix_acl *acl;
202 int status, count; 29 int status, count;
203 30
204 if (!nfs_server_capable(inode, NFS_CAP_ACLS)) 31 if (!nfs_server_capable(inode, NFS_CAP_ACLS))
@@ -207,10 +34,6 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
207 status = nfs_revalidate_inode(server, inode); 34 status = nfs_revalidate_inode(server, inode);
208 if (status < 0) 35 if (status < 0)
209 return ERR_PTR(status); 36 return ERR_PTR(status);
210 acl = nfs3_get_cached_acl(inode, type);
211 if (acl != ERR_PTR(-EAGAIN))
212 return acl;
213 acl = NULL;
214 37
215 /* 38 /*
216 * Only get the access acl when explicitly requested: We don't 39 * Only get the access acl when explicitly requested: We don't
@@ -257,40 +80,41 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
257 } 80 }
258 81
259 if (res.acl_access != NULL) { 82 if (res.acl_access != NULL) {
260 if (posix_acl_equiv_mode(res.acl_access, NULL) == 0) { 83 if ((posix_acl_equiv_mode(res.acl_access, NULL) == 0) ||
84 res.acl_access->a_count == 0) {
261 posix_acl_release(res.acl_access); 85 posix_acl_release(res.acl_access);
262 res.acl_access = NULL; 86 res.acl_access = NULL;
263 } 87 }
264 } 88 }
265 nfs3_cache_acls(inode,
266 (res.mask & NFS_ACL) ? res.acl_access : ERR_PTR(-EINVAL),
267 (res.mask & NFS_DFACL) ? res.acl_default : ERR_PTR(-EINVAL));
268 89
269 switch(type) { 90 if (res.mask & NFS_ACL)
270 case ACL_TYPE_ACCESS: 91 set_cached_acl(inode, ACL_TYPE_ACCESS, res.acl_access);
271 acl = res.acl_access; 92 else
272 res.acl_access = NULL; 93 forget_cached_acl(inode, ACL_TYPE_ACCESS);
273 break;
274 94
275 case ACL_TYPE_DEFAULT: 95 if (res.mask & NFS_DFACL)
276 acl = res.acl_default; 96 set_cached_acl(inode, ACL_TYPE_DEFAULT, res.acl_default);
277 res.acl_default = NULL; 97 else
98 forget_cached_acl(inode, ACL_TYPE_DEFAULT);
99
100 nfs_free_fattr(res.fattr);
101 if (type == ACL_TYPE_ACCESS) {
102 posix_acl_release(res.acl_default);
103 return res.acl_access;
104 } else {
105 posix_acl_release(res.acl_access);
106 return res.acl_default;
278 } 107 }
279 108
280getout: 109getout:
281 posix_acl_release(res.acl_access); 110 posix_acl_release(res.acl_access);
282 posix_acl_release(res.acl_default); 111 posix_acl_release(res.acl_default);
283 nfs_free_fattr(res.fattr); 112 nfs_free_fattr(res.fattr);
284 113 return ERR_PTR(status);
285 if (status != 0) {
286 posix_acl_release(acl);
287 acl = ERR_PTR(status);
288 }
289 return acl;
290} 114}
291 115
292static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl, 116static int __nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
293 struct posix_acl *dfacl) 117 struct posix_acl *dfacl)
294{ 118{
295 struct nfs_server *server = NFS_SERVER(inode); 119 struct nfs_server *server = NFS_SERVER(inode);
296 struct nfs_fattr *fattr; 120 struct nfs_fattr *fattr;
@@ -353,7 +177,8 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
353 switch (status) { 177 switch (status) {
354 case 0: 178 case 0:
355 status = nfs_refresh_inode(inode, fattr); 179 status = nfs_refresh_inode(inode, fattr);
356 nfs3_cache_acls(inode, acl, dfacl); 180 set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
181 set_cached_acl(inode, ACL_TYPE_DEFAULT, dfacl);
357 break; 182 break;
358 case -EPFNOSUPPORT: 183 case -EPFNOSUPPORT:
359 case -EPROTONOSUPPORT: 184 case -EPROTONOSUPPORT:
@@ -373,40 +198,43 @@ out:
373 return status; 198 return status;
374} 199}
375 200
376int nfs3_proc_setacl(struct inode *inode, int type, struct posix_acl *acl) 201int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
202 struct posix_acl *dfacl)
203{
204 int ret;
205 ret = __nfs3_proc_setacls(inode, acl, dfacl);
206 return (ret == -EOPNOTSUPP) ? 0 : ret;
207
208}
209
210int nfs3_set_acl(struct inode *inode, struct posix_acl *acl, int type)
377{ 211{
378 struct posix_acl *alloc = NULL, *dfacl = NULL; 212 struct posix_acl *alloc = NULL, *dfacl = NULL;
379 int status; 213 int status;
380 214
381 if (S_ISDIR(inode->i_mode)) { 215 if (S_ISDIR(inode->i_mode)) {
382 switch(type) { 216 switch(type) {
383 case ACL_TYPE_ACCESS: 217 case ACL_TYPE_ACCESS:
384 alloc = dfacl = nfs3_proc_getacl(inode, 218 alloc = dfacl = get_acl(inode, ACL_TYPE_DEFAULT);
385 ACL_TYPE_DEFAULT); 219 if (IS_ERR(alloc))
386 if (IS_ERR(alloc)) 220 goto fail;
387 goto fail; 221 break;
388 break;
389
390 case ACL_TYPE_DEFAULT:
391 dfacl = acl;
392 alloc = acl = nfs3_proc_getacl(inode,
393 ACL_TYPE_ACCESS);
394 if (IS_ERR(alloc))
395 goto fail;
396 break;
397 222
398 default: 223 case ACL_TYPE_DEFAULT:
399 return -EINVAL; 224 dfacl = acl;
225 alloc = acl = get_acl(inode, ACL_TYPE_ACCESS);
226 if (IS_ERR(alloc))
227 goto fail;
228 break;
400 } 229 }
401 } else if (type != ACL_TYPE_ACCESS) 230 }
402 return -EINVAL;
403 231
404 if (acl == NULL) { 232 if (acl == NULL) {
405 alloc = acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL); 233 alloc = acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
406 if (IS_ERR(alloc)) 234 if (IS_ERR(alloc))
407 goto fail; 235 goto fail;
408 } 236 }
409 status = nfs3_proc_setacls(inode, acl, dfacl); 237 status = __nfs3_proc_setacls(inode, acl, dfacl);
410 posix_acl_release(alloc); 238 posix_acl_release(alloc);
411 return status; 239 return status;
412 240
@@ -414,27 +242,8 @@ fail:
414 return PTR_ERR(alloc); 242 return PTR_ERR(alloc);
415} 243}
416 244
417int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode, 245const struct xattr_handler *nfs3_xattr_handlers[] = {
418 umode_t mode) 246 &posix_acl_access_xattr_handler,
419{ 247 &posix_acl_default_xattr_handler,
420 struct posix_acl *dfacl, *acl; 248 NULL,
421 int error = 0; 249};
422
423 dfacl = nfs3_proc_getacl(dir, ACL_TYPE_DEFAULT);
424 if (IS_ERR(dfacl)) {
425 error = PTR_ERR(dfacl);
426 return (error == -EOPNOTSUPP) ? 0 : error;
427 }
428 if (!dfacl)
429 return 0;
430 acl = posix_acl_dup(dfacl);
431 error = posix_acl_create(&acl, GFP_KERNEL, &mode);
432 if (error < 0)
433 goto out_release_dfacl;
434 error = nfs3_proc_setacls(inode, acl, S_ISDIR(inode->i_mode) ?
435 dfacl : NULL);
436 posix_acl_release(acl);
437out_release_dfacl:
438 posix_acl_release(dfacl);
439 return error;
440}