From: Chuck Lever Subject: [PATCH 18/19] text-based mount.nfs: Create fg/bg helpers for NFSv4 mounts Date: Mon, 10 Sep 2007 20:59:58 -0400 Message-ID: <20070911005958.24927.48955.stgit@monet.1015granger.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: nfs@lists.sourceforge.net Return-path: Received: from sc8-sf-mx1-b.sourceforge.net ([10.3.1.91] helo=mail.sourceforge.net) by sc8-sf-list2-new.sourceforge.net with esmtp (Exim 4.43) id 1IUu6g-00034s-Q7 for nfs@lists.sourceforge.net; Mon, 10 Sep 2007 17:59:58 -0700 Received: from flpi102.sbcis.sbc.com ([207.115.20.71] helo=flpi102.prodigy.net) by mail.sourceforge.net with esmtp (Exim 4.44) id 1IUu6k-0008GN-W7 for nfs@lists.sourceforge.net; Mon, 10 Sep 2007 18:00:03 -0700 Received: from monet.1015granger.net (adsl-76-241-169-38.dsl.sfldmi.sbcglobal.net [76.241.169.38]) by flpi102.prodigy.net (8.13.8 out.dk.spool/8.13.8) with ESMTP id l8B0xm4w029367 for ; Mon, 10 Sep 2007 17:59:48 -0700 Received: from monet.1015granger.net (monet.1015granger.net [127.0.0.1]) by monet.1015granger.net (8.14.1/8.14.1) with ESMTP id l8B0xweu025092 for ; Mon, 10 Sep 2007 20:59:59 -0400 List-Id: "Discussion of NFS under Linux development, interoperability, and testing." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: nfs-bounces@lists.sourceforge.net Errors-To: nfs-bounces@lists.sourceforge.net Clone the NFSv2/3 fg/bg helpers for use with NFSv4 mounts. The fg/bg helpers are very similar to each other... when we've decided they can be exactly the same except for calling either try_nfsmount or try_nfs4mount, we'll refactor these so there is only one set for both v2/3 and v4. Signed-off-by: Chuck Lever --- utils/mount/stropts.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 124 insertions(+), 0 deletions(-) diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c index 5b4cf83..a1ddd99 100644 --- a/utils/mount/stropts.c +++ b/utils/mount/stropts.c @@ -608,6 +608,130 @@ static int try_nfs4mount(const char *spec, const char *node, } /* + * Handle "foreground" NFSv4 mounts. + * + * Retry the mount request for as long as the 'retry=' option says. + * + * Returns a valid mount command return code: zero if successful, + * EX_FAIL if a failure occurred. + */ +static int nfs4mount_fg(const char *spec, const char *node, + int flags, struct mount_options *options, + int fake, char **extra_opts) +{ + unsigned int secs = 1; + time_t timeout = time(NULL); + char *retry; + + retry = po_get(options, "retry"); + if (!retry) + timeout += 60 * 2; /* default: 2 minutes */ + else + timeout += 60 * atoi(retry); + + for (;;) { + if (try_nfs4mount(spec, node, flags, options, + fake, extra_opts)) + return 0; + + if (errno == EINVAL) + break; + + if (time(NULL) > timeout) { + errno = ETIMEDOUT; + break; + } + + if (verbose) + printf(_("%s: will retry until %s\n"), + progname, ctime(&timeout)); + + if (sleep(secs)) + break; + secs <<= 1; + if (secs > 5) + secs = 5; + }; + + mount_error(spec, node, errno); + return EX_FAIL; +} + +/* + * Handle "background" NFSv4 mount [first try] + * + * Returns a valid mount command return code: zero if successful, + * EX_BG if a temporary failure occurred, EX_FAIL if a permanent + * error occurred. + * + * EX_BG should cause the caller to fork and invoke nfsmount_child. + */ +static int nfs4mount_parent(const char *spec, const char *node, + char *hostname, int flags, + struct mount_options *options, + int fake, char **extra_opts) +{ + if (try_nfs4mount(spec, node, flags, options, fake, extra_opts)) + return 0; + + switch(errno) { + /* Permanent errors */ + case EINVAL: + case EBUSY: + mount_error(spec, node, errno); + return EX_FAIL; + /* Everything else */ + default: + sys_mount_errors(hostname, errno, 1, 1); + return EX_BG; + } +} + +/* + * Handle "background" NFSv4 mount [retry daemon] + * + * Returns a valid mount command return code: zero if successful, + * EX_FAIL if a failure occurred. There's nothing to catch the + * error return, though, so we use sys_mount_errors to log the + * failure. + */ +static int nfs4mount_child(const char *spec, const char *node, + char *hostname, int flags, + struct mount_options *options, + int fake, char **extra_opts) +{ + unsigned int secs = 1; + time_t timeout = time(NULL); + char *retry; + + retry = po_get(options, "retry"); + if (!retry) + timeout += 60 * 10000; /* default: 10,000 minutes */ + else + timeout += 60 * atoi(retry); + + for (;;) { + if (sleep(secs)) + break; + secs <<= 1; + if (secs > 30) + secs = 30; + + if (!try_nfs4mount(spec, node, flags, options, + fake, extra_opts)) + return 0; + + if (time(NULL) > timeout) + break; + + sys_mount_errors(hostname, errno, 1, 1); + }; + + sys_mount_errors(hostname, errno, 1, 0); + return EX_FAIL; +} + +/* * nfs4mount_s - Mount an NFSv4 file system using C string options * * @spec: C string hostname:path specifying remoteshare to mount ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ NFS maillist - NFS@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nfs