Bug 1448766

Summary: When the vm name is non-acsii, and the truncation happens to be on a multi-byte character, then vm will be unmanaged after daemon restarted.
Product: Red Hat Enterprise Linux 7 Reporter: Lili Zhu <lizhu>
Component: libvirtAssignee: Martin Kletzander <mkletzan>
Status: CLOSED ERRATA QA Contact: Lili Zhu <lizhu>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.4CC: dyuan, fjin, rbalakri, xuzhang, yafu, yanqzhan
Target Milestone: rcKeywords: Upstream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-3.7.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-10 10:43:32 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 Lili Zhu 2017-05-08 03:15:25 UTC
Description of problem:
 When the vm name is non-acsii, and the truncation happens to be on a multi-byte character, then vm will be unmanaged after daemon restarted. 

Version-Release number of selected component:
   libvirt-3.2.0-4.el7
   qemu-kvm-rhev-2.9.0-3.el7

How reproducible:
   100%

Steps to Reproduce:
1. Start a vm with non-ACSII name, and the length of the name is longer than 20.
# virsh start 朱莉莉的虚拟机 
Domain 朱莉莉的虚拟机 started
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     朱莉莉的虚拟机          running

2. Check the length of the domain name and the last character
# expr length 朱莉莉的虚拟机
21
# expr length 机
3

3. Restart libvirtd 
# systemctl restart libvirtd 

4. Check the status of vm
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     朱莉莉的虚拟机          shut off


Actual result:
The status of the vm is shut off. When domain name length is more than 20 bytes, libvirt will truncate the domain to use the first 20 bytes.
But libvirt doesn't handler it correctly when the character in domain name is not single-byte.

Expected results: 
The status of the vm should be running

Additional info:
After the vm being undefined, the qemu process of that vm still exists.
1. # virsh undefine 朱莉莉的虚拟机
Domain 朱莉莉的虚拟机 has been undefined

2. # virsh list --all
 Id    Name                           State
----------------------------------------------------

3. # ps aux | grep qemu
qemu     23653 13.6 10.9 1774632 853700 ?      Sl   21:38   0:19 /usr/libexec/qemu-kvm -name guest=朱莉莉的虚拟机,

Comment 2 Martin Kletzander 2017-08-23 11:55:51 UTC
Patch proposed upstream:

https://www.redhat.com/archives/libvir-list/2017-August/msg00636.html

Comment 3 Martin Kletzander 2017-08-29 09:27:40 UTC
Fixed upstream with v3.6.0-229-g5102be52d869:
commit 5102be52d8699a5200f25091de2d25afe3841d6d
Author: Martin Kletzander <mkletzan>
Date:   Wed Aug 23 13:18:19 2017 +0200

    conf: Properly truncate wide character names in virDomainObjGetShortName

Comment 5 Lili Zhu 2017-10-27 06:33:33 UTC
Reproduced this bug with libvirt-3.2.0-14.el7_4.3.x86_64
Test steps are as following:
1. start a guest, whose name consisting of multi-byte characters
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 3     1234567890123456789č          running

2. Check the length of the domain name and the last character
# expr length 1234567890123456789č 
21
# expr length č
2

3. Check the truncated name
# virsh dumpxml 1234567890123456789č 
....
 <channel type='unix'>
      <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-1-1234567890123456789�/org.qemu.guest_agent.0'/>   <==The guest name is not properly truncated
....     
 </channel>
....

4. restart libvirtd
# systemctl restart libvirtd

5. Check the state of the vm
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     1234567890123456789č          shut off


Verify this bug with libvirt-3.8.0-1.el7.x86_64
Test steps are as following:

1. start a guest, whose name consisting of multi-byte characters
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     1234567890123456789č          running

2. restart libvirtd
[root@ibm-x3850x5-08 ~]# systemctl restart libvirtd 

3. check the state of the guest
[root@ibm-x3850x5-08 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 3     1234567890123456789č          running

4. Check the truncated name of the vm
# virsh dumpxml 1234567890123456789č 
....
 <channel type='unix'>
      <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-9-1234567890123456789č/org.qemu.guest_agent.0'/>     <==The guest name is properly truncated
....
 </channel>
....

Since the result match with the expected result, mark it as verified

Comment 9 errata-xmlrpc 2018-04-10 10:43:32 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://access.redhat.com/errata/RHEA-2018:0704