[libvirt] [PATCH] Don't use SO_REUSEADDR on Win32 platforms
by Daniel P. Berrange
SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT
on Linux/BSD. ie it allows 2 apps to listen to the same
port at once. Thus we must not set it on Win32 platforms
See http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621.aspx
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/rpc/virnetsocket.c | 16 ++++++++++++++++
src/util/virportallocator.c | 9 +++++++++
2 files changed, 25 insertions(+)
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 2e94a6c..65efdb6 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -255,11 +255,18 @@ int virNetSocketNewListenTCP(const char *nodename,
goto error;
}
+#ifndef WIN32
+ /*
+ * SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT
+ * on Linux/BSD. ie it allows 2 apps to listen to the same
+ * port at once. Thus we must not set it on Win32 platforms
+ */
int opt = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
virReportSystemError(errno, "%s", _("Unable to enable port reuse"));
goto error;
}
+#endif
#ifdef IPV6_V6ONLY
if (runp->ai_family == PF_INET6) {
@@ -460,7 +467,9 @@ int virNetSocketNewConnectTCP(const char *nodename,
runp = ai;
while (runp) {
+#ifndef WIN32
int opt = 1;
+#endif
if ((fd = socket(runp->ai_family, runp->ai_socktype,
runp->ai_protocol)) < 0) {
@@ -468,9 +477,16 @@ int virNetSocketNewConnectTCP(const char *nodename,
goto error;
}
+#ifndef WIN32
+ /*
+ * SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT
+ * on Linux/BSD. ie it allows 2 apps to listen to the same
+ * port at once. Thus we must not set it on Win32 platforms
+ */
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
VIR_WARN("Unable to enable port reuse");
}
+#endif
if (connect(fd, runp->ai_addr, runp->ai_addrlen) >= 0)
break;
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index ed7bdc2..0f22ea1 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -116,7 +116,9 @@ static int virPortAllocatorBindToPort(bool *used,
struct sockaddr* addr;
size_t addrlen;
int v6only = 1;
+#ifndef WIN32
int reuse = 1;
+#endif
int ret = -1;
int fd = -1;
bool ipv6 = false;
@@ -143,12 +145,19 @@ static int virPortAllocatorBindToPort(bool *used,
goto cleanup;
}
+#ifndef WIN32
+ /*
+ * SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT
+ * on Linux/BSD. ie it allows 2 apps to listen to the same
+ * port at once. Thus we must not set it on Win32 platforms
+ */
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*)&reuse,
sizeof(reuse)) < 0) {
virReportSystemError(errno, "%s",
_("Unable to set socket reuse addr flag"));
goto cleanup;
}
+#endif
if (ipv6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&v6only,
sizeof(v6only)) < 0) {
--
1.9.0
10 years, 7 months
[libvirt] [PATCH] build: add nwfilterxml2firewalldata to dist
by Dwight Engen
Signed-off-by: Dwight Engen <dwight.engen(a)oracle.com>
---
tests/Makefile.am | 1 +
1 file changed, 1 insertion(+)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ba79d64..4a5e14b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -96,6 +96,7 @@ EXTRA_DIST = \
nodedevschematest \
nodeinfodata \
nwfilterschematest \
+ nwfilterxml2firewalldata \
nwfilterxml2xmlin \
nwfilterxml2xmlout \
oomtrace.pl \
--
1.9.0
10 years, 7 months
[libvirt] [PATCH] libxl: Support PV consoles
by Ian Campbell
Currently the driver only exposes the ability to connect to the serial console
of a Xen guest, which doesn't work for a PV guest. Instead look for a PV
console first and a serial console second, if an HVM guest has a PV console
then it is a good bet that it is preferred, I think.
Tested with the following bit of config XML:
<domain type='xen'>
...
<devices>
<console type='pty'>
<target type='xen'/>
</console>
</devices>
</domain>
I have observed and tested this on ARM but I believe it also applies to x86 PV
guests.
Signed-off-by: Ian Campbell <ian.campbell(a)citrix.com>
Cc: Jim Fehlig <jfehlig(a)suse.com>
Cc: Dario Faggioli <dario.faggioli(a)citrix.com>
Cc: Clark Laughlin <clark.laughlin(a)linaro.org>
---
src/libxl/libxl_driver.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index a6ae8a1..bcf3595 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3780,6 +3780,7 @@ libxlDomainOpenConsole(virDomainPtr dom,
{
virDomainObjPtr vm = NULL;
int ret = -1;
+ libxl_console_type console_type = LIBXL_CONSOLE_TYPE_UNKNOWN;
virDomainChrDefPtr chr = NULL;
libxlDomainObjPrivatePtr priv;
char *console = NULL;
@@ -3807,8 +3808,15 @@ libxlDomainOpenConsole(virDomainPtr dom,
priv = vm->privateData;
- if (vm->def->nserials)
+ if (!chr && vm->def->nconsoles) {
+ chr = vm->def->consoles[0];
+ console_type = LIBXL_CONSOLE_TYPE_PV;
+ }
+
+ if (!chr && vm->def->nserials) {
chr = vm->def->serials[0];
+ console_type = LIBXL_CONSOLE_TYPE_SERIAL;
+ }
if (!chr) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3824,7 +3832,8 @@ libxlDomainOpenConsole(virDomainPtr dom,
goto cleanup;
}
- ret = libxl_primary_console_get_tty(priv->ctx, vm->def->id, &console);
+ ret = libxl_console_get_tty(priv->ctx, vm->def->id, chr->target.port,
+ console_type, &console);
if (ret)
goto cleanup;
--
1.7.10.4
10 years, 7 months
[libvirt] Schedule for next release 1.2.4
by Daniel Veillard
Sorry about the late notice, I forgot about the end of month
coming. It seems we are trying a lot of patches in right now,
but it would be good to not drift too much, so I am suggesting
to enter the freeze on Monday morning. This mean I could push
1.2.4 either on Friday if everything looks really good or wait
till May 5 for things to settle.
I hope this suits everybody and sorry for late warning !
Daniel
--
Daniel Veillard | Open Source and Standards, Red Hat
veillard(a)redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | virtualization library http://libvirt.org/
10 years, 7 months
[libvirt] [PATCH] qemu: Avoid overflow when setting migration speed on inactive domains
by Jiri Denemark
Commit c4206d7 fixed the overflow for running domains. However, we need
a similar check when setting migration speed on inactive domains.
At first look, it may seem the check in c4206d7 is now redundant but
qemuDomainMigrateSetMaxSpeed is not the only caller of
qemuMonitorSetMigrationSpeed so we need to check the bandwidth in both
places.
https://bugzilla.redhat.com/show_bug.cgi?id=1083483
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_driver.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 67ba487..69a7053 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11927,6 +11927,13 @@ qemuDomainMigrateSetMaxSpeed(virDomainPtr dom,
if (virDomainMigrateSetMaxSpeedEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
+ if (bandwidth > QEMU_DOMAIN_MIG_BANDWIDTH_MAX) {
+ virReportError(VIR_ERR_OVERFLOW,
+ _("bandwidth must be less than %llu"),
+ QEMU_DOMAIN_MIG_BANDWIDTH_MAX + 1ULL);
+ goto cleanup;
+ }
+
if (virDomainObjIsActive(vm)) {
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MIGRATION_OP) < 0)
goto cleanup;
--
1.9.2
10 years, 7 months
[libvirt] [PATCH v5 0/5] Expose FSFreeze/FSThaw within the guest as API
by Tomoki Sekiyama
Hello,
This is patchset v5 to add FSFreeze/FSThaw API for custom disk snapshotting.
Changes to v4:
* add disks and ndisks parameter to specify disks to be frozen/thawed
* make fsfreeze requests nestable
* change api version to 1.2.4
(v4: https://www.redhat.com/archives/libvir-list/2014-March/msg01674.html )
=== Description ===
Currently FSFreeze and FSThaw are supported by qemu guest agent and they are
used internally in snapshot-create command with --quiesce option.
However, when users want to utilize the native snapshot feature of storage
devices (such as LVM over iSCSI, enterprise storage appliances, etc.),
they need to issue fsfreeze command separately from libvirt-driven snapshots.
(OpenStack cinder provides these storages' snapshot feature, but it cannot
quiesce the guest filesystems automatically for now.)
Although virDomainQemuGuestAgent() API could be used for this purpose, it
is only for debugging and is not supported officially.
This patchset adds virDomainFSFreeze()/virDomainFSThaw() APIs and virsh
domfsfreeze/domfsthaw commands to enable the users to freeze and thaw
domain's filesystems cleanly.
<updated>
The APIs take disks and ndisks parameters, which is a list of disk names
to be frozen/thawed. If the option is not provided, every mounted
filesystem is frozen/thawed.
The fsfreeze can be nestable. When fsfreeze requests to a disk are issued
multiple times, it is not thawed until the fsthaw requests are issued as
many times as the freeze requests.
Currently, qemu driver doesn't support disks parameter because the guest
agent doesn't have means to specify disks to be frozen/thawed. Hence, it
just counts depth of fsfreeze per domain, not per disk, so far.
</updated>
The APIs have flags option currently unsupported for future extension.
---
Tomoki Sekiyama (5):
Introduce virDomainFSFreeze() and virDomainFSThaw() public API
remote: Implement virDomainFSFreeze and virDomainFSThaw
qemu: Track domain quiesced status and make fsfreeze/thaw nestable
qemu: Implement virDomainFSFreeze and virDomainFSThaw
virsh: Expose new virDomainFSFreeze and virDomainFSThaw API
include/libvirt/libvirt.h.in | 10 +++
src/access/viraccessperm.c | 2 -
src/access/viraccessperm.h | 6 ++
src/driver.h | 14 ++++
src/libvirt.c | 92 ++++++++++++++++++++++++
src/libvirt_public.syms | 6 ++
src/qemu/qemu_domain.c | 6 ++
src/qemu/qemu_domain.h | 2 +
src/qemu/qemu_driver.c | 159 ++++++++++++++++++++++++++++++++++++++----
src/remote/remote_driver.c | 2 +
src/remote/remote_protocol.x | 30 +++++++-
src/remote_protocol-structs | 18 +++++
src/rpc/gendispatch.pl | 2 +
tools/virsh-domain.c | 128 ++++++++++++++++++++++++++++++++++
tools/virsh.pod | 23 ++++++
15 files changed, 483 insertions(+), 17 deletions(-)
10 years, 7 months
[libvirt] [PATCH 0/9] Standardize on lookup of resources in build dir
by Daniel P. Berrange
Instead of having a bunch of custom override functions for each
different area of code, standardize on one set of helper APIs
for loading resources.
This is derived from Nehal's proposal, based on my / Eric's feedback
https://www.redhat.com/archives/libvir-list/2014-March/msg01544.html
Daniel P. Berrange (5):
Add helpers for resolving path to resources in build tree
Activate build dir overrides in libvirtd, virtlockd & tests
Use virFileFindResource to locate lock manager plugins
Use virFileFindResource to locate driver plugins
Use virFileFindResource to locate CPU map XML
Nehal J Wani (4):
Use virFileFindResource to locate iohelper for virFileWrapperFdNew
Use virFileFindResource to locate libvirt_lxc for capabilities
Use virFileFindResource to locate parthelper for storage backend
Use virFileFindResource to locate iohelper for fdstream
daemon/libvirtd.c | 31 +-----------
src/Makefile.am | 2 +
src/cpu/cpu_map.c | 31 ++++--------
src/cpu/cpu_map.h | 3 --
src/driver.c | 26 +++--------
src/driver.h | 1 -
src/fdstream.c | 21 ++++-----
src/fdstream.h | 3 --
src/libvirt_private.syms | 4 +-
src/locking/lock_daemon.c | 2 +
src/locking/lock_manager.c | 28 ++++-------
src/locking/lock_manager.h | 1 -
src/lxc/lxc_conf.c | 14 +++++-
src/storage/storage_backend_disk.c | 31 +++++++++---
src/util/virfile.c | 96 +++++++++++++++++++++++++++++++++++++-
src/util/virfile.h | 11 +++++
tests/cputest.c | 14 ------
tests/fdstreamtest.c | 3 --
tests/qemuxml2argvtest.c | 7 ---
tests/qemuxmlnstest.c | 7 ---
tests/testutils.c | 2 +
tests/virdrivermoduletest.c | 2 -
22 files changed, 187 insertions(+), 153 deletions(-)
--
1.9.0
10 years, 7 months
[libvirt] [PATCH] build: avoid 'index' as variable name
by Eric Blake
Once again, gcc 4.4.7 (hello RHEL) rears its ugly head:
conf/domain_conf.c: In function 'virDomainDiskBackingStoreFormat':
conf/domain_conf.c:14940: error: declaration of 'index' shadows a global declaration [-Wshadow]
/usr/include/string.h:489: error: shadowed declaration is here [-Wshadow]
* src/conf/domain_conf.c (virDomainDiskBackingStoreFormat): Pacify
older gcc.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
Pushing under the build-breaker rule.
src/conf/domain_conf.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a558b1b..c655bcf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14937,7 +14937,7 @@ static int
virDomainDiskBackingStoreFormat(virBufferPtr buf,
virStorageSourcePtr backingStore,
const char *backingStoreRaw,
- unsigned int index)
+ unsigned int idx)
{
const char *type;
const char *format;
@@ -14965,7 +14965,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
}
virBufferAsprintf(buf, "<backingStore type='%s' index='%u'>\n",
- type, index);
+ type, idx);
virBufferAdjustIndent(buf, 2);
virBufferAsprintf(buf, "<format type='%s'/>\n", format);
@@ -14973,7 +14973,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
virDomainDiskBackingStoreFormat(buf,
backingStore->backingStore,
backingStore->backingStoreRaw,
- index + 1) < 0)
+ idx + 1) < 0)
return -1;
virBufferAdjustIndent(buf, -2);
--
1.7.1
10 years, 7 months
[libvirt] [PATCH] Add test suite for viralloc APIs
by Daniel P. Berrange
In debugging a crash on OOM, I thought that the virInsert APIs
might be at fault, but couldn't isolate them as a cause. While
the viralloc APIs are used in many test suites, this is as a
side-effect, they are not directly tested :-)
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
tests/Makefile.am | 5 +
tests/viralloctest.c | 387 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 392 insertions(+)
create mode 100644 tests/viralloctest.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 122bf6c..c13cc15 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -140,6 +140,7 @@ test_programs = virshtest sockettest \
viratomictest \
utiltest shunloadtest \
virtimetest viruritest virkeyfiletest \
+ viralloctest \
virauthconfigtest \
virbitmaptest \
vircgrouptest \
@@ -929,6 +930,10 @@ virkeyfiletest_SOURCES = \
virkeyfiletest.c testutils.h testutils.c
virkeyfiletest_LDADD = $(LDADDS)
+viralloctest_SOURCES = \
+ viralloctest.c testutils.h testutils.c
+viralloctest_LDADD = $(LDADDS)
+
virauthconfigtest_SOURCES = \
virauthconfigtest.c testutils.h testutils.c
virauthconfigtest_LDADD = $(LDADDS)
diff --git a/tests/viralloctest.c b/tests/viralloctest.c
new file mode 100644
index 0000000..abdd871
--- /dev/null
+++ b/tests/viralloctest.c
@@ -0,0 +1,387 @@
+/*
+ * viralloctest.c: Test memory allocation APIs
+ *
+ * Copyright (C) 2014 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+
+#include <viralloc.h>
+
+#include "testutils.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+typedef struct testDummyStruct {
+ int a;
+ int b;
+} testDummyStruct;
+
+static int
+testAllocScalar(const void *opaque ATTRIBUTE_UNUSED)
+{
+ testDummyStruct *t;
+ int ret = -1;
+
+ if (VIR_ALLOC(t) < 0)
+ return -1;
+
+ if (t == NULL) {
+ fprintf(stderr, "Allocation succeeded by pointer is NULL\n");
+ goto cleanup;
+ }
+
+ if (t->a != 0 ||
+ t->b != 0) {
+ fprintf(stderr, "Allocated ram was not zerod\n");
+ goto cleanup;
+ }
+
+ VIR_FREE(t);
+
+ if (t != NULL) {
+ fprintf(stderr, "Pointer is still set after free\n");
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(t);
+ return ret;
+}
+
+
+static int
+testAllocArray(const void *opaque ATTRIBUTE_UNUSED)
+{
+ testDummyStruct *t;
+ size_t nt = 10, i;
+ int ret = -1;
+
+ if (VIR_ALLOC_N(t, nt) < 0)
+ return -1;
+
+ if (t == NULL) {
+ fprintf(stderr, "Allocation succeeded by pointer is NULL\n");
+ goto cleanup;
+ }
+
+ for (i = 0; i < nt; i++) {
+ if (t[i].a != 0 ||
+ t[i].b != 0) {
+ fprintf(stderr, "Allocated ram block %zu was not zerod\n", i);
+ goto cleanup;
+ }
+ }
+
+ VIR_FREE(t);
+
+ if (t != NULL) {
+ fprintf(stderr, "Pointer is still set after free\n");
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(t);
+ return ret;
+}
+
+
+static int
+testReallocArray(const void *opaque ATTRIBUTE_UNUSED)
+{
+ testDummyStruct *t;
+ size_t nt = 10, i;
+ int ret = -1;
+
+ if (VIR_ALLOC_N(t, nt) < 0)
+ return -1;
+
+ if (t == NULL) {
+ fprintf(stderr, "Allocation succeeded by pointer is NULL\n");
+ goto cleanup;
+ }
+
+ for (i = 0; i < nt; i++) {
+ t[i].a = 10;
+ t[i].b = 20;
+ }
+
+ if (VIR_REALLOC_N(t, nt + 5) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nt; i++) {
+ if (t[i].a != 10 ||
+ t[i].b != 20) {
+ fprintf(stderr, "Reallocated ram block %zu lost data\n", i);
+ goto cleanup;
+ }
+ }
+
+ if (VIR_REALLOC_N(t, nt) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nt; i++) {
+ if (t[i].a != 10 ||
+ t[i].b != 20) {
+ fprintf(stderr, "Reallocated ram block %zu lost data\n", i);
+ goto cleanup;
+ }
+ }
+
+ if (VIR_REALLOC_N(t, nt - 5) < 0)
+ goto cleanup;
+
+ for (i = 0; i < (nt - 5); i++) {
+ if (t[i].a != 10 ||
+ t[i].b != 20) {
+ fprintf(stderr, "Reallocated ram block %zu lost data\n", i);
+ goto cleanup;
+ }
+ }
+
+ VIR_FREE(t);
+
+ if (t != NULL) {
+ fprintf(stderr, "Pointer is still set after free\n");
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(t);
+ return ret;
+}
+
+
+static int
+testExpandArray(const void *opaque ATTRIBUTE_UNUSED)
+{
+ testDummyStruct *t;
+ size_t nt = 10, i;
+ int ret = -1;
+
+ if (VIR_ALLOC_N(t, nt) < 0)
+ return -1;
+
+ if (t == NULL) {
+ fprintf(stderr, "Allocation succeeded by pointer is NULL\n");
+ goto cleanup;
+ }
+
+ for (i = 0; i < nt; i++) {
+ t[i].a = 10;
+ t[i].b = 20;
+ }
+
+ if (VIR_EXPAND_N(t, nt, 5) < 0)
+ goto cleanup;
+
+ for (i = 0; i < (nt - 5); i++) {
+ if (t[i].a != 10 ||
+ t[i].b != 20) {
+ fprintf(stderr, "Reallocated ram block %zu lost data\n", i);
+ goto cleanup;
+ }
+ }
+
+ for (i = (nt - 5); i < nt; i++) {
+ if (t[i].a != 0 ||
+ t[i].b != 0) {
+ fprintf(stderr, "New ram block %zu was not zerod\n", i);
+ goto cleanup;
+ }
+ }
+
+ VIR_SHRINK_N(t, nt, 5);
+
+ for (i = 0; i < nt; i++) {
+ if (t[i].a != 10 ||
+ t[i].b != 20) {
+ fprintf(stderr, "Reallocated ram block %zu lost data\n", i);
+ goto cleanup;
+ }
+ }
+
+ VIR_SHRINK_N(t, nt, 5);
+
+ for (i = 0; i < nt; i++) {
+ if (t[i].a != 10 ||
+ t[i].b != 20) {
+ fprintf(stderr, "Reallocated ram block %zu lost data\n", i);
+ goto cleanup;
+ }
+ }
+
+ VIR_FREE(t);
+
+ if (t != NULL) {
+ fprintf(stderr, "Pointer is still set after free\n");
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(t);
+ return ret;
+}
+
+
+static int
+testResizeArray(const void *opaque ATTRIBUTE_UNUSED)
+{
+ testDummyStruct *t;
+ size_t nt = 10, at, i;
+ int ret = -1;
+
+ if (VIR_ALLOC_N(t, nt) < 0)
+ return -1;
+
+ at = nt;
+
+ if (t == NULL) {
+ fprintf(stderr, "Allocation succeeded by pointer is NULL\n");
+ goto cleanup;
+ }
+
+ for (i = 0; i < nt; i++) {
+ t[i].a = 10;
+ t[i].b = 20;
+ }
+
+ if (VIR_RESIZE_N(t, at, nt, 8) < 0)
+ goto cleanup;
+
+ if (at != 18) {
+ fprintf(stderr, "Expected allocation of 16 not %zu\n", at);
+ goto cleanup;
+ }
+
+ for (i = 0; i < at; i++) {
+ if (i >= nt) {
+ if (t[i].a != 0 ||
+ t[i].b != 0) {
+ fprintf(stderr, "New ram block %zu was not zerod\n", i);
+ goto cleanup;
+ }
+ } else {
+ if (t[i].a != 10 ||
+ t[i].b != 20) {
+ fprintf(stderr, "Reallocated ram block %zu lost data\n", i);
+ goto cleanup;
+ }
+ }
+ }
+
+ VIR_FREE(t);
+
+ if (t != NULL) {
+ fprintf(stderr, "Pointer is still set after free\n");
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(t);
+ return ret;
+}
+
+
+static int
+testInsertArray(const void *opaque ATTRIBUTE_UNUSED)
+{
+ testDummyStruct **t;
+ size_t nt = 10, i;
+ int ret = -1;
+ testDummyStruct *n = (void *)0xff;
+
+ if (VIR_ALLOC_N(t, nt) < 0)
+ return -1;
+
+ if (t == NULL) {
+ fprintf(stderr, "Allocation succeeded by pointer is NULL\n");
+ goto cleanup;
+ }
+
+ for (i = 0; i < nt; i++)
+ t[i] = (void*)0x50;
+
+ if (VIR_INSERT_ELEMENT(t, 3, nt, n) < 0) {
+ if (nt != 10) {
+ fprintf(stderr, "Expecting array size 10 after OOM not %zu\n", nt);
+ goto cleanup;
+ }
+ goto cleanup;
+ }
+
+ if (nt != 11) {
+ fprintf(stderr, "Expecting array size 11 not %zu\n", nt);
+ goto cleanup;
+ }
+
+ if (n != NULL) {
+ fprintf(stderr, "Expecting element to be set to NULL\n");
+ goto cleanup;
+ }
+
+ for (i = 0; i < nt; i++) {
+ void *expect = i == 3 ? (void *)0xff : (void*)0x50;
+ if (t[i] != expect) {
+ fprintf(stderr, "Expecting %p at offset %zu not %p\n",
+ expect, i, t[i]);
+ goto cleanup;
+ }
+ }
+
+ VIR_FREE(t);
+
+ if (t != NULL) {
+ fprintf(stderr, "Pointer is still set after free\n");
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(t);
+ return ret;
+}
+
+
+static int
+mymain(void)
+{
+ int ret = 0;
+
+ if (virtTestRun("alloc scalar", testAllocScalar, NULL) < 0)
+ ret = -1;
+ if (virtTestRun("alloc array", testAllocArray, NULL) < 0)
+ ret = -1;
+ if (virtTestRun("realloc array", testReallocArray, NULL) < 0)
+ ret = -1;
+ if (virtTestRun("expand array", testExpandArray, NULL) < 0)
+ ret = -1;
+ if (virtTestRun("resize array", testResizeArray, NULL) < 0)
+ ret = -1;
+ if (virtTestRun("insert array", testInsertArray, NULL) < 0)
+ ret = -1;
+
+ return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
--
1.9.0
10 years, 7 months
[libvirt] [PATCH 0/4] Add support for addressing backing stores by index
by Jiri Denemark
Jiri Denemark (4):
qemuDomainBlockCommit: Don't track top_canon path separately
qemuDomainBlockCommit: Track virStorageSourcePtr for base
virStorageFileChainLookup: Return virStorageSourcePtr
Add support for addressing backing stores by index
src/libvirt.c | 13 ++++++-
src/libvirt_private.syms | 1 +
src/qemu/qemu_driver.c | 57 +++++++++++++++-------------
src/util/virstoragefile.c | 97 +++++++++++++++++++++++++++++++++++++----------
src/util/virstoragefile.h | 14 +++++--
tests/virstoragetest.c | 86 ++++++++++++++++++++++++++++++-----------
6 files changed, 193 insertions(+), 75 deletions(-)
--
1.9.2
10 years, 7 months