[libvirt] [PATCH] command: Fix ATTRIBUTE_UNUSED on virSetCapabilities
by Michal Privoznik
If we are building not on a WIN32 architecture and without HAVE_CAPNG
virSetCapabilities has unused argument and virClearCapabilities
is unused as well.
---
Pushed under build breaker rule.
src/util/command.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/util/command.c b/src/util/command.c
index e3a8371..6f51fbb 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -169,8 +169,9 @@ virCommandFDSet(int fd,
#ifndef WIN32
-# if HAVE_CAPNG
static int virClearCapabilities(void) ATTRIBUTE_UNUSED;
+
+# if HAVE_CAPNG
static int virClearCapabilities(void)
{
int ret;
@@ -220,7 +221,8 @@ static int virClearCapabilities(void)
return 0;
}
-static int virSetCapabilities(unsigned long long capabilities)
+static int
+virSetCapabilities(unsigned long long capabilities ATTRIBUTE_UNUSED)
{
return 0;
}
--
1.7.3.4
12 years, 9 months
[libvirt] [PATCH] qemu: Clenup qemuDomainSetInterfaceParameters
by Michal Privoznik
which contained some useless lines, copied code, NULL
dereference.
---
src/libvirt.c | 4 ++--
src/qemu/qemu_driver.c | 44 ++++++++++++++++----------------------------
2 files changed, 18 insertions(+), 30 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c
index e702a34..433ae0a 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -7226,8 +7226,8 @@ error:
*
* Change a subset or all parameters of interface; currently this
* includes bandwidth parameters. The value of @flags should be
- * either VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of values from
- * VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CURRENT, although
+ * either VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of values
+ * VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CONFIG, although
* hypervisors vary in which flags are supported.
*
* This function may require privileged access to the hypervisor.
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1b147a9..b1d0b7f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7779,20 +7779,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
}
}
- if (VIR_ALLOC(bandwidth) < 0) {
+ if ((VIR_ALLOC(bandwidth) < 0) ||
+ (VIR_ALLOC(bandwidth->in) < 0) ||
+ (VIR_ALLOC(bandwidth->out) < 0)) {
virReportOOMError();
goto cleanup;
}
- if (VIR_ALLOC(bandwidth->in) < 0) {
- virReportOOMError();
- goto cleanup;
- }
- memset(bandwidth->in, 0, sizeof(*bandwidth->in));
- if (VIR_ALLOC(bandwidth->out) < 0) {
- virReportOOMError();
- goto cleanup;
- }
- memset(bandwidth->out, 0, sizeof(*bandwidth->out));
for (i = 0; i < nparams; i++) {
virTypedParameterPtr param = ¶ms[i];
@@ -7817,11 +7809,9 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
* inbound/outbound to not be set. */
if (!bandwidth->in->average) {
VIR_FREE(bandwidth->in);
- bandwidth->in = NULL;
}
if (!bandwidth->out->average) {
VIR_FREE(bandwidth->out);
- bandwidth->out = NULL;
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
@@ -7833,29 +7823,27 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
/* virNetDevBandwidthSet() will clear any previous value of
* bandwidth parameters, so merge with old bandwidth parameters
* here to prevent them from being lost. */
- if (bandwidth->in || net->bandwidth->in) {
+ if (bandwidth->in ||
+ (net->bandwidth && net->bandwidth->in)) {
if (VIR_ALLOC(newBandwidth->in) < 0) {
virReportOOMError();
goto cleanup;
}
- if (bandwidth->in)
- memcpy(newBandwidth->in, bandwidth->in,
- sizeof(*newBandwidth->in));
- else if (net->bandwidth->in)
- memcpy(newBandwidth->in, net->bandwidth->in,
- sizeof(*newBandwidth->in));
- }
- if (bandwidth->out || net->bandwidth->out) {
+
+ memcpy(newBandwidth->in,
+ bandwidth->in ? bandwidth->in : net->bandwidth->in,
+ sizeof(*newBandwidth->in));
+ }
+ if (bandwidth->out ||
+ (net->bandwidth && net->bandwidth->out)) {
if (VIR_ALLOC(newBandwidth->out) < 0) {
virReportOOMError();
goto cleanup;
}
- if (bandwidth->out)
- memcpy(newBandwidth->out, bandwidth->out,
- sizeof(*newBandwidth->out));
- else if (net->bandwidth->out)
- memcpy(newBandwidth->out, net->bandwidth->out,
- sizeof(*newBandwidth->out));
+
+ memcpy(newBandwidth->out,
+ bandwidth->out ? bandwidth->out : net->bandwidth->out,
+ sizeof(*newBandwidth->out));
}
if (virNetDevBandwidthSet(net->ifname, newBandwidth) < 0) {
--
1.7.3.4
12 years, 9 months
[libvirt] [PATCH] qemu: Don't jump to endjob if no job was even started
by Michal Privoznik
In qemuDomainShutdownFlags if we try to use guest agent,
which has error or is not configured, we jump go endjob
label even if we haven't started any job yet. This may
lead to the daemon crash:
1) virsh shutdown --mode agent on a domain without agent configured
2) wait until domain quits
3) virsh edit
---
src/qemu/qemu_driver.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1b147a9..7945c5d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1546,12 +1546,12 @@ static int qemuDomainShutdownFlags(virDomainPtr dom, unsigned int flags) {
if (priv->agentError) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("QEMU guest agent is not available due to an error"));
- goto endjob;
+ goto cleanup;
}
if (!priv->agent) {
qemuReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("QEMU guest agent is not configured"));
- goto endjob;
+ goto cleanup;
}
}
--
1.7.3.4
12 years, 9 months
[libvirt] [test-API][PATCH 1/2] Add 2 new functions in storageAPI
by Wayne Sun
* download(self, poolname, volname, stream, offset, length, flags = 0)
* upload(self, poolname, volname, stream, offset, length, flags = 0)
---
lib/storageAPI.py | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/lib/storageAPI.py b/lib/storageAPI.py
index 6c9d286..b0733f8 100644
--- a/lib/storageAPI.py
+++ b/lib/storageAPI.py
@@ -466,3 +466,20 @@ class StorageAPI(object):
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
+ def download(self, poolname, volname, stream, offset, length, flags = 0):
+ try:
+ volobj = self.get_volume_obj(poolname, volname)
+ return volobj.download(stream, offset, length, flags)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def upload(self, poolname, volname, stream, offset, length, flags = 0):
+ try:
+ volobj = self.get_volume_obj(poolname, volname)
+ return volobj.upload(stream, offset, length, flags)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
--
1.7.1
12 years, 9 months
[libvirt] ANNOUNCE: virt-manager 0.9.1 and virtinst 0.600.1 released
by Cole Robinson
I'm happy to announce two new releases:
virt-manager 0.9.1: virt-manager is a desktop application for managing
KVM and Xen virtual machines via libvirt.
virtinst 0.600.1: virtinst is a collection of command line tools for
provisioning libvirt virtual machines, including virt-install and
virt-clone.
The releases can be downloaded from:
http://virt-manager.org/download.html
The direct download links are:
http://virt-manager.org/download/sources/virt-manager/virt-manager-0.9.1....
http://virt-manager.org/download/sources/virtinst/virtinst-0.600.1.tar.gz
The virt-manager release includes:
- Support for adding usb redirection devices (Marc-André Lureau)
- Option to switch usb controller to support usb2.0 (Marc-André Lureau)
- Option to specify machine type for non-x86 guests (Li Zhang)
- Support for filesystem device type and write policy (Deepak C Shetty)
- Many bug fixes!
The virtinst release includes:
- virt-install: --redir option for usb redirection (Marc-André Lureau)
- virt-install: Advanced --controller support for usb2 (Marc-André
Lureau)
- Many bug fixes and minor improvments.
Thanks to everyone who has contributed to this release through testing,
bug reporting, submitting patches, and otherwise sending in feedback!
Thanks,
Cole
12 years, 9 months
[libvirt] [PATCH] tests: dynamically replace dnsmasq path
by Philipp Hahn
The path to the dnsmasq binary can be configured while in the test data
the path is hard-coded to /usr/bin/. This break the test suite if a the
binary is located in a different location, like /usr/local/sbin/.
Replace the hard coded path in the test data by a token, which is
dynamically replaced in networkxml2argvtest with the configured path
after the test data has been loaded.
(Another option would have been to modify configure.ac to generate the
test data during configure, but I do not know of an easy way do trick
configure into mass-generate those test files without listing every
single one, which I consider less flexible.)
Signed-off-by: Philipp Hahn <hahn(a)univention.de>
---
tests/networkxml2argvdata/isolated-network.argv | 2 +-
.../networkxml2argvdata/nat-network-dns-hosts.argv | 2 +-
.../nat-network-dns-srv-record-minimal.argv | 2 +-
.../nat-network-dns-srv-record.argv | 2 +-
.../nat-network-dns-txt-record.argv | 2 +-
tests/networkxml2argvdata/nat-network.argv | 2 +-
tests/networkxml2argvdata/netboot-network.argv | 2 +-
.../networkxml2argvdata/netboot-proxy-network.argv | 2 +-
tests/networkxml2argvdata/routed-network.argv | 2 +-
tests/networkxml2argvtest.c | 42 ++++++++++++++++++++
10 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/tests/networkxml2argvdata/isolated-network.argv b/tests/networkxml2argvdata/isolated-network.argv
index 7ea2e94..a9beb05 100644
--- a/tests/networkxml2argvdata/isolated-network.argv
+++ b/tests/networkxml2argvdata/isolated-network.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= \
+@DNSMASQ@ --strict-order --bind-interfaces --conf-file= \
--except-interface lo --dhcp-option=3 --no-resolv \
--listen-address 192.168.152.1 \
--dhcp-range 192.168.152.2,192.168.152.254 \
diff --git a/tests/networkxml2argvdata/nat-network-dns-hosts.argv b/tests/networkxml2argvdata/nat-network-dns-hosts.argv
index 2158df8..c7e4967 100644
--- a/tests/networkxml2argvdata/nat-network-dns-hosts.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-hosts.argv
@@ -1,3 +1,3 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --domain example.com \
+@DNSMASQ@ --strict-order --bind-interfaces --domain example.com \
--conf-file= --except-interface lo --listen-address 192.168.122.1 \
--expand-hosts --addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts\
diff --git a/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv b/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv
index 021e8f0..ea1da6d 100644
--- a/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq \
+@DNSMASQ@ \
--strict-order \
--bind-interfaces \
--conf-file= \
diff --git a/tests/networkxml2argvdata/nat-network-dns-srv-record.argv b/tests/networkxml2argvdata/nat-network-dns-srv-record.argv
index 85afbba..84c2d2f 100644
--- a/tests/networkxml2argvdata/nat-network-dns-srv-record.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-srv-record.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq \
+@DNSMASQ@ \
--strict-order \
--bind-interfaces \
--conf-file= \
diff --git a/tests/networkxml2argvdata/nat-network-dns-txt-record.argv b/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
index be6ba4b..bed309f 100644
--- a/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= \
+@DNSMASQ@ --strict-order --bind-interfaces --conf-file= \
--except-interface lo --txt-record=example,example value \
--listen-address 192.168.122.1 --listen-address 192.168.123.1 \
--listen-address 2001:db8:ac10:fe01::1 \
diff --git a/tests/networkxml2argvdata/nat-network.argv b/tests/networkxml2argvdata/nat-network.argv
index d7faee2..80878a8 100644
--- a/tests/networkxml2argvdata/nat-network.argv
+++ b/tests/networkxml2argvdata/nat-network.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= \
+@DNSMASQ@ --strict-order --bind-interfaces --conf-file= \
--except-interface lo --listen-address 192.168.122.1 \
--listen-address 192.168.123.1 --listen-address 2001:db8:ac10:fe01::1 \
--listen-address 2001:db8:ac10:fd01::1 --listen-address 10.24.10.1 \
diff --git a/tests/networkxml2argvdata/netboot-network.argv b/tests/networkxml2argvdata/netboot-network.argv
index 78e873c..7ae5b75 100644
--- a/tests/networkxml2argvdata/netboot-network.argv
+++ b/tests/networkxml2argvdata/netboot-network.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --domain example.com \
+@DNSMASQ@ --strict-order --bind-interfaces --domain example.com \
--conf-file= --except-interface lo --listen-address 192.168.122.1 \
--dhcp-range 192.168.122.2,192.168.122.254 \
--dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases \
diff --git a/tests/networkxml2argvdata/netboot-proxy-network.argv b/tests/networkxml2argvdata/netboot-proxy-network.argv
index 5fe1b8e..2c5a0d5 100644
--- a/tests/networkxml2argvdata/netboot-proxy-network.argv
+++ b/tests/networkxml2argvdata/netboot-proxy-network.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --domain example.com \
+@DNSMASQ@ --strict-order --bind-interfaces --domain example.com \
--conf-file= --except-interface lo --listen-address 192.168.122.1 \
--dhcp-range 192.168.122.2,192.168.122.254 \
--dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases \
diff --git a/tests/networkxml2argvdata/routed-network.argv b/tests/networkxml2argvdata/routed-network.argv
index d059630..75303e6 100644
--- a/tests/networkxml2argvdata/routed-network.argv
+++ b/tests/networkxml2argvdata/routed-network.argv
@@ -1,2 +1,2 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= \
+@DNSMASQ@ --strict-order --bind-interfaces --conf-file= \
--except-interface lo --listen-address 192.168.122.1\
diff --git a/tests/networkxml2argvtest.c b/tests/networkxml2argvtest.c
index 2dd9b7f..ec2ef39 100644
--- a/tests/networkxml2argvtest.c
+++ b/tests/networkxml2argvtest.c
@@ -15,6 +15,45 @@
#include "memory.h"
#include "network/bridge_driver.h"
+/* Replace all occurrences of @token in @buf by @replacement and adjust size of
+ * @buf accordingly. Returns 0 on success and -1 on out-of-memory errors. */
+static int replaceTokens(char **buf, const char *token, const char *replacement) {
+ char *token_start, *token_end;
+ size_t old_len, new_len, rest_len;
+ void *tmp;
+ const size_t token_len = strlen(token);
+ const size_t replacement_len = strlen(replacement);
+ const int diff = replacement_len - token_len;
+
+ old_len = rest_len = strlen(*buf) + 1;
+ token_end = *buf;
+ for (;;) {
+ token_start = strstr(token_end, token);
+ if (token_start == NULL)
+ break;
+ rest_len -= token_start + token_len - token_end;
+ token_end = token_start + token_len;
+ new_len = old_len + diff;
+ if (diff > 0) {
+ tmp = realloc((void *)*buf, new_len);
+ if (tmp == NULL)
+ return -1;
+ *buf = tmp;
+ }
+ if (diff != 0)
+ memmove(token_end + diff, token_end, rest_len);
+ memmove(token_start, replacement, replacement_len);
+ if (diff < 0) {
+ tmp = realloc((void *)*buf, new_len);
+ if (tmp == NULL)
+ return -1;
+ *buf = tmp;
+ }
+ old_len = new_len;
+ }
+ return 0;
+}
+
static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) {
char *inXmlData = NULL;
char *outArgvData = NULL;
@@ -32,6 +71,9 @@ static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) {
if (virtTestLoadFile(outargv, &outArgvData) < 0)
goto fail;
+ if (replaceTokens(&outArgvData, "@DNSMASQ@", DNSMASQ))
+ goto fail;
+
if (!(dev = virNetworkDefParseString(inXmlData)))
goto fail;
--
1.7.1
12 years, 9 months
[libvirt] Implement virStorageVolResize() for FS backend
by Zeeshan Ali (Khattak)
From: "Zeeshan Ali (Khattak)" <zeeshanak(a)gnome.org>
Currently only VIR_STORAGE_VOL_RESIZE_DELTA flag is supported.
---
src/storage/storage_backend.h | 6 +++
src/storage/storage_backend_fs.c | 53 +++++++++++++++++++++++
src/storage/storage_driver.c | 88 ++++++++++++++++++++++++++++++++++++++
src/util/storage_file.c | 16 +++++++
src/util/storage_file.h | 2 +
5 files changed, 165 insertions(+), 0 deletions(-)
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index 75ed676..a37bf7c 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -44,6 +44,11 @@ typedef int (*virStorageBackendDeleteVol)(virConnectPtr conn, virStoragePoolObjP
typedef int (*virStorageBackendBuildVolFrom)(virConnectPtr conn, virStoragePoolObjPtr pool,
virStorageVolDefPtr origvol, virStorageVolDefPtr newvol,
unsigned int flags);
+typedef int (*virStorageBackendVolumeResize)(virConnectPtr conn,
+ virStoragePoolObjPtr pool,
+ virStorageVolDefPtr vol,
+ unsigned long long capacity,
+ unsigned int flags);
/* File creation/cloning functions used for cloning between backends */
int virStorageBackendCreateRaw(virConnectPtr conn,
@@ -78,6 +83,7 @@ struct _virStorageBackend {
virStorageBackendCreateVol createVol;
virStorageBackendRefreshVol refreshVol;
virStorageBackendDeleteVol deleteVol;
+ virStorageBackendVolumeResize resizeVol;
};
virStorageBackendPtr virStorageBackendForType(int type);
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index d8dc29c..1af12e6 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1187,6 +1187,56 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
return 0;
}
+static int
+virStorageBackendFilesystemResizeQemuImg(const char *path,
+ unsigned long long capacity)
+{
+ int ret = -1;
+ char *img_tool;
+ virCommandPtr cmd = NULL;
+
+ /* KVM is usually ahead of qemu on features, so try that first */
+ img_tool = virFindFileInPath("kvm-img");
+ if (!img_tool)
+ img_tool = virFindFileInPath("qemu-img");
+
+ if (!img_tool) {
+ virStorageReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("unable to find kvm-img or qemu-img"));
+ return -1;
+ }
+
+ cmd = virCommandNew(img_tool);
+ virCommandAddArgList(cmd, "resize", path, NULL);
+ virCommandAddArgFormat(cmd, "%llu", capacity);
+
+ ret = virCommandRun(cmd, NULL);
+
+ VIR_FREE(img_tool);
+ virCommandFree(cmd);
+
+ return ret;
+}
+
+/**
+ * Resize a volume
+ */
+static int
+virStorageBackendFileSystemVolResize(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
+ virStorageVolDefPtr vol,
+ unsigned long long capacity,
+ unsigned int flags)
+{
+ virCheckFlags(0, -1);
+
+ if (vol->target.format == VIR_STORAGE_FILE_RAW)
+ return virStorageFileResize(vol->target.path, capacity);
+ else
+ return virStorageBackendFilesystemResizeQemuImg(vol->target.path,
+ capacity);
+}
+
virStorageBackend virStorageBackendDirectory = {
.type = VIR_STORAGE_POOL_DIR,
@@ -1199,6 +1249,7 @@ virStorageBackend virStorageBackendDirectory = {
.createVol = virStorageBackendFileSystemVolCreate,
.refreshVol = virStorageBackendFileSystemVolRefresh,
.deleteVol = virStorageBackendFileSystemVolDelete,
+ .resizeVol = virStorageBackendFileSystemVolResize,
};
#if WITH_STORAGE_FS
@@ -1216,6 +1267,7 @@ virStorageBackend virStorageBackendFileSystem = {
.createVol = virStorageBackendFileSystemVolCreate,
.refreshVol = virStorageBackendFileSystemVolRefresh,
.deleteVol = virStorageBackendFileSystemVolDelete,
+ .resizeVol = virStorageBackendFileSystemVolResize,
};
virStorageBackend virStorageBackendNetFileSystem = {
.type = VIR_STORAGE_POOL_NETFS,
@@ -1232,5 +1284,6 @@ virStorageBackend virStorageBackendNetFileSystem = {
.createVol = virStorageBackendFileSystemVolCreate,
.refreshVol = virStorageBackendFileSystemVolRefresh,
.deleteVol = virStorageBackendFileSystemVolDelete,
+ .resizeVol = virStorageBackendFileSystemVolResize,
};
#endif /* WITH_STORAGE_FS */
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index a332ada..e7a8a8b 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1695,7 +1695,94 @@ out:
return ret;
}
+static int
+storageVolumeResize(virStorageVolPtr obj,
+ long long capacity,
+ unsigned int flags)
+{
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStorageBackendPtr backend;
+ virStoragePoolObjPtr pool = NULL;
+ virStorageVolDefPtr vol = NULL;
+ unsigned long long abs_capacity;
+ int ret = -1;
+
+ virCheckFlags(VIR_STORAGE_VOL_RESIZE_DELTA, -1);
+
+ storageDriverLock(driver);
+ pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
+ storageDriverUnlock(driver);
+
+ if (!pool) {
+ virStorageReportError(VIR_ERR_NO_STORAGE_POOL,
+ _("no storage pool with matching uuid"));
+ goto out;
+ }
+
+ if (!virStoragePoolObjIsActive(pool)) {
+ virStorageReportError(VIR_ERR_OPERATION_INVALID,
+ _("storage pool is not active"));
+ goto out;
+ }
+
+ if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
+ goto out;
+
+ vol = virStorageVolDefFindByName(pool, obj->name);
+
+ if (vol == NULL) {
+ virStorageReportError(VIR_ERR_NO_STORAGE_VOL,
+ _("no storage vol with matching name '%s'"),
+ obj->name);
+ goto out;
+ }
+
+ if (vol->building) {
+ virStorageReportError(VIR_ERR_OPERATION_INVALID,
+ _("volume '%s' is still being allocated."),
+ vol->name);
+ goto out;
+ }
+ if (flags & VIR_STORAGE_VOL_RESIZE_DELTA) {
+ abs_capacity = vol->capacity + capacity;
+ flags &= ~VIR_STORAGE_VOL_RESIZE_DELTA;
+ } else {
+ abs_capacity = capacity;
+ }
+
+ if (abs_capacity < vol->allocation) {
+ virStorageReportError(VIR_ERR_INVALID_ARG,
+ _("can't shrink capacity below "
+ "existing allocation"));
+ goto out;
+ }
+
+ if (abs_capacity > vol->allocation + pool->def->available) {
+ virStorageReportError(VIR_ERR_INVALID_ARG,
+ _("Not enough space left on storage pool"));
+ goto out;
+ }
+
+ if (!backend->resizeVol) {
+ virStorageReportError(VIR_ERR_NO_SUPPORT,
+ _("storage pool does not support changing of "
+ "volume capacity"));
+ goto out;
+ }
+
+ if (backend->resizeVol(obj->conn, pool, vol, abs_capacity, flags) < 0)
+ goto out;
+
+ vol->capacity = abs_capacity;
+ ret = 0;
+
+out:
+ if (pool)
+ virStoragePoolObjUnlock(pool);
+
+ return ret;
+}
/* If the volume we're wiping is already a sparse file, we simply
* truncate and extend it to its original size, filling it with
@@ -2243,6 +2330,7 @@ static virStorageDriver storageDriver = {
.volGetInfo = storageVolumeGetInfo, /* 0.4.0 */
.volGetXMLDesc = storageVolumeGetXMLDesc, /* 0.4.0 */
.volGetPath = storageVolumeGetPath, /* 0.4.0 */
+ .volResize = storageVolumeResize, /* 0.9.10 */
.poolIsActive = storagePoolIsActive, /* 0.7.3 */
.poolIsPersistent = storagePoolIsPersistent, /* 0.7.3 */
diff --git a/src/util/storage_file.c b/src/util/storage_file.c
index ba9cfc5..8260adb 100644
--- a/src/util/storage_file.c
+++ b/src/util/storage_file.c
@@ -931,6 +931,22 @@ virStorageFileFreeMetadata(virStorageFileMetadata *meta)
VIR_FREE(meta);
}
+/**
+ * virStorageFileResize:
+ *
+ * Change the capacity of the raw storage file at 'path'.
+ */
+int
+virStorageFileResize(const char *path, unsigned long long capacity)
+{
+ if (truncate(path, capacity) < 0) {
+ virReportSystemError(errno, _("Failed to truncate file '%s'"), path);
+ return -1;
+ }
+
+ return 0;
+}
+
#ifdef __linux__
# ifndef NFS_SUPER_MAGIC
diff --git a/src/util/storage_file.h b/src/util/storage_file.h
index b8920d0..96afb12 100644
--- a/src/util/storage_file.h
+++ b/src/util/storage_file.h
@@ -72,6 +72,8 @@ int virStorageFileGetMetadataFromFD(const char *path,
void virStorageFileFreeMetadata(virStorageFileMetadata *meta);
+int virStorageFileResize(const char *path, unsigned long long capacity);
+
enum {
VIR_STORAGE_FILE_SHFS_NFS = (1 << 0),
VIR_STORAGE_FILE_SHFS_GFS2 = (1 << 1),
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCHv3] network: Avoid memory leaks on networkBuildDnsmasqArgv
by ajia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
Detected by valgrind. Leaks introduced in commit 973af236.
* src/network/bridge_driver.c: fix memory leaks on failure and successful path.
* How to reproduce?
% make -C tests check TESTS=networkxml2argvtest
% cd tests && valgrind -v --leak-check=full ./networkxml2argvtest
* Actual result:
==2226== 3 bytes in 1 blocks are definitely lost in loss record 1 of 24
==2226== at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==2226== by 0x39CF0FEDE7: __vasprintf_chk (in /lib64/libc-2.12.so)
==2226== by 0x41DFF7: virVasprintf (stdio2.h:199)
==2226== by 0x41E0B7: virAsprintf (util.c:1695)
==2226== by 0x41A2D9: networkBuildDhcpDaemonCommandLine (bridge_driver.c:545)
==2226== by 0x4145C8: testCompareXMLToArgvHelper (networkxml2argvtest.c:47)
==2226== by 0x4156A1: virtTestRun (testutils.c:141)
==2226== by 0x414332: mymain (networkxml2argvtest.c:123)
==2226== by 0x414D97: virtTestMain (testutils.c:696)
==2226== by 0x39CF01ECDC: (below main) (in /lib64/libc-2.12.so)
==2226==
==2226== 3 bytes in 1 blocks are definitely lost in loss record 2 of 24
==2226== at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==2226== by 0x39CF0FEDE7: __vasprintf_chk (in /lib64/libc-2.12.so)
==2226== by 0x41DFF7: virVasprintf (stdio2.h:199)
==2226== by 0x41E0B7: virAsprintf (util.c:1695)
==2226== by 0x41A307: networkBuildDhcpDaemonCommandLine (bridge_driver.c:551)
==2226== by 0x4145C8: testCompareXMLToArgvHelper (networkxml2argvtest.c:47)
==2226== by 0x4156A1: virtTestRun (testutils.c:141)
==2226== by 0x414332: mymain (networkxml2argvtest.c:123)
==2226== by 0x414D97: virtTestMain (testutils.c:696)
==2226== by 0x39CF01ECDC: (below main) (in /lib64/libc-2.12.so)
==2226==
==2226== 5 bytes in 1 blocks are definitely lost in loss record 4 of 24
==2226== at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==2226== by 0x39CF0FEDE7: __vasprintf_chk (in /lib64/libc-2.12.so)
==2226== by 0x41DFF7: virVasprintf (stdio2.h:199)
==2226== by 0x41E0B7: virAsprintf (util.c:1695)
==2226== by 0x41A2AB: networkBuildDhcpDaemonCommandLine (bridge_driver.c:539)
==2226== by 0x4145C8: testCompareXMLToArgvHelper (networkxml2argvtest.c:47)
==2226== by 0x4156A1: virtTestRun (testutils.c:141)
==2226== by 0x414332: mymain (networkxml2argvtest.c:123)
==2226== by 0x414D97: virtTestMain (testutils.c:696)
==2226== by 0x39CF01ECDC: (below main) (in /lib64/libc-2.12.so)
==2226==
==2226== LEAK SUMMARY:
==2226== definitely lost: 11 bytes in 3 blocks
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
src/network/bridge_driver.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 5d0d528..c9a8ccf 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -458,7 +458,10 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
{
int r, ret = -1;
int nbleases = 0;
- int ii;
+ int ii, i, j;
+ char *recordPort = NULL;
+ char *recordPriority = NULL;
+ char *recordWeight = NULL;
virNetworkIpDefPtr tmpipdef;
/*
@@ -513,7 +516,6 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
if (network->def->dns != NULL) {
virNetworkDNSDefPtr dns = network->def->dns;
- int i;
for (i = 0; i < dns->ntxtrecords; i++) {
char *record = NULL;
@@ -530,10 +532,6 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
for (i = 0; i < dns->nsrvrecords; i++) {
char *record = NULL;
- char *recordPort = NULL;
- char *recordPriority = NULL;
- char *recordWeight = NULL;
-
if (dns->srvrecords[i].service && dns->srvrecords[i].protocol) {
if (dns->srvrecords[i].port) {
if (virAsprintf(&recordPort, "%d", dns->srvrecords[i].port) < 0) {
@@ -671,6 +669,11 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
ret = 0;
cleanup:
+ for (j = 0; j < i; j++) {
+ VIR_FREE(recordPort);
+ VIR_FREE(recordWeight);
+ VIR_FREE(recordPriority);
+ }
return ret;
}
--
1.7.1
12 years, 9 months
[libvirt] [PATCHv3] simplify block of codes
by Alex.Jia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
Using new function 'virTypedParameterArrayClear' to simplify block of codes.
* daemon/remote.c, src/remote/remote_driver.c: simplify codes.
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
daemon/remote.c | 6 +-----
src/remote/remote_driver.c | 19 +++++--------------
2 files changed, 6 insertions(+), 19 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index cb8423a..e7d9b2f 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -848,11 +848,7 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val,
cleanup:
if (rv < 0) {
- int j;
- for (j = 0; j < i; ++j) {
- if (params[j].type == VIR_TYPED_PARAM_STRING)
- VIR_FREE(params[j].value.s);
- }
+ virTypedParameterArrayClear(params, i);
VIR_FREE(params);
}
return params;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 61b96e9..031becd 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -46,6 +46,7 @@
#include "virfile.h"
#include "command.h"
#include "intprops.h"
+#include "virtypedparam.h"
#define VIR_FROM_THIS VIR_FROM_REMOTE
@@ -1417,12 +1418,8 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val,
rv = 0;
cleanup:
- if (rv < 0) {
- int j;
- for (j = 0; j < i; j++)
- if (params[j].type == VIR_TYPED_PARAM_STRING)
- VIR_FREE(params[j].value.s);
- }
+ if (rv < 0)
+ virTypedParameterArrayClear(params, i);
return rv;
}
@@ -2384,15 +2381,9 @@ static int remoteDomainGetCPUStats(virDomainPtr domain,
rv = ret.nparams;
cleanup:
- if (rv < 0) {
- int max = nparams * ncpus;
- int i;
+ if (rv < 0)
+ virTypedParameterArrayClear(params, nparams * ncpus);
- for (i = 0; i < max; i++) {
- if (params[i].type == VIR_TYPED_PARAM_STRING)
- VIR_FREE(params[i].value.s);
- }
- }
xdr_free ((xdrproc_t) xdr_remote_domain_get_cpu_stats_ret,
(char *) &ret);
done:
--
1.7.1
12 years, 9 months