[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 04/12] vfio-user: instantiate vfio-user context
From: |
Jagannathan Raman |
Subject: |
[PATCH v3 04/12] vfio-user: instantiate vfio-user context |
Date: |
Mon, 11 Oct 2021 01:31:09 -0400 |
create a context with the vfio-user library to run a PCI device
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
hw/remote/vfio-user-obj.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index c2a300f0ff..d26e5ec9e9 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -41,6 +41,9 @@
#include "hw/remote/machine.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-sockets.h"
+#include "qemu/notify.h"
+#include "sysemu/sysemu.h"
+#include "libvfio-user.h"
#define TYPE_VFU_OBJECT "vfio-user-server"
OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
@@ -61,6 +64,10 @@ struct VfuObject {
SocketAddress *socket;
char *device;
+
+ Notifier machine_done;
+
+ vfu_ctx_t *vfu_ctx;
};
static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name,
@@ -94,9 +101,31 @@ static void vfu_object_set_device(Object *obj, const char
*str, Error **errp)
trace_vfu_prop("device", str);
}
+/*
+ * vfio-user-server depends on the availability of the 'socket' and 'device'
+ * properties. It also depends on devices instantiated in QEMU. These
+ * dependencies are not available during the instance_init phase of this
+ * object's life-cycle. As such, the server is initialized after the
+ * machine is setup. machine_init_done_notifier notifies vfio-user-server
+ * when the machine is setup, and the dependencies are available.
+ */
+static void vfu_object_machine_done(Notifier *notifier, void *data)
+{
+ VfuObject *o = container_of(notifier, VfuObject, machine_done);
+
+ o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0,
+ o, VFU_DEV_TYPE_PCI);
+ if (o->vfu_ctx == NULL) {
+ error_setg(&error_abort, "vfu: Failed to create context - %s",
+ strerror(errno));
+ return;
+ }
+}
+
static void vfu_object_init(Object *obj)
{
VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj);
+ VfuObject *o = VFU_OBJECT(obj);
if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) {
error_setg(&error_abort, "vfu: %s only compatible with %s machine",
@@ -111,7 +140,12 @@ static void vfu_object_init(Object *obj)
return;
}
+ o->vfu_ctx = NULL;
+
k->nr_devs++;
+
+ o->machine_done.notify = vfu_object_machine_done;
+ qemu_add_machine_init_done_notifier(&o->machine_done);
}
static void vfu_object_finalize(Object *obj)
@@ -123,6 +157,10 @@ static void vfu_object_finalize(Object *obj)
g_free(o->socket);
+ if (o->vfu_ctx) {
+ vfu_destroy_ctx(o->vfu_ctx);
+ }
+
g_free(o->device);
if (k->nr_devs == 0) {
--
2.20.1
- [PATCH v3 00/12] vfio-user server in QEMU, Jagannathan Raman, 2021/10/11
- [PATCH v3 01/12] configure, meson: override C compiler for cmake, Jagannathan Raman, 2021/10/11
- [PATCH v3 02/12] vfio-user: build library, Jagannathan Raman, 2021/10/11
- [PATCH v3 03/12] vfio-user: define vfio-user-server object, Jagannathan Raman, 2021/10/11
- [PATCH v3 04/12] vfio-user: instantiate vfio-user context,
Jagannathan Raman <=
- [PATCH v3 05/12] vfio-user: find and init PCI device, Jagannathan Raman, 2021/10/11
- [PATCH v3 07/12] vfio-user: handle PCI config space accesses, Jagannathan Raman, 2021/10/11
- [PATCH v3 08/12] vfio-user: handle DMA mappings, Jagannathan Raman, 2021/10/11
- [PATCH v3 06/12] vfio-user: run vfio-user context, Jagannathan Raman, 2021/10/11