[libvirt] [PATCH] network: Add support for configuring dhcp lease time
by Nehal J Wani
The default dhcp lease time set by dnsmasq is only one hour, which can be
pretty small for developers relying on ip address(es) to be consistent
across reboots.
This patch adds support for setting a lease time in the network definition.
For now, all IP ranges under one <dhcp> will share a common leasetime.
An example:
<dhcp>
<leasetime units='hours'>12</leasetime>
</dhcp>
The value for attribute 'units' can be seconds/hours/days/weeks/s/h/d/w.
If the leasetime specified is -1, it is considered to be infinite.
docs/schema/{basictypes,network}.rng
* Add datatype long
* Introduce timeUnits, scaledTime
* Add schema for tag: leasetime
src/util/virutil.{c,h}
* Introduce virScaleTime()
src/conf/network_conf.h
* Extend virNetworkIPDef to accomodate leastime
* Define VIR_NETWORK_DHCP_LEASE_TIME_MAX
src/conf/network_conf.c
* Introduce virNetworkDHCPLeaseTimeParseXML
* Modify virNetworkDHCPDefParseXML to have XPath context pointer
tests/*
* Add test cases for xml parsing and conversion
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=913446
---
docs/schemas/basictypes.rng | 20 +++++++
docs/schemas/network.rng | 10 +++-
src/conf/network_conf.c | 67 ++++++++++++++++++++-
src/conf/network_conf.h | 11 ++++
src/network/bridge_driver.c | 8 +++
src/util/virutil.c | 70 ++++++++++++++++++++++
src/util/virutil.h | 3 +
.../isolated-network-with-lease-time.conf | 17 ++++++
.../isolated-network-with-lease-time.xml | 24 ++++++++
tests/networkxml2conftest.c | 1 +
.../isolated-network-with-lease-time.xml | 24 ++++++++
.../isolated-network-with-lease-time.xml | 24 ++++++++
tests/networkxml2xmltest.c | 1 +
13 files changed, 276 insertions(+), 4 deletions(-)
create mode 100644 tests/networkxml2confdata/isolated-network-with-lease-time.conf
create mode 100644 tests/networkxml2confdata/isolated-network-with-lease-time.xml
create mode 100644 tests/networkxml2xmlin/isolated-network-with-lease-time.xml
create mode 100644 tests/networkxml2xmlout/isolated-network-with-lease-time.xml
diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng
index 1b4f980..023edfb 100644
--- a/docs/schemas/basictypes.rng
+++ b/docs/schemas/basictypes.rng
@@ -13,6 +13,12 @@
<param name='pattern'>[0-9]+</param>
</data>
</define>
+ <!-- Our long doesn"t allow a leading "+" in its lexical form -->
+ <define name='long'>
+ <data type='long'>
+ <param name='pattern'>-?[0-9]+</param>
+ </data>
+ </define>
<define name='hexuint'>
<data type='string'>
@@ -283,6 +289,20 @@
<ref name='unsignedLong'/>
</define>
+ <define name='timeUnit'>
+ <data type='string'>
+ <param name='pattern'>(seconds|minutes|hours|days|weeks|s|m|h|d|w)</param>
+ </data>
+ </define>
+ <define name='scaledTime'>
+ <optional>
+ <attribute name='timeUnit'>
+ <ref name='timeUnit'/>
+ </attribute>
+ </optional>
+ <ref name='long'/>
+ </define>
+
<define name="pciDomain">
<ref name="uint16"/>
</define>
diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng
index 1a18e64..66b65bc 100644
--- a/docs/schemas/network.rng
+++ b/docs/schemas/network.rng
@@ -337,9 +337,15 @@
</element>
</optional>
<optional>
- <!-- Define the range(s) of IP addresses that the DHCP
- server should hand out -->
<element name="dhcp">
+ <optional>
+ <element name="leasetime">
+ <ref name="scaledTime"/>
+ <attribute name="unit"><ref name="timeUnit"/></attribute>
+ </element>
+ </optional>
+ <!-- Define the range(s) of IP addresses that the DHCP
+ server should hand out -->
<zeroOrMore>
<element name="range">
<attribute name="start"><ref name="ipAddr"/></attribute>
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index aa39776..d2372f2 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1032,21 +1032,76 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
}
static int
+virNetworkDHCPLeaseTimeParseXML(const char *networkName,
+ virNetworkIPDefPtr def,
+ xmlXPathContextPtr ctxt,
+ xmlNodePtr node)
+{
+ int ret = -1;
+ int scale = 1;
+ xmlNodePtr save;
+ char *unit = NULL;
+ int leasetimeRV = 0;
+ long long leasetime;
+
+ save = ctxt->node;
+ ctxt->node = node;
+
+ leasetimeRV = virXPathLongLong("string(./text())", ctxt, &leasetime);
+ if (leasetimeRV == -2) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid long long value specified for leasetime "
+ "in definition of network '%s'"),
+ networkName);
+ goto cleanup;
+ } else {
+ if (leasetime < 0) {
+ leasetime = -1; /* infinite */
+ } else {
+ unit = virXPathString("string(./@unit)", ctxt);
+ if (virScaleTime(&leasetime, unit, scale,
+ VIR_NETWORK_DHCP_LEASE_TIME_MAX) < 0) {
+ // let virScaleTime() report the appropriate error
+ goto cleanup;
+ }
+ }
+ }
+
+ def->leasetime = leasetime;
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(unit);
+ ctxt->node = save;
+ return ret;
+}
+
+static int
virNetworkDHCPDefParseXML(const char *networkName,
xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
virNetworkIPDefPtr def)
{
int ret = -1;
- xmlNodePtr cur;
+ xmlNodePtr cur, save;
virSocketAddrRange range;
virNetworkDHCPHostDef host;
memset(&range, 0, sizeof(range));
memset(&host, 0, sizeof(host));
+ save = ctxt->node;
+ ctxt->node = node;
+
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE &&
+ xmlStrEqual(cur->name, BAD_CAST "leasetime")) {
+
+ if (virNetworkDHCPLeaseTimeParseXML(networkName, def, ctxt, cur) < 0)
+ goto cleanup;
+
+ } else if (cur->type == XML_ELEMENT_NODE &&
xmlStrEqual(cur->name, BAD_CAST "range")) {
if (virSocketAddrRangeParseXML(networkName, def, cur, &range) < 0)
@@ -1095,6 +1150,7 @@ virNetworkDHCPDefParseXML(const char *networkName,
ret = 0;
cleanup:
virNetworkDHCPHostDefClear(&host);
+ ctxt->node = save;
return ret;
}
@@ -1607,7 +1663,7 @@ virNetworkIPDefParseXML(const char *networkName,
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE &&
xmlStrEqual(cur->name, BAD_CAST "dhcp")) {
- if (virNetworkDHCPDefParseXML(networkName, cur, def) < 0)
+ if (virNetworkDHCPDefParseXML(networkName, cur, ctxt, def) < 0)
goto cleanup;
} else if (cur->type == XML_ELEMENT_NODE &&
xmlStrEqual(cur->name, BAD_CAST "tftp")) {
@@ -2675,6 +2731,13 @@ virNetworkIPDefFormat(virBufferPtr buf,
virBufferAddLit(buf, "<dhcp>\n");
virBufferAdjustIndent(buf, 2);
+ if (def->leasetime) {
+ virBufferAddLit(buf, "<leasetime");
+ virBufferAsprintf(buf, " unit='seconds'>%lld",
+ def->leasetime);
+ virBufferAddLit(buf, "</leasetime>\n");
+ }
+
for (i = 0; i < def->nranges; i++) {
char *saddr = virSocketAddrFormat(&def->ranges[i].start);
if (!saddr)
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 3b227db..965fd3b 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -26,6 +26,15 @@
# define DNS_RECORD_LENGTH_SRV (512 - 30) /* Limit minus overhead as mentioned in RFC-2782 */
+/**
+ * VIR_NETWORK_DHCP_LEASE_TIME_MAX:
+ *
+ * Macro providing the upper limit on DHCP Lease Time (in seconds).
+ * Libvirt supports only dnsmasq as of now, and it stores the lease
+ * time in an unsigned int.
+ */
+# define VIR_NETWORK_DHCP_LEASE_TIME_MAX UINT_MAX
+
# include <libxml/parser.h>
# include <libxml/tree.h>
# include <libxml/xpath.h>
@@ -167,6 +176,8 @@ struct _virNetworkIPDef {
size_t nhosts; /* Zero or more dhcp hosts */
virNetworkDHCPHostDefPtr hosts;
+ long long leasetime; /* DHCP lease time for all ranges */
+
char *tftproot;
char *bootfile;
virSocketAddr bootserver;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 7b99aca..fa628d3 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1222,6 +1222,14 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
saddr, eaddr);
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6))
virBufferAsprintf(&configbuf, ",%d", prefix);
+
+ if (ipdef->leasetime) {
+ if (ipdef->leasetime == -1)
+ virBufferAddLit(&configbuf, ",infinite");
+ else
+ virBufferAsprintf(&configbuf, ",%lld", ipdef->leasetime);
+ }
+
virBufferAddLit(&configbuf, "\n");
VIR_FREE(saddr);
diff --git a/src/util/virutil.c b/src/util/virutil.c
index b57a195..81a60e6 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -275,6 +275,76 @@ virHexToBin(unsigned char c)
}
}
+/**
+ * virScaleTime:
+ * @value: pointer to the integer which is supposed to hold value
+ * @unit: pointer to the string holding the unit
+ * @scale: integer holding the value of scale
+ * @limit: upper limit on scaled value
+ *
+ * Scale an integer @value in-place by an optional case-insensitive @unit,
+ * defaulting to @scale if @unit is NULL or empty. Recognized units include
+ * (w)eeks, (d)ays, (h)ours, (m)inutes and (s)econds. Ensure that the result
+ * does not exceed @limit. Return 0 on success, -1 with error message raised
+ * on failure.
+ */
+int
+virScaleTime(long long *value, const char *unit,
+ long long scale, long long limit)
+{
+ size_t i;
+ static char const* const allowed_units[] = {"s", "m", "h", "d", "w",
+ "seconds", "minutes", "hours", "days", "weeks"};
+
+ size_t n_allowed_units = ARRAY_CARDINALITY(allowed_units);
+
+ if (!unit || !*unit) {
+ if (!scale) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Invalid scale %lld"), scale);
+ return -1;
+ }
+ unit = "";
+ } else {
+ for (i = 0; i < n_allowed_units; i++) {
+ if (STREQ(unit, allowed_units[i])) {
+ switch (*unit) {
+ case 'w':
+ scale *= 7;
+ /* fall through */
+ case 'd':
+ scale *= 24;
+ /* fall through */
+ case 'h':
+ scale *= 60;
+ /* fall through */
+ case 'm':
+ scale *= 60;
+ /* fall through */
+ case 's':
+ break;
+ }
+ break;
+ }
+ }
+ if (i == n_allowed_units) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("Unknown time unit '%s'"), unit);
+ return -1;
+ }
+ }
+
+ if (*value && *value > (limit / scale)) {
+ virReportError(VIR_ERR_OVERFLOW, _("Value too large: %lld %s"),
+ *value, unit);
+ return -1;
+ }
+
+ *value *= scale;
+ return 0;
+}
+
+
/* Scale an integer VALUE in-place by an optional case-insensitive
* SUFFIX, defaulting to SCALE if suffix is NULL or empty (scale is
* typically 1 or 1024). Recognized suffixes include 'b' or 'bytes',
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 703ec53..5c11f77 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -51,6 +51,9 @@ int virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
unsigned long long capBits,
bool clearExistingCaps);
+int virScaleTime(long long *value, const char *unit,
+ long long scale, long long limit);
+
int virScaleInteger(unsigned long long *value, const char *suffix,
unsigned long long scale, unsigned long long limit)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
diff --git a/tests/networkxml2confdata/isolated-network-with-lease-time.conf b/tests/networkxml2confdata/isolated-network-with-lease-time.conf
new file mode 100644
index 0000000..cd353f5
--- /dev/null
+++ b/tests/networkxml2confdata/isolated-network-with-lease-time.conf
@@ -0,0 +1,17 @@
+##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
+##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
+## virsh net-edit private
+## or other application using the libvirt API.
+##
+## dnsmasq conf file created by libvirt
+strict-order
+except-interface=lo
+bind-dynamic
+interface=virbr1
+dhcp-range=192.168.123.2,192.168.123.254,infinite
+dhcp-no-override
+dhcp-range=2001:db8:ca2:2:1::10,2001:db8:ca2:2:1::ff,64,108000
+dhcp-lease-max=493
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/private.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/private.addnhosts
+enable-ra
diff --git a/tests/networkxml2confdata/isolated-network-with-lease-time.xml b/tests/networkxml2confdata/isolated-network-with-lease-time.xml
new file mode 100644
index 0000000..be8ea56
--- /dev/null
+++ b/tests/networkxml2confdata/isolated-network-with-lease-time.xml
@@ -0,0 +1,24 @@
+<network>
+ <name>private</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward mode='nat'>
+ <nat>
+ <port start='1024' end='65535'/>
+ </nat>
+ </forward>
+ <bridge name='virbr1' stp='on' delay='0'/>
+ <mac address='52:54:00:10:2f:05'/>
+ <ip address='192.168.123.1' netmask='255.255.255.0'>
+ <dhcp>
+ <leasetime unit="minutes">-1</leasetime>
+ <range start='192.168.123.2' end='192.168.123.254'/>
+ </dhcp>
+ </ip>
+ <ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" >
+ <dhcp>
+ <leasetime unit="h">30</leasetime>
+ <range start="2001:db8:ca2:2:1::10" end="2001:db8:ca2:2:1::ff" />
+ <host id="0:4:7e:7d:f0:7d:a8:bc:c5:d2:13:32:11:ed:16:ea:84:63" name="nwani" ip="2001:db8:ca2:2:3::4" />
+ </dhcp>
+ </ip>
+</network>
diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c
index 65a0e32..501954d 100644
--- a/tests/networkxml2conftest.c
+++ b/tests/networkxml2conftest.c
@@ -112,6 +112,7 @@ mymain(void)
} while (0)
DO_TEST("isolated-network", restricted);
+ DO_TEST("isolated-network-with-lease-time", dhcpv6);
DO_TEST("netboot-network", restricted);
DO_TEST("netboot-proxy-network", restricted);
DO_TEST("nat-network-dns-srv-record-minimal", restricted);
diff --git a/tests/networkxml2xmlin/isolated-network-with-lease-time.xml b/tests/networkxml2xmlin/isolated-network-with-lease-time.xml
new file mode 100644
index 0000000..75c9f22
--- /dev/null
+++ b/tests/networkxml2xmlin/isolated-network-with-lease-time.xml
@@ -0,0 +1,24 @@
+<network>
+ <name>private</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward mode='nat'>
+ <nat>
+ <port start='1024' end='65535'/>
+ </nat>
+ </forward>
+ <bridge name='virbr1' stp='on' delay='0'/>
+ <mac address='52:54:00:10:2f:05'/>
+ <ip address='192.168.123.1' netmask='255.255.255.0'>
+ <dhcp>
+ <leasetime unit="minutes">-1</leasetime>
+ <range start='192.168.123.2' end='192.168.123.254'/>
+ </dhcp>
+ </ip>
+ <ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" >
+ <dhcp>
+ <leasetime unit="d">30</leasetime>
+ <range start="2001:db8:ca2:2:1::10" end="2001:db8:ca2:2:1::ff" />
+ <host id="0:4:7e:7d:f0:7d:a8:bc:c5:d2:13:32:11:ed:16:ea:84:63" name="nwani" ip="2001:db8:ca2:2:3::4" />
+ </dhcp>
+ </ip>
+</network>
diff --git a/tests/networkxml2xmlout/isolated-network-with-lease-time.xml b/tests/networkxml2xmlout/isolated-network-with-lease-time.xml
new file mode 100644
index 0000000..d9d6ff4
--- /dev/null
+++ b/tests/networkxml2xmlout/isolated-network-with-lease-time.xml
@@ -0,0 +1,24 @@
+<network>
+ <name>private</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward mode='nat'>
+ <nat>
+ <port start='1024' end='65535'/>
+ </nat>
+ </forward>
+ <bridge name='virbr1' stp='on' delay='0'/>
+ <mac address='52:54:00:10:2f:05'/>
+ <ip address='192.168.123.1' netmask='255.255.255.0'>
+ <dhcp>
+ <leasetime unit='seconds'>-1</leasetime>
+ <range start='192.168.123.2' end='192.168.123.254'/>
+ </dhcp>
+ </ip>
+ <ip family='ipv6' address='2001:db8:ca2:2::1' prefix='64'>
+ <dhcp>
+ <leasetime unit='seconds'>2592000</leasetime>
+ <range start='2001:db8:ca2:2:1::10' end='2001:db8:ca2:2:1::ff'/>
+ <host id='0:4:7e:7d:f0:7d:a8:bc:c5:d2:13:32:11:ed:16:ea:84:63' name='nwani' ip='2001:db8:ca2:2:3::4'/>
+ </dhcp>
+ </ip>
+</network>
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
index 01cd6f7..665f695 100644
--- a/tests/networkxml2xmltest.c
+++ b/tests/networkxml2xmltest.c
@@ -126,6 +126,7 @@ mymain(void)
DO_TEST("dhcp6host-routed-network");
DO_TEST("empty-allow-ipv6");
DO_TEST("isolated-network");
+ DO_TEST("isolated-network-with-lease-time");
DO_TEST("routed-network");
DO_TEST("routed-network-no-dns");
DO_TEST_PARSE_ERROR("routed-network-no-dns-extra-elements");
--
2.7.4
8 years, 1 month
[libvirt] [PATCH] bhyve: chase cpuCompareXML rename
by Roman Bogorodskiy
In commit 7f127de cpuCompareXML was renamed to virCPUCompareXML,
so change the bhyve driver to use the new function and thus
fix the build.
---
Pushed under the build-breaker rule.
src/bhyve/bhyve_driver.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 51b6301..49b9e1a 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1436,7 +1436,8 @@ bhyveConnectCompareCPU(virConnectPtr conn,
ret = VIR_CPU_COMPARE_INCOMPATIBLE;
}
} else {
- ret = cpuCompareXML(caps->host.cpu, xmlDesc, failIncompatible);
+ ret = virCPUCompareXML(caps->host.arch, caps->host.cpu,
+ xmlDesc, failIncompatible);
}
cleanup:
--
2.7.4
8 years, 1 month
[libvirt] [PATCH] doc: fix note about Xen credit scheduler
by Jim Fehlig
Commit 6c504d6a added a note to the virsh man page about the
deprecation of 'cap' and 'weight' settings for the credit
scheduler. To this day, the default scheduler in Xen is credit
and it supports setting 'cap' and 'weight'. Remove the deprecation
notice from the note on the Xen credit scheduler.
Reported-by: Volo M. <vm(a)vovs.net>
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
tools/virsh.pod | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 49abda9..971b408 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1959,7 +1959,7 @@ Therefore, -1 is a useful shorthand for 262144. On the Linux kernel, the
values 0 and 1 are automatically converted to a minimal value of 2.
B<Note>: The weight and cap parameters are defined only for the
-XEN_CREDIT scheduler and are now I<DEPRECATED>.
+XEN_CREDIT scheduler.
B<Note>: The vcpu_period, emulator_period, and iothread_period parameters
have a valid value range of 1000-1000000 or 0, and the vcpu_quota,
--
2.1.4
8 years, 1 month
[libvirt] [PATCH] libxl: fix param assignment in domainGetSchedulerParameters
by Jim Fehlig
Due to a copy and paste error, the scheduler 'cap' parameter
was over-writing the 'weight' parameter when preparing the
return parameters in libxlDomainGetSchedulerParametersFlags.
As a result, the scheduler weight was never shown when getting
schedinfo and setting the weight failed as well
virsh schedinfo testvm
Scheduler : credit
cap : 0
virsh schedinfo testvm --cap 50 --weight 500
Scheduler : credit
error: invalid scheduler option: weight
The obvious fix is to assign the 'caps' parameter to the correct
item in the parameter list.
Reported-by: Volo M. <vm(a)vovs.net>
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
src/libxl/libxl_driver.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 1adf4c5..b66cb1f 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -4571,7 +4571,7 @@ libxlDomainGetSchedulerParametersFlags(virDomainPtr dom,
goto cleanup;
if (*nparams > 1) {
- if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_SCHEDULER_CAP,
+ if (virTypedParameterAssign(¶ms[1], VIR_DOMAIN_SCHEDULER_CAP,
VIR_TYPED_PARAM_UINT, sc_info.cap) < 0)
goto cleanup;
}
--
2.1.4
8 years, 1 month
[libvirt] """virsh schedinfo [--weight number] domain""" doesn't work with virsh(libxl) for managing Xen domains.
by Volo M.
Hi Devs,
We're using Centos 7 Xen hypervisors and try to use Libvirt(libxl) for
managing Xen guest domains.
We noticed that we can't set cpu weight values for Xen domains with libvirt
(tested for libvirt v.1.3 and v.2.2) even though its possible to do with XL
toolkit.
[root@hv1xen ~]# virsh schedinfo --domain rtp6a88apsm3or --cap=5
Scheduler : credit
weight : 1000
[root@hv1xen ~]# virsh schedinfo --domain rtp6a88apsm3or --weight=50
Scheduler : credit
error: invalid scheduler option: weight
We noticed in documentation for 'virsh' like this
https://linux.die.net/man/1/virsh that the cpu weight option is going to be
deprecated:
*"""Note*: The weight and cap parameters are defined only for the XEN_CREDIT
scheduler and are now *DEPRECATED* . """
Can you please clarify why it's been deprecated and what should be used
instead for scheduling and limitation of CPU for Xen domains with Libvirt?
We like Libvirt very much and don't want to apply some awkward workarounds
like simultaneous using Libvirt and XL toolkit.
Any suggestion here?
Thanks.
8 years, 1 month
[libvirt] [PATCH v3 0/4] libxl: channels support
by Joao Martins
Hey,
This v3 from channel series with latest comments addressed. Difference to
qemu driver would be only the autogenerated path being slightly different.
Channels have been on xen toolstack since Xen 4.5 and this small series
adds support for it, including xenconfig conversion and appropriate tests.
After this series it's possible to do this:
(assuming correct configuration of qemu agent in the guest)
$ cat domain.xml | grep -a1 channel | head -n 5 | tail -n 4
<channel type='unix'>
<source mode='bind' path='/tmp/channel'/>
<target type='xen' name='org.qemu.guest_agent.0'/>
</channel>
$ virsh create domain.xml
$ echo '{"execute":"guest-network-get-interfaces"}' | socat
stdio,ignoreeof unix-connect:/tmp/channel
{"execute":"guest-network-get-interfaces"}
{"return": [{"name": "lo", "ip-addresses": [{"ip-address-type": "ipv4",
"ip-address": "127.0.0.1", "prefix": 8}, {"ip-address-type": "ipv6",
"ip-address": "::1", "prefix": 128}], "hardware-address":
"00:00:00:00:00:00"}, {"name": "eth0", "ip-addresses":
[{"ip-address-type": "ipv4", "ip-address": "10.100.0.6", "prefix": 24},
{"ip-address-type": "ipv6", "ip-address": "fe80::216:3eff:fe40:88eb",
"prefix": 64}], "hardware-address": "00:16:3e:40:88:eb"}, {"name":
"sit0"}]}
Thanks,
Joao
Joao Martins (4):
conf: add xen type for channels
libxl: channels support
xenconfig: channels conversion support
xlconfigtest: add test for channel conversion
docs/formatdomain.html.in | 10 ++
docs/schemas/domaincommon.rng | 11 ++
src/conf/domain_conf.c | 18 +++-
src/conf/domain_conf.h | 1 +
src/libxl/libxl_conf.c | 110 +++++++++++++++++++
src/libxl/libxl_conf.h | 3 +
src/libxl/libxl_domain.c | 43 +++++++-
src/libxl/libxl_driver.c | 7 ++
src/qemu/qemu_command.c | 1 +
src/xenconfig/xen_xl.c | 176 +++++++++++++++++++++++++++++++
tests/xlconfigdata/test-channel-pty.cfg | 13 +++
tests/xlconfigdata/test-channel-pty.xml | 33 ++++++
tests/xlconfigdata/test-channel-unix.cfg | 13 +++
tests/xlconfigdata/test-channel-unix.xml | 34 ++++++
tests/xlconfigtest.c | 4 +
15 files changed, 472 insertions(+), 5 deletions(-)
create mode 100644 tests/xlconfigdata/test-channel-pty.cfg
create mode 100644 tests/xlconfigdata/test-channel-pty.xml
create mode 100644 tests/xlconfigdata/test-channel-unix.cfg
create mode 100644 tests/xlconfigdata/test-channel-unix.xml
--
2.1.4
8 years, 1 month
[libvirt] [PATCH v2] qemu: Fix crash in qemucapsprobe
by Jiri Denemark
The qemucapsprobe helper calls virQEMUCapsNewForBinaryInternal with
caps == NULL, causing the following crash:
Program received signal SIGSEGV, Segmentation fault.
#0 0x00007ffff788775f in virQEMUCapsInitHostCPUModel
(qemuCaps=qemuCaps@entry=0x649680, host=host@entry=0x10) at
src/qemu/qemu_capabilities.c:2969
#1 0x00007ffff7889dbf in virQEMUCapsNewForBinaryInternal
(caps=caps@entry=0x0, binary=<optimized out>,
libDir=libDir@entry=0x4033f6 "/tmp", cacheDir=cacheDir@entry=0x0,
runUid=runUid@entry=4294967295, runGid=runGid@entry=4294967295,
qmpOnly=true) at src/qemu/qemu_capabilities.c:4039
#2 0x0000000000401702 in main (argc=2, argv=0x7fffffffd968) at
tests/qemucapsprobe.c:73
Caused by v2.2.0-182-g68c7011.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 15 +++++++++------
src/qemu/qemu_capspriv.h | 2 +-
tests/qemuxml2argvtest.c | 2 +-
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 4d859c4..cc8ec58 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2962,14 +2962,17 @@ virQEMUCapsCPUFilterFeatures(const char *name,
void
virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
- virCapsHostPtr host)
+ virCapsPtr caps)
{
virCPUDefPtr cpu = NULL;
- if (!virQEMUCapsGuestIsNative(host->arch, qemuCaps->arch))
+ if (!caps)
+ return;
+
+ if (!virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
goto error;
- if (host->cpu && host->cpu->model) {
+ if (caps->host.cpu && caps->host.cpu->model) {
if (VIR_ALLOC(cpu) < 0)
goto error;
@@ -2978,7 +2981,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
cpu->mode = VIR_CPU_MODE_CUSTOM;
cpu->match = VIR_CPU_MATCH_EXACT;
- if (virCPUDefCopyModelFilter(cpu, host->cpu, true,
+ if (virCPUDefCopyModelFilter(cpu, caps->host.cpu, true,
virQEMUCapsCPUFilterFeatures, NULL) < 0)
goto error;
}
@@ -3248,7 +3251,7 @@ virQEMUCapsLoadCache(virCapsPtr caps,
}
VIR_FREE(nodes);
- virQEMUCapsInitHostCPUModel(qemuCaps, &caps->host);
+ virQEMUCapsInitHostCPUModel(qemuCaps, caps);
ret = 0;
cleanup:
@@ -4036,7 +4039,7 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps,
virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0)
goto error;
- virQEMUCapsInitHostCPUModel(qemuCaps, &caps->host);
+ virQEMUCapsInitHostCPUModel(qemuCaps, caps);
}
cleanup:
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index 22c5a8a..fab2c2a 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -64,5 +64,5 @@ virQEMUCapsSetArch(virQEMUCapsPtr qemuCaps,
void
virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
- virCapsHostPtr host);
+ virCapsPtr caps);
#endif
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 0af71a1..4b9ecb8 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -357,7 +357,7 @@ testUpdateQEMUCaps(const struct testInfo *info,
if (testAddCPUModels(info->qemuCaps, info->skipLegacyCPUs) < 0)
goto cleanup;
- virQEMUCapsInitHostCPUModel(info->qemuCaps, &caps->host);
+ virQEMUCapsInitHostCPUModel(info->qemuCaps, caps);
virQEMUCapsFilterByMachineType(info->qemuCaps, vm->def->os.machine);
--
2.10.0
8 years, 1 month
[libvirt] [PATCH v2 0/8] Pass the path of compress program (redo)
by John Ferlan
v1: http://www.redhat.com/archives/libvir-list/2016-September/msg00971.html
Changes in v2:
1. Create a patch 5 which alters the qemuGetCompressionProgram to take a
new const char * parameter which will be used in the warning message
as the %s image format "style" (dump, save, snapshot) for both messages.
Also removed the unnecessary translated message marker _() for the
VIR_WARN message.
2. Alter former patch 5 to pass the style ("save" or "snapshot") as an
argument for the altered virReportError messages which now will take
a parameter that describe their style. For one message it keeps it
constant, for the other it adds the style into the message.
3. Alter former patches 6 and 7 to account for the new argument (no real
changes, just handling merge conflicts).
(from patch 1's cover)
Rather than try to describe what I was thinking about for the passing
the compress program directly series from Chen Hanxiao:
http://www.redhat.com/archives/libvir-list/2016-September/msg00677.html
and
http://www.redhat.com/archives/libvir-list/2016-August/msg01237.html
I took the liberty of creating my own set of patches which should end
in the more or less same result.
The primary benefit is not calling virFileInPath twice since we already
get it at least once for the various compressed program callers, let's
pass what we originally found.
John Ferlan (8):
qemu: Move getCompressionType
qemu: Adjust doCoreDump to call getCompressionType
qemu: Introduce helper qemuGetCompressionProgram
qemu: Remove getCompressionType
qemu: Alter qemuGetCompressionProgram warning message
qemu: Use qemuGetCompressionProgram for error paths
qemu: Remove qemuCompressProgramAvailable
qemu: Get/return compressedpath program
src/qemu/qemu_driver.c | 241 ++++++++++++++++++++++++-------------------------
1 file changed, 117 insertions(+), 124 deletions(-)
--
2.7.4
8 years, 1 month
[libvirt] [PATCH] libxl: find virDomainObj in libxlDomainShutdownThread
by Jim Fehlig
libxl events are delivered to libvirt via the libxlDomainEventHandler
callback registered with libxl. Documenation in
$xensrc/tools/libxl/libxl_event.h states that the callback "may occur
on any thread in which the application calls libxl". This can result
in deadlock since many of the libvirt callees of libxl hold a lock on
the virDomainObj they are working on. When the callback is invoked, it
attempts to find a virDomainObj corresponding to the domain ID provided
by libxl. Searching the domain obj list results in locking each obj
before checking if it is active, and its ID equals the requested ID.
Deadlock is possible when attempting to lock an obj that is already
locked further up the call stack. Indeed, Max Ustermann reported an
instance of this deadlock
https://www.redhat.com/archives/libvir-list/2015-November/msg00130.html
Guido Rossmueller also recently stumbled across it
https://www.redhat.com/archives/libvir-list/2016-September/msg00287.html
Fix the deadlock by moving the lookup of virDomainObj to the
libxlDomainShutdownThread. After this patch, libxl events are
enqueued on the libvirt side and processed by dedicated thread,
avoiding the described deadlock.
Reported-by: Max Ustermann <ustermann78(a)web.de>
Reported-by: Guido Rossmueller <Guido.Rossmueller(a)gdata.de>
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
Essentially this is a V2 of
https://www.redhat.com/archives/libvir-list/2015-November/msg00520.html
But that patch is nearly a year old and "V2" takes a completely
different (and IMO much better) approach to fixing the deadlock.
src/libxl/libxl_domain.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 43f4a7f..a472751 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -421,7 +421,6 @@ virDomainDefParserConfig libxlDomainDefParserConfig = {
struct libxlShutdownThreadInfo
{
libxlDriverPrivatePtr driver;
- virDomainObjPtr vm;
libxl_event *event;
};
@@ -430,7 +429,7 @@ static void
libxlDomainShutdownThread(void *opaque)
{
struct libxlShutdownThreadInfo *shutdown_info = opaque;
- virDomainObjPtr vm = shutdown_info->vm;
+ virDomainObjPtr vm = NULL;
libxl_event *ev = shutdown_info->event;
libxlDriverPrivatePtr driver = shutdown_info->driver;
virObjectEventPtr dom_event = NULL;
@@ -439,6 +438,12 @@ libxlDomainShutdownThread(void *opaque)
cfg = libxlDriverConfigGet(driver);
+ vm = virDomainObjListFindByIDRef(driver->domains, ev->domid);
+ if (!vm) {
+ VIR_INFO("Received event for unknown domain ID %d", ev->domid);
+ goto cleanup;
+ }
+
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
@@ -547,7 +552,6 @@ void
libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
{
libxlDriverPrivatePtr driver = data;
- virDomainObjPtr vm = NULL;
libxl_shutdown_reason xl_reason = event->u.domain_shutdown.shutdown_reason;
struct libxlShutdownThreadInfo *shutdown_info = NULL;
virThread thread;
@@ -565,12 +569,6 @@ libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
if (xl_reason == LIBXL_SHUTDOWN_REASON_SUSPEND)
goto error;
- vm = virDomainObjListFindByIDRef(driver->domains, event->domid);
- if (!vm) {
- VIR_INFO("Received event for unknown domain ID %d", event->domid);
- goto error;
- }
-
/*
* Start a thread to handle shutdown. We don't want to be tying up
* libxl's event machinery by doing a potentially lengthy shutdown.
@@ -579,7 +577,6 @@ libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
goto error;
shutdown_info->driver = driver;
- shutdown_info->vm = vm;
shutdown_info->event = (libxl_event *)event;
if (virThreadCreate(&thread, false, libxlDomainShutdownThread,
shutdown_info) < 0) {
@@ -591,7 +588,7 @@ libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
}
/*
- * VM is unlocked and libxl_event freed in shutdown thread
+ * libxlShutdownThreadInfo and libxl_event are freed in shutdown thread
*/
return;
@@ -600,7 +597,6 @@ libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
/* Cast away any const */
libxl_event_free(cfg->ctx, (libxl_event *)event);
virObjectUnref(cfg);
- virDomainObjEndAPI(&vm);
VIR_FREE(shutdown_info);
}
--
2.6.6
8 years, 1 month