Skip to content

Commit 073aaa1

Browse files
author
Al Viro
committed
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>
1 parent 06b16e9 commit 073aaa1

10 files changed

Lines changed: 155 additions & 333 deletions

File tree

‎fs/btrfs/acl.c‎

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,51 +29,28 @@
2929

3030
#ifdef CONFIG_FS_POSIX_ACL
3131

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-
4332
static struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
4433
{
4534
int size;
4635
const char *name;
4736
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;
4942

5043
switch (type) {
5144
case ACL_TYPE_ACCESS:
5245
name = POSIX_ACL_XATTR_ACCESS;
53-
p_acl = &inode->i_acl;
5446
break;
5547
case ACL_TYPE_DEFAULT:
5648
name = POSIX_ACL_XATTR_DEFAULT;
57-
p_acl = &inode->i_default_acl;
5849
break;
5950
default:
60-
return ERR_PTR(-EINVAL);
51+
BUG();
6152
}
6253

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-
7754
size = __btrfs_getxattr(inode, name, "", 0);
7855
if (size > 0) {
7956
value = kzalloc(size, GFP_NOFS);
@@ -82,13 +59,13 @@ static struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
8259
size = __btrfs_getxattr(inode, name, value, size);
8360
if (size > 0) {
8461
acl = posix_acl_from_xattr(value, size);
85-
btrfs_update_cached_acl(inode, p_acl, acl);
62+
set_cached_acl(inode, type, acl);
8663
}
8764
kfree(value);
8865
} else if (size == -ENOENT || size == -ENODATA || size == 0) {
8966
/* FIXME, who returns -ENOENT? I think nobody */
9067
acl = NULL;
91-
btrfs_update_cached_acl(inode, p_acl, acl);
68+
set_cached_acl(inode, type, acl);
9269
} else {
9370
acl = ERR_PTR(-EIO);
9471
}
@@ -121,7 +98,6 @@ static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
12198
{
12299
int ret, size = 0;
123100
const char *name;
124-
struct posix_acl **p_acl;
125101
char *value = NULL;
126102
mode_t mode;
127103

@@ -141,13 +117,11 @@ static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
141117
ret = 0;
142118
inode->i_mode = mode;
143119
name = POSIX_ACL_XATTR_ACCESS;
144-
p_acl = &inode->i_acl;
145120
break;
146121
case ACL_TYPE_DEFAULT:
147122
if (!S_ISDIR(inode->i_mode))
148123
return acl ? -EINVAL : 0;
149124
name = POSIX_ACL_XATTR_DEFAULT;
150-
p_acl = &inode->i_default_acl;
151125
break;
152126
default:
153127
return -EINVAL;
@@ -172,7 +146,7 @@ static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
172146
kfree(value);
173147

174148
if (!ret)
175-
btrfs_update_cached_acl(inode, p_acl, acl);
149+
set_cached_acl(inode, type, acl);
176150

177151
return ret;
178152
}

‎fs/ext2/acl.c‎

Lines changed: 17 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,6 @@ ext2_acl_to_disk(const struct posix_acl *acl, size_t *size)
125125
return ERR_PTR(-EINVAL);
126126
}
127127

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-
152128
/*
153129
* inode->i_mutex: don't care
154130
*/
@@ -163,23 +139,19 @@ ext2_get_acl(struct inode *inode, int type)
163139
if (!test_opt(inode->i_sb, POSIX_ACL))
164140
return NULL;
165141

166-
switch(type) {
167-
case ACL_TYPE_ACCESS:
168-
acl = ext2_iget_acl(inode, &inode->i_acl);
169-
if (acl != ACL_NOT_CACHED)
170-
return acl;
171-
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
172-
break;
173-
174-
case ACL_TYPE_DEFAULT:
175-
acl = ext2_iget_acl(inode, &inode->i_default_acl);
176-
if (acl != ACL_NOT_CACHED)
177-
return acl;
178-
name_index = EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT;
179-
break;
180-
181-
default:
182-
return ERR_PTR(-EINVAL);
142+
acl = get_cached_acl(inode, type);
143+
if (acl != ACL_NOT_CACHED)
144+
return acl;
145+
146+
switch (type) {
147+
case ACL_TYPE_ACCESS:
148+
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
149+
break;
150+
case ACL_TYPE_DEFAULT:
151+
name_index = EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT;
152+
break;
153+
default:
154+
BUG();
183155
}
184156
retval = ext2_xattr_get(inode, name_index, "", NULL, 0);
185157
if (retval > 0) {
@@ -196,17 +168,9 @@ ext2_get_acl(struct inode *inode, int type)
196168
acl = ERR_PTR(retval);
197169
kfree(value);
198170

199-
if (!IS_ERR(acl)) {
200-
switch(type) {
201-
case ACL_TYPE_ACCESS:
202-
ext2_iset_acl(inode, &inode->i_acl, acl);
203-
break;
171+
if (!IS_ERR(acl))
172+
set_cached_acl(inode, type, acl);
204173

205-
case ACL_TYPE_DEFAULT:
206-
ext2_iset_acl(inode, &inode->i_default_acl, acl);
207-
break;
208-
}
209-
}
210174
return acl;
211175
}
212176

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

263227
kfree(value);
264-
if (!error) {
265-
switch(type) {
266-
case ACL_TYPE_ACCESS:
267-
ext2_iset_acl(inode, &inode->i_acl, acl);
268-
break;
269-
270-
case ACL_TYPE_DEFAULT:
271-
ext2_iset_acl(inode, &inode->i_default_acl, acl);
272-
break;
273-
}
274-
}
228+
if (!error)
229+
set_cached_acl(inode, type, acl);
275230
return error;
276231
}
277232

‎fs/ext3/acl.c‎

Lines changed: 19 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -126,33 +126,6 @@ ext3_acl_to_disk(const struct posix_acl *acl, size_t *size)
126126
return ERR_PTR(-EINVAL);
127127
}
128128

129-
static inline struct posix_acl *
130-
ext3_iget_acl(struct inode *inode, struct posix_acl **i_acl)
131-
{
132-
struct posix_acl *acl = ACCESS_ONCE(*i_acl);
133-
134-
if (acl) {
135-
spin_lock(&inode->i_lock);
136-
acl = *i_acl;
137-
if (acl != ACL_NOT_CACHED)
138-
acl = posix_acl_dup(acl);
139-
spin_unlock(&inode->i_lock);
140-
}
141-
142-
return acl;
143-
}
144-
145-
static inline void
146-
ext3_iset_acl(struct inode *inode, struct posix_acl **i_acl,
147-
struct posix_acl *acl)
148-
{
149-
spin_lock(&inode->i_lock);
150-
if (*i_acl != ACL_NOT_CACHED)
151-
posix_acl_release(*i_acl);
152-
*i_acl = posix_acl_dup(acl);
153-
spin_unlock(&inode->i_lock);
154-
}
155-
156129
/*
157130
* Inode operation get_posix_acl().
158131
*
@@ -169,24 +142,21 @@ ext3_get_acl(struct inode *inode, int type)
169142
if (!test_opt(inode->i_sb, POSIX_ACL))
170143
return NULL;
171144

172-
switch(type) {
173-
case ACL_TYPE_ACCESS:
174-
acl = ext3_iget_acl(inode, &inode->i_acl);
175-
if (acl != ACL_NOT_CACHED)
176-
return acl;
177-
name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS;
178-
break;
179-
180-
case ACL_TYPE_DEFAULT:
181-
acl = ext3_iget_acl(inode, &inode->i_default_acl);
182-
if (acl != ACL_NOT_CACHED)
183-
return acl;
184-
name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT;
185-
break;
186-
187-
default:
188-
return ERR_PTR(-EINVAL);
145+
acl = get_cached_acl(inode, type);
146+
if (acl != ACL_NOT_CACHED)
147+
return acl;
148+
149+
switch (type) {
150+
case ACL_TYPE_ACCESS:
151+
name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS;
152+
break;
153+
case ACL_TYPE_DEFAULT:
154+
name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT;
155+
break;
156+
default:
157+
BUG();
189158
}
159+
190160
retval = ext3_xattr_get(inode, name_index, "", NULL, 0);
191161
if (retval > 0) {
192162
value = kmalloc(retval, GFP_NOFS);
@@ -202,17 +172,9 @@ ext3_get_acl(struct inode *inode, int type)
202172
acl = ERR_PTR(retval);
203173
kfree(value);
204174

205-
if (!IS_ERR(acl)) {
206-
switch(type) {
207-
case ACL_TYPE_ACCESS:
208-
ext3_iset_acl(inode, &inode->i_acl, acl);
209-
break;
175+
if (!IS_ERR(acl))
176+
set_cached_acl(inode, type, acl);
210177

211-
case ACL_TYPE_DEFAULT:
212-
ext3_iset_acl(inode, &inode->i_default_acl, acl);
213-
break;
214-
}
215-
}
216178
return acl;
217179
}
218180

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

271233
kfree(value);
272-
if (!error) {
273-
switch(type) {
274-
case ACL_TYPE_ACCESS:
275-
ext3_iset_acl(inode, &inode->i_acl, acl);
276-
break;
277234

278-
case ACL_TYPE_DEFAULT:
279-
ext3_iset_acl(inode, &inode->i_default_acl, acl);
280-
break;
281-
}
282-
}
235+
if (!error)
236+
set_cached_acl(inode, type, acl);
237+
283238
return error;
284239
}
285240

0 commit comments

Comments
 (0)