From: Qu Wenruo <wqu@suse.de>
To: Nikolay Borisov <nborisov@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/5] btrfs-progs: image: Refactor fixup_devices() to fixup_chunks_and_devices()
Date: Tue, 27 Nov 2018 15:15:12 +0800 [thread overview]
Message-ID: <dd2d5176-a2e8-2243-656a-3f0276a3394b@suse.de> (raw)
In-Reply-To: <acd445d3-5a04-792f-49b8-8eee9071400c@suse.com>
On 2018/11/27 下午3:13, Nikolay Borisov wrote:
>
>
> On 27.11.18 г. 4:33 ч., Qu Wenruo wrote:
>> Current fixup_devices() will only remove DEV_ITEMs and reset DEV_ITEM
>> size.
>> Later we need to do more fixup works, so change the name to
>> fixup_chunks_and_devices() and refactor the original device size fixup
>> to fixup_device_size().
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>> image/main.c | 52 ++++++++++++++++++++++++++++++++++++----------------
>> 1 file changed, 36 insertions(+), 16 deletions(-)
>>
>> diff --git a/image/main.c b/image/main.c
>> index c680ab19de6c..36b5c95ea146 100644
>> --- a/image/main.c
>> +++ b/image/main.c
>> @@ -2084,28 +2084,19 @@ static void remap_overlapping_chunks(struct mdrestore_struct *mdres)
>> }
>> }
>>
>> -static int fixup_devices(struct btrfs_fs_info *fs_info,
>> - struct mdrestore_struct *mdres, off_t dev_size)
>> +static int fixup_device_size(struct btrfs_trans_handle *trans,
>> + struct btrfs_fs_info *fs_info,
>
> trans already has a handle to the fs_info so you can drop it from the
> param list.
Indeed! My bad habbit of trans then fs_info definitely needs to be
corrected.
Thanks,
Qu
>
>> + struct mdrestore_struct *mdres,
>> + off_t dev_size)
>> {
>> - struct btrfs_trans_handle *trans;
>> struct btrfs_dev_item *dev_item;
>> struct btrfs_path path;
>> - struct extent_buffer *leaf;
>> struct btrfs_root *root = fs_info->chunk_root;
>> struct btrfs_key key;
>> + struct extent_buffer *leaf;
>> u64 devid, cur_devid;
>> int ret;
>>
>> - if (btrfs_super_log_root(fs_info->super_copy)) {
>> - warning(
>> - "log tree detected, its generation will not match superblock");
>> - }
>> - trans = btrfs_start_transaction(fs_info->tree_root, 1);
>> - if (IS_ERR(trans)) {
>> - error("cannot starting transaction %ld", PTR_ERR(trans));
>> - return PTR_ERR(trans);
>> - }
>> -
>> dev_item = &fs_info->super_copy->dev_item;
>>
>> devid = btrfs_stack_device_id(dev_item);
>> @@ -2123,7 +2114,7 @@ again:
>> ret = btrfs_search_slot(trans, root, &key, &path, -1, 1);
>> if (ret < 0) {
>> error("search failed: %d", ret);
>> - exit(1);
>> + return ret;
>> }
>>
>> while (1) {
>> @@ -2170,12 +2161,41 @@ again:
>> }
>>
>> btrfs_release_path(&path);
>> + return 0;
>> +}
>> +
>> +static int fixup_chunks_and_devices(struct btrfs_fs_info *fs_info,
>> + struct mdrestore_struct *mdres, off_t dev_size)
>> +{
>> + struct btrfs_trans_handle *trans;
>> + int ret;
>> +
>> + if (btrfs_super_log_root(fs_info->super_copy)) {
>> + warning(
>> + "log tree detected, its generation will not match superblock");
>> + }
>> + trans = btrfs_start_transaction(fs_info->tree_root, 1);
>> + if (IS_ERR(trans)) {
>> + error("cannot starting transaction %ld", PTR_ERR(trans));
>> + return PTR_ERR(trans);
>> + }
>> +
>> + ret = fixup_device_size(trans, fs_info, mdres, dev_size);
>> + if (ret < 0)
>> + goto error;
>> +
>> ret = btrfs_commit_transaction(trans, fs_info->tree_root);
>> if (ret) {
>> error("unable to commit transaction: %d", ret);
>> return ret;
>> }
>> return 0;
>> +error:
>> + error(
>> +"failed to fix chunks and devices mapping, the fs may not be mountable: %s",
>> + strerror(-ret));
>> + btrfs_abort_transaction(trans, ret);
>> + return ret;
>> }
>>
>> static int restore_metadump(const char *input, FILE *out, int old_restore,
>> @@ -2282,7 +2302,7 @@ static int restore_metadump(const char *input, FILE *out, int old_restore,
>> return 1;
>> }
>>
>> - ret = fixup_devices(info, &mdrestore, st.st_size);
>> + ret = fixup_chunks_and_devices(info, &mdrestore, st.st_size);
>> close_ctree(info->chunk_root);
>> if (ret)
>> goto out;
>>
next prev parent reply other threads:[~2018-11-27 7:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-27 2:33 [PATCH 0/5] btrfs-progs: image: Fix error when restoring multi-disk image to single disk Qu Wenruo
2018-11-27 2:33 ` [PATCH 1/5] btrfs-progs: image: Refactor fixup_devices() to fixup_chunks_and_devices() Qu Wenruo
2018-11-27 7:13 ` Nikolay Borisov
2018-11-27 7:15 ` Qu Wenruo [this message]
2018-11-27 2:33 ` [PATCH 2/5] btrfs-progs: image: Fix block group item flags when restoring multi-device image to single device Qu Wenruo
2018-11-27 7:15 ` Nikolay Borisov
2018-11-27 7:16 ` Qu Wenruo
2018-11-27 2:33 ` [PATCH 3/5] btrfs-progs: image: Remove all existing dev extents for later rebuild Qu Wenruo
2018-11-27 7:26 ` Nikolay Borisov
2018-11-27 2:33 ` [PATCH 4/5] btrfs-progs: image: Rebuild dev extents using chunk tree Qu Wenruo
2018-11-27 7:28 ` Nikolay Borisov
2018-11-27 7:30 ` Qu Wenruo
2018-11-27 7:35 ` Nikolay Borisov
2018-11-27 2:33 ` [PATCH 5/5] btrfs-progs: misc-tests/021: Do extra btrfs check before mounting Qu Wenruo
2018-11-27 7:29 ` Nikolay Borisov
2018-11-27 7:31 ` Qu Wenruo
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=dd2d5176-a2e8-2243-656a-3f0276a3394b@suse.de \
--to=wqu@suse.de \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.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).