linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: fstests@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, josef@toxicpanda.com
Subject: [PATCH] btrfs/254: test cleaning up of the stale device
Date: Wed,  8 Dec 2021 22:07:46 +0800	[thread overview]
Message-ID: <c1c22a67c90f1b0b94ea3f99d6d6fd4a4d5d5473.1638953165.git.anand.jain@oracle.com> (raw)

Recreating a new filesystem or adding a device to a mounted the filesystem
should remove the device entries under its previous fsid even when
confused with different device paths to the same device.

Fixed by the kernel patch (in the ml):
  btrfs: harden identification of the stale device

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 tests/btrfs/254     | 110 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/254.out |   6 +++
 2 files changed, 116 insertions(+)
 create mode 100755 tests/btrfs/254
 create mode 100644 tests/btrfs/254.out

diff --git a/tests/btrfs/254 b/tests/btrfs/254
new file mode 100755
index 000000000000..6c3414f73d15
--- /dev/null
+++ b/tests/btrfs/254
@@ -0,0 +1,110 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 Anand Jain. All Rights Reserved.
+# Copyright (c) 2021 Oracle. All Rights Reserved.
+#
+# FS QA Test No. 254
+#
+# Test if the kernel can free the stale device entries.
+# 
+. ./common/preamble
+_begin_fstest auto quick
+
+# Override the default cleanup function.
+node=$seq-test
+cleanup_dmdev()
+{
+	_dmsetup_remove $node
+}
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+	rm -rf $seq_mnt > /dev/null 2>&1
+	cleanup_dmdev
+}
+
+# Import common functions.
+. ./common/filter
+. ./common/filter.btrfs
+
+# real QA test starts here
+_supported_fs btrfs
+_require_scratch_dev_pool 3
+_require_block_device $SCRATCH_DEV
+_require_dm_target linear
+_require_btrfs_forget_or_module_loadable
+_require_scratch_nocheck
+_require_command "$WIPEFS_PROG" wipefs
+
+_scratch_dev_pool_get 3
+
+setup_dmdev()
+{
+	# Some small size.
+	size=$((1024 * 1024 * 1024))
+	size_in_sector=$((size / 512))
+
+	table="0 $size_in_sector linear $SCRATCH_DEV 0"
+	_dmsetup_create $node --table "$table" || \
+		_fail "setup dm device failed"
+}
+
+# Use a known it is much easier to debug.
+uuid="--uuid 12345678-1234-1234-1234-123456789abc"
+lvdev=/dev/mapper/$node
+
+seq_mnt=$TEST_DIR/$seq.mnt
+mkdir -p $seq_mnt
+
+test_forget()
+{
+	setup_dmdev
+	dmdev=$(realpath $lvdev)
+
+	_mkfs_dev $uuid $dmdev
+
+	# Check if we can un-scan using the mapper device path.
+	$BTRFS_UTIL_PROG device scan --forget $lvdev
+
+	# Cleanup
+	$WIPEFS_PROG -a $lvdev > /dev/null 2>&1
+	$BTRFS_UTIL_PROG device scan --forget
+
+	cleanup_dmdev
+}
+
+test_add_device()
+{
+	setup_dmdev
+	dmdev=$(realpath $lvdev)
+	scratch_dev2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	scratch_dev3=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
+
+	_mkfs_dev $scratch_dev3
+	_mount $scratch_dev3 $seq_mnt
+
+	_mkfs_dev $uuid -draid1 -mraid1 $dmdev $scratch_dev2
+
+	# Add device should free the device under $uuid in the kernel.
+	$BTRFS_UTIL_PROG device add -f $lvdev $seq_mnt
+
+	_mount -o degraded $scratch_dev2 $SCRATCH_MNT
+
+	# Check if the missing device is shown.
+	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
+					_filter_btrfs_filesystem_show
+
+	$UMOUNT_PROG $seq_mnt
+	_scratch_unmount
+	cleanup_dmdev
+}
+
+test_forget
+test_add_device
+
+_scratch_dev_pool_put
+
+status=0
+exit
diff --git a/tests/btrfs/254.out b/tests/btrfs/254.out
new file mode 100644
index 000000000000..20819cf5140c
--- /dev/null
+++ b/tests/btrfs/254.out
@@ -0,0 +1,6 @@
+QA output created by 254
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
-- 
2.27.0


             reply	other threads:[~2021-12-08 14:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-08 14:07 Anand Jain [this message]
2021-12-08 14:50 ` [PATCH] btrfs/254: test cleaning up of the stale device Josef Bacik
2021-12-09  6:41   ` Anand Jain
2021-12-09 14:28     ` Josef Bacik
2021-12-10 18:07       ` Anand Jain
2021-12-14 13:12       ` David Sterba

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=c1c22a67c90f1b0b94ea3f99d6d6fd4a4d5d5473.1638953165.git.anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=fstests@vger.kernel.org \
    --cc=josef@toxicpanda.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).