Bug 1467245 - nvram file will not be deleted if use virsh to undefine a running uefi guest with --nvram option
nvram file will not be deleted if use virsh to undefine a running uefi guest ...
Status: VERIFIED
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.4
x86_64 Unspecified
medium Severity medium
: rc
: ---
Assigned To: Michal Privoznik
lijuan men
: Upstream
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-07-03 04:53 EDT by mxie@redhat.com
Modified: 2017-09-22 03:27 EDT (History)
8 users (show)

See Also:
Fixed In Version: libvirt-3.7.0-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description mxie@redhat.com 2017-07-03 04:53:35 EDT
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 07:18:13 EDT
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 08:27:04 EDT
(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 11:42:35 EDT
I've just pushed the patch upstream:

commit e488ebb31d523c68b0342ea62cd2e174644d66e3
Author:     Michal Privoznik <mprivozn@redhat.com>
AuthorDate: Mon Aug 7 13:18:23 2017 +0200
Commit:     Michal Privoznik <mprivozn@redhat.com>
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@redhat.com>

v3.6.0-64-ge488ebb31
Comment 6 lijuan men 2017-09-22 03:20:14 EDT
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

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