fix dynamic engine build
[fio.git] / zbd.h
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 "io_u.h"
11 #include "ioengines.h"
12 #include "oslib/blkzoned.h"
13 #include "zbd_types.h"
14
15 struct fio_file;
16
17 enum io_u_action {
18         io_u_accept     = 0,
19         io_u_eof        = 1,
20 };
21
22 /**
23  * struct fio_zone_info - information about a single ZBD zone
24  * @start: zone start location (bytes)
25  * @wp: zone write pointer location (bytes)
26  * @capacity: maximum size usable from the start of a zone (bytes)
27  * @verify_block: number of blocks that have been verified for this zone
28  * @mutex: protects the modifiable members in this structure
29  * @type: zone type (BLK_ZONE_TYPE_*)
30  * @cond: zone state (BLK_ZONE_COND_*)
31  * @open: whether or not this zone is currently open. Only relevant if
32  *              max_open_zones > 0.
33  * @reset_zone: whether or not this zone should be reset before writing to it
34  */
35 struct fio_zone_info {
36         pthread_mutex_t         mutex;
37         uint64_t                start;
38         uint64_t                wp;
39         uint64_t                capacity;
40         uint32_t                verify_block;
41         enum zbd_zone_type      type:2;
42         enum zbd_zone_cond      cond:4;
43         unsigned int            open:1;
44         unsigned int            reset_zone:1;
45 };
46
47 /**
48  * zoned_block_device_info - zoned block device characteristics
49  * @model: Device model.
50  * @max_open_zones: global limit on the number of simultaneously opened
51  *      sequential write zones.
52  * @mutex: Protects the modifiable members in this structure (refcount and
53  *              num_open_zones).
54  * @zone_size: size of a single zone in bytes.
55  * @sectors_with_data: total size of data in all zones in units of 512 bytes
56  * @zone_size_log2: log2 of the zone size in bytes if it is a power of 2 or 0
57  *              if the zone size is not a power of 2.
58  * @nr_zones: number of zones
59  * @refcount: number of fio files that share this structure
60  * @num_open_zones: number of open zones
61  * @write_cnt: Number of writes since the latest zone reset triggered by
62  *             the zone_reset_frequency fio job parameter.
63  * @open_zones: zone numbers of open zones
64  * @zone_info: description of the individual zones
65  *
66  * Only devices for which all zones have the same size are supported.
67  * Note: if the capacity is not a multiple of the zone size then the last zone
68  * will be smaller than 'zone_size'.
69  */
70 struct zoned_block_device_info {
71         enum zbd_zoned_model    model;
72         uint32_t                max_open_zones;
73         pthread_mutex_t         mutex;
74         uint64_t                zone_size;
75         uint64_t                sectors_with_data;
76         uint32_t                zone_size_log2;
77         uint32_t                nr_zones;
78         uint32_t                refcount;
79         uint32_t                num_open_zones;
80         uint32_t                write_cnt;
81         uint32_t                open_zones[ZBD_MAX_OPEN_ZONES];
82         struct fio_zone_info    zone_info[0];
83 };
84
85 int zbd_setup_files(struct thread_data *td);
86 void zbd_free_zone_info(struct fio_file *f);
87 void zbd_file_reset(struct thread_data *td, struct fio_file *f);
88 bool zbd_unaligned_write(int error_code);
89 void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u);
90 enum fio_ddir zbd_adjust_ddir(struct thread_data *td, struct io_u *io_u,
91                               enum fio_ddir ddir);
92 enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u);
93 char *zbd_write_status(const struct thread_stat *ts);
94
95 static inline void zbd_close_file(struct fio_file *f)
96 {
97         if (f->zbd_info)
98                 zbd_free_zone_info(f);
99 }
100
101 static inline void zbd_queue_io_u(struct thread_data *td, struct io_u *io_u,
102                                   enum fio_q_status status)
103 {
104         if (io_u->zbd_queue_io) {
105                 io_u->zbd_queue_io(td, io_u, status, io_u->error == 0);
106                 io_u->zbd_queue_io = NULL;
107         }
108 }
109
110 static inline void zbd_put_io_u(struct thread_data *td, struct io_u *io_u)
111 {
112         if (io_u->zbd_put_io) {
113                 io_u->zbd_put_io(td, io_u);
114                 io_u->zbd_queue_io = NULL;
115                 io_u->zbd_put_io = NULL;
116         }
117 }
118
119 #endif /* FIO_ZBD_H */