Commit 97565ed3 authored by Jens Axboe's avatar Jens Axboe

[PATCH] make bio->bi_end_io() optional

Sometimes we don't even need a bio->bi_end_io, so make it optional. This
also encourages users to _use_ bio_endio()! I like that, since it means
they don't have to remember to decrement bi_size themselves.

Also clear bi_private in bio_init(), and switch to subsys_initcall().
parent 14ff27c5
...@@ -1941,7 +1941,6 @@ int submit_bio(int rw, struct bio *bio) ...@@ -1941,7 +1941,6 @@ int submit_bio(int rw, struct bio *bio)
{ {
int count = bio_sectors(bio); int count = bio_sectors(bio);
BUG_ON(!bio->bi_end_io);
BIO_BUG_ON(!bio->bi_size); BIO_BUG_ON(!bio->bi_size);
BIO_BUG_ON(!bio->bi_io_vec); BIO_BUG_ON(!bio->bi_io_vec);
bio->bi_rw = rw; bio->bi_rw = rw;
......
...@@ -548,12 +548,7 @@ static void process_page(unsigned long data) ...@@ -548,12 +548,7 @@ static void process_page(unsigned long data)
return_bio = bio->bi_next; return_bio = bio->bi_next;
bio->bi_next = NULL; bio->bi_next = NULL;
/* should use bio_endio(), however already cleared bio_endio(bio, bio->bi_size, 0);
* BIO_UPTODATE. so set bio->bi_size = 0 manually to indicate
* completely done
*/
bio->bi_size = 0;
bio->bi_end_io(bio, bytes, 0);
} }
} }
......
...@@ -122,6 +122,7 @@ inline void bio_init(struct bio *bio) ...@@ -122,6 +122,7 @@ inline void bio_init(struct bio *bio)
bio->bi_max_vecs = 0; bio->bi_max_vecs = 0;
bio->bi_end_io = NULL; bio->bi_end_io = NULL;
atomic_set(&bio->bi_cnt, 1); atomic_set(&bio->bi_cnt, 1);
bio->bi_private = NULL;
} }
/** /**
...@@ -452,14 +453,15 @@ int bio_add_page(struct bio *bio, struct page *page, unsigned int len, ...@@ -452,14 +453,15 @@ int bio_add_page(struct bio *bio, struct page *page, unsigned int len,
* @error: error, if any * @error: error, if any
* *
* Description: * Description:
* bio_endio() will end I/O @bytes_done number of bytes. This may be just * bio_endio() will end I/O on @bytes_done number of bytes. This may be
* a partial part of the bio, or it may be the whole bio. bio_endio() is * just a partial part of the bio, or it may be the whole bio. bio_endio()
* the preferred way to end I/O on a bio, it takes care of decrementing * is the preferred way to end I/O on a bio, it takes care of decrementing
* bi_size and clearing BIO_UPTODATE on error. @error is 0 on success, and * bi_size and clearing BIO_UPTODATE on error. @error is 0 on success, and
* and one of the established -Exxxx (-EIO, for instance) error values in * and one of the established -Exxxx (-EIO, for instance) error values in
* case something went wrong. * case something went wrong. Noone should call bi_end_io() directly on
* a bio unless they own it and thus know that it has an end_io function.
**/ **/
int bio_endio(struct bio *bio, unsigned int bytes_done, int error) void bio_endio(struct bio *bio, unsigned int bytes_done, int error)
{ {
if (error) if (error)
clear_bit(BIO_UPTODATE, &bio->bi_flags); clear_bit(BIO_UPTODATE, &bio->bi_flags);
...@@ -471,7 +473,9 @@ int bio_endio(struct bio *bio, unsigned int bytes_done, int error) ...@@ -471,7 +473,9 @@ int bio_endio(struct bio *bio, unsigned int bytes_done, int error)
} }
bio->bi_size -= bytes_done; bio->bi_size -= bytes_done;
return bio->bi_end_io(bio, bytes_done, error);
if (bio->bi_end_io)
bio->bi_end_io(bio, bytes_done, error);
} }
static void __init biovec_init_pools(void) static void __init biovec_init_pools(void)
...@@ -543,7 +547,7 @@ static int __init init_bio(void) ...@@ -543,7 +547,7 @@ static int __init init_bio(void)
return 0; return 0;
} }
module_init(init_bio); subsys_initcall(init_bio);
EXPORT_SYMBOL(bio_alloc); EXPORT_SYMBOL(bio_alloc);
EXPORT_SYMBOL(bio_put); EXPORT_SYMBOL(bio_put);
......
...@@ -202,7 +202,7 @@ struct bio { ...@@ -202,7 +202,7 @@ struct bio {
extern struct bio *bio_alloc(int, int); extern struct bio *bio_alloc(int, int);
extern void bio_put(struct bio *); extern void bio_put(struct bio *);
extern int bio_endio(struct bio *, unsigned int, int); extern void bio_endio(struct bio *, unsigned int, int);
struct request_queue; struct request_queue;
extern inline int bio_phys_segments(struct request_queue *, struct bio *); extern inline int bio_phys_segments(struct request_queue *, struct bio *);
extern inline int bio_hw_segments(struct request_queue *, struct bio *); extern inline int bio_hw_segments(struct request_queue *, struct bio *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment