[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/14] qemu-img: Gracefully shutdown when map can't f
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PULL 05/14] qemu-img: Gracefully shutdown when map can't finish |
Date: |
Mon, 1 Apr 2019 09:08:54 -0500 |
Trying 'qemu-img map -f raw nbd://localhost:10809' causes the
NBD server to output a scary message:
qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected
end-of-file before all bytes were read
This is because the NBD client, being remote, has no way to expose a
human-readable map (the --output=json data is fine, however). But
because we exit(1) right after the message, causing the client to
bypass all block cleanup, the server sees the abrupt exit and warns,
whereas it would be silent had the client had a chance to send
NBD_CMD_DISC. Other protocols may have similar cleanup issues, where
failure to blk_unref() could cause unintended effects.
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: John Snow <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
---
qemu-img.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 03a9a10dec1..76a961df824 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2736,14 +2736,14 @@ static int img_info(int argc, char **argv)
return 0;
}
-static void dump_map_entry(OutputFormat output_format, MapEntry *e,
- MapEntry *next)
+static int dump_map_entry(OutputFormat output_format, MapEntry *e,
+ MapEntry *next)
{
switch (output_format) {
case OFORMAT_HUMAN:
if (e->data && !e->has_offset) {
error_report("File contains external, encrypted or compressed
clusters.");
- exit(1);
+ return -1;
}
if (e->data && !e->zero) {
printf("%#-16"PRIx64"%#-16"PRIx64"%#-16"PRIx64"%s\n",
@@ -2776,6 +2776,7 @@ static void dump_map_entry(OutputFormat output_format,
MapEntry *e,
}
break;
}
+ return 0;
}
static int get_block_status(BlockDriverState *bs, int64_t offset,
@@ -2968,12 +2969,15 @@ static int img_map(int argc, char **argv)
}
if (curr.length > 0) {
- dump_map_entry(output_format, &curr, &next);
+ ret = dump_map_entry(output_format, &curr, &next);
+ if (ret < 0) {
+ goto out;
+ }
}
curr = next;
}
- dump_map_entry(output_format, &curr, NULL);
+ ret = dump_map_entry(output_format, &curr, NULL);
out:
blk_unref(blk);
--
2.20.1
- [Qemu-devel] [PULL 00/14] NBD patches for 4.0-rc2, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 01/14] qemu-img: Report bdrv_block_status failures, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 03/14] nbd: Don't lose server's error to NBD_CMD_BLOCK_STATUS, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 04/14] nbd: Permit simple error to NBD_CMD_BLOCK_STATUS, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 02/14] nbd: Tolerate some server non-compliance in NBD_CMD_BLOCK_STATUS, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 05/14] qemu-img: Gracefully shutdown when map can't finish,
Eric Blake <=
- [Qemu-devel] [PULL 06/14] nbd-client: Work around server BLOCK_STATUS misalignment at EOF, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 10/14] nbd/client: Reject inaccessible tail of inconsistent server, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 11/14] nbd/client: Support qemu-img convert from unaligned size, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 08/14] nbd/client: Lower min_block for block-status, unaligned size, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 09/14] nbd/client: Report offsets in bdrv_block_status, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 07/14] iotests: Add 241 to test NBD on unaligned images, Eric Blake, 2019/04/01
- [Qemu-devel] [PULL 12/14] block: Add bdrv_get_request_alignment(), Eric Blake, 2019/04/01