mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-23 12:43:55 +08:00
1cd6121f2a
Implement a zoned chunk and device extent allocator. One device zone becomes a device extent so that a zone reset affects only this device extent and does not change the state of blocks in the neighbor device extents. To implement the allocator, we need to extend the following functions for a zoned filesystem. - init_alloc_chunk_ctl - dev_extent_search_start - dev_extent_hole_check - decide_stripe_size init_alloc_chunk_ctl_zoned() is mostly the same as regular one. It always set the stripe_size to the zone size and aligns the parameters to the zone size. dev_extent_search_start() only aligns the start offset to zone boundaries. We don't care about the first 1MB like in regular filesystem because we anyway reserve the first two zones for superblock logging. dev_extent_hole_check_zoned() checks if zones in given hole are either conventional or empty sequential zones. Also, it skips zones reserved for superblock logging. With the change to the hole, the new hole may now contain pending extents. So, in this case, loop again to check that. Finally, decide_stripe_size_zoned() should shrink the number of devices instead of stripe size because we need to honor stripe_size == zone_size. Reviewed-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
196 lines
5.1 KiB
C
196 lines
5.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef BTRFS_ZONED_H
|
|
#define BTRFS_ZONED_H
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/blkdev.h>
|
|
#include "volumes.h"
|
|
#include "disk-io.h"
|
|
|
|
struct btrfs_zoned_device_info {
|
|
/*
|
|
* Number of zones, zone size and types of zones if bdev is a
|
|
* zoned block device.
|
|
*/
|
|
u64 zone_size;
|
|
u8 zone_size_shift;
|
|
u64 max_zone_append_size;
|
|
u32 nr_zones;
|
|
unsigned long *seq_zones;
|
|
unsigned long *empty_zones;
|
|
struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX];
|
|
};
|
|
|
|
#ifdef CONFIG_BLK_DEV_ZONED
|
|
int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
|
|
struct blk_zone *zone);
|
|
int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info);
|
|
int btrfs_get_dev_zone_info(struct btrfs_device *device);
|
|
void btrfs_destroy_dev_zone_info(struct btrfs_device *device);
|
|
int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
|
|
int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info);
|
|
int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw,
|
|
u64 *bytenr_ret);
|
|
int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw,
|
|
u64 *bytenr_ret);
|
|
void btrfs_advance_sb_log(struct btrfs_device *device, int mirror);
|
|
int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror);
|
|
u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start,
|
|
u64 hole_end, u64 num_bytes);
|
|
int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical,
|
|
u64 length, u64 *bytes);
|
|
int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size);
|
|
#else /* CONFIG_BLK_DEV_ZONED */
|
|
static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
|
|
struct blk_zone *zone)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int btrfs_get_dev_zone_info(struct btrfs_device *device)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void btrfs_destroy_dev_zone_info(struct btrfs_device *device) { }
|
|
|
|
static inline int btrfs_check_zoned_mode(const struct btrfs_fs_info *fs_info)
|
|
{
|
|
if (!btrfs_is_zoned(fs_info))
|
|
return 0;
|
|
|
|
btrfs_err(fs_info, "zoned block devices support is not enabled");
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int btrfs_sb_log_location_bdev(struct block_device *bdev,
|
|
int mirror, int rw, u64 *bytenr_ret)
|
|
{
|
|
*bytenr_ret = btrfs_sb_offset(mirror);
|
|
return 0;
|
|
}
|
|
|
|
static inline int btrfs_sb_log_location(struct btrfs_device *device, int mirror,
|
|
int rw, u64 *bytenr_ret)
|
|
{
|
|
*bytenr_ret = btrfs_sb_offset(mirror);
|
|
return 0;
|
|
}
|
|
|
|
static inline void btrfs_advance_sb_log(struct btrfs_device *device, int mirror)
|
|
{ }
|
|
|
|
static inline int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline u64 btrfs_find_allocatable_zones(struct btrfs_device *device,
|
|
u64 hole_start, u64 hole_end,
|
|
u64 num_bytes)
|
|
{
|
|
return hole_start;
|
|
}
|
|
|
|
static inline int btrfs_reset_device_zone(struct btrfs_device *device,
|
|
u64 physical, u64 length, u64 *bytes)
|
|
{
|
|
*bytes = 0;
|
|
return 0;
|
|
}
|
|
|
|
static inline int btrfs_ensure_empty_zones(struct btrfs_device *device,
|
|
u64 start, u64 size)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
#endif
|
|
|
|
static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)
|
|
{
|
|
struct btrfs_zoned_device_info *zone_info = device->zone_info;
|
|
|
|
if (!zone_info)
|
|
return false;
|
|
|
|
return test_bit(pos >> zone_info->zone_size_shift, zone_info->seq_zones);
|
|
}
|
|
|
|
static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos)
|
|
{
|
|
struct btrfs_zoned_device_info *zone_info = device->zone_info;
|
|
|
|
if (!zone_info)
|
|
return true;
|
|
|
|
return test_bit(pos >> zone_info->zone_size_shift, zone_info->empty_zones);
|
|
}
|
|
|
|
static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device,
|
|
u64 pos, bool set)
|
|
{
|
|
struct btrfs_zoned_device_info *zone_info = device->zone_info;
|
|
unsigned int zno;
|
|
|
|
if (!zone_info)
|
|
return;
|
|
|
|
zno = pos >> zone_info->zone_size_shift;
|
|
if (set)
|
|
set_bit(zno, zone_info->empty_zones);
|
|
else
|
|
clear_bit(zno, zone_info->empty_zones);
|
|
}
|
|
|
|
static inline void btrfs_dev_set_zone_empty(struct btrfs_device *device, u64 pos)
|
|
{
|
|
btrfs_dev_set_empty_zone_bit(device, pos, true);
|
|
}
|
|
|
|
static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 pos)
|
|
{
|
|
btrfs_dev_set_empty_zone_bit(device, pos, false);
|
|
}
|
|
|
|
static inline bool btrfs_check_device_zone_type(const struct btrfs_fs_info *fs_info,
|
|
struct block_device *bdev)
|
|
{
|
|
if (btrfs_is_zoned(fs_info)) {
|
|
/*
|
|
* We can allow a regular device on a zoned filesystem, because
|
|
* we will emulate the zoned capabilities.
|
|
*/
|
|
if (!bdev_is_zoned(bdev))
|
|
return true;
|
|
|
|
return fs_info->zone_size ==
|
|
(bdev_zone_sectors(bdev) << SECTOR_SHIFT);
|
|
}
|
|
|
|
/* Do not allow Host Manged zoned device */
|
|
return bdev_zoned_model(bdev) != BLK_ZONED_HM;
|
|
}
|
|
|
|
static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 pos)
|
|
{
|
|
/*
|
|
* On a non-zoned device, any address is OK. On a zoned device,
|
|
* non-SEQUENTIAL WRITE REQUIRED zones are capable.
|
|
*/
|
|
return device->zone_info == NULL || !btrfs_dev_is_sequential(device, pos);
|
|
}
|
|
|
|
#endif
|