From nobody Mon Feb 9 17:24:28 2026 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; dkim=fail; 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 1499957216759111.48893328105987; Thu, 13 Jul 2017 07:46:56 -0700 (PDT) Received: from localhost ([::1]:60462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVfOG-0004l7-3i for importer@patchew.org; Thu, 13 Jul 2017 10:46:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVf4c-00023L-6d for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVf4Y-0004Ou-3t for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:34 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36042) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVf4X-0004OP-Q2 for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:30 -0400 Received: by mail-wm0-f66.google.com with SMTP id y5so5447375wmh.3 for ; Thu, 13 Jul 2017 07:26:29 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id k75sm6042448wmh.10.2017.07.13.07.25.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 07:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=IsAraw053T4x2DBHhLiM65BKnj8Pc0NKS0x9glIkqI4=; b=orw9rKCXhYh3Itj0grPDdqwBqOzGlK4B/lNanhHYepJT62kGVWKkY7jRZgLZ24Co4b aTSO/q6MOjsIQs3MZPIeCyCHguTd2EYM8E6Z8wCTBZMZMq/BRJw1Oq1QTnGZM3gyU6zt T/dk+1Yaq/736MvkFDFLUfCkllH9xXFHu5IwsD5hWVX7HztLksObp1c3yHVx7F+oYmKi 60TPK2U/AltZRj6KTJHjFS6rTCz+TgomG4ECXEoI9Of+vSXt9abtJfQHvhu+KRxc0zGh r6mqxZmNjxk5GttzQSQ0QMFPpll/kW98HHHZkUZeDxU8i0DnhDog9KqfowZOuSS0ER+h BlTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=IsAraw053T4x2DBHhLiM65BKnj8Pc0NKS0x9glIkqI4=; b=oqZGZ4lG9RQNuzuqh2eMsVXtBuyjXye42tZKKzdURRN351MvDH1QQJ9mmiZ+auAuwp o3vonAcYbVrTyYT2n5WwMbpuFWEK/3oRiZa1TBpSvgkkmNtgtyXHj7qDMiQQyOeShe2F Ol4qBFIWc+dLSdvOZXy2QRbNjzcEjsuEsZpTSZQogYfpbR1I14DUPu9VLSbqwyb5Xlt/ Gth4KJ0gmSaVHnUxtPkqb0/56cDAozLj5ZBd81N9LaCalYhKC6BexcHgA1nMuiRhkS89 nZ8SJGeA9LWMfh4+q+OnKAxq2U3rQh2BUZaxpY39UjaqVnmsx43YQu+U2ULXkloPLpSt NlJQ== X-Gm-Message-State: AIVw1126IaqLbqhLCh9TvmZGCMl1SCMzoBW6Ch0Hvg7ydWAzdW6o2WfY lNDVmOsN9dcRdRYD7fY= X-Received: by 10.28.20.67 with SMTP id 64mr2342602wmu.60.1499955927031; Thu, 13 Jul 2017 07:25:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 13 Jul 2017 16:24:24 +0200 Message-Id: <1499955874-10954-32-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> References: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.66 Subject: [Qemu-devel] [PULL 31/41] nbd: Create struct for tracking export info 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake The NBD Protocol is introducing some additional information about exports, such as minimum request size and alignment, as well as an advertised maximum request size. It will be easier to feed this information back to the block layer if we gather all the information into a struct, rather than adding yet more pointer parameters during negotiation. Signed-off-by: Eric Blake Message-Id: <20170707203049.534-2-eblake@redhat.com> Signed-off-by: Paolo Bonzini --- block/nbd-client.c | 18 ++++++++---------- block/nbd-client.h | 3 +-- block/nbd.c | 2 +- include/block/nbd.h | 15 +++++++++++---- nbd/client.c | 44 ++++++++++++++++++++++---------------------- qemu-nbd.c | 10 ++++------ 6 files changed, 47 insertions(+), 45 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 208f907..aab1e32 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -242,7 +242,7 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, ssize_t ret; =20 if (flags & BDRV_REQ_FUA) { - assert(client->nbdflags & NBD_FLAG_SEND_FUA); + assert(client->info.flags & NBD_FLAG_SEND_FUA); request.flags |=3D NBD_CMD_FLAG_FUA; } =20 @@ -270,12 +270,12 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs,= int64_t offset, }; NBDReply reply; =20 - if (!(client->nbdflags & NBD_FLAG_SEND_WRITE_ZEROES)) { + if (!(client->info.flags & NBD_FLAG_SEND_WRITE_ZEROES)) { return -ENOTSUP; } =20 if (flags & BDRV_REQ_FUA) { - assert(client->nbdflags & NBD_FLAG_SEND_FUA); + assert(client->info.flags & NBD_FLAG_SEND_FUA); request.flags |=3D NBD_CMD_FLAG_FUA; } if (!(flags & BDRV_REQ_MAY_UNMAP)) { @@ -299,7 +299,7 @@ int nbd_client_co_flush(BlockDriverState *bs) NBDReply reply; ssize_t ret; =20 - if (!(client->nbdflags & NBD_FLAG_SEND_FLUSH)) { + if (!(client->info.flags & NBD_FLAG_SEND_FLUSH)) { return 0; } =20 @@ -327,7 +327,7 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_= t offset, int bytes) NBDReply reply; ssize_t ret; =20 - if (!(client->nbdflags & NBD_FLAG_SEND_TRIM)) { + if (!(client->info.flags & NBD_FLAG_SEND_TRIM)) { return 0; } =20 @@ -385,19 +385,17 @@ int nbd_client_init(BlockDriverState *bs, qio_channel_set_blocking(QIO_CHANNEL(sioc), true, NULL); =20 ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), export, - &client->nbdflags, tlscreds, hostname, - &client->ioc, - &client->size, errp); + &client->ioc, &client->info, errp); if (ret < 0) { logout("Failed to negotiate with the NBD server\n"); return ret; } - if (client->nbdflags & NBD_FLAG_SEND_FUA) { + if (client->info.flags & NBD_FLAG_SEND_FUA) { bs->supported_write_flags =3D BDRV_REQ_FUA; bs->supported_zero_flags |=3D BDRV_REQ_FUA; } - if (client->nbdflags & NBD_FLAG_SEND_WRITE_ZEROES) { + if (client->info.flags & NBD_FLAG_SEND_WRITE_ZEROES) { bs->supported_zero_flags |=3D BDRV_REQ_MAY_UNMAP; } =20 diff --git a/block/nbd-client.h b/block/nbd-client.h index 49636bc..df80771 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -20,8 +20,7 @@ typedef struct NBDClientSession { QIOChannelSocket *sioc; /* The master data channel */ QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) = */ - uint16_t nbdflags; - off_t size; + NBDExportInfo info; =20 CoMutex send_mutex; CoQueue free_sema; diff --git a/block/nbd.c b/block/nbd.c index d529305..4a9048c 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -492,7 +492,7 @@ static int64_t nbd_getlength(BlockDriverState *bs) { BDRVNBDState *s =3D bs->opaque; =20 - return s->client.size; + return s->client.info.size; } =20 static void nbd_detach_aio_context(BlockDriverState *bs) diff --git a/include/block/nbd.h b/include/block/nbd.h index 6d75d5a..9092374 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -123,13 +123,20 @@ enum { * aren't overflowing some other buffer. */ #define NBD_MAX_NAME_SIZE 256 =20 +/* Details collected by NBD_OPT_EXPORT_NAME and NBD_OPT_GO */ +struct NBDExportInfo { + uint64_t size; + uint16_t flags; +}; +typedef struct NBDExportInfo NBDExportInfo; + ssize_t nbd_rwv(QIOChannel *ioc, struct iovec *iov, size_t niov, size_t le= ngth, bool do_read, Error **errp); -int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint16_t *fla= gs, +int nbd_receive_negotiate(QIOChannel *ioc, const char *name, QCryptoTLSCreds *tlscreds, const char *hostname, - QIOChannel **outioc, - off_t *size, Error **errp); -int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size, + QIOChannel **outioc, NBDExportInfo *info, + Error **errp); +int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info, Error **errp); ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request); ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp); diff --git a/nbd/client.c b/nbd/client.c index 9c52b9b..1250273 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -425,13 +425,13 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *i= oc, } =20 =20 -int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint16_t *fla= gs, +int nbd_receive_negotiate(QIOChannel *ioc, const char *name, QCryptoTLSCreds *tlscreds, const char *hostname, - QIOChannel **outioc, - off_t *size, Error **errp) + QIOChannel **outioc, NBDExportInfo *info, + Error **errp) { char buf[256]; - uint64_t magic, s; + uint64_t magic; int rc; bool zeroes =3D true; =20 @@ -532,17 +532,17 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, uint16_t *flags, } =20 /* Read the response */ - if (nbd_read(ioc, &s, sizeof(s), errp) < 0) { + if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) { error_prepend(errp, "Failed to read export length"); goto fail; } - *size =3D be64_to_cpu(s); + be64_to_cpus(&info->size); =20 - if (nbd_read(ioc, flags, sizeof(*flags), errp) < 0) { + if (nbd_read(ioc, &info->flags, sizeof(info->flags), errp) < 0) { error_prepend(errp, "Failed to read export flags"); goto fail; } - be16_to_cpus(flags); + be16_to_cpus(&info->flags); } else if (magic =3D=3D NBD_CLIENT_MAGIC) { uint32_t oldflags; =20 @@ -555,11 +555,11 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, uint16_t *flags, goto fail; } =20 - if (nbd_read(ioc, &s, sizeof(s), errp) < 0) { + if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) { error_prepend(errp, "Failed to read export length"); goto fail; } - *size =3D be64_to_cpu(s); + be64_to_cpus(&info->size); =20 if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) { error_prepend(errp, "Failed to read export flags"); @@ -570,13 +570,13 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, uint16_t *flags, error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflag= s); goto fail; } - *flags =3D oldflags; + info->flags =3D oldflags; } else { error_setg(errp, "Bad magic received"); goto fail; } =20 - trace_nbd_receive_negotiate_size_flags(*size, *flags); + trace_nbd_receive_negotiate_size_flags(info->size, info->flags); if (zeroes && nbd_drop(ioc, 124, errp) < 0) { error_prepend(errp, "Failed to read reserved block"); goto fail; @@ -588,13 +588,13 @@ fail: } =20 #ifdef __linux__ -int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size, +int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info, Error **errp) { - unsigned long sectors =3D size / BDRV_SECTOR_SIZE; - if (size / BDRV_SECTOR_SIZE !=3D sectors) { - error_setg(errp, "Export size %lld too large for 32-bit kernel", - (long long) size); + unsigned long sectors =3D info->size / BDRV_SECTOR_SIZE; + if (info->size / BDRV_SECTOR_SIZE !=3D sectors) { + error_setg(errp, "Export size %" PRIu64 " too large for 32-bit ker= nel", + info->size); return -E2BIG; } =20 @@ -615,8 +615,8 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, } =20 trace_nbd_init_set_size(sectors); - if (size % BDRV_SECTOR_SIZE) { - trace_nbd_init_trailing_bytes(size % BDRV_SECTOR_SIZE); + if (info->size % BDRV_SECTOR_SIZE) { + trace_nbd_init_trailing_bytes(info->size % BDRV_SECTOR_SIZE); } =20 if (ioctl(fd, NBD_SET_SIZE_BLOCKS, sectors) < 0) { @@ -625,9 +625,9 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, return -serrno; } =20 - if (ioctl(fd, NBD_SET_FLAGS, (unsigned long) flags) < 0) { + if (ioctl(fd, NBD_SET_FLAGS, (unsigned long) info->flags) < 0) { if (errno =3D=3D ENOTTY) { - int read_only =3D (flags & NBD_FLAG_READ_ONLY) !=3D 0; + int read_only =3D (info->flags & NBD_FLAG_READ_ONLY) !=3D 0; trace_nbd_init_set_readonly(); =20 if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) { @@ -685,7 +685,7 @@ int nbd_disconnect(int fd) } =20 #else -int nbd_init(int fd, QIOChannelSocket *ioc, uint16_t flags, off_t size, +int nbd_init(int fd, QIOChannelSocket *ioc, NBDExportInfo *info, Error **errp) { error_setg(errp, "nbd_init is only supported on Linux"); diff --git a/qemu-nbd.c b/qemu-nbd.c index 4dd3fd4..c8bd47f 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -255,8 +255,7 @@ static void *show_parts(void *arg) static void *nbd_client_thread(void *arg) { char *device =3D arg; - off_t size; - uint16_t nbdflags; + NBDExportInfo info; QIOChannelSocket *sioc; int fd; int ret; @@ -271,9 +270,8 @@ static void *nbd_client_thread(void *arg) goto out; } =20 - ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), NULL, &nbdflags, - NULL, NULL, NULL, - &size, &local_error); + ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), NULL, + NULL, NULL, NULL, &info, &local_error); if (ret < 0) { if (local_error) { error_report_err(local_error); @@ -288,7 +286,7 @@ static void *nbd_client_thread(void *arg) goto out_socket; } =20 - ret =3D nbd_init(fd, sioc, nbdflags, size, &local_error); + ret =3D nbd_init(fd, sioc, &info, &local_error); if (ret < 0) { error_report_err(local_error); goto out_fd; --=20 1.8.3.1