mirror of https://github.com/xqemu/xqemu.git
qemu-io: Drop command functions' return values
For qemu-io, a function returns an integer with two possible values: 0 for "qemu-io may continue execution", or 1 for "qemu-io should exit". However, there is only a single command that returns 1, and that is "quit". So let's turn this case into a global variable instead so we can make better use of the return value in a later patch. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20180509194302.21585-2-mreitz@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
b41ad73a3b
commit
b444d0e9d1
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */
|
#define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */
|
||||||
|
|
||||||
typedef int (*cfunc_t)(BlockBackend *blk, int argc, char **argv);
|
typedef void (*cfunc_t)(BlockBackend *blk, int argc, char **argv);
|
||||||
typedef void (*helpfunc_t)(void);
|
typedef void (*helpfunc_t)(void);
|
||||||
|
|
||||||
typedef struct cmdinfo {
|
typedef struct cmdinfo {
|
||||||
|
@ -41,10 +41,10 @@ typedef struct cmdinfo {
|
||||||
|
|
||||||
extern bool qemuio_misalign;
|
extern bool qemuio_misalign;
|
||||||
|
|
||||||
bool qemuio_command(BlockBackend *blk, const char *cmd);
|
void qemuio_command(BlockBackend *blk, const char *cmd);
|
||||||
|
|
||||||
void qemuio_add_command(const cmdinfo_t *ci);
|
void qemuio_add_command(const cmdinfo_t *ci);
|
||||||
int qemuio_command_usage(const cmdinfo_t *ci);
|
void qemuio_command_usage(const cmdinfo_t *ci);
|
||||||
void qemuio_complete_command(const char *input,
|
void qemuio_complete_command(const char *input,
|
||||||
void (*fn)(const char *cmd, void *opaque),
|
void (*fn)(const char *cmd, void *opaque),
|
||||||
void *opaque);
|
void *opaque);
|
||||||
|
|
294
qemu-io-cmds.c
294
qemu-io-cmds.c
File diff suppressed because it is too large
Load Diff
36
qemu-io.c
36
qemu-io.c
|
@ -37,6 +37,7 @@
|
||||||
static char *progname;
|
static char *progname;
|
||||||
|
|
||||||
static BlockBackend *qemuio_blk;
|
static BlockBackend *qemuio_blk;
|
||||||
|
static bool quit_qemu_io;
|
||||||
|
|
||||||
/* qemu-io commands passed using -c */
|
/* qemu-io commands passed using -c */
|
||||||
static int ncmdline;
|
static int ncmdline;
|
||||||
|
@ -65,11 +66,10 @@ static int get_eof_char(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int close_f(BlockBackend *blk, int argc, char **argv)
|
static void close_f(BlockBackend *blk, int argc, char **argv)
|
||||||
{
|
{
|
||||||
blk_unref(qemuio_blk);
|
blk_unref(qemuio_blk);
|
||||||
qemuio_blk = NULL;
|
qemuio_blk = NULL;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const cmdinfo_t close_cmd = {
|
static const cmdinfo_t close_cmd = {
|
||||||
|
@ -136,7 +136,7 @@ static void open_help(void)
|
||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_f(BlockBackend *blk, int argc, char **argv);
|
static void open_f(BlockBackend *blk, int argc, char **argv);
|
||||||
|
|
||||||
static const cmdinfo_t open_cmd = {
|
static const cmdinfo_t open_cmd = {
|
||||||
.name = "open",
|
.name = "open",
|
||||||
|
@ -160,7 +160,7 @@ static QemuOptsList empty_opts = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int open_f(BlockBackend *blk, int argc, char **argv)
|
static void open_f(BlockBackend *blk, int argc, char **argv)
|
||||||
{
|
{
|
||||||
int flags = BDRV_O_UNMAP;
|
int flags = BDRV_O_UNMAP;
|
||||||
int readonly = 0;
|
int readonly = 0;
|
||||||
|
@ -192,25 +192,25 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
|
||||||
if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) {
|
if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) {
|
||||||
error_report("Invalid cache option: %s", optarg);
|
error_report("Invalid cache option: %s", optarg);
|
||||||
qemu_opts_reset(&empty_opts);
|
qemu_opts_reset(&empty_opts);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
if (bdrv_parse_discard_flags(optarg, &flags) < 0) {
|
if (bdrv_parse_discard_flags(optarg, &flags) < 0) {
|
||||||
error_report("Invalid discard option: %s", optarg);
|
error_report("Invalid discard option: %s", optarg);
|
||||||
qemu_opts_reset(&empty_opts);
|
qemu_opts_reset(&empty_opts);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
if (imageOpts) {
|
if (imageOpts) {
|
||||||
printf("--image-opts and 'open -o' are mutually exclusive\n");
|
printf("--image-opts and 'open -o' are mutually exclusive\n");
|
||||||
qemu_opts_reset(&empty_opts);
|
qemu_opts_reset(&empty_opts);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) {
|
if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) {
|
||||||
qemu_opts_reset(&empty_opts);
|
qemu_opts_reset(&empty_opts);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
|
@ -218,7 +218,8 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
qemu_opts_reset(&empty_opts);
|
qemu_opts_reset(&empty_opts);
|
||||||
return qemuio_command_usage(&open_cmd);
|
qemuio_command_usage(&open_cmd);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +230,7 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
|
||||||
if (imageOpts && (optind == argc - 1)) {
|
if (imageOpts && (optind == argc - 1)) {
|
||||||
if (!qemu_opts_parse_noisily(&empty_opts, argv[optind], false)) {
|
if (!qemu_opts_parse_noisily(&empty_opts, argv[optind], false)) {
|
||||||
qemu_opts_reset(&empty_opts);
|
qemu_opts_reset(&empty_opts);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
@ -246,12 +247,11 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
|
||||||
qobject_unref(opts);
|
qobject_unref(opts);
|
||||||
qemuio_command_usage(&open_cmd);
|
qemuio_command_usage(&open_cmd);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int quit_f(BlockBackend *blk, int argc, char **argv)
|
static void quit_f(BlockBackend *blk, int argc, char **argv)
|
||||||
{
|
{
|
||||||
return 1;
|
quit_qemu_io = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const cmdinfo_t quit_cmd = {
|
static const cmdinfo_t quit_cmd = {
|
||||||
|
@ -392,18 +392,18 @@ static void prep_fetchline(void *opaque)
|
||||||
|
|
||||||
static void command_loop(void)
|
static void command_loop(void)
|
||||||
{
|
{
|
||||||
int i, done = 0, fetchable = 0, prompted = 0;
|
int i, fetchable = 0, prompted = 0;
|
||||||
char *input;
|
char *input;
|
||||||
|
|
||||||
for (i = 0; !done && i < ncmdline; i++) {
|
for (i = 0; !quit_qemu_io && i < ncmdline; i++) {
|
||||||
done = qemuio_command(qemuio_blk, cmdline[i]);
|
qemuio_command(qemuio_blk, cmdline[i]);
|
||||||
}
|
}
|
||||||
if (cmdline) {
|
if (cmdline) {
|
||||||
g_free(cmdline);
|
g_free(cmdline);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!done) {
|
while (!quit_qemu_io) {
|
||||||
if (!prompted) {
|
if (!prompted) {
|
||||||
printf("%s", get_prompt());
|
printf("%s", get_prompt());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -421,7 +421,7 @@ static void command_loop(void)
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
done = qemuio_command(qemuio_blk, input);
|
qemuio_command(qemuio_blk, input);
|
||||||
g_free(input);
|
g_free(input);
|
||||||
|
|
||||||
prompted = 0;
|
prompted = 0;
|
||||||
|
|
Loading…
Reference in New Issue