Expose libzutil error info in libpc_handle_t

In libzutil, for zpool_search_import and zpool_find_config, we use
libpc_handle_t internally, which does not maintain error code and it is
not exposed in the interface. Due to this, the error information is not
propagated to the caller. Instead, an error message is printed on
stderr.

This commit adds lpc_error field in libpc_handle_t and exposes it in
the interface, which can be used by the users of libzutil to get the
appropriate error information and handle it accordingly.

Users of the API can also control if they want to print the error
message on stderr.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Umer Saleem <usaleem@ixsystems.com>
Closes #13969
This commit is contained in:
Umer Saleem
2022-09-26 18:40:43 +05:00
committed by Brian Behlendorf
parent d62bafee9f
commit d9ac17a57f
8 changed files with 130 additions and 69 deletions
-15
View File
@@ -28,26 +28,11 @@
#ifndef _LIBZUTIL_ZUTIL_IMPORT_H_
#define _LIBZUTIL_ZUTIL_IMPORT_H_
#define EZFS_BADCACHE "invalid or missing cache file"
#define EZFS_BADPATH "must be an absolute path"
#define EZFS_NOMEM "out of memory"
#define EZFS_EACESS "some devices require root privileges"
#define IMPORT_ORDER_PREFERRED_1 1
#define IMPORT_ORDER_PREFERRED_2 2
#define IMPORT_ORDER_SCAN_OFFSET 10
#define IMPORT_ORDER_DEFAULT 100
typedef struct libpc_handle {
boolean_t lpc_printerr;
boolean_t lpc_open_access_error;
boolean_t lpc_desc_active;
char lpc_desc[1024];
pool_config_ops_t *lpc_ops;
void *lpc_lib_handle;
} libpc_handle_t;
int label_paths(libpc_handle_t *hdl, nvlist_t *label, char **path,
char **devid);
int zpool_find_import_blkid(libpc_handle_t *hdl, pthread_mutex_t *lock,