Bug 1522706

Summary: Inexact error info when undefine a running uefi guest without flags
Product: Red Hat Enterprise Linux 7 Reporter: Meina Li <meili>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: Meina Li <meili>
Severity: low Docs Contact:
Priority: unspecified    
Version: 7.5CC: dyuan, hhan, jdenemar, lmen, xuzhang, yisun
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-4.3.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-10-30 09:50:00 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Meina Li 2017-12-06 09:53:14 UTC
Description of problem:
Inexact error info when undefine a running uefi guest without flags

Version-Release number of selected component (if applicable):
libvirt-3.9.0-3.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Prepare a running uefi guest:
# virsh dumpxml lmo
...
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.5.0'>hvm</type>
    <loader readonly='yes' secure='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.secboot.fd</loader>
    <nvram>/var/lib/libvirt/qemu/nvram/lmo_VARS.fd</nvram>
    <acpi>
      <table type='slic'>/var/lib/libvirt/images/slic.dat</table>
    </acpi>
    <bootmenu enable='yes' timeout='3000'/>
    <smbios mode='sysinfo'/>
  </os>
...
# virsh start lmo

2. Undefine the running guest. 
# virsh undefine lmo
error: Failed to undefine domain lmo
error: Requested operation is not valid: cannot delete inactive domain with nvram

3. Undefine the shut off guest.
# virsh destroy lmo
# virsh undefine lmo
error: Failed to undefine domain lmo
error: Requested operation is not valid: cannot delete inactive domain with nvram

Actual results:
As above step2, the guest is actually a active domain.

Expected results:
# virsh undefine lmo
error: Failed to undefine domain lmo
error: Requested operation is not valid: cannot delete active domain with nvram

Additional info:
#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.

Comment 2 Jaroslav Suchanek 2017-12-06 11:44:18 UTC
Well, undefine of live domain with nvram should be used with --nvram I guess.
So I would say that the fail is expectable. The error could be probably
better, but this is nothing serious.

Comment 3 Michal Privoznik 2017-12-11 06:58:45 UTC
Patch proposed on upstream list:

https://www.redhat.com/archives/libvir-list/2017-December/msg00327.html

Comment 4 Michal Privoznik 2017-12-11 12:31:09 UTC
Moving to POST:

commit 3446750bab844f16ee2176164e610a876e95a1d7
Author:     Michal Privoznik <mprivozn@redhat.com>
AuthorDate: Sun Dec 10 15:25:42 2017 +0100
Commit:     Michal Privoznik <mprivozn@redhat.com>
CommitDate: Mon Dec 11 13:23:30 2017 +0100

    qemuDomainUndefineFlags: Fix error message
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1522706
    
    If domain is active, but the undefine API was called without the
    VIR_DOMAIN_UNDEFINE_KEEP_NVRAM flag set, the following incorrect
    error message is produced:
    
    error: Requested operation is not valid: cannot delete inactive domain with nvram
    
    Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

v3.10.0-47-g3446750ba

Comment 6 Meina Li 2018-06-22 01:59:03 UTC
Verified on libvirt-4.4.0-2.el7.x86_64 and qemu-kvm-rhev-2.12.0-4.el7.x86_64.

Steps:
1. Prepare a running uefi guest:
# virsh dumpxml ovmf76
...
   <os>
    <type arch='x86_64' machine='pc-q35-rhel7.5.0'>hvm</type>
    <loader readonly='yes' secure='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.secboot.fd</loader>
    <nvram>/var/lib/libvirt/qemu/nvram/ovmf76_VARS.fd</nvram>
    <boot dev='hd'/>
  </os>
...
# virsh start ovmf76

2. Undefine the running and shutoff guest.
# virsh undefine ovmf76
 error: Failed to undefine domain ovmf76
 error: Requested operation is not valid: cannot undefine domain with nvram

# virsh destroy ovmf76

# virsh undefine ovmf76
 error: Failed to undefine domain ovmf76
 error: Requested operation is not valid: cannot undefine domain with nvram

3. Undefine guest with --keep-nvram
# virsh undefine ovmf76 --keep-nvram
Domain ovmf76 has been undefined

# ll /var/lib/libvirt/qemu/nvram/ovmf76_VARS.fd 
-rw-------. 1 root root 540672 Jun 21 06:03 /var/lib/libvirt/qemu/nvram/ovmf76_VARS.fd

4. Undefine guest with --nvram
# virsh undefine ovmf76 --nvram
Domain ovmf76 has been undefined

# ll /var/lib/libvirt/qemu/nvram/ovmf76_VARS.fd 
ls: cannot access /var/lib/libvirt/qemu/nvram/ovmf76_VARS.fd: No such file or directory

All the results are expected.

Comment 8 errata-xmlrpc 2018-10-30 09:50:00 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/RHSA-2018:3113