From nobody Sun Feb 8 11:40:43 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=1593694660; cv=none; d=zohomail.com; s=zohoarc; b=I80EkX7ci4IBXIhLOnDwr/ZmgBapPepysA+QWqiLOYIPwD3r/C4d8r2LQtNjWPPq0Mwt7nb0BkZwR0bfsHtOgLby0SwNaf0lGUOgMVOgBFCGovvstzomO7+1MDHD/xeaHTqTHr+NoetkFVa/1+ZOqo70PXNjGvLKlXCoM9q/UoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593694660; 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=RzCcw/J903H7d+tOkDz+NR6v5DuG2R6mW41FFwjovBM=; b=We1lNJZIAWIiiCPaHnzPMTJ7uTYqC9IHGS+fQUV3nP30gWDaSPSVPARVecaDpm+BBKQuGzZ3b8jevBEqTWmNFuVJy59P4CKAZhUDtuC5X2zN6G6nQR/UqTpApNFr5u7A6q83A2b+d4cRlQFLM7p9dRkiYc5vwgh3MZCccqTGsHA= 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 1593694660449599.0921935733002; Thu, 2 Jul 2020 05:57:40 -0700 (PDT) Received: from localhost ([::1]:42866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqymZ-0007Yd-4y for importer@patchew.org; Thu, 02 Jul 2020 08:57:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqylN-00066P-Kb for qemu-devel@nongnu.org; Thu, 02 Jul 2020 08:56:25 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:21860 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqylM-0004Uk-70 for qemu-devel@nongnu.org; Thu, 02 Jul 2020 08:56:25 -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-26-0a3UHkgTOdejo403e1ZbGw-1; Thu, 02 Jul 2020 08:56:19 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8CB719057A3; Thu, 2 Jul 2020 12:56:18 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12B482B4CA; Thu, 2 Jul 2020 12:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593694583; 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=RzCcw/J903H7d+tOkDz+NR6v5DuG2R6mW41FFwjovBM=; b=PH8ZZrU2mSOzgh5UjfuLcjKQaUiV6zZe0/HekwfnvwHJXM+8sb+GGwPZLauY1jMNga57ji RdP2NIyt5Fyo/pn3qtZIs/I/48VLiiKSGcC8HUX5F95+TP5j8y+jwPTsKHWmEemaRSS6+F mv7vVbkWhLZlUCOcrRhhOfCVpriTcm8= X-MC-Unique: 0a3UHkgTOdejo403e1ZbGw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 1/3] util: validate whether O_DIRECT is supported after failure Date: Thu, 2 Jul 2020 13:56:10 +0100 Message-Id: <20200702125612.2176194-2-berrange@redhat.com> In-Reply-To: <20200702125612.2176194-1-berrange@redhat.com> References: <20200702125612.2176194-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 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=205.139.110.61; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/02 03:42:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , P J P , 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 we suggest that a filesystem may not support O_DIRECT after seeing an EINVAL. Other things can cause EINVAL though, so it is better to do an explicit check, and then report a definitive error message. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- util/osdep.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/util/osdep.c b/util/osdep.c index 4829c07ff6..e2b7507ee2 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -332,9 +332,11 @@ int qemu_open(const char *name, int flags, ...) } =20 #ifdef O_CLOEXEC - ret =3D open(name, flags | O_CLOEXEC, mode); -#else + flags |=3D O_CLOEXEC; +#endif ret =3D open(name, flags, mode); + +#ifndef O_CLOEXEC if (ret >=3D 0) { qemu_set_cloexec(ret); } @@ -342,8 +344,13 @@ int qemu_open(const char *name, int flags, ...) =20 #ifdef O_DIRECT if (ret =3D=3D -1 && errno =3D=3D EINVAL && (flags & O_DIRECT)) { - error_report("file system may not support O_DIRECT"); - errno =3D EINVAL; /* in case it was clobbered */ + int newflags =3D flags & ~O_DIRECT; + ret =3D open(name, newflags, mode); + if (ret !=3D -1) { + close(ret); + error_report("file system does not support O_DIRECT"); + errno =3D EINVAL; + } } #endif /* O_DIRECT */ =20 --=20 2.26.2 From nobody Sun Feb 8 11:40:43 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=1593694731; cv=none; d=zohomail.com; s=zohoarc; b=FZcCkSGrwPal3Wu9EgAdkL95QrJUMKq10RKSIkYAD0x78L9XNWDTdgm+HFqSOdyIu3QDcObhQ7w+CEumAGO4LJzBZ0X+F7UykD2UyUELCx7C7jMBV51ILxvaHsZ6115srvOCVLwsHXn84+4LRXsUIE553r5zJgV7AiZtTIgmNdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593694731; 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=H2C0jip9yx0d5KNdPg+4uWR6SBLh4fq/pQRfW5Z3ch0=; b=X5cwQ/SDzUsTpjtAaFO4NQT8+RjP3t0VaEihJJuc7rTrDHUfp0pZSb+QnGslWQp12JocIvoUd5CNbPjoiXFRnt4vGlLjZIO++k3aG0lvZotdJuhyFJKMZfqHqnoMUwbQ50JK9ynsM9glrMUGLVV6Ocwkpf60eQ3S2cwu/35UMGw= 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 1593694731930305.57438902037734; Thu, 2 Jul 2020 05:58:51 -0700 (PDT) Received: from localhost ([::1]:48722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqyni-0001u2-Nc for importer@patchew.org; Thu, 02 Jul 2020 08:58:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqylP-0006BC-Gw for qemu-devel@nongnu.org; Thu, 02 Jul 2020 08:56:27 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:45814 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqylN-0004Uz-MY for qemu-devel@nongnu.org; Thu, 02 Jul 2020 08:56:27 -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-357-16SZzdgoP8y4jbm-GlQVUg-1; Thu, 02 Jul 2020 08:56:23 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4D2E1015DAB; Thu, 2 Jul 2020 12:56:21 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58E9F2B4CA; Thu, 2 Jul 2020 12:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593694585; 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=H2C0jip9yx0d5KNdPg+4uWR6SBLh4fq/pQRfW5Z3ch0=; b=HztCZtJYhDS+KGr/5T3+CGyqfsiBkeren6cW21ezsKs+2zjpBVCMxPc8Fxc8SGkDAlEMRu PnBCyhHrWsF7o7duEkVRscqaLsrapGRyqpFMVWySeeLjCP9rOFkKx05wXp1VBrcEG1rtZV 26k3aJKFKYAyy9p2XWy99p1LsCPvGAA= X-MC-Unique: 16SZzdgoP8y4jbm-GlQVUg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 2/3] util: support detailed error reporting for qemu_open Date: Thu, 2 Jul 2020 13:56:11 +0100 Message-Id: <20200702125612.2176194-3-berrange@redhat.com> In-Reply-To: <20200702125612.2176194-1-berrange@redhat.com> References: <20200702125612.2176194-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 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=207.211.31.120; envelope-from=berrange@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/02 03:23:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , P J P , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Create a "qemu_open_err" method which does the same as "qemu_open", but with a "Error **errp" for error reporting. There should be no behavioural difference for existing callers at this stage. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Markus Armbruster --- include/qemu/osdep.h | 2 ++ util/osdep.c | 66 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 0d26a1b9bd..8506a978fa 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -483,6 +483,8 @@ int qemu_madvise(void *addr, size_t len, int advice); int qemu_mprotect_rwx(void *addr, size_t size); int qemu_mprotect_none(void *addr, size_t size); =20 +/* This is preferred over qemu_open for its improved error reporting */ +int qemu_open_err(const char *name, int flags, Error **errp, ...); int qemu_open(const char *name, int flags, ...); int qemu_close(int fd); int qemu_unlink(const char *name); diff --git a/util/osdep.c b/util/osdep.c index e2b7507ee2..3de8bee463 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include "qemu/osdep.h" +#include "qapi/error.h" =20 /* Needed early for CONFIG_BSD etc. */ =20 @@ -282,7 +283,7 @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t le= n, bool exclusive) /* * Opens a file with FD_CLOEXEC set */ -int qemu_open(const char *name, int flags, ...) +static int qemu_openv(const char *name, int flags, Error **errp, va_list a= p) { int ret; int mode =3D 0; @@ -297,24 +298,31 @@ int qemu_open(const char *name, int flags, ...) =20 fdset_id =3D qemu_parse_fdset(fdset_id_str); if (fdset_id =3D=3D -1) { + error_setg(errp, "Could not parse fdset %s", name); errno =3D EINVAL; return -1; } =20 fd =3D monitor_fdset_get_fd(fdset_id, flags); if (fd < 0) { + error_setg_errno(errp, -fd, "Could not acquire FD for %s flags= %x", + name, flags); errno =3D -fd; return -1; } =20 dupfd =3D qemu_dup_flags(fd, flags); if (dupfd =3D=3D -1) { + error_setg_errno(errp, errno, "Could not dup FD for %s flags %= x", + name, flags); return -1; } =20 ret =3D monitor_fdset_dup_fd_add(fdset_id, dupfd); if (ret =3D=3D -1) { close(dupfd); + error_setg(errp, "Could not save FD for %s flags %x", + name, flags); errno =3D EINVAL; return -1; } @@ -324,11 +332,7 @@ int qemu_open(const char *name, int flags, ...) #endif =20 if (flags & O_CREAT) { - va_list ap; - - va_start(ap, flags); mode =3D va_arg(ap, int); - va_end(ap); } =20 #ifdef O_CLOEXEC @@ -342,21 +346,57 @@ int qemu_open(const char *name, int flags, ...) } #endif =20 + if (ret =3D=3D -1) { + const char *action =3D "open"; + if (flags & O_CREAT) { + action =3D "create"; + } #ifdef O_DIRECT - if (ret =3D=3D -1 && errno =3D=3D EINVAL && (flags & O_DIRECT)) { - int newflags =3D flags & ~O_DIRECT; - ret =3D open(name, newflags, mode); - if (ret !=3D -1) { - close(ret); - error_report("file system does not support O_DIRECT"); - errno =3D EINVAL; + if (errno =3D=3D EINVAL && (flags & O_DIRECT)) { + int newflags =3D flags & ~O_DIRECT; + ret =3D open(name, newflags, mode); + if (ret !=3D -1) { + close(ret); + error_setg(errp, "Could not %s '%s' flags 0x%x: " + "filesystem does not support O_DIRECT", + action, name, flags); + errno =3D EINVAL; + return -1; + } } - } #endif /* O_DIRECT */ + error_setg_errno(errp, errno, "Could not %s '%s' flags 0x%x", + action, name, flags); + } + =20 return ret; } =20 +int qemu_open_err(const char *name, int flags, Error **errp, ...) +{ + va_list ap; + int rv; + + va_start(ap, errp); + rv =3D qemu_openv(name, flags, errp, ap); + va_end(ap); + + return rv; +} + +int qemu_open(const char *name, int flags, ...) +{ + va_list ap; + int rv; + + va_start(ap, flags); + rv =3D qemu_openv(name, flags, NULL, ap); + va_end(ap); + + return rv; +} + int qemu_close(int fd) { int64_t fdset_id; --=20 2.26.2 From nobody Sun Feb 8 11:40:43 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=1593694692; cv=none; d=zohomail.com; s=zohoarc; b=IQzCggRQQ7JkMGDguMS2s4foagTfuW4RBOAL7+qC5IM2jZFWimWAZPhOIfmPX6cVefw2SLilR/b3jt7YbJh+x+fe0n+ENpii3dEij0SWbThadIF9O1cFivpgcPcwvZjOtuIVpp5nvzBtcnvR37d1jmp9kV3qk3Z1CekTOUsNa2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593694692; 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=jeHC5G9sXPZ5NywerHRHzX2wx0TVRoHT6HaH7KcAUPk=; b=H7i+8PGiioKOJCMn8NvJtrt6k2L7L1DVtIYCjjRTL7lcXYpdEEymtkMOERbpogud2XXYMWRmoBPCKyRTnh06H/FdSvUPb6jF24iMaOtv3qxVEibtrkcoE2hcmBXKajdkKlhIs7pZJZ0fqTy+OmTutjoTndOQM+gJ0EikU2KUHDU= 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 1593694692721336.3464552845162; Thu, 2 Jul 2020 05:58:12 -0700 (PDT) Received: from localhost ([::1]:45510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqyn5-0000aD-Ev for importer@patchew.org; Thu, 02 Jul 2020 08:58:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqylU-0006NR-VZ for qemu-devel@nongnu.org; Thu, 02 Jul 2020 08:56:32 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:37914 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqylS-0004Va-2W for qemu-devel@nongnu.org; Thu, 02 Jul 2020 08:56:32 -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-109-9pr5vSqCNHuxecBqr8qp1g-1; Thu, 02 Jul 2020 08:56:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1B37800FFD; Thu, 2 Jul 2020 12:56:26 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67C792B5BA; Thu, 2 Jul 2020 12:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593694589; 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=jeHC5G9sXPZ5NywerHRHzX2wx0TVRoHT6HaH7KcAUPk=; b=S3dorgB6tYufkT5xrNnTGNt1Z4Ne1lM588HJjq9edZ/3DxIpns8Bw76VyXsSnPrNWdOYVU 6qf900Udw3XtlgarV5Z5h0mZ239palmdkvbtR9D1bPST+fjGTOblIAYB4l5z18Ek7AFWL6 5mB+hnIEABC5zxaR2NZ4OiEvw7F9RIg= X-MC-Unique: 9pr5vSqCNHuxecBqr8qp1g-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 3/3] block: switch to use qemu_open_err for improved errors Date: Thu, 2 Jul 2020 13:56:12 +0100 Message-Id: <20200702125612.2176194-4-berrange@redhat.com> In-Reply-To: <20200702125612.2176194-1-berrange@redhat.com> References: <20200702125612.2176194-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 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=207.211.31.81; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/02 04:18:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , P J P , 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' flags 0x4000: 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' flags 0x4002: filesystem does n= ot support O_DIRECT" } Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Markus Armbruster --- block/file-posix.c | 10 ++++------ tests/qemu-iotests/051.out | 4 ++-- tests/qemu-iotests/051.pc.out | 4 ++-- tests/qemu-iotests/061.out | 2 +- tests/qemu-iotests/069.out | 2 +- tests/qemu-iotests/082.out | 4 ++-- tests/qemu-iotests/111.out | 2 +- tests/qemu-iotests/226.out | 6 +++--- tests/qemu-iotests/232.out | 12 ++++++------ tests/qemu-iotests/244.out | 6 +++--- 10 files changed, 25 insertions(+), 27 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 3ab8f5a0fa..2865b789fb 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -574,11 +574,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(filename, s->open_flags, 0644); + fd =3D qemu_open_err(filename, s->open_flags, errp, 0644); 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; } @@ -970,9 +969,8 @@ static int raw_reconfigure_getfd(BlockDriverState *bs, = int flags, ret =3D raw_normalize_devicepath(&normalized_filename, errp); if (ret >=3D 0) { assert(!(*open_flags & O_CREAT)); - fd =3D qemu_open(normalized_filename, *open_flags); + fd =3D qemu_open_err(normalized_filename, *open_flags, errp); if (fd =3D=3D -1) { - error_setg_errno(errp, errno, "Could not reopen file"); return -1; } } @@ -2324,10 +2322,10 @@ raw_co_create(BlockdevCreateOptions *options, Error= **errp) } =20 /* Create file */ - fd =3D qemu_open(file_opts->filename, O_RDWR | O_CREAT | O_BINARY, 064= 4); + fd =3D qemu_open_err(file_opts->filename, O_RDWR | O_CREAT | O_BINARY, + errp, 0644); if (fd < 0) { result =3D -errno; - error_setg_errno(errp, -result, "Could not create file"); goto out; } =20 diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index 554c5ca90a..1a80eac0ce 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -363,7 +363,7 @@ Testing: -drive file=3Dfoo:bar QEMU_PROG: -drive file=3Dfoo:bar: Unknown protocol 'foo' =20 Testing: -drive file.filename=3Dfoo:bar -QEMU_PROG: -drive file.filename=3Dfoo:bar: Could not open 'foo:bar': No su= ch file or directory +QEMU_PROG: -drive file.filename=3Dfoo:bar: Could not open 'foo:bar' flags = 0x08000: No such file or directory =20 Testing: -hda file:TEST_DIR/t.qcow2 QEMU X.Y.Z monitor - type 'help' for more information @@ -374,7 +374,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) quit =20 Testing: -drive file.filename=3Dfile:TEST_DIR/t.qcow2 -QEMU_PROG: -drive file.filename=3Dfile:TEST_DIR/t.qcow2: Could not open 'f= ile:TEST_DIR/t.qcow2': No such file or directory +QEMU_PROG: -drive file.filename=3Dfile:TEST_DIR/t.qcow2: Could not open 'f= ile:TEST_DIR/t.qcow2' flags 0x80000: No such file or directory =20 =20 =3D=3D=3D Snapshot mode =3D=3D=3D diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out index 0ea80d35f0..bf8f96287b 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -463,7 +463,7 @@ Testing: -drive file=3Dfoo:bar QEMU_PROG: -drive file=3Dfoo:bar: Unknown protocol 'foo' =20 Testing: -drive file.filename=3Dfoo:bar -QEMU_PROG: -drive file.filename=3Dfoo:bar: Could not open 'foo:bar': No su= ch file or directory +QEMU_PROG: -drive file.filename=3Dfoo:bar: Could not open 'foo:bar' flags = 0x80000: No such file or directory =20 Testing: -hda file:TEST_DIR/t.qcow2 QEMU X.Y.Z monitor - type 'help' for more information @@ -474,7 +474,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) quit =20 Testing: -drive file.filename=3Dfile:TEST_DIR/t.qcow2 -QEMU_PROG: -drive file.filename=3Dfile:TEST_DIR/t.qcow2: Could not open 'f= ile:TEST_DIR/t.qcow2': No such file or directory +QEMU_PROG: -drive file.filename=3Dfile:TEST_DIR/t.qcow2: Could not open 'f= ile:TEST_DIR/t.qcow2' flags 0x80000: No such file or directory =20 =20 =3D=3D=3D Snapshot mode =3D=3D=3D diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out index 2f03cf045c..b4bc1f3112 100644 --- a/tests/qemu-iotests/061.out +++ b/tests/qemu-iotests/061.out @@ -533,7 +533,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 qemu-img: data-file can only be set for images that use an external data f= ile =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 data_file=3DT= EST_DIR/t.IMGFMT.data -qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'foo': No suc= h file or directory +qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'foo' flags 0= x80000: No such file or directory image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 64 MiB (67108864 bytes) diff --git a/tests/qemu-iotests/069.out b/tests/qemu-iotests/069.out index c78e8c2b72..60da51f7da 100644 --- a/tests/qemu-iotests/069.out +++ b/tests/qemu-iotests/069.out @@ -4,5 +4,5 @@ QA output created by 069 =20 Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D131072 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 backing_file=3D= TEST_DIR/t.IMGFMT.base -qemu-io: can't open device TEST_DIR/t.IMGFMT: Could not open backing file:= Could not open 'TEST_DIR/t.IMGFMT.base': No such file or directory +qemu-io: can't open device TEST_DIR/t.IMGFMT: Could not open backing file:= Could not open 'TEST_DIR/t.IMGFMT.base' flags 0x80000: No such file or dir= ectory *** done diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 529a1214e1..7e57235183 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -528,10 +528,10 @@ Supported options: size=3D - Virtual disk size =20 Testing: convert -O qcow2 -o backing_file=3DTEST_DIR/t.qcow2,,help TEST_DI= R/t.qcow2 TEST_DIR/t.qcow2.base -qemu-img: Could not open 'TEST_DIR/t.qcow2.base': Could not open backing f= ile: Could not open 'TEST_DIR/t.qcow2,help': No such file or directory +qemu-img: Could not open 'TEST_DIR/t.qcow2.base': Could not open backing f= ile: Could not open 'TEST_DIR/t.qcow2,help' flags 0x80000: No such file or = directory =20 Testing: convert -O qcow2 -o backing_file=3DTEST_DIR/t.qcow2,,? TEST_DIR/t= .qcow2 TEST_DIR/t.qcow2.base -qemu-img: Could not open 'TEST_DIR/t.qcow2.base': Could not open backing f= ile: Could not open 'TEST_DIR/t.qcow2,?': No such file or directory +qemu-img: Could not open 'TEST_DIR/t.qcow2.base': Could not open backing f= ile: Could not open 'TEST_DIR/t.qcow2,?' flags 0x80000: No such file or dir= ectory =20 Testing: convert -O qcow2 -o backing_file=3DTEST_DIR/t.qcow2, -o help TEST= _DIR/t.qcow2 TEST_DIR/t.qcow2.base qemu-img: Invalid option list: backing_file=3DTEST_DIR/t.qcow2, diff --git a/tests/qemu-iotests/111.out b/tests/qemu-iotests/111.out index 5279c462fc..f25f6bf573 100644 --- a/tests/qemu-iotests/111.out +++ b/tests/qemu-iotests/111.out @@ -1,4 +1,4 @@ QA output created by 111 -qemu-img: TEST_DIR/t.IMGFMT: Could not open 'TEST_DIR/t.IMGFMT.inexistent'= : No such file or directory +qemu-img: TEST_DIR/t.IMGFMT: Could not open 'TEST_DIR/t.IMGFMT.inexistent'= flags 0x80000: No such file or directory Could not open backing image to determine size. *** done diff --git a/tests/qemu-iotests/226.out b/tests/qemu-iotests/226.out index 42be973ff2..353fc4c799 100644 --- a/tests/qemu-iotests/226.out +++ b/tests/qemu-iotests/226.out @@ -6,7 +6,7 @@ QA output created by 226 qemu-io: can't open: A regular file was expected by the 'file' driver, but= something else was given qemu-io: warning: Opening a character device as a file using the 'file' dr= iver is deprecated =3D=3D Testing RW =3D=3D -qemu-io: can't open: Could not open 'TEST_DIR/t.IMGFMT': Is a directory +qemu-io: can't open: Could not open 'TEST_DIR/t.IMGFMT' flags 0x80002: Is = a directory qemu-io: warning: Opening a character device as a file using the 'file' dr= iver is deprecated =20 =3D=3D=3D Testing with driver:host_device =3D=3D=3D @@ -14,13 +14,13 @@ qemu-io: warning: Opening a character device as a file = using the 'file' driver i =3D=3D Testing RO =3D=3D qemu-io: can't open: 'host_device' driver expects either a character or bl= ock device =3D=3D Testing RW =3D=3D -qemu-io: can't open: Could not open 'TEST_DIR/t.IMGFMT': Is a directory +qemu-io: can't open: Could not open 'TEST_DIR/t.IMGFMT' flags 0x80002: Is = a directory =20 =3D=3D=3D Testing with driver:host_cdrom =3D=3D=3D =20 =3D=3D Testing RO =3D=3D qemu-io: can't open: 'host_cdrom' driver expects either a character or blo= ck device =3D=3D Testing RW =3D=3D -qemu-io: can't open: Could not open 'TEST_DIR/t.IMGFMT': Is a directory +qemu-io: can't open: Could not open 'TEST_DIR/t.IMGFMT' flags 0x80802: Is = a directory =20 *** done diff --git a/tests/qemu-iotests/232.out b/tests/qemu-iotests/232.out index 3bd1a920af..bfa3f20172 100644 --- a/tests/qemu-iotests/232.out +++ b/tests/qemu-iotests/232.out @@ -21,11 +21,11 @@ NODE_NAME: TEST_DIR/t.IMGFMT (file, read-only) NODE_NAME: TEST_DIR/t.IMGFMT (file, read-only) NODE_NAME: TEST_DIR/t.IMGFMT (file, read-only) =20 -QEMU_PROG: -drive driver=3Dfile,file=3DTEST_DIR/t.IMGFMT,if=3Dnone,read-on= ly=3Doff,auto-read-only=3Doff: Could not open 'TEST_DIR/t.IMGFMT': Permissi= on denied +QEMU_PROG: -drive driver=3Dfile,file=3DTEST_DIR/t.IMGFMT,if=3Dnone,read-on= ly=3Doff,auto-read-only=3Doff: Could not open 'TEST_DIR/t.IMGFMT' flags 0x8= 0002: Permission denied NODE_NAME: TEST_DIR/t.IMGFMT (file) NODE_NAME: TEST_DIR/t.IMGFMT (file) =20 -QEMU_PROG: -drive driver=3Dfile,file=3DTEST_DIR/t.IMGFMT,if=3Dnone,auto-re= ad-only=3Doff: Could not open 'TEST_DIR/t.IMGFMT': Permission denied +QEMU_PROG: -drive driver=3Dfile,file=3DTEST_DIR/t.IMGFMT,if=3Dnone,auto-re= ad-only=3Doff: Could not open 'TEST_DIR/t.IMGFMT' flags 0x80002: Permission= denied NODE_NAME: TEST_DIR/t.IMGFMT (file) NODE_NAME: TEST_DIR/t.IMGFMT (file) =20 @@ -49,11 +49,11 @@ node0: TEST_DIR/t.IMGFMT (file, read-only) node0: TEST_DIR/t.IMGFMT (file, read-only) node0: TEST_DIR/t.IMGFMT (file, read-only) =20 -QEMU_PROG: -blockdev driver=3Dfile,filename=3DTEST_DIR/t.IMGFMT,node-name= =3Dnode0,read-only=3Doff,auto-read-only=3Doff: Could not open 'TEST_DIR/t.I= MGFMT': Permission denied +QEMU_PROG: -blockdev driver=3Dfile,filename=3DTEST_DIR/t.IMGFMT,node-name= =3Dnode0,read-only=3Doff,auto-read-only=3Doff: Could not open 'TEST_DIR/t.I= MGFMT' flags 0x80002: Permission denied node0: TEST_DIR/t.IMGFMT (file) -QEMU_PROG: -blockdev driver=3Dfile,filename=3DTEST_DIR/t.IMGFMT,node-name= =3Dnode0,read-only=3Doff: Could not open 'TEST_DIR/t.IMGFMT': Permission de= nied +QEMU_PROG: -blockdev driver=3Dfile,filename=3DTEST_DIR/t.IMGFMT,node-name= =3Dnode0,read-only=3Doff: Could not open 'TEST_DIR/t.IMGFMT' flags 0x80002:= Permission denied =20 -QEMU_PROG: -blockdev driver=3Dfile,filename=3DTEST_DIR/t.IMGFMT,node-name= =3Dnode0,auto-read-only=3Doff: Could not open 'TEST_DIR/t.IMGFMT': Permissi= on denied +QEMU_PROG: -blockdev driver=3Dfile,filename=3DTEST_DIR/t.IMGFMT,node-name= =3Dnode0,auto-read-only=3Doff: Could not open 'TEST_DIR/t.IMGFMT' flags 0x8= 0002: Permission denied node0: TEST_DIR/t.IMGFMT (file) -QEMU_PROG: -blockdev driver=3Dfile,filename=3DTEST_DIR/t.IMGFMT,node-name= =3Dnode0: Could not open 'TEST_DIR/t.IMGFMT': Permission denied +QEMU_PROG: -blockdev driver=3Dfile,filename=3DTEST_DIR/t.IMGFMT,node-name= =3Dnode0: Could not open 'TEST_DIR/t.IMGFMT' flags 0x80002: Permission deni= ed *** done diff --git a/tests/qemu-iotests/244.out b/tests/qemu-iotests/244.out index dbab7359a9..34daec97f2 100644 --- a/tests/qemu-iotests/244.out +++ b/tests/qemu-iotests/244.out @@ -9,7 +9,7 @@ read 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -qemu-io: can't open device TEST_DIR/t.qcow2: Could not open 'inexistent': = No such file or directory +qemu-io: can't open device TEST_DIR/t.qcow2: Could not open 'inexistent' f= lags 0x80002: No such file or directory no file open, try 'help open' =20 Data file required, but without data file name in the image: @@ -17,14 +17,14 @@ qemu-io: can't open device TEST_DIR/t.qcow2: 'data-file= ' is required for this im no file open, try 'help open' read 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -qemu-io: can't open device TEST_DIR/t.qcow2: Could not open 'inexistent': = No such file or directory +qemu-io: can't open device TEST_DIR/t.qcow2: Could not open 'inexistent' f= lags 0x80002: No such file or directory no file open, try 'help open' =20 Setting data-file for an image with internal data: Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 qemu-io: can't open device TEST_DIR/t.qcow2: 'data-file' can only be set f= or images with an external data file no file open, try 'help open' -qemu-io: can't open device TEST_DIR/t.qcow2: Could not open 'inexistent': = No such file or directory +qemu-io: can't open device TEST_DIR/t.qcow2: Could not open 'inexistent' f= lags 0x80002: No such file or directory no file open, try 'help open' =20 =3D=3D=3D Conflicting features =3D=3D=3D --=20 2.26.2