]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_BLKDEV_H |
2 | #define _LINUX_BLKDEV_H | |
3 | ||
85fd0bc9 RK |
4 | #include <linux/sched.h> |
5 | ||
f5ff8422 JA |
6 | #ifdef CONFIG_BLOCK |
7 | ||
1da177e4 LT |
8 | #include <linux/major.h> |
9 | #include <linux/genhd.h> | |
10 | #include <linux/list.h> | |
11 | #include <linux/timer.h> | |
12 | #include <linux/workqueue.h> | |
13 | #include <linux/pagemap.h> | |
14 | #include <linux/backing-dev.h> | |
15 | #include <linux/wait.h> | |
16 | #include <linux/mempool.h> | |
17 | #include <linux/bio.h> | |
1da177e4 | 18 | #include <linux/stringify.h> |
3e6053d7 | 19 | #include <linux/gfp.h> |
d351af01 | 20 | #include <linux/bsg.h> |
c7c22e4d | 21 | #include <linux/smp.h> |
1da177e4 LT |
22 | |
23 | #include <asm/scatterlist.h> | |
24 | ||
de477254 | 25 | struct module; |
21b2f0c8 CH |
26 | struct scsi_ioctl_command; |
27 | ||
1da177e4 | 28 | struct request_queue; |
1da177e4 | 29 | struct elevator_queue; |
1da177e4 | 30 | struct request_pm_state; |
2056a782 | 31 | struct blk_trace; |
3d6392cf JA |
32 | struct request; |
33 | struct sg_io_hdr; | |
aa387cc8 | 34 | struct bsg_job; |
3c798398 | 35 | struct blkcg_gq; |
1da177e4 LT |
36 | |
37 | #define BLKDEV_MIN_RQ 4 | |
38 | #define BLKDEV_MAX_RQ 128 /* Default maximum */ | |
39 | ||
8bd435b3 TH |
40 | /* |
41 | * Maximum number of blkcg policies allowed to be registered concurrently. | |
42 | * Defined here to simplify include dependency. | |
43 | */ | |
44 | #define BLKCG_MAX_POLS 2 | |
45 | ||
1da177e4 | 46 | struct request; |
8ffdc655 | 47 | typedef void (rq_end_io_fn)(struct request *, int); |
1da177e4 LT |
48 | |
49 | struct request_list { | |
1faa16d2 JA |
50 | /* |
51 | * count[], starved[], and wait[] are indexed by | |
52 | * BLK_RW_SYNC/BLK_RW_ASYNC | |
53 | */ | |
8a5ecdd4 TH |
54 | int count[2]; |
55 | int starved[2]; | |
56 | mempool_t *rq_pool; | |
57 | wait_queue_head_t wait[2]; | |
1da177e4 LT |
58 | }; |
59 | ||
4aff5e23 JA |
60 | /* |
61 | * request command types | |
62 | */ | |
63 | enum rq_cmd_type_bits { | |
64 | REQ_TYPE_FS = 1, /* fs request */ | |
65 | REQ_TYPE_BLOCK_PC, /* scsi command */ | |
66 | REQ_TYPE_SENSE, /* sense request */ | |
67 | REQ_TYPE_PM_SUSPEND, /* suspend request */ | |
68 | REQ_TYPE_PM_RESUME, /* resume request */ | |
69 | REQ_TYPE_PM_SHUTDOWN, /* shutdown request */ | |
4aff5e23 | 70 | REQ_TYPE_SPECIAL, /* driver defined type */ |
4aff5e23 JA |
71 | /* |
72 | * for ATA/ATAPI devices. this really doesn't belong here, ide should | |
73 | * use REQ_TYPE_SPECIAL and use rq->cmd[0] with the range of driver | |
74 | * private REQ_LB opcodes to differentiate what type of request this is | |
75 | */ | |
4aff5e23 | 76 | REQ_TYPE_ATA_TASKFILE, |
cea2885a | 77 | REQ_TYPE_ATA_PC, |
4aff5e23 JA |
78 | }; |
79 | ||
1da177e4 LT |
80 | #define BLK_MAX_CDB 16 |
81 | ||
82 | /* | |
63a71386 | 83 | * try to put the fields that are referenced together in the same cacheline. |
4d0d98b6 | 84 | * if you modify this structure, be sure to check block/blk-core.c:blk_rq_init() |
63a71386 | 85 | * as well! |
1da177e4 LT |
86 | */ |
87 | struct request { | |
ff856bad | 88 | struct list_head queuelist; |
c7c22e4d | 89 | struct call_single_data csd; |
ff856bad | 90 | |
165125e1 | 91 | struct request_queue *q; |
e6a1c874 | 92 | |
4aff5e23 JA |
93 | unsigned int cmd_flags; |
94 | enum rq_cmd_type_bits cmd_type; | |
242f9dcb | 95 | unsigned long atomic_flags; |
1da177e4 | 96 | |
181fdde3 RK |
97 | int cpu; |
98 | ||
a2dec7b3 | 99 | /* the following two fields are internal, NEVER access directly */ |
a2dec7b3 | 100 | unsigned int __data_len; /* total data len */ |
181fdde3 | 101 | sector_t __sector; /* sector cursor */ |
1da177e4 LT |
102 | |
103 | struct bio *bio; | |
104 | struct bio *biotail; | |
105 | ||
9817064b | 106 | struct hlist_node hash; /* merge hash */ |
e6a1c874 JA |
107 | /* |
108 | * The rb_node is only used inside the io scheduler, requests | |
109 | * are pruned when moved to the dispatch queue. So let the | |
c186794d | 110 | * completion_data share space with the rb_node. |
e6a1c874 JA |
111 | */ |
112 | union { | |
113 | struct rb_node rb_node; /* sort/lookup */ | |
c186794d | 114 | void *completion_data; |
e6a1c874 | 115 | }; |
9817064b | 116 | |
ff7d145f | 117 | /* |
7f1dc8a2 | 118 | * Three pointers are available for the IO schedulers, if they need |
c186794d MS |
119 | * more they have to dynamically allocate it. Flush requests are |
120 | * never put on the IO scheduler. So let the flush fields share | |
a612fddf | 121 | * space with the elevator data. |
ff7d145f | 122 | */ |
c186794d | 123 | union { |
a612fddf TH |
124 | struct { |
125 | struct io_cq *icq; | |
126 | void *priv[2]; | |
127 | } elv; | |
128 | ||
c186794d MS |
129 | struct { |
130 | unsigned int seq; | |
131 | struct list_head list; | |
4853abaa | 132 | rq_end_io_fn *saved_end_io; |
c186794d MS |
133 | } flush; |
134 | }; | |
ff7d145f | 135 | |
8f34ee75 | 136 | struct gendisk *rq_disk; |
09e099d4 | 137 | struct hd_struct *part; |
1da177e4 | 138 | unsigned long start_time; |
9195291e DS |
139 | #ifdef CONFIG_BLK_CGROUP |
140 | unsigned long long start_time_ns; | |
141 | unsigned long long io_start_time_ns; /* when passed to hardware */ | |
142 | #endif | |
1da177e4 LT |
143 | /* Number of scatter-gather DMA addr+len pairs after |
144 | * physical address coalescing is performed. | |
145 | */ | |
146 | unsigned short nr_phys_segments; | |
13f05c8d MP |
147 | #if defined(CONFIG_BLK_DEV_INTEGRITY) |
148 | unsigned short nr_integrity_segments; | |
149 | #endif | |
1da177e4 | 150 | |
8f34ee75 JA |
151 | unsigned short ioprio; |
152 | ||
181fdde3 RK |
153 | int ref_count; |
154 | ||
731ec497 TH |
155 | void *special; /* opaque pointer available for LLD use */ |
156 | char *buffer; /* kaddr of the current segment if available */ | |
1da177e4 | 157 | |
cdd60262 JA |
158 | int tag; |
159 | int errors; | |
160 | ||
1da177e4 LT |
161 | /* |
162 | * when request is used as a packet command carrier | |
163 | */ | |
d7e3c324 FT |
164 | unsigned char __cmd[BLK_MAX_CDB]; |
165 | unsigned char *cmd; | |
181fdde3 | 166 | unsigned short cmd_len; |
1da177e4 | 167 | |
7a85f889 | 168 | unsigned int extra_len; /* length of alignment and padding */ |
1da177e4 | 169 | unsigned int sense_len; |
c3a4d78c | 170 | unsigned int resid_len; /* residual count */ |
1da177e4 LT |
171 | void *sense; |
172 | ||
242f9dcb JA |
173 | unsigned long deadline; |
174 | struct list_head timeout_list; | |
1da177e4 | 175 | unsigned int timeout; |
17e01f21 | 176 | int retries; |
1da177e4 | 177 | |
1da177e4 | 178 | /* |
c00895ab | 179 | * completion callback. |
1da177e4 LT |
180 | */ |
181 | rq_end_io_fn *end_io; | |
182 | void *end_io_data; | |
abae1fde FT |
183 | |
184 | /* for bidi */ | |
185 | struct request *next_rq; | |
1da177e4 LT |
186 | }; |
187 | ||
766ca442 FLVC |
188 | static inline unsigned short req_get_ioprio(struct request *req) |
189 | { | |
190 | return req->ioprio; | |
191 | } | |
192 | ||
1da177e4 | 193 | /* |
4aff5e23 | 194 | * State information carried for REQ_TYPE_PM_SUSPEND and REQ_TYPE_PM_RESUME |
1da177e4 LT |
195 | * requests. Some step values could eventually be made generic. |
196 | */ | |
197 | struct request_pm_state | |
198 | { | |
199 | /* PM state machine step value, currently driver specific */ | |
200 | int pm_step; | |
201 | /* requested PM state value (S1, S2, S3, S4, ...) */ | |
202 | u32 pm_state; | |
203 | void* data; /* for driver use */ | |
204 | }; | |
205 | ||
206 | #include <linux/elevator.h> | |
207 | ||
165125e1 | 208 | typedef void (request_fn_proc) (struct request_queue *q); |
5a7bbad2 | 209 | typedef void (make_request_fn) (struct request_queue *q, struct bio *bio); |
165125e1 | 210 | typedef int (prep_rq_fn) (struct request_queue *, struct request *); |
28018c24 | 211 | typedef void (unprep_rq_fn) (struct request_queue *, struct request *); |
1da177e4 LT |
212 | |
213 | struct bio_vec; | |
cc371e66 AK |
214 | struct bvec_merge_data { |
215 | struct block_device *bi_bdev; | |
216 | sector_t bi_sector; | |
217 | unsigned bi_size; | |
218 | unsigned long bi_rw; | |
219 | }; | |
220 | typedef int (merge_bvec_fn) (struct request_queue *, struct bvec_merge_data *, | |
221 | struct bio_vec *); | |
ff856bad | 222 | typedef void (softirq_done_fn)(struct request *); |
2fb98e84 | 223 | typedef int (dma_drain_needed_fn)(struct request *); |
ef9e3fac | 224 | typedef int (lld_busy_fn) (struct request_queue *q); |
aa387cc8 | 225 | typedef int (bsg_job_fn) (struct bsg_job *); |
1da177e4 | 226 | |
242f9dcb JA |
227 | enum blk_eh_timer_return { |
228 | BLK_EH_NOT_HANDLED, | |
229 | BLK_EH_HANDLED, | |
230 | BLK_EH_RESET_TIMER, | |
231 | }; | |
232 | ||
233 | typedef enum blk_eh_timer_return (rq_timed_out_fn)(struct request *); | |
234 | ||
1da177e4 LT |
235 | enum blk_queue_state { |
236 | Queue_down, | |
237 | Queue_up, | |
238 | }; | |
239 | ||
1da177e4 LT |
240 | struct blk_queue_tag { |
241 | struct request **tag_index; /* map of busy tags */ | |
242 | unsigned long *tag_map; /* bit map of free/busy tags */ | |
1da177e4 LT |
243 | int busy; /* current depth */ |
244 | int max_depth; /* what we will send to device */ | |
ba025082 | 245 | int real_max_depth; /* what the array can hold */ |
1da177e4 LT |
246 | atomic_t refcnt; /* map can be shared */ |
247 | }; | |
248 | ||
abf54393 FT |
249 | #define BLK_SCSI_MAX_CMDS (256) |
250 | #define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8)) | |
251 | ||
025146e1 MP |
252 | struct queue_limits { |
253 | unsigned long bounce_pfn; | |
254 | unsigned long seg_boundary_mask; | |
255 | ||
256 | unsigned int max_hw_sectors; | |
257 | unsigned int max_sectors; | |
258 | unsigned int max_segment_size; | |
c72758f3 MP |
259 | unsigned int physical_block_size; |
260 | unsigned int alignment_offset; | |
261 | unsigned int io_min; | |
262 | unsigned int io_opt; | |
67efc925 | 263 | unsigned int max_discard_sectors; |
86b37281 MP |
264 | unsigned int discard_granularity; |
265 | unsigned int discard_alignment; | |
025146e1 MP |
266 | |
267 | unsigned short logical_block_size; | |
8a78362c | 268 | unsigned short max_segments; |
13f05c8d | 269 | unsigned short max_integrity_segments; |
025146e1 | 270 | |
c72758f3 | 271 | unsigned char misaligned; |
86b37281 | 272 | unsigned char discard_misaligned; |
e692cb66 | 273 | unsigned char cluster; |
a934a00a | 274 | unsigned char discard_zeroes_data; |
025146e1 MP |
275 | }; |
276 | ||
d7b76301 | 277 | struct request_queue { |
1da177e4 LT |
278 | /* |
279 | * Together with queue_head for cacheline sharing | |
280 | */ | |
281 | struct list_head queue_head; | |
282 | struct request *last_merge; | |
b374d18a | 283 | struct elevator_queue *elevator; |
8a5ecdd4 TH |
284 | int nr_rqs[2]; /* # allocated [a]sync rqs */ |
285 | int nr_rqs_elvpriv; /* # allocated rqs w/ elvpriv */ | |
1da177e4 LT |
286 | |
287 | /* | |
288 | * the queue request freelist, one for reads and one for writes | |
289 | */ | |
290 | struct request_list rq; | |
291 | ||
292 | request_fn_proc *request_fn; | |
1da177e4 LT |
293 | make_request_fn *make_request_fn; |
294 | prep_rq_fn *prep_rq_fn; | |
28018c24 | 295 | unprep_rq_fn *unprep_rq_fn; |
1da177e4 | 296 | merge_bvec_fn *merge_bvec_fn; |
ff856bad | 297 | softirq_done_fn *softirq_done_fn; |
242f9dcb | 298 | rq_timed_out_fn *rq_timed_out_fn; |
2fb98e84 | 299 | dma_drain_needed_fn *dma_drain_needed; |
ef9e3fac | 300 | lld_busy_fn *lld_busy_fn; |
1da177e4 | 301 | |
8922e16c TH |
302 | /* |
303 | * Dispatch queue sorting | |
304 | */ | |
1b47f531 | 305 | sector_t end_sector; |
8922e16c | 306 | struct request *boundary_rq; |
8922e16c | 307 | |
1da177e4 | 308 | /* |
3cca6dc1 | 309 | * Delayed queue handling |
1da177e4 | 310 | */ |
3cca6dc1 | 311 | struct delayed_work delay_work; |
1da177e4 LT |
312 | |
313 | struct backing_dev_info backing_dev_info; | |
314 | ||
315 | /* | |
316 | * The queue owner gets to use this for whatever they like. | |
317 | * ll_rw_blk doesn't touch it. | |
318 | */ | |
319 | void *queuedata; | |
320 | ||
1da177e4 | 321 | /* |
d7b76301 | 322 | * various queue flags, see QUEUE_* below |
1da177e4 | 323 | */ |
d7b76301 | 324 | unsigned long queue_flags; |
1da177e4 | 325 | |
a73f730d TH |
326 | /* |
327 | * ida allocated id for this queue. Used to index queues from | |
328 | * ioctx. | |
329 | */ | |
330 | int id; | |
331 | ||
1da177e4 | 332 | /* |
d7b76301 | 333 | * queue needs bounce pages for pages above this limit |
1da177e4 | 334 | */ |
d7b76301 | 335 | gfp_t bounce_gfp; |
1da177e4 LT |
336 | |
337 | /* | |
152587de JA |
338 | * protects queue structures from reentrancy. ->__queue_lock should |
339 | * _never_ be used directly, it is queue private. always use | |
340 | * ->queue_lock. | |
1da177e4 | 341 | */ |
152587de | 342 | spinlock_t __queue_lock; |
1da177e4 LT |
343 | spinlock_t *queue_lock; |
344 | ||
345 | /* | |
346 | * queue kobject | |
347 | */ | |
348 | struct kobject kobj; | |
349 | ||
350 | /* | |
351 | * queue settings | |
352 | */ | |
353 | unsigned long nr_requests; /* Max # of requests */ | |
354 | unsigned int nr_congestion_on; | |
355 | unsigned int nr_congestion_off; | |
356 | unsigned int nr_batching; | |
357 | ||
fa0ccd83 | 358 | unsigned int dma_drain_size; |
d7b76301 | 359 | void *dma_drain_buffer; |
e3790c7d | 360 | unsigned int dma_pad_mask; |
1da177e4 LT |
361 | unsigned int dma_alignment; |
362 | ||
363 | struct blk_queue_tag *queue_tags; | |
6eca9004 | 364 | struct list_head tag_busy_list; |
1da177e4 | 365 | |
15853af9 | 366 | unsigned int nr_sorted; |
0a7ae2ff | 367 | unsigned int in_flight[2]; |
1da177e4 | 368 | |
242f9dcb JA |
369 | unsigned int rq_timeout; |
370 | struct timer_list timeout; | |
371 | struct list_head timeout_list; | |
372 | ||
a612fddf | 373 | struct list_head icq_list; |
4eef3049 | 374 | #ifdef CONFIG_BLK_CGROUP |
a2b1693b | 375 | DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS); |
3c798398 | 376 | struct blkcg_gq *root_blkg; |
03aa264a | 377 | struct list_head blkg_list; |
4eef3049 | 378 | #endif |
a612fddf | 379 | |
025146e1 MP |
380 | struct queue_limits limits; |
381 | ||
1da177e4 LT |
382 | /* |
383 | * sg stuff | |
384 | */ | |
385 | unsigned int sg_timeout; | |
386 | unsigned int sg_reserved_size; | |
1946089a | 387 | int node; |
6c5c9341 | 388 | #ifdef CONFIG_BLK_DEV_IO_TRACE |
2056a782 | 389 | struct blk_trace *blk_trace; |
6c5c9341 | 390 | #endif |
1da177e4 | 391 | /* |
4913efe4 | 392 | * for flush operations |
1da177e4 | 393 | */ |
4913efe4 | 394 | unsigned int flush_flags; |
f3876930 | 395 | unsigned int flush_not_queueable:1; |
3ac0cc45 | 396 | unsigned int flush_queue_delayed:1; |
ae1b1539 TH |
397 | unsigned int flush_pending_idx:1; |
398 | unsigned int flush_running_idx:1; | |
399 | unsigned long flush_pending_since; | |
400 | struct list_head flush_queue[2]; | |
401 | struct list_head flush_data_in_flight; | |
dd4c133f | 402 | struct request flush_rq; |
483f4afc AV |
403 | |
404 | struct mutex sysfs_lock; | |
d351af01 | 405 | |
d732580b TH |
406 | int bypass_depth; |
407 | ||
d351af01 | 408 | #if defined(CONFIG_BLK_DEV_BSG) |
aa387cc8 MC |
409 | bsg_job_fn *bsg_job_fn; |
410 | int bsg_job_size; | |
d351af01 FT |
411 | struct bsg_class_device bsg_dev; |
412 | #endif | |
e43473b7 | 413 | |
923adde1 TH |
414 | #ifdef CONFIG_BLK_CGROUP |
415 | struct list_head all_q_node; | |
416 | #endif | |
e43473b7 VG |
417 | #ifdef CONFIG_BLK_DEV_THROTTLING |
418 | /* Throttle data */ | |
419 | struct throtl_data *td; | |
420 | #endif | |
1da177e4 LT |
421 | }; |
422 | ||
1da177e4 LT |
423 | #define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */ |
424 | #define QUEUE_FLAG_STOPPED 2 /* queue is stopped */ | |
1faa16d2 JA |
425 | #define QUEUE_FLAG_SYNCFULL 3 /* read queue has been filled */ |
426 | #define QUEUE_FLAG_ASYNCFULL 4 /* write queue has been filled */ | |
1da177e4 | 427 | #define QUEUE_FLAG_DEAD 5 /* queue being torn down */ |
d732580b | 428 | #define QUEUE_FLAG_BYPASS 6 /* act as dumb FIFO queue */ |
c21e6beb JA |
429 | #define QUEUE_FLAG_BIDI 7 /* queue supports bidi requests */ |
430 | #define QUEUE_FLAG_NOMERGES 8 /* disable merge attempts */ | |
5757a6d7 | 431 | #define QUEUE_FLAG_SAME_COMP 9 /* complete on same CPU-group */ |
c21e6beb JA |
432 | #define QUEUE_FLAG_FAIL_IO 10 /* fake timeout */ |
433 | #define QUEUE_FLAG_STACKABLE 11 /* supports request stacking */ | |
434 | #define QUEUE_FLAG_NONROT 12 /* non-rotational device (SSD) */ | |
88e740f1 | 435 | #define QUEUE_FLAG_VIRT QUEUE_FLAG_NONROT /* paravirt device */ |
c21e6beb JA |
436 | #define QUEUE_FLAG_IO_STAT 13 /* do IO stats */ |
437 | #define QUEUE_FLAG_DISCARD 14 /* supports DISCARD */ | |
438 | #define QUEUE_FLAG_NOXMERGES 15 /* No extended merges */ | |
439 | #define QUEUE_FLAG_ADD_RANDOM 16 /* Contributes to random pool */ | |
440 | #define QUEUE_FLAG_SECDISCARD 17 /* supports SECDISCARD */ | |
5757a6d7 | 441 | #define QUEUE_FLAG_SAME_FORCE 18 /* force complete on same CPU */ |
bc58ba94 JA |
442 | |
443 | #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ | |
01e97f6b | 444 | (1 << QUEUE_FLAG_STACKABLE) | \ |
e2e1a148 JA |
445 | (1 << QUEUE_FLAG_SAME_COMP) | \ |
446 | (1 << QUEUE_FLAG_ADD_RANDOM)) | |
797e7dbb | 447 | |
8bcb6c7d | 448 | static inline void queue_lockdep_assert_held(struct request_queue *q) |
8f45c1a5 | 449 | { |
8bcb6c7d AK |
450 | if (q->queue_lock) |
451 | lockdep_assert_held(q->queue_lock); | |
8f45c1a5 LT |
452 | } |
453 | ||
75ad23bc NP |
454 | static inline void queue_flag_set_unlocked(unsigned int flag, |
455 | struct request_queue *q) | |
456 | { | |
457 | __set_bit(flag, &q->queue_flags); | |
458 | } | |
459 | ||
e48ec690 JA |
460 | static inline int queue_flag_test_and_clear(unsigned int flag, |
461 | struct request_queue *q) | |
462 | { | |
8bcb6c7d | 463 | queue_lockdep_assert_held(q); |
e48ec690 JA |
464 | |
465 | if (test_bit(flag, &q->queue_flags)) { | |
466 | __clear_bit(flag, &q->queue_flags); | |
467 | return 1; | |
468 | } | |
469 | ||
470 | return 0; | |
471 | } | |
472 | ||
473 | static inline int queue_flag_test_and_set(unsigned int flag, | |
474 | struct request_queue *q) | |
475 | { | |
8bcb6c7d | 476 | queue_lockdep_assert_held(q); |
e48ec690 JA |
477 | |
478 | if (!test_bit(flag, &q->queue_flags)) { | |
479 | __set_bit(flag, &q->queue_flags); | |
480 | return 0; | |
481 | } | |
482 | ||
483 | return 1; | |
484 | } | |
485 | ||
75ad23bc NP |
486 | static inline void queue_flag_set(unsigned int flag, struct request_queue *q) |
487 | { | |
8bcb6c7d | 488 | queue_lockdep_assert_held(q); |
75ad23bc NP |
489 | __set_bit(flag, &q->queue_flags); |
490 | } | |
491 | ||
492 | static inline void queue_flag_clear_unlocked(unsigned int flag, | |
493 | struct request_queue *q) | |
494 | { | |
495 | __clear_bit(flag, &q->queue_flags); | |
496 | } | |
497 | ||
0a7ae2ff JA |
498 | static inline int queue_in_flight(struct request_queue *q) |
499 | { | |
500 | return q->in_flight[0] + q->in_flight[1]; | |
501 | } | |
502 | ||
75ad23bc NP |
503 | static inline void queue_flag_clear(unsigned int flag, struct request_queue *q) |
504 | { | |
8bcb6c7d | 505 | queue_lockdep_assert_held(q); |
75ad23bc NP |
506 | __clear_bit(flag, &q->queue_flags); |
507 | } | |
508 | ||
1da177e4 LT |
509 | #define blk_queue_tagged(q) test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags) |
510 | #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags) | |
34f6055c | 511 | #define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags) |
d732580b | 512 | #define blk_queue_bypass(q) test_bit(QUEUE_FLAG_BYPASS, &(q)->queue_flags) |
ac9fafa1 | 513 | #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags) |
488991e2 AB |
514 | #define blk_queue_noxmerges(q) \ |
515 | test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags) | |
a68bbddb | 516 | #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags) |
bc58ba94 | 517 | #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags) |
e2e1a148 | 518 | #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags) |
4ee5eaf4 KU |
519 | #define blk_queue_stackable(q) \ |
520 | test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags) | |
c15227de | 521 | #define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags) |
8d57a98c AH |
522 | #define blk_queue_secdiscard(q) (blk_queue_discard(q) && \ |
523 | test_bit(QUEUE_FLAG_SECDISCARD, &(q)->queue_flags)) | |
1da177e4 | 524 | |
33659ebb CH |
525 | #define blk_noretry_request(rq) \ |
526 | ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \ | |
527 | REQ_FAILFAST_DRIVER)) | |
528 | ||
529 | #define blk_account_rq(rq) \ | |
530 | (((rq)->cmd_flags & REQ_STARTED) && \ | |
531 | ((rq)->cmd_type == REQ_TYPE_FS || \ | |
532 | ((rq)->cmd_flags & REQ_DISCARD))) | |
533 | ||
1da177e4 | 534 | #define blk_pm_request(rq) \ |
33659ebb CH |
535 | ((rq)->cmd_type == REQ_TYPE_PM_SUSPEND || \ |
536 | (rq)->cmd_type == REQ_TYPE_PM_RESUME) | |
1da177e4 | 537 | |
ab780f1e | 538 | #define blk_rq_cpu_valid(rq) ((rq)->cpu != -1) |
abae1fde | 539 | #define blk_bidi_rq(rq) ((rq)->next_rq != NULL) |
336cdb40 KU |
540 | /* rq->queuelist of dequeued request must be list_empty() */ |
541 | #define blk_queued_rq(rq) (!list_empty(&(rq)->queuelist)) | |
1da177e4 LT |
542 | |
543 | #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist) | |
544 | ||
4aff5e23 | 545 | #define rq_data_dir(rq) ((rq)->cmd_flags & 1) |
1da177e4 | 546 | |
e692cb66 MP |
547 | static inline unsigned int blk_queue_cluster(struct request_queue *q) |
548 | { | |
549 | return q->limits.cluster; | |
550 | } | |
551 | ||
9e2585a8 | 552 | /* |
1faa16d2 | 553 | * We regard a request as sync, if either a read or a sync write |
9e2585a8 | 554 | */ |
1faa16d2 JA |
555 | static inline bool rw_is_sync(unsigned int rw_flags) |
556 | { | |
7b6d91da | 557 | return !(rw_flags & REQ_WRITE) || (rw_flags & REQ_SYNC); |
1faa16d2 JA |
558 | } |
559 | ||
560 | static inline bool rq_is_sync(struct request *rq) | |
561 | { | |
562 | return rw_is_sync(rq->cmd_flags); | |
563 | } | |
564 | ||
1faa16d2 | 565 | static inline int blk_queue_full(struct request_queue *q, int sync) |
1da177e4 | 566 | { |
1faa16d2 JA |
567 | if (sync) |
568 | return test_bit(QUEUE_FLAG_SYNCFULL, &q->queue_flags); | |
569 | return test_bit(QUEUE_FLAG_ASYNCFULL, &q->queue_flags); | |
1da177e4 LT |
570 | } |
571 | ||
1faa16d2 | 572 | static inline void blk_set_queue_full(struct request_queue *q, int sync) |
1da177e4 | 573 | { |
1faa16d2 JA |
574 | if (sync) |
575 | queue_flag_set(QUEUE_FLAG_SYNCFULL, q); | |
1da177e4 | 576 | else |
1faa16d2 | 577 | queue_flag_set(QUEUE_FLAG_ASYNCFULL, q); |
1da177e4 LT |
578 | } |
579 | ||
1faa16d2 | 580 | static inline void blk_clear_queue_full(struct request_queue *q, int sync) |
1da177e4 | 581 | { |
1faa16d2 JA |
582 | if (sync) |
583 | queue_flag_clear(QUEUE_FLAG_SYNCFULL, q); | |
1da177e4 | 584 | else |
1faa16d2 | 585 | queue_flag_clear(QUEUE_FLAG_ASYNCFULL, q); |
1da177e4 LT |
586 | } |
587 | ||
588 | ||
589 | /* | |
590 | * mergeable request must not have _NOMERGE or _BARRIER bit set, nor may | |
591 | * it already be started by driver. | |
592 | */ | |
593 | #define RQ_NOMERGE_FLAGS \ | |
02e031cb | 594 | (REQ_NOMERGE | REQ_STARTED | REQ_SOFTBARRIER | REQ_FLUSH | REQ_FUA) |
1da177e4 | 595 | #define rq_mergeable(rq) \ |
e17fc0a1 | 596 | (!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \ |
33659ebb CH |
597 | (((rq)->cmd_flags & REQ_DISCARD) || \ |
598 | (rq)->cmd_type == REQ_TYPE_FS)) | |
1da177e4 | 599 | |
1da177e4 LT |
600 | /* |
601 | * q->prep_rq_fn return values | |
602 | */ | |
603 | #define BLKPREP_OK 0 /* serve it */ | |
604 | #define BLKPREP_KILL 1 /* fatal error, kill */ | |
605 | #define BLKPREP_DEFER 2 /* leave on queue */ | |
606 | ||
607 | extern unsigned long blk_max_low_pfn, blk_max_pfn; | |
608 | ||
609 | /* | |
610 | * standard bounce addresses: | |
611 | * | |
612 | * BLK_BOUNCE_HIGH : bounce all highmem pages | |
613 | * BLK_BOUNCE_ANY : don't bounce anything | |
614 | * BLK_BOUNCE_ISA : bounce pages above ISA DMA boundary | |
615 | */ | |
2472892a AK |
616 | |
617 | #if BITS_PER_LONG == 32 | |
1da177e4 | 618 | #define BLK_BOUNCE_HIGH ((u64)blk_max_low_pfn << PAGE_SHIFT) |
2472892a AK |
619 | #else |
620 | #define BLK_BOUNCE_HIGH -1ULL | |
621 | #endif | |
622 | #define BLK_BOUNCE_ANY (-1ULL) | |
bfe17231 | 623 | #define BLK_BOUNCE_ISA (DMA_BIT_MASK(24)) |
1da177e4 | 624 | |
3d6392cf JA |
625 | /* |
626 | * default timeout for SG_IO if none specified | |
627 | */ | |
628 | #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ) | |
f2f1fa78 | 629 | #define BLK_MIN_SG_TIMEOUT (7 * HZ) |
3d6392cf | 630 | |
2a7326b5 | 631 | #ifdef CONFIG_BOUNCE |
1da177e4 | 632 | extern int init_emergency_isa_pool(void); |
165125e1 | 633 | extern void blk_queue_bounce(struct request_queue *q, struct bio **bio); |
1da177e4 LT |
634 | #else |
635 | static inline int init_emergency_isa_pool(void) | |
636 | { | |
637 | return 0; | |
638 | } | |
165125e1 | 639 | static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio) |
1da177e4 LT |
640 | { |
641 | } | |
642 | #endif /* CONFIG_MMU */ | |
643 | ||
152e283f FT |
644 | struct rq_map_data { |
645 | struct page **pages; | |
646 | int page_order; | |
647 | int nr_entries; | |
56c451f4 | 648 | unsigned long offset; |
97ae77a1 | 649 | int null_mapped; |
ecb554a8 | 650 | int from_user; |
152e283f FT |
651 | }; |
652 | ||
5705f702 N |
653 | struct req_iterator { |
654 | int i; | |
655 | struct bio *bio; | |
656 | }; | |
657 | ||
658 | /* This should not be used directly - use rq_for_each_segment */ | |
1e428079 JA |
659 | #define for_each_bio(_bio) \ |
660 | for (; _bio; _bio = _bio->bi_next) | |
5705f702 | 661 | #define __rq_for_each_bio(_bio, rq) \ |
1da177e4 LT |
662 | if ((rq->bio)) \ |
663 | for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next) | |
664 | ||
5705f702 N |
665 | #define rq_for_each_segment(bvl, _rq, _iter) \ |
666 | __rq_for_each_bio(_iter.bio, _rq) \ | |
667 | bio_for_each_segment(bvl, _iter.bio, _iter.i) | |
668 | ||
669 | #define rq_iter_last(rq, _iter) \ | |
670 | (_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1) | |
671 | ||
2d4dc890 IL |
672 | #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE |
673 | # error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform" | |
674 | #endif | |
675 | #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE | |
676 | extern void rq_flush_dcache_pages(struct request *rq); | |
677 | #else | |
678 | static inline void rq_flush_dcache_pages(struct request *rq) | |
679 | { | |
680 | } | |
681 | #endif | |
682 | ||
1da177e4 LT |
683 | extern int blk_register_queue(struct gendisk *disk); |
684 | extern void blk_unregister_queue(struct gendisk *disk); | |
1da177e4 | 685 | extern void generic_make_request(struct bio *bio); |
2a4aa30c | 686 | extern void blk_rq_init(struct request_queue *q, struct request *rq); |
1da177e4 | 687 | extern void blk_put_request(struct request *); |
165125e1 | 688 | extern void __blk_put_request(struct request_queue *, struct request *); |
165125e1 | 689 | extern struct request *blk_get_request(struct request_queue *, int, gfp_t); |
79eb63e9 BH |
690 | extern struct request *blk_make_request(struct request_queue *, struct bio *, |
691 | gfp_t); | |
165125e1 | 692 | extern void blk_requeue_request(struct request_queue *, struct request *); |
66ac0280 CH |
693 | extern void blk_add_request_payload(struct request *rq, struct page *page, |
694 | unsigned int len); | |
82124d60 | 695 | extern int blk_rq_check_limits(struct request_queue *q, struct request *rq); |
ef9e3fac | 696 | extern int blk_lld_busy(struct request_queue *q); |
b0fd271d KU |
697 | extern int blk_rq_prep_clone(struct request *rq, struct request *rq_src, |
698 | struct bio_set *bs, gfp_t gfp_mask, | |
699 | int (*bio_ctr)(struct bio *, struct bio *, void *), | |
700 | void *data); | |
701 | extern void blk_rq_unprep_clone(struct request *rq); | |
82124d60 KU |
702 | extern int blk_insert_cloned_request(struct request_queue *q, |
703 | struct request *rq); | |
3cca6dc1 | 704 | extern void blk_delay_queue(struct request_queue *, unsigned long); |
165125e1 | 705 | extern void blk_recount_segments(struct request_queue *, struct bio *); |
0bfc96cb | 706 | extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int); |
577ebb37 PB |
707 | extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t, |
708 | unsigned int, void __user *); | |
74f3c8af AV |
709 | extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t, |
710 | unsigned int, void __user *); | |
e915e872 AV |
711 | extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t, |
712 | struct scsi_ioctl_command __user *); | |
3fcfab16 | 713 | |
5a7bbad2 | 714 | extern void blk_queue_bio(struct request_queue *q, struct bio *bio); |
166e1f90 | 715 | |
3fcfab16 AM |
716 | /* |
717 | * A queue has just exitted congestion. Note this in the global counter of | |
718 | * congested queues, and wake up anyone who was waiting for requests to be | |
719 | * put back. | |
720 | */ | |
8aa7e847 | 721 | static inline void blk_clear_queue_congested(struct request_queue *q, int sync) |
3fcfab16 | 722 | { |
8aa7e847 | 723 | clear_bdi_congested(&q->backing_dev_info, sync); |
3fcfab16 AM |
724 | } |
725 | ||
726 | /* | |
727 | * A queue has just entered congestion. Flag that in the queue's VM-visible | |
728 | * state flags and increment the global gounter of congested queues. | |
729 | */ | |
8aa7e847 | 730 | static inline void blk_set_queue_congested(struct request_queue *q, int sync) |
3fcfab16 | 731 | { |
8aa7e847 | 732 | set_bdi_congested(&q->backing_dev_info, sync); |
3fcfab16 AM |
733 | } |
734 | ||
165125e1 JA |
735 | extern void blk_start_queue(struct request_queue *q); |
736 | extern void blk_stop_queue(struct request_queue *q); | |
1da177e4 | 737 | extern void blk_sync_queue(struct request_queue *q); |
165125e1 | 738 | extern void __blk_stop_queue(struct request_queue *q); |
24ecfbe2 | 739 | extern void __blk_run_queue(struct request_queue *q); |
165125e1 | 740 | extern void blk_run_queue(struct request_queue *); |
c21e6beb | 741 | extern void blk_run_queue_async(struct request_queue *q); |
a3bce90e | 742 | extern int blk_rq_map_user(struct request_queue *, struct request *, |
152e283f FT |
743 | struct rq_map_data *, void __user *, unsigned long, |
744 | gfp_t); | |
8e5cfc45 | 745 | extern int blk_rq_unmap_user(struct bio *); |
165125e1 JA |
746 | extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t); |
747 | extern int blk_rq_map_user_iov(struct request_queue *, struct request *, | |
152e283f FT |
748 | struct rq_map_data *, struct sg_iovec *, int, |
749 | unsigned int, gfp_t); | |
165125e1 | 750 | extern int blk_execute_rq(struct request_queue *, struct gendisk *, |
994ca9a1 | 751 | struct request *, int); |
165125e1 | 752 | extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *, |
15fc858a | 753 | struct request *, int, rq_end_io_fn *); |
6e39b69e | 754 | |
165125e1 | 755 | static inline struct request_queue *bdev_get_queue(struct block_device *bdev) |
1da177e4 LT |
756 | { |
757 | return bdev->bd_disk->queue; | |
758 | } | |
759 | ||
5efccd17 | 760 | /* |
80a761fd TH |
761 | * blk_rq_pos() : the current sector |
762 | * blk_rq_bytes() : bytes left in the entire request | |
763 | * blk_rq_cur_bytes() : bytes left in the current segment | |
764 | * blk_rq_err_bytes() : bytes left till the next error boundary | |
765 | * blk_rq_sectors() : sectors left in the entire request | |
766 | * blk_rq_cur_sectors() : sectors left in the current segment | |
5efccd17 | 767 | */ |
5b93629b TH |
768 | static inline sector_t blk_rq_pos(const struct request *rq) |
769 | { | |
a2dec7b3 | 770 | return rq->__sector; |
2e46e8b2 TH |
771 | } |
772 | ||
773 | static inline unsigned int blk_rq_bytes(const struct request *rq) | |
774 | { | |
a2dec7b3 | 775 | return rq->__data_len; |
5b93629b TH |
776 | } |
777 | ||
2e46e8b2 TH |
778 | static inline int blk_rq_cur_bytes(const struct request *rq) |
779 | { | |
780 | return rq->bio ? bio_cur_bytes(rq->bio) : 0; | |
781 | } | |
5efccd17 | 782 | |
80a761fd TH |
783 | extern unsigned int blk_rq_err_bytes(const struct request *rq); |
784 | ||
5b93629b TH |
785 | static inline unsigned int blk_rq_sectors(const struct request *rq) |
786 | { | |
2e46e8b2 | 787 | return blk_rq_bytes(rq) >> 9; |
5b93629b TH |
788 | } |
789 | ||
790 | static inline unsigned int blk_rq_cur_sectors(const struct request *rq) | |
791 | { | |
2e46e8b2 | 792 | return blk_rq_cur_bytes(rq) >> 9; |
5b93629b TH |
793 | } |
794 | ||
9934c8c0 TH |
795 | /* |
796 | * Request issue related functions. | |
797 | */ | |
798 | extern struct request *blk_peek_request(struct request_queue *q); | |
799 | extern void blk_start_request(struct request *rq); | |
800 | extern struct request *blk_fetch_request(struct request_queue *q); | |
801 | ||
1da177e4 | 802 | /* |
2e60e022 TH |
803 | * Request completion related functions. |
804 | * | |
805 | * blk_update_request() completes given number of bytes and updates | |
806 | * the request without completing it. | |
807 | * | |
f06d9a2b TH |
808 | * blk_end_request() and friends. __blk_end_request() must be called |
809 | * with the request queue spinlock acquired. | |
1da177e4 LT |
810 | * |
811 | * Several drivers define their own end_request and call | |
3bcddeac KU |
812 | * blk_end_request() for parts of the original function. |
813 | * This prevents code duplication in drivers. | |
1da177e4 | 814 | */ |
2e60e022 TH |
815 | extern bool blk_update_request(struct request *rq, int error, |
816 | unsigned int nr_bytes); | |
b1f74493 FT |
817 | extern bool blk_end_request(struct request *rq, int error, |
818 | unsigned int nr_bytes); | |
819 | extern void blk_end_request_all(struct request *rq, int error); | |
820 | extern bool blk_end_request_cur(struct request *rq, int error); | |
80a761fd | 821 | extern bool blk_end_request_err(struct request *rq, int error); |
b1f74493 FT |
822 | extern bool __blk_end_request(struct request *rq, int error, |
823 | unsigned int nr_bytes); | |
824 | extern void __blk_end_request_all(struct request *rq, int error); | |
825 | extern bool __blk_end_request_cur(struct request *rq, int error); | |
80a761fd | 826 | extern bool __blk_end_request_err(struct request *rq, int error); |
2e60e022 | 827 | |
ff856bad | 828 | extern void blk_complete_request(struct request *); |
242f9dcb JA |
829 | extern void __blk_complete_request(struct request *); |
830 | extern void blk_abort_request(struct request *); | |
28018c24 | 831 | extern void blk_unprep_request(struct request *); |
ff856bad | 832 | |
1da177e4 LT |
833 | /* |
834 | * Access functions for manipulating queue properties | |
835 | */ | |
165125e1 | 836 | extern struct request_queue *blk_init_queue_node(request_fn_proc *rfn, |
1946089a | 837 | spinlock_t *lock, int node_id); |
165125e1 | 838 | extern struct request_queue *blk_init_queue(request_fn_proc *, spinlock_t *); |
01effb0d MS |
839 | extern struct request_queue *blk_init_allocated_queue(struct request_queue *, |
840 | request_fn_proc *, spinlock_t *); | |
165125e1 JA |
841 | extern void blk_cleanup_queue(struct request_queue *); |
842 | extern void blk_queue_make_request(struct request_queue *, make_request_fn *); | |
843 | extern void blk_queue_bounce_limit(struct request_queue *, u64); | |
72d4cd9f | 844 | extern void blk_limits_max_hw_sectors(struct queue_limits *, unsigned int); |
086fa5ff | 845 | extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int); |
8a78362c | 846 | extern void blk_queue_max_segments(struct request_queue *, unsigned short); |
165125e1 | 847 | extern void blk_queue_max_segment_size(struct request_queue *, unsigned int); |
67efc925 CH |
848 | extern void blk_queue_max_discard_sectors(struct request_queue *q, |
849 | unsigned int max_discard_sectors); | |
e1defc4f | 850 | extern void blk_queue_logical_block_size(struct request_queue *, unsigned short); |
892b6f90 | 851 | extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); |
c72758f3 MP |
852 | extern void blk_queue_alignment_offset(struct request_queue *q, |
853 | unsigned int alignment); | |
7c958e32 | 854 | extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min); |
c72758f3 | 855 | extern void blk_queue_io_min(struct request_queue *q, unsigned int min); |
3c5820c7 | 856 | extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt); |
c72758f3 | 857 | extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt); |
e475bba2 | 858 | extern void blk_set_default_limits(struct queue_limits *lim); |
b1bd055d | 859 | extern void blk_set_stacking_limits(struct queue_limits *lim); |
c72758f3 MP |
860 | extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, |
861 | sector_t offset); | |
17be8c24 MP |
862 | extern int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev, |
863 | sector_t offset); | |
c72758f3 MP |
864 | extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, |
865 | sector_t offset); | |
165125e1 | 866 | extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b); |
e3790c7d | 867 | extern void blk_queue_dma_pad(struct request_queue *, unsigned int); |
27f8221a | 868 | extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int); |
2fb98e84 TH |
869 | extern int blk_queue_dma_drain(struct request_queue *q, |
870 | dma_drain_needed_fn *dma_drain_needed, | |
871 | void *buf, unsigned int size); | |
ef9e3fac | 872 | extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn); |
165125e1 JA |
873 | extern void blk_queue_segment_boundary(struct request_queue *, unsigned long); |
874 | extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn); | |
28018c24 | 875 | extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn); |
165125e1 JA |
876 | extern void blk_queue_merge_bvec(struct request_queue *, merge_bvec_fn *); |
877 | extern void blk_queue_dma_alignment(struct request_queue *, int); | |
11c3e689 | 878 | extern void blk_queue_update_dma_alignment(struct request_queue *, int); |
165125e1 | 879 | extern void blk_queue_softirq_done(struct request_queue *, softirq_done_fn *); |
242f9dcb JA |
880 | extern void blk_queue_rq_timed_out(struct request_queue *, rq_timed_out_fn *); |
881 | extern void blk_queue_rq_timeout(struct request_queue *, unsigned int); | |
4913efe4 | 882 | extern void blk_queue_flush(struct request_queue *q, unsigned int flush); |
f3876930 | 883 | extern void blk_queue_flush_queueable(struct request_queue *q, bool queueable); |
1da177e4 | 884 | extern struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev); |
1da177e4 | 885 | |
165125e1 | 886 | extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatterlist *); |
1da177e4 | 887 | extern void blk_dump_rq_flags(struct request *, char *); |
1da177e4 | 888 | extern long nr_blockdev_pages(void); |
1da177e4 | 889 | |
09ac46c4 | 890 | bool __must_check blk_get_queue(struct request_queue *); |
165125e1 JA |
891 | struct request_queue *blk_alloc_queue(gfp_t); |
892 | struct request_queue *blk_alloc_queue_node(gfp_t, int); | |
893 | extern void blk_put_queue(struct request_queue *); | |
1da177e4 | 894 | |
316cc67d | 895 | /* |
75df7136 SJ |
896 | * blk_plug permits building a queue of related requests by holding the I/O |
897 | * fragments for a short period. This allows merging of sequential requests | |
898 | * into single larger request. As the requests are moved from a per-task list to | |
899 | * the device's request_queue in a batch, this results in improved scalability | |
900 | * as the lock contention for request_queue lock is reduced. | |
901 | * | |
902 | * It is ok not to disable preemption when adding the request to the plug list | |
903 | * or when attempting a merge, because blk_schedule_flush_list() will only flush | |
904 | * the plug list when the task sleeps by itself. For details, please see | |
905 | * schedule() where blk_schedule_flush_plug() is called. | |
316cc67d | 906 | */ |
73c10101 | 907 | struct blk_plug { |
75df7136 SJ |
908 | unsigned long magic; /* detect uninitialized use-cases */ |
909 | struct list_head list; /* requests */ | |
910 | struct list_head cb_list; /* md requires an unplug callback */ | |
911 | unsigned int should_sort; /* list to be sorted before flushing? */ | |
73c10101 | 912 | }; |
55c022bb SL |
913 | #define BLK_MAX_REQUEST_COUNT 16 |
914 | ||
048c9374 N |
915 | struct blk_plug_cb { |
916 | struct list_head list; | |
917 | void (*callback)(struct blk_plug_cb *); | |
918 | }; | |
73c10101 JA |
919 | |
920 | extern void blk_start_plug(struct blk_plug *); | |
921 | extern void blk_finish_plug(struct blk_plug *); | |
f6603783 | 922 | extern void blk_flush_plug_list(struct blk_plug *, bool); |
73c10101 JA |
923 | |
924 | static inline void blk_flush_plug(struct task_struct *tsk) | |
925 | { | |
926 | struct blk_plug *plug = tsk->plug; | |
927 | ||
a237c1c5 JA |
928 | if (plug) |
929 | blk_flush_plug_list(plug, false); | |
930 | } | |
931 | ||
932 | static inline void blk_schedule_flush_plug(struct task_struct *tsk) | |
933 | { | |
934 | struct blk_plug *plug = tsk->plug; | |
935 | ||
88b996cd | 936 | if (plug) |
f6603783 | 937 | blk_flush_plug_list(plug, true); |
73c10101 JA |
938 | } |
939 | ||
940 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) | |
941 | { | |
942 | struct blk_plug *plug = tsk->plug; | |
943 | ||
048c9374 | 944 | return plug && (!list_empty(&plug->list) || !list_empty(&plug->cb_list)); |
73c10101 JA |
945 | } |
946 | ||
1da177e4 LT |
947 | /* |
948 | * tag stuff | |
949 | */ | |
4aff5e23 | 950 | #define blk_rq_tagged(rq) ((rq)->cmd_flags & REQ_QUEUED) |
165125e1 JA |
951 | extern int blk_queue_start_tag(struct request_queue *, struct request *); |
952 | extern struct request *blk_queue_find_tag(struct request_queue *, int); | |
953 | extern void blk_queue_end_tag(struct request_queue *, struct request *); | |
954 | extern int blk_queue_init_tags(struct request_queue *, int, struct blk_queue_tag *); | |
955 | extern void blk_queue_free_tags(struct request_queue *); | |
956 | extern int blk_queue_resize_tags(struct request_queue *, int); | |
957 | extern void blk_queue_invalidate_tags(struct request_queue *); | |
492dfb48 JB |
958 | extern struct blk_queue_tag *blk_init_tags(int); |
959 | extern void blk_free_tags(struct blk_queue_tag *); | |
1da177e4 | 960 | |
f583f492 DS |
961 | static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt, |
962 | int tag) | |
963 | { | |
964 | if (unlikely(bqt == NULL || tag >= bqt->real_max_depth)) | |
965 | return NULL; | |
966 | return bqt->tag_index[tag]; | |
967 | } | |
dd3932ed CH |
968 | |
969 | #define BLKDEV_DISCARD_SECURE 0x01 /* secure discard */ | |
970 | ||
971 | extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *); | |
fbd9b09a DM |
972 | extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector, |
973 | sector_t nr_sects, gfp_t gfp_mask, unsigned long flags); | |
3f14d792 | 974 | extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
dd3932ed | 975 | sector_t nr_sects, gfp_t gfp_mask); |
2cf6d26a CH |
976 | static inline int sb_issue_discard(struct super_block *sb, sector_t block, |
977 | sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags) | |
fb2dce86 | 978 | { |
2cf6d26a CH |
979 | return blkdev_issue_discard(sb->s_bdev, block << (sb->s_blocksize_bits - 9), |
980 | nr_blocks << (sb->s_blocksize_bits - 9), | |
981 | gfp_mask, flags); | |
fb2dce86 | 982 | } |
e6fa0be6 | 983 | static inline int sb_issue_zeroout(struct super_block *sb, sector_t block, |
a107e5a3 | 984 | sector_t nr_blocks, gfp_t gfp_mask) |
e6fa0be6 LC |
985 | { |
986 | return blkdev_issue_zeroout(sb->s_bdev, | |
987 | block << (sb->s_blocksize_bits - 9), | |
988 | nr_blocks << (sb->s_blocksize_bits - 9), | |
a107e5a3 | 989 | gfp_mask); |
e6fa0be6 | 990 | } |
1da177e4 | 991 | |
018e0446 | 992 | extern int blk_verify_command(unsigned char *cmd, fmode_t has_write_perm); |
0b07de85 | 993 | |
eb28d31b MP |
994 | enum blk_default_limits { |
995 | BLK_MAX_SEGMENTS = 128, | |
996 | BLK_SAFE_MAX_SECTORS = 255, | |
997 | BLK_DEF_MAX_SECTORS = 1024, | |
998 | BLK_MAX_SEGMENT_SIZE = 65536, | |
999 | BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL, | |
1000 | }; | |
0e435ac2 | 1001 | |
1da177e4 LT |
1002 | #define blkdev_entry_to_request(entry) list_entry((entry), struct request, queuelist) |
1003 | ||
ae03bf63 MP |
1004 | static inline unsigned long queue_bounce_pfn(struct request_queue *q) |
1005 | { | |
025146e1 | 1006 | return q->limits.bounce_pfn; |
ae03bf63 MP |
1007 | } |
1008 | ||
1009 | static inline unsigned long queue_segment_boundary(struct request_queue *q) | |
1010 | { | |
025146e1 | 1011 | return q->limits.seg_boundary_mask; |
ae03bf63 MP |
1012 | } |
1013 | ||
1014 | static inline unsigned int queue_max_sectors(struct request_queue *q) | |
1015 | { | |
025146e1 | 1016 | return q->limits.max_sectors; |
ae03bf63 MP |
1017 | } |
1018 | ||
1019 | static inline unsigned int queue_max_hw_sectors(struct request_queue *q) | |
1020 | { | |
025146e1 | 1021 | return q->limits.max_hw_sectors; |
ae03bf63 MP |
1022 | } |
1023 | ||
8a78362c | 1024 | static inline unsigned short queue_max_segments(struct request_queue *q) |
ae03bf63 | 1025 | { |
8a78362c | 1026 | return q->limits.max_segments; |
ae03bf63 MP |
1027 | } |
1028 | ||
1029 | static inline unsigned int queue_max_segment_size(struct request_queue *q) | |
1030 | { | |
025146e1 | 1031 | return q->limits.max_segment_size; |
ae03bf63 MP |
1032 | } |
1033 | ||
e1defc4f | 1034 | static inline unsigned short queue_logical_block_size(struct request_queue *q) |
1da177e4 LT |
1035 | { |
1036 | int retval = 512; | |
1037 | ||
025146e1 MP |
1038 | if (q && q->limits.logical_block_size) |
1039 | retval = q->limits.logical_block_size; | |
1da177e4 LT |
1040 | |
1041 | return retval; | |
1042 | } | |
1043 | ||
e1defc4f | 1044 | static inline unsigned short bdev_logical_block_size(struct block_device *bdev) |
1da177e4 | 1045 | { |
e1defc4f | 1046 | return queue_logical_block_size(bdev_get_queue(bdev)); |
1da177e4 LT |
1047 | } |
1048 | ||
c72758f3 MP |
1049 | static inline unsigned int queue_physical_block_size(struct request_queue *q) |
1050 | { | |
1051 | return q->limits.physical_block_size; | |
1052 | } | |
1053 | ||
892b6f90 | 1054 | static inline unsigned int bdev_physical_block_size(struct block_device *bdev) |
ac481c20 MP |
1055 | { |
1056 | return queue_physical_block_size(bdev_get_queue(bdev)); | |
1057 | } | |
1058 | ||
c72758f3 MP |
1059 | static inline unsigned int queue_io_min(struct request_queue *q) |
1060 | { | |
1061 | return q->limits.io_min; | |
1062 | } | |
1063 | ||
ac481c20 MP |
1064 | static inline int bdev_io_min(struct block_device *bdev) |
1065 | { | |
1066 | return queue_io_min(bdev_get_queue(bdev)); | |
1067 | } | |
1068 | ||
c72758f3 MP |
1069 | static inline unsigned int queue_io_opt(struct request_queue *q) |
1070 | { | |
1071 | return q->limits.io_opt; | |
1072 | } | |
1073 | ||
ac481c20 MP |
1074 | static inline int bdev_io_opt(struct block_device *bdev) |
1075 | { | |
1076 | return queue_io_opt(bdev_get_queue(bdev)); | |
1077 | } | |
1078 | ||
c72758f3 MP |
1079 | static inline int queue_alignment_offset(struct request_queue *q) |
1080 | { | |
ac481c20 | 1081 | if (q->limits.misaligned) |
c72758f3 MP |
1082 | return -1; |
1083 | ||
ac481c20 | 1084 | return q->limits.alignment_offset; |
c72758f3 MP |
1085 | } |
1086 | ||
e03a72e1 | 1087 | static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector) |
81744ee4 MP |
1088 | { |
1089 | unsigned int granularity = max(lim->physical_block_size, lim->io_min); | |
e03a72e1 | 1090 | unsigned int alignment = (sector << 9) & (granularity - 1); |
81744ee4 | 1091 | |
e03a72e1 MP |
1092 | return (granularity + lim->alignment_offset - alignment) |
1093 | & (granularity - 1); | |
c72758f3 MP |
1094 | } |
1095 | ||
ac481c20 MP |
1096 | static inline int bdev_alignment_offset(struct block_device *bdev) |
1097 | { | |
1098 | struct request_queue *q = bdev_get_queue(bdev); | |
1099 | ||
1100 | if (q->limits.misaligned) | |
1101 | return -1; | |
1102 | ||
1103 | if (bdev != bdev->bd_contains) | |
1104 | return bdev->bd_part->alignment_offset; | |
1105 | ||
1106 | return q->limits.alignment_offset; | |
1107 | } | |
1108 | ||
86b37281 MP |
1109 | static inline int queue_discard_alignment(struct request_queue *q) |
1110 | { | |
1111 | if (q->limits.discard_misaligned) | |
1112 | return -1; | |
1113 | ||
1114 | return q->limits.discard_alignment; | |
1115 | } | |
1116 | ||
e03a72e1 | 1117 | static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector) |
86b37281 | 1118 | { |
dd3d145d MP |
1119 | unsigned int alignment = (sector << 9) & (lim->discard_granularity - 1); |
1120 | ||
a934a00a MP |
1121 | if (!lim->max_discard_sectors) |
1122 | return 0; | |
1123 | ||
dd3d145d MP |
1124 | return (lim->discard_granularity + lim->discard_alignment - alignment) |
1125 | & (lim->discard_granularity - 1); | |
86b37281 MP |
1126 | } |
1127 | ||
98262f27 MP |
1128 | static inline unsigned int queue_discard_zeroes_data(struct request_queue *q) |
1129 | { | |
a934a00a | 1130 | if (q->limits.max_discard_sectors && q->limits.discard_zeroes_data == 1) |
98262f27 MP |
1131 | return 1; |
1132 | ||
1133 | return 0; | |
1134 | } | |
1135 | ||
1136 | static inline unsigned int bdev_discard_zeroes_data(struct block_device *bdev) | |
1137 | { | |
1138 | return queue_discard_zeroes_data(bdev_get_queue(bdev)); | |
1139 | } | |
1140 | ||
165125e1 | 1141 | static inline int queue_dma_alignment(struct request_queue *q) |
1da177e4 | 1142 | { |
482eb689 | 1143 | return q ? q->dma_alignment : 511; |
1da177e4 LT |
1144 | } |
1145 | ||
14417799 | 1146 | static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr, |
87904074 FT |
1147 | unsigned int len) |
1148 | { | |
1149 | unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask; | |
14417799 | 1150 | return !(addr & alignment) && !(len & alignment); |
87904074 FT |
1151 | } |
1152 | ||
1da177e4 LT |
1153 | /* assumes size > 256 */ |
1154 | static inline unsigned int blksize_bits(unsigned int size) | |
1155 | { | |
1156 | unsigned int bits = 8; | |
1157 | do { | |
1158 | bits++; | |
1159 | size >>= 1; | |
1160 | } while (size > 256); | |
1161 | return bits; | |
1162 | } | |
1163 | ||
2befb9e3 | 1164 | static inline unsigned int block_size(struct block_device *bdev) |
1da177e4 LT |
1165 | { |
1166 | return bdev->bd_block_size; | |
1167 | } | |
1168 | ||
f3876930 | 1169 | static inline bool queue_flush_queueable(struct request_queue *q) |
1170 | { | |
1171 | return !q->flush_not_queueable; | |
1172 | } | |
1173 | ||
1da177e4 LT |
1174 | typedef struct {struct page *v;} Sector; |
1175 | ||
1176 | unsigned char *read_dev_sector(struct block_device *, sector_t, Sector *); | |
1177 | ||
1178 | static inline void put_dev_sector(Sector p) | |
1179 | { | |
1180 | page_cache_release(p.v); | |
1181 | } | |
1182 | ||
1183 | struct work_struct; | |
18887ad9 | 1184 | int kblockd_schedule_work(struct request_queue *q, struct work_struct *work); |
1da177e4 | 1185 | |
9195291e | 1186 | #ifdef CONFIG_BLK_CGROUP |
28f4197e JA |
1187 | /* |
1188 | * This should not be using sched_clock(). A real patch is in progress | |
1189 | * to fix this up, until that is in place we need to disable preemption | |
1190 | * around sched_clock() in this function and set_io_start_time_ns(). | |
1191 | */ | |
9195291e DS |
1192 | static inline void set_start_time_ns(struct request *req) |
1193 | { | |
28f4197e | 1194 | preempt_disable(); |
9195291e | 1195 | req->start_time_ns = sched_clock(); |
28f4197e | 1196 | preempt_enable(); |
9195291e DS |
1197 | } |
1198 | ||
1199 | static inline void set_io_start_time_ns(struct request *req) | |
1200 | { | |
28f4197e | 1201 | preempt_disable(); |
9195291e | 1202 | req->io_start_time_ns = sched_clock(); |
28f4197e | 1203 | preempt_enable(); |
9195291e | 1204 | } |
84c124da DS |
1205 | |
1206 | static inline uint64_t rq_start_time_ns(struct request *req) | |
1207 | { | |
1208 | return req->start_time_ns; | |
1209 | } | |
1210 | ||
1211 | static inline uint64_t rq_io_start_time_ns(struct request *req) | |
1212 | { | |
1213 | return req->io_start_time_ns; | |
1214 | } | |
9195291e DS |
1215 | #else |
1216 | static inline void set_start_time_ns(struct request *req) {} | |
1217 | static inline void set_io_start_time_ns(struct request *req) {} | |
84c124da DS |
1218 | static inline uint64_t rq_start_time_ns(struct request *req) |
1219 | { | |
1220 | return 0; | |
1221 | } | |
1222 | static inline uint64_t rq_io_start_time_ns(struct request *req) | |
1223 | { | |
1224 | return 0; | |
1225 | } | |
9195291e DS |
1226 | #endif |
1227 | ||
1da177e4 LT |
1228 | #define MODULE_ALIAS_BLOCKDEV(major,minor) \ |
1229 | MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor)) | |
1230 | #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \ | |
1231 | MODULE_ALIAS("block-major-" __stringify(major) "-*") | |
1232 | ||
7ba1ba12 MP |
1233 | #if defined(CONFIG_BLK_DEV_INTEGRITY) |
1234 | ||
b24498d4 JA |
1235 | #define INTEGRITY_FLAG_READ 2 /* verify data integrity on read */ |
1236 | #define INTEGRITY_FLAG_WRITE 4 /* generate data integrity on write */ | |
7ba1ba12 MP |
1237 | |
1238 | struct blk_integrity_exchg { | |
1239 | void *prot_buf; | |
1240 | void *data_buf; | |
1241 | sector_t sector; | |
1242 | unsigned int data_size; | |
1243 | unsigned short sector_size; | |
1244 | const char *disk_name; | |
1245 | }; | |
1246 | ||
1247 | typedef void (integrity_gen_fn) (struct blk_integrity_exchg *); | |
1248 | typedef int (integrity_vrfy_fn) (struct blk_integrity_exchg *); | |
1249 | typedef void (integrity_set_tag_fn) (void *, void *, unsigned int); | |
1250 | typedef void (integrity_get_tag_fn) (void *, void *, unsigned int); | |
1251 | ||
1252 | struct blk_integrity { | |
1253 | integrity_gen_fn *generate_fn; | |
1254 | integrity_vrfy_fn *verify_fn; | |
1255 | integrity_set_tag_fn *set_tag_fn; | |
1256 | integrity_get_tag_fn *get_tag_fn; | |
1257 | ||
1258 | unsigned short flags; | |
1259 | unsigned short tuple_size; | |
1260 | unsigned short sector_size; | |
1261 | unsigned short tag_size; | |
1262 | ||
1263 | const char *name; | |
1264 | ||
1265 | struct kobject kobj; | |
1266 | }; | |
1267 | ||
a63a5cf8 | 1268 | extern bool blk_integrity_is_initialized(struct gendisk *); |
7ba1ba12 MP |
1269 | extern int blk_integrity_register(struct gendisk *, struct blk_integrity *); |
1270 | extern void blk_integrity_unregister(struct gendisk *); | |
ad7fce93 | 1271 | extern int blk_integrity_compare(struct gendisk *, struct gendisk *); |
13f05c8d MP |
1272 | extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *, |
1273 | struct scatterlist *); | |
1274 | extern int blk_rq_count_integrity_sg(struct request_queue *, struct bio *); | |
1275 | extern int blk_integrity_merge_rq(struct request_queue *, struct request *, | |
1276 | struct request *); | |
1277 | extern int blk_integrity_merge_bio(struct request_queue *, struct request *, | |
1278 | struct bio *); | |
7ba1ba12 | 1279 | |
b04accc4 JA |
1280 | static inline |
1281 | struct blk_integrity *bdev_get_integrity(struct block_device *bdev) | |
1282 | { | |
1283 | return bdev->bd_disk->integrity; | |
1284 | } | |
1285 | ||
b02739b0 MP |
1286 | static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) |
1287 | { | |
1288 | return disk->integrity; | |
1289 | } | |
1290 | ||
7ba1ba12 MP |
1291 | static inline int blk_integrity_rq(struct request *rq) |
1292 | { | |
d442cc44 MP |
1293 | if (rq->bio == NULL) |
1294 | return 0; | |
1295 | ||
7ba1ba12 MP |
1296 | return bio_integrity(rq->bio); |
1297 | } | |
1298 | ||
13f05c8d MP |
1299 | static inline void blk_queue_max_integrity_segments(struct request_queue *q, |
1300 | unsigned int segs) | |
1301 | { | |
1302 | q->limits.max_integrity_segments = segs; | |
1303 | } | |
1304 | ||
1305 | static inline unsigned short | |
1306 | queue_max_integrity_segments(struct request_queue *q) | |
1307 | { | |
1308 | return q->limits.max_integrity_segments; | |
1309 | } | |
1310 | ||
7ba1ba12 MP |
1311 | #else /* CONFIG_BLK_DEV_INTEGRITY */ |
1312 | ||
fd83240a SR |
1313 | struct bio; |
1314 | struct block_device; | |
1315 | struct gendisk; | |
1316 | struct blk_integrity; | |
1317 | ||
1318 | static inline int blk_integrity_rq(struct request *rq) | |
1319 | { | |
1320 | return 0; | |
1321 | } | |
1322 | static inline int blk_rq_count_integrity_sg(struct request_queue *q, | |
1323 | struct bio *b) | |
1324 | { | |
1325 | return 0; | |
1326 | } | |
1327 | static inline int blk_rq_map_integrity_sg(struct request_queue *q, | |
1328 | struct bio *b, | |
1329 | struct scatterlist *s) | |
1330 | { | |
1331 | return 0; | |
1332 | } | |
1333 | static inline struct blk_integrity *bdev_get_integrity(struct block_device *b) | |
1334 | { | |
1335 | return 0; | |
1336 | } | |
1337 | static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) | |
1338 | { | |
1339 | return NULL; | |
1340 | } | |
1341 | static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b) | |
1342 | { | |
1343 | return 0; | |
1344 | } | |
1345 | static inline int blk_integrity_register(struct gendisk *d, | |
1346 | struct blk_integrity *b) | |
1347 | { | |
1348 | return 0; | |
1349 | } | |
1350 | static inline void blk_integrity_unregister(struct gendisk *d) | |
1351 | { | |
1352 | } | |
1353 | static inline void blk_queue_max_integrity_segments(struct request_queue *q, | |
1354 | unsigned int segs) | |
1355 | { | |
1356 | } | |
1357 | static inline unsigned short queue_max_integrity_segments(struct request_queue *q) | |
1358 | { | |
1359 | return 0; | |
1360 | } | |
1361 | static inline int blk_integrity_merge_rq(struct request_queue *rq, | |
1362 | struct request *r1, | |
1363 | struct request *r2) | |
1364 | { | |
1365 | return 0; | |
1366 | } | |
1367 | static inline int blk_integrity_merge_bio(struct request_queue *rq, | |
1368 | struct request *r, | |
1369 | struct bio *b) | |
1370 | { | |
1371 | return 0; | |
1372 | } | |
1373 | static inline bool blk_integrity_is_initialized(struct gendisk *g) | |
1374 | { | |
1375 | return 0; | |
1376 | } | |
7ba1ba12 MP |
1377 | |
1378 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ | |
1379 | ||
08f85851 | 1380 | struct block_device_operations { |
d4430d62 AV |
1381 | int (*open) (struct block_device *, fmode_t); |
1382 | int (*release) (struct gendisk *, fmode_t); | |
d4430d62 AV |
1383 | int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); |
1384 | int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); | |
08f85851 AV |
1385 | int (*direct_access) (struct block_device *, sector_t, |
1386 | void **, unsigned long *); | |
77ea887e TH |
1387 | unsigned int (*check_events) (struct gendisk *disk, |
1388 | unsigned int clearing); | |
1389 | /* ->media_changed() is DEPRECATED, use ->check_events() instead */ | |
08f85851 | 1390 | int (*media_changed) (struct gendisk *); |
c3e33e04 | 1391 | void (*unlock_native_capacity) (struct gendisk *); |
08f85851 AV |
1392 | int (*revalidate_disk) (struct gendisk *); |
1393 | int (*getgeo)(struct block_device *, struct hd_geometry *); | |
b3a27d05 NG |
1394 | /* this callback is with swap_lock and sometimes page table lock held */ |
1395 | void (*swap_slot_free_notify) (struct block_device *, unsigned long); | |
08f85851 AV |
1396 | struct module *owner; |
1397 | }; | |
1398 | ||
633a08b8 AV |
1399 | extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int, |
1400 | unsigned long); | |
9361401e DH |
1401 | #else /* CONFIG_BLOCK */ |
1402 | /* | |
1403 | * stubs for when the block layer is configured out | |
1404 | */ | |
1405 | #define buffer_heads_over_limit 0 | |
1406 | ||
9361401e DH |
1407 | static inline long nr_blockdev_pages(void) |
1408 | { | |
1409 | return 0; | |
1410 | } | |
1411 | ||
1f940bdf JA |
1412 | struct blk_plug { |
1413 | }; | |
1414 | ||
1415 | static inline void blk_start_plug(struct blk_plug *plug) | |
73c10101 JA |
1416 | { |
1417 | } | |
1418 | ||
1f940bdf | 1419 | static inline void blk_finish_plug(struct blk_plug *plug) |
73c10101 JA |
1420 | { |
1421 | } | |
1422 | ||
1f940bdf | 1423 | static inline void blk_flush_plug(struct task_struct *task) |
73c10101 JA |
1424 | { |
1425 | } | |
1426 | ||
a237c1c5 JA |
1427 | static inline void blk_schedule_flush_plug(struct task_struct *task) |
1428 | { | |
1429 | } | |
1430 | ||
1431 | ||
73c10101 JA |
1432 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) |
1433 | { | |
1434 | return false; | |
1435 | } | |
1436 | ||
9361401e DH |
1437 | #endif /* CONFIG_BLOCK */ |
1438 | ||
1da177e4 | 1439 | #endif |