Re: [PATCH] mount: nofail mount option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 13, 2007 at 11:21:23AM +0200, Kay Sievers wrote:
> On 7/12/07, Matthias Koenig <mkoenig@xxxxxxx> wrote:
> >it would be nice to have a mount option "nofail" indicating
> >that mount should not return an error if the device does not
> >exit. This is useful for hotpluggable devices which are configured
> >in fstab and might not exist at boot time.
> 
> We should probably ignore failures of a failed mount syscall too?
> The device node may exist, even when there is no kernel device at the
> moment as as some subsystems like md create a bunch of nodes
> unconditionally.

 Yes. It seems mount(2) returns ENXIO, ENOTBLK, ENOENT or ENOTDIR when
 something is wrong with source device.

 Please, see updated patch below.

        Karel

>From a2b13fb0bced6525c2e47cdc6f4f9ebb8259f7b4 Mon Sep 17 00:00:00 2001
From: Matthias Koenig <mkoenig@xxxxxxx>
Date: Mon, 17 Dec 2007 11:33:20 +0100
Subject: [PATCH] mount: "nofail" mount option

It would be nice to have a mount option "nofail" indicating that mount
should not return an error if the device does not exit. This is useful
for hotpluggable devices which are configured in fstab and __might__
not exist at boot time.

Co-Author: Karel Zak <kzak@xxxxxxxxxx>
Signed-off-by: Matthias Koenig <mkoenig@xxxxxxx>
Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
 mount/mount.8 |    3 +++
 mount/mount.c |   21 +++++++++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/mount/mount.8 b/mount/mount.8
index 54b11d4..ce52dd8 100644
--- a/mount/mount.8
+++ b/mount/mount.8
@@ -615,6 +615,9 @@ This option implies the options
 (unless overridden by subsequent options, as in the option line
 .BR group,dev,suid ).
 .TP
+.B nofail
+Do not report errors for this device if it does not exist.
+.TP
 .B mand
 Allow mandatory locks on this filesystem. See
 .BR fcntl (2).
diff --git a/mount/mount.c b/mount/mount.c
index 917f62a..0688c57 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -176,9 +176,12 @@ static const struct opt_map opt_map[] = {
   { "norelatime", 0, 1, MS_RELATIME }, /* Update access time without regard
 					  to mtime/ctime */
 #endif
+  { "nofail",	0, 0, MS_COMMENT},	/* Do not fail if ENOENT on dev */
   { NULL,	0, 0, 0		}
 };
 
+static int opt_nofail = 0;
+
 static const char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_encryption,
 	*opt_speed, *opt_comment, *opt_uhelper;
 
@@ -383,6 +386,8 @@ parse_opt(char *opt, int *mask, char **extra_opts) {
 				verbose = 0;
 			}
 #endif
+			if (streq(opt, "nofail"))
+				opt_nofail = 1;
 			return;
 		}
 
@@ -1198,9 +1203,11 @@ try_mount_one (const char *spec0, const char *node0, const char *types0,
       else if (stat (node, &statbuf))
 	   error (_("mount: mount point %s is a symbolic link to nowhere"),
 		  node);
-      else if (stat (spec, &statbuf))
+      else if (stat (spec, &statbuf)) {
+	   if (opt_nofail)
+		goto out;
 	   error (_("mount: special device %s does not exist"), spec);
-      else {
+      } else {
 	   errno = mnt_err;
 	   perror("mount");
       }
@@ -1208,10 +1215,12 @@ try_mount_one (const char *spec0, const char *node0, const char *types0,
     case ENOTDIR:
       if (stat (node, &statbuf) || ! S_ISDIR(statbuf.st_mode))
 	   error (_("mount: mount point %s is not a directory"), node);
-      else if (stat (spec, &statbuf) && errno == ENOTDIR)
+      else if (stat (spec, &statbuf) && errno == ENOTDIR) {
+	   if (opt_nofail)
+              goto out;
 	   error (_("mount: special device %s does not exist\n"
 		    "       (a path prefix is not a directory)\n"), spec);
-      else {
+      } else {
 	   errno = mnt_err;
 	   perror("mount");
       }
@@ -1296,6 +1305,8 @@ try_mount_one (const char *spec0, const char *node0, const char *types0,
       break;
     }
     case ENOTBLK:
+      if (opt_nofail)
+        goto out;
       if (stat (spec, &statbuf)) /* strange ... */
 	error (_("mount: %s is not a block device, and stat fails?"), spec);
       else if (S_ISBLK(statbuf.st_mode))
@@ -1308,6 +1319,8 @@ try_mount_one (const char *spec0, const char *node0, const char *types0,
 	error (_("mount: %s is not a block device"), spec);
       break;
     case ENXIO:
+      if (opt_nofail)
+        goto out;
       error (_("mount: %s is not a valid block device"), spec); break;
     case EACCES:  /* pre-linux 1.1.38, 1.1.41 and later */
     case EROFS:   /* linux 1.1.38 and later */
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux