Skip to content

Commit 6dad38d

Browse files
MatiasBjorlingaxboe
authored andcommitted
null_blk: move shared definitions to header file
Split the null_blk device driver, such that it can prepare for zoned block interface support. Signed-off-by: Matias Bjørling <matias.bjorling@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e9a8385 commit 6dad38d

File tree

2 files changed

+81
-75
lines changed

2 files changed

+81
-75
lines changed

drivers/block/null_blk.c

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77
#include <linux/moduleparam.h>
88
#include <linux/sched.h>
99
#include <linux/fs.h>
10-
#include <linux/blkdev.h>
1110
#include <linux/init.h>
12-
#include <linux/slab.h>
13-
#include <linux/blk-mq.h>
14-
#include <linux/hrtimer.h>
15-
#include <linux/configfs.h>
16-
#include <linux/badblocks.h>
17-
#include <linux/fault-inject.h>
11+
#include "null_blk.h"
1812

1913
#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
2014
#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
@@ -35,28 +29,6 @@ static inline u64 mb_per_tick(int mbps)
3529
return (1 << 20) / TICKS_PER_SEC * ((u64) mbps);
3630
}
3731

38-
struct nullb_cmd {
39-
struct list_head list;
40-
struct llist_node ll_list;
41-
struct __call_single_data csd;
42-
struct request *rq;
43-
struct bio *bio;
44-
unsigned int tag;
45-
blk_status_t error;
46-
struct nullb_queue *nq;
47-
struct hrtimer timer;
48-
};
49-
50-
struct nullb_queue {
51-
unsigned long *tag_map;
52-
wait_queue_head_t wait;
53-
unsigned int queue_depth;
54-
struct nullb_device *dev;
55-
unsigned int requeue_selection;
56-
57-
struct nullb_cmd *cmds;
58-
};
59-
6032
/*
6133
* Status flags for nullb_device.
6234
*
@@ -92,52 +64,6 @@ struct nullb_page {
9264
#define NULLB_PAGE_LOCK (MAP_SZ - 1)
9365
#define NULLB_PAGE_FREE (MAP_SZ - 2)
9466

95-
struct nullb_device {
96-
struct nullb *nullb;
97-
struct config_item item;
98-
struct radix_tree_root data; /* data stored in the disk */
99-
struct radix_tree_root cache; /* disk cache data */
100-
unsigned long flags; /* device flags */
101-
unsigned int curr_cache;
102-
struct badblocks badblocks;
103-
104-
unsigned long size; /* device size in MB */
105-
unsigned long completion_nsec; /* time in ns to complete a request */
106-
unsigned long cache_size; /* disk cache size in MB */
107-
unsigned int submit_queues; /* number of submission queues */
108-
unsigned int home_node; /* home node for the device */
109-
unsigned int queue_mode; /* block interface */
110-
unsigned int blocksize; /* block size */
111-
unsigned int irqmode; /* IRQ completion handler */
112-
unsigned int hw_queue_depth; /* queue depth */
113-
unsigned int index; /* index of the disk, only valid with a disk */
114-
unsigned int mbps; /* Bandwidth throttle cap (in MB/s) */
115-
bool blocking; /* blocking blk-mq device */
116-
bool use_per_node_hctx; /* use per-node allocation for hardware context */
117-
bool power; /* power on/off the device */
118-
bool memory_backed; /* if data is stored in memory */
119-
bool discard; /* if support discard */
120-
};
121-
122-
struct nullb {
123-
struct nullb_device *dev;
124-
struct list_head list;
125-
unsigned int index;
126-
struct request_queue *q;
127-
struct gendisk *disk;
128-
struct blk_mq_tag_set *tag_set;
129-
struct blk_mq_tag_set __tag_set;
130-
unsigned int queue_depth;
131-
atomic_long_t cur_bytes;
132-
struct hrtimer bw_timer;
133-
unsigned long cache_flush_pos;
134-
spinlock_t lock;
135-
136-
struct nullb_queue *queues;
137-
unsigned int nr_queues;
138-
char disk_name[DISK_NAME_LEN];
139-
};
140-
14167
static LIST_HEAD(nullb_list);
14268
static struct mutex lock;
14369
static int null_major;

drivers/block/null_blk.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __BLK_NULL_BLK_H
3+
#define __BLK_NULL_BLK_H
4+
5+
#include <linux/blkdev.h>
6+
#include <linux/slab.h>
7+
#include <linux/blk-mq.h>
8+
#include <linux/hrtimer.h>
9+
#include <linux/configfs.h>
10+
#include <linux/badblocks.h>
11+
#include <linux/fault-inject.h>
12+
13+
struct nullb_cmd {
14+
struct list_head list;
15+
struct llist_node ll_list;
16+
struct __call_single_data csd;
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+
25+
struct 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+
35+
struct 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+
44+
unsigned long size; /* device size in MB */
45+
unsigned long completion_nsec; /* time in ns to complete a request */
46+
unsigned long cache_size; /* disk cache size in MB */
47+
unsigned int submit_queues; /* number of submission queues */
48+
unsigned int home_node; /* home node for the device */
49+
unsigned int queue_mode; /* block interface */
50+
unsigned int blocksize; /* block size */
51+
unsigned int irqmode; /* IRQ completion handler */
52+
unsigned int hw_queue_depth; /* queue depth */
53+
unsigned int index; /* index of the disk, only valid with a disk */
54+
unsigned int mbps; /* Bandwidth throttle cap (in MB/s) */
55+
bool blocking; /* blocking blk-mq device */
56+
bool use_per_node_hctx; /* use per-node allocation for hardware context */
57+
bool power; /* power on/off the device */
58+
bool memory_backed; /* if data is stored in memory */
59+
bool discard; /* if support discard */
60+
};
61+
62+
struct nullb {
63+
struct nullb_device *dev;
64+
struct list_head list;
65+
unsigned int index;
66+
struct request_queue *q;
67+
struct gendisk *disk;
68+
struct blk_mq_tag_set *tag_set;
69+
struct blk_mq_tag_set __tag_set;
70+
unsigned int queue_depth;
71+
atomic_long_t cur_bytes;
72+
struct hrtimer bw_timer;
73+
unsigned long cache_flush_pos;
74+
spinlock_t lock;
75+
76+
struct nullb_queue *queues;
77+
unsigned int nr_queues;
78+
char disk_name[DISK_NAME_LEN];
79+
};
80+
#endif /* __NULL_BLK_H */

0 commit comments

Comments
 (0)