Relax error reporting in zpool import and zpool split

For zpool import and zpool split, zpool_enable_datasets is called
to mount and share all datasets in a pool. If there is an error
while mounting or sharing any dataset in the pool, the status of
import or split is reported as failure. However, the changes do
show up in zpool list.

This commit updates the error reporting in zpool import and zpool
split path. More descriptive messages are shown to user in case
there is an error during mount or share. Errors in mount or share
do not effect the overall status of zpool import and zpool split.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Umer Saleem <usaleem@ixsystems.com>
Closes #15216
This commit is contained in:
Umer Saleem 2023-09-02 05:25:11 +05:00 committed by GitHub
parent bcb1159c09
commit 71472bf375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 13 deletions

View File

@ -3143,6 +3143,7 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
nvlist_t *props, int flags) nvlist_t *props, int flags)
{ {
int ret = 0; int ret = 0;
int ms_status = 0;
zpool_handle_t *zhp; zpool_handle_t *zhp;
const char *name; const char *name;
uint64_t version; uint64_t version;
@ -3232,10 +3233,15 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
ret = 1; ret = 1;
if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL && if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
!(flags & ZFS_IMPORT_ONLY) && !(flags & ZFS_IMPORT_ONLY)) {
zpool_enable_datasets(zhp, mntopts, 0) != 0) { ms_status = zpool_enable_datasets(zhp, mntopts, 0);
zpool_close(zhp); if (ms_status == EZFS_SHAREFAILED) {
return (1); (void) fprintf(stderr, gettext("Import was "
"successful, but unable to share some datasets"));
} else if (ms_status == EZFS_MOUNTFAILED) {
(void) fprintf(stderr, gettext("Import was "
"successful, but unable to mount some datasets"));
}
} }
zpool_close(zhp); zpool_close(zhp);
@ -6755,6 +6761,7 @@ zpool_do_split(int argc, char **argv)
char *mntopts = NULL; char *mntopts = NULL;
splitflags_t flags; splitflags_t flags;
int c, ret = 0; int c, ret = 0;
int ms_status = 0;
boolean_t loadkeys = B_FALSE; boolean_t loadkeys = B_FALSE;
zpool_handle_t *zhp; zpool_handle_t *zhp;
nvlist_t *config, *props = NULL; nvlist_t *config, *props = NULL;
@ -6891,13 +6898,18 @@ zpool_do_split(int argc, char **argv)
ret = 1; ret = 1;
} }
if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL && if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL) {
zpool_enable_datasets(zhp, mntopts, 0) != 0) { ms_status = zpool_enable_datasets(zhp, mntopts, 0);
ret = 1; if (ms_status == EZFS_SHAREFAILED) {
(void) fprintf(stderr, gettext("Split was successful, but " (void) fprintf(stderr, gettext("Split was successful, "
"the datasets could not all be mounted\n")); "datasets are mounted but sharing of some datasets "
(void) fprintf(stderr, gettext("Try doing '%s' with a " "has failed\n"));
"different altroot\n"), "zpool import"); } else if (ms_status == EZFS_MOUNTFAILED) {
(void) fprintf(stderr, gettext("Split was successful"
", but some datasets could not be mounted\n"));
(void) fprintf(stderr, gettext("Try doing '%s' with a "
"different altroot\n"), "zpool import");
}
} }
zpool_close(zhp); zpool_close(zhp);
nvlist_free(config); nvlist_free(config);

View File

@ -156,6 +156,7 @@ typedef enum zfs_error {
EZFS_NOT_USER_NAMESPACE, /* a file is not a user namespace */ EZFS_NOT_USER_NAMESPACE, /* a file is not a user namespace */
EZFS_CKSUM, /* insufficient replicas */ EZFS_CKSUM, /* insufficient replicas */
EZFS_RESUME_EXISTS, /* Resume on existing dataset without force */ EZFS_RESUME_EXISTS, /* Resume on existing dataset without force */
EZFS_SHAREFAILED, /* filesystem share failed */
EZFS_UNKNOWN EZFS_UNKNOWN
} zfs_error_t; } zfs_error_t;

View File

@ -1300,7 +1300,7 @@ zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
zfs_foreach_mountpoint(zhp->zpool_hdl, cb.cb_handles, cb.cb_used, zfs_foreach_mountpoint(zhp->zpool_hdl, cb.cb_handles, cb.cb_used,
zfs_mount_one, &ms, B_TRUE); zfs_mount_one, &ms, B_TRUE);
if (ms.ms_mntstatus != 0) if (ms.ms_mntstatus != 0)
ret = ms.ms_mntstatus; ret = EZFS_MOUNTFAILED;
/* /*
* Share all filesystems that need to be shared. This needs to be * Share all filesystems that need to be shared. This needs to be
@ -1311,7 +1311,7 @@ zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
zfs_foreach_mountpoint(zhp->zpool_hdl, cb.cb_handles, cb.cb_used, zfs_foreach_mountpoint(zhp->zpool_hdl, cb.cb_handles, cb.cb_used,
zfs_share_one, &ms, B_FALSE); zfs_share_one, &ms, B_FALSE);
if (ms.ms_mntstatus != 0) if (ms.ms_mntstatus != 0)
ret = ms.ms_mntstatus; ret = EZFS_SHAREFAILED;
else else
zfs_commit_shares(NULL); zfs_commit_shares(NULL);