Skip to content

Commit 13fe019

Browse files
ahrensbehlendorf
authored andcommitted
Illumos #3464
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> References: https://www.illumos.org/issues/3464 illumos/illumos-gate@3b2aab1 Ported-by: Tim Chase <tim@chase2k.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #1495
1 parent 6f1ffb0 commit 13fe019

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+6559
-6177
lines changed

cmd/zdb/zdb.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,9 @@ dump_dir(objset_t *os)
17251725
int print_header = 1;
17261726
int i, error;
17271727

1728+
dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
17281729
dmu_objset_fast_stat(os, &dds);
1730+
dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
17291731

17301732
if (dds.dds_type < DMU_OST_NUMTYPES)
17311733
type = objset_types[dds.dds_type];
@@ -2171,7 +2173,6 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
21712173

21722174
zio_nowait(zio_read(NULL, spa, bp, data, size,
21732175
zdb_blkptr_done, zcb, ZIO_PRIORITY_ASYNC_READ, flags, zb));
2174-
21752176
}
21762177

21772178
zcb->zcb_readfails = 0;
@@ -2365,8 +2366,10 @@ dump_block_stats(spa_t *spa)
23652366
*/
23662367
(void) bpobj_iterate_nofree(&spa->spa_deferred_bpobj,
23672368
count_block_cb, &zcb, NULL);
2368-
(void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
2369-
count_block_cb, &zcb, NULL);
2369+
if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
2370+
(void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
2371+
count_block_cb, &zcb, NULL);
2372+
}
23702373
if (spa_feature_is_active(spa,
23712374
&spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
23722375
VERIFY3U(0, ==, bptree_iterate(spa->spa_meta_objset,

cmd/zfs/zfs_main.c

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ typedef struct destroy_cbdata {
892892
boolean_t cb_parsable;
893893
boolean_t cb_dryrun;
894894
nvlist_t *cb_nvl;
895+
nvlist_t *cb_batchedsnaps;
895896

896897
/* first snap in contiguous run */
897898
char *cb_firstsnap;
@@ -988,9 +989,27 @@ destroy_callback(zfs_handle_t *zhp, void *data)
988989
zfs_close(zhp);
989990
return (0);
990991
}
992+
if (cb->cb_dryrun) {
993+
zfs_close(zhp);
994+
return (0);
995+
}
996+
997+
/*
998+
* We batch up all contiguous snapshots (even of different
999+
* filesystems) and destroy them with one ioctl. We can't
1000+
* simply do all snap deletions and then all fs deletions,
1001+
* because we must delete a clone before its origin.
1002+
*/
1003+
if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) {
1004+
fnvlist_add_boolean(cb->cb_batchedsnaps, name);
1005+
} else {
1006+
int error = zfs_destroy_snaps_nvl(g_zfs,
1007+
cb->cb_batchedsnaps, B_FALSE);
1008+
fnvlist_free(cb->cb_batchedsnaps);
1009+
cb->cb_batchedsnaps = fnvlist_alloc();
9911010

992-
if (!cb->cb_dryrun) {
993-
if (zfs_unmount(zhp, NULL, cb->cb_force ? MS_FORCE : 0) != 0 ||
1011+
if (error != 0 ||
1012+
zfs_unmount(zhp, NULL, cb->cb_force ? MS_FORCE : 0) != 0 ||
9941013
zfs_destroy(zhp, cb->cb_defer_destroy) != 0) {
9951014
zfs_close(zhp);
9961015
return (-1);
@@ -1146,8 +1165,10 @@ static int
11461165
zfs_do_destroy(int argc, char **argv)
11471166
{
11481167
destroy_cbdata_t cb = { 0 };
1168+
int rv = 0;
1169+
int err = 0;
11491170
int c;
1150-
zfs_handle_t *zhp;
1171+
zfs_handle_t *zhp = NULL;
11511172
char *at;
11521173
zfs_type_t type = ZFS_TYPE_DATASET;
11531174

@@ -1201,11 +1222,9 @@ zfs_do_destroy(int argc, char **argv)
12011222

12021223
at = strchr(argv[0], '@');
12031224
if (at != NULL) {
1204-
int err = 0;
12051225

12061226
/* Build the list of snaps to destroy in cb_nvl. */
1207-
if (nvlist_alloc(&cb.cb_nvl, NV_UNIQUE_NAME, 0) != 0)
1208-
nomem();
1227+
cb.cb_nvl = fnvlist_alloc();
12091228

12101229
*at = '\0';
12111230
zhp = zfs_open(g_zfs, argv[0],
@@ -1216,17 +1235,15 @@ zfs_do_destroy(int argc, char **argv)
12161235
cb.cb_snapspec = at + 1;
12171236
if (gather_snapshots(zfs_handle_dup(zhp), &cb) != 0 ||
12181237
cb.cb_error) {
1219-
zfs_close(zhp);
1220-
nvlist_free(cb.cb_nvl);
1221-
return (1);
1238+
rv = 1;
1239+
goto out;
12221240
}
12231241

12241242
if (nvlist_empty(cb.cb_nvl)) {
12251243
(void) fprintf(stderr, gettext("could not find any "
12261244
"snapshots to destroy; check snapshot names.\n"));
1227-
zfs_close(zhp);
1228-
nvlist_free(cb.cb_nvl);
1229-
return (1);
1245+
rv = 1;
1246+
goto out;
12301247
}
12311248

12321249
if (cb.cb_verbose) {
@@ -1245,18 +1262,26 @@ zfs_do_destroy(int argc, char **argv)
12451262
}
12461263

12471264
if (!cb.cb_dryrun) {
1248-
if (cb.cb_doclones)
1265+
if (cb.cb_doclones) {
1266+
cb.cb_batchedsnaps = fnvlist_alloc();
12491267
err = destroy_clones(&cb);
1268+
if (err == 0) {
1269+
err = zfs_destroy_snaps_nvl(g_zfs,
1270+
cb.cb_batchedsnaps, B_FALSE);
1271+
}
1272+
if (err != 0) {
1273+
rv = 1;
1274+
goto out;
1275+
}
1276+
}
12501277
if (err == 0) {
1251-
err = zfs_destroy_snaps_nvl(zhp, cb.cb_nvl,
1278+
err = zfs_destroy_snaps_nvl(g_zfs, cb.cb_nvl,
12521279
cb.cb_defer_destroy);
12531280
}
12541281
}
12551282

1256-
zfs_close(zhp);
1257-
nvlist_free(cb.cb_nvl);
12581283
if (err != 0)
1259-
return (1);
1284+
rv = 1;
12601285
} else {
12611286
/* Open the given dataset */
12621287
if ((zhp = zfs_open(g_zfs, argv[0], type)) == NULL)
@@ -1277,8 +1302,8 @@ zfs_do_destroy(int argc, char **argv)
12771302
zfs_get_name(zhp));
12781303
(void) fprintf(stderr, gettext("use 'zpool destroy %s' "
12791304
"to destroy the pool itself\n"), zfs_get_name(zhp));
1280-
zfs_close(zhp);
1281-
return (1);
1305+
rv = 1;
1306+
goto out;
12821307
}
12831308

12841309
/*
@@ -1288,30 +1313,42 @@ zfs_do_destroy(int argc, char **argv)
12881313
if (!cb.cb_doclones &&
12891314
zfs_iter_dependents(zhp, B_TRUE, destroy_check_dependent,
12901315
&cb) != 0) {
1291-
zfs_close(zhp);
1292-
return (1);
1316+
rv = 1;
1317+
goto out;
12931318
}
12941319

12951320
if (cb.cb_error) {
1296-
zfs_close(zhp);
1297-
return (1);
1321+
rv = 1;
1322+
goto out;
12981323
}
12991324

1325+
cb.cb_batchedsnaps = fnvlist_alloc();
13001326
if (zfs_iter_dependents(zhp, B_FALSE, destroy_callback,
13011327
&cb) != 0) {
1302-
zfs_close(zhp);
1303-
return (1);
1328+
rv = 1;
1329+
goto out;
13041330
}
13051331

13061332
/*
13071333
* Do the real thing. The callback will close the
13081334
* handle regardless of whether it succeeds or not.
13091335
*/
1310-
if (destroy_callback(zhp, &cb) != 0)
1311-
return (1);
1336+
err = destroy_callback(zhp, &cb);
1337+
zhp = NULL;
1338+
if (err == 0) {
1339+
err = zfs_destroy_snaps_nvl(g_zfs,
1340+
cb.cb_batchedsnaps, cb.cb_defer_destroy);
1341+
}
1342+
if (err != 0)
1343+
rv = 1;
13121344
}
13131345

1314-
return (0);
1346+
out:
1347+
fnvlist_free(cb.cb_batchedsnaps);
1348+
fnvlist_free(cb.cb_nvl);
1349+
if (zhp != NULL)
1350+
zfs_close(zhp);
1351+
return (rv);
13151352
}
13161353

13171354
static boolean_t
@@ -5081,28 +5118,12 @@ zfs_do_allow_unallow_impl(int argc, char **argv, boolean_t un)
50815118
return (error);
50825119
}
50835120

5084-
/*
5085-
* zfs allow [-r] [-t] <tag> <snap> ...
5086-
*
5087-
* -r Recursively hold
5088-
* -t Temporary hold (hidden option)
5089-
*
5090-
* Apply a user-hold with the given tag to the list of snapshots.
5091-
*/
50925121
static int
50935122
zfs_do_allow(int argc, char **argv)
50945123
{
50955124
return (zfs_do_allow_unallow_impl(argc, argv, B_FALSE));
50965125
}
50975126

5098-
/*
5099-
* zfs unallow [-r] [-t] <tag> <snap> ...
5100-
*
5101-
* -r Recursively hold
5102-
* -t Temporary hold (hidden option)
5103-
*
5104-
* Apply a user-hold with the given tag to the list of snapshots.
5105-
*/
51065127
static int
51075128
zfs_do_unallow(int argc, char **argv)
51085129
{
@@ -5116,7 +5137,6 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
51165137
int i;
51175138
const char *tag;
51185139
boolean_t recursive = B_FALSE;
5119-
boolean_t temphold = B_FALSE;
51205140
const char *opts = holding ? "rt" : "r";
51215141
int c;
51225142

@@ -5126,9 +5146,6 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
51265146
case 'r':
51275147
recursive = B_TRUE;
51285148
break;
5129-
case 't':
5130-
temphold = B_TRUE;
5131-
break;
51325149
case '?':
51335150
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
51345151
optopt);
@@ -5177,7 +5194,7 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
51775194
}
51785195
if (holding) {
51795196
if (zfs_hold(zhp, delim+1, tag, recursive,
5180-
temphold, B_FALSE, -1, 0, 0) != 0)
5197+
B_FALSE, -1) != 0)
51815198
++errors;
51825199
} else {
51835200
if (zfs_release(zhp, delim+1, tag, recursive) != 0)
@@ -5193,7 +5210,6 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
51935210
* zfs hold [-r] [-t] <tag> <snap> ...
51945211
*
51955212
* -r Recursively hold
5196-
* -t Temporary hold (hidden option)
51975213
*
51985214
* Apply a user-hold with the given tag to the list of snapshots.
51995215
*/

cmd/zhack/zhack.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <sys/zio_checksum.h>
4747
#include <sys/zio_compress.h>
4848
#include <sys/zfeature.h>
49+
#include <sys/dmu_tx.h>
4950
#undef ZFS_MAXNAMELEN
5051
#include <libzfs.h>
5152

@@ -123,7 +124,7 @@ import_pool(const char *target, boolean_t readonly)
123124
spa_t *spa;
124125
nvpair_t *elem;
125126
nvlist_t *props;
126-
const char *name;
127+
char *name;
127128

128129
kernel_init(readonly ? FREAD : (FREAD | FWRITE));
129130
g_zfs = libzfs_init();
@@ -273,10 +274,10 @@ zhack_do_feature_stat(int argc, char **argv)
273274
}
274275

275276
static void
276-
feature_enable_sync(void *arg1, void *arg2, dmu_tx_t *tx)
277+
feature_enable_sync(void *arg, dmu_tx_t *tx)
277278
{
278-
spa_t *spa = arg1;
279-
zfeature_info_t *feature = arg2;
279+
spa_t *spa = dmu_tx_pool(tx)->dp_spa;
280+
zfeature_info_t *feature = arg;
280281

281282
spa_feature_enable(spa, feature, tx);
282283
spa_history_log_internal(spa, "zhack enable feature", tx,
@@ -344,30 +345,30 @@ zhack_do_feature_enable(int argc, char **argv)
344345
if (0 == zap_contains(mos, spa->spa_feat_desc_obj, feature.fi_guid))
345346
fatal("feature already enabled: %s", feature.fi_guid);
346347

347-
VERIFY3U(0, ==, dsl_sync_task_do(spa->spa_dsl_pool, NULL,
348-
feature_enable_sync, spa, &feature, 5));
348+
VERIFY0(dsl_sync_task(spa_name(spa), NULL,
349+
feature_enable_sync, &feature, 5));
349350

350351
spa_close(spa, FTAG);
351352

352353
free(desc);
353354
}
354355

355356
static void
356-
feature_incr_sync(void *arg1, void *arg2, dmu_tx_t *tx)
357+
feature_incr_sync(void *arg, dmu_tx_t *tx)
357358
{
358-
spa_t *spa = arg1;
359-
zfeature_info_t *feature = arg2;
359+
spa_t *spa = dmu_tx_pool(tx)->dp_spa;
360+
zfeature_info_t *feature = arg;
360361

361362
spa_feature_incr(spa, feature, tx);
362363
spa_history_log_internal(spa, "zhack feature incr", tx,
363364
"name=%s", feature->fi_guid);
364365
}
365366

366367
static void
367-
feature_decr_sync(void *arg1, void *arg2, dmu_tx_t *tx)
368+
feature_decr_sync(void *arg, dmu_tx_t *tx)
368369
{
369-
spa_t *spa = arg1;
370-
zfeature_info_t *feature = arg2;
370+
spa_t *spa = dmu_tx_pool(tx)->dp_spa;
371+
zfeature_info_t *feature = arg;
371372

372373
spa_feature_decr(spa, feature, tx);
373374
spa_history_log_internal(spa, "zhack feature decr", tx,
@@ -442,8 +443,8 @@ zhack_do_feature_ref(int argc, char **argv)
442443
if (decr && !spa_feature_is_active(spa, &feature))
443444
fatal("feature refcount already 0: %s", feature.fi_guid);
444445

445-
VERIFY3U(0, ==, dsl_sync_task_do(spa->spa_dsl_pool, NULL,
446-
decr ? feature_decr_sync : feature_incr_sync, spa, &feature, 5));
446+
VERIFY0(dsl_sync_task(spa_name(spa), NULL,
447+
decr ? feature_decr_sync : feature_incr_sync, &feature, 5));
447448

448449
spa_close(spa, FTAG);
449450
}

0 commit comments

Comments
 (0)