]> err.no Git - util-linux/commitdiff
swapon: add support for "nofail" fstab mount option
authorKarel Zak <kzak@redhat.com>
Mon, 25 Oct 2010 12:03:16 +0000 (14:03 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 25 Oct 2010 12:03:16 +0000 (14:03 +0200)
This option is already supported by mount(8) and fsck(8), there is no
reason to have any exception for swap devices. Note that the --ifexists
command line option applies to all swap devices, the "nofail" setting
is per device.

Signed-off-by: Karel Zak <kzak@redhat.com>
mount/swapon.8
mount/swapon.c

index a3ebc97cdaa8fb08058117d887fbe897bf79b309..595198d51ef0584a1285783c0a0ec0a9ba55718c 100644 (file)
@@ -113,6 +113,12 @@ Devices that are already being used as swap are silently skipped.
 .TP
 .B "\-e, \-\-ifexists"
 Silently skip devices that do not exist.
+The
+.I /etc/fstab
+mount option
+.BI nofail
+may be also used to skip non-existing device.
+
 .TP
 .B "\-f, \-\-fixpgsz"
 Reinitialize (exec /sbin/mkswap) the swap space if its page size does not
index d511492517bfc1832c1dec482482bb2807a39ab2..45cd266993abb8e4cbc97d79f5e4b00aa4b7cadc 100644 (file)
@@ -573,7 +573,7 @@ swapon_all(void) {
 
        while ((fstab = getmntent(fp)) != NULL) {
                const char *special;
-               int skip = 0;
+               int skip = 0, nofail = ifexists;
                int pri = priority;
                char *opt, *opts;
 
@@ -588,6 +588,8 @@ swapon_all(void) {
                                pri = atoi(opt+4);
                        if (strcmp(opt, "noauto") == 0)
                                skip = 1;
+                       if (strcmp(opt, "nofail") == 0)
+                               nofail = 1;
                }
                free(opts);
 
@@ -596,13 +598,13 @@ swapon_all(void) {
 
                special = fsprobe_get_devname_by_spec(fstab->mnt_fsname);
                if (!special) {
-                       if (!ifexists)
+                       if (!nofail)
                                status |= cannot_find(fstab->mnt_fsname);
                        continue;
                }
 
                if (!is_in_proc_swaps(special) &&
-                   (!ifexists || !access(special, R_OK)))
+                   (!nofail || !access(special, R_OK)))
                        status |= do_swapon(special, pri, CANONIC);
 
                free((void *) special);