mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
daemonize qemu processes
This commit is contained in:
parent
5d99a309e6
commit
8dfbfe3145
@ -1,3 +1,10 @@
|
|||||||
|
Mon Jan 19 22:50:53 CET 2009 Guido Günther <agx@sigxcpu.org>
|
||||||
|
|
||||||
|
daemonize qemu processes
|
||||||
|
* src/qemu_driver.c (qemudStartVMDaemon): virExec qemu/kvm via
|
||||||
|
VIR_EXEC_DAEMON
|
||||||
|
(qemudShutdownVMDaemon): use virKillProcess, don't waitpid
|
||||||
|
|
||||||
Mon Jan 19 21:54:25 CET 2009 Guido Günther <agx@sigxcpu.org>
|
Mon Jan 19 21:54:25 CET 2009 Guido Günther <agx@sigxcpu.org>
|
||||||
|
|
||||||
save domstate as string in status file
|
save domstate as string in status file
|
||||||
|
@ -941,6 +941,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
unsigned int qemuCmdFlags;
|
unsigned int qemuCmdFlags;
|
||||||
fd_set keepfd;
|
fd_set keepfd;
|
||||||
const char *emulator;
|
const char *emulator;
|
||||||
|
pid_t child;
|
||||||
|
|
||||||
FD_ZERO(&keepfd);
|
FD_ZERO(&keepfd);
|
||||||
|
|
||||||
@ -1039,12 +1040,26 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
for (i = 0 ; i < ntapfds ; i++)
|
for (i = 0 ; i < ntapfds ; i++)
|
||||||
FD_SET(tapfds[i], &keepfd);
|
FD_SET(tapfds[i], &keepfd);
|
||||||
|
|
||||||
ret = virExec(conn, argv, progenv, &keepfd, &vm->pid,
|
ret = virExec(conn, argv, progenv, &keepfd, &child,
|
||||||
vm->stdin_fd, &vm->stdout_fd, &vm->stderr_fd,
|
vm->stdin_fd, &vm->stdout_fd, &vm->stderr_fd,
|
||||||
VIR_EXEC_NONBLOCK);
|
VIR_EXEC_NONBLOCK | VIR_EXEC_DAEMON);
|
||||||
if (ret == 0)
|
|
||||||
|
/* wait for qemu process to to show up */
|
||||||
|
if (ret == 0) {
|
||||||
|
int retries = 100;
|
||||||
|
while (retries) {
|
||||||
|
if ((ret = virFileReadPid(driver->stateDir, vm->def->name, &vm->pid)) == 0)
|
||||||
|
break;
|
||||||
|
usleep(100*1000);
|
||||||
|
retries--;
|
||||||
|
}
|
||||||
|
if (ret)
|
||||||
|
qemudLog(QEMUD_WARN, _("Domain %s didn't show up\n"), vm->def->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
vm->state = migrateFrom ? VIR_DOMAIN_PAUSED : VIR_DOMAIN_RUNNING;
|
vm->state = migrateFrom ? VIR_DOMAIN_PAUSED : VIR_DOMAIN_RUNNING;
|
||||||
else
|
} else
|
||||||
vm->def->id = -1;
|
vm->def->id = -1;
|
||||||
|
|
||||||
for (i = 0 ; argv[i] ; i++)
|
for (i = 0 ; argv[i] ; i++)
|
||||||
@ -1121,7 +1136,10 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
qemudLog(QEMUD_INFO, _("Shutting down VM '%s'\n"), vm->def->name);
|
qemudLog(QEMUD_INFO, _("Shutting down VM '%s'\n"), vm->def->name);
|
||||||
|
|
||||||
kill(vm->pid, SIGTERM);
|
if (virKillProcess(vm->pid, 0) == 0 &&
|
||||||
|
virKillProcess(vm->pid, SIGTERM) < 0)
|
||||||
|
qemudLog(QEMUD_ERROR, _("Failed to send SIGTERM to %s (%d): %s\n"),
|
||||||
|
vm->def->name, vm->pid, strerror(errno));
|
||||||
|
|
||||||
qemudVMData(driver, vm, vm->stdout_fd);
|
qemudVMData(driver, vm, vm->stdout_fd);
|
||||||
qemudVMData(driver, vm, vm->stderr_fd);
|
qemudVMData(driver, vm, vm->stderr_fd);
|
||||||
@ -1141,15 +1159,10 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
vm->stderr_fd = -1;
|
vm->stderr_fd = -1;
|
||||||
vm->monitor = -1;
|
vm->monitor = -1;
|
||||||
|
|
||||||
if (waitpid(vm->pid, NULL, WNOHANG) != vm->pid) {
|
/* shut it off for sure */
|
||||||
kill(vm->pid, SIGKILL);
|
virKillProcess(vm->pid, SIGKILL);
|
||||||
if (waitpid(vm->pid, NULL, 0) != vm->pid) {
|
|
||||||
qemudLog(QEMUD_WARN,
|
|
||||||
"%s", _("Got unexpected pid, damn\n"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qemudRemoveDomainStatus(conn, driver, vm);
|
|
||||||
|
|
||||||
|
qemudRemoveDomainStatus(conn, driver, vm);
|
||||||
vm->pid = -1;
|
vm->pid = -1;
|
||||||
vm->def->id = -1;
|
vm->def->id = -1;
|
||||||
vm->state = VIR_DOMAIN_SHUTOFF;
|
vm->state = VIR_DOMAIN_SHUTOFF;
|
||||||
|
Loading…
Reference in New Issue
Block a user