Skip to content

Commit a9410cc

Browse files
authored
Make zpool_find_config() report errors
All of zpool_find_config() callers now set lpc_printerr. Actually printing the errors when pool can not be found should make zdb a half percent less confusing. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Closes #17642
1 parent 2c877e8 commit a9410cc

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

lib/libzutil/zutil_import.c

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,30 +1903,43 @@ zpool_find_config(libpc_handle_t *hdl, const char *target, nvlist_t **configp,
19031903
*sepp = '\0';
19041904

19051905
pools = zpool_search_import(hdl, args);
1906+
if (pools == NULL) {
1907+
zutil_error_aux(hdl, dgettext(TEXT_DOMAIN, "no pools found"));
1908+
(void) zutil_error_fmt(hdl, LPC_UNKNOWN, dgettext(TEXT_DOMAIN,
1909+
"failed to find config for pool '%s'"), targetdup);
1910+
free(targetdup);
1911+
return (ENOENT);
1912+
}
19061913

1907-
if (pools != NULL) {
1908-
nvpair_t *elem = NULL;
1909-
while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
1910-
VERIFY0(nvpair_value_nvlist(elem, &config));
1911-
if (pool_match(config, targetdup)) {
1912-
count++;
1913-
if (match != NULL) {
1914-
/* multiple matches found */
1915-
continue;
1916-
} else {
1917-
match = fnvlist_dup(config);
1918-
}
1914+
nvpair_t *elem = NULL;
1915+
while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
1916+
VERIFY0(nvpair_value_nvlist(elem, &config));
1917+
if (pool_match(config, targetdup)) {
1918+
count++;
1919+
if (match != NULL) {
1920+
/* multiple matches found */
1921+
continue;
1922+
} else {
1923+
match = fnvlist_dup(config);
19191924
}
19201925
}
1921-
fnvlist_free(pools);
19221926
}
1927+
fnvlist_free(pools);
19231928

19241929
if (count == 0) {
1930+
zutil_error_aux(hdl, dgettext(TEXT_DOMAIN,
1931+
"no matching pools"));
1932+
(void) zutil_error_fmt(hdl, LPC_UNKNOWN, dgettext(TEXT_DOMAIN,
1933+
"failed to find config for pool '%s'"), targetdup);
19251934
free(targetdup);
19261935
return (ENOENT);
19271936
}
19281937

19291938
if (count > 1) {
1939+
zutil_error_aux(hdl, dgettext(TEXT_DOMAIN,
1940+
"more than one matching pool"));
1941+
(void) zutil_error_fmt(hdl, LPC_UNKNOWN, dgettext(TEXT_DOMAIN,
1942+
"failed to find config for pool '%s'"), targetdup);
19301943
free(targetdup);
19311944
fnvlist_free(match);
19321945
return (EINVAL);

0 commit comments

Comments
 (0)