Commit | Line | Data |
---|---|---|
bfbdd35b BVA |
1 | /* |
2 | * Copyright (C) 2018 Western Digital Corporation or its affiliates. | |
3 | * | |
4 | * This file is released under the GPL. | |
5 | */ | |
6 | ||
7 | #ifndef FIO_ZBD_H | |
8 | #define FIO_ZBD_H | |
9 | ||
10 | #include <inttypes.h> | |
59b07544 | 11 | #include "fio.h" /* FIO_MAX_OPEN_ZBD_ZONES */ |
bfbdd35b BVA |
12 | #ifdef CONFIG_LINUX_BLKZONED |
13 | #include <linux/blkzoned.h> | |
14 | #endif | |
15 | ||
16 | struct fio_file; | |
17 | ||
18 | /* | |
19 | * Zoned block device models. | |
20 | */ | |
21 | enum blk_zoned_model { | |
22 | ZBD_DM_NONE, /* Regular block device */ | |
23 | ZBD_DM_HOST_AWARE, /* Host-aware zoned block device */ | |
24 | ZBD_DM_HOST_MANAGED, /* Host-managed zoned block device */ | |
25 | }; | |
26 | ||
27 | enum io_u_action { | |
28 | io_u_accept = 0, | |
29 | io_u_eof = 1, | |
30 | }; | |
31 | ||
32 | /** | |
33 | * struct fio_zone_info - information about a single ZBD zone | |
2c477f4f DLM |
34 | * @start: zone start location (bytes) |
35 | * @wp: zone write pointer location (bytes) | |
bfbdd35b BVA |
36 | * @verify_block: number of blocks that have been verified for this zone |
37 | * @mutex: protects the modifiable members in this structure | |
38 | * @type: zone type (BLK_ZONE_TYPE_*) | |
39 | * @cond: zone state (BLK_ZONE_COND_*) | |
40 | * @open: whether or not this zone is currently open. Only relevant if | |
41 | * max_open_zones > 0. | |
42 | * @reset_zone: whether or not this zone should be reset before writing to it | |
43 | */ | |
44 | struct fio_zone_info { | |
45 | #ifdef CONFIG_LINUX_BLKZONED | |
46 | pthread_mutex_t mutex; | |
47 | uint64_t start; | |
48 | uint64_t wp; | |
49 | uint32_t verify_block; | |
50 | enum blk_zone_type type:2; | |
51 | enum blk_zone_cond cond:4; | |
52 | unsigned int open:1; | |
53 | unsigned int reset_zone:1; | |
54 | #endif | |
55 | }; | |
56 | ||
57 | /** | |
58 | * zoned_block_device_info - zoned block device characteristics | |
59 | * @model: Device model. | |
59b07544 BVA |
60 | * @mutex: Protects the modifiable members in this structure (refcount and |
61 | * num_open_zones). | |
bfbdd35b | 62 | * @zone_size: size of a single zone in units of 512 bytes |
a7c2b6fc | 63 | * @sectors_with_data: total size of data in all zones in units of 512 bytes |
bfbdd35b BVA |
64 | * @zone_size_log2: log2 of the zone size in bytes if it is a power of 2 or 0 |
65 | * if the zone size is not a power of 2. | |
66 | * @nr_zones: number of zones | |
67 | * @refcount: number of fio files that share this structure | |
59b07544 | 68 | * @num_open_zones: number of open zones |
a7c2b6fc BVA |
69 | * @write_cnt: Number of writes since the latest zone reset triggered by |
70 | * the zone_reset_frequency fio job parameter. | |
59b07544 | 71 | * @open_zones: zone numbers of open zones |
bfbdd35b BVA |
72 | * @zone_info: description of the individual zones |
73 | * | |
74 | * Only devices for which all zones have the same size are supported. | |
75 | * Note: if the capacity is not a multiple of the zone size then the last zone | |
76 | * will be smaller than 'zone_size'. | |
77 | */ | |
78 | struct zoned_block_device_info { | |
79 | enum blk_zoned_model model; | |
80 | pthread_mutex_t mutex; | |
81 | uint64_t zone_size; | |
a7c2b6fc | 82 | uint64_t sectors_with_data; |
bfbdd35b BVA |
83 | uint32_t zone_size_log2; |
84 | uint32_t nr_zones; | |
85 | uint32_t refcount; | |
59b07544 | 86 | uint32_t num_open_zones; |
a7c2b6fc | 87 | uint32_t write_cnt; |
59b07544 | 88 | uint32_t open_zones[FIO_MAX_OPEN_ZBD_ZONES]; |
bfbdd35b BVA |
89 | struct fio_zone_info zone_info[0]; |
90 | }; | |
91 | ||
92 | #ifdef CONFIG_LINUX_BLKZONED | |
93 | void zbd_free_zone_info(struct fio_file *f); | |
94 | int zbd_init(struct thread_data *td); | |
95 | void zbd_file_reset(struct thread_data *td, struct fio_file *f); | |
96 | bool zbd_unaligned_write(int error_code); | |
4d37720a | 97 | void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u); |
bfbdd35b | 98 | enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u); |
fd5d733f | 99 | char *zbd_write_status(const struct thread_stat *ts); |
d9ed3e63 DLM |
100 | |
101 | static inline void zbd_queue_io_u(struct io_u *io_u, enum fio_q_status status) | |
102 | { | |
103 | if (io_u->zbd_queue_io) { | |
104 | io_u->zbd_queue_io(io_u, status, io_u->error == 0); | |
105 | io_u->zbd_queue_io = NULL; | |
106 | } | |
107 | } | |
108 | ||
109 | static inline void zbd_put_io_u(struct io_u *io_u) | |
110 | { | |
111 | if (io_u->zbd_put_io) { | |
112 | io_u->zbd_put_io(io_u); | |
113 | io_u->zbd_queue_io = NULL; | |
114 | io_u->zbd_put_io = NULL; | |
115 | } | |
116 | } | |
117 | ||
bfbdd35b BVA |
118 | #else |
119 | static inline void zbd_free_zone_info(struct fio_file *f) | |
120 | { | |
121 | } | |
122 | ||
123 | static inline int zbd_init(struct thread_data *td) | |
124 | { | |
125 | return 0; | |
126 | } | |
127 | ||
128 | static inline void zbd_file_reset(struct thread_data *td, struct fio_file *f) | |
129 | { | |
130 | } | |
131 | ||
132 | static inline bool zbd_unaligned_write(int error_code) | |
133 | { | |
134 | return false; | |
135 | } | |
136 | ||
137 | static inline enum io_u_action zbd_adjust_block(struct thread_data *td, | |
138 | struct io_u *io_u) | |
139 | { | |
140 | return io_u_accept; | |
141 | } | |
142 | ||
fd5d733f BVA |
143 | static inline char *zbd_write_status(const struct thread_stat *ts) |
144 | { | |
145 | return NULL; | |
146 | } | |
d9ed3e63 DLM |
147 | |
148 | static inline void zbd_queue_io_u(struct io_u *io_u, | |
149 | enum fio_q_status status) {} | |
150 | static inline void zbd_put_io_u(struct io_u *io_u) {} | |
c012becd JA |
151 | |
152 | static inline void setup_zbd_zone_mode(struct thread_data *td, | |
153 | struct io_u *io_u) | |
154 | { | |
155 | } | |
156 | ||
bfbdd35b BVA |
157 | #endif |
158 | ||
159 | #endif /* FIO_ZBD_H */ |