From nobody Tue Aug 25 03:44:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1779313914; cv=none; d=zohomail.com; s=zohoarc; b=KDFvqch9rXgqwp4oiMOwM4zq43a8XynajyFQLjCYN7IA7C2na/HtR7f7eSR77bUhOAEeLzRSq0j8RwFlLlKj/d9y35wHAep3UKEj4gsVY4CopmTeuzmAgwcoXdY2xikLxEGOyqNKeX7+JZLycpRKUrVFFg+uXmhoRvfmner2gxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779313914; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=q7GvvRPQTRKT8Kaje+f0v9Wy2HvsIqFzenfS/N58Q5o=; b=DqGOAFftNTM6pphEOxaLa0YZDQp1o9FaPo6mv78s+P7EhR9hRcpZC1Mf0dLpveGI9ewiPTRe1rz0q6ZnabKCUvyaJ3WL+BZOlqeCVKXkGQo4ILXriRBvaGPOPrwxYqhyoxyeP2EnaxwDiuk4CP3/GIezKcUAlrM4wR8h0H//2/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779313914929815.1745166561949; Wed, 20 May 2026 14:51:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wPopL-0001gI-Ei; Wed, 20 May 2026 17:51:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wPopK-0001UM-8G for qemu-devel@nongnu.org; Wed, 20 May 2026 17:51:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wPopE-0004Uo-JJ for qemu-devel@nongnu.org; Wed, 20 May 2026 17:51:41 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-114-ob6qK24GNE6H13tFGv_ODA-1; Wed, 20 May 2026 17:51:33 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 151241800451 for ; Wed, 20 May 2026 21:51:33 +0000 (UTC) Received: from localhost (unknown [10.44.24.26]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 156401685; Wed, 20 May 2026 21:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779313896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q7GvvRPQTRKT8Kaje+f0v9Wy2HvsIqFzenfS/N58Q5o=; b=dZLGQ4IacJU+F4BkwEklVW6qg4Fu7W4TyxgVxEp4o6T8+AclRaHzzTidFqObwLj47rcXAs Ajh8ZiphzBiBi8nivNHJfdlz9HuxcmuJVlC1Y6MkKRepA22npaGg3ibJe9RrMEXi0WtlRZ R59WzV6jaeIHF+nixy9aUdr+7snpG1o= X-MC-Unique: ob6qK24GNE6H13tFGv_ODA-1 X-Mimecast-MFC-AGG-ID: ob6qK24GNE6H13tFGv_ODA_1779313893 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 21 May 2026 01:49:15 +0400 Subject: [PATCH 14/40] qemu-io: propagate errors through Error API instead of printf MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-qemu-no-hmp-v1-14-d104f809e145@redhat.com> References: <20260521-qemu-no-hmp-v1-0-d104f809e145@redhat.com> In-Reply-To: <20260521-qemu-no-hmp-v1-0-d104f809e145@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=103176; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=GzLfhQALNps/ir3QBbcOMLk4C16QnmT1WpBPIlVEkTI=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqDiyDBl/LcLYY0Occ13ipS0JYpill+gmnSRXjE PGFy66zvFKJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCag4sgwAKCRDa6OEJdZac 5Sf4EACOxhk+1RRVa9PzNMvaMtwk/AjTuwLXt7UCnRVQxCU+qiEzRcZCtXjbab7CpIeTdZg/2NH UuAcfGg4UQ/ZTIlE0/Yfy+b4Ng8YOf1nUbKqnj+kLT7MDJKkv49ufetSO645FVbcbYd6sO7OGcZ rOo1+ZiSGLhb0xrWMQfJXhbj7mncz4p4y1urruvuvMH5YSyl/tzGYQ3zlkzOqfs4i1RDUHr9Lfo COCCSm0bvG+LMjnVWMzApw/ezY5jdOrkNBDMmKMXlxv5t+FJsBp+34SxbvBkq8vs/DnrdY9ezlj OrnUqXX5NHQW34fI5wMlcgFITkFdwUAbGE4hAcliitHRV+g+W+TN1jgmHt/kj/+0ZFY2aQmY+KG fbeosQOHTieRUNZZR7QkE4mKz2gT3hkZHxu+yhocXhYZM2Mke3Yg4v+Fl8VvjxIWcHZEd/CS3PH Y/5v5EjicCWaPtoHiaizbdEhpsylsP0A3vetF4Nywlsl5rJnQSdtyUAeMYIQbU52AG2DQG6xLY1 4ZQpWugzhV6u5TtbovFLrur6YHwcGHuzV2jjTQ+OKPM3I0QboxH1vn2vLso9uqDaFg/EzgKaPte c0zM2I6JKwk3ktzCIOq7aQ7CRPjKGSzWNZ+tF2ldV+1Hx1Dr9N4eCX5/qRy2/KamJCjZcqMK6sx XZuux65medZ0nhA== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1779313916754154100 Convert the qemu-io command infrastructure to use QEMU's Error API (Error **errp) for error propagation instead of printing directly to stdout/stderr via printf/fprintf. The cfunc_t typedef, all ~35 command functions, the dispatcher chain (command/init_check_command/qemuio_command), and helper functions (parse_pattern, create_iovec, qemu_io_alloc_from_file) all gain an Error **errp parameter. Async completion callbacks (aio_read_done, aio_write_done, aio_discard_done) use error_report() since they have no Error path back to the caller. Update tests: - error_report_err() prepends qemu-io: prefix - copy-before-write: check the HMP return value, rather than stdio - other tests: update to check JSON {"return": "Error: error text"} Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu-io.h | 4 +- block/monitor/block-hmp-cmds.c | 2 +- qemu-io-cmds.c | 426 +++++++++++++++----------= ---- qemu-io.c | 17 +- tests/qemu-iotests/004.out | 20 +- tests/qemu-iotests/021.out | 60 ++-- tests/qemu-iotests/060.out | 44 ++- tests/qemu-iotests/071.out | 10 +- tests/qemu-iotests/072.out | 2 +- tests/qemu-iotests/080.out | 4 +- tests/qemu-iotests/089.out | 4 +- tests/qemu-iotests/114.out | 2 +- tests/qemu-iotests/134.out | 2 +- tests/qemu-iotests/137.out | 2 +- tests/qemu-iotests/171 | 2 +- tests/qemu-iotests/171.out | 68 ++--- tests/qemu-iotests/214.out | 2 +- tests/qemu-iotests/220.out | 2 +- tests/qemu-iotests/244.out | 12 +- tests/qemu-iotests/249.out | 6 +- tests/qemu-iotests/271.out | 14 +- tests/qemu-iotests/tests/copy-before-write | 66 +++-- 22 files changed, 404 insertions(+), 367 deletions(-) diff --git a/include/qemu-io.h b/include/qemu-io.h index 3af513004a6..240764bb35c 100644 --- a/include/qemu-io.h +++ b/include/qemu-io.h @@ -25,7 +25,7 @@ * Operate on @blk using @argc/@argv as the command's arguments, and * return 0 on success or negative errno on failure. */ -typedef int (*cfunc_t)(BlockBackend *blk, int argc, char **argv); +typedef int (*cfunc_t)(BlockBackend *blk, int argc, char **argv, Error **e= rrp); =20 typedef void (*helpfunc_t)(void); =20 @@ -45,7 +45,7 @@ typedef struct cmdinfo { =20 extern bool qemuio_misalign; =20 -int qemuio_command(BlockBackend *blk, const char *cmd); +int qemuio_command(BlockBackend *blk, const char *cmd, Error **errp); =20 void qemuio_add_command(const cmdinfo_t *ci); void qemuio_command_usage(const cmdinfo_t *ci); diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 69ade0534f1..c7113b8ea5e 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -608,7 +608,7 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) * extended, possibly resulting in a read-only guest device keeping wr= ite * permissions. Ugly, but it appears to be the lesser evil. */ - qemuio_command(blk, command); + qemuio_command(blk, command, &err); =20 fail: blk_unref(local_blk); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index de4c1966fea..5093aa4169a 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -55,40 +55,43 @@ void qemuio_command_usage(const cmdinfo_t *ci) printf("%s %s -- %s\n", ci->name, ci->args, ci->oneline); } =20 -static int init_check_command(BlockBackend *blk, const cmdinfo_t *ct) +static int init_check_command(BlockBackend *blk, const cmdinfo_t *ct, + Error **errp) { if (ct->flags & CMD_FLAG_GLOBAL) { return 1; } if (!(ct->flags & CMD_NOFILE_OK) && !blk) { - fprintf(stderr, "no file open, try 'help open'\n"); + error_setg(errp, "no file open, try 'help open'"); return 0; } return 1; } =20 static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc, - char **argv) + char **argv, Error **errp) { char *cmd =3D argv[0]; =20 - if (!init_check_command(blk, ct)) { + if (!init_check_command(blk, ct, errp)) { return -EINVAL; } =20 if (argc - 1 < ct->argmin || (ct->argmax !=3D -1 && argc - 1 > ct->arg= max)) { if (ct->argmax =3D=3D -1) { - fprintf(stderr, - "bad argument count %d to %s, expected at least %d arg= uments\n", - argc-1, cmd, ct->argmin); + error_setg(errp, + "bad argument count %d to %s," + " expected at least %d arguments", + argc - 1, cmd, ct->argmin); } else if (ct->argmin =3D=3D ct->argmax) { - fprintf(stderr, - "bad argument count %d to %s, expected %d arguments\n", - argc-1, cmd, ct->argmin); + error_setg(errp, + "bad argument count %d to %s, expected %d arguments= ", + argc - 1, cmd, ct->argmin); } else { - fprintf(stderr, - "bad argument count %d to %s, expected between %d and = %d arguments\n", - argc-1, cmd, ct->argmin, ct->argmax); + error_setg(errp, + "bad argument count %d to %s," + " expected between %d and %d arguments", + argc - 1, cmd, ct->argmin, ct->argmax); } return -EINVAL; } @@ -112,21 +115,19 @@ static int command(BlockBackend *blk, const cmdinfo_t= *ct, int argc, =20 if (ct->perm & ~orig_perm) { uint64_t new_perm; - Error *local_err =3D NULL; int ret; =20 new_perm =3D orig_perm | ct->perm; =20 - ret =3D blk_set_perm(blk, new_perm, orig_shared_perm, &local_e= rr); + ret =3D blk_set_perm(blk, new_perm, orig_shared_perm, errp); if (ret < 0) { - error_report_err(local_err); return ret; } } } =20 qemu_reset_optind(); - return ct->cfunc(blk, argc, argv); + return ct->cfunc(blk, argc, argv, errp); } =20 static const cmdinfo_t *find_command(const char *cmd) @@ -192,18 +193,18 @@ static int64_t cvtnum(const char *s) return value; } =20 -static void print_cvtnum_err(int64_t rc, const char *arg) +static void set_cvtnum_err(int64_t rc, const char *arg, Error **errp) { switch (rc) { case -EINVAL: - printf("Parsing error: non-numeric argument," - " or extraneous/unrecognized suffix -- %s\n", arg); + error_setg(errp, "Parsing error: non-numeric argument," + " or extraneous/unrecognized suffix -- %s", arg); break; case -ERANGE: - printf("Parsing error: argument too large -- %s\n", arg); + error_setg(errp, "Parsing error: argument too large -- %s", arg); break; default: - printf("Parsing error: %s\n", arg); + error_setg(errp, "Parsing error: %s", arg); } } =20 @@ -316,14 +317,14 @@ static void timestr(struct timespec *tv, char *ts, si= ze_t size, int format) * Because the pattern is used as an argument to memset it must evaluate * to an unsigned integer that fits into a single byte. */ -static int parse_pattern(const char *arg) +static int parse_pattern(const char *arg, Error **errp) { char *endptr =3D NULL; long pattern; =20 pattern =3D strtol(arg, &endptr, 0); if (pattern < 0 || pattern > UCHAR_MAX || *endptr !=3D '\0') { - printf("%s is not a valid pattern byte\n", arg); + error_setg(errp, "%s is not a valid pattern byte", arg); return -1; } =20 @@ -386,7 +387,8 @@ static void qemu_io_free(BlockBackend *blk, void *p, si= ze_t len, * NULL on error */ static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len, - const char *file_name, bool register_= buf) + const char *file_name, bool register_= buf, + Error **errp) { size_t alloc_len =3D len + (qemuio_misalign ? MISALIGN_OFFSET : 0); char *alloc_buf, *buf, *end; @@ -394,7 +396,7 @@ static void *qemu_io_alloc_from_file(BlockBackend *blk,= size_t len, int pattern_len; =20 if (!f) { - perror(file_name); + error_setg_errno(errp, errno, "%s", file_name); return NULL; } =20 @@ -407,12 +409,12 @@ static void *qemu_io_alloc_from_file(BlockBackend *bl= k, size_t len, pattern_len =3D fread(buf, 1, len, f); =20 if (ferror(f)) { - perror(file_name); + error_setg_errno(errp, errno, "%s", file_name); goto error; } =20 if (pattern_len =3D=3D 0) { - fprintf(stderr, "%s: file is empty\n", file_name); + error_setg(errp, "%s: file is empty", file_name); goto error; } =20 @@ -494,7 +496,7 @@ static void print_report(const char *op, struct timespe= c *t, int64_t offset, */ static void * create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_io= v, - int pattern, bool register_buf) + int pattern, bool register_buf, Error **errp) { size_t *sizes =3D g_new0(size_t, nr_iov); size_t count =3D 0; @@ -508,19 +510,20 @@ create_iovec(BlockBackend *blk, QEMUIOVector *qiov, c= har **argv, int nr_iov, =20 len =3D cvtnum(arg); if (len < 0) { - print_cvtnum_err(len, arg); + set_cvtnum_err(len, arg, errp); goto fail; } =20 if (len > BDRV_REQUEST_MAX_BYTES) { - printf("Argument '%s' exceeds maximum size %" PRIu64 "\n", arg, - (uint64_t)BDRV_REQUEST_MAX_BYTES); + error_setg(errp, "Argument '%s' exceeds maximum size %" PRIu64, + arg, (uint64_t)BDRV_REQUEST_MAX_BYTES); goto fail; } =20 if (count > BDRV_REQUEST_MAX_BYTES - len) { - printf("The total number of bytes exceed the maximum size %" P= RIu64 - "\n", (uint64_t)BDRV_REQUEST_MAX_BYTES); + error_setg(errp, + "The total number of bytes exceed the maximum size = %" + PRIu64, (uint64_t)BDRV_REQUEST_MAX_BYTES); goto fail; } =20 @@ -692,7 +695,7 @@ static void read_help(void) "\n"); } =20 -static int read_f(BlockBackend *blk, int argc, char **argv); +static int read_f(BlockBackend *blk, int argc, char **argv, Error **errp); =20 static const cmdinfo_t read_cmd =3D { .name =3D "read", @@ -705,7 +708,7 @@ static const cmdinfo_t read_cmd =3D { .help =3D read_help, }; =20 -static int read_f(BlockBackend *blk, int argc, char **argv) +static int read_f(BlockBackend *blk, int argc, char **argv, Error **errp) { struct timespec t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; @@ -732,7 +735,7 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) lflag =3D true; pattern_count =3D cvtnum(optarg); if (pattern_count < 0) { - print_cvtnum_err(pattern_count, optarg); + set_cvtnum_err(pattern_count, optarg, errp); return pattern_count; } break; @@ -741,7 +744,7 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) break; case 'P': Pflag =3D true; - pattern =3D parse_pattern(optarg); + pattern =3D parse_pattern(optarg, errp); if (pattern < 0) { return -EINVAL; } @@ -756,7 +759,7 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) sflag =3D true; pattern_offset =3D cvtnum(optarg); if (pattern_offset < 0) { - print_cvtnum_err(pattern_offset, optarg); + set_cvtnum_err(pattern_offset, optarg, errp); return pattern_offset; } break; @@ -776,18 +779,18 @@ static int read_f(BlockBackend *blk, int argc, char *= *argv) =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { - print_cvtnum_err(count, argv[optind]); + set_cvtnum_err(count, argv[optind], errp); 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]); + error_setg(errp, "length cannot exceed %" PRIu64 ", given %s", + (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); return -EINVAL; } =20 @@ -801,24 +804,26 @@ 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"); + error_setg(errp, "pattern verification range exceeds end of read d= ata"); 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); + error_setg(errp, + "%" PRId64 " is not a sector-aligned value for 'off= set'", + offset); return -EINVAL; } if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { - printf("%"PRId64" is not a sector-aligned value for 'count'\n", - count); + error_setg(errp, + "%" PRId64 " is not a sector-aligned value for 'cou= nt'", + count); return -EINVAL; } if (flags & BDRV_REQ_REGISTERED_BUF) { - printf("I/O buffer registration is not supported when reading " - "from vmstate\n"); + error_setg(errp, "I/O buffer registration is not supported whe= n" + " reading from vmstate"); return -EINVAL; } } @@ -834,7 +839,7 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) clock_gettime(CLOCK_MONOTONIC, &t2); =20 if (ret < 0) { - printf("read failed: %s\n", strerror(-ret)); + error_setg(errp, "read failed: %s", strerror(-ret)); goto out; } cnt =3D ret; @@ -845,9 +850,9 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) void *cmp_buf =3D g_malloc(pattern_count); memset(cmp_buf, pattern, pattern_count); if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) { - printf("Pattern verification failed at offset %" - PRId64 ", %"PRId64" bytes\n", - offset + pattern_offset, pattern_count); + error_setg(errp, "Pattern verification failed at offset %" + PRId64 ", %" PRId64 " bytes", + offset + pattern_offset, pattern_count); ret =3D -EINVAL; } g_free(cmp_buf); @@ -890,7 +895,7 @@ static void readv_help(void) "\n"); } =20 -static int readv_f(BlockBackend *blk, int argc, char **argv); +static int readv_f(BlockBackend *blk, int argc, char **argv, Error **errp); =20 static const cmdinfo_t readv_cmd =3D { .name =3D "readv", @@ -902,7 +907,7 @@ static const cmdinfo_t readv_cmd =3D { .help =3D readv_help, }; =20 -static int readv_f(BlockBackend *blk, int argc, char **argv) +static int readv_f(BlockBackend *blk, int argc, char **argv, Error **errp) { struct timespec t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; @@ -924,7 +929,7 @@ static int readv_f(BlockBackend *blk, int argc, char **= argv) break; case 'P': Pflag =3D true; - pattern =3D parse_pattern(optarg); + pattern =3D parse_pattern(optarg, errp); if (pattern < 0) { return -EINVAL; } @@ -952,14 +957,14 @@ static int readv_f(BlockBackend *blk, int argc, char = **argv) =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab, - flags & BDRV_REQ_REGISTERED_BUF); + flags & BDRV_REQ_REGISTERED_BUF, errp); if (buf =3D=3D NULL) { return -EINVAL; } @@ -969,7 +974,7 @@ static int readv_f(BlockBackend *blk, int argc, char **= argv) clock_gettime(CLOCK_MONOTONIC, &t2); =20 if (ret < 0) { - printf("readv failed: %s\n", strerror(-ret)); + error_setg(errp, "readv failed: %s", strerror(-ret)); goto out; } cnt =3D ret; @@ -980,8 +985,8 @@ static int readv_f(BlockBackend *blk, int argc, char **= argv) void *cmp_buf =3D g_malloc(qiov.size); memset(cmp_buf, pattern, qiov.size); if (memcmp(buf, cmp_buf, qiov.size)) { - printf("Pattern verification failed at offset %" - PRId64 ", %zu bytes\n", offset, qiov.size); + error_setg(errp, "Pattern verification failed at offset %" + PRId64 ", %zu bytes", offset, qiov.size); ret =3D -EINVAL; } g_free(cmp_buf); @@ -1031,7 +1036,7 @@ static void write_help(void) "\n"); } =20 -static int write_f(BlockBackend *blk, int argc, char **argv); +static int write_f(BlockBackend *blk, int argc, char **argv, Error **errp); =20 static const cmdinfo_t write_cmd =3D { .name =3D "write", @@ -1045,7 +1050,7 @@ static const cmdinfo_t write_cmd =3D { .help =3D write_help, }; =20 -static int write_f(BlockBackend *blk, int argc, char **argv) +static int write_f(BlockBackend *blk, int argc, char **argv, Error **errp) { struct timespec t1, t2; bool Cflag =3D false, qflag =3D false, bflag =3D false; @@ -1082,7 +1087,7 @@ static int write_f(BlockBackend *blk, int argc, char = **argv) break; case 'P': Pflag =3D true; - pattern =3D parse_pattern(optarg); + pattern =3D parse_pattern(optarg, errp); if (pattern < 0) { return -EINVAL; } @@ -1115,72 +1120,78 @@ static int write_f(BlockBackend *blk, int argc, cha= r **argv) } =20 if (bflag && zflag) { - printf("-b and -z cannot be specified at the same time\n"); + error_setg(errp, "-b and -z cannot be specified at the same time"); return -EINVAL; } =20 if ((flags & BDRV_REQ_FUA) && (bflag || cflag)) { - printf("-f and -b or -c cannot be specified at the same time\n"); + error_setg(errp, + "-f and -b or -c cannot be specified at the same time"); return -EINVAL; } =20 if ((flags & BDRV_REQ_NO_FALLBACK) && !zflag) { - printf("-n requires -z to be specified\n"); + error_setg(errp, "-n requires -z to be specified"); return -EINVAL; } =20 if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) { - printf("-u requires -z to be specified\n"); + error_setg(errp, "-u requires -z to be specified"); return -EINVAL; } =20 if (zflag + Pflag + sflag > 1) { - printf("Only one of -z, -P, and -s " - "can be specified at the same time\n"); + error_setg(errp, "Only one of -z, -P, and -s " + "can be specified at the same time"); return -EINVAL; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { - print_cvtnum_err(count, argv[optind]); + set_cvtnum_err(count, argv[optind], errp); return count; } else if (count > BDRV_REQUEST_MAX_BYTES && !(flags & BDRV_REQ_NO_FALLBACK)) { - printf("length cannot exceed %" PRIu64 " without -n, given %s\n", - (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); + error_setg(errp, + "length cannot exceed %" PRIu64 " without -n, given %s", + (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); 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); + error_setg(errp, + "%" PRId64 " is not a sector-aligned value for 'off= set'", + offset); return -EINVAL; } =20 if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { - printf("%"PRId64" is not a sector-aligned value for 'count'\n", - count); + error_setg(errp, + "%" PRId64 " is not a sector-aligned value for 'cou= nt'", + count); return -EINVAL; } } =20 if (zflag) { if (flags & BDRV_REQ_REGISTERED_BUF) { - printf("cannot combine zero write with registered I/O buffer\n= "); + error_setg(errp, + "cannot combine zero write with registered I/O buff= er"); return -EINVAL; } } else { if (sflag) { buf =3D qemu_io_alloc_from_file(blk, count, file_name, - flags & BDRV_REQ_REGISTERED_BUF); + flags & BDRV_REQ_REGISTERED_BUF, + errp); if (!buf) { return -EINVAL; } @@ -1203,7 +1214,7 @@ static int write_f(BlockBackend *blk, int argc, char = **argv) clock_gettime(CLOCK_MONOTONIC, &t2); =20 if (ret < 0) { - printf("write failed: %s\n", strerror(-ret)); + error_setg(errp, "write failed: %s", strerror(-ret)); goto out; } cnt =3D ret; @@ -1245,7 +1256,7 @@ writev_help(void) "\n"); } =20 -static int writev_f(BlockBackend *blk, int argc, char **argv); +static int writev_f(BlockBackend *blk, int argc, char **argv, Error **errp= ); =20 static const cmdinfo_t writev_cmd =3D { .name =3D "writev", @@ -1258,7 +1269,7 @@ static const cmdinfo_t writev_cmd =3D { .help =3D writev_help, }; =20 -static int writev_f(BlockBackend *blk, int argc, char **argv) +static int writev_f(BlockBackend *blk, int argc, char **argv, Error **errp) { struct timespec t1, t2; bool Cflag =3D false, qflag =3D false; @@ -1287,7 +1298,7 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv) flags |=3D BDRV_REQ_REGISTERED_BUF; break; case 'P': - pattern =3D parse_pattern(optarg); + pattern =3D parse_pattern(optarg, errp); if (pattern < 0) { return -EINVAL; } @@ -1305,14 +1316,14 @@ static int writev_f(BlockBackend *blk, int argc, ch= ar **argv) =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern, - flags & BDRV_REQ_REGISTERED_BUF); + flags & BDRV_REQ_REGISTERED_BUF, errp); if (buf =3D=3D NULL) { return -EINVAL; } @@ -1322,7 +1333,7 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv) clock_gettime(CLOCK_MONOTONIC, &t2); =20 if (ret < 0) { - printf("writev failed: %s\n", strerror(-ret)); + error_setg(errp, "writev failed: %s", strerror(-ret)); goto out; } cnt =3D ret; @@ -1367,7 +1378,7 @@ static void aio_write_done(void *opaque, int ret) =20 =20 if (ret < 0) { - printf("aio_write failed: %s\n", strerror(-ret)); + error_report("aio_write failed: %s", strerror(-ret)); block_acct_failed(blk_get_stats(ctx->blk), &ctx->acct); goto out; } @@ -1399,7 +1410,7 @@ static void aio_read_done(void *opaque, int ret) clock_gettime(CLOCK_MONOTONIC, &t2); =20 if (ret < 0) { - printf("readv failed: %s\n", strerror(-ret)); + error_report("readv failed: %s", strerror(-ret)); block_acct_failed(blk_get_stats(ctx->blk), &ctx->acct); goto out; } @@ -1409,8 +1420,8 @@ static void aio_read_done(void *opaque, int ret) =20 memset(cmp_buf, ctx->pattern, ctx->qiov.size); if (memcmp(ctx->buf, cmp_buf, ctx->qiov.size)) { - printf("Pattern verification failed at offset %" - PRId64 ", %zu bytes\n", ctx->offset, ctx->qiov.size); + error_report("Pattern verification failed at offset %" + PRId64 ", %zu bytes", ctx->offset, ctx->qiov.size= ); } g_free(cmp_buf); } @@ -1461,7 +1472,7 @@ static void aio_read_help(void) "\n"); } =20 -static int aio_read_f(BlockBackend *blk, int argc, char **argv); +static int aio_read_f(BlockBackend *blk, int argc, char **argv, Error **er= rp); =20 static const cmdinfo_t aio_read_cmd =3D { .name =3D "aio_read", @@ -1473,7 +1484,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 int aio_read_f(BlockBackend *blk, int argc, char **argv, Error **er= rp) { int nr_iov, c; struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); @@ -1486,7 +1497,7 @@ static int aio_read_f(BlockBackend *blk, int argc, ch= ar **argv) break; case 'P': ctx->Pflag =3D true; - ctx->pattern =3D parse_pattern(optarg); + ctx->pattern =3D parse_pattern(optarg, errp); if (ctx->pattern < 0) { g_free(ctx); return -EINVAL; @@ -1522,7 +1533,7 @@ static int aio_read_f(BlockBackend *blk, int argc, ch= ar **argv) ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { int ret =3D ctx->offset; - print_cvtnum_err(ret, argv[optind]); + set_cvtnum_err(ret, argv[optind], errp); g_free(ctx); return ret; } @@ -1530,7 +1541,7 @@ static int aio_read_f(BlockBackend *blk, int argc, ch= ar **argv) =20 nr_iov =3D argc - optind; ctx->buf =3D create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, 0xab, - ctx->flags & BDRV_REQ_REGISTERED_BUF); + ctx->flags & BDRV_REQ_REGISTERED_BUF, errp); if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); @@ -1573,7 +1584,7 @@ static void aio_write_help(void) "\n"); } =20 -static int aio_write_f(BlockBackend *blk, int argc, char **argv); +static int aio_write_f(BlockBackend *blk, int argc, char **argv, Error **e= rrp); =20 static const cmdinfo_t aio_write_cmd =3D { .name =3D "aio_write", @@ -1586,7 +1597,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 int aio_write_f(BlockBackend *blk, int argc, char **argv, Error **e= rrp) { int nr_iov, c; int pattern =3D 0xcd; @@ -1611,7 +1622,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) ctx->flags |=3D BDRV_REQ_MAY_UNMAP; break; case 'P': - pattern =3D parse_pattern(optarg); + pattern =3D parse_pattern(optarg, errp); if (pattern < 0) { g_free(ctx); return -EINVAL; @@ -1639,25 +1650,26 @@ static int aio_write_f(BlockBackend *blk, int argc,= char **argv) } =20 if (ctx->zflag && optind !=3D argc - 2) { - printf("-z supports only a single length parameter\n"); + error_setg(errp, "-z supports only a single length parameter"); g_free(ctx); return -EINVAL; } =20 if ((ctx->flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) { - printf("-u requires -z to be specified\n"); + error_setg(errp, "-u requires -z to be specified"); g_free(ctx); return -EINVAL; } =20 if (ctx->zflag && ctx->Pflag) { - printf("-z and -P cannot be specified at the same time\n"); + error_setg(errp, "-z and -P cannot be specified at the same time"); g_free(ctx); return -EINVAL; } =20 if (ctx->zflag && (ctx->flags & BDRV_REQ_REGISTERED_BUF)) { - printf("cannot combine zero write with registered I/O buffer\n"); + error_setg(errp, + "cannot combine zero write with registered I/O buffer"); g_free(ctx); return -EINVAL; } @@ -1665,7 +1677,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { int ret =3D ctx->offset; - print_cvtnum_err(ret, argv[optind]); + set_cvtnum_err(ret, argv[optind], errp); g_free(ctx); return ret; } @@ -1674,7 +1686,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) if (ctx->zflag) { int64_t count =3D cvtnum(argv[optind]); if (count < 0) { - print_cvtnum_err(count, argv[optind]); + set_cvtnum_err(count, argv[optind], errp); g_free(ctx); return count; } @@ -1685,7 +1697,8 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) } else { nr_iov =3D argc - optind; ctx->buf =3D create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, - pattern, ctx->flags & BDRV_REQ_REGISTERED_= BUF); + pattern, + ctx->flags & BDRV_REQ_REGISTERED_BUF, errp= ); if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); @@ -1703,7 +1716,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) return 0; } =20 -static int aio_flush_f(BlockBackend *blk, int argc, char **argv) +static int aio_flush_f(BlockBackend *blk, int argc, char **argv, Error **e= rrp) { BlockAcctCookie cookie; block_acct_start(blk_get_stats(blk), &cookie, 0, BLOCK_ACCT_FLUSH); @@ -1718,7 +1731,7 @@ 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 int flush_f(BlockBackend *blk, int argc, char **argv, Error **errp) { return blk_flush(blk); } @@ -1735,7 +1748,7 @@ static inline int64_t tosector(int64_t bytes) return bytes >> BDRV_SECTOR_BITS; } =20 -static int zone_report_f(BlockBackend *blk, int argc, char **argv) +static int zone_report_f(BlockBackend *blk, int argc, char **argv, Error *= *errp) { int ret; int64_t offset; @@ -1745,17 +1758,17 @@ static int zone_report_f(BlockBackend *blk, int arg= c, char **argv) ++optind; offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } ++optind; val =3D cvtnum(argv[optind]); if (val < 0) { - print_cvtnum_err(val, argv[optind]); + set_cvtnum_err(val, argv[optind], errp); return val; } if (val > UINT_MAX) { - printf("Number of zones must be less than 2^32\n"); + error_setg(errp, "Number of zones must be less than 2^32"); return -ERANGE; } nr_zones =3D val; @@ -1764,7 +1777,7 @@ static int zone_report_f(BlockBackend *blk, int argc,= char **argv) zones =3D g_new(BlockZoneDescriptor, nr_zones); ret =3D blk_zone_report(blk, offset, &nr_zones, zones); if (ret < 0) { - printf("zone report failed: %s\n", strerror(-ret)); + error_setg(errp, "zone report failed: %s", strerror(-ret)); } else { for (int i =3D 0; i < nr_zones; ++i) { printf("start: 0x%" PRIx64 ", len 0x%" PRIx64 ", " @@ -1788,25 +1801,25 @@ static const cmdinfo_t zone_report_cmd =3D { .oneline =3D "report zone information", }; =20 -static int zone_open_f(BlockBackend *blk, int argc, char **argv) +static int zone_open_f(BlockBackend *blk, int argc, char **argv, Error **e= rrp) { int ret; int64_t offset, len; ++optind; offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } ++optind; len =3D cvtnum(argv[optind]); if (len < 0) { - print_cvtnum_err(len, argv[optind]); + set_cvtnum_err(len, argv[optind], errp); return len; } ret =3D blk_zone_mgmt(blk, BLK_ZO_OPEN, offset, len); if (ret < 0) { - printf("zone open failed: %s\n", strerror(-ret)); + error_setg(errp, "zone open failed: %s", strerror(-ret)); } return ret; } @@ -1821,25 +1834,25 @@ static const cmdinfo_t zone_open_cmd =3D { .oneline =3D "explicit open a range of zones in zone block device", }; =20 -static int zone_close_f(BlockBackend *blk, int argc, char **argv) +static int zone_close_f(BlockBackend *blk, int argc, char **argv, Error **= errp) { int ret; int64_t offset, len; ++optind; offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } ++optind; len =3D cvtnum(argv[optind]); if (len < 0) { - print_cvtnum_err(len, argv[optind]); + set_cvtnum_err(len, argv[optind], errp); return len; } ret =3D blk_zone_mgmt(blk, BLK_ZO_CLOSE, offset, len); if (ret < 0) { - printf("zone close failed: %s\n", strerror(-ret)); + error_setg(errp, "zone close failed: %s", strerror(-ret)); } return ret; } @@ -1854,25 +1867,25 @@ static const cmdinfo_t zone_close_cmd =3D { .oneline =3D "close a range of zones in zone block device", }; =20 -static int zone_finish_f(BlockBackend *blk, int argc, char **argv) +static int zone_finish_f(BlockBackend *blk, int argc, char **argv, Error *= *errp) { int ret; int64_t offset, len; ++optind; offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } ++optind; len =3D cvtnum(argv[optind]); if (len < 0) { - print_cvtnum_err(len, argv[optind]); + set_cvtnum_err(len, argv[optind], errp); return len; } ret =3D blk_zone_mgmt(blk, BLK_ZO_FINISH, offset, len); if (ret < 0) { - printf("zone finish failed: %s\n", strerror(-ret)); + error_setg(errp, "zone finish failed: %s", strerror(-ret)); } return ret; } @@ -1887,25 +1900,25 @@ static const cmdinfo_t zone_finish_cmd =3D { .oneline =3D "finish a range of zones in zone block device", }; =20 -static int zone_reset_f(BlockBackend *blk, int argc, char **argv) +static int zone_reset_f(BlockBackend *blk, int argc, char **argv, Error **= errp) { int ret; int64_t offset, len; ++optind; offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } ++optind; len =3D cvtnum(argv[optind]); if (len < 0) { - print_cvtnum_err(len, argv[optind]); + set_cvtnum_err(len, argv[optind], errp); return len; } ret =3D blk_zone_mgmt(blk, BLK_ZO_RESET, offset, len); if (ret < 0) { - printf("zone reset failed: %s\n", strerror(-ret)); + error_setg(errp, "zone reset failed: %s", strerror(-ret)); } return ret; } @@ -1934,7 +1947,7 @@ static int do_aio_zone_append(BlockBackend *blk, QEMU= IOVector *qiov, return async_ret < 0 ? async_ret : 1; } =20 -static int zone_append_f(BlockBackend *blk, int argc, char **argv) +static int zone_append_f(BlockBackend *blk, int argc, char **argv, Error *= *errp) { int ret; bool pflag =3D false; @@ -1956,19 +1969,19 @@ static int zone_append_f(BlockBackend *blk, int arg= c, char **argv) =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } optind++; nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern, - flags & BDRV_REQ_REGISTERED_BUF); + flags & BDRV_REQ_REGISTERED_BUF, errp); if (buf =3D=3D NULL) { return -EINVAL; } ret =3D do_aio_zone_append(blk, &qiov, &offset, flags, &total); if (ret < 0) { - printf("zone append failed: %s\n", strerror(-ret)); + error_setg(errp, "zone append failed: %s", strerror(-ret)); goto out; } =20 @@ -1994,7 +2007,7 @@ static const cmdinfo_t zone_append_cmd =3D { .oneline =3D "append write a number of bytes at a specified offset", }; =20 -static int truncate_f(BlockBackend *blk, int argc, char **argv); +static int truncate_f(BlockBackend *blk, int argc, char **argv, Error **er= rp); static const cmdinfo_t truncate_cmd =3D { .name =3D "truncate", .altname =3D "t", @@ -2006,9 +2019,8 @@ static const cmdinfo_t truncate_cmd =3D { .oneline =3D "truncates the current file at the given offset", }; =20 -static int truncate_f(BlockBackend *blk, int argc, char **argv) +static int truncate_f(BlockBackend *blk, int argc, char **argv, Error **er= rp) { - Error *local_err =3D NULL; int64_t offset; int c, ret; PreallocMode prealloc =3D PREALLOC_MODE_OFF; @@ -2019,7 +2031,7 @@ static int truncate_f(BlockBackend *blk, int argc, ch= ar **argv) prealloc =3D qapi_enum_parse(&PreallocMode_lookup, optarg, PREALLOC_MODE__MAX, NULL); if (prealloc =3D=3D PREALLOC_MODE__MAX) { - error_report("Invalid preallocation mode '%s'", optarg); + error_setg(errp, "Invalid preallocation mode '%s'", optarg= ); return -EINVAL; } break; @@ -2031,7 +2043,7 @@ static int truncate_f(BlockBackend *blk, int argc, ch= ar **argv) =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[1]); + set_cvtnum_err(offset, argv[1], errp); return offset; } =20 @@ -2040,23 +2052,22 @@ static int truncate_f(BlockBackend *blk, int argc, = char **argv) * exact=3Dtrue. It is better to err on the "emit more errors" side * than to be overly permissive. */ - ret =3D blk_truncate(blk, offset, false, prealloc, 0, &local_err); + ret =3D blk_truncate(blk, offset, false, prealloc, 0, errp); if (ret < 0) { - error_report_err(local_err); return ret; } =20 return 0; } =20 -static int length_f(BlockBackend *blk, int argc, char **argv) +static int length_f(BlockBackend *blk, int argc, char **argv, Error **errp) { int64_t size; char s1[64]; =20 size =3D blk_getlength(blk); if (size < 0) { - printf("getlength: %s\n", strerror(-size)); + error_setg(errp, "getlength: %s", strerror(-size)); return size; } =20 @@ -2074,12 +2085,11 @@ static const cmdinfo_t length_cmd =3D { }; =20 =20 -static int info_f(BlockBackend *blk, int argc, char **argv) +static int info_f(BlockBackend *blk, int argc, char **argv, Error **errp) { BlockDriverState *bs =3D blk_bs(blk); BlockDriverInfo bdi; ImageInfoSpecific *spec_info; - Error *local_err =3D NULL; char s1[64], s2[64]; int ret; =20 @@ -2104,10 +2114,13 @@ static int info_f(BlockBackend *blk, int argc, char= **argv) printf("cluster size: %s\n", s1); printf("vm state offset: %s\n", s2); =20 - spec_info =3D bdrv_get_specific_info(bs, &local_err); - if (local_err) { - error_report_err(local_err); - return -EIO; + { + Error *local_err =3D NULL; + spec_info =3D bdrv_get_specific_info(bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return -EIO; + } } if (spec_info) { bdrv_image_info_specific_dump(spec_info, @@ -2143,7 +2156,7 @@ static void discard_help(void) "\n"); } =20 -static int discard_f(BlockBackend *blk, int argc, char **argv); +static int discard_f(BlockBackend *blk, int argc, char **argv, Error **err= p); =20 static const cmdinfo_t discard_cmd =3D { .name =3D "discard", @@ -2157,7 +2170,7 @@ static const cmdinfo_t discard_cmd =3D { .help =3D discard_help, }; =20 -static int discard_f(BlockBackend *blk, int argc, char **argv) +static int discard_f(BlockBackend *blk, int argc, char **argv, Error **err= p) { struct timespec t1, t2; bool Cflag =3D false, qflag =3D false; @@ -2185,18 +2198,18 @@ static int discard_f(BlockBackend *blk, int argc, c= har **argv) =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { - print_cvtnum_err(offset, argv[optind]); + set_cvtnum_err(offset, argv[optind], errp); return offset; } =20 optind++; bytes =3D cvtnum(argv[optind]); if (bytes < 0) { - print_cvtnum_err(bytes, argv[optind]); + set_cvtnum_err(bytes, argv[optind], errp); return bytes; } else if (bytes > BDRV_REQUEST_MAX_BYTES) { - printf("length cannot exceed %"PRIu64", given %s\n", - (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); + error_setg(errp, "length cannot exceed %" PRIu64 ", given %s", + (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); return -EINVAL; } =20 @@ -2205,7 +2218,7 @@ static int discard_f(BlockBackend *blk, int argc, cha= r **argv) clock_gettime(CLOCK_MONOTONIC, &t2); =20 if (ret < 0) { - printf("discard failed: %s\n", strerror(-ret)); + error_setg(errp, "discard failed: %s", strerror(-ret)); return ret; } =20 @@ -2238,7 +2251,8 @@ static void aio_discard_help(void) "\n"); } =20 -static int aio_discard_f(BlockBackend *blk, int argc, char **argv); +static int aio_discard_f(BlockBackend *blk, int argc, char **argv, + Error **errp); =20 static const cmdinfo_t aio_discard_cmd =3D { .name =3D "aio_discard", @@ -2259,7 +2273,7 @@ static void aio_discard_done(void *opaque, int ret) clock_gettime(CLOCK_MONOTONIC, &t2); =20 if (ret < 0) { - printf("aio_discard failed: %s\n", strerror(-ret)); + error_report("aio_discard failed: %s", strerror(-ret)); block_acct_failed(blk_get_stats(ctx->blk), &ctx->acct); goto out; } @@ -2278,7 +2292,7 @@ out: g_free(ctx); } =20 -static int aio_discard_f(BlockBackend *blk, int argc, char **argv) +static int aio_discard_f(BlockBackend *blk, int argc, char **argv, Error *= *errp) { int c, ret; int64_t count; @@ -2310,7 +2324,7 @@ static int aio_discard_f(BlockBackend *blk, int argc,= char **argv) ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { ret =3D ctx->offset; - print_cvtnum_err(ret, argv[optind]); + set_cvtnum_err(ret, argv[optind], errp); g_free(ctx); return ret; } @@ -2318,7 +2332,7 @@ static int aio_discard_f(BlockBackend *blk, int argc,= char **argv) =20 count =3D cvtnum(argv[optind]); if (count < 0) { - print_cvtnum_err(count, argv[optind]); + set_cvtnum_err(count, argv[optind], errp); g_free(ctx); return count; } @@ -2332,7 +2346,7 @@ static int aio_discard_f(BlockBackend *blk, int argc,= char **argv) return 0; } =20 -static int alloc_f(BlockBackend *blk, int argc, char **argv) +static int alloc_f(BlockBackend *blk, int argc, char **argv, Error **errp) { BlockDriverState *bs =3D blk_bs(blk); int64_t offset, start, remaining, count; @@ -2342,14 +2356,14 @@ static int alloc_f(BlockBackend *blk, int argc, cha= r **argv) =20 start =3D offset =3D cvtnum(argv[1]); if (offset < 0) { - print_cvtnum_err(offset, argv[1]); + set_cvtnum_err(offset, argv[1], errp); return offset; } =20 if (argc =3D=3D 3) { count =3D cvtnum(argv[2]); if (count < 0) { - print_cvtnum_err(count, argv[2]); + set_cvtnum_err(count, argv[2], errp); return count; } } else { @@ -2361,7 +2375,7 @@ static int alloc_f(BlockBackend *blk, int argc, char = **argv) while (remaining) { ret =3D bdrv_is_allocated(bs, offset, remaining, &num); if (ret < 0) { - printf("is_allocated failed: %s\n", strerror(-ret)); + error_setg(errp, "is_allocated failed: %s", strerror(-ret)); return ret; } offset +=3D num; @@ -2422,7 +2436,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 int map_f(BlockBackend *blk, int argc, char **argv, Error **errp) { int64_t offset, bytes; char s1[64], s2[64]; @@ -2433,17 +2447,18 @@ static int map_f(BlockBackend *blk, int argc, char = **argv) offset =3D 0; bytes =3D blk_getlength(blk); if (bytes < 0) { - error_report("Failed to query image length: %s", strerror(-bytes)); + error_setg(errp, "Failed to query image length: %s", strerror(-byt= es)); 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)); + error_setg(errp, "Failed to get allocation status: %s", + strerror(-ret)); return ret; } else if (!num) { - error_report("Unexpected end of image"); + error_setg(errp, "Unexpected end of image"); return -EIO; } =20 @@ -2485,7 +2500,7 @@ static void reopen_help(void) "\n"); } =20 -static int reopen_f(BlockBackend *blk, int argc, char **argv); +static int reopen_f(BlockBackend *blk, int argc, char **argv, Error **errp= ); =20 static QemuOptsList reopen_opts =3D { .name =3D "reopen", @@ -2507,7 +2522,7 @@ static const cmdinfo_t reopen_cmd =3D { .help =3D reopen_help, }; =20 -static int reopen_f(BlockBackend *blk, int argc, char **argv) +static int reopen_f(BlockBackend *blk, int argc, char **argv, Error **errp) { BlockDriverState *bs =3D blk_bs(blk); QemuOpts *qopts; @@ -2517,13 +2532,12 @@ static int reopen_f(BlockBackend *blk, int argc, ch= ar **argv) bool writethrough =3D !blk_enable_write_cache(blk); bool has_rw_option =3D false; bool has_cache_option =3D false; - Error *local_err =3D NULL; =20 while ((c =3D getopt(argc, argv, "c:o:rw")) !=3D -1) { switch (c) { case 'c': if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { - error_report("Invalid cache option: %s", optarg); + error_setg(errp, "Invalid cache option: %s", optarg); return -EINVAL; } has_cache_option =3D true; @@ -2536,7 +2550,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) break; case 'r': if (has_rw_option) { - error_report("Only one -r/-w option may be given"); + error_setg(errp, "Only one -r/-w option may be given"); return -EINVAL; } flags &=3D ~BDRV_O_RDWR; @@ -2544,7 +2558,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) break; case 'w': if (has_rw_option) { - error_report("Only one -r/-w option may be given"); + error_setg(errp, "Only one -r/-w option may be given"); return -EINVAL; } flags |=3D BDRV_O_RDWR; @@ -2566,7 +2580,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) if (!writethrough !=3D blk_enable_write_cache(blk) && blk_get_attached_dev(blk)) { - error_report("Cannot change cache.writeback: Device attached"); + error_setg(errp, "Cannot change cache.writeback: Device attached"); qemu_opts_reset(&reopen_opts); return -EBUSY; } @@ -2589,7 +2603,8 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) =20 if (qdict_haskey(opts, BDRV_OPT_READ_ONLY)) { if (has_rw_option) { - error_report("Cannot set both -r/-w and '" BDRV_OPT_READ_ONLY = "'"); + error_setg(errp, + "Cannot set both -r/-w and '" BDRV_OPT_READ_ONLY "'= "); qobject_unref(opts); return -EINVAL; } @@ -2600,7 +2615,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) if (qdict_haskey(opts, BDRV_OPT_CACHE_DIRECT) || qdict_haskey(opts, BDRV_OPT_CACHE_NO_FLUSH)) { if (has_cache_option) { - error_report("Cannot set both -c and the cache options"); + error_setg(errp, "Cannot set both -c and the cache options"); qobject_unref(opts); return -EINVAL; } @@ -2609,37 +2624,41 @@ static int reopen_f(BlockBackend *blk, int argc, ch= ar **argv) qdict_put_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, flags & BDRV_O_NO_FL= USH); } =20 - bdrv_reopen(bs, opts, true, &local_err); - - if (local_err) { - error_report_err(local_err); - return -EINVAL; + { + Error *local_err =3D NULL; + bdrv_reopen(bs, opts, true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return -EINVAL; + } } =20 blk_set_enable_write_cache(blk, !writethrough); return 0; } =20 -static int break_f(BlockBackend *blk, int argc, char **argv) +static int break_f(BlockBackend *blk, int argc, char **argv, Error **errp) { 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)); + error_setg(errp, "Could not set breakpoint: %s", strerror(-ret)); return ret; } =20 return 0; } =20 -static int remove_break_f(BlockBackend *blk, int argc, char **argv) +static int remove_break_f(BlockBackend *blk, int argc, char **argv, + Error **errp) { 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)); + error_setg(errp, "Could not remove breakpoint %s: %s", + argv[1], strerror(-ret)); return ret; } =20 @@ -2665,13 +2684,13 @@ 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 int resume_f(BlockBackend *blk, int argc, char **argv, Error **errp) { 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)); + error_setg(errp, "Could not resume request: %s", strerror(-ret)); return ret; } =20 @@ -2687,7 +2706,7 @@ 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 int wait_break_f(BlockBackend *blk, int argc, char **argv, Error **= errp) { while (!bdrv_debug_is_suspended(blk_bs(blk), argv[1])) { aio_poll(blk_get_aio_context(blk), true); @@ -2704,7 +2723,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 int abort_f(BlockBackend *blk, int argc, char **argv, Error **errp) { abort(); } @@ -2730,7 +2749,7 @@ static void sigraise_help(void) "\n", SIGTERM); } =20 -static int sigraise_f(BlockBackend *blk, int argc, char **argv); +static int sigraise_f(BlockBackend *blk, int argc, char **argv, Error **er= rp); =20 static const cmdinfo_t sigraise_cmd =3D { .name =3D "sigraise", @@ -2743,15 +2762,16 @@ static const cmdinfo_t sigraise_cmd =3D { .help =3D sigraise_help, }; =20 -static int sigraise_f(BlockBackend *blk, int argc, char **argv) +static int sigraise_f(BlockBackend *blk, int argc, char **argv, Error **er= rp) { int64_t sig =3D cvtnum(argv[1]); if (sig < 0) { - print_cvtnum_err(sig, argv[1]); + set_cvtnum_err(sig, argv[1], errp); return sig; } else if (sig > NSIG) { - printf("signal argument '%s' is too large to be a valid signal\n", - argv[1]); + error_setg(errp, + "signal argument '%s' is too large to be a valid signal= ", + argv[1]); return -EINVAL; } =20 @@ -2772,7 +2792,7 @@ static void sleep_cb(void *opaque) *expired =3D true; } =20 -static int sleep_f(BlockBackend *blk, int argc, char **argv) +static int sleep_f(BlockBackend *blk, int argc, char **argv, Error **errp) { char *endptr; long ms; @@ -2781,7 +2801,7 @@ static int sleep_f(BlockBackend *blk, int argc, char = **argv) =20 ms =3D strtol(argv[1], &endptr, 0); if (ms < 0 || *endptr !=3D '\0') { - printf("%s is not a valid number\n", argv[1]); + error_setg(errp, "%s is not a valid number", argv[1]); return -EINVAL; } =20 @@ -2833,7 +2853,7 @@ 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 int help_f(BlockBackend *blk, int argc, char **argv, Error **errp) { const cmdinfo_t *ct; =20 @@ -2844,7 +2864,7 @@ static int help_f(BlockBackend *blk, int argc, char *= *argv) =20 ct =3D find_command(argv[1]); if (ct =3D=3D NULL) { - printf("command %s not found\n", argv[1]); + error_setg(errp, "command %s not found", argv[1]); return -EINVAL; } =20 @@ -2867,7 +2887,7 @@ static const cmdinfo_t help_cmd =3D { * Called with aio context of blk acquired. Or with qemu_get_aio_context() * context acquired if blk is NULL. */ -int qemuio_command(BlockBackend *blk, const char *cmd) +int qemuio_command(BlockBackend *blk, const char *cmd, Error **errp) { char *input; const cmdinfo_t *ct; @@ -2880,9 +2900,9 @@ int qemuio_command(BlockBackend *blk, const char *cmd) if (c) { ct =3D find_command(v[0]); if (ct) { - ret =3D command(blk, ct, c, v); + ret =3D command(blk, ct, c, v, errp); } else { - fprintf(stderr, "command \"%s\" not found\n", v[0]); + error_setg(errp, "command \"%s\" not found", v[0]); ret =3D -EINVAL; } } diff --git a/qemu-io.c b/qemu-io.c index 8f2de83f3c8..598d5b1c9ca 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -68,7 +68,7 @@ static int get_eof_char(void) #endif } =20 -static int close_f(BlockBackend *blk, int argc, char **argv) +static int close_f(BlockBackend *blk, int argc, char **argv, Error **errp) { blk_unref(qemuio_blk); qemuio_blk =3D NULL; @@ -140,7 +140,7 @@ static void open_help(void) "\n"); } =20 -static int open_f(BlockBackend *blk, int argc, char **argv); +static int open_f(BlockBackend *blk, int argc, char **argv, Error **errp); =20 static const cmdinfo_t open_cmd =3D { .name =3D "open", @@ -164,7 +164,7 @@ static QemuOptsList empty_opts =3D { }, }; =20 -static int open_f(BlockBackend *blk, int argc, char **argv) +static int open_f(BlockBackend *blk, int argc, char **argv, Error **errp) { int flags =3D BDRV_O_UNMAP; int readonly =3D 0; @@ -268,7 +268,7 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv) return 0; } =20 -static int quit_f(BlockBackend *blk, int argc, char **argv) +static int quit_f(BlockBackend *blk, int argc, char **argv, Error **errp) { quit_qemu_io =3D true; return 0; @@ -414,7 +414,14 @@ static void prep_fetchline(void *opaque) =20 static int do_qemuio_command(const char *cmd) { - return qemuio_command(qemuio_blk, cmd); + Error *local_err =3D NULL; + int ret; + + ret =3D qemuio_command(qemuio_blk, cmd, &local_err); + if (local_err) { + error_report_err(local_err); + } + return ret; } =20 static int command_loop(void) diff --git a/tests/qemu-iotests/004.out b/tests/qemu-iotests/004.out index fb8593289f5..37da6024809 100644 --- a/tests/qemu-iotests/004.out +++ b/tests/qemu-iotests/004.out @@ -6,36 +6,36 @@ wrote 1048576/1048576 bytes at offset 133169152 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 write into image boundary -write failed: Input/output error +qemu-io: write failed: Input/output error =20 write at image boundary -write failed: Input/output error +qemu-io: write failed: Input/output error =20 write past image boundary -write failed: Input/output error +qemu-io: write failed: Input/output error =20 pwrite past image boundary -write failed: Input/output error +qemu-io: write failed: Input/output error =20 writev past image boundary -writev failed: Input/output error +qemu-io: writev failed: Input/output error =20 read before image boundary read 1048576/1048576 bytes at offset 133169152 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 read into image boundary -read failed: Input/output error +qemu-io: read failed: Input/output error =20 read at image boundary -read failed: Input/output error +qemu-io: read failed: Input/output error =20 read past image boundary -read failed: Input/output error +qemu-io: read failed: Input/output error =20 pread past image boundary -read failed: Input/output error +qemu-io: read failed: Input/output error =20 readv past image boundary -readv failed: Input/output error +qemu-io: readv failed: Input/output error *** done diff --git a/tests/qemu-iotests/021.out b/tests/qemu-iotests/021.out index 8533f8e58ae..dfdfeb50378 100644 --- a/tests/qemu-iotests/021.out +++ b/tests/qemu-iotests/021.out @@ -2,92 +2,92 @@ QA output created by 021 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 =20 =3D=3D testing writev -P -1 =3D=3D --1 is not a valid pattern byte +qemu-io: -1 is not a valid pattern byte =20 =3D=3D testing read -P -1 =3D=3D --1 is not a valid pattern byte +qemu-io: -1 is not a valid pattern byte =20 =3D=3D testing write -P -1 =3D=3D --1 is not a valid pattern byte +qemu-io: -1 is not a valid pattern byte =20 =3D=3D testing readv -P -1 =3D=3D --1 is not a valid pattern byte +qemu-io: -1 is not a valid pattern byte =20 =3D=3D testing aio_read -P -1 =3D=3D --1 is not a valid pattern byte +qemu-io: -1 is not a valid pattern byte =20 =3D=3D testing aio_write -P -1 =3D=3D --1 is not a valid pattern byte +qemu-io: -1 is not a valid pattern byte =20 =3D=3D testing writev -P 300 =3D=3D -300 is not a valid pattern byte +qemu-io: 300 is not a valid pattern byte =20 =3D=3D testing read -P 300 =3D=3D -300 is not a valid pattern byte +qemu-io: 300 is not a valid pattern byte =20 =3D=3D testing write -P 300 =3D=3D -300 is not a valid pattern byte +qemu-io: 300 is not a valid pattern byte =20 =3D=3D testing readv -P 300 =3D=3D -300 is not a valid pattern byte +qemu-io: 300 is not a valid pattern byte =20 =3D=3D testing aio_read -P 300 =3D=3D -300 is not a valid pattern byte +qemu-io: 300 is not a valid pattern byte =20 =3D=3D testing aio_write -P 300 =3D=3D -300 is not a valid pattern byte +qemu-io: 300 is not a valid pattern byte =20 =3D=3D testing writev -P 12m =3D=3D -12m is not a valid pattern byte +qemu-io: 12m is not a valid pattern byte =20 =3D=3D testing read -P 12m =3D=3D -12m is not a valid pattern byte +qemu-io: 12m is not a valid pattern byte =20 =3D=3D testing write -P 12m =3D=3D -12m is not a valid pattern byte +qemu-io: 12m is not a valid pattern byte =20 =3D=3D testing readv -P 12m =3D=3D -12m is not a valid pattern byte +qemu-io: 12m is not a valid pattern byte =20 =3D=3D testing aio_read -P 12m =3D=3D -12m is not a valid pattern byte +qemu-io: 12m is not a valid pattern byte =20 =3D=3D testing aio_write -P 12m =3D=3D -12m is not a valid pattern byte +qemu-io: 12m is not a valid pattern byte =20 =3D=3D testing writev -P 4k =3D=3D -4k is not a valid pattern byte +qemu-io: 4k is not a valid pattern byte =20 =3D=3D testing read -P 4k =3D=3D -4k is not a valid pattern byte +qemu-io: 4k is not a valid pattern byte =20 =3D=3D testing write -P 4k =3D=3D -4k is not a valid pattern byte +qemu-io: 4k is not a valid pattern byte =20 =3D=3D testing readv -P 4k =3D=3D -4k is not a valid pattern byte +qemu-io: 4k is not a valid pattern byte =20 =3D=3D testing aio_read -P 4k =3D=3D -4k is not a valid pattern byte +qemu-io: 4k is not a valid pattern byte =20 =3D=3D testing aio_write -P 4k =3D=3D -4k is not a valid pattern byte +qemu-io: 4k is not a valid pattern byte =20 =3D=3D testing writev -P route66 =3D=3D -route66 is not a valid pattern byte +qemu-io: route66 is not a valid pattern byte =20 =3D=3D testing read -P route66 =3D=3D -route66 is not a valid pattern byte +qemu-io: route66 is not a valid pattern byte =20 =3D=3D testing write -P route66 =3D=3D -route66 is not a valid pattern byte +qemu-io: route66 is not a valid pattern byte =20 =3D=3D testing readv -P route66 =3D=3D -route66 is not a valid pattern byte +qemu-io: route66 is not a valid pattern byte =20 =3D=3D testing aio_read -P route66 =3D=3D -route66 is not a valid pattern byte +qemu-io: route66 is not a valid pattern byte =20 =3D=3D testing aio_write -P route66 =3D=3D -route66 is not a valid pattern byte +qemu-io: route66 is not a valid pattern byte *** done diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out index a37bf446e94..27275fd6b70 100644 --- a/tests/qemu-iotests/060.out +++ b/tests/qemu-iotests/060.out @@ -9,7 +9,7 @@ ERROR cluster 3 refcount=3D1 reference=3D3 Data may be corrupted, or further writes to the image may corrupt it. incompatible_features [] qcow2: Marking image as corrupt: Preventing invalid write on metadata (ove= rlaps with active L1 table); further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error incompatible_features [1] image: TEST_DIR/t.IMGFMT file format: IMGFMT @@ -23,7 +23,7 @@ Format specific information: corrupt: true extended l2: false qemu-io: can't open device TEST_DIR/t.IMGFMT: IMGFMT: Image is corrupt; ca= nnot be opened read/write -no file open, try 'help open' +qemu-io: no file open, try 'help open' read 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 @@ -37,7 +37,7 @@ ERROR cluster 2 refcount=3D1 reference=3D2 Data may be corrupted, or further writes to the image may corrupt it. incompatible_features [] qcow2: Marking image as corrupt: Preventing invalid write on metadata (ove= rlaps with refcount block); further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error incompatible_features [1] ERROR refcount block 0 refcount=3D2 ERROR cluster 2 refcount=3D1 reference=3D2 @@ -73,7 +73,7 @@ Data may be corrupted, or further writes to the image may= corrupt it. This means waste of disk space, but no harm to data. incompatible_features [] qcow2: Marking image as corrupt: Preventing invalid write on metadata (ove= rlaps with inactive L2 table); further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error incompatible_features [1] ERROR cluster 4 refcount=3D1 reference=3D2 Leaked cluster 9 refcount=3D1 reference=3D0 @@ -108,10 +108,10 @@ wrote 65536/65536 bytes at offset 0 wrote 65536/65536 bytes at offset 536870912 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: Preventing invalid write on metadata (ove= rlaps with active L2 table); further corruption events will be suppressed +qemu-io: write failed: Input/output error +qemu-io: aio_write failed: No medium found blkdebug: Suspended request '0' -write failed: Input/output error blkdebug: Resuming request '0' -aio_write failed: No medium found =20 =3D=3D=3D Testing unallocated image header =3D=3D=3D =20 @@ -119,7 +119,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: Preventing invalid write on metadata (ove= rlaps with qcow2_header); further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error =20 =3D=3D=3D Testing unaligned L1 entry =3D=3D=3D =20 @@ -127,7 +127,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: L2 table offset 0x42a00 unaligned (L1 ind= ex: 0); further corruption events will be suppressed -read failed: Input/output error +qemu-io: read failed: Input/output error Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -140,7 +140,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: Cluster allocation offset 0x52a00 unalign= ed (L2 offset: 0x40000, L2 index: 0); further corruption events will be sup= pressed -read failed: Input/output error +qemu-io: read failed: Input/output error =20 =3D=3D=3D Testing unaligned pre-allocated zero cluster =3D=3D=3D =20 @@ -154,7 +154,7 @@ qemu-img: Failed to turn zero into data clusters: Input= /output error =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 qcow2: Marking image as corrupt: Refblock offset 0x22a00 unaligned (reftab= le index: 0); further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error =20 =3D=3D=3D Testing non-fatal corruption on freeing =3D=3D=3D =20 @@ -171,8 +171,8 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Image is corrupt: Cluster allocation offset 0x52a00 unaligned (L2 o= ffset: 0x40000, L2 index: 0); further non-fatal corruption events will be s= uppressed -read failed: Input/output error -read failed: Input/output error +qemu-io: read failed: Input/output error +qemu-io: read failed: Input/output error =20 =3D=3D=3D Testing non-fatal and then fatal corruption report =3D=3D=3D =20 @@ -181,15 +181,15 @@ wrote 131072/131072 bytes at offset 0 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Image is corrupt: Cannot free unaligned cluster 0x52a00; further no= n-fatal corruption events will be suppressed qcow2: Marking image as corrupt: Cluster allocation offset 0x62a00 unalign= ed (L2 offset: 0x40000, L2 index: 0x1); further corruption events will be s= uppressed +qemu-io: read failed: Input/output error discard 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -read failed: Input/output error =20 =3D=3D=3D Testing empty refcount table =3D=3D=3D =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 qcow2: Marking image as corrupt: Preventing invalid write on metadata (ove= rlaps with refcount table); further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error ERROR cluster 0 refcount=3D0 reference=3D1 ERROR cluster 1 refcount=3D0 reference=3D1 ERROR cluster 3 refcount=3D0 reference=3D1 @@ -209,7 +209,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: Preventing invalid allocation of refcount= block at offset 0; further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error ERROR cluster 0 refcount=3D0 reference=3D1 ERROR cluster 1 refcount=3D0 reference=3D1 ERROR cluster 3 refcount=3D0 reference=3D1 @@ -229,7 +229,7 @@ No errors were found on the image. =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 qcow2: Marking image as corrupt: Preventing invalid allocation of L2 table= at offset 0; further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error ERROR cluster 0 refcount=3D0 reference=3D1 ERROR cluster 1 refcount=3D0 reference=3D1 ERROR cluster 2 refcount=3D0 reference=3D1 @@ -251,7 +251,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 65536 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: Preventing invalid allocation of compress= ed cluster at offset 0; further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error ERROR cluster 0 refcount=3D0 reference=3D1 ERROR cluster 1 refcount=3D0 reference=3D1 ERROR cluster 2 refcount=3D0 reference=3D1 @@ -286,7 +286,7 @@ No errors were found on the image. =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 qcow2: Marking image as corrupt: Preventing invalid allocation of L2 table= at offset 0; further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error =20 =3D=3D=3D Testing dirty corrupt image =3D=3D=3D =20 @@ -319,7 +319,7 @@ wrote 65536/65536 bytes at offset 0 discard 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: Preallocated zero cluster offset 0x2a00 u= naligned (guest offset: 0); further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error --- Repairing --- Repairing offset=3D2a00: Preallocated cluster is not properly aligned; L2 = entry corrupted. The following inconsistencies were found and repaired: @@ -337,7 +337,7 @@ wrote 131072/131072 bytes at offset 0 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: Refblock offset 0x2a00 unaligned (reftabl= e index: 0); further corruption events will be suppressed qcow2_free_clusters failed: Input/output error -discard failed: No medium found +qemu-io: discard failed: No medium found --- Repairing --- ERROR refcount block 0 is not cluster aligned; refcount table entry corrup= ted qcow2: Marking image as corrupt: Refblock offset 0x2a00 unaligned (reftabl= e index: 0); further corruption events will be suppressed @@ -419,8 +419,7 @@ qcow2: Marking image as corrupt: Preventing invalid wri= te on metadata (overlaps QMP_VERSION {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_IMAGE_CORRUPTED", "data": {"device": "none0", "msg": "Preventing i= nvalid write on metadata (overlaps with refcount table)", "offset": 65536, = "node-name": "drive", "fatal": true, "size": 65536}} -write failed: Input/output error -{"return": ""} +{"return": "Error: write failed: Input/output error\r\n"} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} {"return": {}} =20 @@ -431,7 +430,6 @@ QMP_VERSION {"return": {}} qcow2: Image is corrupt: L2 table offset 0x2a2a2a00 unaligned (L1 index: 0= ); further non-fatal corruption events will be suppressed {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_IMAGE_CORRUPTED", "data": {"device": "", "msg": "L2 table offset 0= x2a2a2a00 unaligned (L1 index: 0)", "node-name": "drive", "fatal": false}} -{"return": ""} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} {"return": {}} =20 diff --git a/tests/qemu-iotests/071.out b/tests/qemu-iotests/071.out index a2923b05c29..f2d015d8cca 100644 --- a/tests/qemu-iotests/071.out +++ b/tests/qemu-iotests/071.out @@ -30,11 +30,11 @@ blkverify: read offset=3D0 bytes=3D512 contents mismatc= h at offset 0 =20 =3D=3D=3D Testing blkdebug through filename =3D=3D=3D =20 -read failed: Input/output error +qemu-io: read failed: Input/output error =20 =3D=3D=3D Testing blkdebug through file blockref =3D=3D=3D =20 -read failed: Input/output error +qemu-io: read failed: Input/output error =20 =3D=3D=3D Testing blkdebug on existing block device =3D=3D=3D =20 @@ -43,8 +43,7 @@ QMP_VERSION {"return": {}} {"return": {}} {"return": {}} -read failed: Input/output error -{"return": ""} +{"return": "Error: read failed: Input/output error\r\n"} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} {"return": {}} =20 @@ -82,8 +81,7 @@ read 512/512 bytes at offset 0 wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) {"return": ""} -read failed: Input/output error -{"return": ""} +{"return": "Error: read failed: Input/output error\r\n"} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} QEMU_PROG: Failed to flush the L2 table cache: Input/output error QEMU_PROG: Failed to flush the refcount block cache: Input/output error diff --git a/tests/qemu-iotests/072.out b/tests/qemu-iotests/072.out index fe949d47817..d7ce24da1f7 100644 --- a/tests/qemu-iotests/072.out +++ b/tests/qemu-iotests/072.out @@ -15,7 +15,7 @@ read 512/512 bytes at offset 512 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 512/512 bytes at offset 1024 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -Pattern verification failed at offset 0, 512 bytes +qemu-io: Pattern verification failed at offset 0, 512 bytes read 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out index d8acb3e7235..b20c21faf6a 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -66,8 +66,8 @@ wrote 512/512 bytes at offset 0 qemu-img: Failed to load snapshot: Snapshot L1 table offset invalid qemu-img: Snapshot L1 table offset invalid qemu-img: Failed to turn zero into data clusters: Invalid argument +qemu-io: write failed: Invalid argument qemu-io: Failed to flush the refcount block cache: Invalid argument -write failed: Invalid argument qemu-img: Snapshot L1 table offset invalid qemu-img: Could not apply snapshot 'test': Failed to load snapshot: Invali= d argument qemu-img: Could not delete snapshot 'test': Snapshot L1 table offset inval= id @@ -89,8 +89,8 @@ wrote 512/512 bytes at offset 0 qemu-img: Failed to load snapshot: Snapshot L1 table too large qemu-img: Snapshot L1 table too large qemu-img: Failed to turn zero into data clusters: File too large +qemu-io: write failed: File too large qemu-io: Failed to flush the refcount block cache: File too large -write failed: File too large qemu-img: Snapshot L1 table too large qemu-img: Could not apply snapshot 'test': Failed to load snapshot: File t= oo large qemu-img: Could not delete snapshot 'test': Snapshot L1 table too large diff --git a/tests/qemu-iotests/089.out b/tests/qemu-iotests/089.out index c53fc4823a1..a29e19b12d7 100644 --- a/tests/qemu-iotests/089.out +++ b/tests/qemu-iotests/089.out @@ -16,7 +16,7 @@ read 512/512 bytes at offset 512 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 512/512 bytes at offset 1024 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -Pattern verification failed at offset 0, 512 bytes +qemu-io: Pattern verification failed at offset 0, 512 bytes read 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 @@ -33,7 +33,7 @@ read 512/512 bytes at offset 0 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 wrote 512/512 bytes at offset 229376 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -read failed: Input/output error +qemu-io: read failed: Input/output error =20 =3D=3D=3D Testing qemu-img info output =3D=3D=3D =20 diff --git a/tests/qemu-iotests/114.out b/tests/qemu-iotests/114.out index f51dd9d20a1..80220e440ec 100644 --- a/tests/qemu-iotests/114.out +++ b/tests/qemu-iotests/114.out @@ -11,7 +11,7 @@ cluster_size: 65536 backing file: TEST_DIR/t.IMGFMT.base backing file format: foo qemu-io: can't open device TEST_DIR/t.qcow2: Could not open backing file: = Unknown driver 'foo' -no file open, try 'help open' +qemu-io: no file open, try 'help open' read 4096/4096 bytes at offset 0 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Could not change the backing file to 'TEST_DIR/t.qcow2.base': ba= cking format must be specified diff --git a/tests/qemu-iotests/134.out b/tests/qemu-iotests/134.out index 4abc5b5f7da..ce2a0df166e 100644 --- a/tests/qemu-iotests/134.out +++ b/tests/qemu-iotests/134.out @@ -24,7 +24,7 @@ read 134217728/134217728 bytes at offset 0 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 =3D=3D verify pattern failure with wrong password =3D=3D -Pattern verification failed at offset 0, 134217728 bytes +qemu-io: Pattern verification failed at offset 0, 134217728 bytes read 134217728/134217728 bytes at offset 0 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done diff --git a/tests/qemu-iotests/137.out b/tests/qemu-iotests/137.out index e19df5b6ba8..1947c1a1bd7 100644 --- a/tests/qemu-iotests/137.out +++ b/tests/qemu-iotests/137.out @@ -40,5 +40,5 @@ OK: Dirty bit not set Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 qemu-io: Parameter 'lazy-refcounts' expects 'on' or 'off' qcow2: Marking image as corrupt: Preventing invalid allocation of L2 table= at offset 0; further corruption events will be suppressed -write failed: Input/output error +qemu-io: write failed: Input/output error *** done diff --git a/tests/qemu-iotests/171 b/tests/qemu-iotests/171 index d1d77f70130..87a8aa24d96 100755 --- a/tests/qemu-iotests/171 +++ b/tests/qemu-iotests/171 @@ -188,7 +188,7 @@ img_offset=3D512 img_size=3D512 _make_test_img $size ( -$QEMU_IO "$(img_json)" <&1 <