mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Make QEMU driver report errors against virConnectPtr if available
This commit is contained in:
parent
c0a3f03f4d
commit
e958eff752
@ -1,3 +1,9 @@
|
|||||||
|
Thu Jul 12 11:02:17 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* src/qemu_conf.c, src/qemu_conf.h, src/qemu_driver.c: Pass
|
||||||
|
around the virConnectPtr when available so errors get reported
|
||||||
|
against that rather than the global error location.
|
||||||
|
|
||||||
Thu Jul 12 11:02:17 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
Thu Jul 12 11:02:17 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* qemud/qemud.c: Fix cleanup when client access checks fail
|
* qemud/qemud.c: Fix cleanup when client access checks fail
|
||||||
|
273
src/qemu_conf.c
273
src/qemu_conf.c
@ -266,7 +266,8 @@ 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_driver *driver ATTRIBUTE_UNUSED,
|
static char *qemudLocateBinaryForArch(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
int virtType, const char *arch) {
|
int virtType, const char *arch) {
|
||||||
const char *name;
|
const char *name;
|
||||||
char *path;
|
char *path;
|
||||||
@ -277,14 +278,14 @@ static char *qemudLocateBinaryForArch(struct qemud_driver *driver ATTRIBUTE_UNUS
|
|||||||
name = qemudDefaultBinaryForArch(arch);
|
name = qemudDefaultBinaryForArch(arch);
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot determin binary for architecture %s", arch);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot determin binary for architecture %s", arch);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX lame. should actually use $PATH ... */
|
/* XXX lame. should actually use $PATH ... */
|
||||||
path = malloc(strlen(name) + strlen("/usr/bin/") + 1);
|
path = malloc(strlen(name) + strlen("/usr/bin/") + 1);
|
||||||
if (!path) {
|
if (!path) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "path");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "path");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strcpy(path, "/usr/bin/");
|
strcpy(path, "/usr/bin/");
|
||||||
@ -386,18 +387,19 @@ static int qemudExtractVersionInfo(const char *qemu, int *version, int *flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemudExtractVersion(struct qemud_driver *driver) {
|
int qemudExtractVersion(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver) {
|
||||||
char *binary = NULL;
|
char *binary = NULL;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (driver->qemuVersion > 0)
|
if (driver->qemuVersion > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(binary = qemudLocateBinaryForArch(driver, QEMUD_VIRT_QEMU, "i686")))
|
if (!(binary = qemudLocateBinaryForArch(conn, driver, QEMUD_VIRT_QEMU, "i686")))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (stat(binary, &sb) < 0) {
|
if (stat(binary, &sb) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Cannot find QEMU binary %s: %s", binary,
|
"Cannot find QEMU binary %s: %s", binary,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
free(binary);
|
free(binary);
|
||||||
@ -415,7 +417,8 @@ int qemudExtractVersion(struct qemud_driver *driver) {
|
|||||||
|
|
||||||
|
|
||||||
/* Parse the XML definition for a disk */
|
/* Parse the XML definition for a disk */
|
||||||
static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
static struct qemud_vm_disk_def *qemudParseDiskXML(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
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;
|
||||||
@ -426,7 +429,7 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_driver *driver A
|
|||||||
int typ = 0;
|
int typ = 0;
|
||||||
|
|
||||||
if (!disk) {
|
if (!disk) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "disk");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "disk");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,11 +469,11 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_driver *driver A
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (source == NULL) {
|
if (source == NULL) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_SOURCE, target ? "%s" : NULL, target);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_SOURCE, target ? "%s" : NULL, target);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (target == NULL) {
|
if (target == NULL) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_TARGET, source ? "%s" : NULL, source);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_TARGET, source ? "%s" : NULL, source);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,14 +481,14 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_driver *driver A
|
|||||||
!strcmp((const char *)device, "floppy") &&
|
!strcmp((const char *)device, "floppy") &&
|
||||||
strcmp((const char *)target, "fda") &&
|
strcmp((const char *)target, "fda") &&
|
||||||
strcmp((const char *)target, "fdb")) {
|
strcmp((const char *)target, "fdb")) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid floppy device name: %s", target);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid floppy device name: %s", target);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device &&
|
if (device &&
|
||||||
!strcmp((const char *)device, "cdrom") &&
|
!strcmp((const char *)device, "cdrom") &&
|
||||||
strcmp((const char *)target, "hdc")) {
|
strcmp((const char *)target, "hdc")) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid cdrom device name: %s", target);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid cdrom device name: %s", target);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,7 +501,7 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_driver *driver A
|
|||||||
strcmp((const char *)target, "hdb") &&
|
strcmp((const char *)target, "hdb") &&
|
||||||
strcmp((const char *)target, "hdc") &&
|
strcmp((const char *)target, "hdc") &&
|
||||||
strcmp((const char *)target, "hdd")) {
|
strcmp((const char *)target, "hdd")) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid harddisk device name: %s", target);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid harddisk device name: %s", target);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -518,7 +521,7 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_driver *driver A
|
|||||||
else if (!strcmp((const char *)device, "floppy"))
|
else if (!strcmp((const char *)device, "floppy"))
|
||||||
disk->device = QEMUD_DISK_FLOPPY;
|
disk->device = QEMUD_DISK_FLOPPY;
|
||||||
else {
|
else {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid device type: %s", device);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid device type: %s", device);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,7 +555,8 @@ 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_driver *driver ATTRIBUTE_UNUSED,
|
static struct qemud_vm_net_def *qemudParseInterfaceXML(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
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;
|
||||||
@ -566,7 +570,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
xmlChar *port = NULL;
|
xmlChar *port = NULL;
|
||||||
|
|
||||||
if (!net) {
|
if (!net) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "net");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "net");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -656,11 +660,11 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (network == NULL) {
|
if (network == NULL) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"No <source> 'network' attribute specified with <interface type='network'/>");
|
"No <source> 'network' attribute specified with <interface type='network'/>");
|
||||||
goto error;
|
goto error;
|
||||||
} else if ((len = xmlStrlen(network)) >= (QEMUD_MAX_NAME_LEN-1)) {
|
} else if ((len = xmlStrlen(network)) >= (QEMUD_MAX_NAME_LEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Network name '%s' too long", network);
|
"Network name '%s' too long", network);
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
@ -675,7 +679,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
|
|
||||||
if (ifname != NULL) {
|
if (ifname != NULL) {
|
||||||
if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) {
|
if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"TAP interface name '%s' is too long", ifname);
|
"TAP interface name '%s' is too long", ifname);
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
@ -690,7 +694,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
|
|
||||||
if (script != NULL) {
|
if (script != NULL) {
|
||||||
if ((len = xmlStrlen(script)) >= (PATH_MAX-1)) {
|
if ((len = xmlStrlen(script)) >= (PATH_MAX-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"TAP script path '%s' is too long", script);
|
"TAP script path '%s' is too long", script);
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
@ -702,7 +706,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
}
|
}
|
||||||
if (ifname != NULL) {
|
if (ifname != NULL) {
|
||||||
if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) {
|
if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"TAP interface name '%s' is too long", ifname);
|
"TAP interface name '%s' is too long", ifname);
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
@ -715,11 +719,11 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (bridge == NULL) {
|
if (bridge == NULL) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"No <source> 'dev' attribute specified with <interface type='bridge'/>");
|
"No <source> 'dev' attribute specified with <interface type='bridge'/>");
|
||||||
goto error;
|
goto error;
|
||||||
} else if ((len = xmlStrlen(bridge)) >= (BR_IFNAME_MAXLEN-1)) {
|
} else if ((len = xmlStrlen(bridge)) >= (BR_IFNAME_MAXLEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"TAP bridge path '%s' is too long", bridge);
|
"TAP bridge path '%s' is too long", bridge);
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
@ -732,7 +736,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
|
|
||||||
if (ifname != NULL) {
|
if (ifname != NULL) {
|
||||||
if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) {
|
if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"TAP interface name '%s' is too long", ifname);
|
"TAP interface name '%s' is too long", ifname);
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
@ -748,13 +752,13 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
if (port == NULL) {
|
if (port == NULL) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"No <source> 'port' attribute specified with socket interface");
|
"No <source> 'port' attribute specified with socket interface");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!(net->dst.socket.port = strtol((char*)port, &ret, 10)) &&
|
if (!(net->dst.socket.port = strtol((char*)port, &ret, 10)) &&
|
||||||
ret == (char*)port) {
|
ret == (char*)port) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Cannot parse <source> 'port' attribute with socket interface");
|
"Cannot parse <source> 'port' attribute with socket interface");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -764,12 +768,12 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
if (address == NULL) {
|
if (address == NULL) {
|
||||||
if (net->type == QEMUD_NET_CLIENT ||
|
if (net->type == QEMUD_NET_CLIENT ||
|
||||||
net->type == QEMUD_NET_MCAST) {
|
net->type == QEMUD_NET_MCAST) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"No <source> 'address' attribute specified with socket interface");
|
"No <source> 'address' attribute specified with socket interface");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else if ((len = xmlStrlen(address)) >= (BR_INET_ADDR_MAXLEN)) {
|
} else if ((len = xmlStrlen(address)) >= (BR_INET_ADDR_MAXLEN)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"IP address '%s' is too long", address);
|
"IP address '%s' is too long", address);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -806,7 +810,8 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driv
|
|||||||
* 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_driver *driver,
|
static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
xmlDocPtr xml) {
|
xmlDocPtr xml) {
|
||||||
xmlNodePtr root = NULL;
|
xmlNodePtr root = NULL;
|
||||||
xmlChar *prop = NULL;
|
xmlChar *prop = NULL;
|
||||||
@ -817,27 +822,27 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
struct qemud_vm_def *def;
|
struct qemud_vm_def *def;
|
||||||
|
|
||||||
if (!(def = calloc(1, sizeof(struct qemud_vm_def)))) {
|
if (!(def = calloc(1, sizeof(struct qemud_vm_def)))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare parser / xpath context */
|
/* Prepare parser / xpath context */
|
||||||
root = xmlDocGetRootElement(xml);
|
root = xmlDocGetRootElement(xml);
|
||||||
if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "domain"))) {
|
if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "domain"))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt = xmlXPathNewContext(xml);
|
ctxt = xmlXPathNewContext(xml);
|
||||||
if (ctxt == NULL) {
|
if (ctxt == NULL) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Find out what type of QEMU virtualization to use */
|
/* Find out what type of QEMU virtualization to use */
|
||||||
if (!(prop = xmlGetProp(root, BAD_CAST "type"))) {
|
if (!(prop = xmlGetProp(root, BAD_CAST "type"))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "missing domain type attribute");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "missing domain type attribute");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -848,7 +853,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
else if (!strcmp((char *)prop, "kvm"))
|
else if (!strcmp((char *)prop, "kvm"))
|
||||||
def->virtType = QEMUD_VIRT_KVM;
|
def->virtType = QEMUD_VIRT_KVM;
|
||||||
else {
|
else {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "invalid domain type attribute");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "invalid domain type attribute");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
free(prop);
|
free(prop);
|
||||||
@ -859,11 +864,11 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
|
obj = xmlXPathEval(BAD_CAST "string(/domain/name[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)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_NAME, NULL);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_NAME, NULL);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (strlen((const char *)obj->stringval) >= (QEMUD_MAX_NAME_LEN-1)) {
|
if (strlen((const char *)obj->stringval) >= (QEMUD_MAX_NAME_LEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "domain name length too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "domain name length too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->name, (const char *)obj->stringval);
|
strcpy(def->name, (const char *)obj->stringval);
|
||||||
@ -876,12 +881,12 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
||||||
int err;
|
int err;
|
||||||
if ((err = virUUIDGenerate(def->uuid))) {
|
if ((err = virUUIDGenerate(def->uuid))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Failed to generate UUID: %s", strerror(err));
|
"Failed to generate UUID: %s", strerror(err));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else if (virUUIDParse((const char *)obj->stringval, def->uuid) < 0) {
|
} else if (virUUIDParse((const char *)obj->stringval, def->uuid) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
@ -891,13 +896,13 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
obj = xmlXPathEval(BAD_CAST "string(/domain/memory[1])", ctxt);
|
obj = xmlXPathEval(BAD_CAST "string(/domain/memory[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)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "missing memory element");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "missing memory element");
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
conv = NULL;
|
conv = NULL;
|
||||||
def->maxmem = strtoll((const char*)obj->stringval, &conv, 10);
|
def->maxmem = strtoll((const char*)obj->stringval, &conv, 10);
|
||||||
if (conv == (const char*)obj->stringval) {
|
if (conv == (const char*)obj->stringval) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -916,7 +921,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
if (def->memory > def->maxmem)
|
if (def->memory > def->maxmem)
|
||||||
def->memory = def->maxmem;
|
def->memory = def->maxmem;
|
||||||
if (conv == (const char*)obj->stringval) {
|
if (conv == (const char*)obj->stringval) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -932,7 +937,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
conv = NULL;
|
conv = NULL;
|
||||||
def->vcpus = strtoll((const char*)obj->stringval, &conv, 10);
|
def->vcpus = strtoll((const char*)obj->stringval, &conv, 10);
|
||||||
if (conv == (const char*)obj->stringval) {
|
if (conv == (const char*)obj->stringval) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed vcpu information");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed vcpu information");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -967,11 +972,11 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt);
|
obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[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)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_OS_TYPE, NULL);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_OS_TYPE, NULL);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (strcmp((const char *)obj->stringval, "hvm")) {
|
if (strcmp((const char *)obj->stringval, "hvm")) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_OS_TYPE, "%s", obj->stringval);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_OS_TYPE, "%s", obj->stringval);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->os.type, (const char *)obj->stringval);
|
strcpy(def->os.type, (const char *)obj->stringval);
|
||||||
@ -983,13 +988,13 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
||||||
const char *defaultArch = qemudDefaultArch();
|
const char *defaultArch = qemudDefaultArch();
|
||||||
if (strlen(defaultArch) >= (QEMUD_OS_TYPE_MAX_LEN-1)) {
|
if (strlen(defaultArch) >= (QEMUD_OS_TYPE_MAX_LEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->os.arch, defaultArch);
|
strcpy(def->os.arch, defaultArch);
|
||||||
} else {
|
} else {
|
||||||
if (strlen((const char *)obj->stringval) >= (QEMUD_OS_TYPE_MAX_LEN-1)) {
|
if (strlen((const char *)obj->stringval) >= (QEMUD_OS_TYPE_MAX_LEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->os.arch, (const char *)obj->stringval);
|
strcpy(def->os.arch, (const char *)obj->stringval);
|
||||||
@ -1002,13 +1007,13 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
||||||
const char *defaultMachine = qemudDefaultMachineForArch(def->os.arch);
|
const char *defaultMachine = qemudDefaultMachineForArch(def->os.arch);
|
||||||
if (strlen(defaultMachine) >= (QEMUD_OS_MACHINE_MAX_LEN-1)) {
|
if (strlen(defaultMachine) >= (QEMUD_OS_MACHINE_MAX_LEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "machine type too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "machine type too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->os.machine, defaultMachine);
|
strcpy(def->os.machine, defaultMachine);
|
||||||
} else {
|
} else {
|
||||||
if (strlen((const char *)obj->stringval) >= (QEMUD_OS_MACHINE_MAX_LEN-1)) {
|
if (strlen((const char *)obj->stringval) >= (QEMUD_OS_MACHINE_MAX_LEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->os.machine, (const char *)obj->stringval);
|
strcpy(def->os.machine, (const char *)obj->stringval);
|
||||||
@ -1021,7 +1026,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
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)) {
|
||||||
if (strlen((const char *)obj->stringval) >= (PATH_MAX-1)) {
|
if (strlen((const char *)obj->stringval) >= (PATH_MAX-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "kernel path too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "kernel path too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->os.kernel, (const char *)obj->stringval);
|
strcpy(def->os.kernel, (const char *)obj->stringval);
|
||||||
@ -1034,7 +1039,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
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)) {
|
||||||
if (strlen((const char *)obj->stringval) >= (PATH_MAX-1)) {
|
if (strlen((const char *)obj->stringval) >= (PATH_MAX-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "initrd path too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "initrd path too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->os.initrd, (const char *)obj->stringval);
|
strcpy(def->os.initrd, (const char *)obj->stringval);
|
||||||
@ -1047,7 +1052,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
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)) {
|
||||||
if (strlen((const char *)obj->stringval) >= (PATH_MAX-1)) {
|
if (strlen((const char *)obj->stringval) >= (PATH_MAX-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "cmdline arguments too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "cmdline arguments too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->os.cmdline, (const char *)obj->stringval);
|
strcpy(def->os.cmdline, (const char *)obj->stringval);
|
||||||
@ -1089,7 +1094,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
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(driver, def->virtType, def->os.arch);
|
char *tmp = qemudLocateBinaryForArch(conn, driver, def->virtType, def->os.arch);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -1097,7 +1102,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
free(tmp);
|
free(tmp);
|
||||||
} else {
|
} else {
|
||||||
if (strlen((const char *)obj->stringval) >= (PATH_MAX-1)) {
|
if (strlen((const char *)obj->stringval) >= (PATH_MAX-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "emulator path too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "emulator path too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->os.binary, (const char *)obj->stringval);
|
strcpy(def->os.binary, (const char *)obj->stringval);
|
||||||
@ -1122,7 +1127,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
} else if (!strcmp((char *)prop, "sdl")) {
|
} else if (!strcmp((char *)prop, "sdl")) {
|
||||||
def->graphicsType = QEMUD_GRAPHICS_SDL;
|
def->graphicsType = QEMUD_GRAPHICS_SDL;
|
||||||
} else {
|
} else {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unsupported graphics type %s", prop);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unsupported graphics type %s", prop);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
xmlFree(prop);
|
xmlFree(prop);
|
||||||
@ -1137,7 +1142,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
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(driver, obj->nodesetval->nodeTab[i]))) {
|
if (!(disk = qemudParseDiskXML(conn, driver, obj->nodesetval->nodeTab[i]))) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->ndisks++;
|
def->ndisks++;
|
||||||
@ -1160,7 +1165,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
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(driver, obj->nodesetval->nodeTab[i]))) {
|
if (!(net = qemudParseInterfaceXML(conn, driver, obj->nodesetval->nodeTab[i]))) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->nnets++;
|
def->nnets++;
|
||||||
@ -1191,7 +1196,8 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver,
|
|||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
qemudNetworkIfaceConnect(struct qemud_driver *driver,
|
qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||||
|
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)
|
||||||
@ -1207,11 +1213,11 @@ qemudNetworkIfaceConnect(struct qemud_driver *driver,
|
|||||||
|
|
||||||
if (net->type == QEMUD_NET_NETWORK) {
|
if (net->type == QEMUD_NET_NETWORK) {
|
||||||
if (!(network = qemudFindNetworkByName(driver, net->dst.network.name))) {
|
if (!(network = qemudFindNetworkByName(driver, net->dst.network.name))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, 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;
|
||||||
} else if (network->bridge[0] == '\0') {
|
} else if (network->bridge[0] == '\0') {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Network '%s' not active", net->dst.network.name);
|
"Network '%s' not active", net->dst.network.name);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -1229,20 +1235,20 @@ qemudNetworkIfaceConnect(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
ifname = net->dst.bridge.ifname;
|
ifname = net->dst.bridge.ifname;
|
||||||
} else {
|
} else {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Network type %d is not supported", net->type);
|
"Network type %d is not supported", net->type);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, 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(driver->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(conn, 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",
|
||||||
ifname, brname, strerror(err));
|
ifname, brname, strerror(err));
|
||||||
goto error;
|
goto error;
|
||||||
@ -1263,7 +1269,7 @@ qemudNetworkIfaceConnect(struct qemud_driver *driver,
|
|||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "tapfds");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "tapfds");
|
||||||
error:
|
error:
|
||||||
if (retval)
|
if (retval)
|
||||||
free(retval);
|
free(retval);
|
||||||
@ -1276,7 +1282,8 @@ qemudNetworkIfaceConnect(struct qemud_driver *driver,
|
|||||||
* 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_driver *driver,
|
int qemudBuildCommandLine(virConnectPtr conn,
|
||||||
|
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;
|
||||||
@ -1289,7 +1296,7 @@ int qemudBuildCommandLine(struct qemud_driver *driver,
|
|||||||
struct utsname ut;
|
struct utsname ut;
|
||||||
int disableKQEMU = 0;
|
int disableKQEMU = 0;
|
||||||
|
|
||||||
if (qemudExtractVersion(driver) < 0)
|
if (qemudExtractVersion(conn, driver) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uname(&ut);
|
uname(&ut);
|
||||||
@ -1316,7 +1323,7 @@ int qemudBuildCommandLine(struct qemud_driver *driver,
|
|||||||
* in a sub-process so its hard to feed back a useful error
|
* in a sub-process so its hard to feed back a useful error
|
||||||
*/
|
*/
|
||||||
if (stat(vm->def->os.binary, &sb) < 0) {
|
if (stat(vm->def->os.binary, &sb) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Cannot find QEMU binary %s: %s", vm->def->os.binary,
|
"Cannot find QEMU binary %s: %s", vm->def->os.binary,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
@ -1470,7 +1477,7 @@ int qemudBuildCommandLine(struct qemud_driver *driver,
|
|||||||
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(driver, vm, net, vlan)))
|
if (!((*argv)[++n] = qemudNetworkIfaceConnect(conn, driver, vm, net, vlan)))
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1560,7 +1567,7 @@ int qemudBuildCommandLine(struct qemud_driver *driver,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "argv");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "argv");
|
||||||
error:
|
error:
|
||||||
if (vm->tapfds) {
|
if (vm->tapfds) {
|
||||||
for (i = 0; vm->tapfds[i] != -1; i++)
|
for (i = 0; vm->tapfds[i] != -1; i++)
|
||||||
@ -1579,20 +1586,21 @@ int qemudBuildCommandLine(struct qemud_driver *driver,
|
|||||||
|
|
||||||
|
|
||||||
/* 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_driver *driver,
|
static int qemudSaveConfig(virConnectPtr conn,
|
||||||
|
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(driver, vm, def, 0)))
|
if (!(xml = qemudGenerateXML(conn, driver, vm, def, 0)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((fd = open(vm->configFile,
|
if ((fd = open(vm->configFile,
|
||||||
O_WRONLY | O_CREAT | O_TRUNC,
|
O_WRONLY | O_CREAT | O_TRUNC,
|
||||||
S_IRUSR | S_IWUSR )) < 0) {
|
S_IRUSR | S_IWUSR )) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create config file %s: %s",
|
"cannot create config file %s: %s",
|
||||||
vm->configFile, strerror(errno));
|
vm->configFile, strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1600,14 +1608,14 @@ static int qemudSaveConfig(struct qemud_driver *driver,
|
|||||||
|
|
||||||
towrite = strlen(xml);
|
towrite = strlen(xml);
|
||||||
if (write(fd, xml, towrite) != towrite) {
|
if (write(fd, xml, towrite) != towrite) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot write config file %s: %s",
|
"cannot write config file %s: %s",
|
||||||
vm->configFile, strerror(errno));
|
vm->configFile, strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot save config file %s: %s",
|
"cannot save config file %s: %s",
|
||||||
vm->configFile, strerror(errno));
|
vm->configFile, strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1625,7 +1633,8 @@ static int qemudSaveConfig(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_vm_def *
|
struct qemud_vm_def *
|
||||||
qemudParseVMDef(struct qemud_driver *driver,
|
qemudParseVMDef(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
const char *displayName) {
|
const char *displayName) {
|
||||||
xmlDocPtr xml;
|
xmlDocPtr xml;
|
||||||
@ -1634,11 +1643,11 @@ qemudParseVMDef(struct qemud_driver *driver,
|
|||||||
if (!(xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : "domain.xml", NULL,
|
if (!(xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : "domain.xml", NULL,
|
||||||
XML_PARSE_NOENT | XML_PARSE_NONET |
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) {
|
XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
def = qemudParseXML(driver, xml);
|
def = qemudParseXML(conn, driver, xml);
|
||||||
|
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
|
||||||
@ -1646,7 +1655,8 @@ qemudParseVMDef(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_vm *
|
struct qemud_vm *
|
||||||
qemudAssignVMDef(struct qemud_driver *driver,
|
qemudAssignVMDef(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_vm_def *def)
|
struct qemud_vm_def *def)
|
||||||
{
|
{
|
||||||
struct qemud_vm *vm = NULL;
|
struct qemud_vm *vm = NULL;
|
||||||
@ -1665,7 +1675,7 @@ qemudAssignVMDef(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(vm = calloc(1, sizeof(struct qemud_vm)))) {
|
if (!(vm = calloc(1, sizeof(struct qemud_vm)))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "vm");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "vm");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1709,14 +1719,15 @@ qemudRemoveInactiveVM(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
qemudSaveVMDef(struct qemud_driver *driver,
|
qemudSaveVMDef(virConnectPtr conn,
|
||||||
|
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(driver->configDir))) {
|
if ((err = qemudEnsureDir(driver->configDir))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create config directory %s: %s",
|
"cannot create config directory %s: %s",
|
||||||
driver->configDir, strerror(err));
|
driver->configDir, strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
@ -1724,24 +1735,25 @@ qemudSaveVMDef(struct qemud_driver *driver,
|
|||||||
|
|
||||||
if (qemudMakeConfigPath(driver->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(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot construct config file path");
|
"cannot construct config file path");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudMakeConfigPath(driver->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(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot construct autostart link path");
|
"cannot construct autostart link path");
|
||||||
vm->configFile[0] = '\0';
|
vm->configFile[0] = '\0';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return qemudSaveConfig(driver, vm, def);
|
return qemudSaveConfig(conn, driver, vm, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudSaveNetworkConfig(struct qemud_driver *driver,
|
static int qemudSaveNetworkConfig(virConnectPtr conn,
|
||||||
|
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;
|
||||||
@ -1749,12 +1761,12 @@ static int qemudSaveNetworkConfig(struct qemud_driver *driver,
|
|||||||
int towrite;
|
int towrite;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!(xml = qemudGenerateNetworkXML(driver, network, def))) {
|
if (!(xml = qemudGenerateNetworkXML(conn, driver, network, def))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = qemudEnsureDir(driver->networkConfigDir))) {
|
if ((err = qemudEnsureDir(driver->networkConfigDir))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create config directory %s: %s",
|
"cannot create config directory %s: %s",
|
||||||
driver->networkConfigDir, strerror(err));
|
driver->networkConfigDir, strerror(err));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1763,7 +1775,7 @@ static int qemudSaveNetworkConfig(struct qemud_driver *driver,
|
|||||||
if ((fd = open(network->configFile,
|
if ((fd = open(network->configFile,
|
||||||
O_WRONLY | O_CREAT | O_TRUNC,
|
O_WRONLY | O_CREAT | O_TRUNC,
|
||||||
S_IRUSR | S_IWUSR )) < 0) {
|
S_IRUSR | S_IWUSR )) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create config file %s: %s",
|
"cannot create config file %s: %s",
|
||||||
network->configFile, strerror(errno));
|
network->configFile, strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1771,14 +1783,14 @@ static int qemudSaveNetworkConfig(struct qemud_driver *driver,
|
|||||||
|
|
||||||
towrite = strlen(xml);
|
towrite = strlen(xml);
|
||||||
if (write(fd, xml, towrite) != towrite) {
|
if (write(fd, xml, towrite) != towrite) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot write config file %s: %s",
|
"cannot write config file %s: %s",
|
||||||
network->configFile, strerror(errno));
|
network->configFile, strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot save config file %s: %s",
|
"cannot save config file %s: %s",
|
||||||
network->configFile, strerror(errno));
|
network->configFile, strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1842,7 +1854,8 @@ static int qemudParseBridgeXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudParseDhcpRangesXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
static int qemudParseDhcpRangesXML(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
struct qemud_network_def *def,
|
struct qemud_network_def *def,
|
||||||
xmlNodePtr node) {
|
xmlNodePtr node) {
|
||||||
|
|
||||||
@ -1860,7 +1873,7 @@ static int qemudParseDhcpRangesXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(range = calloc(1, sizeof(struct qemud_dhcp_range_def)))) {
|
if (!(range = calloc(1, sizeof(struct qemud_dhcp_range_def)))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "range");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "range");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1892,7 +1905,8 @@ static int qemudParseDhcpRangesXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudParseInetXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
static int qemudParseInetXML(virConnectPtr conn,
|
||||||
|
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;
|
||||||
@ -1933,7 +1947,7 @@ static int qemudParseInetXML(struct qemud_driver *driver 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(driver, def, cur))
|
!qemudParseDhcpRangesXML(conn, driver, def, cur))
|
||||||
return 0;
|
return 0;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
@ -1942,7 +1956,8 @@ static int qemudParseInetXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *driver,
|
static struct qemud_network_def *qemudParseNetworkXML(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
xmlDocPtr xml) {
|
xmlDocPtr xml) {
|
||||||
xmlNodePtr root = NULL;
|
xmlNodePtr root = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
@ -1950,20 +1965,20 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *drive
|
|||||||
struct qemud_network_def *def;
|
struct qemud_network_def *def;
|
||||||
|
|
||||||
if (!(def = calloc(1, sizeof(struct qemud_network_def)))) {
|
if (!(def = calloc(1, sizeof(struct qemud_network_def)))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "network_def");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network_def");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare parser / xpath context */
|
/* Prepare parser / xpath context */
|
||||||
root = xmlDocGetRootElement(xml);
|
root = xmlDocGetRootElement(xml);
|
||||||
if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "network"))) {
|
if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "network"))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt = xmlXPathNewContext(xml);
|
ctxt = xmlXPathNewContext(xml);
|
||||||
if (ctxt == NULL) {
|
if (ctxt == NULL) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1972,11 +1987,11 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *drive
|
|||||||
obj = xmlXPathEval(BAD_CAST "string(/network/name[1])", ctxt);
|
obj = xmlXPathEval(BAD_CAST "string(/network/name[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)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_NAME, NULL);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_NAME, NULL);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (strlen((const char *)obj->stringval) >= (QEMUD_MAX_NAME_LEN-1)) {
|
if (strlen((const char *)obj->stringval) >= (QEMUD_MAX_NAME_LEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "network name length too long");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "network name length too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(def->name, (const char *)obj->stringval);
|
strcpy(def->name, (const char *)obj->stringval);
|
||||||
@ -1989,12 +2004,12 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *drive
|
|||||||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
||||||
int err;
|
int err;
|
||||||
if ((err = virUUIDGenerate(def->uuid))) {
|
if ((err = virUUIDGenerate(def->uuid))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Failed to generate UUID: %s", strerror(err));
|
"Failed to generate UUID: %s", strerror(err));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else if (virUUIDParse((const char *)obj->stringval, def->uuid) < 0) {
|
} else if (virUUIDParse((const char *)obj->stringval, def->uuid) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
@ -2013,7 +2028,7 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *drive
|
|||||||
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(driver, def, obj->nodesetval->nodeTab[0])) {
|
if (!qemudParseInetXML(conn, driver, def, obj->nodesetval->nodeTab[0])) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2025,7 +2040,7 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *drive
|
|||||||
obj->boolval) {
|
obj->boolval) {
|
||||||
if (!def->ipAddress[0] ||
|
if (!def->ipAddress[0] ||
|
||||||
!def->netmask[0]) {
|
!def->netmask[0]) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Forwarding requested, but no IPv4 address/netmask provided");
|
"Forwarding requested, but no IPv4 address/netmask provided");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -2036,7 +2051,7 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *drive
|
|||||||
(tmp->stringval != NULL) && (tmp->stringval[0] != 0)) {
|
(tmp->stringval != NULL) && (tmp->stringval[0] != 0)) {
|
||||||
int len;
|
int len;
|
||||||
if ((len = xmlStrlen(tmp->stringval)) >= (BR_IFNAME_MAXLEN-1)) {
|
if ((len = xmlStrlen(tmp->stringval)) >= (BR_IFNAME_MAXLEN-1)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"forward device name '%s' is too long",
|
"forward device name '%s' is too long",
|
||||||
(char*)tmp->stringval);
|
(char*)tmp->stringval);
|
||||||
goto error;
|
goto error;
|
||||||
@ -2070,7 +2085,8 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *drive
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_network_def *
|
struct qemud_network_def *
|
||||||
qemudParseNetworkDef(struct qemud_driver *driver,
|
qemudParseNetworkDef(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
const char *displayName) {
|
const char *displayName) {
|
||||||
xmlDocPtr xml;
|
xmlDocPtr xml;
|
||||||
@ -2079,11 +2095,11 @@ qemudParseNetworkDef(struct qemud_driver *driver,
|
|||||||
if (!(xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : "network.xml", NULL,
|
if (!(xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : "network.xml", NULL,
|
||||||
XML_PARSE_NOENT | XML_PARSE_NONET |
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) {
|
XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
def = qemudParseNetworkXML(driver, xml);
|
def = qemudParseNetworkXML(conn, driver, xml);
|
||||||
|
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
|
||||||
@ -2091,7 +2107,8 @@ qemudParseNetworkDef(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_network *
|
struct qemud_network *
|
||||||
qemudAssignNetworkDef(struct qemud_driver *driver,
|
qemudAssignNetworkDef(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_network_def *def) {
|
struct qemud_network_def *def) {
|
||||||
struct qemud_network *network;
|
struct qemud_network *network;
|
||||||
|
|
||||||
@ -2109,7 +2126,7 @@ qemudAssignNetworkDef(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(network = calloc(1, sizeof(struct qemud_network)))) {
|
if (!(network = calloc(1, sizeof(struct qemud_network)))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "network");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2147,7 +2164,8 @@ qemudRemoveInactiveNetwork(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
qemudSaveNetworkDef(struct qemud_driver *driver,
|
qemudSaveNetworkDef(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_network *network,
|
struct qemud_network *network,
|
||||||
struct qemud_network_def *def) {
|
struct qemud_network_def *def) {
|
||||||
|
|
||||||
@ -2155,7 +2173,7 @@ qemudSaveNetworkDef(struct qemud_driver *driver,
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((err = qemudEnsureDir(driver->networkConfigDir))) {
|
if ((err = qemudEnsureDir(driver->networkConfigDir))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create config directory %s: %s",
|
"cannot create config directory %s: %s",
|
||||||
driver->networkConfigDir, strerror(err));
|
driver->networkConfigDir, strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
@ -2163,21 +2181,21 @@ qemudSaveNetworkDef(struct qemud_driver *driver,
|
|||||||
|
|
||||||
if (qemudMakeConfigPath(driver->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(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot construct config file path");
|
"cannot construct config file path");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudMakeConfigPath(driver->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(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot construct autostart link path");
|
"cannot construct autostart link path");
|
||||||
network->configFile[0] = '\0';
|
network->configFile[0] = '\0';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return qemudSaveNetworkConfig(driver, network, def);
|
return qemudSaveNetworkConfig(conn, driver, network, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2358,7 +2376,7 @@ qemudLoadConfig(struct qemud_driver *driver,
|
|||||||
struct qemud_vm_def *def;
|
struct qemud_vm_def *def;
|
||||||
struct qemud_vm *vm;
|
struct qemud_vm *vm;
|
||||||
|
|
||||||
if (!(def = qemudParseVMDef(driver, xml, file))) {
|
if (!(def = qemudParseVMDef(NULL, 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);
|
||||||
@ -2372,7 +2390,7 @@ qemudLoadConfig(struct qemud_driver *driver,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(vm = qemudAssignVMDef(driver, def))) {
|
if (!(vm = qemudAssignVMDef(NULL, 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;
|
||||||
@ -2398,7 +2416,7 @@ qemudLoadNetworkConfig(struct qemud_driver *driver,
|
|||||||
struct qemud_network_def *def;
|
struct qemud_network_def *def;
|
||||||
struct qemud_network *network;
|
struct qemud_network *network;
|
||||||
|
|
||||||
if (!(def = qemudParseNetworkDef(driver, xml, file))) {
|
if (!(def = qemudParseNetworkDef(NULL, 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);
|
||||||
@ -2412,7 +2430,7 @@ qemudLoadNetworkConfig(struct qemud_driver *driver,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(network = qemudAssignNetworkDef(driver, def))) {
|
if (!(network = qemudAssignNetworkDef(NULL, 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;
|
||||||
@ -2494,7 +2512,8 @@ int qemudScanConfigs(struct qemud_driver *driver) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate an XML document describing the guest's configuration */
|
/* Generate an XML document describing the guest's configuration */
|
||||||
char *qemudGenerateXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
char *qemudGenerateXML(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
struct qemud_vm_def *def,
|
struct qemud_vm_def *def,
|
||||||
int live) {
|
int live) {
|
||||||
@ -2521,7 +2540,7 @@ char *qemudGenerateXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!type) {
|
if (!type) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "unexpected domain type %d", def->virtType);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "unexpected domain type %d", def->virtType);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2765,14 +2784,15 @@ char *qemudGenerateXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
return virBufferContentAndFree (buf);
|
return virBufferContentAndFree (buf);
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
|
||||||
cleanup:
|
cleanup:
|
||||||
if (buf) virBufferFree (buf);
|
if (buf) virBufferFree (buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *qemudGenerateNetworkXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
char *qemudGenerateNetworkXML(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
struct qemud_network *network,
|
struct qemud_network *network,
|
||||||
struct qemud_network_def *def) {
|
struct qemud_network_def *def) {
|
||||||
virBufferPtr buf = 0;
|
virBufferPtr buf = 0;
|
||||||
@ -2857,22 +2877,23 @@ char *qemudGenerateNetworkXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
return virBufferContentAndFree (buf);
|
return virBufferContentAndFree (buf);
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
|
||||||
if (buf) virBufferFree (buf);
|
if (buf) virBufferFree (buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int qemudDeleteConfig(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
int qemudDeleteConfig(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
const char *configFile,
|
const char *configFile,
|
||||||
const char *name) {
|
const char *name) {
|
||||||
if (!configFile[0]) {
|
if (!configFile[0]) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no config file for %s", name);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no config file for %s", name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlink(configFile) < 0) {
|
if (unlink(configFile) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot remove config for %s", name);
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot remove config for %s", name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,13 +299,16 @@ struct qemud_network *qemudFindNetworkByUUID(const struct qemud_driver *driver,
|
|||||||
struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
|
struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver,
|
||||||
const char *name);
|
const char *name);
|
||||||
|
|
||||||
int qemudExtractVersion (struct qemud_driver *driver);
|
int qemudExtractVersion (virConnectPtr conn,
|
||||||
int qemudBuildCommandLine (struct qemud_driver *driver,
|
struct qemud_driver *driver);
|
||||||
|
int qemudBuildCommandLine (virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
char ***argv);
|
char ***argv);
|
||||||
|
|
||||||
int qemudScanConfigs (struct qemud_driver *driver);
|
int qemudScanConfigs (struct qemud_driver *driver);
|
||||||
int qemudDeleteConfig (struct qemud_driver *driver,
|
int qemudDeleteConfig (virConnectPtr conn,
|
||||||
|
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);
|
||||||
@ -314,19 +317,23 @@ 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_driver *driver,
|
qemudAssignVMDef (virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_vm_def *def);
|
struct qemud_vm_def *def);
|
||||||
void qemudRemoveInactiveVM (struct qemud_driver *driver,
|
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_driver *driver,
|
qemudParseVMDef (virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
const char *displayName);
|
const char *displayName);
|
||||||
int qemudSaveVMDef (struct qemud_driver *driver,
|
int qemudSaveVMDef (virConnectPtr conn,
|
||||||
|
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_driver *driver,
|
char * qemudGenerateXML (virConnectPtr conn,
|
||||||
|
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);
|
||||||
@ -335,19 +342,23 @@ 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_driver *driver,
|
qemudAssignNetworkDef (virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_network_def *def);
|
struct qemud_network_def *def);
|
||||||
void qemudRemoveInactiveNetwork (struct qemud_driver *driver,
|
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_driver *driver,
|
qemudParseNetworkDef (virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
const char *displayName);
|
const char *displayName);
|
||||||
int qemudSaveNetworkDef (struct qemud_driver *driver,
|
int qemudSaveNetworkDef (virConnectPtr conn,
|
||||||
|
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_driver *driver,
|
char * qemudGenerateNetworkXML (virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_network *network,
|
struct qemud_network *network,
|
||||||
struct qemud_network_def *def);
|
struct qemud_network_def *def);
|
||||||
|
|
||||||
|
@ -87,17 +87,21 @@ static int qemudSetNonBlock(int fd) {
|
|||||||
|
|
||||||
|
|
||||||
static void qemudDispatchVMEvent(int fd, int events, void *opaque);
|
static void qemudDispatchVMEvent(int fd, int events, void *opaque);
|
||||||
static int qemudStartVMDaemon(struct qemud_driver *driver,
|
static int qemudStartVMDaemon(virConnectPtr conn,
|
||||||
struct qemud_vm *vm);
|
struct qemud_driver *driver,
|
||||||
|
struct qemud_vm *vm);
|
||||||
|
|
||||||
static int qemudShutdownVMDaemon(struct qemud_driver *driver,
|
static int qemudShutdownVMDaemon(virConnectPtr conn,
|
||||||
struct qemud_vm *vm);
|
struct qemud_driver *driver,
|
||||||
|
struct qemud_vm *vm);
|
||||||
|
|
||||||
static int qemudStartNetworkDaemon(struct qemud_driver *driver,
|
static int qemudStartNetworkDaemon(virConnectPtr conn,
|
||||||
struct qemud_network *network);
|
struct qemud_driver *driver,
|
||||||
|
struct qemud_network *network);
|
||||||
|
|
||||||
static int qemudShutdownNetworkDaemon(struct qemud_driver *driver,
|
static int qemudShutdownNetworkDaemon(virConnectPtr conn,
|
||||||
struct qemud_network *network);
|
struct qemud_driver *driver,
|
||||||
|
struct qemud_network *network);
|
||||||
|
|
||||||
struct qemud_driver *qemu_driver = NULL;
|
struct qemud_driver *qemu_driver = NULL;
|
||||||
|
|
||||||
@ -113,7 +117,7 @@ void qemudAutostartConfigs(struct qemud_driver *driver) {
|
|||||||
|
|
||||||
if (network->autostart &&
|
if (network->autostart &&
|
||||||
!qemudIsActiveNetwork(network) &&
|
!qemudIsActiveNetwork(network) &&
|
||||||
qemudStartNetworkDaemon(driver, network) < 0) {
|
qemudStartNetworkDaemon(NULL, driver, network) < 0) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
qemudLog(QEMUD_ERR, "Failed to autostart network '%s': %s",
|
qemudLog(QEMUD_ERR, "Failed to autostart network '%s': %s",
|
||||||
network->def->name, err->message);
|
network->def->name, err->message);
|
||||||
@ -128,7 +132,7 @@ void qemudAutostartConfigs(struct qemud_driver *driver) {
|
|||||||
|
|
||||||
if (vm->autostart &&
|
if (vm->autostart &&
|
||||||
!qemudIsActiveVM(vm) &&
|
!qemudIsActiveVM(vm) &&
|
||||||
qemudStartVMDaemon(driver, vm) < 0) {
|
qemudStartVMDaemon(NULL, driver, vm) < 0) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
qemudLog(QEMUD_ERR, "Failed to autostart VM '%s': %s",
|
qemudLog(QEMUD_ERR, "Failed to autostart VM '%s': %s",
|
||||||
vm->def->name, err->message);
|
vm->def->name, err->message);
|
||||||
@ -271,7 +275,7 @@ qemudShutdown(void) {
|
|||||||
while (vm) {
|
while (vm) {
|
||||||
struct qemud_vm *next = vm->next;
|
struct qemud_vm *next = vm->next;
|
||||||
if (qemudIsActiveVM(vm))
|
if (qemudIsActiveVM(vm))
|
||||||
qemudShutdownVMDaemon(qemu_driver, vm);
|
qemudShutdownVMDaemon(NULL, qemu_driver, vm);
|
||||||
vm = next;
|
vm = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +295,7 @@ qemudShutdown(void) {
|
|||||||
while (network) {
|
while (network) {
|
||||||
struct qemud_network *next = network->next;
|
struct qemud_network *next = network->next;
|
||||||
if (qemudIsActiveNetwork(network))
|
if (qemudIsActiveNetwork(network))
|
||||||
qemudShutdownNetworkDaemon(qemu_driver, network);
|
qemudShutdownNetworkDaemon(NULL, qemu_driver, network);
|
||||||
network = next;
|
network = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,27 +331,28 @@ qemudShutdown(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemudExec(char **argv,
|
qemudExec(virConnectPtr conn,
|
||||||
|
char **argv,
|
||||||
int *retpid, int *outfd, int *errfd) {
|
int *retpid, int *outfd, int *errfd) {
|
||||||
int pid, null;
|
int pid, null;
|
||||||
int pipeout[2] = {-1,-1};
|
int pipeout[2] = {-1,-1};
|
||||||
int pipeerr[2] = {-1,-1};
|
int pipeerr[2] = {-1,-1};
|
||||||
|
|
||||||
if ((null = open(_PATH_DEVNULL, O_RDONLY)) < 0) {
|
if ((null = open(_PATH_DEVNULL, O_RDONLY)) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot open %s : %s",
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot open %s : %s",
|
||||||
_PATH_DEVNULL, strerror(errno));
|
_PATH_DEVNULL, strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((outfd != NULL && pipe(pipeout) < 0) ||
|
if ((outfd != NULL && pipe(pipeout) < 0) ||
|
||||||
(errfd != NULL && pipe(pipeerr) < 0)) {
|
(errfd != NULL && pipe(pipeerr) < 0)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create pipe : %s",
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create pipe : %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pid = fork()) < 0) {
|
if ((pid = fork()) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot fork child process : %s",
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot fork child process : %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -411,13 +416,15 @@ qemudExec(char **argv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Return -1 for error, 1 to continue reading and 0 for success */
|
/* Return -1 for error, 1 to continue reading and 0 for success */
|
||||||
typedef int qemudHandlerMonitorOutput(struct qemud_driver *driver,
|
typedef int qemudHandlerMonitorOutput(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
const char *output,
|
const char *output,
|
||||||
int fd);
|
int fd);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemudReadMonitorOutput(struct qemud_driver *driver,
|
qemudReadMonitorOutput(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
int fd,
|
int fd,
|
||||||
char *buf,
|
char *buf,
|
||||||
@ -436,7 +443,7 @@ qemudReadMonitorOutput(struct qemud_driver *driver,
|
|||||||
|
|
||||||
ret = read(fd, buf+got, buflen-got-1);
|
ret = read(fd, buf+got, buflen-got-1);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"QEMU quit during %s startup\n%s", what, buf);
|
"QEMU quit during %s startup\n%s", what, buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -446,7 +453,7 @@ qemudReadMonitorOutput(struct qemud_driver *driver,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (errno != EAGAIN) {
|
if (errno != EAGAIN) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Failure while reading %s startup output: %s",
|
"Failure while reading %s startup output: %s",
|
||||||
what, strerror(errno));
|
what, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
@ -454,12 +461,12 @@ qemudReadMonitorOutput(struct qemud_driver *driver,
|
|||||||
|
|
||||||
ret = poll(&pfd, 1, MONITOR_TIMEOUT);
|
ret = poll(&pfd, 1, MONITOR_TIMEOUT);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Timed out while reading %s startup output", what);
|
"Timed out while reading %s startup output", what);
|
||||||
return -1;
|
return -1;
|
||||||
} else if (ret == -1) {
|
} else if (ret == -1) {
|
||||||
if (errno != EINTR) {
|
if (errno != EINTR) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Failure while reading %s startup output: %s",
|
"Failure while reading %s startup output: %s",
|
||||||
what, strerror(errno));
|
what, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
@ -470,19 +477,19 @@ qemudReadMonitorOutput(struct qemud_driver *driver,
|
|||||||
if (pfd.revents & (POLLIN | POLLHUP))
|
if (pfd.revents & (POLLIN | POLLHUP))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Failure while reading %s startup output", what);
|
"Failure while reading %s startup output", what);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
got += ret;
|
got += ret;
|
||||||
buf[got] = '\0';
|
buf[got] = '\0';
|
||||||
if ((ret = func(driver, vm, buf, fd)) != 1)
|
if ((ret = func(conn, driver, vm, buf, fd)) != 1)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Out of space while reading %s startup output", what);
|
"Out of space while reading %s startup output", what);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -490,7 +497,8 @@ qemudReadMonitorOutput(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemudCheckMonitorPrompt(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
qemudCheckMonitorPrompt(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
|
struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
const char *output,
|
const char *output,
|
||||||
int fd)
|
int fd)
|
||||||
@ -503,28 +511,32 @@ qemudCheckMonitorPrompt(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudOpenMonitor(struct qemud_driver *driver, struct qemud_vm *vm, const char *monitor) {
|
static int qemudOpenMonitor(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
|
struct qemud_vm *vm,
|
||||||
|
const char *monitor) {
|
||||||
int monfd;
|
int monfd;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(monfd = open(monitor, O_RDWR))) {
|
if (!(monfd = open(monitor, O_RDWR))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Unable to open monitor path %s", monitor);
|
"Unable to open monitor path %s", monitor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (qemudSetCloseExec(monfd) < 0) {
|
if (qemudSetCloseExec(monfd) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Unable to set monitor close-on-exec flag");
|
"Unable to set monitor close-on-exec flag");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (qemudSetNonBlock(monfd) < 0) {
|
if (qemudSetNonBlock(monfd) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Unable to put monitor into non-blocking mode");
|
"Unable to put monitor into non-blocking mode");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemudReadMonitorOutput(driver, vm, monfd,
|
ret = qemudReadMonitorOutput(conn,
|
||||||
|
driver, vm, monfd,
|
||||||
buf, sizeof(buf),
|
buf, sizeof(buf),
|
||||||
qemudCheckMonitorPrompt,
|
qemudCheckMonitorPrompt,
|
||||||
"monitor");
|
"monitor");
|
||||||
@ -564,7 +576,8 @@ static int qemudExtractMonitorPath(const char *haystack, char *path, int pathmax
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemudOpenMonitorPath(struct qemud_driver *driver,
|
qemudOpenMonitorPath(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_vm *vm,
|
struct qemud_vm *vm,
|
||||||
const char *output,
|
const char *output,
|
||||||
int fd ATTRIBUTE_UNUSED)
|
int fd ATTRIBUTE_UNUSED)
|
||||||
@ -574,12 +587,15 @@ qemudOpenMonitorPath(struct qemud_driver *driver,
|
|||||||
if (qemudExtractMonitorPath(output, monitor, sizeof(monitor)) < 0)
|
if (qemudExtractMonitorPath(output, monitor, sizeof(monitor)) < 0)
|
||||||
return 1; /* keep reading */
|
return 1; /* keep reading */
|
||||||
|
|
||||||
return qemudOpenMonitor(driver, vm, monitor);
|
return qemudOpenMonitor(conn, driver, vm, monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudWaitForMonitor(struct qemud_driver *driver, struct qemud_vm *vm) {
|
static int qemudWaitForMonitor(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
|
struct qemud_vm *vm) {
|
||||||
char buf[1024]; /* Plenty of space to get startup greeting */
|
char buf[1024]; /* Plenty of space to get startup greeting */
|
||||||
int ret = qemudReadMonitorOutput(driver, vm, vm->stderr,
|
int ret = qemudReadMonitorOutput(conn,
|
||||||
|
driver, vm, vm->stderr,
|
||||||
buf, sizeof(buf),
|
buf, sizeof(buf),
|
||||||
qemudOpenMonitorPath,
|
qemudOpenMonitorPath,
|
||||||
"console");
|
"console");
|
||||||
@ -593,7 +609,6 @@ static int qemudWaitForMonitor(struct qemud_driver *driver, struct qemud_vm *vm)
|
|||||||
qemudLog(QEMUD_WARN, "Unable to log VM console data: %s",
|
qemudLog(QEMUD_WARN, "Unable to log VM console data: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,14 +648,15 @@ static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudStartVMDaemon(struct qemud_driver *driver,
|
static int qemudStartVMDaemon(virConnectPtr conn,
|
||||||
struct qemud_vm *vm) {
|
struct qemud_driver *driver,
|
||||||
|
struct qemud_vm *vm) {
|
||||||
char **argv = NULL, **tmp;
|
char **argv = NULL, **tmp;
|
||||||
int i;
|
int i;
|
||||||
char logfile[PATH_MAX];
|
char logfile[PATH_MAX];
|
||||||
|
|
||||||
if (qemudIsActiveVM(vm)) {
|
if (qemudIsActiveVM(vm)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"VM is already active");
|
"VM is already active");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -648,7 +664,7 @@ static int qemudStartVMDaemon(struct qemud_driver *driver,
|
|||||||
if (vm->def->vncPort < 0) {
|
if (vm->def->vncPort < 0) {
|
||||||
int port = qemudNextFreeVNCPort(driver);
|
int port = qemudNextFreeVNCPort(driver);
|
||||||
if (port < 0) {
|
if (port < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"Unable to find an unused VNC port");
|
"Unable to find an unused VNC port");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -661,7 +677,7 @@ static int qemudStartVMDaemon(struct qemud_driver *driver,
|
|||||||
strlen(vm->def->name) + /* basename */
|
strlen(vm->def->name) + /* basename */
|
||||||
4 + /* suffix .log */
|
4 + /* suffix .log */
|
||||||
1 /* NULL */) > PATH_MAX) {
|
1 /* NULL */) > PATH_MAX) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"config file path too long: %s/%s.log",
|
"config file path too long: %s/%s.log",
|
||||||
driver->logDir, vm->def->name);
|
driver->logDir, vm->def->name);
|
||||||
return -1;
|
return -1;
|
||||||
@ -672,7 +688,7 @@ static int qemudStartVMDaemon(struct qemud_driver *driver,
|
|||||||
strcat(logfile, ".log");
|
strcat(logfile, ".log");
|
||||||
|
|
||||||
if (qemudEnsureDir(driver->logDir) < 0) {
|
if (qemudEnsureDir(driver->logDir) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create log directory %s: %s",
|
"cannot create log directory %s: %s",
|
||||||
driver->logDir, strerror(errno));
|
driver->logDir, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
@ -680,13 +696,13 @@ static int qemudStartVMDaemon(struct qemud_driver *driver,
|
|||||||
|
|
||||||
if ((vm->logfile = open(logfile, O_CREAT | O_TRUNC | O_WRONLY,
|
if ((vm->logfile = open(logfile, O_CREAT | O_TRUNC | O_WRONLY,
|
||||||
S_IRUSR | S_IWUSR)) < 0) {
|
S_IRUSR | S_IWUSR)) < 0) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to create logfile %s: %s",
|
"failed to create logfile %s: %s",
|
||||||
logfile, strerror(errno));
|
logfile, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudBuildCommandLine(driver, vm, &argv) < 0) {
|
if (qemudBuildCommandLine(conn, driver, vm, &argv) < 0) {
|
||||||
close(vm->logfile);
|
close(vm->logfile);
|
||||||
vm->logfile = -1;
|
vm->logfile = -1;
|
||||||
return -1;
|
return -1;
|
||||||
@ -706,7 +722,7 @@ static int qemudStartVMDaemon(struct qemud_driver *driver,
|
|||||||
qemudLog(QEMUD_WARN, "Unable to write argv to logfile %d: %s",
|
qemudLog(QEMUD_WARN, "Unable to write argv to logfile %d: %s",
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
|
|
||||||
if (qemudExec(argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
|
if (qemudExec(conn, argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
|
||||||
vm->id = driver->nextvmid++;
|
vm->id = driver->nextvmid++;
|
||||||
vm->state = VIR_DOMAIN_RUNNING;
|
vm->state = VIR_DOMAIN_RUNNING;
|
||||||
|
|
||||||
@ -732,7 +748,7 @@ static int qemudStartVMDaemon(struct qemud_driver *driver,
|
|||||||
POLLIN | POLLERR | POLLHUP,
|
POLLIN | POLLERR | POLLHUP,
|
||||||
qemudDispatchVMEvent,
|
qemudDispatchVMEvent,
|
||||||
driver) < 0) {
|
driver) < 0) {
|
||||||
qemudShutdownVMDaemon(driver, vm);
|
qemudShutdownVMDaemon(conn, driver, vm);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,13 +756,12 @@ static int qemudStartVMDaemon(struct qemud_driver *driver,
|
|||||||
POLLIN | POLLERR | POLLHUP,
|
POLLIN | POLLERR | POLLHUP,
|
||||||
qemudDispatchVMEvent,
|
qemudDispatchVMEvent,
|
||||||
driver) < 0) {
|
driver) < 0) {
|
||||||
qemudShutdownVMDaemon(driver, vm);
|
qemudShutdownVMDaemon(conn, driver, vm);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (qemudWaitForMonitor(conn, driver, vm) < 0) {
|
||||||
if (qemudWaitForMonitor(driver, vm) < 0) {
|
qemudShutdownVMDaemon(conn, driver, vm);
|
||||||
qemudShutdownVMDaemon(driver, vm);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,7 +800,8 @@ static int qemudVMData(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int qemudShutdownVMDaemon(struct qemud_driver *driver, struct qemud_vm *vm) {
|
static int qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
|
struct qemud_driver *driver, struct qemud_vm *vm) {
|
||||||
if (!qemudIsActiveVM(vm))
|
if (!qemudIsActiveVM(vm))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -838,20 +854,21 @@ static int qemudShutdownVMDaemon(struct qemud_driver *driver, struct qemud_vm *v
|
|||||||
|
|
||||||
static int qemudDispatchVMLog(struct qemud_driver *driver, struct qemud_vm *vm, int fd) {
|
static int qemudDispatchVMLog(struct qemud_driver *driver, struct qemud_vm *vm, int fd) {
|
||||||
if (qemudVMData(driver, vm, fd) < 0)
|
if (qemudVMData(driver, vm, fd) < 0)
|
||||||
if (qemudShutdownVMDaemon(driver, vm) < 0)
|
if (qemudShutdownVMDaemon(NULL, driver, vm) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchVMFailure(struct qemud_driver *driver, struct qemud_vm *vm,
|
static int qemudDispatchVMFailure(struct qemud_driver *driver, struct qemud_vm *vm,
|
||||||
int fd ATTRIBUTE_UNUSED) {
|
int fd ATTRIBUTE_UNUSED) {
|
||||||
if (qemudShutdownVMDaemon(driver, vm) < 0)
|
if (qemudShutdownVMDaemon(NULL, driver, vm) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemudBuildDnsmasqArgv(struct qemud_network *network,
|
qemudBuildDnsmasqArgv(virConnectPtr conn,
|
||||||
|
struct qemud_network *network,
|
||||||
char ***argv) {
|
char ***argv) {
|
||||||
int i, len;
|
int i, len;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
@ -942,28 +959,29 @@ qemudBuildDnsmasqArgv(struct qemud_network *network,
|
|||||||
free((*argv)[i]);
|
free((*argv)[i]);
|
||||||
free(*argv);
|
free(*argv);
|
||||||
}
|
}
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "dnsmasq argv");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "dnsmasq argv");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dhcpStartDhcpDaemon(struct qemud_network *network)
|
dhcpStartDhcpDaemon(virConnectPtr conn,
|
||||||
|
struct qemud_network *network)
|
||||||
{
|
{
|
||||||
char **argv;
|
char **argv;
|
||||||
int ret, i;
|
int ret, i;
|
||||||
|
|
||||||
if (network->def->ipAddress[0] == '\0') {
|
if (network->def->ipAddress[0] == '\0') {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot start dhcp daemon without IP address for server");
|
"cannot start dhcp daemon without IP address for server");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
argv = NULL;
|
argv = NULL;
|
||||||
if (qemudBuildDnsmasqArgv(network, &argv) < 0)
|
if (qemudBuildDnsmasqArgv(conn, network, &argv) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = qemudExec(argv, &network->dnsmasqPid, NULL, NULL);
|
ret = qemudExec(conn, argv, &network->dnsmasqPid, NULL, NULL);
|
||||||
|
|
||||||
for (i = 0; argv[i]; i++)
|
for (i = 0; argv[i]; i++)
|
||||||
free(argv[i]);
|
free(argv[i]);
|
||||||
@ -973,26 +991,27 @@ dhcpStartDhcpDaemon(struct qemud_network *network)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemudAddIptablesRules(struct qemud_driver *driver,
|
qemudAddIptablesRules(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
struct qemud_network *network) {
|
struct qemud_network *network) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!driver->iptables && !(driver->iptables = iptablesContextNew())) {
|
if (!driver->iptables && !(driver->iptables = iptablesContextNew())) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "iptables support");
|
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "iptables support");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* allow DHCP requests through to dnsmasq */
|
/* allow DHCP requests through to dnsmasq */
|
||||||
if ((err = iptablesAddTcpInput(driver->iptables, network->bridge, 67))) {
|
if ((err = iptablesAddTcpInput(driver->iptables, network->bridge, 67))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to allow DHCP requests from '%s' : %s\n",
|
"failed to add iptables rule to allow DHCP requests from '%s' : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = iptablesAddUdpInput(driver->iptables, network->bridge, 67))) {
|
if ((err = iptablesAddUdpInput(driver->iptables, network->bridge, 67))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to allow DHCP requests from '%s' : %s\n",
|
"failed to add iptables rule to allow DHCP requests from '%s' : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err2;
|
goto err2;
|
||||||
@ -1000,14 +1019,14 @@ qemudAddIptablesRules(struct qemud_driver *driver,
|
|||||||
|
|
||||||
/* allow DNS requests through to dnsmasq */
|
/* allow DNS requests through to dnsmasq */
|
||||||
if ((err = iptablesAddTcpInput(driver->iptables, network->bridge, 53))) {
|
if ((err = iptablesAddTcpInput(driver->iptables, network->bridge, 53))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to allow DNS requests from '%s' : %s\n",
|
"failed to add iptables rule to allow DNS requests from '%s' : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err3;
|
goto err3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = iptablesAddUdpInput(driver->iptables, network->bridge, 53))) {
|
if ((err = iptablesAddUdpInput(driver->iptables, network->bridge, 53))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to allow DNS requests from '%s' : %s\n",
|
"failed to add iptables rule to allow DNS requests from '%s' : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err4;
|
goto err4;
|
||||||
@ -1017,14 +1036,14 @@ qemudAddIptablesRules(struct qemud_driver *driver,
|
|||||||
/* Catch all rules to block forwarding to/from bridges */
|
/* Catch all rules to block forwarding to/from bridges */
|
||||||
|
|
||||||
if ((err = iptablesAddForwardRejectOut(driver->iptables, network->bridge))) {
|
if ((err = iptablesAddForwardRejectOut(driver->iptables, network->bridge))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to block outbound traffic from '%s' : %s\n",
|
"failed to add iptables rule to block outbound traffic from '%s' : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err5;
|
goto err5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = iptablesAddForwardRejectIn(driver->iptables, network->bridge))) {
|
if ((err = iptablesAddForwardRejectIn(driver->iptables, network->bridge))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to block inbound traffic to '%s' : %s\n",
|
"failed to add iptables rule to block inbound traffic to '%s' : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err6;
|
goto err6;
|
||||||
@ -1032,7 +1051,7 @@ qemudAddIptablesRules(struct qemud_driver *driver,
|
|||||||
|
|
||||||
/* Allow traffic between guests on the same bridge */
|
/* Allow traffic between guests on the same bridge */
|
||||||
if ((err = iptablesAddForwardAllowCross(driver->iptables, network->bridge))) {
|
if ((err = iptablesAddForwardAllowCross(driver->iptables, network->bridge))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to allow cross bridge traffic on '%s' : %s\n",
|
"failed to add iptables rule to allow cross bridge traffic on '%s' : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err7;
|
goto err7;
|
||||||
@ -1048,7 +1067,7 @@ qemudAddIptablesRules(struct qemud_driver *driver,
|
|||||||
network->def->network,
|
network->def->network,
|
||||||
network->bridge,
|
network->bridge,
|
||||||
network->def->forwardDev))) {
|
network->def->forwardDev))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to allow forwarding from '%s' : %s\n",
|
"failed to add iptables rule to allow forwarding from '%s' : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err8;
|
goto err8;
|
||||||
@ -1059,7 +1078,7 @@ qemudAddIptablesRules(struct qemud_driver *driver,
|
|||||||
network->def->network,
|
network->def->network,
|
||||||
network->bridge,
|
network->bridge,
|
||||||
network->def->forwardDev))) {
|
network->def->forwardDev))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to allow forwarding to '%s' : %s\n",
|
"failed to add iptables rule to allow forwarding to '%s' : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err9;
|
goto err9;
|
||||||
@ -1069,7 +1088,7 @@ qemudAddIptablesRules(struct qemud_driver *driver,
|
|||||||
if ((err = iptablesAddForwardMasquerade(driver->iptables,
|
if ((err = iptablesAddForwardMasquerade(driver->iptables,
|
||||||
network->def->network,
|
network->def->network,
|
||||||
network->def->forwardDev))) {
|
network->def->forwardDev))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to add iptables rule to enable masquerading : %s\n",
|
"failed to add iptables rule to enable masquerading : %s\n",
|
||||||
strerror(err));
|
strerror(err));
|
||||||
goto err10;
|
goto err10;
|
||||||
@ -1153,19 +1172,20 @@ qemudEnableIpForwarding(void)
|
|||||||
#undef PROC_IP_FORWARD
|
#undef PROC_IP_FORWARD
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudStartNetworkDaemon(struct qemud_driver *driver,
|
static int qemudStartNetworkDaemon(virConnectPtr conn,
|
||||||
struct qemud_network *network) {
|
struct qemud_driver *driver,
|
||||||
|
struct qemud_network *network) {
|
||||||
const char *name;
|
const char *name;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (qemudIsActiveNetwork(network)) {
|
if (qemudIsActiveNetwork(network)) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"network is already active");
|
"network is already active");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot initialize bridge support: %s", strerror(err));
|
"cannot initialize bridge support: %s", strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1178,7 +1198,7 @@ static int qemudStartNetworkDaemon(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((err = brAddBridge(driver->brctl, name, network->bridge, sizeof(network->bridge)))) {
|
if ((err = brAddBridge(driver->brctl, name, network->bridge, sizeof(network->bridge)))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot create bridge '%s' : %s", name, strerror(err));
|
"cannot create bridge '%s' : %s", name, strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1186,14 +1206,14 @@ static int qemudStartNetworkDaemon(struct qemud_driver *driver,
|
|||||||
|
|
||||||
if (network->def->forwardDelay &&
|
if (network->def->forwardDelay &&
|
||||||
(err = brSetForwardDelay(driver->brctl, network->bridge, network->def->forwardDelay))) {
|
(err = brSetForwardDelay(driver->brctl, network->bridge, network->def->forwardDelay))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to set bridge forward delay to %d\n",
|
"failed to set bridge forward delay to %d\n",
|
||||||
network->def->forwardDelay);
|
network->def->forwardDelay);
|
||||||
goto err_delbr;
|
goto err_delbr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = brSetForwardDelay(driver->brctl, network->bridge, network->def->disableSTP ? 0 : 1))) {
|
if ((err = brSetForwardDelay(driver->brctl, network->bridge, network->def->disableSTP ? 0 : 1))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to set bridge STP to %s\n",
|
"failed to set bridge STP to %s\n",
|
||||||
network->def->disableSTP ? "off" : "on");
|
network->def->disableSTP ? "off" : "on");
|
||||||
goto err_delbr;
|
goto err_delbr;
|
||||||
@ -1201,7 +1221,7 @@ static int qemudStartNetworkDaemon(struct qemud_driver *driver,
|
|||||||
|
|
||||||
if (network->def->ipAddress[0] &&
|
if (network->def->ipAddress[0] &&
|
||||||
(err = brSetInetAddress(driver->brctl, network->bridge, network->def->ipAddress))) {
|
(err = brSetInetAddress(driver->brctl, network->bridge, network->def->ipAddress))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot set IP address on bridge '%s' to '%s' : %s\n",
|
"cannot set IP address on bridge '%s' to '%s' : %s\n",
|
||||||
network->bridge, network->def->ipAddress, strerror(err));
|
network->bridge, network->def->ipAddress, strerror(err));
|
||||||
goto err_delbr;
|
goto err_delbr;
|
||||||
@ -1209,7 +1229,7 @@ static int qemudStartNetworkDaemon(struct qemud_driver *driver,
|
|||||||
|
|
||||||
if (network->def->netmask[0] &&
|
if (network->def->netmask[0] &&
|
||||||
(err = brSetInetNetmask(driver->brctl, network->bridge, network->def->netmask))) {
|
(err = brSetInetNetmask(driver->brctl, network->bridge, network->def->netmask))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot set netmask on bridge '%s' to '%s' : %s\n",
|
"cannot set netmask on bridge '%s' to '%s' : %s\n",
|
||||||
network->bridge, network->def->netmask, strerror(err));
|
network->bridge, network->def->netmask, strerror(err));
|
||||||
goto err_delbr;
|
goto err_delbr;
|
||||||
@ -1217,24 +1237,24 @@ static int qemudStartNetworkDaemon(struct qemud_driver *driver,
|
|||||||
|
|
||||||
if (network->def->ipAddress[0] &&
|
if (network->def->ipAddress[0] &&
|
||||||
(err = brSetInterfaceUp(driver->brctl, network->bridge, 1))) {
|
(err = brSetInterfaceUp(driver->brctl, network->bridge, 1))) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to bring the bridge '%s' up : %s\n",
|
"failed to bring the bridge '%s' up : %s\n",
|
||||||
network->bridge, strerror(err));
|
network->bridge, strerror(err));
|
||||||
goto err_delbr;
|
goto err_delbr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!qemudAddIptablesRules(driver, network))
|
if (!qemudAddIptablesRules(conn, driver, network))
|
||||||
goto err_delbr1;
|
goto err_delbr1;
|
||||||
|
|
||||||
if (network->def->forward &&
|
if (network->def->forward &&
|
||||||
!qemudEnableIpForwarding()) {
|
!qemudEnableIpForwarding()) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
"failed to enable IP forwarding : %s\n", strerror(err));
|
"failed to enable IP forwarding : %s\n", strerror(err));
|
||||||
goto err_delbr2;
|
goto err_delbr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (network->def->ranges &&
|
if (network->def->ranges &&
|
||||||
dhcpStartDhcpDaemon(network) < 0)
|
dhcpStartDhcpDaemon(conn, network) < 0)
|
||||||
goto err_delbr2;
|
goto err_delbr2;
|
||||||
|
|
||||||
network->active = 1;
|
network->active = 1;
|
||||||
@ -1264,8 +1284,9 @@ static int qemudStartNetworkDaemon(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int qemudShutdownNetworkDaemon(struct qemud_driver *driver,
|
static int qemudShutdownNetworkDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
struct qemud_network *network) {
|
struct qemud_driver *driver,
|
||||||
|
struct qemud_network *network) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
qemudLog(QEMUD_INFO, "Shutting down network '%s'", network->def->name);
|
qemudLog(QEMUD_INFO, "Shutting down network '%s'", network->def->name);
|
||||||
@ -1790,7 +1811,7 @@ static virDomainPtr qemudDomainLookupByName(virConnectPtr conn,
|
|||||||
|
|
||||||
static int qemudGetVersion(virConnectPtr conn, unsigned long *version) {
|
static int qemudGetVersion(virConnectPtr conn, unsigned long *version) {
|
||||||
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
|
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
|
||||||
if (qemudExtractVersion(driver) < 0)
|
if (qemudExtractVersion(conn, driver) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*version = qemu_driver->qemuVersion;
|
*version = qemu_driver->qemuVersion;
|
||||||
@ -1815,21 +1836,21 @@ static int qemudNumDomains(virConnectPtr conn) {
|
|||||||
return driver->nactivevms;
|
return driver->nactivevms;
|
||||||
}
|
}
|
||||||
static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
|
static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
|
||||||
unsigned int flags ATTRIBUTE_UNUSED) {
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
||||||
struct qemud_vm_def *def;
|
struct qemud_vm_def *def;
|
||||||
struct qemud_vm *vm;
|
struct qemud_vm *vm;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
|
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
|
||||||
|
|
||||||
if (!(def = qemudParseVMDef(driver, xml, NULL)))
|
if (!(def = qemudParseVMDef(conn, driver, xml, NULL)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(vm = qemudAssignVMDef(driver, def))) {
|
if (!(vm = qemudAssignVMDef(conn, driver, def))) {
|
||||||
qemudFreeVMDef(def);
|
qemudFreeVMDef(def);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudStartVMDaemon(driver, vm) < 0) {
|
if (qemudStartVMDaemon(conn, driver, vm) < 0) {
|
||||||
qemudRemoveInactiveVM(driver, vm);
|
qemudRemoveInactiveVM(driver, vm);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1902,7 +1923,7 @@ static int qemudDomainDestroy(virDomainPtr dom) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemudShutdownVMDaemon(driver, vm);
|
ret = qemudShutdownVMDaemon(dom->conn, driver, vm);
|
||||||
virFreeDomain(dom->conn, dom);
|
virFreeDomain(dom->conn, dom);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1987,7 +2008,7 @@ static char *qemudDomainDumpXML(virDomainPtr dom,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return qemudGenerateXML(driver, vm, vm->def, 1);
|
return qemudGenerateXML(dom->conn, driver, vm, vm->def, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2031,7 +2052,7 @@ static int qemudDomainStart(virDomainPtr dom) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return qemudStartVMDaemon(driver, vm);
|
return qemudStartVMDaemon(dom->conn, driver, vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2041,15 +2062,15 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
|
|||||||
struct qemud_vm *vm;
|
struct qemud_vm *vm;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
|
|
||||||
if (!(def = qemudParseVMDef(driver, xml, NULL)))
|
if (!(def = qemudParseVMDef(conn, driver, xml, NULL)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(vm = qemudAssignVMDef(driver, def))) {
|
if (!(vm = qemudAssignVMDef(conn, driver, def))) {
|
||||||
qemudFreeVMDef(def);
|
qemudFreeVMDef(def);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudSaveVMDef(driver, vm, def) < 0) {
|
if (qemudSaveVMDef(conn, driver, vm, def) < 0) {
|
||||||
qemudRemoveInactiveVM(driver, vm);
|
qemudRemoveInactiveVM(driver, vm);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2073,7 +2094,7 @@ static int qemudDomainUndefine(virDomainPtr dom) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudDeleteConfig(driver, vm->configFile, vm->def->name) < 0)
|
if (qemudDeleteConfig(dom->conn, driver, vm->configFile, vm->def->name) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (unlink(vm->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR)
|
if (unlink(vm->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR)
|
||||||
@ -2252,15 +2273,15 @@ static virNetworkPtr qemudNetworkCreate(virConnectPtr conn, const char *xml) {
|
|||||||
struct qemud_network *network;
|
struct qemud_network *network;
|
||||||
virNetworkPtr net;
|
virNetworkPtr net;
|
||||||
|
|
||||||
if (!(def = qemudParseNetworkDef(driver, xml, NULL)))
|
if (!(def = qemudParseNetworkDef(conn, driver, xml, NULL)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(network = qemudAssignNetworkDef(driver, def))) {
|
if (!(network = qemudAssignNetworkDef(conn, driver, def))) {
|
||||||
qemudFreeNetworkDef(def);
|
qemudFreeNetworkDef(def);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudStartNetworkDaemon(driver, network) < 0) {
|
if (qemudStartNetworkDaemon(conn, driver, network) < 0) {
|
||||||
qemudRemoveInactiveNetwork(driver, network);
|
qemudRemoveInactiveNetwork(driver, network);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2275,15 +2296,15 @@ static virNetworkPtr qemudNetworkDefine(virConnectPtr conn, const char *xml) {
|
|||||||
struct qemud_network *network;
|
struct qemud_network *network;
|
||||||
virNetworkPtr net;
|
virNetworkPtr net;
|
||||||
|
|
||||||
if (!(def = qemudParseNetworkDef(driver, xml, NULL)))
|
if (!(def = qemudParseNetworkDef(conn, driver, xml, NULL)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(network = qemudAssignNetworkDef(driver, def))) {
|
if (!(network = qemudAssignNetworkDef(conn, driver, def))) {
|
||||||
qemudFreeNetworkDef(def);
|
qemudFreeNetworkDef(def);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudSaveNetworkDef(driver, network, def) < 0) {
|
if (qemudSaveNetworkDef(conn, driver, network, def) < 0) {
|
||||||
qemudRemoveInactiveNetwork(driver, network);
|
qemudRemoveInactiveNetwork(driver, network);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2301,7 +2322,7 @@ static int qemudNetworkUndefine(virNetworkPtr net) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudDeleteConfig(driver, network->configFile, network->def->name) < 0)
|
if (qemudDeleteConfig(net->conn, driver, network->configFile, network->def->name) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR)
|
if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR)
|
||||||
@ -2326,7 +2347,7 @@ static int qemudNetworkStart(virNetworkPtr net) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return qemudStartNetworkDaemon(driver, network);
|
return qemudStartNetworkDaemon(net->conn, driver, network);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudNetworkDestroy(virNetworkPtr net) {
|
static int qemudNetworkDestroy(virNetworkPtr net) {
|
||||||
@ -2340,7 +2361,7 @@ static int qemudNetworkDestroy(virNetworkPtr net) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemudShutdownNetworkDaemon(driver, network);
|
ret = qemudShutdownNetworkDaemon(net->conn, driver, network);
|
||||||
|
|
||||||
virFreeNetwork(net->conn, net);
|
virFreeNetwork(net->conn, net);
|
||||||
|
|
||||||
@ -2357,7 +2378,7 @@ static char *qemudNetworkDumpXML(virNetworkPtr net, int flags ATTRIBUTE_UNUSED)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return qemudGenerateNetworkXML(driver, network, network->def);
|
return qemudGenerateNetworkXML(net->conn, driver, network, network->def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *qemudNetworkGetBridgeName(virNetworkPtr net) {
|
static char *qemudNetworkGetBridgeName(virNetworkPtr net) {
|
||||||
|
Loading…
Reference in New Issue
Block a user