From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2APe-0003wL-Ng for qemu-devel@nongnu.org; Mon, 08 Jun 2015 23:41:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z2APd-0000s6-Io for qemu-devel@nongnu.org; Mon, 08 Jun 2015 23:41:18 -0400 Received: from [59.151.112.132] (port=14161 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2APZ-0000Uq-HI for qemu-devel@nongnu.org; Mon, 08 Jun 2015 23:41:17 -0400 From: Chen Fan Date: Tue, 9 Jun 2015 11:37:37 +0800 Message-ID: <271aa9f9c26213c43241c44273a18109af505223.1433812962.git.chen.fan.fnst@cn.fujitsu.com> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [RFC v9 09/18] vfio: add ref for group to support own affected groups List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com Signed-off-by: Chen Fan --- 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