From nobody Mon Apr 29 13:14:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1571128542; cv=none; d=zoho.com; s=zohoarc; b=Txu/yfsl5v6fKMYBBsoT+6RgP/3g0heZogGWDqDOkwrtGeih5CZ0BAvuKFZwq6zdrWgK53L6RhCXPqDjeLVgQblKVMItG+dJq3ELOIFdiyvygg+6H2dU1pPKgR4AOR8gi6iuzGuOoJLHjpudd8NeL7P2KJOkRtMJD7pgSWkNDcU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571128542; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=w9haxjGoHkLrLQC8flDWyILFM2rYrdF1mrx6UiMvZas=; b=TC4gvE0Fv6CVSNpqWEdcLYNcihHIvjmZDBqawfCbXEudvFJ4Q8pghZFtttbWRNRPB/AGKfaySuKnbiiE55/JBdVib4a7QSPSpoLjJyOLQJ7bvzSHQOad+f17aDkQggDJij8lhZZTGrdPs13aXYW+DEgKZytld+4s30L8wqt0JP4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1571128542293655.4146599951252; Tue, 15 Oct 2019 01:35:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E9FF10DCC8C; Tue, 15 Oct 2019 08:35:39 +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 6A77660C5E; Tue, 15 Oct 2019 08:35:38 +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 D577018037CA; Tue, 15 Oct 2019 08:35:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9F8Vo3N001916 for ; Tue, 15 Oct 2019 04:31:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id EA2426031D; Tue, 15 Oct 2019 08:31:50 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25E396012E; Tue, 15 Oct 2019 08:31:44 +0000 (UTC) From: Pavel Mores To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 10:31:22 +0200 Message-Id: <20191015083122.21217-1-pmores@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, Pavel Mores Subject: [libvirt] [PATCH] qemu: fix EFI nvram removal on domain undefine 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Tue, 15 Oct 2019 08:35:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When undefining a UEFI domain its nvram file has to be properly handled as well. It's mandatory to use one of --nvram and --keep-nvram options when 'virsh undefine ' is issued for a UEFI domain. To fix the bug as reported, virsh should return an error message if neither option is used and the nvram file should be removed when --nvram is given. The cause of the problem is that when qemuDomainUndefineFlags() is invoked on an inactive domain the path to its nvram file is empty. This commit aims to fix this by formatting and filling in the path in time for the nvram removal code to run properly. https://bugzilla.redhat.com/show_bug.cgi?id=3D1751596 Signed-off-by: Pavel Mores Reviewed-by: Michal Privoznik and pushed. --- src/qemu/qemu_domain.c | 12 +++++++++--- src/qemu/qemu_domain.h | 4 ++++ src/qemu/qemu_driver.c | 20 +++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 35067c851f..1a0367cc27 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -15441,16 +15441,22 @@ qemuDomainDiskIsMissingLocalOptional(virDomainDis= kDefPtr disk) } =20 =20 +int +qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg, + virDomainDefPtr def, char **path) +{ + return virAsprintf(path, "%s/%s_VARS.fd", cfg->nvramDir, def->name); +} + int qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg, virDomainDefPtr def) { if (def->os.loader && def->os.loader->type =3D=3D VIR_DOMAIN_LOADER_TYPE_PFLASH && - def->os.loader->readonly =3D=3D VIR_TRISTATE_SWITCH_ON && + def->os.loader->readonly =3D=3D VIR_TRISTATE_BOOL_YES && !def->os.loader->nvram) { - return virAsprintf(&def->os.loader->nvram, "%s/%s_VARS.fd", - cfg->nvramDir, def->name); + return qemuDomainNVRAMPathFormat(cfg, def, &def->os.loader->nvram); } =20 return 0; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 01a54d4265..07725c7cc4 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1207,6 +1207,10 @@ qemuDomainIsUsingNoShutdown(qemuDomainObjPrivatePtr = priv); bool qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk); =20 +int +qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg, + virDomainDefPtr def, char **path); + int qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg, virDomainDefPtr def); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bc0ede2fb0..dcaadbdb52 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7828,6 +7828,8 @@ qemuDomainUndefineFlags(virDomainPtr dom, int nsnapshots; int ncheckpoints; virQEMUDriverConfigPtr cfg =3D NULL; + char *nvram_path =3D NULL; + bool need_deallocate_nvram_path =3D false; =20 virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE | VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA | @@ -7905,14 +7907,20 @@ qemuDomainUndefineFlags(virDomainPtr dom, } } =20 - if (vm->def->os.loader && - vm->def->os.loader->nvram && - virFileExists(vm->def->os.loader->nvram)) { + if (vm->def->os.firmware =3D=3D VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) { + qemuDomainNVRAMPathFormat(cfg, vm->def, &nvram_path); + need_deallocate_nvram_path =3D true; + } else { + if (vm->def->os.loader) + nvram_path =3D vm->def->os.loader->nvram; + } + + if (nvram_path && virFileExists(nvram_path)) { if ((flags & VIR_DOMAIN_UNDEFINE_NVRAM)) { - if (unlink(vm->def->os.loader->nvram) < 0) { + if (unlink(nvram_path) < 0) { virReportSystemError(errno, _("failed to remove nvram: %s"), - vm->def->os.loader->nvram); + nvram_path); goto endjob; } } else if (!(flags & VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)) { @@ -7948,6 +7956,8 @@ qemuDomainUndefineFlags(virDomainPtr dom, virDomainObjEndAPI(&vm); virObjectEventStateQueue(driver->domainEventState, event); virObjectUnref(cfg); + if (need_deallocate_nvram_path) + VIR_FREE(nvram_path); return ret; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list