Bug 854133

Summary: libvirt should check the range of emulator_period and emulator_quota when set them with --config
Product: Red Hat Enterprise Linux 6 Reporter: hongming <honzhang>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.4CC: acathrow, ajia, dyasny, dyuan, mzhan, rwu, ydu, yupzhang
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-0.10.2-0rc1.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 854536 854537 (view as bug list) Environment:
Last Closed: 2013-02-21 07:23:06 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:
Embargoed:
Bug Depends On:    
Bug Blocks: 854536, 854537    

Description hongming 2012-09-04 07:10:44 UTC
Description of problem:
libvirt should check the range of emulator_period and emulator_quota when set them with --config.

Refer to the http://libvirt.org/formatdomain.html#elementsCPUTuning
emulator_period - The value should be in range [1000, 1000000]. A period with value 0 means no value.
emulator_quota -The value should be in range [1000, 18446744073709551] or less than 0. A quota with value 0 means no value.


Version-Release number of selected component (if applicable):
libvirt-0.10.1-1.el6.x86_64
qemu-kvm-0.12.1.2-2.305.el6.x86_64


How reproducible:
100% 

Steps to Reproduce:
1. # virsh start rhel6.2
Domain rhel6.2 started


2.# virsh schedinfo rhel6.2 --set emulator_period=500 --config
Scheduler      : posix
cpu_shares     : 0
vcpu_period    : 0
vcpu_quota     : 0
emulator_period: 500
emulator_quota : 0


3. # virsh schedinfo rhel6.2 --set emulator_quota=500 --config
Scheduler      : posix
cpu_shares     : 0
vcpu_period    : 0
vcpu_quota     : 0
emulator_period: 500
emulator_quota : 500


4. # virsh destroy rhel6.2
Domain rhel6.2 destroyed

5.# virsh start rhel6.2
Domain rhel6.2 started

6.# virsh dumpxml rhel6.2
<domain type='kvm' id='37'>
 .....
  <cputune>
    <emulator_period>500</emulator_period>
    <emulator_quota>500</emulator_quota>
    <vcpupin vcpu='0' cpuset='1'/>
    <vcpupin vcpu='1' cpuset='2'/>
  </cputune>
.....
</domain>

# virsh schedinfo rhel6.2
Scheduler      : posix
cpu_shares     : 1024
vcpu_period    : 100000
vcpu_quota     : -1
emulator_period: 100000
emulator_quota : -1
  
Actual results:
libvirt  doesn't check the range of emulator_period and emulator_quota when set them with --config.

Expected results:
libvirt should check the range of emulator_period and emulator_quota when set them with --config.

Additional info:

Comment 2 Jiri Denemark 2012-09-04 07:46:40 UTC
Another related issue visible in step 6 is that libvirtd is silently ignoring values in emulator_{period,quota}.

Comment 3 Peter Krempa 2012-09-07 06:26:38 UTC
API range checking added upstream with:

commit 972e914f59aa90bb727c4b5596e77f7bacdeb703
Author: Peter Krempa <pkrempa>
Date:   Tue Sep 4 15:17:07 2012 +0200

    qemu: Add range checking for scheduler tunables when changed by API
    
    The quota and period tunables for cpu scheduler accept only a certain
    range of values. When changing the live configuration invalid values get
    rejected. This check is not performed when changing persistent config.
    
    This patch adds a separate range check, that improves error messages
    when changing live config and adds the check for persistent config.
    This check is done only when using the API. It is still possible to
    specify invalid values in the XML.

The range checking commit exposed a problem in virsh that was updating all tunables not the only that were changed by the user, so if an invalid configuration was present in the XML (that is still lacking range checking) users could not set the new values. This issue is fixed upstream with:

commit 51907779ee025e6edf4125cf4b4f35e279e2f6e2
Author: Peter Krempa <pkrempa>
Date:   Wed Sep 5 14:41:25 2012 +0200

    virsh: Update only changed scheduler tunables
    
    When setting the cpu tunables in virsh you are able to update only a
    subset of them. Virsh while doing the update updated all of the
    tunables, changed ones with new values and unchanged with old ones.
    This is unfortunate as it:
    a) might overwrite some other change by a race condition (unprobable)
    b) fails with range checking as some of the old values saved might be
       out of range
    
    This patch changes the update procedure so that only the changed value
    is updated on the host.
    
    This patch also fixes a very unprobable memory leak if the daemon would
    return a string tunable parameter, as the typed parameter array was not
    cleared.


I also opened bug https://bugzilla.redhat.com/show_bug.cgi?id=854537 to remind to add range checking also to XML parsing, but that's a more difficult issue.

I'm moving this bug to POST, the fix will be picked up by rebasing.

Comment 5 yanbing du 2012-09-20 09:55:36 UTC
Test with libvirt-0.10.2-0rc1.el6.x86_64.
If set emulator_period to an integer(eg. 500, 1000...), the result is correct
# virsh schedinfo aaa --set emulator_period=500 --config
Scheduler      : posix
error: invalid argument: value of 'emulator_period' is out of range [1000, 1000000]

# virsh schedinfo aaa --set emulator_period=1234 --config
Scheduler      : posix
cpu_shares     : 0
vcpu_period    : 0
vcpu_quota     : 0
emulator_period: 1234
emulator_quota : 0

but when set emulator_period to invalid value(such as 'aaa'), the result is:
# virsh schedinfo aaa --set emulator_period=aaa --config
Scheduler      : posix
and i think it also need check, right?

For emulator_period, the result is same with emulator_period.

Comment 6 Peter Krempa 2012-12-03 10:53:47 UTC
The error isn't propagated to virsh when the value of the updated argument is not valid. I opened https://bugzilla.redhat.com/show_bug.cgi?id=882915 to track this issue.

Comment 7 yanbing du 2012-12-04 02:36:26 UTC
(In reply to comment #6)
> The error isn't propagated to virsh when the value of the updated argument
> is not valid. I opened https://bugzilla.redhat.com/show_bug.cgi?id=882915 to
> track this issue.

OK, then this bug can move to VERIFIED.

Comment 8 errata-xmlrpc 2013-02-21 07:23:06 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.

http://rhn.redhat.com/errata/RHSA-2013-0276.html