aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2024-02-20 03:48:47 +0800
committerZorro Lang <zlang@kernel.org>2024-03-01 19:22:36 +0800
commit3ec2d4378c6c2021951d3705f27f0e6807196401 (patch)
tree70b5f479c098600e5099349e94f9638c5f611f97
parent5673516f98243e5dfff9f6ecb967b1255fb0ebb1 (diff)
downloadxfstests-dev-3ec2d4378c6c2021951d3705f27f0e6807196401.tar.gz
btrfs: introduce helper for creating cloned devices with mkfs
Use newer mkfs.btrfs option to generate two cloned devices, used in test cases. Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Anand Jain <anand.jain@oracle.com>
-rw-r--r--common/btrfs23
1 files changed, 23 insertions, 0 deletions
diff --git a/common/btrfs b/common/btrfs
index fe6fc2196e..7141a0bb7b 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -843,3 +843,26 @@ check_fsid()
echo -e -n "Tempfsid status:\t"
cat /sys/fs/btrfs/$tempfsid/temp_fsid
}
+
+mkfs_clone()
+{
+ local fsid
+ local uuid
+ local dev1=$1
+ local dev2=$2
+
+ _require_btrfs_command inspect-internal dump-super
+ _require_btrfs_mkfs_uuid_option
+
+ [[ -z $dev1 || -z $dev2 ]] && \
+ _fail "mkfs_clone requires two devices as arguments"
+
+ _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
+}