[PATCH] NFS: Add support for NFSv3 ACLs
[deliverable/linux.git] / fs / nfs / inode.c
index 32ddcf69e9ac81bbf1631e9233908385f7c9bce2..440b9cbb6f8116e006b0657b1791e9765fd5f5fc 100644 (file)
@@ -39,6 +39,7 @@
 #include <asm/system.h>
 #include <asm/uaccess.h>
 
+#include "nfs4_fs.h"
 #include "delegation.h"
 
 #define NFSDBG_FACILITY                NFSDBG_VFS
@@ -63,6 +64,7 @@ static void nfs_clear_inode(struct inode *);
 static void nfs_umount_begin(struct super_block *);
 static int  nfs_statfs(struct super_block *, struct kstatfs *);
 static int  nfs_show_options(struct seq_file *, struct vfsmount *);
+static void nfs_zap_acl_cache(struct inode *);
 
 static struct rpc_program      nfs_program;
 
@@ -106,6 +108,21 @@ static struct rpc_program  nfs_program = {
        .pipe_dir_name          = "/nfs",
 };
 
+#ifdef CONFIG_NFS_V3_ACL
+static struct rpc_stat         nfsacl_rpcstat = { &nfsacl_program };
+static struct rpc_version *    nfsacl_version[] = {
+       [3]                     = &nfsacl_version3,
+};
+
+struct rpc_program             nfsacl_program = {
+       .name =                 "nfsacl",
+       .number =               NFS_ACL_PROGRAM,
+       .nrvers =               sizeof(nfsacl_version) / sizeof(nfsacl_version[0]),
+       .version =              nfsacl_version,
+       .stats =                &nfsacl_rpcstat,
+};
+#endif  /* CONFIG_NFS_V3_ACL */
+
 static inline unsigned long
 nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
 {
@@ -140,10 +157,6 @@ nfs_delete_inode(struct inode * inode)
        clear_inode(inode);
 }
 
-/*
- * For the moment, the only task for the NFS clear_inode method is to
- * release the mmap credential
- */
 static void
 nfs_clear_inode(struct inode *inode)
 {
@@ -152,6 +165,7 @@ nfs_clear_inode(struct inode *inode)
 
        nfs_wb_all(inode);
        BUG_ON (!list_empty(&nfsi->open_files));
+       nfs_zap_acl_cache(inode);
        cred = nfsi->cache_access.cred;
        if (cred)
                put_rpccred(cred);
@@ -161,11 +175,13 @@ nfs_clear_inode(struct inode *inode)
 void
 nfs_umount_begin(struct super_block *sb)
 {
-       struct nfs_server *server = NFS_SB(sb);
-       struct rpc_clnt *rpc;
+       struct rpc_clnt *rpc = NFS_SB(sb)->client;
 
        /* -EIO all pending I/O */
-       if ((rpc = server->client) != NULL)
+       if (!IS_ERR(rpc))
+               rpc_killall_tasks(rpc);
+       rpc = NFS_SB(sb)->client_acl;
+       if (!IS_ERR(rpc))
                rpc_killall_tasks(rpc);
 }
 
@@ -451,17 +467,29 @@ nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent)
                return PTR_ERR(server->client);
        /* RFC 2623, sec 2.3.2 */
        if (authflavor != RPC_AUTH_UNIX) {
+               struct rpc_auth *auth;
+
                server->client_sys = rpc_clone_client(server->client);
                if (IS_ERR(server->client_sys))
                        return PTR_ERR(server->client_sys);
-               if (!rpcauth_create(RPC_AUTH_UNIX, server->client_sys))
-                       return -ENOMEM;
+               auth = rpcauth_create(RPC_AUTH_UNIX, server->client_sys);
+               if (IS_ERR(auth))
+                       return PTR_ERR(auth);
        } else {
                atomic_inc(&server->client->cl_count);
                server->client_sys = server->client;
        }
-
        if (server->flags & NFS_MOUNT_VER3) {
+#ifdef CONFIG_NFS_V3_ACL
+               if (!(server->flags & NFS_MOUNT_NOACL)) {
+                       server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
+                       /* No errors! Assume that Sun nfsacls are supported */
+                       if (!IS_ERR(server->client_acl))
+                               server->caps |= NFS_CAP_ACLS;
+               }
+#else
+               server->flags &= ~NFS_MOUNT_NOACL;
+#endif /* CONFIG_NFS_V3_ACL */
                if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
                        server->namelen = NFS3_MAXNAMLEN;
                sb->s_time_gran = 1;
@@ -545,6 +573,7 @@ static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
                { NFS_MOUNT_NOCTO, ",nocto", "" },
                { NFS_MOUNT_NOAC, ",noac", "" },
                { NFS_MOUNT_NONLM, ",nolock", ",lock" },
+               { NFS_MOUNT_NOACL, ",noacl", "" },
                { 0, NULL, NULL }
        };
        struct proc_nfs_info *nfs_infop;
@@ -586,9 +615,19 @@ nfs_zap_caches(struct inode *inode)
 
        memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
        if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
-               nfsi->flags |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS;
+               nfsi->flags |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
        else
-               nfsi->flags |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS;
+               nfsi->flags |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
+}
+
+static void nfs_zap_acl_cache(struct inode *inode)
+{
+       void (*clear_acl_cache)(struct inode *);
+
+       clear_acl_cache = NFS_PROTO(inode)->clear_acl_cache;
+       if (clear_acl_cache != NULL)
+               clear_acl_cache(inode);
+       NFS_I(inode)->flags &= ~NFS_INO_INVALID_ACL;
 }
 
 /*
@@ -685,7 +724,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                /* Why so? Because we want revalidate for devices/FIFOs, and
                 * that's precisely what we have in nfs_file_inode_operations.
                 */
-               inode->i_op = &nfs_file_inode_operations;
+               inode->i_op = NFS_SB(sb)->rpc_ops->file_inode_ops;
                if (S_ISREG(inode->i_mode)) {
                        inode->i_fop = &nfs_file_operations;
                        inode->i_data.a_ops = &nfs_file_aops;
@@ -788,7 +827,7 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
                }
        }
        if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
-               NFS_FLAGS(inode) |= NFS_INO_INVALID_ACCESS;
+               NFS_FLAGS(inode) |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
        nfs_end_data_update(inode);
        unlock_kernel();
        return error;
@@ -847,7 +886,6 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rp
                ctx->state = NULL;
                ctx->lockowner = current->files;
                ctx->error = 0;
-               init_waitqueue_head(&ctx->waitq);
        }
        return ctx;
 }
@@ -1033,6 +1071,8 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
                /* This ensures we revalidate dentries */
                nfsi->cache_change_attribute++;
        }
+       if (flags & NFS_INO_INVALID_ACL)
+               nfs_zap_acl_cache(inode);
        dfprintk(PAGECACHE, "NFS: (%s/%Ld) revalidation complete\n",
                inode->i_sb->s_id,
                (long long)NFS_FILEID(inode));
@@ -1183,7 +1223,7 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
        if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
                        || inode->i_uid != fattr->uid
                        || inode->i_gid != fattr->gid)
-               nfsi->flags |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS;
+               nfsi->flags |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
 
        /* Has the link count changed? */
        if (inode->i_nlink != fattr->nlink)
@@ -1292,16 +1332,21 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr, unsign
 #endif
                nfsi->change_attr = fattr->change_attr;
                if (!data_unstable)
-                       invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS;
+                       invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
        }
 
-       memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
+       /* If ctime has changed we should definitely clear access+acl caches */
+       if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) {
+               if (!data_unstable)
+                       invalid |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
+               memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
+       }
        memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
 
        if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
            inode->i_uid != fattr->uid ||
            inode->i_gid != fattr->gid)
-               invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS;
+               invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
 
        inode->i_mode = fattr->mode;
        inode->i_nlink = fattr->nlink;
@@ -1435,6 +1480,7 @@ static struct super_block *nfs_get_sb(struct file_system_type *fs_type,
        memset(server, 0, sizeof(struct nfs_server));
        /* Zero out the NFS state stuff */
        init_nfsv4_state(server);
+       server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
 
        root = &server->fh;
        if (data->flags & NFS_MOUNT_VER3)
@@ -1491,10 +1537,12 @@ static void nfs_kill_super(struct super_block *s)
 
        kill_anon_super(s);
 
-       if (server->client != NULL && !IS_ERR(server->client))
+       if (!IS_ERR(server->client))
                rpc_shutdown_client(server->client);
-       if (server->client_sys != NULL && !IS_ERR(server->client_sys))
+       if (!IS_ERR(server->client_sys))
                rpc_shutdown_client(server->client_sys);
+       if (!IS_ERR(server->client_acl))
+               rpc_shutdown_client(server->client_acl);
 
        if (!(server->flags & NFS_MOUNT_NONLM))
                lockd_down();   /* release rpc.lockd */
@@ -1635,7 +1683,7 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
        }
 
        down_write(&clp->cl_sem);
-       if (clp->cl_rpcclient == NULL) {
+       if (IS_ERR(clp->cl_rpcclient)) {
                xprt = xprt_create_proto(proto, &server->addr, &timeparms);
                if (IS_ERR(xprt)) {
                        up_write(&clp->cl_sem);
@@ -1696,9 +1744,12 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
        }
 
        if (clnt->cl_auth->au_flavor != authflavour) {
-               if (rpcauth_create(authflavour, clnt) == NULL) {
+               struct rpc_auth *auth;
+
+               auth = rpcauth_create(authflavour, clnt);
+               if (IS_ERR(auth)) {
                        dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
-                       return -ENOMEM;
+                       return PTR_ERR(auth);
                }
        }
 
@@ -1773,6 +1824,7 @@ static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
        memset(server, 0, sizeof(struct nfs_server));
        /* Zero out the NFS state stuff */
        init_nfsv4_state(server);
+       server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
 
        p = nfs_copy_user_string(NULL, &data->hostname, 256);
        if (IS_ERR(p))
@@ -1904,6 +1956,9 @@ static struct inode *nfs_alloc_inode(struct super_block *sb)
        if (!nfsi)
                return NULL;
        nfsi->flags = 0;
+#ifdef CONFIG_NFS_V4
+       nfsi->nfs4_acl = NULL;
+#endif /* CONFIG_NFS_V4 */
        return &nfsi->vfs_inode;
 }
 
This page took 0.038854 seconds and 5 git commands to generate.