Bug 994891

Summary: duplicate chardev reported after chardev-remove
Product: Red Hat Enterprise Linux 6 Reporter: Amit Shah <amit.shah>
Component: qemu-kvmAssignee: Gerd Hoffmann <kraxel>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.5CC: acathrow, amit.shah, bsarathy, flang, hhuang, juzhang, lersek, mdeng, mkenneth, pbonzini, qzhang, virt-maint
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-kvm-0.12.1.2-2.388.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 970548 Environment:
Last Closed: 2013-11-21 07:08:20 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:
Bug Depends On: 970548    
Bug Blocks:    

Description Amit Shah 2013-08-08 08:26:29 UTC
RHEL6 clone

+++ This bug was initially created as a clone of Bug #970548 +++

An error is reported when readding a character device with the same id as a removed one:

(qemu) chardev-add file,path=foo2,id=foo2
(qemu) chardev-remove foo2
(qemu) chardev-add file,path=foo2,id=foo2
Duplicate ID 'foo2' for chardev
Parsing chardev args failed


--- Additional comment from dengmin on 2013-06-05 16:50:43 IST ---

Hi Paolo,
   I can not reproduce it via QMP,my detail steps:
Build info,
qemu-kvm-common-1.5.0-2.el7.x86_64
qemu-kvm-tools-1.5.0-2.el7.x86_64
qemu-kvm-1.5.0-2.el7.x86_64
qemu-kvm-debuginfo-1.5.0-2.el7.x86_64
CLI-
1./usr/libexec/qemu-kvm -cpu SandyBridge -M pc-i440fx-1.5 -enable-kvm -m 4G -smp 4,sockets=2,cores=2,threads=1 -no-kvm-pit-reinjection -usb -device usb-tablet,id=input0 -name sluo-test -uuid a5fd4bfe-ccbf-403d-9a26-41b1b3843729 -rtc base=localtime,clock=host,driftfix=slew -device virtio-serial-pci,id=virtio-serial0,max_ports=16,vectors=0,bus=pci.0,addr=0x3 -chardev socket,id=channel1,path=/tmp/helloworld1,server,nowait -device virtserialport,chardev=channel1,name=com.redhat.rhevm.vdsm,bus=virtio-serial0.0,id=port1 -chardev socket,id=channel2,path=/tmp/helloworld2,server,nowait -device virtserialport,chardev=channel2,name=com.redhat.rhevm.vdsm,bus=virtio-serial0.0,id=port2 -drive file=RHEL-Server-7.0-64-virtio-min.qcow2,if=none,id=drive-system-disk,format=qcow2,cache=none,aio=native,werror=stop,rerror=stop -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-system-disk,id=system-disk,bootindex=1 -netdev tap,id=hostnet0,vhost=on,script=/etc/qemu-ifup -device rtl8139,netdev=hostnet0,id=rtl8139-net-pci0,mac=08:2e:5f:0a:0d:a1,bus=pci.0,addr=0x5,bootindex=2 -monitor stdio -vnc :3 -qmp tcp:0:4444,server,nowait

2.{"execute":"chardev-add","arguments":{"id":"bar3","backend":{"type":"file","data":{"out":"/tmp/bar3.log"}}}}

{"return": {}} 

3.{"execute":"chardev-remove","arguments":{"id":"bar3"}}

{"return": {}}

4.{"execute":"chardev-add","arguments":{"id":"bar3","backend":{"type":"file","data":{"out":"/tmp/bar3.log"}}}} 

{"return": {}}

  I repeated many times but I still can not reproduce,if possible,could you please tell me why it cannot be reproduced via qmp? thanks in advance.

Best Regards,
Min

--- Additional comment from juzhang on 2013-06-06 07:18:17 IST ---

Additional infos,

Min can reproduce this issue by using HMP commands? Would you please tell QE what's different between HMP and QMP?  QE are using QMP command for usual testing since upper mgmt are using QMP. Thanks in advance .

--- Additional comment from Bandan Das on 2013-07-18 01:14:55 IST ---

The issue here is that the call path to hmp_chardev_remove isn't removing OptsList. The fix is already upstream :

commit 2ea3e2c1e85097c45a882dbc1fbba4a7fdb3ff1c
Author: Markus Armbruster <armbru>
Date:   Thu Jun 27 15:25:12 2013 +0200

    qemu-char: Fix ID reuse after chardev-remove for qapi-based init
    
    Commit 2c5f488 introduced qapi-based character device initialization
    as a new code path in qemu_chr_new_from_opts().  Unfortunately, it
    failed to store parameter opts in the new chardev.  Therefore,
    qemu_chr_delete() doesn't delete it.  Even though the device is gone,
    its options linger, and any attempt to create another one with the
    same ID fails.
    
    Cc: qemu-stable
    Signed-off-by: Markus Armbruster <armbru>
    Reviewed-by: Gerd Hoffmann <kraxel>
    Message-id: 1372339512-28149-1-git-send-email-armbru
    Signed-off-by: Anthony Liguori <aliguori.com>

diff --git a/qemu-char.c b/qemu-char.c
index a030e6b..63972ae 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3219,6 +3219,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
         }
 
         chr = qemu_chr_find(id);
+        chr->opts = opts;
 
     qapi_out:
         qapi_free_ChardevBackend(backend);

Comment 5 Qunfang Zhang 2013-09-04 11:31:28 UTC
Test this bug on both unfixed version qemu-kvm-0.12.1.2-2.381.el6 and fixed version qemu-kvm-0.12.1.2-2.398.el6, both can not reproduce because failed to add chardev with 'chardev-add' hmp command.  Only can hot add it with qmp command. 


1. Boot a guest with qmp.

2. 
(qemu) chardev-add file,path=foo2,id=foo2
chardev-add: unknown type 'q' ======> Failed to hot add chardev with HMP.

3. Tried with qmp commands.
(1) All with qmp commands:

{"execute":"chardev-add","arguments":{"id":"foo2","backend":{"type":"file","data":{"out":"foo2"}}}}
{"return": {}}

{"execute":"chardev-remove","arguments":{"id":"foo2"}}
{"return": {}}

{"execute":"chardev-add","arguments":{"id":"foo2","backend":{"type":"file","data":{"out":"foo2"}}}}
{"return": {}}

{"execute":"chardev-remove","arguments":{"id":"foo2"}}
{"return": {}}

{"execute":"chardev-add","arguments":{"id":"foo2","backend":{"type":"file","data":{"out":"foo2"}}}}
{"return": {}}

(2) qmp + HMP commands:

{"execute":"chardev-add","arguments":{"id":"foo2","backend":{"type":"file","data":{"out":"foo2"}}}}
{"return": {}}

(qemu) info chardev 
monitor: filename=stdio
charserial0: filename=pty:/dev/pts/2
charchannel0: filename=unix:/var/lib/libvirt/qemu/r6.agent,server
monitor1: filename=tcp:0.0.0.0:5555,server
foo2: filename=file

(qemu) chardev-remove foo2   =====> HMP "chardev-remove" works.
(qemu)  

(qemu) info chardev 
monitor: filename=stdio
charserial0: filename=pty:/dev/pts/2
charchannel0: filename=unix:/var/lib/libvirt/qemu/r6.agent,server
monitor1: filename=tcp:0.0.0.0:5555,server


{"execute":"chardev-add","arguments":{"id":"foo2","backend":{"type":"file","data":{"out":"foo2"}}}}
{"return": {}}

(qemu) chardev-remove foo2  
(qemu) 


{"execute":"chardev-add","arguments":{"id":"foo2","backend":{"type":"file","data":{"out":"foo2"}}}}
{"return": {}}

(qemu) chardev-remove foo2  
(qemu) 

Amit, we talked about this before, do you have some suggestion?

Comment 6 Amit Shah 2013-09-04 11:48:03 UTC
(In reply to Qunfang Zhang from comment #5)
> Test this bug on both unfixed version qemu-kvm-0.12.1.2-2.381.el6 and fixed
> version qemu-kvm-0.12.1.2-2.398.el6, both can not reproduce because failed
> to add chardev with 'chardev-add' hmp command.  Only can hot add it with qmp
> command. 

> Amit, we talked about this before, do you have some suggestion?

Yes, the hmp command doesn't work in RHEL6, and there are no plans to fix it.

Since the fix is obvious by code review, and since it fixes things for RHEL7, let's use that data for this bug too?

Comment 7 Qunfang Zhang 2013-09-05 07:24:40 UTC
(In reply to Amit Shah from comment #6)
> (In reply to Qunfang Zhang from comment #5)
> > Test this bug on both unfixed version qemu-kvm-0.12.1.2-2.381.el6 and fixed
> > version qemu-kvm-0.12.1.2-2.398.el6, both can not reproduce because failed
> > to add chardev with 'chardev-add' hmp command.  Only can hot add it with qmp
> > command. 
> 
> > Amit, we talked about this before, do you have some suggestion?
> 
> Yes, the hmp command doesn't work in RHEL6, and there are no plans to fix it.
> 
> Since the fix is obvious by code review, and since it fixes things for
> RHEL7, let's use that data for this bug too?

Okay, agree that and as we can not reproduce it in the latest qemu-kvm with qmp commands. So I will verify it.

Comment 9 errata-xmlrpc 2013-11-21 07:08:20 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.

http://rhn.redhat.com/errata/RHSA-2013-1553.html