[libvirt] [PATCH 0/8] Remove virConnectPtr from yet more places

Following on from previous two postings http://www.redhat.com/archives/libvir-list/2010-February/msg00198.html http://www.redhat.com/archives/libvir-list/2010-February/msg00279.html With this series, none of the shared driver code uses virConnectPtr anymore, with the exception of src/conf/domain_events.h which has a genuine need for it - events are dispatched back to a specifici connection handle.

All callers now pass a NULL virConnectPtr into the USB/PCi device iterator functions. Therefore the virConnectPtr arg can now be removed from these functions * src/util/hostusb.h, src/util/hostusb.c: Remove virConnectPtr from usbDeviceFileIterate * src/util/pci.c, src/util/pci.h: Remove virConnectPtr arg from pciDeviceFileIterate * src/qemu/qemu_security_dac.c, src/security/security_selinux.c: Update to drop redundant virConnectPtr arg --- src/qemu/qemu_security_dac.c | 20 ++++++++------------ src/security/security_selinux.c | 20 ++++++++------------ src/util/hostusb.c | 5 ++--- src/util/hostusb.h | 5 ++--- src/util/pci.c | 5 ++--- src/util/pci.h | 5 ++--- 6 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_security_dac.c b/src/qemu/qemu_security_dac.c index 11f41b3..f281b96 100644 --- a/src/qemu/qemu_security_dac.c +++ b/src/qemu/qemu_security_dac.c @@ -173,8 +173,7 @@ qemuSecurityDACRestoreSecurityImageLabel(virDomainObjPtr vm ATTRIBUTE_UNUSED, static int -qemuSecurityDACSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, - pciDevice *dev ATTRIBUTE_UNUSED, +qemuSecurityDACSetSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -183,8 +182,7 @@ qemuSecurityDACSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, static int -qemuSecurityDACSetSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED, - usbDevice *dev ATTRIBUTE_UNUSED, +qemuSecurityDACSetSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -215,7 +213,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virDomainObjPtr vm, if (!usb) goto done; - ret = usbDeviceFileIterate(NULL, usb, qemuSecurityDACSetSecurityUSBLabel, vm); + ret = usbDeviceFileIterate(usb, qemuSecurityDACSetSecurityUSBLabel, vm); usbFreeDevice(usb); break; } @@ -229,7 +227,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virDomainObjPtr vm, if (!pci) goto done; - ret = pciDeviceFileIterate(NULL, pci, qemuSecurityDACSetSecurityPCILabel, vm); + ret = pciDeviceFileIterate(pci, qemuSecurityDACSetSecurityPCILabel, vm); pciFreeDevice(pci); break; @@ -246,8 +244,7 @@ done: static int -qemuSecurityDACRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, - pciDevice *dev ATTRIBUTE_UNUSED, +qemuSecurityDACRestoreSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -256,8 +253,7 @@ qemuSecurityDACRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, static int -qemuSecurityDACRestoreSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED, - usbDevice *dev ATTRIBUTE_UNUSED, +qemuSecurityDACRestoreSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -288,7 +284,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virDomainObjPtr vm ATTRIBUTE_UNUSED, if (!usb) goto done; - ret = usbDeviceFileIterate(NULL, usb, qemuSecurityDACRestoreSecurityUSBLabel, NULL); + ret = usbDeviceFileIterate(usb, qemuSecurityDACRestoreSecurityUSBLabel, NULL); usbFreeDevice(usb); break; @@ -303,7 +299,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virDomainObjPtr vm ATTRIBUTE_UNUSED, if (!pci) goto done; - ret = pciDeviceFileIterate(NULL, pci, qemuSecurityDACRestoreSecurityPCILabel, NULL); + ret = pciDeviceFileIterate(pci, qemuSecurityDACRestoreSecurityPCILabel, NULL); pciFreeDevice(pci); break; diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 7507549..06a2479 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -455,8 +455,7 @@ SELinuxSetSecurityImageLabel(virDomainObjPtr vm, static int -SELinuxSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, - pciDevice *dev ATTRIBUTE_UNUSED, +SELinuxSetSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque) { virDomainObjPtr vm = opaque; @@ -466,8 +465,7 @@ SELinuxSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, } static int -SELinuxSetSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED, - usbDevice *dev ATTRIBUTE_UNUSED, +SELinuxSetSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque) { virDomainObjPtr vm = opaque; @@ -500,7 +498,7 @@ SELinuxSetSecurityHostdevLabel(virDomainObjPtr vm, if (!usb) goto done; - ret = usbDeviceFileIterate(NULL, usb, SELinuxSetSecurityUSBLabel, vm); + ret = usbDeviceFileIterate(usb, SELinuxSetSecurityUSBLabel, vm); usbFreeDevice(usb); break; } @@ -514,7 +512,7 @@ SELinuxSetSecurityHostdevLabel(virDomainObjPtr vm, if (!pci) goto done; - ret = pciDeviceFileIterate(NULL, pci, SELinuxSetSecurityPCILabel, vm); + ret = pciDeviceFileIterate(pci, SELinuxSetSecurityPCILabel, vm); pciFreeDevice(pci); break; @@ -531,8 +529,7 @@ done: static int -SELinuxRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, - pciDevice *dev ATTRIBUTE_UNUSED, +SELinuxRestoreSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -540,8 +537,7 @@ SELinuxRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, } static int -SELinuxRestoreSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED, - usbDevice *dev ATTRIBUTE_UNUSED, +SELinuxRestoreSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -572,7 +568,7 @@ SELinuxRestoreSecurityHostdevLabel(virDomainObjPtr vm, if (!usb) goto done; - ret = usbDeviceFileIterate(NULL, usb, SELinuxRestoreSecurityUSBLabel, NULL); + ret = usbDeviceFileIterate(usb, SELinuxRestoreSecurityUSBLabel, NULL); usbFreeDevice(usb); break; @@ -587,7 +583,7 @@ SELinuxRestoreSecurityHostdevLabel(virDomainObjPtr vm, if (!pci) goto done; - ret = pciDeviceFileIterate(NULL, pci, SELinuxRestoreSecurityPCILabel, NULL); + ret = pciDeviceFileIterate(pci, SELinuxRestoreSecurityPCILabel, NULL); pciFreeDevice(pci); break; diff --git a/src/util/hostusb.c b/src/util/hostusb.c index 7ed262b..3cce66b 100644 --- a/src/util/hostusb.c +++ b/src/util/hostusb.c @@ -202,10 +202,9 @@ usbFreeDevice(usbDevice *dev) } -int usbDeviceFileIterate(virConnectPtr conn, - usbDevice *dev, +int usbDeviceFileIterate(usbDevice *dev, usbDeviceFileActor actor, void *opaque) { - return (actor)(conn, dev, dev->path, opaque); + return (actor)(dev, dev->path, opaque); } diff --git a/src/util/hostusb.h b/src/util/hostusb.h index 2579bdb..bc22671 100644 --- a/src/util/hostusb.h +++ b/src/util/hostusb.h @@ -39,11 +39,10 @@ void usbFreeDevice (usbDevice *dev); * Should return 0 if successfully processed, or * -1 to indicate error and abort iteration */ -typedef int (*usbDeviceFileActor)(virConnectPtr conn, usbDevice *dev, +typedef int (*usbDeviceFileActor)(usbDevice *dev, const char *path, void *opaque); -int usbDeviceFileIterate(virConnectPtr conn, - usbDevice *dev, +int usbDeviceFileIterate(usbDevice *dev, usbDeviceFileActor actor, void *opaque); diff --git a/src/util/pci.c b/src/util/pci.c index e639910..44eb439 100644 --- a/src/util/pci.c +++ b/src/util/pci.c @@ -1194,8 +1194,7 @@ pciDeviceListFind(pciDeviceList *list, pciDevice *dev) } -int pciDeviceFileIterate(virConnectPtr conn, - pciDevice *dev, +int pciDeviceFileIterate(pciDevice *dev, pciDeviceFileActor actor, void *opaque) { @@ -1228,7 +1227,7 @@ int pciDeviceFileIterate(virConnectPtr conn, virReportOOMError(); goto cleanup; } - if ((actor)(conn, dev, file, opaque) < 0) + if ((actor)(dev, file, opaque) < 0) goto cleanup; VIR_FREE(file); diff --git a/src/util/pci.h b/src/util/pci.h index ad518a5..b31d0cf 100644 --- a/src/util/pci.h +++ b/src/util/pci.h @@ -61,11 +61,10 @@ pciDevice * pciDeviceListFind (pciDeviceList *list, * Should return 0 if successfully processed, or * -1 to indicate error and abort iteration */ -typedef int (*pciDeviceFileActor)(virConnectPtr conn, pciDevice *dev, +typedef int (*pciDeviceFileActor)(pciDevice *dev, const char *path, void *opaque); -int pciDeviceFileIterate(virConnectPtr conn, - pciDevice *dev, +int pciDeviceFileIterate(pciDevice *dev, pciDeviceFileActor actor, void *opaque); -- 1.6.6

On Wed, Feb 10, 2010 at 01:36:19PM +0000, Daniel P. Berrange wrote:
All callers now pass a NULL virConnectPtr into the USB/PCi device iterator functions. Therefore the virConnectPtr arg can now be removed from these functions
* src/util/hostusb.h, src/util/hostusb.c: Remove virConnectPtr from usbDeviceFileIterate * src/util/pci.c, src/util/pci.h: Remove virConnectPtr arg from pciDeviceFileIterate * src/qemu/qemu_security_dac.c, src/security/security_selinux.c: Update to drop redundant virConnectPtr arg --- src/qemu/qemu_security_dac.c | 20 ++++++++------------ src/security/security_selinux.c | 20 ++++++++------------ src/util/hostusb.c | 5 ++--- src/util/hostusb.h | 5 ++--- src/util/pci.c | 5 ++--- src/util/pci.h | 5 ++--- 6 files changed, 24 insertions(+), 36 deletions(-)
diff --git a/src/qemu/qemu_security_dac.c b/src/qemu/qemu_security_dac.c index 11f41b3..f281b96 100644 --- a/src/qemu/qemu_security_dac.c +++ b/src/qemu/qemu_security_dac.c @@ -173,8 +173,7 @@ qemuSecurityDACRestoreSecurityImageLabel(virDomainObjPtr vm ATTRIBUTE_UNUSED,
static int -qemuSecurityDACSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, - pciDevice *dev ATTRIBUTE_UNUSED, +qemuSecurityDACSetSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -183,8 +182,7 @@ qemuSecurityDACSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED,
static int -qemuSecurityDACSetSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED, - usbDevice *dev ATTRIBUTE_UNUSED, +qemuSecurityDACSetSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -215,7 +213,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virDomainObjPtr vm, if (!usb) goto done;
- ret = usbDeviceFileIterate(NULL, usb, qemuSecurityDACSetSecurityUSBLabel, vm); + ret = usbDeviceFileIterate(usb, qemuSecurityDACSetSecurityUSBLabel, vm); usbFreeDevice(usb); break; } @@ -229,7 +227,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virDomainObjPtr vm, if (!pci) goto done;
- ret = pciDeviceFileIterate(NULL, pci, qemuSecurityDACSetSecurityPCILabel, vm); + ret = pciDeviceFileIterate(pci, qemuSecurityDACSetSecurityPCILabel, vm); pciFreeDevice(pci);
break; @@ -246,8 +244,7 @@ done:
static int -qemuSecurityDACRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, - pciDevice *dev ATTRIBUTE_UNUSED, +qemuSecurityDACRestoreSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -256,8 +253,7 @@ qemuSecurityDACRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED,
static int -qemuSecurityDACRestoreSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED, - usbDevice *dev ATTRIBUTE_UNUSED, +qemuSecurityDACRestoreSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -288,7 +284,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virDomainObjPtr vm ATTRIBUTE_UNUSED, if (!usb) goto done;
- ret = usbDeviceFileIterate(NULL, usb, qemuSecurityDACRestoreSecurityUSBLabel, NULL); + ret = usbDeviceFileIterate(usb, qemuSecurityDACRestoreSecurityUSBLabel, NULL); usbFreeDevice(usb);
break; @@ -303,7 +299,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virDomainObjPtr vm ATTRIBUTE_UNUSED, if (!pci) goto done;
- ret = pciDeviceFileIterate(NULL, pci, qemuSecurityDACRestoreSecurityPCILabel, NULL); + ret = pciDeviceFileIterate(pci, qemuSecurityDACRestoreSecurityPCILabel, NULL); pciFreeDevice(pci);
break; diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 7507549..06a2479 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -455,8 +455,7 @@ SELinuxSetSecurityImageLabel(virDomainObjPtr vm,
static int -SELinuxSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, - pciDevice *dev ATTRIBUTE_UNUSED, +SELinuxSetSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque) { virDomainObjPtr vm = opaque; @@ -466,8 +465,7 @@ SELinuxSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, }
static int -SELinuxSetSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED, - usbDevice *dev ATTRIBUTE_UNUSED, +SELinuxSetSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque) { virDomainObjPtr vm = opaque; @@ -500,7 +498,7 @@ SELinuxSetSecurityHostdevLabel(virDomainObjPtr vm, if (!usb) goto done;
- ret = usbDeviceFileIterate(NULL, usb, SELinuxSetSecurityUSBLabel, vm); + ret = usbDeviceFileIterate(usb, SELinuxSetSecurityUSBLabel, vm); usbFreeDevice(usb); break; } @@ -514,7 +512,7 @@ SELinuxSetSecurityHostdevLabel(virDomainObjPtr vm, if (!pci) goto done;
- ret = pciDeviceFileIterate(NULL, pci, SELinuxSetSecurityPCILabel, vm); + ret = pciDeviceFileIterate(pci, SELinuxSetSecurityPCILabel, vm); pciFreeDevice(pci);
break; @@ -531,8 +529,7 @@ done:
static int -SELinuxRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, - pciDevice *dev ATTRIBUTE_UNUSED, +SELinuxRestoreSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -540,8 +537,7 @@ SELinuxRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED, }
static int -SELinuxRestoreSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED, - usbDevice *dev ATTRIBUTE_UNUSED, +SELinuxRestoreSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED, const char *file, void *opaque ATTRIBUTE_UNUSED) { @@ -572,7 +568,7 @@ SELinuxRestoreSecurityHostdevLabel(virDomainObjPtr vm, if (!usb) goto done;
- ret = usbDeviceFileIterate(NULL, usb, SELinuxRestoreSecurityUSBLabel, NULL); + ret = usbDeviceFileIterate(usb, SELinuxRestoreSecurityUSBLabel, NULL); usbFreeDevice(usb);
break; @@ -587,7 +583,7 @@ SELinuxRestoreSecurityHostdevLabel(virDomainObjPtr vm, if (!pci) goto done;
- ret = pciDeviceFileIterate(NULL, pci, SELinuxRestoreSecurityPCILabel, NULL); + ret = pciDeviceFileIterate(pci, SELinuxRestoreSecurityPCILabel, NULL); pciFreeDevice(pci);
break; diff --git a/src/util/hostusb.c b/src/util/hostusb.c index 7ed262b..3cce66b 100644 --- a/src/util/hostusb.c +++ b/src/util/hostusb.c @@ -202,10 +202,9 @@ usbFreeDevice(usbDevice *dev) }
-int usbDeviceFileIterate(virConnectPtr conn, - usbDevice *dev, +int usbDeviceFileIterate(usbDevice *dev, usbDeviceFileActor actor, void *opaque) { - return (actor)(conn, dev, dev->path, opaque); + return (actor)(dev, dev->path, opaque); } diff --git a/src/util/hostusb.h b/src/util/hostusb.h index 2579bdb..bc22671 100644 --- a/src/util/hostusb.h +++ b/src/util/hostusb.h @@ -39,11 +39,10 @@ void usbFreeDevice (usbDevice *dev); * Should return 0 if successfully processed, or * -1 to indicate error and abort iteration */ -typedef int (*usbDeviceFileActor)(virConnectPtr conn, usbDevice *dev, +typedef int (*usbDeviceFileActor)(usbDevice *dev, const char *path, void *opaque);
-int usbDeviceFileIterate(virConnectPtr conn, - usbDevice *dev, +int usbDeviceFileIterate(usbDevice *dev, usbDeviceFileActor actor, void *opaque);
diff --git a/src/util/pci.c b/src/util/pci.c index e639910..44eb439 100644 --- a/src/util/pci.c +++ b/src/util/pci.c @@ -1194,8 +1194,7 @@ pciDeviceListFind(pciDeviceList *list, pciDevice *dev) }
-int pciDeviceFileIterate(virConnectPtr conn, - pciDevice *dev, +int pciDeviceFileIterate(pciDevice *dev, pciDeviceFileActor actor, void *opaque) { @@ -1228,7 +1227,7 @@ int pciDeviceFileIterate(virConnectPtr conn, virReportOOMError(); goto cleanup; } - if ((actor)(conn, dev, file, opaque) < 0) + if ((actor)(dev, file, opaque) < 0) goto cleanup;
VIR_FREE(file); diff --git a/src/util/pci.h b/src/util/pci.h index ad518a5..b31d0cf 100644 --- a/src/util/pci.h +++ b/src/util/pci.h @@ -61,11 +61,10 @@ pciDevice * pciDeviceListFind (pciDeviceList *list, * Should return 0 if successfully processed, or * -1 to indicate error and abort iteration */ -typedef int (*pciDeviceFileActor)(virConnectPtr conn, pciDevice *dev, +typedef int (*pciDeviceFileActor)(pciDevice *dev, const char *path, void *opaque);
-int pciDeviceFileIterate(virConnectPtr conn, - pciDevice *dev, +int pciDeviceFileIterate(pciDevice *dev, pciDeviceFileActor actor, void *opaque);
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in network_conf.{h,c} and update all callers to match --- src/conf/network_conf.c | 162 ++++++++++++++++++------------------------- src/conf/network_conf.h | 44 ++++-------- src/network/bridge_driver.c | 128 ++++++++++++++++------------------ src/test/test_driver.c | 20 +++--- src/vbox/vbox_tmpl.c | 4 +- tests/networkxml2xmltest.c | 4 +- 6 files changed, 157 insertions(+), 205 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 6e857f9..6d3c3c0 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -53,9 +53,9 @@ VIR_ENUM_IMPL(virNetworkForward, VIR_NETWORK_FORWARD_LAST, "none", "nat", "route" ) -#define virNetworkReportError(conn, code, fmt...) \ - virReportErrorHelper(conn, VIR_FROM_NETWORK, code, __FILE__, \ - __FUNCTION__, __LINE__, fmt) +#define virNetworkReportError(code, fmt...) \ + virReportErrorHelper(NULL, VIR_FROM_NETWORK, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets, const unsigned char *uuid) @@ -147,8 +147,7 @@ void virNetworkObjListFree(virNetworkObjListPtr nets) nets->count = 0; } -virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn, - virNetworkObjListPtr nets, +virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets, const virNetworkDefPtr def) { virNetworkObjPtr network; @@ -171,7 +170,7 @@ virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn, return NULL; } if (virMutexInit(&network->lock) < 0) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); VIR_FREE(network); return NULL; @@ -221,8 +220,7 @@ void virNetworkRemoveInactive(virNetworkObjListPtr nets, static int -virNetworkDHCPRangeDefParseXML(virConnectPtr conn, - virNetworkDefPtr def, +virNetworkDHCPRangeDefParseXML(virNetworkDefPtr def, xmlNodePtr node) { xmlNodePtr cur; @@ -246,7 +244,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, } if (virSocketParseAddr(start, &saddr, 0) < 0) { - virNetworkReportError(conn, VIR_ERR_XML_ERROR, + virNetworkReportError(VIR_ERR_XML_ERROR, _("cannot parse dhcp start address '%s'"), start); xmlFree(start); @@ -255,7 +253,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, continue; } if (virSocketParseAddr(end, &eaddr, 0) < 0) { - virNetworkReportError(conn, VIR_ERR_XML_ERROR, + virNetworkReportError(VIR_ERR_XML_ERROR, _("cannot parse dhcp end address '%s'"), end); xmlFree(start); @@ -266,7 +264,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, range = virSocketGetRange(&saddr, &eaddr); if (range < 0) { - virNetworkReportError(conn, VIR_ERR_XML_ERROR, + virNetworkReportError(VIR_ERR_XML_ERROR, _("dhcp range '%s' to '%s' invalid"), start, end); xmlFree(start); @@ -294,14 +292,14 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, mac = xmlGetProp(cur, BAD_CAST "mac"); if ((mac != NULL) && (virParseMacAddr((const char *) mac, &addr[0]) != 0)) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse MAC address '%s'"), mac); VIR_FREE(mac); } name = xmlGetProp(cur, BAD_CAST "name"); if ((name != NULL) && (!c_isalpha(name[0]))) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("cannot use name address '%s'"), name); VIR_FREE(name); @@ -317,7 +315,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, } ip = xmlGetProp(cur, BAD_CAST "ip"); if (inet_pton(AF_INET, (const char *) ip, &inaddress) <= 0) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse IP address '%s'"), ip); VIR_FREE(ip); @@ -358,8 +356,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, } static int -virNetworkIPParseXML(virConnectPtr conn, - virNetworkDefPtr def, +virNetworkIPParseXML(virNetworkDefPtr def, xmlNodePtr node) { xmlNodePtr cur; @@ -367,7 +364,7 @@ virNetworkIPParseXML(virConnectPtr conn, while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "dhcp")) { - int result = virNetworkDHCPRangeDefParseXML(conn, def, cur); + int result = virNetworkDHCPRangeDefParseXML(def, cur); if (result) return result; @@ -389,8 +386,7 @@ virNetworkIPParseXML(virConnectPtr conn, } static virNetworkDefPtr -virNetworkDefParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt) +virNetworkDefParseXML(xmlXPathContextPtr ctxt) { virNetworkDefPtr def; char *tmp; @@ -403,7 +399,7 @@ virNetworkDefParseXML(virConnectPtr conn, /* Extract network name */ def->name = virXPathString("string(./name[1])", ctxt); if (!def->name) { - virNetworkReportError(conn, VIR_ERR_NO_NAME, NULL); + virNetworkReportError(VIR_ERR_NO_NAME, NULL); goto error; } @@ -411,14 +407,14 @@ virNetworkDefParseXML(virConnectPtr conn, tmp = virXPathString("string(./uuid[1])", ctxt); if (!tmp) { if (virUUIDGenerate(def->uuid)) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to generate UUID")); goto error; } } else { if (virUUIDParse(tmp, def->uuid) < 0) { VIR_FREE(tmp); - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed uuid element")); goto error; } @@ -447,13 +443,13 @@ virNetworkDefParseXML(virConnectPtr conn, xmlNodePtr ip; if (inet_pton(AF_INET, def->ipAddress, &inaddress) <= 0) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse IP address '%s'"), def->ipAddress); goto error; } if (inet_pton(AF_INET, def->netmask, &innetmask) <= 0) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse netmask '%s'"), def->netmask); goto error; @@ -468,7 +464,7 @@ virNetworkDefParseXML(virConnectPtr conn, } if ((ip = virXPathNode("./ip[1]", ctxt)) && - virNetworkIPParseXML(conn, def, ip) < 0) + virNetworkIPParseXML(def, ip) < 0) goto error; } @@ -477,7 +473,7 @@ virNetworkDefParseXML(virConnectPtr conn, if (virXPathBoolean("count(./forward) > 0", ctxt)) { if (!def->ipAddress || !def->netmask) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Forwarding requested, but no IPv4 address/netmask provided")); goto error; } @@ -485,7 +481,7 @@ virNetworkDefParseXML(virConnectPtr conn, tmp = virXPathString("string(./forward[1]/@mode)", ctxt); if (tmp) { if ((def->forwardType = virNetworkForwardTypeFromString(tmp)) < 0) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("unknown forwarding type '%s'"), tmp); VIR_FREE(tmp); goto error; @@ -515,22 +511,18 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; if (ctxt) { - virConnectPtr conn = ctxt->_private; - - if (conn && - conn->err.code == VIR_ERR_NONE && + if (virGetLastError() == NULL && ctxt->lastError.level == XML_ERR_FATAL && ctxt->lastError.message != NULL) { - virNetworkReportError (conn, VIR_ERR_XML_DETAIL, - _("at line %d: %s"), - ctxt->lastError.line, - ctxt->lastError.message); + virNetworkReportError(VIR_ERR_XML_DETAIL, + _("at line %d: %s"), + ctxt->lastError.line, + ctxt->lastError.message); } } } -virNetworkDefPtr virNetworkDefParseString(virConnectPtr conn, - const char *xmlStr) +virNetworkDefPtr virNetworkDefParseString(const char *xmlStr) { xmlParserCtxtPtr pctxt; xmlDocPtr xml = NULL; @@ -542,26 +534,24 @@ virNetworkDefPtr virNetworkDefParseString(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn; - if (conn) virResetError (&conn->err); xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "network.xml", NULL, XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOWARNING); if (!xml) { - if (conn && conn->err.code == VIR_ERR_NONE) - virNetworkReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("failed to parse xml document")); + if (virGetLastError() == NULL) + virNetworkReportError(VIR_ERR_XML_ERROR, + "%s", _("failed to parse xml document")); goto cleanup; } if ((root = xmlDocGetRootElement(xml)) == NULL) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing root element")); goto cleanup; } - def = virNetworkDefParseNode(conn, xml, root); + def = virNetworkDefParseNode(xml, root); cleanup: xmlFreeParserCtxt (pctxt); @@ -569,8 +559,7 @@ cleanup: return def; } -virNetworkDefPtr virNetworkDefParseFile(virConnectPtr conn, - const char *filename) +virNetworkDefPtr virNetworkDefParseFile(const char *filename) { xmlParserCtxtPtr pctxt; xmlDocPtr xml = NULL; @@ -582,26 +571,24 @@ virNetworkDefPtr virNetworkDefParseFile(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn; - if (conn) virResetError (&conn->err); xml = xmlCtxtReadFile (pctxt, filename, NULL, XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOWARNING); if (!xml) { - if (conn && conn->err.code == VIR_ERR_NONE) - virNetworkReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("failed to parse xml document")); + if (virGetLastError() == NULL) + virNetworkReportError(VIR_ERR_XML_ERROR, + "%s", _("failed to parse xml document")); goto cleanup; } if ((root = xmlDocGetRootElement(xml)) == NULL) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing root element")); goto cleanup; } - def = virNetworkDefParseNode(conn, xml, root); + def = virNetworkDefParseNode(xml, root); cleanup: xmlFreeParserCtxt (pctxt); @@ -610,15 +597,14 @@ cleanup: } -virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn, - xmlDocPtr xml, +virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml, xmlNodePtr root) { xmlXPathContextPtr ctxt = NULL; virNetworkDefPtr def = NULL; if (!xmlStrEqual(root->name, BAD_CAST "network")) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("incorrect root element")); return NULL; } @@ -630,15 +616,14 @@ virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn, } ctxt->node = root; - def = virNetworkDefParseXML(conn, ctxt); + def = virNetworkDefParseXML(ctxt); cleanup: xmlXPathFreeContext(ctxt); return def; } -char *virNetworkDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, - const virNetworkDefPtr def) +char *virNetworkDefFormat(const virNetworkDefPtr def) { virBuffer buf = VIR_BUFFER_INITIALIZER; unsigned char *uuid; @@ -734,8 +719,7 @@ char *virNetworkDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, return NULL; } -int virNetworkSaveXML(virConnectPtr conn, - const char *configDir, +int virNetworkSaveXML(const char *configDir, virNetworkDefPtr def, const char *xml) { @@ -744,7 +728,7 @@ int virNetworkSaveXML(virConnectPtr conn, size_t towrite; int err; - if ((configFile = virNetworkConfigFile(conn, configDir, def->name)) == NULL) + if ((configFile = virNetworkConfigFile(configDir, def->name)) == NULL) goto cleanup; if ((err = virFileMakePath(configDir))) { @@ -789,17 +773,16 @@ int virNetworkSaveXML(virConnectPtr conn, return ret; } -int virNetworkSaveConfig(virConnectPtr conn, - const char *configDir, +int virNetworkSaveConfig(const char *configDir, virNetworkDefPtr def) { int ret = -1; char *xml; - if (!(xml = virNetworkDefFormat(conn, def))) + if (!(xml = virNetworkDefFormat(def))) goto cleanup; - if (virNetworkSaveXML(conn, configDir, def, xml)) + if (virNetworkSaveXML(configDir, def, xml)) goto cleanup; ret = 0; @@ -809,8 +792,7 @@ cleanup: } -virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn, - virNetworkObjListPtr nets, +virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets, const char *configDir, const char *autostartDir, const char *name) @@ -820,19 +802,19 @@ virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn, virNetworkObjPtr net; int autostart; - if ((configFile = virNetworkConfigFile(conn, configDir, name)) == NULL) + if ((configFile = virNetworkConfigFile(configDir, name)) == NULL) goto error; - if ((autostartLink = virNetworkConfigFile(conn, autostartDir, name)) == NULL) + if ((autostartLink = virNetworkConfigFile(autostartDir, name)) == NULL) goto error; if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0) goto error; - if (!(def = virNetworkDefParseFile(conn, configFile))) + if (!(def = virNetworkDefParseFile(configFile))) goto error; if (!STREQ(name, def->name)) { - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("Network config filename '%s'" " does not match network name '%s'"), configFile, def->name); @@ -842,10 +824,10 @@ virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn, /* Generate a bridge if none is specified, but don't check for collisions * if a bridge is hardcoded, so the network is at least defined */ - if (virNetworkSetBridgeName(conn, nets, def, 0)) + if (virNetworkSetBridgeName(nets, def, 0)) goto error; - if (!(net = virNetworkAssignDef(conn, nets, def))) + if (!(net = virNetworkAssignDef(nets, def))) goto error; net->autostart = autostart; @@ -863,8 +845,7 @@ error: return NULL; } -int virNetworkLoadAllConfigs(virConnectPtr conn, - virNetworkObjListPtr nets, +int virNetworkLoadAllConfigs(virNetworkObjListPtr nets, const char *configDir, const char *autostartDir) { @@ -891,8 +872,7 @@ int virNetworkLoadAllConfigs(virConnectPtr conn, /* NB: ignoring errors, so one malformed config doesn't kill the whole process */ - net = virNetworkLoadConfig(conn, - nets, + net = virNetworkLoadConfig(nets, configDir, autostartDir, entry->d_name); @@ -905,8 +885,7 @@ int virNetworkLoadAllConfigs(virConnectPtr conn, return 0; } -int virNetworkDeleteConfig(virConnectPtr conn, - const char *configDir, +int virNetworkDeleteConfig(const char *configDir, const char *autostartDir, virNetworkObjPtr net) { @@ -914,9 +893,9 @@ int virNetworkDeleteConfig(virConnectPtr conn, char *autostartLink = NULL; int ret = -1; - if ((configFile = virNetworkConfigFile(conn, configDir, net->def->name)) == NULL) + if ((configFile = virNetworkConfigFile(configDir, net->def->name)) == NULL) goto error; - if ((autostartLink = virNetworkConfigFile(conn, autostartDir, net->def->name)) == NULL) + if ((autostartLink = virNetworkConfigFile(autostartDir, net->def->name)) == NULL) goto error; /* Not fatal if this doesn't work */ @@ -937,8 +916,7 @@ error: return ret; } -char *virNetworkConfigFile(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, - const char *dir, +char *virNetworkConfigFile(const char *dir, const char *name) { char *ret = NULL; @@ -970,8 +948,7 @@ int virNetworkBridgeInUse(const virNetworkObjListPtr nets, return ret; } -char *virNetworkAllocateBridge(virConnectPtr conn, - const virNetworkObjListPtr nets, +char *virNetworkAllocateBridge(const virNetworkObjListPtr nets, const char *template) { @@ -997,14 +974,13 @@ char *virNetworkAllocateBridge(virConnectPtr conn, id++; } while (id <= MAX_BRIDGE_ID); - virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("Bridge generation exceeded max id %d"), MAX_BRIDGE_ID); return NULL; } -int virNetworkSetBridgeName(virConnectPtr conn, - const virNetworkObjListPtr nets, +int virNetworkSetBridgeName(const virNetworkObjListPtr nets, virNetworkDefPtr def, int check_collision) { @@ -1016,14 +992,14 @@ int virNetworkSetBridgeName(virConnectPtr conn, * defined. */ if (check_collision && virNetworkBridgeInUse(nets, def->bridge, def->name)) { - networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, - _("bridge name '%s' already in use."), - def->bridge); + virNetworkReportError(VIR_ERR_INTERNAL_ERROR, + _("bridge name '%s' already in use."), + def->bridge); goto error; } } else { /* Allocate a bridge name */ - if (!(def->bridge = virNetworkAllocateBridge(conn, nets, def->bridge))) + if (!(def->bridge = virNetworkAllocateBridge(nets, def->bridge))) goto error; } diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 9e50659..c1d31c1 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -112,11 +112,6 @@ virNetworkObjIsActive(const virNetworkObjPtr net) return net->active; } -#define networkReportError(conn, dom, net, code, fmt...) \ - virReportErrorHelper(conn, VIR_FROM_QEMU, code, __FILE__, \ - __FUNCTION__, __LINE__, fmt) - - virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets, const unsigned char *uuid); virNetworkObjPtr virNetworkFindByName(const virNetworkObjListPtr nets, @@ -127,63 +122,50 @@ void virNetworkDefFree(virNetworkDefPtr def); void virNetworkObjFree(virNetworkObjPtr net); void virNetworkObjListFree(virNetworkObjListPtr vms); -virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn, - virNetworkObjListPtr nets, +virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets, const virNetworkDefPtr def); void virNetworkRemoveInactive(virNetworkObjListPtr nets, const virNetworkObjPtr net); -virNetworkDefPtr virNetworkDefParseString(virConnectPtr conn, - const char *xmlStr); -virNetworkDefPtr virNetworkDefParseFile(virConnectPtr conn, - const char *filename); -virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn, - xmlDocPtr xml, +virNetworkDefPtr virNetworkDefParseString(const char *xmlStr); +virNetworkDefPtr virNetworkDefParseFile(const char *filename); +virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml, xmlNodePtr root); -char *virNetworkDefFormat(virConnectPtr conn, - const virNetworkDefPtr def); +char *virNetworkDefFormat(const virNetworkDefPtr def); -int virNetworkSaveXML(virConnectPtr conn, - const char *configDir, +int virNetworkSaveXML(const char *configDir, virNetworkDefPtr def, const char *xml); -int virNetworkSaveConfig(virConnectPtr conn, - const char *configDir, +int virNetworkSaveConfig(const char *configDir, virNetworkDefPtr def); -virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn, - virNetworkObjListPtr nets, +virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets, const char *configDir, const char *autostartDir, const char *file); -int virNetworkLoadAllConfigs(virConnectPtr conn, - virNetworkObjListPtr nets, +int virNetworkLoadAllConfigs(virNetworkObjListPtr nets, const char *configDir, const char *autostartDir); -int virNetworkDeleteConfig(virConnectPtr conn, - const char *configDir, +int virNetworkDeleteConfig(const char *configDir, const char *autostartDir, virNetworkObjPtr net); -char *virNetworkConfigFile(virConnectPtr conn, - const char *dir, +char *virNetworkConfigFile(const char *dir, const char *name); int virNetworkBridgeInUse(const virNetworkObjListPtr nets, const char *bridge, const char *skipname); -char *virNetworkAllocateBridge(virConnectPtr conn, - const virNetworkObjListPtr nets, +char *virNetworkAllocateBridge(const virNetworkObjListPtr nets, const char *template); -int virNetworkSetBridgeName(virConnectPtr conn, - const virNetworkObjListPtr nets, +int virNetworkSetBridgeName(const virNetworkObjListPtr nets, virNetworkDefPtr def, int check_collision); diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index a3c6b9c..8cef714 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -63,6 +63,10 @@ #define VIR_FROM_THIS VIR_FROM_NETWORK +#define networkReportError(code, fmt...) \ + virReportErrorHelper(NULL, VIR_FROM_NETWORK, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) + /* Main driver state */ struct network_driver { virMutex lock; @@ -88,13 +92,11 @@ static void networkDriverUnlock(struct network_driver *driver) static int networkShutdown(void); -static int networkStartNetworkDaemon(virConnectPtr conn, - struct network_driver *driver, - virNetworkObjPtr network); +static int networkStartNetworkDaemon(struct network_driver *driver, + virNetworkObjPtr network); -static int networkShutdownNetworkDaemon(virConnectPtr conn, - struct network_driver *driver, - virNetworkObjPtr network); +static int networkShutdownNetworkDaemon(struct network_driver *driver, + virNetworkObjPtr network); static void networkReloadIptablesRules(struct network_driver *driver); @@ -112,8 +114,7 @@ networkFindActiveConfigs(struct network_driver *driver) { virNetworkObjLock(obj); - if ((config = virNetworkConfigFile(NULL, - NETWORK_STATE_DIR, + if ((config = virNetworkConfigFile(NETWORK_STATE_DIR, obj->def->name)) == NULL) { virNetworkObjUnlock(obj); continue; @@ -126,7 +127,7 @@ networkFindActiveConfigs(struct network_driver *driver) { } /* Try and load the live config */ - tmp = virNetworkDefParseFile(NULL, config); + tmp = virNetworkDefParseFile(config); VIR_FREE(config); if (tmp) { obj->newDef = obj->def; @@ -176,7 +177,7 @@ networkAutostartConfigs(struct network_driver *driver) { virNetworkObjLock(driver->networks.objs[i]); if (driver->networks.objs[i]->autostart && !virNetworkObjIsActive(driver->networks.objs[i]) && - networkStartNetworkDaemon(NULL, driver, driver->networks.objs[i]) < 0) { + networkStartNetworkDaemon(driver, driver->networks.objs[i]) < 0) { /* failed to start but already logged */ } virNetworkObjUnlock(driver->networks.objs[i]); @@ -252,8 +253,7 @@ networkStartup(int privileged) { } - if (virNetworkLoadAllConfigs(NULL, - &driverState->networks, + if (virNetworkLoadAllConfigs(&driverState->networks, driverState->networkConfigDir, driverState->networkAutostartDir) < 0) goto error; @@ -290,8 +290,7 @@ networkReload(void) { return 0; networkDriverLock(driverState); - virNetworkLoadAllConfigs(NULL, - &driverState->networks, + virNetworkLoadAllConfigs(&driverState->networks, driverState->networkConfigDir, driverState->networkAutostartDir); networkReloadIptablesRules(driverState); @@ -523,8 +522,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network, static int -dhcpStartDhcpDaemon(virConnectPtr conn, - virNetworkObjPtr network) +dhcpStartDhcpDaemon(virNetworkObjPtr network) { const char **argv; char *pidfile; @@ -533,8 +531,8 @@ dhcpStartDhcpDaemon(virConnectPtr conn, network->dnsmasqPid = -1; if (network->def->ipAddress == NULL) { - networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot start dhcp daemon without IP address for server")); + networkReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot start dhcp daemon without IP address for server")); return -1; } @@ -885,14 +883,14 @@ cleanup: return ret; } -static int networkStartNetworkDaemon(virConnectPtr conn, - struct network_driver *driver, - virNetworkObjPtr network) { +static int networkStartNetworkDaemon(struct network_driver *driver, + virNetworkObjPtr network) +{ int err; if (virNetworkObjIsActive(network)) { - networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, - "%s", _("network is already active")); + networkReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("network is already active")); return -1; } @@ -947,12 +945,12 @@ static int networkStartNetworkDaemon(virConnectPtr conn, if ((network->def->ipAddress || network->def->nranges) && - dhcpStartDhcpDaemon(conn, network) < 0) + dhcpStartDhcpDaemon(network) < 0) goto err_delbr2; /* Persist the live configuration now we have bridge info */ - if (virNetworkSaveConfig(conn, NETWORK_STATE_DIR, network->def) < 0) { + if (virNetworkSaveConfig(NETWORK_STATE_DIR, network->def) < 0) { goto err_kill; } @@ -987,9 +985,9 @@ static int networkStartNetworkDaemon(virConnectPtr conn, } -static int networkShutdownNetworkDaemon(virConnectPtr conn, - struct network_driver *driver, - virNetworkObjPtr network) { +static int networkShutdownNetworkDaemon(struct network_driver *driver, + virNetworkObjPtr network) +{ int err; char *stateFile; @@ -998,7 +996,7 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn, if (!virNetworkObjIsActive(network)) return 0; - stateFile = virNetworkConfigFile(conn, NETWORK_STATE_DIR, network->def->name); + stateFile = virNetworkConfigFile(NETWORK_STATE_DIR, network->def->name); if (!stateFile) return -1; @@ -1049,8 +1047,8 @@ static virNetworkPtr networkLookupByUUID(virConnectPtr conn, network = virNetworkFindByUUID(&driver->networks, uuid); networkDriverUnlock(driver); if (!network) { - networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK, - "%s", _("no network with matching uuid")); + networkReportError(VIR_ERR_NO_NETWORK, + "%s", _("no network with matching uuid")); goto cleanup; } @@ -1072,8 +1070,8 @@ static virNetworkPtr networkLookupByName(virConnectPtr conn, network = virNetworkFindByName(&driver->networks, name); networkDriverUnlock(driver); if (!network) { - networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), name); + networkReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), name); goto cleanup; } @@ -1198,7 +1196,7 @@ static int networkIsActive(virNetworkPtr net) obj = virNetworkFindByUUID(&driver->networks, net->uuid); networkDriverUnlock(driver); if (!obj) { - networkReportError(net->conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL); + networkReportError(VIR_ERR_NO_NETWORK, NULL); goto cleanup; } ret = virNetworkObjIsActive(obj); @@ -1219,7 +1217,7 @@ static int networkIsPersistent(virNetworkPtr net) obj = virNetworkFindByUUID(&driver->networks, net->uuid); networkDriverUnlock(driver); if (!obj) { - networkReportError(net->conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL); + networkReportError(VIR_ERR_NO_NETWORK, NULL); goto cleanup; } ret = obj->persistent; @@ -1239,19 +1237,18 @@ static virNetworkPtr networkCreate(virConnectPtr conn, const char *xml) { networkDriverLock(driver); - if (!(def = virNetworkDefParseString(conn, xml))) + if (!(def = virNetworkDefParseString(xml))) goto cleanup; - if (virNetworkSetBridgeName(conn, &driver->networks, def, 1)) + if (virNetworkSetBridgeName(&driver->networks, def, 1)) goto cleanup; - if (!(network = virNetworkAssignDef(conn, - &driver->networks, + if (!(network = virNetworkAssignDef(&driver->networks, def))) goto cleanup; def = NULL; - if (networkStartNetworkDaemon(conn, driver, network) < 0) { + if (networkStartNetworkDaemon(driver, network) < 0) { virNetworkRemoveInactive(&driver->networks, network); network = NULL; @@ -1276,22 +1273,20 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { networkDriverLock(driver); - if (!(def = virNetworkDefParseString(conn, xml))) + if (!(def = virNetworkDefParseString(xml))) goto cleanup; - if (virNetworkSetBridgeName(conn, &driver->networks, def, 1)) + if (virNetworkSetBridgeName(&driver->networks, def, 1)) goto cleanup; - if (!(network = virNetworkAssignDef(conn, - &driver->networks, + if (!(network = virNetworkAssignDef(&driver->networks, def))) goto cleanup; def = NULL; network->persistent = 1; - if (virNetworkSaveConfig(conn, - driver->networkConfigDir, + if (virNetworkSaveConfig(driver->networkConfigDir, network->newDef ? network->newDef : network->def) < 0) { virNetworkRemoveInactive(&driver->networks, network); @@ -1318,19 +1313,18 @@ static int networkUndefine(virNetworkPtr net) { network = virNetworkFindByUUID(&driver->networks, net->uuid); if (!network) { - networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, + networkReportError(VIR_ERR_INVALID_NETWORK, "%s", _("no network with matching uuid")); goto cleanup; } if (virNetworkObjIsActive(network)) { - networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, + networkReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("network is still active")); goto cleanup; } - if (virNetworkDeleteConfig(net->conn, - driver->networkConfigDir, + if (virNetworkDeleteConfig(driver->networkConfigDir, driver->networkAutostartDir, network) < 0) goto cleanup; @@ -1356,12 +1350,12 @@ static int networkStart(virNetworkPtr net) { network = virNetworkFindByUUID(&driver->networks, net->uuid); if (!network) { - networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, + networkReportError(VIR_ERR_INVALID_NETWORK, "%s", _("no network with matching uuid")); goto cleanup; } - ret = networkStartNetworkDaemon(net->conn, driver, network); + ret = networkStartNetworkDaemon(driver, network); cleanup: if (network) @@ -1379,18 +1373,18 @@ static int networkDestroy(virNetworkPtr net) { network = virNetworkFindByUUID(&driver->networks, net->uuid); if (!network) { - networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, + networkReportError(VIR_ERR_INVALID_NETWORK, "%s", _("no network with matching uuid")); goto cleanup; } if (!virNetworkObjIsActive(network)) { - networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, + networkReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("network is not active")); goto cleanup; } - ret = networkShutdownNetworkDaemon(net->conn, driver, network); + ret = networkShutdownNetworkDaemon(driver, network); if (!network->persistent) { virNetworkRemoveInactive(&driver->networks, network); @@ -1414,12 +1408,12 @@ static char *networkDumpXML(virNetworkPtr net, int flags ATTRIBUTE_UNUSED) { networkDriverUnlock(driver); if (!network) { - networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, + networkReportError(VIR_ERR_INVALID_NETWORK, "%s", _("no network with matching uuid")); goto cleanup; } - ret = virNetworkDefFormat(net->conn, network->def); + ret = virNetworkDefFormat(network->def); cleanup: if (network) @@ -1437,13 +1431,13 @@ static char *networkGetBridgeName(virNetworkPtr net) { networkDriverUnlock(driver); if (!network) { - networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, + networkReportError(VIR_ERR_INVALID_NETWORK, "%s", _("no network with matching id")); goto cleanup; } if (!(network->def->bridge)) { - networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, + networkReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' does not have a bridge name."), network->def->name); goto cleanup; @@ -1469,8 +1463,8 @@ static int networkGetAutostart(virNetworkPtr net, network = virNetworkFindByUUID(&driver->networks, net->uuid); networkDriverUnlock(driver); if (!network) { - networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, - "%s", _("no network with matching uuid")); + networkReportError(VIR_ERR_INVALID_NETWORK, + "%s", _("no network with matching uuid")); goto cleanup; } @@ -1494,23 +1488,23 @@ static int networkSetAutostart(virNetworkPtr net, network = virNetworkFindByUUID(&driver->networks, net->uuid); if (!network) { - networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, - "%s", _("no network with matching uuid")); + networkReportError(VIR_ERR_INVALID_NETWORK, + "%s", _("no network with matching uuid")); goto cleanup; } if (!network->persistent) { - networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot set autostart for transient network")); + networkReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot set autostart for transient network")); goto cleanup; } autostart = (autostart != 0); if (network->autostart != autostart) { - if ((configFile = virNetworkConfigFile(net->conn, driver->networkConfigDir, network->def->name)) == NULL) + if ((configFile = virNetworkConfigFile(driver->networkConfigDir, network->def->name)) == NULL) goto cleanup; - if ((autostartLink = virNetworkConfigFile(net->conn, driver->networkAutostartDir, network->def->name)) == NULL) + if ((autostartLink = virNetworkConfigFile(driver->networkAutostartDir, network->def->name)) == NULL) goto cleanup; if (autostart) { diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c141ae4..2f3ef16 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -558,9 +558,9 @@ static int testOpenDefault(virConnectPtr conn) { domobj->persistent = 1; virDomainObjUnlock(domobj); - if (!(netdef = virNetworkDefParseString(conn, defaultNetworkXML))) + if (!(netdef = virNetworkDefParseString(defaultNetworkXML))) goto error; - if (!(netobj = virNetworkAssignDef(conn, &privconn->networks, netdef))) { + if (!(netobj = virNetworkAssignDef(&privconn->networks, netdef))) { virNetworkDefFree(netdef); goto error; } @@ -934,15 +934,15 @@ static int testOpenFromFile(virConnectPtr conn, goto error; } - def = virNetworkDefParseFile(conn, absFile); + def = virNetworkDefParseFile(absFile); VIR_FREE(absFile); if (!def) goto error; } else { - if ((def = virNetworkDefParseNode(conn, xml, networks[i])) == NULL) + if ((def = virNetworkDefParseNode(xml, networks[i])) == NULL) goto error; } - if (!(net = virNetworkAssignDef(conn, &privconn->networks, + if (!(net = virNetworkAssignDef(&privconn->networks, def))) { virNetworkDefFree(def); goto error; @@ -2881,10 +2881,10 @@ static virNetworkPtr testNetworkCreate(virConnectPtr conn, const char *xml) { virNetworkPtr ret = NULL; testDriverLock(privconn); - if ((def = virNetworkDefParseString(conn, xml)) == NULL) + if ((def = virNetworkDefParseString(xml)) == NULL) goto cleanup; - if ((net = virNetworkAssignDef(conn, &privconn->networks, def)) == NULL) + if ((net = virNetworkAssignDef(&privconn->networks, def)) == NULL) goto cleanup; def = NULL; net->active = 1; @@ -2906,10 +2906,10 @@ static virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) { virNetworkPtr ret = NULL; testDriverLock(privconn); - if ((def = virNetworkDefParseString(conn, xml)) == NULL) + if ((def = virNetworkDefParseString(xml)) == NULL) goto cleanup; - if ((net = virNetworkAssignDef(conn, &privconn->networks, def)) == NULL) + if ((net = virNetworkAssignDef(&privconn->networks, def)) == NULL) goto cleanup; def = NULL; net->persistent = 1; @@ -3030,7 +3030,7 @@ static char *testNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSE goto cleanup; } - ret = virNetworkDefFormat(network->conn, privnet->def); + ret = virNetworkDefFormat(privnet->def); cleanup: if (privnet) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index c175e0d..06f6802 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5722,7 +5722,7 @@ static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char * char *networkInterfaceNameUtf8 = NULL; IHostNetworkInterface *networkInterface = NULL; - virNetworkDefPtr def = virNetworkDefParseString(conn, xml); + virNetworkDefPtr def = virNetworkDefParseString(xml); if ( (!def) || (def->forwardType != VIR_NETWORK_FORWARD_NONE)) @@ -6180,7 +6180,7 @@ static char *vboxNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSE VBOX_UTF16_FREE(networkInterfaceNameUtf16); VBOX_RELEASE(host); - ret = virNetworkDefFormat(network->conn, def); + ret = virNetworkDefFormat(def); cleanup: VIR_FREE(networkNameUtf8); diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 957e64b..7805548 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -33,10 +33,10 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) goto fail; - if (!(dev = virNetworkDefParseString(NULL, inXmlData))) + if (!(dev = virNetworkDefParseString(inXmlData))) goto fail; - if (!(actual = virNetworkDefFormat(NULL, dev))) + if (!(actual = virNetworkDefFormat(dev))) goto fail; if (STRNEQ(outXmlData, actual)) { -- 1.6.6

On Wed, Feb 10, 2010 at 01:36:20PM +0000, Daniel P. Berrange wrote:
The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in network_conf.{h,c} and update all callers to match --- src/conf/network_conf.c | 162 ++++++++++++++++++------------------------- src/conf/network_conf.h | 44 ++++-------- src/network/bridge_driver.c | 128 ++++++++++++++++------------------ src/test/test_driver.c | 20 +++--- src/vbox/vbox_tmpl.c | 4 +- tests/networkxml2xmltest.c | 4 +- 6 files changed, 157 insertions(+), 205 deletions(-)
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in node_device_conf.{h,c} and update all callers to match --- src/conf/node_device_conf.c | 208 +++++++++++++++------------------- src/conf/node_device_conf.h | 27 ++--- src/node_device/node_device_driver.c | 57 ++++----- src/node_device/node_device_hal.c | 3 +- src/node_device/node_device_udev.c | 4 +- src/qemu/qemu_driver.c | 2 +- src/test/test_driver.c | 44 ++++---- src/xen/xen_driver.c | 2 +- tests/nodedevxml2xmltest.c | 4 +- 9 files changed, 155 insertions(+), 196 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index d04505a..4b65953 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -60,8 +60,7 @@ VIR_ENUM_IMPL(virNodeDevHBACap, VIR_NODE_DEV_CAP_HBA_LAST, static int -virNodeDevCapsDefParseString(virConnectPtr conn, - const char *xpath, +virNodeDevCapsDefParseString(const char *xpath, xmlXPathContextPtr ctxt, char **string, virNodeDeviceDefPtr def, @@ -71,7 +70,7 @@ virNodeDevCapsDefParseString(virConnectPtr conn, s = virXPathString(xpath, ctxt); if (s == NULL) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, missing_error_fmt, def->name); return -1; @@ -174,8 +173,7 @@ void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) devs->count = 0; } -virNodeDeviceObjPtr virNodeDeviceAssignDef(virConnectPtr conn, - virNodeDeviceObjListPtr devs, +virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, const virNodeDeviceDefPtr def) { virNodeDeviceObjPtr device; @@ -192,7 +190,7 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virConnectPtr conn, } if (virMutexInit(&device->lock) < 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); VIR_FREE(device); return NULL; @@ -241,8 +239,7 @@ void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, } } -char *virNodeDeviceDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, - const virNodeDeviceDefPtr def) +char *virNodeDeviceDefFormat(const virNodeDeviceDefPtr def) { virBuffer buf = VIR_BUFFER_INITIALIZER; virNodeDevCapsDefPtr caps; @@ -500,8 +497,7 @@ char *virNodeDeviceDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, } static int -virNodeDevCapsDefParseULong(virConnectPtr conn, - const char *xpath, +virNodeDevCapsDefParseULong(const char *xpath, xmlXPathContextPtr ctxt, unsigned *value, virNodeDeviceDefPtr def, @@ -513,7 +509,7 @@ virNodeDevCapsDefParseULong(virConnectPtr conn, ret = virXPathULong(xpath, ctxt, &val); if (ret < 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, ret == -1 ? missing_error_fmt : invalid_error_fmt, def->name); return -1; @@ -524,8 +520,7 @@ virNodeDevCapsDefParseULong(virConnectPtr conn, } static int -virNodeDevCapsDefParseULongLong(virConnectPtr conn, - const char *xpath, +virNodeDevCapsDefParseULongLong(const char *xpath, xmlXPathContextPtr ctxt, unsigned long long *value, virNodeDeviceDefPtr def, @@ -537,7 +532,7 @@ virNodeDevCapsDefParseULongLong(virConnectPtr conn, ret = virXPathULongLong(xpath, ctxt, &val); if (ret < 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, ret == -1 ? missing_error_fmt : invalid_error_fmt, def->name); return -1; @@ -548,8 +543,7 @@ virNodeDevCapsDefParseULongLong(virConnectPtr conn, } static int -virNodeDevCapStorageParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, union _virNodeDevCapData *data) @@ -563,7 +557,7 @@ virNodeDevCapStorageParseXML(virConnectPtr conn, data->storage.block = virXPathString("string(./block[1])", ctxt); if (!data->storage.block) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("no block device path supplied for '%s'"), def->name); goto out; @@ -576,7 +570,7 @@ virNodeDevCapStorageParseXML(virConnectPtr conn, data->storage.serial = virXPathString("string(./serial[1])", ctxt); if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("error parsing storage capabilities for '%s'"), def->name); goto out; @@ -586,7 +580,7 @@ virNodeDevCapStorageParseXML(virConnectPtr conn, char *type = virXMLPropString(nodes[i], "type"); if (!type) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("missing storage capability type for '%s'"), def->name); goto out; @@ -608,7 +602,7 @@ virNodeDevCapStorageParseXML(virConnectPtr conn, data->storage.media_label = virXPathString("string(./media_label[1])", ctxt); val = 0; - if (virNodeDevCapsDefParseULongLong(conn, "number(./media_size[1])", ctxt, &val, def, + if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def, _("no removable media size supplied for '%s'"), _("invalid removable media size supplied for '%s'")) < 0) { ctxt->node = orignode2; @@ -619,7 +613,7 @@ virNodeDevCapStorageParseXML(virConnectPtr conn, ctxt->node = orignode2; } else { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage capability type '%s' for '%s'"), type, def->name); VIR_FREE(type); @@ -631,7 +625,7 @@ virNodeDevCapStorageParseXML(virConnectPtr conn, if (!(data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) { val = 0; - if (virNodeDevCapsDefParseULongLong(conn, "number(./size[1])", ctxt, &val, def, + if (virNodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def, _("no size supplied for '%s'"), _("invalid size supplied for '%s'")) < 0) goto out; @@ -646,8 +640,7 @@ out: } static int -virNodeDevCapScsiParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapScsiParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, union _virNodeDevCapData *data) @@ -658,25 +651,25 @@ virNodeDevCapScsiParseXML(virConnectPtr conn, orignode = ctxt->node; ctxt->node = node; - if (virNodeDevCapsDefParseULong(conn, "number(./host[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, &data->scsi.host, def, _("no SCSI host ID supplied for '%s'"), _("invalid SCSI host ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./bus[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, &data->scsi.bus, def, _("no SCSI bus ID supplied for '%s'"), _("invalid SCSI bus ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./target[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./target[1])", ctxt, &data->scsi.target, def, _("no SCSI target ID supplied for '%s'"), _("invalid SCSI target ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./lun[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./lun[1])", ctxt, &data->scsi.lun, def, _("no SCSI LUN ID supplied for '%s'"), _("invalid SCSI LUN ID supplied for '%s'")) < 0) @@ -692,8 +685,7 @@ out: static int -virNodeDevCapScsiTargetParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapScsiTargetParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, union _virNodeDevCapData *data) @@ -706,7 +698,7 @@ virNodeDevCapScsiTargetParseXML(virConnectPtr conn, data->scsi_target.name = virXPathString("string(./name[1])", ctxt); if (!data->scsi_target.name) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("no target name supplied for '%s'"), def->name); goto out; @@ -721,8 +713,7 @@ out: static int -virNodeDevCapScsiHostParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapScsiHostParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, union _virNodeDevCapData *data, @@ -736,7 +727,7 @@ virNodeDevCapScsiHostParseXML(virConnectPtr conn, ctxt->node = node; if (create == EXISTING_DEVICE && - virNodeDevCapsDefParseULong(conn, "number(./host[1])", ctxt, + virNodeDevCapsDefParseULong("number(./host[1])", ctxt, &data->scsi_host.host, def, _("no SCSI host ID supplied for '%s'"), _("invalid SCSI host ID supplied for '%s'")) < 0) { @@ -744,7 +735,7 @@ virNodeDevCapScsiHostParseXML(virConnectPtr conn, } if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("error parsing SCSI host capabilities for '%s'"), def->name); goto out; @@ -754,7 +745,7 @@ virNodeDevCapScsiHostParseXML(virConnectPtr conn, type = virXMLPropString(nodes[i], "type"); if (!type) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("missing SCSI host capability type for '%s'"), def->name); goto out; @@ -773,7 +764,7 @@ virNodeDevCapScsiHostParseXML(virConnectPtr conn, orignode2 = ctxt->node; ctxt->node = nodes[i]; - if (virNodeDevCapsDefParseString(conn, "string(./wwnn[1])", + if (virNodeDevCapsDefParseString("string(./wwnn[1])", ctxt, &data->scsi_host.wwnn, def, @@ -781,7 +772,7 @@ virNodeDevCapScsiHostParseXML(virConnectPtr conn, goto out; } - if (virNodeDevCapsDefParseString(conn, "string(./wwpn[1])", + if (virNodeDevCapsDefParseString("string(./wwpn[1])", ctxt, &data->scsi_host.wwpn, def, @@ -792,7 +783,7 @@ virNodeDevCapScsiHostParseXML(virConnectPtr conn, ctxt->node = orignode2; } else { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("unknown SCSI host capability type '%s' for '%s'"), type, def->name); goto out; @@ -811,8 +802,7 @@ out: static int -virNodeDevCapNetParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, union _virNodeDevCapData *data) @@ -826,7 +816,7 @@ virNodeDevCapNetParseXML(virConnectPtr conn, data->net.ifname = virXPathString("string(./interface[1])", ctxt); if (!data->net.ifname) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("no network interface supplied for '%s'"), def->name); goto out; @@ -841,7 +831,7 @@ virNodeDevCapNetParseXML(virConnectPtr conn, int val = virNodeDevNetCapTypeFromString(tmp); VIR_FREE(tmp); if (val < 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("invalid network type supplied for '%s'"), def->name); goto out; @@ -856,8 +846,7 @@ out: } static int -virNodeDevCapUsbInterfaceParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapUsbInterfaceParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, union _virNodeDevCapData *data) @@ -868,25 +857,25 @@ virNodeDevCapUsbInterfaceParseXML(virConnectPtr conn, orignode = ctxt->node; ctxt->node = node; - if (virNodeDevCapsDefParseULong(conn, "number(./number[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt, &data->usb_if.number, def, _("no USB interface number supplied for '%s'"), _("invalid USB interface number supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./class[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./class[1])", ctxt, &data->usb_if._class, def, _("no USB interface class supplied for '%s'"), _("invalid USB interface class supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./subclass[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./subclass[1])", ctxt, &data->usb_if.subclass, def, _("no USB interface subclass supplied for '%s'"), _("invalid USB interface subclass supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./protocol[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./protocol[1])", ctxt, &data->usb_if.protocol, def, _("no USB interface protocol supplied for '%s'"), _("invalid USB interface protocol supplied for '%s'")) < 0) @@ -901,8 +890,7 @@ out: } static int -virNodeDevCapsDefParseHexId(virConnectPtr conn, - const char *xpath, +virNodeDevCapsDefParseHexId(const char *xpath, xmlXPathContextPtr ctxt, unsigned *value, virNodeDeviceDefPtr def, @@ -914,7 +902,7 @@ virNodeDevCapsDefParseHexId(virConnectPtr conn, ret = virXPathULongHex(xpath, ctxt, &val); if (ret < 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, ret == -1 ? missing_error_fmt : invalid_error_fmt, def->name); return -1; @@ -925,8 +913,7 @@ virNodeDevCapsDefParseHexId(virConnectPtr conn, } static int -virNodeDevCapUsbDevParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapUsbDevParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, union _virNodeDevCapData *data) @@ -937,25 +924,25 @@ virNodeDevCapUsbDevParseXML(virConnectPtr conn, orignode = ctxt->node; ctxt->node = node; - if (virNodeDevCapsDefParseULong(conn, "number(./bus[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, &data->usb_dev.bus, def, _("no USB bus number supplied for '%s'"), _("invalid USB bus number supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./device[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./device[1])", ctxt, &data->usb_dev.device, def, _("no USB device number supplied for '%s'"), _("invalid USB device number supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseHexId(conn, "string(./vendor[1]/@id)", ctxt, + if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, &data->usb_dev.vendor, def, _("no USB vendor ID supplied for '%s'"), _("invalid USB vendor ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseHexId(conn, "string(./product[1]/@id)", ctxt, + if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, &data->usb_dev.product, def, _("no USB product ID supplied for '%s'"), _("invalid USB product ID supplied for '%s'")) < 0) @@ -971,8 +958,7 @@ out: } static int -virNodeDevCapPciDevParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapPciDevParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, union _virNodeDevCapData *data) @@ -983,37 +969,37 @@ virNodeDevCapPciDevParseXML(virConnectPtr conn, orignode = ctxt->node; ctxt->node = node; - if (virNodeDevCapsDefParseULong(conn, "number(./domain[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./domain[1])", ctxt, &data->pci_dev.domain, def, _("no PCI domain ID supplied for '%s'"), _("invalid PCI domain ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./bus[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, &data->pci_dev.bus, def, _("no PCI bus ID supplied for '%s'"), _("invalid PCI bus ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./slot[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./slot[1])", ctxt, &data->pci_dev.slot, def, _("no PCI slot ID supplied for '%s'"), _("invalid PCI slot ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong(conn, "number(./function[1])", ctxt, + if (virNodeDevCapsDefParseULong("number(./function[1])", ctxt, &data->pci_dev.function, def, _("no PCI function ID supplied for '%s'"), _("invalid PCI function ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseHexId(conn, "string(./vendor[1]/@id)", ctxt, + if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, &data->pci_dev.vendor, def, _("no PCI vendor ID supplied for '%s'"), _("invalid PCI vendor ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseHexId(conn, "string(./product[1]/@id)", ctxt, + if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, &data->pci_dev.product, def, _("no PCI product ID supplied for '%s'"), _("invalid PCI product ID supplied for '%s'")) < 0) @@ -1029,8 +1015,7 @@ out: } static int -virNodeDevCapSystemParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, union _virNodeDevCapData *data) @@ -1050,13 +1035,13 @@ virNodeDevCapSystemParseXML(virConnectPtr conn, tmp = virXPathString("string(./hardware/uuid[1])", ctxt); if (!tmp) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("no system UUID supplied for '%s'"), def->name); goto out; } if (virUUIDParse(tmp, data->system.hardware.uuid) < 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("malformed uuid element for '%s'"), def->name); VIR_FREE(tmp); goto out; @@ -1074,8 +1059,7 @@ out: } static virNodeDevCapsDefPtr -virNodeDevCapsDefParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, int create) @@ -1091,13 +1075,13 @@ virNodeDevCapsDefParseXML(virConnectPtr conn, tmp = virXMLPropString(node, "type"); if (!tmp) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing capability type")); goto error; } if ((val = virNodeDevCapTypeFromString(tmp)) < 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("unknown capability type '%s'"), tmp); VIR_FREE(tmp); goto error; @@ -1107,34 +1091,34 @@ virNodeDevCapsDefParseXML(virConnectPtr conn, switch (caps->type) { case VIR_NODE_DEV_CAP_SYSTEM: - ret = virNodeDevCapSystemParseXML(conn, ctxt, def, node, &caps->data); + ret = virNodeDevCapSystemParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_PCI_DEV: - ret = virNodeDevCapPciDevParseXML(conn, ctxt, def, node, &caps->data); + ret = virNodeDevCapPciDevParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_USB_DEV: - ret = virNodeDevCapUsbDevParseXML(conn, ctxt, def, node, &caps->data); + ret = virNodeDevCapUsbDevParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_USB_INTERFACE: - ret = virNodeDevCapUsbInterfaceParseXML(conn, ctxt, def, node, &caps->data); + ret = virNodeDevCapUsbInterfaceParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_NET: - ret = virNodeDevCapNetParseXML(conn, ctxt, def, node, &caps->data); + ret = virNodeDevCapNetParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_SCSI_HOST: - ret = virNodeDevCapScsiHostParseXML(conn, ctxt, def, node, &caps->data, create); + ret = virNodeDevCapScsiHostParseXML(ctxt, def, node, &caps->data, create); break; case VIR_NODE_DEV_CAP_SCSI_TARGET: - ret = virNodeDevCapScsiTargetParseXML(conn, ctxt, def, node, &caps->data); + ret = virNodeDevCapScsiTargetParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_SCSI: - ret = virNodeDevCapScsiParseXML(conn, ctxt, def, node, &caps->data); + ret = virNodeDevCapScsiParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_STORAGE: - ret = virNodeDevCapStorageParseXML(conn, ctxt, def, node, &caps->data); + ret = virNodeDevCapStorageParseXML(ctxt, def, node, &caps->data); break; default: - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("unknown capability type '%d' for '%s'"), caps->type, def->name); ret = -1; @@ -1151,7 +1135,7 @@ error: } static virNodeDeviceDefPtr -virNodeDeviceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt, int create) +virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, int create) { virNodeDeviceDefPtr def; virNodeDevCapsDefPtr *next_cap; @@ -1168,7 +1152,7 @@ virNodeDeviceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt, int create def->name = virXPathString("string(./name[1])", ctxt); if (!def->name) { - virNodeDeviceReportError(conn, VIR_ERR_NO_NAME, NULL); + virNodeDeviceReportError(VIR_ERR_NO_NAME, NULL); goto error; } } else { @@ -1186,7 +1170,7 @@ virNodeDeviceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt, int create /* Parse device capabilities */ nodes = NULL; if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) <= 0) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("no device capabilities for '%s'"), def->name); goto error; @@ -1194,7 +1178,7 @@ virNodeDeviceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt, int create next_cap = &def->caps; for (i = 0 ; i < n ; i++) { - *next_cap = virNodeDevCapsDefParseXML(conn, ctxt, def, nodes[i], create); + *next_cap = virNodeDevCapsDefParseXML(ctxt, def, nodes[i], create); if (!*next_cap) { VIR_FREE(nodes); goto error; @@ -1212,8 +1196,7 @@ virNodeDeviceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt, int create } virNodeDeviceDefPtr -virNodeDeviceDefParseNode(virConnectPtr conn, - xmlDocPtr xml, +virNodeDeviceDefParseNode(xmlDocPtr xml, xmlNodePtr root, int create) { @@ -1221,7 +1204,7 @@ virNodeDeviceDefParseNode(virConnectPtr conn, virNodeDeviceDefPtr def = NULL; if (!xmlStrEqual(root->name, BAD_CAST "device")) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("incorrect root element")); return NULL; } @@ -1233,7 +1216,7 @@ virNodeDeviceDefParseNode(virConnectPtr conn, } ctxt->node = root; - def = virNodeDeviceDefParseXML(conn, ctxt, create); + def = virNodeDeviceDefParseXML(ctxt, create); cleanup: xmlXPathFreeContext(ctxt); @@ -1247,12 +1230,10 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; if (ctxt) { - virConnectPtr conn = ctxt->_private; - if (virGetLastError() == NULL && ctxt->lastError.level == XML_ERR_FATAL && ctxt->lastError.message != NULL) { - virNodeDeviceReportError(conn, VIR_ERR_XML_DETAIL, + virNodeDeviceReportError(VIR_ERR_XML_DETAIL, _("at line %d: %s"), ctxt->lastError.line, ctxt->lastError.message); @@ -1263,8 +1244,7 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) static virNodeDeviceDefPtr -virNodeDeviceDefParse(virConnectPtr conn, - const char *str, +virNodeDeviceDefParse(const char *str, const char *filename, int create) { @@ -1278,9 +1258,7 @@ virNodeDeviceDefParse(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn; - if (conn) virResetError (&conn->err); if (filename) { xml = xmlCtxtReadFile (pctxt, filename, NULL, XML_PARSE_NOENT | XML_PARSE_NONET | @@ -1293,19 +1271,19 @@ virNodeDeviceDefParse(virConnectPtr conn, } if (!xml) { - if (conn && conn->err.code == VIR_ERR_NONE) - virNodeDeviceReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("failed to parse xml document")); + if (virGetLastError() == NULL) + virNodeDeviceReportError(VIR_ERR_XML_ERROR, + "%s", _("failed to parse xml document")); goto cleanup; } if ((root = xmlDocGetRootElement(xml)) == NULL) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing root element")); goto cleanup; } - def = virNodeDeviceDefParseNode(conn, xml, root, create); + def = virNodeDeviceDefParseNode(xml, root, create); cleanup: xmlFreeParserCtxt(pctxt); @@ -1314,27 +1292,24 @@ cleanup: } virNodeDeviceDefPtr -virNodeDeviceDefParseString(virConnectPtr conn, - const char *str, +virNodeDeviceDefParseString(const char *str, int create) { - return virNodeDeviceDefParse(conn, str, NULL, create); + return virNodeDeviceDefParse(str, NULL, create); } virNodeDeviceDefPtr -virNodeDeviceDefParseFile(virConnectPtr conn, - const char *filename, +virNodeDeviceDefParseFile(const char *filename, int create) { - return virNodeDeviceDefParse(conn, NULL, filename, create); + return virNodeDeviceDefParse(NULL, filename, create); } /* * Return fc_host dev's WWNN and WWPN */ int -virNodeDeviceGetWWNs(virConnectPtr conn, - virNodeDeviceDefPtr def, +virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, char **wwnn, char **wwpn) { @@ -1354,7 +1329,7 @@ virNodeDeviceGetWWNs(virConnectPtr conn, } if (cap == NULL) { - virNodeDeviceReportError(conn, VIR_ERR_NO_SUPPORT, + virNodeDeviceReportError(VIR_ERR_NO_SUPPORT, "%s", _("Device is not a fibre channel HBA")); ret = -1; } else if (*wwnn == NULL || *wwpn == NULL) { @@ -1372,8 +1347,7 @@ virNodeDeviceGetWWNs(virConnectPtr conn, * Return the NPIV dev's parent device name */ int -virNodeDeviceGetParentHost(virConnectPtr conn, - const virNodeDeviceObjListPtr devs, +virNodeDeviceGetParentHost(const virNodeDeviceObjListPtr devs, const char *dev_name, const char *parent_name, int *parent_host) @@ -1384,7 +1358,7 @@ virNodeDeviceGetParentHost(virConnectPtr conn, parent = virNodeDeviceFindByName(devs, parent_name); if (parent == NULL) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent HBA for '%s'"), dev_name); ret = -1; @@ -1404,7 +1378,7 @@ virNodeDeviceGetParentHost(virConnectPtr conn, } if (cap == NULL) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("Parent HBA %s is not capable " "of vport operations"), parent->def->name); diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 318fa3e..3a5432c 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -217,9 +217,9 @@ struct _virDeviceMonitorState { void *privateData; /* driver-specific private data */ }; -#define virNodeDeviceReportError(conn, code, fmt...) \ - virReportErrorHelper(conn, VIR_FROM_NODEDEV, code, __FILE__, \ - __FUNCTION__, __LINE__, fmt) +#define virNodeDeviceReportError(code, fmt...) \ + virReportErrorHelper(NULL, VIR_FROM_NODEDEV, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) int virNodeDeviceHasCap(const virNodeDeviceObjPtr dev, const char *cap); @@ -229,34 +229,27 @@ virNodeDeviceObjPtr virNodeDeviceFindBySysfsPath(const virNodeDeviceObjListPtr devs, const char *sysfs_path); -virNodeDeviceObjPtr virNodeDeviceAssignDef(virConnectPtr conn, - virNodeDeviceObjListPtr devs, +virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, const virNodeDeviceDefPtr def); void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, const virNodeDeviceObjPtr dev); -char *virNodeDeviceDefFormat(virConnectPtr conn, - const virNodeDeviceDefPtr def); +char *virNodeDeviceDefFormat(const virNodeDeviceDefPtr def); -virNodeDeviceDefPtr virNodeDeviceDefParseString(virConnectPtr conn, - const char *str, +virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str, int create); -virNodeDeviceDefPtr virNodeDeviceDefParseFile(virConnectPtr conn, - const char *filename, +virNodeDeviceDefPtr virNodeDeviceDefParseFile(const char *filename, int create); -virNodeDeviceDefPtr virNodeDeviceDefParseNode(virConnectPtr conn, - xmlDocPtr xml, +virNodeDeviceDefPtr virNodeDeviceDefParseNode(xmlDocPtr xml, xmlNodePtr root, int create); -int virNodeDeviceGetWWNs(virConnectPtr conn, - virNodeDeviceDefPtr def, +int virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, char **wwnn, char **wwpn); -int virNodeDeviceGetParentHost(virConnectPtr conn, - const virNodeDeviceObjListPtr devs, +int virNodeDeviceGetParentHost(const virNodeDeviceObjListPtr devs, const char *dev_name, const char *parent_name, int *parent_host); diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index ad5503b..b9f6d17 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -203,7 +203,7 @@ static virNodeDevicePtr nodeDeviceLookupByName(virConnectPtr conn, nodeDeviceUnlock(driver); if (!obj) { - virNodeDeviceReportError(conn, VIR_ERR_NO_NODE_DEVICE, NULL); + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, NULL); goto cleanup; } @@ -274,8 +274,8 @@ static char *nodeDeviceDumpXML(virNodeDevicePtr dev, nodeDeviceUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, + _("no node device with matching name '%s'"), dev->name); goto cleanup; } @@ -283,7 +283,7 @@ static char *nodeDeviceDumpXML(virNodeDevicePtr dev, update_driver_name(obj); update_caps(obj); - ret = virNodeDeviceDefFormat(dev->conn, obj->def); + ret = virNodeDeviceDefFormat(obj->def); cleanup: if (obj) @@ -303,8 +303,8 @@ static char *nodeDeviceGetParent(virNodeDevicePtr dev) nodeDeviceUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, + _("no node device with matching name '%s'"), dev->name); goto cleanup; } @@ -314,7 +314,7 @@ static char *nodeDeviceGetParent(virNodeDevicePtr dev) if (!ret) virReportOOMError(); } else { - virNodeDeviceReportError(dev->conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no parent for this device")); } @@ -338,8 +338,8 @@ static int nodeDeviceNumOfCaps(virNodeDevicePtr dev) nodeDeviceUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, + _("no node device with matching name '%s'"), dev->name); goto cleanup; } @@ -369,8 +369,8 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) nodeDeviceUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, + _("no node device with matching name '%s'"), dev->name); goto cleanup; } @@ -397,8 +397,7 @@ cleanup: static int -nodeDeviceVportCreateDelete(virConnectPtr conn, - const int parent_host, +nodeDeviceVportCreateDelete(const int parent_host, const char *wwpn, const char *wwnn, int operation) @@ -415,7 +414,7 @@ nodeDeviceVportCreateDelete(virConnectPtr conn, operation_file = LINUX_SYSFS_VPORT_DELETE_POSTFIX; break; default: - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid vport operation (%d)"), operation); retval = -1; goto cleanup; @@ -462,13 +461,13 @@ cleanup: static int -get_time(virConnectPtr conn, time_t *t) +get_time(time_t *t) { int ret = 0; *t = time(NULL); if (*t == (time_t)-1) { - virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not get current time")); *t = 0; @@ -506,7 +505,7 @@ find_new_device(virConnectPtr conn, const char *wwnn, const char *wwpn) * doesn't become invalid. */ nodeDeviceUnlock(driver); - get_time(conn, &start); + get_time(&start); while ((now - start) < LINUX_NEW_DEVICE_WAIT_TIME) { @@ -519,7 +518,7 @@ find_new_device(virConnectPtr conn, const char *wwnn, const char *wwpn) } sleep(5); - if (get_time(conn, &now) == -1) { + if (get_time(&now) == -1) { break; } } @@ -542,25 +541,23 @@ nodeDeviceCreateXML(virConnectPtr conn, nodeDeviceLock(driver); - def = virNodeDeviceDefParseString(conn, xmlDesc, CREATE_DEVICE); + def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE); if (def == NULL) { goto cleanup; } - if (virNodeDeviceGetWWNs(conn, def, &wwnn, &wwpn) == -1) { + if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) { goto cleanup; } - if (virNodeDeviceGetParentHost(conn, - &driver->devs, + if (virNodeDeviceGetParentHost(&driver->devs, def->name, def->parent, &parent_host) == -1) { goto cleanup; } - if (nodeDeviceVportCreateDelete(conn, - parent_host, + if (nodeDeviceVportCreateDelete(parent_host, wwpn, wwnn, VPORT_CREATE) == -1) { @@ -572,7 +569,7 @@ nodeDeviceCreateXML(virConnectPtr conn, * we're returning what we get... */ if (dev == NULL) { - virNodeDeviceReportError(conn, VIR_ERR_NO_NODE_DEVICE, NULL); + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, NULL); } cleanup: @@ -598,11 +595,11 @@ nodeDeviceDestroy(virNodeDevicePtr dev) nodeDeviceUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, NULL); + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, NULL); goto out; } - if (virNodeDeviceGetWWNs(dev->conn, obj->def, &wwnn, &wwpn) == -1) { + if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1) { goto out; } @@ -620,16 +617,14 @@ nodeDeviceDestroy(virNodeDevicePtr dev) goto out; } - if (virNodeDeviceGetParentHost(dev->conn, - &driver->devs, + if (virNodeDeviceGetParentHost(&driver->devs, dev->name, parent_name, &parent_host) == -1) { goto out; } - if (nodeDeviceVportCreateDelete(dev->conn, - parent_host, + if (nodeDeviceVportCreateDelete(parent_host, wwpn, wwnn, VPORT_DELETE) == -1) { diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index 02fcbf6..6cc2864 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -465,8 +465,7 @@ static void dev_create(const char *udi) /* Some devices don't have a path in sysfs, so ignore failure */ get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath); - dev = virNodeDeviceAssignDef(NULL, - &driverState->devs, + dev = virNodeDeviceAssignDef(&driverState->devs, def); if (!dev) { diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 76f83bf..68509f4 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1292,7 +1292,7 @@ static int udevAddOneDevice(struct udev_device *device) } nodeDeviceLock(driverState); - dev = virNodeDeviceAssignDef(NULL, &driverState->devs, def); + dev = virNodeDeviceAssignDef(&driverState->devs, def); nodeDeviceUnlock(driverState); if (dev == NULL) { @@ -1534,7 +1534,7 @@ static int udevSetupSystemDev(void) udev_device_unref(device); - dev = virNodeDeviceAssignDef(NULL, &driverState->devs, def); + dev = virNodeDeviceAssignDef(&driverState->devs, def); if (dev == NULL) { VIR_ERROR("Failed to create device for '%s'", def->name); virNodeDeviceDefFree(def); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4cc66be..1b3b271 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8377,7 +8377,7 @@ qemudNodeDeviceGetPciInfo (virNodeDevicePtr dev, if (!xml) goto out; - def = virNodeDeviceDefParseString(dev->conn, xml, EXISTING_DEVICE); + def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE); if (!def) goto out; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2f3ef16..5cecb93 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -594,9 +594,9 @@ static int testOpenDefault(virConnectPtr conn) { virStoragePoolObjUnlock(poolobj); /* Init default node device */ - if (!(nodedef = virNodeDeviceDefParseString(conn, defaultNodeXML, 0))) + if (!(nodedef = virNodeDeviceDefParseString(defaultNodeXML, 0))) goto error; - if (!(nodeobj = virNodeDeviceAssignDef(conn, &privconn->devs, + if (!(nodeobj = virNodeDeviceAssignDef(&privconn->devs, nodedef))) { virNodeDeviceDefFree(nodedef); goto error; @@ -1061,15 +1061,15 @@ static int testOpenFromFile(virConnectPtr conn, goto error; } - def = virNodeDeviceDefParseFile(conn, absFile, 0); + def = virNodeDeviceDefParseFile(absFile, 0); VIR_FREE(absFile); if (!def) goto error; } else { - if ((def = virNodeDeviceDefParseNode(conn, xml, devs[i], 0)) == NULL) + if ((def = virNodeDeviceDefParseNode(xml, devs[i], 0)) == NULL) goto error; } - if (!(dev = virNodeDeviceAssignDef(conn, &privconn->devs, def))) { + if (!(dev = virNodeDeviceAssignDef(&privconn->devs, def))) { virNodeDeviceDefFree(def); goto error; } @@ -4778,7 +4778,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name) testDriverUnlock(driver); if (!obj) { - virNodeDeviceReportError(conn, VIR_ERR_NO_NODE_DEVICE, NULL); + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, NULL); goto cleanup; } @@ -4803,13 +4803,13 @@ testNodeDeviceDumpXML(virNodeDevicePtr dev, testDriverUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, + _("no node device with matching name '%s'"), dev->name); goto cleanup; } - ret = virNodeDeviceDefFormat(dev->conn, obj->def); + ret = virNodeDeviceDefFormat(obj->def); cleanup: if (obj) @@ -4829,7 +4829,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) testDriverUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; @@ -4840,7 +4840,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) if (!ret) virReportOOMError(); } else { - virNodeDeviceReportError(dev->conn, VIR_ERR_INTERNAL_ERROR, + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no parent for this device")); } @@ -4865,8 +4865,8 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) testDriverUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, - _("no node device with matching name '%s'"), + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, + _("no node device with matching name '%s'"), dev->name); goto cleanup; } @@ -4896,7 +4896,7 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) testDriverUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; @@ -4935,18 +4935,17 @@ testNodeDeviceCreateXML(virConnectPtr conn, testDriverLock(driver); - def = virNodeDeviceDefParseString(conn, xmlDesc, CREATE_DEVICE); + def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE); if (def == NULL) { goto cleanup; } /* We run these next two simply for validation */ - if (virNodeDeviceGetWWNs(conn, def, &wwnn, &wwpn) == -1) { + if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) { goto cleanup; } - if (virNodeDeviceGetParentHost(conn, - &driver->devs, + if (virNodeDeviceGetParentHost(&driver->devs, def->name, def->parent, &parent_host) == -1) { @@ -4973,7 +4972,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, } - if (!(obj = virNodeDeviceAssignDef(conn, &driver->devs, def))) { + if (!(obj = virNodeDeviceAssignDef(&driver->devs, def))) { goto cleanup; } virNodeDeviceObjUnlock(obj); @@ -5003,11 +5002,11 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) testDriverUnlock(driver); if (!obj) { - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, NULL); + virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, NULL); goto out; } - if (virNodeDeviceGetWWNs(dev->conn, obj->def, &wwnn, &wwpn) == -1) { + if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1) { goto out; } @@ -5024,8 +5023,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjUnlock(obj); /* We do this just for basic validation */ - if (virNodeDeviceGetParentHost(dev->conn, - &driver->devs, + if (virNodeDeviceGetParentHost(&driver->devs, dev->name, parent_name, &parent_host) == -1) { diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 6f21c6a..d5a0d00 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1722,7 +1722,7 @@ xenUnifiedNodeDeviceGetPciInfo (virNodeDevicePtr dev, if (!xml) goto out; - def = virNodeDeviceDefParseString(dev->conn, xml, EXISTING_DEVICE); + def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE); if (!def) goto out; diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index bf8be7e..2bc6743 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -29,10 +29,10 @@ static int testCompareXMLToXMLFiles(const char *xml) { if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) goto fail; - if (!(dev = virNodeDeviceDefParseString(NULL, xmlData, EXISTING_DEVICE))) + if (!(dev = virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE))) goto fail; - if (!(actual = virNodeDeviceDefFormat(NULL, dev))) + if (!(actual = virNodeDeviceDefFormat(dev))) goto fail; if (STRNEQ(xmlData, actual)) { -- 1.6.6

On Wed, Feb 10, 2010 at 01:36:21PM +0000, Daniel P. Berrange wrote:
The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in node_device_conf.{h,c} and update all callers to match --- src/conf/node_device_conf.c | 208 +++++++++++++++------------------- src/conf/node_device_conf.h | 27 ++--- src/node_device/node_device_driver.c | 57 ++++----- src/node_device/node_device_hal.c | 3 +- src/node_device/node_device_udev.c | 4 +- src/qemu/qemu_driver.c | 2 +- src/test/test_driver.c | 44 ++++---- src/xen/xen_driver.c | 2 +- tests/nodedevxml2xmltest.c | 4 +- 9 files changed, 155 insertions(+), 196 deletions(-)
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in storage_conf.{h,c} and storage_encryption_conf.{h,c} and update all callers to match --- src/conf/domain_conf.c | 4 +- src/conf/storage_conf.c | 257 ++++++++++++++------------------- src/conf/storage_conf.h | 51 +++----- src/conf/storage_encryption_conf.c | 45 +++--- src/conf/storage_encryption_conf.h | 7 +- src/storage/storage_backend.c | 77 +++++----- src/storage/storage_backend.h | 18 +-- src/storage/storage_backend_disk.c | 74 +++++------ src/storage/storage_backend_fs.c | 59 ++++---- src/storage/storage_backend_iscsi.c | 109 ++++++-------- src/storage/storage_backend_logical.c | 49 +++---- src/storage/storage_backend_mpath.c | 30 ++--- src/storage/storage_backend_scsi.c | 47 +++---- src/storage/storage_backend_scsi.h | 3 +- src/storage/storage_driver.c | 164 +++++++++++----------- src/test/test_driver.c | 37 +++--- src/vbox/vbox_tmpl.c | 4 +- tests/storagepoolxml2xmltest.c | 4 +- tests/storagevolxml2xmltest.c | 6 +- 19 files changed, 465 insertions(+), 580 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f9d7b13..101be4e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1297,7 +1297,7 @@ virDomainDiskDefParseXML(xmlNodePtr node, devaddr = virXMLPropString(cur, "devaddr"); } else if (encryption == NULL && xmlStrEqual(cur->name, BAD_CAST "encryption")) { - encryption = virStorageEncryptionParseNode(NULL, node->doc, + encryption = virStorageEncryptionParseNode(node->doc, cur); if (encryption == NULL) goto error; @@ -4581,7 +4581,7 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferEscapeString(buf, " <serial>%s</serial>\n", def->serial); if (def->encryption != NULL && - virStorageEncryptionFormat(NULL, buf, def->encryption) < 0) + virStorageEncryptionFormat(buf, def->encryption) < 0) return -1; if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index b80fef0..eb1c9d9 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -46,9 +46,6 @@ #define VIR_FROM_THIS VIR_FROM_STORAGE -#define virStorageError(conn, code, fmt...) \ - virReportErrorHelper(conn, VIR_FROM_STORAGE, code, __FILE__,\ - __FUNCTION__, __LINE__, fmt) VIR_ENUM_IMPL(virStoragePool, VIR_STORAGE_POOL_LAST, @@ -223,7 +220,7 @@ virStoragePoolTypeInfoLookup(int type) { if (poolTypeInfo[i].poolType == type) return &poolTypeInfo[i]; - virStorageReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("missing backend for pool type %d"), type); return NULL; } @@ -366,19 +363,18 @@ virStoragePoolObjRemove(virStoragePoolObjListPtr pools, static int -virStoragePoolDefParseAuthChap(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virStoragePoolDefParseAuthChap(xmlXPathContextPtr ctxt, virStoragePoolAuthChapPtr auth) { auth->login = virXPathString("string(./auth/@login)", ctxt); if (auth->login == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing auth host attribute")); return -1; } auth->passwd = virXPathString("string(./auth/@passwd)", ctxt); if (auth->passwd == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing auth passwd attribute")); return -1; } @@ -387,8 +383,7 @@ virStoragePoolDefParseAuthChap(virConnectPtr conn, } static int -virStoragePoolDefParseSource(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, virStoragePoolSourcePtr source, int pool_type, xmlNodePtr node) { @@ -415,7 +410,7 @@ virStoragePoolDefParseSource(virConnectPtr conn, source->format = options->formatFromString(format); if (source->format < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, _("unknown pool format type %s"), format); VIR_FREE(format); goto cleanup; @@ -438,7 +433,7 @@ virStoragePoolDefParseSource(virConnectPtr conn, xmlChar *path = xmlGetProp(nodeset[i], BAD_CAST "path"); if (path == NULL) { VIR_FREE(nodeset); - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source device path")); goto cleanup; } @@ -457,7 +452,7 @@ virStoragePoolDefParseSource(virConnectPtr conn, if (STREQ(authType, "chap")) { source->authType = VIR_STORAGE_POOL_AUTH_CHAP; } else { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, _("unknown auth type '%s'"), (const char *)authType); goto cleanup; @@ -465,7 +460,7 @@ virStoragePoolDefParseSource(virConnectPtr conn, } if (source->authType == VIR_STORAGE_POOL_AUTH_CHAP) { - if (virStoragePoolDefParseAuthChap(conn, ctxt, &source->auth.chap) < 0) + if (virStoragePoolDefParseAuthChap(ctxt, &source->auth.chap) < 0) goto cleanup; } @@ -479,8 +474,7 @@ cleanup: } virStoragePoolSourcePtr -virStoragePoolDefParseSourceString(virConnectPtr conn, - const char *srcSpec, +virStoragePoolDefParseSourceString(const char *srcSpec, int pool_type) { xmlDocPtr doc = NULL; @@ -493,7 +487,7 @@ virStoragePoolDefParseSourceString(virConnectPtr conn, XML_PARSE_NOERROR | XML_PARSE_NOWARNING); if (doc == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("bad <source> spec")); goto cleanup; } @@ -511,12 +505,12 @@ virStoragePoolDefParseSourceString(virConnectPtr conn, node = virXPathNode("/source", xpath_ctxt); if (!node) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("root element was not source")); goto cleanup; } - if (virStoragePoolDefParseSource(conn, xpath_ctxt, def, pool_type, + if (virStoragePoolDefParseSource(xpath_ctxt, def, pool_type, node) < 0) goto cleanup; @@ -531,8 +525,7 @@ cleanup: return ret; } static int -virStorageDefParsePerms(virConnectPtr conn, - xmlXPathContextPtr ctxt, +virStorageDefParsePerms(xmlXPathContextPtr ctxt, virStoragePermsPtr perms, const char *permxpath, int defaultmode) { @@ -563,7 +556,7 @@ virStorageDefParsePerms(virConnectPtr conn, perms->mode = strtol(mode, &end, 8); if (*end || perms->mode < 0 || perms->mode > 0777) { VIR_FREE(mode); - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("malformed octal mode")); goto error; } @@ -574,7 +567,7 @@ virStorageDefParsePerms(virConnectPtr conn, perms->uid = getuid(); } else { if (virXPathLong("number(./owner)", ctxt, &v) < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("malformed owner element")); goto error; } @@ -585,7 +578,7 @@ virStorageDefParsePerms(virConnectPtr conn, perms->gid = getgid(); } else { if (virXPathLong("number(./group)", ctxt, &v) < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("malformed group element")); goto error; } @@ -602,8 +595,7 @@ error: } static virStoragePoolDefPtr -virStoragePoolDefParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt) { +virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { virStoragePoolOptionsPtr options; virStoragePoolDefPtr ret; xmlNodePtr source_node; @@ -617,7 +609,7 @@ virStoragePoolDefParseXML(virConnectPtr conn, type = virXPathString("string(./@type)", ctxt); if ((ret->type = virStoragePoolTypeFromString((const char *)type)) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage pool type %s"), (const char*)type); goto cleanup; } @@ -631,7 +623,7 @@ virStoragePoolDefParseXML(virConnectPtr conn, source_node = virXPathNode("./source", ctxt); if (source_node) { - if (virStoragePoolDefParseSource(conn, ctxt, &ret->source, ret->type, + if (virStoragePoolDefParseSource(ctxt, &ret->source, ret->type, source_node) < 0) goto cleanup; } @@ -641,7 +633,7 @@ virStoragePoolDefParseXML(virConnectPtr conn, options->flags & VIR_STORAGE_POOL_SOURCE_NAME) ret->name = ret->source.name; if (ret->name == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing pool source name element")); goto cleanup; } @@ -649,13 +641,13 @@ virStoragePoolDefParseXML(virConnectPtr conn, uuid = virXPathString("string(./uuid)", ctxt); if (uuid == NULL) { if (virUUIDGenerate(ret->uuid) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to generate uuid")); goto cleanup; } } else { if (virUUIDParse(uuid, ret->uuid) < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("malformed uuid element")); goto cleanup; } @@ -664,7 +656,7 @@ virStoragePoolDefParseXML(virConnectPtr conn, if (options->flags & VIR_STORAGE_POOL_SOURCE_HOST) { if (!ret->source.host.name) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source host name")); goto cleanup; @@ -673,7 +665,7 @@ virStoragePoolDefParseXML(virConnectPtr conn, if (options->flags & VIR_STORAGE_POOL_SOURCE_DIR) { if (!ret->source.dir) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source path")); goto cleanup; } @@ -691,19 +683,19 @@ virStoragePoolDefParseXML(virConnectPtr conn, if (options->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER) { if (!ret->source.adapter) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool source adapter name")); goto cleanup; } } if ((ret->target.path = virXPathString("string(./target/path)", ctxt)) == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool target path")); goto cleanup; } - if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms, + if (virStorageDefParsePerms(ctxt, &ret->target.perms, "./target/permissions", 0700) < 0) goto cleanup; @@ -723,13 +715,10 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; if (ctxt) { - virConnectPtr conn = ctxt->_private; - - if (conn && - conn->err.code == VIR_ERR_NONE && + if (virGetLastError() == NULL && ctxt->lastError.level == XML_ERR_FATAL && ctxt->lastError.message != NULL) { - virStorageReportError (conn, VIR_ERR_XML_DETAIL, + virStorageReportError (VIR_ERR_XML_DETAIL, _("at line %d: %s"), ctxt->lastError.line, ctxt->lastError.message); @@ -738,15 +727,14 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) } virStoragePoolDefPtr -virStoragePoolDefParseNode(virConnectPtr conn, - xmlDocPtr xml, +virStoragePoolDefParseNode(xmlDocPtr xml, xmlNodePtr root) { xmlXPathContextPtr ctxt = NULL; virStoragePoolDefPtr def = NULL; if (STRNEQ((const char *)root->name, "pool")) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("unknown root element for storage pool")); + virStorageReportError(VIR_ERR_XML_ERROR, + "%s", _("unknown root element for storage pool")); goto cleanup; } @@ -757,15 +745,14 @@ virStoragePoolDefParseNode(virConnectPtr conn, } ctxt->node = root; - def = virStoragePoolDefParseXML(conn, ctxt); + def = virStoragePoolDefParseXML(ctxt); cleanup: xmlXPathFreeContext(ctxt); return def; } static virStoragePoolDefPtr -virStoragePoolDefParse(virConnectPtr conn, - const char *xmlStr, +virStoragePoolDefParse(const char *xmlStr, const char *filename) { virStoragePoolDefPtr ret = NULL; xmlParserCtxtPtr pctxt; @@ -777,9 +764,7 @@ virStoragePoolDefParse(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn; - if (conn) virResetError (&conn->err); if (filename) { xml = xmlCtxtReadFile (pctxt, filename, NULL, XML_PARSE_NOENT | XML_PARSE_NONET | @@ -792,20 +777,20 @@ virStoragePoolDefParse(virConnectPtr conn, } if (!xml) { - if (conn && conn->err.code == VIR_ERR_NONE) - virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s",_("failed to parse xml document")); + if (virGetLastError() == NULL) + virStorageReportError(VIR_ERR_XML_ERROR, + "%s",_("failed to parse xml document")); goto cleanup; } node = xmlDocGetRootElement(xml); if (node == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing root element")); goto cleanup; } - ret = virStoragePoolDefParseNode(conn, xml, node); + ret = virStoragePoolDefParseNode(xml, node); xmlFreeParserCtxt (pctxt); xmlFreeDoc(xml); @@ -819,22 +804,19 @@ virStoragePoolDefParse(virConnectPtr conn, } virStoragePoolDefPtr -virStoragePoolDefParseString(virConnectPtr conn, - const char *xmlStr) +virStoragePoolDefParseString(const char *xmlStr) { - return virStoragePoolDefParse(conn, xmlStr, NULL); + return virStoragePoolDefParse(xmlStr, NULL); } virStoragePoolDefPtr -virStoragePoolDefParseFile(virConnectPtr conn, - const char *filename) +virStoragePoolDefParseFile(const char *filename) { - return virStoragePoolDefParse(conn, NULL, filename); + return virStoragePoolDefParse(NULL, filename); } static int -virStoragePoolSourceFormat(virConnectPtr conn, - virBufferPtr buf, +virStoragePoolSourceFormat(virBufferPtr buf, virStoragePoolOptionsPtr options, virStoragePoolSourcePtr src) { @@ -876,7 +858,7 @@ virStoragePoolSourceFormat(virConnectPtr conn, if (options->formatToString) { const char *format = (options->formatToString)(src->format); if (!format) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("unknown pool format number %d"), src->format); return -1; @@ -896,8 +878,7 @@ virStoragePoolSourceFormat(virConnectPtr conn, char * -virStoragePoolDefFormat(virConnectPtr conn, - virStoragePoolDefPtr def) { +virStoragePoolDefFormat(virStoragePoolDefPtr def) { virStoragePoolOptionsPtr options; virBuffer buf = VIR_BUFFER_INITIALIZER; const char *type; @@ -909,7 +890,7 @@ virStoragePoolDefFormat(virConnectPtr conn, type = virStoragePoolTypeToString(def->type); if (!type) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unexpected pool type")); goto cleanup; } @@ -926,7 +907,7 @@ virStoragePoolDefFormat(virConnectPtr conn, virBufferVSprintf(&buf," <available>%llu</available>\n", def->available); - if (virStoragePoolSourceFormat(conn, &buf, options, &def->source) < 0) + if (virStoragePoolSourceFormat(&buf, options, &def->source) < 0) goto cleanup; virBufferAddLit(&buf," <target>\n"); @@ -964,8 +945,7 @@ virStoragePoolDefFormat(virConnectPtr conn, static int -virStorageSize(virConnectPtr conn, - const char *unit, +virStorageSize(const char *unit, const char *val, unsigned long long *ret) { unsigned long long mult; @@ -1007,19 +987,19 @@ virStorageSize(virConnectPtr conn, break; default: - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, _("unknown size units '%s'"), unit); return -1; } } if (virStrToLong_ull (val, &end, 10, ret) < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("malformed capacity element")); return -1; } if (*ret > (ULLONG_MAX / mult)) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("capacity element value too large")); return -1; } @@ -1030,8 +1010,7 @@ virStorageSize(virConnectPtr conn, } static virStorageVolDefPtr -virStorageVolDefParseXML(virConnectPtr conn, - virStoragePoolDefPtr pool, +virStorageVolDefParseXML(virStoragePoolDefPtr pool, xmlXPathContextPtr ctxt) { virStorageVolDefPtr ret; virStorageVolOptionsPtr options; @@ -1051,7 +1030,7 @@ virStorageVolDefParseXML(virConnectPtr conn, ret->name = virXPathString("string(./name)", ctxt); if (ret->name == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing volume name element")); goto cleanup; } @@ -1062,11 +1041,11 @@ virStorageVolDefParseXML(virConnectPtr conn, capacity = virXPathString("string(./capacity)", ctxt); unit = virXPathString("string(./capacity/@unit)", ctxt); if (capacity == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing capacity element")); goto cleanup; } - if (virStorageSize(conn, unit, capacity, &ret->capacity) < 0) + if (virStorageSize(unit, capacity, &ret->capacity) < 0) goto cleanup; VIR_FREE(capacity); VIR_FREE(unit); @@ -1074,7 +1053,7 @@ virStorageVolDefParseXML(virConnectPtr conn, allocation = virXPathString("string(./allocation)", ctxt); if (allocation) { unit = virXPathString("string(./allocation/@unit)", ctxt); - if (virStorageSize(conn, unit, allocation, &ret->allocation) < 0) + if (virStorageSize(unit, allocation, &ret->allocation) < 0) goto cleanup; VIR_FREE(allocation); VIR_FREE(unit); @@ -1091,7 +1070,7 @@ virStorageVolDefParseXML(virConnectPtr conn, ret->target.format = (options->formatFromString)(format); if (ret->target.format < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, _("unknown volume format type %s"), format); VIR_FREE(format); goto cleanup; @@ -1099,13 +1078,13 @@ virStorageVolDefParseXML(virConnectPtr conn, VIR_FREE(format); } - if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms, + if (virStorageDefParsePerms(ctxt, &ret->target.perms, "./target/permissions", 0600) < 0) goto cleanup; node = virXPathNode("./target/encryption", ctxt); if (node != NULL) { - ret->target.encryption = virStorageEncryptionParseNode(conn, ctxt->doc, + ret->target.encryption = virStorageEncryptionParseNode(ctxt->doc, node); if (ret->target.encryption == NULL) goto cleanup; @@ -1122,7 +1101,7 @@ virStorageVolDefParseXML(virConnectPtr conn, ret->backingStore.format = (options->formatFromString)(format); if (ret->backingStore.format < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, _("unknown volume format type %s"), format); VIR_FREE(format); goto cleanup; @@ -1130,7 +1109,7 @@ virStorageVolDefParseXML(virConnectPtr conn, VIR_FREE(format); } - if (virStorageDefParsePerms(conn, ctxt, &ret->backingStore.perms, + if (virStorageDefParsePerms(ctxt, &ret->backingStore.perms, "./backingStore/permissions", 0600) < 0) goto cleanup; @@ -1145,15 +1124,14 @@ virStorageVolDefParseXML(virConnectPtr conn, } virStorageVolDefPtr -virStorageVolDefParseNode(virConnectPtr conn, - virStoragePoolDefPtr pool, +virStorageVolDefParseNode(virStoragePoolDefPtr pool, xmlDocPtr xml, xmlNodePtr root) { xmlXPathContextPtr ctxt = NULL; virStorageVolDefPtr def = NULL; if (STRNEQ((const char *)root->name, "volume")) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("unknown root element for storage vol")); goto cleanup; } @@ -1165,15 +1143,14 @@ virStorageVolDefParseNode(virConnectPtr conn, } ctxt->node = root; - def = virStorageVolDefParseXML(conn, pool, ctxt); + def = virStorageVolDefParseXML(pool, ctxt); cleanup: xmlXPathFreeContext(ctxt); return def; } static virStorageVolDefPtr -virStorageVolDefParse(virConnectPtr conn, - virStoragePoolDefPtr pool, +virStorageVolDefParse(virStoragePoolDefPtr pool, const char *xmlStr, const char *filename) { virStorageVolDefPtr ret = NULL; @@ -1186,9 +1163,6 @@ virStorageVolDefParse(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn; - - if (conn) virResetError (&conn->err); if (filename) { xml = xmlCtxtReadFile (pctxt, filename, NULL, @@ -1202,20 +1176,20 @@ virStorageVolDefParse(virConnectPtr conn, } if (!xml) { - if (conn && conn->err.code == VIR_ERR_NONE) - virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("failed to parse xml document")); + if (virGetLastError() == NULL) + virStorageReportError(VIR_ERR_XML_ERROR, + "%s", _("failed to parse xml document")); goto cleanup; } node = xmlDocGetRootElement(xml); if (node == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing root element")); goto cleanup; } - ret = virStorageVolDefParseNode(conn, pool, xml, node); + ret = virStorageVolDefParseNode(pool, xml, node); xmlFreeParserCtxt (pctxt); xmlFreeDoc(xml); @@ -1229,24 +1203,21 @@ virStorageVolDefParse(virConnectPtr conn, } virStorageVolDefPtr -virStorageVolDefParseString(virConnectPtr conn, - virStoragePoolDefPtr pool, +virStorageVolDefParseString(virStoragePoolDefPtr pool, const char *xmlStr) { - return virStorageVolDefParse(conn, pool, xmlStr, NULL); + return virStorageVolDefParse(pool, xmlStr, NULL); } virStorageVolDefPtr -virStorageVolDefParseFile(virConnectPtr conn, - virStoragePoolDefPtr pool, +virStorageVolDefParseFile(virStoragePoolDefPtr pool, const char *filename) { - return virStorageVolDefParse(conn, pool, NULL, filename); + return virStorageVolDefParse(pool, NULL, filename); } static int -virStorageVolTargetDefFormat(virConnectPtr conn, - virStorageVolOptionsPtr options, +virStorageVolTargetDefFormat(virStorageVolOptionsPtr options, virBufferPtr buf, virStorageVolTargetPtr def, const char *type) { @@ -1258,7 +1229,7 @@ virStorageVolTargetDefFormat(virConnectPtr conn, if (options->formatToString) { const char *format = (options->formatToString)(def->format); if (!format) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("unknown volume format number %d"), def->format); return -1; @@ -1282,7 +1253,7 @@ virStorageVolTargetDefFormat(virConnectPtr conn, virBufferAddLit(buf," </permissions>\n"); if (def->encryption != NULL && - virStorageEncryptionFormat(conn, buf, def->encryption) < 0) + virStorageEncryptionFormat(buf, def->encryption) < 0) return -1; virBufferVSprintf(buf, " </%s>\n", type); @@ -1291,8 +1262,7 @@ virStorageVolTargetDefFormat(virConnectPtr conn, } char * -virStorageVolDefFormat(virConnectPtr conn, - virStoragePoolDefPtr pool, +virStorageVolDefFormat(virStoragePoolDefPtr pool, virStorageVolDefPtr def) { virStorageVolOptionsPtr options; virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -1335,12 +1305,12 @@ virStorageVolDefFormat(virConnectPtr conn, virBufferVSprintf(&buf," <allocation>%llu</allocation>\n", def->allocation); - if (virStorageVolTargetDefFormat(conn, options, &buf, + if (virStorageVolTargetDefFormat(options, &buf, &def->target, "target") < 0) goto cleanup; if (def->backingStore.path && - virStorageVolTargetDefFormat(conn, options, &buf, + virStorageVolTargetDefFormat(options, &buf, &def->backingStore, "backingStore") < 0) goto cleanup; @@ -1437,8 +1407,7 @@ virStorageVolDefFindByName(virStoragePoolObjPtr pool, } virStoragePoolObjPtr -virStoragePoolObjAssignDef(virConnectPtr conn, - virStoragePoolObjListPtr pools, +virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def) { virStoragePoolObjPtr pool; @@ -1460,7 +1429,7 @@ virStoragePoolObjAssignDef(virConnectPtr conn, } if (virMutexInit(&pool->lock) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); VIR_FREE(pool); return NULL; @@ -1482,27 +1451,26 @@ virStoragePoolObjAssignDef(virConnectPtr conn, } static virStoragePoolObjPtr -virStoragePoolObjLoad(virConnectPtr conn, - virStoragePoolObjListPtr pools, +virStoragePoolObjLoad(virStoragePoolObjListPtr pools, const char *file, const char *path, const char *autostartLink) { virStoragePoolDefPtr def; virStoragePoolObjPtr pool; - if (!(def = virStoragePoolDefParseFile(conn, path))) { + if (!(def = virStoragePoolDefParseFile(path))) { return NULL; } if (!virFileMatchesNameSuffix(file, def->name, ".xml")) { - virStorageError(conn, VIR_ERR_INVALID_STORAGE_POOL, - "Storage pool config filename '%s' does not match pool name '%s'", - path, def->name); + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, + "Storage pool config filename '%s' does not match pool name '%s'", + path, def->name); virStoragePoolDefFree(def); return NULL; } - if (!(pool = virStoragePoolObjAssignDef(conn, pools, def))) { + if (!(pool = virStoragePoolObjAssignDef(pools, def))) { virStoragePoolDefFree(def); return NULL; } @@ -1528,8 +1496,7 @@ virStoragePoolObjLoad(virConnectPtr conn, int -virStoragePoolLoadAllConfigs(virConnectPtr conn, - virStoragePoolObjListPtr pools, +virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools, const char *configDir, const char *autostartDir) { DIR *dir; @@ -1556,21 +1523,21 @@ virStoragePoolLoadAllConfigs(virConnectPtr conn, if (virFileBuildPath(configDir, entry->d_name, NULL, path, PATH_MAX) < 0) { - virStorageError(conn, VIR_ERR_INTERNAL_ERROR, - "Config filename '%s/%s' is too long", - configDir, entry->d_name); + virStorageReportError(VIR_ERR_INTERNAL_ERROR, + "Config filename '%s/%s' is too long", + configDir, entry->d_name); continue; } if (virFileBuildPath(autostartDir, entry->d_name, NULL, autostartLink, PATH_MAX) < 0) { - virStorageError(conn, VIR_ERR_INTERNAL_ERROR, - "Autostart link path '%s/%s' is too long", - autostartDir, entry->d_name); + virStorageReportError(VIR_ERR_INTERNAL_ERROR, + "Autostart link path '%s/%s' is too long", + autostartDir, entry->d_name); continue; } - pool = virStoragePoolObjLoad(conn, pools, entry->d_name, path, + pool = virStoragePoolObjLoad(pools, entry->d_name, path, autostartLink); if (pool) virStoragePoolObjUnlock(pool); @@ -1582,8 +1549,7 @@ virStoragePoolLoadAllConfigs(virConnectPtr conn, } int -virStoragePoolObjSaveDef(virConnectPtr conn, - virStorageDriverStatePtr driver, +virStoragePoolObjSaveDef(virStorageDriverStatePtr driver, virStoragePoolObjPtr pool, virStoragePoolDefPtr def) { char *xml; @@ -1603,7 +1569,7 @@ virStoragePoolObjSaveDef(virConnectPtr conn, if (virFileBuildPath(driver->configDir, def->name, ".xml", path, sizeof(path)) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot construct config file path")); return -1; } @@ -1614,7 +1580,7 @@ virStoragePoolObjSaveDef(virConnectPtr conn, if (virFileBuildPath(driver->autostartDir, def->name, ".xml", path, sizeof(path)) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot construct " "autostart link path")); VIR_FREE(pool->configFile); @@ -1627,8 +1593,8 @@ virStoragePoolObjSaveDef(virConnectPtr conn, } } - if (!(xml = virStoragePoolDefFormat(conn, def))) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + if (!(xml = virStoragePoolDefFormat(def))) { + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to generate XML")); return -1; } @@ -1669,16 +1635,15 @@ virStoragePoolObjSaveDef(virConnectPtr conn, } int -virStoragePoolObjDeleteDef(virConnectPtr conn, - virStoragePoolObjPtr pool) { +virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool) { if (!pool->configFile) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("no config file for %s"), pool->def->name); return -1; } if (unlink(pool->configFile) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("cannot remove config for %s"), pool->def->name); return -1; @@ -1688,8 +1653,7 @@ virStoragePoolObjDeleteDef(virConnectPtr conn, } virStoragePoolSourcePtr -virStoragePoolSourceListNewSource(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, - virStoragePoolSourceListPtr list) +virStoragePoolSourceListNewSource(virStoragePoolSourceListPtr list) { virStoragePoolSourcePtr source; @@ -1704,8 +1668,7 @@ virStoragePoolSourceListNewSource(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORAR return source; } -char *virStoragePoolSourceListFormat(virConnectPtr conn, - virStoragePoolSourceListPtr def) +char *virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def) { virStoragePoolOptionsPtr options; virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -1718,7 +1681,7 @@ char *virStoragePoolSourceListFormat(virConnectPtr conn, type = virStoragePoolTypeToString(def->type); if (!type) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unexpected pool type")); goto cleanup; } @@ -1726,7 +1689,7 @@ char *virStoragePoolSourceListFormat(virConnectPtr conn, virBufferAddLit(&buf, "<sources>\n"); for (i = 0; i < def->nsources; i++) { - virStoragePoolSourceFormat(conn, &buf, options, &def->sources[i]); + virStoragePoolSourceFormat(&buf, options, &def->sources[i]); } virBufferAddLit(&buf, "</sources>\n"); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index a5f0100..c643984 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -318,12 +318,11 @@ static inline int virStoragePoolObjIsActive(virStoragePoolObjPtr pool) { return pool->active; } -#define virStorageReportError(conn, code, fmt...) \ - virReportErrorHelper(conn, VIR_FROM_STORAGE, code, __FILE__, \ - __FUNCTION__, __LINE__, fmt) +#define virStorageReportError(code, fmt...) \ + virReportErrorHelper(NULL, VIR_FROM_STORAGE, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) -int virStoragePoolLoadAllConfigs(virConnectPtr conn, - virStoragePoolObjListPtr pools, +int virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools, const char *configDir, const char *autostartDir); @@ -341,40 +340,29 @@ virStorageVolDefPtr virStorageVolDefFindByName(virStoragePoolObjPtr pool, void virStoragePoolObjClearVols(virStoragePoolObjPtr pool); -virStoragePoolDefPtr virStoragePoolDefParseString(virConnectPtr conn, - const char *xml); -virStoragePoolDefPtr virStoragePoolDefParseFile(virConnectPtr conn, - const char *filename); -virStoragePoolDefPtr virStoragePoolDefParseNode(virConnectPtr conn, - xmlDocPtr xml, +virStoragePoolDefPtr virStoragePoolDefParseString(const char *xml); +virStoragePoolDefPtr virStoragePoolDefParseFile(const char *filename); +virStoragePoolDefPtr virStoragePoolDefParseNode(xmlDocPtr xml, xmlNodePtr root); -char *virStoragePoolDefFormat(virConnectPtr conn, - virStoragePoolDefPtr def); +char *virStoragePoolDefFormat(virStoragePoolDefPtr def); -virStorageVolDefPtr virStorageVolDefParseString(virConnectPtr conn, - virStoragePoolDefPtr pool, +virStorageVolDefPtr virStorageVolDefParseString(virStoragePoolDefPtr pool, const char *xml); -virStorageVolDefPtr virStorageVolDefParseFile(virConnectPtr conn, - virStoragePoolDefPtr pool, +virStorageVolDefPtr virStorageVolDefParseFile(virStoragePoolDefPtr pool, const char *filename); -virStorageVolDefPtr virStorageVolDefParseNode(virConnectPtr conn, - virStoragePoolDefPtr pool, +virStorageVolDefPtr virStorageVolDefParseNode(virStoragePoolDefPtr pool, xmlDocPtr xml, xmlNodePtr root); -char *virStorageVolDefFormat(virConnectPtr conn, - virStoragePoolDefPtr pool, +char *virStorageVolDefFormat(virStoragePoolDefPtr pool, virStorageVolDefPtr def); -virStoragePoolObjPtr virStoragePoolObjAssignDef(virConnectPtr conn, - virStoragePoolObjListPtr pools, +virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def); -int virStoragePoolObjSaveDef(virConnectPtr conn, - virStorageDriverStatePtr driver, +int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver, virStoragePoolObjPtr pool, virStoragePoolDefPtr def); -int virStoragePoolObjDeleteDef(virConnectPtr conn, - virStoragePoolObjPtr pool); +int virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool); void virStorageVolDefFree(virStorageVolDefPtr def); void virStoragePoolSourceFree(virStoragePoolSourcePtr source); @@ -385,14 +373,11 @@ void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, virStoragePoolObjPtr pool); virStoragePoolSourcePtr -virStoragePoolDefParseSourceString(virConnectPtr conn, - const char *srcSpec, +virStoragePoolDefParseSourceString(const char *srcSpec, int pool_type); virStoragePoolSourcePtr -virStoragePoolSourceListNewSource(virConnectPtr conn, - virStoragePoolSourceListPtr list); -char *virStoragePoolSourceListFormat(virConnectPtr conn, - virStoragePoolSourceListPtr def); +virStoragePoolSourceListNewSource(virStoragePoolSourceListPtr list); +char *virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def); void virStoragePoolObjLock(virStoragePoolObjPtr obj); void virStoragePoolObjUnlock(virStoragePoolObjPtr obj); diff --git a/src/conf/storage_encryption_conf.c b/src/conf/storage_encryption_conf.c index f19af88..ed71688 100644 --- a/src/conf/storage_encryption_conf.c +++ b/src/conf/storage_encryption_conf.c @@ -70,7 +70,7 @@ virStorageEncryptionFree(virStorageEncryptionPtr enc) #ifndef PROXY static virStorageEncryptionSecretPtr -virStorageEncryptionSecretParse(virConnectPtr conn, xmlXPathContextPtr ctxt, +virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, xmlNodePtr node) { xmlNodePtr old_node; @@ -89,13 +89,13 @@ virStorageEncryptionSecretParse(virConnectPtr conn, xmlXPathContextPtr ctxt, type_str = virXPathString("string(./@type)", ctxt); if (type_str == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, "%s", + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("unknown volume encryption secret type")); goto cleanup; } type = virStorageEncryptionSecretTypeTypeFromString(type_str); if (type < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, _("unknown volume encryption secret type %s"), type_str); VIR_FREE(type_str); @@ -107,14 +107,14 @@ virStorageEncryptionSecretParse(virConnectPtr conn, xmlXPathContextPtr ctxt, uuidstr = virXPathString("string(./@uuid)", ctxt); if (uuidstr) { if (virUUIDParse(uuidstr, ret->uuid) < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, _("malformed volume encryption uuid '%s'"), uuidstr); goto cleanup; } VIR_FREE(uuidstr); } else { - virStorageReportError(conn, VIR_ERR_XML_ERROR, "%s", + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing volume encryption uuid")); goto cleanup; } @@ -129,7 +129,7 @@ virStorageEncryptionSecretParse(virConnectPtr conn, xmlXPathContextPtr ctxt, } static virStorageEncryptionPtr -virStorageEncryptionParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) +virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) { xmlNodePtr *nodes = NULL; virStorageEncryptionPtr ret; @@ -143,13 +143,13 @@ virStorageEncryptionParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) format_str = virXPathString("string(./@format)", ctxt); if (format_str == NULL) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, "%s", + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("unknown volume encryption format")); goto cleanup; } format = virStorageEncryptionFormatTypeFromString(format_str); if (format < 0) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, _("unknown volume encryption format type %s"), format_str); VIR_FREE(format_str); @@ -160,7 +160,7 @@ virStorageEncryptionParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) n = virXPathNodeSet("./secret", ctxt, &nodes); if (n < 0){ - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot extract volume encryption secrets")); goto cleanup; } @@ -170,7 +170,7 @@ virStorageEncryptionParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) } ret->nsecrets = n; for (i = 0; i < n; i++) { - ret->secrets[i] = virStorageEncryptionSecretParse(conn, ctxt, nodes[i]); + ret->secrets[i] = virStorageEncryptionSecretParse(ctxt, nodes[i]); if (ret->secrets[i] == NULL) goto cleanup; } @@ -185,14 +185,13 @@ virStorageEncryptionParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) } virStorageEncryptionPtr -virStorageEncryptionParseNode(virConnectPtr conn, - xmlDocPtr xml, xmlNodePtr root) +virStorageEncryptionParseNode(xmlDocPtr xml, xmlNodePtr root) { xmlXPathContextPtr ctxt = NULL; virStorageEncryptionPtr enc = NULL; if (STRNEQ((const char *) root->name, "encryption")) { - virStorageReportError(conn, VIR_ERR_XML_ERROR, + virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("unknown root element for volume " "encryption information")); goto cleanup; @@ -205,7 +204,7 @@ virStorageEncryptionParseNode(virConnectPtr conn, } ctxt->node = root; - enc = virStorageEncryptionParseXML(conn, ctxt); + enc = virStorageEncryptionParseXML(ctxt); cleanup: xmlXPathFreeContext(ctxt); @@ -215,8 +214,7 @@ virStorageEncryptionParseNode(virConnectPtr conn, static int -virStorageEncryptionSecretFormat(virConnectPtr conn, - virBufferPtr buf, +virStorageEncryptionSecretFormat(virBufferPtr buf, virStorageEncryptionSecretPtr secret) { const char *type; @@ -224,7 +222,7 @@ virStorageEncryptionSecretFormat(virConnectPtr conn, type = virStorageEncryptionSecretTypeTypeToString(secret->type); if (!type) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unexpected volume encryption secret type")); return -1; } @@ -235,8 +233,7 @@ virStorageEncryptionSecretFormat(virConnectPtr conn, } int -virStorageEncryptionFormat(virConnectPtr conn, - virBufferPtr buf, +virStorageEncryptionFormat(virBufferPtr buf, virStorageEncryptionPtr enc) { const char *format; @@ -244,14 +241,14 @@ virStorageEncryptionFormat(virConnectPtr conn, format = virStorageEncryptionFormatTypeToString(enc->format); if (!format) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unexpected encryption format")); return -1; } virBufferVSprintf(buf, " <encryption format='%s'>\n", format); for (i = 0; i < enc->nsecrets; i++) { - if (virStorageEncryptionSecretFormat(conn, buf, enc->secrets[i]) < 0) + if (virStorageEncryptionSecretFormat(buf, enc->secrets[i]) < 0) return -1; } @@ -261,7 +258,7 @@ virStorageEncryptionFormat(virConnectPtr conn, } int -virStorageGenerateQcowPassphrase(virConnectPtr conn, unsigned char *dest) +virStorageGenerateQcowPassphrase(unsigned char *dest) { int fd; size_t i; @@ -271,7 +268,7 @@ virStorageGenerateQcowPassphrase(virConnectPtr conn, unsigned char *dest) unpleasant surprises with the qemu monitor input mechanism. */ fd = open("/dev/urandom", O_RDONLY); if (fd < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot open /dev/urandom")); return -1; } @@ -282,7 +279,7 @@ virStorageGenerateQcowPassphrase(virConnectPtr conn, unsigned char *dest) while ((r = read(fd, dest + i, 1)) == -1 && errno == EINTR) ; if (r <= 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot read from /dev/urandom")); close(fd); return -1; diff --git a/src/conf/storage_encryption_conf.h b/src/conf/storage_encryption_conf.h index 5d0bc3c..bb19850 100644 --- a/src/conf/storage_encryption_conf.h +++ b/src/conf/storage_encryption_conf.h @@ -64,10 +64,9 @@ struct _virStorageEncryption { void virStorageEncryptionFree(virStorageEncryptionPtr enc); -virStorageEncryptionPtr virStorageEncryptionParseNode(virConnectPtr conn, - xmlDocPtr xml, +virStorageEncryptionPtr virStorageEncryptionParseNode(xmlDocPtr xml, xmlNodePtr root); -int virStorageEncryptionFormat(virConnectPtr conn, virBufferPtr buf, +int virStorageEncryptionFormat(virBufferPtr buf, virStorageEncryptionPtr enc); /* A helper for VIR_STORAGE_ENCRYPTION_FORMAT_QCOW */ @@ -75,6 +74,6 @@ enum { VIR_STORAGE_QCOW_PASSPHRASE_SIZE = 16 }; -int virStorageGenerateQcowPassphrase(virConnectPtr conn, unsigned char *dest); +int virStorageGenerateQcowPassphrase(unsigned char *dest); #endif /* __VIR_STORAGE_ENCRYPTION_H__ */ diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 4c62d48..de7fbd1 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -271,7 +271,7 @@ cleanup: } int -virStorageBackendCreateRaw(virConnectPtr conn, +virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, @@ -284,7 +284,7 @@ virStorageBackendCreateRaw(virConnectPtr conn, char *buf = NULL; if (vol->target.encryption != NULL) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("storage pool does not support encrypted " "volumes")); return -1; @@ -419,14 +419,14 @@ virStorageGenerateQcowEncryption(virConnectPtr conn, conn->secretDriver->lookupByUUID == NULL || conn->secretDriver->defineXML == NULL || conn->secretDriver->setValue == NULL) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, "%s", + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("secret storage not supported")); goto cleanup; } enc = vol->target.encryption; if (enc->nsecrets != 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("secrets already defined")); goto cleanup; } @@ -461,7 +461,7 @@ virStorageGenerateQcowEncryption(virConnectPtr conn, } VIR_FREE(xml); - if (virStorageGenerateQcowPassphrase(conn, value) < 0) + if (virStorageGenerateQcowPassphrase(value) < 0) goto cleanup; if (conn->secretDriver->setValue(secret, value, sizeof(value), 0) < 0) @@ -619,13 +619,13 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, }; if (type == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage vol type %d"), vol->target.format); return -1; } if (inputvol && inputType == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage vol type %d"), inputvol->target.format); return -1; @@ -640,14 +640,14 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, if (inputvol && (!inputBackingPath || STRNEQ(inputBackingPath, vol->backingStore.path))) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("a different backing store can not " "be specified.")); return -1; } if (backingType == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage vol backing store type %d"), vol->backingStore.format); return -1; @@ -665,7 +665,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, if (vol->target.format != VIR_STORAGE_FILE_QCOW && vol->target.format != VIR_STORAGE_FILE_QCOW2) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, _("qcow volume encryption unsupported with " "volume format %s"), type); return -1; @@ -673,13 +673,13 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, enc = vol->target.encryption; if (enc->format != VIR_STORAGE_ENCRYPTION_FORMAT_QCOW && enc->format != VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, _("unsupported volume encryption format %d"), vol->target.encryption->format); return -1; } if (enc->nsecrets > 1) { - virStorageReportError(conn, VIR_ERR_INVALID_STORAGE_VOL, "%s", + virStorageReportError(VIR_ERR_INVALID_STORAGE_VOL, "%s", _("too many secrets for qcow encryption")); return -1; } @@ -695,7 +695,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, else if ((create_tool = virFindFileInPath("qemu-img")) != NULL) use_kvmimg = 0; else { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to find kvm-img or qemu-img")); return -1; } @@ -737,7 +737,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, * with a partially functional qcow-create. Go figure ??!? */ static int -virStorageBackendCreateQcowCreate(virConnectPtr conn, +virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, @@ -748,25 +748,25 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn, const char *imgargv[4]; if (inputvol) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot copy from volume with qcow-create")); return -1; } if (vol->target.format != VIR_STORAGE_FILE_QCOW2) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported storage vol type %d"), vol->target.format); return -1; } if (vol->backingStore.path != NULL) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, "%s", + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("copy-on-write image not supported with " "qcow-create")); return -1; } if (vol->target.encryption != NULL) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("encrypted volumes not supported with " "qcow-create")); return -1; @@ -787,7 +787,7 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn, } virStorageBackendBuildVolFrom -virStorageBackendFSImageToolTypeToFunc(virConnectPtr conn, int tool_type) +virStorageBackendFSImageToolTypeToFunc(int tool_type) { switch (tool_type) { case TOOL_KVM_IMG: @@ -796,7 +796,7 @@ virStorageBackendFSImageToolTypeToFunc(virConnectPtr conn, int tool_type) case TOOL_QCOW_CREATE: return virStorageBackendCreateQcowCreate; default: - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown file create tool type '%d'."), tool_type); } @@ -827,8 +827,7 @@ virStorageBackendFindFSImageTool(char **tool) } virStorageBackendBuildVolFrom -virStorageBackendGetBuildVolFromFunction(virConnectPtr conn, - virStorageVolDefPtr vol, +virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol, virStorageVolDefPtr inputvol) { int tool_type; @@ -845,13 +844,13 @@ virStorageBackendGetBuildVolFromFunction(virConnectPtr conn, inputvol->target.format != VIR_STORAGE_FILE_RAW)) { if ((tool_type = virStorageBackendFindFSImageTool(NULL)) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("creation of non-raw file images is " "not supported without qemu-img.")); return NULL; } - return virStorageBackendFSImageToolTypeToFunc(conn, tool_type); + return virStorageBackendFSImageToolTypeToFunc(tool_type); } if (vol->type == VIR_STORAGE_VOL_BLOCK) @@ -868,7 +867,7 @@ virStorageBackendForType(int type) { if (backends[i]->type == type) return backends[i]; - virStorageReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("missing backend for pool type %d"), type); return NULL; } @@ -1192,8 +1191,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, * then run a callback passing in all the matches */ int -virStorageBackendRunProgRegex(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, const char *const*prog, int nregex, const char **regex, @@ -1223,7 +1221,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn, if (err != 0) { char error[100]; regerror(err, ®[i], error, sizeof(error)); - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to compile regex %s"), error); for (j = 0 ; j <= i ; j++) regfree(®[j]); @@ -1255,7 +1253,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn, } if ((list = fdopen(fd, "r")) == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot read fd")); goto cleanup; } @@ -1286,7 +1284,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn, /* We're matching on the last regex, so callback time */ if (i == (nregex-1)) { - if (((*func)(conn, pool, groups, data)) < 0) + if (((*func)(pool, groups, data)) < 0) goto cleanup; /* Release matches & restart to matching the first regex */ @@ -1337,7 +1335,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn, if (outexit != NULL) *outexit = WEXITSTATUS(exitstatus); } else { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("command did not exit cleanly")); return -1; } @@ -1358,8 +1356,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn, * If there are no input tokens (empty input), call FUNC with N_COLUMNS == 0. */ int -virStorageBackendRunProgNul(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendRunProgNul(virStoragePoolObjPtr pool, const char **prog, size_t n_columns, virStorageBackendListVolNulFunc func, @@ -1391,7 +1388,7 @@ virStorageBackendRunProgNul(virConnectPtr conn, } if ((fp = fdopen(fd, "r")) == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot read fd")); goto cleanup; } @@ -1406,13 +1403,13 @@ virStorageBackendRunProgNul(virConnectPtr conn, if (tok_len < 0) { /* Maybe EOF, maybe an error. If n_tok > 0, then we know it's an error. */ - if (n_tok && func (conn, pool, n_tok, v, data) < 0) + if (n_tok && func (pool, n_tok, v, data) < 0) goto cleanup; break; } ++n_tok; if (n_tok == n_columns) { - if (func (conn, pool, n_tok, v, data) < 0) + if (func (pool, n_tok, v, data) < 0) goto cleanup; n_tok = 0; for (i = 0; i < n_columns; i++) { @@ -1452,13 +1449,13 @@ virStorageBackendRunProgNul(virConnectPtr conn, } else { if (WIFEXITED(exitstatus)) { if (WEXITSTATUS(exitstatus) != 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("non-zero exit status from command %d"), WEXITSTATUS(exitstatus)); return -1; } } else { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("command did not exit cleanly")); return -1; } @@ -1480,7 +1477,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn, void *data ATTRIBUTE_UNUSED, int *outexit ATTRIBUTE_UNUSED) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, _("%s not implemented on Win32"), __FUNCTION__); + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("%s not implemented on Win32"), __FUNCTION__); return -1; } @@ -1492,7 +1489,7 @@ virStorageBackendRunProgNul(virConnectPtr conn, virStorageBackendListVolNulFunc func ATTRIBUTE_UNUSED, void *data ATTRIBUTE_UNUSED) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, _("%s not implemented on Win32"), __FUNCTION__); + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("%s not implemented on Win32"), __FUNCTION__); return -1; } #endif diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index a69aeee..00bc725 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -51,13 +51,11 @@ int virStorageBackendCreateRaw(virConnectPtr conn, virStorageVolDefPtr inputvol, unsigned int flags); virStorageBackendBuildVolFrom -virStorageBackendGetBuildVolFromFunction(virConnectPtr conn, - virStorageVolDefPtr vol, +virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol, virStorageVolDefPtr inputvol); int virStorageBackendFindFSImageTool(char **tool); virStorageBackendBuildVolFrom -virStorageBackendFSImageToolTypeToFunc(virConnectPtr conn, - int tool_type); +virStorageBackendFSImageToolTypeToFunc(int tool_type); typedef struct _virStorageBackend virStorageBackend; @@ -100,18 +98,15 @@ virStorageBackendUpdateVolTargetFormatFD(virStorageVolTargetPtr target, char *virStorageBackendStablePath(virStoragePoolObjPtr pool, const char *devpath); -typedef int (*virStorageBackendListVolRegexFunc)(virConnectPtr conn, - virStoragePoolObjPtr pool, +typedef int (*virStorageBackendListVolRegexFunc)(virStoragePoolObjPtr pool, char **const groups, void *data); -typedef int (*virStorageBackendListVolNulFunc)(virConnectPtr conn, - virStoragePoolObjPtr pool, +typedef int (*virStorageBackendListVolNulFunc)(virStoragePoolObjPtr pool, size_t n_tokens, char **const groups, void *data); -int virStorageBackendRunProgRegex(virConnectPtr conn, - virStoragePoolObjPtr pool, +int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, const char *const*prog, int nregex, const char **regex, @@ -120,8 +115,7 @@ int virStorageBackendRunProgRegex(virConnectPtr conn, void *data, int *exitstatus); -int virStorageBackendRunProgNul(virConnectPtr conn, - virStoragePoolObjPtr pool, +int virStorageBackendRunProgNul(virStoragePoolObjPtr pool, const char **prog, size_t n_columns, virStorageBackendListVolNulFunc func, diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 2082841..5717cfd 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -39,8 +39,7 @@ #define SECTOR_SIZE 512 static int -virStorageBackendDiskMakeDataVol(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, char **const groups, virStorageVolDefPtr vol) { @@ -105,14 +104,14 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn, if (virStrToLong_ull(groups[3], NULL, 10, &vol->source.extents[0].start) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot parse device start location")); return -1; } if (virStrToLong_ull(groups[4], NULL, 10, &vol->source.extents[0].end) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot parse device end location")); return -1; } @@ -154,8 +153,7 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn, } static int -virStorageBackendDiskMakeFreeExtent(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool, +virStorageBackendDiskMakeFreeExtent(virStoragePoolObjPtr pool, char **const groups) { virStoragePoolSourceDevicePtr dev = &pool->def->source.devices[0]; @@ -202,8 +200,7 @@ virStorageBackendDiskMakeFreeExtent(virConnectPtr conn ATTRIBUTE_UNUSED, static int -virStorageBackendDiskMakeVol(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendDiskMakeVol(virStoragePoolObjPtr pool, size_t ntok ATTRIBUTE_UNUSED, char **const groups, void *data) @@ -237,10 +234,10 @@ virStorageBackendDiskMakeVol(virConnectPtr conn, } } - return virStorageBackendDiskMakeDataVol(conn, pool, groups, vol); + return virStorageBackendDiskMakeDataVol(pool, groups, vol); } else if (STREQ(groups[2], "free")) { /* ....or free space extents */ - return virStorageBackendDiskMakeFreeExtent(conn, pool, groups); + return virStorageBackendDiskMakeFreeExtent(pool, groups); } else { /* This code path should never happen unless someone changed * libvirt_parthelper forgot to change this code */ @@ -260,8 +257,7 @@ virStorageBackendDiskMakeVol(virConnectPtr conn, * and we can even ensure the output is friendly. */ static int -virStorageBackendDiskReadPartitions(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { @@ -278,8 +274,7 @@ virStorageBackendDiskReadPartitions(virConnectPtr conn, pool->def->allocation = pool->def->capacity = pool->def->available = 0; - return virStorageBackendRunProgNul(conn, - pool, + return virStorageBackendRunProgNul(pool, prog, 6, virStorageBackendDiskMakeVol, @@ -287,11 +282,10 @@ virStorageBackendDiskReadPartitions(virConnectPtr conn, } static int -virStorageBackendDiskMakePoolGeometry(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool, - size_t ntok ATTRIBUTE_UNUSED, - char **const groups, - void *data ATTRIBUTE_UNUSED) +virStorageBackendDiskMakePoolGeometry(virStoragePoolObjPtr pool, + size_t ntok ATTRIBUTE_UNUSED, + char **const groups, + void *data ATTRIBUTE_UNUSED) { pool->def->source.devices[0].geometry.cyliders = atoi(groups[0]); @@ -302,14 +296,13 @@ virStorageBackendDiskMakePoolGeometry(virConnectPtr conn ATTRIBUTE_UNUSED, } static int -virStorageBackendDiskReadGeometry(virConnectPtr conn, virStoragePoolObjPtr pool) +virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool) { const char *prog[] = { PARTHELPER, pool->def->source.devices[0].path, "-g", NULL, }; - return virStorageBackendRunProgNul(conn, - pool, + return virStorageBackendRunProgNul(pool, prog, 3, virStorageBackendDiskMakePoolGeometry, @@ -317,7 +310,7 @@ virStorageBackendDiskReadGeometry(virConnectPtr conn, virStoragePoolObjPtr pool) } static int -virStorageBackendDiskRefreshPool(virConnectPtr conn, +virStorageBackendDiskRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { VIR_FREE(pool->def->source.devices[0].freeExtents); @@ -325,11 +318,11 @@ virStorageBackendDiskRefreshPool(virConnectPtr conn, virFileWaitForDevices(); - if (virStorageBackendDiskReadGeometry(conn, pool) != 0) { + if (virStorageBackendDiskReadGeometry(pool) != 0) { return -1; } - return virStorageBackendDiskReadPartitions(conn, pool, NULL); + return virStorageBackendDiskReadPartitions(pool, NULL); } @@ -386,7 +379,7 @@ virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool) } static int -virStorageBackendDiskPartFormat(virConnectPtr conn, virStoragePoolObjPtr pool, +virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, virStorageVolDefPtr vol, char* partFormat) { @@ -394,7 +387,7 @@ virStorageBackendDiskPartFormat(virConnectPtr conn, virStoragePoolObjPtr pool, if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) { const char *partedFormat = virStoragePartedFsTypeTypeToString(vol->target.format); if(partedFormat == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid partition type")); return -1; } @@ -402,7 +395,7 @@ virStorageBackendDiskPartFormat(virConnectPtr conn, virStoragePoolObjPtr pool, /* make sure we don't have a extended partition already */ for (i = 0; i < pool->volumes.count; i++) { if (pool->volumes.objs[i]->target.format == VIR_STORAGE_VOL_DISK_EXTENDED) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("extended partition already exists")); return -1; } @@ -426,7 +419,7 @@ virStorageBackendDiskPartFormat(virConnectPtr conn, virStoragePoolObjPtr pool, } } if (i == pool->volumes.count) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no extended partition found and no primary partition available")); return -1; } @@ -448,8 +441,7 @@ virStorageBackendDiskPartFormat(virConnectPtr conn, virStoragePoolObjPtr pool, * partitions */ static int -virStorageBackendDiskPartBoundries(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendDiskPartBoundries(virStoragePoolObjPtr pool, unsigned long long *start, unsigned long long *end, unsigned long long allocation) @@ -511,7 +503,7 @@ virStorageBackendDiskPartBoundries(virConnectPtr conn, } if (smallestExtent == -1) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no large enough free extent")); return -1; } @@ -538,7 +530,7 @@ virStorageBackendDiskPartBoundries(virConnectPtr conn, static int -virStorageBackendDiskCreateVol(virConnectPtr conn, +virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { @@ -556,17 +548,17 @@ virStorageBackendDiskCreateVol(virConnectPtr conn, }; if (vol->target.encryption != NULL) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("storage pool does not support encrypted " "volumes")); return -1; } - if (virStorageBackendDiskPartFormat(conn, pool, vol, partFormat) != 0) { + if (virStorageBackendDiskPartFormat(pool, vol, partFormat) != 0) { return -1; } - if (virStorageBackendDiskPartBoundries(conn, pool, &startOffset, + if (virStorageBackendDiskPartBoundries(pool, &startOffset, &endOffset, vol->capacity) != 0) { return -1; @@ -591,7 +583,7 @@ virStorageBackendDiskCreateVol(virConnectPtr conn, VIR_FREE(vol->target.path); /* Fetch actual extent info, generate key */ - if (virStorageBackendDiskReadPartitions(conn, pool, vol) < 0) + if (virStorageBackendDiskReadPartitions(pool, vol) < 0) return -1; return 0; @@ -606,7 +598,7 @@ virStorageBackendDiskBuildVolFrom(virConnectPtr conn, { virStorageBackendBuildVolFrom build_func; - build_func = virStorageBackendGetBuildVolFromFunction(conn, vol, inputvol); + build_func = virStorageBackendGetBuildVolFromFunction(vol, inputvol); if (!build_func) return -1; @@ -614,7 +606,7 @@ virStorageBackendDiskBuildVolFrom(virConnectPtr conn, } static int -virStorageBackendDiskDeleteVol(virConnectPtr conn, +virStorageBackendDiskDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, unsigned int flags ATTRIBUTE_UNUSED) @@ -637,7 +629,7 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn, DEBUG("devname=%s, srcname=%s", devname, srcname); if (!STRPREFIX(devname, srcname)) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Volume path '%s' did not start with parent " "pool source device name."), devname); goto cleanup; @@ -646,7 +638,7 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn, part_num = devname + strlen(srcname); if (*part_num == 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse partition number from target " "'%s'"), devname); goto cleanup; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index a431ac1..03ba43a 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -135,8 +135,7 @@ struct _virNetfsDiscoverState { typedef struct _virNetfsDiscoverState virNetfsDiscoverState; static int -virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, +virStorageBackendFileSystemNetFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, char **const groups, void *data) { @@ -149,18 +148,18 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn, name = strrchr(path, '/'); if (name == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("invalid netfs path (no /): %s"), path); goto cleanup; } name += 1; if (*name == '\0') { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("invalid netfs path (ends in /): %s"), path); goto cleanup; } - if (!(src = virStoragePoolSourceListNewSource(conn, &state->list))) + if (!(src = virStoragePoolSourceListNewSource(&state->list))) goto cleanup; if (!(src->host.name = strdup(state->host)) || @@ -180,7 +179,7 @@ cleanup: static char * -virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn, +virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec, unsigned int flags ATTRIBUTE_UNUSED) { @@ -212,7 +211,7 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn, char *retval = NULL; unsigned int i; - source = virStoragePoolDefParseSourceString(conn, srcSpec, + source = virStoragePoolDefParseSourceString(srcSpec, VIR_STORAGE_POOL_NETFS); if (!source) goto cleanup; @@ -220,12 +219,12 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn, state.host = source->host.name; prog[3] = source->host.name; - if (virStorageBackendRunProgRegex(conn, NULL, prog, 1, regexes, vars, + if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars, virStorageBackendFileSystemNetFindPoolSourcesFunc, &state, &exitstatus) < 0) goto cleanup; - retval = virStoragePoolSourceListFormat(conn, &state.list); + retval = virStoragePoolSourceListFormat(&state.list); if (retval == NULL) { virReportOOMError(); goto cleanup; @@ -286,8 +285,7 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool) { * Returns 0 if successfully mounted, -1 on error */ static int -virStorageBackendFileSystemMount(virConnectPtr conn, - virStoragePoolObjPtr pool) { +virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) { char *src; char *options; const char **mntargv; @@ -351,18 +349,18 @@ virStorageBackendFileSystemMount(virConnectPtr conn, if (pool->def->type == VIR_STORAGE_POOL_NETFS) { if (pool->def->source.host.name == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source host")); return -1; } if (pool->def->source.dir == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source path")); return -1; } } else { if (pool->def->source.ndevice != 1) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source device")); return -1; } @@ -420,25 +418,24 @@ virStorageBackendFileSystemMount(virConnectPtr conn, * Returns 0 if successfully unmounted, -1 on error */ static int -virStorageBackendFileSystemUnmount(virConnectPtr conn, - virStoragePoolObjPtr pool) { +virStorageBackendFileSystemUnmount(virStoragePoolObjPtr pool) { const char *mntargv[3]; int ret; if (pool->def->type == VIR_STORAGE_POOL_NETFS) { if (pool->def->source.host.name == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source host")); return -1; } if (pool->def->source.dir == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source dir")); return -1; } } else { if (pool->def->source.ndevice != 1) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source device")); return -1; } @@ -476,11 +473,11 @@ virStorageBackendFileSystemUnmount(virConnectPtr conn, */ #if WITH_STORAGE_FS static int -virStorageBackendFileSystemStart(virConnectPtr conn, +virStorageBackendFileSystemStart(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { if (pool->def->type != VIR_STORAGE_POOL_DIR && - virStorageBackendFileSystemMount(conn, pool) < 0) + virStorageBackendFileSystemMount(pool) < 0) return -1; return 0; @@ -499,7 +496,7 @@ virStorageBackendFileSystemStart(virConnectPtr conn, * Returns 0 on success, -1 on error */ static int -virStorageBackendFileSystemBuild(virConnectPtr conn, +virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, unsigned int flags ATTRIBUTE_UNUSED) { @@ -512,7 +509,7 @@ virStorageBackendFileSystemBuild(virConnectPtr conn, goto error; } if (!(p = strrchr(parent, '/'))) { - virStorageReportError(conn, VIR_ERR_INVALID_ARG, + virStorageReportError(VIR_ERR_INVALID_ARG, _("path '%s' is not absolute"), pool->def->target.path); goto error; @@ -694,11 +691,11 @@ no_memory: */ #if WITH_STORAGE_FS static int -virStorageBackendFileSystemStop(virConnectPtr conn, +virStorageBackendFileSystemStop(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { if (pool->def->type != VIR_STORAGE_POOL_DIR && - virStorageBackendFileSystemUnmount(conn, pool) < 0) + virStorageBackendFileSystemUnmount(pool) < 0) return -1; return 0; @@ -766,7 +763,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; } -static int createFileDir(virConnectPtr conn, +static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, @@ -774,7 +771,7 @@ static int createFileDir(virConnectPtr conn, int err; if (inputvol) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot copy from volume to a directory volume")); return -1; @@ -803,13 +800,13 @@ _virStorageBackendFileSystemVolBuild(virConnectPtr conn, if (inputvol) { if (vol->target.encryption != NULL) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("storage pool does not support " "building encrypted volumes from " "other volumes")); return -1; } - create_func = virStorageBackendGetBuildVolFromFunction(conn, vol, + create_func = virStorageBackendGetBuildVolFromFunction(vol, inputvol); if (!create_func) return -1; @@ -818,12 +815,12 @@ _virStorageBackendFileSystemVolBuild(virConnectPtr conn, } else if (vol->target.format == VIR_STORAGE_FILE_DIR) { create_func = createFileDir; } else if ((tool_type = virStorageBackendFindFSImageTool(NULL)) != -1) { - create_func = virStorageBackendFSImageToolTypeToFunc(conn, tool_type); + create_func = virStorageBackendFSImageToolTypeToFunc(tool_type); if (!create_func) return -1; } else { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("creation of non-raw images " "is not supported without qemu-img")); return -1; diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c index 4e2a75e..f34123f 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -45,8 +45,7 @@ #define VIR_FROM_THIS VIR_FROM_STORAGE static int -virStorageBackendISCSITargetIP(virConnectPtr conn, - const char *hostname, +virStorageBackendISCSITargetIP(const char *hostname, char *ipaddr, size_t ipaddrlen) { @@ -62,14 +61,14 @@ virStorageBackendISCSITargetIP(virConnectPtr conn, ret = getaddrinfo(hostname, NULL, &hints, &result); if (ret != 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("host lookup failed %s"), gai_strerror(ret)); return -1; } if (result == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("no IP address for target %s"), hostname); return -1; @@ -78,7 +77,7 @@ virStorageBackendISCSITargetIP(virConnectPtr conn, if (getnameinfo(result->ai_addr, result->ai_addrlen, ipaddr, ipaddrlen, NULL, 0, NI_NUMERICHOST) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("cannot format ip addr for %s"), hostname); freeaddrinfo(result); @@ -90,8 +89,7 @@ virStorageBackendISCSITargetIP(virConnectPtr conn, } static int -virStorageBackendISCSIExtractSession(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool, +virStorageBackendISCSIExtractSession(virStoragePoolObjPtr pool, char **const groups, void *data) { @@ -108,8 +106,7 @@ virStorageBackendISCSIExtractSession(virConnectPtr conn ATTRIBUTE_UNUSED, } static char * -virStorageBackendISCSISession(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendISCSISession(virStoragePoolObjPtr pool, int probe) { /* @@ -134,7 +131,7 @@ virStorageBackendISCSISession(virConnectPtr conn, * returned an exit status of > 0, even if they succeeded. We will just * rely on whether session got filled in properly. */ - if (virStorageBackendRunProgRegex(conn, pool, + if (virStorageBackendRunProgRegex(pool, prog, 1, regexes, @@ -146,7 +143,7 @@ virStorageBackendISCSISession(virConnectPtr conn, if (session == NULL && !probe) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot find session")); return NULL; } @@ -158,8 +155,7 @@ virStorageBackendISCSISession(virConnectPtr conn, #define LINE_SIZE 4096 static int -virStorageBackendIQNFound(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendIQNFound(virStoragePoolObjPtr pool, char **ifacename) { int ret = IQN_MISSING, fd = -1; @@ -174,7 +170,7 @@ virStorageBackendIQNFound(virConnectPtr conn, if (VIR_ALLOC_N(line, LINE_SIZE) != 0) { ret = IQN_ERROR; - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Could not allocate memory for output of '%s'"), prog[0]); goto out; @@ -183,7 +179,7 @@ virStorageBackendIQNFound(virConnectPtr conn, memset(line, 0, LINE_SIZE); if (virExec(prog, NULL, NULL, &child, -1, &fd, NULL, VIR_EXEC_NONE) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run '%s' when looking for existing interface with IQN '%s'"), prog[0], pool->def->source.initiator.iqn); @@ -192,7 +188,7 @@ virStorageBackendIQNFound(virConnectPtr conn, } if ((fp = fdopen(fd, "r")) == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open stream for file descriptor " "when reading output from '%s': '%s'"), prog[0], virStrerror(errno, ebuf, sizeof ebuf)); @@ -204,7 +200,7 @@ virStorageBackendIQNFound(virConnectPtr conn, newline = strrchr(line, '\n'); if (newline == NULL) { ret = IQN_ERROR; - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected line > %d characters " "when parsing output of '%s'"), LINE_SIZE, prog[0]); @@ -251,15 +247,14 @@ out: static int -virStorageBackendCreateIfaceIQN(virConnectPtr conn, - virStoragePoolObjPtr pool, - char **ifacename) +virStorageBackendCreateIfaceIQN(virStoragePoolObjPtr pool, + char **ifacename) { int ret = -1, exitstatus = -1; char temp_ifacename[32]; if (virRandomInitialize(time(NULL) ^ getpid()) == -1) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to initialize random generator " "when creating iscsi interface")); goto out; @@ -280,7 +275,7 @@ virStorageBackendCreateIfaceIQN(virConnectPtr conn, * We will just rely on whether the interface got created * properly. */ if (virRun(cmdargv1, &exitstatus) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run command '%s' to create new iscsi interface"), cmdargv1[0]); goto out; @@ -296,14 +291,14 @@ virStorageBackendCreateIfaceIQN(virConnectPtr conn, * returned an exit status of > 0, even if they succeeded. We will just * rely on whether iface file got updated properly. */ if (virRun(cmdargv2, &exitstatus) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run command '%s' to update iscsi interface with IQN '%s'"), cmdargv1[0], pool->def->source.initiator.iqn); goto out; } /* Check again to make sure the interface was created. */ - if (virStorageBackendIQNFound(conn, pool, ifacename) != IQN_FOUND) { + if (virStorageBackendIQNFound(pool, ifacename) != IQN_FOUND) { VIR_DEBUG("Failed to find interface '%s' with IQN '%s' " "after attempting to create it", &temp_ifacename[0], pool->def->source.initiator.iqn); @@ -323,20 +318,19 @@ out: static int -virStorageBackendISCSIConnectionIQN(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendISCSIConnectionIQN(virStoragePoolObjPtr pool, const char *portal, const char *action) { int ret = -1; char *ifacename = NULL; - switch (virStorageBackendIQNFound(conn, pool, &ifacename)) { + switch (virStorageBackendIQNFound(pool, &ifacename)) { case IQN_FOUND: VIR_DEBUG("ifacename: '%s'", ifacename); break; case IQN_MISSING: - if (virStorageBackendCreateIfaceIQN(conn, pool, &ifacename) != 0) { + if (virStorageBackendCreateIfaceIQN(pool, &ifacename) != 0) { goto out; } break; @@ -349,7 +343,7 @@ virStorageBackendISCSIConnectionIQN(virConnectPtr conn, ISCSIADM, "--mode", "discovery", "--type", "sendtargets", "--portal", portal, NULL }; if (virRun(sendtargets, NULL) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run %s to get target list"), sendtargets[0]); goto out; @@ -362,7 +356,7 @@ virStorageBackendISCSIConnectionIQN(virConnectPtr conn, }; if (virRun(cmdargv, NULL) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run command '%s' with action '%s'"), cmdargv[0], action); goto out; @@ -377,8 +371,7 @@ out: static int -virStorageBackendISCSIConnection(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendISCSIConnection(virStoragePoolObjPtr pool, const char *portal, const char *action) { @@ -386,7 +379,7 @@ virStorageBackendISCSIConnection(virConnectPtr conn, if (pool->def->source.initiator.iqn != NULL) { - ret = virStorageBackendISCSIConnectionIQN(conn, pool, portal, action); + ret = virStorageBackendISCSIConnectionIQN(pool, portal, action); } else { @@ -406,8 +399,7 @@ virStorageBackendISCSIConnection(virConnectPtr conn, static int -virStorageBackendISCSIFindLUs(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool, const char *session) { char sysfs_path[PATH_MAX]; @@ -425,7 +417,7 @@ virStorageBackendISCSIFindLUs(virConnectPtr conn, retval = -1; } - if (virStorageBackendSCSIFindLUs(conn, pool, host) < 0) { + if (virStorageBackendSCSIFindLUs(pool, host) < 0) { virReportSystemError(errno, _("Failed to find LUs on host %u"), host); retval = -1; @@ -435,8 +427,7 @@ virStorageBackendISCSIFindLUs(virConnectPtr conn, } static int -virStorageBackendISCSIRescanLUNs(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, +virStorageBackendISCSIRescanLUNs(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, const char *session) { const char *const cmdargv[] = { @@ -451,8 +442,7 @@ virStorageBackendISCSIRescanLUNs(virConnectPtr conn ATTRIBUTE_UNUSED, static int -virStorageBackendISCSILogin(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendISCSILogin(virStoragePoolObjPtr pool, const char *portal) { const char *const cmdsendtarget[] = { @@ -463,26 +453,23 @@ virStorageBackendISCSILogin(virConnectPtr conn, if (virRun(cmdsendtarget, NULL) < 0) return -1; - return virStorageBackendISCSIConnection(conn, pool, portal, "--login"); + return virStorageBackendISCSIConnection(pool, portal, "--login"); } static int -virStorageBackendISCSILogout(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendISCSILogout(virStoragePoolObjPtr pool, const char *portal) { - return virStorageBackendISCSIConnection(conn, pool, portal, "--logout"); + return virStorageBackendISCSIConnection(pool, portal, "--logout"); } static char * -virStorageBackendISCSIPortal(virConnectPtr conn, - virStoragePoolObjPtr pool) +virStorageBackendISCSIPortal(virStoragePoolObjPtr pool) { char ipaddr[NI_MAXHOST]; char *portal; - if (virStorageBackendISCSITargetIP(conn, - pool->def->source.host.name, + if (virStorageBackendISCSITargetIP(pool->def->source.host.name, ipaddr, sizeof(ipaddr)) < 0) return NULL; @@ -499,29 +486,29 @@ virStorageBackendISCSIPortal(virConnectPtr conn, static int -virStorageBackendISCSIStartPool(virConnectPtr conn, +virStorageBackendISCSIStartPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { char *portal = NULL; char *session; if (pool->def->source.host.name == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source host")); return -1; } if (pool->def->source.ndevice != 1 || pool->def->source.devices[0].path == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source device")); return -1; } - if ((session = virStorageBackendISCSISession(conn, pool, 1)) == NULL) { - if ((portal = virStorageBackendISCSIPortal(conn, pool)) == NULL) + if ((session = virStorageBackendISCSISession(pool, 1)) == NULL) { + if ((portal = virStorageBackendISCSIPortal(pool)) == NULL) return -1; - if (virStorageBackendISCSILogin(conn, pool, portal) < 0) { + if (virStorageBackendISCSILogin(pool, portal) < 0) { VIR_FREE(portal); return -1; } @@ -533,18 +520,18 @@ virStorageBackendISCSIStartPool(virConnectPtr conn, } static int -virStorageBackendISCSIRefreshPool(virConnectPtr conn, +virStorageBackendISCSIRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { char *session = NULL; pool->def->allocation = pool->def->capacity = pool->def->available = 0; - if ((session = virStorageBackendISCSISession(conn, pool, 0)) == NULL) + if ((session = virStorageBackendISCSISession(pool, 0)) == NULL) goto cleanup; - if (virStorageBackendISCSIRescanLUNs(conn, pool, session) < 0) + if (virStorageBackendISCSIRescanLUNs(pool, session) < 0) goto cleanup; - if (virStorageBackendISCSIFindLUs(conn, pool, session) < 0) + if (virStorageBackendISCSIFindLUs(pool, session) < 0) goto cleanup; VIR_FREE(session); @@ -557,15 +544,15 @@ virStorageBackendISCSIRefreshPool(virConnectPtr conn, static int -virStorageBackendISCSIStopPool(virConnectPtr conn, +virStorageBackendISCSIStopPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { char *portal; - if ((portal = virStorageBackendISCSIPortal(conn, pool)) == NULL) + if ((portal = virStorageBackendISCSIPortal(pool)) == NULL) return -1; - if (virStorageBackendISCSILogout(conn, pool, portal) < 0) { + if (virStorageBackendISCSILogout(pool, portal) < 0) { VIR_FREE(portal); return -1; } diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 35bedc0..06238d1 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -62,8 +62,7 @@ virStorageBackendLogicalSetActive(virStoragePoolObjPtr pool, static int -virStorageBackendLogicalMakeVol(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, char **const groups, void *data) { @@ -149,17 +148,17 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn, } if (virStrToLong_ull(groups[4], NULL, 10, &offset) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed volume extent offset value")); return -1; } if (virStrToLong_ull(groups[5], NULL, 10, &length) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed volume extent length value")); return -1; } if (virStrToLong_ull(groups[6], NULL, 10, &size) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed volume extent size value")); return -1; } @@ -172,8 +171,7 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn, } static int -virStorageBackendLogicalFindLVs(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { /* @@ -208,8 +206,7 @@ virStorageBackendLogicalFindLVs(virConnectPtr conn, int exitstatus; - if (virStorageBackendRunProgRegex(conn, - pool, + if (virStorageBackendRunProgRegex(pool, prog, 1, regexes, @@ -217,13 +214,13 @@ virStorageBackendLogicalFindLVs(virConnectPtr conn, virStorageBackendLogicalMakeVol, vol, &exitstatus) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("lvs command failed")); return -1; } if (exitstatus != 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("lvs command failed with exitstatus %d"), exitstatus); return -1; @@ -233,8 +230,7 @@ virStorageBackendLogicalFindLVs(virConnectPtr conn, } static int -virStorageBackendLogicalRefreshPoolFunc(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, +virStorageBackendLogicalRefreshPoolFunc(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, char **const groups, void *data ATTRIBUTE_UNUSED) { @@ -249,8 +245,7 @@ virStorageBackendLogicalRefreshPoolFunc(virConnectPtr conn ATTRIBUTE_UNUSED, static int -virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, +virStorageBackendLogicalFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, char **const groups, void *data) { @@ -278,8 +273,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn, } if (thisSource == NULL) { - if (!(thisSource = virStoragePoolSourceListNewSource(conn, - sourceList))) + if (!(thisSource = virStoragePoolSourceListNewSource(sourceList))) goto err_no_memory; thisSource->name = vgname; @@ -309,7 +303,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn, } static char * -virStorageBackendLogicalFindPoolSources(virConnectPtr conn, +virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec ATTRIBUTE_UNUSED, unsigned int flags ATTRIBUTE_UNUSED) { @@ -343,14 +337,14 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn, memset(&sourceList, 0, sizeof(sourceList)); sourceList.type = VIR_STORAGE_POOL_LOGICAL; - if (virStorageBackendRunProgRegex(conn, NULL, prog, 1, regexes, vars, + if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars, virStorageBackendLogicalFindPoolSourcesFunc, &sourceList, &exitstatus) < 0) return NULL; - retval = virStoragePoolSourceListFormat(conn, &sourceList); + retval = virStoragePoolSourceListFormat(&sourceList); if (retval == NULL) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to get source from sourceList")); goto cleanup; } @@ -451,7 +445,7 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, static int -virStorageBackendLogicalRefreshPool(virConnectPtr conn, +virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { /* @@ -478,14 +472,13 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn, virFileWaitForDevices(); /* Get list of all logical volumes */ - if (virStorageBackendLogicalFindLVs(conn, pool, NULL) < 0) { + if (virStorageBackendLogicalFindLVs(pool, NULL) < 0) { virStoragePoolObjClearVols(pool); return -1; } /* Now get basic volgrp metadata */ - if (virStorageBackendRunProgRegex(conn, - pool, + if (virStorageBackendRunProgRegex(pool, prog, 1, regexes, @@ -579,7 +572,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, const char **cmdargv = cmdargvnew; if (vol->target.encryption != NULL) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("storage pool does not support encrypted " "volumes")); return -1; @@ -641,7 +634,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, fd = -1; /* Fill in data about this new vol */ - if (virStorageBackendLogicalFindLVs(conn, pool, vol) < 0) { + if (virStorageBackendLogicalFindLVs(pool, vol) < 0) { virReportSystemError(errno, _("cannot find newly created volume '%s'"), vol->target.path); @@ -666,7 +659,7 @@ virStorageBackendLogicalBuildVolFrom(virConnectPtr conn, { virStorageBackendBuildVolFrom build_func; - build_func = virStorageBackendGetBuildVolFromFunction(conn, vol, inputvol); + build_func = virStorageBackendGetBuildVolFromFunction(vol, inputvol); if (!build_func) return -1; diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c index 8b8fba5..dbcd6d8 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -39,8 +39,7 @@ #define VIR_FROM_THIS VIR_FROM_STORAGE static int -virStorageBackendMpathUpdateVolTargetInfo(virConnectPtr conn, - virStorageVolTargetPtr target, +virStorageBackendMpathUpdateVolTargetInfo(virStorageVolTargetPtr target, unsigned long long *allocation, unsigned long long *capacity) { @@ -60,7 +59,7 @@ virStorageBackendMpathUpdateVolTargetInfo(virConnectPtr conn, allocation, capacity) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to update volume target info for '%s'"), target->path); @@ -69,7 +68,7 @@ virStorageBackendMpathUpdateVolTargetInfo(virConnectPtr conn, } if (virStorageBackendUpdateVolTargetFormatFD(target, fd) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to update volume target format for '%s'"), target->path); @@ -86,8 +85,7 @@ out: static int -virStorageBackendMpathNewVol(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendMpathNewVol(virStoragePoolObjPtr pool, const int devnum, const char *dev) { @@ -111,12 +109,11 @@ virStorageBackendMpathNewVol(virConnectPtr conn, goto cleanup; } - if (virStorageBackendMpathUpdateVolTargetInfo(conn, - &vol->target, + if (virStorageBackendMpathUpdateVolTargetInfo(&vol->target, &vol->allocation, &vol->capacity) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to update volume for '%s'"), vol->target.path); goto cleanup; @@ -231,8 +228,7 @@ out: static int -virStorageBackendCreateVols(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendCreateVols(virStoragePoolObjPtr pool, struct dm_names *names) { int retval = 0, is_mpath = 0; @@ -260,8 +256,7 @@ virStorageBackendCreateVols(virConnectPtr conn, goto out; } - virStorageBackendMpathNewVol(conn, - pool, + virStorageBackendMpathNewVol(pool, minor, map_device); @@ -280,8 +275,7 @@ out: static int -virStorageBackendGetMaps(virConnectPtr conn, - virStoragePoolObjPtr pool) +virStorageBackendGetMaps(virStoragePoolObjPtr pool) { int retval = 0; struct dm_task *dmt = NULL; @@ -309,7 +303,7 @@ virStorageBackendGetMaps(virConnectPtr conn, goto out; } - virStorageBackendCreateVols(conn, pool, names); + virStorageBackendCreateVols(pool, names); out: if (dmt != NULL) { @@ -320,7 +314,7 @@ out: static int -virStorageBackendMpathRefreshPool(virConnectPtr conn, +virStorageBackendMpathRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { int retval = 0; @@ -331,7 +325,7 @@ virStorageBackendMpathRefreshPool(virConnectPtr conn, virFileWaitForDevices(); - virStorageBackendGetMaps(conn, pool); + virStorageBackendGetMaps(pool); return retval; } diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c index 9c13dee..0260818 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -40,8 +40,7 @@ * the device otherwise. */ static int -getDeviceType(virConnectPtr conn, - uint32_t host, +getDeviceType(uint32_t host, uint32_t bus, uint32_t target, uint32_t lun, @@ -85,7 +84,7 @@ getDeviceType(virConnectPtr conn, * character is not \0, virStrToLong_i complains */ if (virStrToLong_i(typestr, &p, 10, type) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Device type '%s' is not an integer"), typestr); /* Hm, type wasn't an integer; seems strange */ @@ -191,8 +190,7 @@ virStorageBackendSCSIUpdateVolTargetInfo(virStorageVolTargetPtr target, } static int -virStorageBackendSCSINewLun(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, uint32_t host, uint32_t bus, uint32_t target, @@ -252,7 +250,7 @@ virStorageBackendSCSINewLun(virConnectPtr conn, &vol->allocation, &vol->capacity) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to update volume for '%s'"), devpath); retval = -1; @@ -289,8 +287,7 @@ out: static int -getNewStyleBlockDevice(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, - const char *lun_path, +getNewStyleBlockDevice(const char *lun_path, const char *block_name ATTRIBUTE_UNUSED, char **block_device) { @@ -344,8 +341,7 @@ out: static int -getOldStyleBlockDevice(virConnectPtr conn, - const char *lun_path ATTRIBUTE_UNUSED, +getOldStyleBlockDevice(const char *lun_path ATTRIBUTE_UNUSED, const char *block_name, char **block_device) { @@ -356,7 +352,7 @@ getOldStyleBlockDevice(virConnectPtr conn, blockp = strrchr(block_name, ':'); if (blockp == NULL) { /* Hm, wasn't what we were expecting; have to give up */ - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to parse block name %s"), block_name); retval = -1; @@ -379,8 +375,7 @@ out: static int -getBlockDevice(virConnectPtr conn, - uint32_t host, +getBlockDevice(uint32_t host, uint32_t bus, uint32_t target, uint32_t lun, @@ -409,13 +404,11 @@ getBlockDevice(virConnectPtr conn, while ((lun_dirent = readdir(lun_dir))) { if (STREQLEN(lun_dirent->d_name, "block", 5)) { if (strlen(lun_dirent->d_name) == 5) { - retval = getNewStyleBlockDevice(conn, - lun_path, + retval = getNewStyleBlockDevice(lun_path, lun_dirent->d_name, block_device); } else { - retval = getOldStyleBlockDevice(conn, - lun_path, + retval = getOldStyleBlockDevice(lun_path, lun_dirent->d_name, block_device); } @@ -432,8 +425,7 @@ out: static int -processLU(virConnectPtr conn, - virStoragePoolObjPtr pool, +processLU(virStoragePoolObjPtr pool, uint32_t host, uint32_t bus, uint32_t target, @@ -447,8 +439,8 @@ processLU(virConnectPtr conn, VIR_DEBUG(_("Processing LU %u:%u:%u:%u"), host, bus, target, lun); - if (getDeviceType(conn, host, bus, target, lun, &device_type) < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + if (getDeviceType(host, bus, target, lun, &device_type) < 0) { + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to determine if %u:%u:%u:%u is a Direct-Access LUN"), host, bus, target, lun); retval = -1; @@ -468,11 +460,11 @@ processLU(virConnectPtr conn, VIR_DEBUG(_("%u:%u:%u:%u is a Direct-Access LUN"), host, bus, target, lun); - if (getBlockDevice(conn, host, bus, target, lun, &block_device) < 0) { + if (getBlockDevice(host, bus, target, lun, &block_device) < 0) { goto out; } - if (virStorageBackendSCSINewLun(conn, pool, + if (virStorageBackendSCSINewLun(pool, host, bus, target, lun, block_device) < 0) { VIR_DEBUG(_("Failed to create new storage volume for %u:%u:%u:%u"), @@ -492,8 +484,7 @@ out: int -virStorageBackendSCSIFindLUs(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, uint32_t scanhost) { int retval = 0; @@ -531,7 +522,7 @@ virStorageBackendSCSIFindLUs(virConnectPtr conn, VIR_DEBUG(_("Found LU '%s'"), lun_dirent->d_name); - processLU(conn, pool, scanhost, bus, target, lun); + processLU(pool, scanhost, bus, target, lun); } closedir(devicedir); @@ -627,7 +618,7 @@ out: static int -virStorageBackendSCSIRefreshPool(virConnectPtr conn, +virStorageBackendSCSIRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { int retval = 0; @@ -649,7 +640,7 @@ virStorageBackendSCSIRefreshPool(virConnectPtr conn, goto out; } - virStorageBackendSCSIFindLUs(conn, pool, host); + virStorageBackendSCSIFindLUs(pool, host); out: return retval; diff --git a/src/storage/storage_backend_scsi.h b/src/storage/storage_backend_scsi.h index 8467993..a886660 100644 --- a/src/storage/storage_backend_scsi.h +++ b/src/storage/storage_backend_scsi.h @@ -36,8 +36,7 @@ int virStorageBackendSCSIGetHostNumber(const char *sysfs_path, uint32_t *host); int -virStorageBackendSCSIFindLUs(virConnectPtr conn, - virStoragePoolObjPtr pool, +virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, uint32_t scanhost); #endif /* __VIR_STORAGE_BACKEND_SCSI_H__ */ diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index fd5e51d..6b1045a 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -161,8 +161,7 @@ storageDriverStartup(int privileged) { } */ - if (virStoragePoolLoadAllConfigs(NULL, - &driverState->pools, + if (virStoragePoolLoadAllConfigs(&driverState->pools, driverState->configDir, driverState->autostartDir) < 0) goto error; @@ -192,8 +191,7 @@ storageDriverReload(void) { return -1; storageDriverLock(driverState); - virStoragePoolLoadAllConfigs(NULL, - &driverState->pools, + virStoragePoolLoadAllConfigs(&driverState->pools, driverState->configDir, driverState->autostartDir); storageDriverAutostart(driverState); @@ -268,7 +266,7 @@ storagePoolLookupByUUID(virConnectPtr conn, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(conn, VIR_ERR_NO_STORAGE_POOL, + virStorageReportError(VIR_ERR_NO_STORAGE_POOL, "%s", _("no pool with matching uuid")); goto cleanup; } @@ -293,7 +291,7 @@ storagePoolLookupByName(virConnectPtr conn, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(conn, VIR_ERR_NO_STORAGE_POOL, + virStorageReportError(VIR_ERR_NO_STORAGE_POOL, _("no pool with matching name '%s'"), name); goto cleanup; } @@ -439,7 +437,7 @@ storageFindPoolSources(virConnectPtr conn, backend_type = virStoragePoolTypeFromString(type); if (backend_type < 0) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage pool type %s"), type); goto cleanup; } @@ -449,7 +447,7 @@ storageFindPoolSources(virConnectPtr conn, goto cleanup; if (!backend->findPoolSources) { - virStorageReportError(conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, _("pool type '%s' does not support source " "discovery"), type); goto cleanup; @@ -472,7 +470,7 @@ static int storagePoolIsActive(virStoragePoolPtr pool) obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid); storageDriverUnlock(driver); if (!obj) { - virStorageReportError(pool->conn, VIR_ERR_NO_STORAGE_POOL, NULL); + virStorageReportError(VIR_ERR_NO_STORAGE_POOL, NULL); goto cleanup; } ret = virStoragePoolObjIsActive(obj); @@ -493,7 +491,7 @@ static int storagePoolIsPersistent(virStoragePoolPtr pool) obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid); storageDriverUnlock(driver); if (!obj) { - virStorageReportError(pool->conn, VIR_ERR_NO_STORAGE_POOL, NULL); + virStorageReportError(VIR_ERR_NO_STORAGE_POOL, NULL); goto cleanup; } ret = obj->configFile ? 1 : 0; @@ -516,7 +514,7 @@ storagePoolCreate(virConnectPtr conn, virStorageBackendPtr backend; storageDriverLock(driver); - if (!(def = virStoragePoolDefParseString(conn, xml))) + if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; pool = virStoragePoolObjFindByUUID(&driver->pools, def->uuid); @@ -524,7 +522,7 @@ storagePoolCreate(virConnectPtr conn, pool = virStoragePoolObjFindByName(&driver->pools, def->name); if (pool) { - virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool already exists")); virStoragePoolObjUnlock(pool); pool = NULL; @@ -534,7 +532,7 @@ storagePoolCreate(virConnectPtr conn, if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup; - if (!(pool = virStoragePoolObjAssignDef(conn, &driver->pools, def))) + if (!(pool = virStoragePoolObjAssignDef(&driver->pools, def))) goto cleanup; def = NULL; @@ -574,16 +572,16 @@ storagePoolDefine(virConnectPtr conn, virStoragePoolPtr ret = NULL; storageDriverLock(driver); - if (!(def = virStoragePoolDefParseString(conn, xml))) + if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; if (virStorageBackendForType(def->type) == NULL) goto cleanup; - if (!(pool = virStoragePoolObjAssignDef(conn, &driver->pools, def))) + if (!(pool = virStoragePoolObjAssignDef(&driver->pools, def))) goto cleanup; - if (virStoragePoolObjSaveDef(conn, driver, pool, def) < 0) { + if (virStoragePoolObjSaveDef(driver, pool, def) < 0) { virStoragePoolObjRemove(&driver->pools, pool); def = NULL; goto cleanup; @@ -609,25 +607,25 @@ storagePoolUndefine(virStoragePoolPtr obj) { storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("pool is still active")); goto cleanup; } if (pool->asyncjobs > 0) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), pool->def->name); goto cleanup; } - if (virStoragePoolObjDeleteDef(obj->conn, pool) < 0) + if (virStoragePoolObjDeleteDef(pool) < 0) goto cleanup; if (unlink(pool->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) { @@ -663,7 +661,7 @@ storagePoolStart(virStoragePoolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } @@ -672,7 +670,7 @@ storagePoolStart(virStoragePoolPtr obj, goto cleanup; if (virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("pool already active")); goto cleanup; } @@ -708,7 +706,7 @@ storagePoolBuild(virStoragePoolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } @@ -717,7 +715,7 @@ storagePoolBuild(virStoragePoolPtr obj, goto cleanup; if (virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is already active")); goto cleanup; } @@ -745,7 +743,7 @@ storagePoolDestroy(virStoragePoolPtr obj) { pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } @@ -754,13 +752,13 @@ storagePoolDestroy(virStoragePoolPtr obj) { goto cleanup; if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } if (pool->asyncjobs > 0) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), pool->def->name); goto cleanup; @@ -801,7 +799,7 @@ storagePoolDelete(virStoragePoolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } @@ -810,20 +808,20 @@ storagePoolDelete(virStoragePoolPtr obj, goto cleanup; if (virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is still active")); goto cleanup; } if (pool->asyncjobs > 0) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), pool->def->name); goto cleanup; } if (!backend->deletePool) { - virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("pool does not support volume delete")); goto cleanup; } @@ -850,7 +848,7 @@ storagePoolRefresh(virStoragePoolPtr obj, pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } @@ -859,13 +857,13 @@ storagePoolRefresh(virStoragePoolPtr obj, goto cleanup; if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } if (pool->asyncjobs > 0) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), pool->def->name); goto cleanup; @@ -906,7 +904,7 @@ storagePoolGetInfo(virStoragePoolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } @@ -942,12 +940,12 @@ storagePoolDumpXML(virStoragePoolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } - ret = virStoragePoolDefFormat(obj->conn, pool->def); + ret = virStoragePoolDefFormat(pool->def); cleanup: if (pool) @@ -967,7 +965,7 @@ storagePoolGetAutostart(virStoragePoolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no pool with matching uuid")); goto cleanup; } @@ -996,13 +994,13 @@ storagePoolSetAutostart(virStoragePoolPtr obj, pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no pool with matching uuid")); goto cleanup; } if (!pool->configFile) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_ARG, + virStorageReportError(VIR_ERR_INVALID_ARG, "%s", _("pool has no config file")); goto cleanup; } @@ -1058,13 +1056,13 @@ storagePoolNumVolumes(virStoragePoolPtr obj) { storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } @@ -1091,13 +1089,13 @@ storagePoolListVolumes(virStoragePoolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } @@ -1136,13 +1134,13 @@ storageVolumeLookupByName(virStoragePoolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } @@ -1150,8 +1148,8 @@ storageVolumeLookupByName(virStoragePoolPtr obj, vol = virStorageVolDefFindByName(pool, name); if (!vol) { - virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), + virStorageReportError(VIR_ERR_NO_STORAGE_VOL, + _("no storage vol with matching name '%s'"), name); goto cleanup; } @@ -1190,7 +1188,7 @@ storageVolumeLookupByKey(virConnectPtr conn, storageDriverUnlock(driver); if (!ret) - virStorageReportError(conn, VIR_ERR_INVALID_STORAGE_VOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_VOL, "%s", _("no storage vol with matching key")); return ret; @@ -1236,7 +1234,7 @@ storageVolumeLookupByPath(virConnectPtr conn, } if (!ret) - virStorageReportError(conn, VIR_ERR_INVALID_STORAGE_VOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_VOL, "%s", _("no storage vol with matching path")); cleanup: @@ -1261,13 +1259,13 @@ storageVolumeCreateXML(virStoragePoolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } @@ -1275,12 +1273,12 @@ storageVolumeCreateXML(virStoragePoolPtr obj, if ((backend = virStorageBackendForType(pool->def->type)) == NULL) goto cleanup; - voldef = virStorageVolDefParseString(obj->conn, pool->def, xmldesc); + voldef = virStorageVolDefParseString(pool->def, xmldesc); if (voldef == NULL) goto cleanup; if (virStorageVolDefFindByName(pool, voldef->name)) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("storage vol already exists")); goto cleanup; } @@ -1292,7 +1290,7 @@ storageVolumeCreateXML(virStoragePoolPtr obj, } if (!backend->createVol) { - virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("storage pool does not support volume " "creation")); goto cleanup; @@ -1382,26 +1380,26 @@ storageVolumeCreateXMLFrom(virStoragePoolPtr obj, } storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (STRNEQ(obj->name, vobj->pool) && !origpool) { - virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching name '%s'"), + virStorageReportError(VIR_ERR_NO_STORAGE_POOL, + _("no storage pool with matching name '%s'"), vobj->pool); goto cleanup; } if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } if (origpool && !virStoragePoolObjIsActive(origpool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } @@ -1411,18 +1409,18 @@ storageVolumeCreateXMLFrom(virStoragePoolPtr obj, origvol = virStorageVolDefFindByName(origpool ? origpool : pool, vobj->name); if (!origvol) { - virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), + virStorageReportError(VIR_ERR_NO_STORAGE_VOL, + _("no storage vol with matching name '%s'"), vobj->name); goto cleanup; } - newvol = virStorageVolDefParseString(obj->conn, pool->def, xmldesc); + newvol = virStorageVolDefParseString(pool->def, xmldesc); if (newvol == NULL) goto cleanup; if (virStorageVolDefFindByName(pool, newvol->name)) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, _("storage volume name '%s' already in use."), newvol->name); goto cleanup; @@ -1438,13 +1436,13 @@ storageVolumeCreateXMLFrom(virStoragePoolPtr obj, newvol->allocation = origvol->capacity; if (!backend->buildVolFrom) { - virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("storage pool does not support volume creation from an existing volume")); goto cleanup; } if (origvol->building) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("volume '%s' is still being allocated."), origvol->name); goto cleanup; @@ -1535,13 +1533,13 @@ storageVolumeDelete(virStorageVolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } @@ -1552,21 +1550,21 @@ storageVolumeDelete(virStorageVolPtr obj, vol = virStorageVolDefFindByName(pool, obj->name); if (!vol) { - virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL, + virStorageReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching name '%s'"), obj->name); goto cleanup; } if (vol->building) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("volume '%s' is still being allocated."), vol->name); goto cleanup; } if (!backend->deleteVol) { - virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT, + virStorageReportError(VIR_ERR_NO_SUPPORT, "%s", _("storage pool does not support vol deletion")); goto cleanup; @@ -1614,13 +1612,13 @@ storageVolumeGetInfo(virStorageVolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } @@ -1628,8 +1626,8 @@ storageVolumeGetInfo(virStorageVolPtr obj, vol = virStorageVolDefFindByName(pool, obj->name); if (!vol) { - virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), + virStorageReportError(VIR_ERR_NO_STORAGE_VOL, + _("no storage vol with matching name '%s'"), obj->name); goto cleanup; } @@ -1667,13 +1665,13 @@ storageVolumeGetXMLDesc(virStorageVolPtr obj, storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } @@ -1681,7 +1679,7 @@ storageVolumeGetXMLDesc(virStorageVolPtr obj, vol = virStorageVolDefFindByName(pool, obj->name); if (!vol) { - virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL, + virStorageReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching name '%s'"), obj->name); goto cleanup; @@ -1694,7 +1692,7 @@ storageVolumeGetXMLDesc(virStorageVolPtr obj, backend->refreshVol(obj->conn, pool, vol) < 0) goto cleanup; - ret = virStorageVolDefFormat(obj->conn, pool->def, vol); + ret = virStorageVolDefFormat(pool->def, vol); cleanup: if (pool) @@ -1714,13 +1712,13 @@ storageVolumeGetPath(virStorageVolPtr obj) { pool = virStoragePoolObjFindByName(&driver->pools, obj->pool); storageDriverUnlock(driver); if (!pool) { - virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL, + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, "%s", _("no storage pool with matching uuid")); goto cleanup; } if (!virStoragePoolObjIsActive(pool)) { - virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR, + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool is not active")); goto cleanup; } @@ -1728,8 +1726,8 @@ storageVolumeGetPath(virStorageVolPtr obj) { vol = virStorageVolDefFindByName(pool, obj->name); if (!vol) { - virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), + virStorageReportError(VIR_ERR_NO_STORAGE_VOL, + _("no storage vol with matching name '%s'"), obj->name); goto cleanup; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 5cecb93..ac0818b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -577,10 +577,10 @@ static int testOpenDefault(virConnectPtr conn) { interfaceobj->active = 1; virInterfaceObjUnlock(interfaceobj); - if (!(pooldef = virStoragePoolDefParseString(conn, defaultPoolXML))) + if (!(pooldef = virStoragePoolDefParseString(defaultPoolXML))) goto error; - if (!(poolobj = virStoragePoolObjAssignDef(conn, &privconn->pools, + if (!(poolobj = virStoragePoolObjAssignDef(&privconn->pools, pooldef))) { virStoragePoolDefFree(pooldef); goto error; @@ -648,8 +648,7 @@ static char *testBuildFilename(const char *relativeTo, } } -static int testOpenVolumesForPool(virConnectPtr conn, - xmlDocPtr xml, +static int testOpenVolumesForPool(xmlDocPtr xml, xmlXPathContextPtr ctxt, const char *file, virStoragePoolObjPtr pool, @@ -684,12 +683,12 @@ static int testOpenVolumesForPool(virConnectPtr conn, goto error; } - def = virStorageVolDefParseFile(conn, pool->def, absFile); + def = virStorageVolDefParseFile(pool->def, absFile); VIR_FREE(absFile); if (!def) goto error; } else { - if ((def = virStorageVolDefParseNode(conn, pool->def, xml, + if ((def = virStorageVolDefParseNode(pool->def, xml, vols[i])) == NULL) { goto error; } @@ -1008,18 +1007,18 @@ static int testOpenFromFile(virConnectPtr conn, goto error; } - def = virStoragePoolDefParseFile(conn, absFile); + def = virStoragePoolDefParseFile(absFile); VIR_FREE(absFile); if (!def) goto error; } else { - if ((def = virStoragePoolDefParseNode(conn, xml, + if ((def = virStoragePoolDefParseNode(xml, pools[i])) == NULL) { goto error; } } - if (!(pool = virStoragePoolObjAssignDef(conn, &privconn->pools, + if (!(pool = virStoragePoolObjAssignDef(&privconn->pools, def))) { virStoragePoolDefFree(def); goto error; @@ -1032,7 +1031,7 @@ static int testOpenFromFile(virConnectPtr conn, pool->active = 1; /* Find storage volumes */ - if (testOpenVolumesForPool(conn, xml, ctxt, file, pool, i+1) < 0) { + if (testOpenVolumesForPool(xml, ctxt, file, pool, i+1) < 0) { virStoragePoolObjUnlock(pool); goto error; } @@ -3727,7 +3726,7 @@ testStorageFindPoolSources(virConnectPtr conn, } if (srcSpec) { - source = virStoragePoolDefParseSourceString(conn, srcSpec, pool_type); + source = virStoragePoolDefParseSourceString(srcSpec, pool_type); if (!source) goto cleanup; } @@ -3773,7 +3772,7 @@ testStoragePoolCreate(virConnectPtr conn, virStoragePoolPtr ret = NULL; testDriverLock(privconn); - if (!(def = virStoragePoolDefParseString(conn, xml))) + if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; pool = virStoragePoolObjFindByUUID(&privconn->pools, def->uuid); @@ -3785,7 +3784,7 @@ testStoragePoolCreate(virConnectPtr conn, goto cleanup; } - if (!(pool = virStoragePoolObjAssignDef(conn, &privconn->pools, def))) + if (!(pool = virStoragePoolObjAssignDef(&privconn->pools, def))) goto cleanup; def = NULL; @@ -3816,14 +3815,14 @@ testStoragePoolDefine(virConnectPtr conn, virStoragePoolPtr ret = NULL; testDriverLock(privconn); - if (!(def = virStoragePoolDefParseString(conn, xml))) + if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; def->capacity = defaultPoolCap; def->allocation = defaultPoolAlloc; def->available = defaultPoolCap - defaultPoolAlloc; - if (!(pool = virStoragePoolObjAssignDef(conn, &privconn->pools, def))) + if (!(pool = virStoragePoolObjAssignDef(&privconn->pools, def))) goto cleanup; def = NULL; @@ -4055,7 +4054,7 @@ testStoragePoolDumpXML(virStoragePoolPtr pool, goto cleanup; } - ret = virStoragePoolDefFormat(pool->conn, privpool->def); + ret = virStoragePoolDefFormat(privpool->def); cleanup: if (privpool) @@ -4341,7 +4340,7 @@ testStorageVolumeCreateXML(virStoragePoolPtr pool, goto cleanup; } - privvol = virStorageVolDefParseString(pool->conn, privpool->def, xmldesc); + privvol = virStorageVolDefParseString(privpool->def, xmldesc); if (privvol == NULL) goto cleanup; @@ -4422,7 +4421,7 @@ testStorageVolumeCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; } - privvol = virStorageVolDefParseString(pool->conn, privpool->def, xmldesc); + privvol = virStorageVolDefParseString(privpool->def, xmldesc); if (privvol == NULL) goto cleanup; @@ -4645,7 +4644,7 @@ testStorageVolumeGetXMLDesc(virStorageVolPtr vol, goto cleanup; } - ret = virStorageVolDefFormat(vol->conn, privpool->def, privvol); + ret = virStorageVolDefFormat(privpool->def, privvol); cleanup: if (privpool) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 06f6802..0965021 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -6578,7 +6578,7 @@ static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, memset(&poolDef, 0, sizeof(poolDef)); poolDef.type = VIR_STORAGE_POOL_DIR; - if ((def = virStorageVolDefParseString(pool->conn, &poolDef, xml)) == NULL) + if ((def = virStorageVolDefParseString(&poolDef, xml)) == NULL) goto cleanup; if ( !def->name @@ -6922,7 +6922,7 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags A vboxIIDUtf16Free(hddIID); if (defOk) - ret = virStorageVolDefFormat(vol->conn, &pool, &def); + ret = virStorageVolDefFormat(&pool, &def); return ret; } diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index a7370c7..4550407 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -33,10 +33,10 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) goto fail; - if (!(dev = virStoragePoolDefParseString(NULL, inXmlData))) + if (!(dev = virStoragePoolDefParseString(inXmlData))) goto fail; - if (!(actual = virStoragePoolDefFormat(NULL, dev))) + if (!(actual = virStoragePoolDefFormat(dev))) goto fail; if (STRNEQ(outXmlData, actual)) { diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index 17bf009..ffa5dfe 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -40,13 +40,13 @@ static int testCompareXMLToXMLFiles(const char *poolxml, if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) goto fail; - if (!(pool = virStoragePoolDefParseString(NULL, poolXmlData))) + if (!(pool = virStoragePoolDefParseString(poolXmlData))) goto fail; - if (!(dev = virStorageVolDefParseString(NULL, pool, inXmlData))) + if (!(dev = virStorageVolDefParseString(pool, inXmlData))) goto fail; - if (!(actual = virStorageVolDefFormat(NULL, pool, dev))) + if (!(actual = virStorageVolDefFormat(pool, dev))) goto fail; if (STRNEQ(outXmlData, actual)) { -- 1.6.6

On Wed, Feb 10, 2010 at 01:36:22PM +0000, Daniel P. Berrange wrote:
The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in storage_conf.{h,c} and storage_encryption_conf.{h,c} and update all callers to match --- src/conf/domain_conf.c | 4 +- src/conf/storage_conf.c | 257 ++++++++++++++------------------- src/conf/storage_conf.h | 51 +++----- src/conf/storage_encryption_conf.c | 45 +++--- src/conf/storage_encryption_conf.h | 7 +- src/storage/storage_backend.c | 77 +++++----- src/storage/storage_backend.h | 18 +-- src/storage/storage_backend_disk.c | 74 +++++------ src/storage/storage_backend_fs.c | 59 ++++---- src/storage/storage_backend_iscsi.c | 109 ++++++-------- src/storage/storage_backend_logical.c | 49 +++---- src/storage/storage_backend_mpath.c | 30 ++--- src/storage/storage_backend_scsi.c | 47 +++---- src/storage/storage_backend_scsi.h | 3 +- src/storage/storage_driver.c | 164 +++++++++++----------- src/test/test_driver.c | 37 +++--- src/vbox/vbox_tmpl.c | 4 +- tests/storagepoolxml2xmltest.c | 4 +- tests/storagevolxml2xmltest.c | 6 +- 19 files changed, 465 insertions(+), 580 deletions(-) [...] if (!virFileMatchesNameSuffix(file, def->name, ".xml")) { - virStorageError(conn, VIR_ERR_INVALID_STORAGE_POOL, - "Storage pool config filename '%s' does not match pool name '%s'", - path, def->name); + virStorageReportError(VIR_ERR_INVALID_STORAGE_POOL, + "Storage pool config filename '%s' does not match pool name '%s'", + path, def->name);
stylistic, I prefer to not align on the opening brace than go over 80 columns Pfeewww that was huge ... done ! ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in cpu_conf.{h,c} and update all callers to match --- src/conf/capabilities.c | 2 +- src/conf/cpu_conf.c | 54 ++++++++++++++++++++----------------------- src/conf/cpu_conf.h | 12 +++------ src/conf/domain_conf.c | 4 +- src/cpu/cpu.c | 58 ++++++++++++++++++++-------------------------- src/cpu/cpu.h | 27 ++++++++------------- src/cpu/cpu_map.c | 8 +++--- src/cpu/cpu_x86.c | 24 +++++++++--------- src/qemu/qemu_conf.c | 14 +++++----- src/qemu/qemu_driver.c | 2 +- 10 files changed, 91 insertions(+), 114 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 47976af..dafd821 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -678,7 +678,7 @@ virCapabilitiesFormatXML(virCapsPtr caps) virBufferAddLit(&xml, " </features>\n"); } - virCPUDefFormatBuf(NULL, &xml, caps->host.cpu, " ", + virCPUDefFormatBuf(&xml, caps->host.cpu, " ", VIR_CPU_FORMAT_EMBEDED); virBufferAddLit(&xml, " </cpu>\n"); diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index fabbede..ed83188 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -31,9 +31,9 @@ #define VIR_FROM_THIS VIR_FROM_CPU -#define virCPUReportError(conn, code, fmt...) \ - virReportErrorHelper(conn, VIR_FROM_CPU, code, __FILE__, \ - __FUNCTION__, __LINE__, fmt) +#define virCPUReportError(code, fmt...) \ + virReportErrorHelper(NULL, VIR_FROM_CPU, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) VIR_ENUM_IMPL(virCPUMatch, VIR_CPU_MATCH_LAST, "minimum", @@ -69,8 +69,7 @@ virCPUDefFree(virCPUDefPtr def) #ifndef PROXY virCPUDefPtr -virCPUDefParseXML(virConnectPtr conn, - const xmlNodePtr node, +virCPUDefParseXML(const xmlNodePtr node, xmlXPathContextPtr ctxt, enum virCPUType mode) { @@ -97,7 +96,7 @@ virCPUDefParseXML(virConnectPtr conn, if (!match) { if (virXPathBoolean("boolean(./model)", ctxt)) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing match attribute for CPU specification")); goto error; } @@ -107,7 +106,7 @@ virCPUDefParseXML(virConnectPtr conn, VIR_FREE(match); if (def->match < 0) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid match attribute for CPU specification")); goto error; } @@ -117,7 +116,7 @@ virCPUDefParseXML(virConnectPtr conn, if (def->type == VIR_CPU_TYPE_HOST) { def->arch = virXPathString("string(./arch[1])", ctxt); if (!def->arch) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing CPU architecture")); goto error; } @@ -125,7 +124,7 @@ virCPUDefParseXML(virConnectPtr conn, if (!(def->model = virXPathString("string(./model[1])", ctxt)) && def->type == VIR_CPU_TYPE_HOST) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing CPU model name")); goto error; } @@ -137,7 +136,7 @@ virCPUDefParseXML(virConnectPtr conn, ret = virXPathULong("string(./topology[1]/@sockets)", ctxt, &ul); if (ret < 0) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing 'sockets' attribute in CPU topology")); goto error; } @@ -146,7 +145,7 @@ virCPUDefParseXML(virConnectPtr conn, ret = virXPathULong("string(./topology[1]/@cores)", ctxt, &ul); if (ret < 0) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing 'cores' attribute in CPU topology")); goto error; } @@ -155,14 +154,14 @@ virCPUDefParseXML(virConnectPtr conn, ret = virXPathULong("string(./topology[1]/@threads)", ctxt, &ul); if (ret < 0) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing 'threads' attribute in CPU topology")); goto error; } def->threads = (unsigned int) ul; if (!def->sockets || !def->cores || !def->threads) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid CPU topology")); goto error; } @@ -174,7 +173,7 @@ virCPUDefParseXML(virConnectPtr conn, if (n > 0) { if (!def->model) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Non-empty feature list specified without CPU model")); goto error; } @@ -197,7 +196,7 @@ virCPUDefParseXML(virConnectPtr conn, VIR_FREE(strpolicy); if (policy < 0) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid CPU feature policy")); goto error; } @@ -207,14 +206,14 @@ virCPUDefParseXML(virConnectPtr conn, if (!(name = virXMLPropString(nodes[i], "name")) || *name == 0) { VIR_FREE(name); - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid CPU feature name")); goto error; } for (j = 0 ; j < i ; j++) { if (STREQ(name, def->features[j].name)) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("CPU feature `%s' specified more than once"), name); VIR_FREE(name); @@ -243,14 +242,13 @@ error: char * -virCPUDefFormat(virConnectPtr conn, - virCPUDefPtr def, +virCPUDefFormat(virCPUDefPtr def, const char *indent, int flags) { virBuffer buf = VIR_BUFFER_INITIALIZER; - if (virCPUDefFormatBuf(conn, &buf, def, indent, flags) < 0) + if (virCPUDefFormatBuf(&buf, def, indent, flags) < 0) goto cleanup; if (virBufferError(&buf)) @@ -267,8 +265,7 @@ cleanup: int -virCPUDefFormatBuf(virConnectPtr conn, - virBufferPtr buf, +virCPUDefFormatBuf(virBufferPtr buf, virCPUDefPtr def, const char *indent, int flags) @@ -282,7 +279,7 @@ virCPUDefFormatBuf(virConnectPtr conn, indent = ""; if (!def->model && def->nfeatures) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Non-empty feature list specified without CPU model")); return -1; } @@ -291,7 +288,7 @@ virCPUDefFormatBuf(virConnectPtr conn, if (def->type == VIR_CPU_TYPE_GUEST && def->model) { const char *match; if (!(match = virCPUMatchTypeToString(def->match))) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected CPU match policy %d"), def->match); return -1; } @@ -320,7 +317,7 @@ virCPUDefFormatBuf(virConnectPtr conn, virCPUFeatureDefPtr feature = def->features + i; if (!feature->name) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing CPU feature name")); return -1; } @@ -330,7 +327,7 @@ virCPUDefFormatBuf(virConnectPtr conn, policy = virCPUFeaturePolicyTypeToString(feature->policy); if (!policy) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected CPU feature policy %d"), feature->policy); return -1; } @@ -351,8 +348,7 @@ virCPUDefFormatBuf(virConnectPtr conn, int -virCPUDefAddFeature(virConnectPtr conn, - virCPUDefPtr def, +virCPUDefAddFeature(virCPUDefPtr def, const char *name, int policy) { @@ -360,7 +356,7 @@ virCPUDefAddFeature(virConnectPtr conn, for (i = 0 ; i < def->nfeatures ; i++) { if (STREQ(name, def->features[i].name)) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("CPU feature `%s' specified more than once"), name); return -1; } diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index e95afaa..6a66959 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -85,8 +85,7 @@ virCPUDefFree(virCPUDefPtr def); #ifndef PROXY virCPUDefPtr -virCPUDefParseXML(virConnectPtr conn, - const xmlNodePtr node, +virCPUDefParseXML(const xmlNodePtr node, xmlXPathContextPtr ctxt, enum virCPUType mode); #endif @@ -98,21 +97,18 @@ enum virCPUFormatFlags { char * -virCPUDefFormat(virConnectPtr conn, - virCPUDefPtr def, +virCPUDefFormat(virCPUDefPtr def, const char *indent, int flags); int -virCPUDefFormatBuf(virConnectPtr conn, - virBufferPtr buf, +virCPUDefFormatBuf(virBufferPtr buf, virCPUDefPtr def, const char *indent, int flags); int -virCPUDefAddFeature(virConnectPtr conn, - virCPUDefPtr cpu, +virCPUDefAddFeature(virCPUDefPtr cpu, const char *name, int policy); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 101be4e..b8f82ab 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3928,7 +3928,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if ((node = virXPathNode("./cpu[1]", ctxt)) != NULL) { xmlNodePtr oldnode = ctxt->node; ctxt->node = node; - def->cpu = virCPUDefParseXML(NULL, node, ctxt, VIR_CPU_TYPE_GUEST); + def->cpu = virCPUDefParseXML(node, ctxt, VIR_CPU_TYPE_GUEST); ctxt->node = oldnode; if (def->cpu == NULL) @@ -5341,7 +5341,7 @@ char *virDomainDefFormat(virDomainDefPtr def, virBufferAddLit(&buf, " </features>\n"); } - if (virCPUDefFormatBuf(NULL, &buf, def->cpu, " ", 0) < 0) + if (virCPUDefFormatBuf(&buf, def->cpu, " ", 0) < 0) goto cleanup; virBufferVSprintf(&buf, " <clock offset='%s'/>\n", diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 5162d95..ae8d37d 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -40,14 +40,13 @@ static struct cpuArchDriver *drivers[] = { static struct cpuArchDriver * -cpuGetSubDriver(virConnectPtr conn, - const char *arch) +cpuGetSubDriver(const char *arch) { unsigned int i; unsigned int j; if (arch == NULL) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("undefined hardware architecture")); return NULL; } @@ -65,8 +64,7 @@ cpuGetSubDriver(virConnectPtr conn, virCPUCompareResult -cpuCompareXML(virConnectPtr conn, - virCPUDefPtr host, +cpuCompareXML(virCPUDefPtr host, const char *xml) { xmlDocPtr doc = NULL; @@ -83,11 +81,11 @@ cpuCompareXML(virConnectPtr conn, ctxt->node = xmlDocGetRootElement(doc); - cpu = virCPUDefParseXML(conn, ctxt->node, ctxt, VIR_CPU_TYPE_AUTO); + cpu = virCPUDefParseXML(ctxt->node, ctxt, VIR_CPU_TYPE_AUTO); if (cpu == NULL) goto cleanup; - ret = cpuCompare(conn, host, cpu); + ret = cpuCompare(host, cpu); cleanup: virCPUDefFree(cpu); @@ -99,17 +97,16 @@ cleanup: virCPUCompareResult -cpuCompare(virConnectPtr conn, - virCPUDefPtr host, +cpuCompare(virCPUDefPtr host, virCPUDefPtr cpu) { struct cpuArchDriver *driver; - if ((driver = cpuGetSubDriver(conn, host->arch)) == NULL) + if ((driver = cpuGetSubDriver(host->arch)) == NULL) return VIR_CPU_COMPARE_ERROR; if (driver->compare == NULL) { - virCPUReportError(conn, VIR_ERR_NO_SUPPORT, + virCPUReportError(VIR_ERR_NO_SUPPORT, _("cannot compare CPUs of %s architecture"), host->arch); return VIR_CPU_COMPARE_ERROR; @@ -120,8 +117,7 @@ cpuCompare(virConnectPtr conn, int -cpuDecode(virConnectPtr conn, - virCPUDefPtr cpu, +cpuDecode(virCPUDefPtr cpu, const union cpuData *data, unsigned int nmodels, const char **models) @@ -129,22 +125,22 @@ cpuDecode(virConnectPtr conn, struct cpuArchDriver *driver; if (models == NULL && nmodels != 0) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nonzero nmodels doesn't match with NULL models")); return -1; } if (cpu == NULL) { - virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid CPU definition")); return -1; } - if ((driver = cpuGetSubDriver(conn, cpu->arch)) == NULL) + if ((driver = cpuGetSubDriver(cpu->arch)) == NULL) return -1; if (driver->decode == NULL) { - virCPUReportError(conn, VIR_ERR_NO_SUPPORT, + virCPUReportError(VIR_ERR_NO_SUPPORT, _("cannot decode CPU data for %s architecture"), cpu->arch); return -1; @@ -155,8 +151,7 @@ cpuDecode(virConnectPtr conn, int -cpuEncode(virConnectPtr conn, - const char *arch, +cpuEncode(const char *arch, const virCPUDefPtr cpu, union cpuData **forced, union cpuData **required, @@ -166,11 +161,11 @@ cpuEncode(virConnectPtr conn, { struct cpuArchDriver *driver; - if ((driver = cpuGetSubDriver(conn, arch)) == NULL) + if ((driver = cpuGetSubDriver(arch)) == NULL) return -1; if (driver->encode == NULL) { - virCPUReportError(conn, VIR_ERR_NO_SUPPORT, + virCPUReportError(VIR_ERR_NO_SUPPORT, _("cannot encode CPU data for %s architecture"), arch); return -1; @@ -182,8 +177,7 @@ cpuEncode(virConnectPtr conn, void -cpuDataFree(virConnectPtr conn, - const char *arch, +cpuDataFree(const char *arch, union cpuData *data) { struct cpuArchDriver *driver; @@ -191,11 +185,11 @@ cpuDataFree(virConnectPtr conn, if (data == NULL) return; - if ((driver = cpuGetSubDriver(conn, arch)) == NULL) + if ((driver = cpuGetSubDriver(arch)) == NULL) return; if (driver->free == NULL) { - virCPUReportError(conn, VIR_ERR_NO_SUPPORT, + virCPUReportError(VIR_ERR_NO_SUPPORT, _("cannot free CPU data for %s architecture"), arch); return; @@ -206,16 +200,15 @@ cpuDataFree(virConnectPtr conn, union cpuData * -cpuNodeData(virConnectPtr conn, - const char *arch) +cpuNodeData(const char *arch) { struct cpuArchDriver *driver; - if ((driver = cpuGetSubDriver(conn, arch)) == NULL) + if ((driver = cpuGetSubDriver(arch)) == NULL) return NULL; if (driver->nodeData == NULL) { - virCPUReportError(conn, VIR_ERR_NO_SUPPORT, + virCPUReportError(VIR_ERR_NO_SUPPORT, _("cannot get node CPU data for %s architecture"), arch); return NULL; @@ -226,18 +219,17 @@ cpuNodeData(virConnectPtr conn, virCPUCompareResult -cpuGuestData(virConnectPtr conn, - virCPUDefPtr host, +cpuGuestData(virCPUDefPtr host, virCPUDefPtr guest, union cpuData **data) { struct cpuArchDriver *driver; - if ((driver = cpuGetSubDriver(conn, host->arch)) == NULL) + if ((driver = cpuGetSubDriver(host->arch)) == NULL) return VIR_CPU_COMPARE_ERROR; if (driver->guestData == NULL) { - virCPUReportError(conn, VIR_ERR_NO_SUPPORT, + virCPUReportError(VIR_ERR_NO_SUPPORT, _("cannot compute guest CPU data for %s architecture"), host->arch); return VIR_CPU_COMPARE_ERROR; diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 5b1636d..1e04993 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -30,9 +30,9 @@ #include "cpu_x86_data.h" -#define virCPUReportError(conn, code, fmt...) \ - virReportErrorHelper(conn, VIR_FROM_CPU, code, __FILE__, \ - __FUNCTION__, __LINE__, fmt) +#define virCPUReportError(code, fmt...) \ + virReportErrorHelper(NULL, VIR_FROM_CPU, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) union cpuData { @@ -85,25 +85,21 @@ struct cpuArchDriver { extern virCPUCompareResult -cpuCompareXML(virConnectPtr conn, - virCPUDefPtr host, +cpuCompareXML(virCPUDefPtr host, const char *xml); extern virCPUCompareResult -cpuCompare (virConnectPtr conn, - virCPUDefPtr host, +cpuCompare (virCPUDefPtr host, virCPUDefPtr cpu); extern int -cpuDecode (virConnectPtr conn, - virCPUDefPtr cpu, +cpuDecode (virCPUDefPtr cpu, const union cpuData *data, unsigned int nmodels, const char **models); extern int -cpuEncode (virConnectPtr conn, - const char *arch, +cpuEncode (const char *arch, const virCPUDefPtr cpu, union cpuData **forced, union cpuData **required, @@ -112,17 +108,14 @@ cpuEncode (virConnectPtr conn, union cpuData **forbidden); extern void -cpuDataFree (virConnectPtr conn, - const char *arch, +cpuDataFree (const char *arch, union cpuData *data); extern union cpuData * -cpuNodeData (virConnectPtr conn, - const char *arch); +cpuNodeData (const char *arch); extern virCPUCompareResult -cpuGuestData(virConnectPtr conn, - virCPUDefPtr host, +cpuGuestData(virCPUDefPtr host, virCPUDefPtr guest, union cpuData **data); diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index b63e2eb..5fb88e0 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -78,13 +78,13 @@ int cpuMapLoad(const char *arch, int ret = -1; if (arch == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("undefined hardware architecture")); return -1; } if ((xml = xmlParseFile(CPUMAPFILE)) == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse CPU map file: %s"), CPUMAPFILE); goto cleanup; @@ -102,14 +102,14 @@ int cpuMapLoad(const char *arch, ctxt->node = xmlDocGetRootElement(xml); if ((ctxt->node = virXPathNode(xpath, ctxt)) == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find CPU map for %s architecture"), arch); goto cleanup; } if ((feature_cb && load(ctxt, "feature", feature_cb, feature_data) < 0) || (model_cb && load(ctxt, "model", model_cb, model_data) < 0)) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse CPU map for %s architecture"), arch); goto cleanup; } diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 93bd675..7ae7fbf 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -265,7 +265,7 @@ x86DataToCPU(const union cpuData *data, if ((cpuid = x86DataCpuid(tmp, feature->cpuid[i].function)) && x86cpuidMatchMasked(cpuid, feature->cpuid + i)) { x86cpuidClearBits(cpuid, feature->cpuid + i); - if (virCPUDefAddFeature(NULL, cpu, feature->name, + if (virCPUDefAddFeature(cpu, feature->name, VIR_CPU_FEATURE_REQUIRE) < 0) goto error; } @@ -334,13 +334,13 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, feature->name = virXPathString("string(@name)", ctxt); if (feature->name == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing CPU feature name")); goto ignore; } if (x86FeatureFind(map, feature->name)) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("CPU feature %s already defined"), feature->name); goto ignore; } @@ -370,7 +370,7 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, if (ret_fun < 0 || ret_eax == -2 || ret_ebx == -2 || ret_ecx == -2 || ret_edx == -2) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid cpuid[%d] in %s feature"), i, feature->name); goto ignore; } @@ -539,7 +539,7 @@ x86ModelFromCPU(const virCPUDefPtr cpu, if (cpu->type == VIR_CPU_TYPE_HOST || policy == VIR_CPU_FEATURE_REQUIRE) { if ((model = x86ModelFind(map, cpu->model)) == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown CPU model %s"), cpu->model); goto error; } @@ -558,7 +558,7 @@ x86ModelFromCPU(const virCPUDefPtr cpu, continue; if ((feature = x86FeatureFind(map, cpu->features[i].name)) == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown CPU feature %s"), cpu->features[i].name); goto error; } @@ -647,7 +647,7 @@ x86ModelLoad(xmlXPathContextPtr ctxt, model->name = virXPathString("string(@name)", ctxt); if (model->name == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing CPU model name")); goto ignore; } @@ -658,14 +658,14 @@ x86ModelLoad(xmlXPathContextPtr ctxt, name = virXPathString("string(./model/@name)", ctxt); if (name == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("Missing ancestor's name in CPU model %s"), model->name); goto ignore; } if ((ancestor = x86ModelFind(map, name)) == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("Ancestor model %s not found for CPU model %s"), name, model->name); VIR_FREE(name); @@ -691,13 +691,13 @@ x86ModelLoad(xmlXPathContextPtr ctxt, char *name; if ((name = virXMLPropString(nodes[i], "name")) == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("Missing feature name for CPU model %s"), model->name); goto ignore; } if ((feature = x86FeatureFind(map, name)) == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("Feature %s required by CPU model %s not found"), name, model->name); VIR_FREE(name); @@ -993,7 +993,7 @@ x86Decode(virCPUDefPtr cpu, } if (cpuModel == NULL) { - virCPUReportError(NULL, VIR_ERR_INTERNAL_ERROR, + virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot find suitable CPU model for given data")); goto out; } diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index beb4386..3988582 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1015,8 +1015,8 @@ qemudCapsInitCPU(virCapsPtr caps, cpu->cores = nodeinfo.cores; cpu->threads = nodeinfo.threads; - if (!(data = cpuNodeData(NULL, arch)) - || cpuDecode(NULL, cpu, data, 0, NULL) < 0) + if (!(data = cpuNodeData(arch)) + || cpuDecode(cpu, data, 0, NULL) < 0) goto error; caps->host.cpu = cpu; @@ -1024,7 +1024,7 @@ qemudCapsInitCPU(virCapsPtr caps, ret = 0; cleanup: - cpuDataFree(NULL, arch, data); + cpuDataFree(arch, data); return ret; @@ -2943,7 +2943,7 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver, if (ncpus > 0 && host) { virCPUCompareResult cmp; - cmp = cpuGuestData(NULL, host, def->cpu, &data); + cmp = cpuGuestData(host, def->cpu, &data); switch (cmp) { case VIR_CPU_COMPARE_INCOMPATIBLE: qemuReportError(VIR_ERR_INTERNAL_ERROR, @@ -2959,7 +2959,7 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver, if (VIR_ALLOC(guest) < 0 || !(guest->arch = strdup(ut->machine))) goto no_memory; - if (cpuDecode(NULL, guest, data, ncpus, cpus) < 0) + if (cpuDecode(guest, data, ncpus, cpus) < 0) goto cleanup; virBufferVSprintf(&buf, "%s", guest->model); @@ -2995,7 +2995,7 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver, cleanup: virCPUDefFree(guest); - cpuDataFree(NULL, ut->machine, data); + cpuDataFree(ut->machine, data); if (cpus) { for (i = 0; i < ncpus; i++) @@ -5026,7 +5026,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom, else feature = strdup(p); - ret = virCPUDefAddFeature(NULL, cpu, feature, policy); + ret = virCPUDefAddFeature(cpu, feature, policy); VIR_FREE(feature); if (ret < 0) goto error; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1b3b271..b009dd3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8495,7 +8495,7 @@ qemuCPUCompare(virConnectPtr conn, "%s", _("cannot get host CPU capabilities")); } else - ret = cpuCompareXML(conn, driver->caps->host.cpu, xmlDesc); + ret = cpuCompareXML(driver->caps->host.cpu, xmlDesc); qemuDriverUnlock(driver); -- 1.6.6

On Wed, Feb 10, 2010 at 01:36:23PM +0000, Daniel P. Berrange wrote:
The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in cpu_conf.{h,c} and update all callers to match --- src/conf/capabilities.c | 2 +- src/conf/cpu_conf.c | 54 ++++++++++++++++++++----------------------- src/conf/cpu_conf.h | 12 +++------ src/conf/domain_conf.c | 4 +- src/cpu/cpu.c | 58 ++++++++++++++++++++-------------------------- src/cpu/cpu.h | 27 ++++++++------------- src/cpu/cpu_map.c | 8 +++--- src/cpu/cpu_x86.c | 24 +++++++++--------- src/qemu/qemu_conf.c | 14 +++++----- src/qemu/qemu_driver.c | 2 +- 10 files changed, 91 insertions(+), 114 deletions(-)
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in interface_conf.{h,c} and update all callers to match --- src/conf/interface_conf.c | 259 ++++++++++++++++++++---------------------- src/conf/interface_conf.h | 15 +-- src/interface/netcf_driver.c | 8 +- src/test/test_driver.c | 16 ++-- tests/interfacexml2xmltest.c | 4 +- 5 files changed, 141 insertions(+), 161 deletions(-) diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index c111385..a0d2dfa 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -40,15 +40,14 @@ VIR_ENUM_IMPL(virInterface, "ethernet", "bridge", "bond", "vlan" ) static virInterfaceDefPtr -virInterfaceDefParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, int parentIfType); +virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType); static int -virInterfaceDefDevFormat(virConnectPtr conn, virBufferPtr buf, +virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDefPtr def, int level); -#define virInterfaceReportError(conn, code, fmt...) \ - virReportErrorHelper(conn, VIR_FROM_INTERFACE, code, __FILE__, \ - __FUNCTION__, __LINE__, fmt) +#define virInterfaceReportError(code, fmt...) \ + virReportErrorHelper(NULL, VIR_FROM_INTERFACE, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) static void virInterfaceIpDefFree(virInterfaceIpDefPtr def) { @@ -118,14 +117,14 @@ void virInterfaceDefFree(virInterfaceDefPtr def) } static int -virInterfaceDefParseName(virConnectPtr conn, virInterfaceDefPtr def, +virInterfaceDefParseName(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { char *tmp; tmp = virXPathString("string(./@name)", ctxt); if (tmp == NULL) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("interface has no name")); + virInterfaceReportError(VIR_ERR_XML_ERROR, + "%s", _("interface has no name")); return(-1); } def->name = tmp; @@ -133,14 +132,14 @@ virInterfaceDefParseName(virConnectPtr conn, virInterfaceDefPtr def, } static int -virInterfaceDefParseMtu(virConnectPtr conn, virInterfaceDefPtr def, +virInterfaceDefParseMtu(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { unsigned long mtu; int ret; ret = virXPathULong("string(./mtu/@size)", ctxt, &mtu); if ((ret == -2) || ((ret == 0) && (mtu > 100000))) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("interface mtu value is improper")); return(-1); } else if (ret == 0) { @@ -150,7 +149,7 @@ virInterfaceDefParseMtu(virConnectPtr conn, virInterfaceDefPtr def, } static int -virInterfaceDefParseStartMode(virConnectPtr conn, virInterfaceDefPtr def, +virInterfaceDefParseStartMode(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { char *tmp; @@ -164,7 +163,7 @@ virInterfaceDefParseStartMode(virConnectPtr conn, virInterfaceDefPtr def, else if (STREQ(tmp, "none")) def->startmode = VIR_INTERFACE_START_NONE; else { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, _("unknown interface startmode %s"), tmp); VIR_FREE(tmp); return(-1); @@ -174,7 +173,7 @@ virInterfaceDefParseStartMode(virConnectPtr conn, virInterfaceDefPtr def, } static int -virInterfaceDefParseBondMode(virConnectPtr conn, xmlXPathContextPtr ctxt) { +virInterfaceDefParseBondMode(xmlXPathContextPtr ctxt) { char *tmp; int ret = 0; @@ -196,7 +195,7 @@ virInterfaceDefParseBondMode(virConnectPtr conn, xmlXPathContextPtr ctxt) { else if (STREQ(tmp, "balance-alb")) ret = VIR_INTERFACE_BOND_BALALB; else { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, _("unknown bonding mode %s"), tmp); ret = -1; } @@ -205,7 +204,7 @@ virInterfaceDefParseBondMode(virConnectPtr conn, xmlXPathContextPtr ctxt) { } static int -virInterfaceDefParseBondMiiCarrier(virConnectPtr conn, xmlXPathContextPtr ctxt) { +virInterfaceDefParseBondMiiCarrier(xmlXPathContextPtr ctxt) { char *tmp; int ret = 0; @@ -217,7 +216,7 @@ virInterfaceDefParseBondMiiCarrier(virConnectPtr conn, xmlXPathContextPtr ctxt) else if (STREQ(tmp, "netif")) ret = VIR_INTERFACE_BOND_MII_NETIF; else { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, _("unknown mii bonding carrier %s"), tmp); ret = -1; } @@ -226,7 +225,7 @@ virInterfaceDefParseBondMiiCarrier(virConnectPtr conn, xmlXPathContextPtr ctxt) } static int -virInterfaceDefParseBondArpValid(virConnectPtr conn, xmlXPathContextPtr ctxt) { +virInterfaceDefParseBondArpValid(xmlXPathContextPtr ctxt) { char *tmp; int ret = 0; @@ -240,7 +239,7 @@ virInterfaceDefParseBondArpValid(virConnectPtr conn, xmlXPathContextPtr ctxt) { else if (STREQ(tmp, "all")) ret = VIR_INTERFACE_BOND_ARP_ALL; else { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, _("unknown arp bonding validate %s"), tmp); ret = -1; } @@ -249,7 +248,7 @@ virInterfaceDefParseBondArpValid(virConnectPtr conn, xmlXPathContextPtr ctxt) { } static int -virInterfaceDefParseDhcp(virConnectPtr conn, virInterfaceProtocolDefPtr def, +virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def, xmlNodePtr dhcp, xmlXPathContextPtr ctxt) { xmlNodePtr save; char *tmp; @@ -266,7 +265,7 @@ virInterfaceDefParseDhcp(virConnectPtr conn, virInterfaceProtocolDefPtr def, else if (STREQ(tmp, "no")) def->peerdns = 0; else { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, _("unknown dhcp peerdns value %s"), tmp); ret = -1; } @@ -279,7 +278,7 @@ virInterfaceDefParseDhcp(virConnectPtr conn, virInterfaceProtocolDefPtr def, } static int -virInterfaceDefParseIp(virConnectPtr conn, virInterfaceIpDefPtr def, +virInterfaceDefParseIp(virInterfaceIpDefPtr def, xmlXPathContextPtr ctxt) { int ret = 0; char *tmp; @@ -292,7 +291,7 @@ virInterfaceDefParseIp(virConnectPtr conn, virInterfaceIpDefPtr def, if (ret == 0) def->prefix = (int) l; else if (ret == -2) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("Invalid ip address prefix value")); return(-1); } @@ -302,7 +301,7 @@ virInterfaceDefParseIp(virConnectPtr conn, virInterfaceIpDefPtr def, } static int -virInterfaceDefParseProtoIPv4(virConnectPtr conn, virInterfaceProtocolDefPtr def, +virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr dhcp; xmlNodePtr *ipNodes = NULL; @@ -314,7 +313,7 @@ virInterfaceDefParseProtoIPv4(virConnectPtr conn, virInterfaceProtocolDefPtr def dhcp = virXPathNode("./dhcp", ctxt); if (dhcp != NULL) { - ret = virInterfaceDefParseDhcp(conn, def, dhcp, ctxt); + ret = virInterfaceDefParseDhcp(def, dhcp, ctxt); if (ret != 0) return(ret); } @@ -341,7 +340,7 @@ virInterfaceDefParseProtoIPv4(virConnectPtr conn, virInterfaceProtocolDefPtr def } ctxt->node = ipNodes[ii]; - ret = virInterfaceDefParseIp(conn, ip, ctxt); + ret = virInterfaceDefParseIp(ip, ctxt); if (ret != 0) { virInterfaceIpDefFree(ip); goto error; @@ -357,7 +356,7 @@ error: } static int -virInterfaceDefParseProtoIPv6(virConnectPtr conn, virInterfaceProtocolDefPtr def, +virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr dhcp, autoconf; xmlNodePtr *ipNodes = NULL; @@ -373,7 +372,7 @@ virInterfaceDefParseProtoIPv6(virConnectPtr conn, virInterfaceProtocolDefPtr def dhcp = virXPathNode("./dhcp", ctxt); if (dhcp != NULL) { - ret = virInterfaceDefParseDhcp(conn, def, dhcp, ctxt); + ret = virInterfaceDefParseDhcp(def, dhcp, ctxt); if (ret != 0) return(ret); } @@ -400,7 +399,7 @@ virInterfaceDefParseProtoIPv6(virConnectPtr conn, virInterfaceProtocolDefPtr def } ctxt->node = ipNodes[ii]; - ret = virInterfaceDefParseIp(conn, ip, ctxt); + ret = virInterfaceDefParseIp(ip, ctxt); if (ret != 0) { virInterfaceIpDefFree(ip); goto error; @@ -416,7 +415,7 @@ error: } static int -virInterfaceDefParseIfAdressing(virConnectPtr conn, virInterfaceDefPtr def, +virInterfaceDefParseIfAdressing(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr save; xmlNodePtr *protoNodes = NULL; @@ -449,26 +448,26 @@ virInterfaceDefParseIfAdressing(virConnectPtr conn, virInterfaceDefPtr def, ctxt->node = protoNodes[pp]; tmp = virXPathString("string(./@family)", ctxt); if (tmp == NULL) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("protocol misses the family attribute")); virInterfaceProtocolDefFree(proto); goto error; } proto->family = tmp; if (STREQ(tmp, "ipv4")) { - ret = virInterfaceDefParseProtoIPv4(conn, proto, ctxt); + ret = virInterfaceDefParseProtoIPv4(proto, ctxt); if (ret != 0) { virInterfaceProtocolDefFree(proto); goto error; } } else if (STREQ(tmp, "ipv6")) { - ret = virInterfaceDefParseProtoIPv6(conn, proto, ctxt); + ret = virInterfaceDefParseProtoIPv6(proto, ctxt); if (ret != 0) { virInterfaceProtocolDefFree(proto); goto error; } } else { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, _("unsupported protocol family '%s'"), tmp); virInterfaceProtocolDefFree(proto); goto error; @@ -486,7 +485,7 @@ error: } static int -virInterfaceDefParseBridge(virConnectPtr conn, virInterfaceDefPtr def, +virInterfaceDefParseBridge(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr *interfaces = NULL; xmlNodePtr bridge; @@ -497,7 +496,7 @@ virInterfaceDefParseBridge(virConnectPtr conn, virInterfaceDefPtr def, bridge = ctxt->node; nbItf = virXPathNodeSet("./interface", ctxt, &interfaces); if (nbItf < 0) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bridge interfaces")); ret = -1; goto error; @@ -512,7 +511,7 @@ virInterfaceDefParseBridge(virConnectPtr conn, virInterfaceDefPtr def, for (i = 0; i < nbItf;i++) { ctxt->node = interfaces[i]; - itf = virInterfaceDefParseXML(conn, ctxt, VIR_INTERFACE_TYPE_BRIDGE); + itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BRIDGE); if (itf == NULL) { ret = -1; def->data.bridge.nbItf = i; @@ -529,7 +528,7 @@ error: } static int -virInterfaceDefParseBondItfs(virConnectPtr conn, virInterfaceDefPtr def, +virInterfaceDefParseBondItfs(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr *interfaces = NULL; xmlNodePtr bond = ctxt->node; @@ -539,7 +538,7 @@ virInterfaceDefParseBondItfs(virConnectPtr conn, virInterfaceDefPtr def, nbItf = virXPathNodeSet("./interface", ctxt, &interfaces); if (nbItf <= 0) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bond has no interfaces")); ret = -1; goto error; @@ -553,7 +552,7 @@ virInterfaceDefParseBondItfs(virConnectPtr conn, virInterfaceDefPtr def, for (i = 0; i < nbItf;i++) { ctxt->node = interfaces[i]; - itf = virInterfaceDefParseXML(conn, ctxt, VIR_INTERFACE_TYPE_BOND); + itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BOND); if (itf == NULL) { ret = -1; def->data.bond.nbItf = i; @@ -569,17 +568,17 @@ error: } static int -virInterfaceDefParseBond(virConnectPtr conn, virInterfaceDefPtr def, +virInterfaceDefParseBond(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr node; int ret = -1; unsigned long tmp; - def->data.bond.mode = virInterfaceDefParseBondMode(conn, ctxt); + def->data.bond.mode = virInterfaceDefParseBondMode(ctxt); if (def->data.bond.mode < 0) goto error; - ret = virInterfaceDefParseBondItfs(conn, def, ctxt); + ret = virInterfaceDefParseBondItfs(def, ctxt); if (ret != 0) goto error; @@ -589,7 +588,7 @@ virInterfaceDefParseBond(virConnectPtr conn, virInterfaceDefPtr def, ret = virXPathULong("string(./miimon/@freq)", ctxt, &tmp); if ((ret == -2) || (ret == -1)) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bond interface miimon freq missing or invalid")); goto error; } @@ -597,7 +596,7 @@ virInterfaceDefParseBond(virConnectPtr conn, virInterfaceDefPtr def, ret = virXPathULong("string(./miimon/@downdelay)", ctxt, &tmp); if (ret == -2) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bond interface miimon downdelay invalid")); goto error; } else if (ret == 0) { @@ -606,14 +605,14 @@ virInterfaceDefParseBond(virConnectPtr conn, virInterfaceDefPtr def, ret = virXPathULong("string(./miimon/@updelay)", ctxt, &tmp); if (ret == -2) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bond interface miimon updelay invalid")); goto error; } else if (ret == 0) { def->data.bond.updelay = (int) tmp; } - def->data.bond.carrier = virInterfaceDefParseBondMiiCarrier(conn, ctxt); + def->data.bond.carrier = virInterfaceDefParseBondMiiCarrier(ctxt); if (def->data.bond.carrier < 0) { ret = -1; goto error; @@ -625,7 +624,7 @@ virInterfaceDefParseBond(virConnectPtr conn, virInterfaceDefPtr def, ret = virXPathULong("string(./arpmon/@interval)", ctxt, &tmp); if ((ret == -2) || (ret == -1)) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bond interface arpmon interval missing or invalid")); goto error; } @@ -634,13 +633,13 @@ virInterfaceDefParseBond(virConnectPtr conn, virInterfaceDefPtr def, def->data.bond.target = virXPathString("string(./arpmon/@target)", ctxt); if (def->data.bond.target == NULL) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bond interface arpmon target missing")); ret = -1; goto error; } - def->data.bond.validate = virInterfaceDefParseBondArpValid(conn, ctxt); + def->data.bond.validate = virInterfaceDefParseBondArpValid(ctxt); if (def->data.bond.validate < 0) { ret = -1; goto error; @@ -651,11 +650,11 @@ error: } static int -virInterfaceDefParseVlan(virConnectPtr conn, virInterfaceDefPtr def, +virInterfaceDefParseVlan(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { def->data.vlan.tag = virXPathString("string(./@tag)", ctxt); if (def->data.vlan.tag == NULL) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("vlan interface misses the tag attribute")); return(-1); } @@ -663,7 +662,7 @@ virInterfaceDefParseVlan(virConnectPtr conn, virInterfaceDefPtr def, def->data.vlan.devname = virXPathString("string(./interface/@name)", ctxt); if (def->data.vlan.devname == NULL) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("vlan interface misses name attribute")); return(-1); } @@ -671,8 +670,7 @@ virInterfaceDefParseVlan(virConnectPtr conn, virInterfaceDefPtr def, } static virInterfaceDefPtr -virInterfaceDefParseXML(virConnectPtr conn, - xmlXPathContextPtr ctxt, int parentIfType) { +virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType) { virInterfaceDefPtr def; int type; char *tmp; @@ -681,13 +679,13 @@ virInterfaceDefParseXML(virConnectPtr conn, /* check @type */ tmp = virXPathString("string(./@type)", ctxt); if (tmp == NULL) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("interface misses the type attribute")); return(NULL); } type = virInterfaceTypeFromString(tmp); if (type == -1) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, _("unknown interface type %s"), tmp); VIR_FREE(tmp); return(NULL); @@ -708,7 +706,7 @@ virInterfaceDefParseXML(virConnectPtr conn, || (parentIfType == VIR_INTERFACE_TYPE_ETHERNET) || (parentIfType == VIR_INTERFACE_TYPE_VLAN)) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, _("interface has unsupported type '%s'"), virInterfaceTypeToString(type)); goto error; @@ -716,36 +714,36 @@ virInterfaceDefParseXML(virConnectPtr conn, def->type = type; switch (type) { case VIR_INTERFACE_TYPE_ETHERNET: - if (virInterfaceDefParseName(conn, def, ctxt) < 0) + if (virInterfaceDefParseName(def, ctxt) < 0) goto error; tmp = virXPathString("string(./mac/@address)", ctxt); if (tmp != NULL) def->mac = tmp; if (parentIfType == VIR_INTERFACE_TYPE_LAST) { /* only recognize these in toplevel bond interfaces */ - if (virInterfaceDefParseStartMode(conn, def, ctxt) < 0) + if (virInterfaceDefParseStartMode(def, ctxt) < 0) goto error; - if (virInterfaceDefParseMtu(conn, def, ctxt) < 0) + if (virInterfaceDefParseMtu(def, ctxt) < 0) goto error; - if (virInterfaceDefParseIfAdressing(conn, def, ctxt) < 0) + if (virInterfaceDefParseIfAdressing(def, ctxt) < 0) goto error; } break; case VIR_INTERFACE_TYPE_BRIDGE: { xmlNodePtr bridge; - if (virInterfaceDefParseName(conn, def, ctxt) < 0) + if (virInterfaceDefParseName(def, ctxt) < 0) goto error; - if (virInterfaceDefParseStartMode(conn, def, ctxt) < 0) + if (virInterfaceDefParseStartMode(def, ctxt) < 0) goto error; - if (virInterfaceDefParseMtu(conn, def, ctxt) < 0) + if (virInterfaceDefParseMtu(def, ctxt) < 0) goto error; - if (virInterfaceDefParseIfAdressing(conn, def, ctxt) < 0) + if (virInterfaceDefParseIfAdressing(def, ctxt) < 0) goto error; bridge = virXPathNode("./bridge[1]", ctxt); if (bridge == NULL) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bridge interface misses the bridge element")); goto error; } @@ -757,7 +755,7 @@ virInterfaceDefParseXML(virConnectPtr conn, } else if (STREQ(tmp, "off")) { def->data.bridge.stp = 0; } else { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, _("bridge interface stp should be on or off got %s"), tmp); VIR_FREE(tmp); @@ -767,32 +765,32 @@ virInterfaceDefParseXML(virConnectPtr conn, } def->data.bridge.delay = virXMLPropString(bridge, "delay"); ctxt->node = bridge; - virInterfaceDefParseBridge(conn, def, ctxt); + virInterfaceDefParseBridge(def, ctxt); break; } case VIR_INTERFACE_TYPE_BOND: { xmlNodePtr bond; - if (virInterfaceDefParseName(conn, def, ctxt) < 0) + if (virInterfaceDefParseName(def, ctxt) < 0) goto error; if (parentIfType == VIR_INTERFACE_TYPE_LAST) { /* only recognize these in toplevel bond interfaces */ - if (virInterfaceDefParseStartMode(conn, def, ctxt) < 0) + if (virInterfaceDefParseStartMode(def, ctxt) < 0) goto error; - if (virInterfaceDefParseMtu(conn, def, ctxt) < 0) + if (virInterfaceDefParseMtu(def, ctxt) < 0) goto error; - if (virInterfaceDefParseIfAdressing(conn, def, ctxt) < 0) + if (virInterfaceDefParseIfAdressing(def, ctxt) < 0) goto error; } bond = virXPathNode("./bond[1]", ctxt); if (bond == NULL) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bond interface misses the bond element")); goto error; } ctxt->node = bond; - if (virInterfaceDefParseBond(conn, def, ctxt) < 0) + if (virInterfaceDefParseBond(def, ctxt) < 0) goto error; break; } @@ -802,18 +800,18 @@ virInterfaceDefParseXML(virConnectPtr conn, tmp = virXPathString("string(./@name)", ctxt); if (tmp != NULL) def->name = tmp; - if (virInterfaceDefParseStartMode(conn, def, ctxt) < 0) + if (virInterfaceDefParseStartMode(def, ctxt) < 0) goto error; - if (virInterfaceDefParseIfAdressing(conn, def, ctxt) < 0) + if (virInterfaceDefParseIfAdressing(def, ctxt) < 0) goto error; vlan = virXPathNode("./vlan[1]", ctxt); if (vlan == NULL) { - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("vlan interface misses the vlan element")); goto error; } ctxt->node = vlan; - if (virInterfaceDefParseVlan(conn, def, ctxt) < 0) + if (virInterfaceDefParseVlan(def, ctxt) < 0) goto error; break; } @@ -829,15 +827,14 @@ error: return NULL; } -virInterfaceDefPtr virInterfaceDefParseNode(virConnectPtr conn, - xmlDocPtr xml, - xmlNodePtr root) +virInterfaceDefPtr virInterfaceDefParseNode(xmlDocPtr xml, + xmlNodePtr root) { xmlXPathContextPtr ctxt = NULL; virInterfaceDefPtr def = NULL; if (!xmlStrEqual(root->name, BAD_CAST "interface")) { - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("incorrect root element")); return NULL; } @@ -849,7 +846,7 @@ virInterfaceDefPtr virInterfaceDefParseNode(virConnectPtr conn, } ctxt->node = root; - def = virInterfaceDefParseXML(conn, ctxt, VIR_INTERFACE_TYPE_LAST); + def = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST); cleanup: xmlXPathFreeContext(ctxt); @@ -863,13 +860,10 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; if (ctxt) { - virConnectPtr conn = ctxt->_private; - - if (conn && - conn->err.code == VIR_ERR_NONE && + if (virGetLastError() == NULL && ctxt->lastError.level == XML_ERR_FATAL && ctxt->lastError.message != NULL) { - virInterfaceReportError (conn, VIR_ERR_XML_DETAIL, + virInterfaceReportError (VIR_ERR_XML_DETAIL, _("at line %d: %s"), ctxt->lastError.line, ctxt->lastError.message); @@ -877,8 +871,7 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) } } -virInterfaceDefPtr virInterfaceDefParseString(virConnectPtr conn, - const char *xmlStr) +virInterfaceDefPtr virInterfaceDefParseString(const char *xmlStr) { xmlParserCtxtPtr pctxt; xmlDocPtr xml = NULL; @@ -890,26 +883,24 @@ virInterfaceDefPtr virInterfaceDefParseString(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn; - if (conn) virResetError (&conn->err); xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "interface.xml", NULL, XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOWARNING); if (!xml) { - if (conn && conn->err.code == VIR_ERR_NONE) - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + if (virGetLastError() == NULL) + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("failed to parse xml document")); goto cleanup; } if ((root = xmlDocGetRootElement(xml)) == NULL) { - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing root element")); goto cleanup; } - def = virInterfaceDefParseNode(conn, xml, root); + def = virInterfaceDefParseNode(xml, root); cleanup: xmlFreeParserCtxt (pctxt); @@ -917,8 +908,7 @@ cleanup: return def; } -virInterfaceDefPtr virInterfaceDefParseFile(virConnectPtr conn, - const char *filename) +virInterfaceDefPtr virInterfaceDefParseFile(const char *filename) { xmlParserCtxtPtr pctxt; xmlDocPtr xml = NULL; @@ -930,26 +920,24 @@ virInterfaceDefPtr virInterfaceDefParseFile(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn; - if (conn) virResetError (&conn->err); xml = xmlCtxtReadFile (pctxt, filename, NULL, XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOWARNING); if (!xml) { - if (conn && conn->err.code == VIR_ERR_NONE) - virInterfaceReportError(conn, VIR_ERR_XML_ERROR, + if (virGetLastError() == NULL) + virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("failed to parse xml document")); goto cleanup; } if ((root = xmlDocGetRootElement(xml)) == NULL) { - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing root element")); goto cleanup; } - def = virInterfaceDefParseNode(conn, xml, root); + def = virInterfaceDefParseNode(xml, root); cleanup: xmlFreeParserCtxt (pctxt); @@ -958,7 +946,7 @@ cleanup: } static int -virInterfaceBridgeDefFormat(virConnectPtr conn, virBufferPtr buf, +virInterfaceBridgeDefFormat(virBufferPtr buf, const virInterfaceDefPtr def, int level) { int i; int ret = 0; @@ -973,7 +961,7 @@ virInterfaceBridgeDefFormat(virConnectPtr conn, virBufferPtr buf, virBufferAddLit(buf, ">\n"); for (i = 0;i < def->data.bridge.nbItf;i++) { - if (virInterfaceDefDevFormat(conn, buf, + if (virInterfaceDefDevFormat(buf, def->data.bridge.itf[i], level+2) < 0) ret = -1; } @@ -983,7 +971,7 @@ virInterfaceBridgeDefFormat(virConnectPtr conn, virBufferPtr buf, } static int -virInterfaceBondDefFormat(virConnectPtr conn, virBufferPtr buf, +virInterfaceBondDefFormat(virBufferPtr buf, const virInterfaceDefPtr def, int level) { int i; int ret = 0; @@ -1019,7 +1007,7 @@ virInterfaceBondDefFormat(virConnectPtr conn, virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } else if (def->data.bond.monit == VIR_INTERFACE_BOND_MONIT_ARP) { if (def->data.bond.target == NULL) { - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("bond arp monitoring has no target")); return(-1); } @@ -1035,7 +1023,7 @@ virInterfaceBondDefFormat(virConnectPtr conn, virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } for (i = 0;i < def->data.bond.nbItf;i++) { - if (virInterfaceDefDevFormat(conn, buf, def->data.bond.itf[i], level+2) < 0) + if (virInterfaceDefDevFormat(buf, def->data.bond.itf[i], level+2) < 0) ret = -1; } @@ -1044,10 +1032,10 @@ virInterfaceBondDefFormat(virConnectPtr conn, virBufferPtr buf, } static int -virInterfaceVlanDefFormat(virConnectPtr conn, virBufferPtr buf, +virInterfaceVlanDefFormat(virBufferPtr buf, const virInterfaceDefPtr def, int level) { if (def->data.vlan.tag == NULL) { - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("vlan misses the tag name")); return(-1); } @@ -1065,8 +1053,7 @@ virInterfaceVlanDefFormat(virConnectPtr conn, virBufferPtr buf, } static int -virInterfaceProtocolDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED, - virBufferPtr buf, const virInterfaceDefPtr def, +virInterfaceProtocolDefFormat(virBufferPtr buf, const virInterfaceDefPtr def, int level) { int pp, ii; @@ -1113,7 +1100,7 @@ virInterfaceProtocolDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED, } static int -virInterfaceStartmodeDefFormat(virConnectPtr conn, virBufferPtr buf, +virInterfaceStartmodeDefFormat(virBufferPtr buf, enum virInterfaceStartMode startmode, int level) { const char *mode; @@ -1130,7 +1117,7 @@ virInterfaceStartmodeDefFormat(virConnectPtr conn, virBufferPtr buf, mode = "hotplug"; break; default: - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("virInterfaceDefFormat unknown startmode")); return -1; } @@ -1139,24 +1126,24 @@ virInterfaceStartmodeDefFormat(virConnectPtr conn, virBufferPtr buf, } static int -virInterfaceDefDevFormat(virConnectPtr conn, virBufferPtr buf, +virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDefPtr def, int level) { const char *type = NULL; if (def == NULL) { - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("virInterfaceDefFormat NULL def")); goto cleanup; } if ((def->name == NULL) && (def->type != VIR_INTERFACE_TYPE_VLAN)) { - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("virInterfaceDefFormat missing interface name")); goto cleanup; } if (!(type = virInterfaceTypeToString(def->type))) { - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected interface type %d"), def->type); goto cleanup; } @@ -1168,41 +1155,41 @@ virInterfaceDefDevFormat(virConnectPtr conn, virBufferPtr buf, switch (def->type) { case VIR_INTERFACE_TYPE_ETHERNET: - virInterfaceStartmodeDefFormat(conn, buf, def->startmode, level); + virInterfaceStartmodeDefFormat(buf, def->startmode, level); if (def->mac != NULL) virBufferVSprintf(buf, "%*s <mac address='%s'/>\n", level*2, "", def->mac); if (def->mtu != 0) virBufferVSprintf(buf, "%*s <mtu size='%d'/>\n", level*2, "", def->mtu); - virInterfaceProtocolDefFormat(conn, buf, def, level); + virInterfaceProtocolDefFormat(buf, def, level); break; case VIR_INTERFACE_TYPE_BRIDGE: - virInterfaceStartmodeDefFormat(conn, buf, def->startmode, level); + virInterfaceStartmodeDefFormat(buf, def->startmode, level); if (def->mtu != 0) virBufferVSprintf(buf, "%*s <mtu size='%d'/>\n", level*2, "", def->mtu); - virInterfaceProtocolDefFormat(conn, buf, def, level); - virInterfaceBridgeDefFormat(conn, buf, def, level); + virInterfaceProtocolDefFormat(buf, def, level); + virInterfaceBridgeDefFormat(buf, def, level); break; case VIR_INTERFACE_TYPE_BOND: - virInterfaceStartmodeDefFormat(conn, buf, def->startmode, level); + virInterfaceStartmodeDefFormat(buf, def->startmode, level); if (def->mtu != 0) virBufferVSprintf(buf, "%*s <mtu size='%d'/>\n", level*2, "", def->mtu); - virInterfaceProtocolDefFormat(conn, buf, def, level); - virInterfaceBondDefFormat(conn, buf, def, level); + virInterfaceProtocolDefFormat(buf, def, level); + virInterfaceBondDefFormat(buf, def, level); break; case VIR_INTERFACE_TYPE_VLAN: - virInterfaceStartmodeDefFormat(conn, buf, def->startmode, level); + virInterfaceStartmodeDefFormat(buf, def->startmode, level); if (def->mac != NULL) virBufferVSprintf(buf, "%*s <mac address='%s'/>\n", level*2, "", def->mac); if (def->mtu != 0) virBufferVSprintf(buf, "%*s <mtu size='%d'/>\n", level*2, "", def->mtu); - virInterfaceProtocolDefFormat(conn, buf, def, level); - virInterfaceVlanDefFormat(conn, buf, def, level); + virInterfaceProtocolDefFormat(buf, def, level); + virInterfaceVlanDefFormat(buf, def, level); break; } @@ -1217,12 +1204,11 @@ cleanup: return -1; } -char *virInterfaceDefFormat(virConnectPtr conn, - const virInterfaceDefPtr def) +char *virInterfaceDefFormat(const virInterfaceDefPtr def) { virBuffer buf = VIR_BUFFER_INITIALIZER; - if (virInterfaceDefDevFormat(conn, &buf, def, 0) < 0) { + if (virInterfaceDefDevFormat(&buf, def, 0) < 0) { virBufferFreeAndReset(&buf); return NULL; } @@ -1304,8 +1290,7 @@ void virInterfaceObjListFree(virInterfaceObjListPtr interfaces) interfaces->count = 0; } -virInterfaceObjPtr virInterfaceAssignDef(virConnectPtr conn, - virInterfaceObjListPtr interfaces, +virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces, const virInterfaceDefPtr def) { virInterfaceObjPtr iface; @@ -1323,7 +1308,7 @@ virInterfaceObjPtr virInterfaceAssignDef(virConnectPtr conn, return NULL; } if (virMutexInit(&iface->lock) < 0) { - virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR, + virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); VIR_FREE(iface); return NULL; diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h index 8a18a03..bd479a7 100644 --- a/src/conf/interface_conf.h +++ b/src/conf/interface_conf.h @@ -193,22 +193,17 @@ void virInterfaceDefFree(virInterfaceDefPtr def); void virInterfaceObjFree(virInterfaceObjPtr iface); void virInterfaceObjListFree(virInterfaceObjListPtr vms); -virInterfaceObjPtr virInterfaceAssignDef(virConnectPtr conn, - virInterfaceObjListPtr interfaces, +virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces, const virInterfaceDefPtr def); void virInterfaceRemove(virInterfaceObjListPtr interfaces, const virInterfaceObjPtr iface); -virInterfaceDefPtr virInterfaceDefParseString(virConnectPtr conn, - const char *xmlStr); -virInterfaceDefPtr virInterfaceDefParseFile(virConnectPtr conn, - const char *filename); -virInterfaceDefPtr virInterfaceDefParseNode(virConnectPtr conn, - xmlDocPtr xml, +virInterfaceDefPtr virInterfaceDefParseString(const char *xmlStr); +virInterfaceDefPtr virInterfaceDefParseFile(const char *filename); +virInterfaceDefPtr virInterfaceDefParseNode(xmlDocPtr xml, xmlNodePtr root); -char *virInterfaceDefFormat(virConnectPtr conn, - const virInterfaceDefPtr def); +char *virInterfaceDefFormat(const virInterfaceDefPtr def); void virInterfaceObjLock(virInterfaceObjPtr obj); void virInterfaceObjUnlock(virInterfaceObjPtr obj); diff --git a/src/interface/netcf_driver.c b/src/interface/netcf_driver.c index bccb167..2753049 100644 --- a/src/interface/netcf_driver.c +++ b/src/interface/netcf_driver.c @@ -356,13 +356,13 @@ static char *interfaceGetXMLDesc(virInterfacePtr ifinfo, goto cleanup; } - ifacedef = virInterfaceDefParseString(ifinfo->conn, xmlstr); + ifacedef = virInterfaceDefParseString(xmlstr); if (!ifacedef) { /* error was already reported */ goto cleanup; } - ret = virInterfaceDefFormat(ifinfo->conn, ifacedef); + ret = virInterfaceDefFormat(ifacedef); if (!ret) { /* error was already reported */ goto cleanup; @@ -388,13 +388,13 @@ static virInterfacePtr interfaceDefineXML(virConnectPtr conn, interfaceDriverLock(driver); - ifacedef = virInterfaceDefParseString(conn, xml); + ifacedef = virInterfaceDefParseString(xml); if (!ifacedef) { /* error was already reported */ goto cleanup; } - xmlstr = virInterfaceDefFormat(conn, ifacedef); + xmlstr = virInterfaceDefFormat(ifacedef); if (!xmlstr) { /* error was already reported */ goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ac0818b..4bb2b0b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -568,9 +568,9 @@ static int testOpenDefault(virConnectPtr conn) { netobj->persistent = 1; virNetworkObjUnlock(netobj); - if (!(interfacedef = virInterfaceDefParseString(conn, defaultInterfaceXML))) + if (!(interfacedef = virInterfaceDefParseString(defaultInterfaceXML))) goto error; - if (!(interfaceobj = virInterfaceAssignDef(conn, &privconn->ifaces, interfacedef))) { + if (!(interfaceobj = virInterfaceAssignDef(&privconn->ifaces, interfacedef))) { virInterfaceDefFree(interfacedef); goto error; } @@ -969,16 +969,16 @@ static int testOpenFromFile(virConnectPtr conn, goto error; } - def = virInterfaceDefParseFile(conn, absFile); + def = virInterfaceDefParseFile(absFile); VIR_FREE(absFile); if (!def) goto error; } else { - if ((def = virInterfaceDefParseNode(conn, xml, ifaces[i])) == NULL) + if ((def = virInterfaceDefParseNode(xml, ifaces[i])) == NULL) goto error; } - if (!(iface = virInterfaceAssignDef(conn, &privconn->ifaces, def))) { + if (!(iface = virInterfaceAssignDef(&privconn->ifaces, def))) { virInterfaceDefFree(def); goto error; } @@ -3328,7 +3328,7 @@ static char *testInterfaceGetXMLDesc(virInterfacePtr iface, goto cleanup; } - ret = virInterfaceDefFormat(iface->conn, privinterface->def); + ret = virInterfaceDefFormat(privinterface->def); cleanup: if (privinterface) @@ -3346,10 +3346,10 @@ static virInterfacePtr testInterfaceDefineXML(virConnectPtr conn, const char *xm virInterfacePtr ret = NULL; testDriverLock(privconn); - if ((def = virInterfaceDefParseString(conn, xmlStr)) == NULL) + if ((def = virInterfaceDefParseString(xmlStr)) == NULL) goto cleanup; - if ((iface = virInterfaceAssignDef(conn, &privconn->ifaces, def)) == NULL) + if ((iface = virInterfaceAssignDef(&privconn->ifaces, def)) == NULL) goto cleanup; def = NULL; diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c index d8f1b43..094ccf5 100644 --- a/tests/interfacexml2xmltest.c +++ b/tests/interfacexml2xmltest.c @@ -29,10 +29,10 @@ static int testCompareXMLToXMLFiles(const char *xml) { if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) goto fail; - if (!(dev = virInterfaceDefParseString(NULL, xmlData))) + if (!(dev = virInterfaceDefParseString(xmlData))) goto fail; - if (!(actual = virInterfaceDefFormat(NULL, dev))) + if (!(actual = virInterfaceDefFormat(dev))) goto fail; if (STRNEQ(xmlData, actual)) { -- 1.6.6

On Wed, Feb 10, 2010 at 01:36:24PM +0000, Daniel P. Berrange wrote:
The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in interface_conf.{h,c} and update all callers to match --- src/conf/interface_conf.c | 259 ++++++++++++++++++++---------------------- src/conf/interface_conf.h | 15 +-- src/interface/netcf_driver.c | 8 +- src/test/test_driver.c | 16 ++-- tests/interfacexml2xmltest.c | 4 +- 5 files changed, 141 insertions(+), 161 deletions(-)
[...]
@@ -890,26 +883,24 @@ virInterfaceDefPtr virInterfaceDefParseString(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn;
- if (conn) virResetError (&conn->err);
Hum, there there is a semantic change, the function used to reset the error and not anymore, though it's probably better that way
@@ -930,26 +920,24 @@ virInterfaceDefPtr virInterfaceDefParseFile(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn;
- if (conn) virResetError (&conn->err);
Here too ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Wed, Feb 10, 2010 at 03:39:45PM +0100, Daniel Veillard wrote:
On Wed, Feb 10, 2010 at 01:36:24PM +0000, Daniel P. Berrange wrote:
The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in interface_conf.{h,c} and update all callers to match --- src/conf/interface_conf.c | 259 ++++++++++++++++++++---------------------- src/conf/interface_conf.h | 15 +-- src/interface/netcf_driver.c | 8 +- src/test/test_driver.c | 16 ++-- tests/interfacexml2xmltest.c | 4 +- 5 files changed, 141 insertions(+), 161 deletions(-)
[...]
@@ -890,26 +883,24 @@ virInterfaceDefPtr virInterfaceDefParseString(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn;
- if (conn) virResetError (&conn->err);
Hum, there there is a semantic change, the function used to reset the error and not anymore, though it's probably better that way
@@ -930,26 +920,24 @@ virInterfaceDefPtr virInterfaceDefParseFile(virConnectPtr conn, if (!pctxt || !pctxt->sax) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn;
- if (conn) virResetError (&conn->err);
Here too
All the public API methods do a virResetError() before invoking the internal drivers, so there really shouldn't be any error present at this point. Also note that 'conn' has been NULL in at least 50% of the locations that invoke this method, so I don't think this is worth worrying about.. Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in secret_conf.{h,c} and update all callers to match --- src/conf/secret_conf.c | 57 ++++++++++++-------------- src/conf/secret_conf.h | 10 ++-- src/secret/secret_driver.c | 90 ++++++++++++++++++++--------------------- src/storage/storage_backend.c | 10 ++-- 4 files changed, 81 insertions(+), 86 deletions(-) diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index c002a5d..946d425 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -60,7 +60,7 @@ virSecretDefFree(virSecretDefPtr def) } static int -virSecretDefParseUsage(virConnectPtr conn, xmlXPathContextPtr ctxt, +virSecretDefParseUsage(xmlXPathContextPtr ctxt, virSecretDefPtr def) { char *type_str; @@ -68,13 +68,13 @@ virSecretDefParseUsage(virConnectPtr conn, xmlXPathContextPtr ctxt, type_str = virXPathString("string(./usage/@type)", ctxt); if (type_str == NULL) { - virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", + virSecretReportError(VIR_ERR_XML_ERROR, "%s", _("unknown secret usage type")); return -1; } type = virSecretUsageTypeTypeFromString(type_str); if (type < 0) { - virSecretReportError(conn, VIR_ERR_XML_ERROR, + virSecretReportError(VIR_ERR_XML_ERROR, _("unknown secret usage type %s"), type_str); VIR_FREE(type_str); return -1; @@ -88,14 +88,14 @@ virSecretDefParseUsage(virConnectPtr conn, xmlXPathContextPtr ctxt, case VIR_SECRET_USAGE_TYPE_VOLUME: def->usage.volume = virXPathString("string(./usage/volume)", ctxt); if (!def->usage.volume) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("volume usage specified, but volume path is missing")); return -1; } break; default: - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected secret usage type %d"), def->usage_type); return -1; @@ -104,7 +104,7 @@ virSecretDefParseUsage(virConnectPtr conn, xmlXPathContextPtr ctxt, } static virSecretDefPtr -secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root) +secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) { xmlXPathContextPtr ctxt = NULL; virSecretDefPtr def = NULL, ret = NULL; @@ -112,7 +112,7 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root) char *uuidstr = NULL; if (!xmlStrEqual(root->name, BAD_CAST "secret")) { - virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", + virSecretReportError(VIR_ERR_XML_ERROR, "%s", _("incorrect root element")); goto cleanup; } @@ -136,7 +136,7 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root) else if (STREQ(prop, "no")) def->ephemeral = 0; else { - virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", + virSecretReportError(VIR_ERR_XML_ERROR, "%s", _("invalid value of 'ephemeral'")); goto cleanup; } @@ -150,7 +150,7 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root) else if (STREQ(prop, "no")) def->private = 0; else { - virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", + virSecretReportError(VIR_ERR_XML_ERROR, "%s", _("invalid value of 'private'")); goto cleanup; } @@ -160,13 +160,13 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root) uuidstr = virXPathString("string(./uuid)", ctxt); if (!uuidstr) { if (virUUIDGenerate(def->uuid)) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to generate UUID")); goto cleanup; } } else { if (virUUIDParse(uuidstr, def->uuid) < 0) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed uuid element")); goto cleanup; } @@ -175,7 +175,7 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root) def->description = virXPathString("string(./description)", ctxt); if (virXPathNode("./usage", ctxt) != NULL - && virSecretDefParseUsage(conn, ctxt, def) < 0) + && virSecretDefParseUsage(ctxt, def) < 0) goto cleanup; ret = def; def = NULL; @@ -194,19 +194,17 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; if (ctxt) { - virConnectPtr conn = ctxt->_private; - if (virGetLastError() == NULL && ctxt->lastError.level == XML_ERR_FATAL && ctxt->lastError.message != NULL) { - virSecretReportError(conn, VIR_ERR_XML_DETAIL, _("at line %d: %s"), + virSecretReportError(VIR_ERR_XML_DETAIL, _("at line %d: %s"), ctxt->lastError.line, ctxt->lastError.message); } } } static virSecretDefPtr -virSecretDefParse(virConnectPtr conn, const char *xmlStr, const char *filename) +virSecretDefParse(const char *xmlStr, const char *filename) { xmlParserCtxtPtr pctxt; xmlDocPtr xml = NULL; @@ -217,7 +215,6 @@ virSecretDefParse(virConnectPtr conn, const char *xmlStr, const char *filename) if (pctxt == NULL || pctxt->sax == NULL) goto cleanup; pctxt->sax->error = catchXMLError; - pctxt->_private = conn; if (filename != NULL) xml = xmlCtxtReadFile(pctxt, filename, NULL, @@ -228,20 +225,20 @@ virSecretDefParse(virConnectPtr conn, const char *xmlStr, const char *filename) XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOWARNING); if (xml == NULL) { - if (conn->err.code == VIR_ERR_NONE) - virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", + if (virGetLastError() == NULL) + virSecretReportError(VIR_ERR_XML_ERROR, "%s", _("failed to parse xml document")); goto cleanup; } root = xmlDocGetRootElement(xml); if (root == NULL) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing root element")); goto cleanup; } - ret = secretXMLParseNode(conn, xml, root); + ret = secretXMLParseNode(xml, root); cleanup: xmlFreeDoc(xml); @@ -250,26 +247,26 @@ virSecretDefParse(virConnectPtr conn, const char *xmlStr, const char *filename) } virSecretDefPtr -virSecretDefParseString(virConnectPtr conn, const char *xmlStr) +virSecretDefParseString(const char *xmlStr) { - return virSecretDefParse(conn, xmlStr, NULL); + return virSecretDefParse(xmlStr, NULL); } virSecretDefPtr -virSecretDefParseFile(virConnectPtr conn, const char *filename) +virSecretDefParseFile(const char *filename) { - return virSecretDefParse(conn, NULL, filename); + return virSecretDefParse(NULL, filename); } static int -virSecretDefFormatUsage(virConnectPtr conn, virBufferPtr buf, +virSecretDefFormatUsage(virBufferPtr buf, const virSecretDefPtr def) { const char *type; type = virSecretUsageTypeTypeToString(def->usage_type); if (type == NULL) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected secret usage type %d"), def->usage_type); return -1; @@ -286,7 +283,7 @@ virSecretDefFormatUsage(virConnectPtr conn, virBufferPtr buf, break; default: - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected secret usage type %d"), def->usage_type); return -1; @@ -297,7 +294,7 @@ virSecretDefFormatUsage(virConnectPtr conn, virBufferPtr buf, } char * -virSecretDefFormat(virConnectPtr conn, const virSecretDefPtr def) +virSecretDefFormat(const virSecretDefPtr def) { virBuffer buf = VIR_BUFFER_INITIALIZER; unsigned char *uuid; @@ -314,7 +311,7 @@ virSecretDefFormat(virConnectPtr conn, const virSecretDefPtr def) virBufferEscapeString(&buf, " <description>%s</description>\n", def->description); if (def->usage_type != VIR_SECRET_USAGE_TYPE_NONE && - virSecretDefFormatUsage(conn, &buf, def) < 0) + virSecretDefFormatUsage(&buf, def) < 0) goto error; virBufferAddLit(&buf, "</secret>\n"); diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h index 1ecf419..da00920 100644 --- a/src/conf/secret_conf.h +++ b/src/conf/secret_conf.h @@ -26,8 +26,8 @@ #include "internal.h" #include "util.h" -#define virSecretReportError(conn, code, fmt...) \ - virReportErrorHelper(conn, VIR_FROM_SECRET, code, __FILE__, \ +#define virSecretReportError(code, fmt...) \ + virReportErrorHelper(NULL, VIR_FROM_SECRET, code, __FILE__, \ __FUNCTION__, __LINE__, fmt) VIR_ENUM_DECL(virSecretUsageType) @@ -46,8 +46,8 @@ struct _virSecretDef { }; void virSecretDefFree(virSecretDefPtr def); -virSecretDefPtr virSecretDefParseString(virConnectPtr conn, const char *xml); -virSecretDefPtr virSecretDefParseFile(virConnectPtr conn, const char *filename); -char *virSecretDefFormat(virConnectPtr conn, const virSecretDefPtr def); +virSecretDefPtr virSecretDefParseString(const char *xml); +virSecretDefPtr virSecretDefParseFile(const char *filename); +char *virSecretDefFormat(const virSecretDefPtr def); #endif diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 85c7e7c..22852a1 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -222,16 +222,14 @@ secretComputePath(virSecretDriverStatePtr driver, } static char * -secretXMLPath(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, - virSecretDriverStatePtr driver, +secretXMLPath(virSecretDriverStatePtr driver, const virSecretEntry *secret) { return secretComputePath(driver, secret, ".xml"); } static char * -secretBase64Path(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, - virSecretDriverStatePtr driver, +secretBase64Path(virSecretDriverStatePtr driver, const virSecretEntry *secret) { return secretComputePath(driver, secret, ".base64"); @@ -249,7 +247,7 @@ secretEnsureDirectory(virSecretDriverStatePtr driver) } static int -secretSaveDef(virConnectPtr conn, virSecretDriverStatePtr driver, +secretSaveDef(virSecretDriverStatePtr driver, const virSecretEntry *secret) { char *filename = NULL, *xml = NULL; @@ -258,10 +256,10 @@ secretSaveDef(virConnectPtr conn, virSecretDriverStatePtr driver, if (secretEnsureDirectory(driver) < 0) goto cleanup; - filename = secretXMLPath(conn, driver, secret); + filename = secretXMLPath(driver, secret); if (filename == NULL) goto cleanup; - xml = virSecretDefFormat(conn, secret->def); + xml = virSecretDefFormat(secret->def); if (xml == NULL) goto cleanup; @@ -277,7 +275,7 @@ cleanup: } static int -secretSaveValue(virConnectPtr conn, virSecretDriverStatePtr driver, +secretSaveValue(virSecretDriverStatePtr driver, const virSecretEntry *secret) { char *filename = NULL, *base64 = NULL; @@ -289,7 +287,7 @@ secretSaveValue(virConnectPtr conn, virSecretDriverStatePtr driver, if (secretEnsureDirectory(driver) < 0) goto cleanup; - filename = secretBase64Path(conn, driver, secret); + filename = secretBase64Path(driver, secret); if (filename == NULL) goto cleanup; base64_encode_alloc((const char *)secret->value, secret->value_size, @@ -311,16 +309,16 @@ cleanup: } static int -secretDeleteSaved(virConnectPtr conn, virSecretDriverStatePtr driver, +secretDeleteSaved(virSecretDriverStatePtr driver, const virSecretEntry *secret) { char *xml_filename = NULL, *value_filename = NULL; int ret = -1; - xml_filename = secretXMLPath(conn, driver, secret); + xml_filename = secretXMLPath(driver, secret); if (xml_filename == NULL) goto cleanup; - value_filename = secretBase64Path(conn, driver, secret); + value_filename = secretBase64Path(driver, secret); if (value_filename == NULL) goto cleanup; @@ -339,7 +337,7 @@ cleanup: } static int -secretLoadValidateUUID(virConnectPtr conn, virSecretDefPtr def, +secretLoadValidateUUID(virSecretDefPtr def, const char *xml_basename) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -347,7 +345,7 @@ secretLoadValidateUUID(virConnectPtr conn, virSecretDefPtr def, virUUIDFormat(def->uuid, uuidstr); if (!virFileMatchesNameSuffix(xml_basename, uuidstr, ".xml")) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, _("<uuid> does not match secret file name '%s'"), xml_basename); return -1; @@ -357,7 +355,7 @@ secretLoadValidateUUID(virConnectPtr conn, virSecretDefPtr def, } static int -secretLoadValue(virConnectPtr conn, virSecretDriverStatePtr driver, +secretLoadValue(virSecretDriverStatePtr driver, virSecretEntryPtr secret) { int ret = -1, fd = -1; @@ -365,7 +363,7 @@ secretLoadValue(virConnectPtr conn, virSecretDriverStatePtr driver, char *filename = NULL, *contents = NULL, *value = NULL; size_t value_size; - filename = secretBase64Path(conn, driver, secret); + filename = secretBase64Path(driver, secret); if (filename == NULL) goto cleanup; @@ -383,7 +381,7 @@ secretLoadValue(virConnectPtr conn, virSecretDriverStatePtr driver, goto cleanup; } if ((size_t)st.st_size != st.st_size) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, _("'%s' file does not fit in memory"), filename); goto cleanup; } @@ -400,7 +398,7 @@ secretLoadValue(virConnectPtr conn, virSecretDriverStatePtr driver, fd = -1; if (!base64_decode_alloc(contents, st.st_size, &value, &value_size)) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, _("invalid base64 in '%s'"), filename); goto cleanup; } @@ -431,7 +429,7 @@ cleanup: } static virSecretEntryPtr -secretLoad(virConnectPtr conn, virSecretDriverStatePtr driver, +secretLoad(virSecretDriverStatePtr driver, const char *xml_basename) { virSecretDefPtr def = NULL; @@ -443,12 +441,12 @@ secretLoad(virConnectPtr conn, virSecretDriverStatePtr driver, virReportOOMError(); goto cleanup; } - def = virSecretDefParseFile(conn, xml_filename); + def = virSecretDefParseFile(xml_filename); if (def == NULL) goto cleanup; VIR_FREE(xml_filename); - if (secretLoadValidateUUID(conn, def, xml_basename) < 0) + if (secretLoadValidateUUID(def, xml_basename) < 0) goto cleanup; if (VIR_ALLOC(secret) < 0) { @@ -458,7 +456,7 @@ secretLoad(virConnectPtr conn, virSecretDriverStatePtr driver, secret->def = def; def = NULL; - if (secretLoadValue(conn, driver, secret) < 0) + if (secretLoadValue(driver, secret) < 0) goto cleanup; ret = secret; @@ -472,7 +470,7 @@ cleanup: } static int -loadSecrets(virConnectPtr conn, virSecretDriverStatePtr driver, +loadSecrets(virSecretDriverStatePtr driver, virSecretEntryPtr *dest) { int ret = -1; @@ -496,7 +494,7 @@ loadSecrets(virConnectPtr conn, virSecretDriverStatePtr driver, if (!virFileHasSuffix(de->d_name, ".xml")) continue; - secret = secretLoad(conn, driver, de->d_name); + secret = secretLoad(driver, de->d_name); if (secret == NULL) { virErrorPtr err = virGetLastError(); @@ -632,7 +630,7 @@ secretLookupByUUID(virConnectPtr conn, const unsigned char *uuid) if (secret == NULL) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(uuid, uuidstr); - virSecretReportError(conn, VIR_ERR_NO_SECRET, + virSecretReportError(VIR_ERR_NO_SECRET, _("no secret with matching uuid '%s'"), uuidstr); goto cleanup; } @@ -659,7 +657,7 @@ secretLookupByUsage(virConnectPtr conn, int usageType, const char *usageID) secret = secretFindByUsage(driver, usageType, usageID); if (secret == NULL) { - virSecretReportError(conn, VIR_ERR_NO_SECRET, + virSecretReportError(VIR_ERR_NO_SECRET, _("no secret with matching usage '%s'"), usageID); goto cleanup; } @@ -685,7 +683,7 @@ secretDefineXML(virConnectPtr conn, const char *xml, virSecretDefPtr backup = NULL; virSecretDefPtr new_attrs; - new_attrs = virSecretDefParseString(conn, xml); + new_attrs = virSecretDefParseString(xml); if (new_attrs == NULL) return NULL; @@ -699,7 +697,7 @@ secretDefineXML(virConnectPtr conn, const char *xml, if (secret) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(secret->def->uuid, uuidstr); - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s already defined for use with %s"), uuidstr, usageID); goto cleanup; @@ -719,14 +717,14 @@ secretDefineXML(virConnectPtr conn, const char *xml, if (STRNEQ(oldUsageID, newUsageID)) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(secret->def->uuid, uuidstr); - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, + virSecretReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s is already defined for use with %s"), uuidstr, oldUsageID); goto cleanup; } if (secret->def->private && !new_attrs->private) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot change private flag on existing secret")); goto cleanup; } @@ -738,15 +736,15 @@ secretDefineXML(virConnectPtr conn, const char *xml, if (!new_attrs->ephemeral) { if (backup && backup->ephemeral) { - if (secretSaveValue(conn, driver, secret) < 0) + if (secretSaveValue(driver, secret) < 0) goto restore_backup; } - if (secretSaveDef(conn, driver, secret) < 0) { + if (secretSaveDef(driver, secret) < 0) { if (backup && backup->ephemeral) { char *filename; /* Undo the secretSaveValue() above; ignore errors */ - filename = secretBase64Path(conn, driver, secret); + filename = secretBase64Path(driver, secret); if (filename != NULL) (void)unlink(filename); VIR_FREE(filename); @@ -754,7 +752,7 @@ secretDefineXML(virConnectPtr conn, const char *xml, goto restore_backup; } } else if (backup && !backup->ephemeral) { - if (secretDeleteSaved(conn, driver, secret) < 0) + if (secretDeleteSaved(driver, secret) < 0) goto restore_backup; } /* Saved successfully - drop old values */ @@ -774,7 +772,7 @@ restore_backup: } else { /* "secret" was added to the head of the list above */ if (listUnlink(&driverState->secrets) != secret) - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", + virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("list of secrets is inconsistent")); else secretFree(secret); @@ -800,12 +798,12 @@ secretGetXMLDesc(virSecretPtr obj, unsigned int flags ATTRIBUTE_UNUSED) if (secret == NULL) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(obj->uuid, uuidstr); - virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, + virSecretReportError(VIR_ERR_NO_SECRET, _("no secret with matching uuid '%s'"), uuidstr); goto cleanup; } - ret = virSecretDefFormat(obj->conn, secret->def); + ret = virSecretDefFormat(secret->def); cleanup: secretDriverUnlock(driver); @@ -834,7 +832,7 @@ secretSetValue(virSecretPtr obj, const unsigned char *value, if (secret == NULL) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(obj->uuid, uuidstr); - virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, + virSecretReportError(VIR_ERR_NO_SECRET, _("no secret with matching uuid '%s'"), uuidstr); goto cleanup; } @@ -846,7 +844,7 @@ secretSetValue(virSecretPtr obj, const unsigned char *value, secret->value = new_value; secret->value_size = value_size; if (!secret->def->ephemeral) { - if (secretSaveValue(obj->conn, driver, secret) < 0) + if (secretSaveValue(driver, secret) < 0) goto restore_backup; } /* Saved successfully - drop old value */ @@ -886,7 +884,7 @@ secretGetValue(virSecretPtr obj, size_t *value_size, unsigned int flags) if (secret == NULL) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(obj->uuid, uuidstr); - virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, + virSecretReportError(VIR_ERR_NO_SECRET, _("no secret with matching uuid '%s'"), uuidstr); goto cleanup; } @@ -894,14 +892,14 @@ secretGetValue(virSecretPtr obj, size_t *value_size, unsigned int flags) if (secret->value == NULL) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(obj->uuid, uuidstr); - virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, + virSecretReportError(VIR_ERR_NO_SECRET, _("secret '%s' does not have a value"), uuidstr); goto cleanup; } if ((flags & VIR_SECRET_GET_VALUE_INTERNAL_CALL) == 0 && secret->def->private) { - virSecretReportError(obj->conn, VIR_ERR_OPERATION_DENIED, "%s", + virSecretReportError(VIR_ERR_OPERATION_DENIED, "%s", _("secret is private")); goto cleanup; } @@ -932,13 +930,13 @@ secretUndefine(virSecretPtr obj) if (secret == NULL) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(obj->uuid, uuidstr); - virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, + virSecretReportError(VIR_ERR_NO_SECRET, _("no secret with matching uuid '%s'"), uuidstr); goto cleanup; } if (!secret->def->ephemeral && - secretDeleteSaved(obj->conn, driver, secret) < 0) + secretDeleteSaved(driver, secret) < 0) goto cleanup; if (driver->secrets == secret) { @@ -1018,7 +1016,7 @@ secretDriverStartup(int privileged) goto out_of_memory; VIR_FREE(base); - if (loadSecrets(NULL, driverState, &driverState->secrets) < 0) + if (loadSecrets(driverState, &driverState->secrets) < 0) goto error; secretDriverUnlock(driverState); @@ -1043,7 +1041,7 @@ secretDriverReload(void) secretDriverLock(driverState); - if (loadSecrets(NULL, driverState, &new_secrets) < 0) + if (loadSecrets(driverState, &new_secrets) < 0) goto end; /* Keep ephemeral secrets from current state. Discard non-ephemeral secrets diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index de7fbd1..a12ddc7 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -385,8 +385,8 @@ virStorageGenerateSecretUUID(virConnectPtr conn, for (attempt = 0; attempt < 65536; attempt++) { virSecretPtr tmp; if (virUUIDGenerate(uuid) < 0) { - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", - _("unable to generate uuid")); + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unable to generate uuid")); return -1; } tmp = conn->secretDriver->lookupByUUID(conn, uuid); @@ -396,8 +396,8 @@ virStorageGenerateSecretUUID(virConnectPtr conn, virSecretFree(tmp); } - virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", - _("too many conflicts when generating an uuid")); + virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("too many conflicts when generating an uuid")); return -1; } @@ -448,7 +448,7 @@ virStorageGenerateQcowEncryption(virConnectPtr conn, virReportOOMError(); goto cleanup; } - xml = virSecretDefFormat(conn, def); + xml = virSecretDefFormat(def); virSecretDefFree(def); def = NULL; if (xml == NULL) -- 1.6.6

On Wed, Feb 10, 2010 at 01:36:25PM +0000, Daniel P. Berrange wrote:
The virConnectPtr is no longer required for error reporting since that is recorded in a thread local. Remove use of virConnectPtr from all APIs in secret_conf.{h,c} and update all callers to match --- src/conf/secret_conf.c | 57 ++++++++++++-------------- src/conf/secret_conf.h | 10 ++-- src/secret/secret_driver.c | 90 ++++++++++++++++++++--------------------- src/storage/storage_backend.c | 10 ++-- 4 files changed, 81 insertions(+), 86 deletions(-)
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

Use the ATTRIBUTE_NONNULL annotation to mark some virConnectPtr args as mandatory non-null so the compiler can warn of mistakes * src/conf/domain_event.h: All virConnectPtr args must be non-null * src/qemu/qemu_conf.h: qemudBuildCommandLine and qemudNetworkIfaceConnect() must be given non-null connection * tests/qemuxml2argvtest.c: Provide a non-null (dummy) connection to qemudBuildCommandLine() --- src/conf/domain_event.h | 13 +++++++++---- src/qemu/qemu_conf.h | 6 ++++-- tests/qemuxml2argvtest.c | 8 +++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index f29e42e..aa0346b 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -50,18 +50,23 @@ int virDomainEventCallbackListAdd(virConnectPtr conn, virDomainEventCallbackListPtr cbList, virConnectDomainEventCallback callback, void *opaque, - virFreeCallback freecb); + virFreeCallback freecb) + ATTRIBUTE_NONNULL(1); int virDomainEventCallbackListRemove(virConnectPtr conn, virDomainEventCallbackListPtr cbList, - virConnectDomainEventCallback callback); + virConnectDomainEventCallback callback) + ATTRIBUTE_NONNULL(1); int virDomainEventCallbackListRemoveConn(virConnectPtr conn, - virDomainEventCallbackListPtr cbList); + virDomainEventCallbackListPtr cbList) + ATTRIBUTE_NONNULL(1); int virDomainEventCallbackListMarkDelete(virConnectPtr conn, virDomainEventCallbackListPtr cbList, - virConnectDomainEventCallback callback); + virConnectDomainEventCallback callback) + ATTRIBUTE_NONNULL(1); + int virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList); /** diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 5c41a1a..d26bb90 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -188,7 +188,8 @@ int qemudBuildCommandLine (virConnectPtr conn, const char ***retenv, int **tapfds, int *ntapfds, - const char *migrateFrom); + const char *migrateFrom) + ATTRIBUTE_NONNULL(1); /* With vlan == -1, use netdev syntax, else old hostnet */ char * qemuBuildHostNetStr(virDomainNetDefPtr net, @@ -241,7 +242,8 @@ char * qemuBuildUSBHostdevDevStr(virDomainHostdevDefPtr dev); int qemudNetworkIfaceConnect (virConnectPtr conn, struct qemud_driver *driver, virDomainNetDefPtr net, - unsigned long long qemuCmdFlags); + unsigned long long qemuCmdFlags) + ATTRIBUTE_NONNULL(1); int qemudProbeMachineTypes (const char *binary, virCapsGuestMachinePtr **machines, diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 8bdab49..3ee71a3 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -13,6 +13,7 @@ #include "internal.h" #include "testutils.h" #include "qemu/qemu_conf.h" +#include "datatypes.h" #include "testutilsqemu.h" @@ -36,6 +37,10 @@ static int testCompareXMLToArgvFiles(const char *xml, unsigned long long flags; virDomainDefPtr vmdef = NULL; virDomainChrDef monitor_chr; + virConnectPtr conn; + + if (!(conn = virGetConnect())) + goto fail; if (virtTestLoadFile(cmd, &expectargv, MAX_FILE) < 0) goto fail; @@ -75,7 +80,7 @@ static int testCompareXMLToArgvFiles(const char *xml, } - if (qemudBuildCommandLine(NULL, &driver, + if (qemudBuildCommandLine(conn, &driver, vmdef, &monitor_chr, 0, flags, &argv, &qenv, NULL, NULL, migrateFrom) < 0) @@ -137,6 +142,7 @@ static int testCompareXMLToArgvFiles(const char *xml, free(qenv); } virDomainDefFree(vmdef); + virUnrefConnect(conn); return ret; } -- 1.6.6

On Wed, Feb 10, 2010 at 01:36:26PM +0000, Daniel P. Berrange wrote:
Use the ATTRIBUTE_NONNULL annotation to mark some virConnectPtr args as mandatory non-null so the compiler can warn of mistakes
* src/conf/domain_event.h: All virConnectPtr args must be non-null * src/qemu/qemu_conf.h: qemudBuildCommandLine and qemudNetworkIfaceConnect() must be given non-null connection * tests/qemuxml2argvtest.c: Provide a non-null (dummy) connection to qemudBuildCommandLine() --- src/conf/domain_event.h | 13 +++++++++---- src/qemu/qemu_conf.h | 6 ++++-- tests/qemuxml2argvtest.c | 8 +++++++- 3 files changed, 20 insertions(+), 7 deletions(-)
ACK, good idea ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (2)
-
Daniel P. Berrange
-
Daniel Veillard