Permalink
Browse files

ztest: scrub ddt repair

The ztest_ddt_repair() test is designed inflict damage to the
ddt which can be repairable by a scrub.  Unfortunately, this
repair logic was broken at some point and it went undetected.
This issue is not specific to ztest, but thankfully this extra
redundancy is rarely enabled and even more rarely needed.

The root cause was identified to be the ddt_bp_create()
function called by dsl_scan_ddt_entry() which did not set the
dedup bit of the generated block pointer.

The consequence of this was that the ZIO_DDT_READ_PIPELINE was
never enabled for the block pointer during the scrub, and the
dedup ditto repair logic was never run.  Note that for demand
reads which don't rely on ddt_bp_create() the required pipeline
stages would be enabled and the repair performed.

This was resolved by unconditionally setting the dedup bit in
ddt_bp_create().  This way all codes paths which may need to
perform a repair from a block pointer generated from the dtt
entry will be able too.  The only exception is that the dedup
bit is cleared in ddt_phys_free() which is required to avoid
leaking space.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
  • Loading branch information...
behlendorf committed Jan 11, 2019
1 parent 6955b40 commit ef874624bf59a60f7beade8f764107d7058e5ac7
Showing with 31 additions and 14 deletions.
  1. +23 −13 cmd/ztest/ztest.c
  2. +8 −1 module/zfs/ddt.c
@@ -6010,20 +6010,15 @@ ztest_ddt_repair(ztest_ds_t *zd, uint64_t id)
spa_t *spa = ztest_spa;
objset_t *os = zd->zd_os;
ztest_od_t *od;
uint64_t object, blocksize, txg, pattern, psize;
uint64_t object, blocksize, txg, pattern;
enum zio_checksum checksum = spa_dedup_checksum(spa);
dmu_buf_t *db;
dmu_tx_t *tx;
abd_t *abd;
blkptr_t blk;
int copies = 2 * ZIO_DEDUPDITTO_MIN;
int i;

blocksize = ztest_random_blocksize();
blocksize = MIN(blocksize, 2048); /* because we write so many */

od = umem_alloc(sizeof (ztest_od_t), UMEM_NOFAIL);
ztest_od_init(od, id, FTAG, 0, DMU_OT_UINT64_OTHER, blocksize, 0, 0);
ztest_od_init(od, id, FTAG, 0, DMU_OT_UINT64_OTHER, 0, 0, 0);

if (ztest_object_init(zd, od, sizeof (ztest_od_t), B_FALSE) != 0) {
umem_free(od, sizeof (ztest_od_t));
@@ -6032,7 +6027,7 @@ ztest_ddt_repair(ztest_ds_t *zd, uint64_t id)

/*
* Take the name lock as writer to prevent anyone else from changing
* the pool and dataset properies we need to maintain during this test.
* the pool and dataset properties we need to maintain during this test.
*/
(void) pthread_rwlock_wrlock(&ztest_name_lock);

@@ -6054,6 +6049,22 @@ ztest_ddt_repair(ztest_ds_t *zd, uint64_t id)
blocksize = od[0].od_blocksize;
pattern = zs->zs_guid ^ dds.dds_guid;

/*
* The block size is limited by DMU_MAX_ACCESS (64MB) which
* caps the maximum transaction size. A block size of up to
* SPA_OLD_MAXBLOCKSIZE is allowed which results in a maximum
* transaction size of: 128K * 200 (copies) = ~25MB
*
* The actual block size is checked here, rather than requested
* above, because the way ztest_od_init() is implemented it does
* not guarantee the block size requested will be used.
*/
if (blocksize > SPA_OLD_MAXBLOCKSIZE) {
(void) pthread_rwlock_unlock(&ztest_name_lock);
umem_free(od, sizeof (ztest_od_t));
return;
}

ASSERT(object != 0);

tx = dmu_tx_create(os);
@@ -6091,16 +6102,15 @@ ztest_ddt_repair(ztest_ds_t *zd, uint64_t id)
/*
* Find out what block we got.
*/
VERIFY0(dmu_buf_hold(os, object, 0, FTAG, &db,
DMU_READ_NO_PREFETCH));
blk = *((dmu_buf_impl_t *)db)->db_blkptr;
VERIFY0(dmu_buf_hold(os, object, 0, FTAG, &db, DMU_READ_NO_PREFETCH));
blkptr_t blk = *((dmu_buf_impl_t *)db)->db_blkptr;
dmu_buf_rele(db, FTAG);

/*
* Damage the block. Dedup-ditto will save us when we read it later.
*/
psize = BP_GET_PSIZE(&blk);
abd = abd_alloc_linear(psize, B_TRUE);
uint64_t psize = BP_GET_PSIZE(&blk);
abd_t *abd = abd_alloc_linear(psize, B_TRUE);
ztest_pattern_set(abd_to_buf(abd), psize, ~pattern);

(void) zio_wait(zio_rewrite(NULL, spa, 0, &blk,
@@ -291,7 +291,7 @@ ddt_bp_create(enum zio_checksum checksum,
BP_SET_CHECKSUM(bp, checksum);
BP_SET_TYPE(bp, DMU_OT_DEDUP);
BP_SET_LEVEL(bp, 0);
BP_SET_DEDUP(bp, 0);
BP_SET_DEDUP(bp, 1);
BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
}

@@ -346,6 +346,13 @@ ddt_phys_free(ddt_t *ddt, ddt_key_t *ddk, ddt_phys_t *ddp, uint64_t txg)
blkptr_t blk;

ddt_bp_create(ddt->ddt_checksum, ddk, ddp, &blk);

/*
* We set the dedup bit to 0 here now that we are actually freeing
* the dedup block instead of simply decrementing the reference count.
*/
BP_SET_DEDUP(&blk, 0);

ddt_phys_clear(ddp);
zio_free(ddt->ddt_spa, txg, &blk);
}

0 comments on commit ef87462

Please sign in to comment.