Re: [PATCH for-11.1?] qemu-iotest 161: fix race

Daniel P. Berrangé <[email protected]>
Newsgroups gmane.comp.emulators.qemu.block,gmane.comp.emulators.qemu
Message-ID <[email protected]>
On Tue, Jul 28, 2026 at 07:39:16PM +0300, Michael Tokarev wrote:
> qemu-iotest 161 fails intermittedly due to a race condition:
> 
> qemu:block / io-qcow2-161             ERROR            2.08s   exit status 1
> ――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――
> stderr:
> --- tests/qemu-iotests/161.out
> +++ scratch/qcow2-file-161/161.out.bad
> @@ -34,6 +34,8 @@
>  *** Commit and then change an option on the backing file
> 
>  Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=1048576
> +qemu-img: TEST_DIR/t.IMGFMT.base: Failed to get "write" lock
> +Is another process using the image [TEST_DIR/t.IMGFMT.base]?
>  Formatting 'TEST_DIR/t.IMGFMT.int', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=IMGFMT
>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/t.IMGFMT.int backing_fmt=IMGFMT
>  { 'execute': 'qmp_capabilities' }
> 
> This test is run right after a previous test, where we've
> killed qemu process which holds the test image open.

When you say "previous test" can you clarify the scenario you're
hitting. The tests run with TEST_DIR set to a name that is unique
to the test name + format. eg

   qemu.git/build/scratch/raw-file-101

so...

> It looks like when the next test is started (with creating
> the image files), old qemu is still running, so we're racing
> with that qemu, and qemu-img is unable to lock the image file
> properly.

...iiuc this can only happen if the exact same test + format is
re-run ?

Is that what you're doing ?

If so, rather than deleting the image we should do two
things

 * Make sure tests clean up after themselves if we find one that
   is buggy and leaves stuff running
 
 * Make TEST_DIR more unique by adding the current test hardness
   PID to is, so re-runs can never clash

diff --git a/tests/qemu-iotests/testrunner.py b/tests/qemu-iotests/testrunner.py
index dbe2dddc32..9c7f9d733e 100644
--- a/tests/qemu-iotests/testrunner.py
+++ b/tests/qemu-iotests/testrunner.py
@@ -259,7 +259,7 @@ def do_run_test(self, test: str) -> TestResult:
         for d in ['TEST_DIR', 'SOCK_DIR']:
             env[d] = os.path.join(
                 env[d],
-                f"{self.env.imgfmt}-{self.env.imgproto}-{f_test.name}")
+                f"{self.env.imgfmt}-{self.env.imgproto}-{f_test.name}-{os.getpid()}")
             Path(env[d]).mkdir(parents=True, exist_ok=True)
 
         test_dir = env['TEST_DIR']



With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.