aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/acl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/acl.c')
-rw-r--r--fs/btrfs/acl.c63
1 files changed, 14 insertions, 49 deletions
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index 9f62ab2a7282..65a735d8f6e4 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -30,7 +30,7 @@
30 30
31#ifdef CONFIG_BTRFS_FS_POSIX_ACL 31#ifdef CONFIG_BTRFS_FS_POSIX_ACL
32 32
33static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) 33struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
34{ 34{
35 int size; 35 int size;
36 const char *name; 36 const char *name;
@@ -195,27 +195,6 @@ out:
195 return ret; 195 return ret;
196} 196}
197 197
198int btrfs_check_acl(struct inode *inode, int mask)
199{
200 int error = -EAGAIN;
201
202 if (mask & MAY_NOT_BLOCK) {
203 if (!negative_cached_acl(inode, ACL_TYPE_ACCESS))
204 error = -ECHILD;
205 } else {
206 struct posix_acl *acl;
207 acl = btrfs_get_acl(inode, ACL_TYPE_ACCESS);
208 if (IS_ERR(acl))
209 return PTR_ERR(acl);
210 if (acl) {
211 error = posix_acl_permission(inode, acl, mask);
212 posix_acl_release(acl);
213 }
214 }
215
216 return error;
217}
218
219/* 198/*
220 * btrfs_init_acl is already generally called under fs_mutex, so the locking 199 * btrfs_init_acl is already generally called under fs_mutex, so the locking
221 * stuff has been fixed to work with that. If the locking stuff changes, we 200 * stuff has been fixed to work with that. If the locking stuff changes, we
@@ -243,8 +222,7 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
243 } 222 }
244 223
245 if (IS_POSIXACL(dir) && acl) { 224 if (IS_POSIXACL(dir) && acl) {
246 struct posix_acl *clone; 225 mode_t mode = inode->i_mode;
247 mode_t mode;
248 226
249 if (S_ISDIR(inode->i_mode)) { 227 if (S_ISDIR(inode->i_mode)) {
250 ret = btrfs_set_acl(trans, inode, acl, 228 ret = btrfs_set_acl(trans, inode, acl,
@@ -252,22 +230,15 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
252 if (ret) 230 if (ret)
253 goto failed; 231 goto failed;
254 } 232 }
255 clone = posix_acl_clone(acl, GFP_NOFS); 233 ret = posix_acl_create(&acl, GFP_NOFS, &mode);
256 ret = -ENOMEM; 234 if (ret < 0)
257 if (!clone) 235 return ret;
258 goto failed;
259 236
260 mode = inode->i_mode; 237 inode->i_mode = mode;
261 ret = posix_acl_create_masq(clone, &mode); 238 if (ret > 0) {
262 if (ret >= 0) { 239 /* we need an acl */
263 inode->i_mode = mode; 240 ret = btrfs_set_acl(trans, inode, acl, ACL_TYPE_ACCESS);
264 if (ret > 0) {
265 /* we need an acl */
266 ret = btrfs_set_acl(trans, inode, clone,
267 ACL_TYPE_ACCESS);
268 }
269 } 241 }
270 posix_acl_release(clone);
271 } 242 }
272failed: 243failed:
273 posix_acl_release(acl); 244 posix_acl_release(acl);
@@ -277,7 +248,7 @@ failed:
277 248
278int btrfs_acl_chmod(struct inode *inode) 249int btrfs_acl_chmod(struct inode *inode)
279{ 250{
280 struct posix_acl *acl, *clone; 251 struct posix_acl *acl;
281 int ret = 0; 252 int ret = 0;
282 253
283 if (S_ISLNK(inode->i_mode)) 254 if (S_ISLNK(inode->i_mode))
@@ -290,17 +261,11 @@ int btrfs_acl_chmod(struct inode *inode)
290 if (IS_ERR_OR_NULL(acl)) 261 if (IS_ERR_OR_NULL(acl))
291 return PTR_ERR(acl); 262 return PTR_ERR(acl);
292 263
293 clone = posix_acl_clone(acl, GFP_KERNEL); 264 ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
265 if (ret)
266 return ret;
267 ret = btrfs_set_acl(NULL, inode, acl, ACL_TYPE_ACCESS);
294 posix_acl_release(acl); 268 posix_acl_release(acl);
295 if (!clone)
296 return -ENOMEM;
297
298 ret = posix_acl_chmod_masq(clone, inode->i_mode);
299 if (!ret)
300 ret = btrfs_set_acl(NULL, inode, clone, ACL_TYPE_ACCESS);
301
302 posix_acl_release(clone);
303
304 return ret; 269 return ret;
305} 270}
306 271