From nobody Mon May 6 09:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508028158983122.89267570496088; Sat, 14 Oct 2017 17:42:38 -0700 (PDT) Received: from localhost ([::1]:55599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3X0c-0007Vq-74 for importer@patchew.org; Sat, 14 Oct 2017 20:42:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3Wyy-0006TF-ND for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3Wyx-0003jE-RY for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3Wyv-0003ed-D8; Sat, 14 Oct 2017 20:40:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 65C9E5F739; Sun, 15 Oct 2017 00:40:40 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8327860BEE; Sun, 15 Oct 2017 00:40:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 65C9E5F739 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 19:40:25 -0500 Message-Id: <20171015004033.3248-2-eblake@redhat.com> In-Reply-To: <20171015004033.3248-1-eblake@redhat.com> References: <20171015004033.3248-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 15 Oct 2017 00:40:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/9] NBD: use g_new() family of functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "open list:Network Block Dev..." , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20171006235023.11952-22-f4bug@amsat.org> Signed-off-by: Eric Blake --- nbd/server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 993ade30bb..b74cc6ab7e 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1047,7 +1047,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t= dev_offset, off_t size, { AioContext *ctx; BlockBackend *blk; - NBDExport *exp =3D g_malloc0(sizeof(NBDExport)); + NBDExport *exp =3D g_new0(NBDExport, 1); uint64_t perm; int ret; @@ -1539,7 +1539,7 @@ void nbd_client_new(NBDExport *exp, NBDClient *client; Coroutine *co; - client =3D g_malloc0(sizeof(NBDClient)); + client =3D g_new0(NBDClient, 1); client->refcount =3D 1; client->exp =3D exp; client->tlscreds =3D tlscreds; --=20 2.13.6 From nobody Mon May 6 09:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508028269156406.5863364395874; Sat, 14 Oct 2017 17:44:29 -0700 (PDT) Received: from localhost ([::1]:55608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3X2W-0000ap-GG for importer@patchew.org; Sat, 14 Oct 2017 20:44:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3Wz0-0006Ui-L4 for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3Wyz-0003lx-PX for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3Wyx-0003gm-5x; Sat, 14 Oct 2017 20:40:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D0A781E00; Sun, 15 Oct 2017 00:40:42 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAD7160BEE; Sun, 15 Oct 2017 00:40:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3D0A781E00 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 19:40:26 -0500 Message-Id: <20171015004033.3248-3-eblake@redhat.com> In-Reply-To: <20171015004033.3248-1-eblake@redhat.com> References: <20171015004033.3248-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 15 Oct 2017 00:40:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/9] block/nbd-client: assert qiov len once in nbd_co_request X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Also improve the assertion: check that qiov is NULL for other commands than CMD_READ and CMD_WRITE. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20171012095319.136610-2-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 72651dcdb1..ddf273a6a4 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -156,7 +156,6 @@ static int nbd_co_send_request(BlockDriverState *bs, qio_channel_set_cork(s->ioc, true); rc =3D nbd_send_request(s->ioc, request); if (rc >=3D 0 && !s->quit) { - assert(request->len =3D=3D iov_size(qiov->iov, qiov->niov)); if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov, NULL) < 0) { rc =3D -EIO; @@ -197,7 +196,6 @@ static int nbd_co_receive_reply(NBDClientSession *s, assert(s->reply.handle =3D=3D request->handle); ret =3D -s->reply.error; if (qiov && s->reply.error =3D=3D 0) { - assert(request->len =3D=3D iov_size(qiov->iov, qiov->niov)); if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov, NULL) < 0) { ret =3D -EIO; @@ -231,8 +229,12 @@ static int nbd_co_request(BlockDriverState *bs, NBDClientSession *client =3D nbd_get_client_session(bs); int ret; - assert(!qiov || request->type =3D=3D NBD_CMD_WRITE || - request->type =3D=3D NBD_CMD_READ); + if (qiov) { + assert(request->type =3D=3D NBD_CMD_WRITE || request->type =3D=3D = NBD_CMD_READ); + assert(request->len =3D=3D iov_size(qiov->iov, qiov->niov)); + } else { + assert(request->type !=3D NBD_CMD_WRITE && request->type !=3D NBD_= CMD_READ); + } ret =3D nbd_co_send_request(bs, request, request->type =3D=3D NBD_CMD_WRITE ? qiov : = NULL); if (ret < 0) { --=20 2.13.6 From nobody Mon May 6 09:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508028158972707.2832287242989; Sat, 14 Oct 2017 17:42:38 -0700 (PDT) Received: from localhost ([::1]:55600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3X0n-0007eI-P0 for importer@patchew.org; Sat, 14 Oct 2017 20:42:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3Wz2-0006WQ-HJ for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3Wz1-0003oA-Mi for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39940) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3Wyz-0003kD-8S; Sat, 14 Oct 2017 20:40:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BDB1C057FAD; Sun, 15 Oct 2017 00:40:44 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9829C60BEE; Sun, 15 Oct 2017 00:40:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4BDB1C057FAD Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 19:40:27 -0500 Message-Id: <20171015004033.3248-4-eblake@redhat.com> In-Reply-To: <20171015004033.3248-1-eblake@redhat.com> References: <20171015004033.3248-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 15 Oct 2017 00:40:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/9] block/nbd-client: refactor nbd_co_receive_reply X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Pass handle parameter directly, as the whole request isn't needed. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20171012095319.136610-3-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index ddf273a6a4..c0683c3c83 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -180,11 +180,11 @@ err: } static int nbd_co_receive_reply(NBDClientSession *s, - NBDRequest *request, + uint64_t handle, QEMUIOVector *qiov) { int ret; - int i =3D HANDLE_TO_INDEX(s, request->handle); + int i =3D HANDLE_TO_INDEX(s, handle); /* Wait until we're woken up by nbd_read_reply_entry. */ s->requests[i].receiving =3D true; @@ -193,7 +193,7 @@ static int nbd_co_receive_reply(NBDClientSession *s, if (!s->ioc || s->quit) { ret =3D -EIO; } else { - assert(s->reply.handle =3D=3D request->handle); + assert(s->reply.handle =3D=3D handle); ret =3D -s->reply.error; if (qiov && s->reply.error =3D=3D 0) { if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov, @@ -241,7 +241,7 @@ static int nbd_co_request(BlockDriverState *bs, return ret; } - return nbd_co_receive_reply(client, request, + return nbd_co_receive_reply(client, request->handle, request->type =3D=3D NBD_CMD_READ ? qiov := NULL); } --=20 2.13.6 From nobody Mon May 6 09:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508028374252665.5210829184318; Sat, 14 Oct 2017 17:46:14 -0700 (PDT) Received: from localhost ([::1]:55619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3X4E-0001m4-Hn for importer@patchew.org; Sat, 14 Oct 2017 20:46:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3Wz7-0006bg-3R for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3Wz5-0003pN-S1 for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45982) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3Wz1-0003mw-Ar; Sat, 14 Oct 2017 20:40:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54DD985547; Sun, 15 Oct 2017 00:40:46 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4B157841D; Sun, 15 Oct 2017 00:40:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 54DD985547 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 19:40:28 -0500 Message-Id: <20171015004033.3248-5-eblake@redhat.com> In-Reply-To: <20171015004033.3248-1-eblake@redhat.com> References: <20171015004033.3248-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sun, 15 Oct 2017 00:40:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/9] nbd: rename some simple-request related objects to be _simple_ X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy To be consistent when their _structured_ analogs will be introduced. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20171012095319.136610-4-vsementsov@virtuozzo.com> [eblake: also tweak trace message contents] Signed-off-by: Eric Blake --- nbd/nbd-internal.h | 2 +- nbd/client.c | 4 ++-- nbd/server.c | 12 ++++++------ nbd/trace-events | 2 +- tests/qemu-iotests/nbd-fault-injector.py | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 8a609a227f..2d6663de23 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -47,7 +47,7 @@ #define NBD_OLDSTYLE_NEGOTIATE_SIZE (8 + 8 + 8 + 4 + 124) #define NBD_REQUEST_MAGIC 0x25609513 -#define NBD_REPLY_MAGIC 0x67446698 +#define NBD_SIMPLE_REPLY_MAGIC 0x67446698 #define NBD_OPTS_MAGIC 0x49484156454F5054LL #define NBD_CLIENT_MAGIC 0x0000420281861253LL #define NBD_REP_MAGIC 0x0003e889045565a9LL diff --git a/nbd/client.c b/nbd/client.c index 68a0bc1ffc..cd5a2c80ac 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -931,7 +931,7 @@ int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply,= Error **errp) } /* Reply - [ 0 .. 3] magic (NBD_REPLY_MAGIC) + [ 0 .. 3] magic (NBD_SIMPLE_REPLY_MAGIC) [ 4 .. 7] error (0 =3D=3D no error) [ 7 .. 15] handle */ @@ -949,7 +949,7 @@ int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply,= Error **errp) } trace_nbd_receive_reply(magic, reply->error, reply->handle); - if (magic !=3D NBD_REPLY_MAGIC) { + if (magic !=3D NBD_SIMPLE_REPLY_MAGIC) { error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic); return -EINVAL; } diff --git a/nbd/server.c b/nbd/server.c index b74cc6ab7e..ea2f0fa476 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -911,11 +911,11 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *= reply, Error **errp) trace_nbd_send_reply(reply->error, reply->handle); /* Reply - [ 0 .. 3] magic (NBD_REPLY_MAGIC) + [ 0 .. 3] magic (NBD_SIMPLE_REPLY_MAGIC) [ 4 .. 7] error (0 =3D=3D no error) [ 7 .. 15] handle */ - stl_be_p(buf, NBD_REPLY_MAGIC); + stl_be_p(buf, NBD_SIMPLE_REPLY_MAGIC); stl_be_p(buf + 4, reply->error); stq_be_p(buf + 8, reply->handle); @@ -1208,15 +1208,15 @@ void nbd_export_close_all(void) } } -static int nbd_co_send_reply(NBDRequestData *req, NBDReply *reply, int len, - Error **errp) +static int nbd_co_send_simple_reply(NBDRequestData *req, NBDReply *reply, + int len, Error **errp) { NBDClient *client =3D req->client; int ret; g_assert(qemu_in_coroutine()); - trace_nbd_co_send_reply(reply->handle, reply->error, len); + trace_nbd_co_send_simple_reply(reply->handle, reply->error, len); qemu_co_mutex_lock(&client->send_lock); client->send_coroutine =3D qemu_coroutine_self(); @@ -1465,7 +1465,7 @@ reply: local_err =3D NULL; } - if (nbd_co_send_reply(req, &reply, reply_data_len, &local_err) < 0) { + if (nbd_co_send_simple_reply(req, &reply, reply_data_len, &local_err) = < 0) { error_prepend(&local_err, "Failed to send reply: "); goto disconnect; } diff --git a/nbd/trace-events b/nbd/trace-events index 48a4f27682..4d6f86c2d4 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -54,7 +54,7 @@ nbd_receive_request(uint32_t magic, uint16_t flags, uint1= 6_t type, uint64_t from nbd_send_reply(int32_t error, uint64_t handle) "Sending response to client= : { .error =3D %" PRId32 ", handle =3D %" PRIu64 " }" nbd_blk_aio_attached(const char *name, void *ctx) "Export %s: Attaching cl= ients to AIO context %p\n" nbd_blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clie= nts from AIO context %p\n" -nbd_co_send_reply(uint64_t handle, uint32_t error, int len) "Send reply: h= andle =3D %" PRIu64 ", error =3D %" PRIu32 ", len =3D %d" +nbd_co_send_simple_reply(uint64_t handle, uint32_t error, int len) "Send s= imple reply: handle =3D %" PRIu64 ", error =3D %" PRIu32 ", len =3D %d" nbd_co_receive_request_decode_type(uint64_t handle, uint16_t type, const c= har *name) "Decoding type: handle =3D %" PRIu64 ", type =3D %" PRIu16 " (%s= )" nbd_co_receive_request_payload_received(uint64_t handle, uint32_t len) "Pa= yload received: handle =3D %" PRIu64 ", len =3D %" PRIu32 nbd_co_receive_request_cmd_write(uint32_t len) "Reading %" PRIu32 " byte(s= )" diff --git a/tests/qemu-iotests/nbd-fault-injector.py b/tests/qemu-iotests/= nbd-fault-injector.py index 1c10dcb51c..8a04d979aa 100755 --- a/tests/qemu-iotests/nbd-fault-injector.py +++ b/tests/qemu-iotests/nbd-fault-injector.py @@ -56,7 +56,7 @@ NBD_CMD_READ =3D 0 NBD_CMD_WRITE =3D 1 NBD_CMD_DISC =3D 2 NBD_REQUEST_MAGIC =3D 0x25609513 -NBD_REPLY_MAGIC =3D 0x67446698 +NBD_SIMPLE_REPLY_MAGIC =3D 0x67446698 NBD_PASSWD =3D 0x4e42444d41474943 NBD_OPTS_MAGIC =3D 0x49484156454F5054 NBD_CLIENT_MAGIC =3D 0x0000420281861253 @@ -166,7 +166,7 @@ def read_request(conn): return req def write_reply(conn, error, handle): - buf =3D reply_struct.pack(NBD_REPLY_MAGIC, error, handle) + buf =3D reply_struct.pack(NBD_SIMPLE_REPLY_MAGIC, error, handle) conn.send(buf, event=3D'reply') def handle_connection(conn, use_export): --=20 2.13.6 From nobody Mon May 6 09:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508028279640410.45409050993976; Sat, 14 Oct 2017 17:44:39 -0700 (PDT) Received: from localhost ([::1]:55609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3X2k-0000ik-Vr for importer@patchew.org; Sat, 14 Oct 2017 20:44:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3Wz8-0006bt-BT for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3Wz7-0003pz-8e for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49884) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3Wz3-0003oR-9R; Sat, 14 Oct 2017 20:40:49 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A1EB5D68A; Sun, 15 Oct 2017 00:40:48 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id B044960BEE; Sun, 15 Oct 2017 00:40:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4A1EB5D68A Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 19:40:29 -0500 Message-Id: <20171015004033.3248-6-eblake@redhat.com> In-Reply-To: <20171015004033.3248-1-eblake@redhat.com> References: <20171015004033.3248-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 15 Oct 2017 00:40:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/9] nbd/server: structurize simple reply header sending X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Use packed structure instead of pointer arithmetics. Also, merge two redundant traces into one. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20171012095319.136610-5-vsementsov@virtuozzo.com> [eblake: tweak and mention impact on traces, fix errp usage] Signed-off-by: Eric Blake --- include/block/nbd.h | 6 ++++++ nbd/server.c | 37 ++++++++++++++----------------------- nbd/trace-events | 1 - 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 707fd37575..49008980f4 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -63,6 +63,12 @@ struct NBDReply { }; typedef struct NBDReply NBDReply; +typedef struct NBDSimpleReply { + uint32_t magic; /* NBD_SIMPLE_REPLY_MAGIC */ + uint32_t error; + uint64_t handle; +} QEMU_PACKED NBDSimpleReply; + /* Transmission (export) flags: sent from server to client during handshak= e, but describe what will happen during transmission */ #define NBD_FLAG_HAS_FLAGS (1 << 0) /* Flags are there */ diff --git a/nbd/server.c b/nbd/server.c index ea2f0fa476..4f765ba992 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -902,26 +902,6 @@ static int nbd_receive_request(QIOChannel *ioc, NBDReq= uest *request, return 0; } -static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) -{ - uint8_t buf[NBD_REPLY_SIZE]; - - reply->error =3D system_errno_to_nbd_errno(reply->error); - - trace_nbd_send_reply(reply->error, reply->handle); - - /* Reply - [ 0 .. 3] magic (NBD_SIMPLE_REPLY_MAGIC) - [ 4 .. 7] error (0 =3D=3D no error) - [ 7 .. 15] handle - */ - stl_be_p(buf, NBD_SIMPLE_REPLY_MAGIC); - stl_be_p(buf + 4, reply->error); - stq_be_p(buf + 8, reply->handle); - - return nbd_write(ioc, buf, sizeof(buf), errp); -} - #define MAX_NBD_REQUESTS 16 void nbd_client_get(NBDClient *client) @@ -1208,24 +1188,35 @@ void nbd_export_close_all(void) } } +static inline void set_be_simple_reply(NBDSimpleReply *reply, uint64_t err= or, + uint64_t handle) +{ + stl_be_p(&reply->magic, NBD_SIMPLE_REPLY_MAGIC); + stl_be_p(&reply->error, error); + stq_be_p(&reply->handle, handle); +} + static int nbd_co_send_simple_reply(NBDRequestData *req, NBDReply *reply, int len, Error **errp) { NBDClient *client =3D req->client; + NBDSimpleReply simple_reply; + int nbd_err =3D system_errno_to_nbd_errno(reply->error); int ret; g_assert(qemu_in_coroutine()); - trace_nbd_co_send_simple_reply(reply->handle, reply->error, len); + trace_nbd_co_send_simple_reply(reply->handle, nbd_err, len); + set_be_simple_reply(&simple_reply, nbd_err, reply->handle); qemu_co_mutex_lock(&client->send_lock); client->send_coroutine =3D qemu_coroutine_self(); if (!len) { - ret =3D nbd_send_reply(client->ioc, reply, errp); + ret =3D nbd_write(client->ioc, &simple_reply, sizeof(simple_reply)= , errp); } else { qio_channel_set_cork(client->ioc, true); - ret =3D nbd_send_reply(client->ioc, reply, errp); + ret =3D nbd_write(client->ioc, &simple_reply, sizeof(simple_reply)= , errp); if (ret =3D=3D 0) { ret =3D nbd_write(client->ioc, req->data, len, errp); if (ret < 0) { diff --git a/nbd/trace-events b/nbd/trace-events index 4d6f86c2d4..e27614f050 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -51,7 +51,6 @@ nbd_negotiate_old_style(uint64_t size, unsigned flags) "a= dvertising size %" PRIu nbd_negotiate_new_style_size_flags(uint64_t size, unsigned flags) "adverti= sing size %" PRIu64 " and flags 0x%x" nbd_negotiate_success(void) "Negotiation succeeded" nbd_receive_request(uint32_t magic, uint16_t flags, uint16_t type, uint64_= t from, uint32_t len) "Got request: { magic =3D 0x%" PRIx32 ", .flags =3D 0= x%" PRIx16 ", .type =3D 0x%" PRIx16 ", from =3D %" PRIu64 ", len =3D %" PRI= u32 " }" -nbd_send_reply(int32_t error, uint64_t handle) "Sending response to client= : { .error =3D %" PRId32 ", handle =3D %" PRIu64 " }" nbd_blk_aio_attached(const char *name, void *ctx) "Export %s: Attaching cl= ients to AIO context %p\n" nbd_blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clie= nts from AIO context %p\n" nbd_co_send_simple_reply(uint64_t handle, uint32_t error, int len) "Send s= imple reply: handle =3D %" PRIu64 ", error =3D %" PRIu32 ", len =3D %d" --=20 2.13.6 From nobody Mon May 6 09:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508028506465733.6040418855002; Sat, 14 Oct 2017 17:48:26 -0700 (PDT) Received: from localhost ([::1]:55624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3X6A-0002zi-RF for importer@patchew.org; Sat, 14 Oct 2017 20:48:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3WzA-0006di-Gx for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3Wz9-0003tr-HB for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40162) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3Wz4-0003oj-Te; Sat, 14 Oct 2017 20:40:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1E6013A4E; Sun, 15 Oct 2017 00:40:49 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2B2A60BEE; Sun, 15 Oct 2017 00:40:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E1E6013A4E Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 19:40:30 -0500 Message-Id: <20171015004033.3248-7-eblake@redhat.com> In-Reply-To: <20171015004033.3248-1-eblake@redhat.com> References: <20171015004033.3248-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sun, 15 Oct 2017 00:40:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/9] nbd/server: do not use NBDReply structure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy NBDReply structure will be upgraded in future patches to handle both simple and structured replies and will be used only in the client Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20171012095319.136610-6-vsementsov@virtuozzo.com> [eblake: rebase to tweaks earlier in series] Signed-off-by: Eric Blake --- nbd/server.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 4f765ba992..06aeadcfbb 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1196,18 +1196,20 @@ static inline void set_be_simple_reply(NBDSimpleRep= ly *reply, uint64_t error, stq_be_p(&reply->handle, handle); } -static int nbd_co_send_simple_reply(NBDRequestData *req, NBDReply *reply, +static int nbd_co_send_simple_reply(NBDRequestData *req, + uint64_t handle, + uint32_t error, int len, Error **errp) { NBDClient *client =3D req->client; NBDSimpleReply simple_reply; - int nbd_err =3D system_errno_to_nbd_errno(reply->error); + int nbd_err =3D system_errno_to_nbd_errno(error); int ret; g_assert(qemu_in_coroutine()); - trace_nbd_co_send_simple_reply(reply->handle, nbd_err, len); - set_be_simple_reply(&simple_reply, nbd_err, reply->handle); + trace_nbd_co_send_simple_reply(handle, nbd_err, len); + set_be_simple_reply(&simple_reply, nbd_err, handle); qemu_co_mutex_lock(&client->send_lock); client->send_coroutine =3D qemu_coroutine_self(); @@ -1322,7 +1324,6 @@ static coroutine_fn void nbd_trip(void *opaque) NBDExport *exp =3D client->exp; NBDRequestData *req; NBDRequest request =3D { 0 }; /* GCC thinks it can be used uninitia= lized */ - NBDReply reply; int ret; int flags; int reply_data_len =3D 0; @@ -1342,11 +1343,7 @@ static coroutine_fn void nbd_trip(void *opaque) goto disconnect; } - reply.handle =3D request.handle; - reply.error =3D 0; - if (ret < 0) { - reply.error =3D -ret; goto reply; } @@ -1365,7 +1362,6 @@ static coroutine_fn void nbd_trip(void *opaque) ret =3D blk_co_flush(exp->blk); if (ret < 0) { error_setg_errno(&local_err, -ret, "flush failed"); - reply.error =3D -ret; break; } } @@ -1374,7 +1370,6 @@ static coroutine_fn void nbd_trip(void *opaque) req->data, request.len); if (ret < 0) { error_setg_errno(&local_err, -ret, "reading from file failed"); - reply.error =3D -ret; break; } @@ -1383,7 +1378,7 @@ static coroutine_fn void nbd_trip(void *opaque) break; case NBD_CMD_WRITE: if (exp->nbdflags & NBD_FLAG_READ_ONLY) { - reply.error =3D EROFS; + ret =3D -EROFS; break; } @@ -1395,14 +1390,13 @@ static coroutine_fn void nbd_trip(void *opaque) req->data, request.len, flags); if (ret < 0) { error_setg_errno(&local_err, -ret, "writing to file failed"); - reply.error =3D -ret; } break; case NBD_CMD_WRITE_ZEROES: if (exp->nbdflags & NBD_FLAG_READ_ONLY) { error_setg(&local_err, "Server is read-only, return error"); - reply.error =3D EROFS; + ret =3D -EROFS; break; } @@ -1417,7 +1411,6 @@ static coroutine_fn void nbd_trip(void *opaque) request.len, flags); if (ret < 0) { error_setg_errno(&local_err, -ret, "writing to file failed"); - reply.error =3D -ret; } break; @@ -1429,7 +1422,6 @@ static coroutine_fn void nbd_trip(void *opaque) ret =3D blk_co_flush(exp->blk); if (ret < 0) { error_setg_errno(&local_err, -ret, "flush failed"); - reply.error =3D -ret; } break; @@ -1438,25 +1430,27 @@ static coroutine_fn void nbd_trip(void *opaque) request.len); if (ret < 0) { error_setg_errno(&local_err, -ret, "discard failed"); - reply.error =3D -ret; } break; default: error_setg(&local_err, "invalid request type (%" PRIu32 ") receive= d", request.type); - reply.error =3D EINVAL; + ret =3D -EINVAL; } reply: if (local_err) { - /* If we are here local_err is not fatal error, already stored in - * reply.error */ + /* If we get here, local_err was not a fatal error, and should be = sent + * to the client. */ error_report_err(local_err); local_err =3D NULL; } - if (nbd_co_send_simple_reply(req, &reply, reply_data_len, &local_err) = < 0) { + if (nbd_co_send_simple_reply(req, request.handle, + ret < 0 ? -ret : 0, + reply_data_len, &local_err) < 0) + { error_prepend(&local_err, "Failed to send reply: "); goto disconnect; } --=20 2.13.6 From nobody Mon May 6 09:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508028383623546.8407727755472; Sat, 14 Oct 2017 17:46:23 -0700 (PDT) Received: from localhost ([::1]:55620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3X4Q-0001wJ-VL for importer@patchew.org; Sat, 14 Oct 2017 20:46:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3WzA-0006dY-Bx for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3Wz9-0003u4-JH for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40210) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3Wz6-0003pR-Hx; Sat, 14 Oct 2017 20:40:52 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C85213AB1; Sun, 15 Oct 2017 00:40:51 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49D1260BEE; Sun, 15 Oct 2017 00:40:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8C85213AB1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 19:40:31 -0500 Message-Id: <20171015004033.3248-8-eblake@redhat.com> In-Reply-To: <20171015004033.3248-1-eblake@redhat.com> References: <20171015004033.3248-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sun, 15 Oct 2017 00:40:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/9] nbd/server: refactor nbd_co_send_simple_reply parameters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Pass client and buffer (*data) parameters directly, to make the function consistent with further structured reply sending functions. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20171012095319.136610-7-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- nbd/server.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 06aeadcfbb..3fcc3d3c7c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1196,12 +1196,13 @@ static inline void set_be_simple_reply(NBDSimpleRep= ly *reply, uint64_t error, stq_be_p(&reply->handle, handle); } -static int nbd_co_send_simple_reply(NBDRequestData *req, +static int nbd_co_send_simple_reply(NBDClient *client, uint64_t handle, uint32_t error, - int len, Error **errp) + void *data, + size_t len, + Error **errp) { - NBDClient *client =3D req->client; NBDSimpleReply simple_reply; int nbd_err =3D system_errno_to_nbd_errno(error); int ret; @@ -1220,7 +1221,7 @@ static int nbd_co_send_simple_reply(NBDRequestData *r= eq, qio_channel_set_cork(client->ioc, true); ret =3D nbd_write(client->ioc, &simple_reply, sizeof(simple_reply)= , errp); if (ret =3D=3D 0) { - ret =3D nbd_write(client->ioc, req->data, len, errp); + ret =3D nbd_write(client->ioc, data, len, errp); if (ret < 0) { ret =3D -EIO; } @@ -1447,9 +1448,9 @@ reply: local_err =3D NULL; } - if (nbd_co_send_simple_reply(req, request.handle, + if (nbd_co_send_simple_reply(req->client, request.handle, ret < 0 ? -ret : 0, - reply_data_len, &local_err) < 0) + req->data, reply_data_len, &local_err) < = 0) { error_prepend(&local_err, "Failed to send reply: "); goto disconnect; --=20 2.13.6 From nobody Mon May 6 09:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508028580373820.9829652710752; Sat, 14 Oct 2017 17:49:40 -0700 (PDT) Received: from localhost ([::1]:55628 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3X7Y-0003sU-Op for importer@patchew.org; Sat, 14 Oct 2017 20:49:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3WzB-0006ew-Br for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:41:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3WzA-0003vr-JJ for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:40:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40096) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3Wz8-0003qC-7q; Sat, 14 Oct 2017 20:40:54 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 396C7C0587CB; Sun, 15 Oct 2017 00:40:53 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5C0960BEE; Sun, 15 Oct 2017 00:40:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 396C7C0587CB Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 19:40:32 -0500 Message-Id: <20171015004033.3248-9-eblake@redhat.com> In-Reply-To: <20171015004033.3248-1-eblake@redhat.com> References: <20171015004033.3248-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 15 Oct 2017 00:40:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 8/9] nbd/server: simplify reply transmission X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Send qiov via qio_channel_writev_all instead of calling nbd_write twice with a cork. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20171012095319.136610-8-vsementsov@virtuozzo.com> [eblake: rebase to tweaks earlier in series] Signed-off-by: Eric Blake --- nbd/server.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 3fcc3d3c7c..3df3548d6d 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1188,6 +1188,23 @@ void nbd_export_close_all(void) } } +static int coroutine_fn nbd_co_send_iov(NBDClient *client, struct iovec *i= ov, + unsigned niov, Error **errp) +{ + int ret; + + g_assert(qemu_in_coroutine()); + qemu_co_mutex_lock(&client->send_lock); + client->send_coroutine =3D qemu_coroutine_self(); + + ret =3D qio_channel_writev_all(client->ioc, iov, niov, errp) < 0 ? -EI= O : 0; + + client->send_coroutine =3D NULL; + qemu_co_mutex_unlock(&client->send_lock); + + return ret; +} + static inline void set_be_simple_reply(NBDSimpleReply *reply, uint64_t err= or, uint64_t handle) { @@ -1203,35 +1220,17 @@ static int nbd_co_send_simple_reply(NBDClient *clie= nt, size_t len, Error **errp) { - NBDSimpleReply simple_reply; + NBDSimpleReply reply; int nbd_err =3D system_errno_to_nbd_errno(error); - int ret; - - g_assert(qemu_in_coroutine()); + struct iovec iov[] =3D { + {.iov_base =3D &reply, .iov_len =3D sizeof(reply)}, + {.iov_base =3D data, .iov_len =3D len} + }; trace_nbd_co_send_simple_reply(handle, nbd_err, len); - set_be_simple_reply(&simple_reply, nbd_err, handle); + set_be_simple_reply(&reply, nbd_err, handle); - qemu_co_mutex_lock(&client->send_lock); - client->send_coroutine =3D qemu_coroutine_self(); - - if (!len) { - ret =3D nbd_write(client->ioc, &simple_reply, sizeof(simple_reply)= , errp); - } else { - qio_channel_set_cork(client->ioc, true); - ret =3D nbd_write(client->ioc, &simple_reply, sizeof(simple_reply)= , errp); - if (ret =3D=3D 0) { - ret =3D nbd_write(client->ioc, data, len, errp); - if (ret < 0) { - ret =3D -EIO; - } - } - qio_channel_set_cork(client->ioc, false); - } - - client->send_coroutine =3D NULL; - qemu_co_mutex_unlock(&client->send_lock); - return ret; + return nbd_co_send_iov(client, iov, len ? 2 : 1, errp); } /* nbd_co_receive_request --=20 2.13.6 From nobody Mon May 6 09:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508028500159774.2599902638533; Sat, 14 Oct 2017 17:48:20 -0700 (PDT) Received: from localhost ([::1]:55625 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3X6G-00035K-G0 for importer@patchew.org; Sat, 14 Oct 2017 20:48:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3WzH-0006mD-TH for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:41:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3WzG-0003yV-Iz for qemu-devel@nongnu.org; Sat, 14 Oct 2017 20:41:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38382) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3WzA-0003uB-74; Sat, 14 Oct 2017 20:40:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3DA6F83F43; Sun, 15 Oct 2017 00:40:55 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E03A60BEE; Sun, 15 Oct 2017 00:40:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3DA6F83F43 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 19:40:33 -0500 Message-Id: <20171015004033.3248-10-eblake@redhat.com> In-Reply-To: <20171015004033.3248-1-eblake@redhat.com> References: <20171015004033.3248-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sun, 15 Oct 2017 00:40:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 9/9] nbd: header constants indenting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Prepare indenting for the following commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20171012095319.136610-9-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- include/block/nbd.h | 15 ++++++++------- nbd/nbd-internal.h | 32 ++++++++++++++++---------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 49008980f4..a6df5ce8b5 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -71,13 +71,14 @@ typedef struct NBDSimpleReply { /* Transmission (export) flags: sent from server to client during handshak= e, but describe what will happen during transmission */ -#define NBD_FLAG_HAS_FLAGS (1 << 0) /* Flags are there */ -#define NBD_FLAG_READ_ONLY (1 << 1) /* Device is read-only */ -#define NBD_FLAG_SEND_FLUSH (1 << 2) /* Send FLUSH */ -#define NBD_FLAG_SEND_FUA (1 << 3) /* Send FUA (Force Unit Ac= cess) */ -#define NBD_FLAG_ROTATIONAL (1 << 4) /* Use elevator algorithm = - rotational media */ -#define NBD_FLAG_SEND_TRIM (1 << 5) /* Send TRIM (discard) */ -#define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6) /* Send WRITE_ZEROES */ +#define NBD_FLAG_HAS_FLAGS (1 << 0) /* Flags are there */ +#define NBD_FLAG_READ_ONLY (1 << 1) /* Device is read-only */ +#define NBD_FLAG_SEND_FLUSH (1 << 2) /* Send FLUSH */ +#define NBD_FLAG_SEND_FUA (1 << 3) /* Send FUA (Force Unit Access= ) */ +#define NBD_FLAG_ROTATIONAL (1 << 4) /* Use elevator algorithm - + rotational media */ +#define NBD_FLAG_SEND_TRIM (1 << 5) /* Send TRIM (discard) */ +#define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6) /* Send WRITE_ZEROES */ /* New-style handshake (global) flags, sent from server to client, and control what will happen during handshake phase. */ diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 2d6663de23..11a130d050 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -46,23 +46,23 @@ /* Size of oldstyle negotiation */ #define NBD_OLDSTYLE_NEGOTIATE_SIZE (8 + 8 + 8 + 4 + 124) -#define NBD_REQUEST_MAGIC 0x25609513 -#define NBD_SIMPLE_REPLY_MAGIC 0x67446698 -#define NBD_OPTS_MAGIC 0x49484156454F5054LL -#define NBD_CLIENT_MAGIC 0x0000420281861253LL -#define NBD_REP_MAGIC 0x0003e889045565a9LL +#define NBD_REQUEST_MAGIC 0x25609513 +#define NBD_SIMPLE_REPLY_MAGIC 0x67446698 +#define NBD_OPTS_MAGIC 0x49484156454F5054LL +#define NBD_CLIENT_MAGIC 0x0000420281861253LL +#define NBD_REP_MAGIC 0x0003e889045565a9LL -#define NBD_SET_SOCK _IO(0xab, 0) -#define NBD_SET_BLKSIZE _IO(0xab, 1) -#define NBD_SET_SIZE _IO(0xab, 2) -#define NBD_DO_IT _IO(0xab, 3) -#define NBD_CLEAR_SOCK _IO(0xab, 4) -#define NBD_CLEAR_QUE _IO(0xab, 5) -#define NBD_PRINT_DEBUG _IO(0xab, 6) -#define NBD_SET_SIZE_BLOCKS _IO(0xab, 7) -#define NBD_DISCONNECT _IO(0xab, 8) -#define NBD_SET_TIMEOUT _IO(0xab, 9) -#define NBD_SET_FLAGS _IO(0xab, 10) +#define NBD_SET_SOCK _IO(0xab, 0) +#define NBD_SET_BLKSIZE _IO(0xab, 1) +#define NBD_SET_SIZE _IO(0xab, 2) +#define NBD_DO_IT _IO(0xab, 3) +#define NBD_CLEAR_SOCK _IO(0xab, 4) +#define NBD_CLEAR_QUE _IO(0xab, 5) +#define NBD_PRINT_DEBUG _IO(0xab, 6) +#define NBD_SET_SIZE_BLOCKS _IO(0xab, 7) +#define NBD_DISCONNECT _IO(0xab, 8) +#define NBD_SET_TIMEOUT _IO(0xab, 9) +#define NBD_SET_FLAGS _IO(0xab, 10) /* NBD errors are based on errno numbers, so there is a 1:1 mapping, * but only a limited set of errno values is specified in the protocol. --=20 2.13.6