qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC v10 08/19] vfio: add ref for group to support own affe


From: Chen Fan
Subject: [Qemu-devel] [RFC v10 08/19] vfio: add ref for group to support own affected groups
Date: Tue, 16 Jun 2015 16:10:52 +0800

Signed-off-by: Chen Fan <address@hidden>
---
 hw/vfio/common.c              | 14 +++++++++++++-
 include/hw/vfio/vfio-common.h |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index b1045da..67881f7 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -795,6 +795,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as)
         if (group->groupid == groupid) {
             /* Found it.  Now is it already in the right context? */
             if (group->container->space->as == as) {
+                group->ref++;
                 return group;
             } else {
                 error_report("vfio: group %d used in multiple address spaces",
@@ -825,6 +826,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as)
         goto close_fd_exit;
     }
 
+    group->ref = 1;
     group->groupid = groupid;
     QLIST_INIT(&group->device_list);
 
@@ -854,7 +856,17 @@ free_group_exit:
 
 void vfio_put_group(VFIOGroup *group)
 {
-    if (!group || !QLIST_EMPTY(&group->device_list)) {
+    if (!group) {
+        return;
+    }
+
+    group->ref--;
+    assert(group->ref >= 0);
+    if (!QLIST_EMPTY(&group->device_list)) {
+        return;
+    }
+
+    if (group->ref) {
         return;
     }
 
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 0d1fb80..3eb042e 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -117,6 +117,7 @@ struct VFIODeviceOps {
 typedef struct VFIOGroup {
     int fd;
     int groupid;
+    int ref;
     VFIOContainer *container;
     QLIST_HEAD(, VFIODevice) device_list;
     QLIST_ENTRY(VFIOGroup) next;
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]