From nobody Fri Apr 26 16:39:51 2024 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=1600249721; cv=none; d=zohomail.com; s=zohoarc; b=V8SvwN75nVwWqQg5m4kIJiyNOeOsh77djL+nA6EHtiSXSAq/FRZHGrfpCw1hXrHs/2UJQN0ELjngbbnGqaSbFmZ444L/Gef/XWT3BiZRdf76t/cfirBWIvbWGobjw4eZPRqFMAqNdfxXyvN2R+9MkKMk8zilwBmln9fDFhA/UEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600249721; 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=En9XmbF7Tna3bYhRN9P26rLjCRstqFqylF0ibsHCMeE=; b=kEER78pwd5PU/DCNmlaz6la6USfNRqOrxicB6/XYObbpM75LKqNQQAnwKVF40WHTVljabxUtapjoHpGld4jWoXP7+Cp1Vgf4YNizD2c5TxHWI4YMx/Xinqv8FEACZWY3JQhgEVfPNR8tj8WT3XMDoOmuq6CPEBUwd39pkylAskA= 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 1600249721377415.4957158592316; Wed, 16 Sep 2020 02:48:41 -0700 (PDT) Received: from localhost ([::1]:59032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIU3M-00083G-7S for importer@patchew.org; Wed, 16 Sep 2020 05:48:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIU25-0006JY-3a for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46820) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIU21-0008IQ-AO for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:20 -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-42-lY369xK7P0iez2hKf6c9_A-1; Wed, 16 Sep 2020 05:47:12 -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 850CE186DD21; Wed, 16 Sep 2020 09:47:11 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FFD675123; Wed, 16 Sep 2020 09:47:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600249636; 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=En9XmbF7Tna3bYhRN9P26rLjCRstqFqylF0ibsHCMeE=; b=IrXI1f3L9eck9ei5VuGgO/Qu8afl6hZurXujBqaEzLcqQprtUzegk9xkLGURZ7QnO2mOGi e2V6u/6YMaW4iBmhQmkCnG0ehg0g1yBuN9NS9eMGIBH1uwcABbj9OExXVTcLmsb+7O38dr Lh2zrJ4RC70B5jnN1rAxy882yFPIoQA= X-MC-Unique: lY369xK7P0iez2hKf6c9_A-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 1/8] monitor: simplify functions for getting a dup'd fdset entry Date: Wed, 16 Sep 2020 10:46:58 +0100 Message-Id: <20200916094705.2625331-2-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 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=unavailable 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?= , 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 code has to call monitor_fdset_get_fd, then dup the return fd, and then add the duplicate FD back into the fdset. This dance is overly verbose for the caller and introduces extra failure modes which can be avoided by folding all the logic into monitor_fdset_dup_fd_add and removing monitor_fdset_get_fd entirely. Signed-off-by: Daniel P. Berrang=C3=A9 --- include/monitor/monitor.h | 3 +- include/qemu/osdep.h | 1 + monitor/misc.c | 58 +++++++++++++++++---------------------- stubs/fdset.c | 8 ++---- util/osdep.c | 19 ++----------- 5 files changed, 32 insertions(+), 57 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 1018d754a6..c0170773d4 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -43,8 +43,7 @@ int monitor_read_password(MonitorHMP *mon, ReadLineFunc *= readline_func, AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_i= d, bool has_opaque, const char *opaque, Error **errp); -int monitor_fdset_get_fd(int64_t fdset_id, int flags); -int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd); +int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags); void monitor_fdset_dup_fd_remove(int dup_fd); int64_t monitor_fdset_dup_fd_find(int dup_fd); =20 diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 412962d91a..66ee5bc45d 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -501,6 +501,7 @@ int qemu_open(const char *name, int flags, ...); int qemu_close(int fd); int qemu_unlink(const char *name); #ifndef _WIN32 +int qemu_dup_flags(int fd, int flags); int qemu_dup(int fd); #endif int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive); diff --git a/monitor/misc.c b/monitor/misc.c index e847b58a8c..0b1b9b196c 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -1547,69 +1547,61 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fd= set_id, int64_t fdset_id, return fdinfo; } =20 -int monitor_fdset_get_fd(int64_t fdset_id, int flags) +int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags) { #ifdef _WIN32 return -ENOENT; #else MonFdset *mon_fdset; - MonFdsetFd *mon_fdset_fd; - int mon_fd_flags; - int ret; =20 qemu_mutex_lock(&mon_fdsets_lock); QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { + MonFdsetFd *mon_fdset_fd; + MonFdsetFd *mon_fdset_fd_dup; + int fd =3D -1; + int dup_fd; + int mon_fd_flags; + if (mon_fdset->id !=3D fdset_id) { continue; } + QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) { mon_fd_flags =3D fcntl(mon_fdset_fd->fd, F_GETFL); if (mon_fd_flags =3D=3D -1) { - ret =3D -errno; - goto out; + qemu_mutex_unlock(&mon_fdsets_lock); + return -1; } =20 if ((flags & O_ACCMODE) =3D=3D (mon_fd_flags & O_ACCMODE)) { - ret =3D mon_fdset_fd->fd; - goto out; + fd =3D mon_fdset_fd->fd; + break; } } - ret =3D -EACCES; - goto out; - } - ret =3D -ENOENT; - -out: - qemu_mutex_unlock(&mon_fdsets_lock); - return ret; -#endif -} - -int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd) -{ - MonFdset *mon_fdset; - MonFdsetFd *mon_fdset_fd_dup; =20 - qemu_mutex_lock(&mon_fdsets_lock); - QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { - if (mon_fdset->id !=3D fdset_id) { - continue; + if (fd =3D=3D -1) { + qemu_mutex_unlock(&mon_fdsets_lock); + errno =3D EACCES; + return -1; } - QLIST_FOREACH(mon_fdset_fd_dup, &mon_fdset->dup_fds, next) { - if (mon_fdset_fd_dup->fd =3D=3D dup_fd) { - goto err; - } + + dup_fd =3D qemu_dup_flags(fd, flags); + if (dup_fd =3D=3D -1) { + qemu_mutex_unlock(&mon_fdsets_lock); + return -1; } + mon_fdset_fd_dup =3D g_malloc0(sizeof(*mon_fdset_fd_dup)); mon_fdset_fd_dup->fd =3D dup_fd; QLIST_INSERT_HEAD(&mon_fdset->dup_fds, mon_fdset_fd_dup, next); qemu_mutex_unlock(&mon_fdsets_lock); - return 0; + return dup_fd; } =20 -err: qemu_mutex_unlock(&mon_fdsets_lock); + errno =3D ENOENT; return -1; +#endif } =20 static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove) diff --git a/stubs/fdset.c b/stubs/fdset.c index 67dd5e1d34..56b3663d58 100644 --- a/stubs/fdset.c +++ b/stubs/fdset.c @@ -1,8 +1,9 @@ #include "qemu/osdep.h" #include "monitor/monitor.h" =20 -int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd) +int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags) { + errno =3D ENOSYS; return -1; } =20 @@ -11,11 +12,6 @@ int64_t monitor_fdset_dup_fd_find(int dup_fd) return -1; } =20 -int monitor_fdset_get_fd(int64_t fdset_id, int flags) -{ - return -ENOENT; -} - void monitor_fdset_dup_fd_remove(int dupfd) { } diff --git a/util/osdep.c b/util/osdep.c index 4829c07ff6..3d94b4d732 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -122,7 +122,7 @@ static int fcntl_op_getlk =3D -1; /* * Dups an fd and sets the flags */ -static int qemu_dup_flags(int fd, int flags) +int qemu_dup_flags(int fd, int flags) { int ret; int serrno; @@ -293,7 +293,7 @@ int qemu_open(const char *name, int flags, ...) /* Attempt dup of fd from fd set */ if (strstart(name, "/dev/fdset/", &fdset_id_str)) { int64_t fdset_id; - int fd, dupfd; + int dupfd; =20 fdset_id =3D qemu_parse_fdset(fdset_id_str); if (fdset_id =3D=3D -1) { @@ -301,24 +301,11 @@ int qemu_open(const char *name, int flags, ...) return -1; } =20 - fd =3D monitor_fdset_get_fd(fdset_id, flags); - if (fd < 0) { - errno =3D -fd; - return -1; - } - - dupfd =3D qemu_dup_flags(fd, flags); + dupfd =3D monitor_fdset_dup_fd_add(fdset_id, flags); if (dupfd =3D=3D -1) { return -1; } =20 - ret =3D monitor_fdset_dup_fd_add(fdset_id, dupfd); - if (ret =3D=3D -1) { - close(dupfd); - errno =3D EINVAL; - return -1; - } - return dupfd; } #endif --=20 2.26.2 From nobody Fri Apr 26 16:39:51 2024 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=1600249823; cv=none; d=zohomail.com; s=zohoarc; b=IVbrPa0vncL5TodcLAL7ZpdgIXi60aO223ifsoCbNcVfa2s+Wgxsl8HIpjnwKntCJHjQZ4uAuHICvW9PSpE3g4DJKvXYduxiTGKiSsPqYoLhxSG7e+GjPQxDFR5sCLm190PD9tjuoK+kamUh9LZazO31DoTl/K/uNynk2CebUVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600249823; 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=V+05SS4UCsP/bMVJucHP6bpXPrium8HR8Ap+BdMCfME=; b=aLG9XFY6vQJw6KboyWZKqkdmY/5ccMWdxFNu4STbk9Li9W8utg2NZEU5f0o9OqRfY4INM1kvGZIEFkn4tqIJnfbptrBlgg7pP/blLfvhno8rfyyWTvK9WnrZc6kyn4m/Eg1UjLA2BYQQ4N11OuYVBLURKInAlUrEG6uI+UbROOQ= 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 160024982306380.10824302536184; Wed, 16 Sep 2020 02:50:23 -0700 (PDT) Received: from localhost ([::1]:38978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIU4z-0002uC-F4 for importer@patchew.org; Wed, 16 Sep 2020 05:50:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIU25-0006La-Tg for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:21 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:36687 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 1kIU24-0008K9-4a for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:21 -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-165-Kwge5TyFNEywH6DV9yHUuQ-1; Wed, 16 Sep 2020 05:47:15 -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 4C731186DD21; Wed, 16 Sep 2020 09:47:14 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF0A675141; Wed, 16 Sep 2020 09:47:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600249639; 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=V+05SS4UCsP/bMVJucHP6bpXPrium8HR8Ap+BdMCfME=; b=hat9pJ8N8elSdK/7NuyR8/8K+yHPRJ2Nztz/AjcR+wqZHfV6D5INdwrKTk+UkK6kWVITit 8RB6HqkR1zQso6dIJiL3rq+F6Sxw5J0kS3ebxo0dkqmebJcVIZeujOkp5K1Iw0jqc5GAW/ /zfUCNtJi7mVI1WPQXXpIOoJWK7oRzM= X-MC-Unique: Kwge5TyFNEywH6DV9yHUuQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 2/8] util: split off a helper for dealing with O_CLOEXEC flag Date: Wed, 16 Sep 2020 10:46:59 +0100 Message-Id: <20200916094705.2625331-3-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.001 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/09/16 02:41:36 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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?= , 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) We're going to have multiple callers to open() from qemu_open() soon. Readability would thus benefit from having a helper for dealing with O_CLOEXEC. Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- util/osdep.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/util/osdep.c b/util/osdep.c index 3d94b4d732..0d8fa9f016 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -279,6 +279,20 @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t l= en, bool exclusive) } #endif =20 +static int qemu_open_cloexec(const char *name, int flags, mode_t mode) +{ + int ret; +#ifdef O_CLOEXEC + ret =3D open(name, flags | O_CLOEXEC, mode); +#else + ret =3D open(name, flags, mode); + if (ret >=3D 0) { + qemu_set_cloexec(ret); + } +#endif + return ret; +} + /* * Opens a file with FD_CLOEXEC set */ @@ -318,14 +332,7 @@ int qemu_open(const char *name, int flags, ...) va_end(ap); } =20 -#ifdef O_CLOEXEC - ret =3D open(name, flags | O_CLOEXEC, mode); -#else - ret =3D open(name, flags, mode); - if (ret >=3D 0) { - qemu_set_cloexec(ret); - } -#endif + ret =3D qemu_open_cloexec(name, flags, mode); =20 #ifdef O_DIRECT if (ret =3D=3D -1 && errno =3D=3D EINVAL && (flags & O_DIRECT)) { --=20 2.26.2 From nobody Fri Apr 26 16:39:51 2024 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=1600249953; cv=none; d=zohomail.com; s=zohoarc; b=H+xLSumMAZkVAoajw7tg5moLaGDe5Qoaj2Z6bgphEeh28f8Xtl8yp3cWhN0xA9TnZcOpbaaAypIcTGkSewhxgrMN0rMJ4uteLOsYzFSt5dTC9QUxuJZfFWhgRgtk87ruNuASFViE2b5JukVVgCS91gSGi+NAtL8eCBiL8in379Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600249953; 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=rqMrcRYY7vZu7K/XVF3Zm7hdVdgT7JL/9mm71/ZtzAg=; b=L4Ok8b6NOosoo2Z26YWt8BgQ92Vkzuel0iz9a54IM22gqLQIkl4FsrQPffaVqw3zvzpfIyBT5zA443aRgu2I+EnvS6qMgpzMTDJwG/hz++Vdde9EIkZZUahm41Ph0rdhqqsYqWsu3zT5ZVVBF5i+sleZbqtDdTNDmRI7gbwZPkw= 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 1600249953895229.85950744159447; Wed, 16 Sep 2020 02:52:33 -0700 (PDT) Received: from localhost ([::1]:46370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIU76-00065C-Mq for importer@patchew.org; Wed, 16 Sep 2020 05:52:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIU2C-0006Z9-Ij for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40395) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIU28-0008M7-KN for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:28 -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-176-R8lCPnhrNgeLkwOce_vJ6g-1; Wed, 16 Sep 2020 05:47:18 -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 A8C83425CE; Wed, 16 Sep 2020 09:47:17 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96FA475123; Wed, 16 Sep 2020 09:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600249643; 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=rqMrcRYY7vZu7K/XVF3Zm7hdVdgT7JL/9mm71/ZtzAg=; b=ZcOMTsqCgBj23b99pBcadTqeWBMf6Xi4AZF4onJ+O9jSwuLcyk29sLrouIYXJIUxJUjr3Q 5rGxnhNGuiLZH4nqmf82F4us9qJCVvt7L0D5sgfOwceSJAcUGrvOHqTV30EdVN+sKfzvkn fFsQYKe8xRTEuTegU4IVoL+msd6QFZ8= X-MC-Unique: R8lCPnhrNgeLkwOce_vJ6g-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 3/8] util: rename qemu_open() to qemu_open_old() Date: Wed, 16 Sep 2020 10:47:00 +0100 Message-Id: <20200916094705.2625331-4-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=unavailable 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) We want to introduce a new version of qemu_open() that uses an Error object for reporting problems and make this it the preferred interface. Rename the existing method to release the namespace for the new impl. Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- accel/kvm/kvm-all.c | 2 +- backends/rng-random.c | 2 +- backends/tpm/tpm_passthrough.c | 8 ++++---- block/file-posix.c | 14 +++++++------- block/file-win32.c | 5 +++-- block/vvfat.c | 5 +++-- chardev/char-fd.c | 2 +- chardev/char-pipe.c | 6 +++--- chardev/char.c | 2 +- dump/dump.c | 2 +- hw/s390x/s390-skeys.c | 2 +- hw/usb/host-libusb.c | 2 +- hw/usb/u2f-passthru.c | 4 ++-- hw/vfio/common.c | 4 ++-- include/qemu/osdep.h | 2 +- io/channel-file.c | 2 +- net/vhost-vdpa.c | 2 +- os-posix.c | 2 +- qga/channel-posix.c | 4 ++-- qga/commands-posix.c | 6 +++--- target/arm/kvm.c | 2 +- ui/console.c | 2 +- util/osdep.c | 2 +- util/oslib-posix.c | 2 +- 24 files changed, 44 insertions(+), 42 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 63ef6af9a1..ad8b315b35 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2013,7 +2013,7 @@ static int kvm_init(MachineState *ms) #endif QLIST_INIT(&s->kvm_parked_vcpus); s->vmfd =3D -1; - s->fd =3D qemu_open("/dev/kvm", O_RDWR); + s->fd =3D qemu_open_old("/dev/kvm", O_RDWR); if (s->fd =3D=3D -1) { fprintf(stderr, "Could not access KVM kernel module: %m\n"); ret =3D -errno; diff --git a/backends/rng-random.c b/backends/rng-random.c index 32998d8ee7..245b12ab24 100644 --- a/backends/rng-random.c +++ b/backends/rng-random.c @@ -75,7 +75,7 @@ static void rng_random_opened(RngBackend *b, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "filename", "a valid filename"); } else { - s->fd =3D qemu_open(s->filename, O_RDONLY | O_NONBLOCK); + s->fd =3D qemu_open_old(s->filename, O_RDONLY | O_NONBLOCK); if (s->fd =3D=3D -1) { error_setg_file_open(errp, errno, s->filename); } diff --git a/backends/tpm/tpm_passthrough.c b/backends/tpm/tpm_passthrough.c index 10722e0a41..6d6294ef0a 100644 --- a/backends/tpm/tpm_passthrough.c +++ b/backends/tpm/tpm_passthrough.c @@ -218,7 +218,7 @@ static int tpm_passthrough_open_sysfs_cancel(TPMPassthr= uState *tpm_pt) char path[PATH_MAX]; =20 if (tpm_pt->options->cancel_path) { - fd =3D qemu_open(tpm_pt->options->cancel_path, O_WRONLY); + fd =3D qemu_open_old(tpm_pt->options->cancel_path, O_WRONLY); if (fd < 0) { error_report("tpm_passthrough: Could not open TPM cancel path:= %s", strerror(errno)); @@ -236,11 +236,11 @@ static int tpm_passthrough_open_sysfs_cancel(TPMPasst= hruState *tpm_pt) dev++; if (snprintf(path, sizeof(path), "/sys/class/tpm/%s/device/cancel", dev) < sizeof(path)) { - fd =3D qemu_open(path, O_WRONLY); + fd =3D qemu_open_old(path, O_WRONLY); if (fd < 0) { if (snprintf(path, sizeof(path), "/sys/class/misc/%s/device/ca= ncel", dev) < sizeof(path)) { - fd =3D qemu_open(path, O_WRONLY); + fd =3D qemu_open_old(path, O_WRONLY); } } } @@ -272,7 +272,7 @@ tpm_passthrough_handle_device_opts(TPMPassthruState *tp= m_pt, QemuOpts *opts) } =20 tpm_pt->tpm_dev =3D value ? value : TPM_PASSTHROUGH_DEFAULT_DEVICE; - tpm_pt->tpm_fd =3D qemu_open(tpm_pt->tpm_dev, O_RDWR); + tpm_pt->tpm_fd =3D qemu_open_old(tpm_pt->tpm_dev, O_RDWR); if (tpm_pt->tpm_fd < 0) { error_report("Cannot access TPM device using '%s': %s", tpm_pt->tpm_dev, strerror(errno)); diff --git a/block/file-posix.c b/block/file-posix.c index 9a00d4190a..bac2566f10 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -630,7 +630,7 @@ static int raw_open_common(BlockDriverState *bs, QDict = *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_old(filename, s->open_flags, 0644); ret =3D fd < 0 ? -errno : 0; =20 if (ret < 0) { @@ -1032,13 +1032,13 @@ static int raw_reconfigure_getfd(BlockDriverState *= bs, int flags, } } =20 - /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */ + /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open_old= () */ 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(normalized_filename, *open_flags); + fd =3D qemu_open_old(normalized_filename, *open_flags); if (fd =3D=3D -1) { error_setg_errno(errp, errno, "Could not reopen file"); return -1; @@ -2411,7 +2411,7 @@ 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_old(file_opts->filename, O_RDWR | O_CREAT | O_BINARY,= 0644); if (fd < 0) { result =3D -errno; error_setg_errno(errp, -result, "Could not create file"); @@ -3335,7 +3335,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(test_partition, O_RDONLY | O_BINARY | O_LARGEFILE= ); + fd =3D qemu_open_old(test_partition, O_RDONLY | O_BINARY | O_LARGE= FILE); if (fd >=3D 0) { partition_found =3D true; qemu_close(fd); @@ -3653,7 +3653,7 @@ static int cdrom_probe_device(const char *filename) int prio =3D 0; struct stat st; =20 - fd =3D qemu_open(filename, O_RDONLY | O_NONBLOCK); + fd =3D qemu_open_old(filename, O_RDONLY | O_NONBLOCK); if (fd < 0) { goto out; } @@ -3787,7 +3787,7 @@ static int cdrom_reopen(BlockDriverState *bs) */ if (s->fd >=3D 0) qemu_close(s->fd); - fd =3D qemu_open(bs->filename, s->open_flags, 0644); + fd =3D qemu_open_old(bs->filename, s->open_flags, 0644); if (fd < 0) { s->fd =3D -1; return -EIO; diff --git a/block/file-win32.c b/block/file-win32.c index e2900c3a51..b28603c7d5 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -596,8 +596,9 @@ static int raw_co_create(BlockdevCreateOptions *options= , Error **errp) return -EINVAL; } =20 - fd =3D qemu_open(file_opts->filename, O_WRONLY | O_CREAT | O_TRUNC | O= _BINARY, - 0644); + fd =3D qemu_open_old(file_opts->filename, + O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + 0644); if (fd < 0) { error_setg_errno(errp, errno, "Could not create file"); return -EIO; diff --git a/block/vvfat.c b/block/vvfat.c index 36b53c8757..5abb90e7c7 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1352,7 +1352,8 @@ static int open_file(BDRVVVFATState* s,mapping_t* map= ping) if(!s->current_mapping || strcmp(s->current_mapping->path,mapping->path)) { /* open file */ - int fd =3D qemu_open(mapping->path, O_RDONLY | O_BINARY | O_LARGEF= ILE); + int fd =3D qemu_open_old(mapping->path, + O_RDONLY | O_BINARY | O_LARGEFILE); if(fd<0) return -1; vvfat_close_current_file(s); @@ -2513,7 +2514,7 @@ static int commit_one_file(BDRVVVFATState* s, for (i =3D s->cluster_size; i < offset; i +=3D s->cluster_size) c =3D modified_fat_get(s, c); =20 - fd =3D qemu_open(mapping->path, O_RDWR | O_CREAT | O_BINARY, 0666); + fd =3D qemu_open_old(mapping->path, O_RDWR | O_CREAT | O_BINARY, 0666); if (fd < 0) { fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path, strerror(errno), errno); diff --git a/chardev/char-fd.c b/chardev/char-fd.c index c2d8101106..1cd62f2779 100644 --- a/chardev/char-fd.c +++ b/chardev/char-fd.c @@ -119,7 +119,7 @@ int qmp_chardev_open_file_source(char *src, int flags, = Error **errp) { int fd =3D -1; =20 - TFR(fd =3D qemu_open(src, flags, 0666)); + TFR(fd =3D qemu_open_old(src, flags, 0666)); if (fd =3D=3D -1) { error_setg_file_open(errp, errno, src); } diff --git a/chardev/char-pipe.c b/chardev/char-pipe.c index fd12c9e63b..7eca5d9a56 100644 --- a/chardev/char-pipe.c +++ b/chardev/char-pipe.c @@ -132,8 +132,8 @@ static void qemu_chr_open_pipe(Chardev *chr, =20 filename_in =3D g_strdup_printf("%s.in", filename); filename_out =3D g_strdup_printf("%s.out", filename); - TFR(fd_in =3D qemu_open(filename_in, O_RDWR | O_BINARY)); - TFR(fd_out =3D qemu_open(filename_out, O_RDWR | O_BINARY)); + TFR(fd_in =3D qemu_open_old(filename_in, O_RDWR | O_BINARY)); + TFR(fd_out =3D qemu_open_old(filename_out, O_RDWR | O_BINARY)); g_free(filename_in); g_free(filename_out); if (fd_in < 0 || fd_out < 0) { @@ -143,7 +143,7 @@ static void qemu_chr_open_pipe(Chardev *chr, if (fd_out >=3D 0) { close(fd_out); } - TFR(fd_in =3D fd_out =3D qemu_open(filename, O_RDWR | O_BINARY)); + TFR(fd_in =3D fd_out =3D qemu_open_old(filename, O_RDWR | O_BINARY= )); if (fd_in < 0) { error_setg_file_open(errp, errno, filename); return; diff --git a/chardev/char.c b/chardev/char.c index 77e7ec814f..6b85099c03 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -235,7 +235,7 @@ static void qemu_char_open(Chardev *chr, ChardevBackend= *backend, } else { flags |=3D O_TRUNC; } - chr->logfd =3D qemu_open(common->logfile, flags, 0666); + chr->logfd =3D qemu_open_old(common->logfile, flags, 0666); if (chr->logfd < 0) { error_setg_errno(errp, errno, "Unable to open logfile %s", diff --git a/dump/dump.c b/dump/dump.c index 383bc7876b..13fda440a4 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1994,7 +1994,7 @@ void qmp_dump_guest_memory(bool paging, const char *f= ile, #endif =20 if (strstart(file, "file:", &p)) { - fd =3D qemu_open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRU= SR); + fd =3D qemu_open_old(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S= _IRUSR); if (fd < 0) { error_setg_file_open(errp, errno, p); return; diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index db2f49cb27..5cc559fe4c 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -125,7 +125,7 @@ void qmp_dump_skeys(const char *filename, Error **errp) return; } =20 - fd =3D qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600); + fd =3D qemu_open_old(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd < 0) { error_setg_file_open(errp, errno, filename); return; diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index 43c93504a2..8b02bee547 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -1147,7 +1147,7 @@ static void usb_host_realize(USBDevice *udev, Error *= *errp) if (s->hostdevice) { int fd; s->needs_autoscan =3D false; - fd =3D qemu_open(s->hostdevice, O_RDWR); + fd =3D qemu_open_old(s->hostdevice, O_RDWR); if (fd < 0) { error_setg_errno(errp, errno, "failed to open %s", s->hostdevi= ce); return; diff --git a/hw/usb/u2f-passthru.c b/hw/usb/u2f-passthru.c index e9c8aa4595..ae00e93f35 100644 --- a/hw/usb/u2f-passthru.c +++ b/hw/usb/u2f-passthru.c @@ -383,7 +383,7 @@ static int u2f_passthru_open_from_device(struct udev_de= vice *device) { const char *devnode =3D udev_device_get_devnode(device); =20 - int fd =3D qemu_open(devnode, O_RDWR); + int fd =3D qemu_open_old(devnode, O_RDWR); if (fd < 0) { return -1; } else if (!u2f_passthru_is_u2f_device(fd)) { @@ -482,7 +482,7 @@ static void u2f_passthru_realize(U2FKeyState *base, Err= or **errp) return; #endif } else { - fd =3D qemu_open(key->hidraw, O_RDWR); + fd =3D qemu_open_old(key->hidraw, O_RDWR); if (fd < 0) { error_setg(errp, "%s: Failed to open %s", TYPE_U2F_PASSTHRU, key->hidraw); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 33357140b8..13471ae294 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1254,7 +1254,7 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, } } =20 - fd =3D qemu_open("/dev/vfio/vfio", O_RDWR); + fd =3D qemu_open_old("/dev/vfio/vfio", O_RDWR); if (fd < 0) { error_setg_errno(errp, errno, "failed to open /dev/vfio/vfio"); ret =3D -errno; @@ -1479,7 +1479,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *= as, Error **errp) group =3D g_malloc0(sizeof(*group)); =20 snprintf(path, sizeof(path), "/dev/vfio/%d", groupid); - group->fd =3D qemu_open(path, O_RDWR); + group->fd =3D qemu_open_old(path, O_RDWR); if (group->fd < 0) { error_setg_errno(errp, errno, "failed to open %s", path); goto free_group_exit; diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 66ee5bc45d..ae1234104c 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -497,7 +497,7 @@ 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 -int qemu_open(const char *name, int flags, ...); +int qemu_open_old(const char *name, int flags, ...); int qemu_close(int fd); int qemu_unlink(const char *name); #ifndef _WIN32 diff --git a/io/channel-file.c b/io/channel-file.c index dac21f6012..2ed3b75e8b 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -51,7 +51,7 @@ qio_channel_file_new_path(const char *path, =20 ioc =3D QIO_CHANNEL_FILE(object_new(TYPE_QIO_CHANNEL_FILE)); =20 - ioc->fd =3D qemu_open(path, flags, mode); + ioc->fd =3D qemu_open_old(path, flags, mode); if (ioc->fd < 0) { object_unref(OBJECT(ioc)); error_setg_errno(errp, errno, diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index bc0e0d2d35..e2b3ba85bf 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -184,7 +184,7 @@ static int net_vhost_vdpa_init(NetClientState *peer, co= nst char *device, snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); nc->queue_index =3D 0; s =3D DO_UPCAST(VhostVDPAState, nc, nc); - vdpa_device_fd =3D qemu_open(vhostdev, O_RDWR); + vdpa_device_fd =3D qemu_open_old(vhostdev, O_RDWR); if (vdpa_device_fd =3D=3D -1) { return -errno; } diff --git a/os-posix.c b/os-posix.c index bf98508b6d..0bfd8e2d3c 100644 --- a/os-posix.c +++ b/os-posix.c @@ -297,7 +297,7 @@ void os_setup_post(void) error_report("not able to chdir to /: %s", strerror(errno)); exit(1); } - TFR(fd =3D qemu_open("/dev/null", O_RDWR)); + TFR(fd =3D qemu_open_old("/dev/null", O_RDWR)); if (fd =3D=3D -1) { exit(1); } diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 8fc205ad21..0373975360 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -127,7 +127,7 @@ static gboolean ga_channel_open(GAChannel *c, const gch= ar *path, switch (c->method) { case GA_CHANNEL_VIRTIO_SERIAL: { assert(fd < 0); - fd =3D qemu_open(path, O_RDWR | O_NONBLOCK + fd =3D qemu_open_old(path, O_RDWR | O_NONBLOCK #ifndef CONFIG_SOLARIS | O_ASYNC #endif @@ -157,7 +157,7 @@ static gboolean ga_channel_open(GAChannel *c, const gch= ar *path, struct termios tio; =20 assert(fd < 0); - fd =3D qemu_open(path, O_RDWR | O_NOCTTY | O_NONBLOCK); + fd =3D qemu_open_old(path, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd =3D=3D -1) { g_critical("error opening channel: %s", strerror(errno)); return false; diff --git a/qga/commands-posix.c b/qga/commands-posix.c index af5a58a9fd..3bffee99d4 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1365,7 +1365,7 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mount= points, } } =20 - fd =3D qemu_open(mount->dirname, O_RDONLY); + fd =3D qemu_open_old(mount->dirname, O_RDONLY); if (fd =3D=3D -1) { error_setg_errno(errp, errno, "failed to open %s", mount->dirn= ame); goto error; @@ -1432,7 +1432,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) =20 QTAILQ_FOREACH(mount, &mounts, next) { logged =3D false; - fd =3D qemu_open(mount->dirname, O_RDONLY); + fd =3D qemu_open_old(mount->dirname, O_RDONLY); if (fd =3D=3D -1) { continue; } @@ -1522,7 +1522,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, E= rror **errp) list->next =3D response->paths; response->paths =3D list; =20 - fd =3D qemu_open(mount->dirname, O_RDONLY); + fd =3D qemu_open_old(mount->dirname, O_RDONLY); if (fd =3D=3D -1) { result->error =3D g_strdup_printf("failed to open: %s", strerror(errno)); diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 2eae73315d..0dcb9bfe13 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -71,7 +71,7 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpu= s_to_try, { int ret =3D 0, kvmfd =3D -1, vmfd =3D -1, cpufd =3D -1; =20 - kvmfd =3D qemu_open("/dev/kvm", O_RDWR); + kvmfd =3D qemu_open_old("/dev/kvm", O_RDWR); if (kvmfd < 0) { goto err; } diff --git a/ui/console.c b/ui/console.c index f8d7643fe4..7592c3c324 100644 --- a/ui/console.c +++ b/ui/console.c @@ -373,7 +373,7 @@ void qmp_screendump(const char *filename, bool has_devi= ce, const char *device, return; } =20 - fd =3D qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 06= 66); + fd =3D qemu_open_old(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY= , 0666); if (fd =3D=3D -1) { error_setg(errp, "failed to open file '%s': %s", filename, strerror(errno)); diff --git a/util/osdep.c b/util/osdep.c index 0d8fa9f016..7504c156e8 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -296,7 +296,7 @@ static int qemu_open_cloexec(const char *name, int flag= s, mode_t mode) /* * Opens a file with FD_CLOEXEC set */ -int qemu_open(const char *name, int flags, ...) +int qemu_open_old(const char *name, int flags, ...) { int ret; int mode =3D 0; diff --git a/util/oslib-posix.c b/util/oslib-posix.c index ad8001a4ad..f5f676f079 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -125,7 +125,7 @@ bool qemu_write_pidfile(const char *path, Error **errp) .l_len =3D 0, }; =20 - fd =3D qemu_open(path, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); + fd =3D qemu_open_old(path, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); if (fd =3D=3D -1) { error_setg_errno(errp, errno, "Cannot open pid file"); return false; --=20 2.26.2 From nobody Fri Apr 26 16:39:51 2024 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=1600249731; cv=none; d=zohomail.com; s=zohoarc; b=KF1uoalank/vVfrCyR7GgKjVxiXknc/dD8/X8xM4HwA7Bfutt2yYiCBqFRM9qmxjUg+V09M5PeUmIXm01YmhZb6lItfOTeqJymmfEAkm2TiHpb+NesIV8VQG1vGoCDVlKBJFZ58LD46uN8JuVxFyhV7Ec3gud0VO9NDbi6CcjOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600249731; 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=OBlwjFxU47XSKApD1+IlD4HJKgm38Z1/BvcNTQ3pVb0=; b=FRWc2orJ0XxkzsUGUdoBwIV5RxZYyKRkgntszbQKF/WdL/HnBnVwsp1GZsAi6BhI+Qjthv7ve9RcDapSXHERGVtqej9iMg97nDzKOYHD4K0vr29Usl/7ZnAMYBVTpR/rSrQWppAsVQ5hrwdw5esH4SxTRWBL8nwt+Fe56U0G+r0= 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 1600249731011121.34767934128513; Wed, 16 Sep 2020 02:48:51 -0700 (PDT) Received: from localhost ([::1]:59632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIU3V-0008Hq-TG for importer@patchew.org; Wed, 16 Sep 2020 05:48:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIU2B-0006Wm-7i for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48011) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIU28-0008Lx-AX for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:26 -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-226-XGKY2quZMOWkB7N7CkrsTA-1; Wed, 16 Sep 2020 05:47:21 -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 8812F1006701; Wed, 16 Sep 2020 09:47:20 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id F269B75123; Wed, 16 Sep 2020 09:47:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600249643; 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=OBlwjFxU47XSKApD1+IlD4HJKgm38Z1/BvcNTQ3pVb0=; b=IyUPgtg0+T09le6q6qtnO5b6wpV19gdlpya/3GYqVzLmtGDix+j3ohK8MfzdMWoYv7/a/5 zf0QlLCN/cWFI0sGTDSQTbG8nXcxo+cwXFH7kiZL0tMGpGXuRvowGZrfzEZS5KmrecZvW+ 00MqsRjz7Qg4ym0FHAGnk7+MrfnzS6k= X-MC-Unique: XGKY2quZMOWkB7N7CkrsTA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 4/8] util: refactor qemu_open_old to split off variadic args handling Date: Wed, 16 Sep 2020 10:47:01 +0100 Message-Id: <20200916094705.2625331-5-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.001 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?= , 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) This simple refactoring prepares for future patches. The variadic args handling is split from the main bulk of the open logic. Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- util/osdep.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/util/osdep.c b/util/osdep.c index 7504c156e8..11531e8f59 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -296,10 +296,10 @@ static int qemu_open_cloexec(const char *name, int fl= ags, mode_t mode) /* * Opens a file with FD_CLOEXEC set */ -int qemu_open_old(const char *name, int flags, ...) +static int +qemu_open_internal(const char *name, int flags, mode_t mode) { int ret; - int mode =3D 0; =20 #ifndef _WIN32 const char *fdset_id_str; @@ -324,15 +324,25 @@ int qemu_open_old(const char *name, int flags, ...) } #endif =20 - if (flags & O_CREAT) { - va_list ap; + ret =3D qemu_open_cloexec(name, flags, mode); + + return ret; +} + =20 - va_start(ap, flags); +int qemu_open_old(const char *name, int flags, ...) +{ + va_list ap; + mode_t mode =3D 0; + int ret; + + va_start(ap, flags); + if (flags & O_CREAT) { mode =3D va_arg(ap, int); - va_end(ap); } + va_end(ap); =20 - ret =3D qemu_open_cloexec(name, flags, mode); + ret =3D qemu_open_internal(name, flags, mode); =20 #ifdef O_DIRECT if (ret =3D=3D -1 && errno =3D=3D EINVAL && (flags & O_DIRECT)) { --=20 2.26.2 From nobody Fri Apr 26 16:39:51 2024 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=1600249756; cv=none; d=zohomail.com; s=zohoarc; b=jEUCdwjuCaQIKfMwPePkGjldkddp4+d2lH6Xp0t/gviGYX2+8KAzKYftwj4tnEHOLUPmnlUfDODdzx/rhL2QPf0UuwRjCPOUuNubukkTh0AYVJvaObvJmwwSvQ6PYYKfZpfNoObOrsnfqwnGr4iLeMvR8cirRpEaMjnBfDe2YtM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600249756; 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=dWG3F29NuQdM++zSGzyguvFvgwq86vzl492BOIPsLuA=; b=MpCYWq/AyEkIRwHz9MP/YX+uvywFRLY9rKBf7h10E68oi553L4i/kTCbKtkkPN43YCqOnYdL00FMccKeh90+mgjb8YyyurUptkYVRfZeZDMJoMd585JgUpbqsRj9tx68XCkjwJ0lBBi3bvZqdVkuJCplStE0U9AEhJadNBSpT/s= 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 1600249756839655.1039626167401; Wed, 16 Sep 2020 02:49:16 -0700 (PDT) Received: from localhost ([::1]:60848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIU3v-0000Kx-Lx for importer@patchew.org; Wed, 16 Sep 2020 05:49:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIU2G-0006eS-PL for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:33 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:22298 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 1kIU2D-0008P0-P8 for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47: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-454-m6c9JIhPNkqgbHx_Uxy1Bg-1; Wed, 16 Sep 2020 05:47:24 -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 369E81006706; Wed, 16 Sep 2020 09:47:23 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2F1F75141; Wed, 16 Sep 2020 09:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600249648; 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=dWG3F29NuQdM++zSGzyguvFvgwq86vzl492BOIPsLuA=; b=fVsoqiT7fx6uFDkcz7SSp9QSh9bzjVA7/gNUveEmF0jGQKBfLyfMLnJEDaVGYHvfW2KJA5 /sdH7K0Ll11sVkvb2BwsXvC8BH8UpfY9DbXr7wH2zauy+/oK3wLjzTd1q8WsarEMQoKIGO nvXGKZkjDKoKkNVwSy8+CP/Zy2dmubs= X-MC-Unique: m6c9JIhPNkqgbHx_Uxy1Bg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 5/8] util: add Error object for qemu_open_internal error reporting Date: Wed, 16 Sep 2020 10:47:02 +0100 Message-Id: <20200916094705.2625331-6-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=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/16 00:53:39 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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?= , 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) Instead of relying on the limited information from errno, we can now also provide detailed error messages to callers that ask for it. Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- util/osdep.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/util/osdep.c b/util/osdep.c index 11531e8f59..28aa89adc9 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 @@ -297,7 +298,7 @@ static int qemu_open_cloexec(const char *name, int flag= s, mode_t mode) * Opens a file with FD_CLOEXEC set */ static int -qemu_open_internal(const char *name, int flags, mode_t mode) +qemu_open_internal(const char *name, int flags, mode_t mode, Error **errp) { int ret; =20 @@ -311,12 +312,15 @@ qemu_open_internal(const char *name, int flags, mode_= t mode) =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 dupfd =3D monitor_fdset_dup_fd_add(fdset_id, flags); if (dupfd =3D=3D -1) { + error_setg_errno(errp, errno, "Could not dup FD for %s flags %= x", + name, flags); return -1; } =20 @@ -326,6 +330,13 @@ qemu_open_internal(const char *name, int flags, mode_t= mode) =20 ret =3D qemu_open_cloexec(name, flags, mode); =20 + if (ret =3D=3D -1) { + const char *action =3D flags & O_CREAT ? "create" : "open"; + error_setg_errno(errp, errno, "Could not %s '%s'", + action, name); + } + + return ret; } =20 @@ -342,7 +353,7 @@ int qemu_open_old(const char *name, int flags, ...) } va_end(ap); =20 - ret =3D qemu_open_internal(name, flags, mode); + ret =3D qemu_open_internal(name, flags, mode, NULL); =20 #ifdef O_DIRECT if (ret =3D=3D -1 && errno =3D=3D EINVAL && (flags & O_DIRECT)) { --=20 2.26.2 From nobody Fri Apr 26 16:39:51 2024 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=1600249960; cv=none; d=zohomail.com; s=zohoarc; b=kveRYA5ZI/t75M2VpyeQ8gDviU6g55QTNXmoJeMljQTzy2wCVIdauUMLh54As+NlLu1LXKncp/PaFhxBxjrdoGQ/FVs0OlzT/ytos3te9DhBtlro4+Hs6YeUvzV6fniyGvmL1w2PMygMMn6zntMpibDjCDpOt+VaJM2HIIq8Kzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600249960; 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=ncL3MwxzJsCd1kf/SACKaGDcExKE2Jw+i5yqXBhHZf8=; b=PlnuDAuwoAvjmLOd6zHvYPU/Kwv6sw6kAukvcsT10rCkTX5BF//U0QPHijalP93PkLrJThTNK/Kk28Lh+8MEBh632M+jj59tGrcN26OZUyTysFZB3Cac0yMJ3l+E1Odh6At3ysBIUjrR7aO5C69DA642/3TkIivC2+1ww7yw1ZQ= 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 1600249960275528.8341944859653; Wed, 16 Sep 2020 02:52:40 -0700 (PDT) Received: from localhost ([::1]:46838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIU7D-0006Gz-8B for importer@patchew.org; Wed, 16 Sep 2020 05:52:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIU2H-0006f5-Nq for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:33 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:59349 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 1kIU2D-0008P1-PD for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47: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-326-MecEK4kdPU60bv2DL-xYIw-1; Wed, 16 Sep 2020 05:47:27 -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 2EC211006702; Wed, 16 Sep 2020 09:47:26 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8196175123; Wed, 16 Sep 2020 09:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600249649; 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=ncL3MwxzJsCd1kf/SACKaGDcExKE2Jw+i5yqXBhHZf8=; b=bGw5CKFi8+XV4HUiJcr4kNMayZmk55qPUYOerUc2lrLDmDcKqgEtqJ6c62iqRZVK7CFADE Dnm03bBnmW6LwZ+w2gPH2dH2ncyhEfwmCEFnFCIIEA1Ki+vHfquqKkOws2hCtjsFMwJByw 8XD9d/s1k8pMXfeVXdjjfgpuCmhPXWM= X-MC-Unique: MecEK4kdPU60bv2DL-xYIw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 6/8] util: introduce qemu_open and qemu_create with error reporting Date: Wed, 16 Sep 2020 10:47:03 +0100 Message-Id: <20200916094705.2625331-7-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.001 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/16 00:53:39 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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?= , 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) qemu_open_old() works like open(): set errno and return -1 on failure. It has even more failure modes, though. Reporting the error clearly to users is basically impossible for many of them. Our standard cure for "errno is too coarse" is the Error object. Introduce two new helper methods: int qemu_open(const char *name, int flags, Error **errp); int qemu_create(const char *name, int flags, mode_t mode, Error **errp); Note that with this design we no longer require or even accept the O_CREAT flag. Avoiding overloading the two distinct operations means we can avoid variable arguments which would prevent 'errp' from being the last argument. It also gives us a guarantee that the 'mode' is given when creating files, avoiding a latent security bug. Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/osdep.h | 6 ++++++ util/osdep.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index ae1234104c..577d9e8315 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -497,7 +497,13 @@ 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 +/* + * Don't introduce new usage of this function, prefer the following + * qemu_open/qemu_create that take an "Error **errp" + */ int qemu_open_old(const char *name, int flags, ...); +int qemu_open(const char *name, int flags, Error **errp); +int qemu_create(const char *name, int flags, mode_t mode, Error **errp); int qemu_close(int fd); int qemu_unlink(const char *name); #ifndef _WIN32 diff --git a/util/osdep.c b/util/osdep.c index 28aa89adc9..c99f1e7db2 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -341,6 +341,22 @@ qemu_open_internal(const char *name, int flags, mode_t= mode, Error **errp) } =20 =20 +int qemu_open(const char *name, int flags, Error **errp) +{ + assert(!(flags & O_CREAT)); + + return qemu_open_internal(name, flags, 0, errp); +} + + +int qemu_create(const char *name, int flags, mode_t mode, Error **errp) +{ + assert(!(flags & O_CREAT)); + + return qemu_open_internal(name, flags | O_CREAT, mode, errp); +} + + int qemu_open_old(const char *name, int flags, ...) { va_list ap; --=20 2.26.2 From nobody Fri Apr 26 16:39:51 2024 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=1600250058; cv=none; d=zohomail.com; s=zohoarc; b=A0bEEVp5ZYztsJeq50PvLjzaXhbxXCKI5kUF6ZriF4E1hDLWmRCVwUFJzk2fVPHZJQPFOoA2NEwed5eQx+nozsr2llTJpYPl85JfFEmOG/kx8oL2trY8IV1s9zLUAkC970NYWBwsVzsyXg4EO9yq2MbQvvPPxGtma0v1qouN25M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600250058; 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=3JXPYA2yrsOAf5k3nPhmksH7m/JuM8SwBbaZNJhTJO8=; b=lUk4VvNg1pGNGse6csxDXetOyBDuvL7yoCQ51ioOZCqTPkf+Itu0dixP03/KmWFxdhqx98ybMwmWyHIfa8t0H1FhV/271NHqLQsPCO/uprFTEX7YYLDZL0MeKBOWN6kTTSLUksE7UNEkGYkSlYZnNRMHp9GraG3PuBGnUZ8zo5Y= 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 1600250058606409.77272178369435; Wed, 16 Sep 2020 02:54:18 -0700 (PDT) Received: from localhost ([::1]:52310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIU8n-00007v-B9 for importer@patchew.org; Wed, 16 Sep 2020 05:54:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIU2J-0006i1-5J for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39185) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIU2H-0008Pr-DC for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:47:34 -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-101-GhTuMSsfNduf39b4GBHcnA-1; Wed, 16 Sep 2020 05:47:30 -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 420F7425CE; Wed, 16 Sep 2020 09:47:29 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F14D75123; Wed, 16 Sep 2020 09:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600249651; 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=3JXPYA2yrsOAf5k3nPhmksH7m/JuM8SwBbaZNJhTJO8=; b=i0QStMeaQNEIe6d1kjuUgBC0C8wvun0diO4DGOC2h/D+olZeZlFG6JzKXBwl/eGLQJb9MD 1CSWxBeXTgDrp4gc6e6C73SqxHLrPpiA24Kr/NIoCnFli0SxDVw1d9UfRBTjasdti5WoAp 1apVNenuNakUsRXAAjLS472TQj51378= X-MC-Unique: GhTuMSsfNduf39b4GBHcnA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 7/8] util: give a specific error message when O_DIRECT doesn't work Date: Wed, 16 Sep 2020 10:47:04 +0100 Message-Id: <20200916094705.2625331-8-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.001 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=216.205.24.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:16:02 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?= , 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) A common error scenario is to tell QEMU to use O_DIRECT in combination with a filesystem that doesn't support it. To aid users to diagnosing their mistake we want to provide a clear error message when this happens. Reviewed-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 --- util/osdep.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/util/osdep.c b/util/osdep.c index c99f1e7db2..8ea7a807c1 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -332,11 +332,24 @@ qemu_open_internal(const char *name, int flags, mode_= t mode, Error **errp) =20 if (ret =3D=3D -1) { const char *action =3D flags & O_CREAT ? "create" : "open"; +#ifdef O_DIRECT + /* Give more helpful error message for O_DIRECT */ + if (errno =3D=3D EINVAL && (flags & O_DIRECT)) { + ret =3D open(name, flags & ~O_DIRECT, mode); + if (ret !=3D -1) { + close(ret); + error_setg(errp, "Could not %s '%s': " + "filesystem does not support O_DIRECT", + action, name); + errno =3D EINVAL; /* restore first open()'s errno */ + return -1; + } + } +#endif /* O_DIRECT */ error_setg_errno(errp, errno, "Could not %s '%s'", action, name); } =20 - return ret; } =20 --=20 2.26.2 From nobody Fri Apr 26 16:39:51 2024 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