From nobody Fri May 3 06:28:05 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538602024219129.49638187704738; Wed, 3 Oct 2018 14:27:04 -0700 (PDT) Received: from localhost ([::1]:53240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7ofe-0004oE-Vw for importer@patchew.org; Wed, 03 Oct 2018 17:27:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7obO-0001fG-1p for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7obM-000110-3B for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7obF-0000qL-TA; Wed, 03 Oct 2018 17:22:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E2E43003B32; Wed, 3 Oct 2018 21:22:17 +0000 (UTC) Received: from red.redhat.com (ovpn-126-73.rdu2.redhat.com [10.10.126.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 428D360F97; Wed, 3 Oct 2018 21:22:16 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 16:22:07 -0500 Message-Id: <20181003212211.812374-2-eblake@redhat.com> In-Reply-To: <20181003212211.812374-1-eblake@redhat.com> References: <20181003212211.812374-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 03 Oct 2018 21:22:17 +0000 (UTC) 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 1/5] nbd: Don't take address of fields in packed structs 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: Peter Maydell , "open list:Network Block Dev..." , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell Taking the address of a field in a packed struct is a bad idea, because it might not be actually aligned enough for that pointer type (and thus cause a crash on dereference on some host architectures). Newer versions of clang warn about this. Avoid the bug by not using the "modify in place" byte swapping functions. This patch was produced with the following spatch script: @@ expression E; @@ -be16_to_cpus(&E); +E =3D be16_to_cpu(E); @@ expression E; @@ -be32_to_cpus(&E); +E =3D be32_to_cpu(E); @@ expression E; @@ -be64_to_cpus(&E); +E =3D be64_to_cpu(E); @@ expression E; @@ -cpu_to_be16s(&E); +E =3D cpu_to_be16(E); @@ expression E; @@ -cpu_to_be32s(&E); +E =3D cpu_to_be32(E); @@ expression E; @@ -cpu_to_be64s(&E); +E =3D cpu_to_be64(E); Signed-off-by: Peter Maydell Message-Id: <20180927164200.15097-1-peter.maydell@linaro.org> Reviewed-by: Eric Blake [eblake: rebase, and squash in missed changes] Signed-off-by: Eric Blake --- nbd/client.c | 44 ++++++++++++++++++++++---------------------- nbd/server.c | 24 ++++++++++++------------ 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 40b74d9761f..b4d457a19ad 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -117,10 +117,10 @@ static int nbd_receive_option_reply(QIOChannel *ioc, = uint32_t opt, nbd_send_opt_abort(ioc); return -1; } - be64_to_cpus(&reply->magic); - be32_to_cpus(&reply->option); - be32_to_cpus(&reply->type); - be32_to_cpus(&reply->length); + reply->magic =3D be64_to_cpu(reply->magic); + reply->option =3D be32_to_cpu(reply->option); + reply->type =3D be32_to_cpu(reply->type); + reply->length =3D be32_to_cpu(reply->length); trace_nbd_receive_option_reply(reply->option, nbd_opt_lookup(reply->op= tion), reply->type, nbd_rep_lookup(reply->type= ), @@ -396,7 +396,7 @@ static int nbd_opt_go(QIOChannel *ioc, const char *want= name, return -1; } len -=3D sizeof(type); - be16_to_cpus(&type); + type =3D be16_to_cpu(type); switch (type) { case NBD_INFO_EXPORT: if (len !=3D sizeof(info->size) + sizeof(info->flags)) { @@ -410,13 +410,13 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wa= ntname, nbd_send_opt_abort(ioc); return -1; } - be64_to_cpus(&info->size); + info->size =3D be64_to_cpu(info->size); if (nbd_read(ioc, &info->flags, sizeof(info->flags), errp) < 0= ) { error_prepend(errp, "failed to read info flags: "); nbd_send_opt_abort(ioc); return -1; } - be16_to_cpus(&info->flags); + info->flags =3D be16_to_cpu(info->flags); trace_nbd_receive_negotiate_size_flags(info->size, info->flags= ); break; @@ -433,7 +433,7 @@ static int nbd_opt_go(QIOChannel *ioc, const char *want= name, nbd_send_opt_abort(ioc); return -1; } - be32_to_cpus(&info->min_block); + info->min_block =3D be32_to_cpu(info->min_block); if (!is_power_of_2(info->min_block)) { error_setg(errp, "server minimum block size %" PRIu32 " is not a power of two", info->min_block); @@ -447,7 +447,7 @@ static int nbd_opt_go(QIOChannel *ioc, const char *want= name, nbd_send_opt_abort(ioc); return -1; } - be32_to_cpus(&info->opt_block); + info->opt_block =3D be32_to_cpu(info->opt_block); if (!is_power_of_2(info->opt_block) || info->opt_block < info->min_block) { error_setg(errp, "server preferred block size %" PRIu32 @@ -461,7 +461,7 @@ static int nbd_opt_go(QIOChannel *ioc, const char *want= name, nbd_send_opt_abort(ioc); return -1; } - be32_to_cpus(&info->max_block); + info->max_block =3D be32_to_cpu(info->max_block); if (info->max_block < info->min_block) { error_setg(errp, "server maximum block size %" PRIu32 " is not valid", info->max_block); @@ -668,7 +668,7 @@ static int nbd_negotiate_simple_meta_context(QIOChannel= *ioc, if (nbd_read(ioc, &received_id, sizeof(received_id), errp) < 0) { return -1; } - be32_to_cpus(&received_id); + received_id =3D be32_to_cpu(received_id); reply.length -=3D sizeof(received_id); name =3D g_malloc(reply.length + 1); @@ -872,13 +872,13 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, error_prepend(errp, "Failed to read export length: "); goto fail; } - be64_to_cpus(&info->size); + info->size =3D be64_to_cpu(info->size); if (nbd_read(ioc, &info->flags, sizeof(info->flags), errp) < 0) { error_prepend(errp, "Failed to read export flags: "); goto fail; } - be16_to_cpus(&info->flags); + info->flags =3D be16_to_cpu(info->flags); } else if (magic =3D=3D NBD_CLIENT_MAGIC) { uint32_t oldflags; @@ -895,13 +895,13 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, error_prepend(errp, "Failed to read export length: "); goto fail; } - be64_to_cpus(&info->size); + info->size =3D be64_to_cpu(info->size); if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) { error_prepend(errp, "Failed to read export flags: "); goto fail; } - be32_to_cpus(&oldflags); + oldflags =3D be32_to_cpu(oldflags); if (oldflags & ~0xffff) { error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflag= s); goto fail; @@ -1080,8 +1080,8 @@ static int nbd_receive_simple_reply(QIOChannel *ioc, = NBDSimpleReply *reply, return ret; } - be32_to_cpus(&reply->error); - be64_to_cpus(&reply->handle); + reply->error =3D be32_to_cpu(reply->error); + reply->handle =3D be64_to_cpu(reply->handle); return 0; } @@ -1105,10 +1105,10 @@ static int nbd_receive_structured_reply_chunk(QIOCh= annel *ioc, return ret; } - be16_to_cpus(&chunk->flags); - be16_to_cpus(&chunk->type); - be64_to_cpus(&chunk->handle); - be32_to_cpus(&chunk->length); + chunk->flags =3D be16_to_cpu(chunk->flags); + chunk->type =3D be16_to_cpu(chunk->type); + chunk->handle =3D be64_to_cpu(chunk->handle); + chunk->length =3D be32_to_cpu(chunk->length); return 0; } @@ -1128,7 +1128,7 @@ int nbd_receive_reply(QIOChannel *ioc, NBDReply *repl= y, Error **errp) return ret; } - be32_to_cpus(&reply->magic); + reply->magic =3D be32_to_cpu(reply->magic); switch (reply->magic) { case NBD_SIMPLE_REPLY_MAGIC: diff --git a/nbd/server.c b/nbd/server.c index c3dd402b45e..98d0fa25158 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -333,7 +333,7 @@ static int nbd_opt_read_name(NBDClient *client, char *n= ame, uint32_t *length, if (ret <=3D 0) { return ret; } - cpu_to_be32s(&len); + len =3D cpu_to_be32(len); if (len > NBD_MAX_NAME_SIZE) { return nbd_opt_invalid(client, errp, @@ -486,7 +486,7 @@ static int nbd_negotiate_send_info(NBDClient *client, if (rc < 0) { return rc; } - cpu_to_be16s(&info); + info =3D cpu_to_be16(info); if (nbd_write(client->ioc, &info, sizeof(info), errp) < 0) { return -EIO; } @@ -551,14 +551,14 @@ static int nbd_negotiate_handle_info(NBDClient *clien= t, uint16_t myflags, if (rc <=3D 0) { return rc; } - be16_to_cpus(&requests); + requests =3D be16_to_cpu(requests); trace_nbd_negotiate_handle_info_requests(requests); while (requests--) { rc =3D nbd_opt_read(client, &request, sizeof(request), errp); if (rc <=3D 0) { return rc; } - be16_to_cpus(&request); + request =3D be16_to_cpu(request); trace_nbd_negotiate_handle_info_request(request, nbd_info_lookup(request)); /* We care about NBD_INFO_NAME and NBD_INFO_BLOCK_SIZE; @@ -618,9 +618,9 @@ static int nbd_negotiate_handle_info(NBDClient *client,= uint16_t myflags, /* maximum - At most 32M, but smaller as appropriate. */ sizes[2] =3D MIN(blk_get_max_transfer(exp->blk), NBD_MAX_BUFFER_SIZE); trace_nbd_negotiate_handle_info_block_size(sizes[0], sizes[1], sizes[2= ]); - cpu_to_be32s(&sizes[0]); - cpu_to_be32s(&sizes[1]); - cpu_to_be32s(&sizes[2]); + sizes[0] =3D cpu_to_be32(sizes[0]); + sizes[1] =3D cpu_to_be32(sizes[1]); + sizes[2] =3D cpu_to_be32(sizes[2]); rc =3D nbd_negotiate_send_info(client, NBD_INFO_BLOCK_SIZE, sizeof(sizes), sizes, errp); if (rc < 0) { @@ -904,7 +904,7 @@ static int nbd_negotiate_meta_query(NBDClient *client, if (ret <=3D 0) { return ret; } - cpu_to_be32s(&len); + len =3D cpu_to_be32(len); if (len < ns_len) { trace_nbd_negotiate_meta_query_skip("length too short"); @@ -971,7 +971,7 @@ static int nbd_negotiate_meta_queries(NBDClient *client, if (ret <=3D 0) { return ret; } - cpu_to_be32s(&nb_queries); + nb_queries =3D cpu_to_be32(nb_queries); trace_nbd_negotiate_meta_context(nbd_opt_lookup(client->opt), export_name, nb_queries); @@ -1049,7 +1049,7 @@ static int nbd_negotiate_options(NBDClient *client, u= int16_t myflags, error_prepend(errp, "read failed: "); return -EIO; } - be32_to_cpus(&flags); + flags =3D be32_to_cpu(flags); trace_nbd_negotiate_options_flags(flags); if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) { fixedNewstyle =3D true; @@ -1900,8 +1900,8 @@ static int blockstatus_to_extents(BlockDriverState *b= s, uint64_t offset, extents_end =3D extent + 1; for (extent =3D extents; extent < extents_end; extent++) { - cpu_to_be32s(&extent->flags); - cpu_to_be32s(&extent->length); + extent->flags =3D cpu_to_be32(extent->flags); + extent->length =3D cpu_to_be32(extent->length); } *bytes -=3D remaining_bytes; --=20 2.17.1 From nobody Fri May 3 06:28:05 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538601996082938.2906576287852; Wed, 3 Oct 2018 14:26:36 -0700 (PDT) Received: from localhost ([::1]:53239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7of8-0004UA-Lu for importer@patchew.org; Wed, 03 Oct 2018 17:26:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7obM-0001dU-Il for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7obL-00010B-Gh for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7obD-0000qh-BE; Wed, 03 Oct 2018 17:22:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C73963083392; Wed, 3 Oct 2018 21:22:18 +0000 (UTC) Received: from red.redhat.com (ovpn-126-73.rdu2.redhat.com [10.10.126.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD28EBA65; Wed, 3 Oct 2018 21:22:17 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 16:22:08 -0500 Message-Id: <20181003212211.812374-3-eblake@redhat.com> In-Reply-To: <20181003212211.812374-1-eblake@redhat.com> References: <20181003212211.812374-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 03 Oct 2018 21:22:18 +0000 (UTC) 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 2/5] nbd/server: fix NBD_CMD_CACHE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-stable@nongnu.org, "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We should not go to structured-read branch on CACHE command, fix that. Bug introduced in bc37b06a5cde24 "nbd/server: introduce NBD_CMD_CACHE" with the whole feature and affects 3.0.0 release. Signed-off-by: Vladimir Sementsov-Ogievskiy CC: qemu-stable@nongnu.org Message-Id: <20181003144738.70670-1-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: commit message typo fix] Signed-off-by: Eric Blake --- nbd/server.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nbd/server.c b/nbd/server.c index 98d0fa25158..4fb247b1166 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2177,7 +2177,8 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, } if (client->structured_reply && !(request->flags & NBD_CMD_FLAG_DF) && - request->len) { + request->len && request->type !=3D NBD_CMD_CACHE) + { return nbd_co_send_sparse_read(client, request->handle, request->f= rom, data, request->len, errp); } --=20 2.17.1 From nobody Fri May 3 06:28:05 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538601890847111.17100768604189; Wed, 3 Oct 2018 14:24:50 -0700 (PDT) Received: from localhost ([::1]:53220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7odO-0002pe-LR for importer@patchew.org; Wed, 03 Oct 2018 17:24:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7obM-0001dE-7f for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7obL-000101-Bd for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55306) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7obF-0000qu-Ve; Wed, 03 Oct 2018 17:22:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB51BA459C; Wed, 3 Oct 2018 21:22:19 +0000 (UTC) Received: from red.redhat.com (ovpn-126-73.rdu2.redhat.com [10.10.126.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 126E360F97; Wed, 3 Oct 2018 21:22:18 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 16:22:09 -0500 Message-Id: <20181003212211.812374-4-eblake@redhat.com> In-Reply-To: <20181003212211.812374-1-eblake@redhat.com> References: <20181003212211.812374-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 03 Oct 2018 21:22:19 +0000 (UTC) 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 3/5] qemu-nbd: Document --tls-creds X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit 145614a1 introduced --tls-creds and documented it in qemu-nbd.texi, but forgot to document it in 'qemu-nbd --help'. Signed-off-by: Eric Blake Message-Id: <20181003180426.602765-1-eblake@redhat.com> Reviewed-by: John Snow --- qemu-nbd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/qemu-nbd.c b/qemu-nbd.c index 51b9d38c727..66e023f7fa4 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -94,6 +94,7 @@ static void usage(const char *name) "General purpose options:\n" " --object type,id=3DID,... define an object such as 'secret' for provi= ding\n" " passwords and/or encryption keys\n" +" --tls-creds=3DID use id of an earlier --object to provide TL= S\n" " -T, --trace [[enable=3D]][,events=3D][,file=3D]\n" " specify tracing options\n" " --fork fork off the server process and exit the pare= nt\n" --=20 2.17.1 From nobody Fri May 3 06:28:05 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538602083205359.1368481226974; Wed, 3 Oct 2018 14:28:03 -0700 (PDT) Received: from localhost ([::1]:53245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7ogc-0006GD-3d for importer@patchew.org; Wed, 03 Oct 2018 17:28:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7obN-0001eg-DZ for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7obM-00010r-2D for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7obF-0000r2-W6; Wed, 03 Oct 2018 17:22:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D23DE307D858; Wed, 3 Oct 2018 21:22:20 +0000 (UTC) Received: from red.redhat.com (ovpn-126-73.rdu2.redhat.com [10.10.126.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08D0860F97; Wed, 3 Oct 2018 21:22:19 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 16:22:10 -0500 Message-Id: <20181003212211.812374-5-eblake@redhat.com> In-Reply-To: <20181003212211.812374-1-eblake@redhat.com> References: <20181003212211.812374-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 03 Oct 2018 21:22:20 +0000 (UTC) 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 4/5] qemu-nbd: drop old-style negotiation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Use new-style negotiation always, with default "" (empty) export name if it is not specified with '-x' option. qemu as client can manage either style since 2.6.0, commit 69b49502d8 For comparison: nbd 3.10 dropped oldstyle long ago (Mar 2015): https://github.com/NetworkBlockDevice/nbd/commit/36940193 nbdkit 1.3 switched its default to newstyle (Jan 2018): https://github.com/libguestfs/nbdkit/commit/b2a8aecc https://github.com/libguestfs/nbdkit/commit/8158e773 Furthermore, if a client that only speaks oldstyle still needs to communicate to qemu, nbdkit remains available to perform the translation between the two protocols. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20181003170228.95973-2-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: enhance commit message] Signed-off-by: Eric Blake --- qemu-nbd.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 66e023f7fa4..6aaebe7d938 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -56,7 +56,6 @@ #define MBR_SIZE 512 static NBDExport *exp; -static bool newproto; static int verbose; static char *srcpath; static SocketAddress *saddr; @@ -84,8 +83,8 @@ static void usage(const char *name) " -e, --shared=3DNUM device can be shared by NUM clients (defaul= t '1')\n" " -t, --persistent don't exit on the last connection\n" " -v, --verbose display extra debugging information\n" -" -x, --export-name=3DNAME expose export by name\n" -" -D, --description=3DTEXT with -x, also export a human-readable descr= iption\n" +" -x, --export-name=3DNAME expose export by name (default is empty str= ing)\n" +" -D, --description=3DTEXT export a human-readable description\n" "\n" "Exposing part of the image:\n" " -o, --offset=3DOFFSET offset into the image\n" @@ -355,8 +354,7 @@ static void nbd_accept(QIONetListener *listener, QIOCha= nnelSocket *cioc, nb_fds++; nbd_update_server_watch(); - nbd_client_new(newproto ? NULL : exp, cioc, - tlscreds, NULL, nbd_client_closed); + nbd_client_new(NULL, cioc, tlscreds, NULL, nbd_client_closed); } static void nbd_update_server_watch(void) @@ -550,7 +548,7 @@ int main(int argc, char **argv) Error *local_err =3D NULL; BlockdevDetectZeroesOptions detect_zeroes =3D BLOCKDEV_DETECT_ZEROES_O= PTIONS_OFF; QDict *options =3D NULL; - const char *export_name =3D NULL; + const char *export_name =3D ""; /* Default export name */ const char *export_description =3D NULL; const char *tlscredsid =3D NULL; bool imageOpts =3D false; @@ -809,11 +807,6 @@ int main(int argc, char **argv) error_report("TLS is not supported with a host device"); exit(EXIT_FAILURE); } - if (!export_name) { - /* Set the default NBD protocol export name, since - * we *must* use new style protocol for TLS */ - export_name =3D ""; - } tlscreds =3D nbd_get_tls_creds(tlscredsid, &local_err); if (local_err) { error_report("Failed to get TLS creds %s", @@ -1014,14 +1007,8 @@ int main(int argc, char **argv) error_report_err(local_err); exit(EXIT_FAILURE); } - if (export_name) { - nbd_export_set_name(exp, export_name); - nbd_export_set_description(exp, export_description); - newproto =3D true; - } else if (export_description) { - error_report("Export description requires an export name"); - exit(EXIT_FAILURE); - } + nbd_export_set_name(exp, export_name); + nbd_export_set_description(exp, export_description); if (device) { int ret; --=20 2.17.1 From nobody Fri May 3 06:28:05 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153860189093882.05144991469047; Wed, 3 Oct 2018 14:24:50 -0700 (PDT) Received: from localhost ([::1]:53221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7odO-0002pg-GM for importer@patchew.org; Wed, 03 Oct 2018 17:24:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7obN-0001e9-3U for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7obL-00010V-NB for qemu-devel@nongnu.org; Wed, 03 Oct 2018 17:22:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57606) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7obF-0000rT-VR; Wed, 03 Oct 2018 17:22:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B4F03DD47; Wed, 3 Oct 2018 21:22:22 +0000 (UTC) Received: from red.redhat.com (ovpn-126-73.rdu2.redhat.com [10.10.126.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21FF5662E7; Wed, 3 Oct 2018 21:22:21 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 16:22:11 -0500 Message-Id: <20181003212211.812374-6-eblake@redhat.com> In-Reply-To: <20181003212211.812374-1-eblake@redhat.com> References: <20181003212211.812374-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 03 Oct 2018 21:22:22 +0000 (UTC) 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 5/5] nbd/server: drop old-style negotiation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy After the previous commit, nbd_client_new's first parameter is always NULL. Let's drop it with all corresponding old-style negotiation code path which is unreachable now. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20181003170228.95973-3-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: re-wrap short line] Signed-off-by: Eric Blake --- include/block/nbd.h | 3 +-- blockdev-nbd.c | 3 +-- nbd/server.c | 53 +++++++++++++-------------------------------- qemu-nbd.c | 2 +- 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 4638c839f51..0129d1a4b46 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -308,8 +308,7 @@ void nbd_export_set_name(NBDExport *exp, const char *na= me); void nbd_export_set_description(NBDExport *exp, const char *description); void nbd_export_close_all(void); -void nbd_client_new(NBDExport *exp, - QIOChannelSocket *sioc, +void nbd_client_new(QIOChannelSocket *sioc, QCryptoTLSCreds *tlscreds, const char *tlsaclname, void (*close_fn)(NBDClient *, bool)); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 1ef11041a73..1d170c80b82 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -36,8 +36,7 @@ static void nbd_accept(QIONetListener *listener, QIOChann= elSocket *cioc, gpointer opaque) { qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server"); - nbd_client_new(NULL, cioc, - nbd_server->tlscreds, NULL, + nbd_client_new(cioc, nbd_server->tlscreds, NULL, nbd_blockdev_client_closed); } diff --git a/nbd/server.c b/nbd/server.c index 4fb247b1166..a1eda0114fa 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1253,7 +1253,6 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) const uint16_t myflags =3D (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA | NBD_FLAG_SEND_WRITE_ZEROES | NBD_FLAG_SEND_C= ACHE); - bool oldStyle; /* Old style negotiation header, no room for options [ 0 .. 7] passwd ("NBDMAGIC") @@ -1274,33 +1273,19 @@ static coroutine_fn int nbd_negotiate(NBDClient *cl= ient, Error **errp) trace_nbd_negotiate_begin(); memcpy(buf, "NBDMAGIC", 8); - oldStyle =3D client->exp !=3D NULL && !client->tlscreds; - if (oldStyle) { - 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); - stl_be_p(buf + 24, client->exp->nbdflags | myflags); + 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, 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); - - if (nbd_write(client->ioc, buf, 18, errp) < 0) { - error_prepend(errp, "write failed: "); - return -EINVAL; - } - ret =3D nbd_negotiate_options(client, myflags, errp); - if (ret !=3D 0) { - if (ret < 0) { - error_prepend(errp, "option negotiation failed: "); - } - return ret; + if (nbd_write(client->ioc, buf, 18, errp) < 0) { + error_prepend(errp, "write failed: "); + return -EINVAL; + } + ret =3D nbd_negotiate_options(client, myflags, errp); + if (ret !=3D 0) { + if (ret < 0) { + error_prepend(errp, "option negotiation failed: "); } + return ret; } assert(!client->optlen); @@ -2396,13 +2381,8 @@ static void nbd_client_receive_next_request(NBDClien= t *client) static coroutine_fn void nbd_co_client_start(void *opaque) { NBDClient *client =3D opaque; - NBDExport *exp =3D client->exp; Error *local_err =3D NULL; - if (exp) { - nbd_export_get(exp); - QTAILQ_INSERT_TAIL(&exp->clients, client, next); - } qemu_co_mutex_init(&client->send_lock); if (nbd_negotiate(client, &local_err)) { @@ -2417,13 +2397,11 @@ static coroutine_fn void nbd_co_client_start(void *= opaque) } /* - * Create a new client listener on the given export @exp, using the - * given channel @sioc. Begin servicing it in a coroutine. When the - * connection closes, call @close_fn with an indication of whether the - * client completed negotiation. + * Create a new client listener using the given channel @sioc. + * Begin servicing it in a coroutine. When the connection closes, call + * @close_fn with an indication of whether the client completed negotiatio= n. */ -void nbd_client_new(NBDExport *exp, - QIOChannelSocket *sioc, +void nbd_client_new(QIOChannelSocket *sioc, QCryptoTLSCreds *tlscreds, const char *tlsaclname, void (*close_fn)(NBDClient *, bool)) @@ -2433,7 +2411,6 @@ void nbd_client_new(NBDExport *exp, client =3D g_new0(NBDClient, 1); client->refcount =3D 1; - client->exp =3D exp; client->tlscreds =3D tlscreds; if (tlscreds) { object_ref(OBJECT(client->tlscreds)); diff --git a/qemu-nbd.c b/qemu-nbd.c index 6aaebe7d938..e76fe3082ab 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -354,7 +354,7 @@ static void nbd_accept(QIONetListener *listener, QIOCha= nnelSocket *cioc, nb_fds++; nbd_update_server_watch(); - nbd_client_new(NULL, cioc, tlscreds, NULL, nbd_client_closed); + nbd_client_new(cioc, tlscreds, NULL, nbd_client_closed); } static void nbd_update_server_watch(void) --=20 2.17.1