2 * Copyright (C) 2018 Western Digital Corporation or its affiliates.
4 * This file is released under the GPL.
11 #include "ioengines.h"
12 #include "oslib/blkzoned.h"
13 #include "zbd_types.h"
24 * struct fio_zone_info - information about a single ZBD zone
25 * @start: zone start location (bytes)
26 * @wp: zone write pointer location (bytes)
27 * @capacity: maximum size usable from the start of a zone (bytes)
28 * @mutex: protects the modifiable members in this structure
29 * @type: zone type (BLK_ZONE_TYPE_*)
30 * @cond: zone state (BLK_ZONE_COND_*)
31 * @has_wp: whether or not this zone can have a valid write pointer
32 * @open: whether or not this zone is currently open. Only relevant if
34 * @reset_zone: whether or not this zone should be reset before writing to it
36 struct fio_zone_info {
37 pthread_mutex_t mutex;
41 enum zbd_zone_type type:2;
42 enum zbd_zone_cond cond:4;
43 unsigned int has_wp:1;
45 unsigned int reset_zone:1;
49 * zoned_block_device_info - zoned block device characteristics
50 * @model: Device model.
51 * @max_open_zones: global limit on the number of simultaneously opened
52 * sequential write zones. A zero value means unlimited open zones,
53 * and that open zones will not be tracked in the open_zones array.
54 * @mutex: Protects the modifiable members in this structure (refcount and
56 * @zone_size: size of a single zone in bytes.
57 * @wp_valid_data_bytes: total size of data in zones with write pointers
58 * @zone_size_log2: log2 of the zone size in bytes if it is a power of 2 or 0
59 * if the zone size is not a power of 2.
60 * @nr_zones: number of zones
61 * @refcount: number of fio files that share this structure
62 * @num_open_zones: number of open zones
63 * @write_cnt: Number of writes since the latest zone reset triggered by
64 * the zone_reset_frequency fio job parameter.
65 * @open_zones: zone numbers of open zones
66 * @zone_info: description of the individual zones
68 * Only devices for which all zones have the same size are supported.
69 * Note: if the capacity is not a multiple of the zone size then the last zone
70 * will be smaller than 'zone_size'.
72 struct zoned_block_device_info {
73 enum zbd_zoned_model model;
74 uint32_t max_open_zones;
75 pthread_mutex_t mutex;
77 uint64_t wp_valid_data_bytes;
78 uint32_t zone_size_log2;
81 uint32_t num_open_zones;
83 uint32_t open_zones[ZBD_MAX_OPEN_ZONES];
84 struct fio_zone_info zone_info[0];
87 int zbd_init_files(struct thread_data *td);
88 void zbd_recalc_options_with_zone_granularity(struct thread_data *td);
89 int zbd_setup_files(struct thread_data *td);
90 void zbd_free_zone_info(struct fio_file *f);
91 void zbd_file_reset(struct thread_data *td, struct fio_file *f);
92 bool zbd_unaligned_write(int error_code);
93 void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u);
94 enum fio_ddir zbd_adjust_ddir(struct thread_data *td, struct io_u *io_u,
96 enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u);
97 char *zbd_write_status(const struct thread_stat *ts);
98 int zbd_do_io_u_trim(const struct thread_data *td, struct io_u *io_u);
100 static inline void zbd_close_file(struct fio_file *f)
103 zbd_free_zone_info(f);
106 static inline void zbd_queue_io_u(struct thread_data *td, struct io_u *io_u,
107 enum fio_q_status status)
109 if (io_u->zbd_queue_io) {
110 io_u->zbd_queue_io(td, io_u, status, io_u->error == 0);
111 io_u->zbd_queue_io = NULL;
115 static inline void zbd_put_io_u(struct thread_data *td, struct io_u *io_u)
117 if (io_u->zbd_put_io) {
118 io_u->zbd_put_io(td, io_u);
119 io_u->zbd_queue_io = NULL;
120 io_u->zbd_put_io = NULL;
124 #endif /* FIO_ZBD_H */