From nobody Sun Oct 5 19:22:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894111; cv=none; d=zoho.com; s=zohoarc; b=nNsLfY2aq5j+I4FEAxnp1CQdTUic/RyiGLojGkPqdPgZZSZWljfogHcF0fVpO03klenfFKRgiO4hf1jz6voK3KQwp4xq4gYfl0vDVDpTOcprnIVzd7w8BT8U9xQ4ex2RrORl3ZMye/hHoYWrx44QM+VR1F1c7/oNLxIGQ/ILl4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894111; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZtOupEQPrS8mufNfELTMouVyf6aRjBqEE+3pChb2bSE=; b=GYdiHNVQMb8/IMMFVrC4U4U3+MLJoNe7me7AVnjjmaN7oUR3ncjU2zLdD/k94O2cRKo1Hpf79V40D1gFJxSCz6epXJq3fyrNPahChazO3vO8mwHQngO8G4tmdTHLmW/pIeBdbl125hKNK2fBiLTlSqsvlbNtjSsPxRX903YdWlQ= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894111063636.5580850773568; Thu, 15 Aug 2019 11:35:11 -0700 (PDT) Received: from localhost ([::1]:46064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKaP-0004vL-IJ for importer@patchew.org; Thu, 15 Aug 2019 14:34:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37333) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKWW-0002m8-TI for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:30:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKWU-0001JJ-Ak for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:30:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35056) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKWU-0001I8-1a for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:30:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63A1AC08E2BD; Thu, 15 Aug 2019 18:30:53 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21BFE8388F; Thu, 15 Aug 2019 18:30:41 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:31 -0500 Message-Id: <20190815183039.4264-2-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 15 Aug 2019 18:30:53 +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 1/9] qapi: Add InetSocketAddress member keep-alive X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Markus Armbruster , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy It's needed to provide keepalive for nbd client to track server availability. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20190725094937.32454-1-vsementsov@virtuozzo.com> Reviewed-by: Markus Armbruster Acked-by: Daniel P. Berrang=C3=A9 [eblake: Fix error message typo] Signed-off-by: Eric Blake --- qapi/sockets.json | 6 +++++- util/qemu-sockets.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/qapi/sockets.json b/qapi/sockets.json index fc81d8d5e8b9..32375f3a361e 100644 --- a/qapi/sockets.json +++ b/qapi/sockets.json @@ -53,6 +53,9 @@ # # @ipv6: whether to accept IPv6 addresses, default try both IPv4 and IPv6 # +# @keep-alive: enable keep-alive when connecting to this socket. Not suppo= rted +# for passive sockets. (Since 4.2) +# # Since: 1.3 ## { 'struct': 'InetSocketAddress', @@ -61,7 +64,8 @@ '*numeric': 'bool', '*to': 'uint16', '*ipv4': 'bool', - '*ipv6': 'bool' } } + '*ipv6': 'bool', + '*keep-alive': 'bool' } } ## # @UnixSocketAddress: diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index a5092dbd12e7..e3a1666578d9 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -219,6 +219,12 @@ static int inet_listen_saddr(InetSocketAddress *saddr, bool socket_created =3D false; Error *err =3D NULL; + if (saddr->keep_alive) { + error_setg(errp, "keep-alive option is not supported for passive " + "sockets"); + return -1; + } + memset(&ai,0, sizeof(ai)); ai.ai_flags =3D AI_PASSIVE; if (saddr->has_numeric && saddr->numeric) { @@ -458,6 +464,19 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error= **errp) } freeaddrinfo(res); + + if (saddr->keep_alive) { + int val =3D 1; + int ret =3D qemu_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, + &val, sizeof(val)); + + if (ret < 0) { + error_setg_errno(errp, errno, "Unable to set KEEPALIVE"); + close(sock); + return -1; + } + } + return sock; } @@ -653,6 +672,15 @@ int inet_parse(InetSocketAddress *addr, const char *st= r, Error **errp) } addr->has_ipv6 =3D true; } + begin =3D strstr(optstr, ",keep-alive"); + if (begin) { + if (inet_parse_flag("keep-alive", begin + strlen(",keep-alive"), + &addr->keep_alive, errp) < 0) + { + return -1; + } + addr->has_keep_alive =3D true; + } return 0; } --=20 2.20.1 From nobody Sun Oct 5 19:22:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894324; cv=none; d=zoho.com; s=zohoarc; b=Ez/+1hayZeztLPhtJwagaXX07efgu2e1BAauES17ThDJ4sj8uH8Z5QGu7GHX1h5kp3mbYG9rKlIFOQcR7fYky3dXFj4G9o7GN6z9w2njEJl5k3+L3RY+ja8xc4sOCtv1DjZmkXv1wk92POMcUYRIEGIZky7mxdIqSNs9jaiSh84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894324; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=faIlNUqR7zIzCordVtQTr5pf6hC295KkPLnm5WkUMdI=; b=lwgJ7t9uxDrOvfvwmsntwYqc0bOg9p5L3xfWvrdA7l6B2gxvJ1zh14yXAmbO2gKijTR4y0O4l9tGwaxqSL9Nhvll0DJykaYVE+QBkM2+nf1YnZnC7UNdPKV3noLozhzbwztrUHg/Ry5xb+PDYFB1veEHbOvISRd5liErpn7xHpc= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894324161144.09418217679377; Thu, 15 Aug 2019 11:38:44 -0700 (PDT) Received: from localhost ([::1]:46132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKe2-0000pC-TH for importer@patchew.org; Thu, 15 Aug 2019 14:38:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37566) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKXC-00030o-HO for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKX6-0001s3-9t for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKWz-0001db-Cp; Thu, 15 Aug 2019 14:31:26 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9497DC0BAA0D; Thu, 15 Aug 2019 18:31:21 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CF5E8388F; Thu, 15 Aug 2019 18:30:53 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:32 -0500 Message-Id: <20190815183039.4264-3-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 15 Aug 2019 18:31: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 2/9] block: implement BDRV_REQ_PREFETCH X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , "open list:Block I/O path" , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Do effective copy-on-read request when we don't need data actually. It will be used for block-stream and NBD_CMD_CACHE. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20190725100550.33801-2-vsementsov@virtuozzo.com> Reviewed-by: Stefan Hajnoczi [eblake: comment grammar fix] Signed-off-by: Eric Blake --- include/block/block.h | 8 +++++++- block/io.c | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 50a07c1c3385..a9df34ff94b6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -88,8 +88,14 @@ typedef enum { * fallback. */ BDRV_REQ_NO_FALLBACK =3D 0x100, + /* + * BDRV_REQ_PREFETCH may be used only together with BDRV_REQ_COPY_ON_R= EAD + * on read request and means that caller doesn't really need data to be + * written to qiov parameter which may be NULL. + */ + BDRV_REQ_PREFETCH =3D 0x200, /* Mask of valid flags */ - BDRV_REQ_MASK =3D 0x1ff, + BDRV_REQ_MASK =3D 0x3ff, } BdrvRequestFlags; typedef struct BlockSizes { diff --git a/block/io.c b/block/io.c index 06305c6ea62e..9d99858b554b 100644 --- a/block/io.c +++ b/block/io.c @@ -1167,7 +1167,8 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, = uint64_t offset, } static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, - int64_t offset, unsigned int bytes, QEMUIOVector *qiov) + int64_t offset, unsigned int bytes, QEMUIOVector *qiov, + int flags) { BlockDriverState *bs =3D child->bs; @@ -1278,9 +1279,11 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bdr= vChild *child, goto err; } - qemu_iovec_from_buf(qiov, progress, bounce_buffer + skip_bytes, - pnum - skip_bytes); - } else { + if (!(flags & BDRV_REQ_PREFETCH)) { + qemu_iovec_from_buf(qiov, progress, bounce_buffer + skip_b= ytes, + pnum - skip_bytes); + } + } else if (!(flags & BDRV_REQ_PREFETCH)) { /* Read directly into the destination */ qemu_iovec_init(&local_qiov, qiov->niov); qemu_iovec_concat(&local_qiov, qiov, progress, pnum - skip_byt= es); @@ -1331,7 +1334,8 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild= *child, * potential fallback support, if we ever implement any read flags * to pass through to drivers. For now, there aren't any * passthrough flags. */ - assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ))); + assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ | + BDRV_REQ_PREFETCH))); /* Handle Copy on Read and associated serialisation */ if (flags & BDRV_REQ_COPY_ON_READ) { @@ -1359,7 +1363,9 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild= *child, } if (!ret || pnum !=3D bytes) { - ret =3D bdrv_co_do_copy_on_readv(child, offset, bytes, qiov); + ret =3D bdrv_co_do_copy_on_readv(child, offset, bytes, qiov, f= lags); + goto out; + } else if (flags & BDRV_REQ_PREFETCH) { goto out; } } --=20 2.20.1 From nobody Sun Oct 5 19:22:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894119; cv=none; d=zoho.com; s=zohoarc; b=Y673oH5ZjxGk+HHqlamXqvHudo4UPUDbOiCPqL16zK8VQOJ3P0PDQQKw57vffsworeM+5Nd1BhUMLCFoZ6I/ZztkpC5tFg3F/b/6B2H+Wp4kW/DVLNyMVwM0+Ca/2pQbajQZMxls2fZP9FgpFqr7doiENo6gyeh/nGDCrzH+qw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894119; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HVRbXt0ssclIlyO9sqXZ9gut807szqG91wpCvvFf9R8=; b=OGZAIVJkLz+B0DP3cVcM0jg/WzC3wlvvsYknbjXwxw4mTuvGgMo2sndntw8+AIQj4XCijRmhnu1lTdjsrhOMEN3KgL+jD5qIb5130CFfICuySri5JSnZO+VtzFOdUoW+6iYFxcqEV/jR1i67qocxjXElcmxsNPDPKj+BQemJKOA= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894119641917.2308288277644; Thu, 15 Aug 2019 11:35:19 -0700 (PDT) Received: from localhost ([::1]:46068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKag-0005GG-41 for importer@patchew.org; Thu, 15 Aug 2019 14:35:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37522) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKX9-0002za-Fj for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKX6-0001sl-Oa for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60088) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKWz-0001e3-Cf; Thu, 15 Aug 2019 14:31:26 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99EC8D7A52; Thu, 15 Aug 2019 18:31:22 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1FB084D8D; Thu, 15 Aug 2019 18:31:21 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:33 -0500 Message-Id: <20190815183039.4264-4-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 15 Aug 2019 18:31:22 +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/9] block/stream: use BDRV_REQ_PREFETCH X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , "open list:Block Jobs" , Max Reitz , Stefan Hajnoczi , John Snow 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 helps to avoid extra io, allocations and memory copying. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20190725100550.33801-3-vsementsov@virtuozzo.com> Reviewed-by: Stefan Hajnoczi [eblake: fix comment grammar] Signed-off-by: Eric Blake --- block/stream.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/block/stream.c b/block/stream.c index 6ac1e7bec42c..0d3a6ac7c3f7 100644 --- a/block/stream.c +++ b/block/stream.c @@ -22,11 +22,11 @@ enum { /* - * Size of data buffer for populating the image file. This should be = large - * enough to process multiple clusters in a single call, so that popul= ating - * contiguous regions of the image is efficient. + * Maximum chunk size to feed to copy-on-read. This should be + * large enough to process multiple clusters in a single call, so + * that populating contiguous regions of the image is efficient. */ - STREAM_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ + STREAM_CHUNK =3D 512 * 1024, /* in bytes */ }; typedef struct StreamBlockJob { @@ -39,13 +39,12 @@ typedef struct StreamBlockJob { } StreamBlockJob; static int coroutine_fn stream_populate(BlockBackend *blk, - int64_t offset, uint64_t bytes, - void *buf) + int64_t offset, uint64_t bytes) { assert(bytes < SIZE_MAX); - /* Copy-on-read the unallocated clusters */ - return blk_co_pread(blk, offset, bytes, buf, BDRV_REQ_COPY_ON_READ); + return blk_co_preadv(blk, offset, bytes, NULL, + BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH); } static void stream_abort(Job *job) @@ -117,7 +116,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) int error =3D 0; int ret =3D 0; int64_t n =3D 0; /* bytes */ - void *buf; if (bs =3D=3D s->bottom) { /* Nothing to stream */ @@ -130,8 +128,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) } job_progress_set_remaining(&s->common.job, len); - buf =3D qemu_blockalign(bs, STREAM_BUFFER_SIZE); - /* Turn on copy-on-read for the whole block device so that guest read * requests help us make progress. Only do this when copying the enti= re * backing chain since the copy-on-read operation does not take base i= nto @@ -154,7 +150,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) copy =3D false; - ret =3D bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &n); + ret =3D bdrv_is_allocated(bs, offset, STREAM_CHUNK, &n); if (ret =3D=3D 1) { /* Allocated in the top, no need to copy. */ } else if (ret >=3D 0) { @@ -171,7 +167,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) } trace_stream_one_iteration(s, offset, n, ret); if (copy) { - ret =3D stream_populate(blk, offset, n, buf); + ret =3D stream_populate(blk, offset, n); } if (ret < 0) { BlockErrorAction action =3D @@ -202,8 +198,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) bdrv_disable_copy_on_read(bs); } - qemu_vfree(buf); - /* Do not remove the backing file if an error was there but ignored. */ return error; } --=20 2.20.1 From nobody Sun Oct 5 19:22:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894116; cv=none; d=zoho.com; s=zohoarc; b=ZylC/EEMERlILv3fYRaPQzQ640Doi+p2+PbVPBld4yJNCtRTyfmQCfEKf9zcEYLaJ5+OsET4KHsBDceFg4GBV6vPaSNLwzmhpI1iPW/3NNY9O6MBfqI9BhITP3yzIH60iQzxojWuUYxqLL2EoGdBEEcMFn4mnQZ59RQOjpt5Bts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894116; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=L7xVmzXTeMJcwfsl9JCKG5xijiSTdJkCSTWzFjFvfY0=; b=W/9JaMzHV2JA/UJ7lt1YESYV8wd5c1NB+pCdIDtlhuskbootuG3bqyPg5p9uQ+4n8s+aMXvTOfHWbjbITYmJv9Uk98KqtNLensj0WTGOKpMDErBgCsRnr6PQz0Lkc1WABlnI6cdFj7eWNnHNFHuV/uifsndvpMdGl7wave5eZG0= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894116678534.0392102045563; Thu, 15 Aug 2019 11:35:16 -0700 (PDT) Received: from localhost ([::1]:46070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKaf-0005IL-36 for importer@patchew.org; Thu, 15 Aug 2019 14:35:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37535) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKXA-0002zr-DJ for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKX7-0001wy-Td for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38626) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKWz-0001ey-C6; Thu, 15 Aug 2019 14:31:26 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 297F230BB8E8; Thu, 15 Aug 2019 18:31:23 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id A359F84BBA; Thu, 15 Aug 2019 18:31:22 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:34 -0500 Message-Id: <20190815183039.4264-5-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 15 Aug 2019 18:31:23 +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/9] nbd: improve CMD_CACHE: use BDRV_REQ_PREFETCH X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Stefan Hajnoczi 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 helps to avoid extra io, allocations and memory copying. We assume here that CMD_CACHE is always used with copy-on-read, as otherwise it's a noop. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20190725100550.33801-4-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Eric Blake --- nbd/server.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 10faedcfc55d..a2cf085f7635 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2104,12 +2104,15 @@ static int nbd_co_receive_request(NBDRequestData *r= eq, NBDRequest *request, return -EINVAL; } - req->data =3D blk_try_blockalign(client->exp->blk, request->len); - if (req->data =3D=3D NULL) { - error_setg(errp, "No memory"); - return -ENOMEM; + if (request->type !=3D NBD_CMD_CACHE) { + req->data =3D blk_try_blockalign(client->exp->blk, request->le= n); + if (req->data =3D=3D NULL) { + error_setg(errp, "No memory"); + return -ENOMEM; + } } } + if (request->type =3D=3D NBD_CMD_WRITE) { if (nbd_read(client->ioc, req->data, request->len, "CMD_WRITE data= ", errp) < 0) @@ -2194,7 +2197,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, int ret; NBDExport *exp =3D client->exp; - assert(request->type =3D=3D NBD_CMD_READ || request->type =3D=3D NBD_C= MD_CACHE); + assert(request->type =3D=3D NBD_CMD_READ); /* XXX: NBD Protocol only documents use of FUA with WRITE */ if (request->flags & NBD_CMD_FLAG_FUA) { @@ -2206,7 +2209,7 @@ 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->type !=3D NBD_CMD_CACHE) + request->len) { return nbd_co_send_sparse_read(client, request->handle, request->f= rom, data, request->len, errp); @@ -2214,7 +2217,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, ret =3D blk_pread(exp->blk, request->from + exp->dev_offset, data, request->len); - if (ret < 0 || request->type =3D=3D NBD_CMD_CACHE) { + if (ret < 0) { return nbd_send_generic_reply(client, request->handle, ret, "reading from file failed", errp); } @@ -2233,6 +2236,28 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *c= lient, NBDRequest *request, } } +/* + * nbd_do_cmd_cache + * + * Handle NBD_CMD_CACHE request. + * Return -errno if sending fails. Other errors are reported directly to t= he + * client as an error reply. + */ +static coroutine_fn int nbd_do_cmd_cache(NBDClient *client, NBDRequest *re= quest, + Error **errp) +{ + int ret; + NBDExport *exp =3D client->exp; + + assert(request->type =3D=3D NBD_CMD_CACHE); + + ret =3D blk_co_preadv(exp->blk, request->from + exp->dev_offset, reque= st->len, + NULL, BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH); + + return nbd_send_generic_reply(client, request->handle, ret, + "caching data failed", errp); +} + /* Handle NBD request. * Return -errno if sending fails. Other errors are reported directly to t= he * client as an error reply. */ @@ -2246,8 +2271,10 @@ static coroutine_fn int nbd_handle_request(NBDClient= *client, char *msg; switch (request->type) { - case NBD_CMD_READ: case NBD_CMD_CACHE: + return nbd_do_cmd_cache(client, request, errp); + + case NBD_CMD_READ: return nbd_do_cmd_read(client, request, data, errp); case NBD_CMD_WRITE: --=20 2.20.1 From nobody Sun Oct 5 19:22:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894308; cv=none; d=zoho.com; s=zohoarc; b=E/91vv9HNG4Lx1rJc7RTGUqOJMyFpc+vDtWxfqZcP5NMysPNyXxb7Sz9CxDgZODKuxDtm6Yh4xRIcqHJiscq7h2XoOzoBkiafX23TwEjD7FcPotPyuMM4o99fKQbYqO9WLJRJrwl6tkPAt9HLjGUtF3su52J13MO3m7I8GVplLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894308; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HyPIWDwuk+1I8efv6bDmUsK+K4K60h+xOcPj3dbae1w=; b=jXbNFpA+S4/K8kFLyJ2dN7ZTKu2mYhjxRhv/uzYkrwWwGfbjl28Xl9VB77k3deKeZ5u9s1j/R21wLuGuCg4vvRbHp9ysU0AtsCyc/AhTZccLTXrSjPOnyXJ9zvL6C6DHj0Dr30Mnk71bZZGhIfZUeMWnOH+0ZQ/16woF6R2rOms= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894308700713.1740336324575; Thu, 15 Aug 2019 11:38:28 -0700 (PDT) Received: from localhost ([::1]:46112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKdn-0000RX-Cn for importer@patchew.org; Thu, 15 Aug 2019 14:38:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37564) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKXC-00030j-Dt for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKX6-0001s8-AA for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38313) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKWz-0001f3-CH; Thu, 15 Aug 2019 14:31:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB21FC04DBCD; Thu, 15 Aug 2019 18:31:23 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48C1512A72; Thu, 15 Aug 2019 18:31:23 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:35 -0500 Message-Id: <20190815183039.4264-6-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 15 Aug 2019 18:31:23 +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/9] block/nbd: split connection_co start out of nbd_client_connect X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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 nbd_client_connect is going to be used from connection_co, so, let's refactor nbd_client_connect in advance, leaving io channel configuration all in nbd_client_connect. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190618114328.55249-2-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 57c1a205811a..c16d02528b2f 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1231,14 +1231,8 @@ static int nbd_client_connect(BlockDriverState *bs, object_ref(OBJECT(s->ioc)); } - /* - * 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); - s->connection_co =3D qemu_coroutine_create(nbd_connection_entry, s); - bdrv_inc_in_flight(bs); - nbd_client_attach_aio_context(bs, bdrv_get_aio_context(bs)); + qio_channel_attach_aio_context(s->ioc, bdrv_get_aio_context(bs)); trace_nbd_client_connect_success(export); @@ -1269,14 +1263,24 @@ static int nbd_client_init(BlockDriverState *bs, const char *x_dirty_bitmap, Error **errp) { + int ret; BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; s->bs =3D bs; qemu_co_mutex_init(&s->send_mutex); qemu_co_queue_init(&s->free_sema); - return nbd_client_connect(bs, saddr, export, tlscreds, hostname, - x_dirty_bitmap, errp); + ret =3D nbd_client_connect(bs, saddr, export, tlscreds, hostname, + x_dirty_bitmap, errp); + if (ret < 0) { + return ret; + } + + s->connection_co =3D qemu_coroutine_create(nbd_connection_entry, s); + bdrv_inc_in_flight(bs); + aio_co_schedule(bdrv_get_aio_context(bs), s->connection_co); + + return 0; } static int nbd_parse_uri(const char *filename, QDict *options) --=20 2.20.1 From nobody Sun Oct 5 19:22:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894785; cv=none; d=zoho.com; s=zohoarc; b=JSK7XEDdRjXSzBX550GV5chVETU6BL5PZ43eLKOqmXc7A8++d3ggG9O7E/059D7fRaeLqylIY0k6JUYkBJfzKFU49Fu2DKdbSCzu05zZt2mrtDAzG7aswLlmB1T80Yg3Oe8VqnDR8YGnqx9XdvdtLyj/PuWMpSisSQ9eSi6ESeo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894785; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=hfDiqnxuSf4j/ypfQSFChHQ1srOqEdk4/uyVIyAodWY=; b=GWYQtAj1Dgd7XJfhHbcXCE+xb/0B3sH1uxeoABEP92EZDO4uSrzsm0E3dyik50hyR3Ftwcm9Zlnd7Xt6WEDYIhpIyhpQ0iyhk6r9HWen9jRrnH1+/G2wOrw8fET3teoe89f3U6D6PR805FF2nJ2fEmWEmvK5+VNX1F1bUBjLV+U= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894785069834.8512673510747; Thu, 15 Aug 2019 11:46:25 -0700 (PDT) Received: from localhost ([::1]:46254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKlT-0001c4-Ls for importer@patchew.org; Thu, 15 Aug 2019 14:46:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37577) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKXD-00030z-P6 for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKXA-00020n-9T for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58812) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKX1-0001fx-I8; Thu, 15 Aug 2019 14:31:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67CE930BC824; Thu, 15 Aug 2019 18:31:24 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA5F112A72; Thu, 15 Aug 2019 18:31:23 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:36 -0500 Message-Id: <20190815183039.4264-7-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 15 Aug 2019 18:31:24 +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/9] block/nbd: use non-blocking io channel for nbd negotiation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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 No reason to use blocking channel for negotiation and we'll benefit in further reconnect feature, as qio_channel reads and writes will do qemu_coroutine_yield while waiting for io completion. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190618114328.55249-3-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- include/block/nbd.h | 3 ++- block/nbd.c | 16 +++++++--------- nbd/client.c | 16 +++++++++++----- qemu-nbd.c | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index bb9f5bc0216f..7b36d672f046 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -304,7 +304,8 @@ struct NBDExportInfo { }; typedef struct NBDExportInfo NBDExportInfo; -int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, +int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc, + QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, Error **errp); void nbd_free_export_list(NBDExportInfo *info, int count); diff --git a/block/nbd.c b/block/nbd.c index c16d02528b2f..3a243d9de96e 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1175,6 +1175,7 @@ static int nbd_client_connect(BlockDriverState *bs, Error **errp) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; + AioContext *aio_context =3D bdrv_get_aio_context(bs); int ret; /* @@ -1189,15 +1190,16 @@ static int nbd_client_connect(BlockDriverState *bs, /* NBD handshake */ trace_nbd_client_connect(export); - qio_channel_set_blocking(QIO_CHANNEL(sioc), true, NULL); + qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL); + qio_channel_attach_aio_context(QIO_CHANNEL(sioc), aio_context); s->info.request_sizes =3D true; s->info.structured_reply =3D true; s->info.base_allocation =3D true; s->info.x_dirty_bitmap =3D g_strdup(x_dirty_bitmap); s->info.name =3D g_strdup(export ?: ""); - ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), tlscreds, hostname, - &s->ioc, &s->info, errp); + ret =3D nbd_receive_negotiate(aio_context, QIO_CHANNEL(sioc), tlscreds, + hostname, &s->ioc, &s->info, errp); g_free(s->info.x_dirty_bitmap); g_free(s->info.name); if (ret < 0) { @@ -1231,18 +1233,14 @@ static int nbd_client_connect(BlockDriverState *bs, object_ref(OBJECT(s->ioc)); } - qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL); - qio_channel_attach_aio_context(s->ioc, bdrv_get_aio_context(bs)); - trace_nbd_client_connect_success(export); return 0; fail: /* - * We have connected, but must fail for other reasons. The - * connection is still blocking; send NBD_CMD_DISC as a courtesy - * to the server. + * We have connected, but must fail for other reasons. + * Send NBD_CMD_DISC as a courtesy to the server. */ { NBDRequest request =3D { .type =3D NBD_CMD_DISC }; diff --git a/nbd/client.c b/nbd/client.c index 4de30630c738..8f524c3e3502 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -867,7 +867,8 @@ static int nbd_list_meta_contexts(QIOChannel *ioc, * 2: server is newstyle, but lacks structured replies * 3: server is newstyle and set up for structured replies */ -static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, +static int nbd_start_negotiate(AioContext *aio_context, QIOChannel *ioc, + QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, bool structured_reply, bool *zeroes, Error **errp) @@ -934,6 +935,10 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCrypt= oTLSCreds *tlscreds, return -EINVAL; } ioc =3D *outioc; + if (aio_context) { + qio_channel_set_blocking(ioc, false, NULL); + qio_channel_attach_aio_context(ioc, aio_context); + } } else { error_setg(errp, "Server does not support STARTTLS"); return -EINVAL; @@ -998,7 +1003,8 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel *i= oc, NBDExportInfo *info, * Returns: negative errno: failure talking to server * 0: server is connected */ -int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, +int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc, + QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, Error **errp) { @@ -1009,7 +1015,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLS= Creds *tlscreds, assert(info->name); trace_nbd_receive_negotiate_name(info->name); - result =3D nbd_start_negotiate(ioc, tlscreds, hostname, outioc, + result =3D nbd_start_negotiate(aio_context, ioc, tlscreds, hostname, o= utioc, info->structured_reply, &zeroes, errp); info->structured_reply =3D false; @@ -1129,8 +1135,8 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, QIOChannel *sioc =3D NULL; *info =3D NULL; - result =3D nbd_start_negotiate(ioc, tlscreds, hostname, &sioc, true, N= ULL, - errp); + result =3D nbd_start_negotiate(NULL, ioc, tlscreds, hostname, &sioc, t= rue, + NULL, errp); if (tlscreds && sioc) { ioc =3D sioc; } diff --git a/qemu-nbd.c b/qemu-nbd.c index a8cb39e51043..049645491dab 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -362,7 +362,7 @@ static void *nbd_client_thread(void *arg) goto out; } - ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), + ret =3D nbd_receive_negotiate(NULL, QIO_CHANNEL(sioc), NULL, NULL, NULL, &info, &local_error); if (ret < 0) { if (local_error) { --=20 2.20.1 From nobody Sun Oct 5 19:22:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894515; cv=none; d=zoho.com; s=zohoarc; b=NmbhwsTTw/AuydcybBYOei14TN7fNAKuGBg/S44yiVSLgOOQy8WRwmFiZ/g9E2VjUUC1gnWDyIQFNL4uaI/2fovOdVFszlliRVcovPM8PejGyuHBcDAEhUbHtMcBmbrH8aB+qOlX//PhMINhgDV1yKvtAWe2cf4jHQGB9qURccg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894515; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=B/8nlaik/FkMk2yl2EpfjYUiBMKp2lvHFodTqZwjD1o=; b=KxQuMzMgjpZLBTaK42nQ810hd//xPMGXDtgoRt79HHSyqkpbJ8VhFdK8IJzn+vNsJdQdWVZNQFZoBhch7AM/nXR+bXK1fcWCMxIlTG2BQRyN0T6zgqEm6L09EVmFpjJI70utHxPdBs69ENCQz5G2MlwReRw++7f4nDFcSNxqjmg= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894515099746.8548189348494; Thu, 15 Aug 2019 11:41:55 -0700 (PDT) Received: from localhost ([::1]:46176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKh7-0004Wr-8Y for importer@patchew.org; Thu, 15 Aug 2019 14:41:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37543) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKXB-00030G-0a for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKX8-0001xv-46 for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59585) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKX1-0001gg-8k; Thu, 15 Aug 2019 14:31:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D75B30BC838; Thu, 15 Aug 2019 18:31:25 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9044C600CD; Thu, 15 Aug 2019 18:31:24 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:37 -0500 Message-Id: <20190815183039.4264-8-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 15 Aug 2019 18:31:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/9] block/nbd: move from quit to state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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 reconnect we need several states for the client: CONNECTED, QUIT and two different CONNECTING states. CONNECTING states will be added in the following patches. This patch implements CONNECTED and QUIT. QUIT means, that we should close the connection and fail all current and further requests (like old quit =3D true). CONNECTED means that connection is ok, we can send requests (like old quit =3D false). For receiving loop we use a comparison of the current state with QUIT, because reconnect will be in the same loop, so it should be looping until the end. Opposite, for requests we use a comparison of the current state with CONNECTED, as we don't want to send requests in future CONNECTING states. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190618114328.55249-4-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd.c | 58 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 3a243d9de96e..d03b00fc30b0 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -53,6 +53,11 @@ typedef struct { bool receiving; /* waiting for connection_co? */ } NBDClientRequest; +typedef enum NBDClientState { + NBD_CLIENT_CONNECTED, + NBD_CLIENT_QUIT +} NBDClientState; + typedef struct BDRVNBDState { QIOChannelSocket *sioc; /* The master data channel */ QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) = */ @@ -62,17 +67,23 @@ typedef struct BDRVNBDState { CoQueue free_sema; Coroutine *connection_co; int in_flight; + NBDClientState state; NBDClientRequest requests[MAX_NBD_REQUESTS]; NBDReply reply; BlockDriverState *bs; - bool quit; /* For nbd_refresh_filename() */ SocketAddress *saddr; char *export, *tlscredsid; } BDRVNBDState; +/* @ret will be used for reconnect in future */ +static void nbd_channel_error(BDRVNBDState *s, int ret) +{ + s->state =3D NBD_CLIENT_QUIT; +} + static void nbd_recv_coroutines_wake_all(BDRVNBDState *s) { int i; @@ -151,7 +162,7 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) int ret =3D 0; Error *local_err =3D NULL; - while (!s->quit) { + while (s->state !=3D NBD_CLIENT_QUIT) { /* * The NBD client can only really be considered idle when it has * yielded from qio_channel_readv_all_eof(), waiting for data. Thi= s is @@ -169,6 +180,7 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) error_free(local_err); } if (ret <=3D 0) { + nbd_channel_error(s, ret ? ret : -EIO); break; } @@ -183,6 +195,7 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) !s->requests[i].receiving || (nbd_reply_is_structured(&s->reply) && !s->info.structured_rep= ly)) { + nbd_channel_error(s, -EINVAL); break; } @@ -202,7 +215,6 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) qemu_coroutine_yield(); } - s->quit =3D true; nbd_recv_coroutines_wake_all(s); bdrv_dec_in_flight(s->bs); @@ -215,12 +227,18 @@ static int nbd_co_send_request(BlockDriverState *bs, QEMUIOVector *qiov) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; - int rc, i; + int rc, i =3D -1; qemu_co_mutex_lock(&s->send_mutex); while (s->in_flight =3D=3D MAX_NBD_REQUESTS) { qemu_co_queue_wait(&s->free_sema, &s->send_mutex); } + + if (s->state !=3D NBD_CLIENT_CONNECTED) { + rc =3D -EIO; + goto err; + } + s->in_flight++; for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { @@ -238,16 +256,12 @@ static int nbd_co_send_request(BlockDriverState *bs, request->handle =3D INDEX_TO_HANDLE(s, i); - if (s->quit) { - rc =3D -EIO; - goto err; - } assert(s->ioc); if (qiov) { qio_channel_set_cork(s->ioc, true); rc =3D nbd_send_request(s->ioc, request); - if (rc >=3D 0 && !s->quit) { + if (rc >=3D 0 && s->state =3D=3D NBD_CLIENT_CONNECTED) { if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov, NULL) < 0) { rc =3D -EIO; @@ -262,9 +276,11 @@ static int nbd_co_send_request(BlockDriverState *bs, err: if (rc < 0) { - s->quit =3D true; - s->requests[i].coroutine =3D NULL; - s->in_flight--; + nbd_channel_error(s, rc); + if (i !=3D -1) { + s->requests[i].coroutine =3D NULL; + s->in_flight--; + } qemu_co_queue_next(&s->free_sema); } qemu_co_mutex_unlock(&s->send_mutex); @@ -556,7 +572,7 @@ 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->quit) { + if (s->state !=3D NBD_CLIENT_CONNECTED) { error_setg(errp, "Connection closed"); return -EIO; } @@ -641,7 +657,7 @@ static coroutine_fn int nbd_co_receive_one_chunk( if (ret < 0) { memset(reply, 0, sizeof(*reply)); - s->quit =3D true; + nbd_channel_error(s, ret); } else { /* For assert at loop start in nbd_connection_entry */ *reply =3D s->reply; @@ -709,7 +725,7 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *= s, NBDReply local_reply; NBDStructuredReplyChunk *chunk; Error *local_err =3D NULL; - if (s->quit) { + if (s->state !=3D NBD_CLIENT_CONNECTED) { error_setg(&local_err, "Connection closed"); nbd_iter_channel_error(iter, -EIO, &local_err); goto break_loop; @@ -734,7 +750,7 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *= s, } /* Do not execute the body of NBD_FOREACH_REPLY_CHUNK for simple reply= . */ - if (nbd_reply_is_simple(reply) || s->quit) { + if (nbd_reply_is_simple(reply) || s->state !=3D NBD_CLIENT_CONNECTED) { goto break_loop; } @@ -808,14 +824,14 @@ static int nbd_co_receive_cmdread_reply(BDRVNBDState = *s, uint64_t handle, ret =3D nbd_parse_offset_hole_payload(s, &reply.structured, pa= yload, offset, qiov, &local_err); if (ret < 0) { - s->quit =3D true; + nbd_channel_error(s, ret); nbd_iter_channel_error(&iter, ret, &local_err); } break; default: if (!nbd_reply_type_is_error(chunk->type)) { /* not allowed reply type */ - s->quit =3D true; + nbd_channel_error(s, -EINVAL); error_setg(&local_err, "Unexpected reply type: %d (%s) for CMD_READ", chunk->type, nbd_reply_type_lookup(chunk->type)= ); @@ -853,7 +869,7 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBDStat= e *s, switch (chunk->type) { case NBD_REPLY_TYPE_BLOCK_STATUS: if (received) { - s->quit =3D true; + nbd_channel_error(s, -EINVAL); error_setg(&local_err, "Several BLOCK_STATUS chunks in rep= ly"); nbd_iter_channel_error(&iter, -EINVAL, &local_err); } @@ -863,13 +879,13 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBDSt= ate *s, payload, length, extent, &local_err); if (ret < 0) { - s->quit =3D true; + nbd_channel_error(s, ret); nbd_iter_channel_error(&iter, ret, &local_err); } break; default: if (!nbd_reply_type_is_error(chunk->type)) { - s->quit =3D true; + nbd_channel_error(s, -EINVAL); error_setg(&local_err, "Unexpected reply type: %d (%s) " "for CMD_BLOCK_STATUS", --=20 2.20.1 From nobody Sun Oct 5 19:22:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894348; cv=none; d=zoho.com; s=zohoarc; b=iCQ7IImX2+zT1ym9D/B3LiOPpd+06YCWn3UQeuOHlKB+D9UcmSS8r0VoHVO5aMGeuh/ZfrTNKJSctbh/ZJezTipkeqYR84+1TJFc56Uz7kB1YfZI6sAFu2EMIFtoxr/g2d9IniJjQwCsGDvxS5M3LxgK2tcF7RLZdQGpcW18QzI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894348; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=BIgMSjjWbgba+pdSDYGSaWM0yEK1dd0RQ7zDG9cG0Zk=; b=JXHln8n9U1nD75ygI3FMFI/PwUT7UJ7FpMXjsplGbHJ3koEV5FyDaGs6LiT08G5spMt2f36qzl1aOxq60+GErFQfW1Xs/JTjbPz4VP/brGg84cH8E/BZbMmQ8aZ7DT3Fc62mR/lH/S70G/ePYif4jbH+0nnISmCol3/MtgHpQrA= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894348656326.3761486278935; Thu, 15 Aug 2019 11:39:08 -0700 (PDT) Received: from localhost ([::1]:46144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKeR-0001T1-DB for importer@patchew.org; Thu, 15 Aug 2019 14:39:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37530) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKXA-0002zi-AR for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKX7-0001wz-Ta for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50638) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKX1-0001iB-I1; Thu, 15 Aug 2019 14:31:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA2DC300442C; Thu, 15 Aug 2019 18:31:25 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39970600CD; Thu, 15 Aug 2019 18:31:25 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:38 -0500 Message-Id: <20190815183039.4264-9-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 15 Aug 2019 18:31:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 8/9] block/nbd: add cmdline and qapi parameter reconnect-delay X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Markus Armbruster , "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 Reconnect will be implemented in the following commit, so for now, in semantics below, disconnect itself is a "serious error". Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20190618114328.55249-5-vsementsov@virtuozzo.com> [eblake: slipped from 4.1 to 4.2] Signed-off-by: Eric Blake --- qapi/block-core.json | 11 ++++++++++- block/nbd.c | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 0d43d4f37c1a..f1e7701fbea9 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3860,13 +3860,22 @@ # traditional "base:allocation" block status (see # NBD_OPT_LIST_META_CONTEXT in the NBD protocol) (since 3= .0) # +# @reconnect-delay: On an unexpected disconnect, the nbd client tries to +# connect again until succeeding or encountering a serio= us +# error. During the first @reconnect-delay seconds, all +# requests are paused and will be rerun on a successful +# reconnect. After that time, any delayed requests and a= ll +# future requests before a successful reconnect will +# immediately fail. Default 0 (Since 4.2) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsNbd', 'data': { 'server': 'SocketAddress', '*export': 'str', '*tls-creds': 'str', - '*x-dirty-bitmap': 'str' } } + '*x-dirty-bitmap': 'str', + '*reconnect-delay': 'uint32' } } ## # @BlockdevOptionsRaw: diff --git a/block/nbd.c b/block/nbd.c index d03b00fc30b0..de2a26097bf9 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1275,6 +1275,7 @@ static int nbd_client_init(BlockDriverState *bs, QCryptoTLSCreds *tlscreds, const char *hostname, const char *x_dirty_bitmap, + uint32_t reconnect_delay, Error **errp) { int ret; @@ -1600,6 +1601,17 @@ static QemuOptsList nbd_runtime_opts =3D { .help =3D "experimental: expose named dirty bitmap in place of= " "block status", }, + { + .name =3D "reconnect-delay", + .type =3D QEMU_OPT_NUMBER, + .help =3D "On an unexpected disconnect, the nbd client tries t= o " + "connect again until succeeding or encountering a seri= ous " + "error. During the first @reconnect-delay seconds, al= l " + "requests are paused and will be rerun on a successful= " + "reconnect. After that time, any delayed requests and = all " + "future requests before a successful reconnect will " + "immediately fail. Default 0", + }, { /* end of list */ } }, }; @@ -1651,7 +1663,9 @@ static int nbd_open(BlockDriverState *bs, QDict *opti= ons, int flags, /* NBD handshake */ ret =3D nbd_client_init(bs, s->saddr, s->export, tlscreds, hostname, - qemu_opt_get(opts, "x-dirty-bitmap"), errp); + qemu_opt_get(opts, "x-dirty-bitmap"), + qemu_opt_get_number(opts, "reconnect-delay", 0), + errp); error: if (tlscreds) { --=20 2.20.1 From nobody Sun Oct 5 19:22:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894673; cv=none; d=zoho.com; s=zohoarc; b=mYESczBA/oN0mYnRN0xqBdNBJS6Mvb1j/ZlkFUeNiwRcPwFHHbCEMk+MvEpaMbGgo5vgtdUxRCXCHHmHX6SzKcCgvZ33anfWSjHoNIWCaNWtpUITEqEmh8CMecoVnrIKAMrek77EAJpJsvPAmWQBT96Uvaef6mK2grfSR6rJyXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894673; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KmZOyneRNeFl2vYSovXSeJUcQ2qAykHrMTesftNdSyM=; b=QZO3uRE1QNctf0iTXSzy38M7AyRihTOIRTC5i0H0ENKGbx4GtdBDeF3RZQpPPS9pf2POfQeJyiRxkbwxvxAvsS/eP7ba7z7mFANF0dIsrJk6hgntAxPzj4u1g8TD6jGgLoYzCgScK1NtyQPzOxuUSUhwuR6dCZoeKXgoW6VIbNg= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894673432564.930284951357; Thu, 15 Aug 2019 11:44:33 -0700 (PDT) Received: from localhost ([::1]:46216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKjg-0007VH-34 for importer@patchew.org; Thu, 15 Aug 2019 14:44:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37578) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKXD-000310-Pr for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKXA-00020s-AQ for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:31:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37296) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKX1-0001id-PR; Thu, 15 Aug 2019 14:31:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5FE6B317556D; Thu, 15 Aug 2019 18:31:26 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3143600CD; Thu, 15 Aug 2019 18:31:25 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:39 -0500 Message-Id: <20190815183039.4264-10-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 15 Aug 2019 18:31:26 +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 9/9] block/nbd: refactor nbd connection parameters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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'll need some connection parameters to be available all the time to implement nbd reconnect. So, let's refactor them: define additional parameters in BDRVNBDState, drop them from function parameters, drop nbd_client_init and separate options parsing instead from nbd_open. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20190618114328.55249-6-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: Drop useless 'if' before object_unref] Signed-off-by: Eric Blake --- block/nbd.c | 121 ++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index de2a26097bf9..00b8d86783d9 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -73,9 +73,13 @@ typedef struct BDRVNBDState { NBDReply reply; BlockDriverState *bs; - /* For nbd_refresh_filename() */ + /* Connection parameters */ + uint32_t reconnect_delay; SocketAddress *saddr; char *export, *tlscredsid; + QCryptoTLSCreds *tlscreds; + const char *hostname; + char *x_dirty_bitmap; } BDRVNBDState; /* @ret will be used for reconnect in future */ @@ -1182,13 +1186,7 @@ static QIOChannelSocket *nbd_establish_connection(So= cketAddress *saddr, return sioc; } -static int nbd_client_connect(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, Error **errp) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; AioContext *aio_context =3D bdrv_get_aio_context(bs); @@ -1198,33 +1196,33 @@ static int nbd_client_connect(BlockDriverState *bs, * establish TCP connection, return error if it fails * TODO: Configurable retry-until-timeout behaviour. */ - QIOChannelSocket *sioc =3D nbd_establish_connection(saddr, errp); + QIOChannelSocket *sioc =3D nbd_establish_connection(s->saddr, errp); if (!sioc) { return -ECONNREFUSED; } /* NBD handshake */ - trace_nbd_client_connect(export); + trace_nbd_client_connect(s->export); qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL); qio_channel_attach_aio_context(QIO_CHANNEL(sioc), aio_context); s->info.request_sizes =3D true; s->info.structured_reply =3D true; s->info.base_allocation =3D true; - s->info.x_dirty_bitmap =3D g_strdup(x_dirty_bitmap); - s->info.name =3D g_strdup(export ?: ""); - ret =3D nbd_receive_negotiate(aio_context, QIO_CHANNEL(sioc), tlscreds, - hostname, &s->ioc, &s->info, errp); + s->info.x_dirty_bitmap =3D g_strdup(s->x_dirty_bitmap); + s->info.name =3D g_strdup(s->export ?: ""); + ret =3D nbd_receive_negotiate(aio_context, QIO_CHANNEL(sioc), s->tlscr= eds, + s->hostname, &s->ioc, &s->info, errp); g_free(s->info.x_dirty_bitmap); g_free(s->info.name); if (ret < 0) { object_unref(OBJECT(sioc)); return ret; } - if (x_dirty_bitmap && !s->info.base_allocation) { + if (s->x_dirty_bitmap && !s->info.base_allocation) { error_setg(errp, "requested x-dirty-bitmap %s not found", - x_dirty_bitmap); + s->x_dirty_bitmap); ret =3D -EINVAL; goto fail; } @@ -1249,7 +1247,7 @@ static int nbd_client_connect(BlockDriverState *bs, object_ref(OBJECT(s->ioc)); } - trace_nbd_client_connect_success(export); + trace_nbd_client_connect_success(s->export); return 0; @@ -1269,34 +1267,9 @@ static int nbd_client_connect(BlockDriverState *bs, } } -static int nbd_client_init(BlockDriverState *bs, - SocketAddress *saddr, - const char *export, - QCryptoTLSCreds *tlscreds, - const char *hostname, - const char *x_dirty_bitmap, - uint32_t reconnect_delay, - Error **errp) -{ - int ret; - BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; - - s->bs =3D bs; - qemu_co_mutex_init(&s->send_mutex); - qemu_co_queue_init(&s->free_sema); - - ret =3D nbd_client_connect(bs, saddr, export, tlscreds, hostname, - x_dirty_bitmap, errp); - if (ret < 0) { - return ret; - } - - s->connection_co =3D qemu_coroutine_create(nbd_connection_entry, s); - bdrv_inc_in_flight(bs); - aio_co_schedule(bdrv_get_aio_context(bs), s->connection_co); - - return 0; -} +/* + * Parse nbd_open options + */ static int nbd_parse_uri(const char *filename, QDict *options) { @@ -1616,14 +1589,12 @@ static QemuOptsList nbd_runtime_opts =3D { }, }; -static int nbd_open(BlockDriverState *bs, QDict *options, int flags, - Error **errp) +static int nbd_process_options(BlockDriverState *bs, QDict *options, + Error **errp) { BDRVNBDState *s =3D bs->opaque; - QemuOpts *opts =3D NULL; + QemuOpts *opts; Error *local_err =3D NULL; - QCryptoTLSCreds *tlscreds =3D NULL; - const char *hostname =3D NULL; int ret =3D -EINVAL; opts =3D qemu_opts_create(&nbd_runtime_opts, NULL, 0, &error_abort); @@ -1648,8 +1619,8 @@ static int nbd_open(BlockDriverState *bs, QDict *opti= ons, int flags, s->tlscredsid =3D g_strdup(qemu_opt_get(opts, "tls-creds")); if (s->tlscredsid) { - tlscreds =3D nbd_get_tls_creds(s->tlscredsid, errp); - if (!tlscreds) { + s->tlscreds =3D nbd_get_tls_creds(s->tlscredsid, errp); + if (!s->tlscreds) { goto error; } @@ -1658,20 +1629,17 @@ static int nbd_open(BlockDriverState *bs, QDict *op= tions, int flags, error_setg(errp, "TLS only supported over IP sockets"); goto error; } - hostname =3D s->saddr->u.inet.host; + s->hostname =3D s->saddr->u.inet.host; } - /* NBD handshake */ - ret =3D nbd_client_init(bs, s->saddr, s->export, tlscreds, hostname, - qemu_opt_get(opts, "x-dirty-bitmap"), - qemu_opt_get_number(opts, "reconnect-delay", 0), - errp); + s->x_dirty_bitmap =3D g_strdup(qemu_opt_get(opts, "x-dirty-bitmap")); + s->reconnect_delay =3D qemu_opt_get_number(opts, "reconnect-delay", 0); + + ret =3D 0; error: - if (tlscreds) { - object_unref(OBJECT(tlscreds)); - } if (ret < 0) { + object_unref(OBJECT(s->tlscreds)); qapi_free_SocketAddress(s->saddr); g_free(s->export); g_free(s->tlscredsid); @@ -1680,6 +1648,35 @@ static int nbd_open(BlockDriverState *bs, QDict *opt= ions, int flags, return ret; } +static int nbd_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) +{ + int ret; + BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; + + ret =3D nbd_process_options(bs, options, errp); + if (ret < 0) { + return ret; + } + + s->bs =3D bs; + qemu_co_mutex_init(&s->send_mutex); + qemu_co_queue_init(&s->free_sema); + + ret =3D nbd_client_connect(bs, errp); + if (ret < 0) { + return ret; + } + /* successfully connected */ + s->state =3D NBD_CLIENT_CONNECTED; + + s->connection_co =3D qemu_coroutine_create(nbd_connection_entry, s); + bdrv_inc_in_flight(bs); + aio_co_schedule(bdrv_get_aio_context(bs), s->connection_co); + + return 0; +} + static int nbd_co_flush(BlockDriverState *bs) { return nbd_client_co_flush(bs); @@ -1725,9 +1722,11 @@ static void nbd_close(BlockDriverState *bs) nbd_client_close(bs); + object_unref(OBJECT(s->tlscreds)); qapi_free_SocketAddress(s->saddr); g_free(s->export); g_free(s->tlscredsid); + g_free(s->x_dirty_bitmap); } static int64_t nbd_getlength(BlockDriverState *bs) --=20 2.20.1