From nobody Sun Feb 8 12:58:18 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600250179; cv=none; d=zohomail.com; s=zohoarc; b=JKNUJY23UammSLf13VJMcnQ7Zx2/lcuwSfZOCHfYdrEEQV0Eq+7kjhhZr6hWFAkfPL5erM12xz9XWs5OnCf1GjFW68cli8pg+rzG08G6nld89jn/3H77w8wovDms27mJhgHbWIWGaY2bvR2Fl5SeRBkWQrKzIYyp9wPy+muLyFw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600250179; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O2ouGnkiYaquzvHLH10l3C36l1wlfZEHCowdYJan56E=; b=UqKxxJtBNNoVWyg8G108rSCDGLsLyjTtKpW1K3hMjI2UGGFzKCII/xXALmq/OkDBkGOgpGHCAduKStZ2WqNyeid4LTrk+Q4xPkiC4hl7knr4piMnL6m9LkeBsxp0/7hZpkQ0o9ITkJO+rfRAQXuHOgtnmvotHyHkrfa1dphS4/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600250179122532.6537321310116; Wed, 16 Sep 2020 02:56:19 -0700 (PDT) Received: from localhost ([::1]:59568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIUAj-0003GF-TW for importer@patchew.org; Wed, 16 Sep 2020 05:56:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIU2M-0006oj-E4 for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIU2K-0008R9-7K for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-1LyKDxvVMaC3bEDG3vgDRQ-1; Wed, 16 Sep 2020 05:47:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3969E80EDA3; Wed, 16 Sep 2020 09:47:32 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A14975123; Wed, 16 Sep 2020 09:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600249655; 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=O2ouGnkiYaquzvHLH10l3C36l1wlfZEHCowdYJan56E=; b=cK28ktZUrNFmql3uyFZsB7Z8AVFGoDdvQUXeebzig7Bc+rw/oWZLyu9pvu3jAsVECwO5if BYfT376NbLM54fSxai5bZib9cnEIwS05W6Pury+841LmfICZ8fY3gUtejVJHssq3Dr08FA yYwVU9AKhLex6TIi2hyepMyt1KWZtcY= X-MC-Unique: 1LyKDxvVMaC3bEDG3vgDRQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 8/8] block/file: switch to use qemu_open/qemu_create for improved errors Date: Wed, 16 Sep 2020 10:47:05 +0100 Message-Id: <20200916094705.2625331-9-berrange@redhat.com> In-Reply-To: <20200916094705.2625331-1-berrange@redhat.com> References: <20200916094705.2625331-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/16 02:35:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Currently at startup if using cache=3Dnone on a filesystem lacking O_DIRECT such as tmpfs, at startup QEMU prints qemu-system-x86_64: -drive file=3D/tmp/foo.img,cache=3Dnone: file system ma= y not support O_DIRECT qemu-system-x86_64: -drive file=3D/tmp/foo.img,cache=3Dnone: Could not open= '/tmp/foo.img': Invalid argument while at QMP level the hint is missing, so QEMU reports just "error": { "class": "GenericError", "desc": "Could not open '/tmp/foo.img': Invalid argument" } which is close to useless for the end user trying to figure out what they did wrong. With this change at startup QEMU prints qemu-system-x86_64: -drive file=3D/tmp/foo.img,cache=3Dnone: Unable to open= '/tmp/foo.img': filesystem does not support O_DIRECT while at the QMP level QEMU reports a massively more informative "error": { "class": "GenericError", "desc": "Unable to open '/tmp/foo.img': filesystem does not support O_= DIRECT" } Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- block/file-posix.c | 18 +++++++----------- block/file-win32.c | 6 ++---- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index bac2566f10..c63926d592 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -630,11 +630,10 @@ static int raw_open_common(BlockDriverState *bs, QDic= t *options, raw_parse_flags(bdrv_flags, &s->open_flags, false); =20 s->fd =3D -1; - fd =3D qemu_open_old(filename, s->open_flags, 0644); + fd =3D qemu_open(filename, s->open_flags, errp); ret =3D fd < 0 ? -errno : 0; =20 if (ret < 0) { - error_setg_file_open(errp, -ret, filename); if (ret =3D=3D -EROFS) { ret =3D -EACCES; } @@ -1032,15 +1031,13 @@ static int raw_reconfigure_getfd(BlockDriverState *= bs, int flags, } } =20 - /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open_old= () */ + /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */ if (fd =3D=3D -1) { const char *normalized_filename =3D bs->filename; ret =3D raw_normalize_devicepath(&normalized_filename, errp); if (ret >=3D 0) { - assert(!(*open_flags & O_CREAT)); - fd =3D qemu_open_old(normalized_filename, *open_flags); + fd =3D qemu_open(normalized_filename, *open_flags, errp); if (fd =3D=3D -1) { - error_setg_errno(errp, errno, "Could not reopen file"); return -1; } } @@ -2411,10 +2408,9 @@ raw_co_create(BlockdevCreateOptions *options, Error = **errp) } =20 /* Create file */ - fd =3D qemu_open_old(file_opts->filename, O_RDWR | O_CREAT | O_BINARY,= 0644); + fd =3D qemu_create(file_opts->filename, O_RDWR | O_BINARY, 0644, errp); if (fd < 0) { result =3D -errno; - error_setg_errno(errp, -result, "Could not create file"); goto out; } =20 @@ -3335,7 +3331,7 @@ static bool setup_cdrom(char *bsd_path, Error **errp) for (index =3D 0; index < num_of_test_partitions; index++) { snprintf(test_partition, sizeof(test_partition), "%ss%d", bsd_path, index); - fd =3D qemu_open_old(test_partition, O_RDONLY | O_BINARY | O_LARGE= FILE); + fd =3D qemu_open(test_partition, O_RDONLY | O_BINARY | O_LARGEFILE= , NULL); if (fd >=3D 0) { partition_found =3D true; qemu_close(fd); @@ -3653,7 +3649,7 @@ static int cdrom_probe_device(const char *filename) int prio =3D 0; struct stat st; =20 - fd =3D qemu_open_old(filename, O_RDONLY | O_NONBLOCK); + fd =3D qemu_open(filename, O_RDONLY | O_NONBLOCK, NULL); if (fd < 0) { goto out; } @@ -3787,7 +3783,7 @@ static int cdrom_reopen(BlockDriverState *bs) */ if (s->fd >=3D 0) qemu_close(s->fd); - fd =3D qemu_open_old(bs->filename, s->open_flags, 0644); + fd =3D qemu_open(bs->filename, s->open_flags, NULL); if (fd < 0) { s->fd =3D -1; return -EIO; diff --git a/block/file-win32.c b/block/file-win32.c index b28603c7d5..2642088bd6 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -596,11 +596,9 @@ static int raw_co_create(BlockdevCreateOptions *option= s, Error **errp) return -EINVAL; } =20 - fd =3D qemu_open_old(file_opts->filename, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - 0644); + fd =3D qemu_create(file_opts->filename, O_WRONLY | O_TRUNC | O_BINARY, + 0644, errp); if (fd < 0) { - error_setg_errno(errp, errno, "Could not create file"); return -EIO; } set_sparse(fd); --=20 2.26.2