From: Su Yue <Damenly_Su@gmx.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>,
Su Yue <suy.fnst@cn.fujitsu.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3 4/7] btrfs-progs: lowmem: search key of root again after check_fs_root() after repair
Date: Mon, 17 Sep 2018 20:55:47 +0800 [thread overview]
Message-ID: <b26bc272-9756-cbfd-1e78-0df999ee22c2@gmx.com> (raw)
In-Reply-To: <0841e3f5-0e2c-220b-4627-41347a89280c@gmx.com>
On 2018/9/17 8:51 PM, Qu Wenruo wrote:
>
>
> On 2018/9/17 下午3:28, Su Yue wrote:
>> In check_fs_roots_lowmem(), we do search and follow the resulted path
>> to call check_fs_root(), then call btrfs_next_item() to check next
>> root.
>> However, if repair is enabled, the root tree can be cowed, the
>> existed path can cause strange errors.
>>
>> Solution:
>> If repair, save the key before calling check_fs_root,
>> search the saved key again before checking next root.
>>
>> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
>
> The idea is pretty valid, however I'm not pretty sure about one practice
> below.
>
>> ---
>> check/mode-lowmem.c | 22 ++++++++++++++++++++++
>> 1 file changed, 22 insertions(+)
>>
>> diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
>> index 4db12cc7f9fe..db44456fd85b 100644
>> --- a/check/mode-lowmem.c
>> +++ b/check/mode-lowmem.c
>> @@ -4967,9 +4967,13 @@ int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info)
>> }
>>
>> while (1) {
>> + struct btrfs_key saved_key;
>> +
>> node = path.nodes[0];
>> slot = path.slots[0];
>> btrfs_item_key_to_cpu(node, &key, slot);
>> + if (repair)
>> + saved_key = key;
>
> Is this OK? Shouldn't it be something like memcpy(&saved_key, &key,
> sizeof(key));
>
> Or some new C standard make it work?
>
I don't quite know how C89 standard defines this behavior.
It should work in C99...
Seems you are not familiar with this style, will use memcpy.
Thanks,
Su
> Although compiler doesn't give any warning on this.
>
> Thanks,
> Qu
>
>> if (key.objectid > BTRFS_LAST_FREE_OBJECTID)
>> goto out;
>> if (key.type == BTRFS_ROOT_ITEM_KEY &&
>> @@ -5000,6 +5004,24 @@ int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info)
>> err |= ret;
>> }
>> next:
>> + /*
>> + * Since root tree can be cowed during repair,
>> + * here search the saved key again.
>> + */
>> + if (repair) {
>> + btrfs_release_path(&path);
>> + ret = btrfs_search_slot(NULL, fs_info->tree_root,
>> + &saved_key, &path, 0, 0);
>> + /* Repair never deletes trees, search must succeed. */
>> + if (ret > 0)
>> + ret = -ENOENT;
>> + if (ret) {
>> + error(
>> + "search root key[%llu %u %llu] failed after repair: %s",
>> + saved_key.objectid, saved_key.type,
>> + saved_key.offset, strerror(-ret));
>> + }
>> + }
>> ret = btrfs_next_item(tree_root, &path);
>> if (ret > 0)
>> goto out;
>>
next prev parent reply other threads:[~2018-09-17 18:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-17 7:28 [PATCH v3 0/7] btrfs-progs: lowmem: bug fixes and inode_extref repair Su Yue
2018-09-17 7:28 ` [PATCH v3 1/7] btrfs-progs: adjust arguments of btrfs_lookup_inode_extref() Su Yue
2018-09-17 7:28 ` [PATCH v3 2/7] btrfs-progs: make btrfs_unlink() lookup inode_extref Su Yue
2018-09-17 7:28 ` [PATCH v3 3/7] btrfs-progs: lowmem check: find dir_item by di_key in check_dir_item() Su Yue
2018-09-17 12:47 ` Qu Wenruo
2018-09-17 7:28 ` [PATCH v3 4/7] btrfs-progs: lowmem: search key of root again after check_fs_root() after repair Su Yue
2018-09-17 12:51 ` Qu Wenruo
2018-09-17 12:55 ` Su Yue [this message]
2018-09-17 13:03 ` Qu Wenruo
2018-09-17 13:13 ` Nikolay Borisov
2018-09-17 7:28 ` [PATCH v3 5/7] btrfs-progs: lowmem: do missing check of last item after check_inode_item() Su Yue
2018-09-17 12:53 ` Qu Wenruo
2018-09-17 13:24 ` Su Yue
2018-09-18 5:32 ` Qu Wenruo
2018-09-18 8:01 ` Su Yue
2018-09-18 8:15 ` Qu Wenruo
2018-09-17 7:28 ` [PATCH v3 6/7] btrfs-progs: lowmem: optimization and repair for check_inode_extref() Su Yue
2018-09-17 13:00 ` Qu Wenruo
2018-09-17 15:25 ` Nikolay Borisov
2018-09-17 7:28 ` [PATCH v3 7/7] btrfs-progs: fsck-tests: add test case inode_extref without dir_item and dir_index Su Yue
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=b26bc272-9756-cbfd-1e78-0df999ee22c2@gmx.com \
--to=damenly_su@gmx.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
--cc=suy.fnst@cn.fujitsu.com \
/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).