]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
btrfs: introduce helper for creating cloned devices with mkfs
authorAnand Jain <anand.jain@oracle.com>
Mon, 19 Feb 2024 19:48:47 +0000 (03:48 +0800)
committerZorro Lang <zlang@kernel.org>
Fri, 1 Mar 2024 11:22:36 +0000 (19:22 +0800)
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>
common/btrfs

index fe6fc2196e6828d114be289d4ff58e46145677f4..7141a0bb7b786289d2f1b2402df78f2653c5b0b0 100644 (file)
@@ -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
+}