Bug 1961118

Summary: virsh setmem run failed with " --current" when domain is not running
Product: Red Hat Enterprise Linux Advanced Virtualization Reporter: Jing Qi <jinqi>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: Jing Qi <jinqi>
Severity: high Docs Contact:
Priority: low    
Version: 8.4CC: ehadley, jdenemar, jsuchane, lcheng, lmen, pkrempa, smitterl, virt-maint, yidliu
Target Milestone: rcKeywords: Automation, Regression, TestBlocker, Triaged, Upstream
Target Release: 8.5   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-7.4.0-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-16 07:53:34 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: 7.4.0
Embargoed:

Description Jing Qi 2021-05-17 09:56:46 UTC
Description of problem:
virsh setmem run failed with " --current"  when domain is not running 


Version-Release number of selected component (if applicable):
libvirt-7.3.0-1.module+el8.5.0+11004+f4810536.x86_64
qemu-kvm-6.0.0-16.module+el8.5.0+10848+2dccc46d.x86_64

How reproducible:

always

Steps to Reproduce:
1.  prepare vm -
<memory unit='KiB'>2621439</memory>
  <currentMemory unit='KiB'>2621439</currentMemory>
2. try to run "virsh setmem *** --current"
# virsh setmem avocado-vt-vm1 1G --current
error: Requested operation is not valid: domain is not running

Actual results:
current memory can't be set  when the domain is not running

Expected results:
current memory can be set 

Additional info:
It can be set well with libvirt-7.0.0-10.module+el8.4.0+10417+37f6984d.x86_64 & qemu-kvm-5.2.0-14.module+el8.4.0+10425+ad586fa5.x86_64.

Comment 1 Peter Krempa 2021-05-17 10:33:23 UTC
Caused by:

commit b5e267e8c59a257652f88d034cb1e0ce1ed4b58a
Author: Michal Prívozník <mprivozn>
Date:   Wed Nov 25 10:40:50 2020 +0100

    virsh: Simplify @flags handing in cmdSetmem() and cmdSetmaxmem()
    
    What code tries to achieve is that if no flags were provided to
    either 'setmem' or 'setmaxmem' commands then the old (no flags)
    API is called to be able to communicate with older daemons.
    Well, the code can be simplified a bit.
    
    Note that with this change the old no flag version of APIs is
    used more often. Previously if --current argument was given it
    resulted in *Flags() version to be called even though it is not
    necessary - VIR_DOMAIN_AFFECT_CURRENT is implied.
    
    Therefore, this change in fact allows virsh to talk with broader
    set of daemons. No other user visible changes were made.
    
    Signed-off-by: Michal Privoznik <mprivozn>
    Reviewed-by: Daniel Henrique Barboza <danielhb413>

The problem is that the legacy API virDomainSetMaxMemory implies VIR_DOMAIN_AFFECT_LIVE in it's internal call and since --current doesn't add any special flag the old API is used instead of the new one which handles CURRENT properly. This was a hack in virsh though, the public API behavior didn't change.

Comment 5 Michal Privoznik 2021-05-18 12:31:44 UTC
Ooops. Patch proposed upstream:

https://listman.redhat.com/archives/libvir-list/2021-May/msg00484.html

Comment 7 Eric Hadley 2021-05-20 18:22:31 UTC
Setting to blocker- as while this has the "test blocker" keyword it will not be a blocker for a release.

Comment 8 Michal Privoznik 2021-05-21 12:11:45 UTC
Fixed upstream as:

168190e19c virsh: Fix logic wrt to --current flag in cmdSetmem

v7.3.0-222-g168190e19c

Comment 9 Jing Qi 2021-05-24 01:01:00 UTC
Tested with libvirt upstream version v7.3.0-257-gd8c468d58c & qemu-kvm-5.2.0-0.7.rc2.fc34.x86_64.

S1. Run "virsh setmem x x --current" on a stopped vm.

1. Prepare a vm with below configuration. 
<maxMemory slots='16' unit='KiB'>8388608</maxMemory>
  <memory unit='KiB'>2621439</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>2</vcpu>

2. ✗ virsh setmem pc 2GiB --current

3. ✗ virsh dumpxml pc |grep -i memory
  <maxMemory slots='16' unit='KiB'>8388608</maxMemory>
  <memory unit='KiB'>2621439</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
      <cell id='0' cpus='0-1' memory='2097152' unit='KiB'/>
    <memory model='dimm' access='private' discard='yes'>
    </memory>

Comment 12 Jing Qi 2021-06-21 07:10:13 UTC
Verified with libvirt-daemon-7.4.0-1.module+el8.5.0+11218+83343022.x86_64 & qemu-kvm-6.0.0-19.module+el8.5.0+11385+6e7d542e.x86_64
Passed and test steps are the same as Comment 9.

Comment 14 errata-xmlrpc 2021-11-16 07:53:34 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 (virt:av bug fix and enhancement update), 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/RHBA-2021:4684