[libvirt] [PATCH v2] storage: Refresh storage pool after upload
by John Ferlan
https://bugzilla.redhat.com/show_bug.cgi?id=1072653
Upon successful upload of a volume, the target volume and storage pool
were not updated to reflect any changes as a result of the upload. Make
use of the existing stream close callback mechanism to force a backend
pool refresh to occur in a separate thread once the stream closes. The
separate thread should avoid potential deadlocks if the refresh needed
to wait on some event from the event loop which is used to perform
the stream callback.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
Update since v1 - as discussed in original posting, use virThreadCreate to
generate a thread to handle the refresh callback:
http://www.redhat.com/archives/libvir-list/2014-July/msg01395.html
Avoid the Free callback function and have the thread do the memory free
as long as thread creation was successful. Thus a couple of changes to
function names were appropriate.
Understood that this can wait for 1.2.8 - figured to get it ready to go
NOTE: Still used pool refresh, since I found that without this patch
applied a pool-dumpxml displayed the same allocation/available before
and after the upload, so that data is not refreshed for each call as
was my concern over using refreshVol vs. refreshPool
# virsh pool-dumpxml default
...
<allocation unit='bytes'>33852141568</allocation>
<available unit='bytes'>110510419968</available>
...
# virsh vol-upload test-qcow2-4g.img test.img default
# virsh pool-dumpxml default
...
<allocation unit='bytes'>33852141568</allocation>
<available unit='bytes'>110510419968</available>
...
#
src/libvirt.c | 8 ++++
src/libvirt_private.syms | 1 +
src/storage/storage_driver.c | 103 +++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 3 ++
4 files changed, 115 insertions(+)
diff --git a/src/libvirt.c b/src/libvirt.c
index 143d319..992e4f2 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -13960,6 +13960,14 @@ virStorageVolDownload(virStorageVolPtr vol,
* detect any errors. The results will be unpredictable if
* another active stream is writing to the storage volume.
*
+ * When the data stream is closed whether the upload is successful
+ * or not the target storage pool will be refreshed to reflect pool
+ * and volume changes as a result of the upload. Depending on
+ * the target volume storage backend and the source stream type
+ * for a successful upload, the target volume may take on the
+ * characteristics from the source stream such as format type,
+ * capacity, and allocation.
+ *
* Returns 0, or -1 upon error.
*/
int
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e792a44..08111d4 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -825,6 +825,7 @@ virFDStreamCreateFile;
virFDStreamOpen;
virFDStreamOpenFile;
virFDStreamOpenPTY;
+virFDStreamSetInternalCloseCb;
# libvirt_internal.h
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index efbe5ff..b023281 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -59,6 +59,12 @@ static virStorageDriverStatePtr driverState;
static int storageStateCleanup(void);
+typedef struct _virStorageVolStreamInfo virStorageVolStreamInfo;
+typedef virStorageVolStreamInfo *virStorageVolStreamInfoPtr;
+struct _virStorageVolStreamInfo {
+ char *pool_name;
+};
+
static void storageDriverLock(virStorageDriverStatePtr driver)
{
virMutexLock(&driver->lock);
@@ -1956,6 +1962,78 @@ storageVolDownload(virStorageVolPtr obj,
}
+/**
+ * Frees opaque data.
+ *
+ * @opaque Data to be freed.
+ */
+static void
+virStorageVolPoolRefreshDataFree(void *opaque)
+{
+ virStorageVolStreamInfoPtr cbdata = opaque;
+
+ VIR_FREE(cbdata->pool_name);
+ VIR_FREE(cbdata);
+}
+
+/**
+ * Thread to handle the pool refresh
+ *
+ * @st Pointer to stream being closed.
+ * @opaque Domain's device information structure.
+ */
+static void
+virStorageVolPoolRefreshThread(void *opaque)
+{
+
+ virStorageVolStreamInfoPtr cbdata = opaque;
+ virStoragePoolObjPtr pool = NULL;
+ virStorageBackendPtr backend;
+
+ storageDriverLock(driverState);
+ if (!(pool = virStoragePoolObjFindByName(&driverState->pools,
+ cbdata->pool_name)))
+ goto cleanup;
+
+ if (!(backend = virStorageBackendForType(pool->def->type)))
+ goto cleanup;
+
+ virStoragePoolObjClearVols(pool);
+ if (backend->refreshPool(NULL, pool) < 0)
+ VIR_DEBUG("Failed to refresh storage pool");
+
+ cleanup:
+ if (pool)
+ virStoragePoolObjUnlock(pool);
+ storageDriverUnlock(driverState);
+ virStorageVolPoolRefreshDataFree(cbdata);
+}
+
+/**
+ * Callback being called if a FDstream is closed. Will spin off a thread
+ * to perform a pool refresh.
+ *
+ * @st Pointer to stream being closed.
+ * @opaque Buffer to hold the pool name to be rereshed
+ */
+static void
+virStorageVolFDStreamCloseCb(virStreamPtr st ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ virThread thread;
+
+ if (virThreadCreate(&thread, false, virStorageVolPoolRefreshThread,
+ opaque) < 0) {
+ /* Not much else can be done */
+ VIR_ERROR(_("Failed to create thread to handle pool refresh"));
+ goto error;
+ }
+ return; /* Thread will free opaque data */
+
+ error:
+ virStorageVolPoolRefreshDataFree(opaque);
+}
+
static int
storageVolUpload(virStorageVolPtr obj,
virStreamPtr stream,
@@ -1966,6 +2044,7 @@ storageVolUpload(virStorageVolPtr obj,
virStorageBackendPtr backend;
virStoragePoolObjPtr pool = NULL;
virStorageVolDefPtr vol = NULL;
+ virStorageVolStreamInfoPtr cbdata = NULL;
int ret = -1;
virCheckFlags(0, -1);
@@ -1996,11 +2075,35 @@ storageVolUpload(virStorageVolPtr obj,
goto cleanup;
}
+ /* If we have a refreshPool, use the callback routine in order to
+ * refresh the pool after the volume upload stream closes. This way
+ * we make sure the volume and pool data are refreshed without user
+ * interaction and we can just lookup the backend in the callback
+ * routine in order to call the refresh API.
+ */
+ if (backend->refreshPool) {
+ if (VIR_ALLOC(cbdata) < 0 ||
+ VIR_STRDUP(cbdata->pool_name, pool->def->name) < 0)
+ goto cleanup;
+ }
+
ret = backend->uploadVol(obj->conn, pool, vol, stream,
offset, length, flags);
+ /* Add cleanup callback - call after uploadVol since the stream
+ * is then fully set up
+ */
+ if (cbdata) {
+ virFDStreamSetInternalCloseCb(stream,
+ virStorageVolFDStreamCloseCb,
+ cbdata, NULL);
+ cbdata = NULL;
+ }
+
cleanup:
virStoragePoolObjUnlock(pool);
+ if (cbdata)
+ virStorageVolPoolRefreshDataFree(cbdata);
return ret;
}
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 849ae31..e377df9 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2981,6 +2981,9 @@ of the amount of data to be uploaded. A negative value is interpreted
as an unsigned long long value to essentially include everything from
the offset to the end of the volume.
An error will occur if the I<local-file> is greater than the specified length.
+See the description for the libvirt virStorageVolUpload API for details
+regarding possible target volume and pool changes as a result of the
+pool refresh when the upload is attempted.
=item B<vol-download> [I<--pool> I<pool-or-uuid>] [I<--offset> I<bytes>]
[I<--length> I<bytes>] I<vol-name-or-key-or-path> I<local-file>
--
1.9.3
10 years, 3 months
[libvirt] [PATCH 0/9] LXC network configuration support
by Cédric Bosdonnat
Hi all,
This patch series aims at filling one of the remaining gaps between lxc and our
lxc driver. It opens up the possibilities to setup IP addresses on network devices,
adds the possibility to add them default gateways, and uses them all in the libvirt
driver. The LXC conf2xml conversion has also been updated to help migrating the
remaining untouched lxc.network.ipv[46]* properties.
The first patch in the series has almost nothing to do with the rest: it just adds
some forgotten VIR_FREE from one of my previous patch.
--
Cedric
Cédric Bosdonnat (9):
Domain conf: allow more than one IP address for net devices
LXC: set IP addresses to veth devices in the container
lxc conf2xml: convert IP addresses
Allow network capabilities hostdev to configure IP addresses
lxc conf2xml: convert ip addresses for hostdev NICs
Domain network devices can now have a <gateway> element
lxc conf2xml: convert lxc.network.ipv[46].gateway
LXC: use the new net devices gateway definition
LXC: honour network devices link state
docs/formatdomain.html.in | 39 ++++
docs/schemas/domaincommon.rng | 55 +++++-
src/conf/domain_conf.c | 211 +++++++++++++++++++--
src/conf/domain_conf.h | 22 ++-
src/libvirt_private.syms | 2 +
src/lxc/lxc_container.c | 66 ++++++-
src/lxc/lxc_native.c | 173 ++++++++++++-----
src/openvz/openvz_conf.c | 2 +-
src/openvz/openvz_driver.c | 6 +-
src/qemu/qemu_driver.c | 25 ++-
src/qemu/qemu_hotplug.c | 6 +-
src/uml/uml_conf.c | 2 +-
src/vbox/vbox_tmpl.c | 3 +-
src/xenxs/xen_sxpr.c | 12 +-
src/xenxs/xen_xm.c | 12 +-
.../lxcconf2xmldata/lxcconf2xml-physnetwork.config | 4 +
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml | 3 +
tests/lxcconf2xmldata/lxcconf2xml-simple.config | 4 +
tests/lxcconf2xmldata/lxcconf2xml-simple.xml | 3 +
tests/lxcxml2xmldata/lxc-hostdev.xml | 3 +
tests/lxcxml2xmldata/lxc-idmap.xml | 3 +
21 files changed, 548 insertions(+), 108 deletions(-)
--
1.8.4.5
10 years, 3 months
[libvirt] CPU model API (v3)
by Zeeshan Ali (Khattak)
v3: Two classes for CPU model:
* CapabilitiesCpuModel
* DomainCpuModel that derives from CapabilitiesCpuModel.
10 years, 3 months
[libvirt] [PATCH] blockcopy: check dst = identical device
by Chunyan Liu
Check whether dst is the same device as source, if yes, report
error and exit.
Currently if dst is the same device as source, blockcopy is still
going and qemu 'drive-mirror' is executed. Considering that:
a). blockcopy to the same device is meaningless. b.) result is
unexpected. (tested with block device whose source path is /dev/sdaX,
after blockcopy, shutdown VM and then create VM from xml again, the
VM cannot be started.) This case should not be allowed.
Signed-off-by: Chunyan Liu <cyliu(a)suse.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 704ba39..87a3790 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15309,6 +15309,13 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
}
/* Prepare the destination file. */
+ if (STREQ(disk->src->path, dest)) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("destination '%s' is the same as disk '%s' source"),
+ dest, path);
+ goto endjob;
+ }
+
if (stat(dest, &st) < 0) {
if (errno != ENOENT) {
virReportSystemError(errno, _("unable to stat for disk %s: %s"),
--
1.8.4.5
10 years, 3 months
[libvirt] How to Disbale SPICE recording; microphone input to Guests
by bancfc@openmailbox.org
Hi. I just noticed that Spice audio recording is on by default. It
passes microphone input to guests. Is there a way to disable this
behvior through libvirt xml?
On another note I think the privacy implications are alarming. Could you
please change this to be off/safe by default.
10 years, 3 months
[libvirt] [PATCH 0/2] Fix domiftune bandwidth bounds checking
by Ján Tomko
For https://bugzilla.redhat.com/show_bug.cgi?id=1043735
Ján Tomko (2):
virsh: check if domiftune parameters fit into UINT
Don't overwrite errors from virNetDevBandwidthSet
src/lxc/lxc_process.c | 6 +-----
src/network/bridge_driver.c | 6 +-----
src/qemu/qemu_command.c | 6 +-----
src/qemu/qemu_driver.c | 6 +-----
src/qemu/qemu_hotplug.c | 6 +-----
src/util/virnetdevmacvlan.c | 3 ---
tools/virsh-domain.c | 14 ++++++++++++++
7 files changed, 19 insertions(+), 28 deletions(-)
--
1.8.5.5
10 years, 3 months
[libvirt] missing libvirt-sock after compile and install libvirt 1.2.6
by Yuanzhen Gu
Hi folks,
I compiled and installed libvirt latest version 1.2.6, based on this
tutorial,
http://blog.scottlowe.org/2012/11/05/compiling-libvirt-1-0-0-on-ubuntu-12...
I have compiled qemu and installed too, and make a symbolic link to
/usr/bin/qemu-system-x86_64
but my question is even I launch a vm in qemu, $virsh list showed nothing,
further more,
1) if I use virtual machine manager, it get connection failiure, due to
socket to '/var/run/libvirt/libvirt-sock'; No such file of dirctory.
2). there is missing libvirt-bin under /etc/init.d/, after compile and
installed libvirt 1.2.6
3). I tried to start libvirtd daemon, sudo /usr/sbin/libvirtd/start
shows "/usr/sbin/libvirtd: unexpected, non-option, command line
arguments"
4). I've checked /var/log/libvirt/libvirtd.log
which shows cannot find suitable emulator for x86_64
I've stuck here for whole afternoon yesterday, any help or suggestion is
highly appreciated, thanks a lot in advance !
Best,
Yuanzhen
10 years, 3 months
[libvirt] [PATCH] docs: bhyve: document recent changes
by Roman Bogorodskiy
- mention that one disk and one network limitation
is no longer actual for 1.2.6 and newer
- add 'cdrom' device to the sample domain XML
---
docs/drvbhyve.html.in | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/docs/drvbhyve.html.in b/docs/drvbhyve.html.in
index e75eb83..9a97c57 100644
--- a/docs/drvbhyve.html.in
+++ b/docs/drvbhyve.html.in
@@ -42,9 +42,10 @@ in this sample domain XML.
</p>
<p>
-A limitation that is not obvious from this sample domain XML is that currently only a
-single network and a single disk device are supported for each domain (as PCI slot allocation code
-in libvirt bhyve driver is yet to be implemented).
+Note: an older versions of the libvirt bhyve driver had a limitation that only a
+single network and a single disk device were supported for each domain. However,
+<span class="since">since 1.2.6</span> the libvirt bhyve driver supports
+up to 31 PCI devices.
</p>
<pre>
@@ -71,6 +72,11 @@ in libvirt bhyve driver is yet to be implemented).
<source file='/path/to/bhyve_freebsd.img'/>
<target dev='hda' bus='sata'/>
</disk>
+ <disk type='file' device='cdrom'>
+ <driver name='file' type='raw'/>
+ <source file='/path/to/cdrom.iso'/>
+ <target dev='hdc' bus='sata'/>
+ </disk>
<interface type='bridge'>
<model type='virtio'/>
<source bridge="virbr0"/>
--
1.9.0
10 years, 3 months
[libvirt] [PATCH v6 0/2] turn on active commit
by Eric Blake
v5 was here, and got tentative ACKs:
https://www.redhat.com/archives/libvir-list/2014-July/msg01414.html
the only change is some reordering of logic in patch 2/2 (the former
4/4) to make sure that even for a super-fast commit where the event
d occurs before the API call regains the lock that the event is correct.
I'm still unsure whether to count this as a bug fix to a partial
new feature and include it in 1.2.7, or defer it to 1.2.8. If we
want it in this release, then getting it in before rc2 would be
the nicest.
Also at:
http://repo.or.cz/w/libvirt/ericb.git/shortlog/refs/heads/gluster
or git checkout git://repo.or.cz/libvirt/ericb.git gluster
Eric Blake (2):
blockcommit: track job type in xml
blockcommit: turn on active commit
docs/formatdomain.html.in | 15 ++++---
docs/schemas/domaincommon.rng | 13 ++++++
src/conf/domain_conf.c | 33 ++++++++++++++-
src/conf/domain_conf.h | 1 +
src/qemu/qemu_driver.c | 48 +++++++++++++++++++---
src/qemu/qemu_process.c | 39 +++++++++++++++++-
.../qemuxml2argv-disk-active-commit.xml | 37 +++++++++++++++++
.../qemuxml2argvdata/qemuxml2argv-disk-mirror.xml | 6 +--
.../qemuxml2xmlout-disk-mirror-old.xml | 4 +-
tests/qemuxml2xmltest.c | 1 +
10 files changed, 179 insertions(+), 18 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-active-commit.xml
--
1.9.3
10 years, 3 months