Bug 970548

Summary: duplicate chardev reported after chardev-remove
Product: Red Hat Enterprise Linux 7 Reporter: Paolo Bonzini <pbonzini>
Component: qemu-kvmAssignee: Bandan Das <bdas>
Status: CLOSED CURRENTRELEASE QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0CC: acathrow, bdas, flang, hhuang, juli, juzhang, mdeng, mrezanin, pbonzini, virt-maint
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: QEMU 1.5.2 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 994891 (view as bug list) Environment:
Last Closed: 2014-06-13 10:52:34 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:    
Bug Blocks: 994891    

Description Paolo Bonzini 2013-06-04 10:01:48 UTC
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

Comment 2 Min Deng 2013-06-05 11:20:43 UTC
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

Comment 3 juzhang 2013-06-06 01:48:17 UTC
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 .

Comment 4 Bandan Das 2013-07-17 19:44:55 UTC
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 10 Jun Li 2014-03-14 02:35:42 UTC
Reproduce:
Version of component:
qemu-kvm-1.5.1-2.el7.x86_64
-------
(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
(qemu) info chardev 
compat_monitor0: filename=stdio

------------------------------
verify this issue:
Version of components:
qemu-kvm-rhev-1.5.3-52.el7.x86_64
---------
Steps as comment0, no error will be reported.
(qemu) chardev-add file,path=foo2,id=foo2
(qemu) chardev-remove foo2
(qemu) chardev-add file,path=foo2,id=foo2
(qemu) info chardev 
foo2: filename=file
...
-------
Based on above test, this issue has been verified.

Comment 12 Ludek Smid 2014-06-13 10:52:34 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.