cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
34b321
From 2653e21a25d8fb99479337c785e81b07f755acda Mon Sep 17 00:00:00 2001
34b321
From: John Snow <jsnow@redhat.com>
34b321
Date: Mon, 23 Nov 2015 17:38:24 +0100
34b321
Subject: [PATCH 05/27] qemu-io: Don't use global bs in command implementations
34b321
34b321
RH-Author: John Snow <jsnow@redhat.com>
34b321
Message-id: <1448300320-7772-6-git-send-email-jsnow@redhat.com>
34b321
Patchwork-id: 68433
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 05/21] qemu-io: Don't use global bs in command implementations
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
Pass in the BlockDriverState to the command handlers instead of using
34b321
the global variable. This is an important step to make the commands
34b321
usable outside of qemu-io.
34b321
34b321
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34b321
Reviewed-by: Eric Blake <eblake@redhat.com>
34b321
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
(cherry picked from commit 734c3b85cb72d264ad2b38a87f30304e05de2cb1)
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
34b321
Conflicts:
34b321
  qemu-io.c
34b321
    Number of arguments to bdrv_co_write_zeroes
34b321
    bdrv_unref used downstream instead of bdrv_delete
34b321
    downstream, local_err used for bdrv_open
34b321
    downstream, error_abort used for bdrv_new
34b321
    map_is_allocated was never backported from a00e81e98f71
34b321
    sleep_f was backported, adjust its signature
34b321
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
---
34b321
 cmd.c     |   6 ++-
34b321
 cmd.h     |   8 ++-
34b321
 qemu-io.c | 164 ++++++++++++++++++++++++++++++++++----------------------------
34b321
 3 files changed, 99 insertions(+), 79 deletions(-)
34b321
34b321
diff --git a/cmd.c b/cmd.c
34b321
index 214c6f7..d501aab 100644
34b321
--- a/cmd.c
34b321
+++ b/cmd.c
34b321
@@ -57,7 +57,7 @@ check_command(
34b321
 	const cmdinfo_t	*ci)
34b321
 {
34b321
 	if (check_func)
34b321
-		return check_func(ci);
34b321
+		return check_func(qemuio_bs, ci);
34b321
 	return 1;
34b321
 }
34b321
 
34b321
@@ -103,7 +103,7 @@ command(
34b321
 		return 0;
34b321
 	}
34b321
 	optind = 0;
34b321
-	return ct->cfunc(argc, argv);
34b321
+	return ct->cfunc(qemuio_bs, argc, argv);
34b321
 }
34b321
 
34b321
 const cmdinfo_t *
34b321
@@ -452,6 +452,7 @@ static cmdinfo_t quit_cmd;
34b321
 /* ARGSUSED */
34b321
 static int
34b321
 quit_f(
34b321
+    BlockDriverState *bs,
34b321
 	int	argc,
34b321
 	char	**argv)
34b321
 {
34b321
@@ -490,6 +491,7 @@ help_all(void)
34b321
 
34b321
 static int
34b321
 help_f(
34b321
+    BlockDriverState *bs,
34b321
 	int		argc,
34b321
 	char		**argv)
34b321
 {
34b321
diff --git a/cmd.h b/cmd.h
34b321
index 4dcfe88..ccf6336 100644
34b321
--- a/cmd.h
34b321
+++ b/cmd.h
34b321
@@ -17,9 +17,13 @@
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
-typedef int (*cfunc_t)(int argc, char **argv);
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
@@ -41,7 +45,7 @@ extern int		ncmds;
34b321
 void help_init(void);
34b321
 void quit_init(void);
34b321
 
34b321
-typedef int (*checkfunc_t)(const cmdinfo_t *ci);
34b321
+typedef int (*checkfunc_t)(BlockDriverState *bs, const cmdinfo_t *ci);
34b321
 
34b321
 void add_command(const cmdinfo_t *ci);
34b321
 void add_user_command(char *optarg);
34b321
diff --git a/qemu-io.c b/qemu-io.c
34b321
index e4fa2fc..c3cc4f3 100644
34b321
--- a/qemu-io.c
34b321
+++ b/qemu-io.c
34b321
@@ -29,8 +29,8 @@
34b321
 #define CMD_NOFILE_OK   0x01
34b321
 
34b321
 char *progname;
34b321
-static BlockDriverState *bs;
34b321
 
34b321
+BlockDriverState *qemuio_bs;
34b321
 static int misalign;
34b321
 
34b321
 static int64_t cvtnum(const char *s)
34b321
@@ -67,7 +67,7 @@ static int parse_pattern(const char *arg)
34b321
  */
34b321
 
34b321
 #define MISALIGN_OFFSET     16
34b321
-static void *qemu_io_alloc(size_t len, int pattern)
34b321
+static void *qemu_io_alloc(BlockDriverState *bs, size_t len, int pattern)
34b321
 {
34b321
     void *buf;
34b321
 
34b321
@@ -140,7 +140,8 @@ static void print_report(const char *op, struct timeval *t, int64_t offset,
34b321
  * vector matching it.
34b321
  */
34b321
 static void *
34b321
-create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern)
34b321
+create_iovec(BlockDriverState *bs, QEMUIOVector *qiov, char **argv, int nr_iov,
34b321
+             int pattern)
34b321
 {
34b321
     size_t *sizes = g_new0(size_t, nr_iov);
34b321
     size_t count = 0;
34b321
@@ -176,7 +177,7 @@ create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern)
34b321
 
34b321
     qemu_iovec_init(qiov, nr_iov);
34b321
 
34b321
-    buf = p = qemu_io_alloc(count, pattern);
34b321
+    buf = p = qemu_io_alloc(bs, count, pattern);
34b321
 
34b321
     for (i = 0; i < nr_iov; i++) {
34b321
         qemu_iovec_add(qiov, p, sizes[i]);
34b321
@@ -188,7 +189,8 @@ fail:
34b321
     return buf;
34b321
 }
34b321
 
34b321
-static int do_read(char *buf, int64_t offset, int count, int *total)
34b321
+static int do_read(BlockDriverState *bs, char *buf, int64_t offset, int count,
34b321
+                   int *total)
34b321
 {
34b321
     int ret;
34b321
 
34b321
@@ -200,7 +202,8 @@ static int do_read(char *buf, int64_t offset, int count, int *total)
34b321
     return 1;
34b321
 }
34b321
 
34b321
-static int do_write(char *buf, int64_t offset, int count, int *total)
34b321
+static int do_write(BlockDriverState *bs, char *buf, int64_t offset, int count,
34b321
+                    int *total)
34b321
 {
34b321
     int ret;
34b321
 
34b321
@@ -212,7 +215,8 @@ static int do_write(char *buf, int64_t offset, int count, int *total)
34b321
     return 1;
34b321
 }
34b321
 
34b321
-static int do_pread(char *buf, int64_t offset, int count, int *total)
34b321
+static int do_pread(BlockDriverState *bs, char *buf, int64_t offset, int count,
34b321
+                    int *total)
34b321
 {
34b321
     *total = bdrv_pread(bs, offset, (uint8_t *)buf, count);
34b321
     if (*total < 0) {
34b321
@@ -221,7 +225,8 @@ static int do_pread(char *buf, int64_t offset, int count, int *total)
34b321
     return 1;
34b321
 }
34b321
 
34b321
-static int do_pwrite(char *buf, int64_t offset, int count, int *total)
34b321
+static int do_pwrite(BlockDriverState *bs, char *buf, int64_t offset, int count,
34b321
+                     int *total)
34b321
 {
34b321
     *total = bdrv_pwrite(bs, offset, (uint8_t *)buf, count);
34b321
     if (*total < 0) {
34b321
@@ -231,6 +236,7 @@ static int do_pwrite(char *buf, int64_t offset, int count, int *total)
34b321
 }
34b321
 
34b321
 typedef struct {
34b321
+    BlockDriverState *bs;
34b321
     int64_t offset;
34b321
     int count;
34b321
     int *total;
34b321
@@ -242,7 +248,7 @@ static void coroutine_fn co_write_zeroes_entry(void *opaque)
34b321
 {
34b321
     CoWriteZeroes *data = opaque;
34b321
 
34b321
-    data->ret = bdrv_co_write_zeroes(bs, data->offset / BDRV_SECTOR_SIZE,
34b321
+    data->ret = bdrv_co_write_zeroes(data->bs, data->offset / BDRV_SECTOR_SIZE,
34b321
                                      data->count / BDRV_SECTOR_SIZE, 0);
34b321
     data->done = true;
34b321
     if (data->ret < 0) {
34b321
@@ -253,10 +259,12 @@ static void coroutine_fn co_write_zeroes_entry(void *opaque)
34b321
     *data->total = data->count;
34b321
 }
34b321
 
34b321
-static int do_co_write_zeroes(int64_t offset, int count, int *total)
34b321
+static int do_co_write_zeroes(BlockDriverState *bs, int64_t offset, int count,
34b321
+                              int *total)
34b321
 {
34b321
     Coroutine *co;
34b321
     CoWriteZeroes data = {
34b321
+        .bs     = bs,
34b321
         .offset = offset,
34b321
         .count  = count,
34b321
         .total  = total,
34b321
@@ -275,7 +283,8 @@ static int do_co_write_zeroes(int64_t offset, int count, int *total)
34b321
     }
34b321
 }
34b321
 
34b321
-static int do_write_compressed(char *buf, int64_t offset, int count, int *total)
34b321
+static int do_write_compressed(BlockDriverState *bs, char *buf, int64_t offset,
34b321
+                               int count, int *total)
34b321
 {
34b321
     int ret;
34b321
 
34b321
@@ -287,7 +296,8 @@ static int do_write_compressed(char *buf, int64_t offset, int count, int *total)
34b321
     return 1;
34b321
 }
34b321
 
34b321
-static int do_load_vmstate(char *buf, int64_t offset, int count, int *total)
34b321
+static int do_load_vmstate(BlockDriverState *bs, char *buf, int64_t offset,
34b321
+                           int count, int *total)
34b321
 {
34b321
     *total = bdrv_load_vmstate(bs, (uint8_t *)buf, offset, count);
34b321
     if (*total < 0) {
34b321
@@ -296,7 +306,8 @@ static int do_load_vmstate(char *buf, int64_t offset, int count, int *total)
34b321
     return 1;
34b321
 }
34b321
 
34b321
-static int do_save_vmstate(char *buf, int64_t offset, int count, int *total)
34b321
+static int do_save_vmstate(BlockDriverState *bs, char *buf, int64_t offset,
34b321
+                           int count, int *total)
34b321
 {
34b321
     *total = bdrv_save_vmstate(bs, (uint8_t *)buf, offset, count);
34b321
     if (*total < 0) {
34b321
@@ -311,7 +322,8 @@ static void aio_rw_done(void *opaque, int ret)
34b321
     *(int *)opaque = ret;
34b321
 }
34b321
 
34b321
-static int do_aio_readv(QEMUIOVector *qiov, int64_t offset, int *total)
34b321
+static int do_aio_readv(BlockDriverState *bs, QEMUIOVector *qiov,
34b321
+                        int64_t offset, int *total)
34b321
 {
34b321
     int async_ret = NOT_DONE;
34b321
 
34b321
@@ -325,7 +337,8 @@ static int do_aio_readv(QEMUIOVector *qiov, int64_t offset, int *total)
34b321
     return async_ret < 0 ? async_ret : 1;
34b321
 }
34b321
 
34b321
-static int do_aio_writev(QEMUIOVector *qiov, int64_t offset, int *total)
34b321
+static int do_aio_writev(BlockDriverState *bs, QEMUIOVector *qiov,
34b321
+                         int64_t offset, int *total)
34b321
 {
34b321
     int async_ret = NOT_DONE;
34b321
 
34b321
@@ -354,7 +367,8 @@ static void multiwrite_cb(void *opaque, int ret)
34b321
     }
34b321
 }
34b321
 
34b321
-static int do_aio_multiwrite(BlockRequest* reqs, int num_reqs, int *total)
34b321
+static int do_aio_multiwrite(BlockDriverState *bs, BlockRequest* reqs,
34b321
+                             int num_reqs, int *total)
34b321
 {
34b321
     int i, ret;
34b321
     struct multiwrite_async_ret async_ret = {
34b321
@@ -403,7 +417,7 @@ static void read_help(void)
34b321
 "\n");
34b321
 }
34b321
 
34b321
-static int read_f(int argc, char **argv);
34b321
+static int read_f(BlockDriverState *bs, int argc, char **argv);
34b321
 
34b321
 static const cmdinfo_t read_cmd = {
34b321
     .name       = "read",
34b321
@@ -416,7 +430,7 @@ static const cmdinfo_t read_cmd = {
34b321
     .help       = read_help,
34b321
 };
34b321
 
34b321
-static int read_f(int argc, char **argv)
34b321
+static int read_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     struct timeval t1, t2;
34b321
     int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;
34b321
@@ -522,15 +536,15 @@ static int read_f(int argc, char **argv)
34b321
         }
34b321
     }
34b321
 
34b321
-    buf = qemu_io_alloc(count, 0xab);
34b321
+    buf = qemu_io_alloc(bs, count, 0xab);
34b321
 
34b321
     gettimeofday(&t1, NULL);
34b321
     if (pflag) {
34b321
-        cnt = do_pread(buf, offset, count, &total);
34b321
+        cnt = do_pread(bs, buf, offset, count, &total);
34b321
     } else if (bflag) {
34b321
-        cnt = do_load_vmstate(buf, offset, count, &total);
34b321
+        cnt = do_load_vmstate(bs, buf, offset, count, &total);
34b321
     } else {
34b321
-        cnt = do_read(buf, offset, count, &total);
34b321
+        cnt = do_read(bs, buf, offset, count, &total);
34b321
     }
34b321
     gettimeofday(&t2, NULL);
34b321
 
34b321
@@ -587,7 +601,7 @@ static void readv_help(void)
34b321
 "\n");
34b321
 }
34b321
 
34b321
-static int readv_f(int argc, char **argv);
34b321
+static int readv_f(BlockDriverState *bs, int argc, char **argv);
34b321
 
34b321
 static const cmdinfo_t readv_cmd = {
34b321
     .name       = "readv",
34b321
@@ -599,7 +613,7 @@ static const cmdinfo_t readv_cmd = {
34b321
     .help       = readv_help,
34b321
 };
34b321
 
34b321
-static int readv_f(int argc, char **argv)
34b321
+static int readv_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     struct timeval t1, t2;
34b321
     int Cflag = 0, qflag = 0, vflag = 0;
34b321
@@ -655,13 +669,13 @@ static int readv_f(int argc, char **argv)
34b321
     }
34b321
 
34b321
     nr_iov = argc - optind;
34b321
-    buf = create_iovec(&qiov, &argv[optind], nr_iov, 0xab);
34b321
+    buf = create_iovec(bs, &qiov, &argv[optind], nr_iov, 0xab);
34b321
     if (buf == NULL) {
34b321
         return 0;
34b321
     }
34b321
 
34b321
     gettimeofday(&t1, NULL);
34b321
-    cnt = do_aio_readv(&qiov, offset, &total);
34b321
+    cnt = do_aio_readv(bs, &qiov, offset, &total);
34b321
     gettimeofday(&t2, NULL);
34b321
 
34b321
     if (cnt < 0) {
34b321
@@ -718,7 +732,7 @@ static void write_help(void)
34b321
 "\n");
34b321
 }
34b321
 
34b321
-static int write_f(int argc, char **argv);
34b321
+static int write_f(BlockDriverState *bs, int argc, char **argv);
34b321
 
34b321
 static const cmdinfo_t write_cmd = {
34b321
     .name       = "write",
34b321
@@ -731,7 +745,7 @@ static const cmdinfo_t write_cmd = {
34b321
     .help       = write_help,
34b321
 };
34b321
 
34b321
-static int write_f(int argc, char **argv)
34b321
+static int write_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     struct timeval t1, t2;
34b321
     int Cflag = 0, pflag = 0, qflag = 0, bflag = 0, Pflag = 0, zflag = 0;
34b321
@@ -818,20 +832,20 @@ static int write_f(int argc, char **argv)
34b321
     }
34b321
 
34b321
     if (!zflag) {
34b321
-        buf = qemu_io_alloc(count, pattern);
34b321
+        buf = qemu_io_alloc(bs, count, pattern);
34b321
     }
34b321
 
34b321
     gettimeofday(&t1, NULL);
34b321
     if (pflag) {
34b321
-        cnt = do_pwrite(buf, offset, count, &total);
34b321
+        cnt = do_pwrite(bs, buf, offset, count, &total);
34b321
     } else if (bflag) {
34b321
-        cnt = do_save_vmstate(buf, offset, count, &total);
34b321
+        cnt = do_save_vmstate(bs, buf, offset, count, &total);
34b321
     } else if (zflag) {
34b321
-        cnt = do_co_write_zeroes(offset, count, &total);
34b321
+        cnt = do_co_write_zeroes(bs, offset, count, &total);
34b321
     } else if (cflag) {
34b321
-        cnt = do_write_compressed(buf, offset, count, &total);
34b321
+        cnt = do_write_compressed(bs, buf, offset, count, &total);
34b321
     } else {
34b321
-        cnt = do_write(buf, offset, count, &total);
34b321
+        cnt = do_write(bs, buf, offset, count, &total);
34b321
     }
34b321
     gettimeofday(&t2, NULL);
34b321
 
34b321
@@ -874,7 +888,7 @@ writev_help(void)
34b321
 "\n");
34b321
 }
34b321
 
34b321
-static int writev_f(int argc, char **argv);
34b321
+static int writev_f(BlockDriverState *bs, int argc, char **argv);
34b321
 
34b321
 static const cmdinfo_t writev_cmd = {
34b321
     .name       = "writev",
34b321
@@ -886,7 +900,7 @@ static const cmdinfo_t writev_cmd = {
34b321
     .help       = writev_help,
34b321
 };
34b321
 
34b321
-static int writev_f(int argc, char **argv)
34b321
+static int writev_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     struct timeval t1, t2;
34b321
     int Cflag = 0, qflag = 0;
34b321
@@ -936,13 +950,13 @@ static int writev_f(int argc, char **argv)
34b321
     }
34b321
 
34b321
     nr_iov = argc - optind;
34b321
-    buf = create_iovec(&qiov, &argv[optind], nr_iov, pattern);
34b321
+    buf = create_iovec(bs, &qiov, &argv[optind], nr_iov, pattern);
34b321
     if (buf == NULL) {
34b321
         return 0;
34b321
     }
34b321
 
34b321
     gettimeofday(&t1, NULL);
34b321
-    cnt = do_aio_writev(&qiov, offset, &total);
34b321
+    cnt = do_aio_writev(bs, &qiov, offset, &total);
34b321
     gettimeofday(&t2, NULL);
34b321
 
34b321
     if (cnt < 0) {
34b321
@@ -983,7 +997,7 @@ static void multiwrite_help(void)
34b321
 "\n");
34b321
 }
34b321
 
34b321
-static int multiwrite_f(int argc, char **argv);
34b321
+static int multiwrite_f(BlockDriverState *bs, int argc, char **argv);
34b321
 
34b321
 static const cmdinfo_t multiwrite_cmd = {
34b321
     .name       = "multiwrite",
34b321
@@ -995,7 +1009,7 @@ static const cmdinfo_t multiwrite_cmd = {
34b321
     .help       = multiwrite_help,
34b321
 };
34b321
 
34b321
-static int multiwrite_f(int argc, char **argv)
34b321
+static int multiwrite_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     struct timeval t1, t2;
34b321
     int Cflag = 0, qflag = 0;
34b321
@@ -1076,7 +1090,7 @@ static int multiwrite_f(int argc, char **argv)
34b321
         nr_iov = j - optind;
34b321
 
34b321
         /* Build request */
34b321
-        buf[i] = create_iovec(&qiovs[i], &argv[optind], nr_iov, pattern);
34b321
+        buf[i] = create_iovec(bs, &qiovs[i], &argv[optind], nr_iov, pattern);
34b321
         if (buf[i] == NULL) {
34b321
             goto out;
34b321
         }
34b321
@@ -1094,7 +1108,7 @@ static int multiwrite_f(int argc, char **argv)
34b321
     nr_reqs = i;
34b321
 
34b321
     gettimeofday(&t1, NULL);
34b321
-    cnt = do_aio_multiwrite(reqs, nr_reqs, &total);
34b321
+    cnt = do_aio_multiwrite(bs, reqs, nr_reqs, &total);
34b321
     gettimeofday(&t2, NULL);
34b321
 
34b321
     if (cnt < 0) {
34b321
@@ -1222,7 +1236,7 @@ static void aio_read_help(void)
34b321
 "\n");
34b321
 }
34b321
 
34b321
-static int aio_read_f(int argc, char **argv);
34b321
+static int aio_read_f(BlockDriverState *bs, int argc, char **argv);
34b321
 
34b321
 static const cmdinfo_t aio_read_cmd = {
34b321
     .name       = "aio_read",
34b321
@@ -1234,7 +1248,7 @@ static const cmdinfo_t aio_read_cmd = {
34b321
     .help       = aio_read_help,
34b321
 };
34b321
 
34b321
-static int aio_read_f(int argc, char **argv)
34b321
+static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     int nr_iov, c;
34b321
     struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
34b321
@@ -1285,7 +1299,7 @@ static int aio_read_f(int argc, char **argv)
34b321
     }
34b321
 
34b321
     nr_iov = argc - optind;
34b321
-    ctx->buf = create_iovec(&ctx->qiov, &argv[optind], nr_iov, 0xab);
34b321
+    ctx->buf = create_iovec(bs, &ctx->qiov, &argv[optind], nr_iov, 0xab);
34b321
     if (ctx->buf == NULL) {
34b321
         g_free(ctx);
34b321
         return 0;
34b321
@@ -1317,7 +1331,7 @@ static void aio_write_help(void)
34b321
 "\n");
34b321
 }
34b321
 
34b321
-static int aio_write_f(int argc, char **argv);
34b321
+static int aio_write_f(BlockDriverState *bs, int argc, char **argv);
34b321
 
34b321
 static const cmdinfo_t aio_write_cmd = {
34b321
     .name       = "aio_write",
34b321
@@ -1329,7 +1343,7 @@ static const cmdinfo_t aio_write_cmd = {
34b321
     .help       = aio_write_help,
34b321
 };
34b321
 
34b321
-static int aio_write_f(int argc, char **argv)
34b321
+static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     int nr_iov, c;
34b321
     int pattern = 0xcd;
34b321
@@ -1377,7 +1391,7 @@ static int aio_write_f(int argc, char **argv)
34b321
     }
34b321
 
34b321
     nr_iov = argc - optind;
34b321
-    ctx->buf = create_iovec(&ctx->qiov, &argv[optind], nr_iov, pattern);
34b321
+    ctx->buf = create_iovec(bs, &ctx->qiov, &argv[optind], nr_iov, pattern);
34b321
     if (ctx->buf == NULL) {
34b321
         g_free(ctx);
34b321
         return 0;
34b321
@@ -1389,7 +1403,7 @@ static int aio_write_f(int argc, char **argv)
34b321
     return 0;
34b321
 }
34b321
 
34b321
-static int aio_flush_f(int argc, char **argv)
34b321
+static int aio_flush_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     bdrv_drain_all();
34b321
     return 0;
34b321
@@ -1401,7 +1415,7 @@ static const cmdinfo_t aio_flush_cmd = {
34b321
     .oneline    = "completes all outstanding aio requests"
34b321
 };
34b321
 
34b321
-static int flush_f(int argc, char **argv)
34b321
+static int flush_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     bdrv_flush(bs);
34b321
     return 0;
34b321
@@ -1414,7 +1428,7 @@ static const cmdinfo_t flush_cmd = {
34b321
     .oneline    = "flush all in-core file state to disk",
34b321
 };
34b321
 
34b321
-static int truncate_f(int argc, char **argv)
34b321
+static int truncate_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     int64_t offset;
34b321
     int ret;
34b321
@@ -1444,7 +1458,7 @@ static const cmdinfo_t truncate_cmd = {
34b321
     .oneline    = "truncates the current file at the given offset",
34b321
 };
34b321
 
34b321
-static int length_f(int argc, char **argv)
34b321
+static int length_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     int64_t size;
34b321
     char s1[64];
34b321
@@ -1469,7 +1483,7 @@ static const cmdinfo_t length_cmd = {
34b321
 };
34b321
 
34b321
 
34b321
-static int info_f(int argc, char **argv)
34b321
+static int info_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     BlockDriverInfo bdi;
34b321
     ImageInfoSpecific *spec_info;
34b321
@@ -1528,7 +1542,7 @@ static void discard_help(void)
34b321
 "\n");
34b321
 }
34b321
 
34b321
-static int discard_f(int argc, char **argv);
34b321
+static int discard_f(BlockDriverState *bs, int argc, char **argv);
34b321
 
34b321
 static const cmdinfo_t discard_cmd = {
34b321
     .name       = "discard",
34b321
@@ -1541,7 +1555,7 @@ static const cmdinfo_t discard_cmd = {
34b321
     .help       = discard_help,
34b321
 };
34b321
 
34b321
-static int discard_f(int argc, char **argv)
34b321
+static int discard_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     struct timeval t1, t2;
34b321
     int Cflag = 0, qflag = 0;
34b321
@@ -1599,7 +1613,7 @@ out:
34b321
     return 0;
34b321
 }
34b321
 
34b321
-static int alloc_f(int argc, char **argv)
34b321
+static int alloc_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     int64_t offset, sector_num;
34b321
     int nb_sectors, remaining;
34b321
@@ -1664,7 +1678,7 @@ static const cmdinfo_t alloc_cmd = {
34b321
     .oneline    = "checks if a sector is present in the file",
34b321
 };
34b321
 
34b321
-static int map_f(int argc, char **argv)
34b321
+static int map_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     int64_t offset;
34b321
     int64_t nb_sectors;
34b321
@@ -1700,7 +1714,7 @@ static const cmdinfo_t map_cmd = {
34b321
        .oneline        = "prints the allocated areas of a file",
34b321
 };
34b321
 
34b321
-static int break_f(int argc, char **argv)
34b321
+static int break_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     int ret;
34b321
 
34b321
@@ -1722,7 +1736,7 @@ static const cmdinfo_t break_cmd = {
34b321
                          "request as tag",
34b321
 };
34b321
 
34b321
-static int resume_f(int argc, char **argv)
34b321
+static int resume_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     int ret;
34b321
 
34b321
@@ -1743,7 +1757,7 @@ static const cmdinfo_t resume_cmd = {
34b321
        .oneline        = "resumes the request tagged as tag",
34b321
 };
34b321
 
34b321
-static int wait_break_f(int argc, char **argv)
34b321
+static int wait_break_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     while (!bdrv_debug_is_suspended(bs, argv[1])) {
34b321
         qemu_aio_wait();
34b321
@@ -1761,7 +1775,7 @@ static const cmdinfo_t wait_break_cmd = {
34b321
        .oneline        = "waits for the suspension of a request",
34b321
 };
34b321
 
34b321
-static int abort_f(int argc, char **argv)
34b321
+static int abort_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     abort();
34b321
 }
34b321
@@ -1773,10 +1787,10 @@ static const cmdinfo_t abort_cmd = {
34b321
        .oneline        = "simulate a program crash using abort(3)",
34b321
 };
34b321
 
34b321
-static int close_f(int argc, char **argv)
34b321
+static int close_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     bdrv_unref(bs);
34b321
-    bs = NULL;
34b321
+    qemuio_bs = NULL;
34b321
     return 0;
34b321
 }
34b321
 
34b321
@@ -1793,7 +1807,7 @@ static void sleep_cb(void *opaque)
34b321
     *expired = true;
34b321
 }
34b321
 
34b321
-static int sleep_f(int argc, char **argv)
34b321
+static int sleep_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     char *endptr;
34b321
     long ms;
34b321
@@ -1831,27 +1845,27 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
34b321
 {
34b321
     Error *local_err = NULL;
34b321
 
34b321
-    if (bs) {
34b321
+    if (qemuio_bs) {
34b321
         fprintf(stderr, "file open already, try 'help close'\n");
34b321
         return 1;
34b321
     }
34b321
 
34b321
     if (growable) {
34b321
-        if (bdrv_file_open(&bs, name, opts, flags, &local_err)) {
34b321
+        if (bdrv_file_open(&qemuio_bs, name, opts, flags, &local_err)) {
34b321
             fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
34b321
                     error_get_pretty(local_err));
34b321
             error_free(local_err);
34b321
             return 1;
34b321
         }
34b321
     } else {
34b321
-        bs = bdrv_new("hda", &error_abort);
34b321
+        qemuio_bs = bdrv_new("hda", &error_abort);
34b321
 
34b321
-        if (bdrv_open(bs, name, opts, flags, NULL, &local_err) < 0) {
34b321
+        if (bdrv_open(qemuio_bs, name, opts, flags, NULL, &local_err) < 0) {
34b321
             fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
34b321
                     error_get_pretty(local_err));
34b321
             error_free(local_err);
34b321
-            bdrv_unref(bs);
34b321
-            bs = NULL;
34b321
+            bdrv_unref(qemuio_bs);
34b321
+            qemuio_bs = NULL;
34b321
             return 1;
34b321
         }
34b321
     }
34b321
@@ -1877,7 +1891,7 @@ static void open_help(void)
34b321
 "\n");
34b321
 }
34b321
 
34b321
-static int open_f(int argc, char **argv);
34b321
+static int open_f(BlockDriverState *bs, int argc, char **argv);
34b321
 
34b321
 static const cmdinfo_t open_cmd = {
34b321
     .name       = "open",
34b321
@@ -1900,7 +1914,7 @@ static QemuOptsList empty_opts = {
34b321
     },
34b321
 };
34b321
 
34b321
-static int open_f(int argc, char **argv)
34b321
+static int open_f(BlockDriverState *bs, int argc, char **argv)
34b321
 {
34b321
     int flags = 0;
34b321
     int readonly = 0;
34b321
@@ -1948,7 +1962,7 @@ static int open_f(int argc, char **argv)
34b321
     return openfile(argv[optind], flags, growable, opts);
34b321
 }
34b321
 
34b321
-static int init_check_command(const cmdinfo_t *ct)
34b321
+static int init_check_command(BlockDriverState *bs, const cmdinfo_t *ct)
34b321
 {
34b321
     if (ct->flags & CMD_FLAG_GLOBAL) {
34b321
         return 1;
34b321
@@ -2117,8 +2131,8 @@ int main(int argc, char **argv)
34b321
      */
34b321
     bdrv_drain_all();
34b321
 
34b321
-    if (bs) {
34b321
-        bdrv_unref(bs);
34b321
+    if (qemuio_bs) {
34b321
+        bdrv_unref(qemuio_bs);
34b321
     }
34b321
     return 0;
34b321
 }
34b321
-- 
34b321
1.8.3.1
34b321