[libvirt] [PATCH v1 23/31] qemu_domain: Introduce NVMe path getting helpers

Michal Privoznik mprivozn at redhat.com
Thu Jul 11 15:54:10 UTC 2019


Couple of places in the QEMU driver will want to know what paths
are associated with NVMe disks (for instance CGroup code or
namespaces code). Introduce helpers which return desired paths
(for instance /dev/vfio/vfio and /dev/vfio/N).

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/qemu/qemu_domain.c | 44 ++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h |  6 ++++++
 2 files changed, 50 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2a7f09ce24..949bbace88 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11723,6 +11723,50 @@ qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
 }
 
 
+char *
+qemuDomainGetNVMeDiskPath(const virStorageSourceNVMeDef *nvme)
+{
+    VIR_AUTOPTR(virPCIDevice) pci = NULL;
+
+    /* All NVMe devices are VFIO PCI devices */
+    if (!(pci = virPCIDeviceNew(nvme->pciAddr.domain,
+                                nvme->pciAddr.bus,
+                                nvme->pciAddr.slot,
+                                nvme->pciAddr.function)))
+        return NULL;
+
+    return virPCIDeviceGetIOMMUGroupDev(pci);
+}
+
+
+char **
+qemuDomainGetDiskNVMePaths(const virDomainDef *def,
+                           const virStorageSource *src,
+                           bool teardown)
+{
+    VIR_AUTOFREE(char *) iommuGroup = NULL;
+    VIR_AUTOSTRINGLIST paths = NULL;
+    bool includeVFIO = !teardown;
+
+    if (!(iommuGroup = qemuDomainGetNVMeDiskPath(src->nvme)))
+        return NULL;
+
+    if (virStringListAdd(&paths, iommuGroup) < 0)
+        return NULL;
+
+    if (teardown && def &&
+        !virDomainDefHasNVMeDisk(def) &&
+        !virDomainDefHasVFIOHostdev(def))
+        includeVFIO = true;
+
+    if (includeVFIO &&
+        virStringListAdd(&paths, QEMU_DEV_VFIO) < 0)
+        return NULL;
+
+    VIR_RETURN_PTR(paths);
+}
+
+
 /**
  * qemuDomainGetHostdevPath:
  * @def: domain definition
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 3eea8b0f96..82e225088d 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1011,6 +1011,12 @@ int qemuDomainCheckMonitor(virQEMUDriverPtr driver,
 bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
                                 virQEMUCapsPtr qemuCaps);
 
+char * qemuDomainGetNVMeDiskPath(const virStorageSourceNVMeDef *nvme);
+
+char ** qemuDomainGetDiskNVMePaths(const virDomainDef *def,
+                                   const virStorageSource *src,
+                                   bool teardown);
+
 int qemuDomainGetHostdevPath(virDomainDefPtr def,
                              virDomainHostdevDefPtr dev,
                              bool teardown,
-- 
2.21.0




More information about the libvir-list mailing list