From nobody Tue May 14 05:59:24 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=1644491656; cv=none; d=zohomail.com; s=zohoarc; b=nZb4vswGy4GLwoWkZF3+h0ADEuYLdxqcy0cDvehDOlkBJkiOSYFRlXl6mqXQzcH2HYTnFsp9dyWzGbbH0fZk2ItDN7/J+20zRvV8VTC+yNzCOujxnsIBzFmdYNbc6utFW9v5YwkeHaqSX4Uky8uLkZwIgGi4fjkU93BOEm5vtfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644491656; 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=OzdcrL+1VwUBADLvjlU2TBZxVFtDxNZ/udyoZeJWWoY=; b=RnHOLL4EXfmmVUxe15TS3zGy6kQuNOhLC3qxDF/RJolpSfWHcnET9FV3Ms7lB9GOa3kgRTuDMy6am25avre38Bly1ZP7s1b2UwJgkyeZ48j1QAgAhippBAFXYWlO5/4A9T4JYbG0S/HHUHK0LS4LzXvlf5nqkvPGcCL2iaq5eN4= 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 1644491656076685.6992787252063; Thu, 10 Feb 2022 03:14:16 -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-360-EgGMga5VOsq6ym5zzsh5-Q-1; Thu, 10 Feb 2022 06:14:11 -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 B0689344E2; Thu, 10 Feb 2022 11:14:06 +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 5413410589DA; Thu, 10 Feb 2022 11:14:06 +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 249131802E34; Thu, 10 Feb 2022 11:14:06 +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 21ABDjfA018760 for ; Thu, 10 Feb 2022 06:13:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id D949110589DD; Thu, 10 Feb 2022 11:13:45 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6487D10589DA for ; Thu, 10 Feb 2022 11:13:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644491655; 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=OzdcrL+1VwUBADLvjlU2TBZxVFtDxNZ/udyoZeJWWoY=; b=LdjdLnWu/c2aahQ/NEzyYF1Go4548KK9CkYH2raj9yg5g3yivDNGpKVJ5FOoNFkMljMnro GAOjlaSmDUKXKWBdi+xRHpQpG1M+djtrLUU9M1kYcYUlzIot4pV6a4N3ewB0dnItdC7NSJ SZFtU6YAQ2UVfqP5IwcGavuJecbfs18= X-MC-Unique: EgGMga5VOsq6ym5zzsh5-Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/5] qemu_process: Accept VIR_QEMU_PROCESS_START_RESET_NVRAM flag when starting a domain Date: Thu, 10 Feb 2022 12:13:22 +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: 1644491658497100002 Content-Type: text/plain; charset="utf-8" In one of my previous commits I've fixed the value of VIR_QEMU_PROCESS_START_RESET_NVRAM flag (which was masking another value). But what I forgot to do is update virCheckFlags() calls in two places where the flag is passed: qemuProcessLaunch() and qemuProcessStart(). Fixes: 1b636593c76f443169ef7bdb3644fd670379d04e Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_process.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 24873f6fb7..8fccf6b760 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7380,7 +7380,8 @@ qemuProcessLaunch(virConnectPtr conn, VIR_QEMU_PROCESS_START_PAUSED | VIR_QEMU_PROCESS_START_AUTODESTROY | VIR_QEMU_PROCESS_START_NEW | - VIR_QEMU_PROCESS_START_GEN_VMID, -1); + VIR_QEMU_PROCESS_START_GEN_VMID | + VIR_QEMU_PROCESS_START_RESET_NVRAM, -1); =20 cfg =3D virQEMUDriverGetConfig(driver); =20 @@ -7807,7 +7808,8 @@ qemuProcessStart(virConnectPtr conn, virCheckFlagsGoto(VIR_QEMU_PROCESS_START_COLD | VIR_QEMU_PROCESS_START_PAUSED | VIR_QEMU_PROCESS_START_AUTODESTROY | - VIR_QEMU_PROCESS_START_GEN_VMID, cleanup); + VIR_QEMU_PROCESS_START_GEN_VMID | + VIR_QEMU_PROCESS_START_RESET_NVRAM, cleanup); =20 if (!migrateFrom && !snapshot) flags |=3D VIR_QEMU_PROCESS_START_NEW; --=20 2.34.1 From nobody Tue May 14 05:59:24 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=1644491643; cv=none; d=zohomail.com; s=zohoarc; b=S4D6iBV+5+bhV1/k4uWaLQugtrnNCKhHUCoLW474qJbIcEviCpXgzMHZFHSQ1GYgWdTeA7BenplAqiCxifuXq0crH9uvoR3By/7AKNGF2gvWX99Dx3s7L2mEtu7IHzXQTfWNz5kh15j0IW4BiInYmk/VTps8Ok+eUkSV7wZ6Pj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644491643; 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=auoGXS/QpcP+QMr6WrmW8UNuMbWz6a8cuMIsfbUMZ3o=; b=IRKxmg24zhHH6ug0r9cGjdtH6cwubjmDCHHFVoFHj5P86QW0gDMyFVqM3P+U7LpwX1X4X0RYO4YKVQotjTc1gWhmq3CoWeXqpZN7v2JBSjxkZSoDoGBZqaeU28WFBZ5RyAzoEx/ijkINhW8Nc8bKwkoRaXVpcUaS4HAmis70F0Y= 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 1644491643498110.20357333622758; Thu, 10 Feb 2022 03:14:03 -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-204-Vxnnt3HTPVacaahs1j6sZA-1; Thu, 10 Feb 2022 06:13:59 -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 62751343CC; Thu, 10 Feb 2022 11:13:53 +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 80C7A60C5A; Thu, 10 Feb 2022 11:13:51 +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 02B564BB7C; Thu, 10 Feb 2022 11:13:47 +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 21ABDk8I018770 for ; Thu, 10 Feb 2022 06:13:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id A7B8410589DD; Thu, 10 Feb 2022 11:13:46 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 327B310589DA for ; Thu, 10 Feb 2022 11:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644491642; 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=auoGXS/QpcP+QMr6WrmW8UNuMbWz6a8cuMIsfbUMZ3o=; b=DNJL1XQn7k3VshWr+OtT1keeKqs8yn2ajNNynf0Td68WF4yz0L5HKw0+SZYnA56GlpeeAn 6YfMEb2szfNMBeKK0jNOEUkRda5BgNC2MZcU8cNqQTj/cnc7lCMlNNXSv16k6zBqF5GeRG 0kyHAi6Atl/Vcu+ZIZ9IAkIYf2vcfG4= X-MC-Unique: Vxnnt3HTPVacaahs1j6sZA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/5] qemuFirmwareFillDomain: Use FW descriptors to lookup template when resetting NVRAM Date: Thu, 10 Feb 2022 12:13:23 +0100 Message-Id: <697a6a9e90ff75f531f9197c1d0f6a2001aa3fcc.1644491535.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: 1644491644224100003 Content-Type: text/plain; charset="utf-8" If VIR_QEMU_PROCESS_START_RESET_NVRAM flag is passed when starting a domain, then user requested to overwrite the domain specific NVRAM with the one from template. But it is very likely that the path to the template is not stored in the domain definition, which in turn makes the copy function (qemuPrepareNVRAM()) fail. The solution is simple - when preparing domain, specifically when deciding whether the path to the template should be autofilled, ignore any existing NVRAM file. Signed-off-by: Michal Privoznik --- src/qemu/qemu_firmware.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 84c80eaacb..ff364996b8 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -1297,6 +1297,7 @@ qemuFirmwareFillDomain(virQEMUDriver *driver, ssize_t nfirmwares =3D 0; const qemuFirmware *theone =3D NULL; bool needResult =3D true; + const bool reset_nvram =3D flags & VIR_QEMU_PROCESS_START_RESET_NVRAM; size_t i; int ret =3D -1; =20 @@ -1309,7 +1310,7 @@ qemuFirmwareFillDomain(virQEMUDriver *driver, * specified and the varstore doesn't exist ... */ if (!virDomainDefHasOldStyleROUEFI(def) || def->os.loader->templt || - virFileExists(def->os.loader->nvram)) + (!reset_nvram && virFileExists(def->os.loader->nvram))) return 0; =20 /* ... then we want to consult JSON FW descriptors first, --=20 2.34.1 From nobody Tue May 14 05:59:24 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=1644491654; cv=none; d=zohomail.com; s=zohoarc; b=C+dETUHGF1KBt53TGL59camMPiPQIh4P6o/xHJ2gjGm+3VLyCay//G/mk7oly5R0M0SXGqYVDwhbpU/cwlj7LkeoYWbDlJs4mjFSf6Z823QLpD5Mlsnq2GvuE0AJ1cz25phHDO3AlpCRyoT53Vxsp4I7McNJWlpz0Zs57xouuN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644491654; 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=UURNajqPSiWYfXUhKsfrYY/JZenAR0xb7g7rAO0qD+s=; b=iFaEU0hSk7Y2boxj4p8kwg0EYcnWPrBgZvbZt2GlAaAK0hTB8Es8PiIgF4C1pxVa1Vc4YjIA9NLunnSs1bkd7R0ykee/+IZwpwLz1u3rq4kdCApaDcsw7+cBfksjvfz8ixgZptj6Ws/mtFxqWeHQVOUHjMEc0QGQU25Djd+AiTA= 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 1644491654415454.9328594537069; Thu, 10 Feb 2022 03:14:14 -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-383-dfDF36enNxqY7DbenN4GUQ-1; Thu, 10 Feb 2022 06:14:12 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C35541006AA4; Thu, 10 Feb 2022 11:14:06 +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 621AA67849; Thu, 10 Feb 2022 11:14:06 +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 31863180B617; Thu, 10 Feb 2022 11:14:06 +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 21ABDlLg018775 for ; Thu, 10 Feb 2022 06:13:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 774AF10589DD; Thu, 10 Feb 2022 11:13:47 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0117E10589DA for ; Thu, 10 Feb 2022 11:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644491654; 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=UURNajqPSiWYfXUhKsfrYY/JZenAR0xb7g7rAO0qD+s=; b=DrwC5N1d/vrWjevbRu+HTG+pS2wlmU9RcRdNBq4UPZYlOGG588VuV4F90wPjyK3qalm9kt hNeKIqUh056iNBIbeI2rzSnOOfDq1lfFaTOnsnJz7S/wYq8P3VSV1/CVK6Ev+86D5qVZwg QVjdMUY/ickFFIvQP/ofWeG4baxpxkA= X-MC-Unique: dfDF36enNxqY7DbenN4GUQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/5] virFileRewrite: Allow setting owner Date: Thu, 10 Feb 2022 12:13:24 +0100 Message-Id: <8d668f7d69aba95af13d59e593bc84143265bec3.1644491535.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.11 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: 1644491655925100001 Content-Type: text/plain; charset="utf-8" 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 --- 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 Tue May 14 05:59:24 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=1644491644; cv=none; d=zohomail.com; s=zohoarc; b=IokqcNYDIg3m3MErazylgkt7L4yu1vOzhepKNebOPA1epyeyJFnFwSYpNzx9Yb1MYswLd2lNgsUy6OEERtO7FmnWUZkFd+vI5gW3TQK+AXZA40n1OE5r+43XOYyTD4W9fIjzpmeAvbN4DsQAgTz5MVuuk56fb9+lMPWQ8AK8VFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644491644; 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=LKttHx/E6t8Mk31KceJCcmMGr4T+H9o/8mLCfmYuGLc=; b=NoyagNkxXH94EWUuENRXCjfbPhNhlSjWGcXhGzty8qHFk0gTECLdH0QIu7y/GVJknlf6yC0eGC25UlpD4gP7zCR0INke7eDeasg445+EgpCpRSKV+vcQNOOaACaMGYxf9QtyZ7VykqX+V5CjNHccpigKCqPGKLD2AtIPijUK16c= 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 1644491644154916.8008659250276; Thu, 10 Feb 2022 03:14:04 -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-443-Lo9ENB7PM5Cmp1C7i60S3Q-1; Thu, 10 Feb 2022 06:14:00 -0500 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 59DD780D694; Thu, 10 Feb 2022 11:13:55 +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 156897039E; Thu, 10 Feb 2022 11:13:55 +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 D8CD24A7C9; Thu, 10 Feb 2022 11:13:54 +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 21ABDmnG018788 for ; Thu, 10 Feb 2022 06:13:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 46EC910589DE; Thu, 10 Feb 2022 11:13:48 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id C548710589DD for ; Thu, 10 Feb 2022 11:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644491644; 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=LKttHx/E6t8Mk31KceJCcmMGr4T+H9o/8mLCfmYuGLc=; b=GLxD2qNnYY+R6sSssfGuNhrb1J8bp5h+6ys3YGyGxodEqrJIWzsFQhJpJsKD5OV18Js5xe sNgkHq2mJWdTvwCjeVSnnhIvTKpiLMrfH8nO4kCa5LO3mf89Axb7ppFPWVbkv//LHW6BS4 hOeAiF6v1hMZlqbzkN6tSH8Kh8O+NSg= X-MC-Unique: Lo9ENB7PM5Cmp1C7i60S3Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/5] virFileRewrite: Allow callback report errors Date: Thu, 10 Feb 2022 12:13:25 +0100 Message-Id: <22ce632ff98d3f6e9b488798a19623e259327113.1644491535.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.15 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: 1644491646284100005 Content-Type: text/plain; charset="utf-8" Sometimes it may be handy for the callback to report error, even though our current callbacks are trivial. Let's report an error only if callback returns a well known value, otherwise assume it reported error message on its own. Signed-off-by: Michal Privoznik --- src/util/virfile.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index f99e7f95e1..dd065a537c 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -499,6 +499,10 @@ int virFileUnlock(int fd G_GNUC_UNUSED, * @uid:@gid (pass -1 for current uid/gid) and written by * @rewrite callback. * + * A negative value returned by @rewrite callback is treated as + * error and if the value is different to -1 then it's the + * callback's responsibility to report error. + * * Returns: 0 on success, * -1 otherwise (with error reported) */ @@ -512,6 +516,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 +529,11 @@ 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, opaque)) < 0) { + if (rc =3D=3D -1) { + virReportSystemError(errno, _("cannot write data to file '%s'"= ), + newfile); + } goto cleanup; } =20 --=20 2.34.1 From nobody Tue May 14 05:59:24 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=1644491658; cv=none; d=zohomail.com; s=zohoarc; b=L14BQJLaOoieI/0Z29S5vrrHf2v7NgGGDHWrcMPt77yyqQYY2pmL5OB+Un3jCObumiWMpw3R15APrSnrIv/mCoGSLDvX0r4KLtW5My1AaeeN4beiQFmcfpWN8ia3WsfFMyqw74PCSlw6LMnChlh7GbeIYHTSxrcm/2XG5OVq1qQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644491658; 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=nUfxKl8VAlA1PO+6y3VdaIN02W0QR4Pn8C8GPMgZw/U=; b=FJ+8Vd8MXpT59hhR736JuWznDzlsJ375xbwENXHp/ym7YHR+VW9QE2KlSwB6J4mEksSG0i4CyI6gyf5tKOTRM1IqcgBOkgptv0m/0CZWqEjZjEfF5ULe+FBhWbH1XbTPBbRP5Gm77bIxvSZdOfPMSBHEXCbxcS7PsjYaB8PJFb0= 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 1644491658610157.56659697847283; Thu, 10 Feb 2022 03:14:18 -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-491-ymtP-aXWNh-SpcXBc1HBiQ-1; Thu, 10 Feb 2022 06:14:15 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA0661091DB6; Thu, 10 Feb 2022 11:14:09 +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 93D436E1E2; Thu, 10 Feb 2022 11:14:09 +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 38ACA4A7C8; Thu, 10 Feb 2022 11:14:09 +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 21ABDnXg018795 for ; Thu, 10 Feb 2022 06:13:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1571910589DD; Thu, 10 Feb 2022 11:13:49 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9450C10589DA for ; Thu, 10 Feb 2022 11:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644491658; 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=nUfxKl8VAlA1PO+6y3VdaIN02W0QR4Pn8C8GPMgZw/U=; b=Fd1te1qwPdv+IS5XXCwIZxn9YbfWtrv3f+q82Iu3nNbMe/Xc9a8vyJDrelI5TxGNmc8TYd xa9xmKyEnmYeAw2vh29TggFcdLFxAfDth2Q/EzslzDBMfIpVGjdoIergMTitWkjxCPsyZD NR0BUbBiX0h+hp82572iPy6mCBcJaW0= X-MC-Unique: ymtP-aXWNh-SpcXBc1HBiQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/5] qemuPrepareNVRAM: Us virFileRewrite() to write NVRAM Date: Thu, 10 Feb 2022 12:13:26 +0100 Message-Id: <5c4225b39559f3edae53dd66df0681a4de40a10a.1644491535.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.11 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: 1644491660533100005 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 --- src/qemu/qemu_process.c | 118 +++++++++++++--------------------------- 1 file changed, 39 insertions(+), 79 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8fccf6b760..500a91f153 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4421,6 +4421,40 @@ qemuProcessUpdateCPU(virQEMUDriver *driver, } =20 =20 +static int +qemuPrepareNVRAMHelper(int dstFD, + const void *opaque) +{ + const char *master_nvram_path =3D opaque; + VIR_AUTOCLOSE srcFD =3D -1; + ssize_t r; + + if ((srcFD =3D virFileOpenAs(master_nvram_path, O_RDONLY, + 0, -1, -1, 0)) < 0) { + virReportSystemError(-srcFD, + _("Failed to open file '%s'"), + master_nvram_path); + return -2; + } + + do { + char buf[1024]; + + if ((r =3D saferead(srcFD, buf, sizeof(buf))) < 0) { + virReportSystemError(errno, + _("Unable to read from file '%s'"), + master_nvram_path); + return -2; + } + + if (safewrite(dstFD, buf, r) < 0) + return -1; + } while (r); + + return 0; +} + + static int qemuPrepareNVRAM(virQEMUDriver *driver, virDomainObj *vm, @@ -4428,13 +4462,8 @@ 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; =20 if (!loader || !loader->nvram || (virFileExists(loader->nvram) && !reset_nvram)) @@ -4458,84 +4487,15 @@ qemuPrepareNVRAM(virQEMUDriver *driver, goto cleanup; } =20 - if ((srcFD =3D virFileOpenAs(master_nvram_path, O_RDONLY, - 0, -1, -1, 0)) < 0) { - virReportSystemError(-srcFD, - _("Failed to open file '%s'"), - master_nvram_path); + if (virFileRewrite(loader->nvram, + S_IRUSR | S_IWUSR, + cfg->user, cfg->group, + qemuPrepareNVRAMHelper, + master_nvram_path) < 0) goto cleanup; - } - - 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); - 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