diff options
| author | Al Viro <viro@zeniv.linux.org.uk> | 2009-06-09 12:11:54 -0400 |
|---|---|---|
| committer | Al Viro <viro@zeniv.linux.org.uk> | 2009-06-24 08:17:07 -0400 |
| commit | 073aaa1b142461d91f83da66db1184d7c1b1edea (patch) | |
| tree | 2b54d185d78f1229418fca521a93e6b55c57248b | |
| parent | 06b16e9f68edaa1e71aee943d3c030bcf7380af1 (diff) | |
helpers for acl caching + switch to those
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>
| -rw-r--r-- | fs/btrfs/acl.c | 44 | ||||
| -rw-r--r-- | fs/ext2/acl.c | 79 | ||||
| -rw-r--r-- | fs/ext3/acl.c | 83 | ||||
| -rw-r--r-- | fs/ext4/acl.c | 65 | ||||
| -rw-r--r-- | fs/jffs2/acl.c | 60 | ||||
| -rw-r--r-- | fs/jfs/acl.c | 32 | ||||
| -rw-r--r-- | fs/jfs/xattr.c | 10 | ||||
| -rw-r--r-- | fs/reiserfs/xattr_acl.c | 49 | ||||
| -rw-r--r-- | fs/ubifs/xattr.c | 2 | ||||
| -rw-r--r-- | include/linux/posix_acl.h | 64 |
10 files changed, 155 insertions, 333 deletions
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 6db8a42a3e5e..f128427b995b 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c | |||
| @@ -29,51 +29,28 @@ | |||
| 29 | 29 | ||
| 30 | #ifdef CONFIG_FS_POSIX_ACL | 30 | #ifdef CONFIG_FS_POSIX_ACL |
| 31 | 31 | ||
| 32 | static void btrfs_update_cached_acl(struct inode *inode, | ||
| 33 | struct posix_acl **p_acl, | ||
| 34 | struct posix_acl *acl) | ||
| 35 | { | ||
| 36 | spin_lock(&inode->i_lock); | ||
| 37 | if (*p_acl && *p_acl != ACL_NOT_CACHED) | ||
| 38 | posix_acl_release(*p_acl); | ||
| 39 | *p_acl = posix_acl_dup(acl); | ||
| 40 | spin_unlock(&inode->i_lock); | ||
| 41 | } | ||
| 42 | |||
| 43 | static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) | 32 | static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) |
| 44 | { | 33 | { |
| 45 | int size; | 34 | int size; |
| 46 | const char *name; | 35 | const char *name; |
| 47 | char *value = NULL; | 36 | char *value = NULL; |
| 48 | struct posix_acl *acl = NULL, **p_acl; | 37 | struct posix_acl *acl; |
| 38 | |||
| 39 | acl = get_cached_acl(inode, type); | ||
| 40 | if (acl != ACL_NOT_CACHED) | ||
| 41 | return acl; | ||
| 49 | 42 | ||
| 50 | switch (type) { | 43 | switch (type) { |
| 51 | case ACL_TYPE_ACCESS: | 44 | case ACL_TYPE_ACCESS: |
| 52 | name = POSIX_ACL_XATTR_ACCESS; | 45 | name = POSIX_ACL_XATTR_ACCESS; |
| 53 | p_acl = &inode->i_acl; | ||
| 54 | break; | 46 | break; |
| 55 | case ACL_TYPE_DEFAULT: | 47 | case ACL_TYPE_DEFAULT: |
| 56 | name = POSIX_ACL_XATTR_DEFAULT; | 48 | name = POSIX_ACL_XATTR_DEFAULT; |
| 57 | p_acl = &inode->i_default_acl; | ||
| 58 | break; | 49 | break; |
| 59 | default: | 50 | default: |
| 60 | return ERR_PTR(-EINVAL); | 51 | BUG(); |
| 61 | } | 52 | } |
| 62 | 53 | ||
| 63 | /* Handle the cached NULL acl case without locking */ | ||
| 64 | acl = ACCESS_ONCE(*p_acl); | ||
| 65 | if (!acl) | ||
| 66 | return acl; | ||
| 67 | |||
| 68 | spin_lock(&inode->i_lock); | ||
| 69 | acl = *p_acl; | ||
| 70 | if (acl != ACL_NOT_CACHED) | ||
| 71 | acl = posix_acl_dup(acl); | ||
| 72 | spin_unlock(&inode->i_lock); | ||
| 73 | |||
| 74 | if (acl != ACL_NOT_CACHED) | ||
| 75 | return acl; | ||
| 76 | |||
| 77 | size = __btrfs_getxattr(inode, name, "", 0); | 54 | size = __btrfs_getxattr(inode, name, "", 0); |
| 78 | if (size > 0) { | 55 | if (size > 0) { |
| 79 | value = kzalloc(size, GFP_NOFS); | 56 | value = kzalloc(size, GFP_NOFS); |
| @@ -82,13 +59,13 @@ static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) | |||
| 82 | size = __btrfs_getxattr(inode, name, value, size); | 59 | size = __btrfs_getxattr(inode, name, value, size); |
| 83 | if (size > 0) { | 60 | if (size > 0) { |
| 84 | acl = posix_acl_from_xattr(value, size); | 61 | acl = posix_acl_from_xattr(value, size); |
| 85 | btrfs_update_cached_acl(inode, p_acl, acl); | 62 | set_cached_acl(inode, type, acl); |
| 86 | } | 63 | } |
| 87 | kfree(value); | 64 | kfree(value); |
| 88 | } else if (size == -ENOENT || size == -ENODATA || size == 0) { | 65 | } else if (size == -ENOENT || size == -ENODATA || size == 0) { |
| 89 | /* FIXME, who returns -ENOENT? I think nobody */ | 66 | /* FIXME, who returns -ENOENT? I think nobody */ |
| 90 | acl = NULL; | 67 | acl = NULL; |
| 91 | btrfs_update_cached_acl(inode, p_acl, acl); | 68 | set_cached_acl(inode, type, acl); |
| 92 | } else { | 69 | } else { |
| 93 | acl = ERR_PTR(-EIO); | 70 | acl = ERR_PTR(-EIO); |
| 94 | } | 71 | } |
| @@ -121,7 +98,6 @@ static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |||
| 121 | { | 98 | { |
| 122 | int ret, size = 0; | 99 | int ret, size = 0; |
| 123 | const char *name; | 100 | const char *name; |
| 124 | struct posix_acl **p_acl; | ||
| 125 | char *value = NULL; | 101 | char *value = NULL; |
| 126 | mode_t mode; | 102 | mode_t mode; |
| 127 | 103 | ||
| @@ -141,13 +117,11 @@ static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |||
| 141 | ret = 0; | 117 | ret = 0; |
| 142 | inode->i_mode = mode; | 118 | inode->i_mode = mode; |
| 143 | name = POSIX_ACL_XATTR_ACCESS; | 119 | name = POSIX_ACL_XATTR_ACCESS; |
| 144 | p_acl = &inode->i_acl; | ||
| 145 | break; | 120 | break; |
| 146 | case ACL_TYPE_DEFAULT: | 121 | case ACL_TYPE_DEFAULT: |
| 147 | if (!S_ISDIR(inode->i_mode)) | 122 | if (!S_ISDIR(inode->i_mode)) |
| 148 | return acl ? -EINVAL : 0; | 123 | return acl ? -EINVAL : 0; |
| 149 | name = POSIX_ACL_XATTR_DEFAULT; | 124 | name = POSIX_ACL_XATTR_DEFAULT; |
| 150 | p_acl = &inode->i_default_acl; | ||
| 151 | break; | 125 | break; |
| 152 | default: | 126 | default: |
| 153 | return -EINVAL; | 127 | return -EINVAL; |
| @@ -172,7 +146,7 @@ out: | |||
| 172 | kfree(value); | 146 | kfree(value); |
| 173 | 147 | ||
| 174 | if (!ret) | 148 | if (!ret) |
| 175 | btrfs_update_cached_acl(inode, p_acl, acl); | 149 | set_cached_acl(inode, type, acl); |
| 176 | 150 | ||
| 177 | return ret; | 151 | return ret; |
| 178 | } | 152 | } |
diff --git a/fs/ext2/acl.c b/fs/ext2/acl.c index d2ffddc12117..d636e1297cad 100644 --- a/fs/ext2/acl.c +++ b/fs/ext2/acl.c | |||
| @@ -125,30 +125,6 @@ fail: | |||
| 125 | return ERR_PTR(-EINVAL); | 125 | return ERR_PTR(-EINVAL); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | static inline struct posix_acl * | ||
| 129 | ext2_iget_acl(struct inode *inode, struct posix_acl **i_acl) | ||
| 130 | { | ||
| 131 | struct posix_acl *acl = ACL_NOT_CACHED; | ||
| 132 | |||
| 133 | spin_lock(&inode->i_lock); | ||
| 134 | if (*i_acl != ACL_NOT_CACHED) | ||
| 135 | acl = posix_acl_dup(*i_acl); | ||
| 136 | spin_unlock(&inode->i_lock); | ||
| 137 | |||
| 138 | return acl; | ||
| 139 | } | ||
| 140 | |||
| 141 | static inline void | ||
| 142 | ext2_iset_acl(struct inode *inode, struct posix_acl **i_acl, | ||
| 143 | struct posix_acl *acl) | ||
| 144 | { | ||
| 145 | spin_lock(&inode->i_lock); | ||
| 146 | if (*i_acl != ACL_NOT_CACHED) | ||
| 147 | posix_acl_release(*i_acl); | ||
| 148 | *i_acl = posix_acl_dup(acl); | ||
| 149 | spin_unlock(&inode->i_lock); | ||
| 150 | } | ||
| 151 | |||
| 152 | /* | 128 | /* |
| 153 | * inode->i_mutex: don't care | 129 | * inode->i_mutex: don't care |
| 154 | */ | 130 | */ |
| @@ -163,23 +139,19 @@ ext2_get_acl(struct inode *inode, int type) | |||
| 163 | if (!test_opt(inode->i_sb, POSIX_ACL)) | 139 | if (!test_opt(inode->i_sb, POSIX_ACL)) |
| 164 | return NULL; | 140 | return NULL; |
| 165 | 141 | ||
| 166 | switch(type) { | 142 | acl = get_cached_acl(inode, type); |
| 167 | case ACL_TYPE_ACCESS: | 143 | if (acl != ACL_NOT_CACHED) |
| 168 | acl = ext2_iget_acl(inode, &inode->i_acl); | 144 | return acl; |
| 169 | if (acl != ACL_NOT_CACHED) | 145 | |
| 170 | return acl; | 146 | switch (type) { |
| 171 | name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS; | 147 | case ACL_TYPE_ACCESS: |
| 172 | break; | 148 | name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS; |
| 173 | 149 | break; | |
| 174 | case ACL_TYPE_DEFAULT: | 150 | case ACL_TYPE_DEFAULT: |
| 175 | acl = ext2_iget_acl(inode, &inode->i_default_acl); | 151 | name_index = EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT; |
| 176 | if (acl != ACL_NOT_CACHED) | 152 | break; |
| 177 | return acl; | 153 | default: |
| 178 | name_index = EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT; | 154 | BUG(); |
| 179 | break; | ||
| 180 | |||
