From nobody Sun May 5 15:31:29 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.zoho.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 1496155684164728.4957127542631; Tue, 30 May 2017 07:48:04 -0700 (PDT) Received: from localhost ([::1]:54252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiRG-0003sI-Ow for importer@patchew.org; Tue, 30 May 2017 10:48:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005Qc-F2 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAn-0000QP-0B for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:03 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:3338 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000N8-TB for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:00 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEH027829; Tue, 30 May 2017 17:30:54 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:34 +0300 Message-Id: <20170530143052.165002-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 01/19] nbd/server: get rid of nbd_negotiate_read and friends 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Functions nbd_negotiate_{read,write,drop_sync} were introduced in 1a6245a5b, when nbd_wr_syncv was working through qemu_co_sendv_recvv, which just yields, without setting any handlers. But now, nbd_wr_syncv works through qio_channel_yield() which sets handlers, so watchers are redundant in nbd_negotiate_{read,write,drop_sync}, then, let's just use {read,write,drop}_sync functions. Signed-off-by: Vladimir Sementsov-Ogievskiy --- nbd/client.c | 26 ------------- nbd/common.c | 26 +++++++++++++ nbd/nbd-internal.h | 2 + nbd/server.c | 107 +++++++++++--------------------------------------= ---- 4 files changed, 50 insertions(+), 111 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index f9e1d75be4..3d15596120 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -86,32 +86,6 @@ static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD_= INITIALIZER(exports); =20 */ =20 -/* Discard length bytes from channel. Return -errno on failure and 0 on - * success*/ -static int drop_sync(QIOChannel *ioc, size_t size, Error **errp) -{ - ssize_t ret =3D 0; - char small[1024]; - char *buffer; - - buffer =3D sizeof(small) >=3D size ? small : g_malloc(MIN(65536, size)= ); - while (size > 0) { - ssize_t count =3D MIN(65536, size); - ret =3D read_sync(ioc, buffer, MIN(65536, size), errp); - - if (ret < 0) { - goto cleanup; - } - size -=3D count; - } - - cleanup: - if (buffer !=3D small) { - g_free(buffer); - } - return ret; -} - /* Send an option request. * * The request is for option @opt, with @data containing @len bytes of diff --git a/nbd/common.c b/nbd/common.c index bd81637ab9..e520aae741 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -69,6 +69,32 @@ ssize_t nbd_wr_syncv(QIOChannel *ioc, return done; } =20 +/* Discard length bytes from channel. Return -errno on failure and 0 on + * success*/ +int drop_sync(QIOChannel *ioc, size_t size, Error **errp) +{ + ssize_t ret =3D 0; + char small[1024]; + char *buffer; + + buffer =3D sizeof(small) >=3D size ? small : g_malloc(MIN(65536, size)= ); + while (size > 0) { + ssize_t count =3D MIN(65536, size); + ret =3D read_sync(ioc, buffer, MIN(65536, size), errp); + + if (ret < 0) { + goto cleanup; + } + size -=3D count; + } + + cleanup: + if (buffer !=3D small) { + g_free(buffer); + } + return ret; +} + =20 void nbd_tls_handshake(QIOTask *task, void *opaque) diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index d6071640a0..01d5778679 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -153,4 +153,6 @@ struct NBDTLSHandshakeData { void nbd_tls_handshake(QIOTask *task, void *opaque); =20 +int drop_sync(QIOChannel *ioc, size_t size, Error **errp); + #endif diff --git a/nbd/server.c b/nbd/server.c index ee59e5d234..26096f14e1 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -104,69 +104,6 @@ struct NBDClient { =20 static void nbd_client_receive_next_request(NBDClient *client); =20 -static gboolean nbd_negotiate_continue(QIOChannel *ioc, - GIOCondition condition, - void *opaque) -{ - qemu_coroutine_enter(opaque); - return TRUE; -} - -static int nbd_negotiate_read(QIOChannel *ioc, void *buffer, size_t size) -{ - ssize_t ret; - guint watch; - - assert(qemu_in_coroutine()); - /* Negotiation are always in main loop. */ - watch =3D qio_channel_add_watch(ioc, - G_IO_IN, - nbd_negotiate_continue, - qemu_coroutine_self(), - NULL); - ret =3D read_sync(ioc, buffer, size, NULL); - g_source_remove(watch); - return ret; - -} - -static int nbd_negotiate_write(QIOChannel *ioc, const void *buffer, size_t= size) -{ - ssize_t ret; - guint watch; - - assert(qemu_in_coroutine()); - /* Negotiation are always in main loop. */ - watch =3D qio_channel_add_watch(ioc, - G_IO_OUT, - nbd_negotiate_continue, - qemu_coroutine_self(), - NULL); - ret =3D write_sync(ioc, buffer, size, NULL); - g_source_remove(watch); - return ret; -} - -static int nbd_negotiate_drop_sync(QIOChannel *ioc, size_t size) -{ - ssize_t ret; - uint8_t *buffer =3D g_malloc(MIN(65536, size)); - - while (size > 0) { - size_t count =3D MIN(65536, size); - ret =3D nbd_negotiate_read(ioc, buffer, count); - if (ret < 0) { - g_free(buffer); - return ret; - } - - size -=3D count; - } - - g_free(buffer); - return 0; -} - /* Basic flow for negotiation =20 Server Client @@ -205,22 +142,22 @@ static int nbd_negotiate_send_rep_len(QIOChannel *ioc= , uint32_t type, type, opt, len); =20 magic =3D cpu_to_be64(NBD_REP_MAGIC); - if (nbd_negotiate_write(ioc, &magic, sizeof(magic)) < 0) { + if (write_sync(ioc, &magic, sizeof(magic), NULL) < 0) { LOG("write failed (rep magic)"); return -EINVAL; } opt =3D cpu_to_be32(opt); - if (nbd_negotiate_write(ioc, &opt, sizeof(opt)) < 0) { + if (write_sync(ioc, &opt, sizeof(opt), NULL) < 0) { LOG("write failed (rep opt)"); return -EINVAL; } type =3D cpu_to_be32(type); - if (nbd_negotiate_write(ioc, &type, sizeof(type)) < 0) { + if (write_sync(ioc, &type, sizeof(type), NULL) < 0) { LOG("write failed (rep type)"); return -EINVAL; } len =3D cpu_to_be32(len); - if (nbd_negotiate_write(ioc, &len, sizeof(len)) < 0) { + if (write_sync(ioc, &len, sizeof(len), NULL) < 0) { LOG("write failed (rep data length)"); return -EINVAL; } @@ -255,7 +192,7 @@ nbd_negotiate_send_rep_err(QIOChannel *ioc, uint32_t ty= pe, if (ret < 0) { goto out; } - if (nbd_negotiate_write(ioc, msg, len) < 0) { + if (write_sync(ioc, msg, len, NULL) < 0) { LOG("write failed (error message)"); ret =3D -EIO; } else { @@ -286,15 +223,15 @@ static int nbd_negotiate_send_rep_list(QIOChannel *io= c, NBDExport *exp) } =20 len =3D cpu_to_be32(name_len); - if (nbd_negotiate_write(ioc, &len, sizeof(len)) < 0) { + if (write_sync(ioc, &len, sizeof(len), NULL) < 0) { LOG("write failed (name length)"); return -EINVAL; } - if (nbd_negotiate_write(ioc, name, name_len) < 0) { + if (write_sync(ioc, name, name_len, NULL) < 0) { LOG("write failed (name buffer)"); return -EINVAL; } - if (nbd_negotiate_write(ioc, desc, desc_len) < 0) { + if (write_sync(ioc, desc, desc_len, NULL) < 0) { LOG("write failed (description buffer)"); return -EINVAL; } @@ -308,7 +245,7 @@ static int nbd_negotiate_handle_list(NBDClient *client,= uint32_t length) NBDExport *exp; =20 if (length) { - if (nbd_negotiate_drop_sync(client->ioc, length) < 0) { + if (drop_sync(client->ioc, length, NULL) < 0) { return -EIO; } return nbd_negotiate_send_rep_err(client->ioc, @@ -339,7 +276,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, uint32_t length) LOG("Bad length received"); goto fail; } - if (nbd_negotiate_read(client->ioc, name, length) < 0) { + if (read_sync(client->ioc, name, length, NULL) < 0) { LOG("read failed"); goto fail; } @@ -372,7 +309,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, TRACE("Setting up TLS"); ioc =3D client->ioc; if (length) { - if (nbd_negotiate_drop_sync(ioc, length) < 0) { + if (drop_sync(ioc, length, NULL) < 0) { return NULL; } nbd_negotiate_send_rep_err(ioc, NBD_REP_ERR_INVALID, NBD_OPT_START= TLS, @@ -436,7 +373,7 @@ static int nbd_negotiate_options(NBDClient *client) ... Rest of request */ =20 - if (nbd_negotiate_read(client->ioc, &flags, sizeof(flags)) < 0) { + if (read_sync(client->ioc, &flags, sizeof(flags), NULL) < 0) { LOG("read failed"); return -EIO; } @@ -462,7 +399,7 @@ static int nbd_negotiate_options(NBDClient *client) uint32_t clientflags, length; uint64_t magic; =20 - if (nbd_negotiate_read(client->ioc, &magic, sizeof(magic)) < 0) { + if (read_sync(client->ioc, &magic, sizeof(magic), NULL) < 0) { LOG("read failed"); return -EINVAL; } @@ -472,15 +409,15 @@ static int nbd_negotiate_options(NBDClient *client) return -EINVAL; } =20 - if (nbd_negotiate_read(client->ioc, &clientflags, - sizeof(clientflags)) < 0) + if (read_sync(client->ioc, &clientflags, + sizeof(clientflags), NULL) < 0) { LOG("read failed"); return -EINVAL; } clientflags =3D be32_to_cpu(clientflags); =20 - if (nbd_negotiate_read(client->ioc, &length, sizeof(length)) < 0) { + if (read_sync(client->ioc, &length, sizeof(length), NULL) < 0) { LOG("read failed"); return -EINVAL; } @@ -510,7 +447,7 @@ static int nbd_negotiate_options(NBDClient *client) return -EINVAL; =20 default: - if (nbd_negotiate_drop_sync(client->ioc, length) < 0) { + if (drop_sync(client->ioc, length, NULL) < 0) { return -EIO; } ret =3D nbd_negotiate_send_rep_err(client->ioc, @@ -548,7 +485,7 @@ static int nbd_negotiate_options(NBDClient *client) return nbd_negotiate_handle_export_name(client, length); =20 case NBD_OPT_STARTTLS: - if (nbd_negotiate_drop_sync(client->ioc, length) < 0) { + if (drop_sync(client->ioc, length, NULL) < 0) { return -EIO; } if (client->tlscreds) { @@ -567,7 +504,7 @@ static int nbd_negotiate_options(NBDClient *client) } break; default: - if (nbd_negotiate_drop_sync(client->ioc, length) < 0) { + if (drop_sync(client->ioc, length, NULL) < 0) { return -EIO; } ret =3D nbd_negotiate_send_rep_err(client->ioc, @@ -656,12 +593,12 @@ static coroutine_fn int nbd_negotiate(NBDClientNewDat= a *data) TRACE("TLS cannot be enabled with oldstyle protocol"); goto fail; } - if (nbd_negotiate_write(client->ioc, buf, sizeof(buf)) < 0) { + if (write_sync(client->ioc, buf, sizeof(buf), NULL) < 0) { LOG("write failed"); goto fail; } } else { - if (nbd_negotiate_write(client->ioc, buf, 18) < 0) { + if (write_sync(client->ioc, buf, 18, NULL) < 0) { LOG("write failed"); goto fail; } @@ -676,7 +613,7 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData = *data) stq_be_p(buf + 18, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); len =3D client->no_zeroes ? 10 : sizeof(buf) - 18; - if (nbd_negotiate_write(client->ioc, buf + 18, len) < 0) { + if (write_sync(client->ioc, buf + 18, len, NULL) < 0) { LOG("write failed"); goto fail; } --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155440132524.6720634015799; Tue, 30 May 2017 07:44:00 -0700 (PDT) Received: from localhost ([::1]:54224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiNI-00007x-Go for importer@patchew.org; Tue, 30 May 2017 10:43:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005QL-3u for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000Os-0c for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:26866 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NJ-AX for qemu-devel@nongnu.org; Tue, 30 May 2017 10:30:59 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEI027829; Tue, 30 May 2017 17:30:54 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:35 +0300 Message-Id: <20170530143052.165002-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 02/19] nbd/server: get rid of ssize_t 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Now read_sync and friends return int, so get rid of ssize_t. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 26096f14e1..03880fd501 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -625,11 +625,11 @@ fail: return rc; } =20 -static ssize_t nbd_receive_request(QIOChannel *ioc, NBDRequest *request) +static int nbd_receive_request(QIOChannel *ioc, NBDRequest *request) { uint8_t buf[NBD_REQUEST_SIZE]; uint32_t magic; - ssize_t ret; + int ret; =20 ret =3D read_sync(ioc, buf, sizeof(buf), NULL); if (ret < 0) { @@ -663,7 +663,7 @@ static ssize_t nbd_receive_request(QIOChannel *ioc, NBD= Request *request) return 0; } =20 -static ssize_t nbd_send_reply(QIOChannel *ioc, NBDReply *reply) +static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply) { uint8_t buf[NBD_REPLY_SIZE]; =20 @@ -969,11 +969,10 @@ void nbd_export_close_all(void) } } =20 -static ssize_t nbd_co_send_reply(NBDRequestData *req, NBDReply *reply, - int len) +static int nbd_co_send_reply(NBDRequestData *req, NBDReply *reply, int len) { NBDClient *client =3D req->client; - ssize_t rc, ret; + int rc, ret; =20 g_assert(qemu_in_coroutine()); qemu_co_mutex_lock(&client->send_lock); @@ -1003,11 +1002,10 @@ static ssize_t nbd_co_send_reply(NBDRequestData *re= q, NBDReply *reply, * and any other negative value to report an error to the client * (although the caller may still need to disconnect after reporting * the error). */ -static ssize_t nbd_co_receive_request(NBDRequestData *req, - NBDRequest *request) +static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request) { NBDClient *client =3D req->client; - ssize_t rc; + int rc; =20 g_assert(qemu_in_coroutine()); assert(client->recv_coroutine =3D=3D qemu_coroutine_self()); @@ -1105,7 +1103,7 @@ static coroutine_fn void nbd_trip(void *opaque) NBDRequestData *req; NBDRequest request =3D { 0 }; /* GCC thinks it can be used uninitia= lized */ NBDReply reply; - ssize_t ret; + int ret; int flags; =20 TRACE("Reading request."); --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155056247947.0710927217697; Tue, 30 May 2017 07:37:36 -0700 (PDT) Received: from localhost ([::1]:54188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiH7-0002hX-LP for importer@patchew.org; Tue, 30 May 2017 10:37:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005Q0-02 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAl-0000OW-It for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:3571 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NA-6U for qemu-devel@nongnu.org; Tue, 30 May 2017 10:30:59 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEJ027829; Tue, 30 May 2017 17:30:54 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:36 +0300 Message-Id: <20170530143052.165002-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 03/19] nbd/server: refactor nbd_co_send_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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" As write_sync never returns value > 0, we can get rid of extra ret. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 03880fd501..e18eb020a7 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -972,7 +972,7 @@ void nbd_export_close_all(void) static int nbd_co_send_reply(NBDRequestData *req, NBDReply *reply, int len) { NBDClient *client =3D req->client; - int rc, ret; + int rc; =20 g_assert(qemu_in_coroutine()); qemu_co_mutex_lock(&client->send_lock); @@ -983,9 +983,9 @@ static int nbd_co_send_reply(NBDRequestData *req, NBDRe= ply *reply, int len) } else { qio_channel_set_cork(client->ioc, true); rc =3D nbd_send_reply(client->ioc, reply); - if (rc >=3D 0) { - ret =3D write_sync(client->ioc, req->data, len, NULL); - if (ret < 0) { + if (rc =3D=3D 0) { + rc =3D write_sync(client->ioc, req->data, len, NULL); + if (rc < 0) { rc =3D -EIO; } } --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155225555469.6176715087794; Tue, 30 May 2017 07:40:25 -0700 (PDT) Received: from localhost ([::1]:54201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiJr-0005bu-RB for importer@patchew.org; Tue, 30 May 2017 10:40:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005Q2-0R for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000P4-3f for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:4692 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NK-Ez for qemu-devel@nongnu.org; Tue, 30 May 2017 10:30:59 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEK027829; Tue, 30 May 2017 17:30:54 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:37 +0300 Message-Id: <20170530143052.165002-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 04/19] nbd/server: get rid of EAGAIN dead code 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" For now read_sync never returns EAGAIN. So, don't handle it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index e18eb020a7..fcf35f0270 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -997,11 +997,12 @@ static int nbd_co_send_reply(NBDRequestData *req, NBD= Reply *reply, int len) return rc; } =20 -/* Collect a client request. Return 0 if request looks valid, -EAGAIN - * to keep trying the collection, -EIO to drop connection right away, - * and any other negative value to report an error to the client - * (although the caller may still need to disconnect after reporting - * the error). */ +/* nbd_co_receive_request + * Collect a client request. Return 0 if request looks valid, -EIO to drop + * connection right away, and any other negative value to report an error = to + * the client (although the caller may still need to disconnect after repo= rting + * the error). + */ static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request) { NBDClient *client =3D req->client; @@ -1011,9 +1012,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request) assert(client->recv_coroutine =3D=3D qemu_coroutine_self()); rc =3D nbd_receive_request(client->ioc, request); if (rc < 0) { - if (rc !=3D -EAGAIN) { - rc =3D -EIO; - } + rc =3D -EIO; goto out; } =20 @@ -1114,9 +1113,6 @@ static coroutine_fn void nbd_trip(void *opaque) =20 req =3D nbd_request_get(client); ret =3D nbd_co_receive_request(req, &request); - if (ret =3D=3D -EAGAIN) { - goto done; - } if (ret =3D=3D -EIO) { goto out; } --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496154983487271.56715724994035; Tue, 30 May 2017 07:36:23 -0700 (PDT) Received: from localhost ([::1]:54184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiFw-0001bu-DG for importer@patchew.org; Tue, 30 May 2017 10:36:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005QA-1u for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAl-0000Od-QM for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:31234 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NF-73 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:30:59 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEL027829; Tue, 30 May 2017 17:30:54 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:38 +0300 Message-Id: <20170530143052.165002-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 05/19] nbd/server: refactor nbd_co_receive_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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Move function tail, about receiving next request out of the function. Error path is simplified and nbd_co_receive_request becomes more corresponding to its name. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index fcf35f0270..546bf3ae61 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1006,14 +1006,11 @@ static int nbd_co_send_reply(NBDRequestData *req, N= BDReply *reply, int len) static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request) { NBDClient *client =3D req->client; - int rc; =20 g_assert(qemu_in_coroutine()); assert(client->recv_coroutine =3D=3D qemu_coroutine_self()); - rc =3D nbd_receive_request(client->ioc, request); - if (rc < 0) { - rc =3D -EIO; - goto out; + if (nbd_receive_request(client->ioc, request) < 0) { + return -EIO; } =20 TRACE("Decoding type"); @@ -1027,8 +1024,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request) /* Special case: we're going to disconnect without a reply, * whether or not flags, from, or len are bogus */ TRACE("Request type is DISCONNECT"); - rc =3D -EIO; - goto out; + return -EIO; } =20 /* Check for sanity in the parameters, part 1. Defer as many @@ -1036,22 +1032,19 @@ static int nbd_co_receive_request(NBDRequestData *r= eq, NBDRequest *request) * payload, so we can try and keep the connection alive. */ if ((request->from + request->len) < request->from) { LOG("integer overflow detected, you're probably being attacked"); - rc =3D -EINVAL; - goto out; + return -EINVAL; } =20 if (request->type =3D=3D NBD_CMD_READ || request->type =3D=3D NBD_CMD_= WRITE) { if (request->len > NBD_MAX_BUFFER_SIZE) { LOG("len (%" PRIu32" ) is larger than max len (%u)", request->len, NBD_MAX_BUFFER_SIZE); - rc =3D -EINVAL; - goto out; + return -EINVAL; } =20 req->data =3D blk_try_blockalign(client->exp->blk, request->len); if (req->data =3D=3D NULL) { - rc =3D -ENOMEM; - goto out; + return -ENOMEM; } } if (request->type =3D=3D NBD_CMD_WRITE) { @@ -1059,8 +1052,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request) =20 if (read_sync(client->ioc, req->data, request->len, NULL) < 0) { LOG("reading from socket failed"); - rc =3D -EIO; - goto out; + return -EIO; } req->complete =3D true; } @@ -1070,28 +1062,19 @@ static int nbd_co_receive_request(NBDRequestData *r= eq, NBDRequest *request) LOG("operation past EOF; From: %" PRIu64 ", Len: %" PRIu32 ", Size: %" PRIu64, request->from, request->len, (uint64_t)client->exp->size); - rc =3D request->type =3D=3D NBD_CMD_WRITE ? -ENOSPC : -EINVAL; - goto out; + return request->type =3D=3D NBD_CMD_WRITE ? -ENOSPC : -EINVAL; } if (request->flags & ~(NBD_CMD_FLAG_FUA | NBD_CMD_FLAG_NO_HOLE)) { LOG("unsupported flags (got 0x%x)", request->flags); - rc =3D -EINVAL; - goto out; + return -EINVAL; } if (request->type !=3D NBD_CMD_WRITE_ZEROES && (request->flags & NBD_CMD_FLAG_NO_HOLE)) { LOG("unexpected flags (got 0x%x)", request->flags); - rc =3D -EINVAL; - goto out; + return -EINVAL; } =20 - rc =3D 0; - -out: - client->recv_coroutine =3D NULL; - nbd_client_receive_next_request(client); - - return rc; + return 0; } =20 /* Owns a reference to the NBDClient passed as opaque. */ @@ -1113,6 +1096,8 @@ static coroutine_fn void nbd_trip(void *opaque) =20 req =3D nbd_request_get(client); ret =3D nbd_co_receive_request(req, &request); + client->recv_coroutine =3D NULL; + nbd_client_receive_next_request(client); if (ret =3D=3D -EIO) { goto out; } --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155817532655.5714275853734; Tue, 30 May 2017 07:50:17 -0700 (PDT) Received: from localhost ([::1]:54265 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiTO-0005GZ-4p for importer@patchew.org; Tue, 30 May 2017 10:50:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005Q8-1O for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000Q3-Pl for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:33734 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NI-Uv for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:00 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEM027829; Tue, 30 May 2017 17:30:54 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:39 +0300 Message-Id: <20170530143052.165002-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 06/19] nbd/server: remove NBDClientNewData 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" "co" field of NBDClientNewData is unused, so let's just use client pointer instead of extra structure. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 546bf3ae61..3d4cd3d21c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -535,14 +535,8 @@ static int nbd_negotiate_options(NBDClient *client) } } =20 -typedef struct { - NBDClient *client; - Coroutine *co; -} NBDClientNewData; - -static coroutine_fn int nbd_negotiate(NBDClientNewData *data) +static coroutine_fn int nbd_negotiate(NBDClient *client) { - NBDClient *client =3D data->client; char buf[8 + 8 + 8 + 128]; int rc; const uint16_t myflags =3D (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM | @@ -1268,16 +1262,15 @@ static void nbd_client_receive_next_request(NBDClie= nt *client) =20 static coroutine_fn void nbd_co_client_start(void *opaque) { - NBDClientNewData *data =3D opaque; - NBDClient *client =3D data->client; + NBDClient *client =3D opaque; NBDExport *exp =3D client->exp; =20 if (exp) { nbd_export_get(exp); } - if (nbd_negotiate(data)) { + if (nbd_negotiate(client)) { client_close(client); - goto out; + return; } qemu_co_mutex_init(&client->send_lock); =20 @@ -1286,9 +1279,6 @@ static coroutine_fn void nbd_co_client_start(void *op= aque) } =20 nbd_client_receive_next_request(client); - -out: - g_free(data); } =20 void nbd_client_new(NBDExport *exp, @@ -1298,7 +1288,7 @@ void nbd_client_new(NBDExport *exp, void (*close_fn)(NBDClient *)) { NBDClient *client; - NBDClientNewData *data =3D g_new(NBDClientNewData, 1); + Coroutine *co; =20 client =3D g_malloc0(sizeof(NBDClient)); client->refcount =3D 1; @@ -1314,7 +1304,6 @@ void nbd_client_new(NBDExport *exp, object_ref(OBJECT(client->ioc)); client->close =3D close_fn; =20 - data->client =3D client; - data->co =3D qemu_coroutine_create(nbd_co_client_start, data); - qemu_coroutine_enter(data->co); + co =3D qemu_coroutine_create(nbd_co_client_start, client); + qemu_coroutine_enter(co); } --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496154825457878.5783084055502; Tue, 30 May 2017 07:33:45 -0700 (PDT) Received: from localhost ([::1]:54167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiDO-0007sw-Lq for importer@patchew.org; Tue, 30 May 2017 10:33:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005Q4-1H for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000PD-4c for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:1281 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NB-It for qemu-devel@nongnu.org; Tue, 30 May 2017 10:30:59 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEN027829; Tue, 30 May 2017 17:30:54 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:40 +0300 Message-Id: <20170530143052.165002-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 07/19] nbd/server: nbd_negotiate: fix error path 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Current code will return 0 on this write_sync fail, as rc is 0 after successful nbd_negotiate_options. Fix this. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nbd/server.c b/nbd/server.c index 3d4cd3d21c..984fad4bdb 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -607,7 +607,8 @@ static coroutine_fn int nbd_negotiate(NBDClient *client) stq_be_p(buf + 18, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); len =3D client->no_zeroes ? 10 : sizeof(buf) - 18; - if (write_sync(client->ioc, buf + 18, len, NULL) < 0) { + rc =3D write_sync(client->ioc, buf + 18, len, NULL); + if (rc < 0) { LOG("write failed"); goto fail; } --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155296460317.09947820732043; Tue, 30 May 2017 07:41:36 -0700 (PDT) Received: from localhost ([::1]:54213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiL0-0006ef-F7 for importer@patchew.org; Tue, 30 May 2017 10:41:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005Q6-17 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAl-0000OI-GN for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:15767 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NH-4O for qemu-devel@nongnu.org; Tue, 30 May 2017 10:30:59 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEO027829; Tue, 30 May 2017 17:30:55 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:41 +0300 Message-Id: <20170530143052.165002-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 08/19] nbd/server: get rid of fail: return rc 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" "goto fail" error handling scheme is not needed for just returning error code. Better is return it immediately. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 984fad4bdb..4e9d33d83c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -265,7 +265,6 @@ static int nbd_negotiate_handle_list(NBDClient *client,= uint32_t length) =20 static int nbd_negotiate_handle_export_name(NBDClient *client, uint32_t le= ngth) { - int rc =3D -EINVAL; char name[NBD_MAX_NAME_SIZE + 1]; =20 /* Client sends: @@ -274,11 +273,11 @@ static int nbd_negotiate_handle_export_name(NBDClient= *client, uint32_t length) TRACE("Checking length"); if (length >=3D sizeof(name)) { LOG("Bad length received"); - goto fail; + return -EINVAL; } if (read_sync(client->ioc, name, length, NULL) < 0) { LOG("read failed"); - goto fail; + return -EINVAL; } name[length] =3D '\0'; =20 @@ -287,14 +286,13 @@ static int nbd_negotiate_handle_export_name(NBDClient= *client, uint32_t length) client->exp =3D nbd_export_find(name); if (!client->exp) { LOG("export not found"); - goto fail; + return -EINVAL; } =20 QTAILQ_INSERT_TAIL(&client->exp->clients, client, next); nbd_export_get(client->exp); - rc =3D 0; -fail: - return rc; + + return 0; } =20 /* Handle NBD_OPT_STARTTLS. Return NULL to drop connection, or else the @@ -564,7 +562,6 @@ static coroutine_fn int nbd_negotiate(NBDClient *client) */ =20 qio_channel_set_blocking(client->ioc, false, NULL); - rc =3D -EINVAL; =20 TRACE("Beginning negotiation."); memset(buf, 0, sizeof(buf)); @@ -585,21 +582,21 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt) if (oldStyle) { if (client->tlscreds) { TRACE("TLS cannot be enabled with oldstyle protocol"); - goto fail; + return -EINVAL; } if (write_sync(client->ioc, buf, sizeof(buf), NULL) < 0) { LOG("write failed"); - goto fail; + return -EINVAL; } } else { if (write_sync(client->ioc, buf, 18, NULL) < 0) { LOG("write failed"); - goto fail; + return -EINVAL; } rc =3D nbd_negotiate_options(client); if (rc !=3D 0) { LOG("option negotiation failed"); - goto fail; + return rc; } =20 TRACE("advertising size %" PRIu64 " and flags %x", @@ -610,14 +607,13 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt) rc =3D write_sync(client->ioc, buf + 18, len, NULL); if (rc < 0) { LOG("write failed"); - goto fail; + return rc; } } =20 TRACE("Negotiation succeeded."); - rc =3D 0; -fail: - return rc; + + return 0; } =20 static int nbd_receive_request(QIOChannel *ioc, NBDRequest *request) --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155557365843.1851397074172; Tue, 30 May 2017 07:45:57 -0700 (PDT) Received: from localhost ([::1]:54243 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiPC-0001mw-Qm for importer@patchew.org; Tue, 30 May 2017 10:45:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAq-0005Ru-PM for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAn-0000Qf-84 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:9914 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAm-0000NC-Rg for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:01 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEP027829; Tue, 30 May 2017 17:30:55 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:42 +0300 Message-Id: <20170530143052.165002-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 09/19] nbd/server: rename rc to ret 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" For consistency use 'ret' name for saving return code everywhere in the file. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 4e9d33d83c..a76267bea7 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -211,15 +211,15 @@ static int nbd_negotiate_send_rep_list(QIOChannel *io= c, NBDExport *exp) uint32_t len; const char *name =3D exp->name ? exp->name : ""; const char *desc =3D exp->description ? exp->description : ""; - int rc; + int ret; =20 TRACE("Advertising export name '%s' description '%s'", name, desc); name_len =3D strlen(name); desc_len =3D strlen(desc); len =3D name_len + desc_len + sizeof(len); - rc =3D nbd_negotiate_send_rep_len(ioc, NBD_REP_SERVER, NBD_OPT_LIST, l= en); - if (rc < 0) { - return rc; + ret =3D nbd_negotiate_send_rep_len(ioc, NBD_REP_SERVER, NBD_OPT_LIST, = len); + if (ret < 0) { + return ret; } =20 len =3D cpu_to_be32(name_len); @@ -536,7 +536,7 @@ static int nbd_negotiate_options(NBDClient *client) static coroutine_fn int nbd_negotiate(NBDClient *client) { char buf[8 + 8 + 8 + 128]; - int rc; + int ret; const uint16_t myflags =3D (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA | NBD_FLAG_SEND_WRITE_ZEROES); @@ -593,10 +593,10 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt) LOG("write failed"); return -EINVAL; } - rc =3D nbd_negotiate_options(client); - if (rc !=3D 0) { + ret =3D nbd_negotiate_options(client); + if (ret !=3D 0) { LOG("option negotiation failed"); - return rc; + return ret; } =20 TRACE("advertising size %" PRIu64 " and flags %x", @@ -604,10 +604,10 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt) stq_be_p(buf + 18, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); len =3D client->no_zeroes ? 10 : sizeof(buf) - 18; - rc =3D write_sync(client->ioc, buf + 18, len, NULL); - if (rc < 0) { + ret =3D write_sync(client->ioc, buf + 18, len, NULL); + if (ret < 0) { LOG("write failed"); - return rc; + return ret; } } =20 @@ -963,21 +963,21 @@ void nbd_export_close_all(void) static int nbd_co_send_reply(NBDRequestData *req, NBDReply *reply, int len) { NBDClient *client =3D req->client; - int rc; + int ret; =20 g_assert(qemu_in_coroutine()); qemu_co_mutex_lock(&client->send_lock); client->send_coroutine =3D qemu_coroutine_self(); =20 if (!len) { - rc =3D nbd_send_reply(client->ioc, reply); + ret =3D nbd_send_reply(client->ioc, reply); } else { qio_channel_set_cork(client->ioc, true); - rc =3D nbd_send_reply(client->ioc, reply); - if (rc =3D=3D 0) { - rc =3D write_sync(client->ioc, req->data, len, NULL); - if (rc < 0) { - rc =3D -EIO; + ret =3D nbd_send_reply(client->ioc, reply); + if (ret =3D=3D 0) { + ret =3D write_sync(client->ioc, req->data, len, NULL); + if (ret < 0) { + ret =3D -EIO; } } qio_channel_set_cork(client->ioc, false); @@ -985,7 +985,7 @@ static int nbd_co_send_reply(NBDRequestData *req, NBDRe= ply *reply, int len) =20 client->send_coroutine =3D NULL; qemu_co_mutex_unlock(&client->send_lock); - return rc; + return ret; } =20 /* nbd_co_receive_request --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155322182957.369136011594; Tue, 30 May 2017 07:42:02 -0700 (PDT) Received: from localhost ([::1]:54214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiLP-0006yA-4Z for importer@patchew.org; Tue, 30 May 2017 10:41:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005QE-2c for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000PM-5N for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:42902 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000N9-Mw for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:00 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEQ027829; Tue, 30 May 2017 17:30:55 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:43 +0300 Message-Id: <20170530143052.165002-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 10/19] nbd/server: refactor nbd_trip 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" - do not goto into switch block from outer block - reduce code duplications Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index a76267bea7..a47f13e4fb 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1078,6 +1078,7 @@ static coroutine_fn void nbd_trip(void *opaque) NBDReply reply; int ret; int flags; + int reply_data_len =3D 0; =20 TRACE("Reading request."); if (client->closing) { @@ -1090,7 +1091,7 @@ static coroutine_fn void nbd_trip(void *opaque) client->recv_coroutine =3D NULL; nbd_client_receive_next_request(client); if (ret =3D=3D -EIO) { - goto out; + goto disconnect; } =20 reply.handle =3D request.handle; @@ -1098,7 +1099,7 @@ static coroutine_fn void nbd_trip(void *opaque) =20 if (ret < 0) { reply.error =3D -ret; - goto error_reply; + goto reply; } =20 if (client->closing) { @@ -1119,7 +1120,7 @@ static coroutine_fn void nbd_trip(void *opaque) if (ret < 0) { LOG("flush failed"); reply.error =3D -ret; - goto error_reply; + break; } } =20 @@ -1128,12 +1129,12 @@ static coroutine_fn void nbd_trip(void *opaque) if (ret < 0) { LOG("reading from file failed"); reply.error =3D -ret; - goto error_reply; + break; } =20 + reply_data_len =3D request.len; TRACE("Read %" PRIu32" byte(s)", request.len); - if (nbd_co_send_reply(req, &reply, request.len) < 0) - goto out; + break; case NBD_CMD_WRITE: TRACE("Request type is WRITE"); @@ -1141,7 +1142,7 @@ static coroutine_fn void nbd_trip(void *opaque) if (exp->nbdflags & NBD_FLAG_READ_ONLY) { TRACE("Server is read-only, return error"); reply.error =3D EROFS; - goto error_reply; + break; } =20 TRACE("Writing to device"); @@ -1155,21 +1156,16 @@ static coroutine_fn void nbd_trip(void *opaque) if (ret < 0) { LOG("writing to file failed"); reply.error =3D -ret; - goto error_reply; } =20 - if (nbd_co_send_reply(req, &reply, 0) < 0) { - goto out; - } break; - case NBD_CMD_WRITE_ZEROES: TRACE("Request type is WRITE_ZEROES"); =20 if (exp->nbdflags & NBD_FLAG_READ_ONLY) { TRACE("Server is read-only, return error"); reply.error =3D EROFS; - goto error_reply; + break; } =20 TRACE("Writing to device"); @@ -1186,14 +1182,9 @@ static coroutine_fn void nbd_trip(void *opaque) if (ret < 0) { LOG("writing to file failed"); reply.error =3D -ret; - goto error_reply; } =20 - if (nbd_co_send_reply(req, &reply, 0) < 0) { - goto out; - } break; - case NBD_CMD_DISC: /* unreachable, thanks to special case in nbd_co_receive_request()= */ abort(); @@ -1206,9 +1197,7 @@ static coroutine_fn void nbd_trip(void *opaque) LOG("flush failed"); reply.error =3D -ret; } - if (nbd_co_send_reply(req, &reply, 0) < 0) { - goto out; - } + break; case NBD_CMD_TRIM: TRACE("Request type is TRIM"); @@ -1218,21 +1207,19 @@ static coroutine_fn void nbd_trip(void *opaque) LOG("discard failed"); reply.error =3D -ret; } - if (nbd_co_send_reply(req, &reply, 0) < 0) { - goto out; - } + break; default: LOG("invalid request type (%" PRIu32 ") received", request.type); reply.error =3D EINVAL; - error_reply: - /* We must disconnect after NBD_CMD_WRITE if we did not - * read the payload. - */ - if (nbd_co_send_reply(req, &reply, 0) < 0 || !req->complete) { - goto out; - } - break; + } + +reply: + /* We must disconnect after NBD_CMD_WRITE if we did not + * read the payload. + */ + if (nbd_co_send_reply(req, &reply, reply_data_len) < 0 || !req->comple= te) { + goto disconnect; } =20 TRACE("Request/Reply complete"); @@ -1242,7 +1229,7 @@ done: nbd_client_put(client); return; =20 -out: +disconnect: nbd_request_put(req); client_close(client); nbd_client_put(client); --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155166204411.1664679057254; Tue, 30 May 2017 07:39:26 -0700 (PDT) Received: from localhost ([::1]:54195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiIu-0004kR-O8 for importer@patchew.org; Tue, 30 May 2017 10:39:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005QI-37 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000QC-Sz for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:21678 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAm-0000NG-1M for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:00 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqER027829; Tue, 30 May 2017 17:30:55 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:44 +0300 Message-Id: <20170530143052.165002-12-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 11/19] io/channel-socket: qio_channel_socket_writev handle EPIPE 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Return QIO_CHANNEL_ERR_EPIPE on EPIPE, we will need it to improve error path in nbd server. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/io/channel.h | 1 + io/channel-socket.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/io/channel.h b/include/io/channel.h index 5d48906998..5529c2da31 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -38,6 +38,7 @@ typedef struct QIOChannel QIOChannel; typedef struct QIOChannelClass QIOChannelClass; =20 #define QIO_CHANNEL_ERR_BLOCK -2 +#define QIO_CHANNEL_ERR_EPIPE -3 =20 typedef enum QIOChannelFeature QIOChannelFeature; =20 diff --git a/io/channel-socket.c b/io/channel-socket.c index 53386b7ba3..50f9f966c6 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -542,7 +542,7 @@ static ssize_t qio_channel_socket_writev(QIOChannel *io= c, } error_setg_errno(errp, errno, "Unable to write to socket"); - return -1; + return errno =3D=3D EPIPE ? QIO_CHANNEL_ERR_EPIPE : -1; } return ret; } --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 149615477977034.89052735779046; Tue, 30 May 2017 07:32:59 -0700 (PDT) Received: from localhost ([::1]:54163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiCf-0007HM-DI for importer@patchew.org; Tue, 30 May 2017 10:32:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAo-0005Pw-V5 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAl-0000OR-Gz for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:6883 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NO-6Y for qemu-devel@nongnu.org; Tue, 30 May 2017 10:30:59 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqES027829; Tue, 30 May 2017 17:30:55 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:45 +0300 Message-Id: <20170530143052.165002-13-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 12/19] nbd/common: nbd_wr_syncv handle QIO_CHANNEL_ERR_EPIPE 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Return EPIPE in case of QIO_CHANNEL_ERR_EPIPE, we will need it to improve error path in nbd server. Signed-off-by: Vladimir Sementsov-Ogievskiy --- nbd/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbd/common.c b/nbd/common.c index e520aae741..88e0297fb2 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -52,7 +52,7 @@ ssize_t nbd_wr_syncv(QIOChannel *ioc, continue; } if (len < 0) { - done =3D -EIO; + done =3D len =3D=3D QIO_CHANNEL_ERR_EPIPE ? -EPIPE : -EIO; goto cleanup; } =20 --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155414682816.1244984072069; Tue, 30 May 2017 07:43:34 -0700 (PDT) Received: from localhost ([::1]:54222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiMt-0008FE-BS for importer@patchew.org; Tue, 30 May 2017 10:43:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005QF-2T for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000Pe-78 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:5654 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NV-JJ for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:00 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqET027829; Tue, 30 May 2017 17:30:55 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:46 +0300 Message-Id: <20170530143052.165002-14-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 13/19] nbd/server: return original error codes 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" The code in many cases return -EINVAL or -EIO instead of original error code from, for example, write_sync(). Following patch will need EPIPE handling, so, let's refactor this where possible (the only exclusion is nbd_co_receive_request, with own return-code convention) Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 124 +++++++++++++++++++++++++++++++++++++------------------= ---- 1 file changed, 77 insertions(+), 47 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index a47f13e4fb..30dfb81a5c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -136,30 +136,38 @@ static void nbd_client_receive_next_request(NBDClient= *client); static int nbd_negotiate_send_rep_len(QIOChannel *ioc, uint32_t type, uint32_t opt, uint32_t len) { + int ret; uint64_t magic; =20 TRACE("Reply opt=3D%" PRIx32 " type=3D%" PRIx32 " len=3D%" PRIu32, type, opt, len); =20 magic =3D cpu_to_be64(NBD_REP_MAGIC); - if (write_sync(ioc, &magic, sizeof(magic), NULL) < 0) { + ret =3D write_sync(ioc, &magic, sizeof(magic), NULL); + if (ret < 0) { LOG("write failed (rep magic)"); - return -EINVAL; + return ret; } + opt =3D cpu_to_be32(opt); - if (write_sync(ioc, &opt, sizeof(opt), NULL) < 0) { + ret =3D write_sync(ioc, &opt, sizeof(opt), NULL); + if (ret < 0) { LOG("write failed (rep opt)"); - return -EINVAL; + return ret; } + type =3D cpu_to_be32(type); - if (write_sync(ioc, &type, sizeof(type), NULL) < 0) { + ret =3D write_sync(ioc, &type, sizeof(type), NULL); + if (ret < 0) { LOG("write failed (rep type)"); - return -EINVAL; + return ret; } + len =3D cpu_to_be32(len); - if (write_sync(ioc, &len, sizeof(len), NULL) < 0) { + ret =3D write_sync(ioc, &len, sizeof(len), NULL); + if (ret < 0) { LOG("write failed (rep data length)"); - return -EINVAL; + return ret; } return 0; } @@ -192,12 +200,12 @@ nbd_negotiate_send_rep_err(QIOChannel *ioc, uint32_t = type, if (ret < 0) { goto out; } - if (write_sync(ioc, msg, len, NULL) < 0) { + + ret =3D write_sync(ioc, msg, len, NULL); + if (ret < 0) { LOG("write failed (error message)"); - ret =3D -EIO; - } else { - ret =3D 0; } + out: g_free(msg); return ret; @@ -223,18 +231,24 @@ static int nbd_negotiate_send_rep_list(QIOChannel *io= c, NBDExport *exp) } =20 len =3D cpu_to_be32(name_len); - if (write_sync(ioc, &len, sizeof(len), NULL) < 0) { + ret =3D write_sync(ioc, &len, sizeof(len), NULL); + if (ret < 0) { LOG("write failed (name length)"); - return -EINVAL; + return ret; } - if (write_sync(ioc, name, name_len, NULL) < 0) { + + ret =3D write_sync(ioc, name, name_len, NULL); + if (ret < 0) { LOG("write failed (name buffer)"); - return -EINVAL; + return ret; } - if (write_sync(ioc, desc, desc_len, NULL) < 0) { + + ret =3D write_sync(ioc, desc, desc_len, NULL); + if (ret < 0) { LOG("write failed (description buffer)"); - return -EINVAL; + return ret; } + return 0; } =20 @@ -242,11 +256,13 @@ static int nbd_negotiate_send_rep_list(QIOChannel *io= c, NBDExport *exp) * Return -errno on error, 0 on success. */ static int nbd_negotiate_handle_list(NBDClient *client, uint32_t length) { + int ret; NBDExport *exp; =20 if (length) { - if (drop_sync(client->ioc, length, NULL) < 0) { - return -EIO; + ret =3D drop_sync(client->ioc, length, NULL); + if (ret < 0) { + return ret; } return nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_INVALID, NBD_OPT_LIS= T, @@ -255,8 +271,9 @@ static int nbd_negotiate_handle_list(NBDClient *client,= uint32_t length) =20 /* For each export, send a NBD_REP_SERVER reply. */ QTAILQ_FOREACH(exp, &exports, next) { - if (nbd_negotiate_send_rep_list(client->ioc, exp)) { - return -EINVAL; + ret =3D nbd_negotiate_send_rep_list(client->ioc, exp); + if (ret < 0) { + return ret; } } /* Finish with a NBD_REP_ACK. */ @@ -265,6 +282,7 @@ static int nbd_negotiate_handle_list(NBDClient *client,= uint32_t length) =20 static int nbd_negotiate_handle_export_name(NBDClient *client, uint32_t le= ngth) { + int ret; char name[NBD_MAX_NAME_SIZE + 1]; =20 /* Client sends: @@ -275,9 +293,11 @@ static int nbd_negotiate_handle_export_name(NBDClient = *client, uint32_t length) LOG("Bad length received"); return -EINVAL; } - if (read_sync(client->ioc, name, length, NULL) < 0) { + + ret =3D read_sync(client->ioc, name, length, NULL); + if (ret < 0) { LOG("read failed"); - return -EINVAL; + return ret; } name[length] =3D '\0'; =20 @@ -354,6 +374,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, * Return -errno on error, 0 on success. */ static int nbd_negotiate_options(NBDClient *client) { + int ret; uint32_t flags; bool fixedNewstyle =3D false; =20 @@ -371,9 +392,10 @@ static int nbd_negotiate_options(NBDClient *client) ... Rest of request */ =20 - if (read_sync(client->ioc, &flags, sizeof(flags), NULL) < 0) { + ret =3D read_sync(client->ioc, &flags, sizeof(flags), NULL); + if (ret < 0) { LOG("read failed"); - return -EIO; + return ret; } TRACE("Checking client flags"); be32_to_cpus(&flags); @@ -397,9 +419,10 @@ static int nbd_negotiate_options(NBDClient *client) uint32_t clientflags, length; uint64_t magic; =20 - if (read_sync(client->ioc, &magic, sizeof(magic), NULL) < 0) { + ret =3D read_sync(client->ioc, &magic, sizeof(magic), NULL); + if (ret < 0) { LOG("read failed"); - return -EINVAL; + return ret; } TRACE("Checking opts magic"); if (magic !=3D be64_to_cpu(NBD_OPTS_MAGIC)) { @@ -407,17 +430,17 @@ static int nbd_negotiate_options(NBDClient *client) return -EINVAL; } =20 - if (read_sync(client->ioc, &clientflags, - sizeof(clientflags), NULL) < 0) - { + ret =3D read_sync(client->ioc, &clientflags, sizeof(clientflags), = NULL); + if (ret < 0) { LOG("read failed"); - return -EINVAL; + return ret; } clientflags =3D be32_to_cpu(clientflags); =20 - if (read_sync(client->ioc, &length, sizeof(length), NULL) < 0) { + ret =3D read_sync(client->ioc, &length, sizeof(length), NULL); + if (ret < 0) { LOG("read failed"); - return -EINVAL; + return ret; } length =3D be32_to_cpu(length); =20 @@ -445,8 +468,9 @@ static int nbd_negotiate_options(NBDClient *client) return -EINVAL; =20 default: - if (drop_sync(client->ioc, length, NULL) < 0) { - return -EIO; + ret =3D drop_sync(client->ioc, length, NULL); + if (ret < 0) { + return ret; } ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_TLS_REQD, @@ -476,15 +500,17 @@ static int nbd_negotiate_options(NBDClient *client) /* NBD spec says we must try to reply before * disconnecting, but that we must also tolerate * guests that don't wait for our reply. */ - nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, clientfla= gs); - return -EINVAL; + ret =3D nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, + clientflags); + return ret < 0 ? ret : -EINVAL; =20 case NBD_OPT_EXPORT_NAME: return nbd_negotiate_handle_export_name(client, length); =20 case NBD_OPT_STARTTLS: - if (drop_sync(client->ioc, length, NULL) < 0) { - return -EIO; + ret =3D drop_sync(client->ioc, length, NULL); + if (ret < 0) { + return ret; } if (client->tlscreds) { ret =3D nbd_negotiate_send_rep_err(client->ioc, @@ -502,8 +528,9 @@ static int nbd_negotiate_options(NBDClient *client) } break; default: - if (drop_sync(client->ioc, length, NULL) < 0) { - return -EIO; + ret =3D drop_sync(client->ioc, length, NULL); + if (ret < 0) { + return ret; } ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_UNSUP, @@ -584,14 +611,17 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt) TRACE("TLS cannot be enabled with oldstyle protocol"); return -EINVAL; } - if (write_sync(client->ioc, buf, sizeof(buf), NULL) < 0) { + + ret =3D write_sync(client->ioc, buf, sizeof(buf), NULL); + if (ret < 0) { LOG("write failed"); - return -EINVAL; + return ret; } } else { - if (write_sync(client->ioc, buf, 18, NULL) < 0) { + ret =3D write_sync(client->ioc, buf, 18, NULL); + if (ret < 0) { LOG("write failed"); - return -EINVAL; + return ret; } ret =3D nbd_negotiate_options(client); if (ret !=3D 0) { @@ -977,7 +1007,7 @@ static int nbd_co_send_reply(NBDRequestData *req, NBDR= eply *reply, int len) if (ret =3D=3D 0) { ret =3D write_sync(client->ioc, req->data, len, NULL); if (ret < 0) { - ret =3D -EIO; + ret =3D ret; } } qio_channel_set_cork(client->ioc, false); --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155084067688.7363369828025; Tue, 30 May 2017 07:38:04 -0700 (PDT) Received: from localhost ([::1]:54189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiHZ-0003FQ-ME for importer@patchew.org; Tue, 30 May 2017 10:38:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005QB-1v for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAl-0000Oi-SS for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:48695 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NX-6O for qemu-devel@nongnu.org; Tue, 30 May 2017 10:30:59 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEU027829; Tue, 30 May 2017 17:30:56 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:47 +0300 Message-Id: <20170530143052.165002-15-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 14/19] nbd/server: nbd_negotiate: return 1 on NBD_OPT_ABORT 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Separate case when client sent NBD_OPT_ABORT from other errors. It will be needed for the following patch, where errors will be reported. Considered case is not actually the error - it honestly follows NBD protocol. Therefore it should not be reported like an error. -EPIPE case means client not read server reply on NBD_OPT_ABORT, which is also OK. Signed-off-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 30dfb81a5c..0e53d3dd91 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -369,9 +369,13 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCl= ient *client, return QIO_CHANNEL(tioc); } =20 - -/* Process all NBD_OPT_* client option commands. - * Return -errno on error, 0 on success. */ +/* nbd_negotiate_options + * Process all NBD_OPT_* client option commands. + * Return: + * < 0 on error + * 0 on successful negotiation + * 1 if client sent NBD_OPT_ABORT, i.e. on legal disconnect + */ static int nbd_negotiate_options(NBDClient *client) { int ret; @@ -483,7 +487,7 @@ static int nbd_negotiate_options(NBDClient *client) } /* Let the client keep trying, unless they asked to quit */ if (clientflags =3D=3D NBD_OPT_ABORT) { - return -EINVAL; + return 1; } break; } @@ -502,7 +506,7 @@ static int nbd_negotiate_options(NBDClient *client) * guests that don't wait for our reply. */ ret =3D nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, clientflags); - return ret < 0 ? ret : -EINVAL; + return ret < 0 && ret !=3D -EPIPE ? ret : 1; =20 case NBD_OPT_EXPORT_NAME: return nbd_negotiate_handle_export_name(client, length); @@ -560,6 +564,12 @@ static int nbd_negotiate_options(NBDClient *client) } } =20 +/* nbd_negotiate + * Return: + * < 0 on error + * 0 on successful negotiation + * 1 if client sent NBD_OPT_ABORT, i.e. on legal disconnect + */ static coroutine_fn int nbd_negotiate(NBDClient *client) { char buf[8 + 8 + 8 + 128]; --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155351167893.7960573233615; Tue, 30 May 2017 07:42:31 -0700 (PDT) Received: from localhost ([::1]:54215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiLt-0007LS-Gy for importer@patchew.org; Tue, 30 May 2017 10:42:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAr-0005SD-0S for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000PU-6t for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:05 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:23766 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000NZ-ES for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:00 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEV027829; Tue, 30 May 2017 17:30:56 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:48 +0300 Message-Id: <20170530143052.165002-16-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 15/19] nbd/server: use errp instead of LOG 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Move to modern errp scheme from just LOGging errors. Signed-off-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 257 ++++++++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 150 insertions(+), 107 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 0e53d3dd91..3035fb6586 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -134,7 +134,7 @@ static void nbd_client_receive_next_request(NBDClient *= client); /* Send a reply header, including length, but no payload. * Return -errno on error, 0 on success. */ static int nbd_negotiate_send_rep_len(QIOChannel *ioc, uint32_t type, - uint32_t opt, uint32_t len) + uint32_t opt, uint32_t len, Error **= errp) { int ret; uint64_t magic; @@ -143,30 +143,30 @@ static int nbd_negotiate_send_rep_len(QIOChannel *ioc= , uint32_t type, type, opt, len); =20 magic =3D cpu_to_be64(NBD_REP_MAGIC); - ret =3D write_sync(ioc, &magic, sizeof(magic), NULL); + ret =3D write_sync(ioc, &magic, sizeof(magic), errp); if (ret < 0) { - LOG("write failed (rep magic)"); + error_prepend(errp, "write failed (rep magic): "); return ret; } =20 opt =3D cpu_to_be32(opt); - ret =3D write_sync(ioc, &opt, sizeof(opt), NULL); + ret =3D write_sync(ioc, &opt, sizeof(opt), errp); if (ret < 0) { - LOG("write failed (rep opt)"); + error_prepend(errp, "write failed (rep opt): "); return ret; } =20 type =3D cpu_to_be32(type); - ret =3D write_sync(ioc, &type, sizeof(type), NULL); + ret =3D write_sync(ioc, &type, sizeof(type), errp); if (ret < 0) { - LOG("write failed (rep type)"); + error_prepend(errp, "write failed (rep type): "); return ret; } =20 len =3D cpu_to_be32(len); - ret =3D write_sync(ioc, &len, sizeof(len), NULL); + ret =3D write_sync(ioc, &len, sizeof(len), errp); if (ret < 0) { - LOG("write failed (rep data length)"); + error_prepend(errp, "write failed (rep data length): "); return ret; } return 0; @@ -174,16 +174,17 @@ static int nbd_negotiate_send_rep_len(QIOChannel *ioc= , uint32_t type, =20 /* Send a reply header with default 0 length. * Return -errno on error, 0 on success. */ -static int nbd_negotiate_send_rep(QIOChannel *ioc, uint32_t type, uint32_t= opt) +static int nbd_negotiate_send_rep(QIOChannel *ioc, uint32_t type, uint32_t= opt, + Error **errp) { - return nbd_negotiate_send_rep_len(ioc, type, opt, 0); + return nbd_negotiate_send_rep_len(ioc, type, opt, 0, errp); } =20 /* Send an error reply. * Return -errno on error, 0 on success. */ -static int GCC_FMT_ATTR(4, 5) +static int GCC_FMT_ATTR(5, 6) nbd_negotiate_send_rep_err(QIOChannel *ioc, uint32_t type, - uint32_t opt, const char *fmt, ...) + uint32_t opt, Error **errp, const char *fmt, ..= .) { va_list va; char *msg; @@ -196,14 +197,14 @@ nbd_negotiate_send_rep_err(QIOChannel *ioc, uint32_t = type, len =3D strlen(msg); assert(len < 4096); TRACE("sending error message \"%s\"", msg); - ret =3D nbd_negotiate_send_rep_len(ioc, type, opt, len); + ret =3D nbd_negotiate_send_rep_len(ioc, type, opt, len, errp); if (ret < 0) { goto out; } =20 - ret =3D write_sync(ioc, msg, len, NULL); + ret =3D write_sync(ioc, msg, len, errp); if (ret < 0) { - LOG("write failed (error message)"); + error_prepend(errp, "write failed (error message): "); } =20 out: @@ -213,7 +214,8 @@ out: =20 /* Send a single NBD_REP_SERVER reply to NBD_OPT_LIST, including payload. * Return -errno on error, 0 on success. */ -static int nbd_negotiate_send_rep_list(QIOChannel *ioc, NBDExport *exp) +static int nbd_negotiate_send_rep_list(QIOChannel *ioc, NBDExport *exp, + Error **errp) { size_t name_len, desc_len; uint32_t len; @@ -225,27 +227,28 @@ static int nbd_negotiate_send_rep_list(QIOChannel *io= c, NBDExport *exp) name_len =3D strlen(name); desc_len =3D strlen(desc); len =3D name_len + desc_len + sizeof(len); - ret =3D nbd_negotiate_send_rep_len(ioc, NBD_REP_SERVER, NBD_OPT_LIST, = len); + ret =3D nbd_negotiate_send_rep_len(ioc, NBD_REP_SERVER, NBD_OPT_LIST, = len, + errp); if (ret < 0) { return ret; } =20 len =3D cpu_to_be32(name_len); - ret =3D write_sync(ioc, &len, sizeof(len), NULL); + ret =3D write_sync(ioc, &len, sizeof(len), errp); if (ret < 0) { - LOG("write failed (name length)"); + error_prepend(errp, "write failed (name length): "); return ret; } =20 - ret =3D write_sync(ioc, name, name_len, NULL); + ret =3D write_sync(ioc, name, name_len, errp); if (ret < 0) { - LOG("write failed (name buffer)"); + error_prepend(errp, "write failed (name buffer): "); return ret; } =20 - ret =3D write_sync(ioc, desc, desc_len, NULL); + ret =3D write_sync(ioc, desc, desc_len, errp); if (ret < 0) { - LOG("write failed (description buffer)"); + error_prepend(errp, "write failed (description buffer): "); return ret; } =20 @@ -254,33 +257,36 @@ static int nbd_negotiate_send_rep_list(QIOChannel *io= c, NBDExport *exp) =20 /* Process the NBD_OPT_LIST command, with a potential series of replies. * Return -errno on error, 0 on success. */ -static int nbd_negotiate_handle_list(NBDClient *client, uint32_t length) +static int nbd_negotiate_handle_list(NBDClient *client, uint32_t length, + Error **errp) { int ret; NBDExport *exp; =20 if (length) { - ret =3D drop_sync(client->ioc, length, NULL); + ret =3D drop_sync(client->ioc, length, errp); if (ret < 0) { return ret; } return nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_INVALID, NBD_OPT_LIS= T, + errp, "OPT_LIST should not have length= "); } =20 /* For each export, send a NBD_REP_SERVER reply. */ QTAILQ_FOREACH(exp, &exports, next) { - ret =3D nbd_negotiate_send_rep_list(client->ioc, exp); + ret =3D nbd_negotiate_send_rep_list(client->ioc, exp, errp); if (ret < 0) { return ret; } } /* Finish with a NBD_REP_ACK. */ - return nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, NBD_OPT_LIST); + return nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, NBD_OPT_LIST, = errp); } =20 -static int nbd_negotiate_handle_export_name(NBDClient *client, uint32_t le= ngth) +static int nbd_negotiate_handle_export_name(NBDClient *client, uint32_t le= ngth, + Error **errp) { int ret; char name[NBD_MAX_NAME_SIZE + 1]; @@ -290,13 +296,13 @@ static int nbd_negotiate_handle_export_name(NBDClient= *client, uint32_t length) */ TRACE("Checking length"); if (length >=3D sizeof(name)) { - LOG("Bad length received"); + error_setg(errp, "Bad length received"); return -EINVAL; } =20 - ret =3D read_sync(client->ioc, name, length, NULL); + ret =3D read_sync(client->ioc, name, length, errp); if (ret < 0) { - LOG("read failed"); + error_setg(errp, "read failed"); return ret; } name[length] =3D '\0'; @@ -305,7 +311,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, uint32_t length) =20 client->exp =3D nbd_export_find(name); if (!client->exp) { - LOG("export not found"); + error_setg(errp, "export not found"); return -EINVAL; } =20 @@ -318,7 +324,8 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, uint32_t length) /* Handle NBD_OPT_STARTTLS. Return NULL to drop connection, or else the * new channel for all further (now-encrypted) communication. */ static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client, - uint32_t length) + uint32_t length, + Error **errp) { QIOChannel *ioc; QIOChannelTLS *tioc; @@ -327,23 +334,24 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDC= lient *client, TRACE("Setting up TLS"); ioc =3D client->ioc; if (length) { - if (drop_sync(ioc, length, NULL) < 0) { + if (drop_sync(ioc, length, errp) < 0) { return NULL; } nbd_negotiate_send_rep_err(ioc, NBD_REP_ERR_INVALID, NBD_OPT_START= TLS, + errp, "OPT_STARTTLS should not have length"); return NULL; } =20 if (nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, - NBD_OPT_STARTTLS) < 0) { + NBD_OPT_STARTTLS, errp) < 0) { return NULL; } =20 tioc =3D qio_channel_tls_new_server(ioc, client->tlscreds, client->tlsaclname, - NULL); + errp); if (!tioc) { return NULL; } @@ -362,7 +370,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, g_main_loop_unref(data.loop); if (data.error) { object_unref(OBJECT(tioc)); - error_free(data.error); + error_propagate(errp, data.error); return NULL; } =20 @@ -372,15 +380,16 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDC= lient *client, /* nbd_negotiate_options * Process all NBD_OPT_* client option commands. * Return: - * < 0 on error - * 0 on successful negotiation - * 1 if client sent NBD_OPT_ABORT, i.e. on legal disconnect + * < 0 on error, errp is set + * 0 on successful negotiation, errp is not set + * 1 if client sent NBD_OPT_ABORT, i.e. on legal disconnect, errp is not= set */ -static int nbd_negotiate_options(NBDClient *client) +static int nbd_negotiate_options(NBDClient *client, Error **errp) { int ret; uint32_t flags; bool fixedNewstyle =3D false; + Error *local_err =3D NULL; =20 /* Client sends: [ 0 .. 3] client flags @@ -396,9 +405,9 @@ static int nbd_negotiate_options(NBDClient *client) ... Rest of request */ =20 - ret =3D read_sync(client->ioc, &flags, sizeof(flags), NULL); + ret =3D read_sync(client->ioc, &flags, sizeof(flags), errp); if (ret < 0) { - LOG("read failed"); + error_prepend(errp, "read failed: "); return ret; } TRACE("Checking client flags"); @@ -414,7 +423,7 @@ static int nbd_negotiate_options(NBDClient *client) flags &=3D ~NBD_FLAG_C_NO_ZEROES; } if (flags !=3D 0) { - TRACE("Unknown client flags 0x%" PRIx32 " received", flags); + error_setg(errp, "Unknown client flags 0x%" PRIx32 " received", fl= ags); return -EIO; } =20 @@ -423,27 +432,27 @@ static int nbd_negotiate_options(NBDClient *client) uint32_t clientflags, length; uint64_t magic; =20 - ret =3D read_sync(client->ioc, &magic, sizeof(magic), NULL); + ret =3D read_sync(client->ioc, &magic, sizeof(magic), errp); if (ret < 0) { - LOG("read failed"); + error_prepend(errp, "read failed: "); return ret; } TRACE("Checking opts magic"); if (magic !=3D be64_to_cpu(NBD_OPTS_MAGIC)) { - LOG("Bad magic received"); + error_setg(errp, "Bad magic received"); return -EINVAL; } =20 - ret =3D read_sync(client->ioc, &clientflags, sizeof(clientflags), = NULL); + ret =3D read_sync(client->ioc, &clientflags, sizeof(clientflags), = errp); if (ret < 0) { - LOG("read failed"); + error_prepend(errp, "read failed: "); return ret; } clientflags =3D be32_to_cpu(clientflags); =20 - ret =3D read_sync(client->ioc, &length, sizeof(length), NULL); + ret =3D read_sync(client->ioc, &length, sizeof(length), errp); if (ret < 0) { - LOG("read failed"); + error_prepend(errp, "read failed: "); return ret; } length =3D be32_to_cpu(length); @@ -453,12 +462,12 @@ static int nbd_negotiate_options(NBDClient *client) client->ioc =3D=3D (QIOChannel *)client->sioc) { QIOChannel *tioc; if (!fixedNewstyle) { - TRACE("Unsupported option 0x%" PRIx32, clientflags); + error_setg(errp, "Unsupported option 0x%" PRIx32, clientfl= ags); return -EINVAL; } switch (clientflags) { case NBD_OPT_STARTTLS: - tioc =3D nbd_negotiate_handle_starttls(client, length); + tioc =3D nbd_negotiate_handle_starttls(client, length, err= p); if (!tioc) { return -EIO; } @@ -468,17 +477,18 @@ static int nbd_negotiate_options(NBDClient *client) =20 case NBD_OPT_EXPORT_NAME: /* No way to return an error to client, so drop connection= */ - TRACE("Option 0x%x not permitted before TLS", clientflags); + error_setg(errp, "Option 0x%x not permitted before TLS", + clientflags); return -EINVAL; =20 default: - ret =3D drop_sync(client->ioc, length, NULL); + ret =3D drop_sync(client->ioc, length, errp); if (ret < 0) { return ret; } ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_TLS_REQD, - clientflags, + clientflags, errp, "Option 0x%" PRIx32 "not permitted before TLS= ", clientflags); @@ -494,7 +504,7 @@ static int nbd_negotiate_options(NBDClient *client) } else if (fixedNewstyle) { switch (clientflags) { case NBD_OPT_LIST: - ret =3D nbd_negotiate_handle_list(client, length); + ret =3D nbd_negotiate_handle_list(client, length, errp); if (ret < 0) { return ret; } @@ -505,26 +515,33 @@ static int nbd_negotiate_options(NBDClient *client) * disconnecting, but that we must also tolerate * guests that don't wait for our reply. */ ret =3D nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, - clientflags); - return ret < 0 && ret !=3D -EPIPE ? ret : 1; + clientflags, &local_err); + + if (ret < 0 && ret !=3D -EPIPE) { + error_propagate(errp, local_err); + return ret; + } + + error_free(local_err); + return 1; =20 case NBD_OPT_EXPORT_NAME: - return nbd_negotiate_handle_export_name(client, length); + return nbd_negotiate_handle_export_name(client, length, er= rp); =20 case NBD_OPT_STARTTLS: - ret =3D drop_sync(client->ioc, length, NULL); + ret =3D drop_sync(client->ioc, length, errp); if (ret < 0) { return ret; } if (client->tlscreds) { ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_INVALID, - clientflags, + clientflags, errp, "TLS already enabled"= ); } else { ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_POLICY, - clientflags, + clientflags, errp, "TLS not configured"); } if (ret < 0) { @@ -532,13 +549,13 @@ static int nbd_negotiate_options(NBDClient *client) } break; default: - ret =3D drop_sync(client->ioc, length, NULL); + ret =3D drop_sync(client->ioc, length, errp); if (ret < 0) { return ret; } ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_UNSUP, - clientflags, + clientflags, errp, "Unsupported option 0x%" PRIx32, clientflags); @@ -554,10 +571,10 @@ static int nbd_negotiate_options(NBDClient *client) */ switch (clientflags) { case NBD_OPT_EXPORT_NAME: - return nbd_negotiate_handle_export_name(client, length); + return nbd_negotiate_handle_export_name(client, length, er= rp); =20 default: - TRACE("Unsupported option 0x%" PRIx32, clientflags); + error_setg(errp, "Unsupported option 0x%" PRIx32, clientfl= ags); return -EINVAL; } } @@ -566,11 +583,11 @@ static int nbd_negotiate_options(NBDClient *client) =20 /* nbd_negotiate * Return: - * < 0 on error - * 0 on successful negotiation - * 1 if client sent NBD_OPT_ABORT, i.e. on legal disconnect + * < 0 on error, errp is set + * 0 on successful negotiation, errp is not set + * 1 if client sent NBD_OPT_ABORT, i.e. on legal disconnect, errp is not= set */ -static coroutine_fn int nbd_negotiate(NBDClient *client) +static coroutine_fn int nbd_negotiate(NBDClient *client, Error **errp) { char buf[8 + 8 + 8 + 128]; int ret; @@ -618,24 +635,26 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt) =20 if (oldStyle) { if (client->tlscreds) { - TRACE("TLS cannot be enabled with oldstyle protocol"); + error_setg(errp, "TLS cannot be enabled with oldstyle protocol= "); return -EINVAL; } =20 - ret =3D write_sync(client->ioc, buf, sizeof(buf), NULL); + ret =3D write_sync(client->ioc, buf, sizeof(buf), errp); if (ret < 0) { - LOG("write failed"); + error_prepend(errp, "write failed: "); return ret; } } else { - ret =3D write_sync(client->ioc, buf, 18, NULL); + ret =3D write_sync(client->ioc, buf, 18, errp); if (ret < 0) { - LOG("write failed"); + error_prepend(errp, "write failed: "); return ret; } - ret =3D nbd_negotiate_options(client); + ret =3D nbd_negotiate_options(client, errp); if (ret !=3D 0) { - LOG("option negotiation failed"); + if (ret < 0) { + error_prepend(errp, "option negotiation failed: "); + } return ret; } =20 @@ -644,9 +663,9 @@ static coroutine_fn int nbd_negotiate(NBDClient *client) stq_be_p(buf + 18, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); len =3D client->no_zeroes ? 10 : sizeof(buf) - 18; - ret =3D write_sync(client->ioc, buf + 18, len, NULL); + ret =3D write_sync(client->ioc, buf + 18, len, errp); if (ret < 0) { - LOG("write failed"); + error_prepend(errp, "write failed: "); return ret; } } @@ -656,13 +675,14 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt) return 0; } =20 -static int nbd_receive_request(QIOChannel *ioc, NBDRequest *request) +static int nbd_receive_request(QIOChannel *ioc, NBDRequest *request, + Error **errp) { uint8_t buf[NBD_REQUEST_SIZE]; uint32_t magic; int ret; =20 - ret =3D read_sync(ioc, buf, sizeof(buf), NULL); + ret =3D read_sync(ioc, buf, sizeof(buf), errp); if (ret < 0) { return ret; } @@ -688,7 +708,7 @@ static int nbd_receive_request(QIOChannel *ioc, NBDRequ= est *request) magic, request->flags, request->type, request->from, request->le= n); =20 if (magic !=3D NBD_REQUEST_MAGIC) { - LOG("invalid magic (got 0x%" PRIx32 ")", magic); + error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic); return -EINVAL; } return 0; @@ -1034,13 +1054,14 @@ static int nbd_co_send_reply(NBDRequestData *req, N= BDReply *reply, int len) * the client (although the caller may still need to disconnect after repo= rting * the error). */ -static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request) +static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request, + Error **errp) { NBDClient *client =3D req->client; =20 g_assert(qemu_in_coroutine()); assert(client->recv_coroutine =3D=3D qemu_coroutine_self()); - if (nbd_receive_request(client->ioc, request) < 0) { + if (nbd_receive_request(client->ioc, request, errp) < 0) { return -EIO; } =20 @@ -1062,27 +1083,29 @@ static int nbd_co_receive_request(NBDRequestData *r= eq, NBDRequest *request) * checks as possible until after reading any NBD_CMD_WRITE * payload, so we can try and keep the connection alive. */ if ((request->from + request->len) < request->from) { - LOG("integer overflow detected, you're probably being attacked"); + error_setg(errp, + "integer overflow detected, you're probably being attac= ked"); return -EINVAL; } =20 if (request->type =3D=3D NBD_CMD_READ || request->type =3D=3D NBD_CMD_= WRITE) { if (request->len > NBD_MAX_BUFFER_SIZE) { - LOG("len (%" PRIu32" ) is larger than max len (%u)", - request->len, NBD_MAX_BUFFER_SIZE); + error_setg(errp, "len (%" PRIu32" ) is larger than max len (%u= )", + request->len, NBD_MAX_BUFFER_SIZE); return -EINVAL; } =20 req->data =3D blk_try_blockalign(client->exp->blk, request->len); if (req->data =3D=3D NULL) { + error_setg(errp, "No memory"); return -ENOMEM; } } if (request->type =3D=3D NBD_CMD_WRITE) { TRACE("Reading %" PRIu32 " byte(s)", request->len); =20 - if (read_sync(client->ioc, req->data, request->len, NULL) < 0) { - LOG("reading from socket failed"); + if (read_sync(client->ioc, req->data, request->len, errp) < 0) { + error_prepend(errp, "reading from socket failed: "); return -EIO; } req->complete =3D true; @@ -1090,18 +1113,18 @@ static int nbd_co_receive_request(NBDRequestData *r= eq, NBDRequest *request) =20 /* Sanity checks, part 2. */ if (request->from + request->len > client->exp->size) { - LOG("operation past EOF; From: %" PRIu64 ", Len: %" PRIu32 - ", Size: %" PRIu64, request->from, request->len, - (uint64_t)client->exp->size); + error_setg(errp, "operation past EOF; From: %" PRIu64 ", Len: %" P= RIu32 + ", Size: %" PRIu64, request->from, request->len, + (uint64_t)client->exp->size); return request->type =3D=3D NBD_CMD_WRITE ? -ENOSPC : -EINVAL; } if (request->flags & ~(NBD_CMD_FLAG_FUA | NBD_CMD_FLAG_NO_HOLE)) { - LOG("unsupported flags (got 0x%x)", request->flags); + error_setg(errp, "unsupported flags (got 0x%x)", request->flags); return -EINVAL; } if (request->type !=3D NBD_CMD_WRITE_ZEROES && (request->flags & NBD_CMD_FLAG_NO_HOLE)) { - LOG("unexpected flags (got 0x%x)", request->flags); + error_setg(errp, "unexpected flags (got 0x%x)", request->flags); return -EINVAL; } =20 @@ -1119,6 +1142,7 @@ static coroutine_fn void nbd_trip(void *opaque) int ret; int flags; int reply_data_len =3D 0; + Error *local_err =3D NULL; =20 TRACE("Reading request."); if (client->closing) { @@ -1127,7 +1151,7 @@ static coroutine_fn void nbd_trip(void *opaque) } =20 req =3D nbd_request_get(client); - ret =3D nbd_co_receive_request(req, &request); + ret =3D nbd_co_receive_request(req, &request, &local_err); client->recv_coroutine =3D NULL; nbd_client_receive_next_request(client); if (ret =3D=3D -EIO) { @@ -1158,7 +1182,7 @@ static coroutine_fn void nbd_trip(void *opaque) if (request.flags & NBD_CMD_FLAG_FUA) { ret =3D blk_co_flush(exp->blk); if (ret < 0) { - LOG("flush failed"); + error_setg_errno(&local_err, -ret, "flush failed"); reply.error =3D -ret; break; } @@ -1167,7 +1191,7 @@ static coroutine_fn void nbd_trip(void *opaque) ret =3D blk_pread(exp->blk, request.from + exp->dev_offset, req->data, request.len); if (ret < 0) { - LOG("reading from file failed"); + error_setg_errno(&local_err, -ret, "reading from file failed"); reply.error =3D -ret; break; } @@ -1194,7 +1218,7 @@ static coroutine_fn void nbd_trip(void *opaque) ret =3D blk_pwrite(exp->blk, request.from + exp->dev_offset, req->data, request.len, flags); if (ret < 0) { - LOG("writing to file failed"); + error_setg_errno(&local_err, -ret, "writing to file failed"); reply.error =3D -ret; } =20 @@ -1203,7 +1227,7 @@ static coroutine_fn void nbd_trip(void *opaque) TRACE("Request type is WRITE_ZEROES"); =20 if (exp->nbdflags & NBD_FLAG_READ_ONLY) { - TRACE("Server is read-only, return error"); + error_setg(&local_err, "Server is read-only, return error"); reply.error =3D EROFS; break; } @@ -1220,7 +1244,7 @@ static coroutine_fn void nbd_trip(void *opaque) ret =3D blk_pwrite_zeroes(exp->blk, request.from + exp->dev_offset, request.len, flags); if (ret < 0) { - LOG("writing to file failed"); + error_setg_errno(&local_err, -ret, "writing to file failed"); reply.error =3D -ret; } =20 @@ -1234,7 +1258,7 @@ static coroutine_fn void nbd_trip(void *opaque) =20 ret =3D blk_co_flush(exp->blk); if (ret < 0) { - LOG("flush failed"); + error_setg_errno(&local_err, -ret, "flush failed"); reply.error =3D -ret; } =20 @@ -1244,21 +1268,33 @@ static coroutine_fn void nbd_trip(void *opaque) ret =3D blk_co_pdiscard(exp->blk, request.from + exp->dev_offset, request.len); if (ret < 0) { - LOG("discard failed"); + error_setg_errno(&local_err, -ret, "discard failed"); reply.error =3D -ret; } =20 break; default: - LOG("invalid request type (%" PRIu32 ") received", request.type); + error_setg(&local_err, "invalid request type (%" PRIu32 ") receive= d", + request.type); reply.error =3D EINVAL; } =20 reply: + if (local_err) { + error_report_err(local_err); + local_err =3D NULL; + } + + if (nbd_co_send_reply(req, &reply, reply_data_len) < 0) { + error_setg(&local_err, "Failed to send reply"); + goto disconnect; + } + /* We must disconnect after NBD_CMD_WRITE if we did not * read the payload. */ - if (nbd_co_send_reply(req, &reply, reply_data_len) < 0 || !req->comple= te) { + if (!req->complete) { + error_setg(&local_err, "Request handling failed in intermediate st= ate"); goto disconnect; } =20 @@ -1270,6 +1306,9 @@ done: return; =20 disconnect: + if (local_err) { + error_reportf_err(local_err, "Disconnect client, due to: "); + } nbd_request_put(req); client_close(client); nbd_client_put(client); @@ -1288,11 +1327,15 @@ static coroutine_fn void nbd_co_client_start(void *= opaque) { NBDClient *client =3D opaque; NBDExport *exp =3D client->exp; + Error *local_err =3D NULL; =20 if (exp) { nbd_export_get(exp); } - if (nbd_negotiate(client)) { + if (nbd_negotiate(client, &local_err)) { + if (local_err) { + error_report_err(local_err); + } client_close(client); return; } --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155125686794.402452304167; Tue, 30 May 2017 07:38:45 -0700 (PDT) Received: from localhost ([::1]:54192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiIG-0004A1-3r for importer@patchew.org; Tue, 30 May 2017 10:38:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005QD-26 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000P5-3g for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:22448 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000Na-JE for qemu-devel@nongnu.org; Tue, 30 May 2017 10:30:59 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEW027829; Tue, 30 May 2017 17:30:56 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:49 +0300 Message-Id: <20170530143052.165002-17-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 16/19] nbd/server: add errp to nbd_send_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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Signed-off-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 3035fb6586..6c0702287e 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -714,7 +714,7 @@ static int nbd_receive_request(QIOChannel *ioc, NBDRequ= est *request, return 0; } =20 -static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply) +static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) { uint8_t buf[NBD_REPLY_SIZE]; =20 @@ -733,7 +733,7 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *re= ply) stl_be_p(buf + 4, reply->error); stq_be_p(buf + 8, reply->handle); =20 - return write_sync(ioc, buf, sizeof(buf), NULL); + return write_sync(ioc, buf, sizeof(buf), errp); } =20 #define MAX_NBD_REQUESTS 16 @@ -1020,7 +1020,8 @@ void nbd_export_close_all(void) } } =20 -static int nbd_co_send_reply(NBDRequestData *req, NBDReply *reply, int len) +static int nbd_co_send_reply(NBDRequestData *req, NBDReply *reply, int len, + Error **errp) { NBDClient *client =3D req->client; int ret; @@ -1030,12 +1031,12 @@ static int nbd_co_send_reply(NBDRequestData *req, N= BDReply *reply, int len) client->send_coroutine =3D qemu_coroutine_self(); =20 if (!len) { - ret =3D nbd_send_reply(client->ioc, reply); + ret =3D nbd_send_reply(client->ioc, reply, errp); } else { qio_channel_set_cork(client->ioc, true); - ret =3D nbd_send_reply(client->ioc, reply); + ret =3D nbd_send_reply(client->ioc, reply, errp); if (ret =3D=3D 0) { - ret =3D write_sync(client->ioc, req->data, len, NULL); + ret =3D write_sync(client->ioc, req->data, len, errp); if (ret < 0) { ret =3D ret; } @@ -1285,8 +1286,8 @@ reply: local_err =3D NULL; } =20 - if (nbd_co_send_reply(req, &reply, reply_data_len) < 0) { - error_setg(&local_err, "Failed to send reply"); + if (nbd_co_send_reply(req, &reply, reply_data_len, &local_err) < 0) { + error_prepend(&local_err, "Failed to send reply"); goto disconnect; } =20 --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155197913759.0429118675797; Tue, 30 May 2017 07:39:57 -0700 (PDT) Received: from localhost ([::1]:54199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiJP-0005BZ-J9 for importer@patchew.org; Tue, 30 May 2017 10:39:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005QG-2i for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000Pi-7x for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:14177 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAl-0000Nd-R1 for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:00 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEX027829; Tue, 30 May 2017 17:30:56 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:50 +0300 Message-Id: <20170530143052.165002-18-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 17/19] nbd/common: nbd_tls_handshake: use error_reportf_err instead of TRACE 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Use error_reportf_err instead of TRACE in case of fail. Signed-off-by: Vladimir Sementsov-Ogievskiy --- nbd/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbd/common.c b/nbd/common.c index 88e0297fb2..574a551abe 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -102,7 +102,7 @@ void nbd_tls_handshake(QIOTask *task, struct NBDTLSHandshakeData *data =3D opaque; =20 if (qio_task_propagate_error(task, &data->error)) { - TRACE("TLS failed %s", error_get_pretty(data->error)); + error_reportf_err(data->error, "TLS failed"); } data->complete =3D true; g_main_loop_quit(data->loop); --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496154935730201.32177542473403; Tue, 30 May 2017 07:35:35 -0700 (PDT) Received: from localhost ([::1]:54179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiFA-0000vH-3Q for importer@patchew.org; Tue, 30 May 2017 10:35:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAp-0005Q3-0n for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAm-0000QJ-WC for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:02 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:6896 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAm-0000Ne-0s for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:00 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEY027829; Tue, 30 May 2017 17:30:56 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:51 +0300 Message-Id: <20170530143052.165002-19-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 18/19] nbd/client: refactor TRACE of NBD_MAGIC 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Signed-off-by: Vladimir Sementsov-Ogievskiy --- nbd/client.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 3d15596120..52f7981c9c 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -426,6 +426,21 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *io= c, return QIO_CHANNEL(tioc); } =20 +static const char *nbd_magic_to_string(char *out, const char *in, + size_t count) +{ + size_t i; + + for (i =3D 0; i < count; ++i) { + if (in[i] =3D=3D '\0') { + out[i] =3D '\0'; + break; + } + out[i] =3D qemu_isprint(in[i]) ? in[i] : '.'; + } + + return out; +} =20 int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint16_t *fla= gs, QCryptoTLSCreds *tlscreds, const char *hostname, @@ -433,6 +448,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, off_t *size, Error **errp) { char buf[256]; + char print_buf[256]; uint64_t magic, s; int rc; bool zeroes =3D true; @@ -461,15 +477,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char = *name, uint16_t *flags, goto fail; } =20 - TRACE("Magic is %c%c%c%c%c%c%c%c", - qemu_isprint(buf[0]) ? buf[0] : '.', - qemu_isprint(buf[1]) ? buf[1] : '.', - qemu_isprint(buf[2]) ? buf[2] : '.', - qemu_isprint(buf[3]) ? buf[3] : '.', - qemu_isprint(buf[4]) ? buf[4] : '.', - qemu_isprint(buf[5]) ? buf[5] : '.', - qemu_isprint(buf[6]) ? buf[6] : '.', - qemu_isprint(buf[7]) ? buf[7] : '.'); + TRACE("Magic is %s", nbd_magic_to_string(print_buf, buf, 9)); =20 if (memcmp(buf, "NBDMAGIC", 8) !=3D 0) { error_setg(errp, "Invalid magic received"); --=20 2.11.1 From nobody Sun May 5 15:31:29 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.zoho.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 1496155664898651.6194135224039; Tue, 30 May 2017 07:47:44 -0700 (PDT) Received: from localhost ([::1]:54248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiQx-0003Zk-1d for importer@patchew.org; Tue, 30 May 2017 10:47:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFiAs-0005Tc-GE for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFiAn-0000QY-1k for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:06 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:27977 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFiAm-0000O2-1i for qemu-devel@nongnu.org; Tue, 30 May 2017 10:31:00 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UEUqEZ027829; Tue, 30 May 2017 17:30:56 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 30 May 2017 17:30:52 +0300 Message-Id: <20170530143052.165002-20-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530143052.165002-1-vsementsov@virtuozzo.com> References: <20170530143052.165002-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 19/19] nbd: use generic trace subsystem instead of TRACE macro 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, den@openvz.org 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" Signed-off-by: Vladimir Sementsov-Ogievskiy --- Makefile.objs | 1 + nbd/client.c | 77 ++++++++++++++++++++++++--------------------------= -- nbd/nbd-internal.h | 19 ------------- nbd/server.c | 79 ++++++++++++++++++++++++++------------------------= ---- nbd/trace-events | 67 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 141 insertions(+), 102 deletions(-) create mode 100644 nbd/trace-events diff --git a/Makefile.objs b/Makefile.objs index 6167e7b17d..3288f74af1 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -164,6 +164,7 @@ trace-events-subdirs +=3D target/ppc trace-events-subdirs +=3D qom trace-events-subdirs +=3D linux-user trace-events-subdirs +=3D qapi +trace-events-subdirs +=3D nbd =20 trace-events-files =3D $(SRC_PATH)/trace-events $(trace-events-subdirs:%= =3D$(SRC_PATH)/%/trace-events) =20 diff --git a/nbd/client.c b/nbd/client.c index 52f7981c9c..91586f17b1 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -19,6 +19,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "trace.h" #include "nbd-internal.h" =20 static int nbd_errno_to_system_errno(int err) @@ -44,7 +45,7 @@ static int nbd_errno_to_system_errno(int err) ret =3D ESHUTDOWN; break; default: - TRACE("Squashing unexpected error %d to EINVAL", err); + trace_nbd_unknown_error(err); /* fallthrough */ case NBD_EINVAL: ret =3D EINVAL; @@ -103,7 +104,7 @@ static int nbd_send_option_request(QIOChannel *ioc, uin= t32_t opt, if (len =3D=3D -1) { req.length =3D len =3D strlen(data); } - TRACE("Sending option request %" PRIu32", len %" PRIu32, opt, len); + trace_nbd_send_option_request(opt, len); =20 stq_be_p(&req.magic, NBD_OPTS_MAGIC); stl_be_p(&req.option, opt); @@ -153,8 +154,7 @@ static int nbd_receive_option_reply(QIOChannel *ioc, ui= nt32_t opt, be32_to_cpus(&reply->type); be32_to_cpus(&reply->length); =20 - TRACE("Received option reply %" PRIx32", type %" PRIx32", len %" PRIu3= 2, - reply->option, reply->type, reply->length); + trace_nbd_receive_option_reply(reply->option, reply->type, reply->leng= th); =20 if (reply->magic !=3D NBD_REP_MAGIC) { error_setg(errp, "Unexpected option reply magic"); @@ -201,8 +201,7 @@ static int nbd_handle_reply_err(QIOChannel *ioc, nbd_op= t_reply *reply, =20 switch (reply->type) { case NBD_REP_ERR_UNSUP: - TRACE("server doesn't understand request %" PRIx32 - ", attempting fallback", reply->option); + trace_nbd_reply_err_unsup(reply->option); result =3D 0; goto cleanup; =20 @@ -342,12 +341,12 @@ static int nbd_receive_query_exports(QIOChannel *ioc, { bool foundExport =3D false; =20 - TRACE("Querying export list for '%s'", wantname); + trace_nbd_receive_query_exports_start(wantname); if (nbd_send_option_request(ioc, NBD_OPT_LIST, 0, NULL, errp) < 0) { return -1; } =20 - TRACE("Reading available export names"); + trace_nbd_receive_query_exports_loop(); while (1) { int ret =3D nbd_receive_list(ioc, wantname, &foundExport, errp); =20 @@ -362,7 +361,7 @@ static int nbd_receive_query_exports(QIOChannel *ioc, nbd_send_opt_abort(ioc); return -1; } - TRACE("Found desired export name '%s'", wantname); + trace_nbd_receive_query_exports_success(wantname); return 0; } } @@ -376,12 +375,12 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *i= oc, QIOChannelTLS *tioc; struct NBDTLSHandshakeData data =3D { 0 }; =20 - TRACE("Requesting TLS from server"); + trace_nbd_receive_starttls_request(); if (nbd_send_option_request(ioc, NBD_OPT_STARTTLS, 0, NULL, errp) < 0)= { return NULL; } =20 - TRACE("Getting TLS reply from server"); + trace_nbd_receive_starttls_reply(); if (nbd_receive_option_reply(ioc, NBD_OPT_STARTTLS, &reply, errp) < 0)= { return NULL; } @@ -400,14 +399,14 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *i= oc, return NULL; } =20 - TRACE("TLS request approved, setting up TLS"); + trace_nbd_receive_starttls_new_client(); tioc =3D qio_channel_tls_new_client(ioc, tlscreds, hostname, errp); if (!tioc) { return NULL; } qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-client-tls"); data.loop =3D g_main_loop_new(g_main_context_default(), FALSE); - TRACE("Starting TLS handshake"); + trace_nbd_receive_starttls_tls_handshake(); qio_channel_tls_handshake(tioc, nbd_tls_handshake, &data, @@ -453,8 +452,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, int rc; bool zeroes =3D true; =20 - TRACE("Receiving negotiation tlscreds=3D%p hostname=3D%s.", - tlscreds, hostname ? hostname : ""); + trace_nbd_receive_negotiate(tlscreds, hostname ? hostname : ""); =20 rc =3D -EINVAL; =20 @@ -477,7 +475,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } =20 - TRACE("Magic is %s", nbd_magic_to_string(print_buf, buf, 9)); + trace_nbd_receive_negotiate_magic(nbd_magic_to_string(print_buf, buf, = 9)); =20 if (memcmp(buf, "NBDMAGIC", 8) !=3D 0) { error_setg(errp, "Invalid magic received"); @@ -489,7 +487,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } magic =3D be64_to_cpu(magic); - TRACE("Magic is 0x%" PRIx64, magic); + trace_nbd_receive_negotiate_magic2(magic); =20 if (magic =3D=3D NBD_OPTS_MAGIC) { uint32_t clientflags =3D 0; @@ -501,15 +499,16 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, uint16_t *flags, goto fail; } globalflags =3D be16_to_cpu(globalflags); - TRACE("Global flags are %" PRIx32, globalflags); + trace_nbd_receive_negotiate_server_flags( + globalflags, + !!(globalflags & NBD_FLAG_FIXED_NEWSTYLE), + !!(globalflags & NBD_FLAG_NO_ZEROES)); if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) { fixedNewStyle =3D true; - TRACE("Server supports fixed new style"); clientflags |=3D NBD_FLAG_C_FIXED_NEWSTYLE; } if (globalflags & NBD_FLAG_NO_ZEROES) { zeroes =3D false; - TRACE("Server supports no zeroes"); clientflags |=3D NBD_FLAG_C_NO_ZEROES; } /* client requested flags */ @@ -531,7 +530,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, } } if (!name) { - TRACE("Using default NBD export name \"\""); + trace_nbd_receive_negotiate_default_name(); name =3D ""; } if (fixedNewStyle) { @@ -580,7 +579,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } *size =3D be64_to_cpu(s); - TRACE("Size is %" PRIu64, *size); + trace_nbd_receive_negotiate_export_size(*size); =20 if (read_sync(ioc, &oldflags, sizeof(oldflags), errp) < 0) { error_prepend(errp, "Failed to read export flags"); @@ -597,7 +596,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } =20 - TRACE("Size is %" PRIu64 ", export flags %" PRIx16, *size, *flags); + trace_nbd_receive_negotiate_size_flags(*size, *flags); if (zeroes && drop_sync(ioc, 124, errp) < 0) { error_prepend(errp, "Failed to read reserved block"); goto fail; @@ -619,7 +618,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, return -E2BIG; } =20 - TRACE("Setting NBD socket"); + trace_nbd_init_set_socket(); =20 if (ioctl(fd, NBD_SET_SOCK, (unsigned long) sioc->fd) < 0) { int serrno =3D errno; @@ -627,7 +626,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, return -serrno; } =20 - TRACE("Setting block size to %lu", (unsigned long)BDRV_SECTOR_SIZE); + trace_nbd_init_set_block_size(BDRV_SECTOR_SIZE); =20 if (ioctl(fd, NBD_SET_BLKSIZE, (unsigned long)BDRV_SECTOR_SIZE) < 0) { int serrno =3D errno; @@ -635,10 +634,9 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t = flags, off_t size, return -serrno; } =20 - TRACE("Setting size to %lu block(s)", sectors); + trace_nbd_init_set_size(sectors); if (size % BDRV_SECTOR_SIZE) { - TRACE("Ignoring trailing %d bytes of export", - (int) (size % BDRV_SECTOR_SIZE)); + trace_nbd_init_trailing_bytes(size % BDRV_SECTOR_SIZE); } =20 if (ioctl(fd, NBD_SET_SIZE_BLOCKS, sectors) < 0) { @@ -650,7 +648,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, if (ioctl(fd, NBD_SET_FLAGS, (unsigned long) flags) < 0) { if (errno =3D=3D ENOTTY) { int read_only =3D (flags & NBD_FLAG_READ_ONLY) !=3D 0; - TRACE("Setting readonly attribute"); + trace_nbd_init_set_readonly(); =20 if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) { int serrno =3D errno; @@ -664,7 +662,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, } } =20 - TRACE("Negotiation ended"); + trace_nbd_init_finish(); =20 return 0; } @@ -674,7 +672,7 @@ int nbd_client(int fd) int ret; int serrno; =20 - TRACE("Doing NBD loop"); + trace_nbd_client_loop(); =20 ret =3D ioctl(fd, NBD_DO_IT); if (ret < 0 && errno =3D=3D EPIPE) { @@ -686,12 +684,12 @@ int nbd_client(int fd) } serrno =3D errno; =20 - TRACE("NBD loop returned %d: %s", ret, strerror(serrno)); + trace_nbd_client_loop_ret(ret, strerror(serrno)); =20 - TRACE("Clearing NBD queue"); + trace_nbd_client_clear_queue(); ioctl(fd, NBD_CLEAR_QUE); =20 - TRACE("Clearing NBD socket"); + trace_nbd_client_clear_socket(); ioctl(fd, NBD_CLEAR_SOCK); =20 errno =3D serrno; @@ -728,11 +726,8 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *= request) { uint8_t buf[NBD_REQUEST_SIZE]; =20 - TRACE("Sending request to server: " - "{ .from =3D %" PRIu64", .len =3D %" PRIu32 ", .handle =3D %" PR= Iu64 - ", .flags =3D %" PRIx16 ", .type =3D %" PRIu16 " }", - request->from, request->len, request->handle, - request->flags, request->type); + trace_nbd_send_request(request->from, request->len, request->handle, + request->flags, request->type); =20 stl_be_p(buf, NBD_REQUEST_MAGIC); stw_be_p(buf + 4, request->flags); @@ -777,9 +772,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *re= ply, Error **errp) error_setg(errp, "server shutting down"); return -EINVAL; } - TRACE("Got reply: { magic =3D 0x%" PRIx32 ", .error =3D % " PRId32 - ", handle =3D %" PRIu64" }", - magic, reply->error, reply->handle); + trace_nbd_receive_reply(magic, reply->error, reply->handle); =20 if (magic !=3D NBD_REPLY_MAGIC) { error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic); diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 01d5778679..d2ce14f08d 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -31,25 +31,6 @@ #include "qemu/queue.h" #include "qemu/main-loop.h" =20 -/* #define DEBUG_NBD */ - -#ifdef DEBUG_NBD -#define DEBUG_NBD_PRINT 1 -#else -#define DEBUG_NBD_PRINT 0 -#endif - -#define TRACE(msg, ...) do { \ - if (DEBUG_NBD_PRINT) { \ - LOG(msg, ## __VA_ARGS__); \ - } \ -} while (0) - -#define LOG(msg, ...) do { \ - fprintf(stderr, "%s:%s():L%d: " msg "\n", \ - __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \ -} while (0) - /* This is all part of the "official" NBD API. * * The most up-to-date documentation is available at: diff --git a/nbd/server.c b/nbd/server.c index 6c0702287e..64bc577aea 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -19,6 +19,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "trace.h" #include "nbd-internal.h" =20 static int system_errno_to_nbd_errno(int err) @@ -139,8 +140,7 @@ static int nbd_negotiate_send_rep_len(QIOChannel *ioc, = uint32_t type, int ret; uint64_t magic; =20 - TRACE("Reply opt=3D%" PRIx32 " type=3D%" PRIx32 " len=3D%" PRIu32, - type, opt, len); + trace_nbd_negotiate_send_rep_len(type, opt, len); =20 magic =3D cpu_to_be64(NBD_REP_MAGIC); ret =3D write_sync(ioc, &magic, sizeof(magic), errp); @@ -196,7 +196,7 @@ nbd_negotiate_send_rep_err(QIOChannel *ioc, uint32_t ty= pe, va_end(va); len =3D strlen(msg); assert(len < 4096); - TRACE("sending error message \"%s\"", msg); + trace_nbd_negotiate_send_rep_err(msg); ret =3D nbd_negotiate_send_rep_len(ioc, type, opt, len, errp); if (ret < 0) { goto out; @@ -223,7 +223,7 @@ static int nbd_negotiate_send_rep_list(QIOChannel *ioc,= NBDExport *exp, const char *desc =3D exp->description ? exp->description : ""; int ret; =20 - TRACE("Advertising export name '%s' description '%s'", name, desc); + trace_nbd_negotiate_send_rep_list(name, desc); name_len =3D strlen(name); desc_len =3D strlen(desc); len =3D name_len + desc_len + sizeof(len); @@ -294,7 +294,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, uint32_t length, /* Client sends: [20 .. xx] export name (length bytes) */ - TRACE("Checking length"); + trace_nbd_negotiate_handle_export_name(); if (length >=3D sizeof(name)) { error_setg(errp, "Bad length received"); return -EINVAL; @@ -307,7 +307,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, uint32_t length, } name[length] =3D '\0'; =20 - TRACE("Client requested export '%s'", name); + trace_nbd_negotiate_handle_export_name_request(name); =20 client->exp =3D nbd_export_find(name); if (!client->exp) { @@ -331,7 +331,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, QIOChannelTLS *tioc; struct NBDTLSHandshakeData data =3D { 0 }; =20 - TRACE("Setting up TLS"); + trace_nbd_negotiate_handle_starttls(); ioc =3D client->ioc; if (length) { if (drop_sync(ioc, length, errp) < 0) { @@ -357,7 +357,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, } =20 qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-server-tls"); - TRACE("Starting TLS handshake"); + trace_nbd_negotiate_handle_starttls_handshake(); data.loop =3D g_main_loop_new(g_main_context_default(), FALSE); qio_channel_tls_handshake(tioc, nbd_tls_handshake, @@ -410,15 +410,15 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) error_prepend(errp, "read failed: "); return ret; } - TRACE("Checking client flags"); + trace_nbd_negotiate_options_flags(); be32_to_cpus(&flags); if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) { - TRACE("Client supports fixed newstyle handshake"); + trace_nbd_negotiate_options_newstyle(); fixedNewstyle =3D true; flags &=3D ~NBD_FLAG_C_FIXED_NEWSTYLE; } if (flags & NBD_FLAG_C_NO_ZEROES) { - TRACE("Client supports no zeroes at handshake end"); + trace_nbd_negotiate_options_no_zeroes(); client->no_zeroes =3D true; flags &=3D ~NBD_FLAG_C_NO_ZEROES; } @@ -437,7 +437,7 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) error_prepend(errp, "read failed: "); return ret; } - TRACE("Checking opts magic"); + trace_nbd_negotiate_options_check_magic(); if (magic !=3D be64_to_cpu(NBD_OPTS_MAGIC)) { error_setg(errp, "Bad magic received"); return -EINVAL; @@ -457,7 +457,7 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) } length =3D be32_to_cpu(length); =20 - TRACE("Checking option 0x%" PRIx32, clientflags); + trace_nbd_negotiate_options_check_option(clientflags); if (client->tlscreds && client->ioc =3D=3D (QIOChannel *)client->sioc) { QIOChannel *tioc; @@ -617,14 +617,14 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) =20 qio_channel_set_blocking(client->ioc, false, NULL); =20 - TRACE("Beginning negotiation."); + trace_nbd_negotiate_begin(); memset(buf, 0, sizeof(buf)); memcpy(buf, "NBDMAGIC", 8); =20 oldStyle =3D client->exp !=3D NULL && !client->tlscreds; if (oldStyle) { - TRACE("advertising size %" PRIu64 " and flags %x", - client->exp->size, client->exp->nbdflags | myflags); + trace_nbd_negotiate_old_style(client->exp->size, + client->exp->nbdflags | myflags); stq_be_p(buf + 8, NBD_CLIENT_MAGIC); stq_be_p(buf + 16, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); @@ -658,8 +658,8 @@ static coroutine_fn int nbd_negotiate(NBDClient *client= , Error **errp) return ret; } =20 - TRACE("advertising size %" PRIu64 " and flags %x", - client->exp->size, client->exp->nbdflags | myflags); + trace_nbd_negotiate_new_style_size_flags( + client->exp->size, client->exp->nbdflags | myflags); stq_be_p(buf + 18, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); len =3D client->no_zeroes ? 10 : sizeof(buf) - 18; @@ -670,7 +670,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *client= , Error **errp) } } =20 - TRACE("Negotiation succeeded."); + trace_nbd_negotiate_success(); =20 return 0; } @@ -703,9 +703,8 @@ static int nbd_receive_request(QIOChannel *ioc, NBDRequ= est *request, request->from =3D ldq_be_p(buf + 16); request->len =3D ldl_be_p(buf + 24); =20 - TRACE("Got request: { magic =3D 0x%" PRIx32 ", .flags =3D %" PRIx16 - ", .type =3D %" PRIx16 ", from =3D %" PRIu64 ", len =3D %" PRIu3= 2 " }", - magic, request->flags, request->type, request->from, request->le= n); + trace_nbd_receive_request(magic, request->flags, request->type, + request->from, request->len); =20 if (magic !=3D NBD_REQUEST_MAGIC) { error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic); @@ -720,9 +719,7 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *re= ply, Error **errp) =20 reply->error =3D system_errno_to_nbd_errno(reply->error); =20 - TRACE("Sending response to client: { .error =3D %" PRId32 - ", handle =3D %" PRIu64 " }", - reply->error, reply->handle); + trace_nbd_send_reply(reply->error, reply->handle); =20 /* Reply [ 0 .. 3] magic (NBD_REPLY_MAGIC) @@ -819,7 +816,7 @@ static void blk_aio_attached(AioContext *ctx, void *opa= que) NBDExport *exp =3D opaque; NBDClient *client; =20 - TRACE("Export %s: Attaching clients to AIO context %p\n", exp->name, c= tx); + trace_blk_aio_attached(exp->name, ctx); =20 exp->ctx =3D ctx; =20 @@ -839,7 +836,7 @@ static void blk_aio_detach(void *opaque) NBDExport *exp =3D opaque; NBDClient *client; =20 - TRACE("Export %s: Detaching clients from AIO context %p\n", exp->name,= exp->ctx); + trace_blk_aio_detach(exp->name, exp->ctx); =20 QTAILQ_FOREACH(client, &exp->clients, next) { qio_channel_detach_aio_context(client->ioc); @@ -1066,7 +1063,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, return -EIO; } =20 - TRACE("Decoding type"); + trace_nbd_co_receive_request_decode_type(); =20 if (request->type !=3D NBD_CMD_WRITE) { /* No payload, we are ready to read the next request. */ @@ -1076,7 +1073,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, if (request->type =3D=3D NBD_CMD_DISC) { /* Special case: we're going to disconnect without a reply, * whether or not flags, from, or len are bogus */ - TRACE("Request type is DISCONNECT"); + trace_nbd_co_receive_request_disconnect(); return -EIO; } =20 @@ -1103,7 +1100,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, } } if (request->type =3D=3D NBD_CMD_WRITE) { - TRACE("Reading %" PRIu32 " byte(s)", request->len); + trace_nbd_co_receive_request_cmd_write(request->len); =20 if (read_sync(client->ioc, req->data, request->len, errp) < 0) { error_prepend(errp, "reading from socket failed: "); @@ -1145,7 +1142,7 @@ static coroutine_fn void nbd_trip(void *opaque) int reply_data_len =3D 0; Error *local_err =3D NULL; =20 - TRACE("Reading request."); + trace_do_nbd_trip(); if (client->closing) { nbd_client_put(client); return; @@ -1177,7 +1174,7 @@ static coroutine_fn void nbd_trip(void *opaque) =20 switch (request.type) { case NBD_CMD_READ: - TRACE("Request type is READ"); + trace_do_nbd_trip_cmd_read(); =20 /* XXX: NBD Protocol only documents use of FUA with WRITE */ if (request.flags & NBD_CMD_FLAG_FUA) { @@ -1198,19 +1195,19 @@ static coroutine_fn void nbd_trip(void *opaque) } =20 reply_data_len =3D request.len; - TRACE("Read %" PRIu32" byte(s)", request.len); + trace_do_nbd_trip_read(request.len); =20 break; case NBD_CMD_WRITE: - TRACE("Request type is WRITE"); + trace_do_nbd_trip_cmd_write(); =20 if (exp->nbdflags & NBD_FLAG_READ_ONLY) { - TRACE("Server is read-only, return error"); + trace_do_nbd_trip_cmd_write_readonly(); reply.error =3D EROFS; break; } =20 - TRACE("Writing to device"); + trace_do_nbd_trip_write(); =20 flags =3D 0; if (request.flags & NBD_CMD_FLAG_FUA) { @@ -1225,7 +1222,7 @@ static coroutine_fn void nbd_trip(void *opaque) =20 break; case NBD_CMD_WRITE_ZEROES: - TRACE("Request type is WRITE_ZEROES"); + trace_do_nbd_trip_cmd_write_zeroes(); =20 if (exp->nbdflags & NBD_FLAG_READ_ONLY) { error_setg(&local_err, "Server is read-only, return error"); @@ -1233,7 +1230,7 @@ static coroutine_fn void nbd_trip(void *opaque) break; } =20 - TRACE("Writing to device"); + trace_do_nbd_trip_write_zeroes(); =20 flags =3D 0; if (request.flags & NBD_CMD_FLAG_FUA) { @@ -1255,7 +1252,7 @@ static coroutine_fn void nbd_trip(void *opaque) abort(); =20 case NBD_CMD_FLUSH: - TRACE("Request type is FLUSH"); + trace_do_nbd_trip_cmd_flush(); =20 ret =3D blk_co_flush(exp->blk); if (ret < 0) { @@ -1265,7 +1262,7 @@ static coroutine_fn void nbd_trip(void *opaque) =20 break; case NBD_CMD_TRIM: - TRACE("Request type is TRIM"); + trace_do_nbd_trip_cmd_trim(); ret =3D blk_co_pdiscard(exp->blk, request.from + exp->dev_offset, request.len); if (ret < 0) { @@ -1299,7 +1296,7 @@ reply: goto disconnect; } =20 - TRACE("Request/Reply complete"); + trace_do_nbd_trip_complete(); =20 done: nbd_request_put(req); diff --git a/nbd/trace-events b/nbd/trace-events new file mode 100644 index 0000000000..82e45a1a27 --- /dev/null +++ b/nbd/trace-events @@ -0,0 +1,67 @@ +# nbd/client.c +nbd_unknown_error(int err) "Squashing unexpected error %d to EINVAL" +nbd_send_option_request(uint32_t opt, uint32_t len) "Sending option reques= t %" PRIu32", len %" PRIu32 +nbd_receive_option_reply(uint32_t option, uint32_t type, uint32_t length) = "Received option reply %" PRIx32", type %" PRIx32", len %" PRIu32 +nbd_reply_err_unsup(uint32_t option) "server doesn't understand request %"= PRIx32 ", attempting fallback" +nbd_receive_query_exports_start(const char *wantname) "Querying export lis= t for '%s'" +nbd_receive_query_exports_loop(void) "Reading available export names" +nbd_receive_query_exports_success(const char *wantname) "Found desired exp= ort name '%s'" +nbd_receive_starttls_request(void) "Requesting TLS from server" +nbd_receive_starttls_reply(void) "Getting TLS reply from server" +nbd_receive_starttls_new_client(void) "TLS request approved, setting up TL= S" +nbd_receive_starttls_tls_handshake(void) "Starting TLS handshake" +nbd_receive_negotiate(void *tlscreds, const char *hostname) "Receiving neg= otiation tlscreds=3D%p hostname=3D%s." +nbd_receive_negotiate_magic(const char *magic) "Magic is %s" +nbd_receive_negotiate_magic2(uint64_t magic) "Magic is 0x%" PRIx64 +nbd_receive_negotiate_server_flags(uint32_t globalflags, int fixed_newstyl= e, int no_zeroes) "Global flags are %d" PRIx32 " fixed_newstyle %d no_zeroe= s %d" +nbd_receive_negotiate_default_name(void) "Using default NBD export name \"= \"" +nbd_receive_negotiate_export_size(uint64_t size) "Size is %" PRIu64 +nbd_receive_negotiate_size_flags(uint64_t size, uint16_t flags) "Size is %= " PRIu64 ", export flags %" PRIx16 +nbd_init_set_socket(void) "Setting NBD socket" +nbd_init_set_block_size(unsigned long block_size) "Setting block size to %= lu" +nbd_init_set_size(unsigned long sectors) "Setting size to %lu block(s)" +nbd_init_trailing_bytes(int ignored_bytes) "Ignoring trailing %d bytes of = export" +nbd_init_set_readonly(void) "Setting readonly attribute" +nbd_init_finish(void) "Negotiation ended" +nbd_client_loop(void) "Doing NBD loop" +nbd_client_loop_ret(int ret, const char *error) "NBD loop returned %d: %s" +nbd_client_clear_queue(void) "Clearing NBD queue" +nbd_client_clear_socket(void) "Clearing NBD socket" +nbd_send_request(uint64_t from, uint32_t len, uint64_t handle, uint16_t fl= ags, uint16_t type) "Sending request to server: { .from =3D %" PRIu64", .le= n =3D %" PRIu32 ", .handle =3D %" PRIu64 ", .flags =3D %" PRIx16 ", .type = =3D %" PRIu16 " }" +nbd_receive_reply(uint32_t magic, int32_t error, uint64_t handle) "Got rep= ly: { magic =3D 0x%" PRIx32 ", .error =3D % " PRId32 ", handle =3D %" PRIu6= 4" }" + +# nbd/server.c +nbd_negotiate_send_rep_len(uint32_t type, uint32_t opt, uint32_t len) "Rep= ly opt=3D%" PRIx32 " type=3D%" PRIx32 " len=3D%" PRIu32 +nbd_negotiate_send_rep_err(const char *msg) "sending error message \"%s\"" +nbd_negotiate_send_rep_list(const char *name, const char *desc) "Advertisi= ng export name '%s' description '%s'" +nbd_negotiate_handle_export_name(void) "Checking length" +nbd_negotiate_handle_export_name_request(const char *name) "Client request= ed export '%s'" +nbd_negotiate_handle_starttls(void) "Setting up TLS" +nbd_negotiate_handle_starttls_handshake(void) "Starting TLS handshake" +nbd_negotiate_options_flags(void) "Checking client flags" +nbd_negotiate_options_newstyle(void) "Client supports fixed newstyle hands= hake" +nbd_negotiate_options_no_zeroes(void) "Client supports no zeroes at handsh= ake end" +nbd_negotiate_options_check_magic(void) "Checking opts magic" +nbd_negotiate_options_check_option(uint32_t clientflags) "Checking option = 0x%" PRIx32 +nbd_negotiate_begin(void) "Beginning negotiation." +nbd_negotiate_old_style(uint64_t size, unsigned flags) "advertising size %= " PRIu64 " and flags %x" +nbd_negotiate_new_style_size_flags(uint64_t size, unsigned flags) "adverti= sing size %" PRIu64 " and flags %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 %= " PRIx16 ", .type =3D %" PRIx16 ", from =3D %" PRIu64 ", len =3D %" PRIu32 = " }" +nbd_send_reply(int32_t error, uint64_t handle) "Sending response to client= : { .error =3D %" PRId32 ", handle =3D %" PRIu64 " }" +blk_aio_attached(const char *name, void *ctx) "Export %s: Attaching client= s to AIO context %p\n" +blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clients = from AIO context %p\n" +nbd_co_receive_request_decode_type(void) "Decoding type" +nbd_co_receive_request_disconnect(void) "Request type is DISCONNECT" +nbd_co_receive_request_cmd_write(uint32_t len) "Reading %" PRIu32 " byte(s= )" +do_nbd_trip(void) "Reading request." +do_nbd_trip_cmd_read(void) "Request type is READ" +do_nbd_trip_read(uint32_t len) "Read %" PRIu32" byte(s)" +do_nbd_trip_cmd_write(void) "Request type is WRITE" +do_nbd_trip_cmd_write_readonly(void) "Server is read-only, return error" +do_nbd_trip_write(void) "Writing to device" +do_nbd_trip_cmd_write_zeroes(void) "Request type is WRITE_ZEROES" +do_nbd_trip_write_zeroes(void) "Writing to device" +do_nbd_trip_cmd_flush(void) "Request type is FLUSH" +do_nbd_trip_cmd_trim(void) "Request type is TRIM" +do_nbd_trip_complete(void) "Request/Reply complete" --=20 2.11.1