]> git.hungrycats.org Git - linux/commitdiff
btrfs: add flags to give a hint to the chunk allocator
authorKai Krakow <kai@kaishome.de>
Fri, 10 Jul 2026 22:51:17 +0000 (00:51 +0200)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 2 Nov 2026 02:17:16 +0000 (21:17 -0500)
Add the following flags to give a hint about which chunk should be
allocated on which a disk.

The following flags are created:

- BTRFS_DEV_ALLOCATION_PREFERRED_DATA
  preferred data chunk, but metadata chunk allowed
- BTRFS_DEV_ALLOCATION_PREFERRED_METADATA
  preferred metadata chunk, but data chunk allowed
- BTRFS_DEV_ALLOCATION_METADATA_ONLY
  only metadata chunk allowed
- BTRFS_DEV_ALLOCATION_DATA_ONLY
  only data chunk allowed

Co-authored-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: Kai Krakow <kai@kaishome.de>
include/uapi/linux/btrfs_tree.h

index 47ee52859b4589567683785edbfcaec8b24b7af1..a8da0a23b70a2e991e8c1181840ef39ba9c21929 100644 (file)
@@ -585,6 +585,27 @@ 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)
+/* 5..7 are unused values */
+
+#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
+
 struct btrfs_dev_item {
        /* the internal btrfs device id */
        __le64 devid;