From nobody Thu May 2 14:53:56 2024 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 154105385172665.23079739625223; Wed, 31 Oct 2018 23:30:51 -0700 (PDT) Received: from localhost ([::1]:35645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gI6V7-0007Ju-GD for importer@patchew.org; Thu, 01 Nov 2018 02:30:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gI6U8-0006e1-Fe for qemu-devel@nongnu.org; Thu, 01 Nov 2018 02:29:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gI6U5-0007Po-CG for qemu-devel@nongnu.org; Thu, 01 Nov 2018 02:29:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gI6Tj-0007Hn-93; Thu, 01 Nov 2018 02:29:16 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5B273084295; Thu, 1 Nov 2018 06:29:13 +0000 (UTC) Received: from magic.redhat.com (ovpn-12-172.pek2.redhat.com [10.72.12.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6200E1001F59; Thu, 1 Nov 2018 06:29:11 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 1 Nov 2018 14:29:09 +0800 Message-Id: <20181101062909.18833-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 01 Nov 2018 06:29:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3] file-posix: Use error API properly 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 , armbru@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use error_report for situations that affect user operation (i.e. we're actually returning error), and warn_report/warn_report_err when some less critical error happened but the user operation can still carry on. For raw_normalize_devicepath, add Error parameter to propagate to its callers. Suggested-by: Markus Armbruster Signed-off-by: Fam Zheng --- v3: Use error_setg_errno. [Eric] v2: Add Error ** to raw_normalize_devicepath. [Markus] Use error_printf for splitting multi-sentence message. [Markus] --- block/file-posix.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 2da3a76355..e5606655b6 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -205,7 +205,7 @@ static int cdrom_reopen(BlockDriverState *bs); #endif =20 #if defined(__NetBSD__) -static int raw_normalize_devicepath(const char **filename) +static int raw_normalize_devicepath(const char **filename, Error **errp) { static char namebuf[PATH_MAX]; const char *dp, *fname; @@ -214,8 +214,7 @@ static int raw_normalize_devicepath(const char **filena= me) fname =3D *filename; dp =3D strrchr(fname, '/'); if (lstat(fname, &sb) < 0) { - fprintf(stderr, "%s: stat failed: %s\n", - fname, strerror(errno)); + error_setg_errno(errp, errno, "%s: stat failed", fname); return -errno; } =20 @@ -229,14 +228,13 @@ static int raw_normalize_devicepath(const char **file= name) snprintf(namebuf, PATH_MAX, "%.*s/r%s", (int)(dp - fname), fname, dp + 1); } - fprintf(stderr, "%s is a block device", fname); *filename =3D namebuf; - fprintf(stderr, ", using %s\n", *filename); + warn_report("%s is a block device, using %s", fname, *filename); =20 return 0; } #else -static int raw_normalize_devicepath(const char **filename) +static int raw_normalize_devicepath(const char **filename, Error **errp) { return 0; } @@ -461,9 +459,8 @@ static int raw_open_common(BlockDriverState *bs, QDict = *options, =20 filename =3D qemu_opt_get(opts, "filename"); =20 - ret =3D raw_normalize_devicepath(&filename); + ret =3D raw_normalize_devicepath(&filename, errp); if (ret !=3D 0) { - error_setg_errno(errp, -ret, "Could not normalize device path"); goto fail; } =20 @@ -492,11 +489,10 @@ static int raw_open_common(BlockDriverState *bs, QDic= t *options, case ON_OFF_AUTO_ON: s->use_lock =3D true; if (!qemu_has_ofd_lock()) { - fprintf(stderr, - "File lock requested but OFD locking syscall is " - "unavailable, falling back to POSIX file locks.\n" - "Due to the implementation, locks can be lost " - "unexpectedly.\n"); + warn_report("File lock requested but OFD locking syscall is " + "unavailable, falling back to POSIX file locks"); + error_printf("Due to the implementation, locks can be lost " + "unexpectedly.\n"); } break; case ON_OFF_AUTO_OFF: @@ -805,7 +801,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs, /* Theoretically the above call only unlocks bytes and it cann= ot * fail. Something weird happened, report it. */ - error_report_err(local_err); + warn_report_err(local_err); } break; case RAW_PL_COMMIT: @@ -815,7 +811,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs, /* Theoretically the above call only unlocks bytes and it cann= ot * fail. Something weird happened, report it. */ - error_report_err(local_err); + warn_report_err(local_err); } break; } @@ -892,10 +888,8 @@ static int raw_reopen_prepare(BDRVReopenState *state, /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */ if (rs->fd =3D=3D -1) { const char *normalized_filename =3D state->bs->filename; - ret =3D raw_normalize_devicepath(&normalized_filename); - if (ret < 0) { - error_setg_errno(errp, -ret, "Could not normalize device path"= ); - } else { + ret =3D raw_normalize_devicepath(&normalized_filename, errp); + if (ret >=3D 0) { assert(!(rs->open_flags & O_CREAT)); rs->fd =3D qemu_open(normalized_filename, rs->open_flags); if (rs->fd =3D=3D -1) { @@ -1775,7 +1769,7 @@ static int aio_worker(void *arg) ret =3D handle_aiocb_truncate(aiocb); break; default: - fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type); + error_report("invalid aio request (0x%x)", aiocb->aio_type); ret =3D -EINVAL; break; } @@ -2263,7 +2257,7 @@ out_unlock: * not mean the whole creation operation has failed. So * report it the user for their convenience, but do not report * it to the caller. */ - error_report_err(local_err); + warn_report_err(local_err); } =20 out_close: @@ -3128,9 +3122,8 @@ static int coroutine_fn hdev_co_create_opts(const cha= r *filename, QemuOpts *opts =20 (void)has_prefix; =20 - ret =3D raw_normalize_devicepath(&filename); + ret =3D raw_normalize_devicepath(&filename, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "Could not normalize device path"); return ret; } =20 --=20 2.17.2