Staging: hv: Fix null pointer error after vmbus loading
[safe/jmp/linux-2.6] / fs / ext4 / acl.c
index d143489..0df88b2 100644 (file)
@@ -9,8 +9,8 @@
 #include <linux/slab.h>
 #include <linux/capability.h>
 #include <linux/fs.h>
-#include <linux/ext4_jbd.h>
-#include <linux/ext4_fs.h>
+#include "ext4_jbd2.h"
+#include "ext4.h"
 #include "xattr.h"
 #include "acl.h"
 
@@ -37,37 +37,38 @@ ext4_acl_from_disk(const void *value, size_t size)
                return ERR_PTR(-EINVAL);
        if (count == 0)
                return NULL;
-       acl = posix_acl_alloc(count, GFP_KERNEL);
+       acl = posix_acl_alloc(count, GFP_NOFS);
        if (!acl)
                return ERR_PTR(-ENOMEM);
-       for (n=0; n < count; n++) {
+       for (n = 0; n < count; n++) {
                ext4_acl_entry *entry =
                        (ext4_acl_entry *)value;
                if ((char *)value + sizeof(ext4_acl_entry_short) > end)
                        goto fail;
                acl->a_entries[n].e_tag  = le16_to_cpu(entry->e_tag);
                acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
-               switch(acl->a_entries[n].e_tag) {
-                       case ACL_USER_OBJ:
-                       case ACL_GROUP_OBJ:
-                       case ACL_MASK:
-                       case ACL_OTHER:
-                               value = (char *)value +
-                                       sizeof(ext4_acl_entry_short);
-                               acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
-                               break;
-
-                       case ACL_USER:
-                       case ACL_GROUP:
-                               value = (char *)value + sizeof(ext4_acl_entry);
-                               if ((char *)value > end)
-                                       goto fail;
-                               acl->a_entries[n].e_id =
-                                       le32_to_cpu(entry->e_id);
-                               break;
-
-                       default:
+
+               switch (acl->a_entries[n].e_tag) {
+               case ACL_USER_OBJ:
+               case ACL_GROUP_OBJ:
+               case ACL_MASK:
+               case ACL_OTHER:
+                       value = (char *)value +
+                               sizeof(ext4_acl_entry_short);
+                       acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
+                       break;
+
+               case ACL_USER:
+               case ACL_GROUP:
+                       value = (char *)value + sizeof(ext4_acl_entry);
+                       if ((char *)value > end)
                                goto fail;
+                       acl->a_entries[n].e_id =
+                               le32_to_cpu(entry->e_id);
+                       break;
+
+               default:
+                       goto fail;
                }
        }
        if (value != end)
@@ -91,32 +92,31 @@ ext4_acl_to_disk(const struct posix_acl *acl, size_t *size)
 
        *size = ext4_acl_size(acl->a_count);
        ext_acl = kmalloc(sizeof(ext4_acl_header) + acl->a_count *
-                       sizeof(ext4_acl_entry), GFP_KERNEL);
+                       sizeof(ext4_acl_entry), GFP_NOFS);
        if (!ext_acl)
                return ERR_PTR(-ENOMEM);
        ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION);
        e = (char *)ext_acl + sizeof(ext4_acl_header);
-       for (n=0; n < acl->a_count; n++) {
+       for (n = 0; n < acl->a_count; n++) {
                ext4_acl_entry *entry = (ext4_acl_entry *)e;
                entry->e_tag  = cpu_to_le16(acl->a_entries[n].e_tag);
                entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
-               switch(acl->a_entries[n].e_tag) {
-                       case ACL_USER:
-                       case ACL_GROUP:
-                               entry->e_id =
-                                       cpu_to_le32(acl->a_entries[n].e_id);
-                               e += sizeof(ext4_acl_entry);
-                               break;
-
-                       case ACL_USER_OBJ:
-                       case ACL_GROUP_OBJ:
-                       case ACL_MASK:
-                       case ACL_OTHER:
-                               e += sizeof(ext4_acl_entry_short);
-                               break;
-
-                       default:
-                               goto fail;
+               switch (acl->a_entries[n].e_tag) {
+               case ACL_USER:
+               case ACL_GROUP:
+                       entry->e_id = cpu_to_le32(acl->a_entries[n].e_id);
+                       e += sizeof(ext4_acl_entry);
+                       break;
+
+               case ACL_USER_OBJ:
+               case ACL_GROUP_OBJ:
+               case ACL_MASK:
+               case ACL_OTHER:
+                       e += sizeof(ext4_acl_entry_short);
+                       break;
+
+               default:
+                       goto fail;
                }
        }
        return (char *)ext_acl;
@@ -126,30 +126,6 @@ fail:
        return ERR_PTR(-EINVAL);
 }
 
-static inline struct posix_acl *
-ext4_iget_acl(struct inode *inode, struct posix_acl **i_acl)
-{
-       struct posix_acl *acl = EXT4_ACL_NOT_CACHED;
-
-       spin_lock(&inode->i_lock);
-       if (*i_acl != EXT4_ACL_NOT_CACHED)
-               acl = posix_acl_dup(*i_acl);
-       spin_unlock(&inode->i_lock);
-
-       return acl;
-}
-
-static inline void
-ext4_iset_acl(struct inode *inode, struct posix_acl **i_acl,
-                  struct posix_acl *acl)
-{
-       spin_lock(&inode->i_lock);
-       if (*i_acl != EXT4_ACL_NOT_CACHED)
-               posix_acl_release(*i_acl);
-       *i_acl = posix_acl_dup(acl);
-       spin_unlock(&inode->i_lock);
-}
-
 /*
  * Inode operation get_posix_acl().
  *
@@ -158,7 +134,6 @@ ext4_iset_acl(struct inode *inode, struct posix_acl **i_acl,
 static struct posix_acl *
 ext4_get_acl(struct inode *inode, int type)
 {
-       struct ext4_inode_info *ei = EXT4_I(inode);
        int name_index;
        char *value = NULL;
        struct posix_acl *acl;
@@ -167,27 +142,23 @@ ext4_get_acl(struct inode *inode, int type)
        if (!test_opt(inode->i_sb, POSIX_ACL))
                return NULL;
 
-       switch(type) {
-               case ACL_TYPE_ACCESS:
-                       acl = ext4_iget_acl(inode, &ei->i_acl);
-                       if (acl != EXT4_ACL_NOT_CACHED)
-                               return acl;
-                       name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
-                       break;
-
-               case ACL_TYPE_DEFAULT:
-                       acl = ext4_iget_acl(inode, &ei->i_default_acl);
-                       if (acl != EXT4_ACL_NOT_CACHED)
-                               return acl;
-                       name_index = EXT4_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 = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
+               break;
+       case ACL_TYPE_DEFAULT:
+               name_index = EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT;
+               break;
+       default:
+               BUG();
        }
        retval = ext4_xattr_get(inode, name_index, "", NULL, 0);
        if (retval > 0) {
-               value = kmalloc(retval, GFP_KERNEL);
+               value = kmalloc(retval, GFP_NOFS);
                if (!value)
                        return ERR_PTR(-ENOMEM);
                retval = ext4_xattr_get(inode, name_index, "", value, retval);
@@ -200,17 +171,9 @@ ext4_get_acl(struct inode *inode, int type)
                acl = ERR_PTR(retval);
        kfree(value);
 
-       if (!IS_ERR(acl)) {
-               switch(type) {
-                       case ACL_TYPE_ACCESS:
-                               ext4_iset_acl(inode, &ei->i_acl, acl);
-                               break;
+       if (!IS_ERR(acl))
+               set_cached_acl(inode, type, acl);
 
-                       case ACL_TYPE_DEFAULT:
-                               ext4_iset_acl(inode, &ei->i_default_acl, acl);
-                               break;
-               }
-       }
        return acl;
 }
 
@@ -223,7 +186,6 @@ static int
 ext4_set_acl(handle_t *handle, struct inode *inode, int type,
             struct posix_acl *acl)
 {
-       struct ext4_inode_info *ei = EXT4_I(inode);
        int name_index;
        void *value = NULL;
        size_t size = 0;
@@ -232,31 +194,31 @@ ext4_set_acl(handle_t *handle, struct inode *inode, int type,
        if (S_ISLNK(inode->i_mode))
                return -EOPNOTSUPP;
 
-       switch(type) {
-               case ACL_TYPE_ACCESS:
-                       name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
-                       if (acl) {
-                               mode_t mode = inode->i_mode;
-                               error = posix_acl_equiv_mode(acl, &mode);
-                               if (error < 0)
-                                       return error;
-                               else {
-                                       inode->i_mode = mode;
-                                       ext4_mark_inode_dirty(handle, inode);
-                                       if (error == 0)
-                                               acl = NULL;
-                               }
+       switch (type) {
+       case ACL_TYPE_ACCESS:
+               name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
+               if (acl) {
+                       mode_t mode = inode->i_mode;
+                       error = posix_acl_equiv_mode(acl, &mode);
+                       if (error < 0)
+                               return error;
+                       else {
+                               inode->i_mode = mode;
+                               ext4_mark_inode_dirty(handle, inode);
+                               if (error == 0)
+                                       acl = NULL;
                        }
-                       break;
+               }
+               break;
 
-               case ACL_TYPE_DEFAULT:
-                       name_index = EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT;
-                       if (!S_ISDIR(inode->i_mode))
-                               return acl ? -EACCES : 0;
-                       break;
+       case ACL_TYPE_DEFAULT:
+               name_index = EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT;
+               if (!S_ISDIR(inode->i_mode))
+                       return acl ? -EACCES : 0;
+               break;
 
-               default:
-                       return -EINVAL;
+       default:
+               return -EINVAL;
        }
        if (acl) {
                value = ext4_acl_to_disk(acl, &size);
@@ -268,21 +230,13 @@ ext4_set_acl(handle_t *handle, struct inode *inode, int type,
                                      value, size, 0);
 
        kfree(value);
-       if (!error) {
-               switch(type) {
-                       case ACL_TYPE_ACCESS:
-                               ext4_iset_acl(inode, &ei->i_acl, acl);
-                               break;
-
-                       case ACL_TYPE_DEFAULT:
-                               ext4_iset_acl(inode, &ei->i_default_acl, acl);
-                               break;
-               }
-       }
+       if (!error)
+               set_cached_acl(inode, type, acl);
+
        return error;
 }
 
-static int
+int
 ext4_check_acl(struct inode *inode, int mask)
 {
        struct posix_acl *acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
@@ -298,12 +252,6 @@ ext4_check_acl(struct inode *inode, int mask)
        return -EAGAIN;
 }
 
-int
-ext4_permission(struct inode *inode, int mask, struct nameidata *nd)
-{
-       return generic_permission(inode, mask, ext4_check_acl);
-}
-
 /*
  * Initialize the ACLs of a new inode. Called from ext4_new_inode.
  *
@@ -323,7 +271,7 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
                                return PTR_ERR(acl);
                }
                if (!acl)
-                       inode->i_mode &= ~current->fs->umask;
+                       inode->i_mode &= ~current_umask();
        }
        if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
                struct posix_acl *clone;
@@ -335,7 +283,7 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
                        if (error)
                                goto cleanup;
                }
-               clone = posix_acl_clone(acl, GFP_KERNEL);
+               clone = posix_acl_clone(acl, GFP_NOFS);
                error = -ENOMEM;
                if (!clone)
                        goto cleanup;
@@ -375,7 +323,7 @@ int
 ext4_acl_chmod(struct inode *inode)
 {
        struct posix_acl *acl, *clone;
-        int error;
+       int error;
 
        if (S_ISLNK(inode->i_mode))
                return -EOPNOTSUPP;
@@ -489,7 +437,7 @@ ext4_xattr_set_acl(struct inode *inode, int type, const void *value,
 
        if (!test_opt(inode->i_sb, POSIX_ACL))
                return -EOPNOTSUPP;
-       if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
+       if (!is_owner_or_cap(inode))
                return -EPERM;
 
        if (value) {