[libvirt] [PATCH 00/10] start tackling *printf issues
by Eric Blake
Based on the long thread about whether %zu and %llu are safe
to use, here's a series of patches to start tackling the
problems. I've got more work to do, but had enough ready that
it was worth posting this much for review, and can push in
pieces as individual patches are ACK'd.
Eric Blake (10):
uml: fix logic bug in checking reply length
nwfilter: use consistent OOM reporting
build: delete dead comment
maint: whitespace cleanups
storage: avoid s[n]printf
squash to dead comment
xenapi: avoid sprintf
vbox: add location used in rpmfusion release
vbox: factor a large function
vbox: avoid sprintf
configure.ac | 1 +
src/nwfilter/nwfilter_driver.c | 6 +-
src/qemu/qemu_driver.c | 1 -
src/storage/storage_backend.c | 16 ++-
src/storage/storage_backend_disk.c | 124 +++++++++-----
src/uml/uml_driver.c | 8 +-
src/vbox/vbox_tmpl.c | 327 +++++++++++++++++++-----------------
src/xen/sexpr.c | 8 -
src/xenapi/xenapi_utils.c | 15 +-
src/xenapi/xenapi_utils.h | 4 -
10 files changed, 277 insertions(+), 233 deletions(-)
--
1.7.2.1
14 years, 3 months
[libvirt] [PATCH] Add support for Vendor and Model in Storage Pool XML
by Patrick Dignan
Hi all,
I wrote a patch to add support for listing the Vendor and Model of a
storage pool in the storage pool XML. This would allow vendor
extensions of specific devices. The patch includes a test for the new
attributes as well. I'd appreciate some feedback on it, and would like
get it merged when it's ready. Patch added at the bottom of the message.
Best,
Patrick Dignan
diff -Naurb libvirt-0.8.2.mod/docs/schemas/storagepool.rng
libvirt-0.8.2.ml/docs/schemas/storagepool.rng
--- libvirt-0.8.2.mod/docs/schemas/storagepool.rng 2010-06-16
17:27:22.000000000 -0500
+++ libvirt-0.8.2.ml/docs/schemas/storagepool.rng 2010-07-30
17:19:32.835531455 -0500
@@ -8,6 +8,10 @@
<define name='pool'>
<element name='pool'>
+ <optional>
+ <ref name='poolvendor'/>
+ <ref name='poolmodel'/>
+ </optional>
<choice>
<ref name='pooldir'/>
<ref name='poolfs'/>
@@ -103,6 +107,18 @@
<ref name='target'/>
</define>
+ <define name='poolvendor'>
+ <attribute name='vendor'>
+ <text/>
+ </attribute>
+ </define>
+
+ <define name='poolmodel'>
+ <attribute name='model'>
+ <text/>
+ </attribute>
+ </define>
+
<define name='commonmetadata'>
<element name='name'>
<ref name='name'/>
diff -Naurb libvirt-0.8.2.mod/include/libvirt/libvirt.h
libvirt-0.8.2.ml/include/libvirt/libvirt.h
--- libvirt-0.8.2.mod/include/libvirt/libvirt.h 2010-07-22
10:26:05.000000000 -0500
+++ libvirt-0.8.2.ml/include/libvirt/libvirt.h 2010-07-30
11:56:48.726415607 -0500
@@ -1141,6 +1141,8 @@
typedef struct _virStoragePoolInfo virStoragePoolInfo;
struct _virStoragePoolInfo {
+ char *vendor;
+ char *model;
int state; /* virStoragePoolState flags */
unsigned long long capacity; /* Logical size bytes */
unsigned long long allocation; /* Current allocation bytes */
diff -Naurb libvirt-0.8.2.mod/src/conf/storage_conf.c
libvirt-0.8.2.ml/src/conf/storage_conf.c
--- libvirt-0.8.2.mod/src/conf/storage_conf.c 2010-06-16
17:27:22.000000000 -0500
+++ libvirt-0.8.2.ml/src/conf/storage_conf.c 2010-08-02
11:52:48.618533010 -0500
@@ -298,6 +298,12 @@
VIR_FREE(def->name);
+ if (def->vendor != "generic")
+ VIR_FREE(def->vendor);
+
+ if (def->model != "generic")
+ VIR_FREE(def->model);
+
virStoragePoolSourceFree(&def->source);
VIR_FREE(def->target.path);
@@ -601,6 +607,8 @@
virStoragePoolDefPtr ret;
xmlNodePtr source_node;
char *type = NULL;
+ char *vendor = NULL;
+ char *model = NULL;
char *uuid = NULL;
char *tmppath;
@@ -616,6 +624,22 @@
goto cleanup;
}
+ /* Get the vendor and model from the XML and set them in the struct */
+ vendor = virXPathString("string(./@vendor)", ctxt);
+ model = virXPathString("string(./@model)", ctxt);
+
+ if (vendor != NULL) {
+ ret->vendor = vendor;
+ } else {
+ ret->vendor = "generic";
+ }
+
+ if (model != NULL) {
+ ret->model = model;
+ } else {
+ ret->model = "generic";
+ }
+
xmlFree(type);
type = NULL;
@@ -861,7 +885,13 @@
"%s", _("unexpected pool type"));
goto cleanup;
}
+
+ if (def->vendor == NULL || def->model == NULL ||
STREQ(def->vendor,"generic") || STREQ(def->model,"generic")) {
virBufferVSprintf(&buf, "<pool type='%s'>\n", type);
+ } else {
+ virBufferVSprintf(&buf, "<pool type='%s' vendor='%s'
model='%s'>\n", type, def->vendor, def->model);
+ }
+
virBufferVSprintf(&buf," <name>%s</name>\n", def->name);
virUUIDFormat(def->uuid, uuid);
diff -Naurb libvirt-0.8.2.mod/src/conf/storage_conf.h
libvirt-0.8.2.ml/src/conf/storage_conf.h
--- libvirt-0.8.2.mod/src/conf/storage_conf.h 2010-06-16
17:27:22.000000000 -0500
+++ libvirt-0.8.2.ml/src/conf/storage_conf.h 2010-07-29
16:37:28.333458251 -0500
@@ -256,6 +256,8 @@
char *name;
unsigned char uuid[VIR_UUID_BUFLEN];
int type; /* virStoragePoolType */
+ char *vendor;
+ char *model;
unsigned long long allocation;
unsigned long long capacity;
diff -Naurb
libvirt-0.8.2.mod/tests/storagepoolxml2xmlin/pool-iscsi-vendor-model.xml
libvirt-0.8.2.ml/tests/storagepoolxml2xmlin/pool-iscsi-vendor-model.xml
---
libvirt-0.8.2.mod/tests/storagepoolxml2xmlin/pool-iscsi-vendor-model.xml
1969-12-31 18:00:00.000000000 -0600
+++
libvirt-0.8.2.ml/tests/storagepoolxml2xmlin/pool-iscsi-vendor-model.xml
2010-08-02 12:00:37.015538583 -0500
@@ -0,0 +1,17 @@
+<pool type='iscsi' vendor='test-vendor' model='test-model'>
+ <name>virtimages</name>
+ <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+ <source>
+ <host name="iscsi.example.com"/>
+ <device path="demo-target"/>
+ <auth type='chap' login='foobar' passwd='frobbar'/>
+ </source>
+ <target>
+ <path>/dev/disk/by-path</path>
+ <permissions>
+ <mode>0700</mode>
+ <owner>0</owner>
+ <group>0</group>
+ </permissions>
+ </target>
+</pool>
diff -Naurb
libvirt-0.8.2.mod/tests/storagepoolxml2xmlout/pool-iscsi-vendor-model.xml libvirt-0.8.2.ml/tests/storagepoolxml2xmlout/pool-iscsi-vendor-model.xml
---
libvirt-0.8.2.mod/tests/storagepoolxml2xmlout/pool-iscsi-vendor-model.xml
1969-12-31 18:00:00.000000000 -0600
+++
libvirt-0.8.2.ml/tests/storagepoolxml2xmlout/pool-iscsi-vendor-model.xml
2010-08-02 12:16:19.571537734 -0500
@@ -0,0 +1,20 @@
+<pool type='iscsi' vendor='test-vendor' model='test-model'>
+ <name>virtimages</name>
+ <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+ <capacity>0</capacity>
+ <allocation>0</allocation>
+ <available>0</available>
+ <source>
+ <host name='iscsi.example.com'/>
+ <device path='demo-target'/>
+ <auth type='chap' login='foobar' passwd='frobbar'/>
+ </source>
+ <target>
+ <path>/dev/disk/by-path</path>
+ <permissions>
+ <mode>0700</mode>
+ <owner>0</owner>
+ <group>0</group>
+ </permissions>
+ </target>
+</pool>
diff -Naurb libvirt-0.8.2.mod/tests/storagepoolxml2xmltest.c
libvirt-0.8.2.ml/tests/storagepoolxml2xmltest.c
--- libvirt-0.8.2.mod/tests/storagepoolxml2xmltest.c 2010-06-16
17:27:22.000000000 -0500
+++ libvirt-0.8.2.ml/tests/storagepoolxml2xmltest.c 2010-08-02
12:32:47.838532225 -0500
@@ -96,6 +96,7 @@
DO_TEST("pool-scsi");
DO_TEST("pool-mpath");
DO_TEST("pool-iscsi-multiiqn");
+ DO_TEST("pool-iscsi-vendor-model");
return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
14 years, 3 months
[libvirt] [PATCH] Support virDomainAttachDevice and virDomainDetachDevice for disks in UML
by soren@linux2go.dk
From: Soren Hansen <soren(a)linux2go.dk>
UML supports hot plugging and unplugging of various devices. This patch
exposes this functionality for disks.
Signed-off-by: Soren Hansen <soren(a)linux2go.dk>
---
src/uml/uml_driver.c | 223 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 221 insertions(+), 2 deletions(-)
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 04493ba..a09bc60 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1686,6 +1686,225 @@ cleanup:
}
+static inline void umlShrinkDisks(virDomainDefPtr def, size_t i)
+{
+ if (def->ndisks > 1) {
+ memmove(def->disks + i,
+ def->disks + i + 1,
+ sizeof(*def->disks) *
+ (def->ndisks - (i + 1)));
+ def->ndisks--;
+ if (VIR_REALLOC_N(def->disks, def->ndisks) < 0) {
+ /* ignore, harmless */
+ }
+ } else {
+ VIR_FREE(def->disks);
+ def->ndisks = 0;
+ }
+}
+
+
+static int umlDomainAttachUmlDisk(struct uml_driver *driver,
+ virDomainObjPtr vm,
+ virDomainDiskDefPtr disk)
+{
+ int i, ret;
+ char *cmd = NULL;
+ char *reply;
+
+ for (i = 0 ; i < vm->def->ndisks ; i++) {
+ if (STREQ(vm->def->disks[i]->dst, disk->dst)) {
+ umlReportError(VIR_ERR_OPERATION_FAILED,
+ _("target %s already exists"), disk->dst);
+ return -1;
+ }
+ }
+
+ if (!disk->src) {
+ umlReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("disk source path is missing"));
+ goto error;
+ }
+
+ if (virAsprintf(&cmd, "config %s=%s", disk->dst, disk->src) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
+ if (umlMonitorCommand(driver, vm, cmd, &reply) < 0)
+ return -1;
+
+ if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) {
+ virReportOOMError();
+ goto error;
+ }
+
+ if (ret < 0)
+ goto error;
+
+ virDomainDiskInsertPreAlloced(vm->def, disk);
+
+ VIR_FREE(cmd);
+
+ return 0;
+
+error:
+
+ VIR_FREE(cmd);
+
+ return -1;
+}
+
+
+static int umlDomainAttachDevice(virDomainPtr dom, const char *xml)
+{
+ struct uml_driver *driver = dom->conn->privateData;
+ virDomainObjPtr vm;
+ virDomainDeviceDefPtr dev = NULL;
+ int ret = -1;
+
+ umlDriverLock(driver);
+
+ vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+ if (!vm) {
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+ virUUIDFormat(dom->uuid, uuidstr);
+ umlReportError(VIR_ERR_NO_DOMAIN,
+ _("no domain with matching uuid '%s'"), uuidstr);
+ goto cleanup;
+ }
+
+ if (!virDomainObjIsActive(vm)) {
+ umlReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("cannot attach device on inactive domain"));
+ goto cleanup;
+ }
+
+ dev = virDomainDeviceDefParse(driver->caps, vm->def, xml,
+ VIR_DOMAIN_XML_INACTIVE);
+
+ if (dev == NULL)
+ goto cleanup;
+
+ if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
+ if (dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_UML) {
+ ret = umlDomainAttachUmlDisk(driver, vm, dev->data.disk);
+ if (ret == 0)
+ dev->data.disk = NULL;
+ } else {
+ umlReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("disk bus '%s' cannot be hotplugged."),
+ virDomainDiskBusTypeToString(dev->data.disk->bus));
+ }
+ } else {
+ umlReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("device type '%s' cannot be attached"),
+ virDomainDeviceTypeToString(dev->type));
+ goto cleanup;
+ }
+
+cleanup:
+
+ virDomainDeviceDefFree(dev);
+ if (vm)
+ virDomainObjUnlock(vm);
+ umlDriverUnlock(driver);
+ return ret;
+}
+
+
+static int umlDomainDetachUmlDisk(struct uml_driver *driver,
+ virDomainObjPtr vm,
+ virDomainDeviceDefPtr dev)
+{
+ int i, ret = -1;
+ virDomainDiskDefPtr detach = NULL;
+ char *cmd;
+ char *reply;
+
+ for (i = 0 ; i < vm->def->ndisks ; i++) {
+ if (STREQ(vm->def->disks[i]->dst, dev->data.disk->dst)) {
+ break;
+ }
+ }
+
+ if (i == vm->def->ndisks) {
+ umlReportError(VIR_ERR_OPERATION_FAILED,
+ _("disk %s not found"), dev->data.disk->dst);
+ return -1;
+ }
+
+ detach = vm->def->disks[i];
+
+ if (virAsprintf(&cmd, "remove %s", detach->dst) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
+ if (umlMonitorCommand(driver, vm, cmd, &reply) < 0)
+ goto cleanup;
+
+ umlShrinkDisks(vm->def, i);
+
+ virDomainDiskDefFree(detach);
+
+ ret = 0;
+
+cleanup:
+ VIR_FREE(cmd);
+
+ return ret;
+}
+
+
+static int umlDomainDetachDevice(virDomainPtr dom, const char *xml) {
+ struct uml_driver *driver = dom->conn->privateData;
+ virDomainObjPtr vm;
+ virDomainDeviceDefPtr dev = NULL;
+ int ret = -1;
+
+ umlDriverLock(driver);
+ vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+ if (!vm) {
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+ virUUIDFormat(dom->uuid, uuidstr);
+ umlReportError(VIR_ERR_NO_DOMAIN,
+ _("no domain with matching uuid '%s'"), uuidstr);
+ goto cleanup;
+ }
+
+ if (!virDomainObjIsActive(vm)) {
+ umlReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("cannot detach device on inactive domain"));
+ goto cleanup;
+ }
+
+ dev = virDomainDeviceDefParse(driver->caps, vm->def, xml,
+ VIR_DOMAIN_XML_INACTIVE);
+ if (dev == NULL)
+ goto cleanup;
+
+ if (dev->type == VIR_DOMAIN_DEVICE_DISK &&
+ dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
+ if (dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_UML)
+ ret = umlDomainDetachUmlDisk(driver, vm, dev);
+ else {
+ umlReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("This type of disk cannot be hot unplugged"));
+ }
+ } else {
+ umlReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ "%s", _("This type of device cannot be hot unplugged"));
+ }
+
+cleanup:
+ virDomainDeviceDefFree(dev);
+ if (vm)
+ virDomainObjUnlock(vm);
+ umlDriverUnlock(driver);
+ return ret;
+}
+
static int umlDomainGetAutostart(virDomainPtr dom,
int *autostart) {
@@ -1900,9 +2119,9 @@ static virDriver umlDriver = {
umlDomainStartWithFlags, /* domainCreateWithFlags */
umlDomainDefine, /* domainDefineXML */
umlDomainUndefine, /* domainUndefine */
- NULL, /* domainAttachDevice */
+ umlDomainAttachDevice, /* domainAttachDevice */
NULL, /* domainAttachDeviceFlags */
- NULL, /* domainDetachDevice */
+ umlDomainDetachDevice, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
umlDomainGetAutostart, /* domainGetAutostart */
--
1.7.0.4
14 years, 3 months
[libvirt] [PATCH] build: fix compiler warning
by Eric Blake
node_device/node_device_driver.c: In function 'nodeDeviceVportCreateDelete':
node_device/node_device_driver.c:423: error: implicit declaration of function 'stat' [-Wimplicit-function-declaration]
* src/node_device/node_device_driver.c (includes): Add <sys/stat.h>.
---
Pushing as obvious under the build-breaker rule.
src/node_device/node_device_driver.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index a6ac80b..448cfd3 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -1,6 +1,7 @@
/*
* node_device.c: node device enumeration
*
+ * Copyright (C) 2010 Red Hat, Inc.
* Copyright (C) 2008 Virtual Iron Software, Inc.
* Copyright (C) 2008 David F. Lively
*
@@ -27,6 +28,7 @@
#include <errno.h>
#include <fcntl.h>
#include <time.h>
+#include <sys/stat.h>
#include "virterror_internal.h"
#include "datatypes.h"
--
1.7.2.1
14 years, 3 months
[libvirt] virsh attach-disk using files and KVM
by Ryan Harper
Currently virsh attach-disk interface only accepts 'file' or 'tap' for
driver type when attaching files as disks. One can succesfully attach
a file as disk with:
virsh attach-disk <vm> <file> <drive> --driver file --type disk
which generates the following xml which is passed to libvirt:
<disk type='file' device='disk'>
<driver name='file' type='raw'/>
<source file='/images/test02.img'/>
<target dev='vdc' bus='virtio'/>
<alias name='virtio-disk2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
Now, if you shutdown the guest and restart, libvirt complains that the
driver type 'file' isn't supported. This is from
src/qemu/qemu_conf.c:4146 where if the driver name isn't 'qemu' it
rejects the configuration.
How best to resolve this? Update qemu_conf.c to accept 'file' type?
update virsh to allow specifying 'qemu' as a driver type for files?
--
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
ryanh(a)us.ibm.com
14 years, 3 months
[libvirt] [PATCH 0/5] Salvage old fixes
by Jiri Denemark
The following fixes did never make it to upstream libvirt
Daniel Berrange (2):
remote: Fix incorrect use of private data field
xen: Fix device count on detach
Daniel Veillard (1):
xen: Fix scheduler setting problems
Dave Allan (1):
nodedev: Fix sysfs paths for vport operations
Jiri Denemark (1):
nodedev: Free the right pointers when getting WWNs fails
src/conf/node_device_conf.c | 4 +-
src/node_device/node_device_driver.c | 21 +++++++++++++++++++
src/node_device/node_device_driver.h | 2 +-
src/node_device/node_device_linux_sysfs.c | 31 +++++++++++++++++++++++-----
src/remote/remote_driver.c | 10 +++++++-
src/xen/xen_driver.c | 3 +-
src/xen/xen_hypervisor.c | 4 +-
src/xen/xm_internal.c | 2 +
8 files changed, 63 insertions(+), 14 deletions(-)
--
1.7.2
14 years, 3 months
[libvirt] cygwin: #include netinet/inet.h -- needed only on cygwin
by Stefan Berger
When doing './autogen.sh --with-sasl --with-libvirtd=no' on cygwin, I
needed to #include netinet/in.h for a successful build. Now
authentication using SASL works.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
diff --git a/src/remote/qemu_protocol.h b/src/remote/qemu_protocol.h
index b822187..8d806fc 100644
--- a/src/remote/qemu_protocol.h
+++ b/src/remote/qemu_protocol.h
@@ -6,6 +6,9 @@
#ifndef _RP_QEMU_H_RPCGEN
#define _RP_QEMU_H_RPCGEN
+#ifdef __CYGWIN__
+# include <netinet/in.h>
+#endif
#include <rpc/rpc.h>
diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h
index afe9287..113818d 100644
--- a/src/remote/remote_protocol.h
+++ b/src/remote/remote_protocol.h
@@ -6,6 +6,9 @@
#ifndef _RP_H_RPCGEN
#define _RP_H_RPCGEN
+#ifdef __CYGWIN__
+# include <netinet/in.h>
+#endif
#include <rpc/rpc.h>
14 years, 3 months
Re: [libvirt] how to print size_t in LGPLv2+ program
by Eric Blake
On 08/17/2010 03:47 PM, Paul Eggert wrote:
> On 08/17/10 23:17, Eric Blake wrote:
>
>> libvirt is currently LGPLv2+
>
> Can this be changed to LPGLv3+? That'd solve the problem.
True, but it would have knock-on effects on all sorts of other clients
of libvirt. I'm re-adding the libvirt list for thoughts from anyone else.
>
>> Is it worth relaxing the license on the *printf-posix family of modules
>> to LGPLv2+ from their current LGPLv3+, or is this too big of a request?
>
> I dunno, at some point we should be encouraging people to switch
> to LGPLv3+.
It makes sense for the FSF to request that GNU projects use better
licenses. Unfortunately, libvirt is not a GNU project; so it is more a
question as to how Red Hat wants to license it, rather than what the FSF
prefers. At any rate, I think the ultimate decision on how libvirt is
licensed is rather political in nature, and will involve quite a bit of
discussion among more than just the software developers contributing to
libvirt.
But at least libvirt is LGPLv2+; unlike some projects (like git) that
are explicitly v2-only and can't do the upgrade.
Meanwhile, I tend to agree that relaxing printf-posix to LGPLv2+ is a
rather hefty sledge-hammer, and probably not appropriate for gnulib.
>
>> since using umaxtostr penalizes 32-bit machines for converting to the
>> 64-bit intermediary, maybe it's worth adding a size_t variant?
>
> That would be fine. The *tostr routines were mainly written
> for two reasons. First, for platforms that can't/couldn't portably
> and reliably output wide integers. Second, speed.
>
>> What a shame that POSIX omitted an <inttypes.h> PRIu* for size_t.
>
> We could add one in gnulib, no?
In a quick google search, I found this use of PRIdS (which is geared
more for ssize_t, but the analog PRIuS would apply to size_t):
http://bytes.com/topic/c/answers/506972-64-bit-portability-size_t-printf-...
However, S is awfully short; I'd prefer something a bit longer like
PRIuSIZE.
Is there any other project already using gnulib that has invented a
PRIuXXX name for size_t? It would also be nice if we had some prior art
from glibc or even one of the BSD systems to copy a commonly-used name.
Meanwhile, the idea is slightly more appealing than relicensing lots of
gnulib or using the inttostr code; but it still requires auditing code
and forbidding "%zu" in favor of "%"PRIuSIZE (or whatever other name we
settle on).
Also, it seems like we might want to create a new intttypes-plus (or
inttypes-gnu) module, and leave the existing inttypes module as
providing just the namespace guaranteed by glibc, while requiring the
use of the new module to pollute the namespace with these new (but
useful) macros.
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
14 years, 3 months
[libvirt] [PATCH] esx: Fix memory leak when looking up an non-existing domain by name
by Matthias Bolte
In case an optional object cannot be found the lookup function is
left early and the cleanup code is not executed. Add a success label
and goto instead of an early return.
This pattern occurs in some other functions too.
---
src/esx/esx_vi.c | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index c6b2b63..b064b11 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -2254,7 +2254,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
if (managedObjectReference == NULL) {
if (occurrence == esxVI_Occurrence_OptionalItem) {
- return 0;
+ goto success;
} else {
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
_("Could not find domain with UUID '%s'"),
@@ -2270,6 +2270,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
goto cleanup;
}
+ success:
result = 0;
cleanup:
@@ -2327,7 +2328,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
if (*virtualMachine == NULL) {
if (occurrence == esxVI_Occurrence_OptionalItem) {
- return 0;
+ goto success;
} else {
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
_("Could not find domain with name '%s'"), name);
@@ -2335,6 +2336,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
}
}
+ success:
result = 0;
cleanup:
@@ -2890,7 +2892,7 @@ esxVI_LookupCurrentSnapshotTree
if (currentSnapshot == NULL) {
if (occurrence == esxVI_Occurrence_OptionalItem) {
- return 0;
+ goto success;
} else {
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s",
_("Domain has no current snapshot"));
@@ -2911,6 +2913,7 @@ esxVI_LookupCurrentSnapshotTree
goto cleanup;
}
+ success:
result = 0;
cleanup:
@@ -3050,9 +3053,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
/* Interpret search result */
if (searchResults->file == NULL) {
if (occurrence == esxVI_Occurrence_OptionalItem) {
- result = 0;
-
- goto cleanup;
+ goto success;
} else {
ESX_VI_ERROR(VIR_ERR_NO_STORAGE_VOL,
_("No storage volume with key or path '%s'"),
@@ -3064,6 +3065,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
*fileInfo = searchResults->file;
searchResults->file = NULL;
+ success:
result = 0;
cleanup:
--
1.7.0.4
14 years, 3 months