Skip to content

Commit

Permalink
helpers for acl caching + switch to those
Browse files Browse the repository at this point in the history
helpers: get_cached_acl(inode, type), set_cached_acl(inode, type, acl),
forget_cached_acl(inode, type).

ubifs/xattr.c needed includes reordered, the rest is a plain switchover.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Jun 24, 2009
1 parent 06b16e9 commit 073aaa1
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 333 deletions.
44 changes: 9 additions & 35 deletions fs/btrfs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,28 @@

#ifdef CONFIG_FS_POSIX_ACL

static void btrfs_update_cached_acl(struct inode *inode,
struct posix_acl **p_acl,
struct posix_acl *acl)
{
spin_lock(&inode->i_lock);
if (*p_acl && *p_acl != ACL_NOT_CACHED)
posix_acl_release(*p_acl);
*p_acl = posix_acl_dup(acl);
spin_unlock(&inode->i_lock);
}

static struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
{
int size;
const char *name;
char *value = NULL;
struct posix_acl *acl = NULL, **p_acl;
struct posix_acl *acl;

acl = get_cached_acl(inode, type);
if (acl != ACL_NOT_CACHED)
return acl;

switch (type) {
case ACL_TYPE_ACCESS:
name = POSIX_ACL_XATTR_ACCESS;
p_acl = &inode->i_acl;
break;
case ACL_TYPE_DEFAULT:
name = POSIX_ACL_XATTR_DEFAULT;
p_acl = &inode->i_default_acl;
break;
default:
return ERR_PTR(-EINVAL);
BUG();
}

/* Handle the cached NULL acl case without locking */
acl = ACCESS_ONCE(*p_acl);
if (!acl)
return acl;

spin_lock(&inode->i_lock);
acl = *p_acl;
if (acl != ACL_NOT_CACHED)
acl = posix_acl_dup(acl);
spin_unlock(&inode->i_lock);

if (acl != ACL_NOT_CACHED)
return acl;

size = __btrfs_getxattr(inode, name, "", 0);
if (size > 0) {
value = kzalloc(size, GFP_NOFS);
Expand All @@ -82,13 +59,13 @@ static struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
size = __btrfs_getxattr(inode, name, value, size);
if (size > 0) {
acl = posix_acl_from_xattr(value, size);
btrfs_update_cached_acl(inode, p_acl, acl);
set_cached_acl(inode, type, acl);
}
kfree(value);
} else if (size == -ENOENT || size == -ENODATA || size == 0) {
/* FIXME, who returns -ENOENT? I think nobody */
acl = NULL;
btrfs_update_cached_acl(inode, p_acl, acl);
set_cached_acl(inode, type, acl);
} else {
acl = ERR_PTR(-EIO);
}
Expand Down Expand Up @@ -121,7 +98,6 @@ static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
{
int ret, size = 0;
const char *name;
struct posix_acl **p_acl;
char *value = NULL;
mode_t mode;

Expand All @@ -141,13 +117,11 @@ static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
ret = 0;
inode->i_mode = mode;
name = POSIX_ACL_XATTR_ACCESS;
p_acl = &inode->i_acl;
break;
case ACL_TYPE_DEFAULT:
if (!S_ISDIR(inode->i_mode))
return acl ? -EINVAL : 0;
name = POSIX_ACL_XATTR_DEFAULT;
p_acl = &inode->i_default_acl;
break;
default:
return -EINVAL;
Expand All @@ -172,7 +146,7 @@ static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
kfree(value);

if (!ret)
btrfs_update_cached_acl(inode, p_acl, acl);
set_cached_acl(inode, type, acl);

return ret;
}
Expand Down
79 changes: 17 additions & 62 deletions fs/ext2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,6 @@ ext2_acl_to_disk(const struct posix_acl *acl, size_t *size)
return ERR_PTR(-EINVAL);
}

static inline struct posix_acl *
ext2_iget_acl(struct inode *inode, struct posix_acl **i_acl)
{
struct posix_acl *acl = ACL_NOT_CACHED;

spin_lock(&inode->i_lock);
if (*i_acl != ACL_NOT_CACHED)
acl = posix_acl_dup(*i_acl);
spin_unlock(&inode->i_lock);

return acl;
}

static inline void
ext2_iset_acl(struct inode *inode, struct posix_acl **i_acl,
struct posix_acl *acl)
{
spin_lock(&inode->i_lock);
if (*i_acl != ACL_NOT_CACHED)
posix_acl_release(*i_acl);
*i_acl = posix_acl_dup(acl);
spin_unlock(&inode->i_lock);
}

/*
* inode->i_mutex: don't care
*/
Expand All @@ -163,23 +139,19 @@ ext2_get_acl(struct inode *inode, int type)
if (!test_opt(inode->i_sb, POSIX_ACL))
return NULL;

switch(type) {
case ACL_TYPE_ACCESS:
acl = ext2_iget_acl(inode, &inode->i_acl);
if (acl != ACL_NOT_CACHED)
return acl;
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
break;

case ACL_TYPE_DEFAULT:
acl = ext2_iget_acl(inode, &inode->i_default_acl);
if (acl != ACL_NOT_CACHED)
return acl;
name_index = EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT;
break;

default:
return ERR_PTR(-EINVAL);
acl = get_cached_acl(inode, type);
if (acl != ACL_NOT_CACHED)
return acl;

switch (type) {
case ACL_TYPE_ACCESS:
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
break;
case ACL_TYPE_DEFAULT:
name_index = EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT;
break;
default:
BUG();
}
retval = ext2_xattr_get(inode, name_index, "", NULL, 0);
if (retval > 0) {
Expand All @@ -196,17 +168,9 @@ ext2_get_acl(struct inode *inode, int type)
acl = ERR_PTR(retval);
kfree(value);

if (!IS_ERR(acl)) {
switch(type) {
case ACL_TYPE_ACCESS:
ext2_iset_acl(inode, &inode->i_acl, acl);
break;
if (!IS_ERR(acl))
set_cached_acl(inode, type, acl);

case ACL_TYPE_DEFAULT:
ext2_iset_acl(inode, &inode->i_default_acl, acl);
break;
}
}
return acl;
}

Expand Down Expand Up @@ -261,17 +225,8 @@ ext2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
error = ext2_xattr_set(inode, name_index, "", value, size, 0);

kfree(value);
if (!error) {
switch(type) {
case ACL_TYPE_ACCESS:
ext2_iset_acl(inode, &inode->i_acl, acl);
break;

case ACL_TYPE_DEFAULT:
ext2_iset_acl(inode, &inode->i_default_acl, acl);
break;
}
}
if (!error)
set_cached_acl(inode, type, acl);
return error;
}

Expand Down
83 changes: 19 additions & 64 deletions fs/ext3/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,6 @@ ext3_acl_to_disk(const struct posix_acl *acl, size_t *size)
return ERR_PTR(-EINVAL);
}

static inline struct posix_acl *
ext3_iget_acl(struct inode *inode, struct posix_acl **i_acl)
{
struct posix_acl *acl = ACCESS_ONCE(*i_acl);

if (acl) {
spin_lock(&inode->i_lock);
acl = *i_acl;
if (acl != ACL_NOT_CACHED)
acl = posix_acl_dup(acl);
spin_unlock(&inode->i_lock);
}

return acl;
}

static inline void
ext3_iset_acl(struct inode *inode, struct posix_acl **i_acl,
struct posix_acl *acl)
{
spin_lock(&inode->i_lock);
if (*i_acl != ACL_NOT_CACHED)
posix_acl_release(*i_acl);
*i_acl = posix_acl_dup(acl);
spin_unlock(&inode->i_lock);
}

/*
* Inode operation get_posix_acl().
*
Expand All @@ -169,24 +142,21 @@ ext3_get_acl(struct inode *inode, int type)
if (!test_opt(inode->i_sb, POSIX_ACL))
return NULL;

switch(type) {
case ACL_TYPE_ACCESS:
acl = ext3_iget_acl(inode, &inode->i_acl);
if (acl != ACL_NOT_CACHED)
return acl;
name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS;
break;

case ACL_TYPE_DEFAULT:
acl = ext3_iget_acl(inode, &inode->i_default_acl);
if (acl != ACL_NOT_CACHED)
return acl;
name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT;
break;

default:
return ERR_PTR(-EINVAL);
acl = get_cached_acl(inode, type);
if (acl != ACL_NOT_CACHED)
return acl;

switch (type) {
case ACL_TYPE_ACCESS:
name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS;
break;
case ACL_TYPE_DEFAULT:
name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT;
break;
default:
BUG();
}

retval = ext3_xattr_get(inode, name_index, "", NULL, 0);
if (retval > 0) {
value = kmalloc(retval, GFP_NOFS);
Expand All @@ -202,17 +172,9 @@ ext3_get_acl(struct inode *inode, int type)
acl = ERR_PTR(retval);
kfree(value);

if (!IS_ERR(acl)) {
switch(type) {
case ACL_TYPE_ACCESS:
ext3_iset_acl(inode, &inode->i_acl, acl);
break;
if (!IS_ERR(acl))
set_cached_acl(inode, type, acl);

case ACL_TYPE_DEFAULT:
ext3_iset_acl(inode, &inode->i_default_acl, acl);
break;
}
}
return acl;
}

Expand Down Expand Up @@ -269,17 +231,10 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
value, size, 0);

kfree(value);
if (!error) {
switch(type) {
case ACL_TYPE_ACCESS:
ext3_iset_acl(inode, &inode->i_acl, acl);
break;

case ACL_TYPE_DEFAULT:
ext3_iset_acl(inode, &inode->i_default_acl, acl);
break;
}
}
if (!error)
set_cached_acl(inode, type, acl);

return error;
}

Expand Down
Loading

0 comments on commit 073aaa1

Please sign in to comment.