34b321
From 0dfb1b6f831f5b2a1fdf5e77330db3c95db2e464 Mon Sep 17 00:00:00 2001
34b321
From: John Snow <jsnow@redhat.com>
34b321
Date: Mon, 23 Nov 2015 17:38:33 +0100
34b321
Subject: [PATCH 14/27] qemu-io: Interface cleanup
34b321
34b321
RH-Author: John Snow <jsnow@redhat.com>
34b321
Message-id: <1448300320-7772-15-git-send-email-jsnow@redhat.com>
34b321
Patchwork-id: 68444
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 14/21] qemu-io: Interface cleanup
34b321
Bugzilla: 1272523
34b321
RH-Acked-by: Thomas Huth <thuth@redhat.com>
34b321
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
34b321
RH-Acked-by: Max Reitz <mreitz@redhat.com>
34b321
34b321
From: Kevin Wolf <kwolf@redhat.com>
34b321
34b321
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34b321
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
(cherry picked from commit 3d21994f9c511cb63220fef5abea164b83fbb997)
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
34b321
Conflicts:
34b321
  qemu-io-cmds.c: include block/qapi.h context
34b321
  qemu-io.c       include block/qapi.h context
34b321
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
---
34b321
 cmd.h             | 48 ------------------------------------------------
34b321
 include/qemu-io.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++
34b321
 qemu-io-cmds.c    | 14 +++++++-------
34b321
 qemu-io.c         |  7 +++----
34b321
 4 files changed, 56 insertions(+), 59 deletions(-)
34b321
 delete mode 100644 cmd.h
34b321
 create mode 100644 include/qemu-io.h
34b321
34b321
diff --git a/cmd.h b/cmd.h
34b321
deleted file mode 100644
34b321
index 9907795..0000000
34b321
--- a/cmd.h
34b321
+++ /dev/null
34b321
@@ -1,48 +0,0 @@
34b321
-/*
34b321
- * Copyright (c) 2000-2005 Silicon Graphics, Inc.
34b321
- * All Rights Reserved.
34b321
- *
34b321
- * This program is free software; you can redistribute it and/or
34b321
- * modify it under the terms of the GNU General Public License as
34b321
- * published by the Free Software Foundation.
34b321
- *
34b321
- * This program is distributed in the hope that it would be useful,
34b321
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
34b321
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34b321
- * GNU General Public License for more details.
34b321
- *
34b321
- * You should have received a copy of the GNU General Public License
34b321
- * along with this program; if not, see <http: www.gnu.org="" licenses=""/>.
34b321
- */
34b321
-#ifndef __COMMAND_H__
34b321
-#define __COMMAND_H__
34b321
-
34b321
-#include "qemu-common.h"
34b321
-
34b321
-#define CMD_FLAG_GLOBAL	((int)0x80000000)	/* don't iterate "args" */
34b321
-
34b321
-extern BlockDriverState *qemuio_bs;
34b321
-
34b321
-typedef int (*cfunc_t)(BlockDriverState *bs, int argc, char **argv);
34b321
-typedef void (*helpfunc_t)(void);
34b321
-
34b321
-typedef struct cmdinfo {
34b321
-	const char	*name;
34b321
-	const char	*altname;
34b321
-	cfunc_t		cfunc;
34b321
-	int		argmin;
34b321
-	int		argmax;
34b321
-	int		canpush;
34b321
-	int		flags;
34b321
-	const char	*args;
34b321
-	const char	*oneline;
34b321
-	helpfunc_t      help;
34b321
-} cmdinfo_t;
34b321
-
34b321
-void qemuio_add_command(const cmdinfo_t *ci);
34b321
-
34b321
-int qemuio_command_usage(const cmdinfo_t *ci);
34b321
-
34b321
-bool qemuio_command(const char *cmd);
34b321
-
34b321
-#endif	/* __COMMAND_H__ */
34b321
diff --git a/include/qemu-io.h b/include/qemu-io.h
34b321
new file mode 100644
34b321
index 0000000..a418b46
34b321
--- /dev/null
34b321
+++ b/include/qemu-io.h
34b321
@@ -0,0 +1,46 @@
34b321
+/*
34b321
+ * Copyright (c) 2000-2005 Silicon Graphics, Inc.
34b321
+ * All Rights Reserved.
34b321
+ *
34b321
+ * This program is free software; you can redistribute it and/or
34b321
+ * modify it under the terms of the GNU General Public License as
34b321
+ * published by the Free Software Foundation.
34b321
+ *
34b321
+ * This program is distributed in the hope that it would be useful,
34b321
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
34b321
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34b321
+ * GNU General Public License for more details.
34b321
+ *
34b321
+ * You should have received a copy of the GNU General Public License
34b321
+ * along with this program; if not, see <http: www.gnu.org="" licenses=""/>.
34b321
+ */
34b321
+
34b321
+#ifndef QEMU_IO_H
34b321
+#define QEMU_IO_H
34b321
+
34b321
+#include "qemu-common.h"
34b321
+
34b321
+#define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */
34b321
+
34b321
+typedef int (*cfunc_t)(BlockDriverState *bs, int argc, char **argv);
34b321
+typedef void (*helpfunc_t)(void);
34b321
+
34b321
+typedef struct cmdinfo {
34b321
+    const char* name;
34b321
+    const char* altname;
34b321
+    cfunc_t     cfunc;
34b321
+    int         argmin;
34b321
+    int         argmax;
34b321
+    int         canpush;
34b321
+    int         flags;
34b321
+    const char  *args;
34b321
+    const char  *oneline;
34b321
+    helpfunc_t  help;
34b321
+} cmdinfo_t;
34b321
+
34b321
+bool qemuio_command(BlockDriverState *bs, const char *cmd);
34b321
+
34b321
+void qemuio_add_command(const cmdinfo_t *ci);
34b321
+int qemuio_command_usage(const cmdinfo_t *ci);
34b321
+
34b321
+#endif /* QEMU_IO_H */
34b321
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
34b321
index 1db7fb9..1f21ce9 100644
34b321
--- a/qemu-io-cmds.c
34b321
+++ b/qemu-io-cmds.c
34b321
@@ -8,10 +8,9 @@
34b321
  * See the COPYING file in the top-level directory.
34b321
  */
34b321
 
34b321
-#include "qemu-common.h"
34b321
+#include "qemu-io.h"
34b321
 #include "block/block_int.h"
34b321
 #include "block/qapi.h"
34b321
-#include "cmd.h"
34b321
 
34b321
 #define CMD_NOFILE_OK   0x01
34b321
 
34b321
@@ -51,11 +50,12 @@ static int init_check_command(BlockDriverState *bs, const cmdinfo_t *ct)
34b321
     return 1;
34b321
 }
34b321
 
34b321
-static int command(const cmdinfo_t *ct, int argc, char **argv)
34b321
+static int command(BlockDriverState *bs, const cmdinfo_t *ct, int argc,
34b321
+                   char **argv)
34b321
 {
34b321
     char *cmd = argv[0];
34b321
 
34b321
-    if (!init_check_command(qemuio_bs, ct)) {
34b321
+    if (!init_check_command(bs, ct)) {
34b321
         return 0;
34b321
     }
34b321
 
34b321
@@ -76,7 +76,7 @@ static int command(const cmdinfo_t *ct, int argc, char **argv)
34b321
         return 0;
34b321
     }
34b321
     optind = 0;
34b321
-    return ct->cfunc(qemuio_bs, argc, argv);
34b321
+    return ct->cfunc(bs, argc, argv);
34b321
 }
34b321
 
34b321
 static const cmdinfo_t *find_command(const char *cmd)
34b321
@@ -2084,7 +2084,7 @@ static const cmdinfo_t help_cmd = {
34b321
     .oneline    = "help for one or all commands",
34b321
 };
34b321
 
34b321
-bool qemuio_command(const char *cmd)
34b321
+bool qemuio_command(BlockDriverState *bs, const char *cmd)
34b321
 {
34b321
     char *input;
34b321
     const cmdinfo_t *ct;
34b321
@@ -2097,7 +2097,7 @@ bool qemuio_command(const char *cmd)
34b321
     if (c) {
34b321
         ct = find_command(v[0]);
34b321
         if (ct) {
34b321
-            done = command(ct, c, v);
34b321
+            done = command(bs, ct, c, v);
34b321
         } else {
34b321
             fprintf(stderr, "command \"%s\" not found\n", v[0]);
34b321
         }
34b321
diff --git a/qemu-io.c b/qemu-io.c
34b321
index da9944e..e685808 100644
34b321
--- a/qemu-io.c
34b321
+++ b/qemu-io.c
34b321
@@ -14,13 +14,12 @@
34b321
 #include <getopt.h>
34b321
 #include <libgen.h>
34b321
 
34b321
-#include "qemu-common.h"
34b321
+#include "qemu-io.h"
34b321
 #include "qemu/main-loop.h"
34b321
 #include "qemu/option.h"
34b321
 #include "qemu/config-file.h"
34b321
 #include "block/block_int.h"
34b321
 #include "block/qapi.h"
34b321
-#include "cmd.h"
34b321
 #include "trace/control.h"
34b321
 #include "qemu/timer.h"
34b321
 
34b321
@@ -306,7 +305,7 @@ static void command_loop(void)
34b321
     char *input;
34b321
 
34b321
     for (i = 0; !done && i < ncmdline; i++) {
34b321
-        done = qemuio_command(cmdline[i]);
34b321
+        done = qemuio_command(qemuio_bs, cmdline[i]);
34b321
     }
34b321
     if (cmdline) {
34b321
         g_free(cmdline);
34b321
@@ -331,7 +330,7 @@ static void command_loop(void)
34b321
         if (input == NULL) {
34b321
             break;
34b321
         }
34b321
-        done = qemuio_command(input);
34b321
+        done = qemuio_command(qemuio_bs, input);
34b321
         g_free(input);
34b321
 
34b321
         prompted = 0;
34b321
-- 
34b321
1.8.3.1
34b321