[libvirt] [PATCH 00/10] qemu: clean up formatting of networked disk sources
by Peter Krempa
Few cleanups I made to cleanup the def->JSON generator for qemu disk sources.
Peter Krempa (10):
qemu: command: Set port number only for TCP transport
util: Extract helper to retrieve default port for network protocol
util: storage: Fill in default ports for gluster and iscsi
conf: Pre-fill default ports when parsing network disk sources
qemu: command: Remove default port numbers for NBD and GLUSTER
qemu: command: Call qemuGetDriveSourceProps only if necessary
qemu: Move qemuGetDriveSourceProps to qemu_block
qemu: block: Refactor and rename qemuGetDriveSourceProps
qemu: block: refactor and rename qemuBuildGlusterDriveJSONHosts
qemu: block: rename and refactor qemuBuildGlusterDriveJSON
po/POTFILES.in | 1 +
src/conf/domain_conf.c | 3 +
src/libvirt_private.syms | 1 +
src/qemu/qemu_block.c | 156 ++++++++++++++
src/qemu/qemu_block.h | 3 +
src/qemu/qemu_command.c | 229 ++++-----------------
src/util/virstoragefile.c | 65 ++++++
src/util/virstoragefile.h | 4 +
.../generic-disk-network-http.xml | 4 +-
.../qemuxml2xmlout-disk-drive-network-gluster.xml | 2 +-
10 files changed, 273 insertions(+), 195 deletions(-)
--
2.12.2
7 years, 5 months
[libvirt] [PATCH 0/2] qemu: Add AAVMF32 to the list of known UEFIs
by dann frazier
v2: Add a virt-aa-helper-test case.
dann frazier (2):
qemu: Add AAVMF32 to the list of known UEFIs
virt-aa-helper-test: Add test for aarch32 UEFI image path
src/qemu/qemu_conf.c | 12 ++++++++----
tests/virt-aa-helper-test | 1 +
2 files changed, 9 insertions(+), 4 deletions(-)
--
2.13.2
7 years, 5 months
[libvirt] [PATCH 1/3] leasetime support for <dhcp> globally
by aruiz@gnome.org
From: Alberto Ruiz <aruiz(a)gnome.org>
---
docs/schemas/basictypes.rng | 16 +++++
docs/schemas/network.rng | 8 +++
src/conf/network_conf.c | 78 ++++++++++++++++++++++-
src/conf/network_conf.h | 3 +-
src/network/bridge_driver.c | 49 +++++++++++++-
tests/networkxml2confdata/leasetime-days.conf | 17 +++++
tests/networkxml2confdata/leasetime-days.xml | 18 ++++++
tests/networkxml2confdata/leasetime-hours.conf | 17 +++++
tests/networkxml2confdata/leasetime-hours.xml | 18 ++++++
tests/networkxml2confdata/leasetime-infinite.conf | 17 +++++
tests/networkxml2confdata/leasetime-infinite.xml | 18 ++++++
tests/networkxml2confdata/leasetime-minutes.conf | 17 +++++
tests/networkxml2confdata/leasetime-minutes.xml | 18 ++++++
tests/networkxml2confdata/leasetime-seconds.conf | 17 +++++
tests/networkxml2confdata/leasetime-seconds.xml | 18 ++++++
tests/networkxml2confdata/leasetime.conf | 17 +++++
tests/networkxml2confdata/leasetime.xml | 18 ++++++
tests/networkxml2conftest.c | 7 ++
18 files changed, 368 insertions(+), 3 deletions(-)
create mode 100644 tests/networkxml2confdata/leasetime-days.conf
create mode 100644 tests/networkxml2confdata/leasetime-days.xml
create mode 100644 tests/networkxml2confdata/leasetime-hours.conf
create mode 100644 tests/networkxml2confdata/leasetime-hours.xml
create mode 100644 tests/networkxml2confdata/leasetime-infinite.conf
create mode 100644 tests/networkxml2confdata/leasetime-infinite.xml
create mode 100644 tests/networkxml2confdata/leasetime-minutes.conf
create mode 100644 tests/networkxml2confdata/leasetime-minutes.xml
create mode 100644 tests/networkxml2confdata/leasetime-seconds.conf
create mode 100644 tests/networkxml2confdata/leasetime-seconds.xml
create mode 100644 tests/networkxml2confdata/leasetime.conf
create mode 100644 tests/networkxml2confdata/leasetime.xml
diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng
index 1b4f980e7..8a76c235a 100644
--- a/docs/schemas/basictypes.rng
+++ b/docs/schemas/basictypes.rng
@@ -518,4 +518,20 @@
</element>
</define>
+ <define name="leaseTimeUnit">
+ <choice>
+ <value>seconds</value>
+ <value>minutes</value>
+ <value>hours</value>
+ <value>days</value>
+ </choice>
+ </define>
+
+ <define name="leaseTime">
+ <data type="long">
+ <param name="minInclusive">-1</param>
+ <param name="maxInclusive">4294967295</param>
+ </data>
+ </define>
+
</grammar>
diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng
index 1a18e64b2..4b8056ab6 100644
--- a/docs/schemas/network.rng
+++ b/docs/schemas/network.rng
@@ -340,6 +340,14 @@
<!-- Define the range(s) of IP addresses that the DHCP
server should hand out -->
<element name="dhcp">
+ <optional>
+ <element name="leasetime">
+ <optional>
+ <attribute name="unit"><ref name="leaseTimeUnit"/></attribute>
+ </optional>
+ <ref name="leaseTime"/>
+ </element>
+ </optional>
<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 aa397768c..6f051493f 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -30,6 +30,8 @@
#include <fcntl.h>
#include <string.h>
#include <dirent.h>
+#include <stdlib.h>
+#include <inttypes.h>
#include "virerror.h"
#include "datatypes.h"
@@ -1031,12 +1033,82 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
return ret;
}
+static int64_t
+virNetworkDHCPDefGetLeaseTime (xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
+ bool *error)
+{
+ int64_t multiplier, result = -1;
+ char *leaseString, *leaseUnit;
+ xmlNodePtr save;
+
+ *error = 0;
+
+ save = ctxt->node;
+ ctxt->node = node;
+
+ leaseString = virXPathString ("string(./leasetime/text())", ctxt);
+ leaseUnit = virXPathString ("string(./leasetime/@unit)", ctxt);
+
+ /* If value is not present we set the value to -2 */
+ if (leaseString == NULL) {
+ result = -2;
+ goto cleanup;
+ }
+
+ if (leaseUnit == NULL || strcmp (leaseUnit, "seconds") == 0)
+ multiplier = 1;
+ else if (strcmp (leaseUnit, "minutes") == 0)
+ multiplier = 60;
+ else if (strcmp (leaseUnit, "hours") == 0)
+ multiplier = 60 * 60;
+ else if (strcmp (leaseUnit, "days") == 0)
+ multiplier = 60 * 60 * 24;
+ else {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("invalid value for unit parameter in <leasetime> element found in <dhcp> network, "
+ "only 'seconds', 'minutes', 'hours' or 'days' are valid: %s"),
+ leaseUnit);
+ *error = 1;
+ goto cleanup;
+ }
+
+ errno = 0;
+ result = (int64_t) strtoll((const char*)leaseString, NULL, 10);
+
+ /* Report any errors parsing the string */
+ if (errno != 0) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("<leasetime> value could not be converted to a signed integer: %s"),
+ leaseString);
+ *error = 1;
+ goto cleanup;
+ }
+
+ result = result * multiplier;
+
+ if (result > UINT32_MAX) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("<leasetime> value cannot be greater than the equivalent of %" PRIo32 " seconds : %" PRId64),
+ UINT32_MAX, result);
+ *error = 1;
+ }
+
+cleanup:
+ VIR_FREE(leaseString);
+ VIR_FREE(leaseUnit);
+ ctxt->node = save;
+ return result;
+}
+
static int
virNetworkDHCPDefParseXML(const char *networkName,
xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
virNetworkIPDefPtr def)
{
int ret = -1;
+ bool error;
xmlNodePtr cur;
virSocketAddrRange range;
virNetworkDHCPHostDef host;
@@ -1044,6 +1116,10 @@ virNetworkDHCPDefParseXML(const char *networkName,
memset(&range, 0, sizeof(range));
memset(&host, 0, sizeof(host));
+ def->leasetime = virNetworkDHCPDefGetLeaseTime (node, ctxt, &error);
+ if (error)
+ goto cleanup;
+
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE &&
@@ -1607,7 +1683,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")) {
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 3b227db6f..f7557f581 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -170,7 +170,8 @@ struct _virNetworkIPDef {
char *tftproot;
char *bootfile;
virSocketAddr bootserver;
- };
+ int64_t leasetime;
+};
typedef struct _virNetworkForwardIfDef virNetworkForwardIfDef;
typedef virNetworkForwardIfDef *virNetworkForwardIfDefPtr;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 7b99acafa..e51e469c8 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -41,6 +41,8 @@
#include <sys/ioctl.h>
#include <net/if.h>
#include <dirent.h>
+#include <inttypes.h>
+#include <stdint.h>
#if HAVE_SYS_SYSCTL_H
# include <sys/sysctl.h>
#endif
@@ -903,6 +905,40 @@ networkBuildDnsmasqHostsList(dnsmasqContext *dctx,
return 0;
}
+/* translates the leasetime value into a dnsmasq configuration string for dhcp-range/host */
+static char *
+networkDnsmasqConfLeaseValueToString (int64_t leasetime)
+{
+ char *result = NULL;
+ virBuffer leasebuf = VIR_BUFFER_INITIALIZER;
+
+ /* Leasetime parameter set on the XML */
+ /* Less than -1 means there was no value set */
+ if (leasetime < -1) {
+ virBufferAsprintf(&leasebuf, "%s", "");
+ }
+ /* -1 means no expiration */
+ else if (leasetime == -1)
+ virBufferAsprintf(&leasebuf, ",infinite");
+ /* Minimum expiry value is 120 */
+ /* TODO: Discuss if we should up as we do here or just forward whatever value to dnsmasq */
+ else if (leasetime < 120)
+ virBufferAsprintf(&leasebuf, ",120");
+ /* DHCP value for lease time is a unsigned four octect integer */
+ else if (leasetime <= UINT32_MAX)
+ virBufferAsprintf(&leasebuf, ",%" PRId64, leasetime);
+ /* TODO: Discuss the use of "deprecated" for ipv6*/
+ /* TODO: Discuss what is the default value that we want as dnsmasq's is 1 hour */
+ /* TODO: Discuss what to do if value exceeds maximum, use default value for now */
+ else {
+ virBufferAsprintf(&leasebuf, "%s", "");
+ }
+
+ result = virBufferContentAndReset(&leasebuf);
+ virBufferFreeAndReset (&leasebuf);
+
+ return result;
+}
int
networkDnsmasqConfContents(virNetworkObjPtr network,
@@ -1213,6 +1249,7 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
}
for (r = 0; r < ipdef->nranges; r++) {
int thisRange;
+ char *leasestr;
if (!(saddr = virSocketAddrFormat(&ipdef->ranges[r].start)) ||
!(eaddr = virSocketAddrFormat(&ipdef->ranges[r].end)))
@@ -1220,12 +1257,22 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
virBufferAsprintf(&configbuf, "dhcp-range=%s,%s",
saddr, eaddr);
- if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6))
+
+ /* Add ipv6 prefix length parameter if needed */
+ if (ipdef == ipv6def)
virBufferAsprintf(&configbuf, ",%d", prefix);
+
+ leasestr = networkDnsmasqConfLeaseValueToString (ipdef->leasetime);
+ if (!leasestr)
+ goto cleanup;
+ virBufferAsprintf(&configbuf, "%s", leasestr);
+
+ /* Add the newline */
virBufferAddLit(&configbuf, "\n");
VIR_FREE(saddr);
VIR_FREE(eaddr);
+ VIR_FREE(leasestr);
thisRange = virSocketAddrGetRange(&ipdef->ranges[r].start,
&ipdef->ranges[r].end,
&ipdef->address,
diff --git a/tests/networkxml2confdata/leasetime-days.conf b/tests/networkxml2confdata/leasetime-days.conf
new file mode 100644
index 000000000..9501e2f8a
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-days.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 default
+## or other application using the libvirt API.
+##
+## dnsmasq conf file created by libvirt
+strict-order
+except-interface=lo
+bind-dynamic
+interface=virbr0
+dhcp-range=192.168.122.2,192.168.122.254,86400
+dhcp-no-override
+dhcp-range=2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff,64,86400
+dhcp-lease-max=493
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+enable-ra
diff --git a/tests/networkxml2confdata/leasetime-days.xml b/tests/networkxml2confdata/leasetime-days.xml
new file mode 100644
index 000000000..b990b4d68
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-days.xml
@@ -0,0 +1,18 @@
+<network>
+ <name>default</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward dev='eth1' mode='nat'/>
+ <bridge name='virbr0' stp='on' delay='0'/>
+ <ip address='192.168.122.1' netmask='255.255.255.0'>
+ <dhcp>
+ <leasetime unit="days">1</leasetime>
+ <range start='192.168.122.2' end='192.168.122.254'/>
+ </dhcp>
+ </ip>
+ <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+ <dhcp>
+ <leasetime unit="days">1</leasetime>
+ <range start='2001:db8:ac10:fd01::1:10' end='2001:db8:ac10:fd01::1:ff'/>
+ </dhcp>
+ </ip>
+</network>
diff --git a/tests/networkxml2confdata/leasetime-hours.conf b/tests/networkxml2confdata/leasetime-hours.conf
new file mode 100644
index 000000000..021a769bc
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-hours.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 default
+## or other application using the libvirt API.
+##
+## dnsmasq conf file created by libvirt
+strict-order
+except-interface=lo
+bind-dynamic
+interface=virbr0
+dhcp-range=192.168.122.2,192.168.122.254,3600
+dhcp-no-override
+dhcp-range=2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff,64,3600
+dhcp-lease-max=493
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+enable-ra
diff --git a/tests/networkxml2confdata/leasetime-hours.xml b/tests/networkxml2confdata/leasetime-hours.xml
new file mode 100644
index 000000000..3b9609601
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-hours.xml
@@ -0,0 +1,18 @@
+<network>
+ <name>default</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward dev='eth1' mode='nat'/>
+ <bridge name='virbr0' stp='on' delay='0'/>
+ <ip address='192.168.122.1' netmask='255.255.255.0'>
+ <dhcp>
+ <leasetime unit="hours">1</leasetime>
+ <range start='192.168.122.2' end='192.168.122.254'/>
+ </dhcp>
+ </ip>
+ <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+ <dhcp>
+ <leasetime unit="hours">1</leasetime>
+ <range start='2001:db8:ac10:fd01::1:10' end='2001:db8:ac10:fd01::1:ff'/>
+ </dhcp>
+ </ip>
+</network>
diff --git a/tests/networkxml2confdata/leasetime-infinite.conf b/tests/networkxml2confdata/leasetime-infinite.conf
new file mode 100644
index 000000000..cc21135de
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-infinite.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 default
+## or other application using the libvirt API.
+##
+## dnsmasq conf file created by libvirt
+strict-order
+except-interface=lo
+bind-dynamic
+interface=virbr0
+dhcp-range=192.168.122.2,192.168.122.254,infinite
+dhcp-no-override
+dhcp-range=2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff,64,infinite
+dhcp-lease-max=493
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+enable-ra
diff --git a/tests/networkxml2confdata/leasetime-infinite.xml b/tests/networkxml2confdata/leasetime-infinite.xml
new file mode 100644
index 000000000..bc8740ee6
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-infinite.xml
@@ -0,0 +1,18 @@
+<network>
+ <name>default</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward dev='eth1' mode='nat'/>
+ <bridge name='virbr0' stp='on' delay='0'/>
+ <ip address='192.168.122.1' netmask='255.255.255.0'>
+ <dhcp>
+ <leasetime>-1</leasetime>
+ <range start='192.168.122.2' end='192.168.122.254'/>
+ </dhcp>
+ </ip>
+ <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+ <dhcp>
+ <leasetime>-1</leasetime>
+ <range start='2001:db8:ac10:fd01::1:10' end='2001:db8:ac10:fd01::1:ff'/>
+ </dhcp>
+ </ip>
+</network>
diff --git a/tests/networkxml2confdata/leasetime-minutes.conf b/tests/networkxml2confdata/leasetime-minutes.conf
new file mode 100644
index 000000000..db688951b
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-minutes.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 default
+## or other application using the libvirt API.
+##
+## dnsmasq conf file created by libvirt
+strict-order
+except-interface=lo
+bind-dynamic
+interface=virbr0
+dhcp-range=192.168.122.2,192.168.122.254,300
+dhcp-no-override
+dhcp-range=2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff,64,300
+dhcp-lease-max=493
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+enable-ra
diff --git a/tests/networkxml2confdata/leasetime-minutes.xml b/tests/networkxml2confdata/leasetime-minutes.xml
new file mode 100644
index 000000000..e7a27afe6
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-minutes.xml
@@ -0,0 +1,18 @@
+<network>
+ <name>default</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward dev='eth1' mode='nat'/>
+ <bridge name='virbr0' stp='on' delay='0'/>
+ <ip address='192.168.122.1' netmask='255.255.255.0'>
+ <dhcp>
+ <leasetime unit="minutes">5</leasetime>
+ <range start='192.168.122.2' end='192.168.122.254'/>
+ </dhcp>
+ </ip>
+ <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+ <dhcp>
+ <leasetime unit="minutes">5</leasetime>
+ <range start='2001:db8:ac10:fd01::1:10' end='2001:db8:ac10:fd01::1:ff'/>
+ </dhcp>
+ </ip>
+</network>
diff --git a/tests/networkxml2confdata/leasetime-seconds.conf b/tests/networkxml2confdata/leasetime-seconds.conf
new file mode 100644
index 000000000..635896b29
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-seconds.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 default
+## or other application using the libvirt API.
+##
+## dnsmasq conf file created by libvirt
+strict-order
+except-interface=lo
+bind-dynamic
+interface=virbr0
+dhcp-range=192.168.122.2,192.168.122.254,125
+dhcp-no-override
+dhcp-range=2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff,64,125
+dhcp-lease-max=493
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+enable-ra
diff --git a/tests/networkxml2confdata/leasetime-seconds.xml b/tests/networkxml2confdata/leasetime-seconds.xml
new file mode 100644
index 000000000..56b07f8ae
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime-seconds.xml
@@ -0,0 +1,18 @@
+<network>
+ <name>default</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward dev='eth1' mode='nat'/>
+ <bridge name='virbr0' stp='on' delay='0'/>
+ <ip address='192.168.122.1' netmask='255.255.255.0'>
+ <dhcp>
+ <leasetime unit="seconds">125</leasetime>
+ <range start='192.168.122.2' end='192.168.122.254'/>
+ </dhcp>
+ </ip>
+ <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+ <dhcp>
+ <leasetime unit="seconds">125</leasetime>
+ <range start='2001:db8:ac10:fd01::1:10' end='2001:db8:ac10:fd01::1:ff'/>
+ </dhcp>
+ </ip>
+</network>
diff --git a/tests/networkxml2confdata/leasetime.conf b/tests/networkxml2confdata/leasetime.conf
new file mode 100644
index 000000000..72a2f6926
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime.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 default
+## or other application using the libvirt API.
+##
+## dnsmasq conf file created by libvirt
+strict-order
+except-interface=lo
+bind-dynamic
+interface=virbr0
+dhcp-range=192.168.122.2,192.168.122.254,122
+dhcp-no-override
+dhcp-range=2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff,64,121
+dhcp-lease-max=493
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+enable-ra
diff --git a/tests/networkxml2confdata/leasetime.xml b/tests/networkxml2confdata/leasetime.xml
new file mode 100644
index 000000000..fdbb15fc0
--- /dev/null
+++ b/tests/networkxml2confdata/leasetime.xml
@@ -0,0 +1,18 @@
+<network>
+ <name>default</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward dev='eth1' mode='nat'/>
+ <bridge name='virbr0' stp='on' delay='0'/>
+ <ip address='192.168.122.1' netmask='255.255.255.0'>
+ <dhcp>
+ <leasetime>122</leasetime>
+ <range start='192.168.122.2' end='192.168.122.254'/>
+ </dhcp>
+ </ip>
+ <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+ <dhcp>
+ <leasetime>121</leasetime>
+ <range start='2001:db8:ac10:fd01::1:10' end='2001:db8:ac10:fd01::1:ff'/>
+ </dhcp>
+ </ip>
+</network>
diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c
index 65a0e3218..223a56f54 100644
--- a/tests/networkxml2conftest.c
+++ b/tests/networkxml2conftest.c
@@ -129,6 +129,13 @@ mymain(void)
DO_TEST("dhcp6-network", dhcpv6);
DO_TEST("dhcp6-nat-network", dhcpv6);
DO_TEST("dhcp6host-routed-network", dhcpv6);
+ DO_TEST("leasetime", dhcpv6);
+ DO_TEST("leasetime-seconds", dhcpv6);
+ DO_TEST("leasetime-hours", dhcpv6);
+ DO_TEST("leasetime-minutes", dhcpv6);
+ DO_TEST("leasetime-hours", dhcpv6);
+ DO_TEST("leasetime-days", dhcpv6);
+ DO_TEST("leasetime-infinite", dhcpv6);
virObjectUnref(dhcpv6);
virObjectUnref(full);
--
2.13.0
7 years, 5 months
[libvirt] Regarding docs for Adding new Hypervisor support
by Rohit Sakala
Hello all,
I would start to work on adding z/vm hypervisor to libvirt. I am currently
going through libvirt source code and found that I need to add a new driver
implementation for z/VM hypervisor. Can you please let me know the best way
to add a driver to libvirt. Basically looking for a head start on which
part of the code look for ? and any related docs ?
Regards,
*Venkata Krishna Rohit Sakala*
B.Tech 4th Year,
International Institute of Information Technology Hyderabad, India.
Mobile:
*+91-9666255517*
Website: https://researchweb.iiit.ac.in/~rohit.sakala/
ᐧ
7 years, 5 months
[libvirt] [PATCH] qemu: Default hwclock source for sPAPR to RTC
by Kothapally Madhu Pavan
QEMU fails to launch a sPAPR guest with clock sources other that RTC.
Internally qemu only uses RTC timer for hwclock. This patch reports
the right error message instead of qemu erroring out when any other
timer other than RTC is used.
Signed-off-by: Kothapally Madhu Pavan <kmp(a)linux.vnet.ibm.com>
---
src/qemu/qemu_command.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c53ab97..31561ce 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6440,6 +6440,15 @@ qemuBuildClockCommandLine(virCommandPtr cmd,
break;
case VIR_DOMAIN_TIMER_NAME_PIT:
+ /* Only RTC timer is supported as hwclock for sPAPR machines */
+ if (ARCH_IS_PPC64(def->os.arch)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unsupported clock timer '%s' for '%s' architecture"),
+ virDomainTimerNameTypeToString(def->clock.timers[i]->name),
+ virArchToString(def->os.arch));
+ return -1;
+ }
+
switch (def->clock.timers[i]->tickpolicy) {
case -1:
case VIR_DOMAIN_TIMER_TICKPOLICY_DELAY:
@@ -6483,13 +6492,21 @@ qemuBuildClockCommandLine(virCommandPtr cmd,
break;
case VIR_DOMAIN_TIMER_NAME_HPET:
+ /* Only RTC timer is supported as hwclock for sPAPR machines */
+ if (ARCH_IS_PPC64(def->os.arch)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unsupported clock timer '%s' for '%s' architecture"),
+ virDomainTimerNameTypeToString(def->clock.timers[i]->name),
+ virArchToString(def->os.arch));
+ return -1;
+ }
+
/* the only meaningful attribute for hpet is "present". If
* present is -1, that means it wasn't specified, and
* should be left at the default for the
* hypervisor. "default" when -no-hpet exists is "yes",
* and when -no-hpet doesn't exist is "no". "confusing"?
* "yes"! */
-
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NO_HPET)) {
if (def->clock.timers[i]->present == 0)
virCommandAddArg(cmd, "-no-hpet");
@@ -7047,6 +7064,15 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
for (i = 0; i < def->clock.ntimers; i++) {
virDomainTimerDefPtr timer = def->clock.timers[i];
+ /* Only RTC timer is supported as hwclock for sPAPR machines */
+ if (ARCH_IS_PPC64(def->os.arch) && timer->name != VIR_DOMAIN_TIMER_NAME_RTC) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unsupported clock timer '%s' for '%s' architecture"),
+ virDomainTimerNameTypeToString(def->clock.timers[i]->name),
+ virArchToString(def->os.arch));
+ return -1;
+ }
+
if (timer->name == VIR_DOMAIN_TIMER_NAME_KVMCLOCK &&
timer->present != -1) {
virBufferAsprintf(&buf, "%s,%ckvmclock",
--
1.8.3.1
7 years, 5 months
[libvirt] [PATCH] Rewrite the way mockable functions are handled.
by Daniel P. Berrange
Currently any mockable functions are marked with attributes
noinline, noclone and weak. This prevents the compiler from
optimizing away the impl of these functions.
It has an unfortunate side effect with the libtool convenience
libraries, if executables directly link to them. For example
virlockd, virlogd both link to libvirt_util.la When this is
done, the linker does not consider weak symbols as being
undefined, so it never copies them into the final executable.
In this new approach, we stop annotating the headers entirely.
Instead we create a weak function alias in the source.
int fooImpl(void) {
..the real code..
}
int foo(void) __attribute__((noinline, noclone, weak, alias("fooImpl"))
If any functions in the same file call "foo", this prevents the
optimizer from inlining any part of fooImpl. When linking to the
libtool convenience static library, we also get all the symbols
present. Finally the test suite can just directly define a
'foo' function in its source, removing the need to use LD_PRELOAD
(though removal of LD_PRELOADS is left for a future patch).
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
build-aux/mock-noinline.pl | 35 ++++++-------
src/internal.h | 59 +++++++++++----------
src/qemu/qemu_capabilities.c | 9 ++--
src/qemu/qemu_capspriv.h | 2 +-
src/rpc/virnetsocket.c | 48 ++++++++++-------
src/rpc/virnetsocket.h | 6 +--
src/util/vircommand.c | 6 ++-
src/util/vircommand.h | 2 +-
src/util/vircrypto.c | 5 +-
src/util/vircrypto.h | 2 +-
src/util/virfile.c | 5 +-
src/util/virfile.h | 2 +-
src/util/virhostcpu.c | 10 ++--
src/util/virhostcpu.h | 4 +-
src/util/virmacaddr.c | 6 ++-
src/util/virmacaddr.h | 2 +-
src/util/virnetdev.c | 23 +++++----
src/util/virnetdev.h | 9 ++--
src/util/virnetdevip.c | 9 ++--
src/util/virnetdevip.h | 2 +-
src/util/virnetdevopenvswitch.c | 8 +--
src/util/virnetdevopenvswitch.h | 2 +-
src/util/virnetdevtap.c | 45 ++++++++--------
src/util/virnetdevtap.h | 6 +--
src/util/virnuma.c | 111 +++++++++++++++++++++++-----------------
src/util/virnuma.h | 16 +++---
src/util/virrandom.c | 18 ++++---
src/util/virrandom.h | 6 +--
src/util/virscsi.c | 13 ++---
src/util/virscsi.h | 2 +-
src/util/virscsivhost.c | 5 +-
src/util/virscsivhost.h | 2 +-
src/util/virtpm.c | 5 +-
src/util/virtpm.h | 2 +-
src/util/virutil.c | 33 +++++++-----
src/util/virutil.h | 10 ++--
src/util/viruuid.c | 5 +-
src/util/viruuid.h | 2 +-
38 files changed, 296 insertions(+), 241 deletions(-)
diff --git a/build-aux/mock-noinline.pl b/build-aux/mock-noinline.pl
index 2745d4b..1d39300 100644
--- a/build-aux/mock-noinline.pl
+++ b/build-aux/mock-noinline.pl
@@ -1,28 +1,28 @@
#!/usr/bin/perl
-my %noninlined;
+my %mockable;
my %mocked;
# Functions in public header don't get the noinline annotation
# so whitelist them here
-$noninlined{"virEventAddTimeout"} = 1;
+$mockable{"virEventAddTimeout"} = 1;
foreach my $arg (@ARGV) {
- if ($arg =~ /\.h$/) {
- #print "Scan header $arg\n";
- &scan_annotations($arg);
- } elsif ($arg =~ /mock\.c$/) {
+ if ($arg =~ /mock\.c$/) {
#print "Scan mock $arg\n";
&scan_overrides($arg);
+ } elsif ($arg =~ /\.c$/) {
+ #print "Scan source $arg\n";
+ &scan_annotations($arg);
}
}
my $warned = 0;
foreach my $func (keys %mocked) {
- next if exists $noninlined{$func};
+ next if exists $mockable{$func};
$warned++;
- print STDERR "$func is mocked at $mocked{$func} but missing noinline annotation\n";
+ print STDERR "$func is mocked at $mocked{$func} but missing VIR_MOCKABLE impl\n";
}
exit $warned ? 1 : 0;
@@ -34,19 +34,16 @@ sub scan_annotations {
open FH, $file or die "cannot read $file: $!";
my $func;
+ my $mockable = 0;
while (<FH>) {
- if (/^\s*(\w+)\(/ || /^(?:\w+\*?\s+)+(?:\*\s*)?(\w+)\(/) {
- my $name = $1;
- if ($name !~ /ATTRIBUTE/) {
- $func = $name;
- }
- } elsif (/^\s*$/) {
- $func = undef;
- }
- if (/ATTRIBUTE_MOCKABLE/) {
- if (defined $func) {
- $noninlined{$func} = 1;
+ if (/^VIR_MOCKABLE/) {
+ $mockable = 1;
+ } elsif ($mockable) {
+ if (/^\s*(\w+),$/) {
+ my $func = $1;
+ $mockable{$func} = 1;
}
+ $mockable = 0;
}
}
diff --git a/src/internal.h b/src/internal.h
index edc3587..e34338e 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -113,33 +113,6 @@
# endif
/**
- * ATTRIBUTE_MOCKABLE:
- *
- * Ensure that the symbol can be overridden in a mock
- * library preload. This implies a number of attributes
- *
- * - noinline: prevents the body being inlined to
- * callers,
- * - noclone: prevents specialized copies of the
- * function body being created for different
- * callers
- * - weak: prevents the compiler making optimizations
- * such as constant return value propagation
- *
- */
-# ifndef ATTRIBUTE_MOCKABLE
-# if defined(WIN32)
-# define ATTRIBUTE_MOCKABLE
-# else
-# if __GNUC_PREREQ(4, 5)
-# define ATTRIBUTE_MOCKABLE __attribute__((__noinline__, __noclone__, __weak__))
-# else
-# define ATTRIBUTE_MOCKABLE __attribute__((__noinline__, __weak__))
-# endif
-# endif
-# endif
-
-/**
* ATTRIBUTE_FMT_PRINTF
*
* Macro used to check printf like functions, if compiling
@@ -251,6 +224,38 @@
/*
+ * VIR_MOCKABLE(return type, func name, args...)
+ *
+ * Defines a function implementation that can be later overriden in
+ * the test suite
+ *
+ * NB, Win32 can't use 'weak' attribute because such symbols
+ * can't be marked exported in DLLs
+ *
+ * NB, the ${name}Impl function ought to be static, but that
+ * causes CLang to throw bogus errors about unused functions,
+ * despite there being an alias to it
+ */
+# ifdef WIN32
+# define VIR_MOCKABLE(ret, name, ...) \
+ ret name(__VA_ARGS__) __attribute__((noinline, noclone, __alias__(#name "Impl"))); \
+ ret name ## Impl (__VA_ARGS__); \
+ ret name ## Impl (__VA_ARGS__)
+# else
+# if __GNUC_PREREQ(4, 5)
+# define VIR_MOCKABLE(ret, name, ...) \
+ ret name(__VA_ARGS__) __attribute__((noinline, noclone, weak, __alias__(#name "Impl"))); \
+ ret name ## Impl (__VA_ARGS__); \
+ ret name ## Impl (__VA_ARGS__)
+# else
+# define VIR_MOCKABLE(ret, name, ...) \
+ ret name(__VA_ARGS__) __attribute__((noinline, weak, __alias__(#name "Impl"))); \
+ ret name ## Impl (__VA_ARGS__); \
+ ret name ## Impl (__VA_ARGS__)
+# endif
+# endif
+
+/*
* Use this when passing possibly-NULL strings to printf-a-likes.
*/
# define NULLSTR(s) ((s) ? (s) : "<null>")
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index db9f9b8..d4316bc 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1148,10 +1148,11 @@ virQEMUCapsInitGuestFromBinary(virCapsPtr caps,
}
-virCPUDefPtr
-virQEMUCapsProbeHostCPUForEmulator(virCapsPtr caps,
- virQEMUCapsPtr qemuCaps,
- virDomainVirtType type)
+VIR_MOCKABLE(virCPUDefPtr,
+ virQEMUCapsProbeHostCPUForEmulator,
+ virCapsPtr caps,
+ virQEMUCapsPtr qemuCaps,
+ virDomainVirtType type)
{
size_t nmodels;
char **models;
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index 6cc189e..a7c92fd 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -95,7 +95,7 @@ virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps,
virCPUDefPtr
virQEMUCapsProbeHostCPUForEmulator(virCapsPtr caps,
virQEMUCapsPtr qemuCaps,
- virDomainVirtType type) ATTRIBUTE_MOCKABLE;
+ virDomainVirtType type);
void
virQEMUCapsSetGICCapabilities(virQEMUCapsPtr qemuCaps,
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index d228c8a..db872bb 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -1425,11 +1425,13 @@ int virNetSocketGetPort(virNetSocketPtr sock)
#if defined(SO_PEERCRED)
-int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
- uid_t *uid,
- gid_t *gid,
- pid_t *pid,
- unsigned long long *timestamp)
+VIR_MOCKABLE(int,
+ virNetSocketGetUNIXIdentity,
+ virNetSocketPtr sock,
+ uid_t *uid,
+ gid_t *gid,
+ pid_t *pid,
+ unsigned long long *timestamp)
{
# if defined(HAVE_STRUCT_SOCKPEERCRED)
struct sockpeercred cr;
@@ -1482,11 +1484,13 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
# define VIR_SOL_PEERCRED 0
# endif
-int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
- uid_t *uid,
- gid_t *gid,
- pid_t *pid,
- unsigned long long *timestamp)
+VIR_MOCKABLE(int,
+ virNetSocketGetUNIXIdentity,
+ virNetSocketPtr sock,
+ uid_t *uid,
+ gid_t *gid,
+ pid_t *pid,
+ unsigned long long *timestamp)
{
struct xucred cr;
socklen_t cr_len = sizeof(cr);
@@ -1550,11 +1554,13 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
return ret;
}
#else
-int virNetSocketGetUNIXIdentity(virNetSocketPtr sock ATTRIBUTE_UNUSED,
- uid_t *uid ATTRIBUTE_UNUSED,
- gid_t *gid ATTRIBUTE_UNUSED,
- pid_t *pid ATTRIBUTE_UNUSED,
- unsigned long long *timestamp ATTRIBUTE_UNUSED)
+VIR_MOCKABLE(int,
+ virNetSocketGetUNIXIdentity,
+ virNetSocketPtr sock ATTRIBUTE_UNUSED,
+ uid_t *uid ATTRIBUTE_UNUSED,
+ gid_t *gid ATTRIBUTE_UNUSED,
+ pid_t *pid ATTRIBUTE_UNUSED,
+ unsigned long long *timestamp ATTRIBUTE_UNUSED)
{
/* XXX Many more OS support UNIX socket credentials we could port to. See dbus ....*/
virReportSystemError(ENOSYS, "%s",
@@ -1564,8 +1570,10 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock ATTRIBUTE_UNUSED,
#endif
#ifdef WITH_SELINUX
-int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
- char **context)
+VIR_MOCKABLE(int,
+ virNetSocketGetSELinuxContext,
+ virNetSocketPtr sock,
+ char **context)
{
security_context_t seccon = NULL;
int ret = -1;
@@ -1593,8 +1601,10 @@ int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
return ret;
}
#else
-int virNetSocketGetSELinuxContext(virNetSocketPtr sock ATTRIBUTE_UNUSED,
- char **context)
+VIR_MOCKABLE(int,
+ virNetSocketGetSELinuxContext,
+ virNetSocketPtr sock ATTRIBUTE_UNUSED,
+ char **context)
{
*context = NULL;
return 0;
diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h
index 3c2945e..1e75ee6 100644
--- a/src/rpc/virnetsocket.h
+++ b/src/rpc/virnetsocket.h
@@ -136,11 +136,9 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
uid_t *uid,
gid_t *gid,
pid_t *pid,
- unsigned long long *timestamp)
- ATTRIBUTE_MOCKABLE;
+ unsigned long long *timestamp);
int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
- char **context)
- ATTRIBUTE_MOCKABLE;
+ char **context);
int virNetSocketSetBlocking(virNetSocketPtr sock,
bool blocking);
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 60c1121..4ac0aa9 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -985,8 +985,9 @@ virCommandNewVAList(const char *binary, va_list list)
* be closed in the parent no later than Run/RunAsync/Free. The parent
* should cease using the @fd when this call completes
*/
-void
-virCommandPassFD(virCommandPtr cmd, int fd, unsigned int flags)
+VIR_MOCKABLE(void,
+ virCommandPassFD,
+ virCommandPtr cmd, int fd, unsigned int flags)
{
int ret = 0;
@@ -1012,6 +1013,7 @@ virCommandPassFD(virCommandPtr cmd, int fd, unsigned int flags)
}
}
+
/**
* virCommandPassListenFDs:
* @cmd: the command to modify
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index c042a53..99dcdeb 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -58,7 +58,7 @@ enum {
void virCommandPassFD(virCommandPtr cmd,
int fd,
- unsigned int flags) ATTRIBUTE_MOCKABLE;
+ unsigned int flags);
void virCommandPassListenFDs(virCommandPtr cmd);
diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c
index 48b04fc..13cacfb 100644
--- a/src/util/vircrypto.c
+++ b/src/util/vircrypto.c
@@ -300,8 +300,9 @@ virCryptoEncryptData(virCryptoCipher algorithm,
*
* Returns pointer memory containing byte stream on success, NULL on failure
*/
-uint8_t *
-virCryptoGenerateRandom(size_t nbytes)
+VIR_MOCKABLE(uint8_t *,
+ virCryptoGenerateRandom,
+ size_t nbytes)
{
uint8_t *buf;
int ret;
diff --git a/src/util/vircrypto.h b/src/util/vircrypto.h
index 50400c6..52ba3b3 100644
--- a/src/util/vircrypto.h
+++ b/src/util/vircrypto.h
@@ -55,6 +55,6 @@ int virCryptoEncryptData(virCryptoCipher algorithm,
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(6)
ATTRIBUTE_NONNULL(8) ATTRIBUTE_NONNULL(9) ATTRIBUTE_RETURN_CHECK;
-uint8_t *virCryptoGenerateRandom(size_t nbytes) ATTRIBUTE_MOCKABLE;
+uint8_t *virCryptoGenerateRandom(size_t nbytes);
#endif /* __VIR_CRYPTO_H__ */
diff --git a/src/util/virfile.c b/src/util/virfile.c
index d444b32..b612ad5 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1824,8 +1824,9 @@ virFileIsDir(const char *path)
* Returns true if the file exists, false if it doesn't, setting errno
* appropriately.
*/
-bool
-virFileExists(const char *path)
+VIR_MOCKABLE(bool,
+ virFileExists,
+ const char *path)
{
return access(path, F_OK) == 0;
}
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 32c9115..40034f0 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -188,7 +188,7 @@ void virFileActivateDirOverride(const char *argv0)
off_t virFileLength(const char *path, int fd) ATTRIBUTE_NONNULL(1);
bool virFileIsDir (const char *file) ATTRIBUTE_NONNULL(1);
-bool virFileExists(const char *file) ATTRIBUTE_NONNULL(1) ATTRIBUTE_MOCKABLE;
+bool virFileExists(const char *file) ATTRIBUTE_NONNULL(1);
bool virFileIsExecutable(const char *file) ATTRIBUTE_NONNULL(1);
enum {
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index c485a97..4d63842 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -1112,8 +1112,9 @@ virHostCPUGetMap(unsigned char **cpumap,
*
* Returns the number of threads per subcore if subcores are in use, zero
* if subcores are not in use, and a negative value on error */
-int
-virHostCPUGetThreadsPerSubcore(virArch arch)
+VIR_MOCKABLE(int,
+ virHostCPUGetThreadsPerSubcore,
+ virArch arch)
{
int threads_per_subcore = 0;
int kvmfd;
@@ -1167,8 +1168,9 @@ virHostCPUGetThreadsPerSubcore(virArch arch ATTRIBUTE_UNUSED)
#endif /* HAVE_LINUX_KVM_H && defined(KVM_CAP_PPC_SMT) */
#if HAVE_LINUX_KVM_H
-int
-virHostCPUGetKVMMaxVCPUs(void)
+VIR_MOCKABLE(int,
+ virHostCPUGetKVMMaxVCPUs,
+ void)
{
int fd;
int ret;
diff --git a/src/util/virhostcpu.h b/src/util/virhostcpu.h
index 3b30a0d..e9c22ee 100644
--- a/src/util/virhostcpu.h
+++ b/src/util/virhostcpu.h
@@ -38,7 +38,7 @@ bool virHostCPUHasBitmap(void);
virBitmapPtr virHostCPUGetPresentBitmap(void);
virBitmapPtr virHostCPUGetOnlineBitmap(void);
int virHostCPUGetCount(void);
-int virHostCPUGetThreadsPerSubcore(virArch arch) ATTRIBUTE_MOCKABLE;
+int virHostCPUGetThreadsPerSubcore(virArch arch);
int virHostCPUGetMap(unsigned char **cpumap,
unsigned int *online,
@@ -51,7 +51,7 @@ int virHostCPUGetInfo(virArch hostarch,
unsigned int *cores,
unsigned int *threads);
-int virHostCPUGetKVMMaxVCPUs(void) ATTRIBUTE_MOCKABLE;
+int virHostCPUGetKVMMaxVCPUs(void);
int virHostCPUStatsAssign(virNodeCPUStatsPtr param,
const char *name,
diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c
index 7afe032..29d6980 100644
--- a/src/util/virmacaddr.c
+++ b/src/util/virmacaddr.c
@@ -223,8 +223,10 @@ virMacAddrParseHex(const char *str, virMacAddrPtr addr)
return 0;
}
-void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
- virMacAddrPtr addr)
+VIR_MOCKABLE(void,
+ virMacAddrGenerate,
+ const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
+ virMacAddrPtr addr)
{
addr->addr[0] = prefix[0];
addr->addr[1] = prefix[1];
diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h
index 79492cd..ae26867 100644
--- a/src/util/virmacaddr.h
+++ b/src/util/virmacaddr.h
@@ -48,7 +48,7 @@ void virMacAddrGetRaw(const virMacAddr *src, unsigned char dst[VIR_MAC_BUFLEN]);
const char *virMacAddrFormat(const virMacAddr *addr,
char *str);
void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
- virMacAddrPtr addr) ATTRIBUTE_MOCKABLE;
+ virMacAddrPtr addr);
int virMacAddrParse(const char* str,
virMacAddrPtr addr) ATTRIBUTE_RETURN_CHECK;
int virMacAddrParseHex(const char* str,
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 90b7bee..7c1ec5c 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -346,9 +346,9 @@ virNetDevSetMACInternal(const char *ifname,
#endif
-int
-virNetDevSetMAC(const char *ifname,
- const virMacAddr *macaddr)
+VIR_MOCKABLE(int,
+ virNetDevSetMAC,
+ const char *ifname, const virMacAddr *macaddr)
{
return virNetDevSetMACInternal(ifname, macaddr, false);
}
@@ -686,9 +686,9 @@ virNetDevSetIFFlag(const char *ifname,
*
* Returns 0 in case of success or -1 on error.
*/
-int
-virNetDevSetOnline(const char *ifname,
- bool online)
+VIR_MOCKABLE(int,
+ virNetDevSetOnline,
+ const char *ifname, bool online)
{
return virNetDevSetIFFlag(ifname, VIR_IFF_UP, online);
@@ -1122,9 +1122,9 @@ int virNetDevValidateConfig(const char *ifname ATTRIBUTE_UNUSED,
#ifdef __linux__
-int
-virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname,
- const char *file)
+VIR_MOCKABLE(int,
+ virNetDevSysfsFile,
+ char **pf_sysfs_device_link, const char *ifname, const char *file)
{
if (virAsprintf(pf_sysfs_device_link, SYSFS_NET_DIR "%s/%s", ifname, file) < 0)
@@ -3268,8 +3268,9 @@ int virNetDevSetCoalesce(const char *ifname,
* This function executes script for new tap device created by libvirt.
* Returns 0 in case of success or -1 on failure
*/
-int
-virNetDevRunEthernetScript(const char *ifname, const char *script)
+VIR_MOCKABLE(int,
+ virNetDevRunEthernetScript,
+ const char *ifname, const char *script)
{
virCommandPtr cmd;
int ret;
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
index 2e9a9c4..c2c09af 100644
--- a/src/util/virnetdev.h
+++ b/src/util/virnetdev.h
@@ -156,7 +156,7 @@ int virNetDevExists(const char *brname)
int virNetDevSetOnline(const char *ifname,
bool online)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virNetDevGetOnline(const char *ifname,
bool *online)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
@@ -164,7 +164,7 @@ int virNetDevGetOnline(const char *ifname,
int virNetDevSetMAC(const char *ifname,
const virMacAddr *macaddr)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int virNetDevGetMAC(const char *ifname,
virMacAddrPtr macaddr)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
@@ -303,8 +303,7 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link,
const char *ifname,
const char *file)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
- ATTRIBUTE_RETURN_CHECK ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_RETURN_CHECK;
-int virNetDevRunEthernetScript(const char *ifname, const char *script)
- ATTRIBUTE_MOCKABLE;
+int virNetDevRunEthernetScript(const char *ifname, const char *script);
#endif /* __VIR_NETDEV_H__ */
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index bf98ed8..6dcd2e8 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -163,11 +163,10 @@ virNetDevCreateNetlinkAddressMessage(int messageType,
*
* Returns 0 in case of success or -1 in case of error.
*/
-int
-virNetDevIPAddrAdd(const char *ifname,
- virSocketAddr *addr,
- virSocketAddr *peer,
- unsigned int prefix)
+VIR_MOCKABLE(int,
+ virNetDevIPAddrAdd,
+ const char *ifname, virSocketAddr *addr,
+ virSocketAddr *peer, unsigned int prefix)
{
virSocketAddr *broadcast = NULL;
int ret = -1;
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index 972a49a..cc466ca 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -67,7 +67,7 @@ int virNetDevIPAddrAdd(const char *ifname,
virSocketAddr *addr,
virSocketAddr *peer,
unsigned int prefix)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int virNetDevIPRouteAdd(const char *ifname,
virSocketAddrPtr addr,
unsigned int prefix,
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index a5ecfb6..ab292a4 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -382,7 +382,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname,
}
/**
- * virNetDevOpenvswitchVhostuserGetIfname:
+ * virNetDevOpenvswitchGetVhostuserIfname:
* @path: the path of the unix socket
* @ifname: the retrieved name of the interface
*
@@ -392,9 +392,9 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname,
* 0 if it is not, but no other error occurred,
* -1 otherwise.
*/
-int
-virNetDevOpenvswitchGetVhostuserIfname(const char *path,
- char **ifname)
+VIR_MOCKABLE(int,
+ virNetDevOpenvswitchGetVhostuserIfname,
+ const char *path, char **ifname)
{
virCommandPtr cmd = NULL;
char *tmpIfname = NULL;
diff --git a/src/util/virnetdevopenvswitch.h b/src/util/virnetdevopenvswitch.h
index dc677ca..7380a2d 100644
--- a/src/util/virnetdevopenvswitch.h
+++ b/src/util/virnetdevopenvswitch.h
@@ -59,6 +59,6 @@ int virNetDevOpenvswitchInterfaceStats(const char *ifname,
int virNetDevOpenvswitchGetVhostuserIfname(const char *path,
char **ifname)
- ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
#endif /* __VIR_NETDEV_OPENVSWITCH_H__ */
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
index 175dc2b..93cb65d 100644
--- a/src/util/virnetdevtap.c
+++ b/src/util/virnetdevtap.c
@@ -98,8 +98,9 @@ virNetDevTapGetName(int tapfd ATTRIBUTE_UNUSED, char **ifname ATTRIBUTE_UNUSED)
* Returns the proper interface name or NULL if no corresponding interface
* found.
*/
-char*
-virNetDevTapGetRealDeviceName(char *ifname ATTRIBUTE_UNUSED)
+VIR_MOCKABLE(char *,
+ virNetDevTapGetRealDeviceName,
+ char *ifname ATTRIBUTE_UNUSED)
{
#ifdef TAPGIFNAME
char *ret = NULL;
@@ -238,11 +239,13 @@ virNetDevProbeVnetHdr(int tapfd)
*
* Returns 0 in case of success or -1 on failure.
*/
-int virNetDevTapCreate(char **ifname,
- const char *tunpath,
- int *tapfd,
- size_t tapfdSize,
- unsigned int flags)
+VIR_MOCKABLE(int,
+ virNetDevTapCreate,
+ char **ifname,
+ const char *tunpath,
+ int *tapfd,
+ size_t tapfdSize,
+ unsigned int flags)
{
size_t i;
struct ifreq ifr;
@@ -608,19 +611,21 @@ virNetDevTapAttachBridge(const char *tapname,
*
* Returns 0 in case of success or -1 on failure
*/
-int virNetDevTapCreateInBridgePort(const char *brname,
- char **ifname,
- const virMacAddr *macaddr,
- const unsigned char *vmuuid,
- const char *tunpath,
- int *tapfd,
- size_t tapfdSize,
- virNetDevVPortProfilePtr virtPortProfile,
- virNetDevVlanPtr virtVlan,
- virNetDevCoalescePtr coalesce,
- unsigned int mtu,
- unsigned int *actualMTU,
- unsigned int flags)
+VIR_MOCKABLE(int,
+ virNetDevTapCreateInBridgePort,
+ const char *brname,
+ char **ifname,
+ const virMacAddr *macaddr,
+ const unsigned char *vmuuid,
+ const char *tunpath,
+ int *tapfd,
+ size_t tapfdSize,
+ virNetDevVPortProfilePtr virtPortProfile,
+ virNetDevVlanPtr virtVlan,
+ virNetDevCoalescePtr coalesce,
+ unsigned int mtu,
+ unsigned int *actualMTU,
+ unsigned int flags)
{
virMacAddr tapmac;
char macaddrstr[VIR_MAC_STRING_BUFLEN];
diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h
index 1c4343e..bd5ec14 100644
--- a/src/util/virnetdevtap.h
+++ b/src/util/virnetdevtap.h
@@ -39,7 +39,7 @@ int virNetDevTapCreate(char **ifname,
int *tapfd,
size_t tapfdSize,
unsigned int flags)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virNetDevTapDelete(const char *ifname,
const char *tunpath)
@@ -49,7 +49,7 @@ int virNetDevTapGetName(int tapfd, char **ifname)
ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
char* virNetDevTapGetRealDeviceName(char *ifname)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
typedef enum {
VIR_NETDEV_TAP_CREATE_NONE = 0,
@@ -89,7 +89,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,
unsigned int *actualMTU,
unsigned int flags)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
- ATTRIBUTE_RETURN_CHECK ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_RETURN_CHECK;
int virNetDevTapInterfaceStats(const char *ifname,
virDomainInterfaceStatsPtr stats)
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index bebe301..6300bc1 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -160,8 +160,9 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode,
return ret;
}
-bool
-virNumaIsAvailable(void)
+VIR_MOCKABLE(bool,
+ virNumaIsAvailable,
+ void)
{
return numa_available() != -1;
}
@@ -174,8 +175,9 @@ virNumaIsAvailable(void)
*
* Returns the highest NUMA node id on success, -1 on error.
*/
-int
-virNumaGetMaxNode(void)
+VIR_MOCKABLE(int,
+ virNumaGetMaxNode,
+ void)
{
int ret;
@@ -207,10 +209,11 @@ virNumaGetMaxNode(void)
*
* Returns 0 on success, -1 on error. Does not report errors.
*/
-int
-virNumaGetNodeMemory(int node,
- unsigned long long *memsize,
- unsigned long long *memfree)
+VIR_MOCKABLE(int,
+ virNumaGetNodeMemory,
+ int node,
+ unsigned long long *memsize,
+ unsigned long long *memfree)
{
long long node_size;
long long node_free;
@@ -248,9 +251,10 @@ virNumaGetNodeMemory(int node,
# define n_bits(var) (8 * sizeof(var))
# define MASK_CPU_ISSET(mask, cpu) \
(((mask)[((cpu) / n_bits(*(mask)))] >> ((cpu) % n_bits(*(mask)))) & 1)
-int
-virNumaGetNodeCPUs(int node,
- virBitmapPtr *cpus)
+VIR_MOCKABLE(int,
+ virNumaGetNodeCPUs,
+ int node,
+ virBitmapPtr *cpus)
{
unsigned long *mask = NULL;
unsigned long *allonesmask = NULL;
@@ -321,15 +325,17 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode ATTRIBUTE_UNUSED,
return 0;
}
-bool
-virNumaIsAvailable(void)
+VIR_MOCKABLE(bool,
+ virNumaIsAvailable,
+ void)
{
return false;
}
-int
-virNumaGetMaxNode(void)
+VIR_MOCKABLE(int,
+ virNumaGetMaxNode,
+ void)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("NUMA isn't available on this host"));
@@ -337,10 +343,11 @@ virNumaGetMaxNode(void)
}
-int
-virNumaGetNodeMemory(int node ATTRIBUTE_UNUSED,
- unsigned long long *memsize,
- unsigned long long *memfree)
+VIR_MOCKABLE(int,
+ virNumaGetNodeMemory,
+ int node ATTRIBUTE_UNUSED,
+ unsigned long long *memsize,
+ unsigned long long *memfree)
{
if (memsize)
*memsize = 0;
@@ -353,9 +360,10 @@ virNumaGetNodeMemory(int node ATTRIBUTE_UNUSED,
}
-int
-virNumaGetNodeCPUs(int node ATTRIBUTE_UNUSED,
- virBitmapPtr *cpus)
+VIR_MOCKABLE(int,
+ virNumaGetNodeCPUs,
+ int node ATTRIBUTE_UNUSED,
+ virBitmapPtr *cpus)
{
*cpus = NULL;
@@ -390,8 +398,9 @@ virNumaGetMaxCPUs(void)
* Returns: true if @node is available,
* false if @node doesn't exist
*/
-bool
-virNumaNodeIsAvailable(int node)
+VIR_MOCKABLE(bool,
+ virNumaNodeIsAvailable,
+ int node)
{
return numa_bitmask_isbitset(numa_nodes_ptr, node);
}
@@ -416,10 +425,11 @@ virNumaNodeIsAvailable(int node)
*
* Returns 0 on success, -1 otherwise.
*/
-int
-virNumaGetDistances(int node,
- int **distances,
- int *ndistances)
+VIR_MOCKABLE(int,
+ virNumaGetDistances,
+ int node,
+ int **distances,
+ int *ndistances)
{
int ret = -1;
int max_node;
@@ -454,8 +464,9 @@ virNumaGetDistances(int node,
#else /* !(WITH_NUMACTL && HAVE_NUMA_BITMASK_ISBITSET) */
-bool
-virNumaNodeIsAvailable(int node)
+VIR_MOCKABLE(bool,
+ virNumaNodeIsAvailable,
+ int node)
{
int max_node = virNumaGetMaxNode();
@@ -467,10 +478,11 @@ virNumaNodeIsAvailable(int node)
}
-int
-virNumaGetDistances(int node ATTRIBUTE_UNUSED,
- int **distances,
- int *ndistances)
+VIR_MOCKABLE(int,
+ virNumaGetDistances,
+ int node ATTRIBUTE_UNUSED,
+ int **distances,
+ int *ndistances)
{
*distances = NULL;
*ndistances = 0;
@@ -706,12 +718,13 @@ virNumaGetPageInfo(int node,
*
* Returns 0 on success, -1 otherwise.
*/
-int
-virNumaGetPages(int node,
- unsigned int **pages_size,
- unsigned int **pages_avail,
- unsigned int **pages_free,
- size_t *npages)
+VIR_MOCKABLE(int,
+ virNumaGetPages,
+ int node,
+ unsigned int **pages_size,
+ unsigned int **pages_avail,
+ unsigned int **pages_free,
+ size_t *npages)
{
int ret = -1;
char *path = NULL;
@@ -943,12 +956,13 @@ virNumaGetPageInfo(int node ATTRIBUTE_UNUSED,
}
-int
-virNumaGetPages(int node ATTRIBUTE_UNUSED,
- unsigned int **pages_size ATTRIBUTE_UNUSED,
- unsigned int **pages_avail ATTRIBUTE_UNUSED,
- unsigned int **pages_free ATTRIBUTE_UNUSED,
- size_t *npages ATTRIBUTE_UNUSED)
+VIR_MOCKABLE(int,
+ virNumaGetPages,
+ int node ATTRIBUTE_UNUSED,
+ unsigned int **pages_size ATTRIBUTE_UNUSED,
+ unsigned int **pages_avail ATTRIBUTE_UNUSED,
+ unsigned int **pages_free ATTRIBUTE_UNUSED,
+ size_t *npages ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("page info is not supported on this platform"));
@@ -968,8 +982,9 @@ virNumaSetPagePoolSize(int node ATTRIBUTE_UNUSED,
}
#endif /* #ifdef __linux__ */
-bool
-virNumaNodesetIsAvailable(virBitmapPtr nodeset)
+VIR_MOCKABLE(bool,
+ virNumaNodesetIsAvailable,
+ virBitmapPtr nodeset)
{
ssize_t bit = -1;
diff --git a/src/util/virnuma.h b/src/util/virnuma.h
index 62b89e9..f3eef32 100644
--- a/src/util/virnuma.h
+++ b/src/util/virnuma.h
@@ -34,20 +34,20 @@ int virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode,
virBitmapPtr nodeset);
virBitmapPtr virNumaGetHostMemoryNodeset(void);
-bool virNumaNodesetIsAvailable(virBitmapPtr nodeset) ATTRIBUTE_MOCKABLE;
-bool virNumaIsAvailable(void) ATTRIBUTE_MOCKABLE;
-int virNumaGetMaxNode(void) ATTRIBUTE_MOCKABLE;
-bool virNumaNodeIsAvailable(int node) ATTRIBUTE_MOCKABLE;
+bool virNumaNodesetIsAvailable(virBitmapPtr nodeset);
+bool virNumaIsAvailable(void);
+int virNumaGetMaxNode(void);
+bool virNumaNodeIsAvailable(int node);
int virNumaGetDistances(int node,
int **distances,
- int *ndistances) ATTRIBUTE_MOCKABLE;
+ int *ndistances);
int virNumaGetNodeMemory(int node,
unsigned long long *memsize,
- unsigned long long *memfree) ATTRIBUTE_MOCKABLE;
+ unsigned long long *memfree);
unsigned int virNumaGetMaxCPUs(void);
-int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) ATTRIBUTE_MOCKABLE;
+int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus);
int virNumaGetPageInfo(int node,
unsigned int page_size,
@@ -59,7 +59,7 @@ int virNumaGetPages(int node,
unsigned int **pages_avail,
unsigned int **pages_free,
size_t *npages)
- ATTRIBUTE_NONNULL(5) ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_NONNULL(5);
int virNumaSetPagePoolSize(int node,
unsigned int page_size,
unsigned long long page_count,
diff --git a/src/util/virrandom.c b/src/util/virrandom.c
index 41daa40..90d6905 100644
--- a/src/util/virrandom.c
+++ b/src/util/virrandom.c
@@ -99,7 +99,9 @@ VIR_ONCE_GLOBAL_INIT(virRandom)
*
* Return: a random number with @nbits entropy
*/
-uint64_t virRandomBits(int nbits)
+VIR_MOCKABLE(uint64_t,
+ virRandomBits,
+ int nbits)
{
uint64_t ret = 0;
int32_t bits;
@@ -170,9 +172,10 @@ uint32_t virRandomInt(uint32_t max)
*
* Returns 0 on success or an errno on failure
*/
-int
-virRandomBytes(unsigned char *buf,
- size_t buflen)
+VIR_MOCKABLE(int,
+ virRandomBytes,
+ unsigned char *buf,
+ size_t buflen)
{
int fd;
@@ -205,9 +208,10 @@ virRandomBytes(unsigned char *buf,
#define XEN_OUI "00163e"
-int
-virRandomGenerateWWN(char **wwn,
- const char *virt_type)
+VIR_MOCKABLE(int,
+ virRandomGenerateWWN,
+ char **wwn,
+ const char *virt_type)
{
const char *oui = NULL;
diff --git a/src/util/virrandom.h b/src/util/virrandom.h
index 990a456..f457d2d 100644
--- a/src/util/virrandom.h
+++ b/src/util/virrandom.h
@@ -24,11 +24,11 @@
# include "internal.h"
-uint64_t virRandomBits(int nbits) ATTRIBUTE_MOCKABLE;
+uint64_t virRandomBits(int nbits);
double virRandom(void);
uint32_t virRandomInt(uint32_t max);
int virRandomBytes(unsigned char *buf, size_t buflen)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_MOCKABLE;
-int virRandomGenerateWWN(char **wwn, const char *virt_type) ATTRIBUTE_MOCKABLE;
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+int virRandomGenerateWWN(char **wwn, const char *virt_type);
#endif /* __VIR_RANDOM_H__ */
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
index 22f2677..d6fe4b7 100644
--- a/src/util/virscsi.c
+++ b/src/util/virscsi.c
@@ -109,12 +109,13 @@ virSCSIDeviceGetAdapterId(const char *adapter,
return -1;
}
-char *
-virSCSIDeviceGetSgName(const char *sysfs_prefix,
- const char *adapter,
- unsigned int bus,
- unsigned int target,
- unsigned long long unit)
+VIR_MOCKABLE(char *,
+ virSCSIDeviceGetSgName,
+ const char *sysfs_prefix,
+ const char *adapter,
+ unsigned int bus,
+ unsigned int target,
+ unsigned long long unit)
{
DIR *dir = NULL;
struct dirent *entry;
diff --git a/src/util/virscsi.h b/src/util/virscsi.h
index eed563d..7d88d4e 100644
--- a/src/util/virscsi.h
+++ b/src/util/virscsi.h
@@ -37,7 +37,7 @@ char *virSCSIDeviceGetSgName(const char *sysfs_prefix,
const char *adapter,
unsigned int bus,
unsigned int target,
- unsigned long long unit) ATTRIBUTE_MOCKABLE;
+ unsigned long long unit);
char *virSCSIDeviceGetDevName(const char *sysfs_prefix,
const char *adapter,
unsigned int bus,
diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c
index dc7df75..32828f7 100644
--- a/src/util/virscsivhost.c
+++ b/src/util/virscsivhost.c
@@ -83,8 +83,9 @@ virSCSIVHostOnceInit(void)
VIR_ONCE_GLOBAL_INIT(virSCSIVHost)
-int
-virSCSIVHostOpenVhostSCSI(int *vhostfd)
+VIR_MOCKABLE(int,
+ virSCSIVHostOpenVhostSCSI,
+ int *vhostfd)
{
if (!virFileExists(VHOST_SCSI_DEVICE))
goto error;
diff --git a/src/util/virscsivhost.h b/src/util/virscsivhost.h
index f9272a6..6018b83 100644
--- a/src/util/virscsivhost.h
+++ b/src/util/virscsivhost.h
@@ -61,6 +61,6 @@ void virSCSIVHostDeviceGetUsedBy(virSCSIVHostDevicePtr dev,
const char **drv_name,
const char **dom_name);
void virSCSIVHostDeviceFree(virSCSIVHostDevicePtr dev);
-int virSCSIVHostOpenVhostSCSI(int *vhostfd) ATTRIBUTE_MOCKABLE;
+int virSCSIVHostOpenVhostSCSI(int *vhostfd);
#endif /* __VIR_SCSIHOST_H__ */
diff --git a/src/util/virtpm.c b/src/util/virtpm.c
index 6d9b065..07db753 100644
--- a/src/util/virtpm.c
+++ b/src/util/virtpm.c
@@ -38,8 +38,9 @@
*
* Create the cancel path given the path to the TPM device
*/
-char *
-virTPMCreateCancelPath(const char *devpath)
+VIR_MOCKABLE(char *,
+ virTPMCreateCancelPath,
+ const char *devpath)
{
char *path = NULL;
const char *dev;
diff --git a/src/util/virtpm.h b/src/util/virtpm.h
index 7067bb5..fe71307 100644
--- a/src/util/virtpm.h
+++ b/src/util/virtpm.h
@@ -22,6 +22,6 @@
#ifndef __VIR_TPM_H__
# define __VIR_TPM_H__
-char *virTPMCreateCancelPath(const char *devpath) ATTRIBUTE_MOCKABLE;
+char *virTPMCreateCancelPath(const char *devpath);
#endif /* __VIR_TPM_H__ */
diff --git a/src/util/virutil.c b/src/util/virutil.c
index e08f9fa..81bfba7 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -884,14 +884,18 @@ char *virGetUserRuntimeDirectory(void)
}
}
-char *virGetUserName(uid_t uid)
+VIR_MOCKABLE(char *,
+ virGetUserName,
+ uid_t uid)
{
char *ret;
virGetUserEnt(uid, &ret, NULL, NULL, NULL, false);
return ret;
}
-char *virGetGroupName(gid_t gid)
+VIR_MOCKABLE(char *,
+ virGetGroupName,
+ gid_t gid)
{
return virGetGroupEnt(gid);
}
@@ -1340,8 +1344,9 @@ virGetUserRuntimeDirectory(void)
}
# endif /* ! HAVE_GETPWUID_R && ! WIN32 */
-char *
-virGetUserName(uid_t uid ATTRIBUTE_UNUSED)
+VIR_MOCKABLE(char *,
+ virGetUserName,
+ uid_t uid ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("virGetUserName is not available"));
@@ -1379,8 +1384,9 @@ virSetUIDGID(uid_t uid ATTRIBUTE_UNUSED,
return -1;
}
-char *
-virGetGroupName(gid_t gid ATTRIBUTE_UNUSED)
+VIR_MOCKABLE(char *,
+ virGetGroupName,
+ gid_t gid ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("virGetGroupName is not available"));
@@ -1908,12 +1914,16 @@ virGetListenFDs(void)
#endif /* WIN32 */
#ifndef WIN32
-long virGetSystemPageSize(void)
+VIR_MOCKABLE(long,
+ virGetSystemPageSize,
+ void)
{
return sysconf(_SC_PAGESIZE);
}
#else /* WIN32 */
-long virGetSystemPageSize(void)
+VIR_MOCKABLE(long,
+ virGetSystemPageSize,
+ void)
{
errno = ENOSYS;
return -1;
@@ -1959,12 +1969,11 @@ virMemoryLimitIsSet(unsigned long long value)
* @capped: whether the value must fit into unsigned long
* (long long is assumed otherwise)
*
- * Note: This function is mocked in tests/qemuxml2argvmock.c for test stability
- *
* Returns the maximum possible memory value in bytes.
*/
-unsigned long long
-virMemoryMaxValue(bool capped)
+VIR_MOCKABLE(unsigned long long,
+ virMemoryMaxValue,
+ bool capped)
{
/* On 32-bit machines, our bound is 0xffffffff * KiB. On 64-bit
* machines, our bound is off_t (2^63). */
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 35e5ca3..3bbe29e 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -139,8 +139,8 @@ char *virGetUserConfigDirectory(void);
char *virGetUserCacheDirectory(void);
char *virGetUserRuntimeDirectory(void);
char *virGetUserShell(uid_t uid);
-char *virGetUserName(uid_t uid) ATTRIBUTE_MOCKABLE;
-char *virGetGroupName(gid_t gid) ATTRIBUTE_MOCKABLE;
+char *virGetUserName(uid_t uid);
+char *virGetGroupName(gid_t gid);
int virGetGroupList(uid_t uid, gid_t group, gid_t **groups)
ATTRIBUTE_NONNULL(3);
int virGetUserID(const char *name,
@@ -201,12 +201,12 @@ verify((int)VIR_TRISTATE_BOOL_ABSENT == (int)VIR_TRISTATE_SWITCH_ABSENT);
unsigned int virGetListenFDs(void);
-long virGetSystemPageSize(void) ATTRIBUTE_MOCKABLE;
-long virGetSystemPageSizeKB(void) ATTRIBUTE_MOCKABLE;
+long virGetSystemPageSize(void);
+long virGetSystemPageSizeKB(void);
unsigned long long virMemoryLimitTruncate(unsigned long long value);
bool virMemoryLimitIsSet(unsigned long long value);
-unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_MOCKABLE;
+unsigned long long virMemoryMaxValue(bool ulong);
/**
* VIR_ASSIGN_IS_OVERFLOW:
diff --git a/src/util/viruuid.c b/src/util/viruuid.c
index 3cbaae0..30de6f5 100644
--- a/src/util/viruuid.c
+++ b/src/util/viruuid.c
@@ -68,8 +68,9 @@ virUUIDGeneratePseudoRandomBytes(unsigned char *buf,
*
* Returns 0 in case of success and -1 in case of failure
*/
-int
-virUUIDGenerate(unsigned char *uuid)
+VIR_MOCKABLE(int,
+ virUUIDGenerate,
+ unsigned char *uuid)
{
int err;
diff --git a/src/util/viruuid.h b/src/util/viruuid.h
index 3b41b42..5790a17 100644
--- a/src/util/viruuid.h
+++ b/src/util/viruuid.h
@@ -49,7 +49,7 @@ int virGetHostUUID(unsigned char *host_uuid) ATTRIBUTE_NONNULL(1);
int virUUIDIsValid(unsigned char *uuid);
-int virUUIDGenerate(unsigned char *uuid) ATTRIBUTE_MOCKABLE;
+int virUUIDGenerate(unsigned char *uuid);
int virUUIDParse(const char *uuidstr,
unsigned char *uuid)
--
2.9.4
7 years, 5 months
[libvirt] [PATCH 0/2] Revert use of weak symbols
by Daniel P. Berrange
This series reverts the use of the __weak__ attribute which we did
to fix the test suite with CLang. It cause unintended problems
elsewhere which are not practical to fix. See the second patch
for details.
Daniel P. Berrange (2):
Revert "internal: don't use weak symbols for Win32 platform"
Revert "Prevent more compiler optimization of mockable functions"
build-aux/mock-noinline.pl | 2 +-
src/check-symfile.pl | 2 +-
src/internal.h | 27 +++++----------------------
src/qemu/qemu_capspriv.h | 2 +-
src/rpc/virnetsocket.h | 4 ++--
src/util/vircommand.h | 2 +-
src/util/vircrypto.h | 2 +-
src/util/virfile.h | 2 +-
src/util/virhostcpu.h | 4 ++--
src/util/virmacaddr.h | 2 +-
src/util/virnetdev.h | 8 ++++----
src/util/virnetdevip.h | 2 +-
src/util/virnetdevopenvswitch.h | 2 +-
src/util/virnetdevtap.h | 6 +++---
src/util/virnuma.h | 16 ++++++++--------
src/util/virrandom.h | 6 +++---
src/util/virscsi.h | 2 +-
src/util/virscsivhost.h | 2 +-
src/util/virtpm.h | 2 +-
src/util/virutil.h | 10 +++++-----
src/util/viruuid.h | 2 +-
21 files changed, 45 insertions(+), 62 deletions(-)
--
2.9.4
7 years, 5 months
[libvirt] [PATCH] tests: add virjsondata to EXTRA_DIST
by Daniel P. Berrange
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
Pushed as a build fix for RPM builds
tests/Makefile.am | 1 +
1 file changed, 1 insertion(+)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3596b5ff1..efc1a310d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -148,6 +148,7 @@ EXTRA_DIST = \
vircgroupdata \
virconfdata \
virfiledata \
+ virjsondata \
virmacmaptestdata \
virmock.h \
virnetdaemondata \
--
2.13.0
7 years, 5 months
[libvirt] [PATCH] util: Don't leak linksrc in vircgroup
by Martin Kletzander
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/util/vircgroup.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index a53908fc9246..2912fc9be539 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -382,6 +382,8 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
FILE *mounts = NULL;
struct mntent entry;
char buf[CGROUP_MAX_VAL];
+ char *linksrc = NULL;
+ int ret = -1;
mounts = fopen(path, "r");
if (mounts == NULL) {
@@ -409,7 +411,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
}
if (typelen == len && STREQLEN(typestr, tmp, len)) {
- char *linksrc;
struct stat sb;
char *tmp2;
@@ -423,35 +424,35 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
VIR_FREE(controller->mountPoint);
VIR_FREE(controller->linkPoint);
if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0)
- goto error;
+ goto cleanup;
tmp2 = strrchr(entry.mnt_dir, '/');
if (!tmp2) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Missing '/' separator in cgroup mount '%s'"),
entry.mnt_dir);
- goto error;
+ goto cleanup;
}
/* If it is a co-mount it has a filename like "cpu,cpuacct"
* and we must identify the symlink path */
if (checkLinks && strchr(tmp2 + 1, ',')) {
*tmp2 = '\0';
+ VIR_FREE(linksrc);
if (virAsprintf(&linksrc, "%s/%s",
entry.mnt_dir, typestr) < 0)
- goto error;
+ goto cleanup;
*tmp2 = '/';
if (lstat(linksrc, &sb) < 0) {
if (errno == ENOENT) {
VIR_WARN("Controller %s co-mounted at %s is missing symlink at %s",
typestr, entry.mnt_dir, linksrc);
- VIR_FREE(linksrc);
} else {
virReportSystemError(errno,
_("Cannot stat %s"),
linksrc);
- goto error;
+ goto cleanup;
}
} else {
if (!S_ISLNK(sb.st_mode)) {
@@ -459,6 +460,7 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
linksrc, typestr);
} else {
controller->linkPoint = linksrc;
+ linksrc = NULL;
}
}
}
@@ -468,13 +470,11 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
}
}
+ ret = 0;
+ cleanup:
+ VIR_FREE(linksrc);
VIR_FORCE_FCLOSE(mounts);
-
- return 0;
-
- error:
- VIR_FORCE_FCLOSE(mounts);
- return -1;
+ return ret;
}
static int
--
2.13.2
7 years, 5 months
[libvirt] [PATCH 0/7] qemu: Update host-model CPUs on reconnect
by Jiri Denemark
This series fixes migration of a domain with a host-model CPU started by
an old libvirt (< 2.3).
https://bugzilla.redhat.com/show_bug.cgi?id=1463957
Jiri Denemark (7):
qemu: Add qemuProcessFetchGuestCPU
qemu: Add qemuProcessVerifyCPU
qemu: Rename qemuProcessUpdateLiveGuestCPU
qemu: Add qemuProcessUpdateLiveGuestCPU
qemu: Export virQEMUCapsGuestIsNative
qemu: Move qemuProcessReconnect to the end of qemu_process.c
qemu: Update host-model CPUs on reconnect
src/qemu/qemu_capabilities.c | 2 +-
src/qemu/qemu_capabilities.h | 3 +
src/qemu/qemu_process.c | 856 ++++++++++++++++++++++++-------------------
3 files changed, 489 insertions(+), 372 deletions(-)
--
2.13.2
7 years, 5 months