Skip to content

Commit 2738442

Browse files
committed
btrfs: add allocator_hint to disable allocation completely
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 <kai@kaishome.de>
1 parent cc4d585 commit 2738442

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

fs/btrfs/volumes.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags
191191
BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT)
192192

193193
static const char alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
194+
[BTRFS_DEV_ALLOCATION_NONE_ONLY] = -99,
194195
[BTRFS_DEV_ALLOCATION_DATA_ONLY] = -1,
195196
[BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0,
196197
[BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 1,
@@ -5344,6 +5345,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
53445345
*/
53455346
if (hint == BTRFS_DEV_ALLOCATION_METADATA_ONLY)
53465347
continue;
5348+
/*
5349+
* skip BTRFS_DEV_NONE_ONLY disks
5350+
*/
5351+
if (hint == BTRFS_DEV_ALLOCATION_NONE_ONLY)
5352+
continue;
53475353
/*
53485354
* if a data chunk must be allocated,
53495355
* sort also by hint (data disk
@@ -5358,6 +5364,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
53585364
*/
53595365
if (hint == BTRFS_DEV_ALLOCATION_DATA_ONLY)
53605366
continue;
5367+
/*
5368+
* skip BTRFS_DEV_NONE_ONLY disks
5369+
*/
5370+
if (hint == BTRFS_DEV_ALLOCATION_NONE_ONLY)
5371+
continue;
53615372
/*
53625373
* if a data chunk must be allocated,
53635374
* sort also by hint (metadata hint

include/uapi/linux/btrfs_tree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,9 @@ struct btrfs_node {
593593
#define BTRFS_DEV_ALLOCATION_DATA_ONLY (3ULL)
594594
/* avoid chunk allocation if possible */
595595
#define BTRFS_DEV_ALLOCATION_PREFERRED_NONE (4ULL)
596-
/* 5..7 are unused values */
596+
/* deny chunk allocation */
597+
#define BTRFS_DEV_ALLOCATION_NONE_ONLY (5ULL)
598+
/* 6..7 are unused values */
597599

598600
#endif
599601

0 commit comments

Comments
 (0)