Bug 1248277 - no error output when pass a negative number to setvcpus
no error output when pass a negative number to setvcpus
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.2
x86_64 Linux
low Severity low
: rc
: ---
Assigned To: Libvirt Maintainers
Virtualization Bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-07-29 22:44 EDT by Luyao Huang
Modified: 2016-11-03 14:21 EDT (History)
5 users (show)

See Also:
Fixed In Version: libvirt-1.3.1-1.el7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-11-03 14:21:39 EDT
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 Luyao Huang 2015-07-29 22:44:33 EDT
Description of problem:
no error output when pass a negative number to setvcpus

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

How reproducible:
100%

Steps to Reproduce:
1.
# virsh setvcpus rhel7.0 0

2.
# virsh setvcpus rhel7.0 -1


3.

Actual results:
no error in setp 1 & 2

Expected results:

output error in step 1 & 2

Additional info:

test with 1.2.16 and can get an error:

# rpm -q libvirt
libvirt-1.2.16-1.el7.x86_64

# virsh setvcpus rhel7.0 -1
error: Numeric value for <count> option is malformed or out of range
Comment 1 Luyao Huang 2015-07-29 22:58:24 EDT
Send a patch to upstream:

https://www.redhat.com/archives/libvir-list/2015-July/msg01109.html
Comment 2 Peter Krempa 2015-10-22 03:36:12 EDT
Fixed upstream:

commit c62c59a9840cde925f4f88fddf639e434bcef33d
Author:     Luyao Huang <lhuang@redhat.com>
AuthorDate: Thu Oct 22 11:27:35 2015 +0800
Commit:     Andrea Bolognani <abologna@redhat.com>
CommitDate: Thu Oct 22 09:22:44 2015 +0200

    virsh: Display an error when passing count <= 0 to setvcpus
    
    The number of vCPUs for a guest must be between 1 and the
    maximum value configured in the domain XML. This commit
    introduces checks to make sure that passing count <= 0
    results in an error.
Comment 4 yafu 2016-03-07 05:18:23 EST
Passed with version libvirt-1.3.1-1.el7.x86_64.

steps:
1.#virsh setvcpus rhel7.2 0
error: Can't set 0 processors for a VM

2.#virsh setvcpus rhel7.2 -1
error: Numeric value '-1' for <count> option is malformed or out of range

3.#virsh setvcpus rhel7.2 4294967296
error: Numeric value '4294967296' for <count> option is malformed or out of range

4.#virsh setvcpus rhel7.2 4294967295
error: invalid argument: requested vcpus is greater than max allowable vcpus for the domain: -1 > 1

5.#virsh setvcpus rhel7.2 4294967297
error: Numeric value '4294967297' for <count> option is malformed or out of range
Comment 5 yafu 2016-08-15 23:27:42 EDT
Reproduced with libvirt-1.2.17-2.el7.x86_64.


Verified pass with libvirt-2.0.0-5.el7.x86_64.
steps:
1.virsh setvcpus rhel7.2 0
error: Can't set 0 processors for a VM

2.#virsh setvcpus rhel7.2 -1
error: Numeric value '-1' for <count> option is malformed or out of range

3.#virsh setvcpus rhle7.2 -4294967296
error: Numeric value '-4294967296' for <count> option is malformed or out of range

4.virsh setvcpus rhel7 -4.0
error: Numeric value '-4.1' for <count> option is malformed or out of range
Comment 6 yafu 2016-08-16 00:28:08 EDT
Hi,Peter, 

When I pass a number between 2^31 to 2^32-1,the error output is strange:

1.#virsh setvcpus rhel7.2 2147483648
error: invalid argument: requested vcpus is greater than max allowable vcpus for the domain: -2147483648 > 4

2.# virsh setvcpus rhel7 4294967295
error: invalid argument: requested vcpus is greater than max allowable vcpus for the domain: -1 > 4


Would you help to check whether it needs to be fixed please?
Thank you!
Comment 7 Peter Krempa 2016-08-16 04:03:03 EDT
The problem is in the format character in the error message:

    if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && nvcpus > maxvcpus) {
        virReportError(VIR_ERR_INVALID_ARG,
                       _("requested vcpus is greater than max allowable"
                         " vcpus for the domain: %d > %d"),
                       nvcpus, maxvcpus);
        goto endjob;
    }


Both nvcpus and maxvcpus are unsigned. I'll post a patch upstream.
Comment 9 Peter Krempa 2016-08-16 06:40:29 EDT
The error message should make more sense as of:

commit e96041ff1ac270b719e43bf0e3d5a224fe61c26a
Author: Peter Krempa <pkrempa@redhat.com>
Date:   Wed Aug 3 12:57:23 2016 +0200

    qemu: setcpus: Report better errors
    
    Mention whether it was the live or persistent definition which caused an
    error reported and explicitly error out in case when attempting to set
    maximum vcpu count for a live domain.
Comment 10 yafu 2016-08-17 00:49:49 EDT
According to comment 5, move this BZ to verified.
Comment 12 errata-xmlrpc 2016-11-03 14:21:39 EDT
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://rhn.redhat.com/errata/RHSA-2016-2577.html

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