Skip to content

Commit e77819e

Browse files
torvaldsAl Viro
authored andcommitted
vfs: move ACL cache lookup into generic code
This moves logic for checking the cached ACL values from low-level filesystems into generic code. The end result is a streamlined ACL check that doesn't need to load the inode->i_op->check_acl pointer at all for the common cached case. The filesystems also don't need to check for a non-blocking RCU walk case in their acl_check() functions, because that is all handled at a VFS layer. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 3ca30d4 commit e77819e

12 files changed

Lines changed: 65 additions & 69 deletions

File tree

‎fs/9p/acl.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ int v9fs_check_acl(struct inode *inode, int mask)
101101
struct posix_acl *acl;
102102
struct v9fs_session_info *v9ses;
103103

104-
if (mask & MAY_NOT_BLOCK)
105-
return -ECHILD;
106-
107104
v9ses = v9fs_inode2v9ses(inode);
108105
if (((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) ||
109106
((v9ses->flags & V9FS_ACL_MASK) != V9FS_POSIX_ACL)) {

‎fs/btrfs/acl.c‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,14 @@ static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name,
198198
int btrfs_check_acl(struct inode *inode, int mask)
199199
{
200200
int error = -EAGAIN;
201+
struct posix_acl *acl;
201202

202-
if (mask & MAY_NOT_BLOCK) {
203-
if (!negative_cached_acl(inode, ACL_TYPE_ACCESS))
204-
error = -ECHILD;
205-
} else {
206-
struct posix_acl *acl;
207-
acl = btrfs_get_acl(inode, ACL_TYPE_ACCESS);
208-
if (IS_ERR(acl))
209-
return PTR_ERR(acl);
210-
if (acl) {
211-
error = posix_acl_permission(inode, acl, mask);
212-
posix_acl_release(acl);
213-
}
203+
acl = btrfs_get_acl(inode, ACL_TYPE_ACCESS);
204+
if (IS_ERR(acl))
205+
return PTR_ERR(acl);
206+
if (acl) {
207+
error = posix_acl_permission(inode, acl, mask);
208+
posix_acl_release(acl);
214209
}
215210

216211
return error;

‎fs/ext2/acl.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,6 @@ ext2_check_acl(struct inode *inode, int mask)
236236
{
237237
struct posix_acl *acl;
238238

239-
if (mask & MAY_NOT_BLOCK) {
240-
if (!negative_cached_acl(inode, ACL_TYPE_ACCESS))
241-
return -ECHILD;
242-
return -EAGAIN;
243-
}
244-
245239
acl = ext2_get_acl(inode, ACL_TYPE_ACCESS);
246240
if (IS_ERR(acl))
247241
return PTR_ERR(acl);

‎fs/ext3/acl.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,6 @@ ext3_check_acl(struct inode *inode, int mask)
244244
{
245245
struct posix_acl *acl;
246246

247-
if (mask & MAY_NOT_BLOCK) {
248-
if (!negative_cached_acl(inode, ACL_TYPE_ACCESS))
249-
return -ECHILD;
250-
return -EAGAIN;
251-
}
252-
253247
acl = ext3_get_acl(inode, ACL_TYPE_ACCESS);
254248
if (IS_ERR(acl))
255249
return PTR_ERR(acl);

‎fs/ext4/acl.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,6 @@ ext4_check_acl(struct inode *inode, int mask)
242242
{
243243
struct posix_acl *acl;
244244

245-
if (mask & MAY_NOT_BLOCK) {
246-
if (!negative_cached_acl(inode, ACL_TYPE_ACCESS))
247-
return -ECHILD;
248-
return -EAGAIN;
249-
}
250-
251245
acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
252246
if (IS_ERR(acl))
253247
return PTR_ERR(acl);

‎fs/generic_acl.c‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,13 @@ generic_acl_chmod(struct inode *inode)
192192
int
193193
generic_check_acl(struct inode *inode, int mask)
194194
{
195-
if (mask & MAY_NOT_BLOCK) {
196-
if (!negative_cached_acl(inode, ACL_TYPE_ACCESS))
197-
return -ECHILD;
198-
} else {
199-
struct posix_acl *acl;
200-
201-
acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
202-
if (acl) {
203-
int error = posix_acl_permission(inode, acl, mask);
204-
posix_acl_release(acl);
205-
return error;
206-
}
195+
struct posix_acl *acl;
196+
197+
acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
198+
if (acl) {
199+
int error = posix_acl_permission(inode, acl, mask);
200+
posix_acl_release(acl);
201+
return error;
207202
}
208203
return -EAGAIN;
209204
}

‎fs/gfs2/acl.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ int gfs2_check_acl(struct inode *inode, int mask)
8080
struct posix_acl *acl;
8181
int error;
8282

83-
if (mask & MAY_NOT_BLOCK) {
84-
if (!negative_cached_acl(inode, ACL_TYPE_ACCESS))
85-
return -ECHILD;
86-
return -EAGAIN;
87-
}
88-
8983
acl = gfs2_acl_get(GFS2_I(inode), ACL_TYPE_ACCESS);
9084
if (IS_ERR(acl))
9185
return PTR_ERR(acl);

‎fs/jffs2/acl.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ int jffs2_check_acl(struct inode *inode, int mask)
264264
struct posix_acl *acl;
265265
int rc;
266266

267-
if (mask & MAY_NOT_BLOCK)
268-
return -ECHILD;
269-
270267
acl = jffs2_get_acl(inode, ACL_TYPE_ACCESS);
271268
if (IS_ERR(acl))
272269
return PTR_ERR(acl);

‎fs/jfs/acl.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ int jfs_check_acl(struct inode *inode, int mask)
118118
{
119119
struct posix_acl *acl;
120120

121-
if (mask & MAY_NOT_BLOCK)
122-
return -ECHILD;
123-
124121
acl = jfs_get_acl(inode, ACL_TYPE_ACCESS);
125122
if (IS_ERR(acl))
126123
return PTR_ERR(acl);

‎fs/namei.c‎

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/fcntl.h>
3333
#include <linux/device_cgroup.h>
3434
#include <linux/fs_struct.h>
35+
#include <linux/posix_acl.h>
3536
#include <asm/uaccess.h>
3637

3738
#include "internal.h"
@@ -173,12 +174,58 @@ void putname(const char *name)
173174
EXPORT_SYMBOL(putname);
174175
#endif
175176

177+
static int check_acl(struct inode *inode, int mask)
178+
{
179+
struct posix_acl *acl;
180+
181+
/*
182+
* Under RCU walk, we cannot even do a "get_cached_acl()",
183+
* because that involves locking and getting a refcount on
184+
* a cached ACL.
185+
*
186+
* So the only case we handle during RCU walking is the
187+
* case of a cached "no ACL at all", which needs no locks
188+
* or refcounts.
189+
*/
190+
if (mask & MAY_NOT_BLOCK) {
191+
if (negative_cached_acl(inode, ACL_TYPE_ACCESS))
192+
return -EAGAIN;
193+
return -ECHILD;
194+
}
195+
196+
acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
197+
198+
/*
199+
* A filesystem can force a ACL callback by just never
200+
* filling the ACL cache. But normally you'd fill the
201+
* cache either at inode instantiation time, or on the
202+
* first ->check_acl call.
203+
*
204+
* If the filesystem doesn't have a check_acl() function
205+
* at all, we'll just create the negative cache entry.
206+
*/
207+
if (acl == ACL_NOT_CACHED) {
208+
if (inode->i_op->check_acl)
209+
return inode->i_op->check_acl(inode, mask);
210+
211+
set_cached_acl(inode, ACL_TYPE_ACCESS, NULL);
212+
return -EAGAIN;
213+
}
214+
215+
if (acl) {
216+
int error = posix_acl_permission(inode, acl, mask);
217+
posix_acl_release(acl);
218+
return error;
219+
}
220+
221+
return -EAGAIN;
222+
}
223+
176224
/*
177225
* This does basic POSIX ACL permission checking
178226
*/
179227
static int acl_permission_check(struct inode *inode, int mask)
180228
{
181-
int (*check_acl)(struct inode *inode, int mask);
182229
unsigned int mode = inode->i_mode;
183230

184231
mask &= MAY_READ | MAY_WRITE | MAY_EXEC | MAY_NOT_BLOCK;
@@ -189,8 +236,7 @@ static int acl_permission_check(struct inode *inode, int mask)
189236
if (current_fsuid() == inode->i_uid)
190237
mode >>= 6;
191238
else {
192-
check_acl = inode->i_op->check_acl;
193-
if (IS_POSIXACL(inode) && (mode & S_IRWXG) && check_acl) {
239+
if (IS_POSIXACL(inode) && (mode & S_IRWXG)) {
194240
int error = check_acl(inode, mask);
195241
if (error != -EAGAIN)
196242
return error;

0 commit comments

Comments
 (0)