From 947465b9843b588a57703f000783fafd9d9ad68c Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Thu, 4 Aug 2022 20:04:09 -0400 Subject: [PATCH] libzfs: Remove unused zpool_get_physpath() This is an oddly specific function that has never had any consumers in the history of this repo. Get rid of it and the pile of helper functions that exist for it. Reviewed-by: Brian Behlendorf Reviewed-by: Alexander Motin Signed-off-by: Ryan Moeller Closes #13724 --- include/libzfs.h | 1 - lib/libzfs/libzfs.abi | 7 -- lib/libzfs/libzfs_pool.c | 148 --------------------------------------- 3 files changed, 156 deletions(-) diff --git a/include/libzfs.h b/include/libzfs.h index 4948cd0d3..96cf1e186 100644 --- a/include/libzfs.h +++ b/include/libzfs.h @@ -475,7 +475,6 @@ _LIBZFS_H void zpool_obj_to_path_ds(zpool_handle_t *, uint64_t, uint64_t, _LIBZFS_H void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *, size_t); _LIBZFS_H int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *); -_LIBZFS_H int zpool_get_physpath(zpool_handle_t *, char *, size_t); _LIBZFS_H void zpool_explain_recover(libzfs_handle_t *, const char *, int, nvlist_t *); _LIBZFS_H int zpool_checkpoint(zpool_handle_t *); diff --git a/lib/libzfs/libzfs.abi b/lib/libzfs/libzfs.abi index aaef38151..0494aec20 100644 --- a/lib/libzfs/libzfs.abi +++ b/lib/libzfs/libzfs.abi @@ -476,7 +476,6 @@ - @@ -3468,12 +3467,6 @@ - - - - - - diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 877eb2be0..928f8b428 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -2898,154 +2898,6 @@ zpool_find_vdev(zpool_handle_t *zhp, const char *path, boolean_t *avail_spare, return (ret); } -static int -vdev_is_online(nvlist_t *nv) -{ - uint64_t ival; - - if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_OFFLINE, &ival) == 0 || - nvlist_lookup_uint64(nv, ZPOOL_CONFIG_FAULTED, &ival) == 0 || - nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVED, &ival) == 0) - return (0); - - return (1); -} - -/* - * Helper function for zpool_get_physpaths(). - */ -static int -vdev_get_one_physpath(nvlist_t *config, char *physpath, size_t physpath_size, - size_t *bytes_written) -{ - size_t bytes_left, pos, rsz; - char *tmppath; - const char *format; - - if (nvlist_lookup_string(config, ZPOOL_CONFIG_PHYS_PATH, - &tmppath) != 0) - return (EZFS_NODEVICE); - - pos = *bytes_written; - bytes_left = physpath_size - pos; - format = (pos == 0) ? "%s" : " %s"; - - rsz = snprintf(physpath + pos, bytes_left, format, tmppath); - *bytes_written += rsz; - - if (rsz >= bytes_left) { - /* if physpath was not copied properly, clear it */ - if (bytes_left != 0) { - physpath[pos] = 0; - } - return (EZFS_NOSPC); - } - return (0); -} - -static int -vdev_get_physpaths(nvlist_t *nv, char *physpath, size_t phypath_size, - size_t *rsz, boolean_t is_spare) -{ - char *type; - int ret; - - if (nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) != 0) - return (EZFS_INVALCONFIG); - - if (strcmp(type, VDEV_TYPE_DISK) == 0) { - /* - * An active spare device has ZPOOL_CONFIG_IS_SPARE set. - * For a spare vdev, we only want to boot from the active - * spare device. - */ - if (is_spare) { - uint64_t spare = 0; - (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_SPARE, - &spare); - if (!spare) - return (EZFS_INVALCONFIG); - } - - if (vdev_is_online(nv)) { - if ((ret = vdev_get_one_physpath(nv, physpath, - phypath_size, rsz)) != 0) - return (ret); - } - } else if (strcmp(type, VDEV_TYPE_MIRROR) == 0 || - strcmp(type, VDEV_TYPE_RAIDZ) == 0 || - strcmp(type, VDEV_TYPE_REPLACING) == 0 || - (is_spare = (strcmp(type, VDEV_TYPE_SPARE) == 0))) { - nvlist_t **child; - uint_t count; - int i, ret; - - if (nvlist_lookup_nvlist_array(nv, - ZPOOL_CONFIG_CHILDREN, &child, &count) != 0) - return (EZFS_INVALCONFIG); - - for (i = 0; i < count; i++) { - ret = vdev_get_physpaths(child[i], physpath, - phypath_size, rsz, is_spare); - if (ret == EZFS_NOSPC) - return (ret); - } - } - - return (EZFS_POOL_INVALARG); -} - -/* - * Get phys_path for a root pool config. - * Return 0 on success; non-zero on failure. - */ -static int -zpool_get_config_physpath(nvlist_t *config, char *physpath, size_t phypath_size) -{ - size_t rsz; - nvlist_t *vdev_root; - nvlist_t **child; - uint_t count; - char *type; - - rsz = 0; - - if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, - &vdev_root) != 0) - return (EZFS_INVALCONFIG); - - if (nvlist_lookup_string(vdev_root, ZPOOL_CONFIG_TYPE, &type) != 0 || - nvlist_lookup_nvlist_array(vdev_root, ZPOOL_CONFIG_CHILDREN, - &child, &count) != 0) - return (EZFS_INVALCONFIG); - - /* - * root pool can only have a single top-level vdev. - */ - if (strcmp(type, VDEV_TYPE_ROOT) != 0 || count != 1) - return (EZFS_POOL_INVALARG); - - (void) vdev_get_physpaths(child[0], physpath, phypath_size, &rsz, - B_FALSE); - - /* No online devices */ - if (rsz == 0) - return (EZFS_NODEVICE); - - return (0); -} - -/* - * Get phys_path for a root pool - * Return 0 on success; non-zero on failure. - */ -int -zpool_get_physpath(zpool_handle_t *zhp, char *physpath, size_t phypath_size) -{ - return (zpool_get_config_physpath(zhp->zpool_config, physpath, - phypath_size)); -} - /* * Convert a vdev path to a GUID. Returns GUID or 0 on error. *