Here's the big one: >From 099536470ae2cbe9503ed471d391e403fb2587a4 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@xxxxxxxxxx> Date: Tue, 27 Jan 2009 12:20:06 +0100 Subject: [PATCH 1/3] error-reporting calls using VIR_ERR_NO_MEMORY: use virReportOOMError instead * src/uml_conf.c (VIR_FROM_THIS): Define to VIR_FROM_UML. * src/xs_internal.c (VIR_FROM_THIS): Define to VIR_FROM_XEN. * src/xml.c (VIR_FROM_THIS): Define to VIR_FROM_XML. * src/stats_linux.c (VIR_FROM_THIS): Define to VIR_FROM_STATS_LINUX. * src/datatypes.c (VIR_FROM_THIS): Define to VIR_FROM_NONE. * src/lxc_conf.c (VIR_FROM_THIS): Define to VIR_FROM_LXC. * src/libvirt.c (VIR_FROM_THIS): Define to VIR_FROM_NONE. * src/node_device_conf.c (VIR_FROM_THIS): Define to VIR_FROM_NODEDEV. * src/openvz_conf.c (VIR_FROM_THIS): Define to VIR_FROM_OPENVZ. * src/openvz_driver.c (VIR_FROM_THIS): Define to VIR_FROM_OPENVZ. * src/conf.c (VIR_FROM_THIS): Define to VIR_FROM_CONF. Note: this loses config_filename:config_lineno diagnostics, but that's ok. * src/node_device.c (VIR_FROM_THIS): Define to VIR_FROM_NODEDEV. * src/sexpr.c (VIR_FROM_THIS): Define to VIR_FROM_SEXPR. --- src/conf.c | 18 +++++++------ src/datatypes.c | 28 +++++++++++---------- src/domain_conf.c | 47 +++++++++++++++++------------------ src/libvirt.c | 4 ++- src/lxc_conf.c | 5 ++- src/lxc_container.c | 8 +++--- src/lxc_controller.c | 2 +- src/lxc_driver.c | 11 ++++---- src/network_conf.c | 18 +++++++------- src/network_driver.c | 15 ++++------- src/node_device.c | 4 ++- src/node_device_conf.c | 8 +++--- src/openvz_conf.c | 8 ++++-- src/openvz_driver.c | 9 ++++--- src/proxy_internal.c | 6 ++-- src/qemu_conf.c | 25 +++++++------------ src/qemu_driver.c | 54 +++++++++++++++++----------------------- src/remote_internal.c | 16 ++++++------ src/sexpr.c | 7 +++-- src/stats_linux.c | 7 +++-- src/storage_backend_iscsi.c | 17 ++++++------- src/storage_backend_logical.c | 27 +++++++++----------- src/storage_conf.c | 34 ++++++++++---------------- src/uml_conf.c | 16 ++++++------ src/util.c | 6 ++-- src/xen_internal.c | 20 ++++++--------- src/xend_internal.c | 35 +++++++++++++------------- src/xml.c | 11 ++++---- src/xs_internal.c | 10 ++++---- 29 files changed, 225 insertions(+), 251 deletions(-) diff --git a/src/conf.c b/src/conf.c index 339a150..b5bfc0c 100644 --- a/src/conf.c +++ b/src/conf.c @@ -25,6 +25,8 @@ #include "c-ctype.h" #include "memory.h" +#define VIR_FROM_THIS VIR_FROM_CONF + /************************************************************************ * * * Structures and macros used by the mini parser * @@ -161,7 +163,7 @@ virConfNew(void) virConfPtr ret; if (VIR_ALLOC(ret) < 0) { - virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration")); + virReportOOMError(NULL); return(NULL); } ret->filename = NULL; @@ -209,7 +211,7 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm) return(NULL); if (VIR_ALLOC(ret) < 0) { - virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration")); + virReportOOMError(NULL); return(NULL); } @@ -488,7 +490,7 @@ virConfParseValue(virConfParserCtxtPtr ctxt) return(NULL); } if (VIR_ALLOC(ret) < 0) { - virConfError(ctxt, VIR_ERR_NO_MEMORY, _("allocating configuration")); + virReportOOMError(NULL); virConfFreeList(lst); VIR_FREE(str); return(NULL); @@ -525,7 +527,7 @@ virConfParseName(virConfParserCtxtPtr ctxt) NEXT; ret = strndup(base, ctxt->cur - base); if (ret == NULL) { - virConfError(ctxt, VIR_ERR_NO_MEMORY, _("allocating configuration")); + virReportOOMError(NULL); return(NULL); } return(ret); @@ -552,7 +554,7 @@ virConfParseComment(virConfParserCtxtPtr ctxt) while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT; comm = strndup(base, ctxt->cur - base); if (comm == NULL) { - virConfError(ctxt, VIR_ERR_NO_MEMORY, _("allocating configuration")); + virReportOOMError(NULL); return(-1); } virConfAddEntry(ctxt->conf, NULL, NULL, comm); @@ -627,7 +629,7 @@ virConfParseStatement(virConfParserCtxtPtr ctxt) while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT; comm = strndup(base, ctxt->cur - base); if (comm == NULL) { - virConfError(ctxt, VIR_ERR_NO_MEMORY, _("allocating configuration")); + virReportOOMError(NULL); VIR_FREE(name); virConfFreeValue(value); return(-1); @@ -888,7 +890,7 @@ virConfWriteFile(const char *filename, virConfPtr conf) } if (virBufferError(&buf)) { - virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocate buffer")); + virReportOOMError(NULL); return -1; } @@ -944,7 +946,7 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf) } if (virBufferError(&buf)) { - virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocate buffer")); + virReportOOMError(NULL); return -1; } diff --git a/src/datatypes.c b/src/datatypes.c index d59c5b4..3b2c958 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -1,7 +1,7 @@ /* * datatypes.h: management of structs for public data types * - * Copyright (C) 2006-2008 Red Hat, Inc. + * Copyright (C) 2006-2009 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -26,6 +26,8 @@ #include "logging.h" #include "memory.h" +#define VIR_FROM_THIS VIR_FROM_NONE + /************************************************************************ * * * Domain and Connections allocations * @@ -120,7 +122,7 @@ virGetConnect(void) { virConnectPtr ret; if (VIR_ALLOC(ret) < 0) { - virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection")); + virReportOOMError(NULL); goto failed; } if (virMutexInit(&ret->lock) < 0) { @@ -262,12 +264,12 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) { /* TODO check the UUID */ if (ret == NULL) { if (VIR_ALLOC(ret) < 0) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating domain")); + virReportOOMError(conn); goto error; } ret->name = strdup(name); if (ret->name == NULL) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating domain")); + virReportOOMError(conn); goto error; } ret->magic = VIR_DOMAIN_MAGIC; @@ -398,12 +400,12 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) { /* TODO check the UUID */ if (ret == NULL) { if (VIR_ALLOC(ret) < 0) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating network")); + virReportOOMError(conn); goto error; } ret->name = strdup(name); if (ret->name == NULL) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating network")); + virReportOOMError(conn); goto error; } ret->magic = VIR_NETWORK_MAGIC; @@ -530,12 +532,12 @@ virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uui /* TODO check the UUID */ if (ret == NULL) { if (VIR_ALLOC(ret) < 0) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating storage pool")); + virReportOOMError(conn); goto error; } ret->name = strdup(name); if (ret->name == NULL) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating storage pool")); + virReportOOMError(conn); goto error; } ret->magic = VIR_STORAGE_POOL_MAGIC; @@ -661,17 +663,17 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, const c ret = (virStorageVolPtr) virHashLookup(conn->storageVols, key); if (ret == NULL) { if (VIR_ALLOC(ret) < 0) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating storage vol")); + virReportOOMError(conn); goto error; } ret->pool = strdup(pool); if (ret->pool == NULL) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating storage vol")); + virReportOOMError(conn); goto error; } ret->name = strdup(name); if (ret->name == NULL) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating storage vol")); + virReportOOMError(conn); goto error; } strncpy(ret->key, key, sizeof(ret->key)-1); @@ -798,14 +800,14 @@ virGetNodeDevice(virConnectPtr conn, const char *name) ret = (virNodeDevicePtr) virHashLookup(conn->nodeDevices, name); if (ret == NULL) { if (VIR_ALLOC(ret) < 0) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("allocating node dev")); + virReportOOMError(conn); goto error; } ret->magic = VIR_NODE_DEVICE_MAGIC; ret->conn = conn; ret->name = strdup(name); if (ret->name == NULL) { - virLibConnError(conn, VIR_ERR_NO_MEMORY, _("copying node dev name")); + virReportOOMError(conn); goto error; } diff --git a/src/domain_conf.c b/src/domain_conf.c index 30336d4..f696b6a 100644 --- a/src/domain_conf.c +++ b/src/domain_conf.c @@ -483,7 +483,7 @@ virDomainObjPtr virDomainAssignDef(virConnectPtr conn, } if (VIR_ALLOC(domain) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -499,7 +499,7 @@ virDomainObjPtr virDomainAssignDef(virConnectPtr conn, domain->def = def; if (VIR_REALLOC_N(doms->objs, doms->count + 1) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); VIR_FREE(domain); return NULL; } @@ -569,7 +569,7 @@ virDomainDiskDefParseXML(virConnectPtr conn, char *bus = NULL; if (VIR_ALLOC(def) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -753,7 +753,7 @@ virDomainFSDefParseXML(virConnectPtr conn, char *target = NULL; if (VIR_ALLOC(def) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -847,7 +847,7 @@ virDomainNetDefParseXML(virConnectPtr conn, char *model = NULL; if (VIR_ALLOC(def) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -1087,7 +1087,7 @@ virDomainChrDefParseXML(virConnectPtr conn, virDomainChrDefPtr def; if (VIR_ALLOC(def) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -1300,7 +1300,7 @@ virDomainInputDefParseXML(virConnectPtr conn, char *bus = NULL; if (VIR_ALLOC(def) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -1385,7 +1385,7 @@ virDomainGraphicsDefParseXML(virConnectPtr conn, char *type = NULL; if (VIR_ALLOC(def) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -1480,7 +1480,7 @@ virDomainSoundDefParseXML(virConnectPtr conn, virDomainSoundDefPtr def; if (VIR_ALLOC(def) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -1714,7 +1714,7 @@ virDomainHostdevDefParseXML(virConnectPtr conn, char *mode, *type = NULL; if (VIR_ALLOC(def) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } def->target = NULL; @@ -1826,7 +1826,7 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virConnectPtr conn, } if (VIR_ALLOC(dev) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } @@ -1892,8 +1892,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, virDomainDefPtr def; if (VIR_ALLOC(def) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for xmlXPathContext")); + virReportOOMError(conn); return NULL; } @@ -1958,7 +1957,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, char *set = tmp; def->cpumasklen = VIR_DOMAIN_CPUMASK_LEN; if (VIR_ALLOC_N(def->cpumask, def->cpumasklen) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } if (virDomainCpuSetParse(conn, (const char **)&set, @@ -2008,7 +2007,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, if (def->os.bootloader) { def->os.type = strdup("xen"); if (!def->os.type) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } } else { @@ -2026,7 +2025,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, def->virtType == VIR_DOMAIN_VIRT_XEN) { VIR_FREE(def->os.type); if (!(def->os.type = strdup("xen"))) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } } @@ -2047,7 +2046,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, goto error; } if (!(def->os.arch = strdup(defaultArch))) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } } @@ -2059,7 +2058,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, def->os.arch); if (defaultMachine != NULL) { if (!(def->os.machine = strdup(defaultMachine))) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } } @@ -2310,7 +2309,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } if (STREQ(def->os.type, "hvm")) { @@ -2382,7 +2381,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, return def; no_memory: - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); /* fallthrough */ error: @@ -2514,7 +2513,7 @@ virDomainDefPtr virDomainDefParseNode(virConnectPtr conn, ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto cleanup; } @@ -2611,7 +2610,7 @@ virDomainCpuSetFormat(virConnectPtr conn, char *cpuset, int maxcpu) } if (virBufferError(&buf)) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -3400,7 +3399,7 @@ char *virDomainDefFormat(virConnectPtr conn, return virBufferContentAndReset(&buf); no_memory: - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); cleanup: tmp = virBufferContentAndReset(&buf); VIR_FREE(tmp); @@ -3624,7 +3623,7 @@ char *virDomainConfigFile(virConnectPtr conn, char *ret = NULL; if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) { - virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } diff --git a/src/libvirt.c b/src/libvirt.c index 71df57d..72095dd 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -57,6 +57,8 @@ #endif #endif +#define VIR_FROM_THIS VIR_FROM_NONE + /* * TODO: * - use lock to protect against concurrent accesses ? @@ -1323,7 +1325,7 @@ virConnectGetURI (virConnectPtr conn) name = (char *)xmlSaveUri(conn->uri); if (!name) { - virLibConnError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__); + virReportOOMError (conn); goto error; } return name; diff --git a/src/lxc_conf.c b/src/lxc_conf.c index fe964c2..34c8aea 100644 --- a/src/lxc_conf.c +++ b/src/lxc_conf.c @@ -31,6 +31,8 @@ #include "nodeinfo.h" #include "virterror_internal.h" +#define VIR_FROM_THIS VIR_FROM_LXC + /* Functions */ virCapsPtr lxcCapsInit(void) { @@ -87,7 +89,6 @@ int lxcLoadDriverConfig(lxc_driver_t *driver) return 0; no_memory: - lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("while loading LXC driver config")); + virReportOOMError(NULL); return -1; } diff --git a/src/lxc_container.c b/src/lxc_container.c index 3bf533c..ea52eed 100644 --- a/src/lxc_container.c +++ b/src/lxc_container.c @@ -386,7 +386,7 @@ static int lxcContainerMountNewFS(virDomainDefPtr vmDef) continue; if (virAsprintf(&src, "/.oldroot/%s", vmDef->fss[i]->src) < 0) { - lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(NULL); return -1; } @@ -432,12 +432,12 @@ static int lxcContainerUnmountOldFS(void) if (VIR_REALLOC_N(mounts, nmounts+1) < 0) { endmntent(procmnt); - lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(NULL); return -1; } if (!(mounts[nmounts++] = strdup(mntent.mnt_dir))) { endmntent(procmnt); - lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(NULL); return -1; } } @@ -618,7 +618,7 @@ int lxcContainerStart(virDomainDefPtr def, /* allocate a stack for the container */ if (VIR_ALLOC_N(stack, stacksize) < 0) { - lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(NULL); return -1; } stacktop = stack + stacksize; diff --git a/src/lxc_controller.c b/src/lxc_controller.c index 2ef88d9..e25fe76 100644 --- a/src/lxc_controller.c +++ b/src/lxc_controller.c @@ -127,7 +127,7 @@ static char*lxcMonitorPath(virDomainDefPtr def) if (virAsprintf(&sockpath, "%s/%s.sock", LXC_STATE_DIR, def->name) < 0) - lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(NULL); return sockpath; } diff --git a/src/lxc_driver.c b/src/lxc_driver.c index a702635..300b919 100644 --- a/src/lxc_driver.c +++ b/src/lxc_driver.c @@ -90,7 +90,7 @@ static virDrvOpenStatus lxcOpen(virConnectPtr conn, if (conn->uri == NULL) { conn->uri = xmlParseURI("lxc:///"); if (!conn->uri) { - lxcError(conn, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return VIR_DRV_OPEN_ERROR; } } else if (conn->uri->scheme == NULL || @@ -231,8 +231,7 @@ static int lxcListDefinedDomains(virConnectPtr conn, virDomainObjLock(driver->domains.objs[i]); if (!virDomainIsActive(driver->domains.objs[i])) { if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) { - lxcError(conn, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for VM name string")); + virReportOOMError(conn); virDomainObjUnlock(driver->domains.objs[i]); goto cleanup; } @@ -613,7 +612,7 @@ static int lxcMonitorClient(virConnectPtr conn, if (virAsprintf(&sockpath, "%s/%s.sock", driver->stateDir, vm->def->name) < 0) { - lxcError(conn, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } @@ -816,7 +815,7 @@ cleanup: return ret; no_memory: - lxcError(conn, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto cleanup; } @@ -853,7 +852,7 @@ static int lxcVmStart(virConnectPtr conn, if (virAsprintf(&logfile, "%s/%s.log", driver->logDir, vm->def->name) < 0) { - lxcError(conn, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } diff --git a/src/network_conf.c b/src/network_conf.c index 4186629..e19f0fe 100644 --- a/src/network_conf.c +++ b/src/network_conf.c @@ -161,7 +161,7 @@ virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn, } if (VIR_ALLOC(network) < 0) { - virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } if (virMutexInit(&network->lock) < 0) { @@ -174,7 +174,7 @@ virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn, network->def = def; if (VIR_REALLOC_N(nets->objs, nets->count + 1) < 0) { - virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); VIR_FREE(network); return NULL; } @@ -240,7 +240,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, if (VIR_REALLOC_N(def->ranges, def->nranges + 1) < 0) { xmlFree(start); xmlFree(end); - virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } def->ranges[def->nranges].start = (char *)start; @@ -291,7 +291,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, VIR_FREE(ip); VIR_FREE(mac); VIR_FREE(name); - virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } def->hosts[def->nhosts].mac = (char *)mac; @@ -314,7 +314,7 @@ virNetworkDefParseXML(virConnectPtr conn, char *tmp; if (VIR_ALLOC(def) < 0) { - virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -382,7 +382,7 @@ virNetworkDefParseXML(virConnectPtr conn, netaddr = inet_ntoa(inaddress); if (virAsprintf(&def->network, "%s/%s", netaddr, def->netmask) < 0) { - virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } @@ -544,7 +544,7 @@ virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn, ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { - virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto cleanup; } @@ -632,7 +632,7 @@ char *virNetworkDefFormat(virConnectPtr conn, return virBufferContentAndReset(&buf); no_memory: - virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); tmp = virBufferContentAndReset(&buf); VIR_FREE(tmp); return NULL; @@ -840,7 +840,7 @@ char *virNetworkConfigFile(virConnectPtr conn, char *ret = NULL; if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) { - virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } diff --git a/src/network_driver.c b/src/network_driver.c index c546a2b..dcc6ad9 100644 --- a/src/network_driver.c +++ b/src/network_driver.c @@ -252,8 +252,7 @@ networkStartup(void) { } if (!(driverState->iptables = iptablesContextNew())) { - networkReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for IP tables support")); + virReportOOMError(NULL); goto error; } @@ -502,8 +501,7 @@ networkBuildDnsmasqArgv(virConnectPtr conn, VIR_FREE((*argv)[i]); VIR_FREE(*argv); } - networkReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for dnsmasq argv")); + virReportOOMError(conn); return -1; } @@ -1062,8 +1060,7 @@ static int networkListNetworks(virConnectPtr conn, char **const names, int nname if (virNetworkIsActive(driver->networks.objs[i])) { if (!(names[got] = strdup(driver->networks.objs[i]->def->name))) { virNetworkObjUnlock(driver->networks.objs[i]); - networkReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for VM name string")); + virReportOOMError(conn); goto cleanup; } got++; @@ -1107,8 +1104,7 @@ static int networkListDefinedNetworks(virConnectPtr conn, char **const names, in if (!virNetworkIsActive(driver->networks.objs[i])) { if (!(names[got] = strdup(driver->networks.objs[i]->def->name))) { virNetworkObjUnlock(driver->networks.objs[i]); - networkReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for VM name string")); + virReportOOMError(conn); goto cleanup; } got++; @@ -1331,8 +1327,7 @@ static char *networkGetBridgeName(virNetworkPtr net) { bridge = strdup(network->def->bridge); if (!bridge) - networkReportError(net->conn, NULL, net, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for network bridge string")); + virReportOOMError(net->conn); cleanup: if (network) diff --git a/src/node_device.c b/src/node_device.c index 9586fa6..1b7be60 100644 --- a/src/node_device.c +++ b/src/node_device.c @@ -33,6 +33,8 @@ #include "node_device_conf.h" #include "node_device.h" +#define VIR_FROM_THIS VIR_FROM_NODEDEV + static int dev_has_cap(const virNodeDeviceObjPtr dev, const char *cap) { virNodeDevCapsDefPtr caps = dev->def->caps; @@ -176,7 +178,7 @@ static char *nodeDeviceGetParent(virNodeDevicePtr dev) ret = strdup(obj->def->parent); if (!ret) - virNodeDeviceReportError(dev->conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(dev->conn); cleanup: if (obj) diff --git a/src/node_device_conf.c b/src/node_device_conf.c index ff022b7..af2f9a3 100644 --- a/src/node_device_conf.c +++ b/src/node_device_conf.c @@ -36,6 +36,7 @@ #include "buf.h" #include "uuid.h" +#define VIR_FROM_THIS VIR_FROM_NODEDEV VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST, "system", @@ -126,7 +127,7 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virConnectPtr conn, } if (VIR_ALLOC(device) < 0) { - virNodeDeviceReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -143,7 +144,7 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virConnectPtr conn, device->def = NULL; virNodeDeviceObjUnlock(device); virNodeDeviceObjFree(device); - virNodeDeviceReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } devs->objs[devs->count++] = device; @@ -360,7 +361,7 @@ char *virNodeDeviceDefFormat(virConnectPtr conn, return virBufferContentAndReset(&buf); no_memory: - virNodeDeviceReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); tmp = virBufferContentAndReset(&buf); VIR_FREE(tmp); return NULL; @@ -425,4 +426,3 @@ void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) { virMutexUnlock(&obj->lock); } - diff --git a/src/openvz_conf.c b/src/openvz_conf.c index 54474b7..ff3d607 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -51,6 +51,8 @@ #include "util.h" #include "nodeinfo.h" +#define VIR_FROM_THIS VIR_FROM_OPENVZ + static char *openvzLocateConfDir(void); static int openvzGetVPSUUID(int vpsid, char *uuidstr); static int openvzLocateConfFile(int vpsid, char *conffile, int maxlen, const char *ext); @@ -305,7 +307,7 @@ openvzReadNetworkConf(virConnectPtr conn, return 0; no_memory: - openvzError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); error: virDomainNetDefFree(net); return -1; @@ -346,7 +348,7 @@ openvzReadFSConf(virConnectPtr conn, return 0; no_memory: - openvzError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); error: virDomainFSDefFree(fs); return -1; @@ -461,7 +463,7 @@ int openvzLoadDomains(struct openvz_driver *driver) { return 0; no_memory: - openvzError(NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(NULL); cleanup: fclose(fp); diff --git a/src/openvz_driver.c b/src/openvz_driver.c index d22ea39..e004819 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -58,6 +58,8 @@ #include "memory.h" #include "bridge.h" +#define VIR_FROM_THIS VIR_FROM_OPENVZ + #define OPENVZ_MAX_ARG 28 #define CMDBUF_LEN 1488 #define CMDOP_LEN 288 @@ -213,7 +215,7 @@ static char *openvzGetOSType(virDomainPtr dom) } if (!(ret = strdup(vm->def->os.type))) - openvzError(dom->conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(dom->conn); cleanup: if (vm) @@ -1056,7 +1058,7 @@ static virDrvOpenStatus openvzOpen(virConnectPtr conn, } if (VIR_ALLOC(driver) < 0) { - openvzError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return VIR_DRV_OPEN_ERROR; } @@ -1194,7 +1196,7 @@ static int openvzListDefinedDomains(virConnectPtr conn, return got; no_memory: - openvzError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); for ( ; got >= 0 ; got--) VIR_FREE(names[got]); return -1; @@ -1329,4 +1331,3 @@ int openvzRegister(void) { virRegisterDriver(&openvzDriver); return 0; } - diff --git a/src/proxy_internal.c b/src/proxy_internal.c index d1255ae..6a34e7e 100644 --- a/src/proxy_internal.c +++ b/src/proxy_internal.c @@ -948,7 +948,7 @@ xenProxyGetCapabilities (virConnectPtr conn) xmllen = ans.len - sizeof (virProxyPacket); if (VIR_ALLOC_N(xml, xmllen+1) < 0) { - virProxyError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__); + virReportOOMError (conn); return NULL; } memmove (xml, ans.extra.str, xmllen); @@ -998,7 +998,7 @@ xenProxyDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED) } xmllen = ans.len - sizeof(virProxyPacket); if (VIR_ALLOC_N(xml, xmllen+1) < 0) { - virProxyError(domain->conn, VIR_ERR_NO_MEMORY, __FUNCTION__); + virReportOOMError(domain->conn); return NULL; } memmove(xml, &ans.extra.dinfo, xmllen); @@ -1050,7 +1050,7 @@ xenProxyDomainGetOSType(virDomainPtr domain) } oslen = ans.len - sizeof(virProxyPacket); if (VIR_ALLOC_N(ostype, oslen+1) < 0) { - virProxyError(domain->conn, VIR_ERR_NO_MEMORY, __FUNCTION__); + virReportOOMError(domain->conn); return NULL; } memmove(ostype, &ans.extra.dinfo, oslen); diff --git a/src/qemu_conf.c b/src/qemu_conf.c index bd5d414..ce9278e 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -70,13 +70,11 @@ int qemudLoadDriverConfig(struct qemud_driver *driver, /* Setup 2 critical defaults */ if (!(driver->vncListen = strdup("127.0.0.1"))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate vncListen")); + virReportOOMError(NULL); return -1; } if (!(driver->vncTLSx509certdir = strdup(SYSCONF_DIR "/pki/libvirt-vnc"))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate vncTLSx509certdir")); + virReportOOMError(NULL); return -1; } @@ -110,8 +108,7 @@ int qemudLoadDriverConfig(struct qemud_driver *driver, if (p && p->str) { VIR_FREE(driver->vncTLSx509certdir); if (!(driver->vncTLSx509certdir = strdup(p->str))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate vncTLSx509certdir")); + virReportOOMError(NULL); virConfFree(conf); return -1; } @@ -122,8 +119,7 @@ int qemudLoadDriverConfig(struct qemud_driver *driver, if (p && p->str) { VIR_FREE(driver->vncListen); if (!(driver->vncListen = strdup(p->str))) { - qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate vnc_listen")); + virReportOOMError(NULL); virConfFree(conf); return -1; } @@ -512,7 +508,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn, strchr(net->ifname, '%')) { VIR_FREE(net->ifname); if (!(net->ifname = strdup("vnet%d"))) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } } @@ -555,8 +551,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn, return retval; no_memory: - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for tapfds string")); + virReportOOMError(conn); error: VIR_FREE(retval); if (tapfd != -1) @@ -1296,8 +1291,7 @@ int qemudBuildCommandLine(virConnectPtr conn, return 0; no_memory: - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for argv string")); + virReportOOMError(conn); error: if (tapfds && *tapfds) { @@ -1371,8 +1365,7 @@ qemudDomainStatusParseFile(virConnectPtr conn, qemudDomainStatusPtr status = NULL; if (VIR_ALLOC(status) < 0) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for vm status")); + virReportOOMError(conn); goto error; } @@ -1402,7 +1395,7 @@ qemudDomainStatusParseFile(virConnectPtr conn, ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 3d9a0a2..aae29a9 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -1,7 +1,7 @@ /* * driver.c: core driver methods for managing qemu guests * - * Copyright (C) 2006, 2007, 2008 Red Hat, Inc. + * Copyright (C) 2006, 2007, 2008, 2009 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -275,8 +275,7 @@ qemudRemoveDomainStatus(virConnectPtr conn, char *file = NULL; if (virAsprintf(&file, "%s/%s.xml", driver->stateDir, vm->def->name) < 0) { - qemudReportError(conn, vm, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for status file")); + virReportOOMError(conn); goto cleanup; } @@ -728,8 +727,7 @@ static int qemudOpenMonitor(virConnectPtr conn, goto error; if (!(vm->monitorpath = strdup(monitor))) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for monitor path")); + virReportOOMError(conn); goto error; } @@ -770,8 +768,7 @@ static int qemudExtractMonitorPath(virConnectPtr conn, while (*tmp) { if (c_isspace(*tmp)) { if (VIR_ALLOC_N(*path, (tmp-dev)+1) < 0) { - qemudReportError(conn, NULL, NULL, - VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } strncpy(*path, dev, (tmp-dev)); @@ -876,8 +873,7 @@ qemudDetectVcpuPIDs(virConnectPtr conn, vm->nvcpupids = vm->def->vcpus; if (VIR_ALLOC_N(vm->vcpupids, vm->nvcpupids) < 0) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("allocate cpumap")); + virReportOOMError(conn); return -1; } @@ -1434,7 +1430,7 @@ static virDrvOpenStatus qemudOpen(virConnectPtr conn, if (conn->uri == NULL) { conn->uri = xmlParseURI(uid ? "qemu:///session" : "qemu:///system"); if (!conn->uri) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,NULL); + virReportOOMError(conn); return VIR_DRV_OPEN_ERROR; } } else if (conn->uri->scheme == NULL || @@ -1537,8 +1533,7 @@ static char *qemudGetCapabilities(virConnectPtr conn) { qemuDriverLock(driver); if ((xml = virCapabilitiesFormatXML(driver->caps)) == NULL) - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for capabilities support")); + virReportOOMError(conn); qemuDriverUnlock(driver); return xml; @@ -2020,8 +2015,7 @@ static char *qemudDomainGetOSType(virDomainPtr dom) { } if (!(type = strdup(vm->def->os.type))) - qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for ostype")); + virReportOOMError(dom->conn); cleanup: if (vm) @@ -2785,8 +2779,7 @@ static int qemudListDefinedDomains(virConnectPtr conn, virDomainObjLock(driver->domains.objs[i]); if (!virDomainIsActive(driver->domains.objs[i])) { if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for VM name string")); + virReportOOMError(conn); virDomainObjUnlock(driver->domains.objs[i]); goto cleanup; } @@ -2996,7 +2989,7 @@ static char *qemudDiskDeviceName(const virConnectPtr conn, } if (ret == -1) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -3060,7 +3053,7 @@ static int qemudDomainChangeEjectableMedia(virConnectPtr conn, } if (!devname) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } } @@ -3068,12 +3061,12 @@ static int qemudDomainChangeEjectableMedia(virConnectPtr conn, if (newdisk->src) { safe_path = qemudEscapeMonitorArg(newdisk->src); if (!safe_path) { - qemudReportError(conn, dom, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); VIR_FREE(devname); return -1; } if (virAsprintf(&cmd, "change %s \"%s\"", devname, safe_path) == -1) { - qemudReportError(conn, dom, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); VIR_FREE(safe_path); VIR_FREE(devname); return -1; @@ -3081,7 +3074,7 @@ static int qemudDomainChangeEjectableMedia(virConnectPtr conn, VIR_FREE(safe_path); } else if (virAsprintf(&cmd, "eject %s", devname) == -1) { - qemudReportError(conn, dom, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); VIR_FREE(devname); return -1; } @@ -3133,7 +3126,7 @@ static int qemudDomainAttachPciDiskDevice(virConnectPtr conn, } if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } @@ -3148,7 +3141,7 @@ static int qemudDomainAttachPciDiskDevice(virConnectPtr conn, safe_path, type); VIR_FREE(safe_path); if (ret == -1) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return ret; } @@ -3203,7 +3196,7 @@ static int qemudDomainAttachUsbMassstorageDevice(virConnectPtr conn, } if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } @@ -3217,7 +3210,7 @@ static int qemudDomainAttachUsbMassstorageDevice(virConnectPtr conn, ret = virAsprintf(&cmd, "usb_add disk:%s", safe_path); VIR_FREE(safe_path); if (ret == -1) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return ret; } @@ -3257,7 +3250,7 @@ static int qemudDomainAttachHostDevice(virConnectPtr conn, char *cmd, *reply; if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } @@ -3271,7 +3264,7 @@ static int qemudDomainAttachHostDevice(virConnectPtr conn, dev->data.hostdev->source.subsys.u.usb.device); } if (ret == -1) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } @@ -3398,7 +3391,7 @@ static int qemudDomainDetachPciDiskDevice(virConnectPtr conn, } if (virAsprintf(&cmd, "pci_del 0 %d", detach->slotnum) < 0) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto cleanup; } @@ -3421,7 +3414,7 @@ static int qemudDomainDetachPciDiskDevice(virConnectPtr conn, if (vm->def->ndisks > 1) { vm->def->disks[i] = vm->def->disks[--vm->def->ndisks]; if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks) < 0) { - qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto cleanup; } qsort(vm->def->disks, vm->def->ndisks, sizeof(*vm->def->disks), @@ -4071,8 +4064,7 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn, /* Caller frees */ if (virAsprintf(uri_out, "tcp:%s:%d", hostname, this_port) < 0) { - qemudReportError (dconn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", strerror (errno)); + virReportOOMError (dconn); goto cleanup; } } else { diff --git a/src/remote_internal.c b/src/remote_internal.c index 93b27af..8ed52bc 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -507,7 +507,7 @@ doRemoteOpen (virConnectPtr conn, } if (!name) { - error(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto failed; } @@ -803,7 +803,7 @@ doRemoteOpen (virConnectPtr conn, conn->uri = xmlParseURI(uriret.uri); VIR_FREE(uriret.uri); if (!conn->uri) { - error (conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError (conn); goto failed; } } @@ -862,7 +862,7 @@ doRemoteOpen (virConnectPtr conn, return retcode; out_of_memory: - error (conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError (conn); failed: /* Close the socket if we failed. */ @@ -904,7 +904,7 @@ remoteOpen (virConnectPtr conn, return VIR_DRV_OPEN_DECLINED; if (VIR_ALLOC(priv) < 0) { - error (conn, VIR_ERR_NO_MEMORY, _("struct private_data")); + virReportOOMError (conn); return VIR_DRV_OPEN_ERROR; } @@ -2837,7 +2837,7 @@ remoteDomainSetSchedulerParameters (virDomainPtr domain, // call() will free this: args.params.params_val[i].field = strdup (params[i].field); if (args.params.params_val[i].field == NULL) { - error (domain->conn, VIR_ERR_NO_MEMORY, _("out of memory")); + virReportOOMError (domain->conn); do_error = 1; } args.params.params_val[i].value.type = params[i].type; @@ -3087,7 +3087,7 @@ remoteNetworkOpen (virConnectPtr conn, struct private_data *priv; int ret, rflags = 0; if (VIR_ALLOC(priv) < 0) { - error (conn, VIR_ERR_NO_MEMORY, _("struct private_data")); + virReportOOMError (conn); return VIR_DRV_OPEN_ERROR; } if (virMutexInit(&priv->lock) < 0) { @@ -3600,7 +3600,7 @@ remoteStorageOpen (virConnectPtr conn, struct private_data *priv; int ret, rflags = 0; if (VIR_ALLOC(priv) < 0) { - error (NULL, VIR_ERR_NO_MEMORY, _("struct private_data")); + virReportOOMError (NULL); return VIR_DRV_OPEN_ERROR; } if (virMutexInit(&priv->lock) < 0) { @@ -4553,7 +4553,7 @@ remoteDevMonOpen(virConnectPtr conn, struct private_data *priv; int ret, rflags = 0; if (VIR_ALLOC(priv) < 0) { - error (NULL, VIR_ERR_NO_MEMORY, _("struct private_data")); + virReportOOMError (NULL); return VIR_DRV_OPEN_ERROR; } if (virMutexInit(&priv->lock) < 0) { diff --git a/src/sexpr.c b/src/sexpr.c index d97bf77..7450c79 100644 --- a/src/sexpr.c +++ b/src/sexpr.c @@ -23,6 +23,8 @@ #include "util.h" #include "memory.h" +#define VIR_FROM_THIS VIR_FROM_SEXPR + #define virSexprError(code, fmt...) \ virReportErrorHelper(NULL, VIR_FROM_SEXPR, code, __FILE__, \ __FUNCTION__, __LINE__, fmt) @@ -40,7 +42,7 @@ sexpr_new(void) struct sexpr *ret; if (VIR_ALLOC(ret) < 0) { - virSexprError(VIR_ERR_NO_MEMORY, "%s", _("failed to allocate a node")); + virReportOOMError(NULL); return (NULL); } ret->kind = SEXPR_NIL; @@ -343,8 +345,7 @@ _string2sexpr(const char *buffer, size_t * end) ret->u.value = strndup(start, ptr - start); if (ret->u.value == NULL) { - virSexprError(VIR_ERR_NO_MEMORY, - "%s", _("failed to copy a string")); + virReportOOMError(NULL); goto error; } diff --git a/src/stats_linux.c b/src/stats_linux.c index b58457d..eccda94 100644 --- a/src/stats_linux.c +++ b/src/stats_linux.c @@ -1,7 +1,7 @@ /* * Linux block and network stats. * - * Copyright (C) 2007, 2008 Red Hat, Inc. + * Copyright (C) 2007-2009 Red Hat, Inc. * * See COPYING.LIB for the License of this software * @@ -31,6 +31,8 @@ #include "stats_linux.h" #include "memory.h" +#define VIR_FROM_THIS VIR_FROM_STATS_LINUX + /** * statsErrorFunc: * @conn: the connection @@ -297,8 +299,7 @@ xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path) retval = virAsprintf(&mod_path, "/dev/%s", path); if (retval < 0) { - statsErrorFunc (conn, VIR_ERR_NO_MEMORY, __FUNCTION__, - "allocating mod_path", domid); + virReportOOMError (conn); return -1; } diff --git a/src/storage_backend_iscsi.c b/src/storage_backend_iscsi.c index 1d909c5..bbb94a5 100644 --- a/src/storage_backend_iscsi.c +++ b/src/storage_backend_iscsi.c @@ -97,7 +97,7 @@ virStorageBackendISCSIExtractSession(virConnectPtr conn, if (STREQ(groups[1], pool->def->source.devices[0].path)) { if ((*session = strdup(groups[0])) == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("session")); + virReportOOMError(conn); return -1; } } @@ -179,19 +179,19 @@ virStorageBackendISCSINewLun(virConnectPtr conn, virStoragePoolObjPtr pool, int opentries = 0; if (VIR_ALLOC(vol) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume")); + virReportOOMError(conn); goto cleanup; } vol->type = VIR_STORAGE_VOL_BLOCK; if (virAsprintf(&(vol->name), "lun-%d", lun) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("name")); + virReportOOMError(conn); goto cleanup; } if (virAsprintf(&devpath, "/dev/%s", dev) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("devpath")); + virReportOOMError(conn); goto cleanup; } @@ -234,7 +234,7 @@ virStorageBackendISCSINewLun(virConnectPtr conn, virStoragePoolObjPtr pool, /* XXX use unique iSCSI id instead */ vol->key = strdup(vol->target.path); if (vol->key == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("key")); + virReportOOMError(conn); goto cleanup; } @@ -244,7 +244,7 @@ virStorageBackendISCSINewLun(virConnectPtr conn, virStoragePoolObjPtr pool, if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count+1) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto cleanup; } pool->volumes.objs[pool->volumes.count++] = vol; @@ -477,8 +477,7 @@ virStorageBackendISCSIFindLUNs(virConnectPtr conn, scsidev = strdup(block2); } if (scsidev == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", - _("Failed allocating memory for scsidev")); + virReportOOMError(conn); retval = -1; goto namelist_cleanup; } @@ -559,7 +558,7 @@ virStorageBackendISCSIPortal(virConnectPtr conn, return NULL; if (VIR_ALLOC_N(portal, strlen(ipaddr) + 1 + 4 + 2 + 1) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("portal")); + virReportOOMError(conn); return NULL; } diff --git a/src/storage_backend_logical.c b/src/storage_backend_logical.c index 474c3d8..461c110 100644 --- a/src/storage_backend_logical.c +++ b/src/storage_backend_logical.c @@ -84,21 +84,21 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn, /* Or a completely new volume */ if (vol == NULL) { if (VIR_ALLOC(vol) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume")); + virReportOOMError(conn); return -1; } vol->type = VIR_STORAGE_VOL_BLOCK; if ((vol->name = strdup(groups[0])) == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume")); + virReportOOMError(conn); virStorageVolDefFree(vol); return -1; } if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1)) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); virStorageVolDefFree(vol); return -1; } @@ -108,7 +108,7 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn, if (vol->target.path == NULL) { if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) + 1 + strlen(vol->name) + 1) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume")); + virReportOOMError(conn); return -1; } strcpy(vol->target.path, pool->def->target.path); @@ -118,7 +118,7 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn, if (vol->key == NULL && (vol->key = strdup(groups[1])) == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume")); + virReportOOMError(conn); return -1; } @@ -129,13 +129,13 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn, /* Finally fill in extents information */ if (VIR_REALLOC_N(vol->source.extents, vol->source.nextent + 1) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("extents")); + virReportOOMError(conn); return -1; } if ((vol->source.extents[vol->source.nextent].path = strdup(groups[2])) == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("extents")); + virReportOOMError(conn); return -1; } @@ -256,8 +256,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn, vgname = strdup(groups[1]); if (pvname == NULL || vgname == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", - _("allocating pvname or vgname")); + virReportOOMError(conn); goto err_no_memory; } @@ -271,8 +270,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn, if (thisSource == NULL) { if (VIR_REALLOC_N(sourceList->sources, sourceList->nsources + 1) != 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", - _("allocating new source")); + virReportOOMError(conn); goto err_no_memory; } @@ -286,8 +284,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn, VIR_FREE(vgname); if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) != 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", - _("allocating new device")); + virReportOOMError(conn); goto err_no_memory; } @@ -386,7 +383,7 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn, memset(zeros, 0, sizeof(zeros)); if (VIR_ALLOC_N(vgargv, 3 + pool->def->source.ndevice) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("command line")); + virReportOOMError(conn); return -1; } @@ -581,7 +578,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, } if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) + 1 + strlen(vol->name) + 1) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume")); + virReportOOMError(conn); return -1; } strcpy(vol->target.path, pool->def->target.path); diff --git a/src/storage_conf.c b/src/storage_conf.c index 9d3f5a7..a2b7fab 100644 --- a/src/storage_conf.c +++ b/src/storage_conf.c @@ -426,8 +426,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn, char *authType = NULL; if (VIR_ALLOC(ret) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, - "%s", _("cannot allocate storage pool")); + virReportOOMError(conn); return NULL; } @@ -511,7 +510,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn, } if (VIR_ALLOC_N(ret->source.devices, nsource) < 0) { VIR_FREE(nodeset); - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("device")); + virReportOOMError(conn); goto cleanup; } for (i = 0 ; i < nsource ; i++) { @@ -541,8 +540,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn, /* source name defaults to pool name */ ret->source.name = strdup(ret->name); if (ret->source.name == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", - _("pool name")); + virReportOOMError(conn); goto cleanup; } } @@ -640,8 +638,7 @@ virStoragePoolDefParse(virConnectPtr conn, ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, - "%s", _("xmlXPathContext")); + virReportOOMError(conn); goto cleanup; } @@ -791,7 +788,7 @@ virStoragePoolDefFormat(virConnectPtr conn, return virBufferContentAndReset(&buf); no_memory: - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("xml")); + virReportOOMError(conn); cleanup: free(virBufferContentAndReset(&buf)); return NULL; @@ -934,8 +931,7 @@ virStorageVolDefParseDoc(virConnectPtr conn, return NULL; if (VIR_ALLOC(ret) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, - "%s", _("cannot allocate storage vol")); + virReportOOMError(conn); return NULL; } @@ -1041,8 +1037,7 @@ virStorageVolDefParse(virConnectPtr conn, ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, - "%s", _("xmlXPathContext")); + virReportOOMError(conn); goto cleanup; } @@ -1155,7 +1150,7 @@ virStorageVolDefFormat(virConnectPtr conn, return virBufferContentAndReset(&buf); no_memory: - virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("xml")); + virReportOOMError(conn); cleanup: tmp = virBufferContentAndReset(&buf); VIR_FREE(tmp); @@ -1259,8 +1254,7 @@ virStoragePoolObjAssignDef(virConnectPtr conn, } if (VIR_ALLOC(pool) < 0) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, - "%s", _("pool")); + virReportOOMError(conn); return NULL; } @@ -1278,7 +1272,7 @@ virStoragePoolObjAssignDef(virConnectPtr conn, pool->def = NULL; virStoragePoolObjUnlock(pool); virStoragePoolObjFree(pool); - virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } pools->objs[pools->count++] = pool; @@ -1420,8 +1414,7 @@ virStoragePoolObjSaveDef(virConnectPtr conn, return -1; } if (!(pool->configFile = strdup(path))) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, - "%s", _("configFile")); + virReportOOMError(conn); return -1; } @@ -1434,8 +1427,7 @@ virStoragePoolObjSaveDef(virConnectPtr conn, return -1; } if (!(pool->autostartLink = strdup(path))) { - virStorageReportError(conn, VIR_ERR_NO_MEMORY, - "%s", _("config file")); + virReportOOMError(conn); VIR_FREE(pool->configFile); return -1; } @@ -1534,7 +1526,7 @@ char *virStoragePoolSourceListFormat(virConnectPtr conn, return virBufferContentAndReset(&buf); no_memory: - virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); cleanup: free(virBufferContentAndReset(&buf)); return NULL; diff --git a/src/uml_conf.c b/src/uml_conf.c index f2bf09f..c0d086e 100644 --- a/src/uml_conf.c +++ b/src/uml_conf.c @@ -1,7 +1,7 @@ /* * uml_conf.c: UML driver configuration * - * Copyright (C) 2006, 2007, 2008 Red Hat, Inc. + * Copyright (C) 2006-2009 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -45,6 +45,7 @@ #include "nodeinfo.h" #include "verify.h" +#define VIR_FROM_THIS VIR_FROM_UML #define umlLog(level, msg, ...) \ virLogMessage(__FILE__, level, 0, msg, __VA_ARGS__) @@ -100,14 +101,14 @@ umlBuildCommandLineChr(virConnectPtr conn, switch (def->type) { case VIR_DOMAIN_CHR_TYPE_NULL: if (virAsprintf(&ret, "%s%d=null", dev, def->dstPort) < 0) { - umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } break; case VIR_DOMAIN_CHR_TYPE_PTY: if (virAsprintf(&ret, "%s%d=pts", dev, def->dstPort) < 0) { - umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } break; @@ -115,14 +116,14 @@ umlBuildCommandLineChr(virConnectPtr conn, case VIR_DOMAIN_CHR_TYPE_DEV: if (virAsprintf(&ret, "%s%d=tty:%s", dev, def->dstPort, def->data.file.path) < 0) { - umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } break; case VIR_DOMAIN_CHR_TYPE_STDIO: if (virAsprintf(&ret, "%s%d=fd:0,fd:1", dev, def->dstPort) < 0) { - umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } break; @@ -136,7 +137,7 @@ umlBuildCommandLineChr(virConnectPtr conn, if (virAsprintf(&ret, "%s%d=port:%s", dev, def->dstPort, def->data.tcp.service) < 0) { - umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } break; @@ -308,8 +309,7 @@ int umlBuildCommandLine(virConnectPtr conn, return 0; no_memory: - umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for argv string")); + virReportOOMError(conn); error: if (tapfds && *tapfds) { diff --git a/src/util.c b/src/util.c index b513559..e049999 100644 --- a/src/util.c +++ b/src/util.c @@ -458,7 +458,7 @@ virExec(virConnectPtr conn, char *argv_str; if ((argv_str = virArgvToString(argv)) == NULL) { - ReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("command debug string")); + virReportOOMError(conn); return -1; } DEBUG0(argv_str); @@ -526,7 +526,7 @@ virPipeReadUntilEOF(virConnectPtr conn, int outfd, int errfd, buf = ((fds[i].fd == outfd) ? outbuf : errbuf); size = (*buf ? strlen(*buf) : 0); if (VIR_REALLOC_N(*buf, size+got+1) < 0) { - ReportError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); goto error; } memmove(*buf+size, data, got); @@ -576,7 +576,7 @@ virRun(virConnectPtr conn, char *argv_str = NULL; if ((argv_str = virArgvToString(argv)) == NULL) { - ReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("command debug string")); + virReportOOMError(conn); goto error; } DEBUG0(argv_str); diff --git a/src/xen_internal.c b/src/xen_internal.c index 1ef835e..9a7272f 100644 --- a/src/xen_internal.c +++ b/src/xen_internal.c @@ -1639,8 +1639,7 @@ virXen_setvcpumap(int handle, int id, unsigned int vcpu, * for Xen, and also nr_cpus must be 'sizeof(uint64_t) * 8' */ if (maplen < 8) { if (VIR_ALLOC_N(new, sizeof(uint64_t)) < 0) { - virXenErrorFunc(NULL, VIR_ERR_NO_MEMORY, __FUNCTION__, - "allocating private data", 0); + virReportOOMError(NULL); return (-1); } memcpy(new, cpumap, maplen); @@ -1965,7 +1964,7 @@ xenHypervisorInit(void) hypervisor_version = 2; if (VIR_ALLOC(ipt) < 0) { - virXenError(NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(NULL); return(-1); } /* Currently consider RHEL5.0 Fedora7, xen-3.1, and xen-unstable */ @@ -2359,7 +2358,7 @@ xenHypervisorMakeCapabilitiesSunOS(virConnectPtr conn) utsname.machine, pae, hvm, guest_arches, i)) == NULL) - virXenError(NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(NULL); return caps; } @@ -2520,7 +2519,7 @@ xenHypervisorMakeCapabilitiesInternal(virConnectPtr conn, return caps; no_memory: - virXenError(NULL, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(NULL); virCapabilitiesFree(caps); return NULL; } @@ -2593,7 +2592,7 @@ xenHypervisorGetCapabilities (virConnectPtr conn) char *xml; if (!(xml = virCapabilitiesFormatXML(priv->caps))) { - virXenError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -2626,8 +2625,7 @@ xenHypervisorNumOfDomains(virConnectPtr conn) retry: if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) { - virXenError(conn, VIR_ERR_NO_MEMORY, _("allocating %d domain info"), - maxids); + virReportOOMError(conn); return(-1); } @@ -2688,8 +2686,7 @@ xenHypervisorListDomains(virConnectPtr conn, int *ids, int maxids) return(0); if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) { - virXenError(conn, VIR_ERR_NO_MEMORY, "allocating %d domain info", - maxids); + virReportOOMError(conn); return(-1); } @@ -2798,8 +2795,7 @@ xenHypervisorLookupDomainByUUID(virConnectPtr conn, retry: if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) { - virXenError(conn, VIR_ERR_NO_MEMORY, "allocating %d domain info", - maxids); + virReportOOMError(conn); return(NULL); } diff --git a/src/xend_internal.c b/src/xend_internal.c index 3bd70ad..75a4324 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -526,7 +526,7 @@ xend_op_ext(virConnectPtr xend, const char *path, char *error, } if (virBufferError(&buf)) { - virXendError(NULL, VIR_ERR_NO_MEMORY, "%s", _("allocate buffer")); + virReportOOMError(NULL); return -1; } @@ -706,7 +706,7 @@ urlencode(const char *string) size_t i; if (VIR_ALLOC_N(buffer, len * 3 + 1) < 0) { - virXendError(NULL, VIR_ERR_NO_MEMORY, "%s", _("allocate new buffer")); + virReportOOMError(NULL); return (NULL); } ptr = buffer; @@ -1186,7 +1186,7 @@ xenDaemonParseSxprOS(virConnectPtr xend, return 0; no_memory: - virXendError(xend, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(xend); return -1; } @@ -1399,8 +1399,7 @@ xend_parse_sexp_desc_char(virConnectPtr conn, if (ret == -1) { no_memory: - virXendError(conn, VIR_ERR_NO_MEMORY, - "%s", _("no memory for char device config")); + virReportOOMError(conn); } error: @@ -1424,7 +1423,7 @@ xenDaemonParseSxprChar(virConnectPtr conn, virDomainChrDefPtr def; if (VIR_ALLOC(def) < 0) { - virXendError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return NULL; } @@ -1553,7 +1552,7 @@ xenDaemonParseSxprChar(virConnectPtr conn, return def; no_memory: - virXendError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); error: virDomainChrDefFree(def); return NULL; @@ -1722,7 +1721,7 @@ xenDaemonParseSxprDisks(virConnectPtr conn, return 0; no_memory: - virXendError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); error: virDomainDiskDefFree(disk); @@ -1824,7 +1823,7 @@ xenDaemonParseSxprNets(virConnectPtr conn, return 0; no_memory: - virXendError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); cleanup: virDomainNetDefFree(net); return -1; @@ -1905,7 +1904,7 @@ xenDaemonParseSxprSound(virConnectPtr conn, return 0; no_memory: - virXendError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); error: return -1; } @@ -1949,7 +1948,7 @@ xenDaemonParseSxprUSB(virConnectPtr conn, return 0; no_memory: - virXendError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); return -1; } @@ -2032,7 +2031,7 @@ xenDaemonParseSxprGraphicsOld(virConnectPtr conn, return 0; no_memory: - virXendError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); virDomainGraphicsDefFree(graphics); return -1; } @@ -2122,7 +2121,7 @@ xenDaemonParseSxprGraphicsNew(virConnectPtr conn, return 0; no_memory: - virXendError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); error: virDomainGraphicsDefFree(graphics); return -1; @@ -2416,7 +2415,7 @@ xenDaemonParseSxpr(virConnectPtr conn, return def; no_memory: - virXendError(conn, VIR_ERR_NO_MEMORY, NULL); + virReportOOMError(conn); error: VIR_FREE(tty); virDomainDefFree(def); @@ -2637,7 +2636,7 @@ sexpr_to_xend_topology(virConnectPtr conn, memory_error: VIR_FREE(cpuNums); VIR_FREE(cpuset); - virXendError(conn, VIR_ERR_NO_MEMORY, "%s", _("allocate buffer")); + virReportOOMError(conn); return (-1); } @@ -4205,7 +4204,7 @@ xenDaemonDomainMigratePerform (virDomainPtr domain, } hostname = strdup (uriptr->server); if (!hostname) { - virXendError (conn, VIR_ERR_NO_MEMORY, "%s", _("strdup failed")); + virReportOOMError (conn); xmlFreeURI (uriptr); return -1; } @@ -4227,7 +4226,7 @@ xenDaemonDomainMigratePerform (virDomainPtr domain, n = p - uri; /* n = Length of hostname in bytes. */ hostname = strdup (uri); if (!hostname) { - virXendError (conn, VIR_ERR_NO_MEMORY, "%s", _("strdup failed")); + virReportOOMError (conn); return -1; } hostname[n] = '\0'; @@ -4235,7 +4234,7 @@ xenDaemonDomainMigratePerform (virDomainPtr domain, else { /* "hostname" (or IP address) */ hostname = strdup (uri); if (!hostname) { - virXendError (conn, VIR_ERR_NO_MEMORY, "%s", _("strdup failed")); + virReportOOMError (conn); return -1; } } diff --git a/src/xml.c b/src/xml.c index a7ebe7c..ad77eca 100644 --- a/src/xml.c +++ b/src/xml.c @@ -1,7 +1,7 @@ /* * xml.c: XML based interfaces for the libvir library * - * Copyright (C) 2005, 2007, 2008 Red Hat, Inc. + * Copyright (C) 2005, 2007-2009 Red Hat, Inc. * * See COPYING.LIB for the License of this software * @@ -23,6 +23,8 @@ #include "util.h" #include "memory.h" +#define VIR_FROM_THIS VIR_FROM_XML + #define virXMLError(conn, code, fmt...) \ virReportErrorHelper(conn, VIR_FROM_XML, code, __FILE__, \ __FUNCTION__, __LINE__, fmt) @@ -68,7 +70,7 @@ virXPathString(virConnectPtr conn, ret = strdup((char *) obj->stringval); xmlXPathFreeObject(obj); if (ret == NULL) { - virXMLError(conn, VIR_ERR_NO_MEMORY, "%s", _("strdup failed")); + virReportOOMError(conn); } ctxt->node = relnode; return (ret); @@ -350,9 +352,7 @@ virXPathNodeSet(virConnectPtr conn, ret = obj->nodesetval->nodeNr; if (list != NULL && ret) { if (VIR_ALLOC_N(*list, ret) < 0) { - virXMLError(conn, VIR_ERR_NO_MEMORY, - _("allocate string array size %lu"), - (unsigned long)ret * sizeof(**list)); + virReportOOMError(conn); ret = -1; } else { memcpy(*list, obj->nodesetval->nodeTab, @@ -363,4 +363,3 @@ virXPathNodeSet(virConnectPtr conn, ctxt->node = relnode; return (ret); } - diff --git a/src/xs_internal.c b/src/xs_internal.c index dbbf7f2..c7087ed 100644 --- a/src/xs_internal.c +++ b/src/xs_internal.c @@ -1,7 +1,7 @@ /* * xs_internal.c: access to Xen Store * - * Copyright (C) 2006 Red Hat, Inc. + * Copyright (C) 2006, 2009 Red Hat, Inc. * * See COPYING.LIB for the License of this software * @@ -37,6 +37,8 @@ #include "xs_internal.h" #include "xen_internal.h" +#define VIR_FROM_THIS VIR_FROM_XEN + #ifndef PROXY static char *xenStoreDomainGetOSType(virDomainPtr domain); static void xenStoreWatchEvent(int watch, int fd, int events, void *data); @@ -1271,8 +1273,7 @@ int xenStoreDomainIntroduced(virConnectPtr conn, retry: new_domain_cnt = xenStoreNumOfDomains(conn); if( VIR_ALLOC_N(new_domids,new_domain_cnt) < 0 ) { - virXenStoreError(NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate domids")); + virReportOOMError(NULL); return -1; } nread = xenStoreDoListDomains(priv, new_domids, new_domain_cnt); @@ -1353,8 +1354,7 @@ retry: new_domain_cnt = xenStoreNumOfDomains(conn); if( VIR_ALLOC_N(new_domids,new_domain_cnt) < 0 ) { - virXenStoreError(NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate domids")); + virReportOOMError(NULL); return -1; } nread = xenStoreDoListDomains(priv, new_domids, new_domain_cnt); -- 1.6.1.1.363.g2a3bd -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list