]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/block/null_blk.h
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[mirror_ubuntu-hirsute-kernel.git] / drivers / block / null_blk.h
CommitLineData
6dad38d3
MB
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __BLK_NULL_BLK_H
3#define __BLK_NULL_BLK_H
4
9c7eddf1
AA
5#undef pr_fmt
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7
6dad38d3
MB
8#include <linux/blkdev.h>
9#include <linux/slab.h>
10#include <linux/blk-mq.h>
11#include <linux/hrtimer.h>
12#include <linux/configfs.h>
13#include <linux/badblocks.h>
14#include <linux/fault-inject.h>
15
16struct nullb_cmd {
6dad38d3
MB
17 struct request *rq;
18 struct bio *bio;
19 unsigned int tag;
20 blk_status_t error;
21 struct nullb_queue *nq;
22 struct hrtimer timer;
23};
24
25struct nullb_queue {
26 unsigned long *tag_map;
27 wait_queue_head_t wait;
28 unsigned int queue_depth;
29 struct nullb_device *dev;
30 unsigned int requeue_selection;
31
32 struct nullb_cmd *cmds;
33};
34
35struct nullb_device {
36 struct nullb *nullb;
37 struct config_item item;
38 struct radix_tree_root data; /* data stored in the disk */
39 struct radix_tree_root cache; /* disk cache data */
40 unsigned long flags; /* device flags */
41 unsigned int curr_cache;
42 struct badblocks badblocks;
43
ca4b2a01 44 unsigned int nr_zones;
dc4d137e
NC
45 unsigned int nr_zones_imp_open;
46 unsigned int nr_zones_exp_open;
47 unsigned int nr_zones_closed;
ca4b2a01
MB
48 struct blk_zone *zones;
49 sector_t zone_size_sects;
e1777d09 50 spinlock_t zone_lock;
aa1c09cb 51 unsigned long *zone_locks;
ca4b2a01 52
6dad38d3
MB
53 unsigned long size; /* device size in MB */
54 unsigned long completion_nsec; /* time in ns to complete a request */
55 unsigned long cache_size; /* disk cache size in MB */
ca4b2a01 56 unsigned long zone_size; /* zone size in MB if device is zoned */
089565fb 57 unsigned long zone_capacity; /* zone capacity in MB if device is zoned */
ea2c18e1 58 unsigned int zone_nr_conv; /* number of conventional zones */
dc4d137e
NC
59 unsigned int zone_max_open; /* max number of open zones */
60 unsigned int zone_max_active; /* max number of active zones */
6dad38d3
MB
61 unsigned int submit_queues; /* number of submission queues */
62 unsigned int home_node; /* home node for the device */
63 unsigned int queue_mode; /* block interface */
64 unsigned int blocksize; /* block size */
65 unsigned int irqmode; /* IRQ completion handler */
66 unsigned int hw_queue_depth; /* queue depth */
67 unsigned int index; /* index of the disk, only valid with a disk */
68 unsigned int mbps; /* Bandwidth throttle cap (in MB/s) */
69 bool blocking; /* blocking blk-mq device */
70 bool use_per_node_hctx; /* use per-node allocation for hardware context */
71 bool power; /* power on/off the device */
72 bool memory_backed; /* if data is stored in memory */
73 bool discard; /* if support discard */
ca4b2a01 74 bool zoned; /* if device is zoned */
6dad38d3
MB
75};
76
77struct nullb {
78 struct nullb_device *dev;
79 struct list_head list;
80 unsigned int index;
81 struct request_queue *q;
82 struct gendisk *disk;
83 struct blk_mq_tag_set *tag_set;
84 struct blk_mq_tag_set __tag_set;
85 unsigned int queue_depth;
86 atomic_long_t cur_bytes;
87 struct hrtimer bw_timer;
88 unsigned long cache_flush_pos;
89 spinlock_t lock;
90
91 struct nullb_queue *queues;
92 unsigned int nr_queues;
93 char disk_name[DISK_NAME_LEN];
94};
ca4b2a01 95
9dd44c7e
DLM
96blk_status_t null_process_cmd(struct nullb_cmd *cmd,
97 enum req_opf op, sector_t sector,
98 unsigned int nr_sectors);
99
ca4b2a01 100#ifdef CONFIG_BLK_DEV_ZONED
d205bde7
DLM
101int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q);
102int null_register_zoned_dev(struct nullb *nullb);
103void null_free_zoned_dev(struct nullb_device *dev);
7fc8fb51 104int null_report_zones(struct gendisk *disk, sector_t sector,
d4100351 105 unsigned int nr_zones, report_zones_cb cb, void *data);
9dd44c7e
DLM
106blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
107 enum req_opf op, sector_t sector,
108 sector_t nr_sectors);
dd85b492
AJ
109size_t null_zone_valid_read_len(struct nullb *nullb,
110 sector_t sector, unsigned int len);
ca4b2a01 111#else
d205bde7
DLM
112static inline int null_init_zoned_dev(struct nullb_device *dev,
113 struct request_queue *q)
ca4b2a01 114{
9c7eddf1 115 pr_err("CONFIG_BLK_DEV_ZONED not enabled\n");
ca4b2a01
MB
116 return -EINVAL;
117}
d205bde7
DLM
118static inline int null_register_zoned_dev(struct nullb *nullb)
119{
120 return -ENODEV;
121}
122static inline void null_free_zoned_dev(struct nullb_device *dev) {}
9dd44c7e
DLM
123static inline blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
124 enum req_opf op, sector_t sector, sector_t nr_sectors)
b228ba1c 125{
fceb5d1b 126 return BLK_STS_NOTSUPP;
b228ba1c 127}
dd85b492
AJ
128static inline size_t null_zone_valid_read_len(struct nullb *nullb,
129 sector_t sector,
130 unsigned int len)
131{
132 return len;
133}
7fc8fb51 134#define null_report_zones NULL
ca4b2a01 135#endif /* CONFIG_BLK_DEV_ZONED */
6dad38d3 136#endif /* __NULL_BLK_H */