From nobody Sun Nov 16 07:38:06 2025 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=1599066884; cv=none; d=zohomail.com; s=zohoarc; b=QV56x199shDA6c9d7Vz4x+m5eSx1D2Jo3GCa8bkv3NLc7G/4moXr4+7P7sVA0k1MvBm8snkno3lU9pZk2LuQ8MEiBscAJtRDi8+T3m9fYtuY/UhJwzfxXg1tdt6UPdGiahgMUBdgSbIAUtnBDnXJSG/bM5maD1UJhX074oWs/oM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599066884; 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=qzs3aUJxV2cZ6h1cobn1/ATKpeDKXdCUHXnxMVc3LTc=; b=ICE7vmLij8l/CQ6+XdoVJiHOrwcs2vLTB/hDGZP+RsQJxZGKufhdjArWMp6115Vq/bl09cA045Pxy3uS8F5CTGnyle0WrmlHMzYVKLBavbRDLiF5QcXbDO+9YvRqwziSS+8v2O+ILRfNB4ijMIDTQ1wWlqZM1d5oP4PVefzCy8g= 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 1599066884798253.30763879484823; Wed, 2 Sep 2020 10:14:44 -0700 (PDT) Received: from localhost ([::1]:51156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDWLM-0006Ea-2Z for importer@patchew.org; Wed, 02 Sep 2020 13:14:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDWGf-0006Wv-2Y for qemu-devel@nongnu.org; Wed, 02 Sep 2020 13:09:53 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:23778 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 1kDWGd-0001QE-6b for qemu-devel@nongnu.org; Wed, 02 Sep 2020 13:09:52 -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-278-LIuQ0bi1MSynPckRN6xmHg-1; Wed, 02 Sep 2020 13:09:48 -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 B57AA56C89; Wed, 2 Sep 2020 17:09:47 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11F5319C59; Wed, 2 Sep 2020 17:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599066590; 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=qzs3aUJxV2cZ6h1cobn1/ATKpeDKXdCUHXnxMVc3LTc=; b=dqRW2INQ4fHcHsmPt7yuzzWqEN9G8bL08vCiRWos8/jdJ/XI3cIpjIKMb3JObOG3ZXlZYz 2TJ+anKjZgRHg4rHmCaMvSyCGoGWyIJdSZdUZqQx50FEMjnFgx2rICbmfJwXH0zB8t5vYf vhjkd3BhcsD0+VMr1pSkUQJaNwBY7pg= X-MC-Unique: LIuQ0bi1MSynPckRN6xmHg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 8/8] block/file: switch to use qemu_open/qemu_create for improved errors Date: Wed, 2 Sep 2020 18:09:13 +0100 Message-Id: <20200902170913.1785194-9-berrange@redhat.com> In-Reply-To: <20200902170913.1785194-1-berrange@redhat.com> References: <20200902170913.1785194-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.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=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/09/02 03:24:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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.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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 8c1845830e..1a31f8a5ba 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -576,11 +576,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