[PATCH] kvm tools: Wait for all VCPU threads to exit while rebooting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch changes kvm_cpu__reboot() behaviour to block until all VCPU
threads have ended, this allows us to assume that the guest is stopped
when the function has returned.

This fixes errors on close caused by releasing KVM_RUN structure while
VCPUs were still running.

Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
---
 tools/kvm/kvm-cpu.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 2f5d23c..64c0997 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -421,7 +421,13 @@ static void kvm_cpu__handle_coalesced_mmio(struct kvm_cpu *cpu)
 
 void kvm_cpu__reboot(void)
 {
-	pthread_kill(kvm_cpus[0]->thread, SIGKVMEXIT);
+	int i;
+
+	for (i = 0; i < KVM_NR_CPUS; i++)
+		if (kvm_cpus[i]) {
+			pthread_kill(kvm_cpus[i]->thread, SIGKVMEXIT);
+			pthread_join(kvm_cpus[i]->thread, NULL);
+		}
 }
 
 int kvm_cpu__start(struct kvm_cpu *cpu)
@@ -442,7 +448,7 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
 	if (cpu->kvm->single_step)
 		kvm_cpu__enable_singlestep(cpu);
 
-	for (;;) {
+	while (cpu->is_running) {
 		if (cpu->paused) {
 			kvm__notify_paused();
 			cpu->paused = 0;
-- 
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux