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
1 changed files with 12 additions and 23 deletions

View File

@ -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;
/*