[libvirt] [PATCH 00/12] OOM reporting cleanups

Patches 1-3 don't touch any code 4-5 no functional change 6 introduces a new function 7-8 have no functional change unless virBuffer API is misused (that case resulted in an OOM error before, now it's an internal error) 9-10 add OOM error reporting to a few functions 11-12 remove double OOM error reporting Ján Tomko (12): Fix indentation in bridge driver More indentation fixes usb: Remove redundant comment Remove useless condition in networkRadvdConfContents Use virStringReplace instead of openvz_replace Introduce virBufferCheckError Report errors in virCapabilitiesFormatXML Use virBufferCheckError everywhere we report OOM error Set errno on OOM in lxcProcReadMeminfo Add OOM error reporting to a few fucntions Remove double OOM error reporting from JSON monitor Remove double OOM error reporting HACKING | 7 +- docs/hacking.html.in | 7 +- po/POTFILES.in | 1 + src/bhyve/bhyve_driver.c | 12 +-- src/conf/capabilities.c | 2 +- src/conf/cpu_conf.c | 6 +- src/conf/domain_conf.c | 17 +--- src/conf/interface_conf.c | 8 +- src/conf/network_conf.c | 12 +-- src/conf/node_device_conf.c | 9 +- src/conf/nwfilter_conf.c | 16 +--- src/conf/secret_conf.c | 6 +- src/conf/snapshot_conf.c | 5 +- src/conf/storage_conf.c | 18 ++-- src/cpu/cpu_map.c | 14 ++- src/cpu/cpu_x86.c | 5 +- src/esx/esx_driver.c | 20 +--- src/esx/esx_util.c | 12 +-- src/esx/esx_vi.c | 20 +--- src/esx/esx_vi_methods.c | 4 +- src/hyperv/hyperv_wmi.c | 4 +- src/libvirt_private.syms | 1 + src/libxl/libxl_driver.c | 12 +-- src/locking/lock_driver_sanlock.c | 5 +- src/lxc/lxc_container.c | 2 +- src/lxc/lxc_controller.c | 8 +- src/lxc/lxc_driver.c | 47 +++------- src/lxc/lxc_fuse.c | 4 +- src/network/bridge_driver.c | 105 ++++++++++----------- src/node_device/node_device_udev.c | 8 +- src/nwfilter/nwfilter_ebiptables_driver.c | 10 +- src/nwfilter/nwfilter_gentech_driver.c | 63 ++++++------- src/openvz/openvz_conf.c | 40 +------- src/parallels/parallels_driver.c | 3 +- src/phyp/phyp_driver.c | 16 +--- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_command.c | 150 ++++++++---------------------- src/qemu/qemu_driver.c | 47 +++------- src/qemu/qemu_hotplug.c | 4 +- src/qemu/qemu_migration.c | 5 +- src/qemu/qemu_monitor.c | 5 +- src/qemu/qemu_monitor_json.c | 21 ++--- src/qemu/qemu_monitor_text.c | 9 +- src/rpc/virnetsocket.c | 4 +- src/rpc/virnetsshsession.c | 8 +- src/storage/storage_backend.c | 6 +- src/storage/storage_backend_rbd.c | 12 +-- src/test/test_driver.c | 3 +- src/uml/uml_conf.c | 4 +- src/uml/uml_driver.c | 3 +- src/util/virbuffer.c | 31 ++++++ src/util/virbuffer.h | 17 ++++ src/util/vircommand.c | 5 +- src/util/virconf.c | 10 +- src/util/virnetdevopenvswitch.c | 4 +- src/util/virstoragefile.c | 4 +- src/util/virstring.c | 8 +- src/util/virsysinfo.c | 4 +- src/util/virsystemd.c | 8 +- src/util/viruri.c | 7 +- src/util/virusb.c | 1 - src/vmx/vmx.c | 4 +- src/xen/xen_driver.c | 12 +-- src/xen/xen_hypervisor.c | 8 +- src/xen/xend_internal.c | 9 +- src/xenapi/xenapi_driver.c | 8 +- src/xenapi/xenapi_utils.c | 5 +- src/xenxs/xen_sxpr.c | 12 +-- src/xenxs/xen_xm.c | 17 +--- tests/domainsnapshotxml2xmltest.c | 4 +- tests/vircaps2xmltest.c | 4 +- 71 files changed, 328 insertions(+), 666 deletions(-) -- 1.8.5.5

--- src/network/bridge_driver.c | 84 ++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 0ece432..8624f1e 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -104,16 +104,16 @@ static int networkShutdownNetwork(virNetworkDriverStatePtr driver, virNetworkObjPtr network); static int networkStartNetworkVirtual(virNetworkDriverStatePtr driver, - virNetworkObjPtr network); + virNetworkObjPtr network); static int networkShutdownNetworkVirtual(virNetworkDriverStatePtr driver, virNetworkObjPtr network); static int networkStartNetworkExternal(virNetworkDriverStatePtr driver, - virNetworkObjPtr network); + virNetworkObjPtr network); static int networkShutdownNetworkExternal(virNetworkDriverStatePtr driver, - virNetworkObjPtr network); + virNetworkObjPtr network); static void networkReloadFirewallRules(virNetworkDriverStatePtr driver); static void networkRefreshDaemons(virNetworkDriverStatePtr driver); @@ -364,7 +364,7 @@ networkUpdateAllState(virNetworkDriverStatePtr driver) virNetworkObjPtr obj = driver->networks.objs[i]; if (!obj->active) - continue; + continue; virNetworkObjLock(obj); @@ -445,7 +445,7 @@ networkAutostartConfigs(virNetworkDriverStatePtr driver) if (driver->networks.objs[i]->autostart && !virNetworkObjIsActive(driver->networks.objs[i])) { if (networkStartNetwork(driver, driver->networks.objs[i]) < 0) { - /* failed to start but already logged */ + /* failed to start but already logged */ } } virNetworkObjUnlock(driver->networks.objs[i]); @@ -516,13 +516,13 @@ networkMigrateStateFiles(virNetworkDriverStatePtr driver) if (virAsprintf(&oldPath, "%s/%s", oldStateDir, entry->d_name) < 0) - goto cleanup; + goto cleanup; if (virFileReadAll(oldPath, 1024*1024, &contents) < 0) - goto cleanup; + goto cleanup; if (virAsprintf(&newPath, "%s/%s", driver->stateDir, entry->d_name) < 0) - goto cleanup; + goto cleanup; if (virFileWriteStr(newPath, contents, S_IRUSR | S_IWUSR) < 0) { virReportSystemError(errno, _("failed to write network status file '%s'"), @@ -536,7 +536,7 @@ networkMigrateStateFiles(virNetworkDriverStatePtr driver) VIR_FREE(contents); } if (direrr < 0) - goto cleanup; + goto cleanup; ret = 0; cleanup: @@ -824,9 +824,9 @@ networkKillDaemon(pid_t pid, const char *daemonName, const char *networkName) return ret; } - /* the following does not build a file, it builds a list - * which is later saved into a file - */ +/* the following does not build a file, it builds a list + * which is later saved into a file + */ static int networkBuildDnsmasqDhcpHostsList(dnsmasqContext *dctx, @@ -916,7 +916,7 @@ networkDnsmasqConfContents(virNetworkObjPtr network, virBufferAddLit(&configbuf, "no-resolv\n"); for (i = 0; i < network->def->dns.nfwds; i++) { virBufferAsprintf(&configbuf, "server=%s\n", - network->def->dns.forwarders[i]); + network->def->dns.forwarders[i]); } } @@ -1276,8 +1276,8 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, /* Write the file */ if (virFileWriteStr(configfile, configstr, 0600) < 0) { virReportSystemError(errno, - _("couldn't write dnsmasq config file '%s'"), - configfile); + _("couldn't write dnsmasq config file '%s'"), + configfile); goto cleanup; } @@ -1426,13 +1426,13 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr driver, } if (ipv4def && (networkBuildDnsmasqDhcpHostsList(dctx, ipv4def) < 0)) - goto cleanup; + goto cleanup; if (ipv6def && (networkBuildDnsmasqDhcpHostsList(dctx, ipv6def) < 0)) - goto cleanup; + goto cleanup; if (networkBuildDnsmasqHostsList(dctx, &network->def->dns) < 0) - goto cleanup; + goto cleanup; if ((ret = dnsmasqSave(dctx)) < 0) goto cleanup; @@ -1596,7 +1596,7 @@ networkRadvdConfWrite(virNetworkObjPtr network, char **configFile) static int networkStartRadvd(virNetworkDriverStatePtr driver ATTRIBUTE_UNUSED, - virNetworkObjPtr network) + virNetworkObjPtr network) { char *pidfile = NULL; char *radvdpidbase = NULL; @@ -1607,7 +1607,7 @@ networkStartRadvd(virNetworkDriverStatePtr driver ATTRIBUTE_UNUSED, network->radvdPid = -1; /* Is dnsmasq handling RA? */ - if (DNSMASQ_RA_SUPPORT(driver->dnsmasqCaps)) { + if (DNSMASQ_RA_SUPPORT(driver->dnsmasqCaps)) { ret = 0; goto cleanup; } @@ -1812,10 +1812,10 @@ networkEnableIpForwarding(bool enableIPv4, bool enableIPv6) int enabled = 1; if (enableIPv4) ret = sysctlbyname("net.inet.ip.forwarding", NULL, 0, - &enabled, sizeof(enabled)); + &enabled, sizeof(enabled)); if (enableIPv6 && ret == 0) ret = sysctlbyname("net.inet6.ip6.forwarding", NULL, 0, - &enabled, sizeof(enabled)); + &enabled, sizeof(enabled)); #else if (enableIPv4) ret = virFileWriteStr("/proc/sys/net/ipv4/ip_forward", "1\n", 0); @@ -1936,7 +1936,7 @@ networkAddRouteToBridge(virNetworkObjPtr network, if (routedef->has_prefix && routedef->prefix == 0) prefix = 0; else if ((VIR_SOCKET_ADDR_IS_FAMILY(mask, AF_INET) && - virSocketAddrEqual(mask, &zero))) + virSocketAddrEqual(mask, &zero))) prefix = 0; else prefix = virSocketAddrGetIpPrefix(addr, mask, routedef->prefix); @@ -1966,7 +1966,7 @@ networkAddRouteToBridge(virNetworkObjPtr network, static int networkStartNetworkVirtual(virNetworkDriverStatePtr driver, - virNetworkObjPtr network) + virNetworkObjPtr network) { size_t i; bool v4present = false, v6present = false; @@ -2204,7 +2204,7 @@ networkStartNetworkExternal(virNetworkDriverStatePtr driver ATTRIBUTE_UNUSED, } static int networkShutdownNetworkExternal(virNetworkDriverStatePtr driver ATTRIBUTE_UNUSED, - virNetworkObjPtr network ATTRIBUTE_UNUSED) + virNetworkObjPtr network ATTRIBUTE_UNUSED) { /* put anything here that needs to be done each time a network of * type BRIDGE, PRIVATE, VEPA, HOSTDEV or PASSTHROUGH is shutdown. On @@ -2291,7 +2291,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver, } static int networkShutdownNetwork(virNetworkDriverStatePtr driver, - virNetworkObjPtr network) + virNetworkObjPtr network) { int ret = 0; char *stateFile; @@ -2739,8 +2739,8 @@ networkValidate(virNetworkDriverStatePtr driver, */ vlanAllowed = ((def->forward.type == VIR_NETWORK_FORWARD_BRIDGE && - def->virtPortProfile && - def->virtPortProfile->virtPortType + def->virtPortProfile && + def->virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) || def->forward.type == VIR_NETWORK_FORWARD_HOSTDEV); @@ -2809,7 +2809,7 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const char *xml) goto cleanup; if (networkValidate(driver, def, true) < 0) - goto cleanup; + goto cleanup; /* NB: even though this transient network hasn't yet been started, * we assign the def with live = true in anticipation that it will @@ -2862,10 +2862,10 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml) goto cleanup; if (networkValidate(driver, def, false) < 0) - goto cleanup; + goto cleanup; if (!(network = virNetworkAssignDef(&driver->networks, def, false))) - goto cleanup; + goto cleanup; /* def was assigned to network object */ freeDef = false; @@ -2895,7 +2895,7 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml) if (event) virObjectEventStateQueue(driver->networkEventState, event); if (freeDef) - virNetworkDefFree(def); + virNetworkDefFree(def); if (network) virNetworkObjUnlock(network); networkDriverUnlock(driver); @@ -3009,7 +3009,7 @@ networkUpdate(virNetworkPtr net, /* VIR_NETWORK_UPDATE_AFFECT_CURRENT means "change LIVE if network * is active, else change CONFIG - */ + */ isActive = virNetworkObjIsActive(network); if ((flags & (VIR_NETWORK_UPDATE_AFFECT_LIVE | VIR_NETWORK_UPDATE_AFFECT_CONFIG)) == @@ -3278,7 +3278,7 @@ static char *networkGetBridgeName(virNetworkPtr net) { } static int networkGetAutostart(virNetworkPtr net, - int *autostart) + int *autostart) { virNetworkObjPtr network; int ret = -1; @@ -3637,7 +3637,7 @@ networkCreateInterfacePool(virNetworkDefPtr netdef) virReportError(VIR_ERR_INTERNAL_ERROR, _("No Vf's present on SRIOV PF %s"), netdef->forward.pfs->dev); - goto finish; + goto finish; } if (VIR_ALLOC_N(netdef->forward.ifs, num_virt_fns) < 0) @@ -3739,7 +3739,7 @@ networkAllocateActualDevice(virDomainDefPtr dom, /* portgroup can be present for any type of network, in particular * for bandwidth information, so we need to check for that and * fill it in appropriately for all forward types. - */ + */ portgroup = virPortGroupFindByName(netdef, iface->data.network.portgroup); /* If there is already interface-specific bandwidth, just use that @@ -3773,7 +3773,7 @@ networkAllocateActualDevice(virDomainDefPtr dom, /* for these forward types, the actual net type really *is* *NETWORK; we just keep the info from the portgroup in * iface->data.network.actual - */ + */ iface->data.network.actual->type = VIR_DOMAIN_NET_TYPE_NETWORK; if (networkPlugBandwidth(network, iface) < 0) @@ -4105,7 +4105,7 @@ networkNotifyActualDevice(virDomainDefPtr dom, int ret = -1; if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) - return 0; + return 0; networkDriverLock(driver); network = virNetworkFindByName(&driver->networks, iface->data.network.name); @@ -4219,7 +4219,7 @@ networkNotifyActualDevice(virDomainDefPtr dom, hostdev->source.subsys.u.pci.addr.bus, hostdev->source.subsys.u.pci.addr.slot, hostdev->source.subsys.u.pci.addr.function); - goto error; + goto error; } /* PASSTHROUGH mode, PRIVATE Mode + 802.1Qbh, and hostdev (PCI @@ -4296,7 +4296,7 @@ networkReleaseActualDevice(virDomainDefPtr dom, int ret = -1; if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) - return 0; + return 0; networkDriverLock(driver); network = virNetworkFindByName(&driver->networks, iface->data.network.name); @@ -4392,7 +4392,7 @@ networkReleaseActualDevice(virDomainDefPtr dom, hostdev->source.subsys.u.pci.addr.bus, hostdev->source.subsys.u.pci.addr.slot, hostdev->source.subsys.u.pci.addr.function); - goto error; + goto error; } dev->connections--; @@ -4400,7 +4400,7 @@ networkReleaseActualDevice(virDomainDefPtr dom, dev->device.pci.domain, dev->device.pci.bus, dev->device.pci.slot, dev->device.pci.function, dev->connections); - } + } success: if (iface->data.network.actual) { -- 1.8.5.5

Reindent nwfilter gentech driver and one block in rbd storage backend. --- src/nwfilter/nwfilter_gentech_driver.c | 66 +++++++++++++++++----------------- src/storage/storage_backend_rbd.c | 6 ++-- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 5bed106..8226195 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -105,12 +105,12 @@ virNWFilterTechDriverForName(const char *name) { size_t i = 0; while (filter_tech_drivers[i]) { - if (STREQ(filter_tech_drivers[i]->name, name)) { - if ((filter_tech_drivers[i]->flags & TECHDRV_FLAG_INITIALIZED) == 0) - break; - return filter_tech_drivers[i]; - } - i++; + if (STREQ(filter_tech_drivers[i]->name, name)) { + if ((filter_tech_drivers[i]->flags & TECHDRV_FLAG_INITIALIZED) == 0) + break; + return filter_tech_drivers[i]; + } + i++; } return NULL; } @@ -212,10 +212,10 @@ virNWFilterCreateVarHashmap(char *macaddr, */ struct printString { - virBuffer buf; - const char *separator; - bool reportMAC; - bool reportIP; + virBuffer buf; + const char *separator; + bool reportMAC; + bool reportIP; }; @@ -250,21 +250,21 @@ virNWFilterPrintVars(virHashTablePtr vars, bool reportMAC, bool reportIP) { - struct printString ps = { - .buf = VIR_BUFFER_INITIALIZER, - .separator = separator, - .reportMAC = reportMAC, - .reportIP = reportIP, - }; - - virHashForEach(vars, printString, &ps); - - if (virBufferError(&ps.buf)) { - virBufferFreeAndReset(&ps.buf); - virReportOOMError(); - return NULL; - } - return virBufferContentAndReset(&ps.buf); + struct printString ps = { + .buf = VIR_BUFFER_INITIALIZER, + .separator = separator, + .reportMAC = reportMAC, + .reportIP = reportIP, + }; + + virHashForEach(vars, printString, &ps); + + if (virBufferError(&ps.buf)) { + virBufferFreeAndReset(&ps.buf); + virReportOOMError(); + return NULL; + } + return virBufferContentAndReset(&ps.buf); } @@ -573,9 +573,9 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter, if (obj->newDef) { next_filter = obj->newDef; } - break; + break; case INSTANTIATE_ALWAYS: - break; + break; } rc = virNWFilterDetermineMissingVarsRec(next_filter, @@ -703,7 +703,7 @@ virNWFilterInstantiate(const unsigned char *vmuuid ATTRIBUTE_UNUSED, goto err_exit; } } else - goto err_unresolvable_vars; + goto err_unresolvable_vars; } else if (virHashSize(missing_vars->hashTable) > 1) { goto err_unresolvable_vars; } else if (!forceWithPendingReq && @@ -723,10 +723,10 @@ virNWFilterInstantiate(const unsigned char *vmuuid ATTRIBUTE_UNUSED, switch (useNewFilter) { case INSTANTIATE_FOLLOW_NEWFILTER: instantiate = *foundNewFilter; - break; + break; case INSTANTIATE_ALWAYS: instantiate = true; - break; + break; } if (instantiate) { @@ -857,10 +857,10 @@ __virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver, filter = obj->newDef; *foundNewFilter = true; } - break; + break; case INSTANTIATE_ALWAYS: - break; + break; } rc = virNWFilterInstantiate(vmuuid, @@ -1087,7 +1087,7 @@ _virNWFilterTeardownFilter(const char *ifname) virNWFilterTerminateLearnReq(ifname); if (virNWFilterLockIface(ifname) < 0) - return -1; + return -1; techdriver->allTeardown(ifname); diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index 5d4ef79..0e78f68 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -196,9 +196,9 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, mon_buff = virBufferContentAndReset(&mon_host); VIR_DEBUG("RADOS mon_host has been set to: %s", mon_buff); if (rados_conf_set(ptr->cluster, "mon_host", mon_buff) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to set RADOS option: %s"), - "mon_host"); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to set RADOS option: %s"), + "mon_host"); goto cleanup; } -- 1.8.5.5

--- src/util/virusb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/virusb.c b/src/util/virusb.c index 8244771..520610b 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -45,7 +45,6 @@ #define USB_ID_LEN 10 /* "1234 5678" */ #define USB_ADDR_LEN 8 /* "123:456" */ -/* For virReportOOMError() and virReportSystemError() */ #define VIR_FROM_THIS VIR_FROM_NONE VIR_LOG_INIT("util.usb"); -- 1.8.5.5

If v6present is false, this code is not reachable. Also, there is no need to check for errors twice. --- src/network/bridge_driver.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 8624f1e..149a8fd 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1535,20 +1535,15 @@ networkRadvdConfContents(virNetworkObjPtr network, char **configstr) VIR_FREE(netaddr); } - /* only create the string if we found at least one IPv6 address */ - if (v6present) { - virBufferAddLit(&configbuf, "};\n"); + virBufferAddLit(&configbuf, "};\n"); - if (virBufferError(&configbuf)) { - virReportOOMError(); - goto cleanup; - } - if (!(*configstr = virBufferContentAndReset(&configbuf))) { - virReportOOMError(); - goto cleanup; - } + if (virBufferError(&configbuf)) { + virReportOOMError(); + goto cleanup; } + *configstr = virBufferContentAndReset(&configbuf); + ret = 0; cleanup: virBufferFreeAndReset(&configbuf); -- 1.8.5.5

This function didn't report an error on OOM. Better delete it and use virStringReplace instead. :) --- src/openvz/openvz_conf.c | 40 ++-------------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index dc84b29..38d3ea7 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -343,40 +343,6 @@ openvzReadNetworkConf(virDomainDefPtr def, } -/* utility function to replace 'from' by 'to' in 'str' */ -static char* -openvz_replace(const char* str, - const char* from, - const char* to) { - const char* offset = NULL; - const char* str_start = str; - int to_len; - int from_len; - virBuffer buf = VIR_BUFFER_INITIALIZER; - - if ((!from) || (!to)) - return NULL; - from_len = strlen(from); - to_len = strlen(to); - - while ((offset = strstr(str_start, from))) - { - virBufferAdd(&buf, str_start, offset-str_start); - virBufferAdd(&buf, to, to_len); - str_start = offset + from_len; - } - - virBufferAdd(&buf, str_start, -1); - - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - return NULL; - } - - return virBufferContentAndReset(&buf); -} - - static int openvzReadFSConf(virDomainDefPtr def, int veid) @@ -418,8 +384,8 @@ openvzReadFSConf(virDomainDefPtr def, goto error; fs->type = VIR_DOMAIN_FS_TYPE_MOUNT; - if (!(fs->src = openvz_replace(temp, "$VEID", veid_str))) - goto no_memory; + if (!(fs->src = virStringReplace(temp, "$VEID", veid_str))) + goto error; VIR_FREE(veid_str); } @@ -454,8 +420,6 @@ openvzReadFSConf(virDomainDefPtr def, VIR_FREE(temp); return 0; - no_memory: - virReportOOMError(); error: VIR_FREE(temp); virDomainFSDefFree(fs); -- 1.8.5.5

Check if the buffer is in error state and report an error if it is. This replaces the pattern: if (virBufferError(buf)) { virReportOOMError(); goto cleanup; } with: if (virBufferCheckError(buf) < 0) goto cleanup; Document typical buffer usage to favor this. Also remove the redundant FreeAndReset - if an error has been set via virBufferSetError, the content is already freed. --- HACKING | 7 ++----- docs/hacking.html.in | 7 ++----- po/POTFILES.in | 1 + src/libvirt_private.syms | 1 + src/util/virbuffer.c | 31 +++++++++++++++++++++++++++++++ src/util/virbuffer.h | 17 +++++++++++++++++ 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/HACKING b/HACKING index ac3e9d7..0745d5f 100644 --- a/HACKING +++ b/HACKING @@ -776,7 +776,7 @@ Variable length string buffer ============================= If there is a need for complex string concatenations, avoid using the usual sequence of malloc/strcpy/strcat/snprintf functions and make use of the -virBuffer API described in buf.h +virBuffer API described in virbuffer.h Typical usage is as follows: @@ -794,11 +794,8 @@ Typical usage is as follows: ... - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 9c6dd26..9456520 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -948,7 +948,7 @@ <p> If there is a need for complex string concatenations, avoid using the usual sequence of malloc/strcpy/strcat/snprintf functions and - make use of the virBuffer API described in buf.h + make use of the virBuffer API described in virbuffer.h </p> <p>Typical usage is as follows:</p> @@ -968,11 +968,8 @@ ... - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/po/POTFILES.in b/po/POTFILES.in index 31a8381..d338151 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -156,6 +156,7 @@ src/util/viraudit.c src/util/virauth.c src/util/virauthconfig.c src/util/virbitmap.c +src/util/virbuffer.c src/util/vircgroup.c src/util/virclosecallbacks.c src/util/vircommand.c diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ed56103..cc5fd32 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1008,6 +1008,7 @@ virBufferAdd; virBufferAddChar; virBufferAdjustIndent; virBufferAsprintf; +virBufferCheckErrorInternal; virBufferContentAndReset; virBufferCurrentContent; virBufferError; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index eb29012..025f0ab 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -32,6 +32,7 @@ #include "virbuffer.h" #include "viralloc.h" +#include "virerror.h" /* If adding more fields, ensure to edit buf.h to match @@ -264,6 +265,36 @@ virBufferError(const virBuffer *buf) } /** + * virBufferCheckErrorInternal: + * @buf: the buffer + * + * Report an error if the buffer is in an error state. + * + * Return -1 if an error has been reported, 0 otherwise. + */ +int +virBufferCheckErrorInternal(const virBuffer *buf, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) +{ + if (buf->error == 0) + return 0; + + if (buf->error == ENOMEM) { + virReportOOMErrorFull(domcode, filename, funcname, linenr); + errno = ENOMEM; + } else { + virReportErrorHelper(domcode, VIR_ERR_INTERNAL_ERROR, filename, + funcname, linenr, "%s", + _("Invalid buffer API usage")); + errno = EINVAL; + } + return -1; +} + +/** * virBufferUse: * @buf: the usage of the string in the buffer * diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index a0cc4e6..bdfff5e 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -53,6 +53,23 @@ const char *virBufferCurrentContent(virBufferPtr buf); char *virBufferContentAndReset(virBufferPtr buf); void virBufferFreeAndReset(virBufferPtr buf); int virBufferError(const virBuffer *buf); +int virBufferCheckErrorInternal(const virBuffer *buf, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +/** + * virBufferCheckError + * + * Checks if the buffer is in error state and reports an error. + * + * Returns 0 if no error has occured, otherwise an error is reported + * and -1 is returned. + */ +# define virBufferCheckError(buf) \ + virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__, \ + __LINE__) unsigned int virBufferUse(const virBuffer *buf); void virBufferAdd(virBufferPtr buf, const char *str, int len); void virBufferAddChar(virBufferPtr buf, char c); -- 1.8.5.5

So far, we only report an error if formatting the siblings bitmap in NUMA topology fails. Be consistent and always report error in virCapabilitiesFormatXML. --- src/bhyve/bhyve_driver.c | 4 +--- src/conf/capabilities.c | 2 +- src/esx/esx_driver.c | 8 +------- src/libxl/libxl_driver.c | 3 +-- src/lxc/lxc_driver.c | 3 +-- src/parallels/parallels_driver.c | 3 +-- src/phyp/phyp_driver.c | 6 +----- src/qemu/qemu_driver.c | 3 +-- src/test/test_driver.c | 3 +-- src/uml/uml_driver.c | 3 +-- src/xen/xen_driver.c | 8 +------- src/xen/xen_hypervisor.c | 8 +------- src/xenapi/xenapi_driver.c | 8 ++------ tests/vircaps2xmltest.c | 4 +--- 14 files changed, 15 insertions(+), 51 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index eb5fc95..6c0c8b1 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -150,10 +150,8 @@ bhyveConnectGetCapabilities(virConnectPtr conn) goto cleanup; } - if (!(xml = virCapabilitiesFormatXML(caps))) { - virReportOOMError(); + if (!(xml = virCapabilitiesFormatXML(caps))) goto cleanup; - } cleanup: virObjectUnref(caps); diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 19359a5..fca461a 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1025,7 +1025,7 @@ virCapabilitiesFormatXML(virCapsPtr caps) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</capabilities>\n"); - if (virBufferError(&buf)) { + if (virBufferCheckError(&buf) < 0) { virBufferFreeAndReset(&buf); return NULL; } diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 5dd0a63..48e0cd9 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -1420,14 +1420,8 @@ static char * esxConnectGetCapabilities(virConnectPtr conn) { esxPrivate *priv = conn->privateData; - char *xml = virCapabilitiesFormatXML(priv->caps); - if (!xml) { - virReportOOMError(); - return NULL; - } - - return xml; + return virCapabilitiesFormatXML(priv->caps); } diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 646c9b9..08faa19 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -594,8 +594,7 @@ libxlConnectGetCapabilities(virConnectPtr conn) return NULL; cfg = libxlDriverConfigGet(driver); - if ((xml = virCapabilitiesFormatXML(cfg->caps)) == NULL) - virReportOOMError(); + xml = virCapabilitiesFormatXML(cfg->caps); virObjectUnref(cfg); return xml; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 3875bf3..f2bbd5e 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -232,8 +232,7 @@ static char *lxcConnectGetCapabilities(virConnectPtr conn) { if (!(caps = virLXCDriverGetCapabilities(driver, false))) return NULL; - if ((xml = virCapabilitiesFormatXML(caps)) == NULL) - virReportOOMError(); + xml = virCapabilitiesFormatXML(caps); virObjectUnref(caps); return xml; diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 411527c..b388e2d 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -186,8 +186,7 @@ parallelsConnectGetCapabilities(virConnectPtr conn) char *xml; parallelsDriverLock(privconn); - if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) - virReportOOMError(); + xml = virCapabilitiesFormatXML(privconn->caps); parallelsDriverUnlock(privconn); return xml; } diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 508e4c0..659f8db 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -3582,12 +3582,8 @@ static char * phypConnectGetCapabilities(virConnectPtr conn) { phyp_driverPtr phyp_driver = conn->privateData; - char *xml; - if ((xml = virCapabilitiesFormatXML(phyp_driver->caps)) == NULL) - virReportOOMError(); - - return xml; + return virCapabilitiesFormatXML(phyp_driver->caps); } static int diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d45a161..fd91d15 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1245,8 +1245,7 @@ static char *qemuConnectGetCapabilities(virConnectPtr conn) { if (!(caps = virQEMUDriverGetCapabilities(driver, true))) goto cleanup; - if ((xml = virCapabilitiesFormatXML(caps)) == NULL) - virReportOOMError(); + xml = virCapabilitiesFormatXML(caps); virObjectUnref(caps); cleanup: diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 0bf710a..7bfc88d 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1677,8 +1677,7 @@ static char *testConnectGetCapabilities(virConnectPtr conn) testConnPtr privconn = conn->privateData; char *xml; testDriverLock(privconn); - if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) - virReportOOMError(); + xml = virCapabilitiesFormatXML(privconn->caps); testDriverUnlock(privconn); return xml; } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index f14cfaa..62d1afe 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1310,8 +1310,7 @@ static char *umlConnectGetCapabilities(virConnectPtr conn) { return NULL; umlDriverLock(driver); - if ((xml = virCapabilitiesFormatXML(driver->caps)) == NULL) - virReportOOMError(); + xml = virCapabilitiesFormatXML(driver->caps); umlDriverUnlock(driver); return xml; diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 8c0050a..9355a4e 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -720,17 +720,11 @@ static char * xenUnifiedConnectGetCapabilities(virConnectPtr conn) { xenUnifiedPrivatePtr priv = conn->privateData; - char *xml; if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL; - if (!(xml = virCapabilitiesFormatXML(priv->caps))) { - virReportOOMError(); - return NULL; - } - - return xml; + return virCapabilitiesFormatXML(priv->caps); } static int diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 2e35edf..524b21f 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -2557,14 +2557,8 @@ char * xenHypervisorGetCapabilities(virConnectPtr conn) { xenUnifiedPrivatePtr priv = conn->privateData; - char *xml; - if (!(xml = virCapabilitiesFormatXML(priv->caps))) { - virReportOOMError(); - return NULL; - } - - return xml; + return virCapabilitiesFormatXML(priv->caps); } diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 500b78a..e3bb77e 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -445,12 +445,8 @@ xenapiConnectGetCapabilities(virConnectPtr conn) { virCapsPtr caps = ((struct _xenapiPrivate *)(conn->privateData))->caps; - if (caps) { - char *xml = virCapabilitiesFormatXML(caps); - if (!xml) - goto cleanup; - return xml; - } + if (caps) + return virCapabilitiesFormatXML(caps); cleanup: xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, _("Capabilities not available")); diff --git a/tests/vircaps2xmltest.c b/tests/vircaps2xmltest.c index 7166c98..d8b61aa 100644 --- a/tests/vircaps2xmltest.c +++ b/tests/vircaps2xmltest.c @@ -114,10 +114,8 @@ test_virCapabilitiesFormat(const void *opaque) data->max_mem_in_cell))) goto cleanup; - if (!(capsXML = virCapabilitiesFormatXML(caps))) { - fprintf(stderr, "Unable to format capabilities XML"); + if (!(capsXML = virCapabilitiesFormatXML(caps))) goto cleanup; - } if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s.xml", abs_srcdir, data->filename) < 0) -- 1.8.5.5

On Wed, Jul 02, 2014 at 12:11:00 +0200, Jano Tomko wrote:
So far, we only report an error if formatting the siblings bitmap in NUMA topology fails.
Be consistent and always report error in virCapabilitiesFormatXML. --- src/bhyve/bhyve_driver.c | 4 +--- src/conf/capabilities.c | 2 +- src/esx/esx_driver.c | 8 +------- src/libxl/libxl_driver.c | 3 +-- src/lxc/lxc_driver.c | 3 +-- src/parallels/parallels_driver.c | 3 +-- src/phyp/phyp_driver.c | 6 +----- src/qemu/qemu_driver.c | 3 +-- src/test/test_driver.c | 3 +-- src/uml/uml_driver.c | 3 +-- src/xen/xen_driver.c | 8 +------- src/xen/xen_hypervisor.c | 8 +------- src/xenapi/xenapi_driver.c | 8 ++------ tests/vircaps2xmltest.c | 4 +--- 14 files changed, 15 insertions(+), 51 deletions(-)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index eb5fc95..6c0c8b1 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -150,10 +150,8 @@ bhyveConnectGetCapabilities(virConnectPtr conn) goto cleanup; }
- if (!(xml = virCapabilitiesFormatXML(caps))) { - virReportOOMError(); + if (!(xml = virCapabilitiesFormatXML(caps))) goto cleanup; - }
cleanup: virObjectUnref(caps); diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 19359a5..fca461a 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1025,7 +1025,7 @@ virCapabilitiesFormatXML(virCapsPtr caps) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</capabilities>\n");
- if (virBufferError(&buf)) { + if (virBufferCheckError(&buf) < 0) { virBufferFreeAndReset(&buf); return NULL; }
This should be changed to if (virBufferCheckError(&buf) < 0) return NULL; Jirka

Replace: if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); virReportOOMError(); ... } with: if (virBufferCheckError(&buf) < 0) ... This should not be a functional change (unless some callers misused the virBuffer APIs - a different error would be reported then) --- src/bhyve/bhyve_driver.c | 8 +- src/conf/cpu_conf.c | 6 +- src/conf/domain_conf.c | 17 ++-- src/conf/interface_conf.c | 8 +- src/conf/network_conf.c | 12 +-- src/conf/node_device_conf.c | 9 +- src/conf/nwfilter_conf.c | 16 +--- src/conf/secret_conf.c | 6 +- src/conf/snapshot_conf.c | 5 +- src/conf/storage_conf.c | 18 ++-- src/cpu/cpu_map.c | 14 ++- src/cpu/cpu_x86.c | 5 +- src/esx/esx_driver.c | 12 +-- src/esx/esx_util.c | 12 +-- src/esx/esx_vi.c | 20 ++--- src/esx/esx_vi_methods.c | 4 +- src/hyperv/hyperv_wmi.c | 4 +- src/libxl/libxl_driver.c | 4 +- src/locking/lock_driver_sanlock.c | 5 +- src/lxc/lxc_controller.c | 8 +- src/lxc/lxc_driver.c | 44 +++------ src/network/bridge_driver.c | 8 +- src/node_device/node_device_udev.c | 8 +- src/nwfilter/nwfilter_ebiptables_driver.c | 10 +-- src/nwfilter/nwfilter_gentech_driver.c | 5 +- src/phyp/phyp_driver.c | 10 +-- src/qemu/qemu_command.c | 142 ++++++++---------------------- src/qemu/qemu_driver.c | 44 +++------ src/qemu/qemu_migration.c | 5 +- src/qemu/qemu_monitor.c | 5 +- src/qemu/qemu_monitor_text.c | 9 +- src/rpc/virnetsocket.c | 4 +- src/rpc/virnetsshsession.c | 8 +- src/storage/storage_backend.c | 6 +- src/storage/storage_backend_rbd.c | 6 +- src/uml/uml_conf.c | 4 +- src/util/vircommand.c | 5 +- src/util/virconf.c | 10 +-- src/util/virnetdevopenvswitch.c | 4 +- src/util/virstoragefile.c | 4 +- src/util/virstring.c | 8 +- src/util/virsysinfo.c | 4 +- src/util/virsystemd.c | 8 +- src/util/viruri.c | 5 +- src/vmx/vmx.c | 4 +- src/xen/xen_driver.c | 4 +- src/xen/xend_internal.c | 9 +- src/xenapi/xenapi_utils.c | 5 +- src/xenxs/xen_sxpr.c | 12 +-- src/xenxs/xen_xm.c | 17 +--- tests/domainsnapshotxml2xmltest.c | 4 +- 51 files changed, 158 insertions(+), 456 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 6c0c8b1..a3b043d 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -258,10 +258,8 @@ bhyveConnectGetSysinfo(virConnectPtr conn, unsigned int flags) if (virSysinfoFormat(&buf, privconn->hostsysinfo) < 0) return NULL; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } @@ -701,10 +699,8 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, virBufferAddChar(&buf, '\n'); virBufferAdd(&buf, virCommandToString(cmd), -1); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } ret = virBufferContentAndReset(&buf); diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index ebdaa19..811893d 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -494,13 +494,11 @@ virCPUDefFormat(virCPUDefPtr def, if (virCPUDefFormatBufFull(&buf, def, flags) < 0) goto cleanup; - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto cleanup; return virBufferContentAndReset(&buf); - no_memory: - virReportOOMError(); cleanup: virBufferFreeAndReset(&buf); return NULL; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f7fe64b..e1ce585 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11335,11 +11335,8 @@ virDomainDefParseXML(xmlDocPtr xml, } } - if (virBufferError(&buffer)) { - virReportOOMError(); - virBufferFreeAndReset(&buffer); + if (virBufferCheckError(&buffer) < 0) goto error; - } string = virBufferContentAndReset(&buffer); @@ -17972,13 +17969,11 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</domain>\n"); - if (virBufferError(buf)) - goto no_memory; + if (virBufferCheckError(buf) < 0) + goto error; return 0; - no_memory: - virReportOOMError(); error: virBufferFreeAndReset(buf); return -1; @@ -18030,13 +18025,11 @@ virDomainObjFormat(virDomainXMLOptionPtr xmlopt, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</domstatus>\n"); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto error; return virBufferContentAndReset(&buf); - no_memory: - virReportOOMError(); error: virBufferFreeAndReset(&buf); return NULL; diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 141b4a2..103e878 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -1101,11 +1101,11 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</interface>\n"); - if (virBufferError(buf)) - goto no_memory; + if (virBufferCheckError(buf) < 0) + goto cleanup; + return 0; - no_memory: - virReportOOMError(); + cleanup: return -1; } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index f391056..909631b 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2830,13 +2830,11 @@ virNetworkDefFormat(const virNetworkDef *def, if (virNetworkDefFormatBuf(&buf, def, flags) < 0) goto error; - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto error; return virBufferContentAndReset(&buf); - no_memory: - virReportOOMError(); error: virBufferFreeAndReset(&buf); return NULL; @@ -2871,13 +2869,11 @@ virNetworkObjFormat(virNetworkObjPtr net, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</networkstatus>"); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto error; return virBufferContentAndReset(&buf); - no_memory: - virReportOOMError(); error: virBufferFreeAndReset(&buf); return NULL; diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index cb85914..30aa477 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -555,15 +555,10 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</device>\n"); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + return NULL; return virBufferContentAndReset(&buf); - - no_memory: - virReportOOMError(); - virBufferFreeAndReset(&buf); - return NULL; } /** diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index c675967..0f633da 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -967,10 +967,8 @@ virNWFilterPrintTCPFlags(uint8_t flags) { virBuffer buf = VIR_BUFFER_INITIALIZER; printTCPFlags(&buf, flags); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } @@ -2548,11 +2546,8 @@ virNWFilterIsAllowedChain(const char *chainname) printed = true; } - if (virBufferError(&buf)) { - virReportOOMError(); - virBufferFreeAndReset(&buf); + if (virBufferCheckError(&buf) < 0) goto err_exit; - } msg = virBufferContentAndReset(&buf); @@ -3484,14 +3479,11 @@ virNWFilterDefFormat(const virNWFilterDef *def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</filter>\n"); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto err_exit; return virBufferContentAndReset(&buf); - no_memory: - virReportOOMError(); - err_exit: virBufferFreeAndReset(&buf); return NULL; diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index d85bb4e..f958240 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -318,13 +318,11 @@ virSecretDefFormat(const virSecretDef *def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</secret>\n"); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto error; return virBufferContentAndReset(&buf); - no_memory: - virReportOOMError(); error: virBufferFreeAndReset(&buf); return NULL; diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 441162c..240ca90 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -705,11 +705,8 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</domainsnapshot>\n"); - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index c8df5b2..8cf470b 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1239,13 +1239,11 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</pool>\n"); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto cleanup; return virBufferContentAndReset(&buf); - no_memory: - virReportOOMError(); cleanup: virBufferFreeAndReset(&buf); return NULL; @@ -1662,13 +1660,11 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</volume>\n"); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto cleanup; return virBufferContentAndReset(&buf); - no_memory: - virReportOOMError(); cleanup: virBufferFreeAndReset(&buf); return NULL; @@ -2013,13 +2009,11 @@ virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</sources>\n"); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto cleanup; return virBufferContentAndReset(&buf); - no_memory: - virReportOOMError(); cleanup: virBufferFreeAndReset(&buf); return NULL; diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index 4706f67..b77f688 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -112,12 +112,14 @@ int cpuMapLoad(const char *arch, goto cleanup; } - if ((ctxt = xmlXPathNewContext(xml)) == NULL) - goto no_memory; + if ((ctxt = xmlXPathNewContext(xml)) == NULL) { + virReportOOMError(); + goto cleanup; + } virBufferAsprintf(&buf, "./arch[@name='%s']", arch); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto cleanup; xpath = virBufferContentAndReset(&buf); @@ -146,8 +148,4 @@ int cpuMapLoad(const char *arch, VIR_FREE(mapfile); return ret; - - no_memory: - virReportOOMError(); - goto cleanup; } diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 235fa49..fb89086 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1221,11 +1221,8 @@ x86CPUDataFormat(const virCPUData *data) } virBufferAddLit(&buf, "</cpudata>\n"); - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 48e0cd9..d2cc230 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -340,10 +340,8 @@ esxFormatVMXFileName(const char *fileName, void *opaque) virBufferAddChar(&buffer, separator); virBufferAdd(&buffer, directoryAndFileName, -1); - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto cleanup; - } result = virBufferContentAndReset(&buffer); } else if (*fileName == '/') { @@ -2701,10 +2699,8 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) virBufferAddLit(&buffer, "&dsName="); virBufferURIEncodeString(&buffer, datastoreName); - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto cleanup; - } url = virBufferContentAndReset(&buffer); @@ -3169,10 +3165,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) virBufferAddLit(&buffer, "&dsName="); virBufferURIEncodeString(&buffer, datastoreName); - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto cleanup; - } url = virBufferContentAndReset(&buffer); diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index f84ecd5..9a41241 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -425,12 +425,8 @@ esxUtil_EscapeBase64(const char *string) } } - if (virBufferError(&buffer)) { - virReportOOMError(); - virBufferFreeAndReset(&buffer); - + if (virBufferCheckError(&buffer) < 0) return NULL; - } return virBufferContentAndReset(&buffer); } @@ -498,12 +494,8 @@ esxUtil_EscapeForXml(const char *string) virBufferEscapeString(&buffer, "%s", string); - if (virBufferError(&buffer)) { - virReportOOMError(); - virBufferFreeAndReset(&buffer); - + if (virBufferCheckError(&buffer) < 0) return NULL; - } return virBufferContentAndReset(&buffer); } diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 6188139..3f5becb 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -426,10 +426,8 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content, goto cleanup; } - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto cleanup; - } if (length) { *length = virBufferUse(&buffer); @@ -1046,10 +1044,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto cleanup; - } ctx->datacenterPath = virBufferContentAndReset(&buffer); @@ -1116,10 +1112,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto cleanup; - } ctx->computeResourcePath = virBufferContentAndReset(&buffer); @@ -1259,10 +1253,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, goto cleanup; } - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto cleanup; - } (*response)->content = virBufferContentAndReset(&buffer); @@ -4243,10 +4235,8 @@ esxVI_HandleVirtualMachineQuestion ++answerIndex; } - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto cleanup; - } possibleAnswers = virBufferContentAndReset(&buffer); } diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c index 0fdd0cd..184b01f 100644 --- a/src/esx/esx_vi_methods.c +++ b/src/esx/esx_vi_methods.c @@ -126,10 +126,8 @@ virBufferAddLit(&buffer, "</"#_name">"); \ virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER); \ \ - if (virBufferError(&buffer)) { \ - virReportOOMError(); \ + if (virBufferCheckError(&buffer) < 0) \ goto cleanup; \ - } \ \ request = virBufferContentAndReset(&buffer); \ \ diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 6e6f629..acb705c 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -128,10 +128,8 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root, return -1; } - if (virBufferError(query)) { - virReportOOMError(); + if (virBufferCheckError(query) < 0) return -1; - } serializerContext = wsmc_get_serialization_context(priv->client); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 08faa19..f195b7e 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -544,10 +544,8 @@ libxlConnectGetSysinfo(virConnectPtr conn, unsigned int flags) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) return NULL; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index d0339a6..ea43051 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -819,11 +819,8 @@ virLockManagerSanlockRegisterKillscript(int sock, virBufferEscape(&buf, '\\', "\\ ", "%s", virDomainLockFailureTypeToString(action)); - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } /* Unfortunately, sanlock_killpath() does not use const for either * path or args even though it will just copy them into its own diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 38acdff..bc1b962 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1181,8 +1181,8 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map, virBufferAsprintf(&map_value, "%u %u %u\n", map[i].start, map[i].target, map[i].count); - if (virBufferError(&map_value)) - goto no_memory; + if (virBufferCheckError(&map_value) < 0) + goto cleanup; VIR_DEBUG("Set '%s' to '%s'", path, virBufferCurrentContent(&map_value)); @@ -1195,10 +1195,6 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map, cleanup: virBufferFreeAndReset(&map_value); return ret; - - no_memory: - virReportOOMError(); - goto cleanup; } /** diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f2bbd5e..7f2655b 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2738,10 +2738,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].weight); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -2767,10 +2765,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].riops); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -2796,10 +2792,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].wiops); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -2825,10 +2819,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].rbps); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -2854,10 +2846,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].wbps); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -2902,10 +2892,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].weight); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) @@ -2936,10 +2924,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].riops); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) @@ -2969,10 +2955,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].wiops); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) @@ -3002,10 +2986,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].rbps); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) @@ -3036,10 +3018,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].wbps); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) @@ -5363,10 +5343,8 @@ lxcConnectGetSysinfo(virConnectPtr conn, unsigned int flags) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) return NULL; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 149a8fd..6a2e760 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -180,10 +180,10 @@ networkRunHook(virNetworkObjPtr network, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</hookData>"); - if (virBufferError(&buf) || - !(xml = virBufferContentAndReset(&buf))) + if (virBufferCheckError(&buf) < 0) goto cleanup; + xml = virBufferContentAndReset(&buf); hookret = virHookCall(VIR_HOOK_DRIVER_NETWORK, network->def->name, op, sub_op, NULL, xml, NULL); @@ -1537,10 +1537,8 @@ networkRadvdConfContents(virNetworkObjPtr network, char **configstr) virBufferAddLit(&configbuf, "};\n"); - if (virBufferError(&configbuf)) { - virReportOOMError(); + if (virBufferCheckError(&configbuf) < 0) goto cleanup; - } *configstr = virBufferContentAndReset(&configbuf); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 8a2e5ff..28d2953 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -333,12 +333,8 @@ static int udevGenerateDeviceName(struct udev_device *device, virBufferAsprintf(&buf, "_%s", s); } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - VIR_ERROR(_("Buffer error when generating device name for device " - "with sysname '%s'"), udev_device_get_sysname(device)); - ret = -1; - } + if (virBufferCheckError(&buf) < 0) + return -1; def->name = virBufferContentAndReset(&buf); diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index 5cb0b74..1701d62 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -306,11 +306,8 @@ _printDataType(virNWFilterVarCombIterPtr vars, } } - if (virBufferError(&vb)) { - virReportOOMError(); - virBufferFreeAndReset(&vb); + if (virBufferCheckError(&vb) < 0) return -1; - } flags = virBufferContentAndReset(&vb); @@ -1560,11 +1557,8 @@ printStateMatchFlags(int32_t flags, char **bufptr) "", flags, false); - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return -1; - } *bufptr = virBufferContentAndReset(&buf); return 0; } diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 8226195..6c7f77b 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -259,11 +259,8 @@ virNWFilterPrintVars(virHashTablePtr vars, virHashForEach(vars, printString, &ps); - if (virBufferError(&ps.buf)) { - virBufferFreeAndReset(&ps.buf); - virReportOOMError(); + if (virBufferCheckError(&ps.buf) < 0) return NULL; - } return virBufferContentAndReset(&ps.buf); } diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 659f8db..056d289 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -186,11 +186,8 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status, channel = NULL; VIR_FREE(buffer); - if (virBufferError(&tex_ret)) { - virBufferFreeAndReset(&tex_ret); - virReportOOMError(); + if (virBufferCheckError(&tex_ret) < 0) return NULL; - } return virBufferContentAndReset(&tex_ret); err: @@ -211,11 +208,8 @@ phypExecBuffer(LIBSSH2_SESSION *session, virBufferPtr buf, int *exit_status, char *cmd; char *ret; - if (virBufferError(buf)) { - virBufferFreeAndReset(buf); - virReportOOMError(); + if (virBufferCheckError(buf) < 0) return NULL; - } cmd = virBufferContentAndReset(buf); ret = phypExec(session, cmd, exit_status, conn); VIR_FREE(cmd); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 4724382..0c1f0f1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2962,10 +2962,8 @@ qemuBuildNetworkDriveURI(int protocol, if (src) virBufferAsprintf(&buf, ":exportname=%s", src); - if (virBufferError(&buf) < 0) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } ret = virBufferContentAndReset(&buf); goto cleanup; @@ -3098,10 +3096,8 @@ qemuBuildNetworkDriveURI(int protocol, } } - if (virBufferError(&buf) < 0) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } ret = virBufferContentAndReset(&buf); break; @@ -3557,10 +3553,8 @@ qemuBuildDriveStr(virConnectPtr conn, disk->blkdeviotune.write_iops_sec); } - if (virBufferError(&opt)) { - virReportOOMError(); + if (virBufferCheckError(&opt) < 0) goto error; - } return virBufferContentAndReset(&opt); @@ -3899,10 +3893,8 @@ qemuBuildDriveDevStr(virDomainDefPtr def, } } - if (virBufferError(&opt)) { - virReportOOMError(); + if (virBufferCheckError(&opt) < 0) goto error; - } return virBufferContentAndReset(&opt); @@ -3975,10 +3967,8 @@ char *qemuBuildFSStr(virDomainFSDefPtr fs, } } - if (virBufferError(&opt)) { - virReportOOMError(); + if (virBufferCheckError(&opt) < 0) goto error; - } return virBufferContentAndReset(&opt); @@ -4009,10 +3999,8 @@ qemuBuildFSDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&opt, def, &fs->info, qemuCaps) < 0) goto error; - if (virBufferError(&opt)) { - virReportOOMError(); + if (virBufferCheckError(&opt) < 0) goto error; - } return virBufferContentAndReset(&opt); @@ -4252,10 +4240,8 @@ qemuBuildControllerDevStr(virDomainDefPtr domainDef, if (qemuBuildDeviceAddressStr(&buf, domainDef, &def->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -4365,10 +4351,8 @@ qemuBuildNicDevStr(virDomainDefPtr def, if (bootindex && virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX)) virBufferAsprintf(&buf, ",bootindex=%d", bootindex); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -4502,11 +4486,8 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, virObjectUnref(cfg); - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } @@ -4530,10 +4511,8 @@ qemuBuildWatchdogDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -4571,10 +4550,8 @@ qemuBuildMemballoonDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -4598,10 +4575,8 @@ qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev) goto error; } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -4634,10 +4609,8 @@ qemuBuildUSBInputDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -4687,10 +4660,8 @@ qemuBuildSoundDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &sound->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -4802,10 +4773,8 @@ qemuBuildDeviceVideoStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &video->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -4889,10 +4858,8 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def, if (qemuBuildRomStr(&buf, dev->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5010,10 +4977,8 @@ qemuBuildRedirdevDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5050,10 +5015,8 @@ qemuBuildUSBHostdevDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5088,10 +5051,8 @@ qemuBuildHubDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5157,10 +5118,8 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev, } } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } VIR_FREE(sg); return virBufferContentAndReset(&buf); @@ -5222,10 +5181,8 @@ qemuBuildSCSIHostdevDevStr(virDomainDefPtr def, if (dev->info->bootIndex) virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); error: @@ -5342,10 +5299,8 @@ qemuBuildChrChardevStr(virDomainChrSourceDefPtr dev, const char *alias, goto error; } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5438,10 +5393,8 @@ qemuBuildChrArgStr(virDomainChrSourceDefPtr dev, const char *prefix) break; } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5518,10 +5471,8 @@ qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev, } else { virBufferAsprintf(&buf, ",id=%s", dev->info.alias); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5550,10 +5501,8 @@ qemuBuildSclpDevStr(virDomainChrDefPtr dev) } virBufferAsprintf(&buf, ",chardev=char%s,id=%s", dev->info.alias, dev->info.alias); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5703,10 +5652,8 @@ static char *qemuBuildTPMBackendStr(const virDomainDef *def, goto error; } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5741,10 +5688,8 @@ static char *qemuBuildTPMDevStr(const virDomainDef *def, virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s", model, tpm->info.alias, tpm->info.alias); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5777,10 +5722,8 @@ static char *qemuBuildSmbiosBiosStr(virSysinfoDefPtr def) if (def->bios_release) virBufferAsprintf(&buf, ",release=%s", def->bios_release); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5824,10 +5767,8 @@ static char *qemuBuildSmbiosSystemStr(virSysinfoDefPtr def, bool skip_uuid) if (def->system_family) virBufferAsprintf(&buf, ",family=%s", def->system_family); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -5944,10 +5885,8 @@ qemuBuildClockArgStr(virDomainClockDefPtr def) } } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } return virBufferContentAndReset(&buf); @@ -6185,10 +6124,8 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver, } } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } *opt = virBufferContentAndReset(&buf); @@ -6390,11 +6327,8 @@ qemuBuildSmpArgStr(const virDomainDef *def, return NULL; } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } @@ -6432,10 +6366,8 @@ qemuBuildNumaArgStr(const virDomainDef *def, virCommandPtr cmd) 1024) * 1024; virBufferAsprintf(&buf, ",mem=%d", def->cpu->cells[i].mem / 1024); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } virCommandAddArgBuffer(cmd, &buf); } @@ -7690,10 +7622,8 @@ qemuBuildCommandLine(virConnectPtr conn, if (boot_nparams > 0) { virCommandAddArg(cmd, "-boot"); - if (virBufferError(&boot_buf)) { - virReportOOMError(); + if (virBufferCheckError(&boot_buf) < 0) goto error; - } if (boot_nparams < 2 || emitBootindex) { virCommandAddArgBuffer(cmd, &boot_buf); @@ -9167,10 +9097,8 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, } } - if (virBufferError(&cmd)) { - virReportOOMError(); + if (virBufferCheckError(&cmd) < 0) goto error; - } *deviceStr = virBufferContentAndReset(&cmd); return 0; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index fd91d15..2a01c9c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1203,10 +1203,8 @@ qemuConnectGetSysinfo(virConnectPtr conn, unsigned int flags) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) return NULL; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } @@ -8005,10 +8003,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].weight); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -8034,10 +8030,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].riops); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -8063,10 +8057,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].wiops); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -8092,10 +8084,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].rbps); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -8121,10 +8111,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].wbps); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (virTypedParameterAssign(param, @@ -8173,10 +8161,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].weight); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) @@ -8207,10 +8193,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].riops); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) @@ -8240,10 +8224,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].wiops); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) @@ -8273,10 +8255,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].rbps); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) @@ -8307,10 +8287,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].wbps); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } param->value.s = virBufferContentAndReset(&buf); } if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 99d4c4a..dc25242 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -666,11 +666,8 @@ static char *qemuMigrationCookieXMLFormatStr(virQEMUDriverPtr driver, return NULL; } - if (virBufferError(&buf)) { - virReportOOMError(); - virBufferFreeAndReset(&buf); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 80d7b9d..739fe61 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2297,11 +2297,8 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon, /* Migrate to file */ virBufferEscapeShell(&buf, target); - if (virBufferError(&buf)) { - virReportOOMError(); - virBufferFreeAndReset(&buf); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } safe_target = virBufferContentAndReset(&buf); /* Two dd processes, sharing the same stdout, are necessary to diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index fea484d..fc54a11 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -1576,11 +1576,8 @@ int qemuMonitorTextMigrate(qemuMonitorPtr mon, virBufferAddLit(&extra, " -b"); if (flags & QEMU_MONITOR_MIGRATE_NON_SHARED_INC) virBufferAddLit(&extra, " -i"); - if (virBufferError(&extra)) { - virBufferFreeAndReset(&extra); - virReportOOMError(); + if (virBufferCheckError(&extra) < 0) goto cleanup; - } extrastr = virBufferContentAndReset(&extra); if (virAsprintf(&cmd, "migrate %s\"%s\"", extrastr ? extrastr : "", @@ -2911,10 +2908,8 @@ int qemuMonitorTextSendKey(qemuMonitorPtr mon, if (holdtime) virBufferAsprintf(&buf, " %u", holdtime); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return -1; - } cmd = virBufferContentAndReset(&buf); if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index bdf2929..a94b2bc 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -728,10 +728,8 @@ int virNetSocketNewConnectSSH(const char *nodename, virCommandAddArgList(cmd, nodename, "sh", "-c", NULL); virBufferEscapeShell(&buf, netcat); - if (virBufferError(&buf)) { + if (virBufferCheckError(&buf) < 0) { virCommandFree(cmd); - virBufferFreeAndReset(&buf); - virReportOOMError(); return -1; } quoted = virBufferContentAndReset(&buf); diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 9d09699..7f47b29 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -372,10 +372,8 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) virBufferAsprintf(&buff, "%02hhX:", keyhash[i]); virBufferTrim(&buff, ":", 1); - if (virBufferError(&buff) != 0) { - virReportOOMError(); + if (virBufferCheckError(&buff) < 0) return -1; - } keyhashstr = virBufferContentAndReset(&buff); @@ -439,10 +437,8 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) * to port number */ virBufferAsprintf(&buff, "[%s]:%d", sess->hostname, sess->port); - if (virBufferError(&buff) != 0) { - virReportOOMError(); + if (virBufferCheckError(&buff) < 0) return -1; - } hostnameStr = virBufferContentAndReset(&buff); diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index b38af52..e83a108 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -760,14 +760,12 @@ virStorageBackendCreateQemuImgOpts(char **opts, virBufferTrim(&buf, ",", -1); - if (virBufferError(&buf)) - goto no_memory; + if (virBufferCheckError(&buf) < 0) + goto error; *opts = virBufferContentAndReset(&buf); return 0; - no_memory: - virReportOOMError(); error: virBufferFreeAndReset(&buf); return -1; diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index 0e78f68..c456e65 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -188,10 +188,8 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, } } - if (virBufferError(&mon_host)) { - virReportOOMError(); - goto cleanup; - } + if (virBufferCheckError(&mon_host) < 0) + goto cleanup; mon_buff = virBufferContentAndReset(&mon_host); VIR_DEBUG("RADOS mon_host has been set to: %s", mon_buff); diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index 464d56d..7a206d2 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -266,10 +266,8 @@ umlBuildCommandLineNet(virConnectPtr conn, def->data.socket.port); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 448f6d3..e775ba6 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1843,11 +1843,8 @@ virCommandToString(virCommandPtr cmd) virBufferEscapeShell(&buf, cmd->args[i]); } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/util/virconf.c b/src/util/virconf.c index 55de0e9..e221fb5 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -979,11 +979,8 @@ virConfWriteFile(const char *filename, virConfPtr conf) cur = cur->next; } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return -1; - } fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -1035,11 +1032,8 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf) cur = cur->next; } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return -1; - } use = virBufferUse(&buf); content = virBufferContentAndReset(&buf); diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index d6a16c6..9bcbfb1 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -119,10 +119,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } virCommandAddArg(cmd, virBufferCurrentContent(&buf)); } else if (virtVlan->nTags) { virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]); diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 0c50de1..cd3c4c3 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1946,10 +1946,8 @@ virStorageFileCanonicalizeFormatPath(char **components, virBufferAdd(&buf, components[i], -1); } - if (virBufferError(&buf) != 0) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } /* if the output string is empty just return an empty string */ if (!(ret = virBufferContentAndReset(&buf))) diff --git a/src/util/virstring.c b/src/util/virstring.c index 35b99a5..b14f785 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -158,10 +158,8 @@ char *virStringJoin(const char **strings, virBufferAdd(&buf, delim, -1); strings++; } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } ret = virBufferContentAndReset(&buf); if (!ret) ignore_value(VIR_STRDUP(ret, "")); @@ -909,10 +907,8 @@ virStringReplace(const char *haystack, tmp1 = tmp2; } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 40c78ca..1bb6392 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -1064,10 +1064,8 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</sysinfo>\n"); - if (virBufferError(buf)) { - virReportOOMError(); + if (virBufferCheckError(buf) < 0) return -1; - } return 0; } diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index ad15a18..ddfc047 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -94,10 +94,8 @@ char *virSystemdMakeScopeName(const char *name, virSystemdEscapeName(&buf, name); virBufferAddLit(&buf, ".scope"); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } @@ -113,10 +111,8 @@ char *virSystemdMakeSliceName(const char *partition) virSystemdEscapeName(&buf, partition); virBufferAddLit(&buf, ".slice"); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/util/viruri.c b/src/util/viruri.c index 661ba76..eb47bbe 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -286,11 +286,8 @@ char *virURIFormatParams(virURIPtr uri) } } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 30ee384..cd6c51e 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -3344,10 +3344,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe } /* Get final VMX output */ - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto cleanup; - } vmx = virBufferContentAndReset(&buffer); diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 9355a4e..79df3ee 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -659,10 +659,8 @@ xenUnifiedConnectGetSysinfo(virConnectPtr conn ATTRIBUTE_UNUSED, if (virSysinfoFormat(&buf, hostsysinfo) < 0) return NULL; - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return NULL; - } return virBufferContentAndReset(&buf); } diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 03fdde1..b2797b6 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -505,11 +505,8 @@ xend_op_ext(virConnectPtr xend, const char *path, const char *key, va_list ap) virBufferAddChar(&buf, '&'); } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) return -1; - } content = virBufferContentAndReset(&buf); VIR_DEBUG("xend op: %s\n", content); @@ -2611,10 +2608,8 @@ xenDaemonDomainSetAutostart(virConnectPtr conn, goto error; } - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferCheckError(&buffer) < 0) goto error; - } content = virBufferContentAndReset(&buffer); diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c index 156e0c8..8b28914 100644 --- a/src/xenapi/xenapi_utils.c +++ b/src/xenapi/xenapi_utils.c @@ -284,11 +284,8 @@ mapDomainPinVcpu(unsigned char *cpumap, int maplen) } } } - if (virBufferError(&buf)) { - virReportOOMError(); - virBufferFreeAndReset(&buf); + if (virBufferCheckError(&buf) < 0) return NULL; - } ret = virBufferContentAndReset(&buf); len = strlen(ret); if (len > 0 && ret[len - 1] == ',') diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index aacf74c..38b8423 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -1693,10 +1693,8 @@ xenFormatSxprChr(virDomainChrDefPtr def, return -1; } - if (virBufferError(buf)) { - virReportOOMError(); + if (virBufferCheckError(buf) < 0) return -1; - } return 0; } @@ -2118,10 +2116,8 @@ xenFormatSxprSound(virDomainDefPtr def, virBufferEscapeSexpr(buf, "%s", str); } - if (virBufferError(buf)) { - virReportOOMError(); + if (virBufferCheckError(buf) < 0) return -1; - } return 0; } @@ -2551,10 +2547,8 @@ xenFormatSxpr(virConnectPtr conn, virBufferAddLit(&buf, ")"); /* closes (vm */ - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto error; - } bufout = virBufferContentAndReset(&buf); VIR_DEBUG("Formatted sexpr: \n%s", bufout); diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 2cd6d4c..2b28150 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1261,10 +1261,8 @@ xenFormatXMDisk(virConfValuePtr list, return -1; } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } if (VIR_ALLOC(val) < 0) goto cleanup; @@ -1300,10 +1298,8 @@ static int xenFormatXMSerial(virConfValuePtr list, } else { virBufferAddLit(&buf, "none"); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } if (VIR_ALLOC(val) < 0) goto cleanup; @@ -1406,10 +1402,8 @@ static int xenFormatXMNet(virConnectPtr conn, virBufferAsprintf(&buf, ",vifname=%s", net->ifname); - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } if (VIR_ALLOC(val) < 0) goto cleanup; @@ -1861,11 +1855,8 @@ virConfPtr xenFormatXM(virConnectPtr conn, virBufferAsprintf(&buf, ",keymap=%s", def->graphics[0]->data.vnc.keymap); } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } vfbstr = virBufferContentAndReset(&buf); diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c index 6d20181..1b3a28f 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -58,10 +58,8 @@ testFilterXML(char *xml) virBufferStrcat(&buf, *xmlLine, "\n", NULL); } - if (virBufferError(&buf)) { - virReportOOMError(); + if (virBufferCheckError(&buf) < 0) goto cleanup; - } ret = virBufferContentAndReset(&buf); -- 1.8.5.5

It sets the errno on all other errors, do it here too. Also report an error. --- src/lxc/lxc_fuse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index ee1561c..a3a1275 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -208,8 +208,10 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def, virBufferAdd(new_meminfo, line, -1); } - if (virBufferError(new_meminfo)) + if (virBufferCheckError(new_meminfo) < 0) { + res = -errno; goto cleanup; + } copied += strlen(line); if (copied > size) -- 1.8.5.5

They report errors in all other cases. --- src/lxc/lxc_container.c | 2 +- src/qemu/qemu_capabilities.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index fd8ab16..4d89677 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -223,7 +223,7 @@ static virCommandPtr lxcContainerBuildInitCmd(virDomainDefPtr vmDef, } virBufferTrim(&buf, NULL, 1); - if (virBufferError(&buf)) + if (virBufferCheckError(&buf) < 0) return NULL; virUUIDFormat(vmDef->uuid, uuidstr); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 8e0a550..751c143 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2686,7 +2686,7 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const char *filename) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</qemuCaps>\n"); - if (virBufferError(&buf)) + if (virBufferCheckError(&buf) < 0) goto cleanup; xml = virBufferContentAndReset(&buf); -- 1.8.5.5

The functions called here report an OOM error when the allocation fails, or quietly return -1 on wrong usage (which is not the case here) --- src/qemu/qemu_monitor_json.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index bedd959..85168eb 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5220,7 +5220,6 @@ qemuMonitorJSONBuildUnixSocketAddress(const char *path) return addr; error: - virReportOOMError(); virJSONValueFree(data); virJSONValueFree(addr); return NULL; @@ -5415,7 +5414,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, if (!(backend = virJSONValueNewObject()) || !(data = virJSONValueNewObject())) { - goto no_memory; + goto error; } switch ((virDomainChrType) chr->type) { @@ -5431,14 +5430,14 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, case VIR_DOMAIN_CHR_TYPE_FILE: backend_type = "file"; if (virJSONValueObjectAppendString(data, "out", chr->data.file.path) < 0) - goto no_memory; + goto error; break; case VIR_DOMAIN_CHR_TYPE_DEV: backend_type = STRPREFIX(chrID, "parallel") ? "parallel" : "serial"; if (virJSONValueObjectAppendString(data, "device", chr->data.file.path) < 0) - goto no_memory; + goto error; break; case VIR_DOMAIN_CHR_TYPE_TCP: @@ -5447,7 +5446,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, chr->data.tcp.service); if (!addr || virJSONValueObjectAppend(data, "addr", addr) < 0) - goto no_memory; + goto error; addr = NULL; telnet = chr->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET; @@ -5455,7 +5454,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, if (virJSONValueObjectAppendBoolean(data, "wait", false) < 0 || virJSONValueObjectAppendBoolean(data, "telnet", telnet) < 0 || virJSONValueObjectAppendBoolean(data, "server", chr->data.tcp.listen) < 0) - goto no_memory; + goto error; break; case VIR_DOMAIN_CHR_TYPE_UDP: @@ -5464,7 +5463,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, chr->data.udp.connectService); if (!addr || virJSONValueObjectAppend(data, "addr", addr) < 0) - goto no_memory; + goto error; addr = NULL; break; @@ -5474,12 +5473,12 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, if (!addr || virJSONValueObjectAppend(data, "addr", addr) < 0) - goto no_memory; + goto error; addr = NULL; if (virJSONValueObjectAppendBoolean(data, "wait", false) < 0 || virJSONValueObjectAppendBoolean(data, "server", chr->data.nix.listen) < 0) - goto no_memory; + goto error; break; case VIR_DOMAIN_CHR_TYPE_SPICEVMC: @@ -5496,7 +5495,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, if (virJSONValueObjectAppendString(backend, "type", backend_type) < 0 || virJSONValueObjectAppend(backend, "data", data) < 0) - goto no_memory; + goto error; data = NULL; if (!(ret = qemuMonitorJSONMakeCommand("chardev-add", @@ -5507,8 +5506,6 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, return ret; - no_memory: - virReportOOMError(); error: virJSONValueFree(addr); virJSONValueFree(data); -- 1.8.5.5

--- src/libxl/libxl_driver.c | 5 +++-- src/qemu/qemu_command.c | 8 ++------ src/qemu/qemu_hotplug.c | 4 +--- src/util/viruri.c | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index f195b7e..9aec78d 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3983,11 +3983,12 @@ libxlDomainGetNumaParameters(virDomainPtr dom, if (numnodes <= 0) goto cleanup; - if (libxl_node_bitmap_alloc(priv->ctx, &nodemap, 0) || - !(nodes = virBitmapNew(numnodes))) { + if (libxl_node_bitmap_alloc(priv->ctx, &nodemap, 0)) { virReportOOMError(); goto cleanup; } + if (!(nodes = virBitmapNew(numnodes))) + goto cleanup; rc = libxl_domain_get_nodeaffinity(priv->ctx, vm->def->id, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 0c1f0f1..6d3cc07 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9113,10 +9113,8 @@ qemuBuildParallelChrDeviceStr(char **deviceStr, virDomainChrDefPtr chr) { if (virAsprintf(deviceStr, "isa-parallel,chardev=char%s,id=%s", - chr->info.alias, chr->info.alias) < 0) { - virReportOOMError(); + chr->info.alias, chr->info.alias) < 0) return -1; - } return 0; } @@ -9139,10 +9137,8 @@ qemuBuildChannelChrDeviceStr(char **deviceStr, if (virAsprintf(deviceStr, "user,guestfwd=tcp:%s:%i-chardev:char%s,id=user-%s", - addr, port, chr->info.alias, chr->info.alias) < 0) { - virReportOOMError(); + addr, port, chr->info.alias, chr->info.alias) < 0) goto cleanup; - } break; case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 5e8aa4e..3060dbc 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1450,10 +1450,8 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, if (qemuBuildChrDeviceStr(&devstr, vm->def, chr, priv->qemuCaps) < 0) return ret; - if (virAsprintf(&charAlias, "char%s", chr->info.alias) < 0) { - virReportOOMError(); + if (virAsprintf(&charAlias, "char%s", chr->info.alias) < 0) goto cleanup; - } if (qemuDomainChrInsert(vmdef, chr) < 0) goto cleanup; diff --git a/src/util/viruri.c b/src/util/viruri.c index eb47bbe..1bb3e97 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -120,7 +120,7 @@ virURIParseParams(virURIPtr uri) if (virURIParamAppend(uri, name, value ? value : "") < 0) { VIR_FREE(name); VIR_FREE(value); - goto no_memory; + return -1; } VIR_FREE(name); VIR_FREE(value); -- 1.8.5.5

On Wed, Jul 02, 2014 at 12:10:53 +0200, Jano Tomko wrote:
Patches 1-3 don't touch any code 4-5 no functional change 6 introduces a new function 7-8 have no functional change unless virBuffer API is misused (that case resulted in an OOM error before, now it's an internal error) 9-10 add OOM error reporting to a few functions 11-12 remove double OOM error reporting
Ján Tomko (12): Fix indentation in bridge driver More indentation fixes usb: Remove redundant comment Remove useless condition in networkRadvdConfContents Use virStringReplace instead of openvz_replace Introduce virBufferCheckError Report errors in virCapabilitiesFormatXML Use virBufferCheckError everywhere we report OOM error Set errno on OOM in lxcProcReadMeminfo Add OOM error reporting to a few fucntions Remove double OOM error reporting from JSON monitor Remove double OOM error reporting
ACK series after fixing the small issue I pointed out in 7/12. Jirka

On 07/02/2014 11:03 PM, Jiri Denemark wrote:
On Wed, Jul 02, 2014 at 12:10:53 +0200, Jano Tomko wrote:
Patches 1-3 don't touch any code 4-5 no functional change 6 introduces a new function 7-8 have no functional change unless virBuffer API is misused (that case resulted in an OOM error before, now it's an internal error) 9-10 add OOM error reporting to a few functions 11-12 remove double OOM error reporting
Ján Tomko (12): Fix indentation in bridge driver More indentation fixes usb: Remove redundant comment Remove useless condition in networkRadvdConfContents Use virStringReplace instead of openvz_replace Introduce virBufferCheckError Report errors in virCapabilitiesFormatXML Use virBufferCheckError everywhere we report OOM error Set errno on OOM in lxcProcReadMeminfo Add OOM error reporting to a few fucntions Remove double OOM error reporting from JSON monitor Remove double OOM error reporting
ACK series after fixing the small issue I pointed out in 7/12.
Jirka
I've fixed the issue and pushed the series. Thanks! Jan
participants (2)
-
Jiri Denemark
-
Ján Tomko