diff options
Diffstat (limited to 'fs/bio.c')
-rw-r--r-- | fs/bio.c | 73 |
1 files changed, 22 insertions, 51 deletions
@@ -109,11 +109,14 @@ static inline struct bio_vec *bvec_alloc_bs(gfp_t gfp_mask, int nr, unsigned lon | |||
109 | 109 | ||
110 | void bio_free(struct bio *bio, struct bio_set *bio_set) | 110 | void bio_free(struct bio *bio, struct bio_set *bio_set) |
111 | { | 111 | { |
112 | const int pool_idx = BIO_POOL_IDX(bio); | 112 | if (bio->bi_io_vec) { |
113 | const int pool_idx = BIO_POOL_IDX(bio); | ||
113 | 114 | ||
114 | BIO_BUG_ON(pool_idx >= BIOVEC_NR_POOLS); | 115 | BIO_BUG_ON(pool_idx >= BIOVEC_NR_POOLS); |
116 | |||
117 | mempool_free(bio->bi_io_vec, bio_set->bvec_pools[pool_idx]); | ||
118 | } | ||
115 | 119 | ||
116 | mempool_free(bio->bi_io_vec, bio_set->bvec_pools[pool_idx]); | ||
117 | mempool_free(bio, bio_set->bio_pool); | 120 | mempool_free(bio, bio_set->bio_pool); |
118 | } | 121 | } |
119 | 122 | ||
@@ -127,21 +130,9 @@ static void bio_fs_destructor(struct bio *bio) | |||
127 | 130 | ||
128 | void bio_init(struct bio *bio) | 131 | void bio_init(struct bio *bio) |
129 | { | 132 | { |
130 | bio->bi_next = NULL; | 133 | memset(bio, 0, sizeof(*bio)); |
131 | bio->bi_bdev = NULL; | ||
132 | bio->bi_flags = 1 << BIO_UPTODATE; | 134 | bio->bi_flags = 1 << BIO_UPTODATE; |
133 | bio->bi_rw = 0; | ||
134 | bio->bi_vcnt = 0; | ||
135 | bio->bi_idx = 0; | ||
136 | bio->bi_phys_segments = 0; | ||
137 | bio->bi_hw_segments = 0; | ||
138 | bio->bi_hw_front_size = 0; | ||
139 | bio->bi_hw_back_size = 0; | ||
140 | bio->bi_size = 0; | ||
141 | bio->bi_max_vecs = 0; | ||
142 | bio->bi_end_io = NULL; | ||
143 | atomic_set(&bio->bi_cnt, 1); | 135 | atomic_set(&bio->bi_cnt, 1); |
144 | bio->bi_private = NULL; | ||
145 | } | 136 | } |
146 | 137 | ||
147 | /** | 138 | /** |
@@ -798,13 +789,9 @@ void bio_unmap_user(struct bio *bio) | |||
798 | bio_put(bio); | 789 | bio_put(bio); |
799 | } | 790 | } |
800 | 791 | ||
801 | static int bio_map_kern_endio(struct bio *bio, unsigned int bytes_done, int err) | 792 | static void bio_map_kern_endio(struct bio *bio, int err) |
802 | { | 793 | { |
803 | if (bio->bi_size) | ||
804 | return 1; | ||
805 | |||
806 | bio_put(bio); | 794 | bio_put(bio); |
807 | return 0; | ||
808 | } | 795 | } |
809 | 796 | ||
810 | 797 | ||
@@ -1002,34 +989,26 @@ void bio_check_pages_dirty(struct bio *bio) | |||
1002 | /** | 989 | /** |
1003 | * bio_endio - end I/O on a bio | 990 | * bio_endio - end I/O on a bio |
1004 | * @bio: bio | 991 | * @bio: bio |
1005 | * @bytes_done: number of bytes completed | ||
1006 | * @error: error, if any | 992 | * @error: error, if any |
1007 | * | 993 | * |
1008 | * Description: | 994 | * Description: |
1009 | * bio_endio() will end I/O on @bytes_done number of bytes. This may be | 995 | * bio_endio() will end I/O on the whole bio. bio_endio() is the |
1010 | * just a partial part of the bio, or it may be the whole bio. bio_endio() | 996 | * preferred way to end I/O on a bio, it takes care of clearing |
1011 | * is the preferred way to end I/O on a bio, it takes care of decrementing | 997 | * BIO_UPTODATE on error. @error is 0 on success, and and one of the |
1012 | * bi_size and clearing BIO_UPTODATE on error. @error is 0 on success, and | 998 | * established -Exxxx (-EIO, for instance) error values in case |
1013 | * and one of the established -Exxxx (-EIO, for instance) error values in | 999 | * something went wrong. Noone should call bi_end_io() directly on a |
1014 | * case something went wrong. Noone should call bi_end_io() directly on | 1000 | * bio unless they own it and thus know that it has an end_io |
1015 | * a bio unless they own it and thus know that it has an end_io function. | 1001 | * function. |
1016 | **/ | 1002 | **/ |
1017 | void bio_endio(struct bio *bio, unsigned int bytes_done, int error) | 1003 | void bio_endio(struct bio *bio, int error) |
1018 | { | 1004 | { |
1019 | if (error) | 1005 | if (error) |
1020 | clear_bit(BIO_UPTODATE, &bio->bi_flags); | 1006 | clear_bit(BIO_UPTODATE, &bio->bi_flags); |
1021 | 1007 | else if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) | |
1022 | if (unlikely(bytes_done > bio->bi_size)) { | 1008 | error = -EIO; |
1023 | printk("%s: want %u bytes done, only %u left\n", __FUNCTION__, | ||
1024 | bytes_done, bio->bi_size); | ||
1025 | bytes_done = bio->bi_size; | ||
1026 | } | ||
1027 | |||
1028 | bio->bi_size -= bytes_done; | ||
1029 | bio->bi_sector += (bytes_done >> 9); | ||
1030 | 1009 | ||
1031 | if (bio->bi_end_io) | 1010 | if (bio->bi_end_io) |
1032 | bio->bi_end_io(bio, bytes_done, error); | 1011 | bio->bi_end_io(bio, error); |
1033 | } | 1012 | } |
1034 | 1013 | ||
1035 | void bio_pair_release(struct bio_pair *bp) | 1014 | void bio_pair_release(struct bio_pair *bp) |
@@ -1037,37 +1016,29 @@ void bio_pair_release(struct bio_pair *bp) | |||
1037 | if (atomic_dec_and_test(&bp->cnt)) { | 1016 | if (atomic_dec_and_test(&bp->cnt)) { |
1038 | struct bio *master = bp->bio1.bi_private; | 1017 | struct bio *master = bp->bio1.bi_private; |
1039 | 1018 | ||
1040 | bio_endio(master, master->bi_size, bp->error); | 1019 | bio_endio(master, bp->error); |
1041 | mempool_free(bp, bp->bio2.bi_private); | 1020 | mempool_free(bp, bp->bio2.bi_private); |
1042 | } | 1021 | } |
1043 | } | 1022 | } |
1044 | 1023 | ||
1045 | static int bio_pair_end_1(struct bio * bi, unsigned int done, int err) | 1024 | static void bio_pair_end_1(struct bio *bi, int err) |
1046 | { | 1025 | { |
1047 | struct bio_pair *bp = container_of(bi, struct bio_pair, bio1); | 1026 | struct bio_pair *bp = container_of(bi, struct bio_pair, bio1); |
1048 | 1027 | ||
1049 | if (err) | 1028 | if (err) |
1050 | bp->error = err; | 1029 | bp->error = err; |
1051 | 1030 | ||
1052 | if (bi->bi_size) | ||
1053 | return 1; | ||
1054 | |||
1055 | bio_pair_release(bp); | 1031 | bio_pair_release(bp); |
1056 | return 0; | ||
1057 | } | 1032 | } |
1058 | 1033 | ||
1059 | static int bio_pair_end_2(struct bio * bi, unsigned int done, int err) | 1034 | static void bio_pair_end_2(struct bio *bi, int err) |
1060 | { | 1035 | { |
1061 | struct bio_pair *bp = container_of(bi, struct bio_pair, bio2); | 1036 | struct bio_pair *bp = container_of(bi, struct bio_pair, bio2); |
1062 | 1037 | ||
1063 | if (err) | 1038 | if (err) |
1064 | bp->error = err; | 1039 | bp->error = err; |
1065 | 1040 | ||
1066 | if (bi->bi_size) | ||
1067 | return 1; | ||
1068 | |||
1069 | bio_pair_release(bp); | 1041 | bio_pair_release(bp); |
1070 | return 0; | ||
1071 | } | 1042 | } |
1072 | 1043 | ||
1073 | /* | 1044 | /* |