diff options
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/btrfs/check-integrity.c | 2 | ||||
| -rw-r--r-- | fs/btrfs/disk-io.c | 2 | ||||
| -rw-r--r-- | fs/btrfs/extent_io.c | 49 | ||||
| -rw-r--r-- | fs/btrfs/extent_io.h | 2 | ||||
| -rw-r--r-- | fs/btrfs/inode.c | 64 | ||||
| -rw-r--r-- | fs/btrfs/raid56.c | 2 | ||||
| -rw-r--r-- | fs/btrfs/scrub.c | 10 | ||||
| -rw-r--r-- | fs/btrfs/volumes.c | 41 | ||||
| -rw-r--r-- | fs/btrfs/volumes.h | 20 |
9 files changed, 120 insertions, 72 deletions
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index 18af6f48781a..1431a6965017 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c | |||
| @@ -1700,7 +1700,7 @@ static int btrfsic_read_block(struct btrfsic_state *state, | |||
| 1700 | unsigned int j; | 1700 | unsigned int j; |
| 1701 | DECLARE_COMPLETION_ONSTACK(complete); | 1701 | DECLARE_COMPLETION_ONSTACK(complete); |
| 1702 | 1702 | ||
| 1703 | bio = bio_alloc(GFP_NOFS, num_pages - i); | 1703 | bio = btrfs_io_bio_alloc(GFP_NOFS, num_pages - i); |
| 1704 | if (!bio) { | 1704 | if (!bio) { |
| 1705 | printk(KERN_INFO | 1705 | printk(KERN_INFO |
| 1706 | "btrfsic: bio_alloc() for %u pages failed!\n", | 1706 | "btrfsic: bio_alloc() for %u pages failed!\n", |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4bdb0528688a..e7b3cb5286a5 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
| @@ -3130,7 +3130,7 @@ static int write_dev_flush(struct btrfs_device *device, int wait) | |||
| 3130 | * caller | 3130 | * caller |
| 3131 | */ | 3131 | */ |
| 3132 | device->flush_bio = NULL; | 3132 | device->flush_bio = NULL; |
| 3133 | bio = bio_alloc(GFP_NOFS, 0); | 3133 | bio = btrfs_io_bio_alloc(GFP_NOFS, 0); |
| 3134 | if (!bio) | 3134 | if (!bio) |
| 3135 | return -ENOMEM; | 3135 | return -ENOMEM; |
| 3136 | 3136 | ||
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index ca4355ddea06..b306b3a88fc7 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | 23 | ||
| 24 | static struct kmem_cache *extent_state_cache; | 24 | static struct kmem_cache *extent_state_cache; |
| 25 | static struct kmem_cache *extent_buffer_cache; | 25 | static struct kmem_cache *extent_buffer_cache; |
| 26 | static struct bio_set *btrfs_bioset; | ||
| 26 | 27 | ||
| 27 | #ifdef CONFIG_BTRFS_DEBUG | 28 | #ifdef CONFIG_BTRFS_DEBUG |
| 28 | static LIST_HEAD(buffers); | 29 | static LIST_HEAD(buffers); |
| @@ -125,10 +126,20 @@ int __init extent_io_init(void) | |||
| 125 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 126 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); |
| 126 | if (!extent_buffer_cache) | 127 | if (!extent_buffer_cache) |
| 127 | goto free_state_cache; | 128 | goto free_state_cache; |
| 129 | |||
| 130 | btrfs_bioset = bioset_create(BIO_POOL_SIZE, | ||
| 131 | offsetof(struct btrfs_io_bio, bio)); | ||
| 132 | if (!btrfs_bioset) | ||
| 133 | goto free_buffer_cache; | ||
| 128 | return 0; | 134 | return 0; |
| 129 | 135 | ||
| 136 | free_buffer_cache: | ||
| 137 | kmem_cache_destroy(extent_buffer_cache); | ||
| 138 | extent_buffer_cache = NULL; | ||
| 139 | |||
| 130 | free_state_cache: | 140 | free_state_cache: |
| 131 | kmem_cache_destroy(extent_state_cache); | 141 | kmem_cache_destroy(extent_state_cache); |
| 142 | extent_state_cache = NULL; | ||
| 132 | return -ENOMEM; | 143 | return -ENOMEM; |
| 133 | } | 144 | } |
| 134 | 145 | ||
| @@ -145,6 +156,8 @@ void extent_io_exit(void) | |||
| 145 | kmem_cache_destroy(extent_state_cache); | 156 | kmem_cache_destroy(extent_state_cache); |
| 146 | if (extent_buffer_cache) | 157 | if (extent_buffer_cache) |
| 147 | kmem_cache_destroy(extent_buffer_cache); | 158 | kmem_cache_destroy(extent_buffer_cache); |
| 159 | if (btrfs_bioset) | ||
| 160 | bioset_free(btrfs_bioset); | ||
| 148 | } | 161 | } |
| 149 | 162 | ||
| 150 | void extent_io_tree_init(struct extent_io_tree *tree, | 163 | void extent_io_tree_init(struct extent_io_tree *tree, |
| @@ -2024,7 +2037,7 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start, | |||
| 2024 | if (btrfs_is_parity_mirror(map_tree, logical, length, mirror_num)) | 2037 | if (btrfs_is_parity_mirror(map_tree, logical, length, mirror_num)) |
| 2025 | return 0; | 2038 | return 0; |
| 2026 | 2039 | ||
| 2027 | bio = bio_alloc(GFP_NOFS, 1); | 2040 | bio = btrfs_io_bio_alloc(GFP_NOFS, 1); |
| 2028 | if (!bio) | 2041 | if (!bio) |
| 2029 | return -EIO; | 2042 | return -EIO; |
| 2030 | bio->bi_private = &compl; | 2043 | bio->bi_private = &compl; |
| @@ -2314,7 +2327,7 @@ static int bio_readpage_error(struct bio *failed_bio, struct page *page, | |||
| 2314 | return -EIO; | 2327 | return -EIO; |
| 2315 | } | 2328 | } |
| 2316 | 2329 | ||
| 2317 | bio = bio_alloc(GFP_NOFS, 1); | 2330 | bio = btrfs_io_bio_alloc(GFP_NOFS, 1); |
| 2318 | if (!bio) { | 2331 | if (!bio) { |
| 2319 | free_io_failure(inode, failrec, 0); | 2332 | free_io_failure(inode, failrec, 0); |
| 2320 | return -EIO; | 2333 | return -EIO; |
| @@ -2436,10 +2449,11 @@ static void end_bio_extent_readpage(struct bio *bio, int err) | |||
| 2436 | struct page *page = bvec->bv_page; | 2449 | struct page *page = bvec->bv_page; |
| 2437 | struct extent_state *cached = NULL; | 2450 | struct extent_state *cached = NULL; |
| 2438 | struct extent_state *state; | 2451 | struct extent_state *state; |
| 2452 | struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); | ||
| 2439 | 2453 | ||
| 2440 | pr_debug("end_bio_extent_readpage: bi_sector=%llu, err=%d, " | 2454 | pr_debug("end_bio_extent_readpage: bi_sector=%llu, err=%d, " |
| 2441 | "mirror=%ld\n", (u64)bio->bi_sector, err, | 2455 | "mirror=%lu\n", (u64)bio->bi_sector, err, |
| 2442 | (long int)bio->bi_bdev); | 2456 | io_bio->mirror_num); |
| 2443 | tree = &BTRFS_I(page->mapping->host)->io_tree; | 2457 | tree = &BTRFS_I(page->mapping->host)->io_tree; |
| 2444 | 2458 | ||
| 2445 | /* We always issue full-page reads, but if some block | 2459 | /* We always issue full-page reads, but if some block |
| @@ -2470,7 +2484,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err) | |||
| 2470 | } | 2484 | } |
| 2471 | spin_unlock(&tree->lock); | 2485 | spin_unlock(&tree->lock); |
| 2472 | 2486 | ||
| 2473 | mirror = (int)(unsigned long)bio->bi_bdev; | 2487 | mirror = io_bio->mirror_num; |
| 2474 | if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { | 2488 | if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { |
| 2475 | ret = tree->ops->readpage_end_io_hook(page, start, end, | 2489 | ret = tree->ops->readpage_end_io_hook(page, start, end, |
| 2476 | state, mirror); | 2490 | state, mirror); |
| @@ -2525,17 +2539,23 @@ static void end_bio_extent_readpage(struct bio *bio, int err) | |||
| 2525 | bio_put(bio); | 2539 | bio_put(bio); |
| 2526 | } | 2540 | } |
| 2527 | 2541 | ||
| 2542 | /* | ||
| 2543 | * this allocates from the btrfs_bioset. We're returning a bio right now | ||
| 2544 | * but you can call btrfs_io_bio for the appropriate container_of magic | ||
| 2545 | */ | ||
| 2528 | struct bio * | 2546 | struct bio * |
| 2529 | btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, | 2547 | btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, |
| 2530 | gfp_t gfp_flags) | 2548 | gfp_t gfp_flags) |
| 2531 | { | 2549 | { |
| 2532 | struct bio *bio; | 2550 | struct bio *bio; |
| 2533 | 2551 | ||
| 2534 | bio = bio_alloc(gfp_flags, nr_vecs); | 2552 | bio = bio_alloc_bioset(gfp_flags, nr_vecs, btrfs_bioset); |
| 2535 | 2553 | ||
| 2536 | if (bio == NULL && (current->flags & PF_MEMALLOC)) { | 2554 | if (bio == NULL && (current->flags & PF_MEMALLOC)) { |
| 2537 | while (!bio && (nr_vecs /= 2)) | 2555 | while (!bio && (nr_vecs /= 2)) { |
| 2538 | bio = bio_alloc(gfp_flags, nr_vecs); | 2556 | bio = bio_alloc_bioset(gfp_flags, |
| 2557 | nr_vecs, btrfs_bioset); | ||
| 2558 | } | ||
| 2539 | } | 2559 | } |
| 2540 | 2560 | ||
| 2541 | if (bio) { | 2561 | if (bio) { |
| @@ -2546,6 +2566,19 @@ btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, | |||
| 2546 | return bio; | 2566 | return bio; |
| 2547 | } | 2567 | } |
| 2548 | 2568 | ||
| 2569 | struct bio *btrfs_bio_clone(struct bio *bio, gfp_t gfp_mask) | ||
| 2570 | { | ||
| 2571 | return bio_clone_bioset(bio, gfp_mask, btrfs_bioset); | ||
| 2572 | } | ||
| 2573 | |||
| 2574 | |||
| 2575 | /* this also allocates from the btrfs_bioset */ | ||
| 2576 | struct bio *btrfs_io_bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs) | ||
| 2577 | { | ||
| 2578 | return bio_alloc_bioset(gfp_mask, nr_iovecs, btrfs_bioset); | ||
| 2579 | } | ||
| 2580 | |||
| 2581 | |||
| 2549 | static int __must_check submit_one_bio(int rw, struct bio *bio, | 2582 | static int __must_check submit_one_bio(int rw, struct bio *bio, |
| 2550 | int mirror_num, unsigned long bio_flags) | 2583 | int mirror_num, unsigned long bio_flags) |
| 2551 | { | 2584 | { |
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index a2c03a175009..41fb81e7ec53 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h | |||
| @@ -336,6 +336,8 @@ int extent_clear_unlock_delalloc(struct inode *inode, | |||
| 336 | struct bio * | 336 | struct bio * |
| 337 | btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, | 337 | btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, |
| 338 | gfp_t gfp_flags); | 338 | gfp_t gfp_flags); |
| 339 | struct bio *btrfs_io_bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs); | ||
| 340 | struct bio *btrfs_bio_clone(struct bio *bio, gfp_t gfp_mask); | ||
| 339 | 341 | ||
| 340 | struct btrfs_fs_info; | 342 | struct btrfs_fs_info; |
| 341 | 343 | ||
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 19eef3e852b0..23c596cd1b98 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
| @@ -6931,7 +6931,11 @@ struct btrfs_dio_private { | |||
| 6931 | /* IO errors */ | 6931 | /* IO errors */ |
| 6932 | int errors; | 6932 | int errors; |
| 6933 | 6933 | ||
| 6934 | /* orig_bio is our btrfs_io_bio */ | ||
| 6934 | struct bio *orig_bio; | 6935 | struct bio *orig_bio; |
| 6936 | |||
| 6937 | /* dio_bio came from fs/direct-io.c */ | ||
| 6938 | struct bio *dio_bio; | ||
| 6935 | }; | 6939 | }; |
| 6936 | 6940 | ||
| 6937 | static void btrfs_endio_direct_read(struct bio *bio, int err) | 6941 | static void btrfs_endio_direct_read(struct bio *bio, int err) |
| @@ -6941,6 +6945,7 @@ static void btrfs_endio_direct_read(struct bio *bio, int err) | |||
| 6941 | struct bio_vec *bvec = bio->bi_io_vec; | 6945 | struct bio_vec *bvec = bio->bi_io_vec; |
| 6942 | struct inode *inode = dip->inode; | 6946 | struct inode *inode = dip->inode; |
| 6943 | struct btrfs_root *root = BTRFS_I(inode)->root; | 6947 | struct btrfs_root *root = BTRFS_I(inode)->root; |
| 6948 | struct bio *dio_bio; | ||
| 6944 | u64 start; | 6949 | u64 start; |
| 6945 | 6950 | ||
| 6946 | start = dip->logical_offset; | 6951 | start = dip->logical_offset; |
| @@ -6980,14 +6985,15 @@ failed: | |||
| 6980 | 6985 | ||
| 6981 | unlock_extent(&BTRFS_I(inode)->io_tree, dip->logical_offset, | 6986 | unlock_extent(&BTRFS_I(inode)->io_tree, dip->logical_offset, |
| 6982 | dip->logical_offset + dip->bytes - 1); | 6987 | dip->logical_offset + dip->bytes - 1); |
| 6983 | bio->bi_private = dip->private; | 6988 | dio_bio = dip->dio_bio; |
| 6984 | 6989 | ||
| 6985 | kfree(dip); | 6990 | kfree(dip); |
| 6986 | 6991 | ||
| 6987 | /* If we had a csum failure make sure to clear the uptodate flag */ | 6992 | /* If we had a csum failure make sure to clear the uptodate flag */ |
| 6988 | if (err) | 6993 | if (err) |
| 6989 | clear_bit(BIO_UPTODATE, &bio->bi_flags); | 6994 | clear_bit(BIO_UPTODATE, &dio_bio->bi_flags); |
| 6990 | dio_end_io(bio, err); | 6995 | dio_end_io(dio_bio, err); |
| 6996 | bio_put(bio); | ||
| 6991 | } | 6997 | } |
| 6992 | 6998 | ||
| 6993 | static void btrfs_endio_direct_write(struct bio *bio, int err) | 6999 | static void btrfs_endio_direct_write(struct bio *bio, int err) |
| @@ -6998,6 +7004,7 @@ static void btrfs_endio_direct_write(struct bio *bio, int err) | |||
| 6998 | struct btrfs_ordered_extent *ordered = NULL; | 7004 | struct btrfs_ordered_extent *ordered = NULL; |
| 6999 | u64 ordered_offset = dip->logical_offset; | 7005 | u64 ordered_offset = dip->logical_offset; |
| 7000 | u64 ordered_bytes = dip->bytes; | 7006 | u64 ordered_bytes = dip->bytes; |
| 7007 | struct bio *dio_bio; | ||
| 7001 | int ret; | 7008 | int ret; |
| 7002 | 7009 | ||
| 7003 | if (err) | 7010 | if (err) |
| @@ -7025,14 +7032,15 @@ out_test: | |||
| 7025 | goto again; | 7032 | goto again; |
| 7026 | } | 7033 | } |
| 7027 | out_done: | 7034 | out_done: |
| 7028 | bio->bi_private = dip->private; | 7035 | dio_bio = dip->dio_bio; |
| 7029 | 7036 | ||
| 7030 | kfree(dip); | 7037 | kfree(dip); |
| 7031 | 7038 | ||
| 7032 | /* If we had an error make sure to clear the uptodate flag */ | 7039 | /* If we had an error make sure to clear the uptodate flag */ |
| 7033 | if (err) | 7040 | if (err) |
| 7034 | clear_bit(BIO_UPTODATE, &bio->bi_flags); | 7041 | clear_bit(BIO_UPTODATE, &dio_bio->bi_flags); |
| 7035 | dio_end_io(bio, err); | 7042 | dio_end_io(dio_bio, err); |
| 7043 | bio_put(bio); | ||
| 7036 | } | 7044 | } |
| 7037 | 7045 | ||
| 7038 | static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw, | 7046 | static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw, |
| @@ -7068,10 +7076,10 @@ static void btrfs_end_dio_bio(struct bio *bio, int err) | |||
| 7068 | if (!atomic_dec_and_test(&dip->pending_bios)) | 7076 | if (!atomic_dec_and_test(&dip->pending_bios)) |
| 7069 | goto out; | 7077 | goto out; |
| 7070 | 7078 | ||
| 7071 | if (dip->errors) | 7079 | if (dip->errors) { |
| 7072 | bio_io_error(dip->orig_bio); | 7080 | bio_io_error(dip->orig_bio); |
| 7073 | else { | 7081 | } else { |
| 7074 | set_bit(BIO_UPTODATE, &dip->orig_bio->bi_flags); | 7082 | set_bit(BIO_UPTODATE, &dip->dio_bio->bi_flags); |
| 7075 | bio_endio(dip->orig_bio, 0); | 7083 | bio_endio(dip->orig_bio, 0); |
| 7076 | } | 7084 | } |
| 7077 | out: | 7085 | out: |
| @@ -7246,25 +7254,34 @@ out_err: | |||
| 7246 | return 0; | 7254 | return 0; |
| 7247 | } | 7255 | } |
| 7248 | 7256 | ||
| 7249 | static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode, | 7257 | static void btrfs_submit_direct(int rw, struct bio *dio_bio, |
| 7250 | loff_t file_offset) | 7258 | struct inode *inode, loff_t file_offset) |
| 7251 | { | 7259 | { |
| 7252 | struct btrfs_root *root = BTRFS_I(inode)->root; | 7260 | struct btrfs_root *root = BTRFS_I(inode)->root; |
| 7253 | struct btrfs_dio_private *dip; | 7261 | struct btrfs_dio_private *dip; |
| 7254 | struct bio_vec *bvec = bio->bi_io_vec; | 7262 | struct bio_vec *bvec = dio_bio->bi_io_vec; |
| 7263 | struct bio *io_bio; | ||
| 7255 | int skip_sum; | 7264 | int skip_sum; |
| 7256 | int write = rw & REQ_WRITE; | 7265 | int write = rw & REQ_WRITE; |
| 7257 | int ret = 0; | 7266 | int ret = 0; |
| 7258 | 7267 | ||
| 7259 | skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; | 7268 | skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; |
| 7260 | 7269 | ||
| 7270 | io_bio = btrfs_bio_clone(dio_bio, GFP_NOFS); | ||
| 7271 | |||
| 7272 | if (!io_bio) { | ||
| 7273 | ret = -ENOMEM; | ||
| 7274 | goto free_ordered; | ||
| 7275 | } | ||
| 7276 | |||
| 7261 | dip = kmalloc(sizeof(*dip), GFP_NOFS); | 7277 | dip = kmalloc(sizeof(*dip), GFP_NOFS); |
| 7262 | if (!dip) { | 7278 | if (!dip) { |
| 7263 | ret = -ENOMEM; | 7279 | ret = -ENOMEM; |
| 7264 | goto free_ordered; | 7280 | goto free_io_bio; |
| 7265 | } | 7281 | } |
| 7266 | 7282 | ||
| 7267 | dip->private = bio->bi_private; | 7283 | dip->private = dio_bio->bi_private; |
| 7284 | io_bio->bi_private = dio_bio->bi_private; | ||
| 7268 | dip->inode = inode; | 7285 | dip->inode = inode; |
| 7269 | dip->logical_offset = file_offset; | 7286 | dip->logical_offset = file_offset; |
| 7270 | 7287 | ||
| @@ -7272,22 +7289,27 @@ static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode, | |||
| 7272 | do { | 7289 | do { |
| 7273 | dip->bytes += bvec->bv_len; | 7290 | dip->bytes += bvec->bv_len; |
| 7274 | bvec++; | 7291 | bvec++; |
| 7275 | } while (bvec <= (bio->bi_io_vec + bio->bi_vcnt - 1)); | 7292 | } while (bvec <= (dio_bio->bi_io_vec + dio_bio->bi_vcnt - 1)); |
| 7276 | 7293 | ||
| 7277 | dip->disk_bytenr = (u64)bio->bi_sector << 9; | 7294 | dip->disk_bytenr = (u64)dio_bio->bi_sector << 9; |
| 7278 | bio->bi_private = dip; | 7295 | io_bio->bi_private = dip; |
| 7279 | dip->errors = 0; | 7296 | dip->errors = 0; |
| 7280 | dip->orig_bio = bio; | 7297 | dip->orig_bio = io_bio; |
| 7298 | dip->dio_bio = dio_bio; | ||
| 7281 | atomic_set(&dip->pending_bios, 0); | 7299 | atomic_set(&dip->pending_bios, 0); |
| 7282 | 7300 | ||
| 7283 | if (write) | 7301 | if (write) |
| 7284 | bio->bi_end_io = btrfs_endio_direct_write; | 7302 | io_bio->bi_end_io = btrfs_endio_direct_write; |
| 7285 | else | 7303 | else |
| 7286 | bio->bi_end_io = btrfs_endio_direct_read; | 7304 | io_bio->bi_end_io = btrfs_endio_direct_read; |
| 7287 | 7305 | ||
| 7288 | ret = btrfs_submit_direct_hook(rw, dip, skip_sum); | 7306 | ret = btrfs_submit_direct_hook(rw, dip, skip_sum); |
| 7289 | if (!ret) | 7307 | if (!ret) |
| 7290 | return; | 7308 | return; |
| 7309 | |||
| 7310 | free_io_bio: | ||
| 7311 | bio_put(io_bio); | ||
| 7312 | |||
| 7291 | free_ordered: | 7313 | free_ordered: |
| 7292 | /* | 7314 | /* |
| 7293 | * If this is a write, we need to clean up the reserved space and kill | 7315 | * If this is a write, we need to clean up the reserved space and kill |
| @@ -7303,7 +7325,7 @@ free_ordered: | |||
| 7303 | btrfs_put_ordered_extent(ordered); | 7325 | btrfs_put_ordered_extent(ordered); |
| 7304 | btrfs_put_ordered_extent(ordered); | 7326 | btrfs_put_ordered_extent(ordered); |
| 7305 | } | 7327 | } |
| 7306 | bio_endio(bio, ret); | 7328 | bio_endio(dio_bio, ret); |
| 7307 | } | 7329 | } |
| 7308 | 7330 | ||
| 7309 | static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb, | 7331 | static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb, |
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index 0740621daf6c..0525e1389f5b 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c | |||
| @@ -1050,7 +1050,7 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio, | |||
| 1050 | } | 1050 | } |
| 1051 | 1051 | ||
| 1052 | /* put a new bio on the list */ | 1052 | /* put a new bio on the list */ |
| 1053 | bio = bio_alloc(GFP_NOFS, bio_max_len >> PAGE_SHIFT?:1); | 1053 | bio = btrfs_io_bio_alloc(GFP_NOFS, bio_max_len >> PAGE_SHIFT?:1); |
| 1054 | if (!bio) | 1054 | if (!bio) |
| 1055 | return -ENOMEM; | 1055 | return -ENOMEM; |
| 1056 | 1056 | ||
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index f489e24659a4..79bd479317cb 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
| @@ -1296,7 +1296,7 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info, | |||
| 1296 | } | 1296 | } |
| 1297 | 1297 | ||
| 1298 | WARN_ON(!page->page); | 1298 | WARN_ON(!page->page); |
| 1299 | bio = bio_alloc(GFP_NOFS, 1); | 1299 | bio = btrfs_io_bio_alloc(GFP_NOFS, 1); |
| 1300 | if (!bio) { | 1300 | if (!bio) { |
| 1301 | page->io_error = 1; | 1301 | page->io_error = 1; |
| 1302 | sblock->no_io_error_seen = 0; | 1302 | sblock->no_io_error_seen = 0; |
| @@ -1431,7 +1431,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad, | |||
| 1431 | return -EIO; | 1431 | return -EIO; |
| 1432 | } | 1432 | } |
| 1433 | 1433 | ||
| 1434 | bio = bio_alloc(GFP_NOFS, 1); | 1434 | bio = btrfs_io_bio_alloc(GFP_NOFS, 1); |
| 1435 | if (!bio) | 1435 | if (!bio) |
| 1436 | return -EIO; | 1436 | return -EIO; |
| 1437 | bio->bi_bdev = page_bad->dev->bdev; | 1437 | bio->bi_bdev = page_bad->dev->bdev; |
| @@ -1522,7 +1522,7 @@ again: | |||
| 1522 | sbio->dev = wr_ctx->tgtdev; | 1522 | sbio->dev = wr_ctx->tgtdev; |
| 1523 | bio = sbio->bio; | 1523 | bio = sbio->bio; |
| 1524 | if (!bio) { | 1524 | if (!bio) { |
| 1525 | bio = bio_alloc(GFP_NOFS, wr_ctx->pages_per_wr_bio); | 1525 | bio = btrfs_io_bio_alloc(GFP_NOFS, wr_ctx->pages_per_wr_bio); |
| 1526 | if (!bio) { | 1526 | if (!bio) { |
| 1527 | mutex_unlock(&wr_ctx->wr_lock); | 1527 | mutex_unlock(&wr_ctx->wr_lock); |
| 1528 | return -ENOMEM; | 1528 | return -ENOMEM; |
| @@ -1930,7 +1930,7 @@ again: | |||
| 1930 | sbio->dev = spage->dev; | 1930 | sbio->dev = spage->dev; |
| 1931 | bio = sbio->bio; | 1931 | bio = sbio->bio; |
| 1932 | if (!bio) { | 1932 | if (!bio) { |
| 1933 | bio = bio_alloc(GFP_NOFS, sctx->pages_per_rd_bio); | 1933 | bio = btrfs_io_bio_alloc(GFP_NOFS, sctx->pages_per_rd_bio); |
| 1934 | if (!bio) | 1934 | if (!bio) |
| 1935 | return -ENOMEM; | 1935 | return -ENOMEM; |
| 1936 | sbio->bio = bio; | 1936 | sbio->bio = bio; |
| @@ -3307,7 +3307,7 @@ static int write_page_nocow(struct scrub_ctx *sctx, | |||
| 3307 | "btrfs: scrub write_page_nocow(bdev == NULL) is unexpected!\n"); | 3307 | "btrfs: scrub write_page_nocow(bdev == NULL) is unexpected!\n"); |
| 3308 | return -EIO; | 3308 | return -EIO; |
| 3309 | } | 3309 | } |
| 3310 | bio = bio_alloc(GFP_NOFS, 1); | 3310 | bio = btrfs_io_bio_alloc(GFP_NOFS, 1); |
| 3311 | if (!bio) { | 3311 | if (!bio) { |
| 3312 | spin_lock(&sctx->stat_lock); | 3312 | spin_lock(&sctx->stat_lock); |
| 3313 | sctx->stat.malloc_errors++; | 3313 | sctx->stat.malloc_errors++; |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 062e93069c5e..24940085cdac 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
| @@ -5018,42 +5018,16 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, | |||
| 5018 | return 0; | 5018 | return 0; |
| 5019 | } | 5019 | } |
| 5020 | 5020 | ||
| 5021 | static void *merge_stripe_index_into_bio_private(void *bi_private, | ||
| 5022 | unsigned int stripe_index) | ||
| 5023 | { | ||
| 5024 | /* | ||
| 5025 | * with single, dup, RAID0, RAID1 and RAID10, stripe_index is | ||
| 5026 | * at most 1. | ||
| 5027 | * The alternative solution (instead of stealing bits from the | ||
| 5028 | * pointer) would be to allocate an intermediate structure | ||
| 5029 | * that contains the old private pointer plus the stripe_index. | ||
| 5030 | */ | ||
| 5031 | BUG_ON((((uintptr_t)bi_private) & 3) != 0); | ||
| 5032 | BUG_ON(stripe_index > 3); | ||
| 5033 | return (void *)(((uintptr_t)bi_private) | stripe_index); | ||
| 5034 | } | ||
| 5035 | |||
| 5036 | static struct btrfs_bio *extract_bbio_from_bio_private(void *bi_private) | ||
| 5037 | { | ||
| 5038 | return (struct btrfs_bio *)(((uintptr_t)bi_private) & ~((uintptr_t)3)); | ||
| 5039 | } | ||
| 5040 | |||
| 5041 | static unsigned int extract_stripe_index_from_bio_private(void *bi_private) | ||
| 5042 | { | ||
| 5043 | return (unsigned int)((uintptr_t)bi_private) & 3; | ||
| 5044 | } | ||
| 5045 | |||
| 5046 | static void btrfs_end_bio(struct bio *bio, int err) | 5021 | static void btrfs_end_bio(struct bio *bio, int err) |
| 5047 | { | 5022 | { |
| 5048 | struct btrfs_bio *bbio = extract_bbio_from_bio_private(bio->bi_private); | 5023 | struct btrfs_bio *bbio = bio->bi_private; |
| 5049 | int is_orig_bio = 0; | 5024 | int is_orig_bio = 0; |
| 5050 | 5025 | ||
| 5051 | if (err) { | 5026 | if (err) { |
| 5052 | atomic_inc(&bbio->error); | 5027 | atomic_inc(&bbio->error); |
| 5053 | if (err == -EIO || err == -EREMOTEIO) { | 5028 | if (err == -EIO || err == -EREMOTEIO) { |
| 5054 | unsigned int stripe_index = | 5029 | unsigned int stripe_index = |
| 5055 | extract_stripe_index_from_bio_private( | 5030 | btrfs_io_bio(bio)->stripe_index; |
| 5056 | bio->bi_private); | ||
| 5057 | struct btrfs_device *dev; | 5031 | struct btrfs_device *dev; |
| 5058 | 5032 | ||
| 5059 | BUG_ON(stripe_index >= bbio->num_stripes); | 5033 | BUG_ON(stripe_index >= bbio->num_stripes); |
| @@ -5083,8 +5057,7 @@ static void btrfs_end_bio(struct bio *bio, int err) | |||
| 5083 | } | 5057 | } |
| 5084 | bio->bi_private = bbio->private; | 5058 | bio->bi_private = bbio->private; |
| 5085 | bio->bi_end_io = bbio->end_io; | 5059 | bio->bi_end_io = bbio->end_io; |
| 5086 | bio->bi_bdev = (struct block_device *) | 5060 | btrfs_io_bio(bio)->mirror_num = bbio->mirror_num; |
| 5087 | (unsigned long)bbio->mirror_num; | ||
| 5088 | /* only send an error to the higher layers if it is | 5061 | /* only send an error to the higher layers if it is |
| 5089 | * beyond the tolerance of the btrfs bio | 5062 | * beyond the tolerance of the btrfs bio |
| 5090 | */ | 5063 | */ |
| @@ -5210,8 +5183,7 @@ static void submit_stripe_bio(struct btrfs_root *root, struct btrfs_bio *bbio, | |||
| 5210 | struct btrfs_device *dev = bbio->stripes[dev_nr].dev; | 5183 | struct btrfs_device *dev = bbio->stripes[dev_nr].dev; |
| 5211 | 5184 | ||
| 5212 | bio->bi_private = bbio; | 5185 | bio->bi_private = bbio; |
| 5213 | bio->bi_private = merge_stripe_index_into_bio_private( | 5186 | btrfs_io_bio(bio)->stripe_index = dev_nr; |
| 5214 | bio->bi_private, (unsigned int)dev_nr); | ||
| 5215 | bio->bi_end_io = btrfs_end_bio; | 5187 | bio->bi_end_io = btrfs_end_bio; |
| 5216 | bio->bi_sector = physical >> 9; | 5188 | bio->bi_sector = physical >> 9; |
| 5217 | #ifdef DEBUG | 5189 | #ifdef DEBUG |
| @@ -5272,8 +5244,7 @@ static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical) | |||
| 5272 | if (atomic_dec_and_test(&bbio->stripes_pending)) { | 5244 | if (atomic_dec_and_test(&bbio->stripes_pending)) { |
| 5273 | bio->bi_private = bbio->private; | 5245 | bio->bi_private = bbio->private; |
| 5274 | bio->bi_end_io = bbio->end_io; | 5246 | bio->bi_end_io = bbio->end_io; |
| 5275 | bio->bi_bdev = (struct block_device *) | 5247 | btrfs_io_bio(bio)->mirror_num = bbio->mirror_num; |
| 5276 | (unsigned long)bbio->mirror_num; | ||
| 5277 | bio->bi_sector = logical >> 9; | 5248 | bio->bi_sector = logical >> 9; |
| 5278 | kfree(bbio); | 5249 | kfree(bbio); |
| 5279 | bio_endio(bio, -EIO); | 5250 | bio_endio(bio, -EIO); |
| @@ -5351,7 +5322,7 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio, | |||
| 5351 | } | 5322 | } |
| 5352 | 5323 | ||
| 5353 | if (dev_nr < total_devs - 1) { | 5324 | if (dev_nr < total_devs - 1) { |
| 5354 | bio = bio_clone(first_bio, GFP_NOFS); | 5325 | bio = btrfs_bio_clone(first_bio, GFP_NOFS); |
| 5355 | BUG_ON(!bio); /* -ENOMEM */ | 5326 | BUG_ON(!bio); /* -ENOMEM */ |
| 5356 | } else { | 5327 | } else { |
| 5357 | bio = first_bio; | 5328 | bio = first_bio; |
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 845ccbb0d2e3..f6247e2a47f7 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h | |||
| @@ -152,6 +152,26 @@ struct btrfs_fs_devices { | |||
| 152 | int rotating; | 152 | int rotating; |
| 153 | }; | 153 | }; |
| 154 | 154 | ||
| 155 | /* | ||
| 156 | * we need the mirror number and stripe index to be passed around | ||
| 157 | * the call chain while we are processing end_io (especially errors). | ||
| 158 | * Really, what we need is a btrfs_bio structure that has this info | ||
| 159 | * and is properly sized with its stripe array, but we're not there | ||
| 160 | * quite yet. We have our own btrfs bioset, and all of the bios | ||
| 161 | * we allocate are actually btrfs_io_bios. We'll cram as much of | ||
| 162 | * struct btrfs_bio as we can into this over time. | ||
| 163 | */ | ||
| 164 | struct btrfs_io_bio { | ||
| 165 | unsigned long mirror_num; | ||
| 166 | unsigned long stripe_index; | ||
| 167 | struct bio bio; | ||
| 168 | }; | ||
| 169 | |||
| 170 | static inline struct btrfs_io_bio *btrfs_io_bio(struct bio *bio) | ||
| 171 | { | ||
| 172 | return container_of(bio, struct btrfs_io_bio, bio); | ||
| 173 | } | ||
| 174 | |||
| 155 | struct btrfs_bio_stripe { | 175 | struct btrfs_bio_stripe { |
| 156 | struct btrfs_device *dev; | 176 | struct btrfs_device *dev; |
| 157 | u64 physical; | 177 | u64 physical; |
