Skip to content

Commit

Permalink
kill boilerplates around posix_acl_create_masq()
Browse files Browse the repository at this point in the history
new helper: posix_acl_create(&acl, gfp, mode_p).  Replaces acl with
modified clone, on failure releases acl and replaces with NULL.
Returns 0 or -ve on error.  All callers of posix_acl_create_masq()
switched.

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jul 25, 2011
1 parent 95203be commit 826cae2
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 204 deletions.
22 changes: 5 additions & 17 deletions fs/9p/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,30 +206,18 @@ int v9fs_acl_mode(struct inode *dir, mode_t *modep,
mode &= ~current_umask();
}
if (acl) {
struct posix_acl *clone;

if (S_ISDIR(mode))
*dpacl = posix_acl_dup(acl);
clone = posix_acl_clone(acl, GFP_NOFS);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;

retval = posix_acl_create_masq(clone, &mode);
if (retval < 0) {
posix_acl_release(clone);
goto cleanup;
}
retval = posix_acl_create(&acl, GFP_NOFS, &mode);
if (retval < 0)
return retval;
if (retval > 0)
*pacl = clone;
*pacl = acl;
else
posix_acl_release(clone);
posix_acl_release(acl);
}
*modep = mode;
return 0;
cleanup:
return retval;

}

static int v9fs_remote_get_acl(struct dentry *dentry, const char *name,
Expand Down
24 changes: 8 additions & 16 deletions fs/btrfs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,31 +238,23 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
}

if (IS_POSIXACL(dir) && acl) {
struct posix_acl *clone;
mode_t mode;
mode_t mode = inode->i_mode;

if (S_ISDIR(inode->i_mode)) {
ret = btrfs_set_acl(trans, inode, acl,
ACL_TYPE_DEFAULT);
if (ret)
goto failed;
}
clone = posix_acl_clone(acl, GFP_NOFS);
ret = -ENOMEM;
if (!clone)
goto failed;
ret = posix_acl_create(&acl, GFP_NOFS, &mode);
if (ret < 0)
return ret;

mode = inode->i_mode;
ret = posix_acl_create_masq(clone, &mode);
if (ret >= 0) {
inode->i_mode = mode;
if (ret > 0) {
/* we need an acl */
ret = btrfs_set_acl(trans, inode, clone,
ACL_TYPE_ACCESS);
}
inode->i_mode = mode;
if (ret > 0) {
/* we need an acl */
ret = btrfs_set_acl(trans, inode, acl, ACL_TYPE_ACCESS);
}
posix_acl_release(clone);
}
failed:
posix_acl_release(acl);
Expand Down
25 changes: 8 additions & 17 deletions fs/ext2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,29 +270,20 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
inode->i_mode &= ~current_umask();
}
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
struct posix_acl *clone;
mode_t mode;

mode_t mode = inode->i_mode;
if (S_ISDIR(inode->i_mode)) {
error = ext2_set_acl(inode, ACL_TYPE_DEFAULT, acl);
if (error)
goto cleanup;
}
clone = posix_acl_clone(acl, GFP_KERNEL);
error = -ENOMEM;
if (!clone)
goto cleanup;
mode = inode->i_mode;
error = posix_acl_create_masq(clone, &mode);
if (error >= 0) {
inode->i_mode = mode;
if (error > 0) {
/* This is an extended ACL */
error = ext2_set_acl(inode,
ACL_TYPE_ACCESS, clone);
}
error = posix_acl_create(&acl, GFP_KERNEL, &mode);
if (error < 0)
return error;
inode->i_mode = mode;
if (error > 0) {
/* This is an extended ACL */
error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
}
posix_acl_release(clone);
}
cleanup:
posix_acl_release(acl);
Expand Down
26 changes: 9 additions & 17 deletions fs/ext3/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,31 +278,23 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
inode->i_mode &= ~current_umask();
}
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
struct posix_acl *clone;
mode_t mode;
mode_t mode = inode->i_mode;

if (S_ISDIR(inode->i_mode)) {
error = ext3_set_acl(handle, inode,
ACL_TYPE_DEFAULT, acl);
if (error)
goto cleanup;
}
clone = posix_acl_clone(acl, GFP_NOFS);
error = -ENOMEM;
if (!clone)
goto cleanup;

mode = inode->i_mode;
error = posix_acl_create_masq(clone, &mode);
if (error >= 0) {
inode->i_mode = mode;
if (error > 0) {
/* This is an extended ACL */
error = ext3_set_acl(handle, inode,
ACL_TYPE_ACCESS, clone);
}
error = posix_acl_create(&acl, GFP_NOFS, &mode);
if (error < 0)
return error;

inode->i_mode = mode;
if (error > 0) {
/* This is an extended ACL */
error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
}
posix_acl_release(clone);
}
cleanup:
posix_acl_release(acl);
Expand Down
26 changes: 9 additions & 17 deletions fs/ext4/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,31 +276,23 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
inode->i_mode &= ~current_umask();
}
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
struct posix_acl *clone;
mode_t mode;
mode_t mode = inode->i_mode;

if (S_ISDIR(inode->i_mode)) {
error = ext4_set_acl(handle, inode,
ACL_TYPE_DEFAULT, acl);
if (error)
goto cleanup;
}
clone = posix_acl_clone(acl, GFP_NOFS);
error = -ENOMEM;
if (!clone)
goto cleanup;

mode = inode->i_mode;
error = posix_acl_create_masq(clone, &mode);
if (error >= 0) {
inode->i_mode = mode;
if (error > 0) {
/* This is an extended ACL */
error = ext4_set_acl(handle, inode,
ACL_TYPE_ACCESS, clone);
}
error = posix_acl_create(&acl, GFP_NOFS, &mode);
if (error < 0)
return error;

inode->i_mode = mode;
if (error > 0) {
/* This is an extended ACL */
error = ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
}
posix_acl_release(clone);
}
cleanup:
posix_acl_release(acl);
Expand Down
20 changes: 6 additions & 14 deletions fs/generic_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,17 @@ generic_acl_init(struct inode *inode, struct inode *dir)
if (!S_ISLNK(inode->i_mode))
acl = get_cached_acl(dir, ACL_TYPE_DEFAULT);
if (acl) {
struct posix_acl *clone;

if (S_ISDIR(inode->i_mode))
set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);
clone = posix_acl_clone(acl, GFP_KERNEL);
error = -ENOMEM;
if (!clone)
goto cleanup;
error = posix_acl_create_masq(clone, &mode);
if (error >= 0) {
inode->i_mode = mode;
if (error > 0)
set_cached_acl(inode, ACL_TYPE_ACCESS, clone);
}
posix_acl_release(clone);
error = posix_acl_create(&acl, GFP_KERNEL, &mode);
if (error < 0)
return error;
inode->i_mode = mode;
if (error > 0)
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
}
error = 0;

cleanup:
posix_acl_release(acl);
return error;
}
Expand Down
14 changes: 4 additions & 10 deletions fs/gfs2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static int gfs2_acl_set(struct inode *inode, int type, struct posix_acl *acl)
int gfs2_acl_create(struct gfs2_inode *dip, struct inode *inode)
{
struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
struct posix_acl *acl, *clone;
struct posix_acl *acl;
mode_t mode = inode->i_mode;
int error = 0;

Expand All @@ -162,16 +162,10 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct inode *inode)
goto out;
}

clone = posix_acl_clone(acl, GFP_NOFS);
error = -ENOMEM;
if (!clone)
goto out;
posix_acl_release(acl);
acl = clone;

error = posix_acl_create_masq(acl, &mode);
error = posix_acl_create(&acl, GFP_NOFS, &mode);
if (error < 0)
goto out;
return error;

if (error == 0)
goto munge;

Expand Down
15 changes: 5 additions & 10 deletions fs/jffs2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ int jffs2_check_acl(struct inode *inode, int mask)

int jffs2_init_acl_pre(struct inode *dir_i, struct inode *inode, mode_t *i_mode)
{
struct posix_acl *acl, *clone;
struct posix_acl *acl;
int rc;

cache_no_acl(inode);
Expand All @@ -295,18 +295,13 @@ int jffs2_init_acl_pre(struct inode *dir_i, struct inode *inode, mode_t *i_mode)
if (S_ISDIR(*i_mode))
set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);

clone = posix_acl_clone(acl, GFP_KERNEL);
if (!clone)
return -ENOMEM;
rc = posix_acl_create_masq(clone, i_mode);
if (rc < 0) {
posix_acl_release(clone);
rc = posix_acl_create(&acl, GFP_KERNEL, i_mode);
if (rc < 0)
return rc;
}
if (rc > 0)
set_cached_acl(inode, ACL_TYPE_ACCESS, clone);
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);

posix_acl_release(clone);
posix_acl_release(acl);
}
return 0;
}
Expand Down
23 changes: 7 additions & 16 deletions fs/jfs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ int jfs_check_acl(struct inode *inode, int mask)
int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
{
struct posix_acl *acl = NULL;
struct posix_acl *clone;
mode_t mode;
int rc = 0;

if (S_ISLNK(inode->i_mode))
Expand All @@ -145,25 +143,18 @@ int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
return PTR_ERR(acl);

if (acl) {
mode_t mode = inode->i_mode;
if (S_ISDIR(inode->i_mode)) {
rc = jfs_set_acl(tid, inode, ACL_TYPE_DEFAULT, acl);
if (rc)
goto cleanup;
}
clone = posix_acl_clone(acl, GFP_KERNEL);
if (!clone) {
rc = -ENOMEM;
goto cleanup;
}
mode = inode->i_mode;
rc = posix_acl_create_masq(clone, &mode);
if (rc >= 0) {
inode->i_mode = mode;
if (rc > 0)
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS,
clone);
}
posix_acl_release(clone);
rc = posix_acl_create(&acl, GFP_KERNEL, &mode);
if (rc < 0)
goto cleanup; /* posix_acl_release(NULL) is no-op */
inode->i_mode = mode;
if (rc > 0)
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
cleanup:
posix_acl_release(acl);
} else
Expand Down
10 changes: 3 additions & 7 deletions fs/nfs/nfs3acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,12 @@ int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode,
}
if (!dfacl)
return 0;
acl = posix_acl_clone(dfacl, GFP_KERNEL);
error = -ENOMEM;
if (!acl)
goto out_release_dfacl;
error = posix_acl_create_masq(acl, &mode);
acl = posix_acl_dup(dfacl);
error = posix_acl_create(&acl, GFP_KERNEL, &mode);
if (error < 0)
goto out_release_acl;
goto out_release_dfacl;
error = nfs3_proc_setacls(inode, acl, S_ISDIR(inode->i_mode) ?
dfacl : NULL);
out_release_acl:
posix_acl_release(acl);
out_release_dfacl:
posix_acl_release(dfacl);
Expand Down
Loading

0 comments on commit 826cae2

Please sign in to comment.