From nobody Sun May 5 19:01:59 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513820519586169.40910819852365; Wed, 20 Dec 2017 17:41:59 -0800 (PST) Received: from localhost ([::1]:52125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRprs-0003Am-Gh for importer@patchew.org; Wed, 20 Dec 2017 20:41:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRpmN-0007KQ-3f for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRpmL-0001Vq-E4 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51896) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRpmG-0001Ql-TR; Wed, 20 Dec 2017 20:36:05 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1960581DEA; Thu, 21 Dec 2017 01:36:04 +0000 (UTC) Received: from red.redhat.com (ovpn-120-109.rdu2.redhat.com [10.10.120.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D7645C88F; Thu, 21 Dec 2017 01:36:03 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 20 Dec 2017 19:35:57 -0600 Message-Id: <20171221013600.17648-2-eblake@redhat.com> In-Reply-To: <20171221013600.17648-1-eblake@redhat.com> References: <20171221013600.17648-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 21 Dec 2017 01:36:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/4] nbd/server: Implement sparse reads atop structured 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 , "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 reason that NBD added structured reply in the first place was to allow for efficient reads of sparse files, by allowing the reply to include chunks to quickly communicate holes to the client without sending lots of zeroes over the wire. Time to implement this in the server; our client can already read such data. We can only skip holes insofar as the block layer can query them; and only if the client is okay with a fragmented request (if a client requests NBD_CMD_FLAG_DF and the entire read is a hole, we could technically return a single NBD_REPLY_TYPE_OFFSET_HOLE, but that's a fringe case not worth catering to here). Sadly, the control flow is a bit wonkier than I would have preferred, but it was minimally invasive to have a split in the action between a fragmented read (handled directly where we recognize NBD_CMD_READ with the right conditions, and sending multiple chunks) vs. a single read (handled at the end of nbd_trip, for both simple and structured replies, when we know there is only one thing being read). Likewise, I didn't make any effort to optimize the final chunk of a fragmented read to set the NBD_REPLY_FLAG_DONE, but unconditionally send that as a separate NBD_REPLY_TYPE_NONE. Signed-off-by: Eric Blake Message-Id: <20171107030912.23930-2-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- nbd/trace-events | 1 + 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 92c0fdd03b..be7310cb41 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1303,6 +1303,7 @@ static int coroutine_fn nbd_co_send_structured_read(N= BDClient *client, uint64_t offset, void *data, size_t size, + bool final, Error **errp) { NBDStructuredReadData chunk; @@ -1313,13 +1314,73 @@ static int coroutine_fn nbd_co_send_structured_read= (NBDClient *client, assert(size); trace_nbd_co_send_structured_read(handle, offset, data, size); - set_be_chunk(&chunk.h, NBD_REPLY_FLAG_DONE, NBD_REPLY_TYPE_OFFSET_DATA, - handle, sizeof(chunk) - sizeof(chunk.h) + size); + set_be_chunk(&chunk.h, final ? NBD_REPLY_FLAG_DONE : 0, + NBD_REPLY_TYPE_OFFSET_DATA, handle, + sizeof(chunk) - sizeof(chunk.h) + size); stq_be_p(&chunk.offset, offset); return nbd_co_send_iov(client, iov, 2, errp); } +static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client, + uint64_t handle, + uint64_t offset, + uint8_t *data, + size_t size, + Error **errp) +{ + int ret =3D 0; + NBDExport *exp =3D client->exp; + size_t progress =3D 0; + + while (progress < size) { + int64_t pnum; + int status =3D bdrv_block_status_above(blk_bs(exp->blk), NULL, + offset + progress, + size - progress, &pnum, NULL, + NULL); + + if (status < 0) { + error_setg_errno(errp, -status, "unable to check for holes"); + return status; + } + assert(pnum && pnum <=3D size - progress); + if (status & BDRV_BLOCK_ZERO) { + NBDStructuredReadHole chunk; + struct iovec iov[] =3D { + {.iov_base =3D &chunk, .iov_len =3D sizeof(chunk)}, + }; + + trace_nbd_co_send_structured_read_hole(handle, offset + progre= ss, + pnum); + set_be_chunk(&chunk.h, 0, NBD_REPLY_TYPE_OFFSET_HOLE, + handle, sizeof(chunk) - sizeof(chunk.h)); + stq_be_p(&chunk.offset, offset + progress); + stl_be_p(&chunk.length, pnum); + ret =3D nbd_co_send_iov(client, iov, 1, errp); + } else { + ret =3D blk_pread(exp->blk, offset + progress + exp->dev_offse= t, + data + progress, pnum); + if (ret < 0) { + error_setg_errno(errp, -ret, "reading from file failed"); + break; + } + ret =3D nbd_co_send_structured_read(client, handle, offset + p= rogress, + data + progress, pnum, false, + errp); + } + + if (ret < 0) { + break; + } + progress +=3D pnum; + } + if (!ret) { + ret =3D nbd_co_send_structured_done(client, handle, errp); + } + return ret; +} + static int coroutine_fn nbd_co_send_structured_error(NBDClient *client, uint64_t handle, uint32_t error, @@ -1481,6 +1542,16 @@ static coroutine_fn void nbd_trip(void *opaque) } } + if (client->structured_reply && !(request.flags & NBD_CMD_FLAG_DF)= ) { + ret =3D nbd_co_send_sparse_read(req->client, request.handle, + request.from, req->data, request= .len, + &local_err); + if (ret < 0) { + goto reply; + } + goto done; + } + ret =3D blk_pread(exp->blk, request.from + exp->dev_offset, req->data, request.len); if (ret < 0) { @@ -1561,7 +1632,8 @@ reply: } else if (reply_data_len) { ret =3D nbd_co_send_structured_read(req->client, request.handl= e, request.from, req->data, - reply_data_len, &local_err); + reply_data_len, true, + &local_err); } else { ret =3D nbd_co_send_structured_done(req->client, request.handl= e, &local_err); diff --git a/nbd/trace-events b/nbd/trace-events index 92568edce5..2b8268ce8c 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -57,6 +57,7 @@ nbd_blk_aio_detach(const char *name, void *ctx) "Export %= s: Detaching clients fr nbd_co_send_simple_reply(uint64_t handle, uint32_t error, const char *errn= ame, int len) "Send simple reply: handle =3D %" PRIu64 ", error =3D %" PRIu= 32 " (%s), len =3D %d" nbd_co_send_structured_done(uint64_t handle) "Send structured reply done: = handle =3D %" PRIu64 nbd_co_send_structured_read(uint64_t handle, uint64_t offset, void *data, = size_t size) "Send structured read data reply: handle =3D %" PRIu64 ", offs= et =3D %" PRIu64 ", data =3D %p, len =3D %zu" +nbd_co_send_structured_read_hole(uint64_t handle, uint64_t offset, size_t = size) "Send structured read hole reply: handle =3D %" PRIu64 ", offset =3D = %" PRIu64 ", len =3D %zu" nbd_co_send_structured_error(uint64_t handle, int err, const char *errname= , const char *msg) "Send structured error reply: handle =3D %" PRIu64 ", er= ror =3D %d (%s), msg =3D '%s'" nbd_co_receive_request_decode_type(uint64_t handle, uint16_t type, const c= har *name) "Decoding type: handle =3D %" PRIu64 ", type =3D %" PRIu16 " (%s= )" nbd_co_receive_request_payload_received(uint64_t handle, uint32_t len) "Pa= yload received: handle =3D %" PRIu64 ", len =3D %" PRIu32 --=20 2.14.3 From nobody Sun May 5 19:01:59 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513820426425868.4232776366164; Wed, 20 Dec 2017 17:40:26 -0800 (PST) Received: from localhost ([::1]:52033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRpqD-0001lm-BZ for importer@patchew.org; Wed, 20 Dec 2017 20:40:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRpmL-0007Io-Oh for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRpmK-0001VH-RM for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53258) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRpmI-0001Se-0P; Wed, 20 Dec 2017 20:36:06 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1731183F3D; Thu, 21 Dec 2017 01:36:05 +0000 (UTC) Received: from red.redhat.com (ovpn-120-109.rdu2.redhat.com [10.10.120.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BC385C88F; Thu, 21 Dec 2017 01:36:04 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 20 Dec 2017 19:35:58 -0600 Message-Id: <20171221013600.17648-3-eblake@redhat.com> In-Reply-To: <20171221013600.17648-1-eblake@redhat.com> References: <20171221013600.17648-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 21 Dec 2017 01:36:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/4] nbd/server: Optimize final chunk of 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 , "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" If we are careful to handle 0-length read requests correctly, we can optimize our sparse read to send the NBD_REPLY_FLAG_DONE bit on our last OFFSET_DATA or OFFSET_HOLE chunk rather than needing a separate chunk. Signed-off-by: Eric Blake Message-Id: <20171107030912.23930-3-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index be7310cb41..e443b3cf5c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1339,12 +1339,14 @@ static int coroutine_fn nbd_co_send_sparse_read(NBD= Client *client, offset + progress, size - progress, &pnum, NULL, NULL); + bool final; if (status < 0) { error_setg_errno(errp, -status, "unable to check for holes"); return status; } assert(pnum && pnum <=3D size - progress); + final =3D progress + pnum =3D=3D size; if (status & BDRV_BLOCK_ZERO) { NBDStructuredReadHole chunk; struct iovec iov[] =3D { @@ -1353,7 +1355,8 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, trace_nbd_co_send_structured_read_hole(handle, offset + progre= ss, pnum); - set_be_chunk(&chunk.h, 0, NBD_REPLY_TYPE_OFFSET_HOLE, + set_be_chunk(&chunk.h, final ? NBD_REPLY_FLAG_DONE : 0, + NBD_REPLY_TYPE_OFFSET_HOLE, handle, sizeof(chunk) - sizeof(chunk.h)); stq_be_p(&chunk.offset, offset + progress); stl_be_p(&chunk.length, pnum); @@ -1366,7 +1369,7 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, break; } ret =3D nbd_co_send_structured_read(client, handle, offset + p= rogress, - data + progress, pnum, false, + data + progress, pnum, final, errp); } @@ -1375,9 +1378,6 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, } progress +=3D pnum; } - if (!ret) { - ret =3D nbd_co_send_structured_done(client, handle, errp); - } return ret; } @@ -1542,7 +1542,8 @@ static coroutine_fn void nbd_trip(void *opaque) } } - if (client->structured_reply && !(request.flags & NBD_CMD_FLAG_DF)= ) { + 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); --=20 2.14.3 From nobody Sun May 5 19:01:59 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513820287048537.5543995306539; Wed, 20 Dec 2017 17:38:07 -0800 (PST) Received: from localhost ([::1]:51956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRpo3-0008SV-PM for importer@patchew.org; Wed, 20 Dec 2017 20:37:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRpmM-0007J3-1t for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRpmL-0001Vf-9e for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39332) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRpmJ-0001TZ-7s; Wed, 20 Dec 2017 20:36:07 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C34A82101; Thu, 21 Dec 2017 01:36:06 +0000 (UTC) Received: from red.redhat.com (ovpn-120-109.rdu2.redhat.com [10.10.120.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5709B4CE; Thu, 21 Dec 2017 01:36:05 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 20 Dec 2017 19:35:59 -0600 Message-Id: <20171221013600.17648-4-eblake@redhat.com> In-Reply-To: <20171221013600.17648-1-eblake@redhat.com> References: <20171221013600.17648-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 21 Dec 2017 01:36:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/4] nbd/server: add additional assert to nbd_export_put 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 This place is not obvious, nbd_export_close may theoretically reduce refcount to 0. It may happen if someone calls nbd_export_put on named export not through nbd_export_set_name when refcount is 1. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20171109154049.42386-2-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- nbd/server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/nbd/server.c b/nbd/server.c index e443b3cf5c..a6d7c24663 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1190,6 +1190,7 @@ void nbd_export_put(NBDExport *exp) nbd_export_close(exp); } + assert(exp->refcount > 0); if (--exp->refcount =3D=3D 0) { assert(exp->name =3D=3D NULL); assert(exp->description =3D=3D NULL); --=20 2.14.3 From nobody Sun May 5 19:01:59 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513820297684165.1285666920013; Wed, 20 Dec 2017 17:38:17 -0800 (PST) Received: from localhost ([::1]:51957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRpoD-00006b-Nz for importer@patchew.org; Wed, 20 Dec 2017 20:38:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRpmO-0007Lk-34 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRpmN-0001XJ-5i for qemu-devel@nongnu.org; Wed, 20 Dec 2017 20:36:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRpmK-0001Uq-PN; Wed, 20 Dec 2017 20:36:08 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA4BAC047B62; Thu, 21 Dec 2017 01:36:07 +0000 (UTC) Received: from red.redhat.com (ovpn-120-109.rdu2.redhat.com [10.10.120.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EDD85C88F; Thu, 21 Dec 2017 01:36:06 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 20 Dec 2017 19:36:00 -0600 Message-Id: <20171221013600.17648-5-eblake@redhat.com> In-Reply-To: <20171221013600.17648-1-eblake@redhat.com> References: <20171221013600.17648-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 21 Dec 2017 01:36:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/4] qmp: add nbd-server-remove 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" , Markus Armbruster , Max Reitz , Paolo Bonzini 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 command for export removing. It is needed for cases when we don't want to keep export after the operation on it was completed. The other example is temporary node, created with blockdev-add. If we want to delete it we should firstly remove corresponding NBD export. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20171109154049.42386-3-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- qapi/block.json | 20 ++++++++++++++++++++ blockdev-nbd.c | 27 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/qapi/block.json b/qapi/block.json index f093fa3f27..1827940717 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -222,6 +222,26 @@ ## { 'command': 'nbd-server-add', 'data': {'device': 'str', '*writable': 'boo= l'} } +## +# @nbd-server-remove: +# +# Stop exporting block node through QEMU's embedded NBD server. +# +# @device: The device name or node name of the exported node. Should be eq= ual +# to @device parameter for corresponding nbd-server-add command c= all. +# +# @force: Whether active connections to the export should be closed. If th= is +# parameter is false the export is only removed from named exports= list, +# so new connetions are impossible and it would be freed after all +# clients are disconnected (default false). +# +# Returns: error if the server is not running or the device is not marked = for +# export. +# +# Since: 2.12 +## +{ 'command': 'nbd-server-remove', 'data': {'device': 'str', '*force': 'boo= l'} } + ## # @nbd-server-stop: # diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 28f551a7b0..5f66951c33 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -203,6 +203,33 @@ void qmp_nbd_server_add(const char *device, bool has_w= ritable, bool writable, nbd_export_put(exp); } +void qmp_nbd_server_remove(const char *device, bool has_force, bool force, + Error **errp) +{ + NBDExport *exp; + + if (!nbd_server) { + error_setg(errp, "NBD server not running"); + return; + } + + exp =3D nbd_export_find(device); + if (exp =3D=3D NULL) { + error_setg(errp, "'%s' is not exported", device); + return; + } + + if (!has_force) { + force =3D false; + } + + if (force) { + nbd_export_close(exp); + } else { + nbd_export_set_name(exp, NULL); + } +} + void qmp_nbd_server_stop(Error **errp) { nbd_export_close_all(); --=20 2.14.3