Bug 1941407

Summary: weight info of blkiotune in guest xml does not updated after setting it via virsh blkiotune
Product: Red Hat Enterprise Linux Advanced Virtualization Reporter: Lili Zhu <lizhu>
Component: libvirtAssignee: Daniel Henrique Barboza (IBM) <dbarboza>
Status: CLOSED ERRATA QA Contact: yisun
Severity: low Docs Contact:
Priority: low    
Version: 8.4CC: jdenemar, jsuchane, knoel, lmen, pkrempa, virt-maint, xuzhang, yisun
Target Milestone: rcKeywords: Regression, Triaged
Target Release: 8.5   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-7.3.0-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-16 07:52:17 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.2.0
Embargoed:

Description Lili Zhu 2021-03-22 05:32:44 UTC
Description of problem:
weight info of blkiotune in guest xml does not updated after setting it via virsh blkiotune 

Version-Release number of selected component (if applicable):
libvirt-daemon-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

How reproducible:
100%

1. prepare a running guest 
# virsh list --all
 Id   Name    State
-----------------------
 1    lizhu   running

# virsh dumpxml lizhu |grep '<blkiotune' -A2
  <blkiotune>
    <weight>123</weight>
  </blkiotune>

2. set the blkio weight parameters
# virsh blkiotune lizhu 560; echo $?

0

3. check the blkio parameter
# virsh blkiotune lizhu
weight         : 560
device_weight  :
device_read_iops_sec:
device_write_iops_sec:
device_read_bytes_sec:
device_write_bytes_sec:

4. check the cgroup info
# cat /sys/fs/cgroup/blkio/machine.slice/machineqemu\\x2d1\\x2dlizhu.scope/blkio.bfq.weight
560

5. check the guest xml
# virsh dumpxml lizhu |grep '<blkiotune' -A2
  <blkiotune>
    <weight>123</weight>
  </blkiotune>

Expected results:
weight info in blkiotune xml should be updated
 
 Additional info:
1) virsh blkiotune --config  to a living guest, works well
2) virsh blkiotune to a shutdown guest, works well
3) can be reproduced with:
libvirt-daemon-6.6.0-8.module+el8.4.0+8855+a9e237a9.x86_64 
4) can not be reproduced with:
libvirt-6.0.0-25.5.module+el8.2.1+8680+ea98947b.x86_64

Comment 1 Peter Krempa 2021-03-22 09:39:39 UTC
The regression was introduced by:

commit ac87d3520ad542d558854a72b0ae0a81fddc6747
Author: Daniel Henrique Barboza <danielhb413>
Date:   Mon Feb 17 16:29:18 2020 -0500

    domain_cgroup.c: add virDomainCgroupSetupDomainBlkioParameters()
    
    After the introduction of virDomainDriverMergeBlkioDevice() in a
    previous patch, it is now clear that lxcDomainSetBlkioParameters() and
    qemuDomainSetBlkioParameters() uses the same loop to set cgroup
    blkio parameter of a domain.
    
    Avoid the repetition by adding a new helper called
    virDomainCgroupSetupDomainBlkioParameters().
    
    Signed-off-by: Daniel Henrique Barboza <danielhb413>
    Signed-off-by: Ján Tomko <jtomko>
    Reviewed-by: Ján Tomko <jtomko>


The important part is:

The code removed from the qemu driver:

-            if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) {
-                if (virCgroupSetBlkioWeight(priv->cgroup, param->value.ui) < 0 ||
-                    virCgroupGetBlkioWeight(priv->cgroup, &def->blkio.weight) < 0)
-                    ret = -1;


vs the code added in the common helper:

+        if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) {
+            if (virCgroupSetBlkioWeight(cgroup, params[i].value.ui) < 0)
+                ret = -1;

Comment 2 Jaroslav Suchanek 2021-03-22 09:44:26 UTC
Daniel, would you please have a look? Thanks.

Comment 3 Daniel Henrique Barboza (IBM) 2021-03-22 20:52:02 UTC
(In reply to Jaroslav Suchanek from comment #2)
> Daniel, would you please have a look? Thanks.

As said by Peter in comment #1, the problem is that the patch mentioned there removed
the virCgroupGetBlkioWeight() call that is used to set the new blkio.weight value back
to the domain.

Adding this call back fixes the issue. The patch is posted to the mailing list:


https://listman.redhat.com/archives/libvir-list/2021-March/msg01176.html

Comment 4 Daniel Henrique Barboza (IBM) 2021-03-23 14:50:28 UTC
Patch was accepted upstream and posted downstream.

Comment 7 yisun 2021-05-17 04:49:18 UTC
[root@dell-per740xd-11 ~]# rpm -qa | grep ^libvirt-7
libvirt-7.3.0-1.module+el8.5.0+11004+f4810536.x86_64

1. start vm with blkio.bfq.weight set to 123
[root@dell-per740xd-11 ~]# virsh start avocado-vt-vm1
Domain 'avocado-vt-vm1' started

[root@dell-per740xd-11 ~]# virsh dumpxml avocado-vt-vm1 | awk '/<blk/,/<\/blk/'
  <blkiotune>
    <weight>123</weight>
  </blkiotune>

2. set it to 560
[root@dell-per740xd-11 ~]# virsh blkiotune avocado-vt-vm1 560

3. check active vm xml
[root@dell-per740xd-11 ~]# virsh dumpxml avocado-vt-vm1 | awk '/<blk/,/<\/blk/'
  <blkiotune>
    <weight>560</weight>
  </blkiotune>

4. check cgroup value
[root@dell-per740xd-11 ~]# cat /sys/fs/cgroup/blkio/machine.slice/machine-qemu\\x2d1\\x2davocado\\x2dvt\\x2dvm1.scope/blkio.bfq.weight
560

Comment 10 errata-xmlrpc 2021-11-16 07:52:17 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