Permalink
Browse files

3464 zfs synctask code needs restructuring

Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Approved by: Garrett D'Amore <garrett@damore.org>
  • Loading branch information...
1 parent 584d084 commit 3b2aab18808792cbd248a12f1edf139b89833c13 @ahrens ahrens committed with Christopher Siden Feb 28, 2013
Showing with 6,501 additions and 6,044 deletions.
  1. +1 −1 usr/src/cmd/mdb/common/modules/zfs/zfs.c
  2. +2 −2 usr/src/cmd/ndmpd/ndmp/ndmpd_chkpnt.c
  3. +2 −3 usr/src/cmd/truss/expound.c
  4. +6 −3 usr/src/cmd/zdb/zdb.c
  5. +66 −50 usr/src/cmd/zfs/zfs_main.c
  6. +14 −13 usr/src/cmd/zhack/zhack.c
  7. +108 −82 usr/src/cmd/ztest/ztest.c
  8. +13 −0 usr/src/common/nvpair/fnvpair.c
  9. +1 −0 usr/src/lib/libnvpair/mapfile-vers
  10. +3 −3 usr/src/lib/libzfs/common/libzfs.h
  11. +194 −122 usr/src/lib/libzfs/common/libzfs_dataset.c
  12. +4 −8 usr/src/lib/libzfs/common/libzfs_sendrecv.c
  13. +98 −4 usr/src/lib/libzfs_core/common/libzfs_core.c
  14. +4 −0 usr/src/lib/libzfs_core/common/libzfs_core.h
  15. +3 −0 usr/src/lib/libzfs_core/common/mapfile-vers
  16. +5 −0 usr/src/lib/libzpool/common/kernel.c
  17. +3 −0 usr/src/lib/libzpool/common/llib-lzpool
  18. +14 −1 usr/src/lib/libzpool/common/sys/zfs_context.h
  19. +4 −2 usr/src/man/man1m/zfs.1m
  20. +3 −1 usr/src/uts/common/Makefile.files
  21. +5 −5 usr/src/uts/common/fs/zfs/arc.c
  22. +8 −0 usr/src/uts/common/fs/zfs/bplist.c
  23. +4 −0 usr/src/uts/common/fs/zfs/bpobj.c
  24. +34 −51 usr/src/uts/common/fs/zfs/dbuf.c
  25. +1 −1 usr/src/uts/common/fs/zfs/dmu.c
  26. +41 −39 usr/src/uts/common/fs/zfs/dmu_diff.c
  27. +380 −475 usr/src/uts/common/fs/zfs/dmu_objset.c
  28. +466 −445 usr/src/uts/common/fs/zfs/dmu_send.c
  29. +24 −18 usr/src/uts/common/fs/zfs/dmu_traverse.c
  30. +16 −15 usr/src/uts/common/fs/zfs/dmu_tx.c
  31. +5 −1 usr/src/uts/common/fs/zfs/dnode.c
  32. +1 −0 usr/src/uts/common/fs/zfs/dnode_sync.c
  33. +1,380 −2,746 usr/src/uts/common/fs/zfs/dsl_dataset.c
  34. +80 −58 usr/src/uts/common/fs/zfs/dsl_deleg.c
  35. +926 −0 usr/src/uts/common/fs/zfs/dsl_destroy.c
  36. +258 −329 usr/src/uts/common/fs/zfs/dsl_dir.c
  37. +156 −60 usr/src/uts/common/fs/zfs/dsl_pool.c
  38. +235 −240 usr/src/uts/common/fs/zfs/dsl_prop.c
  39. +57 −61 usr/src/uts/common/fs/zfs/dsl_scan.c
  40. +90 −153 usr/src/uts/common/fs/zfs/dsl_synctask.c
  41. +536 −0 usr/src/uts/common/fs/zfs/dsl_userhold.c
  42. +38 −0 usr/src/uts/common/fs/zfs/metaslab.c
  43. +14 −7 usr/src/uts/common/fs/zfs/refcount.c
  44. +26 −15 usr/src/uts/common/fs/zfs/rrwlock.c
  45. +3 −3 usr/src/uts/common/fs/zfs/sa.c
  46. +43 −38 usr/src/uts/common/fs/zfs/spa.c
  47. +10 −16 usr/src/uts/common/fs/zfs/spa_history.c
  48. +11 −12 usr/src/uts/common/fs/zfs/spa_misc.c
  49. +21 −22 usr/src/uts/common/fs/zfs/space_map.c
  50. +1 −1 usr/src/uts/common/fs/zfs/sys/arc.h
  51. +3 −6 usr/src/uts/common/fs/zfs/sys/dbuf.h
  52. +13 −39 usr/src/uts/common/fs/zfs/sys/dmu.h
  53. +6 −5 usr/src/uts/common/fs/zfs/sys/dmu_objset.h
  54. +66 −0 usr/src/uts/common/fs/zfs/sys/dmu_send.h
  55. +5 −1 usr/src/uts/common/fs/zfs/sys/dmu_tx.h
  56. +51 −61 usr/src/uts/common/fs/zfs/sys/dsl_dataset.h
  57. +52 −0 usr/src/uts/common/fs/zfs/sys/dsl_destroy.h
  58. +8 −9 usr/src/uts/common/fs/zfs/sys/dsl_dir.h
  59. +11 −5 usr/src/uts/common/fs/zfs/sys/dsl_pool.h
  60. +21 −32 usr/src/uts/common/fs/zfs/sys/dsl_prop.h
  61. +15 −31 usr/src/uts/common/fs/zfs/sys/dsl_synctask.h
  62. +57 −0 usr/src/uts/common/fs/zfs/sys/dsl_userhold.h
  63. +2 −1 usr/src/uts/common/fs/zfs/sys/metaslab.h
  64. +4 −1 usr/src/uts/common/fs/zfs/sys/refcount.h
  65. +6 −1 usr/src/uts/common/fs/zfs/sys/rrwlock.h
  66. +2 −0 usr/src/uts/common/fs/zfs/sys/space_map.h
  67. +3 −6 usr/src/uts/common/fs/zfs/sys/txg.h
  68. +10 −7 usr/src/uts/common/fs/zfs/sys/zfeature.h
  69. +7 −5 usr/src/uts/common/fs/zfs/sys/zfs_debug.h
  70. +2 −2 usr/src/uts/common/fs/zfs/sys/zfs_ioctl.h
  71. +2 −1 usr/src/uts/common/fs/zfs/sys/zfs_znode.h
  72. +2 −2 usr/src/uts/common/fs/zfs/sys/zil.h
  73. +21 −16 usr/src/uts/common/fs/zfs/txg.c
  74. +19 −14 usr/src/uts/common/fs/zfs/zfs_ctldir.c
  75. +489 −594 usr/src/uts/common/fs/zfs/zfs_ioctl.c
  76. +43 −31 usr/src/uts/common/fs/zfs/zfs_vfsops.c
  77. +104 −33 usr/src/uts/common/fs/zfs/zil.c
  78. +6 −2 usr/src/uts/common/fs/zfs/zio.c
  79. +52 −33 usr/src/uts/common/fs/zfs/zvol.c
  80. +1 −0 usr/src/uts/common/sys/nvpair.h
@@ -859,7 +859,7 @@ dbgmsg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
NULL) != argc)
return (DCMD_USAGE);
- if (mdb_lookup_by_name("zfs_dbgmsgs", &sym)) {
+ if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "zfs_dbgmsgs", &sym)) {
mdb_warn("can't find zfs_dbgmsgs");
return (DCMD_ERR);
}
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013 by Delphix. All rights reserved.
*/
/*
@@ -202,8 +203,7 @@ snapshot_hold(char *volname, char *snapname, char *jname, boolean_t recursive)
}
p = strchr(snapname, '@') + 1;
- if (zfs_hold(zhp, p, jname, recursive, B_TRUE, B_FALSE,
- cleanup_fd, 0, 0) != 0) {
+ if (zfs_hold(zhp, p, jname, recursive, B_FALSE, cleanup_fd) != 0) {
NDMP_LOG(LOG_ERR, "Cannot hold snapshot %s", p);
zfs_close(zhp);
return (-1);
@@ -22,6 +22,7 @@
/*
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 by Delphix. All rights reserved.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
@@ -4876,9 +4877,7 @@ show_zfs_ioc(private_t *pri, long addr)
if (zc.zc_value[0])
(void) printf(" zc_value=%s\n", zc.zc_value);
if (zc.zc_string[0])
- (void) printf(" zc_strign=%s\n", zc.zc_string);
- if (zc.zc_top_ds[0])
- (void) printf(" zc_top_ds=%s\n", zc.zc_top_ds);
+ (void) printf(" zc_string=%s\n", zc.zc_string);
if (zc.zc_guid != 0) {
(void) printf(" zc_guid=%llu\n",
(u_longlong_t)zc.zc_guid);
@@ -1658,7 +1658,9 @@ dump_dir(objset_t *os)
int print_header = 1;
int i, error;
+ dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
dmu_objset_fast_stat(os, &dds);
+ dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
if (dds.dds_type < DMU_OST_NUMTYPES)
type = objset_types[dds.dds_type];
@@ -2109,7 +2111,6 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
zio_nowait(zio_read(NULL, spa, bp, data, size,
zdb_blkptr_done, zcb, ZIO_PRIORITY_ASYNC_READ, flags, zb));
-
}
zcb->zcb_readfails = 0;
@@ -2297,8 +2298,10 @@ dump_block_stats(spa_t *spa)
*/
(void) bpobj_iterate_nofree(&spa->spa_deferred_bpobj,
count_block_cb, &zcb, NULL);
- (void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
- count_block_cb, &zcb, NULL);
+ if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
+ (void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
+ count_block_cb, &zcb, NULL);
+ }
if (spa_feature_is_active(spa,
&spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
VERIFY3U(0, ==, bptree_iterate(spa->spa_meta_objset,
@@ -898,6 +898,7 @@ typedef struct destroy_cbdata {
boolean_t cb_parsable;
boolean_t cb_dryrun;
nvlist_t *cb_nvl;
+ nvlist_t *cb_batchedsnaps;
/* first snap in contiguous run */
char *cb_firstsnap;
@@ -994,9 +995,27 @@ destroy_callback(zfs_handle_t *zhp, void *data)
zfs_close(zhp);
return (0);
}
+ if (cb->cb_dryrun) {
+ zfs_close(zhp);
+ return (0);
+ }
+
+ /*
+ * We batch up all contiguous snapshots (even of different
+ * filesystems) and destroy them with one ioctl. We can't
+ * simply do all snap deletions and then all fs deletions,
+ * because we must delete a clone before its origin.
+ */
+ if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) {
+ fnvlist_add_boolean(cb->cb_batchedsnaps, name);
+ } else {
+ int error = zfs_destroy_snaps_nvl(g_zfs,
+ cb->cb_batchedsnaps, B_FALSE);
+ fnvlist_free(cb->cb_batchedsnaps);
+ cb->cb_batchedsnaps = fnvlist_alloc();
- if (!cb->cb_dryrun) {
- if (zfs_unmount(zhp, NULL, cb->cb_force ? MS_FORCE : 0) != 0 ||
+ if (error != 0 ||
+ zfs_unmount(zhp, NULL, cb->cb_force ? MS_FORCE : 0) != 0 ||
zfs_destroy(zhp, cb->cb_defer_destroy) != 0) {
zfs_close(zhp);
return (-1);
@@ -1152,8 +1171,10 @@ static int
zfs_do_destroy(int argc, char **argv)
{
destroy_cbdata_t cb = { 0 };
+ int rv = 0;
+ int err = 0;
int c;
- zfs_handle_t *zhp;
+ zfs_handle_t *zhp = NULL;
char *at;
zfs_type_t type = ZFS_TYPE_DATASET;
@@ -1207,11 +1228,9 @@ zfs_do_destroy(int argc, char **argv)
at = strchr(argv[0], '@');
if (at != NULL) {
- int err = 0;
/* Build the list of snaps to destroy in cb_nvl. */
- if (nvlist_alloc(&cb.cb_nvl, NV_UNIQUE_NAME, 0) != 0)
- nomem();
+ cb.cb_nvl = fnvlist_alloc();
*at = '\0';
zhp = zfs_open(g_zfs, argv[0],
@@ -1222,17 +1241,15 @@ zfs_do_destroy(int argc, char **argv)
cb.cb_snapspec = at + 1;
if (gather_snapshots(zfs_handle_dup(zhp), &cb) != 0 ||
cb.cb_error) {
- zfs_close(zhp);
- nvlist_free(cb.cb_nvl);
- return (1);
+ rv = 1;
+ goto out;
}
if (nvlist_empty(cb.cb_nvl)) {
(void) fprintf(stderr, gettext("could not find any "
"snapshots to destroy; check snapshot names.\n"));
- zfs_close(zhp);
- nvlist_free(cb.cb_nvl);
- return (1);
+ rv = 1;
+ goto out;
}
if (cb.cb_verbose) {
@@ -1251,18 +1268,26 @@ zfs_do_destroy(int argc, char **argv)
}
if (!cb.cb_dryrun) {
- if (cb.cb_doclones)
+ if (cb.cb_doclones) {
+ cb.cb_batchedsnaps = fnvlist_alloc();
err = destroy_clones(&cb);
+ if (err == 0) {
+ err = zfs_destroy_snaps_nvl(g_zfs,
+ cb.cb_batchedsnaps, B_FALSE);
+ }
+ if (err != 0) {
+ rv = 1;
+ goto out;
+ }
+ }
if (err == 0) {
- err = zfs_destroy_snaps_nvl(zhp, cb.cb_nvl,
+ err = zfs_destroy_snaps_nvl(g_zfs, cb.cb_nvl,
cb.cb_defer_destroy);
}
}
- zfs_close(zhp);
- nvlist_free(cb.cb_nvl);
if (err != 0)
- return (1);
+ rv = 1;
} else {
/* Open the given dataset */
if ((zhp = zfs_open(g_zfs, argv[0], type)) == NULL)
@@ -1283,8 +1308,8 @@ zfs_do_destroy(int argc, char **argv)
zfs_get_name(zhp));
(void) fprintf(stderr, gettext("use 'zpool destroy %s' "
"to destroy the pool itself\n"), zfs_get_name(zhp));
- zfs_close(zhp);
- return (1);
+ rv = 1;
+ goto out;
}
/*
@@ -1294,30 +1319,42 @@ zfs_do_destroy(int argc, char **argv)
if (!cb.cb_doclones &&
zfs_iter_dependents(zhp, B_TRUE, destroy_check_dependent,
&cb) != 0) {
- zfs_close(zhp);
- return (1);
+ rv = 1;
+ goto out;
}
if (cb.cb_error) {
- zfs_close(zhp);
- return (1);
+ rv = 1;
+ goto out;
}
+ cb.cb_batchedsnaps = fnvlist_alloc();
if (zfs_iter_dependents(zhp, B_FALSE, destroy_callback,
&cb) != 0) {
- zfs_close(zhp);
- return (1);
+ rv = 1;
+ goto out;
}
/*
* Do the real thing. The callback will close the
* handle regardless of whether it succeeds or not.
*/
- if (destroy_callback(zhp, &cb) != 0)
- return (1);
+ err = destroy_callback(zhp, &cb);
+ zhp = NULL;
+ if (err == 0) {
+ err = zfs_destroy_snaps_nvl(g_zfs,
+ cb.cb_batchedsnaps, cb.cb_defer_destroy);
+ }
+ if (err != 0)
+ rv = 1;
}
- return (0);
+out:
+ fnvlist_free(cb.cb_batchedsnaps);
+ fnvlist_free(cb.cb_nvl);
+ if (zhp != NULL)
+ zfs_close(zhp);
+ return (rv);
}
static boolean_t
@@ -5052,28 +5089,12 @@ zfs_do_allow_unallow_impl(int argc, char **argv, boolean_t un)
return (error);
}
-/*
- * zfs allow [-r] [-t] <tag> <snap> ...
- *
- * -r Recursively hold
- * -t Temporary hold (hidden option)
- *
- * Apply a user-hold with the given tag to the list of snapshots.
- */
static int
zfs_do_allow(int argc, char **argv)
{
return (zfs_do_allow_unallow_impl(argc, argv, B_FALSE));
}
-/*
- * zfs unallow [-r] [-t] <tag> <snap> ...
- *
- * -r Recursively hold
- * -t Temporary hold (hidden option)
- *
- * Apply a user-hold with the given tag to the list of snapshots.
- */
static int
zfs_do_unallow(int argc, char **argv)
{
@@ -5087,7 +5108,6 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
int i;
const char *tag;
boolean_t recursive = B_FALSE;
- boolean_t temphold = B_FALSE;
const char *opts = holding ? "rt" : "r";
int c;
@@ -5097,9 +5117,6 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
case 'r':
recursive = B_TRUE;
break;
- case 't':
- temphold = B_TRUE;
- break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
@@ -5148,7 +5165,7 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
}
if (holding) {
if (zfs_hold(zhp, delim+1, tag, recursive,
- temphold, B_FALSE, -1, 0, 0) != 0)
+ B_FALSE, -1) != 0)
++errors;
} else {
if (zfs_release(zhp, delim+1, tag, recursive) != 0)
@@ -5164,7 +5181,6 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
* zfs hold [-r] [-t] <tag> <snap> ...
*
* -r Recursively hold
- * -t Temporary hold (hidden option)
*
* Apply a user-hold with the given tag to the list of snapshots.
*/
@@ -46,6 +46,7 @@
#include <sys/zio_checksum.h>
#include <sys/zio_compress.h>
#include <sys/zfeature.h>
+#include <sys/dmu_tx.h>
#undef ZFS_MAXNAMELEN
#undef verify
#include <libzfs.h>
@@ -273,10 +274,10 @@ zhack_do_feature_stat(int argc, char **argv)
}
static void
-feature_enable_sync(void *arg1, void *arg2, dmu_tx_t *tx)
+feature_enable_sync(void *arg, dmu_tx_t *tx)
{
- spa_t *spa = arg1;
- zfeature_info_t *feature = arg2;
+ spa_t *spa = dmu_tx_pool(tx)->dp_spa;
+ zfeature_info_t *feature = arg;
spa_feature_enable(spa, feature, tx);
spa_history_log_internal(spa, "zhack enable feature", tx,
@@ -344,30 +345,30 @@ zhack_do_feature_enable(int argc, char **argv)
if (0 == zap_contains(mos, spa->spa_feat_desc_obj, feature.fi_guid))
fatal("feature already enabled: %s", feature.fi_guid);
- VERIFY3U(0, ==, dsl_sync_task_do(spa->spa_dsl_pool, NULL,
- feature_enable_sync, spa, &feature, 5));
+ VERIFY0(dsl_sync_task(spa_name(spa), NULL,
+ feature_enable_sync, &feature, 5));
spa_close(spa, FTAG);
free(desc);
}
static void
-feature_incr_sync(void *arg1, void *arg2, dmu_tx_t *tx)
+feature_incr_sync(void *arg, dmu_tx_t *tx)
{
- spa_t *spa = arg1;
- zfeature_info_t *feature = arg2;
+ spa_t *spa = dmu_tx_pool(tx)->dp_spa;
+ zfeature_info_t *feature = arg;
spa_feature_incr(spa, feature, tx);
spa_history_log_internal(spa, "zhack feature incr", tx,
"guid=%s", feature->fi_guid);
}
static void
-feature_decr_sync(void *arg1, void *arg2, dmu_tx_t *tx)
+feature_decr_sync(void *arg, dmu_tx_t *tx)
{
- spa_t *spa = arg1;
- zfeature_info_t *feature = arg2;
+ spa_t *spa = dmu_tx_pool(tx)->dp_spa;
+ zfeature_info_t *feature = arg;
spa_feature_decr(spa, feature, tx);
spa_history_log_internal(spa, "zhack feature decr", tx,
@@ -442,8 +443,8 @@ zhack_do_feature_ref(int argc, char **argv)
if (decr && !spa_feature_is_active(spa, &feature))
fatal("feature refcount already 0: %s", feature.fi_guid);
- VERIFY3U(0, ==, dsl_sync_task_do(spa->spa_dsl_pool, NULL,
- decr ? feature_decr_sync : feature_incr_sync, spa, &feature, 5));
+ VERIFY0(dsl_sync_task(spa_name(spa), NULL,
+ decr ? feature_decr_sync : feature_incr_sync, &feature, 5));
spa_close(spa, FTAG);
}
Oops, something went wrong.

0 comments on commit 3b2aab1

Please sign in to comment.