diff -r 6886d4fcdd28 qemud/Makefile.am --- a/qemud/Makefile.am Thu Jun 21 16:11:17 2007 -0400 +++ b/qemud/Makefile.am Thu Jun 21 16:11:42 2007 -0400 @@ -17,6 +17,7 @@ libvirt_qemud_SOURCES = \ protocol.h protocol.c \ remote_protocol.h remote_protocol.c \ remote.c \ + ../src/virterror.c \ event.c event.h #-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L libvirt_qemud_CFLAGS = \ @@ -24,7 +25,9 @@ libvirt_qemud_CFLAGS = \ $(WARN_CFLAGS) -DLOCAL_STATE_DIR="\"$(localstatedir)\"" \ -DSYSCONF_DIR="\"$(sysconfdir)\"" \ -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_DEPENDENCIES = ../src/libvirt.la libvirt_qemud_LDADD = ../src/libvirt.la diff -r 6886d4fcdd28 qemud/conf.c --- a/qemud/conf.c Thu Jun 21 16:11:17 2007 -0400 +++ b/qemud/conf.c Thu Jun 21 16:11:42 2007 -0400 @@ -194,14 +194,14 @@ static char *qemudLocateBinaryForArch(st name = qemudDefaultBinaryForArch(arch); 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; } /* XXX lame. should actually use $PATH ... */ path = malloc(strlen(name) + strlen("/usr/bin/") + 1); if (!path) { - qemudReportError(server, VIR_ERR_NO_MEMORY, "path"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "path"); return NULL; } strcpy(path, "/usr/bin/"); @@ -314,7 +314,7 @@ int qemudExtractVersion(struct qemud_ser return -1; 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, strerror(errno)); free(binary); @@ -343,7 +343,7 @@ static struct qemud_vm_disk_def *qemudPa int typ = 0; if (!disk) { - qemudReportError(server, VIR_ERR_NO_MEMORY, "disk"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "disk"); return NULL; } @@ -383,11 +383,11 @@ static struct qemud_vm_disk_def *qemudPa } 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; } 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; } @@ -395,14 +395,14 @@ static struct qemud_vm_disk_def *qemudPa !strcmp((const char *)device, "floppy") && strcmp((const char *)target, "fda") && 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; } if (device && !strcmp((const char *)device, "cdrom") && 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; } @@ -415,7 +415,7 @@ static struct qemud_vm_disk_def *qemudPa strcmp((const char *)target, "hdb") && strcmp((const char *)target, "hdc") && 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; } @@ -435,7 +435,7 @@ static struct qemud_vm_disk_def *qemudPa else if (!strcmp((const char *)device, "floppy")) disk->device = QEMUD_DISK_FLOPPY; 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; } @@ -483,7 +483,7 @@ static struct qemud_vm_net_def *qemudPar xmlChar *port = NULL; if (!net) { - qemudReportError(server, VIR_ERR_NO_MEMORY, "net"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "net"); return NULL; } @@ -573,11 +573,11 @@ static struct qemud_vm_net_def *qemudPar int len; if (network == NULL) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "No 'network' attribute specified with "); goto error; } 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); goto error; } else { @@ -592,7 +592,7 @@ static struct qemud_vm_net_def *qemudPar if (ifname != NULL) { 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); goto error; } else { @@ -607,7 +607,7 @@ static struct qemud_vm_net_def *qemudPar if (script != NULL) { 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); goto error; } else { @@ -619,7 +619,7 @@ static struct qemud_vm_net_def *qemudPar } if (ifname != NULL) { 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); goto error; } else { @@ -632,11 +632,11 @@ static struct qemud_vm_net_def *qemudPar int len; if (bridge == NULL) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "No 'dev' attribute specified with "); goto error; } 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); goto error; } else { @@ -649,7 +649,7 @@ static struct qemud_vm_net_def *qemudPar if (ifname != NULL) { 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); goto error; } else { @@ -665,13 +665,13 @@ static struct qemud_vm_net_def *qemudPar char *ret; if (port == NULL) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "No 'port' attribute specified with socket interface"); goto error; } if (!(net->dst.socket.port = strtol((char*)port, &ret, 10)) && ret == (char*)port) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Cannot parse 'port' attribute with socket interface"); goto error; } @@ -681,12 +681,12 @@ static struct qemud_vm_net_def *qemudPar if (address == NULL) { if (net->type == QEMUD_NET_CLIENT || net->type == QEMUD_NET_MCAST) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "No 'address' attribute specified with socket interface"); goto error; } } 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); goto error; } @@ -734,27 +734,27 @@ static struct qemud_vm_def *qemudParseXM struct qemud_vm_def *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; } /* Prepare parser / xpath context */ root = xmlDocGetRootElement(xml); 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; } ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { - qemudReportError(server, VIR_ERR_NO_MEMORY, "xmlXPathContext"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext"); goto error; } /* Find out what type of QEMU virtualization to use */ 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; } @@ -765,7 +765,7 @@ static struct qemud_vm_def *qemudParseXM else if (!strcmp((char *)prop, "kvm")) def->virtType = QEMUD_VIRT_KVM; 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; } free(prop); @@ -776,11 +776,11 @@ static struct qemud_vm_def *qemudParseXM obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt); if ((obj == NULL) || (obj->type != XPATH_STRING) || (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; } 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; } strcpy(def->name, (const char *)obj->stringval); @@ -793,12 +793,12 @@ static struct qemud_vm_def *qemudParseXM (obj->stringval == NULL) || (obj->stringval[0] == 0)) { int err; 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)); goto error; } } 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; } xmlXPathFreeObject(obj); @@ -808,13 +808,13 @@ static struct qemud_vm_def *qemudParseXM obj = xmlXPathEval(BAD_CAST "string(/domain/memory[1])", ctxt); if ((obj == NULL) || (obj->type != XPATH_STRING) || (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; } else { conv = NULL; def->maxmem = strtoll((const char*)obj->stringval, &conv, 10); 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; } } @@ -833,7 +833,7 @@ static struct qemud_vm_def *qemudParseXM if (def->memory > def->maxmem) def->memory = def->maxmem; 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; } } @@ -849,7 +849,7 @@ static struct qemud_vm_def *qemudParseXM conv = NULL; def->vcpus = strtoll((const char*)obj->stringval, &conv, 10); 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; } } @@ -884,11 +884,11 @@ static struct qemud_vm_def *qemudParseXM obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt); if ((obj == NULL) || (obj->type != XPATH_STRING) || (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; } 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; } strcpy(def->os.type, (const char *)obj->stringval); @@ -900,13 +900,13 @@ static struct qemud_vm_def *qemudParseXM (obj->stringval == NULL) || (obj->stringval[0] == 0)) { const char *defaultArch = qemudDefaultArch(); 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; } strcpy(def->os.arch, defaultArch); } else { 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; } strcpy(def->os.arch, (const char *)obj->stringval); @@ -919,13 +919,13 @@ static struct qemud_vm_def *qemudParseXM (obj->stringval == NULL) || (obj->stringval[0] == 0)) { const char *defaultMachine = qemudDefaultMachineForArch(def->os.arch); 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; } strcpy(def->os.machine, defaultMachine); } else { 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; } strcpy(def->os.machine, (const char *)obj->stringval); @@ -938,7 +938,7 @@ static struct qemud_vm_def *qemudParseXM if ((obj != NULL) && (obj->type == XPATH_STRING) && (obj->stringval != NULL) && (obj->stringval[0] != 0)) { 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; } strcpy(def->os.kernel, (const char *)obj->stringval); @@ -951,7 +951,7 @@ static struct qemud_vm_def *qemudParseXM if ((obj != NULL) && (obj->type == XPATH_STRING) && (obj->stringval != NULL) && (obj->stringval[0] != 0)) { 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; } strcpy(def->os.initrd, (const char *)obj->stringval); @@ -964,7 +964,7 @@ static struct qemud_vm_def *qemudParseXM if ((obj != NULL) && (obj->type == XPATH_STRING) && (obj->stringval != NULL) && (obj->stringval[0] != 0)) { 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; } strcpy(def->os.cmdline, (const char *)obj->stringval); @@ -1014,7 +1014,7 @@ static struct qemud_vm_def *qemudParseXM free(tmp); } else { 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; } strcpy(def->os.binary, (const char *)obj->stringval); @@ -1039,7 +1039,7 @@ static struct qemud_vm_def *qemudParseXM } else if (!strcmp((char *)prop, "sdl")) { def->graphicsType = QEMUD_GRAPHICS_SDL; } 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; } xmlFree(prop); @@ -1124,11 +1124,11 @@ qemudNetworkIfaceConnect(struct qemud_se if (net->type == QEMUD_NET_NETWORK) { 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); goto error; } 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); goto error; } @@ -1146,20 +1146,20 @@ qemudNetworkIfaceConnect(struct qemud_se } ifname = net->dst.bridge.ifname; } else { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Network type %d is not supported", net->type); goto error; } 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)); goto error; } if ((err = brAddTap(server->brctl, brname, 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", ifname, brname, strerror(err)); goto error; @@ -1180,7 +1180,7 @@ qemudNetworkIfaceConnect(struct qemud_se return retval; no_memory: - qemudReportError(server, VIR_ERR_NO_MEMORY, "tapfds"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "tapfds"); error: if (retval) free(retval); @@ -1233,7 +1233,7 @@ int qemudBuildCommandLine(struct qemud_s * in a sub-process so its hard to feed back a useful error */ 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, strerror(errno)); return -1; @@ -1477,7 +1477,7 @@ int qemudBuildCommandLine(struct qemud_s return 0; no_memory: - qemudReportError(server, VIR_ERR_NO_MEMORY, "argv"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "argv"); error: if (vm->tapfds) { for (i = 0; vm->tapfds[i] != -1; i++) @@ -1509,7 +1509,7 @@ static int qemudSaveConfig(struct qemud_ if ((fd = open(vm->configFile, O_WRONLY | O_CREAT | O_TRUNC, 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", vm->configFile, strerror(errno)); goto cleanup; @@ -1517,14 +1517,14 @@ static int qemudSaveConfig(struct qemud_ towrite = strlen(xml); 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", vm->configFile, strerror(errno)); goto cleanup; } if (close(fd) < 0) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot save config file %s: %s", vm->configFile, strerror(errno)); goto cleanup; @@ -1551,7 +1551,7 @@ qemudParseVMDef(struct qemud_server *ser if (!(xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : "domain.xml", NULL, XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) { - qemudReportError(server, VIR_ERR_XML_ERROR, NULL); + qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL); return NULL; } @@ -1582,7 +1582,7 @@ qemudAssignVMDef(struct qemud_server *se } 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; } @@ -1633,7 +1633,7 @@ qemudSaveVMDef(struct qemud_server *serv int err; 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", server->configDir, strerror(err)); return -1; @@ -1641,14 +1641,14 @@ qemudSaveVMDef(struct qemud_server *serv if (qemudMakeConfigPath(server->configDir, def->name, ".xml", vm->configFile, PATH_MAX) < 0) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot construct config file path"); return -1; } if (qemudMakeConfigPath(server->autostartDir, def->name, ".xml", vm->autostartLink, PATH_MAX) < 0) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot construct autostart link path"); vm->configFile[0] = '\0'; return -1; @@ -1671,7 +1671,7 @@ static int qemudSaveNetworkConfig(struct } 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", server->networkConfigDir, strerror(err)); goto cleanup; @@ -1680,7 +1680,7 @@ static int qemudSaveNetworkConfig(struct if ((fd = open(network->configFile, O_WRONLY | O_CREAT | O_TRUNC, 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", network->configFile, strerror(errno)); goto cleanup; @@ -1688,14 +1688,14 @@ static int qemudSaveNetworkConfig(struct towrite = strlen(xml); 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", network->configFile, strerror(errno)); goto cleanup; } if (close(fd) < 0) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot save config file %s: %s", network->configFile, strerror(errno)); goto cleanup; @@ -1777,7 +1777,7 @@ static int qemudParseDhcpRangesXML(struc } 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; } @@ -1867,20 +1867,20 @@ static struct qemud_network_def *qemudPa struct qemud_network_def *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; } /* Prepare parser / xpath context */ root = xmlDocGetRootElement(xml); 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; } ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { - qemudReportError(server, VIR_ERR_NO_MEMORY, "xmlXPathContext"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext"); goto error; } @@ -1889,11 +1889,11 @@ static struct qemud_network_def *qemudPa obj = xmlXPathEval(BAD_CAST "string(/network/name[1])", ctxt); if ((obj == NULL) || (obj->type != XPATH_STRING) || (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; } 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; } strcpy(def->name, (const char *)obj->stringval); @@ -1906,12 +1906,12 @@ static struct qemud_network_def *qemudPa (obj->stringval == NULL) || (obj->stringval[0] == 0)) { int err; 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)); goto error; } } 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; } xmlXPathFreeObject(obj); @@ -1942,7 +1942,7 @@ static struct qemud_network_def *qemudPa obj->boolval) { if (!def->ipAddress[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"); goto error; } @@ -1953,7 +1953,7 @@ static struct qemud_network_def *qemudPa (tmp->stringval != NULL) && (tmp->stringval[0] != 0)) { int len; 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", (char*)tmp->stringval); goto error; @@ -1996,7 +1996,7 @@ qemudParseNetworkDef(struct qemud_server if (!(xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : "network.xml", NULL, XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) { - qemudReportError(server, VIR_ERR_XML_ERROR, NULL); + qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL); return NULL; } @@ -2026,7 +2026,7 @@ qemudAssignNetworkDef(struct qemud_serve } 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; } @@ -2072,7 +2072,7 @@ qemudSaveNetworkDef(struct qemud_server int err; 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", server->networkConfigDir, strerror(err)); return -1; @@ -2080,14 +2080,14 @@ qemudSaveNetworkDef(struct qemud_server if (qemudMakeConfigPath(server->networkConfigDir, def->name, ".xml", network->configFile, PATH_MAX) < 0) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot construct config file path"); return -1; } if (qemudMakeConfigPath(server->networkAutostartDir, def->name, ".xml", network->autostartLink, PATH_MAX) < 0) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot construct autostart link path"); network->configFile[0] = '\0'; return -1; @@ -2276,8 +2276,9 @@ qemudLoadConfig(struct qemud_server *ser struct qemud_vm *vm; if (!(def = qemudParseVMDef(server, xml, file))) { + virErrorPtr err = virGetLastError(); qemudLog(QEMUD_WARN, "Error parsing QEMU guest config '%s' : %s", - path, server->errorMessage); + path, err->message); return NULL; } @@ -2315,8 +2316,9 @@ qemudLoadNetworkConfig(struct qemud_serv struct qemud_network *network; if (!(def = qemudParseNetworkDef(server, xml, file))) { + virErrorPtr err = virGetLastError(); qemudLog(QEMUD_WARN, "Error parsing network config '%s' : %s", - path, server->errorMessage); + path, err->message); return NULL; } @@ -2408,9 +2410,11 @@ void qemudAutostartConfigs(struct qemud_ if (network->autostart && !qemudIsActiveNetwork(network) && - qemudStartNetworkDaemon(server, network) < 0) + qemudStartNetworkDaemon(server, network) < 0) { + virErrorPtr err = virGetLastError(); qemudLog(QEMUD_ERR, "Failed to autostart network '%s': %s", - network->def->name, server->errorMessage); + network->def->name, err->message); + } network = next; } @@ -2421,9 +2425,11 @@ void qemudAutostartConfigs(struct qemud_ if (vm->autostart && !qemudIsActiveVM(vm) && - qemudStartVMDaemon(server, vm) < 0) + qemudStartVMDaemon(server, vm) < 0) { + virErrorPtr err = virGetLastError(); qemudLog(QEMUD_ERR, "Failed to autostart VM '%s': %s", - vm->def->name, server->errorMessage); + vm->def->name, err->message); + } vm = next; } @@ -2470,7 +2476,7 @@ char *qemudGenerateXML(struct qemud_serv break; } 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; } @@ -2714,7 +2720,7 @@ char *qemudGenerateXML(struct qemud_serv return bufferContentAndFree (buf); no_memory: - qemudReportError(server, VIR_ERR_NO_MEMORY, "xml"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); cleanup: if (buf) bufferFree (buf); return NULL; @@ -2806,7 +2812,7 @@ char *qemudGenerateNetworkXML(struct qem return bufferContentAndFree (buf); no_memory: - qemudReportError(server, VIR_ERR_NO_MEMORY, "xml"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); if (buf) bufferFree (buf); return NULL; } @@ -2816,12 +2822,12 @@ int qemudDeleteConfig(struct qemud_serve const char *configFile, const char *name) { 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; } 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; } diff -r 6886d4fcdd28 qemud/dispatch.c --- a/qemud/dispatch.c Thu Jun 21 16:11:17 2007 -0400 +++ b/qemud/dispatch.c Thu Jun 21 16:11:42 2007 -0400 @@ -39,9 +39,14 @@ static int qemudDispatchFailure(struct q static int qemudDispatchFailure(struct qemud_server *server ATTRIBUTE_UNUSED, struct qemud_client *client ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) { + virErrorPtr err = virGetLastError(); + 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; } @@ -90,7 +95,7 @@ qemudDispatchGetCapabilities (struct qem char *xml = qemudGetCapabilities(server); 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); free(xml); return 0; @@ -784,8 +789,7 @@ int qemudDispatch(struct qemud_server *s qemudDebug("> Dispatching request type %d, readonly ? %d", in->type, client->readonly); - server->errorCode = 0; - server->errorMessage[0] = '\0'; + virResetLastError(); memset(out, 0, sizeof(*out)); @@ -801,7 +805,7 @@ int qemudDispatch(struct qemud_server *s if (!funcs[type]) { qemudDebug("Illegal operation requested"); - qemudReportError(server, VIR_ERR_OPERATION_DENIED, NULL); + qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_DENIED, NULL); qemudDispatchFailure(server, client, out); } else { if ((funcs[type])(server, client, in, out) < 0) { diff -r 6886d4fcdd28 qemud/driver.c --- a/qemud/driver.c Thu Jun 21 16:11:17 2007 -0400 +++ b/qemud/driver.c Thu Jun 21 16:13:01 2007 -0400 @@ -50,17 +50,35 @@ #include "driver.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, ...) { va_list args; - server->errorCode = code; + char errorMessage[QEMUD_MAX_ERROR_LEN]; + if (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); } 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); @@ -159,20 +177,20 @@ qemudExec(struct qemud_server *server, c int pipeerr[2] = {-1,-1}; 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)); goto cleanup; } if ((outfd != NULL && pipe(pipeout) < 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)); goto cleanup; } 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)); goto cleanup; } @@ -261,7 +279,7 @@ qemudReadMonitorOutput(struct qemud_serv ret = read(fd, buf+got, buflen-got-1); 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); return -1; } @@ -271,7 +289,7 @@ qemudReadMonitorOutput(struct qemud_serv continue; if (errno != EAGAIN) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Failure while reading %s startup output: %s", what, strerror(errno)); return -1; @@ -279,12 +297,12 @@ qemudReadMonitorOutput(struct qemud_serv ret = poll(&pfd, 1, MONITOR_TIMEOUT); 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); return -1; } else if (ret == -1) { if (errno != EINTR) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Failure while reading %s startup output: %s", what, strerror(errno)); return -1; @@ -295,7 +313,7 @@ qemudReadMonitorOutput(struct qemud_serv if (pfd.revents & (POLLIN | POLLHUP)) continue; - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Failure while reading %s startup output", what); return -1; } @@ -307,7 +325,7 @@ qemudReadMonitorOutput(struct qemud_serv } } - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Out of space while reading %s startup output", what); return -1; @@ -334,17 +352,17 @@ static int qemudOpenMonitor(struct qemud int ret = -1; 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); return -1; } 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"); goto error; } 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"); goto error; } @@ -465,7 +483,7 @@ int qemudStartVMDaemon(struct qemud_serv char logfile[PATH_MAX]; if (qemudIsActiveVM(vm)) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "VM is already active"); return -1; } @@ -473,7 +491,7 @@ int qemudStartVMDaemon(struct qemud_serv if (vm->def->vncPort < 0) { int port = qemudNextFreeVNCPort(server); if (port < 0) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unable to find an unused VNC port"); return -1; } @@ -486,7 +504,7 @@ int qemudStartVMDaemon(struct qemud_serv strlen(vm->def->name) + /* basename */ 4 + /* suffix .log */ 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", server->logDir, vm->def->name); return -1; @@ -497,7 +515,7 @@ int qemudStartVMDaemon(struct qemud_serv strcat(logfile, ".log"); 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", server->logDir, strerror(errno)); return -1; @@ -505,7 +523,7 @@ int qemudStartVMDaemon(struct qemud_serv if ((vm->logfile = open(logfile, O_CREAT | O_TRUNC | O_WRONLY, 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", logfile, strerror(errno)); return -1; @@ -766,7 +784,7 @@ qemudBuildDnsmasqArgv(struct qemud_serve free((*argv)[i]); free(*argv); } - qemudReportError(server, VIR_ERR_NO_MEMORY, "dnsmasq argv"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "dnsmasq argv"); return -1; } @@ -779,7 +797,7 @@ dhcpStartDhcpDaemon(struct qemud_server int ret, i; 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"); return -1; } @@ -803,21 +821,21 @@ qemudAddIptablesRules(struct qemud_serve int err; 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; } /* allow DHCP requests through to dnsmasq */ 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", network->bridge, strerror(err)); goto err1; } 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", network->bridge, strerror(err)); goto err2; @@ -825,14 +843,14 @@ qemudAddIptablesRules(struct qemud_serve /* allow DNS requests through to dnsmasq */ 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", network->bridge, strerror(err)); goto err3; } 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", network->bridge, strerror(err)); goto err4; @@ -842,14 +860,14 @@ qemudAddIptablesRules(struct qemud_serve /* Catch all rules to block forwarding to/from bridges */ 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", network->bridge, strerror(err)); goto err5; } 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", network->bridge, strerror(err)); goto err6; @@ -857,7 +875,7 @@ qemudAddIptablesRules(struct qemud_serve /* Allow traffic between guests on the same 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", network->bridge, strerror(err)); goto err7; @@ -873,7 +891,7 @@ qemudAddIptablesRules(struct qemud_serve network->def->network, network->bridge, 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", network->bridge, strerror(err)); goto err8; @@ -884,7 +902,7 @@ qemudAddIptablesRules(struct qemud_serve network->def->network, network->bridge, 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", network->bridge, strerror(err)); goto err9; @@ -894,7 +912,7 @@ qemudAddIptablesRules(struct qemud_serve if ((err = iptablesAddForwardMasquerade(server->iptables, network->def->network, 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", strerror(err)); goto err10; @@ -984,13 +1002,13 @@ int qemudStartNetworkDaemon(struct qemud int err; if (qemudIsActiveNetwork(network)) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "network is already active"); return -1; } 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)); return -1; } @@ -1003,14 +1021,14 @@ int qemudStartNetworkDaemon(struct qemud } 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)); return -1; } if (network->def->ipAddress[0] && (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", network->bridge, network->def->ipAddress, strerror(err)); goto err_delbr; @@ -1018,7 +1036,7 @@ int qemudStartNetworkDaemon(struct qemud if (network->def->netmask[0] && (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", network->bridge, network->def->netmask, strerror(err)); goto err_delbr; @@ -1026,7 +1044,7 @@ int qemudStartNetworkDaemon(struct qemud if (network->def->ipAddress[0] && (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", network->bridge, strerror(err)); goto err_delbr; @@ -1037,7 +1055,7 @@ int qemudStartNetworkDaemon(struct qemud if (network->def->forward && !qemudEnableIpForwarding()) { - qemudReportError(server, VIR_ERR_INTERNAL_ERROR, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to enable IP forwarding : %s\n", strerror(err)); goto err_delbr2; } @@ -1325,7 +1343,7 @@ char *qemudGetCapabilities(struct qemud_ /* Construct the XML. */ xml = bufferNew (1024); if (!xml) { - qemudReportError (server, VIR_ERR_NO_MEMORY, NULL); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); return NULL; } @@ -1341,7 +1359,7 @@ char *qemudGetCapabilities(struct qemud_ if (r == -1) { vir_buffer_failed: bufferFree (xml); - qemudReportError (server, VIR_ERR_NO_MEMORY, NULL); + qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); return NULL; } @@ -1582,18 +1600,18 @@ int qemudDomainSuspend(struct qemud_serv char *info; struct qemud_vm *vm = qemudFindVMByID(server, id); 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; } 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; } if (vm->state == QEMUD_STATE_PAUSED) return 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; } vm->state = QEMUD_STATE_PAUSED; @@ -1607,17 +1625,17 @@ int qemudDomainResume(struct qemud_serve char *info; struct qemud_vm *vm = qemudFindVMByID(server, id); 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; } 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; } if (vm->state == QEMUD_STATE_RUNNING) return 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; } vm->state = QEMUD_STATE_RUNNING; @@ -1631,7 +1649,7 @@ int qemudDomainDestroy(struct qemud_serv struct qemud_vm *vm = qemudFindVMByID(server, id); if (!vm) { - qemudReportError(server, VIR_ERR_INVALID_DOMAIN, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id); return -1; } @@ -1648,7 +1666,7 @@ int qemudDomainGetInfo(struct qemud_serv unsigned int *nrVirtCpu) { struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); 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; } @@ -1658,7 +1676,7 @@ int qemudDomainGetInfo(struct qemud_serv *cputime = 0; } else { 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; } } @@ -1674,21 +1692,21 @@ int qemudDomainSave(struct qemud_server const char *path ATTRIBUTE_UNUSED) { struct qemud_vm *vm = qemudFindVMByID(server, id); 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; } if (!qemudIsActiveVM(vm)) { - qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running"); - return -1; - } - qemudReportError(server, VIR_ERR_OPERATION_FAILED, "save is not supported"); + qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "domain is not running"); + return -1; + } + qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "save is not supported"); return -1; } int qemudDomainRestore(struct qemud_server *server, 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; } @@ -1697,7 +1715,7 @@ int qemudDomainDumpXML(struct qemud_serv struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); char *vmxml; 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; } @@ -1738,7 +1756,7 @@ struct qemud_vm *qemudDomainStart(struct struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); if (!vm) { - qemudReportError(server, VIR_ERR_INVALID_DOMAIN, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid"); return NULL; } @@ -1771,12 +1789,12 @@ int qemudDomainUndefine(struct qemud_ser struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); 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; } 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; } @@ -1801,7 +1819,7 @@ int qemudDomainGetAutostart(struct qemud struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); 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; } @@ -1816,7 +1834,7 @@ int qemudDomainSetAutostart(struct qemud struct qemud_vm *vm = qemudFindVMByUUID(server, uuid); 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; } @@ -1829,21 +1847,21 @@ int qemudDomainSetAutostart(struct qemud int err; 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", server->autostartDir, strerror(err)); return -1; } 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", vm->autostartLink, vm->configFile, strerror(errno)); return -1; } } else { 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", vm->autostartLink, strerror(errno)); return -1; @@ -1961,7 +1979,7 @@ int qemudNetworkUndefine(struct qemud_se struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); 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; } @@ -1984,7 +2002,7 @@ struct qemud_network *qemudNetworkStart( struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); if (!network) { - qemudReportError(server, VIR_ERR_INVALID_NETWORK, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching uuid"); return NULL; } @@ -1996,7 +2014,7 @@ int qemudNetworkDestroy(struct qemud_ser struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); if (!network) { - qemudReportError(server, VIR_ERR_INVALID_NETWORK, + qemudReportError(NULL, NULL, NULL, VIR_ERR_INVALID_NETWORK, "no network with matching uuid"); return -1; } @@ -2008,7 +2026,7 @@ int qemudNetworkDumpXML(struct qemud_ser struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); char *networkxml; 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; } @@ -2028,7 +2046,7 @@ int qemudNetworkGetBridgeName(struct qem struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); 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; } @@ -2044,7 +2062,7 @@ int qemudNetworkGetAutostart(struct qemu struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); 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; } @@ -2059,7 +2077,7 @@ int qemudNetworkSetAutostart(struct qemu struct qemud_network *network = qemudFindNetworkByUUID(server, uuid); 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; } @@ -2072,21 +2090,21 @@ int qemudNetworkSetAutostart(struct qemu int err; 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", server->networkAutostartDir, strerror(err)); return -1; } 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", network->autostartLink, network->configFile, strerror(errno)); return -1; } } else { 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", network->autostartLink, strerror(errno)); return -1; diff -r 6886d4fcdd28 qemud/driver.h --- a/qemud/driver.h Thu Jun 21 16:11:17 2007 -0400 +++ b/qemud/driver.h Thu Jun 21 16:11:42 2007 -0400 @@ -43,9 +43,11 @@ void qemudReload(struct qemud_server *se void qemudReload(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, ...) - ATTRIBUTE_FORMAT(printf,3,4); + ATTRIBUTE_FORMAT(printf,5,6); int qemudGetNodeInfo(unsigned int *memory, char *cpuModel, int cpuModelLength, diff -r 6886d4fcdd28 qemud/internal.h --- a/qemud/internal.h Thu Jun 21 16:11:17 2007 -0400 +++ b/qemud/internal.h Thu Jun 21 16:11:42 2007 -0400 @@ -352,8 +352,6 @@ struct qemud_server { char *networkConfigDir; char *networkAutostartDir; char logDir[PATH_MAX]; - char errorMessage[QEMUD_MAX_ERROR_LEN]; - int errorCode; unsigned int shutdown : 1; }; diff -r 6886d4fcdd28 qemud/qemud.c --- a/qemud/qemud.c Thu Jun 21 16:11:17 2007 -0400 +++ b/qemud/qemud.c Thu Jun 21 16:11:42 2007 -0400 @@ -1484,7 +1484,7 @@ static void qemudDispatchServerEvent(int } -static int qemudOneLoop(struct qemud_server *server ATTRIBUTE_UNUSED) { +static int qemudOneLoop(void) { sig_atomic_t errors; if (virEventRunOnce() < 0) @@ -1506,7 +1506,7 @@ static int qemudRunLoop(struct qemud_ser static int qemudRunLoop(struct qemud_server *server) { int ret; - while ((ret = qemudOneLoop(server)) == 0 && !server->shutdown) + while ((ret = qemudOneLoop()) == 0 && !server->shutdown) ; return ret == -1 ? -1 : 0;