From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: [PATCH v2 4/4] btrfs: Add checker for EXTENT_CSUM
Date: Wed, 23 Aug 2017 16:57:59 +0900 [thread overview]
Message-ID: <20170823075759.13982-5-quwenruo.btrfs@gmx.com> (raw)
In-Reply-To: <20170823075759.13982-1-quwenruo.btrfs@gmx.com>
EXTENT_CSUM checker is a relatively easy checker, only needs to check:
1) Objectid
Fixed to BTRFS_EXTENT_CSUM_OBJECTID.
2) Key offset alignment
Must be aligned to sectorsize
3) Item size alignedment
Must be aligned to csum size.
Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
---
fs/btrfs/disk-io.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index b92296c6a698..1746c5a2a7f7 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -628,6 +628,27 @@ static int check_extent_data_item(struct btrfs_root *root,
return 0;
}
+static int check_csum_item(struct btrfs_root *root, struct extent_buffer *leaf,
+ struct btrfs_key *key, int slot)
+{
+ u32 sectorsize = root->fs_info->sectorsize;
+ u32 csumsize = btrfs_super_csum_size(root->fs_info->super_copy);
+
+ if (key->objectid != BTRFS_EXTENT_CSUM_OBJECTID) {
+ CORRUPT("invalid objectid for csum item", leaf, root, slot);
+ return -EUCLEAN;
+ }
+ if (!IS_ALIGNED(key->offset, sectorsize)) {
+ CORRUPT("unaligned key offset for csum item", leaf, root, slot);
+ return -EUCLEAN;
+ }
+ if (!IS_ALIGNED(btrfs_item_size_nr(leaf, slot), csumsize)) {
+ CORRUPT("unaligned csum item size", leaf, root, slot);
+ return -EUCLEAN;
+ }
+ return 0;
+}
+
static int check_leaf_item(struct btrfs_root *root,
struct extent_buffer *leaf,
struct btrfs_key *key, int slot)
@@ -642,6 +663,9 @@ static int check_leaf_item(struct btrfs_root *root,
case BTRFS_EXTENT_DATA_KEY:
ret = check_extent_data_item(root, leaf, key, slot);
break;
+ case BTRFS_EXTENT_CSUM_KEY:
+ ret = check_csum_item(root, leaf, key, slot);
+ break;
}
return ret;
}
--
2.14.1
next prev parent reply other threads:[~2017-08-23 7:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-23 7:57 [PATCH v2 0/3] Introduce comprehensive sanity check framework and Qu Wenruo
2017-08-23 7:57 ` [PATCH v2 1/4] btrfs: Refactor check_leaf function for later expansion Qu Wenruo
2017-08-23 7:57 ` [PATCH v2 2/4] btrfs: Check if item pointer overlap with item itself Qu Wenruo
2017-08-23 7:57 ` [PATCH v2 3/4] btrfs: Add sanity check for EXTENT_DATA when reading out leaf Qu Wenruo
2017-09-25 15:45 ` David Sterba
2017-09-26 0:28 ` Qu Wenruo
2017-09-26 0:46 ` Qu Wenruo
2017-09-26 12:13 ` David Sterba
2017-09-26 12:49 ` Qu Wenruo
2017-09-26 14:42 ` David Sterba
2017-09-26 12:05 ` David Sterba
2017-09-26 12:42 ` Qu Wenruo
2017-08-23 7:57 ` Qu Wenruo [this message]
2017-08-23 15:19 ` [PATCH v2 0/3] Introduce comprehensive sanity check framework and Nikolay Borisov
2017-09-25 15:17 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170823075759.13982-5-quwenruo.btrfs@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).