[libvirt] [PATCH] qemu: Faster response time to qemu startup errors

The below patch decreases the response time of libvirt to errors reported by Qemu upon startup by checking whether the qemu process is still alive while polling for the local socket to show up. This patch also introduces a special handling of signal for the Win32 part of virKillProcess. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 26bb814..92c44bf 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -247,7 +247,7 @@ qemuMonitorUnwatch(void *monitor) } static int -qemuMonitorOpenUnix(const char *monitor) +qemuMonitorOpenUnix(const char *monitor, pid_t cpid) { struct sockaddr_un addr; int monfd; @@ -274,7 +274,8 @@ qemuMonitorOpenUnix(const char *monitor) if (ret == 0) break; - if (errno == ENOENT || errno == ECONNREFUSED) { + if ((errno == ENOENT || errno == ECONNREFUSED) && + virKillProcess(cpid, 0) == 0) { /* ENOENT : Socket may not have shown up yet * ECONNREFUSED : Leftover socket hasn't been removed yet */ continue; @@ -691,7 +692,7 @@ qemuMonitorOpen(virDomainObjPtr vm, switch (config->type) { case VIR_DOMAIN_CHR_TYPE_UNIX: mon->hasSendFD = 1; - mon->fd = qemuMonitorOpenUnix(config->data.nix.path); + mon->fd = qemuMonitorOpenUnix(config->data.nix.path, vm->pid); break; case VIR_DOMAIN_CHR_TYPE_PTY: diff --git a/src/util/util.c b/src/util/util.c index d00f065..df4dfac 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -2010,7 +2010,7 @@ int virKillProcess(pid_t pid, int sig) * TerminateProcess is more or less equiv to SIG_KILL, in that * a process can't trap / block it */ - if (!TerminateProcess(proc, sig)) { + if (sig != 0 && !TerminateProcess(proc, sig)) { errno = ESRCH; return -1; }

On 06/13/2011 01:26 PM, Stefan Berger wrote:
The below patch decreases the response time of libvirt to errors reported by Qemu upon startup by checking whether the qemu process is still alive while polling for the local socket to show up.
@@ -274,7 +274,8 @@ qemuMonitorOpenUnix(const char *monitor) if (ret == 0) break;
- if (errno == ENOENT || errno == ECONNREFUSED) { + if ((errno == ENOENT || errno == ECONNREFUSED) && + virKillProcess(cpid, 0) == 0) { /* ENOENT : Socket may not have shown up yet * ECONNREFUSED : Leftover socket hasn't been removed yet */ continue;
Calling virKillProcess changes errno; in fact, errno will probably be ESRCH if virKillProcess ended up being called but the process is not alive. But I guess that is just as good a message, and can only happen on ENOENT or ECONNREFUSED in the first place, so it looks okay to me. ACK. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 06/13/2011 03:36 PM, Eric Blake wrote:
On 06/13/2011 01:26 PM, Stefan Berger wrote:
The below patch decreases the response time of libvirt to errors reported by Qemu upon startup by checking whether the qemu process is still alive while polling for the local socket to show up.
@@ -274,7 +274,8 @@ qemuMonitorOpenUnix(const char *monitor) if (ret == 0) break;
- if (errno == ENOENT || errno == ECONNREFUSED) { + if ((errno == ENOENT || errno == ECONNREFUSED)&& + virKillProcess(cpid, 0) == 0) { /* ENOENT : Socket may not have shown up yet * ECONNREFUSED : Leftover socket hasn't been removed yet */ continue; Calling virKillProcess changes errno; in fact, errno will probably be ESRCH if virKillProcess ended up being called but the process is not alive. But I guess that is just as good a message, and can only happen on ENOENT or ECONNREFUSED in the first place, so it looks okay to me.
ACK.
Pushed. Stefan
participants (2)
-
Eric Blake
-
Stefan Berger