Skip to content

Commit 5bf3258

Browse files
Christoph HellwigAl Viro
authored andcommitted
fs: make posix_acl_chmod more useful
Rename the current posix_acl_chmod to __posix_acl_chmod and add a fully featured ACL chmod helper that uses the ->set_acl inode operation. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 2aeccbe commit 5bf3258

File tree

16 files changed

+54
-21
lines changed

16 files changed

+54
-21
lines changed

fs/9p/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int v9fs_acl_chmod(struct inode *inode, struct p9_fid *fid)
156156
return -EOPNOTSUPP;
157157
acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS);
158158
if (acl) {
159-
retval = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
159+
retval = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
160160
if (retval)
161161
return retval;
162162
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);

fs/btrfs/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ int btrfs_acl_chmod(struct inode *inode)
256256
if (IS_ERR_OR_NULL(acl))
257257
return PTR_ERR(acl);
258258

259-
ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
259+
ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
260260
if (ret)
261261
return ret;
262262
ret = btrfs_set_acl(NULL, inode, acl, ACL_TYPE_ACCESS);

fs/ext2/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ ext2_acl_chmod(struct inode *inode)
308308
acl = ext2_get_acl(inode, ACL_TYPE_ACCESS);
309309
if (IS_ERR(acl) || !acl)
310310
return PTR_ERR(acl);
311-
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
311+
error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
312312
if (error)
313313
return error;
314314
error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);

fs/ext3/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ ext3_acl_chmod(struct inode *inode)
314314
acl = ext3_get_acl(inode, ACL_TYPE_ACCESS);
315315
if (IS_ERR(acl) || !acl)
316316
return PTR_ERR(acl);
317-
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
317+
error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
318318
if (error)
319319
return error;
320320
retry:

fs/ext4/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ ext4_acl_chmod(struct inode *inode)
320320
acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
321321
if (IS_ERR(acl) || !acl)
322322
return PTR_ERR(acl);
323-
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
323+
error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
324324
if (error)
325325
return error;
326326
retry:

fs/f2fs/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ int f2fs_acl_chmod(struct inode *inode)
311311
if (IS_ERR(acl) || !acl)
312312
return PTR_ERR(acl);
313313

314-
error = posix_acl_chmod(&acl, GFP_KERNEL, mode);
314+
error = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
315315
if (error)
316316
return error;
317317

fs/generic_acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ generic_acl_chmod(struct inode *inode)
158158
return -EOPNOTSUPP;
159159
acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
160160
if (acl) {
161-
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
161+
error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
162162
if (error)
163163
return error;
164164
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);

fs/gfs2/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
162162
if (!acl)
163163
return gfs2_setattr_simple(inode, attr);
164164

165-
error = posix_acl_chmod(&acl, GFP_NOFS, attr->ia_mode);
165+
error = __posix_acl_chmod(&acl, GFP_NOFS, attr->ia_mode);
166166
if (error)
167167
return error;
168168

fs/hfsplus/posix_acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ int hfsplus_posix_acl_chmod(struct inode *inode)
167167
if (IS_ERR(acl) || !acl)
168168
return PTR_ERR(acl);
169169

170-
err = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
170+
err = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
171171
if (unlikely(err))
172172
return err;
173173

fs/jffs2/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ int jffs2_acl_chmod(struct inode *inode)
335335
acl = jffs2_get_acl(inode, ACL_TYPE_ACCESS);
336336
if (IS_ERR(acl) || !acl)
337337
return PTR_ERR(acl);
338-
rc = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
338+
rc = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
339339
if (rc)
340340
return rc;
341341
rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, acl);

fs/jfs/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ int jfs_acl_chmod(struct inode *inode)
161161
if (IS_ERR(acl) || !acl)
162162
return PTR_ERR(acl);
163163

164-
rc = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
164+
rc = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
165165
if (rc)
166166
return rc;
167167

fs/ocfs2/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ int ocfs2_acl_chmod(struct inode *inode)
350350
acl = ocfs2_get_acl(inode, ACL_TYPE_ACCESS);
351351
if (IS_ERR(acl) || !acl)
352352
return PTR_ERR(acl);
353-
ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
353+
ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
354354
if (ret)
355355
return ret;
356356
ret = ocfs2_set_acl(NULL, inode, NULL, ACL_TYPE_ACCESS,

fs/posix_acl.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
364364
/*
365365
* Modify the ACL for the chmod syscall.
366366
*/
367-
static int posix_acl_chmod_masq(struct posix_acl *acl, umode_t mode)
367+
static int __posix_acl_chmod_masq(struct posix_acl *acl, umode_t mode)
368368
{
369369
struct posix_acl_entry *group_obj = NULL, *mask_obj = NULL;
370370
struct posix_acl_entry *pa, *pe;
@@ -428,12 +428,12 @@ posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
428428
EXPORT_SYMBOL(posix_acl_create);
429429

430430
int
431-
posix_acl_chmod(struct posix_acl **acl, gfp_t gfp, umode_t mode)
431+
__posix_acl_chmod(struct posix_acl **acl, gfp_t gfp, umode_t mode)
432432
{
433433
struct posix_acl *clone = posix_acl_clone(*acl, gfp);
434434
int err = -ENOMEM;
435435
if (clone) {
436-
err = posix_acl_chmod_masq(clone, mode);
436+
err = __posix_acl_chmod_masq(clone, mode);
437437
if (err) {
438438
posix_acl_release(clone);
439439
clone = NULL;
@@ -443,6 +443,30 @@ posix_acl_chmod(struct posix_acl **acl, gfp_t gfp, umode_t mode)
443443
*acl = clone;
444444
return err;
445445
}
446+
EXPORT_SYMBOL(__posix_acl_chmod);
447+
448+
int
449+
posix_acl_chmod(struct inode *inode)
450+
{
451+
struct posix_acl *acl;
452+
int ret = 0;
453+
454+
if (!IS_POSIXACL(inode))
455+
return 0;
456+
if (!inode->i_op->set_acl)
457+
return -EOPNOTSUPP;
458+
459+
acl = get_acl(inode, ACL_TYPE_ACCESS);
460+
if (IS_ERR_OR_NULL(acl))
461+
return PTR_ERR(acl);
462+
463+
ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
464+
if (ret)
465+
return ret;
466+
ret = inode->i_op->set_acl(inode, acl, ACL_TYPE_ACCESS);
467+
posix_acl_release(acl);
468+
return ret;
469+
}
446470
EXPORT_SYMBOL(posix_acl_chmod);
447471

448472
/*

fs/reiserfs/xattr_acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ int reiserfs_acl_chmod(struct inode *inode)
463463
return 0;
464464
if (IS_ERR(acl))
465465
return PTR_ERR(acl);
466-
error = posix_acl_chmod(&acl, GFP_NOFS, inode->i_mode);
466+
error = __posix_acl_chmod(&acl, GFP_NOFS, inode->i_mode);
467467
if (error)
468468
return error;
469469

fs/xfs/xfs_acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ xfs_acl_chmod(struct inode *inode)
334334
if (IS_ERR(acl) || !acl)
335335
return PTR_ERR(acl);
336336

337-
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
337+
error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
338338
if (error)
339339
return error;
340340

include/linux/posix_acl.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ extern int posix_acl_permission(struct inode *, const struct posix_acl *, int);
8989
extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
9090
extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);
9191
extern int posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
92-
extern int posix_acl_chmod(struct posix_acl **, gfp_t, umode_t);
92+
extern int __posix_acl_chmod(struct posix_acl **, gfp_t, umode_t);
9393

9494
extern struct posix_acl *get_posix_acl(struct inode *, int);
9595
extern int set_posix_acl(struct inode *, int, struct posix_acl *);
9696

9797
#ifdef CONFIG_FS_POSIX_ACL
98+
extern int posix_acl_chmod(struct inode *);
99+
98100
static inline struct posix_acl **acl_by_type(struct inode *inode, int type)
99101
{
100102
switch (type) {
@@ -165,15 +167,22 @@ static inline void forget_all_cached_acls(struct inode *inode)
165167
if (old_default != ACL_NOT_CACHED)
166168
posix_acl_release(old_default);
167169
}
168-
#endif
169170

170171
static inline void cache_no_acl(struct inode *inode)
171172
{
172-
#ifdef CONFIG_FS_POSIX_ACL
173173
inode->i_acl = NULL;
174174
inode->i_default_acl = NULL;
175-
#endif
176175
}
176+
#else
177+
static inline int posix_acl_chmod(struct inode *inode)
178+
{
179+
return 0;
180+
}
181+
182+
static inline void cache_no_acl(struct inode *inode)
183+
{
184+
}
185+
#endif /* CONFIG_FS_POSIX_ACL */
177186

178187
struct posix_acl *get_acl(struct inode *inode, int type);
179188

0 commit comments

Comments
 (0)