btrfs: make btrfs_verify_data_csum() to return a bitmap
authorQu Wenruo <wqu@suse.com>
Mon, 3 May 2021 02:08:54 +0000 (10:08 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jun 2021 13:19:05 +0000 (15:19 +0200)
This will provide the basis for later per-sector repair for subpage,
while still keeping the existing code happy.

As if all csums match, the return value will be 0, same as now.
Only when csum mismatches, the return value is different.

The new return value will be a bitmap, for 4K sectorsize and 4K page
size, it will be either 1, instead of the -EIO (which is not used
directly by the callers, no effective change).

But for 4K sectorsize and 64K page size, aka subpage case, since the
bvec can contain multiple sectors, knowing which sectors are corrupted
will allow us to submit repair only for corrupted sectors.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/inode.c

index 9fb76829a281c8d0d38936dcd0b225af54d5dfc4..938d8ebf4cf39d06f5530ea72c3765971beaf8d0 100644 (file)
@@ -3100,8 +3100,8 @@ u64 btrfs_file_extent_end(const struct btrfs_path *path);
 /* inode.c */
 blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
                                   int mirror_num, unsigned long bio_flags);
-int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u32 bio_offset,
-                          struct page *page, u64 start, u64 end);
+unsigned int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u32 bio_offset,
+                                   struct page *page, u64 start, u64 end);
 struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode,
                                           u64 start, u64 len);
 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
index 46f392943f4d0a051c80272b444d068e800f7816..3211469eb90fc055462060cfd0e93fa6b91ab462 100644 (file)
@@ -3152,15 +3152,19 @@ zeroit:
  * @bio_offset:        offset to the beginning of the bio (in bytes)
  * @start:     file offset of the range start
  * @end:       file offset of the range end (inclusive)
+ *
+ * Return a bitmap where bit set means a csum mismatch, and bit not set means
+ * csum match.
  */
-int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u32 bio_offset,
-                          struct page *page, u64 start, u64 end)
+unsigned int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u32 bio_offset,
+                                   struct page *page, u64 start, u64 end)
 {
        struct inode *inode = page->mapping->host;
        struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
        struct btrfs_root *root = BTRFS_I(inode)->root;
        const u32 sectorsize = root->fs_info->sectorsize;
        u32 pg_off;
+       unsigned int result = 0;
 
        if (PageChecked(page)) {
                ClearPageChecked(page);
@@ -3188,10 +3192,14 @@ int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u32 bio_offset,
 
                ret = check_data_csum(inode, io_bio, bio_offset, page, pg_off,
                                      page_offset(page) + pg_off);
-               if (ret < 0)
-                       return -EIO;
+               if (ret < 0) {
+                       const int nr_bit = (pg_off - offset_in_page(start)) >>
+                                    root->fs_info->sectorsize_bits;
+
+                       result |= (1U << nr_bit);
+               }
        }
-       return 0;
+       return result;
 }
 
 /*