2019-01-08 17:48:48 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Citrix Systems Inc.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qemu/cutils.h"
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 08:23:50 +03:00
|
|
|
#include "qemu/main-loop.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2019-01-08 17:49:01 +03:00
|
|
|
#include "qemu/option.h"
|
2019-01-08 17:48:48 +03:00
|
|
|
#include "qapi/error.h"
|
2019-01-08 17:49:01 +03:00
|
|
|
#include "qapi/qapi-commands-block-core.h"
|
2019-06-19 23:10:37 +03:00
|
|
|
#include "qapi/qapi-commands-qom.h"
|
2019-01-08 17:49:01 +03:00
|
|
|
#include "qapi/qapi-visit-block-core.h"
|
|
|
|
#include "qapi/qobject-input-visitor.h"
|
2019-01-08 17:48:48 +03:00
|
|
|
#include "qapi/visitor.h"
|
2019-01-08 17:49:01 +03:00
|
|
|
#include "qapi/qmp/qdict.h"
|
|
|
|
#include "qapi/qmp/qstring.h"
|
2020-02-24 17:29:55 +03:00
|
|
|
#include "qom/object_interfaces.h"
|
2019-01-08 17:48:59 +03:00
|
|
|
#include "hw/block/xen_blkif.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-01-08 17:48:48 +03:00
|
|
|
#include "hw/xen/xen-block.h"
|
2019-01-08 17:49:01 +03:00
|
|
|
#include "hw/xen/xen-backend.h"
|
2019-01-08 17:48:59 +03:00
|
|
|
#include "sysemu/blockdev.h"
|
|
|
|
#include "sysemu/block-backend.h"
|
|
|
|
#include "sysemu/iothread.h"
|
|
|
|
#include "dataplane/xen-block.h"
|
2019-01-08 17:48:48 +03:00
|
|
|
#include "trace.h"
|
|
|
|
|
2019-01-08 17:48:49 +03:00
|
|
|
static char *xen_block_get_name(XenDevice *xendev, Error **errp)
|
|
|
|
{
|
|
|
|
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
|
|
|
XenBlockVdev *vdev = &blockdev->props.vdev;
|
|
|
|
|
|
|
|
return g_strdup_printf("%lu", vdev->number);
|
|
|
|
}
|
|
|
|
|
2019-01-08 17:48:50 +03:00
|
|
|
static void xen_block_disconnect(XenDevice *xendev, Error **errp)
|
|
|
|
{
|
|
|
|
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
|
|
|
const char *type = object_get_typename(OBJECT(blockdev));
|
|
|
|
XenBlockVdev *vdev = &blockdev->props.vdev;
|
|
|
|
|
|
|
|
trace_xen_block_disconnect(type, vdev->disk, vdev->partition);
|
2019-01-08 17:48:59 +03:00
|
|
|
|
|
|
|
xen_block_dataplane_stop(blockdev->dataplane);
|
2019-01-08 17:48:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_block_connect(XenDevice *xendev, Error **errp)
|
|
|
|
{
|
|
|
|
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
|
|
|
const char *type = object_get_typename(OBJECT(blockdev));
|
|
|
|
XenBlockVdev *vdev = &blockdev->props.vdev;
|
2019-04-09 19:40:38 +03:00
|
|
|
BlockConf *conf = &blockdev->props.conf;
|
|
|
|
unsigned int feature_large_sector_size;
|
2019-01-08 17:48:59 +03:00
|
|
|
unsigned int order, nr_ring_ref, *ring_ref, event_channel, protocol;
|
|
|
|
char *str;
|
2019-01-08 17:48:50 +03:00
|
|
|
|
|
|
|
trace_xen_block_connect(type, vdev->disk, vdev->partition);
|
2019-01-08 17:48:59 +03:00
|
|
|
|
2019-04-09 19:40:38 +03:00
|
|
|
if (xen_device_frontend_scanf(xendev, "feature-large-sector-size", "%u",
|
|
|
|
&feature_large_sector_size) != 1) {
|
|
|
|
feature_large_sector_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (feature_large_sector_size != 1 &&
|
|
|
|
conf->logical_block_size != XEN_BLKIF_SECTOR_SIZE) {
|
|
|
|
error_setg(errp, "logical_block_size != %u not supported by frontend",
|
|
|
|
XEN_BLKIF_SECTOR_SIZE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-08 17:48:59 +03:00
|
|
|
if (xen_device_frontend_scanf(xendev, "ring-page-order", "%u",
|
|
|
|
&order) != 1) {
|
|
|
|
nr_ring_ref = 1;
|
|
|
|
ring_ref = g_new(unsigned int, nr_ring_ref);
|
|
|
|
|
|
|
|
if (xen_device_frontend_scanf(xendev, "ring-ref", "%u",
|
|
|
|
&ring_ref[0]) != 1) {
|
|
|
|
error_setg(errp, "failed to read ring-ref");
|
|
|
|
g_free(ring_ref);
|
|
|
|
return;
|
|
|
|
}
|
2023-01-30 19:27:07 +03:00
|
|
|
} else if (qemu_xen_gnttab_can_map_multi() &&
|
|
|
|
order <= blockdev->props.max_ring_page_order) {
|
2019-01-08 17:48:59 +03:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
nr_ring_ref = 1 << order;
|
|
|
|
ring_ref = g_new(unsigned int, nr_ring_ref);
|
|
|
|
|
|
|
|
for (i = 0; i < nr_ring_ref; i++) {
|
|
|
|
const char *key = g_strdup_printf("ring-ref%u", i);
|
|
|
|
|
|
|
|
if (xen_device_frontend_scanf(xendev, key, "%u",
|
|
|
|
&ring_ref[i]) != 1) {
|
|
|
|
error_setg(errp, "failed to read %s", key);
|
|
|
|
g_free((gpointer)key);
|
|
|
|
g_free(ring_ref);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free((gpointer)key);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_setg(errp, "invalid ring-page-order (%d)", order);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xen_device_frontend_scanf(xendev, "event-channel", "%u",
|
|
|
|
&event_channel) != 1) {
|
|
|
|
error_setg(errp, "failed to read event-channel");
|
|
|
|
g_free(ring_ref);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xen_device_frontend_scanf(xendev, "protocol", "%ms",
|
|
|
|
&str) != 1) {
|
|
|
|
protocol = BLKIF_PROTOCOL_NATIVE;
|
|
|
|
} else {
|
|
|
|
if (strcmp(str, XEN_IO_PROTO_ABI_X86_32) == 0) {
|
|
|
|
protocol = BLKIF_PROTOCOL_X86_32;
|
|
|
|
} else if (strcmp(str, XEN_IO_PROTO_ABI_X86_64) == 0) {
|
|
|
|
protocol = BLKIF_PROTOCOL_X86_64;
|
|
|
|
} else {
|
|
|
|
protocol = BLKIF_PROTOCOL_NATIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
xen_block_dataplane_start(blockdev->dataplane, ring_ref, nr_ring_ref,
|
|
|
|
event_channel, protocol, errp);
|
|
|
|
|
|
|
|
g_free(ring_ref);
|
2019-01-08 17:48:50 +03:00
|
|
|
}
|
|
|
|
|
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
2020-05-05 18:29:24 +03:00
|
|
|
static void xen_block_unrealize(XenDevice *xendev)
|
2019-01-08 17:48:48 +03:00
|
|
|
{
|
|
|
|
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
|
|
|
XenBlockDeviceClass *blockdev_class =
|
|
|
|
XEN_BLOCK_DEVICE_GET_CLASS(xendev);
|
|
|
|
const char *type = object_get_typename(OBJECT(blockdev));
|
|
|
|
XenBlockVdev *vdev = &blockdev->props.vdev;
|
|
|
|
|
|
|
|
if (vdev->type == XEN_BLOCK_VDEV_TYPE_INVALID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_xen_block_unrealize(type, vdev->disk, vdev->partition);
|
|
|
|
|
2019-01-08 17:48:50 +03:00
|
|
|
/* Disconnect from the frontend in case this has not already happened */
|
|
|
|
xen_block_disconnect(xendev, NULL);
|
|
|
|
|
2019-01-08 17:48:59 +03:00
|
|
|
xen_block_dataplane_destroy(blockdev->dataplane);
|
|
|
|
blockdev->dataplane = NULL;
|
|
|
|
|
2019-01-08 17:48:48 +03:00
|
|
|
if (blockdev_class->unrealize) {
|
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
2020-05-05 18:29:24 +03:00
|
|
|
blockdev_class->unrealize(blockdev);
|
2019-01-08 17:48:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 18:33:16 +03:00
|
|
|
static void xen_block_set_size(XenBlockDevice *blockdev)
|
|
|
|
{
|
|
|
|
const char *type = object_get_typename(OBJECT(blockdev));
|
|
|
|
XenBlockVdev *vdev = &blockdev->props.vdev;
|
|
|
|
BlockConf *conf = &blockdev->props.conf;
|
2019-04-09 19:40:38 +03:00
|
|
|
int64_t sectors = blk_getlength(conf->blk) / conf->logical_block_size;
|
2019-01-31 18:33:16 +03:00
|
|
|
XenDevice *xendev = XEN_DEVICE(blockdev);
|
|
|
|
|
|
|
|
trace_xen_block_size(type, vdev->disk, vdev->partition, sectors);
|
|
|
|
|
|
|
|
xen_device_backend_printf(xendev, "sectors", "%"PRIi64, sectors);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_block_resize_cb(void *opaque)
|
|
|
|
{
|
|
|
|
XenBlockDevice *blockdev = opaque;
|
|
|
|
XenDevice *xendev = XEN_DEVICE(blockdev);
|
|
|
|
enum xenbus_state state = xen_device_backend_get_state(xendev);
|
|
|
|
|
|
|
|
xen_block_set_size(blockdev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mimic the behaviour of Linux xen-blkback and re-write the state
|
|
|
|
* to trigger the frontend watch.
|
|
|
|
*/
|
|
|
|
xen_device_backend_printf(xendev, "state", "%u", state);
|
|
|
|
}
|
|
|
|
|
2023-05-16 22:02:29 +03:00
|
|
|
/* Suspend request handling */
|
|
|
|
static void xen_block_drained_begin(void *opaque)
|
|
|
|
{
|
|
|
|
XenBlockDevice *blockdev = opaque;
|
|
|
|
|
|
|
|
xen_block_dataplane_detach(blockdev->dataplane);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resume request handling */
|
|
|
|
static void xen_block_drained_end(void *opaque)
|
|
|
|
{
|
|
|
|
XenBlockDevice *blockdev = opaque;
|
|
|
|
|
|
|
|
xen_block_dataplane_attach(blockdev->dataplane);
|
|
|
|
}
|
|
|
|
|
2019-01-31 18:33:16 +03:00
|
|
|
static const BlockDevOps xen_block_dev_ops = {
|
2023-05-16 22:02:29 +03:00
|
|
|
.resize_cb = xen_block_resize_cb,
|
|
|
|
.drained_begin = xen_block_drained_begin,
|
|
|
|
.drained_end = xen_block_drained_end,
|
2019-01-31 18:33:16 +03:00
|
|
|
};
|
|
|
|
|
2019-01-08 17:48:48 +03:00
|
|
|
static void xen_block_realize(XenDevice *xendev, Error **errp)
|
|
|
|
{
|
2020-07-07 19:50:37 +03:00
|
|
|
ERRP_GUARD();
|
2019-01-08 17:48:48 +03:00
|
|
|
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
|
|
|
XenBlockDeviceClass *blockdev_class =
|
|
|
|
XEN_BLOCK_DEVICE_GET_CLASS(xendev);
|
|
|
|
const char *type = object_get_typename(OBJECT(blockdev));
|
|
|
|
XenBlockVdev *vdev = &blockdev->props.vdev;
|
2019-01-08 17:48:59 +03:00
|
|
|
BlockConf *conf = &blockdev->props.conf;
|
2019-04-09 19:40:38 +03:00
|
|
|
BlockBackend *blk = conf->blk;
|
2019-01-08 17:48:48 +03:00
|
|
|
|
|
|
|
if (vdev->type == XEN_BLOCK_VDEV_TYPE_INVALID) {
|
|
|
|
error_setg(errp, "vdev property not set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_xen_block_realize(type, vdev->disk, vdev->partition);
|
|
|
|
|
|
|
|
if (blockdev_class->realize) {
|
2020-07-07 19:50:37 +03:00
|
|
|
blockdev_class->realize(blockdev, errp);
|
|
|
|
if (*errp) {
|
2019-01-08 17:48:59 +03:00
|
|
|
return;
|
2019-01-08 17:48:48 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 17:48:59 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The blkif protocol does not deal with removable media, so it must
|
|
|
|
* always be present, even for CDRom devices.
|
|
|
|
*/
|
2019-04-09 19:40:38 +03:00
|
|
|
assert(blk);
|
|
|
|
if (!blk_is_inserted(blk)) {
|
2019-01-08 17:48:59 +03:00
|
|
|
error_setg(errp, "device needs media, but drive is empty");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!blkconf_apply_backend_options(conf, blockdev->info & VDISK_READONLY,
|
2019-01-31 18:33:16 +03:00
|
|
|
true, errp)) {
|
2019-01-08 17:48:59 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(blockdev->info & VDISK_CDROM) &&
|
|
|
|
!blkconf_geometry(conf, NULL, 65535, 255, 255, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-29 01:55:10 +03:00
|
|
|
if (!blkconf_blocksizes(conf, errp)) {
|
2019-01-08 17:48:59 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-20 17:28:25 +03:00
|
|
|
if (conf->discard_granularity == -1) {
|
|
|
|
conf->discard_granularity = conf->physical_block_size;
|
|
|
|
}
|
|
|
|
|
2019-04-09 19:40:38 +03:00
|
|
|
if (blk_get_flags(blk) & BDRV_O_UNMAP) {
|
2019-01-08 17:48:59 +03:00
|
|
|
xen_device_backend_printf(xendev, "feature-discard", "%u", 1);
|
2019-03-20 17:28:25 +03:00
|
|
|
xen_device_backend_printf(xendev, "discard-granularity", "%u",
|
|
|
|
conf->discard_granularity);
|
2021-01-18 18:33:30 +03:00
|
|
|
xen_device_backend_printf(xendev, "discard-alignment", "%u", 0);
|
2019-01-08 17:48:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
xen_device_backend_printf(xendev, "feature-flush-cache", "%u", 1);
|
2023-01-30 19:27:07 +03:00
|
|
|
|
|
|
|
if (qemu_xen_gnttab_can_map_multi()) {
|
|
|
|
xen_device_backend_printf(xendev, "max-ring-page-order", "%u",
|
|
|
|
blockdev->props.max_ring_page_order);
|
|
|
|
}
|
|
|
|
|
2019-01-08 17:48:59 +03:00
|
|
|
xen_device_backend_printf(xendev, "info", "%u", blockdev->info);
|
|
|
|
|
|
|
|
xen_device_frontend_printf(xendev, "virtual-device", "%lu",
|
|
|
|
vdev->number);
|
|
|
|
xen_device_frontend_printf(xendev, "device-type", "%s",
|
|
|
|
blockdev->device_type);
|
|
|
|
|
|
|
|
xen_device_backend_printf(xendev, "sector-size", "%u",
|
2019-04-09 19:40:38 +03:00
|
|
|
conf->logical_block_size);
|
2019-01-31 18:33:16 +03:00
|
|
|
|
|
|
|
xen_block_set_size(blockdev);
|
2019-01-08 17:48:59 +03:00
|
|
|
|
|
|
|
blockdev->dataplane =
|
2019-04-09 19:40:38 +03:00
|
|
|
xen_block_dataplane_create(xendev, blk, conf->logical_block_size,
|
|
|
|
blockdev->props.iothread);
|
2023-05-16 22:02:29 +03:00
|
|
|
|
|
|
|
blk_set_dev_ops(blk, &xen_block_dev_ops, blockdev);
|
2019-01-08 17:48:48 +03:00
|
|
|
}
|
|
|
|
|
2019-01-08 17:48:50 +03:00
|
|
|
static void xen_block_frontend_changed(XenDevice *xendev,
|
|
|
|
enum xenbus_state frontend_state,
|
|
|
|
Error **errp)
|
|
|
|
{
|
2020-07-07 19:50:37 +03:00
|
|
|
ERRP_GUARD();
|
2019-01-08 17:48:50 +03:00
|
|
|
enum xenbus_state backend_state = xen_device_backend_get_state(xendev);
|
|
|
|
|
|
|
|
switch (frontend_state) {
|
|
|
|
case XenbusStateInitialised:
|
|
|
|
case XenbusStateConnected:
|
|
|
|
if (backend_state == XenbusStateConnected) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:50:37 +03:00
|
|
|
xen_block_disconnect(xendev, errp);
|
|
|
|
if (*errp) {
|
2019-01-08 17:48:50 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:50:37 +03:00
|
|
|
xen_block_connect(xendev, errp);
|
|
|
|
if (*errp) {
|
2019-01-08 17:48:50 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xen_device_backend_set_state(xendev, XenbusStateConnected);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XenbusStateClosing:
|
|
|
|
xen_device_backend_set_state(xendev, XenbusStateClosing);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XenbusStateClosed:
|
2019-09-18 14:57:02 +03:00
|
|
|
case XenbusStateUnknown:
|
2020-07-07 19:50:37 +03:00
|
|
|
xen_block_disconnect(xendev, errp);
|
|
|
|
if (*errp) {
|
2019-01-08 17:48:50 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xen_device_backend_set_state(xendev, XenbusStateClosed);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 17:48:48 +03:00
|
|
|
static char *disk_to_vbd_name(unsigned int disk)
|
|
|
|
{
|
|
|
|
char *name, *prefix = (disk >= 26) ?
|
|
|
|
disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
|
|
|
|
|
|
|
|
name = g_strdup_printf("%s%c", prefix, 'a' + disk % 26);
|
|
|
|
g_free(prefix);
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_block_get_vdev(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-12 01:05:27 +03:00
|
|
|
XenBlockVdev *vdev = object_field_prop_ptr(obj, prop);
|
2019-01-08 17:48:48 +03:00
|
|
|
char *str;
|
|
|
|
|
|
|
|
switch (vdev->type) {
|
|
|
|
case XEN_BLOCK_VDEV_TYPE_DP:
|
|
|
|
str = g_strdup_printf("d%lup%lu", vdev->disk, vdev->partition);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XEN_BLOCK_VDEV_TYPE_XVD:
|
|
|
|
case XEN_BLOCK_VDEV_TYPE_HD:
|
|
|
|
case XEN_BLOCK_VDEV_TYPE_SD: {
|
2023-09-21 15:13:11 +03:00
|
|
|
char *vbd_name = disk_to_vbd_name(vdev->disk);
|
2019-01-08 17:48:48 +03:00
|
|
|
|
|
|
|
str = g_strdup_printf("%s%s%lu",
|
|
|
|
(vdev->type == XEN_BLOCK_VDEV_TYPE_XVD) ?
|
|
|
|
"xvd" :
|
|
|
|
(vdev->type == XEN_BLOCK_VDEV_TYPE_HD) ?
|
|
|
|
"hd" :
|
|
|
|
"sd",
|
2023-09-21 15:13:11 +03:00
|
|
|
vbd_name, vdev->partition);
|
|
|
|
g_free(vbd_name);
|
2019-01-08 17:48:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
error_setg(errp, "invalid vdev type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
visit_type_str(v, name, &str, errp);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
2019-02-15 19:25:33 +03:00
|
|
|
static int vbd_name_to_disk(const char *name, const char **endp,
|
|
|
|
unsigned long *disk)
|
2019-01-08 17:48:48 +03:00
|
|
|
{
|
2019-02-15 19:25:33 +03:00
|
|
|
unsigned int n = 0;
|
2019-01-08 17:48:48 +03:00
|
|
|
|
|
|
|
while (*name != '\0') {
|
|
|
|
if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-02-15 19:25:33 +03:00
|
|
|
n *= 26;
|
|
|
|
n += *name++ - 'a' + 1;
|
2019-01-08 17:48:48 +03:00
|
|
|
}
|
|
|
|
*endp = name;
|
|
|
|
|
2019-02-15 19:25:33 +03:00
|
|
|
if (!n) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*disk = n - 1;
|
|
|
|
|
|
|
|
return 0;
|
2019-01-08 17:48:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-12 01:05:27 +03:00
|
|
|
XenBlockVdev *vdev = object_field_prop_ptr(obj, prop);
|
2019-01-08 17:48:48 +03:00
|
|
|
char *str, *p;
|
|
|
|
const char *end;
|
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!visit_type_str(v, name, &str, errp)) {
|
2019-01-08 17:48:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = strchr(str, 'd');
|
|
|
|
if (!p) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p++ = '\0';
|
|
|
|
if (*str == '\0') {
|
|
|
|
vdev->type = XEN_BLOCK_VDEV_TYPE_DP;
|
|
|
|
} else if (strcmp(str, "xv") == 0) {
|
|
|
|
vdev->type = XEN_BLOCK_VDEV_TYPE_XVD;
|
|
|
|
} else if (strcmp(str, "h") == 0) {
|
|
|
|
vdev->type = XEN_BLOCK_VDEV_TYPE_HD;
|
|
|
|
} else if (strcmp(str, "s") == 0) {
|
|
|
|
vdev->type = XEN_BLOCK_VDEV_TYPE_SD;
|
|
|
|
} else {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vdev->type == XEN_BLOCK_VDEV_TYPE_DP) {
|
|
|
|
if (qemu_strtoul(p, &end, 10, &vdev->disk)) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*end == 'p') {
|
2019-02-15 19:25:32 +03:00
|
|
|
if (*(++end) == '\0') {
|
2019-01-08 17:48:48 +03:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-02-15 19:25:33 +03:00
|
|
|
if (vbd_name_to_disk(p, &end, &vdev->disk)) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
2019-01-08 17:48:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*end != '\0') {
|
|
|
|
p = (char *)end;
|
|
|
|
|
|
|
|
if (qemu_strtoul(p, &end, 10, &vdev->partition)) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*end != '\0') {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vdev->partition = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (vdev->type) {
|
|
|
|
case XEN_BLOCK_VDEV_TYPE_DP:
|
|
|
|
case XEN_BLOCK_VDEV_TYPE_XVD:
|
|
|
|
if (vdev->disk < (1 << 4) && vdev->partition < (1 << 4)) {
|
|
|
|
vdev->number = (202 << 8) | (vdev->disk << 4) |
|
|
|
|
vdev->partition;
|
|
|
|
} else if (vdev->disk < (1 << 20) && vdev->partition < (1 << 8)) {
|
|
|
|
vdev->number = (1 << 28) | (vdev->disk << 8) |
|
|
|
|
vdev->partition;
|
|
|
|
} else {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XEN_BLOCK_VDEV_TYPE_HD:
|
|
|
|
if ((vdev->disk == 0 || vdev->disk == 1) &&
|
|
|
|
vdev->partition < (1 << 6)) {
|
|
|
|
vdev->number = (3 << 8) | (vdev->disk << 6) | vdev->partition;
|
|
|
|
} else if ((vdev->disk == 2 || vdev->disk == 3) &&
|
|
|
|
vdev->partition < (1 << 6)) {
|
|
|
|
vdev->number = (22 << 8) | ((vdev->disk - 2) << 6) |
|
|
|
|
vdev->partition;
|
|
|
|
} else {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XEN_BLOCK_VDEV_TYPE_SD:
|
|
|
|
if (vdev->disk < (1 << 4) && vdev->partition < (1 << 4)) {
|
|
|
|
vdev->number = (8 << 8) | (vdev->disk << 4) | vdev->partition;
|
|
|
|
} else {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(str);
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
error_setg(errp, "invalid virtual disk specifier");
|
|
|
|
|
|
|
|
vdev->type = XEN_BLOCK_VDEV_TYPE_INVALID;
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This property deals with 'vdev' names adhering to the Xen VBD naming
|
|
|
|
* scheme described in:
|
|
|
|
*
|
|
|
|
* https://xenbits.xen.org/docs/unstable/man/xen-vbd-interface.7.html
|
|
|
|
*/
|
|
|
|
const PropertyInfo xen_block_prop_vdev = {
|
|
|
|
.name = "str",
|
|
|
|
.description = "Virtual Disk specifier: d*p*/xvd*/hd*/sd*",
|
|
|
|
.get = xen_block_get_vdev,
|
|
|
|
.set = xen_block_set_vdev,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Property xen_block_props[] = {
|
|
|
|
DEFINE_PROP("vdev", XenBlockDevice, props.vdev,
|
|
|
|
xen_block_prop_vdev, XenBlockVdev),
|
2019-01-08 17:48:59 +03:00
|
|
|
DEFINE_BLOCK_PROPERTIES(XenBlockDevice, props.conf),
|
|
|
|
DEFINE_PROP_UINT32("max-ring-page-order", XenBlockDevice,
|
|
|
|
props.max_ring_page_order, 4),
|
|
|
|
DEFINE_PROP_LINK("iothread", XenBlockDevice, props.iothread,
|
|
|
|
TYPE_IOTHREAD, IOThread *),
|
2019-01-08 17:48:48 +03:00
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
};
|
|
|
|
|
|
|
|
static void xen_block_class_init(ObjectClass *class, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dev_class = DEVICE_CLASS(class);
|
|
|
|
XenDeviceClass *xendev_class = XEN_DEVICE_CLASS(class);
|
|
|
|
|
2019-01-08 17:49:01 +03:00
|
|
|
xendev_class->backend = "qdisk";
|
2019-01-08 17:48:59 +03:00
|
|
|
xendev_class->device = "vbd";
|
2019-01-08 17:48:49 +03:00
|
|
|
xendev_class->get_name = xen_block_get_name;
|
2019-01-08 17:48:48 +03:00
|
|
|
xendev_class->realize = xen_block_realize;
|
2019-01-08 17:48:50 +03:00
|
|
|
xendev_class->frontend_changed = xen_block_frontend_changed;
|
2019-01-08 17:48:48 +03:00
|
|
|
xendev_class->unrealize = xen_block_unrealize;
|
|
|
|
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dev_class, xen_block_props);
|
2019-01-08 17:48:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo xen_block_type_info = {
|
|
|
|
.name = TYPE_XEN_BLOCK_DEVICE,
|
|
|
|
.parent = TYPE_XEN_DEVICE,
|
|
|
|
.instance_size = sizeof(XenBlockDevice),
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(XenBlockDeviceClass),
|
|
|
|
.class_init = xen_block_class_init,
|
|
|
|
};
|
|
|
|
|
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
2020-05-05 18:29:24 +03:00
|
|
|
static void xen_disk_unrealize(XenBlockDevice *blockdev)
|
2019-01-08 17:48:48 +03:00
|
|
|
{
|
|
|
|
trace_xen_disk_unrealize();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_disk_realize(XenBlockDevice *blockdev, Error **errp)
|
|
|
|
{
|
2019-01-08 17:48:59 +03:00
|
|
|
BlockConf *conf = &blockdev->props.conf;
|
|
|
|
|
2019-01-08 17:48:48 +03:00
|
|
|
trace_xen_disk_realize();
|
2019-01-08 17:48:59 +03:00
|
|
|
|
|
|
|
blockdev->device_type = "disk";
|
|
|
|
|
|
|
|
if (!conf->blk) {
|
|
|
|
error_setg(errp, "drive property not set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-18 15:34:47 +03:00
|
|
|
blockdev->info = blk_supports_write_perm(conf->blk) ? 0 : VDISK_READONLY;
|
2019-01-08 17:48:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_disk_class_init(ObjectClass *class, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dev_class = DEVICE_CLASS(class);
|
|
|
|
XenBlockDeviceClass *blockdev_class = XEN_BLOCK_DEVICE_CLASS(class);
|
|
|
|
|
|
|
|
blockdev_class->realize = xen_disk_realize;
|
|
|
|
blockdev_class->unrealize = xen_disk_unrealize;
|
|
|
|
|
|
|
|
dev_class->desc = "Xen Disk Device";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo xen_disk_type_info = {
|
|
|
|
.name = TYPE_XEN_DISK_DEVICE,
|
|
|
|
.parent = TYPE_XEN_BLOCK_DEVICE,
|
|
|
|
.instance_size = sizeof(XenDiskDevice),
|
|
|
|
.class_init = xen_disk_class_init,
|
|
|
|
};
|
|
|
|
|
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
2020-05-05 18:29:24 +03:00
|
|
|
static void xen_cdrom_unrealize(XenBlockDevice *blockdev)
|
2019-01-08 17:48:48 +03:00
|
|
|
{
|
|
|
|
trace_xen_cdrom_unrealize();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_cdrom_realize(XenBlockDevice *blockdev, Error **errp)
|
|
|
|
{
|
2019-01-08 17:48:59 +03:00
|
|
|
BlockConf *conf = &blockdev->props.conf;
|
|
|
|
|
2019-01-08 17:48:48 +03:00
|
|
|
trace_xen_cdrom_realize();
|
2019-01-08 17:48:59 +03:00
|
|
|
|
|
|
|
blockdev->device_type = "cdrom";
|
|
|
|
|
|
|
|
if (!conf->blk) {
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Set up an empty drive */
|
2019-04-25 15:25:10 +03:00
|
|
|
conf->blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
|
2019-01-08 17:48:59 +03:00
|
|
|
|
|
|
|
rc = blk_attach_dev(conf->blk, DEVICE(blockdev));
|
|
|
|
if (!rc) {
|
|
|
|
error_setg_errno(errp, -rc, "failed to create drive");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
blockdev->info = VDISK_READONLY | VDISK_CDROM;
|
2019-01-08 17:48:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_cdrom_class_init(ObjectClass *class, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dev_class = DEVICE_CLASS(class);
|
|
|
|
XenBlockDeviceClass *blockdev_class = XEN_BLOCK_DEVICE_CLASS(class);
|
|
|
|
|
|
|
|
blockdev_class->realize = xen_cdrom_realize;
|
|
|
|
blockdev_class->unrealize = xen_cdrom_unrealize;
|
|
|
|
|
|
|
|
dev_class->desc = "Xen CD-ROM Device";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo xen_cdrom_type_info = {
|
|
|
|
.name = TYPE_XEN_CDROM_DEVICE,
|
|
|
|
.parent = TYPE_XEN_BLOCK_DEVICE,
|
|
|
|
.instance_size = sizeof(XenCDRomDevice),
|
|
|
|
.class_init = xen_cdrom_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void xen_block_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&xen_block_type_info);
|
|
|
|
type_register_static(&xen_disk_type_info);
|
|
|
|
type_register_static(&xen_cdrom_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(xen_block_register_types)
|
2019-01-08 17:49:01 +03:00
|
|
|
|
|
|
|
static void xen_block_blockdev_del(const char *node_name, Error **errp)
|
|
|
|
{
|
|
|
|
trace_xen_block_blockdev_del(node_name);
|
|
|
|
|
|
|
|
qmp_blockdev_del(node_name, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *xen_block_blockdev_add(const char *id, QDict *qdict,
|
|
|
|
Error **errp)
|
|
|
|
{
|
2020-07-07 19:50:37 +03:00
|
|
|
ERRP_GUARD();
|
2019-01-08 17:49:01 +03:00
|
|
|
const char *driver = qdict_get_try_str(qdict, "driver");
|
|
|
|
BlockdevOptions *options = NULL;
|
|
|
|
char *node_name;
|
|
|
|
Visitor *v;
|
|
|
|
|
|
|
|
if (!driver) {
|
|
|
|
error_setg(errp, "no 'driver' parameter");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
node_name = g_strdup_printf("%s-%s", id, driver);
|
|
|
|
qdict_put_str(qdict, "node-name", node_name);
|
|
|
|
|
|
|
|
trace_xen_block_blockdev_add(node_name);
|
|
|
|
|
|
|
|
v = qobject_input_visitor_new(QOBJECT(qdict));
|
2020-07-07 19:06:07 +03:00
|
|
|
visit_type_BlockdevOptions(v, NULL, &options, errp);
|
2019-01-08 17:49:01 +03:00
|
|
|
visit_free(v);
|
2020-07-07 19:06:07 +03:00
|
|
|
if (!options) {
|
2019-01-08 17:49:01 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:50:37 +03:00
|
|
|
qmp_blockdev_add(options, errp);
|
2019-01-08 17:49:01 +03:00
|
|
|
|
2020-07-07 19:50:37 +03:00
|
|
|
if (*errp) {
|
2019-01-08 17:49:01 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
qapi_free_BlockdevOptions(options);
|
|
|
|
|
|
|
|
return node_name;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (options) {
|
|
|
|
qapi_free_BlockdevOptions(options);
|
|
|
|
}
|
|
|
|
g_free(node_name);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_block_drive_destroy(XenBlockDrive *drive, Error **errp)
|
|
|
|
{
|
2020-07-07 19:50:37 +03:00
|
|
|
ERRP_GUARD();
|
2019-01-08 17:49:01 +03:00
|
|
|
char *node_name = drive->node_name;
|
|
|
|
|
|
|
|
if (node_name) {
|
2020-07-07 19:50:37 +03:00
|
|
|
xen_block_blockdev_del(node_name, errp);
|
|
|
|
if (*errp) {
|
2019-01-08 17:49:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_free(node_name);
|
|
|
|
drive->node_name = NULL;
|
|
|
|
}
|
|
|
|
g_free(drive->id);
|
|
|
|
g_free(drive);
|
|
|
|
}
|
|
|
|
|
|
|
|
static XenBlockDrive *xen_block_drive_create(const char *id,
|
|
|
|
const char *device_type,
|
|
|
|
QDict *opts, Error **errp)
|
|
|
|
{
|
2020-07-07 19:50:37 +03:00
|
|
|
ERRP_GUARD();
|
2019-01-08 17:49:01 +03:00
|
|
|
const char *params = qdict_get_try_str(opts, "params");
|
|
|
|
const char *mode = qdict_get_try_str(opts, "mode");
|
|
|
|
const char *direct_io_safe = qdict_get_try_str(opts, "direct-io-safe");
|
|
|
|
const char *discard_enable = qdict_get_try_str(opts, "discard-enable");
|
|
|
|
char *driver = NULL;
|
|
|
|
char *filename = NULL;
|
|
|
|
XenBlockDrive *drive = NULL;
|
|
|
|
QDict *file_layer;
|
|
|
|
QDict *driver_layer;
|
2021-04-30 19:34:32 +03:00
|
|
|
struct stat st;
|
|
|
|
int rc;
|
2019-01-08 17:49:01 +03:00
|
|
|
|
|
|
|
if (params) {
|
|
|
|
char **v = g_strsplit(params, ":", 2);
|
|
|
|
|
|
|
|
if (v[1] == NULL) {
|
|
|
|
filename = g_strdup(v[0]);
|
|
|
|
driver = g_strdup("raw");
|
|
|
|
} else {
|
|
|
|
if (strcmp(v[0], "aio") == 0) {
|
|
|
|
driver = g_strdup("raw");
|
|
|
|
} else if (strcmp(v[0], "vhd") == 0) {
|
|
|
|
driver = g_strdup("vpc");
|
|
|
|
} else {
|
|
|
|
driver = g_strdup(v[0]);
|
|
|
|
}
|
|
|
|
filename = g_strdup(v[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev(v);
|
2019-02-19 19:34:40 +03:00
|
|
|
} else {
|
|
|
|
error_setg(errp, "no params");
|
2019-01-08 17:49:01 +03:00
|
|
|
goto done;
|
|
|
|
}
|
2019-02-19 19:34:40 +03:00
|
|
|
|
|
|
|
assert(filename);
|
2019-01-08 17:49:01 +03:00
|
|
|
assert(driver);
|
|
|
|
|
|
|
|
drive = g_new0(XenBlockDrive, 1);
|
|
|
|
drive->id = g_strdup(id);
|
|
|
|
|
2021-04-30 19:34:32 +03:00
|
|
|
rc = stat(filename, &st);
|
|
|
|
if (rc) {
|
|
|
|
error_setg_errno(errp, errno, "Could not stat file '%s'", filename);
|
|
|
|
goto done;
|
|
|
|
}
|
2023-07-04 20:18:19 +03:00
|
|
|
|
|
|
|
file_layer = qdict_new();
|
|
|
|
driver_layer = qdict_new();
|
|
|
|
|
2021-04-30 19:34:32 +03:00
|
|
|
if (S_ISBLK(st.st_mode)) {
|
|
|
|
qdict_put_str(file_layer, "driver", "host_device");
|
|
|
|
} else {
|
|
|
|
qdict_put_str(file_layer, "driver", "file");
|
|
|
|
}
|
|
|
|
|
2019-01-08 17:49:01 +03:00
|
|
|
qdict_put_str(file_layer, "filename", filename);
|
|
|
|
|
|
|
|
if (mode && *mode != 'w') {
|
|
|
|
qdict_put_bool(file_layer, "read-only", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (direct_io_safe) {
|
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
if (!qemu_strtoul(direct_io_safe, NULL, 2, &value) && !!value) {
|
|
|
|
QDict *cache_qdict = qdict_new();
|
|
|
|
|
|
|
|
qdict_put_bool(cache_qdict, "direct", true);
|
2019-03-13 20:44:33 +03:00
|
|
|
qdict_put(file_layer, "cache", cache_qdict);
|
2019-01-08 17:49:01 +03:00
|
|
|
|
|
|
|
qdict_put_str(file_layer, "aio", "native");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (discard_enable) {
|
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
if (!qemu_strtoul(discard_enable, NULL, 2, &value) && !!value) {
|
|
|
|
qdict_put_str(file_layer, "discard", "unmap");
|
2019-03-20 17:28:25 +03:00
|
|
|
qdict_put_str(driver_layer, "discard", "unmap");
|
2019-01-08 17:49:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is necessary to turn file locking off as an emulated device
|
|
|
|
* may have already opened the same image file.
|
|
|
|
*/
|
|
|
|
qdict_put_str(file_layer, "locking", "off");
|
|
|
|
|
|
|
|
qdict_put_str(driver_layer, "driver", driver);
|
2019-02-19 19:34:40 +03:00
|
|
|
|
2019-03-13 20:44:33 +03:00
|
|
|
qdict_put(driver_layer, "file", file_layer);
|
2019-01-08 17:49:01 +03:00
|
|
|
|
|
|
|
g_assert(!drive->node_name);
|
|
|
|
drive->node_name = xen_block_blockdev_add(drive->id, driver_layer,
|
2020-07-07 19:50:37 +03:00
|
|
|
errp);
|
2019-01-08 17:49:01 +03:00
|
|
|
|
2019-02-19 19:34:40 +03:00
|
|
|
qobject_unref(driver_layer);
|
2019-01-08 17:49:01 +03:00
|
|
|
|
2019-02-19 19:34:40 +03:00
|
|
|
done:
|
2023-07-04 20:18:19 +03:00
|
|
|
g_free(filename);
|
|
|
|
g_free(driver);
|
2020-07-07 19:50:37 +03:00
|
|
|
if (*errp) {
|
2019-01-08 17:49:01 +03:00
|
|
|
xen_block_drive_destroy(drive, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return drive;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *xen_block_drive_get_node_name(XenBlockDrive *drive)
|
|
|
|
{
|
|
|
|
return drive->node_name ? drive->node_name : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_block_iothread_destroy(XenBlockIOThread *iothread,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
qmp_object_del(iothread->id, errp);
|
|
|
|
|
|
|
|
g_free(iothread->id);
|
|
|
|
g_free(iothread);
|
|
|
|
}
|
|
|
|
|
|
|
|
static XenBlockIOThread *xen_block_iothread_create(const char *id,
|
|
|
|
Error **errp)
|
|
|
|
{
|
2020-07-07 19:50:37 +03:00
|
|
|
ERRP_GUARD();
|
2019-01-08 17:49:01 +03:00
|
|
|
XenBlockIOThread *iothread = g_new(XenBlockIOThread, 1);
|
2020-10-20 14:27:22 +03:00
|
|
|
ObjectOptions *opts;
|
2019-01-08 17:49:01 +03:00
|
|
|
|
|
|
|
iothread->id = g_strdup(id);
|
|
|
|
|
2020-10-20 14:27:22 +03:00
|
|
|
opts = g_new(ObjectOptions, 1);
|
|
|
|
*opts = (ObjectOptions) {
|
|
|
|
.qom_type = OBJECT_TYPE_IOTHREAD,
|
|
|
|
.id = g_strdup(id),
|
|
|
|
};
|
|
|
|
qmp_object_add(opts, errp);
|
|
|
|
qapi_free_ObjectOptions(opts);
|
2020-02-24 17:29:55 +03:00
|
|
|
|
2020-07-07 19:50:37 +03:00
|
|
|
if (*errp) {
|
2019-01-08 17:49:01 +03:00
|
|
|
g_free(iothread->id);
|
|
|
|
g_free(iothread);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iothread;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_block_device_create(XenBackendInstance *backend,
|
|
|
|
QDict *opts, Error **errp)
|
|
|
|
{
|
2020-07-07 19:50:37 +03:00
|
|
|
ERRP_GUARD();
|
2019-01-08 17:49:01 +03:00
|
|
|
XenBus *xenbus = xen_backend_get_bus(backend);
|
|
|
|
const char *name = xen_backend_get_name(backend);
|
|
|
|
unsigned long number;
|
|
|
|
const char *vdev, *device_type;
|
|
|
|
XenBlockDrive *drive = NULL;
|
|
|
|
XenBlockIOThread *iothread = NULL;
|
|
|
|
XenDevice *xendev = NULL;
|
|
|
|
const char *type;
|
|
|
|
XenBlockDevice *blockdev;
|
|
|
|
|
|
|
|
if (qemu_strtoul(name, NULL, 10, &number)) {
|
|
|
|
error_setg(errp, "failed to parse name '%s'", name);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_xen_block_device_create(number);
|
|
|
|
|
|
|
|
vdev = qdict_get_try_str(opts, "dev");
|
|
|
|
if (!vdev) {
|
|
|
|
error_setg(errp, "no dev parameter");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_type = qdict_get_try_str(opts, "device-type");
|
|
|
|
if (!device_type) {
|
|
|
|
error_setg(errp, "no device-type parameter");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(device_type, "disk")) {
|
|
|
|
type = TYPE_XEN_DISK_DEVICE;
|
|
|
|
} else if (!strcmp(device_type, "cdrom")) {
|
|
|
|
type = TYPE_XEN_CDROM_DEVICE;
|
|
|
|
} else {
|
|
|
|
error_setg(errp, "invalid device-type parameter '%s'", device_type);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:50:37 +03:00
|
|
|
drive = xen_block_drive_create(vdev, device_type, opts, errp);
|
2019-01-08 17:49:01 +03:00
|
|
|
if (!drive) {
|
2020-07-07 19:50:37 +03:00
|
|
|
error_prepend(errp, "failed to create drive: ");
|
2019-01-08 17:49:01 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:50:37 +03:00
|
|
|
iothread = xen_block_iothread_create(vdev, errp);
|
|
|
|
if (*errp) {
|
|
|
|
error_prepend(errp, "failed to create iothread: ");
|
2019-01-08 17:49:01 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-06-10 08:31:59 +03:00
|
|
|
xendev = XEN_DEVICE(qdev_new(type));
|
2019-01-08 17:49:01 +03:00
|
|
|
blockdev = XEN_BLOCK_DEVICE(xendev);
|
|
|
|
|
qom: Use returned bool to check for failure, Coccinelle part
The previous commit enables conversion of
foo(..., &err);
if (err) {
...
}
to
if (!foo(..., errp)) {
...
}
for QOM functions that now return true / false on success / error.
Coccinelle script:
@@
identifier fun = {
object_apply_global_props, object_initialize_child_with_props,
object_initialize_child_with_propsv, object_property_get,
object_property_get_bool, object_property_parse, object_property_set,
object_property_set_bool, object_property_set_int,
object_property_set_link, object_property_set_qobject,
object_property_set_str, object_property_set_uint, object_set_props,
object_set_propv, user_creatable_add_dict,
user_creatable_complete, user_creatable_del
};
expression list args, args2;
typedef Error;
Error *err;
@@
- fun(args, &err, args2);
- if (err)
+ if (!fun(args, &err, args2))
{
...
}
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Line breaks tidied up manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-29-armbru@redhat.com>
2020-07-07 19:05:56 +03:00
|
|
|
if (!object_property_set_str(OBJECT(xendev), "vdev", vdev,
|
2020-07-07 19:50:37 +03:00
|
|
|
errp)) {
|
|
|
|
error_prepend(errp, "failed to set 'vdev': ");
|
2019-01-08 17:49:01 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
qom: Use returned bool to check for failure, Coccinelle part
The previous commit enables conversion of
foo(..., &err);
if (err) {
...
}
to
if (!foo(..., errp)) {
...
}
for QOM functions that now return true / false on success / error.
Coccinelle script:
@@
identifier fun = {
object_apply_global_props, object_initialize_child_with_props,
object_initialize_child_with_propsv, object_property_get,
object_property_get_bool, object_property_parse, object_property_set,
object_property_set_bool, object_property_set_int,
object_property_set_link, object_property_set_qobject,
object_property_set_str, object_property_set_uint, object_set_props,
object_set_propv, user_creatable_add_dict,
user_creatable_complete, user_creatable_del
};
expression list args, args2;
typedef Error;
Error *err;
@@
- fun(args, &err, args2);
- if (err)
+ if (!fun(args, &err, args2))
{
...
}
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Line breaks tidied up manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-29-armbru@redhat.com>
2020-07-07 19:05:56 +03:00
|
|
|
if (!object_property_set_str(OBJECT(xendev), "drive",
|
|
|
|
xen_block_drive_get_node_name(drive),
|
2020-07-07 19:50:37 +03:00
|
|
|
errp)) {
|
|
|
|
error_prepend(errp, "failed to set 'drive': ");
|
2019-01-08 17:49:01 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
qom: Use returned bool to check for failure, Coccinelle part
The previous commit enables conversion of
foo(..., &err);
if (err) {
...
}
to
if (!foo(..., errp)) {
...
}
for QOM functions that now return true / false on success / error.
Coccinelle script:
@@
identifier fun = {
object_apply_global_props, object_initialize_child_with_props,
object_initialize_child_with_propsv, object_property_get,
object_property_get_bool, object_property_parse, object_property_set,
object_property_set_bool, object_property_set_int,
object_property_set_link, object_property_set_qobject,
object_property_set_str, object_property_set_uint, object_set_props,
object_set_propv, user_creatable_add_dict,
user_creatable_complete, user_creatable_del
};
expression list args, args2;
typedef Error;
Error *err;
@@
- fun(args, &err, args2);
- if (err)
+ if (!fun(args, &err, args2))
{
...
}
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Line breaks tidied up manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-29-armbru@redhat.com>
2020-07-07 19:05:56 +03:00
|
|
|
if (!object_property_set_str(OBJECT(xendev), "iothread", iothread->id,
|
2020-07-07 19:50:37 +03:00
|
|
|
errp)) {
|
|
|
|
error_prepend(errp, "failed to set 'iothread': ");
|
2019-01-08 17:49:01 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
blockdev->iothread = iothread;
|
|
|
|
blockdev->drive = drive;
|
|
|
|
|
2020-07-07 19:50:37 +03:00
|
|
|
if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
|
|
|
|
error_prepend(errp, "realization of device %s failed: ", type);
|
2019-01-08 17:49:01 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
xen_backend_set_device(backend, xendev);
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (xendev) {
|
|
|
|
object_unparent(OBJECT(xendev));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iothread) {
|
|
|
|
xen_block_iothread_destroy(iothread, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drive) {
|
|
|
|
xen_block_drive_destroy(drive, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_block_device_destroy(XenBackendInstance *backend,
|
|
|
|
Error **errp)
|
|
|
|
{
|
2020-07-07 19:50:37 +03:00
|
|
|
ERRP_GUARD();
|
2019-01-08 17:49:01 +03:00
|
|
|
XenDevice *xendev = xen_backend_get_device(backend);
|
|
|
|
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
|
|
|
XenBlockVdev *vdev = &blockdev->props.vdev;
|
|
|
|
XenBlockDrive *drive = blockdev->drive;
|
|
|
|
XenBlockIOThread *iothread = blockdev->iothread;
|
|
|
|
|
|
|
|
trace_xen_block_device_destroy(vdev->number);
|
|
|
|
|
|
|
|
object_unparent(OBJECT(xendev));
|
|
|
|
|
2021-03-08 17:32:32 +03:00
|
|
|
/*
|
|
|
|
* Drain all pending RCU callbacks as object_unparent() frees `xendev'
|
|
|
|
* in a RCU callback.
|
|
|
|
* And due to the property "drive" still existing in `xendev', we
|
|
|
|
* can't destroy the XenBlockDrive associated with `xendev' with
|
|
|
|
* xen_block_drive_destroy() below.
|
|
|
|
*/
|
|
|
|
drain_call_rcu();
|
|
|
|
|
2019-01-08 17:49:01 +03:00
|
|
|
if (iothread) {
|
2020-07-07 19:50:37 +03:00
|
|
|
xen_block_iothread_destroy(iothread, errp);
|
|
|
|
if (*errp) {
|
|
|
|
error_prepend(errp, "failed to destroy iothread: ");
|
2019-01-08 17:49:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drive) {
|
2020-07-07 19:50:37 +03:00
|
|
|
xen_block_drive_destroy(drive, errp);
|
|
|
|
if (*errp) {
|
|
|
|
error_prepend(errp, "failed to destroy drive: ");
|
2020-03-13 20:05:17 +03:00
|
|
|
return;
|
2019-01-08 17:49:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const XenBackendInfo xen_block_backend_info = {
|
|
|
|
.type = "qdisk",
|
|
|
|
.create = xen_block_device_create,
|
|
|
|
.destroy = xen_block_device_destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void xen_block_register_backend(void)
|
|
|
|
{
|
|
|
|
xen_backend_register(&xen_block_backend_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
xen_backend_init(xen_block_register_backend);
|