diff mbox series

[v3,07/10] btrfs: introduce helper for creating cloned devices with mkfs

Message ID 8b66778c41341db1ae73fcdf4d30b8f1cd32208c.1708772619.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs: functional test cases for tempfsid | expand

Commit Message

Anand Jain Feb. 24, 2024, 4:43 p.m. UTC
Use newer mkfs.btrfs option to generate two cloned devices,
used in test cases.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3:
 call
 _require_btrfs_command inspect-internal dump-super
 _require_btrfs_mkfs_uuid_option
 in the function mkfs_clone()
 Remove the conflict fix metadata line

v2:
 Organize changes to its right patch.
 Fix _fail erorr message.
 Declare local variables for fsid and uuid.

 common/btrfs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Filipe Manana Feb. 26, 2024, 11:57 a.m. UTC | #1
On Sat, Feb 24, 2024 at 4:44 PM Anand Jain <anand.jain@oracle.com> wrote:
>
> Use newer mkfs.btrfs option to generate two cloned devices,
> used in test cases.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Looks good, thanks.

> ---
> v3:
>  call
>  _require_btrfs_command inspect-internal dump-super
>  _require_btrfs_mkfs_uuid_option
>  in the function mkfs_clone()
>  Remove the conflict fix metadata line
>
> v2:
>  Organize changes to its right patch.
>  Fix _fail erorr message.
>  Declare local variables for fsid and uuid.
>
>  common/btrfs | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/common/btrfs b/common/btrfs
> index 55847733b20e..04ecff6ada71 100644
> --- a/common/btrfs
> +++ b/common/btrfs
> @@ -840,3 +840,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
> +}
> --
> 2.39.3
>
diff mbox series

Patch

diff --git a/common/btrfs b/common/btrfs
index 55847733b20e..04ecff6ada71 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -840,3 +840,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
+}