Bug 1248277

Summary: no error output when pass a negative number to setvcpus
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.2CC: dyuan, mzhan, pkrempa, rbalakri, yafu
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
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 18:21:39 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:

Description Luyao Huang 2015-07-30 02:44:33 UTC
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-30 02:58:24 UTC
Send a patch to upstream:

https://www.redhat.com/archives/libvir-list/2015-July/msg01109.html

Comment 2 Peter Krempa 2015-10-22 07:36:12 UTC
Fixed upstream:

commit c62c59a9840cde925f4f88fddf639e434bcef33d
Author:     Luyao Huang <lhuang>
AuthorDate: Thu Oct 22 11:27:35 2015 +0800
Commit:     Andrea Bolognani <abologna>
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 10:18:23 UTC
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-16 03:27:42 UTC
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 04:28:08 UTC
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 08:03:03 UTC
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 10:40:29 UTC
The error message should make more sense as of:

commit e96041ff1ac270b719e43bf0e3d5a224fe61c26a
Author: Peter Krempa <pkrempa>
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 04:49:49 UTC
According to comment 5, move this BZ to verified.

Comment 12 errata-xmlrpc 2016-11-03 18:21:39 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://rhn.redhat.com/errata/RHSA-2016-2577.html