Skip to contentSkip to conversation

text-based mount.nfs: Add functions to handle background NFS v2/3 mounts

PATCH New Chuck Lever 1 participant 1 message Sep 11, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 16/19 text-based mount.nfs: Add functions to handle background NFS v2/3 mounts

Add two helper functions that handle background NFS mounts; one for the foreground processing (to try the request, and determine when to fork) and one for the background processing (retry the request as a forked child).

---

 utils/mount/stropts.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)
utils/mount/stropts.c +74 -0
index 0bfa1ab..ba4486b 100644
@@ -448,6 +448,80 @@ static int nfsmount_fg(const char *spec, const char *node,
 }
 
 /*
+ * Handle "background" NFSv2/3 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 nfsmount_parent(const char *spec, const char *node,
+			   char *hostname, int flags,
+			   struct mount_options *options,
+			   int fake, char **extra_opts)
+{
+	if (try_nfsmount(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" NFSv2/3 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 nfsmount_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_nfsmount(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;
+}
+
+/*
  * nfsmount_s - Mount an NFSv2 or v3 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 - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs