aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorнаб <[email protected]>2022-05-03 19:33:31 +0200
committerBrian Behlendorf <[email protected]>2022-05-16 15:56:27 -0700
commite9072c76f832dc649d27cdb7cd739b3e73fbed37 (patch)
treea92fb1f0b4a2059036225454621bedef3312be7f /cmd
parentde8216451840add3be18df0d9fa423a30e35e8a6 (diff)
zpool: max_width: monomorphise subtype iteration
Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #13413
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zpool/zpool_main.c43
1 files changed, 12 insertions, 31 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index bfe798ffe..ac4a0b23a 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -1987,40 +1987,21 @@ static int
max_width(zpool_handle_t *zhp, nvlist_t *nv, int depth, int max,
int name_flags)
{
- char *name;
- nvlist_t **child;
- uint_t c, children;
- int ret;
-
- name = zpool_vdev_name(g_zfs, zhp, nv, name_flags);
- if (strlen(name) + depth > max)
- max = strlen(name) + depth;
+ static const char *const subtypes[] =
+ {ZPOOL_CONFIG_SPARES, ZPOOL_CONFIG_L2CACHE, ZPOOL_CONFIG_CHILDREN};
+ char *name = zpool_vdev_name(g_zfs, zhp, nv, name_flags);
+ max = MAX(strlen(name) + depth, max);
free(name);
- if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
- &child, &children) == 0) {
- for (c = 0; c < children; c++)
- if ((ret = max_width(zhp, child[c], depth + 2,
- max, name_flags)) > max)
- max = ret;
- }
-
- if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
- &child, &children) == 0) {
- for (c = 0; c < children; c++)
- if ((ret = max_width(zhp, child[c], depth + 2,
- max, name_flags)) > max)
- max = ret;
- }
-
- if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
- &child, &children) == 0) {
- for (c = 0; c < children; c++)
- if ((ret = max_width(zhp, child[c], depth + 2,
- max, name_flags)) > max)
- max = ret;
- }
+ nvlist_t **child;
+ uint_t children;
+ for (size_t i = 0; i < ARRAY_SIZE(subtypes); ++i)
+ if (nvlist_lookup_nvlist_array(nv, subtypes[i],
+ &child, &children) == 0)
+ for (uint_t c = 0; c < children; ++c)
+ max = MAX(max_width(zhp, child[c], depth + 2,
+ max, name_flags), max);
return (max);
}