From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: libvir-list@redhat.com
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, aik@ozlabs.ru,
alex.williamson@redhat.com, abologna@redhat.com, laine@laine.org,
pkrempa@redhat.com, berrange@redhat.com, mprivozn@redhat.com,
sbhat@linux.vnet.ibm.com
Subject: [Qemu-devel] [RFC PATCH 3/5] virpci: introduce virPCIIOMMUGroupIterate()
Date: Wed, 28 Jun 2017 19:24:58 -0500 [thread overview]
Message-ID: <1498695900-1648-4-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com>
This serves a similar purpose to virPCIDeviceAddressIOMMUGroupIterate,
but uses the iommu group number to find matches instead of a device
within the group. We refactor the code to use this new function and
also export it for use in subsequent patches.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
src/util/virpci.c | 42 ++++++++++++++++++++++++++++++------------
src/util/virpci.h | 3 +++
2 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 2c1b758..b842f44 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -49,6 +49,7 @@
VIR_LOG_INIT("util.pci");
#define PCI_SYSFS "/sys/bus/pci/"
+#define IOMMU_GROUP_SYSFS "/sys/kernel/iommu_groups/"
#define PCI_ID_LEN 10 /* "XXXX XXXX" */
#define PCI_ADDR_LEN 13 /* "XXXX:XX:XX.X" */
@@ -2178,16 +2179,13 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
return ret;
}
-
-/* virPCIDeviceAddressIOMMUGroupIterate:
- * Call @actor for all devices in the same iommu_group as orig
- * (including orig itself) Even if there is no iommu_group for the
- * device, call @actor once for orig.
+/* virPCIIOMMUGroupIterate:
+ * Call @actor for all devices in a particular iommu_group.
*/
int
-virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
- virPCIDeviceAddressActor actor,
- void *opaque)
+virPCIIOMMUGroupIterate(int iommu_group,
+ virPCIDeviceAddressActor actor,
+ void *opaque)
{
char *groupPath = NULL;
DIR *groupDir = NULL;
@@ -2196,13 +2194,11 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
int direrr;
if (virAsprintf(&groupPath,
- PCI_SYSFS "devices/%04x:%02x:%02x.%x/iommu_group/devices",
- orig->domain, orig->bus, orig->slot, orig->function) < 0)
+ IOMMU_GROUP_SYSFS "%d/devices",
+ iommu_group) < 0)
goto cleanup;
if (virDirOpenQuiet(&groupDir, groupPath) < 0) {
- /* just process the original device, nothing more */
- ret = (actor)(orig, opaque);
goto cleanup;
}
@@ -2230,6 +2226,28 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
return ret;
}
+/* virPCIDeviceAddressIOMMUGroupIterate:
+ * Call @actor for all devices in the same iommu_group as orig
+ * (including orig itself) Even if there is no iommu_group for the
+ * device, call @actor once for orig.
+ */
+int
+virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
+ virPCIDeviceAddressActor actor,
+ void *opaque)
+{
+ int ret = -1;
+
+ ret = virPCIIOMMUGroupIterate(virPCIDeviceAddressGetIOMMUGroupNum(orig),
+ actor, opaque);
+ if (ret < 0) {
+ /* just process the original device, nothing more */
+ ret = (actor)(orig, opaque);
+ }
+
+ return ret;
+}
+
static int
virPCIDeviceGetIOMMUGroupAddOne(virPCIDeviceAddressPtr newDevAddr, void *opaque)
diff --git a/src/util/virpci.h b/src/util/virpci.h
index 570684e..5ec1306 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -176,6 +176,9 @@ typedef int (*virPCIDeviceAddressActor)(virPCIDeviceAddressPtr addr,
int virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
virPCIDeviceAddressActor actor,
void *opaque);
+int virPCIIOMMUGroupIterate(int iommu_group,
+ virPCIDeviceAddressActor actor,
+ void *opaque);
virPCIDeviceListPtr virPCIDeviceGetIOMMUGroupList(virPCIDevicePtr dev);
int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAddr,
virPCIDeviceAddressPtr **iommuGroupDevices,
--
2.7.4
next prev parent reply other threads:[~2017-06-29 0:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-29 0:24 [Qemu-devel] [RFC PATCH 0/5] hotplug: fix premature rebinding of VFIO devices to host Michael Roth
2017-06-29 0:24 ` [Qemu-devel] [RFC PATCH 1/5] virhostdev: factor release out from reattach and export it for use later Michael Roth
2017-06-29 0:24 ` [Qemu-devel] [RFC PATCH 2/5] qemu_hotplug: squash qemuDomainRemovePCIHostDevice into caller Michael Roth
2017-06-29 0:24 ` Michael Roth [this message]
2017-06-29 0:24 ` [Qemu-devel] [RFC PATCH 4/5] qemu: hotplug: unbind VFIO devices as a group Michael Roth
2017-06-29 0:25 ` [Qemu-devel] [RFC PATCH 5/5] qemu: hotplug: wait for VFIO group FD close before unbind Michael Roth
2017-06-29 8:33 ` [Qemu-devel] [RFC PATCH 0/5] hotplug: fix premature rebinding of VFIO devices to host Daniel P. Berrange
2017-06-29 18:22 ` Michael Roth
2017-06-29 19:31 ` Alex Williamson
2017-06-29 19:28 ` Alex Williamson
2017-06-29 20:21 ` Michael Roth
2017-06-29 18:50 ` Laine Stump
2017-06-29 19:44 ` Alex Williamson
2017-06-30 2:27 ` Laine Stump
2017-06-29 20:59 ` Michael Roth
2017-06-30 6:59 ` Andrea Bolognani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1498695900-1648-4-git-send-email-mdroth@linux.vnet.ibm.com \
--to=mdroth@linux.vnet.ibm.com \
--cc=abologna@redhat.com \
--cc=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=berrange@redhat.com \
--cc=laine@laine.org \
--cc=libvir-list@redhat.com \
--cc=mprivozn@redhat.com \
--cc=pkrempa@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=sbhat@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).