mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
qemu-io: Use BlockBackend
qemu-io should behave like a guest, therefore it should use BlockBackend to access the block layer. There are a couple of places where that is infeasible: First, the bdrv_debug_* functions could theoretically be mirrored in the BlockBackend, but since these are functions internal to the block layer, they should not be visible externally (qemu-io as a test tool is exempt from this). Second, bdrv_get_info() and bdrv_get_specific_info() work on a single BDS alone, therefore they should stay BDS-specific. Third, bdrv_is_allocated() mainly works on a single BDS as well. Some data may be passed through from the BDS's file (if sectors which are apparently allocated in the file are not really allocated there but just zero). [Fixed conflicts around block_acct_start() usage from Fam Zheng's "qemu-io: Account IO by aio_read and aio_write" commit. Use BlockBackend and blk_get_stats() instead of BlockDriverState. --Stefan] Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 1423162705-32065-14-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
committed by
Stefan Hajnoczi
parent
10d9d75ce4
commit
4c7b7e9b94
@@ -16,6 +16,7 @@
|
||||
#include "hmp.h"
|
||||
#include "net/net.h"
|
||||
#include "sysemu/char.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/timer.h"
|
||||
#include "qmp-commands.h"
|
||||
@@ -1720,14 +1721,14 @@ void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
|
||||
|
||||
void hmp_qemu_io(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
BlockDriverState *bs;
|
||||
BlockBackend *blk;
|
||||
const char* device = qdict_get_str(qdict, "device");
|
||||
const char* command = qdict_get_str(qdict, "command");
|
||||
Error *err = NULL;
|
||||
|
||||
bs = bdrv_find(device);
|
||||
if (bs) {
|
||||
qemuio_command(bs, command);
|
||||
blk = blk_by_name(device);
|
||||
if (blk) {
|
||||
qemuio_command(blk, command);
|
||||
} else {
|
||||
error_set(&err, QERR_DEVICE_NOT_FOUND, device);
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@
|
||||
|
||||
#define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */
|
||||
|
||||
typedef int (*cfunc_t)(BlockDriverState *bs, int argc, char **argv);
|
||||
typedef int (*cfunc_t)(BlockBackend *blk, int argc, char **argv);
|
||||
typedef void (*helpfunc_t)(void);
|
||||
|
||||
typedef struct cmdinfo {
|
||||
@@ -40,7 +40,7 @@ typedef struct cmdinfo {
|
||||
|
||||
extern bool qemuio_misalign;
|
||||
|
||||
bool qemuio_command(BlockDriverState *bs, const char *cmd);
|
||||
bool qemuio_command(BlockBackend *blk, const char *cmd);
|
||||
|
||||
void qemuio_add_command(const cmdinfo_t *ci);
|
||||
int qemuio_command_usage(const cmdinfo_t *ci);
|
||||
|
||||
+133
-120
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,6 @@
|
||||
static char *progname;
|
||||
|
||||
static BlockBackend *qemuio_blk;
|
||||
static BlockDriverState *qemuio_bs;
|
||||
|
||||
/* qemu-io commands passed using -c */
|
||||
static int ncmdline;
|
||||
@@ -36,10 +35,9 @@ static char **cmdline;
|
||||
|
||||
static ReadLineState *readline_state;
|
||||
|
||||
static int close_f(BlockDriverState *bs, int argc, char **argv)
|
||||
static int close_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
blk_unref(qemuio_blk);
|
||||
qemuio_bs = NULL;
|
||||
qemuio_blk = NULL;
|
||||
return 0;
|
||||
}
|
||||
@@ -69,7 +67,6 @@ static int openfile(char *name, int flags, QDict *opts)
|
||||
error_free(local_err);
|
||||
return 1;
|
||||
}
|
||||
qemuio_bs = blk_bs(qemuio_blk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -91,7 +88,7 @@ static void open_help(void)
|
||||
"\n");
|
||||
}
|
||||
|
||||
static int open_f(BlockDriverState *bs, int argc, char **argv);
|
||||
static int open_f(BlockBackend *blk, int argc, char **argv);
|
||||
|
||||
static const cmdinfo_t open_cmd = {
|
||||
.name = "open",
|
||||
@@ -115,7 +112,7 @@ static QemuOptsList empty_opts = {
|
||||
},
|
||||
};
|
||||
|
||||
static int open_f(BlockDriverState *bs, int argc, char **argv)
|
||||
static int open_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
int flags = 0;
|
||||
int readonly = 0;
|
||||
@@ -165,7 +162,7 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
static int quit_f(BlockDriverState *bs, int argc, char **argv)
|
||||
static int quit_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -302,7 +299,7 @@ static void command_loop(void)
|
||||
char *input;
|
||||
|
||||
for (i = 0; !done && i < ncmdline; i++) {
|
||||
done = qemuio_command(qemuio_bs, cmdline[i]);
|
||||
done = qemuio_command(qemuio_blk, cmdline[i]);
|
||||
}
|
||||
if (cmdline) {
|
||||
g_free(cmdline);
|
||||
@@ -327,7 +324,7 @@ static void command_loop(void)
|
||||
if (input == NULL) {
|
||||
break;
|
||||
}
|
||||
done = qemuio_command(qemuio_bs, input);
|
||||
done = qemuio_command(qemuio_blk, input);
|
||||
g_free(input);
|
||||
|
||||
prompted = 0;
|
||||
|
||||
Reference in New Issue
Block a user