{"id":814947,"url":"http://patchwork.ozlabs.org/api/patches/814947/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170918135935.255591-3-vsementsov@virtuozzo.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170918135935.255591-3-vsementsov@virtuozzo.com>","list_archive_url":null,"date":"2017-09-18T13:59:30","name":"[v2,2/7] block/nbd-client: exit reply-reading coroutine on incorrect handle","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e50f4c28c4f27e9e11d30d357ef5c1fa167397e2","submitter":{"id":66592,"url":"http://patchwork.ozlabs.org/api/people/66592/?format=json","name":"Vladimir Sementsov-Ogievskiy","email":"vsementsov@virtuozzo.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170918135935.255591-3-vsementsov@virtuozzo.com/mbox/","series":[{"id":3654,"url":"http://patchwork.ozlabs.org/api/series/3654/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=3654","date":"2017-09-18T13:59:31","name":"nbd client refactoring and fixing","version":2,"mbox":"http://patchwork.ozlabs.org/series/3654/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/814947/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/814947/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","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 3xwnjj0dRVz9s7G\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 19 Sep 2017 00:01:29 +1000 (AEST)","from localhost ([::1]:36790 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@nongnu.org>)\n\tid 1dtwc3-0002gS-3e\n\tfor incoming@patchwork.ozlabs.org; Mon, 18 Sep 2017 10:01:27 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:38441)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <vsementsov@virtuozzo.com>) id 1dtwaR-0001iN-AF\n\tfor qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:48 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <vsementsov@virtuozzo.com>) id 1dtwaN-0001QY-Ns\n\tfor qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:47 -0400","from mailhub.sw.ru ([195.214.232.25]:2112 helo=relay.sw.ru)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <vsementsov@virtuozzo.com>)\n\tid 1dtwaN-0001Pe-BK\n\tfor qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:43 -0400","from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6])\n\tby relay.sw.ru (8.13.4/8.13.4) with ESMTP id v8IDxZdW022049;\n\tMon, 18 Sep 2017 16:59:37 +0300 (MSK)"],"From":"Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>","To":"qemu-block@nongnu.org, qemu-devel@nongnu.org","Date":"Mon, 18 Sep 2017 16:59:30 +0300","Message-Id":"<20170918135935.255591-3-vsementsov@virtuozzo.com>","X-Mailer":"git-send-email 2.11.1","In-Reply-To":"<20170918135935.255591-1-vsementsov@virtuozzo.com>","References":"<20170918135935.255591-1-vsementsov@virtuozzo.com>","X-detected-operating-system":"by eggs.gnu.org: OpenBSD 3.x [fuzzy]","X-Received-From":"195.214.232.25","Subject":"[Qemu-devel] [PATCH v2 2/7] block/nbd-client: exit reply-reading\n\tcoroutine on incorrect handle","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"kwolf@redhat.com, vsementsov@virtuozzo.com, mreitz@redhat.com,\n\tden@openvz.org, pbonzini@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"Check reply-handle == request-handle in the same place, where\nrecv coroutine number is calculated from reply->handle and it's\ncorrectness checked - in nbd_read_reply_entry.\n\nAlso finish nbd_read_reply_entry in case of reply-handle !=\nrequest-handle in the same way as in case of incorrect reply-handle.\n\nSigned-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>\n---\n block/nbd-client.h | 1 +\n block/nbd-client.c | 8 ++++++--\n 2 files changed, 7 insertions(+), 2 deletions(-)","diff":"diff --git a/block/nbd-client.h b/block/nbd-client.h\nindex b435754b82..b1900e6a6d 100644\n--- a/block/nbd-client.h\n+++ b/block/nbd-client.h\n@@ -20,6 +20,7 @@\n typedef struct {\n     Coroutine *coroutine;\n     bool receiving;         /* waiting for read_reply_co? */\n+    NBDRequest *request;\n } NBDClientRequest;\n \n typedef struct NBDClientSession {\ndiff --git a/block/nbd-client.c b/block/nbd-client.c\nindex acd8e5d007..5f241ecc22 100644\n--- a/block/nbd-client.c\n+++ b/block/nbd-client.c\n@@ -92,7 +92,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)\n         i = HANDLE_TO_INDEX(s, s->reply.handle);\n         if (i >= MAX_NBD_REQUESTS ||\n             !s->requests[i].coroutine ||\n-            !s->requests[i].receiving) {\n+            !s->requests[i].receiving ||\n+            s->reply.handle != s->requests[i].request->handle)\n+        {\n             break;\n         }\n \n@@ -142,6 +144,7 @@ static int nbd_co_send_request(BlockDriverState *bs,\n     s->requests[i].receiving = false;\n \n     request->handle = INDEX_TO_HANDLE(s, i);\n+    s->requests[i].request = request;\n \n     if (s->quit) {\n         rc = -EIO;\n@@ -189,9 +192,10 @@ static int nbd_co_receive_reply(NBDClientSession *s,\n     s->requests[i].receiving = true;\n     qemu_coroutine_yield();\n     s->requests[i].receiving = false;\n-    if (s->reply.handle != request->handle || !s->ioc || s->quit) {\n+    if (!s->ioc || s->quit) {\n         ret = -EIO;\n     } else {\n+        assert(s->reply.handle == request->handle);\n         ret = -s->reply.error;\n         if (qiov && s->reply.error == 0) {\n             assert(request->len == iov_size(qiov->iov, qiov->niov));\n","prefixes":["v2","2/7"]}