From nobody Sun Oct 5 21:14:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548111647849383.98173014136455; Mon, 21 Jan 2019 15:00:47 -0800 (PST) Received: from localhost ([127.0.0.1]:35565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gliYg-00023Z-PO for importer@patchew.org; Mon, 21 Jan 2019 18:00:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gliO2-0001Oy-EI for qemu-devel@nongnu.org; Mon, 21 Jan 2019 17:49:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gliNx-0005Bo-Ou for qemu-devel@nongnu.org; Mon, 21 Jan 2019 17:49:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54788) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gliNs-00050e-D3; Mon, 21 Jan 2019 17:49:38 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36075C002961; Mon, 21 Jan 2019 22:49:25 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-44.phx2.redhat.com [10.3.117.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id D322360123; Mon, 21 Jan 2019 22:49:24 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 21 Jan 2019 16:49:02 -0600 Message-Id: <20190121224907.26634-17-eblake@redhat.com> In-Reply-To: <20190121224907.26634-1-eblake@redhat.com> References: <20190121224907.26634-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 21 Jan 2019 22:49:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 16/21] nbd/client: Refactor nbd_opt_go() to support NBD_OPT_INFO 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: Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Rename the function to nbd_opt_info_or_go() with an added parameter and slight changes to comments and trace messages, in order to reuse the function for NBD_OPT_INFO. Signed-off-by: Eric Blake Message-Id: <20190117193658.16413-17-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/client.c | 36 ++++++++++++++++++++++-------------- nbd/trace-events | 8 ++++---- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 6829c684fec..fa1657a1cb3 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -330,11 +330,16 @@ static int nbd_receive_list(QIOChannel *ioc, char **n= ame, char **description, } -/* Returns -1 if NBD_OPT_GO proves the export @info->name cannot be - * used, 0 if NBD_OPT_GO is unsupported (fall back to NBD_OPT_LIST and +/* + * nbd_opt_info_or_go: + * Send option for NBD_OPT_INFO or NBD_OPT_GO and parse the reply. + * Returns -1 if the option proves the export @info->name cannot be + * used, 0 if the option is unsupported (fall back to NBD_OPT_LIST and * NBD_OPT_EXPORT_NAME in that case), and > 0 if the export is good to - * go (with the rest of @info populated). */ -static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *info, Error **errp) + * go (with the rest of @info populated). + */ +static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt, + NBDExportInfo *info, Error **errp) { NBDOptionReply reply; uint32_t len =3D strlen(info->name); @@ -347,7 +352,8 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *i= nfo, Error **errp) * flags still 0 is a witness of a broken server. */ info->flags =3D 0; - trace_nbd_opt_go_start(info->name); + assert(opt =3D=3D NBD_OPT_GO || opt =3D=3D NBD_OPT_INFO); + trace_nbd_opt_info_go_start(nbd_opt_lookup(opt), info->name); buf =3D g_malloc(4 + len + 2 + 2 * info->request_sizes + 1); stl_be_p(buf, len); memcpy(buf + 4, info->name, len); @@ -356,7 +362,7 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *i= nfo, Error **errp) if (info->request_sizes) { stw_be_p(buf + 4 + len + 2, NBD_INFO_BLOCK_SIZE); } - error =3D nbd_send_option_request(ioc, NBD_OPT_GO, + error =3D nbd_send_option_request(ioc, opt, 4 + len + 2 + 2 * info->request_sizes, buf, errp); g_free(buf); @@ -365,7 +371,7 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *i= nfo, Error **errp) } while (1) { - if (nbd_receive_option_reply(ioc, NBD_OPT_GO, &reply, errp) < 0) { + if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) { return -1; } error =3D nbd_handle_reply_err(ioc, &reply, errp); @@ -375,8 +381,10 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *= info, Error **errp) len =3D reply.length; if (reply.type =3D=3D NBD_REP_ACK) { - /* Server is done sending info and moved into transmission - phase, but make sure it sent flags */ + /* + * Server is done sending info, and moved into transmission + * phase for NBD_OPT_GO, but make sure it sent flags + */ if (len) { error_setg(errp, "server sent invalid NBD_REP_ACK"); return -1; @@ -385,7 +393,7 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *i= nfo, Error **errp) error_setg(errp, "broken server omitted NBD_INFO_EXPORT"); return -1; } - trace_nbd_opt_go_success(); + trace_nbd_opt_info_go_success(nbd_opt_lookup(opt)); return 1; } if (reply.type !=3D NBD_REP_INFO) { @@ -479,12 +487,12 @@ static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo = *info, Error **errp) nbd_send_opt_abort(ioc); return -1; } - trace_nbd_opt_go_info_block_size(info->min_block, info->opt_bl= ock, - info->max_block); + trace_nbd_opt_info_block_size(info->min_block, info->opt_block, + info->max_block); break; default: - trace_nbd_opt_go_info_unknown(type, nbd_info_lookup(type)); + trace_nbd_opt_info_unknown(type, nbd_info_lookup(type)); if (nbd_drop(ioc, len, errp) < 0) { error_prepend(errp, "Failed to read info payload: "); nbd_send_opt_abort(ioc); @@ -993,7 +1001,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSC= reds *tlscreds, * TLS). If it is not available, fall back to * NBD_OPT_LIST for nicer error messages about a missing * export, then use NBD_OPT_EXPORT_NAME. */ - result =3D nbd_opt_go(ioc, info, errp); + result =3D nbd_opt_info_or_go(ioc, NBD_OPT_GO, info, errp); if (result < 0) { return -EINVAL; } diff --git a/nbd/trace-events b/nbd/trace-events index 663d11687ab..7f10ebd4e0b 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -4,10 +4,10 @@ nbd_receive_option_reply(uint32_t option, const char *opt= name, uint32_t type, co nbd_server_error_msg(uint32_t err, const char *type, const char *msg) "ser= ver reported error 0x%" PRIx32 " (%s) with additional message: %s" nbd_reply_err_unsup(uint32_t option, const char *name) "server doesn't und= erstand request %" PRIu32 " (%s), attempting fallback" nbd_receive_list(const char *name, const char *desc) "export list includes= '%s', description '%s'" -nbd_opt_go_start(const char *name) "Attempting NBD_OPT_GO for export '%s'" -nbd_opt_go_success(void) "Export is good to go" -nbd_opt_go_info_unknown(int info, const char *name) "Ignoring unknown info= %d (%s)" -nbd_opt_go_info_block_size(uint32_t minimum, uint32_t preferred, uint32_t = maximum) "Block sizes are 0x%" PRIx32 ", 0x%" PRIx32 ", 0x%" PRIx32 +nbd_opt_info_go_start(const char *opt, const char *name) "Attempting %s fo= r export '%s'" +nbd_opt_info_go_success(const char *opt) "Export is ready after %s request" +nbd_opt_info_unknown(int info, const char *name) "Ignoring unknown info %d= (%s)" +nbd_opt_info_block_size(uint32_t minimum, uint32_t preferred, uint32_t max= imum) "Block sizes are 0x%" PRIx32 ", 0x%" PRIx32 ", 0x%" PRIx32 nbd_receive_query_exports_start(const char *wantname) "Querying export lis= t for '%s'" nbd_receive_query_exports_success(const char *wantname) "Found desired exp= ort name '%s'" nbd_receive_starttls_new_client(void) "Setting up TLS" --=20 2.20.1