Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Functions related to barrier IO handling |
| 3 | */ |
| 4 | #include <linux/kernel.h> |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/bio.h> |
| 7 | #include <linux/blkdev.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include <linux/gfp.h> |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 9 | |
| 10 | #include "blk.h" |
| 11 | |
| 12 | /** |
| 13 | * blk_queue_ordered - does this queue support ordered writes |
| 14 | * @q: the request queue |
| 15 | * @ordered: one of QUEUE_ORDERED_* |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 16 | * |
| 17 | * Description: |
| 18 | * For journalled file systems, doing ordered writes on a commit |
| 19 | * block instead of explicitly doing wait_on_buffer (which is bad |
| 20 | * for performance) can be a big win. Block drivers supporting this |
| 21 | * feature should call this function and indicate so. |
| 22 | * |
| 23 | **/ |
FUJITA Tomonori | 00fff26 | 2010-07-03 17:45:40 +0900 | [diff] [blame] | 24 | int blk_queue_ordered(struct request_queue *q, unsigned ordered) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 25 | { |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 26 | if (ordered != QUEUE_ORDERED_NONE && |
| 27 | ordered != QUEUE_ORDERED_DRAIN && |
| 28 | ordered != QUEUE_ORDERED_DRAIN_FLUSH && |
Tejun Heo | 6958f14 | 2010-09-03 11:56:16 +0200 | [diff] [blame^] | 29 | ordered != QUEUE_ORDERED_DRAIN_FUA) { |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 30 | printk(KERN_ERR "blk_queue_ordered: bad value %d\n", ordered); |
| 31 | return -EINVAL; |
| 32 | } |
| 33 | |
| 34 | q->ordered = ordered; |
| 35 | q->next_ordered = ordered; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 36 | |
| 37 | return 0; |
| 38 | } |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 39 | EXPORT_SYMBOL(blk_queue_ordered); |
| 40 | |
| 41 | /* |
| 42 | * Cache flushing for ordered writes handling |
| 43 | */ |
Adrian Bunk | 6f6a036 | 2008-04-29 09:49:06 +0200 | [diff] [blame] | 44 | unsigned blk_ordered_cur_seq(struct request_queue *q) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 45 | { |
| 46 | if (!q->ordseq) |
| 47 | return 0; |
| 48 | return 1 << ffz(q->ordseq); |
| 49 | } |
| 50 | |
| 51 | unsigned blk_ordered_req_seq(struct request *rq) |
| 52 | { |
| 53 | struct request_queue *q = rq->q; |
| 54 | |
| 55 | BUG_ON(q->ordseq == 0); |
| 56 | |
| 57 | if (rq == &q->pre_flush_rq) |
| 58 | return QUEUE_ORDSEQ_PREFLUSH; |
| 59 | if (rq == &q->bar_rq) |
| 60 | return QUEUE_ORDSEQ_BAR; |
| 61 | if (rq == &q->post_flush_rq) |
| 62 | return QUEUE_ORDSEQ_POSTFLUSH; |
| 63 | |
| 64 | /* |
| 65 | * !fs requests don't need to follow barrier ordering. Always |
| 66 | * put them at the front. This fixes the following deadlock. |
| 67 | * |
| 68 | * http://thread.gmane.org/gmane.linux.kernel/537473 |
| 69 | */ |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 70 | if (rq->cmd_type != REQ_TYPE_FS) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 71 | return QUEUE_ORDSEQ_DRAIN; |
| 72 | |
| 73 | if ((rq->cmd_flags & REQ_ORDERED_COLOR) == |
| 74 | (q->orig_bar_rq->cmd_flags & REQ_ORDERED_COLOR)) |
| 75 | return QUEUE_ORDSEQ_DRAIN; |
| 76 | else |
| 77 | return QUEUE_ORDSEQ_DONE; |
| 78 | } |
| 79 | |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 80 | bool blk_ordered_complete_seq(struct request_queue *q, unsigned seq, int error) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 81 | { |
| 82 | struct request *rq; |
| 83 | |
| 84 | if (error && !q->orderr) |
| 85 | q->orderr = error; |
| 86 | |
| 87 | BUG_ON(q->ordseq & seq); |
| 88 | q->ordseq |= seq; |
| 89 | |
| 90 | if (blk_ordered_cur_seq(q) != QUEUE_ORDSEQ_DONE) |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 91 | return false; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * Okay, sequence complete. |
| 95 | */ |
| 96 | q->ordseq = 0; |
| 97 | rq = q->orig_bar_rq; |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 98 | __blk_end_request_all(rq, q->orderr); |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 99 | return true; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static void pre_flush_end_io(struct request *rq, int error) |
| 103 | { |
| 104 | elv_completed_request(rq->q, rq); |
| 105 | blk_ordered_complete_seq(rq->q, QUEUE_ORDSEQ_PREFLUSH, error); |
| 106 | } |
| 107 | |
| 108 | static void bar_end_io(struct request *rq, int error) |
| 109 | { |
| 110 | elv_completed_request(rq->q, rq); |
| 111 | blk_ordered_complete_seq(rq->q, QUEUE_ORDSEQ_BAR, error); |
| 112 | } |
| 113 | |
| 114 | static void post_flush_end_io(struct request *rq, int error) |
| 115 | { |
| 116 | elv_completed_request(rq->q, rq); |
| 117 | blk_ordered_complete_seq(rq->q, QUEUE_ORDSEQ_POSTFLUSH, error); |
| 118 | } |
| 119 | |
| 120 | static void queue_flush(struct request_queue *q, unsigned which) |
| 121 | { |
| 122 | struct request *rq; |
| 123 | rq_end_io_fn *end_io; |
| 124 | |
Tejun Heo | 313e429 | 2008-11-28 13:32:02 +0900 | [diff] [blame] | 125 | if (which == QUEUE_ORDERED_DO_PREFLUSH) { |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 126 | rq = &q->pre_flush_rq; |
| 127 | end_io = pre_flush_end_io; |
| 128 | } else { |
| 129 | rq = &q->post_flush_rq; |
| 130 | end_io = post_flush_end_io; |
| 131 | } |
| 132 | |
FUJITA Tomonori | 2a4aa30 | 2008-04-29 09:54:36 +0200 | [diff] [blame] | 133 | blk_rq_init(q, rq); |
FUJITA Tomonori | 28e18d0 | 2010-07-09 09:38:24 +0900 | [diff] [blame] | 134 | rq->cmd_type = REQ_TYPE_FS; |
FUJITA Tomonori | 8749534 | 2010-07-03 17:45:32 +0900 | [diff] [blame] | 135 | rq->cmd_flags = REQ_HARDBARRIER | REQ_FLUSH; |
FUJITA Tomonori | 16f2319 | 2010-07-09 09:38:25 +0900 | [diff] [blame] | 136 | rq->rq_disk = q->orig_bar_rq->rq_disk; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 137 | rq->end_io = end_io; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 138 | |
| 139 | elv_insert(q, rq, ELEVATOR_INSERT_FRONT); |
| 140 | } |
| 141 | |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 142 | static inline bool start_ordered(struct request_queue *q, struct request **rqp) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 143 | { |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 144 | struct request *rq = *rqp; |
| 145 | unsigned skip = 0; |
| 146 | |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 147 | q->orderr = 0; |
| 148 | q->ordered = q->next_ordered; |
| 149 | q->ordseq |= QUEUE_ORDSEQ_STARTED; |
| 150 | |
Tejun Heo | 58eea92 | 2008-11-28 13:32:06 +0900 | [diff] [blame] | 151 | /* |
| 152 | * For an empty barrier, there's no actual BAR request, which |
| 153 | * in turn makes POSTFLUSH unnecessary. Mask them off. |
| 154 | */ |
Tejun Heo | 6958f14 | 2010-09-03 11:56:16 +0200 | [diff] [blame^] | 155 | if (!blk_rq_sectors(rq)) |
Tejun Heo | 58eea92 | 2008-11-28 13:32:06 +0900 | [diff] [blame] | 156 | q->ordered &= ~(QUEUE_ORDERED_DO_BAR | |
| 157 | QUEUE_ORDERED_DO_POSTFLUSH); |
| 158 | |
Tejun Heo | f671620 | 2008-11-28 13:32:04 +0900 | [diff] [blame] | 159 | /* stash away the original request */ |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 160 | blk_dequeue_request(rq); |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 161 | q->orig_bar_rq = rq; |
Tejun Heo | f671620 | 2008-11-28 13:32:04 +0900 | [diff] [blame] | 162 | rq = NULL; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * Queue ordered sequence. As we stack them at the head, we |
| 166 | * need to queue in reverse order. Note that we rely on that |
| 167 | * no fs request uses ELEVATOR_INSERT_FRONT and thus no fs |
Tejun Heo | 58eea92 | 2008-11-28 13:32:06 +0900 | [diff] [blame] | 168 | * request gets inbetween ordered sequence. |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 169 | */ |
Tejun Heo | 58eea92 | 2008-11-28 13:32:06 +0900 | [diff] [blame] | 170 | if (q->ordered & QUEUE_ORDERED_DO_POSTFLUSH) { |
Tejun Heo | 313e429 | 2008-11-28 13:32:02 +0900 | [diff] [blame] | 171 | queue_flush(q, QUEUE_ORDERED_DO_POSTFLUSH); |
Tejun Heo | f671620 | 2008-11-28 13:32:04 +0900 | [diff] [blame] | 172 | rq = &q->post_flush_rq; |
| 173 | } else |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 174 | skip |= QUEUE_ORDSEQ_POSTFLUSH; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 175 | |
Tejun Heo | f671620 | 2008-11-28 13:32:04 +0900 | [diff] [blame] | 176 | if (q->ordered & QUEUE_ORDERED_DO_BAR) { |
| 177 | rq = &q->bar_rq; |
| 178 | |
| 179 | /* initialize proxy request and queue it */ |
| 180 | blk_rq_init(q, rq); |
| 181 | if (bio_data_dir(q->orig_bar_rq->bio) == WRITE) |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 182 | rq->cmd_flags |= REQ_WRITE; |
Tejun Heo | f671620 | 2008-11-28 13:32:04 +0900 | [diff] [blame] | 183 | if (q->ordered & QUEUE_ORDERED_DO_FUA) |
| 184 | rq->cmd_flags |= REQ_FUA; |
| 185 | init_request_from_bio(rq, q->orig_bar_rq->bio); |
| 186 | rq->end_io = bar_end_io; |
| 187 | |
| 188 | elv_insert(q, rq, ELEVATOR_INSERT_FRONT); |
| 189 | } else |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 190 | skip |= QUEUE_ORDSEQ_BAR; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 191 | |
Tejun Heo | 313e429 | 2008-11-28 13:32:02 +0900 | [diff] [blame] | 192 | if (q->ordered & QUEUE_ORDERED_DO_PREFLUSH) { |
| 193 | queue_flush(q, QUEUE_ORDERED_DO_PREFLUSH); |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 194 | rq = &q->pre_flush_rq; |
| 195 | } else |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 196 | skip |= QUEUE_ORDSEQ_PREFLUSH; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 197 | |
Tejun Heo | 6958f14 | 2010-09-03 11:56:16 +0200 | [diff] [blame^] | 198 | if (queue_in_flight(q)) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 199 | rq = NULL; |
Tejun Heo | f671620 | 2008-11-28 13:32:04 +0900 | [diff] [blame] | 200 | else |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 201 | skip |= QUEUE_ORDSEQ_DRAIN; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 202 | |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 203 | *rqp = rq; |
| 204 | |
| 205 | /* |
| 206 | * Complete skipped sequences. If whole sequence is complete, |
| 207 | * return false to tell elevator that this request is gone. |
| 208 | */ |
| 209 | return !blk_ordered_complete_seq(q, skip, 0); |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 212 | bool blk_do_ordered(struct request_queue *q, struct request **rqp) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 213 | { |
| 214 | struct request *rq = *rqp; |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 215 | const int is_barrier = rq->cmd_type == REQ_TYPE_FS && |
| 216 | (rq->cmd_flags & REQ_HARDBARRIER); |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 217 | |
| 218 | if (!q->ordseq) { |
| 219 | if (!is_barrier) |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 220 | return true; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 221 | |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 222 | if (q->next_ordered != QUEUE_ORDERED_NONE) |
| 223 | return start_ordered(q, rqp); |
| 224 | else { |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 225 | /* |
Tejun Heo | a738467 | 2008-11-28 13:32:03 +0900 | [diff] [blame] | 226 | * Queue ordering not supported. Terminate |
| 227 | * with prejudice. |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 228 | */ |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 229 | blk_dequeue_request(rq); |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 230 | __blk_end_request_all(rq, -EOPNOTSUPP); |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 231 | *rqp = NULL; |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 232 | return false; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Ordered sequence in progress |
| 238 | */ |
| 239 | |
| 240 | /* Special requests are not subject to ordering rules. */ |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 241 | if (rq->cmd_type != REQ_TYPE_FS && |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 242 | rq != &q->pre_flush_rq && rq != &q->post_flush_rq) |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 243 | return true; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 244 | |
Tejun Heo | 6958f14 | 2010-09-03 11:56:16 +0200 | [diff] [blame^] | 245 | /* Ordered by draining. Wait for turn. */ |
| 246 | WARN_ON(blk_ordered_req_seq(rq) < blk_ordered_cur_seq(q)); |
| 247 | if (blk_ordered_req_seq(rq) > blk_ordered_cur_seq(q)) |
| 248 | *rqp = NULL; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 249 | |
Tejun Heo | 8f11b3e | 2008-11-28 13:32:05 +0900 | [diff] [blame] | 250 | return true; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | static void bio_end_empty_barrier(struct bio *bio, int err) |
| 254 | { |
Jens Axboe | cc66b45 | 2008-03-04 11:47:46 +0100 | [diff] [blame] | 255 | if (err) { |
| 256 | if (err == -EOPNOTSUPP) |
| 257 | set_bit(BIO_EOPNOTSUPP, &bio->bi_flags); |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 258 | clear_bit(BIO_UPTODATE, &bio->bi_flags); |
Jens Axboe | cc66b45 | 2008-03-04 11:47:46 +0100 | [diff] [blame] | 259 | } |
Dmitry Monakhov | f17e232 | 2010-04-28 17:55:07 +0400 | [diff] [blame] | 260 | if (bio->bi_private) |
| 261 | complete(bio->bi_private); |
| 262 | bio_put(bio); |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /** |
| 266 | * blkdev_issue_flush - queue a flush |
| 267 | * @bdev: blockdev to issue flush for |
Dmitry Monakhov | fbd9b09 | 2010-04-28 17:55:06 +0400 | [diff] [blame] | 268 | * @gfp_mask: memory allocation flags (for bio_alloc) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 269 | * @error_sector: error sector |
Dmitry Monakhov | fbd9b09 | 2010-04-28 17:55:06 +0400 | [diff] [blame] | 270 | * @flags: BLKDEV_IFL_* flags to control behaviour |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 271 | * |
| 272 | * Description: |
| 273 | * Issue a flush for the block device in question. Caller can supply |
| 274 | * room for storing the error offset in case of a flush error, if they |
Dmitry Monakhov | f17e232 | 2010-04-28 17:55:07 +0400 | [diff] [blame] | 275 | * wish to. If WAIT flag is not passed then caller may check only what |
| 276 | * request was pushed in some internal queue for later handling. |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 277 | */ |
Dmitry Monakhov | fbd9b09 | 2010-04-28 17:55:06 +0400 | [diff] [blame] | 278 | int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask, |
| 279 | sector_t *error_sector, unsigned long flags) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 280 | { |
| 281 | DECLARE_COMPLETION_ONSTACK(wait); |
| 282 | struct request_queue *q; |
| 283 | struct bio *bio; |
Dmitry Monakhov | fbd9b09 | 2010-04-28 17:55:06 +0400 | [diff] [blame] | 284 | int ret = 0; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 285 | |
| 286 | if (bdev->bd_disk == NULL) |
| 287 | return -ENXIO; |
| 288 | |
| 289 | q = bdev_get_queue(bdev); |
| 290 | if (!q) |
| 291 | return -ENXIO; |
| 292 | |
Dave Chinner | f10d9f6 | 2010-07-13 17:50:50 +1000 | [diff] [blame] | 293 | /* |
| 294 | * some block devices may not have their queue correctly set up here |
| 295 | * (e.g. loop device without a backing file) and so issuing a flush |
| 296 | * here will panic. Ensure there is a request function before issuing |
| 297 | * the barrier. |
| 298 | */ |
| 299 | if (!q->make_request_fn) |
| 300 | return -ENXIO; |
| 301 | |
Dmitry Monakhov | fbd9b09 | 2010-04-28 17:55:06 +0400 | [diff] [blame] | 302 | bio = bio_alloc(gfp_mask, 0); |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 303 | bio->bi_end_io = bio_end_empty_barrier; |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 304 | bio->bi_bdev = bdev; |
Dmitry Monakhov | f17e232 | 2010-04-28 17:55:07 +0400 | [diff] [blame] | 305 | if (test_bit(BLKDEV_WAIT, &flags)) |
| 306 | bio->bi_private = &wait; |
| 307 | |
| 308 | bio_get(bio); |
OGAWA Hirofumi | 2ebca85 | 2008-08-11 17:07:08 +0100 | [diff] [blame] | 309 | submit_bio(WRITE_BARRIER, bio); |
Dmitry Monakhov | f17e232 | 2010-04-28 17:55:07 +0400 | [diff] [blame] | 310 | if (test_bit(BLKDEV_WAIT, &flags)) { |
| 311 | wait_for_completion(&wait); |
| 312 | /* |
| 313 | * The driver must store the error location in ->bi_sector, if |
| 314 | * it supports it. For non-stacked drivers, this should be |
| 315 | * copied from blk_rq_pos(rq). |
| 316 | */ |
| 317 | if (error_sector) |
| 318 | *error_sector = bio->bi_sector; |
| 319 | } |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 320 | |
Jens Axboe | cc66b45 | 2008-03-04 11:47:46 +0100 | [diff] [blame] | 321 | if (bio_flagged(bio, BIO_EOPNOTSUPP)) |
| 322 | ret = -EOPNOTSUPP; |
| 323 | else if (!bio_flagged(bio, BIO_UPTODATE)) |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 324 | ret = -EIO; |
| 325 | |
| 326 | bio_put(bio); |
| 327 | return ret; |
| 328 | } |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 329 | EXPORT_SYMBOL(blkdev_issue_flush); |