From bd06e62ec85319d50df8a7a65fbc7939d8d14411 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Mon, 12 Aug 2013 14:59:25 -0400 Subject: [PATCH] Revert #3464 changes that crept into #2882 commit Signed-off-by: Richard Yao --- cmd/zfs/zfs_main.c | 4 +-- include/libzfs.h | 2 +- lib/libzfs/libzfs_dataset.c | 54 +++++++++++++++++-------------------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index db007dc1e8a3..fdae6a5119ba 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -1146,7 +1146,7 @@ zfs_do_destroy(int argc, char **argv) { destroy_cbdata_t cb = { 0 }; int c; - zfs_handle_t *zhp = NULL; + zfs_handle_t *zhp; char *at; zfs_type_t type = ZFS_TYPE_DATASET; @@ -1247,7 +1247,7 @@ zfs_do_destroy(int argc, char **argv) if (cb.cb_doclones) err = destroy_clones(&cb); if (err == 0) { - err = zfs_destroy_snaps_nvl(g_zfs, cb.cb_nvl, + err = zfs_destroy_snaps_nvl(zhp, cb.cb_nvl, cb.cb_defer_destroy); } } diff --git a/include/libzfs.h b/include/libzfs.h index 55033d4192dc..d51a71d7598b 100644 --- a/include/libzfs.h +++ b/include/libzfs.h @@ -563,7 +563,7 @@ extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t, extern int zfs_create_ancestors(libzfs_handle_t *, const char *); extern int zfs_destroy(zfs_handle_t *, boolean_t); extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t); -extern int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t); +extern int zfs_destroy_snaps_nvl(zfs_handle_t *, nvlist_t *, boolean_t); extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); extern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index 20d3b99d42d1..5da1cfaae595 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -3189,50 +3189,46 @@ zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer) dgettext(TEXT_DOMAIN, "cannot destroy '%s@%s'"), zhp->zfs_name, snapname); } else { - ret = zfs_destroy_snaps_nvl(zhp->zfs_hdl, dd.nvl, defer); + ret = zfs_destroy_snaps_nvl(zhp, dd.nvl, defer); } nvlist_free(dd.nvl); return (ret); } /* - * Destroys all the snapshots named in the nvlist. + * Destroys all the snapshots named in the nvlist. They must be underneath + * the zhp (either snapshots of it, or snapshots of its descendants). */ int -zfs_destroy_snaps_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, boolean_t defer) +zfs_destroy_snaps_nvl(zfs_handle_t *zhp, nvlist_t *snaps, boolean_t defer) { int ret; nvlist_t *errlist; - nvpair_t *pair; ret = lzc_destroy_snaps(snaps, defer, &errlist); - if (ret == 0) - return (0); - - if (nvlist_next_nvpair(errlist, NULL) == NULL) { - char errbuf[1024]; - (void) snprintf(errbuf, sizeof (errbuf), - dgettext(TEXT_DOMAIN, "cannot destroy snapshots")); - - ret = zfs_standard_error(hdl, ret, errbuf); - } - for (pair = nvlist_next_nvpair(errlist, NULL); - pair != NULL; pair = nvlist_next_nvpair(errlist, pair)) { - char errbuf[1024]; - (void) snprintf(errbuf, sizeof (errbuf), - dgettext(TEXT_DOMAIN, "cannot destroy snapshot %s"), - nvpair_name(pair)); + if (ret != 0) { + nvpair_t *pair; + for (pair = nvlist_next_nvpair(errlist, NULL); + pair != NULL; pair = nvlist_next_nvpair(errlist, pair)) { + char errbuf[1024]; + (void) snprintf(errbuf, sizeof (errbuf), + dgettext(TEXT_DOMAIN, "cannot destroy snapshot %s"), + nvpair_name(pair)); - switch (fnvpair_value_int32(pair)) { - case EEXIST: - zfs_error_aux(hdl, - dgettext(TEXT_DOMAIN, "snapshot is cloned")); - ret = zfs_error(hdl, EZFS_EXISTS, errbuf); - break; - default: - ret = zfs_standard_error(hdl, errno, errbuf); - break; + switch (fnvpair_value_int32(pair)) { + case EEXIST: + zfs_error_aux(zhp->zfs_hdl, + dgettext(TEXT_DOMAIN, + "snapshot is cloned")); + ret = zfs_error(zhp->zfs_hdl, EZFS_EXISTS, + errbuf); + break; + default: + ret = zfs_standard_error(zhp->zfs_hdl, errno, + errbuf); + break; + } } }