aboutsummaryrefslogtreecommitdiff
path: root/hw/block
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>2020-07-07 18:50:37 +0200
committerMarkus Armbruster <armbru@redhat.com>2020-07-10 15:18:09 +0200
commit1de7096d8378a57e2d75d9cacc9a119e7e41640d (patch)
treeb7582f17ac7fb572a23b02bfdac638d19d780d48 /hw/block
parent795d946d0797e7ba28ed97c86e2592e346b02b0e (diff)
xen: Use ERRP_GUARD()
If we want to check error after errp-function call, we need to introduce local_err and then propagate it to errp. Instead, use the ERRP_GUARD() macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_GUARD() leaves errp as is if it's not NULL or &error_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_GUARD() macro. Otherwise, this info will not be added when errp == &error_fatal (the program will exit prior to the error_append_hint() or error_prepend() call). No such cases are being fixed here. This commit is generated by command sed -n '/^X86 Xen CPUs$/,/^$/{s/^F: //p}' MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/errp-guard.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf <kwolf@redhat.com> Reported-by: Greg Kurz <groug@kaod.org> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> [Commit message tweaked] Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20200707165037.1026246-9-armbru@redhat.com> [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and auto-propagated-errp.cocci to errp-guard.cocci. Commit message tweaked again.]
Diffstat (limited to 'hw/block')
-rw-r--r--hw/block/dataplane/xen-block.c17
-rw-r--r--hw/block/xen-block.c102
2 files changed, 50 insertions, 69 deletions
diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c
index 5f8f15778b..71c337c7b7 100644
--- a/hw/block/dataplane/xen-block.c
+++ b/hw/block/dataplane/xen-block.c
@@ -723,8 +723,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
unsigned int protocol,
Error **errp)
{
+ ERRP_GUARD();
XenDevice *xendev = dataplane->xendev;
- Error *local_err = NULL;
unsigned int ring_size;
unsigned int i;
@@ -760,9 +760,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
}
xen_device_set_max_grant_refs(xendev, dataplane->nr_ring_ref,
- &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ errp);
+ if (*errp) {
goto stop;
}
@@ -770,9 +769,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
dataplane->ring_ref,
dataplane->nr_ring_ref,
PROT_READ | PROT_WRITE,
- &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ errp);
+ if (*errp) {
goto stop;
}
@@ -805,9 +803,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
dataplane->event_channel =
xen_device_bind_event_channel(xendev, event_channel,
xen_block_dataplane_event, dataplane,
- &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ errp);
+ if (*errp) {
goto stop;
}
diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index a775fba7c0..8a7a3f5452 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -195,6 +195,7 @@ static const BlockDevOps xen_block_dev_ops = {
static void xen_block_realize(XenDevice *xendev, Error **errp)
{
+ ERRP_GUARD();
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
XenBlockDeviceClass *blockdev_class =
XEN_BLOCK_DEVICE_GET_CLASS(xendev);
@@ -202,7 +203,6 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
XenBlockVdev *vdev = &blockdev->props.vdev;
BlockConf *conf = &blockdev->props.conf;
BlockBackend *blk = conf->blk;
- Error *local_err = NULL;
if (vdev->type == XEN_BLOCK_VDEV_TYPE_INVALID) {
error_setg(errp, "vdev property not set");
@@ -212,9 +212,8 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
trace_xen_block_realize(type, vdev->disk, vdev->partition);
if (blockdev_class->realize) {
- blockdev_class->realize(blockdev, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ blockdev_class->realize(blockdev, errp);
+ if (*errp) {
return;
}
}
@@ -280,8 +279,8 @@ static void xen_block_frontend_changed(XenDevice *xendev,
enum xenbus_state frontend_state,
Error **errp)
{
+ ERRP_GUARD();
enum xenbus_state backend_state = xen_device_backend_get_state(xendev);
- Error *local_err = NULL;
switch (frontend_state) {
case XenbusStateInitialised:
@@ -290,15 +289,13 @@ static void xen_block_frontend_changed(XenDevice *xendev,
break;
}
- xen_block_disconnect(xendev, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ xen_block_disconnect(xendev, errp);
+ if (*errp) {
break;
}
- xen_block_connect(xendev, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ xen_block_connect(xendev, errp);
+ if (*errp) {
break;
}
@@ -311,9 +308,8 @@ static void xen_block_frontend_changed(XenDevice *xendev,
case XenbusStateClosed:
case XenbusStateUnknown:
- xen_block_disconnect(xendev, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ xen_block_disconnect(xendev, errp);
+ if (*errp) {
break;
}
@@ -665,9 +661,9 @@ static void xen_block_blockdev_del(const char *node_name, Error **errp)
static char *xen_block_blockdev_add(const char *id, QDict *qdict,
Error **errp)
{
+ ERRP_GUARD();
const char *driver = qdict_get_try_str(qdict, "driver");
BlockdevOptions *options = NULL;
- Error *local_err = NULL;
char *node_name;
Visitor *v;
@@ -688,10 +684,9 @@ static char *xen_block_blockdev_add(const char *id, QDict *qdict,
goto fail;
}
- qmp_blockdev_add(options, &local_err);
+ qmp_blockdev_add(options, errp);
- if (local_err) {
- error_propagate(errp, local_err);
+ if (*errp) {
goto fail;
}
@@ -710,14 +705,12 @@ fail:
static void xen_block_drive_destroy(XenBlockDrive *drive, Error **errp)
{
+ ERRP_GUARD();
char *node_name = drive->node_name;
if (node_name) {
- Error *local_err = NULL;
-
- xen_block_blockdev_del(node_name, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ xen_block_blockdev_del(node_name, errp);
+ if (*errp) {
return;
}
g_free(node_name);
@@ -731,6 +724,7 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
const char *device_type,
QDict *opts, Error **errp)
{
+ ERRP_GUARD();
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");
@@ -738,7 +732,6 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
char *driver = NULL;
char *filename = NULL;
XenBlockDrive *drive = NULL;
- Error *local_err = NULL;
QDict *file_layer;
QDict *driver_layer;
@@ -817,13 +810,12 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
g_assert(!drive->node_name);
drive->node_name = xen_block_blockdev_add(drive->id, driver_layer,
- &local_err);
+ errp);
qobject_unref(driver_layer);
done:
- if (local_err) {
- error_propagate(errp, local_err);
+ if (*errp) {
xen_block_drive_destroy(drive, NULL);
return NULL;
}
@@ -848,8 +840,8 @@ static void xen_block_iothread_destroy(XenBlockIOThread *iothread,
static XenBlockIOThread *xen_block_iothread_create(const char *id,
Error **errp)
{
+ ERRP_GUARD();
XenBlockIOThread *iothread = g_new(XenBlockIOThread, 1);
- Error *local_err = NULL;
QDict *opts;
QObject *ret_data = NULL;
@@ -858,13 +850,11 @@ static XenBlockIOThread *xen_block_iothread_create(const char *id,
opts = qdict_new();
qdict_put_str(opts, "qom-type", TYPE_IOTHREAD);
qdict_put_str(opts, "id", id);
- qmp_object_add(opts, &ret_data, &local_err);
+ qmp_object_add(opts, &ret_data, errp);
qobject_unref(opts);
qobject_unref(ret_data);
- if (local_err) {
- error_propagate(errp, local_err);
-
+ if (*errp) {
g_free(iothread->id);
g_free(iothread);
return NULL;
@@ -876,6 +866,7 @@ static XenBlockIOThread *xen_block_iothread_create(const char *id,
static void xen_block_device_create(XenBackendInstance *backend,
QDict *opts, Error **errp)
{
+ ERRP_GUARD();
XenBus *xenbus = xen_backend_get_bus(backend);
const char *name = xen_backend_get_name(backend);
unsigned long number;
@@ -883,7 +874,6 @@ static void xen_block_device_create(XenBackendInstance *backend,
XenBlockDrive *drive = NULL;
XenBlockIOThread *iothread = NULL;
XenDevice *xendev = NULL;
- Error *local_err = NULL;
const char *type;
XenBlockDevice *blockdev;
@@ -915,16 +905,15 @@ static void xen_block_device_create(XenBackendInstance *backend,
goto fail;
}
- drive = xen_block_drive_create(vdev, device_type, opts, &local_err);
+ drive = xen_block_drive_create(vdev, device_type, opts, errp);
if (!drive) {
- error_propagate_prepend(errp, local_err, "failed to create drive: ");
+ error_prepend(errp, "failed to create drive: ");
goto fail;
}
- iothread = xen_block_iothread_create(vdev, &local_err);
- if (local_err) {
- error_propagate_prepend(errp, local_err,
- "failed to create iothread: ");
+ iothread = xen_block_iothread_create(vdev, errp);
+ if (*errp) {
+ error_prepend(errp, "failed to create iothread: ");
goto fail;
}
@@ -932,32 +921,29 @@ static void xen_block_device_create(XenBackendInstance *backend,
blockdev = XEN_BLOCK_DEVICE(xendev);
if (!object_property_set_str(OBJECT(xendev), "vdev", vdev,
- &local_err)) {
- error_propagate_prepend(errp, local_err, "failed to set 'vdev': ");
+ errp)) {
+ error_prepend(errp, "failed to set 'vdev': ");
goto fail;
}
if (!object_property_set_str(OBJECT(xendev), "drive",
xen_block_drive_get_node_name(drive),
- &local_err)) {
- error_propagate_prepend(errp, local_err, "failed to set 'drive': ");
+ errp)) {
+ error_prepend(errp, "failed to set 'drive': ");
goto fail;
}
if (!object_property_set_str(OBJECT(xendev), "iothread", iothread->id,
- &local_err)) {
- error_propagate_prepend(errp, local_err,
- "failed to set 'iothread': ");
+ errp)) {
+ error_prepend(errp, "failed to set 'iothread': ");
goto fail;
}
blockdev->iothread = iothread;
blockdev->drive = drive;
- if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), &local_err)) {
- error_propagate_prepend(errp, local_err,
- "realization of device %s failed: ",
- type);
+ if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
+ error_prepend(errp, "realization of device %s failed: ", type);
goto fail;
}
@@ -981,31 +967,29 @@ fail:
static void xen_block_device_destroy(XenBackendInstance *backend,
Error **errp)
{
+ ERRP_GUARD();
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;
- Error *local_err = NULL;
trace_xen_block_device_destroy(vdev->number);
object_unparent(OBJECT(xendev));
if (iothread) {
- xen_block_iothread_destroy(iothread, &local_err);
- if (local_err) {
- error_propagate_prepend(errp, local_err,
- "failed to destroy iothread: ");
+ xen_block_iothread_destroy(iothread, errp);
+ if (*errp) {
+ error_prepend(errp, "failed to destroy iothread: ");
return;
}
}
if (drive) {
- xen_block_drive_destroy(drive, &local_err);
- if (local_err) {
- error_propagate_prepend(errp, local_err,
- "failed to destroy drive: ");
+ xen_block_drive_destroy(drive, errp);
+ if (*errp) {
+ error_prepend(errp, "failed to destroy drive: ");
return;
}
}