1 /* SPDX-License-Identifier: GPL-2.0 */
6 #include <linux/types.h>
7 #include <linux/blkdev.h>
11 struct btrfs_zoned_device_info
{
13 * Number of zones, zone size and types of zones if bdev is a
18 u64 max_zone_append_size
;
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
,
34 int btrfs_sb_log_location(struct btrfs_device
*device
, int mirror
, int rw
,
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
)
45 static inline int btrfs_get_dev_zone_info(struct btrfs_device
*device
)
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
))
57 btrfs_err(fs_info
, "zoned block devices support is not enabled");
61 static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info
*info
)
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
);
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
);
80 static inline void btrfs_advance_sb_log(struct btrfs_device
*device
, int mirror
)
83 static inline int btrfs_reset_sb_log_zones(struct block_device
*bdev
, int mirror
)
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
;
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
;
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
,
113 struct btrfs_zoned_device_info
*zone_info
= device
->zone_info
;
119 zno
= pos
>> zone_info
->zone_size_shift
;
121 set_bit(zno
, zone_info
->empty_zones
);
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
)
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
);