summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNikolay Borisov <[email protected]>2016-04-13 09:40:42 +0300
committerBrian Behlendorf <[email protected]>2016-04-18 11:55:22 -0700
commit8fc5674c522e22f0b97e4714bf5410e24d481afa (patch)
tree04c7683c08e47eb1cba9a62ff30d81875b535bf1 /lib
parent98f03691a4c08f38ca4538c468e9523f8e6b24be (diff)
Rework zpool import excluded devices check
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 <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #4438
Diffstat (limited to 'lib')
-rw-r--r--lib/libzfs/libzfs_import.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c
index 50c0019ce..8f27ed58c 100644
--- a/lib/libzfs/libzfs_import.c
+++ b/lib/libzfs/libzfs_import.c
@@ -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;
/*