Updated to use virError object & APIs for error reporting

This commit is contained in:
Daniel P. Berrange 2007-06-26 20:51:00 +00:00
parent 2dd21783ec
commit 498cc57835
8 changed files with 220 additions and 182 deletions

View File

@ -1,4 +1,11 @@
Tue Jun 26 16:41:00 EST 2007 Daniel P. Berrange <berrange@redhat.com> Tue Jun 26 16:50:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* qemud/Makefile.am, qemud/conf.c, qemud/dispatch.c, qemud/driver.c,
qemud/driver.h, qemud/internal.h, qemud/qemud.c: Switch over to
use regular libvirt virError objects & APIs for QEMU error
reporting purposes
Tue Jun 26 16:43:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* qemud/driver.c, qemud/driver.h, qemud/qemud.c: Move code * qemud/driver.c, qemud/driver.h, qemud/qemud.c: Move code
handling global startup, shutdown & reload into driver.c handling global startup, shutdown & reload into driver.c

View File

@ -17,6 +17,7 @@ libvirt_qemud_SOURCES = \
protocol.h protocol.c \ protocol.h protocol.c \
remote_protocol.h remote_protocol.c \ remote_protocol.h remote_protocol.c \
remote.c \ remote.c \
../src/virterror.c \
event.c event.h event.c event.h
#-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L #-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L
libvirt_qemud_CFLAGS = \ libvirt_qemud_CFLAGS = \
@ -24,7 +25,9 @@ libvirt_qemud_CFLAGS = \
$(WARN_CFLAGS) -DLOCAL_STATE_DIR="\"$(localstatedir)\"" \ $(WARN_CFLAGS) -DLOCAL_STATE_DIR="\"$(localstatedir)\"" \
-DSYSCONF_DIR="\"$(sysconfdir)\"" \ -DSYSCONF_DIR="\"$(sysconfdir)\"" \
-DQEMUD_PID_FILE="\"$(QEMUD_PID_FILE)\"" \ -DQEMUD_PID_FILE="\"$(QEMUD_PID_FILE)\"" \
-DREMOTE_PID_FILE="\"$(REMOTE_PID_FILE)\"" -DREMOTE_PID_FILE="\"$(REMOTE_PID_FILE)\"" \
-DGETTEXT_PACKAGE=\"$(PACKAGE)\"
libvirt_qemud_LDFLAGS = $(WARN_CFLAGS) $(LIBXML_LIBS) $(SYSFS_LIBS) libvirt_qemud_LDFLAGS = $(WARN_CFLAGS) $(LIBXML_LIBS) $(SYSFS_LIBS)
libvirt_qemud_DEPENDENCIES = ../src/libvirt.la libvirt_qemud_DEPENDENCIES = ../src/libvirt.la
libvirt_qemud_LDADD = ../src/libvirt.la libvirt_qemud_LDADD = ../src/libvirt.la

View File

@ -194,14 +194,14 @@ static char *qemudLocateBinaryForArch(struct qemud_server *server,
name = qemudDefaultBinaryForArch(arch); name = qemudDefaultBinaryForArch(arch);
if (!name) { if (!name) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, "cannot determin binary for architecture %s", arch); qemudReportError(NULL, 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(server, VIR_ERR_NO_MEMORY, "path"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "path");
return NULL; return NULL;
} }
strcpy(path, "/usr/bin/"); strcpy(path, "/usr/bin/");
@ -314,7 +314,7 @@ int qemudExtractVersion(struct qemud_server *server) {
return -1; return -1;
if (stat(binary, &sb) < 0) { if (stat(binary, &sb) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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);
@ -343,7 +343,7 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_server *server,
int typ = 0; int typ = 0;
if (!disk) { if (!disk) {
qemudReportError(server, VIR_ERR_NO_MEMORY, "disk"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "disk");
return NULL; return NULL;
} }
@ -383,11 +383,11 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_server *server,
} }
if (source == NULL) { if (source == NULL) {
qemudReportError(server, VIR_ERR_NO_SOURCE, target ? "%s" : NULL, target); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_SOURCE, target ? "%s" : NULL, target);
goto error; goto error;
} }
if (target == NULL) { if (target == NULL) {
qemudReportError(server, VIR_ERR_NO_TARGET, source ? "%s" : NULL, source); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_TARGET, source ? "%s" : NULL, source);
goto error; goto error;
} }
@ -395,14 +395,14 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_server *server,
!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(server, VIR_ERR_INTERNAL_ERROR, "Invalid floppy device name: %s", target); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "Invalid cdrom device name: %s", target); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid cdrom device name: %s", target);
goto error; goto error;
} }
@ -415,7 +415,7 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "Invalid harddisk device name: %s", target); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid harddisk device name: %s", target);
goto error; goto error;
} }
@ -435,7 +435,7 @@ static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "Invalid device type: %s", device); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid device type: %s", device);
goto error; goto error;
} }
@ -483,7 +483,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
xmlChar *port = NULL; xmlChar *port = NULL;
if (!net) { if (!net) {
qemudReportError(server, VIR_ERR_NO_MEMORY, "net"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "net");
return NULL; return NULL;
} }
@ -573,11 +573,11 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
int len; int len;
if (network == NULL) { if (network == NULL) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Network name '%s' too long", network); "Network name '%s' too long", network);
goto error; goto error;
} else { } else {
@ -592,7 +592,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
if (ifname != NULL) { if (ifname != NULL) {
if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) { if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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 {
@ -607,7 +607,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
if (script != NULL) { if (script != NULL) {
if ((len = xmlStrlen(script)) >= (PATH_MAX-1)) { if ((len = xmlStrlen(script)) >= (PATH_MAX-1)) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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 {
@ -619,7 +619,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
} }
if (ifname != NULL) { if (ifname != NULL) {
if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) { if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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 {
@ -632,11 +632,11 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
int len; int len;
if (bridge == NULL) { if (bridge == NULL) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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 {
@ -649,7 +649,7 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
if (ifname != NULL) { if (ifname != NULL) {
if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) { if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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 {
@ -665,13 +665,13 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
char *ret; char *ret;
if (port == NULL) { if (port == NULL) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
} }
@ -681,12 +681,12 @@ static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_server *serv
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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"IP address '%s' is too long", address); "IP address '%s' is too long", address);
goto error; goto error;
} }
@ -734,27 +734,27 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_NO_MEMORY, "xmlXPathContext"); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element"); qemudReportError(NULL, 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(server, VIR_ERR_NO_MEMORY, "xmlXPathContext"); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "%s", "missing domain type attribute"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "missing domain type attribute");
goto error; goto error;
} }
@ -765,7 +765,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "%s", "invalid domain type attribute"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "invalid domain type attribute");
goto error; goto error;
} }
free(prop); free(prop);
@ -776,11 +776,11 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_NO_NAME, NULL); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "%s", "domain name length too long"); qemudReportError(NULL, 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);
@ -793,12 +793,12 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
(obj->stringval == NULL) || (obj->stringval[0] == 0)) { (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
int err; int err;
if ((err = qemudGenerateUUID(def->uuid))) { if ((err = qemudGenerateUUID(def->uuid))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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 (qemudParseUUID((const char *)obj->stringval, def->uuid) < 0) { } else if (qemudParseUUID((const char *)obj->stringval, def->uuid) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element");
goto error; goto error;
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
@ -808,13 +808,13 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "%s", "missing memory element"); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information");
goto error; goto error;
} }
} }
@ -833,7 +833,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information");
goto error; goto error;
} }
} }
@ -849,7 +849,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "%s", "malformed vcpu information"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed vcpu information");
goto error; goto error;
} }
} }
@ -884,11 +884,11 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_OS_TYPE, NULL); qemudReportError(NULL, 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(server, VIR_ERR_OS_TYPE, "%s", obj->stringval); qemudReportError(NULL, 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);
@ -900,13 +900,13 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
(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(server, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long"); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long"); qemudReportError(NULL, 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);
@ -919,13 +919,13 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
(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(server, VIR_ERR_INTERNAL_ERROR, "%s", "machine type too long"); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long"); qemudReportError(NULL, 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);
@ -938,7 +938,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "%s", "kernel path too long"); qemudReportError(NULL, 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);
@ -951,7 +951,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "%s", "initrd path too long"); qemudReportError(NULL, 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);
@ -964,7 +964,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "%s", "cmdline arguments too long"); qemudReportError(NULL, 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);
@ -1014,7 +1014,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, "%s", "emulator path too long"); qemudReportError(NULL, 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);
@ -1039,7 +1039,7 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
} 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(server, VIR_ERR_INTERNAL_ERROR, "Unsupported graphics type %s", prop); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unsupported graphics type %s", prop);
goto error; goto error;
} }
xmlFree(prop); xmlFree(prop);
@ -1124,11 +1124,11 @@ qemudNetworkIfaceConnect(struct qemud_server *server,
if (net->type == QEMUD_NET_NETWORK) { if (net->type == QEMUD_NET_NETWORK) {
if (!(network = qemudFindNetworkByName(server, net->dst.network.name))) { if (!(network = qemudFindNetworkByName(server, net->dst.network.name))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Network '%s' not found", net->dst.network.name); "Network '%s' not found", net->dst.network.name);
goto error; goto error;
} else if (network->bridge[0] == '\0') { } else if (network->bridge[0] == '\0') {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
} }
@ -1146,20 +1146,20 @@ qemudNetworkIfaceConnect(struct qemud_server *server,
} }
ifname = net->dst.bridge.ifname; ifname = net->dst.bridge.ifname;
} else { } else {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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 (!server->brctl && (err = brInit(&server->brctl))) { if (!server->brctl && (err = brInit(&server->brctl))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot initialize bridge support: %s", strerror(err)); "cannot initialize bridge support: %s", strerror(err));
goto error; goto error;
} }
if ((err = brAddTap(server->brctl, brname, if ((err = brAddTap(server->brctl, brname,
ifname, BR_IFNAME_MAXLEN, &tapfd))) { ifname, BR_IFNAME_MAXLEN, &tapfd))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Failed to add tap interface '%s' to bridge '%s' : %s", "Failed to add tap interface '%s' to bridge '%s' : %s",
ifname, brname, strerror(err)); ifname, brname, strerror(err));
goto error; goto error;
@ -1180,7 +1180,7 @@ qemudNetworkIfaceConnect(struct qemud_server *server,
return retval; return retval;
no_memory: no_memory:
qemudReportError(server, VIR_ERR_NO_MEMORY, "tapfds"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "tapfds");
error: error:
if (retval) if (retval)
free(retval); free(retval);
@ -1233,7 +1233,7 @@ int qemudBuildCommandLine(struct qemud_server *server,
* 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1477,7 +1477,7 @@ int qemudBuildCommandLine(struct qemud_server *server,
return 0; return 0;
no_memory: no_memory:
qemudReportError(server, VIR_ERR_NO_MEMORY, "argv"); qemudReportError(NULL, 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++)
@ -1509,7 +1509,7 @@ static int qemudSaveConfig(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1517,14 +1517,14 @@ static int qemudSaveConfig(struct qemud_server *server,
towrite = strlen(xml); towrite = strlen(xml);
if (write(fd, xml, towrite) != towrite) { if (write(fd, xml, towrite) != towrite) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1551,7 +1551,7 @@ qemudParseVMDef(struct qemud_server *server,
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(server, VIR_ERR_XML_ERROR, NULL); qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
return NULL; return NULL;
} }
@ -1582,7 +1582,7 @@ qemudAssignVMDef(struct qemud_server *server,
} }
if (!(vm = calloc(1, sizeof(struct qemud_vm)))) { if (!(vm = calloc(1, sizeof(struct qemud_vm)))) {
qemudReportError(server, VIR_ERR_NO_MEMORY, "vm"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "vm");
return NULL; return NULL;
} }
@ -1633,7 +1633,7 @@ qemudSaveVMDef(struct qemud_server *server,
int err; int err;
if ((err = qemudEnsureDir(server->configDir))) { if ((err = qemudEnsureDir(server->configDir))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot create config directory %s: %s", "cannot create config directory %s: %s",
server->configDir, strerror(err)); server->configDir, strerror(err));
return -1; return -1;
@ -1641,14 +1641,14 @@ qemudSaveVMDef(struct qemud_server *server,
if (qemudMakeConfigPath(server->configDir, def->name, ".xml", if (qemudMakeConfigPath(server->configDir, def->name, ".xml",
vm->configFile, PATH_MAX) < 0) { vm->configFile, PATH_MAX) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot construct config file path"); "cannot construct config file path");
return -1; return -1;
} }
if (qemudMakeConfigPath(server->autostartDir, def->name, ".xml", if (qemudMakeConfigPath(server->autostartDir, def->name, ".xml",
vm->autostartLink, PATH_MAX) < 0) { vm->autostartLink, PATH_MAX) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1671,7 +1671,7 @@ static int qemudSaveNetworkConfig(struct qemud_server *server,
} }
if ((err = qemudEnsureDir(server->networkConfigDir))) { if ((err = qemudEnsureDir(server->networkConfigDir))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot create config directory %s: %s", "cannot create config directory %s: %s",
server->networkConfigDir, strerror(err)); server->networkConfigDir, strerror(err));
goto cleanup; goto cleanup;
@ -1680,7 +1680,7 @@ static int qemudSaveNetworkConfig(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1688,14 +1688,14 @@ static int qemudSaveNetworkConfig(struct qemud_server *server,
towrite = strlen(xml); towrite = strlen(xml);
if (write(fd, xml, towrite) != towrite) { if (write(fd, xml, towrite) != towrite) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1777,7 +1777,7 @@ static int qemudParseDhcpRangesXML(struct qemud_server *server,
} }
if (!(range = calloc(1, sizeof(struct qemud_dhcp_range_def)))) { if (!(range = calloc(1, sizeof(struct qemud_dhcp_range_def)))) {
qemudReportError(server, VIR_ERR_NO_MEMORY, "range"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "range");
return 0; return 0;
} }
@ -1867,20 +1867,20 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *serve
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(server, VIR_ERR_NO_MEMORY, "network_def"); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element"); qemudReportError(NULL, 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(server, VIR_ERR_NO_MEMORY, "xmlXPathContext"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext");
goto error; goto error;
} }
@ -1889,11 +1889,11 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *serve
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(server, VIR_ERR_NO_NAME, NULL); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "%s", "network name length too long"); qemudReportError(NULL, 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);
@ -1906,12 +1906,12 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *serve
(obj->stringval == NULL) || (obj->stringval[0] == 0)) { (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
int err; int err;
if ((err = qemudGenerateUUID(def->uuid))) { if ((err = qemudGenerateUUID(def->uuid))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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 (qemudParseUUID((const char *)obj->stringval, def->uuid) < 0) { } else if (qemudParseUUID((const char *)obj->stringval, def->uuid) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element");
goto error; goto error;
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
@ -1942,7 +1942,7 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *serve
obj->boolval) { obj->boolval) {
if (!def->ipAddress[0] || if (!def->ipAddress[0] ||
!def->netmask[0]) { !def->netmask[0]) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
} }
@ -1953,7 +1953,7 @@ static struct qemud_network_def *qemudParseNetworkXML(struct qemud_server *serve
(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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1996,7 +1996,7 @@ qemudParseNetworkDef(struct qemud_server *server,
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(server, VIR_ERR_XML_ERROR, NULL); qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
return NULL; return NULL;
} }
@ -2026,7 +2026,7 @@ qemudAssignNetworkDef(struct qemud_server *server,
} }
if (!(network = calloc(1, sizeof(struct qemud_network)))) { if (!(network = calloc(1, sizeof(struct qemud_network)))) {
qemudReportError(server, VIR_ERR_NO_MEMORY, "network"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "network");
return NULL; return NULL;
} }
@ -2072,7 +2072,7 @@ qemudSaveNetworkDef(struct qemud_server *server,
int err; int err;
if ((err = qemudEnsureDir(server->networkConfigDir))) { if ((err = qemudEnsureDir(server->networkConfigDir))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot create config directory %s: %s", "cannot create config directory %s: %s",
server->networkConfigDir, strerror(err)); server->networkConfigDir, strerror(err));
return -1; return -1;
@ -2080,14 +2080,14 @@ qemudSaveNetworkDef(struct qemud_server *server,
if (qemudMakeConfigPath(server->networkConfigDir, def->name, ".xml", if (qemudMakeConfigPath(server->networkConfigDir, def->name, ".xml",
network->configFile, PATH_MAX) < 0) { network->configFile, PATH_MAX) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot construct config file path"); "cannot construct config file path");
return -1; return -1;
} }
if (qemudMakeConfigPath(server->networkAutostartDir, def->name, ".xml", if (qemudMakeConfigPath(server->networkAutostartDir, def->name, ".xml",
network->autostartLink, PATH_MAX) < 0) { network->autostartLink, PATH_MAX) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -2276,8 +2276,9 @@ qemudLoadConfig(struct qemud_server *server,
struct qemud_vm *vm; struct qemud_vm *vm;
if (!(def = qemudParseVMDef(server, xml, file))) { if (!(def = qemudParseVMDef(server, xml, file))) {
virErrorPtr err = virGetLastError();
qemudLog(QEMUD_WARN, "Error parsing QEMU guest config '%s' : %s", qemudLog(QEMUD_WARN, "Error parsing QEMU guest config '%s' : %s",
path, server->errorMessage); path, err->message);
return NULL; return NULL;
} }
@ -2315,8 +2316,9 @@ qemudLoadNetworkConfig(struct qemud_server *server,
struct qemud_network *network; struct qemud_network *network;
if (!(def = qemudParseNetworkDef(server, xml, file))) { if (!(def = qemudParseNetworkDef(server, xml, file))) {
virErrorPtr err = virGetLastError();
qemudLog(QEMUD_WARN, "Error parsing network config '%s' : %s", qemudLog(QEMUD_WARN, "Error parsing network config '%s' : %s",
path, server->errorMessage); path, err->message);
return NULL; return NULL;
} }
@ -2408,9 +2410,11 @@ void qemudAutostartConfigs(struct qemud_server *server) {
if (network->autostart && if (network->autostart &&
!qemudIsActiveNetwork(network) && !qemudIsActiveNetwork(network) &&
qemudStartNetworkDaemon(server, network) < 0) qemudStartNetworkDaemon(server, network) < 0) {
virErrorPtr err = virGetLastError();
qemudLog(QEMUD_ERR, "Failed to autostart network '%s': %s", qemudLog(QEMUD_ERR, "Failed to autostart network '%s': %s",
network->def->name, server->errorMessage); network->def->name, err->message);
}
network = next; network = next;
} }
@ -2421,9 +2425,11 @@ void qemudAutostartConfigs(struct qemud_server *server) {
if (vm->autostart && if (vm->autostart &&
!qemudIsActiveVM(vm) && !qemudIsActiveVM(vm) &&
qemudStartVMDaemon(server, vm) < 0) qemudStartVMDaemon(server, vm) < 0) {
virErrorPtr err = virGetLastError();
qemudLog(QEMUD_ERR, "Failed to autostart VM '%s': %s", qemudLog(QEMUD_ERR, "Failed to autostart VM '%s': %s",
vm->def->name, server->errorMessage); vm->def->name, err->message);
}
vm = next; vm = next;
} }
@ -2470,7 +2476,7 @@ char *qemudGenerateXML(struct qemud_server *server,
break; break;
} }
if (!type) { if (!type) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, "unexpected domain type %d", def->virtType); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "unexpected domain type %d", def->virtType);
goto cleanup; goto cleanup;
} }
@ -2714,7 +2720,7 @@ char *qemudGenerateXML(struct qemud_server *server,
return bufferContentAndFree (buf); return bufferContentAndFree (buf);
no_memory: no_memory:
qemudReportError(server, VIR_ERR_NO_MEMORY, "xml"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
cleanup: cleanup:
if (buf) bufferFree (buf); if (buf) bufferFree (buf);
return NULL; return NULL;
@ -2806,7 +2812,7 @@ char *qemudGenerateNetworkXML(struct qemud_server *server,
return bufferContentAndFree (buf); return bufferContentAndFree (buf);
no_memory: no_memory:
qemudReportError(server, VIR_ERR_NO_MEMORY, "xml"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
if (buf) bufferFree (buf); if (buf) bufferFree (buf);
return NULL; return NULL;
} }
@ -2816,12 +2822,12 @@ int qemudDeleteConfig(struct qemud_server *server,
const char *configFile, const char *configFile,
const char *name) { const char *name) {
if (!configFile[0]) { if (!configFile[0]) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, "no config file for %s", name); qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "cannot remove config for %s", name); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot remove config for %s", name);
return -1; return -1;
} }

View File

@ -39,9 +39,14 @@
static int qemudDispatchFailure(struct qemud_server *server ATTRIBUTE_UNUSED, static int qemudDispatchFailure(struct qemud_server *server ATTRIBUTE_UNUSED,
struct qemud_client *client ATTRIBUTE_UNUSED, struct qemud_client *client ATTRIBUTE_UNUSED,
struct qemud_packet_server_data *out) { struct qemud_packet_server_data *out) {
virErrorPtr err = virGetLastError();
out->type = QEMUD_SERVER_PKT_FAILURE; out->type = QEMUD_SERVER_PKT_FAILURE;
out->qemud_packet_server_data_u.failureReply.code = server->errorCode;
strcpy(out->qemud_packet_server_data_u.failureReply.message, server->errorMessage); out->qemud_packet_server_data_u.failureReply.code = err->code;
strncpy(out->qemud_packet_server_data_u.failureReply.message,
err->message, QEMUD_MAX_ERROR_LEN-1);
out->qemud_packet_server_data_u.failureReply.message[QEMUD_MAX_ERROR_LEN-1] = '\0';
return 0; return 0;
} }
@ -90,7 +95,7 @@ qemudDispatchGetCapabilities (struct qemud_server *server,
char *xml = qemudGetCapabilities(server); char *xml = qemudGetCapabilities(server);
if (strlen(xml) > QEMUD_MAX_XML_LEN) { if (strlen(xml) > QEMUD_MAX_XML_LEN) {
qemudReportError (server, VIR_ERR_XML_ERROR, NULL); qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
qemudDispatchFailure (server, client, out); qemudDispatchFailure (server, client, out);
free(xml); free(xml);
return 0; return 0;
@ -784,8 +789,7 @@ int qemudDispatch(struct qemud_server *server, struct qemud_client *client,
qemudDebug("> Dispatching request type %d, readonly ? %d", qemudDebug("> Dispatching request type %d, readonly ? %d",
in->type, client->readonly); in->type, client->readonly);
server->errorCode = 0; virResetLastError();
server->errorMessage[0] = '\0';
memset(out, 0, sizeof(*out)); memset(out, 0, sizeof(*out));
@ -801,7 +805,7 @@ int qemudDispatch(struct qemud_server *server, struct qemud_client *client,
if (!funcs[type]) { if (!funcs[type]) {
qemudDebug("Illegal operation requested"); qemudDebug("Illegal operation requested");
qemudReportError(server, VIR_ERR_OPERATION_DENIED, NULL); qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_DENIED, NULL);
qemudDispatchFailure(server, client, out); qemudDispatchFailure(server, client, out);
} else { } else {
if ((funcs[type])(server, client, in, out) < 0) { if ((funcs[type])(server, client, in, out) < 0) {

View File

@ -50,17 +50,35 @@
#include "driver.h" #include "driver.h"
#include "conf.h" #include "conf.h"
void qemudReportError(struct qemud_server *server, extern void __virRaiseError(virConnectPtr conn,
virDomainPtr dom,
virNetworkPtr net,
int domain,
int code,
virErrorLevel level,
const char *str1,
const char *str2,
const char *str3,
int int1, int int2, const char *msg, ...)
ATTRIBUTE_FORMAT(printf, 12, 13);
void qemudReportError(virConnectPtr conn,
virDomainPtr dom,
virNetworkPtr net,
int code, const char *fmt, ...) { int code, const char *fmt, ...) {
va_list args; va_list args;
server->errorCode = code; char errorMessage[QEMUD_MAX_ERROR_LEN];
if (fmt) { if (fmt) {
va_start(args, fmt); va_start(args, fmt);
vsnprintf(server->errorMessage, QEMUD_MAX_ERROR_LEN-1, fmt, args); vsnprintf(errorMessage, QEMUD_MAX_ERROR_LEN-1, fmt, args);
va_end(args); va_end(args);
} else { } else {
server->errorMessage[0] = '\0'; errorMessage[0] = '\0';
} }
__virRaiseError(conn, dom, net, VIR_FROM_QEMU, code, VIR_ERR_ERROR,
NULL, NULL, NULL, -1, -1, errorMessage);
} }
static void qemudDispatchVMEvent(int fd, int events, void *opaque); static void qemudDispatchVMEvent(int fd, int events, void *opaque);
@ -159,20 +177,20 @@ qemudExec(struct qemud_server *server, char **argv,
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(server, VIR_ERR_INTERNAL_ERROR, "cannot open %s : %s", qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "cannot create pipe : %s", qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, "cannot fork child process : %s", qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot fork child process : %s",
strerror(errno)); strerror(errno));
goto cleanup; goto cleanup;
} }
@ -261,7 +279,7 @@ qemudReadMonitorOutput(struct qemud_server *server,
ret = read(fd, buf+got, buflen-got-1); ret = read(fd, buf+got, buflen-got-1);
if (ret == 0) { if (ret == 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
} }
@ -271,7 +289,7 @@ qemudReadMonitorOutput(struct qemud_server *server,
continue; continue;
if (errno != EAGAIN) { if (errno != EAGAIN) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -279,12 +297,12 @@ qemudReadMonitorOutput(struct qemud_server *server,
ret = poll(&pfd, 1, MONITOR_TIMEOUT); ret = poll(&pfd, 1, MONITOR_TIMEOUT);
if (ret == 0) { if (ret == 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -295,7 +313,7 @@ qemudReadMonitorOutput(struct qemud_server *server,
if (pfd.revents & (POLLIN | POLLHUP)) if (pfd.revents & (POLLIN | POLLHUP))
continue; continue;
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Failure while reading %s startup output", what); "Failure while reading %s startup output", what);
return -1; return -1;
} }
@ -307,7 +325,7 @@ qemudReadMonitorOutput(struct qemud_server *server,
} }
} }
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -334,17 +352,17 @@ static int qemudOpenMonitor(struct qemud_server *server, struct qemud_vm *vm, co
int ret = -1; int ret = -1;
if (!(monfd = open(monitor, O_RDWR))) { if (!(monfd = open(monitor, O_RDWR))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
} }
@ -465,7 +483,7 @@ int qemudStartVMDaemon(struct qemud_server *server,
char logfile[PATH_MAX]; char logfile[PATH_MAX];
if (qemudIsActiveVM(vm)) { if (qemudIsActiveVM(vm)) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"VM is already active"); "VM is already active");
return -1; return -1;
} }
@ -473,7 +491,7 @@ int qemudStartVMDaemon(struct qemud_server *server,
if (vm->def->vncPort < 0) { if (vm->def->vncPort < 0) {
int port = qemudNextFreeVNCPort(server); int port = qemudNextFreeVNCPort(server);
if (port < 0) { if (port < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Unable to find an unused VNC port"); "Unable to find an unused VNC port");
return -1; return -1;
} }
@ -486,7 +504,7 @@ int qemudStartVMDaemon(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"config file path too long: %s/%s.log", "config file path too long: %s/%s.log",
server->logDir, vm->def->name); server->logDir, vm->def->name);
return -1; return -1;
@ -497,7 +515,7 @@ int qemudStartVMDaemon(struct qemud_server *server,
strcat(logfile, ".log"); strcat(logfile, ".log");
if (qemudEnsureDir(server->logDir) < 0) { if (qemudEnsureDir(server->logDir) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot create log directory %s: %s", "cannot create log directory %s: %s",
server->logDir, strerror(errno)); server->logDir, strerror(errno));
return -1; return -1;
@ -505,7 +523,7 @@ int qemudStartVMDaemon(struct qemud_server *server,
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(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -766,7 +784,7 @@ qemudBuildDnsmasqArgv(struct qemud_server *server,
free((*argv)[i]); free((*argv)[i]);
free(*argv); free(*argv);
} }
qemudReportError(server, VIR_ERR_NO_MEMORY, "dnsmasq argv"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "dnsmasq argv");
return -1; return -1;
} }
@ -779,7 +797,7 @@ dhcpStartDhcpDaemon(struct qemud_server *server,
int ret, i; int ret, i;
if (network->def->ipAddress[0] == '\0') { if (network->def->ipAddress[0] == '\0') {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
} }
@ -803,21 +821,21 @@ qemudAddIptablesRules(struct qemud_server *server,
int err; int err;
if (!server->iptables && !(server->iptables = iptablesContextNew())) { if (!server->iptables && !(server->iptables = iptablesContextNew())) {
qemudReportError(server, VIR_ERR_NO_MEMORY, "iptables support"); qemudReportError(NULL, 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(server->iptables, network->bridge, 67))) { if ((err = iptablesAddTcpInput(server->iptables, network->bridge, 67))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server->iptables, network->bridge, 67))) { if ((err = iptablesAddUdpInput(server->iptables, network->bridge, 67))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -825,14 +843,14 @@ qemudAddIptablesRules(struct qemud_server *server,
/* allow DNS requests through to dnsmasq */ /* allow DNS requests through to dnsmasq */
if ((err = iptablesAddTcpInput(server->iptables, network->bridge, 53))) { if ((err = iptablesAddTcpInput(server->iptables, network->bridge, 53))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server->iptables, network->bridge, 53))) { if ((err = iptablesAddUdpInput(server->iptables, network->bridge, 53))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -842,14 +860,14 @@ qemudAddIptablesRules(struct qemud_server *server,
/* Catch all rules to block forwarding to/from bridges */ /* Catch all rules to block forwarding to/from bridges */
if ((err = iptablesAddForwardRejectOut(server->iptables, network->bridge))) { if ((err = iptablesAddForwardRejectOut(server->iptables, network->bridge))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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(server->iptables, network->bridge))) { if ((err = iptablesAddForwardRejectIn(server->iptables, network->bridge))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -857,7 +875,7 @@ qemudAddIptablesRules(struct qemud_server *server,
/* Allow traffic between guests on the same bridge */ /* Allow traffic between guests on the same bridge */
if ((err = iptablesAddForwardAllowCross(server->iptables, network->bridge))) { if ((err = iptablesAddForwardAllowCross(server->iptables, network->bridge))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -873,7 +891,7 @@ qemudAddIptablesRules(struct qemud_server *server,
network->def->network, network->def->network,
network->bridge, network->bridge,
network->def->forwardDev))) { network->def->forwardDev))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -884,7 +902,7 @@ qemudAddIptablesRules(struct qemud_server *server,
network->def->network, network->def->network,
network->bridge, network->bridge,
network->def->forwardDev))) { network->def->forwardDev))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -894,7 +912,7 @@ qemudAddIptablesRules(struct qemud_server *server,
if ((err = iptablesAddForwardMasquerade(server->iptables, if ((err = iptablesAddForwardMasquerade(server->iptables,
network->def->network, network->def->network,
network->def->forwardDev))) { network->def->forwardDev))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -984,13 +1002,13 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
int err; int err;
if (qemudIsActiveNetwork(network)) { if (qemudIsActiveNetwork(network)) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"network is already active"); "network is already active");
return -1; return -1;
} }
if (!server->brctl && (err = brInit(&server->brctl))) { if (!server->brctl && (err = brInit(&server->brctl))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot initialize bridge support: %s", strerror(err)); "cannot initialize bridge support: %s", strerror(err));
return -1; return -1;
} }
@ -1003,14 +1021,14 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
} }
if ((err = brAddBridge(server->brctl, name, network->bridge, sizeof(network->bridge)))) { if ((err = brAddBridge(server->brctl, name, network->bridge, sizeof(network->bridge)))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
} }
if (network->def->ipAddress[0] && if (network->def->ipAddress[0] &&
(err = brSetInetAddress(server->brctl, network->bridge, network->def->ipAddress))) { (err = brSetInetAddress(server->brctl, network->bridge, network->def->ipAddress))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1018,7 +1036,7 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
if (network->def->netmask[0] && if (network->def->netmask[0] &&
(err = brSetInetNetmask(server->brctl, network->bridge, network->def->netmask))) { (err = brSetInetNetmask(server->brctl, network->bridge, network->def->netmask))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1026,7 +1044,7 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
if (network->def->ipAddress[0] && if (network->def->ipAddress[0] &&
(err = brSetInterfaceUp(server->brctl, network->bridge, 1))) { (err = brSetInterfaceUp(server->brctl, network->bridge, 1))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
@ -1037,7 +1055,7 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
if (network->def->forward && if (network->def->forward &&
!qemudEnableIpForwarding()) { !qemudEnableIpForwarding()) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, 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;
} }
@ -1329,7 +1347,7 @@ char *qemudGetCapabilities(struct qemud_server *server) {
/* Construct the XML. */ /* Construct the XML. */
xml = bufferNew (1024); xml = bufferNew (1024);
if (!xml) { if (!xml) {
qemudReportError (server, VIR_ERR_NO_MEMORY, NULL); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL; return NULL;
} }
@ -1345,7 +1363,7 @@ char *qemudGetCapabilities(struct qemud_server *server) {
if (r == -1) { if (r == -1) {
vir_buffer_failed: vir_buffer_failed:
bufferFree (xml); bufferFree (xml);
qemudReportError (server, VIR_ERR_NO_MEMORY, NULL); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL; return NULL;
} }
@ -1586,18 +1604,18 @@ int qemudDomainSuspend(struct qemud_server *server, int id) {
char *info; char *info;
struct qemud_vm *vm = qemudFindVMByID(server, id); struct qemud_vm *vm = qemudFindVMByID(server, id);
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
return -1; return -1;
} }
if (!qemudIsActiveVM(vm)) { if (!qemudIsActiveVM(vm)) {
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running"); qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "domain is not running");
return -1; return -1;
} }
if (vm->state == QEMUD_STATE_PAUSED) if (vm->state == QEMUD_STATE_PAUSED)
return 0; return 0;
if (qemudMonitorCommand(server, vm, "stop\n", &info) < 0) { if (qemudMonitorCommand(server, vm, "stop\n", &info) < 0) {
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "suspend operation failed"); qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "suspend operation failed");
return -1; return -1;
} }
vm->state = QEMUD_STATE_PAUSED; vm->state = QEMUD_STATE_PAUSED;
@ -1611,17 +1629,17 @@ int qemudDomainResume(struct qemud_server *server, int id) {
char *info; char *info;
struct qemud_vm *vm = qemudFindVMByID(server, id); struct qemud_vm *vm = qemudFindVMByID(server, id);
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
return -1; return -1;
} }
if (!qemudIsActiveVM(vm)) { if (!qemudIsActiveVM(vm)) {
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running"); qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "domain is not running");
return -1; return -1;
} }
if (vm->state == QEMUD_STATE_RUNNING) if (vm->state == QEMUD_STATE_RUNNING)
return 0; return 0;
if (qemudMonitorCommand(server, vm, "cont\n", &info) < 0) { if (qemudMonitorCommand(server, vm, "cont\n", &info) < 0) {
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "resume operation failed"); qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "resume operation failed");
return -1; return -1;
} }
vm->state = QEMUD_STATE_RUNNING; vm->state = QEMUD_STATE_RUNNING;
@ -1635,7 +1653,7 @@ int qemudDomainDestroy(struct qemud_server *server, int id) {
struct qemud_vm *vm = qemudFindVMByID(server, id); struct qemud_vm *vm = qemudFindVMByID(server, id);
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN,
"no domain with matching id %d", id); "no domain with matching id %d", id);
return -1; return -1;
} }
@ -1652,7 +1670,7 @@ int qemudDomainGetInfo(struct qemud_server *server, const unsigned char *uuid,
unsigned int *nrVirtCpu) { unsigned int *nrVirtCpu) {
struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
return -1; return -1;
} }
@ -1662,7 +1680,7 @@ int qemudDomainGetInfo(struct qemud_server *server, const unsigned char *uuid,
*cputime = 0; *cputime = 0;
} else { } else {
if (qemudGetProcessInfo(cputime, vm->pid) < 0) { if (qemudGetProcessInfo(cputime, vm->pid) < 0) {
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "cannot read cputime for domain"); qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "cannot read cputime for domain");
return -1; return -1;
} }
} }
@ -1678,21 +1696,21 @@ int qemudDomainSave(struct qemud_server *server, int id,
const char *path ATTRIBUTE_UNUSED) { const char *path ATTRIBUTE_UNUSED) {
struct qemud_vm *vm = qemudFindVMByID(server, id); struct qemud_vm *vm = qemudFindVMByID(server, id);
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
return -1; return -1;
} }
if (!qemudIsActiveVM(vm)) { if (!qemudIsActiveVM(vm)) {
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running"); qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "domain is not running");
return -1; return -1;
} }
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "save is not supported"); qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "save is not supported");
return -1; return -1;
} }
int qemudDomainRestore(struct qemud_server *server, int qemudDomainRestore(struct qemud_server *server,
const char *path ATTRIBUTE_UNUSED) { const char *path ATTRIBUTE_UNUSED) {
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "restore is not supported"); qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "restore is not supported");
return -1; return -1;
} }
@ -1701,7 +1719,7 @@ int qemudDomainDumpXML(struct qemud_server *server, const unsigned char *uuid, c
struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
char *vmxml; char *vmxml;
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
return -1; return -1;
} }
@ -1742,7 +1760,7 @@ struct qemud_vm *qemudDomainStart(struct qemud_server *server, const unsigned ch
struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN,
"no domain with matching uuid"); "no domain with matching uuid");
return NULL; return NULL;
} }
@ -1775,12 +1793,12 @@ int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid)
struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
return -1; return -1;
} }
if (qemudIsActiveVM(vm)) { if (qemudIsActiveVM(vm)) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, "cannot delete active domain"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot delete active domain");
return -1; return -1;
} }
@ -1805,7 +1823,7 @@ int qemudDomainGetAutostart(struct qemud_server *server,
struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
return -1; return -1;
} }
@ -1820,7 +1838,7 @@ int qemudDomainSetAutostart(struct qemud_server *server,
struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
if (!vm) { if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
return -1; return -1;
} }
@ -1833,21 +1851,21 @@ int qemudDomainSetAutostart(struct qemud_server *server,
int err; int err;
if ((err = qemudEnsureDir(server->autostartDir))) { if ((err = qemudEnsureDir(server->autostartDir))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot create autostart directory %s: %s", "cannot create autostart directory %s: %s",
server->autostartDir, strerror(err)); server->autostartDir, strerror(err));
return -1; return -1;
} }
if (symlink(vm->configFile, vm->autostartLink) < 0) { if (symlink(vm->configFile, vm->autostartLink) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Failed to create symlink '%s' to '%s': %s", "Failed to create symlink '%s' to '%s': %s",
vm->autostartLink, vm->configFile, strerror(errno)); vm->autostartLink, vm->configFile, strerror(errno));
return -1; return -1;
} }
} else { } else {
if (unlink(vm->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) { if (unlink(vm->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Failed to delete symlink '%s': %s", "Failed to delete symlink '%s': %s",
vm->autostartLink, strerror(errno)); vm->autostartLink, strerror(errno));
return -1; return -1;
@ -1965,7 +1983,7 @@ int qemudNetworkUndefine(struct qemud_server *server, const unsigned char *uuid)
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
if (!network) { if (!network) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no network with matching uuid"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no network with matching uuid");
return -1; return -1;
} }
@ -1988,7 +2006,7 @@ struct qemud_network *qemudNetworkStart(struct qemud_server *server, const unsig
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
if (!network) { if (!network) {
qemudReportError(server, VIR_ERR_INVALID_NETWORK, qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK,
"no network with matching uuid"); "no network with matching uuid");
return NULL; return NULL;
} }
@ -2000,7 +2018,7 @@ int qemudNetworkDestroy(struct qemud_server *server, const unsigned char *uuid)
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
if (!network) { if (!network) {
qemudReportError(server, VIR_ERR_INVALID_NETWORK, qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK,
"no network with matching uuid"); "no network with matching uuid");
return -1; return -1;
} }
@ -2012,7 +2030,7 @@ int qemudNetworkDumpXML(struct qemud_server *server, const unsigned char *uuid,
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
char *networkxml; char *networkxml;
if (!network) { if (!network) {
qemudReportError(server, VIR_ERR_INVALID_NETWORK, "no network with matching uuid"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching uuid");
return -1; return -1;
} }
@ -2032,7 +2050,7 @@ int qemudNetworkGetBridgeName(struct qemud_server *server, const unsigned char *
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
if (!network) { if (!network) {
qemudReportError(server, VIR_ERR_INVALID_NETWORK, "no network with matching id"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching id");
return -1; return -1;
} }
@ -2048,7 +2066,7 @@ int qemudNetworkGetAutostart(struct qemud_server *server,
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
if (!network) { if (!network) {
qemudReportError(server, VIR_ERR_INVALID_NETWORK, "no network with matching uuid"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching uuid");
return -1; return -1;
} }
@ -2063,7 +2081,7 @@ int qemudNetworkSetAutostart(struct qemud_server *server,
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
if (!network) { if (!network) {
qemudReportError(server, VIR_ERR_INVALID_NETWORK, "no network with matching uuid"); qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching uuid");
return -1; return -1;
} }
@ -2076,21 +2094,21 @@ int qemudNetworkSetAutostart(struct qemud_server *server,
int err; int err;
if ((err = qemudEnsureDir(server->networkAutostartDir))) { if ((err = qemudEnsureDir(server->networkAutostartDir))) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot create autostart directory %s: %s", "cannot create autostart directory %s: %s",
server->networkAutostartDir, strerror(err)); server->networkAutostartDir, strerror(err));
return -1; return -1;
} }
if (symlink(network->configFile, network->autostartLink) < 0) { if (symlink(network->configFile, network->autostartLink) < 0) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Failed to create symlink '%s' to '%s': %s", "Failed to create symlink '%s' to '%s': %s",
network->autostartLink, network->configFile, strerror(errno)); network->autostartLink, network->configFile, strerror(errno));
return -1; return -1;
} }
} else { } else {
if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) { if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Failed to delete symlink '%s': %s", "Failed to delete symlink '%s': %s",
network->autostartLink, strerror(errno)); network->autostartLink, strerror(errno));
return -1; return -1;

View File

@ -43,9 +43,11 @@ int qemudStartup(struct qemud_server *server);
void qemudReload(struct qemud_server *server); void qemudReload(struct qemud_server *server);
void qemudShutdown(struct qemud_server *server); void qemudShutdown(struct qemud_server *server);
void qemudReportError(struct qemud_server *server, void qemudReportError(virConnectPtr conn,
virDomainPtr dom,
virNetworkPtr net,
int code, const char *fmt, ...) int code, const char *fmt, ...)
ATTRIBUTE_FORMAT(printf,3,4); ATTRIBUTE_FORMAT(printf,5,6);
int qemudGetNodeInfo(unsigned int *memory, int qemudGetNodeInfo(unsigned int *memory,
char *cpuModel, int cpuModelLength, char *cpuModel, int cpuModelLength,

View File

@ -352,8 +352,6 @@ struct qemud_server {
char *networkConfigDir; char *networkConfigDir;
char *networkAutostartDir; char *networkAutostartDir;
char logDir[PATH_MAX]; char logDir[PATH_MAX];
char errorMessage[QEMUD_MAX_ERROR_LEN];
int errorCode;
unsigned int shutdown : 1; unsigned int shutdown : 1;
}; };

View File

@ -1484,7 +1484,7 @@ static void qemudDispatchServerEvent(int fd, int events, void *opaque) {
} }
static int qemudOneLoop(struct qemud_server *server ATTRIBUTE_UNUSED) { static int qemudOneLoop(void) {
sig_atomic_t errors; sig_atomic_t errors;
if (virEventRunOnce() < 0) if (virEventRunOnce() < 0)
@ -1506,7 +1506,7 @@ static int qemudOneLoop(struct qemud_server *server ATTRIBUTE_UNUSED) {
static int qemudRunLoop(struct qemud_server *server) { static int qemudRunLoop(struct qemud_server *server) {
int ret; int ret;
while ((ret = qemudOneLoop(server)) == 0 && !server->shutdown) while ((ret = qemudOneLoop()) == 0 && !server->shutdown)
; ;
return ret == -1 ? -1 : 0; return ret == -1 ? -1 : 0;