summaryrefslogtreecommitdiffstats
path: root/block/blk-lib.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-07-20 09:29:37 -0400
committerJens Axboe <axboe@fb.com>2015-07-29 10:55:15 -0400
commit4246a0b63bd8f56a1469b12eafeb875b1041a451 (patch)
tree3281bb158d658ef7f208ad380c0ecee600a5ab5e /block/blk-lib.c
parent0034af036554c39eefd14d835a8ec3496ac46712 (diff)
block: add a bi_error field to struct bio
Currently we have two different ways to signal an I/O error on a BIO: (1) by clearing the BIO_UPTODATE flag (2) by returning a Linux errno value to the bi_end_io callback The first one has the drawback of only communicating a single possible error (-EIO), and the second one has the drawback of not beeing persistent when bios are queued up, and are not passed along from child to parent bio in the ever more popular chaining scenario. Having both mechanisms available has the additional drawback of utterly confusing driver authors and introducing bugs where various I/O submitters only deal with one of them, and the others have to add boilerplate code to deal with both kinds of error returns. So add a new bi_error field to store an errno value directly in struct bio and remove the existing mechanisms to clean all this up. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block/blk-lib.c')
-rw-r--r--block/blk-lib.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 7688ee3f5d72..6dee17443f14 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -11,16 +11,16 @@
11 11
12struct bio_batch { 12struct bio_batch {
13 atomic_t done; 13 atomic_t done;
14 unsigned long flags; 14 int error;
15 struct completion *wait; 15 struct completion *wait;
16}; 16};
17 17
18static void bio_batch_end_io(struct bio *bio, int err) 18static void bio_batch_end_io(struct bio *bio)
19{ 19{
20 struct bio_batch *bb = bio->bi_private; 20 struct bio_batch *bb = bio->bi_private;
21 21
22 if (err && (err != -EOPNOTSUPP)) 22 if (bio->bi_error && bio->bi_error != -EOPNOTSUPP)
23 clear_bit(BIO_UPTODATE, &bb->flags); 23 bb->error = bio->bi_error;
24 if (atomic_dec_and_test(&bb->done)) 24 if (atomic_dec_and_test(&bb->done))
25 complete(bb->wait); 25 complete(bb->wait);
26 bio_put(bio); 26 bio_put(bio);
@@ -78,7 +78,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
78 } 78 }
79 79
80 atomic_set(&bb.done, 1); 80 atomic_set(&bb.done, 1);
81 bb.flags = 1 << BIO_UPTODATE; 81 bb.error = 0;
82 bb.wait = &wait; 82 bb.wait = &wait;
83 83
84 blk_start_plug(&plug); 84 blk_start_plug(&plug);
@@ -134,9 +134,8 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
134 if (!atomic_dec_and_test(&bb.done)) 134 if (!atomic_dec_and_test(&bb.done))
135 wait_for_completion_io(&wait); 135 wait_for_completion_io(&wait);
136 136
137 if (!test_bit(BIO_UPTODATE, &bb.flags)) 137 if (bb.error)
138 ret = -EIO; 138 return bb.error;
139
140 return ret; 139 return ret;
141} 140}
142EXPORT_SYMBOL(blkdev_issue_discard); 141EXPORT_SYMBOL(blkdev_issue_discard);
@@ -172,7 +171,7 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
172 return -EOPNOTSUPP; 171 return -EOPNOTSUPP;
173 172
174 atomic_set(&bb.done, 1); 173 atomic_set(&bb.done, 1);
175 bb.flags = 1 << BIO_UPTODATE; 174 bb.error = 0;
176 bb.wait = &wait; 175 bb.wait = &wait;
177 176
178 while (nr_sects) { 177 while (nr_sects) {
@@ -208,9 +207,8 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
208 if (!atomic_dec_and_test(&bb.done)) 207 if (!atomic_dec_and_test(&bb.done))
209 wait_for_completion_io(&wait); 208 wait_for_completion_io(&wait);
210 209
211 if (!test_bit(BIO_UPTODATE, &bb.flags)) 210 if (bb.error)
212 ret = -ENOTSUPP; 211 return bb.error;
213
214 return ret; 212 return ret;
215} 213}
216EXPORT_SYMBOL(blkdev_issue_write_same); 214EXPORT_SYMBOL(blkdev_issue_write_same);
@@ -236,7 +234,7 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
236 DECLARE_COMPLETION_ONSTACK(wait); 234 DECLARE_COMPLETION_ONSTACK(wait);
237 235
238 atomic_set(&bb.done, 1); 236 atomic_set(&bb.done, 1);
239 bb.flags = 1 << BIO_UPTODATE; 237 bb.error = 0;
240 bb.wait = &wait; 238 bb.wait = &wait;
241 239
242 ret = 0; 240 ret = 0;
@@ -270,10 +268,8 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
270 if (!atomic_dec_and_test(&bb.done)) 268 if (!atomic_dec_and_test(&bb.done))
271 wait_for_completion_io(&wait); 269 wait_for_completion_io(&wait);
272 270
273 if (!test_bit(BIO_UPTODATE, &bb.flags)) 271 if (bb.error)
274 /* One of bios in the batch was completed with error.*/ 272 return bb.error;
275 ret = -EIO;
276
277 return ret; 273 return ret;
278} 274}
279 275