Move code relating to vm/network lookups into conf.c

This commit is contained in:
Daniel P. Berrange 2007-06-26 22:42:47 +00:00
parent a041de159f
commit 133fdfe9e8
6 changed files with 94 additions and 87 deletions

View File

@ -1,3 +1,9 @@
Tue Jun 26 18:41:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* qemud/conf.c, qemud/conf.h, qemud/dispatch.c, qemud/driver.c,
qemud/driver.h: Move code related to looking up VMs/networks
into the conf.c
Tue Jun 26 18:35:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* qemud/conf.c, qemud/dispatch.c, qemud/driver.c, qemud/driver.h

View File

@ -66,6 +66,70 @@ void qemudReportError(virConnectPtr conn,
NULL, NULL, NULL, -1, -1, errorMessage);
}
struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver, int id) {
struct qemud_vm *vm = driver->vms;
while (vm) {
if (qemudIsActiveVM(vm) && vm->id == id)
return vm;
vm = vm->next;
}
return NULL;
}
struct qemud_vm *qemudFindVMByUUID(const struct qemud_driver *driver,
const unsigned char *uuid) {
struct qemud_vm *vm = driver->vms;
while (vm) {
if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
return vm;
vm = vm->next;
}
return NULL;
}
struct qemud_vm *qemudFindVMByName(const struct qemud_driver *driver,
const char *name) {
struct qemud_vm *vm = driver->vms;
while (vm) {
if (!strcmp(vm->def->name, name))
return vm;
vm = vm->next;
}
return NULL;
}
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_driver *driver,
const unsigned char *uuid) {
struct qemud_network *network = driver->networks;
while (network) {
if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
return network;
network = network->next;
}
return NULL;
}
struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
const char *name) {
struct qemud_network *network = driver->networks;
while (network) {
if (!strcmp(network->def->name, name))
return network;
network = network->next;
}
return NULL;
}
/* Free all memory associated with a struct qemud_vm object */
void qemudFreeVMDef(struct qemud_vm_def *def) {

View File

@ -24,6 +24,8 @@
#ifndef __QEMUD_CONF_H
#define __QEMUD_CONF_H
#include "../src/internal.h"
/* Different types of QEMU acceleration possible */
enum qemud_vm_virt_type {
QEMUD_VIRT_QEMU,

View File

@ -31,6 +31,7 @@
#include <libvirt/virterror.h>
#include "internal.h"
#include "../src/internal.h"
#include "driver.h"
#include "dispatch.h"
#include "conf.h"
@ -105,15 +106,10 @@ qemudDispatchGetCapabilities (struct qemud_packet_client_data *in ATTRIBUTE_UNUS
{
char *xml = qemudGetCapabilities(&conn);
if (strlen(xml) > QEMUD_MAX_XML_LEN) {
qemudReportError(&conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
qemudDispatchFailure(out);
free(xml);
return 0;
}
out->type = QEMUD_SERVER_PKT_GET_CAPABILITIES;
strcpy (out->qemud_packet_server_data_u.getCapabilitiesReply.xml, xml);
strncpy (out->qemud_packet_server_data_u.getCapabilitiesReply.xml, xml,
QEMUD_MAX_XML_LEN-1);
out->qemud_packet_server_data_u.getCapabilitiesReply.xml[QEMUD_MAX_XML_LEN-1] = '\0';
free(xml);
return 0;
}
@ -915,7 +911,8 @@ int qemudDispatch(struct qemud_server *server ATTRIBUTE_UNUSED,
if (!funcs[type]) {
qemudDebug("Illegal operation requested");
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_DENIED, NULL);
__virRaiseError(&conn, NULL, NULL, VIR_FROM_QEMU, VIR_ERR_OPERATION_DENIED, VIR_ERR_ERROR,
NULL, NULL, NULL, -1, -1, "Illegal operation requested");
qemudDispatchFailure(out);
} else {
if ((funcs[type])(in, out) < 0) {

View File

@ -51,6 +51,7 @@
#include "event.h"
#include "../src/buf.h"
#include "driver.h"
#include "conf.h"
static int qemudSetCloseExec(int fd) {
int flags;
@ -82,6 +83,19 @@ static int qemudSetNonBlock(int fd) {
static void qemudDispatchVMEvent(int fd, int events, void *opaque);
int qemudStartVMDaemon(struct qemud_driver *driver,
struct qemud_vm *vm);
int qemudShutdownVMDaemon(struct qemud_driver *driver,
struct qemud_vm *vm);
int qemudStartNetworkDaemon(struct qemud_driver *driver,
struct qemud_network *network);
int qemudShutdownNetworkDaemon(struct qemud_driver *driver,
struct qemud_network *network);
struct qemud_driver *qemu_driver = NULL;
static
@ -120,8 +134,6 @@ void qemudAutostartConfigs(struct qemud_driver *driver) {
}
}
struct qemud_driver *qemu_driver = NULL;
int qemudStartup(void) {
uid_t uid = geteuid();
struct passwd *pw;
@ -720,6 +732,8 @@ static int qemudVMData(struct qemud_driver *driver ATTRIBUTE_UNUSED,
strerror(errno));
}
}
qemudAutostartConfigs(qemu_driver);
}
@ -1662,43 +1676,6 @@ static int qemudGetProcessInfo(unsigned long long *cpuTime, int pid) {
return 0;
}
struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver, int id) {
struct qemud_vm *vm = driver->vms;
while (vm) {
if (qemudIsActiveVM(vm) && vm->id == id)
return vm;
vm = vm->next;
}
return NULL;
}
struct qemud_vm *qemudFindVMByUUID(const struct qemud_driver *driver,
const unsigned char *uuid) {
struct qemud_vm *vm = driver->vms;
while (vm) {
if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
return vm;
vm = vm->next;
}
return NULL;
}
struct qemud_vm *qemudFindVMByName(const struct qemud_driver *driver,
const char *name) {
struct qemud_vm *vm = driver->vms;
while (vm) {
if (!strcmp(vm->def->name, name))
return vm;
vm = vm->next;
}
return NULL;
}
virDomainPtr qemudDomainLookupByID(virConnectPtr conn ATTRIBUTE_UNUSED,
int id) {
@ -2147,32 +2124,6 @@ int qemudDomainSetAutostart(virDomainPtr dom,
return 0;
}
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_driver *driver,
const unsigned char *uuid) {
struct qemud_network *network = driver->networks;
while (network) {
if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
return network;
network = network->next;
}
return NULL;
}
struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
const char *name) {
struct qemud_network *network = driver->networks;
while (network) {
if (!strcmp(network->def->name, name))
return network;
network = network->next;
}
return NULL;
}
virNetworkPtr qemudNetworkLookupByUUID(virConnectPtr conn ATTRIBUTE_UNUSED,
const unsigned char *uuid) {
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;

View File

@ -27,19 +27,6 @@
#include "internal.h"
#include "../src/internal.h"
#include "conf.h"
int qemudStartVMDaemon(struct qemud_driver *driver,
struct qemud_vm *vm);
int qemudShutdownVMDaemon(struct qemud_driver *driver,
struct qemud_vm *vm);
int qemudStartNetworkDaemon(struct qemud_driver *driver,
struct qemud_network *network);
int qemudShutdownNetworkDaemon(struct qemud_driver *driver,
struct qemud_network *network);
int qemudStartup(void);
void qemudReload(void);