Skip to content

Commit 37bc153

Browse files
Christoph HellwigAl Viro
authored andcommitted
fs: make posix_acl_create more useful
Rename the current posix_acl_created to __posix_acl_create and add a fully featured helper to set up the ACLs on file creation that uses get_acl(). 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 5bf3258 commit 37bc153

File tree

17 files changed

+81
-23
lines changed

17 files changed

+81
-23
lines changed

fs/9p/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep,
200200
if (acl) {
201201
if (S_ISDIR(mode))
202202
*dpacl = posix_acl_dup(acl);
203-
retval = posix_acl_create(&acl, GFP_NOFS, &mode);
203+
retval = __posix_acl_create(&acl, GFP_NOFS, &mode);
204204
if (retval < 0)
205205
return retval;
206206
if (retval > 0)

fs/btrfs/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
222222
if (ret)
223223
goto failed;
224224
}
225-
ret = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
225+
ret = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
226226
if (ret < 0)
227227
return ret;
228228

fs/ext2/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
268268
if (error)
269269
goto cleanup;
270270
}
271-
error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
271+
error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
272272
if (error < 0)
273273
return error;
274274
if (error > 0) {

fs/ext3/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
271271
if (error)
272272
goto cleanup;
273273
}
274-
error = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
274+
error = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
275275
if (error < 0)
276276
return error;
277277

fs/ext4/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
276276
if (error)
277277
goto cleanup;
278278
}
279-
error = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
279+
error = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
280280
if (error < 0)
281281
return error;
282282

fs/f2fs/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage)
285285
if (error)
286286
goto cleanup;
287287
}
288-
error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
288+
error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
289289
if (error < 0)
290290
return error;
291291
if (error > 0)

fs/generic_acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ generic_acl_init(struct inode *inode, struct inode *dir)
128128
if (acl) {
129129
if (S_ISDIR(inode->i_mode))
130130
set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);
131-
error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
131+
error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
132132
if (error < 0)
133133
return error;
134134
if (error > 0)

fs/gfs2/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct inode *inode)
131131
goto out;
132132
}
133133

134-
error = posix_acl_create(&acl, GFP_NOFS, &mode);
134+
error = __posix_acl_create(&acl, GFP_NOFS, &mode);
135135
if (error < 0)
136136
return error;
137137

fs/hfsplus/posix_acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
137137
goto init_acl_cleanup;
138138
}
139139

140-
err = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
140+
err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
141141
if (unlikely(err < 0))
142142
return err;
143143

fs/jffs2/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ int jffs2_init_acl_pre(struct inode *dir_i, struct inode *inode, umode_t *i_mode
295295
if (S_ISDIR(*i_mode))
296296
set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);
297297

298-
rc = posix_acl_create(&acl, GFP_KERNEL, i_mode);
298+
rc = __posix_acl_create(&acl, GFP_KERNEL, i_mode);
299299
if (rc < 0)
300300
return rc;
301301
if (rc > 0)

fs/jfs/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
132132
if (rc)
133133
goto cleanup;
134134
}
135-
rc = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
135+
rc = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
136136
if (rc < 0)
137137
goto cleanup; /* posix_acl_release(NULL) is no-op */
138138
if (rc > 0)

fs/nfs/nfs3acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode,
428428
if (!dfacl)
429429
return 0;
430430
acl = posix_acl_dup(dfacl);
431-
error = posix_acl_create(&acl, GFP_KERNEL, &mode);
431+
error = __posix_acl_create(&acl, GFP_KERNEL, &mode);
432432
if (error < 0)
433433
goto out_release_dfacl;
434434
error = nfs3_proc_setacls(inode, acl, S_ISDIR(inode->i_mode) ?

fs/ocfs2/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ int ocfs2_init_acl(handle_t *handle,
401401
goto cleanup;
402402
}
403403
mode = inode->i_mode;
404-
ret = posix_acl_create(&acl, GFP_NOFS, &mode);
404+
ret = __posix_acl_create(&acl, GFP_NOFS, &mode);
405405
if (ret < 0)
406406
return ret;
407407

fs/posix_acl.c

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static int __posix_acl_chmod_masq(struct posix_acl *acl, umode_t mode)
410410
}
411411

412412
int
413-
posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
413+
__posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
414414
{
415415
struct posix_acl *clone = posix_acl_clone(*acl, gfp);
416416
int err = -ENOMEM;
@@ -425,7 +425,7 @@ posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
425425
*acl = clone;
426426
return err;
427427
}
428-
EXPORT_SYMBOL(posix_acl_create);
428+
EXPORT_SYMBOL(__posix_acl_create);
429429

430430
int
431431
__posix_acl_chmod(struct posix_acl **acl, gfp_t gfp, umode_t mode)
@@ -446,7 +446,7 @@ __posix_acl_chmod(struct posix_acl **acl, gfp_t gfp, umode_t mode)
446446
EXPORT_SYMBOL(__posix_acl_chmod);
447447

448448
int
449-
posix_acl_chmod(struct inode *inode)
449+
posix_acl_chmod(struct inode *inode, umode_t mode)
450450
{
451451
struct posix_acl *acl;
452452
int ret = 0;
@@ -460,7 +460,7 @@ posix_acl_chmod(struct inode *inode)
460460
if (IS_ERR_OR_NULL(acl))
461461
return PTR_ERR(acl);
462462

463-
ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
463+
ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
464464
if (ret)
465465
return ret;
466466
ret = inode->i_op->set_acl(inode, acl, ACL_TYPE_ACCESS);
@@ -469,6 +469,55 @@ posix_acl_chmod(struct inode *inode)
469469
}
470470
EXPORT_SYMBOL(posix_acl_chmod);
471471

472+
int
473+
posix_acl_create(struct inode *dir, umode_t *mode,
474+
struct posix_acl **default_acl, struct posix_acl **acl)
475+
{
476+
struct posix_acl *p;
477+
int ret;
478+
479+
if (S_ISLNK(*mode) || !IS_POSIXACL(dir))
480+
goto no_acl;
481+
482+
p = get_acl(dir, ACL_TYPE_DEFAULT);
483+
if (IS_ERR(p))
484+
return PTR_ERR(p);
485+
486+
if (!p) {
487+
*mode &= ~current_umask();
488+
goto no_acl;
489+
}
490+
491+
*acl = posix_acl_clone(p, GFP_NOFS);
492+
if (!*acl)
493+
return -ENOMEM;
494+
495+
ret = posix_acl_create_masq(*acl, mode);
496+
if (ret < 0) {
497+
posix_acl_release(*acl);
498+
return -ENOMEM;
499+
}
500+
501+
if (ret == 0) {
502+
posix_acl_release(*acl);
503+
*acl = NULL;
504+
}
505+
506+
if (!S_ISDIR(*mode)) {
507+
posix_acl_release(p);
508+
*default_acl = NULL;
509+
} else {
510+
*default_acl = p;
511+
}
512+
return 0;
513+
514+
no_acl:
515+
*default_acl = NULL;
516+
*acl = NULL;
517+
return 0;
518+
}
519+
EXPORT_SYMBOL_GPL(posix_acl_create);
520+
472521
/*
473522
* Fix up the uids and gids in posix acl extended attributes in place.
474523
*/

fs/reiserfs/xattr_acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
378378

379379
/* Now we reconcile the new ACL and the mode,
380380
potentially modifying both */
381-
err = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
381+
err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
382382
if (err < 0)
383383
return err;
384384

fs/xfs/xfs_acl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,12 @@ xfs_inherit_acl(struct inode *inode, struct posix_acl *acl)
297297
goto out;
298298
}
299299

300-
error = posix_acl_create(&acl, GFP_KERNEL, &mode);
300+
error = __posix_acl_create(&acl, GFP_KERNEL, &mode);
301301
if (error < 0)
302302
return error;
303303

304304
/*
305-
* If posix_acl_create returns a positive value we need to
305+
* If __posix_acl_create returns a positive value we need to
306306
* inherit a permission that can't be represented using the Unix
307307
* mode bits and we actually need to set an ACL.
308308
*/

include/linux/posix_acl.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,16 @@ extern int posix_acl_valid(const struct posix_acl *);
8888
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 *);
91-
extern int posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
91+
extern int __posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
9292
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 *);
98+
extern int posix_acl_chmod(struct inode *, umode_t);
99+
extern int posix_acl_create(struct inode *, umode_t *, struct posix_acl **,
100+
struct posix_acl **);
99101

100102
static inline struct posix_acl **acl_by_type(struct inode *inode, int type)
101103
{
@@ -174,14 +176,21 @@ static inline void cache_no_acl(struct inode *inode)
174176
inode->i_default_acl = NULL;
175177
}
176178
#else
177-
static inline int posix_acl_chmod(struct inode *inode)
179+
static inline int posix_acl_chmod(struct inode *inode, umode_t mode)
178180
{
179181
return 0;
180182
}
181183

182184
static inline void cache_no_acl(struct inode *inode)
183185
{
184186
}
187+
188+
static inline int posix_acl_create(struct inode *inode, umode_t *mode,
189+
struct posix_acl **default_acl, struct posix_acl **acl)
190+
{
191+
*default_acl = *acl = NULL;
192+
return 0;
193+
}
185194
#endif /* CONFIG_FS_POSIX_ACL */
186195

187196
struct posix_acl *get_acl(struct inode *inode, int type);

0 commit comments

Comments
 (0)