mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
Split up struct qemud_server to move qemu stuff into conf.c
This commit is contained in:
parent
498cc57835
commit
b63f8cc9f9
@ -1,3 +1,11 @@
|
|||||||
|
Tue Jun 26 18:10:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* qemud/conf.c, qemud/conf.h, qemud/dispatch.c, qemud/driver.c,
|
||||||
|
qemud/driver.h, qemud/internal.h, qemud/qemud.c: Split the
|
||||||
|
struct qemud_server into two parts, moving QEMU stuff out into
|
||||||
|
struct qemud_driver. Move all QEMU related data structures
|
||||||
|
and manipulation code into conf.c file
|
||||||
|
|
||||||
Tue Jun 26 16:50:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
Tue Jun 26 16:50:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* qemud/Makefile.am, qemud/conf.c, qemud/dispatch.c, qemud/driver.c,
|
* qemud/Makefile.am, qemud/conf.c, qemud/dispatch.c, qemud/driver.c,
|
||||||
|
239
qemud/conf.c
239
qemud/conf.c
@ -44,10 +44,41 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "driver.h"
|
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
|
|
||||||
|
extern void __virRaiseError(virConnectPtr conn,
|
||||||
|
virDomainPtr dom,
|
||||||
|
virNetworkPtr net,
|
||||||
|
int domain,
|
||||||
|
int code,
|
||||||
|
virErrorLevel level,
|
||||||
|
const char *str1,
|
||||||
|
const char *str2,
|
||||||
|
const char *str3,
|
||||||
|
int int1, int int2, const char *msg, ...)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 12, 13);
|
||||||
|
|
||||||
|
void qemudReportError(virConnectPtr conn,
|
||||||
|
virDomainPtr dom,
|
||||||
|
virNetworkPtr net,
|
||||||
|
int code, const char *fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
char errorMessage[QEMUD_MAX_ERROR_LEN];
|
||||||
|
|
||||||
|
if (fmt) {
|
||||||
|
va_start(args, fmt);
|
||||||
|
vsnprintf(errorMessage, QEMUD_MAX_ERROR_LEN-1, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
} else {
|
||||||
|
errorMessage[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
__virRaiseError(conn, dom, net, VIR_FROM_QEMU, code, VIR_ERR_ERROR,
|
||||||
|
NULL, NULL, NULL, -1, -1, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Free all memory associated with a struct qemud_vm object */
|
/* Free all memory associated with a struct qemud_vm object */
|
||||||
void qemudFreeVMDef(struct qemud_vm_def *def) {
|
void qemudFreeVMDef(struct qemud_vm_def *def) {
|
||||||
struct qemud_vm_disk_def *disk = def->disks;
|
struct qemud_vm_disk_def *disk = def->disks;
|
||||||
@ -183,7 +214,7 @@ static const char *qemudDefaultBinaryForArch(const char *arch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Find the fully qualified path to the binary for an architecture */
|
/* Find the fully qualified path to the binary for an architecture */
|
||||||
static char *qemudLocateBinaryForArch(struct qemud_server *server,
|
static char *qemudLocateBinaryForArch(struct qemud_driver *driver,
|
||||||
int virtType, const char *arch) {
|
int virtType, const char *arch) {
|
||||||
const char *name;
|
const char *name;
|
||||||
char *path;
|
char *path;
|
||||||
@ -303,14 +334,14 @@ static int qemudExtractVersionInfo(const char *qemu, int *version, int *flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemudExtractVersion(struct qemud_server *server) {
|
int qemudExtractVersion(struct qemud_driver *driver) {
|
||||||
char *binary = NULL;
|
char *binary = NULL;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (server->qemuVersion > 0)
|
if (driver->qemuVersion > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(binary = qemudLocateBinaryForArch(server, QEMUD_VIRT_QEMU, "i686")))
|
if (!(binary = qemudLocateBinaryForArch(driver, QEMUD_VIRT_QEMU, "i686")))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (stat(binary, &sb) < 0) {
|
if (stat(binary, &sb) < 0) {
|
||||||
@ -321,7 +352,7 @@ int qemudExtractVersion(struct qemud_server *server) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudExtractVersionInfo(binary, &server->qemuVersion, &server->qemuCmdFlags) < 0) {
|
if (qemudExtractVersionInfo(binary, &driver->qemuVersion, &driver->qemuCmdFlags) < 0) {
|
||||||
free(binary);
|
free(binary);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -332,7 +363,7 @@ int qemudExtractVersion(struct qemud_server *server) {
|
|||||||
|
|
||||||
|
|
||||||
/* Parse the XML definition for a disk */
|
/* Parse the XML definition for a disk */
|
||||||
static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_server *server,
|
static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_driver *driver,
|
||||||
xmlNodePtr node) {
|
xmlNodePtr node) {
|
||||||
struct qemud_vm_disk_def *disk = calloc(1, sizeof(struct qemud_vm_disk_def));
|
struct qemud_vm_disk_def *disk = calloc(1, sizeof(struct qemud_vm_disk_def));
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
@ -469,7 +500,7 @@ static void qemudRandomMAC(struct qemud_vm_net_def *net) {
|
|||||||
|
|
||||||
|
|
||||||
/* Parse the XML definition for a network interface */
|
/* Parse the XML definition for a network interface */
|
||||||
static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *server,
|
static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driver,
|
||||||
xmlNodePtr node) {
|
xmlNodePtr node) {
|
||||||
struct qemud_vm_net_def *net = calloc(1, sizeof(struct qemud_vm_net_def));
|
struct qemud_vm_net_def *net = calloc(1, sizeof(struct qemud_vm_net_def));
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
@ -723,7 +754,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
|
|||||||
* Parses a libvirt XML definition of a guest, and populates the
|
* Parses a libvirt XML definition of a guest, and populates the
|
||||||
* the qemud_vm struct with matching data about the guests config
|
* the qemud_vm struct with matching data about the guests config
|
||||||
*/
|
*/
|
||||||
static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
|
static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
||||||
xmlDocPtr xml) {
|
xmlDocPtr xml) {
|
||||||
xmlNodePtr root = NULL;
|
xmlNodePtr root = NULL;
|
||||||
xmlChar *prop = NULL;
|
xmlChar *prop = NULL;
|
||||||
@ -1006,7 +1037,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
|
|||||||
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt);
|
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt);
|
||||||
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
||||||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
||||||
char *tmp = qemudLocateBinaryForArch(server, def->virtType, def->os.arch);
|
char *tmp = qemudLocateBinaryForArch(driver, def->virtType, def->os.arch);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -1054,7 +1085,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
|
|||||||
struct qemud_vm_disk_def *prev = NULL;
|
struct qemud_vm_disk_def *prev = NULL;
|
||||||
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
||||||
struct qemud_vm_disk_def *disk;
|
struct qemud_vm_disk_def *disk;
|
||||||
if (!(disk = qemudParseDiskXML(server, obj->nodesetval->nodeTab[i]))) {
|
if (!(disk = qemudParseDiskXML(driver, obj->nodesetval->nodeTab[i]))) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->ndisks++;
|
def->ndisks++;
|
||||||
@ -1077,7 +1108,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
|
|||||||
struct qemud_vm_net_def *prev = NULL;
|
struct qemud_vm_net_def *prev = NULL;
|
||||||
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
||||||
struct qemud_vm_net_def *net;
|
struct qemud_vm_net_def *net;
|
||||||
if (!(net = qemudParseInterfaceXML(server, obj->nodesetval->nodeTab[i]))) {
|
if (!(net = qemudParseInterfaceXML(driver, obj->nodesetval->nodeTab[i]))) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->nnets++;
|
def->nnets++;
|
||||||
@ -1108,7 +1139,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
|
|||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
qemudNetworkIfaceConnect(struct qemud_server *server,
|
qemudNetworkIfaceConnect(struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
struct qemud_vm_net_def *net,
|
struct qemud_vm_net_def *net,
|
||||||
int vlan)
|
int vlan)
|
||||||
@ -1123,7 +1154,7 @@ qemudNetworkIfaceConnect(struct qemud_server *server,
|
|||||||
int *tapfds;
|
int *tapfds;
|
||||||
|
|
||||||
if (net->type == QEMUD_NET_NETWORK) {
|
if (net->type == QEMUD_NET_NETWORK) {
|
||||||
if (!(network = qemudFindNetworkByName(server, net->dst.network.name))) {
|
if (!(network = qemudFindNetworkByName(driver, net->dst.network.name))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Network '%s' not found", net->dst.network.name);
|
"Network '%s' not found", net->dst.network.name);
|
||||||
goto error;
|
goto error;
|
||||||
@ -1151,13 +1182,13 @@ qemudNetworkIfaceConnect(struct qemud_server *server,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server->brctl && (err = brInit(&server->brctl))) {
|
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot initialize bridge support: %s", strerror(err));
|
"cannot initialize bridge support: %s", strerror(err));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = brAddTap(server->brctl, brname,
|
if ((err = brAddTap(driver->brctl, brname,
|
||||||
ifname, BR_IFNAME_MAXLEN, &tapfd))) {
|
ifname, BR_IFNAME_MAXLEN, &tapfd))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Failed to add tap interface '%s' to bridge '%s' : %s",
|
"Failed to add tap interface '%s' to bridge '%s' : %s",
|
||||||
@ -1193,7 +1224,7 @@ qemudNetworkIfaceConnect(struct qemud_server *server,
|
|||||||
* Constructs a argv suitable for launching qemu with config defined
|
* Constructs a argv suitable for launching qemu with config defined
|
||||||
* for a given virtual machine.
|
* for a given virtual machine.
|
||||||
*/
|
*/
|
||||||
int qemudBuildCommandLine(struct qemud_server *server,
|
int qemudBuildCommandLine(struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
char ***argv) {
|
char ***argv) {
|
||||||
int len, n = -1, i;
|
int len, n = -1, i;
|
||||||
@ -1206,7 +1237,7 @@ int qemudBuildCommandLine(struct qemud_server *server,
|
|||||||
struct utsname ut;
|
struct utsname ut;
|
||||||
int disableKQEMU = 0;
|
int disableKQEMU = 0;
|
||||||
|
|
||||||
if (qemudExtractVersion(server) < 0)
|
if (qemudExtractVersion(driver) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uname(&ut);
|
uname(&ut);
|
||||||
@ -1223,7 +1254,7 @@ int qemudBuildCommandLine(struct qemud_server *server,
|
|||||||
* 2. Guest is 'qemu'
|
* 2. Guest is 'qemu'
|
||||||
* 3. The qemu binary has the -no-kqemu flag
|
* 3. The qemu binary has the -no-kqemu flag
|
||||||
*/
|
*/
|
||||||
if ((server->qemuCmdFlags & QEMUD_CMD_FLAG_KQEMU) &&
|
if ((driver->qemuCmdFlags & QEMUD_CMD_FLAG_KQEMU) &&
|
||||||
!strcmp(ut.machine, vm->def->os.arch) &&
|
!strcmp(ut.machine, vm->def->os.arch) &&
|
||||||
vm->def->virtType == QEMUD_VIRT_QEMU)
|
vm->def->virtType == QEMUD_VIRT_QEMU)
|
||||||
disableKQEMU = 1;
|
disableKQEMU = 1;
|
||||||
@ -1248,7 +1279,7 @@ int qemudBuildCommandLine(struct qemud_server *server,
|
|||||||
2 + /* cpus */
|
2 + /* cpus */
|
||||||
2 + /* boot device */
|
2 + /* boot device */
|
||||||
2 + /* monitor */
|
2 + /* monitor */
|
||||||
(server->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
|
(driver->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
|
||||||
vm->def->noReboot ? 1 : 0) + /* no-reboot */
|
vm->def->noReboot ? 1 : 0) + /* no-reboot */
|
||||||
(vm->def->features & QEMUD_FEATURE_ACPI ? 0 : 1) + /* acpi */
|
(vm->def->features & QEMUD_FEATURE_ACPI ? 0 : 1) + /* acpi */
|
||||||
(vm->def->os.kernel[0] ? 2 : 0) + /* kernel */
|
(vm->def->os.kernel[0] ? 2 : 0) + /* kernel */
|
||||||
@ -1286,7 +1317,7 @@ int qemudBuildCommandLine(struct qemud_server *server,
|
|||||||
if (!((*argv)[++n] = strdup("pty")))
|
if (!((*argv)[++n] = strdup("pty")))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
if (server->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
|
if (driver->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
|
||||||
vm->def->noReboot) {
|
vm->def->noReboot) {
|
||||||
if (!((*argv)[++n] = strdup("-no-reboot")))
|
if (!((*argv)[++n] = strdup("-no-reboot")))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
@ -1387,7 +1418,7 @@ int qemudBuildCommandLine(struct qemud_server *server,
|
|||||||
switch (net->type) {
|
switch (net->type) {
|
||||||
case QEMUD_NET_NETWORK:
|
case QEMUD_NET_NETWORK:
|
||||||
case QEMUD_NET_BRIDGE:
|
case QEMUD_NET_BRIDGE:
|
||||||
if (!((*argv)[++n] = qemudNetworkIfaceConnect(server, vm, net, vlan)))
|
if (!((*argv)[++n] = qemudNetworkIfaceConnect(driver, vm, net, vlan)))
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1455,7 +1486,7 @@ int qemudBuildCommandLine(struct qemud_server *server,
|
|||||||
char port[10];
|
char port[10];
|
||||||
int ret;
|
int ret;
|
||||||
ret = snprintf(port, sizeof(port),
|
ret = snprintf(port, sizeof(port),
|
||||||
((server->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON) ?
|
((driver->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON) ?
|
||||||
":%d" : "%d"),
|
":%d" : "%d"),
|
||||||
vm->def->vncActivePort - 5900);
|
vm->def->vncActivePort - 5900);
|
||||||
if (ret < 0 || ret >= (int)sizeof(port))
|
if (ret < 0 || ret >= (int)sizeof(port))
|
||||||
@ -1496,14 +1527,14 @@ int qemudBuildCommandLine(struct qemud_server *server,
|
|||||||
|
|
||||||
|
|
||||||
/* Save a guest's config data into a persistent file */
|
/* Save a guest's config data into a persistent file */
|
||||||
static int qemudSaveConfig(struct qemud_server *server,
|
static int qemudSaveConfig(struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
struct qemud_vm_def *def) {
|
struct qemud_vm_def *def) {
|
||||||
char *xml;
|
char *xml;
|
||||||
int fd = -1, ret = -1;
|
int fd = -1, ret = -1;
|
||||||
int towrite;
|
int towrite;
|
||||||
|
|
||||||
if (!(xml = qemudGenerateXML(server, vm, def, 0)))
|
if (!(xml = qemudGenerateXML(driver, vm, def, 0)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((fd = open(vm->configFile,
|
if ((fd = open(vm->configFile,
|
||||||
@ -1542,7 +1573,7 @@ static int qemudSaveConfig(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_vm_def *
|
struct qemud_vm_def *
|
||||||
qemudParseVMDef(struct qemud_server *server,
|
qemudParseVMDef(struct qemud_driver *driver,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
const char *displayName) {
|
const char *displayName) {
|
||||||
xmlDocPtr xml;
|
xmlDocPtr xml;
|
||||||
@ -1555,7 +1586,7 @@ qemudParseVMDef(struct qemud_server *server,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
def = qemudParseXML(server, xml);
|
def = qemudParseXML(driver, xml);
|
||||||
|
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
|
||||||
@ -1563,12 +1594,12 @@ qemudParseVMDef(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_vm *
|
struct qemud_vm *
|
||||||
qemudAssignVMDef(struct qemud_server *server,
|
qemudAssignVMDef(struct qemud_driver *driver,
|
||||||
struct qemud_vm_def *def)
|
struct qemud_vm_def *def)
|
||||||
{
|
{
|
||||||
struct qemud_vm *vm = NULL;
|
struct qemud_vm *vm = NULL;
|
||||||
|
|
||||||
if ((vm = qemudFindVMByName(server, def->name))) {
|
if ((vm = qemudFindVMByName(driver, def->name))) {
|
||||||
if (!qemudIsActiveVM(vm)) {
|
if (!qemudIsActiveVM(vm)) {
|
||||||
qemudFreeVMDef(vm->def);
|
qemudFreeVMDef(vm->def);
|
||||||
vm->def = def;
|
vm->def = def;
|
||||||
@ -1593,21 +1624,21 @@ qemudAssignVMDef(struct qemud_server *server,
|
|||||||
vm->id = -1;
|
vm->id = -1;
|
||||||
vm->state = QEMUD_STATE_STOPPED;
|
vm->state = QEMUD_STATE_STOPPED;
|
||||||
vm->def = def;
|
vm->def = def;
|
||||||
vm->next = server->vms;
|
vm->next = driver->vms;
|
||||||
|
|
||||||
server->vms = vm;
|
driver->vms = vm;
|
||||||
server->ninactivevms++;
|
driver->ninactivevms++;
|
||||||
|
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
qemudRemoveInactiveVM(struct qemud_server *server,
|
qemudRemoveInactiveVM(struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm)
|
struct qemud_vm *vm)
|
||||||
{
|
{
|
||||||
struct qemud_vm *prev = NULL, *curr;
|
struct qemud_vm *prev = NULL, *curr;
|
||||||
|
|
||||||
curr = server->vms;
|
curr = driver->vms;
|
||||||
while (curr != vm) {
|
while (curr != vm) {
|
||||||
prev = curr;
|
prev = curr;
|
||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
@ -1617,36 +1648,36 @@ qemudRemoveInactiveVM(struct qemud_server *server,
|
|||||||
if (prev)
|
if (prev)
|
||||||
prev->next = curr->next;
|
prev->next = curr->next;
|
||||||
else
|
else
|
||||||
server->vms = curr->next;
|
driver->vms = curr->next;
|
||||||
|
|
||||||
server->ninactivevms--;
|
driver->ninactivevms--;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemudFreeVM(vm);
|
qemudFreeVM(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
qemudSaveVMDef(struct qemud_server *server,
|
qemudSaveVMDef(struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
struct qemud_vm_def *def) {
|
struct qemud_vm_def *def) {
|
||||||
if (vm->configFile[0] == '\0') {
|
if (vm->configFile[0] == '\0') {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((err = qemudEnsureDir(server->configDir))) {
|
if ((err = qemudEnsureDir(driver->configDir))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create config directory %s: %s",
|
"cannot create config directory %s: %s",
|
||||||
server->configDir, strerror(err));
|
driver->configDir, strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudMakeConfigPath(server->configDir, def->name, ".xml",
|
if (qemudMakeConfigPath(driver->configDir, def->name, ".xml",
|
||||||
vm->configFile, PATH_MAX) < 0) {
|
vm->configFile, PATH_MAX) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot construct config file path");
|
"cannot construct config file path");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudMakeConfigPath(server->autostartDir, def->name, ".xml",
|
if (qemudMakeConfigPath(driver->autostartDir, def->name, ".xml",
|
||||||
vm->autostartLink, PATH_MAX) < 0) {
|
vm->autostartLink, PATH_MAX) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot construct autostart link path");
|
"cannot construct autostart link path");
|
||||||
@ -1655,10 +1686,10 @@ qemudSaveVMDef(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return qemudSaveConfig(server, vm, def);
|
return qemudSaveConfig(driver, vm, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudSaveNetworkConfig(struct qemud_server *server,
|
static int qemudSaveNetworkConfig(struct qemud_driver *driver,
|
||||||
struct qemud_network *network,
|
struct qemud_network *network,
|
||||||
struct qemud_network_def *def) {
|
struct qemud_network_def *def) {
|
||||||
char *xml;
|
char *xml;
|
||||||
@ -1666,14 +1697,14 @@ static int qemudSaveNetworkConfig(struct qemud_server *server,
|
|||||||
int towrite;
|
int towrite;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!(xml = qemudGenerateNetworkXML(server, network, def))) {
|
if (!(xml = qemudGenerateNetworkXML(driver, network, def))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = qemudEnsureDir(server->networkConfigDir))) {
|
if ((err = qemudEnsureDir(driver->networkConfigDir))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create config directory %s: %s",
|
"cannot create config directory %s: %s",
|
||||||
server->networkConfigDir, strerror(err));
|
driver->networkConfigDir, strerror(err));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1727,7 +1758,7 @@ void qemudFreeNetwork(struct qemud_network *network) {
|
|||||||
free(network);
|
free(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudParseBridgeXML(struct qemud_server *server ATTRIBUTE_UNUSED,
|
static int qemudParseBridgeXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
struct qemud_network_def *def,
|
struct qemud_network_def *def,
|
||||||
xmlNodePtr node) {
|
xmlNodePtr node) {
|
||||||
xmlChar *name, *stp, *delay;
|
xmlChar *name, *stp, *delay;
|
||||||
@ -1759,7 +1790,7 @@ static int qemudParseBridgeXML(struct qemud_server *server ATTRIBUTE_UNUSED,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudParseDhcpRangesXML(struct qemud_server *server,
|
static int qemudParseDhcpRangesXML(struct qemud_driver *driver,
|
||||||
struct qemud_network_def *def,
|
struct qemud_network_def *def,
|
||||||
xmlNodePtr node) {
|
xmlNodePtr node) {
|
||||||
|
|
||||||
@ -1809,7 +1840,7 @@ static int qemudParseDhcpRangesXML(struct qemud_server *server,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudParseInetXML(struct qemud_server *server ATTRIBUTE_UNUSED,
|
static int qemudParseInetXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
struct qemud_network_def *def,
|
struct qemud_network_def *def,
|
||||||
xmlNodePtr node) {
|
xmlNodePtr node) {
|
||||||
xmlChar *address, *netmask;
|
xmlChar *address, *netmask;
|
||||||
@ -1850,7 +1881,7 @@ static int qemudParseInetXML(struct qemud_server *server ATTRIBUTE_UNUSED,
|
|||||||
while (cur != NULL) {
|
while (cur != NULL) {
|
||||||
if (cur->type == XML_ELEMENT_NODE &&
|
if (cur->type == XML_ELEMENT_NODE &&
|
||||||
xmlStrEqual(cur->name, BAD_CAST "dhcp") &&
|
xmlStrEqual(cur->name, BAD_CAST "dhcp") &&
|
||||||
!qemudParseDhcpRangesXML(server, def, cur))
|
!qemudParseDhcpRangesXML(driver, def, cur))
|
||||||
return 0;
|
return 0;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
@ -1859,7 +1890,7 @@ static int qemudParseInetXML(struct qemud_server *server ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *server,
|
static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *driver,
|
||||||
xmlDocPtr xml) {
|
xmlDocPtr xml) {
|
||||||
xmlNodePtr root = NULL;
|
xmlNodePtr root = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
@ -1920,7 +1951,7 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *serve
|
|||||||
obj = xmlXPathEval(BAD_CAST "/network/bridge[1]", ctxt);
|
obj = xmlXPathEval(BAD_CAST "/network/bridge[1]", ctxt);
|
||||||
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
||||||
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) {
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) {
|
||||||
if (!qemudParseBridgeXML(server, def, obj->nodesetval->nodeTab[0])) {
|
if (!qemudParseBridgeXML(driver, def, obj->nodesetval->nodeTab[0])) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1930,7 +1961,7 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *serve
|
|||||||
obj = xmlXPathEval(BAD_CAST "/network/ip[1]", ctxt);
|
obj = xmlXPathEval(BAD_CAST "/network/ip[1]", ctxt);
|
||||||
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
||||||
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) {
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) {
|
||||||
if (!qemudParseInetXML(server, def, obj->nodesetval->nodeTab[0])) {
|
if (!qemudParseInetXML(driver, def, obj->nodesetval->nodeTab[0])) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1987,7 +2018,7 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *serve
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_network_def *
|
struct qemud_network_def *
|
||||||
qemudParseNetworkDef(struct qemud_server *server,
|
qemudParseNetworkDef(struct qemud_driver *driver,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
const char *displayName) {
|
const char *displayName) {
|
||||||
xmlDocPtr xml;
|
xmlDocPtr xml;
|
||||||
@ -2000,7 +2031,7 @@ qemudParseNetworkDef(struct qemud_server *server,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
def = qemudParseNetworkXML(server, xml);
|
def = qemudParseNetworkXML(driver, xml);
|
||||||
|
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
|
||||||
@ -2008,11 +2039,11 @@ qemudParseNetworkDef(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_network *
|
struct qemud_network *
|
||||||
qemudAssignNetworkDef(struct qemud_server *server,
|
qemudAssignNetworkDef(struct qemud_driver *driver,
|
||||||
struct qemud_network_def *def) {
|
struct qemud_network_def *def) {
|
||||||
struct qemud_network *network;
|
struct qemud_network *network;
|
||||||
|
|
||||||
if ((network = qemudFindNetworkByName(server, def->name))) {
|
if ((network = qemudFindNetworkByName(driver, def->name))) {
|
||||||
if (!qemudIsActiveNetwork(network)) {
|
if (!qemudIsActiveNetwork(network)) {
|
||||||
qemudFreeNetworkDef(network->def);
|
qemudFreeNetworkDef(network->def);
|
||||||
network->def = def;
|
network->def = def;
|
||||||
@ -2031,21 +2062,21 @@ qemudAssignNetworkDef(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
network->def = def;
|
network->def = def;
|
||||||
network->next = server->networks;
|
network->next = driver->networks;
|
||||||
|
|
||||||
server->networks = network;
|
driver->networks = network;
|
||||||
server->ninactivenetworks++;
|
driver->ninactivenetworks++;
|
||||||
|
|
||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
qemudRemoveInactiveNetwork(struct qemud_server *server,
|
qemudRemoveInactiveNetwork(struct qemud_driver *driver,
|
||||||
struct qemud_network *network)
|
struct qemud_network *network)
|
||||||
{
|
{
|
||||||
struct qemud_network *prev = NULL, *curr;
|
struct qemud_network *prev = NULL, *curr;
|
||||||
|
|
||||||
curr = server->networks;
|
curr = driver->networks;
|
||||||
while (curr != network) {
|
while (curr != network) {
|
||||||
prev = curr;
|
prev = curr;
|
||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
@ -2055,37 +2086,37 @@ qemudRemoveInactiveNetwork(struct qemud_server *server,
|
|||||||
if (prev)
|
if (prev)
|
||||||
prev->next = curr->next;
|
prev->next = curr->next;
|
||||||
else
|
else
|
||||||
server->networks = curr->next;
|
driver->networks = curr->next;
|
||||||
|
|
||||||
server->ninactivenetworks--;
|
driver->ninactivenetworks--;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemudFreeNetwork(network);
|
qemudFreeNetwork(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
qemudSaveNetworkDef(struct qemud_server *server,
|
qemudSaveNetworkDef(struct qemud_driver *driver,
|
||||||
struct qemud_network *network,
|
struct qemud_network *network,
|
||||||
struct qemud_network_def *def) {
|
struct qemud_network_def *def) {
|
||||||
|
|
||||||
if (network->configFile[0] == '\0') {
|
if (network->configFile[0] == '\0') {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((err = qemudEnsureDir(server->networkConfigDir))) {
|
if ((err = qemudEnsureDir(driver->networkConfigDir))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create config directory %s: %s",
|
"cannot create config directory %s: %s",
|
||||||
server->networkConfigDir, strerror(err));
|
driver->networkConfigDir, strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudMakeConfigPath(server->networkConfigDir, def->name, ".xml",
|
if (qemudMakeConfigPath(driver->networkConfigDir, def->name, ".xml",
|
||||||
network->configFile, PATH_MAX) < 0) {
|
network->configFile, PATH_MAX) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot construct config file path");
|
"cannot construct config file path");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudMakeConfigPath(server->networkAutostartDir, def->name, ".xml",
|
if (qemudMakeConfigPath(driver->networkAutostartDir, def->name, ".xml",
|
||||||
network->autostartLink, PATH_MAX) < 0) {
|
network->autostartLink, PATH_MAX) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot construct autostart link path");
|
"cannot construct autostart link path");
|
||||||
@ -2094,7 +2125,7 @@ qemudSaveNetworkDef(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return qemudSaveNetworkConfig(server, network, def);
|
return qemudSaveNetworkConfig(driver, network, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2267,7 +2298,7 @@ checkLinkPointsTo(const char *checkLink,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct qemud_vm *
|
static struct qemud_vm *
|
||||||
qemudLoadConfig(struct qemud_server *server,
|
qemudLoadConfig(struct qemud_driver *driver,
|
||||||
const char *file,
|
const char *file,
|
||||||
const char *path,
|
const char *path,
|
||||||
const char *xml,
|
const char *xml,
|
||||||
@ -2275,7 +2306,7 @@ qemudLoadConfig(struct qemud_server *server,
|
|||||||
struct qemud_vm_def *def;
|
struct qemud_vm_def *def;
|
||||||
struct qemud_vm *vm;
|
struct qemud_vm *vm;
|
||||||
|
|
||||||
if (!(def = qemudParseVMDef(server, xml, file))) {
|
if (!(def = qemudParseVMDef(driver, xml, file))) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
qemudLog(QEMUD_WARN, "Error parsing QEMU guest config '%s' : %s",
|
qemudLog(QEMUD_WARN, "Error parsing QEMU guest config '%s' : %s",
|
||||||
path, err->message);
|
path, err->message);
|
||||||
@ -2289,7 +2320,7 @@ qemudLoadConfig(struct qemud_server *server,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(vm = qemudAssignVMDef(server, def))) {
|
if (!(vm = qemudAssignVMDef(driver, def))) {
|
||||||
qemudLog(QEMUD_WARN, "Failed to load QEMU guest config '%s': out of memory", path);
|
qemudLog(QEMUD_WARN, "Failed to load QEMU guest config '%s': out of memory", path);
|
||||||
qemudFreeVMDef(def);
|
qemudFreeVMDef(def);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -2307,7 +2338,7 @@ qemudLoadConfig(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct qemud_network *
|
static struct qemud_network *
|
||||||
qemudLoadNetworkConfig(struct qemud_server *server,
|
qemudLoadNetworkConfig(struct qemud_driver *driver,
|
||||||
const char *file,
|
const char *file,
|
||||||
const char *path,
|
const char *path,
|
||||||
const char *xml,
|
const char *xml,
|
||||||
@ -2315,7 +2346,7 @@ qemudLoadNetworkConfig(struct qemud_server *server,
|
|||||||
struct qemud_network_def *def;
|
struct qemud_network_def *def;
|
||||||
struct qemud_network *network;
|
struct qemud_network *network;
|
||||||
|
|
||||||
if (!(def = qemudParseNetworkDef(server, xml, file))) {
|
if (!(def = qemudParseNetworkDef(driver, xml, file))) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
qemudLog(QEMUD_WARN, "Error parsing network config '%s' : %s",
|
qemudLog(QEMUD_WARN, "Error parsing network config '%s' : %s",
|
||||||
path, err->message);
|
path, err->message);
|
||||||
@ -2329,7 +2360,7 @@ qemudLoadNetworkConfig(struct qemud_server *server,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(network = qemudAssignNetworkDef(server, def))) {
|
if (!(network = qemudAssignNetworkDef(driver, def))) {
|
||||||
qemudLog(QEMUD_WARN, "Failed to load network config '%s': out of memory", path);
|
qemudLog(QEMUD_WARN, "Failed to load network config '%s': out of memory", path);
|
||||||
qemudFreeNetworkDef(def);
|
qemudFreeNetworkDef(def);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -2347,7 +2378,7 @@ qemudLoadNetworkConfig(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int qemudScanConfigDir(struct qemud_server *server,
|
int qemudScanConfigDir(struct qemud_driver *driver,
|
||||||
const char *configDir,
|
const char *configDir,
|
||||||
const char *autostartDir,
|
const char *autostartDir,
|
||||||
int isGuest) {
|
int isGuest) {
|
||||||
@ -2389,9 +2420,9 @@ int qemudScanConfigDir(struct qemud_server *server,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (isGuest)
|
if (isGuest)
|
||||||
qemudLoadConfig(server, entry->d_name, path, xml, autostartLink);
|
qemudLoadConfig(driver, entry->d_name, path, xml, autostartLink);
|
||||||
else
|
else
|
||||||
qemudLoadNetworkConfig(server, entry->d_name, path, xml, autostartLink);
|
qemudLoadNetworkConfig(driver, entry->d_name, path, xml, autostartLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
@ -2399,57 +2430,19 @@ int qemudScanConfigDir(struct qemud_server *server,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
void qemudAutostartConfigs(struct qemud_server *server) {
|
|
||||||
struct qemud_network *network;
|
|
||||||
struct qemud_vm *vm;
|
|
||||||
|
|
||||||
network = server->networks;
|
|
||||||
while (network != NULL) {
|
|
||||||
struct qemud_network *next = network->next;
|
|
||||||
|
|
||||||
if (network->autostart &&
|
|
||||||
!qemudIsActiveNetwork(network) &&
|
|
||||||
qemudStartNetworkDaemon(server, network) < 0) {
|
|
||||||
virErrorPtr err = virGetLastError();
|
|
||||||
qemudLog(QEMUD_ERR, "Failed to autostart network '%s': %s",
|
|
||||||
network->def->name, err->message);
|
|
||||||
}
|
|
||||||
|
|
||||||
network = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
vm = server->vms;
|
|
||||||
while (vm != NULL) {
|
|
||||||
struct qemud_vm *next = vm->next;
|
|
||||||
|
|
||||||
if (vm->autostart &&
|
|
||||||
!qemudIsActiveVM(vm) &&
|
|
||||||
qemudStartVMDaemon(server, vm) < 0) {
|
|
||||||
virErrorPtr err = virGetLastError();
|
|
||||||
qemudLog(QEMUD_ERR, "Failed to autostart VM '%s': %s",
|
|
||||||
vm->def->name, err->message);
|
|
||||||
}
|
|
||||||
|
|
||||||
vm = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Scan for all guest and network config files */
|
/* Scan for all guest and network config files */
|
||||||
int qemudScanConfigs(struct qemud_server *server) {
|
int qemudScanConfigs(struct qemud_driver *driver) {
|
||||||
if (qemudScanConfigDir(server, server->configDir, server->autostartDir, 1) < 0)
|
if (qemudScanConfigDir(driver, driver->configDir, driver->autostartDir, 1) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (qemudScanConfigDir(server, server->networkConfigDir, server->networkAutostartDir, 0) < 0)
|
if (qemudScanConfigDir(driver, driver->networkConfigDir, driver->networkAutostartDir, 0) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
qemudAutostartConfigs(server);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate an XML document describing the guest's configuration */
|
/* Generate an XML document describing the guest's configuration */
|
||||||
char *qemudGenerateXML(struct qemud_server *server,
|
char *qemudGenerateXML(struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
struct qemud_vm_def *def,
|
struct qemud_vm_def *def,
|
||||||
int live) {
|
int live) {
|
||||||
@ -2727,7 +2720,7 @@ char *qemudGenerateXML(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *qemudGenerateNetworkXML(struct qemud_server *server,
|
char *qemudGenerateNetworkXML(struct qemud_driver *driver,
|
||||||
struct qemud_network *network,
|
struct qemud_network *network,
|
||||||
struct qemud_network_def *def) {
|
struct qemud_network_def *def) {
|
||||||
bufferPtr buf = 0;
|
bufferPtr buf = 0;
|
||||||
@ -2818,7 +2811,7 @@ char *qemudGenerateNetworkXML(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int qemudDeleteConfig(struct qemud_server *server,
|
int qemudDeleteConfig(struct qemud_driver *driver,
|
||||||
const char *configFile,
|
const char *configFile,
|
||||||
const char *name) {
|
const char *name) {
|
||||||
if (!configFile[0]) {
|
if (!configFile[0]) {
|
||||||
|
292
qemud/conf.h
292
qemud/conf.h
@ -24,15 +24,277 @@
|
|||||||
#ifndef __QEMUD_CONF_H
|
#ifndef __QEMUD_CONF_H
|
||||||
#define __QEMUD_CONF_H
|
#define __QEMUD_CONF_H
|
||||||
|
|
||||||
#include "internal.h"
|
/* Different types of QEMU acceleration possible */
|
||||||
|
enum qemud_vm_virt_type {
|
||||||
|
QEMUD_VIRT_QEMU,
|
||||||
|
QEMUD_VIRT_KQEMU,
|
||||||
|
QEMUD_VIRT_KVM,
|
||||||
|
};
|
||||||
|
|
||||||
int qemudExtractVersion (struct qemud_server *server);
|
|
||||||
int qemudBuildCommandLine (struct qemud_server *server,
|
/* Two types of disk backends */
|
||||||
|
enum qemud_vm_disk_type {
|
||||||
|
QEMUD_DISK_BLOCK,
|
||||||
|
QEMUD_DISK_FILE
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Three types of disk frontend */
|
||||||
|
enum qemud_vm_disk_device {
|
||||||
|
QEMUD_DISK_DISK,
|
||||||
|
QEMUD_DISK_CDROM,
|
||||||
|
QEMUD_DISK_FLOPPY,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Stores the virtual disk configuration */
|
||||||
|
struct qemud_vm_disk_def {
|
||||||
|
int type;
|
||||||
|
int device;
|
||||||
|
char src[PATH_MAX];
|
||||||
|
char dst[NAME_MAX];
|
||||||
|
int readonly;
|
||||||
|
|
||||||
|
struct qemud_vm_disk_def *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define QEMUD_MAC_ADDRESS_LEN 6
|
||||||
|
#define QEMUD_OS_TYPE_MAX_LEN 10
|
||||||
|
#define QEMUD_OS_ARCH_MAX_LEN 10
|
||||||
|
#define QEMUD_OS_MACHINE_MAX_LEN 10
|
||||||
|
|
||||||
|
/* 5 different types of networking config */
|
||||||
|
enum qemud_vm_net_type {
|
||||||
|
QEMUD_NET_USER,
|
||||||
|
QEMUD_NET_ETHERNET,
|
||||||
|
QEMUD_NET_SERVER,
|
||||||
|
QEMUD_NET_CLIENT,
|
||||||
|
QEMUD_NET_MCAST,
|
||||||
|
QEMUD_NET_NETWORK,
|
||||||
|
QEMUD_NET_BRIDGE,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Stores the virtual network interface configuration */
|
||||||
|
struct qemud_vm_net_def {
|
||||||
|
int type;
|
||||||
|
unsigned char mac[QEMUD_MAC_ADDRESS_LEN];
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
char ifname[BR_IFNAME_MAXLEN];
|
||||||
|
char script[PATH_MAX];
|
||||||
|
} ethernet;
|
||||||
|
struct {
|
||||||
|
char address[BR_INET_ADDR_MAXLEN];
|
||||||
|
int port;
|
||||||
|
} socket; /* any of NET_CLIENT or NET_SERVER or NET_MCAST */
|
||||||
|
struct {
|
||||||
|
char name[QEMUD_MAX_NAME_LEN];
|
||||||
|
char ifname[BR_IFNAME_MAXLEN];
|
||||||
|
} network;
|
||||||
|
struct {
|
||||||
|
char brname[BR_IFNAME_MAXLEN];
|
||||||
|
char ifname[BR_IFNAME_MAXLEN];
|
||||||
|
} bridge;
|
||||||
|
} dst;
|
||||||
|
|
||||||
|
struct qemud_vm_net_def *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define QEMUD_MAX_BOOT_DEVS 4
|
||||||
|
|
||||||
|
/* 3 possible boot devices */
|
||||||
|
enum qemud_vm_boot_order {
|
||||||
|
QEMUD_BOOT_FLOPPY,
|
||||||
|
QEMUD_BOOT_CDROM,
|
||||||
|
QEMUD_BOOT_DISK,
|
||||||
|
QEMUD_BOOT_NET,
|
||||||
|
};
|
||||||
|
/* 3 possible graphics console modes */
|
||||||
|
enum qemud_vm_grapics_type {
|
||||||
|
QEMUD_GRAPHICS_NONE,
|
||||||
|
QEMUD_GRAPHICS_SDL,
|
||||||
|
QEMUD_GRAPHICS_VNC,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Internal flags to keep track of qemu command line capabilities */
|
||||||
|
enum qemud_cmd_flags {
|
||||||
|
QEMUD_CMD_FLAG_KQEMU = 1,
|
||||||
|
QEMUD_CMD_FLAG_VNC_COLON = 2,
|
||||||
|
QEMUD_CMD_FLAG_NO_REBOOT = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum qemud_vm_features {
|
||||||
|
QEMUD_FEATURE_ACPI = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Operating system configuration data & machine / arch */
|
||||||
|
struct qemud_vm_os_def {
|
||||||
|
char type[QEMUD_OS_TYPE_MAX_LEN];
|
||||||
|
char arch[QEMUD_OS_ARCH_MAX_LEN];
|
||||||
|
char machine[QEMUD_OS_MACHINE_MAX_LEN];
|
||||||
|
int nBootDevs;
|
||||||
|
int bootDevs[QEMUD_MAX_BOOT_DEVS];
|
||||||
|
char kernel[PATH_MAX];
|
||||||
|
char initrd[PATH_MAX];
|
||||||
|
char cmdline[PATH_MAX];
|
||||||
|
char binary[PATH_MAX];
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Guest VM main configuration */
|
||||||
|
struct qemud_vm_def {
|
||||||
|
int virtType;
|
||||||
|
unsigned char uuid[QEMUD_UUID_RAW_LEN];
|
||||||
|
char name[QEMUD_MAX_NAME_LEN];
|
||||||
|
|
||||||
|
int memory;
|
||||||
|
int maxmem;
|
||||||
|
int vcpus;
|
||||||
|
|
||||||
|
int noReboot;
|
||||||
|
|
||||||
|
struct qemud_vm_os_def os;
|
||||||
|
|
||||||
|
int features;
|
||||||
|
int graphicsType;
|
||||||
|
int vncPort;
|
||||||
|
int vncActivePort;
|
||||||
|
|
||||||
|
int ndisks;
|
||||||
|
struct qemud_vm_disk_def *disks;
|
||||||
|
|
||||||
|
int nnets;
|
||||||
|
struct qemud_vm_net_def *nets;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Guest VM runtime state */
|
||||||
|
struct qemud_vm {
|
||||||
|
int stdout;
|
||||||
|
int stderr;
|
||||||
|
int monitor;
|
||||||
|
int logfile;
|
||||||
|
int pid;
|
||||||
|
int id;
|
||||||
|
int state;
|
||||||
|
|
||||||
|
int *tapfds;
|
||||||
|
int ntapfds;
|
||||||
|
|
||||||
|
char configFile[PATH_MAX];
|
||||||
|
char autostartLink[PATH_MAX];
|
||||||
|
|
||||||
|
struct qemud_vm_def *def; /* The current definition */
|
||||||
|
struct qemud_vm_def *newDef; /* New definition to activate at shutdown */
|
||||||
|
|
||||||
|
unsigned int autostart : 1;
|
||||||
|
|
||||||
|
struct qemud_vm *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Store start and end addresses of a dhcp range */
|
||||||
|
struct qemud_dhcp_range_def {
|
||||||
|
char start[BR_INET_ADDR_MAXLEN];
|
||||||
|
char end[BR_INET_ADDR_MAXLEN];
|
||||||
|
|
||||||
|
struct qemud_dhcp_range_def *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Virtual Network main configuration */
|
||||||
|
struct qemud_network_def {
|
||||||
|
unsigned char uuid[QEMUD_UUID_RAW_LEN];
|
||||||
|
char name[QEMUD_MAX_NAME_LEN];
|
||||||
|
|
||||||
|
char bridge[BR_IFNAME_MAXLEN];
|
||||||
|
int disableSTP;
|
||||||
|
int forwardDelay;
|
||||||
|
|
||||||
|
int forward;
|
||||||
|
char forwardDev[BR_IFNAME_MAXLEN];
|
||||||
|
|
||||||
|
char ipAddress[BR_INET_ADDR_MAXLEN];
|
||||||
|
char netmask[BR_INET_ADDR_MAXLEN];
|
||||||
|
char network[BR_INET_ADDR_MAXLEN+BR_INET_ADDR_MAXLEN+1];
|
||||||
|
|
||||||
|
int nranges;
|
||||||
|
struct qemud_dhcp_range_def *ranges;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Virtual Network runtime state */
|
||||||
|
struct qemud_network {
|
||||||
|
char configFile[PATH_MAX];
|
||||||
|
char autostartLink[PATH_MAX];
|
||||||
|
|
||||||
|
struct qemud_network_def *def; /* The current definition */
|
||||||
|
struct qemud_network_def *newDef; /* New definition to activate at shutdown */
|
||||||
|
|
||||||
|
char bridge[BR_IFNAME_MAXLEN];
|
||||||
|
int dnsmasqPid;
|
||||||
|
|
||||||
|
unsigned int active : 1;
|
||||||
|
unsigned int autostart : 1;
|
||||||
|
|
||||||
|
struct qemud_network *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Main driver state */
|
||||||
|
struct qemud_driver {
|
||||||
|
int qemuVersion;
|
||||||
|
int qemuCmdFlags; /* values from enum qemud_cmd_flags */
|
||||||
|
int nactivevms;
|
||||||
|
int ninactivevms;
|
||||||
|
struct qemud_vm *vms;
|
||||||
|
int nextvmid;
|
||||||
|
int nactivenetworks;
|
||||||
|
int ninactivenetworks;
|
||||||
|
struct qemud_network *networks;
|
||||||
|
brControl *brctl;
|
||||||
|
iptablesContext *iptables;
|
||||||
|
char *configDir;
|
||||||
|
char *autostartDir;
|
||||||
|
char *networkConfigDir;
|
||||||
|
char *networkAutostartDir;
|
||||||
|
char logDir[PATH_MAX];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
qemudIsActiveVM(struct qemud_vm *vm)
|
||||||
|
{
|
||||||
|
return vm->id != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
qemudIsActiveNetwork(struct qemud_network *network)
|
||||||
|
{
|
||||||
|
return network->active;
|
||||||
|
}
|
||||||
|
|
||||||
|
void qemudReportError(virConnectPtr conn,
|
||||||
|
virDomainPtr dom,
|
||||||
|
virNetworkPtr net,
|
||||||
|
int code, const char *fmt, ...)
|
||||||
|
ATTRIBUTE_FORMAT(printf,5,6);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver,
|
||||||
|
int id);
|
||||||
|
struct qemud_vm *qemudFindVMByUUID(const struct qemud_driver *driver,
|
||||||
|
const unsigned char *uuid);
|
||||||
|
struct qemud_vm *qemudFindVMByName(const struct qemud_driver *driver,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
|
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_driver *driver,
|
||||||
|
const unsigned char *uuid);
|
||||||
|
struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
|
int qemudExtractVersion (struct qemud_driver *driver);
|
||||||
|
int qemudBuildCommandLine (struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
char ***argv);
|
char ***argv);
|
||||||
|
|
||||||
int qemudScanConfigs (struct qemud_server *server);
|
int qemudScanConfigs (struct qemud_driver *driver);
|
||||||
int qemudDeleteConfig (struct qemud_server *server,
|
int qemudDeleteConfig (struct qemud_driver *driver,
|
||||||
const char *configFile,
|
const char *configFile,
|
||||||
const char *name);
|
const char *name);
|
||||||
int qemudEnsureDir (const char *path);
|
int qemudEnsureDir (const char *path);
|
||||||
@ -41,19 +303,19 @@ void qemudFreeVMDef (struct qemud_vm_def *vm);
|
|||||||
void qemudFreeVM (struct qemud_vm *vm);
|
void qemudFreeVM (struct qemud_vm *vm);
|
||||||
|
|
||||||
struct qemud_vm *
|
struct qemud_vm *
|
||||||
qemudAssignVMDef (struct qemud_server *server,
|
qemudAssignVMDef (struct qemud_driver *driver,
|
||||||
struct qemud_vm_def *def);
|
struct qemud_vm_def *def);
|
||||||
void qemudRemoveInactiveVM (struct qemud_server *server,
|
void qemudRemoveInactiveVM (struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm);
|
struct qemud_vm *vm);
|
||||||
|
|
||||||
struct qemud_vm_def *
|
struct qemud_vm_def *
|
||||||
qemudParseVMDef (struct qemud_server *server,
|
qemudParseVMDef (struct qemud_driver *driver,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
const char *displayName);
|
const char *displayName);
|
||||||
int qemudSaveVMDef (struct qemud_server *server,
|
int qemudSaveVMDef (struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
struct qemud_vm_def *def);
|
struct qemud_vm_def *def);
|
||||||
char * qemudGenerateXML (struct qemud_server *server,
|
char * qemudGenerateXML (struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
struct qemud_vm_def *def,
|
struct qemud_vm_def *def,
|
||||||
int live);
|
int live);
|
||||||
@ -62,19 +324,19 @@ void qemudFreeNetworkDef (struct qemud_network_def *def);
|
|||||||
void qemudFreeNetwork (struct qemud_network *network);
|
void qemudFreeNetwork (struct qemud_network *network);
|
||||||
|
|
||||||
struct qemud_network *
|
struct qemud_network *
|
||||||
qemudAssignNetworkDef (struct qemud_server *server,
|
qemudAssignNetworkDef (struct qemud_driver *driver,
|
||||||
struct qemud_network_def *def);
|
struct qemud_network_def *def);
|
||||||
void qemudRemoveInactiveNetwork (struct qemud_server *server,
|
void qemudRemoveInactiveNetwork (struct qemud_driver *driver,
|
||||||
struct qemud_network *network);
|
struct qemud_network *network);
|
||||||
|
|
||||||
struct qemud_network_def *
|
struct qemud_network_def *
|
||||||
qemudParseNetworkDef (struct qemud_server *server,
|
qemudParseNetworkDef (struct qemud_driver *driver,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
const char *displayName);
|
const char *displayName);
|
||||||
int qemudSaveNetworkDef (struct qemud_server *server,
|
int qemudSaveNetworkDef (struct qemud_driver *driver,
|
||||||
struct qemud_network *network,
|
struct qemud_network *network,
|
||||||
struct qemud_network_def *def);
|
struct qemud_network_def *def);
|
||||||
char * qemudGenerateNetworkXML (struct qemud_server *server,
|
char * qemudGenerateNetworkXML (struct qemud_driver *driver,
|
||||||
struct qemud_network *network,
|
struct qemud_network *network,
|
||||||
struct qemud_network_def *def);
|
struct qemud_network_def *def);
|
||||||
|
|
||||||
|
281
qemud/dispatch.c
281
qemud/dispatch.c
@ -34,11 +34,10 @@
|
|||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "dispatch.h"
|
#include "dispatch.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
extern struct qemud_driver *qemu_driver;
|
||||||
|
|
||||||
|
|
||||||
static int qemudDispatchFailure(struct qemud_server *server ATTRIBUTE_UNUSED,
|
static int qemudDispatchFailure(struct qemud_packet_server_data *out) {
|
||||||
struct qemud_client *client ATTRIBUTE_UNUSED,
|
|
||||||
struct qemud_packet_server_data *out) {
|
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
|
|
||||||
out->type = QEMUD_SERVER_PKT_FAILURE;
|
out->type = QEMUD_SERVER_PKT_FAILURE;
|
||||||
@ -51,11 +50,10 @@ static int qemudDispatchFailure(struct qemud_server *server ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int qemudDispatchGetVersion(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchGetVersion(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
int version = qemudGetVersion(qemu_driver);
|
||||||
int version = qemudGetVersion(server);
|
|
||||||
if (version < 0) {
|
if (version < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_GET_VERSION;
|
out->type = QEMUD_SERVER_PKT_GET_VERSION;
|
||||||
@ -64,8 +62,7 @@ static int qemudDispatchGetVersion(struct qemud_server *server, struct qemud_cli
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchGetNodeInfo(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchGetNodeInfo(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
|
||||||
if (qemudGetNodeInfo(&out->qemud_packet_server_data_u.getNodeInfoReply.memory,
|
if (qemudGetNodeInfo(&out->qemud_packet_server_data_u.getNodeInfoReply.memory,
|
||||||
out->qemud_packet_server_data_u.getNodeInfoReply.model,
|
out->qemud_packet_server_data_u.getNodeInfoReply.model,
|
||||||
sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model),
|
sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model),
|
||||||
@ -75,7 +72,7 @@ static int qemudDispatchGetNodeInfo(struct qemud_server *server, struct qemud_cl
|
|||||||
&out->qemud_packet_server_data_u.getNodeInfoReply.sockets,
|
&out->qemud_packet_server_data_u.getNodeInfoReply.sockets,
|
||||||
&out->qemud_packet_server_data_u.getNodeInfoReply.cores,
|
&out->qemud_packet_server_data_u.getNodeInfoReply.cores,
|
||||||
&out->qemud_packet_server_data_u.getNodeInfoReply.threads) < 0) {
|
&out->qemud_packet_server_data_u.getNodeInfoReply.threads) < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -87,16 +84,14 @@ static int qemudDispatchGetNodeInfo(struct qemud_server *server, struct qemud_cl
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemudDispatchGetCapabilities (struct qemud_server *server,
|
qemudDispatchGetCapabilities (struct qemud_packet_client_data *in ATTRIBUTE_UNUSED,
|
||||||
struct qemud_client *client,
|
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED,
|
|
||||||
struct qemud_packet_server_data *out)
|
struct qemud_packet_server_data *out)
|
||||||
{
|
{
|
||||||
char *xml = qemudGetCapabilities(server);
|
char *xml = qemudGetCapabilities(qemu_driver);
|
||||||
|
|
||||||
if (strlen(xml) > QEMUD_MAX_XML_LEN) {
|
if (strlen(xml) > QEMUD_MAX_XML_LEN) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
|
||||||
qemudDispatchFailure (server, client, out);
|
qemudDispatchFailure(out);
|
||||||
free(xml);
|
free(xml);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -107,15 +102,14 @@ qemudDispatchGetCapabilities (struct qemud_server *server,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchListDomains(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchListDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
|
||||||
int i, ndomains, domains[QEMUD_MAX_NUM_DOMAINS];
|
int i, ndomains, domains[QEMUD_MAX_NUM_DOMAINS];
|
||||||
|
|
||||||
ndomains = qemudListDomains(server,
|
ndomains = qemudListDomains(qemu_driver,
|
||||||
domains,
|
domains,
|
||||||
QEMUD_MAX_NUM_DOMAINS);
|
QEMUD_MAX_NUM_DOMAINS);
|
||||||
if (ndomains < 0) {
|
if (ndomains < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_LIST_DOMAINS;
|
out->type = QEMUD_SERVER_PKT_LIST_DOMAINS;
|
||||||
@ -127,11 +121,10 @@ static int qemudDispatchListDomains(struct qemud_server *server, struct qemud_cl
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNumDomains(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNumDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
int ndomains = qemudNumDomains(qemu_driver);
|
||||||
int ndomains = qemudNumDomains(server);
|
|
||||||
if (ndomains < 0) {
|
if (ndomains < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NUM_DOMAINS;
|
out->type = QEMUD_SERVER_PKT_NUM_DOMAINS;
|
||||||
@ -140,13 +133,12 @@ static int qemudDispatchNumDomains(struct qemud_server *server, struct qemud_cli
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainCreate(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainCreate(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
in->qemud_packet_client_data_u.domainCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
in->qemud_packet_client_data_u.domainCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
||||||
|
|
||||||
struct qemud_vm *vm = qemudDomainCreate(server, in->qemud_packet_client_data_u.domainCreateRequest.xml);
|
struct qemud_vm *vm = qemudDomainCreate(qemu_driver, in->qemud_packet_client_data_u.domainCreateRequest.xml);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_CREATE;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_CREATE;
|
||||||
@ -158,11 +150,10 @@ static int qemudDispatchDomainCreate(struct qemud_server *server, struct qemud_c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainLookupByID(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainLookupByID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
struct qemud_vm *vm = qemudFindVMByID(qemu_driver, in->qemud_packet_client_data_u.domainLookupByIDRequest.id);
|
||||||
struct qemud_vm *vm = qemudFindVMByID(server, in->qemud_packet_client_data_u.domainLookupByIDRequest.id);
|
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_ID;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_ID;
|
||||||
@ -173,11 +164,10 @@ static int qemudDispatchDomainLookupByID(struct qemud_server *server, struct qem
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainLookupByUUID(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainLookupByUUID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
struct qemud_vm *vm = qemudFindVMByUUID(qemu_driver, in->qemud_packet_client_data_u.domainLookupByUUIDRequest.uuid);
|
||||||
struct qemud_vm *vm = qemudFindVMByUUID(server, in->qemud_packet_client_data_u.domainLookupByUUIDRequest.uuid);
|
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_UUID;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_UUID;
|
||||||
@ -188,13 +178,12 @@ static int qemudDispatchDomainLookupByUUID(struct qemud_server *server, struct q
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainLookupByName(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainLookupByName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
/* Paranoia NULL termination */
|
/* Paranoia NULL termination */
|
||||||
in->qemud_packet_client_data_u.domainLookupByNameRequest.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
in->qemud_packet_client_data_u.domainLookupByNameRequest.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
struct qemud_vm *vm = qemudFindVMByName(server, in->qemud_packet_client_data_u.domainLookupByNameRequest.name);
|
struct qemud_vm *vm = qemudFindVMByName(qemu_driver, in->qemud_packet_client_data_u.domainLookupByNameRequest.name);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_NAME;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_NAME;
|
||||||
@ -204,11 +193,10 @@ static int qemudDispatchDomainLookupByName(struct qemud_server *server, struct q
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainSuspend(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainSuspend(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
int ret = qemudDomainSuspend(qemu_driver, in->qemud_packet_client_data_u.domainSuspendRequest.id);
|
||||||
int ret = qemudDomainSuspend(server, in->qemud_packet_client_data_u.domainSuspendRequest.id);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_SUSPEND;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_SUSPEND;
|
||||||
@ -216,11 +204,10 @@ static int qemudDispatchDomainSuspend(struct qemud_server *server, struct qemud_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainResume(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainResume(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
int ret = qemudDomainResume(qemu_driver, in->qemud_packet_client_data_u.domainResumeRequest.id);
|
||||||
int ret = qemudDomainResume(server, in->qemud_packet_client_data_u.domainResumeRequest.id);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_RESUME;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_RESUME;
|
||||||
@ -228,10 +215,9 @@ static int qemudDispatchDomainResume(struct qemud_server *server, struct qemud_c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainDestroy(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainDestroy(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
if (qemudDomainDestroy(qemu_driver, in->qemud_packet_client_data_u.domainDestroyRequest.id) < 0) {
|
||||||
if (qemudDomainDestroy(server, in->qemud_packet_client_data_u.domainDestroyRequest.id) < 0) {
|
if (qemudDispatchFailure(out) < 0)
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_DESTROY;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_DESTROY;
|
||||||
@ -239,22 +225,21 @@ static int qemudDispatchDomainDestroy(struct qemud_server *server, struct qemud_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainGetInfo(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainGetInfo(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
int runstate;
|
int runstate;
|
||||||
unsigned long long cpuTime;
|
unsigned long long cpuTime;
|
||||||
unsigned long memory;
|
unsigned long memory;
|
||||||
unsigned long maxmem;
|
unsigned long maxmem;
|
||||||
unsigned int nrVirtCpu;
|
unsigned int nrVirtCpu;
|
||||||
|
|
||||||
int ret = qemudDomainGetInfo(server, in->qemud_packet_client_data_u.domainGetInfoRequest.uuid,
|
int ret = qemudDomainGetInfo(qemu_driver, in->qemud_packet_client_data_u.domainGetInfoRequest.uuid,
|
||||||
&runstate,
|
&runstate,
|
||||||
&cpuTime,
|
&cpuTime,
|
||||||
&maxmem,
|
&maxmem,
|
||||||
&memory,
|
&memory,
|
||||||
&nrVirtCpu);
|
&nrVirtCpu);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_GET_INFO;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_GET_INFO;
|
||||||
@ -267,16 +252,15 @@ static int qemudDispatchDomainGetInfo(struct qemud_server *server, struct qemud_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainSave(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainSave(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
/* Paranoia NULL termination */
|
/* Paranoia NULL termination */
|
||||||
in->qemud_packet_client_data_u.domainSaveRequest.file[PATH_MAX-1] ='\0';
|
in->qemud_packet_client_data_u.domainSaveRequest.file[PATH_MAX-1] ='\0';
|
||||||
|
|
||||||
int ret = qemudDomainSave(server,
|
int ret = qemudDomainSave(qemu_driver,
|
||||||
in->qemud_packet_client_data_u.domainSaveRequest.id,
|
in->qemud_packet_client_data_u.domainSaveRequest.id,
|
||||||
in->qemud_packet_client_data_u.domainSaveRequest.file);
|
in->qemud_packet_client_data_u.domainSaveRequest.file);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_SAVE;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_SAVE;
|
||||||
@ -284,16 +268,15 @@ static int qemudDispatchDomainSave(struct qemud_server *server, struct qemud_cli
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainRestore(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainRestore(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
/* Paranoia null termination */
|
/* Paranoia null termination */
|
||||||
in->qemud_packet_client_data_u.domainRestoreRequest.file[PATH_MAX-1] ='\0';
|
in->qemud_packet_client_data_u.domainRestoreRequest.file[PATH_MAX-1] ='\0';
|
||||||
|
|
||||||
id = qemudDomainRestore(server, in->qemud_packet_client_data_u.domainRestoreRequest.file);
|
id = qemudDomainRestore(qemu_driver, in->qemud_packet_client_data_u.domainRestoreRequest.file);
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_RESTORE;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_RESTORE;
|
||||||
@ -302,15 +285,14 @@ static int qemudDispatchDomainRestore(struct qemud_server *server, struct qemud_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDumpXML(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDumpXML(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
int ret;
|
int ret;
|
||||||
ret = qemudDomainDumpXML(server,
|
ret = qemudDomainDumpXML(qemu_driver,
|
||||||
in->qemud_packet_client_data_u.domainDumpXMLRequest.uuid,
|
in->qemud_packet_client_data_u.domainDumpXMLRequest.uuid,
|
||||||
out->qemud_packet_server_data_u.domainDumpXMLReply.xml,
|
out->qemud_packet_server_data_u.domainDumpXMLReply.xml,
|
||||||
QEMUD_MAX_XML_LEN);
|
QEMUD_MAX_XML_LEN);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DUMP_XML;
|
out->type = QEMUD_SERVER_PKT_DUMP_XML;
|
||||||
@ -318,8 +300,7 @@ static int qemudDispatchDumpXML(struct qemud_server *server, struct qemud_client
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchListDefinedDomains(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchListDefinedDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
|
||||||
char **names;
|
char **names;
|
||||||
int i, ndomains;
|
int i, ndomains;
|
||||||
|
|
||||||
@ -330,12 +311,12 @@ static int qemudDispatchListDefinedDomains(struct qemud_server *server, struct q
|
|||||||
names[i] = &out->qemud_packet_server_data_u.listDefinedDomainsReply.domains[i*QEMUD_MAX_NAME_LEN];
|
names[i] = &out->qemud_packet_server_data_u.listDefinedDomainsReply.domains[i*QEMUD_MAX_NAME_LEN];
|
||||||
}
|
}
|
||||||
|
|
||||||
ndomains = qemudListDefinedDomains(server,
|
ndomains = qemudListDefinedDomains(qemu_driver,
|
||||||
names,
|
names,
|
||||||
QEMUD_MAX_NUM_DOMAINS);
|
QEMUD_MAX_NUM_DOMAINS);
|
||||||
free(names);
|
free(names);
|
||||||
if (ndomains < 0) {
|
if (ndomains < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_LIST_DEFINED_DOMAINS;
|
out->type = QEMUD_SERVER_PKT_LIST_DEFINED_DOMAINS;
|
||||||
@ -348,11 +329,10 @@ static int qemudDispatchListDefinedDomains(struct qemud_server *server, struct q
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNumDefinedDomains(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNumDefinedDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
int ndomains = qemudNumDefinedDomains(qemu_driver);
|
||||||
int ndomains = qemudNumDefinedDomains(server);
|
|
||||||
if (ndomains < 0) {
|
if (ndomains < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NUM_DEFINED_DOMAINS;
|
out->type = QEMUD_SERVER_PKT_NUM_DEFINED_DOMAINS;
|
||||||
@ -361,12 +341,11 @@ static int qemudDispatchNumDefinedDomains(struct qemud_server *server, struct qe
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainStart(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainStart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
struct qemud_vm *vm;
|
struct qemud_vm *vm;
|
||||||
|
|
||||||
if (!(vm = qemudDomainStart(server, in->qemud_packet_client_data_u.domainStartRequest.uuid))) {
|
if (!(vm = qemudDomainStart(qemu_driver, in->qemud_packet_client_data_u.domainStartRequest.uuid))) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_START;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_START;
|
||||||
@ -375,13 +354,12 @@ static int qemudDispatchDomainStart(struct qemud_server *server, struct qemud_cl
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainDefine(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainDefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
in->qemud_packet_client_data_u.domainDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
in->qemud_packet_client_data_u.domainDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
||||||
|
|
||||||
struct qemud_vm *vm = qemudDomainDefine(server, in->qemud_packet_client_data_u.domainDefineRequest.xml);
|
struct qemud_vm *vm = qemudDomainDefine(qemu_driver, in->qemud_packet_client_data_u.domainDefineRequest.xml);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_DEFINE;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_DEFINE;
|
||||||
@ -392,11 +370,10 @@ static int qemudDispatchDomainDefine(struct qemud_server *server, struct qemud_c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainUndefine(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainUndefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
int ret = qemudDomainUndefine(qemu_driver, in->qemud_packet_client_data_u.domainUndefineRequest.uuid);
|
||||||
int ret = qemudDomainUndefine(server, in->qemud_packet_client_data_u.domainUndefineRequest.uuid);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_UNDEFINE;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_UNDEFINE;
|
||||||
@ -404,11 +381,10 @@ static int qemudDispatchDomainUndefine(struct qemud_server *server, struct qemud
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNumNetworks(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNumNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
int nnetworks = qemudNumNetworks(qemu_driver);
|
||||||
int nnetworks = qemudNumNetworks(server);
|
|
||||||
if (nnetworks < 0) {
|
if (nnetworks < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NUM_NETWORKS;
|
out->type = QEMUD_SERVER_PKT_NUM_NETWORKS;
|
||||||
@ -417,8 +393,7 @@ static int qemudDispatchNumNetworks(struct qemud_server *server, struct qemud_cl
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchListNetworks(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchListNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
|
||||||
char **names;
|
char **names;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -429,12 +404,12 @@ static int qemudDispatchListNetworks(struct qemud_server *server, struct qemud_c
|
|||||||
names[i] = &out->qemud_packet_server_data_u.listNetworksReply.networks[i*QEMUD_MAX_NAME_LEN];
|
names[i] = &out->qemud_packet_server_data_u.listNetworksReply.networks[i*QEMUD_MAX_NAME_LEN];
|
||||||
}
|
}
|
||||||
|
|
||||||
int nnetworks = qemudListNetworks(server,
|
int nnetworks = qemudListNetworks(qemu_driver,
|
||||||
names,
|
names,
|
||||||
QEMUD_MAX_NUM_NETWORKS);
|
QEMUD_MAX_NUM_NETWORKS);
|
||||||
free(names);
|
free(names);
|
||||||
if (nnetworks < 0) {
|
if (nnetworks < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_LIST_NETWORKS;
|
out->type = QEMUD_SERVER_PKT_LIST_NETWORKS;
|
||||||
@ -443,11 +418,10 @@ static int qemudDispatchListNetworks(struct qemud_server *server, struct qemud_c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNumDefinedNetworks(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNumDefinedNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
int nnetworks = qemudNumDefinedNetworks(qemu_driver);
|
||||||
int nnetworks = qemudNumDefinedNetworks(server);
|
|
||||||
if (nnetworks < 0) {
|
if (nnetworks < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NUM_DEFINED_NETWORKS;
|
out->type = QEMUD_SERVER_PKT_NUM_DEFINED_NETWORKS;
|
||||||
@ -456,8 +430,7 @@ static int qemudDispatchNumDefinedNetworks(struct qemud_server *server, struct q
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchListDefinedNetworks(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchListDefinedNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
|
||||||
char **names;
|
char **names;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -468,12 +441,12 @@ static int qemudDispatchListDefinedNetworks(struct qemud_server *server, struct
|
|||||||
names[i] = &out->qemud_packet_server_data_u.listDefinedNetworksReply.networks[i*QEMUD_MAX_NAME_LEN];
|
names[i] = &out->qemud_packet_server_data_u.listDefinedNetworksReply.networks[i*QEMUD_MAX_NAME_LEN];
|
||||||
}
|
}
|
||||||
|
|
||||||
int nnetworks = qemudListDefinedNetworks(server,
|
int nnetworks = qemudListDefinedNetworks(qemu_driver,
|
||||||
names,
|
names,
|
||||||
QEMUD_MAX_NUM_NETWORKS);
|
QEMUD_MAX_NUM_NETWORKS);
|
||||||
free(names);
|
free(names);
|
||||||
if (nnetworks < 0) {
|
if (nnetworks < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_LIST_DEFINED_NETWORKS;
|
out->type = QEMUD_SERVER_PKT_LIST_DEFINED_NETWORKS;
|
||||||
@ -482,13 +455,12 @@ static int qemudDispatchListDefinedNetworks(struct qemud_server *server, struct
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkLookupByName(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkLookupByName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
/* Paranoia NULL termination */
|
/* Paranoia NULL termination */
|
||||||
in->qemud_packet_client_data_u.networkLookupByNameRequest.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
in->qemud_packet_client_data_u.networkLookupByNameRequest.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
struct qemud_network *network = qemudFindNetworkByName(server, in->qemud_packet_client_data_u.networkLookupByNameRequest.name);
|
struct qemud_network *network = qemudFindNetworkByName(qemu_driver, in->qemud_packet_client_data_u.networkLookupByNameRequest.name);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_LOOKUP_BY_NAME;
|
out->type = QEMUD_SERVER_PKT_NETWORK_LOOKUP_BY_NAME;
|
||||||
@ -497,11 +469,10 @@ static int qemudDispatchNetworkLookupByName(struct qemud_server *server, struct
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkLookupByUUID(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkLookupByUUID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
struct qemud_network *network = qemudFindNetworkByUUID(qemu_driver, in->qemud_packet_client_data_u.networkLookupByUUIDRequest.uuid);
|
||||||
struct qemud_network *network = qemudFindNetworkByUUID(server, in->qemud_packet_client_data_u.networkLookupByUUIDRequest.uuid);
|
|
||||||
if (!network) {
|
if (!network) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_LOOKUP_BY_UUID;
|
out->type = QEMUD_SERVER_PKT_NETWORK_LOOKUP_BY_UUID;
|
||||||
@ -511,13 +482,12 @@ static int qemudDispatchNetworkLookupByUUID(struct qemud_server *server, struct
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkCreate(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkCreate(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
in->qemud_packet_client_data_u.networkCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
in->qemud_packet_client_data_u.networkCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
||||||
|
|
||||||
struct qemud_network *network = qemudNetworkCreate(server, in->qemud_packet_client_data_u.networkCreateRequest.xml);
|
struct qemud_network *network = qemudNetworkCreate(qemu_driver, in->qemud_packet_client_data_u.networkCreateRequest.xml);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_CREATE;
|
out->type = QEMUD_SERVER_PKT_NETWORK_CREATE;
|
||||||
@ -528,13 +498,12 @@ static int qemudDispatchNetworkCreate(struct qemud_server *server, struct qemud_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkDefine(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkDefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
in->qemud_packet_client_data_u.networkDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
in->qemud_packet_client_data_u.networkDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
||||||
|
|
||||||
struct qemud_network *network = qemudNetworkDefine(server, in->qemud_packet_client_data_u.networkDefineRequest.xml);
|
struct qemud_network *network = qemudNetworkDefine(qemu_driver, in->qemud_packet_client_data_u.networkDefineRequest.xml);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_DEFINE;
|
out->type = QEMUD_SERVER_PKT_NETWORK_DEFINE;
|
||||||
@ -545,11 +514,10 @@ static int qemudDispatchNetworkDefine(struct qemud_server *server, struct qemud_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkUndefine(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkUndefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
int ret = qemudNetworkUndefine(qemu_driver, in->qemud_packet_client_data_u.networkUndefineRequest.uuid);
|
||||||
int ret = qemudNetworkUndefine(server, in->qemud_packet_client_data_u.networkUndefineRequest.uuid);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_UNDEFINE;
|
out->type = QEMUD_SERVER_PKT_NETWORK_UNDEFINE;
|
||||||
@ -557,12 +525,11 @@ static int qemudDispatchNetworkUndefine(struct qemud_server *server, struct qemu
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkStart(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkStart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
|
||||||
struct qemud_network *network;
|
struct qemud_network *network;
|
||||||
|
|
||||||
if (!(network = qemudNetworkStart(server, in->qemud_packet_client_data_u.networkStartRequest.uuid))) {
|
if (!(network = qemudNetworkStart(qemu_driver, in->qemud_packet_client_data_u.networkStartRequest.uuid))) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_START;
|
out->type = QEMUD_SERVER_PKT_NETWORK_START;
|
||||||
@ -570,10 +537,9 @@ static int qemudDispatchNetworkStart(struct qemud_server *server, struct qemud_c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkDestroy(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkDestroy(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
if (qemudNetworkDestroy(qemu_driver, in->qemud_packet_client_data_u.networkDestroyRequest.uuid) < 0) {
|
||||||
if (qemudNetworkDestroy(server, in->qemud_packet_client_data_u.networkDestroyRequest.uuid) < 0) {
|
if (qemudDispatchFailure(out) < 0)
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_DESTROY;
|
out->type = QEMUD_SERVER_PKT_NETWORK_DESTROY;
|
||||||
@ -581,13 +547,12 @@ static int qemudDispatchNetworkDestroy(struct qemud_server *server, struct qemud
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkDumpXML(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkDumpXML(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
int ret = qemudNetworkDumpXML(qemu_driver,
|
||||||
int ret = qemudNetworkDumpXML(server,
|
|
||||||
in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid,
|
in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid,
|
||||||
out->qemud_packet_server_data_u.networkDumpXMLReply.xml, QEMUD_MAX_XML_LEN);
|
out->qemud_packet_server_data_u.networkDumpXMLReply.xml, QEMUD_MAX_XML_LEN);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_DUMP_XML;
|
out->type = QEMUD_SERVER_PKT_NETWORK_DUMP_XML;
|
||||||
@ -595,13 +560,12 @@ static int qemudDispatchNetworkDumpXML(struct qemud_server *server, struct qemud
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkGetBridgeName(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkGetBridgeName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
int ret = qemudNetworkGetBridgeName(qemu_driver,
|
||||||
int ret = qemudNetworkGetBridgeName(server,
|
|
||||||
in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid,
|
in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid,
|
||||||
out->qemud_packet_server_data_u.networkGetBridgeNameReply.ifname, QEMUD_MAX_IFNAME_LEN);
|
out->qemud_packet_server_data_u.networkGetBridgeNameReply.ifname, QEMUD_MAX_IFNAME_LEN);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_GET_BRIDGE_NAME;
|
out->type = QEMUD_SERVER_PKT_NETWORK_GET_BRIDGE_NAME;
|
||||||
@ -609,19 +573,18 @@ static int qemudDispatchNetworkGetBridgeName(struct qemud_server *server, struct
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainGetAutostart(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainGetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int autostart;
|
int autostart;
|
||||||
|
|
||||||
autostart = 0;
|
autostart = 0;
|
||||||
|
|
||||||
ret = qemudDomainGetAutostart(server,
|
ret = qemudDomainGetAutostart(qemu_driver,
|
||||||
in->qemud_packet_client_data_u.domainGetAutostartRequest.uuid,
|
in->qemud_packet_client_data_u.domainGetAutostartRequest.uuid,
|
||||||
&autostart);
|
&autostart);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_GET_AUTOSTART;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_GET_AUTOSTART;
|
||||||
@ -630,16 +593,15 @@ static int qemudDispatchDomainGetAutostart(struct qemud_server *server, struct q
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainSetAutostart(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchDomainSetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = qemudDomainSetAutostart(server,
|
ret = qemudDomainSetAutostart(qemu_driver,
|
||||||
in->qemud_packet_client_data_u.domainGetAutostartRequest.uuid,
|
in->qemud_packet_client_data_u.domainGetAutostartRequest.uuid,
|
||||||
in->qemud_packet_client_data_u.domainSetAutostartRequest.autostart);
|
in->qemud_packet_client_data_u.domainSetAutostartRequest.autostart);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_SET_AUTOSTART;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_SET_AUTOSTART;
|
||||||
@ -647,19 +609,18 @@ static int qemudDispatchDomainSetAutostart(struct qemud_server *server, struct q
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkGetAutostart(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkGetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int autostart;
|
int autostart;
|
||||||
|
|
||||||
autostart = 0;
|
autostart = 0;
|
||||||
|
|
||||||
ret = qemudNetworkGetAutostart(server,
|
ret = qemudNetworkGetAutostart(qemu_driver,
|
||||||
in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid,
|
in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid,
|
||||||
&autostart);
|
&autostart);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_GET_AUTOSTART;
|
out->type = QEMUD_SERVER_PKT_NETWORK_GET_AUTOSTART;
|
||||||
@ -668,16 +629,15 @@ static int qemudDispatchNetworkGetAutostart(struct qemud_server *server, struct
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkSetAutostart(struct qemud_server *server, struct qemud_client *client,
|
static int qemudDispatchNetworkSetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = qemudNetworkSetAutostart(server,
|
ret = qemudNetworkSetAutostart(qemu_driver,
|
||||||
in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid,
|
in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid,
|
||||||
in->qemud_packet_client_data_u.networkSetAutostartRequest.autostart);
|
in->qemud_packet_client_data_u.networkSetAutostartRequest.autostart);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(server, client, out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_SET_AUTOSTART;
|
out->type = QEMUD_SERVER_PKT_NETWORK_SET_AUTOSTART;
|
||||||
@ -685,8 +645,7 @@ static int qemudDispatchNetworkSetAutostart(struct qemud_server *server, struct
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*clientFunc)(struct qemud_server *server, struct qemud_client *client,
|
typedef int (*clientFunc)(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out);
|
||||||
struct qemud_packet_client_data *in, struct qemud_packet_server_data *out);
|
|
||||||
|
|
||||||
|
|
||||||
/* One per message type recorded in qemud_packet_type enum */
|
/* One per message type recorded in qemud_packet_type enum */
|
||||||
@ -782,7 +741,9 @@ clientFunc funcsTransmitRO[QEMUD_CLIENT_PKT_MAX] = {
|
|||||||
* is recorded by the return message type - either it matches the
|
* is recorded by the return message type - either it matches the
|
||||||
* incoming type, or is QEMUD_PKT_FAILURE
|
* incoming type, or is QEMUD_PKT_FAILURE
|
||||||
*/
|
*/
|
||||||
int qemudDispatch(struct qemud_server *server, struct qemud_client *client,
|
|
||||||
|
int qemudDispatch(struct qemud_server *server ATTRIBUTE_UNUSED,
|
||||||
|
struct qemud_client *client,
|
||||||
qemud_packet_client_data *in, qemud_packet_server_data *out) {
|
qemud_packet_client_data *in, qemud_packet_server_data *out) {
|
||||||
clientFunc *funcs;
|
clientFunc *funcs;
|
||||||
unsigned int type = in->type;
|
unsigned int type = in->type;
|
||||||
@ -806,9 +767,9 @@ int qemudDispatch(struct qemud_server *server, struct qemud_client *client,
|
|||||||
if (!funcs[type]) {
|
if (!funcs[type]) {
|
||||||
qemudDebug("Illegal operation requested");
|
qemudDebug("Illegal operation requested");
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_DENIED, NULL);
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_DENIED, NULL);
|
||||||
qemudDispatchFailure(server, client, out);
|
qemudDispatchFailure(out);
|
||||||
} else {
|
} else {
|
||||||
if ((funcs[type])(server, client, in, out) < 0) {
|
if ((funcs[type])(in, out) < 0) {
|
||||||
qemudDebug("Dispatch failed");
|
qemudDebug("Dispatch failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
621
qemud/driver.c
621
qemud/driver.c
File diff suppressed because it is too large
Load Diff
@ -26,28 +26,23 @@
|
|||||||
#define QEMUD_DRIVER_H
|
#define QEMUD_DRIVER_H
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
int qemudStartVMDaemon(struct qemud_server *server,
|
int qemudStartVMDaemon(struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm);
|
struct qemud_vm *vm);
|
||||||
|
|
||||||
int qemudShutdownVMDaemon(struct qemud_server *server,
|
int qemudShutdownVMDaemon(struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm);
|
struct qemud_vm *vm);
|
||||||
|
|
||||||
int qemudStartNetworkDaemon(struct qemud_server *server,
|
int qemudStartNetworkDaemon(struct qemud_driver *driver,
|
||||||
struct qemud_network *network);
|
struct qemud_network *network);
|
||||||
|
|
||||||
int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
int qemudShutdownNetworkDaemon(struct qemud_driver *driver,
|
||||||
struct qemud_network *network);
|
struct qemud_network *network);
|
||||||
|
|
||||||
int qemudStartup(struct qemud_server *server);
|
int qemudStartup(void);
|
||||||
void qemudReload(struct qemud_server *server);
|
void qemudReload(void);
|
||||||
void qemudShutdown(struct qemud_server *server);
|
void qemudShutdown(void);
|
||||||
|
|
||||||
void qemudReportError(virConnectPtr conn,
|
|
||||||
virDomainPtr dom,
|
|
||||||
virNetworkPtr net,
|
|
||||||
int code, const char *fmt, ...)
|
|
||||||
ATTRIBUTE_FORMAT(printf,5,6);
|
|
||||||
|
|
||||||
int qemudGetNodeInfo(unsigned int *memory,
|
int qemudGetNodeInfo(unsigned int *memory,
|
||||||
char *cpuModel, int cpuModelLength,
|
char *cpuModel, int cpuModelLength,
|
||||||
@ -55,100 +50,89 @@ int qemudGetNodeInfo(unsigned int *memory,
|
|||||||
unsigned int *nodes, unsigned int *sockets,
|
unsigned int *nodes, unsigned int *sockets,
|
||||||
unsigned int *cores, unsigned int *threads);
|
unsigned int *cores, unsigned int *threads);
|
||||||
|
|
||||||
char *qemudGetCapabilities(struct qemud_server *server);
|
char *qemudGetCapabilities(struct qemud_driver *driver);
|
||||||
int qemudMonitorCommand(struct qemud_server *server,
|
int qemudMonitorCommand(struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
const char *cmd,
|
const char *cmd,
|
||||||
char **reply);
|
char **reply);
|
||||||
|
|
||||||
struct qemud_vm *qemudFindVMByID(const struct qemud_server *server,
|
int qemudGetVersion(struct qemud_driver *driver);
|
||||||
int id);
|
int qemudListDomains(struct qemud_driver *driver,
|
||||||
struct qemud_vm *qemudFindVMByUUID(const struct qemud_server *server,
|
|
||||||
const unsigned char *uuid);
|
|
||||||
struct qemud_vm *qemudFindVMByName(const struct qemud_server *server,
|
|
||||||
const char *name);
|
|
||||||
|
|
||||||
int qemudGetVersion(struct qemud_server *server);
|
|
||||||
int qemudListDomains(struct qemud_server *server,
|
|
||||||
int *ids,
|
int *ids,
|
||||||
int nids);
|
int nids);
|
||||||
int qemudNumDomains(struct qemud_server *server);
|
int qemudNumDomains(struct qemud_driver *driver);
|
||||||
struct qemud_vm *qemudDomainCreate(struct qemud_server *server,
|
struct qemud_vm *qemudDomainCreate(struct qemud_driver *driver,
|
||||||
const char *xml);
|
const char *xml);
|
||||||
int qemudDomainSuspend(struct qemud_server *server,
|
int qemudDomainSuspend(struct qemud_driver *driver,
|
||||||
int id);
|
int id);
|
||||||
int qemudDomainResume(struct qemud_server *server,
|
int qemudDomainResume(struct qemud_driver *driver,
|
||||||
int id);
|
int id);
|
||||||
int qemudDomainDestroy(struct qemud_server *server,
|
int qemudDomainDestroy(struct qemud_driver *driver,
|
||||||
int id);
|
int id);
|
||||||
int qemudDomainGetInfo(struct qemud_server *server,
|
int qemudDomainGetInfo(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
int *runstate,
|
int *runstate,
|
||||||
unsigned long long *cputime,
|
unsigned long long *cputime,
|
||||||
unsigned long *maxmem,
|
unsigned long *maxmem,
|
||||||
unsigned long *memory,
|
unsigned long *memory,
|
||||||
unsigned int *nrVirtCpu);
|
unsigned int *nrVirtCpu);
|
||||||
int qemudDomainSave(struct qemud_server *server,
|
int qemudDomainSave(struct qemud_driver *driver,
|
||||||
int id,
|
int id,
|
||||||
const char *path);
|
const char *path);
|
||||||
int qemudDomainRestore(struct qemud_server *server,
|
int qemudDomainRestore(struct qemud_driver *driver,
|
||||||
const char *path);
|
const char *path);
|
||||||
int qemudDomainDumpXML(struct qemud_server *server,
|
int qemudDomainDumpXML(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
char *xml,
|
char *xml,
|
||||||
int xmllen);
|
int xmllen);
|
||||||
int qemudListDefinedDomains(struct qemud_server *server,
|
int qemudListDefinedDomains(struct qemud_driver *driver,
|
||||||
char *const*names,
|
char *const*names,
|
||||||
int nnames);
|
int nnames);
|
||||||
int qemudNumDefinedDomains(struct qemud_server *server);
|
int qemudNumDefinedDomains(struct qemud_driver *driver);
|
||||||
struct qemud_vm *qemudDomainStart(struct qemud_server *server,
|
struct qemud_vm *qemudDomainStart(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid);
|
const unsigned char *uuid);
|
||||||
struct qemud_vm *qemudDomainDefine(struct qemud_server *server,
|
struct qemud_vm *qemudDomainDefine(struct qemud_driver *driver,
|
||||||
const char *xml);
|
const char *xml);
|
||||||
int qemudDomainUndefine(struct qemud_server *server,
|
int qemudDomainUndefine(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid);
|
const unsigned char *uuid);
|
||||||
int qemudDomainGetAutostart(struct qemud_server *server,
|
int qemudDomainGetAutostart(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
int *autostart);
|
int *autostart);
|
||||||
int qemudDomainSetAutostart(struct qemud_server *server,
|
int qemudDomainSetAutostart(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
int autostart);
|
int autostart);
|
||||||
|
|
||||||
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server,
|
|
||||||
const unsigned char *uuid);
|
|
||||||
struct qemud_network *qemudFindNetworkByName(const struct qemud_server *server,
|
|
||||||
const char *name);
|
|
||||||
|
|
||||||
int qemudNumNetworks(struct qemud_server *server);
|
int qemudNumNetworks(struct qemud_driver *driver);
|
||||||
int qemudListNetworks(struct qemud_server *server,
|
int qemudListNetworks(struct qemud_driver *driver,
|
||||||
char *const*names,
|
char *const*names,
|
||||||
int nnames);
|
int nnames);
|
||||||
int qemudNumDefinedNetworks(struct qemud_server *server);
|
int qemudNumDefinedNetworks(struct qemud_driver *driver);
|
||||||
int qemudListDefinedNetworks(struct qemud_server *server,
|
int qemudListDefinedNetworks(struct qemud_driver *driver,
|
||||||
char *const*names,
|
char *const*names,
|
||||||
int nnames);
|
int nnames);
|
||||||
struct qemud_network *qemudNetworkCreate(struct qemud_server *server,
|
struct qemud_network *qemudNetworkCreate(struct qemud_driver *driver,
|
||||||
const char *xml);
|
const char *xml);
|
||||||
struct qemud_network *qemudNetworkDefine(struct qemud_server *server,
|
struct qemud_network *qemudNetworkDefine(struct qemud_driver *driver,
|
||||||
const char *xml);
|
const char *xml);
|
||||||
struct qemud_network *qemudNetworkStart(struct qemud_server *server,
|
struct qemud_network *qemudNetworkStart(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid);
|
const unsigned char *uuid);
|
||||||
int qemudNetworkUndefine(struct qemud_server *server,
|
int qemudNetworkUndefine(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid);
|
const unsigned char *uuid);
|
||||||
int qemudNetworkDestroy(struct qemud_server *server,
|
int qemudNetworkDestroy(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid);
|
const unsigned char *uuid);
|
||||||
int qemudNetworkDumpXML(struct qemud_server *server,
|
int qemudNetworkDumpXML(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
char *xml,
|
char *xml,
|
||||||
int xmllen);
|
int xmllen);
|
||||||
int qemudNetworkGetBridgeName(struct qemud_server *server,
|
int qemudNetworkGetBridgeName(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
char *ifname,
|
char *ifname,
|
||||||
int ifnamelen);
|
int ifnamelen);
|
||||||
int qemudNetworkGetAutostart(struct qemud_server *server,
|
int qemudNetworkGetAutostart(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
int *autostart);
|
int *autostart);
|
||||||
int qemudNetworkSetAutostart(struct qemud_server *server,
|
int qemudNetworkSetAutostart(struct qemud_driver *driver,
|
||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
int autostart);
|
int autostart);
|
||||||
|
|
||||||
|
236
qemud/internal.h
236
qemud/internal.h
@ -61,216 +61,6 @@ typedef enum {
|
|||||||
#endif
|
#endif
|
||||||
} qemudLogPriority;
|
} qemudLogPriority;
|
||||||
|
|
||||||
/* Different types of QEMU acceleration possible */
|
|
||||||
enum qemud_vm_virt_type {
|
|
||||||
QEMUD_VIRT_QEMU,
|
|
||||||
QEMUD_VIRT_KQEMU,
|
|
||||||
QEMUD_VIRT_KVM,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Two types of disk backends */
|
|
||||||
enum qemud_vm_disk_type {
|
|
||||||
QEMUD_DISK_BLOCK,
|
|
||||||
QEMUD_DISK_FILE
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Three types of disk frontend */
|
|
||||||
enum qemud_vm_disk_device {
|
|
||||||
QEMUD_DISK_DISK,
|
|
||||||
QEMUD_DISK_CDROM,
|
|
||||||
QEMUD_DISK_FLOPPY,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Stores the virtual disk configuration */
|
|
||||||
struct qemud_vm_disk_def {
|
|
||||||
int type;
|
|
||||||
int device;
|
|
||||||
char src[PATH_MAX];
|
|
||||||
char dst[NAME_MAX];
|
|
||||||
int readonly;
|
|
||||||
|
|
||||||
struct qemud_vm_disk_def *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define QEMUD_MAC_ADDRESS_LEN 6
|
|
||||||
#define QEMUD_OS_TYPE_MAX_LEN 10
|
|
||||||
#define QEMUD_OS_ARCH_MAX_LEN 10
|
|
||||||
#define QEMUD_OS_MACHINE_MAX_LEN 10
|
|
||||||
|
|
||||||
/* 5 different types of networking config */
|
|
||||||
enum qemud_vm_net_type {
|
|
||||||
QEMUD_NET_USER,
|
|
||||||
QEMUD_NET_ETHERNET,
|
|
||||||
QEMUD_NET_SERVER,
|
|
||||||
QEMUD_NET_CLIENT,
|
|
||||||
QEMUD_NET_MCAST,
|
|
||||||
QEMUD_NET_NETWORK,
|
|
||||||
QEMUD_NET_BRIDGE,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Stores the virtual network interface configuration */
|
|
||||||
struct qemud_vm_net_def {
|
|
||||||
int type;
|
|
||||||
unsigned char mac[QEMUD_MAC_ADDRESS_LEN];
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
char ifname[BR_IFNAME_MAXLEN];
|
|
||||||
char script[PATH_MAX];
|
|
||||||
} ethernet;
|
|
||||||
struct {
|
|
||||||
char address[BR_INET_ADDR_MAXLEN];
|
|
||||||
int port;
|
|
||||||
} socket; /* any of NET_CLIENT or NET_SERVER or NET_MCAST */
|
|
||||||
struct {
|
|
||||||
char name[QEMUD_MAX_NAME_LEN];
|
|
||||||
char ifname[BR_IFNAME_MAXLEN];
|
|
||||||
} network;
|
|
||||||
struct {
|
|
||||||
char brname[BR_IFNAME_MAXLEN];
|
|
||||||
char ifname[BR_IFNAME_MAXLEN];
|
|
||||||
} bridge;
|
|
||||||
} dst;
|
|
||||||
|
|
||||||
struct qemud_vm_net_def *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define QEMUD_MAX_BOOT_DEVS 4
|
|
||||||
|
|
||||||
/* 3 possible boot devices */
|
|
||||||
enum qemud_vm_boot_order {
|
|
||||||
QEMUD_BOOT_FLOPPY,
|
|
||||||
QEMUD_BOOT_CDROM,
|
|
||||||
QEMUD_BOOT_DISK,
|
|
||||||
QEMUD_BOOT_NET,
|
|
||||||
};
|
|
||||||
/* 3 possible graphics console modes */
|
|
||||||
enum qemud_vm_grapics_type {
|
|
||||||
QEMUD_GRAPHICS_NONE,
|
|
||||||
QEMUD_GRAPHICS_SDL,
|
|
||||||
QEMUD_GRAPHICS_VNC,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Internal flags to keep track of qemu command line capabilities */
|
|
||||||
enum qemud_cmd_flags {
|
|
||||||
QEMUD_CMD_FLAG_KQEMU = 1,
|
|
||||||
QEMUD_CMD_FLAG_VNC_COLON = 2,
|
|
||||||
QEMUD_CMD_FLAG_NO_REBOOT = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
enum qemud_vm_features {
|
|
||||||
QEMUD_FEATURE_ACPI = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Operating system configuration data & machine / arch */
|
|
||||||
struct qemud_vm_os_def {
|
|
||||||
char type[QEMUD_OS_TYPE_MAX_LEN];
|
|
||||||
char arch[QEMUD_OS_ARCH_MAX_LEN];
|
|
||||||
char machine[QEMUD_OS_MACHINE_MAX_LEN];
|
|
||||||
int nBootDevs;
|
|
||||||
int bootDevs[QEMUD_MAX_BOOT_DEVS];
|
|
||||||
char kernel[PATH_MAX];
|
|
||||||
char initrd[PATH_MAX];
|
|
||||||
char cmdline[PATH_MAX];
|
|
||||||
char binary[PATH_MAX];
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Guest VM main configuration */
|
|
||||||
struct qemud_vm_def {
|
|
||||||
int virtType;
|
|
||||||
unsigned char uuid[QEMUD_UUID_RAW_LEN];
|
|
||||||
char name[QEMUD_MAX_NAME_LEN];
|
|
||||||
|
|
||||||
int memory;
|
|
||||||
int maxmem;
|
|
||||||
int vcpus;
|
|
||||||
|
|
||||||
int noReboot;
|
|
||||||
|
|
||||||
struct qemud_vm_os_def os;
|
|
||||||
|
|
||||||
int features;
|
|
||||||
int graphicsType;
|
|
||||||
int vncPort;
|
|
||||||
int vncActivePort;
|
|
||||||
|
|
||||||
int ndisks;
|
|
||||||
struct qemud_vm_disk_def *disks;
|
|
||||||
|
|
||||||
int nnets;
|
|
||||||
struct qemud_vm_net_def *nets;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Guest VM runtime state */
|
|
||||||
struct qemud_vm {
|
|
||||||
int stdout;
|
|
||||||
int stderr;
|
|
||||||
int monitor;
|
|
||||||
int logfile;
|
|
||||||
int pid;
|
|
||||||
int id;
|
|
||||||
int state;
|
|
||||||
|
|
||||||
int *tapfds;
|
|
||||||
int ntapfds;
|
|
||||||
|
|
||||||
char configFile[PATH_MAX];
|
|
||||||
char autostartLink[PATH_MAX];
|
|
||||||
|
|
||||||
struct qemud_vm_def *def; /* The current definition */
|
|
||||||
struct qemud_vm_def *newDef; /* New definition to activate at shutdown */
|
|
||||||
|
|
||||||
unsigned int autostart : 1;
|
|
||||||
|
|
||||||
struct qemud_vm *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Store start and end addresses of a dhcp range */
|
|
||||||
struct qemud_dhcp_range_def {
|
|
||||||
char start[BR_INET_ADDR_MAXLEN];
|
|
||||||
char end[BR_INET_ADDR_MAXLEN];
|
|
||||||
|
|
||||||
struct qemud_dhcp_range_def *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Virtual Network main configuration */
|
|
||||||
struct qemud_network_def {
|
|
||||||
unsigned char uuid[QEMUD_UUID_RAW_LEN];
|
|
||||||
char name[QEMUD_MAX_NAME_LEN];
|
|
||||||
|
|
||||||
char bridge[BR_IFNAME_MAXLEN];
|
|
||||||
int disableSTP;
|
|
||||||
int forwardDelay;
|
|
||||||
|
|
||||||
int forward;
|
|
||||||
char forwardDev[BR_IFNAME_MAXLEN];
|
|
||||||
|
|
||||||
char ipAddress[BR_INET_ADDR_MAXLEN];
|
|
||||||
char netmask[BR_INET_ADDR_MAXLEN];
|
|
||||||
char network[BR_INET_ADDR_MAXLEN+BR_INET_ADDR_MAXLEN+1];
|
|
||||||
|
|
||||||
int nranges;
|
|
||||||
struct qemud_dhcp_range_def *ranges;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Virtual Network runtime state */
|
|
||||||
struct qemud_network {
|
|
||||||
char configFile[PATH_MAX];
|
|
||||||
char autostartLink[PATH_MAX];
|
|
||||||
|
|
||||||
struct qemud_network_def *def; /* The current definition */
|
|
||||||
struct qemud_network_def *newDef; /* New definition to activate at shutdown */
|
|
||||||
|
|
||||||
char bridge[BR_IFNAME_MAXLEN];
|
|
||||||
int dnsmasqPid;
|
|
||||||
|
|
||||||
unsigned int active : 1;
|
|
||||||
unsigned int autostart : 1;
|
|
||||||
|
|
||||||
struct qemud_network *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
enum qemud_mode {
|
enum qemud_mode {
|
||||||
QEMUD_MODE_RX_HEADER,
|
QEMUD_MODE_RX_HEADER,
|
||||||
@ -333,24 +123,9 @@ struct qemud_socket {
|
|||||||
struct qemud_server {
|
struct qemud_server {
|
||||||
int nsockets;
|
int nsockets;
|
||||||
struct qemud_socket *sockets;
|
struct qemud_socket *sockets;
|
||||||
int qemuVersion;
|
|
||||||
int qemuCmdFlags; /* values from enum qemud_cmd_flags */
|
|
||||||
int nclients;
|
int nclients;
|
||||||
struct qemud_client *clients;
|
struct qemud_client *clients;
|
||||||
int sigread;
|
int sigread;
|
||||||
int nactivevms;
|
|
||||||
int ninactivevms;
|
|
||||||
struct qemud_vm *vms;
|
|
||||||
int nextvmid;
|
|
||||||
int nactivenetworks;
|
|
||||||
int ninactivenetworks;
|
|
||||||
struct qemud_network *networks;
|
|
||||||
brControl *brctl;
|
|
||||||
iptablesContext *iptables;
|
|
||||||
char *configDir;
|
|
||||||
char *autostartDir;
|
|
||||||
char *networkConfigDir;
|
|
||||||
char *networkAutostartDir;
|
|
||||||
char logDir[PATH_MAX];
|
char logDir[PATH_MAX];
|
||||||
unsigned int shutdown : 1;
|
unsigned int shutdown : 1;
|
||||||
};
|
};
|
||||||
@ -367,17 +142,6 @@ void qemudLog(int priority, const char *fmt, ...)
|
|||||||
void remoteDispatchClientRequest (struct qemud_server *server,
|
void remoteDispatchClientRequest (struct qemud_server *server,
|
||||||
struct qemud_client *client);
|
struct qemud_client *client);
|
||||||
|
|
||||||
static inline int
|
|
||||||
qemudIsActiveVM(struct qemud_vm *vm)
|
|
||||||
{
|
|
||||||
return vm->id != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
qemudIsActiveNetwork(struct qemud_network *network)
|
|
||||||
{
|
|
||||||
return network->active;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -207,7 +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) {
|
||||||
qemudReload(server);
|
qemudReload();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ static void qemudDispatchSignalEvent(int fd ATTRIBUTE_UNUSED,
|
|||||||
qemudLog(QEMUD_WARN, "Shutting down on signal %d", sigc);
|
qemudLog(QEMUD_WARN, "Shutting down on signal %d", sigc);
|
||||||
|
|
||||||
if (!remote) {
|
if (!remote) {
|
||||||
qemudShutdown(server);
|
qemudShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
server->shutdown = 1;
|
server->shutdown = 1;
|
||||||
@ -620,11 +620,6 @@ static int qemudInitPaths(struct qemud_server *server,
|
|||||||
|
|
||||||
unlink(roSockname);
|
unlink(roSockname);
|
||||||
|
|
||||||
server->configDir =
|
|
||||||
server->autostartDir =
|
|
||||||
server->networkConfigDir =
|
|
||||||
server->networkAutostartDir = NULL;
|
|
||||||
|
|
||||||
if (snprintf(server->logDir, PATH_MAX, "%s/log/libvirt/qemu", LOCAL_STATE_DIR) >= PATH_MAX)
|
if (snprintf(server->logDir, PATH_MAX, "%s/log/libvirt/qemu", LOCAL_STATE_DIR) >= PATH_MAX)
|
||||||
goto snprintf_error;
|
goto snprintf_error;
|
||||||
} else {
|
} else {
|
||||||
@ -660,30 +655,15 @@ static int qemudInitPaths(struct qemud_server *server,
|
|||||||
if (snprintf(sockname, maxlen, "@%s/.libvirt/qemud-sock", pw->pw_dir) >= maxlen)
|
if (snprintf(sockname, maxlen, "@%s/.libvirt/qemud-sock", pw->pw_dir) >= maxlen)
|
||||||
goto snprintf_error;
|
goto snprintf_error;
|
||||||
|
|
||||||
|
if (snprintf(server->logDir, PATH_MAX, "%s/.libvirt/qemu/log", pw->pw_dir) >= PATH_MAX)
|
||||||
|
goto snprintf_error;
|
||||||
|
|
||||||
if (asprintf (&base, "%s/.libvirt/qemu", pw->pw_dir) == -1) {
|
if (asprintf (&base, "%s/.libvirt/qemu", pw->pw_dir) == -1) {
|
||||||
qemudLog (QEMUD_ERR, "out of memory in asprintf");
|
qemudLog (QEMUD_ERR, "out of memory in asprintf");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configuration paths are either ~/.libvirt/qemu/... (session) or
|
|
||||||
* /etc/libvirt/qemu/... (system).
|
|
||||||
*/
|
|
||||||
if (asprintf (&server->configDir, "%s", base) == -1)
|
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (asprintf (&server->autostartDir, "%s/autostart", base) == -1)
|
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (asprintf (&server->networkConfigDir, "%s/networks", base) == -1)
|
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (asprintf (&server->networkAutostartDir, "%s/networks/autostart",
|
|
||||||
base) == -1)
|
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (snprintf(server->logDir, PATH_MAX, "%s/log", base) >= PATH_MAX)
|
|
||||||
goto snprintf_error;
|
|
||||||
} /* !remote */
|
} /* !remote */
|
||||||
|
|
||||||
if (base) free (base);
|
if (base) free (base);
|
||||||
@ -711,7 +691,6 @@ static struct qemud_server *qemudInitialize(int sigread) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We don't have a dom-0, so start from 1 */
|
/* We don't have a dom-0, so start from 1 */
|
||||||
server->nextvmid = 1;
|
|
||||||
server->sigread = sigread;
|
server->sigread = sigread;
|
||||||
|
|
||||||
roSockname[0] = '\0';
|
roSockname[0] = '\0';
|
||||||
@ -726,7 +705,7 @@ static struct qemud_server *qemudInitialize(int sigread) {
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!remote) /* qemud only */ {
|
if (!remote) /* qemud only */ {
|
||||||
if (qemudStartup(server) < 0) {
|
if (qemudStartup() < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else /* remote only */ {
|
} else /* remote only */ {
|
||||||
@ -745,6 +724,7 @@ static struct qemud_server *qemudInitialize(int sigread) {
|
|||||||
return server;
|
return server;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
qemudShutdown();
|
||||||
if (server) {
|
if (server) {
|
||||||
struct qemud_socket *sock = server->sockets;
|
struct qemud_socket *sock = server->sockets;
|
||||||
while (sock) {
|
while (sock) {
|
||||||
@ -752,11 +732,6 @@ static struct qemud_server *qemudInitialize(int sigread) {
|
|||||||
sock = sock->next;
|
sock = sock->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server->configDir) free (server->configDir);
|
|
||||||
if (server->autostartDir) free (server->autostartDir);
|
|
||||||
if (server->networkConfigDir) free (server->networkConfigDir);
|
|
||||||
if (server->networkAutostartDir) free (server->networkAutostartDir);
|
|
||||||
|
|
||||||
free(server);
|
free(server);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1525,15 +1500,8 @@ static void qemudCleanup(struct qemud_server *server) {
|
|||||||
sock = next;
|
sock = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server->brctl)
|
|
||||||
brShutdown(server->brctl);
|
|
||||||
if (server->iptables)
|
|
||||||
iptablesContextFree(server->iptables);
|
|
||||||
|
|
||||||
if (server->configDir) free (server->configDir);
|
qemudShutdown();
|
||||||
if (server->autostartDir) free (server->autostartDir);
|
|
||||||
if (server->networkConfigDir) free (server->networkConfigDir);
|
|
||||||
if (server->networkAutostartDir) free (server->networkAutostartDir);
|
|
||||||
|
|
||||||
free(server);
|
free(server);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user