aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Naik <manoj@almaden.ibm.com>2006-06-09 09:34:26 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2006-06-09 09:34:26 -0400
commitc818ba43f9ca2e8214412ab5f126b1f436c35098 (patch)
tree02e3646c172000c8bc71d6de52d4991bbeb3db14
parent830b8e33fe1900b87c8eb7ec5c646117a9f298d6 (diff)
NFSv4: Create NFSv4 transport and client
Move existing code into a separate function so that it can be also used by referral code. Signed-off-by: Manoj Naik <manoj@almaden.ibm.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
-rw-r--r--fs/nfs/inode.c131
1 files changed, 73 insertions, 58 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 3eea556d8f59..db62a5a7e4fc 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -2027,62 +2027,24 @@ static void nfs4_clear_inode(struct inode *inode)
2027} 2027}
2028 2028
2029 2029
2030static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent) 2030static struct rpc_clnt *nfs4_create_client(struct nfs_server *server,
2031 struct rpc_timeout *timeparms, int proto, rpc_authflavor_t flavor)
2031{ 2032{
2032 struct nfs_server *server; 2033 struct nfs4_client *clp;
2033 struct nfs4_client *clp = NULL;
2034 struct rpc_xprt *xprt = NULL; 2034 struct rpc_xprt *xprt = NULL;
2035 struct rpc_clnt *clnt = NULL; 2035 struct rpc_clnt *clnt = NULL;
2036 struct rpc_timeout timeparms;
2037 rpc_authflavor_t authflavour;
2038 int err = -EIO; 2036 int err = -EIO;
2039 2037
2040 sb->s_blocksize_bits = 0;
2041 sb->s_blocksize = 0;
2042 server = NFS_SB(sb);
2043 if (data->rsize != 0)
2044 server->rsize = nfs_block_size(data->rsize, NULL);
2045 if (data->wsize != 0)
2046 server->wsize = nfs_block_size(data->wsize, NULL);
2047 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
2048 server->caps = NFS_CAP_ATOMIC_OPEN;
2049
2050 server->acregmin = data->acregmin*HZ;
2051 server->acregmax = data->acregmax*HZ;
2052 server->acdirmin = data->acdirmin*HZ;
2053 server->acdirmax = data->acdirmax*HZ;
2054
2055 server->rpc_ops = &nfs_v4_clientops;
2056
2057 nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
2058
2059 server->retrans_timeo = timeparms.to_initval;
2060 server->retrans_count = timeparms.to_retries;
2061
2062 clp = nfs4_get_client(&server->addr.sin_addr); 2038 clp = nfs4_get_client(&server->addr.sin_addr);
2063 if (!clp) { 2039 if (!clp) {
2064 dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__); 2040 dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__);
2065 return -EIO; 2041 return ERR_PTR(err);
2066 } 2042 }
2067 2043
2068 /* Now create transport and client */ 2044 /* Now create transport and client */
2069 authflavour = RPC_AUTH_UNIX;
2070 if (data->auth_flavourlen != 0) {
2071 if (data->auth_flavourlen != 1) {
2072 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
2073 __FUNCTION__, data->auth_flavourlen);
2074 err = -EINVAL;
2075 goto out_fail;
2076 }
2077 if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
2078 err = -EFAULT;
2079 goto out_fail;
2080 }
2081 }
2082
2083 down_write(&clp->cl_sem); 2045 down_write(&clp->cl_sem);
2084 if (IS_ERR(clp->cl_rpcclient)) { 2046 if (IS_ERR(clp->cl_rpcclient)) {
2085 xprt = xprt_create_proto(data->proto, &server->addr, &timeparms); 2047 xprt = xprt_create_proto(proto, &server->addr, timeparms);
2086 if (IS_ERR(xprt)) { 2048 if (IS_ERR(xprt)) {
2087 up_write(&clp->cl_sem); 2049 up_write(&clp->cl_sem);
2088 err = PTR_ERR(xprt); 2050 err = PTR_ERR(xprt);
@@ -2091,7 +2053,7 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
2091 goto out_fail; 2053 goto out_fail;
2092 } 2054 }
2093 clnt = rpc_create_client(xprt, server->hostname, &nfs_program, 2055 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
2094 server->rpc_ops->version, authflavour); 2056 server->rpc_ops->version, flavor);
2095 if (IS_ERR(clnt)) { 2057 if (IS_ERR(clnt)) {
2096 up_write(&clp->cl_sem); 2058 up_write(&clp->cl_sem);
2097 err = PTR_ERR(clnt); 2059 err = PTR_ERR(clnt);
@@ -2108,43 +2070,96 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
2108 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks); 2070 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
2109 clnt = rpc_clone_client(clp->cl_rpcclient); 2071 clnt = rpc_clone_client(clp->cl_rpcclient);
2110 if (!IS_ERR(clnt)) 2072 if (!IS_ERR(clnt))
2111 server->nfs4_state = clp; 2073 server->nfs4_state = clp;
2112 up_write(&clp->cl_sem); 2074 up_write(&clp->cl_sem);
2113 clp = NULL; 2075 clp = NULL;
2114 2076
2115 if (IS_ERR(clnt)) { 2077 if (IS_ERR(clnt)) {
2116 err = PTR_ERR(clnt);
2117 dprintk("%s: cannot create RPC client. Error = %d\n", 2078 dprintk("%s: cannot create RPC client. Error = %d\n",
2118 __FUNCTION__, err); 2079 __FUNCTION__, err);
2119 return err; 2080 return clnt;
2120 } 2081 }
2121 2082
2122 server->client = clnt;
2123
2124 if (server->nfs4_state->cl_idmap == NULL) { 2083 if (server->nfs4_state->cl_idmap == NULL) {
2125 dprintk("%s: failed to create idmapper.\n", __FUNCTION__); 2084 dprintk("%s: failed to create idmapper.\n", __FUNCTION__);
2126 return -ENOMEM; 2085 return ERR_PTR(-ENOMEM);
2127 } 2086 }
2128 2087
2129 if (clnt->cl_auth->au_flavor != authflavour) { 2088 if (clnt->cl_auth->au_flavor != flavor) {
2130 struct rpc_auth *auth; 2089 struct rpc_auth *auth;
2131 2090
2132 auth = rpcauth_create(authflavour, clnt); 2091 auth = rpcauth_create(flavor, clnt);
2133 if (IS_ERR(auth)) { 2092 if (IS_ERR(auth)) {
2134 dprintk("%s: couldn't create credcache!\n", __FUNCTION__); 2093 dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
2135 return PTR_ERR(auth); 2094 return (struct rpc_clnt *)auth;
2095 }
2096 }
2097 return clnt;
2098
2099 out_fail:
2100 if (clp)
2101 nfs4_put_client(clp);
2102 return ERR_PTR(err);
2103}
2104
2105static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent)
2106{
2107 struct nfs_server *server;
2108 struct rpc_timeout timeparms;
2109 rpc_authflavor_t authflavour;
2110 int err = -EIO;
2111
2112 sb->s_blocksize_bits = 0;
2113 sb->s_blocksize = 0;
2114 server = NFS_SB(sb);
2115 if (data->rsize != 0)
2116 server->rsize = nfs_block_size(data->rsize, NULL);
2117 if (data->wsize != 0)
2118 server->wsize = nfs_block_size(data->wsize, NULL);
2119 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
2120 server->caps = NFS_CAP_ATOMIC_OPEN;
2121
2122 server->acregmin = data->acregmin*HZ;
2123 server->acregmax = data->acregmax*HZ;
2124 server->acdirmin = data->acdirmin*HZ;
2125 server->acdirmax = data->acdirmax*HZ;
2126
2127 server->rpc_ops = &nfs_v4_clientops;
2128
2129 nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
2130
2131 server->retrans_timeo = timeparms.to_initval;
2132 server->retrans_count = timeparms.to_retries;
2133
2134 /* Now create transport and client */
2135 authflavour = RPC_AUTH_UNIX;
2136 if (data->auth_flavourlen != 0) {
2137 if (data->auth_flavourlen != 1) {
2138 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
2139 __FUNCTION__, data->auth_flavourlen);
2140 err = -EINVAL;
2141 goto out_fail;
2142 }
2143 if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
2144 err = -EFAULT;
2145 goto out_fail;
2136 } 2146 }
2137 } 2147 }
2138 2148
2149 server->client = nfs4_create_client(server, &timeparms, data->proto, authflavour);
2150 if (IS_ERR(server->client)) {
2151 err = PTR_ERR(server->client);
2152 dprintk("%s: cannot create RPC client. Error = %d\n",
2153 __FUNCTION__, err);
2154 goto out_fail;
2155 }
2156
2139 sb->s_time_gran = 1; 2157 sb->s_time_gran = 1;
2140 2158
2141 sb->s_op = &nfs4_sops; 2159 sb->s_op = &nfs4_sops;
2142 err = nfs_sb_init(sb, authflavour); 2160 err = nfs_sb_init(sb, authflavour);
2143 if (err == 0) 2161
2144 return 0; 2162 out_fail:
2145out_fail:
2146 if (clp)
2147 nfs4_put_client(clp);
2148 return err; 2163 return err;
2149} 2164}
2150 2165