diff options
176 files changed, 953 insertions, 1102 deletions
diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c index 5c6f726757..42ae4a45f7 100644 --- a/audio/spiceaudio.c +++ b/audio/spiceaudio.c @@ -18,6 +18,7 @@ */ #include "hw/hw.h" +#include "qemu/error-report.h" #include "qemu/timer.h" #include "ui/qemu-spice.h" diff --git a/audio/wavcapture.c b/audio/wavcapture.c index 6f6d792691..86e905627a 100644 --- a/audio/wavcapture.c +++ b/audio/wavcapture.c @@ -1,5 +1,6 @@ #include "hw/hw.h" #include "monitor/monitor.h" +#include "qemu/error-report.h" #include "audio.h" typedef struct { diff --git a/backends/hostmem.c b/backends/hostmem.c index 7d74be04c3..61c1ac0843 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -13,7 +13,6 @@ #include "qapi/visitor.h" #include "qapi-types.h" #include "qapi-visit.h" -#include "qapi/qmp/qerror.h" #include "qemu/config-file.h" #include "qom/object_interfaces.h" diff --git a/backends/rng-egd.c b/backends/rng-egd.c index 2962795a8f..6c13409632 100644 --- a/backends/rng-egd.c +++ b/backends/rng-egd.c @@ -140,19 +140,20 @@ static void rng_egd_opened(RngBackend *b, Error **errp) RngEgd *s = RNG_EGD(b); if (s->chr_name == NULL) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, - "chardev", "a valid character device"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "chardev", "a valid character device"); return; } s->chr = qemu_chr_find(s->chr_name); if (s->chr == NULL) { - error_set(errp, QERR_DEVICE_NOT_FOUND, s->chr_name); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", s->chr_name); return; } if (qemu_chr_fe_claim(s->chr) != 0) { - error_set(errp, QERR_DEVICE_IN_USE, s->chr_name); + error_setg(errp, QERR_DEVICE_IN_USE, s->chr_name); return; } @@ -167,7 +168,7 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp) RngEgd *s = RNG_EGD(b); if (b->opened) { - error_set(errp, QERR_PERMISSION_DENIED); + error_setg(errp, QERR_PERMISSION_DENIED); } else { g_free(s->chr_name); s->chr_name = g_strdup(value); diff --git a/backends/rng-random.c b/backends/rng-random.c index 4f85a8ea49..4e51f4609b 100644 --- a/backends/rng-random.c +++ b/backends/rng-random.c @@ -74,8 +74,8 @@ static void rng_random_opened(RngBackend *b, Error **errp) RndRandom *s = RNG_RANDOM(b); if (s->filename == NULL) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, - "filename", "a valid filename"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "filename", "a valid filename"); } else { s->fd = qemu_open(s->filename, O_RDONLY | O_NONBLOCK); if (s->fd == -1) { @@ -98,7 +98,7 @@ static void rng_random_set_filename(Object *obj, const char *filename, RndRandom *s = RNG_RANDOM(obj); if (b->opened) { - error_set(errp, QERR_PERMISSION_DENIED); + error_setg(errp, QERR_PERMISSION_DENIED); return; } diff --git a/backends/rng.c b/backends/rng.c index 0f2fc11dd8..5065fdc155 100644 --- a/backends/rng.c +++ b/backends/rng.c @@ -57,7 +57,7 @@ static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp) } if (!value && s->opened) { - error_set(errp, QERR_PERMISSION_DENIED); + error_setg(errp, QERR_PERMISSION_DENIED); return; } diff --git a/backends/tpm.c b/backends/tpm.c index f3ab3b30bd..a512693b15 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -133,7 +133,7 @@ static void tpm_backend_prop_set_opened(Object *obj, bool value, Error **errp) } if (!value && s->opened) { - error_set(errp, QERR_PERMISSION_DENIED); + error_setg(errp, QERR_PERMISSION_DENIED); return; } @@ -24,12 +24,13 @@ * THE SOFTWARE. */ -#include "monitor/monitor.h" +#include "qemu-common.h" #include "exec/cpu-common.h" #include "sysemu/kvm.h" #include "sysemu/balloon.h" #include "trace.h" #include "qmp-commands.h" +#include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" static QEMUBalloonEvent *balloon_event_fn; @@ -96,7 +97,7 @@ void qmp_balloon(int64_t target, Error **errp) } if (target <= 0) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "target", "a size"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "target", "a size"); return; } @@ -26,7 +26,9 @@ #include "trace.h" #include "block/block_int.h" #include "block/blockjob.h" +#include "qemu/error-report.h" #include "qemu/module.h" +#include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" #include "sysemu/block-backend.h" #include "sysemu/sysemu.h" @@ -2698,7 +2700,7 @@ void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) error_setg(errp, "Node '%s' is not encrypted", bdrv_get_device_or_node_name(bs)); } else if (bdrv_set_key(bs, key) < 0) { - error_set(errp, QERR_INVALID_PASSWORD); + error_setg(errp, QERR_INVALID_PASSWORD); } } else { if (bdrv_key_required(bs)) { diff --git a/block/backup.c b/block/backup.c index d3f648ddd7..4a1af68c32 100644 --- a/block/backup.c +++ b/block/backup.c @@ -19,6 +19,7 @@ #include "block/block.h" #include "block/block_int.h" #include "block/blockjob.h" +#include "qapi/qmp/qerror.h" #include "qemu/ratelimit.h" #define BACKUP_CLUSTER_BITS 16 @@ -197,7 +198,7 @@ static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp) BackupBlockJob *s = container_of(job, BackupBlockJob, common); if (speed < 0) { - error_set(errp, QERR_INVALID_PARAMETER, "speed"); + error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); @@ -472,7 +473,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target, if ((on_source_error == BLOCKDEV_ON_ERROR_STOP || on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) && !bdrv_iostatus_is_enabled(bs)) { - error_set(errp, QERR_INVALID_PARAMETER, "on-source-error"); + error_setg(errp, QERR_INVALID_PARAMETER, "on-source-error"); return; } diff --git a/block/commit.c b/block/commit.c index cfa2bbebc2..7312a5bdc0 100644 --- a/block/commit.c +++ b/block/commit.c @@ -15,6 +15,7 @@ #include "trace.h" #include "block/block_int.h" #include "block/blockjob.h" +#include "qapi/qmp/qerror.h" #include "qemu/ratelimit.h" enum { @@ -186,7 +187,7 @@ static void commit_set_speed(BlockJob *job, int64_t speed, Error **errp) CommitBlockJob *s = container_of(job, CommitBlockJob, common); if (speed < 0) { - error_set(errp, QERR_INVALID_PARAMETER, "speed"); + error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); diff --git a/block/curl.c b/block/curl.c index bbee3ca179..3a2b63e16e 100644 --- a/block/curl.c +++ b/block/curl.c @@ -24,6 +24,7 @@ #include "qemu-common.h" #include "block/block_int.h" #include "qapi/qmp/qbool.h" +#include "qapi/qmp/qstring.h" #include <curl/curl.h> // #define DEBUG_CURL diff --git a/block/dmg.c b/block/dmg.c index 825c49d59a..9f2528169c 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -24,6 +24,7 @@ #include "qemu-common.h" #include "block/block_int.h" #include "qemu/bswap.h" +#include "qemu/error-report.h" #include "qemu/module.h" #include <zlib.h> #ifdef CONFIG_BZIP2 diff --git a/block/io.c b/block/io.c index bb4f78784e..9cc729be7e 100644 --- a/block/io.c +++ b/block/io.c @@ -26,6 +26,7 @@ #include "block/blockjob.h" #include "block/block_int.h" #include "block/throttle-groups.h" +#include "qemu/error-report.h" #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */ diff --git a/block/iscsi.c b/block/iscsi.c index 14e97a6b48..5f7b60c99b 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -38,6 +38,7 @@ #include "qemu/iov.h" #include "sysemu/sysemu.h" #include "qmp-commands.h" +#include "qapi/qmp/qstring.h" #include <iscsi/iscsi.h> #include <iscsi/scsi-lowlevel.h> diff --git a/block/mirror.c b/block/mirror.c index 58f391a6d6..048e452d17 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -14,6 +14,7 @@ #include "trace.h" #include "block/blockjob.h" #include "block/block_int.h" +#include "qapi/qmp/qerror.h" #include "qemu/ratelimit.h" #include "qemu/bitmap.h" @@ -573,7 +574,7 @@ static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp) MirrorBlockJob *s = container_of(job, MirrorBlockJob, common); if (speed < 0) { - error_set(errp, QERR_INVALID_PARAMETER, "speed"); + error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); @@ -598,8 +599,8 @@ static void mirror_complete(BlockJob *job, Error **errp) return; } if (!s->synced) { - error_set(errp, QERR_BLOCK_JOB_NOT_READY, - bdrv_get_device_name(job->bs)); + error_setg(errp, QERR_BLOCK_JOB_NOT_READY, + bdrv_get_device_name(job->bs)); return; } @@ -667,7 +668,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target, if ((on_source_error == BLOCKDEV_ON_ERROR_STOP || on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) && !bdrv_iostatus_is_enabled(bs)) { - error_set(errp, QERR_INVALID_PARAMETER, "on-source-error"); + error_setg(errp, QERR_INVALID_PARAMETER, "on-source-error"); return; } diff --git a/block/qapi.c b/block/qapi.c index a738148bce..2ce509711d 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -520,13 +520,7 @@ static void dump_qobject(fprintf_function func_fprintf, void *f, } case QTYPE_QBOOL: { QBool *value = qobject_to_qbool(obj); - func_fprintf(f, "%s", qbool_get_int(value) ? "true" : "false"); - break; - } - case QTYPE_QERROR: { - QString *value = qerror_human((QError *)obj); - func_fprintf(f, "%s", qstring_get_str(value)); - QDECREF(value); + func_fprintf(f, "%s", qbool_get_bool(value) ? "true" : "false"); break; } default: diff --git a/block/qcow.c b/block/qcow.c index 911e59fd0b..733627fbf2 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -25,6 +25,7 @@ #include "block/block_int.h" #include "qemu/module.h" #include <zlib.h> +#include "qapi/qmp/qerror.h" #include "qemu/aes.h" #include "migration/migration.h" @@ -123,8 +124,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, char version[64]; snprintf(version, sizeof(version), "QCOW version %" PRIu32, header.version); - error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, - bdrv_get_device_or_node_name(bs), "qcow", version); + error_setg(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, + bdrv_get_device_or_node_name(bs), "qcow", version); ret = -ENOTSUP; goto fail; } diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 17bb2119b2..b6f58c13e2 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -25,6 +25,7 @@ #include "qemu-common.h" #include "block/block_int.h" #include "block/qcow2.h" +#include "qemu/error-report.h" void qcow2_free_snapshots(BlockDriverState *bs) { diff --git a/block/qcow2.c b/block/qcow2.c index c4f6938a36..d522ec7d14 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -207,8 +207,8 @@ static void GCC_FMT_ATTR(3, 4) report_unsupported(BlockDriverState *bs, vsnprintf(msg, sizeof(msg), fmt, ap); va_end(ap); - error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, - bdrv_get_device_or_node_name(bs), "qcow2", msg); + error_setg(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, + bdrv_get_device_or_node_name(bs), "qcow2", msg); } static void report_unsupported_feature(BlockDriverState *bs, diff --git a/block/qed.c b/block/qed.c index 5bbe069ce9..954ed007c0 100644 --- a/block/qed.c +++ b/block/qed.c @@ -407,8 +407,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, char buf[64]; snprintf(buf, sizeof(buf), "%" PRIx64, s->header.features & ~QED_FEATURE_MASK); - error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, - bdrv_get_device_or_node_name(bs), "QED", buf); + error_setg(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, + bdrv_get_device_or_node_name(bs), "QED", buf); return -ENOTSUP; } if (!qed_is_cluster_size_valid(s->header.cluster_size)) { diff --git a/block/quorum.c b/block/quorum.c index 77e55b2775..a7df17c185 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -18,6 +18,7 @@ #include "block/block_int.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qerror.h" #include "qapi/qmp/qint.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qlist.h" @@ -800,8 +801,8 @@ static int quorum_valid_threshold(int threshold, int num_children, Error **errp) { if (threshold < 1) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, - "vote-threshold", "value >= 1"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "vote-threshold", "value >= 1"); return -ERANGE; } @@ -1024,9 +1025,9 @@ static void quorum_refresh_filename(BlockDriverState *bs) qdict_put_obj(opts, QUORUM_OPT_VOTE_THRESHOLD, QOBJECT(qint_from_int(s->threshold))); qdict_put_obj(opts, QUORUM_OPT_BLKVERIFY, - QOBJECT(qbool_from_int(s->is_blkverify))); + QOBJECT(qbool_from_bool(s->is_blkverify))); qdict_put_obj(opts, QUORUM_OPT_REWRITE, - QOBJECT(qbool_from_int(s->rewrite_corrupted))); + QOBJECT(qbool_from_bool(s->rewrite_corrupted))); qdict_put_obj(opts, "children", QOBJECT(children)); bs->full_open_options = opts; diff --git a/block/raw-posix.c b/block/raw-posix.c index 44ade8cf4e..a967464000 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include "qemu-common.h" +#include "qemu/error-report.h" #include "qemu/timer.h" #include "qemu/log.h" #include "block/block_int.h" @@ -31,6 +32,7 @@ #include "qemu/iov.h" #include "raw-aio.h" #include "qapi/util.h" +#include "qapi/qmp/qstring.h" #if defined(__APPLE__) && (__MACH__) #include <paths.h> diff --git a/block/raw-win32.c b/block/raw-win32.c index dae5d2fee9..68f2338acc 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -29,6 +29,7 @@ #include "trace.h" #include "block/thread-pool.h" #include "qemu/iov.h" +#include "qapi/qmp/qstring.h" #include <windows.h> #include <winioctl.h> diff --git a/block/snapshot.c b/block/snapshot.c index 50ae610139..19395ae014 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -24,6 +24,7 @@ #include "block/snapshot.h" #include "block/block_int.h" +#include "qapi/qmp/qerror.h" QemuOptsList internal_snapshot_opts = { .name = "snapshot", @@ -229,7 +230,7 @@ int bdrv_snapshot_delete(BlockDriverState *bs, { BlockDriver *drv = bs->drv; if (!drv) { - error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, bdrv_get_device_name(bs)); + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, bdrv_get_device_name(bs)); return -ENOMEDIUM; } if (!snapshot_id && !name) { @@ -315,7 +316,7 @@ int bdrv_snapshot_load_tmp(BlockDriverState *bs, BlockDriver *drv = bs->drv; if (!drv) { - error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, bdrv_get_device_name(bs)); + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, bdrv_get_device_name(bs)); return -ENOMEDIUM; } if (!snapshot_id && !name) { diff --git a/block/ssh.c b/block/ssh.c index f466cbf396..aebb18cc8f 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -30,9 +30,11 @@ #include <libssh2_sftp.h> #include "block/block_int.h" +#include "qemu/error-report.h" #include "qemu/sockets.h" #include "qemu/uri.h" #include "qapi/qmp/qint.h" +#include "qapi/qmp/qstring.h" /* DEBUG_SSH=1 enables the DPRINTF (debugging printf) statements in * this block driver code. diff --git a/block/stream.c b/block/stream.c index a628901f69..ab0bd057f7 100644 --- a/block/stream.c +++ b/block/stream.c @@ -14,6 +14,7 @@ #include "trace.h" #include "block/block_int.h" #include "block/blockjob.h" +#include "qapi/qmp/qerror.h" #include "qemu/ratelimit.h" enum { @@ -227,7 +228,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp) StreamBlockJob *s = container_of(job, StreamBlockJob, common); if (speed < 0) { - error_set(errp, QERR_INVALID_PARAMETER, "speed"); + error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); @@ -250,7 +251,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base, if ((on_error == BLOCKDEV_ON_ERROR_STOP || on_error == BLOCKDEV_ON_ERROR_ENOSPC) && !bdrv_iostatus_is_enabled(bs)) { - error_set(errp, QERR_INVALID_PARAMETER, "on-error"); + error_setg(errp, QERR_INVALID_PARAMETER, "on-error"); return; } diff --git a/block/vhdx-log.c b/block/vhdx-log.c index 6547bec404..47fec63c61 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -19,6 +19,7 @@ */ #include "qemu-common.h" #include "block/block_int.h" +#include "qemu/error-report.h" #include "qemu/module.h" #include "block/vhdx.h" diff --git a/block/vmdk.c b/block/vmdk.c index be9263a34e..fbaab67c8f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -25,6 +25,8 @@ #include "qemu-common.h" #include "block/block_int.h" +#include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qemu/module.h" #include "migration/migration.h" #include <zlib.h> @@ -645,8 +647,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, char buf[64]; snprintf(buf, sizeof(buf), "VMDK version %" PRId32, le32_to_cpu(header.version)); - error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, - bdrv_get_device_or_node_name(bs), "vmdk", buf); + error_setg(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, + bdrv_get_device_or_node_name(bs), "vmdk", buf); return -ENOTSUP; } else if (le32_to_cpu(header.version) == 3 && (flags & BDRV_O_RDWR)) { /* VMware KB 2064959 explains that version 3 added support for @@ -1688,12 +1690,12 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, /* write all the data */ ret = bdrv_pwrite(bs, 0, &magic, sizeof(magic)); if (ret < 0) { - error_set(errp, QERR_IO_ERROR); + error_setg(errp, QERR_IO_ERROR); goto exit; } ret = bdrv_pwrite(bs, sizeof(magic), &header, sizeof(header)); if (ret < 0) { - error_set(errp, QERR_IO_ERROR); + error_setg(errp, QERR_IO_ERROR); goto exit; } @@ -1713,7 +1715,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, ret = bdrv_pwrite(bs, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE, gd_buf, gd_buf_size); if (ret < 0) { - error_set(errp, QERR_IO_ERROR); + error_setg(errp, QERR_IO_ERROR); goto exit; } @@ -1725,7 +1727,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, ret = bdrv_pwrite(bs, le64_to_cpu(header.gd_offset) * BDRV_SECTOR_SIZE, gd_buf, gd_buf_size); if (ret < 0) { - error_set(errp, QERR_IO_ERROR); + error_setg(errp, QERR_IO_ERROR); goto exit; } diff --git a/block/vvfat.c b/block/vvfat.c index e803589675..c35550cd41 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -30,6 +30,7 @@ #include "migration/migration.h" #include "qapi/qmp/qint.h" #include "qapi/qmp/qbool.h" +#include "qapi/qmp/qstring.h" #ifndef S_IWGRP #define S_IWGRP 0 @@ -1059,8 +1060,8 @@ static void vvfat_parse_filename(const char *filename, QDict *options, /* Fill in the options QDict */ qdict_put(options, "dir", qstring_from_str(filename)); qdict_put(options, "fat-type", qint_from_int(fat_type)); - qdict_put(options, "floppy", qbool_from_int(floppy)); - qdict_put(options, "rw", qbool_from_int(rw)); + qdict_put(options, "floppy", qbool_from_bool(floppy)); + qdict_put(options, "rw", qbool_from_bool(rw)); } static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 0d9df47ce4..bcdd18b3f6 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -12,7 +12,6 @@ #include "sysemu/blockdev.h" #include "sysemu/block-backend.h" #include "hw/block/block.h" -#include "monitor/monitor.h" #include "qapi/qmp/qerror.h" #include "sysemu/sysemu.h" #include "qmp-commands.h" @@ -91,11 +90,12 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable, blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } if (!blk_is_inserted(blk)) { - error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); return; } diff --git a/blockdev.c b/blockdev.c index 41d7e0fe54..b35467646e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -36,10 +36,12 @@ #include "block/blockjob.h" #include "block/throttle-groups.h" #include "monitor/monitor.h" +#include "qemu/error-report.h" #include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/qmp/types.h" #include "qapi-visit.h" +#include "qapi/qmp/qerror.h" #include "qapi/qmp-output-visitor.h" #include "qapi/util.h" #include "sysemu/sysemu.h" @@ -174,7 +176,7 @@ static int drive_index_to_unit_id(BlockInterfaceType type, int index) QemuOpts *drive_def(const char *optstr) { - return qemu_opts_parse(qemu_find_opts("drive"), optstr, 0); + return qemu_opts_parse_noisily(qemu_find_opts("drive"), optstr, false); } QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file, @@ -1111,7 +1113,8 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return NULL; } bs = blk_bs(blk); @@ -1300,7 +1303,8 @@ static void internal_snapshot_prepare(BlkTransactionState *common, /* 2. check for validation */ blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } bs = blk_bs(blk); @@ -1310,7 +1314,7 @@ static void internal_snapshot_prepare(BlkTransactionState *common, aio_context_acquire(state->aio_context); if (!bdrv_is_inserted(bs)) { - error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); return; } @@ -1451,7 +1455,7 @@ static void external_snapshot_prepare(BlkTransactionState *common, /* start processing */ drv = bdrv_find_format(format); if (!drv) { - error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); + error_setg(errp, QERR_INVALID_BLOCK_FORMAT, format); return; } @@ -1478,7 +1482,7 @@ static void external_snapshot_prepare(BlkTransactionState *common, aio_context_acquire(state->aio_context); if (!bdrv_is_inserted(state->old_bs)) { - error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); return; } @@ -1489,13 +1493,13 @@ static void external_snapshot_prepare(BlkTransactionState *common, if (!bdrv_is_read_only(state->old_bs)) { if (bdrv_flush(state->old_bs)) { - error_set(errp, QERR_IO_ERROR); + error_setg(errp, QERR_IO_ERROR); return; } } if (!bdrv_is_first_non_filter(state->old_bs)) { - error_set(errp, QERR_FEATURE_DISABLED, "snapshot"); + error_setg(errp, QERR_FEATURE_DISABLED, "snapshot"); return; } @@ -1580,7 +1584,8 @@ static void drive_backup_prepare(BlkTransactionState *common, Error **errp) blk = blk_by_name(backup->device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, backup->device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", backup->device); return; } bs = blk_bs(blk); @@ -1850,7 +1855,8 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp) blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } @@ -1910,7 +1916,8 @@ void qmp_change_blockdev(const char *device, const char *filename, blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } bs = blk_bs(blk); @@ -1921,7 +1928,7 @@ void qmp_change_blockdev(const char *device, const char *filename, if (format) { drv = bdrv_find_whitelisted_format(format, bs->read_only); if (!drv) { - error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); + error_setg(errp, QERR_INVALID_BLOCK_FORMAT, format); goto out; } } @@ -1971,7 +1978,8 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } bs = blk_bs(blk); @@ -2202,17 +2210,17 @@ void qmp_block_resize(bool has_device, const char *device, aio_context_acquire(aio_context); if (!bdrv_is_first_non_filter(bs)) { - error_set(errp, QERR_FEATURE_DISABLED, "resize"); + error_setg(errp, QERR_FEATURE_DISABLED, "resize"); goto out; } if (size < 0) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size"); goto out; } if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_RESIZE, NULL)) { - error_set(errp, QERR_DEVICE_IN_USE, device); + error_setg(errp, QERR_DEVICE_IN_USE, device); goto out; } @@ -2224,16 +2232,16 @@ void qmp_block_resize(bool has_device, const char *device, case 0: break; case -ENOMEDIUM: - error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); break; case -ENOTSUP: - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); break; case -EACCES: error_setg(errp, "Device '%s' is read only", device); break; case -EBUSY: - error_set(errp, QERR_DEVICE_IN_USE, device); + error_setg(errp, QERR_DEVICE_IN_USE, device); break; default: error_setg_errno(errp, -ret, "Could not resize"); @@ -2291,7 +2299,8 @@ void qmp_block_stream(const char *device, blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } bs = blk_bs(blk); @@ -2306,7 +2315,7 @@ void qmp_block_stream(const char *device, if (has_base) { base_bs = bdrv_find_backing_image(bs, base); if (base_bs == NULL) { - error_set(errp, QERR_BASE_NOT_FOUND, base); + error_setg(errp, QERR_BASE_NOT_FOUND, base); goto out; } assert(bdrv_get_aio_context(base_bs) == aio_context); @@ -2365,7 +2374,8 @@ void qmp_block_commit(const char *device, * scenario in which all optional arguments are omitted. */ blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } bs = blk_bs(blk); @@ -2403,7 +2413,7 @@ void qmp_block_commit(const char *device, } if (base_bs == NULL) { - error_set(errp, QERR_BASE_NOT_FOUND, base ? base : "NULL"); + error_setg(errp, QERR_BASE_NOT_FOUND, base ? base : "NULL"); goto out; } @@ -2477,7 +2487,8 @@ void qmp_drive_backup(const char *device, const char *target, blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } bs = blk_bs(blk); @@ -2488,7 +2499,7 @@ void qmp_drive_backup(const char *device, const char *target, /* Although backup_run has this check too, we need to use bs->drv below, so * do an early check redundantly. */ if (!bdrv_is_inserted(bs)) { - error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); goto out; } @@ -2498,7 +2509,7 @@ void qmp_drive_backup(const char *device, const char *target, if (format) { drv = bdrv_find_format(format); if (!drv) { - error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); + error_setg(errp, QERR_INVALID_BLOCK_FORMAT, format); goto out; } } @@ -2680,18 +2691,20 @@ void qmp_drive_mirror(const char *device, const char *target, } if (granularity != 0 && (granularity < 512 || granularity > 1048576 * 64)) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "granularity", - "a value in range [512B, 64MB]"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "granularity", + "a value in range [512B, 64MB]"); return; } if (granularity & (granularity - 1)) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "granularity", "power of 2"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "granularity", + "power of 2"); return; } blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } bs = blk_bs(blk); @@ -2700,7 +2713,7 @@ void qmp_drive_mirror(const char *device, const char *target, aio_context_acquire(aio_context); if (!bdrv_is_inserted(bs)) { - error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); goto out; } @@ -2710,7 +2723,7 @@ void qmp_drive_mirror(const char *device, const char *target, if (format) { drv = bdrv_find_format(format); if (!drv) { - error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); + error_setg(errp, QERR_INVALID_BLOCK_FORMAT, format); goto out; } } @@ -2957,7 +2970,8 @@ void qmp_change_backing_file(const char *device, blk = blk_by_name(device); if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); return; } bs = blk_bs(blk); diff --git a/blockjob.c b/blockjob.c index 2755465259..ec46fad2f1 100644 --- a/blockjob.c +++ b/blockjob.c @@ -29,6 +29,7 @@ #include "block/block.h" #include "block/blockjob.h" #include "block/block_int.h" +#include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" #include "block/coroutine.h" #include "qmp-commands.h" @@ -42,7 +43,7 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, BlockJob *job; if (bs->job) { - error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs)); + error_setg(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs)); return NULL; } bdrv_ref(bs); @@ -93,7 +94,7 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) Error *local_err = NULL; if (!job->driver->set_speed) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return; } job->driver->set_speed(job, speed, &local_err); @@ -108,8 +109,8 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) void block_job_complete(BlockJob *job, Error **errp) { if (job->pause_count || job->cancelled || !job->driver->complete) { - error_set(errp, QERR_BLOCK_JOB_NOT_READY, - bdrv_get_device_name(job->bs)); + error_setg(errp, QERR_BLOCK_JOB_NOT_READY, + bdrv_get_device_name(job->bs)); return; } @@ -27,6 +27,7 @@ #include "monitor/monitor.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "sysemu/sysemu.h" #include "exec/gdbstub.h" #include "sysemu/dma.h" @@ -1512,8 +1513,8 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename, cpu = qemu_get_cpu(cpu_index); if (cpu == NULL) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", - "a CPU number"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", + "a CPU number"); return; } @@ -1533,7 +1534,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename, goto exit; } if (fwrite(buf, 1, l, f) != l) { - error_set(errp, QERR_IO_ERROR); + error_setg(errp, QERR_IO_ERROR); goto exit; } addr += l; @@ -1563,7 +1564,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, l = size; cpu_physical_memory_read(addr, buf, l); if (fwrite(buf, 1, l, f) != l) { - error_set(errp, QERR_IO_ERROR); + error_setg(errp, QERR_IO_ERROR); goto exit; } addr += l; @@ -9,7 +9,7 @@ typedef struct CPUDebug { struct disassemble_info info; - CPUArchState *env; + CPUState *cpu; } CPUDebug; /* Filled in by elfload.c. Simplistic, but will do for now. */ @@ -39,7 +39,7 @@ target_read_memory (bfd_vma memaddr, { CPUDebug *s = container_of(info, CPUDebug, info); - cpu_memory_rw_debug(ENV_GET_CPU(s->env), memaddr, myaddr, length, 0); + cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); return 0; } @@ -195,7 +195,7 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info) bit 16 indicates little endian. other targets - unused */ -void target_disas(FILE *out, CPUArchState *env, target_ulong code, +void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size, int flags) { target_ulong pc; @@ -205,7 +205,7 @@ void target_disas(FILE *out, CPUArchState *env, target_ulong code, INIT_DISASSEMBLE_INFO(s.info, out, fprintf); - s.env = env; + s.cpu = cpu; s.info.read_memory_func = target_read_memory; s.info.buffer_vma = code; s.info.buffer_length = size; @@ -430,7 +430,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length, if (monitor_disas_is_physical) { cpu_physical_memory_read(memaddr, myaddr, length); } else { - cpu_memory_rw_debug(ENV_GET_CPU(s->env), memaddr, myaddr, length, 0); + cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); } return 0; } @@ -447,7 +447,7 @@ monitor_fprintf(FILE *stream, const char *fmt, ...) /* Disassembler for the monitor. See target_disas for a description of flags. */ -void monitor_disas(Monitor *mon, CPUArchState *env, +void monitor_disas(Monitor *mon, CPUState *cpu, target_ulong pc, int nb_insn, int is_physical, int flags) { int count, i; @@ -456,7 +456,7 @@ void monitor_disas(Monitor *mon, CPUArchState *env, INIT_DISASSEMBLE_INFO(s.info, (FILE *)mon, monitor_fprintf); - s.env = env; + s.cpu = cpu; monitor_disas_is_physical = is_physical; s.info.read_memory_func = monitor_read_memory; s.info.print_address_func = generic_print_target_address; @@ -23,6 +23,7 @@ #include "sysemu/memory_mapping.h" #include "sysemu/cpus.h" #include "qapi/error.h" +#include "qapi/qmp/qerror.h" #include "qmp-commands.h" #include <zlib.h> @@ -1474,7 +1475,7 @@ static void dump_init(DumpState *s, int fd, bool has_format, s->start = get_start_block(s); if (s->start == -1) { - error_set(errp, QERR_INVALID_PARAMETER, "begin"); + error_setg(errp, QERR_INVALID_PARAMETER, "begin"); goto cleanup; } @@ -1484,14 +1485,14 @@ static void dump_init(DumpState *s, int fd, bool has_format, */ ret = cpu_get_dump_info(&s->dump_info, &s->guest_phys_blocks); if (ret < 0) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); goto cleanup; } s->note_size = cpu_get_note_size(s->dump_info.d_class, s->dump_info.d_machine, nr_cpus); if (s->note_size < 0) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); goto cleanup; } @@ -1615,11 +1616,11 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin, return; } if (has_begin && !has_length) { - error_set(errp, QERR_MISSING_PARAMETER, "length"); + error_setg(errp, QERR_MISSING_PARAMETER, "length"); return; } if (!has_begin && has_length) { - error_set(errp, QERR_MISSING_PARAMETER, "begin"); + error_setg(errp, QERR_MISSING_PARAMETER, "begin"); return; } @@ -1656,7 +1657,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin, } if (fd == -1) { - error_set(errp, QERR_INVALID_PARAMETER, "protocol"); + error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); return; } @@ -25,6 +25,7 @@ #include "monitor/monitor.h" #include "monitor/qdev.h" #include "qapi/opts-visitor.h" +#include "qapi/qmp/qerror.h" #include "qapi/string-output-visitor.h" #include "qapi-visit.h" #include "ui/console.h" @@ -438,8 +439,8 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) BlockInfoList *block_list, *info; BlockDeviceInfoList *blockdev_list, *blockdev; const char *device = qdict_get_try_str(qdict, "device"); - bool verbose = qdict_get_try_bool(qdict, "verbose", 0); - bool nodes = qdict_get_try_bool(qdict, "nodes", 0); + bool verbose = qdict_get_try_bool(qdict, "verbose", false); + bool nodes = qdict_get_try_bool(qdict, "nodes", false); bool printed = false; /* Print BlockBackend information */ @@ -995,7 +996,7 @@ void hmp_nmi(Monitor *mon, const QDict *qdict) void hmp_set_link(Monitor *mon, const QDict *qdict) { const char *name = qdict_get_str(qdict, "name"); - int up = qdict_get_bool(qdict, "up"); + bool up = qdict_get_bool(qdict, "up"); Error *err = NULL; qmp_set_link(name, up, &err); @@ -1039,13 +1040,13 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict) const char *device = qdict_get_str(qdict, "device"); const char *filename = qdict_get_str(qdict, "target"); const char *format = qdict_get_try_str(qdict, "format"); - int reuse = qdict_get_try_bool(qdict, "reuse", 0); - int full = qdict_get_try_bool(qdict, "full", 0); + bool reuse = qdict_get_try_bool(qdict, "reuse", false); + bool full = qdict_get_try_bool(qdict, "full", false); enum NewImageMode mode; Error *err = NULL; if (!filename) { - error_set(&err, QERR_MISSING_PARAMETER, "target"); + error_setg(&err, QERR_MISSING_PARAMETER, "target"); hmp_handle_error(mon, &err); return; } @@ -1069,13 +1070,13 @@ void hmp_drive_backup(Monitor *mon, const QDict *qdict) const char *device = qdict_get_str(qdict, "device"); const char *filename = qdict_get_str(qdict, "target"); const char *format = qdict_get_try_str(qdict, "format"); - int reuse = qdict_get_try_bool(qdict, "reuse", 0); - int full = qdict_get_try_bool(qdict, "full", 0); + bool reuse = qdict_get_try_bool(qdict, "reuse", false); + bool full = qdict_get_try_bool(qdict, "full", false); enum NewImageMode mode; Error *err = NULL; if (!filename) { - error_set(&err, QERR_MISSING_PARAMETER, "target"); + error_setg(&err, QERR_MISSING_PARAMETER, "target"); hmp_handle_error(mon, &err); return; } @@ -1098,14 +1099,14 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) const char *device = qdict_get_str(qdict, "device"); const char *filename = qdict_get_try_str(qdict, "snapshot-file"); const char *format = qdict_get_try_str(qdict, "format"); - int reuse = qdict_get_try_bool(qdict, "reuse", 0); + bool reuse = qdict_get_try_bool(qdict, "reuse", false); enum NewImageMode mode; Error *err = NULL; if (!filename) { /* In the future, if 'snapshot-file' is not specified, the snapshot will be taken internally. Today it's actually required. */ - error_set(&err, QERR_MISSING_PARAMETER, "snapshot-file"); + error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file"); hmp_handle_error(mon, &err); return; } @@ -1200,7 +1201,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) } if (i == MIGRATION_CAPABILITY_MAX) { - error_set(&err, QERR_INVALID_PARAMETER, cap); + error_setg(&err, QERR_INVALID_PARAMETER, cap); } qapi_free_MigrationCapabilityStatusList(caps); @@ -1244,7 +1245,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) } if (i == MIGRATION_PARAMETER_MAX) { - error_set(&err, QERR_INVALID_PARAMETER, param); + error_setg(&err, QERR_INVALID_PARAMETER, param); } if (err) { @@ -1294,7 +1295,7 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict) void hmp_eject(Monitor *mon, const QDict *qdict) { - int force = qdict_get_try_bool(qdict, "force", 0); + bool force = qdict_get_try_bool(qdict, "force", false); const char *device = qdict_get_str(qdict, "device"); Error *err = NULL; @@ -1394,7 +1395,7 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) { Error *error = NULL; const char *device = qdict_get_str(qdict, "device"); - bool force = qdict_get_try_bool(qdict, "force", 0); + bool force = qdict_get_try_bool(qdict, "force", false); qmp_block_job_cancel(device, true, force, &error); @@ -1474,9 +1475,9 @@ static void hmp_migrate_status_cb(void *opaque) void hmp_migrate(Monitor *mon, const QDict *qdict) { - int detach = qdict_get_try_bool(qdict, "detach", 0); - int blk = qdict_get_try_bool(qdict, "blk", 0); - int inc = qdict_get_try_bool(qdict, "inc", 0); + bool detach = qdict_get_try_bool(qdict, "detach", false); + bool blk = qdict_get_try_bool(qdict, "blk", false); + bool inc = qdict_get_try_bool(qdict, "inc", false); const char *uri = qdict_get_str(qdict, "uri"); Error *err = NULL; @@ -1507,7 +1508,10 @@ void hmp_migrate(Monitor *mon, const QDict *qdict) void hmp_device_add(Monitor *mon, const QDict *qdict) { - do_device_add(mon, qdict, NULL); + Error *err = NULL; + + qmp_device_add((QDict *)qdict, NULL, &err); + hmp_handle_error(mon, &err); } void hmp_device_del(Monitor *mon, const QDict *qdict) @@ -1522,10 +1526,10 @@ void hmp_device_del(Monitor *mon, const QDict *qdict) void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) { Error *err = NULL; - int paging = qdict_get_try_bool(qdict, "paging", 0); - int zlib = qdict_get_try_bool(qdict, "zlib", 0); - int lzo = qdict_get_try_bool(qdict, "lzo", 0); - int snappy = qdict_get_try_bool(qdict, "snappy", 0); + bool paging = qdict_get_try_bool(qdict, "paging", false); + bool zlib = qdict_get_try_bool(qdict, "zlib", false); + bool lzo = qdict_get_try_bool(qdict, "lzo", false); + bool snappy = qdict_get_try_bool(qdict, "snappy", false); const char *file = qdict_get_str(qdict, "filename"); bool has_begin = qdict_haskey(qdict, "begin"); bool has_length = qdict_haskey(qdict, "length"); @@ -1751,8 +1755,8 @@ void hmp_screendump(Monitor *mon, const QDict *qdict) void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) { const char *uri = qdict_get_str(qdict, "uri"); - int writable = qdict_get_try_bool(qdict, "writable", 0); - int all = qdict_get_try_bool(qdict, "all", 0); + bool writable = qdict_get_try_bool(qdict, "writable", false); + bool all = qdict_get_try_bool(qdict, "all", false); Error *local_err = NULL; BlockInfoList *block_list, *info; SocketAddress *addr; @@ -1805,7 +1809,7 @@ exit: void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_str(qdict, "device"); - int writable = qdict_get_try_bool(qdict, "writable", 0); + bool writable = qdict_get_try_bool(qdict, "writable", false); Error *local_err = NULL; qmp_nbd_server_add(device, true, writable, &local_err); @@ -1839,7 +1843,7 @@ void hmp_chardev_add(Monitor *mon, const QDict *qdict) Error *err = NULL; QemuOpts *opts; - opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); if (opts == NULL) { error_setg(&err, "Parsing chardev args failed"); } else { @@ -1867,7 +1871,8 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) if (blk) { qemuio_command(blk, command); } else { - error_set(&err, QERR_DEVICE_NOT_FOUND, device); + error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); } hmp_handle_error(mon, &err); @@ -1995,7 +2000,8 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict) obj = object_resolve_path(path, &ambiguous); if (obj == NULL) { - error_set(&err, QERR_DEVICE_NOT_FOUND, path); + error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", path); } else { if (ambiguous) { monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path); diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index 4964da0d7e..6ef8af3f64 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -13,6 +13,7 @@ #include "hw/virtio/virtio.h" #include "hw/i386/pc.h" +#include "qemu/error-report.h" #include "qemu/sockets.h" #include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c index 653064fadf..1c8b9be5cc 100644 --- a/hw/char/serial-pci.c +++ b/hw/char/serial-pci.c @@ -27,7 +27,6 @@ #include "hw/char/serial.h" #include "hw/pci/pci.h" -#include "qapi/qmp/qerror.h" #define PCI_SERIAL_MAX_PORTS 4 diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index d451b22386..78c73e5abe 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -20,6 +20,7 @@ #include "qemu/iov.h" #include "monitor/monitor.h" +#include "qemu/error-report.h" #include "qemu/queue.h" #include "hw/sysbus.h" #include "trace.h" diff --git a/hw/core/nmi.c b/hw/core/nmi.c index 5260d6c1ec..de1d1f8cb1 100644 --- a/hw/core/nmi.c +++ b/hw/core/nmi.c @@ -67,7 +67,7 @@ void nmi_monitor_handle(int cpu_index, Error **errp) if (ns.handled) { error_propagate(errp, ns.errp); } else { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } } diff --git a/hw/core/platform-bus.c b/hw/core/platform-bus.c index 0f052b3338..70e0518901 100644 --- a/hw/core/platform-bus.c +++ b/hw/core/platform-bus.c @@ -20,7 +20,6 @@ */ #include "hw/platform-bus.h" -#include "monitor/monitor.h" #include "exec/address-spaces.h" #include "sysemu/sysemu.h" diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index 0309fe5767..aa794ca445 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -326,8 +326,8 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque, hubport = net_hub_port_find(id); if (!hubport) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, - name, prop->info->name); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name, prop->info->name); return; } *ptr = hubport; diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index a1606deaca..47c1e8f3c5 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1,6 +1,7 @@ #include "net/net.h" #include "hw/qdev.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "sysemu/block-backend.h" #include "hw/block/block.h" #include "net/hub.h" @@ -570,8 +571,8 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, if (local_err) { error_propagate(errp, local_err); } else if (value < -1 || value > 255) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "pci_devfn"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", "pci_devfn"); } else { *ptr = value; } @@ -640,8 +641,8 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque, } /* value of 0 means "unset" */ if (value && (value < min || value > max)) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, - dev->id?:"", name, (int64_t)value, min, max); + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, + dev->id ? : "", name, (int64_t)value, min, max); return; } @@ -923,8 +924,8 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, break; default: case -EINVAL: - error_set(errp, QERR_PROPERTY_VALUE_BAD, - object_get_typename(OBJECT(dev)), prop->name, value); + error_setg(errp, QERR_PROPERTY_VALUE_BAD, + object_get_typename(OBJECT(dev)), prop->name, value); break; case -ENOENT: error_setg(errp, "Property '%s.%s' can't find value '%s'", diff --git a/hw/core/qdev.c b/hw/core/qdev.c index a6353c177f..b2f404a765 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -32,6 +32,7 @@ #include "qapi/qmp/qerror.h" #include "qapi/visitor.h" #include "qapi/qmp/qjson.h" +#include "qemu/error-report.h" #include "hw/hotplug.h" #include "hw/boards.h" #include "qapi-event.h" @@ -276,13 +277,13 @@ void qdev_unplug(DeviceState *dev, Error **errp) HotplugHandlerClass *hdc; if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) { - error_set(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); + error_setg(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); return; } if (!dc->hotpluggable) { - error_set(errp, QERR_DEVICE_NO_HOTPLUG, - object_get_typename(OBJECT(dev))); + error_setg(errp, QERR_DEVICE_NO_HOTPLUG, + object_get_typename(OBJECT(dev))); return; } @@ -1026,7 +1027,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp) Error *local_err = NULL; if (dev->hotplugged && !dc->hotpluggable) { - error_set(errp, QERR_DEVICE_NO_HOTPLUG, object_get_typename(obj)); + error_setg(errp, QERR_DEVICE_NO_HOTPLUG, object_get_typename(obj)); return; } diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c index 52a9733bfd..7f83a007b7 100644 --- a/hw/display/g364fb.c +++ b/hw/display/g364fb.c @@ -18,6 +18,7 @@ */ #include "hw/hw.h" +#include "qemu/error-report.h" #include "ui/console.h" #include "ui/pixel_ops.h" #include "trace.h" diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 722146ec3a..f87a5ee602 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -25,7 +25,6 @@ #include "qemu/timer.h" #include "qemu/queue.h" #include "qemu/atomic.h" -#include "monitor/monitor.h" #include "sysemu/sysemu.h" #include "trace.h" diff --git a/hw/display/tcx.c b/hw/display/tcx.c index f3faf78bf8..a0b6bc58de 100644 --- a/hw/display/tcx.c +++ b/hw/display/tcx.c @@ -27,6 +27,7 @@ #include "ui/pixel_ops.h" #include "hw/loader.h" #include "hw/sysbus.h" +#include "qemu/error-report.h" #define TCX_ROM_FILE "QEMU,tcx.bin" #define FCODE_MAX_ROM_SIZE 0x10000 diff --git a/hw/dma/xilinx_axidma.c b/hw/dma/xilinx_axidma.c index d06002dde8..cf842a3cc7 100644 --- a/hw/dma/xilinx_axidma.c +++ b/hw/dma/xilinx_axidma.c @@ -26,7 +26,6 @@ #include "qemu/timer.h" #include "hw/ptimer.h" #include "qemu/log.h" -#include "qapi/qmp/qerror.h" #include "qemu/main-loop.h" #include "hw/stream.h" diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 3f0d435da9..7072930cfc 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -31,7 +31,6 @@ #include "hw/ide.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" -#include "monitor/monitor.h" #include "hw/nvram/fw_cfg.h" #include "hw/timer/hpet.h" #include "hw/i386/smbios.h" @@ -57,6 +56,7 @@ #include "sysemu/arch_init.h" #include "qemu/bitmap.h" #include "qemu/config-file.h" +#include "qemu/error-report.h" #include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" #include "hw/cpu/icc_bus.h" diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 9e5d86297c..b4b65c100a 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -27,7 +27,7 @@ #include <hw/pci/pci.h> #include <hw/sysbus.h> -#include "monitor/monitor.h" +#include "qemu/error-report.h" #include "sysemu/block-backend.h" #include "sysemu/dma.h" #include "internal.h" diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c index 87fe2e865d..14ab0e31b8 100644 --- a/hw/intc/openpic.c +++ b/hw/intc/openpic.c @@ -1556,9 +1556,9 @@ static void openpic_realize(DeviceState *dev, Error **errp) }; if (opp->nb_cpus > MAX_CPU) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, - TYPE_OPENPIC, "nb_cpus", (uint64_t)opp->nb_cpus, - (uint64_t)0, (uint64_t)MAX_CPU); + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, + TYPE_OPENPIC, "nb_cpus", (uint64_t)opp->nb_cpus, + (uint64_t)0, (uint64_t)MAX_CPU); return; } diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 231c35fdef..cc76989a39 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -22,7 +22,7 @@ #include "hw/pci/msix.h" #include "sysemu/kvm.h" #include "migration/migration.h" -#include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qemu/event_notifier.h" #include "qemu/fifo8.h" #include "sysemu/char.h" diff --git a/hw/net/rocker/qmp-norocker.c b/hw/net/rocker/qmp-norocker.c index f253747361..49b498b642 100644 --- a/hw/net/rocker/qmp-norocker.c +++ b/hw/net/rocker/qmp-norocker.c @@ -21,13 +21,13 @@ RockerSwitch *qmp_query_rocker(const char *name, Error **errp) { - error_set(errp, QERR_FEATURE_DISABLED, "rocker"); + error_setg(errp, QERR_FEATURE_DISABLED, "rocker"); return NULL; }; RockerPortList *qmp_query_rocker_ports(const char *name, Error **errp) { - error_set(errp, QERR_FEATURE_DISABLED, "rocker"); + error_setg(errp, QERR_FEATURE_DISABLED, "rocker"); return NULL; }; @@ -36,7 +36,7 @@ RockerOfDpaFlowList *qmp_query_rocker_of_dpa_flows(const char *name, uint32_t tbl_id, Error **errp) { - error_set(errp, QERR_FEATURE_DISABLED, "rocker"); + error_setg(errp, QERR_FEATURE_DISABLED, "rocker"); return NULL; }; @@ -45,6 +45,6 @@ RockerOfDpaGroupList *qmp_query_rocker_of_dpa_groups(const char *name, uint8_t type, Error **errp) { - error_set(errp, QERR_FEATURE_DISABLED, "rocker"); + error_setg(errp, QERR_FEATURE_DISABLED, "rocker"); return NULL; }; diff --git a/hw/net/xilinx_axienet.c b/hw/net/xilinx_axienet.c index 21efedfc3e..92057707e0 100644 --- a/hw/net/xilinx_axienet.c +++ b/hw/net/xilinx_axienet.c @@ -26,7 +26,6 @@ #include "qemu/log.h" #include "net/net.h" #include "net/checksum.h" -#include "qapi/qmp/qerror.h" #include "hw/stream.h" diff --git a/hw/pci/pci-stub.c b/hw/pci/pci-stub.c index f8f237e823..063a7c2427 100644 --- a/hw/pci/pci-stub.c +++ b/hw/pci/pci-stub.c @@ -20,12 +20,13 @@ #include "sysemu/sysemu.h" #include "monitor/monitor.h" +#include "qapi/qmp/qerror.h" #include "hw/pci/pci.h" #include "qmp-commands.h" PciInfoList *qmp_query_pci(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 21580433d4..45394cfe32 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -30,6 +30,7 @@ #include "net/net.h" #include "sysemu/sysemu.h" #include "hw/loader.h" +#include "qemu/error-report.h" #include "qemu/range.h" #include "qmp-commands.h" #include "trace.h" diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 1463e65b5d..14c77117f6 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -26,7 +26,6 @@ #include "hw/pci/pci_bus.h" #include "hw/pci/pcie_regs.h" #include "qemu/range.h" -#include "qapi/qmp/qerror.h" //#define DEBUG_PCIE #ifdef DEBUG_PCIE diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index c8dea8ed9c..f1847ac210 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -975,7 +975,7 @@ static int do_pcie_aer_inject_error(Monitor *mon, if (pcie_aer_parse_error_string(error_name, &error_status, &correctable)) { char *e = NULL; error_status = strtoul(error_name, &e, 0); - correctable = qdict_get_try_bool(qdict, "correctable", 0); + correctable = qdict_get_try_bool(qdict, "correctable", false); if (!e || *e != '\0') { monitor_printf(mon, "invalid error status value. \"%s\"", error_name); @@ -989,7 +989,7 @@ static int do_pcie_aer_inject_error(Monitor *mon, if (correctable) { err.flags |= PCIE_AER_ERR_IS_CORRECTABLE; } - if (qdict_get_try_bool(qdict, "advisory_non_fatal", 0)) { + if (qdict_get_try_bool(qdict, "advisory_non_fatal", false)) { err.flags |= PCIE_AER_ERR_MAYBE_ADVISORY; } if (qdict_haskey(qdict, "header0")) { diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index a706486394..bfb4d31b62 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -7,7 +7,6 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" #include "hw/pci/msi.h" -#include "qapi/qmp/qerror.h" /* TODO: model power only and disabled slot states. */ /* TODO: handle SERR and wakeups */ diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 4df3a33db4..d4a6150527 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1062,8 +1062,8 @@ static void spapr_phb_hot_plug_child(HotplugHandler *plug_handler, * we need to let them know it's not enabled */ if (plugged_dev->hotplugged) { - error_set(errp, QERR_BUS_NO_HOTPLUG, - object_get_typename(OBJECT(phb))); + error_setg(errp, QERR_BUS_NO_HOTPLUG, + object_get_typename(OBJECT(phb))); } return; } @@ -1090,8 +1090,8 @@ static void spapr_phb_hot_unplug_child(HotplugHandler *plug_handler, Error *local_err = NULL; if (!phb->dr_enabled) { - error_set(errp, QERR_BUS_NO_HOTPLUG, - object_get_typename(OBJECT(phb))); + error_setg(errp, QERR_BUS_NO_HOTPLUG, + object_get_typename(OBJECT(phb))); return; } diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c index 174033dd41..8b59b64b7e 100644 --- a/hw/ppc/spapr_vio.c +++ b/hw/ppc/spapr_vio.c @@ -22,7 +22,6 @@ #include "hw/hw.h" #include "sysemu/sysemu.h" #include "hw/boards.h" -#include "monitor/monitor.h" #include "hw/loader.h" #include "elf.h" #include "hw/sysbus.h" diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c index 6ebd5bee8b..439732f7ab 100644 --- a/hw/ppc/virtex_ml507.c +++ b/hw/ppc/virtex_ml507.c @@ -32,6 +32,7 @@ #include "sysemu/device_tree.h" #include "hw/loader.h" #include "elf.h" +#include "qemu/error-report.h" #include "qemu/log.h" #include "exec/address-spaces.h" @@ -40,7 +41,6 @@ #include "ppc405.h" #include "sysemu/block-backend.h" -#include "qapi/qmp/qerror.h" #define EPAPR_MAGIC (0x45504150) #define FLASH_SIZE (16 * 1024 * 1024) diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index 1cb116a297..0c700effb1 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -15,7 +15,6 @@ * */ -#include "monitor/monitor.h" #include "sysemu/sysemu.h" #include "hw/s390x/sclp.h" diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c index 8a6e27eac1..77aec8a5bd 100644 --- a/hw/s390x/s390-virtio-bus.c +++ b/hw/s390x/s390-virtio-bus.c @@ -21,7 +21,6 @@ #include "sysemu/block-backend.h" #include "sysemu/sysemu.h" #include "hw/boards.h" -#include "monitor/monitor.h" #include "hw/loader.h" #include "elf.h" #include "hw/virtio/virtio.h" diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c index 00ea793651..1284e77b22 100644 --- a/hw/s390x/s390-virtio.c +++ b/hw/s390x/s390-virtio.c @@ -22,12 +22,12 @@ */ #include "hw/hw.h" +#include "qapi/qmp/qerror.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "sysemu/sysemu.h" #include "net/net.h" #include "hw/boards.h" -#include "monitor/monitor.h" #include "hw/loader.h" #include "hw/virtio/virtio.h" #include "hw/sysbus.h" @@ -324,7 +324,7 @@ void s390_nmi(NMIState *n, int cpu_index, Error **errp) CPUState *cs = qemu_get_cpu(cpu_index); if (s390_cpu_restart(S390_CPU(cs))) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } } diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index e32ada9bf1..9605bf40b9 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -15,12 +15,12 @@ #include "sysemu/blockdev.h" #include "sysemu/sysemu.h" #include "net/net.h" -#include "monitor/monitor.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-serial.h" #include "hw/virtio/virtio-net.h" #include "hw/sysbus.h" #include "qemu/bitops.h" +#include "qemu/error-report.h" #include "hw/virtio/virtio-bus.h" #include "hw/s390x/adapter.h" #include "hw/s390x/s390_flic.h" diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 1c389c4d7e..52549f8beb 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -16,6 +16,7 @@ #include <sys/ioctl.h> #include "config.h" +#include "qemu/error-report.h" #include "qemu/queue.h" #include "monitor/monitor.h" #include "migration/migration.h" diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index b50071ef93..2bb62211c3 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -27,6 +27,7 @@ #include "hw/hw.h" #include "hw/i386/pc.h" #include "ui/console.h" +#include "qemu/error-report.h" #include "qemu/timer.h" #include "hw/timer/hpet.h" #include "hw/sysbus.h" diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 8d8523a535..79a8f98af0 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -26,6 +26,7 @@ #include "qemu-common.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "qemu/sockets.h" #include "sysemu/tpm_backend.h" #include "tpm_int.h" diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 375167573d..5f39e1e3ac 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -1,6 +1,7 @@ #include "hw/hw.h" #include "hw/usb.h" #include "hw/qdev.h" +#include "qemu/error-report.h" #include "sysemu/sysemu.h" #include "monitor/monitor.h" #include "trace.h" diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index aa1c37aabd..72329ed7d7 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -33,7 +33,6 @@ #include "qemu/thread.h" #include "sysemu/char.h" -#include "monitor/monitor.h" #include "ccid.h" #define DPRINTF(card, lvl, fmt, ...) \ diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 10f1d309a6..85a4fc3e53 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -9,8 +9,8 @@ */ #include "sysemu/char.h" +#include "qemu/error-report.h" #include "qemu/sockets.h" -#include "monitor/monitor.h" #include "ccid.h" #include "libcacard/vscard_common.h" diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 743c231d6b..5eeb4c6b06 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1397,7 +1397,7 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline) QemuOpts *opts; int idx; - opts = qemu_opts_parse(qemu_find_opts("net"), cmdline, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("net"), cmdline, false); if (!opts) { return NULL; } diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c index 6ca3da9727..a6a66008ec 100644 --- a/hw/usb/dev-serial.c +++ b/hw/usb/dev-serial.c @@ -9,7 +9,7 @@ */ #include "qemu-common.h" -#include "monitor/monitor.h" +#include "qemu/error-report.h" #include "hw/usb.h" #include "hw/usb/desc.h" #include "sysemu/char.h" diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index 2d29367ae7..de534bab37 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -38,7 +38,6 @@ #include "qemu/error-report.h" #include "hw/usb.h" #include "hw/usb/desc.h" -#include "monitor/monitor.h" #include "ccid.h" diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index abe0e1d6a1..9a4e7dc0cb 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -8,6 +8,7 @@ */ #include "qemu-common.h" +#include "qemu/error-report.h" #include "qemu/option.h" #include "qemu/config-file.h" #include "hw/usb.h" diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h index 87b240f70a..30218423c8 100644 --- a/hw/usb/hcd-ehci.h +++ b/hw/usb/hcd-ehci.h @@ -20,7 +20,6 @@ #include "hw/hw.h" #include "qemu/timer.h" #include "hw/usb.h" -#include "monitor/monitor.h" #include "sysemu/dma.h" #include "sysemu/sysemu.h" #include "hw/pci/pci.h" diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index 10f4735ddf..bc2944c6b2 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -38,6 +38,7 @@ #include "qemu-common.h" #include "monitor/monitor.h" +#include "qemu/error-report.h" #include "sysemu/sysemu.h" #include "trace.h" diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 6b4218c037..25df25fd0f 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -27,8 +27,9 @@ #include "qemu-common.h" #include "qemu/timer.h" -#include "monitor/monitor.h" #include "sysemu/sysemu.h" +#include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qemu/iov.h" #include "sysemu/char.h" @@ -1369,7 +1370,7 @@ static void usbredir_realize(USBDevice *udev, Error **errp) int i; if (dev->cs == NULL) { - error_set(errp, QERR_MISSING_PARAMETER, "chardev"); + error_setg(errp, QERR_MISSING_PARAMETER, "chardev"); return; } @@ -1378,8 +1379,8 @@ static void usbredir_realize(USBDevice *udev, Error **errp) &dev->filter_rules, &dev->filter_rules_count); if (i) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "filter", - "a usb device filter string"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "filter", + "a usb device filter string"); return; } } diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c index 22b1d87d0e..740ed3102b 100644 --- a/hw/virtio/virtio-rng.c +++ b/hw/virtio/virtio-rng.c @@ -11,7 +11,6 @@ #include "qemu/iov.h" #include "hw/qdev.h" -#include "qapi/qmp/qerror.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-rng.h" #include "sysemu/rng.h" diff --git a/include/block/block_int.h b/include/block/block_int.h index 888ec09e96..b0476fc36e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -31,8 +31,6 @@ #include "block/coroutine.h" #include "qemu/timer.h" #include "qapi-types.h" -#include "qapi/qmp/qerror.h" -#include "monitor/monitor.h" #include "qemu/hbitmap.h" #include "block/snapshot.h" #include "qemu/main-loop.h" diff --git a/include/disas/disas.h b/include/disas/disas.h index c13ca9a3a4..2b9293b62a 100644 --- a/include/disas/disas.h +++ b/include/disas/disas.h @@ -6,10 +6,10 @@ #ifdef NEED_CPU_H /* Disassemble this for me please... (debugging). */ void disas(FILE *out, void *code, unsigned long size); -void target_disas(FILE *out, CPUArchState *env, target_ulong code, +void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size, int flags); -void monitor_disas(Monitor *mon, CPUArchState *env, +void monitor_disas(Monitor *mon, CPUState *cpu, target_ulong pc, int nb_insn, int is_physical, int flags); /* Look up symbol for debugging purpose. Returns "" if unknown. */ diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 88644ceda7..9aff47e699 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -2,7 +2,6 @@ #define MONITOR_H #include "qemu-common.h" -#include "qapi/qmp/qerror.h" #include "qapi/qmp/qdict.h" #include "block/block.h" #include "qemu/readline.h" @@ -39,15 +38,13 @@ void monitor_flush(Monitor *mon); int monitor_set_cpu(int cpu_index); int monitor_get_cpu_index(void); -void monitor_set_error(Monitor *mon, QError *qerror); void monitor_read_command(Monitor *mon, int show_prompt); int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, void *opaque); -int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret); - -int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret); -int qmp_object_add(Monitor *mon, const QDict *qdict, QObject **ret); +void qmp_qom_set(QDict *qdict, QObject **ret, Error **errp); +void qmp_qom_get(QDict *qdict, QObject **ret, Error **errp); +void qmp_object_add(QDict *qdict, QObject **ret, Error **errp); void object_add(const char *type, const char *id, const QDict *qdict, Visitor *v, Error **errp); diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 719075283c..50ec2ffc12 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -2,15 +2,16 @@ #define QEMU_QDEV_MONITOR_H #include "hw/qdev-core.h" -#include "monitor/monitor.h" +#include "qemu/typedefs.h" /*** monitor commands ***/ void hmp_info_qtree(Monitor *mon, const QDict *qdict); void hmp_info_qdm(Monitor *mon, const QDict *qdict); void hmp_info_qom_tree(Monitor *mon, const QDict *dict); -int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data); +void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp); + int qdev_device_help(QemuOpts *opts); -DeviceState *qdev_device_add(QemuOpts *opts); +DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); #endif diff --git a/include/net/net.h b/include/net/net.h index 4306252b97..6a6cbef24a 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -197,7 +197,7 @@ void net_cleanup(void); void hmp_host_net_add(Monitor *mon, const QDict *qdict); void hmp_host_net_remove(Monitor *mon, const QDict *qdict); void netdev_add(QemuOpts *opts, Error **errp); -int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret); +void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp); int net_hub_id_for_client(NetClientState *nc, int *id); NetClientState *net_hub_port_find(int hub_id); diff --git a/include/qapi/qmp/qbool.h b/include/qapi/qmp/qbool.h index c4eaab9bb9..4aa6be3b33 100644 --- a/include/qapi/qmp/qbool.h +++ b/include/qapi/qmp/qbool.h @@ -14,16 +14,16 @@ #ifndef QBOOL_H #define QBOOL_H -#include <stdint.h> +#include <stdbool.h> #include "qapi/qmp/qobject.h" typedef struct QBool { QObject_HEAD; - int value; + bool value; } QBool; -QBool *qbool_from_int(int value); -int qbool_get_int(const QBool *qb); +QBool *qbool_from_bool(bool value); +bool qbool_get_bool(const QBool *qb); QBool *qobject_to_qbool(const QObject *obj); #endif /* QBOOL_H */ diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 9fbf68ee0c..a37f4c1567 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -56,13 +56,13 @@ const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry); /* High level helpers */ double qdict_get_double(const QDict *qdict, const char *key); int64_t qdict_get_int(const QDict *qdict, const char *key); -int qdict_get_bool(const QDict *qdict, const char *key); +bool qdict_get_bool(const QDict *qdict, const char *key); QList *qdict_get_qlist(const QDict *qdict, const char *key); QDict *qdict_get_qdict(const QDict *qdict, const char *key); const char *qdict_get_str(const QDict *qdict, const char *key); int64_t qdict_get_try_int(const QDict *qdict, const char *key, int64_t def_value); -int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value); +bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value); const char *qdict_get_try_str(const QDict *qdict, const char *key); void qdict_copy_default(QDict *dst, QDict *src, const char *key); diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h index e5673394d3..842b27ae11 100644 --- a/include/qapi/qmp/qerror.h +++ b/include/qapi/qmp/qerror.h @@ -12,122 +12,98 @@ #ifndef QERROR_H #define QERROR_H -#include "qapi/qmp/qstring.h" -#include "qemu/error-report.h" -#include "qapi/error.h" -#include "qapi-types.h" -#include <stdarg.h> - -typedef struct QError { - QObject_HEAD; - Location loc; - char *err_msg; - ErrorClass err_class; -} QError; - -QString *qerror_human(const QError *qerror); -void qerror_report(ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(2, 3); -void qerror_report_err(Error *err); - /* - * QError class list - * Please keep the definitions in alphabetical order. - * Use scripts/check-qerror.sh to check. + * These macros will go away, please don't use in new code, and do not + * add new ones! */ #define QERR_BASE_NOT_FOUND \ - ERROR_CLASS_GENERIC_ERROR, "Base '%s' not found" + "Base '%s' not found" #define QERR_BLOCK_JOB_NOT_READY \ - ERROR_CLASS_GENERIC_ERROR, "The active block job for device '%s' cannot be completed" + "The active block job for device '%s' cannot be completed" #define QERR_BUS_NO_HOTPLUG \ - ERROR_CLASS_GENERIC_ERROR, "Bus '%s' does not support hotplugging" - -#define QERR_BUS_NOT_FOUND \ - ERROR_CLASS_GENERIC_ERROR, "Bus '%s' not found" + "Bus '%s' does not support hotplugging" #define QERR_DEVICE_HAS_NO_MEDIUM \ - ERROR_CLASS_GENERIC_ERROR, "Device '%s' has no medium" + "Device '%s' has no medium" #define QERR_DEVICE_INIT_FAILED \ - ERROR_CLASS_GENERIC_ERROR, "Device '%s' could not be initialized" + "Device '%s' could not be initialized" #define QERR_DEVICE_IN_USE \ - ERROR_CLASS_GENERIC_ERROR, "Device '%s' is in use" + "Device '%s' is in use" #define QERR_DEVICE_NO_HOTPLUG \ - ERROR_CLASS_GENERIC_ERROR, "Device '%s' does not support hotplugging" - -#define QERR_DEVICE_NOT_FOUND \ - ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found" + "Device '%s' does not support hotplugging" #define QERR_FD_NOT_FOUND \ - ERROR_CLASS_GENERIC_ERROR, "File descriptor named '%s' not found" + "File descriptor named '%s' not found" #define QERR_FD_NOT_SUPPLIED \ - ERROR_CLASS_GENERIC_ERROR, "No file descriptor supplied via SCM_RIGHTS" + "No file descriptor supplied via SCM_RIGHTS" #define QERR_FEATURE_DISABLED \ - ERROR_CLASS_GENERIC_ERROR, "The feature '%s' is not enabled" + "The feature '%s' is not enabled" #define QERR_INVALID_BLOCK_FORMAT \ - ERROR_CLASS_GENERIC_ERROR, "Invalid block format '%s'" + "Invalid block format '%s'" #define QERR_INVALID_PARAMETER \ - ERROR_CLASS_GENERIC_ERROR, "Invalid parameter '%s'" + "Invalid parameter '%s'" #define QERR_INVALID_PARAMETER_TYPE \ - ERROR_CLASS_GENERIC_ERROR, "Invalid parameter type for '%s', expected: %s" + "Invalid parameter type for '%s', expected: %s" #define QERR_INVALID_PARAMETER_VALUE \ - ERROR_CLASS_GENERIC_ERROR, "Parameter '%s' expects %s" + "Parameter '%s' expects %s" #define QERR_INVALID_PASSWORD \ - ERROR_CLASS_GENERIC_ERROR, "Password incorrect" + "Password incorrect" #define QERR_IO_ERROR \ - ERROR_CLASS_GENERIC_ERROR, "An IO error has occurred" + "An IO error has occurred" #define QERR_JSON_PARSING \ - ERROR_CLASS_GENERIC_ERROR, "Invalid JSON syntax" + "Invalid JSON syntax" #define QERR_MIGRATION_ACTIVE \ - ERROR_CLASS_GENERIC_ERROR, "There's a migration process in progress" + "There's a migration process in progress" #define QERR_MISSING_PARAMETER \ - ERROR_CLASS_GENERIC_ERROR, "Parameter '%s' is missing" + "Parameter '%s' is missing" #define QERR_PERMISSION_DENIED \ - ERROR_CLASS_GENERIC_ERROR, "Insufficient permission to perform this operation" + "Insufficient permission to perform this operation" #define QERR_PROPERTY_VALUE_BAD \ - ERROR_CLASS_GENERIC_ERROR, "Property '%s.%s' doesn't take value '%s'" + "Property '%s.%s' doesn't take value '%s'" #define QERR_PROPERTY_VALUE_OUT_OF_RANGE \ - ERROR_CLASS_GENERIC_ERROR, "Property %s.%s doesn't take value %" PRId64 " (minimum: %" PRId64 ", maximum: %" PRId64 ")" + "Property %s.%s doesn't take value %" PRId64 " (minimum: %" PRId64 ", maximum: %" PRId64 ")" #define QERR_QGA_COMMAND_FAILED \ - ERROR_CLASS_GENERIC_ERROR, "Guest agent command failed, error was '%s'" + "Guest agent command failed, error was '%s'" #define QERR_QMP_BAD_INPUT_OBJECT \ - ERROR_CLASS_GENERIC_ERROR, "Expected '%s' in QMP input" + "Expected '%s' in QMP input" #define QERR_QMP_BAD_INPUT_OBJECT_MEMBER \ - ERROR_CLASS_GENERIC_ERROR, "QMP input object member '%s' expects '%s'" + "QMP input object member '%s' expects '%s'" #define QERR_QMP_EXTRA_MEMBER \ - ERROR_CLASS_GENERIC_ERROR, "QMP input object member '%s' is unexpected" + "QMP input object member '%s' is unexpected" #define QERR_SET_PASSWD_FAILED \ - ERROR_CLASS_GENERIC_ERROR, "Could not set password" + "Could not set password" #define QERR_UNDEFINED_ERROR \ - ERROR_CLASS_GENERIC_ERROR, "An undefined error has occurred" + "An undefined error has occurred" #define QERR_UNKNOWN_BLOCK_FORMAT_FEATURE \ - ERROR_CLASS_GENERIC_ERROR, "'%s' uses a %s feature which is not supported by this qemu version: %s" + "'%s' uses a %s feature which is not supported by this qemu version: %s" #define QERR_UNSUPPORTED \ - ERROR_CLASS_GENERIC_ERROR, "this feature or command is not currently supported" + "this feature or command is not currently supported" #endif /* QERROR_H */ diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index 84b2d9fef5..260d2ed3cc 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -44,7 +44,6 @@ typedef enum { QTYPE_QLIST, QTYPE_QFLOAT, QTYPE_QBOOL, - QTYPE_QERROR, QTYPE_MAX, } qtype_code; diff --git a/include/qemu/log.h b/include/qemu/log.h index 195f665c4b..f880e66dbc 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -104,10 +104,10 @@ static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags) #ifdef NEED_CPU_H /* disas() and target_disas() to qemu_logfile: */ -static inline void log_target_disas(CPUArchState *env, target_ulong start, +static inline void log_target_disas(CPUState *cpu, target_ulong start, target_ulong len, int flags) { - target_disas(qemu_logfile, env, start, len, flags); + target_disas(qemu_logfile, cpu, start, len, flags); } static inline void log_disas(void *code, unsigned long size) diff --git a/include/qemu/option.h b/include/qemu/option.h index ac0e43b7e5..57e51c9628 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -119,7 +119,10 @@ void qemu_opts_del(QemuOpts *opts); void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp); void qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname, Error **errp); -QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev); +QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, + bool permit_abbrev); +QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, + bool permit_abbrev, Error **errp); void qemu_opts_set_defaults(QemuOptsList *list, const char *params, int permit_abbrev); QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 7992ece72a..c174b5cbdd 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -28,7 +28,6 @@ int inet_aton(const char *cp, struct in_addr *ia); #include "qemu/option.h" #include "qapi/error.h" -#include "qapi/qmp/qerror.h" #include "qapi-types.h" extern QemuOptsList socket_optslist; diff --git a/include/sysemu/balloon.h b/include/sysemu/balloon.h index 0345e01efb..17fe30070d 100644 --- a/include/sysemu/balloon.h +++ b/include/sysemu/balloon.h @@ -14,7 +14,6 @@ #ifndef _QEMU_BALLOON_H #define _QEMU_BALLOON_H -#include "monitor/monitor.h" #include "qapi-types.h" typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target); diff --git a/include/ui/console.h b/include/ui/console.h index de92523bbb..047a2b4640 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -5,7 +5,7 @@ #include "qom/object.h" #include "qapi/qmp/qdict.h" #include "qemu/notify.h" -#include "monitor/monitor.h" +#include "qemu/typedefs.h" #include "qapi-types.h" #include "qapi/error.h" @@ -369,7 +369,7 @@ char *vnc_display_local_addr(const char *id); #ifdef CONFIG_VNC int vnc_display_password(const char *id, const char *password); int vnc_display_pw_expire(const char *id, time_t expires); -QemuOpts *vnc_parse_func(const char *str); +QemuOpts *vnc_parse(const char *str, Error **errp); int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp); #else static inline int vnc_display_password(const char *id, const char *password) diff --git a/include/ui/qemu-spice.h b/include/ui/qemu-spice.h index 42db3c1645..0dff4229fc 100644 --- a/include/ui/qemu-spice.h +++ b/include/ui/qemu-spice.h @@ -26,7 +26,6 @@ #include "qemu/option.h" #include "qemu/config-file.h" -#include "monitor/monitor.h" extern int using_spice; @@ -54,7 +53,6 @@ static inline CharDriverState *qemu_chr_open_spice_port(const char *name) #endif #else /* CONFIG_SPICE */ -#include "monitor/monitor.h" #define using_spice 0 #define spice_displays 0 diff --git a/migration/migration.c b/migration/migration.c index b04b4571a8..c6ac08a0cb 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -14,12 +14,13 @@ */ #include "qemu-common.h" +#include "qemu/error-report.h" #include "qemu/main-loop.h" #include "migration/migration.h" -#include "monitor/monitor.h" #include "migration/qemu-file.h" #include "sysemu/sysemu.h" #include "block/block.h" +#include "qapi/qmp/qerror.h" #include "qemu/sockets.h" #include "migration/block.h" #include "qemu/thread.h" @@ -337,7 +338,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, if (s->state == MIGRATION_STATUS_ACTIVE || s->state == MIGRATION_STATUS_SETUP) { - error_set(errp, QERR_MIGRATION_ACTIVE); + error_setg(errp, QERR_MIGRATION_ACTIVE); return; } @@ -356,22 +357,22 @@ void qmp_migrate_set_parameters(bool has_compress_level, MigrationState *s = migrate_get_current(); if (has_compress_level && (compress_level < 0 || compress_level > 9)) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level", - "is invalid, it should be in the range of 0 to 9"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level", + "is invalid, it should be in the range of 0 to 9"); return; } if (has_compress_threads && (compress_threads < 1 || compress_threads > 255)) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, - "compress_threads", - "is invalid, it should be in the range of 1 to 255"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "compress_threads", + "is invalid, it should be in the range of 1 to 255"); return; } if (has_decompress_threads && (decompress_threads < 1 || decompress_threads > 255)) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, - "decompress_threads", - "is invalid, it should be in the range of 1 to 255"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "decompress_threads", + "is invalid, it should be in the range of 1 to 255"); return; } @@ -573,7 +574,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, if (s->state == MIGRATION_STATUS_ACTIVE || s->state == MIGRATION_STATUS_SETUP || s->state == MIGRATION_STATUS_CANCELLING) { - error_set(errp, QERR_MIGRATION_ACTIVE); + error_setg(errp, QERR_MIGRATION_ACTIVE); return; } @@ -608,7 +609,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, fd_start_outgoing_migration(s, p, &local_err); #endif } else { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", + "a valid migration protocol"); s->state = MIGRATION_STATUS_FAILED; return; } @@ -632,22 +634,22 @@ void qmp_migrate_set_cache_size(int64_t value, Error **errp) /* Check for truncation */ if (value != (size_t)value) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "exceeding address space"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "exceeding address space"); return; } /* Cache should not be larger than guest ram size */ if (value > ram_bytes_total()) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "exceeds guest ram size "); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "exceeds guest ram size "); return; } new_size = xbzrle_cache_resize(value); if (new_size < 0) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "is smaller than page size"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "is smaller than page size"); return; } diff --git a/migration/qemu-file-buf.c b/migration/qemu-file-buf.c index 16a51a1e17..2de9330ca5 100644 --- a/migration/qemu-file-buf.c +++ b/migration/qemu-file-buf.c @@ -26,6 +26,7 @@ * THE SOFTWARE. */ #include "qemu-common.h" +#include "qemu/error-report.h" #include "qemu/iov.h" #include "qemu/sockets.h" #include "block/coroutine.h" diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 965a757772..557c1c1a62 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -23,6 +23,7 @@ */ #include <zlib.h> #include "qemu-common.h" +#include "qemu/error-report.h" #include "qemu/iov.h" #include "qemu/sockets.h" #include "block/coroutine.h" diff --git a/migration/rdma.c b/migration/rdma.c index cf5de7e2ae..b777273b59 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -15,6 +15,7 @@ #include "migration/migration.h" #include "migration/qemu-file.h" #include "exec/cpu-common.h" +#include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" #include "qemu/bitmap.h" diff --git a/migration/savevm.c b/migration/savevm.c index 2091882196..9e0e286797 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -37,6 +37,8 @@ #include "qemu/timer.h" #include "audio/audio.h" #include "migration/migration.h" +#include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qemu/sockets.h" #include "qemu/queue.h" #include "sysemu/cpus.h" @@ -1307,7 +1309,7 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) ret = qemu_save_device_state(f); qemu_fclose(f); if (ret < 0) { - error_set(errp, QERR_IO_ERROR); + error_setg(errp, QERR_IO_ERROR); } the_end: @@ -49,6 +49,7 @@ #include "sysemu/kvm.h" #include "qemu/acl.h" #include "sysemu/tpm.h" +#include "qapi/qmp/qerror.h" #include "qapi/qmp/qint.h" #include "qapi/qmp/qfloat.h" #include "qapi/qmp/qlist.h" @@ -81,9 +82,6 @@ #endif #include "hw/lm32/lm32_pic.h" -//#define DEBUG -//#define DEBUG_COMPLETION - /* * Supported types: * @@ -125,7 +123,7 @@ typedef struct mon_cmd_t { const char *help; union { void (*cmd)(Monitor *mon, const QDict *qdict); - int (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data); + void (*cmd_new)(QDict *params, QObject **ret_data, Error **errp); } mhandler; /* @sub_table is a list of 2nd level of commands. If it do not exist, * mhandler should be used. If it exist, sub_table[?].mhandler should be @@ -205,7 +203,6 @@ struct Monitor { BlockCompletionFunc *password_completion_cb; void *password_opaque; mon_cmd_t *cmd_table; - QError *error; QLIST_HEAD(,mon_fd_t) fds; QLIST_ENTRY(Monitor) entry; }; @@ -566,11 +563,9 @@ static void monitor_qapi_event_init(void) qmp_event_set_func_emit(monitor_qapi_event_queue); } -static int do_qmp_capabilities(Monitor *mon, const QDict *params, - QObject **ret_data) +static void qmp_capabilities(QDict *params, QObject **ret_data, Error **errp) { - mon->qmp.in_command_mode = true; - return 0; + cur_mon->qmp.in_command_mode = true; } static void handle_hmp_command(Monitor *mon, const char *cmdline); @@ -606,8 +601,8 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index, int ret = monitor_set_cpu(cpu_index); if (ret < 0) { cur_mon = old_mon; - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", - "a CPU number"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", + "a CPU number"); goto out; } } @@ -942,28 +937,28 @@ int monitor_set_cpu(int cpu_index) return 0; } -static CPUArchState *mon_get_cpu(void) +static CPUState *mon_get_cpu(void) { if (!cur_mon->mon_cpu) { monitor_set_cpu(0); } cpu_synchronize_state(cur_mon->mon_cpu); - return cur_mon->mon_cpu->env_ptr; + return cur_mon->mon_cpu; +} + +static CPUArchState *mon_get_cpu_env(void) +{ + return mon_get_cpu()->env_ptr; } int monitor_get_cpu_index(void) { - CPUState *cpu = ENV_GET_CPU(mon_get_cpu()); - return cpu->cpu_index; + return mon_get_cpu()->cpu_index; } static void hmp_info_registers(Monitor *mon, const QDict *qdict) { - CPUState *cpu; - CPUArchState *env; - env = mon_get_cpu(); - cpu = ENV_GET_CPU(env); - cpu_dump_state(cpu, (FILE *)mon, monitor_fprintf, CPU_DUMP_FPU); + cpu_dump_state(mon_get_cpu(), (FILE *)mon, monitor_fprintf, CPU_DUMP_FPU); } static void hmp_info_jit(Monitor *mon, const QDict *qdict) @@ -996,12 +991,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict) static void hmp_info_cpustats(Monitor *mon, const QDict *qdict) { - CPUState *cpu; - CPUArchState *env; - - env = mon_get_cpu(); - cpu = ENV_GET_CPU(env); - cpu_dump_statistics(cpu, (FILE *)mon, &monitor_fprintf, 0); + cpu_dump_statistics(mon_get_cpu(), (FILE *)mon, &monitor_fprintf, 0); } static void hmp_info_trace_events(Monitor *mon, const QDict *qdict) @@ -1029,7 +1019,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname, } if (!has_port && !has_tls_port) { - error_set(errp, QERR_MISSING_PARAMETER, "port/tls-port"); + error_setg(errp, QERR_MISSING_PARAMETER, "port/tls-port"); return; } @@ -1037,13 +1027,13 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname, has_port ? port : -1, has_tls_port ? tls_port : -1, cert_subject)) { - error_set(errp, QERR_UNDEFINED_ERROR); + error_setg(errp, QERR_UNDEFINED_ERROR); return; } return; } - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice"); } static void hmp_logfile(Monitor *mon, const QDict *qdict) @@ -1134,16 +1124,14 @@ static void monitor_printc(Monitor *mon, int c) static void memory_dump(Monitor *mon, int count, int format, int wsize, hwaddr addr, int is_physical) { - CPUArchState *env; int l, line_size, i, max_digits, len; uint8_t buf[16]; uint64_t v; if (format == 'i') { - int flags; - flags = 0; - env = mon_get_cpu(); + int flags = 0; #ifdef TARGET_I386 + CPUArchState *env = mon_get_cpu_env(); if (wsize == 2) { flags = 1; } else if (wsize == 4) { @@ -1164,10 +1152,11 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, } #endif #ifdef TARGET_PPC + CPUArchState *env = mon_get_cpu_env(); flags = msr_le << 16; flags |= env->bfd_mach; #endif - monitor_disas(mon, env, addr, count, is_physical, flags); + monitor_disas(mon, mon_get_cpu(), addr, count, is_physical, flags); return; } @@ -1206,8 +1195,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, if (is_physical) { cpu_physical_memory_read(addr, buf, l); } else { - env = mon_get_cpu(); - if (cpu_memory_rw_debug(ENV_GET_CPU(env), addr, buf, l, 0) < 0) { + if (cpu_memory_rw_debug(mon_get_cpu(), addr, buf, l, 0) < 0) { monitor_printf(mon, " Cannot access memory\n"); break; } @@ -1586,7 +1574,7 @@ static void hmp_info_tlb(Monitor *mon, const QDict *qdict) { CPUArchState *env; - env = mon_get_cpu(); + env = mon_get_cpu_env(); if (!(env->cr[0] & CR0_PG_MASK)) { monitor_printf(mon, "PG disabled\n"); @@ -1809,7 +1797,7 @@ static void hmp_info_mem(Monitor *mon, const QDict *qdict) { CPUArchState *env; - env = mon_get_cpu(); + env = mon_get_cpu_env(); if (!(env->cr[0] & CR0_PG_MASK)) { monitor_printf(mon, "PG disabled\n"); @@ -1846,7 +1834,7 @@ static void print_tlb(Monitor *mon, int idx, tlb_t *tlb) static void hmp_info_tlb(Monitor *mon, const QDict *qdict) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); int i; monitor_printf (mon, "ITLB:\n"); @@ -1862,7 +1850,7 @@ static void hmp_info_tlb(Monitor *mon, const QDict *qdict) #if defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_XTENSA) static void hmp_info_tlb(Monitor *mon, const QDict *qdict) { - CPUArchState *env1 = mon_get_cpu(); + CPUArchState *env1 = mon_get_cpu_env(); dump_mmu((FILE*)mon, (fprintf_function)monitor_printf, env1); } @@ -2091,7 +2079,7 @@ static void hmp_mce(Monitor *mon, const QDict *qdict) uint64_t misc = qdict_get_int(qdict, "misc"); int flags = MCE_INJECT_UNCOND_AO; - if (qdict_get_try_bool(qdict, "broadcast", 0)) { + if (qdict_get_try_bool(qdict, "broadcast", false)) { flags |= MCE_INJECT_BROADCAST; } cs = qemu_get_cpu(cpu_index); @@ -2110,14 +2098,14 @@ void qmp_getfd(const char *fdname, Error **errp) fd = qemu_chr_fe_get_msgfd(cur_mon->chr); if (fd == -1) { - error_set(errp, QERR_FD_NOT_SUPPLIED); + error_setg(errp, QERR_FD_NOT_SUPPLIED); return; } if (qemu_isdigit(fdname[0])) { close(fd); - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname", - "a name not starting with a digit"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdname", + "a name not starting with a digit"); return; } @@ -2154,7 +2142,7 @@ void qmp_closefd(const char *fdname, Error **errp) return; } - error_set(errp, QERR_FD_NOT_FOUND, fdname); + error_setg(errp, QERR_FD_NOT_FOUND, fdname); } static void hmp_loadvm(Monitor *mon, const QDict *qdict) @@ -2235,7 +2223,7 @@ AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque, fd = qemu_chr_fe_get_msgfd(mon->chr); if (fd == -1) { - error_set(errp, QERR_FD_NOT_SUPPLIED); + error_setg(errp, QERR_FD_NOT_SUPPLIED); goto error; } @@ -2287,7 +2275,7 @@ error: } else { snprintf(fd_str, sizeof(fd_str), "fdset-id:%" PRId64, fdset_id); } - error_set(errp, QERR_FD_NOT_FOUND, fd_str); + error_setg(errp, QERR_FD_NOT_FOUND, fd_str); } FdsetInfoList *qmp_query_fdsets(Error **errp) @@ -2355,8 +2343,8 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id, if (has_fdset_id) { if (fdset_id < 0) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id", - "a non-negative value"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id", + "a non-negative value"); return NULL; } /* Use specified fdset ID */ @@ -2923,7 +2911,7 @@ typedef struct MonitorDef { #if defined(TARGET_I386) static target_long monitor_get_pc (const struct MonitorDef *md, int val) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); return env->eip + env->segs[R_CS].base; } #endif @@ -2931,7 +2919,7 @@ static target_long monitor_get_pc (const struct MonitorDef *md, int val) #if defined(TARGET_PPC) static target_long monitor_get_ccr (const struct MonitorDef *md, int val) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); unsigned int u; int i; @@ -2944,31 +2932,31 @@ static target_long monitor_get_ccr (const struct MonitorDef *md, int val) static target_long monitor_get_msr (const struct MonitorDef *md, int val) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); return env->msr; } static target_long monitor_get_xer (const struct MonitorDef *md, int val) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); return env->xer; } static target_long monitor_get_decr (const struct MonitorDef *md, int val) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); return cpu_ppc_load_decr(env); } static target_long monitor_get_tbu (const struct MonitorDef *md, int val) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); return cpu_ppc_load_tbu(env); } static target_long monitor_get_tbl (const struct MonitorDef *md, int val) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); return cpu_ppc_load_tbl(env); } #endif @@ -2977,7 +2965,7 @@ static target_long monitor_get_tbl (const struct MonitorDef *md, int val) #ifndef TARGET_SPARC64 static target_long monitor_get_psr (const struct MonitorDef *md, int val) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); return cpu_get_psr(env); } @@ -2985,7 +2973,7 @@ static target_long monitor_get_psr (const struct MonitorDef *md, int val) static target_long monitor_get_reg(const struct MonitorDef *md, int val) { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); return env->regwptr[val]; } #endif @@ -3321,7 +3309,7 @@ static int get_monitor_def(target_long *pval, const char *name) if (md->get_value) { *pval = md->get_value(md, md->offset); } else { - CPUArchState *env = mon_get_cpu(); + CPUArchState *env = mon_get_cpu_env(); ptr = (uint8_t *)env + md->offset; switch(md->type) { case MD_I32: @@ -3637,43 +3625,32 @@ static const mon_cmd_t *qmp_find_cmd(const char *cmdname) } /* - * Parse @cmdline according to command table @table. - * If @cmdline is blank, return NULL. - * If it can't be parsed, report to @mon, and return NULL. - * Else, insert command arguments into @qdict, and return the command. - * If a sub-command table exists, and if @cmdline contains an additional string - * for a sub-command, this function will try to search the sub-command table. - * If no additional string for a sub-command is present, this function will - * return the command found in @table. - * Do not assume the returned command points into @table! It doesn't - * when the command is a sub-command. + * Parse command name from @cmdp according to command table @table. + * If blank, return NULL. + * Else, if no valid command can be found, report to @mon, and return + * NULL. + * Else, change @cmdp to point right behind the name, and return its + * command table entry. + * Do not assume the return value points into @table! It doesn't when + * the command is found in a sub-command table. */ static const mon_cmd_t *monitor_parse_command(Monitor *mon, - const char *cmdline, - int start, - mon_cmd_t *table, - QDict *qdict) + const char **cmdp, + mon_cmd_t *table) { - const char *p, *typestr; - int c; + const char *p; const mon_cmd_t *cmd; char cmdname[256]; - char buf[1024]; - char *key; - -#ifdef DEBUG - monitor_printf(mon, "command='%s', start='%d'\n", cmdline, start); -#endif /* extract the command name */ - p = get_command_name(cmdline + start, cmdname, sizeof(cmdname)); + p = get_command_name(*cmdp, cmdname, sizeof(cmdname)); if (!p) return NULL; cmd = search_dispatch_table(table, cmdname); if (!cmd) { monitor_printf(mon, "unknown command: '%.*s'\n", - (int)(p - cmdline), cmdline); + (int)(p - *cmdp), *cmdp); return NULL; } @@ -3681,16 +3658,34 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, while (qemu_isspace(*p)) { p++; } + + *cmdp = p; /* search sub command */ - if (cmd->sub_table != NULL) { - /* check if user set additional command */ - if (*p == '\0') { - return cmd; - } - return monitor_parse_command(mon, cmdline, p - cmdline, - cmd->sub_table, qdict); + if (cmd->sub_table != NULL && *p != '\0') { + return monitor_parse_command(mon, cmdp, cmd->sub_table); } + return cmd; +} + +/* + * Parse arguments for @cmd. + * If it can't be parsed, report to @mon, and return NULL. + * Else, insert command arguments into a QDict, and return it. + * Note: On success, caller has to free the QDict structure. + */ + +static QDict *monitor_parse_arguments(Monitor *mon, + const char **endp, + const mon_cmd_t *cmd) +{ + const char *typestr; + char *key; + int c; + const char *p = *endp; + char buf[1024]; + QDict *qdict = qdict_new(); + /* parse the parameters */ typestr = cmd->args_type; for(;;) { @@ -3720,14 +3715,14 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, switch(c) { case 'F': monitor_printf(mon, "%s: filename expected\n", - cmdname); + cmd->name); break; case 'B': monitor_printf(mon, "%s: block device name expected\n", - cmdname); + cmd->name); break; default: - monitor_printf(mon, "%s: string expected\n", cmdname); + monitor_printf(mon, "%s: string expected\n", cmd->name); break; } goto fail; @@ -3752,7 +3747,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, if (get_str(buf, sizeof(buf), &p) < 0) { goto fail; } - opts = qemu_opts_parse(opts_list, buf, 1); + opts = qemu_opts_parse_noisily(opts_list, buf, true); if (!opts) { goto fail; } @@ -3869,7 +3864,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, goto fail; /* Check if 'i' is greater than 32-bit */ if ((c == 'i') && ((val >> 32) & 0xffffffff)) { - monitor_printf(mon, "\'%s\' has failed: ", cmdname); + monitor_printf(mon, "\'%s\' has failed: ", cmd->name); monitor_printf(mon, "integer is for 32-bit values\n"); goto fail; } else if (c == 'M') { @@ -3940,7 +3935,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, case 'b': { const char *beg; - int val; + bool val; while (qemu_isspace(*p)) { p++; @@ -3950,14 +3945,14 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, p++; } if (p - beg == 2 && !memcmp(beg, "on", p - beg)) { - val = 1; + val = true; } else if (p - beg == 3 && !memcmp(beg, "off", p - beg)) { - val = 0; + val = false; } else { monitor_printf(mon, "Expected 'on' or 'off'\n"); goto fail; } - qdict_put(qdict, key, qbool_from_int(val)); + qdict_put(qdict, key, qbool_from_bool(val)); } break; case '-': @@ -3977,7 +3972,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, if(!is_valid_option(p, typestr)) { monitor_printf(mon, "%s: unsupported option -%c\n", - cmdname, *p); + cmd->name, *p); goto fail; } else { skip_key = 1; @@ -3988,7 +3983,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, } else { /* has option */ p++; - qdict_put(qdict, key, qbool_from_int(1)); + qdict_put(qdict, key, qbool_from_bool(true)); } } } @@ -4011,8 +4006,8 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, len = strlen(p); if (len <= 0) { monitor_printf(mon, "%s: string expected\n", - cmdname); - break; + cmd->name); + goto fail; } qdict_put(qdict, key, qstring_from_str(p)); p += len; @@ -4020,7 +4015,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, break; default: bad_type: - monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c); + monitor_printf(mon, "%s: unknown type '%c'\n", cmd->name, c); goto fail; } g_free(key); @@ -4031,39 +4026,36 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, p++; if (*p != '\0') { monitor_printf(mon, "%s: extraneous characters at the end of line\n", - cmdname); + cmd->name); goto fail; } - return cmd; + return qdict; fail: + QDECREF(qdict); g_free(key); return NULL; } -void monitor_set_error(Monitor *mon, QError *qerror) -{ - /* report only the first error */ - if (!mon->error) { - mon->error = qerror; - } else { - QDECREF(qerror); - } -} - static void handle_hmp_command(Monitor *mon, const char *cmdline) { QDict *qdict; const mon_cmd_t *cmd; - qdict = qdict_new(); + cmd = monitor_parse_command(mon, &cmdline, mon->cmd_table); + if (!cmd) { + return; + } - cmd = monitor_parse_command(mon, cmdline, 0, mon->cmd_table, qdict); - if (cmd) { - cmd->mhandler.cmd(mon, qdict); + qdict = monitor_parse_arguments(mon, &cmdline, cmd); + if (!qdict) { + monitor_printf(mon, "Try \"help %s\" for more information\n", + cmd->name); + return; } + cmd->mhandler.cmd(mon, qdict); QDECREF(qdict); } @@ -4115,10 +4107,7 @@ static void file_completion(Monitor *mon, const char *input) path[input_path_len] = '\0'; pstrcpy(file_prefix, sizeof(file_prefix), p + 1); } -#ifdef DEBUG_COMPLETION - monitor_printf(mon, "input='%s' path='%s' prefix='%s'\n", - input, path, file_prefix); -#endif + ffs = opendir(path); if (!ffs) return; @@ -4696,14 +4685,6 @@ static void monitor_find_completion(void *opaque, if (parse_cmdline(cmdline, &nb_args, args) < 0) { return; } -#ifdef DEBUG_COMPLETION - { - int i; - for (i = 0; i < nb_args; i++) { - monitor_printf(mon, "arg%d = '%s'\n", i, args[i]); - } - } -#endif /* if the line ends with a space, it means we want to complete the next arg */ @@ -4732,7 +4713,7 @@ static int monitor_can_read(void *opaque) static bool invalid_qmp_mode(const Monitor *mon, const mon_cmd_t *cmd, Error **errp) { - bool is_cap = cmd->mhandler.cmd_new == do_qmp_capabilities; + bool is_cap = cmd->mhandler.cmd_new == qmp_capabilities; if (is_cap && mon->qmp.in_command_mode) { error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, @@ -4778,7 +4759,7 @@ static void check_client_args_type(const QDict *client_args, continue; } /* client arg doesn't exist */ - error_set(errp, QERR_INVALID_PARAMETER, client_arg_name); + error_setg(errp, QERR_INVALID_PARAMETER, client_arg_name); return; } @@ -4791,8 +4772,8 @@ static void check_client_args_type(const QDict *client_args, case 'B': case 's': if (qobject_type(client_arg) != QTYPE_QSTRING) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, - client_arg_name, "string"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, + client_arg_name, "string"); return; } break; @@ -4801,24 +4782,24 @@ static void check_client_args_type(const QDict *client_args, case 'M': case 'o': if (qobject_type(client_arg) != QTYPE_QINT) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, - client_arg_name, "int"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, + client_arg_name, "int"); return; } break; case 'T': if (qobject_type(client_arg) != QTYPE_QINT && qobject_type(client_arg) != QTYPE_QFLOAT) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, - client_arg_name, "number"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, + client_arg_name, "number"); return; } break; case 'b': case '-': if (qobject_type(client_arg) != QTYPE_QBOOL) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, - client_arg_name, "bool"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, + client_arg_name, "bool"); return; } break; @@ -4861,7 +4842,7 @@ static void check_mandatory_args(const QDict *cmd_args, } else if (qstring_get_str(type)[0] != '-' && qstring_get_str(type)[1] != '?' && !qdict_haskey(client_args, cmd_arg_name)) { - error_set(errp, QERR_MISSING_PARAMETER, cmd_arg_name); + error_setg(errp, QERR_MISSING_PARAMETER, cmd_arg_name); return; } } @@ -4959,7 +4940,7 @@ static QDict *qmp_check_input_obj(QObject *input_obj, Error **errp) QDict *input_dict; if (qobject_type(input_obj) != QTYPE_QDICT) { - error_set(errp, QERR_QMP_BAD_INPUT_OBJECT, "object"); + error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT, "object"); return NULL; } @@ -4971,27 +4952,27 @@ static QDict *qmp_check_input_obj(QObject *input_obj, Error **errp) if (!strcmp(arg_name, "execute")) { if (qobject_type(arg_obj) != QTYPE_QSTRING) { - error_set(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, - "execute", "string"); + error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, + "execute", "string"); return NULL; } has_exec_key = 1; } else if (!strcmp(arg_name, "arguments")) { if (qobject_type(arg_obj) != QTYPE_QDICT) { - error_set(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, - "arguments", "object"); + error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, + "arguments", "object"); return NULL; } } else if (!strcmp(arg_name, "id")) { /* Any string is acceptable as "id", so nothing to check */ } else { - error_set(errp, QERR_QMP_EXTRA_MEMBER, arg_name); + error_setg(errp, QERR_QMP_EXTRA_MEMBER, arg_name); return NULL; } } if (!has_exec_key) { - error_set(errp, QERR_QMP_BAD_INPUT_OBJECT, "execute"); + error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT, "execute"); return NULL; } @@ -5013,7 +4994,7 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) obj = json_parser_parse(tokens, NULL); if (!obj) { // FIXME: should be triggered in json_parser_parse() - error_set(&local_err, QERR_JSON_PARSING); + error_setg(&local_err, QERR_JSON_PARSING); goto err_out; } @@ -5051,23 +5032,11 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) goto err_out; } - if (cmd->mhandler.cmd_new(mon, args, &data)) { - /* Command failed... */ - if (!mon->error) { - /* ... without setting an error, so make one up */ - error_set(&local_err, QERR_UNDEFINED_ERROR); - } - } - if (mon->error) { - error_set(&local_err, mon->error->err_class, "%s", - mon->error->err_msg); - } + cmd->mhandler.cmd_new(args, &data, &local_err); err_out: monitor_protocol_emitter(mon, data, local_err); qobject_decref(data); - QDECREF(mon->error); - mon->error = NULL; QDECREF(input); QDECREF(args); } @@ -5133,7 +5102,7 @@ static QObject *get_qmp_greeting(void) { QObject *ver = NULL; - qmp_marshal_input_query_version(NULL, NULL, &ver); + qmp_marshal_input_query_version(NULL, &ver, NULL); return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver); } @@ -5389,6 +5358,6 @@ QemuOptsList qemu_mon_opts = { #ifndef TARGET_I386 void qmp_rtc_reset_reinjection(Error **errp) { - error_set(errp, QERR_FEATURE_DISABLED, "rtc-reset-reinjection"); + error_setg(errp, QERR_FEATURE_DISABLED, "rtc-reset-reinjection"); } #endif diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 356dae2b72..4f9bceecc9 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -28,7 +28,6 @@ #include "config-host.h" #include "net/net.h" #include "clients.h" -#include "monitor/monitor.h" #include "qemu-common.h" #include "qemu/error-report.h" #include "qemu/option.h" @@ -32,6 +32,8 @@ #include "monitor/monitor.h" #include "qemu-common.h" +#include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qemu/sockets.h" #include "qemu/config-file.h" #include "qmp-commands.h" @@ -945,16 +947,16 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) break; default: - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "type", - "a netdev backend type"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", + "a netdev backend type"); return -1; } } else { u.net = object; opts = u.net->opts; if (opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "type", - "a net type"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", + "a net type"); return -1; } /* missing optional values have been initialized to "all bits zero" */ @@ -975,8 +977,8 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) if (net_client_init_fun[opts->kind](opts, name, peer, errp) < 0) { /* FIXME drop when all init functions store an Error */ if (errp && !*errp) { - error_set(errp, QERR_DEVICE_INIT_FAILED, - NetClientOptionsKind_lookup[opts->kind]); + error_setg(errp, QERR_DEVICE_INIT_FAILED, + NetClientOptionsKind_lookup[opts->kind]); } return -1; } @@ -1049,7 +1051,8 @@ void hmp_host_net_add(Monitor *mon, const QDict *qdict) return; } - opts = qemu_opts_parse(qemu_find_opts("net"), opts_str ? opts_str : "", 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("net"), + opts_str ? opts_str : "", false); if (!opts) { return; } @@ -1089,7 +1092,7 @@ void netdev_add(QemuOpts *opts, Error **errp) net_client_init(opts, 1, errp); } -int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret) +void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp) { Error *local_err = NULL; QemuOptsList *opts_list; @@ -1097,26 +1100,22 @@ int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret) opts_list = qemu_find_opts_err("netdev", &local_err); if (local_err) { - goto exit_err; + goto out; } opts = qemu_opts_from_qdict(opts_list, qdict, &local_err); if (local_err) { - goto exit_err; + goto out; } netdev_add(opts, &local_err); if (local_err) { qemu_opts_del(opts); - goto exit_err; + goto out; } - return 0; - -exit_err: - qerror_report_err(local_err); - error_free(local_err); - return -1; +out: + error_propagate(errp, local_err); } void qmp_netdev_del(const char *id, Error **errp) @@ -1126,7 +1125,8 @@ void qmp_netdev_del(const char *id, Error **errp) nc = qemu_find_netdev(id); if (!nc) { - error_set(errp, QERR_DEVICE_NOT_FOUND, id); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", id); return; } @@ -1237,7 +1237,8 @@ void qmp_set_link(const char *name, bool up, Error **errp) MAX_QUEUE_NUM); if (queues == 0) { - error_set(errp, QERR_DEVICE_NOT_FOUND, name); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", name); return; } nc = ncs[0]; @@ -1412,7 +1413,7 @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg) } #endif - if (!qemu_opts_parse(opts_list, optarg, 1)) { + if (!qemu_opts_parse_noisily(opts_list, optarg, true)) { return -1; } diff --git a/net/slirp.c b/net/slirp.c index 35338376f7..7657b38fdf 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -33,6 +33,7 @@ #include "clients.h" #include "hub.h" #include "monitor/monitor.h" +#include "qemu/error-report.h" #include "qemu/sockets.h" #include "slirp/libslirp.h" #include "sysemu/char.h" @@ -31,7 +31,6 @@ #include "qapi-visit.h" #include "qapi/opts-visitor.h" #include "qapi/dealloc-visitor.h" -#include "qapi/qmp/qerror.h" #include "hw/boards.h" #include "sysemu/hostmem.h" #include "qmp-commands.h" diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index f2ad6d729a..7ae33b311e 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -173,7 +173,7 @@ opts_end_struct(Visitor *v, Error **errp) const QemuOpt *first; first = g_queue_peek_head(any); - error_set(errp, QERR_INVALID_PARAMETER, first->name); + error_setg(errp, QERR_INVALID_PARAMETER, first->name); } g_hash_table_destroy(ov->unprocessed_opts); ov->unprocessed_opts = NULL; @@ -193,7 +193,7 @@ lookup_distinct(const OptsVisitor *ov, const char *name, Error **errp) list = g_hash_table_lookup(ov->unprocessed_opts, name); if (!list) { - error_set(errp, QERR_MISSING_PARAMETER, name); + error_setg(errp, QERR_MISSING_PARAMETER, name); } return list; } @@ -341,8 +341,8 @@ opts_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) strcmp(opt->str, "n") == 0) { *obj = false; } else { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, - "on|yes|y|off|no|n"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, + "on|yes|y|off|no|n"); return; } } else { @@ -403,9 +403,9 @@ opts_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) } } } - error_set(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, - (ov->list_mode == LM_NONE) ? "an int64 value" : - "an int64 value or range"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, + (ov->list_mode == LM_NONE) ? "an int64 value" : + "an int64 value or range"); } @@ -455,9 +455,9 @@ opts_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp) } } } - error_set(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, - (ov->list_mode == LM_NONE) ? "a uint64 value" : - "a uint64 value or range"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, + (ov->list_mode == LM_NONE) ? "a uint64 value" : + "a uint64 value or range"); } @@ -477,8 +477,8 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) val = strtosz_suffix(opt->str ? opt->str : "", &endptr, STRTOSZ_DEFSUFFIX_B); if (val < 0 || *endptr) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, - "a size value representible as a non-negative int64"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, + "a size value representible as a non-negative int64"); return; } diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index a18ba1670f..5a7c900504 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -110,8 +110,8 @@ void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp) value = *obj; v->type_int(v, &value, name, errp); if (value < 0 || value > UINT8_MAX) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "uint8_t"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", "uint8_t"); return; } *obj = value; @@ -128,8 +128,8 @@ void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp value = *obj; v->type_int(v, &value, name, errp); if (value < 0 || value > UINT16_MAX) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "uint16_t"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", "uint16_t"); return; } *obj = value; @@ -146,8 +146,8 @@ void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp value = *obj; v->type_int(v, &value, name, errp); if (value < 0 || value > UINT32_MAX) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "uint32_t"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", "uint32_t"); return; } *obj = value; @@ -177,8 +177,8 @@ void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp) value = *obj; v->type_int(v, &value, name, errp); if (value < INT8_MIN || value > INT8_MAX) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "int8_t"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", "int8_t"); return; } *obj = value; @@ -195,8 +195,8 @@ void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp) value = *obj; v->type_int(v, &value, name, errp); if (value < INT16_MIN || value > INT16_MAX) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "int16_t"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", "int16_t"); return; } *obj = value; @@ -213,8 +213,8 @@ void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp) value = *obj; v->type_int(v, &value, name, errp); if (value < INT32_MIN || value > INT32_MAX) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "int32_t"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", "int32_t"); return; } *obj = value; @@ -271,7 +271,7 @@ void output_type_enum(Visitor *v, int *obj, const char * const strings[], assert(strings); while (strings[i++] != NULL); if (value < 0 || value >= i - 1) { - error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null"); + error_setg(errp, QERR_INVALID_PARAMETER, name ? name : "null"); return; } @@ -303,7 +303,7 @@ void input_type_enum(Visitor *v, int *obj, const char * const strings[], } if (strings[value] == NULL) { - error_set(errp, QERR_INVALID_PARAMETER, enum_str); + error_setg(errp, QERR_INVALID_PARAMETER, enum_str); g_free(enum_str); return; } diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 222742013f..7bcc86080e 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -27,8 +27,8 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp) QDict *dict = NULL; if (qobject_type(request) != QTYPE_QDICT) { - error_set(errp, QERR_QMP_BAD_INPUT_OBJECT, - "request is not a dictionary"); + error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT, + "request is not a dictionary"); return NULL; } @@ -41,19 +41,19 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp) if (!strcmp(arg_name, "execute")) { if (qobject_type(arg_obj) != QTYPE_QSTRING) { - error_set(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "execute", - "string"); + error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "execute", + "string"); return NULL; } has_exec_key = true; } else if (strcmp(arg_name, "arguments")) { - error_set(errp, QERR_QMP_EXTRA_MEMBER, arg_name); + error_setg(errp, QERR_QMP_EXTRA_MEMBER, arg_name); return NULL; } } if (!has_exec_key) { - error_set(errp, QERR_QMP_BAD_INPUT_OBJECT, "execute"); + error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT, "execute"); return NULL; } diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index d8612062f1..e97b8a4282 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -105,7 +105,7 @@ static void qmp_input_pop(QmpInputVisitor *qiv, Error **errp) if (g_hash_table_size(top_ht)) { const char *key; g_hash_table_find(top_ht, always_true, &key); - error_set(errp, QERR_QMP_EXTRA_MEMBER, key); + error_setg(errp, QERR_QMP_EXTRA_MEMBER, key); } g_hash_table_unref(top_ht); } @@ -122,8 +122,8 @@ static void qmp_input_start_struct(Visitor *v, void **obj, const char *kind, Error *err = NULL; if (!qobj || qobject_type(qobj) != QTYPE_QDICT) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "QDict"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "QDict"); return; } @@ -163,8 +163,8 @@ static void qmp_input_start_list(Visitor *v, const char *name, Error **errp) QObject *qobj = qmp_input_get_object(qiv, name, true); if (!qobj || qobject_type(qobj) != QTYPE_QLIST) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "list"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "list"); return; } @@ -215,7 +215,7 @@ static void qmp_input_get_next_type(Visitor *v, int *kind, const int *qobjects, QObject *qobj = qmp_input_get_object(qiv, name, false); if (!qobj) { - error_set(errp, QERR_MISSING_PARAMETER, name ? name : "null"); + error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null"); return; } *kind = qobjects[qobject_type(qobj)]; @@ -228,8 +228,8 @@ static void qmp_input_type_int(Visitor *v, int64_t *obj, const char *name, QObject *qobj = qmp_input_get_object(qiv, name, true); if (!qobj || qobject_type(qobj) != QTYPE_QINT) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "integer"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "integer"); return; } @@ -243,12 +243,12 @@ static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name, QObject *qobj = qmp_input_get_object(qiv, name, true); if (!qobj || qobject_type(qobj) != QTYPE_QBOOL) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "boolean"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "boolean"); return; } - *obj = qbool_get_int(qobject_to_qbool(qobj)); + *obj = qbool_get_bool(qobject_to_qbool(qobj)); } static void qmp_input_type_str(Visitor *v, char **obj, const char *name, @@ -258,8 +258,8 @@ static void qmp_input_type_str(Visitor *v, char **obj, const char *name, QObject *qobj = qmp_input_get_object(qiv, name, true); if (!qobj || qobject_type(qobj) != QTYPE_QSTRING) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "string"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "string"); return; } @@ -274,8 +274,8 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name, if (!qobj || (qobject_type(qobj) != QTYPE_QFLOAT && qobject_type(qobj) != QTYPE_QINT)) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "number"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "number"); return; } diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index 96b338463e..efc19d5841 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -16,7 +16,6 @@ #include "qemu/queue.h" #include "qemu-common.h" #include "qapi/qmp/types.h" -#include "qapi/qmp/qerror.h" typedef struct QStackEntry { @@ -166,7 +165,7 @@ static void qmp_output_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) { QmpOutputVisitor *qov = to_qov(v); - qmp_output_add(qov, name, qbool_from_int(*obj)); + qmp_output_add(qov, name, qbool_from_bool(*obj)); } static void qmp_output_type_str(Visitor *v, char **obj, const char *name, diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index d8a8db02ed..bbd6a5456c 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -185,8 +185,8 @@ static void parse_type_int(Visitor *v, int64_t *obj, const char *name, StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); if (!siv->string) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "integer"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "integer"); return; } @@ -217,8 +217,8 @@ static void parse_type_int(Visitor *v, int64_t *obj, const char *name, return; error: - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, - "an int64 value or range"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, + "an int64 value or range"); } static void parse_type_size(Visitor *v, uint64_t *obj, const char *name, @@ -231,8 +231,8 @@ static void parse_type_size(Visitor *v, uint64_t *obj, const char *name, if (siv->string) { parse_option_size(name, siv->string, &val, &err); } else { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "size"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "size"); return; } if (err) { @@ -263,8 +263,8 @@ static void parse_type_bool(Visitor *v, bool *obj, const char *name, } } - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "boolean"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "boolean"); } static void parse_type_str(Visitor *v, char **obj, const char *name, @@ -274,8 +274,8 @@ static void parse_type_str(Visitor *v, char **obj, const char *name, if (siv->string) { *obj = g_strdup(siv->string); } else { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "string"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "string"); } } @@ -291,8 +291,8 @@ static void parse_type_number(Visitor *v, double *obj, const char *name, val = strtod(siv->string, &endp); } if (!siv->string || errno || endp == siv->string || *endp) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "number"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "number"); return; } diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index 1ab8574585..b86ce2cd07 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -13,7 +13,6 @@ #include "qemu-common.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" -#include "qapi/qmp/qerror.h" #include "qemu/host-utils.h" #include <math.h> #include "qemu/range.h" diff --git a/qdev-monitor.c b/qdev-monitor.c index d71d1ee520..f9e2d6258d 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -23,7 +23,9 @@ #include "monitor/qdev.h" #include "qmp-commands.h" #include "sysemu/arch_init.h" +#include "qapi/qmp/qerror.h" #include "qemu/config-file.h" +#include "qemu/error-report.h" /* * Aliases were a bad idea from the start. Let's keep them @@ -156,8 +158,7 @@ static int set_property(void *opaque, const char *name, const char *value, object_property_parse(obj, value, name, &err); if (err != NULL) { - qerror_report_err(err); - error_free(err); + error_propagate(errp, err); return -1; } return 0; @@ -202,16 +203,16 @@ static DeviceClass *qdev_get_device_class(const char **driver, Error **errp) } if (object_class_is_abstract(oc)) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver", - "non-abstract device type"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "driver", + "non-abstract device type"); return NULL; } dc = DEVICE_CLASS(oc); if (dc->cannot_instantiate_with_device_add_yet || (qdev_hotplug && !dc->hotpluggable)) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver", - "pluggable device type"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "driver", + "pluggable device type"); return NULL; } @@ -288,12 +289,13 @@ static Object *qdev_get_peripheral_anon(void) return dev; } +#if 0 /* conversion from qerror_report() to error_set() broke their use */ static void qbus_list_bus(DeviceState *dev) { BusState *child; const char *sep = " "; - error_printf("child busses at \"%s\":", + error_printf("child buses at \"%s\":", dev->id ? dev->id : object_get_typename(OBJECT(dev))); QLIST_FOREACH(child, &dev->child_bus, sibling) { error_printf("%s\"%s\"", sep, child->name); @@ -317,6 +319,7 @@ static void qbus_list_dev(BusState *bus) } error_printf("\n"); } +#endif static BusState *qbus_find_bus(DeviceState *dev, char *elem) { @@ -364,46 +367,58 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem) return NULL; } +static inline bool qbus_is_full(BusState *bus) +{ + BusClass *bus_class = BUS_GET_CLASS(bus); + return bus_class->max_dev && bus->max_index >= bus_class->max_dev; +} + +/* + * Search the tree rooted at @bus for a bus. + * If @name, search for a bus with that name. Note that bus names + * need not be unique. Yes, that's screwed up. + * Else search for a bus that is a subtype of @bus_typename. + * If more than one exists, prefer one that can take another device. + * Return the bus if found, else %NULL. + */ static BusState *qbus_find_recursive(BusState *bus, const char *name, const char *bus_typename) { - BusClass *bus_class = BUS_GET_CLASS(bus); BusChild *kid; - BusState *child, *ret; - int match = 1; - - if (name && (strcmp(bus->name, name) != 0)) { - match = 0; - } else if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) { - match = 0; - } else if ((bus_class->max_dev != 0) && (bus_class->max_dev <= bus->max_index)) { - if (name != NULL) { - /* bus was explicitly specified: return an error. */ - qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full", - bus->name); - return NULL; - } else { - /* bus was not specified: try to find another one. */ - match = 0; - } + BusState *pick, *child, *ret; + bool match; + + assert(name || bus_typename); + if (name) { + match = !strcmp(bus->name, name); + } else { + match = !!object_dynamic_cast(OBJECT(bus), bus_typename); } - if (match) { - return bus; + + if (match && !qbus_is_full(bus)) { + return bus; /* root matches and isn't full */ } + pick = match ? bus : NULL; + QTAILQ_FOREACH(kid, &bus->children, sibling) { DeviceState *dev = kid->child; QLIST_FOREACH(child, &dev->child_bus, sibling) { ret = qbus_find_recursive(child, name, bus_typename); - if (ret) { - return ret; + if (ret && !qbus_is_full(ret)) { + return ret; /* a descendant matches and isn't full */ + } + if (ret && !pick) { + pick = ret; } } } - return NULL; + + /* root or a descendant matches, but is full */ + return pick; } -static BusState *qbus_find(const char *path) +static BusState *qbus_find(const char *path, Error **errp) { DeviceState *dev; BusState *bus; @@ -421,7 +436,7 @@ static BusState *qbus_find(const char *path) } bus = qbus_find_recursive(sysbus_get_default(), elem, NULL); if (!bus) { - qerror_report(QERR_BUS_NOT_FOUND, elem); + error_setg(errp, "Bus '%s' not found", elem); return NULL; } pos = len; @@ -433,7 +448,7 @@ static BusState *qbus_find(const char *path) pos++; } if (path[pos] == '\0') { - return bus; + break; } /* find device */ @@ -444,10 +459,13 @@ static BusState *qbus_find(const char *path) pos += len; dev = qbus_find_dev(bus, elem); if (!dev) { - qerror_report(QERR_DEVICE_NOT_FOUND, elem); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", elem); +#if 0 /* conversion from qerror_report() to error_set() broke this: */ if (!monitor_cur_is_qmp()) { qbus_list_dev(bus); } +#endif return NULL; } @@ -458,21 +476,22 @@ static BusState *qbus_find(const char *path) if (path[pos] == '\0') { /* last specified element is a device. If it has exactly * one child bus accept it nevertheless */ - switch (dev->num_child_bus) { - case 0: - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "Device '%s' has no child bus", elem); - return NULL; - case 1: - return QLIST_FIRST(&dev->child_bus); - default: - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "Device '%s' has multiple child busses", elem); + if (dev->num_child_bus == 1) { + bus = QLIST_FIRST(&dev->child_bus); + break; + } + if (dev->num_child_bus) { + error_setg(errp, "Device '%s' has multiple child buses", + elem); +#if 0 /* conversion from qerror_report() to error_set() broke this: */ if (!monitor_cur_is_qmp()) { qbus_list_bus(dev); } - return NULL; +#endif + } else { + error_setg(errp, "Device '%s' has no child bus", elem); } + return NULL; } /* find bus */ @@ -483,16 +502,24 @@ static BusState *qbus_find(const char *path) pos += len; bus = qbus_find_bus(dev, elem); if (!bus) { - qerror_report(QERR_BUS_NOT_FOUND, elem); + error_setg(errp, "Bus '%s' not found", elem); +#if 0 /* conversion from qerror_report() to error_set() broke this: */ if (!monitor_cur_is_qmp()) { qbus_list_bus(dev); } +#endif return NULL; } } + + if (qbus_is_full(bus)) { + error_setg(errp, "Bus '%s' is full", path); + return NULL; + } + return bus; } -DeviceState *qdev_device_add(QemuOpts *opts) +DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) { DeviceClass *dc; const char *driver, *path, *id; @@ -502,42 +529,38 @@ DeviceState *qdev_device_add(QemuOpts *opts) driver = qemu_opt_get(opts, "driver"); if (!driver) { - qerror_report(QERR_MISSING_PARAMETER, "driver"); + error_setg(errp, QERR_MISSING_PARAMETER, "driver"); return NULL; } /* find driver */ - dc = qdev_get_device_class(&driver, &err); - if (err) { - qerror_report_err(err); - error_free(err); + dc = qdev_get_device_class(&driver, errp); + if (!dc) { return NULL; } /* find bus */ path = qemu_opt_get(opts, "bus"); if (path != NULL) { - bus = qbus_find(path); + bus = qbus_find(path, errp); if (!bus) { return NULL; } if (!object_dynamic_cast(OBJECT(bus), dc->bus_type)) { - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "Device '%s' can't go on a %s bus", - driver, object_get_typename(OBJECT(bus))); + error_setg(errp, "Device '%s' can't go on %s bus", + driver, object_get_typename(OBJECT(bus))); return NULL; } } else if (dc->bus_type != NULL) { bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type); - if (!bus) { - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "No '%s' bus found for device '%s'", - dc->bus_type, driver); + if (!bus || qbus_is_full(bus)) { + error_setg(errp, "No '%s' bus found for device '%s'", + dc->bus_type, driver); return NULL; } } if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) { - qerror_report(QERR_BUS_NO_HOTPLUG, bus->name); + error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name); return NULL; } @@ -565,7 +588,8 @@ DeviceState *qdev_device_add(QemuOpts *opts) } /* set properties */ - if (qemu_opt_foreach(opts, set_property, dev, NULL)) { + if (qemu_opt_foreach(opts, set_property, dev, &err)) { + error_propagate(errp, err); object_unparent(OBJECT(dev)); object_unref(OBJECT(dev)); return NULL; @@ -574,12 +598,10 @@ DeviceState *qdev_device_add(QemuOpts *opts) dev->opts = opts; object_property_set_bool(OBJECT(dev), true, "realized", &err); if (err != NULL) { - qerror_report_err(err); - error_free(err); + error_propagate(errp, err); dev->opts = NULL; object_unparent(OBJECT(dev)); object_unref(OBJECT(dev)); - qerror_report(QERR_DEVICE_INIT_FAILED, driver); return NULL; } return dev; @@ -736,7 +758,7 @@ void hmp_info_qom_tree(Monitor *mon, const QDict *dict) print_qom_composition(mon, obj, 0); } -int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) +void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) { Error *local_err = NULL; QemuOpts *opts; @@ -744,21 +766,20 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err); if (local_err) { - qerror_report_err(local_err); - error_free(local_err); - return -1; + error_propagate(errp, local_err); + return; } if (!monitor_cur_is_qmp() && qdev_device_help(opts)) { qemu_opts_del(opts); - return 0; + return; } - dev = qdev_device_add(opts); + dev = qdev_device_add(opts, &local_err); if (!dev) { + error_propagate(errp, local_err); qemu_opts_del(opts); - return -1; + return; } object_unref(OBJECT(dev)); - return 0; } void qmp_device_del(const char *id, Error **errp) @@ -772,7 +793,8 @@ void qmp_device_del(const char *id, Error **errp) g_free(path); if (!obj) { - error_set(errp, QERR_DEVICE_NOT_FOUND, id); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", id); return; } @@ -832,7 +854,7 @@ int qemu_global_option(const char *str) return 0; } - opts = qemu_opts_parse(&qemu_global_opts, str, false); + opts = qemu_opts_parse_noisily(&qemu_global_opts, str, false); if (!opts) { return -1; } diff --git a/qemu-char.c b/qemu-char.c index d0c1564306..617e034455 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -24,6 +24,7 @@ #include "qemu-common.h" #include "monitor/monitor.h" #include "sysemu/sysemu.h" +#include "qemu/error-report.h" #include "qemu/timer.h" #include "sysemu/char.h" #include "hw/usb.h" diff --git a/qemu-img.c b/qemu-img.c index 60c820d002..75f4ee4421 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -23,6 +23,7 @@ */ #include "qapi-visit.h" #include "qapi/qmp-output-visitor.h" +#include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" #include "qemu-common.h" #include "qemu/option.h" @@ -739,7 +740,7 @@ static int img_commit(int argc, char **argv) if (base) { base_bs = bdrv_find_backing_image(bs, base); if (!base_bs) { - error_set(&local_err, QERR_BASE_NOT_FOUND, base); + error_setg(&local_err, QERR_BASE_NOT_FOUND, base); goto done; } } else { @@ -1590,7 +1591,8 @@ static int img_convert(int argc, char **argv) break; case 'l': if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { - sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0); + sn_opts = qemu_opts_parse_noisily(&internal_snapshot_opts, + optarg, false); if (!sn_opts) { error_report("Failed in parsing snapshot param '%s'", optarg); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 52dc6111bf..53477e1e17 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -13,6 +13,7 @@ #include "block/block.h" #include "block/block_int.h" /* for info_f() */ #include "block/qapi.h" +#include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/timer.h" #include "sysemu/block-backend.h" @@ -15,10 +15,12 @@ #include <libgen.h> #include "qemu-io.h" +#include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/option.h" #include "qemu/config-file.h" #include "qemu/readline.h" +#include "qapi/qmp/qstring.h" #include "sysemu/block-backend.h" #include "block/block_int.h" #include "trace/control.h" @@ -153,7 +155,7 @@ static int open_f(BlockBackend *blk, int argc, char **argv) readonly = 1; break; case 'o': - if (!qemu_opts_parse(&empty_opts, optarg, 0)) { + if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) { printf("could not parse option list -- %s\n", optarg); qemu_opts_reset(&empty_opts); return 0; diff --git a/qemu-nbd.c b/qemu-nbd.c index 5af6d11e33..5106b802e6 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -25,6 +25,7 @@ #include "qemu/error-report.h" #include "block/snapshot.h" #include "qapi/util.h" +#include "qapi/qmp/qstring.h" #include <stdarg.h> #include <stdio.h> @@ -549,7 +550,8 @@ int main(int argc, char **argv) break; case 'l': if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { - sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0); + sn_opts = qemu_opts_parse_noisily(&internal_snapshot_opts, + optarg, false); if (!sn_opts) { errx(EXIT_FAILURE, "Failed in parsing snapshot param `%s'", optarg); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index ba8de62436..befd00b00d 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -382,15 +382,15 @@ static int guest_file_toggle_flags(int fd, int flags, bool set, Error **err) old_flags = fcntl(fd, F_GETFL); if (old_flags == -1) { - error_set_errno(err, errno, QERR_QGA_COMMAND_FAILED, - "failed to fetch filehandle flags"); + error_setg_errno(err, errno, QERR_QGA_COMMAND_FAILED, + "failed to fetch filehandle flags"); return -1; } ret = fcntl(fd, F_SETFL, set ? (old_flags | flags) : (old_flags & ~flags)); if (ret == -1) { - error_set_errno(err, errno, QERR_QGA_COMMAND_FAILED, - "failed to set filehandle flags"); + error_setg_errno(err, errno, QERR_QGA_COMMAND_FAILED, + "failed to set filehandle flags"); return -1; } @@ -2302,34 +2302,34 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) void qmp_guest_suspend_disk(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } void qmp_guest_suspend_ram(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } void qmp_guest_suspend_hybrid(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return -1; } @@ -2338,25 +2338,25 @@ void qmp_guest_set_user_password(const char *username, bool crypted, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } GuestMemoryBlockResponseList * qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } @@ -2366,20 +2366,20 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return 0; } int64_t qmp_guest_fsfreeze_freeze(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return 0; } @@ -2388,14 +2388,14 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, strList *mountpoints, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return 0; } int64_t qmp_guest_fsfreeze_thaw(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return 0; } @@ -2404,7 +2404,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) #if !defined(CONFIG_FSTRIM) void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } #endif diff --git a/qga/commands-win32.c b/qga/commands-win32.c index d0aaec70f3..fbddc8b1b2 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -182,8 +182,8 @@ static void acquire_privilege(const char *name, Error **errp) TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token)) { if (!LookupPrivilegeValue(NULL, name, &priv.Privileges[0].Luid)) { - error_set(&local_err, QERR_QGA_COMMAND_FAILED, - "no luid for requested privilege"); + error_setg(&local_err, QERR_QGA_COMMAND_FAILED, + "no luid for requested privilege"); goto out; } @@ -191,14 +191,14 @@ static void acquire_privilege(const char *name, Error **errp) priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (!AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0)) { - error_set(&local_err, QERR_QGA_COMMAND_FAILED, - "unable to acquire requested privilege"); + error_setg(&local_err, QERR_QGA_COMMAND_FAILED, + "unable to acquire requested privilege"); goto out; } } else { - error_set(&local_err, QERR_QGA_COMMAND_FAILED, - "failed to open privilege token"); + error_setg(&local_err, QERR_QGA_COMMAND_FAILED, + "failed to open privilege token"); } out: @@ -217,8 +217,8 @@ static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque, HANDLE thread = CreateThread(NULL, 0, func, opaque, 0, NULL); if (!thread) { - error_set(&local_err, QERR_QGA_COMMAND_FAILED, - "failed to dispatch asynchronous command"); + error_setg(&local_err, QERR_QGA_COMMAND_FAILED, + "failed to dispatch asynchronous command"); error_propagate(errp, local_err); } } @@ -237,8 +237,8 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) } else if (strcmp(mode, "reboot") == 0) { shutdown_flag |= EWX_REBOOT; } else { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "mode", - "halt|powerdown|reboot"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "mode", + "halt|powerdown|reboot"); return; } @@ -252,7 +252,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) { slog("guest-shutdown failed: %lu", GetLastError()); - error_set(errp, QERR_UNDEFINED_ERROR); + error_setg(errp, QERR_UNDEFINED_ERROR); } } @@ -384,7 +384,7 @@ static void guest_file_init(void) GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } @@ -394,7 +394,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) { if (!vss_initialized()) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return 0; } @@ -415,7 +415,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **errp) Error *local_err = NULL; if (!vss_initialized()) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return 0; } @@ -446,7 +446,7 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, strList *mountpoints, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return 0; } @@ -459,7 +459,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) int i; if (!vss_initialized()) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return 0; } @@ -495,7 +495,7 @@ static void guest_fsfreeze_cleanup(void) */ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } typedef enum { @@ -510,27 +510,27 @@ static void check_suspend_mode(GuestSuspendMode mode, Error **errp) ZeroMemory(&sys_pwr_caps, sizeof(sys_pwr_caps)); if (!GetPwrCapabilities(&sys_pwr_caps)) { - error_set(&local_err, QERR_QGA_COMMAND_FAILED, - "failed to determine guest suspend capabilities"); + error_setg(&local_err, QERR_QGA_COMMAND_FAILED, + "failed to determine guest suspend capabilities"); goto out; } switch (mode) { case GUEST_SUSPEND_MODE_DISK: if (!sys_pwr_caps.SystemS4) { - error_set(&local_err, QERR_QGA_COMMAND_FAILED, - "suspend-to-disk not supported by OS"); + error_setg(&local_err, QERR_QGA_COMMAND_FAILED, + "suspend-to-disk not supported by OS"); } break; case GUEST_SUSPEND_MODE_RAM: if (!sys_pwr_caps.SystemS3) { - error_set(&local_err, QERR_QGA_COMMAND_FAILED, - "suspend-to-ram not supported by OS"); + error_setg(&local_err, QERR_QGA_COMMAND_FAILED, + "suspend-to-ram not supported by OS"); } break; default: - error_set(&local_err, QERR_INVALID_PARAMETER_VALUE, "mode", - "GuestSuspendMode"); + error_setg(&local_err, QERR_INVALID_PARAMETER_VALUE, "mode", + "GuestSuspendMode"); } out: @@ -586,12 +586,12 @@ void qmp_guest_suspend_ram(Error **errp) void qmp_guest_suspend_hybrid(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } @@ -666,13 +666,13 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return -1; } @@ -681,25 +681,25 @@ void qmp_guest_set_user_password(const char *username, bool crypted, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); } GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } GuestMemoryBlockResponseList * qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } diff --git a/qga/main.c b/qga/main.c index 7e1e438f67..23cde0104a 100644 --- a/qga/main.c +++ b/qga/main.c @@ -578,7 +578,7 @@ static void process_event(JSONMessageParser *parser, QList *tokens) qdict = qdict_new(); if (!err) { g_warning("failed to parse event: unknown error"); - error_set(&err, QERR_JSON_PARSING); + error_setg(&err, QERR_JSON_PARSING); } else { g_warning("failed to parse event: %s", error_get_pretty(err)); } @@ -598,7 +598,7 @@ static void process_event(JSONMessageParser *parser, QList *tokens) QDECREF(qdict); qdict = qdict_new(); g_warning("unrecognized payload format"); - error_set(&err, QERR_UNSUPPORTED); + error_setg(&err, QERR_UNSUPPORTED); qdict_put_obj(qdict, "error", qmp_build_error_object(err)); error_free(err); } diff --git a/qmp-commands.hx b/qmp-commands.hx index 1db6524e97..3ffa612f2c 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -276,7 +276,7 @@ EQMP .args_type = "device:O", .params = "driver[,prop=value][,...]", .help = "add device, like -device on the command line", - .mhandler.cmd_new = do_device_add, + .mhandler.cmd_new = qmp_device_add, }, SQMP @@ -1983,7 +1983,7 @@ EQMP .args_type = "", .params = "", .help = "enable QMP capabilities", - .mhandler.cmd_new = do_qmp_capabilities, + .mhandler.cmd_new = qmp_capabilities, }, SQMP @@ -14,6 +14,7 @@ */ #include "qemu-common.h" +#include "monitor/monitor.h" #include "sysemu/sysemu.h" #include "qmp-commands.h" #include "sysemu/char.h" @@ -24,6 +25,7 @@ #include "hw/qdev.h" #include "sysemu/blockdev.h" #include "qom/qom-qobject.h" +#include "qapi/qmp/qerror.h" #include "qapi/qmp/qobject.h" #include "qapi/qmp-input-visitor.h" #include "hw/boards.h" @@ -132,13 +134,13 @@ void qmp_cpu_add(int64_t id, Error **errp) defined in the VNC subsystem */ VncInfo *qmp_query_vnc(Error **errp) { - error_set(errp, QERR_FEATURE_DISABLED, "vnc"); + error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); return NULL; }; VncInfo2List *qmp_query_vnc_servers(Error **errp) { - error_set(errp, QERR_FEATURE_DISABLED, "vnc"); + error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); return NULL; }; #endif @@ -206,7 +208,8 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) if (ambiguous) { error_setg(errp, "Path '%s' is ambiguous", path); } else { - error_set(errp, QERR_DEVICE_NOT_FOUND, path); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", path); } return NULL; } @@ -226,55 +229,37 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) } /* FIXME: teach qapi about how to pass through Visitors */ -int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret) +void qmp_qom_set(QDict *qdict, QObject **ret, Error **errp) { const char *path = qdict_get_str(qdict, "path"); const char *property = qdict_get_str(qdict, "property"); QObject *value = qdict_get(qdict, "value"); - Error *local_err = NULL; Object *obj; obj = object_resolve_path(path, NULL); if (!obj) { - error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); - goto out; - } - - object_property_set_qobject(obj, value, property, &local_err); - -out: - if (local_err) { - qerror_report_err(local_err); - error_free(local_err); - return -1; + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", path); + return; } - return 0; + object_property_set_qobject(obj, value, property, errp); } -int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret) +void qmp_qom_get(QDict *qdict, QObject **ret, Error **errp) { const char *path = qdict_get_str(qdict, "path"); const char *property = qdict_get_str(qdict, "property"); - Error *local_err = NULL; Object *obj; obj = object_resolve_path(path, NULL); if (!obj) { - error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); - goto out; - } - - *ret = object_property_get_qobject(obj, property, &local_err); - -out: - if (local_err) { - qerror_report_err(local_err); - error_free(local_err); - return -1; + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", path); + return; } - return 0; + *ret = object_property_get_qobject(obj, property, errp); } void qmp_set_password(const char *protocol, const char *password, @@ -292,7 +277,7 @@ void qmp_set_password(const char *protocol, const char *password, } else if (strcmp(connected, "keep") == 0) { /* nothing */ } else { - error_set(errp, QERR_INVALID_PARAMETER, "connected"); + error_setg(errp, QERR_INVALID_PARAMETER, "connected"); return; } } @@ -304,7 +289,7 @@ void qmp_set_password(const char *protocol, const char *password, rc = qemu_spice_set_passwd(password, fail_if_connected, disconnect_if_connected); if (rc != 0) { - error_set(errp, QERR_SET_PASSWD_FAILED); + error_setg(errp, QERR_SET_PASSWD_FAILED); } return; } @@ -312,19 +297,19 @@ void qmp_set_password(const char *protocol, const char *password, if (strcmp(protocol, "vnc") == 0) { if (fail_if_connected || disconnect_if_connected) { /* vnc supports "connected=keep" only */ - error_set(errp, QERR_INVALID_PARAMETER, "connected"); + error_setg(errp, QERR_INVALID_PARAMETER, "connected"); return; } /* Note that setting an empty password will not disable login through * this interface. */ rc = vnc_display_password(NULL, password); if (rc < 0) { - error_set(errp, QERR_SET_PASSWD_FAILED); + error_setg(errp, QERR_SET_PASSWD_FAILED); } return; } - error_set(errp, QERR_INVALID_PARAMETER, "protocol"); + error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); } void qmp_expire_password(const char *protocol, const char *whenstr, @@ -349,7 +334,7 @@ void qmp_expire_password(const char *protocol, const char *whenstr, } rc = qemu_spice_set_pw_expire(when); if (rc != 0) { - error_set(errp, QERR_SET_PASSWD_FAILED); + error_setg(errp, QERR_SET_PASSWD_FAILED); } return; } @@ -357,19 +342,19 @@ void qmp_expire_password(const char *protocol, const char *whenstr, if (strcmp(protocol, "vnc") == 0) { rc = vnc_display_pw_expire(NULL, when); if (rc != 0) { - error_set(errp, QERR_SET_PASSWD_FAILED); + error_setg(errp, QERR_SET_PASSWD_FAILED); } return; } - error_set(errp, QERR_INVALID_PARAMETER, "protocol"); + error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); } #ifdef CONFIG_VNC void qmp_change_vnc_password(const char *password, Error **errp) { if (vnc_display_password(NULL, password) < 0) { - error_set(errp, QERR_SET_PASSWD_FAILED); + error_setg(errp, QERR_SET_PASSWD_FAILED); } } @@ -387,7 +372,7 @@ static void qmp_change_vnc_listen(const char *target, Error **errp) if (opts) { qemu_opts_del(opts); } - opts = vnc_parse_func(target); + opts = vnc_parse(target, errp); if (!opts) { return; } @@ -400,7 +385,7 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, { if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) { if (!has_arg) { - error_set(errp, QERR_MISSING_PARAMETER, "password"); + error_setg(errp, QERR_MISSING_PARAMETER, "password"); } else { qmp_change_vnc_password(arg, errp); } @@ -411,12 +396,12 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, #else void qmp_change_vnc_password(const char *password, Error **errp) { - error_set(errp, QERR_FEATURE_DISABLED, "vnc"); + error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); } static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, Error **errp) { - error_set(errp, QERR_FEATURE_DISABLED, "vnc"); + error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); } #endif /* !CONFIG_VNC */ @@ -518,14 +503,14 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename, klass = object_class_by_name(typename); if (klass == NULL) { - error_set(errp, QERR_DEVICE_NOT_FOUND, typename); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", typename); return NULL; } klass = object_class_dynamic_cast(klass, TYPE_DEVICE); if (klass == NULL) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, - "name", TYPE_DEVICE); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "name", TYPE_DEVICE); return NULL; } @@ -670,35 +655,25 @@ out: object_unref(obj); } -int qmp_object_add(Monitor *mon, const QDict *qdict, QObject **ret) +void qmp_object_add(QDict *qdict, QObject **ret, Error **errp) { const char *type = qdict_get_str(qdict, "qom-type"); const char *id = qdict_get_str(qdict, "id"); QObject *props = qdict_get(qdict, "props"); const QDict *pdict = NULL; - Error *local_err = NULL; QmpInputVisitor *qiv; if (props) { pdict = qobject_to_qdict(props); if (!pdict) { - error_set(&local_err, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); - goto out; + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); + return; } } qiv = qmp_input_visitor_new(props); - object_add(type, id, pdict, qmp_input_get_visitor(qiv), &local_err); + object_add(type, id, pdict, qmp_input_get_visitor(qiv), errp); qmp_input_visitor_cleanup(qiv); - -out: - if (local_err) { - qerror_report_err(local_err); - error_free(local_err); - return -1; - } - - return 0; } void qmp_object_del(const char *id, Error **errp) diff --git a/qobject/Makefile.objs b/qobject/Makefile.objs index f7595f56fe..0031e8b691 100644 --- a/qobject/Makefile.objs +++ b/qobject/Makefile.objs @@ -1,3 +1,2 @@ util-obj-y = qnull.o qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o util-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o -util-obj-y += qerror.o diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 717cb8fde7..ac991ba3cf 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -22,7 +22,6 @@ #include "qapi/qmp/qbool.h" #include "qapi/qmp/json-parser.h" #include "qapi/qmp/json-lexer.h" -#include "qapi/qmp/qerror.h" typedef struct JSONParserContext { @@ -558,9 +557,9 @@ static QObject *parse_keyword(JSONParserContext *ctxt) } if (token_is_keyword(token, "true")) { - ret = QOBJECT(qbool_from_int(true)); + ret = QOBJECT(qbool_from_bool(true)); } else if (token_is_keyword(token, "false")) { - ret = QOBJECT(qbool_from_int(false)); + ret = QOBJECT(qbool_from_bool(false)); } else if (token_is_keyword(token, "null")) { ret = qnull(); } else { @@ -593,7 +592,7 @@ static QObject *parse_escape(JSONParserContext *ctxt, va_list *ap) if (token_is_escape(token, "%p")) { obj = va_arg(*ap, QObject *); } else if (token_is_escape(token, "%i")) { - obj = QOBJECT(qbool_from_int(va_arg(*ap, int))); + obj = QOBJECT(qbool_from_bool(va_arg(*ap, int))); } else if (token_is_escape(token, "%d")) { obj = QOBJECT(qint_from_int(va_arg(*ap, int))); } else if (token_is_escape(token, "%ld")) { diff --git a/qobject/qbool.c b/qobject/qbool.c index a3d2afa827..5ff69f0b2d 100644 --- a/qobject/qbool.c +++ b/qobject/qbool.c @@ -23,11 +23,11 @@ static const QType qbool_type = { }; /** - * qbool_from_int(): Create a new QBool from an int + * qbool_from_bool(): Create a new QBool from a bool * * Return strong reference. */ -QBool *qbool_from_int(int value) +QBool *qbool_from_bool(bool value) { QBool *qb; @@ -39,9 +39,9 @@ QBool *qbool_from_int(int value) } /** - * qbool_get_int(): Get the stored int + * qbool_get_bool(): Get the stored bool */ -int qbool_get_int(const QBool *qb) +bool qbool_get_bool(const QBool *qb) { return qb->value; } diff --git a/qobject/qdict.c b/qobject/qdict.c index 190791becf..67b1a58abf 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -241,10 +241,10 @@ int64_t qdict_get_int(const QDict *qdict, const char *key) * * Return bool mapped by 'key'. */ -int qdict_get_bool(const QDict *qdict, const char *key) +bool qdict_get_bool(const QDict *qdict, const char *key) { QObject *obj = qdict_get_obj(qdict, key, QTYPE_QBOOL); - return qbool_get_int(qobject_to_qbool(obj)); + return qbool_get_bool(qobject_to_qbool(obj)); } /** @@ -314,7 +314,7 @@ int64_t qdict_get_try_int(const QDict *qdict, const char *key, * dictionary or if the stored object is not of QBool type * 'def_value' will be returned. */ -int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value) +bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value) { QObject *obj; @@ -322,7 +322,7 @@ int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value) if (!obj || qobject_type(obj) != QTYPE_QBOOL) return def_value; - return qbool_get_int(qobject_to_qbool(obj)); + return qbool_get_bool(qobject_to_qbool(obj)); } /** diff --git a/qobject/qerror.c b/qobject/qerror.c deleted file mode 100644 index e3608e2402..0000000000 --- a/qobject/qerror.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * QError Module - * - * Copyright (C) 2009 Red Hat Inc. - * - * Authors: - * Luiz Capitulino <lcapitulino@redhat.com> - * - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. - * See the COPYING.LIB file in the top-level directory. - */ - -#include "monitor/monitor.h" -#include "qapi/qmp/qjson.h" -#include "qapi/qmp/qerror.h" -#include "qemu-common.h" - -static void qerror_destroy_obj(QObject *obj); - -static const QType qerror_type = { - .code = QTYPE_QERROR, - .destroy = qerror_destroy_obj, -}; - -/** - * qerror_new(): Create a new QError - * - * Return strong reference. - */ -static QError *qerror_new(void) -{ - QError *qerr; - - qerr = g_malloc0(sizeof(*qerr)); - QOBJECT_INIT(qerr, &qerror_type); - - return qerr; -} - -/** - * qerror_from_info(): Create a new QError from error information - * - * Return strong reference. - */ -static QError * GCC_FMT_ATTR(2, 0) -qerror_from_info(ErrorClass err_class, const char *fmt, va_list *va) -{ - QError *qerr; - - qerr = qerror_new(); - loc_save(&qerr->loc); - - qerr->err_msg = g_strdup_vprintf(fmt, *va); - qerr->err_class = err_class; - - return qerr; -} - -/** - * qerror_human(): Format QError data into human-readable string. - */ -QString *qerror_human(const QError *qerror) -{ - return qstring_from_str(qerror->err_msg); -} - -/** - * qerror_print(): Print QError data - * - * This function will print the member 'desc' of the specified QError object, - * it uses error_report() for this, so that the output is routed to the right - * place (ie. stderr or Monitor's device). - */ -static void qerror_print(QError *qerror) -{ - QString *qstring = qerror_human(qerror); - loc_push_restore(&qerror->loc); - error_report("%s", qstring_get_str(qstring)); - loc_pop(&qerror->loc); - QDECREF(qstring); -} - -void qerror_report(ErrorClass eclass, const char *fmt, ...) -{ - va_list va; - QError *qerror; - - va_start(va, fmt); - qerror = qerror_from_info(eclass, fmt, &va); - va_end(va); - - if (monitor_cur_is_qmp()) { - monitor_set_error(cur_mon, qerror); - } else { - qerror_print(qerror); - QDECREF(qerror); - } -} - -/* Evil... */ -struct Error -{ - char *msg; - ErrorClass err_class; -}; - -void qerror_report_err(Error *err) -{ - QError *qerr; - - qerr = qerror_new(); - loc_save(&qerr->loc); - qerr->err_msg = g_strdup(err->msg); - qerr->err_class = err->err_class; - - if (monitor_cur_is_qmp()) { - monitor_set_error(cur_mon, qerr); - } else { - qerror_print(qerr); - QDECREF(qerr); - } -} - -/** - * qobject_to_qerror(): Convert a QObject into a QError - */ -static QError *qobject_to_qerror(const QObject *obj) -{ - if (qobject_type(obj) != QTYPE_QERROR) { - return NULL; - } - - return container_of(obj, QError, base); -} - -/** - * qerror_destroy_obj(): Free all memory allocated by a QError - */ -static void qerror_destroy_obj(QObject *obj) -{ - QError *qerr; - - assert(obj != NULL); - qerr = qobject_to_qerror(obj); - - g_free(qerr->err_msg); - g_free(qerr); -} diff --git a/qobject/qjson.c b/qobject/qjson.c index 846733dafb..33f8ef530c 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -254,16 +254,13 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent) case QTYPE_QBOOL: { QBool *val = qobject_to_qbool(obj); - if (qbool_get_int(val)) { + if (qbool_get_bool(val)) { qstring_append(str, "true"); } else { qstring_append(str, "false"); } break; } - case QTYPE_QERROR: - /* XXX: should QError be emitted? */ - break; default: abort(); } diff --git a/qom/object.c b/qom/object.c index ee384311f9..eea8edf3d3 100644 --- a/qom/object.c +++ b/qom/object.c @@ -926,7 +926,7 @@ void object_property_get(Object *obj, Visitor *v, const char *name, } if (!prop->get) { - error_set(errp, QERR_PERMISSION_DENIED); + error_setg(errp, QERR_PERMISSION_DENIED); } else { prop->get(obj, v, prop->opaque, name, errp); } @@ -941,7 +941,7 @@ void object_property_set(Object *obj, Visitor *v, const char *name, } if (!prop->set) { - error_set(errp, QERR_PERMISSION_DENIED); + error_setg(errp, QERR_PERMISSION_DENIED); } else { prop->set(obj, v, prop->opaque, name, errp); } @@ -968,7 +968,7 @@ char *object_property_get_str(Object *obj, const char *name, } qstring = qobject_to_qstring(ret); if (!qstring) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "string"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "string"); retval = NULL; } else { retval = g_strdup(qstring_get_str(qstring)); @@ -999,7 +999,8 @@ Object *object_property_get_link(Object *obj, const char *name, if (str && *str) { target = object_resolve_path(str, NULL); if (!target) { - error_set(errp, QERR_DEVICE_NOT_FOUND, str); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", str); } } @@ -1010,7 +1011,7 @@ Object *object_property_get_link(Object *obj, const char *name, void object_property_set_bool(Object *obj, bool value, const char *name, Error **errp) { - QBool *qbool = qbool_from_int(value); + QBool *qbool = qbool_from_bool(value); object_property_set_qobject(obj, QOBJECT(qbool), name, errp); QDECREF(qbool); @@ -1028,10 +1029,10 @@ bool object_property_get_bool(Object *obj, const char *name, } qbool = qobject_to_qbool(ret); if (!qbool) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean"); retval = false; } else { - retval = qbool_get_int(qbool); + retval = qbool_get_bool(qbool); } QDECREF(qbool); @@ -1059,7 +1060,7 @@ int64_t object_property_get_int(Object *obj, const char *name, } qint = qobject_to_qint(ret); if (!qint) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "int"); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "int"); retval = -1; } else { retval = qint_get_int(qint); @@ -1303,9 +1304,10 @@ static Object *object_resolve_link(Object *obj, const char *name, } else if (!target) { target = object_resolve_path(path, &ambiguous); if (target || ambiguous) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, target_type); + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, target_type); } else { - error_set(errp, QERR_DEVICE_NOT_FOUND, path); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", path); } target = NULL; } diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 1c1d3aa029..ca22acc1d5 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -195,12 +195,10 @@ out: return ret def gen_marshal_input_decl(name, args, ret_type, middle_mode): - if middle_mode: - return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_name(name) - else: - return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name) - - + ret = 'void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name) + if not middle_mode: + ret = "static " + ret + return ret def gen_marshal_input(name, args, ret_type, middle_mode): hdr = gen_marshal_input_decl(name, args, ret_type, middle_mode) @@ -212,11 +210,6 @@ def gen_marshal_input(name, args, ret_type, middle_mode): ''', header=hdr) - if middle_mode: - ret += mcgen(''' - QDict *args = (QDict *)qdict; -''') - if ret_type: if is_c_ptr(ret_type): retval = " %s retval = NULL;" % c_type(ret_type) @@ -253,35 +246,13 @@ def gen_marshal_input(name, args, ret_type, middle_mode): out: ''') - if not middle_mode: - ret += mcgen(''' - error_propagate(errp, local_err); -''') ret += mcgen(''' + error_propagate(errp, local_err); %(visitor_input_block_cleanup)s +} ''', visitor_input_block_cleanup=gen_visitor_input_block(args, dealloc=True)) - - if middle_mode: - ret += mcgen(''' - - if (local_err) { - qerror_report_err(local_err); - error_free(local_err); - return -1; - } - return 0; -''') - else: - ret += mcgen(''' - return; -''') - - ret += mcgen(''' -} -''') - return ret def gen_registry(commands): @@ -358,7 +329,6 @@ h_comment = ''' fdef.write(mcgen(''' #include "qemu-common.h" #include "qemu/module.h" -#include "qapi/qmp/qerror.h" #include "qapi/qmp/types.h" #include "qapi/qmp/dispatch.h" #include "qapi/visitor.h" diff --git a/slirp/misc.c b/slirp/misc.c index 6543dc7772..578e8b2c16 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -9,6 +9,7 @@ #include <libslirp.h> #include "monitor/monitor.h" +#include "qemu/error-report.h" #include "qemu/main-loop.h" #ifdef DEBUG diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 8beff4c732..9937a1295e 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -21,7 +21,6 @@ stub-obj-y += machine-init-done.o stub-obj-y += migr-blocker.o stub-obj-y += mon-is-qmp.o stub-obj-y += mon-printf.o -stub-obj-y += mon-set-error.o stub-obj-y += monitor-init.o stub-obj-y += notify-event.o stub-obj-$(CONFIG_SPICE) += qemu-chr-open-spice.o diff --git a/stubs/arch-query-cpu-def.c b/stubs/arch-query-cpu-def.c index 22e0b43de9..a975ab453a 100644 --- a/stubs/arch-query-cpu-def.c +++ b/stubs/arch-query-cpu-def.c @@ -4,6 +4,6 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + error_setg(errp, QERR_UNSUPPORTED); return NULL; } diff --git a/stubs/dump.c b/stubs/dump.c index fac70191eb..8c24eda847 100644 --- a/stubs/dump.c +++ b/stubs/dump.c @@ -13,7 +13,6 @@ #include "qemu-common.h" #include "sysemu/dump-arch.h" -#include "qapi/qmp/qerror.h" #include "qmp-commands.h" int cpu_get_dump_info(ArchDumpInfo *info, diff --git a/stubs/mon-is-qmp.c b/stubs/mon-is-qmp.c index 1ef136ab1d..dd26f19c87 100644 --- a/stubs/mon-is-qmp.c +++ b/stubs/mon-is-qmp.c @@ -1,6 +1,8 @@ #include "qemu-common.h" #include "monitor/monitor.h" +Monitor *cur_mon; + bool monitor_cur_is_qmp(void) { return false; diff --git a/stubs/mon-set-error.c b/stubs/mon-set-error.c deleted file mode 100644 index d0411f97fa..0000000000 --- a/stubs/mon-set-error.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "qemu-common.h" -#include "monitor/monitor.h" - -Monitor *cur_mon; - -void monitor_set_error(Monitor *mon, QError *qerror) -{ -} diff --git a/target-alpha/translate.c b/target-alpha/translate.c index e9927b56b4..81d4ff827c 100644 --- a/target-alpha/translate.c +++ b/target-alpha/translate.c @@ -2939,7 +2939,7 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, ctx.pc - pc_start, 1); + log_target_disas(cs, pc_start, ctx.pc - pc_start, 1); qemu_log("\n"); } #endif diff --git a/target-arm/cpu.c b/target-arm/cpu.c index b3d07ac7d8..80669a6d1b 100644 --- a/target-arm/cpu.c +++ b/target-arm/cpu.c @@ -22,7 +22,6 @@ #include "internals.h" #include "qemu-common.h" #include "hw/qdev-properties.h" -#include "qapi/qmp/qerror.h" #if !defined(CONFIG_USER_ONLY) #include "hw/loader.h" #endif diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index ffa6cb8e56..e077f2dc30 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -11128,7 +11128,7 @@ done_generating: if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc->pc - pc_start, + log_target_disas(cs, pc_start, dc->pc - pc_start, 4 | (dc->bswap_code << 1)); qemu_log("\n"); } diff --git a/target-arm/translate.c b/target-arm/translate.c index ead08f4820..971b6db061 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -11485,7 +11485,7 @@ done_generating: if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc->pc - pc_start, + log_target_disas(cs, pc_start, dc->pc - pc_start, dc->thumb | (dc->bswap_code << 1)); qemu_log("\n"); } diff --git a/target-cris/translate.c b/target-cris/translate.c index 687c88be28..3e59601eb4 100644 --- a/target-cris/translate.c +++ b/target-cris/translate.c @@ -3345,7 +3345,7 @@ gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb, #ifdef DEBUG_DISAS #if !DISAS_CRIS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { - log_target_disas(env, pc_start, dc->pc - pc_start, + log_target_disas(cs, pc_start, dc->pc - pc_start, env->pregs[PR_VR]); qemu_log("\nisize=%d osize=%d\n", dc->pc - pc_start, tcg_op_buf_count()); diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 4e7cdaaaa5..36b07f99aa 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -26,6 +26,7 @@ #include "sysemu/cpus.h" #include "kvm_i386.h" +#include "qemu/error-report.h" #include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/qmp/qerror.h" @@ -1524,8 +1525,8 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque, return; } if (value < min || value > max) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", - name ? name : "null", value, min, max); + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", + name ? name : "null", value, min, max); return; } @@ -1565,8 +1566,8 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque, return; } if (value < min || value > max) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", - name ? name : "null", value, min, max); + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", + name ? name : "null", value, min, max); return; } @@ -1603,8 +1604,8 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, return; } if (value < min || value > max) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", - name ? name : "null", value, min, max); + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", + name ? name : "null", value, min, max); return; } @@ -1632,8 +1633,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value, int i; if (strlen(value) != CPUID_VENDOR_SZ) { - error_set(errp, QERR_PROPERTY_VALUE_BAD, "", - "vendor", value); + error_setg(errp, QERR_PROPERTY_VALUE_BAD, "", "vendor", value); return; } @@ -1709,8 +1709,8 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, return; } if (value < min || value > max) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", - name ? name : "null", value, min, max); + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", + name ? name : "null", value, min, max); return; } diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 5a236e3103..daced5cb94 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -36,7 +36,6 @@ #include <asm/hyperv.h> #include "hw/pci/pci.h" #include "migration/migration.h" -#include "qapi/qmp/qerror.h" #include "exec/memattrs.h" //#define DEBUG_KVM diff --git a/target-i386/translate.c b/target-i386/translate.c index 58b1959154..7a1bdee271 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -8093,7 +8093,7 @@ done_generating: else #endif disas_flags = !dc->code32; - log_target_disas(env, pc_start, pc_ptr - pc_start, disas_flags); + log_target_disas(cs, pc_start, pc_ptr - pc_start, disas_flags); qemu_log("\n"); } #endif diff --git a/target-lm32/translate.c b/target-lm32/translate.c index 81a204f5cf..cf7042e3e0 100644 --- a/target-lm32/translate.c +++ b/target-lm32/translate.c @@ -1168,7 +1168,7 @@ void gen_intermediate_code_internal(LM32CPU *cpu, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("\n"); - log_target_disas(env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); qemu_log("\nisize=%d osize=%d\n", dc->pc - pc_start, tcg_op_buf_count()); } diff --git a/target-m68k/translate.c b/target-m68k/translate.c index 96d75bf956..d6c478fd28 100644 --- a/target-m68k/translate.c +++ b/target-m68k/translate.c @@ -3077,7 +3077,7 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb, if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c index 1f5fe9afcd..f4e969b29c 100644 --- a/target-microblaze/translate.c +++ b/target-microblaze/translate.c @@ -1851,7 +1851,7 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb, if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("\n"); #if DISAS_GNU - log_target_disas(env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); #endif qemu_log("\nisize=%d osize=%d\n", dc->pc - pc_start, tcg_op_buf_count()); diff --git a/target-mips/translate.c b/target-mips/translate.c index 1d128eef02..a2dbad5ed2 100644 --- a/target-mips/translate.c +++ b/target-mips/translate.c @@ -19558,7 +19558,7 @@ done_generating: LOG_DISAS("\n"); if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, ctx.pc - pc_start, 0); + log_target_disas(cs, pc_start, ctx.pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-openrisc/translate.c b/target-openrisc/translate.c index dc76789785..a62cbf4011 100644 --- a/target-openrisc/translate.c +++ b/target-openrisc/translate.c @@ -1770,7 +1770,7 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("\n"); - log_target_disas(&cpu->env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); qemu_log("\nisize=%d osize=%d\n", dc->pc - pc_start, tcg_op_buf_count()); } diff --git a/target-ppc/translate.c b/target-ppc/translate.c index 8f255ea5c2..84c5cead6b 100644 --- a/target-ppc/translate.c +++ b/target-ppc/translate.c @@ -11607,7 +11607,7 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, flags = env->bfd_mach; flags |= ctx.le_mode << 16; qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, ctx.nip - pc_start, flags); + log_target_disas(cs, pc_start, ctx.nip - pc_start, flags); qemu_log("\n"); } #endif diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index b02ff8d61d..135111a2c4 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -29,6 +29,7 @@ #include <asm/ptrace.h> #include "qemu-common.h" +#include "qemu/error-report.h" #include "qemu/timer.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" @@ -36,7 +37,6 @@ #include "cpu.h" #include "sysemu/device_tree.h" #include "qapi/qmp/qjson.h" -#include "monitor/monitor.h" #include "exec/gdbstub.h" #include "exec/address-spaces.h" #include "trace.h" diff --git a/target-s390x/translate.c b/target-s390x/translate.c index 42f52c70c6..c748290d5c 100644 --- a/target-s390x/translate.c +++ b/target-s390x/translate.c @@ -5446,7 +5446,7 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu, #if defined(S390X_DEBUG_DISAS) if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc.pc - pc_start, 1); + log_target_disas(cs, pc_start, dc.pc - pc_start, 1); qemu_log("\n"); } #endif diff --git a/target-sh4/translate.c b/target-sh4/translate.c index 28259f9e14..3b4a1b5cea 100644 --- a/target-sh4/translate.c +++ b/target-sh4/translate.c @@ -1961,7 +1961,7 @@ gen_intermediate_code_internal(SuperHCPU *cpu, TranslationBlock *tb, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN:\n"); /* , lookup_symbol(pc_start)); */ - log_target_disas(env, pc_start, ctx.pc - pc_start, 0); + log_target_disas(cs, pc_start, ctx.pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-sparc/translate.c b/target-sparc/translate.c index 3708c0148e..c58dd4e95b 100644 --- a/target-sparc/translate.c +++ b/target-sparc/translate.c @@ -5334,7 +5334,7 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu, if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("--------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, last_pc + 4 - pc_start, 0); + log_target_disas(cs, pc_start, last_pc + 4 - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-tricore/translate.c b/target-tricore/translate.c index 8d41239617..7dc7a325b4 100644 --- a/target-tricore/translate.c +++ b/target-tricore/translate.c @@ -8324,7 +8324,7 @@ gen_intermediate_code_internal(TriCoreCPU *cpu, struct TranslationBlock *tb, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, ctx.pc - pc_start, 0); + log_target_disas(cs, pc_start, ctx.pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-unicore32/translate.c b/target-unicore32/translate.c index 9efcff5faf..2fc78e6f3e 100644 --- a/target-unicore32/translate.c +++ b/target-unicore32/translate.c @@ -2039,7 +2039,7 @@ done_generating: if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-xtensa/translate.c b/target-xtensa/translate.c index 3d52079233..86e4849fb6 100644 --- a/target-xtensa/translate.c +++ b/target-xtensa/translate.c @@ -3138,7 +3138,7 @@ void gen_intermediate_code_internal(XtensaCPU *cpu, if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc.pc - pc_start, 0); + log_target_disas(cs, pc_start, dc.pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 60e5b22a98..1cfffa5934 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -1013,7 +1013,7 @@ static void keyword_literal(void) g_assert(qobject_type(obj) == QTYPE_QBOOL); qbool = qobject_to_qbool(obj); - g_assert(qbool_get_int(qbool) != 0); + g_assert(qbool_get_bool(qbool) == true); str = qobject_to_json(obj); g_assert(strcmp(qstring_get_str(str), "true") == 0); @@ -1026,7 +1026,7 @@ static void keyword_literal(void) g_assert(qobject_type(obj) == QTYPE_QBOOL); qbool = qobject_to_qbool(obj); - g_assert(qbool_get_int(qbool) == 0); + g_assert(qbool_get_bool(qbool) == false); str = qobject_to_json(obj); g_assert(strcmp(qstring_get_str(str), "false") == 0); @@ -1039,16 +1039,17 @@ static void keyword_literal(void) g_assert(qobject_type(obj) == QTYPE_QBOOL); qbool = qobject_to_qbool(obj); - g_assert(qbool_get_int(qbool) == 0); + g_assert(qbool_get_bool(qbool) == false); QDECREF(qbool); - obj = qobject_from_jsonf("%i", true); + /* Test that non-zero values other than 1 get collapsed to true */ + obj = qobject_from_jsonf("%i", 2); g_assert(obj != NULL); g_assert(qobject_type(obj) == QTYPE_QBOOL); qbool = qobject_to_qbool(obj); - g_assert(qbool_get_int(qbool) != 0); + g_assert(qbool_get_bool(qbool) == true); QDECREF(qbool); diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c index ebeee5d589..1c753d9824 100644 --- a/tests/test-opts-visitor.c +++ b/tests/test-opts-visitor.c @@ -39,7 +39,8 @@ setup_fixture(OptsVisitorFixture *f, gconstpointer test_data) QemuOpts *opts; OptsVisitor *ov; - opts = qemu_opts_parse(qemu_find_opts("userdef"), opts_string, 0); + opts = qemu_opts_parse(qemu_find_opts("userdef"), opts_string, false, + NULL); g_assert(opts != NULL); ov = opts_visitor_new(opts); diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index da564923d0..0c1136d1b2 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -323,7 +323,7 @@ static void test_qemu_opt_unset(void) int ret; /* dynamically initialized (parsed) opts */ - opts = qemu_opts_parse(&opts_list_03, "key=value", 0); + opts = qemu_opts_parse(&opts_list_03, "key=value", false, NULL); g_assert(opts != NULL); /* check default/parsed value */ diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index cb354e6e81..1ee40e148a 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -60,8 +60,8 @@ void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque) switch (qobject_type(obj1)) { case QTYPE_QBOOL: - d->result = (qbool_get_int(qobject_to_qbool(obj1)) == - qbool_get_int(qobject_to_qbool(obj2))); + d->result = (qbool_get_bool(qobject_to_qbool(obj1)) == + qbool_get_bool(qobject_to_qbool(obj2))); return; case QTYPE_QINT: d->result = (qint_get_int(qobject_to_qint(obj1)) == diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c index f8c9367e48..87ba350b43 100644 --- a/tests/test-qmp-output-visitor.c +++ b/tests/test-qmp-output-visitor.c @@ -72,7 +72,7 @@ static void test_visitor_out_bool(TestOutputVisitorData *data, obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); g_assert(qobject_type(obj) == QTYPE_QBOOL); - g_assert(qbool_get_int(qobject_to_qbool(obj)) == value); + g_assert(qbool_get_bool(qobject_to_qbool(obj)) == value); qobject_decref(obj); } @@ -223,7 +223,7 @@ static void test_visitor_out_struct(TestOutputVisitorData *data, qdict = qobject_to_qdict(obj); g_assert_cmpint(qdict_size(qdict), ==, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42); - g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, 0); + g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, false); g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo"); QDECREF(qdict); @@ -662,7 +662,7 @@ static void check_native_list(QObject *qobj, tmp = qlist_peek(qlist); g_assert(tmp); qvalue = qobject_to_qbool(tmp); - g_assert_cmpint(qbool_get_int(qvalue), ==, (i % 3 == 0) ? 1 : 0); + g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0); qobject_decref(qlist_pop(qlist)); } break; @@ -13,11 +13,11 @@ */ #include "config-host.h" -#include "monitor/monitor.h" #include "qapi/qmp/qerror.h" #include "sysemu/tpm_backend.h" #include "sysemu/tpm.h" #include "qemu/config-file.h" +#include "qemu/error-report.h" #include "qmp-commands.h" static QLIST_HEAD(, TPMBackend) tpm_backends = @@ -140,21 +140,21 @@ static int configure_tpm(QemuOpts *opts) id = qemu_opts_id(opts); if (id == NULL) { - qerror_report(QERR_MISSING_PARAMETER, "id"); + error_report(QERR_MISSING_PARAMETER, "id"); return 1; } value = qemu_opt_get(opts, "type"); if (!value) { - qerror_report(QERR_MISSING_PARAMETER, "type"); + error_report(QERR_MISSING_PARAMETER, "type"); tpm_display_backend_drivers(); return 1; } be = tpm_get_backend_driver(value); if (be == NULL) { - qerror_report(QERR_INVALID_PARAMETER_VALUE, "type", - "a TPM backend type"); + error_report(QERR_INVALID_PARAMETER_VALUE, + "type", "a TPM backend type"); tpm_display_backend_drivers(); return 1; } @@ -228,7 +228,7 @@ int tpm_config_parse(QemuOptsList *opts_list, const char *optarg) tpm_display_backend_drivers(); return -1; } - opts = qemu_opts_parse(opts_list, optarg, 1); + opts = qemu_opts_parse_noisily(opts_list, optarg, true); if (!opts) { return -1; } diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 3e9bb380e5..e50f2968e1 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -23,7 +23,6 @@ */ #include "sysemu/sysemu.h" -#include "monitor/monitor.h" #include "ui/console.h" #include "qapi/error.h" #include "qmp-commands.h" diff --git a/ui/input.c b/ui/input.c index eeeabe844c..1a552d1de1 100644 --- a/ui/input.c +++ b/ui/input.c @@ -1,6 +1,7 @@ #include "hw/qdev.h" #include "sysemu/sysemu.h" #include "qapi-types.h" +#include "qemu/error-report.h" #include "qmp-commands.h" #include "trace.h" #include "ui/input.h" @@ -84,7 +85,8 @@ void qemu_input_handler_bind(QemuInputHandlerState *s, dev = qdev_find_recursive(sysbus_get_default(), device_id); if (dev == NULL) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device_id); + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device_id); return; } diff --git a/ui/spice-core.c b/ui/spice-core.c index a30da3cf9f..bf4fd07499 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -22,6 +22,7 @@ #include "qemu-common.h" #include "ui/qemu-spice.h" +#include "qemu/error-report.h" #include "qemu/thread.h" #include "qemu/timer.h" #include "qemu/queue.h" diff --git a/ui/spice-display.c b/ui/spice-display.c index cc4a6ce98d..0360abfd2c 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -19,7 +19,6 @@ #include "ui/qemu-spice.h" #include "qemu/timer.h" #include "qemu/queue.h" -#include "monitor/monitor.h" #include "ui/console.h" #include "sysemu/sysemu.h" #include "trace.h" diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c index c8ee203495..22c9abce55 100644 --- a/ui/vnc-jobs.c +++ b/ui/vnc-jobs.c @@ -29,6 +29,7 @@ #include "vnc.h" #include "vnc-jobs.h" #include "qemu/sockets.h" +#include "block/aio.h" /* * Locking: @@ -29,10 +29,12 @@ #include "trace.h" #include "hw/qdev.h" #include "sysemu/sysemu.h" +#include "qemu/error-report.h" #include "qemu/sockets.h" #include "qemu/timer.h" #include "qemu/acl.h" #include "qemu/config-file.h" +#include "qapi/qmp/qerror.h" #include "qapi/qmp/types.h" #include "qmp-commands.h" #include "qemu/osdep.h" @@ -427,7 +429,7 @@ VncInfo *qmp_query_vnc(Error **errp) if (getsockname(vd->lsock, (struct sockaddr *)&sa, &salen) == -1) { - error_set(errp, QERR_UNDEFINED_ERROR); + error_setg(errp, QERR_UNDEFINED_ERROR); goto out_error; } @@ -435,7 +437,7 @@ VncInfo *qmp_query_vnc(Error **errp) host, sizeof(host), serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV) < 0) { - error_set(errp, QERR_UNDEFINED_ERROR); + error_setg(errp, QERR_UNDEFINED_ERROR); goto out_error; } @@ -3749,10 +3751,10 @@ static void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts *opts) qemu_opts_set_id(opts, id); } -QemuOpts *vnc_parse_func(const char *str) +QemuOpts *vnc_parse(const char *str, Error **errp) { QemuOptsList *olist = qemu_find_opts("vnc"); - QemuOpts *opts = qemu_opts_parse(olist, str, 1); + QemuOpts *opts = qemu_opts_parse(olist, str, true, errp); const char *id; if (!opts) { diff --git a/util/osdep.c b/util/osdep.c index f938b69466..0092bb61b9 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -47,6 +47,7 @@ extern int madvise(caddr_t, size_t, int); #include "qemu-common.h" #include "qemu/sockets.h" +#include "qemu/error-report.h" #include "monitor/monitor.h" static bool fips_enabled = false; diff --git a/util/qemu-config.c b/util/qemu-config.c index 6cfdd7204a..5fcfd0e6ac 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -2,7 +2,6 @@ #include "qemu/error-report.h" #include "qemu/option.h" #include "qemu/config-file.h" -#include "qapi/qmp/qerror.h" #include "qapi/error.h" #include "qmp-commands.h" diff --git a/util/qemu-error.c b/util/qemu-error.c index 9bba5f53d8..77ea6c6145 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -12,6 +12,7 @@ #include <stdio.h> #include "monitor/monitor.h" +#include "qemu/error-report.h" /* * Print to current monitor if we have one, else to stderr. @@ -202,7 +203,7 @@ bool enable_timestamp_msg; * Format arguments like vsprintf(). The result should not contain * newlines. * Prepend the current location and append a newline. - * It's wrong to call this in a QMP monitor. Use qerror_report() there. + * It's wrong to call this in a QMP monitor. Use error_setg() there. */ void error_vreport(const char *fmt, va_list ap) { @@ -226,7 +227,7 @@ void error_vreport(const char *fmt, va_list ap) * Format arguments like sprintf(). The result should not contain * newlines. * Prepend the current location and append a newline. - * It's wrong to call this in a QMP monitor. Use qerror_report() there. + * It's wrong to call this in a QMP monitor. Use error_setg() there. */ void error_report(const char *fmt, ...) { diff --git a/util/qemu-option.c b/util/qemu-option.c index 840f5f7a5b..efe9d279c4 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -132,7 +132,8 @@ static void parse_option_bool(const char *name, const char *value, bool *ret, } else if (!strcmp(value, "off")) { *ret = 0; } else { - error_set(errp,QERR_INVALID_PARAMETER_VALUE, name, "'on' or 'off'"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name, "'on' or 'off'"); } } else { *ret = 1; @@ -148,12 +149,12 @@ static void parse_option_number(const char *name, const char *value, if (value != NULL) { number = strtoull(value, &postfix, 0); if (*postfix != '\0') { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); return; } *ret = number; } else { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); } } @@ -198,7 +199,7 @@ void parse_option_size(const char *name, const char *value, *ret = (uint64_t) sizef; break; default: - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size"); #if 0 /* conversion from qerror_report() to error_set() broke this: */ error_printf_unless_qmp("You may use k, M, G or T suffixes for " "kilobytes, megabytes, gigabytes and terabytes.\n"); @@ -206,7 +207,7 @@ void parse_option_size(const char *name, const char *value, return; } } else { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size"); } } @@ -527,7 +528,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value, desc = find_desc_by_name(opts->list->desc, name); if (!desc && !opts_accepts_any(opts)) { - error_set(errp, QERR_INVALID_PARAMETER, name); + error_setg(errp, QERR_INVALID_PARAMETER, name); return; } @@ -563,7 +564,7 @@ void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val, opt = g_malloc0(sizeof(*opt)); opt->desc = find_desc_by_name(desc, name); if (!opt->desc && !opts_accepts_any(opts)) { - error_set(errp, QERR_INVALID_PARAMETER, name); + error_setg(errp, QERR_INVALID_PARAMETER, name); g_free(opt); return; } @@ -584,7 +585,7 @@ void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val, opt = g_malloc0(sizeof(*opt)); opt->desc = find_desc_by_name(desc, name); if (!opt->desc && !opts_accepts_any(opts)) { - error_set(errp, QERR_INVALID_PARAMETER, name); + error_setg(errp, QERR_INVALID_PARAMETER, name); g_free(opt); return; } @@ -640,7 +641,8 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, if (id) { if (!id_wellformed(id)) { - error_set(errp,QERR_INVALID_PARAMETER_VALUE, "id", "an identifier"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", + "an identifier"); #if 0 /* conversion from qerror_report() to error_set() broke this: */ error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n"); #endif @@ -820,7 +822,7 @@ void qemu_opts_do_parse(QemuOpts *opts, const char *params, } static QemuOpts *opts_parse(QemuOptsList *list, const char *params, - int permit_abbrev, bool defaults, Error **errp) + bool permit_abbrev, bool defaults, Error **errp) { const char *firstname; char value[1024], *id = NULL; @@ -867,19 +869,32 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params, * Create a QemuOpts in @list and with options parsed from @params. * If @permit_abbrev, the first key=value in @params may omit key=, * and is treated as if key was @list->implied_opt_name. - * Report errors with qerror_report_err(). + * On error, store an error object through @errp if non-null. * Return the new QemuOpts on success, null pointer on error. */ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, - int permit_abbrev) + bool permit_abbrev, Error **errp) +{ + return opts_parse(list, params, permit_abbrev, false, errp); +} + +/** + * Create a QemuOpts in @list and with options parsed from @params. + * If @permit_abbrev, the first key=value in @params may omit key=, + * and is treated as if key was @list->implied_opt_name. + * Report errors with error_report_err(). This is inappropriate in + * QMP context. Do not use this function there! + * Return the new QemuOpts on success, null pointer on error. + */ +QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, + bool permit_abbrev) { Error *err = NULL; QemuOpts *opts; opts = opts_parse(list, params, permit_abbrev, false, &err); - if (!opts) { - qerror_report_err(err); - error_free(err); + if (err) { + error_report_err(err); } return opts; } @@ -927,7 +942,7 @@ static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque) break; case QTYPE_QBOOL: pstrcpy(buf, sizeof(buf), - qbool_get_int(qobject_to_qbool(obj)) ? "on" : "off"); + qbool_get_bool(qobject_to_qbool(obj)) ? "on" : "off"); value = buf; break; default: @@ -1042,7 +1057,7 @@ void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp) QTAILQ_FOREACH(opt, &opts->head, next) { opt->desc = find_desc_by_name(desc, opt->name); if (!opt->desc) { - error_set(errp, QERR_INVALID_PARAMETER, opt->name); + error_setg(errp, QERR_INVALID_PARAMETER, opt->name); return; } @@ -58,6 +58,7 @@ int main(int argc, char **argv) #include <glib.h> +#include "qemu/error-report.h" #include "qemu/sockets.h" #include "hw/hw.h" #include "hw/boards.h" @@ -990,13 +991,13 @@ static int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) if (qemu_opt_get_bool(opts, "enable", false)) { #ifdef CONFIG_SECCOMP if (seccomp_start() < 0) { - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "failed to install seccomp syscall filter in the kernel"); + error_report("failed to install seccomp syscall filter " + "in the kernel"); return -1; } #else - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "sandboxing request but seccomp is not compiled into this build"); + error_report("sandboxing request but seccomp is not compiled " + "into this build"); return -1; #endif } @@ -1044,14 +1045,12 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) fd_opaque = qemu_opt_get(opts, "opaque"); if (fd < 0) { - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "fd option is required and must be non-negative"); + error_report("fd option is required and must be non-negative"); return -1; } if (fd <= STDERR_FILENO) { - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "fd cannot be a standard I/O stream"); + error_report("fd cannot be a standard I/O stream"); return -1; } @@ -1061,14 +1060,12 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) */ flags = fcntl(fd, F_GETFD); if (flags == -1 || (flags & FD_CLOEXEC)) { - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "fd is not valid or already in use"); + error_report("fd is not valid or already in use"); return -1; } if (fdset_id < 0) { - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "set option is required and must be non-negative"); + error_report("set option is required and must be non-negative"); return -1; } @@ -1081,8 +1078,7 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) } #endif if (dupfd == -1) { - qerror_report(ERROR_CLASS_GENERIC_ERROR, - "Error duplicating fd: %s", strerror(errno)); + error_report("Error duplicating fd: %s", strerror(errno)); return -1; } @@ -2046,6 +2042,7 @@ static void select_vgahw (const char *p) static DisplayType select_display(const char *p) { + Error *err = NULL; const char *opts; DisplayType display = DT_DEFAULT; @@ -2102,34 +2099,35 @@ static DisplayType select_display(const char *p) } } else { invalid_sdl_args: - fprintf(stderr, "Invalid SDL option string: %s\n", p); + error_report("Invalid SDL option string"); exit(1); } opts = nextopt; } #else - fprintf(stderr, "SDL support is disabled\n"); + error_report("SDL support is disabled"); exit(1); #endif } else if (strstart(p, "vnc", &opts)) { #ifdef CONFIG_VNC if (*opts == '=') { - if (vnc_parse_func(opts+1) == NULL) { + if (vnc_parse(opts + 1, &err) == NULL) { + error_report_err(err); exit(1); } } else { - fprintf(stderr, "VNC requires a display argument vnc=<display>\n"); + error_report("VNC requires a display argument vnc=<display>"); exit(1); } #else - fprintf(stderr, "VNC support is disabled\n"); + error_report("VNC support is disabled"); exit(1); #endif } else if (strstart(p, "curses", &opts)) { #ifdef CONFIG_CURSES display = DT_CURSES; #else - fprintf(stderr, "Curses support is disabled\n"); + error_report("Curses support is disabled"); exit(1); #endif } else if (strstart(p, "gtk", &opts)) { @@ -2158,19 +2156,19 @@ static DisplayType select_display(const char *p) } } else { invalid_gtk_args: - fprintf(stderr, "Invalid GTK option string: %s\n", p); + error_report("Invalid GTK option string"); exit(1); } opts = nextopt; } #else - fprintf(stderr, "GTK support is disabled\n"); + error_report("GTK support is disabled"); exit(1); #endif } else if (strstart(p, "none", &opts)) { display = DT_NONE; } else { - fprintf(stderr, "Unknown display type: %s\n", p); + error_report("Unknown display type"); exit(1); } @@ -2188,7 +2186,8 @@ static int balloon_parse(const char *arg) if (!strncmp(arg, "virtio", 6)) { if (arg[6] == ',') { /* have params -> parse them */ - opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("device"), arg + 7, + false); if (!opts) return -1; } else { @@ -2276,11 +2275,14 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) { + Error *err = NULL; DeviceState *dev; - dev = qdev_device_add(opts); - if (!dev) + dev = qdev_device_add(opts, &err); + if (!dev) { + error_report_err(err); return -1; + } object_unref(OBJECT(dev)); return 0; } @@ -3064,7 +3066,7 @@ int main(int argc, char **argv, char **envp) switch(popt->index) { case QEMU_OPTION_no_kvm_irqchip: { olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "kernel_irqchip=off", 0); + qemu_opts_parse_noisily(olist, "kernel_irqchip=off", false); break; } case QEMU_OPTION_cpu: @@ -3181,7 +3183,8 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_numa: - opts = qemu_opts_parse(qemu_find_opts("numa"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("numa"), + optarg, true); if (!opts) { exit(1); } @@ -3232,7 +3235,8 @@ int main(int argc, char **argv, char **envp) drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); break; case QEMU_OPTION_boot: - opts = qemu_opts_parse(qemu_find_opts("boot-opts"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"), + optarg, true); if (!opts) { exit(1); } @@ -3257,7 +3261,8 @@ int main(int argc, char **argv, char **envp) break; #ifdef CONFIG_LIBISCSI case QEMU_OPTION_iscsi: - opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"), + optarg, false); if (!opts) { exit(1); } @@ -3293,8 +3298,8 @@ int main(int argc, char **argv, char **envp) exit(0); break; case QEMU_OPTION_m: - opts = qemu_opts_parse(qemu_find_opts("memory"), - optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), + optarg, true); if (!opts) { exit(EXIT_FAILURE); } @@ -3406,14 +3411,16 @@ int main(int argc, char **argv, char **envp) default_monitor = 0; break; case QEMU_OPTION_mon: - opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg, + true); if (!opts) { exit(1); } default_monitor = 0; break; case QEMU_OPTION_chardev: - opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), + optarg, true); if (!opts) { exit(1); } @@ -3424,7 +3431,7 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "fsdev is not supported by this qemu build.\n"); exit(1); } - opts = qemu_opts_parse(olist, optarg, 1); + opts = qemu_opts_parse_noisily(olist, optarg, true); if (!opts) { exit(1); } @@ -3439,7 +3446,7 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "virtfs is not supported by this qemu build.\n"); exit(1); } - opts = qemu_opts_parse(olist, optarg, 1); + opts = qemu_opts_parse_noisily(olist, optarg, true); if (!opts) { exit(1); } @@ -3599,40 +3606,43 @@ int main(int argc, char **argv, char **envp) break; } case QEMU_OPTION_acpitable: - opts = qemu_opts_parse(qemu_find_opts("acpi"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"), + optarg, true); if (!opts) { exit(1); } do_acpitable_option(opts); break; case QEMU_OPTION_smbios: - opts = qemu_opts_parse(qemu_find_opts("smbios"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"), + optarg, false); if (!opts) { exit(1); } do_smbios_option(opts); break; case QEMU_OPTION_fwcfg: - opts = qemu_opts_parse(qemu_find_opts("fw_cfg"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"), + optarg, true); if (opts == NULL) { exit(1); } break; case QEMU_OPTION_enable_kvm: olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "accel=kvm", 0); + qemu_opts_parse_noisily(olist, "accel=kvm", false); break; case QEMU_OPTION_M: case QEMU_OPTION_machine: olist = qemu_find_opts("machine"); - opts = qemu_opts_parse(olist, optarg, 1); + opts = qemu_opts_parse_noisily(olist, optarg, true); if (!opts) { exit(1); } break; case QEMU_OPTION_no_kvm: olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "accel=tcg", 0); + qemu_opts_parse_noisily(olist, "accel=tcg", false); break; case QEMU_OPTION_no_kvm_pit: { fprintf(stderr, "Warning: KVM PIT can no longer be disabled " @@ -3656,26 +3666,32 @@ int main(int argc, char **argv, char **envp) } case QEMU_OPTION_usb: olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "usb=on", 0); + qemu_opts_parse_noisily(olist, "usb=on", false); break; case QEMU_OPTION_usbdevice: olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "usb=on", 0); + qemu_opts_parse_noisily(olist, "usb=on", false); add_device_config(DEV_USB, optarg); break; case QEMU_OPTION_device: - if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) { + if (!qemu_opts_parse_noisily(qemu_find_opts("device"), + optarg, true)) { exit(1); } break; case QEMU_OPTION_smp: - if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg, 1)) { + if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"), + optarg, true)) { exit(1); } break; case QEMU_OPTION_vnc: + { #ifdef CONFIG_VNC - if (vnc_parse_func(optarg) == NULL) { + Error *local_err = NULL; + + if (vnc_parse(optarg, &local_err) == NULL) { + error_report_err(local_err); exit(1); } #else @@ -3683,6 +3699,7 @@ int main(int argc, char **argv, char **envp) exit(1); #endif break; + } case QEMU_OPTION_no_acpi: acpi_enabled = 0; break; @@ -3717,7 +3734,8 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "Too many option ROMs\n"); exit(1); } - opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"), + optarg, true); if (!opts) { exit(1); } @@ -3736,8 +3754,8 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_semihosting_config: semihosting.enabled = true; - opts = qemu_opts_parse(qemu_find_opts("semihosting-config"), - optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"), + optarg, false); if (opts != NULL) { semihosting.enabled = qemu_opt_get_bool(opts, "enable", true); @@ -3772,7 +3790,8 @@ int main(int argc, char **argv, char **envp) "is no longer supported.\n"); break; case QEMU_OPTION_name: - opts = qemu_opts_parse(qemu_find_opts("name"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("name"), + optarg, true); if (!opts) { exit(1); } @@ -3797,7 +3816,8 @@ int main(int argc, char **argv, char **envp) configure_rtc_date_offset(optarg, 1); break; case QEMU_OPTION_rtc: - opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg, + false); if (!opts) { exit(1); } @@ -3810,8 +3830,8 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_icount: - icount_opts = qemu_opts_parse(qemu_find_opts("icount"), - optarg, 1); + icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"), + optarg, true); if (!icount_opts) { exit(1); } @@ -3848,7 +3868,8 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_trace: { - opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("trace"), + optarg, false); if (!opts) { exit(1); } @@ -3872,7 +3893,7 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "spice is not supported by this qemu build.\n"); exit(1); } - opts = qemu_opts_parse(olist, optarg, 0); + opts = qemu_opts_parse_noisily(olist, optarg, false); if (!opts) { exit(1); } @@ -3903,14 +3924,16 @@ int main(int argc, char **argv, char **envp) qtest_log = optarg; break; case QEMU_OPTION_sandbox: - opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("sandbox"), + optarg, true); if (!opts) { exit(1); } break; case QEMU_OPTION_add_fd: #ifndef _WIN32 - opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"), + optarg, false); if (!opts) { exit(1); } @@ -3921,20 +3944,23 @@ int main(int argc, char **argv, char **envp) #endif break; case QEMU_OPTION_object: - opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("object"), + optarg, true); if (!opts) { exit(1); } break; case QEMU_OPTION_realtime: - opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("realtime"), + optarg, false); if (!opts) { exit(1); } enable_mlock = qemu_opt_get_bool(opts, "mlock", true); break; case QEMU_OPTION_msg: - opts = qemu_opts_parse(qemu_find_opts("msg"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg, + false); if (!opts) { exit(1); } @@ -4186,7 +4212,7 @@ int main(int argc, char **argv, char **envp) #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA) display_type = DT_SDL; #elif defined(CONFIG_VNC) - vnc_parse_func("localhost:0,to=99,id=default"); + vnc_parse("localhost:0,to=99,id=default", &error_abort); show_vnc_port = 1; #else display_type = DT_NONE; |