]> Pileus Git - ~andy/linux/commitdiff
fs: make posix_acl_create more useful
authorChristoph Hellwig <hch@infradead.org>
Fri, 20 Dec 2013 13:16:42 +0000 (05:16 -0800)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 26 Jan 2014 04:58:18 +0000 (23:58 -0500)
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>
17 files changed:
fs/9p/acl.c
fs/btrfs/acl.c
fs/ext2/acl.c
fs/ext3/acl.c
fs/ext4/acl.c
fs/f2fs/acl.c
fs/generic_acl.c
fs/gfs2/acl.c
fs/hfsplus/posix_acl.c
fs/jffs2/acl.c
fs/jfs/acl.c
fs/nfs/nfs3acl.c
fs/ocfs2/acl.c
fs/posix_acl.c
fs/reiserfs/xattr_acl.c
fs/xfs/xfs_acl.c
include/linux/posix_acl.h

index f5ce5c50c57e0d43e36306d73f6f6cdd93be77a9..8482f2d1160667ba1255ee5b48434287bc51da65 100644 (file)
@@ -200,7 +200,7 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep,
        if (acl) {
                if (S_ISDIR(mode))
                        *dpacl = posix_acl_dup(acl);
-               retval = posix_acl_create(&acl, GFP_NOFS, &mode);
+               retval = __posix_acl_create(&acl, GFP_NOFS, &mode);
                if (retval < 0)
                        return retval;
                if (retval > 0)
index 1af04ff889869c8a6f48fac3f3a8002cef846143..b56519d4726850ebd06e9dc740ef2c9ca26ee236 100644 (file)
@@ -222,7 +222,7 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
                        if (ret)
                                goto failed;
                }
-               ret = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
+               ret = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
                if (ret < 0)
                        return ret;
 
index 7006ced453246fef25abde2c328b672d59365d5b..6e842a764ee746d506b10a4f2505c3fb3c908003 100644 (file)
@@ -268,7 +268,7 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
                        if (error)
                                goto cleanup;
                }
-               error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
+               error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
                if (error < 0)
                        return error;
                if (error > 0) {
index 6691a6c6b2111facc974bc46814b2c0f769e4854..4f3d8fa0c0a3c0c94e1c35171fa8e7cf4210aa58 100644 (file)
@@ -271,7 +271,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
                        if (error)
                                goto cleanup;
                }
-               error = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
+               error = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
                if (error < 0)
                        return error;
 
index 2eebe02fdf09ebc87aa6427352f80ccf45964ed8..f827f3bb6d41f2b19d6365f1af5688388c2dabfc 100644 (file)
@@ -276,7 +276,7 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
                        if (error)
                                goto cleanup;
                }
-               error = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
+               error = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
                if (error < 0)
                        return error;
 
index 14c4df0ede34a4485e91c7d8b33c8ebc834204c3..45e84303c2471e6c68b6e6ebed8d9fa15337b855 100644 (file)
@@ -285,7 +285,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage)
                if (error)
                        goto cleanup;
        }
-       error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
+       error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
        if (error < 0)
                return error;
        if (error > 0)
index 46a5076e9776695b2e55c7e59fe45506f20be160..4357f39c8441c51c890ee15dcbd923755c363259 100644 (file)
@@ -128,7 +128,7 @@ generic_acl_init(struct inode *inode, struct inode *dir)
        if (acl) {
                if (S_ISDIR(inode->i_mode))
                        set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);
-               error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
+               error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
                if (error < 0)
                        return error;
                if (error > 0)
index 3e200c7ca7ad5d317f97fda4b646edca39eba370..e82e4ac574a65d83ebe127ee1ae4bab260866e5f 100644 (file)
@@ -131,7 +131,7 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct inode *inode)
                        goto out;
        }
 
-       error = posix_acl_create(&acl, GFP_NOFS, &mode);
+       error = __posix_acl_create(&acl, GFP_NOFS, &mode);
        if (error < 0)
                return error;
 
index cab5fd6fdb72b781d8b2811ed7c59ae08865fd9d..277942f36f80674f6e8d9f9073ef6e37c832f058 100644 (file)
@@ -137,7 +137,7 @@ int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
                                goto init_acl_cleanup;
                }
 
-               err = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
+               err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
                if (unlikely(err < 0))
                        return err;
 
index 5853969a51bc150981fc41995e82ab65e2bd0637..4d6e31b19816be4304951a93a4b97da890a3033c 100644 (file)
@@ -295,7 +295,7 @@ int jffs2_init_acl_pre(struct inode *dir_i, struct inode *inode, umode_t *i_mode
                if (S_ISDIR(*i_mode))
                        set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);
 
-               rc = posix_acl_create(&acl, GFP_KERNEL, i_mode);
+               rc = __posix_acl_create(&acl, GFP_KERNEL, i_mode);
                if (rc < 0)
                        return rc;
                if (rc > 0)
index 9c0fca8073da54de913029df13ad97cd5dfc0e6b..28d529ae9a4af41d832812d3fce1b0c7fa2cae56 100644 (file)
@@ -132,7 +132,7 @@ int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
                        if (rc)
                                goto cleanup;
                }
-               rc = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
+               rc = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
                if (rc < 0)
                        goto cleanup; /* posix_acl_release(NULL) is no-op */
                if (rc > 0)
index 4a1aafba6a20030532ba589ac9db021b10c21ceb..e85967587d74d4823fc8babf8f0ac6c99cd7a6c6 100644 (file)
@@ -428,7 +428,7 @@ int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode,
        if (!dfacl)
                return 0;
        acl = posix_acl_dup(dfacl);
-       error = posix_acl_create(&acl, GFP_KERNEL, &mode);
+       error = __posix_acl_create(&acl, GFP_KERNEL, &mode);
        if (error < 0)
                goto out_release_dfacl;
        error = nfs3_proc_setacls(inode, acl, S_ISDIR(inode->i_mode) ?
index 73ccf0e22ec5d8af5a0668d63488fe3b0426b024..c0f9d2fe134ffbefa33a1b8eb2f141dd8a1b25a9 100644 (file)
@@ -401,7 +401,7 @@ int ocfs2_init_acl(handle_t *handle,
                                goto cleanup;
                }
                mode = inode->i_mode;
-               ret = posix_acl_create(&acl, GFP_NOFS, &mode);
+               ret = __posix_acl_create(&acl, GFP_NOFS, &mode);
                if (ret < 0)
                        return ret;
 
index 08218550b0dbc6b393313a89d877b0460085d46d..8f245ab20143ff984a286e453d1843bcbdb077e8 100644 (file)
@@ -410,7 +410,7 @@ static int __posix_acl_chmod_masq(struct posix_acl *acl, umode_t mode)
 }
 
 int
-posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
+__posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
 {
        struct posix_acl *clone = posix_acl_clone(*acl, gfp);
        int err = -ENOMEM;
@@ -425,7 +425,7 @@ posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
        *acl = clone;
        return err;
 }
-EXPORT_SYMBOL(posix_acl_create);
+EXPORT_SYMBOL(__posix_acl_create);
 
 int
 __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)
 EXPORT_SYMBOL(__posix_acl_chmod);
 
 int
-posix_acl_chmod(struct inode *inode)
+posix_acl_chmod(struct inode *inode, umode_t mode)
 {
        struct posix_acl *acl;
        int ret = 0;
@@ -460,7 +460,7 @@ posix_acl_chmod(struct inode *inode)
        if (IS_ERR_OR_NULL(acl))
                return PTR_ERR(acl);
 
-       ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
+       ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
        if (ret)
                return ret;
        ret = inode->i_op->set_acl(inode, acl, ACL_TYPE_ACCESS);
@@ -469,6 +469,55 @@ posix_acl_chmod(struct inode *inode)
 }
 EXPORT_SYMBOL(posix_acl_chmod);
 
+int
+posix_acl_create(struct inode *dir, umode_t *mode,
+               struct posix_acl **default_acl, struct posix_acl **acl)
+{
+       struct posix_acl *p;
+       int ret;
+
+       if (S_ISLNK(*mode) || !IS_POSIXACL(dir))
+               goto no_acl;
+
+       p = get_acl(dir, ACL_TYPE_DEFAULT);
+       if (IS_ERR(p))
+               return PTR_ERR(p);
+
+       if (!p) {
+               *mode &= ~current_umask();
+               goto no_acl;
+       }
+
+       *acl = posix_acl_clone(p, GFP_NOFS);
+       if (!*acl)
+               return -ENOMEM;
+
+       ret = posix_acl_create_masq(*acl, mode);
+       if (ret < 0) {
+               posix_acl_release(*acl);
+               return -ENOMEM;
+       }
+
+       if (ret == 0) {
+               posix_acl_release(*acl);
+               *acl = NULL;
+       }
+
+       if (!S_ISDIR(*mode)) {
+               posix_acl_release(p);
+               *default_acl = NULL;
+       } else {
+               *default_acl = p;
+       }
+       return 0;
+
+no_acl:
+       *default_acl = NULL;
+       *acl = NULL;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(posix_acl_create);
+
 /*
  * Fix up the uids and gids in posix acl extended attributes in place.
  */
index ea4e44351f769fa8835ba03e384dd942afef7777..d95c9592327b36f75239e2e427f684688cb5ca64 100644 (file)
@@ -378,7 +378,7 @@ reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
 
                /* Now we reconcile the new ACL and the mode,
                   potentially modifying both */
-               err = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
+               err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
                if (err < 0)
                        return err;
 
index 4eac1058b680149b56136624240562850d2287ae..057ae2d502dc2bf2559b0ada386d493cdc563e2b 100644 (file)
@@ -297,12 +297,12 @@ xfs_inherit_acl(struct inode *inode, struct posix_acl *acl)
                        goto out;
        }
 
-       error = posix_acl_create(&acl, GFP_KERNEL, &mode);
+       error = __posix_acl_create(&acl, GFP_KERNEL, &mode);
        if (error < 0)
                return error;
 
        /*
-        * If posix_acl_create returns a positive value we need to
+        * If __posix_acl_create returns a positive value we need to
         * inherit a permission that can't be represented using the Unix
         * mode bits and we actually need to set an ACL.
         */
index 8b64e7899989924a53d779cb14c6bbbf10c98954..f7e6f6cb214a5312a78444914789fba2bfd3b97c 100644 (file)
@@ -88,14 +88,16 @@ extern int posix_acl_valid(const struct posix_acl *);
 extern int posix_acl_permission(struct inode *, const struct posix_acl *, int);
 extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
 extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);
-extern int posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
+extern int __posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
 extern int __posix_acl_chmod(struct posix_acl **, gfp_t, umode_t);
 
 extern struct posix_acl *get_posix_acl(struct inode *, int);
 extern int set_posix_acl(struct inode *, int, struct posix_acl *);
 
 #ifdef CONFIG_FS_POSIX_ACL
-extern int posix_acl_chmod(struct inode *);
+extern int posix_acl_chmod(struct inode *, umode_t);
+extern int posix_acl_create(struct inode *, umode_t *, struct posix_acl **,
+               struct posix_acl **);
 
 static inline struct posix_acl **acl_by_type(struct inode *inode, int type)
 {
@@ -174,7 +176,7 @@ static inline void cache_no_acl(struct inode *inode)
        inode->i_default_acl = NULL;
 }
 #else
-static inline int posix_acl_chmod(struct inode *inode)
+static inline int posix_acl_chmod(struct inode *inode, umode_t mode)
 {
        return 0;
 }
@@ -182,6 +184,13 @@ static inline int posix_acl_chmod(struct inode *inode)
 static inline void cache_no_acl(struct inode *inode)
 {
 }
+
+static inline int posix_acl_create(struct inode *inode, umode_t *mode,
+               struct posix_acl **default_acl, struct posix_acl **acl)
+{
+       *default_acl = *acl = NULL;
+       return 0;
+}
 #endif /* CONFIG_FS_POSIX_ACL */
 
 struct posix_acl *get_acl(struct inode *inode, int type);