Received: from eggs.gnu.org ([2001:4830:134:3::10]:48594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brmRQ-0000wX-Jo for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:41:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brmRK-0007Nz-Vg for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:40:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brmRK-0007Nf-M0 for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:40:54 -0400 From: Markus Armbruster References: <20160930095948.3154-1-marcandre.lureau@redhat.com> <20160930095948.3154-4-marcandre.lureau@redhat.com> Date: Wed, 05 Oct 2016 15:40:51 +0200 In-Reply-To: <20160930095948.3154-4-marcandre.lureau@redhat.com> (=?utf-8?Q?=22Marc-Andr=C3=A9?= Lureau"'s message of "Fri, 30 Sep 2016 13:59:48 +0400") Message-ID: <87twcqsyl8.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 3/3] qapi: return a 'missing parameter' error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Cc: qemu-devel@nongnu.org, berto@igalia.com Marc-Andr=C3=A9 Lureau writes: > 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=C3=A9 Lureau > Reviewed-by: Alberto Garcia > Reviewed-by: Eric Blake > --- > qapi/qmp-input-visitor.c | 69 ++++++++++++++++++++++++++++++++++------= ------ > tests/qemu-iotests/087.out | 2 +- > 2 files changed, 53 insertions(+), 18 deletions(-) > > diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c > index fe097c9..9b9b350 100644 > --- a/qapi/qmp-input-visitor.c > +++ b/qapi/qmp-input-visitor.c > @@ -56,7 +56,7 @@ static QmpInputVisitor *to_qiv(Visitor *v) >=20=20 > 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 *q= iv, > bool removed =3D g_hash_table_remove(tos->h, name); > assert(removed); > } > + if (!ret) { > + error_setg(errp, QERR_MISSING_PARAMETER, name); > + } > } else { > assert(qobject_type(qobj) =3D=3D QTYPE_QLIST); > assert(!name); Note for later: qmp_input_get_object() either returns non-null and leaves @errp alone, or it returns null and sets an error. > @@ -165,13 +168,16 @@ static void qmp_input_start_struct(Visitor *v, cons= t char *name, void **obj, > size_t size, Error **errp) > { > QmpInputVisitor *qiv =3D to_qiv(v); > - QObject *qobj =3D qmp_input_get_object(qiv, name, true); > + QObject *qobj =3D qmp_input_get_object(qiv, name, true, errp); > Error *err =3D NULL; >=20=20 > if (obj) { > *obj =3D NULL; > } > - if (!qobj || qobject_type(qobj) !=3D QTYPE_QDICT) { > + if (!qobj) { > + return; > + } > + if (qobject_type(qobj) !=3D QTYPE_QDICT) { > error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "nul= l", > "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 =3D to_qiv(v); > - QObject *qobj =3D qmp_input_get_object(qiv, name, true); > + QObject *qobj =3D qmp_input_get_object(qiv, name, true, errp); > const QListEntry *entry; >=20=20 > - if (!qobj || qobject_type(qobj) !=3D QTYPE_QLIST) { > + if (!qobj) { > + return; > + } > + if (qobject_type(qobj) !=3D QTYPE_QLIST) { > if (list) { > *list =3D NULL; > } > @@ -234,11 +243,10 @@ static void qmp_input_start_alternate(Visitor *v, c= onst char *name, > bool promote_int, Error **errp) > { > QmpInputVisitor *qiv =3D to_qiv(v); > - QObject *qobj =3D qmp_input_get_object(qiv, name, false); > + QObject *qobj =3D qmp_input_get_object(qiv, name, false, errp); >=20=20 > if (!qobj) { > *obj =3D NULL; > - error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null"); > return; > } > *obj =3D g_malloc0(size); > @@ -252,8 +260,13 @@ static void qmp_input_type_int64(Visitor *v, const c= har *name, int64_t *obj, > Error **errp) > { > QmpInputVisitor *qiv =3D to_qiv(v); > - QInt *qint =3D qobject_to_qint(qmp_input_get_object(qiv, name, true)= ); > + QObject *qobj =3D qmp_input_get_object(qiv, name, true, errp); > + QInt *qint; >=20=20 > + if (!qobj) { > + return; > + } > + qint =3D qobject_to_qint(qobj); > if (!qint) { > error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "nul= l", > "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 =3D to_qiv(v); > - QInt *qint =3D qobject_to_qint(qmp_input_get_object(qiv, name, true)= ); > + QObject *qobj =3D qmp_input_get_object(qiv, name, true, errp); > + QInt *qint; >=20=20 > + if (!qobj) { > + return; > + } > + qint =3D qobject_to_qint(qobj); > if (!qint) { > error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "nul= l", > "integer"); > @@ -283,8 +301,13 @@ static void qmp_input_type_bool(Visitor *v, const ch= ar *name, bool *obj, > Error **errp) > { > QmpInputVisitor *qiv =3D to_qiv(v); > - QBool *qbool =3D qobject_to_qbool(qmp_input_get_object(qiv, name, tr= ue)); > + QObject *qobj =3D qmp_input_get_object(qiv, name, true, errp); > + QBool *qbool; >=20=20 > + if (!qobj) { > + return; > + } > + qbool =3D qobject_to_qbool(qobj); > if (!qbool) { > error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "nul= l", > "boolean"); > @@ -298,10 +321,15 @@ static void qmp_input_type_str(Visitor *v, const ch= ar *name, char **obj, > Error **errp) > { > QmpInputVisitor *qiv =3D to_qiv(v); > - QString *qstr =3D qobject_to_qstring(qmp_input_get_object(qiv, name,= true)); > + QObject *qobj =3D qmp_input_get_object(qiv, name, true, errp); > + QString *qstr; >=20=20 > + *obj =3D NULL; > + if (!qobj) { > + return; > + } > + qstr =3D qobject_to_qstring(qobj); > if (!qstr) { > - *obj =3D NULL; > error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "nul= l", > "string"); > return; > @@ -314,10 +342,13 @@ static void qmp_input_type_number(Visitor *v, const= char *name, double *obj, > Error **errp) > { > QmpInputVisitor *qiv =3D to_qiv(v); > - QObject *qobj =3D qmp_input_get_object(qiv, name, true); > + QObject *qobj =3D qmp_input_get_object(qiv, name, true, errp); > QInt *qint; > QFloat *qfloat; >=20=20 > + if (!qobj) { > + return; > + } > qint =3D qobject_to_qint(qobj); > if (qint) { > *obj =3D qint_get_int(qobject_to_qint(qobj)); > @@ -338,11 +369,15 @@ static void qmp_input_type_any(Visitor *v, const ch= ar *name, QObject **obj, > Error **errp) > { > QmpInputVisitor *qiv =3D to_qiv(v); > - QObject *qobj =3D qmp_input_get_object(qiv, name, true); > + QObject *qobj =3D qmp_input_get_object(qiv, name, true, errp); > + > + *obj =3D NULL; > + if (!qobj) { > + return; > + } >=20=20 > if (!qobj) { > error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null"); > - *obj =3D NULL; > return; > } The second conditional is dead. Mismerge? The obvious fix is to drop it. Can do on commit. >=20=20 > @@ -353,7 +388,7 @@ 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 **er= rp) > { > QmpInputVisitor *qiv =3D to_qiv(v); > - QObject *qobj =3D qmp_input_get_object(qiv, name, true); > + QObject *qobj =3D qmp_input_get_object(qiv, name, true, errp); >=20=20 > if (!qobj) { > error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null"); return; When qmp_input_get_object() returns null, it also sets an error. The conditional then sets an error again, which is wrong and can fail the assertion in error_setv(). The obvious fix is to drop the error_setg(). Can do on commit. } if (qobject_type(qobj) !=3D QTYPE_QNULL) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "nul= l", "null"); } } > @@ -369,7 +404,7 @@ static void qmp_input_type_null(Visitor *v, const cha= r *name, Error **errp) > static void qmp_input_optional(Visitor *v, const char *name, bool *prese= nt) > { > QmpInputVisitor *qiv =3D to_qiv(v); > - QObject *qobj =3D qmp_input_get_object(qiv, name, false); > + QObject *qobj =3D qmp_input_get_object(qiv, name, false, NULL); >=20=20 > if (!qobj) { > *present =3D false; > diff --git a/tests/qemu-iotests/087.out b/tests/qemu-iotests/087.out > index bef6862..55ba6a7 100644 > --- a/tests/qemu-iotests/087.out > +++ b/tests/qemu-iotests/087.out > @@ -56,7 +56,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134= 217728 encryption=3Don > Testing: -S > QMP_VERSION > {"return": {}} > -{"error": {"class": "GenericError", "desc": "Invalid parameter type for = 'driver', expected: string"}} > +{"error": {"class": "GenericError", "desc": "Parameter 'driver' is missi= ng"}} > {"return": {}} > {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "even= t": "SHUTDOWN"}