From nobody Sun Dec 22 01:19:17 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652465998; cv=none; d=zohomail.com; s=zohoarc; b=aTY4vhPWvZOhn4SV8Bu+PYX1V7RVtbXLxs1yyfNbudLUESKZ56lygQG6QkqeBuHbZp1CqWb3yguHv/87iRxSIS8wSUCRDPCKdjHRO3wQaagiqh+6y2zp4UfLIshltFH2PezuRan76cLQdMhfrCMTyOkLfGLfLph6DTE6Fq+XgeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652465998; 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=zLW3ERMVmhDAAG+REaOZKcjlv8XYBvV4yL5VFMVvzr8=; b=SCULXDapZmrEvfBEqf7k7EHBE77948cs5o/5cjU/ISSVC4G7a4kpFSVXOJX1O6cD05O+QiP6qreoW5ro25YI7ZIElcAa4K9oOHUQ79OoSp6LKcSSN62kP/zzoc8SyQK2iWj1aq6IpVuzfeH6jnvihUi4/yOuxrqc2TZKUtoVZ1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652465998800919.2090039686333; Fri, 13 May 2022 11:19:58 -0700 (PDT) Received: from localhost ([::1]:54810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npZtN-0000av-An for importer2@patchew.org; Fri, 13 May 2022 14:19:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npZic-00018u-4U for qemu-devel@nongnu.org; Fri, 13 May 2022 14:08:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:50111) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npZia-00071G-6O for qemu-devel@nongnu.org; Fri, 13 May 2022 14:08:49 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-467-NyMu8-p6OIaZ2T9Y2gN9eA-1; Fri, 13 May 2022 14:08:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7F3086B8BC; Fri, 13 May 2022 18:08:45 +0000 (UTC) Received: from localhost (unknown [10.39.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EA1E7AD5; Fri, 13 May 2022 18:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652465327; 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=zLW3ERMVmhDAAG+REaOZKcjlv8XYBvV4yL5VFMVvzr8=; b=jIQd++RCjyD8iRsX2ZgVJ/9K9dTH1wM8nQSkFEI40kwOPiUiHjjcMuiQbBQcAwwl5v6O3j ISiIOFF2vGI67zfztcpx6uXMN1gmCLWKe0/rLqiDNtXPMuviFAMXms2h26JWg1Eyadkhgr yefKH7qmh3MqQJBZM1Xp4+m6loj1mNc= X-MC-Unique: NyMu8-p6OIaZ2T9Y2gN9eA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Michael Roth , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v3 08/15] qga: replace qemu_open_old() with qemu_open_cloexec() Date: Fri, 13 May 2022 20:08:14 +0200 Message-Id: <20220513180821.905149-9-marcandre.lureau@redhat.com> In-Reply-To: <20220513180821.905149-1-marcandre.lureau@redhat.com> References: <20220513180821.905149-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652465999282100001 From: Marc-Andr=C3=A9 Lureau qemu_open_old() uses qemu_open_internal() which handles special "/dev/fdset/" path for monitor fd sets, set CLOEXEC, and uses Error reporting (and some O_DIRECT special error casing). The monitor fdset handling is unnecessary for qga, use qemu_open_cloexec() instead. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Konstantin Kostiuk --- qga/channel-posix.c | 14 +++++++++----- qga/commands-posix.c | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 039e1ddcb2..affee485fc 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -1,4 +1,5 @@ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include #include "qapi/error.h" #include "qemu/sockets.h" @@ -128,11 +129,15 @@ static gboolean ga_channel_open(GAChannel *c, const g= char *path, switch (c->method) { case GA_CHANNEL_VIRTIO_SERIAL: { assert(fd < 0); - fd =3D qemu_open_old(path, O_RDWR | O_NONBLOCK + fd =3D qemu_open_cloexec( + path, #ifndef CONFIG_SOLARIS - | O_ASYNC + O_ASYNC | #endif - ); + O_RDWR | O_NONBLOCK, + 0, + errp + ); if (fd =3D=3D -1) { error_setg_errno(errp, errno, "error opening channel"); return false; @@ -157,9 +162,8 @@ static gboolean ga_channel_open(GAChannel *c, const gch= ar *path, struct termios tio; =20 assert(fd < 0); - fd =3D qemu_open_old(path, O_RDWR | O_NOCTTY | O_NONBLOCK); + fd =3D qemu_open_cloexec(path, O_RDWR | O_NOCTTY | O_NONBLOCK, 0, = errp); if (fd =3D=3D -1) { - error_setg_errno(errp, errno, "error opening channel"); return false; } tcgetattr(fd, &tio); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 7761458ce1..e8eafad74d 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1394,6 +1394,7 @@ static GuestDiskInfoList *get_disk_partitions( =20 static void get_nvme_smart(GuestDiskInfo *disk) { + Error *err =3D NULL; int fd; GuestNVMeSmart *smart; NvmeSmartLog log =3D {0}; @@ -1406,9 +1407,10 @@ static void get_nvme_smart(GuestDiskInfo *disk) | (((sizeof(log) >> 2) - 1) << 16) }; =20 - fd =3D qemu_open_old(disk->name, O_RDONLY); + fd =3D qemu_open_cloexec(disk->name, O_RDONLY, 0, &err); if (fd =3D=3D -1) { - g_debug("Failed to open device: %s: %s", disk->name, g_strerror(er= rno)); + g_debug("Failed to open device: %s: %s", disk->name, error_get_pre= tty(err)); + error_free(err); return; } =20 @@ -1739,9 +1741,8 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mount= points, } } =20 - fd =3D qemu_open_old(mount->dirname, O_RDONLY); + fd =3D qemu_open_cloexec(mount->dirname, O_RDONLY, 0, errp); if (fd =3D=3D -1) { - error_setg_errno(errp, errno, "failed to open %s", mount->dirn= ame); goto error; } =20 @@ -1806,7 +1807,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) =20 QTAILQ_FOREACH(mount, &mounts, next) { logged =3D false; - fd =3D qemu_open_old(mount->dirname, O_RDONLY); + fd =3D qemu_open_cloexec(mount->dirname, O_RDONLY, 0, NULL); if (fd =3D=3D -1) { continue; } @@ -1866,21 +1867,20 @@ static void guest_fsfreeze_cleanup(void) GuestFilesystemTrimResponse * qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) { + ERRP_GUARD(); GuestFilesystemTrimResponse *response; GuestFilesystemTrimResult *result; int ret =3D 0; FsMountList mounts; struct FsMount *mount; int fd; - Error *local_err =3D NULL; struct fstrim_range r; =20 slog("guest-fstrim called"); =20 QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { - error_propagate(errp, local_err); + build_fs_mount_list(&mounts, errp); + if (*errp) { return NULL; } =20 @@ -1892,11 +1892,11 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum,= Error **errp) =20 QAPI_LIST_PREPEND(response->paths, result); =20 - fd =3D qemu_open_old(mount->dirname, O_RDONLY); + fd =3D qemu_open_cloexec(mount->dirname, O_RDONLY, 0, errp); if (fd =3D=3D -1) { - result->error =3D g_strdup_printf("failed to open: %s", - strerror(errno)); + result->error =3D g_strdup(error_get_pretty(*errp)); result->has_error =3D true; + g_clear_pointer(errp, error_free); continue; } =20 --=20 2.36.1