Received: from eggs.gnu.org ([140.186.70.92]:52088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RcltW-0003ST-HQ for qemu-devel@nongnu.org; Mon, 19 Dec 2011 17:41:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RcltU-00016O-Op for qemu-devel@nongnu.org; Mon, 19 Dec 2011 17:41:18 -0500 Received: from indium.canonical.com ([91.189.90.7]:33642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RcltT-00016I-Vk for qemu-devel@nongnu.org; Mon, 19 Dec 2011 17:41:16 -0500 Received: from loganberry.canonical.com ([91.189.90.37]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1RcltS-0001Lh-4V for ; Mon, 19 Dec 2011 22:41:14 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id CA3F22E80F0 for ; Mon, 19 Dec 2011 22:41:13 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Date: Mon, 19 Dec 2011 22:32:50 -0000 From: Justin L Werner <897750@bugs.launchpad.net> Sender: bounces@canonical.com References: <20111129155310.23239.76602.malonedeb@wampee.canonical.com> Message-Id: <20111219223250.9016.20495.malone@wampee.canonical.com> Errors-To: bounces@canonical.com Subject: [Qemu-devel] [Bug 897750] Re: libvirt/kvm problem with disk attach/detach/reattach on running virt Reply-To: Bug 897750 <897750@bugs.launchpad.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Some incremental findings: In 'qemu-kvm' the DeviceState for the peer device of the BlockDeviceState that gets created when a disk attached by 'virsh attach-disk' references the 'QemuOpts' options structure that lists the options and the device ID string (ex: as 'virtio-disk4') that will (on a re-attach for the same disk when the hotplug module is not loaded in the virt) be found by 'qemu_find_opts()' under the call to 'drive_add'. When the PCI hotplug module *is* loaded in the virt, the DriveState struct= ure and the associatsd QemuOpts get released from within a separate thread = by a call to 'qdev_free()' asynchronously from the main thread's invocation= of 'do_device_del()'. When the PCI hotplug modules is *not* loaded in = the virt, there is never an invocation of 'qdev_free' for the device , so t= he options structure hangs around to be located in the attempt to re-attach= a disk for the same disk, and we get the Duplicate ID error. In the e= ven of the hotplug module being loaded in the virt, the trace of the thread= which invokes 'qdev_free' looks something like: =3D=3D #1 0x00007fbb4b3403d9 in qdev_free (dev=3D0x7fbb4cc8d820) at /home/justinl= w/src/qemu/qemu-kvm-0.14.1+noroms/hw/qdev.c:382 #2 0x00007fbb4b4aabd7 in pciej_write (opaque=3D0x7fbb4c95dc90, addr=3D4455= 2, val=3D33554432) at /home/justinlw/src/qemu/qemu-kvm-0.14.1+noroms/hw/acpi_piix4.c:615 #3 0x00007fbb4b309839 in ioport_write (index=3D2, address=3D44552, data=3D= 33554432) at ioport.c:81 #4 0x00007fbb4b30a2c7 in cpu_outl (addr=3D44552, val=3D33554432) at ioport= .c:278 #5 0x00007fbb4b2a7b82 in kvm_handle_io (port=3D44552, data=3D0x7fbb4b1fa00= 0, direction=3D1, size=3D4, count=3D1) at /home/justinlw/src/qemu/qemu-kvm-0.14.1+noroms/kvm-all.c:824 #6 0x00007fbb4b2aa353 in kvm_run (env=3D0x7fbb4c734860) at /home/justinlw/= src/qemu/qemu-kvm-0.14.1+noroms/qemu-kvm.c:617 #7 0x00007fbb4b2abab8 in kvm_cpu_exec (env=3D0x7fbb4c734860) at /home/just= inlw/src/qemu/qemu-kvm-0.14.1+noroms/qemu-kvm.c:1233 #8 0x00007fbb4b2ac2dd in kvm_main_loop_cpu (env=3D0x7fbb4c734860) at /home= /justinlw/src/qemu/qemu-kvm-0.14.1+noroms/qemu-kvm.c:1419 #9 0x00007fbb4b2ac476 in ap_main_loop (_env=3D0x7fbb4c734860) at /home/jus= tinlw/src/qemu/qemu-kvm-0.14.1+noroms/qemu-kvm.c:1466 #10 0x00007fbb4a9bbefc in start_thread (arg=3D0x7fbb4397f700) at pthread_cr= eate.c:304 #11 0x00007fbb481c589d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clo= ne.S:112 #12 0x0000000000000000 in ?? () =3D=3D In a nutshell, the code is designed such that there is a resource leak if the virt does not play ball with PCI hotplugging in a case like this. I have yet to do complete line of code: I will have to have a much better understanding of the Qemu PCI handling mechanisms first, I think. Still I believe there are potentially useful findings in further nailing this bug (design feature?). -- = You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/897750 Title: libvirt/kvm problem with disk attach/detach/reattach on running virt Status in QEMU: New Status in =E2=80=9Cqemu-kvm=E2=80=9D package in Ubuntu: Confirmed Bug description: Release: Ubuntu 11.10 (Oneiric) libvirt-bin: 0.9.2-4ubuntu15.1 qemu-kvm: 0.14.1+noroms-0ubuntu6 Summary: With a running KVM virt, performing an 'attach-disk', then= a 'detach-disk', then another 'attach-disk' = in an attempt to reattach the volume at the same point on the virt, fails= , with the qemu reporting back to libvirt a 'Duplicate ID' error. Expected behavior: The 2nd invocation of 'attach-disk' should have succ= eeded Actual behavior: Duplicate ID error reported = I believe this is most likely a qemu-kvm issue, as the DOM kvm spits bac= k at libvirt after the 'detach-disk' does not show the just-detached disk. There is some kind of registry/lo= okup for devices in qemu-kvm and for whatever reason, the entry for the disk does not get removed when= it is detached from the virt. Specifically, the error gets reported at the 2nd attach-disk atte= mpt from: = qemu-option.c:qemu_opts_create:697 684 QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fa= il_if_exists) = 685 { = = 686 QemuOpts *opts =3D NULL; = = 687 = = 688 if (id) { = = 689 if (!id_wellformed(id)) { = = 690 qerror_report(QERR_INVALID_PARAMETER_VALUE, "id", "an ide= ntifier"); = 691 error_printf_unless_qmp("Identifiers consist of letters, = digits, '-', '.', '_', starting with a letter.\n"); = 692 return NULL; = = 693 } = = 694 opts =3D qemu_opts_find(list, id); = = 695 if (opts !=3D NULL) { = = 696 if (fail_if_exists) { = = 697 qerror_report(QERR_DUPLICATE_ID, id, list->name); = <<<< =3D=3D=3D=3D=3D=3D HERE =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = = 698 return NULL; = = 699 } else { = = 700 return opts; = = 701 } = = 702 } = = 703 } = = 704 opts =3D qemu_mallocz(sizeof(*opts)); = = 705 if (id) { = = 706 opts->id =3D qemu_strdup(id); = = 707 } = = 708 opts->list =3D list; = = 709 loc_save(&opts->loc); = = 710 QTAILQ_INIT(&opts->head); = = 711 QTAILQ_INSERT_TAIL(&list->head, opts, next); = = 712 return opts; = = 713 } = = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Output of my attach/detach/attach =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D virsh # attach-disk base1 /var/lib/libvirt/images/extrastorage.img vdb Disk attached successfully virsh # dumpxml base1 base1 9ebebe7f-7dfa-4735-a80c-c19ebe4e1459 1048576 1048576 2 hvm Opteron_G3 AMD destroy restart restart /usr/bin/kvm