RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1467245 - nvram file will not be deleted if use virsh to undefine a running uefi guest with --nvram option
Summary: nvram file will not be deleted if use virsh to undefine a running uefi guest ...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.4
Hardware: x86_64
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Michal Privoznik
QA Contact: lijuan men
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-07-03 08:53 UTC by mxie@redhat.com
Modified: 2018-04-10 10:52 UTC (History)
8 users (show)

Fixed In Version: libvirt-3.7.0-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-10 10:50:46 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2018:0704 0 None None None 2018-04-10 10:52:02 UTC

Description mxie@redhat.com 2017-07-03 08:53:35 UTC
Description of problem:
nvram file will not be deleted if use virsh to undefine a running uefi guest with --nvram option

Version-Release number of selected component (if applicable):
libvirt-3.2.0-14.el7.x86_64
qemu-kvm-rhev-2.9.0-14.el7.x86_64
OVMF-20170228-5.gitc325e41585e3.el7.noarch


How reproducible:
100%

Steps to Reproduce:
1.Check --nvram option in virsh man page
#man virsh  
--nvram and --keep-nvram specify accordingly to delete or keep
nvram (/domain/os/nvram/) file. If the domain has an nvram file and
the flags are omitted, the undefine will fail.

Result: nvram file should be deleted when undefine a guest with --nvram option by virsh 

2.Prepare a uefi guest
# virsh dumpxml win2012r2-efi
<domain type='kvm'>
  <name>win2012r2-efi</name>
  <uuid>05b35b4f-ea2a-4d47-8dd5-83fe77b2d1d1</uuid>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.4.0'>hvm</type>
    <loader readonly='yes' secure='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.secboot.fd</loader>
    <nvram template='/usr/share/OVMF/OVMF_VARS.fd'>/var/lib/libvirt/qemu/nvram/win2012r2-efi_VARS.fd</nvram>
....

3.Power on a guest
# virsh start win2012r2-efi
Domain win2012r2-efi started

4.Use virsh to undefine the running uefi guest with --nvram option
# virsh undefine win2012r2-efi --nvram
Domain win2012r2-efi has been undefined

5.The guest's nvram file is not deleted
# ls /var/lib/libvirt/qemu/nvram/
...    win2012r2-efi_VARS.fd

6.# virsh destroy Auto-esx6.0-win7-efi
Domain Auto-esx6.0-win7-efi destroyed

7.# virsh list --all
there is no win2012r2-efi guest

8.The guest's nvram file still exists
# ls /var/lib/libvirt/qemu/nvram/
.... win2012r2-efi_VARS.fd


Actual results:
As above description

Expected results:
nvram file will be deleted if use virsh to undefine a running uefi guest with --nvram option


Additional info:
1.nvram file could be deleted if use virsh to undefine a shutdown uefi guest with --nvram option

Comment 2 Michal Privoznik 2017-08-07 11:18:13 UTC
This is not specific just to NVRAM, e.g. snapshot metadata is also left behind. I wonder if we can remove those files and rely on qemu having them opened.

Comment 3 Michal Privoznik 2017-08-07 12:27:04 UTC
(In reply to Michal Privoznik from comment #2)
> This is not specific just to NVRAM, e.g. snapshot metadata is also left
> behind. I wonder if we can remove those files and rely on qemu having them
> opened.

Ah, my bad. snapshot metadata are removed in different parts of the code. Anyway, patches proposed here:

https://www.redhat.com/archives/libvir-list/2017-August/msg00221.html

Comment 4 Michal Privoznik 2017-08-10 15:42:35 UTC
I've just pushed the patch upstream:

commit e488ebb31d523c68b0342ea62cd2e174644d66e3
Author:     Michal Privoznik <mprivozn>
AuthorDate: Mon Aug 7 13:18:23 2017 +0200
Commit:     Michal Privoznik <mprivozn>
CommitDate: Thu Aug 10 09:30:15 2017 +0200

    qemuDomainUndefineFlags: unlink nvram file regardless of domain state
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1467245
    
    Currently, there's a bug when undefining a domain with NVRAM
    store. Basically, the unlink() of the NVRAM store file happens
    during the undefine procedure iff domain is inactive. So, if
    domain is running and undefine is called the file is left behind.
    It won't be removed in the domain cleanup process either
    (qemuProcessStop). One of the solutions is to remove if
    regardless of the domain state and rely on qemu having the file
    opened. This still has a downside that if the domain is defined
    back the NVRAM store file is going to be new, any changes to the
    current one are lost (just like with any other file that is
    deleted while a process has it opened). But is it really a
    downside?
    
    Signed-off-by: Michal Privoznik <mprivozn>

v3.6.0-64-ge488ebb31

Comment 6 lijuan men 2017-09-22 07:20:14 UTC
verify the bug:

version:
libvirt-3.7.0-2.el7.x86_64
qemu-kvm-rhev-2.9.0-16.el7_4.8.x86_64
OVMF-20170228-5.gitc325e41585e3.el7.noarch

steps:
1.prepare a OVMF guest with the xml:
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.4.0'>hvm</type>
    <loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.secboot.fd</loader>
    <nvram>/var/lib/libvirt/qemu/nvram/uefi_VARS.fd</nvram>
    <boot dev='hd'/>
  </os>

2.start the guest
[root@lmen1 ~]# virsh start uefi
Domain uefi started

3.check the vnram file
[root@lmen1 ~]# ls /var/lib/libvirt/qemu/nvram/uefi_VARS.fd
/var/lib/libvirt/qemu/nvram/uefi_VARS.fd


4.undefine the running guest
[root@lmen1 ~]# virsh undefine uefi --nvram
Domain uefi has been undefined

5.check the nvram file again
[root@lmen1 ~]# ls /var/lib/libvirt/qemu/nvram/uefi_VARS.fd
ls: cannot access /var/lib/libvirt/qemu/nvram/uefi_VARS.fd: No such file or directory

Comment 10 errata-xmlrpc 2018-04-10 10:50:46 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:0704


Note You need to log in before you can comment on or make changes to this bug.