提交 c818ba43 编写于 作者: M Manoj Naik 提交者: Trond Myklebust

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: NManoj Naik <manoj@almaden.ibm.com>
Signed-off-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
上级 830b8e33
...@@ -2027,62 +2027,24 @@ static void nfs4_clear_inode(struct inode *inode) ...@@ -2027,62 +2027,24 @@ static void nfs4_clear_inode(struct inode *inode)
} }
static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent) static struct rpc_clnt *nfs4_create_client(struct nfs_server *server,
struct rpc_timeout *timeparms, int proto, rpc_authflavor_t flavor)
{ {
struct nfs_server *server; struct nfs4_client *clp;
struct nfs4_client *clp = NULL;
struct rpc_xprt *xprt = NULL; struct rpc_xprt *xprt = NULL;
struct rpc_clnt *clnt = NULL; struct rpc_clnt *clnt = NULL;
struct rpc_timeout timeparms;
rpc_authflavor_t authflavour;
int err = -EIO; int err = -EIO;
sb->s_blocksize_bits = 0;
sb->s_blocksize = 0;
server = NFS_SB(sb);
if (data->rsize != 0)
server->rsize = nfs_block_size(data->rsize, NULL);
if (data->wsize != 0)
server->wsize = nfs_block_size(data->wsize, NULL);
server->flags = data->flags & NFS_MOUNT_FLAGMASK;
server->caps = NFS_CAP_ATOMIC_OPEN;
server->acregmin = data->acregmin*HZ;
server->acregmax = data->acregmax*HZ;
server->acdirmin = data->acdirmin*HZ;
server->acdirmax = data->acdirmax*HZ;
server->rpc_ops = &nfs_v4_clientops;
nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
server->retrans_timeo = timeparms.to_initval;
server->retrans_count = timeparms.to_retries;
clp = nfs4_get_client(&server->addr.sin_addr); clp = nfs4_get_client(&server->addr.sin_addr);
if (!clp) { if (!clp) {
dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__); dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__);
return -EIO; return ERR_PTR(err);
} }
/* Now create transport and client */ /* Now create transport and client */
authflavour = RPC_AUTH_UNIX;
if (data->auth_flavourlen != 0) {
if (data->auth_flavourlen != 1) {
dprintk("%s: Invalid number of RPC auth flavours %d.\n",
__FUNCTION__, data->auth_flavourlen);
err = -EINVAL;
goto out_fail;
}
if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
err = -EFAULT;
goto out_fail;
}
}
down_write(&clp->cl_sem); down_write(&clp->cl_sem);
if (IS_ERR(clp->cl_rpcclient)) { if (IS_ERR(clp->cl_rpcclient)) {
xprt = xprt_create_proto(data->proto, &server->addr, &timeparms); xprt = xprt_create_proto(proto, &server->addr, timeparms);
if (IS_ERR(xprt)) { if (IS_ERR(xprt)) {
up_write(&clp->cl_sem); up_write(&clp->cl_sem);
err = PTR_ERR(xprt); err = PTR_ERR(xprt);
...@@ -2091,7 +2053,7 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, ...@@ -2091,7 +2053,7 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
goto out_fail; goto out_fail;
} }
clnt = rpc_create_client(xprt, server->hostname, &nfs_program, clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
server->rpc_ops->version, authflavour); server->rpc_ops->version, flavor);
if (IS_ERR(clnt)) { if (IS_ERR(clnt)) {
up_write(&clp->cl_sem); up_write(&clp->cl_sem);
err = PTR_ERR(clnt); err = PTR_ERR(clnt);
...@@ -2108,43 +2070,96 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, ...@@ -2108,43 +2070,96 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks); list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
clnt = rpc_clone_client(clp->cl_rpcclient); clnt = rpc_clone_client(clp->cl_rpcclient);
if (!IS_ERR(clnt)) if (!IS_ERR(clnt))
server->nfs4_state = clp; server->nfs4_state = clp;
up_write(&clp->cl_sem); up_write(&clp->cl_sem);
clp = NULL; clp = NULL;
if (IS_ERR(clnt)) { if (IS_ERR(clnt)) {
err = PTR_ERR(clnt);
dprintk("%s: cannot create RPC client. Error = %d\n", dprintk("%s: cannot create RPC client. Error = %d\n",
__FUNCTION__, err); __FUNCTION__, err);
return err; return clnt;
} }
server->client = clnt;
if (server->nfs4_state->cl_idmap == NULL) { if (server->nfs4_state->cl_idmap == NULL) {
dprintk("%s: failed to create idmapper.\n", __FUNCTION__); dprintk("%s: failed to create idmapper.\n", __FUNCTION__);
return -ENOMEM; return ERR_PTR(-ENOMEM);
} }
if (clnt->cl_auth->au_flavor != authflavour) { if (clnt->cl_auth->au_flavor != flavor) {
struct rpc_auth *auth; struct rpc_auth *auth;
auth = rpcauth_create(authflavour, clnt); auth = rpcauth_create(flavor, clnt);
if (IS_ERR(auth)) { if (IS_ERR(auth)) {
dprintk("%s: couldn't create credcache!\n", __FUNCTION__); dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
return PTR_ERR(auth); return (struct rpc_clnt *)auth;
}
}
return clnt;
out_fail:
if (clp)
nfs4_put_client(clp);
return ERR_PTR(err);
}
static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent)
{
struct nfs_server *server;
struct rpc_timeout timeparms;
rpc_authflavor_t authflavour;
int err = -EIO;
sb->s_blocksize_bits = 0;
sb->s_blocksize = 0;
server = NFS_SB(sb);
if (data->rsize != 0)
server->rsize = nfs_block_size(data->rsize, NULL);
if (data->wsize != 0)
server->wsize = nfs_block_size(data->wsize, NULL);
server->flags = data->flags & NFS_MOUNT_FLAGMASK;
server->caps = NFS_CAP_ATOMIC_OPEN;
server->acregmin = data->acregmin*HZ;
server->acregmax = data->acregmax*HZ;
server->acdirmin = data->acdirmin*HZ;
server->acdirmax = data->acdirmax*HZ;
server->rpc_ops = &nfs_v4_clientops;
nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
server->retrans_timeo = timeparms.to_initval;
server->retrans_count = timeparms.to_retries;
/* Now create transport and client */
authflavour = RPC_AUTH_UNIX;
if (data->auth_flavourlen != 0) {
if (data->auth_flavourlen != 1) {
dprintk("%s: Invalid number of RPC auth flavours %d.\n",
__FUNCTION__, data->auth_flavourlen);
err = -EINVAL;
goto out_fail;
}
if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
err = -EFAULT;
goto out_fail;
} }
} }
server->client = nfs4_create_client(server, &timeparms, data->proto, authflavour);
if (IS_ERR(server->client)) {
err = PTR_ERR(server->client);
dprintk("%s: cannot create RPC client. Error = %d\n",
__FUNCTION__, err);
goto out_fail;
}
sb->s_time_gran = 1; sb->s_time_gran = 1;
sb->s_op = &nfs4_sops; sb->s_op = &nfs4_sops;
err = nfs_sb_init(sb, authflavour); err = nfs_sb_init(sb, authflavour);
if (err == 0)
return 0; out_fail:
out_fail:
if (clp)
nfs4_put_client(clp);
return err; return err;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册