nfs41: sessions client infrastructure
[linux-2.6-block.git] / fs / nfs / client.c
index 75c9cd2aa1194e0f0c4ac754ae2b85e722ce5809..f1506f1485216fb8c141190e25a0f495d99ac165 100644 (file)
@@ -102,6 +102,7 @@ struct nfs_client_initdata {
        size_t addrlen;
        const struct nfs_rpc_ops *rpc_ops;
        int proto;
+       u32 minorversion;
 };
 
 /*
@@ -150,6 +151,7 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
        rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
        clp->cl_boot_time = CURRENT_TIME;
        clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
+       clp->cl_minorversion = cl_init->minorversion;
 #endif
        cred = rpc_lookup_machine_cred();
        if (!IS_ERR(cred))
@@ -181,6 +183,20 @@ static void nfs4_shutdown_client(struct nfs_client *clp)
 #endif
 }
 
+/*
+ * Clears/puts all minor version specific parts from an nfs_client struct
+ * reverting it to minorversion 0.
+ */
+static void nfs4_clear_client_minor_version(struct nfs_client *clp)
+{
+#ifdef CONFIG_NFS_V4_1
+       if (nfs4_has_session(clp)) {
+               nfs4_destroy_session(clp->cl_session);
+               clp->cl_session = NULL;
+       }
+#endif /* CONFIG_NFS_V4_1 */
+}
+
 /*
  * Destroy a shared client record
  */
@@ -188,6 +204,7 @@ static void nfs_free_client(struct nfs_client *clp)
 {
        dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version);
 
+       nfs4_clear_client_minor_version(clp);
        nfs4_shutdown_client(clp);
 
        nfs_fscache_release_client_cookie(clp);
@@ -420,7 +437,9 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *dat
 
                if (clp->cl_proto != data->proto)
                        continue;
-
+               /* Match nfsv4 minorversion */
+               if (clp->cl_minorversion != data->minorversion)
+                       continue;
                /* Match the full socket address */
                if (!nfs_sockaddr_cmp(sap, clap))
                        continue;
@@ -1049,6 +1068,30 @@ error:
 }
 
 #ifdef CONFIG_NFS_V4
+/*
+ * Initialize the minor version specific parts of an NFS4 client record
+ */
+static int nfs4_init_client_minor_version(struct nfs_client *clp)
+{
+#if defined(CONFIG_NFS_V4_1)
+       if (clp->cl_minorversion) {
+               struct nfs4_session *session = NULL;
+               /*
+                * Create the session and mark it expired.
+                * When a SEQUENCE operation encounters the expired session
+                * it will do session recovery to initialize it.
+                */
+               session = nfs4_alloc_session(clp);
+               if (!session)
+                       return -ENOMEM;
+
+               clp->cl_session = session;
+       }
+#endif /* CONFIG_NFS_V4_1 */
+
+       return 0;
+}
+
 /*
  * Initialise an NFS4 client record
  */
@@ -1083,6 +1126,10 @@ static int nfs4_init_client(struct nfs_client *clp,
        }
        __set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
 
+       error = nfs4_init_client_minor_version(clp);
+       if (error < 0)
+               goto error;
+
        nfs_mark_client_ready(clp, NFS_CS_READY);
        return 0;
 
@@ -1101,7 +1148,8 @@ static int nfs4_set_client(struct nfs_server *server,
                const size_t addrlen,
                const char *ip_addr,
                rpc_authflavor_t authflavour,
-               int proto, const struct rpc_timeout *timeparms)
+               int proto, const struct rpc_timeout *timeparms,
+               u32 minorversion)
 {
        struct nfs_client_initdata cl_init = {
                .hostname = hostname,
@@ -1109,6 +1157,7 @@ static int nfs4_set_client(struct nfs_server *server,
                .addrlen = addrlen,
                .rpc_ops = &nfs_v4_clientops,
                .proto = proto,
+               .minorversion = minorversion,
        };
        struct nfs_client *clp;
        int error;
@@ -1137,6 +1186,21 @@ error:
        return error;
 }
 
+/*
+ * Initialize a session.
+ * Note: save the mount rsize and wsize for create_server negotiation.
+ */
+static void nfs4_init_session(struct nfs_client *clp,
+                             unsigned int wsize, unsigned int rsize)
+{
+#if defined(CONFIG_NFS_V4_1)
+       if (nfs4_has_session(clp)) {
+               clp->cl_session->fc_attrs.max_rqst_sz = wsize;
+               clp->cl_session->fc_attrs.max_resp_sz = rsize;
+       }
+#endif /* CONFIG_NFS_V4_1 */
+}
+
 /*
  * Create a version 4 volume record
  */
@@ -1164,7 +1228,8 @@ static int nfs4_init_server(struct nfs_server *server,
                        data->client_address,
                        data->auth_flavors[0],
                        data->nfs_server.protocol,
-                       &timeparms);
+                       &timeparms,
+                       data->minorversion);
        if (error < 0)
                goto error;
 
@@ -1214,6 +1279,8 @@ struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
        BUG_ON(!server->nfs_client->rpc_ops);
        BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
 
+       nfs4_init_session(server->nfs_client, server->wsize, server->rsize);
+
        /* Probe the root fh to retrieve its FSID */
        error = nfs4_path_walk(server, mntfh, data->nfs_server.export_path);
        if (error < 0)
@@ -1282,7 +1349,8 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
                                parent_client->cl_ipaddr,
                                data->authflavor,
                                parent_server->client->cl_xprt->prot,
-                               parent_server->client->cl_timeout);
+                               parent_server->client->cl_timeout,
+                               parent_client->cl_minorversion);
        if (error < 0)
                goto error;