Thanks: Laine Stump, Andrea Bolognani, Marcel Apfelbaum.
---
src/guestfs-internal.h | 6 +++---
src/launch-libvirt.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index d437b9a..428da7f 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -137,17 +137,17 @@
/* Differences in device names on ARM (virtio-mmio) vs normal
* hardware with PCI.
*/
-#if !defined(__arm__) && !defined(__aarch64__)
+#if !defined(__arm__)
#define VIRTIO_BLK "virtio-blk-pci"
#define VIRTIO_SCSI "virtio-scsi-pci"
#define VIRTIO_SERIAL "virtio-serial-pci"
#define VIRTIO_NET "virtio-net-pci"
-#else /* ARM */
+#else /* ARMv7 */
#define VIRTIO_BLK "virtio-blk-device"
#define VIRTIO_SCSI "virtio-scsi-device"
#define VIRTIO_SERIAL "virtio-serial-device"
#define VIRTIO_NET "virtio-net-device"
-#endif /* ARM */
+#endif /* ARMv7 */
/* Machine types. */
#ifdef __arm__
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index d8479dc..1ac5604 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -950,6 +950,13 @@ static int construct_libvirt_xml_disk_source_hosts (guestfs_h *g,
xmlTextWriterP
static int construct_libvirt_xml_disk_source_seclabel (guestfs_h *g, const struct
backend_libvirt_data *data, xmlTextWriterPtr xo);
static int construct_libvirt_xml_appliance (guestfs_h *g, const struct libvirt_xml_params
*params, xmlTextWriterPtr xo);
+static int construct_libvirt_xml_virtio_pci_address (guestfs_h *g, xmlTextWriterPtr xo,
int slot);
+/* Don't use slot 1, since can be used by video. */
+#define VIRTIO_PCI_SLOT_RNG 2
+#define VIRTIO_PCI_SLOT_SCSI 3
+#define VIRTIO_PCI_SLOT_SERIAL 4
+#define VIRTIO_PCI_SLOT_NETWORK 5
+
/* These macros make it easier to write XML, but they also make a lot
* of assumptions:
*
@@ -1337,6 +1344,9 @@ construct_libvirt_xml_devices (guestfs_h *g,
attribute ("model", "random");
string ("/dev/urandom");
} end_element ();
+ if (construct_libvirt_xml_virtio_pci_address (g, xo,
+ VIRTIO_PCI_SLOT_RNG) == -1)
+ return -1;
} end_element ();
}
@@ -1345,6 +1355,9 @@ construct_libvirt_xml_devices (guestfs_h *g,
attribute ("type", "scsi");
attribute ("index", "0");
attribute ("model", "virtio-scsi");
+ if (construct_libvirt_xml_virtio_pci_address (g, xo,
+ VIRTIO_PCI_SLOT_SCSI) == -1)
+ return -1;
} end_element ();
/* Disks. */
@@ -1382,6 +1395,9 @@ construct_libvirt_xml_devices (guestfs_h *g,
attribute ("type", "virtio");
attribute ("name", "org.libguestfs.channel.0");
} end_element ();
+ if (construct_libvirt_xml_virtio_pci_address (g, xo,
+ VIRTIO_PCI_SLOT_SERIAL) == -1)
+ return -1;
} end_element ();
/* Connect to libvirt bridge (see: RHBZ#1148012). */
@@ -1394,6 +1410,9 @@ construct_libvirt_xml_devices (guestfs_h *g,
start_element ("model") {
attribute ("type", "virtio");
} end_element ();
+ if (construct_libvirt_xml_virtio_pci_address (g, xo,
+ VIRTIO_PCI_SLOT_NETWORK) == -1)
+ return -1;
} end_element ();
}
@@ -1986,6 +2005,28 @@ find_secret (guestfs_h *g,
return 0;
}
+/**
+ * On aarch64 only, to force libvirt to use virtio-pci instead of
+ * virtio-mmio, we assign every virtio device to a unique function
+ * within the (implicitly created) pcie-root bus. Every virtio device
+ * must have a unique slot number.
+ */
+static int
+construct_libvirt_xml_virtio_pci_address (guestfs_h *g,
+ xmlTextWriterPtr xo,
+ int slot)
+{
+#if defined(__aarch64__)
+ start_element ("address") {
+ attribute ("type", "pci");
+ attribute ("bus", "0");
+ attribute_format ("slot", "%d", slot);
+ } end_element ();
+#endif
+
+ return 0;
+}
+
static int
is_blk (const char *path)
{
--
2.9.3