Blame SOURCES/kvm-qemu-io-Exit-with-error-when-a-command-failed.patch

383d26
From 4dad2c0644a22a935a87f86b4d63747a9598bb5d Mon Sep 17 00:00:00 2001
383d26
From: Max Reitz <mreitz@redhat.com>
383d26
Date: Mon, 18 Jun 2018 16:43:10 +0200
383d26
Subject: [PATCH 42/54] qemu-io: Exit with error when a command failed
383d26
383d26
RH-Author: Max Reitz <mreitz@redhat.com>
383d26
Message-id: <20180618164312.24423-4-mreitz@redhat.com>
383d26
Patchwork-id: 80780
383d26
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 3/5] qemu-io: Exit with error when a command failed
383d26
Bugzilla: 1519617
383d26
RH-Acked-by: John Snow <jsnow@redhat.com>
383d26
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
383d26
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
383d26
Currently, qemu-io basically always returns success when it gets to
383d26
interactive mode (so once the whole command line has been parsed; even
383d26
before the commands on the command line are interpreted).  That is not
383d26
very useful.
383d26
383d26
This patch makes qemu-io return failure when any of the executed
383d26
commands failed.
383d26
383d26
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1519617
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
Reviewed-by: Eric Blake <eblake@redhat.com>
383d26
Message-id: 20180509194302.21585-4-mreitz@redhat.com
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
(cherry picked from commit 6b3aa8485ca8e61b168f51d465188855cf549bd2)
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 qemu-io.c | 28 ++++++++++++++++++++++------
383d26
 1 file changed, 22 insertions(+), 6 deletions(-)
383d26
383d26
diff --git a/qemu-io.c b/qemu-io.c
383d26
index ec66838..13829f5 100644
383d26
--- a/qemu-io.c
383d26
+++ b/qemu-io.c
383d26
@@ -400,17 +400,21 @@ static void prep_fetchline(void *opaque)
383d26
     *fetchable= 1;
383d26
 }
383d26
 
383d26
-static void command_loop(void)
383d26
+static int command_loop(void)
383d26
 {
383d26
     int i, fetchable = 0, prompted = 0;
383d26
+    int ret, last_error = 0;
383d26
     char *input;
383d26
 
383d26
     for (i = 0; !quit_qemu_io && i < ncmdline; i++) {
383d26
-        qemuio_command(qemuio_blk, cmdline[i]);
383d26
+        ret = qemuio_command(qemuio_blk, cmdline[i]);
383d26
+        if (ret < 0) {
383d26
+            last_error = ret;
383d26
+        }
383d26
     }
383d26
     if (cmdline) {
383d26
         g_free(cmdline);
383d26
-        return;
383d26
+        return last_error;
383d26
     }
383d26
 
383d26
     while (!quit_qemu_io) {
383d26
@@ -431,13 +435,19 @@ static void command_loop(void)
383d26
         if (input == NULL) {
383d26
             break;
383d26
         }
383d26
-        qemuio_command(qemuio_blk, input);
383d26
+        ret = qemuio_command(qemuio_blk, input);
383d26
         g_free(input);
383d26
 
383d26
+        if (ret < 0) {
383d26
+            last_error = ret;
383d26
+        }
383d26
+
383d26
         prompted = 0;
383d26
         fetchable = 0;
383d26
     }
383d26
     qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
383d26
+
383d26
+    return last_error;
383d26
 }
383d26
 
383d26
 static void add_user_command(char *optarg)
383d26
@@ -502,6 +512,7 @@ int main(int argc, char **argv)
383d26
     int c;
383d26
     int opt_index = 0;
383d26
     int flags = BDRV_O_UNMAP;
383d26
+    int ret;
383d26
     bool writethrough = true;
383d26
     Error *local_error = NULL;
383d26
     QDict *opts = NULL;
383d26
@@ -663,7 +674,7 @@ int main(int argc, char **argv)
383d26
             }
383d26
         }
383d26
     }
383d26
-    command_loop();
383d26
+    ret = command_loop();
383d26
 
383d26
     /*
383d26
      * Make sure all outstanding requests complete before the program exits.
383d26
@@ -672,5 +683,10 @@ int main(int argc, char **argv)
383d26
 
383d26
     blk_unref(qemuio_blk);
383d26
     g_free(readline_state);
383d26
-    return 0;
383d26
+
383d26
+    if (ret < 0) {
383d26
+        return 1;
383d26
+    } else {
383d26
+        return 0;
383d26
+    }
383d26
 }
383d26
-- 
383d26
1.8.3.1
383d26