* [kvm-unit-tests PATCH v2 0/9] Multi-migration support
@ 2024-02-02 6:57 Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation Nicholas Piggin
` (8 more replies)
0 siblings, 9 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
There were not many comments on the previous post last year, so
this a rebase and resend. No significant change to migration patches,
but this rebases on Marc's better fix for cleaning auxinfo. So that
s390 patch is dropped, but added a minor fix for it instead :).
Multi migration works fine. And arm now has a reason to implement a
a getchar that can run more than 15 times.
Thanks,
Nick
Nicholas Piggin (9):
(arm|powerpc|s390x): Makefile: Fix .aux.o generation
arch-run: Clean up temporary files properly
arch-run: Clean up initrd cleanup
migration: use a more robust way to wait for background job
migration: Support multiple migrations
arch-run: rename migration variables
migration: Add quiet migration support
Add common/ directory for architecture-independent tests
migration: add a migration selftest
arm/Makefile.common | 3 +-
arm/sieve.c | 2 +-
arm/unittests.cfg | 6 ++
common/selftest-migration.c | 34 +++++++
common/sieve.c | 51 ++++++++++
lib/migrate.c | 20 +++-
lib/migrate.h | 2 +
powerpc/Makefile.common | 3 +-
powerpc/unittests.cfg | 4 +
s390x/Makefile | 3 +-
s390x/sieve.c | 2 +-
s390x/unittests.cfg | 4 +
scripts/arch-run.bash | 181 ++++++++++++++++++++++++++----------
x86/sieve.c | 52 +----------
14 files changed, 260 insertions(+), 107 deletions(-)
create mode 100644 common/selftest-migration.c
create mode 100644 common/sieve.c
mode change 100644 => 120000 x86/sieve.c
--
2.42.0
^ permalink raw reply [flat|nested] 19+ messages in thread
* [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
@ 2024-02-02 6:57 ` Nicholas Piggin
2024-02-02 9:30 ` Andrew Jones
2024-02-05 14:20 ` Marc Hartmayer
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 2/9] arch-run: Clean up temporary files properly Nicholas Piggin
` (7 subsequent siblings)
8 siblings, 2 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
Using all prerequisites for the source file results in the build
dying on the second time around with:
gcc: fatal error: cannot specify ‘-o’ with ‘-c’, ‘-S’ or ‘-E’ with multiple files
This is due to auxinfo.h becoming a prerequisite after the first
build recorded the dependency.
Use the first prerequisite for this recipe.
Fixes: f2372f2d49135 ("(arm|powerpc|s390x): Makefile: add `%.aux.o` target")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arm/Makefile.common | 2 +-
powerpc/Makefile.common | 2 +-
s390x/Makefile | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arm/Makefile.common b/arm/Makefile.common
index 54cb4a63..c2ee568c 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -71,7 +71,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libeabi)
ifeq ($(CONFIG_EFI),y)
%.aux.o: $(SRCDIR)/lib/auxinfo.c
- $(CC) $(CFLAGS) -c -o $@ $^ \
+ $(CC) $(CFLAGS) -c -o $@ $< \
-DPROGNAME=\"$(@:.aux.o=.efi)\" -DAUXFLAGS=$(AUXFLAGS)
%.so: EFI_LDFLAGS += -defsym=EFI_SUBSYSTEM=0xa --no-undefined
diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
index 483ff648..eb88398d 100644
--- a/powerpc/Makefile.common
+++ b/powerpc/Makefile.common
@@ -48,7 +48,7 @@ cflatobjs += lib/powerpc/smp.o
OBJDIRS += lib/powerpc
%.aux.o: $(SRCDIR)/lib/auxinfo.c
- $(CC) $(CFLAGS) -c -o $@ $^ -DPROGNAME=\"$(@:.aux.o=.elf)\"
+ $(CC) $(CFLAGS) -c -o $@ $< -DPROGNAME=\"$(@:.aux.o=.elf)\"
FLATLIBS = $(libcflat) $(LIBFDT_archive)
%.elf: CFLAGS += $(arch_CFLAGS)
diff --git a/s390x/Makefile b/s390x/Makefile
index e64521e0..b72f7578 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -177,7 +177,7 @@ lds-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@
$(CPP) $(lds-autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
%.aux.o: $(SRCDIR)/lib/auxinfo.c
- $(CC) $(CFLAGS) -c -o $@ $^ -DPROGNAME=\"$(@:.aux.o=.elf)\"
+ $(CC) $(CFLAGS) -c -o $@ $< -DPROGNAME=\"$(@:.aux.o=.elf)\"
.SECONDEXPANSION:
%.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o %.aux.o
--
2.42.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [kvm-unit-tests PATCH v2 2/9] arch-run: Clean up temporary files properly
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation Nicholas Piggin
@ 2024-02-02 6:57 ` Nicholas Piggin
2024-02-07 7:58 ` Thomas Huth
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 3/9] arch-run: Clean up initrd cleanup Nicholas Piggin
` (6 subsequent siblings)
8 siblings, 1 reply; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
Migration files weren't being removed when tests were interrupted.
This improves the situation.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
scripts/arch-run.bash | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index d0864360..f22ead6f 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -134,12 +134,14 @@ run_migration ()
qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX)
qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX)
fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX)
+
+ # race here between file creation and trap
+ trap "trap - TERM ; kill 0 ; exit 2" INT TERM
+ trap "rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}" RETURN EXIT
+
qmpout1=/dev/null
qmpout2=/dev/null
- trap 'kill 0; exit 2' INT TERM
- trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT
-
eval "$@" -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \
-mon chardev=mon1,mode=control | tee ${migout1} &
live_pid=`jobs -l %+ | grep "eval" | awk '{print$2}'`
@@ -211,8 +213,8 @@ run_panic ()
qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX)
- trap 'kill 0; exit 2' INT TERM
- trap 'rm -f ${qmp}' RETURN EXIT
+ trap "trap - TERM ; kill 0 ; exit 2" INT TERM
+ trap "rm -f ${qmp}" RETURN EXIT
# start VM stopped so we don't miss any events
eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \
--
2.42.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [kvm-unit-tests PATCH v2 3/9] arch-run: Clean up initrd cleanup
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 2/9] arch-run: Clean up temporary files properly Nicholas Piggin
@ 2024-02-02 6:57 ` Nicholas Piggin
2024-02-05 12:04 ` Thomas Huth
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 4/9] migration: use a more robust way to wait for background job Nicholas Piggin
` (5 subsequent siblings)
8 siblings, 1 reply; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
Rather than put a big script into the trap handler, have it call
a function.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
scripts/arch-run.bash | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index f22ead6f..cc7da7c5 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -271,10 +271,20 @@ search_qemu_binary ()
export PATH=$save_path
}
+initrd_cleanup ()
+{
+ if [ "$KVM_UNIT_TESTS_ENV_OLD" ]; then
+ export KVM_UNIT_TESTS_ENV="$KVM_UNIT_TESTS_ENV_OLD"
+ else
+ unset KVM_UNIT_TESTS_ENV
+ unset KVM_UNIT_TESTS_ENV_OLD
+ fi
+}
+
initrd_create ()
{
if [ "$ENVIRON_DEFAULT" = "yes" ]; then
- trap_exit_push 'rm -f $KVM_UNIT_TESTS_ENV; [ "$KVM_UNIT_TESTS_ENV_OLD" ] && export KVM_UNIT_TESTS_ENV="$KVM_UNIT_TESTS_ENV_OLD" || unset KVM_UNIT_TESTS_ENV; unset KVM_UNIT_TESTS_ENV_OLD'
+ trap_exit_push 'rm -f $KVM_UNIT_TESTS_ENV; initrd_cleanup'
[ -f "$KVM_UNIT_TESTS_ENV" ] && export KVM_UNIT_TESTS_ENV_OLD="$KVM_UNIT_TESTS_ENV"
export KVM_UNIT_TESTS_ENV=$(mktemp)
env_params
--
2.42.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [kvm-unit-tests PATCH v2 4/9] migration: use a more robust way to wait for background job
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
` (2 preceding siblings ...)
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 3/9] arch-run: Clean up initrd cleanup Nicholas Piggin
@ 2024-02-02 6:57 ` Nicholas Piggin
2024-02-05 14:58 ` Marc Hartmayer
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 5/9] migration: Support multiple migrations Nicholas Piggin
` (4 subsequent siblings)
8 siblings, 1 reply; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
Starting a pipeline of jobs in the background does not seem to have
a simple way to reliably find the pid of a particular process in the
pipeline (because not all processes are started when the shell
continues to execute).
The way PID of QEMU is derived can result in a failure waiting on a
PID that is not running. This is easier to hit with subsequent
multiple-migration support. Changing this to use $! by swapping the
pipeline for a fifo is more robust.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
scripts/arch-run.bash | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index cc7da7c5..8fbfc50c 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -131,6 +131,7 @@ run_migration ()
migsock=$(mktemp -u -t mig-helper-socket.XXXXXXXXXX)
migout1=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX)
+ migout_fifo1=$(mktemp -u -t mig-helper-fifo-stdout1.XXXXXXXXXX)
qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX)
qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX)
fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX)
@@ -143,8 +144,9 @@ run_migration ()
qmpout2=/dev/null
eval "$@" -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \
- -mon chardev=mon1,mode=control | tee ${migout1} &
- live_pid=`jobs -l %+ | grep "eval" | awk '{print$2}'`
+ -mon chardev=mon1,mode=control > ${migout_fifo1} &
+ live_pid=$!
+ cat ${migout_fifo1} | tee ${migout1} &
# We have to use cat to open the named FIFO, because named FIFO's, unlike
# pipes, will block on open() until the other end is also opened, and that
@@ -152,7 +154,7 @@ run_migration ()
mkfifo ${fifo}
eval "$@" -chardev socket,id=mon2,path=${qmp2},server=on,wait=off \
-mon chardev=mon2,mode=control -incoming unix:${migsock} < <(cat ${fifo}) &
- incoming_pid=`jobs -l %+ | awk '{print$2}'`
+ incoming_pid=$!
# The test must prompt the user to migrate, so wait for the "migrate" keyword
while ! grep -q -i "Now migrate the VM" < ${migout1} ; do
@@ -166,6 +168,10 @@ run_migration ()
sleep 1
done
+ # Wait until the destination has created the incoming and qmp sockets
+ while ! [ -S ${migsock} ] ; do sleep 0.1 ; done
+ while ! [ -S ${qmp2} ] ; do sleep 0.1 ; done
+
qmp ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1}
# Wait for the migration to complete
--
2.42.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [kvm-unit-tests PATCH v2 5/9] migration: Support multiple migrations
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
` (3 preceding siblings ...)
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 4/9] migration: use a more robust way to wait for background job Nicholas Piggin
@ 2024-02-02 6:57 ` Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 6/9] arch-run: rename migration variables Nicholas Piggin
` (3 subsequent siblings)
8 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
Support multiple migrations by flipping dest file/socket variables to
source after the migration is complete, ready to start again. A new
destination is created if the test outputs the migrate line again.
Test cases may now switch to calling migrate() one or more times.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
lib/migrate.c | 8 ++--
lib/migrate.h | 1 +
scripts/arch-run.bash | 93 +++++++++++++++++++++++++++++++++++++------
3 files changed, 85 insertions(+), 17 deletions(-)
diff --git a/lib/migrate.c b/lib/migrate.c
index 527e63ae..b7721659 100644
--- a/lib/migrate.c
+++ b/lib/migrate.c
@@ -8,8 +8,10 @@
#include <libcflat.h>
#include "migrate.h"
-/* static for now since we only support migrating exactly once per test. */
-static void migrate(void)
+/*
+ * Initiate migration and wait for it to complete.
+ */
+void migrate(void)
{
puts("Now migrate the VM, then press a key to continue...\n");
(void)getchar();
@@ -19,8 +21,6 @@ static void migrate(void)
/*
* Initiate migration and wait for it to complete.
* If this function is called more than once, it is a no-op.
- * Since migrate_cmd can only migrate exactly once this function can
- * simplify the control flow, especially when skipping tests.
*/
void migrate_once(void)
{
diff --git a/lib/migrate.h b/lib/migrate.h
index 3c94e6af..2af06a72 100644
--- a/lib/migrate.h
+++ b/lib/migrate.h
@@ -6,4 +6,5 @@
* Author: Nico Boehr <nrb@linux.ibm.com>
*/
+void migrate(void);
void migrate_once(void);
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 8fbfc50c..1ea0f8bc 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -132,29 +132,76 @@ run_migration ()
migsock=$(mktemp -u -t mig-helper-socket.XXXXXXXXXX)
migout1=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX)
migout_fifo1=$(mktemp -u -t mig-helper-fifo-stdout1.XXXXXXXXXX)
+ migout2=$(mktemp -t mig-helper-stdout2.XXXXXXXXXX)
+ migout_fifo2=$(mktemp -u -t mig-helper-fifo-stdout2.XXXXXXXXXX)
qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX)
qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX)
fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX)
# race here between file creation and trap
trap "trap - TERM ; kill 0 ; exit 2" INT TERM
- trap "rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}" RETURN EXIT
+ trap "rm -f ${migout1} ${migout2} ${migout_fifo1} ${migout_fifo2} ${migsock} ${qmp1} ${qmp2} ${fifo}" RETURN EXIT
qmpout1=/dev/null
qmpout2=/dev/null
+ migcmdline=$@
- eval "$@" -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \
+ mkfifo ${migout_fifo1}
+ mkfifo ${migout_fifo2}
+
+ eval "$migcmdline" \
+ -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \
-mon chardev=mon1,mode=control > ${migout_fifo1} &
live_pid=$!
cat ${migout_fifo1} | tee ${migout1} &
- # We have to use cat to open the named FIFO, because named FIFO's, unlike
- # pipes, will block on open() until the other end is also opened, and that
- # totally breaks QEMU...
+ # The test must prompt the user to migrate, so wait for the "migrate"
+ # keyword
+ while ! grep -q -i "Now migrate the VM" < ${migout1} ; do
+ if ! ps -p ${live_pid} > /dev/null ; then
+ echo "ERROR: Test exit before migration point." >&2
+ qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null
+ return 3
+ fi
+ sleep 0.1
+ done
+
+ # This starts the first source QEMU in advance of the test reaching the
+ # migration point, since we expect at least one migration. Subsequent
+ # sources are started as the test hits migrate keywords.
+ do_migration || return $?
+
+ while ps -p ${live_pid} > /dev/null ; do
+ # Wait for EXIT or further migrations
+ if ! grep -q -i "Now migrate the VM" < ${migout1} ; then
+ sleep 0.1
+ else
+ do_migration || return $?
+ fi
+ done
+
+ wait ${live_pid}
+ ret=$?
+
+ while (( $(jobs -r | wc -l) > 0 )); do
+ sleep 0.1
+ done
+
+ return $ret
+}
+
+do_migration ()
+{
+ # We have to use cat to open the named FIFO, because named FIFO's,
+ # unlike pipes, will block on open() until the other end is also
+ # opened, and that totally breaks QEMU...
mkfifo ${fifo}
- eval "$@" -chardev socket,id=mon2,path=${qmp2},server=on,wait=off \
- -mon chardev=mon2,mode=control -incoming unix:${migsock} < <(cat ${fifo}) &
+ eval "$migcmdline" \
+ -chardev socket,id=mon2,path=${qmp2},server=on,wait=off \
+ -mon chardev=mon2,mode=control -incoming unix:${migsock} \
+ < <(cat ${fifo}) > ${migout_fifo2} &
incoming_pid=$!
+ cat ${migout_fifo2} | tee ${migout2} &
# The test must prompt the user to migrate, so wait for the "migrate" keyword
while ! grep -q -i "Now migrate the VM" < ${migout1} ; do
@@ -165,7 +212,7 @@ run_migration ()
qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null
return 3
fi
- sleep 1
+ sleep 0.1
done
# Wait until the destination has created the incoming and qmp sockets
@@ -177,7 +224,7 @@ run_migration ()
# Wait for the migration to complete
migstatus=`qmp ${qmp1} '"query-migrate"' | grep return`
while ! grep -q '"completed"' <<<"$migstatus" ; do
- sleep 1
+ sleep 0.1
if ! migstatus=`qmp ${qmp1} '"query-migrate"'`; then
echo "ERROR: Querying migration state failed." >&2
echo > ${fifo}
@@ -193,14 +240,34 @@ run_migration ()
return 2
fi
done
+
qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null
+
+ # keypress to dst so getchar completes and test continues
echo > ${fifo}
- wait $incoming_pid
+ rm ${fifo}
+
+ # Ensure the incoming socket is removed, ready for next destination
+ if [ -S ${migsock} ] ; then
+ echo "ERROR: Incoming migration socket not removed after migration." >& 2
+ qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null
+ return 2
+ fi
+
+ wait ${live_pid}
ret=$?
- while (( $(jobs -r | wc -l) > 0 )); do
- sleep 0.5
- done
+ # Now flip the variables because dest becomes source
+ live_pid=${incoming_pid}
+ tmp=${migout1}
+ migout1=${migout2}
+ migout2=${tmp}
+ tmp=${migout_fifo1}
+ migout_fifo1=${migout_fifo2}
+ migout_fifo2=${tmp}
+ tmp=${qmp1}
+ qmp1=${qmp2}
+ qmp2=${tmp}
return $ret
}
--
2.42.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [kvm-unit-tests PATCH v2 6/9] arch-run: rename migration variables
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
` (4 preceding siblings ...)
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 5/9] migration: Support multiple migrations Nicholas Piggin
@ 2024-02-02 6:57 ` Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 7/9] migration: Add quiet migration support Nicholas Piggin
` (2 subsequent siblings)
8 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
Using 1 and 2 for source and destination is confusing, particularly
now with multiple migrations that flip between them. Do a rename
pass to tidy things up.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
scripts/arch-run.bash | 112 +++++++++++++++++++++---------------------
1 file changed, 57 insertions(+), 55 deletions(-)
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 1ea0f8bc..0feaa190 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -129,38 +129,39 @@ run_migration ()
return 77
fi
- migsock=$(mktemp -u -t mig-helper-socket.XXXXXXXXXX)
- migout1=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX)
- migout_fifo1=$(mktemp -u -t mig-helper-fifo-stdout1.XXXXXXXXXX)
- migout2=$(mktemp -t mig-helper-stdout2.XXXXXXXXXX)
- migout_fifo2=$(mktemp -u -t mig-helper-fifo-stdout2.XXXXXXXXXX)
- qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX)
- qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX)
- fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX)
+ dst_incoming=$(mktemp -u -t mig-helper-socket-incoming.XXXXXXXXXX)
+ src_out=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX)
+ src_outfifo=$(mktemp -u -t mig-helper-fifo-stdout1.XXXXXXXXXX)
+ dst_out=$(mktemp -t mig-helper-stdout2.XXXXXXXXXX)
+ dst_outfifo=$(mktemp -u -t mig-helper-fifo-stdout2.XXXXXXXXXX)
+ src_qmp=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX)
+ dst_qmp=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX)
+ dst_infifo=$(mktemp -u -t mig-helper-fifo-stdin.XXXXXXXXXX)
# race here between file creation and trap
trap "trap - TERM ; kill 0 ; exit 2" INT TERM
- trap "rm -f ${migout1} ${migout2} ${migout_fifo1} ${migout_fifo2} ${migsock} ${qmp1} ${qmp2} ${fifo}" RETURN EXIT
+ trap "rm -f ${src_out} ${dst_out} ${src_outfifo} ${dst_outfifo} ${dst_incoming} ${src_qmp} ${dst_qmp} ${dst_infifo}" RETURN EXIT
+
+ src_qmpout=/dev/null
+ dst_qmpout=/dev/null
- qmpout1=/dev/null
- qmpout2=/dev/null
migcmdline=$@
- mkfifo ${migout_fifo1}
- mkfifo ${migout_fifo2}
+ mkfifo ${src_outfifo}
+ mkfifo ${dst_outfifo}
eval "$migcmdline" \
- -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \
- -mon chardev=mon1,mode=control > ${migout_fifo1} &
+ -chardev socket,id=mon,path=${src_qmp},server=on,wait=off \
+ -mon chardev=mon,mode=control > ${src_outfifo} &
live_pid=$!
- cat ${migout_fifo1} | tee ${migout1} &
+ cat ${src_outfifo} | tee ${src_out} &
# The test must prompt the user to migrate, so wait for the "migrate"
# keyword
- while ! grep -q -i "Now migrate the VM" < ${migout1} ; do
+ while ! grep -q -i "Now migrate the VM" < ${src_out} ; do
if ! ps -p ${live_pid} > /dev/null ; then
echo "ERROR: Test exit before migration point." >&2
- qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null
+ qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null
return 3
fi
sleep 0.1
@@ -173,7 +174,7 @@ run_migration ()
while ps -p ${live_pid} > /dev/null ; do
# Wait for EXIT or further migrations
- if ! grep -q -i "Now migrate the VM" < ${migout1} ; then
+ if ! grep -q -i "Now migrate the VM" < ${src_out} ; then
sleep 0.1
else
do_migration || return $?
@@ -195,79 +196,80 @@ do_migration ()
# We have to use cat to open the named FIFO, because named FIFO's,
# unlike pipes, will block on open() until the other end is also
# opened, and that totally breaks QEMU...
- mkfifo ${fifo}
+ mkfifo ${dst_infifo}
eval "$migcmdline" \
- -chardev socket,id=mon2,path=${qmp2},server=on,wait=off \
- -mon chardev=mon2,mode=control -incoming unix:${migsock} \
- < <(cat ${fifo}) > ${migout_fifo2} &
+ -chardev socket,id=mon,path=${dst_qmp},server=on,wait=off \
+ -mon chardev=mon,mode=control -incoming unix:${dst_incoming} \
+ < <(cat ${dst_infifo}) > ${dst_outfifo} &
incoming_pid=$!
- cat ${migout_fifo2} | tee ${migout2} &
+ cat ${dst_outfifo} | tee ${dst_out} &
# The test must prompt the user to migrate, so wait for the "migrate" keyword
- while ! grep -q -i "Now migrate the VM" < ${migout1} ; do
+ while ! grep -q -i "Now migrate the VM" < ${src_out} ; do
if ! ps -p ${live_pid} > /dev/null ; then
echo "ERROR: Test exit before migration point." >&2
- echo > ${fifo}
- qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null
- qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null
+ echo > ${dst_infifo}
+ qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null
+ qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null
return 3
fi
sleep 0.1
done
# Wait until the destination has created the incoming and qmp sockets
- while ! [ -S ${migsock} ] ; do sleep 0.1 ; done
- while ! [ -S ${qmp2} ] ; do sleep 0.1 ; done
+ while ! [ -S ${dst_incoming} ] ; do sleep 0.1 ; done
+ while ! [ -S ${dst_qmp} ] ; do sleep 0.1 ; done
- qmp ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1}
+ qmp ${src_qmp} '"migrate", "arguments": { "uri": "unix:'${dst_incoming}'" }' > ${src_qmpout}
# Wait for the migration to complete
- migstatus=`qmp ${qmp1} '"query-migrate"' | grep return`
+ migstatus=`qmp ${src_qmp} '"query-migrate"' | grep return`
while ! grep -q '"completed"' <<<"$migstatus" ; do
sleep 0.1
- if ! migstatus=`qmp ${qmp1} '"query-migrate"'`; then
+ if ! migstatus=`qmp ${src_qmp} '"query-migrate"'`; then
echo "ERROR: Querying migration state failed." >&2
- echo > ${fifo}
- qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null
+ echo > ${dst_infifo}
+ qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null
return 2
fi
migstatus=`grep return <<<"$migstatus"`
if grep -q '"failed"' <<<"$migstatus"; then
echo "ERROR: Migration failed." >&2
- echo > ${fifo}
- qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null
- qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null
+ echo > ${dst_infifo}
+ qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null
+ qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null
return 2
fi
done
- qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null
+ qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null
# keypress to dst so getchar completes and test continues
- echo > ${fifo}
- rm ${fifo}
+ echo > ${dst_infifo}
+ rm ${dst_infifo}
# Ensure the incoming socket is removed, ready for next destination
- if [ -S ${migsock} ] ; then
+ if [ -S ${dst_incoming} ] ; then
echo "ERROR: Incoming migration socket not removed after migration." >& 2
- qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null
+ qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null
return 2
fi
wait ${live_pid}
ret=$?
- # Now flip the variables because dest becomes source
+ # Now flip the variables because destination machine becomes source
+ # for the next migration.
live_pid=${incoming_pid}
- tmp=${migout1}
- migout1=${migout2}
- migout2=${tmp}
- tmp=${migout_fifo1}
- migout_fifo1=${migout_fifo2}
- migout_fifo2=${tmp}
- tmp=${qmp1}
- qmp1=${qmp2}
- qmp2=${tmp}
+ tmp=${src_out}
+ src_out=${dst_out}
+ dst_out=${tmp}
+ tmp=${src_outfifo}
+ src_outfifo=${dst_outfifo}
+ dst_outfifo=${tmp}
+ tmp=${src_qmp}
+ src_qmp=${dst_qmp}
+ dst_qmp=${tmp}
return $ret
}
@@ -290,8 +292,8 @@ run_panic ()
trap "rm -f ${qmp}" RETURN EXIT
# start VM stopped so we don't miss any events
- eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \
- -mon chardev=mon1,mode=control -S &
+ eval "$@" -chardev socket,id=mon,path=${qmp},server=on,wait=off \
+ -mon chardev=mon,mode=control -S &
panic_event_count=$(qmp_events ${qmp} | jq -c 'select(.event == "GUEST_PANICKED")' | wc -l)
if [ "$panic_event_count" -lt 1 ]; then
--
2.42.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [kvm-unit-tests PATCH v2 7/9] migration: Add quiet migration support
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
` (5 preceding siblings ...)
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 6/9] arch-run: rename migration variables Nicholas Piggin
@ 2024-02-02 6:57 ` Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 8/9] Add common/ directory for architecture-independent tests Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 9/9] migration: add a migration selftest Nicholas Piggin
8 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
Console output required to support migration becomes quite noisy
when doing lots of migrations. Provide a migrate_quiet() call that
suppresses console output and doesn't log a message.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
lib/migrate.c | 12 ++++++++++++
lib/migrate.h | 1 +
scripts/arch-run.bash | 4 ++--
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/lib/migrate.c b/lib/migrate.c
index b7721659..4e0ab516 100644
--- a/lib/migrate.c
+++ b/lib/migrate.c
@@ -18,6 +18,18 @@ void migrate(void)
report_info("Migration complete");
}
+/*
+ * Like migrate() but supporess output and logs, useful for intensive
+ * migration stress testing without polluting logs. Test cases should
+ * provide relevant information about migration in failure reports.
+ */
+void migrate_quiet(void)
+{
+ puts("Now migrate the VM (quiet)\n");
+ (void)getchar();
+}
+
+
/*
* Initiate migration and wait for it to complete.
* If this function is called more than once, it is a no-op.
diff --git a/lib/migrate.h b/lib/migrate.h
index 2af06a72..95b9102b 100644
--- a/lib/migrate.h
+++ b/lib/migrate.h
@@ -7,4 +7,5 @@
*/
void migrate(void);
+void migrate_quiet(void);
void migrate_once(void);
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 0feaa190..5810f9a1 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -154,7 +154,7 @@ run_migration ()
-chardev socket,id=mon,path=${src_qmp},server=on,wait=off \
-mon chardev=mon,mode=control > ${src_outfifo} &
live_pid=$!
- cat ${src_outfifo} | tee ${src_out} &
+ cat ${src_outfifo} | tee ${src_out} | grep -v "Now migrate the VM (quiet)" &
# The test must prompt the user to migrate, so wait for the "migrate"
# keyword
@@ -202,7 +202,7 @@ do_migration ()
-mon chardev=mon,mode=control -incoming unix:${dst_incoming} \
< <(cat ${dst_infifo}) > ${dst_outfifo} &
incoming_pid=$!
- cat ${dst_outfifo} | tee ${dst_out} &
+ cat ${dst_outfifo} | tee ${dst_out} | grep -v "Now migrate the VM (quiet)" &
# The test must prompt the user to migrate, so wait for the "migrate" keyword
while ! grep -q -i "Now migrate the VM" < ${src_out} ; do
--
2.42.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [kvm-unit-tests PATCH v2 8/9] Add common/ directory for architecture-independent tests
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
` (6 preceding siblings ...)
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 7/9] migration: Add quiet migration support Nicholas Piggin
@ 2024-02-02 6:57 ` Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 9/9] migration: add a migration selftest Nicholas Piggin
8 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
x86/sieve.c is used by s390x and arm via symbolic link. Make a new
directory common/ for architecture-independent tests and move
sieve.c here.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arm/sieve.c | 2 +-
common/sieve.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
s390x/sieve.c | 2 +-
x86/sieve.c | 52 +-------------------------------------------------
4 files changed, 54 insertions(+), 53 deletions(-)
create mode 100644 common/sieve.c
mode change 100644 => 120000 x86/sieve.c
diff --git a/arm/sieve.c b/arm/sieve.c
index 8f14a5c3..fe299f30 120000
--- a/arm/sieve.c
+++ b/arm/sieve.c
@@ -1 +1 @@
-../x86/sieve.c
\ No newline at end of file
+../common/sieve.c
\ No newline at end of file
diff --git a/common/sieve.c b/common/sieve.c
new file mode 100644
index 00000000..8150f2d9
--- /dev/null
+++ b/common/sieve.c
@@ -0,0 +1,51 @@
+#include "alloc.h"
+#include "libcflat.h"
+
+static int sieve(char* data, int size)
+{
+ int i, j, r = 0;
+
+ for (i = 0; i < size; ++i)
+ data[i] = 1;
+
+ data[0] = data[1] = 0;
+
+ for (i = 2; i < size; ++i)
+ if (data[i]) {
+ ++r;
+ for (j = i*2; j < size; j += i)
+ data[j] = 0;
+ }
+ return r;
+}
+
+static void test_sieve(const char *msg, char *data, int size)
+{
+ int r;
+
+ printf("%s:", msg);
+ r = sieve(data, size);
+ printf("%d out of %d\n", r, size);
+}
+
+#define STATIC_SIZE 1000000
+#define VSIZE 100000000
+char static_data[STATIC_SIZE];
+
+int main(void)
+{
+ void *v;
+ int i;
+
+ printf("starting sieve\n");
+ test_sieve("static", static_data, STATIC_SIZE);
+ setup_vm();
+ test_sieve("mapped", static_data, STATIC_SIZE);
+ for (i = 0; i < 3; ++i) {
+ v = malloc(VSIZE);
+ test_sieve("virtual", v, VSIZE);
+ free(v);
+ }
+
+ return 0;
+}
diff --git a/s390x/sieve.c b/s390x/sieve.c
index 8f14a5c3..fe299f30 120000
--- a/s390x/sieve.c
+++ b/s390x/sieve.c
@@ -1 +1 @@
-../x86/sieve.c
\ No newline at end of file
+../common/sieve.c
\ No newline at end of file
diff --git a/x86/sieve.c b/x86/sieve.c
deleted file mode 100644
index 8150f2d9..00000000
--- a/x86/sieve.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "alloc.h"
-#include "libcflat.h"
-
-static int sieve(char* data, int size)
-{
- int i, j, r = 0;
-
- for (i = 0; i < size; ++i)
- data[i] = 1;
-
- data[0] = data[1] = 0;
-
- for (i = 2; i < size; ++i)
- if (data[i]) {
- ++r;
- for (j = i*2; j < size; j += i)
- data[j] = 0;
- }
- return r;
-}
-
-static void test_sieve(const char *msg, char *data, int size)
-{
- int r;
-
- printf("%s:", msg);
- r = sieve(data, size);
- printf("%d out of %d\n", r, size);
-}
-
-#define STATIC_SIZE 1000000
-#define VSIZE 100000000
-char static_data[STATIC_SIZE];
-
-int main(void)
-{
- void *v;
- int i;
-
- printf("starting sieve\n");
- test_sieve("static", static_data, STATIC_SIZE);
- setup_vm();
- test_sieve("mapped", static_data, STATIC_SIZE);
- for (i = 0; i < 3; ++i) {
- v = malloc(VSIZE);
- test_sieve("virtual", v, VSIZE);
- free(v);
- }
-
- return 0;
-}
diff --git a/x86/sieve.c b/x86/sieve.c
new file mode 120000
index 00000000..fe299f30
--- /dev/null
+++ b/x86/sieve.c
@@ -0,0 +1 @@
+../common/sieve.c
\ No newline at end of file
--
2.42.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [kvm-unit-tests PATCH v2 9/9] migration: add a migration selftest
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
` (7 preceding siblings ...)
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 8/9] Add common/ directory for architecture-independent tests Nicholas Piggin
@ 2024-02-02 6:57 ` Nicholas Piggin
8 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-02 6:57 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
Add a selftest for migration support in guest library and test harness
code. It performs migrations a tight loop to irritate races and bugs in
the test harness code.
Acked-by: Claudio Imbrenda <imbrenda@linux.ibm.com> (s390x)
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
This has flushed out several bugs in developing the multi migration test
harness code already.
---
arm/Makefile.common | 1 +
arm/unittests.cfg | 6 ++++++
common/selftest-migration.c | 34 ++++++++++++++++++++++++++++++++++
powerpc/Makefile.common | 1 +
powerpc/unittests.cfg | 4 ++++
s390x/Makefile | 1 +
s390x/unittests.cfg | 4 ++++
7 files changed, 51 insertions(+)
create mode 100644 common/selftest-migration.c
diff --git a/arm/Makefile.common b/arm/Makefile.common
index c2ee568c..371a2c6a 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -5,6 +5,7 @@
#
tests-common = $(TEST_DIR)/selftest.$(exe)
+tests-common += $(TEST_DIR)/selftest-migration.$(exe)
tests-common += $(TEST_DIR)/spinlock-test.$(exe)
tests-common += $(TEST_DIR)/pci-test.$(exe)
tests-common += $(TEST_DIR)/pmu.$(exe)
diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index fe601cbb..1ffd9a82 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -55,6 +55,12 @@ smp = $MAX_SMP
extra_params = -append 'smp'
groups = selftest
+# Test migration
+[selftest-migration]
+file = selftest-migration.flat
+groups = selftest migration
+
+arch = arm64
# Test PCI emulation
[pci-test]
file = pci-test.flat
diff --git a/common/selftest-migration.c b/common/selftest-migration.c
new file mode 100644
index 00000000..f70c505f
--- /dev/null
+++ b/common/selftest-migration.c
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Machine independent migration tests
+ *
+ * This is just a very simple test that is intended to stress the migration
+ * support in the test harness. This could be expanded to test more guest
+ * library code, but architecture-specific tests should be used to test
+ * migration of tricky machine state.
+ */
+#include <libcflat.h>
+#include <migrate.h>
+
+#if defined(__arm__) || defined(__aarch64__)
+/* arm can only call getchar 15 times */
+#define NR_MIGRATIONS 15
+#else
+#define NR_MIGRATIONS 100
+#endif
+
+int main(int argc, char **argv)
+{
+ int i = 0;
+
+ report_prefix_push("migration");
+
+ for (i = 0; i < NR_MIGRATIONS; i++)
+ migrate_quiet();
+
+ report(true, "simple harness stress test");
+
+ report_prefix_pop();
+
+ return report_summary();
+}
diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
index eb88398d..da4a7bbb 100644
--- a/powerpc/Makefile.common
+++ b/powerpc/Makefile.common
@@ -6,6 +6,7 @@
tests-common = \
$(TEST_DIR)/selftest.elf \
+ $(TEST_DIR)/selftest-migration.elf \
$(TEST_DIR)/spapr_hcall.elf \
$(TEST_DIR)/rtas.elf \
$(TEST_DIR)/emulator.elf \
diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg
index e71140aa..7ce57de0 100644
--- a/powerpc/unittests.cfg
+++ b/powerpc/unittests.cfg
@@ -36,6 +36,10 @@ smp = 2
extra_params = -m 256 -append 'setup smp=2 mem=256'
groups = selftest
+[selftest-migration]
+file = selftest-migration.elf
+groups = selftest migration
+
[spapr_hcall]
file = spapr_hcall.elf
diff --git a/s390x/Makefile b/s390x/Makefile
index b72f7578..344d46d6 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -1,4 +1,5 @@
tests = $(TEST_DIR)/selftest.elf
+tests += $(TEST_DIR)/selftest-migration.elf
tests += $(TEST_DIR)/intercept.elf
tests += $(TEST_DIR)/emulator.elf
tests += $(TEST_DIR)/sieve.elf
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index f5024b6e..a7ad522c 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -24,6 +24,10 @@ groups = selftest
# please keep the kernel cmdline in sync with $(TEST_DIR)/selftest.parmfile
extra_params = -append 'test 123'
+[selftest-migration]
+file = selftest-migration.elf
+groups = selftest migration
+
[intercept]
file = intercept.elf
--
2.42.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation Nicholas Piggin
@ 2024-02-02 9:30 ` Andrew Jones
2024-02-05 11:28 ` Thomas Huth
2024-02-05 14:20 ` Marc Hartmayer
1 sibling, 1 reply; 19+ messages in thread
From: Andrew Jones @ 2024-02-02 9:30 UTC (permalink / raw)
To: Nicholas Piggin
Cc: Laurent Vivier, linux-s390, Thomas Huth, Nico Boehr,
Janosch Frank, kvm, David Hildenbrand, linuxppc-dev,
Shaoqin Huang, Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
On Fri, Feb 02, 2024 at 04:57:32PM +1000, Nicholas Piggin wrote:
> Using all prerequisites for the source file results in the build
> dying on the second time around with:
>
> gcc: fatal error: cannot specify ‘-o’ with ‘-c’, ‘-S’ or ‘-E’ with multiple files
>
> This is due to auxinfo.h becoming a prerequisite after the first
> build recorded the dependency.
>
> Use the first prerequisite for this recipe.
>
> Fixes: f2372f2d49135 ("(arm|powerpc|s390x): Makefile: add `%.aux.o` target")
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> arm/Makefile.common | 2 +-
> powerpc/Makefile.common | 2 +-
> s390x/Makefile | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arm/Makefile.common b/arm/Makefile.common
> index 54cb4a63..c2ee568c 100644
> --- a/arm/Makefile.common
> +++ b/arm/Makefile.common
> @@ -71,7 +71,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libeabi)
>
> ifeq ($(CONFIG_EFI),y)
> %.aux.o: $(SRCDIR)/lib/auxinfo.c
> - $(CC) $(CFLAGS) -c -o $@ $^ \
> + $(CC) $(CFLAGS) -c -o $@ $< \
> -DPROGNAME=\"$(@:.aux.o=.efi)\" -DAUXFLAGS=$(AUXFLAGS)
There are two instances of the %.aux.o target in arm/Makefile.common. We
need to fix both. We can actually pull the target out of the two arms of
the CONFIG_EFI if-else, though, by changing the .efi/.flat to .$(exe).
Thanks,
drew
>
> %.so: EFI_LDFLAGS += -defsym=EFI_SUBSYSTEM=0xa --no-undefined
> diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
> index 483ff648..eb88398d 100644
> --- a/powerpc/Makefile.common
> +++ b/powerpc/Makefile.common
> @@ -48,7 +48,7 @@ cflatobjs += lib/powerpc/smp.o
> OBJDIRS += lib/powerpc
>
> %.aux.o: $(SRCDIR)/lib/auxinfo.c
> - $(CC) $(CFLAGS) -c -o $@ $^ -DPROGNAME=\"$(@:.aux.o=.elf)\"
> + $(CC) $(CFLAGS) -c -o $@ $< -DPROGNAME=\"$(@:.aux.o=.elf)\"
>
> FLATLIBS = $(libcflat) $(LIBFDT_archive)
> %.elf: CFLAGS += $(arch_CFLAGS)
> diff --git a/s390x/Makefile b/s390x/Makefile
> index e64521e0..b72f7578 100644
> --- a/s390x/Makefile
> +++ b/s390x/Makefile
> @@ -177,7 +177,7 @@ lds-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@
> $(CPP) $(lds-autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
>
> %.aux.o: $(SRCDIR)/lib/auxinfo.c
> - $(CC) $(CFLAGS) -c -o $@ $^ -DPROGNAME=\"$(@:.aux.o=.elf)\"
> + $(CC) $(CFLAGS) -c -o $@ $< -DPROGNAME=\"$(@:.aux.o=.elf)\"
>
> .SECONDEXPANSION:
> %.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o %.aux.o
> --
> 2.42.0
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation
2024-02-02 9:30 ` Andrew Jones
@ 2024-02-05 11:28 ` Thomas Huth
0 siblings, 0 replies; 19+ messages in thread
From: Thomas Huth @ 2024-02-05 11:28 UTC (permalink / raw)
To: Andrew Jones, Nicholas Piggin
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Eric Auger,
Marc Hartmayer, kvmarm, Paolo Bonzini, Claudio Imbrenda,
Alexandru Elisei
On 02/02/2024 10.30, Andrew Jones wrote:
> On Fri, Feb 02, 2024 at 04:57:32PM +1000, Nicholas Piggin wrote:
>> Using all prerequisites for the source file results in the build
>> dying on the second time around with:
>>
>> gcc: fatal error: cannot specify ‘-o’ with ‘-c’, ‘-S’ or ‘-E’ with multiple files
>>
>> This is due to auxinfo.h becoming a prerequisite after the first
>> build recorded the dependency.
D'oh, of course I only tried to run "make" once when testing that patch :-/
>> diff --git a/arm/Makefile.common b/arm/Makefile.common
>> index 54cb4a63..c2ee568c 100644
>> --- a/arm/Makefile.common
>> +++ b/arm/Makefile.common
>> @@ -71,7 +71,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libeabi)
>>
>> ifeq ($(CONFIG_EFI),y)
>> %.aux.o: $(SRCDIR)/lib/auxinfo.c
>> - $(CC) $(CFLAGS) -c -o $@ $^ \
>> + $(CC) $(CFLAGS) -c -o $@ $< \
>> -DPROGNAME=\"$(@:.aux.o=.efi)\" -DAUXFLAGS=$(AUXFLAGS)
>
> There are two instances of the %.aux.o target in arm/Makefile.common. We
> need to fix both. We can actually pull the target out of the two arms of
> the CONFIG_EFI if-else, though, by changing the .efi/.flat to .$(exe).
I went ahead and pushed this patch with the trivial fix for the else-branch
to the repo to unbreak the build. If you think it's worthwhile to unify the
target, please provide a patch to do so, thanks!
Thomas
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [kvm-unit-tests PATCH v2 3/9] arch-run: Clean up initrd cleanup
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 3/9] arch-run: Clean up initrd cleanup Nicholas Piggin
@ 2024-02-05 12:04 ` Thomas Huth
2024-02-06 5:20 ` Nicholas Piggin
0 siblings, 1 reply; 19+ messages in thread
From: Thomas Huth @ 2024-02-05 12:04 UTC (permalink / raw)
To: Nicholas Piggin
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Andrew Jones,
Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
On 02/02/2024 07.57, Nicholas Piggin wrote:
> Rather than put a big script into the trap handler, have it call
> a function.
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> scripts/arch-run.bash | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> index f22ead6f..cc7da7c5 100644
> --- a/scripts/arch-run.bash
> +++ b/scripts/arch-run.bash
> @@ -271,10 +271,20 @@ search_qemu_binary ()
> export PATH=$save_path
> }
>
> +initrd_cleanup ()
> +{
> + if [ "$KVM_UNIT_TESTS_ENV_OLD" ]; then
> + export KVM_UNIT_TESTS_ENV="$KVM_UNIT_TESTS_ENV_OLD"
> + else
> + unset KVM_UNIT_TESTS_ENV
> + unset KVM_UNIT_TESTS_ENV_OLD
> + fi
> +}
> +
> initrd_create ()
> {
> if [ "$ENVIRON_DEFAULT" = "yes" ]; then
> - trap_exit_push 'rm -f $KVM_UNIT_TESTS_ENV; [ "$KVM_UNIT_TESTS_ENV_OLD" ] && export KVM_UNIT_TESTS_ENV="$KVM_UNIT_TESTS_ENV_OLD" || unset KVM_UNIT_TESTS_ENV; unset KVM_UNIT_TESTS_ENV_OLD'
> + trap_exit_push 'rm -f $KVM_UNIT_TESTS_ENV; initrd_cleanup'
>
Why don't you move the 'rm -f $KVM_UNIT_TESTS_ENV' into the initrd_cleanup()
function, too? ... that would IMHO make more sense for a function that is
called *_cleanup() ?
Thomas
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation Nicholas Piggin
2024-02-02 9:30 ` Andrew Jones
@ 2024-02-05 14:20 ` Marc Hartmayer
1 sibling, 0 replies; 19+ messages in thread
From: Marc Hartmayer @ 2024-02-05 14:20 UTC (permalink / raw)
To: Nicholas Piggin, Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, kvmarm, Paolo Bonzini, Claudio Imbrenda,
Alexandru Elisei
On Fri, Feb 02, 2024 at 04:57 PM +1000, Nicholas Piggin <npiggin@gmail.com> wrote:
> Using all prerequisites for the source file results in the build
> dying on the second time around with:
>
> gcc: fatal error: cannot specify ‘-o’ with ‘-c’, ‘-S’ or ‘-E’ with multiple files
>
> This is due to auxinfo.h becoming a prerequisite after the first
> build recorded the dependency.
>
> Use the first prerequisite for this recipe.
>
> Fixes: f2372f2d49135 ("(arm|powerpc|s390x): Makefile: add `%.aux.o` target")
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> arm/Makefile.common | 2 +-
[…snip]
Thanks a ton for fixing this!
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
--
Kind regards / Beste Grüße
Marc Hartmayer
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [kvm-unit-tests PATCH v2 4/9] migration: use a more robust way to wait for background job
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 4/9] migration: use a more robust way to wait for background job Nicholas Piggin
@ 2024-02-05 14:58 ` Marc Hartmayer
2024-02-06 6:50 ` Nicholas Piggin
0 siblings, 1 reply; 19+ messages in thread
From: Marc Hartmayer @ 2024-02-05 14:58 UTC (permalink / raw)
To: Nicholas Piggin, Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Nicholas Piggin,
Andrew Jones, Eric Auger, kvmarm, Paolo Bonzini, Claudio Imbrenda,
Alexandru Elisei
On Fri, Feb 02, 2024 at 04:57 PM +1000, Nicholas Piggin <npiggin@gmail.com> wrote:
> Starting a pipeline of jobs in the background does not seem to have
> a simple way to reliably find the pid of a particular process in the
> pipeline (because not all processes are started when the shell
> continues to execute).
>
> The way PID of QEMU is derived can result in a failure waiting on a
> PID that is not running. This is easier to hit with subsequent
> multiple-migration support. Changing this to use $! by swapping the
> pipeline for a fifo is more robust.
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
[…snip…]
>
> + # Wait until the destination has created the incoming and qmp sockets
> + while ! [ -S ${migsock} ] ; do sleep 0.1 ; done
> + while ! [ -S ${qmp2} ] ; do sleep 0.1 ; done
There should be timeout implemented, otherwise we might end in an
endless loop in case of a bug. Or is the global timeout good enough to
handle this situation?
> +
> qmp ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1}
>
> # Wait for the migration to complete
> --
> 2.42.0
>
>
--
Kind regards / Beste Grüße
Marc Hartmayer
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [kvm-unit-tests PATCH v2 3/9] arch-run: Clean up initrd cleanup
2024-02-05 12:04 ` Thomas Huth
@ 2024-02-06 5:20 ` Nicholas Piggin
0 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-06 5:20 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Andrew Jones,
Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
On Mon Feb 5, 2024 at 10:04 PM AEST, Thomas Huth wrote:
> On 02/02/2024 07.57, Nicholas Piggin wrote:
> > Rather than put a big script into the trap handler, have it call
> > a function.
> >
> > Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> > ---
> > scripts/arch-run.bash | 12 +++++++++++-
> > 1 file changed, 11 insertions(+), 1 deletion(-)
> >
> > diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> > index f22ead6f..cc7da7c5 100644
> > --- a/scripts/arch-run.bash
> > +++ b/scripts/arch-run.bash
> > @@ -271,10 +271,20 @@ search_qemu_binary ()
> > export PATH=$save_path
> > }
> >
> > +initrd_cleanup ()
> > +{
> > + if [ "$KVM_UNIT_TESTS_ENV_OLD" ]; then
> > + export KVM_UNIT_TESTS_ENV="$KVM_UNIT_TESTS_ENV_OLD"
> > + else
> > + unset KVM_UNIT_TESTS_ENV
> > + unset KVM_UNIT_TESTS_ENV_OLD
> > + fi
> > +}
> > +
> > initrd_create ()
> > {
> > if [ "$ENVIRON_DEFAULT" = "yes" ]; then
> > - trap_exit_push 'rm -f $KVM_UNIT_TESTS_ENV; [ "$KVM_UNIT_TESTS_ENV_OLD" ] && export KVM_UNIT_TESTS_ENV="$KVM_UNIT_TESTS_ENV_OLD" || unset KVM_UNIT_TESTS_ENV; unset KVM_UNIT_TESTS_ENV_OLD'
> > + trap_exit_push 'rm -f $KVM_UNIT_TESTS_ENV; initrd_cleanup'
> >
>
> Why don't you move the 'rm -f $KVM_UNIT_TESTS_ENV' into the initrd_cleanup()
> function, too? ... that would IMHO make more sense for a function that is
> called *_cleanup() ?
Yeah good point, will respin.
Thanks,
Nick
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [kvm-unit-tests PATCH v2 4/9] migration: use a more robust way to wait for background job
2024-02-05 14:58 ` Marc Hartmayer
@ 2024-02-06 6:50 ` Nicholas Piggin
0 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-06 6:50 UTC (permalink / raw)
To: Marc Hartmayer, Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Andrew Jones,
Eric Auger, kvmarm, Paolo Bonzini, Claudio Imbrenda,
Alexandru Elisei
On Tue Feb 6, 2024 at 12:58 AM AEST, Marc Hartmayer wrote:
> On Fri, Feb 02, 2024 at 04:57 PM +1000, Nicholas Piggin <npiggin@gmail.com> wrote:
> > Starting a pipeline of jobs in the background does not seem to have
> > a simple way to reliably find the pid of a particular process in the
> > pipeline (because not all processes are started when the shell
> > continues to execute).
> >
> > The way PID of QEMU is derived can result in a failure waiting on a
> > PID that is not running. This is easier to hit with subsequent
> > multiple-migration support. Changing this to use $! by swapping the
> > pipeline for a fifo is more robust.
> >
> > Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> > ---
>
> […snip…]
>
> >
> > + # Wait until the destination has created the incoming and qmp sockets
> > + while ! [ -S ${migsock} ] ; do sleep 0.1 ; done
> > + while ! [ -S ${qmp2} ] ; do sleep 0.1 ; done
>
> There should be timeout implemented, otherwise we might end in an
> endless loop in case of a bug. Or is the global timeout good enough to
> handle this situation?
I was going to say it's not worthwhile since we can't recover, but
actually printing where the timeout happens if nothing else would
be pretty helpful to gather and diagnose problems especially ones
we can't reproduce locally. So, yeah good idea.
We have a bunch of potential hangs where we don't do anything already
though. Sadly it doesn't look like $BASH_LINENO can give anything
useful of the interrupted context from a SIGHUP trap. We might be able
to do something like -
timeout_handler() {
echo "Timeout $timeout_msg"
exit
}
trap timeout_handler HUP
timeout_msg="waiting for destination migration socket to be created"
while ! [ -S ${migsock} ] ; do sleep 0.1 ; done
timeout_msg="waiting for destination QMP socket to be created"
while ! [ -S ${qmp2} ] ; do sleep 0.1 ; done
timeout_msg=
Unless you have any better ideas. Not sure if there's some useful
bash debugging options that can be used. Other option is adding timeout
checks in loops and blocking commands... not sure if that's simpler and
less error prone though.
Anyway we have a bunch of potential hangs and timeouts that aren't
handled already though, so I might leave this out for a later pass at
it unless we come up with a really nice easy way to go.
Thanks,
Nick
>
> > +
> > qmp ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1}
> >
> > # Wait for the migration to complete
> > --
> > 2.42.0
> >
> >
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [kvm-unit-tests PATCH v2 2/9] arch-run: Clean up temporary files properly
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 2/9] arch-run: Clean up temporary files properly Nicholas Piggin
@ 2024-02-07 7:58 ` Thomas Huth
2024-02-09 5:01 ` Nicholas Piggin
0 siblings, 1 reply; 19+ messages in thread
From: Thomas Huth @ 2024-02-07 7:58 UTC (permalink / raw)
To: Nicholas Piggin
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Andrew Jones,
Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
On 02/02/2024 07.57, Nicholas Piggin wrote:
> Migration files weren't being removed when tests were interrupted.
> This improves the situation.
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> scripts/arch-run.bash | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> index d0864360..f22ead6f 100644
> --- a/scripts/arch-run.bash
> +++ b/scripts/arch-run.bash
> @@ -134,12 +134,14 @@ run_migration ()
> qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX)
> qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX)
> fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX)
> +
> + # race here between file creation and trap
> + trap "trap - TERM ; kill 0 ; exit 2" INT TERM
> + trap "rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}" RETURN EXIT
> +
> qmpout1=/dev/null
> qmpout2=/dev/null
>
> - trap 'kill 0; exit 2' INT TERM
> - trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT
> -
> eval "$@" -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \
> -mon chardev=mon1,mode=control | tee ${migout1} &
> live_pid=`jobs -l %+ | grep "eval" | awk '{print$2}'`
> @@ -211,8 +213,8 @@ run_panic ()
>
> qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX)
>
> - trap 'kill 0; exit 2' INT TERM
> - trap 'rm -f ${qmp}' RETURN EXIT
> + trap "trap - TERM ; kill 0 ; exit 2" INT TERM
> + trap "rm -f ${qmp}" RETURN EXIT
>
> # start VM stopped so we don't miss any events
> eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \
So the point is that the "EXIT" trap wasn't executed without the "trap -
TERM" in the other trap? ... ok, then your patch certainly makes sense.
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [kvm-unit-tests PATCH v2 2/9] arch-run: Clean up temporary files properly
2024-02-07 7:58 ` Thomas Huth
@ 2024-02-09 5:01 ` Nicholas Piggin
0 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2024-02-09 5:01 UTC (permalink / raw)
To: Thomas Huth
Cc: Laurent Vivier, linux-s390, Nico Boehr, Janosch Frank, kvm,
David Hildenbrand, linuxppc-dev, Shaoqin Huang, Andrew Jones,
Eric Auger, Marc Hartmayer, kvmarm, Paolo Bonzini,
Claudio Imbrenda, Alexandru Elisei
On Wed Feb 7, 2024 at 5:58 PM AEST, Thomas Huth wrote:
> On 02/02/2024 07.57, Nicholas Piggin wrote:
> > Migration files weren't being removed when tests were interrupted.
> > This improves the situation.
> >
> > Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> > ---
> > scripts/arch-run.bash | 12 +++++++-----
> > 1 file changed, 7 insertions(+), 5 deletions(-)
> >
> > diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> > index d0864360..f22ead6f 100644
> > --- a/scripts/arch-run.bash
> > +++ b/scripts/arch-run.bash
> > @@ -134,12 +134,14 @@ run_migration ()
> > qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX)
> > qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX)
> > fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX)
> > +
> > + # race here between file creation and trap
> > + trap "trap - TERM ; kill 0 ; exit 2" INT TERM
> > + trap "rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}" RETURN EXIT
> > +
> > qmpout1=/dev/null
> > qmpout2=/dev/null
> >
> > - trap 'kill 0; exit 2' INT TERM
> > - trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT
> > -
> > eval "$@" -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \
> > -mon chardev=mon1,mode=control | tee ${migout1} &
> > live_pid=`jobs -l %+ | grep "eval" | awk '{print$2}'`
> > @@ -211,8 +213,8 @@ run_panic ()
> >
> > qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX)
> >
> > - trap 'kill 0; exit 2' INT TERM
> > - trap 'rm -f ${qmp}' RETURN EXIT
> > + trap "trap - TERM ; kill 0 ; exit 2" INT TERM
> > + trap "rm -f ${qmp}" RETURN EXIT
> >
> > # start VM stopped so we don't miss any events
> > eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \
>
> So the point is that the "EXIT" trap wasn't executed without the "trap -
> TERM" in the other trap? ... ok, then your patch certainly makes sense.
Iff you don't remove the TERM handler then the kill will recursively
invoke it until some crash. This did solve some cases of dangling temp
files for me, although now I test with a simple script:
#!/bin/bash
trap 'echo "INT" ; kill 0 ; exit 2' INT
trap 'trap - TERM ; echo "TERM" ; kill 0 ; exit 2' TERM
trap 'echo "RETURN"' RETURN
trap 'echo "EXIT"' EXIT
sleep 10
echo "done"
If you ^C it then it still doesn't get to the EXIT or RETURN handlers.
It looks like 'kill -INT $$' might be the way to do it instad of kill 0.
Not sure if that means my observation was incorrect, or if the real
script is behaving differently. In any case, I will dig into it and
try to explain more precisely in the changelog what it is fixing. And
possibly do another patch for the 'kill -INT $$' if that is needed.
Thanks,
Nick
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2024-02-09 5:02 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-02 6:57 [kvm-unit-tests PATCH v2 0/9] Multi-migration support Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 1/9] (arm|powerpc|s390x): Makefile: Fix .aux.o generation Nicholas Piggin
2024-02-02 9:30 ` Andrew Jones
2024-02-05 11:28 ` Thomas Huth
2024-02-05 14:20 ` Marc Hartmayer
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 2/9] arch-run: Clean up temporary files properly Nicholas Piggin
2024-02-07 7:58 ` Thomas Huth
2024-02-09 5:01 ` Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 3/9] arch-run: Clean up initrd cleanup Nicholas Piggin
2024-02-05 12:04 ` Thomas Huth
2024-02-06 5:20 ` Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 4/9] migration: use a more robust way to wait for background job Nicholas Piggin
2024-02-05 14:58 ` Marc Hartmayer
2024-02-06 6:50 ` Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 5/9] migration: Support multiple migrations Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 6/9] arch-run: rename migration variables Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 7/9] migration: Add quiet migration support Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 8/9] Add common/ directory for architecture-independent tests Nicholas Piggin
2024-02-02 6:57 ` [kvm-unit-tests PATCH v2 9/9] migration: add a migration selftest Nicholas Piggin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).