[PATCH 09/12] btrfs: introduce helper for creating cloned devices with mkfs

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



Use newer mkfs.btrfs option to generate two cloned devices,
used in test cases.

Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx>
---
 common/btrfs | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/common/btrfs b/common/btrfs
index 9a7fa2c71ec5..8ffce3c39695 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -91,13 +91,7 @@ _require_btrfs_mkfs_feature()
 _require_btrfs_mkfs_uuid_option()
 {
 	local cnt
-	local feature
 
-	if [ -z $1 ]; then
-		echo "Missing option name argument for _require_btrfs_mkfs_option"
-		exit 1
-	fi
-	feature=$1
 	cnt=$($MKFS_BTRFS_PROG --help 2>&1 |grep -E --count "\-\-uuid|\-\-device-uuid")
 	if [ $cnt != 2 ]; then
 		_notrun "Require $MKFS_BTRFS_PROG with --uuid and --device-uuid option"
@@ -864,3 +858,21 @@ create_cloned_devices()
 							_fail "dd failed: $?"
 	echo done
 }
+
+mkfs_clone()
+{
+	local dev1=$1
+	local dev2=$2
+
+	[[ -z $dev1 || -z $dev2 ]] && \
+		_fail "BUGGY code, mkfs_clone needs arg1 arg2"
+
+	_mkfs_dev -fq $dev1
+
+	fsid=$($BTRFS_UTIL_PROG inspect-internal dump-super $dev1 | \
+					grep -E ^fsid | $AWK_PROG '{print $2}')
+	uuid=$($BTRFS_UTIL_PROG inspect-internal dump-super $dev1 | \
+				grep -E ^dev_item.uuid | $AWK_PROG '{print $2}')
+
+	_mkfs_dev -fq --uuid $fsid --device-uuid $uuid $dev2
+}
-- 
2.39.3





[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux