From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520963867156662.7475255746546; Tue, 13 Mar 2018 10:57:47 -0700 (PDT) Received: from localhost ([::1]:41675 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoBG-0003YD-3D for importer@patchew.org; Tue, 13 Mar 2018 13:57:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUo-0007Fv-7u for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUn-0000pN-8S for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54420 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUi-0000jh-N0; Tue, 13 Mar 2018 13:13:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5466620CC6; Tue, 13 Mar 2018 17:13:48 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id E29672026DFD; Tue, 13 Mar 2018 17:13:47 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:29 -0500 Message-Id: <20180313171345.659672-2-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Mar 2018 17:13:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Mar 2018 17:13:48 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 01/17] iotests: Fix stuck NBD process on 33 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 , "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit afe35cde6 added additional actions to test 33, but forgot to reset the image between tests. As a result, './check -nbd 33' fails because the qemu-nbd process from the first half is still occupying the port, preventing the second half from starting a new qemu-nbd process. Worse, the failure leaves a rogue qemu-nbd process behind even after the test fails, which causes knock-on failures to later tests that also want to start qemu-nbd. Reported-by: Max Reitz Signed-off-by: Eric Blake Message-Id: <20180312211156.452139-1-eblake@redhat.com> Reviewed-by: Max Reitz --- tests/qemu-iotests/033 | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033 index a1d8357331d..ee8a1338bbd 100755 --- a/tests/qemu-iotests/033 +++ b/tests/qemu-iotests/033 @@ -105,6 +105,7 @@ for align in 512 4k; do done done +_cleanup_test_img # Trigger truncate that would shrink qcow2 L1 table, which is done by # clearing one entry (8 bytes) with bdrv_co_pwrite_zeroes() --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520963967320920.002269805591; Tue, 13 Mar 2018 10:59:27 -0700 (PDT) Received: from localhost ([::1]:41685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoCs-00054k-IA for importer@patchew.org; Tue, 13 Mar 2018 13:59:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUp-0007Hw-Aa for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUn-0000pk-L8 for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54262 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUj-0000k5-8R; Tue, 13 Mar 2018 13:13:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF2A07CBBA; Tue, 13 Mar 2018 17:13:48 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 787B02026DFD; Tue, 13 Mar 2018 17:13:48 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:30 -0500 Message-Id: <20180313171345.659672-3-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Mar 2018 17:13:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Mar 2018 17:13:48 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 02/17] nbd/server: move nbd_co_send_structured_error up X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy To be reused in nbd_co_send_sparse_read() in the following patch. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180308184636.178534-2-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- nbd/server.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index e714bfe6a17..3d0f024193c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1342,6 +1342,30 @@ static int coroutine_fn nbd_co_send_structured_read(= NBDClient *client, return nbd_co_send_iov(client, iov, 2, errp); } +static int coroutine_fn nbd_co_send_structured_error(NBDClient *client, + uint64_t handle, + uint32_t error, + const char *msg, + Error **errp) +{ + NBDStructuredError chunk; + int nbd_err =3D system_errno_to_nbd_errno(error); + struct iovec iov[] =3D { + {.iov_base =3D &chunk, .iov_len =3D sizeof(chunk)}, + {.iov_base =3D (char *)msg, .iov_len =3D msg ? strlen(msg) : 0}, + }; + + assert(nbd_err); + trace_nbd_co_send_structured_error(handle, nbd_err, + nbd_err_lookup(nbd_err), msg ? msg = : ""); + set_be_chunk(&chunk.h, NBD_REPLY_FLAG_DONE, NBD_REPLY_TYPE_ERROR, hand= le, + sizeof(chunk) - sizeof(chunk.h) + iov[1].iov_len); + stl_be_p(&chunk.error, nbd_err); + stw_be_p(&chunk.message_length, iov[1].iov_len); + + return nbd_co_send_iov(client, iov, 1 + !!iov[1].iov_len, errp); +} + static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client, uint64_t handle, uint64_t offset, @@ -1401,30 +1425,6 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDC= lient *client, return ret; } -static int coroutine_fn nbd_co_send_structured_error(NBDClient *client, - uint64_t handle, - uint32_t error, - const char *msg, - Error **errp) -{ - NBDStructuredError chunk; - int nbd_err =3D system_errno_to_nbd_errno(error); - struct iovec iov[] =3D { - {.iov_base =3D &chunk, .iov_len =3D sizeof(chunk)}, - {.iov_base =3D (char *)msg, .iov_len =3D msg ? strlen(msg) : 0}, - }; - - assert(nbd_err); - trace_nbd_co_send_structured_error(handle, nbd_err, - nbd_err_lookup(nbd_err), msg ? msg = : ""); - set_be_chunk(&chunk.h, NBD_REPLY_FLAG_DONE, NBD_REPLY_TYPE_ERROR, hand= le, - sizeof(chunk) - sizeof(chunk.h) + iov[1].iov_len); - stl_be_p(&chunk.error, nbd_err); - stw_be_p(&chunk.message_length, iov[1].iov_len); - - return nbd_co_send_iov(client, iov, 1 + !!iov[1].iov_len, errp); -} - /* nbd_co_receive_request * Collect a client request. Return 0 if request looks valid, -EIO to drop * connection right away, and any other negative value to report an error = to --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520963800670576.4973663383469; Tue, 13 Mar 2018 10:56:40 -0700 (PDT) Received: from localhost ([::1]:41672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoAB-0002XI-NS for importer@patchew.org; Tue, 13 Mar 2018 13:56:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUp-0007He-4o for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUn-0000pr-Nf for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39232 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUj-0000kW-Rg; Tue, 13 Mar 2018 13:13:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7679240201A3; Tue, 13 Mar 2018 17:13:49 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F1072026DFD; Tue, 13 Mar 2018 17:13:48 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:31 -0500 Message-Id: <20180313171345.659672-4-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 13 Mar 2018 17:13:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 13 Mar 2018 17:13:49 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 03/17] nbd/server: fix sparse 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: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy In case of io error in nbd_co_send_sparse_read we should not "goto reply:", as it was a fatal error and the common behavior is to disconnect in this case. We should not try to send the client an additional error reply, since we already hit a channel-io error on our previous attempt to send one. Fix this by handling block-status error in nbd_co_send_sparse_read, so nbd_co_send_sparse_read fails only on io error. Then just skip common "reply:" code path in nbd_trip. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180308184636.178534-3-vsementsov@virtuozzo.com> [eblake: grammar tweaks] Signed-off-by: Eric Blake --- nbd/server.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 3d0f024193c..5f292064af0 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1366,6 +1366,10 @@ static int coroutine_fn nbd_co_send_structured_error= (NBDClient *client, return nbd_co_send_iov(client, iov, 1 + !!iov[1].iov_len, errp); } +/* Do a sparse read and send the structured reply to the client. + * Returns -errno if sending fails. bdrv_block_status_above() failure is + * reported to the client, at which point this function succeeds. + */ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client, uint64_t handle, uint64_t offset, @@ -1386,8 +1390,13 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDC= lient *client, bool final; if (status < 0) { - error_setg_errno(errp, -status, "unable to check for holes"); - return status; + char *msg =3D g_strdup_printf("unable to check for holes: %s", + strerror(-status)); + + ret =3D nbd_co_send_structured_error(client, handle, -status, = msg, + errp); + g_free(msg); + return ret; } assert(pnum && pnum <=3D size - progress); final =3D progress + pnum =3D=3D size; @@ -1568,7 +1577,7 @@ static coroutine_fn void nbd_trip(void *opaque) request.from, req->data, request= .len, &local_err); if (ret < 0) { - goto reply; + goto replied; } goto done; } @@ -1665,6 +1674,8 @@ reply: req->data, reply_data_len, &local_e= rr); } g_free(msg); + +replied: if (ret < 0) { error_prepend(&local_err, "Failed to send reply: "); goto disconnect; --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520962832496947.1586191323605; Tue, 13 Mar 2018 10:40:32 -0700 (PDT) Received: from localhost ([::1]:41547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnuW-0004x0-41 for importer@patchew.org; Tue, 13 Mar 2018 13:40:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUp-0007Hk-7e for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUn-0000q3-Sv for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56964 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUk-0000l3-CQ; Tue, 13 Mar 2018 13:13:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C18D4023BB3; Tue, 13 Mar 2018 17:13:50 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B1C72026DFD; Tue, 13 Mar 2018 17:13:49 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:32 -0500 Message-Id: <20180313171345.659672-5-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Mar 2018 17:13:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Mar 2018 17:13:50 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 04/17] nbd/server: fix: check client->closing before sending reply X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Since the unchanged code has just set client->recv_coroutine to NULL before calling nbd_client_receive_next_request(), we are spawning a new coroutine unconditionally, but the first thing that coroutine will do is check for client->closing, making it a no-op if we have already detected that the client is going away. Furthermore, for any error other than EIO (where we disconnect, which itself sets client->closing), if the client has already gone away, we'll probably encounter EIO later in the function and attempt disconnect at that point. Logically, as soon as we know the connection is closing, there is no need to try a likely-to-fail a response or spawn a no-op coroutine. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180308184636.178534-4-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: squash in further reordering: hoist check before spawning next coroutine, and document rationale in commit message] Signed-off-by: Eric Blake --- nbd/server.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 5f292064af0..b230ecb4fb8 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1543,14 +1543,6 @@ static coroutine_fn void nbd_trip(void *opaque) req =3D nbd_request_get(client); ret =3D nbd_co_receive_request(req, &request, &local_err); client->recv_coroutine =3D NULL; - nbd_client_receive_next_request(client); - if (ret =3D=3D -EIO) { - goto disconnect; - } - - if (ret < 0) { - goto reply; - } if (client->closing) { /* @@ -1560,6 +1552,15 @@ static coroutine_fn void nbd_trip(void *opaque) goto done; } + nbd_client_receive_next_request(client); + if (ret =3D=3D -EIO) { + goto disconnect; + } + + if (ret < 0) { + goto reply; + } + switch (request.type) { case NBD_CMD_READ: /* XXX: NBD Protocol only documents use of FUA with WRITE */ --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520962259426178.2131039124107; Tue, 13 Mar 2018 10:30:59 -0700 (PDT) Received: from localhost ([::1]:41490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnlK-0005BV-HS for importer@patchew.org; Tue, 13 Mar 2018 13:30:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUs-0007Lz-V9 for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUq-0000tE-LT for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:58 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41552 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUl-0000lw-62; Tue, 13 Mar 2018 13:13:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3FAB818AAF8; Tue, 13 Mar 2018 17:13:50 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 303F72026DFD; Tue, 13 Mar 2018 17:13:50 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:33 -0500 Message-Id: <20180313171345.659672-6-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 13 Mar 2018 17:13:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 13 Mar 2018 17:13:50 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 05/17] nbd/server: refactor nbd_trip: cmd_read and generic reply X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy nbd_trip has difficult logic when sending replies: it tries to use one code path for all replies. It is ok for simple replies, but is not comfortable for structured replies. Also, two types of error (and corresponding messages in local_err) - fatal (leading to disconnect) and not-fatal (just to be sent to the client) are difficult to follow. To make things a bit clearer, the following is done: - split CMD_READ logic to separate function. It is the most difficult command for now, and it is definitely cramped inside nbd_trip. Also, it is difficult to follow CMD_READ logic, shared between "case NBD_CMD_READ" and "if"s under "reply:" label. - create separate helper function nbd_send_generic_reply() and use it both in new nbd_do_cmd_read and for other commands in nbd_trip instead of common code-path under "reply:" label in nbd_trip. The helper supports an error message, so logic with local_err in nbd_trip is simplified. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180308184636.178534-5-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: grammar tweaks and blank line placement] Signed-off-by: Eric Blake --- nbd/server.c | 176 ++++++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 95 insertions(+), 81 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index b230ecb4fb8..297d314bd0b 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1521,6 +1521,72 @@ static int nbd_co_receive_request(NBDRequestData *re= q, NBDRequest *request, return 0; } +/* Send simple reply without a payload, or a structured error + * @error_msg is ignored if @ret >=3D 0 + * Returns 0 if connection is still live, -errno on failure to talk to cli= ent + */ +static coroutine_fn int nbd_send_generic_reply(NBDClient *client, + uint64_t handle, + int ret, + const char *error_msg, + Error **errp) +{ + if (client->structured_reply && ret < 0) { + return nbd_co_send_structured_error(client, handle, -ret, error_ms= g, + errp); + } else { + return nbd_co_send_simple_reply(client, handle, ret < 0 ? -ret : 0, + NULL, 0, errp); + } +} + +/* Handle NBD_CMD_READ 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_read(NBDClient *client, NBDRequest *req= uest, + uint8_t *data, Error **errp) +{ + int ret; + NBDExport *exp =3D client->exp; + + 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) { + ret =3D blk_co_flush(exp->blk); + if (ret < 0) { + return nbd_send_generic_reply(client, request->handle, ret, + "flush failed", errp); + } + } + + if (client->structured_reply && !(request->flags & NBD_CMD_FLAG_DF) && + request->len) { + return nbd_co_send_sparse_read(client, request->handle, request->f= rom, + data, request->len, errp); + } + + ret =3D blk_pread(exp->blk, request->from + exp->dev_offset, data, + request->len); + if (ret < 0) { + return nbd_send_generic_reply(client, request->handle, ret, + "reading from file failed", errp); + } + + if (client->structured_reply) { + if (request->len) { + return nbd_co_send_structured_read(client, request->handle, + request->from, data, + request->len, true, errp); + } else { + return nbd_co_send_structured_done(client, request->handle, er= rp); + } + } else { + return nbd_co_send_simple_reply(client, request->handle, 0, + data, request->len, errp); + } +} + /* Owns a reference to the NBDClient passed as opaque. */ static coroutine_fn void nbd_trip(void *opaque) { @@ -1530,7 +1596,6 @@ static coroutine_fn void nbd_trip(void *opaque) NBDRequest request =3D { 0 }; /* GCC thinks it can be used uninitia= lized */ int ret; int flags; - int reply_data_len =3D 0; Error *local_err =3D NULL; char *msg =3D NULL; @@ -1558,41 +1623,23 @@ static coroutine_fn void nbd_trip(void *opaque) } if (ret < 0) { - goto reply; + /* It wans't -EIO, so, according to nbd_co_receive_request() + * semantics, we should return the error to the client. */ + Error *export_err =3D local_err; + + local_err =3D NULL; + ret =3D nbd_send_generic_reply(client, request.handle, -EINVAL, + error_get_pretty(export_err), &local_= err); + error_free(export_err); + + goto replied; } switch (request.type) { case NBD_CMD_READ: - /* XXX: NBD Protocol only documents use of FUA with WRITE */ - if (request.flags & NBD_CMD_FLAG_FUA) { - ret =3D blk_co_flush(exp->blk); - if (ret < 0) { - error_setg_errno(&local_err, -ret, "flush failed"); - break; - } - } - - if (client->structured_reply && !(request.flags & NBD_CMD_FLAG_DF)= && - request.len) { - ret =3D nbd_co_send_sparse_read(req->client, request.handle, - request.from, req->data, request= .len, - &local_err); - if (ret < 0) { - goto replied; - } - goto done; - } - - ret =3D blk_pread(exp->blk, request.from + exp->dev_offset, - req->data, request.len); - if (ret < 0) { - error_setg_errno(&local_err, -ret, "reading from file failed"); - break; - } - - reply_data_len =3D request.len; - + ret =3D nbd_do_cmd_read(client, &request, req->data, &local_err); break; + case NBD_CMD_WRITE: flags =3D 0; if (request.flags & NBD_CMD_FLAG_FUA) { @@ -1600,11 +1647,10 @@ static coroutine_fn void nbd_trip(void *opaque) } ret =3D blk_pwrite(exp->blk, request.from + exp->dev_offset, req->data, request.len, flags); - if (ret < 0) { - error_setg_errno(&local_err, -ret, "writing to file failed"); - } - + ret =3D nbd_send_generic_reply(client, request.handle, ret, + "writing to file failed", &local_err); break; + case NBD_CMD_WRITE_ZEROES: flags =3D 0; if (request.flags & NBD_CMD_FLAG_FUA) { @@ -1615,67 +1661,35 @@ static coroutine_fn void nbd_trip(void *opaque) } ret =3D blk_pwrite_zeroes(exp->blk, request.from + exp->dev_offset, request.len, flags); - if (ret < 0) { - error_setg_errno(&local_err, -ret, "writing to file failed"); - } - + ret =3D nbd_send_generic_reply(client, request.handle, ret, + "writing to file failed", &local_err); break; + case NBD_CMD_DISC: /* unreachable, thanks to special case in nbd_co_receive_request()= */ abort(); case NBD_CMD_FLUSH: ret =3D blk_co_flush(exp->blk); - if (ret < 0) { - error_setg_errno(&local_err, -ret, "flush failed"); - } - + ret =3D nbd_send_generic_reply(client, request.handle, ret, + "flush failed", &local_err); break; + case NBD_CMD_TRIM: ret =3D blk_co_pdiscard(exp->blk, request.from + exp->dev_offset, request.len); - if (ret < 0) { - error_setg_errno(&local_err, -ret, "discard failed"); - } - + ret =3D nbd_send_generic_reply(client, request.handle, ret, + "discard failed", &local_err); break; + default: - error_setg(&local_err, "invalid request type (%" PRIu32 ") receive= d", - request.type); - ret =3D -EINVAL; + msg =3D g_strdup_printf("invalid request type (%" PRIu32 ") receiv= ed", + request.type); + ret =3D nbd_send_generic_reply(client, request.handle, -EINVAL, ms= g, + &local_err); + g_free(msg); } -reply: - if (local_err) { - /* If we get here, local_err was not a fatal error, and should be = sent - * to the client. */ - assert(ret < 0); - msg =3D g_strdup(error_get_pretty(local_err)); - error_report_err(local_err); - local_err =3D NULL; - } - - if (client->structured_reply && - (ret < 0 || request.type =3D=3D NBD_CMD_READ)) { - if (ret < 0) { - ret =3D nbd_co_send_structured_error(req->client, request.hand= le, - -ret, msg, &local_err); - } else if (reply_data_len) { - ret =3D nbd_co_send_structured_read(req->client, request.handl= e, - request.from, req->data, - reply_data_len, true, - &local_err); - } else { - ret =3D nbd_co_send_structured_done(req->client, request.handl= e, - &local_err); - } - } else { - ret =3D nbd_co_send_simple_reply(req->client, request.handle, - ret < 0 ? -ret : 0, - req->data, reply_data_len, &local_e= rr); - } - g_free(msg); - replied: if (ret < 0) { error_prepend(&local_err, "Failed to send reply: "); --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520964377374833.6049057649017; Tue, 13 Mar 2018 11:06:17 -0700 (PDT) Received: from localhost ([::1]:41731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoJU-0002g7-Fm for importer@patchew.org; Tue, 13 Mar 2018 14:06:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUr-0007Kd-D3 for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUp-0000sb-SW for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38068 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUl-0000nI-Q9; Tue, 13 Mar 2018 13:13:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A962406802A; Tue, 13 Mar 2018 17:13:51 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0558C2026DFD; Tue, 13 Mar 2018 17:13:50 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:34 -0500 Message-Id: <20180313171345.659672-7-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:51 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 06/17] nbd/server: refactor nbd_trip: split out nbd_handle_request X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Split out request handling logic. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180308184636.178534-6-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: touch up blank line placement] Signed-off-by: Eric Blake --- nbd/server.c | 128 ++++++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 66 insertions(+), 62 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 297d314bd0b..83f21c55912 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1587,17 +1587,78 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *= client, NBDRequest *request, } } +/* Handle NBD request. + * Return -errno if sending fails. Other errors are reported directly to t= he + * client as an error reply. */ +static coroutine_fn int nbd_handle_request(NBDClient *client, + NBDRequest *request, + uint8_t *data, Error **errp) +{ + int ret; + int flags; + NBDExport *exp =3D client->exp; + char *msg; + + switch (request->type) { + case NBD_CMD_READ: + return nbd_do_cmd_read(client, request, data, errp); + + case NBD_CMD_WRITE: + flags =3D 0; + if (request->flags & NBD_CMD_FLAG_FUA) { + flags |=3D BDRV_REQ_FUA; + } + ret =3D blk_pwrite(exp->blk, request->from + exp->dev_offset, + data, request->len, flags); + return nbd_send_generic_reply(client, request->handle, ret, + "writing to file failed", errp); + + case NBD_CMD_WRITE_ZEROES: + flags =3D 0; + if (request->flags & NBD_CMD_FLAG_FUA) { + flags |=3D BDRV_REQ_FUA; + } + if (!(request->flags & NBD_CMD_FLAG_NO_HOLE)) { + flags |=3D BDRV_REQ_MAY_UNMAP; + } + ret =3D blk_pwrite_zeroes(exp->blk, request->from + exp->dev_offse= t, + request->len, flags); + return nbd_send_generic_reply(client, request->handle, ret, + "writing to file failed", errp); + + case NBD_CMD_DISC: + /* unreachable, thanks to special case in nbd_co_receive_request()= */ + abort(); + + case NBD_CMD_FLUSH: + ret =3D blk_co_flush(exp->blk); + return nbd_send_generic_reply(client, request->handle, ret, + "flush failed", errp); + + case NBD_CMD_TRIM: + ret =3D blk_co_pdiscard(exp->blk, request->from + exp->dev_offset, + request->len); + return nbd_send_generic_reply(client, request->handle, ret, + "discard failed", errp); + + default: + msg =3D g_strdup_printf("invalid request type (%" PRIu32 ") receiv= ed", + request->type); + ret =3D nbd_send_generic_reply(client, request->handle, -EINVAL, m= sg, + errp); + g_free(msg); + return ret; + } +} + /* Owns a reference to the NBDClient passed as opaque. */ static coroutine_fn void nbd_trip(void *opaque) { NBDClient *client =3D opaque; - NBDExport *exp =3D client->exp; NBDRequestData *req; NBDRequest request =3D { 0 }; /* GCC thinks it can be used uninitia= lized */ int ret; - int flags; Error *local_err =3D NULL; - char *msg =3D NULL; trace_nbd_trip(); if (client->closing) { @@ -1631,66 +1692,9 @@ static coroutine_fn void nbd_trip(void *opaque) ret =3D nbd_send_generic_reply(client, request.handle, -EINVAL, error_get_pretty(export_err), &local_= err); error_free(export_err); - - goto replied; + } else { + ret =3D nbd_handle_request(client, &request, req->data, &local_err= ); } - - switch (request.type) { - case NBD_CMD_READ: - ret =3D nbd_do_cmd_read(client, &request, req->data, &local_err); - break; - - case NBD_CMD_WRITE: - flags =3D 0; - if (request.flags & NBD_CMD_FLAG_FUA) { - flags |=3D BDRV_REQ_FUA; - } - ret =3D blk_pwrite(exp->blk, request.from + exp->dev_offset, - req->data, request.len, flags); - ret =3D nbd_send_generic_reply(client, request.handle, ret, - "writing to file failed", &local_err); - break; - - case NBD_CMD_WRITE_ZEROES: - flags =3D 0; - if (request.flags & NBD_CMD_FLAG_FUA) { - flags |=3D BDRV_REQ_FUA; - } - if (!(request.flags & NBD_CMD_FLAG_NO_HOLE)) { - flags |=3D BDRV_REQ_MAY_UNMAP; - } - ret =3D blk_pwrite_zeroes(exp->blk, request.from + exp->dev_offset, - request.len, flags); - ret =3D nbd_send_generic_reply(client, request.handle, ret, - "writing to file failed", &local_err); - break; - - case NBD_CMD_DISC: - /* unreachable, thanks to special case in nbd_co_receive_request()= */ - abort(); - - case NBD_CMD_FLUSH: - ret =3D blk_co_flush(exp->blk); - ret =3D nbd_send_generic_reply(client, request.handle, ret, - "flush failed", &local_err); - break; - - case NBD_CMD_TRIM: - ret =3D blk_co_pdiscard(exp->blk, request.from + exp->dev_offset, - request.len); - ret =3D nbd_send_generic_reply(client, request.handle, ret, - "discard failed", &local_err); - break; - - default: - msg =3D g_strdup_printf("invalid request type (%" PRIu32 ") receiv= ed", - request.type); - ret =3D nbd_send_generic_reply(client, request.handle, -EINVAL, ms= g, - &local_err); - g_free(msg); - } - -replied: if (ret < 0) { error_prepend(&local_err, "Failed to send reply: "); goto disconnect; --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520963019613537.1636366635097; Tue, 13 Mar 2018 10:43:39 -0700 (PDT) Received: from localhost ([::1]:41572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnxa-0007tD-RT for importer@patchew.org; Tue, 13 Mar 2018 13:43:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUr-0007K9-2B for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUp-0000ru-BX for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39236 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUm-0000oJ-B7; Tue, 13 Mar 2018 13:13:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E537A40201A8; Tue, 13 Mar 2018 17:13:51 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DA252026DFD; Tue, 13 Mar 2018 17:13:51 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:35 -0500 Message-Id: <20180313171345.659672-8-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 13 Mar 2018 17:13:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 13 Mar 2018 17:13:51 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 07/17] nbd/server: Honor FUA request on NBD_CMD_TRIM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The NBD spec states that since trim requests can affect disk contents, then they should allow for FUA semantics just like writes for ensuring the disk has settled before returning. As bdrv_[co_]pdiscard() does not support a flags argument, we can't pass FUA down the block layer stack, and must therefore emulate it with a flush at the NBD layer. Note that in all reality, generic well-behaved clients will never send TRIM+FUA (in fact, qemu as a client never does, and we have no intention to plumb flags into bdrv_pdiscard). This is because the NBD protocol states that it is unspecified to READ a trimmed area (you might read stale data, all zeroes, or even random unrelated data) without first rewriting it, and even the experimental BLOCK_STATUS extension states that TRIM need not affect reported status. Thus, in the general case, a client cannot tell the difference between an arbitrary server that ignores TRIM, a server that had a power outage without flushing to disk, and a server that actually affected the disk before returning; so waiting for the trim actions to flush to disk makes little sense. However, for a specific client and server pair, where the client knows the server treats TRIM'd areas as guaranteed reads-zero, waiting for a flush makes sense, hence why the protocol documents that FUA is valid on trim. So, even though the NBD protocol doesn't have a way for the server to advertise what effects (if any) TRIM will actually have, and thus any client that relies on specific effects is probably in error, we can at least support a client that requests TRIM+FUA. Signed-off-by: Eric Blake Message-Id: <20180307225732.155835-1-eblake@redhat.com> --- nbd/server.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nbd/server.c b/nbd/server.c index 83f21c55912..4776009a2d1 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1638,6 +1638,9 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, case NBD_CMD_TRIM: ret =3D blk_co_pdiscard(exp->blk, request->from + exp->dev_offset, request->len); + if (ret =3D=3D 0 && request->flags & NBD_CMD_FLAG_FUA) { + ret =3D blk_co_flush(exp->blk); + } return nbd_send_generic_reply(client, request->handle, ret, "discard failed", errp); --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520964185180820.4148648957749; Tue, 13 Mar 2018 11:03:05 -0700 (PDT) Received: from localhost ([::1]:41709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoGI-0008A1-13 for importer@patchew.org; Tue, 13 Mar 2018 14:02:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUs-0007Ly-L9 for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUq-0000tP-NQ for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:13:58 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38072 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUm-0000ov-W5; Tue, 13 Mar 2018 13:13:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 925B8406802E; Tue, 13 Mar 2018 17:13:52 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1737C2026DFD; Tue, 13 Mar 2018 17:13:52 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:36 -0500 Message-Id: <20180313171345.659672-9-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:52 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 08/17] block: let blk_add/remove_aio_context_notifier() tolerate BDS changes 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 , "open list:Block layer core" , Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Commit 2019ba0a0197 ("block: Add AioContextNotifier functions to BB") added blk_add/remove_aio_context_notifier() and implemented them by passing through the bdrv_*() equivalent. This doesn't work across bdrv_append(), which detaches child->bs and re-attaches it to a new BlockDriverState. When blk_remove_aio_context_notifier() is called we will access the new BDS instead of the one where the notifier was added! >From the point of view of the blk_*() API user, changes to the root BDS should be transparent. This patch maintains a list of AioContext notifiers in BlockBackend and adds/removes them from the BlockDriverState as needed. Reported-by: Stefano Panella Cc: Max Reitz Signed-off-by: Stefan Hajnoczi Message-Id: <20180306204819.11266-2-stefanha@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Eric Blake --- block/block-backend.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ block/trace-events | 2 ++ 2 files changed, 65 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index f2e0a855ff7..681b240b126 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -31,6 +31,13 @@ static AioContext *blk_aiocb_get_aio_context(BlockAIOCB *acb); +typedef struct BlockBackendAioNotifier { + void (*attached_aio_context)(AioContext *new_context, void *opaque); + void (*detach_aio_context)(void *opaque); + void *opaque; + QLIST_ENTRY(BlockBackendAioNotifier) list; +} BlockBackendAioNotifier; + struct BlockBackend { char *name; int refcnt; @@ -69,6 +76,7 @@ struct BlockBackend { bool allow_write_beyond_eof; NotifierList remove_bs_notifiers, insert_bs_notifiers; + QLIST_HEAD(, BlockBackendAioNotifier) aio_notifiers; int quiesce_counter; VMChangeStateEntry *vmsh; @@ -247,6 +255,36 @@ static int blk_root_inactivate(BdrvChild *child) return 0; } +static void blk_root_attach(BdrvChild *child) +{ + BlockBackend *blk =3D child->opaque; + BlockBackendAioNotifier *notifier; + + trace_blk_root_attach(child, blk, child->bs); + + QLIST_FOREACH(notifier, &blk->aio_notifiers, list) { + bdrv_add_aio_context_notifier(child->bs, + notifier->attached_aio_context, + notifier->detach_aio_context, + notifier->opaque); + } +} + +static void blk_root_detach(BdrvChild *child) +{ + BlockBackend *blk =3D child->opaque; + BlockBackendAioNotifier *notifier; + + trace_blk_root_detach(child, blk, child->bs); + + QLIST_FOREACH(notifier, &blk->aio_notifiers, list) { + bdrv_remove_aio_context_notifier(child->bs, + notifier->attached_aio_context, + notifier->detach_aio_context, + notifier->opaque); + } +} + static const BdrvChildRole child_root =3D { .inherit_options =3D blk_root_inherit_options, @@ -260,6 +298,9 @@ static const BdrvChildRole child_root =3D { .activate =3D blk_root_activate, .inactivate =3D blk_root_inactivate, + + .attach =3D blk_root_attach, + .detach =3D blk_root_detach, }; /* @@ -287,6 +328,7 @@ BlockBackend *blk_new(uint64_t perm, uint64_t shared_pe= rm) notifier_list_init(&blk->remove_bs_notifiers); notifier_list_init(&blk->insert_bs_notifiers); + QLIST_INIT(&blk->aio_notifiers); QTAILQ_INSERT_TAIL(&block_backends, blk, link); return blk; @@ -364,6 +406,7 @@ static void blk_delete(BlockBackend *blk) } assert(QLIST_EMPTY(&blk->remove_bs_notifiers.notifiers)); assert(QLIST_EMPTY(&blk->insert_bs_notifiers.notifiers)); + assert(QLIST_EMPTY(&blk->aio_notifiers)); QTAILQ_REMOVE(&block_backends, blk, link); drive_info_del(blk->legacy_dinfo); block_acct_cleanup(&blk->stats); @@ -1857,8 +1900,15 @@ void blk_add_aio_context_notifier(BlockBackend *blk, void (*attached_aio_context)(AioContext *new_context, void *opaque= ), void (*detach_aio_context)(void *opaque), void *opaque) { + BlockBackendAioNotifier *notifier; BlockDriverState *bs =3D blk_bs(blk); + notifier =3D g_new(BlockBackendAioNotifier, 1); + notifier->attached_aio_context =3D attached_aio_context; + notifier->detach_aio_context =3D detach_aio_context; + notifier->opaque =3D opaque; + QLIST_INSERT_HEAD(&blk->aio_notifiers, notifier, list); + if (bs) { bdrv_add_aio_context_notifier(bs, attached_aio_context, detach_aio_context, opaque); @@ -1871,12 +1921,25 @@ void blk_remove_aio_context_notifier(BlockBackend *= blk, void (*detach_aio_context)(void *), void *opaque) { + BlockBackendAioNotifier *notifier; BlockDriverState *bs =3D blk_bs(blk); if (bs) { bdrv_remove_aio_context_notifier(bs, attached_aio_context, detach_aio_context, opaque); } + + QLIST_FOREACH(notifier, &blk->aio_notifiers, list) { + if (notifier->attached_aio_context =3D=3D attached_aio_context && + notifier->detach_aio_context =3D=3D detach_aio_context && + notifier->opaque =3D=3D opaque) { + QLIST_REMOVE(notifier, list); + g_free(notifier); + return; + } + } + + abort(); } void blk_add_remove_bs_notifier(BlockBackend *blk, Notifier *notify) diff --git a/block/trace-events b/block/trace-events index 02dd80ff0c3..7493d521dcf 100644 --- a/block/trace-events +++ b/block/trace-events @@ -7,6 +7,8 @@ bdrv_lock_medium(void *bs, bool locked) "bs %p locked %d" # block/block-backend.c blk_co_preadv(void *blk, void *bs, int64_t offset, unsigned int bytes, int= flags) "blk %p bs %p offset %"PRId64" bytes %u flags 0x%x" blk_co_pwritev(void *blk, void *bs, int64_t offset, unsigned int bytes, in= t flags) "blk %p bs %p offset %"PRId64" bytes %u flags 0x%x" +blk_root_attach(void *child, void *blk, void *bs) "child %p blk %p bs %p" +blk_root_detach(void *child, void *blk, void *bs) "child %p blk %p bs %p" # block/io.c bdrv_co_preadv(void *bs, int64_t offset, int64_t nbytes, unsigned int flag= s) "bs %p offset %"PRId64" nbytes %"PRId64" flags 0x%x" --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520964084232637.7489422702922; Tue, 13 Mar 2018 11:01:24 -0700 (PDT) Received: from localhost ([::1]:41702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoEl-0006rZ-Ex for importer@patchew.org; Tue, 13 Mar 2018 14:01:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUu-0007MY-GY for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUs-0000vA-Hs for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54268 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUn-0000pR-Ld; Tue, 13 Mar 2018 13:13:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3F02A7CBBA; Tue, 13 Mar 2018 17:13:53 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id B98B52026DFD; Tue, 13 Mar 2018 17:13:52 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:37 -0500 Message-Id: <20180313171345.659672-10-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Mar 2018 17:13:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Mar 2018 17:13:53 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 09/17] iotests: add 208 nbd-server + blockdev-snapshot-sync test case 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 , "open list:Block layer core" , Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi This test case adds an NBD server export and then invokes blockdev-snapshot-sync, which changes the BlockDriverState node that the NBD server's BlockBackend points to. This is an interesting scenario to test and exercises the code path fixed by the previous commit. Signed-off-by: Stefan Hajnoczi Message-Id: <20180306204819.11266-3-stefanha@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Eric Blake --- tests/qemu-iotests/208 | 55 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/208.out | 9 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 65 insertions(+) create mode 100755 tests/qemu-iotests/208 create mode 100644 tests/qemu-iotests/208.out diff --git a/tests/qemu-iotests/208 b/tests/qemu-iotests/208 new file mode 100755 index 00000000000..4e82b96c829 --- /dev/null +++ b/tests/qemu-iotests/208 @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Creator/Owner: Stefan Hajnoczi +# +# Check that the runtime NBD server does not crash when stopped after +# blockdev-snapshot-sync. + +import iotests + +with iotests.FilePath('disk.img') as disk_img_path, \ + iotests.FilePath('disk-snapshot.img') as disk_snapshot_img_path, \ + iotests.FilePath('nbd.sock') as nbd_sock_path, \ + iotests.VM() as vm: + + img_size =3D '10M' + iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk_img_path, i= mg_size) + + iotests.log('Launching VM...') + (vm.add_drive(disk_img_path, 'node-name=3Ddrive0-node', interface=3D'n= one') + .launch()) + + iotests.log('Starting NBD server...') + iotests.log(vm.qmp('nbd-server-start', addr=3D{ + "type": "unix", + "data": { + "path": nbd_sock_path, + } + })) + + iotests.log('Adding NBD export...') + iotests.log(vm.qmp('nbd-server-add', device=3D'drive0-node', writable= =3DTrue)) + + iotests.log('Creating external snapshot...') + iotests.log(vm.qmp('blockdev-snapshot-sync', + node_name=3D'drive0-node', + snapshot_node_name=3D'drive0-snapshot-node', + snapshot_file=3Ddisk_snapshot_img_path)) + + iotests.log('Stopping NBD server...') + iotests.log(vm.qmp('nbd-server-stop')) diff --git a/tests/qemu-iotests/208.out b/tests/qemu-iotests/208.out new file mode 100644 index 00000000000..3687e9d0dd4 --- /dev/null +++ b/tests/qemu-iotests/208.out @@ -0,0 +1,9 @@ +Launching VM... +Starting NBD server... +{u'return': {}} +Adding NBD export... +{u'return': {}} +Creating external snapshot... +{u'return': {}} +Stopping NBD server... +{u'return': {}} diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index c401791fcdb..890fe91f2b1 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -204,3 +204,4 @@ 205 rw auto quick 206 rw auto 207 rw auto +208 rw auto quick --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520964550799749.6536071649525; Tue, 13 Mar 2018 11:09:10 -0700 (PDT) Received: from localhost ([::1]:41747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoMH-0005Kp-VR for importer@patchew.org; Tue, 13 Mar 2018 14:09:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUu-0007Mb-HC for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUr-0000uU-QZ for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38076 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUo-0000qG-83; Tue, 13 Mar 2018 13:13:54 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C8D29406802A; Tue, 13 Mar 2018 17:13:53 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 632A02024CAB; Tue, 13 Mar 2018 17:13:53 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:38 -0500 Message-Id: <20180313171345.659672-11-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:53 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 10/17] nbd/server: add nbd_opt_invalid helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy NBD_REP_ERR_INVALID is often parameter to nbd_opt_drop and it would be used more in following patches. So, let's add a helper. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20180312152126.286890-2-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- nbd/server.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 4776009a2d1..01ea97afe98 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -218,22 +218,46 @@ nbd_negotiate_send_rep_err(NBDClient *client, uint32_= t type, /* Drop remainder of the current option, and send a reply with the * given error type and message. Return -errno on read or write * failure; or 0 if connection is still live. */ -static int GCC_FMT_ATTR(4, 5) -nbd_opt_drop(NBDClient *client, uint32_t type, Error **errp, - const char *fmt, ...) +static int GCC_FMT_ATTR(4, 0) +nbd_opt_vdrop(NBDClient *client, uint32_t type, Error **errp, + const char *fmt, va_list va) { int ret =3D nbd_drop(client->ioc, client->optlen, errp); - va_list va; client->optlen =3D 0; if (!ret) { - va_start(va, fmt); ret =3D nbd_negotiate_send_rep_verr(client, type, errp, fmt, va); - va_end(va); } return ret; } +static int GCC_FMT_ATTR(4, 5) +nbd_opt_drop(NBDClient *client, uint32_t type, Error **errp, + const char *fmt, ...) +{ + int ret; + va_list va; + + va_start(va, fmt); + ret =3D nbd_opt_vdrop(client, type, errp, fmt, va); + va_end(va); + + return ret; +} + +static int GCC_FMT_ATTR(3, 4) +nbd_opt_invalid(NBDClient *client, Error **errp, const char *fmt, ...) +{ + int ret; + va_list va; + + va_start(va, fmt); + ret =3D nbd_opt_vdrop(client, NBD_REP_ERR_INVALID, errp, fmt, va); + va_end(va); + + return ret; +} + /* Read size bytes from the unparsed payload of the current option. * Return -errno on I/O error, 0 if option was completely handled by * sending a reply about inconsistent lengths, or 1 on success. */ @@ -241,9 +265,9 @@ static int nbd_opt_read(NBDClient *client, void *buffer= , size_t size, Error **errp) { if (size > client->optlen) { - return nbd_opt_drop(client, NBD_REP_ERR_INVALID, errp, - "Inconsistent lengths in option %s", - nbd_opt_lookup(client->opt)); + return nbd_opt_invalid(client, errp, + "Inconsistent lengths in option %s", + nbd_opt_lookup(client->opt)); } client->optlen -=3D size; return qio_channel_read_all(client->ioc, buffer, size, errp) < 0 ? -EI= O : 1; @@ -398,9 +422,8 @@ static int nbd_reject_length(NBDClient *client, bool fa= tal, Error **errp) int ret; assert(client->optlen); - ret =3D nbd_opt_drop(client, NBD_REP_ERR_INVALID, errp, - "option '%s' has unexpected length", - nbd_opt_lookup(client->opt)); + ret =3D nbd_opt_invalid(client, errp, "option '%s' has unexpected leng= th", + nbd_opt_lookup(client->opt)); if (fatal && !ret) { error_setg(errp, "option '%s' has unexpected length", nbd_opt_lookup(client->opt)); @@ -438,8 +461,7 @@ static int nbd_negotiate_handle_info(NBDClient *client,= uint16_t myflags, } be32_to_cpus(&namelen); if (namelen >=3D sizeof(name)) { - return nbd_opt_drop(client, NBD_REP_ERR_INVALID, errp, - "name too long for qemu"); + return nbd_opt_invalid(client, errp, "name too long for qemu"); } rc =3D nbd_opt_read(client, name, namelen, errp); if (rc <=3D 0) { --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520962464672238.0479432005236; Tue, 13 Mar 2018 10:34:24 -0700 (PDT) Received: from localhost ([::1]:41499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnoN-0007lJ-BF for importer@patchew.org; Tue, 13 Mar 2018 13:34:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUw-0007Of-1T for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUu-0000xG-MJ for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54270 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUo-0000qt-NS; Tue, 13 Mar 2018 13:13:54 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5DB537CBBA; Tue, 13 Mar 2018 17:13:54 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECB0F202322B; Tue, 13 Mar 2018 17:13:53 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:39 -0500 Message-Id: <20180313171345.659672-12-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Mar 2018 17:13:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Mar 2018 17:13:54 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 11/17] nbd/server: add nbd_read_opt_name helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Add helper to read name in format: uint32 len (<=3D NBD_MAX_NAME_SIZE) len bytes string (not 0-terminated) The helper will be reused in following patch. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180312152126.286890-3-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: grammar fixes, actually check error] Signed-off-by: Eric Blake --- nbd/server.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 01ea97afe98..280bdbb1040 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -273,6 +273,48 @@ static int nbd_opt_read(NBDClient *client, void *buffe= r, size_t size, return qio_channel_read_all(client->ioc, buffer, size, errp) < 0 ? -EI= O : 1; } +/* nbd_opt_read_name + * + * Read a string with the format: + * uint32_t len (<=3D NBD_MAX_NAME_SIZE) + * len bytes string (not 0-terminated) + * + * @name should be enough to store NBD_MAX_NAME_SIZE+1. + * If @length is non-null, it will be set to the actual string length. + * + * Return -errno on I/O error, 0 if option was completely handled by + * sending a reply about inconsistent lengths, or 1 on success. + */ +static int nbd_opt_read_name(NBDClient *client, char *name, uint32_t *leng= th, + Error **errp) +{ + int ret; + uint32_t len; + + ret =3D nbd_opt_read(client, &len, sizeof(len), errp); + if (ret <=3D 0) { + return ret; + } + cpu_to_be32s(&len); + + if (len > NBD_MAX_NAME_SIZE) { + return nbd_opt_invalid(client, errp, + "Invalid name length: %" PRIu32, len); + } + + ret =3D nbd_opt_read(client, name, len, errp); + if (ret <=3D 0) { + return ret; + } + name[len] =3D '\0'; + + if (length) { + *length =3D len; + } + + return 1; +} + /* Send a single NBD_REP_SERVER reply to NBD_OPT_LIST, including payload. * Return -errno on error, 0 on success. */ static int nbd_negotiate_send_rep_list(NBDClient *client, NBDExport *exp, @@ -455,19 +497,10 @@ static int nbd_negotiate_handle_info(NBDClient *clien= t, uint16_t myflags, 2 bytes: N, number of requests (can be 0) N * 2 bytes: N requests */ - rc =3D nbd_opt_read(client, &namelen, sizeof(namelen), errp); + rc =3D nbd_opt_read_name(client, name, &namelen, errp); if (rc <=3D 0) { return rc; } - be32_to_cpus(&namelen); - if (namelen >=3D sizeof(name)) { - return nbd_opt_invalid(client, errp, "name too long for qemu"); - } - rc =3D nbd_opt_read(client, name, namelen, errp); - if (rc <=3D 0) { - return rc; - } - name[namelen] =3D '\0'; trace_nbd_negotiate_handle_export_name_request(name); rc =3D nbd_opt_read(client, &requests, sizeof(requests), errp); --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520962633341492.8075375554972; Tue, 13 Mar 2018 10:37:13 -0700 (PDT) Received: from localhost ([::1]:41526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnrM-00024q-AU for importer@patchew.org; Tue, 13 Mar 2018 13:37:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnV0-0007UM-BL for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUv-0000xe-5N for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:06 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54276 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUp-0000rc-Eh; Tue, 13 Mar 2018 13:13:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2138D1449; Tue, 13 Mar 2018 17:13:54 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84FEE202322B; Tue, 13 Mar 2018 17:13:54 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:40 -0500 Message-Id: <20180313171345.659672-13-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Mar 2018 17:13:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Mar 2018 17:13:55 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 12/17] nbd: BLOCK_STATUS for standard get_block_status function: server part X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Minimal realization: only one extent in server answer is supported. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180312152126.286890-4-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: tweak whitespace, move constant from .h to .c, improve logic of check_meta_export_name, simplify nbd_negotiate_options by doing more in nbd_negotiate_meta_queries] Signed-off-by: Eric Blake --- nbd/server.c | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 311 insertions(+) diff --git a/nbd/server.c b/nbd/server.c index 280bdbb1040..cea158913ba 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -22,6 +22,8 @@ #include "trace.h" #include "nbd-internal.h" +#define NBD_META_ID_BASE_ALLOCATION 0 + static int system_errno_to_nbd_errno(int err) { switch (err) { @@ -82,6 +84,16 @@ struct NBDExport { static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD_INITIALIZER(export= s); +/* NBDExportMetaContexts represents a list of contexts to be exported, + * as selected by NBD_OPT_SET_META_CONTEXT. Also used for + * NBD_OPT_LIST_META_CONTEXT. */ +typedef struct NBDExportMetaContexts { + char export_name[NBD_MAX_NAME_SIZE + 1]; + bool valid; /* means that negotiation of the option finished without + errors */ + bool base_allocation; /* export base:allocation context (block status)= */ +} NBDExportMetaContexts; + struct NBDClient { int refcount; void (*close_fn)(NBDClient *client, bool negotiated); @@ -102,6 +114,7 @@ struct NBDClient { bool closing; bool structured_reply; + NBDExportMetaContexts export_meta; uint32_t opt; /* Current option being negotiated */ uint32_t optlen; /* remaining length of data in ioc for the option bei= ng @@ -273,6 +286,20 @@ static int nbd_opt_read(NBDClient *client, void *buffe= r, size_t size, return qio_channel_read_all(client->ioc, buffer, size, errp) < 0 ? -EI= O : 1; } +/* Drop size bytes from the unparsed payload of the current option. + * Return -errno on I/O error, 0 if option was completely handled by + * sending a reply about inconsistent lengths, or 1 on success. */ +static int nbd_opt_skip(NBDClient *client, size_t size, Error **errp) +{ + if (size > client->optlen) { + return nbd_opt_invalid(client, errp, + "Inconsistent lengths in option %s", + nbd_opt_lookup(client->opt)); + } + client->optlen -=3D size; + return nbd_drop(client->ioc, size, errp) < 0 ? -EIO : 1; +} + /* nbd_opt_read_name * * Read a string with the format: @@ -372,6 +399,12 @@ static int nbd_negotiate_handle_list(NBDClient *client= , Error **errp) return nbd_negotiate_send_rep(client, NBD_REP_ACK, errp); } +static void nbd_check_meta_export_name(NBDClient *client) +{ + client->export_meta.valid &=3D !strcmp(client->exp->name, + client->export_meta.export_name); +} + /* Send a reply to NBD_OPT_EXPORT_NAME. * Return -errno on error, 0 on success. */ static int nbd_negotiate_handle_export_name(NBDClient *client, @@ -423,6 +456,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, QTAILQ_INSERT_TAIL(&client->exp->clients, client, next); nbd_export_get(client->exp); + nbd_check_meta_export_name(client); return 0; } @@ -616,6 +650,7 @@ static int nbd_negotiate_handle_info(NBDClient *client,= uint16_t myflags, client->exp =3D exp; QTAILQ_INSERT_TAIL(&client->exp->clients, client, next); nbd_export_get(client->exp); + nbd_check_meta_export_name(client); rc =3D 1; } return rc; @@ -670,6 +705,189 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDC= lient *client, return QIO_CHANNEL(tioc); } +/* nbd_negotiate_send_meta_context + * + * Send one chunk of reply to NBD_OPT_{LIST,SET}_META_CONTEXT + * + * For NBD_OPT_LIST_META_CONTEXT @context_id is ignored, 0 is used instead. + */ +static int nbd_negotiate_send_meta_context(NBDClient *client, + const char *context, + uint32_t context_id, + Error **errp) +{ + NBDOptionReplyMetaContext opt; + struct iovec iov[] =3D { + {.iov_base =3D &opt, .iov_len =3D sizeof(opt)}, + {.iov_base =3D (void *)context, .iov_len =3D strlen(context)} + }; + + if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { + context_id =3D 0; + } + + set_be_option_rep(&opt.h, client->opt, NBD_REP_META_CONTEXT, + sizeof(opt) - sizeof(opt.h) + iov[1].iov_len); + stl_be_p(&opt.context_id, context_id); + + return qio_channel_writev_all(client->ioc, iov, 2, errp) < 0 ? -EIO : = 0; +} + +/* nbd_meta_base_query + * + * Handle query to 'base' namespace. For now, only base:allocation context= is + * available in it. 'len' is the amount of text remaining to be read from + * the current name, after the 'base:' portion has been stripped. + * + * Return -errno on I/O error, 0 if option was completely handled by + * sending a reply about inconsistent lengths, or 1 on success. */ +static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *m= eta, + uint32_t len, Error **errp) +{ + int ret; + char query[sizeof("allocation") - 1]; + size_t alen =3D strlen("allocation"); + + if (len =3D=3D 0) { + if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { + meta->base_allocation =3D true; + } + return 1; + } + + if (len !=3D alen) { + return nbd_opt_skip(client, len, errp); + } + + ret =3D nbd_opt_read(client, query, len, errp); + if (ret <=3D 0) { + return ret; + } + + if (strncmp(query, "allocation", alen) =3D=3D 0) { + meta->base_allocation =3D true; + } + + return 1; +} + +/* nbd_negotiate_meta_query + * + * Parse namespace name and call corresponding function to parse body of t= he + * query. + * + * The only supported namespace now is 'base'. + * + * The function aims not wasting time and memory to read long unknown name= space + * names. + * + * Return -errno on I/O error, 0 if option was completely handled by + * sending a reply about inconsistent lengths, or 1 on success. */ +static int nbd_negotiate_meta_query(NBDClient *client, + NBDExportMetaContexts *meta, Error **e= rrp) +{ + int ret; + char query[sizeof("base:") - 1]; + size_t baselen =3D strlen("base:"); + uint32_t len; + + ret =3D nbd_opt_read(client, &len, sizeof(len), errp); + if (ret <=3D 0) { + return ret; + } + cpu_to_be32s(&len); + + /* The only supported namespace for now is 'base'. So query should sta= rt + * with 'base:'. Otherwise, we can ignore it and skip the remainder. */ + if (len < baselen) { + return nbd_opt_skip(client, len, errp); + } + + len -=3D baselen; + ret =3D nbd_opt_read(client, query, baselen, errp); + if (ret <=3D 0) { + return ret; + } + if (strncmp(query, "base:", baselen) !=3D 0) { + return nbd_opt_skip(client, len, errp); + } + + return nbd_meta_base_query(client, meta, len, errp); +} + +/* nbd_negotiate_meta_queries + * Handle NBD_OPT_LIST_META_CONTEXT and NBD_OPT_SET_META_CONTEXT + * + * Return -errno on I/O error, or 0 if option was completely handled. */ +static int nbd_negotiate_meta_queries(NBDClient *client, + NBDExportMetaContexts *meta, Error *= *errp) +{ + int ret; + NBDExport *exp; + NBDExportMetaContexts local_meta; + uint32_t nb_queries; + int i; + + if (!client->structured_reply) { + return nbd_opt_invalid(client, errp, + "request option '%s' when structured reply " + "is not negotiated", + nbd_opt_lookup(client->opt)); + } + + if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { + /* Only change the caller's meta on SET. */ + meta =3D &local_meta; + } + + memset(meta, 0, sizeof(*meta)); + + ret =3D nbd_opt_read_name(client, meta->export_name, NULL, errp); + if (ret <=3D 0) { + return ret; + } + + exp =3D nbd_export_find(meta->export_name); + if (exp =3D=3D NULL) { + return nbd_opt_drop(client, NBD_REP_ERR_UNKNOWN, errp, + "export '%s' not present", meta->export_name); + } + + ret =3D nbd_opt_read(client, &nb_queries, sizeof(nb_queries), errp); + if (ret <=3D 0) { + return ret; + } + cpu_to_be32s(&nb_queries); + + if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT && !nb_queries) { + /* enable all known contexts */ + meta->base_allocation =3D true; + } else { + for (i =3D 0; i < nb_queries; ++i) { + ret =3D nbd_negotiate_meta_query(client, meta, errp); + if (ret <=3D 0) { + return ret; + } + } + } + + if (meta->base_allocation) { + ret =3D nbd_negotiate_send_meta_context(client, "base:allocation", + NBD_META_ID_BASE_ALLOCATION, + errp); + if (ret < 0) { + return ret; + } + } + + ret =3D nbd_negotiate_send_rep(client, NBD_REP_ACK, errp); + if (ret =3D=3D 0) { + meta->valid =3D true; + } + + return ret; +} + /* nbd_negotiate_options * Process all NBD_OPT_* client option commands, during fixed newstyle * negotiation. @@ -860,6 +1078,12 @@ static int nbd_negotiate_options(NBDClient *client, u= int16_t myflags, } break; + case NBD_OPT_LIST_META_CONTEXT: + case NBD_OPT_SET_META_CONTEXT: + ret =3D nbd_negotiate_meta_queries(client, &client->export= _meta, + errp); + break; + default: ret =3D nbd_opt_drop(client, NBD_REP_ERR_UNSUP, errp, "Unsupported option %" PRIu32 " (%s)", @@ -1489,6 +1713,79 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDC= lient *client, return ret; } +static int blockstatus_to_extent_be(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, NBDExtent *extent) +{ + uint64_t remaining_bytes =3D bytes; + + while (remaining_bytes) { + uint32_t flags; + int64_t num; + int ret =3D bdrv_block_status_above(bs, NULL, offset, remaining_by= tes, + &num, NULL, NULL); + if (ret < 0) { + return ret; + } + + flags =3D (ret & BDRV_BLOCK_ALLOCATED ? 0 : NBD_STATE_HOLE) | + (ret & BDRV_BLOCK_ZERO ? NBD_STATE_ZERO : 0); + + if (remaining_bytes =3D=3D bytes) { + extent->flags =3D flags; + } + + if (flags !=3D extent->flags) { + break; + } + + offset +=3D num; + remaining_bytes -=3D num; + } + + cpu_to_be32s(&extent->flags); + extent->length =3D cpu_to_be32(bytes - remaining_bytes); + + return 0; +} + +/* nbd_co_send_extents + * @extents should be in big-endian */ +static int nbd_co_send_extents(NBDClient *client, uint64_t handle, + NBDExtent *extents, unsigned nb_extents, + uint32_t context_id, Error **errp) +{ + NBDStructuredMeta chunk; + + struct iovec iov[] =3D { + {.iov_base =3D &chunk, .iov_len =3D sizeof(chunk)}, + {.iov_base =3D extents, .iov_len =3D nb_extents * sizeof(extents[0= ])} + }; + + set_be_chunk(&chunk.h, NBD_REPLY_FLAG_DONE, NBD_REPLY_TYPE_BLOCK_STATU= S, + handle, sizeof(chunk) - sizeof(chunk.h) + iov[1].iov_len); + stl_be_p(&chunk.context_id, context_id); + + return nbd_co_send_iov(client, iov, 2, errp); +} + +/* Get block status from the exported device and send it to the client */ +static int nbd_co_send_block_status(NBDClient *client, uint64_t handle, + BlockDriverState *bs, uint64_t offset, + uint64_t length, uint32_t context_id, + Error **errp) +{ + int ret; + NBDExtent extent; + + ret =3D blockstatus_to_extent_be(bs, offset, length, &extent); + if (ret < 0) { + return nbd_co_send_structured_error( + client, handle, -ret, "can't get block status", errp); + } + + return nbd_co_send_extents(client, handle, &extent, 1, context_id, err= p); +} + /* nbd_co_receive_request * Collect a client request. Return 0 if request looks valid, -EIO to drop * connection right away, and any other negative value to report an error = to @@ -1566,6 +1863,8 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, valid_flags |=3D NBD_CMD_FLAG_DF; } else if (request->type =3D=3D NBD_CMD_WRITE_ZEROES) { valid_flags |=3D NBD_CMD_FLAG_NO_HOLE; + } else if (request->type =3D=3D NBD_CMD_BLOCK_STATUS) { + valid_flags |=3D NBD_CMD_FLAG_REQ_ONE; } if (request->flags & ~valid_flags) { error_setg(errp, "unsupported flags for command %s (got 0x%x)", @@ -1699,6 +1998,18 @@ static coroutine_fn int nbd_handle_request(NBDClient= *client, return nbd_send_generic_reply(client, request->handle, ret, "discard failed", errp); + case NBD_CMD_BLOCK_STATUS: + if (client->export_meta.valid && client->export_meta.base_allocati= on) { + return nbd_co_send_block_status(client, request->handle, + blk_bs(exp->blk), request->fro= m, + request->len, + NBD_META_ID_BASE_ALLOCATION, e= rrp); + } else { + return nbd_send_generic_reply(client, request->handle, -EINVAL, + "CMD_BLOCK_STATUS not negotiated= ", + errp); + } + default: msg =3D g_strdup_printf("invalid request type (%" PRIu32 ") receiv= ed", request->type); --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520964718581316.1652411168475; Tue, 13 Mar 2018 11:11:58 -0700 (PDT) Received: from localhost ([::1]:41767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoOz-0007xB-Lb for importer@patchew.org; Tue, 13 Mar 2018 14:11:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUv-0007OA-K7 for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUu-0000xM-OX for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38080 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUq-0000sT-1r; Tue, 13 Mar 2018 13:13:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8EBC406802E; Tue, 13 Mar 2018 17:13:55 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 239962026DFD; Tue, 13 Mar 2018 17:13:55 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:41 -0500 Message-Id: <20180313171345.659672-14-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:55 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 13/17] block/nbd-client: save first fatal error in nbd_iter_error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy It is ok, that fatal error hides previous not fatal, but hiding first fatal error is a bad feature. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20180312152126.286890-5-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 7b68499b76a..0d9f73a137f 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -481,6 +481,7 @@ static coroutine_fn int nbd_co_receive_one_chunk( typedef struct NBDReplyChunkIter { int ret; + bool fatal; Error *err; bool done, only_structured; } NBDReplyChunkIter; @@ -490,11 +491,12 @@ static void nbd_iter_error(NBDReplyChunkIter *iter, b= ool fatal, { assert(ret < 0); - if (fatal || iter->ret =3D=3D 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; iter->ret =3D ret; error_propagate(&iter->err, *local_err); } else { --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520964881768782.0393554086421; Tue, 13 Mar 2018 11:14:41 -0700 (PDT) Received: from localhost ([::1]:41798 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoRc-00024W-Rq for importer@patchew.org; Tue, 13 Mar 2018 14:14:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUy-0007Sx-Vg for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUx-0000zZ-37 for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:04 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38082 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUq-0000tA-Q4; Tue, 13 Mar 2018 13:13:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A2CA4068031; Tue, 13 Mar 2018 17:13:56 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id D393C2024CAB; Tue, 13 Mar 2018 17:13:55 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:42 -0500 Message-Id: <20180313171345.659672-15-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Mar 2018 17:13:56 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 14/17] nbd: BLOCK_STATUS for standard get_block_status function: client part X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Minimal realization: only one extent in server answer is supported. Flag NBD_CMD_FLAG_REQ_ONE is used to force this behavior. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180312152126.286890-6-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: grammar tweaks, fix min_block check and 32-bit cap, use -1 instead of errno on failure in nbd_negotiate_simple_meta_context] Signed-off-by: Eric Blake --- block/nbd-client.h | 6 +++ include/block/nbd.h | 3 ++ block/nbd-client.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ block/nbd.c | 3 ++ nbd/client.c | 117 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 270 insertions(+) diff --git a/block/nbd-client.h b/block/nbd-client.h index 612c4c21a0c..0ece76e5aff 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -61,4 +61,10 @@ void nbd_client_detach_aio_context(BlockDriverState *bs); void nbd_client_attach_aio_context(BlockDriverState *bs, AioContext *new_context); +int coroutine_fn nbd_client_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file); + #endif /* NBD_CLIENT_H */ diff --git a/include/block/nbd.h b/include/block/nbd.h index 2285637e673..fcdcd545023 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -260,6 +260,7 @@ struct NBDExportInfo { /* In-out fields, set by client before nbd_receive_negotiate() and * updated by server results during nbd_receive_negotiate() */ bool structured_reply; + bool base_allocation; /* base:allocation context for NBD_CMD_BLOCK_STA= TUS */ /* Set by server results during nbd_receive_negotiate() */ uint64_t size; @@ -267,6 +268,8 @@ struct NBDExportInfo { uint32_t min_block; uint32_t opt_block; uint32_t max_block; + + uint32_t meta_base_allocation_id; }; typedef struct NBDExportInfo NBDExportInfo; diff --git a/block/nbd-client.c b/block/nbd-client.c index 0d9f73a137f..be160052cb1 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -228,6 +228,48 @@ static int nbd_parse_offset_hole_payload(NBDStructured= ReplyChunk *chunk, return 0; } +/* nbd_parse_blockstatus_payload + * support only one extent in reply and only for + * base:allocation context + */ +static int nbd_parse_blockstatus_payload(NBDClientSession *client, + NBDStructuredReplyChunk *chunk, + uint8_t *payload, uint64_t orig_l= ength, + NBDExtent *extent, Error **errp) +{ + uint32_t context_id; + + if (chunk->length !=3D sizeof(context_id) + sizeof(extent)) { + error_setg(errp, "Protocol error: invalid payload for " + "NBD_REPLY_TYPE_BLOCK_STATUS"); + return -EINVAL; + } + + context_id =3D payload_advance32(&payload); + if (client->info.meta_base_allocation_id !=3D context_id) { + error_setg(errp, "Protocol error: unexpected context id %d for " + "NBD_REPLY_TYPE_BLOCK_STATUS, when negotiated con= text " + "id is %d", context_id, + client->info.meta_base_allocation_id); + return -EINVAL; + } + + extent->length =3D payload_advance32(&payload); + extent->flags =3D payload_advance32(&payload); + + if (extent->length =3D=3D 0 || + (client->info.min_block && !QEMU_IS_ALIGNED(extent->length, + client->info.min_block= )) || + extent->length > orig_length) + { + error_setg(errp, "Protocol error: server sent status chunk with " + "invalid length"); + return -EINVAL; + } + + return 0; +} + /* nbd_parse_error_payload * on success @errp contains message describing nbd error reply */ @@ -642,6 +684,60 @@ static int nbd_co_receive_cmdread_reply(NBDClientSessi= on *s, uint64_t handle, return iter.ret; } +static int nbd_co_receive_blockstatus_reply(NBDClientSession *s, + uint64_t handle, uint64_t leng= th, + NBDExtent *extent, Error **err= p) +{ + NBDReplyChunkIter iter; + NBDReply reply; + void *payload =3D NULL; + Error *local_err =3D NULL; + bool received =3D false; + + NBD_FOREACH_REPLY_CHUNK(s, iter, handle, s->info.structured_reply, + NULL, &reply, &payload) + { + int ret; + NBDStructuredReplyChunk *chunk =3D &reply.structured; + + assert(nbd_reply_is_structured(&reply)); + + switch (chunk->type) { + case NBD_REPLY_TYPE_BLOCK_STATUS: + 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); + } + received =3D true; + + ret =3D nbd_parse_blockstatus_payload(s, &reply.structured, + payload, length, extent, + &local_err); + if (ret < 0) { + s->quit =3D true; + nbd_iter_error(&iter, true, ret, &local_err); + } + break; + default: + if (!nbd_reply_type_is_error(chunk->type)) { + s->quit =3D true; + error_setg(&local_err, + "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); + } + } + + g_free(payload); + payload =3D NULL; + } + + error_propagate(errp, iter.err); + return iter.ret; +} + static int nbd_co_request(BlockDriverState *bs, NBDRequest *request, QEMUIOVector *write_qiov) { @@ -784,6 +880,50 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64= _t offset, int bytes) return nbd_co_request(bs, &request, NULL); } +int coroutine_fn nbd_client_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file) +{ + int64_t ret; + NBDExtent extent; + NBDClientSession *client =3D nbd_get_client_session(bs); + Error *local_err =3D NULL; + + NBDRequest request =3D { + .type =3D NBD_CMD_BLOCK_STATUS, + .from =3D offset, + .len =3D MIN(MIN_NON_ZERO(QEMU_ALIGN_DOWN(INT_MAX, + bs->bl.request_alignment), + client->info.max_block), bytes), + .flags =3D NBD_CMD_FLAG_REQ_ONE, + }; + + if (!client->info.base_allocation) { + *pnum =3D bytes; + return BDRV_BLOCK_DATA; + } + + ret =3D nbd_co_send_request(bs, &request, NULL); + if (ret < 0) { + return ret; + } + + ret =3D nbd_co_receive_blockstatus_reply(client, request.handle, bytes, + &extent, &local_err); + if (local_err) { + error_report_err(local_err); + } + if (ret < 0) { + return ret; + } + + *pnum =3D extent.length; + return (extent.flags & NBD_STATE_HOLE ? 0 : BDRV_BLOCK_DATA) | + (extent.flags & NBD_STATE_ZERO ? BDRV_BLOCK_ZERO : 0); +} + void nbd_client_detach_aio_context(BlockDriverState *bs) { NBDClientSession *client =3D nbd_get_client_session(bs); @@ -828,6 +968,7 @@ int nbd_client_init(BlockDriverState *bs, client->info.request_sizes =3D true; client->info.structured_reply =3D true; + client->info.base_allocation =3D true; ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), export, tlscreds, hostname, &client->ioc, &client->info, errp); diff --git a/block/nbd.c b/block/nbd.c index d4e4172c08c..1e2b3ba2d3b 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -585,6 +585,7 @@ static BlockDriver bdrv_nbd =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_co_block_status =3D nbd_client_co_block_status, }; static BlockDriver bdrv_nbd_tcp =3D { @@ -604,6 +605,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_co_block_status =3D nbd_client_co_block_status, }; static BlockDriver bdrv_nbd_unix =3D { @@ -623,6 +625,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_co_block_status =3D nbd_client_co_block_status, }; static void bdrv_nbd_init(void) diff --git a/nbd/client.c b/nbd/client.c index dcad23a0531..9b9b7f0ea29 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -595,6 +595,111 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *i= oc, return QIO_CHANNEL(tioc); } +/* nbd_negotiate_simple_meta_context: + * Set one meta context. Simple means that reply must contain zero (not + * negotiated) or one (negotiated) contexts. More contexts would be consid= ered + * as a protocol error. It's also implied that meta-data query equals quer= ied + * context name, so, if server replies with something different then @cont= ext, + * it considered as error too. + * return 1 for successful negotiation, context_id is set + * 0 if operation is unsupported, + * -1 with errp set for any other error + */ +static int nbd_negotiate_simple_meta_context(QIOChannel *ioc, + const char *export, + const char *context, + uint32_t *context_id, + Error **errp) +{ + int ret; + NBDOptionReply reply; + uint32_t received_id; + bool received; + uint32_t export_len =3D strlen(export); + uint32_t context_len =3D strlen(context); + uint32_t data_len =3D sizeof(export_len) + export_len + + sizeof(uint32_t) + /* number of queries */ + sizeof(context_len) + context_len; + char *data =3D g_malloc(data_len); + char *p =3D data; + + stl_be_p(p, export_len); + memcpy(p +=3D sizeof(export_len), export, export_len); + stl_be_p(p +=3D export_len, 1); + stl_be_p(p +=3D sizeof(uint32_t), context_len); + memcpy(p +=3D sizeof(context_len), context, context_len); + + ret =3D nbd_send_option_request(ioc, NBD_OPT_SET_META_CONTEXT, data_le= n, data, + errp); + g_free(data); + if (ret < 0) { + return ret; + } + + if (nbd_receive_option_reply(ioc, NBD_OPT_SET_META_CONTEXT, &reply, + errp) < 0) + { + return -1; + } + + ret =3D nbd_handle_reply_err(ioc, &reply, errp); + if (ret <=3D 0) { + return ret; + } + + if (reply.type =3D=3D NBD_REP_META_CONTEXT) { + char *name; + size_t len; + + if (nbd_read(ioc, &received_id, sizeof(received_id), errp) < 0) { + return -1; + } + be32_to_cpus(&received_id); + + len =3D reply.length - sizeof(received_id); + name =3D g_malloc(len + 1); + if (nbd_read(ioc, name, len, errp) < 0) { + g_free(name); + return -1; + } + name[len] =3D '\0'; + if (strcmp(context, name)) { + error_setg(errp, "Failed to negotiate meta context '%s', serve= r " + "answered with different context '%s'", context, + name); + g_free(name); + return -1; + } + g_free(name); + + received =3D true; + + /* receive NBD_REP_ACK */ + if (nbd_receive_option_reply(ioc, NBD_OPT_SET_META_CONTEXT, &reply, + errp) < 0) + { + return -1; + } + + ret =3D nbd_handle_reply_err(ioc, &reply, errp); + if (ret <=3D 0) { + return ret; + } + } + + if (reply.type !=3D NBD_REP_ACK) { + error_setg(errp, "Unexpected reply type %" PRIx32 " expected %x", + reply.type, NBD_REP_ACK); + return -1; + } + + if (received) { + *context_id =3D received_id; + return 1; + } + + return 0; +} int nbd_receive_negotiate(QIOChannel *ioc, const char *name, QCryptoTLSCreds *tlscreds, const char *hostname, @@ -606,10 +711,12 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, int rc; bool zeroes =3D true; bool structured_reply =3D info->structured_reply; + bool base_allocation =3D info->base_allocation; trace_nbd_receive_negotiate(tlscreds, hostname ? hostname : ""); info->structured_reply =3D false; + info->base_allocation =3D false; rc =3D -EINVAL; if (outioc) { @@ -700,6 +807,16 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char = *name, info->structured_reply =3D result =3D=3D 1; } + if (info->structured_reply && base_allocation) { + result =3D nbd_negotiate_simple_meta_context( + ioc, name, "base:allocation", + &info->meta_base_allocation_id, errp); + if (result < 0) { + goto fail; + } + info->base_allocation =3D result =3D=3D 1; + } + /* Try NBD_OPT_GO first - if it works, we are done (it * also gives us a good message if the server requires * TLS). If it is not available, fall back to --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520964635355154.84858932728127; Tue, 13 Mar 2018 11:10:35 -0700 (PDT) Received: from localhost ([::1]:41755 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoNe-0006db-IF for importer@patchew.org; Tue, 13 Mar 2018 14:10:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUz-0007U3-UI for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUw-0000ys-2u for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:05 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56972 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUr-0000uH-RP; Tue, 13 Mar 2018 13:13:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 647B7406E8B9; Tue, 13 Mar 2018 17:13:57 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EA59202322D; Tue, 13 Mar 2018 17:13:56 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:43 -0500 Message-Id: <20180313171345.659672-16-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Mar 2018 17:13:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Mar 2018 17:13:57 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 15/17] iotests.py: tiny refactor: move system imports up 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:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20180312152126.286890-7-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/iotests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 1bcc9ca57dc..c1302a2f9b1 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -23,13 +23,14 @@ import subprocess import string import unittest import sys -sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scrip= ts')) -import qtest import struct import json import signal import logging +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scrip= ts')) +import qtest + # This will not work if arguments contain spaces but is necessary if we # want to support the override options that ./check supports. --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520964465166796.9006774123868; Tue, 13 Mar 2018 11:07:45 -0700 (PDT) Received: from localhost ([::1]:41737 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoKt-000404-BM for importer@patchew.org; Tue, 13 Mar 2018 14:07:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnV1-0007VQ-VY for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUv-0000yf-VB for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56974 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUs-0000un-D4; Tue, 13 Mar 2018 13:13:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A463406E8BD; Tue, 13 Mar 2018 17:13:58 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88D56202322C; Tue, 13 Mar 2018 17:13:57 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:44 -0500 Message-Id: <20180313171345.659672-17-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Mar 2018 17:13:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Mar 2018 17:13:58 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 16/17] iotests: add file_path helper 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:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Simple way to have auto generated filenames with auto cleanup. Like FilePath but without using 'with' statement and without additional indentation of the whole test. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180312152126.286890-8-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: grammar tweak] Signed-off-by: Eric Blake --- tests/qemu-iotests/iotests.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index c1302a2f9b1..90cd751e2af 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -27,6 +27,7 @@ import struct import json import signal import logging +import atexit sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scrip= ts')) import qtest @@ -250,6 +251,37 @@ class FilePath(object): return False +def file_path_remover(): + for path in reversed(file_path_remover.paths): + try: + os.remove(path) + except OSError: + pass + + +def file_path(*names): + ''' Another way to get auto-generated filename that cleans itself up. + + Use is as simple as: + + img_a, img_b =3D file_path('a.img', 'b.img') + sock =3D file_path('socket') + ''' + + if not hasattr(file_path_remover, 'paths'): + file_path_remover.paths =3D [] + atexit.register(file_path_remover) + + paths =3D [] + for name in names: + filename =3D '{0}-{1}'.format(os.getpid(), name) + path =3D os.path.join(test_dir, filename) + file_path_remover.paths.append(path) + paths.append(path) + + return paths[0] if len(paths) =3D=3D 1 else paths + + class VM(qtest.QEMUQtestMachine): '''A QEMU VM''' --=20 2.14.3 From nobody Tue Apr 16 20:42:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520964286930643.9128560991018; Tue, 13 Mar 2018 11:04:46 -0700 (PDT) Received: from localhost ([::1]:41721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoI2-0001P3-1L for importer@patchew.org; Tue, 13 Mar 2018 14:04:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnUx-0007RN-PT for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnUw-0000zA-IP for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:14:03 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56978 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evnUt-0000va-1r; Tue, 13 Mar 2018 13:13:59 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4B5D406E8C3; Tue, 13 Mar 2018 17:13:58 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 308A82026DFD; Tue, 13 Mar 2018 17:13:58 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 12:13:45 -0500 Message-Id: <20180313171345.659672-18-eblake@redhat.com> In-Reply-To: <20180313171345.659672-1-eblake@redhat.com> References: <20180313171345.659672-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Mar 2018 17:13:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Mar 2018 17:13:58 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 17/17] iotests: new test 209 for NBD BLOCK_STATUS 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:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180312152126.286890-9-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/209 | 34 ++++++++++++++++++++++++++++++++++ tests/qemu-iotests/209.out | 2 ++ tests/qemu-iotests/group | 1 + 3 files changed, 37 insertions(+) create mode 100755 tests/qemu-iotests/209 create mode 100644 tests/qemu-iotests/209.out diff --git a/tests/qemu-iotests/209 b/tests/qemu-iotests/209 new file mode 100755 index 00000000000..259e991ec6e --- /dev/null +++ b/tests/qemu-iotests/209 @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# +# Tests for NBD BLOCK_STATUS extension +# +# Copyright (c) 2018 Virtuozzo International GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import iotests +from iotests import qemu_img_create, qemu_io, qemu_img_verbose, qemu_nbd, \ + file_path + +iotests.verify_image_format(supported_fmts=3D['qcow2']) + +disk, nbd_sock =3D file_path('disk', 'nbd-sock') +nbd_uri =3D 'nbd+unix:///exp?socket=3D' + nbd_sock + +qemu_img_create('-f', iotests.imgfmt, disk, '1M') +qemu_io('-f', iotests.imgfmt, '-c', 'write 0 512K', disk) + +qemu_nbd('-k', nbd_sock, '-x', 'exp', '-f', iotests.imgfmt, disk) +qemu_img_verbose('map', '-f', 'raw', '--output=3Djson', nbd_uri) diff --git a/tests/qemu-iotests/209.out b/tests/qemu-iotests/209.out new file mode 100644 index 00000000000..0d29724e84a --- /dev/null +++ b/tests/qemu-iotests/209.out @@ -0,0 +1,2 @@ +[{ "start": 0, "length": 524288, "depth": 0, "zero": false, "data": true}, +{ "start": 524288, "length": 524288, "depth": 0, "zero": true, "data": fal= se}] diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 890fe91f2b1..624e1fbd4fe 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -205,3 +205,4 @@ 206 rw auto 207 rw auto 208 rw auto quick +209 rw auto quick --=20 2.14.3