diff options
author | наб <[email protected]> | 2021-05-22 16:26:40 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2021-06-11 09:10:09 -0700 |
commit | bf80fb53f59c1d98c03758dec6322cfacec4ccf9 (patch) | |
tree | 7e292b170f32b4eeb39b2ba3e3dbd46c28f58d61 | |
parent | 0854d4c186f52066ba0bd2da4282c5fde4bd9326 (diff) |
linux/libzutil: zpool_open_func: don't dup name, extract untouchables
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Ryan Moeller <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12105
-rw-r--r-- | lib/libzutil/os/linux/zutil_import_os.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/lib/libzutil/os/linux/zutil_import_os.c b/lib/libzutil/os/linux/zutil_import_os.c index 0a647375b..433a72282 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<digit><whatever> */ - 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; /* |