linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs: Fix lost-data-profile caused by auto removing bg
@ 2015-09-29 13:51 Zhao Lei
  2015-09-29 13:51 ` [PATCH 2/2] btrfs: Fix lost-data-profile caused by balance bg Zhao Lei
  2015-09-30  7:42 ` [PATCH 1/2] btrfs: Fix lost-data-profile caused by auto removing bg Filipe Manana
  0 siblings, 2 replies; 10+ messages in thread
From: Zhao Lei @ 2015-09-29 13:51 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Zhao Lei

Reproduce:
 (In integration-4.3 branch)

 TEST_DEV=(/dev/vdg /dev/vdh)
 TEST_DIR=/mnt/tmp

 umount "$TEST_DEV" >/dev/null
 mkfs.btrfs -f -d raid1 "${TEST_DEV[@]}"

 mount -o nospace_cache "$TEST_DEV" "$TEST_DIR"
 umount "$TEST_DEV"

 mount -o nospace_cache "$TEST_DEV" "$TEST_DIR"
 btrfs filesystem usage $TEST_DIR

We can see the data chunk changed from raid1 to single:
 # btrfs filesystem usage $TEST_DIR
 Data,single: Size:8.00MiB, Used:0.00B
    /dev/vdg        8.00MiB
 #

Reason:
 When a empty filesystem mount with -o nospace_cache, the last
 data blockgroup will be auto-removed in umount.

 Then if we mount it again, there is no data chunk in the
 filesystem, so the only available data profile is 0x0, result
 is all new chunks are created as single type.

Fix:
 Don't auto-delete last blockgroup for a raid type.

Test:
 Test by above script, and confirmed the logic by debug output.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 fs/btrfs/extent-tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 79a5bd9..3505649 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -10012,7 +10012,8 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
 					       bg_list);
 		space_info = block_group->space_info;
 		list_del_init(&block_group->bg_list);
-		if (ret || btrfs_mixed_space_info(space_info)) {
+		if (ret || btrfs_mixed_space_info(space_info) ||
+		    block_group->list.next == block_group->list.prev) {
 			btrfs_put_block_group(block_group);
 			continue;
 		}
-- 
1.8.5.1


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

end of thread, other threads:[~2015-09-30 10:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-29 13:51 [PATCH 1/2] btrfs: Fix lost-data-profile caused by auto removing bg Zhao Lei
2015-09-29 13:51 ` [PATCH 2/2] btrfs: Fix lost-data-profile caused by balance bg Zhao Lei
2015-09-29 15:47   ` Filipe Manana
2015-09-30  4:20     ` Zhao Lei
2015-09-30  7:41       ` Filipe Manana
2015-09-30  8:26         ` Zhao Lei
2015-09-30  9:44           ` Filipe Manana
2015-09-30  7:42 ` [PATCH 1/2] btrfs: Fix lost-data-profile caused by auto removing bg Filipe Manana
2015-09-30 10:06   ` Zhao Lei
2015-09-30 10:26     ` Filipe Manana

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).