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

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