From nobody Wed Oct 29 06:51:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524926813134734.2643517526396; Sat, 28 Apr 2018 07:46:53 -0700 (PDT) Received: from localhost ([::1]:52370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR7k-0007rr-5A for importer@patchew.org; Sat, 28 Apr 2018 10:46:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR2o-0003zZ-HG for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCR2k-0004ov-Kb for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56774 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fCR2b-0004cj-KD; Sat, 28 Apr 2018 10:41:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 26E6C81A8ED2; Sat, 28 Apr 2018 14:41:32 +0000 (UTC) Received: from localhost (ovpn-204-56.brq.redhat.com [10.40.204.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A7A12023227; Sat, 28 Apr 2018 14:41:31 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 28 Apr 2018 16:41:19 +0200 Message-Id: <20180428144123.30333-2-mreitz@redhat.com> In-Reply-To: <20180428144123.30333-1-mreitz@redhat.com> References: <20180428144123.30333-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 28 Apr 2018 14:41:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 28 Apr 2018 14:41:32 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/5] qemu-io: Drop command functions' return values X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Eric Blake --- include/qemu-io.h | 6 +- qemu-io-cmds.c | 294 +++++++++++++++++++++++++-------------------------= ---- qemu-io.c | 36 +++---- 3 files changed, 157 insertions(+), 179 deletions(-) diff --git a/include/qemu-io.h b/include/qemu-io.h index 196fde0f3a..06cdfbf660 100644 --- a/include/qemu-io.h +++ b/include/qemu-io.h @@ -22,7 +22,7 @@ =20 #define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */ =20 -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); =20 typedef struct cmdinfo { @@ -41,10 +41,10 @@ typedef struct cmdinfo { =20 extern bool qemuio_misalign; =20 -bool qemuio_command(BlockBackend *blk, const char *cmd); +void qemuio_command(BlockBackend *blk, const char *cmd); =20 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 (*fn)(const char *cmd, void *opaque), void *opaque); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 9b3cd00af6..c2fbaae0fd 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -48,10 +48,9 @@ void qemuio_add_command(const cmdinfo_t *ci) qsort(cmdtab, ncmds, sizeof(*cmdtab), compare_cmdname); } =20 -int qemuio_command_usage(const cmdinfo_t *ci) +void qemuio_command_usage(const cmdinfo_t *ci) { printf("%s %s -- %s\n", ci->name, ci->args, ci->oneline); - return 0; } =20 static int init_check_command(BlockBackend *blk, const cmdinfo_t *ct) @@ -66,13 +65,13 @@ static int init_check_command(BlockBackend *blk, const = cmdinfo_t *ct) return 1; } =20 -static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc, - char **argv) +static void command(BlockBackend *blk, const cmdinfo_t *ct, int argc, + char **argv) { char *cmd =3D argv[0]; =20 if (!init_check_command(blk, ct)) { - return 0; + return; } =20 if (argc - 1 < ct->argmin || (ct->argmax !=3D -1 && argc - 1 > ct->arg= max)) { @@ -89,7 +88,7 @@ static int command(BlockBackend *blk, const cmdinfo_t *ct= , int argc, "bad argument count %d to %s, expected between %d and = %d arguments\n", argc-1, cmd, ct->argmin, ct->argmax); } - return 0; + return; } =20 /* Request additional permissions if necessary for this command. The c= aller @@ -109,13 +108,13 @@ static int command(BlockBackend *blk, const cmdinfo_t= *ct, int argc, ret =3D blk_set_perm(blk, new_perm, orig_shared_perm, &local_e= rr); if (ret < 0) { error_report_err(local_err); - return 0; + return; } } } =20 optind =3D 0; - return ct->cfunc(blk, argc, argv); + ct->cfunc(blk, argc, argv); } =20 static const cmdinfo_t *find_command(const char *cmd) @@ -634,7 +633,7 @@ static void read_help(void) "\n"); } =20 -static int read_f(BlockBackend *blk, int argc, char **argv); +static void read_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t read_cmd =3D { .name =3D "read", @@ -647,7 +646,7 @@ static const cmdinfo_t read_cmd =3D { .help =3D read_help, }; =20 -static int read_f(BlockBackend *blk, int argc, char **argv) +static void read_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; @@ -674,7 +673,7 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) pattern_count =3D cvtnum(optarg); if (pattern_count < 0) { print_cvtnum_err(pattern_count, optarg); - return 0; + return; } break; case 'p': @@ -684,7 +683,7 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return 0; + return; } break; case 'q': @@ -695,40 +694,43 @@ static int read_f(BlockBackend *blk, int argc, char *= *argv) pattern_offset =3D cvtnum(optarg); if (pattern_offset < 0) { print_cvtnum_err(pattern_offset, optarg); - return 0; + return; } break; case 'v': vflag =3D true; break; default: - return qemuio_command_usage(&read_cmd); + qemuio_command_usage(&read_cmd); + return; } } =20 if (optind !=3D argc - 2) { - return qemuio_command_usage(&read_cmd); + qemuio_command_usage(&read_cmd); + return; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { print_cvtnum_err(count, argv[optind]); - return 0; + return; } else if (count > BDRV_REQUEST_MAX_BYTES) { printf("length cannot exceed %" PRIu64 ", given %s\n", (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); - return 0; + return; } =20 if (!Pflag && (lflag || sflag)) { - return qemuio_command_usage(&read_cmd); + qemuio_command_usage(&read_cmd); + return; } =20 if (!lflag) { @@ -737,19 +739,19 @@ static int read_f(BlockBackend *blk, int argc, char *= *argv) =20 if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) { printf("pattern verification range exceeds end of read data\n"); - return 0; + return; } =20 if (bflag) { if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { printf("%" PRId64 " is not a sector-aligned value for 'offset'= \n", offset); - return 0; + return; } if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { printf("%"PRId64" is not a sector-aligned value for 'count'\n", count); - return 0; + return; } } =20 @@ -793,8 +795,6 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) =20 out: qemu_io_free(buf); - - return 0; } =20 static void readv_help(void) @@ -816,7 +816,7 @@ static void readv_help(void) "\n"); } =20 -static int readv_f(BlockBackend *blk, int argc, char **argv); +static void readv_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t readv_cmd =3D { .name =3D "readv", @@ -828,7 +828,7 @@ static const cmdinfo_t readv_cmd =3D { .help =3D readv_help, }; =20 -static int readv_f(BlockBackend *blk, int argc, char **argv) +static void readv_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; @@ -851,7 +851,7 @@ static int readv_f(BlockBackend *blk, int argc, char **= argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return 0; + return; } break; case 'q': @@ -861,26 +861,28 @@ static int readv_f(BlockBackend *blk, int argc, char = **argv) vflag =3D true; break; default: - return qemuio_command_usage(&readv_cmd); + qemuio_command_usage(&readv_cmd); + return; } } =20 if (optind > argc - 2) { - return qemuio_command_usage(&readv_cmd); + qemuio_command_usage(&readv_cmd); + return; } =20 =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab); if (buf =3D=3D NULL) { - return 0; + return; } =20 gettimeofday(&t1, NULL); @@ -917,7 +919,6 @@ static int readv_f(BlockBackend *blk, int argc, char **= argv) out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); - return 0; } =20 static void write_help(void) @@ -943,7 +944,7 @@ static void write_help(void) "\n"); } =20 -static int write_f(BlockBackend *blk, int argc, char **argv); +static void write_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t write_cmd =3D { .name =3D "write", @@ -957,7 +958,7 @@ static const cmdinfo_t write_cmd =3D { .help =3D write_help, }; =20 -static int write_f(BlockBackend *blk, int argc, char **argv) +static void write_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, bflag =3D false; @@ -992,7 +993,7 @@ static int write_f(BlockBackend *blk, int argc, char **= argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return 0; + return; } break; case 'q': @@ -1005,62 +1006,64 @@ static int write_f(BlockBackend *blk, int argc, cha= r **argv) zflag =3D true; break; default: - return qemuio_command_usage(&write_cmd); + qemuio_command_usage(&write_cmd); + return; } } =20 if (optind !=3D argc - 2) { - return qemuio_command_usage(&write_cmd); + qemuio_command_usage(&write_cmd); + return; } =20 if (bflag && zflag) { printf("-b and -z cannot be specified at the same time\n"); - return 0; + return; } =20 if ((flags & BDRV_REQ_FUA) && (bflag || cflag)) { printf("-f and -b or -c cannot be specified at the same time\n"); - return 0; + return; } =20 if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) { printf("-u requires -z to be specified\n"); - return 0; + return; } =20 if (zflag && Pflag) { printf("-z and -P cannot be specified at the same time\n"); - return 0; + return; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { print_cvtnum_err(count, argv[optind]); - return 0; + return; } else if (count > BDRV_REQUEST_MAX_BYTES) { printf("length cannot exceed %" PRIu64 ", given %s\n", (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); - return 0; + return; } =20 if (bflag || cflag) { if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { printf("%" PRId64 " is not a sector-aligned value for 'offset'= \n", offset); - return 0; + return; } =20 if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { printf("%"PRId64" is not a sector-aligned value for 'count'\n", count); - return 0; + return; } } =20 @@ -1097,8 +1100,6 @@ out: if (!zflag) { qemu_io_free(buf); } - - return 0; } =20 static void @@ -1120,7 +1121,7 @@ writev_help(void) "\n"); } =20 -static int writev_f(BlockBackend *blk, int argc, char **argv); +static void writev_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t writev_cmd =3D { .name =3D "writev", @@ -1133,7 +1134,7 @@ static const cmdinfo_t writev_cmd =3D { .help =3D writev_help, }; =20 -static int writev_f(BlockBackend *blk, int argc, char **argv) +static void writev_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false; @@ -1161,29 +1162,31 @@ static int writev_f(BlockBackend *blk, int argc, ch= ar **argv) case 'P': pattern =3D parse_pattern(optarg); if (pattern < 0) { - return 0; + return; } break; default: - return qemuio_command_usage(&writev_cmd); + qemuio_command_usage(&writev_cmd); + return; } } =20 if (optind > argc - 2) { - return qemuio_command_usage(&writev_cmd); + qemuio_command_usage(&writev_cmd); + return; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern); if (buf =3D=3D NULL) { - return 0; + return; } =20 gettimeofday(&t1, NULL); @@ -1205,7 +1208,6 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv) out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); - return 0; } =20 struct aio_ctx { @@ -1320,7 +1322,7 @@ static void aio_read_help(void) "\n"); } =20 -static int aio_read_f(BlockBackend *blk, int argc, char **argv); +static void aio_read_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t aio_read_cmd =3D { .name =3D "aio_read", @@ -1332,7 +1334,7 @@ static const cmdinfo_t aio_read_cmd =3D { .help =3D aio_read_help, }; =20 -static int aio_read_f(BlockBackend *blk, int argc, char **argv) +static void aio_read_f(BlockBackend *blk, int argc, char **argv) { int nr_iov, c; struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); @@ -1348,14 +1350,14 @@ static int aio_read_f(BlockBackend *blk, int argc, = char **argv) ctx->pattern =3D parse_pattern(optarg); if (ctx->pattern < 0) { g_free(ctx); - return 0; + return; } break; case 'i': printf("injecting invalid read request\n"); block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); - return 0; + return; case 'q': ctx->qflag =3D true; break; @@ -1364,20 +1366,22 @@ static int aio_read_f(BlockBackend *blk, int argc, = char **argv) break; default: g_free(ctx); - return qemuio_command_usage(&aio_read_cmd); + qemuio_command_usage(&aio_read_cmd); + return; } } =20 if (optind > argc - 2) { g_free(ctx); - return qemuio_command_usage(&aio_read_cmd); + qemuio_command_usage(&aio_read_cmd); + return; } =20 ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { print_cvtnum_err(ctx->offset, argv[optind]); g_free(ctx); - return 0; + return; } optind++; =20 @@ -1386,14 +1390,13 @@ static int aio_read_f(BlockBackend *blk, int argc, = char **argv) if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); - return 0; + return; } =20 gettimeofday(&ctx->t1, NULL); block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size, BLOCK_ACCT_READ); blk_aio_preadv(blk, ctx->offset, &ctx->qiov, 0, aio_read_done, ctx); - return 0; } =20 static void aio_write_help(void) @@ -1420,7 +1423,7 @@ static void aio_write_help(void) "\n"); } =20 -static int aio_write_f(BlockBackend *blk, int argc, char **argv); +static void aio_write_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t aio_write_cmd =3D { .name =3D "aio_write", @@ -1433,7 +1436,7 @@ static const cmdinfo_t aio_write_cmd =3D { .help =3D aio_write_help, }; =20 -static int aio_write_f(BlockBackend *blk, int argc, char **argv) +static void aio_write_f(BlockBackend *blk, int argc, char **argv) { int nr_iov, c; int pattern =3D 0xcd; @@ -1459,51 +1462,53 @@ static int aio_write_f(BlockBackend *blk, int argc,= char **argv) pattern =3D parse_pattern(optarg); if (pattern < 0) { g_free(ctx); - return 0; + return; } break; case 'i': printf("injecting invalid write request\n"); block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); - return 0; + return; case 'z': ctx->zflag =3D true; break; default: g_free(ctx); - return qemuio_command_usage(&aio_write_cmd); + qemuio_command_usage(&aio_write_cmd); + return; } } =20 if (optind > argc - 2) { g_free(ctx); - return qemuio_command_usage(&aio_write_cmd); + qemuio_command_usage(&aio_write_cmd); + return; } =20 if (ctx->zflag && optind !=3D argc - 2) { printf("-z supports only a single length parameter\n"); g_free(ctx); - return 0; + return; } =20 if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) { printf("-u requires -z to be specified\n"); g_free(ctx); - return 0; + return; } =20 if (ctx->zflag && ctx->Pflag) { printf("-z and -P cannot be specified at the same time\n"); g_free(ctx); - return 0; + return; } =20 ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { print_cvtnum_err(ctx->offset, argv[optind]); g_free(ctx); - return 0; + return; } optind++; =20 @@ -1512,7 +1517,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) if (count < 0) { print_cvtnum_err(count, argv[optind]); g_free(ctx); - return 0; + return; } =20 ctx->qiov.size =3D count; @@ -1525,7 +1530,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); - return 0; + return; } =20 gettimeofday(&ctx->t1, NULL); @@ -1535,16 +1540,14 @@ static int aio_write_f(BlockBackend *blk, int argc,= char **argv) blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, flags, aio_write_don= e, ctx); } - return 0; } =20 -static int aio_flush_f(BlockBackend *blk, int argc, char **argv) +static void aio_flush_f(BlockBackend *blk, int argc, char **argv) { BlockAcctCookie cookie; block_acct_start(blk_get_stats(blk), &cookie, 0, BLOCK_ACCT_FLUSH); blk_drain_all(); block_acct_done(blk_get_stats(blk), &cookie); - return 0; } =20 static const cmdinfo_t aio_flush_cmd =3D { @@ -1553,10 +1556,9 @@ static const cmdinfo_t aio_flush_cmd =3D { .oneline =3D "completes all outstanding aio requests" }; =20 -static int flush_f(BlockBackend *blk, int argc, char **argv) +static void flush_f(BlockBackend *blk, int argc, char **argv) { blk_flush(blk); - return 0; } =20 static const cmdinfo_t flush_cmd =3D { @@ -1566,7 +1568,7 @@ static const cmdinfo_t flush_cmd =3D { .oneline =3D "flush all in-core file state to disk", }; =20 -static int truncate_f(BlockBackend *blk, int argc, char **argv) +static void truncate_f(BlockBackend *blk, int argc, char **argv) { Error *local_err =3D NULL; int64_t offset; @@ -1575,16 +1577,14 @@ static int truncate_f(BlockBackend *blk, int argc, = char **argv) offset =3D cvtnum(argv[1]); if (offset < 0) { print_cvtnum_err(offset, argv[1]); - return 0; + return; } =20 ret =3D blk_truncate(blk, offset, PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); - return 0; + return; } - - return 0; } =20 static const cmdinfo_t truncate_cmd =3D { @@ -1598,7 +1598,7 @@ static const cmdinfo_t truncate_cmd =3D { .oneline =3D "truncates the current file at the given offset", }; =20 -static int length_f(BlockBackend *blk, int argc, char **argv) +static void length_f(BlockBackend *blk, int argc, char **argv) { int64_t size; char s1[64]; @@ -1606,12 +1606,11 @@ static int length_f(BlockBackend *blk, int argc, ch= ar **argv) size =3D blk_getlength(blk); if (size < 0) { printf("getlength: %s\n", strerror(-size)); - return 0; + return; } =20 cvtstr(size, s1, sizeof(s1)); printf("%s\n", s1); - return 0; } =20 =20 @@ -1623,7 +1622,7 @@ static const cmdinfo_t length_cmd =3D { }; =20 =20 -static int info_f(BlockBackend *blk, int argc, char **argv) +static void info_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); BlockDriverInfo bdi; @@ -1640,7 +1639,7 @@ static int info_f(BlockBackend *blk, int argc, char *= *argv) =20 ret =3D bdrv_get_info(bs, &bdi); if (ret) { - return 0; + return; } =20 cvtstr(bdi.cluster_size, s1, sizeof(s1)); @@ -1655,8 +1654,6 @@ static int info_f(BlockBackend *blk, int argc, char *= *argv) bdrv_image_info_specific_dump(fprintf, stdout, spec_info); qapi_free_ImageInfoSpecific(spec_info); } - - return 0; } =20 =20 @@ -1683,7 +1680,7 @@ static void discard_help(void) "\n"); } =20 -static int discard_f(BlockBackend *blk, int argc, char **argv); +static void discard_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t discard_cmd =3D { .name =3D "discard", @@ -1697,7 +1694,7 @@ static const cmdinfo_t discard_cmd =3D { .help =3D discard_help, }; =20 -static int discard_f(BlockBackend *blk, int argc, char **argv) +static void discard_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false; @@ -1713,30 +1710,32 @@ static int discard_f(BlockBackend *blk, int argc, c= har **argv) qflag =3D true; break; default: - return qemuio_command_usage(&discard_cmd); + qemuio_command_usage(&discard_cmd); + return; } } =20 if (optind !=3D argc - 2) { - return qemuio_command_usage(&discard_cmd); + qemuio_command_usage(&discard_cmd); + return; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } =20 optind++; bytes =3D cvtnum(argv[optind]); if (bytes < 0) { print_cvtnum_err(bytes, argv[optind]); - return 0; + return; } else if (bytes >> BDRV_SECTOR_BITS > BDRV_REQUEST_MAX_SECTORS) { printf("length cannot exceed %"PRIu64", given %s\n", (uint64_t)BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS, argv[optind]); - return 0; + return; } =20 gettimeofday(&t1, NULL); @@ -1745,7 +1744,7 @@ static int discard_f(BlockBackend *blk, int argc, cha= r **argv) =20 if (ret < 0) { printf("discard failed: %s\n", strerror(-ret)); - goto out; + return; } =20 /* Finally, report back -- -C gives a parsable format */ @@ -1753,12 +1752,9 @@ static int discard_f(BlockBackend *blk, int argc, ch= ar **argv) t2 =3D tsub(t2, t1); print_report("discard", &t2, offset, bytes, bytes, 1, Cflag); } - -out: - return 0; } =20 -static int alloc_f(BlockBackend *blk, int argc, char **argv) +static void alloc_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); int64_t offset, start, remaining, count; @@ -1769,14 +1765,14 @@ static int alloc_f(BlockBackend *blk, int argc, cha= r **argv) start =3D offset =3D cvtnum(argv[1]); if (offset < 0) { print_cvtnum_err(offset, argv[1]); - return 0; + return; } =20 if (argc =3D=3D 3) { count =3D cvtnum(argv[2]); if (count < 0) { print_cvtnum_err(count, argv[2]); - return 0; + return; } } else { count =3D BDRV_SECTOR_SIZE; @@ -1788,7 +1784,7 @@ static int alloc_f(BlockBackend *blk, int argc, char = **argv) ret =3D bdrv_is_allocated(bs, offset, remaining, &num); if (ret < 0) { printf("is_allocated failed: %s\n", strerror(-ret)); - return 0; + return; } offset +=3D num; remaining -=3D num; @@ -1805,7 +1801,6 @@ static int alloc_f(BlockBackend *blk, int argc, char = **argv) =20 printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n", sum_alloc, count, s1); - return 0; } =20 static const cmdinfo_t alloc_cmd =3D { @@ -1851,7 +1846,7 @@ static int map_is_allocated(BlockDriverState *bs, int= 64_t offset, return firstret; } =20 -static int map_f(BlockBackend *blk, int argc, char **argv) +static void map_f(BlockBackend *blk, int argc, char **argv) { int64_t offset, bytes; char s1[64], s2[64]; @@ -1863,17 +1858,17 @@ static int map_f(BlockBackend *blk, int argc, char = **argv) bytes =3D blk_getlength(blk); if (bytes < 0) { error_report("Failed to query image length: %s", strerror(-bytes)); - return 0; + return; } =20 while (bytes) { ret =3D map_is_allocated(blk_bs(blk), offset, bytes, &num); if (ret < 0) { error_report("Failed to get allocation status: %s", strerror(-= ret)); - return 0; + return; } else if (!num) { error_report("Unexpected end of image"); - return 0; + return; } =20 retstr =3D ret ? " allocated" : "not allocated"; @@ -1885,8 +1880,6 @@ static int map_f(BlockBackend *blk, int argc, char **= argv) offset +=3D num; bytes -=3D num; } - - return 0; } =20 static const cmdinfo_t map_cmd =3D { @@ -1914,7 +1907,7 @@ static void reopen_help(void) "\n"); } =20 -static int reopen_f(BlockBackend *blk, int argc, char **argv); +static void reopen_f(BlockBackend *blk, int argc, char **argv); =20 static QemuOptsList reopen_opts =3D { .name =3D "reopen", @@ -1936,7 +1929,7 @@ static const cmdinfo_t reopen_cmd =3D { .help =3D reopen_help, }; =20 -static int reopen_f(BlockBackend *blk, int argc, char **argv) +static void reopen_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); QemuOpts *qopts; @@ -1954,19 +1947,19 @@ static int reopen_f(BlockBackend *blk, int argc, ch= ar **argv) case 'c': if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); - return 0; + return; } break; case 'o': if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) { qemu_opts_reset(&reopen_opts); - return 0; + return; } break; case 'r': if (has_rw_option) { error_report("Only one -r/-w option may be given"); - return 0; + return; } flags &=3D ~BDRV_O_RDWR; has_rw_option =3D true; @@ -1974,20 +1967,22 @@ static int reopen_f(BlockBackend *blk, int argc, ch= ar **argv) case 'w': if (has_rw_option) { error_report("Only one -r/-w option may be given"); - return 0; + return; } flags |=3D BDRV_O_RDWR; has_rw_option =3D true; break; default: qemu_opts_reset(&reopen_opts); - return qemuio_command_usage(&reopen_cmd); + qemuio_command_usage(&reopen_cmd); + return; } } =20 if (optind !=3D argc) { qemu_opts_reset(&reopen_opts); - return qemuio_command_usage(&reopen_cmd); + qemuio_command_usage(&reopen_cmd); + return; } =20 if (writethrough !=3D blk_enable_write_cache(blk) && @@ -1995,7 +1990,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) { error_report("Cannot change cache.writeback: Device attached"); qemu_opts_reset(&reopen_opts); - return 0; + return; } =20 if (!(flags & BDRV_O_RDWR)) { @@ -2024,11 +2019,9 @@ static int reopen_f(BlockBackend *blk, int argc, cha= r **argv) } else { blk_set_enable_write_cache(blk, !writethrough); } - - return 0; } =20 -static int break_f(BlockBackend *blk, int argc, char **argv) +static void break_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 @@ -2036,11 +2029,9 @@ static int break_f(BlockBackend *blk, int argc, char= **argv) if (ret < 0) { printf("Could not set breakpoint: %s\n", strerror(-ret)); } - - return 0; } =20 -static int remove_break_f(BlockBackend *blk, int argc, char **argv) +static void remove_break_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 @@ -2048,8 +2039,6 @@ static int remove_break_f(BlockBackend *blk, int argc= , char **argv) if (ret < 0) { printf("Could not remove breakpoint %s: %s\n", argv[1], strerror(-= ret)); } - - return 0; } =20 static const cmdinfo_t break_cmd =3D { @@ -2071,7 +2060,7 @@ static const cmdinfo_t remove_break_cmd =3D { .oneline =3D "remove a breakpoint by tag", }; =20 -static int resume_f(BlockBackend *blk, int argc, char **argv) +static void resume_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 @@ -2079,8 +2068,6 @@ static int resume_f(BlockBackend *blk, int argc, char= **argv) if (ret < 0) { printf("Could not resume request: %s\n", strerror(-ret)); } - - return 0; } =20 static const cmdinfo_t resume_cmd =3D { @@ -2092,13 +2079,11 @@ static const cmdinfo_t resume_cmd =3D { .oneline =3D "resumes the request tagged as tag", }; =20 -static int wait_break_f(BlockBackend *blk, int argc, char **argv) +static void wait_break_f(BlockBackend *blk, int argc, char **argv) { while (!bdrv_debug_is_suspended(blk_bs(blk), argv[1])) { aio_poll(blk_get_aio_context(blk), true); } - - return 0; } =20 static const cmdinfo_t wait_break_cmd =3D { @@ -2110,7 +2095,7 @@ static const cmdinfo_t wait_break_cmd =3D { .oneline =3D "waits for the suspension of a request", }; =20 -static int abort_f(BlockBackend *blk, int argc, char **argv) +static void abort_f(BlockBackend *blk, int argc, char **argv) { abort(); } @@ -2136,7 +2121,7 @@ static void sigraise_help(void) "\n", SIGTERM); } =20 -static int sigraise_f(BlockBackend *blk, int argc, char **argv); +static void sigraise_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t sigraise_cmd =3D { .name =3D "sigraise", @@ -2149,16 +2134,16 @@ static const cmdinfo_t sigraise_cmd =3D { .help =3D sigraise_help, }; =20 -static int sigraise_f(BlockBackend *blk, int argc, char **argv) +static void sigraise_f(BlockBackend *blk, int argc, char **argv) { int64_t sig =3D cvtnum(argv[1]); if (sig < 0) { print_cvtnum_err(sig, argv[1]); - return 0; + return; } else if (sig > NSIG) { printf("signal argument '%s' is too large to be a valid signal\n", argv[1]); - return 0; + return; } =20 /* Using raise() to kill this process does not necessarily flush all o= pen @@ -2168,7 +2153,6 @@ static int sigraise_f(BlockBackend *blk, int argc, ch= ar **argv) fflush(stderr); =20 raise(sig); - return 0; } =20 static void sleep_cb(void *opaque) @@ -2177,7 +2161,7 @@ static void sleep_cb(void *opaque) *expired =3D true; } =20 -static int sleep_f(BlockBackend *blk, int argc, char **argv) +static void sleep_f(BlockBackend *blk, int argc, char **argv) { char *endptr; long ms; @@ -2187,7 +2171,7 @@ static int sleep_f(BlockBackend *blk, int argc, char = **argv) ms =3D strtol(argv[1], &endptr, 0); if (ms < 0 || *endptr !=3D '\0') { printf("%s is not a valid number\n", argv[1]); - return 0; + return; } =20 timer =3D timer_new_ns(QEMU_CLOCK_HOST, sleep_cb, &expired); @@ -2198,8 +2182,6 @@ static int sleep_f(BlockBackend *blk, int argc, char = **argv) } =20 timer_free(timer); - - return 0; } =20 static const cmdinfo_t sleep_cmd =3D { @@ -2246,23 +2228,22 @@ static void help_all(void) printf("\nUse 'help commandname' for extended help.\n"); } =20 -static int help_f(BlockBackend *blk, int argc, char **argv) +static void help_f(BlockBackend *blk, int argc, char **argv) { const cmdinfo_t *ct; =20 if (argc =3D=3D 1) { help_all(); - return 0; + return; } =20 ct =3D find_command(argv[1]); if (ct =3D=3D NULL) { printf("command %s not found\n", argv[1]); - return 0; + return; } =20 help_onecmd(argv[1], ct); - return 0; } =20 static const cmdinfo_t help_cmd =3D { @@ -2276,14 +2257,13 @@ static const cmdinfo_t help_cmd =3D { .oneline =3D "help for one or all commands", }; =20 -bool qemuio_command(BlockBackend *blk, const char *cmd) +void qemuio_command(BlockBackend *blk, const char *cmd) { AioContext *ctx; char *input; const cmdinfo_t *ct; char **v; int c; - bool done =3D false; =20 input =3D g_strdup(cmd); v =3D breakline(input, &c); @@ -2292,7 +2272,7 @@ bool qemuio_command(BlockBackend *blk, const char *cm= d) if (ct) { ctx =3D blk ? blk_get_aio_context(blk) : qemu_get_aio_context(= ); aio_context_acquire(ctx); - done =3D command(blk, ct, c, v); + command(blk, ct, c, v); aio_context_release(ctx); } else { fprintf(stderr, "command \"%s\" not found\n", v[0]); @@ -2300,8 +2280,6 @@ bool qemuio_command(BlockBackend *blk, const char *cm= d) } g_free(input); g_free(v); - - return done; } =20 static void __attribute((constructor)) init_qemuio_commands(void) diff --git a/qemu-io.c b/qemu-io.c index e692c555e0..4578ccfaa5 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -37,6 +37,7 @@ static char *progname; =20 static BlockBackend *qemuio_blk; +static bool quit_qemu_io; =20 /* qemu-io commands passed using -c */ static int ncmdline; @@ -65,11 +66,10 @@ static int get_eof_char(void) #endif } =20 -static int close_f(BlockBackend *blk, int argc, char **argv) +static void close_f(BlockBackend *blk, int argc, char **argv) { blk_unref(qemuio_blk); qemuio_blk =3D NULL; - return 0; } =20 static const cmdinfo_t close_cmd =3D { @@ -136,7 +136,7 @@ static void open_help(void) "\n"); } =20 -static int open_f(BlockBackend *blk, int argc, char **argv); +static void open_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t open_cmd =3D { .name =3D "open", @@ -160,7 +160,7 @@ static QemuOptsList empty_opts =3D { }, }; =20 -static int open_f(BlockBackend *blk, int argc, char **argv) +static void open_f(BlockBackend *blk, int argc, char **argv) { int flags =3D BDRV_O_UNMAP; int readonly =3D 0; @@ -192,25 +192,25 @@ static int open_f(BlockBackend *blk, int argc, char *= *argv) if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); qemu_opts_reset(&empty_opts); - return 0; + return; } break; case 'd': if (bdrv_parse_discard_flags(optarg, &flags) < 0) { error_report("Invalid discard option: %s", optarg); qemu_opts_reset(&empty_opts); - return 0; + return; } break; case 'o': if (imageOpts) { printf("--image-opts and 'open -o' are mutually exclusive\= n"); qemu_opts_reset(&empty_opts); - return 0; + return; } if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) { qemu_opts_reset(&empty_opts); - return 0; + return; } break; case 'U': @@ -218,7 +218,8 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv) break; default: qemu_opts_reset(&empty_opts); - return qemuio_command_usage(&open_cmd); + qemuio_command_usage(&open_cmd); + return; } } =20 @@ -229,7 +230,7 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv) if (imageOpts && (optind =3D=3D argc - 1)) { if (!qemu_opts_parse_noisily(&empty_opts, argv[optind], false)) { qemu_opts_reset(&empty_opts); - return 0; + return; } optind++; } @@ -246,12 +247,11 @@ static int open_f(BlockBackend *blk, int argc, char *= *argv) QDECREF(opts); qemuio_command_usage(&open_cmd); } - return 0; } =20 -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 =3D true; } =20 static const cmdinfo_t quit_cmd =3D { @@ -392,18 +392,18 @@ static void prep_fetchline(void *opaque) =20 static void command_loop(void) { - int i, done =3D 0, fetchable =3D 0, prompted =3D 0; + int i, fetchable =3D 0, prompted =3D 0; char *input; =20 - for (i =3D 0; !done && i < ncmdline; i++) { - done =3D qemuio_command(qemuio_blk, cmdline[i]); + for (i =3D 0; !quit_qemu_io && i < ncmdline; i++) { + qemuio_command(qemuio_blk, cmdline[i]); } if (cmdline) { g_free(cmdline); return; } =20 - while (!done) { + while (!quit_qemu_io) { if (!prompted) { printf("%s", get_prompt()); fflush(stdout); @@ -421,7 +421,7 @@ static void command_loop(void) if (input =3D=3D NULL) { break; } - done =3D qemuio_command(qemuio_blk, input); + qemuio_command(qemuio_blk, input); g_free(input); =20 prompted =3D 0; --=20 2.14.3 From nobody Wed Oct 29 06:51:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524926798608373.80822188843035; Sat, 28 Apr 2018 07:46:38 -0700 (PDT) Received: from localhost ([::1]:52368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR7V-0007gu-ME for importer@patchew.org; Sat, 28 Apr 2018 10:46:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR2r-00041x-9R for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCR2m-0004r5-Fc for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37534 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fCR2d-0004f7-NP; Sat, 28 Apr 2018 10:41:35 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 454ED40858EE; Sat, 28 Apr 2018 14:41:35 +0000 (UTC) Received: from localhost (ovpn-204-56.brq.redhat.com [10.40.204.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C55E9215CDCB; Sat, 28 Apr 2018 14:41:33 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 28 Apr 2018 16:41:20 +0200 Message-Id: <20180428144123.30333-3-mreitz@redhat.com> In-Reply-To: <20180428144123.30333-1-mreitz@redhat.com> References: <20180428144123.30333-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 28 Apr 2018 14:41:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 28 Apr 2018 14:41:35 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/5] qemu-io: Let command functions return error code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is basically what everything else in the qemu code base does, so we can do it here, too. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- include/qemu-io.h | 4 +- qemu-io-cmds.c | 346 ++++++++++++++++++++++++++++++++------------------= ---- qemu-io.c | 34 ++++-- 3 files changed, 227 insertions(+), 157 deletions(-) diff --git a/include/qemu-io.h b/include/qemu-io.h index 06cdfbf660..380724ad59 100644 --- a/include/qemu-io.h +++ b/include/qemu-io.h @@ -22,7 +22,7 @@ =20 #define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */ =20 -typedef void (*cfunc_t)(BlockBackend *blk, int argc, char **argv); +typedef int (*cfunc_t)(BlockBackend *blk, int argc, char **argv); typedef void (*helpfunc_t)(void); =20 typedef struct cmdinfo { @@ -41,7 +41,7 @@ typedef struct cmdinfo { =20 extern bool qemuio_misalign; =20 -void qemuio_command(BlockBackend *blk, const char *cmd); +int qemuio_command(BlockBackend *blk, const char *cmd); =20 void qemuio_add_command(const cmdinfo_t *ci); void qemuio_command_usage(const cmdinfo_t *ci); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index c2fbaae0fd..5bf5f28178 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -65,13 +65,13 @@ static int init_check_command(BlockBackend *blk, const = cmdinfo_t *ct) return 1; } =20 -static void command(BlockBackend *blk, const cmdinfo_t *ct, int argc, - char **argv) +static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc, + char **argv) { char *cmd =3D argv[0]; =20 if (!init_check_command(blk, ct)) { - return; + return -EINVAL; } =20 if (argc - 1 < ct->argmin || (ct->argmax !=3D -1 && argc - 1 > ct->arg= max)) { @@ -88,7 +88,7 @@ static void command(BlockBackend *blk, const cmdinfo_t *c= t, int argc, "bad argument count %d to %s, expected between %d and = %d arguments\n", argc-1, cmd, ct->argmin, ct->argmax); } - return; + return -EINVAL; } =20 /* Request additional permissions if necessary for this command. The c= aller @@ -108,13 +108,13 @@ static void command(BlockBackend *blk, const cmdinfo_= t *ct, int argc, ret =3D blk_set_perm(blk, new_perm, orig_shared_perm, &local_e= rr); if (ret < 0) { error_report_err(local_err); - return; + return ret; } } } =20 optind =3D 0; - ct->cfunc(blk, argc, argv); + return ct->cfunc(blk, argc, argv); } =20 static const cmdinfo_t *find_command(const char *cmd) @@ -633,7 +633,7 @@ static void read_help(void) "\n"); } =20 -static void read_f(BlockBackend *blk, int argc, char **argv); +static int read_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t read_cmd =3D { .name =3D "read", @@ -646,12 +646,12 @@ static const cmdinfo_t read_cmd =3D { .help =3D read_help, }; =20 -static void read_f(BlockBackend *blk, int argc, char **argv) +static int read_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; bool Pflag =3D false, sflag =3D false, lflag =3D false, bflag =3D fals= e; - int c, cnt; + int c, cnt, ret; char *buf; int64_t offset; int64_t count; @@ -673,7 +673,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) pattern_count =3D cvtnum(optarg); if (pattern_count < 0) { print_cvtnum_err(pattern_count, optarg); - return; + return pattern_count; } break; case 'p': @@ -683,7 +683,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return; + return -EINVAL; } break; case 'q': @@ -694,7 +694,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) pattern_offset =3D cvtnum(optarg); if (pattern_offset < 0) { print_cvtnum_err(pattern_offset, optarg); - return; + return pattern_offset; } break; case 'v': @@ -702,35 +702,35 @@ static void read_f(BlockBackend *blk, int argc, char = **argv) break; default: qemuio_command_usage(&read_cmd); - return; + return -EINVAL; } } =20 if (optind !=3D argc - 2) { qemuio_command_usage(&read_cmd); - return; + return -EINVAL; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { print_cvtnum_err(count, argv[optind]); - return; + return count; } else if (count > BDRV_REQUEST_MAX_BYTES) { printf("length cannot exceed %" PRIu64 ", given %s\n", (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); - return; + return -EINVAL; } =20 if (!Pflag && (lflag || sflag)) { qemuio_command_usage(&read_cmd); - return; + return -EINVAL; } =20 if (!lflag) { @@ -739,19 +739,19 @@ static void read_f(BlockBackend *blk, int argc, char = **argv) =20 if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) { printf("pattern verification range exceeds end of read data\n"); - return; + return -EINVAL; } =20 if (bflag) { if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { printf("%" PRId64 " is not a sector-aligned value for 'offset'= \n", offset); - return; + return -EINVAL; } if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { printf("%"PRId64" is not a sector-aligned value for 'count'\n", count); - return; + return -EINVAL; } } =20 @@ -759,16 +759,19 @@ static void read_f(BlockBackend *blk, int argc, char = **argv) =20 gettimeofday(&t1, NULL); if (bflag) { - cnt =3D do_load_vmstate(blk, buf, offset, count, &total); + ret =3D do_load_vmstate(blk, buf, offset, count, &total); } else { - cnt =3D do_pread(blk, buf, offset, count, &total); + ret =3D do_pread(blk, buf, offset, count, &total); } gettimeofday(&t2, NULL); =20 - if (cnt < 0) { - printf("read failed: %s\n", strerror(-cnt)); + if (ret < 0) { + printf("read failed: %s\n", strerror(-ret)); goto out; } + cnt =3D ret; + + ret =3D 0; =20 if (Pflag) { void *cmp_buf =3D g_malloc(pattern_count); @@ -777,6 +780,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) printf("Pattern verification failed at offset %" PRId64 ", %"PRId64" bytes\n", offset + pattern_offset, pattern_count); + ret =3D -EINVAL; } g_free(cmp_buf); } @@ -795,6 +799,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) =20 out: qemu_io_free(buf); + return ret; } =20 static void readv_help(void) @@ -816,7 +821,7 @@ static void readv_help(void) "\n"); } =20 -static void readv_f(BlockBackend *blk, int argc, char **argv); +static int readv_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t readv_cmd =3D { .name =3D "readv", @@ -828,11 +833,11 @@ static const cmdinfo_t readv_cmd =3D { .help =3D readv_help, }; =20 -static void readv_f(BlockBackend *blk, int argc, char **argv) +static int readv_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; - int c, cnt; + int c, cnt, ret; char *buf; int64_t offset; /* Some compilers get confused and warn if this is not initialized. */ @@ -851,7 +856,7 @@ static void readv_f(BlockBackend *blk, int argc, char *= *argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return; + return -EINVAL; } break; case 'q': @@ -862,37 +867,40 @@ static void readv_f(BlockBackend *blk, int argc, char= **argv) break; default: qemuio_command_usage(&readv_cmd); - return; + return -EINVAL; } } =20 if (optind > argc - 2) { qemuio_command_usage(&readv_cmd); - return; + return -EINVAL; } =20 =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab); if (buf =3D=3D NULL) { - return; + return -EINVAL; } =20 gettimeofday(&t1, NULL); - cnt =3D do_aio_readv(blk, &qiov, offset, &total); + ret =3D do_aio_readv(blk, &qiov, offset, &total); gettimeofday(&t2, NULL); =20 - if (cnt < 0) { - printf("readv failed: %s\n", strerror(-cnt)); + if (ret < 0) { + printf("readv failed: %s\n", strerror(-ret)); goto out; } + cnt =3D ret; + + ret =3D 0; =20 if (Pflag) { void *cmp_buf =3D g_malloc(qiov.size); @@ -900,6 +908,7 @@ static void readv_f(BlockBackend *blk, int argc, char *= *argv) if (memcmp(buf, cmp_buf, qiov.size)) { printf("Pattern verification failed at offset %" PRId64 ", %zd bytes\n", offset, qiov.size); + ret =3D -EINVAL; } g_free(cmp_buf); } @@ -919,6 +928,7 @@ static void readv_f(BlockBackend *blk, int argc, char *= *argv) out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); + return ret; } =20 static void write_help(void) @@ -944,7 +954,7 @@ static void write_help(void) "\n"); } =20 -static void write_f(BlockBackend *blk, int argc, char **argv); +static int write_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t write_cmd =3D { .name =3D "write", @@ -958,13 +968,13 @@ static const cmdinfo_t write_cmd =3D { .help =3D write_help, }; =20 -static void write_f(BlockBackend *blk, int argc, char **argv) +static int write_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, bflag =3D false; bool Pflag =3D false, zflag =3D false, cflag =3D false; int flags =3D 0; - int c, cnt; + int c, cnt, ret; char *buf =3D NULL; int64_t offset; int64_t count; @@ -993,7 +1003,7 @@ static void write_f(BlockBackend *blk, int argc, char = **argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return; + return -EINVAL; } break; case 'q': @@ -1007,63 +1017,63 @@ static void write_f(BlockBackend *blk, int argc, ch= ar **argv) break; default: qemuio_command_usage(&write_cmd); - return; + return -EINVAL; } } =20 if (optind !=3D argc - 2) { qemuio_command_usage(&write_cmd); - return; + return -EINVAL; } =20 if (bflag && zflag) { printf("-b and -z cannot be specified at the same time\n"); - return; + return -EINVAL; } =20 if ((flags & BDRV_REQ_FUA) && (bflag || cflag)) { printf("-f and -b or -c cannot be specified at the same time\n"); - return; + return -EINVAL; } =20 if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) { printf("-u requires -z to be specified\n"); - return; + return -EINVAL; } =20 if (zflag && Pflag) { printf("-z and -P cannot be specified at the same time\n"); - return; + return -EINVAL; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { print_cvtnum_err(count, argv[optind]); - return; + return count; } else if (count > BDRV_REQUEST_MAX_BYTES) { printf("length cannot exceed %" PRIu64 ", given %s\n", (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); - return; + return -EINVAL; } =20 if (bflag || cflag) { if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { printf("%" PRId64 " is not a sector-aligned value for 'offset'= \n", offset); - return; + return -EINVAL; } =20 if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { printf("%"PRId64" is not a sector-aligned value for 'count'\n", count); - return; + return -EINVAL; } } =20 @@ -1073,20 +1083,23 @@ static void write_f(BlockBackend *blk, int argc, ch= ar **argv) =20 gettimeofday(&t1, NULL); if (bflag) { - cnt =3D do_save_vmstate(blk, buf, offset, count, &total); + ret =3D do_save_vmstate(blk, buf, offset, count, &total); } else if (zflag) { - cnt =3D do_co_pwrite_zeroes(blk, offset, count, flags, &total); + ret =3D do_co_pwrite_zeroes(blk, offset, count, flags, &total); } else if (cflag) { - cnt =3D do_write_compressed(blk, buf, offset, count, &total); + ret =3D do_write_compressed(blk, buf, offset, count, &total); } else { - cnt =3D do_pwrite(blk, buf, offset, count, flags, &total); + ret =3D do_pwrite(blk, buf, offset, count, flags, &total); } gettimeofday(&t2, NULL); =20 - if (cnt < 0) { - printf("write failed: %s\n", strerror(-cnt)); + if (ret < 0) { + printf("write failed: %s\n", strerror(-ret)); goto out; } + cnt =3D ret; + + ret =3D 0; =20 if (qflag) { goto out; @@ -1100,6 +1113,7 @@ out: if (!zflag) { qemu_io_free(buf); } + return ret; } =20 static void @@ -1121,7 +1135,7 @@ writev_help(void) "\n"); } =20 -static void writev_f(BlockBackend *blk, int argc, char **argv); +static int writev_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t writev_cmd =3D { .name =3D "writev", @@ -1134,12 +1148,12 @@ static const cmdinfo_t writev_cmd =3D { .help =3D writev_help, }; =20 -static void writev_f(BlockBackend *blk, int argc, char **argv) +static int writev_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false; int flags =3D 0; - int c, cnt; + int c, cnt, ret; char *buf; int64_t offset; /* Some compilers get confused and warn if this is not initialized. */ @@ -1162,41 +1176,44 @@ static void writev_f(BlockBackend *blk, int argc, c= har **argv) case 'P': pattern =3D parse_pattern(optarg); if (pattern < 0) { - return; + return -EINVAL; } break; default: qemuio_command_usage(&writev_cmd); - return; + return -EINVAL; } } =20 if (optind > argc - 2) { qemuio_command_usage(&writev_cmd); - return; + return -EINVAL; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern); if (buf =3D=3D NULL) { - return; + return -EINVAL; } =20 gettimeofday(&t1, NULL); - cnt =3D do_aio_writev(blk, &qiov, offset, flags, &total); + ret =3D do_aio_writev(blk, &qiov, offset, flags, &total); gettimeofday(&t2, NULL); =20 - if (cnt < 0) { - printf("writev failed: %s\n", strerror(-cnt)); + if (ret < 0) { + printf("writev failed: %s\n", strerror(-ret)); goto out; } + cnt =3D ret; + + ret =3D 0; =20 if (qflag) { goto out; @@ -1208,6 +1225,7 @@ static void writev_f(BlockBackend *blk, int argc, cha= r **argv) out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); + return ret; } =20 struct aio_ctx { @@ -1314,6 +1332,9 @@ static void aio_read_help(void) " standard output stream (with -v option) for subsequent inspection.\n" " The read is performed asynchronously and the aio_flush command must be\n" " used to ensure all outstanding aio requests have been completed.\n" +" Note that due to its asynchronous nature, this command will be\n" +" considered successful once the request is submitted, independently\n" +" of potential I/O errors or pattern mismatches.\n" " -C, -- report statistics in a machine parsable format\n" " -P, -- use a pattern to verify read data\n" " -i, -- treat request as invalid, for exercising stats\n" @@ -1322,7 +1343,7 @@ static void aio_read_help(void) "\n"); } =20 -static void aio_read_f(BlockBackend *blk, int argc, char **argv); +static int aio_read_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t aio_read_cmd =3D { .name =3D "aio_read", @@ -1334,7 +1355,7 @@ static const cmdinfo_t aio_read_cmd =3D { .help =3D aio_read_help, }; =20 -static void aio_read_f(BlockBackend *blk, int argc, char **argv) +static int aio_read_f(BlockBackend *blk, int argc, char **argv) { int nr_iov, c; struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); @@ -1350,14 +1371,14 @@ static void aio_read_f(BlockBackend *blk, int argc,= char **argv) ctx->pattern =3D parse_pattern(optarg); if (ctx->pattern < 0) { g_free(ctx); - return; + return -EINVAL; } break; case 'i': printf("injecting invalid read request\n"); block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); - return; + return 0; case 'q': ctx->qflag =3D true; break; @@ -1367,21 +1388,22 @@ static void aio_read_f(BlockBackend *blk, int argc,= char **argv) default: g_free(ctx); qemuio_command_usage(&aio_read_cmd); - return; + return -EINVAL; } } =20 if (optind > argc - 2) { g_free(ctx); qemuio_command_usage(&aio_read_cmd); - return; + return -EINVAL; } =20 ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { - print_cvtnum_err(ctx->offset, argv[optind]); + int ret =3D ctx->offset; + print_cvtnum_err(ret, argv[optind]); g_free(ctx); - return; + return ret; } optind++; =20 @@ -1390,13 +1412,14 @@ static void aio_read_f(BlockBackend *blk, int argc,= char **argv) if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); - return; + return -EINVAL; } =20 gettimeofday(&ctx->t1, NULL); block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size, BLOCK_ACCT_READ); blk_aio_preadv(blk, ctx->offset, &ctx->qiov, 0, aio_read_done, ctx); + return 0; } =20 static void aio_write_help(void) @@ -1413,6 +1436,9 @@ static void aio_write_help(void) " filled with a set pattern (0xcdcdcdcd).\n" " The write is performed asynchronously and the aio_flush command must be\= n" " used to ensure all outstanding aio requests have been completed.\n" +" Note that due to its asynchronous nature, this command will be\n" +" considered successful once the request is submitted, independently\n" +" of potential I/O errors or pattern mismatches.\n" " -P, -- use different pattern to fill file\n" " -C, -- report statistics in a machine parsable format\n" " -f, -- use Force Unit Access semantics\n" @@ -1423,7 +1449,7 @@ static void aio_write_help(void) "\n"); } =20 -static void aio_write_f(BlockBackend *blk, int argc, char **argv); +static int aio_write_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t aio_write_cmd =3D { .name =3D "aio_write", @@ -1436,7 +1462,7 @@ static const cmdinfo_t aio_write_cmd =3D { .help =3D aio_write_help, }; =20 -static void aio_write_f(BlockBackend *blk, int argc, char **argv) +static int aio_write_f(BlockBackend *blk, int argc, char **argv) { int nr_iov, c; int pattern =3D 0xcd; @@ -1462,53 +1488,54 @@ static void aio_write_f(BlockBackend *blk, int argc= , char **argv) pattern =3D parse_pattern(optarg); if (pattern < 0) { g_free(ctx); - return; + return -EINVAL; } break; case 'i': printf("injecting invalid write request\n"); block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); - return; + return 0; case 'z': ctx->zflag =3D true; break; default: g_free(ctx); qemuio_command_usage(&aio_write_cmd); - return; + return -EINVAL; } } =20 if (optind > argc - 2) { g_free(ctx); qemuio_command_usage(&aio_write_cmd); - return; + return -EINVAL; } =20 if (ctx->zflag && optind !=3D argc - 2) { printf("-z supports only a single length parameter\n"); g_free(ctx); - return; + return -EINVAL; } =20 if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) { printf("-u requires -z to be specified\n"); g_free(ctx); - return; + return -EINVAL; } =20 if (ctx->zflag && ctx->Pflag) { printf("-z and -P cannot be specified at the same time\n"); g_free(ctx); - return; + return -EINVAL; } =20 ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { - print_cvtnum_err(ctx->offset, argv[optind]); + int ret =3D ctx->offset; + print_cvtnum_err(ret, argv[optind]); g_free(ctx); - return; + return ret; } optind++; =20 @@ -1517,7 +1544,7 @@ static void aio_write_f(BlockBackend *blk, int argc, = char **argv) if (count < 0) { print_cvtnum_err(count, argv[optind]); g_free(ctx); - return; + return count; } =20 ctx->qiov.size =3D count; @@ -1530,7 +1557,7 @@ static void aio_write_f(BlockBackend *blk, int argc, = char **argv) if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); - return; + return -EINVAL; } =20 gettimeofday(&ctx->t1, NULL); @@ -1540,14 +1567,17 @@ static void aio_write_f(BlockBackend *blk, int argc= , char **argv) blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, flags, aio_write_don= e, ctx); } + + return 0; } =20 -static void aio_flush_f(BlockBackend *blk, int argc, char **argv) +static int aio_flush_f(BlockBackend *blk, int argc, char **argv) { BlockAcctCookie cookie; block_acct_start(blk_get_stats(blk), &cookie, 0, BLOCK_ACCT_FLUSH); blk_drain_all(); block_acct_done(blk_get_stats(blk), &cookie); + return 0; } =20 static const cmdinfo_t aio_flush_cmd =3D { @@ -1556,9 +1586,9 @@ static const cmdinfo_t aio_flush_cmd =3D { .oneline =3D "completes all outstanding aio requests" }; =20 -static void flush_f(BlockBackend *blk, int argc, char **argv) +static int flush_f(BlockBackend *blk, int argc, char **argv) { - blk_flush(blk); + return blk_flush(blk); } =20 static const cmdinfo_t flush_cmd =3D { @@ -1568,7 +1598,7 @@ static const cmdinfo_t flush_cmd =3D { .oneline =3D "flush all in-core file state to disk", }; =20 -static void truncate_f(BlockBackend *blk, int argc, char **argv) +static int truncate_f(BlockBackend *blk, int argc, char **argv) { Error *local_err =3D NULL; int64_t offset; @@ -1577,14 +1607,16 @@ static void truncate_f(BlockBackend *blk, int argc,= char **argv) offset =3D cvtnum(argv[1]); if (offset < 0) { print_cvtnum_err(offset, argv[1]); - return; + return offset; } =20 ret =3D blk_truncate(blk, offset, PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); - return; + return ret; } + + return 0; } =20 static const cmdinfo_t truncate_cmd =3D { @@ -1598,7 +1630,7 @@ static const cmdinfo_t truncate_cmd =3D { .oneline =3D "truncates the current file at the given offset", }; =20 -static void length_f(BlockBackend *blk, int argc, char **argv) +static int length_f(BlockBackend *blk, int argc, char **argv) { int64_t size; char s1[64]; @@ -1606,11 +1638,12 @@ static void length_f(BlockBackend *blk, int argc, c= har **argv) size =3D blk_getlength(blk); if (size < 0) { printf("getlength: %s\n", strerror(-size)); - return; + return size; } =20 cvtstr(size, s1, sizeof(s1)); printf("%s\n", s1); + return 0; } =20 =20 @@ -1622,7 +1655,7 @@ static const cmdinfo_t length_cmd =3D { }; =20 =20 -static void info_f(BlockBackend *blk, int argc, char **argv) +static int info_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); BlockDriverInfo bdi; @@ -1639,7 +1672,7 @@ static void info_f(BlockBackend *blk, int argc, char = **argv) =20 ret =3D bdrv_get_info(bs, &bdi); if (ret) { - return; + return ret; } =20 cvtstr(bdi.cluster_size, s1, sizeof(s1)); @@ -1654,6 +1687,8 @@ static void info_f(BlockBackend *blk, int argc, char = **argv) bdrv_image_info_specific_dump(fprintf, stdout, spec_info); qapi_free_ImageInfoSpecific(spec_info); } + + return 0; } =20 =20 @@ -1680,7 +1715,7 @@ static void discard_help(void) "\n"); } =20 -static void discard_f(BlockBackend *blk, int argc, char **argv); +static int discard_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t discard_cmd =3D { .name =3D "discard", @@ -1694,7 +1729,7 @@ static const cmdinfo_t discard_cmd =3D { .help =3D discard_help, }; =20 -static void discard_f(BlockBackend *blk, int argc, char **argv) +static int discard_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false; @@ -1711,31 +1746,31 @@ static void discard_f(BlockBackend *blk, int argc, = char **argv) break; default: qemuio_command_usage(&discard_cmd); - return; + return -EINVAL; } } =20 if (optind !=3D argc - 2) { qemuio_command_usage(&discard_cmd); - return; + return -EINVAL; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } =20 optind++; bytes =3D cvtnum(argv[optind]); if (bytes < 0) { print_cvtnum_err(bytes, argv[optind]); - return; + return bytes; } else if (bytes >> BDRV_SECTOR_BITS > BDRV_REQUEST_MAX_SECTORS) { printf("length cannot exceed %"PRIu64", given %s\n", (uint64_t)BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS, argv[optind]); - return; + return -EINVAL; } =20 gettimeofday(&t1, NULL); @@ -1744,7 +1779,7 @@ static void discard_f(BlockBackend *blk, int argc, ch= ar **argv) =20 if (ret < 0) { printf("discard failed: %s\n", strerror(-ret)); - return; + return ret; } =20 /* Finally, report back -- -C gives a parsable format */ @@ -1752,9 +1787,11 @@ static void discard_f(BlockBackend *blk, int argc, c= har **argv) t2 =3D tsub(t2, t1); print_report("discard", &t2, offset, bytes, bytes, 1, Cflag); } + + return 0; } =20 -static void alloc_f(BlockBackend *blk, int argc, char **argv) +static int alloc_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); int64_t offset, start, remaining, count; @@ -1765,14 +1802,14 @@ static void alloc_f(BlockBackend *blk, int argc, ch= ar **argv) start =3D offset =3D cvtnum(argv[1]); if (offset < 0) { print_cvtnum_err(offset, argv[1]); - return; + return offset; } =20 if (argc =3D=3D 3) { count =3D cvtnum(argv[2]); if (count < 0) { print_cvtnum_err(count, argv[2]); - return; + return count; } } else { count =3D BDRV_SECTOR_SIZE; @@ -1784,7 +1821,7 @@ static void alloc_f(BlockBackend *blk, int argc, char= **argv) ret =3D bdrv_is_allocated(bs, offset, remaining, &num); if (ret < 0) { printf("is_allocated failed: %s\n", strerror(-ret)); - return; + return ret; } offset +=3D num; remaining -=3D num; @@ -1801,6 +1838,7 @@ static void alloc_f(BlockBackend *blk, int argc, char= **argv) =20 printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n", sum_alloc, count, s1); + return 0; } =20 static const cmdinfo_t alloc_cmd =3D { @@ -1846,7 +1884,7 @@ static int map_is_allocated(BlockDriverState *bs, int= 64_t offset, return firstret; } =20 -static void map_f(BlockBackend *blk, int argc, char **argv) +static int map_f(BlockBackend *blk, int argc, char **argv) { int64_t offset, bytes; char s1[64], s2[64]; @@ -1858,17 +1896,17 @@ static void map_f(BlockBackend *blk, int argc, char= **argv) bytes =3D blk_getlength(blk); if (bytes < 0) { error_report("Failed to query image length: %s", strerror(-bytes)); - return; + return bytes; } =20 while (bytes) { ret =3D map_is_allocated(blk_bs(blk), offset, bytes, &num); if (ret < 0) { error_report("Failed to get allocation status: %s", strerror(-= ret)); - return; + return ret; } else if (!num) { error_report("Unexpected end of image"); - return; + return -EIO; } =20 retstr =3D ret ? " allocated" : "not allocated"; @@ -1880,6 +1918,8 @@ static void map_f(BlockBackend *blk, int argc, char *= *argv) offset +=3D num; bytes -=3D num; } + + return 0; } =20 static const cmdinfo_t map_cmd =3D { @@ -1907,7 +1947,7 @@ static void reopen_help(void) "\n"); } =20 -static void reopen_f(BlockBackend *blk, int argc, char **argv); +static int reopen_f(BlockBackend *blk, int argc, char **argv); =20 static QemuOptsList reopen_opts =3D { .name =3D "reopen", @@ -1929,7 +1969,7 @@ static const cmdinfo_t reopen_cmd =3D { .help =3D reopen_help, }; =20 -static void reopen_f(BlockBackend *blk, int argc, char **argv) +static int reopen_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); QemuOpts *qopts; @@ -1947,19 +1987,19 @@ static void reopen_f(BlockBackend *blk, int argc, c= har **argv) case 'c': if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); - return; + return -EINVAL; } break; case 'o': if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) { qemu_opts_reset(&reopen_opts); - return; + return -EINVAL; } break; case 'r': if (has_rw_option) { error_report("Only one -r/-w option may be given"); - return; + return -EINVAL; } flags &=3D ~BDRV_O_RDWR; has_rw_option =3D true; @@ -1967,7 +2007,7 @@ static void reopen_f(BlockBackend *blk, int argc, cha= r **argv) case 'w': if (has_rw_option) { error_report("Only one -r/-w option may be given"); - return; + return -EINVAL; } flags |=3D BDRV_O_RDWR; has_rw_option =3D true; @@ -1975,14 +2015,14 @@ static void reopen_f(BlockBackend *blk, int argc, c= har **argv) default: qemu_opts_reset(&reopen_opts); qemuio_command_usage(&reopen_cmd); - return; + return -EINVAL; } } =20 if (optind !=3D argc) { qemu_opts_reset(&reopen_opts); qemuio_command_usage(&reopen_cmd); - return; + return -EINVAL; } =20 if (writethrough !=3D blk_enable_write_cache(blk) && @@ -1990,7 +2030,7 @@ static void reopen_f(BlockBackend *blk, int argc, cha= r **argv) { error_report("Cannot change cache.writeback: Device attached"); qemu_opts_reset(&reopen_opts); - return; + return -EBUSY; } =20 if (!(flags & BDRV_O_RDWR)) { @@ -2016,29 +2056,37 @@ static void reopen_f(BlockBackend *blk, int argc, c= har **argv) =20 if (local_err) { error_report_err(local_err); - } else { - blk_set_enable_write_cache(blk, !writethrough); + return -EINVAL; } + + blk_set_enable_write_cache(blk, !writethrough); + return 0; } =20 -static void break_f(BlockBackend *blk, int argc, char **argv) +static int break_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 ret =3D bdrv_debug_breakpoint(blk_bs(blk), argv[1], argv[2]); if (ret < 0) { printf("Could not set breakpoint: %s\n", strerror(-ret)); + return ret; } + + return 0; } =20 -static void remove_break_f(BlockBackend *blk, int argc, char **argv) +static int remove_break_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 ret =3D bdrv_debug_remove_breakpoint(blk_bs(blk), argv[1]); if (ret < 0) { printf("Could not remove breakpoint %s: %s\n", argv[1], strerror(-= ret)); + return ret; } + + return 0; } =20 static const cmdinfo_t break_cmd =3D { @@ -2060,14 +2108,17 @@ static const cmdinfo_t remove_break_cmd =3D { .oneline =3D "remove a breakpoint by tag", }; =20 -static void resume_f(BlockBackend *blk, int argc, char **argv) +static int resume_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 ret =3D bdrv_debug_resume(blk_bs(blk), argv[1]); if (ret < 0) { printf("Could not resume request: %s\n", strerror(-ret)); + return ret; } + + return 0; } =20 static const cmdinfo_t resume_cmd =3D { @@ -2079,11 +2130,12 @@ static const cmdinfo_t resume_cmd =3D { .oneline =3D "resumes the request tagged as tag", }; =20 -static void wait_break_f(BlockBackend *blk, int argc, char **argv) +static int wait_break_f(BlockBackend *blk, int argc, char **argv) { while (!bdrv_debug_is_suspended(blk_bs(blk), argv[1])) { aio_poll(blk_get_aio_context(blk), true); } + return 0; } =20 static const cmdinfo_t wait_break_cmd =3D { @@ -2095,7 +2147,7 @@ static const cmdinfo_t wait_break_cmd =3D { .oneline =3D "waits for the suspension of a request", }; =20 -static void abort_f(BlockBackend *blk, int argc, char **argv) +static int abort_f(BlockBackend *blk, int argc, char **argv) { abort(); } @@ -2121,7 +2173,7 @@ static void sigraise_help(void) "\n", SIGTERM); } =20 -static void sigraise_f(BlockBackend *blk, int argc, char **argv); +static int sigraise_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t sigraise_cmd =3D { .name =3D "sigraise", @@ -2134,16 +2186,16 @@ static const cmdinfo_t sigraise_cmd =3D { .help =3D sigraise_help, }; =20 -static void sigraise_f(BlockBackend *blk, int argc, char **argv) +static int sigraise_f(BlockBackend *blk, int argc, char **argv) { int64_t sig =3D cvtnum(argv[1]); if (sig < 0) { print_cvtnum_err(sig, argv[1]); - return; + return sig; } else if (sig > NSIG) { printf("signal argument '%s' is too large to be a valid signal\n", argv[1]); - return; + return -EINVAL; } =20 /* Using raise() to kill this process does not necessarily flush all o= pen @@ -2153,6 +2205,8 @@ static void sigraise_f(BlockBackend *blk, int argc, c= har **argv) fflush(stderr); =20 raise(sig); + + return 0; } =20 static void sleep_cb(void *opaque) @@ -2161,7 +2215,7 @@ static void sleep_cb(void *opaque) *expired =3D true; } =20 -static void sleep_f(BlockBackend *blk, int argc, char **argv) +static int sleep_f(BlockBackend *blk, int argc, char **argv) { char *endptr; long ms; @@ -2171,7 +2225,7 @@ static void sleep_f(BlockBackend *blk, int argc, char= **argv) ms =3D strtol(argv[1], &endptr, 0); if (ms < 0 || *endptr !=3D '\0') { printf("%s is not a valid number\n", argv[1]); - return; + return -EINVAL; } =20 timer =3D timer_new_ns(QEMU_CLOCK_HOST, sleep_cb, &expired); @@ -2182,6 +2236,7 @@ static void sleep_f(BlockBackend *blk, int argc, char= **argv) } =20 timer_free(timer); + return 0; } =20 static const cmdinfo_t sleep_cmd =3D { @@ -2228,22 +2283,23 @@ static void help_all(void) printf("\nUse 'help commandname' for extended help.\n"); } =20 -static void help_f(BlockBackend *blk, int argc, char **argv) +static int help_f(BlockBackend *blk, int argc, char **argv) { const cmdinfo_t *ct; =20 if (argc =3D=3D 1) { help_all(); - return; + return 0; } =20 ct =3D find_command(argv[1]); if (ct =3D=3D NULL) { printf("command %s not found\n", argv[1]); - return; + return -EINVAL; } =20 help_onecmd(argv[1], ct); + return 0; } =20 static const cmdinfo_t help_cmd =3D { @@ -2257,13 +2313,14 @@ static const cmdinfo_t help_cmd =3D { .oneline =3D "help for one or all commands", }; =20 -void qemuio_command(BlockBackend *blk, const char *cmd) +int qemuio_command(BlockBackend *blk, const char *cmd) { AioContext *ctx; char *input; const cmdinfo_t *ct; char **v; int c; + int ret =3D 0; =20 input =3D g_strdup(cmd); v =3D breakline(input, &c); @@ -2272,14 +2329,17 @@ void qemuio_command(BlockBackend *blk, const char *= cmd) if (ct) { ctx =3D blk ? blk_get_aio_context(blk) : qemu_get_aio_context(= ); aio_context_acquire(ctx); - command(blk, ct, c, v); + ret =3D command(blk, ct, c, v); aio_context_release(ctx); } else { fprintf(stderr, "command \"%s\" not found\n", v[0]); + ret =3D -EINVAL; } } g_free(input); g_free(v); + + return ret; } =20 static void __attribute((constructor)) init_qemuio_commands(void) diff --git a/qemu-io.c b/qemu-io.c index 4578ccfaa5..e82dd0b999 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -66,10 +66,11 @@ static int get_eof_char(void) #endif } =20 -static void close_f(BlockBackend *blk, int argc, char **argv) +static int close_f(BlockBackend *blk, int argc, char **argv) { blk_unref(qemuio_blk); qemuio_blk =3D NULL; + return 0; } =20 static const cmdinfo_t close_cmd =3D { @@ -136,7 +137,7 @@ static void open_help(void) "\n"); } =20 -static void open_f(BlockBackend *blk, int argc, char **argv); +static int open_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t open_cmd =3D { .name =3D "open", @@ -160,12 +161,13 @@ static QemuOptsList empty_opts =3D { }, }; =20 -static void open_f(BlockBackend *blk, int argc, char **argv) +static int open_f(BlockBackend *blk, int argc, char **argv) { int flags =3D BDRV_O_UNMAP; int readonly =3D 0; bool writethrough =3D true; int c; + int ret; QemuOpts *qopts; QDict *opts; bool force_share =3D false; @@ -192,25 +194,25 @@ static void open_f(BlockBackend *blk, int argc, char = **argv) if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } break; case 'd': if (bdrv_parse_discard_flags(optarg, &flags) < 0) { error_report("Invalid discard option: %s", optarg); qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } break; case 'o': if (imageOpts) { printf("--image-opts and 'open -o' are mutually exclusive\= n"); qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) { qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } break; case 'U': @@ -219,7 +221,7 @@ static void open_f(BlockBackend *blk, int argc, char **= argv) default: qemu_opts_reset(&empty_opts); qemuio_command_usage(&open_cmd); - return; + return -EINVAL; } } =20 @@ -230,7 +232,7 @@ static void open_f(BlockBackend *blk, int argc, char **= argv) if (imageOpts && (optind =3D=3D argc - 1)) { if (!qemu_opts_parse_noisily(&empty_opts, argv[optind], false)) { qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } optind++; } @@ -240,18 +242,26 @@ static void open_f(BlockBackend *blk, int argc, char = **argv) qemu_opts_reset(&empty_opts); =20 if (optind =3D=3D argc - 1) { - openfile(argv[optind], flags, writethrough, force_share, opts); + ret =3D openfile(argv[optind], flags, writethrough, force_share, o= pts); } else if (optind =3D=3D argc) { - openfile(NULL, flags, writethrough, force_share, opts); + ret =3D openfile(NULL, flags, writethrough, force_share, opts); } else { QDECREF(opts); qemuio_command_usage(&open_cmd); + return -EINVAL; + } + + if (ret) { + return -EINVAL; } + + return 0; } =20 -static void quit_f(BlockBackend *blk, int argc, char **argv) +static int quit_f(BlockBackend *blk, int argc, char **argv) { quit_qemu_io =3D true; + return 0; } =20 static const cmdinfo_t quit_cmd =3D { --=20 2.14.3 From nobody Wed Oct 29 06:51:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524926642990603.9005137158634; Sat, 28 Apr 2018 07:44:02 -0700 (PDT) Received: from localhost ([::1]:52350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR50-0005I0-7v for importer@patchew.org; Sat, 28 Apr 2018 10:44:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR2j-0003tx-PG for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCR2i-0004kt-Hj for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37536 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fCR2g-0004h1-1i; Sat, 28 Apr 2018 10:41:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96BD8406C756; Sat, 28 Apr 2018 14:41:37 +0000 (UTC) Received: from localhost (ovpn-204-56.brq.redhat.com [10.40.204.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2AF27111F3DE; Sat, 28 Apr 2018 14:41:37 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 28 Apr 2018 16:41:21 +0200 Message-Id: <20180428144123.30333-4-mreitz@redhat.com> In-Reply-To: <20180428144123.30333-1-mreitz@redhat.com> References: <20180428144123.30333-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 28 Apr 2018 14:41:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 28 Apr 2018 14:41:37 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 3/5] qemu-io: Exit with error when a command failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, qemu-io basically always returns success when it gets to interactive mode (so once the whole command line has been parsed; even before the commands on the command line are interpreted). That is not very useful. This patch makes qemu-io return failure when any of the executed commands failed. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1519617 Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qemu-io.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index e82dd0b999..c95886d22a 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -400,17 +400,21 @@ static void prep_fetchline(void *opaque) *fetchable=3D 1; } =20 -static void command_loop(void) +static int command_loop(void) { int i, fetchable =3D 0, prompted =3D 0; + int ret, last_error =3D 0; char *input; =20 for (i =3D 0; !quit_qemu_io && i < ncmdline; i++) { - qemuio_command(qemuio_blk, cmdline[i]); + ret =3D qemuio_command(qemuio_blk, cmdline[i]); + if (ret < 0) { + last_error =3D ret; + } } if (cmdline) { g_free(cmdline); - return; + return last_error; } =20 while (!quit_qemu_io) { @@ -431,13 +435,19 @@ static void command_loop(void) if (input =3D=3D NULL) { break; } - qemuio_command(qemuio_blk, input); + ret =3D qemuio_command(qemuio_blk, input); g_free(input); =20 + if (ret < 0) { + last_error =3D ret; + } + prompted =3D 0; fetchable =3D 0; } qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL); + + return last_error; } =20 static void add_user_command(char *optarg) @@ -502,6 +512,7 @@ int main(int argc, char **argv) int c; int opt_index =3D 0; int flags =3D BDRV_O_UNMAP; + int ret; bool writethrough =3D true; Error *local_error =3D NULL; QDict *opts =3D NULL; @@ -663,7 +674,7 @@ int main(int argc, char **argv) } } } - command_loop(); + ret =3D command_loop(); =20 /* * Make sure all outstanding requests complete before the program exit= s. @@ -672,5 +683,10 @@ int main(int argc, char **argv) =20 blk_unref(qemuio_blk); g_free(readline_state); - return 0; + + if (ret < 0) { + return 1; + } else { + return 0; + } } --=20 2.14.3 From nobody Wed Oct 29 06:51:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524926639812804.3568663321258; Sat, 28 Apr 2018 07:43:59 -0700 (PDT) Received: from localhost ([::1]:52349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR4s-0005D1-Do for importer@patchew.org; Sat, 28 Apr 2018 10:43:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR2k-0003um-OE for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCR2j-0004nk-Vs for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:42 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34814 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fCR2i-0004jr-2x; Sat, 28 Apr 2018 10:41:40 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AB32A2021; Sat, 28 Apr 2018 14:41:39 +0000 (UTC) Received: from localhost (ovpn-204-56.brq.redhat.com [10.40.204.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 439687C50; Sat, 28 Apr 2018 14:41:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 28 Apr 2018 16:41:22 +0200 Message-Id: <20180428144123.30333-5-mreitz@redhat.com> In-Reply-To: <20180428144123.30333-1-mreitz@redhat.com> References: <20180428144123.30333-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Sat, 28 Apr 2018 14:41:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Sat, 28 Apr 2018 14:41:39 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 4/5] iotests.py: Add qemu_io_silent X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With qemu-io now returning a useful exit code, some tests may find it sufficient to just query that instead of logging (and filtering) the whole output. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/iotests.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index b25d48a91b..9747ca9eba 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -119,6 +119,15 @@ def qemu_io(*args): sys.stderr.write('qemu-io received signal %i: %s\n' % (-exitcode, = ' '.join(args))) return subp.communicate()[0] =20 +def qemu_io_silent(*args): + '''Run qemu-io and return the exit code, suppressing stdout''' + args =3D qemu_io_args + list(args) + exitcode =3D subprocess.call(args, stdout=3Dopen('/dev/null', 'w')) + if exitcode < 0: + sys.stderr.write('qemu-io received signal %i: %s\n' % + (-exitcode, ' '.join(args))) + return exitcode + =20 class QemuIoInteractive: def __init__(self, *args): --=20 2.14.3 From nobody Wed Oct 29 06:51:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152492680211867.78146159669109; Sat, 28 Apr 2018 07:46:42 -0700 (PDT) Received: from localhost ([::1]:52369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR7Z-0007kV-Bi for importer@patchew.org; Sat, 28 Apr 2018 10:46:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCR2r-00041v-8p for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCR2m-0004qy-Cf for qemu-devel@nongnu.org; Sat, 28 Apr 2018 10:41:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46168 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fCR2k-0004nS-2s; Sat, 28 Apr 2018 10:41:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4E6F427361D; Sat, 28 Apr 2018 14:41:41 +0000 (UTC) Received: from localhost (ovpn-204-56.brq.redhat.com [10.40.204.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 509EA2166BCC; Sat, 28 Apr 2018 14:41:41 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 28 Apr 2018 16:41:23 +0200 Message-Id: <20180428144123.30333-6-mreitz@redhat.com> In-Reply-To: <20180428144123.30333-1-mreitz@redhat.com> References: <20180428144123.30333-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sat, 28 Apr 2018 14:41:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sat, 28 Apr 2018 14:41:41 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 5/5] iotests: Let 216 make use of qemu-io's exit code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As a showcase of how you can use qemu-io's exit code to determine success or failure (same for qemu-img), this test is changed to use qemu_io_silent() instead of qemu_io(), and to assert the exit code instead of logging the filtered result. One real advantage of this is that in case of an error, you get a backtrace that helps you locate the issue in the test file quickly. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/216 | 23 ++++++++++++----------- tests/qemu-iotests/216.out | 17 ++--------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/tests/qemu-iotests/216 b/tests/qemu-iotests/216 index b362cf93a8..072707449d 100755 --- a/tests/qemu-iotests/216 +++ b/tests/qemu-iotests/216 @@ -22,7 +22,7 @@ # Non-shared storage migration test using NBD server and drive-mirror =20 import iotests -from iotests import log, qemu_img_pipe, qemu_io, filter_qemu_io +from iotests import log, qemu_img, qemu_io_silent =20 # Need backing file support iotests.verify_image_format(supported_fmts=3D['qcow2', 'qcow', 'qed', 'vmd= k']) @@ -52,14 +52,13 @@ with iotests.FilePath('base.img') as base_img_path, \ log('--- Setting up images ---') log('') =20 - qemu_img_pipe('create', '-f', iotests.imgfmt, base_img_path, '64M') + assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') = =3D=3D 0 + assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') =3D=3D 0 + assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, + top_img_path) =3D=3D 0 + assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') =3D=3D 0 =20 - log(filter_qemu_io(qemu_io(base_img_path, '-c', 'write -P 1 0M 1M'))) - - qemu_img_pipe('create', '-f', iotests.imgfmt, '-b', base_img_path, - top_img_path) - - log(filter_qemu_io(qemu_io(top_img_path, '-c', 'write -P 2 1M 1M'))) + log('Done') =20 log('') log('--- Doing COR ---') @@ -112,6 +111,8 @@ with iotests.FilePath('base.img') as base_img_path, \ log('--- Checking COR result ---') log('') =20 - log(filter_qemu_io(qemu_io(base_img_path, '-c', 'discard 0 64M'))) - log(filter_qemu_io(qemu_io(top_img_path, '-c', 'read -P 1 0M 1M'))) - log(filter_qemu_io(qemu_io(top_img_path, '-c', 'read -P 2 1M 1M'))) + assert qemu_io_silent(base_img_path, '-c', 'discard 0 64M') =3D=3D 0 + assert qemu_io_silent(top_img_path, '-c', 'read -P 1 0M 1M') =3D=3D 0 + assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') =3D=3D 0 + + log('Done') diff --git a/tests/qemu-iotests/216.out b/tests/qemu-iotests/216.out index d3fc590d29..45ea857ee1 100644 --- a/tests/qemu-iotests/216.out +++ b/tests/qemu-iotests/216.out @@ -3,12 +3,7 @@ =20 --- Setting up images --- =20 -wrote 1048576/1048576 bytes at offset 0 -1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -wrote 1048576/1048576 bytes at offset 1048576 -1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - +Done =20 --- Doing COR --- =20 @@ -17,12 +12,4 @@ wrote 1048576/1048576 bytes at offset 1048576 =20 --- Checking COR result --- =20 -discard 67108864/67108864 bytes at offset 0 -64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -read 1048576/1048576 bytes at offset 0 -1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -read 1048576/1048576 bytes at offset 1048576 -1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - +Done --=20 2.14.3