.. | .. |
---|
77 | 77 | |
---|
78 | 78 | #include <linux/sched.h> |
---|
79 | 79 | #include <linux/slab.h> |
---|
80 | | -#include <linux/buffer_head.h> |
---|
81 | 80 | #include <linux/mutex.h> |
---|
82 | 81 | #include <linux/genhd.h> |
---|
83 | 82 | #include <linux/blkdev.h> |
---|
84 | 83 | #include <linux/mm.h> |
---|
85 | 84 | #include <linux/string.h> |
---|
86 | | -#include <linux/crc32c.h> |
---|
| 85 | +#include <crypto/hash.h> |
---|
87 | 86 | #include "ctree.h" |
---|
88 | 87 | #include "disk-io.h" |
---|
89 | 88 | #include "transaction.h" |
---|
.. | .. |
---|
152 | 151 | struct list_head ref_to_list; /* list */ |
---|
153 | 152 | struct list_head ref_from_list; /* list */ |
---|
154 | 153 | struct btrfsic_block *next_in_same_bio; |
---|
155 | | - void *orig_bio_bh_private; |
---|
156 | | - union { |
---|
157 | | - bio_end_io_t *bio; |
---|
158 | | - bh_end_io_t *bh; |
---|
159 | | - } orig_bio_bh_end_io; |
---|
| 154 | + void *orig_bio_private; |
---|
| 155 | + bio_end_io_t *orig_bio_end_io; |
---|
160 | 156 | int submit_bio_bh_rw; |
---|
161 | 157 | u64 flush_gen; /* only valid if !never_written */ |
---|
162 | 158 | }; |
---|
.. | .. |
---|
325 | 321 | u64 dev_bytenr, char **mapped_datav, |
---|
326 | 322 | unsigned int num_pages, |
---|
327 | 323 | struct bio *bio, int *bio_is_patched, |
---|
328 | | - struct buffer_head *bh, |
---|
329 | 324 | int submit_bio_bh_rw); |
---|
330 | 325 | static int btrfsic_process_written_superblock( |
---|
331 | 326 | struct btrfsic_state *state, |
---|
332 | 327 | struct btrfsic_block *const block, |
---|
333 | 328 | struct btrfs_super_block *const super_hdr); |
---|
334 | 329 | static void btrfsic_bio_end_io(struct bio *bp); |
---|
335 | | -static void btrfsic_bh_end_io(struct buffer_head *bh, int uptodate); |
---|
336 | 330 | static int btrfsic_is_block_ref_by_superblock(const struct btrfsic_state *state, |
---|
337 | 331 | const struct btrfsic_block *block, |
---|
338 | 332 | int recursion_level); |
---|
.. | .. |
---|
399 | 393 | b->never_written = 0; |
---|
400 | 394 | b->mirror_num = 0; |
---|
401 | 395 | b->next_in_same_bio = NULL; |
---|
402 | | - b->orig_bio_bh_private = NULL; |
---|
403 | | - b->orig_bio_bh_end_io.bio = NULL; |
---|
| 396 | + b->orig_bio_private = NULL; |
---|
| 397 | + b->orig_bio_end_io = NULL; |
---|
404 | 398 | INIT_LIST_HEAD(&b->collision_resolving_node); |
---|
405 | 399 | INIT_LIST_HEAD(&b->all_blocks_node); |
---|
406 | 400 | INIT_LIST_HEAD(&b->ref_to_list); |
---|
.. | .. |
---|
636 | 630 | int ret = 0; |
---|
637 | 631 | int pass; |
---|
638 | 632 | |
---|
639 | | - BUG_ON(NULL == state); |
---|
640 | 633 | selected_super = kzalloc(sizeof(*selected_super), GFP_NOFS); |
---|
641 | | - if (NULL == selected_super) { |
---|
642 | | - pr_info("btrfsic: error, kmalloc failed!\n"); |
---|
| 634 | + if (!selected_super) |
---|
643 | 635 | return -ENOMEM; |
---|
644 | | - } |
---|
645 | 636 | |
---|
646 | 637 | list_for_each_entry(device, dev_head, dev_list) { |
---|
647 | 638 | int i; |
---|
.. | .. |
---|
768 | 759 | struct btrfs_fs_info *fs_info = state->fs_info; |
---|
769 | 760 | struct btrfs_super_block *super_tmp; |
---|
770 | 761 | u64 dev_bytenr; |
---|
771 | | - struct buffer_head *bh; |
---|
772 | 762 | struct btrfsic_block *superblock_tmp; |
---|
773 | 763 | int pass; |
---|
774 | 764 | struct block_device *const superblock_bdev = device->bdev; |
---|
| 765 | + struct page *page; |
---|
| 766 | + struct address_space *mapping = superblock_bdev->bd_inode->i_mapping; |
---|
| 767 | + int ret = 0; |
---|
775 | 768 | |
---|
776 | 769 | /* super block bytenr is always the unmapped device bytenr */ |
---|
777 | 770 | dev_bytenr = btrfs_sb_offset(superblock_mirror_num); |
---|
778 | 771 | if (dev_bytenr + BTRFS_SUPER_INFO_SIZE > device->commit_total_bytes) |
---|
779 | 772 | return -1; |
---|
780 | | - bh = __bread(superblock_bdev, dev_bytenr / BTRFS_BDEV_BLOCKSIZE, |
---|
781 | | - BTRFS_SUPER_INFO_SIZE); |
---|
782 | | - if (NULL == bh) |
---|
| 773 | + |
---|
| 774 | + page = read_cache_page_gfp(mapping, dev_bytenr >> PAGE_SHIFT, GFP_NOFS); |
---|
| 775 | + if (IS_ERR(page)) |
---|
783 | 776 | return -1; |
---|
784 | | - super_tmp = (struct btrfs_super_block *) |
---|
785 | | - (bh->b_data + (dev_bytenr & (BTRFS_BDEV_BLOCKSIZE - 1))); |
---|
| 777 | + |
---|
| 778 | + super_tmp = page_address(page); |
---|
786 | 779 | |
---|
787 | 780 | if (btrfs_super_bytenr(super_tmp) != dev_bytenr || |
---|
788 | 781 | btrfs_super_magic(super_tmp) != BTRFS_MAGIC || |
---|
789 | 782 | memcmp(device->uuid, super_tmp->dev_item.uuid, BTRFS_UUID_SIZE) || |
---|
790 | 783 | btrfs_super_nodesize(super_tmp) != state->metablock_size || |
---|
791 | 784 | btrfs_super_sectorsize(super_tmp) != state->datablock_size) { |
---|
792 | | - brelse(bh); |
---|
793 | | - return 0; |
---|
| 785 | + ret = 0; |
---|
| 786 | + goto out; |
---|
794 | 787 | } |
---|
795 | 788 | |
---|
796 | 789 | superblock_tmp = |
---|
.. | .. |
---|
800 | 793 | if (NULL == superblock_tmp) { |
---|
801 | 794 | superblock_tmp = btrfsic_block_alloc(); |
---|
802 | 795 | if (NULL == superblock_tmp) { |
---|
803 | | - pr_info("btrfsic: error, kmalloc failed!\n"); |
---|
804 | | - brelse(bh); |
---|
805 | | - return -1; |
---|
| 796 | + ret = -1; |
---|
| 797 | + goto out; |
---|
806 | 798 | } |
---|
807 | 799 | /* for superblock, only the dev_bytenr makes sense */ |
---|
808 | 800 | superblock_tmp->dev_bytenr = dev_bytenr; |
---|
.. | .. |
---|
886 | 878 | mirror_num)) { |
---|
887 | 879 | pr_info("btrfsic: btrfsic_map_block(bytenr @%llu, mirror %d) failed!\n", |
---|
888 | 880 | next_bytenr, mirror_num); |
---|
889 | | - brelse(bh); |
---|
890 | | - return -1; |
---|
| 881 | + ret = -1; |
---|
| 882 | + goto out; |
---|
891 | 883 | } |
---|
892 | 884 | |
---|
893 | 885 | next_block = btrfsic_block_lookup_or_add( |
---|
.. | .. |
---|
896 | 888 | mirror_num, NULL); |
---|
897 | 889 | if (NULL == next_block) { |
---|
898 | 890 | btrfsic_release_block_ctx(&tmp_next_block_ctx); |
---|
899 | | - brelse(bh); |
---|
900 | | - return -1; |
---|
| 891 | + ret = -1; |
---|
| 892 | + goto out; |
---|
901 | 893 | } |
---|
902 | 894 | |
---|
903 | 895 | next_block->disk_key = tmp_disk_key; |
---|
.. | .. |
---|
908 | 900 | BTRFSIC_GENERATION_UNKNOWN); |
---|
909 | 901 | btrfsic_release_block_ctx(&tmp_next_block_ctx); |
---|
910 | 902 | if (NULL == l) { |
---|
911 | | - brelse(bh); |
---|
912 | | - return -1; |
---|
| 903 | + ret = -1; |
---|
| 904 | + goto out; |
---|
913 | 905 | } |
---|
914 | 906 | } |
---|
915 | 907 | } |
---|
916 | 908 | if (state->print_mask & BTRFSIC_PRINT_MASK_INITIAL_ALL_TREES) |
---|
917 | 909 | btrfsic_dump_tree_sub(state, superblock_tmp, 0); |
---|
918 | 910 | |
---|
919 | | - brelse(bh); |
---|
920 | | - return 0; |
---|
| 911 | +out: |
---|
| 912 | + put_page(page); |
---|
| 913 | + return ret; |
---|
921 | 914 | } |
---|
922 | 915 | |
---|
923 | 916 | static struct btrfsic_stack_frame *btrfsic_stack_frame_alloc(void) |
---|
.. | .. |
---|
925 | 918 | struct btrfsic_stack_frame *sf; |
---|
926 | 919 | |
---|
927 | 920 | sf = kzalloc(sizeof(*sf), GFP_NOFS); |
---|
928 | | - if (NULL == sf) |
---|
929 | | - pr_info("btrfsic: alloc memory failed!\n"); |
---|
930 | | - else |
---|
| 921 | + if (sf) |
---|
931 | 922 | sf->magic = BTRFSIC_BLOCK_STACK_FRAME_MAGIC_NUMBER; |
---|
932 | 923 | return sf; |
---|
933 | 924 | } |
---|
.. | .. |
---|
939 | 930 | kfree(sf); |
---|
940 | 931 | } |
---|
941 | 932 | |
---|
942 | | -static int btrfsic_process_metablock( |
---|
| 933 | +static noinline_for_stack int btrfsic_process_metablock( |
---|
943 | 934 | struct btrfsic_state *state, |
---|
944 | 935 | struct btrfsic_block *const first_block, |
---|
945 | 936 | struct btrfsic_block_data_ctx *const first_block_ctx, |
---|
.. | .. |
---|
1201 | 1192 | void *dstv, u32 offset, size_t len) |
---|
1202 | 1193 | { |
---|
1203 | 1194 | size_t cur; |
---|
1204 | | - size_t offset_in_page; |
---|
| 1195 | + size_t pgoff; |
---|
1205 | 1196 | char *kaddr; |
---|
1206 | 1197 | char *dst = (char *)dstv; |
---|
1207 | | - size_t start_offset = block_ctx->start & ((u64)PAGE_SIZE - 1); |
---|
| 1198 | + size_t start_offset = offset_in_page(block_ctx->start); |
---|
1208 | 1199 | unsigned long i = (start_offset + offset) >> PAGE_SHIFT; |
---|
1209 | 1200 | |
---|
1210 | 1201 | WARN_ON(offset + len > block_ctx->len); |
---|
1211 | | - offset_in_page = (start_offset + offset) & (PAGE_SIZE - 1); |
---|
| 1202 | + pgoff = offset_in_page(start_offset + offset); |
---|
1212 | 1203 | |
---|
1213 | 1204 | while (len > 0) { |
---|
1214 | | - cur = min(len, ((size_t)PAGE_SIZE - offset_in_page)); |
---|
| 1205 | + cur = min(len, ((size_t)PAGE_SIZE - pgoff)); |
---|
1215 | 1206 | BUG_ON(i >= DIV_ROUND_UP(block_ctx->len, PAGE_SIZE)); |
---|
1216 | 1207 | kaddr = block_ctx->datav[i]; |
---|
1217 | | - memcpy(dst, kaddr + offset_in_page, cur); |
---|
| 1208 | + memcpy(dst, kaddr + pgoff, cur); |
---|
1218 | 1209 | |
---|
1219 | 1210 | dst += cur; |
---|
1220 | 1211 | len -= cur; |
---|
1221 | | - offset_in_page = 0; |
---|
| 1212 | + pgoff = 0; |
---|
1222 | 1213 | i++; |
---|
1223 | 1214 | } |
---|
1224 | 1215 | } |
---|
.. | .. |
---|
1317 | 1308 | if (NULL == l) { |
---|
1318 | 1309 | l = btrfsic_block_link_alloc(); |
---|
1319 | 1310 | if (NULL == l) { |
---|
1320 | | - pr_info("btrfsic: error, kmalloc failed!\n"); |
---|
1321 | 1311 | btrfsic_release_block_ctx(next_block_ctx); |
---|
1322 | 1312 | *next_blockp = NULL; |
---|
1323 | 1313 | return -1; |
---|
.. | .. |
---|
1474 | 1464 | mirror_num, |
---|
1475 | 1465 | &block_was_created); |
---|
1476 | 1466 | if (NULL == next_block) { |
---|
1477 | | - pr_info("btrfsic: error, kmalloc failed!\n"); |
---|
1478 | 1467 | btrfsic_release_block_ctx(&next_block_ctx); |
---|
1479 | 1468 | return -1; |
---|
1480 | 1469 | } |
---|
.. | .. |
---|
1593 | 1582 | { |
---|
1594 | 1583 | unsigned int num_pages; |
---|
1595 | 1584 | unsigned int i; |
---|
| 1585 | + size_t size; |
---|
1596 | 1586 | u64 dev_bytenr; |
---|
1597 | 1587 | int ret; |
---|
1598 | 1588 | |
---|
1599 | 1589 | BUG_ON(block_ctx->datav); |
---|
1600 | 1590 | BUG_ON(block_ctx->pagev); |
---|
1601 | 1591 | BUG_ON(block_ctx->mem_to_free); |
---|
1602 | | - if (block_ctx->dev_bytenr & ((u64)PAGE_SIZE - 1)) { |
---|
| 1592 | + if (!PAGE_ALIGNED(block_ctx->dev_bytenr)) { |
---|
1603 | 1593 | pr_info("btrfsic: read_block() with unaligned bytenr %llu\n", |
---|
1604 | 1594 | block_ctx->dev_bytenr); |
---|
1605 | 1595 | return -1; |
---|
.. | .. |
---|
1607 | 1597 | |
---|
1608 | 1598 | num_pages = (block_ctx->len + (u64)PAGE_SIZE - 1) >> |
---|
1609 | 1599 | PAGE_SHIFT; |
---|
1610 | | - block_ctx->mem_to_free = kcalloc(sizeof(*block_ctx->datav) + |
---|
1611 | | - sizeof(*block_ctx->pagev), |
---|
1612 | | - num_pages, GFP_NOFS); |
---|
| 1600 | + size = sizeof(*block_ctx->datav) + sizeof(*block_ctx->pagev); |
---|
| 1601 | + block_ctx->mem_to_free = kcalloc(num_pages, size, GFP_NOFS); |
---|
1613 | 1602 | if (!block_ctx->mem_to_free) |
---|
1614 | 1603 | return -ENOMEM; |
---|
1615 | 1604 | block_ctx->datav = block_ctx->mem_to_free; |
---|
.. | .. |
---|
1705 | 1694 | * Test whether the disk block contains a tree block (leaf or node) |
---|
1706 | 1695 | * (note that this test fails for the super block) |
---|
1707 | 1696 | */ |
---|
1708 | | -static int btrfsic_test_for_metadata(struct btrfsic_state *state, |
---|
1709 | | - char **datav, unsigned int num_pages) |
---|
| 1697 | +static noinline_for_stack int btrfsic_test_for_metadata( |
---|
| 1698 | + struct btrfsic_state *state, |
---|
| 1699 | + char **datav, unsigned int num_pages) |
---|
1710 | 1700 | { |
---|
1711 | 1701 | struct btrfs_fs_info *fs_info = state->fs_info; |
---|
| 1702 | + SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); |
---|
1712 | 1703 | struct btrfs_header *h; |
---|
1713 | 1704 | u8 csum[BTRFS_CSUM_SIZE]; |
---|
1714 | | - u32 crc = ~(u32)0; |
---|
1715 | 1705 | unsigned int i; |
---|
1716 | 1706 | |
---|
1717 | 1707 | if (num_pages * PAGE_SIZE < state->metablock_size) |
---|
.. | .. |
---|
1719 | 1709 | num_pages = state->metablock_size >> PAGE_SHIFT; |
---|
1720 | 1710 | h = (struct btrfs_header *)datav[0]; |
---|
1721 | 1711 | |
---|
1722 | | - if (memcmp(h->fsid, fs_info->fsid, BTRFS_FSID_SIZE)) |
---|
| 1712 | + if (memcmp(h->fsid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE)) |
---|
1723 | 1713 | return 1; |
---|
| 1714 | + |
---|
| 1715 | + shash->tfm = fs_info->csum_shash; |
---|
| 1716 | + crypto_shash_init(shash); |
---|
1724 | 1717 | |
---|
1725 | 1718 | for (i = 0; i < num_pages; i++) { |
---|
1726 | 1719 | u8 *data = i ? datav[i] : (datav[i] + BTRFS_CSUM_SIZE); |
---|
1727 | 1720 | size_t sublen = i ? PAGE_SIZE : |
---|
1728 | 1721 | (PAGE_SIZE - BTRFS_CSUM_SIZE); |
---|
1729 | 1722 | |
---|
1730 | | - crc = crc32c(crc, data, sublen); |
---|
| 1723 | + crypto_shash_update(shash, data, sublen); |
---|
1731 | 1724 | } |
---|
1732 | | - btrfs_csum_final(crc, csum); |
---|
| 1725 | + crypto_shash_final(shash, csum); |
---|
1733 | 1726 | if (memcmp(csum, h->csum, state->csum_size)) |
---|
1734 | 1727 | return 1; |
---|
1735 | 1728 | |
---|
.. | .. |
---|
1740 | 1733 | u64 dev_bytenr, char **mapped_datav, |
---|
1741 | 1734 | unsigned int num_pages, |
---|
1742 | 1735 | struct bio *bio, int *bio_is_patched, |
---|
1743 | | - struct buffer_head *bh, |
---|
1744 | 1736 | int submit_bio_bh_rw) |
---|
1745 | 1737 | { |
---|
1746 | 1738 | int is_metadata; |
---|
.. | .. |
---|
1777 | 1769 | return; |
---|
1778 | 1770 | } |
---|
1779 | 1771 | is_metadata = 1; |
---|
1780 | | - BUG_ON(BTRFS_SUPER_INFO_SIZE & (PAGE_SIZE - 1)); |
---|
| 1772 | + BUG_ON(!PAGE_ALIGNED(BTRFS_SUPER_INFO_SIZE)); |
---|
1781 | 1773 | processed_len = BTRFS_SUPER_INFO_SIZE; |
---|
1782 | 1774 | if (state->print_mask & |
---|
1783 | 1775 | BTRFSIC_PRINT_MASK_TREE_BEFORE_SB_WRITE) { |
---|
.. | .. |
---|
1899 | 1891 | block->is_iodone = 0; |
---|
1900 | 1892 | BUG_ON(NULL == bio_is_patched); |
---|
1901 | 1893 | if (!*bio_is_patched) { |
---|
1902 | | - block->orig_bio_bh_private = |
---|
| 1894 | + block->orig_bio_private = |
---|
1903 | 1895 | bio->bi_private; |
---|
1904 | | - block->orig_bio_bh_end_io.bio = |
---|
| 1896 | + block->orig_bio_end_io = |
---|
1905 | 1897 | bio->bi_end_io; |
---|
1906 | 1898 | block->next_in_same_bio = NULL; |
---|
1907 | 1899 | bio->bi_private = block; |
---|
.. | .. |
---|
1913 | 1905 | bio->bi_private; |
---|
1914 | 1906 | |
---|
1915 | 1907 | BUG_ON(NULL == chained_block); |
---|
1916 | | - block->orig_bio_bh_private = |
---|
1917 | | - chained_block->orig_bio_bh_private; |
---|
1918 | | - block->orig_bio_bh_end_io.bio = |
---|
1919 | | - chained_block->orig_bio_bh_end_io. |
---|
1920 | | - bio; |
---|
| 1908 | + block->orig_bio_private = |
---|
| 1909 | + chained_block->orig_bio_private; |
---|
| 1910 | + block->orig_bio_end_io = |
---|
| 1911 | + chained_block->orig_bio_end_io; |
---|
1921 | 1912 | block->next_in_same_bio = chained_block; |
---|
1922 | 1913 | bio->bi_private = block; |
---|
1923 | 1914 | } |
---|
1924 | | - } else if (NULL != bh) { |
---|
1925 | | - block->is_iodone = 0; |
---|
1926 | | - block->orig_bio_bh_private = bh->b_private; |
---|
1927 | | - block->orig_bio_bh_end_io.bh = bh->b_end_io; |
---|
1928 | | - block->next_in_same_bio = NULL; |
---|
1929 | | - bh->b_private = block; |
---|
1930 | | - bh->b_end_io = btrfsic_bh_end_io; |
---|
1931 | 1915 | } else { |
---|
1932 | 1916 | block->is_iodone = 1; |
---|
1933 | | - block->orig_bio_bh_private = NULL; |
---|
1934 | | - block->orig_bio_bh_end_io.bio = NULL; |
---|
| 1917 | + block->orig_bio_private = NULL; |
---|
| 1918 | + block->orig_bio_end_io = NULL; |
---|
1935 | 1919 | block->next_in_same_bio = NULL; |
---|
1936 | 1920 | } |
---|
1937 | 1921 | } |
---|
.. | .. |
---|
2022 | 2006 | |
---|
2023 | 2007 | block = btrfsic_block_alloc(); |
---|
2024 | 2008 | if (NULL == block) { |
---|
2025 | | - pr_info("btrfsic: error, kmalloc failed!\n"); |
---|
2026 | 2009 | btrfsic_release_block_ctx(&block_ctx); |
---|
2027 | 2010 | goto continue_loop; |
---|
2028 | 2011 | } |
---|
.. | .. |
---|
2039 | 2022 | block->is_iodone = 0; |
---|
2040 | 2023 | BUG_ON(NULL == bio_is_patched); |
---|
2041 | 2024 | if (!*bio_is_patched) { |
---|
2042 | | - block->orig_bio_bh_private = bio->bi_private; |
---|
2043 | | - block->orig_bio_bh_end_io.bio = bio->bi_end_io; |
---|
| 2025 | + block->orig_bio_private = bio->bi_private; |
---|
| 2026 | + block->orig_bio_end_io = bio->bi_end_io; |
---|
2044 | 2027 | block->next_in_same_bio = NULL; |
---|
2045 | 2028 | bio->bi_private = block; |
---|
2046 | 2029 | bio->bi_end_io = btrfsic_bio_end_io; |
---|
.. | .. |
---|
2051 | 2034 | bio->bi_private; |
---|
2052 | 2035 | |
---|
2053 | 2036 | BUG_ON(NULL == chained_block); |
---|
2054 | | - block->orig_bio_bh_private = |
---|
2055 | | - chained_block->orig_bio_bh_private; |
---|
2056 | | - block->orig_bio_bh_end_io.bio = |
---|
2057 | | - chained_block->orig_bio_bh_end_io.bio; |
---|
| 2037 | + block->orig_bio_private = |
---|
| 2038 | + chained_block->orig_bio_private; |
---|
| 2039 | + block->orig_bio_end_io = |
---|
| 2040 | + chained_block->orig_bio_end_io; |
---|
2058 | 2041 | block->next_in_same_bio = chained_block; |
---|
2059 | 2042 | bio->bi_private = block; |
---|
2060 | 2043 | } |
---|
2061 | | - } else if (NULL != bh) { |
---|
2062 | | - block->is_iodone = 0; |
---|
2063 | | - block->orig_bio_bh_private = bh->b_private; |
---|
2064 | | - block->orig_bio_bh_end_io.bh = bh->b_end_io; |
---|
2065 | | - block->next_in_same_bio = NULL; |
---|
2066 | | - bh->b_private = block; |
---|
2067 | | - bh->b_end_io = btrfsic_bh_end_io; |
---|
2068 | 2044 | } else { |
---|
2069 | 2045 | block->is_iodone = 1; |
---|
2070 | | - block->orig_bio_bh_private = NULL; |
---|
2071 | | - block->orig_bio_bh_end_io.bio = NULL; |
---|
| 2046 | + block->orig_bio_private = NULL; |
---|
| 2047 | + block->orig_bio_end_io = NULL; |
---|
2072 | 2048 | block->next_in_same_bio = NULL; |
---|
2073 | 2049 | } |
---|
2074 | 2050 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) |
---|
.. | .. |
---|
2109 | 2085 | iodone_w_error = 1; |
---|
2110 | 2086 | |
---|
2111 | 2087 | BUG_ON(NULL == block); |
---|
2112 | | - bp->bi_private = block->orig_bio_bh_private; |
---|
2113 | | - bp->bi_end_io = block->orig_bio_bh_end_io.bio; |
---|
| 2088 | + bp->bi_private = block->orig_bio_private; |
---|
| 2089 | + bp->bi_end_io = block->orig_bio_end_io; |
---|
2114 | 2090 | |
---|
2115 | 2091 | do { |
---|
2116 | 2092 | struct btrfsic_block *next_block; |
---|
.. | .. |
---|
2141 | 2117 | } while (NULL != block); |
---|
2142 | 2118 | |
---|
2143 | 2119 | bp->bi_end_io(bp); |
---|
2144 | | -} |
---|
2145 | | - |
---|
2146 | | -static void btrfsic_bh_end_io(struct buffer_head *bh, int uptodate) |
---|
2147 | | -{ |
---|
2148 | | - struct btrfsic_block *block = (struct btrfsic_block *)bh->b_private; |
---|
2149 | | - int iodone_w_error = !uptodate; |
---|
2150 | | - struct btrfsic_dev_state *dev_state; |
---|
2151 | | - |
---|
2152 | | - BUG_ON(NULL == block); |
---|
2153 | | - dev_state = block->dev_state; |
---|
2154 | | - if ((dev_state->state->print_mask & BTRFSIC_PRINT_MASK_END_IO_BIO_BH)) |
---|
2155 | | - pr_info("bh_end_io(error=%d) for %c @%llu (%s/%llu/%d)\n", |
---|
2156 | | - iodone_w_error, |
---|
2157 | | - btrfsic_get_block_type(dev_state->state, block), |
---|
2158 | | - block->logical_bytenr, block->dev_state->name, |
---|
2159 | | - block->dev_bytenr, block->mirror_num); |
---|
2160 | | - |
---|
2161 | | - block->iodone_w_error = iodone_w_error; |
---|
2162 | | - if (block->submit_bio_bh_rw & REQ_PREFLUSH) { |
---|
2163 | | - dev_state->last_flush_gen++; |
---|
2164 | | - if ((dev_state->state->print_mask & |
---|
2165 | | - BTRFSIC_PRINT_MASK_END_IO_BIO_BH)) |
---|
2166 | | - pr_info("bh_end_io() new %s flush_gen=%llu\n", |
---|
2167 | | - dev_state->name, dev_state->last_flush_gen); |
---|
2168 | | - } |
---|
2169 | | - if (block->submit_bio_bh_rw & REQ_FUA) |
---|
2170 | | - block->flush_gen = 0; /* FUA completed means block is on disk */ |
---|
2171 | | - |
---|
2172 | | - bh->b_private = block->orig_bio_bh_private; |
---|
2173 | | - bh->b_end_io = block->orig_bio_bh_end_io.bh; |
---|
2174 | | - block->is_iodone = 1; /* for FLUSH, this releases the block */ |
---|
2175 | | - bh->b_end_io(bh, uptodate); |
---|
2176 | 2120 | } |
---|
2177 | 2121 | |
---|
2178 | 2122 | static int btrfsic_process_written_superblock( |
---|
.. | .. |
---|
2282 | 2226 | mirror_num, |
---|
2283 | 2227 | &was_created); |
---|
2284 | 2228 | if (NULL == next_block) { |
---|
2285 | | - pr_info("btrfsic: error, kmalloc failed!\n"); |
---|
2286 | 2229 | btrfsic_release_block_ctx(&tmp_next_block_ctx); |
---|
2287 | 2230 | return -1; |
---|
2288 | 2231 | } |
---|
.. | .. |
---|
2326 | 2269 | * write operations. Therefore it keeps the linkage |
---|
2327 | 2270 | * information for a block until a block is |
---|
2328 | 2271 | * rewritten. This can temporarily cause incorrect |
---|
2329 | | - * and even circular linkage informations. This |
---|
| 2272 | + * and even circular linkage information. This |
---|
2330 | 2273 | * causes no harm unless such blocks are referenced |
---|
2331 | 2274 | * by the most recent super block. |
---|
2332 | 2275 | */ |
---|
.. | .. |
---|
2590 | 2533 | &state->block_link_hashtable); |
---|
2591 | 2534 | if (NULL == l) { |
---|
2592 | 2535 | l = btrfsic_block_link_alloc(); |
---|
2593 | | - if (NULL == l) { |
---|
2594 | | - pr_info("btrfsic: error, kmalloc failed!\n"); |
---|
| 2536 | + if (!l) |
---|
2595 | 2537 | return NULL; |
---|
2596 | | - } |
---|
2597 | 2538 | |
---|
2598 | 2539 | l->block_ref_to = next_block; |
---|
2599 | 2540 | l->block_ref_from = from_block; |
---|
.. | .. |
---|
2637 | 2578 | struct btrfsic_dev_state *dev_state; |
---|
2638 | 2579 | |
---|
2639 | 2580 | block = btrfsic_block_alloc(); |
---|
2640 | | - if (NULL == block) { |
---|
2641 | | - pr_info("btrfsic: error, kmalloc failed!\n"); |
---|
| 2581 | + if (!block) |
---|
2642 | 2582 | return NULL; |
---|
2643 | | - } |
---|
| 2583 | + |
---|
2644 | 2584 | dev_state = btrfsic_dev_state_lookup(block_ctx->dev->bdev->bd_dev); |
---|
2645 | 2585 | if (NULL == dev_state) { |
---|
2646 | 2586 | pr_info("btrfsic: error, lookup dev_state failed!\n"); |
---|
.. | .. |
---|
2727 | 2667 | &btrfsic_dev_state_hashtable); |
---|
2728 | 2668 | } |
---|
2729 | 2669 | |
---|
2730 | | -int btrfsic_submit_bh(int op, int op_flags, struct buffer_head *bh) |
---|
2731 | | -{ |
---|
2732 | | - struct btrfsic_dev_state *dev_state; |
---|
2733 | | - |
---|
2734 | | - if (!btrfsic_is_initialized) |
---|
2735 | | - return submit_bh(op, op_flags, bh); |
---|
2736 | | - |
---|
2737 | | - mutex_lock(&btrfsic_mutex); |
---|
2738 | | - /* since btrfsic_submit_bh() might also be called before |
---|
2739 | | - * btrfsic_mount(), this might return NULL */ |
---|
2740 | | - dev_state = btrfsic_dev_state_lookup(bh->b_bdev->bd_dev); |
---|
2741 | | - |
---|
2742 | | - /* Only called to write the superblock (incl. FLUSH/FUA) */ |
---|
2743 | | - if (NULL != dev_state && |
---|
2744 | | - (op == REQ_OP_WRITE) && bh->b_size > 0) { |
---|
2745 | | - u64 dev_bytenr; |
---|
2746 | | - |
---|
2747 | | - dev_bytenr = BTRFS_BDEV_BLOCKSIZE * bh->b_blocknr; |
---|
2748 | | - if (dev_state->state->print_mask & |
---|
2749 | | - BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH) |
---|
2750 | | - pr_info("submit_bh(op=0x%x,0x%x, blocknr=%llu (bytenr %llu), size=%zu, data=%p, bdev=%p)\n", |
---|
2751 | | - op, op_flags, (unsigned long long)bh->b_blocknr, |
---|
2752 | | - dev_bytenr, bh->b_size, bh->b_data, bh->b_bdev); |
---|
2753 | | - btrfsic_process_written_block(dev_state, dev_bytenr, |
---|
2754 | | - &bh->b_data, 1, NULL, |
---|
2755 | | - NULL, bh, op_flags); |
---|
2756 | | - } else if (NULL != dev_state && (op_flags & REQ_PREFLUSH)) { |
---|
2757 | | - if (dev_state->state->print_mask & |
---|
2758 | | - BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH) |
---|
2759 | | - pr_info("submit_bh(op=0x%x,0x%x FLUSH, bdev=%p)\n", |
---|
2760 | | - op, op_flags, bh->b_bdev); |
---|
2761 | | - if (!dev_state->dummy_block_for_bio_bh_flush.is_iodone) { |
---|
2762 | | - if ((dev_state->state->print_mask & |
---|
2763 | | - (BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH | |
---|
2764 | | - BTRFSIC_PRINT_MASK_VERBOSE))) |
---|
2765 | | - pr_info("btrfsic_submit_bh(%s) with FLUSH but dummy block already in use (ignored)!\n", |
---|
2766 | | - dev_state->name); |
---|
2767 | | - } else { |
---|
2768 | | - struct btrfsic_block *const block = |
---|
2769 | | - &dev_state->dummy_block_for_bio_bh_flush; |
---|
2770 | | - |
---|
2771 | | - block->is_iodone = 0; |
---|
2772 | | - block->never_written = 0; |
---|
2773 | | - block->iodone_w_error = 0; |
---|
2774 | | - block->flush_gen = dev_state->last_flush_gen + 1; |
---|
2775 | | - block->submit_bio_bh_rw = op_flags; |
---|
2776 | | - block->orig_bio_bh_private = bh->b_private; |
---|
2777 | | - block->orig_bio_bh_end_io.bh = bh->b_end_io; |
---|
2778 | | - block->next_in_same_bio = NULL; |
---|
2779 | | - bh->b_private = block; |
---|
2780 | | - bh->b_end_io = btrfsic_bh_end_io; |
---|
2781 | | - } |
---|
2782 | | - } |
---|
2783 | | - mutex_unlock(&btrfsic_mutex); |
---|
2784 | | - return submit_bh(op, op_flags, bh); |
---|
2785 | | -} |
---|
2786 | | - |
---|
2787 | 2670 | static void __btrfsic_submit_bio(struct bio *bio) |
---|
2788 | 2671 | { |
---|
2789 | 2672 | struct btrfsic_dev_state *dev_state; |
---|
.. | .. |
---|
2835 | 2718 | btrfsic_process_written_block(dev_state, dev_bytenr, |
---|
2836 | 2719 | mapped_datav, segs, |
---|
2837 | 2720 | bio, &bio_is_patched, |
---|
2838 | | - NULL, bio->bi_opf); |
---|
| 2721 | + bio->bi_opf); |
---|
2839 | 2722 | bio_for_each_segment(bvec, bio, iter) |
---|
2840 | 2723 | kunmap(bvec.bv_page); |
---|
2841 | 2724 | kfree(mapped_datav); |
---|
.. | .. |
---|
2859 | 2742 | block->iodone_w_error = 0; |
---|
2860 | 2743 | block->flush_gen = dev_state->last_flush_gen + 1; |
---|
2861 | 2744 | block->submit_bio_bh_rw = bio->bi_opf; |
---|
2862 | | - block->orig_bio_bh_private = bio->bi_private; |
---|
2863 | | - block->orig_bio_bh_end_io.bio = bio->bi_end_io; |
---|
| 2745 | + block->orig_bio_private = bio->bi_private; |
---|
| 2746 | + block->orig_bio_end_io = bio->bi_end_io; |
---|
2864 | 2747 | block->next_in_same_bio = NULL; |
---|
2865 | 2748 | bio->bi_private = block; |
---|
2866 | 2749 | bio->bi_end_io = btrfsic_bio_end_io; |
---|
.. | .. |
---|
2891 | 2774 | struct list_head *dev_head = &fs_devices->devices; |
---|
2892 | 2775 | struct btrfs_device *device; |
---|
2893 | 2776 | |
---|
2894 | | - if (fs_info->nodesize & ((u64)PAGE_SIZE - 1)) { |
---|
| 2777 | + if (!PAGE_ALIGNED(fs_info->nodesize)) { |
---|
2895 | 2778 | pr_info("btrfsic: cannot handle nodesize %d not being a multiple of PAGE_SIZE %ld!\n", |
---|
2896 | 2779 | fs_info->nodesize, PAGE_SIZE); |
---|
2897 | 2780 | return -1; |
---|
2898 | 2781 | } |
---|
2899 | | - if (fs_info->sectorsize & ((u64)PAGE_SIZE - 1)) { |
---|
| 2782 | + if (!PAGE_ALIGNED(fs_info->sectorsize)) { |
---|
2900 | 2783 | pr_info("btrfsic: cannot handle sectorsize %d not being a multiple of PAGE_SIZE %ld!\n", |
---|
2901 | 2784 | fs_info->sectorsize, PAGE_SIZE); |
---|
2902 | 2785 | return -1; |
---|
2903 | 2786 | } |
---|
2904 | 2787 | state = kvzalloc(sizeof(*state), GFP_KERNEL); |
---|
2905 | | - if (!state) { |
---|
2906 | | - pr_info("btrfs check-integrity: allocation failed!\n"); |
---|
| 2788 | + if (!state) |
---|
2907 | 2789 | return -ENOMEM; |
---|
2908 | | - } |
---|
2909 | 2790 | |
---|
2910 | 2791 | if (!btrfsic_is_initialized) { |
---|
2911 | 2792 | mutex_init(&btrfsic_mutex); |
---|
.. | .. |
---|
2934 | 2815 | |
---|
2935 | 2816 | ds = btrfsic_dev_state_alloc(); |
---|
2936 | 2817 | if (NULL == ds) { |
---|
2937 | | - pr_info("btrfs check-integrity: kmalloc() failed!\n"); |
---|
2938 | 2818 | mutex_unlock(&btrfsic_mutex); |
---|
2939 | 2819 | return -ENOMEM; |
---|
2940 | 2820 | } |
---|