aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/extent_io.c')
-rw-r--r--fs/btrfs/extent_io.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index cd4b5e400221..198c2ba2fa40 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -402,20 +402,28 @@ static int split_state(struct extent_io_tree *tree, struct extent_state *orig,
402 return 0; 402 return 0;
403} 403}
404 404
405static struct extent_state *next_state(struct extent_state *state)
406{
407 struct rb_node *next = rb_next(&state->rb_node);
408 if (next)
409 return rb_entry(next, struct extent_state, rb_node);
410 else
411 return NULL;
412}
413
405/* 414/*
406 * utility function to clear some bits in an extent state struct. 415 * utility function to clear some bits in an extent state struct.
407 * it will optionally wake up any one waiting on this state (wake == 1), or 416 * it will optionally wake up any one waiting on this state (wake == 1)
408 * forcibly remove the state from the tree (delete == 1).
409 * 417 *
410 * If no bits are set on the state struct after clearing things, the 418 * If no bits are set on the state struct after clearing things, the
411 * struct is freed and removed from the tree 419 * struct is freed and removed from the tree
412 */ 420 */
413static int clear_state_bit(struct extent_io_tree *tree, 421static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
414 struct extent_state *state, 422 struct extent_state *state,
415 int *bits, int wake) 423 int *bits, int wake)
416{ 424{
425 struct extent_state *next;
417 int bits_to_clear = *bits & ~EXTENT_CTLBITS; 426 int bits_to_clear = *bits & ~EXTENT_CTLBITS;
418 int ret = state->state & bits_to_clear;
419 427
420 if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { 428 if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) {
421 u64 range = state->end - state->start + 1; 429 u64 range = state->end - state->start + 1;
@@ -427,6 +435,7 @@ static int clear_state_bit(struct extent_io_tree *tree,
427 if (wake) 435 if (wake)
428 wake_up(&state->wq); 436 wake_up(&state->wq);
429 if (state->state == 0) { 437 if (state->state == 0) {
438 next = next_state(state);
430 if (state->tree) { 439 if (state->tree) {
431 rb_erase(&state->rb_node, &tree->state); 440 rb_erase(&state->rb_node, &tree->state);
432 state->tree = NULL; 441 state->tree = NULL;
@@ -436,8 +445,9 @@ static int clear_state_bit(struct extent_io_tree *tree,
436 } 445 }
437 } else { 446 } else {
438 merge_state(tree, state); 447 merge_state(tree, state);
448 next = next_state(state);
439 } 449 }
440 return ret; 450 return next;
441} 451}
442 452
443static struct extent_state * 453static struct extent_state *
@@ -476,7 +486,6 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
476 struct extent_state *state; 486 struct extent_state *state;
477 struct extent_state *cached; 487 struct extent_state *cached;
478 struct extent_state *prealloc = NULL; 488 struct extent_state *prealloc = NULL;
479 struct rb_node *next_node;
480 struct rb_node *node; 489 struct rb_node *node;
481 u64 last_end; 490 u64 last_end;
482 int err; 491 int err;
@@ -528,14 +537,11 @@ hit_next:
528 WARN_ON(state->end < start); 537 WARN_ON(state->end < start);
529 last_end = state->end; 538 last_end = state->end;
530 539
531 if (state->end < end && !need_resched())
532 next_node = rb_next(&state->rb_node);
533 else
534 next_node = NULL;
535
536 /* the state doesn't have the wanted bits, go ahead */ 540 /* the state doesn't have the wanted bits, go ahead */
537 if (!(state->state & bits)) 541 if (!(state->state & bits)) {
542 state = next_state(state);
538 goto next; 543 goto next;
544 }
539 545
540 /* 546 /*
541 * | ---- desired range ---- | 547 * | ---- desired range ---- |
@@ -593,16 +599,13 @@ hit_next:
593 goto out; 599 goto out;
594 } 600 }
595 601
596 clear_state_bit(tree, state, &bits, wake); 602 state = clear_state_bit(tree, state, &bits, wake);
597next: 603next:
598 if (last_end == (u64)-1) 604 if (last_end == (u64)-1)
599 goto out; 605 goto out;
600 start = last_end + 1; 606 start = last_end + 1;
601 if (start <= end && next_node) { 607 if (start <= end && state && !need_resched())
602 state = rb_entry(next_node, struct extent_state,
603 rb_node);
604 goto hit_next; 608 goto hit_next;
605 }
606 goto search_again; 609 goto search_again;
607 610
608out: 611out:
@@ -2301,7 +2304,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2301 u64 start; 2304 u64 start;
2302 u64 end; 2305 u64 end;
2303 int whole_page; 2306 int whole_page;
2304 int failed_mirror; 2307 int mirror;
2305 int ret; 2308 int ret;
2306 2309
2307 if (err) 2310 if (err)
@@ -2340,20 +2343,18 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2340 } 2343 }
2341 spin_unlock(&tree->lock); 2344 spin_unlock(&tree->lock);
2342 2345
2346 mirror = (int)(unsigned long)bio->bi_bdev;
2343 if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { 2347 if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) {
2344 ret = tree->ops->readpage_end_io_hook(page, start, end, 2348 ret = tree->ops->readpage_end_io_hook(page, start, end,
2345 state); 2349 state, mirror);
2346 if (ret) 2350 if (ret)
2347 uptodate = 0; 2351 uptodate = 0;
2348 else 2352 else
2349 clean_io_failure(start, page); 2353 clean_io_failure(start, page);
2350 } 2354 }
2351 2355
2352 if (!uptodate)
2353 failed_mirror = (int)(unsigned long)bio->bi_bdev;
2354
2355 if (!uptodate && tree->ops && tree->ops->readpage_io_failed_hook) { 2356 if (!uptodate && tree->ops && tree->ops->readpage_io_failed_hook) {
2356 ret = tree->ops->readpage_io_failed_hook(page, failed_mirror); 2357 ret = tree->ops->readpage_io_failed_hook(page, mirror);
2357 if (!ret && !err && 2358 if (!ret && !err &&
2358 test_bit(BIO_UPTODATE, &bio->bi_flags)) 2359 test_bit(BIO_UPTODATE, &bio->bi_flags))
2359 uptodate = 1; 2360 uptodate = 1;
@@ -2368,8 +2369,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2368 * can't handle the error it will return -EIO and we 2369 * can't handle the error it will return -EIO and we
2369 * remain responsible for that page. 2370 * remain responsible for that page.
2370 */ 2371 */
2371 ret = bio_readpage_error(bio, page, start, end, 2372 ret = bio_readpage_error(bio, page, start, end, mirror, NULL);
2372 failed_mirror, NULL);
2373 if (ret == 0) { 2373 if (ret == 0) {
2374 uptodate = 2374 uptodate =
2375 test_bit(BIO_UPTODATE, &bio->bi_flags); 2375 test_bit(BIO_UPTODATE, &bio->bi_flags);
@@ -4462,7 +4462,7 @@ int read_extent_buffer_pages(struct extent_io_tree *tree,
4462 } 4462 }
4463 4463
4464 clear_bit(EXTENT_BUFFER_IOERR, &eb->bflags); 4464 clear_bit(EXTENT_BUFFER_IOERR, &eb->bflags);
4465 eb->failed_mirror = 0; 4465 eb->read_mirror = 0;
4466 atomic_set(&eb->io_pages, num_reads); 4466 atomic_set(&eb->io_pages, num_reads);
4467 for (i = start_i; i < num_pages; i++) { 4467 for (i = start_i; i < num_pages; i++) {
4468 page = extent_buffer_page(eb, i); 4468 page = extent_buffer_page(eb, i);