]> granicus.if.org Git - zfs/commitdiff
Rework zpool import excluded devices check
authorNikolay Borisov <n.borisov@siteground.com>
Wed, 13 Apr 2016 06:40:42 +0000 (09:40 +0300)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 18 Apr 2016 18:55:22 +0000 (11:55 -0700)
Current zpool import code skips directory entries which have prefixes
similar to some system files on linux such as "fd", "core" etc. However,
this means one cannot have one's zpools hosted inside files which are named
e.g. core-1 or lp. Furthermore, apart from the string checks there is already
which makes the zpool_open_func work only with regular files and block devices.

To fix this problem remove most of the checks since they are redundant but
leave the checks for the 'hpet' and 'watchdog' names. Furthermore, change
the checks to strcmp which albeit less safe than strncmp allows to have
devices whose names are prefixed by 'hpet' or 'watchdog'.

Signed-off-by: Nikolay Borisov <kernel@kyup.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4438

lib/libzfs/libzfs_import.c

index 50c0019ceeed67674fb257269a7599918e443345..8f27ed58c8dfc0d2fd73bed2dd06b85b7df0bd03 100644 (file)
@@ -1353,6 +1353,20 @@ check_slices(avl_tree_t *r, int fd, const char *sname)
 #endif
 }
 
+static boolean_t
+is_watchdog_dev(char *dev)
+{
+       /* For 'watchdog' dev */
+       if (strcmp(dev, "watchdog") == 0)
+               return (B_TRUE);
+
+       /* For 'watchdog<digit><whatever> */
+       if (strstr(dev, "watchdog") == dev && isdigit(dev[8]))
+               return (B_TRUE);
+
+       return (B_FALSE);
+}
+
 static void
 zpool_open_func(void *arg)
 {
@@ -1369,35 +1383,11 @@ zpool_open_func(void *arg)
         * Skip devices with well known prefixes there can be side effects
         * when opening devices which need to be avoided.
         *
-        * core     - Symlink to /proc/kcore
-        * fd*      - Floppy interface.
-        * fuse     - Fuse control device.
         * hpet     - High Precision Event Timer
-        * lp*      - Printer interface.
-        * parport* - Parallel port interface.
-        * ppp      - Generic PPP driver.
-        * random   - Random device
-        * rtc      - Real Time Clock
-        * tty*     - Generic serial interface.
-        * urandom  - Random device.
-        * usbmon*  - USB IO monitor.
-        * vcs*     - Virtual console memory.
         * watchdog - Watchdog must be closed in a special way.
         */
-       if ((strncmp(rn->rn_name, "core", 4) == 0) ||
-           (strncmp(rn->rn_name, "fd", 2) == 0) ||
-           (strncmp(rn->rn_name, "fuse", 4) == 0) ||
-           (strncmp(rn->rn_name, "hpet", 4) == 0) ||
-           (strncmp(rn->rn_name, "lp", 2) == 0) ||
-           (strncmp(rn->rn_name, "parport", 7) == 0) ||
-           (strncmp(rn->rn_name, "ppp", 3) == 0) ||
-           (strncmp(rn->rn_name, "random", 6) == 0) ||
-           (strncmp(rn->rn_name, "rtc", 3) == 0) ||
-           (strncmp(rn->rn_name, "tty", 3) == 0) ||
-           (strncmp(rn->rn_name, "urandom", 7) == 0) ||
-           (strncmp(rn->rn_name, "usbmon", 6) == 0) ||
-           (strncmp(rn->rn_name, "vcs", 3) == 0) ||
-           (strncmp(rn->rn_name, "watchdog", 8) == 0))
+       if ((strcmp(rn->rn_name, "hpet") == 0) ||
+           is_watchdog_dev(rn->rn_name))
                return;
 
        /*