[Libguestfs] [PATCH nbdkit] protocol: Fix base:allocation replies when req_one is not set.

Richard W.M. Jones rjones at redhat.com
Tue May 21 09:13:21 UTC 2019


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




More information about the Libguestfs mailing list