From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
"open list:Network Block Dev..." <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PULL 2/4] nbd/server: Optimize final chunk of sparse read
Date: Wed, 20 Dec 2017 19:35:58 -0600 [thread overview]
Message-ID: <20171221013600.17648-3-eblake@redhat.com> (raw)
In-Reply-To: <20171221013600.17648-1-eblake@redhat.com>
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 <eblake@redhat.com>
Message-Id: <20171107030912.23930-3-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
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(NBDClient *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 <= size - progress);
+ final = progress + pnum == size;
if (status & BDRV_BLOCK_ZERO) {
NBDStructuredReadHole chunk;
struct iovec iov[] = {
@@ -1353,7 +1355,8 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client,
trace_nbd_co_send_structured_read_hole(handle, offset + progress,
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(NBDClient *client,
break;
}
ret = nbd_co_send_structured_read(client, handle, offset + progress,
- data + progress, pnum, false,
+ data + progress, pnum, final,
errp);
}
@@ -1375,9 +1378,6 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client,
}
progress += pnum;
}
- if (!ret) {
- ret = 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 = nbd_co_send_sparse_read(req->client, request.handle,
request.from, req->data, request.len,
&local_err);
--
2.14.3
next prev parent reply other threads:[~2017-12-21 1:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-21 1:35 [Qemu-devel] [PULL 0/4] NBD patches through 20 Dec Eric Blake
2017-12-21 1:35 ` [Qemu-devel] [PULL 1/4] nbd/server: Implement sparse reads atop structured reply Eric Blake
2017-12-21 1:35 ` Eric Blake [this message]
2017-12-21 1:35 ` [Qemu-devel] [PULL 3/4] nbd/server: add additional assert to nbd_export_put Eric Blake
2017-12-21 1:36 ` [Qemu-devel] [PULL 4/4] qmp: add nbd-server-remove Eric Blake
2017-12-21 9:07 ` [Qemu-devel] STOP " Vladimir Sementsov-Ogievskiy
2017-12-21 9:10 ` Vladimir Sementsov-Ogievskiy
2017-12-21 14:01 ` Eric Blake
2017-12-21 13:13 ` Peter Maydell
2017-12-21 13:13 ` [Qemu-devel] [PULL 0/4] NBD patches through 20 Dec Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171221013600.17648-3-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).