[PATCH v2 0/7] Add Security Guest doc and check for capabilities cache validation
by Paulo de Rezende Pinatti
This series introduces the concept of a 'Secure Guest' feature
which covers on s390 IBM Secure Execution and on x86 AMD Secure
Encrypted Virtualization.
Besides adding documentation for IBM Secure Execution it also adds
checks during validation of the qemu capabilities cache.
These checks per architecture can be performed for IBM Secure
Execution on s390 and AMD Secure Encrypted Virtualization on AMD x86
CPUs (both checks implemented in this series).
For s390 the verification consists of:
- checking if /sys/firmware/uv is available: meaning the HW
facility is available and the host OS supports it;
- checking if the kernel cmdline contains 'prot_virt=1': meaning
the host OS wants to use the feature.
For AMD Secure Encrypted Virtualization the verification consists of:
- checking if /sys/module/kvm_amd/parameters/sev contains the
value '1': meaning SEV is enabled in the host kernel;
- checking if /dev/sev exists
Whenever the availability of the feature does not match the secure
guest flag in the cache then libvirt will re-build it in order to
pick up the new set of capabilities available.
Additionally, this series adds the same aforementioned checks to the
virt-host-validate tool to facilitate the manual verification
process for users.
Changes in v2:
[Patch 1]
Reworked kernel cmdline parser into a parameter based processing.
[Patch 2]
Added missing value "on" to kvalue list
[Patch 3]
Changed AMD SEV support check to module parameter is set and /dev/sev exists.
Moved doc changes to a new standalone patch 6.
[Patch 4]
Added missing value "on" to kvalue list
[Patch 5]
Changed AMD SEV support check to align with patch 3.
Moved doc changes to a new standalone patch 6.
[Patch 6]
Summarized AMD SEV doc changes from patches 3 and 5.
Adjusted libvirt version number
[Patch 7 (v1: Patch 6)]
Adjusted libvirt version number
link to v1: https://www.redhat.com/archives/libvir-list/2020-May/msg00416.html
Boris Fiuczynski (3):
tools: secure guest check on s390 in virt-host-validate
tools: secure guest check for AMD in virt-host-validate
docs: update AMD launch secure description
Paulo de Rezende Pinatti (3):
util: introduce a parser for kernel cmdline arguments
qemu: check if s390 secure guest support is enabled
qemu: check if AMD secure guest support is enabled
Viktor Mihajlovski (1):
docs: Describe protected virtualization guest setup
docs/kbase.html.in | 3 +
docs/kbase/launch_security_sev.rst | 9 +-
docs/kbase/s390_protected_virt.rst | 189 +++++++++++++++++++++++++++++
src/libvirt_private.syms | 2 +
src/qemu/qemu_capabilities.c | 76 ++++++++++++
src/util/virutil.c | 169 ++++++++++++++++++++++++++
src/util/virutil.h | 17 +++
tests/utiltest.c | 141 +++++++++++++++++++++
tools/virt-host-validate-common.c | 83 ++++++++++++-
tools/virt-host-validate-common.h | 5 +
tools/virt-host-validate-qemu.c | 4 +
11 files changed, 693 insertions(+), 5 deletions(-)
create mode 100644 docs/kbase/s390_protected_virt.rst
--
2.25.4
4 years, 5 months
[libvirt PATCH] ci: Swap mipsel and ppc64le builds
by Andrea Bolognani
Debian sid is currently broken on mipsel, so use Debian 10 for
that architecture; at the same time, move the ppc64le build from
Debian 10 to Debian sid to keep things balanced.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
Pushed as a CI fix.
.gitlab-ci.yml | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0def25ff32..bfb66a652d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -257,12 +257,12 @@ mips64el-debian-10-container:
NAME: debian-10-cross-mips64el
mipsel-debian-10-container:
- <<: *container_optional_job_definition
+ <<: *container_extra_job_definition
variables:
NAME: debian-10-cross-mipsel
ppc64le-debian-10-container:
- <<: *container_extra_job_definition
+ <<: *container_optional_job_definition
variables:
NAME: debian-10-cross-ppc64le
@@ -302,12 +302,12 @@ mips64el-debian-sid-container:
NAME: debian-sid-cross-mips64el
mipsel-debian-sid-container:
- <<: *container_extra_job_definition
+ <<: *container_optional_job_definition
variables:
NAME: debian-sid-cross-mipsel
ppc64le-debian-sid-container:
- <<: *container_optional_job_definition
+ <<: *container_extra_job_definition
variables:
NAME: debian-sid-cross-ppc64le
@@ -426,11 +426,11 @@ aarch64-debian-10:
NAME: debian-10
CROSS: aarch64
-ppc64le-debian-10:
+mipsel-debian-10:
<<: *cross_build_extra_job_definition
variables:
NAME: debian-10
- CROSS: ppc64le
+ CROSS: mipsel
s390x-debian-10:
<<: *cross_build_default_job_definition
@@ -450,11 +450,11 @@ i686-debian-sid:
NAME: debian-sid
CROSS: i686
-mipsel-debian-sid:
+ppc64le-debian-sid:
<<: *cross_build_extra_job_definition
variables:
NAME: debian-sid
- CROSS: mipsel
+ CROSS: ppc64le
mingw32-fedora-rawhide:
<<: *cross_build_default_job_definition
--
2.25.4
4 years, 5 months
[libvirt PATCH v4 0/3] ci: Use GitLab container registry
by Andrea Bolognani
Changes from [v3]:
* use 'latest' as tag name, consistently with how we do it for other
repositories;
* name the various Dockerfiles the same as the lcitool host instead
of processing the name, which again is the same behavior seen in
other repositories;
* since we're running all builds as part of the same stage now,
there is no need to add an additional stage between 'containers'
and 'builds', so the corresponding patch has been dropped.
Changes from [v2]:
* use $CI_COMMIT_REF_SLUG instead of 'master' as tag name, so that
it's possible to test changes to the Dockerfiles that affect the
subsequent build jobs in a feature branch;
* add CentOS Stream;
* rename 'preliminary_checks' stage to 'sanity_checks'.
Changes from [v1]:
* only build containers necessary for extra jobs when said jobs
are actually going to run;
* rename container build jobs to '$arch-$os-container';
* rename 'other' stage to 'preliminary_checks' and move it before
native builds;
* simplify build system integration.
[v1] https://www.redhat.com/archives/libvir-list/2020-May/msg01183.html
[v2] https://www.redhat.com/archives/libvir-list/2020-June/msg00067.html
[v3] https://www.redhat.com/archives/libvir-list/2020-June/msg00412.html
Andrea Bolognani (3):
ci: Use variables to build image names
ci: Use GitLab container registry
ci: Update build system integration
.gitlab-ci.yml | 330 ++++++++++++++++--
ci/Makefile | 10 +-
ci/containers/README.rst | 14 +
ci/containers/libvirt-centos-7.Dockerfile | 137 ++++++++
ci/containers/libvirt-centos-8.Dockerfile | 108 ++++++
.../libvirt-centos-stream.Dockerfile | 109 ++++++
...libvirt-debian-10-cross-aarch64.Dockerfile | 122 +++++++
.../libvirt-debian-10-cross-armv6l.Dockerfile | 120 +++++++
.../libvirt-debian-10-cross-armv7l.Dockerfile | 121 +++++++
.../libvirt-debian-10-cross-i686.Dockerfile | 121 +++++++
.../libvirt-debian-10-cross-mips.Dockerfile | 121 +++++++
...ibvirt-debian-10-cross-mips64el.Dockerfile | 121 +++++++
.../libvirt-debian-10-cross-mipsel.Dockerfile | 121 +++++++
...libvirt-debian-10-cross-ppc64le.Dockerfile | 121 +++++++
.../libvirt-debian-10-cross-s390x.Dockerfile | 121 +++++++
ci/containers/libvirt-debian-10.Dockerfile | 112 ++++++
.../libvirt-debian-9-cross-aarch64.Dockerfile | 126 +++++++
.../libvirt-debian-9-cross-armv6l.Dockerfile | 124 +++++++
.../libvirt-debian-9-cross-armv7l.Dockerfile | 125 +++++++
.../libvirt-debian-9-cross-mips.Dockerfile | 125 +++++++
...libvirt-debian-9-cross-mips64el.Dockerfile | 125 +++++++
.../libvirt-debian-9-cross-mipsel.Dockerfile | 125 +++++++
.../libvirt-debian-9-cross-ppc64le.Dockerfile | 125 +++++++
.../libvirt-debian-9-cross-s390x.Dockerfile | 125 +++++++
ci/containers/libvirt-debian-9.Dockerfile | 116 ++++++
...ibvirt-debian-sid-cross-aarch64.Dockerfile | 122 +++++++
...libvirt-debian-sid-cross-armv6l.Dockerfile | 120 +++++++
...libvirt-debian-sid-cross-armv7l.Dockerfile | 121 +++++++
.../libvirt-debian-sid-cross-i686.Dockerfile | 121 +++++++
.../libvirt-debian-sid-cross-mips.Dockerfile | 121 +++++++
...bvirt-debian-sid-cross-mips64el.Dockerfile | 121 +++++++
...libvirt-debian-sid-cross-mipsel.Dockerfile | 120 +++++++
...ibvirt-debian-sid-cross-ppc64le.Dockerfile | 121 +++++++
.../libvirt-debian-sid-cross-s390x.Dockerfile | 121 +++++++
ci/containers/libvirt-debian-sid.Dockerfile | 112 ++++++
ci/containers/libvirt-fedora-31.Dockerfile | 109 ++++++
ci/containers/libvirt-fedora-32.Dockerfile | 109 ++++++
...rt-fedora-rawhide-cross-mingw32.Dockerfile | 130 +++++++
...rt-fedora-rawhide-cross-mingw64.Dockerfile | 130 +++++++
.../libvirt-fedora-rawhide.Dockerfile | 110 ++++++
ci/containers/libvirt-opensuse-151.Dockerfile | 109 ++++++
ci/containers/libvirt-ubuntu-1804.Dockerfile | 117 +++++++
ci/containers/libvirt-ubuntu-2004.Dockerfile | 113 ++++++
ci/containers/refresh | 41 +++
ci/list-images.sh | 24 +-
45 files changed, 5169 insertions(+), 48 deletions(-)
create mode 100644 ci/containers/README.rst
create mode 100644 ci/containers/libvirt-centos-7.Dockerfile
create mode 100644 ci/containers/libvirt-centos-8.Dockerfile
create mode 100644 ci/containers/libvirt-centos-stream.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10-cross-aarch64.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10-cross-armv6l.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10-cross-armv7l.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10-cross-i686.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10-cross-mips.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10-cross-mips64el.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10-cross-mipsel.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10-cross-ppc64le.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10-cross-s390x.Dockerfile
create mode 100644 ci/containers/libvirt-debian-10.Dockerfile
create mode 100644 ci/containers/libvirt-debian-9-cross-aarch64.Dockerfile
create mode 100644 ci/containers/libvirt-debian-9-cross-armv6l.Dockerfile
create mode 100644 ci/containers/libvirt-debian-9-cross-armv7l.Dockerfile
create mode 100644 ci/containers/libvirt-debian-9-cross-mips.Dockerfile
create mode 100644 ci/containers/libvirt-debian-9-cross-mips64el.Dockerfile
create mode 100644 ci/containers/libvirt-debian-9-cross-mipsel.Dockerfile
create mode 100644 ci/containers/libvirt-debian-9-cross-ppc64le.Dockerfile
create mode 100644 ci/containers/libvirt-debian-9-cross-s390x.Dockerfile
create mode 100644 ci/containers/libvirt-debian-9.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid-cross-aarch64.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid-cross-armv6l.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid-cross-armv7l.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid-cross-i686.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid-cross-mips.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid-cross-mips64el.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid-cross-mipsel.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid-cross-ppc64le.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid-cross-s390x.Dockerfile
create mode 100644 ci/containers/libvirt-debian-sid.Dockerfile
create mode 100644 ci/containers/libvirt-fedora-31.Dockerfile
create mode 100644 ci/containers/libvirt-fedora-32.Dockerfile
create mode 100644 ci/containers/libvirt-fedora-rawhide-cross-mingw32.Dockerfile
create mode 100644 ci/containers/libvirt-fedora-rawhide-cross-mingw64.Dockerfile
create mode 100644 ci/containers/libvirt-fedora-rawhide.Dockerfile
create mode 100644 ci/containers/libvirt-opensuse-151.Dockerfile
create mode 100644 ci/containers/libvirt-ubuntu-1804.Dockerfile
create mode 100644 ci/containers/libvirt-ubuntu-2004.Dockerfile
create mode 100755 ci/containers/refresh
--
2.25.4
4 years, 5 months
[libvirt PATCH v2 0/3] network: support NAT with IPv6
by Daniel P. Berrangé
The virtual network has never supported NAT with IPv6 since this feature
didn't exist at the time. NAT has been available since RHEL-7 vintage
though, and it is desirable to be able to use it.
This series enables it with
<forward mode=3D"nat">
<nat ipv6=3D"yes"/>
</forward>
Note that I do NOT actually change the default.xml to enable use of IPv6
because that will cause failure if the user has force disabled IPv6 on
their host kernel.
Of course our current default.xml is already broken if someone has done
the reverse and force disabled IPv4.
We've also long had a problem with guests bringing up the default
network with the same subnet as the host. We'll have this same issue
with IPv6 too.
On my prompting Laine proposed a way to deal with the clash by tearing
down a network, if we see a real host NIC get assigned the same subnet.
Meanwhile we also have complaints about the fact that libvirt does
anything todo with networking in the %post of the RPM.
I'm thinking that we can do something entirely different by introducing
a concept of "automatic subnet selection" into the virtual network.
Consider if we made default.xml be able to contain only:
<network>
<name>default</name>
<forward/>
<ip family=3D"ipv4" autoaddr=3D"yes">
<dhcp/>
</ip>
<ip family=3D"ipv6" autoaddr=3D"yes"/>
</network>
Conceptually this means
- Try to gimme a subnet with IPv4 and DHCP
- Try to gimme a subnet with IPv6 and RAs
Now when we start the virtual network
- If IPv4 is not enabled on host, don't assign addr
- Else
- Iterate N=3D1..254 to find a free range for IPv4
- Use 192.168.N.0/24 for subnet
- Use 192.168.N.1 for host IP
- Use 192.168.N.2 -> 192.168.N.254 for guest DHCP
- If IPv6 is not enabled on host, don't assign addr
- Else
- Generate NNNN:NNNN as 4 random bytes
- Use fd00:add:f00d:NNNN:NNNN::0/64 for IPv6 subnet
- Use fd00:add:f00d:NNNN:NNNN::1 for host IP
- Use route advertizement for IPv6 zero-conf
With NNNN:NNNN, even with 1000 guests running, we have just a 0.02%
chance of clashing with a guest for IPv6.
The "live" XML would always reflect the currently assigned addresses
Proactively monitor the address allocations of the host. If we see
a conflicting address appear, take down the dnsmasq intance, generate
a new subnet, bring dnsmasq back online.
Ideally we would have to bring the guest network links offline and
then online again to force DHCP re-assignment immediately.
In v2:
- Fix short circuit XML closing tag
- Fix error checking in enum conversion
- Fix docs typos
- Improve RNG schema
Daniel P. Berrang=C3=A9 (3):
util: add support for IPv6 masquerade rules
conf: add an attribute to turn on NAT for IPv6 virtual networks
network: wire up support for IPv6 NAT rules
docs/formatnetwork.html.in | 14 ++
docs/schemas/network.rng | 5 +
src/conf/network_conf.c | 30 ++-
src/conf/network_conf.h | 2 +
src/network/bridge_driver_linux.c | 23 +-
src/util/viriptables.c | 33 +--
.../nat-ipv6-masquerade-linux.args | 228 ++++++++++++++++++
.../nat-ipv6-masquerade.xml | 17 ++
tests/networkxml2firewalltest.c | 1 +
.../nat-network-forward-nat-ipv6.xml | 10 +
.../nat-network-forward-nat-ipv6.xml | 10 +
tests/networkxml2xmltest.c | 1 +
12 files changed, 342 insertions(+), 32 deletions(-)
create mode 100644 tests/networkxml2firewalldata/nat-ipv6-masquerade-linux.a=
rgs
create mode 100644 tests/networkxml2firewalldata/nat-ipv6-masquerade.xml
create mode 100644 tests/networkxml2xmlin/nat-network-forward-nat-ipv6.xml
create mode 100644 tests/networkxml2xmlout/nat-network-forward-nat-ipv6.xml
--=20
2.26.2
4 years, 5 months
[PATCH] conf: convert network_conf.c to use g_auto* pointers
by Laine Stump
This was mostly boilerplate conversion, but in one case I needed to
define several differently named char* to take the place of a single
char *tmp that was re-used multiple times, and in another place there
was a single char* that was used at the toplevel of the function, and
then later used repeatedly inside a for loop, so I defined a new
separate char* inside the loop.
Signed-off-by: Laine Stump <laine(a)redhat.com>
---
This should be applied on top of Dan's IPv6 NAT patch series (it was
reviewing that series that showed me this file hadn't yet been
converted).
src/conf/network_conf.c | 613 +++++++++++++++++-----------------------
src/conf/network_conf.h | 1 +
src/util/virxml.h | 1 +
3 files changed, 259 insertions(+), 356 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 1b89e2985d..ebe8a03262 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -306,8 +306,7 @@ virNetworkDefCopy(virNetworkDefPtr def,
virNetworkXMLOptionPtr xmlopt,
unsigned int flags)
{
- char *xml = NULL;
- virNetworkDefPtr newDef = NULL;
+ g_autofree char *xml = NULL;
if (!def) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -317,11 +316,9 @@ virNetworkDefCopy(virNetworkDefPtr def,
/* deep copy with a format/parse cycle */
if (!(xml = virNetworkDefFormat(def, xmlopt, flags)))
- goto cleanup;
- newDef = virNetworkDefParseString(xml, xmlopt);
- cleanup:
- VIR_FREE(xml);
- return newDef;
+ return NULL;
+
+ return virNetworkDefParseString(xml, xmlopt);
}
@@ -465,48 +462,43 @@ virNetworkDHCPRangeDefParseXML(const char *networkName,
{
virSocketAddrRangePtr addr = &range->addr;
xmlNodePtr cur = node->children;
- char *start = NULL, *end = NULL;
- int ret = -1;
+ g_autofree char *start = NULL;
+ g_autofree char *end = NULL;
if (!(start = virXMLPropString(node, "start"))) {
virReportError(VIR_ERR_XML_ERROR,
_("Missing 'start' attribute in dhcp range for network '%s'"),
networkName);
- goto cleanup;
+ return -1;
}
if (virSocketAddrParse(&addr->start, start, AF_UNSPEC) < 0)
- goto cleanup;
+ return -1;
if (!(end = virXMLPropString(node, "end"))) {
virReportError(VIR_ERR_XML_ERROR,
_("Missing 'end' attribute in dhcp range for network '%s'"),
networkName);
- goto cleanup;
+ return -1;
}
if (virSocketAddrParse(&addr->end, end, AF_UNSPEC) < 0)
- goto cleanup;
+ return -1;
/* do a sanity check of the range */
if (virSocketAddrGetRange(&addr->start, &addr->end, &ipdef->address,
virNetworkIPDefPrefix(ipdef)) < 0)
- goto cleanup;
+ return -1;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE &&
virXMLNodeNameEqual(cur, "lease")) {
if (virNetworkDHCPLeaseTimeDefParseXML(&range->lease, cur) < 0)
- goto cleanup;
+ return -1;
}
cur = cur->next;
}
- ret = 0;
-
- cleanup:
- VIR_FREE(start);
- VIR_FREE(end);
- return ret;
+ return 0;
}
@@ -517,11 +509,13 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
virNetworkDHCPHostDefPtr host,
bool partialOkay)
{
- char *mac = NULL, *name = NULL, *ip = NULL, *id = NULL;
+ g_autofree char *mac = NULL;
+ g_autofree char *name = NULL;
+ g_autofree char *ip = NULL;
+ g_autofree char *id = NULL;
virMacAddr addr;
virSocketAddr inaddr;
xmlNodePtr cur = node->children;
- int ret = -1;
mac = virXMLPropString(node, "mac");
if (mac != NULL) {
@@ -530,20 +524,20 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
_("Invalid to specify MAC address '%s' "
"in network '%s' IPv6 static host definition"),
mac, networkName);
- goto cleanup;
+ return -1;
}
if (virMacAddrParse(mac, &addr) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Cannot parse MAC address '%s' in network '%s'"),
mac, networkName);
- goto cleanup;
+ return -1;
}
if (virMacAddrIsMulticast(&addr)) {
virReportError(VIR_ERR_XML_ERROR,
_("expected unicast mac address, found "
"multicast '%s' in network '%s'"),
(const char *)mac, networkName);
- goto cleanup;
+ return -1;
}
}
@@ -554,7 +548,7 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("Invalid character '%c' in id '%s' of network '%s'"),
*cp, id, networkName);
- goto cleanup;
+ return -1;
}
}
@@ -563,7 +557,7 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("Cannot use host name '%s' in network '%s'"),
name, networkName);
- goto cleanup;
+ return -1;
}
ip = virXMLPropString(node, "ip");
@@ -572,7 +566,7 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
_("Invalid IP address in static host definition "
"for network '%s'"),
networkName);
- goto cleanup;
+ return -1;
}
if (partialOkay) {
@@ -583,7 +577,7 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
"must be specified for static host definition "
"in network '%s' "),
networkName);
- goto cleanup;
+ return -1;
}
} else {
/* normal usage - you need at least name (IPv6) or one of MAC
@@ -595,21 +589,21 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
_("Static host definition in IPv6 network '%s' "
"must have id or name attribute"),
networkName);
- goto cleanup;
+ return -1;
}
} else if (!(mac || name)) {
virReportError(VIR_ERR_XML_ERROR,
_("Static host definition in IPv4 network '%s' "
"must have mac or name attribute"),
networkName);
- goto cleanup;
+ return -1;
}
if (!ip) {
virReportError(VIR_ERR_XML_ERROR,
_("Missing IP address in static host definition "
"for network '%s'"),
networkName);
- goto cleanup;
+ return -1;
}
}
@@ -618,7 +612,7 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
virXMLNodeNameEqual(cur, "lease")) {
if (virNetworkDHCPLeaseTimeDefParseXML(&host->lease, cur) < 0)
- goto cleanup;
+ return -1;
}
cur = cur->next;
}
@@ -631,14 +625,9 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
name = NULL;
if (ip)
host->ip = inaddr;
- ret = 0;
- cleanup:
- VIR_FREE(mac);
- VIR_FREE(id);
- VIR_FREE(name);
- VIR_FREE(ip);
- return ret;
+ return 0;
+
}
@@ -676,8 +665,8 @@ virNetworkDHCPDefParseXML(const char *networkName,
} else if (VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET) &&
cur->type == XML_ELEMENT_NODE &&
virXMLNodeNameEqual(cur, "bootp")) {
- char *file;
- char *server;
+ g_autofree char *file = NULL;
+ g_autofree char *server = NULL;
virSocketAddr inaddr;
memset(&inaddr, 0, sizeof(inaddr));
@@ -689,14 +678,12 @@ virNetworkDHCPDefParseXML(const char *networkName,
if (server &&
virSocketAddrParse(&inaddr, server, AF_UNSPEC) < 0) {
- VIR_FREE(file);
- VIR_FREE(server);
goto cleanup;
}
def->bootfile = file;
+ file = NULL;
def->bootserver = inaddr;
- VIR_FREE(server);
}
cur = cur->next;
@@ -716,7 +703,7 @@ virNetworkDNSHostDefParseXML(const char *networkName,
bool partialOkay)
{
xmlNodePtr cur;
- char *ip;
+ g_autofree char *ip = NULL;
if (!(ip = virXMLPropString(node, "ip")) && !partialOkay) {
virReportError(VIR_ERR_XML_DETAIL,
@@ -729,17 +716,15 @@ virNetworkDNSHostDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_DETAIL,
_("Invalid IP address in network '%s' DNS HOST record"),
networkName);
- VIR_FREE(ip);
goto error;
}
- VIR_FREE(ip);
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE &&
virXMLNodeNameEqual(cur, "hostname")) {
if (cur->children != NULL) {
- char *name = (char *) xmlNodeGetContent(cur);
+ g_autofree char *name = (char *) xmlNodeGetContent(cur);
if (!name) {
virReportError(VIR_ERR_XML_DETAIL,
@@ -747,10 +732,8 @@ virNetworkDNSHostDefParseXML(const char *networkName,
networkName);
goto error;
}
- if (VIR_APPEND_ELEMENT(def->names, def->nnames, name) < 0) {
- VIR_FREE(name);
+ if (VIR_APPEND_ELEMENT(def->names, def->nnames, name) < 0)
goto error;
- }
}
}
cur = cur->next;
@@ -950,15 +933,14 @@ virNetworkDNSDefParseXML(const char *networkName,
xmlXPathContextPtr ctxt,
virNetworkDNSDefPtr def)
{
- xmlNodePtr *hostNodes = NULL;
- xmlNodePtr *srvNodes = NULL;
- xmlNodePtr *txtNodes = NULL;
- xmlNodePtr *fwdNodes = NULL;
- char *forwardPlainNames = NULL;
- char *enable = NULL;
+ g_autofree xmlNodePtr *hostNodes = NULL;
+ g_autofree xmlNodePtr *srvNodes = NULL;
+ g_autofree xmlNodePtr *txtNodes = NULL;
+ g_autofree xmlNodePtr *fwdNodes = NULL;
+ g_autofree char *forwardPlainNames = NULL;
+ g_autofree char *enable = NULL;
int nhosts, nsrvs, ntxts, nfwds;
size_t i;
- int ret = -1;
VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node;
@@ -971,7 +953,7 @@ virNetworkDNSDefParseXML(const char *networkName,
_("Invalid dns enable setting '%s' "
"in network '%s'"),
enable, networkName);
- goto cleanup;
+ return -1;
}
}
@@ -983,7 +965,7 @@ virNetworkDNSDefParseXML(const char *networkName,
_("Invalid dns forwardPlainNames setting '%s' "
"in network '%s'"),
forwardPlainNames, networkName);
- goto cleanup;
+ return -1;
}
}
@@ -992,14 +974,14 @@ virNetworkDNSDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <forwarder> element found in <dns> of network %s"),
networkName);
- goto cleanup;
+ return -1;
}
if (nfwds > 0) {
if (VIR_ALLOC_N(def->forwarders, nfwds) < 0)
- goto cleanup;
+ return -1;
for (i = 0; i < nfwds; i++) {
- char *addr = virXMLPropString(fwdNodes[i], "addr");
+ g_autofree char *addr = virXMLPropString(fwdNodes[i], "addr");
if (addr && virSocketAddrParse(&def->forwarders[i].addr,
addr, AF_UNSPEC) < 0) {
@@ -1007,17 +989,15 @@ virNetworkDNSDefParseXML(const char *networkName,
_("Invalid forwarder IP address '%s' "
"in network '%s'"),
addr, networkName);
- VIR_FREE(addr);
- goto cleanup;
+ return -1;
}
def->forwarders[i].domain = virXMLPropString(fwdNodes[i], "domain");
if (!(addr || def->forwarders[i].domain)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Invalid forwarder element, must contain "
"at least one of addr or domain"));
- goto cleanup;
+ return -1;
}
- VIR_FREE(addr);
def->nfwds++;
}
}
@@ -1027,16 +1007,16 @@ virNetworkDNSDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <host> element found in <dns> of network %s"),
networkName);
- goto cleanup;
+ return -1;
}
if (nhosts > 0) {
if (VIR_ALLOC_N(def->hosts, nhosts) < 0)
- goto cleanup;
+ return -1;
for (i = 0; i < nhosts; i++) {
if (virNetworkDNSHostDefParseXML(networkName, hostNodes[i],
&def->hosts[def->nhosts], false) < 0) {
- goto cleanup;
+ return -1;
}
def->nhosts++;
}
@@ -1047,16 +1027,16 @@ virNetworkDNSDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <srv> element found in <dns> of network %s"),
networkName);
- goto cleanup;
+ return -1;
}
if (nsrvs > 0) {
if (VIR_ALLOC_N(def->srvs, nsrvs) < 0)
- goto cleanup;
+ return -1;
for (i = 0; i < nsrvs; i++) {
if (virNetworkDNSSrvDefParseXML(networkName, srvNodes[i], ctxt,
&def->srvs[def->nsrvs], false) < 0) {
- goto cleanup;
+ return -1;
}
def->nsrvs++;
}
@@ -1067,16 +1047,16 @@ virNetworkDNSDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <txt> element found in <dns> of network %s"),
networkName);
- goto cleanup;
+ return -1;
}
if (ntxts > 0) {
if (VIR_ALLOC_N(def->txts, ntxts) < 0)
- goto cleanup;
+ return -1;
for (i = 0; i < ntxts; i++) {
if (virNetworkDNSTxtDefParseXML(networkName, txtNodes[i],
&def->txts[def->ntxts], false) < 0) {
- goto cleanup;
+ return -1;
}
def->ntxts++;
}
@@ -1087,18 +1067,10 @@ virNetworkDNSDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("Extra data in disabled network '%s'"),
networkName);
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- VIR_FREE(enable);
- VIR_FREE(forwardPlainNames);
- VIR_FREE(fwdNodes);
- VIR_FREE(hostNodes);
- VIR_FREE(srvNodes);
- VIR_FREE(txtNodes);
- return ret;
+ return 0;
}
@@ -1115,11 +1087,12 @@ virNetworkIPDefParseXML(const char *networkName,
VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr dhcp;
- char *address = NULL, *netmask = NULL;
+ g_autofree char *address = NULL;
+ g_autofree char *netmask = NULL;
+ g_autofree char *localPtr = NULL;
unsigned long prefix = 0;
int prefixRc;
- int result = -1;
- char *localPtr = NULL;
+ int ret = -1;
ctxt->node = node;
@@ -1243,16 +1216,13 @@ virNetworkIPDefParseXML(const char *networkName,
def->tftproot = virXPathString("string(./tftp[1]/@root)", ctxt);
}
- result = 0;
+ ret = 0;
cleanup:
- if (result < 0)
+ if (ret < 0)
virNetworkIPDefClear(def);
- VIR_FREE(address);
- VIR_FREE(netmask);
- VIR_FREE(localPtr);
- return result;
+ return ret;
}
@@ -1290,10 +1260,10 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def,
xmlNodePtr virtPortNode;
xmlNodePtr vlanNode;
xmlNodePtr bandwidth_node;
- char *isDefault = NULL;
- char *trustGuestRxFilters = NULL;
+ g_autofree char *isDefault = NULL;
+ g_autofree char *trustGuestRxFilters = NULL;
- int result = -1;
+ int ret = -1;
ctxt->node = node;
@@ -1335,14 +1305,12 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def,
if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0)
goto cleanup;
- result = 0;
+ ret = 0;
cleanup:
- if (result < 0)
+ if (ret < 0)
virPortGroupDefClear(def);
- VIR_FREE(isDefault);
- VIR_FREE(trustGuestRxFilters);
- return result;
+ return ret;
}
@@ -1352,13 +1320,12 @@ virNetworkForwardNatDefParseXML(const char *networkName,
xmlXPathContextPtr ctxt,
virNetworkForwardDefPtr def)
{
- int ret = -1;
- xmlNodePtr *natAddrNodes = NULL;
- xmlNodePtr *natPortNodes = NULL;
int nNatAddrs, nNatPorts;
- char *addrStart = NULL;
- char *addrEnd = NULL;
- char *ipv6 = NULL;
+ g_autofree xmlNodePtr *natAddrNodes = NULL;
+ g_autofree xmlNodePtr *natPortNodes = NULL;
+ g_autofree char *addrStart = NULL;
+ g_autofree char *addrEnd = NULL;
+ g_autofree char *ipv6 = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node;
@@ -1367,7 +1334,7 @@ virNetworkForwardNatDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("The <nat> element can only be used when <forward> 'mode' is 'nat' in network %s"),
networkName);
- goto cleanup;
+ return -1;
}
ipv6 = virXMLPropString(node, "ipv6");
@@ -1378,10 +1345,9 @@ virNetworkForwardNatDefParseXML(const char *networkName,
_("Invalid ipv6 setting '%s' "
"in network '%s' NAT"),
ipv6, networkName);
- goto cleanup;
+ return -1;
}
def->natIPv6 = natIPv6;
- VIR_FREE(ipv6);
}
/* addresses for SNAT */
@@ -1390,26 +1356,26 @@ virNetworkForwardNatDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <address> element found in <forward> of "
"network %s"), networkName);
- goto cleanup;
+ return -1;
} else if (nNatAddrs > 1) {
virReportError(VIR_ERR_XML_ERROR,
_("Only one <address> element is allowed in <nat> in "
"<forward> in network %s"), networkName);
- goto cleanup;
+ return -1;
} else if (nNatAddrs == 1) {
addrStart = virXMLPropString(*natAddrNodes, "start");
if (addrStart == NULL) {
virReportError(VIR_ERR_XML_ERROR,
_("missing 'start' attribute in <address> element in <nat> in "
"<forward> in network %s"), networkName);
- goto cleanup;
+ return -1;
}
addrEnd = virXMLPropString(*natAddrNodes, "end");
if (addrEnd == NULL) {
virReportError(VIR_ERR_XML_ERROR,
_("missing 'end' attribute in <address> element in <nat> in "
"<forward> in network %s"), networkName);
- goto cleanup;
+ return -1;
}
}
@@ -1417,34 +1383,34 @@ virNetworkForwardNatDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("Bad ipv4 start address '%s' in <nat> in <forward> in "
"network '%s'"), addrStart, networkName);
- goto cleanup;
+ return -1;
}
if (addrEnd && virSocketAddrParse(&def->addr.end, addrEnd, AF_INET) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Bad ipv4 end address '%s' in <nat> in <forward> in "
"network '%s'"), addrEnd, networkName);
- goto cleanup;
+ return -1;
}
if (addrStart && addrEnd) {
/* verify that start <= end */
if (virSocketAddrGetRange(&def->addr.start, &def->addr.end, NULL, 0) < 0)
- goto cleanup;
+ return -1;
} else {
if (addrStart) {
virReportError(VIR_ERR_XML_ERROR,
_("Only start address '%s' specified in <nat> in "
"<forward> in network '%s'"),
addrStart, networkName);
- goto cleanup;
+ return -1;
}
if (addrEnd) {
virReportError(VIR_ERR_XML_ERROR,
_("Only end address '%s' specified in <nat> in "
"<forward> in network '%s'"),
addrEnd, networkName);
- goto cleanup;
+ return -1;
}
}
@@ -1454,12 +1420,12 @@ virNetworkForwardNatDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <port> element found in <forward> of "
"network %s"), networkName);
- goto cleanup;
+ return -1;
} else if (nNatPorts > 1) {
virReportError(VIR_ERR_XML_ERROR,
_("Only one <port> element is allowed in <nat> in "
"<forward> in network %s"), networkName);
- goto cleanup;
+ return -1;
} else if (nNatPorts == 1) {
if (virXPathUInt("string(./port[1]/@start)", ctxt, &def->port.start) < 0
|| def->port.start > 65535) {
@@ -1468,24 +1434,17 @@ virNetworkForwardNatDefParseXML(const char *networkName,
_("Missing or invalid 'start' attribute in <port> "
"in <nat> in <forward> in network %s"),
networkName);
- goto cleanup;
+ return -1;
}
if (virXPathUInt("string(./port[1]/@end)", ctxt, &def->port.end) < 0
|| def->port.end > 65535 || def->port.end < def->port.start) {
virReportError(VIR_ERR_XML_DETAIL,
_("Missing or invalid 'end' attribute in <port> in "
"<nat> in <forward> in network %s"), networkName);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
-
- cleanup:
- VIR_FREE(addrStart);
- VIR_FREE(addrEnd);
- VIR_FREE(natAddrNodes);
- VIR_FREE(natPortNodes);
- return ret;
+ return 0;
}
@@ -1496,16 +1455,15 @@ virNetworkForwardDefParseXML(const char *networkName,
virNetworkForwardDefPtr def)
{
size_t i, j;
- int ret = -1;
- xmlNodePtr *forwardIfNodes = NULL;
- xmlNodePtr *forwardPfNodes = NULL;
- xmlNodePtr *forwardAddrNodes = NULL;
- xmlNodePtr *forwardNatNodes = NULL;
int nForwardIfs, nForwardAddrs, nForwardPfs, nForwardNats;
- char *forwardDev = NULL;
- char *forwardManaged = NULL;
- char *forwardDriverName = NULL;
- char *type = NULL;
+ g_autofree xmlNodePtr *forwardIfNodes = NULL;
+ g_autofree xmlNodePtr *forwardPfNodes = NULL;
+ g_autofree xmlNodePtr *forwardAddrNodes = NULL;
+ g_autofree xmlNodePtr *forwardNatNodes = NULL;
+ g_autofree char *forwardDev = NULL;
+ g_autofree char *forwardManaged = NULL;
+ g_autofree char *forwardDriverName = NULL;
+ g_autofree char *type = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node;
@@ -1516,9 +1474,8 @@ virNetworkForwardDefParseXML(const char *networkName,
if ((def->type = virNetworkForwardTypeFromString(type)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown forwarding type '%s'"), type);
- goto cleanup;
+ return -1;
}
- VIR_FREE(type);
}
forwardManaged = virXPathString("string(./@managed)", ctxt);
@@ -1537,7 +1494,7 @@ virNetworkForwardDefParseXML(const char *networkName,
_("Unknown forward <driver name='%s'/> "
"in network %s"),
forwardDriverName, networkName);
- goto cleanup;
+ return -1;
}
def->driverName = driverName;
}
@@ -1548,7 +1505,7 @@ virNetworkForwardDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <interface> element found in <forward> of network %s"),
networkName);
- goto cleanup;
+ return -1;
}
nForwardAddrs = virXPathNodeSet("./address", ctxt, &forwardAddrNodes);
@@ -1556,7 +1513,7 @@ virNetworkForwardDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <address> element found in <forward> of network %s"),
networkName);
- goto cleanup;
+ return -1;
}
nForwardPfs = virXPathNodeSet("./pf", ctxt, &forwardPfNodes);
@@ -1564,7 +1521,7 @@ virNetworkForwardDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <pf> element found in <forward> of network %s"),
networkName);
- goto cleanup;
+ return -1;
}
nForwardNats = virXPathNodeSet("./nat", ctxt, &forwardNatNodes);
@@ -1572,17 +1529,17 @@ virNetworkForwardDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("invalid <nat> element found in <forward> of network %s"),
networkName);
- goto cleanup;
+ return -1;
} else if (nForwardNats > 1) {
virReportError(VIR_ERR_XML_ERROR,
_("Only one <nat> element is allowed in <forward> of network %s"),
networkName);
- goto cleanup;
+ return -1;
} else if (nForwardNats == 1) {
if (virNetworkForwardNatDefParseXML(networkName,
*forwardNatNodes,
ctxt, def) < 0)
- goto cleanup;
+ return -1;
}
forwardDev = virXPathString("string(./@dev)", ctxt);
@@ -1591,12 +1548,12 @@ virNetworkForwardDefParseXML(const char *networkName,
_("the <forward> 'dev' attribute cannot be used when "
"<address> or <pf> sub-elements are present "
"in network %s"));
- goto cleanup;
+ return -1;
}
if (nForwardIfs > 0 || forwardDev) {
if (VIR_ALLOC_N(def->ifs, MAX(nForwardIfs, 1)) < 0)
- goto cleanup;
+ return -1;
if (forwardDev) {
def->ifs[0].device.dev = forwardDev;
@@ -1607,64 +1564,66 @@ virNetworkForwardDefParseXML(const char *networkName,
/* parse each <interface> */
for (i = 0; i < nForwardIfs; i++) {
- forwardDev = virXMLPropString(forwardIfNodes[i], "dev");
- if (!forwardDev) {
+ g_autofree char *forwardDevi = virXMLPropString(forwardIfNodes[i], "dev");
+
+ if (!forwardDevi) {
virReportError(VIR_ERR_XML_ERROR,
_("Missing required dev attribute in "
"<forward> <interface> element of network %s"),
networkName);
- goto cleanup;
+ return -1;
}
if ((i == 0) && (def->nifs == 1)) {
/* both <forward dev='x'> and <interface dev='x'/> are
* present. If they don't match, it's an error.
*/
- if (STRNEQ(forwardDev, def->ifs[0].device.dev)) {
+ if (STRNEQ(forwardDevi, def->ifs[0].device.dev)) {
virReportError(VIR_ERR_XML_ERROR,
_("<forward dev='%s'> must match first "
"<interface dev='%s'/> in network %s"),
def->ifs[0].device.dev,
- forwardDev, networkName);
- goto cleanup;
+ forwardDevi, networkName);
+ return -1;
}
- VIR_FREE(forwardDev);
continue;
}
for (j = 0; j < i; j++) {
- if (STREQ_NULLABLE(def->ifs[j].device.dev, forwardDev)) {
+ if (STREQ_NULLABLE(def->ifs[j].device.dev, forwardDevi)) {
virReportError(VIR_ERR_XML_ERROR,
_("interface '%s' can only be "
"listed once in network %s"),
- forwardDev, networkName);
- goto cleanup;
+ forwardDevi, networkName);
+ return -1;
}
}
- def->ifs[i].device.dev = forwardDev;
- forwardDev = NULL;
+ def->ifs[i].device.dev = forwardDevi;
+ forwardDevi = NULL;
def->ifs[i].type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV;
def->nifs++;
}
} else if (nForwardAddrs > 0) {
if (VIR_ALLOC_N(def->ifs, nForwardAddrs) < 0)
- goto cleanup;
+ return -1;
for (i = 0; i < nForwardAddrs; i++) {
- if (!(type = virXMLPropString(forwardAddrNodes[i], "type"))) {
+ g_autofree char *addrType = NULL;
+
+ if (!(addrType = virXMLPropString(forwardAddrNodes[i], "type"))) {
virReportError(VIR_ERR_XML_ERROR,
_("missing address type in network %s"),
networkName);
- goto cleanup;
+ return -1;
}
- if ((def->ifs[i].type = virNetworkForwardHostdevDeviceTypeFromString(type)) < 0) {
+ if ((def->ifs[i].type = virNetworkForwardHostdevDeviceTypeFromString(addrType)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown address type '%s' in network %s"),
- type, networkName);
- goto cleanup;
+ addrType, networkName);
+ return -1;
}
switch (def->ifs[i].type) {
@@ -1673,7 +1632,7 @@ virNetworkForwardDefParseXML(const char *networkName,
virPCIDeviceAddressPtr addr = &def->ifs[i].device.pci;
if (virPCIDeviceAddressParseXML(forwardAddrNodes[i], addr) < 0)
- goto cleanup;
+ return -1;
for (j = 0; j < i; j++) {
if (virPCIDeviceAddressEqual(addr, &def->ifs[j].device.pci)) {
@@ -1683,7 +1642,7 @@ virNetworkForwardDefParseXML(const char *networkName,
addr->domain, addr->bus,
addr->slot, addr->function,
networkName);
- goto cleanup;
+ return -1;
}
}
break;
@@ -1693,10 +1652,9 @@ virNetworkForwardDefParseXML(const char *networkName,
default:
virReportError(VIR_ERR_XML_ERROR,
_("unsupported address type '%s' in network %s"),
- type, networkName);
- goto cleanup;
+ addrType, networkName);
+ return -1;
}
- VIR_FREE(type);
def->nifs++;
}
@@ -1704,10 +1662,10 @@ virNetworkForwardDefParseXML(const char *networkName,
virReportError(VIR_ERR_XML_ERROR,
_("Only one <pf> element is allowed in <forward> of network %s"),
networkName);
- goto cleanup;
+ return -1;
} else if (nForwardPfs == 1) {
if (VIR_ALLOC_N(def->pfs, nForwardPfs) < 0)
- goto cleanup;
+ return -1;
forwardDev = virXMLPropString(*forwardPfNodes, "dev");
if (!forwardDev) {
@@ -1715,7 +1673,7 @@ virNetworkForwardDefParseXML(const char *networkName,
_("Missing required dev attribute "
"in <pf> element of network '%s'"),
networkName);
- goto cleanup;
+ return -1;
}
def->pfs->dev = forwardDev;
@@ -1723,17 +1681,7 @@ virNetworkForwardDefParseXML(const char *networkName,
def->npfs++;
}
- ret = 0;
- cleanup:
- VIR_FREE(type);
- VIR_FREE(forwardDev);
- VIR_FREE(forwardManaged);
- VIR_FREE(forwardDriverName);
- VIR_FREE(forwardPfNodes);
- VIR_FREE(forwardIfNodes);
- VIR_FREE(forwardAddrNodes);
- VIR_FREE(forwardNatNodes);
- return ret;
+ return 0;
}
@@ -1741,18 +1689,23 @@ virNetworkDefPtr
virNetworkDefParseXML(xmlXPathContextPtr ctxt,
virNetworkXMLOptionPtr xmlopt)
{
- virNetworkDefPtr def;
- char *tmp = NULL;
- char *stp = NULL;
- xmlNodePtr *ipNodes = NULL;
- xmlNodePtr *routeNodes = NULL;
- xmlNodePtr *portGroupNodes = NULL;
+ g_autoptr(virNetworkDef) def = NULL;
+ g_autofree char *uuid = NULL;
+ g_autofree char *localOnly = NULL;
+ g_autofree char *stp = NULL;
+ g_autofree char *stpDelay = NULL;
+ g_autofree char *macTableManager = NULL;
+ g_autofree char *macAddr = NULL;
+ g_autofree char *mtuSize = NULL;
+ g_autofree xmlNodePtr *ipNodes = NULL;
+ g_autofree xmlNodePtr *routeNodes = NULL;
+ g_autofree xmlNodePtr *portGroupNodes = NULL;
int nips, nPortGroups, nRoutes;
xmlNodePtr dnsNode = NULL;
xmlNodePtr virtPortNode = NULL;
xmlNodePtr forwardNode = NULL;
- char *ipv6nogwStr = NULL;
- char *trustGuestRxFilters = NULL;
+ g_autofree char *ipv6nogwStr = NULL;
+ g_autofree char *trustGuestRxFilters = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr bandwidthNode = NULL;
xmlNodePtr vlanNode;
@@ -1765,27 +1718,26 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
def->name = virXPathString("string(./name[1])", ctxt);
if (!def->name) {
virReportError(VIR_ERR_NO_NAME, NULL);
- goto error;
+ return NULL;
}
if (virXMLCheckIllegalChars("name", def->name, "/") < 0)
- goto error;
+ return NULL;
/* Extract network uuid */
- tmp = virXPathString("string(./uuid[1])", ctxt);
- if (!tmp) {
+ uuid = virXPathString("string(./uuid[1])", ctxt);
+ if (!uuid) {
if (virUUIDGenerate(def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate UUID"));
- goto error;
+ return NULL;
}
} else {
- if (virUUIDParse(tmp, def->uuid) < 0) {
+ if (virUUIDParse(uuid, def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed uuid element"));
- goto error;
+ return NULL;
}
- VIR_FREE(tmp);
def->uuid_specified = true;
}
@@ -1798,9 +1750,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
virReportError(VIR_ERR_XML_ERROR,
_("Invalid ipv6 setting '%s' in network '%s'"),
ipv6nogwStr, def->name);
- goto error;
+ return NULL;
}
- VIR_FREE(ipv6nogwStr);
}
trustGuestRxFilters
@@ -1812,36 +1763,34 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
_("Invalid trustGuestRxFilters setting '%s' "
"in network '%s'"),
trustGuestRxFilters, def->name);
- goto error;
+ return NULL;
}
- VIR_FREE(trustGuestRxFilters);
}
/* Parse network domain information */
def->domain = virXPathString("string(./domain[1]/@name)", ctxt);
- tmp = virXPathString("string(./domain[1]/@localOnly)", ctxt);
- if (tmp) {
- def->domainLocalOnly = virTristateBoolTypeFromString(tmp);
+ localOnly = virXPathString("string(./domain[1]/@localOnly)", ctxt);
+ if (localOnly) {
+ def->domainLocalOnly = virTristateBoolTypeFromString(localOnly);
if (def->domainLocalOnly <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid domain localOnly setting '%s' "
"in network '%s'"),
- tmp, def->name);
- goto error;
+ localOnly, def->name);
+ return NULL;
}
- VIR_FREE(tmp);
}
if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) &&
virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidthNode, false) < 0)
- goto error;
+ return NULL;
vlanNode = virXPathNode("./vlan", ctxt);
if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0)
- goto error;
+ return NULL;
if (virNetworkPortOptionsParseXML(ctxt, &def->isolatedPort) < 0)
- goto error;
+ return NULL;
/* Parse bridge information */
def->bridge = virXPathString("string(./bridge[1]/@name)", ctxt);
@@ -1849,124 +1798,118 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
stp = virXPathString("string(./bridge[1]/@stp)", ctxt);
def->stp = (stp && STREQ(stp, "off")) ? false : true;
- tmp = virXPathString("string(./bridge[1]/@delay)", ctxt);
- if (tmp) {
- if (virStrToLong_ulp(tmp, NULL, 10, &def->delay) < 0) {
+ stpDelay = virXPathString("string(./bridge[1]/@delay)", ctxt);
+ if (stpDelay) {
+ if (virStrToLong_ulp(stpDelay, NULL, 10, &def->delay) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid delay value in network '%s'"),
def->name);
- goto error;
+ return NULL;
}
}
- VIR_FREE(tmp);
- tmp = virXPathString("string(./bridge[1]/@macTableManager)", ctxt);
- if (tmp) {
+ macTableManager = virXPathString("string(./bridge[1]/@macTableManager)", ctxt);
+ if (macTableManager) {
if ((def->macTableManager
- = virNetworkBridgeMACTableManagerTypeFromString(tmp)) <= 0) {
+ = virNetworkBridgeMACTableManagerTypeFromString(macTableManager)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid macTableManager setting '%s' "
- "in network '%s'"), tmp, def->name);
- goto error;
+ "in network '%s'"), macTableManager, def->name);
+ return NULL;
}
- VIR_FREE(tmp);
}
- tmp = virXPathString("string(./mac[1]/@address)", ctxt);
- if (tmp) {
- if (virMacAddrParse(tmp, &def->mac) < 0) {
+ macAddr = virXPathString("string(./mac[1]/@address)", ctxt);
+ if (macAddr) {
+ if (virMacAddrParse(macAddr, &def->mac) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid bridge mac address '%s' in network '%s'"),
- tmp, def->name);
- goto error;
+ macAddr, def->name);
+ return NULL;
}
if (virMacAddrIsMulticast(&def->mac)) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid multicast bridge mac address '%s' in network '%s'"),
- tmp, def->name);
- goto error;
+ macAddr, def->name);
+ return NULL;
}
- VIR_FREE(tmp);
def->mac_specified = true;
}
- tmp = virXPathString("string(./mtu/@size)", ctxt);
- if (tmp) {
- if (virStrToLong_ui(tmp, NULL, 10, &def->mtu) < 0) {
+ mtuSize = virXPathString("string(./mtu/@size)", ctxt);
+ if (mtuSize) {
+ if (virStrToLong_ui(mtuSize, NULL, 10, &def->mtu) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid mtu size '%s' in network '%s'"),
- tmp, def->name);
- goto error;
+ mtuSize, def->name);
+ return NULL;
}
}
- VIR_FREE(tmp);
dnsNode = virXPathNode("./dns", ctxt);
if (dnsNode != NULL &&
virNetworkDNSDefParseXML(def->name, dnsNode, ctxt, &def->dns) < 0) {
- goto error;
+ return NULL;
}
virtPortNode = virXPathNode("./virtualport", ctxt);
if (virtPortNode &&
(!(def->virtPortProfile = virNetDevVPortProfileParse(virtPortNode,
VIR_VPORT_XML_REQUIRE_TYPE)))) {
- goto error;
+ return NULL;
}
nPortGroups = virXPathNodeSet("./portgroup", ctxt, &portGroupNodes);
if (nPortGroups < 0)
- goto error;
+ return NULL;
if (nPortGroups > 0) {
size_t i;
/* allocate array to hold all the portgroups */
if (VIR_ALLOC_N(def->portGroups, nPortGroups) < 0)
- goto error;
+ return NULL;
/* parse each portgroup */
for (i = 0; i < nPortGroups; i++) {
if (virNetworkPortGroupParseXML(&def->portGroups[i],
portGroupNodes[i],
ctxt) < 0)
- goto error;
+ return NULL;
def->nPortGroups++;
}
}
- VIR_FREE(portGroupNodes);
nips = virXPathNodeSet("./ip", ctxt, &ipNodes);
if (nips < 0)
- goto error;
+ return NULL;
if (nips > 0) {
size_t i;
/* allocate array to hold all the addrs */
if (VIR_ALLOC_N(def->ips, nips) < 0)
- goto error;
+ return NULL;
/* parse each addr */
for (i = 0; i < nips; i++) {
if (virNetworkIPDefParseXML(def->name,
ipNodes[i],
ctxt,
&def->ips[i]) < 0)
- goto error;
+ return NULL;
def->nips++;
}
}
- VIR_FREE(ipNodes);
nRoutes = virXPathNodeSet("./route", ctxt, &routeNodes);
if (nRoutes < 0)
- goto error;
+ return NULL;
if (nRoutes > 0) {
size_t i;
/* allocate array to hold all the route definitions */
if (VIR_ALLOC_N(def->routes, nRoutes) < 0)
- goto error;
+ return NULL;
/* parse each definition */
for (i = 0; i < nRoutes; i++) {
virNetDevIPRoutePtr route = NULL;
@@ -1974,7 +1917,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
if (!(route = virNetDevIPRouteParseXML(def->name,
routeNodes[i],
ctxt)))
- goto error;
+ return NULL;
def->routes[i] = route;
def->nroutes++;
}
@@ -2011,21 +1954,19 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
}
}
if (!addrMatch) {
- char *gw = virSocketAddrFormat(gateway);
+ g_autofree char *gw = virSocketAddrFormat(gateway);
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unreachable static route gateway '%s' specified for network '%s'"),
gw, def->name);
- VIR_FREE(gw);
- goto error;
+ return NULL;
}
}
}
- VIR_FREE(routeNodes);
forwardNode = virXPathNode("./forward", ctxt);
if (forwardNode &&
virNetworkForwardDefParseXML(def->name, forwardNode, ctxt, &def->forward) < 0) {
- goto error;
+ return NULL;
}
/* Validate some items in the main NetworkDef that need to align
@@ -2047,14 +1988,14 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
"but no IP address provided for network '%s'"),
virNetworkForwardTypeToString(def->forward.type),
def->name);
- goto error;
+ return NULL;
}
if (def->forward.nifs > 1) {
virReportError(VIR_ERR_XML_ERROR,
_("multiple forwarding interfaces specified "
"for network '%s', only one is supported"),
def->name);
- goto error;
+ return NULL;
}
if (def->forward.type == VIR_NETWORK_FORWARD_OPEN && def->forward.nifs) {
@@ -2067,7 +2008,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
"network '%s' with forward mode='%s'"),
def->name,
virNetworkForwardTypeToString(def->forward.type));
- goto error;
+ return NULL;
}
break;
@@ -2080,14 +2021,14 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
_("bridge name not allowed in %s mode (network '%s')"),
virNetworkForwardTypeToString(def->forward.type),
def->name);
- goto error;
+ return NULL;
}
if (def->bridgeZone) {
virReportError(VIR_ERR_XML_ERROR,
_("bridge zone not allowed in %s mode (network '%s')"),
virNetworkForwardTypeToString(def->forward.type),
def->name);
- goto error;
+ return NULL;
}
if (def->macTableManager) {
virReportError(VIR_ERR_XML_ERROR,
@@ -2095,7 +2036,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
"in %s mode (network '%s')"),
virNetworkForwardTypeToString(def->forward.type),
def->name);
- goto error;
+ return NULL;
}
G_GNUC_FALLTHROUGH;
@@ -2107,7 +2048,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
"(network '%s')"),
virNetworkForwardTypeToString(def->forward.type),
def->name);
- goto error;
+ return NULL;
}
if (def->bridge && (def->forward.nifs || def->forward.npfs)) {
virReportError(VIR_ERR_XML_ERROR,
@@ -2116,18 +2057,16 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
"both (network '%s')"),
virNetworkForwardTypeToString(def->forward.type),
def->name);
- goto error;
+ return NULL;
}
break;
case VIR_NETWORK_FORWARD_LAST:
default:
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
- goto error;
+ return NULL;
}
- VIR_FREE(stp);
-
if (def->mtu) {
switch ((virNetworkForwardType) def->forward.type) {
case VIR_NETWORK_FORWARD_NONE:
@@ -2146,12 +2085,12 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
"and isolated mode, not in %s (network '%s')"),
virNetworkForwardTypeToString(def->forward.type),
def->name);
- goto error;
+ return NULL;
case VIR_NETWORK_FORWARD_LAST:
default:
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
- goto error;
+ return NULL;
}
}
@@ -2165,23 +2104,12 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
def->ns = xmlopt->ns;
if (def->ns.parse) {
if (virXMLNamespaceRegister(ctxt, &def->ns) < 0)
- goto error;
+ return NULL;
if ((def->ns.parse)(ctxt, &def->namespaceData) < 0)
- goto error;
+ return NULL;
}
- return def;
-
- error:
- VIR_FREE(tmp);
- VIR_FREE(routeNodes);
- VIR_FREE(stp);
- virNetworkDefFree(def);
- VIR_FREE(ipNodes);
- VIR_FREE(portGroupNodes);
- VIR_FREE(ipv6nogwStr);
- VIR_FREE(trustGuestRxFilters);
- return NULL;
+ return g_steal_pointer(&def);
}
@@ -2190,14 +2118,12 @@ virNetworkDefParse(const char *xmlStr,
const char *filename,
virNetworkXMLOptionPtr xmlopt)
{
- xmlDocPtr xml;
+ g_autoptr(xmlDoc) xml = NULL;
virNetworkDefPtr def = NULL;
int keepBlanksDefault = xmlKeepBlanksDefault(0);
- if ((xml = virXMLParse(filename, xmlStr, _("(network_definition)")))) {
+ if ((xml = virXMLParse(filename, xmlStr, _("(network_definition)"))))
def = virNetworkDefParseNode(xml, xmlDocGetRootElement(xml), xmlopt);
- xmlFreeDoc(xml);
- }
xmlKeepBlanksDefault(keepBlanksDefault);
return def;
@@ -2292,13 +2218,12 @@ virNetworkDNSDefFormat(virBufferPtr buf,
def->forwarders[i].domain);
}
if (VIR_SOCKET_ADDR_VALID(&def->forwarders[i].addr)) {
- char *addr = virSocketAddrFormat(&def->forwarders[i].addr);
+ g_autofree char *addr = virSocketAddrFormat(&def->forwarders[i].addr);
- if (!addr)
- return -1;
+ if (!addr)
+ return -1;
- virBufferAsprintf(buf, " addr='%s'", addr);
- VIR_FREE(addr);
+ virBufferAsprintf(buf, " addr='%s'", addr);
}
virBufferAddLit(buf, "/>\n");
}
@@ -2331,7 +2256,7 @@ virNetworkDNSDefFormat(virBufferPtr buf,
if (def->nhosts) {
for (i = 0; i < def->nhosts; i++) {
- char *ip = virSocketAddrFormat(&def->hosts[i].ip);
+ g_autofree char *ip = virSocketAddrFormat(&def->hosts[i].ip);
virBufferAsprintf(buf, "<host ip='%s'>\n", ip);
virBufferAdjustIndent(buf, 2);
@@ -2341,7 +2266,6 @@ virNetworkDNSDefFormat(virBufferPtr buf,
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</host>\n");
- VIR_FREE(ip);
}
}
virBufferAdjustIndent(buf, -2);
@@ -2359,18 +2283,16 @@ virNetworkIPDefFormat(virBufferPtr buf,
if (def->family)
virBufferAsprintf(buf, " family='%s'", def->family);
if (VIR_SOCKET_ADDR_VALID(&def->address)) {
- char *addr = virSocketAddrFormat(&def->address);
+ g_autofree char *addr = virSocketAddrFormat(&def->address);
if (!addr)
return -1;
virBufferAsprintf(buf, " address='%s'", addr);
- VIR_FREE(addr);
}
if (VIR_SOCKET_ADDR_VALID(&def->netmask)) {
- char *addr = virSocketAddrFormat(&def->netmask);
+ g_autofree char *addr = virSocketAddrFormat(&def->netmask);
if (!addr)
return -1;
virBufferAsprintf(buf, " netmask='%s'", addr);
- VIR_FREE(addr);
}
if (def->prefix > 0)
virBufferAsprintf(buf, " prefix='%u'", def->prefix);
@@ -2395,15 +2317,15 @@ virNetworkIPDefFormat(virBufferPtr buf,
for (i = 0; i < def->nranges; i++) {
virSocketAddrRange addr = def->ranges[i].addr;
virNetworkDHCPLeaseTimeDefPtr lease = def->ranges[i].lease;
+ g_autofree char *saddr = NULL;
+ g_autofree char *eaddr = NULL;
- char *saddr = virSocketAddrFormat(&addr.start);
- if (!saddr)
+ if (!(saddr = virSocketAddrFormat(&addr.start)))
return -1;
- char *eaddr = virSocketAddrFormat(&addr.end);
- if (!eaddr) {
- VIR_FREE(saddr);
+
+ if (!(eaddr = virSocketAddrFormat(&addr.end)))
return -1;
- }
+
virBufferAsprintf(buf, "<range start='%s' end='%s'",
saddr, eaddr);
if (lease) {
@@ -2421,8 +2343,6 @@ virNetworkIPDefFormat(virBufferPtr buf,
} else {
virBufferAddLit(buf, "/>\n");
}
- VIR_FREE(saddr);
- VIR_FREE(eaddr);
}
for (i = 0; i < def->nhosts; i++) {
virNetworkDHCPLeaseTimeDefPtr lease = def->hosts[i].lease;
@@ -2434,11 +2354,11 @@ virNetworkIPDefFormat(virBufferPtr buf,
if (def->hosts[i].name)
virBufferAsprintf(buf, " name='%s'", def->hosts[i].name);
if (VIR_SOCKET_ADDR_VALID(&def->hosts[i].ip)) {
- char *ipaddr = virSocketAddrFormat(&def->hosts[i].ip);
+ g_autofree char *ipaddr = virSocketAddrFormat(&def->hosts[i].ip);
if (!ipaddr)
return -1;
+
virBufferAsprintf(buf, " ip='%s'", ipaddr);
- VIR_FREE(ipaddr);
}
if (lease) {
virBufferAddLit(buf, ">\n");
@@ -2460,11 +2380,11 @@ virNetworkIPDefFormat(virBufferPtr buf,
virBufferEscapeString(buf, "<bootp file='%s'",
def->bootfile);
if (VIR_SOCKET_ADDR_VALID(&def->bootserver)) {
- char *ipaddr = virSocketAddrFormat(&def->bootserver);
+ g_autofree char *ipaddr = virSocketAddrFormat(&def->bootserver);
if (!ipaddr)
return -1;
+
virBufferEscapeString(buf, " server='%s'", ipaddr);
- VIR_FREE(ipaddr);
}
virBufferAddLit(buf, "/>\n");
@@ -2515,20 +2435,19 @@ static int
virNetworkForwardNatDefFormat(virBufferPtr buf,
const virNetworkForwardDef *fwd)
{
- char *addrStart = NULL;
- char *addrEnd = NULL;
- int ret = -1;
+ g_autofree char *addrStart = NULL;
+ g_autofree char *addrEnd = NULL;
if (VIR_SOCKET_ADDR_VALID(&fwd->addr.start)) {
addrStart = virSocketAddrFormat(&fwd->addr.start);
if (!addrStart)
- goto cleanup;
+ return -1;
}
if (VIR_SOCKET_ADDR_VALID(&fwd->addr.end)) {
addrEnd = virSocketAddrFormat(&fwd->addr.end);
if (!addrEnd)
- goto cleanup;
+ return -1;
}
if (!addrEnd && !addrStart && !fwd->port.start && !fwd->port.end && !fwd->natIPv6)
@@ -2561,12 +2480,7 @@ virNetworkForwardNatDefFormat(virBufferPtr buf,
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</nat>\n");
- ret = 0;
-
- cleanup:
- VIR_FREE(addrStart);
- VIR_FREE(addrEnd);
- return ret;
+ return 0;
}
@@ -2856,27 +2770,22 @@ virNetworkSaveXML(const char *configDir,
const char *xml)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *configFile = NULL;
- int ret = -1;
+ g_autofree char *configFile = NULL;
if ((configFile = virNetworkConfigFile(configDir, def->name)) == NULL)
- goto cleanup;
+ return -1;
if (virFileMakePath(configDir) < 0) {
virReportSystemError(errno,
_("cannot create config directory '%s'"),
configDir);
- goto cleanup;
+ return -1;
}
virUUIDFormat(def->uuid, uuidstr);
- ret = virXMLSaveFile(configFile,
- virXMLPickShellSafeComment(def->name, uuidstr),
- "net-edit", xml);
-
- cleanup:
- VIR_FREE(configFile);
- return ret;
+ return virXMLSaveFile(configFile,
+ virXMLPickShellSafeComment(def->name, uuidstr),
+ "net-edit", xml);
}
@@ -2885,19 +2794,15 @@ virNetworkSaveConfig(const char *configDir,
virNetworkDefPtr def,
virNetworkXMLOptionPtr xmlopt)
{
- int ret = -1;
- char *xml;
+ g_autofree char *xml = NULL;
if (!(xml = virNetworkDefFormat(def, xmlopt, VIR_NETWORK_XML_INACTIVE)))
- goto cleanup;
+ return -1;
if (virNetworkSaveXML(configDir, def, xml))
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- VIR_FREE(xml);
- return ret;
+ return 0;
}
@@ -3113,14 +3018,13 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
}
if (i == ipdef->nhosts) {
- char *ip = virSocketAddrFormat(&host.ip);
+ g_autofree char *ip = virSocketAddrFormat(&host.ip);
virReportError(VIR_ERR_OPERATION_INVALID,
_("couldn't locate an existing dhcp host entry with "
"\"mac='%s'\" \"name='%s'\" \"ip='%s'\" in"
" network '%s'"),
host.mac ? host.mac : _("unknown"), host.name,
ip ? ip : _("unknown"), def->name);
- VIR_FREE(ip);
goto cleanup;
}
@@ -3146,7 +3050,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
STREQ_NULLABLE(host.name, ipdef->hosts[i].name)) ||
(VIR_SOCKET_ADDR_VALID(&host.ip) &&
virSocketAddrEqual(&host.ip, &ipdef->hosts[i].ip))) {
- char *ip = virSocketAddrFormat(&host.ip);
+ g_autofree char *ip = virSocketAddrFormat(&host.ip);
virReportError(VIR_ERR_OPERATION_INVALID,
_("there is an existing dhcp host entry in "
@@ -3154,7 +3058,6 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
"\"<host mac='%s' name='%s' ip='%s'/>\""),
def->name, host.mac ? host.mac : _("unknown"),
host.name, ip ? ip : _("unknown"));
- VIR_FREE(ip);
goto cleanup;
}
}
@@ -3258,8 +3161,8 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDefPtr def,
return -1;
if (i < ipdef->nranges) {
- char *startip = virSocketAddrFormat(&range.addr.start);
- char *endip = virSocketAddrFormat(&range.addr.end);
+ g_autofree char *startip = virSocketAddrFormat(&range.addr.start);
+ g_autofree char *endip = virSocketAddrFormat(&range.addr.end);
virReportError(VIR_ERR_OPERATION_INVALID,
_("there is an existing dhcp range entry in "
@@ -3268,8 +3171,6 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDefPtr def,
def->name,
startip ? startip : "unknown",
endip ? endip : "unknown");
- VIR_FREE(startip);
- VIR_FREE(endip);
return -1;
}
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index e3a61c62ea..34b9aa9505 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -321,6 +321,7 @@ typedef enum {
} virNetworkTaintFlags;
void virNetworkDefFree(virNetworkDefPtr def);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkDef, virNetworkDefFree);
enum {
VIR_NETWORK_OBJ_LIST_ADD_LIVE = (1 << 0),
diff --git a/src/util/virxml.h b/src/util/virxml.h
index 26ab9f9c2d..ed178105f6 100644
--- a/src/util/virxml.h
+++ b/src/util/virxml.h
@@ -247,6 +247,7 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, virXPathContextNodeRes
G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlDoc, xmlFreeDoc);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlXPathContext, xmlXPathFreeContext);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlBuffer, xmlBufferFree);
typedef int (*virXMLNamespaceParse)(xmlXPathContextPtr ctxt, void **nsdata);
typedef void (*virXMLNamespaceFree)(void *nsdata);
--
2.25.4
4 years, 5 months
Re: Libvirt compile issues
by K. Kahurani
On Wed, Jun 03, 2020 at 12:24:27PM +0100, Daniel P. Berrangé wrote:
> On Tue, Jun 02, 2020 at 03:30:00PM +0300, K. Kahurani wrote:
> > ---------- Forwarded message ---------
> > From: K. Kahurani <k.kahurani(a)gmail.com>
> > Date: Sun, May 31, 2020 at 2:26 PM
> > Subject: Hello
> > To: <eblake(a)redhat.com>
> >
> >
> > Hello,
> >
> > Hopefully this finds you well.
> >
> > This is not a bug report but more or less an inquiry as based on the
> > information acquired from Jim Fehlig a while back, it is possible you would
> > have some important information regarding this.
> >
> > It is currently not possible for me to compile libvirt right from the word
> > go while configuring with the error [1]. From the look of it and a bit of
> > searching on the internet, it does look like the package portablexdr is
> > obsolete.
> >
> > Could it be that this is a known issue? Could it be there already is a
> > workaround this? Do you suppose this should go into the mailing list?
> >
> > [1]
> > checking for WIRESHARK_DISSECTOR... no
> > checking for xdrmem_create in -lportablexdr... no
> > checking for library containing xdrmem_create... no
> > configure: error: Cannot find a XDR library
>
> You're missing a build pre-requisite library for XDR. On Linux distros
> this is provided by "tirpc" these days, try libtirpc-devel RPM or
> libtirpc-dev Debian package.
Thanks a lot!
My distribution/distro is openSUSE.
Posting this here, for list purposes as someone might find it worthwhile.
$zypper in libpciaccess-devel device-mapper-devel rst2html5 libtirpc-devel rpcgen
Other packages were probably already installed.
$zypper addrepo https://download.opensuse.org/repositories/Publishing/openSUSE_Tumbleweed...
Had to add the above repo for package rst2html5
Sincerely,
David
>
>
> Regards,
> Daniel
> --
> |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o- https://fstop138.berrange.com :|
> |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
>
4 years, 5 months
[PATCH 0/7] More cleanups of unused and uninitialized variables
by Peter Krempa
Recent commit showed that compilers are not able to detect unused
variables when passed to VIR_FREE, so I fixed all the other instances
the patch didn't fix.
Peter Krempa (7):
libxlDomainMigrationDstPrepareDef: remove use of temporary variable
testVirFindSCSIHostByPCI: Remove unused 'path_addr'
cputest: Avoid use of temporary variable in DO_TEST macro
virTPMEmulatorInit: Don't use temporary variable to free path
remoteDispatchDomainMigratePrepare: Don't pass uninitialized variable
to VIR_FREE
vboxDomainScreenshot: Don't pass uninitialized 'screenData' to
VIR_FREE
Remove use of variables passed only to 'VIR_FREE'
src/libxl/libxl_migration.c | 4 +---
src/locking/sanlock_helper.c | 2 --
src/logging/log_daemon.c | 2 --
src/nwfilter/nwfilter_ebiptables_driver.c | 2 --
src/openvz/openvz_driver.c | 2 --
src/remote/remote_daemon_dispatch.c | 2 +-
src/security/security_selinux.c | 2 --
src/test/test_driver.c | 2 --
src/util/virstorageencryption.c | 4 ----
src/util/virsysinfo.c | 2 --
src/util/virtpm.c | 5 +----
src/vbox/vbox_common.c | 2 +-
src/vmware/vmware_conf.c | 4 ----
src/vmware/vmware_driver.c | 4 ----
tests/cputest.c | 4 +---
tests/networkxml2firewalltest.c | 2 --
tests/scsihosttest.c | 4 ----
tests/xmconfigtest.c | 2 --
tools/virsh-checkpoint.c | 2 --
19 files changed, 5 insertions(+), 48 deletions(-)
--
2.26.2
4 years, 5 months
[libvirt PATCH v3 0/4] ci: Use GitLab container registry
by Andrea Bolognani
Changes from [v2]:
* use $CI_COMMIT_REF_SLUG instead of 'master' as tag name, so that
it's possible to test changes to the Dockerfiles that affect the
subsequent build jobs in a feature branch;
* add CentOS Stream;
* rename 'preliminary_checks' stage to 'sanity_checks'.
Changes from [v1]:
* only build containers necessary for extra jobs when said jobs
are actually going to run;
* rename container build jobs to '$arch-$os-container';
* rename 'other' stage to 'preliminary_checks' and move it before
native builds;
* simplify build system integration.
[v1] https://www.redhat.com/archives/libvir-list/2020-May/msg01183.html
[v2] https://www.redhat.com/archives/libvir-list/2020-June/msg00067.html
Andrea Bolognani (4):
ci: Use variables to build image names
ci: Add 'sanity_checks' stage
ci: Use GitLab container registry
ci: Update build system integration
.gitlab-ci.yml | 333 ++++++++++++++++--
ci/Makefile | 10 +-
ci/containers/README.rst | 14 +
ci/containers/ci-centos-7.Dockerfile | 137 +++++++
ci/containers/ci-centos-8.Dockerfile | 108 ++++++
ci/containers/ci-centos-stream.Dockerfile | 109 ++++++
.../ci-debian-10-cross-aarch64.Dockerfile | 122 +++++++
.../ci-debian-10-cross-armv6l.Dockerfile | 120 +++++++
.../ci-debian-10-cross-armv7l.Dockerfile | 121 +++++++
.../ci-debian-10-cross-i686.Dockerfile | 121 +++++++
.../ci-debian-10-cross-mips.Dockerfile | 121 +++++++
.../ci-debian-10-cross-mips64el.Dockerfile | 121 +++++++
.../ci-debian-10-cross-mipsel.Dockerfile | 121 +++++++
.../ci-debian-10-cross-ppc64le.Dockerfile | 121 +++++++
.../ci-debian-10-cross-s390x.Dockerfile | 121 +++++++
ci/containers/ci-debian-10.Dockerfile | 112 ++++++
.../ci-debian-9-cross-aarch64.Dockerfile | 126 +++++++
.../ci-debian-9-cross-armv6l.Dockerfile | 124 +++++++
.../ci-debian-9-cross-armv7l.Dockerfile | 125 +++++++
.../ci-debian-9-cross-mips.Dockerfile | 125 +++++++
.../ci-debian-9-cross-mips64el.Dockerfile | 125 +++++++
.../ci-debian-9-cross-mipsel.Dockerfile | 125 +++++++
.../ci-debian-9-cross-ppc64le.Dockerfile | 125 +++++++
.../ci-debian-9-cross-s390x.Dockerfile | 125 +++++++
ci/containers/ci-debian-9.Dockerfile | 116 ++++++
.../ci-debian-sid-cross-aarch64.Dockerfile | 122 +++++++
.../ci-debian-sid-cross-armv6l.Dockerfile | 120 +++++++
.../ci-debian-sid-cross-armv7l.Dockerfile | 121 +++++++
.../ci-debian-sid-cross-i686.Dockerfile | 121 +++++++
.../ci-debian-sid-cross-mips.Dockerfile | 121 +++++++
.../ci-debian-sid-cross-mips64el.Dockerfile | 121 +++++++
.../ci-debian-sid-cross-mipsel.Dockerfile | 120 +++++++
.../ci-debian-sid-cross-ppc64le.Dockerfile | 121 +++++++
.../ci-debian-sid-cross-s390x.Dockerfile | 121 +++++++
ci/containers/ci-debian-sid.Dockerfile | 112 ++++++
ci/containers/ci-fedora-31.Dockerfile | 109 ++++++
ci/containers/ci-fedora-32.Dockerfile | 109 ++++++
...ci-fedora-rawhide-cross-mingw32.Dockerfile | 130 +++++++
...ci-fedora-rawhide-cross-mingw64.Dockerfile | 130 +++++++
ci/containers/ci-fedora-rawhide.Dockerfile | 110 ++++++
ci/containers/ci-opensuse-151.Dockerfile | 109 ++++++
ci/containers/ci-ubuntu-1804.Dockerfile | 117 ++++++
ci/containers/ci-ubuntu-2004.Dockerfile | 113 ++++++
ci/containers/refresh | 43 +++
ci/list-images.sh | 24 +-
45 files changed, 5173 insertions(+), 49 deletions(-)
create mode 100644 ci/containers/README.rst
create mode 100644 ci/containers/ci-centos-7.Dockerfile
create mode 100644 ci/containers/ci-centos-8.Dockerfile
create mode 100644 ci/containers/ci-centos-stream.Dockerfile
create mode 100644 ci/containers/ci-debian-10-cross-aarch64.Dockerfile
create mode 100644 ci/containers/ci-debian-10-cross-armv6l.Dockerfile
create mode 100644 ci/containers/ci-debian-10-cross-armv7l.Dockerfile
create mode 100644 ci/containers/ci-debian-10-cross-i686.Dockerfile
create mode 100644 ci/containers/ci-debian-10-cross-mips.Dockerfile
create mode 100644 ci/containers/ci-debian-10-cross-mips64el.Dockerfile
create mode 100644 ci/containers/ci-debian-10-cross-mipsel.Dockerfile
create mode 100644 ci/containers/ci-debian-10-cross-ppc64le.Dockerfile
create mode 100644 ci/containers/ci-debian-10-cross-s390x.Dockerfile
create mode 100644 ci/containers/ci-debian-10.Dockerfile
create mode 100644 ci/containers/ci-debian-9-cross-aarch64.Dockerfile
create mode 100644 ci/containers/ci-debian-9-cross-armv6l.Dockerfile
create mode 100644 ci/containers/ci-debian-9-cross-armv7l.Dockerfile
create mode 100644 ci/containers/ci-debian-9-cross-mips.Dockerfile
create mode 100644 ci/containers/ci-debian-9-cross-mips64el.Dockerfile
create mode 100644 ci/containers/ci-debian-9-cross-mipsel.Dockerfile
create mode 100644 ci/containers/ci-debian-9-cross-ppc64le.Dockerfile
create mode 100644 ci/containers/ci-debian-9-cross-s390x.Dockerfile
create mode 100644 ci/containers/ci-debian-9.Dockerfile
create mode 100644 ci/containers/ci-debian-sid-cross-aarch64.Dockerfile
create mode 100644 ci/containers/ci-debian-sid-cross-armv6l.Dockerfile
create mode 100644 ci/containers/ci-debian-sid-cross-armv7l.Dockerfile
create mode 100644 ci/containers/ci-debian-sid-cross-i686.Dockerfile
create mode 100644 ci/containers/ci-debian-sid-cross-mips.Dockerfile
create mode 100644 ci/containers/ci-debian-sid-cross-mips64el.Dockerfile
create mode 100644 ci/containers/ci-debian-sid-cross-mipsel.Dockerfile
create mode 100644 ci/containers/ci-debian-sid-cross-ppc64le.Dockerfile
create mode 100644 ci/containers/ci-debian-sid-cross-s390x.Dockerfile
create mode 100644 ci/containers/ci-debian-sid.Dockerfile
create mode 100644 ci/containers/ci-fedora-31.Dockerfile
create mode 100644 ci/containers/ci-fedora-32.Dockerfile
create mode 100644 ci/containers/ci-fedora-rawhide-cross-mingw32.Dockerfile
create mode 100644 ci/containers/ci-fedora-rawhide-cross-mingw64.Dockerfile
create mode 100644 ci/containers/ci-fedora-rawhide.Dockerfile
create mode 100644 ci/containers/ci-opensuse-151.Dockerfile
create mode 100644 ci/containers/ci-ubuntu-1804.Dockerfile
create mode 100644 ci/containers/ci-ubuntu-2004.Dockerfile
create mode 100755 ci/containers/refresh
--
2.25.4
4 years, 5 months
[libvirt PATCH v2] docs: Document CIRRUS_GITHUB_REPO variable
by Andrea Bolognani
This needs to be set for every repository for Cirrus CI integration
to work.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
docs/newreposetup.rst | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/docs/newreposetup.rst b/docs/newreposetup.rst
index f81e26747b..ac2e6a15f1 100644
--- a/docs/newreposetup.rst
+++ b/docs/newreposetup.rst
@@ -83,6 +83,22 @@ required under the **Settings** page:
* *Shared runners*: Enable shared runners
+ * **Variables**
+
+ * *Key*: ``CIRRUS_GITHUB_REPO``
+
+ * *Value*: ``libvirt/$repo``
+
+ * *Protect variable*: enabled
+
+ * *Mask variable*: disabled
+
+ * *Key*: ``CIRRUS_API_TOKEN``
+
+ * No need to set this at the project level: it's already set for the
+ libvirt organization and will be inherited from there.
+
+
GitHub configuration
====================
--
2.25.4
4 years, 5 months
[PATCH] conf: remove unused variable
by Yi Li
Signed-off-by: Yi Li <yili(a)winhong.com>
---
src/conf/snapshot_conf.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 857d04c476..f73eeb06c7 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -231,7 +231,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
xmlNodePtr inactiveDomNode = NULL;
size_t i;
int n;
- char *creation = NULL, *state = NULL;
+ char *state = NULL;
int active;
char *tmp;
char *memorySnapshot = NULL;
@@ -404,7 +404,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
ret = g_steal_pointer(&def);
cleanup:
- VIR_FREE(creation);
VIR_FREE(state);
VIR_FREE(nodes);
VIR_FREE(memorySnapshot);
--
2.25.3
4 years, 5 months