mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-25 13:43:55 +08:00
btrfs: use named constant for reserved device space
There's a reserved space on each device of size 1MiB that can be used by bootloaders or to avoid accidental overwrite. Use a symbolic constant with the explaining comment instead of hard coding the value and multiple comments. Note: since btrfs-progs v4.1, mkfs.btrfs will reserve the first 1MiB for the primary super block (at offset 64KiB), until then the range could have been used by mistake. Kernel has been always respecting the 1MiB range for writes. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> [ update changelog ] Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
bfceac7fd3
commit
37f85ec320
@ -229,6 +229,13 @@ struct btrfs_root_backup {
|
|||||||
#define BTRFS_SUPER_INFO_OFFSET SZ_64K
|
#define BTRFS_SUPER_INFO_OFFSET SZ_64K
|
||||||
#define BTRFS_SUPER_INFO_SIZE 4096
|
#define BTRFS_SUPER_INFO_SIZE 4096
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The reserved space at the beginning of each device.
|
||||||
|
* It covers the primary super block and leaves space for potential use by other
|
||||||
|
* tools like bootloaders or to lower potential damage of accidental overwrite.
|
||||||
|
*/
|
||||||
|
#define BTRFS_DEVICE_RANGE_RESERVED (SZ_1M)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the super block basically lists the main trees of the FS
|
* the super block basically lists the main trees of the FS
|
||||||
* it currently lacks any block count etc etc
|
* it currently lacks any block count etc etc
|
||||||
|
@ -5976,7 +5976,7 @@ int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
|
|||||||
*/
|
*/
|
||||||
static int btrfs_trim_free_extents(struct btrfs_device *device, u64 *trimmed)
|
static int btrfs_trim_free_extents(struct btrfs_device *device, u64 *trimmed)
|
||||||
{
|
{
|
||||||
u64 start = SZ_1M, len = 0, end = 0;
|
u64 start = BTRFS_DEVICE_RANGE_RESERVED, len = 0, end = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
*trimmed = 0;
|
*trimmed = 0;
|
||||||
@ -6020,8 +6020,8 @@ static int btrfs_trim_free_extents(struct btrfs_device *device, u64 *trimmed)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure we skip the reserved area in the first 1M */
|
/* Ensure we skip the reserved space on each device. */
|
||||||
start = max_t(u64, start, SZ_1M);
|
start = max_t(u64, start, BTRFS_DEVICE_RANGE_RESERVED);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If find_first_clear_extent_bit find a range that spans the
|
* If find_first_clear_extent_bit find a range that spans the
|
||||||
|
@ -2272,17 +2272,13 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
|
|||||||
avail_space = rounddown(avail_space, BTRFS_STRIPE_LEN);
|
avail_space = rounddown(avail_space, BTRFS_STRIPE_LEN);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In order to avoid overwriting the superblock on the drive,
|
* Ensure we have at least min_stripe_size on top of the
|
||||||
* btrfs starts at an offset of at least 1MB when doing chunk
|
* reserved space on the device.
|
||||||
* allocation.
|
|
||||||
*
|
|
||||||
* This ensures we have at least min_stripe_size free space
|
|
||||||
* after excluding 1MB.
|
|
||||||
*/
|
*/
|
||||||
if (avail_space <= SZ_1M + min_stripe_size)
|
if (avail_space <= BTRFS_DEVICE_RANGE_RESERVED + min_stripe_size)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
avail_space -= SZ_1M;
|
avail_space -= BTRFS_DEVICE_RANGE_RESERVED;
|
||||||
|
|
||||||
devices_info[i].dev = device;
|
devices_info[i].dev = device;
|
||||||
devices_info[i].max_avail = avail_space;
|
devices_info[i].max_avail = avail_space;
|
||||||
|
@ -1403,12 +1403,7 @@ static u64 dev_extent_search_start(struct btrfs_device *device, u64 start)
|
|||||||
{
|
{
|
||||||
switch (device->fs_devices->chunk_alloc_policy) {
|
switch (device->fs_devices->chunk_alloc_policy) {
|
||||||
case BTRFS_CHUNK_ALLOC_REGULAR:
|
case BTRFS_CHUNK_ALLOC_REGULAR:
|
||||||
/*
|
return max_t(u64, start, BTRFS_DEVICE_RANGE_RESERVED);
|
||||||
* We don't want to overwrite the superblock on the drive nor
|
|
||||||
* any area used by the boot loader (grub for example), so we
|
|
||||||
* make sure to start at an offset of at least 1MB.
|
|
||||||
*/
|
|
||||||
return max_t(u64, start, SZ_1M);
|
|
||||||
case BTRFS_CHUNK_ALLOC_ZONED:
|
case BTRFS_CHUNK_ALLOC_ZONED:
|
||||||
/*
|
/*
|
||||||
* We don't care about the starting region like regular
|
* We don't care about the starting region like regular
|
||||||
|
Loading…
Reference in New Issue
Block a user