Skip to content

Commit

Permalink
btrfs: add allocator_hint for no allocation preferred
Browse files Browse the repository at this point in the history
This is useful where you want to prevent new allocations of chunks on a
disk which is going to removed from the pool anyways, e.g. due to bad
blocks or because it's slow.

Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed Sep 9, 2024
1 parent 0e46a86 commit 186029a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ static const char alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
[BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0,
[BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 1,
[BTRFS_DEV_ALLOCATION_METADATA_ONLY] = 2,
[BTRFS_DEV_ALLOCATION_PREFERRED_NONE] = 99,
/* the other values are set to 0 */
};

Expand Down Expand Up @@ -5320,7 +5321,10 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
* sort also by hint (metadata hint
* higher priority)
*/
devices_info[ndevs].alloc_hint = alloc_hint_map[hint];
if (hint == BTRFS_DEV_ALLOCATION_PREFERRED_NONE)
devices_info[ndevs].alloc_hint = -alloc_hint_map[hint];
else
devices_info[ndevs].alloc_hint = alloc_hint_map[hint];
}

++ndevs;
Expand Down
2 changes: 2 additions & 0 deletions include/uapi/linux/btrfs_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ struct btrfs_node {
#define BTRFS_DEV_ALLOCATION_METADATA_ONLY (2ULL)
/* only data chunk allowed */
#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 */

struct btrfs_dev_item {
Expand Down

0 comments on commit 186029a

Please sign in to comment.