Skip to content

Commit

Permalink
3086 unnecessarily setting DS_FLAG_INCONSISTENT on async destroyed da…
Browse files Browse the repository at this point in the history
…tasets

Reviewed by: Christopher Siden <[email protected]>
Approved by: Eric Schrock <[email protected]>
  • Loading branch information
ahrens committed Aug 21, 2012
1 parent a970c70 commit ce636f8
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 116 deletions.
3 changes: 3 additions & 0 deletions usr/src/cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,7 @@ ztest_zil_remount(ztest_ds_t *zd, uint64_t id)
{
objset_t *os = zd->zd_os;

VERIFY(mutex_lock(&zd->zd_dirobj_lock) == 0);
(void) rw_wrlock(&zd->zd_zilog_lock);

/* zfsvfs_teardown() */
Expand All @@ -2233,6 +2234,7 @@ ztest_zil_remount(ztest_ds_t *zd, uint64_t id)
zil_replay(os, zd, ztest_replay_vector);

(void) rw_unlock(&zd->zd_zilog_lock);
VERIFY(mutex_unlock(&zd->zd_dirobj_lock) == 0);
}

/*
Expand Down Expand Up @@ -5531,6 +5533,7 @@ ztest_freeze(void)
*/
kernel_init(FREAD | FWRITE);
VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
ASSERT(spa_freeze_txg(spa) == UINT64_MAX);
VERIFY3U(0, ==, ztest_dataset_open(0));
ztest_dataset_close(0);
spa_close(spa, FTAG);
Expand Down
4 changes: 2 additions & 2 deletions usr/src/uts/common/fs/zfs/dmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1759,15 +1759,15 @@ dmu_init(void)
dnode_init();
dbuf_init();
zfetch_init();
arc_init();
l2arc_init();
arc_init();
}

void
dmu_fini(void)
{
l2arc_fini();
arc_fini();
l2arc_fini();
zfetch_fini();
dbuf_fini();
dnode_fini();
Expand Down
7 changes: 0 additions & 7 deletions usr/src/uts/common/fs/zfs/dmu_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,13 +1608,6 @@ dmu_recv_existing_end(dmu_recv_cookie_t *drc)
dsl_dataset_t *ds = drc->drc_logical_ds;
int err, myerr;

/*
* XXX hack; seems the ds is still dirty and dsl_pool_zil_clean()
* expects it to have a ds_user_ptr (and zil), but clone_swap()
* can close it.
*/
txg_wait_synced(ds->ds_dir->dd_pool, 0);

if (dsl_dataset_tryown(ds, FALSE, dmu_recv_tag)) {
err = dsl_dataset_clone_swap(drc->drc_real_ds, ds,
drc->drc_force);
Expand Down
109 changes: 47 additions & 62 deletions usr/src/uts/common/fs/zfs/dsl_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,8 @@ dsl_dataset_block_born(dsl_dataset_t *ds, const blkptr_t *bp, dmu_tx_t *tx)
ASSERT(BP_GET_TYPE(bp) != DMU_OT_NONE);
ASSERT(DMU_OT_IS_VALID(BP_GET_TYPE(bp)));
if (ds == NULL) {
/*
* Account for the meta-objset space in its placeholder
* dsl_dir.
*/
ASSERT3U(compressed, ==, uncompressed); /* it's all metadata */
dsl_dir_diduse_space(tx->tx_pool->dp_mos_dir, DD_USED_HEAD,
used, compressed, uncompressed, tx);
dsl_dir_dirty(tx->tx_pool->dp_mos_dir, tx);
dsl_pool_mos_diduse_space(tx->tx_pool,
used, compressed, uncompressed);
return;
}
dmu_buf_will_dirty(ds->ds_dbuf, tx);
Expand Down Expand Up @@ -146,15 +140,9 @@ dsl_dataset_block_kill(dsl_dataset_t *ds, const blkptr_t *bp, dmu_tx_t *tx,

ASSERT(used > 0);
if (ds == NULL) {
/*
* Account for the meta-objset space in its placeholder
* dataset.
*/
dsl_free(tx->tx_pool, tx->tx_txg, bp);

dsl_dir_diduse_space(tx->tx_pool->dp_mos_dir, DD_USED_HEAD,
-used, -compressed, -uncompressed, tx);
dsl_dir_dirty(tx->tx_pool->dp_mos_dir, tx);
dsl_pool_mos_diduse_space(tx->tx_pool,
-used, -compressed, -uncompressed);
return (used);
}
ASSERT3P(tx->tx_pool, ==, ds->ds_dir->dd_pool);
Expand Down Expand Up @@ -1068,26 +1056,26 @@ dsl_dataset_destroy(dsl_dataset_t *ds, void *tag, boolean_t defer)

dd = ds->ds_dir;

/*
* Check for errors and mark this ds as inconsistent, in
* case we crash while freeing the objects.
*/
err = dsl_sync_task_do(dd->dd_pool, dsl_dataset_destroy_begin_check,
dsl_dataset_destroy_begin_sync, ds, NULL, 0);
if (err)
goto out;

err = dmu_objset_from_ds(ds, &os);
if (err)
goto out;

/*
* If async destruction is not enabled try to remove all objects
* while in the open context so that there is less work to do in
* the syncing context.
*/
if (!spa_feature_is_enabled(dsl_dataset_get_spa(ds),
&spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
/*
* Check for errors and mark this ds as inconsistent, in
* case we crash while freeing the objects.
*/
err = dsl_sync_task_do(dd->dd_pool,
dsl_dataset_destroy_begin_check,
dsl_dataset_destroy_begin_sync, ds, NULL, 0);
if (err)
goto out;

err = dmu_objset_from_ds(ds, &os);
if (err)
goto out;

/*
* Remove all objects while in the open context so that
* there is less work to do in the syncing context.
*/
for (obj = 0; err == 0; err = dmu_object_next(os, &obj, FALSE,
ds->ds_phys->ds_prev_snap_txg)) {
/*
Expand All @@ -1098,30 +1086,25 @@ dsl_dataset_destroy(dsl_dataset_t *ds, void *tag, boolean_t defer)
}
if (err != ESRCH)
goto out;
}

/*
* Only the ZIL knows how to free log blocks.
*/
zil_destroy(dmu_objset_zil(os), B_FALSE);

/*
* Sync out all in-flight IO.
*/
txg_wait_synced(dd->dd_pool, 0);

/*
* If we managed to free all the objects in open
* context, the user space accounting should be zero.
*/
if (ds->ds_phys->ds_bp.blk_fill == 0 &&
dmu_objset_userused_enabled(os)) {
uint64_t count;
/*
* Sync out all in-flight IO.
*/
txg_wait_synced(dd->dd_pool, 0);

ASSERT(zap_count(os, DMU_USERUSED_OBJECT, &count) != 0 ||
count == 0);
ASSERT(zap_count(os, DMU_GROUPUSED_OBJECT, &count) != 0 ||
count == 0);
/*
* If we managed to free all the objects in open
* context, the user space accounting should be zero.
*/
if (ds->ds_phys->ds_bp.blk_fill == 0 &&
dmu_objset_userused_enabled(os)) {
uint64_t count;

ASSERT(zap_count(os, DMU_USERUSED_OBJECT,
&count) != 0 || count == 0);
ASSERT(zap_count(os, DMU_GROUPUSED_OBJECT,
&count) != 0 || count == 0);
}
}

rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER);
Expand Down Expand Up @@ -1859,6 +1842,7 @@ dsl_dataset_destroy_sync(void *arg1, void *tag, dmu_tx_t *tx)
} else {
zfeature_info_t *async_destroy =
&spa_feature_table[SPA_FEATURE_ASYNC_DESTROY];
objset_t *os;

/*
* There's no next snapshot, so this is a head dataset.
Expand All @@ -1870,6 +1854,8 @@ dsl_dataset_destroy_sync(void *arg1, void *tag, dmu_tx_t *tx)
dsl_deadlist_free(mos, ds->ds_phys->ds_deadlist_obj, tx);
ds->ds_phys->ds_deadlist_obj = 0;

VERIFY3U(0, ==, dmu_objset_from_ds(ds, &os));

if (!spa_feature_is_enabled(dp->dp_spa, async_destroy)) {
err = old_synchronous_dataset_destroy(ds, tx);
} else {
Expand All @@ -1879,12 +1865,12 @@ dsl_dataset_destroy_sync(void *arg1, void *tag, dmu_tx_t *tx)
*/
uint64_t used, comp, uncomp;

ASSERT(err == 0 || err == EBUSY);
zil_destroy_sync(dmu_objset_zil(os), tx);

if (!spa_feature_is_active(dp->dp_spa, async_destroy)) {
spa_feature_incr(dp->dp_spa, async_destroy, tx);
dp->dp_bptree_obj = bptree_alloc(
dp->dp_meta_objset, tx);
VERIFY(zap_add(dp->dp_meta_objset,
dp->dp_bptree_obj = bptree_alloc(mos, tx);
VERIFY(zap_add(mos,
DMU_POOL_DIRECTORY_OBJECT,
DMU_POOL_BPTREE_OBJ, sizeof (uint64_t), 1,
&dp->dp_bptree_obj, tx) == 0);
Expand All @@ -1897,7 +1883,7 @@ dsl_dataset_destroy_sync(void *arg1, void *tag, dmu_tx_t *tx)
ASSERT(!DS_UNIQUE_IS_ACCURATE(ds) ||
ds->ds_phys->ds_unique_bytes == used);

bptree_add(dp->dp_meta_objset, dp->dp_bptree_obj,
bptree_add(mos, dp->dp_bptree_obj,
&ds->ds_phys->ds_bp, ds->ds_phys->ds_prev_snap_txg,
used, comp, uncomp, tx);
dsl_dir_diduse_space(ds->ds_dir, DD_USED_HEAD,
Expand Down Expand Up @@ -2179,7 +2165,6 @@ dsl_dataset_sync(dsl_dataset_t *ds, zio_t *zio, dmu_tx_t *tx)
dmu_buf_will_dirty(ds->ds_dbuf, tx);
ds->ds_phys->ds_fsid_guid = ds->ds_fsid_guid;

dsl_dir_dirty(ds->ds_dir, tx);
dmu_objset_sync(ds->ds_objset, zio, tx);
}

Expand Down
10 changes: 3 additions & 7 deletions usr/src/uts/common/fs/zfs/dsl_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ dsl_dir_open_obj(dsl_pool_t *dp, uint64_t ddobj,
kmem_free(dd, sizeof (dsl_dir_t));
dmu_buf_rele(dbuf, tag);
return (err);

}

void
Expand Down Expand Up @@ -224,7 +223,7 @@ dsl_dir_name(dsl_dir_t *dd, char *buf)
}
}

/* Calculate name legnth, avoiding all the strcat calls of dsl_dir_name */
/* Calculate name length, avoiding all the strcat calls of dsl_dir_name */
int
dsl_dir_namelen(dsl_dir_t *dd)
{
Expand Down Expand Up @@ -582,8 +581,6 @@ dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx)
{
ASSERT(dmu_tx_is_syncing(tx));

dmu_buf_will_dirty(dd->dd_dbuf, tx);

mutex_enter(&dd->dd_lock);
ASSERT3U(dd->dd_tempreserved[tx->tx_txg&TXG_MASK], ==, 0);
dprintf_dd(dd, "txg=%llu towrite=%lluK\n", tx->tx_txg,
Expand Down Expand Up @@ -940,8 +937,6 @@ dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type,
ASSERT(dmu_tx_is_syncing(tx));
ASSERT(type < DD_USED_NUM);

dsl_dir_dirty(dd, tx);

if (needlock)
mutex_enter(&dd->dd_lock);
accounted_delta = parent_delta(dd, dd->dd_phys->dd_used_bytes, used);
Expand All @@ -950,6 +945,7 @@ dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type,
dd->dd_phys->dd_compressed_bytes >= -compressed);
ASSERT(uncompressed >= 0 ||
dd->dd_phys->dd_uncompressed_bytes >= -uncompressed);
dmu_buf_will_dirty(dd->dd_dbuf, tx);
dd->dd_phys->dd_used_bytes += used;
dd->dd_phys->dd_uncompressed_bytes += uncompressed;
dd->dd_phys->dd_compressed_bytes += compressed;
Expand Down Expand Up @@ -991,13 +987,13 @@ dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta,
if (delta == 0 || !(dd->dd_phys->dd_flags & DD_FLAG_USED_BREAKDOWN))
return;

dsl_dir_dirty(dd, tx);
if (needlock)
mutex_enter(&dd->dd_lock);
ASSERT(delta > 0 ?
dd->dd_phys->dd_used_breakdown[oldtype] >= delta :
dd->dd_phys->dd_used_breakdown[newtype] >= -delta);
ASSERT(dd->dd_phys->dd_used_bytes >= ABS(delta));
dmu_buf_will_dirty(dd->dd_dbuf, tx);
dd->dd_phys->dd_used_breakdown[oldtype] -= delta;
dd->dd_phys->dd_used_breakdown[newtype] += delta;
if (needlock)
Expand Down
Loading

0 comments on commit ce636f8

Please sign in to comment.