Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / fs / btrfs / zoned.h
blob8abe2f83272b56f0a5b40a78f2a1478d996357f9
1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef BTRFS_ZONED_H
4 #define BTRFS_ZONED_H
6 #include <linux/types.h>
7 #include <linux/blkdev.h>
8 #include "volumes.h"
9 #include "disk-io.h"
11 struct btrfs_zoned_device_info {
13 * Number of zones, zone size and types of zones if bdev is a
14 * zoned block device.
16 u64 zone_size;
17 u8 zone_size_shift;
18 u64 max_zone_append_size;
19 u32 nr_zones;
20 unsigned long *seq_zones;
21 unsigned long *empty_zones;
22 struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX];
25 #ifdef CONFIG_BLK_DEV_ZONED
26 int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
27 struct blk_zone *zone);
28 int btrfs_get_dev_zone_info(struct btrfs_device *device);
29 void btrfs_destroy_dev_zone_info(struct btrfs_device *device);
30 int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
31 int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info);
32 int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw,
33 u64 *bytenr_ret);
34 int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw,
35 u64 *bytenr_ret);
36 void btrfs_advance_sb_log(struct btrfs_device *device, int mirror);
37 int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror);
38 #else /* CONFIG_BLK_DEV_ZONED */
39 static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
40 struct blk_zone *zone)
42 return 0;
45 static inline int btrfs_get_dev_zone_info(struct btrfs_device *device)
47 return 0;
50 static inline void btrfs_destroy_dev_zone_info(struct btrfs_device *device) { }
52 static inline int btrfs_check_zoned_mode(const struct btrfs_fs_info *fs_info)
54 if (!btrfs_is_zoned(fs_info))
55 return 0;
57 btrfs_err(fs_info, "zoned block devices support is not enabled");
58 return -EOPNOTSUPP;
61 static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
63 return 0;
66 static inline int btrfs_sb_log_location_bdev(struct block_device *bdev,
67 int mirror, int rw, u64 *bytenr_ret)
69 *bytenr_ret = btrfs_sb_offset(mirror);
70 return 0;
73 static inline int btrfs_sb_log_location(struct btrfs_device *device, int mirror,
74 int rw, u64 *bytenr_ret)
76 *bytenr_ret = btrfs_sb_offset(mirror);
77 return 0;
80 static inline void btrfs_advance_sb_log(struct btrfs_device *device, int mirror)
81 { }
83 static inline int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror)
85 return 0;
88 #endif
90 static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)
92 struct btrfs_zoned_device_info *zone_info = device->zone_info;
94 if (!zone_info)
95 return false;
97 return test_bit(pos >> zone_info->zone_size_shift, zone_info->seq_zones);
100 static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos)
102 struct btrfs_zoned_device_info *zone_info = device->zone_info;
104 if (!zone_info)
105 return true;
107 return test_bit(pos >> zone_info->zone_size_shift, zone_info->empty_zones);
110 static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device,
111 u64 pos, bool set)
113 struct btrfs_zoned_device_info *zone_info = device->zone_info;
114 unsigned int zno;
116 if (!zone_info)
117 return;
119 zno = pos >> zone_info->zone_size_shift;
120 if (set)
121 set_bit(zno, zone_info->empty_zones);
122 else
123 clear_bit(zno, zone_info->empty_zones);
126 static inline void btrfs_dev_set_zone_empty(struct btrfs_device *device, u64 pos)
128 btrfs_dev_set_empty_zone_bit(device, pos, true);
131 static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 pos)
133 btrfs_dev_set_empty_zone_bit(device, pos, false);
136 static inline bool btrfs_check_device_zone_type(const struct btrfs_fs_info *fs_info,
137 struct block_device *bdev)
139 u64 zone_size;
141 if (btrfs_is_zoned(fs_info)) {
142 zone_size = bdev_zone_sectors(bdev) << SECTOR_SHIFT;
143 /* Do not allow non-zoned device */
144 return bdev_is_zoned(bdev) && fs_info->zone_size == zone_size;
147 /* Do not allow Host Manged zoned device */
148 return bdev_zoned_model(bdev) != BLK_ZONED_HM;
151 static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 pos)
154 * On a non-zoned device, any address is OK. On a zoned device,
155 * non-SEQUENTIAL WRITE REQUIRED zones are capable.
157 return device->zone_info == NULL || !btrfs_dev_is_sequential(device, pos);
160 #endif