Richard W.M. Jones
2019-May-21 09:13 UTC
[Libguestfs] [PATCH nbdkit] protocol: Fix base:allocation replies when req_one is not set.
I pushed this one already. It should go into the stable-1.12 branch too. Rich.
Richard W.M. Jones
2019-May-21 09:13 UTC
[Libguestfs] [PATCH nbdkit] protocol: Fix base:allocation replies when req_one is not set.
We never tested this path because qemu always sets the req_one flag, but what we sent back was totally broken. The length field was not set at all, and the count of blocks could be off by one in some cases. These problems were revealed while writing libnbd tests. --- server/protocol.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/protocol.c b/server/protocol.c index 792b1ac..6d519e7 100644 --- a/server/protocol.c +++ b/server/protocol.c @@ -501,6 +501,7 @@ extents_to_block_descriptors (struct nbdkit_extents *extents, else { uint64_t pos = offset; + *nr_blocks = 0; for (i = 0; i < nr_extents; ++i) { const struct nbdkit_extent e = nbdkit_get_extent (extents, i); uint64_t length; @@ -509,8 +510,9 @@ extents_to_block_descriptors (struct nbdkit_extents *extents, assert (e.offset == offset); /* Must not exceed UINT32_MAX. */ - length = MIN (e.length, UINT32_MAX); + blocks[i].length = length = MIN (e.length, UINT32_MAX); blocks[i].status_flags = e.type & 3; + (*nr_blocks)++; pos += length; if (pos > offset + count) /* this must be the last block */ @@ -524,8 +526,6 @@ extents_to_block_descriptors (struct nbdkit_extents *extents, */ assert (e.length <= length); } - - *nr_blocks = i; } #if 0 -- 2.21.0
Maybe Matching Threads
- [PATCH nbdkit v4 00/15] Implement Block Status.
- [PATCH nbdkit v5 FINAL 00/19] Implement extents.
- [PATCH nbdkit 0/8] Implement extents using a simpler array.
- [PATCH nbdkit 0/4] common/protocol: Unify public <nbd-protocol.h>
- [nbdkit PATCH v2] Introduce cacheextents filter