aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r--fs/btrfs/ctree.c51
1 files changed, 24 insertions, 27 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index f60920e8a0e0..9427b79c5d79 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -464,22 +464,12 @@ static int check_block(struct btrfs_root *root, struct btrfs_path *path,
464 int level) 464 int level)
465{ 465{
466 struct extent_buffer *buf = path->nodes[level]; 466 struct extent_buffer *buf = path->nodes[level];
467 char fsid[BTRFS_FSID_SIZE];
468 467
469 read_extent_buffer(buf, fsid, (unsigned long)btrfs_header_fsid(buf), 468 if (memcmp_extent_buffer(buf, root->fs_info->fsid,
470 BTRFS_FSID_SIZE); 469 (unsigned long)btrfs_header_fsid(buf),
471 470 BTRFS_FSID_SIZE)) {
472 if (memcmp(fsid, root->fs_info->fsid, BTRFS_FSID_SIZE)) {
473 int i = 0;
474 printk("warning bad block %Lu\n", buf->start); 471 printk("warning bad block %Lu\n", buf->start);
475 if (!btrfs_buffer_uptodate(buf)) { 472 BUG();
476 WARN_ON(1);
477 }
478 for (i = 0; i < BTRFS_FSID_SIZE; i++) {
479 printk("%x:%x ", root->fs_info->fsid[i], fsid[i]);
480 }
481 printk("\n");
482 // BUG();
483 } 473 }
484 if (level == 0) 474 if (level == 0)
485 return check_leaf(root, path, level); 475 return check_leaf(root, path, level);
@@ -504,13 +494,14 @@ static int generic_bin_search(struct extent_buffer *eb, unsigned long p,
504 int high = max; 494 int high = max;
505 int mid; 495 int mid;
506 int ret; 496 int ret;
507 struct btrfs_disk_key *tmp; 497 struct btrfs_disk_key *tmp = NULL;
508 struct btrfs_disk_key unaligned; 498 struct btrfs_disk_key unaligned;
509 unsigned long offset; 499 unsigned long offset;
510 char *map_token = NULL; 500 char *map_token = NULL;
511 char *kaddr = NULL; 501 char *kaddr = NULL;
512 unsigned long map_start = 0; 502 unsigned long map_start = 0;
513 unsigned long map_len = 0; 503 unsigned long map_len = 0;
504 int err;
514 505
515 while(low < high) { 506 while(low < high) {
516 mid = (low + high) / 2; 507 mid = (low + high) / 2;
@@ -519,19 +510,24 @@ static int generic_bin_search(struct extent_buffer *eb, unsigned long p,
519 if (!map_token || offset < map_start || 510 if (!map_token || offset < map_start ||
520 (offset + sizeof(struct btrfs_disk_key)) > 511 (offset + sizeof(struct btrfs_disk_key)) >
521 map_start + map_len) { 512 map_start + map_len) {
522 if (map_token) 513 if (map_token) {
523 unmap_extent_buffer(eb, map_token, KM_USER0); 514 unmap_extent_buffer(eb, map_token, KM_USER0);
524 map_extent_buffer(eb, offset, &map_token, &kaddr, 515 map_token = NULL;
525 &map_start, &map_len, KM_USER0); 516 }
517 err = map_extent_buffer(eb, offset,
518 sizeof(struct btrfs_disk_key),
519 &map_token, &kaddr,
520 &map_start, &map_len, KM_USER0);
521
522 if (!err) {
523 tmp = (struct btrfs_disk_key *)(kaddr + offset -
524 map_start);
525 } else {
526 read_extent_buffer(eb, &unaligned,
527 offset, sizeof(unaligned));
528 tmp = &unaligned;
529 }
526 530
527 }
528 if (offset + sizeof(struct btrfs_disk_key) >
529 map_start + map_len) {
530 unmap_extent_buffer(eb, map_token, KM_USER0);
531 read_extent_buffer(eb, &unaligned,
532 offset, sizeof(unaligned));
533 map_token = NULL;
534 tmp = &unaligned;
535 } else { 531 } else {
536 tmp = (struct btrfs_disk_key *)(kaddr + offset - 532 tmp = (struct btrfs_disk_key *)(kaddr + offset -
537 map_start); 533 map_start);
@@ -544,7 +540,8 @@ static int generic_bin_search(struct extent_buffer *eb, unsigned long p,
544 high = mid; 540 high = mid;
545 else { 541 else {
546 *slot = mid; 542 *slot = mid;
547 unmap_extent_buffer(eb, map_token, KM_USER0); 543 if (map_token)
544 unmap_extent_buffer(eb, map_token, KM_USER0);
548 return 0; 545 return 0;
549 } 546 }
550 } 547 }