From nobody Tue Aug 16 15:03:15 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4M6ZCR2Wl1z4ZKf5; Tue, 16 Aug 2022 15:03:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M6ZCR20t8z3M6q; Tue, 16 Aug 2022 15:03:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660662195; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hiR9rbSnacCAcpeM02c7A+4V6fEQ1CEANOkFFdML4Ko=; b=OFmy9MUsCiRP824gD/KG1wIqKH6FqC5r+FND3KT8eM+Buzbopvuii8CqJRf8POc2PULboT lCVy19G/Q4+34VRASRNuhlQYMbfwhRul1jV23a6Sw2Ve9C/UhaLVse3le/gNgCPiiJxnR6 awwPomTPaJBnDjNjBfzYuM0TPpAVhByejcmgLNTdL+jc7RZIF3eJVP6B3xLtGuj/YQQz0w DlqxAT/uVxJkrvLxfTaUgXHdeFUR6m/X/kRyujvO4VwCEZcOA4LYl4MxiTTp22JSGLQgsR oD4kwAxnp4NT3GBizHQrdMUtGGdQAY4V+KuUCq0HACvGLJPKpoFRWVBNyRJ44w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4M6ZCR0trQz1CNP; Tue, 16 Aug 2022 15:03:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27GF3FoE046701; Tue, 16 Aug 2022 15:03:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27GF3F1I046700; Tue, 16 Aug 2022 15:03:15 GMT (envelope-from git) Date: Tue, 16 Aug 2022 15:03:15 GMT Message-Id: <202208161503.27GF3F1I046700@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 4f816f5b11ca - main - makefs: Fix space accounting for the root DSL directory List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4f816f5b11ca7a5db965455d11d1db19162cfca6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660662195; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hiR9rbSnacCAcpeM02c7A+4V6fEQ1CEANOkFFdML4Ko=; b=Yo/WgavcWzD1Qzrsy3XILeDK/S5U+qZ3wAWeZpaWzwCuwLetMtZPLEUA9j5FSFo/oo9Gy+ mq8vlzX54709cTZTiz0vE9bFaHncNc2jnI8dM81mL6l/QJwSFXsuN6UlZyc20/Ttl6UGfL INzMJulQxjPmZp4gXACGbj5Zrzgd381LcjT9Qf8qCzYGB3knGdOIGhB44uzaPCDuM+jtMD qJahelLsS6KV8wzatwOuchsAogk019sZaOkE3XOPi9h1yZyFCp9IPjRmA/M4bgo+WhqO+B wU2WZkUmkJkMYSw9jMBG0yFthmQSqDQocT0b4o08d3lX0ra2+k8WTsqLFxQyqw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660662195; a=rsa-sha256; cv=none; b=LZcVKq961v7rWUKqM/Vb8B1Agv79DXT29UmFMzLy3JBKzYFJwAay+bG0hYfXa8U8F44vRD 1Bkxt5AGxcGn6/qEIK8Hf6PQMnEXdLgvNCn2iISSSF3WmMzkRVyWu29TRdr3NYU61y71u/ ohEq9cUP212RRFo0Ur70IEmJMkaNV4L6VsAHIro9pYkqnTNJUOo7+3vxvFhmL4BYxhk7J3 d3VgZBV3Pk4BcLRnqVVkOnp0nkKHBbw6xh/QSf71wHpFtcqWsc4DmCvbQkSOeDbw3YhQhM HR3AKAl0r+LAnImzcLSsYn9zzb6TldqdMnKK6/K0URyB5/mRNTG0NlczRgOBAA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=4f816f5b11ca7a5db965455d11d1db19162cfca6 commit 4f816f5b11ca7a5db965455d11d1db19162cfca6 Author: Mark Johnston AuthorDate: 2022-08-16 14:15:53 +0000 Commit: Mark Johnston CommitDate: 2022-08-16 15:02:51 +0000 makefs: Fix space accounting for the root DSL directory Space used by the MOS is summed after all on-disk data structures are finalized, so the MOS DSL directory represents a special case when counting bytes used for each directory. The DSL layer failed to update the MOS DSL directory's parent, the root directory, accordingly, so the root directory reported less space used than was used in reality. Be careful to update the root directory after the MOS is finalized. PR: 265849 Sponsored by: The FreeBSD Foundation --- usr.sbin/makefs/zfs/dsl.c | 21 +++++++++++++++------ usr.sbin/makefs/zfs/objset.c | 6 ++++-- usr.sbin/makefs/zfs/zfs.h | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/usr.sbin/makefs/zfs/dsl.c b/usr.sbin/makefs/zfs/dsl.c index 1d20f5f3891a..223f5941ef69 100644 --- a/usr.sbin/makefs/zfs/dsl.c +++ b/usr.sbin/makefs/zfs/dsl.c @@ -425,11 +425,11 @@ dsl_dir_alloc(zfs_opt_t *zfs, const char *name) } void -dsl_dir_size_set(zfs_dsl_dir_t *dir, uint64_t bytes) +dsl_dir_size_add(zfs_dsl_dir_t *dir, uint64_t bytes) { - dir->phys->dd_used_bytes = bytes; - dir->phys->dd_compressed_bytes = bytes; - dir->phys->dd_uncompressed_bytes = bytes; + dir->phys->dd_used_bytes += bytes; + dir->phys->dd_compressed_bytes += bytes; + dir->phys->dd_uncompressed_bytes += bytes; } /* @@ -515,9 +515,18 @@ 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; - STAILQ_FOREACH(cdir, &dir->children, next) + STAILQ_FOREACH(cdir, &dir->children, next) { + /* + * 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. + */ + if (dir == zfs->rootdsldir && cdir == zfs->mosdsldir) + continue; bytes += cdir->phys->dd_used_bytes; - dsl_dir_size_set(dir, bytes); + } + dsl_dir_size_add(dir, bytes); } void diff --git a/usr.sbin/makefs/zfs/objset.c b/usr.sbin/makefs/zfs/objset.c index fdb17167a607..edd0b66d6147 100644 --- a/usr.sbin/makefs/zfs/objset.c +++ b/usr.sbin/makefs/zfs/objset.c @@ -180,9 +180,11 @@ objset_write(zfs_opt_t *zfs, zfs_objset_t *os) vdev_spacemap_write(zfs); /* - * We've finished allocating space, account for it in $MOS. + * We've finished allocating space, account for it in $MOS and + * in the parent directory. */ - dsl_dir_size_set(zfs->mosdsldir, os->space); + dsl_dir_size_add(zfs->mosdsldir, os->space); + dsl_dir_size_add(zfs->rootdsldir, 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 7ad3151dd8a2..6b743b40b3ab 100644 --- a/usr.sbin/makefs/zfs/zfs.h +++ b/usr.sbin/makefs/zfs/zfs.h @@ -123,7 +123,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_set(zfs_dsl_dir_t *, uint64_t); +void dsl_dir_size_add(zfs_dsl_dir_t *, uint64_t); void dsl_write(zfs_opt_t *); /* fs.c */