Skip to content

Commit

Permalink
btrfs: add allocator_hint to disable allocation completely
Browse files Browse the repository at this point in the history
This is useful where you want to prevent new allocations of chunks to
a set of multiple disks which are going to be removed from the pool.
This acts as a multiple `btrfs dev remove` on steroids that can remove
multiple disks in parallel without moving data to disks which would be
removed in the next round. In such cases, it will avoid moving the
same data multiple times, and thus avoid placing it on potentially bad
disks.

Thanks to @Zygo for the explanation and suggestion.

Link: kdave/btrfs-progs#907 (comment)
Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed Dec 6, 2024
1 parent 1c1f2e2 commit 82553ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags
BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT)

static const char alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
[BTRFS_DEV_ALLOCATION_NONE_ONLY] = -99,
[BTRFS_DEV_ALLOCATION_DATA_ONLY] = -1,
[BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0,
[BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 1,
Expand Down Expand Up @@ -5271,6 +5272,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
*/
if (hint == BTRFS_DEV_ALLOCATION_METADATA_ONLY)
continue;
/*
* skip BTRFS_DEV_NONE_ONLY disks
*/
if (hint == BTRFS_DEV_ALLOCATION_NONE_ONLY)
continue;
/*
* if a data chunk must be allocated,
* sort also by hint (data disk
Expand All @@ -5285,6 +5291,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
*/
if (hint == BTRFS_DEV_ALLOCATION_DATA_ONLY)
continue;
/*
* skip BTRFS_DEV_NONE_ONLY disks
*/
if (hint == BTRFS_DEV_ALLOCATION_NONE_ONLY)
continue;
/*
* if a data chunk must be allocated,
* sort also by hint (metadata hint
Expand Down
4 changes: 3 additions & 1 deletion include/uapi/linux/btrfs_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,9 @@ struct btrfs_node {
#define BTRFS_DEV_ALLOCATION_DATA_ONLY (3ULL)
/* preferred no chunk, but chunks allowed */
#define BTRFS_DEV_ALLOCATION_PREFERRED_NONE (4ULL)
/* 5..7 are unused values */
/* no chunks allowed */
#define BTRFS_DEV_ALLOCATION_NONE_ONLY (5ULL)
/* 6..7 are unused values */

struct btrfs_dev_item {
/* the internal btrfs device id */
Expand Down

0 comments on commit 82553ef

Please sign in to comment.