File: /usr/include/linux/blkdev.h
1 #ifndef _LINUX_BLKDEV_H
2 #define _LINUX_BLKDEV_H
3
4 #include <linux/major.h>
5 #include <linux/sched.h>
6 #include <linux/genhd.h>
7 #include <linux/tqueue.h>
8 #include <linux/list.h>
9
10 struct request_queue;
11 typedef struct request_queue request_queue_t;
12 struct elevator_s;
13 typedef struct elevator_s elevator_t;
14
15 /*
16 * Ok, this is an expanded form so that we can use the same
17 * request for paging requests when that is implemented. In
18 * paging, 'bh' is NULL, and the semaphore is used to wait
19 * for read/write completion.
20 */
21 struct request {
22 struct list_head queue;
23 int elevator_sequence;
24 struct list_head table;
25
26 volatile int rq_status; /* should split this into a few status bits */
27 #define RQ_INACTIVE (-1)
28 #define RQ_ACTIVE 1
29 #define RQ_SCSI_BUSY 0xffff
30 #define RQ_SCSI_DONE 0xfffe
31 #define RQ_SCSI_DISCONNECTING 0xffe0
32
33 kdev_t rq_dev;
34 int cmd; /* READ or WRITE */
35 int errors;
36 unsigned long start_time;
37 unsigned long sector;
38 unsigned long nr_sectors;
39 unsigned long hard_sector, hard_nr_sectors;
40 unsigned int nr_segments;
41 unsigned int nr_hw_segments;
42 unsigned long current_nr_sectors;
43 void * special;
44 char * buffer;
45 struct semaphore * sem;
46 struct buffer_head * bh;
47 struct buffer_head * bhtail;
48 request_queue_t *q;
49 };
50
51 #include <linux/elevator.h>
52
53 typedef int (merge_request_fn) (request_queue_t *q,
54 struct request *req,
55 struct buffer_head *bh,
56 int);
57 typedef int (merge_requests_fn) (request_queue_t *q,
58 struct request *req,
59 struct request *req2,
60 int);
61 typedef void (request_fn_proc) (request_queue_t *q);
62 typedef request_queue_t * (queue_proc) (kdev_t dev);
63 typedef int (make_request_fn) (request_queue_t *q, int rw, struct buffer_head *bh);
64 typedef void (plug_device_fn) (request_queue_t *q, kdev_t device);
65 typedef void (unplug_device_fn) (void *q);
66
67 /*
68 * Default nr free requests per queue, ll_rw_blk will scale it down
69 * according to available RAM at init time
70 */
71 #define QUEUE_NR_REQUESTS 8192
72
73 struct request_queue
74 {
75 /*
76 * the queue request freelist, one for reads and one for writes
77 */
78 struct list_head request_freelist[2];
79 struct list_head pending_freelist[2];
80 int pending_free[2];
81
82 /*
83 * Together with queue_head for cacheline sharing
84 */
85 struct list_head queue_head;
86 elevator_t elevator;
87
88 request_fn_proc * request_fn;
89 merge_request_fn * back_merge_fn;
90 merge_request_fn * front_merge_fn;
91 merge_requests_fn * merge_requests_fn;
92 make_request_fn * make_request_fn;
93 plug_device_fn * plug_device_fn;
94 /*
95 * The queue owner gets to use this for whatever they like.
96 * ll_rw_blk doesn't touch it.
97 */
98 void * queuedata;
99
100 /*
101 * This is used to remove the plug when tq_disk runs.
102 */
103 struct tq_struct plug_tq;
104
105 /*
106 * Boolean that indicates whether this queue is plugged or not.
107 */
108 char plugged;
109
110 /*
111 * Boolean that indicates whether current_request is active or
112 * not.
113 */
114 char head_active;
115
116 /*
117 * Boolean, if true then make_request injects one artifical
118 * IO error into the next bh that is submitted. Useful for
119 * testing the effects of IO errors.
120 */
121 char oneshot_error;
122
123 /*
124 * Is meant to protect the queue in the future instead of
125 * io_request_lock
126 */
127 spinlock_t queue_lock;
128
129 /*
130 * Tasks wait here for free request
131 */
132 wait_queue_head_t wait_for_request;
133 };
134
135 struct blk_dev_struct {
136 /*
137 * queue_proc has to be atomic
138 */
139 request_queue_t request_queue;
140 queue_proc *queue;
141 void *data;
142 };
143
144 struct sec_size {
145 unsigned block_size;
146 unsigned block_size_bits;
147 };
148
149 /*
150 * Used to indicate the default queue for drivers that don't bother
151 * to implement multiple queues. We have this access macro here
152 * so as to eliminate the need for each and every block device
153 * driver to know about the internal structure of blk_dev[].
154 */
155 #define BLK_DEFAULT_QUEUE(_MAJOR) &blk_dev[_MAJOR].request_queue
156
157 extern struct blk_dev_struct blk_dev[MAX_BLKDEV];
158 extern void grok_partitions(struct gendisk *dev, int drive, unsigned minors, long size);
159 extern void register_disk(struct gendisk *dev, kdev_t first, unsigned minors, struct block_device_operations *ops, long size);
160 extern void generic_make_request(int rw, struct buffer_head * bh);
161 extern request_queue_t *blk_get_queue(kdev_t dev);
162 extern inline request_queue_t *__blk_get_queue(kdev_t dev);
163 extern void blkdev_release_request(struct request *);
164
165 /*
166 * Access functions for manipulating queue properties
167 */
168 extern void blk_init_queue(request_queue_t *, request_fn_proc *);
169 extern void blk_cleanup_queue(request_queue_t *);
170 extern void blk_queue_headactive(request_queue_t *, int);
171 extern void blk_queue_pluggable(request_queue_t *, plug_device_fn *);
172 extern void blk_queue_make_request(request_queue_t *, make_request_fn *);
173 extern void generic_unplug_device(void *);
174
175 extern int * blk_size[MAX_BLKDEV];
176
177 extern int * blksize_size[MAX_BLKDEV];
178
179 extern int * hardsect_size[MAX_BLKDEV];
180
181 extern int * max_readahead[MAX_BLKDEV];
182
183 extern int * max_sectors[MAX_BLKDEV];
184
185 extern atomic_t queued_sectors;
186
187 #define MAX_SEGMENTS 128
188 #define MAX_SECTORS (MAX_SEGMENTS*8)
189
190 #define PageAlignSize(size) (((size) + PAGE_SIZE -1) & PAGE_MASK)
191
192 /* read-ahead in pages.. */
193 #define MAX_READAHEAD 127
194 #define MIN_READAHEAD 3
195
196 #define blkdev_entry_to_request(entry) list_entry((entry), struct request, queue)
197 #define blkdev_entry_next_request(entry) blkdev_entry_to_request((entry)->next)
198 #define blkdev_entry_prev_request(entry) blkdev_entry_to_request((entry)->prev)
199 #define blkdev_next_request(req) blkdev_entry_to_request((req)->queue.next)
200 #define blkdev_prev_request(req) blkdev_entry_to_request((req)->queue.prev)
201
202 extern void drive_stat_acct (kdev_t dev, int rw,
203 unsigned long nr_sectors, int new_io);
204
205 static inline int get_hardsect_size(kdev_t dev)
206 {
207 extern int *hardsect_size[];
208 if (hardsect_size[MAJOR(dev)] != NULL)
209 return hardsect_size[MAJOR(dev)][MINOR(dev)];
210 else
211 return 512;
212 }
213
214 #define blk_finished_io(nsects) \
215 atomic_sub(nsects, &queued_sectors); \
216 if (atomic_read(&queued_sectors) < 0) { \
217 printk("block: queued_sectors < 0\n"); \
218 atomic_set(&queued_sectors, 0); \
219 }
220
221 #define blk_started_io(nsects) \
222 atomic_add(nsects, &queued_sectors);
223
224 #endif
225