diff --git a/cmd/zed/agents/zfs_mod.c b/cmd/zed/agents/zfs_mod.c index ecba2d4a563e..6f7f092485b8 100644 --- a/cmd/zed/agents/zfs_mod.c +++ b/cmd/zed/agents/zfs_mod.c @@ -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); } diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 10a3b5b14fc9..ee4d396d2c27 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -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; @@ -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); @@ -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; @@ -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); diff --git a/include/libzfs.h b/include/libzfs.h index a7037e3e6266..509935d03621 100644 --- a/include/libzfs.h +++ b/include/libzfs.h @@ -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 @@ -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 *); diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c index 5d1fe651c97e..3025e2b64c18 100644 --- a/lib/libzfs/libzfs_mount.c +++ b/lib/libzfs/libzfs_mount.c @@ -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 }; @@ -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 @@ -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);