From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 3/3] btrfs: Add btrfsck support for nocow compressed prealloc write.
Date: Thu, 18 Sep 2014 12:22:18 +0800 [thread overview]
Message-ID: <1411014138-20124-3-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1411014138-20124-1-git-send-email-quwenruo@cn.fujitsu.com>
Add support for nocow compressed write into preallocated range.
The main change is the following:
1) use disk_bytenr + data_offset to search csum
2) use offset + num_bytes - data_offset to judge if this is a valid
file extent.
3) add file extent item size check,
Since now regular file extent has 2 sizes(one with appended members
and the old one),
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-check.c | 19 ++++++++++++++++---
ctree.h | 1 -
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/cmds-check.c b/cmds-check.c
index 268e588..7a18ad4 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -1175,12 +1175,17 @@ static int process_file_extent(struct btrfs_root *root,
num_bytes = (num_bytes + mask) & ~mask;
} else if (extent_type == BTRFS_FILE_EXTENT_REG ||
extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
+ u32 item_size = btrfs_item_size_nr(eb, slot);
num_bytes = btrfs_file_extent_num_bytes(eb, fi);
- disk_bytenr = btrfs_file_extent_disk_bytenr(eb, fi);
+ /* data_offset will fallback to 0 on normal extent */
+ disk_bytenr = btrfs_file_extent_disk_bytenr(eb, fi) +
+ btrfs_ondemand_file_extent_data_offset(eb,
+ slot, fi);
extent_offset = btrfs_file_extent_offset(eb, fi);
if (num_bytes == 0 || (num_bytes & mask))
rec->errors |= I_ERR_BAD_FILE_EXTENT;
- if (num_bytes + extent_offset >
+ if (num_bytes + extent_offset -
+ btrfs_ondemand_file_extent_data_offset(eb, slot, fi) >
btrfs_file_extent_ram_bytes(eb, fi))
rec->errors |= I_ERR_BAD_FILE_EXTENT;
if (extent_type == BTRFS_FILE_EXTENT_PREALLOC &&
@@ -1190,6 +1195,13 @@ static int process_file_extent(struct btrfs_root *root,
rec->errors |= I_ERR_BAD_FILE_EXTENT;
if (disk_bytenr > 0)
rec->found_size += num_bytes;
+ if (item_size != BTRFS_FILE_EXTENT_SIZE_NORMAL &&
+ item_size != BTRFS_FILE_EXTENT_SIZE_MAX)
+ rec->errors |= I_ERR_BAD_FILE_EXTENT;
+ if (!btrfs_fs_incompat(root->fs_info,
+ BTRFS_FEATURE_INCOMPAT_COMPPREALLOC) &&
+ (item_size == BTRFS_FILE_EXTENT_SIZE_MAX))
+ rec->errors |= I_ERR_BAD_FILE_EXTENT;
} else {
rec->errors |= I_ERR_BAD_FILE_EXTENT;
}
@@ -1198,7 +1210,8 @@ static int process_file_extent(struct btrfs_root *root,
if (disk_bytenr > 0) {
u64 found;
if (btrfs_file_extent_compression(eb, fi))
- num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi);
+ num_bytes = btrfs_ondemand_file_extent_data_len(eb,
+ slot, fi);
else
disk_bytenr += extent_offset;
diff --git a/ctree.h b/ctree.h
index ab87133..e11e4d8 100644
--- a/ctree.h
+++ b/ctree.h
@@ -834,7 +834,6 @@ struct __compprealloc_data {
__le64 data_len;
} __attribute__ ((__packed__));
-
#define BTRFS_FILE_EXTENT_SIZE_NORMAL (sizeof(struct btrfs_file_extent_item))
#define BTRFS_FILE_EXTENT_SIZE_MAX (sizeof(struct btrfs_file_extent_item) + \
sizeof(struct __compprealloc_data))
--
2.1.0
prev parent reply other threads:[~2014-09-18 4:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-18 4:22 [PATCH 1/3] btrfs-progs: Add nocow compressed write into prealloc support Qu Wenruo
2014-09-18 4:22 ` [PATCH 2/3] btrfs-progs: Add data_offset and data_len output for print_file_extent_item Qu Wenruo
2014-09-18 4:22 ` Qu Wenruo [this message]
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=1411014138-20124-3-git-send-email-quwenruo@cn.fujitsu.com \
--to=quwenruo@cn.fujitsu.com \
--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).