NFSv3: Fix posix ACL code
[safe/jmp/linux-2.6] / fs / nfs / nfs3acl.c
index ee3536f..6bbf0e6 100644 (file)
@@ -2,9 +2,11 @@
 #include <linux/nfs.h>
 #include <linux/nfs3.h>
 #include <linux/nfs_fs.h>
-#include <linux/xattr_acl.h>
+#include <linux/posix_acl_xattr.h>
 #include <linux/nfsacl.h>
 
+#include "internal.h"
+
 #define NFSDBG_FACILITY        NFSDBG_PROC
 
 ssize_t nfs3_listxattr(struct dentry *dentry, char *buffer, size_t size)
@@ -53,9 +55,9 @@ ssize_t nfs3_getxattr(struct dentry *dentry, const char *name,
        struct posix_acl *acl;
        int type, error = 0;
 
-       if (strcmp(name, XATTR_NAME_ACL_ACCESS) == 0)
+       if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
                type = ACL_TYPE_ACCESS;
-       else if (strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0)
+       else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
                type = ACL_TYPE_DEFAULT;
        else
                return -EOPNOTSUPP;
@@ -82,9 +84,9 @@ int nfs3_setxattr(struct dentry *dentry, const char *name,
        struct posix_acl *acl;
        int type, error;
 
-       if (strcmp(name, XATTR_NAME_ACL_ACCESS) == 0)
+       if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
                type = ACL_TYPE_ACCESS;
-       else if (strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0)
+       else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
                type = ACL_TYPE_DEFAULT;
        else
                return -EOPNOTSUPP;
@@ -103,9 +105,9 @@ int nfs3_removexattr(struct dentry *dentry, const char *name)
        struct inode *inode = dentry->d_inode;
        int type;
 
-       if (strcmp(name, XATTR_NAME_ACL_ACCESS) == 0)
+       if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
                type = ACL_TYPE_ACCESS;
-       else if (strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0)
+       else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
                type = ACL_TYPE_DEFAULT;
        else
                return -EOPNOTSUPP;
@@ -172,8 +174,10 @@ static void nfs3_cache_acls(struct inode *inode, struct posix_acl *acl,
                inode->i_ino, acl, dfacl);
        spin_lock(&inode->i_lock);
        __nfs3_forget_cached_acls(NFS_I(inode));
-       nfsi->acl_access = posix_acl_dup(acl);
-       nfsi->acl_default = posix_acl_dup(dfacl);
+       if (!IS_ERR(acl))
+               nfsi->acl_access = posix_acl_dup(acl);
+       if (!IS_ERR(dfacl))
+               nfsi->acl_default = posix_acl_dup(dfacl);
        spin_unlock(&inode->i_lock);
 }
 
@@ -190,6 +194,10 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
        struct nfs3_getaclres res = {
                .fattr =        &fattr,
        };
+       struct rpc_message msg = {
+               .rpc_argp       = &args,
+               .rpc_resp       = &res,
+       };
        struct posix_acl *acl;
        int status, count;
 
@@ -199,6 +207,8 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
        status = nfs_revalidate_inode(server, inode);
        if (status < 0)
                return ERR_PTR(status);
+       if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
+               nfs_zap_acl_cache(inode);
        acl = nfs3_get_cached_acl(inode, type);
        if (acl != ERR_PTR(-EAGAIN))
                return acl;
@@ -218,8 +228,9 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
                return NULL;
 
        dprintk("NFS call getacl\n");
-       status = rpc_call(server->client_acl, ACLPROC3_GETACL,
-                         &args, &res, 0);
+       msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_GETACL];
+       nfs_fattr_init(&fattr);
+       status = rpc_call_sync(server->client_acl, &msg, 0);
        dprintk("NFS reply getacl: %d\n", status);
 
        /* pages may have been allocated at the xdr layer. */
@@ -250,7 +261,9 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
                        res.acl_access = NULL;
                }
        }
-       nfs3_cache_acls(inode, res.acl_access, res.acl_default);
+       nfs3_cache_acls(inode,
+               (res.mask & NFS_ACL)   ? res.acl_access  : ERR_PTR(-EINVAL),
+               (res.mask & NFS_DFACL) ? res.acl_default : ERR_PTR(-EINVAL));
 
        switch(type) {
                case ACL_TYPE_ACCESS:
@@ -279,14 +292,18 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
 {
        struct nfs_server *server = NFS_SERVER(inode);
        struct nfs_fattr fattr;
-       struct page *pages[NFSACL_MAXPAGES] = { };
+       struct page *pages[NFSACL_MAXPAGES];
        struct nfs3_setaclargs args = {
                .inode = inode,
                .mask = NFS_ACL,
                .acl_access = acl,
                .pages = pages,
        };
-       int status, count;
+       struct rpc_message msg = {
+               .rpc_argp       = &args,
+               .rpc_resp       = &fattr,
+       };
+       int status;
 
        status = -EOPNOTSUPP;
        if (!nfs_server_capable(inode, NFS_CAP_ACLS))
@@ -302,23 +319,34 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
        if (S_ISDIR(inode->i_mode)) {
                args.mask |= NFS_DFACL;
                args.acl_default = dfacl;
+               args.len = nfsacl_size(acl, dfacl);
+       } else
+               args.len = nfsacl_size(acl, NULL);
+
+       if (args.len > NFS_ACL_INLINE_BUFSIZE) {
+               unsigned int npages = 1 + ((args.len - 1) >> PAGE_SHIFT);
+
+               status = -ENOMEM;
+               do {
+                       args.pages[args.npages] = alloc_page(GFP_KERNEL);
+                       if (args.pages[args.npages] == NULL)
+                               goto out_freepages;
+                       args.npages++;
+               } while (args.npages < npages);
        }
 
        dprintk("NFS call setacl\n");
-       nfs_begin_data_update(inode);
-       status = rpc_call(server->client_acl, ACLPROC3_SETACL,
-                         &args, &fattr, 0);
-       NFS_FLAGS(inode) |= NFS_INO_INVALID_ACCESS;
-       nfs_end_data_update(inode);
+       msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL];
+       nfs_fattr_init(&fattr);
+       status = rpc_call_sync(server->client_acl, &msg, 0);
+       nfs_access_zap_cache(inode);
+       nfs_zap_acl_cache(inode);
        dprintk("NFS reply setacl: %d\n", status);
 
-       /* pages may have been allocated at the xdr layer. */
-       for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++)
-               __free_page(args.pages[count]);
-
        switch (status) {
                case 0:
                        status = nfs_refresh_inode(inode, &fattr);
+                       nfs3_cache_acls(inode, acl, dfacl);
                        break;
                case -EPFNOSUPPORT:
                case -EPROTONOSUPPORT:
@@ -328,6 +356,11 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
                case -ENOTSUPP:
                        status = -EOPNOTSUPP;
        }
+out_freepages:
+       while (args.npages != 0) {
+               args.npages--;
+               __free_page(args.pages[args.npages]);
+       }
 out:
        return status;
 }