From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PULL 07/12] qapi: return a 'missing parameter' error
Date: Fri, 7 Oct 2016 14:09:14 +0200 [thread overview]
Message-ID: <1475842159-26039-8-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1475842159-26039-1-git-send-email-armbru@redhat.com>
From: Marc-André Lureau <marcandre.lureau@redhat.com>
The 'old' dispatch code returned a QERR_MISSING_PARAMETER for missing
parameters, but the qapi qmp_dispatch() code uses
QERR_INVALID_PARAMETER_TYPE.
Improve qapi code to return QERR_MISSING_PARAMETER where
appropriate.
Fix expected error message in iotests.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20160930095948.3154-4-marcandre.lureau@redhat.com>
[Drop incorrect error_setg() from qmp_input_type_any() and
qmp_input_type_null()]
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
qapi/qmp-input-visitor.c | 67 +++++++++++++++++++++++++++++++++-------------
tests/qemu-iotests/087.out | 2 +-
2 files changed, 49 insertions(+), 20 deletions(-)
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index fe097c9..37a8e1f 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -56,7 +56,7 @@ static QmpInputVisitor *to_qiv(Visitor *v)
static QObject *qmp_input_get_object(QmpInputVisitor *qiv,
const char *name,
- bool consume)
+ bool consume, Error **errp)
{
StackObject *tos;
QObject *qobj;
@@ -80,6 +80,9 @@ static QObject *qmp_input_get_object(QmpInputVisitor *qiv,
bool removed = g_hash_table_remove(tos->h, name);
assert(removed);
}
+ if (!ret) {
+ error_setg(errp, QERR_MISSING_PARAMETER, name);
+ }
} else {
assert(qobject_type(qobj) == QTYPE_QLIST);
assert(!name);
@@ -165,13 +168,16 @@ static void qmp_input_start_struct(Visitor *v, const char *name, void **obj,
size_t size, Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qmp_input_get_object(qiv, name, true);
+ QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
Error *err = NULL;
if (obj) {
*obj = NULL;
}
- if (!qobj || qobject_type(qobj) != QTYPE_QDICT) {
+ if (!qobj) {
+ return;
+ }
+ if (qobject_type(qobj) != QTYPE_QDICT) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"QDict");
return;
@@ -193,10 +199,13 @@ static void qmp_input_start_list(Visitor *v, const char *name,
GenericList **list, size_t size, Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qmp_input_get_object(qiv, name, true);
+ QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
const QListEntry *entry;
- if (!qobj || qobject_type(qobj) != QTYPE_QLIST) {
+ if (!qobj) {
+ return;
+ }
+ if (qobject_type(qobj) != QTYPE_QLIST) {
if (list) {
*list = NULL;
}
@@ -234,11 +243,10 @@ static void qmp_input_start_alternate(Visitor *v, const char *name,
bool promote_int, Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qmp_input_get_object(qiv, name, false);
+ QObject *qobj = qmp_input_get_object(qiv, name, false, errp);
if (!qobj) {
*obj = NULL;
- error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null");
return;
}
*obj = g_malloc0(size);
@@ -252,8 +260,13 @@ static void qmp_input_type_int64(Visitor *v, const char *name, int64_t *obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
- QInt *qint = qobject_to_qint(qmp_input_get_object(qiv, name, true));
+ QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
+ QInt *qint;
+ if (!qobj) {
+ return;
+ }
+ qint = qobject_to_qint(qobj);
if (!qint) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"integer");
@@ -268,8 +281,13 @@ static void qmp_input_type_uint64(Visitor *v, const char *name, uint64_t *obj,
{
/* FIXME: qobject_to_qint mishandles values over INT64_MAX */
QmpInputVisitor *qiv = to_qiv(v);
- QInt *qint = qobject_to_qint(qmp_input_get_object(qiv, name, true));
+ QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
+ QInt *qint;
+ if (!qobj) {
+ return;
+ }
+ qint = qobject_to_qint(qobj);
if (!qint) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"integer");
@@ -283,8 +301,13 @@ static void qmp_input_type_bool(Visitor *v, const char *name, bool *obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
- QBool *qbool = qobject_to_qbool(qmp_input_get_object(qiv, name, true));
+ QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
+ QBool *qbool;
+ if (!qobj) {
+ return;
+ }
+ qbool = qobject_to_qbool(qobj);
if (!qbool) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"boolean");
@@ -298,10 +321,15 @@ static void qmp_input_type_str(Visitor *v, const char *name, char **obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
- QString *qstr = qobject_to_qstring(qmp_input_get_object(qiv, name, true));
+ QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
+ QString *qstr;
+ *obj = NULL;
+ if (!qobj) {
+ return;
+ }
+ qstr = qobject_to_qstring(qobj);
if (!qstr) {
- *obj = NULL;
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"string");
return;
@@ -314,10 +342,13 @@ static void qmp_input_type_number(Visitor *v, const char *name, double *obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qmp_input_get_object(qiv, name, true);
+ QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QInt *qint;
QFloat *qfloat;
+ if (!qobj) {
+ return;
+ }
qint = qobject_to_qint(qobj);
if (qint) {
*obj = qint_get_int(qobject_to_qint(qobj));
@@ -338,11 +369,10 @@ static void qmp_input_type_any(Visitor *v, const char *name, QObject **obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qmp_input_get_object(qiv, name, true);
+ QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
+ *obj = NULL;
if (!qobj) {
- error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null");
- *obj = NULL;
return;
}
@@ -353,10 +383,9 @@ static void qmp_input_type_any(Visitor *v, const char *name, QObject **obj,
static void qmp_input_type_null(Visitor *v, const char *name, Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qmp_input_get_object(qiv, name, true);
+ QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
if (!qobj) {
- error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null");
return;
}
@@ -369,7 +398,7 @@ static void qmp_input_type_null(Visitor *v, const char *name, Error **errp)
static void qmp_input_optional(Visitor *v, const char *name, bool *present)
{
QmpInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qmp_input_get_object(qiv, name, false);
+ QObject *qobj = qmp_input_get_object(qiv, name, false, NULL);
if (!qobj) {
*present = false;
diff --git a/tests/qemu-iotests/087.out b/tests/qemu-iotests/087.out
index cd02eae..dc6baf9 100644
--- a/tests/qemu-iotests/087.out
+++ b/tests/qemu-iotests/087.out
@@ -56,7 +56,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 encryption=on
Testing: -S
QMP_VERSION
{"return": {}}
-{"error": {"class": "GenericError", "desc": "Invalid parameter type for 'driver', expected: string"}}
+{"error": {"class": "GenericError", "desc": "Parameter 'driver' is missing"}}
{"return": {}}
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"}
--
2.5.5
next prev parent reply other threads:[~2016-10-07 12:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-07 12:09 [Qemu-devel] [PULL 00/12] QAPI patches for 2016-10-07 Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 01/12] qmp: fix object-add assert() without props Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 02/12] qapi: Fix crash when 'any' or 'null' parameter is missing Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 03/12] tests/test-qmp-input-strict: Cover missing struct members Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 04/12] tests: start generic qemu-qmp tests Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 05/12] qapi: add assert about root value Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 06/12] qapi: assert list entry has a value Markus Armbruster
2016-10-07 12:09 ` Markus Armbruster [this message]
2016-10-07 12:09 ` [Qemu-devel] [PULL 08/12] MAINTAINERS: Pass the HMP staff from Luiz to David Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 09/12] MAINTAINERS: Pass the QObject staff from Luiz to Markus Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 10/12] qmp: Disable query-cpu-* commands when they're unavailable Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 11/12] docs: Belatedly update for move of qmp-commands.txt Markus Armbruster
2016-10-07 12:09 ` [Qemu-devel] [PULL 12/12] docs: Belatedly update for move of QMP/* to docs/ Markus Armbruster
2016-10-07 14:14 ` [Qemu-devel] [PULL 00/12] QAPI patches for 2016-10-07 Peter Maydell
2016-10-07 18:16 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475842159-26039-8-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).