From nobody Wed Oct 07 14:58:22 2026 X-Original-To: dev-commits-src-main@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 4j0GTV6L4fz6w2B5 for ; Wed, 07 Oct 2026 14:58:22 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4j0GTV4hD4z4JPM for ; Wed, 07 Oct 2026 14:58:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791385102; 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=VVlDH/Dxmo54xzgI1U9Jr2+YtY0d69Le68YSp/UYTNY=; b=G8qupPI4PUfhQR4+IGuPGLY7ZfhDRkQF0Iv/YzqQhLEhPPKY0uIcwQ+J96Foy+tpQfBZfT Ip6ohaXnOUXbZ6AXaat5IKbKyJbD/84sE7SQ7Rz9k5WndlmRHbKkkbwGKS60P7KqtH9PQo 07Hci704+xK/POFA2SVcQdlaRRhxM+hrx8V+b2I4dMOw9QeOCLAukViGP6L6fh0H3awtrg Sn+iPqzuBTte6dXplO5QGQUeuGiMLdsFY3Geua40yjjiWRkYjqCCknBc5ee35uBGesE/We ZAYxVQbwNp+MVTlaNyzWoamYvJD/a6QLhcIhqmsE/91d//pdrVlNHZIvxbKaNg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791385102; b=IrH4Pk9xu3+FALRmBPZN6IkiXXIEuI6Um0cZTLbxWielocgx70dxsLYca5ZNopsWb/NXDS zgDLM6ZaisXTLUEXYS4pQX6Z0EyoiUXAZGNX1AT7OMUJSKlNP8MqBAmX5kdovflyXw/8wl 2EqUDbxpXZcsxfjX46ZliL69/Jva/nmlzrxGTrViTVhrm32fc5tnsAZIMDPsqtIH/qF+g/ EvnMqSk0SFDfiBb6Oh9YZ+8M6HgocI9Zefm+Im2Qw+79aTL3mtLqd4Bpb79wDYMfzUTPiH wuKxwgPxEpcycAQuXWjTnYawnHwfpwm5jk+9LIQw0VgOUfQI8fg/K+9FbDEZPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791385102; 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=VVlDH/Dxmo54xzgI1U9Jr2+YtY0d69Le68YSp/UYTNY=; b=p+8LWgRIBR4KGoe5lvg31yumCtSHQDMATEEwYTRSKmaTBWszthaioirYl//l8gUuLQgbFF 7/MxXYuvY1HXJHnXb1xxrVnufUzUD7w9wzcrQg07FMaisk3sYOWs6Yu9ZZR2q61rI95N5N W0aZ9nSEE84cXq3/MgClvFDQ95bPj/onHnmA1VHBnE5UP6qwgRMxyozeOs2w15VeqVhs5q qS5hIjtK6Tz7ldDw/GTxIRzDCs4cpptMRudY67j+XuR0H0v0R6FlIfH8cM63HfFLcNGJqp 6DNgZxdLt9HjcZ8CZixcezrmOsqEbevSpRWryvI2soeRVge9uUUxsnW7F0UmYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j0GTV39vBzy8R for ; Wed, 07 Oct 2026 14:58:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2190a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 07 Oct 2026 14:58:22 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: R. Christian McDonald Subject: git: dece5b05f577 - main - makefs/zfs: Allow the autotrim pool property to be set List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rcm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: dece5b05f577fc4c6b89af7ad48dfbdf7cc4945c Auto-Submitted: auto-generated Date: Wed, 07 Oct 2026 14:58:22 +0000 Message-Id: <6ac65e0e.2190a.1c9d522b@gitrepo.freebsd.org> The branch main has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=dece5b05f577fc4c6b89af7ad48dfbdf7cc4945c commit dece5b05f577fc4c6b89af7ad48dfbdf7cc4945c Author: R. Christian McDonald AuthorDate: 2026-10-07 14:57:40 +0000 Commit: R. Christian McDonald CommitDate: 2026-10-07 14:57:40 +0000 makefs/zfs: Allow the autotrim pool property to be set Add an "autotrim" option taking "on" or "off". The value is stored in the pool properties object alongside "bootfs", so the imported pool starts trimming freed space automatically without a separate "zpool set" step. When the option is omitted nothing is written and the pool keeps the default ("off"), exactly as before. A string option is used rather than makefs's boolean option type since the latter ignores its value, which would make "autotrim=off" enable the feature. Define the spa_autotrim_t enumeration in the boot zfsimpl.h, copied from OpenZFS's sys/spa.h, so that makefs can refer to SPA_AUTOTRIM_OFF and SPA_AUTOTRIM_ON by name. The loader does not use it. Document the option in makefs(8) and add a regression test. Reviewed by: markj MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D60420 --- sys/cddl/boot/zfs/zfsimpl.h | 10 ++++++ usr.sbin/makefs/makefs.8 | 11 +++++- usr.sbin/makefs/tests/makefs_zfs_tests.sh | 59 +++++++++++++++++++++++++++++++ usr.sbin/makefs/zfs.c | 17 +++++++++ usr.sbin/makefs/zfs/zfs.h | 2 ++ 5 files changed, 98 insertions(+), 1 deletion(-) diff --git a/sys/cddl/boot/zfs/zfsimpl.h b/sys/cddl/boot/zfs/zfsimpl.h index d3ae3c32635d..b14a829025d1 100644 --- a/sys/cddl/boot/zfs/zfsimpl.h +++ b/sys/cddl/boot/zfs/zfsimpl.h @@ -904,6 +904,16 @@ typedef enum pool_state { POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */ } pool_state_t; +/* + * Send TRIM commands in-line during normal pool operation while deleting. + * OFF: no + * ON: yes + */ +typedef enum { + SPA_AUTOTRIM_OFF = 0, + SPA_AUTOTRIM_ON, +} spa_autotrim_t; + /* * The uberblock version is incremented whenever an incompatible on-disk * format change is made to the SPA, DMU, or ZAP. diff --git a/usr.sbin/makefs/makefs.8 b/usr.sbin/makefs/makefs.8 index e165702813ae..47c7bf50df5a 100644 --- a/usr.sbin/makefs/makefs.8 +++ b/usr.sbin/makefs/makefs.8 @@ -33,7 +33,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd August 12, 2026 +.Dd October 7, 2026 .Dt MAKEFS 8 .Os .Sh NAME @@ -535,6 +535,15 @@ The following keywords are supported: The base-2 logarithm of the minimum block size. Typical values are 9 (512B blocks) and 12 (4KB blocks). The default value is 12. +.It Cm autotrim +The value of the +.Ql autotrim +pool property, either +.Ql on +or +.Ql off . +The default is +.Ql off . .It Cm bootfs The name of the bootable dataset for the pool. Specifying this option causes the diff --git a/usr.sbin/makefs/tests/makefs_zfs_tests.sh b/usr.sbin/makefs/tests/makefs_zfs_tests.sh index 22adfda00d2b..fe27c62ab765 100644 --- a/usr.sbin/makefs/tests/makefs_zfs_tests.sh +++ b/usr.sbin/makefs/tests/makefs_zfs_tests.sh @@ -107,6 +107,64 @@ autoexpand_cleanup() common_cleanup } +# +# Test setting the autotrim pool property. +# +atf_test_case autotrim cleanup +autotrim_body() +{ + local src val + + create_test_inputs + + atf_check -s exit:1 -e match:"invalid value .foo. for autotrim" \ + $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ + -o autotrim=foo $TEST_IMAGE $TEST_INPUTS_DIR + + for val in on off; do + atf_check $MAKEFS -s 1g -o rootpath=/ \ + -o poolname=$ZFS_POOL_NAME \ + -o autotrim=$val \ + $TEST_IMAGE $TEST_INPUTS_DIR + + import_image + + check_image_contents + + # OpenZFS reports a pool property whose value equals the + # default as coming from the default, even if it was set. + if [ $val = off ]; then + src=default + else + src=local + fi + atf_check -o inline:$val\\n \ + zpool get -H -o value autotrim $ZFS_POOL_NAME + atf_check -o inline:$src\\n \ + zpool get -H -o source autotrim $ZFS_POOL_NAME + + atf_check zpool destroy ${ZFS_POOL_NAME} + atf_check rm -f ${TEST_ZFS_POOL_NAME} + atf_check mdconfig -d -u $(cat ${TEST_MD_DEVICE_FILE}) + atf_check rm -f ${TEST_MD_DEVICE_FILE} + done + + # Without the option the property keeps its default value. + atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ + $TEST_IMAGE $TEST_INPUTS_DIR + + import_image + + atf_check -o inline:off\\n \ + zpool get -H -o value autotrim $ZFS_POOL_NAME + atf_check -o inline:default\\n \ + zpool get -H -o source autotrim $ZFS_POOL_NAME +} +autotrim_cleanup() +{ + common_cleanup +} + # # Test with some default layout defined by the common code. # @@ -1110,6 +1168,7 @@ T_flag_mtree_cleanup() atf_init_test_cases() { atf_add_test_case autoexpand + atf_add_test_case autotrim atf_add_test_case basic atf_add_test_case compression atf_add_test_case dataset_removal diff --git a/usr.sbin/makefs/zfs.c b/usr.sbin/makefs/zfs.c index 1288c52141ab..9e304202fb4f 100644 --- a/usr.sbin/makefs/zfs.c +++ b/usr.sbin/makefs/zfs.c @@ -82,6 +82,8 @@ zfs_prep_opts(fsinfo_t *fsopts) memset(zfs, 0, sizeof(*zfs)); const option_t zfs_options[] = { + { '\0', "autotrim", &zfs->autotrim, OPT_STRPTR, + 0, 0, "Automatic TRIM (on or off)" }, { '\0', "bootfs", &zfs->bootfs, OPT_STRPTR, 0, 0, "Bootable dataset" }, { '\0', "mssize", &zfs->mssize, OPT_INT64, @@ -247,6 +249,17 @@ zfs_check_opts(fsinfo_t *fsopts) if (zfs->vdevpath[0] != '/') errx(1, "path `%s' must be absolute", zfs->vdevpath); + zfs->autotrimval = SPA_AUTOTRIM_OFF; + if (zfs->autotrim != NULL) { + if (strcmp(zfs->autotrim, "on") == 0) + zfs->autotrimval = SPA_AUTOTRIM_ON; + else if (strcmp(zfs->autotrim, "off") == 0) + zfs->autotrimval = SPA_AUTOTRIM_OFF; + else + errx(1, "invalid value `%s' for autotrim", + zfs->autotrim); + } + if (zfs->ashift == 0) zfs->ashift = 12; @@ -262,6 +275,7 @@ zfs_cleanup_opts(fsinfo_t *fsopts) zfs = fsopts->fs_specific; free(zfs->rootpath); free(zfs->vdevpath); + free(zfs->autotrim); free(zfs->bootfs); free(__DECONST(void *, zfs->poolname)); STAILQ_FOREACH_SAFE(d, &zfs->datasetdescs, next, tmp) { @@ -474,6 +488,9 @@ pool_init_objdir_poolprops(zfs_opt_t *zfs, zfs_zap_t *objdir) zap_add_uint64(objdir, DMU_POOL_PROPS, id); zfs->poolprops = zap_alloc(zfs->mos, dnode); + + if (zfs->autotrim != NULL) + zap_add_uint64(zfs->poolprops, "autotrim", zfs->autotrimval); } /* diff --git a/usr.sbin/makefs/zfs/zfs.h b/usr.sbin/makefs/zfs/zfs.h index 13f2ece43c69..ebc54caad8e9 100644 --- a/usr.sbin/makefs/zfs/zfs.h +++ b/usr.sbin/makefs/zfs/zfs.h @@ -80,6 +80,8 @@ typedef struct { const char *poolname; char *rootpath; /* implicit mount point prefix */ char *vdevpath; /* vdev path, pool property */ + char *autotrim; /* "on" or "off", pool property */ + spa_autotrim_t autotrimval; /* parsed autotrim value */ char *bootfs; /* bootable dataset, pool property */ int ashift; /* vdev block size */ uint64_t mssize; /* metaslab size */