[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libnbd PATCH v3 16/22] examples: Update copy-libev to use 64-bit block
From: |
Eric Blake |
Subject: |
[libnbd PATCH v3 16/22] examples: Update copy-libev to use 64-bit block status |
Date: |
Thu, 25 May 2023 08:01:02 -0500 |
Although our use of "base:allocation" doesn't require the use of the
64-bit API for flags, we might perform slightly faster for a server
that does give us 64-bit extent lengths and honors larger nbd_zero
lengths.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
examples/copy-libev.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/examples/copy-libev.c b/examples/copy-libev.c
index 32cb46b3..9346faf7 100644
--- a/examples/copy-libev.c
+++ b/examples/copy-libev.c
@@ -96,7 +96,7 @@ struct request {
};
struct extent {
- uint32_t length;
+ uint64_t length;
bool zero;
};
@@ -184,7 +184,7 @@ get_events (struct connection *c)
static int
extent_callback (void *user_data, const char *metacontext, uint64_t offset,
- uint32_t *entries, size_t nr_entries, int *error)
+ nbd_extent *entries, size_t nr_entries, int *error)
{
struct request *r = user_data;
@@ -199,22 +199,21 @@ extent_callback (void *user_data, const char
*metacontext, uint64_t offset,
return 1;
}
- /* Libnbd returns uint32_t pair (length, flags) for each extent. */
- extents_len = nr_entries / 2;
+ extents_len = nr_entries;
extents = malloc (extents_len * sizeof *extents);
if (extents == NULL)
FAIL ("Cannot allocated extents: %s", strerror (errno));
/* Copy libnbd entries to extents array. */
- for (int i = 0, j = 0; i < extents_len; i++, j=i*2) {
- extents[i].length = entries[j];
+ for (int i = 0; i < extents_len; i++) {
+ extents[i].length = entries[i].length;
/* Libnbd exposes both ZERO and HOLE flags. We care only about
* ZERO status, meaning we can copy this extent using efficinet
* zero method.
*/
- extents[i].zero = (entries[j + 1] & LIBNBD_STATE_ZERO) != 0;
+ extents[i].zero = (entries[i].flags & LIBNBD_STATE_ZERO) != 0;
}
DEBUG ("r%zu: received %zu extents for %s",
@@ -286,10 +285,10 @@ start_extents (struct request *r)
DEBUG ("r%zu: start extents offset=%" PRIi64 " count=%zu",
r->index, offset, count);
- cookie = nbd_aio_block_status (
+ cookie = nbd_aio_block_status_64 (
src.nbd, count, offset,
- (nbd_extent_callback) { .callback=extent_callback,
- .user_data=r },
+ (nbd_extent64_callback) { .callback=extent_callback,
+ .user_data=r },
(nbd_completion_callback) { .callback=extents_completed,
.user_data=r },
0);
@@ -324,7 +323,7 @@ next_extent (struct request *r)
limit = MIN (REQUEST_SIZE, size - offset);
while (length < limit) {
- DEBUG ("e%zu: offset=%" PRIi64 " len=%" PRIu32 " zero=%d",
+ DEBUG ("e%zu: offset=%" PRIi64 " len=%" PRIu64 " zero=%d",
extents_pos, offset, extents[extents_pos].length, is_zero);
/* If this extent is too large, steal some data from it to
--
2.40.1
- [libnbd PATCH v3 11/22] api: Add several functions for controlling extended headers, (continued)
- [libnbd PATCH v3 11/22] api: Add several functions for controlling extended headers, Eric Blake, 2023/05/25
- [libnbd PATCH v3 20/22] interop: Add test of 64-bit block status, Eric Blake, 2023/05/25
- [libnbd PATCH v3 08/22] block_status: Track 64-bit extents internally, Eric Blake, 2023/05/25
- [libnbd PATCH v3 17/22] ocaml: Add example for 64-bit extents, Eric Blake, 2023/05/25
- [libnbd PATCH v3 15/22] info: Update nbdinfo --map to use 64-bit block status, Eric Blake, 2023/05/25
- [libnbd PATCH v3 07/22] generator: Add struct nbd_extent in prep for 64-bit extents, Eric Blake, 2023/05/25
- [libnbd PATCH v3 13/22] dump: Update nbddump to use 64-bit block status, Eric Blake, 2023/05/25
- [libnbd PATCH v3 01/22] block_status: Refactor array storage, Eric Blake, 2023/05/25
- [libnbd PATCH v3 16/22] examples: Update copy-libev to use 64-bit block status,
Eric Blake <=
- [libnbd PATCH v3 06/22] states: Break deadlock if server goofs on extended replies, Eric Blake, 2023/05/25
- [libnbd PATCH v3 10/22] api: Add [aio_]nbd_block_status_64, Eric Blake, 2023/05/25
- [libnbd PATCH v3 02/22] internal: Refactor layout of replies in sbuf, Eric Blake, 2023/05/25
- Re: [Libguestfs] [libnbd PATCH v3 02/22] internal: Refactor layout of replies in sbuf, Eric Blake, 2023/05/26
- Re: [Libguestfs] [libnbd PATCH v3 02/22] internal: Refactor layout of replies in sbuf, Laszlo Ersek, 2023/05/30