Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rwmjones committed May 21, 2019
1 parent 8d70b0c commit 8003366
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/protocol.c
Expand Up @@ -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;
Expand All @@ -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 */
Expand All @@ -524,8 +526,6 @@ extents_to_block_descriptors (struct nbdkit_extents *extents,
*/
assert (e.length <= length);
}

*nr_blocks = i;
}

#if 0
Expand Down

0 comments on commit 8003366

Please sign in to comment.