mirror of
https://github.com/qemu/qemu.git
synced 2025-08-08 08:05:17 +00:00
qemu-io: Let command functions return error code
This is basically what everything else in the qemu code base does, so we can do it here, too. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20180509194302.21585-3-mreitz@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
b444d0e9d1
commit
b32d7a39af
@ -22,7 +22,12 @@
|
|||||||
|
|
||||||
#define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */
|
#define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */
|
||||||
|
|
||||||
typedef void (*cfunc_t)(BlockBackend *blk, int argc, char **argv);
|
/* Implement a qemu-io command.
|
||||||
|
* Operate on @blk using @argc/@argv as the command's arguments, and
|
||||||
|
* return 0 on success or negative errno on failure.
|
||||||
|
*/
|
||||||
|
typedef int (*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,7 +46,7 @@ typedef struct cmdinfo {
|
|||||||
|
|
||||||
extern bool qemuio_misalign;
|
extern bool qemuio_misalign;
|
||||||
|
|
||||||
void qemuio_command(BlockBackend *blk, const char *cmd);
|
int qemuio_command(BlockBackend *blk, const char *cmd);
|
||||||
|
|
||||||
void qemuio_add_command(const cmdinfo_t *ci);
|
void qemuio_add_command(const cmdinfo_t *ci);
|
||||||
void qemuio_command_usage(const cmdinfo_t *ci);
|
void qemuio_command_usage(const cmdinfo_t *ci);
|
||||||
|
344
qemu-io-cmds.c
344
qemu-io-cmds.c
File diff suppressed because it is too large
Load Diff
34
qemu-io.c
34
qemu-io.c
@ -66,10 +66,11 @@ static int get_eof_char(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_f(BlockBackend *blk, int argc, char **argv)
|
static int 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 +137,7 @@ static void open_help(void)
|
|||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void open_f(BlockBackend *blk, int argc, char **argv);
|
static int 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,12 +161,13 @@ static QemuOptsList empty_opts = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void open_f(BlockBackend *blk, int argc, char **argv)
|
static int open_f(BlockBackend *blk, int argc, char **argv)
|
||||||
{
|
{
|
||||||
int flags = BDRV_O_UNMAP;
|
int flags = BDRV_O_UNMAP;
|
||||||
int readonly = 0;
|
int readonly = 0;
|
||||||
bool writethrough = true;
|
bool writethrough = true;
|
||||||
int c;
|
int c;
|
||||||
|
int ret;
|
||||||
QemuOpts *qopts;
|
QemuOpts *qopts;
|
||||||
QDict *opts;
|
QDict *opts;
|
||||||
bool force_share = false;
|
bool force_share = false;
|
||||||
@ -192,25 +194,25 @@ static void 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;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
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;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
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;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
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;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
@ -219,7 +221,7 @@ static void open_f(BlockBackend *blk, int argc, char **argv)
|
|||||||
default:
|
default:
|
||||||
qemu_opts_reset(&empty_opts);
|
qemu_opts_reset(&empty_opts);
|
||||||
qemuio_command_usage(&open_cmd);
|
qemuio_command_usage(&open_cmd);
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +232,7 @@ static void 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;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
@ -240,18 +242,26 @@ static void open_f(BlockBackend *blk, int argc, char **argv)
|
|||||||
qemu_opts_reset(&empty_opts);
|
qemu_opts_reset(&empty_opts);
|
||||||
|
|
||||||
if (optind == argc - 1) {
|
if (optind == argc - 1) {
|
||||||
openfile(argv[optind], flags, writethrough, force_share, opts);
|
ret = openfile(argv[optind], flags, writethrough, force_share, opts);
|
||||||
} else if (optind == argc) {
|
} else if (optind == argc) {
|
||||||
openfile(NULL, flags, writethrough, force_share, opts);
|
ret = openfile(NULL, flags, writethrough, force_share, opts);
|
||||||
} else {
|
} else {
|
||||||
qobject_unref(opts);
|
qobject_unref(opts);
|
||||||
qemuio_command_usage(&open_cmd);
|
qemuio_command_usage(&open_cmd);
|
||||||
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void quit_f(BlockBackend *blk, int argc, char **argv)
|
static int quit_f(BlockBackend *blk, int argc, char **argv)
|
||||||
{
|
{
|
||||||
quit_qemu_io = true;
|
quit_qemu_io = true;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const cmdinfo_t quit_cmd = {
|
static const cmdinfo_t quit_cmd = {
|
||||||
|
Loading…
Reference in New Issue
Block a user