Commit 4814f56d19137b3b9fa8e00e1d332b3683b950de
Committed by
Trond Myklebust
1 parent
1842bfb447
Exists in
master
and in
7 other branches
NFSv3: Client-side nfsacl caching fix
Fix two errors in the client-side acl cache: First, when nfs3_proc_getacl requests only the default acl of a file and the access acl is not cached already, a NULL access acl entry is cached instead of ERR_PTR(-EAGAIN) ("not cached"). Second, update the cached acls in nfs3_proc_setacls: nfs_refresh_inode does not always invalidate the cached acls, and when it does not, the cached acls get out of sync. Signed-off-by: Andreas Gruenbacher <agruen@suse.de> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Showing 1 changed file with 8 additions and 3 deletions Inline Diff
fs/nfs/nfs3acl.c
1 | #include <linux/fs.h> | 1 | #include <linux/fs.h> |
2 | #include <linux/nfs.h> | 2 | #include <linux/nfs.h> |
3 | #include <linux/nfs3.h> | 3 | #include <linux/nfs3.h> |
4 | #include <linux/nfs_fs.h> | 4 | #include <linux/nfs_fs.h> |
5 | #include <linux/posix_acl_xattr.h> | 5 | #include <linux/posix_acl_xattr.h> |
6 | #include <linux/nfsacl.h> | 6 | #include <linux/nfsacl.h> |
7 | 7 | ||
8 | #define NFSDBG_FACILITY NFSDBG_PROC | 8 | #define NFSDBG_FACILITY NFSDBG_PROC |
9 | 9 | ||
10 | ssize_t nfs3_listxattr(struct dentry *dentry, char *buffer, size_t size) | 10 | ssize_t nfs3_listxattr(struct dentry *dentry, char *buffer, size_t size) |
11 | { | 11 | { |
12 | struct inode *inode = dentry->d_inode; | 12 | struct inode *inode = dentry->d_inode; |
13 | struct posix_acl *acl; | 13 | struct posix_acl *acl; |
14 | int pos=0, len=0; | 14 | int pos=0, len=0; |
15 | 15 | ||
16 | # define output(s) do { \ | 16 | # define output(s) do { \ |
17 | if (pos + sizeof(s) <= size) { \ | 17 | if (pos + sizeof(s) <= size) { \ |
18 | memcpy(buffer + pos, s, sizeof(s)); \ | 18 | memcpy(buffer + pos, s, sizeof(s)); \ |
19 | pos += sizeof(s); \ | 19 | pos += sizeof(s); \ |
20 | } \ | 20 | } \ |
21 | len += sizeof(s); \ | 21 | len += sizeof(s); \ |
22 | } while(0) | 22 | } while(0) |
23 | 23 | ||
24 | acl = nfs3_proc_getacl(inode, ACL_TYPE_ACCESS); | 24 | acl = nfs3_proc_getacl(inode, ACL_TYPE_ACCESS); |
25 | if (IS_ERR(acl)) | 25 | if (IS_ERR(acl)) |
26 | return PTR_ERR(acl); | 26 | return PTR_ERR(acl); |
27 | if (acl) { | 27 | if (acl) { |
28 | output("system.posix_acl_access"); | 28 | output("system.posix_acl_access"); |
29 | posix_acl_release(acl); | 29 | posix_acl_release(acl); |
30 | } | 30 | } |
31 | 31 | ||
32 | if (S_ISDIR(inode->i_mode)) { | 32 | if (S_ISDIR(inode->i_mode)) { |
33 | acl = nfs3_proc_getacl(inode, ACL_TYPE_DEFAULT); | 33 | acl = nfs3_proc_getacl(inode, ACL_TYPE_DEFAULT); |
34 | if (IS_ERR(acl)) | 34 | if (IS_ERR(acl)) |
35 | return PTR_ERR(acl); | 35 | return PTR_ERR(acl); |
36 | if (acl) { | 36 | if (acl) { |
37 | output("system.posix_acl_default"); | 37 | output("system.posix_acl_default"); |
38 | posix_acl_release(acl); | 38 | posix_acl_release(acl); |
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
42 | # undef output | 42 | # undef output |
43 | 43 | ||
44 | if (!buffer || len <= size) | 44 | if (!buffer || len <= size) |
45 | return len; | 45 | return len; |
46 | return -ERANGE; | 46 | return -ERANGE; |
47 | } | 47 | } |
48 | 48 | ||
49 | ssize_t nfs3_getxattr(struct dentry *dentry, const char *name, | 49 | ssize_t nfs3_getxattr(struct dentry *dentry, const char *name, |
50 | void *buffer, size_t size) | 50 | void *buffer, size_t size) |
51 | { | 51 | { |
52 | struct inode *inode = dentry->d_inode; | 52 | struct inode *inode = dentry->d_inode; |
53 | struct posix_acl *acl; | 53 | struct posix_acl *acl; |
54 | int type, error = 0; | 54 | int type, error = 0; |
55 | 55 | ||
56 | if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) | 56 | if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) |
57 | type = ACL_TYPE_ACCESS; | 57 | type = ACL_TYPE_ACCESS; |
58 | else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) | 58 | else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) |
59 | type = ACL_TYPE_DEFAULT; | 59 | type = ACL_TYPE_DEFAULT; |
60 | else | 60 | else |
61 | return -EOPNOTSUPP; | 61 | return -EOPNOTSUPP; |
62 | 62 | ||
63 | acl = nfs3_proc_getacl(inode, type); | 63 | acl = nfs3_proc_getacl(inode, type); |
64 | if (IS_ERR(acl)) | 64 | if (IS_ERR(acl)) |
65 | return PTR_ERR(acl); | 65 | return PTR_ERR(acl); |
66 | else if (acl) { | 66 | else if (acl) { |
67 | if (type == ACL_TYPE_ACCESS && acl->a_count == 0) | 67 | if (type == ACL_TYPE_ACCESS && acl->a_count == 0) |
68 | error = -ENODATA; | 68 | error = -ENODATA; |
69 | else | 69 | else |
70 | error = posix_acl_to_xattr(acl, buffer, size); | 70 | error = posix_acl_to_xattr(acl, buffer, size); |
71 | posix_acl_release(acl); | 71 | posix_acl_release(acl); |
72 | } else | 72 | } else |
73 | error = -ENODATA; | 73 | error = -ENODATA; |
74 | 74 | ||
75 | return error; | 75 | return error; |
76 | } | 76 | } |
77 | 77 | ||
78 | int nfs3_setxattr(struct dentry *dentry, const char *name, | 78 | int nfs3_setxattr(struct dentry *dentry, const char *name, |
79 | const void *value, size_t size, int flags) | 79 | const void *value, size_t size, int flags) |
80 | { | 80 | { |
81 | struct inode *inode = dentry->d_inode; | 81 | struct inode *inode = dentry->d_inode; |
82 | struct posix_acl *acl; | 82 | struct posix_acl *acl; |
83 | int type, error; | 83 | int type, error; |
84 | 84 | ||
85 | if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) | 85 | if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) |
86 | type = ACL_TYPE_ACCESS; | 86 | type = ACL_TYPE_ACCESS; |
87 | else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) | 87 | else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) |
88 | type = ACL_TYPE_DEFAULT; | 88 | type = ACL_TYPE_DEFAULT; |
89 | else | 89 | else |
90 | return -EOPNOTSUPP; | 90 | return -EOPNOTSUPP; |
91 | 91 | ||
92 | acl = posix_acl_from_xattr(value, size); | 92 | acl = posix_acl_from_xattr(value, size); |
93 | if (IS_ERR(acl)) | 93 | if (IS_ERR(acl)) |
94 | return PTR_ERR(acl); | 94 | return PTR_ERR(acl); |
95 | error = nfs3_proc_setacl(inode, type, acl); | 95 | error = nfs3_proc_setacl(inode, type, acl); |
96 | posix_acl_release(acl); | 96 | posix_acl_release(acl); |
97 | 97 | ||
98 | return error; | 98 | return error; |
99 | } | 99 | } |
100 | 100 | ||
101 | int nfs3_removexattr(struct dentry *dentry, const char *name) | 101 | int nfs3_removexattr(struct dentry *dentry, const char *name) |
102 | { | 102 | { |
103 | struct inode *inode = dentry->d_inode; | 103 | struct inode *inode = dentry->d_inode; |
104 | int type; | 104 | int type; |
105 | 105 | ||
106 | if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) | 106 | if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) |
107 | type = ACL_TYPE_ACCESS; | 107 | type = ACL_TYPE_ACCESS; |
108 | else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) | 108 | else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) |
109 | type = ACL_TYPE_DEFAULT; | 109 | type = ACL_TYPE_DEFAULT; |
110 | else | 110 | else |
111 | return -EOPNOTSUPP; | 111 | return -EOPNOTSUPP; |
112 | 112 | ||
113 | return nfs3_proc_setacl(inode, type, NULL); | 113 | return nfs3_proc_setacl(inode, type, NULL); |
114 | } | 114 | } |
115 | 115 | ||
116 | static void __nfs3_forget_cached_acls(struct nfs_inode *nfsi) | 116 | static void __nfs3_forget_cached_acls(struct nfs_inode *nfsi) |
117 | { | 117 | { |
118 | if (!IS_ERR(nfsi->acl_access)) { | 118 | if (!IS_ERR(nfsi->acl_access)) { |
119 | posix_acl_release(nfsi->acl_access); | 119 | posix_acl_release(nfsi->acl_access); |
120 | nfsi->acl_access = ERR_PTR(-EAGAIN); | 120 | nfsi->acl_access = ERR_PTR(-EAGAIN); |
121 | } | 121 | } |
122 | if (!IS_ERR(nfsi->acl_default)) { | 122 | if (!IS_ERR(nfsi->acl_default)) { |
123 | posix_acl_release(nfsi->acl_default); | 123 | posix_acl_release(nfsi->acl_default); |
124 | nfsi->acl_default = ERR_PTR(-EAGAIN); | 124 | nfsi->acl_default = ERR_PTR(-EAGAIN); |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | void nfs3_forget_cached_acls(struct inode *inode) | 128 | void nfs3_forget_cached_acls(struct inode *inode) |
129 | { | 129 | { |
130 | dprintk("NFS: nfs3_forget_cached_acls(%s/%ld)\n", inode->i_sb->s_id, | 130 | dprintk("NFS: nfs3_forget_cached_acls(%s/%ld)\n", inode->i_sb->s_id, |
131 | inode->i_ino); | 131 | inode->i_ino); |
132 | spin_lock(&inode->i_lock); | 132 | spin_lock(&inode->i_lock); |
133 | __nfs3_forget_cached_acls(NFS_I(inode)); | 133 | __nfs3_forget_cached_acls(NFS_I(inode)); |
134 | spin_unlock(&inode->i_lock); | 134 | spin_unlock(&inode->i_lock); |
135 | } | 135 | } |
136 | 136 | ||
137 | static struct posix_acl *nfs3_get_cached_acl(struct inode *inode, int type) | 137 | static struct posix_acl *nfs3_get_cached_acl(struct inode *inode, int type) |
138 | { | 138 | { |
139 | struct nfs_inode *nfsi = NFS_I(inode); | 139 | struct nfs_inode *nfsi = NFS_I(inode); |
140 | struct posix_acl *acl = ERR_PTR(-EINVAL); | 140 | struct posix_acl *acl = ERR_PTR(-EINVAL); |
141 | 141 | ||
142 | spin_lock(&inode->i_lock); | 142 | spin_lock(&inode->i_lock); |
143 | switch(type) { | 143 | switch(type) { |
144 | case ACL_TYPE_ACCESS: | 144 | case ACL_TYPE_ACCESS: |
145 | acl = nfsi->acl_access; | 145 | acl = nfsi->acl_access; |
146 | break; | 146 | break; |
147 | 147 | ||
148 | case ACL_TYPE_DEFAULT: | 148 | case ACL_TYPE_DEFAULT: |
149 | acl = nfsi->acl_default; | 149 | acl = nfsi->acl_default; |
150 | break; | 150 | break; |
151 | 151 | ||
152 | default: | 152 | default: |
153 | goto out; | 153 | goto out; |
154 | } | 154 | } |
155 | if (IS_ERR(acl)) | 155 | if (IS_ERR(acl)) |
156 | acl = ERR_PTR(-EAGAIN); | 156 | acl = ERR_PTR(-EAGAIN); |
157 | else | 157 | else |
158 | acl = posix_acl_dup(acl); | 158 | acl = posix_acl_dup(acl); |
159 | out: | 159 | out: |
160 | spin_unlock(&inode->i_lock); | 160 | spin_unlock(&inode->i_lock); |
161 | dprintk("NFS: nfs3_get_cached_acl(%s/%ld, %d) = %p\n", inode->i_sb->s_id, | 161 | dprintk("NFS: nfs3_get_cached_acl(%s/%ld, %d) = %p\n", inode->i_sb->s_id, |
162 | inode->i_ino, type, acl); | 162 | inode->i_ino, type, acl); |
163 | return acl; | 163 | return acl; |
164 | } | 164 | } |
165 | 165 | ||
166 | static void nfs3_cache_acls(struct inode *inode, struct posix_acl *acl, | 166 | static void nfs3_cache_acls(struct inode *inode, struct posix_acl *acl, |
167 | struct posix_acl *dfacl) | 167 | struct posix_acl *dfacl) |
168 | { | 168 | { |
169 | struct nfs_inode *nfsi = NFS_I(inode); | 169 | struct nfs_inode *nfsi = NFS_I(inode); |
170 | 170 | ||
171 | dprintk("nfs3_cache_acls(%s/%ld, %p, %p)\n", inode->i_sb->s_id, | 171 | dprintk("nfs3_cache_acls(%s/%ld, %p, %p)\n", inode->i_sb->s_id, |
172 | inode->i_ino, acl, dfacl); | 172 | inode->i_ino, acl, dfacl); |
173 | spin_lock(&inode->i_lock); | 173 | spin_lock(&inode->i_lock); |
174 | __nfs3_forget_cached_acls(NFS_I(inode)); | 174 | __nfs3_forget_cached_acls(NFS_I(inode)); |
175 | nfsi->acl_access = posix_acl_dup(acl); | 175 | if (!IS_ERR(acl)) |
176 | nfsi->acl_default = posix_acl_dup(dfacl); | 176 | nfsi->acl_access = posix_acl_dup(acl); |
177 | if (!IS_ERR(dfacl)) | ||
178 | nfsi->acl_default = posix_acl_dup(dfacl); | ||
177 | spin_unlock(&inode->i_lock); | 179 | spin_unlock(&inode->i_lock); |
178 | } | 180 | } |
179 | 181 | ||
180 | struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type) | 182 | struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type) |
181 | { | 183 | { |
182 | struct nfs_server *server = NFS_SERVER(inode); | 184 | struct nfs_server *server = NFS_SERVER(inode); |
183 | struct nfs_fattr fattr; | 185 | struct nfs_fattr fattr; |
184 | struct page *pages[NFSACL_MAXPAGES] = { }; | 186 | struct page *pages[NFSACL_MAXPAGES] = { }; |
185 | struct nfs3_getaclargs args = { | 187 | struct nfs3_getaclargs args = { |
186 | .fh = NFS_FH(inode), | 188 | .fh = NFS_FH(inode), |
187 | /* The xdr layer may allocate pages here. */ | 189 | /* The xdr layer may allocate pages here. */ |
188 | .pages = pages, | 190 | .pages = pages, |
189 | }; | 191 | }; |
190 | struct nfs3_getaclres res = { | 192 | struct nfs3_getaclres res = { |
191 | .fattr = &fattr, | 193 | .fattr = &fattr, |
192 | }; | 194 | }; |
193 | struct rpc_message msg = { | 195 | struct rpc_message msg = { |
194 | .rpc_argp = &args, | 196 | .rpc_argp = &args, |
195 | .rpc_resp = &res, | 197 | .rpc_resp = &res, |
196 | }; | 198 | }; |
197 | struct posix_acl *acl; | 199 | struct posix_acl *acl; |
198 | int status, count; | 200 | int status, count; |
199 | 201 | ||
200 | if (!nfs_server_capable(inode, NFS_CAP_ACLS)) | 202 | if (!nfs_server_capable(inode, NFS_CAP_ACLS)) |
201 | return ERR_PTR(-EOPNOTSUPP); | 203 | return ERR_PTR(-EOPNOTSUPP); |
202 | 204 | ||
203 | status = nfs_revalidate_inode(server, inode); | 205 | status = nfs_revalidate_inode(server, inode); |
204 | if (status < 0) | 206 | if (status < 0) |
205 | return ERR_PTR(status); | 207 | return ERR_PTR(status); |
206 | acl = nfs3_get_cached_acl(inode, type); | 208 | acl = nfs3_get_cached_acl(inode, type); |
207 | if (acl != ERR_PTR(-EAGAIN)) | 209 | if (acl != ERR_PTR(-EAGAIN)) |
208 | return acl; | 210 | return acl; |
209 | acl = NULL; | 211 | acl = NULL; |
210 | 212 | ||
211 | /* | 213 | /* |
212 | * Only get the access acl when explicitly requested: We don't | 214 | * Only get the access acl when explicitly requested: We don't |
213 | * need it for access decisions, and only some applications use | 215 | * need it for access decisions, and only some applications use |
214 | * it. Applications which request the access acl first are not | 216 | * it. Applications which request the access acl first are not |
215 | * penalized from this optimization. | 217 | * penalized from this optimization. |
216 | */ | 218 | */ |
217 | if (type == ACL_TYPE_ACCESS) | 219 | if (type == ACL_TYPE_ACCESS) |
218 | args.mask |= NFS_ACLCNT|NFS_ACL; | 220 | args.mask |= NFS_ACLCNT|NFS_ACL; |
219 | if (S_ISDIR(inode->i_mode)) | 221 | if (S_ISDIR(inode->i_mode)) |
220 | args.mask |= NFS_DFACLCNT|NFS_DFACL; | 222 | args.mask |= NFS_DFACLCNT|NFS_DFACL; |
221 | if (args.mask == 0) | 223 | if (args.mask == 0) |
222 | return NULL; | 224 | return NULL; |
223 | 225 | ||
224 | dprintk("NFS call getacl\n"); | 226 | dprintk("NFS call getacl\n"); |
225 | msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_GETACL]; | 227 | msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_GETACL]; |
226 | status = rpc_call_sync(server->client_acl, &msg, 0); | 228 | status = rpc_call_sync(server->client_acl, &msg, 0); |
227 | dprintk("NFS reply getacl: %d\n", status); | 229 | dprintk("NFS reply getacl: %d\n", status); |
228 | 230 | ||
229 | /* pages may have been allocated at the xdr layer. */ | 231 | /* pages may have been allocated at the xdr layer. */ |
230 | for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++) | 232 | for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++) |
231 | __free_page(args.pages[count]); | 233 | __free_page(args.pages[count]); |
232 | 234 | ||
233 | switch (status) { | 235 | switch (status) { |
234 | case 0: | 236 | case 0: |
235 | status = nfs_refresh_inode(inode, &fattr); | 237 | status = nfs_refresh_inode(inode, &fattr); |
236 | break; | 238 | break; |
237 | case -EPFNOSUPPORT: | 239 | case -EPFNOSUPPORT: |
238 | case -EPROTONOSUPPORT: | 240 | case -EPROTONOSUPPORT: |
239 | dprintk("NFS_V3_ACL extension not supported; disabling\n"); | 241 | dprintk("NFS_V3_ACL extension not supported; disabling\n"); |
240 | server->caps &= ~NFS_CAP_ACLS; | 242 | server->caps &= ~NFS_CAP_ACLS; |
241 | case -ENOTSUPP: | 243 | case -ENOTSUPP: |
242 | status = -EOPNOTSUPP; | 244 | status = -EOPNOTSUPP; |
243 | default: | 245 | default: |
244 | goto getout; | 246 | goto getout; |
245 | } | 247 | } |
246 | if ((args.mask & res.mask) != args.mask) { | 248 | if ((args.mask & res.mask) != args.mask) { |
247 | status = -EIO; | 249 | status = -EIO; |
248 | goto getout; | 250 | goto getout; |
249 | } | 251 | } |
250 | 252 | ||
251 | if (res.acl_access != NULL) { | 253 | if (res.acl_access != NULL) { |
252 | if (posix_acl_equiv_mode(res.acl_access, NULL) == 0) { | 254 | if (posix_acl_equiv_mode(res.acl_access, NULL) == 0) { |
253 | posix_acl_release(res.acl_access); | 255 | posix_acl_release(res.acl_access); |
254 | res.acl_access = NULL; | 256 | res.acl_access = NULL; |
255 | } | 257 | } |
256 | } | 258 | } |
257 | nfs3_cache_acls(inode, res.acl_access, res.acl_default); | 259 | nfs3_cache_acls(inode, |
260 | (res.mask & NFS_ACL) ? res.acl_access : ERR_PTR(-EINVAL), | ||
261 | (res.mask & NFS_DFACL) ? res.acl_default : ERR_PTR(-EINVAL)); | ||
258 | 262 | ||
259 | switch(type) { | 263 | switch(type) { |
260 | case ACL_TYPE_ACCESS: | 264 | case ACL_TYPE_ACCESS: |
261 | acl = res.acl_access; | 265 | acl = res.acl_access; |
262 | res.acl_access = NULL; | 266 | res.acl_access = NULL; |
263 | break; | 267 | break; |
264 | 268 | ||
265 | case ACL_TYPE_DEFAULT: | 269 | case ACL_TYPE_DEFAULT: |
266 | acl = res.acl_default; | 270 | acl = res.acl_default; |
267 | res.acl_default = NULL; | 271 | res.acl_default = NULL; |
268 | } | 272 | } |
269 | 273 | ||
270 | getout: | 274 | getout: |
271 | posix_acl_release(res.acl_access); | 275 | posix_acl_release(res.acl_access); |
272 | posix_acl_release(res.acl_default); | 276 | posix_acl_release(res.acl_default); |
273 | 277 | ||
274 | if (status != 0) { | 278 | if (status != 0) { |
275 | posix_acl_release(acl); | 279 | posix_acl_release(acl); |
276 | acl = ERR_PTR(status); | 280 | acl = ERR_PTR(status); |
277 | } | 281 | } |
278 | return acl; | 282 | return acl; |
279 | } | 283 | } |
280 | 284 | ||
281 | static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl, | 285 | static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl, |
282 | struct posix_acl *dfacl) | 286 | struct posix_acl *dfacl) |
283 | { | 287 | { |
284 | struct nfs_server *server = NFS_SERVER(inode); | 288 | struct nfs_server *server = NFS_SERVER(inode); |
285 | struct nfs_fattr fattr; | 289 | struct nfs_fattr fattr; |
286 | struct page *pages[NFSACL_MAXPAGES] = { }; | 290 | struct page *pages[NFSACL_MAXPAGES] = { }; |
287 | struct nfs3_setaclargs args = { | 291 | struct nfs3_setaclargs args = { |
288 | .inode = inode, | 292 | .inode = inode, |
289 | .mask = NFS_ACL, | 293 | .mask = NFS_ACL, |
290 | .acl_access = acl, | 294 | .acl_access = acl, |
291 | .pages = pages, | 295 | .pages = pages, |
292 | }; | 296 | }; |
293 | struct rpc_message msg = { | 297 | struct rpc_message msg = { |
294 | .rpc_argp = &args, | 298 | .rpc_argp = &args, |
295 | .rpc_resp = &fattr, | 299 | .rpc_resp = &fattr, |
296 | }; | 300 | }; |
297 | int status, count; | 301 | int status, count; |
298 | 302 | ||
299 | status = -EOPNOTSUPP; | 303 | status = -EOPNOTSUPP; |
300 | if (!nfs_server_capable(inode, NFS_CAP_ACLS)) | 304 | if (!nfs_server_capable(inode, NFS_CAP_ACLS)) |
301 | goto out; | 305 | goto out; |
302 | 306 | ||
303 | /* We are doing this here, because XDR marshalling can only | 307 | /* We are doing this here, because XDR marshalling can only |
304 | return -ENOMEM. */ | 308 | return -ENOMEM. */ |
305 | status = -ENOSPC; | 309 | status = -ENOSPC; |
306 | if (acl != NULL && acl->a_count > NFS_ACL_MAX_ENTRIES) | 310 | if (acl != NULL && acl->a_count > NFS_ACL_MAX_ENTRIES) |
307 | goto out; | 311 | goto out; |
308 | if (dfacl != NULL && dfacl->a_count > NFS_ACL_MAX_ENTRIES) | 312 | if (dfacl != NULL && dfacl->a_count > NFS_ACL_MAX_ENTRIES) |
309 | goto out; | 313 | goto out; |
310 | if (S_ISDIR(inode->i_mode)) { | 314 | if (S_ISDIR(inode->i_mode)) { |
311 | args.mask |= NFS_DFACL; | 315 | args.mask |= NFS_DFACL; |
312 | args.acl_default = dfacl; | 316 | args.acl_default = dfacl; |
313 | } | 317 | } |
314 | 318 | ||
315 | dprintk("NFS call setacl\n"); | 319 | dprintk("NFS call setacl\n"); |
316 | nfs_begin_data_update(inode); | 320 | nfs_begin_data_update(inode); |
317 | msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL]; | 321 | msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL]; |
318 | status = rpc_call_sync(server->client_acl, &msg, 0); | 322 | status = rpc_call_sync(server->client_acl, &msg, 0); |
319 | spin_lock(&inode->i_lock); | 323 | spin_lock(&inode->i_lock); |
320 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS; | 324 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS; |
321 | spin_unlock(&inode->i_lock); | 325 | spin_unlock(&inode->i_lock); |
322 | nfs_end_data_update(inode); | 326 | nfs_end_data_update(inode); |
323 | dprintk("NFS reply setacl: %d\n", status); | 327 | dprintk("NFS reply setacl: %d\n", status); |
324 | 328 | ||
325 | /* pages may have been allocated at the xdr layer. */ | 329 | /* pages may have been allocated at the xdr layer. */ |
326 | for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++) | 330 | for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++) |
327 | __free_page(args.pages[count]); | 331 | __free_page(args.pages[count]); |
328 | 332 | ||
329 | switch (status) { | 333 | switch (status) { |
330 | case 0: | 334 | case 0: |
331 | status = nfs_refresh_inode(inode, &fattr); | 335 | status = nfs_refresh_inode(inode, &fattr); |
336 | nfs3_cache_acls(inode, acl, dfacl); | ||
332 | break; | 337 | break; |
333 | case -EPFNOSUPPORT: | 338 | case -EPFNOSUPPORT: |
334 | case -EPROTONOSUPPORT: | 339 | case -EPROTONOSUPPORT: |
335 | dprintk("NFS_V3_ACL SETACL RPC not supported" | 340 | dprintk("NFS_V3_ACL SETACL RPC not supported" |
336 | "(will not retry)\n"); | 341 | "(will not retry)\n"); |
337 | server->caps &= ~NFS_CAP_ACLS; | 342 | server->caps &= ~NFS_CAP_ACLS; |
338 | case -ENOTSUPP: | 343 | case -ENOTSUPP: |
339 | status = -EOPNOTSUPP; | 344 | status = -EOPNOTSUPP; |
340 | } | 345 | } |
341 | out: | 346 | out: |
342 | return status; | 347 | return status; |
343 | } | 348 | } |
344 | 349 | ||
345 | int nfs3_proc_setacl(struct inode *inode, int type, struct posix_acl *acl) | 350 | int nfs3_proc_setacl(struct inode *inode, int type, struct posix_acl *acl) |
346 | { | 351 | { |
347 | struct posix_acl *alloc = NULL, *dfacl = NULL; | 352 | struct posix_acl *alloc = NULL, *dfacl = NULL; |
348 | int status; | 353 | int status; |
349 | 354 | ||
350 | if (S_ISDIR(inode->i_mode)) { | 355 | if (S_ISDIR(inode->i_mode)) { |
351 | switch(type) { | 356 | switch(type) { |
352 | case ACL_TYPE_ACCESS: | 357 | case ACL_TYPE_ACCESS: |
353 | alloc = dfacl = nfs3_proc_getacl(inode, | 358 | alloc = dfacl = nfs3_proc_getacl(inode, |
354 | ACL_TYPE_DEFAULT); | 359 | ACL_TYPE_DEFAULT); |
355 | if (IS_ERR(alloc)) | 360 | if (IS_ERR(alloc)) |
356 | goto fail; | 361 | goto fail; |
357 | break; | 362 | break; |
358 | 363 | ||
359 | case ACL_TYPE_DEFAULT: | 364 | case ACL_TYPE_DEFAULT: |
360 | dfacl = acl; | 365 | dfacl = acl; |
361 | alloc = acl = nfs3_proc_getacl(inode, | 366 | alloc = acl = nfs3_proc_getacl(inode, |
362 | ACL_TYPE_ACCESS); | 367 | ACL_TYPE_ACCESS); |
363 | if (IS_ERR(alloc)) | 368 | if (IS_ERR(alloc)) |
364 | goto fail; | 369 | goto fail; |
365 | break; | 370 | break; |
366 | 371 | ||
367 | default: | 372 | default: |
368 | return -EINVAL; | 373 | return -EINVAL; |
369 | } | 374 | } |
370 | } else if (type != ACL_TYPE_ACCESS) | 375 | } else if (type != ACL_TYPE_ACCESS) |
371 | return -EINVAL; | 376 | return -EINVAL; |
372 | 377 | ||
373 | if (acl == NULL) { | 378 | if (acl == NULL) { |
374 | alloc = acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL); | 379 | alloc = acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL); |
375 | if (IS_ERR(alloc)) | 380 | if (IS_ERR(alloc)) |
376 | goto fail; | 381 | goto fail; |
377 | } | 382 | } |
378 | status = nfs3_proc_setacls(inode, acl, dfacl); | 383 | status = nfs3_proc_setacls(inode, acl, dfacl); |
379 | posix_acl_release(alloc); | 384 | posix_acl_release(alloc); |
380 | return status; | 385 | return status; |
381 | 386 | ||
382 | fail: | 387 | fail: |
383 | return PTR_ERR(alloc); | 388 | return PTR_ERR(alloc); |
384 | } | 389 | } |
385 | 390 | ||
386 | int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode, | 391 | int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode, |
387 | mode_t mode) | 392 | mode_t mode) |
388 | { | 393 | { |
389 | struct posix_acl *dfacl, *acl; | 394 | struct posix_acl *dfacl, *acl; |
390 | int error = 0; | 395 | int error = 0; |
391 | 396 | ||
392 | dfacl = nfs3_proc_getacl(dir, ACL_TYPE_DEFAULT); | 397 | dfacl = nfs3_proc_getacl(dir, ACL_TYPE_DEFAULT); |
393 | if (IS_ERR(dfacl)) { | 398 | if (IS_ERR(dfacl)) { |
394 | error = PTR_ERR(dfacl); | 399 | error = PTR_ERR(dfacl); |
395 | return (error == -EOPNOTSUPP) ? 0 : error; | 400 | return (error == -EOPNOTSUPP) ? 0 : error; |
396 | } | 401 | } |
397 | if (!dfacl) | 402 | if (!dfacl) |
398 | return 0; | 403 | return 0; |
399 | acl = posix_acl_clone(dfacl, GFP_KERNEL); | 404 | acl = posix_acl_clone(dfacl, GFP_KERNEL); |
400 | error = -ENOMEM; | 405 | error = -ENOMEM; |
401 | if (!acl) | 406 | if (!acl) |
402 | goto out_release_dfacl; | 407 | goto out_release_dfacl; |
403 | error = posix_acl_create_masq(acl, &mode); | 408 | error = posix_acl_create_masq(acl, &mode); |
404 | if (error < 0) | 409 | if (error < 0) |
405 | goto out_release_acl; | 410 | goto out_release_acl; |
406 | error = nfs3_proc_setacls(inode, acl, S_ISDIR(inode->i_mode) ? | 411 | error = nfs3_proc_setacls(inode, acl, S_ISDIR(inode->i_mode) ? |
407 | dfacl : NULL); | 412 | dfacl : NULL); |
408 | out_release_acl: | 413 | out_release_acl: |
409 | posix_acl_release(acl); | 414 | posix_acl_release(acl); |
410 | out_release_dfacl: | 415 | out_release_dfacl: |
411 | posix_acl_release(dfacl); | 416 | posix_acl_release(dfacl); |
412 | return error; | 417 | return error; |
413 | } | 418 | } |
414 | 419 |