Bug 1208434

Summary: guest will disappear when use vcpupin set a non exist cpu then restart libvirtd
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: dyuan, honzhang, mzhan, rbalakri, shyu
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.15-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 06:27: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:

Description Luyao Huang 2015-04-02 09:07:27 UTC
description of problem:
guest will disappear when use vcpupin set a non exist cpu then restart libvirtd

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

How reproducible:
100%

Steps to Reproduce:
1.prepare a inactive vm:
# virsh dumpxml test3
  <vcpu placement='static' current='5'>10</vcpu>

2.use vcpupin test a non-exist guest cpu:

# virsh vcpupin test3 20 0-3 --config


3.restart libvirtd and check vm:
# service libvirtd restart
Redirecting to /bin/systemctl restart  libvirtd.service

# virsh dumpxml test3
error: failed to get domain 'test3'
error: Domain not found: no domain with matching name 'test3'

Actual results:
guest will disappear when use vcpupin set a non exist cpu then restart libvirtd

Expected results:
forbid set non-exist vcpupin to vm

infomation:

Additional info:

Comment 1 Peter Krempa 2015-04-14 07:39:28 UTC
Following upstream commits fix the issue:

commit 64985217bc57510cb9549200182be3691640e04b
Author: Peter Krempa <pkrempa>
Date:   Tue Apr 7 20:44:15 2015 +0200

    qemu: Fix condition for checking vcpu when pinning vcpus
    
    Previously we checked that the vcpu we are trying to set is in range of
    the number of threads presented by qemu. The problem is that if the VM
    is offline the count is 0. Since the condition subtracted 1 from the
    count the number would overflow and the check would never trigger.
    
    Change the condition for more sensible ones with specific error
    messages.
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1208434

commit 3f9fb2b5871cbd252af592cb210bb46fd7f57d23
Author: Peter Krempa <pkrempa>
Date:   Tue Apr 7 20:09:04 2015 +0200

    conf: Refactor virDomainVcpuPinDefParseXML
    
    Refactor the code to parse the vcpupin in a similar way the iothreadpin
    code is now structured. This allows to get rid of some very strange
    conditions and error messages.
    
    Additionally since a existing bug
    ( https://bugzilla.redhat.com/show_bug.cgi?id=1208434 ) allows to add
    vcpupin definitions for vcpus that don't exist, this patch makes the
    parser to ignore all vcpupins that don't have a matching vCPU in the
    definition rather than just offlined ones.

commit 78d1b0f9b35ae7bc1b5569aeaba6a52355a647a9
Author: Peter Krempa <pkrempa>
Date:   Tue Apr 7 19:52:02 2015 +0200

    conf: Error out if iothread id is missing in iothreadpin
    
    Defining a domain with the following config:
    
    <domain ...>
      ...
      <iothreads>1</iothreads>
      <cputune>
        <iothreadpin cpuset='1'/>
    
    will result in the following config formatted back:
    <domain type='kvm'>
      ...
      <iothreads>1</iothreads>
      <cputune>
        <iothreadpin iothread='0' cpuset='1'/>
    
    After restart the VM would vanish. Since our schema requires the
    @iothread field to be present in <iothreadpin> make it required by the
    code too.

commit 0532ec3faa5f22a0aa19e2e1a66460ba9adc1496
Author: Peter Krempa <pkrempa>
Date:   Tue Apr 7 17:44:12 2015 +0200

    conf: Split up virDomainVcpuPinDefParseXML
    
    Extract part that parses iothreads into virDomainIothreadPinDefParseXML

commit 06c03b48bded39faa0d65e0775f2fa82da618865
Author: Peter Krempa <pkrempa>
Date:   Tue Apr 7 17:13:07 2015 +0200

    conf: Split out parsing of emulatorpin
    
    Split up parts of virDomainVcpuPinDefParseXML into
    virDomainEmulatorPinDefParseXML.

v1.2.14-136-g6498521

Comment 3 hongming 2015-07-13 02:45:55 UTC
Verify it as follows.

# rpm -q libvirt qemu-kvm-rhev
libvirt-1.2.17-1.el7.x86_64
qemu-kvm-rhev-2.3.0-8.el7.x86_64

# virsh dumpxml rhel7.0|grep vcpu
  <vcpu placement='static' current='4'>8</vcpu>

# virsh vcpupin rhel7.0 5 4 --config
error: CPU 4 in cpulist '4' exceed the maxcpu 4

# virsh vcpupin rhel7.0 5 3 --config
error: invalid argument: vcpu 5 is out of range of persistent cpu count 4

# virsh vcpupin rhel7.0 5 0- 3 --config
error: unexpected data '3'

# virsh vcpupin rhel7.0 5 0-3 --config
error: invalid argument: vcpu 5 is out of range of persistent cpu count 4

# virsh vcpupin rhel7.0 4 0-3 --config
error: invalid argument: vcpu 4 is out of range of persistent cpu count 4

# virsh vcpupin rhel7.0 3 3 --config

# service libvirtd restart
Redirecting to /bin/systemctl restart  libvirtd.service

# virsh start rhel7.0
Domain rhel7.0 started

# virsh vcpuinfo rhel7.0
VCPU:           0
CPU:            2
State:          running
CPU time:       7.2s
CPU Affinity:   yyyy

VCPU:           1
CPU:            0
State:          running
CPU time:       1.3s
CPU Affinity:   yyyy

VCPU:           2
CPU:            1
State:          running
CPU time:       1.5s
CPU Affinity:   yyyy

VCPU:           3
CPU:            3
State:          running
CPU time:       1.3s
CPU Affinity:   ---y

Comment 4 hongming 2015-07-13 03:30:44 UTC
# cat rhel7.1.xml |grep iothread
  <iothreads>1</iothreads>
    <iothreadpin cpuset='1'/>


# virsh define rhel7.1.xml
error: Failed to define domain from rhel7.0.xml
error: XML error: missing iothread id in iothreadpin

Comment 5 hongming 2015-07-13 03:31:27 UTC
The result is expected. Move its status to VERIFIED.

Comment 7 errata-xmlrpc 2015-11-19 06:27: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.

https://rhn.redhat.com/errata/RHBA-2015-2202.html