1 From 0f96bb8e2923065d58d89c5c82c9f37ad1f18404 Mon Sep 17 00:00:00 2001
2 From: Hannes Reinecke <hare@suse.de>
3 Date: Thu, 23 Oct 2008 13:42:06 +0200
4 Subject: [PATCH] Implement bio_has_data()
6 Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
7 Signed-off-by: Hannes Reinecke <hare@suse.de>
9 block/blk-core.c | 21 +++++++--------------
10 include/linux/bio.h | 14 +++++++++++---
11 include/linux/blkdev.h | 2 +-
13 4 files changed, 20 insertions(+), 19 deletions(-)
15 --- a/block/blk-core.c
16 +++ b/block/blk-core.c
17 @@ -624,10 +624,6 @@ blk_alloc_request(struct request_queue *
22 - * first three bits are identical in rq->cmd_flags and bio->bi_rw,
23 - * see bio.h and blkdev.h
25 rq->cmd_flags = rw | REQ_ALLOCED;
28 @@ -1490,10 +1486,7 @@ void submit_bio(int rw, struct bio *bio)
29 * If it's a regular read/write or a barrier with data attached,
30 * go through the normal accounting stuff before submission.
32 - if (!bio_empty_barrier(bio)) {
34 - BIO_BUG_ON(!bio->bi_size);
35 - BIO_BUG_ON(!bio->bi_io_vec);
36 + if (bio_has_data(bio)) {
39 count_vm_events(PGPGOUT, count);
40 @@ -1888,7 +1881,7 @@ static int blk_end_io(struct request *rq
41 struct request_queue *q = rq->q;
42 unsigned long flags = 0UL;
44 - if (blk_fs_request(rq) || blk_pc_request(rq)) {
45 + if (bio_has_data(rq->bio)) {
46 if (__end_that_request_first(rq, error, nr_bytes))
49 @@ -1946,10 +1939,9 @@ EXPORT_SYMBOL_GPL(blk_end_request);
51 int __blk_end_request(struct request *rq, int error, unsigned int nr_bytes)
53 - if (blk_fs_request(rq) || blk_pc_request(rq)) {
54 - if (__end_that_request_first(rq, error, nr_bytes))
57 + if (bio_has_data(rq->bio) &&
58 + __end_that_request_first(rq, error, nr_bytes))
61 add_disk_randomness(rq->rq_disk);
63 @@ -2016,7 +2008,8 @@ EXPORT_SYMBOL_GPL(blk_end_request_callba
64 void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
67 - /* first two bits are identical in rq->cmd_flags and bio->bi_rw */
68 + /* Bit 0 (R/W) is identical in rq->cmd_flags and bio->bi_rw, and
69 + we want BIO_RW_AHEAD (bit 1) to imply REQ_FAILFAST (bit 1). */
70 rq->cmd_flags |= (bio->bi_rw & 3);
72 rq->nr_phys_segments = bio_phys_segments(q, bio);
73 --- a/include/linux/bio.h
74 +++ b/include/linux/bio.h
75 @@ -157,8 +157,8 @@ struct bio {
76 * bit 3 -- fail fast, don't want low level driver retries
77 * bit 4 -- synchronous I/O hint: the block layer will unplug immediately
80 -#define BIO_RW_AHEAD 1
81 +#define BIO_RW 0 /* Must match RW in req flags (blkdev.h) */
82 +#define BIO_RW_AHEAD 1 /* Must match FAILFAST in req flags */
83 #define BIO_RW_BARRIER 2
84 #define BIO_RW_FAILFAST 3
86 @@ -192,7 +192,7 @@ struct bio {
87 #define bio_failfast(bio) ((bio)->bi_rw & (1 << BIO_RW_FAILFAST))
88 #define bio_rw_ahead(bio) ((bio)->bi_rw & (1 << BIO_RW_AHEAD))
89 #define bio_rw_meta(bio) ((bio)->bi_rw & (1 << BIO_RW_META))
90 -#define bio_empty_barrier(bio) (bio_barrier(bio) && !(bio)->bi_size)
91 +#define bio_empty_barrier(bio) (bio_barrier(bio) && !bio_has_data(bio))
93 static inline unsigned int bio_cur_sectors(struct bio *bio)
95 @@ -452,6 +452,14 @@ static inline char *__bio_kmap_irq(struc
96 __bio_kmap_irq((bio), (bio)->bi_idx, (flags))
97 #define bio_kunmap_irq(buf,flags) __bio_kunmap_irq(buf, flags)
100 + * Check whether this bio carries any data or not. A NULL bio is allowed.
102 +static inline int bio_has_data(struct bio *bio)
104 + return bio && bio->bi_io_vec != NULL;
107 #if defined(CONFIG_BLK_DEV_INTEGRITY)
109 #define bip_vec_idx(bip, idx) (&(bip->bip_vec[(idx)]))
110 --- a/include/linux/blkdev.h
111 +++ b/include/linux/blkdev.h
112 @@ -84,7 +84,7 @@ enum {
116 - * request type modified bits. first three bits match BIO_RW* bits, important
117 + * request type modified bits. first two bits match BIO_RW* bits, important
120 __REQ_RW, /* not set, read. set, write */
123 @@ -267,7 +267,7 @@ void blk_queue_bounce(struct request_que
125 * Data-less bio, nothing to bounce
127 - if (bio_empty_barrier(*bio_orig))
128 + if (!bio_has_data(*bio_orig))