linux/libzutil: zpool_open_func: don't dup name, extract untouchables

Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12105
This commit is contained in:
наб 2021-05-22 16:26:40 +02:00 committed by Brian Behlendorf
parent 0854d4c186
commit bf80fb53f5

View File

@ -76,18 +76,19 @@
#define DEV_BYID_PATH "/dev/disk/by-id/" #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 static boolean_t
is_watchdog_dev(char *dev) should_skip_dev(const char *dev)
{ {
/* For 'watchdog' dev */ return ((strcmp(dev, "watchdog") == 0) ||
if (strcmp(dev, "watchdog") == 0) (strncmp(dev, "watchdog", 8) == 0 && isdigit(dev[8])) ||
return (B_TRUE); (strcmp(dev, "hpet") == 0));
/* For 'watchdog<digit><whatever> */
if (strstr(dev, "watchdog") == dev && isdigit(dev[8]))
return (B_TRUE);
return (B_FALSE);
} }
int int
@ -103,24 +104,12 @@ zpool_open_func(void *arg)
libpc_handle_t *hdl = rn->rn_hdl; libpc_handle_t *hdl = rn->rn_hdl;
struct stat64 statbuf; struct stat64 statbuf;
nvlist_t *config; nvlist_t *config;
char *bname, *dupname;
uint64_t vdev_guid = 0; uint64_t vdev_guid = 0;
int error; int error;
int num_labels = 0; int num_labels = 0;
int fd; int fd;
/* if (should_skip_dev(zfs_basename(rn->rn_name)))
* 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)
return; return;
/* /*