From: Anand Jain Date: Mon, 19 Feb 2024 19:48:47 +0000 (+0800) Subject: btrfs: introduce helper for creating cloned devices with mkfs X-Git-Tag: v2024.03.03~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3ec2d4378c6c2021951d3705f27f0e6807196401;p=xfstests-dev.git 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 Signed-off-by: Anand Jain --- diff --git a/common/btrfs b/common/btrfs index fe6fc219..7141a0bb 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 +}