@@ -1081,13 +1081,12 @@ static void xen_block_device_create(XenBackendInstance *backend,
blockdev->iothread = iothread;
blockdev->drive = drive;
+ xendev->backend = backend;
if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
error_prepend(errp, "realization of device %s failed: ", type);
goto fail;
}
-
- xen_backend_set_device(backend, xendev);
return;
fail:
@@ -600,8 +600,8 @@ static void xen_console_device_create(XenBackendInstance *backend,
goto fail;
}
+ xendev->backend = backend;
if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
- xen_backend_set_device(backend, xendev);
goto done;
}
@@ -627,8 +627,8 @@ static void xen_net_device_create(XenBackendInstance *backend,
net->dev = number;
memcpy(&net->conf.macaddr, &mac, sizeof(mac));
+ xendev->backend = backend;
if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
- xen_backend_set_device(backend, xendev);
return;
}
@@ -88,19 +88,6 @@ static void xen_backend_list_add(XenBackendInstance *backend)
QLIST_INSERT_HEAD(&backend_list, backend, entry);
}
-static XenBackendInstance *xen_backend_list_find(XenDevice *xendev)
-{
- XenBackendInstance *backend;
-
- QLIST_FOREACH(backend, &backend_list, entry) {
- if (backend->xendev == xendev) {
- return backend;
- }
- }
-
- return NULL;
-}
-
bool xen_backend_exists(const char *type, const char *name)
{
const XenBackendImpl *impl = xen_backend_table_lookup(type);
@@ -170,7 +157,7 @@ XenDevice *xen_backend_get_device(XenBackendInstance *backend)
bool xen_backend_try_device_destroy(XenDevice *xendev, Error **errp)
{
- XenBackendInstance *backend = xen_backend_list_find(xendev);
+ XenBackendInstance *backend = xendev->backend;
const XenBackendImpl *impl;
if (!backend) {
@@ -1079,6 +1079,10 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
}
}
+ if (xendev->backend) {
+ xen_backend_set_device(xendev->backend, xendev);
+ }
+
xendev->exit.notify = xen_device_exit;
qemu_add_exit_notifier(&xendev->exit);
return;
@@ -10,8 +10,6 @@
#include "hw/xen/xen-bus.h"
-typedef struct XenBackendInstance XenBackendInstance;
-
typedef void (*XenBackendDeviceCreate)(XenBackendInstance *backend,
QDict *opts, Error **errp);
typedef void (*XenBackendDeviceDestroy)(XenBackendInstance *backend,
@@ -14,9 +14,11 @@
#include "qom/object.h"
typedef struct XenEventChannel XenEventChannel;
+typedef struct XenBackendInstance XenBackendInstance;
struct XenDevice {
DeviceState qdev;
+ XenBackendInstance *backend;
domid_t frontend_id;
char *name;
struct qemu_xs_handle *xsh;