From bf80fb53f59c1d98c03758dec6322cfacec4ccf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sat, 22 May 2021 16:26:40 +0200 Subject: [PATCH] linux/libzutil: zpool_open_func: don't dup name, extract untouchables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: John Kennedy Reviewed-by: Brian Behlendorf Reviewed-by: Ryan Moeller Signed-off-by: Ahelenia ZiemiaƄska Closes #12105 --- lib/libzutil/os/linux/zutil_import_os.c | 35 +++++++++---------------- 1 file 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 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; /*