All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: John Snow <jsnow@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
	Max Reitz <mreitz@redhat.com>,
	"open list:Block layer core" <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PULL 05/14] qemu-img: Gracefully shutdown when map can't finish
Date: Mon,  1 Apr 2019 09:08:54 -0500	[thread overview]
Message-ID: <20190401140903.19186-6-eblake@redhat.com> (raw)
In-Reply-To: <20190401140903.19186-1-eblake@redhat.com>

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 <eblake@redhat.com>
Message-Id: <20190326184043.7544-1-eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
 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

  parent reply	other threads:[~2019-04-01 14:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01 14:08 [Qemu-devel] [PULL 00/14] NBD patches for 4.0-rc2 Eric Blake
2019-04-01 14:08 ` [Qemu-devel] [PULL 01/14] qemu-img: Report bdrv_block_status failures Eric Blake
2019-04-01 14:08 ` [Qemu-devel] [PULL 02/14] nbd: Tolerate some server non-compliance in NBD_CMD_BLOCK_STATUS Eric Blake
2019-04-01 14:08 ` [Qemu-devel] [PULL 03/14] nbd: Don't lose server's error to NBD_CMD_BLOCK_STATUS Eric Blake
2019-04-01 14:08 ` [Qemu-devel] [PULL 04/14] nbd: Permit simple " Eric Blake
2019-04-01 14:08 ` Eric Blake [this message]
2019-04-01 14:08 ` [Qemu-devel] [PULL 06/14] nbd-client: Work around server BLOCK_STATUS misalignment at EOF Eric Blake
2019-04-01 14:08 ` [Qemu-devel] [PULL 07/14] iotests: Add 241 to test NBD on unaligned images Eric Blake
2019-04-10 17:45   ` [Qemu-devel] [Qemu-block] " Max Reitz
2019-04-10 18:01     ` Eric Blake
2019-04-01 14:08 ` [Qemu-devel] [PULL 08/14] nbd/client: Lower min_block for block-status, unaligned size Eric Blake
2019-04-01 14:08 ` [Qemu-devel] [PULL 09/14] nbd/client: Report offsets in bdrv_block_status Eric Blake
2019-04-01 14:08 ` [Qemu-devel] [PULL 10/14] nbd/client: Reject inaccessible tail of inconsistent server Eric Blake
2019-04-02 22:40   ` Eric Blake
2019-04-01 14:09 ` [Qemu-devel] [PULL 11/14] nbd/client: Support qemu-img convert from unaligned size Eric Blake
2019-04-01 14:09 ` [Qemu-devel] [PULL 12/14] block: Add bdrv_get_request_alignment() Eric Blake
2019-04-01 14:09 ` [Qemu-devel] [PULL 13/14] nbd/server: Advertise actual minimum block size Eric Blake
2019-04-01 14:09 ` [Qemu-devel] [PULL 14/14] nbd/client: Trace server noncompliance on structured reads Eric Blake
2019-04-02  5:29 ` [Qemu-devel] [PULL 00/14] NBD patches for 4.0-rc2 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190401140903.19186-6-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.