]> Git Repo - linux.git/blame - fs/btrfs/zoned.h
Merge tag 'nfsd-5.12-2' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
[linux.git] / fs / btrfs / zoned.h
CommitLineData
5b316468
NA
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef BTRFS_ZONED_H
4#define BTRFS_ZONED_H
5
6#include <linux/types.h>
b70f5097 7#include <linux/blkdev.h>
12659251
NA
8#include "volumes.h"
9#include "disk-io.h"
40ab3be1 10#include "block-group.h"
5b316468
NA
11
12struct btrfs_zoned_device_info {
13 /*
14 * Number of zones, zone size and types of zones if bdev is a
15 * zoned block device.
16 */
17 u64 zone_size;
18 u8 zone_size_shift;
862931c7 19 u64 max_zone_append_size;
5b316468
NA
20 u32 nr_zones;
21 unsigned long *seq_zones;
22 unsigned long *empty_zones;
12659251 23 struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX];
5b316468
NA
24};
25
26#ifdef CONFIG_BLK_DEV_ZONED
27int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
28 struct blk_zone *zone);
73651042 29int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info);
5b316468
NA
30int btrfs_get_dev_zone_info(struct btrfs_device *device);
31void btrfs_destroy_dev_zone_info(struct btrfs_device *device);
b70f5097 32int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
5d1ab66c 33int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info);
12659251
NA
34int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw,
35 u64 *bytenr_ret);
36int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw,
37 u64 *bytenr_ret);
38void btrfs_advance_sb_log(struct btrfs_device *device, int mirror);
39int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror);
1cd6121f
NA
40u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start,
41 u64 hole_end, u64 num_bytes);
42int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical,
43 u64 length, u64 *bytes);
44int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size);
a94794d5 45int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new);
169e0da9 46void btrfs_calc_zone_unusable(struct btrfs_block_group *cache);
d3575156
NA
47void btrfs_redirty_list_add(struct btrfs_transaction *trans,
48 struct extent_buffer *eb);
49void btrfs_free_redirty_list(struct btrfs_transaction *trans);
08f45559 50bool btrfs_use_zone_append(struct btrfs_inode *inode, struct extent_map *em);
d8e3fb10
NA
51void btrfs_record_physical_zoned(struct inode *inode, u64 file_offset,
52 struct bio *bio);
53void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered);
0bc09ca1
NA
54bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info,
55 struct extent_buffer *eb,
56 struct btrfs_block_group **cache_ret);
57void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache,
58 struct extent_buffer *eb);
de17addc 59int btrfs_zoned_issue_zeroout(struct btrfs_device *device, u64 physical, u64 length);
7db1c5d1
NA
60int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical,
61 u64 physical_start, u64 physical_pos);
5b316468
NA
62#else /* CONFIG_BLK_DEV_ZONED */
63static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
64 struct blk_zone *zone)
65{
66 return 0;
67}
68
73651042
NA
69static inline int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info)
70{
71 return 0;
72}
73
5b316468
NA
74static inline int btrfs_get_dev_zone_info(struct btrfs_device *device)
75{
76 return 0;
77}
78
79static inline void btrfs_destroy_dev_zone_info(struct btrfs_device *device) { }
80
b70f5097
NA
81static inline int btrfs_check_zoned_mode(const struct btrfs_fs_info *fs_info)
82{
83 if (!btrfs_is_zoned(fs_info))
84 return 0;
85
86 btrfs_err(fs_info, "zoned block devices support is not enabled");
87 return -EOPNOTSUPP;
88}
89
5d1ab66c
NA
90static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
91{
92 return 0;
93}
94
12659251
NA
95static inline int btrfs_sb_log_location_bdev(struct block_device *bdev,
96 int mirror, int rw, u64 *bytenr_ret)
97{
98 *bytenr_ret = btrfs_sb_offset(mirror);
99 return 0;
100}
101
102static inline int btrfs_sb_log_location(struct btrfs_device *device, int mirror,
103 int rw, u64 *bytenr_ret)
104{
105 *bytenr_ret = btrfs_sb_offset(mirror);
106 return 0;
107}
108
109static inline void btrfs_advance_sb_log(struct btrfs_device *device, int mirror)
110{ }
111
112static inline int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror)
113{
114 return 0;
115}
116
1cd6121f
NA
117static inline u64 btrfs_find_allocatable_zones(struct btrfs_device *device,
118 u64 hole_start, u64 hole_end,
119 u64 num_bytes)
120{
121 return hole_start;
122}
123
124static inline int btrfs_reset_device_zone(struct btrfs_device *device,
125 u64 physical, u64 length, u64 *bytes)
126{
127 *bytes = 0;
128 return 0;
129}
130
131static inline int btrfs_ensure_empty_zones(struct btrfs_device *device,
132 u64 start, u64 size)
133{
134 return 0;
135}
136
08e11a3d 137static inline int btrfs_load_block_group_zone_info(
a94794d5 138 struct btrfs_block_group *cache, bool new)
08e11a3d
NA
139{
140 return 0;
141}
142
169e0da9
NA
143static inline void btrfs_calc_zone_unusable(struct btrfs_block_group *cache) { }
144
d3575156
NA
145static inline void btrfs_redirty_list_add(struct btrfs_transaction *trans,
146 struct extent_buffer *eb) { }
147static inline void btrfs_free_redirty_list(struct btrfs_transaction *trans) { }
148
08f45559
JT
149static inline bool btrfs_use_zone_append(struct btrfs_inode *inode,
150 struct extent_map *em)
151{
152 return false;
153}
d8e3fb10
NA
154
155static inline void btrfs_record_physical_zoned(struct inode *inode,
156 u64 file_offset, struct bio *bio)
157{
158}
159
160static inline void btrfs_rewrite_logical_zoned(
161 struct btrfs_ordered_extent *ordered) { }
162
0bc09ca1
NA
163static inline bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info,
164 struct extent_buffer *eb,
165 struct btrfs_block_group **cache_ret)
166{
167 return true;
168}
169
170static inline void btrfs_revert_meta_write_pointer(
171 struct btrfs_block_group *cache,
172 struct extent_buffer *eb)
173{
174}
175
de17addc
NA
176static inline int btrfs_zoned_issue_zeroout(struct btrfs_device *device,
177 u64 physical, u64 length)
178{
179 return -EOPNOTSUPP;
180}
181
7db1c5d1
NA
182static inline int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev,
183 u64 logical, u64 physical_start,
184 u64 physical_pos)
185{
186 return -EOPNOTSUPP;
187}
188
5b316468
NA
189#endif
190
191static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)
192{
193 struct btrfs_zoned_device_info *zone_info = device->zone_info;
194
195 if (!zone_info)
196 return false;
197
198 return test_bit(pos >> zone_info->zone_size_shift, zone_info->seq_zones);
199}
200
201static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos)
202{
203 struct btrfs_zoned_device_info *zone_info = device->zone_info;
204
205 if (!zone_info)
206 return true;
207
208 return test_bit(pos >> zone_info->zone_size_shift, zone_info->empty_zones);
209}
210
211static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device,
212 u64 pos, bool set)
213{
214 struct btrfs_zoned_device_info *zone_info = device->zone_info;
215 unsigned int zno;
216
217 if (!zone_info)
218 return;
219
220 zno = pos >> zone_info->zone_size_shift;
221 if (set)
222 set_bit(zno, zone_info->empty_zones);
223 else
224 clear_bit(zno, zone_info->empty_zones);
225}
226
227static inline void btrfs_dev_set_zone_empty(struct btrfs_device *device, u64 pos)
228{
229 btrfs_dev_set_empty_zone_bit(device, pos, true);
230}
231
232static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 pos)
233{
234 btrfs_dev_set_empty_zone_bit(device, pos, false);
235}
236
b70f5097
NA
237static inline bool btrfs_check_device_zone_type(const struct btrfs_fs_info *fs_info,
238 struct block_device *bdev)
239{
b70f5097 240 if (btrfs_is_zoned(fs_info)) {
3c9daa09
JT
241 /*
242 * We can allow a regular device on a zoned filesystem, because
243 * we will emulate the zoned capabilities.
244 */
245 if (!bdev_is_zoned(bdev))
246 return true;
247
248 return fs_info->zone_size ==
249 (bdev_zone_sectors(bdev) << SECTOR_SHIFT);
b70f5097
NA
250 }
251
252 /* Do not allow Host Manged zoned device */
253 return bdev_zoned_model(bdev) != BLK_ZONED_HM;
254}
255
12659251
NA
256static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 pos)
257{
258 /*
259 * On a non-zoned device, any address is OK. On a zoned device,
260 * non-SEQUENTIAL WRITE REQUIRED zones are capable.
261 */
262 return device->zone_info == NULL || !btrfs_dev_is_sequential(device, pos);
263}
264
dcba6e48
NA
265static inline bool btrfs_can_zone_reset(struct btrfs_device *device,
266 u64 physical, u64 length)
267{
268 u64 zone_size;
269
270 if (!btrfs_dev_is_sequential(device, physical))
271 return false;
272
273 zone_size = device->zone_info->zone_size;
274 if (!IS_ALIGNED(physical, zone_size) || !IS_ALIGNED(length, zone_size))
275 return false;
276
277 return true;
278}
279
0bc09ca1
NA
280static inline void btrfs_zoned_meta_io_lock(struct btrfs_fs_info *fs_info)
281{
282 if (!btrfs_is_zoned(fs_info))
283 return;
284 mutex_lock(&fs_info->zoned_meta_io_lock);
285}
286
287static inline void btrfs_zoned_meta_io_unlock(struct btrfs_fs_info *fs_info)
288{
289 if (!btrfs_is_zoned(fs_info))
290 return;
291 mutex_unlock(&fs_info->zoned_meta_io_lock);
292}
293
40ab3be1
NA
294static inline void btrfs_clear_treelog_bg(struct btrfs_block_group *bg)
295{
296 struct btrfs_fs_info *fs_info = bg->fs_info;
297
298 if (!btrfs_is_zoned(fs_info))
299 return;
300
301 spin_lock(&fs_info->treelog_bg_lock);
302 if (fs_info->treelog_bg == bg->start)
303 fs_info->treelog_bg = 0;
304 spin_unlock(&fs_info->treelog_bg_lock);
305}
306
5b316468 307#endif
This page took 0.125438 seconds and 4 git commands to generate.