aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/client.c
diff options
context:
space:
mode:
authorBryan Schumaker <bjschuma@netapp.com>2012-07-16 16:39:17 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2012-07-17 13:33:52 -0400
commit428360d77c801932e4b28f15160aebbdb5f5a03e (patch)
tree2e96be9e5f6d1d75009c11e0adfad16a29595851 /fs/nfs/client.c
parenta38a9eac75f0d09f1941a6e85e291c8e96bc8375 (diff)
NFS: Initialize the NFS v4 client from init_nfs_v4()
And split these functions out of the generic client into a v4 specific file. Signed-off-by: Bryan Schumaker <bjschuma@netapp.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/client.c')
-rw-r--r--fs/nfs/client.c137
1 files changed, 3 insertions, 134 deletions
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 254719c4a575..5664c7bbe50d 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -662,9 +662,9 @@ static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
662/* 662/*
663 * Create an RPC client handle 663 * Create an RPC client handle
664 */ 664 */
665static int nfs_create_rpc_client(struct nfs_client *clp, 665int nfs_create_rpc_client(struct nfs_client *clp,
666 const struct rpc_timeout *timeparms, 666 const struct rpc_timeout *timeparms,
667 rpc_authflavor_t flavor) 667 rpc_authflavor_t flavor)
668{ 668{
669 struct rpc_clnt *clnt = NULL; 669 struct rpc_clnt *clnt = NULL;
670 struct rpc_create_args args = { 670 struct rpc_create_args args = {
@@ -1305,137 +1305,6 @@ nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
1305#endif /* CONFIG_NFS_V4_1 */ 1305#endif /* CONFIG_NFS_V4_1 */
1306 1306
1307/* 1307/*
1308 * Initialize the NFS4 callback service
1309 */
1310static int nfs4_init_callback(struct nfs_client *clp)
1311{
1312 int error;
1313
1314 if (clp->rpc_ops->version == 4) {
1315 struct rpc_xprt *xprt;
1316
1317 xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt);
1318
1319 if (nfs4_has_session(clp)) {
1320 error = xprt_setup_backchannel(xprt,
1321 NFS41_BC_MIN_CALLBACKS);
1322 if (error < 0)
1323 return error;
1324 }
1325
1326 error = nfs_callback_up(clp->cl_mvops->minor_version, xprt);
1327 if (error < 0) {
1328 dprintk("%s: failed to start callback. Error = %d\n",
1329 __func__, error);
1330 return error;
1331 }
1332 __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state);
1333 }
1334 return 0;
1335}
1336
1337/*
1338 * Initialize the minor version specific parts of an NFS4 client record
1339 */
1340static int nfs4_init_client_minor_version(struct nfs_client *clp)
1341{
1342#if defined(CONFIG_NFS_V4_1)
1343 if (clp->cl_mvops->minor_version) {
1344 struct nfs4_session *session = NULL;
1345 /*
1346 * Create the session and mark it expired.
1347 * When a SEQUENCE operation encounters the expired session
1348 * it will do session recovery to initialize it.
1349 */
1350 session = nfs4_alloc_session(clp);
1351 if (!session)
1352 return -ENOMEM;
1353
1354 clp->cl_session = session;
1355 /*
1356 * The create session reply races with the server back
1357 * channel probe. Mark the client NFS_CS_SESSION_INITING
1358 * so that the client back channel can find the
1359 * nfs_client struct
1360 */
1361 nfs_mark_client_ready(clp, NFS_CS_SESSION_INITING);
1362 }
1363#endif /* CONFIG_NFS_V4_1 */
1364
1365 return nfs4_init_callback(clp);
1366}
1367
1368/**
1369 * nfs4_init_client - Initialise an NFS4 client record
1370 *
1371 * @clp: nfs_client to initialise
1372 * @timeparms: timeout parameters for underlying RPC transport
1373 * @ip_addr: callback IP address in presentation format
1374 * @authflavor: authentication flavor for underlying RPC transport
1375 *
1376 * Returns pointer to an NFS client, or an ERR_PTR value.
1377 */
1378struct nfs_client *nfs4_init_client(struct nfs_client *clp,
1379 const struct rpc_timeout *timeparms,
1380 const char *ip_addr,
1381 rpc_authflavor_t authflavour)
1382{
1383 char buf[INET6_ADDRSTRLEN + 1];
1384 int error;
1385
1386 if (clp->cl_cons_state == NFS_CS_READY) {
1387 /* the client is initialised already */
1388 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp);
1389 return clp;
1390 }
1391
1392 /* Check NFS protocol revision and initialize RPC op vector */
1393 clp->rpc_ops = &nfs_v4_clientops;
1394
1395 __set_bit(NFS_CS_DISCRTRY, &clp->cl_flags);
1396 error = nfs_create_rpc_client(clp, timeparms, authflavour);
1397 if (error < 0)
1398 goto error;
1399
1400 /* If no clientaddr= option was specified, find a usable cb address */
1401 if (ip_addr == NULL) {
1402 struct sockaddr_storage cb_addr;
1403 struct sockaddr *sap = (struct sockaddr *)&cb_addr;
1404
1405 error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr));
1406 if (error < 0)
1407 goto error;
1408 error = rpc_ntop(sap, buf, sizeof(buf));
1409 if (error < 0)
1410 goto error;
1411 ip_addr = (const char *)buf;
1412 }
1413 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
1414
1415 error = nfs_idmap_new(clp);
1416 if (error < 0) {
1417 dprintk("%s: failed to create idmapper. Error = %d\n",
1418 __func__, error);
1419 goto error;
1420 }
1421 __set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
1422
1423 error = nfs4_init_client_minor_version(clp);
1424 if (error < 0)
1425 goto error;
1426
1427 if (!nfs4_has_session(clp))
1428 nfs_mark_client_ready(clp, NFS_CS_READY);
1429 return clp;
1430
1431error:
1432 nfs_mark_client_ready(clp, error);
1433 nfs_put_client(clp);
1434 dprintk("<-- nfs4_init_client() = xerror %d\n", error);
1435 return ERR_PTR(error);
1436}
1437
1438/*
1439 * Set up an NFS4 client 1308 * Set up an NFS4 client
1440 */ 1309 */
1441static int nfs4_set_client(struct nfs_server *server, 1310static int nfs4_set_client(struct nfs_server *server,