diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 63fb41df8..7f17de03d 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -1905,7 +1905,7 @@ dump_dedup_ratio(const ddt_stat_t *dds) } static void -dump_ddt(ddt_t *ddt, enum ddt_type type, enum ddt_class class) +dump_ddt(ddt_t *ddt, ddt_type_t type, ddt_class_t class) { char name[DDT_NAMELEN]; ddt_entry_t dde; @@ -1965,8 +1965,8 @@ dump_all_ddts(spa_t *spa) for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) { ddt_t *ddt = spa->spa_ddt[c]; - for (enum ddt_type type = 0; type < DDT_TYPES; type++) { - for (enum ddt_class class = 0; class < DDT_CLASSES; + for (ddt_type_t type = 0; type < DDT_TYPES; type++) { + for (ddt_class_t class = 0; class < DDT_CLASSES; class++) { dump_ddt(ddt, type, class); } diff --git a/include/sys/ddt.h b/include/sys/ddt.h index 25b8e7c9d..a11324209 100644 --- a/include/sys/ddt.h +++ b/include/sys/ddt.h @@ -41,22 +41,29 @@ struct abd; /* * On-disk DDT formats, in the desired search order (newest version first). */ -enum ddt_type { +typedef enum { DDT_TYPE_ZAP = 0, DDT_TYPES -}; +} ddt_type_t; + +_Static_assert(DDT_TYPES <= UINT8_MAX, + "ddt_type_t must fit in a uint8_t"); + +/* New and updated entries recieve this type, see ddt_sync_entry() */ +#define DDT_TYPE_DEFAULT (DDT_TYPE_ZAP) /* * DDT classes, in the desired search order (highest replication level first). */ -enum ddt_class { +typedef enum { DDT_CLASS_DITTO = 0, DDT_CLASS_DUPLICATE, DDT_CLASS_UNIQUE, DDT_CLASSES -}; +} ddt_class_t; -#define DDT_TYPE_CURRENT 0 +_Static_assert(DDT_CLASSES < UINT8_MAX, + "ddt_class_t must fit in a uint8_t"); /* * On-disk ddt entry: key (name) and physical storage (value). @@ -116,8 +123,8 @@ struct ddt_entry { ddt_phys_t dde_phys[DDT_PHYS_TYPES]; zio_t *dde_lead_zio[DDT_PHYS_TYPES]; struct abd *dde_repair_abd; - enum ddt_type dde_type; - enum ddt_class dde_class; + ddt_type_t dde_type; + ddt_class_t dde_class; uint8_t dde_loading; uint8_t dde_loaded; kcondvar_t dde_cv; @@ -182,7 +189,7 @@ extern ddt_entry_t *ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add); extern void ddt_prefetch(spa_t *spa, const blkptr_t *bp); extern void ddt_remove(ddt_t *ddt, ddt_entry_t *dde); -extern boolean_t ddt_class_contains(spa_t *spa, enum ddt_class max_class, +extern boolean_t ddt_class_contains(spa_t *spa, ddt_class_t max_class, const blkptr_t *bp); extern ddt_entry_t *ddt_repair_start(ddt_t *ddt, const blkptr_t *bp); diff --git a/include/sys/ddt_impl.h b/include/sys/ddt_impl.h index c43ced5a7..9960f9666 100644 --- a/include/sys/ddt_impl.h +++ b/include/sys/ddt_impl.h @@ -70,14 +70,14 @@ extern void ddt_key_fill(ddt_key_t *ddk, const blkptr_t *bp); extern void ddt_stat_add(ddt_stat_t *dst, const ddt_stat_t *src, uint64_t neg); -extern void ddt_object_name(ddt_t *ddt, enum ddt_type type, - enum ddt_class clazz, char *name); -extern int ddt_object_walk(ddt_t *ddt, enum ddt_type type, - enum ddt_class clazz, uint64_t *walk, ddt_entry_t *dde); -extern int ddt_object_count(ddt_t *ddt, enum ddt_type type, - enum ddt_class clazz, uint64_t *count); -extern int ddt_object_info(ddt_t *ddt, enum ddt_type type, - enum ddt_class clazz, dmu_object_info_t *); +extern void ddt_object_name(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz, + char *name); +extern int ddt_object_walk(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz, + uint64_t *walk, ddt_entry_t *dde); +extern int ddt_object_count(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz, + uint64_t *count); +extern int ddt_object_info(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz, + dmu_object_info_t *); #ifdef __cplusplus } diff --git a/module/zfs/ddt.c b/module/zfs/ddt.c index 321437c22..1b7063998 100644 --- a/module/zfs/ddt.c +++ b/module/zfs/ddt.c @@ -58,7 +58,7 @@ static const char *const ddt_class_name[DDT_CLASSES] = { }; static void -ddt_object_create(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_create(ddt_t *ddt, ddt_type_t type, ddt_class_t class, dmu_tx_t *tx) { spa_t *spa = ddt->ddt_spa; @@ -83,7 +83,7 @@ ddt_object_create(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } static void -ddt_object_destroy(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_destroy(ddt_t *ddt, ddt_type_t type, ddt_class_t class, dmu_tx_t *tx) { spa_t *spa = ddt->ddt_spa; @@ -107,7 +107,7 @@ ddt_object_destroy(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } static int -ddt_object_load(ddt_t *ddt, enum ddt_type type, enum ddt_class class) +ddt_object_load(ddt_t *ddt, ddt_type_t type, ddt_class_t class) { ddt_object_t *ddo = &ddt->ddt_object_stats[type][class]; dmu_object_info_t doi; @@ -147,7 +147,7 @@ ddt_object_load(ddt_t *ddt, enum ddt_type type, enum ddt_class class) } static void -ddt_object_sync(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_sync(ddt_t *ddt, ddt_type_t type, ddt_class_t class, dmu_tx_t *tx) { ddt_object_t *ddo = &ddt->ddt_object_stats[type][class]; @@ -173,13 +173,13 @@ ddt_object_sync(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } static boolean_t -ddt_object_exists(ddt_t *ddt, enum ddt_type type, enum ddt_class class) +ddt_object_exists(ddt_t *ddt, ddt_type_t type, ddt_class_t class) { return (!!ddt->ddt_object[type][class]); } static int -ddt_object_lookup(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_lookup(ddt_t *ddt, ddt_type_t type, ddt_class_t class, ddt_entry_t *dde) { if (!ddt_object_exists(ddt, type, class)) @@ -190,7 +190,7 @@ ddt_object_lookup(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } static void -ddt_object_prefetch(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_prefetch(ddt_t *ddt, ddt_type_t type, ddt_class_t class, ddt_entry_t *dde) { if (!ddt_object_exists(ddt, type, class)) @@ -201,7 +201,7 @@ ddt_object_prefetch(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } static int -ddt_object_update(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_update(ddt_t *ddt, ddt_type_t type, ddt_class_t class, ddt_entry_t *dde, dmu_tx_t *tx) { ASSERT(ddt_object_exists(ddt, type, class)); @@ -211,7 +211,7 @@ ddt_object_update(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } static int -ddt_object_remove(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_remove(ddt_t *ddt, ddt_type_t type, ddt_class_t class, ddt_entry_t *dde, dmu_tx_t *tx) { ASSERT(ddt_object_exists(ddt, type, class)); @@ -221,7 +221,7 @@ ddt_object_remove(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } int -ddt_object_walk(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_walk(ddt_t *ddt, ddt_type_t type, ddt_class_t class, uint64_t *walk, ddt_entry_t *dde) { ASSERT(ddt_object_exists(ddt, type, class)); @@ -231,7 +231,7 @@ ddt_object_walk(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } int -ddt_object_count(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_count(ddt_t *ddt, ddt_type_t type, ddt_class_t class, uint64_t *count) { ASSERT(ddt_object_exists(ddt, type, class)); @@ -241,7 +241,7 @@ ddt_object_count(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } int -ddt_object_info(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_info(ddt_t *ddt, ddt_type_t type, ddt_class_t class, dmu_object_info_t *doi) { if (!ddt_object_exists(ddt, type, class)) @@ -252,7 +252,7 @@ ddt_object_info(ddt_t *ddt, enum ddt_type type, enum ddt_class class, } void -ddt_object_name(ddt_t *ddt, enum ddt_type type, enum ddt_class class, +ddt_object_name(ddt_t *ddt, ddt_type_t type, ddt_class_t class, char *name) { (void) snprintf(name, DDT_NAMELEN, DMU_POOL_DDT, @@ -460,8 +460,8 @@ ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add) { ddt_key_t search; ddt_entry_t *dde; - enum ddt_type type; - enum ddt_class class; + ddt_type_t type; + ddt_class_t class; avl_index_t where; int error; @@ -536,8 +536,8 @@ ddt_prefetch(spa_t *spa, const blkptr_t *bp) ddt = ddt_select(spa, bp); ddt_key_fill(&dde.dde_key, bp); - for (enum ddt_type type = 0; type < DDT_TYPES; type++) { - for (enum ddt_class class = 0; class < DDT_CLASSES; class++) { + for (ddt_type_t type = 0; type < DDT_TYPES; type++) { + for (ddt_class_t class = 0; class < DDT_CLASSES; class++) { ddt_object_prefetch(ddt, type, class, &dde); } } @@ -625,8 +625,8 @@ ddt_load(spa_t *spa) for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) { ddt_t *ddt = spa->spa_ddt[c]; - for (enum ddt_type type = 0; type < DDT_TYPES; type++) { - for (enum ddt_class class = 0; class < DDT_CLASSES; + for (ddt_type_t type = 0; type < DDT_TYPES; type++) { + for (ddt_class_t class = 0; class < DDT_CLASSES; class++) { error = ddt_object_load(ddt, type, class); if (error != 0 && error != ENOENT) @@ -657,7 +657,7 @@ ddt_unload(spa_t *spa) } boolean_t -ddt_class_contains(spa_t *spa, enum ddt_class max_class, const blkptr_t *bp) +ddt_class_contains(spa_t *spa, ddt_class_t max_class, const blkptr_t *bp) { ddt_t *ddt; ddt_entry_t *dde; @@ -673,8 +673,8 @@ ddt_class_contains(spa_t *spa, enum ddt_class max_class, const blkptr_t *bp) ddt_key_fill(&(dde->dde_key), bp); - for (enum ddt_type type = 0; type < DDT_TYPES; type++) { - for (enum ddt_class class = 0; class <= max_class; class++) { + for (ddt_type_t type = 0; type < DDT_TYPES; type++) { + for (ddt_class_t class = 0; class <= max_class; class++) { if (ddt_object_lookup(ddt, type, class, dde) == 0) { kmem_cache_free(ddt_entry_cache, dde); return (B_TRUE); @@ -696,8 +696,8 @@ ddt_repair_start(ddt_t *ddt, const blkptr_t *bp) dde = ddt_alloc(&ddk); - for (enum ddt_type type = 0; type < DDT_TYPES; type++) { - for (enum ddt_class class = 0; class < DDT_CLASSES; class++) { + for (ddt_type_t type = 0; type < DDT_TYPES; type++) { + for (ddt_class_t class = 0; class < DDT_CLASSES; class++) { /* * We can only do repair if there are multiple copies * of the block. For anything in the UNIQUE class, @@ -796,10 +796,10 @@ ddt_sync_entry(ddt_t *ddt, ddt_entry_t *dde, dmu_tx_t *tx, uint64_t txg) dsl_pool_t *dp = ddt->ddt_spa->spa_dsl_pool; ddt_phys_t *ddp = dde->dde_phys; ddt_key_t *ddk = &dde->dde_key; - enum ddt_type otype = dde->dde_type; - enum ddt_type ntype = DDT_TYPE_CURRENT; - enum ddt_class oclass = dde->dde_class; - enum ddt_class nclass; + ddt_type_t otype = dde->dde_type; + ddt_type_t ntype = DDT_TYPE_DEFAULT; + ddt_class_t oclass = dde->dde_class; + ddt_class_t nclass; uint64_t total_refcnt = 0; ASSERT(dde->dde_loaded); @@ -883,9 +883,9 @@ ddt_sync_table(ddt_t *ddt, dmu_tx_t *tx, uint64_t txg) ddt_free(dde); } - for (enum ddt_type type = 0; type < DDT_TYPES; type++) { + for (ddt_type_t type = 0; type < DDT_TYPES; type++) { uint64_t add, count = 0; - for (enum ddt_class class = 0; class < DDT_CLASSES; class++) { + for (ddt_class_t class = 0; class < DDT_CLASSES; class++) { if (ddt_object_exists(ddt, type, class)) { ddt_object_sync(ddt, type, class, tx); VERIFY0(ddt_object_count(ddt, type, class, @@ -893,7 +893,7 @@ ddt_sync_table(ddt_t *ddt, dmu_tx_t *tx, uint64_t txg) count += add; } } - for (enum ddt_class class = 0; class < DDT_CLASSES; class++) { + for (ddt_class_t class = 0; class < DDT_CLASSES; class++) { if (count == 0 && ddt_object_exists(ddt, type, class)) ddt_object_destroy(ddt, type, class, tx); } diff --git a/module/zfs/ddt_stats.c b/module/zfs/ddt_stats.c index e1d367730..4ef6c3a07 100644 --- a/module/zfs/ddt_stats.c +++ b/module/zfs/ddt_stats.c @@ -132,8 +132,8 @@ ddt_get_dedup_object_stats(spa_t *spa, ddt_object_t *ddo_total) /* Sum the statistics we cached in ddt_object_sync(). */ for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) { ddt_t *ddt = spa->spa_ddt[c]; - for (enum ddt_type type = 0; type < DDT_TYPES; type++) { - for (enum ddt_class class = 0; class < DDT_CLASSES; + for (ddt_type_t type = 0; type < DDT_TYPES; type++) { + for (ddt_class_t class = 0; class < DDT_CLASSES; class++) { ddt_object_t *ddo = &ddt->ddt_object_stats[type][class]; @@ -156,8 +156,8 @@ ddt_get_dedup_histogram(spa_t *spa, ddt_histogram_t *ddh) { for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) { ddt_t *ddt = spa->spa_ddt[c]; - for (enum ddt_type type = 0; type < DDT_TYPES && ddt; type++) { - for (enum ddt_class class = 0; class < DDT_CLASSES; + for (ddt_type_t type = 0; type < DDT_TYPES && ddt; type++) { + for (ddt_class_t class = 0; class < DDT_CLASSES; class++) { ddt_histogram_add(ddh, &ddt->ddt_histogram_cache[type][class]); diff --git a/module/zfs/dsl_scan.c b/module/zfs/dsl_scan.c index d04149f56..060a5cc36 100644 --- a/module/zfs/dsl_scan.c +++ b/module/zfs/dsl_scan.c @@ -203,7 +203,7 @@ static uint_t zfs_scan_checkpoint_intval = 7200; /* in seconds */ int zfs_scan_suspend_progress = 0; /* set to prevent scans from progressing */ static int zfs_no_scrub_io = B_FALSE; /* set to disable scrub i/o */ static int zfs_no_scrub_prefetch = B_FALSE; /* set to disable scrub prefetch */ -static const enum ddt_class zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE; +static const ddt_class_t zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE; /* max number of blocks to free in a single TXG */ static uint64_t zfs_async_block_max_blocks = UINT64_MAX; /* max number of dedup blocks to free in a single TXG */ @@ -2962,7 +2962,7 @@ dsl_scan_ddt_entry(dsl_scan_t *scn, enum zio_checksum checksum, * If there are N references to a deduped block, we don't want to scrub it * N times -- ideally, we should scrub it exactly once. * - * We leverage the fact that the dde's replication class (enum ddt_class) + * We leverage the fact that the dde's replication class (ddt_class_t) * is ordered from highest replication class (DDT_CLASS_DITTO) to lowest * (DDT_CLASS_UNIQUE) so that we may walk the DDT in that order. *