Skip to content

Commit

Permalink
Relax errors reporting in zpool import and zpool split
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Umer Saleem <[email protected]>
  • Loading branch information
usaleem-ix committed Aug 22, 2023
1 parent b2e707c commit 8b2a586
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/zed/agents/zfs_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ zfs_enable_ds(void *arg)
{
unavailpool_t *pool = (unavailpool_t *)arg;

(void) zpool_enable_datasets(pool->uap_zhp, NULL, 0);
(void) zpool_enable_datasets(pool->uap_zhp, NULL, 0, NULL);
zpool_close(pool->uap_zhp);
free(pool);
}
Expand Down
32 changes: 22 additions & 10 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,7 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
nvlist_t *props, int flags)
{
int ret = 0;
int ms_status = 0;
zpool_handle_t *zhp;
const char *name;
uint64_t version;
Expand Down Expand Up @@ -3232,10 +3233,15 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
ret = 1;

if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
!(flags & ZFS_IMPORT_ONLY) &&
zpool_enable_datasets(zhp, mntopts, 0) != 0) {
zpool_close(zhp);
return (1);
!(flags & ZFS_IMPORT_ONLY)) {
if (zpool_enable_datasets(zhp, mntopts, 0, &ms_status) != 0) {
if (ms_status == SHARE_FAILED)
(void) fprintf(stderr, "Import was successful"
", but unable to share datasets");
else if (ms_status == MOUNT_FAILED)
(void) fprintf(stderr, "Import was successful"
", but unable to mount datasets");
}
}

zpool_close(zhp);
Expand Down Expand Up @@ -6755,6 +6761,7 @@ zpool_do_split(int argc, char **argv)
char *mntopts = NULL;
splitflags_t flags;
int c, ret = 0;
int ms_status = 0;
boolean_t loadkeys = B_FALSE;
zpool_handle_t *zhp;
nvlist_t *config, *props = NULL;
Expand Down Expand Up @@ -6892,12 +6899,17 @@ zpool_do_split(int argc, char **argv)
}

if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
zpool_enable_datasets(zhp, mntopts, 0) != 0) {
ret = 1;
(void) fprintf(stderr, gettext("Split was successful, but "
"the datasets could not all be mounted\n"));
(void) fprintf(stderr, gettext("Try doing '%s' with a "
"different altroot\n"), "zpool import");
zpool_enable_datasets(zhp, mntopts, 0, &ms_status) != 0) {
if (ms_status == SHARE_FAILED) {
(void) fprintf(stderr, gettext("Split was successful, "
"datasets are mounted but sharing the datasets "
"was unsuccessful\n"));
} else if (ms_status == MOUNT_FAILED) {
(void) fprintf(stderr, gettext("Split was successful"
", but the datasets could not all be mounted\n"));
(void) fprintf(stderr, gettext("Try doing '%s' with a "
"different altroot\n"), "zpool import");
}
}
zpool_close(zhp);
nvlist_free(config);
Expand Down
8 changes: 7 additions & 1 deletion include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ typedef enum zfs_error {
EZFS_UNKNOWN
} zfs_error_t;

typedef enum enable_ds_error {
MOUNT_FAILED = -1,
SHARE_FAILED = -2
} enable_ds_error_t;

/*
* The following data structures are all part
* of the zfs_allow_t data structure which is
Expand Down Expand Up @@ -981,7 +986,8 @@ _LIBZFS_H int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *,
* Enable and disable datasets within a pool by mounting/unmounting and
* sharing/unsharing them.
*/
_LIBZFS_H int zpool_enable_datasets(zpool_handle_t *, const char *, int);
_LIBZFS_H int zpool_enable_datasets(zpool_handle_t *, const char *, int,
int *);
_LIBZFS_H int zpool_disable_datasets(zpool_handle_t *, boolean_t);
_LIBZFS_H void zpool_disable_datasets_os(zpool_handle_t *, boolean_t);
_LIBZFS_H void zpool_disable_volume_os(const char *);
Expand Down
1 change: 1 addition & 0 deletions lib/libzfs/libzfs.abi
Original file line number Diff line number Diff line change
Expand Up @@ -5524,6 +5524,7 @@
<parameter type-id='4c81de99' name='zhp'/>
<parameter type-id='80f4b756' name='mntopts'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='7292109c' name='status'/>
<return type-id='95e97e5e'/>
</function-decl>
<function-decl name='zpool_disable_datasets' mangled-name='zpool_disable_datasets' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_disable_datasets'>
Expand Down
13 changes: 10 additions & 3 deletions lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,8 @@ zfs_foreach_mountpoint(libzfs_handle_t *hdl, zfs_handle_t **handles,
* datasets within the pool are currently mounted.
*/
int
zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags,
int *status)
{
get_all_cb_t cb = { 0 };
mount_state_t ms = { 0 };
Expand All @@ -1299,8 +1300,11 @@ zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
ms.ms_mntflags = flags;
zfs_foreach_mountpoint(zhp->zpool_hdl, cb.cb_handles, cb.cb_used,
zfs_mount_one, &ms, B_TRUE);
if (ms.ms_mntstatus != 0)
if (ms.ms_mntstatus != 0) {
ret = ms.ms_mntstatus;
if (status != NULL)
*status = MOUNT_FAILED;
}

/*
* Share all filesystems that need to be shared. This needs to be
Expand All @@ -1310,8 +1314,11 @@ zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
ms.ms_mntstatus = 0;
zfs_foreach_mountpoint(zhp->zpool_hdl, cb.cb_handles, cb.cb_used,
zfs_share_one, &ms, B_FALSE);
if (ms.ms_mntstatus != 0)
if (ms.ms_mntstatus != 0) {
ret = ms.ms_mntstatus;
if (status != NULL)
*status = SHARE_FAILED;
}
else
zfs_commit_shares(NULL);

Expand Down

0 comments on commit 8b2a586

Please sign in to comment.