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 <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <alexander.motin@TrueNAS.com>
Closes #17642
This commit is contained in:
Alexander Motin 2025-08-19 16:09:25 -04:00 committed by GitHub
parent 2c877e8453
commit a9410ccbd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1903,30 +1903,43 @@ zpool_find_config(libpc_handle_t *hdl, const char *target, nvlist_t **configp,
*sepp = '\0'; *sepp = '\0';
pools = zpool_search_import(hdl, args); pools = zpool_search_import(hdl, args);
if (pools == NULL) {
if (pools != NULL) { zutil_error_aux(hdl, dgettext(TEXT_DOMAIN, "no pools found"));
nvpair_t *elem = NULL; (void) zutil_error_fmt(hdl, LPC_UNKNOWN, dgettext(TEXT_DOMAIN,
while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) { "failed to find config for pool '%s'"), targetdup);
VERIFY0(nvpair_value_nvlist(elem, &config)); free(targetdup);
if (pool_match(config, targetdup)) { return (ENOENT);
count++;
if (match != NULL) {
/* multiple matches found */
continue;
} else {
match = fnvlist_dup(config);
}
}
}
fnvlist_free(pools);
} }
nvpair_t *elem = NULL;
while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
VERIFY0(nvpair_value_nvlist(elem, &config));
if (pool_match(config, targetdup)) {
count++;
if (match != NULL) {
/* multiple matches found */
continue;
} else {
match = fnvlist_dup(config);
}
}
}
fnvlist_free(pools);
if (count == 0) { if (count == 0) {
zutil_error_aux(hdl, dgettext(TEXT_DOMAIN,
"no matching pools"));
(void) zutil_error_fmt(hdl, LPC_UNKNOWN, dgettext(TEXT_DOMAIN,
"failed to find config for pool '%s'"), targetdup);
free(targetdup); free(targetdup);
return (ENOENT); return (ENOENT);
} }
if (count > 1) { if (count > 1) {
zutil_error_aux(hdl, dgettext(TEXT_DOMAIN,
"more than one matching pool"));
(void) zutil_error_fmt(hdl, LPC_UNKNOWN, dgettext(TEXT_DOMAIN,
"failed to find config for pool '%s'"), targetdup);
free(targetdup); free(targetdup);
fnvlist_free(match); fnvlist_free(match);
return (EINVAL); return (EINVAL);