From nobody Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441648036716.5223919432344; Fri, 7 Jul 2017 08:34:08 -0700 (PDT) Received: from localhost ([::1]:57145 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVGe-0004Fc-SD for importer@patchew.org; Fri, 07 Jul 2017 11:34:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCH-0000sB-8h for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCE-0001C5-1b for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:33 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:23511 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 1dTVCD-0001AQ-MQ for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:29 -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 v67FTIuP028047; Fri, 7 Jul 2017 18:29:19 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:09 +0300 Message-Id: <20170707152918.23086-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 01/10] 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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 the case when a client sends NBD_OPT_ABORT from all other errors. It will be needed for the following patch, where errors will be reported. This particular case is not actually an error - it honestly follows the NBD protocol. Therefore it should not be reported like an error. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 8a70c054a6..3963972337 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -349,9 +349,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: + * -errno on error + * 0 on successful negotiation + * 1 if client sent NBD_OPT_ABORT, i.e. on valid disconnect + */ static int nbd_negotiate_options(NBDClient *client) { uint32_t flags; @@ -459,7 +463,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; } @@ -477,7 +481,7 @@ static int nbd_negotiate_options(NBDClient *client) * 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; + return 1; =20 case NBD_OPT_EXPORT_NAME: return nbd_negotiate_handle_export_name(client, length); @@ -533,6 +537,12 @@ static int nbd_negotiate_options(NBDClient *client) } } =20 +/* nbd_negotiate + * Return: + * -errno on error + * 0 on successful negotiation + * 1 if client sent NBD_OPT_ABORT, i.e. on valid disconnect + */ static coroutine_fn int nbd_negotiate(NBDClient *client) { char buf[8 + 8 + 8 + 128]; --=20 2.11.1 From nobody Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441483461733.3647293912571; Fri, 7 Jul 2017 08:31:23 -0700 (PDT) Received: from localhost ([::1]:57137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVE2-00026G-0l for importer@patchew.org; Fri, 07 Jul 2017 11:31:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCH-0000sD-9E for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCF-0001DN-1w for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:33 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:23312 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 1dTVCE-0001BZ-M5 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:30 -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 v67FTIuQ028047; Fri, 7 Jul 2017 18:29:19 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:10 +0300 Message-Id: <20170707152918.23086-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 02/10] nbd/server: refactor nbd_negotiate 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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" Combine two successive "if (oldStyle) {...} else {...}" into one. Block "if (client->tlscreds)" under "if (oldStyle)" is unreachable, as we have "oldStyle =3D client->exp !=3D NULL && !client->tlscreds;". So, delete this block. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 3963972337..a6a57ce7c1 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -584,21 +584,15 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt) 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); - } else { - stq_be_p(buf + 8, NBD_OPTS_MAGIC); - stw_be_p(buf + 16, NBD_FLAG_FIXED_NEWSTYLE | NBD_FLAG_NO_ZEROES); - } =20 - if (oldStyle) { - if (client->tlscreds) { - TRACE("TLS cannot be enabled with oldstyle protocol"); - return -EINVAL; - } if (nbd_write(client->ioc, buf, sizeof(buf), NULL) < 0) { LOG("write failed"); return -EINVAL; } } else { + stq_be_p(buf + 8, NBD_OPTS_MAGIC); + stw_be_p(buf + 16, NBD_FLAG_FIXED_NEWSTYLE | NBD_FLAG_NO_ZEROES); + if (nbd_write(client->ioc, buf, 18, NULL) < 0) { LOG("write failed"); return -EINVAL; --=20 2.11.1 From nobody Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441781813536.9644964203785; Fri, 7 Jul 2017 08:36:21 -0700 (PDT) Received: from localhost ([::1]:57160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVIp-00063q-Dc for importer@patchew.org; Fri, 07 Jul 2017 11:36:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCM-0000sd-9e for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCG-0001EO-Ma for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:36 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:27852 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 1dTVCG-0001DH-0q for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:32 -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 v67FTIuR028047; Fri, 7 Jul 2017 18:29:19 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:11 +0300 Message-Id: <20170707152918.23086-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 03/10] 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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 Reviewed-by: Eric Blake --- nbd/server.c | 266 +++++++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 160 insertions(+), 106 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index a6a57ce7c1..00a7c606ae 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) { uint64_t magic; =20 @@ -142,23 +142,26 @@ 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_write(ioc, &magic, sizeof(magic), NULL) < 0) { - LOG("write failed (rep magic)"); + if (nbd_write(ioc, &magic, sizeof(magic), errp) < 0) { + error_prepend(errp, "write failed (rep magic): "); return -EINVAL; } + opt =3D cpu_to_be32(opt); - if (nbd_write(ioc, &opt, sizeof(opt), NULL) < 0) { - LOG("write failed (rep opt)"); + if (nbd_write(ioc, &opt, sizeof(opt), errp) < 0) { + error_prepend(errp, "write failed (rep opt): "); return -EINVAL; } + type =3D cpu_to_be32(type); - if (nbd_write(ioc, &type, sizeof(type), NULL) < 0) { - LOG("write failed (rep type)"); + if (nbd_write(ioc, &type, sizeof(type), errp) < 0) { + error_prepend(errp, "write failed (rep type): "); return -EINVAL; } + len =3D cpu_to_be32(len); - if (nbd_write(ioc, &len, sizeof(len), NULL) < 0) { - LOG("write failed (rep data length)"); + if (nbd_write(ioc, &len, sizeof(len), errp) < 0) { + error_prepend(errp, "write failed (rep data length): "); return -EINVAL; } return 0; @@ -166,16 +169,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; @@ -188,16 +192,17 @@ 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; } - if (nbd_write(ioc, msg, len, NULL) < 0) { - LOG("write failed (error message)"); + if (nbd_write(ioc, msg, len, errp) < 0) { + error_prepend(errp, "write failed (error message): "); ret =3D -EIO; } else { ret =3D 0; } + out: g_free(msg); return ret; @@ -205,7 +210,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; @@ -217,53 +223,60 @@ 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); - if (nbd_write(ioc, &len, sizeof(len), NULL) < 0) { - LOG("write failed (name length)"); + if (nbd_write(ioc, &len, sizeof(len), errp) < 0) { + error_prepend(errp, "write failed (name length): "); return -EINVAL; } - if (nbd_write(ioc, name, name_len, NULL) < 0) { - LOG("write failed (name buffer)"); + + if (nbd_write(ioc, name, name_len, errp) < 0) { + error_prepend(errp, "write failed (name buffer): "); return -EINVAL; } - if (nbd_write(ioc, desc, desc_len, NULL) < 0) { - LOG("write failed (description buffer)"); + + if (nbd_write(ioc, desc, desc_len, errp) < 0) { + error_prepend(errp, "write failed (description buffer): "); return -EINVAL; } + return 0; } =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) { NBDExport *exp; =20 if (length) { - if (nbd_drop(client->ioc, length, NULL) < 0) { + if (nbd_drop(client->ioc, length, errp) < 0) { return -EIO; } 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) { - if (nbd_negotiate_send_rep_list(client->ioc, exp)) { + if (nbd_negotiate_send_rep_list(client->ioc, exp, errp)) { return -EINVAL; } } /* 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) { char name[NBD_MAX_NAME_SIZE + 1]; =20 @@ -272,11 +285,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"); + error_setg(errp, "Bad length received"); return -EINVAL; } - if (nbd_read(client->ioc, name, length, NULL) < 0) { - LOG("read failed"); + if (nbd_read(client->ioc, name, length, errp) < 0) { + error_prepend(errp, "read failed: "); return -EINVAL; } name[length] =3D '\0'; @@ -285,7 +298,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 @@ -298,7 +311,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; @@ -307,23 +321,24 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDC= lient *client, TRACE("Setting up TLS"); ioc =3D client->ioc; if (length) { - if (nbd_drop(ioc, length, NULL) < 0) { + if (nbd_drop(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; } @@ -342,7 +357,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 @@ -352,14 +367,16 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDC= lient *client, /* nbd_negotiate_options * Process all NBD_OPT_* client option commands. * Return: - * -errno on error - * 0 on successful negotiation - * 1 if client sent NBD_OPT_ABORT, i.e. on valid disconnect + * -errno on error, errp is set + * 0 on successful negotiation, errp is not set + * 1 if client sent NBD_OPT_ABORT, i.e. on valid disconnect, + * errp is not set */ -static int nbd_negotiate_options(NBDClient *client) +static int nbd_negotiate_options(NBDClient *client, Error **errp) { uint32_t flags; bool fixedNewstyle =3D false; + Error *local_err =3D NULL; =20 /* Client sends: [ 0 .. 3] client flags @@ -375,8 +392,8 @@ static int nbd_negotiate_options(NBDClient *client) ... Rest of request */ =20 - if (nbd_read(client->ioc, &flags, sizeof(flags), NULL) < 0) { - LOG("read failed"); + if (nbd_read(client->ioc, &flags, sizeof(flags), errp) < 0) { + error_prepend(errp, "read failed: "); return -EIO; } TRACE("Checking client flags"); @@ -392,7 +409,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 @@ -401,26 +418,25 @@ static int nbd_negotiate_options(NBDClient *client) uint32_t clientflags, length; uint64_t magic; =20 - if (nbd_read(client->ioc, &magic, sizeof(magic), NULL) < 0) { - LOG("read failed"); + if (nbd_read(client->ioc, &magic, sizeof(magic), errp) < 0) { + error_prepend(errp, "read failed: "); return -EINVAL; } 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 if (nbd_read(client->ioc, &clientflags, - sizeof(clientflags), NULL) < 0) - { - LOG("read failed"); + sizeof(clientflags), errp) < 0) { + error_prepend(errp, "read failed: "); return -EINVAL; } clientflags =3D be32_to_cpu(clientflags); =20 - if (nbd_read(client->ioc, &length, sizeof(length), NULL) < 0) { - LOG("read failed"); + if (nbd_read(client->ioc, &length, sizeof(length), errp) < 0) { + error_prepend(errp, "read failed: "); return -EINVAL; } length =3D be32_to_cpu(length); @@ -430,12 +446,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; } @@ -445,16 +461,17 @@ 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: - if (nbd_drop(client->ioc, length, NULL) < 0) { + if (nbd_drop(client->ioc, length, errp) < 0) { return -EIO; } 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); @@ -470,7 +487,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; } @@ -480,25 +497,33 @@ 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); + nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, clientfla= gs, + &local_err); + + if (local_err !=3D NULL) { + TRACE("Reply to NBD_OPT_ABORT request failed: %s", + error_get_pretty(local_err)); + 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: - if (nbd_drop(client->ioc, length, NULL) < 0) { + if (nbd_drop(client->ioc, length, errp) < 0) { return -EIO; } 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) { @@ -506,12 +531,12 @@ static int nbd_negotiate_options(NBDClient *client) } break; default: - if (nbd_drop(client->ioc, length, NULL) < 0) { + if (nbd_drop(client->ioc, length, errp) < 0) { return -EIO; } ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_UNSUP, - clientflags, + clientflags, errp, "Unsupported option 0x%" PRIx32, clientflags); @@ -527,10 +552,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; } } @@ -539,11 +564,12 @@ static int nbd_negotiate_options(NBDClient *client) =20 /* nbd_negotiate * Return: - * -errno on error - * 0 on successful negotiation - * 1 if client sent NBD_OPT_ABORT, i.e. on valid disconnect + * -errno on error, errp is set + * 0 on successful negotiation, errp is not set + * 1 if client sent NBD_OPT_ABORT, i.e. on valid 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; @@ -585,21 +611,23 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt) stq_be_p(buf + 16, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); =20 - if (nbd_write(client->ioc, buf, sizeof(buf), NULL) < 0) { - LOG("write failed"); + if (nbd_write(client->ioc, buf, sizeof(buf), errp) < 0) { + error_prepend(errp, "write failed: "); return -EINVAL; } } else { stq_be_p(buf + 8, NBD_OPTS_MAGIC); stw_be_p(buf + 16, NBD_FLAG_FIXED_NEWSTYLE | NBD_FLAG_NO_ZEROES); =20 - if (nbd_write(client->ioc, buf, 18, NULL) < 0) { - LOG("write failed"); + if (nbd_write(client->ioc, buf, 18, errp) < 0) { + error_prepend(errp, "write failed: "); return -EINVAL; } - 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 @@ -608,9 +636,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 nbd_write(client->ioc, buf + 18, len, NULL); + ret =3D nbd_write(client->ioc, buf + 18, len, errp); if (ret < 0) { - LOG("write failed"); + error_prepend(errp, "write failed: "); return ret; } } @@ -620,13 +648,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 nbd_read(ioc, buf, sizeof(buf), NULL); + ret =3D nbd_read(ioc, buf, sizeof(buf), errp); if (ret < 0) { return ret; } @@ -652,7 +681,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; @@ -998,13 +1027,14 @@ static int nbd_co_send_reply(NBDRequestData *req, NB= DReply *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 @@ -1026,27 +1056,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 (nbd_read(client->ioc, req->data, request->len, NULL) < 0) { - LOG("reading from socket failed"); + if (nbd_read(client->ioc, req->data, request->len, errp) < 0) { + error_prepend(errp, "reading from socket failed: "); return -EIO; } req->complete =3D true; @@ -1054,18 +1086,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 @@ -1083,6 +1115,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) { @@ -1091,7 +1124,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) { @@ -1122,7 +1155,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; } @@ -1131,7 +1164,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; } @@ -1158,7 +1191,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 @@ -1167,7 +1200,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; } @@ -1184,7 +1217,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 @@ -1198,7 +1231,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 @@ -1208,21 +1241,35 @@ 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) { + /* If we are here local_err is not fatal error, already stored in + * reply.error */ + 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 @@ -1234,6 +1281,9 @@ done: return; =20 disconnect: + if (local_err) { + error_reportf_err(local_err, "Disconnect client, due to: "); + } nbd_request_put(req); client_close(client, true); nbd_client_put(client); @@ -1252,6 +1302,7 @@ static coroutine_fn void nbd_co_client_start(void *op= aque) { NBDClient *client =3D opaque; NBDExport *exp =3D client->exp; + Error *local_err =3D NULL; =20 if (exp) { nbd_export_get(exp); @@ -1259,7 +1310,10 @@ static coroutine_fn void nbd_co_client_start(void *o= paque) } qemu_co_mutex_init(&client->send_lock); =20 - if (nbd_negotiate(client)) { + if (nbd_negotiate(client, &local_err)) { + if (local_err) { + error_report_err(local_err); + } client_close(client, false); return; } --=20 2.11.1 From nobody Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441647016625.578663455842; Fri, 7 Jul 2017 08:34:07 -0700 (PDT) Received: from localhost ([::1]:57144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVGd-0004F0-Kt for importer@patchew.org; Fri, 07 Jul 2017 11:34:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCH-0000sE-9U for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCE-0001Co-Is for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:33 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:32994 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 1dTVCE-0001B9-5H for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:30 -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 v67FTIuS028047; Fri, 7 Jul 2017 18:29:19 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:12 +0300 Message-Id: <20170707152918.23086-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 04/10] 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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 Reviewed-by: Eric Blake --- nbd/server.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 00a7c606ae..e3fd0ca8fe 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -687,7 +687,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 @@ -706,7 +706,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 nbd_write(ioc, buf, sizeof(buf), NULL); + return nbd_write(ioc, buf, sizeof(buf), errp); } =20 #define MAX_NBD_REQUESTS 16 @@ -993,7 +993,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; @@ -1003,12 +1004,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 nbd_write(client->ioc, req->data, len, NULL); + ret =3D nbd_write(client->ioc, req->data, len, errp); if (ret < 0) { ret =3D -EIO; } @@ -1260,8 +1261,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 Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441970014573.8062851533571; Fri, 7 Jul 2017 08:39:30 -0700 (PDT) Received: from localhost ([::1]:57170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVLs-00084B-PM for importer@patchew.org; Fri, 07 Jul 2017 11:39:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40337) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCH-0000sC-92 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCE-0001CQ-9o for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:33 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:18026 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 1dTVCD-0001Az-VH for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:30 -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 v67FTIuT028047; Fri, 7 Jul 2017 18:29:19 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:13 +0300 Message-Id: <20170707152918.23086-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 05/10] nbd/common: nbd_tls_handshake: remove extra 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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" Error is propagated to the caller, TRACE is not needed. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nbd/common.c b/nbd/common.c index 6b5c1b7b02..4dab41e2c0 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -97,9 +97,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)); - } + qio_task_propagate_error(task, &data->error); data->complete =3D true; g_main_loop_quit(data->loop); } --=20 2.11.1 From nobody Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441887750917.4247766756764; Fri, 7 Jul 2017 08:38:07 -0700 (PDT) Received: from localhost ([::1]:57167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVKY-0007D9-EC for importer@patchew.org; Fri, 07 Jul 2017 11:38:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCH-0000s9-8M for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCE-0001CB-28 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:33 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:36842 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 1dTVCD-00019z-MM for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:29 -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 v67FTIuU028047; Fri, 7 Jul 2017 18:29:20 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:14 +0300 Message-Id: <20170707152918.23086-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 06/10] 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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" We are going to switch from TRACE macro to trace points, this TRACE complicates things, this patch simplifies it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/client.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index b97143fa60..2125321ebd 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -461,15 +461,8 @@ 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] : '.'); + magic =3D ldq_be_p(buf); + TRACE("Magic is 0x%" PRIx64, magic); =20 if (memcmp(buf, "NBDMAGIC", 8) !=3D 0) { error_setg(errp, "Invalid magic received"); --=20 2.11.1 From nobody Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441483843433.3548707239788; Fri, 7 Jul 2017 08:31:23 -0700 (PDT) Received: from localhost ([::1]:57136 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVE1-00025z-6a for importer@patchew.org; Fri, 07 Jul 2017 11:31:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCH-0000sF-AA for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCE-0001CU-Ab for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:33 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:25072 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 1dTVCD-0001Au-Va for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:30 -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 v67FTIuV028047; Fri, 7 Jul 2017 18:29:20 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:15 +0300 Message-Id: <20170707152918.23086-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 07/10] nbd/server: fix TRACE in nbd_negotiate_send_rep_len 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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" Fix wrong order of TRACE arguments. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbd/server.c b/nbd/server.c index e3fd0ca8fe..1eeafccaca 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -139,7 +139,7 @@ static int nbd_negotiate_send_rep_len(QIOChannel *ioc, = uint32_t type, uint64_t magic; =20 TRACE("Reply opt=3D%" PRIx32 " type=3D%" PRIx32 " len=3D%" PRIu32, - type, opt, len); + opt, type, len); =20 magic =3D cpu_to_be64(NBD_REP_MAGIC); if (nbd_write(ioc, &magic, sizeof(magic), errp) < 0) { --=20 2.11.1 From nobody Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441484665230.40140374422776; Fri, 7 Jul 2017 08:31:24 -0700 (PDT) Received: from localhost ([::1]:57138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVE2-00026f-9n for importer@patchew.org; Fri, 07 Jul 2017 11:31:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCJ-0000sZ-DE for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCH-0001FY-Py for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:35 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:2980 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 1dTVCH-0001Cl-8h for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:33 -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 v67FTIuW028047; Fri, 7 Jul 2017 18:29:20 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:16 +0300 Message-Id: <20170707152918.23086-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 08/10] nbd/server: rename clientflags var in nbd_negotiate_options 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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" Rename 'clientflags' to just 'option'. This variable has nothing to do with flags, but is a single integer representing the option requested by the client. 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 1eeafccaca..c4d64fb3ad 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -415,7 +415,7 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) =20 while (1) { int ret; - uint32_t clientflags, length; + uint32_t option, length; uint64_t magic; =20 if (nbd_read(client->ioc, &magic, sizeof(magic), errp) < 0) { @@ -428,12 +428,12 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) return -EINVAL; } =20 - if (nbd_read(client->ioc, &clientflags, - sizeof(clientflags), errp) < 0) { + if (nbd_read(client->ioc, &option, + sizeof(option), errp) < 0) { error_prepend(errp, "read failed: "); return -EINVAL; } - clientflags =3D be32_to_cpu(clientflags); + option =3D be32_to_cpu(option); =20 if (nbd_read(client->ioc, &length, sizeof(length), errp) < 0) { error_prepend(errp, "read failed: "); @@ -441,15 +441,15 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) } length =3D be32_to_cpu(length); =20 - TRACE("Checking option 0x%" PRIx32, clientflags); + TRACE("Checking option 0x%" PRIx32, option); if (client->tlscreds && client->ioc =3D=3D (QIOChannel *)client->sioc) { QIOChannel *tioc; if (!fixedNewstyle) { - error_setg(errp, "Unsupported option 0x%" PRIx32, clientfl= ags); + error_setg(errp, "Unsupported option 0x%" PRIx32, option); return -EINVAL; } - switch (clientflags) { + switch (option) { case NBD_OPT_STARTTLS: tioc =3D nbd_negotiate_handle_starttls(client, length, err= p); if (!tioc) { @@ -462,7 +462,7 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) case NBD_OPT_EXPORT_NAME: /* No way to return an error to client, so drop connection= */ error_setg(errp, "Option 0x%x not permitted before TLS", - clientflags); + option); return -EINVAL; =20 default: @@ -471,21 +471,21 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) } ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_TLS_REQD, - clientflags, errp, + option, errp, "Option 0x%" PRIx32 "not permitted before TLS= ", - clientflags); + option); if (ret < 0) { return ret; } /* Let the client keep trying, unless they asked to quit */ - if (clientflags =3D=3D NBD_OPT_ABORT) { + if (option =3D=3D NBD_OPT_ABORT) { return 1; } break; } } else if (fixedNewstyle) { - switch (clientflags) { + switch (option) { case NBD_OPT_LIST: ret =3D nbd_negotiate_handle_list(client, length, errp); if (ret < 0) { @@ -497,7 +497,7 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) /* 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, + nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, option, &local_err); =20 if (local_err !=3D NULL) { @@ -518,12 +518,12 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) if (client->tlscreds) { ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_INVALID, - clientflags, errp, + option, errp, "TLS already enabled"= ); } else { ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_POLICY, - clientflags, errp, + option, errp, "TLS not configured"); } if (ret < 0) { @@ -536,10 +536,10 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) } ret =3D nbd_negotiate_send_rep_err(client->ioc, NBD_REP_ERR_UNSUP, - clientflags, errp, + option, errp, "Unsupported option 0x%" PRIx32, - clientflags); + option); if (ret < 0) { return ret; } @@ -550,12 +550,12 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) * If broken new-style we should drop the connection * for anything except NBD_OPT_EXPORT_NAME */ - switch (clientflags) { + switch (option) { case NBD_OPT_EXPORT_NAME: return nbd_negotiate_handle_export_name(client, length, er= rp); =20 default: - error_setg(errp, "Unsupported option 0x%" PRIx32, clientfl= ags); + error_setg(errp, "Unsupported option 0x%" PRIx32, option); return -EINVAL; } } --=20 2.11.1 From nobody Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441483829915.7663714444755; Fri, 7 Jul 2017 08:31:23 -0700 (PDT) Received: from localhost ([::1]:57139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVE2-00026k-GP for importer@patchew.org; Fri, 07 Jul 2017 11:31:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCH-0000sH-Pk for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCG-0001E3-7t for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:33 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:44715 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 1dTVCF-0001Ck-Ml for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:32 -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 v67FTIuX028047; Fri, 7 Jul 2017 18:29:20 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:17 +0300 Message-Id: <20170707152918.23086-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 09/10] nbd: refactor tracing 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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" Reorganize traces: move, reword, add information, drop extra ones. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/client.c | 3 --- nbd/server.c | 30 +++++++++--------------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 2125321ebd..1ae4ff8a8e 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -489,12 +489,10 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, uint16_t *flags, TRACE("Global flags are %" PRIx32, globalflags); 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 */ @@ -565,7 +563,6 @@ 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); =20 if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) { error_prepend(errp, "Failed to read export flags"); diff --git a/nbd/server.c b/nbd/server.c index c4d64fb3ad..4bbce5fe76 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1000,6 +1000,10 @@ static int nbd_co_send_reply(NBDRequestData *req, NB= DReply *reply, int len, int ret; =20 g_assert(qemu_in_coroutine()); + + TRACE("Send reply: handle =3D %" PRIu64 ", error =3D %" PRIu32 ", len = =3D %d", + reply->handle, reply->error, len); + qemu_co_mutex_lock(&client->send_lock); client->send_coroutine =3D qemu_coroutine_self(); =20 @@ -1039,7 +1043,8 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, return -EIO; } =20 - TRACE("Decoding type"); + TRACE("Decoding type: handle =3D %" PRIu64 ", type =3D %" PRIu16, + request->handle, request->type); =20 if (request->type !=3D NBD_CMD_WRITE) { /* No payload, we are ready to read the next request. */ @@ -1049,7 +1054,6 @@ 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"); return -EIO; } =20 @@ -1076,13 +1080,14 @@ static int nbd_co_receive_request(NBDRequestData *r= eq, NBDRequest *request, } } if (request->type =3D=3D NBD_CMD_WRITE) { - TRACE("Reading %" PRIu32 " byte(s)", request->len); - if (nbd_read(client->ioc, req->data, request->len, errp) < 0) { error_prepend(errp, "reading from socket failed: "); return -EIO; } req->complete =3D true; + + TRACE("Payload received: handle =3D %" PRIu64 ", len =3D %" PRIu32, + request->handle, request->len); } =20 /* Sanity checks, part 2. */ @@ -1150,8 +1155,6 @@ static coroutine_fn void nbd_trip(void *opaque) =20 switch (request.type) { case NBD_CMD_READ: - TRACE("Request type is READ"); - /* XXX: NBD Protocol only documents use of FUA with WRITE */ if (request.flags & NBD_CMD_FLAG_FUA) { ret =3D blk_co_flush(exp->blk); @@ -1171,20 +1174,14 @@ static coroutine_fn void nbd_trip(void *opaque) } =20 reply_data_len =3D request.len; - TRACE("Read %" PRIu32" byte(s)", request.len); =20 break; case NBD_CMD_WRITE: - TRACE("Request type is WRITE"); - if (exp->nbdflags & NBD_FLAG_READ_ONLY) { - TRACE("Server is read-only, return error"); reply.error =3D EROFS; break; } =20 - TRACE("Writing to device"); - flags =3D 0; if (request.flags & NBD_CMD_FLAG_FUA) { flags |=3D BDRV_REQ_FUA; @@ -1198,16 +1195,12 @@ static coroutine_fn void nbd_trip(void *opaque) =20 break; case NBD_CMD_WRITE_ZEROES: - TRACE("Request type is WRITE_ZEROES"); - if (exp->nbdflags & NBD_FLAG_READ_ONLY) { error_setg(&local_err, "Server is read-only, return error"); reply.error =3D EROFS; break; } =20 - TRACE("Writing to device"); - flags =3D 0; if (request.flags & NBD_CMD_FLAG_FUA) { flags |=3D BDRV_REQ_FUA; @@ -1228,8 +1221,6 @@ static coroutine_fn void nbd_trip(void *opaque) abort(); =20 case NBD_CMD_FLUSH: - TRACE("Request type is FLUSH"); - ret =3D blk_co_flush(exp->blk); if (ret < 0) { error_setg_errno(&local_err, -ret, "flush failed"); @@ -1238,7 +1229,6 @@ static coroutine_fn void nbd_trip(void *opaque) =20 break; case NBD_CMD_TRIM: - TRACE("Request type is TRIM"); ret =3D blk_co_pdiscard(exp->blk, request.from + exp->dev_offset, request.len); if (ret < 0) { @@ -1274,8 +1264,6 @@ reply: goto disconnect; } =20 - TRACE("Request/Reply complete"); - done: nbd_request_put(req); nbd_client_put(client); --=20 2.11.1 From nobody Sat May 18 23:55:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499441649003298.2514189807189; Fri, 7 Jul 2017 08:34:09 -0700 (PDT) Received: from localhost ([::1]:57146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVGg-0004Ja-LM for importer@patchew.org; Fri, 07 Jul 2017 11:34:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTVCM-0000sc-9c for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTVCG-0001E9-9h for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:36 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:4668 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 1dTVCF-0001Cf-L3 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 11:29:32 -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 v67FTIuY028047; Fri, 7 Jul 2017 18:29:20 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:29:18 +0300 Message-Id: <20170707152918.23086-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170707152918.23086-1-vsementsov@virtuozzo.com> References: <20170707152918.23086-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 v3 10/10] 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: vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com 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" Let NBD use the trace mechanisms already present in qemu. Now you can use the -trace optino of qemu, or the -T/--trace option of qemu-img, qemu-io, and qemu-nbd, to select nbd traces. For qemu, the QMP commands trace-event-{get,set}-state can also toggle tracing on the fly. Example: qemu-nbd --trace 'nbd_*' # enables all nbd traces Recompilation with CFLAGS=3D-DDEBUG_NBD is no more needed, furthermore, DEBUG_NBD macro is removed from the code. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- Makefile.objs | 1 + nbd/client.c | 70 ++++++++++++++++++++++++--------------------------= ---- nbd/nbd-internal.h | 19 --------------- nbd/server.c | 67 ++++++++++++++++++++++++--------------------------- nbd/trace-events | 58 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 94 deletions(-) create mode 100644 nbd/trace-events diff --git a/Makefile.objs b/Makefile.objs index b2e6322ef0..a66ea34cc4 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -168,6 +168,7 @@ trace-events-subdirs +=3D linux-user trace-events-subdirs +=3D qapi trace-events-subdirs +=3D accel/tcg trace-events-subdirs +=3D accel/kvm +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 1ae4ff8a8e..ab4665307b 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, @@ -437,8 +436,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 @@ -462,7 +460,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, } =20 magic =3D ldq_be_p(buf); - TRACE("Magic is 0x%" PRIx64, magic); + trace_nbd_receive_negotiate_magic(magic); =20 if (memcmp(buf, "NBDMAGIC", 8) !=3D 0) { error_setg(errp, "Invalid magic received"); @@ -474,7 +472,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; @@ -486,7 +484,7 @@ 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); if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) { fixedNewStyle =3D true; clientflags |=3D NBD_FLAG_C_FIXED_NEWSTYLE; @@ -514,7 +512,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) { @@ -579,7 +577,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 && nbd_drop(ioc, 124, errp) < 0) { error_prepend(errp, "Failed to read reserved block"); goto fail; @@ -601,7 +599,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; @@ -609,7 +607,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; @@ -617,10 +615,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) { @@ -632,7 +629,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; @@ -646,7 +643,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; } @@ -656,7 +653,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) { @@ -668,12 +665,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; @@ -710,11 +707,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); @@ -759,9 +753,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 39bfed177c..cf6ecbf358 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 4bbce5fe76..ca95f431d4 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) @@ -138,8 +139,7 @@ static int nbd_negotiate_send_rep_len(QIOChannel *ioc, = uint32_t type, { uint64_t magic; =20 - TRACE("Reply opt=3D%" PRIx32 " type=3D%" PRIx32 " len=3D%" PRIu32, - opt, type, len); + trace_nbd_negotiate_send_rep_len(opt, type, len); =20 magic =3D cpu_to_be64(NBD_REP_MAGIC); if (nbd_write(ioc, &magic, sizeof(magic), errp) < 0) { @@ -191,7 +191,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; @@ -219,7 +219,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); @@ -283,7 +283,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; @@ -294,7 +294,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) { @@ -318,7 +318,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 (nbd_drop(ioc, length, errp) < 0) { @@ -344,7 +344,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, @@ -396,15 +396,15 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) error_prepend(errp, "read failed: "); return -EIO; } - 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; } @@ -422,7 +422,7 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) error_prepend(errp, "read failed: "); return -EINVAL; } - 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; @@ -441,7 +441,7 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) } length =3D be32_to_cpu(length); =20 - TRACE("Checking option 0x%" PRIx32, option); + trace_nbd_negotiate_options_check_option(option); if (client->tlscreds && client->ioc =3D=3D (QIOChannel *)client->sioc) { QIOChannel *tioc; @@ -501,8 +501,8 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) &local_err); =20 if (local_err !=3D NULL) { - TRACE("Reply to NBD_OPT_ABORT request failed: %s", - error_get_pretty(local_err)); + const char *error =3D error_get_pretty(local_err); + trace_nbd_opt_abort_reply_failed(error); error_free(local_err); } =20 @@ -599,14 +599,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); @@ -631,8 +631,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; @@ -643,7 +643,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *client= , Error **errp) } } =20 - TRACE("Negotiation succeeded."); + trace_nbd_negotiate_success(); =20 return 0; } @@ -676,9 +676,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); @@ -693,9 +692,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) @@ -792,7 +789,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_nbd_blk_aio_attached(exp->name, ctx); =20 exp->ctx =3D ctx; =20 @@ -812,7 +809,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_nbd_blk_aio_detach(exp->name, exp->ctx); =20 QTAILQ_FOREACH(client, &exp->clients, next) { qio_channel_detach_aio_context(client->ioc); @@ -1001,8 +998,7 @@ static int nbd_co_send_reply(NBDRequestData *req, NBDR= eply *reply, int len, =20 g_assert(qemu_in_coroutine()); =20 - TRACE("Send reply: handle =3D %" PRIu64 ", error =3D %" PRIu32 ", len = =3D %d", - reply->handle, reply->error, len); + trace_nbd_co_send_reply(reply->handle, reply->error, len); =20 qemu_co_mutex_lock(&client->send_lock); client->send_coroutine =3D qemu_coroutine_self(); @@ -1043,8 +1039,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, return -EIO; } =20 - TRACE("Decoding type: handle =3D %" PRIu64 ", type =3D %" PRIu16, - request->handle, request->type); + trace_nbd_co_receive_request_decode_type(request->handle, request->typ= e); =20 if (request->type !=3D NBD_CMD_WRITE) { /* No payload, we are ready to read the next request. */ @@ -1086,8 +1081,8 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, } req->complete =3D true; =20 - TRACE("Payload received: handle =3D %" PRIu64 ", len =3D %" PRIu32, - request->handle, request->len); + trace_nbd_co_receive_request_payload_received(request->handle, + request->len); } =20 /* Sanity checks, part 2. */ @@ -1123,7 +1118,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_nbd_trip(); if (client->closing) { nbd_client_put(client); return; diff --git a/nbd/trace-events b/nbd/trace-events new file mode 100644 index 0000000000..b20165a585 --- /dev/null +++ b/nbd/trace-events @@ -0,0 +1,58 @@ +# 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(uint64_t magic) "Magic is 0x%" PRIx64 +nbd_receive_negotiate_magic2(uint64_t magic) "Magic is 0x%" PRIx64 +nbd_receive_negotiate_server_flags(uint32_t globalflags) "Global flags are= %" PRIx32 +nbd_receive_negotiate_default_name(void) "Using default NBD export name \"= \"" +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 opt, uint32_t type, 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 option) "Checking option 0x%" = PRIx32 +nbd_opt_abort_reply_failed(const char *error) "Reply to NBD_OPT_ABORT requ= est failed: %s" +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 " }" +nbd_blk_aio_attached(const char *name, void *ctx) "Export %s: Attaching cl= ients to AIO context %p\n" +nbd_blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clie= nts from AIO context %p\n" +nbd_co_send_reply(uint64_t handle, uint32_t error, int len) "Send reply: h= andle =3D %" PRIu64 ", error =3D %" PRIu32 ", len =3D %d" +nbd_co_receive_request_decode_type(uint64_t handle, uint16_t type) "Decodi= ng type: handle =3D %" PRIu64 ", type =3D %" PRIu16 +nbd_co_receive_request_payload_received(uint64_t handle, uint32_t len) "Pa= yload received: handle =3D %" PRIu64 ", len =3D %" PRIu32 +nbd_co_receive_request_cmd_write(uint32_t len) "Reading %" PRIu32 " byte(s= )" +nbd_trip(void) "Reading request" --=20 2.11.1