git: 96092bf9108c - main - makefs/zfs: Fill out dd_used_breakdown fields in DSL directories

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Mon, 23 Oct 2023 15:17:59 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=96092bf9108c97b45d18fd26fbe91f2d1c7799b8

commit 96092bf9108c97b45d18fd26fbe91f2d1c7799b8
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-10-23 15:08:04 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-10-23 15:12:14 +0000

    makefs/zfs: Fill out dd_used_breakdown fields in DSL directories
    
    This is required for the "used", "usedds" and "usedchild" dataset
    properties to be displayed.
    
    PR:             274613
    Reported by:    Mike Tancsa <mike@sentex.net>
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
---
 usr.sbin/makefs/zfs/dsl.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/makefs/zfs/dsl.c b/usr.sbin/makefs/zfs/dsl.c
index a9ab93a90c38..f7abebe2e245 100644
--- a/usr.sbin/makefs/zfs/dsl.c
+++ b/usr.sbin/makefs/zfs/dsl.c
@@ -482,7 +482,7 @@ dsl_dir_finalize(zfs_opt_t *zfs, zfs_dsl_dir_t *dir, void *arg __unused)
 	dnode_phys_t *snapnames;
 	zfs_dsl_dataset_t *headds;
 	zfs_objset_t *os;
-	uint64_t bytes, snapnamesid;
+	uint64_t bytes, childbytes, snapnamesid;
 
 	dsl_dir_finalize_props(dir);
 	zap_write(zfs, dir->propszap);
@@ -514,6 +514,7 @@ dsl_dir_finalize(zfs_opt_t *zfs, zfs_dsl_dir_t *dir, void *arg __unused)
 	headds->phys->ds_uncompressed_bytes = bytes;
 	headds->phys->ds_compressed_bytes = bytes;
 
+	childbytes = 0;
 	STAILQ_FOREACH(cdir, &dir->children, next) {
 		/*
 		 * The root directory needs a special case: the amount of
@@ -523,9 +524,13 @@ dsl_dir_finalize(zfs_opt_t *zfs, zfs_dsl_dir_t *dir, void *arg __unused)
 		 */
 		if (dir == zfs->rootdsldir && cdir == zfs->mosdsldir)
 			continue;
-		bytes += cdir->phys->dd_used_bytes;
+		childbytes += cdir->phys->dd_used_bytes;
 	}
-	dsl_dir_size_add(dir, bytes);
+	dsl_dir_size_add(dir, bytes + childbytes);
+
+	dir->phys->dd_flags |= DD_FLAG_USED_BREAKDOWN;
+	dir->phys->dd_used_breakdown[DD_USED_HEAD] = bytes;
+	dir->phys->dd_used_breakdown[DD_USED_CHILD] = childbytes;
 }
 
 void