[{"id":1778478,"web_url":"http://patchwork.ozlabs.org/comment/1778478/","msgid":"<87bmlp1mxl.fsf@dusky.pond.sub.org>","list_archive_url":null,"date":"2017-10-02T17:25:58","subject":"Re: [Qemu-devel] [PATCH 1/4] libqtest: add qmp_device_del()","submitter":{"id":2645,"url":"http://patchwork.ozlabs.org/api/people/2645/","name":"Markus Armbruster","email":"armbru@redhat.com"},"content":"Peter Xu <peterx@redhat.com> writes:\n\n> Device deletion is tricky since we'll get both a response and an event,\n> while the order of arrival may vary.  Provide a helper to handle this\n> complexity.\n>\n> Signed-off-by: Peter Xu <peterx@redhat.com>\n> ---\n>  tests/libqtest.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++\n>  tests/libqtest.h |  8 ++++++++\n>  2 files changed, 56 insertions(+)\n>\n> diff --git a/tests/libqtest.c b/tests/libqtest.c\n> index b9a1f18..a34d8c4 100644\n> --- a/tests/libqtest.c\n> +++ b/tests/libqtest.c\n> @@ -925,6 +925,54 @@ QDict *qmp(const char *fmt, ...)\n>      return response;\n>  }\n>  \n> +void qmp_device_del(const char *id)\n> +{\n> +    QDict *response1, *response2, *event = NULL;\n> +    char *cmd;\n> +\n> +    /*\n> +     * device deletion will get one response and one event. E.g.:\n> +     *\n> +     * {'execute': 'device_del','arguments': { 'id': 'scsi-hd'}}\n> +     *\n> +     * will get this one:\n> +     *\n> +     * {\"timestamp\": {\"seconds\": 1505289667, \"microseconds\": 569862},\n> +     *  \"event\": \"DEVICE_DELETED\", \"data\": {\"device\": \"scsi-hd\",\n> +     *  \"path\": \"/machine/peripheral/scsi-hd\"}}\n> +     *\n> +     * and this one:\n> +     *\n> +     * {\"return\": {}}\n> +     *\n> +     * But the order of arrival may vary.  Detect both.\n> +     */\n> +\n> +    cmd = g_strdup_printf(\"{'execute': 'device_del',\"\n> +                          \" 'arguments': {\"\n> +                          \"   'id': '%s'\"\n> +                          \"}}\", id);\n> +    response1 = qmp(cmd);\n> +    g_free(cmd);\n> +    g_assert(response1);\n> +    g_assert(!qdict_haskey(response1, \"error\"));\n> +\n> +    response2 = qmp(\"\");\n> +    g_assert(response2);\n> +    g_assert(!qdict_haskey(response2, \"error\"));\n\nqmp_receive() would be cleaner than qmp(\"\").\n\n> +\n> +    if (qdict_haskey(response1, \"event\")) {\n> +        event = response1;\n> +    } else if (qdict_haskey(response2, \"event\")) {\n> +        event = response2;\n> +    }\n> +    g_assert(event);\n> +    g_assert(!strcmp(qdict_get_str(event, \"event\"), \"DEVICE_DELETED\"));\n> +\n> +    QDECREF(response1);\n> +    QDECREF(response2);\n> +}\n> +\n\nUh, this looks similar to existing qtest_qmp_device_del().  Do we need both?\n\n>  void qmp_async(const char *fmt, ...)\n>  {\n>      va_list ap;\n> diff --git a/tests/libqtest.h b/tests/libqtest.h\n> index 3ae5709..0d48e4b 100644\n> --- a/tests/libqtest.h\n> +++ b/tests/libqtest.h\n> @@ -920,6 +920,14 @@ QDict *qmp_fdv(int fd, const char *fmt, va_list ap);\n>  QDict *qmp_fd(int fd, const char *fmt, ...);\n>  \n>  /**\n> + * qmp_device_del:\n> + * @id: The device ID to be deleted\n> + *\n> + * Delete the device with ID @id from QMP interface.\n> + */\n> +void qmp_device_del(const char *id);\n> +\n> +/**\n>   * qtest_cb_for_every_machine:\n>   * @cb: Pointer to the callback function\n>   *","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org;\n\treceiver=<UNKNOWN>)","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=armbru@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y5TcN1Kcpz9t4c\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue,  3 Oct 2017 04:26:59 +1100 (AEDT)","from localhost ([::1]:53515 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org>)\n\tid 1dz4Ua-0008Vd-Fx\n\tfor incoming@patchwork.ozlabs.org; Mon, 02 Oct 2017 13:26:56 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:33152)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dz4Ts-0008HG-O4\n\tfor qemu-devel@nongnu.org; Mon, 02 Oct 2017 13:26:13 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dz4Tp-0006TR-LW\n\tfor qemu-devel@nongnu.org; Mon, 02 Oct 2017 13:26:12 -0400","from mx1.redhat.com ([209.132.183.28]:59908)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <armbru@redhat.com>) id 1dz4Tp-0006Su-D2\n\tfor qemu-devel@nongnu.org; Mon, 02 Oct 2017 13:26:09 -0400","from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 35FD85275A\n\tfor <qemu-devel@nongnu.org>; Mon,  2 Oct 2017 17:26:08 +0000 (UTC)","from blackfin.pond.sub.org (ovpn-116-91.ams2.redhat.com\n\t[10.36.116.91])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 3EA2794C70;\n\tMon,  2 Oct 2017 17:26:00 +0000 (UTC)","by blackfin.pond.sub.org (Postfix, from userid 1000)\n\tid 91DDC1132D34; Mon,  2 Oct 2017 19:25:58 +0200 (CEST)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 35FD85275A","From":"Markus Armbruster <armbru@redhat.com>","To":"Peter Xu <peterx@redhat.com>","References":"<1505295366-25295-1-git-send-email-peterx@redhat.com>\n\t<1505295366-25295-2-git-send-email-peterx@redhat.com>","Date":"Mon, 02 Oct 2017 19:25:58 +0200","In-Reply-To":"<1505295366-25295-2-git-send-email-peterx@redhat.com> (Peter\n\tXu's message of \"Wed, 13 Sep 2017 17:36:03 +0800\")","Message-ID":"<87bmlp1mxl.fsf@dusky.pond.sub.org>","User-Agent":"Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)","MIME-Version":"1.0","Content-Type":"text/plain","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.12","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.29]);\n\tMon, 02 Oct 2017 17:26:08 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH 1/4] libqtest: add qmp_device_del()","X-BeenThere":"qemu-devel@gnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.gnu.org>","List-Unsubscribe":"<https://lists.gnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@gnu.org?subject=unsubscribe>","List-Archive":"<http://lists.gnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@gnu.org>","List-Help":"<mailto:qemu-devel-request@gnu.org?subject=help>","List-Subscribe":"<https://lists.gnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@gnu.org?subject=subscribe>","Cc":"Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <famz@redhat.com>,\n\tqemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org>"}},{"id":1778481,"web_url":"http://patchwork.ozlabs.org/comment/1778481/","msgid":"<0ba97cc0-4c1a-a99a-9e9d-ff24cc54db24@redhat.com>","list_archive_url":null,"date":"2017-10-02T17:33:25","subject":"Re: [Qemu-devel] [PATCH 1/4] libqtest: add qmp_device_del()","submitter":{"id":6591,"url":"http://patchwork.ozlabs.org/api/people/6591/","name":"Eric Blake","email":"eblake@redhat.com"},"content":"On 10/02/2017 12:25 PM, Markus Armbruster wrote:\n> Peter Xu <peterx@redhat.com> writes:\n> \n>> Device deletion is tricky since we'll get both a response and an event,\n>> while the order of arrival may vary.  Provide a helper to handle this\n>> complexity.\n>>\n>> Signed-off-by: Peter Xu <peterx@redhat.com>\n>> ---\n>>  tests/libqtest.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++\n>>  tests/libqtest.h |  8 ++++++++\n>>  2 files changed, 56 insertions(+)\n>>\n>> diff --git a/tests/libqtest.c b/tests/libqtest.c\n>> index b9a1f18..a34d8c4 100644\n>> --- a/tests/libqtest.c\n>> +++ b/tests/libqtest.c\n>> @@ -925,6 +925,54 @@ QDict *qmp(const char *fmt, ...)\n>>      return response;\n>>  }\n>>  \n>> +void qmp_device_del(const char *id)\n\n>> +\n>> +    response2 = qmp(\"\");\n>> +    g_assert(response2);\n>> +    g_assert(!qdict_haskey(response2, \"error\"));\n> \n> qmp_receive() would be cleaner than qmp(\"\").\n> \n>> +\n>> +    if (qdict_haskey(response1, \"event\")) {\n>> +        event = response1;\n>> +    } else if (qdict_haskey(response2, \"event\")) {\n>> +        event = response2;\n>> +    }\n>> +    g_assert(event);\n>> +    g_assert(!strcmp(qdict_get_str(event, \"event\"), \"DEVICE_DELETED\"));\n>> +\n>> +    QDECREF(response1);\n>> +    QDECREF(response2);\n>> +}\n>> +\n> \n> Uh, this looks similar to existing qtest_qmp_device_del().  Do we need both?\n\nIn fact, if I'm reading correctly, this is an early version, which was\nretitled into commit acd80015 adding qtest_qmp_device_del().\n\nAt any rate, when I post my respin of my libqtest cleanups, I have the\nqmp(\"\") slated to be fixed.","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org;\n\treceiver=<UNKNOWN>)","ext-mx03.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx03.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eblake@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y5Tmb5pfNz9t4c\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue,  3 Oct 2017 04:34:06 +1100 (AEDT)","from localhost ([::1]:53534 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org>)\n\tid 1dz4bS-0001hQ-Ni\n\tfor incoming@patchwork.ozlabs.org; Mon, 02 Oct 2017 13:34:02 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:36022)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dz4b4-0001h4-Be\n\tfor qemu-devel@nongnu.org; Mon, 02 Oct 2017 13:33:39 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dz4b1-000533-9B\n\tfor qemu-devel@nongnu.org; Mon, 02 Oct 2017 13:33:38 -0400","from mx1.redhat.com ([209.132.183.28]:50808)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <eblake@redhat.com>) id 1dz4b1-00052N-00\n\tfor qemu-devel@nongnu.org; Mon, 02 Oct 2017 13:33:35 -0400","from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id C7B6983F40\n\tfor <qemu-devel@nongnu.org>; Mon,  2 Oct 2017 17:33:33 +0000 (UTC)","from [10.10.123.255] (ovpn-123-255.rdu2.redhat.com [10.10.123.255])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 5DD105C544;\n\tMon,  2 Oct 2017 17:33:26 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com C7B6983F40","To":"Markus Armbruster <armbru@redhat.com>, Peter Xu <peterx@redhat.com>","References":"<1505295366-25295-1-git-send-email-peterx@redhat.com>\n\t<1505295366-25295-2-git-send-email-peterx@redhat.com>\n\t<87bmlp1mxl.fsf@dusky.pond.sub.org>","From":"Eric Blake <eblake@redhat.com>","Openpgp":"url=http://people.redhat.com/eblake/eblake.gpg","Organization":"Red Hat, Inc.","Message-ID":"<0ba97cc0-4c1a-a99a-9e9d-ff24cc54db24@redhat.com>","Date":"Mon, 2 Oct 2017 12:33:25 -0500","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<87bmlp1mxl.fsf@dusky.pond.sub.org>","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\";\n\tboundary=\"Hbx2A8JMb8r6s6dxUM2AKVFkMkjRVWtH9\"","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.16","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.27]);\n\tMon, 02 Oct 2017 17:33:34 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","X-Content-Filtered-By":"Mailman/MimeDel 2.1.21","Subject":"Re: [Qemu-devel] [PATCH 1/4] libqtest: add qmp_device_del()","X-BeenThere":"qemu-devel@gnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.gnu.org>","List-Unsubscribe":"<https://lists.gnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@gnu.org?subject=unsubscribe>","List-Archive":"<http://lists.gnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@gnu.org>","List-Help":"<mailto:qemu-devel-request@gnu.org?subject=help>","List-Subscribe":"<https://lists.gnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@gnu.org?subject=subscribe>","Cc":"Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <famz@redhat.com>,\n\tqemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@gnu.org>"}}]