From nobody Thu May 16 02:24:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644582646; cv=none; d=zohomail.com; s=zohoarc; b=frnDmIPANKNTrxrMnxE9IyDKydSnnEQ8U3WaVKZuSh3Z41UUnsC7PNE5j2qe9HVL1JjqCopGqTh6Ic0sPvchlptIqRwT+W4N+H9ES/y4wth7OBSnLnowCBbC2tWPorRtRLMrULSWDuox5ndoNsGK3PXxeWpgjNA63L1wxK7TQLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644582646; h=Content-Type:Content-Transfer-Encoding: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=Uyyv4yoFtKIg+DINM522FF3Xqz6scwhYelZ3ggf9NNM=; b=PaDGHCvWg6eZ4r47ygshAxriflSvkUHWNNsCd34xuSkzVKlG+gqYlIq0uKB4p48PuT3J//0U4ML3T7xh9XcqXFizJqPx6Vf5NjtaPSgO6ImcNtZDu3mZnnkRXgSpP1wcXB5M4XvWruIfLSyrOy8sYkwkadXixt9KbIVolTtXNdA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644582646293708.2444019540599; Fri, 11 Feb 2022 04:30:46 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-404-Vaj_NrllNIOpLvb2naVVPg-1; Fri, 11 Feb 2022 07:30:44 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B0B41014E62; Fri, 11 Feb 2022 12:30:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51F8C105910A; Fri, 11 Feb 2022 12:30:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2018A1809CB8; Fri, 11 Feb 2022 12:30:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BCUYwL008914 for ; Fri, 11 Feb 2022 07:30:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4CD5E105910E; Fri, 11 Feb 2022 12:30:34 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9EA21059110 for ; Fri, 11 Feb 2022 12:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644582646; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Uyyv4yoFtKIg+DINM522FF3Xqz6scwhYelZ3ggf9NNM=; b=FI8DuJpeXTPQoPFg9HnScoEYBLWoucA7nu34gOrCDA/lm/XvrtHxKMlAwmrqCqJbH/cKcn gwFXQV5eTLp96s9BwmnsUfiZTUBYA9/n4vR0dHO/i8WCk3a7IAA+xDwZCd9VxBWicSZetx sJmprSr9MwHqsu4rVJCBjUaP72PNuW0= X-MC-Unique: Vaj_NrllNIOpLvb2naVVPg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 1/5] virFileRewrite: Allow setting owner Date: Fri, 11 Feb 2022 13:30:25 +0100 Message-Id: <04ed2518501a9de96e08fca3147d1a8a3cdd6776.1644582486.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644582653870100006 Currently, due to the way virFileRewrite() works, the rewritten file is owned by user and group that the daemon runs under. So far, this is not a problem, because the function is used to write XML files or secrets for persistent objects (domains, networks, etc.) and we don't need other users to read/write those files. But shortly, this function is going to be used for creating files for QEMU domains. There we want the QEMU process (i.e. different user) to read the file. Therefore, introduce two new arguments: @uid and @gid that allow setting desired owner of the file. Pass -1 to preserve current behaviour (i.e. create the file owned by the user running the daemon). Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/util/virfile.c | 28 +++++++++++++++++++++++++--- src/util/virfile.h | 1 + src/util/virxml.c | 3 ++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 0b79772da7..f99e7f95e1 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -484,9 +484,28 @@ int virFileUnlock(int fd G_GNUC_UNUSED, #endif /* WIN32 */ =20 =20 +/** + * virFileRewrite: + * @path: file to rewrite + * @mode: mode of the file + * @uid: uid that should own file + * @gid: gid that should own file + * @rewrite: callback to write file contents + * @opaque: opaque data to pass to the callback + * + * Rewrite given @path atomically. This is achieved by writing a + * temporary file on a side and renaming it to the desired name. + * The temporary file is created using supplied @mode and + * @uid:@gid (pass -1 for current uid/gid) and written by + * @rewrite callback. + * + * Returns: 0 on success, + * -1 otherwise (with error reported) + */ int virFileRewrite(const char *path, mode_t mode, + uid_t uid, gid_t gid, virFileRewriteFunc rewrite, const void *opaque) { @@ -496,8 +515,11 @@ virFileRewrite(const char *path, =20 newfile =3D g_strdup_printf("%s.new", path); =20 - if ((fd =3D open(newfile, O_WRONLY | O_CREAT | O_TRUNC, mode)) < 0) { - virReportSystemError(errno, _("cannot create file '%s'"), + if ((fd =3D virFileOpenAs(newfile, O_WRONLY | O_CREAT | O_TRUNC, mode, + uid, gid, + VIR_FILE_OPEN_FORCE_OWNER | VIR_FILE_OPEN_FORC= E_MODE)) < 0) { + virReportSystemError(-fd, + _("Failed to create file '%s'"), newfile); goto cleanup; } @@ -552,7 +574,7 @@ virFileRewriteStr(const char *path, mode_t mode, const char *str) { - return virFileRewrite(path, mode, + return virFileRewrite(path, mode, -1, -1, virFileRewriteStrHelper, str); } =20 diff --git a/src/util/virfile.h b/src/util/virfile.h index 967c9a9b4f..34184b32aa 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -126,6 +126,7 @@ int virFileUnlock(int fd, off_t start, off_t len) typedef int (*virFileRewriteFunc)(int fd, const void *opaque); int virFileRewrite(const char *path, mode_t mode, + uid_t uid, gid_t gid, virFileRewriteFunc rewrite, const void *opaque); int virFileRewriteStr(const char *path, diff --git a/src/util/virxml.c b/src/util/virxml.c index bb1ae3e305..a55eb9629b 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1195,7 +1195,8 @@ virXMLSaveFile(const char *path, { struct virXMLRewriteFileData data =3D { warnName, warnCommand, xml }; =20 - return virFileRewrite(path, S_IRUSR | S_IWUSR, virXMLRewriteFile, &dat= a); + return virFileRewrite(path, S_IRUSR | S_IWUSR, -1, -1, + virXMLRewriteFile, &data); } =20 /** --=20 2.34.1 From nobody Thu May 16 02:24:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644582650; cv=none; d=zohomail.com; s=zohoarc; b=YWJOy91s7o3eQZPH6/jwHmz3cWeWbVjFiActFuoxaH+ZvbbtOHa9WtZoRjOHdp8XVQ2LndEhdHQbiADFrUFUdKvb5++O/PNkOZQ58wwSNRM7/SuNgmDQakniVwE4ZSsWIxvbwNegw7ywgiYQO7FBPHVRokivz/prLemgw3WCj1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644582650; h=Content-Type:Content-Transfer-Encoding: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=qQDAW3ccBh6FsZ3RV7qUURi4d9oY9OQ6+fUwEphW0sI=; b=kpjdMfjsL0y5P6ilT205F84gIjcGxNICFrprvsB9TmgJNKmAz2ALVr8vmIv8Gcig9m1NNwESPm3QmOece1k4LgRip7nK7tH/E6Fl7+ioDydhInESiE93tWe7Ce+2dtIHinp+Q275K2gc2dlwkNl9beKfFlBvINa0DTBuowQ3WDQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644582650970209.80868422299352; Fri, 11 Feb 2022 04:30:50 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-ud3Bn4X3OlaMCJSKIRH63g-1; Fri, 11 Feb 2022 07:30:48 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4AEE0180E48F; Fri, 11 Feb 2022 12:30:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 247C97D3DA; Fri, 11 Feb 2022 12:30:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E13D34BB7C; Fri, 11 Feb 2022 12:30:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BCUZ4J008922 for ; Fri, 11 Feb 2022 07:30:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1CE0E1059111; Fri, 11 Feb 2022 12:30:35 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A6491059110 for ; Fri, 11 Feb 2022 12:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644582650; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qQDAW3ccBh6FsZ3RV7qUURi4d9oY9OQ6+fUwEphW0sI=; b=TmrX2/iu32wj48zGvZDID+5HaKPKWapM9HOrLqCU1RDSvnoJD2+booTsfbUspEV1N3VTUz vv5oTonJFZ3vBgfq0CBITBHScfol/in/STmaH9ce98sPqSXBJ5hy9xcQ+VuUx80qjZpgr0 NUc6oIoywd/DhPcivTrgsdFsgnIdZag= X-MC-Unique: ud3Bn4X3OlaMCJSKIRH63g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 2/5] virFileRewrite: Move error reporting into callback Date: Fri, 11 Feb 2022 13:30:26 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644582651795100001 Content-Type: text/plain; charset="utf-8" When rewriting a file using virFileRewrite() and error occurs while writing into a temporary file it's actually the callback that can report the most accurate error. Move error reporting into very few callback we have currently. Those callbacks are trivial so the benefit of this change is not obvious, but this will change shortly when slightly more complicated callback is introduced. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/util/virfile.c | 18 ++++++++++++------ src/util/virfile.h | 4 +++- src/util/virxml.c | 19 ++++++++++++++----- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index f99e7f95e1..5d6f14ba7e 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -497,7 +497,8 @@ int virFileUnlock(int fd G_GNUC_UNUSED, * temporary file on a side and renaming it to the desired name. * The temporary file is created using supplied @mode and * @uid:@gid (pass -1 for current uid/gid) and written by - * @rewrite callback. + * @rewrite callback. It's callback's responsibility to report + * errors. * * Returns: 0 on success, * -1 otherwise (with error reported) @@ -512,6 +513,7 @@ virFileRewrite(const char *path, g_autofree char *newfile =3D NULL; int fd =3D -1; int ret =3D -1; + int rc; =20 newfile =3D g_strdup_printf("%s.new", path); =20 @@ -524,9 +526,7 @@ virFileRewrite(const char *path, goto cleanup; } =20 - if (rewrite(fd, opaque) < 0) { - virReportSystemError(errno, _("cannot write data to file '%s'"), - newfile); + if ((rc =3D rewrite(fd, newfile, opaque)) < 0) { goto cleanup; } =20 @@ -558,12 +558,18 @@ virFileRewrite(const char *path, =20 =20 static int -virFileRewriteStrHelper(int fd, const void *opaque) +virFileRewriteStrHelper(int fd, + const char *path, + const void *opaque) { const char *data =3D opaque; =20 - if (safewrite(fd, data, strlen(data)) < 0) + if (safewrite(fd, data, strlen(data)) < 0) { + virReportSystemError(errno, + _("cannot write data to file '%s'"), + path); return -1; + } =20 return 0; } diff --git a/src/util/virfile.h b/src/util/virfile.h index 34184b32aa..b04386f6e6 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -123,7 +123,9 @@ int virFileLock(int fd, bool shared, off_t start, off_t= len, bool waitForLock) int virFileUnlock(int fd, off_t start, off_t len) G_GNUC_NO_INLINE; =20 -typedef int (*virFileRewriteFunc)(int fd, const void *opaque); +typedef int (*virFileRewriteFunc)(int fd, + const char *path, + const void *opaque); int virFileRewrite(const char *path, mode_t mode, uid_t uid, gid_t gid, diff --git a/src/util/virxml.c b/src/util/virxml.c index a55eb9629b..268aad1d20 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1172,17 +1172,26 @@ struct virXMLRewriteFileData { }; =20 static int -virXMLRewriteFile(int fd, const void *opaque) +virXMLRewriteFile(int fd, + const char *path, + const void *opaque) { const struct virXMLRewriteFileData *data =3D opaque; =20 - if (data->warnCommand) { - if (virXMLEmitWarning(fd, data->warnName, data->warnCommand) < 0) - return -1; + if (data->warnCommand && + virXMLEmitWarning(fd, data->warnName, data->warnCommand) < 0) { + virReportSystemError(errno, + _("cannot write data to file '%s'"), + path); + return -1; } =20 - if (safewrite(fd, data->xml, strlen(data->xml)) < 0) + if (safewrite(fd, data->xml, strlen(data->xml)) < 0) { + virReportSystemError(errno, + _("cannot write data to file '%s'"), + path); return -1; + } =20 return 0; } --=20 2.34.1 From nobody Thu May 16 02:24:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644582662; cv=none; d=zohomail.com; s=zohoarc; b=BP25FwPeQr1CusAhV5ieUOuxRr/J1lreWpClOOcJgKoGfYEv4dUmMvzlb7HlZ8y/iD2CKGIxVPUvheCRVqeUw0SYSDopT8ON61VW+88KmFzwjU6XmcO+4lC+6XubBn6iZYSzs2wXkTvIpZTb98L/D+o9HVu3MXVM7zwzykALKf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644582662; h=Content-Type:Content-Transfer-Encoding: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=xaHgpUuf1WHIs6DK+zINosZa7hF+Fj69ISHn5+5eUbs=; b=XjEnuENWWDRHpuTUOcAlzUZLL+ArwEX48HKs4tcAHjzRRFyFnfPYtxhc3Gmx3KLoBoy6mH/wqatNNtKzQE2bjg0KGt7UmGfKBWV7VxKlq+3hM8qrNziC2pMWq2t6rD+lGvmrqHc/cag6wzno7gLRIfmOy20vn1nCWi/tm685uo4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644582662676673.7084552796225; Fri, 11 Feb 2022 04:31:02 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-296-a6ShBSeQNHm27wc5IEJs4A-1; Fri, 11 Feb 2022 07:30:51 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 07B9E1014B4E; Fri, 11 Feb 2022 12:30:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D83B76FAE7; Fri, 11 Feb 2022 12:30:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A4E7C180B617; Fri, 11 Feb 2022 12:30:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BCUZDI008934 for ; Fri, 11 Feb 2022 07:30:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id E11AA105910A; Fri, 11 Feb 2022 12:30:35 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A3551059118 for ; Fri, 11 Feb 2022 12:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644582660; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xaHgpUuf1WHIs6DK+zINosZa7hF+Fj69ISHn5+5eUbs=; b=B4NPOCrYrPsyRwOuIUqS6zOcAHSs+caYk2jekHw1hL/RthZNcULFuRcvGqeWMfpS+ZBuJN WGH/UIN9GXhNKJ+7SRW8du8oVC1lzrU6ZV9zrA3GPosrOoGExh9d2raOiDSe2cnOigsqB3 0dWno0x9kdsPmLRkqhbkHHfsRfSwdr4= X-MC-Unique: a6ShBSeQNHm27wc5IEJs4A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 3/5] qemuPrepareNVRAM: Us virFileRewrite() to write NVRAM Date: Fri, 11 Feb 2022 13:30:27 +0100 Message-Id: <4c50ca5bf66f95a16224bb06f404bac7332b5bdf.1644582486.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644582666611100001 Content-Type: text/plain; charset="utf-8" After previous commits there is no need for qemuPrepareNVRAM() to open code virFileRewrite(). Deduplicate the code by calling the function. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_process.c | 112 ++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 68 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8fccf6b760..036d95924c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4421,6 +4421,41 @@ qemuProcessUpdateCPU(virQEMUDriver *driver, } =20 =20 +struct qemuPrepareNVRAMHelperData { + int srcFD; + const char *srcPath; +}; + +static int +qemuPrepareNVRAMHelper(int dstFD, + const char *dstPath, + const void *opaque) +{ + const struct qemuPrepareNVRAMHelperData *data =3D opaque; + ssize_t r; + + do { + char buf[1024]; + + if ((r =3D saferead(data->srcFD, buf, sizeof(buf))) < 0) { + virReportSystemError(errno, + _("Unable to read from file '%s'"), + data->srcPath); + return -2; + } + + if (safewrite(dstFD, buf, r) < 0) { + virReportSystemError(errno, + _("Unable to write to file '%s'"), + dstPath); + return -1; + } + } while (r); + + return 0; +} + + static int qemuPrepareNVRAM(virQEMUDriver *driver, virDomainObj *vm, @@ -4429,12 +4464,9 @@ qemuPrepareNVRAM(virQEMUDriver *driver, g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); int ret =3D -1; int srcFD =3D -1; - int dstFD =3D -1; virDomainLoaderDef *loader =3D vm->def->os.loader; - bool created =3D false; const char *master_nvram_path; - ssize_t r; - g_autofree char *tmp_dst_path =3D NULL; + struct qemuPrepareNVRAMHelperData data; =20 if (!loader || !loader->nvram || (virFileExists(loader->nvram) && !reset_nvram)) @@ -4466,76 +4498,20 @@ qemuPrepareNVRAM(virQEMUDriver *driver, goto cleanup; } =20 - tmp_dst_path =3D g_strdup_printf("%s.tmp", loader->nvram); - if ((dstFD =3D virFileOpenAs(tmp_dst_path, - O_WRONLY | O_CREAT | O_EXCL, - S_IRUSR | S_IWUSR, - cfg->user, cfg->group, - VIR_FILE_OPEN_FORCE_OWNER)) < 0) { - virReportSystemError(-dstFD, - _("Failed to create file '%s'"), - tmp_dst_path); - goto cleanup; - } - - created =3D true; - - do { - char buf[1024]; - - if ((r =3D saferead(srcFD, buf, sizeof(buf))) < 0) { - virReportSystemError(errno, - _("Unable to read from file '%s'"), - master_nvram_path); - goto cleanup; - } - - if (safewrite(dstFD, buf, r) < 0) { - virReportSystemError(errno, - _("Unable to write to file '%s'"), - tmp_dst_path); - goto cleanup; - } - } while (r); - - if (VIR_CLOSE(srcFD) < 0) { - virReportSystemError(errno, - _("Unable to close file '%s'"), - master_nvram_path); - goto cleanup; - } - - if (g_fsync(dstFD) < 0) { - virReportSystemError(errno, _("cannot sync file '%s'"), - tmp_dst_path); - goto cleanup; - } - - if (VIR_CLOSE(dstFD) < 0) { - virReportSystemError(errno, - _("Unable to close file '%s'"), - tmp_dst_path); - goto cleanup; - } - - if (rename(tmp_dst_path, loader->nvram) < 0) { - virReportSystemError(errno, - _("Unable to replace '%s'"), - loader->nvram); + data.srcFD =3D srcFD; + data.srcPath =3D master_nvram_path; + + if (virFileRewrite(loader->nvram, + S_IRUSR | S_IWUSR, + cfg->user, cfg->group, + qemuPrepareNVRAMHelper, + &data) < 0) { goto cleanup; } =20 ret =3D 0; cleanup: - /* We successfully generated the nvram path, but failed to - * copy the file content. Roll back. */ - if (ret < 0) { - if (created) - unlink(tmp_dst_path); - } - VIR_FORCE_CLOSE(srcFD); - VIR_FORCE_CLOSE(dstFD); return ret; } =20 --=20 2.34.1 From nobody Thu May 16 02:24:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644582655; cv=none; d=zohomail.com; s=zohoarc; b=a8mZK4UV81zXGdxH7TGOYZF68SP/uB1+PSoW7j81yR+4LEnf8vSaOfUx3gNucEfA1+qrIwr07xnP8lIU6neS6tEF5GNVjdL/rudrHgIqTqLw+fv/ccXgue4Yr67GZ4CzbqXXcFBn5jzTx+3EHgXdA3vDjwwyxAic9Mg+gKCD4fc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644582655; h=Content-Type:Content-Transfer-Encoding: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=QhCNqaxnWuA1a3IgrYykcNuQxOhdkkqe8eFcwtYAdhs=; b=aS0/QXEYCDB0xIffmDJwMACtxHS2u+6ttAhLkzHeuXM5YUQkpZruBcE8daOoNnHCBzc7hKkbfFG2f4CDMGBoPiQjjKNwzmjHiUQWRaa/r2nOpuc7rWeBABCfJqfLkwWHr5ukL6prtA2dbzhL0uduB5Qb680ogTg0UYEhVjNWoHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 16445826550291012.3062203388349; Fri, 11 Feb 2022 04:30:55 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-281-JJcIunIMPpW5wseuhB8M3w-1; Fri, 11 Feb 2022 07:30:50 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A4EF1854E36; Fri, 11 Feb 2022 12:30:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DAD301059139; Fri, 11 Feb 2022 12:30:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8FE4B4A7C8; Fri, 11 Feb 2022 12:30:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BCUaiv008944 for ; Fri, 11 Feb 2022 07:30:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id B13811059110; Fri, 11 Feb 2022 12:30:36 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39D5C105910E for ; Fri, 11 Feb 2022 12:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644582652; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QhCNqaxnWuA1a3IgrYykcNuQxOhdkkqe8eFcwtYAdhs=; b=KtYjeg8mCGziR3SeAvqKOzHqtE9F7ekRMxLki2PZZ5cIrcY+IGfNPRFu9lNj2nFhhlaW+x s0+tjzqnmPyyIM1ZKJKqNfiYYDDYjXMcnP5aexA19Q8l2GEQAsbZoeEcs4IBDASV700wR9 dUaXc0cs+epbf/O1MsIZcyrFzCRofUk= X-MC-Unique: JJcIunIMPpW5wseuhB8M3w-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 4/5] qemuPrepareNVRAM: Switch to VIR_AUTOCLOSE Date: Fri, 11 Feb 2022 13:30:28 +0100 Message-Id: <9e13d60e337ae9abf7e05b2c57adbaaa3d20d70f.1644582486.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644582656786100001 Content-Type: text/plain; charset="utf-8" Nothing inside the qemuPrepareNVRAM function relies on @srcFD being closed early and nothing closes it early. It's okay then to close it automatically when leaving the function. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 036d95924c..0ba9343b2a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4463,7 +4463,7 @@ qemuPrepareNVRAM(virQEMUDriver *driver, { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); int ret =3D -1; - int srcFD =3D -1; + VIR_AUTOCLOSE srcFD =3D -1; virDomainLoaderDef *loader =3D vm->def->os.loader; const char *master_nvram_path; struct qemuPrepareNVRAMHelperData data; @@ -4511,7 +4511,6 @@ qemuPrepareNVRAM(virQEMUDriver *driver, =20 ret =3D 0; cleanup: - VIR_FORCE_CLOSE(srcFD); return ret; } =20 --=20 2.34.1 From nobody Thu May 16 02:24:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644582658; cv=none; d=zohomail.com; s=zohoarc; b=PEMh5OdDQrlNv453iFZkoYDBpoTAwOtcMV4Lg9lkOhRs1xhXHag6azACOt9DdJqbdYI4EmuKfOIQNHuAmaFYZr6ptccvU4n+LfBMo5rN+4rHmbnrr39D1sRRznkvJxoCT2NOjiZBs+gFCGiFSCEWVCX4PMRcgnvRQmZyupBfkiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644582658; h=Content-Type:Content-Transfer-Encoding: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=R2naWNCr8nwtc3CAsx0zrD/NUEQ1NCswfmkgUtNcB6U=; b=dmP0ir/D3s9dLYeTdIiHHK18M6LAxTyhOE38iXKH3cA6Ba/7PcSQdvOXfS9hufp8ME9YZIbRNNgbxlDCAUVb5pi4b6KAvWzWFVIz67Vh6BcCBTfpFZV0TzPYSfZQDsRFGwR/pmdxMsd71cwcFneE/ObQRZrfKCe/3NDjEe61deA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644582658758417.91709288142954; Fri, 11 Feb 2022 04:30:58 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-349-IB3QCncZO_KubUmR1y8MGA-1; Fri, 11 Feb 2022 07:30:48 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B77551091DC8; Fri, 11 Feb 2022 12:30:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97069105910A; Fri, 11 Feb 2022 12:30:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3CC214CA9B; Fri, 11 Feb 2022 12:30:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BCUbgH008949 for ; Fri, 11 Feb 2022 07:30:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 81FD01059118; Fri, 11 Feb 2022 12:30:37 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AF9A105910E for ; Fri, 11 Feb 2022 12:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644582652; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=R2naWNCr8nwtc3CAsx0zrD/NUEQ1NCswfmkgUtNcB6U=; b=cv3Azihm4OMRuncjukRPbILCaOfOoX2RJ7njclG+mS0ESZQhK70BQLxM6hrZI4O7t9qBdf Gz6UsEfpZuUbF3Aq9Q8bGiSJouJmGo0Yr+Cu9mKjYTAWGCMEDahBTfA9vfh+dtlUUny8Ig dIoG6t3XbbN9nKZg3vRjl5XKuh/v7Ao= X-MC-Unique: IB3QCncZO_KubUmR1y8MGA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 5/5] qemuPrepareNVRAM: Drop cleanup label Date: Fri, 11 Feb 2022 13:30:29 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644582662054100001 Content-Type: text/plain; charset="utf-8" After previous commits, the cleanup label shrank to plain 'return' statement. There's no point in having such label, so drop it. Signed-off-by: Michal Privoznik --- src/qemu/qemu_process.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 0ba9343b2a..0b9d96b7d5 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4462,7 +4462,6 @@ qemuPrepareNVRAM(virQEMUDriver *driver, bool reset_nvram) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - int ret =3D -1; VIR_AUTOCLOSE srcFD =3D -1; virDomainLoaderDef *loader =3D vm->def->os.loader; const char *master_nvram_path; @@ -4487,7 +4486,7 @@ qemuPrepareNVRAM(virQEMUDriver *driver, virReportError(VIR_ERR_OPERATION_FAILED, _("unable to find any master var store for " "loader: %s"), loader->path); - goto cleanup; + return -1; } =20 if ((srcFD =3D virFileOpenAs(master_nvram_path, O_RDONLY, @@ -4495,7 +4494,7 @@ qemuPrepareNVRAM(virQEMUDriver *driver, virReportSystemError(-srcFD, _("Failed to open file '%s'"), master_nvram_path); - goto cleanup; + return -1; } =20 data.srcFD =3D srcFD; @@ -4506,12 +4505,10 @@ qemuPrepareNVRAM(virQEMUDriver *driver, cfg->user, cfg->group, qemuPrepareNVRAMHelper, &data) < 0) { - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 --=20 2.34.1