diff --git a/lib/libzutil/os/linux/zutil_import_os.c b/lib/libzutil/os/linux/zutil_import_os.c index 0a647375b5..433a72282b 100644 --- a/lib/libzutil/os/linux/zutil_import_os.c +++ b/lib/libzutil/os/linux/zutil_import_os.c @@ -76,18 +76,19 @@ #define DEV_BYID_PATH "/dev/disk/by-id/" +/* + * Skip devices with well known prefixes: + * there can be side effects when opening devices which need to be avoided. + * + * hpet - High Precision Event Timer + * watchdog[N] - Watchdog must be closed in a special way. + */ static boolean_t -is_watchdog_dev(char *dev) +should_skip_dev(const char *dev) { - /* For 'watchdog' dev */ - if (strcmp(dev, "watchdog") == 0) - return (B_TRUE); - - /* For 'watchdog */ - if (strstr(dev, "watchdog") == dev && isdigit(dev[8])) - return (B_TRUE); - - return (B_FALSE); + return ((strcmp(dev, "watchdog") == 0) || + (strncmp(dev, "watchdog", 8) == 0 && isdigit(dev[8])) || + (strcmp(dev, "hpet") == 0)); } int @@ -103,24 +104,12 @@ zpool_open_func(void *arg) libpc_handle_t *hdl = rn->rn_hdl; struct stat64 statbuf; nvlist_t *config; - char *bname, *dupname; uint64_t vdev_guid = 0; int error; int num_labels = 0; int fd; - /* - * Skip devices with well known prefixes there can be side effects - * when opening devices which need to be avoided. - * - * hpet - High Precision Event Timer - * watchdog - Watchdog must be closed in a special way. - */ - dupname = zutil_strdup(hdl, rn->rn_name); - bname = basename(dupname); - error = ((strcmp(bname, "hpet") == 0) || is_watchdog_dev(bname)); - free(dupname); - if (error) + if (should_skip_dev(zfs_basename(rn->rn_name))) return; /*