From 85786e0c5ed7eb2f9518c9ad02b9675e12c068f8 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Thu, 30 Jun 2016 01:08:27 +0200 Subject: [PATCH 01/16] Fix crash with __com.redhat_drive_del RH-Author: Fam Zheng Message-id: <20160630010827.10074-1-famz@redhat.com> Patchwork-id: 70829 O-Subject: [RHEL-7.3 qemu-kvm-rhev PATCH v2] Fix crash with __com.redhat_drive_del Bugzilla: 1341531 RH-Acked-by: Miroslav Rezanina RH-Acked-by: Laurent Vivier RH-Acked-by: Markus Armbruster BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1341531 Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=11289585 Upstream: N/A. __com.redhat_drive_del is a downstream only command. hmp_drive_del is not a function for QMP, it has the wrong signature. handle_qmp_command calls it by mistake because 'cmd_new' and 'cmd' are in a union. Signed-off-by: Fam Zheng Signed-off-by: Miroslav Rezanina --- blockdev.c | 27 ++++++++++++++++----------- include/sysemu/blockdev.h | 1 + qmp-commands.hx | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/blockdev.c b/blockdev.c index 46fe7b4..1b987f8 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2880,32 +2880,28 @@ void qmp_block_dirty_bitmap_clear(const char *node, const char *name, aio_context_release(aio_context); } -void hmp_drive_del(Monitor *mon, const QDict *qdict) +void qmp_drive_del(QDict *qdict, QObject **ret_data, Error **errp) { const char *id = qdict_get_str(qdict, "id"); BlockBackend *blk; BlockDriverState *bs; AioContext *aio_context; - Error *local_err = NULL; bs = bdrv_find_node(id); if (bs) { - qmp_x_blockdev_del(false, NULL, true, id, &local_err); - if (local_err) { - error_report_err(local_err); - } + qmp_x_blockdev_del(false, NULL, true, id, errp); return; } blk = blk_by_name(id); if (!blk) { - error_report("Device '%s' not found", id); + error_setg(errp, "Device '%s' not found", id); return; } if (!blk_legacy_dinfo(blk)) { - error_report("Deleting device added with blockdev-add" - " is not supported"); + error_setg(errp, "Deleting device added with blockdev-add" + " is not supported"); return; } @@ -2914,8 +2910,7 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict) bs = blk_bs(blk); if (bs) { - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) { - error_report_err(local_err); + if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, errp)) { aio_context_release(aio_context); return; } @@ -2940,6 +2935,16 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict) aio_context_release(aio_context); } +void hmp_drive_del(Monitor *mon, const QDict *qdict) +{ + Error *local_err = NULL; + + qmp_drive_del((QDict *)qdict, NULL, &local_err); + if (local_err) { + error_report_err(local_err); + } +} + void qmp_block_resize(bool has_device, const char *device, bool has_node_name, const char *node_name, int64_t size, Error **errp) diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index 9c60321..977ffe2 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -64,6 +64,7 @@ DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type); void hmp_commit(Monitor *mon, const QDict *qdict); void hmp_drive_del(Monitor *mon, const QDict *qdict); +void qmp_drive_del(QDict *qdict, QObject **ret_data, Error **errp); void simple_drive_add(QDict *qdict, QObject **ret_data, Error **errp); #endif diff --git a/qmp-commands.hx b/qmp-commands.hx index 87468f9..bd47bf0 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -157,7 +157,7 @@ EQMP .args_type = "id:s", .params = "device", .help = "remove host block device", - .mhandler.cmd = hmp_drive_del, + .mhandler.cmd_new = qmp_drive_del, }, SQMP -- 1.8.3.1