The branch main has been updated by markj:

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

commit ef067b579954c3c443b2a70566e24d94a7583d19
Author:     Mark Johnston <[email protected]>
AuthorDate: 2023-10-23 16:25:20 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2023-10-23 16:29:20 +0000

    makefs/zfs: Update dd_used_breakdown after writing the MOS
    
    Fixes:  96092bf9108c ("makefs/zfs: Fill out dd_used_breakdown fields in DSL 
directories")
    Sponsored by:   The FreeBSD Foundation
---
 usr.sbin/makefs/zfs/dsl.c    | 18 ++++++++++++++++--
 usr.sbin/makefs/zfs/objset.c |  3 +--
 usr.sbin/makefs/zfs/zfs.h    |  2 +-
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/usr.sbin/makefs/zfs/dsl.c b/usr.sbin/makefs/zfs/dsl.c
index f7abebe2e245..93083f286e81 100644
--- a/usr.sbin/makefs/zfs/dsl.c
+++ b/usr.sbin/makefs/zfs/dsl.c
@@ -423,7 +423,7 @@ dsl_dir_alloc(zfs_opt_t *zfs, const char *name)
        return (dir);
 }
 
-void
+static void
 dsl_dir_size_add(zfs_dsl_dir_t *dir, uint64_t bytes)
 {
        dir->phys->dd_used_bytes += bytes;
@@ -431,6 +431,19 @@ dsl_dir_size_add(zfs_dsl_dir_t *dir, uint64_t bytes)
        dir->phys->dd_uncompressed_bytes += bytes;
 }
 
+/*
+ * See dsl_dir_root_finalize().
+ */
+void
+dsl_dir_root_finalize(zfs_opt_t *zfs, uint64_t bytes)
+{
+       dsl_dir_size_add(zfs->mosdsldir, bytes);
+       zfs->mosdsldir->phys->dd_used_breakdown[DD_USED_HEAD] += bytes;
+
+       dsl_dir_size_add(zfs->rootdsldir, bytes);
+       zfs->rootdsldir->phys->dd_used_breakdown[DD_USED_CHILD] += bytes;
+}
+
 /*
  * Convert dataset properties into entries in the DSL directory's properties
  * ZAP.
@@ -520,7 +533,8 @@ dsl_dir_finalize(zfs_opt_t *zfs, zfs_dsl_dir_t *dir, void 
*arg __unused)
                 * The root directory needs a special case: the amount of
                 * space used for the MOS isn't known until everything else is
                 * finalized, so it can't be accounted in the MOS directory's
-                * parent until then.
+                * parent until then, at which point dsl_dir_root_finalize() is
+                * called.
                 */
                if (dir == zfs->rootdsldir && cdir == zfs->mosdsldir)
                        continue;
diff --git a/usr.sbin/makefs/zfs/objset.c b/usr.sbin/makefs/zfs/objset.c
index 3e3dcdeced4b..6be732db477a 100644
--- a/usr.sbin/makefs/zfs/objset.c
+++ b/usr.sbin/makefs/zfs/objset.c
@@ -185,8 +185,7 @@ objset_write(zfs_opt_t *zfs, zfs_objset_t *os)
                 * We've finished allocating space, account for it in $MOS and
                 * in the parent directory.
                 */
-               dsl_dir_size_add(zfs->mosdsldir, os->space);
-               dsl_dir_size_add(zfs->rootdsldir, os->space);
+               dsl_dir_root_finalize(zfs, os->space);
        }
        _objset_write(zfs, os, c, dnodeloc);
 }
diff --git a/usr.sbin/makefs/zfs/zfs.h b/usr.sbin/makefs/zfs/zfs.h
index 193ca1248d89..9af090b14912 100644
--- a/usr.sbin/makefs/zfs/zfs.h
+++ b/usr.sbin/makefs/zfs/zfs.h
@@ -124,7 +124,7 @@ char *dsl_dir_get_mountpoint(zfs_opt_t *, zfs_dsl_dir_t *);
 bool dsl_dir_has_dataset(zfs_dsl_dir_t *);
 bool dsl_dir_dataset_has_objset(zfs_dsl_dir_t *);
 void dsl_dir_dataset_write(zfs_opt_t *, zfs_objset_t *, zfs_dsl_dir_t *);
-void dsl_dir_size_add(zfs_dsl_dir_t *, uint64_t);
+void dsl_dir_root_finalize(zfs_opt_t *, uint64_t);
 void dsl_write(zfs_opt_t *);
 
 /* fs.c */

Reply via email to