[libvirt] [PATCH v5 00/16] Move qemu command line controller checks to qemuDomainDeviceDefValidateController* checks
by John Ferlan
v4: https://www.redhat.com/archives/libvir-list/2017-December/msg00401.html
Changes since v4:
Insert patch 1 to split the qemuDomainSetSCSIControllerModel as has been
discussed during review.
Adjustments to the SCSI patches as a result.
Added patch 16 from Mark Hartmayer
Andrea Bolognani (1):
qemu: Add missing checks for pcie-root-port options
John Ferlan (14):
qemu: Split qemuDomainSetSCSIControllerModel
qemu: Introduce qemuDomainDeviceDefValidateControllerAttributes
qemu: Move and rename qemuBuildCheckSCSIControllerModel
qemu: Move model set for qemuBuildControllerDevStr
qemu: Adjust SCSI controller switch in qemuBuildControllerDevStr
qemu: Add check for iothread attribute in validate controller
qemu: Introduce qemuDomainDeviceDefValidateControllerSCSI
qemu: Introduce qemuDomainDeviceDefValidateControllerPCI
qemu: Use virDomainPCIControllerOpts in qemuBuildControllerDevStr
qemu: Move PCI command modelName check to controller def validate
qemu: Move PCI command modelName TypeToString to controller def
validate
qemu: Move PCI more command checks to controller def validate
qemu: Complete PCI command checks to controller def validate
qemu: Introduce qemuDomainDeviceDefValidateControllerSATA
Marc Hartmayer (1):
qemu: Use switch statement for address types in
qemuBuildControllerDevStr
src/qemu/qemu_alias.c | 4 +-
src/qemu/qemu_command.c | 452 +++++----------------------------------
src/qemu/qemu_domain.c | 474 ++++++++++++++++++++++++++++++++++++++++-
src/qemu/qemu_domain_address.c | 74 ++-----
src/qemu/qemu_domain_address.h | 6 +-
tests/qemumemlocktest.c | 14 ++
tests/qemuxml2xmltest.c | 5 +-
7 files changed, 568 insertions(+), 461 deletions(-)
--
2.13.6
6 years, 10 months
[libvirt] [PATCH] conf: Use correct attribute name in error message
by Andrea Bolognani
The <capabilities> feature has an attribute named 'policy', but the
error message mentioned the non-existing 'state' attribute instead.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
Pushed as trivial.
src/conf/domain_conf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1581f61a4..9c9e3334f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19162,7 +19162,7 @@ virDomainDefParseXML(xmlDocPtr xml,
if ((tmp = virXMLPropString(nodes[i], "policy"))) {
if ((def->features[val] = virDomainCapabilitiesPolicyTypeFromString(tmp)) == -1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown state attribute '%s' of feature '%s'"),
+ _("unknown policy attribute '%s' of feature '%s'"),
tmp, virDomainFeatureTypeToString(val));
goto error;
}
--
2.14.3
6 years, 10 months
[libvirt] [PATCH] storage: util: Properly ignore errors when backing volume is inaccessible
by Peter Krempa
Commit 000e9504559 tried to fix improper bracketing when refreshing disk
volume stats for a backing volume. Unfortunately the condition is still
wrong as in cases as the backing store being inaccessible
storageBackendUpdateVolTargetInfo returns -2 if instructed to ignore
errors. The condition does not take this into account.
Dumping XML of a volume which has inacessible backing store would then
result into:
# virsh vol-dumpxml http.img --pool default
error: An error occurred, but the cause is unknown
Properly ignore -2 for backing volumes.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1540022
---
src/storage/storage_util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 9e1b63a436..61a87b37b6 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1918,7 +1918,7 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
withBlockVolFormat,
VIR_STORAGE_VOL_OPEN_DEFAULT |
VIR_STORAGE_VOL_OPEN_NOERROR,
- readflags)) < 0)
+ readflags)) == -1)
return ret;
return 0;
--
2.15.0
6 years, 10 months
[libvirt] [PATCH] qemu: Refresh caps cache after booting a different kernel
by Jiri Denemark
Whenever a different kernel is booted, some capabilities related to KVM
(such as CPUID bits) may change. We need to refresh the cache to see the
changes.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
The capabilities may also change if a parameter passed to a kvm module
changes (kvm_intel.nested is a good example) so this is not a complete
solution, but we're hopefully getting closer to it :-)
src/qemu/qemu_capabilities.c | 57 +++++++++++++++++++++++++++++++++++++-------
src/qemu/qemu_capspriv.h | 1 +
tests/qemucapsprobe.c | 2 +-
3 files changed, 50 insertions(+), 10 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index ab0ea8ec0d..2c573827f1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -52,6 +52,7 @@
#include <unistd.h>
#include <sys/wait.h>
#include <stdarg.h>
+#include <sys/utsname.h>
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -510,6 +511,7 @@ struct _virQEMUCaps {
unsigned int libvirtVersion;
unsigned int microcodeVersion;
char *package;
+ char *kernelVersion;
virArch arch;
@@ -2303,6 +2305,9 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
if (VIR_STRDUP(ret->package, qemuCaps->package) < 0)
goto error;
+ if (VIR_STRDUP(ret->kernelVersion, qemuCaps->kernelVersion) < 0)
+ goto error;
+
ret->arch = qemuCaps->arch;
if (qemuCaps->kvmCPUModels) {
@@ -2363,6 +2368,7 @@ void virQEMUCapsDispose(void *obj)
virBitmapFree(qemuCaps->flags);
VIR_FREE(qemuCaps->package);
+ VIR_FREE(qemuCaps->kernelVersion);
VIR_FREE(qemuCaps->binary);
VIR_FREE(qemuCaps->gicCapabilities);
@@ -3834,6 +3840,7 @@ struct _virQEMUCapsCachePriv {
gid_t runGid;
virArch hostArch;
unsigned int microcodeVersion;
+ char *kernelVersion;
};
typedef struct _virQEMUCapsCachePriv virQEMUCapsCachePriv;
typedef virQEMUCapsCachePriv *virQEMUCapsCachePrivPtr;
@@ -3845,6 +3852,7 @@ virQEMUCapsCachePrivFree(void *privData)
virQEMUCapsCachePrivPtr priv = privData;
VIR_FREE(priv->libDir);
+ VIR_FREE(priv->kernelVersion);
VIR_FREE(priv);
}
@@ -3970,6 +3978,12 @@ virQEMUCapsLoadCache(virArch hostArch,
goto cleanup;
}
+ if (virXPathBoolean("boolean(./kernelVersion)", ctxt) > 0) {
+ qemuCaps->kernelVersion = virXPathString("string(./kernelVersion)", ctxt);
+ if (!qemuCaps->kernelVersion)
+ goto cleanup;
+ }
+
if (!(str = virXPathString("string(./arch)", ctxt))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing arch in QEMU capabilities cache"));
@@ -4248,6 +4262,10 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps)
virBufferAsprintf(&buf, "<package>%s</package>\n",
qemuCaps->package);
+ if (qemuCaps->kernelVersion)
+ virBufferAsprintf(&buf, "<kernelVersion>%s</kernelVersion>\n",
+ qemuCaps->kernelVersion);
+
virBufferAsprintf(&buf, "<arch>%s</arch>\n",
virArchToString(qemuCaps->arch));
@@ -4385,14 +4403,24 @@ virQEMUCapsIsValid(void *data,
return false;
}
- if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) &&
- priv->microcodeVersion != qemuCaps->microcodeVersion) {
- VIR_DEBUG("Outdated capabilities for '%s': microcode version changed "
- "(%u vs %u)",
- qemuCaps->binary,
- priv->microcodeVersion,
- qemuCaps->microcodeVersion);
- return false;
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
+ if (priv->microcodeVersion != qemuCaps->microcodeVersion) {
+ VIR_DEBUG("Outdated capabilities for '%s': microcode version "
+ "changed (%u vs %u)",
+ qemuCaps->binary,
+ priv->microcodeVersion,
+ qemuCaps->microcodeVersion);
+ return false;
+ }
+
+ if (STRNEQ_NULLABLE(priv->kernelVersion, qemuCaps->kernelVersion)) {
+ VIR_DEBUG("Outdated capabilities for '%s': kernel version changed "
+ "('%s' vs '%s')",
+ qemuCaps->binary,
+ priv->kernelVersion,
+ qemuCaps->kernelVersion);
+ return false;
+ }
}
return true;
@@ -5228,6 +5256,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
uid_t runUid,
gid_t runGid,
unsigned int microcodeVersion,
+ const char *kernelVersion,
bool qmpOnly)
{
virQEMUCapsPtr qemuCaps;
@@ -5284,9 +5313,13 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_KVM);
virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_QEMU);
- if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
qemuCaps->microcodeVersion = microcodeVersion;
+ if (VIR_STRDUP(qemuCaps->kernelVersion, kernelVersion) < 0)
+ goto error;
+ }
+
cleanup:
VIR_FREE(qmperr);
return qemuCaps;
@@ -5309,6 +5342,7 @@ virQEMUCapsNewData(const char *binary,
priv->runUid,
priv->runGid,
priv->microcodeVersion,
+ priv->kernelVersion,
false);
}
@@ -5397,6 +5431,7 @@ virQEMUCapsCacheNew(const char *libDir,
char *capsCacheDir = NULL;
virFileCachePtr cache = NULL;
virQEMUCapsCachePrivPtr priv = NULL;
+ struct utsname uts = { 0 };
if (virAsprintf(&capsCacheDir, "%s/capabilities", cacheDir) < 0)
goto error;
@@ -5417,6 +5452,10 @@ virQEMUCapsCacheNew(const char *libDir,
priv->runGid = runGid;
priv->microcodeVersion = microcodeVersion;
+ if (uname(&uts) == 0 &&
+ virAsprintf(&priv->kernelVersion, "%s %s", uts.release, uts.version) < 0)
+ goto error;
+
cleanup:
VIR_FREE(capsCacheDir);
return cache;
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index 98d163b920..222f3368e3 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -37,6 +37,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
uid_t runUid,
gid_t runGid,
unsigned int microcodeVersion,
+ const char *kernelVersion,
bool qmpOnly);
int virQEMUCapsLoadCache(virArch hostArch,
diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c
index a5f5a38b16..7d60246949 100644
--- a/tests/qemucapsprobe.c
+++ b/tests/qemucapsprobe.c
@@ -72,7 +72,7 @@ main(int argc, char **argv)
return EXIT_FAILURE;
if (!(caps = virQEMUCapsNewForBinaryInternal(VIR_ARCH_NONE, argv[1], "/tmp",
- -1, -1, 0, true)))
+ -1, -1, 0, NULL, true)))
return EXIT_FAILURE;
virObjectUnref(caps);
--
2.16.0
6 years, 10 months
[libvirt] How to use /dev/net/tun from libvirt-lxc with user namespacing enabled
by Thiago Padilha
I have a container rootfs that I use to keep all work-related stuff. This
container was originally created by lxd (which creates all containers for
use with user namespacing), but now I decided to start using libvirt for
container management since I already use it for virtual machines, which
will spare me from dealing with multiple hypervisor technologies.
I managed to create a working domain xml for the container, and everything
seems to be working very well except one thing: I cannot start openconnect
(VPN software) inside the container. I noticed that by default libvirt
won't create /dev/net/tun for the container, so I added this to the domain
xml:
<filesystem type='mount'>
<source dir='/dev/net'/>
<target dir='/dev/net'/>
</filesystem>
This successfully created /dev/net/tun in the container, but openconnect
still can't open it even though it has 666 permissions. It seems this is
exactly what lxd does to allow VPNs for their unprivileged containers, as
shown by the output of ls -l /dev/net
total 0
crw-rw-rw- 1 nobody nogroup 10, 200 Jan 29 13:23 tun
The same container can also be successfully booted with systemd-nspawn,
also allowing openconnect to create its VPN.
I already tried setting security driver to "none" in /etc/libvirt/lxc.conf,
but it had no effect. I get "Operation not permitted" when trying to open
/dev/net/tun, which is also the message openconnect displays in its logs.
Can someone guide me on how I might debug what is causing this error? BTW,
here's the full xml:
<domain type='lxc'>
<name>work-stuff</name>
<uuid>ffee008c-ec6b-48ab-af6d-4aba830847a1</uuid>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>8388608</currentMemory>
<vcpu placement='static'>16</vcpu>
<resource>
<partition>/machine</partition>
</resource>
<os>
<type arch='x86_64'>exe</type>
<init>/sbin/init</init>
</os>
<idmap>
<uid start='0' target='165536' count='65536'/>
<gid start='0' target='165536' count='65536'/>
</idmap>
<cpu mode='host-model'>
<model fallback='allow'/>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/lib/libvirt/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/libvirt/containers/work-stuff/rootfs'/>
<target dir='/'/>
</filesystem>
<filesystem type='mount'>
<source dir='/dev/net'/>
<target dir='/dev/net'/>
</filesystem>
<interface type='network'>
<mac address='52:54:00:3e:59:e9'/>
<source network='default'/>
</interface>
<console type='pty'>
<target type='lxc' port='0'/>
</console>
</devices>
</domain>
6 years, 10 months
[libvirt] [PATCH 0/4] Tiny updates for virresctrl
by Martin Kletzander
The first patch is the only interesting one.
Martin Kletzander (4):
util: Check for empty allocation instead of just NULL pointer
util: Use "resctrl" instead of "resctrlfs" spelling
util: Make it possible for virResctrlAllocSetMask to replace existing
mask
util: Remove unused variable in virResctrlGetInfo
src/qemu/qemu_process.c | 2 +-
src/util/virresctrl.c | 19 +++++++++----------
2 files changed, 10 insertions(+), 11 deletions(-)
--
2.16.1
6 years, 10 months
[libvirt] [PATCH] build: Fix broken build on FreeBSD and OSX after recent nodedev series
by Erik Skultety
Commits f83c7c88 and 6eb1f2b9 broke the build on FreeBSD and OSX because
of symbols being undefined for those platforms.
Signed-off-by: Erik Skultety <eskultet(a)redhat.com>
---
Pushed under the build breaker rule.
src/conf/node_device_conf.c | 6 ++++++
src/util/virpci.c | 9 +++++++++
2 files changed, 15 insertions(+)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index dfd61b7b7..fd8f4e4a9 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -2806,6 +2806,12 @@ virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath,
#else
int
+virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host ATTRIBUTE_UNUSED)
+{
+ return -1;
+}
+
+int
virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath ATTRIBUTE_UNUSED,
virNodeDevCapPCIDevPtr pci_dev ATTRIBUTE_UNUSED)
{
diff --git a/src/util/virpci.c b/src/util/virpci.c
index b6a5739ca..55e4c3e49 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -3158,6 +3158,15 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path ATTRIBUTE_UNUSED,
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
}
+
+
+ssize_t
+virPCIGetMdevTypes(const char *sysfspath ATTRIBUTE_UNUSED,
+ virMediatedDeviceTypePtr **types ATTRIBUTE_UNUSED)
+{
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
+ return -1;
+}
#endif /* __linux__ */
int
--
2.13.6
6 years, 10 months
[libvirt] [PATCH 00/15] Nodedev-mdev overhaul
by Erik Skultety
TL;DR:
nodedev:
- contained a decent amount of redundant code handling the same thing,
now it doesn't.
- only updated dynamic capabilities during dumpXML, now it does every
time it touches them
mdev:
- didn't update mdev capabilities at all, now it does
This series combines some long-needed refactor changes to the nodedev driver
with some necessary mdev fixes based on Wu Zongyong's patch series [1].
There's a lot of simple code movement due to the fact that update of the device
capabilities is strictly bound to the nodedev driver. The problem with the
existing approach is that in order to properly update all capabilities,
especially mdev, we would have to violate the logical code flow we have and
call back into the driver to have access to sysfs, i.e. driver->(conf|obj)
handling->util_helpers->DRIVER. Therefore to resolve it, along with all the
compilation dependencies, I moved most of the capability handling out of the
driver into src/conf/node_device_conf.c which already contained more than just
parsing and formatting of the capabilities. I also had to move the existing
virNodeDevCapMdevType into src/util so that the util helpers would know the
type they're working with.
[1] https://www.redhat.com/archives/libvir-list/2018-January/msg00315.html
Erik Skultety (15):
conf: nodedev: Rename virNodeDevObjHasCap to virNodeDevObjHasCapStr
conf: nodedev: Rename virNodeDeviceCapMatch to virNodeDevObjHasCap
conf: nodedev: Convert virNodeDevObjHasCapStr to a simple wrapper
nodedev: Drop the nodeDeviceSysfsGetSCSIHostCaps wrapper
nodedev: Move the sysfs-related cap handling to node_device_conf.c
nodedev: Export nodeDeviceUpdateCaps from node_device_conf.c
nodedev: Introduce virNodeDeviceCapsListExport
conf: nodedev: Refresh capabilities before touching them
util: mdev: Drop some unused symbols/includes from the header
util: mdev: Introduce virMediatedDeviceType structure
util: mdev: Introduce virMediatedDeviceTypeReadAttrs getter
util: pci: Introduce virPCIGetMdevTypes helper
nodedev: udev: Drop the unused mdev type helpers
conf: Replace usage of virNodeDevCapMdevType with
virMediatedDeviceType
conf: nodedev: Update PCI mdev capabilities dynamically
src/Makefile.am | 4 +-
src/conf/node_device_conf.c | 343 ++++++++++++++++++++++++++++--
src/conf/node_device_conf.h | 29 +--
src/conf/virnodedeviceobj.c | 74 ++-----
src/libvirt_private.syms | 7 +-
src/node_device/node_device_driver.c | 130 ++---------
src/node_device/node_device_hal.c | 5 +-
src/node_device/node_device_linux_sysfs.c | 218 -------------------
src/node_device/node_device_linux_sysfs.h | 34 ---
src/node_device/node_device_udev.c | 127 +----------
src/util/virmdev.c | 47 ++++
src/util/virmdev.h | 20 +-
src/util/virpci.c | 58 +++++
src/util/virpci.h | 4 +
14 files changed, 516 insertions(+), 584 deletions(-)
delete mode 100644 src/node_device/node_device_linux_sysfs.c
delete mode 100644 src/node_device/node_device_linux_sysfs.h
--
2.13.6
6 years, 10 months
[libvirt] [PATCH 0/5] Add optional pSeries features
by Andrea Bolognani
I consider the first 4 patches ready for inclusion, but the last
one - which is basically what justifies going through all this
trouble - is sub-optimal until more development has happened in
QEMU, so it's marked as RFC. Still, I thought I'd get the ball
rolling sooner rather than later.
Andrea Bolognani (5):
docs: Refactor schema for 'resizing' attribute
conf: Add pSeries features
conf: Remove obsolete <hpt> feature
tests: Clean up HPT tests
conf: Add HTM pSeries feature
docs/formatdomain.html.in | 39 +++-
docs/schemas/domaincommon.rng | 39 +++-
src/conf/domain_conf.c | 249 ++++++++++++++++++---
src/conf/domain_conf.h | 14 +-
src/libvirt_private.syms | 2 +
src/qemu/qemu_capabilities.c | 9 +
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 116 ++++++++--
src/qemu/qemu_domain.c | 7 +-
...hpt-resizing.args => pseries-features-hpt.args} | 1 -
.../pseries-features-hpt.xml} | 4 +-
...hpt-resizing.args => pseries-features-htm.args} | 3 +-
.../pseries-features-htm.xml} | 4 +-
...ne.xml => pseries-features-invalid-machine.xml} | 6 +-
tests/qemuxml2argvdata/pseries-hpt-resizing.xml | 19 --
tests/qemuxml2argvtest.c | 12 +-
tests/qemuxml2xmloutdata/pseries-features-hpt.xml | 1 +
tests/qemuxml2xmloutdata/pseries-features-htm.xml | 1 +
tests/qemuxml2xmltest.c | 6 +-
19 files changed, 423 insertions(+), 110 deletions(-)
copy tests/qemuxml2argvdata/{pseries-hpt-resizing.args => pseries-features-hpt.args} (96%)
copy tests/{qemuxml2xmloutdata/pseries-hpt-resizing.xml => qemuxml2argvdata/pseries-features-hpt.xml} (92%)
rename tests/qemuxml2argvdata/{pseries-hpt-resizing.args => pseries-features-htm.args} (86%)
rename tests/{qemuxml2xmloutdata/pseries-hpt-resizing.xml => qemuxml2argvdata/pseries-features-htm.xml} (93%)
rename tests/qemuxml2argvdata/{pseries-hpt-resizing-invalid-machine.xml => pseries-features-invalid-machine.xml} (76%)
delete mode 100644 tests/qemuxml2argvdata/pseries-hpt-resizing.xml
create mode 120000 tests/qemuxml2xmloutdata/pseries-features-hpt.xml
create mode 120000 tests/qemuxml2xmloutdata/pseries-features-htm.xml
--
2.14.3
6 years, 10 months
[libvirt] [PATCH v2] virsh: Checking the volume capacity before uploading a new file.
by Julio Faracco
The current command 'vol-upload' is not checking if the volume accepts
a file bigger than its capacity. It can cause an interrupt of the
upload stream. This commit adds a check that fails before starting to
send new file to volume if the file is bigger.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1529059
Signed-off-by: Julio Faracco <jcfaracco(a)gmail.com>
---
tools/virsh-volume.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 8265a39..04e480c 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -672,6 +672,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
{
const char *file = NULL;
virStorageVolPtr vol = NULL;
+ virStorageVolInfo volumeInfo;
bool ret = false;
int fd = -1;
virStreamPtr st = NULL;
@@ -679,6 +680,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
unsigned long long offset = 0, length = 0;
virshControlPtr priv = ctl->privData;
unsigned int flags = 0;
+ off_t fileLen = -1;
virshStreamCallbackData cbData;
if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0)
@@ -701,6 +703,29 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
cbData.ctl = ctl;
cbData.fd = fd;
+ if (virStorageVolGetInfo(vol, &volumeInfo) < 0)
+ goto cleanup;
+
+ if ((fileLen = virFileLength(file, fd)) < 0) {
+ vshError(ctl, _("cannot get the file %s length"), file);
+ goto cleanup;
+ }
+
+ if (length < fileLen) {
+ vshError(ctl, _("length parameter is smaller than file size"));
+ goto cleanup;
+ }
+
+ if (volumeInfo.capacity < length) {
+ vshError(ctl, _("lenth parameter is bigger than volume %s capacity"), name);
+ goto cleanup;
+ }
+
+ if (volumeInfo.capacity < fileLen + offset) {
+ vshError(ctl, _("file is bigger than volume %s capacity"), name);
+ goto cleanup;
+ }
+
if (vshCommandOptBool(cmd, "sparse"))
flags |= VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM;
--
2.7.4
6 years, 10 months