提交 5bb23a68 编写于 作者: N NeilBrown 提交者: Jens Axboe

Don't decrement bi_size in bio_endio

The only caller of bio_endio that does not pass the full bi_size
is end_that_request_first.  Also, no ->bi_end_io method is really
interested in bi_size being decremented.

So move the decrement and related code into ll_rw_blk and merge it
with order_bio_endio to form req_bio_endio which does endio functionality
specific to request completion.

As some ->bi_end_io methods do check bi_size of 0, we set it thus for
now, but that will go in the next patch.
Signed-off-by: NNeil Brown <neilb@suse.de>

### Diffstat output
 ./block/ll_rw_blk.c |   42 +++++++++++++++++++++++++++---------------
 ./fs/bio.c          |   23 +++++++++++------------
 2 files changed, 38 insertions(+), 27 deletions(-)

diff .prev/block/ll_rw_blk.c ./block/ll_rw_blk.c
Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
上级 9cc54d40
...@@ -527,22 +527,36 @@ int blk_do_ordered(struct request_queue *q, struct request **rqp) ...@@ -527,22 +527,36 @@ int blk_do_ordered(struct request_queue *q, struct request **rqp)
return 1; return 1;
} }
static int ordered_bio_endio(struct request *rq, struct bio *bio, static void req_bio_endio(struct request *rq, struct bio *bio,
unsigned int nbytes, int error) unsigned int nbytes, int error)
{ {
struct request_queue *q = rq->q; struct request_queue *q = rq->q;
if (&q->bar_rq != rq) if (&q->bar_rq != rq) {
return 0; if (error)
clear_bit(BIO_UPTODATE, &bio->bi_flags);
else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
error = -EIO;
/* if (unlikely(nbytes > bio->bi_size)) {
* Okay, this is the barrier request in progress, just printk("%s: want %u bytes done, only %u left\n",
* record the error; __FUNCTION__, nbytes, bio->bi_size);
*/ nbytes = bio->bi_size;
if (error && !q->orderr) }
q->orderr = error;
return 1; bio->bi_size -= nbytes;
bio->bi_sector += (nbytes >> 9);
if (bio->bi_size == 0)
bio_endio(bio, bio->bi_size, error);
} else {
/*
* Okay, this is the barrier request in progress, just
* record the error;
*/
if (error && !q->orderr)
q->orderr = error;
}
} }
/** /**
...@@ -3388,8 +3402,7 @@ static int __end_that_request_first(struct request *req, int uptodate, ...@@ -3388,8 +3402,7 @@ static int __end_that_request_first(struct request *req, int uptodate,
if (nr_bytes >= bio->bi_size) { if (nr_bytes >= bio->bi_size) {
req->bio = bio->bi_next; req->bio = bio->bi_next;
nbytes = bio->bi_size; nbytes = bio->bi_size;
if (!ordered_bio_endio(req, bio, nbytes, error)) req_bio_endio(req, bio, nbytes, error);
bio_endio(bio, nbytes, error);
next_idx = 0; next_idx = 0;
bio_nbytes = 0; bio_nbytes = 0;
} else { } else {
...@@ -3444,8 +3457,7 @@ static int __end_that_request_first(struct request *req, int uptodate, ...@@ -3444,8 +3457,7 @@ static int __end_that_request_first(struct request *req, int uptodate,
* if the request wasn't completed, update state * if the request wasn't completed, update state
*/ */
if (bio_nbytes) { if (bio_nbytes) {
if (!ordered_bio_endio(req, bio, bio_nbytes, error)) req_bio_endio(req, bio, bio_nbytes, error);
bio_endio(bio, bio_nbytes, error);
bio->bi_idx += next_idx; bio->bi_idx += next_idx;
bio_iovec(bio)->bv_offset += nr_bytes; bio_iovec(bio)->bv_offset += nr_bytes;
bio_iovec(bio)->bv_len -= nr_bytes; bio_iovec(bio)->bv_len -= nr_bytes;
......
...@@ -1006,13 +1006,14 @@ void bio_check_pages_dirty(struct bio *bio) ...@@ -1006,13 +1006,14 @@ void bio_check_pages_dirty(struct bio *bio)
* @error: error, if any * @error: error, if any
* *
* Description: * Description:
* bio_endio() will end I/O on @bytes_done number of bytes. This may be * bio_endio() will end I/O on @bytes_done number of bytes. This
* just a partial part of the bio, or it may be the whole bio. bio_endio() * must always be the whole (remaining) bio. bio_endio() is the
* is the preferred way to end I/O on a bio, it takes care of decrementing * preferred way to end I/O on a bio, it takes care of clearing
* bi_size and clearing BIO_UPTODATE on error. @error is 0 on success, and * BIO_UPTODATE on error. @error is 0 on success, and and one of the
* and one of the established -Exxxx (-EIO, for instance) error values in * established -Exxxx (-EIO, for instance) error values in case
* case something went wrong. Noone should call bi_end_io() directly on * something went wrong. Noone should call bi_end_io() directly on a
* a bio unless they own it and thus know that it has an end_io function. * bio unless they own it and thus know that it has an end_io
* function.
**/ **/
void bio_endio(struct bio *bio, unsigned int bytes_done, int error) void bio_endio(struct bio *bio, unsigned int bytes_done, int error)
{ {
...@@ -1021,16 +1022,14 @@ void bio_endio(struct bio *bio, unsigned int bytes_done, int error) ...@@ -1021,16 +1022,14 @@ void bio_endio(struct bio *bio, unsigned int bytes_done, int error)
else if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
error = -EIO; error = -EIO;
if (unlikely(bytes_done > bio->bi_size)) { if (unlikely(bytes_done != bio->bi_size)) {
printk("%s: want %u bytes done, only %u left\n", __FUNCTION__, printk("%s: want %u bytes done, only %u left\n", __FUNCTION__,
bytes_done, bio->bi_size); bytes_done, bio->bi_size);
bytes_done = bio->bi_size; bytes_done = bio->bi_size;
} }
bio->bi_size -= bytes_done; bio->bi_size = 0; /* expected by some callees - will be removed */
bio->bi_sector += (bytes_done >> 9); if (bio->bi_end_io)
if (bio->bi_size && bio->bi_end_io)
bio->bi_end_io(bio, bytes_done, error); bio->bi_end_io(bio, bytes_done, error);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册