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.]
This commit is contained in:
parent
795d946d07
commit
1de7096d83
@ -723,8 +723,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
|
|||||||
unsigned int protocol,
|
unsigned int protocol,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenDevice *xendev = dataplane->xendev;
|
XenDevice *xendev = dataplane->xendev;
|
||||||
Error *local_err = NULL;
|
|
||||||
unsigned int ring_size;
|
unsigned int ring_size;
|
||||||
unsigned int i;
|
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,
|
xen_device_set_max_grant_refs(xendev, dataplane->nr_ring_ref,
|
||||||
&local_err);
|
errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto stop;
|
goto stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -770,9 +769,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
|
|||||||
dataplane->ring_ref,
|
dataplane->ring_ref,
|
||||||
dataplane->nr_ring_ref,
|
dataplane->nr_ring_ref,
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ | PROT_WRITE,
|
||||||
&local_err);
|
errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto stop;
|
goto stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -805,9 +803,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
|
|||||||
dataplane->event_channel =
|
dataplane->event_channel =
|
||||||
xen_device_bind_event_channel(xendev, event_channel,
|
xen_device_bind_event_channel(xendev, event_channel,
|
||||||
xen_block_dataplane_event, dataplane,
|
xen_block_dataplane_event, dataplane,
|
||||||
&local_err);
|
errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto stop;
|
goto stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +195,7 @@ static const BlockDevOps xen_block_dev_ops = {
|
|||||||
|
|
||||||
static void xen_block_realize(XenDevice *xendev, Error **errp)
|
static void xen_block_realize(XenDevice *xendev, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
||||||
XenBlockDeviceClass *blockdev_class =
|
XenBlockDeviceClass *blockdev_class =
|
||||||
XEN_BLOCK_DEVICE_GET_CLASS(xendev);
|
XEN_BLOCK_DEVICE_GET_CLASS(xendev);
|
||||||
@ -202,7 +203,6 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
|
|||||||
XenBlockVdev *vdev = &blockdev->props.vdev;
|
XenBlockVdev *vdev = &blockdev->props.vdev;
|
||||||
BlockConf *conf = &blockdev->props.conf;
|
BlockConf *conf = &blockdev->props.conf;
|
||||||
BlockBackend *blk = conf->blk;
|
BlockBackend *blk = conf->blk;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
if (vdev->type == XEN_BLOCK_VDEV_TYPE_INVALID) {
|
if (vdev->type == XEN_BLOCK_VDEV_TYPE_INVALID) {
|
||||||
error_setg(errp, "vdev property not set");
|
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);
|
trace_xen_block_realize(type, vdev->disk, vdev->partition);
|
||||||
|
|
||||||
if (blockdev_class->realize) {
|
if (blockdev_class->realize) {
|
||||||
blockdev_class->realize(blockdev, &local_err);
|
blockdev_class->realize(blockdev, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,8 +279,8 @@ static void xen_block_frontend_changed(XenDevice *xendev,
|
|||||||
enum xenbus_state frontend_state,
|
enum xenbus_state frontend_state,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
enum xenbus_state backend_state = xen_device_backend_get_state(xendev);
|
enum xenbus_state backend_state = xen_device_backend_get_state(xendev);
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
switch (frontend_state) {
|
switch (frontend_state) {
|
||||||
case XenbusStateInitialised:
|
case XenbusStateInitialised:
|
||||||
@ -290,15 +289,13 @@ static void xen_block_frontend_changed(XenDevice *xendev,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
xen_block_disconnect(xendev, &local_err);
|
xen_block_disconnect(xendev, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
xen_block_connect(xendev, &local_err);
|
xen_block_connect(xendev, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,9 +308,8 @@ static void xen_block_frontend_changed(XenDevice *xendev,
|
|||||||
|
|
||||||
case XenbusStateClosed:
|
case XenbusStateClosed:
|
||||||
case XenbusStateUnknown:
|
case XenbusStateUnknown:
|
||||||
xen_block_disconnect(xendev, &local_err);
|
xen_block_disconnect(xendev, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
break;
|
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,
|
static char *xen_block_blockdev_add(const char *id, QDict *qdict,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
const char *driver = qdict_get_try_str(qdict, "driver");
|
const char *driver = qdict_get_try_str(qdict, "driver");
|
||||||
BlockdevOptions *options = NULL;
|
BlockdevOptions *options = NULL;
|
||||||
Error *local_err = NULL;
|
|
||||||
char *node_name;
|
char *node_name;
|
||||||
Visitor *v;
|
Visitor *v;
|
||||||
|
|
||||||
@ -688,10 +684,9 @@ static char *xen_block_blockdev_add(const char *id, QDict *qdict,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
qmp_blockdev_add(options, &local_err);
|
qmp_blockdev_add(options, errp);
|
||||||
|
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -710,14 +705,12 @@ fail:
|
|||||||
|
|
||||||
static void xen_block_drive_destroy(XenBlockDrive *drive, Error **errp)
|
static void xen_block_drive_destroy(XenBlockDrive *drive, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
char *node_name = drive->node_name;
|
char *node_name = drive->node_name;
|
||||||
|
|
||||||
if (node_name) {
|
if (node_name) {
|
||||||
Error *local_err = NULL;
|
xen_block_blockdev_del(node_name, errp);
|
||||||
|
if (*errp) {
|
||||||
xen_block_blockdev_del(node_name, &local_err);
|
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g_free(node_name);
|
g_free(node_name);
|
||||||
@ -731,6 +724,7 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
|
|||||||
const char *device_type,
|
const char *device_type,
|
||||||
QDict *opts, Error **errp)
|
QDict *opts, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
const char *params = qdict_get_try_str(opts, "params");
|
const char *params = qdict_get_try_str(opts, "params");
|
||||||
const char *mode = qdict_get_try_str(opts, "mode");
|
const char *mode = qdict_get_try_str(opts, "mode");
|
||||||
const char *direct_io_safe = qdict_get_try_str(opts, "direct-io-safe");
|
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 *driver = NULL;
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
XenBlockDrive *drive = NULL;
|
XenBlockDrive *drive = NULL;
|
||||||
Error *local_err = NULL;
|
|
||||||
QDict *file_layer;
|
QDict *file_layer;
|
||||||
QDict *driver_layer;
|
QDict *driver_layer;
|
||||||
|
|
||||||
@ -817,13 +810,12 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
|
|||||||
|
|
||||||
g_assert(!drive->node_name);
|
g_assert(!drive->node_name);
|
||||||
drive->node_name = xen_block_blockdev_add(drive->id, driver_layer,
|
drive->node_name = xen_block_blockdev_add(drive->id, driver_layer,
|
||||||
&local_err);
|
errp);
|
||||||
|
|
||||||
qobject_unref(driver_layer);
|
qobject_unref(driver_layer);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
xen_block_drive_destroy(drive, NULL);
|
xen_block_drive_destroy(drive, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -848,8 +840,8 @@ static void xen_block_iothread_destroy(XenBlockIOThread *iothread,
|
|||||||
static XenBlockIOThread *xen_block_iothread_create(const char *id,
|
static XenBlockIOThread *xen_block_iothread_create(const char *id,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenBlockIOThread *iothread = g_new(XenBlockIOThread, 1);
|
XenBlockIOThread *iothread = g_new(XenBlockIOThread, 1);
|
||||||
Error *local_err = NULL;
|
|
||||||
QDict *opts;
|
QDict *opts;
|
||||||
QObject *ret_data = NULL;
|
QObject *ret_data = NULL;
|
||||||
|
|
||||||
@ -858,13 +850,11 @@ static XenBlockIOThread *xen_block_iothread_create(const char *id,
|
|||||||
opts = qdict_new();
|
opts = qdict_new();
|
||||||
qdict_put_str(opts, "qom-type", TYPE_IOTHREAD);
|
qdict_put_str(opts, "qom-type", TYPE_IOTHREAD);
|
||||||
qdict_put_str(opts, "id", id);
|
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(opts);
|
||||||
qobject_unref(ret_data);
|
qobject_unref(ret_data);
|
||||||
|
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
|
|
||||||
g_free(iothread->id);
|
g_free(iothread->id);
|
||||||
g_free(iothread);
|
g_free(iothread);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -876,6 +866,7 @@ static XenBlockIOThread *xen_block_iothread_create(const char *id,
|
|||||||
static void xen_block_device_create(XenBackendInstance *backend,
|
static void xen_block_device_create(XenBackendInstance *backend,
|
||||||
QDict *opts, Error **errp)
|
QDict *opts, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenBus *xenbus = xen_backend_get_bus(backend);
|
XenBus *xenbus = xen_backend_get_bus(backend);
|
||||||
const char *name = xen_backend_get_name(backend);
|
const char *name = xen_backend_get_name(backend);
|
||||||
unsigned long number;
|
unsigned long number;
|
||||||
@ -883,7 +874,6 @@ static void xen_block_device_create(XenBackendInstance *backend,
|
|||||||
XenBlockDrive *drive = NULL;
|
XenBlockDrive *drive = NULL;
|
||||||
XenBlockIOThread *iothread = NULL;
|
XenBlockIOThread *iothread = NULL;
|
||||||
XenDevice *xendev = NULL;
|
XenDevice *xendev = NULL;
|
||||||
Error *local_err = NULL;
|
|
||||||
const char *type;
|
const char *type;
|
||||||
XenBlockDevice *blockdev;
|
XenBlockDevice *blockdev;
|
||||||
|
|
||||||
@ -915,16 +905,15 @@ static void xen_block_device_create(XenBackendInstance *backend,
|
|||||||
goto fail;
|
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) {
|
if (!drive) {
|
||||||
error_propagate_prepend(errp, local_err, "failed to create drive: ");
|
error_prepend(errp, "failed to create drive: ");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
iothread = xen_block_iothread_create(vdev, &local_err);
|
iothread = xen_block_iothread_create(vdev, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to create iothread: ");
|
||||||
"failed to create iothread: ");
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -932,32 +921,29 @@ static void xen_block_device_create(XenBackendInstance *backend,
|
|||||||
blockdev = XEN_BLOCK_DEVICE(xendev);
|
blockdev = XEN_BLOCK_DEVICE(xendev);
|
||||||
|
|
||||||
if (!object_property_set_str(OBJECT(xendev), "vdev", vdev,
|
if (!object_property_set_str(OBJECT(xendev), "vdev", vdev,
|
||||||
&local_err)) {
|
errp)) {
|
||||||
error_propagate_prepend(errp, local_err, "failed to set 'vdev': ");
|
error_prepend(errp, "failed to set 'vdev': ");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!object_property_set_str(OBJECT(xendev), "drive",
|
if (!object_property_set_str(OBJECT(xendev), "drive",
|
||||||
xen_block_drive_get_node_name(drive),
|
xen_block_drive_get_node_name(drive),
|
||||||
&local_err)) {
|
errp)) {
|
||||||
error_propagate_prepend(errp, local_err, "failed to set 'drive': ");
|
error_prepend(errp, "failed to set 'drive': ");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!object_property_set_str(OBJECT(xendev), "iothread", iothread->id,
|
if (!object_property_set_str(OBJECT(xendev), "iothread", iothread->id,
|
||||||
&local_err)) {
|
errp)) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to set 'iothread': ");
|
||||||
"failed to set 'iothread': ");
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockdev->iothread = iothread;
|
blockdev->iothread = iothread;
|
||||||
blockdev->drive = drive;
|
blockdev->drive = drive;
|
||||||
|
|
||||||
if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), &local_err)) {
|
if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "realization of device %s failed: ", type);
|
||||||
"realization of device %s failed: ",
|
|
||||||
type);
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -981,31 +967,29 @@ fail:
|
|||||||
static void xen_block_device_destroy(XenBackendInstance *backend,
|
static void xen_block_device_destroy(XenBackendInstance *backend,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenDevice *xendev = xen_backend_get_device(backend);
|
XenDevice *xendev = xen_backend_get_device(backend);
|
||||||
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
|
||||||
XenBlockVdev *vdev = &blockdev->props.vdev;
|
XenBlockVdev *vdev = &blockdev->props.vdev;
|
||||||
XenBlockDrive *drive = blockdev->drive;
|
XenBlockDrive *drive = blockdev->drive;
|
||||||
XenBlockIOThread *iothread = blockdev->iothread;
|
XenBlockIOThread *iothread = blockdev->iothread;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
trace_xen_block_device_destroy(vdev->number);
|
trace_xen_block_device_destroy(vdev->number);
|
||||||
|
|
||||||
object_unparent(OBJECT(xendev));
|
object_unparent(OBJECT(xendev));
|
||||||
|
|
||||||
if (iothread) {
|
if (iothread) {
|
||||||
xen_block_iothread_destroy(iothread, &local_err);
|
xen_block_iothread_destroy(iothread, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to destroy iothread: ");
|
||||||
"failed to destroy iothread: ");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drive) {
|
if (drive) {
|
||||||
xen_block_drive_destroy(drive, &local_err);
|
xen_block_drive_destroy(drive, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to destroy drive: ");
|
||||||
"failed to destroy drive: ");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,17 +79,16 @@ static void host_pci_config_read(int pos, int len, uint32_t *val, Error **errp)
|
|||||||
|
|
||||||
static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp)
|
static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
uint32_t val = 0;
|
uint32_t val = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
int pos, len;
|
int pos, len;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(igd_host_bridge_infos); i++) {
|
for (i = 0; i < ARRAY_SIZE(igd_host_bridge_infos); i++) {
|
||||||
pos = igd_host_bridge_infos[i].offset;
|
pos = igd_host_bridge_infos[i].offset;
|
||||||
len = igd_host_bridge_infos[i].len;
|
len = igd_host_bridge_infos[i].len;
|
||||||
host_pci_config_read(pos, len, &val, &local_err);
|
host_pci_config_read(pos, len, &val, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pci_default_write_config(pci_dev, pos, val, len);
|
pci_default_write_config(pci_dev, pos, val, len);
|
||||||
|
@ -98,9 +98,9 @@ static void xen_backend_list_remove(XenBackendInstance *backend)
|
|||||||
void xen_backend_device_create(XenBus *xenbus, const char *type,
|
void xen_backend_device_create(XenBus *xenbus, const char *type,
|
||||||
const char *name, QDict *opts, Error **errp)
|
const char *name, QDict *opts, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
const XenBackendImpl *impl = xen_backend_table_lookup(type);
|
const XenBackendImpl *impl = xen_backend_table_lookup(type);
|
||||||
XenBackendInstance *backend;
|
XenBackendInstance *backend;
|
||||||
Error *local_error = NULL;
|
|
||||||
|
|
||||||
if (!impl) {
|
if (!impl) {
|
||||||
return;
|
return;
|
||||||
@ -110,9 +110,8 @@ void xen_backend_device_create(XenBus *xenbus, const char *type,
|
|||||||
backend->xenbus = xenbus;
|
backend->xenbus = xenbus;
|
||||||
backend->name = g_strdup(name);
|
backend->name = g_strdup(name);
|
||||||
|
|
||||||
impl->create(backend, opts, &local_error);
|
impl->create(backend, opts, errp);
|
||||||
if (local_error) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_error);
|
|
||||||
g_free(backend->name);
|
g_free(backend->name);
|
||||||
g_free(backend);
|
g_free(backend);
|
||||||
return;
|
return;
|
||||||
|
@ -53,9 +53,9 @@ static char *xen_device_get_frontend_path(XenDevice *xendev)
|
|||||||
|
|
||||||
static void xen_device_unplug(XenDevice *xendev, Error **errp)
|
static void xen_device_unplug(XenDevice *xendev, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
||||||
const char *type = object_get_typename(OBJECT(xendev));
|
const char *type = object_get_typename(OBJECT(xendev));
|
||||||
Error *local_err = NULL;
|
|
||||||
xs_transaction_t tid;
|
xs_transaction_t tid;
|
||||||
|
|
||||||
trace_xen_device_unplug(type, xendev->name);
|
trace_xen_device_unplug(type, xendev->name);
|
||||||
@ -69,14 +69,14 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "online",
|
xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "online",
|
||||||
&local_err, "%u", 0);
|
errp, "%u", 0);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "state",
|
xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "state",
|
||||||
&local_err, "%u", XenbusStateClosing);
|
errp, "%u", XenbusStateClosing);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,6 @@ abort:
|
|||||||
* from ending the transaction.
|
* from ending the transaction.
|
||||||
*/
|
*/
|
||||||
xs_transaction_end(xenbus->xsh, tid, true);
|
xs_transaction_end(xenbus->xsh, tid, true);
|
||||||
error_propagate(errp, local_err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xen_bus_print_dev(Monitor *mon, DeviceState *dev, int indent)
|
static void xen_bus_print_dev(Monitor *mon, DeviceState *dev, int indent)
|
||||||
@ -205,15 +204,13 @@ static XenWatch *watch_list_add(XenWatchList *watch_list, const char *node,
|
|||||||
const char *key, XenWatchHandler handler,
|
const char *key, XenWatchHandler handler,
|
||||||
void *opaque, Error **errp)
|
void *opaque, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenWatch *watch = new_watch(node, key, handler, opaque);
|
XenWatch *watch = new_watch(node, key, handler, opaque);
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
notifier_list_add(&watch_list->notifiers, &watch->notifier);
|
notifier_list_add(&watch_list->notifiers, &watch->notifier);
|
||||||
|
|
||||||
xs_node_watch(watch_list->xsh, node, key, watch->token, &local_err);
|
xs_node_watch(watch_list->xsh, node, key, watch->token, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
|
|
||||||
notifier_remove(&watch->notifier);
|
notifier_remove(&watch->notifier);
|
||||||
free_watch(watch);
|
free_watch(watch);
|
||||||
|
|
||||||
@ -255,11 +252,11 @@ static void xen_bus_backend_create(XenBus *xenbus, const char *type,
|
|||||||
const char *name, char *path,
|
const char *name, char *path,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
xs_transaction_t tid;
|
xs_transaction_t tid;
|
||||||
char **key;
|
char **key;
|
||||||
QDict *opts;
|
QDict *opts;
|
||||||
unsigned int i, n;
|
unsigned int i, n;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
trace_xen_bus_backend_create(type, path);
|
trace_xen_bus_backend_create(type, path);
|
||||||
|
|
||||||
@ -314,13 +311,11 @@ again:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xen_backend_device_create(xenbus, type, name, opts, &local_err);
|
xen_backend_device_create(xenbus, type, name, opts, errp);
|
||||||
qobject_unref(opts);
|
qobject_unref(opts);
|
||||||
|
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to create '%s' device '%s': ", type, name);
|
||||||
"failed to create '%s' device '%s': ",
|
|
||||||
type, name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -692,9 +687,9 @@ static void xen_device_remove_watch(XenDevice *xendev, XenWatch *watch,
|
|||||||
|
|
||||||
static void xen_device_backend_create(XenDevice *xendev, Error **errp)
|
static void xen_device_backend_create(XenDevice *xendev, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
||||||
struct xs_permissions perms[2];
|
struct xs_permissions perms[2];
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
xendev->backend_path = xen_device_get_backend_path(xendev);
|
xendev->backend_path = xen_device_get_backend_path(xendev);
|
||||||
|
|
||||||
@ -706,30 +701,27 @@ static void xen_device_backend_create(XenDevice *xendev, Error **errp)
|
|||||||
g_assert(xenbus->xsh);
|
g_assert(xenbus->xsh);
|
||||||
|
|
||||||
xs_node_create(xenbus->xsh, XBT_NULL, xendev->backend_path, perms,
|
xs_node_create(xenbus->xsh, XBT_NULL, xendev->backend_path, perms,
|
||||||
ARRAY_SIZE(perms), &local_err);
|
ARRAY_SIZE(perms), errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to create backend: ");
|
||||||
"failed to create backend: ");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xendev->backend_state_watch =
|
xendev->backend_state_watch =
|
||||||
xen_device_add_watch(xendev, xendev->backend_path,
|
xen_device_add_watch(xendev, xendev->backend_path,
|
||||||
"state", xen_device_backend_changed,
|
"state", xen_device_backend_changed,
|
||||||
&local_err);
|
errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to watch backend state: ");
|
||||||
"failed to watch backend state: ");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xendev->backend_online_watch =
|
xendev->backend_online_watch =
|
||||||
xen_device_add_watch(xendev, xendev->backend_path,
|
xen_device_add_watch(xendev, xendev->backend_path,
|
||||||
"online", xen_device_backend_changed,
|
"online", xen_device_backend_changed,
|
||||||
&local_err);
|
errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to watch backend online: ");
|
||||||
"failed to watch backend online: ");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -866,9 +858,9 @@ static bool xen_device_frontend_exists(XenDevice *xendev)
|
|||||||
|
|
||||||
static void xen_device_frontend_create(XenDevice *xendev, Error **errp)
|
static void xen_device_frontend_create(XenDevice *xendev, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
||||||
struct xs_permissions perms[2];
|
struct xs_permissions perms[2];
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
xendev->frontend_path = xen_device_get_frontend_path(xendev);
|
xendev->frontend_path = xen_device_get_frontend_path(xendev);
|
||||||
|
|
||||||
@ -885,20 +877,18 @@ static void xen_device_frontend_create(XenDevice *xendev, Error **errp)
|
|||||||
g_assert(xenbus->xsh);
|
g_assert(xenbus->xsh);
|
||||||
|
|
||||||
xs_node_create(xenbus->xsh, XBT_NULL, xendev->frontend_path, perms,
|
xs_node_create(xenbus->xsh, XBT_NULL, xendev->frontend_path, perms,
|
||||||
ARRAY_SIZE(perms), &local_err);
|
ARRAY_SIZE(perms), errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to create frontend: ");
|
||||||
"failed to create frontend: ");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xendev->frontend_state_watch =
|
xendev->frontend_state_watch =
|
||||||
xen_device_add_watch(xendev, xendev->frontend_path, "state",
|
xen_device_add_watch(xendev, xendev->frontend_path, "state",
|
||||||
xen_device_frontend_changed, &local_err);
|
xen_device_frontend_changed, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to watch frontend state: ");
|
||||||
"failed to watch frontend state: ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1247,11 +1237,11 @@ static void xen_device_exit(Notifier *n, void *data)
|
|||||||
|
|
||||||
static void xen_device_realize(DeviceState *dev, Error **errp)
|
static void xen_device_realize(DeviceState *dev, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenDevice *xendev = XEN_DEVICE(dev);
|
XenDevice *xendev = XEN_DEVICE(dev);
|
||||||
XenDeviceClass *xendev_class = XEN_DEVICE_GET_CLASS(xendev);
|
XenDeviceClass *xendev_class = XEN_DEVICE_GET_CLASS(xendev);
|
||||||
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
||||||
const char *type = object_get_typename(OBJECT(xendev));
|
const char *type = object_get_typename(OBJECT(xendev));
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
if (xendev->frontend_id == DOMID_INVALID) {
|
if (xendev->frontend_id == DOMID_INVALID) {
|
||||||
xendev->frontend_id = xen_domid;
|
xendev->frontend_id = xen_domid;
|
||||||
@ -1267,10 +1257,9 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
|
|||||||
goto unrealize;
|
goto unrealize;
|
||||||
}
|
}
|
||||||
|
|
||||||
xendev->name = xendev_class->get_name(xendev, &local_err);
|
xendev->name = xendev_class->get_name(xendev, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate_prepend(errp, local_err,
|
error_prepend(errp, "failed to get device name: ");
|
||||||
"failed to get device name: ");
|
|
||||||
goto unrealize;
|
goto unrealize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1293,22 +1282,19 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
|
|||||||
xendev->feature_grant_copy =
|
xendev->feature_grant_copy =
|
||||||
(xengnttab_grant_copy(xendev->xgth, 0, NULL) == 0);
|
(xengnttab_grant_copy(xendev->xgth, 0, NULL) == 0);
|
||||||
|
|
||||||
xen_device_backend_create(xendev, &local_err);
|
xen_device_backend_create(xendev, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto unrealize;
|
goto unrealize;
|
||||||
}
|
}
|
||||||
|
|
||||||
xen_device_frontend_create(xendev, &local_err);
|
xen_device_frontend_create(xendev, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto unrealize;
|
goto unrealize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xendev_class->realize) {
|
if (xendev_class->realize) {
|
||||||
xendev_class->realize(xendev, &local_err);
|
xendev_class->realize(xendev, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto unrealize;
|
goto unrealize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,8 +333,8 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
|
|||||||
uint8_t bus, uint8_t dev, uint8_t func,
|
uint8_t bus, uint8_t dev, uint8_t func,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
unsigned int v;
|
unsigned int v;
|
||||||
Error *err = NULL;
|
|
||||||
|
|
||||||
d->config_fd = -1;
|
d->config_fd = -1;
|
||||||
d->domain = domain;
|
d->domain = domain;
|
||||||
@ -342,36 +342,36 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
|
|||||||
d->dev = dev;
|
d->dev = dev;
|
||||||
d->func = func;
|
d->func = func;
|
||||||
|
|
||||||
xen_host_pci_config_open(d, &err);
|
xen_host_pci_config_open(d, errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
xen_host_pci_get_resource(d, &err);
|
xen_host_pci_get_resource(d, errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
xen_host_pci_get_hex_value(d, "vendor", &v, &err);
|
xen_host_pci_get_hex_value(d, "vendor", &v, errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
d->vendor_id = v;
|
d->vendor_id = v;
|
||||||
|
|
||||||
xen_host_pci_get_hex_value(d, "device", &v, &err);
|
xen_host_pci_get_hex_value(d, "device", &v, errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
d->device_id = v;
|
d->device_id = v;
|
||||||
|
|
||||||
xen_host_pci_get_dec_value(d, "irq", &v, &err);
|
xen_host_pci_get_dec_value(d, "irq", &v, errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
d->irq = v;
|
d->irq = v;
|
||||||
|
|
||||||
xen_host_pci_get_hex_value(d, "class", &v, &err);
|
xen_host_pci_get_hex_value(d, "class", &v, errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
d->class_code = v;
|
d->class_code = v;
|
||||||
@ -381,7 +381,6 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
error_propagate(errp, err);
|
|
||||||
|
|
||||||
if (d->config_fd >= 0) {
|
if (d->config_fd >= 0) {
|
||||||
close(d->config_fd);
|
close(d->config_fd);
|
||||||
|
@ -777,12 +777,12 @@ static void xen_pt_destroy(PCIDevice *d) {
|
|||||||
|
|
||||||
static void xen_pt_realize(PCIDevice *d, Error **errp)
|
static void xen_pt_realize(PCIDevice *d, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
XenPCIPassthroughState *s = XEN_PT_DEVICE(d);
|
XenPCIPassthroughState *s = XEN_PT_DEVICE(d);
|
||||||
int i, rc = 0;
|
int i, rc = 0;
|
||||||
uint8_t machine_irq = 0, scratch;
|
uint8_t machine_irq = 0, scratch;
|
||||||
uint16_t cmd = 0;
|
uint16_t cmd = 0;
|
||||||
int pirq = XEN_PT_UNASSIGNED_PIRQ;
|
int pirq = XEN_PT_UNASSIGNED_PIRQ;
|
||||||
Error *err = NULL;
|
|
||||||
|
|
||||||
/* register real device */
|
/* register real device */
|
||||||
XEN_PT_LOG(d, "Assigning real physical device %02x:%02x.%d"
|
XEN_PT_LOG(d, "Assigning real physical device %02x:%02x.%d"
|
||||||
@ -793,10 +793,9 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
|
|||||||
xen_host_pci_device_get(&s->real_device,
|
xen_host_pci_device_get(&s->real_device,
|
||||||
s->hostaddr.domain, s->hostaddr.bus,
|
s->hostaddr.domain, s->hostaddr.bus,
|
||||||
s->hostaddr.slot, s->hostaddr.function,
|
s->hostaddr.slot, s->hostaddr.function,
|
||||||
&err);
|
errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
error_append_hint(&err, "Failed to \"open\" the real pci device");
|
error_append_hint(errp, "Failed to \"open\" the real pci device");
|
||||||
error_propagate(errp, err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -823,11 +822,10 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xen_pt_setup_vga(s, &s->real_device, &err);
|
xen_pt_setup_vga(s, &s->real_device, errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
error_append_hint(&err, "Setup VGA BIOS of passthrough"
|
error_append_hint(errp, "Setup VGA BIOS of passthrough"
|
||||||
" GFX failed");
|
" GFX failed");
|
||||||
error_propagate(errp, err);
|
|
||||||
xen_host_pci_device_put(&s->real_device);
|
xen_host_pci_device_put(&s->real_device);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -840,10 +838,9 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
|
|||||||
xen_pt_register_regions(s, &cmd);
|
xen_pt_register_regions(s, &cmd);
|
||||||
|
|
||||||
/* reinitialize each config register to be emulated */
|
/* reinitialize each config register to be emulated */
|
||||||
xen_pt_config_init(s, &err);
|
xen_pt_config_init(s, errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
error_append_hint(&err, "PCI Config space initialisation failed");
|
error_append_hint(errp, "PCI Config space initialisation failed");
|
||||||
error_propagate(errp, err);
|
|
||||||
rc = -1;
|
rc = -1;
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
@ -2008,8 +2008,8 @@ static void xen_pt_config_reg_init(XenPCIPassthroughState *s,
|
|||||||
|
|
||||||
void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp)
|
void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
int i, rc;
|
int i, rc;
|
||||||
Error *err = NULL;
|
|
||||||
|
|
||||||
QLIST_INIT(&s->reg_grps);
|
QLIST_INIT(&s->reg_grps);
|
||||||
|
|
||||||
@ -2067,13 +2067,14 @@ void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp)
|
|||||||
|
|
||||||
/* initialize capability register */
|
/* initialize capability register */
|
||||||
for (j = 0; regs->size != 0; j++, regs++) {
|
for (j = 0; regs->size != 0; j++, regs++) {
|
||||||
xen_pt_config_reg_init(s, reg_grp_entry, regs, &err);
|
xen_pt_config_reg_init(s, reg_grp_entry, regs, errp);
|
||||||
if (err) {
|
if (*errp) {
|
||||||
error_append_hint(&err, "Failed to init register %d"
|
error_append_hint(errp, "Failed to init register %d"
|
||||||
" offsets 0x%x in grp_type = 0x%x (%d/%zu)", j,
|
" offsets 0x%x in grp_type = 0x%x (%d/%zu)",
|
||||||
regs->offset, xen_pt_emu_reg_grps[i].grp_type,
|
j,
|
||||||
|
regs->offset,
|
||||||
|
xen_pt_emu_reg_grps[i].grp_type,
|
||||||
i, ARRAY_SIZE(xen_pt_emu_reg_grps));
|
i, ARRAY_SIZE(xen_pt_emu_reg_grps));
|
||||||
error_propagate(errp, err);
|
|
||||||
xen_pt_config_delete(s);
|
xen_pt_config_delete(s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user