This patch moves the code which deals with loading QEMU config files, and autostart of domains & networks out of the qemud.c and into the driver.c file. These will later be invoked via a new libvirt internal driver API method. driver.c | 82 ++++++++++++++++++++++++++++++++++++++++----------------------- driver.h | 2 + qemud.c | 45 ++-------------------------------- 3 files changed, 58 insertions(+), 71 deletions(-) Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
diff -r 1ad7c535691c qemud/driver.c --- a/qemud/driver.c Thu Jun 21 16:11:05 2007 -0400 +++ b/qemud/driver.c Thu Jun 21 16:11:09 2007 -0400 @@ -93,6 +93,19 @@ static int qemudSetNonBlock(int fd) { } +int qemudStartup(struct qemud_server *server) { + return qemudScanConfigs(server); +} + +void qemudReload(struct qemud_server *server) { + qemudScanConfigs(server); + + if (server->iptables) { + qemudLog(QEMUD_INFO, "Reloading iptables rules"); + iptablesReloadRules(server->iptables); + } +} + void qemudShutdown(struct qemud_server *server) { struct qemud_vm *vm; struct qemud_network *network; @@ -448,7 +461,7 @@ int qemudStartVMDaemon(struct qemud_serv int qemudStartVMDaemon(struct qemud_server *server, struct qemud_vm *vm) { char **argv = NULL, **tmp; - int i, ret = -1; + int i; char logfile[PATH_MAX]; if (qemudIsActiveVM(vm)) { @@ -524,23 +537,11 @@ int qemudStartVMDaemon(struct qemud_serv server->ninactivevms--; server->nactivevms++; - - virEventAddHandle(vm->stdout, - POLLIN | POLLERR | POLLHUP, - qemudDispatchVMEvent, - server); - virEventAddHandle(vm->stderr, - POLLIN | POLLERR | POLLHUP, - qemudDispatchVMEvent, - server); - - ret = 0; - - if (qemudWaitForMonitor(server, vm) < 0) { - qemudShutdownVMDaemon(server, vm); - ret = -1; - } - } + } + + for (i = 0 ; argv[i] ; i++) + free(argv[i]); + free(argv); if (vm->tapfds) { for (i = 0; vm->tapfds[i] != -1; i++) { @@ -551,12 +552,30 @@ int qemudStartVMDaemon(struct qemud_serv vm->tapfds = NULL; vm->ntapfds = 0; } - - for (i = 0 ; argv[i] ; i++) - free(argv[i]); - free(argv); - - return ret; + + if (virEventAddHandle(vm->stdout, + POLLIN | POLLERR | POLLHUP, + qemudDispatchVMEvent, + server) < 0) { + qemudShutdownVMDaemon(server, vm); + return -1; + } + + if (virEventAddHandle(vm->stderr, + POLLIN | POLLERR | POLLHUP, + qemudDispatchVMEvent, + server) < 0) { + qemudShutdownVMDaemon(server, vm); + return -1; + } + + + if (qemudWaitForMonitor(server, vm) < 0) { + qemudShutdownVMDaemon(server, vm); + return -1; + } + + return 0; } static int qemudVMData(struct qemud_server *server ATTRIBUTE_UNUSED, @@ -633,6 +652,9 @@ int qemudShutdownVMDaemon(struct qemud_s server->nactivevms--; server->ninactivevms++; + + if (!vm->configFile[0]) + qemudRemoveInactiveVM(server, vm); return 0; } @@ -1096,6 +1118,9 @@ int qemudShutdownNetworkDaemon(struct qe server->nactivenetworks--; server->ninactivenetworks++; + if (!network->configFile[0]) + qemudRemoveInactiveNetwork(server, network); + return 0; } @@ -1116,11 +1141,10 @@ static void qemudDispatchVMEvent(int fd, if (!vm) return; - if (events == POLLIN && - qemudDispatchVMLog(server, vm, fd) == 0) - return; - - qemudDispatchVMFailure(server, vm, fd); + if (events == POLLIN) + qemudDispatchVMLog(server, vm, fd); + else + qemudDispatchVMFailure(server, vm, fd); } int qemudMonitorCommand(struct qemud_server *server ATTRIBUTE_UNUSED, diff -r 1ad7c535691c qemud/driver.h --- a/qemud/driver.h Thu Jun 21 16:11:05 2007 -0400 +++ b/qemud/driver.h Thu Jun 21 16:11:09 2007 -0400 @@ -39,6 +39,8 @@ int qemudShutdownNetworkDaemon(struct qe int qemudShutdownNetworkDaemon(struct qemud_server *server, struct qemud_network *network); +int qemudStartup(struct qemud_server *server); +void qemudReload(struct qemud_server *server); void qemudShutdown(struct qemud_server *server); void qemudReportError(struct qemud_server *server, diff -r 1ad7c535691c qemud/qemud.c --- a/qemud/qemud.c Thu Jun 21 16:11:05 2007 -0400 +++ b/qemud/qemud.c Thu Jun 21 16:11:09 2007 -0400 @@ -57,8 +57,6 @@ #include "../src/remote_internal.h" #include "../src/conf.h" #include "dispatch.h" -#include "conf.h" -#include "iptables.h" #include "driver.h" #include "event.h" @@ -209,12 +207,7 @@ static void qemudDispatchSignalEvent(int case SIGHUP: qemudLog(QEMUD_INFO, "Reloading configuration on SIGHUP"); if (!remote) { - ret = qemudScanConfigs(server); - - if (server->iptables) { - qemudLog(QEMUD_INFO, "Reloading iptables rules"); - iptablesReloadRules(server->iptables); - } + qemudReload(server); } break; @@ -733,7 +726,7 @@ static struct qemud_server *qemudInitial goto cleanup; if (!remote) /* qemud only */ { - if (qemudScanConfigs(server) < 0) { + if (qemudStartup(server) < 0) { goto cleanup; } } else /* remote only */ { @@ -1491,37 +1484,7 @@ static void qemudDispatchServerEvent(int } -static void qemudCleanupInactive(struct qemud_server *server) { - struct qemud_vm *vm = server->vms; - struct qemud_network *network = server->networks; - - /* Cleanup any VMs which shutdown & dont have an associated - config file */ - while (vm) { - struct qemud_vm *next = vm->next; - - if (!qemudIsActiveVM(vm) && !vm->configFile[0]) - qemudRemoveInactiveVM(server, vm); - - vm = next; - } - - /* Cleanup any networks too */ - while (network) { - struct qemud_network *next = network->next; - - if (!qemudIsActiveNetwork(network) && !network->configFile[0]) - qemudRemoveInactiveNetwork(server, network); - - network = next; - } - - return; -} - - - -static int qemudOneLoop(struct qemud_server *server) { +static int qemudOneLoop(struct qemud_server *server ATTRIBUTE_UNUSED) { sig_atomic_t errors; if (virEventRunOnce() < 0) @@ -1536,8 +1499,6 @@ static int qemudOneLoop(struct qemud_ser errors, strerror (sig_lasterrno)); return -1; } - - qemudCleanupInactive(server); return 0; }