Blame SOURCES/kvm-qemu-img-Gracefully-shutdown-when-map-can-t-finish.patch

7711c0
From f93730ef94f17043f240950d40d4661629b89aa3 Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Mon, 6 May 2019 17:56:15 +0200
7711c0
Subject: [PATCH 05/53] qemu-img: Gracefully shutdown when map can't finish
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190506175629.11079-6-jsnow@redhat.com>
7711c0
Patchwork-id: 87190
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 05/19] qemu-img: Gracefully shutdown when map can't finish
7711c0
Bugzilla: 1692018
7711c0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
7711c0
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
7711c0
RH-Acked-by: Thomas Huth <thuth@redhat.com>
7711c0
7711c0
From: Eric Blake <eblake@redhat.com>
7711c0
7711c0
Trying 'qemu-img map -f raw nbd://localhost:10809' causes the
7711c0
NBD server to output a scary message:
7711c0
7711c0
qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected end-of-file before all bytes were read
7711c0
7711c0
This is because the NBD client, being remote, has no way to expose a
7711c0
human-readable map (the --output=json data is fine, however). But
7711c0
because we exit(1) right after the message, causing the client to
7711c0
bypass all block cleanup, the server sees the abrupt exit and warns,
7711c0
whereas it would be silent had the client had a chance to send
7711c0
NBD_CMD_DISC. Other protocols may have similar cleanup issues, where
7711c0
failure to blk_unref() could cause unintended effects.
7711c0
7711c0
Signed-off-by: Eric Blake <eblake@redhat.com>
7711c0
Message-Id: <20190326184043.7544-1-eblake@redhat.com>
7711c0
Reviewed-by: John Snow <jsnow@redhat.com>
7711c0
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
7711c0
(cherry picked from commit 30065d142443981924786da72828ba683da35e8f)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 qemu-img.c | 14 +++++++++-----
7711c0
 1 file changed, 9 insertions(+), 5 deletions(-)
7711c0
7711c0
diff --git a/qemu-img.c b/qemu-img.c
7711c0
index 096e844..5be2abf 100644
7711c0
--- a/qemu-img.c
7711c0
+++ b/qemu-img.c
7711c0
@@ -2713,14 +2713,14 @@ static int img_info(int argc, char **argv)
7711c0
     return 0;
7711c0
 }
7711c0
 
7711c0
-static void dump_map_entry(OutputFormat output_format, MapEntry *e,
7711c0
-                           MapEntry *next)
7711c0
+static int dump_map_entry(OutputFormat output_format, MapEntry *e,
7711c0
+                          MapEntry *next)
7711c0
 {
7711c0
     switch (output_format) {
7711c0
     case OFORMAT_HUMAN:
7711c0
         if (e->data && !e->has_offset) {
7711c0
             error_report("File contains external, encrypted or compressed clusters.");
7711c0
-            exit(1);
7711c0
+            return -1;
7711c0
         }
7711c0
         if (e->data && !e->zero) {
7711c0
             printf("%#-16"PRIx64"%#-16"PRIx64"%#-16"PRIx64"%s\n",
7711c0
@@ -2753,6 +2753,7 @@ static void dump_map_entry(OutputFormat output_format, MapEntry *e,
7711c0
         }
7711c0
         break;
7711c0
     }
7711c0
+    return 0;
7711c0
 }
7711c0
 
7711c0
 static int get_block_status(BlockDriverState *bs, int64_t offset,
7711c0
@@ -2939,12 +2940,15 @@ static int img_map(int argc, char **argv)
7711c0
         }
7711c0
 
7711c0
         if (curr.length > 0) {
7711c0
-            dump_map_entry(output_format, &curr, &next;;
7711c0
+            ret = dump_map_entry(output_format, &curr, &next;;
7711c0
+            if (ret < 0) {
7711c0
+                goto out;
7711c0
+            }
7711c0
         }
7711c0
         curr = next;
7711c0
     }
7711c0
 
7711c0
-    dump_map_entry(output_format, &curr, NULL);
7711c0
+    ret = dump_map_entry(output_format, &curr, NULL);
7711c0
 
7711c0
 out:
7711c0
     blk_unref(blk);
7711c0
-- 
7711c0
1.8.3.1
7711c0