]> git.hungrycats.org Git - linux/commitdiff
allocator-hints: patch 9 keeps the hint values in the UAPI header; patches 10-12...
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 12 Nov 2026 17:19:46 +0000 (12:19 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 12 Nov 2026 17:19:46 +0000 (12:19 -0500)
Re-exported from misc-next topics/allocator-hints 6a3533244111 (testing
9379f731c8e9, zb64 9e0e654aa3f3); export verified, fixup unchanged.
Still 12 patches, Cheng Yongkang's kobject fix excluded (now in
btrfs/for-next 4ab0b18d8a57).

Zygo 11-12: patch 9 drops the CONFIG_ guard instead of moving the values
to volumes.h; patch 10 no longer refuses the replace source (option A);
patch 11 and 12 messages updated (12: statfs changes f_bavail only).

Cover: Cheng paragraph dropped; patch 9 paragraph rewritten; patch 10,
11 and 12 paragraphs extended to match; diffstat now lists
include/uapi/linux/btrfs_tree.h.  Other covers' Date: churn reverted.
TESTING.md: 2026-11-12 round (oracles, object comparison, buildchecks,
headers_install with a control).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
topics/allocator-hints/0000-cover-letter.patch
topics/allocator-hints/0009-btrfs-allocator-hints-define-the-hint-values-uncondi.patch [new file with mode: 0644]
topics/allocator-hints/0009-btrfs-allocator-hints-move-the-hint-values-out-of-th.patch [deleted file]
topics/allocator-hints/0010-btrfs-allocator-hints-keep-the-hint-across-device-re.patch
topics/allocator-hints/0011-btrfs-allocator-hints-don-t-run-a-transaction-from-t.patch
topics/allocator-hints/0012-btrfs-allocator-hints-make-the-available-space-estim.patch
topics/allocator-hints/TESTING.md

index 105a35728fd772a9d7dde99a6c9855121f423cae..ee708e3994f3c0c317091ac347bcccf31ed4bb80 100644 (file)
@@ -1,6 +1,6 @@
-From df0e45e0fe79ddc8c332cba8ab8678b37e55c160 Mon Sep 17 00:00:00 2001
+From a3426d68a9f018271cb42757f657b53701671a0b Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Mon, 9 Nov 2026 08:41:09 -0500
+Date: Thu, 12 Nov 2026 11:46:48 -0500
 Subject: [PATCH 00/12] btrfs: allocator hints (Kai Krakow's series)
 To: linux-btrfs@vger.kernel.org
 
@@ -17,27 +17,28 @@ included so that the series applies as one.
 
 Follow-ups:
 
-Patch 4 adds a writable attribute under the devid kobject.  Deleting a
-missing device frees the btrfs_device with its devid kobject still
-registered, so reading any devinfo attribute is a use-after-free; Cheng
-Yongkang's "[PATCH v2] btrfs: remove devid kobject when deleting a
-missing device" (2026-10-26, Reviewed-by: Qu Wenruo), posted separately,
-fixes that.
-
-Patch 9 moves the hint values out of the UAPI header into
-fs/btrfs/volumes.h: a CONFIG_ symbol in a UAPI header makes
-"make headers_install" (and the deb/rpm package targets) fail.
+Patch 9 drops the CONFIG_BTRFS_ALLOCATOR_HINTS guard around the hint
+values in include/uapi/linux/btrfs_tree.h: a CONFIG_ symbol in a UAPI
+header makes "make headers_install" (and the deb/rpm package targets)
+fail.  The values are on-disk format (the meaning of dev_item.type),
+userspace needs them to read and set the hints, and defining them
+changes no userspace-visible structure, so they are always exported.
 
 Patch 10 keeps the hint across device replace: the target took over the
 source's dev item but not the in-memory type, so the next update of the
-item wrote type 0 over the hint.
+item wrote type 0 over the hint.  The source's hint can still be changed
+during a replace and the target inherits it, so a replace can move to a
+device of a different type (e.g. SSD to HDD).  A type write to the
+target, or to the source after the finish, returns -EBUSY instead of
+aborting the transaction.
 
 Patch 11 stores a changed type without running a transaction from the
 sysfs store: the device is marked dirty (BTRFS_DEV_STATE_TYPE_DIRTY) and
 the item is written by the next commit.  Running a transaction from the
 store deadlocked against device remove.  The store orders the new type
 before the dirty bit, so a commit cannot write the old type and clear
-the bit.
+the bit.  It takes chunk_mutex, which also closes the window at the end
+of a replace where a hint written to the source could be lost.
 
 Patch 12 makes the available space estimates honor the hints.  The
 allocator keeps data off METADATA_ONLY and NONE_ONLY devices and
@@ -48,6 +49,8 @@ the filesystem aborted the transaction with ENOSPC and forced it
 read-only, while statfs still offered 3 GiB.  The patch shares the hint
 rules between the allocator and the estimates, which are kept separately
 for data and metadata.  With it the same fill ends in a clean ENOSPC.
+In statfs only f_bavail (df Avail) changes; f_blocks and f_bfree (df
+Size and Used) still count every device.
 Reproducer: alloc-hints-space-test.sh.  Kai, this patch doubles as the
 bug report for your series.
 
@@ -69,21 +72,23 @@ KeinNiemand (1):
   btrfs: honor allocator hints for fixed-width mirrors
 
 Zygo Blaxell (4):
-  btrfs: allocator hints: move the hint values out of the UAPI header
+  btrfs: allocator hints: define the hint values unconditionally in the
+    UAPI header
   btrfs: allocator hints: keep the hint across device replace
   btrfs: allocator hints: don't run a transaction from the type store
   btrfs: allocator hints: make the available space estimates honor the
     hints
 
- fs/btrfs/Kconfig       |  54 ++++++++
- fs/btrfs/dev-replace.c |   9 ++
- fs/btrfs/space-info.c  |   3 +-
- fs/btrfs/super.c       |   4 +
- fs/btrfs/sysfs.c       | 104 +++++++++++++++
- fs/btrfs/transaction.c |   3 +
- fs/btrfs/volumes.c     | 282 ++++++++++++++++++++++++++++++++++++++---
- fs/btrfs/volumes.h     |  58 ++++++++-
- 8 files changed, 496 insertions(+), 21 deletions(-)
+ fs/btrfs/Kconfig                |  54 ++++++
+ fs/btrfs/dev-replace.c          |   9 +
+ fs/btrfs/space-info.c           |   3 +-
+ fs/btrfs/super.c                |   4 +
+ fs/btrfs/sysfs.c                | 104 ++++++++++++
+ fs/btrfs/transaction.c          |   3 +
+ fs/btrfs/volumes.c              | 282 ++++++++++++++++++++++++++++++--
+ fs/btrfs/volumes.h              |  37 ++++-
+ include/uapi/linux/btrfs_tree.h |  18 ++
+ 9 files changed, 493 insertions(+), 21 deletions(-)
 
 
 -- 
diff --git a/topics/allocator-hints/0009-btrfs-allocator-hints-define-the-hint-values-uncondi.patch b/topics/allocator-hints/0009-btrfs-allocator-hints-define-the-hint-values-uncondi.patch
new file mode 100644 (file)
index 0000000..96a11d3
--- /dev/null
@@ -0,0 +1,55 @@
+From 6c5c219911f08069e629aaa12b0fbb22c6b3d064 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Sun, 4 Oct 2026 00:44:02 -0400
+Subject: [PATCH 09/12] btrfs: allocator hints: define the hint values
+ unconditionally in the UAPI header
+To: linux-btrfs@vger.kernel.org
+
+The BTRFS_DEV_ALLOCATION_* values sit in include/uapi/linux/btrfs_tree.h
+inside #ifdef CONFIG_BTRFS_ALLOCATOR_HINTS, to keep them away from
+userspace until the interface is settled.  A CONFIG_ symbol in a UAPI
+header is rejected by scripts/headers_install.sh:
+
+  error: include/uapi/linux/btrfs_tree.h: leak CONFIG_BTRFS_ALLOCATOR_HINTS to user-space
+
+so 'make headers_install' (and the deb/rpm package targets, which run
+it) fail with the patch set applied.
+
+The values are on-disk format: they give the meaning of the low bits of
+dev_item.type, and userspace (btrfs-progs) needs them to read and set a
+device's hint.  Defining them changes no userspace-visible structure.
+So drop the guard and always export the values.  The code that acts on
+the hints stays under CONFIG_BTRFS_ALLOCATOR_HINTS.
+
+---
+ include/uapi/linux/btrfs_tree.h | 7 -------
+ 1 file changed, 7 deletions(-)
+
+diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
+index 035b7385622bb..f1917364d127e 100644
+--- a/include/uapi/linux/btrfs_tree.h
++++ b/include/uapi/linux/btrfs_tree.h
+@@ -585,11 +585,6 @@ struct btrfs_node {
+       struct btrfs_key_ptr ptrs[];
+ } __attribute__ ((__packed__));
+ 
+-/*
+- * This defines the chunk allocation hints for a device. It uses an ifdef guard
+- * in UAPI to avoid exposing it to userspace.
+- */
+-#ifdef CONFIG_BTRFS_ALLOCATOR_HINTS
+ /* dev_item.type */
+ 
+ /* btrfs chunk allocation hints */
+@@ -608,8 +603,6 @@ struct btrfs_node {
+ #define BTRFS_DEV_ALLOCATION_NONE_ONLY                (5ULL)
+ /* 6..7 are unused values */
+ 
+-#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
+-
+ struct btrfs_dev_item {
+       /* the internal btrfs device id */
+       __le64 devid;
+-- 
+2.47.3
+
diff --git a/topics/allocator-hints/0009-btrfs-allocator-hints-move-the-hint-values-out-of-th.patch b/topics/allocator-hints/0009-btrfs-allocator-hints-move-the-hint-values-out-of-th.patch
deleted file mode 100644 (file)
index f1e4f18..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-From 7fbece5a12d5b4477bd520ac74756a3b3b0aa12a Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 4 Oct 2026 00:44:02 -0400
-Subject: [PATCH 09/12] btrfs: allocator hints: move the hint values out of the
- UAPI header
-To: linux-btrfs@vger.kernel.org
-
-The BTRFS_DEV_ALLOCATION_* values sit in include/uapi/linux/btrfs_tree.h
-inside #ifdef CONFIG_BTRFS_ALLOCATOR_HINTS, to keep them away from
-userspace until the interface is settled.  A CONFIG_ symbol in a UAPI
-header is rejected by scripts/headers_install.sh:
-
-  error: include/uapi/linux/btrfs_tree.h: leak CONFIG_BTRFS_ALLOCATOR_HINTS to user-space
-
-so 'make headers_install' (and the deb/rpm package targets, which run
-it) fail with the patch set applied.
-
-Only fs/btrfs uses the values, so move them to fs/btrfs/volumes.h, still
-under the Kconfig guard.  That keeps them out of userspace, which was the
-intent, without the leak.
-
----
- fs/btrfs/volumes.h              | 21 +++++++++++++++++++++
- include/uapi/linux/btrfs_tree.h | 25 -------------------------
- 2 files changed, 21 insertions(+), 25 deletions(-)
-
-diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index da7c03871b838..91efbea27d04c 100644
---- a/fs/btrfs/volumes.h
-+++ b/fs/btrfs/volumes.h
-@@ -598,6 +598,27 @@ struct btrfs_io_context {
-       struct btrfs_io_stripe stripes[];
- };
- 
-+/*
-+ * Chunk allocation hints, stored in dev_item.type.  Kept out of the UAPI
-+ * headers until the interface is settled.
-+ */
-+#ifdef CONFIG_BTRFS_ALLOCATOR_HINTS
-+#define BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT   3
-+/* preferred data chunk, but metadata chunk allowed */
-+#define BTRFS_DEV_ALLOCATION_PREFERRED_DATA   (0ULL)
-+/* preferred metadata chunk, but data chunk allowed */
-+#define BTRFS_DEV_ALLOCATION_PREFERRED_METADATA       (1ULL)
-+/* only metadata chunk allowed */
-+#define BTRFS_DEV_ALLOCATION_METADATA_ONLY    (2ULL)
-+/* only data chunk allowed */
-+#define BTRFS_DEV_ALLOCATION_DATA_ONLY                (3ULL)
-+/* avoid chunk allocation if possible */
-+#define BTRFS_DEV_ALLOCATION_PREFERRED_NONE   (4ULL)
-+/* deny chunk allocation */
-+#define BTRFS_DEV_ALLOCATION_NONE_ONLY                (5ULL)
-+/* 6..7 are unused values */
-+#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
-+
- struct btrfs_device_info {
-       struct btrfs_device *dev;
-       u64 dev_offset;
-diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
-index 035b7385622bb..47ee52859b458 100644
---- a/include/uapi/linux/btrfs_tree.h
-+++ b/include/uapi/linux/btrfs_tree.h
-@@ -585,31 +585,6 @@ struct btrfs_node {
-       struct btrfs_key_ptr ptrs[];
- } __attribute__ ((__packed__));
- 
--/*
-- * This defines the chunk allocation hints for a device. It uses an ifdef guard
-- * in UAPI to avoid exposing it to userspace.
-- */
--#ifdef CONFIG_BTRFS_ALLOCATOR_HINTS
--/* dev_item.type */
--
--/* btrfs chunk allocation hints */
--#define BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT   3
--/* preferred data chunk, but metadata chunk allowed */
--#define BTRFS_DEV_ALLOCATION_PREFERRED_DATA   (0ULL)
--/* preferred metadata chunk, but data chunk allowed */
--#define BTRFS_DEV_ALLOCATION_PREFERRED_METADATA       (1ULL)
--/* only metadata chunk allowed */
--#define BTRFS_DEV_ALLOCATION_METADATA_ONLY    (2ULL)
--/* only data chunk allowed */
--#define BTRFS_DEV_ALLOCATION_DATA_ONLY                (3ULL)
--/* avoid chunk allocation if possible */
--#define BTRFS_DEV_ALLOCATION_PREFERRED_NONE   (4ULL)
--/* deny chunk allocation */
--#define BTRFS_DEV_ALLOCATION_NONE_ONLY                (5ULL)
--/* 6..7 are unused values */
--
--#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
--
- struct btrfs_dev_item {
-       /* the internal btrfs device id */
-       __le64 devid;
--- 
-2.47.3
-
index 50904d6d08e0a5c75721552e3ef0f878e34b70b3..40cc95f71bbe12a586aa43e0a6e52a4a9a60be78 100644 (file)
@@ -1,4 +1,4 @@
-From 1e8e85d87b5bea59f545e977e229199963980318 Mon Sep 17 00:00:00 2001
+From 389885a1676b3f3bccc445c43edc0911934f862c Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
 Date: Sun, 4 Oct 2026 00:44:58 -0400
 Subject: [PATCH 10/12] btrfs: allocator hints: keep the hint across device
@@ -22,22 +22,29 @@ the transaction, forcing the filesystem read-only in the middle of the
 replace.  Device remove has the same window between deleting the dev
 item and removing the sysfs directory.
 
-Return -EBUSY for the replace target, for a device with the replace
-devid, and for the source of a running or suspended replace.  An -ENOENT
-that still gets past these checks (remove, or a replace that finishes
-after them) ends the transaction without aborting it and returns -ENODEV.
+Return -EBUSY for the replace target and for a device with the replace
+devid.  An -ENOENT that still gets past these checks (remove, or a
+replace that finishes after them) ends the transaction without aborting
+it and returns -ENODEV.
+
+The source's hint can still be changed during a replace, and the target
+inherits it at the finish, so a replace can move to a device of a
+different type, e.g. SSD to HDD.  A write that races the finish can be
+lost: it misses the dev item and returns -ENODEV, or the finish has
+already copied the old type.  That is tolerable, and the next patch
+closes the window.
 
 ---
- fs/btrfs/Kconfig       |  9 +++++----
+ fs/btrfs/Kconfig       |  8 ++++----
  fs/btrfs/dev-replace.c |  6 ++++++
- fs/btrfs/sysfs.c       | 28 ++++++++++++++++++++++++++++
- 3 files changed, 39 insertions(+), 4 deletions(-)
+ fs/btrfs/sysfs.c       | 22 ++++++++++++++++++++++
+ 3 files changed, 32 insertions(+), 4 deletions(-)
 
 diff --git a/fs/btrfs/Kconfig b/fs/btrfs/Kconfig
-index e14cddb83c8a3..038626bd24a68 100644
+index e14cddb83c8a3..72c1ced888a95 100644
 --- a/fs/btrfs/Kconfig
 +++ b/fs/btrfs/Kconfig
-@@ -102,10 +102,11 @@ config BTRFS_ALLOCATOR_HINTS
+@@ -102,10 +102,10 @@ config BTRFS_ALLOCATOR_HINTS
          They cannot separate the two chunk classes and are outside the
          tiering use case targeted by this feature.
  
@@ -45,11 +52,10 @@ index e14cddb83c8a3..038626bd24a68 100644
 -        device. Reapply the hint after replacing a device. Hint updates are
 -        also not serialized with chunk allocation, so a concurrent new chunk
 -        may use either the old or the new setting.
-+        Device replace copies the allocation hint to the target device.
-+        The hint of the source and target devices cannot be changed while
-+        a replace is running or suspended. Hint updates are not serialized
-+        with chunk allocation, so a concurrent new chunk may use either the
-+        old or the new setting.
++        Device replace copies the allocation hint to the target device;
++        the target's hint cannot be changed until the replace finishes.
++        Hint updates are not serialized with chunk allocation, so a
++        concurrent new chunk may use either the old or the new setting.
  
          You are advised to watch your free space closely with btrfs tools
          instead of relying on df only.
@@ -71,48 +77,28 @@ index 3c48cc714fef2..903501370cbb1 100644
        memcpy(uuid_tmp, tgt_device->uuid, sizeof(uuid_tmp));
        memcpy(tgt_device->uuid, src_device->uuid, sizeof(tgt_device->uuid));
 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 16912c8f4f9e6..6457b74d67f93 100644
+index 16912c8f4f9e6..29cc1fba9e9c8 100644
 --- a/fs/btrfs/sysfs.c
 +++ b/fs/btrfs/sysfs.c
-@@ -19,6 +19,7 @@
- #include "transaction.h"
- #include "sysfs.h"
- #include "volumes.h"
-+#include "dev-replace.h"
- #include "space-info.h"
- #include "block-group.h"
- #include "qgroup.h"
-@@ -2021,6 +2022,7 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
-       struct btrfs_device *device;
-       int ret;
-       struct btrfs_trans_handle *trans;
-+      bool replacing;
- 
-       u64 type, prev_type;
- 
-@@ -2049,6 +2051,21 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2049,6 +2049,17 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
        if (!btrfs_dev_allocation_hint_valid(type))
                return -EINVAL;
  
 +      /*
-+       * A replace target has no dev item of its own.  When the replace
-+       * finishes, it takes over the source's dev item and type.  Neither
-+       * device's type may change until then.
++       * A replace target has no dev item of its own until the replace
++       * finishes and it takes over the source's dev item and type.  After
++       * the finish, the source has the replace devid and no dev item.  The
++       * source's type may change during the replace: the target inherits
++       * it at the finish.
 +       */
 +      if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state) ||
 +          device->devid == BTRFS_DEV_REPLACE_DEVID)
 +              return -EBUSY;
-+      down_read(&fs_info->dev_replace.rwsem);
-+      replacing = btrfs_dev_replace_is_ongoing(&fs_info->dev_replace) &&
-+                  fs_info->dev_replace.srcdev == device;
-+      up_read(&fs_info->dev_replace.rwsem);
-+      if (replacing)
-+              return -EBUSY;
 +
        trans = btrfs_start_transaction(root, 1);
        if (IS_ERR(trans))
                return PTR_ERR(trans);
-@@ -2058,6 +2075,17 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2058,6 +2069,17 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
  
        ret = btrfs_update_device(trans, device);
  
index c77333730bddf6a7f4bd0db8e40b4d60c94a4334..4807179d153a5f563271ba7b456affc154249716 100644 (file)
@@ -1,4 +1,4 @@
-From 719bd5945ed892368c908d1fd3e5e5f04d8083c2 Mon Sep 17 00:00:00 2001
+From d49c657c24936286f68a2ab0d35d9b9d01498b3d Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
 Date: Sun, 4 Oct 2026 10:55:00 -0400
 Subject: [PATCH 11/12] btrfs: allocator hints: don't run a transaction from
@@ -35,13 +35,14 @@ at the next commit: a hint is not worth aborting the transaction for.  The
 hint takes effect for new chunks at once and reaches the disk at the next
 commit, sync or unmount.
 
-With the replace swap serialized by chunk_mutex, the source of a running
-replace no longer needs to refuse hint changes: the finish copies the
-hint and the dirty bit to the target.  Only the replace target (devid 0,
-no dev item) still returns -EBUSY.  Also check sb_rdonly() before
-BTRFS_FS_OPEN, so a read-only mount reports -EROFS rather than -EBUSY,
-and refuse seed devices, which are read-only and not written by the
-commit-time update.
+Taking chunk_mutex in the store also closes the race at the end of a
+device replace: the finish moves the hint and the dirty bit to the
+target under the same mutex, so a hint change on the source either
+reaches the target or, once the source has the replace devid, returns
+-EBUSY.  The replace target (devid 0, no dev item) still returns -EBUSY.
+Also check sb_rdonly() before BTRFS_FS_OPEN, so a read-only mount
+reports -EROFS rather than -EBUSY, and refuse seed devices, which are
+read-only and not written by the commit-time update.
 
 The store orders the new type before the dirty bit
 (smp_mb__before_atomic(); the commit's test_and_clear_bit() is the other
@@ -50,31 +51,28 @@ commit cannot write the old type and clear the bit on a weakly ordered
 machine.
 
 ---
- fs/btrfs/Kconfig       |  9 ++---
+ fs/btrfs/Kconfig       |  4 +-
  fs/btrfs/dev-replace.c |  3 ++
- fs/btrfs/sysfs.c       | 89 ++++++++++++++++--------------------------
+ fs/btrfs/sysfs.c       | 83 +++++++++++++++++-------------------------
  fs/btrfs/transaction.c |  3 ++
- fs/btrfs/volumes.c     | 57 ++++++++++++++++++++++++++-
+ fs/btrfs/volumes.c     | 57 ++++++++++++++++++++++++++++-
  fs/btrfs/volumes.h     |  7 ++++
- 6 files changed, 107 insertions(+), 61 deletions(-)
+ 6 files changed, 105 insertions(+), 52 deletions(-)
 
 diff --git a/fs/btrfs/Kconfig b/fs/btrfs/Kconfig
-index 038626bd24a68..f097f9631a857 100644
+index 72c1ced888a95..f097f9631a857 100644
 --- a/fs/btrfs/Kconfig
 +++ b/fs/btrfs/Kconfig
-@@ -102,11 +102,10 @@ config BTRFS_ALLOCATOR_HINTS
+@@ -102,10 +102,10 @@ config BTRFS_ALLOCATOR_HINTS
          They cannot separate the two chunk classes and are outside the
          tiering use case targeted by this feature.
  
--        Device replace copies the allocation hint to the target device.
--        The hint of the source and target devices cannot be changed while
--        a replace is running or suspended. Hint updates are not serialized
--        with chunk allocation, so a concurrent new chunk may use either the
--        old or the new setting.
 +        A hint change applies to new chunks at once and is written to the
 +        device item at the next transaction commit (sync to force it).
-+        Device replace copies the allocation hint to the target device;
-+        the target's hint cannot be changed until the replace finishes.
+         Device replace copies the allocation hint to the target device;
+         the target's hint cannot be changed until the replace finishes.
+-        Hint updates are not serialized with chunk allocation, so a
+-        concurrent new chunk may use either the old or the new setting.
  
          You are advised to watch your free space closely with btrfs tools
          instead of relying on df only.
@@ -93,18 +91,10 @@ index 903501370cbb1..062fd114f5088 100644
        memcpy(uuid_tmp, tgt_device->uuid, sizeof(uuid_tmp));
        memcpy(tgt_device->uuid, src_device->uuid, sizeof(tgt_device->uuid));
 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 6457b74d67f93..6e1d0636f9af9 100644
+index 29cc1fba9e9c8..6e1d0636f9af9 100644
 --- a/fs/btrfs/sysfs.c
 +++ b/fs/btrfs/sysfs.c
-@@ -19,7 +19,6 @@
- #include "transaction.h"
- #include "sysfs.h"
- #include "volumes.h"
--#include "dev-replace.h"
- #include "space-info.h"
- #include "block-group.h"
- #include "qgroup.h"
-@@ -2018,31 +2017,22 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2017,30 +2017,22 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
                                        const char *buf, size_t len)
  {
        struct btrfs_fs_info *fs_info;
@@ -112,7 +102,6 @@ index 6457b74d67f93..6e1d0636f9af9 100644
        struct btrfs_device *device;
        int ret;
 -      struct btrfs_trans_handle *trans;
--      bool replacing;
 -
 -      u64 type, prev_type;
 +      u64 type;
@@ -141,7 +130,7 @@ index 6457b74d67f93..6e1d0636f9af9 100644
        ret = kstrtou64(buf, 0, &type);
        if (ret < 0)
                return -EINVAL;
-@@ -2051,55 +2041,44 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2049,51 +2041,44 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
        if (!btrfs_dev_allocation_hint_valid(type))
                return -EINVAL;
  
@@ -150,9 +139,11 @@ index 6457b74d67f93..6e1d0636f9af9 100644
 +              return -EROFS;
 +
        /*
--       * A replace target has no dev item of its own.  When the replace
--       * finishes, it takes over the source's dev item and type.  Neither
--       * device's type may change until then.
+-       * A replace target has no dev item of its own until the replace
+-       * finishes and it takes over the source's dev item and type.  After
+-       * the finish, the source has the replace devid and no dev item.  The
+-       * source's type may change during the replace: the target inherits
+-       * it at the finish.
 +       * No transaction here.  Device remove drains this attribute while it
 +       * holds a transaction handle and device_list_mutex, so a commit (which
 +       * waits for that handle) or a join (which can wait for
@@ -169,12 +160,6 @@ index 6457b74d67f93..6e1d0636f9af9 100644
 +      mutex_lock(&fs_info->chunk_mutex);
        if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state) ||
 -          device->devid == BTRFS_DEV_REPLACE_DEVID)
--              return -EBUSY;
--      down_read(&fs_info->dev_replace.rwsem);
--      replacing = btrfs_dev_replace_is_ongoing(&fs_info->dev_replace) &&
--                  fs_info->dev_replace.srcdev == device;
--      up_read(&fs_info->dev_replace.rwsem);
--      if (replacing)
 +          device->devid == BTRFS_DEV_REPLACE_DEVID) {
 +              mutex_unlock(&fs_info->chunk_mutex);
                return -EBUSY;
@@ -202,16 +187,16 @@ index 6457b74d67f93..6e1d0636f9af9 100644
 -              ret = -ENODEV;
 -              goto abort;
 -      }
--
++      smp_mb__before_atomic();
++      set_bit(BTRFS_DEV_STATE_TYPE_DIRTY, &device->dev_state);
++      mutex_unlock(&fs_info->chunk_mutex);
+ 
 -      if (ret < 0) {
 -              btrfs_abort_transaction(trans, ret);
 -              btrfs_end_transaction(trans);
 -              goto abort;
 -      }
-+      smp_mb__before_atomic();
-+      set_bit(BTRFS_DEV_STATE_TYPE_DIRTY, &device->dev_state);
-+      mutex_unlock(&fs_info->chunk_mutex);
- 
+-
 -      ret = btrfs_commit_transaction(trans);
 -      if (ret < 0)
 -              goto abort;
@@ -316,7 +301,7 @@ index 3bde22ffbd7c0..34ef420d35ce8 100644
  {
        btrfs_dev_stat_inc(dev, index);
 diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 91efbea27d04c..df5c6db129869 100644
+index da7c03871b838..181b8a4ea14b3 100644
 --- a/fs/btrfs/volumes.h
 +++ b/fs/btrfs/volumes.h
 @@ -110,6 +110,8 @@ static_assert(BTRFS_RAID_RAID1C4 == 8);
@@ -328,7 +313,7 @@ index 91efbea27d04c..df5c6db129869 100644
  
  /* Special value encoding failure to write primary super block. */
  #define BTRFS_SUPER_PRIMARY_WRITE_ERROR               (INT_MAX / 2)
-@@ -819,6 +821,11 @@ int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
+@@ -798,6 +800,11 @@ int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
  int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
  int btrfs_init_writeback_bio_size(struct btrfs_fs_info *fs_info);
  int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
index 38cf4022a1ec8e63d0f220f4baed630485d08a86..71153d58450076855d77b6dc80e374155daaf050 100644 (file)
@@ -1,4 +1,4 @@
-From df0e45e0fe79ddc8c332cba8ab8678b37e55c160 Mon Sep 17 00:00:00 2001
+From a3426d68a9f018271cb42757f657b53701671a0b Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
 Date: Sun, 18 Oct 2026 15:50:43 -0400
 Subject: [PATCH 12/12] btrfs: allocator hints: make the available space
@@ -43,7 +43,13 @@ Give the estimates the allocator's view of the hints:
   exclude for the type and picks hint tiers the way the allocator does.
   btrfs_get_per_profile_avail() takes the block group type.  Mixed block
   groups ignore the hints, as in the allocator.
-- statfs leaves out devices that data chunks may not use.
+- statfs leaves out devices that data chunks may not use.  Only the
+  available space changes: f_bavail (df Avail) leaves out the
+  unallocated space of those devices, while f_blocks (df Size) and
+  f_bfree (and so df Used) still count every device, including the ones
+  the hints keep data off.  On a filesystem with a METADATA_ONLY device,
+  for example, Size minus Used is larger than Avail by about that
+  device's unallocated space.
 - A type change recomputes the estimate.
 
 PREFERRED_NONE devices still count: the allocator uses them as the last
@@ -431,7 +437,7 @@ index 34ef420d35ce8..30e4e217bbe64 100644
        BUG_ON(ndevs > ctl->ndevs);
        ctl->ndevs = ndevs;
 diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index df5c6db129869..31538a7bf7fa6 100644
+index 181b8a4ea14b3..f8b15fc91f9ca 100644
 --- a/fs/btrfs/volumes.h
 +++ b/fs/btrfs/volumes.h
 @@ -337,6 +337,13 @@ enum btrfs_read_policy {
@@ -465,7 +471,7 @@ index df5c6db129869..31538a7bf7fa6 100644
        spinlock_t per_profile_lock;
  };
  
-@@ -947,18 +956,26 @@ const char *btrfs_bg_type_to_raid_name(u64 flags);
+@@ -926,18 +935,26 @@ const char *btrfs_bg_type_to_raid_name(u64 flags);
  int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
  bool btrfs_verify_dev_items(const struct btrfs_fs_info *fs_info);
  void btrfs_update_per_profile_avail(struct btrfs_fs_info *fs_info);
index 30d66f70cfbd16d93ab0d9f33f92636867bf40a0..cd2a8d49e4811a2422b00505a1048c819271419f 100644 (file)
@@ -82,12 +82,11 @@ members and the target are prefilled with labelled poison, mkfs -K,
 nodiscard, replace -K.  Limits: raid1 only; the remove race is timing
 dependent (one run = tens of thousands of writes, not a proof).
 
-**Patch 9 (UAPI header).**  Build-level only: `git grep CONFIG_
-misc-next/testing -- include/uapi/linux/btrfs.h include/uapi/linux/btrfs_tree.h`
-finds nothing, and the hint values live in `fs/btrfs/volumes.h` (checked
-2026-10-18).  `make headers_install` itself was not run this round; the
-original failure (a CONFIG_ symbol in a UAPI header fails the CONFIG-leak
-check) was proven on 6.18 on 2026-10-04.
+**Patch 9 (UAPI header).**  Superseded 2026-11-12: the values stay in
+the UAPI header without the guard, and `make headers_install` was run
+(see "Patch 9 rewritten" below).  Before that, 2026-10-18: no CONFIG_ in
+the UAPI headers, values in `fs/btrfs/volumes.h`; the original failure
+was proven on 6.18 on 2026-10-04.
 
 ## The fix (patch 12; promoted 2026-10-18)
 
@@ -197,6 +196,58 @@ ENOSPC, every file verifies).  No arm is blind.  Evidence: harness
 `forensics/ah1106/` (README, full-319.log, full-ctl.log, full-mn69.log).
 This closes "e2 (patch 8) negative control: not built" below.
 
+## Patch 9 rewritten, patches 10-12 reworded (2026-11-12, uh1112)
+
+Zygo 11-12: patch 9 now drops the `CONFIG_BTRFS_ALLOCATOR_HINTS` guard
+and keeps the values in `include/uapi/linux/btrfs_tree.h` (on-disk
+dev_item.type, needed by btrfs-progs, no structure change) instead of
+moving them to `fs/btrfs/volumes.h`.  Same day: patch 10 no longer
+refuses the replace source (option A: an SSD->HDD emergency replace or an
+HDD->SSD upgrade can re-hint the source; a write racing the finish may be
+lost on patch 10 alone, patch 11 closes it), patch 11's message says so,
+patch 12's message says only f_bavail changes in statfs.  The series' end
+result is unchanged except for where the values are defined: the topic
+tip tree equals the UAPI-only candidate's, and the earlier test results
+above apply to it.
+
+Oracles (all three lanes; harness forensics `uh1112`):
+- topic old tip -> new tip = exactly the moved defines: the 7 values back
+  in btrfs_tree.h without the guard (no `CONFIG_` left in the file), the
+  block gone from volumes.h; testing and zb64 moved by the same delta,
+  nothing else (content lines compared).
+- range-diff: patches 1-8 (and Cheng's, and on 6.18 Qu's three
+  backports) `=`; 9 replaced; 10 changed (code + message); 11 changed
+  (message; its tree equals the UAPI-only candidate's); 12 message only.
+- fs/btrfs objects, lane config (ALLOCATOR_HINTS=y, BTRFS_ASSERT=y, no
+  KASAN), old zb64 vs new zb64: **not byte-identical**.  Every
+  difference is a `__LINE__` constant 21 lower (ASSERT/WARN line
+  immediates in .text, line fields in `__bug_table`/.rodata): the 21
+  lines removed from volumes.h shift the inline helpers below them.  The
+  probe "new zb64 + 21 blank lines in place of the block" is
+  byte-identical to the old zb64 in every object.  So the code is the
+  same; no runtime gate.
+
+  | lane | objects | differ | line immediates -21 | data words -21 | other | padded probe |
+  |---|---|---|---|---|---|---|
+  | 6.18 | 64 | 15 | 26 | 53 | 0 | identical |
+  | misc-next | 75 | 19 | 35 | 86 | 0 | identical |
+  | 7.3 | 64 | 16 | 31 | 58 | 0 | identical |
+
+Build checks (bhive, vm-scripts `uh1112/run-uh1112.sh`):
+- per-commit `topic-buildcheck.sh` with `ENABLE_SYMS=BTRFS_ALLOCATOR_HINTS`
+  (=y from the Kconfig commit on) and again with the feature off: 6.18
+  17/17, misc-next 14/14, 7.3 14/14 (lane base included), 0 failures, 0
+  new warnings, tip vmlinux links rc 0, both modes.
+- `make headers_install` at the topic tip, HINTS=y and =n: rc 0 on all
+  lanes, the installed `linux/btrfs_tree.h` has the 7 defines and no
+  `CONFIG_`.  Control, the series before patch 9 (KeinNiemand's commit):
+  rc 2, `error: include/uapi/linux/btrfs_tree.h: leak
+  CONFIG_BTRFS_ALLOCATOR_HINTS to user-space`.
+- Not run: runtime tests (the code is unchanged, see the object
+  comparison).  Patch 10 alone (source writable, transaction store) is
+  only build-checked; its finish race is closed by patch 11 and was not
+  exercised.
+
 ## Not covered / open
 
 - **KERNEL BUG (found 2026-10-18): space estimates ignore the hints.**  See
@@ -235,7 +286,7 @@ This closes "e2 (patch 8) negative control: not built" below.
   `alloc-hints-space-test.sh` reproduces what is very likely the same
   defect.
 - e2 (patch 8) negative control: done 2026-11-06 (ah1106, above).
-- `make headers_install` on the series (patch 9): not run this round.
+- `make headers_install` on the series (patch 9): done 2026-11-12, above.
 - Striped profiles (raid0/10/5/6) and stripe_alloc data under hints: not
   tested.