public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch
@ 2022-02-28  0:50 Qu Wenruo
  2022-02-28  0:50 ` [PATCH 1/2] btrfs-progs: check: add check and repair ability for super num devs mismatch Qu Wenruo
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Qu Wenruo @ 2022-02-28  0:50 UTC (permalink / raw)
  To: linux-btrfs

The patchset can be fetched from github:
https://github.com/adam900710/btrfs-progs/tree/super_num_devs

The 2nd patch contains a compressed raw image, thus it may be a little
too large for the mail list.

This patchset will allow btrfs check to detect and repair super num devices
mismatch.

The detect part is to iterate through chunk tree to grab the correct
number of devices.
This is more reliable than counting devices in fs_devices, since seed
device is in another fs_devices.

The repair is more straightforward, just reset the value in superblock
and commit a transaction.

Qu Wenruo (2):
  btrfs-progs: check: add check and repair ability for super num devs
    mismatch
  btrfs-progs: tests/fsck: add test case for super num devs mismatch

 check/main.c                                  |   1 +
 check/mode-common.c                           |  88 ++++++++++++++++++
 check/mode-common.h                           |   2 +
 .../default.raw.xz                            | Bin 0 -> 22028 bytes
 4 files changed, 91 insertions(+)
 create mode 100644 tests/fsck-tests/054-super-num-devs-mismatch/default.raw.xz

-- 
2.35.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] btrfs-progs: check: add check and repair ability for super num devs mismatch
  2022-02-28  0:50 [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch Qu Wenruo
@ 2022-02-28  0:50 ` Qu Wenruo
  2022-03-23 17:43   ` David Sterba
  2022-02-28  0:50 ` [PATCH 2/2] btrfs-progs: tests/fsck: add test case " Qu Wenruo
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Qu Wenruo @ 2022-02-28  0:50 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Luca Béla Palkovics

[BUG]
There is a bug report of kernel rejecting fs which has a mismatch in
super num devices and num devices found in chunk tree.

But btrfs-check reports no problem about the fs.

[CAUSE]
We just didn't verify super num devices against the result found in
chunk tree.

[FIX]
Add such check and repair ability for btrfs-check.

The ability is mode independent.

Reported-by: Luca Béla Palkovics <luca.bela.palkovics@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/CA+8xDSpvdm_U0QLBAnrH=zqDq_cWCOH5TiV46CKmp3igr44okQ@mail.gmail.com/
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/main.c        |  1 +
 check/mode-common.c | 88 +++++++++++++++++++++++++++++++++++++++++++++
 check/mode-common.h |  2 ++
 3 files changed, 91 insertions(+)

diff --git a/check/main.c b/check/main.c
index 8ccba4478de8..b29f6266b974 100644
--- a/check/main.c
+++ b/check/main.c
@@ -9140,6 +9140,7 @@ static int do_check_chunks_and_extents(void)
 		if (ret > 0)
 			ret = 0;
 	}
+	ret = check_and_repair_super_num_devs(gfs_info);
 	return ret;
 }
 
diff --git a/check/mode-common.c b/check/mode-common.c
index c3d8bb45c6b6..a2c6c7732f4e 100644
--- a/check/mode-common.c
+++ b/check/mode-common.c
@@ -1583,3 +1583,91 @@ int fill_csum_tree(struct btrfs_trans_handle *trans, bool search_fs_tree)
 	}
 	return ret;
 }
+
+static int get_num_devs_in_chunk_tree(struct btrfs_fs_info *fs_info)
+{
+	struct btrfs_root *chunk_root = fs_info->chunk_root;
+	struct btrfs_path path = {0};
+	struct btrfs_key key = {0};
+	int found_devs = 0;
+	int ret;
+
+	ret = btrfs_search_slot(NULL, chunk_root, &key, &path, 0, 0);
+	if (ret < 0)
+		return ret;
+
+	/* We should be the first slot, and chunk tree should not be empty*/
+	ASSERT(path.slots[0] == 0 && btrfs_header_nritems(path.nodes[0]));
+
+	btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
+
+	while (key.objectid == BTRFS_DEV_ITEMS_OBJECTID &&
+	       key.type == BTRFS_DEV_ITEM_KEY) {
+		found_devs++;
+
+		ret = btrfs_next_item(chunk_root, &path);
+		if (ret < 0)
+			break;
+
+		/*
+		 * This should not happen, as we should have CHUNK items after
+		 * dev items, but since we're only to get the num devices,
+		 * no need to bother the problem.
+		 */
+		if (ret > 0) {
+			ret = 0;
+			break;
+		}
+		btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
+	}
+	btrfs_release_path(&path);
+	if (ret < 0)
+		return ret;
+	return found_devs;
+}
+
+int check_and_repair_super_num_devs(struct btrfs_fs_info *fs_info)
+{
+	struct btrfs_trans_handle *trans;
+	int found_devs;
+	int ret;
+
+	ret = get_num_devs_in_chunk_tree(fs_info);
+	if (ret < 0)
+		return ret;
+
+	found_devs = ret;
+
+	if (found_devs == btrfs_super_num_devices(fs_info->super_copy))
+		return 0;
+
+	/* Now the found devs in chunk tree mismatch with super block*/
+	error("super num devices mismatch, have %llu expect %u",
+	      btrfs_super_num_devices(fs_info->super_copy),
+	      found_devs);
+
+	if (!repair)
+		return -EUCLEAN;
+
+	/*
+	 * Repair is pretty simple, just reset the super block value and
+	 * commit a new transaction.
+	 */
+	trans = btrfs_start_transaction(fs_info->tree_root, 0);
+	if (IS_ERR(trans)) {
+		ret = PTR_ERR(trans);
+		errno = -ret;
+		error("failed to start trans: %m");
+		return ret;
+	}
+	btrfs_set_super_num_devices(fs_info->super_copy, found_devs);
+	ret = btrfs_commit_transaction(trans, fs_info->tree_root);
+	if (ret < 0) {
+		errno = -ret;
+		error("failed to commit trans: %m");
+		btrfs_abort_transaction(trans, ret);
+		return ret;
+	}
+	printf("Successfully reset super num devices to %u\n", found_devs);
+	return 0;
+}
diff --git a/check/mode-common.h b/check/mode-common.h
index b5e6b727fe73..d5bab85a4f5e 100644
--- a/check/mode-common.h
+++ b/check/mode-common.h
@@ -201,4 +201,6 @@ int repair_dev_item_bytes_used(struct btrfs_fs_info *fs_info,
 
 int fill_csum_tree(struct btrfs_trans_handle *trans, bool search_fs_tree);
 
+int check_and_repair_super_num_devs(struct btrfs_fs_info *fs_info);
+
 #endif
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] btrfs-progs: tests/fsck: add test case for super num devs mismatch
  2022-02-28  0:50 [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch Qu Wenruo
  2022-02-28  0:50 ` [PATCH 1/2] btrfs-progs: check: add check and repair ability for super num devs mismatch Qu Wenruo
@ 2022-02-28  0:50 ` Qu Wenruo
  2022-03-23 17:12 ` [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch David Sterba
  2022-03-23 17:17 ` David Sterba
  3 siblings, 0 replies; 10+ messages in thread
From: Qu Wenruo @ 2022-02-28  0:50 UTC (permalink / raw)
  To: linux-btrfs

The new image will has incorrect super num devices (have 8 expect 1).

The image has to be raw format, as btrfs-image restore will reset super
num devices to correct value.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 .../054-super-num-devs-mismatch/default.raw.xz  | Bin 0 -> 22028 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/fsck-tests/054-super-num-devs-mismatch/default.raw.xz

diff --git a/tests/fsck-tests/054-super-num-devs-mismatch/default.raw.xz b/tests/fsck-tests/054-super-num-devs-mismatch/default.raw.xz
new file mode 100644
index 0000000000000000000000000000000000000000..af0306bedbd0bd45dfd2d65a0f0a9f6bf662dfa8
GIT binary patch
literal 22028
zcmeHPXH=8vwoas@6sc0BNCas?L8=&vREg3F0s#a8=}bTvX@U|ugdzw^FQIoOf*4VH
z5oywkB8Uc%CP>SfIdkT&`(vD|&c(xz?{8MJ-j#Pf``P<>-o5v(^sgqSAQ0*7V71yI
z5HFY$1Om~&H0dM~Pmng6gFvpkL}K<MqPn66vxlseZf%_4Y<396m&F<Gpg!>?IR&tG
zg@0RkxQ=)>&2T{8+erSS`csHwO`hRzZfrhG2sm;bKY`M;G0V8hMaK3fLfiMj?R7HR
z{0mR({jztiJw*s5s80C=@O-Z16qMvjZu2W3S;^^9Tn~_JFIMQv8Q&rANbSgEI1fg;
zCB{~dFdzDWW^^>NL=Nba_1PC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mEHi+1c)X;Gy$S%pQlg(
z4m)@%6R5+0It-}8fI4j7RuB9X(*JFe4)q-6)p&33{s>611cHZwVrtk-4P~dFWGU`<
zugniR2fy!S*w@SXOVh%_NB%ruSNwooA$p*?6;tlbi2H3V{<iag!|&P3lF<r%5KfUk
z^5${U|GoC(=fmsY8%G3qBXa?a{Q$;*;X`2f5EwrE)}==K%5H!q23TVITb=<30}uuv
z3@}{*)AcVF7Vc|q|4U)~Kf4n5^=N?f0n*=p(hrpG1W|wp9s&NoSmWPTx`I-aL_b~D
gt#}9mPZxm$0|Q~deb(-YLNT$*LrH%B0x81uU)=*YbpQYW

literal 0
HcmV?d00001

-- 
2.35.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch
  2022-02-28  0:50 [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch Qu Wenruo
  2022-02-28  0:50 ` [PATCH 1/2] btrfs-progs: check: add check and repair ability for super num devs mismatch Qu Wenruo
  2022-02-28  0:50 ` [PATCH 2/2] btrfs-progs: tests/fsck: add test case " Qu Wenruo
@ 2022-03-23 17:12 ` David Sterba
  2022-03-23 17:17 ` David Sterba
  3 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2022-03-23 17:12 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Mon, Feb 28, 2022 at 08:50:06AM +0800, Qu Wenruo wrote:
> The patchset can be fetched from github:
> https://github.com/adam900710/btrfs-progs/tree/super_num_devs
> 
> The 2nd patch contains a compressed raw image, thus it may be a little
> too large for the mail list.
> 
> This patchset will allow btrfs check to detect and repair super num devices
> mismatch.
> 
> The detect part is to iterate through chunk tree to grab the correct
> number of devices.
> This is more reliable than counting devices in fs_devices, since seed
> device is in another fs_devices.
> 
> The repair is more straightforward, just reset the value in superblock
> and commit a transaction.

As repair it should work and be safe, also it should be reasonably safe
to be part of --repair. In addition to that we may also want the rescue
subcommand as it's meant to be for such one-time fixes for specific
errors.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch
  2022-02-28  0:50 [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch Qu Wenruo
                   ` (2 preceding siblings ...)
  2022-03-23 17:12 ` [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch David Sterba
@ 2022-03-23 17:17 ` David Sterba
  2022-03-23 23:30   ` Qu Wenruo
  3 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2022-03-23 17:17 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Mon, Feb 28, 2022 at 08:50:06AM +0800, Qu Wenruo wrote:
> The patchset can be fetched from github:
> https://github.com/adam900710/btrfs-progs/tree/super_num_devs
> 
> The 2nd patch contains a compressed raw image, thus it may be a little
> too large for the mail list.

The compressed size is 22K, that's fine. I've recompressed it with 'xz
--best -e' and it shaved a few hundred bytes but that was just out of
curiosity.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] btrfs-progs: check: add check and repair ability for super num devs mismatch
  2022-02-28  0:50 ` [PATCH 1/2] btrfs-progs: check: add check and repair ability for super num devs mismatch Qu Wenruo
@ 2022-03-23 17:43   ` David Sterba
  2022-03-23 23:15     ` Qu Wenruo
  0 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2022-03-23 17:43 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, Luca Béla Palkovics

On Mon, Feb 28, 2022 at 08:50:07AM +0800, Qu Wenruo wrote:
> [BUG]
> There is a bug report of kernel rejecting fs which has a mismatch in
> super num devices and num devices found in chunk tree.
> 
> But btrfs-check reports no problem about the fs.
> 
> [CAUSE]
> We just didn't verify super num devices against the result found in
> chunk tree.
> 
> [FIX]
> Add such check and repair ability for btrfs-check.
> 
> The ability is mode independent.
> 
> Reported-by: Luca Béla Palkovics <luca.bela.palkovics@gmail.com>
> Link: https://lore.kernel.org/linux-btrfs/CA+8xDSpvdm_U0QLBAnrH=zqDq_cWCOH5TiV46CKmp3igr44okQ@mail.gmail.com/
> Signed-off-by: Qu Wenruo <wqu@suse.com>

With this patch applied there's a new test failure:

=== START TEST .../tests/fsck-tests/014-no-extent-info
testing image no_extent.raw.restored
====== RUN MUSTFAIL .../btrfs check ./no_extent.raw.restored
Opening filesystem to check...
Checking filesystem on ./no_extent.raw.restored
UUID: aeee7297-37a4-4547-a8a9-7b870d58d31f
cache and super generation don't match, space cache will be invalidated
found 180224 bytes used, no error found
total csum bytes: 0
total tree bytes: 180224
total fs tree bytes: 81920
total extent tree bytes: 16384
btree space waste bytes: 138540
file data blocks allocated: 0
 referenced 0
succeeded (unexpected!): .../btrfs check ./no_extent.raw.restored
unexpected success: btrfs check should have detected corruption

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] btrfs-progs: check: add check and repair ability for super num devs mismatch
  2022-03-23 17:43   ` David Sterba
@ 2022-03-23 23:15     ` Qu Wenruo
  2022-03-23 23:38       ` Qu Wenruo
  0 siblings, 1 reply; 10+ messages in thread
From: Qu Wenruo @ 2022-03-23 23:15 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, linux-btrfs, Luca Béla Palkovics



On 2022/3/24 01:43, David Sterba wrote:
> On Mon, Feb 28, 2022 at 08:50:07AM +0800, Qu Wenruo wrote:
>> [BUG]
>> There is a bug report of kernel rejecting fs which has a mismatch in
>> super num devices and num devices found in chunk tree.
>>
>> But btrfs-check reports no problem about the fs.
>>
>> [CAUSE]
>> We just didn't verify super num devices against the result found in
>> chunk tree.
>>
>> [FIX]
>> Add such check and repair ability for btrfs-check.
>>
>> The ability is mode independent.
>>
>> Reported-by: Luca Béla Palkovics <luca.bela.palkovics@gmail.com>
>> Link: https://lore.kernel.org/linux-btrfs/CA+8xDSpvdm_U0QLBAnrH=zqDq_cWCOH5TiV46CKmp3igr44okQ@mail.gmail.com/
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>
> With this patch applied there's a new test failure:
>
> === START TEST .../tests/fsck-tests/014-no-extent-info
> testing image no_extent.raw.restored
> ====== RUN MUSTFAIL .../btrfs check ./no_extent.raw.restored
> Opening filesystem to check...
> Checking filesystem on ./no_extent.raw.restored
> UUID: aeee7297-37a4-4547-a8a9-7b870d58d31f
> cache and super generation don't match, space cache will be invalidated
> found 180224 bytes used, no error found
> total csum bytes: 0
> total tree bytes: 180224
> total fs tree bytes: 81920
> total extent tree bytes: 16384
> btree space waste bytes: 138540
> file data blocks allocated: 0
>   referenced 0
> succeeded (unexpected!): .../btrfs check ./no_extent.raw.restored
> unexpected success: btrfs check should have detected corruption


Weird, the problem is, for the restored image, if I run ./btrfs check
manually it can detects the problem, but still go "no error found" path.

So it must be my patch overriding the return value.

Will fix it soon.

Thanks,
Qu

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch
  2022-03-23 17:17 ` David Sterba
@ 2022-03-23 23:30   ` Qu Wenruo
  2022-03-24 15:12     ` David Sterba
  0 siblings, 1 reply; 10+ messages in thread
From: Qu Wenruo @ 2022-03-23 23:30 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, linux-btrfs



On 2022/3/24 01:17, David Sterba wrote:
> On Mon, Feb 28, 2022 at 08:50:06AM +0800, Qu Wenruo wrote:
>> The patchset can be fetched from github:
>> https://github.com/adam900710/btrfs-progs/tree/super_num_devs
>>
>> The 2nd patch contains a compressed raw image, thus it may be a little
>> too large for the mail list.
>
> The compressed size is 22K, that's fine. I've recompressed it with 'xz
> --best -e' and it shaved a few hundred bytes but that was just out of
> curiosity.

I'm also a little interested in why things like zstd/xz is not that
efficient in compressing raw btrfs images.

Especially when creating the image I have created the image with all
zero (fallocated) file in the first place, thus most space should just
be all zero, and any compression method should be super efficient on them.

My current guesses are:

- DUP metadata is not fully detected by the algo
   Especially when they are mostly quite some ranges away

- Some older tree blocks from mkfs

So for further raw image size reduction, we may want to:

- Use SINGLE metadata/data

- Fstrim the image first

Thanks,
Qu

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] btrfs-progs: check: add check and repair ability for super num devs mismatch
  2022-03-23 23:15     ` Qu Wenruo
@ 2022-03-23 23:38       ` Qu Wenruo
  0 siblings, 0 replies; 10+ messages in thread
From: Qu Wenruo @ 2022-03-23 23:38 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, linux-btrfs, Luca Béla Palkovics



On 2022/3/24 07:15, Qu Wenruo wrote:
>
>
> On 2022/3/24 01:43, David Sterba wrote:
>> On Mon, Feb 28, 2022 at 08:50:07AM +0800, Qu Wenruo wrote:
>>> [BUG]
>>> There is a bug report of kernel rejecting fs which has a mismatch in
>>> super num devices and num devices found in chunk tree.
>>>
>>> But btrfs-check reports no problem about the fs.
>>>
>>> [CAUSE]
>>> We just didn't verify super num devices against the result found in
>>> chunk tree.
>>>
>>> [FIX]
>>> Add such check and repair ability for btrfs-check.
>>>
>>> The ability is mode independent.
>>>
>>> Reported-by: Luca Béla Palkovics <luca.bela.palkovics@gmail.com>
>>> Link:
>>> https://lore.kernel.org/linux-btrfs/CA+8xDSpvdm_U0QLBAnrH=zqDq_cWCOH5TiV46CKmp3igr44okQ@mail.gmail.com/
>>>
>>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>>
>> With this patch applied there's a new test failure:
>>
>> === START TEST .../tests/fsck-tests/014-no-extent-info
>> testing image no_extent.raw.restored
>> ====== RUN MUSTFAIL .../btrfs check ./no_extent.raw.restored
>> Opening filesystem to check...
>> Checking filesystem on ./no_extent.raw.restored
>> UUID: aeee7297-37a4-4547-a8a9-7b870d58d31f
>> cache and super generation don't match, space cache will be invalidated
>> found 180224 bytes used, no error found
>> total csum bytes: 0
>> total tree bytes: 180224
>> total fs tree bytes: 81920
>> total extent tree bytes: 16384
>> btree space waste bytes: 138540
>> file data blocks allocated: 0
>>   referenced 0
>> succeeded (unexpected!): .../btrfs check ./no_extent.raw.restored
>> unexpected success: btrfs check should have detected corruption
>
>
> Weird, the problem is, for the restored image, if I run ./btrfs check
> manually it can detects the problem, but still go "no error found" path.
>
> So it must be my patch overriding the return value.

Indeed that's the case.

Fix upon current devel branch is:
https://lore.kernel.org/linux-btrfs/f576d7a548b91d42d02b17d2dc52ee04d943a57d.1648077794.git.wqu@suse.com/T/#u

Please fold the fix into the patch.

Thanks,
Qu
>
> Will fix it soon.
>
> Thanks,
> Qu

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch
  2022-03-23 23:30   ` Qu Wenruo
@ 2022-03-24 15:12     ` David Sterba
  0 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2022-03-24 15:12 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: dsterba, Qu Wenruo, linux-btrfs

On Thu, Mar 24, 2022 at 07:30:31AM +0800, Qu Wenruo wrote:
> 
> 
> On 2022/3/24 01:17, David Sterba wrote:
> > On Mon, Feb 28, 2022 at 08:50:06AM +0800, Qu Wenruo wrote:
> >> The patchset can be fetched from github:
> >> https://github.com/adam900710/btrfs-progs/tree/super_num_devs
> >>
> >> The 2nd patch contains a compressed raw image, thus it may be a little
> >> too large for the mail list.
> >
> > The compressed size is 22K, that's fine. I've recompressed it with 'xz
> > --best -e' and it shaved a few hundred bytes but that was just out of
> > curiosity.
> 
> I'm also a little interested in why things like zstd/xz is not that
> efficient in compressing raw btrfs images.

I think it is efficient, unpacked image was 128M and getting that to 22K
is a good result.

> Especially when creating the image I have created the image with all
> zero (fallocated) file in the first place, thus most space should just
> be all zero, and any compression method should be super efficient on them.
> 
> My current guesses are:
> 
> - DUP metadata is not fully detected by the algo
>    Especially when they are mostly quite some ranges away
> 
> - Some older tree blocks from mkfs
> 
> So for further raw image size reduction, we may want to:
> 
> - Use SINGLE metadata/data
> 
> - Fstrim the image first

Yeah that could remove any stale blocks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-03-24 15:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-28  0:50 [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch Qu Wenruo
2022-02-28  0:50 ` [PATCH 1/2] btrfs-progs: check: add check and repair ability for super num devs mismatch Qu Wenruo
2022-03-23 17:43   ` David Sterba
2022-03-23 23:15     ` Qu Wenruo
2022-03-23 23:38       ` Qu Wenruo
2022-02-28  0:50 ` [PATCH 2/2] btrfs-progs: tests/fsck: add test case " Qu Wenruo
2022-03-23 17:12 ` [PATCH 0/2] btrfs-progs: add check and repair ability for super num devices mismatch David Sterba
2022-03-23 17:17 ` David Sterba
2022-03-23 23:30   ` Qu Wenruo
2022-03-24 15:12     ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox