The QEMU driver is not passing in a virConnectPtr object for many of the places it calls virRaiseError. This means the errors aren't getting fed back to the client correctly - particularly when starting a VM / network. This patch passes around a virConnectPtr object so errors get reported correctly Instead of: $ ~/usr/bin/virsh --connect qemu://celery.virt.boston.redhat.com/system start demo error: Failed to start domain demo It now gives $ ~/usr/bin/virsh --connect qemu://celery.virt.boston.redhat.com/system start demo libvir: QEMU error : QEMU quit during console startup qemu: could not open hard disk image '/root/demo.img' error: Failed to start domain demo Dan -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
diff -u -p -r1.1 qemu_conf.c --- src/qemu_conf.c 27 Jun 2007 00:12:29 -0000 1.1 +++ src/qemu_conf.c 11 Jul 2007 19:32:30 -0000 @@ -266,7 +266,8 @@ static const char *qemudDefaultBinaryFor } /* Find the fully qualified path to the binary for an architecture */ -static char *qemudLocateBinaryForArch(struct qemud_driver *driver ATTRIBUTE_UNUSED, +static char *qemudLocateBinaryForArch(virConnectPtr conn, + struct qemud_driver *driver ATTRIBUTE_UNUSED, int virtType, const char *arch) { const char *name; char *path; @@ -277,14 +278,14 @@ static char *qemudLocateBinaryForArch(st name = qemudDefaultBinaryForArch(arch); if (!name) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot determin binary for architecture %s", arch); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot determin binary for architecture %s", arch); return NULL; } /* XXX lame. should actually use $PATH ... */ path = malloc(strlen(name) + strlen("/usr/bin/") + 1); if (!path) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "path"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "path"); return NULL; } strcpy(path, "/usr/bin/"); @@ -386,18 +387,19 @@ static int qemudExtractVersionInfo(const } } -int qemudExtractVersion(struct qemud_driver *driver) { +int qemudExtractVersion(virConnectPtr conn, + struct qemud_driver *driver) { char *binary = NULL; struct stat sb; if (driver->qemuVersion > 0) return 0; - if (!(binary = qemudLocateBinaryForArch(driver, QEMUD_VIRT_QEMU, "i686"))) + if (!(binary = qemudLocateBinaryForArch(conn, driver, QEMUD_VIRT_QEMU, "i686"))) return -1; if (stat(binary, &sb) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Cannot find QEMU binary %s: %s", binary, strerror(errno)); free(binary); @@ -415,7 +417,8 @@ int qemudExtractVersion(struct qemud_dri /* Parse the XML definition for a disk */ -static struct qemud_vm_disk_def *qemudParseDiskXML(struct qemud_driver *driver ATTRIBUTE_UNUSED, +static struct qemud_vm_disk_def *qemudParseDiskXML(virConnectPtr conn, + struct qemud_driver *driver ATTRIBUTE_UNUSED, xmlNodePtr node) { struct qemud_vm_disk_def *disk = calloc(1, sizeof(struct qemud_vm_disk_def)); xmlNodePtr cur; @@ -426,7 +429,7 @@ static struct qemud_vm_disk_def *qemudPa int typ = 0; if (!disk) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "disk"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "disk"); return NULL; } @@ -466,11 +469,11 @@ static struct qemud_vm_disk_def *qemudPa } if (source == NULL) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_SOURCE, target ? "%s" : NULL, target); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_SOURCE, target ? "%s" : NULL, target); goto error; } if (target == NULL) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_TARGET, source ? "%s" : NULL, source); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_TARGET, source ? "%s" : NULL, source); goto error; } @@ -478,14 +481,14 @@ static struct qemud_vm_disk_def *qemudPa !strcmp((const char *)device, "floppy") && strcmp((const char *)target, "fda") && strcmp((const char *)target, "fdb")) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid floppy device name: %s", target); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid floppy device name: %s", target); goto error; } if (device && !strcmp((const char *)device, "cdrom") && strcmp((const char *)target, "hdc")) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid cdrom device name: %s", target); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid cdrom device name: %s", target); goto error; } @@ -498,7 +501,7 @@ static struct qemud_vm_disk_def *qemudPa strcmp((const char *)target, "hdb") && strcmp((const char *)target, "hdc") && strcmp((const char *)target, "hdd")) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid harddisk device name: %s", target); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid harddisk device name: %s", target); goto error; } @@ -518,7 +521,7 @@ static struct qemud_vm_disk_def *qemudPa else if (!strcmp((const char *)device, "floppy")) disk->device = QEMUD_DISK_FLOPPY; else { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid device type: %s", device); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid device type: %s", device); goto error; } @@ -552,7 +555,8 @@ static void qemudRandomMAC(struct qemud_ /* Parse the XML definition for a network interface */ -static struct qemud_vm_net_def *qemudParseInterfaceXML(struct qemud_driver *driver ATTRIBUTE_UNUSED, +static struct qemud_vm_net_def *qemudParseInterfaceXML(virConnectPtr conn, + struct qemud_driver *driver ATTRIBUTE_UNUSED, xmlNodePtr node) { struct qemud_vm_net_def *net = calloc(1, sizeof(struct qemud_vm_net_def)); xmlNodePtr cur; @@ -566,7 +570,7 @@ static struct qemud_vm_net_def *qemudPar xmlChar *port = NULL; if (!net) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "net"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "net"); return NULL; } @@ -656,11 +660,11 @@ static struct qemud_vm_net_def *qemudPar int len; if (network == NULL) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "No <source> 'network' attribute specified with <interface type='network'/>"); goto error; } else if ((len = xmlStrlen(network)) >= (QEMUD_MAX_NAME_LEN-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Network name '%s' too long", network); goto error; } else { @@ -675,7 +679,7 @@ static struct qemud_vm_net_def *qemudPar if (ifname != NULL) { if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "TAP interface name '%s' is too long", ifname); goto error; } else { @@ -690,7 +694,7 @@ static struct qemud_vm_net_def *qemudPar if (script != NULL) { if ((len = xmlStrlen(script)) >= (PATH_MAX-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "TAP script path '%s' is too long", script); goto error; } else { @@ -702,7 +706,7 @@ static struct qemud_vm_net_def *qemudPar } if (ifname != NULL) { if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "TAP interface name '%s' is too long", ifname); goto error; } else { @@ -715,11 +719,11 @@ static struct qemud_vm_net_def *qemudPar int len; if (bridge == NULL) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "No <source> 'dev' attribute specified with <interface type='bridge'/>"); goto error; } else if ((len = xmlStrlen(bridge)) >= (BR_IFNAME_MAXLEN-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "TAP bridge path '%s' is too long", bridge); goto error; } else { @@ -732,7 +736,7 @@ static struct qemud_vm_net_def *qemudPar if (ifname != NULL) { if ((len = xmlStrlen(ifname)) >= (BR_IFNAME_MAXLEN-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "TAP interface name '%s' is too long", ifname); goto error; } else { @@ -748,13 +752,13 @@ static struct qemud_vm_net_def *qemudPar char *ret; if (port == NULL) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "No <source> 'port' attribute specified with socket interface"); goto error; } if (!(net->dst.socket.port = strtol((char*)port, &ret, 10)) && ret == (char*)port) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Cannot parse <source> 'port' attribute with socket interface"); goto error; } @@ -764,12 +768,12 @@ static struct qemud_vm_net_def *qemudPar if (address == NULL) { if (net->type == QEMUD_NET_CLIENT || net->type == QEMUD_NET_MCAST) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "No <source> 'address' attribute specified with socket interface"); goto error; } } else if ((len = xmlStrlen(address)) >= (BR_INET_ADDR_MAXLEN)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "IP address '%s' is too long", address); goto error; } @@ -806,7 +810,8 @@ static struct qemud_vm_net_def *qemudPar * Parses a libvirt XML definition of a guest, and populates the * the qemud_vm struct with matching data about the guests config */ -static struct qemud_vm_def *qemudParseXML(struct qemud_driver *driver, +static struct qemud_vm_def *qemudParseXML(virConnectPtr conn, + struct qemud_driver *driver, xmlDocPtr xml) { xmlNodePtr root = NULL; xmlChar *prop = NULL; @@ -817,27 +822,27 @@ static struct qemud_vm_def *qemudParseXM struct qemud_vm_def *def; if (!(def = calloc(1, sizeof(struct qemud_vm_def)))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext"); return NULL; } /* Prepare parser / xpath context */ root = xmlDocGetRootElement(xml); if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "domain"))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element"); goto error; } ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext"); + qemudReportError(conn, 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(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "missing domain type attribute"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "missing domain type attribute"); goto error; } @@ -848,7 +853,7 @@ static struct qemud_vm_def *qemudParseXM else if (!strcmp((char *)prop, "kvm")) def->virtType = QEMUD_VIRT_KVM; else { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "invalid domain type attribute"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "invalid domain type attribute"); goto error; } free(prop); @@ -859,11 +864,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(NULL, NULL, NULL, VIR_ERR_NO_NAME, NULL); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_NAME, NULL); goto error; } if (strlen((const char *)obj->stringval) >= (QEMUD_MAX_NAME_LEN-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "domain name length too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "domain name length too long"); goto error; } strcpy(def->name, (const char *)obj->stringval); @@ -876,12 +881,12 @@ static struct qemud_vm_def *qemudParseXM (obj->stringval == NULL) || (obj->stringval[0] == 0)) { int err; if ((err = virUUIDGenerate(def->uuid))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Failed to generate UUID: %s", strerror(err)); goto error; } } else if (virUUIDParse((const char *)obj->stringval, def->uuid) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element"); goto error; } xmlXPathFreeObject(obj); @@ -891,13 +896,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(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "missing memory element"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "missing memory element"); goto error; } else { conv = NULL; def->maxmem = strtoll((const char*)obj->stringval, &conv, 10); if (conv == (const char*)obj->stringval) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information"); goto error; } } @@ -916,7 +921,7 @@ static struct qemud_vm_def *qemudParseXM if (def->memory > def->maxmem) def->memory = def->maxmem; if (conv == (const char*)obj->stringval) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed memory information"); goto error; } } @@ -932,7 +937,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(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed vcpu information"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed vcpu information"); goto error; } } @@ -967,11 +972,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(NULL, NULL, NULL, VIR_ERR_OS_TYPE, NULL); + qemudReportError(conn, NULL, NULL, VIR_ERR_OS_TYPE, NULL); goto error; } if (strcmp((const char *)obj->stringval, "hvm")) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_OS_TYPE, "%s", obj->stringval); + qemudReportError(conn, NULL, NULL, VIR_ERR_OS_TYPE, "%s", obj->stringval); goto error; } strcpy(def->os.type, (const char *)obj->stringval); @@ -983,13 +988,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(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long"); goto error; } strcpy(def->os.arch, defaultArch); } else { if (strlen((const char *)obj->stringval) >= (QEMUD_OS_TYPE_MAX_LEN-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long"); goto error; } strcpy(def->os.arch, (const char *)obj->stringval); @@ -1002,13 +1007,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(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "machine type too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "machine type too long"); goto error; } strcpy(def->os.machine, defaultMachine); } else { if (strlen((const char *)obj->stringval) >= (QEMUD_OS_MACHINE_MAX_LEN-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "architecture type too long"); goto error; } strcpy(def->os.machine, (const char *)obj->stringval); @@ -1021,7 +1026,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(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "kernel path too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "kernel path too long"); goto error; } strcpy(def->os.kernel, (const char *)obj->stringval); @@ -1034,7 +1039,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(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "initrd path too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "initrd path too long"); goto error; } strcpy(def->os.initrd, (const char *)obj->stringval); @@ -1047,7 +1052,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(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "cmdline arguments too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "cmdline arguments too long"); goto error; } strcpy(def->os.cmdline, (const char *)obj->stringval); @@ -1089,7 +1094,7 @@ static struct qemud_vm_def *qemudParseXM obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt); if ((obj == NULL) || (obj->type != XPATH_STRING) || (obj->stringval == NULL) || (obj->stringval[0] == 0)) { - char *tmp = qemudLocateBinaryForArch(driver, def->virtType, def->os.arch); + char *tmp = qemudLocateBinaryForArch(conn, driver, def->virtType, def->os.arch); if (!tmp) { goto error; } @@ -1097,7 +1102,7 @@ static struct qemud_vm_def *qemudParseXM free(tmp); } else { if (strlen((const char *)obj->stringval) >= (PATH_MAX-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "emulator path too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "emulator path too long"); goto error; } strcpy(def->os.binary, (const char *)obj->stringval); @@ -1122,7 +1127,7 @@ static struct qemud_vm_def *qemudParseXM } else if (!strcmp((char *)prop, "sdl")) { def->graphicsType = QEMUD_GRAPHICS_SDL; } else { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unsupported graphics type %s", prop); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unsupported graphics type %s", prop); goto error; } xmlFree(prop); @@ -1137,7 +1142,7 @@ static struct qemud_vm_def *qemudParseXM struct qemud_vm_disk_def *prev = NULL; for (i = 0; i < obj->nodesetval->nodeNr; i++) { struct qemud_vm_disk_def *disk; - if (!(disk = qemudParseDiskXML(driver, obj->nodesetval->nodeTab[i]))) { + if (!(disk = qemudParseDiskXML(conn, driver, obj->nodesetval->nodeTab[i]))) { goto error; } def->ndisks++; @@ -1160,7 +1165,7 @@ static struct qemud_vm_def *qemudParseXM struct qemud_vm_net_def *prev = NULL; for (i = 0; i < obj->nodesetval->nodeNr; i++) { struct qemud_vm_net_def *net; - if (!(net = qemudParseInterfaceXML(driver, obj->nodesetval->nodeTab[i]))) { + if (!(net = qemudParseInterfaceXML(conn, driver, obj->nodesetval->nodeTab[i]))) { goto error; } def->nnets++; @@ -1191,7 +1196,8 @@ static struct qemud_vm_def *qemudParseXM static char * -qemudNetworkIfaceConnect(struct qemud_driver *driver, +qemudNetworkIfaceConnect(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, struct qemud_vm_net_def *net, int vlan) @@ -1207,11 +1213,11 @@ qemudNetworkIfaceConnect(struct qemud_dr if (net->type == QEMUD_NET_NETWORK) { if (!(network = qemudFindNetworkByName(driver, net->dst.network.name))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Network '%s' not found", net->dst.network.name); goto error; } else if (network->bridge[0] == '\0') { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Network '%s' not active", net->dst.network.name); goto error; } @@ -1229,20 +1235,20 @@ qemudNetworkIfaceConnect(struct qemud_dr } ifname = net->dst.bridge.ifname; } else { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Network type %d is not supported", net->type); goto error; } if (!driver->brctl && (err = brInit(&driver->brctl))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot initialize bridge support: %s", strerror(err)); goto error; } if ((err = brAddTap(driver->brctl, brname, ifname, BR_IFNAME_MAXLEN, &tapfd))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Failed to add tap interface '%s' to bridge '%s' : %s", ifname, brname, strerror(err)); goto error; @@ -1263,7 +1269,7 @@ qemudNetworkIfaceConnect(struct qemud_dr return retval; no_memory: - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "tapfds"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "tapfds"); error: if (retval) free(retval); @@ -1276,7 +1282,8 @@ qemudNetworkIfaceConnect(struct qemud_dr * Constructs a argv suitable for launching qemu with config defined * for a given virtual machine. */ -int qemudBuildCommandLine(struct qemud_driver *driver, +int qemudBuildCommandLine(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, char ***argv) { int len, n = -1, i; @@ -1289,7 +1296,7 @@ int qemudBuildCommandLine(struct qemud_d struct utsname ut; int disableKQEMU = 0; - if (qemudExtractVersion(driver) < 0) + if (qemudExtractVersion(conn, driver) < 0) return -1; uname(&ut); @@ -1316,7 +1323,7 @@ int qemudBuildCommandLine(struct qemud_d * in a sub-process so its hard to feed back a useful error */ if (stat(vm->def->os.binary, &sb) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Cannot find QEMU binary %s: %s", vm->def->os.binary, strerror(errno)); return -1; @@ -1470,7 +1477,7 @@ int qemudBuildCommandLine(struct qemud_d switch (net->type) { case QEMUD_NET_NETWORK: case QEMUD_NET_BRIDGE: - if (!((*argv)[++n] = qemudNetworkIfaceConnect(driver, vm, net, vlan))) + if (!((*argv)[++n] = qemudNetworkIfaceConnect(conn, driver, vm, net, vlan))) goto error; break; @@ -1560,7 +1567,7 @@ int qemudBuildCommandLine(struct qemud_d return 0; no_memory: - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "argv"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "argv"); error: if (vm->tapfds) { for (i = 0; vm->tapfds[i] != -1; i++) @@ -1579,20 +1586,21 @@ int qemudBuildCommandLine(struct qemud_d /* Save a guest's config data into a persistent file */ -static int qemudSaveConfig(struct qemud_driver *driver, +static int qemudSaveConfig(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, struct qemud_vm_def *def) { char *xml; int fd = -1, ret = -1; int towrite; - if (!(xml = qemudGenerateXML(driver, vm, def, 0))) + if (!(xml = qemudGenerateXML(conn, driver, vm, def, 0))) return -1; if ((fd = open(vm->configFile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR )) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create config file %s: %s", vm->configFile, strerror(errno)); goto cleanup; @@ -1600,14 +1608,14 @@ static int qemudSaveConfig(struct qemud_ towrite = strlen(xml); if (write(fd, xml, towrite) != towrite) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot write config file %s: %s", vm->configFile, strerror(errno)); goto cleanup; } if (close(fd) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot save config file %s: %s", vm->configFile, strerror(errno)); goto cleanup; @@ -1625,7 +1633,8 @@ static int qemudSaveConfig(struct qemud_ } struct qemud_vm_def * -qemudParseVMDef(struct qemud_driver *driver, +qemudParseVMDef(virConnectPtr conn, + struct qemud_driver *driver, const char *xmlStr, const char *displayName) { xmlDocPtr xml; @@ -1634,11 +1643,11 @@ qemudParseVMDef(struct qemud_driver *dri if (!(xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : "domain.xml", NULL, XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL); + qemudReportError(conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL); return NULL; } - def = qemudParseXML(driver, xml); + def = qemudParseXML(conn, driver, xml); xmlFreeDoc(xml); @@ -1646,7 +1655,8 @@ qemudParseVMDef(struct qemud_driver *dri } struct qemud_vm * -qemudAssignVMDef(struct qemud_driver *driver, +qemudAssignVMDef(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm_def *def) { struct qemud_vm *vm = NULL; @@ -1665,7 +1675,7 @@ qemudAssignVMDef(struct qemud_driver *dr } if (!(vm = calloc(1, sizeof(struct qemud_vm)))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "vm"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "vm"); return NULL; } @@ -1709,14 +1719,15 @@ qemudRemoveInactiveVM(struct qemud_drive } int -qemudSaveVMDef(struct qemud_driver *driver, +qemudSaveVMDef(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, struct qemud_vm_def *def) { if (vm->configFile[0] == '\0') { int err; if ((err = qemudEnsureDir(driver->configDir))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create config directory %s: %s", driver->configDir, strerror(err)); return -1; @@ -1724,24 +1735,25 @@ qemudSaveVMDef(struct qemud_driver *driv if (qemudMakeConfigPath(driver->configDir, def->name, ".xml", vm->configFile, PATH_MAX) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot construct config file path"); return -1; } if (qemudMakeConfigPath(driver->autostartDir, def->name, ".xml", vm->autostartLink, PATH_MAX) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot construct autostart link path"); vm->configFile[0] = '\0'; return -1; } } - return qemudSaveConfig(driver, vm, def); + return qemudSaveConfig(conn, driver, vm, def); } -static int qemudSaveNetworkConfig(struct qemud_driver *driver, +static int qemudSaveNetworkConfig(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_network *network, struct qemud_network_def *def) { char *xml; @@ -1749,12 +1761,12 @@ static int qemudSaveNetworkConfig(struct int towrite; int err; - if (!(xml = qemudGenerateNetworkXML(driver, network, def))) { + if (!(xml = qemudGenerateNetworkXML(conn, driver, network, def))) { return -1; } if ((err = qemudEnsureDir(driver->networkConfigDir))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create config directory %s: %s", driver->networkConfigDir, strerror(err)); goto cleanup; @@ -1763,7 +1775,7 @@ static int qemudSaveNetworkConfig(struct if ((fd = open(network->configFile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR )) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create config file %s: %s", network->configFile, strerror(errno)); goto cleanup; @@ -1771,14 +1783,14 @@ static int qemudSaveNetworkConfig(struct towrite = strlen(xml); if (write(fd, xml, towrite) != towrite) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot write config file %s: %s", network->configFile, strerror(errno)); goto cleanup; } if (close(fd) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot save config file %s: %s", network->configFile, strerror(errno)); goto cleanup; @@ -1842,7 +1854,8 @@ static int qemudParseBridgeXML(struct qe return 1; } -static int qemudParseDhcpRangesXML(struct qemud_driver *driver ATTRIBUTE_UNUSED, +static int qemudParseDhcpRangesXML(virConnectPtr conn, + struct qemud_driver *driver ATTRIBUTE_UNUSED, struct qemud_network_def *def, xmlNodePtr node) { @@ -1860,7 +1873,7 @@ static int qemudParseDhcpRangesXML(struc } if (!(range = calloc(1, sizeof(struct qemud_dhcp_range_def)))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "range"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "range"); return 0; } @@ -1892,7 +1905,8 @@ static int qemudParseDhcpRangesXML(struc return 1; } -static int qemudParseInetXML(struct qemud_driver *driver ATTRIBUTE_UNUSED, +static int qemudParseInetXML(virConnectPtr conn, + struct qemud_driver *driver ATTRIBUTE_UNUSED, struct qemud_network_def *def, xmlNodePtr node) { xmlChar *address, *netmask; @@ -1933,7 +1947,7 @@ static int qemudParseInetXML(struct qemu while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "dhcp") && - !qemudParseDhcpRangesXML(driver, def, cur)) + !qemudParseDhcpRangesXML(conn, driver, def, cur)) return 0; cur = cur->next; } @@ -1942,7 +1956,8 @@ static int qemudParseInetXML(struct qemu } -static struct qemud_network_def *qemudParseNetworkXML(struct qemud_driver *driver, +static struct qemud_network_def *qemudParseNetworkXML(virConnectPtr conn, + struct qemud_driver *driver, xmlDocPtr xml) { xmlNodePtr root = NULL; xmlXPathContextPtr ctxt = NULL; @@ -1950,20 +1965,20 @@ static struct qemud_network_def *qemudPa struct qemud_network_def *def; if (!(def = calloc(1, sizeof(struct qemud_network_def)))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "network_def"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network_def"); return NULL; } /* Prepare parser / xpath context */ root = xmlDocGetRootElement(xml); if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "network"))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "incorrect root element"); goto error; } ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext"); goto error; } @@ -1972,11 +1987,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(NULL, NULL, NULL, VIR_ERR_NO_NAME, NULL); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_NAME, NULL); goto error; } if (strlen((const char *)obj->stringval) >= (QEMUD_MAX_NAME_LEN-1)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "network name length too long"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "network name length too long"); goto error; } strcpy(def->name, (const char *)obj->stringval); @@ -1989,12 +2004,12 @@ static struct qemud_network_def *qemudPa (obj->stringval == NULL) || (obj->stringval[0] == 0)) { int err; if ((err = virUUIDGenerate(def->uuid))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Failed to generate UUID: %s", strerror(err)); goto error; } } else if (virUUIDParse((const char *)obj->stringval, def->uuid) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element"); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element"); goto error; } xmlXPathFreeObject(obj); @@ -2013,7 +2028,7 @@ static struct qemud_network_def *qemudPa obj = xmlXPathEval(BAD_CAST "/network/ip[1]", ctxt); if ((obj != NULL) && (obj->type == XPATH_NODESET) && (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) { - if (!qemudParseInetXML(driver, def, obj->nodesetval->nodeTab[0])) { + if (!qemudParseInetXML(conn, driver, def, obj->nodesetval->nodeTab[0])) { goto error; } } @@ -2025,7 +2040,7 @@ static struct qemud_network_def *qemudPa obj->boolval) { if (!def->ipAddress[0] || !def->netmask[0]) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Forwarding requested, but no IPv4 address/netmask provided"); goto error; } @@ -2036,7 +2051,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(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "forward device name '%s' is too long", (char*)tmp->stringval); goto error; @@ -2070,7 +2085,8 @@ static struct qemud_network_def *qemudPa } struct qemud_network_def * -qemudParseNetworkDef(struct qemud_driver *driver, +qemudParseNetworkDef(virConnectPtr conn, + struct qemud_driver *driver, const char *xmlStr, const char *displayName) { xmlDocPtr xml; @@ -2079,11 +2095,11 @@ qemudParseNetworkDef(struct qemud_driver if (!(xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : "network.xml", NULL, XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL); + qemudReportError(conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL); return NULL; } - def = qemudParseNetworkXML(driver, xml); + def = qemudParseNetworkXML(conn, driver, xml); xmlFreeDoc(xml); @@ -2091,7 +2107,8 @@ qemudParseNetworkDef(struct qemud_driver } struct qemud_network * -qemudAssignNetworkDef(struct qemud_driver *driver, +qemudAssignNetworkDef(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_network_def *def) { struct qemud_network *network; @@ -2109,7 +2126,7 @@ qemudAssignNetworkDef(struct qemud_drive } if (!(network = calloc(1, sizeof(struct qemud_network)))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "network"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network"); return NULL; } @@ -2147,7 +2164,8 @@ qemudRemoveInactiveNetwork(struct qemud_ } int -qemudSaveNetworkDef(struct qemud_driver *driver, +qemudSaveNetworkDef(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_network *network, struct qemud_network_def *def) { @@ -2155,7 +2173,7 @@ qemudSaveNetworkDef(struct qemud_driver int err; if ((err = qemudEnsureDir(driver->networkConfigDir))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create config directory %s: %s", driver->networkConfigDir, strerror(err)); return -1; @@ -2163,21 +2181,21 @@ qemudSaveNetworkDef(struct qemud_driver if (qemudMakeConfigPath(driver->networkConfigDir, def->name, ".xml", network->configFile, PATH_MAX) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot construct config file path"); return -1; } if (qemudMakeConfigPath(driver->networkAutostartDir, def->name, ".xml", network->autostartLink, PATH_MAX) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot construct autostart link path"); network->configFile[0] = '\0'; return -1; } } - return qemudSaveNetworkConfig(driver, network, def); + return qemudSaveNetworkConfig(conn, driver, network, def); } static int @@ -2358,7 +2376,7 @@ qemudLoadConfig(struct qemud_driver *dri struct qemud_vm_def *def; struct qemud_vm *vm; - if (!(def = qemudParseVMDef(driver, xml, file))) { + if (!(def = qemudParseVMDef(NULL, driver, xml, file))) { virErrorPtr err = virGetLastError(); qemudLog(QEMUD_WARN, "Error parsing QEMU guest config '%s' : %s", path, err->message); @@ -2372,7 +2390,7 @@ qemudLoadConfig(struct qemud_driver *dri return NULL; } - if (!(vm = qemudAssignVMDef(driver, def))) { + if (!(vm = qemudAssignVMDef(NULL, driver, def))) { qemudLog(QEMUD_WARN, "Failed to load QEMU guest config '%s': out of memory", path); qemudFreeVMDef(def); return NULL; @@ -2398,7 +2416,7 @@ qemudLoadNetworkConfig(struct qemud_driv struct qemud_network_def *def; struct qemud_network *network; - if (!(def = qemudParseNetworkDef(driver, xml, file))) { + if (!(def = qemudParseNetworkDef(NULL, driver, xml, file))) { virErrorPtr err = virGetLastError(); qemudLog(QEMUD_WARN, "Error parsing network config '%s' : %s", path, err->message); @@ -2412,7 +2430,7 @@ qemudLoadNetworkConfig(struct qemud_driv return NULL; } - if (!(network = qemudAssignNetworkDef(driver, def))) { + if (!(network = qemudAssignNetworkDef(NULL, driver, def))) { qemudLog(QEMUD_WARN, "Failed to load network config '%s': out of memory", path); qemudFreeNetworkDef(def); return NULL; @@ -2494,7 +2512,8 @@ int qemudScanConfigs(struct qemud_driver } /* Generate an XML document describing the guest's configuration */ -char *qemudGenerateXML(struct qemud_driver *driver ATTRIBUTE_UNUSED, +char *qemudGenerateXML(virConnectPtr conn, + struct qemud_driver *driver ATTRIBUTE_UNUSED, struct qemud_vm *vm, struct qemud_vm_def *def, int live) { @@ -2521,7 +2540,7 @@ char *qemudGenerateXML(struct qemud_driv break; } if (!type) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "unexpected domain type %d", def->virtType); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "unexpected domain type %d", def->virtType); goto cleanup; } @@ -2765,14 +2784,15 @@ char *qemudGenerateXML(struct qemud_driv return virBufferContentAndFree (buf); no_memory: - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); cleanup: if (buf) virBufferFree (buf); return NULL; } -char *qemudGenerateNetworkXML(struct qemud_driver *driver ATTRIBUTE_UNUSED, +char *qemudGenerateNetworkXML(virConnectPtr conn, + struct qemud_driver *driver ATTRIBUTE_UNUSED, struct qemud_network *network, struct qemud_network_def *def) { virBufferPtr buf = 0; @@ -2857,22 +2877,23 @@ char *qemudGenerateNetworkXML(struct qem return virBufferContentAndFree (buf); no_memory: - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); if (buf) virBufferFree (buf); return NULL; } -int qemudDeleteConfig(struct qemud_driver *driver ATTRIBUTE_UNUSED, +int qemudDeleteConfig(virConnectPtr conn, + struct qemud_driver *driver ATTRIBUTE_UNUSED, const char *configFile, const char *name) { if (!configFile[0]) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no config file for %s", name); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no config file for %s", name); return -1; } if (unlink(configFile) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot remove config for %s", name); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot remove config for %s", name); return -1; } diff -u -p -r1.1 qemu_conf.h --- src/qemu_conf.h 27 Jun 2007 00:12:29 -0000 1.1 +++ src/qemu_conf.h 11 Jul 2007 19:32:30 -0000 @@ -299,13 +299,16 @@ struct qemud_network *qemudFindNetworkBy struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver, const char *name); -int qemudExtractVersion (struct qemud_driver *driver); -int qemudBuildCommandLine (struct qemud_driver *driver, +int qemudExtractVersion (virConnectPtr conn, + struct qemud_driver *driver); +int qemudBuildCommandLine (virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, char ***argv); int qemudScanConfigs (struct qemud_driver *driver); -int qemudDeleteConfig (struct qemud_driver *driver, +int qemudDeleteConfig (virConnectPtr conn, + struct qemud_driver *driver, const char *configFile, const char *name); int qemudEnsureDir (const char *path); @@ -314,19 +317,23 @@ void qemudFreeVMDef void qemudFreeVM (struct qemud_vm *vm); struct qemud_vm * - qemudAssignVMDef (struct qemud_driver *driver, + qemudAssignVMDef (virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm_def *def); void qemudRemoveInactiveVM (struct qemud_driver *driver, struct qemud_vm *vm); struct qemud_vm_def * - qemudParseVMDef (struct qemud_driver *driver, + qemudParseVMDef (virConnectPtr conn, + struct qemud_driver *driver, const char *xmlStr, const char *displayName); -int qemudSaveVMDef (struct qemud_driver *driver, +int qemudSaveVMDef (virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, struct qemud_vm_def *def); -char * qemudGenerateXML (struct qemud_driver *driver, +char * qemudGenerateXML (virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, struct qemud_vm_def *def, int live); @@ -335,19 +342,23 @@ void qemudFreeNetworkDef void qemudFreeNetwork (struct qemud_network *network); struct qemud_network * - qemudAssignNetworkDef (struct qemud_driver *driver, + qemudAssignNetworkDef (virConnectPtr conn, + struct qemud_driver *driver, struct qemud_network_def *def); void qemudRemoveInactiveNetwork (struct qemud_driver *driver, struct qemud_network *network); struct qemud_network_def * - qemudParseNetworkDef (struct qemud_driver *driver, + qemudParseNetworkDef (virConnectPtr conn, + struct qemud_driver *driver, const char *xmlStr, const char *displayName); -int qemudSaveNetworkDef (struct qemud_driver *driver, +int qemudSaveNetworkDef (virConnectPtr conn, + struct qemud_driver *driver, struct qemud_network *network, struct qemud_network_def *def); -char * qemudGenerateNetworkXML (struct qemud_driver *driver, +char * qemudGenerateNetworkXML (virConnectPtr conn, + struct qemud_driver *driver, struct qemud_network *network, struct qemud_network_def *def); diff -u -p -r1.7 qemu_driver.c --- src/qemu_driver.c 6 Jul 2007 21:52:42 -0000 1.7 +++ src/qemu_driver.c 11 Jul 2007 19:32:30 -0000 @@ -87,17 +87,21 @@ static int qemudSetNonBlock(int fd) { static void qemudDispatchVMEvent(int fd, int events, void *opaque); -static int qemudStartVMDaemon(struct qemud_driver *driver, - struct qemud_vm *vm); - -static int qemudShutdownVMDaemon(struct qemud_driver *driver, - struct qemud_vm *vm); - -static int qemudStartNetworkDaemon(struct qemud_driver *driver, - struct qemud_network *network); - -static int qemudShutdownNetworkDaemon(struct qemud_driver *driver, - struct qemud_network *network); +static int qemudStartVMDaemon(virConnectPtr conn, + struct qemud_driver *driver, + struct qemud_vm *vm); + +static int qemudShutdownVMDaemon(virConnectPtr conn, + struct qemud_driver *driver, + struct qemud_vm *vm); + +static int qemudStartNetworkDaemon(virConnectPtr conn, + struct qemud_driver *driver, + struct qemud_network *network); + +static int qemudShutdownNetworkDaemon(virConnectPtr conn, + struct qemud_driver *driver, + struct qemud_network *network); struct qemud_driver *qemu_driver = NULL; @@ -113,7 +117,7 @@ void qemudAutostartConfigs(struct qemud_ if (network->autostart && !qemudIsActiveNetwork(network) && - qemudStartNetworkDaemon(driver, network) < 0) { + qemudStartNetworkDaemon(NULL, driver, network) < 0) { virErrorPtr err = virGetLastError(); qemudLog(QEMUD_ERR, "Failed to autostart network '%s': %s", network->def->name, err->message); @@ -128,7 +132,7 @@ void qemudAutostartConfigs(struct qemud_ if (vm->autostart && !qemudIsActiveVM(vm) && - qemudStartVMDaemon(driver, vm) < 0) { + qemudStartVMDaemon(NULL, driver, vm) < 0) { virErrorPtr err = virGetLastError(); qemudLog(QEMUD_ERR, "Failed to autostart VM '%s': %s", vm->def->name, err->message); @@ -271,7 +275,7 @@ qemudShutdown(void) { while (vm) { struct qemud_vm *next = vm->next; if (qemudIsActiveVM(vm)) - qemudShutdownVMDaemon(qemu_driver, vm); + qemudShutdownVMDaemon(NULL, qemu_driver, vm); vm = next; } @@ -291,7 +295,7 @@ qemudShutdown(void) { while (network) { struct qemud_network *next = network->next; if (qemudIsActiveNetwork(network)) - qemudShutdownNetworkDaemon(qemu_driver, network); + qemudShutdownNetworkDaemon(NULL, qemu_driver, network); network = next; } @@ -327,27 +331,28 @@ qemudShutdown(void) { } static int -qemudExec(char **argv, +qemudExec(virConnectPtr conn, + char **argv, int *retpid, int *outfd, int *errfd) { int pid, null; int pipeout[2] = {-1,-1}; int pipeerr[2] = {-1,-1}; if ((null = open(_PATH_DEVNULL, O_RDONLY)) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot open %s : %s", + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot open %s : %s", _PATH_DEVNULL, strerror(errno)); goto cleanup; } if ((outfd != NULL && pipe(pipeout) < 0) || (errfd != NULL && pipe(pipeerr) < 0)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create pipe : %s", + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create pipe : %s", strerror(errno)); goto cleanup; } if ((pid = fork()) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot fork child process : %s", + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot fork child process : %s", strerror(errno)); goto cleanup; } @@ -411,13 +416,15 @@ qemudExec(char **argv, } /* Return -1 for error, 1 to continue reading and 0 for success */ -typedef int qemudHandlerMonitorOutput(struct qemud_driver *driver, +typedef int qemudHandlerMonitorOutput(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, const char *output, int fd); static int -qemudReadMonitorOutput(struct qemud_driver *driver, +qemudReadMonitorOutput(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, int fd, char *buf, @@ -436,7 +443,8 @@ qemudReadMonitorOutput(struct qemud_driv ret = read(fd, buf+got, buflen-got-1); if (ret == 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + printf("Fail [%s]\n", buf); + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "QEMU quit during %s startup\n%s", what, buf); return -1; } @@ -446,7 +454,7 @@ qemudReadMonitorOutput(struct qemud_driv continue; if (errno != EAGAIN) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Failure while reading %s startup output: %s", what, strerror(errno)); return -1; @@ -454,12 +462,12 @@ qemudReadMonitorOutput(struct qemud_driv ret = poll(&pfd, 1, MONITOR_TIMEOUT); if (ret == 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Timed out while reading %s startup output", what); return -1; } else if (ret == -1) { if (errno != EINTR) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Failure while reading %s startup output: %s", what, strerror(errno)); return -1; @@ -470,19 +478,19 @@ qemudReadMonitorOutput(struct qemud_driv if (pfd.revents & (POLLIN | POLLHUP)) continue; - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Failure while reading %s startup output", what); return -1; } } else { got += ret; buf[got] = '\0'; - if ((ret = func(driver, vm, buf, fd)) != 1) + if ((ret = func(conn, driver, vm, buf, fd)) != 1) return ret; } } - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Out of space while reading %s startup output", what); return -1; @@ -490,7 +498,8 @@ qemudReadMonitorOutput(struct qemud_driv } static int -qemudCheckMonitorPrompt(struct qemud_driver *driver ATTRIBUTE_UNUSED, +qemudCheckMonitorPrompt(virConnectPtr conn ATTRIBUTE_UNUSED, + struct qemud_driver *driver ATTRIBUTE_UNUSED, struct qemud_vm *vm, const char *output, int fd) @@ -503,28 +512,32 @@ qemudCheckMonitorPrompt(struct qemud_dri return 0; } -static int qemudOpenMonitor(struct qemud_driver *driver, struct qemud_vm *vm, const char *monitor) { +static int qemudOpenMonitor(virConnectPtr conn, + struct qemud_driver *driver, + struct qemud_vm *vm, + const char *monitor) { int monfd; char buf[1024]; int ret = -1; if (!(monfd = open(monitor, O_RDWR))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unable to open monitor path %s", monitor); return -1; } if (qemudSetCloseExec(monfd) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unable to set monitor close-on-exec flag"); goto error; } if (qemudSetNonBlock(monfd) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unable to put monitor into non-blocking mode"); goto error; } - ret = qemudReadMonitorOutput(driver, vm, monfd, + ret = qemudReadMonitorOutput(conn, + driver, vm, monfd, buf, sizeof(buf), qemudCheckMonitorPrompt, "monitor"); @@ -564,7 +577,8 @@ static int qemudExtractMonitorPath(const } static int -qemudOpenMonitorPath(struct qemud_driver *driver, +qemudOpenMonitorPath(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_vm *vm, const char *output, int fd ATTRIBUTE_UNUSED) @@ -574,12 +588,15 @@ qemudOpenMonitorPath(struct qemud_driver if (qemudExtractMonitorPath(output, monitor, sizeof(monitor)) < 0) return 1; /* keep reading */ - return qemudOpenMonitor(driver, vm, monitor); + return qemudOpenMonitor(conn, driver, vm, monitor); } -static int qemudWaitForMonitor(struct qemud_driver *driver, struct qemud_vm *vm) { +static int qemudWaitForMonitor(virConnectPtr conn, + struct qemud_driver *driver, + struct qemud_vm *vm) { char buf[1024]; /* Plenty of space to get startup greeting */ - int ret = qemudReadMonitorOutput(driver, vm, vm->stderr, + int ret = qemudReadMonitorOutput(conn, + driver, vm, vm->stderr, buf, sizeof(buf), qemudOpenMonitorPath, "console"); @@ -593,7 +610,7 @@ static int qemudWaitForMonitor(struct qe qemudLog(QEMUD_WARN, "Unable to log VM console data: %s", strerror(errno)); } - + printf("Mon %d\n", ret); return ret; } @@ -633,14 +650,15 @@ static int qemudNextFreeVNCPort(struct q return -1; } -static int qemudStartVMDaemon(struct qemud_driver *driver, - struct qemud_vm *vm) { +static int qemudStartVMDaemon(virConnectPtr conn, + struct qemud_driver *driver, + struct qemud_vm *vm) { char **argv = NULL, **tmp; int i; char logfile[PATH_MAX]; if (qemudIsActiveVM(vm)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "VM is already active"); return -1; } @@ -648,7 +666,7 @@ static int qemudStartVMDaemon(struct qem if (vm->def->vncPort < 0) { int port = qemudNextFreeVNCPort(driver); if (port < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Unable to find an unused VNC port"); return -1; } @@ -661,7 +679,7 @@ static int qemudStartVMDaemon(struct qem strlen(vm->def->name) + /* basename */ 4 + /* suffix .log */ 1 /* NULL */) > PATH_MAX) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "config file path too long: %s/%s.log", driver->logDir, vm->def->name); return -1; @@ -672,7 +690,7 @@ static int qemudStartVMDaemon(struct qem strcat(logfile, ".log"); if (qemudEnsureDir(driver->logDir) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create log directory %s: %s", driver->logDir, strerror(errno)); return -1; @@ -680,13 +698,13 @@ static int qemudStartVMDaemon(struct qem if ((vm->logfile = open(logfile, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR)) < 0) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to create logfile %s: %s", logfile, strerror(errno)); return -1; } - if (qemudBuildCommandLine(driver, vm, &argv) < 0) { + if (qemudBuildCommandLine(conn, driver, vm, &argv) < 0) { close(vm->logfile); vm->logfile = -1; return -1; @@ -705,8 +723,9 @@ static int qemudStartVMDaemon(struct qem if (write(vm->logfile, "\n", 1) < 0) qemudLog(QEMUD_WARN, "Unable to write argv to logfile %d: %s", errno, strerror(errno)); - - if (qemudExec(argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) { + printf("Exec\n"); + if (qemudExec(conn, argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) { + printf("Fail exec\n"); vm->id = driver->nextvmid++; vm->state = VIR_DOMAIN_RUNNING; @@ -732,7 +751,7 @@ static int qemudStartVMDaemon(struct qem POLLIN | POLLERR | POLLHUP, qemudDispatchVMEvent, driver) < 0) { - qemudShutdownVMDaemon(driver, vm); + qemudShutdownVMDaemon(conn, driver, vm); return -1; } @@ -740,13 +759,14 @@ static int qemudStartVMDaemon(struct qem POLLIN | POLLERR | POLLHUP, qemudDispatchVMEvent, driver) < 0) { - qemudShutdownVMDaemon(driver, vm); + qemudShutdownVMDaemon(conn, driver, vm); return -1; } + printf("Wait monitor\n"); - - if (qemudWaitForMonitor(driver, vm) < 0) { - qemudShutdownVMDaemon(driver, vm); + if (qemudWaitForMonitor(conn, driver, vm) < 0) { + printf("Moin fail\n"); + qemudShutdownVMDaemon(conn, driver, vm); return -1; } @@ -785,7 +805,8 @@ static int qemudVMData(struct qemud_driv } -static int qemudShutdownVMDaemon(struct qemud_driver *driver, struct qemud_vm *vm) { +static int qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED, + struct qemud_driver *driver, struct qemud_vm *vm) { if (!qemudIsActiveVM(vm)) return 0; @@ -838,20 +859,21 @@ static int qemudShutdownVMDaemon(struct static int qemudDispatchVMLog(struct qemud_driver *driver, struct qemud_vm *vm, int fd) { if (qemudVMData(driver, vm, fd) < 0) - if (qemudShutdownVMDaemon(driver, vm) < 0) + if (qemudShutdownVMDaemon(NULL, driver, vm) < 0) return -1; return 0; } static int qemudDispatchVMFailure(struct qemud_driver *driver, struct qemud_vm *vm, int fd ATTRIBUTE_UNUSED) { - if (qemudShutdownVMDaemon(driver, vm) < 0) + if (qemudShutdownVMDaemon(NULL, driver, vm) < 0) return -1; return 0; } static int -qemudBuildDnsmasqArgv(struct qemud_network *network, +qemudBuildDnsmasqArgv(virConnectPtr conn, + struct qemud_network *network, char ***argv) { int i, len; char buf[PATH_MAX]; @@ -942,28 +964,29 @@ qemudBuildDnsmasqArgv(struct qemud_netwo free((*argv)[i]); free(*argv); } - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "dnsmasq argv"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "dnsmasq argv"); return -1; } static int -dhcpStartDhcpDaemon(struct qemud_network *network) +dhcpStartDhcpDaemon(virConnectPtr conn, + struct qemud_network *network) { char **argv; int ret, i; if (network->def->ipAddress[0] == '\0') { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot start dhcp daemon without IP address for server"); return -1; } argv = NULL; - if (qemudBuildDnsmasqArgv(network, &argv) < 0) + if (qemudBuildDnsmasqArgv(conn, network, &argv) < 0) return -1; - ret = qemudExec(argv, &network->dnsmasqPid, NULL, NULL); + ret = qemudExec(conn, argv, &network->dnsmasqPid, NULL, NULL); for (i = 0; argv[i]; i++) free(argv[i]); @@ -973,26 +996,27 @@ dhcpStartDhcpDaemon(struct qemud_network } static int -qemudAddIptablesRules(struct qemud_driver *driver, +qemudAddIptablesRules(virConnectPtr conn, + struct qemud_driver *driver, struct qemud_network *network) { int err; if (!driver->iptables && !(driver->iptables = iptablesContextNew())) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "iptables support"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "iptables support"); return 1; } /* allow DHCP requests through to dnsmasq */ if ((err = iptablesAddTcpInput(driver->iptables, network->bridge, 67))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to allow DHCP requests from '%s' : %s\n", network->bridge, strerror(err)); goto err1; } if ((err = iptablesAddUdpInput(driver->iptables, network->bridge, 67))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to allow DHCP requests from '%s' : %s\n", network->bridge, strerror(err)); goto err2; @@ -1000,14 +1024,14 @@ qemudAddIptablesRules(struct qemud_drive /* allow DNS requests through to dnsmasq */ if ((err = iptablesAddTcpInput(driver->iptables, network->bridge, 53))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to allow DNS requests from '%s' : %s\n", network->bridge, strerror(err)); goto err3; } if ((err = iptablesAddUdpInput(driver->iptables, network->bridge, 53))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to allow DNS requests from '%s' : %s\n", network->bridge, strerror(err)); goto err4; @@ -1017,14 +1041,14 @@ qemudAddIptablesRules(struct qemud_drive /* Catch all rules to block forwarding to/from bridges */ if ((err = iptablesAddForwardRejectOut(driver->iptables, network->bridge))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to block outbound traffic from '%s' : %s\n", network->bridge, strerror(err)); goto err5; } if ((err = iptablesAddForwardRejectIn(driver->iptables, network->bridge))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to block inbound traffic to '%s' : %s\n", network->bridge, strerror(err)); goto err6; @@ -1032,7 +1056,7 @@ qemudAddIptablesRules(struct qemud_drive /* Allow traffic between guests on the same bridge */ if ((err = iptablesAddForwardAllowCross(driver->iptables, network->bridge))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to allow cross bridge traffic on '%s' : %s\n", network->bridge, strerror(err)); goto err7; @@ -1048,7 +1072,7 @@ qemudAddIptablesRules(struct qemud_drive network->def->network, network->bridge, network->def->forwardDev))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to allow forwarding from '%s' : %s\n", network->bridge, strerror(err)); goto err8; @@ -1059,7 +1083,7 @@ qemudAddIptablesRules(struct qemud_drive network->def->network, network->bridge, network->def->forwardDev))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to allow forwarding to '%s' : %s\n", network->bridge, strerror(err)); goto err9; @@ -1069,7 +1093,7 @@ qemudAddIptablesRules(struct qemud_drive if ((err = iptablesAddForwardMasquerade(driver->iptables, network->def->network, network->def->forwardDev))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to add iptables rule to enable masquerading : %s\n", strerror(err)); goto err10; @@ -1153,19 +1177,20 @@ qemudEnableIpForwarding(void) #undef PROC_IP_FORWARD } -static int qemudStartNetworkDaemon(struct qemud_driver *driver, - struct qemud_network *network) { +static int qemudStartNetworkDaemon(virConnectPtr conn, + struct qemud_driver *driver, + struct qemud_network *network) { const char *name; int err; if (qemudIsActiveNetwork(network)) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "network is already active"); return -1; } if (!driver->brctl && (err = brInit(&driver->brctl))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot initialize bridge support: %s", strerror(err)); return -1; } @@ -1178,7 +1203,7 @@ static int qemudStartNetworkDaemon(struc } if ((err = brAddBridge(driver->brctl, name, network->bridge, sizeof(network->bridge)))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot create bridge '%s' : %s", name, strerror(err)); return -1; } @@ -1186,14 +1211,14 @@ static int qemudStartNetworkDaemon(struc if (network->def->forwardDelay && (err = brSetForwardDelay(driver->brctl, network->bridge, network->def->forwardDelay))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to set bridge forward delay to %d\n", network->def->forwardDelay); goto err_delbr; } if ((err = brSetForwardDelay(driver->brctl, network->bridge, network->def->disableSTP ? 0 : 1))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to set bridge STP to %s\n", network->def->disableSTP ? "off" : "on"); goto err_delbr; @@ -1201,7 +1226,7 @@ static int qemudStartNetworkDaemon(struc if (network->def->ipAddress[0] && (err = brSetInetAddress(driver->brctl, network->bridge, network->def->ipAddress))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot set IP address on bridge '%s' to '%s' : %s\n", network->bridge, network->def->ipAddress, strerror(err)); goto err_delbr; @@ -1209,7 +1234,7 @@ static int qemudStartNetworkDaemon(struc if (network->def->netmask[0] && (err = brSetInetNetmask(driver->brctl, network->bridge, network->def->netmask))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "cannot set netmask on bridge '%s' to '%s' : %s\n", network->bridge, network->def->netmask, strerror(err)); goto err_delbr; @@ -1217,24 +1242,24 @@ static int qemudStartNetworkDaemon(struc if (network->def->ipAddress[0] && (err = brSetInterfaceUp(driver->brctl, network->bridge, 1))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to bring the bridge '%s' up : %s\n", network->bridge, strerror(err)); goto err_delbr; } - if (!qemudAddIptablesRules(driver, network)) + if (!qemudAddIptablesRules(conn, driver, network)) goto err_delbr1; if (network->def->forward && !qemudEnableIpForwarding()) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "failed to enable IP forwarding : %s\n", strerror(err)); goto err_delbr2; } if (network->def->ranges && - dhcpStartDhcpDaemon(network) < 0) + dhcpStartDhcpDaemon(conn, network) < 0) goto err_delbr2; network->active = 1; @@ -1264,8 +1289,9 @@ static int qemudStartNetworkDaemon(struc } -static int qemudShutdownNetworkDaemon(struct qemud_driver *driver, - struct qemud_network *network) { +static int qemudShutdownNetworkDaemon(virConnectPtr conn ATTRIBUTE_UNUSED, + struct qemud_driver *driver, + struct qemud_network *network) { int err; qemudLog(QEMUD_INFO, "Shutting down network '%s'", network->def->name); @@ -1790,7 +1816,7 @@ static virDomainPtr qemudDomainLookupByN static int qemudGetVersion(virConnectPtr conn, unsigned long *version) { struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; - if (qemudExtractVersion(driver) < 0) + if (qemudExtractVersion(conn, driver) < 0) return -1; *version = qemu_driver->qemuVersion; @@ -1815,21 +1841,21 @@ static int qemudNumDomains(virConnectPtr return driver->nactivevms; } static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags ATTRIBUTE_UNUSED) { struct qemud_vm_def *def; struct qemud_vm *vm; virDomainPtr dom; struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; - if (!(def = qemudParseVMDef(driver, xml, NULL))) + if (!(def = qemudParseVMDef(conn, driver, xml, NULL))) return NULL; - if (!(vm = qemudAssignVMDef(driver, def))) { + if (!(vm = qemudAssignVMDef(conn, driver, def))) { qemudFreeVMDef(def); return NULL; } - if (qemudStartVMDaemon(driver, vm) < 0) { + if (qemudStartVMDaemon(conn, driver, vm) < 0) { qemudRemoveInactiveVM(driver, vm); return NULL; } @@ -1902,7 +1928,7 @@ static int qemudDomainDestroy(virDomainP return -1; } - ret = qemudShutdownVMDaemon(driver, vm); + ret = qemudShutdownVMDaemon(dom->conn, driver, vm); virFreeDomain(dom->conn, dom); return ret; } @@ -1987,7 +2013,7 @@ static char *qemudDomainDumpXML(virDomai return NULL; } - return qemudGenerateXML(driver, vm, vm->def, 1); + return qemudGenerateXML(dom->conn, driver, vm, vm->def, 1); } @@ -2031,7 +2057,7 @@ static int qemudDomainStart(virDomainPtr return -1; } - return qemudStartVMDaemon(driver, vm); + return qemudStartVMDaemon(dom->conn, driver, vm); } @@ -2041,15 +2067,15 @@ static virDomainPtr qemudDomainDefine(vi struct qemud_vm *vm; virDomainPtr dom; - if (!(def = qemudParseVMDef(driver, xml, NULL))) + if (!(def = qemudParseVMDef(conn, driver, xml, NULL))) return NULL; - if (!(vm = qemudAssignVMDef(driver, def))) { + if (!(vm = qemudAssignVMDef(conn, driver, def))) { qemudFreeVMDef(def); return NULL; } - if (qemudSaveVMDef(driver, vm, def) < 0) { + if (qemudSaveVMDef(conn, driver, vm, def) < 0) { qemudRemoveInactiveVM(driver, vm); return NULL; } @@ -2073,7 +2099,7 @@ static int qemudDomainUndefine(virDomain return -1; } - if (qemudDeleteConfig(driver, vm->configFile, vm->def->name) < 0) + if (qemudDeleteConfig(dom->conn, driver, vm->configFile, vm->def->name) < 0) return -1; if (unlink(vm->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) @@ -2252,15 +2278,15 @@ static virNetworkPtr qemudNetworkCreate( struct qemud_network *network; virNetworkPtr net; - if (!(def = qemudParseNetworkDef(driver, xml, NULL))) + if (!(def = qemudParseNetworkDef(conn, driver, xml, NULL))) return NULL; - if (!(network = qemudAssignNetworkDef(driver, def))) { + if (!(network = qemudAssignNetworkDef(conn, driver, def))) { qemudFreeNetworkDef(def); return NULL; } - if (qemudStartNetworkDaemon(driver, network) < 0) { + if (qemudStartNetworkDaemon(conn, driver, network) < 0) { qemudRemoveInactiveNetwork(driver, network); return NULL; } @@ -2275,15 +2301,15 @@ static virNetworkPtr qemudNetworkDefine( struct qemud_network *network; virNetworkPtr net; - if (!(def = qemudParseNetworkDef(driver, xml, NULL))) + if (!(def = qemudParseNetworkDef(conn, driver, xml, NULL))) return NULL; - if (!(network = qemudAssignNetworkDef(driver, def))) { + if (!(network = qemudAssignNetworkDef(conn, driver, def))) { qemudFreeNetworkDef(def); return NULL; } - if (qemudSaveNetworkDef(driver, network, def) < 0) { + if (qemudSaveNetworkDef(conn, driver, network, def) < 0) { qemudRemoveInactiveNetwork(driver, network); return NULL; } @@ -2301,7 +2327,7 @@ static int qemudNetworkUndefine(virNetwo return -1; } - if (qemudDeleteConfig(driver, network->configFile, network->def->name) < 0) + if (qemudDeleteConfig(net->conn, driver, network->configFile, network->def->name) < 0) return -1; if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) @@ -2326,7 +2352,7 @@ static int qemudNetworkStart(virNetworkP return -1; } - return qemudStartNetworkDaemon(driver, network); + return qemudStartNetworkDaemon(net->conn, driver, network); } static int qemudNetworkDestroy(virNetworkPtr net) { @@ -2340,7 +2366,7 @@ static int qemudNetworkDestroy(virNetwor return -1; } - ret = qemudShutdownNetworkDaemon(driver, network); + ret = qemudShutdownNetworkDaemon(net->conn, driver, network); virFreeNetwork(net->conn, net); @@ -2357,7 +2383,7 @@ static char *qemudNetworkDumpXML(virNetw return NULL; } - return qemudGenerateNetworkXML(driver, network, network->def); + return qemudGenerateNetworkXML(net->conn, driver, network, network->def); } static char *qemudNetworkGetBridgeName(virNetworkPtr net) {
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list