Bug 1160559

Summary: libvirt do a wrong check when try to use vcpupin --config to a running vm
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirtAssignee: Pavel Hrdina <phrdina>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: dyuan, mzhan, phrdina, pkrempa, rbalakri
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.17-3.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 05:55:08 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 2014-11-05 07:32:01 UTC
Description of problem:
libvirt do a wrong check when try to use vcpupin --config to a running vm

Version-Release number of selected component (if applicable):
libvirt-1.2.8-6.el7.x86_64
qemu-kvm-rhev-2.1.2-6.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
S1:
1.prepare a vm with:
<vcpu placement='static' current='2'>4</vcpu>

2.# virsh start test3
Domain test3 started

3.# virsh vcpupin test3
VCPU: CPU Affinity
----------------------------------
   0: 0-3
   1: 0-3

4.
# virsh setvcpus test3 3 --config

5.# virsh dumpxml test3 --inactive|grep cpu
  <vcpu placement='static' current='3'>4</vcpu>

6.cannot see vcpu 2 when use vcpupin --config:
# virsh vcpupin test3 --config
VCPU: CPU Affinity
----------------------------------
   0: 0-3
   1: 0-3

7.# virsh vcpupin test3 2 1 --config
error: vcpupin: vCPU index out of range.

S2:

1.prepare a vm with:
<vcpu placement='static' current='2'>4</vcpu>

2.# virsh start test3
Domain test3 started

3.# virsh vcpupin test3
VCPU: CPU Affinity
----------------------------------
   0: 0-3
   1: 0-3

4.hot-plug a vcpu:
# virsh setvcpus test3 3

5.# virsh dumpxml test3 |grep cpu
  <vcpu placement='static' current='3'>4</vcpu>

6.# virsh dumpxml test3 --inactive |grep cpu
  <vcpu placement='static' current='2'>4</vcpu>

7.# virsh vcpupin test3 2 --config
VCPU: CPU Affinity
----------------------------------

8.# virsh vcpupin test3 2 1 --config

9.libvirt will add a wrong config in xml
# virsh dumpxml test3 --inactive |grep cpu
  <vcpu placement='static' current='2'>4</vcpu>
  <cputune>
    <vcpupin vcpu='2' cpuset='1'/>
  </cputune>


Actual results:
S1:cannot see vcpu 2 in vcpupin --config and cannot use vcpupin --config to vcpu2
S2:libvirt set a wrong config for a non-exist vcpu in xml

Expected results:
S1:can see vcpu 2 in vcpupin and can set vcpupin to it
S2:report error 

Additional info:

libvirt do a wrong check in cmdVcpupin

    if (virDomainGetInfo(dom, &info) != 0) {
        vshError(ctl, "%s", _("vcpupin: failed to get domain information."));
        goto cleanup;
    }

    if (vcpu >= info.nrVirtCpu) {
        vshError(ctl, "%s", _("vcpupin: vCPU index out of range."));
        goto cleanup;
    }

when a domain is running, virDomainGetInfo will get domain's active info not config info.

Comment 1 Pavel Hrdina 2015-02-20 07:39:42 UTC
Proposed upstream patch:

https://www.redhat.com/archives/libvir-list/2015-February/msg00801.html

Comment 2 Pavel Hrdina 2015-02-20 18:22:56 UTC
Upstream commit:

commit 81dd81e475c475b536eba08417a48a1e5210a265
Author: Pavel Hrdina <phrdina>
Date:   Fri Feb 20 08:21:05 2015 +0100

    virsh: fix vcpupin info
    
    The "virDomainGetInfo" will get for running domain only live info and for
    offline domain only config info. There was no way how to get config info
    for running domain. We will use "vshCPUCountCollect" instead to get the
    correct cpu count that we need to pass to "virDomainGetVcpuPinInfo".
    
    Also cleanup some unnecessary variables and checks that are done by
    drivers.
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1160559
    
    Signed-off-by: Pavel Hrdina <phrdina>

Comment 5 Luyao Huang 2015-06-25 08:16:21 UTC
Verify this issue with libvirt-1.2.16-1.el7.x86_64:

S1:

1.prepare a vm with:
<vcpu placement='static' current='2'>4</vcpu>

2.# virsh start test3
Domain test3 started

3.# virsh vcpupin test3
VCPU: CPU Affinity
----------------------------------
   0: 0-3
   1: 0-3

4.
# virsh setvcpus test3 3 --config

5.# virsh dumpxml test3 --inactive|grep cpu
  <vcpu placement='static' current='3'>4</vcpu>

6.
# virsh vcpupin test3 --config
VCPU: CPU Affinity
----------------------------------
   0: 0-3
   1: 0-3
   2: 0-3


7.
# virsh vcpupin test3 2 --config
VCPU: CPU Affinity
----------------------------------
   2: 0-3

# virsh vcpupin test3 2 1 --config

# virsh vcpupin test3 2 --config
VCPU: CPU Affinity
----------------------------------
   2: 1


S2:



1.prepare a vm with:
<vcpu placement='static' current='2'>4</vcpu>

2.# virsh start test3
Domain test3 started

3.# virsh vcpupin test3
VCPU: CPU Affinity
----------------------------------
   0: 0-3
   1: 0-3

4.hot-plug a vcpu:
# virsh setvcpus test3 3

5.# virsh dumpxml test3 |grep cpu
  <vcpu placement='static' current='3'>4</vcpu>

6.# virsh dumpxml test3 --inactive |grep cpu
  <vcpu placement='static' current='2'>4</vcpu>

7. I still think this is not okay, we should output error in this step(i will send a patch to upstream):

# virsh vcpupin test3 2 --config
VCPU: CPU Affinity
----------------------------------

8.
# virsh vcpupin test3 2 1 --config
error: invalid argument: vcpu 2 is out of range of persistent cpu count 2

Comment 6 Luyao Huang 2015-07-03 02:05:54 UTC
Hi Pavel,

We need a bz for the issue described in comment 5 S2 step 7, and patch:

commit 848ab685f74afae102e265108518095942ecb293
Author: Luyao Huang <lhuang>
Date:   Mon Jun 29 10:10:15 2015 +0800

    virsh: report error if vcpu number exceed the guest maxvcpu number

Do you think it is okay to reopen this bug for this patch ? or we need open a new bz to track this ?

Thanks in advance for your reply.

Luyao

Comment 7 Peter Krempa 2015-07-14 06:34:13 UTC
(In reply to Luyao Huang from comment #6)
> 
> commit 848ab685f74afae102e265108518095942ecb293

Note that after that commit the code is still incorrect as the condition that was added in the commit does not work as expected. Since VIR_DOMAIN_AFFECT_CURRENT is 0 the condition will not trigger if --live is not selected and thus will report "persistent" in the message even if the VM is online but no mode was selected.

Comment 8 Luyao Huang 2015-07-14 08:46:39 UTC
(In reply to Peter Krempa from comment #7)
> (In reply to Luyao Huang from comment #6)
> > 
> > commit 848ab685f74afae102e265108518095942ecb293
> 
> Note that after that commit the code is still incorrect as the condition
> that was added in the commit does not work as expected. Since
> VIR_DOMAIN_AFFECT_CURRENT is 0 the condition will not trigger if --live is
> not selected and thus will report "persistent" in the message even if the VM
> is online but no mode was selected.

Oh, thanks a lot for your reply, i will write a new patch to fix it.

Comment 9 Pavel Hrdina 2015-07-14 10:52:12 UTC
Hi Luyao,

You can reopen this bug to track that issue, because it's related to the original bug and to the patch fixing this bug.

Comment 10 Luyao Huang 2015-07-15 03:11:00 UTC
(In reply to Pavel Hrdina from comment #9)
> Hi Luyao,
> 
> You can reopen this bug to track that issue, because it's related to the
> original bug and to the patch fixing this bug.

Thanks a lot for your reply, reopen this bug.

Comment 12 Luyao Huang 2015-09-22 04:05:55 UTC
Verify the left issue with libvirt-1.2.17-9.el7.x86_64:

1. prepare a inactive guest:

# virsh domstate  test3
shut off

2. check the output error:

# virsh vcpupin test3 --config
VCPU: CPU Affinity
----------------------------------
   0: 0-2
   1: 0-2

# virsh vcpupin test3 1 --config
VCPU: CPU Affinity
----------------------------------
   1: 0-2

# virsh vcpupin test3 2 --config
error: vcpu 2 is out of range of persistent cpu count 2

# virsh vcpupin test3 2 --current
error: vcpu 2 is out of range of persistent cpu count 2


3. start the guest:

# virsh start test3
Domain test3 started

4. check the output error

# virsh vcpupin test3 --config
VCPU: CPU Affinity
----------------------------------
   0: 0-2
   1: 0-2

# virsh vcpupin test3 --live
VCPU: CPU Affinity
----------------------------------
   0: 0-2
   1: 0-2

# virsh vcpupin test3 2 --live
error: vcpu 2 is out of range of live cpu count 2

# virsh vcpupin test3 2 --config
error: vcpu 2 is out of range of persistent cpu count 2

# virsh vcpupin test3 2 --current
error: vcpu 2 is out of range of live cpu count 2

# virsh vcpupin test3 2 3
error: invalid argument: vcpu 2 is out of range of live cpu count 2

# virsh vcpupin test3 2 3 --config
error: invalid argument: vcpu 2 is out of range of persistent cpu count 2

Comment 14 errata-xmlrpc 2015-11-19 05:55:08 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/RHBA-2015-2202.html