From nobody Sun May 5 09:16:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549339046812991.9748344633718; Mon, 4 Feb 2019 19:57:26 -0800 (PST) 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 B655459440; Tue, 5 Feb 2019 03:57:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A314660BE8; Tue, 5 Feb 2019 03:57:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6677518005CB; Tue, 5 Feb 2019 03:57:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x153vBbq027309 for ; Mon, 4 Feb 2019 22:57:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9F56A68D48; Tue, 5 Feb 2019 03:57:11 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-162.phx2.redhat.com [10.3.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3D255C57C; Tue, 5 Feb 2019 03:57:06 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 21:56:57 -0600 Message-Id: <20190205035704.26014-2-eblake@redhat.com> In-Reply-To: <20190205035704.26014-1-eblake@redhat.com> References: <20190205035704.26014-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: "reviewer:Incompatible changes" , "open list:Network Block Dev..." , Stefano Garzarella Subject: [libvirt] [PULL 1/8] qemu-nbd: Deprecate qemu-nbd --partition X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@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.39]); Tue, 05 Feb 2019 03:57:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The existing qemu-nbd --partition code claims to handle logical partitions up to 8, since its introduction in 2008 (commit 7a5ca86). However, the implementation is bogus (actual MBR logical partitions form a sort of linked list, with one partition per extended table entry, rather than four logical partitions in a single extended table), making the code unlikely to work for anything beyond -P5 on actual guest images. What's more, the code does not support GPT partitions, which are becoming more popular, and maintaining device subsetting in both NBD and the raw device is unnecessary duplication of effort (even if it is not too difficult). Note that obtaining the offsets of a partition (MBR or GPT) can be learned by using 'qemu-nbd -c /dev/nbd0 file.qcow2 && sfdisk --dump /dev/nbd0', but by the time you've done that, you might as well just mount /dev/nbd0p1 that the kernel creates for you instead of bothering with qemu exporting a subset. Or, keeping to just user-space code, use nbdkit's partition filter, which has already known both GPT and primary MBR partitions for a while, and was just recently enhanced to support arbitrary logical MBR parititions. Start the clock on the deprecation cycle, with examples of how to accomplish device subsetting without using -P. Signed-off-by: Eric Blake Message-Id: <20190125234837.2272-1-eblake@redhat.com> Reviewed-by: Richard W.M. Jones Reviewed-by: Stefano Garzarella --- qemu-deprecated.texi | 33 +++++++++++++++++++++++++++++++++ qemu-nbd.texi | 6 ++++-- qemu-nbd.c | 2 ++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index 9cc20b365c5..8a6174df0c1 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -160,3 +160,36 @@ Example of legacy encoding: The above, converted to the current supported format: @code{json:@{"file.driver":"rbd", "file.pool":"rbd", "file.image":"name"@}} + +@section Related binaries + +@subsection qemu-nbd --partition (since 4.0.0) + +The ``qemu-nbd --partition $digit'' code (also spelled @option{-P}) +can only handle MBR partitions, and has never correctly handled +logical partitions beyond partition 5. If you know the offset and +length of the partition (perhaps by using @code{sfdisk} within the +guest), you can achieve the effect of exporting just that subset of +the disk by use of the @option{--image-opts} option with a raw +blockdev using the @code{offset} and @code{size} parameters layered on +top of any other existing blockdev. For example, if partition 1 is +100MiB long starting at 1MiB, the old command: + +@code{qemu-nbd -t -P 1 -f qcow2 file.qcow2} + +can be rewritten as: + +@code{qemu-nbd -t --image-opts driver=3Draw,offset=3D1M,size=3D100M,file.d= river=3Dqcow2,file.backing.driver=3Dfile,file.backing.filename=3Dfile.qcow2} + +Alternatively, the @code{nbdkit} project provides a more powerful +partition filter on top of its nbd plugin, which can be used to select +an arbitrary MBR or GPT partition on top of any other full-image NBD +export. Using this to rewrite the above example results in: + +@code{qemu-nbd -t -k /tmp/sock -f qcow2 file.qcow2 &} +@code{nbdkit -f --filter=3Dpartition nbd socket=3D/tmp/sock partition=3D1} + +Note that if you are exposing the export via /dev/nbd0, it is easier +to just export the entire image and then mount only /dev/nbd0p1 than +it is to reinvoke @command{qemu-nbd -c /dev/nbd0} limited to just a +subset of the image. diff --git a/qemu-nbd.texi b/qemu-nbd.texi index 386bece4680..d0c51828149 100644 --- a/qemu-nbd.texi +++ b/qemu-nbd.texi @@ -56,8 +56,10 @@ auto-detecting. @item -r, --read-only Export the disk as read-only. @item -P, --partition=3D@var{num} -Only expose MBR partition @var{num}. Understands physical partitions -1-4 and logical partitions 5-8. +Deprecated: Only expose MBR partition @var{num}. Understands physical +partitions 1-4 and logical partition 5. New code should instead use +@option{--image-opts} with the raw driver wrapping a subset of the +original image. @item -B, --bitmap=3D@var{name} If @var{filename} has a qcow2 persistent bitmap @var{name}, expose that bitmap via the ``qemu:dirty-bitmap:@var{name}'' context diff --git a/qemu-nbd.c b/qemu-nbd.c index 1f7b2a03f5d..00c07fd27ea 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -787,6 +787,8 @@ int main(int argc, char **argv) flags &=3D ~BDRV_O_RDWR; break; case 'P': + warn_report("The '-P' option is deprecated; use --image-opts w= ith " + "a raw device wrapper for subset exports instead"); if (qemu_strtoi(optarg, NULL, 0, &partition) < 0 || partition < 1 || partition > 8) { error_report("Invalid partition '%s'", optarg); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 09:16:58 2024 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549339346318138.16723118083803; Mon, 4 Feb 2019 20:02:26 -0800 (PST) Received: from localhost ([127.0.0.1]:53677 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrwA-0004Fm-3V for importer@patchew.org; Mon, 04 Feb 2019 23:02:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrrM-0000gd-Bg for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqrrJ-0002p6-TO for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56164) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqrrF-0002m4-AG; Mon, 04 Feb 2019 22:57:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AEB8E6A8C; Tue, 5 Feb 2019 03:57:12 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-162.phx2.redhat.com [10.3.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1AAE5C57C; Tue, 5 Feb 2019 03:57:11 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 21:56:58 -0600 Message-Id: <20190205035704.26014-3-eblake@redhat.com> In-Reply-To: <20190205035704.26014-1-eblake@redhat.com> References: <20190205035704.26014-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 05 Feb 2019 03:57:12 +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 2/8] nbd: generalize usage of nbd_read 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 , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We generally do very similar things around nbd_read: error_prepend specifying what we have tried to read, and be_to_cpu conversion of integers. So, it seems reasonable to move common things to helper functions, which: 1. simplify code a bit 2. generalize nbd_read error descriptions, all starting with "Failed to read" 3. make it more difficult to forget to convert things from BE Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190128165830.165170-1-vsementsov@virtuozzo.com> [eblake: rename macro to DEF_NBD_READ_N and formatting tweaks; checkpatch has false positive complaint] Signed-off-by: Eric Blake --- include/block/nbd.h | 32 +++++++++++++++-- block/nbd-client.c | 5 ++- nbd/client.c | 88 +++++++++++++++------------------------------ nbd/common.c | 2 +- nbd/server.c | 27 +++++--------- 5 files changed, 71 insertions(+), 83 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 4faf394e346..96cfb1d7d5d 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -23,6 +23,7 @@ #include "qapi/qapi-types-block.h" #include "io/channel-socket.h" #include "crypto/tlscreds.h" +#include "qapi/error.h" /* Handshake phase structs - this struct is passed on the wire */ @@ -336,11 +337,38 @@ void nbd_server_start(SocketAddress *addr, const char= *tls_creds, * Reads @size bytes from @ioc. Returns 0 on success. */ static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size, - Error **errp) + const char *desc, Error **errp) { - return qio_channel_read_all(ioc, buffer, size, errp) < 0 ? -EIO : 0; + int ret =3D qio_channel_read_all(ioc, buffer, size, errp) < 0 ? -EIO := 0; + + if (ret < 0) { + if (desc) { + error_prepend(errp, "Failed to read %s: ", desc); + } + return -1; + } + + return 0; } +#define DEF_NBD_READ_N(bits) \ +static inline int nbd_read##bits(QIOChannel *ioc, \ + uint##bits##_t *val, \ + const char *desc, Error **errp) \ +{ \ + if (nbd_read(ioc, val, sizeof(*val), desc, errp) < 0) { \ + return -1; \ + } \ + *val =3D be##bits##_to_cpu(*val); \ + return 0; \ +} + +DEF_NBD_READ_N(16) /* Defines nbd_read16(). */ +DEF_NBD_READ_N(32) /* Defines nbd_read32(). */ +DEF_NBD_READ_N(64) /* Defines nbd_read64(). */ + +#undef DEF_NBD_READ_N + static inline bool nbd_reply_is_simple(NBDReply *reply) { return reply->magic =3D=3D NBD_SIMPLE_REPLY_MAGIC; diff --git a/block/nbd-client.c b/block/nbd-client.c index 50a8dadd852..57f679ad4d0 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -338,10 +338,9 @@ static int nbd_co_receive_offset_data_payload(NBDClien= tSession *s, return -EINVAL; } - if (nbd_read(s->ioc, &offset, sizeof(offset), errp) < 0) { + if (nbd_read64(s->ioc, &offset, "OFFSET_DATA offset", errp) < 0) { return -EIO; } - be64_to_cpus(&offset); data_size =3D chunk->length - sizeof(offset); assert(data_size); @@ -388,7 +387,7 @@ static coroutine_fn int nbd_co_receive_structured_paylo= ad( } *payload =3D g_new(char, len); - ret =3D nbd_read(s->ioc, *payload, len, errp); + ret =3D nbd_read(s->ioc, *payload, len, "structured payload", errp); if (ret < 0) { g_free(*payload); *payload =3D NULL; diff --git a/nbd/client.c b/nbd/client.c index 8a083c2f42c..10a52ad7d0c 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -113,8 +113,7 @@ static int nbd_receive_option_reply(QIOChannel *ioc, ui= nt32_t opt, NBDOptionReply *reply, Error **errp) { QEMU_BUILD_BUG_ON(sizeof(*reply) !=3D 20); - if (nbd_read(ioc, reply, sizeof(*reply), errp) < 0) { - error_prepend(errp, "failed to read option reply: "); + if (nbd_read(ioc, reply, sizeof(*reply), "option reply", errp) < 0) { nbd_send_opt_abort(ioc); return -1; } @@ -166,8 +165,8 @@ static int nbd_handle_reply_err(QIOChannel *ioc, NBDOpt= ionReply *reply, goto cleanup; } msg =3D g_malloc(reply->length + 1); - if (nbd_read(ioc, msg, reply->length, errp) < 0) { - error_prepend(errp, "failed to read option error %" PRIu32 + if (nbd_read(ioc, msg, reply->length, NULL, errp) < 0) { + error_prepend(errp, "Failed to read option error %" PRIu32 " (%s) message: ", reply->type, nbd_rep_lookup(reply->type)); goto cleanup; @@ -284,12 +283,10 @@ static int nbd_receive_list(QIOChannel *ioc, char **n= ame, char **description, nbd_send_opt_abort(ioc); return -1; } - if (nbd_read(ioc, &namelen, sizeof(namelen), errp) < 0) { - error_prepend(errp, "failed to read option name length: "); + if (nbd_read32(ioc, &namelen, "option name length", errp) < 0) { nbd_send_opt_abort(ioc); return -1; } - namelen =3D be32_to_cpu(namelen); len -=3D sizeof(namelen); if (len < namelen) { error_setg(errp, "incorrect option name length"); @@ -298,8 +295,7 @@ static int nbd_receive_list(QIOChannel *ioc, char **nam= e, char **description, } local_name =3D g_malloc(namelen + 1); - if (nbd_read(ioc, local_name, namelen, errp) < 0) { - error_prepend(errp, "failed to read export name: "); + if (nbd_read(ioc, local_name, namelen, "export name", errp) < 0) { nbd_send_opt_abort(ioc); goto out; } @@ -307,8 +303,7 @@ static int nbd_receive_list(QIOChannel *ioc, char **nam= e, char **description, len -=3D namelen; if (len) { local_desc =3D g_malloc(len + 1); - if (nbd_read(ioc, local_desc, len, errp) < 0) { - error_prepend(errp, "failed to read export description: "); + if (nbd_read(ioc, local_desc, len, "export description", errp) < 0= ) { nbd_send_opt_abort(ioc); goto out; } @@ -410,13 +405,11 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32= _t opt, nbd_send_opt_abort(ioc); return -1; } - if (nbd_read(ioc, &type, sizeof(type), errp) < 0) { - error_prepend(errp, "failed to read info type: "); + if (nbd_read16(ioc, &type, "info type", errp) < 0) { nbd_send_opt_abort(ioc); return -1; } len -=3D sizeof(type); - type =3D be16_to_cpu(type); switch (type) { case NBD_INFO_EXPORT: if (len !=3D sizeof(info->size) + sizeof(info->flags)) { @@ -425,18 +418,14 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32= _t opt, nbd_send_opt_abort(ioc); return -1; } - if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) { - error_prepend(errp, "failed to read info size: "); + if (nbd_read64(ioc, &info->size, "info size", errp) < 0) { nbd_send_opt_abort(ioc); return -1; } - 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: "); + if (nbd_read16(ioc, &info->flags, "info flags", errp) < 0) { nbd_send_opt_abort(ioc); return -1; } - info->flags =3D be16_to_cpu(info->flags); trace_nbd_receive_negotiate_size_flags(info->size, info->flags= ); break; @@ -447,27 +436,23 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32= _t opt, nbd_send_opt_abort(ioc); return -1; } - if (nbd_read(ioc, &info->min_block, sizeof(info->min_block), - errp) < 0) { - error_prepend(errp, "failed to read info minimum block siz= e: "); + if (nbd_read32(ioc, &info->min_block, "info minimum block size= ", + errp) < 0) { nbd_send_opt_abort(ioc); return -1; } - 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); nbd_send_opt_abort(ioc); return -1; } - if (nbd_read(ioc, &info->opt_block, sizeof(info->opt_block), - errp) < 0) { - error_prepend(errp, - "failed to read info preferred block size: "= ); + if (nbd_read32(ioc, &info->opt_block, "info preferred block si= ze", + errp) < 0) + { nbd_send_opt_abort(ioc); return -1; } - 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 @@ -475,13 +460,12 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32= _t opt, nbd_send_opt_abort(ioc); return -1; } - if (nbd_read(ioc, &info->max_block, sizeof(info->max_block), - errp) < 0) { - error_prepend(errp, "failed to read info maximum block siz= e: "); + if (nbd_read32(ioc, &info->max_block, "info maximum block size= ", + errp) < 0) + { nbd_send_opt_abort(ioc); return -1; } - 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); @@ -731,14 +715,13 @@ static int nbd_receive_one_meta_context(QIOChannel *i= oc, return -1; } - if (nbd_read(ioc, &local_id, sizeof(local_id), errp) < 0) { + if (nbd_read32(ioc, &local_id, "context id", errp) < 0) { return -1; } - local_id =3D be32_to_cpu(local_id); reply.length -=3D sizeof(local_id); local_name =3D g_malloc(reply.length + 1); - if (nbd_read(ioc, local_name, reply.length, errp) < 0) { + if (nbd_read(ioc, local_name, reply.length, "context name", errp) < 0)= { g_free(local_name); return -1; } @@ -896,11 +879,9 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCrypt= oTLSCreds *tlscreds, return -EINVAL; } - if (nbd_read(ioc, &magic, sizeof(magic), errp) < 0) { - error_prepend(errp, "Failed to read initial magic: "); + if (nbd_read64(ioc, &magic, "initial magic", errp) < 0) { return -EINVAL; } - magic =3D be64_to_cpu(magic); trace_nbd_receive_negotiate_magic(magic); if (magic !=3D NBD_INIT_MAGIC) { @@ -908,11 +889,9 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCrypt= oTLSCreds *tlscreds, return -EINVAL; } - if (nbd_read(ioc, &magic, sizeof(magic), errp) < 0) { - error_prepend(errp, "Failed to read server magic: "); + if (nbd_read64(ioc, &magic, "server magic", errp) < 0) { return -EINVAL; } - magic =3D be64_to_cpu(magic); trace_nbd_receive_negotiate_magic(magic); if (magic =3D=3D NBD_OPTS_MAGIC) { @@ -920,11 +899,9 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCrypt= oTLSCreds *tlscreds, uint16_t globalflags; bool fixedNewStyle =3D false; - if (nbd_read(ioc, &globalflags, sizeof(globalflags), errp) < 0) { - error_prepend(errp, "Failed to read server flags: "); + if (nbd_read16(ioc, &globalflags, "server flags", errp) < 0) { return -EINVAL; } - globalflags =3D be16_to_cpu(globalflags); trace_nbd_receive_negotiate_server_flags(globalflags); if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) { fixedNewStyle =3D true; @@ -992,17 +969,13 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel *= ioc, NBDExportInfo *info, { uint32_t oldflags; - if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) { - error_prepend(errp, "Failed to read export length: "); + if (nbd_read64(ioc, &info->size, "export length", errp) < 0) { return -EINVAL; } - 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: "); + if (nbd_read32(ioc, &oldflags, "export flags", errp) < 0) { return -EINVAL; } - oldflags =3D be32_to_cpu(oldflags); if (oldflags & ~0xffff) { error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflags); return -EINVAL; @@ -1079,17 +1052,13 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, } /* Read the response */ - if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) { - error_prepend(errp, "Failed to read export length: "); + if (nbd_read64(ioc, &info->size, "export length", errp) < 0) { return -EINVAL; } - 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: "); + if (nbd_read16(ioc, &info->flags, "export flags", errp) < 0) { return -EINVAL; } - info->flags =3D be16_to_cpu(info->flags); break; case 0: /* oldstyle, parse length and flags */ if (*info->name) { @@ -1379,7 +1348,7 @@ static int nbd_receive_simple_reply(QIOChannel *ioc, = NBDSimpleReply *reply, assert(reply->magic =3D=3D NBD_SIMPLE_REPLY_MAGIC); ret =3D nbd_read(ioc, (uint8_t *)reply + sizeof(reply->magic), - sizeof(*reply) - sizeof(reply->magic), errp); + sizeof(*reply) - sizeof(reply->magic), "reply", errp); if (ret < 0) { return ret; } @@ -1404,7 +1373,8 @@ static int nbd_receive_structured_reply_chunk(QIOChan= nel *ioc, assert(chunk->magic =3D=3D NBD_STRUCTURED_REPLY_MAGIC); ret =3D nbd_read(ioc, (uint8_t *)chunk + sizeof(chunk->magic), - sizeof(*chunk) - sizeof(chunk->magic), errp); + sizeof(*chunk) - sizeof(chunk->magic), "structured chun= k", + errp); if (ret < 0) { return ret; } diff --git a/nbd/common.c b/nbd/common.c index 41f5ed8d9fa..cc8b278e541 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -31,7 +31,7 @@ int nbd_drop(QIOChannel *ioc, size_t size, Error **errp) buffer =3D sizeof(small) >=3D size ? small : g_malloc(MIN(65536, size)= ); while (size > 0) { ssize_t count =3D MIN(65536, size); - ret =3D nbd_read(ioc, buffer, MIN(65536, size), errp); + ret =3D nbd_read(ioc, buffer, MIN(65536, size), NULL, errp); if (ret < 0) { goto cleanup; diff --git a/nbd/server.c b/nbd/server.c index cb0d5634fa1..838c150d8ca 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -438,8 +438,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, error_setg(errp, "Bad length received"); return -EINVAL; } - if (nbd_read(client->ioc, name, client->optlen, errp) < 0) { - error_prepend(errp, "read failed: "); + if (nbd_read(client->ioc, name, client->optlen, "export name", errp) <= 0) { return -EIO; } name[client->optlen] =3D '\0'; @@ -1046,11 +1045,9 @@ static int nbd_negotiate_options(NBDClient *client, = uint16_t myflags, ... Rest of request */ - if (nbd_read(client->ioc, &flags, sizeof(flags), errp) < 0) { - error_prepend(errp, "read failed: "); + if (nbd_read32(client->ioc, &flags, "flags", errp) < 0) { return -EIO; } - flags =3D be32_to_cpu(flags); trace_nbd_negotiate_options_flags(flags); if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) { fixedNewstyle =3D true; @@ -1070,30 +1067,23 @@ static int nbd_negotiate_options(NBDClient *client,= uint16_t myflags, uint32_t option, length; uint64_t magic; - if (nbd_read(client->ioc, &magic, sizeof(magic), errp) < 0) { - error_prepend(errp, "read failed: "); + if (nbd_read64(client->ioc, &magic, "opts magic", errp) < 0) { return -EINVAL; } - magic =3D be64_to_cpu(magic); trace_nbd_negotiate_options_check_magic(magic); if (magic !=3D NBD_OPTS_MAGIC) { error_setg(errp, "Bad magic received"); return -EINVAL; } - if (nbd_read(client->ioc, &option, - sizeof(option), errp) < 0) { - error_prepend(errp, "read failed: "); + if (nbd_read32(client->ioc, &option, "option", errp) < 0) { return -EINVAL; } - option =3D be32_to_cpu(option); client->opt =3D option; - if (nbd_read(client->ioc, &length, sizeof(length), errp) < 0) { - error_prepend(errp, "read failed: "); + if (nbd_read32(client->ioc, &length, "option length", errp) < 0) { return -EINVAL; } - length =3D be32_to_cpu(length); assert(!client->optlen); client->optlen =3D length; @@ -1306,7 +1296,7 @@ static int nbd_receive_request(QIOChannel *ioc, NBDRe= quest *request, uint32_t magic; int ret; - ret =3D nbd_read(ioc, buf, sizeof(buf), errp); + ret =3D nbd_read(ioc, buf, sizeof(buf), "request", errp); if (ret < 0) { return ret; } @@ -2111,8 +2101,9 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, } } if (request->type =3D=3D NBD_CMD_WRITE) { - if (nbd_read(client->ioc, req->data, request->len, errp) < 0) { - error_prepend(errp, "reading from socket failed: "); + if (nbd_read(client->ioc, req->data, request->len, "CMD_WRITE data= ", + errp) < 0) + { return -EIO; } req->complete =3D true; --=20 2.20.1 From nobody Sun May 5 09:16:58 2024 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549339350625249.09330667801657; Mon, 4 Feb 2019 20:02:30 -0800 (PST) Received: from localhost ([127.0.0.1]:53679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrwG-0004L1-Ht for importer@patchew.org; Mon, 04 Feb 2019 23:02:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrrL-0000gR-AR for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqrrJ-0002oc-A6 for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqrrG-0002mE-0G; Mon, 04 Feb 2019 22:57:14 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 520FF356D4; Tue, 5 Feb 2019 03:57:13 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-162.phx2.redhat.com [10.3.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD3325C57C; Tue, 5 Feb 2019 03:57:12 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 21:56:59 -0600 Message-Id: <20190205035704.26014-4-eblake@redhat.com> In-Reply-To: <20190205035704.26014-1-eblake@redhat.com> References: <20190205035704.26014-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 05 Feb 2019 03:57:13 +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 3/8] block/nbd-client: split channel errors from export errors 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 , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy To implement nbd reconnect in further patches, we need to distinguish error codes, returned by nbd server, from channel errors, to reconnect only in the latter case. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190201130138.94525-2-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 83 ++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 57f679ad4d0..fd58cda2f17 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -504,11 +504,11 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( */ static coroutine_fn int nbd_co_receive_one_chunk( NBDClientSession *s, uint64_t handle, bool only_structured, - QEMUIOVector *qiov, NBDReply *reply, void **payload, Error **errp) + int *request_ret, QEMUIOVector *qiov, NBDReply *reply, void **payl= oad, + Error **errp) { - int request_ret; int ret =3D nbd_co_do_receive_one_chunk(s, handle, only_structured, - &request_ret, qiov, payload, err= p); + request_ret, qiov, payload, errp= ); if (ret < 0) { s->quit =3D true; @@ -518,7 +518,6 @@ static coroutine_fn int nbd_co_receive_one_chunk( *reply =3D s->reply; } s->reply.handle =3D 0; - ret =3D request_ret; } if (s->read_reply_co) { @@ -530,22 +529,17 @@ static coroutine_fn int nbd_co_receive_one_chunk( typedef struct NBDReplyChunkIter { int ret; - bool fatal; + int request_ret; Error *err; bool done, only_structured; } NBDReplyChunkIter; -static void nbd_iter_error(NBDReplyChunkIter *iter, bool fatal, - int ret, Error **local_err) +static void nbd_iter_channel_error(NBDReplyChunkIter *iter, + int ret, Error **local_err) { assert(ret < 0); - if ((fatal && !iter->fatal) || iter->ret =3D=3D 0) { - if (iter->ret !=3D 0) { - error_free(iter->err); - iter->err =3D NULL; - } - iter->fatal =3D fatal; + if (!iter->ret) { iter->ret =3D ret; error_propagate(&iter->err, *local_err); } else { @@ -555,6 +549,15 @@ static void nbd_iter_error(NBDReplyChunkIter *iter, bo= ol fatal, *local_err =3D NULL; } +static void nbd_iter_request_error(NBDReplyChunkIter *iter, int ret) +{ + assert(ret < 0); + + if (!iter->request_ret) { + iter->request_ret =3D ret; + } +} + /* NBD_FOREACH_REPLY_CHUNK */ #define NBD_FOREACH_REPLY_CHUNK(s, iter, handle, structured, \ @@ -570,13 +573,13 @@ static bool nbd_reply_chunk_iter_receive(NBDClientSes= sion *s, QEMUIOVector *qiov, NBDReply *rep= ly, void **payload) { - int ret; + int ret, request_ret; NBDReply local_reply; NBDStructuredReplyChunk *chunk; Error *local_err =3D NULL; if (s->quit) { error_setg(&local_err, "Connection closed"); - nbd_iter_error(iter, true, -EIO, &local_err); + nbd_iter_channel_error(iter, -EIO, &local_err); goto break_loop; } @@ -590,10 +593,12 @@ static bool nbd_reply_chunk_iter_receive(NBDClientSes= sion *s, } ret =3D nbd_co_receive_one_chunk(s, handle, iter->only_structured, - qiov, reply, payload, &local_err); + &request_ret, qiov, reply, payload, + &local_err); if (ret < 0) { - /* If it is a fatal error s->quit is set by nbd_co_receive_one_chu= nk */ - nbd_iter_error(iter, s->quit, ret, &local_err); + nbd_iter_channel_error(iter, ret, &local_err); + } else if (request_ret < 0) { + nbd_iter_request_error(iter, request_ret); } /* Do not execute the body of NBD_FOREACH_REPLY_CHUNK for simple reply= . */ @@ -630,7 +635,7 @@ break_loop: } static int nbd_co_receive_return_code(NBDClientSession *s, uint64_t handle, - Error **errp) + int *request_ret, Error **errp) { NBDReplyChunkIter iter; @@ -639,12 +644,13 @@ static int nbd_co_receive_return_code(NBDClientSessio= n *s, uint64_t handle, } error_propagate(errp, iter.err); + *request_ret =3D iter.request_ret; return iter.ret; } static int nbd_co_receive_cmdread_reply(NBDClientSession *s, uint64_t hand= le, uint64_t offset, QEMUIOVector *qio= v, - Error **errp) + int *request_ret, Error **errp) { NBDReplyChunkIter iter; NBDReply reply; @@ -669,7 +675,7 @@ static int nbd_co_receive_cmdread_reply(NBDClientSessio= n *s, uint64_t handle, offset, qiov, &local_err); if (ret < 0) { s->quit =3D true; - nbd_iter_error(&iter, true, ret, &local_err); + nbd_iter_channel_error(&iter, ret, &local_err); } break; default: @@ -679,7 +685,7 @@ static int nbd_co_receive_cmdread_reply(NBDClientSessio= n *s, uint64_t handle, error_setg(&local_err, "Unexpected reply type: %d (%s) for CMD_READ", chunk->type, nbd_reply_type_lookup(chunk->type)= ); - nbd_iter_error(&iter, true, -EINVAL, &local_err); + nbd_iter_channel_error(&iter, -EINVAL, &local_err); } } @@ -688,12 +694,14 @@ static int nbd_co_receive_cmdread_reply(NBDClientSess= ion *s, uint64_t handle, } error_propagate(errp, iter.err); + *request_ret =3D iter.request_ret; return iter.ret; } static int nbd_co_receive_blockstatus_reply(NBDClientSession *s, uint64_t handle, uint64_t leng= th, - NBDExtent *extent, Error **err= p) + NBDExtent *extent, + int *request_ret, Error **errp) { NBDReplyChunkIter iter; NBDReply reply; @@ -715,7 +723,7 @@ static int nbd_co_receive_blockstatus_reply(NBDClientSe= ssion *s, if (received) { s->quit =3D true; error_setg(&local_err, "Several BLOCK_STATUS chunks in rep= ly"); - nbd_iter_error(&iter, true, -EINVAL, &local_err); + nbd_iter_channel_error(&iter, -EINVAL, &local_err); } received =3D true; @@ -724,7 +732,7 @@ static int nbd_co_receive_blockstatus_reply(NBDClientSe= ssion *s, &local_err); if (ret < 0) { s->quit =3D true; - nbd_iter_error(&iter, true, ret, &local_err); + nbd_iter_channel_error(&iter, ret, &local_err); } break; default: @@ -734,7 +742,7 @@ static int nbd_co_receive_blockstatus_reply(NBDClientSe= ssion *s, "Unexpected reply type: %d (%s) " "for CMD_BLOCK_STATUS", chunk->type, nbd_reply_type_lookup(chunk->type)= ); - nbd_iter_error(&iter, true, -EINVAL, &local_err); + nbd_iter_channel_error(&iter, -EINVAL, &local_err); } } @@ -749,14 +757,16 @@ static int nbd_co_receive_blockstatus_reply(NBDClient= Session *s, iter.ret =3D -EIO; } } + error_propagate(errp, iter.err); + *request_ret =3D iter.request_ret; return iter.ret; } static int nbd_co_request(BlockDriverState *bs, NBDRequest *request, QEMUIOVector *write_qiov) { - int ret; + int ret, request_ret; Error *local_err =3D NULL; NBDClientSession *client =3D nbd_get_client_session(bs); @@ -772,7 +782,8 @@ static int nbd_co_request(BlockDriverState *bs, NBDRequ= est *request, return ret; } - ret =3D nbd_co_receive_return_code(client, request->handle, &local_err= ); + ret =3D nbd_co_receive_return_code(client, request->handle, + &request_ret, &local_err); if (local_err) { trace_nbd_co_request_fail(request->from, request->len, request->ha= ndle, request->flags, request->type, @@ -780,13 +791,13 @@ static int nbd_co_request(BlockDriverState *bs, NBDRe= quest *request, ret, error_get_pretty(local_err)); error_free(local_err); } - return ret; + return ret ? ret : request_ret; } int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { - int ret; + int ret, request_ret; Error *local_err =3D NULL; NBDClientSession *client =3D nbd_get_client_session(bs); NBDRequest request =3D { @@ -807,7 +818,7 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t= offset, } ret =3D nbd_co_receive_cmdread_reply(client, request.handle, offset, q= iov, - &local_err); + &request_ret, &local_err); if (local_err) { trace_nbd_co_request_fail(request.from, request.len, request.handl= e, request.flags, request.type, @@ -815,7 +826,7 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t= offset, ret, error_get_pretty(local_err)); error_free(local_err); } - return ret; + return ret ? ret : request_ret; } int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, @@ -909,7 +920,7 @@ int coroutine_fn nbd_client_co_block_status(BlockDriver= State *bs, int64_t *pnum, int64_t *map, BlockDriverState **file) { - int64_t ret; + int ret, request_ret; NBDExtent extent =3D { 0 }; NBDClientSession *client =3D nbd_get_client_session(bs); Error *local_err =3D NULL; @@ -934,7 +945,7 @@ int coroutine_fn nbd_client_co_block_status(BlockDriver= State *bs, } ret =3D nbd_co_receive_blockstatus_reply(client, request.handle, bytes, - &extent, &local_err); + &extent, &request_ret, &local_e= rr); if (local_err) { trace_nbd_co_request_fail(request.from, request.len, request.handl= e, request.flags, request.type, @@ -942,8 +953,8 @@ int coroutine_fn nbd_client_co_block_status(BlockDriver= State *bs, ret, error_get_pretty(local_err)); error_free(local_err); } - if (ret < 0) { - return ret; + if (ret < 0 || request_ret < 0) { + return ret ? ret : request_ret; } assert(extent.length); --=20 2.20.1 From nobody Sun May 5 09:16:58 2024 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549339354303943.8525349337104; Mon, 4 Feb 2019 20:02:34 -0800 (PST) Received: from localhost ([127.0.0.1]:53681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrwP-0004R7-A8 for importer@patchew.org; Mon, 04 Feb 2019 23:02:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrrL-0000gQ-7Q for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqrrJ-0002on-Jr for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqrrG-0002my-Vn; Mon, 04 Feb 2019 22:57:15 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45FC98762D; Tue, 5 Feb 2019 03:57:14 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-162.phx2.redhat.com [10.3.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 791105C57C; Tue, 5 Feb 2019 03:57:13 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 21:57:00 -0600 Message-Id: <20190205035704.26014-5-eblake@redhat.com> In-Reply-To: <20190205035704.26014-1-eblake@redhat.com> References: <20190205035704.26014-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 05 Feb 2019 03:57:14 +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 4/8] block/nbd: move connection code from block/nbd to block/nbd-client 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 , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Keep all connection code in one file, to be able to implement reconnect in further patches. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20190201130138.94525-3-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: format tweak] Signed-off-by: Eric Blake --- block/nbd-client.h | 2 +- block/nbd-client.c | 38 ++++++++++++++++++++++++++++++++++++-- block/nbd.c | 40 ++-------------------------------------- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/block/nbd-client.h b/block/nbd-client.h index cfc90550b99..2f047ba6142 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -41,7 +41,7 @@ typedef struct NBDClientSession { NBDClientSession *nbd_get_client_session(BlockDriverState *bs); int nbd_client_init(BlockDriverState *bs, - QIOChannelSocket *sock, + SocketAddress *saddr, const char *export_name, QCryptoTLSCreds *tlscreds, const char *hostname, diff --git a/block/nbd-client.c b/block/nbd-client.c index fd58cda2f17..80dc8cff473 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -991,8 +991,29 @@ void nbd_client_close(BlockDriverState *bs) nbd_teardown_connection(bs); } +static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr, + Error **errp) +{ + QIOChannelSocket *sioc; + Error *local_err =3D NULL; + + sioc =3D qio_channel_socket_new(); + qio_channel_set_name(QIO_CHANNEL(sioc), "nbd-client"); + + qio_channel_socket_connect_sync(sioc, saddr, &local_err); + if (local_err) { + object_unref(OBJECT(sioc)); + error_propagate(errp, local_err); + return NULL; + } + + qio_channel_set_delay(QIO_CHANNEL(sioc), false); + + return sioc; +} + int nbd_client_init(BlockDriverState *bs, - QIOChannelSocket *sioc, + SocketAddress *saddr, const char *export, QCryptoTLSCreds *tlscreds, const char *hostname, @@ -1002,6 +1023,16 @@ int nbd_client_init(BlockDriverState *bs, NBDClientSession *client =3D nbd_get_client_session(bs); int ret; + /* + * establish TCP connection, return error if it fails + * TODO: Configurable retry-until-timeout behaviour. + */ + QIOChannelSocket *sioc =3D nbd_establish_connection(saddr, errp); + + if (!sioc) { + return -ECONNREFUSED; + } + /* NBD handshake */ logout("session init %s\n", export); qio_channel_set_blocking(QIO_CHANNEL(sioc), true, NULL); @@ -1017,6 +1048,7 @@ int nbd_client_init(BlockDriverState *bs, g_free(client->info.name); if (ret < 0) { logout("Failed to negotiate with the NBD server\n"); + object_unref(OBJECT(sioc)); return ret; } if (x_dirty_bitmap && !client->info.base_allocation) { @@ -1042,7 +1074,6 @@ int nbd_client_init(BlockDriverState *bs, qemu_co_mutex_init(&client->send_mutex); qemu_co_queue_init(&client->free_sema); client->sioc =3D sioc; - object_ref(OBJECT(client->sioc)); if (!client->ioc) { client->ioc =3D QIO_CHANNEL(sioc); @@ -1068,6 +1099,9 @@ int nbd_client_init(BlockDriverState *bs, NBDRequest request =3D { .type =3D NBD_CMD_DISC }; nbd_send_request(client->ioc ?: QIO_CHANNEL(sioc), &request); + + object_unref(OBJECT(sioc)); + return ret; } } diff --git a/block/nbd.c b/block/nbd.c index e87699fb73b..9db5eded892 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -295,30 +295,6 @@ NBDClientSession *nbd_get_client_session(BlockDriverSt= ate *bs) return &s->client; } -static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr, - Error **errp) -{ - QIOChannelSocket *sioc; - Error *local_err =3D NULL; - - sioc =3D qio_channel_socket_new(); - qio_channel_set_name(QIO_CHANNEL(sioc), "nbd-client"); - - qio_channel_socket_connect_sync(sioc, - saddr, - &local_err); - if (local_err) { - object_unref(OBJECT(sioc)); - error_propagate(errp, local_err); - return NULL; - } - - qio_channel_set_delay(QIO_CHANNEL(sioc), false); - - return sioc; -} - - static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp) { Object *obj; @@ -394,7 +370,6 @@ static int nbd_open(BlockDriverState *bs, QDict *option= s, int flags, BDRVNBDState *s =3D bs->opaque; QemuOpts *opts =3D NULL; Error *local_err =3D NULL; - QIOChannelSocket *sioc =3D NULL; QCryptoTLSCreds *tlscreds =3D NULL; const char *hostname =3D NULL; int ret =3D -EINVAL; @@ -434,22 +409,11 @@ static int nbd_open(BlockDriverState *bs, QDict *opti= ons, int flags, hostname =3D s->saddr->u.inet.host; } - /* establish TCP connection, return error if it fails - * TODO: Configurable retry-until-timeout behaviour. - */ - sioc =3D nbd_establish_connection(s->saddr, errp); - if (!sioc) { - ret =3D -ECONNREFUSED; - goto error; - } - /* NBD handshake */ - ret =3D nbd_client_init(bs, sioc, s->export, tlscreds, hostname, + ret =3D nbd_client_init(bs, s->saddr, s->export, tlscreds, hostname, qemu_opt_get(opts, "x-dirty-bitmap"), errp); + error: - if (sioc) { - object_unref(OBJECT(sioc)); - } if (tlscreds) { object_unref(OBJECT(tlscreds)); } --=20 2.20.1 From nobody Sun May 5 09:16:58 2024 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549339190975623.1924769440095; Mon, 4 Feb 2019 19:59:50 -0800 (PST) Received: from localhost ([127.0.0.1]:53617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrth-0002CW-0Y for importer@patchew.org; Mon, 04 Feb 2019 22:59:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrrL-0000gP-4T for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqrrJ-0002p1-SB for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqrrH-0002nB-IX; Mon, 04 Feb 2019 22:57:15 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DAADAC059B80; Tue, 5 Feb 2019 03:57:14 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-162.phx2.redhat.com [10.3.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61F925C57C; Tue, 5 Feb 2019 03:57:14 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 21:57:01 -0600 Message-Id: <20190205035704.26014-6-eblake@redhat.com> In-Reply-To: <20190205035704.26014-1-eblake@redhat.com> References: <20190205035704.26014-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 05 Feb 2019 03:57:14 +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 5/8] block/nbd-client: split connection from initialization 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 , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Split connection code to reuse it for reconnect. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190201130138.94525-4-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 80dc8cff473..d7d88297698 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -1012,13 +1012,13 @@ static QIOChannelSocket *nbd_establish_connection(S= ocketAddress *saddr, return sioc; } -int nbd_client_init(BlockDriverState *bs, - SocketAddress *saddr, - const char *export, - QCryptoTLSCreds *tlscreds, - const char *hostname, - const char *x_dirty_bitmap, - Error **errp) +static int nbd_client_connect(BlockDriverState *bs, + SocketAddress *saddr, + const char *export, + QCryptoTLSCreds *tlscreds, + const char *hostname, + const char *x_dirty_bitmap, + Error **errp) { NBDClientSession *client =3D nbd_get_client_session(bs); int ret; @@ -1071,8 +1071,6 @@ int nbd_client_init(BlockDriverState *bs, bs->supported_zero_flags |=3D BDRV_REQ_MAY_UNMAP; } - qemu_co_mutex_init(&client->send_mutex); - qemu_co_queue_init(&client->free_sema); client->sioc =3D sioc; if (!client->ioc) { @@ -1105,3 +1103,20 @@ int nbd_client_init(BlockDriverState *bs, return ret; } } + +int nbd_client_init(BlockDriverState *bs, + SocketAddress *saddr, + const char *export, + QCryptoTLSCreds *tlscreds, + const char *hostname, + const char *x_dirty_bitmap, + Error **errp) +{ + NBDClientSession *client =3D nbd_get_client_session(bs); + + qemu_co_mutex_init(&client->send_mutex); + qemu_co_queue_init(&client->free_sema); + + return nbd_client_connect(bs, saddr, export, tlscreds, hostname, + x_dirty_bitmap, errp); +} --=20 2.20.1 From nobody Sun May 5 09:16:58 2024 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 1549339176587189.2687746378541; Mon, 4 Feb 2019 19:59:36 -0800 (PST) Received: from localhost ([127.0.0.1]:53615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrtX-00025A-GB for importer@patchew.org; Mon, 04 Feb 2019 22:59:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrrL-0000gS-AP for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqrrK-0002pa-2k for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51924) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqrrI-0002nZ-60; Mon, 04 Feb 2019 22:57:16 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7872F85A07; Tue, 5 Feb 2019 03:57:15 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-162.phx2.redhat.com [10.3.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0477968D48; Tue, 5 Feb 2019 03:57:14 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 21:57:02 -0600 Message-Id: <20190205035704.26014-7-eblake@redhat.com> In-Reply-To: <20190205035704.26014-1-eblake@redhat.com> References: <20190205035704.26014-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 05 Feb 2019 03:57:15 +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 6/8] block/nbd-client: fix nbd_reply_chunk_iter_receive 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 , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Use exported report, not the variable to be reused (should not really matter). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190201130138.94525-5-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index d7d88297698..65e56000681 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -602,7 +602,7 @@ static bool nbd_reply_chunk_iter_receive(NBDClientSessi= on *s, } /* Do not execute the body of NBD_FOREACH_REPLY_CHUNK for simple reply= . */ - if (nbd_reply_is_simple(&s->reply) || s->quit) { + if (nbd_reply_is_simple(reply) || s->quit) { goto break_loop; } --=20 2.20.1 From nobody Sun May 5 09:16:58 2024 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549339522081445.01000905500314; Mon, 4 Feb 2019 20:05:22 -0800 (PST) Received: from localhost ([127.0.0.1]:53713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrz1-0006JX-4E for importer@patchew.org; Mon, 04 Feb 2019 23:05:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrrk-000123-D9 for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqrrU-0002w1-AJ for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59356) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqrrO-0002re-R6; Mon, 04 Feb 2019 22:57:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5FA88637EB; Tue, 5 Feb 2019 03:57:20 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-162.phx2.redhat.com [10.3.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBB0B5C8B3; Tue, 5 Feb 2019 03:57:19 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 21:57:03 -0600 Message-Id: <20190205035704.26014-8-eblake@redhat.com> In-Reply-To: <20190205035704.26014-1-eblake@redhat.com> References: <20190205035704.26014-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 05 Feb 2019 03:57:20 +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 7/8] block/nbd-client: don't check ioc 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 , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We have several paranoid checks for ioc !=3D NULL. But ioc may become NULL only on close, which should not happen during requests handling. Also, we check ioc only sometimes, not after each yield, which is inconsistent. Let's drop these checks. However, for safety, let's leave asserts instead. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190201130138.94525-6-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 65e56000681..386c3feb14f 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -53,9 +53,7 @@ static void nbd_teardown_connection(BlockDriverState *bs) { NBDClientSession *client =3D nbd_get_client_session(bs); - if (!client->ioc) { /* Already closed */ - return; - } + assert(client->ioc); /* finish any pending coroutines */ qio_channel_shutdown(client->ioc, @@ -154,10 +152,7 @@ static int nbd_co_send_request(BlockDriverState *bs, rc =3D -EIO; goto err; } - if (!s->ioc) { - rc =3D -EPIPE; - goto err; - } + assert(s->ioc); if (qiov) { qio_channel_set_cork(s->ioc, true); @@ -429,10 +424,11 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( s->requests[i].receiving =3D true; qemu_coroutine_yield(); s->requests[i].receiving =3D false; - if (!s->ioc || s->quit) { + if (s->quit) { error_setg(errp, "Connection closed"); return -EIO; } + assert(s->ioc); assert(s->reply.handle =3D=3D handle); @@ -982,9 +978,7 @@ void nbd_client_close(BlockDriverState *bs) NBDClientSession *client =3D nbd_get_client_session(bs); NBDRequest request =3D { .type =3D NBD_CMD_DISC }; - if (client->ioc =3D=3D NULL) { - return; - } + assert(client->ioc); nbd_send_request(client->ioc, &request); --=20 2.20.1 From nobody Sun May 5 09:16:58 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549339515151391.6627004641622; Mon, 4 Feb 2019 20:05:15 -0800 (PST) Received: from localhost ([127.0.0.1]:53711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqryn-0006BJ-6S for importer@patchew.org; Mon, 04 Feb 2019 23:05:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrrn-00015L-LG for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqrrg-0002zr-7g for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:57:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40040) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqrrQ-0002rp-Cn; Mon, 04 Feb 2019 22:57:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0515081DEC; Tue, 5 Feb 2019 03:57:21 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-162.phx2.redhat.com [10.3.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81D675C57C; Tue, 5 Feb 2019 03:57:20 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 21:57:04 -0600 Message-Id: <20190205035704.26014-9-eblake@redhat.com> In-Reply-To: <20190205035704.26014-1-eblake@redhat.com> References: <20190205035704.26014-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 05 Feb 2019 03:57:21 +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 8/8] block/nbd-client: rename read_reply_co to connection_co 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 , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy This coroutine will serve nbd reconnects, so, rename it to be something more generic. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190201130138.94525-7-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.h | 4 ++-- block/nbd-client.c | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/block/nbd-client.h b/block/nbd-client.h index 2f047ba6142..d990207a5cb 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -20,7 +20,7 @@ typedef struct { Coroutine *coroutine; uint64_t offset; /* original offset of the request */ - bool receiving; /* waiting for read_reply_co? */ + bool receiving; /* waiting for connection_co? */ } NBDClientRequest; typedef struct NBDClientSession { @@ -30,7 +30,7 @@ typedef struct NBDClientSession { CoMutex send_mutex; CoQueue free_sema; - Coroutine *read_reply_co; + Coroutine *connection_co; int in_flight; NBDClientRequest requests[MAX_NBD_REQUESTS]; diff --git a/block/nbd-client.c b/block/nbd-client.c index 386c3feb14f..f0ad54ce21d 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -59,7 +59,7 @@ static void nbd_teardown_connection(BlockDriverState *bs) qio_channel_shutdown(client->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); - BDRV_POLL_WHILE(bs, client->read_reply_co); + BDRV_POLL_WHILE(bs, client->connection_co); nbd_client_detach_aio_context(bs); object_unref(OBJECT(client->sioc)); @@ -68,7 +68,7 @@ static void nbd_teardown_connection(BlockDriverState *bs) client->ioc =3D NULL; } -static coroutine_fn void nbd_read_reply_entry(void *opaque) +static coroutine_fn void nbd_connection_entry(void *opaque) { NBDClientSession *s =3D opaque; uint64_t i; @@ -100,14 +100,14 @@ static coroutine_fn void nbd_read_reply_entry(void *o= paque) } /* We're woken up again by the request itself. Note that there - * is no race between yielding and reentering read_reply_co. This + * is no race between yielding and reentering connection_co. This * is because: * * - if the request runs on the same AioContext, it is only * entered after we yield * * - if the request runs on a different AioContext, reentering - * read_reply_co happens through a bottom half, which can only + * connection_co happens through a bottom half, which can only * run after we yield. */ aio_co_wake(s->requests[i].coroutine); @@ -116,7 +116,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) s->quit =3D true; nbd_recv_coroutines_wake_all(s); - s->read_reply_co =3D NULL; + s->connection_co =3D NULL; aio_wait_kick(); } @@ -420,7 +420,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( } *request_ret =3D 0; - /* Wait until we're woken up by nbd_read_reply_entry. */ + /* Wait until we're woken up by nbd_connection_entry. */ s->requests[i].receiving =3D true; qemu_coroutine_yield(); s->requests[i].receiving =3D false; @@ -495,7 +495,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( } /* nbd_co_receive_one_chunk - * Read reply, wake up read_reply_co and set s->quit if needed. + * Read reply, wake up connection_co and set s->quit if needed. * Return value is a fatal error code or normal nbd reply error code */ static coroutine_fn int nbd_co_receive_one_chunk( @@ -509,15 +509,15 @@ static coroutine_fn int nbd_co_receive_one_chunk( if (ret < 0) { s->quit =3D true; } else { - /* For assert at loop start in nbd_read_reply_entry */ + /* For assert at loop start in nbd_connection_entry */ if (reply) { *reply =3D s->reply; } s->reply.handle =3D 0; } - if (s->read_reply_co) { - aio_co_wake(s->read_reply_co); + if (s->connection_co) { + aio_co_wake(s->connection_co); } return ret; @@ -970,7 +970,7 @@ void nbd_client_attach_aio_context(BlockDriverState *bs, { NBDClientSession *client =3D nbd_get_client_session(bs); qio_channel_attach_aio_context(QIO_CHANNEL(client->ioc), new_context); - aio_co_schedule(new_context, client->read_reply_co); + aio_co_schedule(new_context, client->connection_co); } void nbd_client_close(BlockDriverState *bs) @@ -1075,7 +1075,7 @@ static int nbd_client_connect(BlockDriverState *bs, /* Now that we're connected, set the socket to be non-blocking and * kick the reply mechanism. */ qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL); - client->read_reply_co =3D qemu_coroutine_create(nbd_read_reply_entry, = client); + client->connection_co =3D qemu_coroutine_create(nbd_connection_entry, = client); nbd_client_attach_aio_context(bs, bdrv_get_aio_context(bs)); logout("Established connection with NBD server\n"); --=20 2.20.1