nfs: hornor timeo and retrans option when mounting NFSv3
authorEryu Guan <eguan@linux.alibaba.com>
Tue, 23 Mar 2021 02:57:13 +0000 (10:57 +0800)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 5 Apr 2021 13:04:21 +0000 (09:04 -0400)
Mounting NFSv3 uses default timeout parameters specified by underlying
sunrpc transport, and mount options like 'timeo' and 'retrans', unlike
NFSv4, are not honored.

But sometimes we want to set non-default timeout value when mounting
NFSv3, so pass 'timeo' and 'retrans' to nfs_mount() and fill the
'timeout' field of struct rpc_create_args before creating RPC
connection. This is also consistent with NFSv4 behavior.

Note that this only sets the timeout value of rpc connection to mountd,
but the timeout of rpcbind connection should be set as well. A later
patch will fix the rpcbind part.

Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/internal.h
fs/nfs/mount_clnt.c
fs/nfs/super.c

index 7b644d6c09e4b27d8e0e5a25d75f91202ea72049..cf0d7db24d44ef398bb00fe690b68c1e94169368 100644 (file)
@@ -180,7 +180,7 @@ struct nfs_mount_request {
        struct net              *net;
 };
 
-extern int nfs_mount(struct nfs_mount_request *info);
+extern int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans);
 extern void nfs_umount(const struct nfs_mount_request *info);
 
 /* client.c */
index dda5c3e65d8d690bfc49333fbd8191d0dd897e83..c5e3b6b3366a65b5d6167b6808289430986eafde 100644 (file)
@@ -136,14 +136,16 @@ struct mnt_fhstatus {
 /**
  * nfs_mount - Obtain an NFS file handle for the given host and path
  * @info: pointer to mount request arguments
+ * @timeo: deciseconds the mount waits for a response before it retries
+ * @retrans: number of times the mount retries a request
  *
- * Uses default timeout parameters specified by underlying transport. On
- * successful return, the auth_flavs list and auth_flav_len will be populated
- * with the list from the server or a faked-up list if the server didn't
- * provide one.
+ * Uses timeout parameters specified by caller. On successful return, the
+ * auth_flavs list and auth_flav_len will be populated with the list from the
+ * server or a faked-up list if the server didn't provide one.
  */
-int nfs_mount(struct nfs_mount_request *info)
+int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans)
 {
+       struct rpc_timeout mnt_timeout;
        struct mountres result = {
                .fh             = info->fh,
                .auth_count     = info->auth_flav_len,
@@ -158,6 +160,7 @@ int nfs_mount(struct nfs_mount_request *info)
                .protocol       = info->protocol,
                .address        = info->sap,
                .addrsize       = info->salen,
+               .timeout        = &mnt_timeout,
                .servername     = info->hostname,
                .program        = &mnt_program,
                .version        = info->version,
@@ -177,6 +180,7 @@ int nfs_mount(struct nfs_mount_request *info)
        if (info->noresvport)
                args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
 
+       nfs_init_timeout_values(&mnt_timeout, info->protocol, timeo, retrans);
        mnt_clnt = rpc_create(&args);
        if (IS_ERR(mnt_clnt))
                goto out_clnt_err;
index 94885c6f8f5410e388566828a80a64104effbb87..13a650750f04a81fc6a9531a1f465f7afaf9dabc 100644 (file)
@@ -867,7 +867,7 @@ static int nfs_request_mount(struct fs_context *fc,
         * Now ask the mount server to map our export path
         * to a file handle.
         */
-       status = nfs_mount(&request);
+       status = nfs_mount(&request, ctx->timeo, ctx->retrans);
        if (status != 0) {
                dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
                                request.hostname, status);