From nobody Sat May 4 05:15:27 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=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538586274434842.9240826442679; Wed, 3 Oct 2018 10:04:34 -0700 (PDT) Received: from localhost ([::1]:50644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7kZW-0002Ue-0o for importer@patchew.org; Wed, 03 Oct 2018 13:04:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7kXk-0001aE-8y for qemu-devel@nongnu.org; Wed, 03 Oct 2018 13:02:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7kXh-0001dw-2b for qemu-devel@nongnu.org; Wed, 03 Oct 2018 13:02:36 -0400 Received: from relay.sw.ru ([185.231.240.75]:37426) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7kXg-0001dM-ON; Wed, 03 Oct 2018 13:02:32 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1g7kXd-0005W7-BW; Wed, 03 Oct 2018 20:02:29 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 3 Oct 2018 20:02:27 +0300 Message-Id: <20181003170228.95973-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181003170228.95973-1-vsementsov@virtuozzo.com> References: <20181003170228.95973-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/2] qemu-nbd: drop old-style negotiation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, den@virtuozzo.com, rjones@redhat.com, mreitz@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use new-style negotiation always, with default "" (empty) export name if it is not specified with '-x' option. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- qemu-nbd.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 51b9d38c72..57e79e30ea 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -56,7 +56,6 @@ #define MBR_SIZE 512 =20 static NBDExport *exp; -static bool newproto; static int verbose; static char *srcpath; static SocketAddress *saddr; @@ -84,8 +83,8 @@ static void usage(const char *name) " -e, --shared=3DNUM device can be shared by NUM clients (defaul= t '1')\n" " -t, --persistent don't exit on the last connection\n" " -v, --verbose display extra debugging information\n" -" -x, --export-name=3DNAME expose export by name\n" -" -D, --description=3DTEXT with -x, also export a human-readable descr= iption\n" +" -x, --export-name=3DNAME expose export by name (default is empty str= ing)\n" +" -D, --description=3DTEXT export a human-readable description\n" "\n" "Exposing part of the image:\n" " -o, --offset=3DOFFSET offset into the image\n" @@ -354,8 +353,7 @@ static void nbd_accept(QIONetListener *listener, QIOCha= nnelSocket *cioc, =20 nb_fds++; nbd_update_server_watch(); - nbd_client_new(newproto ? NULL : exp, cioc, - tlscreds, NULL, nbd_client_closed); + nbd_client_new(NULL, cioc, tlscreds, NULL, nbd_client_closed); } =20 static void nbd_update_server_watch(void) @@ -549,7 +547,7 @@ int main(int argc, char **argv) Error *local_err =3D NULL; BlockdevDetectZeroesOptions detect_zeroes =3D BLOCKDEV_DETECT_ZEROES_O= PTIONS_OFF; QDict *options =3D NULL; - const char *export_name =3D NULL; + const char *export_name =3D ""; /* Default export name */ const char *export_description =3D NULL; const char *tlscredsid =3D NULL; bool imageOpts =3D false; @@ -808,11 +806,6 @@ int main(int argc, char **argv) error_report("TLS is not supported with a host device"); exit(EXIT_FAILURE); } - if (!export_name) { - /* Set the default NBD protocol export name, since - * we *must* use new style protocol for TLS */ - export_name =3D ""; - } tlscreds =3D nbd_get_tls_creds(tlscredsid, &local_err); if (local_err) { error_report("Failed to get TLS creds %s", @@ -1013,14 +1006,8 @@ int main(int argc, char **argv) error_report_err(local_err); exit(EXIT_FAILURE); } - if (export_name) { - nbd_export_set_name(exp, export_name); - nbd_export_set_description(exp, export_description); - newproto =3D true; - } else if (export_description) { - error_report("Export description requires an export name"); - exit(EXIT_FAILURE); - } + nbd_export_set_name(exp, export_name); + nbd_export_set_description(exp, export_description); =20 if (device) { int ret; --=20 2.18.0 From nobody Sat May 4 05:15:27 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=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538586275168692.3711896900473; Wed, 3 Oct 2018 10:04:35 -0700 (PDT) Received: from localhost ([::1]:50645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7kZV-0002Ug-Bh for importer@patchew.org; Wed, 03 Oct 2018 13:04:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7kXk-0001aB-8D for qemu-devel@nongnu.org; Wed, 03 Oct 2018 13:02:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7kXh-0001dx-2b for qemu-devel@nongnu.org; Wed, 03 Oct 2018 13:02:36 -0400 Received: from relay.sw.ru ([185.231.240.75]:37420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7kXg-0001dL-OO; Wed, 03 Oct 2018 13:02:32 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1g7kXd-0005W7-I7; Wed, 03 Oct 2018 20:02:29 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 3 Oct 2018 20:02:28 +0300 Message-Id: <20181003170228.95973-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181003170228.95973-1-vsementsov@virtuozzo.com> References: <20181003170228.95973-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 2/2] nbd/server: drop old-style negotiation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, den@virtuozzo.com, rjones@redhat.com, mreitz@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" After the previous commit, nbd_client_new first parameter is always NULL. Let's drop it with all corresponding old-style negotiation code path which is unreachable now. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- include/block/nbd.h | 3 +-- blockdev-nbd.c | 2 +- nbd/server.c | 53 +++++++++++++-------------------------------- qemu-nbd.c | 2 +- 4 files changed, 18 insertions(+), 42 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 4638c839f5..0129d1a4b4 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -308,8 +308,7 @@ void nbd_export_set_name(NBDExport *exp, const char *na= me); void nbd_export_set_description(NBDExport *exp, const char *description); void nbd_export_close_all(void); =20 -void nbd_client_new(NBDExport *exp, - QIOChannelSocket *sioc, +void nbd_client_new(QIOChannelSocket *sioc, QCryptoTLSCreds *tlscreds, const char *tlsaclname, void (*close_fn)(NBDClient *, bool)); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 1ef11041a7..8913d8ff73 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -36,7 +36,7 @@ static void nbd_accept(QIONetListener *listener, QIOChann= elSocket *cioc, gpointer opaque) { qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server"); - nbd_client_new(NULL, cioc, + nbd_client_new(cioc, nbd_server->tlscreds, NULL, nbd_blockdev_client_closed); } diff --git a/nbd/server.c b/nbd/server.c index 1fba21414b..e87f881525 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1253,7 +1253,6 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) const uint16_t myflags =3D (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA | NBD_FLAG_SEND_WRITE_ZEROES | NBD_FLAG_SEND_C= ACHE); - bool oldStyle; =20 /* Old style negotiation header, no room for options [ 0 .. 7] passwd ("NBDMAGIC") @@ -1274,33 +1273,19 @@ static coroutine_fn int nbd_negotiate(NBDClient *cl= ient, Error **errp) trace_nbd_negotiate_begin(); memcpy(buf, "NBDMAGIC", 8); =20 - oldStyle =3D client->exp !=3D NULL && !client->tlscreds; - if (oldStyle) { - trace_nbd_negotiate_old_style(client->exp->size, - client->exp->nbdflags | myflags); - stq_be_p(buf + 8, NBD_CLIENT_MAGIC); - stq_be_p(buf + 16, client->exp->size); - stl_be_p(buf + 24, client->exp->nbdflags | myflags); + stq_be_p(buf + 8, NBD_OPTS_MAGIC); + stw_be_p(buf + 16, NBD_FLAG_FIXED_NEWSTYLE | NBD_FLAG_NO_ZEROES); =20 - if (nbd_write(client->ioc, buf, sizeof(buf), errp) < 0) { - error_prepend(errp, "write failed: "); - return -EINVAL; - } - } else { - stq_be_p(buf + 8, NBD_OPTS_MAGIC); - stw_be_p(buf + 16, NBD_FLAG_FIXED_NEWSTYLE | NBD_FLAG_NO_ZEROES); - - if (nbd_write(client->ioc, buf, 18, errp) < 0) { - error_prepend(errp, "write failed: "); - return -EINVAL; - } - ret =3D nbd_negotiate_options(client, myflags, errp); - if (ret !=3D 0) { - if (ret < 0) { - error_prepend(errp, "option negotiation failed: "); - } - return ret; + if (nbd_write(client->ioc, buf, 18, errp) < 0) { + error_prepend(errp, "write failed: "); + return -EINVAL; + } + ret =3D nbd_negotiate_options(client, myflags, errp); + if (ret !=3D 0) { + if (ret < 0) { + error_prepend(errp, "option negotiation failed: "); } + return ret; } =20 assert(!client->optlen); @@ -2396,13 +2381,8 @@ static void nbd_client_receive_next_request(NBDClien= t *client) static coroutine_fn void nbd_co_client_start(void *opaque) { NBDClient *client =3D opaque; - NBDExport *exp =3D client->exp; Error *local_err =3D NULL; =20 - if (exp) { - nbd_export_get(exp); - QTAILQ_INSERT_TAIL(&exp->clients, client, next); - } qemu_co_mutex_init(&client->send_lock); =20 if (nbd_negotiate(client, &local_err)) { @@ -2417,13 +2397,11 @@ static coroutine_fn void nbd_co_client_start(void *= opaque) } =20 /* - * Create a new client listener on the given export @exp, using the - * given channel @sioc. Begin servicing it in a coroutine. When the - * connection closes, call @close_fn with an indication of whether the - * client completed negotiation. + * Create a new client listener using the given channel @sioc. + * Begin servicing it in a coroutine. When the connection closes, call + * @close_fn with an indication of whether the client completed negotiatio= n. */ -void nbd_client_new(NBDExport *exp, - QIOChannelSocket *sioc, +void nbd_client_new(QIOChannelSocket *sioc, QCryptoTLSCreds *tlscreds, const char *tlsaclname, void (*close_fn)(NBDClient *, bool)) @@ -2433,7 +2411,6 @@ void nbd_client_new(NBDExport *exp, =20 client =3D g_new0(NBDClient, 1); client->refcount =3D 1; - client->exp =3D exp; client->tlscreds =3D tlscreds; if (tlscreds) { object_ref(OBJECT(client->tlscreds)); diff --git a/qemu-nbd.c b/qemu-nbd.c index 57e79e30ea..aad0b88723 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -353,7 +353,7 @@ static void nbd_accept(QIONetListener *listener, QIOCha= nnelSocket *cioc, =20 nb_fds++; nbd_update_server_watch(); - nbd_client_new(NULL, cioc, tlscreds, NULL, nbd_client_closed); + nbd_client_new(cioc, tlscreds, NULL, nbd_client_closed); } =20 static void nbd_update_server_watch(void) --=20 2.18.0