[libvirt] [PATCH] storage: Cleanup logical volume creation code
by Jiri Denemark
This patch plugs two memory leaks, removes some useless and confusing
constructs and renames renames "cleanup" label as "error" since it is
only used for error path rather then being common for both success and
error paths.
---
src/storage/storage_backend_logical.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index bb709df..4757fe7 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -700,7 +700,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol)
{
- int fdret, fd = -1;
+ int fd = -1;
virCommandPtr cmd = NULL;
virErrorPtr err;
@@ -741,11 +741,12 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
virCommandAddArg(cmd, pool->def->source.name);
if (virCommandRun(cmd, NULL) < 0)
- goto cleanup;
+ goto error;
- if ((fdret = virStorageBackendVolOpen(vol->target.path)) < 0)
- goto cleanup;
- fd = fdret;
+ virCommandFree(cmd);
+
+ if ((fd = virStorageBackendVolOpen(vol->target.path)) < 0)
+ goto error;
/* We can only chown/grp if root */
if (getuid() == 0) {
@@ -753,40 +754,40 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
virReportSystemError(errno,
_("cannot set file owner '%s'"),
vol->target.path);
- goto cleanup;
+ goto error;
}
}
if (fchmod(fd, vol->target.perms.mode) < 0) {
virReportSystemError(errno,
_("cannot set file mode '%s'"),
vol->target.path);
- goto cleanup;
+ goto error;
}
if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot close file '%s'"),
vol->target.path);
- goto cleanup;
+ goto error;
}
- fd = -1;
/* Fill in data about this new vol */
if (virStorageBackendLogicalFindLVs(pool, vol) < 0) {
virReportSystemError(errno,
_("cannot find newly created volume '%s'"),
vol->target.path);
- goto cleanup;
+ goto error;
}
return 0;
- cleanup:
+ error:
err = virSaveLastError();
VIR_FORCE_CLOSE(fd);
virStorageBackendLogicalDeleteVol(conn, pool, vol, 0);
virCommandFree(cmd);
virSetError(err);
+ virFreeError(err);
return -1;
}
--
1.8.1.5
12 years, 1 month
[libvirt] [PATCH] storage: Fix memory leak in error path
by Jiri Denemark
This also renames cleanup label as error since it is only used for error
path rather then being common for both success and error paths.
---
src/storage/storage_backend_logical.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index bb709df..e3b3de4 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -741,10 +741,10 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
virCommandAddArg(cmd, pool->def->source.name);
if (virCommandRun(cmd, NULL) < 0)
- goto cleanup;
+ goto error;
if ((fdret = virStorageBackendVolOpen(vol->target.path)) < 0)
- goto cleanup;
+ goto error;
fd = fdret;
/* We can only chown/grp if root */
@@ -753,21 +753,21 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
virReportSystemError(errno,
_("cannot set file owner '%s'"),
vol->target.path);
- goto cleanup;
+ goto error;
}
}
if (fchmod(fd, vol->target.perms.mode) < 0) {
virReportSystemError(errno,
_("cannot set file mode '%s'"),
vol->target.path);
- goto cleanup;
+ goto error;
}
if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot close file '%s'"),
vol->target.path);
- goto cleanup;
+ goto error;
}
fd = -1;
@@ -776,17 +776,18 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
virReportSystemError(errno,
_("cannot find newly created volume '%s'"),
vol->target.path);
- goto cleanup;
+ goto error;
}
return 0;
- cleanup:
+ error:
err = virSaveLastError();
VIR_FORCE_CLOSE(fd);
virStorageBackendLogicalDeleteVol(conn, pool, vol, 0);
virCommandFree(cmd);
virSetError(err);
+ virFreeError(err);
return -1;
}
--
1.8.1.5
12 years, 1 month
[libvirt] [PATCH 0/3] Resolve some recently uncovered Coverity warnings
by John Ferlan
Perhaps due to other related changes in the code paths, my daily Coverity
scan uncovered a few new issues last week. It didn't seem any of the issues
found were critical path, so I waited for the 1.0.3 before posting.
I am running Coverity on a daily basis and trying to fine tune the "blame"
algorithm. Unfortunately when changes are made in sometimes related code
paths it allows Coverity to scan further thus sometimes uncovering some
paths that hadn't been covered before or had been blocked by other issues
Coverity uncovered in the path. I have a dialogue going with someone at
Coverity regarding these types of discoveries.
John Ferlan (3):
libxl_conf: Resolve Coverity issue with call to regcomp()
libxl_driver: Resolve Coverity errors
sheepdog: Add Coverity filter
src/libxl/libxl_conf.c | 11 ++++++++++-
src/libxl/libxl_driver.c | 10 ++++++----
src/storage/storage_backend_sheepdog.c | 2 ++
3 files changed, 18 insertions(+), 5 deletions(-)
--
1.8.1.2
12 years, 1 month
[libvirt] question about ading spice and vnc hardware
by yue
i create VM through virt-manage.
add hardware--> graphic--(spice,vnc server)
i do not understand the word 'server' means,
In my opinion , spice or vnc server is on KVM-HOST side, vnc,spice client connect to KVM-HOST. there are nothing to do with guestOS.
why virt-manage need me to add "server"?
thanks
12 years, 1 month
[libvirt] [PATCH 00/16] Add ability fill driver specific defaults when parsing the XML
by Peter Krempa
This monster series cleans up a ton of stuff and then adds the ability
to fill driver specific defaults by means of a callback.
The usage is demonstrated on automaticaly filling default NIC type
with qemu.
The long term aim is to move all validations and default settings
out of the parser.
Peter Krempa (16):
conf: Improve core dump config error message
qemu: Refactor error paths in virQEMUDriverCreateCapabilities
conf: Ensure that new devices are added to conf copy function
conf: Fix label naming in virDomainDefFormatInternal
conf: Reformat many function headers in domain_conf.c
conf: Refactor cpumask handling
conf: whitespace cleanups and refactors with no semantic impact
conf: Refactor ABI stability checking and break long lines
conf: Make virDomainDeviceInfoIterate usable without os type
conf: Add separate defaults addition and validation for XML parsing
qemu: Implement the device parse callback and use it for interfaces
tests: add to the tests and fix fallout
qemu_command: Clean up default model passing
conf: Don't add default controllers in the XML parser
conf: Simplify cputune parameter retrieval
conf: Move validation of domain title
src/conf/capabilities.h | 6 +
src/conf/domain_conf.c | 1177 ++++++++++----------
src/conf/domain_conf.h | 4 +-
src/qemu/qemu_command.c | 14 +-
src/qemu/qemu_conf.c | 18 +-
src/qemu/qemu_domain.c | 23 +
src/qemu/qemu_domain.h | 1 +
.../qemuxml2argv-net-bandwidth.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-net-client.args | 6 +-
.../qemuxml2argv-net-eth-ifname.args | 6 +-
.../qemuxml2argv-net-eth-ifname.xml | 1 +
.../qemuxml2argv-net-eth-names.args | 8 +-
tests/qemuxml2argvdata/qemuxml2argv-net-eth.args | 6 +-
tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-net-mcast.args | 6 +-
.../qemuxml2argv-net-openvswitch.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-net-server.args | 6 +-
tests/qemuxml2argvdata/qemuxml2argv-net-user.args | 5 +-
tests/qemuxml2argvdata/qemuxml2argv-net-user.xml | 1 +
.../qemuxml2argv-net-virtio-network-portgroup.xml | 2 +
.../qemuxml2xmlout-graphics-spice-timeout.xml | 1 +
tests/testutilsqemu.c | 1 +
23 files changed, 663 insertions(+), 633 deletions(-)
--
1.8.1.1
12 years, 1 month
[libvirt] [PATCH 0/2] virsh: Improve snapshot-list
by Peter Krempa
Peter Krempa (2):
virsh-snapshot: Add ability to print only snapshot names
virsh-snapshot: Refactor virsh snapshot-list
tools/virsh-snapshot.c | 143 ++++++++++++++++++++++++-------------------------
tools/virsh.pod | 11 ++--
2 files changed, 76 insertions(+), 78 deletions(-)
--
1.8.1.1
12 years, 1 month
[libvirt] [PATCHv4] virtio-rng: Add rate limiting options for virtio-RNG
by Peter Krempa
Qemu's implementation of virtio RNG supports rate limiting of the
entropy used. This patch exposes the option to tune this functionality.
This patch is based on qemu commit 904d6f588063fb5ad2b61998acdf1e73fb4
The rate limiting is exported in the XML as:
<devices>
...
<rng model='virtio'>
<rate period='1234'>4321</rate>
<backend model='random'/>
</rng>
...
---
Notes:
Version 4:
- Reword docs
- state it is available since 1.0.4 as the tree is frozen and this was actually never acked before
Version 3:
- State the time unit in docs
Version 2:
- Qemu uses bytes/period, adapt the value according to that
docs/formatdomain.html.in | 13 +++++++++++++
docs/schemas/domaincommon.rng | 18 +++++++++++++++++-
src/conf/domain_conf.c | 17 +++++++++++++++++
src/conf/domain_conf.h | 2 ++
src/qemu/qemu_command.c | 9 +++++++++
.../qemuxml2argv-virtio-rng-random.args | 2 +-
.../qemuxml2argv-virtio-rng-random.xml | 1 +
7 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 1835b39..1c6c73e 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4280,6 +4280,7 @@ qemu-kvm -net nic,model=? /dev/null
...
<devices>
<rng model='virtio'>
+ <rate period="2000">1234</rate>
<backend model='random'>/dev/random</backend>
<!-- OR -->
<backend model='egd' type='udp'>
@@ -4302,6 +4303,18 @@ qemu-kvm -net nic,model=? /dev/null
<li>'virtio' — supported by qemu and virtio-rng kernel module</li>
</ul>
</dd>
+ <dt><code>rate</code></dt>
+ <dd>
+ <p>
+ The optional <code>rate</code> element allows limiting the rate at
+ which entropy can be consumed from the source. An optional
+ <code>period</code> attribute specifies the duration of a period in
+ milliseconds; if omitted, the period is taken as 1000 milliseconds
+ (1 second). The element contents specify how many bits are permitted
+ per period. Drivers may enforce a minimum rate, and may round the
+ rate down to a minimum granularity.
+ </p>
+ </dd>
<dt><code>backend</code></dt>
<dd>
<p>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index e7231cc..172926c 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3500,7 +3500,12 @@
<value>virtio</value>
</choice>
</attribute>
- <ref name="rng-backend"/>
+ <interleave>
+ <ref name="rng-backend"/>
+ <optional>
+ <ref name="rng-rate"/>
+ </optional>
+ </interleave>
</element>
</define>
@@ -3524,6 +3529,17 @@
</element>
</define>
+ <define name="rng-rate">
+ <element name="rate">
+ <optional>
+ <attribute name="period">
+ <ref name="positiveInteger"/>
+ </attribute>
+ </optional>
+ <ref name="positiveInteger"/>
+ </element>
+ </define>
+
<define name="usbmaster">
<element name="master">
<attribute name="startport">
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 995cf0c..f556e4c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7399,6 +7399,17 @@ virDomainRNGDefParseXML(const xmlNodePtr node,
ctxt->node = node;
+ if (virXPathUInt("string(./rate)", ctxt, &def->rate) < -1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid RNG rate value"));
+ goto error;
+ }
+
+ if (def->rate > 0 &&
+ virXPathUInt("string(./rate/@period)", ctxt, &def->period) < -1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid RNG period value"));
+ goto error;
+ }
+
if ((nbackends = virXPathNodeSet("./backend", ctxt, &backends)) < 0)
goto error;
@@ -13708,6 +13719,12 @@ virDomainRNGDefFormat(virBufferPtr buf,
const char *backend = virDomainRNGBackendTypeToString(def->backend);
virBufferAsprintf(buf, " <rng model='%s'>\n", model);
+ if (def->rate) {
+ virBufferAddLit(buf, " <rate");
+ if (def->period)
+ virBufferAsprintf(buf, " period='%u'", def->period);
+ virBufferAsprintf(buf, ">%u</rate>\n", def->rate);
+ }
virBufferAsprintf(buf, " <backend model='%s'", backend);
switch ((enum virDomainRNGBackend) def->backend) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5828ae2..1546f21 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1721,6 +1721,8 @@ enum virDomainRNGBackend {
struct _virDomainRNGDef {
int model;
int backend;
+ unsigned int rate; /* bits per period */
+ unsigned int period; /* milliseconds */
union {
char *file; /* file name for 'random' source */
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1c9bfc9..6fcc093 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4255,6 +4255,15 @@ qemuBuildRNGDeviceArgs(virCommandPtr cmd,
virBufferAsprintf(&buf, "virtio-rng-pci,rng=%s", dev->info.alias);
+ if (dev->rate > 0) {
+ /* qemu uses bytes */
+ virBufferAsprintf(&buf, ",max-bytes=%u", dev->rate / 8);
+ if (dev->period)
+ virBufferAsprintf(&buf, ",period=%u", dev->period);
+ else
+ virBufferAddLit(&buf, ",period=1000");
+ }
+
if (qemuBuildDeviceAddressStr(&buf, &dev->info, qemuCaps) < 0)
goto cleanup;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args
index ad27132..4a0437b 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args
@@ -3,4 +3,4 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu \
-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
-object 'rng-random,id=rng0,filename=/test/ph<ile' \
--device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x4
+-device virtio-rng-pci,rng=rng0,max-bytes=100,period=1234,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml
index 0658f4b..3899408 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml
@@ -17,6 +17,7 @@
<controller type='usb' index='0'/>
<memballoon model='virtio'/>
<rng model='virtio'>
+ <rate period='1234'>800</rate>
<backend model='random'>/test/ph<ile</backend>
</rng>
</devices>
--
1.8.1.1
12 years, 1 month
[libvirt] [PATCHv2] conf: Report errors on cputune parameter parsing
by Peter Krempa
This patch adds proper error reporting if parsing of cputune parameters
fails due to incorrect values provided by the user. Previously no errors
were reported in such a case and the failure was silently ignored.
---
v2: report errors instead of ignoring them
src/conf/domain_conf.c | 38 ++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ca645c7..1422b47 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9471,29 +9471,43 @@ virDomainDefParseXML(virCapsPtr caps,
/* Extract cpu tunables. */
if (virXPathULong("string(./cputune/shares[1])", ctxt,
- &def->cputune.shares) < 0)
- def->cputune.shares = 0;
+ &def->cputune.shares) < -1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("can't parse cputune shares value"));
+ goto error;
+ }
if (virXPathULongLong("string(./cputune/period[1])", ctxt,
- &def->cputune.period) < 0)
- def->cputune.period = 0;
+ &def->cputune.period) < -1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("can't parse cputune period value"));
+ goto error;
+ }
if (virXPathLongLong("string(./cputune/quota[1])", ctxt,
- &def->cputune.quota) < 0)
- def->cputune.quota = 0;
+ &def->cputune.quota) < -1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("can't parse cputune quota value"));
+ goto error;
+ }
if (virXPathULongLong("string(./cputune/emulator_period[1])", ctxt,
- &def->cputune.emulator_period) < 0)
- def->cputune.emulator_period = 0;
+ &def->cputune.emulator_period) < -1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("can't parse cputune emulator period value"));
+ goto error;
+ }
if (virXPathLongLong("string(./cputune/emulator_quota[1])", ctxt,
- &def->cputune.emulator_quota) < 0)
- def->cputune.emulator_quota = 0;
-
- if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0) {
+ &def->cputune.emulator_quota) < -1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("can't parse cputune emualtor quota value"));
goto error;
}
+ if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0)
+ goto error;
+
if (n && VIR_ALLOC_N(def->cputune.vcpupin, n) < 0)
goto no_memory;
--
1.8.1.1
12 years, 1 month