|
|
357786 |
From cc8c7cffb3786855de0032b376c7b22c461b695c Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Date: Mon, 25 Jun 2018 13:12:14 +0200
|
|
|
357786 |
Subject: [PATCH 41/54] qemu-io: Let command functions return error code
|
|
|
357786 |
|
|
|
357786 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Message-id: <20180618164312.24423-3-mreitz@redhat.com>
|
|
|
357786 |
Patchwork-id: 80781
|
|
|
357786 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 2/5] qemu-io: Let command functions return error code
|
|
|
357786 |
Bugzilla: 1519617
|
|
|
357786 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
This is basically what everything else in the qemu code base does, so we
|
|
|
357786 |
can do it here, too.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
357786 |
Message-id: 20180509194302.21585-3-mreitz@redhat.com
|
|
|
357786 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
(cherry picked from commit b32d7a39af488d280ce5f02a2ed94871d696f87a)
|
|
|
357786 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
include/qemu-io.h | 9 +-
|
|
|
357786 |
qemu-io-cmds.c | 346 ++++++++++++++++++++++++++++++++----------------------
|
|
|
357786 |
qemu-io.c | 34 ++++--
|
|
|
357786 |
3 files changed, 232 insertions(+), 157 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/include/qemu-io.h b/include/qemu-io.h
|
|
|
357786 |
index 06cdfbf..7433239 100644
|
|
|
357786 |
--- a/include/qemu-io.h
|
|
|
357786 |
+++ b/include/qemu-io.h
|
|
|
357786 |
@@ -22,7 +22,12 @@
|
|
|
357786 |
|
|
|
357786 |
#define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */
|
|
|
357786 |
|
|
|
357786 |
-typedef void (*cfunc_t)(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+/* Implement a qemu-io command.
|
|
|
357786 |
+ * Operate on @blk using @argc/@argv as the command's arguments, and
|
|
|
357786 |
+ * return 0 on success or negative errno on failure.
|
|
|
357786 |
+ */
|
|
|
357786 |
+typedef int (*cfunc_t)(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+
|
|
|
357786 |
typedef void (*helpfunc_t)(void);
|
|
|
357786 |
|
|
|
357786 |
typedef struct cmdinfo {
|
|
|
357786 |
@@ -41,7 +46,7 @@ typedef struct cmdinfo {
|
|
|
357786 |
|
|
|
357786 |
extern bool qemuio_misalign;
|
|
|
357786 |
|
|
|
357786 |
-void qemuio_command(BlockBackend *blk, const char *cmd);
|
|
|
357786 |
+int qemuio_command(BlockBackend *blk, const char *cmd);
|
|
|
357786 |
|
|
|
357786 |
void qemuio_add_command(const cmdinfo_t *ci);
|
|
|
357786 |
void qemuio_command_usage(const cmdinfo_t *ci);
|
|
|
357786 |
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
|
|
|
357786 |
index c2fbaae..5bf5f28 100644
|
|
|
357786 |
--- a/qemu-io-cmds.c
|
|
|
357786 |
+++ b/qemu-io-cmds.c
|
|
|
357786 |
@@ -65,13 +65,13 @@ static int init_check_command(BlockBackend *blk, const cmdinfo_t *ct)
|
|
|
357786 |
return 1;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void command(BlockBackend *blk, const cmdinfo_t *ct, int argc,
|
|
|
357786 |
- char **argv)
|
|
|
357786 |
+static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc,
|
|
|
357786 |
+ char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
char *cmd = argv[0];
|
|
|
357786 |
|
|
|
357786 |
if (!init_check_command(blk, ct)) {
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (argc - 1 < ct->argmin || (ct->argmax != -1 && argc - 1 > ct->argmax)) {
|
|
|
357786 |
@@ -88,7 +88,7 @@ static void command(BlockBackend *blk, const cmdinfo_t *ct, int argc,
|
|
|
357786 |
"bad argument count %d to %s, expected between %d and %d arguments\n",
|
|
|
357786 |
argc-1, cmd, ct->argmin, ct->argmax);
|
|
|
357786 |
}
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
/* Request additional permissions if necessary for this command. The caller
|
|
|
357786 |
@@ -108,13 +108,13 @@ static void command(BlockBackend *blk, const cmdinfo_t *ct, int argc,
|
|
|
357786 |
ret = blk_set_perm(blk, new_perm, orig_shared_perm, &local_err);
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
error_report_err(local_err);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
optind = 0;
|
|
|
357786 |
- ct->cfunc(blk, argc, argv);
|
|
|
357786 |
+ return ct->cfunc(blk, argc, argv);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t *find_command(const char *cmd)
|
|
|
357786 |
@@ -633,7 +633,7 @@ static void read_help(void)
|
|
|
357786 |
"\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void read_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int read_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t read_cmd = {
|
|
|
357786 |
.name = "read",
|
|
|
357786 |
@@ -646,12 +646,12 @@ static const cmdinfo_t read_cmd = {
|
|
|
357786 |
.help = read_help,
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
struct timeval t1, t2;
|
|
|
357786 |
bool Cflag = false, qflag = false, vflag = false;
|
|
|
357786 |
bool Pflag = false, sflag = false, lflag = false, bflag = false;
|
|
|
357786 |
- int c, cnt;
|
|
|
357786 |
+ int c, cnt, ret;
|
|
|
357786 |
char *buf;
|
|
|
357786 |
int64_t offset;
|
|
|
357786 |
int64_t count;
|
|
|
357786 |
@@ -673,7 +673,7 @@ static void read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
pattern_count = cvtnum(optarg);
|
|
|
357786 |
if (pattern_count < 0) {
|
|
|
357786 |
print_cvtnum_err(pattern_count, optarg);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return pattern_count;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'p':
|
|
|
357786 |
@@ -683,7 +683,7 @@ static void read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
Pflag = true;
|
|
|
357786 |
pattern = parse_pattern(optarg);
|
|
|
357786 |
if (pattern < 0) {
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'q':
|
|
|
357786 |
@@ -694,7 +694,7 @@ static void read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
pattern_offset = cvtnum(optarg);
|
|
|
357786 |
if (pattern_offset < 0) {
|
|
|
357786 |
print_cvtnum_err(pattern_offset, optarg);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return pattern_offset;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'v':
|
|
|
357786 |
@@ -702,35 +702,35 @@ static void read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
break;
|
|
|
357786 |
default:
|
|
|
357786 |
qemuio_command_usage(&read_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (optind != argc - 2) {
|
|
|
357786 |
qemuio_command_usage(&read_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
offset = cvtnum(argv[optind]);
|
|
|
357786 |
if (offset < 0) {
|
|
|
357786 |
print_cvtnum_err(offset, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return offset;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
optind++;
|
|
|
357786 |
count = cvtnum(argv[optind]);
|
|
|
357786 |
if (count < 0) {
|
|
|
357786 |
print_cvtnum_err(count, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return count;
|
|
|
357786 |
} else if (count > BDRV_REQUEST_MAX_BYTES) {
|
|
|
357786 |
printf("length cannot exceed %" PRIu64 ", given %s\n",
|
|
|
357786 |
(uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (!Pflag && (lflag || sflag)) {
|
|
|
357786 |
qemuio_command_usage(&read_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (!lflag) {
|
|
|
357786 |
@@ -739,19 +739,19 @@ static void read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
|
|
|
357786 |
if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) {
|
|
|
357786 |
printf("pattern verification range exceeds end of read data\n");
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (bflag) {
|
|
|
357786 |
if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
|
|
|
357786 |
printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
|
|
|
357786 |
offset);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
|
|
|
357786 |
printf("%"PRId64" is not a sector-aligned value for 'count'\n",
|
|
|
357786 |
count);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
@@ -759,16 +759,19 @@ static void read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
|
|
|
357786 |
gettimeofday(&t1, NULL);
|
|
|
357786 |
if (bflag) {
|
|
|
357786 |
- cnt = do_load_vmstate(blk, buf, offset, count, &total);
|
|
|
357786 |
+ ret = do_load_vmstate(blk, buf, offset, count, &total);
|
|
|
357786 |
} else {
|
|
|
357786 |
- cnt = do_pread(blk, buf, offset, count, &total);
|
|
|
357786 |
+ ret = do_pread(blk, buf, offset, count, &total);
|
|
|
357786 |
}
|
|
|
357786 |
gettimeofday(&t2, NULL);
|
|
|
357786 |
|
|
|
357786 |
- if (cnt < 0) {
|
|
|
357786 |
- printf("read failed: %s\n", strerror(-cnt));
|
|
|
357786 |
+ if (ret < 0) {
|
|
|
357786 |
+ printf("read failed: %s\n", strerror(-ret));
|
|
|
357786 |
goto out;
|
|
|
357786 |
}
|
|
|
357786 |
+ cnt = ret;
|
|
|
357786 |
+
|
|
|
357786 |
+ ret = 0;
|
|
|
357786 |
|
|
|
357786 |
if (Pflag) {
|
|
|
357786 |
void *cmp_buf = g_malloc(pattern_count);
|
|
|
357786 |
@@ -777,6 +780,7 @@ static void read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
printf("Pattern verification failed at offset %"
|
|
|
357786 |
PRId64 ", %"PRId64" bytes\n",
|
|
|
357786 |
offset + pattern_offset, pattern_count);
|
|
|
357786 |
+ ret = -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
g_free(cmp_buf);
|
|
|
357786 |
}
|
|
|
357786 |
@@ -795,6 +799,7 @@ static void read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
|
|
|
357786 |
out:
|
|
|
357786 |
qemu_io_free(buf);
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void readv_help(void)
|
|
|
357786 |
@@ -816,7 +821,7 @@ static void readv_help(void)
|
|
|
357786 |
"\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void readv_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int readv_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t readv_cmd = {
|
|
|
357786 |
.name = "readv",
|
|
|
357786 |
@@ -828,11 +833,11 @@ static const cmdinfo_t readv_cmd = {
|
|
|
357786 |
.help = readv_help,
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void readv_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int readv_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
struct timeval t1, t2;
|
|
|
357786 |
bool Cflag = false, qflag = false, vflag = false;
|
|
|
357786 |
- int c, cnt;
|
|
|
357786 |
+ int c, cnt, ret;
|
|
|
357786 |
char *buf;
|
|
|
357786 |
int64_t offset;
|
|
|
357786 |
/* Some compilers get confused and warn if this is not initialized. */
|
|
|
357786 |
@@ -851,7 +856,7 @@ static void readv_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
Pflag = true;
|
|
|
357786 |
pattern = parse_pattern(optarg);
|
|
|
357786 |
if (pattern < 0) {
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'q':
|
|
|
357786 |
@@ -862,37 +867,40 @@ static void readv_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
break;
|
|
|
357786 |
default:
|
|
|
357786 |
qemuio_command_usage(&readv_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (optind > argc - 2) {
|
|
|
357786 |
qemuio_command_usage(&readv_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
|
|
|
357786 |
offset = cvtnum(argv[optind]);
|
|
|
357786 |
if (offset < 0) {
|
|
|
357786 |
print_cvtnum_err(offset, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return offset;
|
|
|
357786 |
}
|
|
|
357786 |
optind++;
|
|
|
357786 |
|
|
|
357786 |
nr_iov = argc - optind;
|
|
|
357786 |
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab);
|
|
|
357786 |
if (buf == NULL) {
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
gettimeofday(&t1, NULL);
|
|
|
357786 |
- cnt = do_aio_readv(blk, &qiov, offset, &total);
|
|
|
357786 |
+ ret = do_aio_readv(blk, &qiov, offset, &total);
|
|
|
357786 |
gettimeofday(&t2, NULL);
|
|
|
357786 |
|
|
|
357786 |
- if (cnt < 0) {
|
|
|
357786 |
- printf("readv failed: %s\n", strerror(-cnt));
|
|
|
357786 |
+ if (ret < 0) {
|
|
|
357786 |
+ printf("readv failed: %s\n", strerror(-ret));
|
|
|
357786 |
goto out;
|
|
|
357786 |
}
|
|
|
357786 |
+ cnt = ret;
|
|
|
357786 |
+
|
|
|
357786 |
+ ret = 0;
|
|
|
357786 |
|
|
|
357786 |
if (Pflag) {
|
|
|
357786 |
void *cmp_buf = g_malloc(qiov.size);
|
|
|
357786 |
@@ -900,6 +908,7 @@ static void readv_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
if (memcmp(buf, cmp_buf, qiov.size)) {
|
|
|
357786 |
printf("Pattern verification failed at offset %"
|
|
|
357786 |
PRId64 ", %zd bytes\n", offset, qiov.size);
|
|
|
357786 |
+ ret = -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
g_free(cmp_buf);
|
|
|
357786 |
}
|
|
|
357786 |
@@ -919,6 +928,7 @@ static void readv_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
out:
|
|
|
357786 |
qemu_iovec_destroy(&qiov);
|
|
|
357786 |
qemu_io_free(buf);
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void write_help(void)
|
|
|
357786 |
@@ -944,7 +954,7 @@ static void write_help(void)
|
|
|
357786 |
"\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void write_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int write_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t write_cmd = {
|
|
|
357786 |
.name = "write",
|
|
|
357786 |
@@ -958,13 +968,13 @@ static const cmdinfo_t write_cmd = {
|
|
|
357786 |
.help = write_help,
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
struct timeval t1, t2;
|
|
|
357786 |
bool Cflag = false, qflag = false, bflag = false;
|
|
|
357786 |
bool Pflag = false, zflag = false, cflag = false;
|
|
|
357786 |
int flags = 0;
|
|
|
357786 |
- int c, cnt;
|
|
|
357786 |
+ int c, cnt, ret;
|
|
|
357786 |
char *buf = NULL;
|
|
|
357786 |
int64_t offset;
|
|
|
357786 |
int64_t count;
|
|
|
357786 |
@@ -993,7 +1003,7 @@ static void write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
Pflag = true;
|
|
|
357786 |
pattern = parse_pattern(optarg);
|
|
|
357786 |
if (pattern < 0) {
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'q':
|
|
|
357786 |
@@ -1007,63 +1017,63 @@ static void write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
break;
|
|
|
357786 |
default:
|
|
|
357786 |
qemuio_command_usage(&write_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (optind != argc - 2) {
|
|
|
357786 |
qemuio_command_usage(&write_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (bflag && zflag) {
|
|
|
357786 |
printf("-b and -z cannot be specified at the same time\n");
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if ((flags & BDRV_REQ_FUA) && (bflag || cflag)) {
|
|
|
357786 |
printf("-f and -b or -c cannot be specified at the same time\n");
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) {
|
|
|
357786 |
printf("-u requires -z to be specified\n");
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (zflag && Pflag) {
|
|
|
357786 |
printf("-z and -P cannot be specified at the same time\n");
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
offset = cvtnum(argv[optind]);
|
|
|
357786 |
if (offset < 0) {
|
|
|
357786 |
print_cvtnum_err(offset, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return offset;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
optind++;
|
|
|
357786 |
count = cvtnum(argv[optind]);
|
|
|
357786 |
if (count < 0) {
|
|
|
357786 |
print_cvtnum_err(count, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return count;
|
|
|
357786 |
} else if (count > BDRV_REQUEST_MAX_BYTES) {
|
|
|
357786 |
printf("length cannot exceed %" PRIu64 ", given %s\n",
|
|
|
357786 |
(uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (bflag || cflag) {
|
|
|
357786 |
if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
|
|
|
357786 |
printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
|
|
|
357786 |
offset);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
|
|
|
357786 |
printf("%"PRId64" is not a sector-aligned value for 'count'\n",
|
|
|
357786 |
count);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
@@ -1073,20 +1083,23 @@ static void write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
|
|
|
357786 |
gettimeofday(&t1, NULL);
|
|
|
357786 |
if (bflag) {
|
|
|
357786 |
- cnt = do_save_vmstate(blk, buf, offset, count, &total);
|
|
|
357786 |
+ ret = do_save_vmstate(blk, buf, offset, count, &total);
|
|
|
357786 |
} else if (zflag) {
|
|
|
357786 |
- cnt = do_co_pwrite_zeroes(blk, offset, count, flags, &total);
|
|
|
357786 |
+ ret = do_co_pwrite_zeroes(blk, offset, count, flags, &total);
|
|
|
357786 |
} else if (cflag) {
|
|
|
357786 |
- cnt = do_write_compressed(blk, buf, offset, count, &total);
|
|
|
357786 |
+ ret = do_write_compressed(blk, buf, offset, count, &total);
|
|
|
357786 |
} else {
|
|
|
357786 |
- cnt = do_pwrite(blk, buf, offset, count, flags, &total);
|
|
|
357786 |
+ ret = do_pwrite(blk, buf, offset, count, flags, &total);
|
|
|
357786 |
}
|
|
|
357786 |
gettimeofday(&t2, NULL);
|
|
|
357786 |
|
|
|
357786 |
- if (cnt < 0) {
|
|
|
357786 |
- printf("write failed: %s\n", strerror(-cnt));
|
|
|
357786 |
+ if (ret < 0) {
|
|
|
357786 |
+ printf("write failed: %s\n", strerror(-ret));
|
|
|
357786 |
goto out;
|
|
|
357786 |
}
|
|
|
357786 |
+ cnt = ret;
|
|
|
357786 |
+
|
|
|
357786 |
+ ret = 0;
|
|
|
357786 |
|
|
|
357786 |
if (qflag) {
|
|
|
357786 |
goto out;
|
|
|
357786 |
@@ -1100,6 +1113,7 @@ out:
|
|
|
357786 |
if (!zflag) {
|
|
|
357786 |
qemu_io_free(buf);
|
|
|
357786 |
}
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void
|
|
|
357786 |
@@ -1121,7 +1135,7 @@ writev_help(void)
|
|
|
357786 |
"\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void writev_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int writev_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t writev_cmd = {
|
|
|
357786 |
.name = "writev",
|
|
|
357786 |
@@ -1134,12 +1148,12 @@ static const cmdinfo_t writev_cmd = {
|
|
|
357786 |
.help = writev_help,
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void writev_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int writev_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
struct timeval t1, t2;
|
|
|
357786 |
bool Cflag = false, qflag = false;
|
|
|
357786 |
int flags = 0;
|
|
|
357786 |
- int c, cnt;
|
|
|
357786 |
+ int c, cnt, ret;
|
|
|
357786 |
char *buf;
|
|
|
357786 |
int64_t offset;
|
|
|
357786 |
/* Some compilers get confused and warn if this is not initialized. */
|
|
|
357786 |
@@ -1162,41 +1176,44 @@ static void writev_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
case 'P':
|
|
|
357786 |
pattern = parse_pattern(optarg);
|
|
|
357786 |
if (pattern < 0) {
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
default:
|
|
|
357786 |
qemuio_command_usage(&writev_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (optind > argc - 2) {
|
|
|
357786 |
qemuio_command_usage(&writev_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
offset = cvtnum(argv[optind]);
|
|
|
357786 |
if (offset < 0) {
|
|
|
357786 |
print_cvtnum_err(offset, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return offset;
|
|
|
357786 |
}
|
|
|
357786 |
optind++;
|
|
|
357786 |
|
|
|
357786 |
nr_iov = argc - optind;
|
|
|
357786 |
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern);
|
|
|
357786 |
if (buf == NULL) {
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
gettimeofday(&t1, NULL);
|
|
|
357786 |
- cnt = do_aio_writev(blk, &qiov, offset, flags, &total);
|
|
|
357786 |
+ ret = do_aio_writev(blk, &qiov, offset, flags, &total);
|
|
|
357786 |
gettimeofday(&t2, NULL);
|
|
|
357786 |
|
|
|
357786 |
- if (cnt < 0) {
|
|
|
357786 |
- printf("writev failed: %s\n", strerror(-cnt));
|
|
|
357786 |
+ if (ret < 0) {
|
|
|
357786 |
+ printf("writev failed: %s\n", strerror(-ret));
|
|
|
357786 |
goto out;
|
|
|
357786 |
}
|
|
|
357786 |
+ cnt = ret;
|
|
|
357786 |
+
|
|
|
357786 |
+ ret = 0;
|
|
|
357786 |
|
|
|
357786 |
if (qflag) {
|
|
|
357786 |
goto out;
|
|
|
357786 |
@@ -1208,6 +1225,7 @@ static void writev_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
out:
|
|
|
357786 |
qemu_iovec_destroy(&qiov);
|
|
|
357786 |
qemu_io_free(buf);
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
struct aio_ctx {
|
|
|
357786 |
@@ -1314,6 +1332,9 @@ static void aio_read_help(void)
|
|
|
357786 |
" standard output stream (with -v option) for subsequent inspection.\n"
|
|
|
357786 |
" The read is performed asynchronously and the aio_flush command must be\n"
|
|
|
357786 |
" used to ensure all outstanding aio requests have been completed.\n"
|
|
|
357786 |
+" Note that due to its asynchronous nature, this command will be\n"
|
|
|
357786 |
+" considered successful once the request is submitted, independently\n"
|
|
|
357786 |
+" of potential I/O errors or pattern mismatches.\n"
|
|
|
357786 |
" -C, -- report statistics in a machine parsable format\n"
|
|
|
357786 |
" -P, -- use a pattern to verify read data\n"
|
|
|
357786 |
" -i, -- treat request as invalid, for exercising stats\n"
|
|
|
357786 |
@@ -1322,7 +1343,7 @@ static void aio_read_help(void)
|
|
|
357786 |
"\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void aio_read_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int aio_read_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t aio_read_cmd = {
|
|
|
357786 |
.name = "aio_read",
|
|
|
357786 |
@@ -1334,7 +1355,7 @@ static const cmdinfo_t aio_read_cmd = {
|
|
|
357786 |
.help = aio_read_help,
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void aio_read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int aio_read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
int nr_iov, c;
|
|
|
357786 |
struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
|
|
|
357786 |
@@ -1350,14 +1371,14 @@ static void aio_read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
ctx->pattern = parse_pattern(optarg);
|
|
|
357786 |
if (ctx->pattern < 0) {
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'i':
|
|
|
357786 |
printf("injecting invalid read request\n");
|
|
|
357786 |
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ);
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
case 'q':
|
|
|
357786 |
ctx->qflag = true;
|
|
|
357786 |
break;
|
|
|
357786 |
@@ -1367,21 +1388,22 @@ static void aio_read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
default:
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
qemuio_command_usage(&aio_read_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (optind > argc - 2) {
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
qemuio_command_usage(&aio_read_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
ctx->offset = cvtnum(argv[optind]);
|
|
|
357786 |
if (ctx->offset < 0) {
|
|
|
357786 |
- print_cvtnum_err(ctx->offset, argv[optind]);
|
|
|
357786 |
+ int ret = ctx->offset;
|
|
|
357786 |
+ print_cvtnum_err(ret, argv[optind]);
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
optind++;
|
|
|
357786 |
|
|
|
357786 |
@@ -1390,13 +1412,14 @@ static void aio_read_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
if (ctx->buf == NULL) {
|
|
|
357786 |
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ);
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
gettimeofday(&ctx->t1, NULL);
|
|
|
357786 |
block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
|
|
|
357786 |
BLOCK_ACCT_READ);
|
|
|
357786 |
blk_aio_preadv(blk, ctx->offset, &ctx->qiov, 0, aio_read_done, ctx);
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void aio_write_help(void)
|
|
|
357786 |
@@ -1413,6 +1436,9 @@ static void aio_write_help(void)
|
|
|
357786 |
" filled with a set pattern (0xcdcdcdcd).\n"
|
|
|
357786 |
" The write is performed asynchronously and the aio_flush command must be\n"
|
|
|
357786 |
" used to ensure all outstanding aio requests have been completed.\n"
|
|
|
357786 |
+" Note that due to its asynchronous nature, this command will be\n"
|
|
|
357786 |
+" considered successful once the request is submitted, independently\n"
|
|
|
357786 |
+" of potential I/O errors or pattern mismatches.\n"
|
|
|
357786 |
" -P, -- use different pattern to fill file\n"
|
|
|
357786 |
" -C, -- report statistics in a machine parsable format\n"
|
|
|
357786 |
" -f, -- use Force Unit Access semantics\n"
|
|
|
357786 |
@@ -1423,7 +1449,7 @@ static void aio_write_help(void)
|
|
|
357786 |
"\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void aio_write_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int aio_write_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t aio_write_cmd = {
|
|
|
357786 |
.name = "aio_write",
|
|
|
357786 |
@@ -1436,7 +1462,7 @@ static const cmdinfo_t aio_write_cmd = {
|
|
|
357786 |
.help = aio_write_help,
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void aio_write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
int nr_iov, c;
|
|
|
357786 |
int pattern = 0xcd;
|
|
|
357786 |
@@ -1462,53 +1488,54 @@ static void aio_write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
pattern = parse_pattern(optarg);
|
|
|
357786 |
if (pattern < 0) {
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'i':
|
|
|
357786 |
printf("injecting invalid write request\n");
|
|
|
357786 |
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE);
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
case 'z':
|
|
|
357786 |
ctx->zflag = true;
|
|
|
357786 |
break;
|
|
|
357786 |
default:
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
qemuio_command_usage(&aio_write_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (optind > argc - 2) {
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
qemuio_command_usage(&aio_write_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (ctx->zflag && optind != argc - 2) {
|
|
|
357786 |
printf("-z supports only a single length parameter\n");
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) {
|
|
|
357786 |
printf("-u requires -z to be specified\n");
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (ctx->zflag && ctx->Pflag) {
|
|
|
357786 |
printf("-z and -P cannot be specified at the same time\n");
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
ctx->offset = cvtnum(argv[optind]);
|
|
|
357786 |
if (ctx->offset < 0) {
|
|
|
357786 |
- print_cvtnum_err(ctx->offset, argv[optind]);
|
|
|
357786 |
+ int ret = ctx->offset;
|
|
|
357786 |
+ print_cvtnum_err(ret, argv[optind]);
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
optind++;
|
|
|
357786 |
|
|
|
357786 |
@@ -1517,7 +1544,7 @@ static void aio_write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
if (count < 0) {
|
|
|
357786 |
print_cvtnum_err(count, argv[optind]);
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return count;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
ctx->qiov.size = count;
|
|
|
357786 |
@@ -1530,7 +1557,7 @@ static void aio_write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
if (ctx->buf == NULL) {
|
|
|
357786 |
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE);
|
|
|
357786 |
g_free(ctx);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
gettimeofday(&ctx->t1, NULL);
|
|
|
357786 |
@@ -1540,14 +1567,17 @@ static void aio_write_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, flags, aio_write_done,
|
|
|
357786 |
ctx);
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void aio_flush_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int aio_flush_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
BlockAcctCookie cookie;
|
|
|
357786 |
block_acct_start(blk_get_stats(blk), &cookie, 0, BLOCK_ACCT_FLUSH);
|
|
|
357786 |
blk_drain_all();
|
|
|
357786 |
block_acct_done(blk_get_stats(blk), &cookie);
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t aio_flush_cmd = {
|
|
|
357786 |
@@ -1556,9 +1586,9 @@ static const cmdinfo_t aio_flush_cmd = {
|
|
|
357786 |
.oneline = "completes all outstanding aio requests"
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void flush_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int flush_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
- blk_flush(blk);
|
|
|
357786 |
+ return blk_flush(blk);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t flush_cmd = {
|
|
|
357786 |
@@ -1568,7 +1598,7 @@ static const cmdinfo_t flush_cmd = {
|
|
|
357786 |
.oneline = "flush all in-core file state to disk",
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void truncate_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int truncate_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
Error *local_err = NULL;
|
|
|
357786 |
int64_t offset;
|
|
|
357786 |
@@ -1577,14 +1607,16 @@ static void truncate_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
offset = cvtnum(argv[1]);
|
|
|
357786 |
if (offset < 0) {
|
|
|
357786 |
print_cvtnum_err(offset, argv[1]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return offset;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
ret = blk_truncate(blk, offset, PREALLOC_MODE_OFF, &local_err);
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
error_report_err(local_err);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t truncate_cmd = {
|
|
|
357786 |
@@ -1598,7 +1630,7 @@ static const cmdinfo_t truncate_cmd = {
|
|
|
357786 |
.oneline = "truncates the current file at the given offset",
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void length_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int length_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
int64_t size;
|
|
|
357786 |
char s1[64];
|
|
|
357786 |
@@ -1606,11 +1638,12 @@ static void length_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
size = blk_getlength(blk);
|
|
|
357786 |
if (size < 0) {
|
|
|
357786 |
printf("getlength: %s\n", strerror(-size));
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return size;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
cvtstr(size, s1, sizeof(s1));
|
|
|
357786 |
printf("%s\n", s1);
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
|
|
|
357786 |
@@ -1622,7 +1655,7 @@ static const cmdinfo_t length_cmd = {
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
|
|
|
357786 |
-static void info_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int info_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
BlockDriverState *bs = blk_bs(blk);
|
|
|
357786 |
BlockDriverInfo bdi;
|
|
|
357786 |
@@ -1639,7 +1672,7 @@ static void info_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
|
|
|
357786 |
ret = bdrv_get_info(bs, &bdi;;
|
|
|
357786 |
if (ret) {
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
cvtstr(bdi.cluster_size, s1, sizeof(s1));
|
|
|
357786 |
@@ -1654,6 +1687,8 @@ static void info_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
bdrv_image_info_specific_dump(fprintf, stdout, spec_info);
|
|
|
357786 |
qapi_free_ImageInfoSpecific(spec_info);
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
|
|
|
357786 |
@@ -1680,7 +1715,7 @@ static void discard_help(void)
|
|
|
357786 |
"\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void discard_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int discard_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t discard_cmd = {
|
|
|
357786 |
.name = "discard",
|
|
|
357786 |
@@ -1694,7 +1729,7 @@ static const cmdinfo_t discard_cmd = {
|
|
|
357786 |
.help = discard_help,
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void discard_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int discard_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
struct timeval t1, t2;
|
|
|
357786 |
bool Cflag = false, qflag = false;
|
|
|
357786 |
@@ -1711,31 +1746,31 @@ static void discard_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
break;
|
|
|
357786 |
default:
|
|
|
357786 |
qemuio_command_usage(&discard_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (optind != argc - 2) {
|
|
|
357786 |
qemuio_command_usage(&discard_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
offset = cvtnum(argv[optind]);
|
|
|
357786 |
if (offset < 0) {
|
|
|
357786 |
print_cvtnum_err(offset, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return offset;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
optind++;
|
|
|
357786 |
bytes = cvtnum(argv[optind]);
|
|
|
357786 |
if (bytes < 0) {
|
|
|
357786 |
print_cvtnum_err(bytes, argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return bytes;
|
|
|
357786 |
} else if (bytes >> BDRV_SECTOR_BITS > BDRV_REQUEST_MAX_SECTORS) {
|
|
|
357786 |
printf("length cannot exceed %"PRIu64", given %s\n",
|
|
|
357786 |
(uint64_t)BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS,
|
|
|
357786 |
argv[optind]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
gettimeofday(&t1, NULL);
|
|
|
357786 |
@@ -1744,7 +1779,7 @@ static void discard_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
printf("discard failed: %s\n", strerror(-ret));
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
/* Finally, report back -- -C gives a parsable format */
|
|
|
357786 |
@@ -1752,9 +1787,11 @@ static void discard_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
t2 = tsub(t2, t1);
|
|
|
357786 |
print_report("discard", &t2, offset, bytes, bytes, 1, Cflag);
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void alloc_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int alloc_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
BlockDriverState *bs = blk_bs(blk);
|
|
|
357786 |
int64_t offset, start, remaining, count;
|
|
|
357786 |
@@ -1765,14 +1802,14 @@ static void alloc_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
start = offset = cvtnum(argv[1]);
|
|
|
357786 |
if (offset < 0) {
|
|
|
357786 |
print_cvtnum_err(offset, argv[1]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return offset;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (argc == 3) {
|
|
|
357786 |
count = cvtnum(argv[2]);
|
|
|
357786 |
if (count < 0) {
|
|
|
357786 |
print_cvtnum_err(count, argv[2]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return count;
|
|
|
357786 |
}
|
|
|
357786 |
} else {
|
|
|
357786 |
count = BDRV_SECTOR_SIZE;
|
|
|
357786 |
@@ -1784,7 +1821,7 @@ static void alloc_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
ret = bdrv_is_allocated(bs, offset, remaining, &num);
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
printf("is_allocated failed: %s\n", strerror(-ret));
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
offset += num;
|
|
|
357786 |
remaining -= num;
|
|
|
357786 |
@@ -1801,6 +1838,7 @@ static void alloc_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
|
|
|
357786 |
printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n",
|
|
|
357786 |
sum_alloc, count, s1);
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t alloc_cmd = {
|
|
|
357786 |
@@ -1846,7 +1884,7 @@ static int map_is_allocated(BlockDriverState *bs, int64_t offset,
|
|
|
357786 |
return firstret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void map_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int map_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
int64_t offset, bytes;
|
|
|
357786 |
char s1[64], s2[64];
|
|
|
357786 |
@@ -1858,17 +1896,17 @@ static void map_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
bytes = blk_getlength(blk);
|
|
|
357786 |
if (bytes < 0) {
|
|
|
357786 |
error_report("Failed to query image length: %s", strerror(-bytes));
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return bytes;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
while (bytes) {
|
|
|
357786 |
ret = map_is_allocated(blk_bs(blk), offset, bytes, &num);
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
error_report("Failed to get allocation status: %s", strerror(-ret));
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
} else if (!num) {
|
|
|
357786 |
error_report("Unexpected end of image");
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EIO;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
retstr = ret ? " allocated" : "not allocated";
|
|
|
357786 |
@@ -1880,6 +1918,8 @@ static void map_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
offset += num;
|
|
|
357786 |
bytes -= num;
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t map_cmd = {
|
|
|
357786 |
@@ -1907,7 +1947,7 @@ static void reopen_help(void)
|
|
|
357786 |
"\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void reopen_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int reopen_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static QemuOptsList reopen_opts = {
|
|
|
357786 |
.name = "reopen",
|
|
|
357786 |
@@ -1929,7 +1969,7 @@ static const cmdinfo_t reopen_cmd = {
|
|
|
357786 |
.help = reopen_help,
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void reopen_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int reopen_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
BlockDriverState *bs = blk_bs(blk);
|
|
|
357786 |
QemuOpts *qopts;
|
|
|
357786 |
@@ -1947,19 +1987,19 @@ static void reopen_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
case 'c':
|
|
|
357786 |
if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) {
|
|
|
357786 |
error_report("Invalid cache option: %s", optarg);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'o':
|
|
|
357786 |
if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) {
|
|
|
357786 |
qemu_opts_reset(&reopen_opts);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'r':
|
|
|
357786 |
if (has_rw_option) {
|
|
|
357786 |
error_report("Only one -r/-w option may be given");
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
flags &= ~BDRV_O_RDWR;
|
|
|
357786 |
has_rw_option = true;
|
|
|
357786 |
@@ -1967,7 +2007,7 @@ static void reopen_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
case 'w':
|
|
|
357786 |
if (has_rw_option) {
|
|
|
357786 |
error_report("Only one -r/-w option may be given");
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
flags |= BDRV_O_RDWR;
|
|
|
357786 |
has_rw_option = true;
|
|
|
357786 |
@@ -1975,14 +2015,14 @@ static void reopen_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
default:
|
|
|
357786 |
qemu_opts_reset(&reopen_opts);
|
|
|
357786 |
qemuio_command_usage(&reopen_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (optind != argc) {
|
|
|
357786 |
qemu_opts_reset(&reopen_opts);
|
|
|
357786 |
qemuio_command_usage(&reopen_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (writethrough != blk_enable_write_cache(blk) &&
|
|
|
357786 |
@@ -1990,7 +2030,7 @@ static void reopen_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
error_report("Cannot change cache.writeback: Device attached");
|
|
|
357786 |
qemu_opts_reset(&reopen_opts);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EBUSY;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (!(flags & BDRV_O_RDWR)) {
|
|
|
357786 |
@@ -2016,29 +2056,37 @@ static void reopen_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
|
|
|
357786 |
if (local_err) {
|
|
|
357786 |
error_report_err(local_err);
|
|
|
357786 |
- } else {
|
|
|
357786 |
- blk_set_enable_write_cache(blk, !writethrough);
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ blk_set_enable_write_cache(blk, !writethrough);
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void break_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int break_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
int ret;
|
|
|
357786 |
|
|
|
357786 |
ret = bdrv_debug_breakpoint(blk_bs(blk), argv[1], argv[2]);
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
printf("Could not set breakpoint: %s\n", strerror(-ret));
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void remove_break_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int remove_break_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
int ret;
|
|
|
357786 |
|
|
|
357786 |
ret = bdrv_debug_remove_breakpoint(blk_bs(blk), argv[1]);
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
printf("Could not remove breakpoint %s: %s\n", argv[1], strerror(-ret));
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t break_cmd = {
|
|
|
357786 |
@@ -2060,14 +2108,17 @@ static const cmdinfo_t remove_break_cmd = {
|
|
|
357786 |
.oneline = "remove a breakpoint by tag",
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void resume_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int resume_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
int ret;
|
|
|
357786 |
|
|
|
357786 |
ret = bdrv_debug_resume(blk_bs(blk), argv[1]);
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
printf("Could not resume request: %s\n", strerror(-ret));
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t resume_cmd = {
|
|
|
357786 |
@@ -2079,11 +2130,12 @@ static const cmdinfo_t resume_cmd = {
|
|
|
357786 |
.oneline = "resumes the request tagged as tag",
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void wait_break_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int wait_break_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
while (!bdrv_debug_is_suspended(blk_bs(blk), argv[1])) {
|
|
|
357786 |
aio_poll(blk_get_aio_context(blk), true);
|
|
|
357786 |
}
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t wait_break_cmd = {
|
|
|
357786 |
@@ -2095,7 +2147,7 @@ static const cmdinfo_t wait_break_cmd = {
|
|
|
357786 |
.oneline = "waits for the suspension of a request",
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void abort_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int abort_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
abort();
|
|
|
357786 |
}
|
|
|
357786 |
@@ -2121,7 +2173,7 @@ static void sigraise_help(void)
|
|
|
357786 |
"\n", SIGTERM);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void sigraise_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int sigraise_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t sigraise_cmd = {
|
|
|
357786 |
.name = "sigraise",
|
|
|
357786 |
@@ -2134,16 +2186,16 @@ static const cmdinfo_t sigraise_cmd = {
|
|
|
357786 |
.help = sigraise_help,
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void sigraise_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int sigraise_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
int64_t sig = cvtnum(argv[1]);
|
|
|
357786 |
if (sig < 0) {
|
|
|
357786 |
print_cvtnum_err(sig, argv[1]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return sig;
|
|
|
357786 |
} else if (sig > NSIG) {
|
|
|
357786 |
printf("signal argument '%s' is too large to be a valid signal\n",
|
|
|
357786 |
argv[1]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
/* Using raise() to kill this process does not necessarily flush all open
|
|
|
357786 |
@@ -2153,6 +2205,8 @@ static void sigraise_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
fflush(stderr);
|
|
|
357786 |
|
|
|
357786 |
raise(sig);
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void sleep_cb(void *opaque)
|
|
|
357786 |
@@ -2161,7 +2215,7 @@ static void sleep_cb(void *opaque)
|
|
|
357786 |
*expired = true;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void sleep_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int sleep_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
char *endptr;
|
|
|
357786 |
long ms;
|
|
|
357786 |
@@ -2171,7 +2225,7 @@ static void sleep_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
ms = strtol(argv[1], &endptr, 0);
|
|
|
357786 |
if (ms < 0 || *endptr != '\0') {
|
|
|
357786 |
printf("%s is not a valid number\n", argv[1]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
timer = timer_new_ns(QEMU_CLOCK_HOST, sleep_cb, &expired);
|
|
|
357786 |
@@ -2182,6 +2236,7 @@ static void sleep_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
timer_free(timer);
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t sleep_cmd = {
|
|
|
357786 |
@@ -2228,22 +2283,23 @@ static void help_all(void)
|
|
|
357786 |
printf("\nUse 'help commandname' for extended help.\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void help_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int help_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
const cmdinfo_t *ct;
|
|
|
357786 |
|
|
|
357786 |
if (argc == 1) {
|
|
|
357786 |
help_all();
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
ct = find_command(argv[1]);
|
|
|
357786 |
if (ct == NULL) {
|
|
|
357786 |
printf("command %s not found\n", argv[1]);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
help_onecmd(argv[1], ct);
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t help_cmd = {
|
|
|
357786 |
@@ -2257,13 +2313,14 @@ static const cmdinfo_t help_cmd = {
|
|
|
357786 |
.oneline = "help for one or all commands",
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-void qemuio_command(BlockBackend *blk, const char *cmd)
|
|
|
357786 |
+int qemuio_command(BlockBackend *blk, const char *cmd)
|
|
|
357786 |
{
|
|
|
357786 |
AioContext *ctx;
|
|
|
357786 |
char *input;
|
|
|
357786 |
const cmdinfo_t *ct;
|
|
|
357786 |
char **v;
|
|
|
357786 |
int c;
|
|
|
357786 |
+ int ret = 0;
|
|
|
357786 |
|
|
|
357786 |
input = g_strdup(cmd);
|
|
|
357786 |
v = breakline(input, &c);
|
|
|
357786 |
@@ -2272,14 +2329,17 @@ void qemuio_command(BlockBackend *blk, const char *cmd)
|
|
|
357786 |
if (ct) {
|
|
|
357786 |
ctx = blk ? blk_get_aio_context(blk) : qemu_get_aio_context();
|
|
|
357786 |
aio_context_acquire(ctx);
|
|
|
357786 |
- command(blk, ct, c, v);
|
|
|
357786 |
+ ret = command(blk, ct, c, v);
|
|
|
357786 |
aio_context_release(ctx);
|
|
|
357786 |
} else {
|
|
|
357786 |
fprintf(stderr, "command \"%s\" not found\n", v[0]);
|
|
|
357786 |
+ ret = -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
g_free(input);
|
|
|
357786 |
g_free(v);
|
|
|
357786 |
+
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void __attribute((constructor)) init_qemuio_commands(void)
|
|
|
357786 |
diff --git a/qemu-io.c b/qemu-io.c
|
|
|
357786 |
index 02a67c9..ec66838 100644
|
|
|
357786 |
--- a/qemu-io.c
|
|
|
357786 |
+++ b/qemu-io.c
|
|
|
357786 |
@@ -66,10 +66,11 @@ static int get_eof_char(void)
|
|
|
357786 |
#endif
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void close_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int close_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
blk_unref(qemuio_blk);
|
|
|
357786 |
qemuio_blk = NULL;
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t close_cmd = {
|
|
|
357786 |
@@ -136,7 +137,7 @@ static void open_help(void)
|
|
|
357786 |
"\n");
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void open_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
+static int open_f(BlockBackend *blk, int argc, char **argv);
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t open_cmd = {
|
|
|
357786 |
.name = "open",
|
|
|
357786 |
@@ -160,12 +161,13 @@ static QemuOptsList empty_opts = {
|
|
|
357786 |
},
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
-static void open_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int open_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
int flags = BDRV_O_UNMAP;
|
|
|
357786 |
int readonly = 0;
|
|
|
357786 |
bool writethrough = true;
|
|
|
357786 |
int c;
|
|
|
357786 |
+ int ret;
|
|
|
357786 |
QemuOpts *qopts;
|
|
|
357786 |
QDict *opts;
|
|
|
357786 |
bool force_share = false;
|
|
|
357786 |
@@ -192,25 +194,25 @@ static void open_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) {
|
|
|
357786 |
error_report("Invalid cache option: %s", optarg);
|
|
|
357786 |
qemu_opts_reset(&empty_opts);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'd':
|
|
|
357786 |
if (bdrv_parse_discard_flags(optarg, &flags) < 0) {
|
|
|
357786 |
error_report("Invalid discard option: %s", optarg);
|
|
|
357786 |
qemu_opts_reset(&empty_opts);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'o':
|
|
|
357786 |
if (imageOpts) {
|
|
|
357786 |
printf("--image-opts and 'open -o' are mutually exclusive\n");
|
|
|
357786 |
qemu_opts_reset(&empty_opts);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) {
|
|
|
357786 |
qemu_opts_reset(&empty_opts);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
break;
|
|
|
357786 |
case 'U':
|
|
|
357786 |
@@ -219,7 +221,7 @@ static void open_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
default:
|
|
|
357786 |
qemu_opts_reset(&empty_opts);
|
|
|
357786 |
qemuio_command_usage(&open_cmd);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
@@ -230,7 +232,7 @@ static void open_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
if (imageOpts && (optind == argc - 1)) {
|
|
|
357786 |
if (!qemu_opts_parse_noisily(&empty_opts, argv[optind], false)) {
|
|
|
357786 |
qemu_opts_reset(&empty_opts);
|
|
|
357786 |
- return;
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
optind++;
|
|
|
357786 |
}
|
|
|
357786 |
@@ -240,18 +242,26 @@ static void open_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
qemu_opts_reset(&empty_opts);
|
|
|
357786 |
|
|
|
357786 |
if (optind == argc - 1) {
|
|
|
357786 |
- openfile(argv[optind], flags, writethrough, force_share, opts);
|
|
|
357786 |
+ ret = openfile(argv[optind], flags, writethrough, force_share, opts);
|
|
|
357786 |
} else if (optind == argc) {
|
|
|
357786 |
- openfile(NULL, flags, writethrough, force_share, opts);
|
|
|
357786 |
+ ret = openfile(NULL, flags, writethrough, force_share, opts);
|
|
|
357786 |
} else {
|
|
|
357786 |
qobject_unref(opts);
|
|
|
357786 |
qemuio_command_usage(&open_cmd);
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
+ }
|
|
|
357786 |
+
|
|
|
357786 |
+ if (ret) {
|
|
|
357786 |
+ return -EINVAL;
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void quit_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
+static int quit_f(BlockBackend *blk, int argc, char **argv)
|
|
|
357786 |
{
|
|
|
357786 |
quit_qemu_io = true;
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const cmdinfo_t quit_cmd = {
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|