mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
Move code dealing with global startup/shutdown/reload into driver.c
This commit is contained in:
parent
9f25d22a6f
commit
2dd21783ec
@ -1,3 +1,8 @@
|
|||||||
|
Tue Jun 26 16:41:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* qemud/driver.c, qemud/driver.h, qemud/qemud.c: Move code
|
||||||
|
handling global startup, shutdown & reload into driver.c
|
||||||
|
|
||||||
Tue Jun 26 16:41:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
Tue Jun 26 16:41:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* qemud/driver.c, qemud/driver.h, qemud/internal.h,
|
* qemud/driver.c, qemud/driver.h, qemud/internal.h,
|
||||||
|
@ -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) {
|
void qemudShutdown(struct qemud_server *server) {
|
||||||
struct qemud_vm *vm;
|
struct qemud_vm *vm;
|
||||||
struct qemud_network *network;
|
struct qemud_network *network;
|
||||||
@ -448,7 +461,7 @@ static int qemudNextFreeVNCPort(struct qemud_server *server ATTRIBUTE_UNUSED) {
|
|||||||
int qemudStartVMDaemon(struct qemud_server *server,
|
int qemudStartVMDaemon(struct qemud_server *server,
|
||||||
struct qemud_vm *vm) {
|
struct qemud_vm *vm) {
|
||||||
char **argv = NULL, **tmp;
|
char **argv = NULL, **tmp;
|
||||||
int i, ret = -1;
|
int i;
|
||||||
char logfile[PATH_MAX];
|
char logfile[PATH_MAX];
|
||||||
|
|
||||||
if (qemudIsActiveVM(vm)) {
|
if (qemudIsActiveVM(vm)) {
|
||||||
@ -524,24 +537,12 @@ int qemudStartVMDaemon(struct qemud_server *server,
|
|||||||
|
|
||||||
server->ninactivevms--;
|
server->ninactivevms--;
|
||||||
server->nactivevms++;
|
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) {
|
if (vm->tapfds) {
|
||||||
for (i = 0; vm->tapfds[i] != -1; i++) {
|
for (i = 0; vm->tapfds[i] != -1; i++) {
|
||||||
close(vm->tapfds[i]);
|
close(vm->tapfds[i]);
|
||||||
@ -551,12 +552,30 @@ int qemudStartVMDaemon(struct qemud_server *server,
|
|||||||
vm->tapfds = NULL;
|
vm->tapfds = NULL;
|
||||||
vm->ntapfds = 0;
|
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,
|
static int qemudVMData(struct qemud_server *server ATTRIBUTE_UNUSED,
|
||||||
@ -634,6 +653,9 @@ int qemudShutdownVMDaemon(struct qemud_server *server, struct qemud_vm *vm) {
|
|||||||
server->nactivevms--;
|
server->nactivevms--;
|
||||||
server->ninactivevms++;
|
server->ninactivevms++;
|
||||||
|
|
||||||
|
if (!vm->configFile[0])
|
||||||
|
qemudRemoveInactiveVM(server, vm);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1096,6 +1118,9 @@ int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
|||||||
server->nactivenetworks--;
|
server->nactivenetworks--;
|
||||||
server->ninactivenetworks++;
|
server->ninactivenetworks++;
|
||||||
|
|
||||||
|
if (!network->configFile[0])
|
||||||
|
qemudRemoveInactiveNetwork(server, network);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1116,11 +1141,10 @@ static void qemudDispatchVMEvent(int fd, int events, void *opaque) {
|
|||||||
if (!vm)
|
if (!vm)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (events == POLLIN &&
|
if (events == POLLIN)
|
||||||
qemudDispatchVMLog(server, vm, fd) == 0)
|
qemudDispatchVMLog(server, vm, fd);
|
||||||
return;
|
else
|
||||||
|
qemudDispatchVMFailure(server, vm, fd);
|
||||||
qemudDispatchVMFailure(server, vm, fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemudMonitorCommand(struct qemud_server *server ATTRIBUTE_UNUSED,
|
int qemudMonitorCommand(struct qemud_server *server ATTRIBUTE_UNUSED,
|
||||||
|
@ -39,6 +39,8 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
|
|||||||
int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
||||||
struct qemud_network *network);
|
struct qemud_network *network);
|
||||||
|
|
||||||
|
int qemudStartup(struct qemud_server *server);
|
||||||
|
void qemudReload(struct qemud_server *server);
|
||||||
void qemudShutdown(struct qemud_server *server);
|
void qemudShutdown(struct qemud_server *server);
|
||||||
|
|
||||||
void qemudReportError(struct qemud_server *server,
|
void qemudReportError(struct qemud_server *server,
|
||||||
|
@ -57,8 +57,6 @@
|
|||||||
#include "../src/remote_internal.h"
|
#include "../src/remote_internal.h"
|
||||||
#include "../src/conf.h"
|
#include "../src/conf.h"
|
||||||
#include "dispatch.h"
|
#include "dispatch.h"
|
||||||
#include "conf.h"
|
|
||||||
#include "iptables.h"
|
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
@ -209,12 +207,7 @@ static void qemudDispatchSignalEvent(int fd ATTRIBUTE_UNUSED,
|
|||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
qemudLog(QEMUD_INFO, "Reloading configuration on SIGHUP");
|
qemudLog(QEMUD_INFO, "Reloading configuration on SIGHUP");
|
||||||
if (!remote) {
|
if (!remote) {
|
||||||
ret = qemudScanConfigs(server);
|
qemudReload(server);
|
||||||
|
|
||||||
if (server->iptables) {
|
|
||||||
qemudLog(QEMUD_INFO, "Reloading iptables rules");
|
|
||||||
iptablesReloadRules(server->iptables);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -733,7 +726,7 @@ static struct qemud_server *qemudInitialize(int sigread) {
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!remote) /* qemud only */ {
|
if (!remote) /* qemud only */ {
|
||||||
if (qemudScanConfigs(server) < 0) {
|
if (qemudStartup(server) < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else /* remote only */ {
|
} else /* remote only */ {
|
||||||
@ -1491,37 +1484,7 @@ static void qemudDispatchServerEvent(int fd, int events, void *opaque) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void qemudCleanupInactive(struct qemud_server *server) {
|
static int qemudOneLoop(struct qemud_server *server ATTRIBUTE_UNUSED) {
|
||||||
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) {
|
|
||||||
sig_atomic_t errors;
|
sig_atomic_t errors;
|
||||||
|
|
||||||
if (virEventRunOnce() < 0)
|
if (virEventRunOnce() < 0)
|
||||||
@ -1537,8 +1500,6 @@ static int qemudOneLoop(struct qemud_server *server) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemudCleanupInactive(server);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user