All of lore.kernel.org
 help / color / mirror / Atom feed
From: fdmanana@kernel.org
To: fstests@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, Filipe Manana <fdmanana@suse.com>
Subject: [PATCH 08/10] btrfs: add helper to stop background process running _btrfs_stress_subvolume
Date: Wed, 27 Mar 2024 17:11:42 +0000	[thread overview]
Message-ID: <478d09248cf2a98a59853718197104735edd52c7.1711558345.git.fdmanana@suse.com> (raw)
In-Reply-To: <cover.1711558345.git.fdmanana@suse.com>

From: Filipe Manana <fdmanana@suse.com>

We have this logic to stop a process running _btrfs_stress_subvolume()
spread in several test cases:

   touch $stop_file
   wait $subvol_pid

Add a helper to encapsulate that logic and also remove the stop file after
the process terminated as there's no point having it around anymore.

This will help to avoid repeating the same code again several times in
upcoming changes.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 common/btrfs    | 12 ++++++++++++
 tests/btrfs/060 |  3 +--
 tests/btrfs/065 |  3 +--
 tests/btrfs/066 |  3 +--
 tests/btrfs/067 |  3 +--
 tests/btrfs/068 |  3 +--
 6 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/common/btrfs b/common/btrfs
index 6d7e7a68..e19a6ad1 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -340,6 +340,18 @@ _btrfs_stress_subvolume()
 	done
 }
 
+# Kill a background process running _btrfs_stress_subvolume()
+_btrfs_kill_stress_subvolume_pid()
+{
+	local subvol_pid=$1
+	local stop_file=$2
+
+	touch $stop_file
+	# Ignore if process already died.
+	wait $subvol_pid &> /dev/null
+	rm -f $stop_file
+}
+
 # stress btrfs by running scrub in a loop
 _btrfs_stress_scrub()
 {
diff --git a/tests/btrfs/060 b/tests/btrfs/060
index 58167cc6..87823aba 100755
--- a/tests/btrfs/060
+++ b/tests/btrfs/060
@@ -56,8 +56,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_balance_pid $balance_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
diff --git a/tests/btrfs/065 b/tests/btrfs/065
index d2b04178..ddc28616 100755
--- a/tests/btrfs/065
+++ b/tests/btrfs/065
@@ -64,8 +64,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_replace_pid $replace_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
diff --git a/tests/btrfs/066 b/tests/btrfs/066
index 29821fdd..c7488602 100755
--- a/tests/btrfs/066
+++ b/tests/btrfs/066
@@ -56,8 +56,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_scrub_pid $scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
diff --git a/tests/btrfs/067 b/tests/btrfs/067
index 2bb00b87..ebbec1be 100755
--- a/tests/btrfs/067
+++ b/tests/btrfs/067
@@ -57,8 +57,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_defrag_pid $defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
diff --git a/tests/btrfs/068 b/tests/btrfs/068
index db53254a..5f41fb74 100755
--- a/tests/btrfs/068
+++ b/tests/btrfs/068
@@ -57,8 +57,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
 	echo "Scrub the filesystem" >>$seqres.full
-- 
2.43.0


  parent reply	other threads:[~2024-03-27 17:12 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 17:11 [PATCH 00/10] fstests/btrfs: fixes for tests btrfs/06[0-9] and btrfs/07[0-4] fdmanana
2024-03-27 17:11 ` [PATCH 01/10] btrfs: add helper to kill background process running _btrfs_stress_balance fdmanana
2024-03-28  8:16   ` Anand Jain
2024-03-28  9:21     ` Filipe Manana
2024-03-27 17:11 ` [PATCH 02/10] btrfs/028: use the helper _btrfs_kill_stress_balance_pid fdmanana
2024-03-28  8:41   ` Anand Jain
2024-03-28  9:25     ` Filipe Manana
2024-03-27 17:11 ` [PATCH 03/10] btrfs/028: removed redundant sync and scratch filesystem unmount fdmanana
2024-03-27 17:11 ` [PATCH 04/10] btrfs: add helper to kill background process running _btrfs_stress_scrub fdmanana
2024-03-28  8:41   ` Anand Jain
2024-03-28  9:27     ` Filipe Manana
2024-03-27 17:11 ` [PATCH 05/10] btrfs: add helper to kill background process running _btrfs_stress_defrag fdmanana
2024-03-28  9:18   ` Anand Jain
2024-03-28  9:32     ` Filipe Manana
2024-03-27 17:11 ` [PATCH 06/10] btrfs: add helper to kill background process running _btrfs_stress_remount_compress fdmanana
2024-03-28  9:24   ` Anand Jain
2024-03-28 11:46     ` Anand Jain
2024-03-28 12:03       ` Filipe Manana
2024-03-28 12:50         ` Anand Jain
2024-03-27 17:11 ` [PATCH 07/10] btrfs: add helper to kill background process running _btrfs_stress_replace fdmanana
2024-03-28  9:35   ` Anand Jain
2024-03-27 17:11 ` fdmanana [this message]
2024-03-28  9:36   ` [PATCH 08/10] btrfs: add helper to stop background process running _btrfs_stress_subvolume Anand Jain
2024-03-27 17:11 ` [PATCH 09/10] btrfs: remove stop file early at _btrfs_stress_subvolume fdmanana
2024-03-28  9:38   ` Anand Jain
2024-03-27 17:11 ` [PATCH 10/10] btrfs/06[0-9]..07[0-4]: kill all background tasks when test is killed/interrupted fdmanana
2024-03-28  9:48   ` Anand Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=478d09248cf2a98a59853718197104735edd52c7.1711558345.git.fdmanana@suse.com \
    --to=fdmanana@kernel.org \
    --cc=fdmanana@suse.com \
    --cc=fstests@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.