svn commit: r330745 - head/sys/kern

Ian Lepore ian at FreeBSD.org
Sat Mar 10 22:07:58 UTC 2018


Author: ian
Date: Sat Mar 10 22:07:57 2018
New Revision: 330745
URL: https://svnweb.freebsd.org/changeset/base/330745

Log:
  Make root mount timeout logic work for filesystems other than ufs.
  
  The vfs.mountroot.timeout tunable and .timeout directive in a mount.conf(5)
  file allow specifying a wait timeout for the device(s) hosting the root
  filesystem to become usable.  The current mechanism for waiting for devices
  and detecting their availability can't be used for zfs-hosted filesystems.
  See the comment #20 in the PR for some expanded detail on these points.
  
  This change adds retry logic to the actual root filesystem mount.  That is,
  insted of relying on device availability using device name lookups, it uses
  the kernel_mount() call itself to detect whether the filesystem can be
  mounted, and loops until it succeeds or the configured timeout is exceeded.
  
  These changes are based on the patch attached to the PR, but it's rewritten
  enough that all mistakes belong to me.
  
  PR:		208882
  X-MFC after:	sufficient testing, and hopefully in time for 11.1

Modified:
  head/sys/kern/vfs_mountroot.c

Modified: head/sys/kern/vfs_mountroot.c
==============================================================================
--- head/sys/kern/vfs_mountroot.c	Sat Mar 10 20:46:36 2018	(r330744)
+++ head/sys/kern/vfs_mountroot.c	Sat Mar 10 22:07:57 2018	(r330745)
@@ -714,7 +714,7 @@ parse_mount(char **conf)
 	char *errmsg;
 	struct mntarg *ma;
 	char *dev, *fs, *opts, *tok;
-	int error;
+	int delay, error, timeout;
 
 	error = parse_token(conf, &tok);
 	if (error)
@@ -755,15 +755,31 @@ parse_mount(char **conf)
 	if (error != 0)
 		goto out;
 
-	ma = NULL;
-	ma = mount_arg(ma, "fstype", fs, -1);
-	ma = mount_arg(ma, "fspath", "/", -1);
-	ma = mount_arg(ma, "from", dev, -1);
-	ma = mount_arg(ma, "errmsg", errmsg, ERRMSGL);
-	ma = mount_arg(ma, "ro", NULL, 0);
-	ma = parse_mountroot_options(ma, opts);
-	error = kernel_mount(ma, MNT_ROOTFS);
+	delay = hz / 10;
+	timeout = root_mount_timeout * hz;
 
+	for (;;) {
+		ma = NULL;
+		ma = mount_arg(ma, "fstype", fs, -1);
+		ma = mount_arg(ma, "fspath", "/", -1);
+		ma = mount_arg(ma, "from", dev, -1);
+		ma = mount_arg(ma, "errmsg", errmsg, ERRMSGL);
+		ma = mount_arg(ma, "ro", NULL, 0);
+		ma = parse_mountroot_options(ma, opts);
+
+		error = kernel_mount(ma, MNT_ROOTFS);
+		if (error == 0 || timeout <= 0)
+			break;
+
+		if (root_mount_timeout * hz == timeout ||
+		    (bootverbose && timeout % hz == 0)) {
+			printf("Mounting from %s:%s failed with error %d; "
+			    "retrying for %d more second%s\n", fs, dev, error,
+			    timeout / hz, (timeout / hz > 1) ? "s" : "");
+		}
+		pause("rmretry", delay);
+		timeout -= delay;
+	}
  out:
 	if (error) {
 		printf("Mounting from %s:%s failed with error %d",


More information about the svn-src-head mailing list