Skip to content

Commit 3b2aab1

Browse files
ahrensChristopher Siden
authored and
Christopher Siden
committed
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>
1 parent 584d084 commit 3b2aab1

Some content is hidden

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

80 files changed

+6501
-6044
lines changed

usr/src/cmd/mdb/common/modules/zfs/zfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ dbgmsg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
859859
NULL) != argc)
860860
return (DCMD_USAGE);
861861

862-
if (mdb_lookup_by_name("zfs_dbgmsgs", &sym)) {
862+
if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "zfs_dbgmsgs", &sym)) {
863863
mdb_warn("can't find zfs_dbgmsgs");
864864
return (DCMD_ERR);
865865
}

usr/src/cmd/ndmpd/ndmp/ndmpd_chkpnt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2013 by Delphix. All rights reserved.
34
*/
45

56
/*
@@ -202,8 +203,7 @@ snapshot_hold(char *volname, char *snapname, char *jname, boolean_t recursive)
202203
}
203204

204205
p = strchr(snapname, '@') + 1;
205-
if (zfs_hold(zhp, p, jname, recursive, B_TRUE, B_FALSE,
206-
cleanup_fd, 0, 0) != 0) {
206+
if (zfs_hold(zhp, p, jname, recursive, B_FALSE, cleanup_fd) != 0) {
207207
NDMP_LOG(LOG_ERR, "Cannot hold snapshot %s", p);
208208
zfs_close(zhp);
209209
return (-1);

usr/src/cmd/truss/expound.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/*
2323
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
2424
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
25+
* Copyright (c) 2012 by Delphix. All rights reserved.
2526
*/
2627

2728
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
@@ -4876,9 +4877,7 @@ show_zfs_ioc(private_t *pri, long addr)
48764877
if (zc.zc_value[0])
48774878
(void) printf(" zc_value=%s\n", zc.zc_value);
48784879
if (zc.zc_string[0])
4879-
(void) printf(" zc_strign=%s\n", zc.zc_string);
4880-
if (zc.zc_top_ds[0])
4881-
(void) printf(" zc_top_ds=%s\n", zc.zc_top_ds);
4880+
(void) printf(" zc_string=%s\n", zc.zc_string);
48824881
if (zc.zc_guid != 0) {
48834882
(void) printf(" zc_guid=%llu\n",
48844883
(u_longlong_t)zc.zc_guid);

usr/src/cmd/zdb/zdb.c

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

1661+
dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
16611662
dmu_objset_fast_stat(os, &dds);
1663+
dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
16621664

16631665
if (dds.dds_type < DMU_OST_NUMTYPES)
16641666
type = objset_types[dds.dds_type];
@@ -2109,7 +2111,6 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
21092111

21102112
zio_nowait(zio_read(NULL, spa, bp, data, size,
21112113
zdb_blkptr_done, zcb, ZIO_PRIORITY_ASYNC_READ, flags, zb));
2112-
21132114
}
21142115

21152116
zcb->zcb_readfails = 0;
@@ -2297,8 +2298,10 @@ dump_block_stats(spa_t *spa)
22972298
*/
22982299
(void) bpobj_iterate_nofree(&spa->spa_deferred_bpobj,
22992300
count_block_cb, &zcb, NULL);
2300-
(void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
2301-
count_block_cb, &zcb, NULL);
2301+
if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
2302+
(void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
2303+
count_block_cb, &zcb, NULL);
2304+
}
23022305
if (spa_feature_is_active(spa,
23032306
&spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
23042307
VERIFY3U(0, ==, bptree_iterate(spa->spa_meta_objset,

usr/src/cmd/zfs/zfs_main.c

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ typedef struct destroy_cbdata {
898898
boolean_t cb_parsable;
899899
boolean_t cb_dryrun;
900900
nvlist_t *cb_nvl;
901+
nvlist_t *cb_batchedsnaps;
901902

902903
/* first snap in contiguous run */
903904
char *cb_firstsnap;
@@ -994,9 +995,27 @@ destroy_callback(zfs_handle_t *zhp, void *data)
994995
zfs_close(zhp);
995996
return (0);
996997
}
998+
if (cb->cb_dryrun) {
999+
zfs_close(zhp);
1000+
return (0);
1001+
}
1002+
1003+
/*
1004+
* We batch up all contiguous snapshots (even of different
1005+
* filesystems) and destroy them with one ioctl. We can't
1006+
* simply do all snap deletions and then all fs deletions,
1007+
* because we must delete a clone before its origin.
1008+
*/
1009+
if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) {
1010+
fnvlist_add_boolean(cb->cb_batchedsnaps, name);
1011+
} else {
1012+
int error = zfs_destroy_snaps_nvl(g_zfs,
1013+
cb->cb_batchedsnaps, B_FALSE);
1014+
fnvlist_free(cb->cb_batchedsnaps);
1015+
cb->cb_batchedsnaps = fnvlist_alloc();
9971016

998-
if (!cb->cb_dryrun) {
999-
if (zfs_unmount(zhp, NULL, cb->cb_force ? MS_FORCE : 0) != 0 ||
1017+
if (error != 0 ||
1018+
zfs_unmount(zhp, NULL, cb->cb_force ? MS_FORCE : 0) != 0 ||
10001019
zfs_destroy(zhp, cb->cb_defer_destroy) != 0) {
10011020
zfs_close(zhp);
10021021
return (-1);
@@ -1152,8 +1171,10 @@ static int
11521171
zfs_do_destroy(int argc, char **argv)
11531172
{
11541173
destroy_cbdata_t cb = { 0 };
1174+
int rv = 0;
1175+
int err = 0;
11551176
int c;
1156-
zfs_handle_t *zhp;
1177+
zfs_handle_t *zhp = NULL;
11571178
char *at;
11581179
zfs_type_t type = ZFS_TYPE_DATASET;
11591180

@@ -1207,11 +1228,9 @@ zfs_do_destroy(int argc, char **argv)
12071228

12081229
at = strchr(argv[0], '@');
12091230
if (at != NULL) {
1210-
int err = 0;
12111231

12121232
/* Build the list of snaps to destroy in cb_nvl. */
1213-
if (nvlist_alloc(&cb.cb_nvl, NV_UNIQUE_NAME, 0) != 0)
1214-
nomem();
1233+
cb.cb_nvl = fnvlist_alloc();
12151234

12161235
*at = '\0';
12171236
zhp = zfs_open(g_zfs, argv[0],
@@ -1222,17 +1241,15 @@ zfs_do_destroy(int argc, char **argv)
12221241
cb.cb_snapspec = at + 1;
12231242
if (gather_snapshots(zfs_handle_dup(zhp), &cb) != 0 ||
12241243
cb.cb_error) {
1225-
zfs_close(zhp);
1226-
nvlist_free(cb.cb_nvl);
1227-
return (1);
1244+
rv = 1;
1245+
goto out;
12281246
}
12291247

12301248
if (nvlist_empty(cb.cb_nvl)) {
12311249
(void) fprintf(stderr, gettext("could not find any "
12321250
"snapshots to destroy; check snapshot names.\n"));
1233-
zfs_close(zhp);
1234-
nvlist_free(cb.cb_nvl);
1235-
return (1);
1251+
rv = 1;
1252+
goto out;
12361253
}
12371254

12381255
if (cb.cb_verbose) {
@@ -1251,18 +1268,26 @@ zfs_do_destroy(int argc, char **argv)
12511268
}
12521269

12531270
if (!cb.cb_dryrun) {
1254-
if (cb.cb_doclones)
1271+
if (cb.cb_doclones) {
1272+
cb.cb_batchedsnaps = fnvlist_alloc();
12551273
err = destroy_clones(&cb);
1274+
if (err == 0) {
1275+
err = zfs_destroy_snaps_nvl(g_zfs,
1276+
cb.cb_batchedsnaps, B_FALSE);
1277+
}
1278+
if (err != 0) {
1279+
rv = 1;
1280+
goto out;
1281+
}
1282+
}
12561283
if (err == 0) {
1257-
err = zfs_destroy_snaps_nvl(zhp, cb.cb_nvl,
1284+
err = zfs_destroy_snaps_nvl(g_zfs, cb.cb_nvl,
12581285
cb.cb_defer_destroy);
12591286
}
12601287
}
12611288

1262-
zfs_close(zhp);
1263-
nvlist_free(cb.cb_nvl);
12641289
if (err != 0)
1265-
return (1);
1290+
rv = 1;
12661291
} else {
12671292
/* Open the given dataset */
12681293
if ((zhp = zfs_open(g_zfs, argv[0], type)) == NULL)
@@ -1283,8 +1308,8 @@ zfs_do_destroy(int argc, char **argv)
12831308
zfs_get_name(zhp));
12841309
(void) fprintf(stderr, gettext("use 'zpool destroy %s' "
12851310
"to destroy the pool itself\n"), zfs_get_name(zhp));
1286-
zfs_close(zhp);
1287-
return (1);
1311+
rv = 1;
1312+
goto out;
12881313
}
12891314

12901315
/*
@@ -1294,30 +1319,42 @@ zfs_do_destroy(int argc, char **argv)
12941319
if (!cb.cb_doclones &&
12951320
zfs_iter_dependents(zhp, B_TRUE, destroy_check_dependent,
12961321
&cb) != 0) {
1297-
zfs_close(zhp);
1298-
return (1);
1322+
rv = 1;
1323+
goto out;
12991324
}
13001325

13011326
if (cb.cb_error) {
1302-
zfs_close(zhp);
1303-
return (1);
1327+
rv = 1;
1328+
goto out;
13041329
}
13051330

1331+
cb.cb_batchedsnaps = fnvlist_alloc();
13061332
if (zfs_iter_dependents(zhp, B_FALSE, destroy_callback,
13071333
&cb) != 0) {
1308-
zfs_close(zhp);
1309-
return (1);
1334+
rv = 1;
1335+
goto out;
13101336
}
13111337

13121338
/*
13131339
* Do the real thing. The callback will close the
13141340
* handle regardless of whether it succeeds or not.
13151341
*/
1316-
if (destroy_callback(zhp, &cb) != 0)
1317-
return (1);
1342+
err = destroy_callback(zhp, &cb);
1343+
zhp = NULL;
1344+
if (err == 0) {
1345+
err = zfs_destroy_snaps_nvl(g_zfs,
1346+
cb.cb_batchedsnaps, cb.cb_defer_destroy);
1347+
}
1348+
if (err != 0)
1349+
rv = 1;
13181350
}
13191351

1320-
return (0);
1352+
out:
1353+
fnvlist_free(cb.cb_batchedsnaps);
1354+
fnvlist_free(cb.cb_nvl);
1355+
if (zhp != NULL)
1356+
zfs_close(zhp);
1357+
return (rv);
13211358
}
13221359

13231360
static boolean_t
@@ -5052,28 +5089,12 @@ zfs_do_allow_unallow_impl(int argc, char **argv, boolean_t un)
50525089
return (error);
50535090
}
50545091

5055-
/*
5056-
* zfs allow [-r] [-t] <tag> <snap> ...
5057-
*
5058-
* -r Recursively hold
5059-
* -t Temporary hold (hidden option)
5060-
*
5061-
* Apply a user-hold with the given tag to the list of snapshots.
5062-
*/
50635092
static int
50645093
zfs_do_allow(int argc, char **argv)
50655094
{
50665095
return (zfs_do_allow_unallow_impl(argc, argv, B_FALSE));
50675096
}
50685097

5069-
/*
5070-
* zfs unallow [-r] [-t] <tag> <snap> ...
5071-
*
5072-
* -r Recursively hold
5073-
* -t Temporary hold (hidden option)
5074-
*
5075-
* Apply a user-hold with the given tag to the list of snapshots.
5076-
*/
50775098
static int
50785099
zfs_do_unallow(int argc, char **argv)
50795100
{
@@ -5087,7 +5108,6 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
50875108
int i;
50885109
const char *tag;
50895110
boolean_t recursive = B_FALSE;
5090-
boolean_t temphold = B_FALSE;
50915111
const char *opts = holding ? "rt" : "r";
50925112
int c;
50935113

@@ -5097,9 +5117,6 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
50975117
case 'r':
50985118
recursive = B_TRUE;
50995119
break;
5100-
case 't':
5101-
temphold = B_TRUE;
5102-
break;
51035120
case '?':
51045121
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
51055122
optopt);
@@ -5148,7 +5165,7 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
51485165
}
51495166
if (holding) {
51505167
if (zfs_hold(zhp, delim+1, tag, recursive,
5151-
temphold, B_FALSE, -1, 0, 0) != 0)
5168+
B_FALSE, -1) != 0)
51525169
++errors;
51535170
} else {
51545171
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)
51645181
* zfs hold [-r] [-t] <tag> <snap> ...
51655182
*
51665183
* -r Recursively hold
5167-
* -t Temporary hold (hidden option)
51685184
*
51695185
* Apply a user-hold with the given tag to the list of snapshots.
51705186
*/

usr/src/cmd/zhack/zhack.c

Lines changed: 14 additions & 13 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
#undef verify
5152
#include <libzfs.h>
@@ -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
"guid=%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)