Fix wrong dedup_table_size for legacy dedup

If we call ddt_log_load() for legacy ddt, we will end up going into
ddt_log_update_stats() and filling uninitialized value into ddo_dspace.
This value will then get added to dedup_table_size during
ddt_get_dedup_object_stats().

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Closes #17019
Closes #17699

Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Co-authored-by: Chunwei Chen <david.chen@nutanix.com>
This commit is contained in:
Chunwei Chen 2025-09-08 14:02:51 -07:00 committed by Brian Behlendorf
parent 34ca2b8392
commit c755aa486d
2 changed files with 12 additions and 8 deletions

View File

@ -1701,9 +1701,11 @@ ddt_load(spa_t *spa)
}
}
error = ddt_log_load(ddt);
if (error != 0 && error != ENOENT)
return (error);
if (ddt->ddt_flags & DDT_FLAG_LOG) {
error = ddt_log_load(ddt);
if (error != 0 && error != ENOENT)
return (error);
}
DDT_KSTAT_SET(ddt, dds_log_active_entries,
avl_numnodes(&ddt->ddt_log_active->ddl_tree));

View File

@ -176,11 +176,13 @@ ddt_log_update_stats(ddt_t *ddt)
* that's reasonable to expect anyway.
*/
dmu_object_info_t doi;
uint64_t nblocks;
dmu_object_info(ddt->ddt_os, ddt->ddt_log_active->ddl_object, &doi);
nblocks = doi.doi_physical_blocks_512;
dmu_object_info(ddt->ddt_os, ddt->ddt_log_flushing->ddl_object, &doi);
nblocks += doi.doi_physical_blocks_512;
uint64_t nblocks = 0;
if (dmu_object_info(ddt->ddt_os, ddt->ddt_log_active->ddl_object,
&doi) == 0)
nblocks += doi.doi_physical_blocks_512;
if (dmu_object_info(ddt->ddt_os, ddt->ddt_log_flushing->ddl_object,
&doi) == 0)
nblocks += doi.doi_physical_blocks_512;
ddt_object_t *ddo = &ddt->ddt_log_stats;
ddo->ddo_count =