block: kill rq->data
[safe/jmp/linux-2.6] / include / linux / blkdev.h
1 #ifndef _LINUX_BLKDEV_H
2 #define _LINUX_BLKDEV_H
3
4 #ifdef CONFIG_BLOCK
5
6 #include <linux/sched.h>
7 #include <linux/major.h>
8 #include <linux/genhd.h>
9 #include <linux/list.h>
10 #include <linux/timer.h>
11 #include <linux/workqueue.h>
12 #include <linux/pagemap.h>
13 #include <linux/backing-dev.h>
14 #include <linux/wait.h>
15 #include <linux/mempool.h>
16 #include <linux/bio.h>
17 #include <linux/module.h>
18 #include <linux/stringify.h>
19 #include <linux/gfp.h>
20 #include <linux/bsg.h>
21 #include <linux/smp.h>
22
23 #include <asm/scatterlist.h>
24
25 struct scsi_ioctl_command;
26
27 struct request_queue;
28 struct elevator_queue;
29 struct request_pm_state;
30 struct blk_trace;
31 struct request;
32 struct sg_io_hdr;
33
34 #define BLKDEV_MIN_RQ   4
35 #define BLKDEV_MAX_RQ   128     /* Default maximum */
36
37 struct request;
38 typedef void (rq_end_io_fn)(struct request *, int);
39
40 struct request_list {
41         /*
42          * count[], starved[], and wait[] are indexed by
43          * BLK_RW_SYNC/BLK_RW_ASYNC
44          */
45         int count[2];
46         int starved[2];
47         int elvpriv;
48         mempool_t *rq_pool;
49         wait_queue_head_t wait[2];
50 };
51
52 /*
53  * request command types
54  */
55 enum rq_cmd_type_bits {
56         REQ_TYPE_FS             = 1,    /* fs request */
57         REQ_TYPE_BLOCK_PC,              /* scsi command */
58         REQ_TYPE_SENSE,                 /* sense request */
59         REQ_TYPE_PM_SUSPEND,            /* suspend request */
60         REQ_TYPE_PM_RESUME,             /* resume request */
61         REQ_TYPE_PM_SHUTDOWN,           /* shutdown request */
62         REQ_TYPE_SPECIAL,               /* driver defined type */
63         REQ_TYPE_LINUX_BLOCK,           /* generic block layer message */
64         /*
65          * for ATA/ATAPI devices. this really doesn't belong here, ide should
66          * use REQ_TYPE_SPECIAL and use rq->cmd[0] with the range of driver
67          * private REQ_LB opcodes to differentiate what type of request this is
68          */
69         REQ_TYPE_ATA_TASKFILE,
70         REQ_TYPE_ATA_PC,
71 };
72
73 enum {
74         BLK_RW_ASYNC    = 0,
75         BLK_RW_SYNC     = 1,
76 };
77
78 /*
79  * For request of type REQ_TYPE_LINUX_BLOCK, rq->cmd[0] is the opcode being
80  * sent down (similar to how REQ_TYPE_BLOCK_PC means that ->cmd[] holds a
81  * SCSI cdb.
82  *
83  * 0x00 -> 0x3f are driver private, to be used for whatever purpose they need,
84  * typically to differentiate REQ_TYPE_SPECIAL requests.
85  *
86  */
87 enum {
88         REQ_LB_OP_EJECT = 0x40,         /* eject request */
89         REQ_LB_OP_FLUSH = 0x41,         /* flush request */
90         REQ_LB_OP_DISCARD = 0x42,       /* discard sectors */
91 };
92
93 /*
94  * request type modified bits. first two bits match BIO_RW* bits, important
95  */
96 enum rq_flag_bits {
97         __REQ_RW,               /* not set, read. set, write */
98         __REQ_FAILFAST_DEV,     /* no driver retries of device errors */
99         __REQ_FAILFAST_TRANSPORT, /* no driver retries of transport errors */
100         __REQ_FAILFAST_DRIVER,  /* no driver retries of driver errors */
101         __REQ_DISCARD,          /* request to discard sectors */
102         __REQ_SORTED,           /* elevator knows about this request */
103         __REQ_SOFTBARRIER,      /* may not be passed by ioscheduler */
104         __REQ_HARDBARRIER,      /* may not be passed by drive either */
105         __REQ_FUA,              /* forced unit access */
106         __REQ_NOMERGE,          /* don't touch this for merging */
107         __REQ_STARTED,          /* drive already may have started this one */
108         __REQ_DONTPREP,         /* don't call prep for this one */
109         __REQ_QUEUED,           /* uses queueing */
110         __REQ_ELVPRIV,          /* elevator private data attached */
111         __REQ_FAILED,           /* set if the request failed */
112         __REQ_QUIET,            /* don't worry about errors */
113         __REQ_PREEMPT,          /* set for "ide_preempt" requests */
114         __REQ_ORDERED_COLOR,    /* is before or after barrier */
115         __REQ_RW_SYNC,          /* request is sync (sync write or read) */
116         __REQ_ALLOCED,          /* request came from our alloc pool */
117         __REQ_RW_META,          /* metadata io request */
118         __REQ_COPY_USER,        /* contains copies of user pages */
119         __REQ_INTEGRITY,        /* integrity metadata has been remapped */
120         __REQ_NOIDLE,           /* Don't anticipate more IO after this one */
121         __REQ_IO_STAT,          /* account I/O stat */
122         __REQ_NR_BITS,          /* stops here */
123 };
124
125 #define REQ_RW          (1 << __REQ_RW)
126 #define REQ_FAILFAST_DEV        (1 << __REQ_FAILFAST_DEV)
127 #define REQ_FAILFAST_TRANSPORT  (1 << __REQ_FAILFAST_TRANSPORT)
128 #define REQ_FAILFAST_DRIVER     (1 << __REQ_FAILFAST_DRIVER)
129 #define REQ_DISCARD     (1 << __REQ_DISCARD)
130 #define REQ_SORTED      (1 << __REQ_SORTED)
131 #define REQ_SOFTBARRIER (1 << __REQ_SOFTBARRIER)
132 #define REQ_HARDBARRIER (1 << __REQ_HARDBARRIER)
133 #define REQ_FUA         (1 << __REQ_FUA)
134 #define REQ_NOMERGE     (1 << __REQ_NOMERGE)
135 #define REQ_STARTED     (1 << __REQ_STARTED)
136 #define REQ_DONTPREP    (1 << __REQ_DONTPREP)
137 #define REQ_QUEUED      (1 << __REQ_QUEUED)
138 #define REQ_ELVPRIV     (1 << __REQ_ELVPRIV)
139 #define REQ_FAILED      (1 << __REQ_FAILED)
140 #define REQ_QUIET       (1 << __REQ_QUIET)
141 #define REQ_PREEMPT     (1 << __REQ_PREEMPT)
142 #define REQ_ORDERED_COLOR       (1 << __REQ_ORDERED_COLOR)
143 #define REQ_RW_SYNC     (1 << __REQ_RW_SYNC)
144 #define REQ_ALLOCED     (1 << __REQ_ALLOCED)
145 #define REQ_RW_META     (1 << __REQ_RW_META)
146 #define REQ_COPY_USER   (1 << __REQ_COPY_USER)
147 #define REQ_INTEGRITY   (1 << __REQ_INTEGRITY)
148 #define REQ_NOIDLE      (1 << __REQ_NOIDLE)
149 #define REQ_IO_STAT     (1 << __REQ_IO_STAT)
150
151 #define BLK_MAX_CDB     16
152
153 /*
154  * try to put the fields that are referenced together in the same cacheline.
155  * if you modify this structure, be sure to check block/blk-core.c:rq_init()
156  * as well!
157  */
158 struct request {
159         struct list_head queuelist;
160         struct call_single_data csd;
161         int cpu;
162
163         struct request_queue *q;
164
165         unsigned int cmd_flags;
166         enum rq_cmd_type_bits cmd_type;
167         unsigned long atomic_flags;
168
169         /* Maintain bio traversal state for part by part I/O submission.
170          * hard_* are block layer internals, no driver should touch them!
171          */
172
173         sector_t sector;                /* next sector to submit */
174         sector_t hard_sector;           /* next sector to complete */
175         unsigned long nr_sectors;       /* no. of sectors left to submit */
176         unsigned long hard_nr_sectors;  /* no. of sectors left to complete */
177         /* no. of sectors left to submit in the current segment */
178         unsigned int current_nr_sectors;
179
180         /* no. of sectors left to complete in the current segment */
181         unsigned int hard_cur_sectors;
182
183         struct bio *bio;
184         struct bio *biotail;
185
186         struct hlist_node hash; /* merge hash */
187         /*
188          * The rb_node is only used inside the io scheduler, requests
189          * are pruned when moved to the dispatch queue. So let the
190          * completion_data share space with the rb_node.
191          */
192         union {
193                 struct rb_node rb_node; /* sort/lookup */
194                 void *completion_data;
195         };
196
197         /*
198          * two pointers are available for the IO schedulers, if they need
199          * more they have to dynamically allocate it.
200          */
201         void *elevator_private;
202         void *elevator_private2;
203
204         struct gendisk *rq_disk;
205         unsigned long start_time;
206
207         /* Number of scatter-gather DMA addr+len pairs after
208          * physical address coalescing is performed.
209          */
210         unsigned short nr_phys_segments;
211
212         unsigned short ioprio;
213
214         void *special;          /* opaque pointer available for LLD use */
215         char *buffer;           /* kaddr of the current segment if available */
216
217         int tag;
218         int errors;
219
220         int ref_count;
221
222         /*
223          * when request is used as a packet command carrier
224          */
225         unsigned short cmd_len;
226         unsigned char __cmd[BLK_MAX_CDB];
227         unsigned char *cmd;
228
229         unsigned int data_len;
230         unsigned int extra_len; /* length of alignment and padding */
231         unsigned int sense_len;
232         void *sense;
233
234         unsigned long deadline;
235         struct list_head timeout_list;
236         unsigned int timeout;
237         int retries;
238
239         /*
240          * completion callback.
241          */
242         rq_end_io_fn *end_io;
243         void *end_io_data;
244
245         /* for bidi */
246         struct request *next_rq;
247 };
248
249 static inline unsigned short req_get_ioprio(struct request *req)
250 {
251         return req->ioprio;
252 }
253
254 /*
255  * State information carried for REQ_TYPE_PM_SUSPEND and REQ_TYPE_PM_RESUME
256  * requests. Some step values could eventually be made generic.
257  */
258 struct request_pm_state
259 {
260         /* PM state machine step value, currently driver specific */
261         int     pm_step;
262         /* requested PM state value (S1, S2, S3, S4, ...) */
263         u32     pm_state;
264         void*   data;           /* for driver use */
265 };
266
267 #include <linux/elevator.h>
268
269 typedef void (request_fn_proc) (struct request_queue *q);
270 typedef int (make_request_fn) (struct request_queue *q, struct bio *bio);
271 typedef int (prep_rq_fn) (struct request_queue *, struct request *);
272 typedef void (unplug_fn) (struct request_queue *);
273 typedef int (prepare_discard_fn) (struct request_queue *, struct request *);
274
275 struct bio_vec;
276 struct bvec_merge_data {
277         struct block_device *bi_bdev;
278         sector_t bi_sector;
279         unsigned bi_size;
280         unsigned long bi_rw;
281 };
282 typedef int (merge_bvec_fn) (struct request_queue *, struct bvec_merge_data *,
283                              struct bio_vec *);
284 typedef void (prepare_flush_fn) (struct request_queue *, struct request *);
285 typedef void (softirq_done_fn)(struct request *);
286 typedef int (dma_drain_needed_fn)(struct request *);
287 typedef int (lld_busy_fn) (struct request_queue *q);
288
289 enum blk_eh_timer_return {
290         BLK_EH_NOT_HANDLED,
291         BLK_EH_HANDLED,
292         BLK_EH_RESET_TIMER,
293 };
294
295 typedef enum blk_eh_timer_return (rq_timed_out_fn)(struct request *);
296
297 enum blk_queue_state {
298         Queue_down,
299         Queue_up,
300 };
301
302 struct blk_queue_tag {
303         struct request **tag_index;     /* map of busy tags */
304         unsigned long *tag_map;         /* bit map of free/busy tags */
305         int busy;                       /* current depth */
306         int max_depth;                  /* what we will send to device */
307         int real_max_depth;             /* what the array can hold */
308         atomic_t refcnt;                /* map can be shared */
309 };
310
311 #define BLK_SCSI_MAX_CMDS       (256)
312 #define BLK_SCSI_CMD_PER_LONG   (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
313
314 struct blk_cmd_filter {
315         unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
316         unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
317         struct kobject kobj;
318 };
319
320 struct request_queue
321 {
322         /*
323          * Together with queue_head for cacheline sharing
324          */
325         struct list_head        queue_head;
326         struct request          *last_merge;
327         struct elevator_queue   *elevator;
328
329         /*
330          * the queue request freelist, one for reads and one for writes
331          */
332         struct request_list     rq;
333
334         request_fn_proc         *request_fn;
335         make_request_fn         *make_request_fn;
336         prep_rq_fn              *prep_rq_fn;
337         unplug_fn               *unplug_fn;
338         prepare_discard_fn      *prepare_discard_fn;
339         merge_bvec_fn           *merge_bvec_fn;
340         prepare_flush_fn        *prepare_flush_fn;
341         softirq_done_fn         *softirq_done_fn;
342         rq_timed_out_fn         *rq_timed_out_fn;
343         dma_drain_needed_fn     *dma_drain_needed;
344         lld_busy_fn             *lld_busy_fn;
345
346         /*
347          * Dispatch queue sorting
348          */
349         sector_t                end_sector;
350         struct request          *boundary_rq;
351
352         /*
353          * Auto-unplugging state
354          */
355         struct timer_list       unplug_timer;
356         int                     unplug_thresh;  /* After this many requests */
357         unsigned long           unplug_delay;   /* After this many jiffies */
358         struct work_struct      unplug_work;
359
360         struct backing_dev_info backing_dev_info;
361
362         /*
363          * The queue owner gets to use this for whatever they like.
364          * ll_rw_blk doesn't touch it.
365          */
366         void                    *queuedata;
367
368         /*
369          * queue needs bounce pages for pages above this limit
370          */
371         unsigned long           bounce_pfn;
372         gfp_t                   bounce_gfp;
373
374         /*
375          * various queue flags, see QUEUE_* below
376          */
377         unsigned long           queue_flags;
378
379         /*
380          * protects queue structures from reentrancy. ->__queue_lock should
381          * _never_ be used directly, it is queue private. always use
382          * ->queue_lock.
383          */
384         spinlock_t              __queue_lock;
385         spinlock_t              *queue_lock;
386
387         /*
388          * queue kobject
389          */
390         struct kobject kobj;
391
392         /*
393          * queue settings
394          */
395         unsigned long           nr_requests;    /* Max # of requests */
396         unsigned int            nr_congestion_on;
397         unsigned int            nr_congestion_off;
398         unsigned int            nr_batching;
399
400         unsigned int            max_sectors;
401         unsigned int            max_hw_sectors;
402         unsigned short          max_phys_segments;
403         unsigned short          max_hw_segments;
404         unsigned short          hardsect_size;
405         unsigned int            max_segment_size;
406
407         unsigned long           seg_boundary_mask;
408         void                    *dma_drain_buffer;
409         unsigned int            dma_drain_size;
410         unsigned int            dma_pad_mask;
411         unsigned int            dma_alignment;
412
413         struct blk_queue_tag    *queue_tags;
414         struct list_head        tag_busy_list;
415
416         unsigned int            nr_sorted;
417         unsigned int            in_flight;
418
419         unsigned int            rq_timeout;
420         struct timer_list       timeout;
421         struct list_head        timeout_list;
422
423         /*
424          * sg stuff
425          */
426         unsigned int            sg_timeout;
427         unsigned int            sg_reserved_size;
428         int                     node;
429 #ifdef CONFIG_BLK_DEV_IO_TRACE
430         struct blk_trace        *blk_trace;
431 #endif
432         /*
433          * reserved for flush operations
434          */
435         unsigned int            ordered, next_ordered, ordseq;
436         int                     orderr, ordcolor;
437         struct request          pre_flush_rq, bar_rq, post_flush_rq;
438         struct request          *orig_bar_rq;
439
440         struct mutex            sysfs_lock;
441
442 #if defined(CONFIG_BLK_DEV_BSG)
443         struct bsg_class_device bsg_dev;
444 #endif
445         struct blk_cmd_filter cmd_filter;
446 };
447
448 #define QUEUE_FLAG_CLUSTER      0       /* cluster several segments into 1 */
449 #define QUEUE_FLAG_QUEUED       1       /* uses generic tag queueing */
450 #define QUEUE_FLAG_STOPPED      2       /* queue is stopped */
451 #define QUEUE_FLAG_SYNCFULL     3       /* read queue has been filled */
452 #define QUEUE_FLAG_ASYNCFULL    4       /* write queue has been filled */
453 #define QUEUE_FLAG_DEAD         5       /* queue being torn down */
454 #define QUEUE_FLAG_REENTER      6       /* Re-entrancy avoidance */
455 #define QUEUE_FLAG_PLUGGED      7       /* queue is plugged */
456 #define QUEUE_FLAG_ELVSWITCH    8       /* don't use elevator, just do FIFO */
457 #define QUEUE_FLAG_BIDI         9       /* queue supports bidi requests */
458 #define QUEUE_FLAG_NOMERGES    10       /* disable merge attempts */
459 #define QUEUE_FLAG_SAME_COMP   11       /* force complete on same CPU */
460 #define QUEUE_FLAG_FAIL_IO     12       /* fake timeout */
461 #define QUEUE_FLAG_STACKABLE   13       /* supports request stacking */
462 #define QUEUE_FLAG_NONROT      14       /* non-rotational device (SSD) */
463 #define QUEUE_FLAG_VIRT        QUEUE_FLAG_NONROT /* paravirt device */
464 #define QUEUE_FLAG_IO_STAT     15       /* do IO stats */
465
466 #define QUEUE_FLAG_DEFAULT      ((1 << QUEUE_FLAG_IO_STAT) |            \
467                                  (1 << QUEUE_FLAG_CLUSTER) |            \
468                                  (1 << QUEUE_FLAG_STACKABLE))
469
470 static inline int queue_is_locked(struct request_queue *q)
471 {
472 #ifdef CONFIG_SMP
473         spinlock_t *lock = q->queue_lock;
474         return lock && spin_is_locked(lock);
475 #else
476         return 1;
477 #endif
478 }
479
480 static inline void queue_flag_set_unlocked(unsigned int flag,
481                                            struct request_queue *q)
482 {
483         __set_bit(flag, &q->queue_flags);
484 }
485
486 static inline int queue_flag_test_and_clear(unsigned int flag,
487                                             struct request_queue *q)
488 {
489         WARN_ON_ONCE(!queue_is_locked(q));
490
491         if (test_bit(flag, &q->queue_flags)) {
492                 __clear_bit(flag, &q->queue_flags);
493                 return 1;
494         }
495
496         return 0;
497 }
498
499 static inline int queue_flag_test_and_set(unsigned int flag,
500                                           struct request_queue *q)
501 {
502         WARN_ON_ONCE(!queue_is_locked(q));
503
504         if (!test_bit(flag, &q->queue_flags)) {
505                 __set_bit(flag, &q->queue_flags);
506                 return 0;
507         }
508
509         return 1;
510 }
511
512 static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
513 {
514         WARN_ON_ONCE(!queue_is_locked(q));
515         __set_bit(flag, &q->queue_flags);
516 }
517
518 static inline void queue_flag_clear_unlocked(unsigned int flag,
519                                              struct request_queue *q)
520 {
521         __clear_bit(flag, &q->queue_flags);
522 }
523
524 static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
525 {
526         WARN_ON_ONCE(!queue_is_locked(q));
527         __clear_bit(flag, &q->queue_flags);
528 }
529
530 enum {
531         /*
532          * Hardbarrier is supported with one of the following methods.
533          *
534          * NONE         : hardbarrier unsupported
535          * DRAIN        : ordering by draining is enough
536          * DRAIN_FLUSH  : ordering by draining w/ pre and post flushes
537          * DRAIN_FUA    : ordering by draining w/ pre flush and FUA write
538          * TAG          : ordering by tag is enough
539          * TAG_FLUSH    : ordering by tag w/ pre and post flushes
540          * TAG_FUA      : ordering by tag w/ pre flush and FUA write
541          */
542         QUEUE_ORDERED_BY_DRAIN          = 0x01,
543         QUEUE_ORDERED_BY_TAG            = 0x02,
544         QUEUE_ORDERED_DO_PREFLUSH       = 0x10,
545         QUEUE_ORDERED_DO_BAR            = 0x20,
546         QUEUE_ORDERED_DO_POSTFLUSH      = 0x40,
547         QUEUE_ORDERED_DO_FUA            = 0x80,
548
549         QUEUE_ORDERED_NONE              = 0x00,
550
551         QUEUE_ORDERED_DRAIN             = QUEUE_ORDERED_BY_DRAIN |
552                                           QUEUE_ORDERED_DO_BAR,
553         QUEUE_ORDERED_DRAIN_FLUSH       = QUEUE_ORDERED_DRAIN |
554                                           QUEUE_ORDERED_DO_PREFLUSH |
555                                           QUEUE_ORDERED_DO_POSTFLUSH,
556         QUEUE_ORDERED_DRAIN_FUA         = QUEUE_ORDERED_DRAIN |
557                                           QUEUE_ORDERED_DO_PREFLUSH |
558                                           QUEUE_ORDERED_DO_FUA,
559
560         QUEUE_ORDERED_TAG               = QUEUE_ORDERED_BY_TAG |
561                                           QUEUE_ORDERED_DO_BAR,
562         QUEUE_ORDERED_TAG_FLUSH         = QUEUE_ORDERED_TAG |
563                                           QUEUE_ORDERED_DO_PREFLUSH |
564                                           QUEUE_ORDERED_DO_POSTFLUSH,
565         QUEUE_ORDERED_TAG_FUA           = QUEUE_ORDERED_TAG |
566                                           QUEUE_ORDERED_DO_PREFLUSH |
567                                           QUEUE_ORDERED_DO_FUA,
568
569         /*
570          * Ordered operation sequence
571          */
572         QUEUE_ORDSEQ_STARTED    = 0x01, /* flushing in progress */
573         QUEUE_ORDSEQ_DRAIN      = 0x02, /* waiting for the queue to be drained */
574         QUEUE_ORDSEQ_PREFLUSH   = 0x04, /* pre-flushing in progress */
575         QUEUE_ORDSEQ_BAR        = 0x08, /* original barrier req in progress */
576         QUEUE_ORDSEQ_POSTFLUSH  = 0x10, /* post-flushing in progress */
577         QUEUE_ORDSEQ_DONE       = 0x20,
578 };
579
580 #define blk_queue_plugged(q)    test_bit(QUEUE_FLAG_PLUGGED, &(q)->queue_flags)
581 #define blk_queue_tagged(q)     test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags)
582 #define blk_queue_stopped(q)    test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
583 #define blk_queue_nomerges(q)   test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
584 #define blk_queue_nonrot(q)     test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags)
585 #define blk_queue_io_stat(q)    test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
586 #define blk_queue_flushing(q)   ((q)->ordseq)
587 #define blk_queue_stackable(q)  \
588         test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)
589
590 #define blk_fs_request(rq)      ((rq)->cmd_type == REQ_TYPE_FS)
591 #define blk_pc_request(rq)      ((rq)->cmd_type == REQ_TYPE_BLOCK_PC)
592 #define blk_special_request(rq) ((rq)->cmd_type == REQ_TYPE_SPECIAL)
593 #define blk_sense_request(rq)   ((rq)->cmd_type == REQ_TYPE_SENSE)
594
595 #define blk_failfast_dev(rq)    ((rq)->cmd_flags & REQ_FAILFAST_DEV)
596 #define blk_failfast_transport(rq) ((rq)->cmd_flags & REQ_FAILFAST_TRANSPORT)
597 #define blk_failfast_driver(rq) ((rq)->cmd_flags & REQ_FAILFAST_DRIVER)
598 #define blk_noretry_request(rq) (blk_failfast_dev(rq) ||        \
599                                  blk_failfast_transport(rq) ||  \
600                                  blk_failfast_driver(rq))
601 #define blk_rq_started(rq)      ((rq)->cmd_flags & REQ_STARTED)
602 #define blk_rq_io_stat(rq)      ((rq)->cmd_flags & REQ_IO_STAT)
603
604 #define blk_account_rq(rq)      (blk_rq_started(rq) && (blk_fs_request(rq) || blk_discard_rq(rq))) 
605
606 #define blk_pm_suspend_request(rq)      ((rq)->cmd_type == REQ_TYPE_PM_SUSPEND)
607 #define blk_pm_resume_request(rq)       ((rq)->cmd_type == REQ_TYPE_PM_RESUME)
608 #define blk_pm_request(rq)      \
609         (blk_pm_suspend_request(rq) || blk_pm_resume_request(rq))
610
611 #define blk_rq_cpu_valid(rq)    ((rq)->cpu != -1)
612 #define blk_sorted_rq(rq)       ((rq)->cmd_flags & REQ_SORTED)
613 #define blk_barrier_rq(rq)      ((rq)->cmd_flags & REQ_HARDBARRIER)
614 #define blk_fua_rq(rq)          ((rq)->cmd_flags & REQ_FUA)
615 #define blk_discard_rq(rq)      ((rq)->cmd_flags & REQ_DISCARD)
616 #define blk_bidi_rq(rq)         ((rq)->next_rq != NULL)
617 /* rq->queuelist of dequeued request must be list_empty() */
618 #define blk_queued_rq(rq)       (!list_empty(&(rq)->queuelist))
619
620 #define list_entry_rq(ptr)      list_entry((ptr), struct request, queuelist)
621
622 #define rq_data_dir(rq)         ((rq)->cmd_flags & 1)
623
624 /*
625  * We regard a request as sync, if either a read or a sync write
626  */
627 static inline bool rw_is_sync(unsigned int rw_flags)
628 {
629         return !(rw_flags & REQ_RW) || (rw_flags & REQ_RW_SYNC);
630 }
631
632 static inline bool rq_is_sync(struct request *rq)
633 {
634         return rw_is_sync(rq->cmd_flags);
635 }
636
637 #define rq_is_meta(rq)          ((rq)->cmd_flags & REQ_RW_META)
638 #define rq_noidle(rq)           ((rq)->cmd_flags & REQ_NOIDLE)
639
640 static inline int blk_queue_full(struct request_queue *q, int sync)
641 {
642         if (sync)
643                 return test_bit(QUEUE_FLAG_SYNCFULL, &q->queue_flags);
644         return test_bit(QUEUE_FLAG_ASYNCFULL, &q->queue_flags);
645 }
646
647 static inline void blk_set_queue_full(struct request_queue *q, int sync)
648 {
649         if (sync)
650                 queue_flag_set(QUEUE_FLAG_SYNCFULL, q);
651         else
652                 queue_flag_set(QUEUE_FLAG_ASYNCFULL, q);
653 }
654
655 static inline void blk_clear_queue_full(struct request_queue *q, int sync)
656 {
657         if (sync)
658                 queue_flag_clear(QUEUE_FLAG_SYNCFULL, q);
659         else
660                 queue_flag_clear(QUEUE_FLAG_ASYNCFULL, q);
661 }
662
663
664 /*
665  * mergeable request must not have _NOMERGE or _BARRIER bit set, nor may
666  * it already be started by driver.
667  */
668 #define RQ_NOMERGE_FLAGS        \
669         (REQ_NOMERGE | REQ_STARTED | REQ_HARDBARRIER | REQ_SOFTBARRIER)
670 #define rq_mergeable(rq)        \
671         (!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \
672          (blk_discard_rq(rq) || blk_fs_request((rq))))
673
674 /*
675  * q->prep_rq_fn return values
676  */
677 #define BLKPREP_OK              0       /* serve it */
678 #define BLKPREP_KILL            1       /* fatal error, kill */
679 #define BLKPREP_DEFER           2       /* leave on queue */
680
681 extern unsigned long blk_max_low_pfn, blk_max_pfn;
682
683 /*
684  * standard bounce addresses:
685  *
686  * BLK_BOUNCE_HIGH      : bounce all highmem pages
687  * BLK_BOUNCE_ANY       : don't bounce anything
688  * BLK_BOUNCE_ISA       : bounce pages above ISA DMA boundary
689  */
690
691 #if BITS_PER_LONG == 32
692 #define BLK_BOUNCE_HIGH         ((u64)blk_max_low_pfn << PAGE_SHIFT)
693 #else
694 #define BLK_BOUNCE_HIGH         -1ULL
695 #endif
696 #define BLK_BOUNCE_ANY          (-1ULL)
697 #define BLK_BOUNCE_ISA          (ISA_DMA_THRESHOLD)
698
699 /*
700  * default timeout for SG_IO if none specified
701  */
702 #define BLK_DEFAULT_SG_TIMEOUT  (60 * HZ)
703 #define BLK_MIN_SG_TIMEOUT      (7 * HZ)
704
705 #ifdef CONFIG_BOUNCE
706 extern int init_emergency_isa_pool(void);
707 extern void blk_queue_bounce(struct request_queue *q, struct bio **bio);
708 #else
709 static inline int init_emergency_isa_pool(void)
710 {
711         return 0;
712 }
713 static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio)
714 {
715 }
716 #endif /* CONFIG_MMU */
717
718 struct rq_map_data {
719         struct page **pages;
720         int page_order;
721         int nr_entries;
722         unsigned long offset;
723         int null_mapped;
724 };
725
726 struct req_iterator {
727         int i;
728         struct bio *bio;
729 };
730
731 /* This should not be used directly - use rq_for_each_segment */
732 #define for_each_bio(_bio)              \
733         for (; _bio; _bio = _bio->bi_next)
734 #define __rq_for_each_bio(_bio, rq)     \
735         if ((rq->bio))                  \
736                 for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next)
737
738 #define rq_for_each_segment(bvl, _rq, _iter)                    \
739         __rq_for_each_bio(_iter.bio, _rq)                       \
740                 bio_for_each_segment(bvl, _iter.bio, _iter.i)
741
742 #define rq_iter_last(rq, _iter)                                 \
743                 (_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
744
745 extern int blk_register_queue(struct gendisk *disk);
746 extern void blk_unregister_queue(struct gendisk *disk);
747 extern void register_disk(struct gendisk *dev);
748 extern void generic_make_request(struct bio *bio);
749 extern void blk_rq_init(struct request_queue *q, struct request *rq);
750 extern void blk_put_request(struct request *);
751 extern void __blk_put_request(struct request_queue *, struct request *);
752 extern struct request *blk_get_request(struct request_queue *, int, gfp_t);
753 extern void blk_insert_request(struct request_queue *, struct request *, int, void *);
754 extern void blk_requeue_request(struct request_queue *, struct request *);
755 extern int blk_rq_check_limits(struct request_queue *q, struct request *rq);
756 extern int blk_lld_busy(struct request_queue *q);
757 extern int blk_insert_cloned_request(struct request_queue *q,
758                                      struct request *rq);
759 extern void blk_plug_device(struct request_queue *);
760 extern void blk_plug_device_unlocked(struct request_queue *);
761 extern int blk_remove_plug(struct request_queue *);
762 extern void blk_recount_segments(struct request_queue *, struct bio *);
763 extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
764                           unsigned int, void __user *);
765 extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
766                          struct scsi_ioctl_command __user *);
767
768 /*
769  * Temporary export, until SCSI gets fixed up.
770  */
771 extern int blk_rq_append_bio(struct request_queue *q, struct request *rq,
772                              struct bio *bio);
773
774 /*
775  * A queue has just exitted congestion.  Note this in the global counter of
776  * congested queues, and wake up anyone who was waiting for requests to be
777  * put back.
778  */
779 static inline void blk_clear_queue_congested(struct request_queue *q, int rw)
780 {
781         clear_bdi_congested(&q->backing_dev_info, rw);
782 }
783
784 /*
785  * A queue has just entered congestion.  Flag that in the queue's VM-visible
786  * state flags and increment the global gounter of congested queues.
787  */
788 static inline void blk_set_queue_congested(struct request_queue *q, int rw)
789 {
790         set_bdi_congested(&q->backing_dev_info, rw);
791 }
792
793 extern void blk_start_queue(struct request_queue *q);
794 extern void blk_stop_queue(struct request_queue *q);
795 extern void blk_sync_queue(struct request_queue *q);
796 extern void __blk_stop_queue(struct request_queue *q);
797 extern void __blk_run_queue(struct request_queue *);
798 extern void blk_run_queue(struct request_queue *);
799 extern int blk_rq_map_user(struct request_queue *, struct request *,
800                            struct rq_map_data *, void __user *, unsigned long,
801                            gfp_t);
802 extern int blk_rq_unmap_user(struct bio *);
803 extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t);
804 extern int blk_rq_map_user_iov(struct request_queue *, struct request *,
805                                struct rq_map_data *, struct sg_iovec *, int,
806                                unsigned int, gfp_t);
807 extern int blk_execute_rq(struct request_queue *, struct gendisk *,
808                           struct request *, int);
809 extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
810                                   struct request *, int, rq_end_io_fn *);
811 extern void blk_unplug(struct request_queue *q);
812
813 static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
814 {
815         return bdev->bd_disk->queue;
816 }
817
818 static inline void blk_run_backing_dev(struct backing_dev_info *bdi,
819                                        struct page *page)
820 {
821         if (bdi && bdi->unplug_io_fn)
822                 bdi->unplug_io_fn(bdi, page);
823 }
824
825 static inline void blk_run_address_space(struct address_space *mapping)
826 {
827         if (mapping)
828                 blk_run_backing_dev(mapping->backing_dev_info, NULL);
829 }
830
831 extern void blkdev_dequeue_request(struct request *req);
832
833 /*
834  * blk_end_request() takes bytes instead of sectors as a complete size.
835  * blk_rq_bytes() returns bytes left to complete in the entire request.
836  * blk_rq_cur_bytes() returns bytes left to complete in the current segment.
837  */
838 extern unsigned int blk_rq_bytes(struct request *rq);
839 extern unsigned int blk_rq_cur_bytes(struct request *rq);
840
841 /*
842  * Request completion related functions.
843  *
844  * blk_update_request() completes given number of bytes and updates
845  * the request without completing it.
846  *
847  * blk_end_request() and friends.  __blk_end_request() must be called
848  * with the request queue spinlock acquired.
849  *
850  * Several drivers define their own end_request and call
851  * blk_end_request() for parts of the original function.
852  * This prevents code duplication in drivers.
853  */
854 extern bool blk_update_request(struct request *rq, int error,
855                                unsigned int nr_bytes);
856 extern bool blk_end_bidi_request(struct request *rq, int error,
857                                  unsigned int nr_bytes,
858                                  unsigned int bidi_bytes);
859 extern bool __blk_end_bidi_request(struct request *rq, int error,
860                                    unsigned int nr_bytes,
861                                    unsigned int bidi_bytes);
862
863 /**
864  * blk_end_request - Helper function for drivers to complete the request.
865  * @rq:       the request being processed
866  * @error:    %0 for success, < %0 for error
867  * @nr_bytes: number of bytes to complete
868  *
869  * Description:
870  *     Ends I/O on a number of bytes attached to @rq.
871  *     If @rq has leftover, sets it up for the next range of segments.
872  *
873  * Return:
874  *     %false - we are done with this request
875  *     %true  - still buffers pending for this request
876  **/
877 static inline bool blk_end_request(struct request *rq, int error,
878                                    unsigned int nr_bytes)
879 {
880         return blk_end_bidi_request(rq, error, nr_bytes, 0);
881 }
882
883 /**
884  * blk_end_request_all - Helper function for drives to finish the request.
885  * @rq: the request to finish
886  * @err: %0 for success, < %0 for error
887  *
888  * Description:
889  *     Completely finish @rq.
890  */
891 static inline void blk_end_request_all(struct request *rq, int error)
892 {
893         bool pending;
894
895         pending = blk_end_request(rq, error, blk_rq_bytes(rq));
896         BUG_ON(pending);
897 }
898
899 /**
900  * blk_end_request_cur - Helper function to finish the current request chunk.
901  * @rq: the request to finish the current chunk for
902  * @err: %0 for success, < %0 for error
903  *
904  * Description:
905  *     Complete the current consecutively mapped chunk from @rq.
906  */
907 static inline void blk_end_request_cur(struct request *rq, int error)
908 {
909         blk_end_request(rq, error, rq->hard_cur_sectors << 9);
910 }
911
912 /**
913  * __blk_end_request - Helper function for drivers to complete the request.
914  * @rq:       the request being processed
915  * @error:    %0 for success, < %0 for error
916  * @nr_bytes: number of bytes to complete
917  *
918  * Description:
919  *     Must be called with queue lock held unlike blk_end_request().
920  *
921  * Return:
922  *     %false - we are done with this request
923  *     %true  - still buffers pending for this request
924  **/
925 static inline bool __blk_end_request(struct request *rq, int error,
926                                      unsigned int nr_bytes)
927 {
928         return __blk_end_bidi_request(rq, error, nr_bytes, 0);
929 }
930
931 /**
932  * __blk_end_request_all - Helper function for drives to finish the request.
933  * @rq: the request to finish
934  * @err: %0 for success, < %0 for error
935  *
936  * Description:
937  *     Completely finish @rq.  Must be called with queue lock held.
938  */
939 static inline void __blk_end_request_all(struct request *rq, int error)
940 {
941         bool pending;
942
943         pending = __blk_end_request(rq, error, blk_rq_bytes(rq));
944         BUG_ON(pending);
945 }
946
947 /**
948  * __blk_end_request_cur - Helper function to finish the current request chunk.
949  * @rq: the request to finish the current chunk for
950  * @err: %0 for success, < %0 for error
951  *
952  * Description:
953  *     Complete the current consecutively mapped chunk from @rq.  Must
954  *     be called with queue lock held.
955  */
956 static inline void __blk_end_request_cur(struct request *rq, int error)
957 {
958         __blk_end_request(rq, error, rq->hard_cur_sectors << 9);
959 }
960
961 extern void blk_complete_request(struct request *);
962 extern void __blk_complete_request(struct request *);
963 extern void blk_abort_request(struct request *);
964 extern void blk_abort_queue(struct request_queue *);
965
966 /*
967  * Access functions for manipulating queue properties
968  */
969 extern struct request_queue *blk_init_queue_node(request_fn_proc *rfn,
970                                         spinlock_t *lock, int node_id);
971 extern struct request_queue *blk_init_queue(request_fn_proc *, spinlock_t *);
972 extern void blk_cleanup_queue(struct request_queue *);
973 extern void blk_queue_make_request(struct request_queue *, make_request_fn *);
974 extern void blk_queue_bounce_limit(struct request_queue *, u64);
975 extern void blk_queue_max_sectors(struct request_queue *, unsigned int);
976 extern void blk_queue_max_phys_segments(struct request_queue *, unsigned short);
977 extern void blk_queue_max_hw_segments(struct request_queue *, unsigned short);
978 extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
979 extern void blk_queue_hardsect_size(struct request_queue *, unsigned short);
980 extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b);
981 extern void blk_queue_dma_pad(struct request_queue *, unsigned int);
982 extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
983 extern int blk_queue_dma_drain(struct request_queue *q,
984                                dma_drain_needed_fn *dma_drain_needed,
985                                void *buf, unsigned int size);
986 extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn);
987 extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
988 extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn);
989 extern void blk_queue_merge_bvec(struct request_queue *, merge_bvec_fn *);
990 extern void blk_queue_dma_alignment(struct request_queue *, int);
991 extern void blk_queue_update_dma_alignment(struct request_queue *, int);
992 extern void blk_queue_softirq_done(struct request_queue *, softirq_done_fn *);
993 extern void blk_queue_set_discard(struct request_queue *, prepare_discard_fn *);
994 extern void blk_queue_rq_timed_out(struct request_queue *, rq_timed_out_fn *);
995 extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
996 extern struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev);
997 extern int blk_queue_ordered(struct request_queue *, unsigned, prepare_flush_fn *);
998 extern bool blk_do_ordered(struct request_queue *, struct request **);
999 extern unsigned blk_ordered_cur_seq(struct request_queue *);
1000 extern unsigned blk_ordered_req_seq(struct request *);
1001 extern bool blk_ordered_complete_seq(struct request_queue *, unsigned, int);
1002
1003 extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatterlist *);
1004 extern void blk_dump_rq_flags(struct request *, char *);
1005 extern void generic_unplug_device(struct request_queue *);
1006 extern long nr_blockdev_pages(void);
1007
1008 int blk_get_queue(struct request_queue *);
1009 struct request_queue *blk_alloc_queue(gfp_t);
1010 struct request_queue *blk_alloc_queue_node(gfp_t, int);
1011 extern void blk_put_queue(struct request_queue *);
1012
1013 /*
1014  * tag stuff
1015  */
1016 #define blk_rq_tagged(rq)               ((rq)->cmd_flags & REQ_QUEUED)
1017 extern int blk_queue_start_tag(struct request_queue *, struct request *);
1018 extern struct request *blk_queue_find_tag(struct request_queue *, int);
1019 extern void blk_queue_end_tag(struct request_queue *, struct request *);
1020 extern int blk_queue_init_tags(struct request_queue *, int, struct blk_queue_tag *);
1021 extern void blk_queue_free_tags(struct request_queue *);
1022 extern int blk_queue_resize_tags(struct request_queue *, int);
1023 extern void blk_queue_invalidate_tags(struct request_queue *);
1024 extern struct blk_queue_tag *blk_init_tags(int);
1025 extern void blk_free_tags(struct blk_queue_tag *);
1026
1027 static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
1028                                                 int tag)
1029 {
1030         if (unlikely(bqt == NULL || tag >= bqt->real_max_depth))
1031                 return NULL;
1032         return bqt->tag_index[tag];
1033 }
1034
1035 extern int blkdev_issue_flush(struct block_device *, sector_t *);
1036 extern int blkdev_issue_discard(struct block_device *,
1037                                 sector_t sector, sector_t nr_sects, gfp_t);
1038
1039 static inline int sb_issue_discard(struct super_block *sb,
1040                                    sector_t block, sector_t nr_blocks)
1041 {
1042         block <<= (sb->s_blocksize_bits - 9);
1043         nr_blocks <<= (sb->s_blocksize_bits - 9);
1044         return blkdev_issue_discard(sb->s_bdev, block, nr_blocks, GFP_KERNEL);
1045 }
1046
1047 /*
1048 * command filter functions
1049 */
1050 extern int blk_verify_command(struct blk_cmd_filter *filter,
1051                               unsigned char *cmd, fmode_t has_write_perm);
1052 extern void blk_unregister_filter(struct gendisk *disk);
1053 extern void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter);
1054
1055 #define MAX_PHYS_SEGMENTS 128
1056 #define MAX_HW_SEGMENTS 128
1057 #define SAFE_MAX_SECTORS 255
1058 #define BLK_DEF_MAX_SECTORS 1024
1059
1060 #define MAX_SEGMENT_SIZE        65536
1061
1062 #define BLK_SEG_BOUNDARY_MASK   0xFFFFFFFFUL
1063
1064 #define blkdev_entry_to_request(entry) list_entry((entry), struct request, queuelist)
1065
1066 static inline int queue_hardsect_size(struct request_queue *q)
1067 {
1068         int retval = 512;
1069
1070         if (q && q->hardsect_size)
1071                 retval = q->hardsect_size;
1072
1073         return retval;
1074 }
1075
1076 static inline int bdev_hardsect_size(struct block_device *bdev)
1077 {
1078         return queue_hardsect_size(bdev_get_queue(bdev));
1079 }
1080
1081 static inline int queue_dma_alignment(struct request_queue *q)
1082 {
1083         return q ? q->dma_alignment : 511;
1084 }
1085
1086 static inline int blk_rq_aligned(struct request_queue *q, void *addr,
1087                                  unsigned int len)
1088 {
1089         unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
1090         return !((unsigned long)addr & alignment) && !(len & alignment);
1091 }
1092
1093 /* assumes size > 256 */
1094 static inline unsigned int blksize_bits(unsigned int size)
1095 {
1096         unsigned int bits = 8;
1097         do {
1098                 bits++;
1099                 size >>= 1;
1100         } while (size > 256);
1101         return bits;
1102 }
1103
1104 static inline unsigned int block_size(struct block_device *bdev)
1105 {
1106         return bdev->bd_block_size;
1107 }
1108
1109 typedef struct {struct page *v;} Sector;
1110
1111 unsigned char *read_dev_sector(struct block_device *, sector_t, Sector *);
1112
1113 static inline void put_dev_sector(Sector p)
1114 {
1115         page_cache_release(p.v);
1116 }
1117
1118 struct work_struct;
1119 int kblockd_schedule_work(struct request_queue *q, struct work_struct *work);
1120
1121 #define MODULE_ALIAS_BLOCKDEV(major,minor) \
1122         MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))
1123 #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \
1124         MODULE_ALIAS("block-major-" __stringify(major) "-*")
1125
1126 #if defined(CONFIG_BLK_DEV_INTEGRITY)
1127
1128 #define INTEGRITY_FLAG_READ     2       /* verify data integrity on read */
1129 #define INTEGRITY_FLAG_WRITE    4       /* generate data integrity on write */
1130
1131 struct blk_integrity_exchg {
1132         void                    *prot_buf;
1133         void                    *data_buf;
1134         sector_t                sector;
1135         unsigned int            data_size;
1136         unsigned short          sector_size;
1137         const char              *disk_name;
1138 };
1139
1140 typedef void (integrity_gen_fn) (struct blk_integrity_exchg *);
1141 typedef int (integrity_vrfy_fn) (struct blk_integrity_exchg *);
1142 typedef void (integrity_set_tag_fn) (void *, void *, unsigned int);
1143 typedef void (integrity_get_tag_fn) (void *, void *, unsigned int);
1144
1145 struct blk_integrity {
1146         integrity_gen_fn        *generate_fn;
1147         integrity_vrfy_fn       *verify_fn;
1148         integrity_set_tag_fn    *set_tag_fn;
1149         integrity_get_tag_fn    *get_tag_fn;
1150
1151         unsigned short          flags;
1152         unsigned short          tuple_size;
1153         unsigned short          sector_size;
1154         unsigned short          tag_size;
1155
1156         const char              *name;
1157
1158         struct kobject          kobj;
1159 };
1160
1161 extern int blk_integrity_register(struct gendisk *, struct blk_integrity *);
1162 extern void blk_integrity_unregister(struct gendisk *);
1163 extern int blk_integrity_compare(struct gendisk *, struct gendisk *);
1164 extern int blk_rq_map_integrity_sg(struct request *, struct scatterlist *);
1165 extern int blk_rq_count_integrity_sg(struct request *);
1166
1167 static inline
1168 struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
1169 {
1170         return bdev->bd_disk->integrity;
1171 }
1172
1173 static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk)
1174 {
1175         return disk->integrity;
1176 }
1177
1178 static inline int blk_integrity_rq(struct request *rq)
1179 {
1180         if (rq->bio == NULL)
1181                 return 0;
1182
1183         return bio_integrity(rq->bio);
1184 }
1185
1186 #else /* CONFIG_BLK_DEV_INTEGRITY */
1187
1188 #define blk_integrity_rq(rq)                    (0)
1189 #define blk_rq_count_integrity_sg(a)            (0)
1190 #define blk_rq_map_integrity_sg(a, b)           (0)
1191 #define bdev_get_integrity(a)                   (0)
1192 #define blk_get_integrity(a)                    (0)
1193 #define blk_integrity_compare(a, b)             (0)
1194 #define blk_integrity_register(a, b)            (0)
1195 #define blk_integrity_unregister(a)             do { } while (0);
1196
1197 #endif /* CONFIG_BLK_DEV_INTEGRITY */
1198
1199 struct block_device_operations {
1200         int (*open) (struct block_device *, fmode_t);
1201         int (*release) (struct gendisk *, fmode_t);
1202         int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1203         int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1204         int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1205         int (*direct_access) (struct block_device *, sector_t,
1206                                                 void **, unsigned long *);
1207         int (*media_changed) (struct gendisk *);
1208         int (*revalidate_disk) (struct gendisk *);
1209         int (*getgeo)(struct block_device *, struct hd_geometry *);
1210         struct module *owner;
1211 };
1212
1213 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
1214                                  unsigned long);
1215 #else /* CONFIG_BLOCK */
1216 /*
1217  * stubs for when the block layer is configured out
1218  */
1219 #define buffer_heads_over_limit 0
1220
1221 static inline long nr_blockdev_pages(void)
1222 {
1223         return 0;
1224 }
1225
1226 #endif /* CONFIG_BLOCK */
1227
1228 #endif