diff mbox series

[v1.3,3/3] common/ext4: provide custom ext4 scratch fs options

Message ID YuvzzdisuzXKVlJK@magnolia
State Superseded
Headers show
Series None | expand

Commit Message

Darrick J. Wong Aug. 4, 2022, 4:29 p.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

Create a _scratch_options backend for ext* so that we can inject
pathnames to external log devices into the scratch fs mount options.
This enables common/dm* to install block device filters, e.g. dm-error
for stress testing.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
v1.1: bad at counting
v1.2: refactor _scratch_mkfs_ext4 to use _scratch_options too
v1.3: quiet down realpath usage when SCRATCH_LOGDEV is unset
---
 common/ext4 |   35 ++++++++++++++++++++++++++++++++---
 common/rc   |    3 +++
 2 files changed, 35 insertions(+), 3 deletions(-)

Comments

Zorro Lang Aug. 5, 2022, 5:08 p.m. UTC | #1
On Thu, Aug 04, 2022 at 09:29:01AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create a _scratch_options backend for ext* so that we can inject
> pathnames to external log devices into the scratch fs mount options.
> This enables common/dm* to install block device filters, e.g. dm-error
> for stress testing.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> v1.1: bad at counting
> v1.2: refactor _scratch_mkfs_ext4 to use _scratch_options too
> v1.3: quiet down realpath usage when SCRATCH_LOGDEV is unset

I think you'd like move these 3 change log lines after the "---" ?

As usual, I'm going to give this patchset enough testing before merging
it, due to it affect ext4 testing too much. And hope to get review from
ext4 list, or "no objection" means all good by default :)

Thanks,
Zorro

> ---
>  common/ext4 |   35 ++++++++++++++++++++++++++++++++---
>  common/rc   |    3 +++
>  2 files changed, 35 insertions(+), 3 deletions(-)
> 
> diff --git a/common/ext4 b/common/ext4
> index 287705af..f2df888c 100644
> --- a/common/ext4
> +++ b/common/ext4
> @@ -63,16 +63,24 @@ _setup_large_ext4_fs()
>  	return 0
>  }
>  
> +_scratch_mkfs_ext4_opts()
> +{
> +	mkfs_opts=$*
> +
> +	_scratch_options mkfs
> +
> +	echo "$MKFS_EXT4_PROG $SCRATCH_OPTIONS $mkfs_opts"
> +}
> +
>  _scratch_mkfs_ext4()
>  {
> -	local mkfs_cmd="$MKFS_EXT4_PROG -F"
> +	local mkfs_cmd="`_scratch_mkfs_ext4_opts`"
>  	local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \" | grep -v \"^$\""
>  	local tmp=`mktemp -u`
>  	local mkfs_status
>  
>  	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
> -	    $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
> -	    mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
> +	    $MKFS_EXT4_PROG -F -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV
>  
>  	_scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
>  	mkfs_status=$?
> @@ -154,3 +162,24 @@ _require_scratch_richacl_ext4()
>  		|| _notrun "kernel doesn't support richacl feature on $FSTYP"
>  	_scratch_unmount
>  }
> +
> +_scratch_ext4_options()
> +{
> +	local type=$1
> +	local log_opt=""
> +
> +	case $type in
> +	mkfs)
> +		SCRATCH_OPTIONS="$SCRATCH_OPTIONS -F"
> +		log_opt="-J device=$SCRATCH_LOGDEV"
> +		;;
> +	mount)
> +		# As of kernel 5.19, the kernel mount option path parser only
> +		# accepts direct paths to block devices--the final path
> +		# component cannot be a symlink.
> +		log_opt="-o journal_path=$(realpath -q "$SCRATCH_LOGDEV")"
> +		;;
> +	esac
> +	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
> +		SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}"
> +}
> diff --git a/common/rc b/common/rc
> index dc1d65c3..b82bb36b 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -178,6 +178,9 @@ _scratch_options()
>      "xfs")
>  	_scratch_xfs_options "$@"
>  	;;
> +    ext2|ext3|ext4|ext4dev)
> +	_scratch_ext4_options "$@"
> +	;;
>      esac
>  }
>  
>
diff mbox series

Patch

diff --git a/common/ext4 b/common/ext4
index 287705af..f2df888c 100644
--- a/common/ext4
+++ b/common/ext4
@@ -63,16 +63,24 @@  _setup_large_ext4_fs()
 	return 0
 }
 
+_scratch_mkfs_ext4_opts()
+{
+	mkfs_opts=$*
+
+	_scratch_options mkfs
+
+	echo "$MKFS_EXT4_PROG $SCRATCH_OPTIONS $mkfs_opts"
+}
+
 _scratch_mkfs_ext4()
 {
-	local mkfs_cmd="$MKFS_EXT4_PROG -F"
+	local mkfs_cmd="`_scratch_mkfs_ext4_opts`"
 	local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \" | grep -v \"^$\""
 	local tmp=`mktemp -u`
 	local mkfs_status
 
 	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
-	    $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
-	    mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
+	    $MKFS_EXT4_PROG -F -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV
 
 	_scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
 	mkfs_status=$?
@@ -154,3 +162,24 @@  _require_scratch_richacl_ext4()
 		|| _notrun "kernel doesn't support richacl feature on $FSTYP"
 	_scratch_unmount
 }
+
+_scratch_ext4_options()
+{
+	local type=$1
+	local log_opt=""
+
+	case $type in
+	mkfs)
+		SCRATCH_OPTIONS="$SCRATCH_OPTIONS -F"
+		log_opt="-J device=$SCRATCH_LOGDEV"
+		;;
+	mount)
+		# As of kernel 5.19, the kernel mount option path parser only
+		# accepts direct paths to block devices--the final path
+		# component cannot be a symlink.
+		log_opt="-o journal_path=$(realpath -q "$SCRATCH_LOGDEV")"
+		;;
+	esac
+	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+		SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}"
+}
diff --git a/common/rc b/common/rc
index dc1d65c3..b82bb36b 100644
--- a/common/rc
+++ b/common/rc
@@ -178,6 +178,9 @@  _scratch_options()
     "xfs")
 	_scratch_xfs_options "$@"
 	;;
+    ext2|ext3|ext4|ext4dev)
+	_scratch_ext4_options "$@"
+	;;
     esac
 }