diff mbox series

[v5,2/6] fstests: common/rc: fix unset seqres in _set_fs_sysfs_attr

Message ID 5e081252abdcf7253ad83d2b5eda49a8818305ad.1743996408.git.anand.jain@oracle.com (mailing list archive)
State New
Headers show
Series fstests: btrfs: add test case to validate sysfs input arguments | expand

Commit Message

Anand Jain April 7, 2025, 3:48 a.m. UTC
Ensure logs don’t write to a `.full` file when `_set_fs_sysfs_attr()`
is called during setup (before a testcase) in XFS due to unset seqres.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 common/rc | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Darrick J. Wong April 7, 2025, 4:58 p.m. UTC | #1
On Mon, Apr 07, 2025 at 11:48:16AM +0800, Anand Jain wrote:
> Ensure logs don’t write to a `.full` file when `_set_fs_sysfs_attr()`
> is called during setup (before a testcase) in XFS due to unset seqres.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  common/rc | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/common/rc b/common/rc
> index e89eee5de840..ca1d13ca1f0b 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -5201,6 +5201,13 @@ _set_fs_sysfs_attr()
>  	local attr=$1
>  	shift
>  	local content="$*"
> +	local logfile="/dev/null"

If we're not actually running a test, should the error output go to
$check.full instead?

--D

> +
> +	# This function may be called outside a testcase during setup,
> +	# so seqres might not be set.
> +	if [[ -v seqres ]]; then
> +		logfile="$seqres.full"
> +	fi
>  
>  	if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
>  		_fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
> @@ -5208,8 +5215,8 @@ _set_fs_sysfs_attr()
>  
>  	local dname=$(_fs_sysfs_dname $dev)
>  
> -	echo "echo '$content' 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr}" >> $seqres.full
> -	echo "$content" 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr} | tee -a $seqres.full
> +	echo "echo '$content' 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr}" >> $logfile
> +	echo "$content" 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr} | tee -a $logfile
>  }
>  
>  # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
> -- 
> 2.47.0
> 
>
Anand Jain April 8, 2025, 3:10 p.m. UTC | #2
On 8/4/25 00:58, Darrick J. Wong wrote:
> On Mon, Apr 07, 2025 at 11:48:16AM +0800, Anand Jain wrote:
>> Ensure logs don’t write to a `.full` file when `_set_fs_sysfs_attr()`
>> is called during setup (before a testcase) in XFS due to unset seqres.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   common/rc | 11 +++++++++--
>>   1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/common/rc b/common/rc
>> index e89eee5de840..ca1d13ca1f0b 100644
>> --- a/common/rc
>> +++ b/common/rc
>> @@ -5201,6 +5201,13 @@ _set_fs_sysfs_attr()
>>   	local attr=$1
>>   	shift
>>   	local content="$*"
>> +	local logfile="/dev/null"
> 
> If we're not actually running a test, should the error output go to
> $check.full instead?
> 

Ah. I didn't know. It seems like no one is using check.full.

-----
$ find . -type f -exec grep check\.full {} \; -print
	rm -f $check.full
./check
-----

Thanks, Anand


> --D
> 
>> +
>> +	# This function may be called outside a testcase during setup,
>> +	# so seqres might not be set.
>> +	if [[ -v seqres ]]; then
>> +		logfile="$seqres.full"
>> +	fi
>>   
>>   	if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
>>   		_fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
>> @@ -5208,8 +5215,8 @@ _set_fs_sysfs_attr()
>>   
>>   	local dname=$(_fs_sysfs_dname $dev)
>>   
>> -	echo "echo '$content' 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr}" >> $seqres.full
>> -	echo "$content" 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr} | tee -a $seqres.full
>> +	echo "echo '$content' 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr}" >> $logfile
>> +	echo "$content" 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr} | tee -a $logfile
>>   }
>>   
>>   # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
>> -- 
>> 2.47.0
>>
>>
Darrick J. Wong April 8, 2025, 4:10 p.m. UTC | #3
On Tue, Apr 08, 2025 at 11:10:43PM +0800, Anand Jain wrote:
> 
> 
> On 8/4/25 00:58, Darrick J. Wong wrote:
> > On Mon, Apr 07, 2025 at 11:48:16AM +0800, Anand Jain wrote:
> > > Ensure logs don’t write to a `.full` file when `_set_fs_sysfs_attr()`
> > > is called during setup (before a testcase) in XFS due to unset seqres.
> > > 
> > > Signed-off-by: Anand Jain <anand.jain@oracle.com>
> > > ---
> > >   common/rc | 11 +++++++++--
> > >   1 file changed, 9 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/common/rc b/common/rc
> > > index e89eee5de840..ca1d13ca1f0b 100644
> > > --- a/common/rc
> > > +++ b/common/rc
> > > @@ -5201,6 +5201,13 @@ _set_fs_sysfs_attr()
> > >   	local attr=$1
> > >   	shift
> > >   	local content="$*"
> > > +	local logfile="/dev/null"
> > 
> > If we're not actually running a test, should the error output go to
> > $check.full instead?
> > 
> 
> Ah. I didn't know. It seems like no one is using check.full.

Oh, they do, but it's subtle:

$ git grep seqres=
check:852:      seqres="$check"
check:1120:     seqres="$check"

--D

> -----
> $ find . -type f -exec grep check\.full {} \; -print
> 	rm -f $check.full
> ./check
> -----
> 
> Thanks, Anand
> 
> 
> > --D
> > 
> > > +
> > > +	# This function may be called outside a testcase during setup,
> > > +	# so seqres might not be set.
> > > +	if [[ -v seqres ]]; then
> > > +		logfile="$seqres.full"
> > > +	fi
> > >   	if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
> > >   		_fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
> > > @@ -5208,8 +5215,8 @@ _set_fs_sysfs_attr()
> > >   	local dname=$(_fs_sysfs_dname $dev)
> > > -	echo "echo '$content' 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr}" >> $seqres.full
> > > -	echo "$content" 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr} | tee -a $seqres.full
> > > +	echo "echo '$content' 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr}" >> $logfile
> > > +	echo "$content" 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr} | tee -a $logfile
> > >   }
> > >   # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
> > > -- 
> > > 2.47.0
> > > 
> > > 
> 
>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index e89eee5de840..ca1d13ca1f0b 100644
--- a/common/rc
+++ b/common/rc
@@ -5201,6 +5201,13 @@  _set_fs_sysfs_attr()
 	local attr=$1
 	shift
 	local content="$*"
+	local logfile="/dev/null"
+
+	# This function may be called outside a testcase during setup,
+	# so seqres might not be set.
+	if [[ -v seqres ]]; then
+		logfile="$seqres.full"
+	fi
 
 	if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
 		_fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
@@ -5208,8 +5215,8 @@  _set_fs_sysfs_attr()
 
 	local dname=$(_fs_sysfs_dname $dev)
 
-	echo "echo '$content' 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr}" >> $seqres.full
-	echo "$content" 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr} | tee -a $seqres.full
+	echo "echo '$content' 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr}" >> $logfile
+	echo "$content" 2>&1 > /sys/fs/${FSTYP}/${dname}/${attr} | tee -a $logfile
 }
 
 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR