Skip to content

Commit

Permalink
kill boilerplate around posix_acl_chmod_masq()
Browse files Browse the repository at this point in the history
new helper: posix_acl_chmod(&acl, gfp, mode).  Replaces acl with modified
clone or with NULL if that has failed; returns 0 or -ve on error.  All
callers of posix_acl_chmod_masq() switched to that - they'd been doing
exactly the same thing.

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jul 25, 2011
1 parent 4482a08 commit bc26ab5
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 168 deletions.
13 changes: 5 additions & 8 deletions fs/9p/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,18 @@ static int v9fs_set_acl(struct dentry *dentry, int type, struct posix_acl *acl)
int v9fs_acl_chmod(struct dentry *dentry)
{
int retval = 0;
struct posix_acl *acl, *clone;
struct posix_acl *acl;
struct inode *inode = dentry->d_inode;

if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS);
if (acl) {
clone = posix_acl_clone(acl, GFP_KERNEL);
retval = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (retval)
return retval;
retval = v9fs_set_acl(dentry, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;
retval = posix_acl_chmod_masq(clone, inode->i_mode);
if (!retval)
retval = v9fs_set_acl(dentry, ACL_TYPE_ACCESS, clone);
posix_acl_release(clone);
}
return retval;
}
Expand Down
16 changes: 5 additions & 11 deletions fs/btrfs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,

int btrfs_acl_chmod(struct inode *inode)
{
struct posix_acl *acl, *clone;
struct posix_acl *acl;
int ret = 0;

if (S_ISLNK(inode->i_mode))
Expand All @@ -285,17 +285,11 @@ int btrfs_acl_chmod(struct inode *inode)
if (IS_ERR_OR_NULL(acl))
return PTR_ERR(acl);

clone = posix_acl_clone(acl, GFP_KERNEL);
ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (ret)
return ret;
ret = btrfs_set_acl(NULL, inode, acl, ACL_TYPE_ACCESS);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;

ret = posix_acl_chmod_masq(clone, inode->i_mode);
if (!ret)
ret = btrfs_set_acl(NULL, inode, clone, ACL_TYPE_ACCESS);

posix_acl_release(clone);

return ret;
}

Expand Down
13 changes: 5 additions & 8 deletions fs/ext2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
int
ext2_acl_chmod(struct inode *inode)
{
struct posix_acl *acl, *clone;
struct posix_acl *acl;
int error;

if (!test_opt(inode->i_sb, POSIX_ACL))
Expand All @@ -326,14 +326,11 @@ ext2_acl_chmod(struct inode *inode)
acl = ext2_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
clone = posix_acl_clone(acl, GFP_KERNEL);
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;
error = posix_acl_chmod_masq(clone, inode->i_mode);
if (!error)
error = ext2_set_acl(inode, ACL_TYPE_ACCESS, clone);
posix_acl_release(clone);
return error;
}

Expand Down
43 changes: 19 additions & 24 deletions fs/ext3/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
int
ext3_acl_chmod(struct inode *inode)
{
struct posix_acl *acl, *clone;
struct posix_acl *acl;
handle_t *handle;
int retries = 0;
int error;

if (S_ISLNK(inode->i_mode))
Expand All @@ -336,31 +338,24 @@ ext3_acl_chmod(struct inode *inode)
acl = ext3_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
clone = posix_acl_clone(acl, GFP_KERNEL);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;
error = posix_acl_chmod_masq(clone, inode->i_mode);
if (!error) {
handle_t *handle;
int retries = 0;

retry:
handle = ext3_journal_start(inode,
EXT3_DATA_TRANS_BLOCKS(inode->i_sb));
if (IS_ERR(handle)) {
error = PTR_ERR(handle);
ext3_std_error(inode->i_sb, error);
goto out;
}
error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, clone);
ext3_journal_stop(handle);
if (error == -ENOSPC &&
ext3_should_retry_alloc(inode->i_sb, &retries))
goto retry;
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
retry:
handle = ext3_journal_start(inode,
EXT3_DATA_TRANS_BLOCKS(inode->i_sb));
if (IS_ERR(handle)) {
error = PTR_ERR(handle);
ext3_std_error(inode->i_sb, error);
goto out;
}
error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
ext3_journal_stop(handle);
if (error == -ENOSPC &&
ext3_should_retry_alloc(inode->i_sb, &retries))
goto retry;
out:
posix_acl_release(clone);
posix_acl_release(acl);
return error;
}

Expand Down
44 changes: 20 additions & 24 deletions fs/ext4/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,41 +324,37 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
int
ext4_acl_chmod(struct inode *inode)
{
struct posix_acl *acl, *clone;
struct posix_acl *acl;
handle_t *handle;
int retries = 0;
int error;


if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
if (!test_opt(inode->i_sb, POSIX_ACL))
return 0;
acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
clone = posix_acl_clone(acl, GFP_KERNEL);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;
error = posix_acl_chmod_masq(clone, inode->i_mode);
if (!error) {
handle_t *handle;
int retries = 0;

retry:
handle = ext4_journal_start(inode,
EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
if (IS_ERR(handle)) {
error = PTR_ERR(handle);
ext4_std_error(inode->i_sb, error);
goto out;
}
error = ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, clone);
ext4_journal_stop(handle);
if (error == -ENOSPC &&
ext4_should_retry_alloc(inode->i_sb, &retries))
goto retry;
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
retry:
handle = ext4_journal_start(inode,
EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
if (IS_ERR(handle)) {
error = PTR_ERR(handle);
ext4_std_error(inode->i_sb, error);
goto out;
}
error = ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
ext4_journal_stop(handle);
if (error == -ENOSPC &&
ext4_should_retry_alloc(inode->i_sb, &retries))
goto retry;
out:
posix_acl_release(clone);
posix_acl_release(acl);
return error;
}

Expand Down
13 changes: 5 additions & 8 deletions fs/generic_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,18 @@ generic_acl_init(struct inode *inode, struct inode *dir)
int
generic_acl_chmod(struct inode *inode)
{
struct posix_acl *acl, *clone;
struct posix_acl *acl;
int error = 0;

if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
if (acl) {
clone = posix_acl_clone(acl, GFP_KERNEL);
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;
error = posix_acl_chmod_masq(clone, inode->i_mode);
if (!error)
set_cached_acl(inode, ACL_TYPE_ACCESS, clone);
posix_acl_release(clone);
}
return error;
}
Expand Down
30 changes: 12 additions & 18 deletions fs/gfs2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct inode *inode)

int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
{
struct posix_acl *acl, *clone;
struct posix_acl *acl;
char *data;
unsigned int len;
int error;
Expand All @@ -198,25 +198,19 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
if (!acl)
return gfs2_setattr_simple(ip, attr);

clone = posix_acl_clone(acl, GFP_NOFS);
error = posix_acl_chmod(&acl, GFP_NOFS, attr->ia_mode);
if (error)
return error;

len = posix_acl_to_xattr(acl, NULL, 0);
data = kmalloc(len, GFP_NOFS);
error = -ENOMEM;
if (!clone)
if (data == NULL)
goto out;
posix_acl_release(acl);
acl = clone;

error = posix_acl_chmod_masq(acl, attr->ia_mode);
if (!error) {
len = posix_acl_to_xattr(acl, NULL, 0);
data = kmalloc(len, GFP_NOFS);
error = -ENOMEM;
if (data == NULL)
goto out;
posix_acl_to_xattr(acl, data, len);
error = gfs2_xattr_acl_chmod(ip, attr, data);
kfree(data);
set_cached_acl(&ip->i_inode, ACL_TYPE_ACCESS, acl);
}
posix_acl_to_xattr(acl, data, len);
error = gfs2_xattr_acl_chmod(ip, attr, data);
kfree(data);
set_cached_acl(&ip->i_inode, ACL_TYPE_ACCESS, acl);

out:
posix_acl_release(acl);
Expand Down
13 changes: 5 additions & 8 deletions fs/jffs2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,22 +332,19 @@ int jffs2_init_acl_post(struct inode *inode)

int jffs2_acl_chmod(struct inode *inode)
{
struct posix_acl *acl, *clone;
struct posix_acl *acl;
int rc;

if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
acl = jffs2_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
clone = posix_acl_clone(acl, GFP_KERNEL);
rc = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (rc)
return rc;
rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;
rc = posix_acl_chmod_masq(clone, inode->i_mode);
if (!rc)
rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, clone);
posix_acl_release(clone);
return rc;
}

Expand Down
31 changes: 14 additions & 17 deletions fs/jfs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)

int jfs_acl_chmod(struct inode *inode)
{
struct posix_acl *acl, *clone;
struct posix_acl *acl;
int rc;
tid_t tid;

if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
Expand All @@ -187,22 +188,18 @@ int jfs_acl_chmod(struct inode *inode)
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);

clone = posix_acl_clone(acl, GFP_KERNEL);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;

rc = posix_acl_chmod_masq(clone, inode->i_mode);
if (!rc) {
tid_t tid = txBegin(inode->i_sb, 0);
mutex_lock(&JFS_IP(inode)->commit_mutex);
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, clone);
if (!rc)
rc = txCommit(tid, 1, &inode, 0);
txEnd(tid);
mutex_unlock(&JFS_IP(inode)->commit_mutex);
}
rc = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (rc)
return rc;

posix_acl_release(clone);
tid = txBegin(inode->i_sb, 0);
mutex_lock(&JFS_IP(inode)->commit_mutex);
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
if (!rc)
rc = txCommit(tid, 1, &inode, 0);
txEnd(tid);
mutex_unlock(&JFS_IP(inode)->commit_mutex);

posix_acl_release(acl);
return rc;
}
15 changes: 6 additions & 9 deletions fs/ocfs2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ int ocfs2_check_acl(struct inode *inode, int mask)
int ocfs2_acl_chmod(struct inode *inode)
{
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
struct posix_acl *acl, *clone;
struct posix_acl *acl;
int ret;

if (S_ISLNK(inode->i_mode))
Expand All @@ -339,15 +339,12 @@ int ocfs2_acl_chmod(struct inode *inode)
acl = ocfs2_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
clone = posix_acl_clone(acl, GFP_KERNEL);
ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (ret)
return ret;
ret = ocfs2_set_acl(NULL, inode, NULL, ACL_TYPE_ACCESS,
acl, NULL, NULL);
posix_acl_release(acl);
if (!clone)
return -ENOMEM;
ret = posix_acl_chmod_masq(clone, inode->i_mode);
if (!ret)
ret = ocfs2_set_acl(NULL, inode, NULL, ACL_TYPE_ACCESS,
clone, NULL, NULL);
posix_acl_release(clone);
return ret;
}

Expand Down
Loading

0 comments on commit bc26ab5

Please sign in to comment.