Blame SOURCES/kvm-nbd-client-Report-offsets-in-bdrv_block_status.patch

383d26
From df5a366613d42ec2dc5dae33e10b6fdd5db09e0d Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Mon, 6 May 2019 17:56:19 +0200
383d26
Subject: [PATCH 09/53] nbd/client: Report offsets in bdrv_block_status
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20190506175629.11079-10-jsnow@redhat.com>
383d26
Patchwork-id: 87199
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 09/19] nbd/client: Report offsets in bdrv_block_status
383d26
Bugzilla: 1692018
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
383d26
RH-Acked-by: Thomas Huth <thuth@redhat.com>
383d26
383d26
From: Eric Blake <eblake@redhat.com>
383d26
383d26
It is desirable for 'qemu-img map' to have the same output for a file
383d26
whether it is served over file or nbd protocols. However, ever since
383d26
we implemented block status for NBD (2.12), the NBD protocol forgot to
383d26
inform the block layer that as the final layer in the chain, the
383d26
offset is valid; without an offset, the human-readable form of
383d26
qemu-img map gives up with the unhelpful:
383d26
383d26
$ nbdkit -U - data data="1" size=512 --run 'qemu-img map $nbd'
383d26
Offset          Length          Mapped to       File
383d26
qemu-img: File contains external, encrypted or compressed clusters.
383d26
383d26
The --output=json form always works, because it is reporting the
383d26
lower-level bdrv_block_status results directly rather than trying to
383d26
filter out sparse ranges for human consumption - but now it also
383d26
shows the offset member.
383d26
383d26
With this patch, the human output changes to:
383d26
383d26
Offset          Length          Mapped to       File
383d26
0               0x200           0               nbd+unix://?socket=/tmp/nbdkitOxeoLa/socket
383d26
383d26
This change is observable to several iotests.
383d26
383d26
Fixes: 78a33ab5
383d26
Reported-by: Richard W.M. Jones <rjones@redhat.com>
383d26
Signed-off-by: Eric Blake <eblake@redhat.com>
383d26
Message-Id: <20190329042750.14704-4-eblake@redhat.com>
383d26
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
383d26
(cherry picked from commit a62a85ef5ccd764d03d72d6c3cd558f9755b3457)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 block/nbd-client.c         |  9 +++++++--
383d26
 tests/qemu-iotests/209.out |  4 ++--
383d26
 tests/qemu-iotests/223.out | 18 +++++++++---------
383d26
 tests/qemu-iotests/241.out |  6 +++---
383d26
 4 files changed, 21 insertions(+), 16 deletions(-)
383d26
383d26
diff --git a/block/nbd-client.c b/block/nbd-client.c
383d26
index 09e20b2..9b5779f 100644
383d26
--- a/block/nbd-client.c
383d26
+++ b/block/nbd-client.c
383d26
@@ -959,7 +959,9 @@ int coroutine_fn nbd_client_co_block_status(BlockDriverState *bs,
383d26
 
383d26
     if (!client->info.base_allocation) {
383d26
         *pnum = bytes;
383d26
-        return BDRV_BLOCK_DATA;
383d26
+        *map = offset;
383d26
+        *file = bs;
383d26
+        return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID;
383d26
     }
383d26
 
383d26
     ret = nbd_co_send_request(bs, &request, NULL);
383d26
@@ -982,8 +984,11 @@ int coroutine_fn nbd_client_co_block_status(BlockDriverState *bs,
383d26
 
383d26
     assert(extent.length);
383d26
     *pnum = extent.length;
383d26
+    *map = offset;
383d26
+    *file = bs;
383d26
     return (extent.flags & NBD_STATE_HOLE ? 0 : BDRV_BLOCK_DATA) |
383d26
-           (extent.flags & NBD_STATE_ZERO ? BDRV_BLOCK_ZERO : 0);
383d26
+        (extent.flags & NBD_STATE_ZERO ? BDRV_BLOCK_ZERO : 0) |
383d26
+        BDRV_BLOCK_OFFSET_VALID;
383d26
 }
383d26
 
383d26
 void nbd_client_detach_aio_context(BlockDriverState *bs)
383d26
diff --git a/tests/qemu-iotests/209.out b/tests/qemu-iotests/209.out
383d26
index 0d29724..214e27b 100644
383d26
--- a/tests/qemu-iotests/209.out
383d26
+++ b/tests/qemu-iotests/209.out
383d26
@@ -1,2 +1,2 @@
383d26
-[{ "start": 0, "length": 524288, "depth": 0, "zero": false, "data": true},
383d26
-{ "start": 524288, "length": 524288, "depth": 0, "zero": true, "data": false}]
383d26
+[{ "start": 0, "length": 524288, "depth": 0, "zero": false, "data": true, "offset": 0},
383d26
+{ "start": 524288, "length": 524288, "depth": 0, "zero": true, "data": false, "offset": 524288}]
383d26
diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out
383d26
index 0524ffb..a620f82 100644
383d26
--- a/tests/qemu-iotests/223.out
383d26
+++ b/tests/qemu-iotests/223.out
383d26
@@ -67,18 +67,18 @@ read 1048576/1048576 bytes at offset 1048576
383d26
 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
383d26
 read 2097152/2097152 bytes at offset 2097152
383d26
 2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
383d26
-[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true},
383d26
-{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false},
383d26
-{ "start": 1048576, "length": 3145728, "depth": 0, "zero": false, "data": true}]
383d26
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
383d26
+{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
383d26
+{ "start": 1048576, "length": 3145728, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
383d26
 [{ "start": 0, "length": 65536, "depth": 0, "zero": false, "data": false},
383d26
-{ "start": 65536, "length": 2031616, "depth": 0, "zero": false, "data": true},
383d26
+{ "start": 65536, "length": 2031616, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
383d26
 { "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": false}]
383d26
 
383d26
 === Contrast to small granularity dirty-bitmap ===
383d26
 
383d26
-[{ "start": 0, "length": 512, "depth": 0, "zero": false, "data": true},
383d26
+[{ "start": 0, "length": 512, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
383d26
 { "start": 512, "length": 512, "depth": 0, "zero": false, "data": false},
383d26
-{ "start": 1024, "length": 2096128, "depth": 0, "zero": false, "data": true},
383d26
+{ "start": 1024, "length": 2096128, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
383d26
 { "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": false}]
383d26
 
383d26
 === End qemu NBD server ===
383d26
@@ -94,10 +94,10 @@ read 2097152/2097152 bytes at offset 2097152
383d26
 === Use qemu-nbd as server ===
383d26
 
383d26
 [{ "start": 0, "length": 65536, "depth": 0, "zero": false, "data": false},
383d26
-{ "start": 65536, "length": 2031616, "depth": 0, "zero": false, "data": true},
383d26
+{ "start": 65536, "length": 2031616, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
383d26
 { "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": false}]
383d26
-[{ "start": 0, "length": 512, "depth": 0, "zero": false, "data": true},
383d26
+[{ "start": 0, "length": 512, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
383d26
 { "start": 512, "length": 512, "depth": 0, "zero": false, "data": false},
383d26
-{ "start": 1024, "length": 2096128, "depth": 0, "zero": false, "data": true},
383d26
+{ "start": 1024, "length": 2096128, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
383d26
 { "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": false}]
383d26
 *** done
383d26
diff --git a/tests/qemu-iotests/241.out b/tests/qemu-iotests/241.out
383d26
index b76a623..f22eabb 100644
383d26
--- a/tests/qemu-iotests/241.out
383d26
+++ b/tests/qemu-iotests/241.out
383d26
@@ -4,7 +4,7 @@ QA output created by 241
383d26
 
383d26
   size:  1024
383d26
   min block: 512
383d26
-[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true}]
383d26
+[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
383d26
 1 KiB (0x400) bytes     allocated at offset 0 bytes (0x0)
383d26
 
383d26
 === Exporting unaligned raw image, forced server sector alignment ===
383d26
@@ -14,13 +14,13 @@ WARNING: Image format was not specified for '/home/eblake/qemu/tests/qemu-iotest
383d26
          Specify the 'raw' format explicitly to remove the restrictions.
383d26
   size:  1024
383d26
   min block: 512
383d26
-[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true}]
383d26
+[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
383d26
 1 KiB (0x400) bytes     allocated at offset 0 bytes (0x0)
383d26
 
383d26
 === Exporting unaligned raw image, forced client sector alignment ===
383d26
 
383d26
   size:  1024
383d26
   min block: 512
383d26
-[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true}]
383d26
+[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
383d26
 1 KiB (0x400) bytes     allocated at offset 0 bytes (0x0)
383d26
 *** done
383d26
-- 
383d26
1.8.3.1
383d26