qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [RFC v9 09/18] vfio: add ref for group to support own affec


From: Chen Fan
Subject: [Qemu-devel] [RFC v9 09/18] vfio: add ref for group to support own affected groups
Date: Tue, 9 Jun 2015 11:37:37 +0800

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

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 4230f83..eff1930 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -832,6 +832,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as)
         goto close_fd_exit;
     }
 
+    group->ref = 0;
     group->groupid = groupid;
     QLIST_INIT(&group->device_list);
 
@@ -865,6 +866,15 @@ void vfio_put_group(VFIOGroup *group)
         return;
     }
 
+    if (group->ref) {
+        if (QLIST_EMPTY(&group->device_list)) {
+            if (group->container) {
+                vfio_disconnect_container(group);
+            }
+        }
+        return;
+    }
+
     vfio_kvm_device_del_group(group);
     if (group->container) {
         vfio_disconnect_container(group);
@@ -901,6 +911,7 @@ int vfio_get_device(VFIOGroup *group, const char *name,
         return ret;
     }
 
+    group->ref++;
     vbasedev->fd = fd;
     vbasedev->group = group;
     QLIST_INSERT_HEAD(&group->device_list, vbasedev, next);
@@ -921,6 +932,7 @@ void vfio_put_base_device(VFIODevice *vbasedev)
     if (!vbasedev->group) {
         return;
     }
+    vbasedev->group->ref--;
     QLIST_REMOVE(vbasedev, next);
     vbasedev->group = NULL;
     trace_vfio_put_base_device(vbasedev->fd);
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]