mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
launch-libvirt: add virtio-net via the standard <interface> element
Starting with version 3.8.0, libvirt allows us to specify the network
address and network mask (as prefix) for SLIRP directly via the
<interface> element in the domain XML:
<https://libvirt.org/formatdomain.html#userspace-slirp-stack>. This means
we don't need the <qemu:commandline> hack for virtio-net on such versions.
Restrict the hack in construct_libvirt_xml_qemu_cmdline() to
libvirt<3.8.0, and generate the proper <interface> element in
construct_libvirt_xml_devices() on libvirt>=3.8.0.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2034160
Suggested-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211223103701.12702-4-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Tested-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 5858c2cf6c)
This commit is contained in:
committed by
Richard W.M. Jones
parent
4b9eac11db
commit
8570de6e76
@@ -148,7 +148,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Place the virtio-net controller in slot 0x1e on the root bus, on normal
|
/* Place the virtio-net controller in slot 0x1e on the root bus, on normal
|
||||||
* hardware with PCI. Refer to RHBZ#2034160.
|
* hardware with PCI. Necessary only before libvirt 3.8.0. Refer to
|
||||||
|
* RHBZ#2034160.
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_LIBVIRT_BACKEND
|
#ifdef HAVE_LIBVIRT_BACKEND
|
||||||
#if defined(__arm__) || defined(__s390x__)
|
#if defined(__arm__) || defined(__s390x__)
|
||||||
|
|||||||
@@ -1396,6 +1396,28 @@ construct_libvirt_xml_devices (guestfs_h *g,
|
|||||||
} end_element ();
|
} end_element ();
|
||||||
} end_element ();
|
} end_element ();
|
||||||
|
|
||||||
|
/* Virtio-net NIC with SLIRP (= userspace) back-end, if networking is
|
||||||
|
* enabled. Starting with libvirt 3.8.0, we can specify the network address
|
||||||
|
* and prefix for SLIRP in the domain XML. Therefore, we can add the NIC
|
||||||
|
* via the standard <interface> element rather than <qemu:commandline>, and
|
||||||
|
* so libvirt can manage the PCI address of the virtio-net NIC like the PCI
|
||||||
|
* addresses of all other devices. Refer to RHBZ#2034160.
|
||||||
|
*/
|
||||||
|
if (g->enable_network &&
|
||||||
|
guestfs_int_version_ge (¶ms->data->libvirt_version, 3, 8, 0)) {
|
||||||
|
start_element ("interface") {
|
||||||
|
attribute ("type", "user");
|
||||||
|
start_element ("model") {
|
||||||
|
attribute ("type", "virtio");
|
||||||
|
} end_element ();
|
||||||
|
start_element ("ip") {
|
||||||
|
attribute ("family", "ipv4");
|
||||||
|
attribute ("address", NETWORK_ADDRESS);
|
||||||
|
attribute ("prefix", NETWORK_PREFIX);
|
||||||
|
} end_element ();
|
||||||
|
} end_element ();
|
||||||
|
}
|
||||||
|
|
||||||
/* Libvirt adds some devices by default. Indicate to libvirt
|
/* Libvirt adds some devices by default. Indicate to libvirt
|
||||||
* that we don't want them.
|
* that we don't want them.
|
||||||
*/
|
*/
|
||||||
@@ -1818,9 +1840,10 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
|
|||||||
} end_element ();
|
} end_element ();
|
||||||
|
|
||||||
/* Workaround because libvirt user networking cannot specify "net="
|
/* Workaround because libvirt user networking cannot specify "net="
|
||||||
* parameter.
|
* parameter. Necessary only before libvirt 3.8.0; refer to RHBZ#2034160.
|
||||||
*/
|
*/
|
||||||
if (g->enable_network) {
|
if (g->enable_network &&
|
||||||
|
!guestfs_int_version_ge (¶ms->data->libvirt_version, 3, 8, 0)) {
|
||||||
start_element ("qemu:arg") {
|
start_element ("qemu:arg") {
|
||||||
attribute ("value", "-netdev");
|
attribute ("value", "-netdev");
|
||||||
} end_element ();
|
} end_element ();
|
||||||
|
|||||||
Reference in New Issue
Block a user