]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
Btrfs: fix acl caching
authorChris Mason <chris.mason@oracle.com>
Mon, 27 Apr 2009 14:49:53 +0000 (10:49 -0400)
committerChris Mason <chris.mason@oracle.com>
Mon, 27 Apr 2009 17:18:26 +0000 (13:18 -0400)
Linus noticed the btrfs code to cache acls wasn't properly caching
a NULL acl when the inode didn't have any acls.  This meant the common
case of no acls resulted in expensive btree searches every time the
kernel checked permissions (which is quite often).

This is a modified version of Linus' original patch:

Properly set initial acl fields to BTRFS_ACL_NOT_CACHED in the inode.
This forces an acl lookup when permission checks are done.

Fix btrfs_get_acl to avoid lookups and locking when the inode acls fields
are set to null.

Fix btrfs_get_acl to use the right return value from __btrfs_getxattr
when deciding to cache a NULL acl.  It was storing a NULL acl when
__btrfs_getxattr return -ENOENT, but __btrfs_getxattr was actually returning
-ENODATA for this case.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/acl.c
fs/btrfs/inode.c

index 7fdd184a528d11caa58ddb37f8d59d07de17a517..cbba000dccbea147bb37cf85dd0ad688ec379238 100644 (file)
@@ -60,15 +60,20 @@ static struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
                return ERR_PTR(-EINVAL);
        }
 
+       /* Handle the cached NULL acl case without locking */
+       acl = ACCESS_ONCE(*p_acl);
+       if (!acl)
+               return acl;
+
        spin_lock(&inode->i_lock);
-       if (*p_acl != BTRFS_ACL_NOT_CACHED)
-               acl = posix_acl_dup(*p_acl);
+       acl = *p_acl;
+       if (acl != BTRFS_ACL_NOT_CACHED)
+               acl = posix_acl_dup(acl);
        spin_unlock(&inode->i_lock);
 
-       if (acl)
+       if (acl != BTRFS_ACL_NOT_CACHED)
                return acl;
 
-
        size = __btrfs_getxattr(inode, name, "", 0);
        if (size > 0) {
                value = kzalloc(size, GFP_NOFS);
@@ -80,9 +85,12 @@ static struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
                        btrfs_update_cached_acl(inode, p_acl, acl);
                }
                kfree(value);
-       } else if (size == -ENOENT) {
+       } 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);
+       } else {
+               acl = ERR_PTR(-EIO);
        }
 
        return acl;
index 98bd5069d54ad3f72d97ed83e6755623bdbf28a2..dc812ec551f6b57756f7634643518b10be3a372d 100644 (file)
@@ -3047,8 +3047,8 @@ static noinline void init_btrfs_i(struct inode *inode)
 {
        struct btrfs_inode *bi = BTRFS_I(inode);
 
-       bi->i_acl = NULL;
-       bi->i_default_acl = NULL;
+       bi->i_acl = BTRFS_ACL_NOT_CACHED;
+       bi->i_default_acl = BTRFS_ACL_NOT_CACHED;
 
        bi->generation = 0;
        bi->sequence = 0;