Patchwork Remove a detached device from qemu_device_opts.

login
register
mail settings
Submitter Ken'ichi Ohmichi
Date Jan. 27, 2011, 9 a.m.
Message ID <20110127180057.eb28d17f.oomichi@mxs.nes.nec.co.jp>
Download mbox | patch
Permalink /patch/80613/
State New
Headers show

Comments

Ken'ichi Ohmichi - Jan. 27, 2011, 9 a.m.
Hi,

When I tried to attach the interface after detaching the same interface,
the virsh command output the following and it failed:

  # virsh detach-interface Domain01 network --mac 52:54:00:0d:78:92
  Interface detached successfully

  # virsh attach-interface Domain01 network default --mac 52:54:00:0d:78:92
  error: Failed to attach interface
  error: internal error unable to execute QEMU command 'device_add': Duplicate ID 'net0' for device
  #

The reason is that a detached device is not removed from the list
"qemu_device_opts", and this patch fixes it.


Thanks
Ken'ichi Ohmichi


Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
---
William Dauchy - Feb. 7, 2011, 2:40 p.m.
On Thu, 2011-01-27 at 18:00 +0900, Ken'ichi Ohmichi wrote:
> Hi,
> 
> When I tried to attach the interface after detaching the same interface,
> the virsh command output the following and it failed:
> 
>   # virsh detach-interface Domain01 network --mac 52:54:00:0d:78:92
>   Interface detached successfully
> 
>   # virsh attach-interface Domain01 network default --mac 52:54:00:0d:78:92
>   error: Failed to attach interface
>   error: internal error unable to execute QEMU command 'device_add': Duplicate ID 'net0' for device
>   #
> 
> The reason is that a detached device is not removed from the list
> "qemu_device_opts", and this patch fixes it.
> Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
> ---
> --- a/hw/qdev.c	2011-01-27 17:42:25.000000000 +0900
> +++ b/hw/qdev.c	2011-01-27 17:43:46.000000000 +0900
> @@ -905,6 +905,8 @@ int do_device_del(Monitor *mon, const QD
>          qerror_report(QERR_DEVICE_NOT_FOUND, id);
>          return -1;
>      }
> +    qemu_opts_del(qemu_opts_find(&qemu_device_opts, id));
> +
>      return qdev_unplug(dev);
>  }

I successfully applied and tested this patch. It resolves the attach
problem.
William Dauchy - Feb. 12, 2011, 9:28 p.m.
Hi,

On Mon, Feb 7, 2011 at 3:40 PM, William Dauchy <wdauchy@gmail.com> wrote:
> On Thu, 2011-01-27 at 18:00 +0900, Ken'ichi Ohmichi wrote:
>> Hi,
>>
>> When I tried to attach the interface after detaching the same interface,
>> the virsh command output the following and it failed:
>>
>>   # virsh detach-interface Domain01 network --mac 52:54:00:0d:78:92
>>   Interface detached successfully
>>
>>   # virsh attach-interface Domain01 network default --mac 52:54:00:0d:78:92
>>   error: Failed to attach interface
>>   error: internal error unable to execute QEMU command 'device_add': Duplicate ID 'net0' for device
>>   #
>>
>> The reason is that a detached device is not removed from the list
>> "qemu_device_opts", and this patch fixes it.
>> Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
>> ---
>> --- a/hw/qdev.c       2011-01-27 17:42:25.000000000 +0900
>> +++ b/hw/qdev.c       2011-01-27 17:43:46.000000000 +0900
>> @@ -905,6 +905,8 @@ int do_device_del(Monitor *mon, const QD
>>          qerror_report(QERR_DEVICE_NOT_FOUND, id);
>>          return -1;
>>      }
>> +    qemu_opts_del(qemu_opts_find(&qemu_device_opts, id));
>> +
>>      return qdev_unplug(dev);
>>  }
>
> I successfully applied and tested this patch. It resolves the attach
> problem.
>

I was wondering if it was going to be merged upstream?

Regards,
Wen Congyang - Feb. 14, 2011, 6:19 a.m.
At 01/27/2011 05:00 PM, Ken'ichi Ohmichi Write:
> 
> Hi,
> 
> When I tried to attach the interface after detaching the same interface,
> the virsh command output the following and it failed:
> 
>   # virsh detach-interface Domain01 network --mac 52:54:00:0d:78:92
>   Interface detached successfully
> 
>   # virsh attach-interface Domain01 network default --mac 52:54:00:0d:78:92
>   error: Failed to attach interface
>   error: internal error unable to execute QEMU command 'device_add': Duplicate ID 'net0' for device
>   #

I can reproduce this problem.

> 
> The reason is that a detached device is not removed from the list
> "qemu_device_opts", and this patch fixes it.

The detached device will be removed from the list "qemu_device_opts"
in qdev_free() asynchronously.

> 
> 
> Thanks
> Ken'ichi Ohmichi
> 
> 
> Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
> ---
> --- a/hw/qdev.c	2011-01-27 17:42:25.000000000 +0900
> +++ b/hw/qdev.c	2011-01-27 17:43:46.000000000 +0900
> @@ -905,6 +905,8 @@ int do_device_del(Monitor *mon, const QD
>          qerror_report(QERR_DEVICE_NOT_FOUND, id);
>          return -1;
>      }
> +    qemu_opts_del(qemu_opts_find(&qemu_device_opts, id));
> +

We can not use qemu_device_opts here, because qemu_device_opts is
a static variable in qemu-config.c. We should use qemu_find_opts("device")
instead of qemu_device_opts.

I test your patch by attach/detach interface, and qemu core dumps.
The reason may be that we call qemu_opts_del() twice.

Here is the log(/var/log/libvirt/qemu/<domain>.log):

*** glibc detected *** /usr/libexec/qemu-system-x86_64: free(): invalid pointer: 0x000000000355f000 ***
======= Backtrace: =========
/lib64/libc.so.6[0x351f275676]
/usr/libexec/qemu-system-x86_64[0x43e2a6]
/usr/libexec/qemu-system-x86_64[0x43f9a0]
/usr/libexec/qemu-system-x86_64[0x4400ee]
/usr/libexec/qemu-system-x86_64[0x4cb176]
/usr/libexec/qemu-system-x86_64[0x5af9f6]
/usr/libexec/qemu-system-x86_64[0x4953c1]
/usr/libexec/qemu-system-x86_64[0x495dab]
/usr/libexec/qemu-system-x86_64[0x43a087]
/usr/libexec/qemu-system-x86_64[0x43a5dd]
/usr/libexec/qemu-system-x86_64[0x51f8f5]
/usr/libexec/qemu-system-x86_64[0x40ad4b]
/usr/libexec/qemu-system-x86_64[0x40ae52]
/usr/libexec/qemu-system-x86_64[0x585c81]
/usr/libexec/qemu-system-x86_64[0x589da7]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x351f21ec5d]
/usr/libexec/qemu-system-x86_64[0x408a19]
======= Memory map: ========
00400000-00784000 r-xp 00000000 08:06 679152                             /usr/libexec/qemu-system-x86_64
00983000-009c9000 rw-p 00383000 08:06 679152                             /usr/libexec/qemu-system-x86_64
009c9000-01177000 rw-p 00000000 00:00 0 
01177000-01178000 rwxp 00000000 00:00 0 
01178000-011d5000 rw-p 00000000 00:00 0 
02d32000-03109000 rw-p 00000000 00:00 0 
03109000-03119000 rw-p 00000000 00:00 0 
03119000-03134000 rw-p 00000000 00:00 0 
03134000-03144000 rw-p 00000000 00:00 0 
03144000-0352c000 rw-p 00000000 00:00 0 
0352c000-0353c000 rw-p 00000000 00:00 0 
0353c000-0354f000 rw-p 00000000 00:00 0 
0354f000-0355f000 rw-p 00000000 00:00 0 
0355f000-03580000 rw-p 00000000 00:00 0 
4154f000-4954f000 rwxp 00000000 00:00 0 
328d000000-328d038000 r-xp 00000000 08:06 394303                         /lib64/libgssapi_krb5.so.2.2
328d038000-328d237000 ---p 00038000 08:06 394303                         /lib64/libgssapi_krb5.so.2.2
328d237000-328d239000 rw-p 00037000 08:06 394303                         /lib64/libgssapi_krb5.so.2.2
328d400000-328d453000 r-xp 00000000 08:06 685072                         /usr/lib64/libssl.so.1.0.0
328d453000-328d653000 ---p 00053000 08:06 685072                         /usr/lib64/libssl.so.1.0.0
328d653000-328d65b000 rw-p 00053000 08:06 685072                         /usr/lib64/libssl.so.1.0.0
328d800000-328d827000 r-xp 00000000 08:06 394300                         /lib64/libk5crypto.so.3.1
328d827000-328da27000 ---p 00027000 08:06 394300                         /lib64/libk5crypto.so.3.1
328da27000-328da29000 rw-p 00027000 08:06 394300                         /lib64/libk5crypto.so.3.1
328ec00000-328eccf000 r-xp 00000000 08:06 394302                         /lib64/libkrb5.so.3.3
328eccf000-328eecf000 ---p 000cf000 08:06 394302                         /lib64/libkrb5.so.3.3
328eecf000-328eeda000 rw-p 000cf000 08:06 394302                         /lib64/libkrb5.so.3.3
328f000000-328f003000 r-xp 00000000 08:06 394301                         /lib64/libcom_err.so.2.1
328f003000-328f202000 ---p 00003000 08:06 394301                         /lib64/libcom_err.so.2.1
328f202000-328f203000 rw-p 00002000 08:06 394301                         /lib64/libcom_err.so.2.1
328f400000-328f40a000 r-xp 00000000 08:06 393785                         /lib64/libkrb5support.so.0.1
328f40a000-328f609000 ---p 0000a000 08:06 393785                         /lib64/libkrb5support.so.0.1
328f609000-328f60a000 rw-p 00009000 08:06 393785                         /lib64/libkrb5support.so.0.1
351ea00000-351ea1e000 r-xp 00000000 08:06 398307                         /lib64/ld-2.12.so
351ec1e000-351ec1f000 r--p 0001e000 08:06 398307                         /lib64/ld-2.12.so
351ec1f000-351ec20000 rw-p 0001f000 08:06 398307                         /lib64/ld-2.12.so
351ec20000-351ec21000 rw-p 00000000 00:00 0 
351ee00000-351ee01000 r-xp 00000000 08:06 391907                         /lib64/libaio.so.1.0.1
351ee01000-351f000000 ---p 00001000 08:06 391907                         /lib64/libaio.so.1.0.1
351f000000-351f001000 rw-p 00000000 08:06 391907                         /lib64/libaio.so.1.0.1
351f200000-351f375000 r-xp 00000000 08:06 398308                         /lib64/libc-2.12.so
351f375000-351f575000 ---p 00175000 08:06 398308                         /lib64/libc-2.12.so
351f575000-351f579000 r--p 00175000 08:06 398308                         /lib64/libc-2.12.so
351f579000-351f57a000 rw-p 00179000 08:06 398308                         /lib64/libc-2.12.so
351f57a000-351f57f000 rw-p 00000000 00:00 0 
351f600000-351f683000 r-xp 00000000 08:06 398327                         /lib64/libm-2.12.so
351f683000-351f882000 ---p 00083000 08:06 398327                         /lib64/libm-2.12.so
351f882000-351f883000 r--p 00082000 08:06 398327                         /lib64/libm-2.12.so
351f883000-351f884000 rw-p 00083000 08:06 398327                         /lib64/libm-2.12.so
351fa00000-351fa02000 r-xp 00000000 08:06 398310                         /lib64/libdl-2.12.so
351fa02000-351fc02000 ---p 00002000 08:06 398310                         /lib64/libdl-2.12.so
351fc02000-351fc03000 r--p 00002000 08:06 398310                         /lib64/libdl-2.12.so
351fc03000-351fc04000 rw-p 00003000 08:06 398310                         /lib64/libdl-2.12.so
351fe00000-351fe17000 r-xp 00000000 08:06 398316                         /lib64/libpthread-2.12.so
351fe17000-3520017000 ---p 00017000 08:06 398316                         /lib64/libpthread-2.12.so
3520017000-3520018000 r--p 00017000 08:06 398316                         /lib64/libpthread-2.12.so
3520018000-3520019000 rw-p 00018000 08:06 398316                         /lib64/libpthread-2.12.so
3520019000-352001d000 rw-p 00000000 00:00 0 
3520200000-3520215000 r-xp 00000000 08:06 398326                         /lib64/libz.so.1.2.3
3520215000-3520414000 ---p 00015000 08:06 398326                         /lib64/libz.so.1.2.3
3520414000-3520415000 rw-p 00014000 08:06 398326                         /lib64/libz.so.1.2.3
3520600000-3520607000 r-xp 00000000 08:06 398319                         /lib64/librt-2.12.so
3520607000-3520806000 ---p 00007000 08:06 398319                         /lib64/librt-2.12.so
3520806000-3520807000 r--p 00006000 08:06 398319                         /lib64/librt-2.12.so
3520807000-3520808000 rw-p 00007000 08:06 398319                         /lib64/librt-2.12.so
3520a00000-3520a1d000 r-xp 00000000 08:06 398313                         /lib64/libselinux.so.1
3520a1d000-3520c1c000 ---p 0001d000 08:06 398313                         /lib64/libselinux.so.1
3520c1c000-3520c1d000 r--p 0001c000 08:06 398313                         /lib64/libselinux.so.1
3520c1d000-3520c1e000 rw-p 0001d000 08:06 398313                         /lib64/libselinux.so.1
3520c1e000-3520c1f000 rw-p 00000000 00:00 0 
3520e00000-3520e16000 r-xp 00000000 08:06 398312                         /lib64/libresolv-2.12.so
3520e16000-3521016000 ---p 00016000 08:06 398312                         /lib64/libresolv-2.12.so
3521016000-3521017000 r--p 00016000 08:06 398312                         /lib64/libresolv-2.12.so
3521017000-3521018000 rw-p 00017000 08:06 398312                         /lib64/libresolv-2.12.so
3521018000-352101a000 rw-p 00000000 00:00 0 
3521e00000-3521e1b000 r-xp 00000000 08:06 691194                         /usr/lib64/libxcb.so.1.1.0
3521e1b000-352201a000 ---p 0001b000 08:06 691194                         /usr/lib64/libxcb.so.1.1.0
352201a000-352201b000 rw-p 0001a000 08:06 691194                         /usr/lib64/libxcb.so.1.1.0
3522600000-3522602000 r-xp 00000000 08:06 691193                         /usr/lib64/libXau.so.6.0.0
3522602000-3522802000 ---p 00002000 08:06 691193                         /usr/lib64/libXau.so.6.0.0
3522802000-3522803000 rw-p 00002000 08:06 691193                         /usr/lib64/libXau.so.6.0.0
3522a00000-3522b39000 r-xp 00000000 08:06 691195                         /usr/lib64/libX11.so.6.3.0
3522b39000-3522d39000 ---p 00139000 08:06 691195                         /usr/lib64/libX11.so.6.3.0
3522d39000-3522d3f000 rw-p 00139000 08:06 691195                         /usr/lib64/libX11.so.6.3.0
3522e00000-3522e26000 r-xp 00000000 08:06 691192                         /usr/lib64/libpng12.so.0.44.0
3522e26000-3523025000 ---p 00026000 08:06 691192                         /usr/lib64/libpng12.so.0.44.0
3523025000-3523026000 rw-p 00025000 08:06 691192                         /usr/lib64/libpng12.so.0.44.0
3529a00000-3529a32000 r-xp 00000000 08:06 398336                         /lib64/libidn.so.11.6.1
3529a32000-3529c31000 ---p 00032000 08:06 398336                         /lib64/libidn.so.11.6.1
3529c31000-3529c32000 rw-p 00031000 08:06 398336                         /lib64/libidn.so.11.6.1
352a200000-352a216000 r-xp 00000000 08:06 398354                         /lib64/libgcc_s-4.4.4-20100726.so.1
352a216000-352a415000 ---p 00016000 08:06 398354                         /lib64/libgcc_s-4.4.4-20100726.so.1
352a415000-352a416000 rw-p 00015000 08:06 398354                         /lib64/libgcc_s-4.4.4-20100726.so.1
352a600000-352a771000 r-xp 00000000 08:06 691225                         /usr/lib64/libcrypto.so.1.0.0
352a771000-352a970000 ---p 00171000 08:06 691225                         /usr/lib64/libcrypto.so.1.0.0
352a970000-352a993000 rw-p 00170000 08:06 691225                         /usr/lib64/libcrypto.so.1.0.0
352a993000-352a996000 rw-p 00000000 00:00 0 
352ae00000-352ae02000 r-xp 00000000 08:06 398311                         /lib64/libkeyutils.so.1.3
352ae02000-352b001000 ---p 00002000 08:06 398311                         /lib64/libkeyutils.so.1.3
352b001000-352b002000 rw-p 00001000 08:06 398311                         /lib64/libkeyutils.so.1.3
352ba00000-352ba04000 r-xp 00000000 08:06 398334                         /lib64/libuuid.so.1.3.0
352ba04000-352bc03000 ---p 00004000 08:06 398334                         /lib64/libuuid.so.1.3.0
352bc03000-352bc04000 rw-p 00003000 08:06 398334                         /lib64/libuuid.so.1.3.0
352c600000-352c607000 r-xp 00000000 08:06 398331                         /lib64/libcrypt-2.12.so
352c607000-352c807000 ---p 00007000 08:06 398331                         /lib64/libcrypt-2.12.so
352c807000-352c808000 r--p 00007000 08:06 398331                         /lib64/libcrypt-2.12.so
352c808000-352c809000 rw-p 00008000 08:06 398331                         /lib64/libcrypt-2.12.so
352c809000-352c837000 rw-p 00000000 00:00 0 
352ca00000-352ca58000 r-xp 00000000 08:06 398330                         /lib64/libfreebl3.so
352ca58000-352cc57000 ---p 00058000 08:06 398330                         /lib64/libfreebl3.so
352cc57000-352cc59000 rw-p 00057000 08:06 398330                         /lib64/libfreebl3.so
352cc59000-352cc5d000 rw-p 00000000 00:00 0 
352da00000-352da24000 r-xp 00000000 08:06 659699                         /usr/lib64/libjpeg.so.62.0.0
352da24000-352dc23000 ---p 00024000 08:06 659699                         /usr/lib64/libjpeg.so.62.0.0
352dc23000-352dc24000 rw-p 00023000 08:06 659699                         /usr/lib64/libjpeg.so.62.0.0
352e600000-352e604000 r-xp 00000000 08:06 392061                         /lib64/libattr.so.1.1.0
352e604000-352e803000 ---p 00004000 08:06 392061                         /lib64/libattr.so.1.1.0
352e803000-352e804000 rw-p 00003000 08:06 392061                         /lib64/libattr.so.1.1.0
352ea00000-352ea04000 r-xp 00000000 08:06 398338                         /lib64/libplc4.so
352ea04000-352ec03000 ---p 00004000 08:06 398338                         /lib64/libplc4.so
352ec03000-352ec04000 rw-p 00003000 08:06 398338                         /lib64/libplc4.so
352ee00000-352ee1d000 r-xp 00000000 08:06 398342                         /lib64/libtinfo.so.5.7
352ee1d000-352f01d000 ---p 0001d000 08:06 398342                         /lib64/libtinfo.so.5.7
352f01d000-352f021000 rw-p 0001d000 08:06 398342                         /lib64/libtinfo.so.5.7
352f200000-352f222000 r-xp 00000000 08:06 398343                         /lib64/libncurses.so.5.7
352f222000-352f421000 ---p 00022000 08:06 398343                         /lib64/libncurses.so.5.7
352f421000-352f422000 rw-p 00021000 08:06 398343                         /lib64/libncurses.so.5.7
352f600000-352f733000 r-xp 00000000 08:06 691248                         /usr/lib64/libnss3.so
352f733000-352f932000 ---p 00133000 08:06 691248                         /usr/lib64/libnss3.so
352f932000-352f939000 rw-p 00132000 08:06 691248                         /usr/lib64/libnss3.so
352f939000-352f93a000 rw-p 00000000 00:00 0 
352fa00000-352fa38000 r-xp 00000000 08:06 398337                         /lib64/libnspr4.so
352fa38000-352fc38000 ---p 00038000 08:06 398337                         /lib64/libnspr4.so
352fc38000-352fc3a000 rw-p 00038000 08:06 398337                         /lib64/libnspr4.so
352fc3a000-352fc3d000 rw-p 00000000 00:00 0 
3530200000-3530203000 r-xp 00000000 08:06 398339                         /lib64/libplds4.so
3530203000-3530402000 ---p 00003000 08:06 398339                         /lib64/libplds4.so
3530402000-3530403000 rw-p 00002000 08:06 398339                         /lib64/libplds4.so
3530600000-3530632000 r-xp 00000000 08:06 691249                         /usr/lib64/libssl3.so
3530632000-3530831000 ---p 00032000 08:06 691249                         /usr/lib64/libssl3.so
3530831000-3530834000 rw-p 00031000 08:06 691249                         /usr/lib64/libssl3.so
3530a00000-3530a28000 r-xp 00000000 08:06 691250                         /usr/lib64/libsmime3.so
3530a28000-3530c27000 ---p 00028000 08:06 691250                         /usr/lib64/libsmime3.so
3530c27000-3530c2b000 rw-p 00027000 08:06 691250                         /usr/lib64/libsmime3.so
3530e00000-3530e0d000 r-xp 00000000 08:06 678871                         /usr/lib64/liblber-2.4.so.2.5.2
3530e0d000-353100d000 ---p 0000d000 08:06 678871                         /usr/lib64/liblber-2.4.so.2.5.2
353100d000-353100e000 rw-p 0000d000 08:06 678871                         /usr/lib64/liblber-2.4.so.2.5.2
3531200000-353121a000 r-xp 00000000 08:06 691247                         /usr/lib64/libnssutil3.so
353121a000-3531419000 ---p 0001a000 08:06 691247                         /usr/lib64/libnssutil3.so
3531419000-353141f000 rw-p 00019000 08:06 691247                         /usr/lib64/libnssutil3.so
3532600000-3532610000 r-xp 00000000 08:06 659689                         /usr/lib64/libtasn1.so.3.1.6
3532610000-3532810000 ---p 00010000 08:06 659689                         /usr/lib64/libtasn1.so.3.1.6
3532810000-3532811000 rw-p 00010000 08:06 659689                         /usr/lib64/libtasn1.so.3.1.6
35fd000000-35fd002000 r-xp 00000000 08:06 391735                         /lib64/libutil-2.12.so
35fd002000-35fd201000 ---p 00002000 08:06 391735                         /lib64/libutil-2.12.so
35fd201000-35fd202000 r--p 00001000 08:06 391735                         /lib64/libutil-2.12.so
35fd202000-35fd203000 rw-p 00002000 08:06 391735                         /lib64/libutil-2.12.so
38c3600000-38c366d000 r-xp 00000000 08:06 686286                         /usr/lib64/libSDL-1.2.so.0.11.3
38c366d000-38c386c000 ---p 0006d000 08:06 686286                         /usr/lib64/libSDL-1.2.so.0.11.3
38c386c000-38c386e000 rw-p 0006c000 08:06 686286                         /usr/lib64/libSDL-1.2.so.0.11.3
38c386e000-38c389e000 rw-p 00000000 00:00 0 
3ccea00000-3ccea43000 r-xp 00000000 08:06 674604                         /usr/lib64/libldap-2.4.so.2.5.2
3ccea43000-3ccec42000 ---p 00043000 08:06 674604                         /usr/lib64/libldap-2.4.so.2.5.2
3ccec42000-3ccec44000 rw-p 00042000 08:06 674604                         /usr/lib64/libldap-2.4.so.2.5.2
3ccee00000-3ccee26000 r-xp 00000000 08:06 684897                         /usr/lib64/libssh2.so.1.0.1
3ccee26000-3ccf026000 ---p 00026000 08:06 684897                         /usr/lib64/libssh2.so.1.0.1
3ccf026000-3ccf027000 rw-p 00026000 08:06 684897                         /usr/lib64/libssh2.so.1.0.1
3ccf200000-3ccf251000 r-xp 00000000 08:06 691226                         /usr/lib64/libcurl.so.4.1.1
3ccf251000-3ccf450000 ---p 00051000 08:06 691226                         /usr/lib64/libcurl.so.4.1.1
3ccf450000-3ccf453000 rw-p 00050000 08:06 691226                         /usr/lib64/libcurl.so.4.1.1
3f26600000-3f26619000 r-xp 00000000 08:06 662133                         /usr/lib64/libsasl2.so.2.0.23
3f26619000-3f26819000 ---p 00019000 08:06 662133                         /usr/lib64/libsasl2.so.2.0.23
3f26819000-3f2681a000 rw-p 00019000 08:06 662133                         /usr/lib64/libsasl2.so.2.0.23
3f26e00000-3f26f7c000 r-xp 00000000 08:06 395334                         /lib64/libdb-4.8.so
3f26f7c000-3f2717c000 ---p 0017c000 08:06 395334                         /lib64/libdb-4.8.so
3f2717c000-3f27181000 rw-p 0017c000 08:06 395334                         /lib64/libdb-4.8.so
3f29e00000-3f29e03000 r-xp 00000000 08:06 395336                         /lib64/libgpg-error.so.0.5.0
3f29e03000-3f2a002000 ---p 00003000 08:06 395336                         /lib64/libgpg-error.so.0.5.0
3f2a002000-3f2a003000 rw-p 00002000 08:06 395336                         /lib64/libgpg-error.so.0.5.0
3f2a800000-3f2a89b000 r-xp 00000000 08:06 672202                         /usr/lib64/libgnutls.so.26.14.12
3f2a89b000-3f2aa9a000 ---p 0009b000 08:06 672202                         /usr/lib64/libgnutls.so.26.14.12
3f2aa9a000-3f2aaa1000 rw-p 0009a000 08:06 672202                         /usr/lib64/libgnutls.so.26.14.12
3f2ac00000-3f2ac72000 r-xp 00000000 08:06 395337                         /lib64/libgcrypt.so.11.5.3
3f2ac72000-3f2ae71000 ---p 00072000 08:06 395337                         /lib64/libgcrypt.so.11.5.3
3f2ae71000-3f2ae75000 rw-p 00071000 08:06 395337                         /lib64/libgcrypt.so.11.5.3
7fb17c000000-7fb17c021000 rw-p 00000000 00:00 0 
7fb17c021000-7fb180000000 ---p 00000000 00:00 0 
7fb181610000-7fb18161c000 r-xp 00000000 08:06 661352                     /usr/lib64/sasl2/libdigestmd5.so.2.0.23
7fb18161c000-7fb18181b000 ---p 0000c000 08:06 661352                     /usr/lib64/sasl2/libdigestmd5.so.2.0.23
7fb18181b000-7fb18181c000 rw-p 0000b000 08:06 661352                     /usr/lib64/sasl2/libdigestmd5.so.2.0.23
7fb18181c000-7fb181820000 r-xp 00000000 08:06 661349                     /usr/lib64/sasl2/libcrammd5.so.2.0.23
7fb181820000-7fb181a20000 ---p 00004000 08:06 661349                     /usr/lib64/sasl2/libcrammd5.so.2.0.23
7fb181a20000-7fb181a21000 rw-p 00004000 08:06 661349                     /usr/lib64/sasl2/libcrammd5.so.2.0.23
7fb181a21000-7fb181a25000 r-xp 00000000 08:06 657587                     /usr/lib64/sasl2/libanonymous.so.2.0.23
7fb181a25000-7fb181c24000 ---p 00004000 08:06 657587                     /usr/lib64/sasl2/libanonymous.so.2.0.23
7fb181c24000-7fb181c25000 rw-p 00003000 08:06 657587                     /usr/lib64/sasl2/libanonymous.so.2.0.23
7fb181c25000-7fb181c29000 r-xp 00000000 08:06 686571                     /usr/lib64/sasl2/liblogin.so.2.0.23
7fb181c29000-7fb181e28000 ---p 00004000 08:06 686571                     /usr/lib64/sasl2/liblogin.so.2.0.23
7fb181e28000-7fb181e29000 rw-p 00003000 08:06 686571                     /usr/lib64/sasl2/liblogin.so.2.0.23
7fb181e29000-7fb181e2d000 r-xp 00000000 08:06 686574                     /usr/lib64/sasl2/libplain.so.2.0.23
7fb181e2d000-7fb18202c000 ---p 00004000 08:06 686574                     /usr/lib64/sasl2/libplain.so.2.0.23
7fb18202c000-7fb18202d000 rw-p 00003000 08:06 686574                     /usr/lib64/sasl2/libplain.so.2.0.23
7fb18202d000-7fb182034000 r-xp 00000000 08:06 659871                     /usr/lib64/sasl2/libgssapiv2.so.2.0.23
7fb182034000-7fb182233000 ---p 00007000 08:06 659871                     /usr/lib64/sasl2/libgssapiv2.so.2.0.23
7fb182233000-7fb182234000 rw-p 00006000 08:06 659871                     /usr/lib64/sasl2/libgssapiv2.so.2.0.23
7fb182234000-7fb182239000 r-xp 00000000 08:06 657590                     /usr/lib64/sasl2/libsasldb.so.2.0.23
7fb182239000-7fb182438000 ---p 00005000 08:06 657590                     /usr/lib64/sasl2/libsasldb.so.2.0.23
7fb182438000-7fb182439000 rw-p 00004000 08:06 657590                     /usr/lib64/sasl2/libsasldb.so.2.0.23
7fb182439000-7fb18243a000 ---p 00000000 00:00 0 
7fb18243a000-7fb182fd8000 rw-p 00000000 00:00 0 
7fb182feb000-7fb182fec000 rw-p 00000000 00:00 0 
7fb182fec000-7fb1837ec000 rw-p 00000000 00:00 0 
7fb1837ec000-7fb1837ee000 rw-p 00000000 00:00 0 
7fb1837ee000-7fb18380e000 rw-p 00000000 00:00 0 
7fb18380e000-7fb183810000 rw-p 00000000 00:00 0 
7fb183810000-7fb183830000 rw-p 00000000 00:00 0 
7fb183830000-7fb183853000 rw-p 00000000 00:00 0 
7fb183853000-7fb1a3853000 rw-p 00000000 00:00 0 
7fb1a3853000-7fb1a3854000 rw-p 00000000 00:00 0 
7fb1a3854000-7fb1a3857000 rw-s 00000000 00:09 3567                       anon_inode:kvm-vcpu
7fb1a3857000-7fb1ab27b000 rw-p 00000000 00:00 0 
7fb1ab27b000-7fb1ab287000 r-xp 00000000 08:06 391711                     /lib64/libnss_files-2.12.so
7fb1ab287000-7fb1ab486000 ---p 0000c000 08:06 391711                     /lib64/libnss_files-2.12.so
7fb1ab486000-7fb1ab487000 r--p 0000b000 08:06 391711                     /lib64/libnss_files-2.12.so
7fb1ab487000-7fb1ab488000 rw-p 0000c000 08:06 391711                     /lib64/libnss_files-2.12.so
7fb1ab488000-7fb1ab49e000 rw-p 00000000 00:00 0 
7fb1ab4b2000-7fb1ab4b5000 rw-s 00000000 00:04 304955                     /dev/zero (deleted)
7fb1ab4b5000-7fb1ab4b6000 rw-p 00000000 00:00 0 
7fff99e5f000-7fff99e74000 rw-p 00000000 00:00 0                          [stack]
7fff99f5f000-7fff99f60000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

>      return qdev_unplug(dev);
>  }
>  
> 
>
Minoru Usui - Feb. 15, 2011, 2:32 a.m.
Hi,

On Mon, 14 Feb 2011 14:19:56 +0800
Wen Congyang <wency@cn.fujitsu.com> wrote:

> At 01/27/2011 05:00 PM, Ken'ichi Ohmichi Write:
> > 
> > Hi,
> > 
> > When I tried to attach the interface after detaching the same interface,
> > the virsh command output the following and it failed:
> > 
> >   # virsh detach-interface Domain01 network --mac 52:54:00:0d:78:92
> >   Interface detached successfully
> > 
> >   # virsh attach-interface Domain01 network default --mac 52:54:00:0d:78:92
> >   error: Failed to attach interface
> >   error: internal error unable to execute QEMU command 'device_add': Duplicate ID 'net0' for device
> >   #
> 
> I can reproduce this problem.
> 
> > 
> > The reason is that a detached device is not removed from the list
> > "qemu_device_opts", and this patch fixes it.
> 
> The detached device will be removed from the list "qemu_device_opts"
> in qdev_free() asynchronously.

I can reproduce, too.
But strangely, it don't occur in case of loading acpiphp driver 
to the guest VM on below environment.

  Host : RHEL6.0
  Guest: RHEL5.5 

Unfortunately, I'm not familiar with qemu-kvm.
I investigated below questions about this problem, but I couldn't resolve them.

  - How to call qdev_free() asynchronously. (How should we fix this problem)
  - Why it don't occur with acpiphp driver

If anyone knows answer of above questions or its clue, please let me know.

> 
> > 
> > 
> > Thanks
> > Ken'ichi Ohmichi
> > 
> > 
> > Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
> > ---
> > --- a/hw/qdev.c	2011-01-27 17:42:25.000000000 +0900
> > +++ b/hw/qdev.c	2011-01-27 17:43:46.000000000 +0900
> > @@ -905,6 +905,8 @@ int do_device_del(Monitor *mon, const QD
> >          qerror_report(QERR_DEVICE_NOT_FOUND, id);
> >          return -1;
> >      }
> > +    qemu_opts_del(qemu_opts_find(&qemu_device_opts, id));
> > +
> 
> We can not use qemu_device_opts here, because qemu_device_opts is
> a static variable in qemu-config.c. We should use qemu_find_opts("device")
> instead of qemu_device_opts.
> 
> I test your patch by attach/detach interface, and qemu core dumps.
> The reason may be that we call qemu_opts_del() twice.

If qdev_free() is called asynchronously, I think qemu_opts_del() is called twice, too.
And this patch isn't legal.

I want to fix this problem, but I haven't understand about qemu-kvm, yet. X-(

> 
> Here is the log(/var/log/libvirt/qemu/<domain>.log):
> 
> *** glibc detected *** /usr/libexec/qemu-system-x86_64: free(): invalid pointer: 0x000000000355f000 ***
> ======= Backtrace: =========
> /lib64/libc.so.6[0x351f275676]
> /usr/libexec/qemu-system-x86_64[0x43e2a6]
> /usr/libexec/qemu-system-x86_64[0x43f9a0]
> /usr/libexec/qemu-system-x86_64[0x4400ee]
> /usr/libexec/qemu-system-x86_64[0x4cb176]
> /usr/libexec/qemu-system-x86_64[0x5af9f6]
> /usr/libexec/qemu-system-x86_64[0x4953c1]
> /usr/libexec/qemu-system-x86_64[0x495dab]
> /usr/libexec/qemu-system-x86_64[0x43a087]
> /usr/libexec/qemu-system-x86_64[0x43a5dd]
> /usr/libexec/qemu-system-x86_64[0x51f8f5]
> /usr/libexec/qemu-system-x86_64[0x40ad4b]
> /usr/libexec/qemu-system-x86_64[0x40ae52]
> /usr/libexec/qemu-system-x86_64[0x585c81]
> /usr/libexec/qemu-system-x86_64[0x589da7]
> /lib64/libc.so.6(__libc_start_main+0xfd)[0x351f21ec5d]
> /usr/libexec/qemu-system-x86_64[0x408a19]
> ======= Memory map: ========
> 00400000-00784000 r-xp 00000000 08:06 679152                             /usr/libexec/qemu-system-x86_64
> 00983000-009c9000 rw-p 00383000 08:06 679152                             /usr/libexec/qemu-system-x86_64
> 009c9000-01177000 rw-p 00000000 00:00 0 
> 01177000-01178000 rwxp 00000000 00:00 0 
> 01178000-011d5000 rw-p 00000000 00:00 0 
> 02d32000-03109000 rw-p 00000000 00:00 0 
> 03109000-03119000 rw-p 00000000 00:00 0 
> 03119000-03134000 rw-p 00000000 00:00 0 
> 03134000-03144000 rw-p 00000000 00:00 0 
> 03144000-0352c000 rw-p 00000000 00:00 0 
> 0352c000-0353c000 rw-p 00000000 00:00 0 
> 0353c000-0354f000 rw-p 00000000 00:00 0 
> 0354f000-0355f000 rw-p 00000000 00:00 0 
> 0355f000-03580000 rw-p 00000000 00:00 0 
> 4154f000-4954f000 rwxp 00000000 00:00 0 
> 328d000000-328d038000 r-xp 00000000 08:06 394303                         /lib64/libgssapi_krb5.so.2.2
> 328d038000-328d237000 ---p 00038000 08:06 394303                         /lib64/libgssapi_krb5.so.2.2
> 328d237000-328d239000 rw-p 00037000 08:06 394303                         /lib64/libgssapi_krb5.so.2.2
> 328d400000-328d453000 r-xp 00000000 08:06 685072                         /usr/lib64/libssl.so.1.0.0
> 328d453000-328d653000 ---p 00053000 08:06 685072                         /usr/lib64/libssl.so.1.0.0
> 328d653000-328d65b000 rw-p 00053000 08:06 685072                         /usr/lib64/libssl.so.1.0.0
> 328d800000-328d827000 r-xp 00000000 08:06 394300                         /lib64/libk5crypto.so.3.1
> 328d827000-328da27000 ---p 00027000 08:06 394300                         /lib64/libk5crypto.so.3.1
> 328da27000-328da29000 rw-p 00027000 08:06 394300                         /lib64/libk5crypto.so.3.1
> 328ec00000-328eccf000 r-xp 00000000 08:06 394302                         /lib64/libkrb5.so.3.3
> 328eccf000-328eecf000 ---p 000cf000 08:06 394302                         /lib64/libkrb5.so.3.3
> 328eecf000-328eeda000 rw-p 000cf000 08:06 394302                         /lib64/libkrb5.so.3.3
> 328f000000-328f003000 r-xp 00000000 08:06 394301                         /lib64/libcom_err.so.2.1
> 328f003000-328f202000 ---p 00003000 08:06 394301                         /lib64/libcom_err.so.2.1
> 328f202000-328f203000 rw-p 00002000 08:06 394301                         /lib64/libcom_err.so.2.1
> 328f400000-328f40a000 r-xp 00000000 08:06 393785                         /lib64/libkrb5support.so.0.1
> 328f40a000-328f609000 ---p 0000a000 08:06 393785                         /lib64/libkrb5support.so.0.1
> 328f609000-328f60a000 rw-p 00009000 08:06 393785                         /lib64/libkrb5support.so.0.1
> 351ea00000-351ea1e000 r-xp 00000000 08:06 398307                         /lib64/ld-2.12.so
> 351ec1e000-351ec1f000 r--p 0001e000 08:06 398307                         /lib64/ld-2.12.so
> 351ec1f000-351ec20000 rw-p 0001f000 08:06 398307                         /lib64/ld-2.12.so
> 351ec20000-351ec21000 rw-p 00000000 00:00 0 
> 351ee00000-351ee01000 r-xp 00000000 08:06 391907                         /lib64/libaio.so.1.0.1
> 351ee01000-351f000000 ---p 00001000 08:06 391907                         /lib64/libaio.so.1.0.1
> 351f000000-351f001000 rw-p 00000000 08:06 391907                         /lib64/libaio.so.1.0.1
> 351f200000-351f375000 r-xp 00000000 08:06 398308                         /lib64/libc-2.12.so
> 351f375000-351f575000 ---p 00175000 08:06 398308                         /lib64/libc-2.12.so
> 351f575000-351f579000 r--p 00175000 08:06 398308                         /lib64/libc-2.12.so
> 351f579000-351f57a000 rw-p 00179000 08:06 398308                         /lib64/libc-2.12.so
> 351f57a000-351f57f000 rw-p 00000000 00:00 0 
> 351f600000-351f683000 r-xp 00000000 08:06 398327                         /lib64/libm-2.12.so
> 351f683000-351f882000 ---p 00083000 08:06 398327                         /lib64/libm-2.12.so
> 351f882000-351f883000 r--p 00082000 08:06 398327                         /lib64/libm-2.12.so
> 351f883000-351f884000 rw-p 00083000 08:06 398327                         /lib64/libm-2.12.so
> 351fa00000-351fa02000 r-xp 00000000 08:06 398310                         /lib64/libdl-2.12.so
> 351fa02000-351fc02000 ---p 00002000 08:06 398310                         /lib64/libdl-2.12.so
> 351fc02000-351fc03000 r--p 00002000 08:06 398310                         /lib64/libdl-2.12.so
> 351fc03000-351fc04000 rw-p 00003000 08:06 398310                         /lib64/libdl-2.12.so
> 351fe00000-351fe17000 r-xp 00000000 08:06 398316                         /lib64/libpthread-2.12.so
> 351fe17000-3520017000 ---p 00017000 08:06 398316                         /lib64/libpthread-2.12.so
> 3520017000-3520018000 r--p 00017000 08:06 398316                         /lib64/libpthread-2.12.so
> 3520018000-3520019000 rw-p 00018000 08:06 398316                         /lib64/libpthread-2.12.so
> 3520019000-352001d000 rw-p 00000000 00:00 0 
> 3520200000-3520215000 r-xp 00000000 08:06 398326                         /lib64/libz.so.1.2.3
> 3520215000-3520414000 ---p 00015000 08:06 398326                         /lib64/libz.so.1.2.3
> 3520414000-3520415000 rw-p 00014000 08:06 398326                         /lib64/libz.so.1.2.3
> 3520600000-3520607000 r-xp 00000000 08:06 398319                         /lib64/librt-2.12.so
> 3520607000-3520806000 ---p 00007000 08:06 398319                         /lib64/librt-2.12.so
> 3520806000-3520807000 r--p 00006000 08:06 398319                         /lib64/librt-2.12.so
> 3520807000-3520808000 rw-p 00007000 08:06 398319                         /lib64/librt-2.12.so
> 3520a00000-3520a1d000 r-xp 00000000 08:06 398313                         /lib64/libselinux.so.1
> 3520a1d000-3520c1c000 ---p 0001d000 08:06 398313                         /lib64/libselinux.so.1
> 3520c1c000-3520c1d000 r--p 0001c000 08:06 398313                         /lib64/libselinux.so.1
> 3520c1d000-3520c1e000 rw-p 0001d000 08:06 398313                         /lib64/libselinux.so.1
> 3520c1e000-3520c1f000 rw-p 00000000 00:00 0 
> 3520e00000-3520e16000 r-xp 00000000 08:06 398312                         /lib64/libresolv-2.12.so
> 3520e16000-3521016000 ---p 00016000 08:06 398312                         /lib64/libresolv-2.12.so
> 3521016000-3521017000 r--p 00016000 08:06 398312                         /lib64/libresolv-2.12.so
> 3521017000-3521018000 rw-p 00017000 08:06 398312                         /lib64/libresolv-2.12.so
> 3521018000-352101a000 rw-p 00000000 00:00 0 
> 3521e00000-3521e1b000 r-xp 00000000 08:06 691194                         /usr/lib64/libxcb.so.1.1.0
> 3521e1b000-352201a000 ---p 0001b000 08:06 691194                         /usr/lib64/libxcb.so.1.1.0
> 352201a000-352201b000 rw-p 0001a000 08:06 691194                         /usr/lib64/libxcb.so.1.1.0
> 3522600000-3522602000 r-xp 00000000 08:06 691193                         /usr/lib64/libXau.so.6.0.0
> 3522602000-3522802000 ---p 00002000 08:06 691193                         /usr/lib64/libXau.so.6.0.0
> 3522802000-3522803000 rw-p 00002000 08:06 691193                         /usr/lib64/libXau.so.6.0.0
> 3522a00000-3522b39000 r-xp 00000000 08:06 691195                         /usr/lib64/libX11.so.6.3.0
> 3522b39000-3522d39000 ---p 00139000 08:06 691195                         /usr/lib64/libX11.so.6.3.0
> 3522d39000-3522d3f000 rw-p 00139000 08:06 691195                         /usr/lib64/libX11.so.6.3.0
> 3522e00000-3522e26000 r-xp 00000000 08:06 691192                         /usr/lib64/libpng12.so.0.44.0
> 3522e26000-3523025000 ---p 00026000 08:06 691192                         /usr/lib64/libpng12.so.0.44.0
> 3523025000-3523026000 rw-p 00025000 08:06 691192                         /usr/lib64/libpng12.so.0.44.0
> 3529a00000-3529a32000 r-xp 00000000 08:06 398336                         /lib64/libidn.so.11.6.1
> 3529a32000-3529c31000 ---p 00032000 08:06 398336                         /lib64/libidn.so.11.6.1
> 3529c31000-3529c32000 rw-p 00031000 08:06 398336                         /lib64/libidn.so.11.6.1
> 352a200000-352a216000 r-xp 00000000 08:06 398354                         /lib64/libgcc_s-4.4.4-20100726.so.1
> 352a216000-352a415000 ---p 00016000 08:06 398354                         /lib64/libgcc_s-4.4.4-20100726.so.1
> 352a415000-352a416000 rw-p 00015000 08:06 398354                         /lib64/libgcc_s-4.4.4-20100726.so.1
> 352a600000-352a771000 r-xp 00000000 08:06 691225                         /usr/lib64/libcrypto.so.1.0.0
> 352a771000-352a970000 ---p 00171000 08:06 691225                         /usr/lib64/libcrypto.so.1.0.0
> 352a970000-352a993000 rw-p 00170000 08:06 691225                         /usr/lib64/libcrypto.so.1.0.0
> 352a993000-352a996000 rw-p 00000000 00:00 0 
> 352ae00000-352ae02000 r-xp 00000000 08:06 398311                         /lib64/libkeyutils.so.1.3
> 352ae02000-352b001000 ---p 00002000 08:06 398311                         /lib64/libkeyutils.so.1.3
> 352b001000-352b002000 rw-p 00001000 08:06 398311                         /lib64/libkeyutils.so.1.3
> 352ba00000-352ba04000 r-xp 00000000 08:06 398334                         /lib64/libuuid.so.1.3.0
> 352ba04000-352bc03000 ---p 00004000 08:06 398334                         /lib64/libuuid.so.1.3.0
> 352bc03000-352bc04000 rw-p 00003000 08:06 398334                         /lib64/libuuid.so.1.3.0
> 352c600000-352c607000 r-xp 00000000 08:06 398331                         /lib64/libcrypt-2.12.so
> 352c607000-352c807000 ---p 00007000 08:06 398331                         /lib64/libcrypt-2.12.so
> 352c807000-352c808000 r--p 00007000 08:06 398331                         /lib64/libcrypt-2.12.so
> 352c808000-352c809000 rw-p 00008000 08:06 398331                         /lib64/libcrypt-2.12.so
> 352c809000-352c837000 rw-p 00000000 00:00 0 
> 352ca00000-352ca58000 r-xp 00000000 08:06 398330                         /lib64/libfreebl3.so
> 352ca58000-352cc57000 ---p 00058000 08:06 398330                         /lib64/libfreebl3.so
> 352cc57000-352cc59000 rw-p 00057000 08:06 398330                         /lib64/libfreebl3.so
> 352cc59000-352cc5d000 rw-p 00000000 00:00 0 
> 352da00000-352da24000 r-xp 00000000 08:06 659699                         /usr/lib64/libjpeg.so.62.0.0
> 352da24000-352dc23000 ---p 00024000 08:06 659699                         /usr/lib64/libjpeg.so.62.0.0
> 352dc23000-352dc24000 rw-p 00023000 08:06 659699                         /usr/lib64/libjpeg.so.62.0.0
> 352e600000-352e604000 r-xp 00000000 08:06 392061                         /lib64/libattr.so.1.1.0
> 352e604000-352e803000 ---p 00004000 08:06 392061                         /lib64/libattr.so.1.1.0
> 352e803000-352e804000 rw-p 00003000 08:06 392061                         /lib64/libattr.so.1.1.0
> 352ea00000-352ea04000 r-xp 00000000 08:06 398338                         /lib64/libplc4.so
> 352ea04000-352ec03000 ---p 00004000 08:06 398338                         /lib64/libplc4.so
> 352ec03000-352ec04000 rw-p 00003000 08:06 398338                         /lib64/libplc4.so
> 352ee00000-352ee1d000 r-xp 00000000 08:06 398342                         /lib64/libtinfo.so.5.7
> 352ee1d000-352f01d000 ---p 0001d000 08:06 398342                         /lib64/libtinfo.so.5.7
> 352f01d000-352f021000 rw-p 0001d000 08:06 398342                         /lib64/libtinfo.so.5.7
> 352f200000-352f222000 r-xp 00000000 08:06 398343                         /lib64/libncurses.so.5.7
> 352f222000-352f421000 ---p 00022000 08:06 398343                         /lib64/libncurses.so.5.7
> 352f421000-352f422000 rw-p 00021000 08:06 398343                         /lib64/libncurses.so.5.7
> 352f600000-352f733000 r-xp 00000000 08:06 691248                         /usr/lib64/libnss3.so
> 352f733000-352f932000 ---p 00133000 08:06 691248                         /usr/lib64/libnss3.so
> 352f932000-352f939000 rw-p 00132000 08:06 691248                         /usr/lib64/libnss3.so
> 352f939000-352f93a000 rw-p 00000000 00:00 0 
> 352fa00000-352fa38000 r-xp 00000000 08:06 398337                         /lib64/libnspr4.so
> 352fa38000-352fc38000 ---p 00038000 08:06 398337                         /lib64/libnspr4.so
> 352fc38000-352fc3a000 rw-p 00038000 08:06 398337                         /lib64/libnspr4.so
> 352fc3a000-352fc3d000 rw-p 00000000 00:00 0 
> 3530200000-3530203000 r-xp 00000000 08:06 398339                         /lib64/libplds4.so
> 3530203000-3530402000 ---p 00003000 08:06 398339                         /lib64/libplds4.so
> 3530402000-3530403000 rw-p 00002000 08:06 398339                         /lib64/libplds4.so
> 3530600000-3530632000 r-xp 00000000 08:06 691249                         /usr/lib64/libssl3.so
> 3530632000-3530831000 ---p 00032000 08:06 691249                         /usr/lib64/libssl3.so
> 3530831000-3530834000 rw-p 00031000 08:06 691249                         /usr/lib64/libssl3.so
> 3530a00000-3530a28000 r-xp 00000000 08:06 691250                         /usr/lib64/libsmime3.so
> 3530a28000-3530c27000 ---p 00028000 08:06 691250                         /usr/lib64/libsmime3.so
> 3530c27000-3530c2b000 rw-p 00027000 08:06 691250                         /usr/lib64/libsmime3.so
> 3530e00000-3530e0d000 r-xp 00000000 08:06 678871                         /usr/lib64/liblber-2.4.so.2.5.2
> 3530e0d000-353100d000 ---p 0000d000 08:06 678871                         /usr/lib64/liblber-2.4.so.2.5.2
> 353100d000-353100e000 rw-p 0000d000 08:06 678871                         /usr/lib64/liblber-2.4.so.2.5.2
> 3531200000-353121a000 r-xp 00000000 08:06 691247                         /usr/lib64/libnssutil3.so
> 353121a000-3531419000 ---p 0001a000 08:06 691247                         /usr/lib64/libnssutil3.so
> 3531419000-353141f000 rw-p 00019000 08:06 691247                         /usr/lib64/libnssutil3.so
> 3532600000-3532610000 r-xp 00000000 08:06 659689                         /usr/lib64/libtasn1.so.3.1.6
> 3532610000-3532810000 ---p 00010000 08:06 659689                         /usr/lib64/libtasn1.so.3.1.6
> 3532810000-3532811000 rw-p 00010000 08:06 659689                         /usr/lib64/libtasn1.so.3.1.6
> 35fd000000-35fd002000 r-xp 00000000 08:06 391735                         /lib64/libutil-2.12.so
> 35fd002000-35fd201000 ---p 00002000 08:06 391735                         /lib64/libutil-2.12.so
> 35fd201000-35fd202000 r--p 00001000 08:06 391735                         /lib64/libutil-2.12.so
> 35fd202000-35fd203000 rw-p 00002000 08:06 391735                         /lib64/libutil-2.12.so
> 38c3600000-38c366d000 r-xp 00000000 08:06 686286                         /usr/lib64/libSDL-1.2.so.0.11.3
> 38c366d000-38c386c000 ---p 0006d000 08:06 686286                         /usr/lib64/libSDL-1.2.so.0.11.3
> 38c386c000-38c386e000 rw-p 0006c000 08:06 686286                         /usr/lib64/libSDL-1.2.so.0.11.3
> 38c386e000-38c389e000 rw-p 00000000 00:00 0 
> 3ccea00000-3ccea43000 r-xp 00000000 08:06 674604                         /usr/lib64/libldap-2.4.so.2.5.2
> 3ccea43000-3ccec42000 ---p 00043000 08:06 674604                         /usr/lib64/libldap-2.4.so.2.5.2
> 3ccec42000-3ccec44000 rw-p 00042000 08:06 674604                         /usr/lib64/libldap-2.4.so.2.5.2
> 3ccee00000-3ccee26000 r-xp 00000000 08:06 684897                         /usr/lib64/libssh2.so.1.0.1
> 3ccee26000-3ccf026000 ---p 00026000 08:06 684897                         /usr/lib64/libssh2.so.1.0.1
> 3ccf026000-3ccf027000 rw-p 00026000 08:06 684897                         /usr/lib64/libssh2.so.1.0.1
> 3ccf200000-3ccf251000 r-xp 00000000 08:06 691226                         /usr/lib64/libcurl.so.4.1.1
> 3ccf251000-3ccf450000 ---p 00051000 08:06 691226                         /usr/lib64/libcurl.so.4.1.1
> 3ccf450000-3ccf453000 rw-p 00050000 08:06 691226                         /usr/lib64/libcurl.so.4.1.1
> 3f26600000-3f26619000 r-xp 00000000 08:06 662133                         /usr/lib64/libsasl2.so.2.0.23
> 3f26619000-3f26819000 ---p 00019000 08:06 662133                         /usr/lib64/libsasl2.so.2.0.23
> 3f26819000-3f2681a000 rw-p 00019000 08:06 662133                         /usr/lib64/libsasl2.so.2.0.23
> 3f26e00000-3f26f7c000 r-xp 00000000 08:06 395334                         /lib64/libdb-4.8.so
> 3f26f7c000-3f2717c000 ---p 0017c000 08:06 395334                         /lib64/libdb-4.8.so
> 3f2717c000-3f27181000 rw-p 0017c000 08:06 395334                         /lib64/libdb-4.8.so
> 3f29e00000-3f29e03000 r-xp 00000000 08:06 395336                         /lib64/libgpg-error.so.0.5.0
> 3f29e03000-3f2a002000 ---p 00003000 08:06 395336                         /lib64/libgpg-error.so.0.5.0
> 3f2a002000-3f2a003000 rw-p 00002000 08:06 395336                         /lib64/libgpg-error.so.0.5.0
> 3f2a800000-3f2a89b000 r-xp 00000000 08:06 672202                         /usr/lib64/libgnutls.so.26.14.12
> 3f2a89b000-3f2aa9a000 ---p 0009b000 08:06 672202                         /usr/lib64/libgnutls.so.26.14.12
> 3f2aa9a000-3f2aaa1000 rw-p 0009a000 08:06 672202                         /usr/lib64/libgnutls.so.26.14.12
> 3f2ac00000-3f2ac72000 r-xp 00000000 08:06 395337                         /lib64/libgcrypt.so.11.5.3
> 3f2ac72000-3f2ae71000 ---p 00072000 08:06 395337                         /lib64/libgcrypt.so.11.5.3
> 3f2ae71000-3f2ae75000 rw-p 00071000 08:06 395337                         /lib64/libgcrypt.so.11.5.3
> 7fb17c000000-7fb17c021000 rw-p 00000000 00:00 0 
> 7fb17c021000-7fb180000000 ---p 00000000 00:00 0 
> 7fb181610000-7fb18161c000 r-xp 00000000 08:06 661352                     /usr/lib64/sasl2/libdigestmd5.so.2.0.23
> 7fb18161c000-7fb18181b000 ---p 0000c000 08:06 661352                     /usr/lib64/sasl2/libdigestmd5.so.2.0.23
> 7fb18181b000-7fb18181c000 rw-p 0000b000 08:06 661352                     /usr/lib64/sasl2/libdigestmd5.so.2.0.23
> 7fb18181c000-7fb181820000 r-xp 00000000 08:06 661349                     /usr/lib64/sasl2/libcrammd5.so.2.0.23
> 7fb181820000-7fb181a20000 ---p 00004000 08:06 661349                     /usr/lib64/sasl2/libcrammd5.so.2.0.23
> 7fb181a20000-7fb181a21000 rw-p 00004000 08:06 661349                     /usr/lib64/sasl2/libcrammd5.so.2.0.23
> 7fb181a21000-7fb181a25000 r-xp 00000000 08:06 657587                     /usr/lib64/sasl2/libanonymous.so.2.0.23
> 7fb181a25000-7fb181c24000 ---p 00004000 08:06 657587                     /usr/lib64/sasl2/libanonymous.so.2.0.23
> 7fb181c24000-7fb181c25000 rw-p 00003000 08:06 657587                     /usr/lib64/sasl2/libanonymous.so.2.0.23
> 7fb181c25000-7fb181c29000 r-xp 00000000 08:06 686571                     /usr/lib64/sasl2/liblogin.so.2.0.23
> 7fb181c29000-7fb181e28000 ---p 00004000 08:06 686571                     /usr/lib64/sasl2/liblogin.so.2.0.23
> 7fb181e28000-7fb181e29000 rw-p 00003000 08:06 686571                     /usr/lib64/sasl2/liblogin.so.2.0.23
> 7fb181e29000-7fb181e2d000 r-xp 00000000 08:06 686574                     /usr/lib64/sasl2/libplain.so.2.0.23
> 7fb181e2d000-7fb18202c000 ---p 00004000 08:06 686574                     /usr/lib64/sasl2/libplain.so.2.0.23
> 7fb18202c000-7fb18202d000 rw-p 00003000 08:06 686574                     /usr/lib64/sasl2/libplain.so.2.0.23
> 7fb18202d000-7fb182034000 r-xp 00000000 08:06 659871                     /usr/lib64/sasl2/libgssapiv2.so.2.0.23
> 7fb182034000-7fb182233000 ---p 00007000 08:06 659871                     /usr/lib64/sasl2/libgssapiv2.so.2.0.23
> 7fb182233000-7fb182234000 rw-p 00006000 08:06 659871                     /usr/lib64/sasl2/libgssapiv2.so.2.0.23
> 7fb182234000-7fb182239000 r-xp 00000000 08:06 657590                     /usr/lib64/sasl2/libsasldb.so.2.0.23
> 7fb182239000-7fb182438000 ---p 00005000 08:06 657590                     /usr/lib64/sasl2/libsasldb.so.2.0.23
> 7fb182438000-7fb182439000 rw-p 00004000 08:06 657590                     /usr/lib64/sasl2/libsasldb.so.2.0.23
> 7fb182439000-7fb18243a000 ---p 00000000 00:00 0 
> 7fb18243a000-7fb182fd8000 rw-p 00000000 00:00 0 
> 7fb182feb000-7fb182fec000 rw-p 00000000 00:00 0 
> 7fb182fec000-7fb1837ec000 rw-p 00000000 00:00 0 
> 7fb1837ec000-7fb1837ee000 rw-p 00000000 00:00 0 
> 7fb1837ee000-7fb18380e000 rw-p 00000000 00:00 0 
> 7fb18380e000-7fb183810000 rw-p 00000000 00:00 0 
> 7fb183810000-7fb183830000 rw-p 00000000 00:00 0 
> 7fb183830000-7fb183853000 rw-p 00000000 00:00 0 
> 7fb183853000-7fb1a3853000 rw-p 00000000 00:00 0 
> 7fb1a3853000-7fb1a3854000 rw-p 00000000 00:00 0 
> 7fb1a3854000-7fb1a3857000 rw-s 00000000 00:09 3567                       anon_inode:kvm-vcpu
> 7fb1a3857000-7fb1ab27b000 rw-p 00000000 00:00 0 
> 7fb1ab27b000-7fb1ab287000 r-xp 00000000 08:06 391711                     /lib64/libnss_files-2.12.so
> 7fb1ab287000-7fb1ab486000 ---p 0000c000 08:06 391711                     /lib64/libnss_files-2.12.so
> 7fb1ab486000-7fb1ab487000 r--p 0000b000 08:06 391711                     /lib64/libnss_files-2.12.so
> 7fb1ab487000-7fb1ab488000 rw-p 0000c000 08:06 391711                     /lib64/libnss_files-2.12.so
> 7fb1ab488000-7fb1ab49e000 rw-p 00000000 00:00 0 
> 7fb1ab4b2000-7fb1ab4b5000 rw-s 00000000 00:04 304955                     /dev/zero (deleted)
> 7fb1ab4b5000-7fb1ab4b6000 rw-p 00000000 00:00 0 
> 7fff99e5f000-7fff99e74000 rw-p 00000000 00:00 0                          [stack]
> 7fff99f5f000-7fff99f60000 r-xp 00000000 00:00 0                          [vdso]
> ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
> 
> >      return qdev_unplug(dev);
> >  }
> >  
> > 
> > 
> 
>
William Dauchy - Feb. 23, 2011, 9:42 a.m.
Hi Minoru,

On Tue, Feb 15, 2011 at 3:32 AM, Minoru Usui <usui@mxm.nes.nec.co.jp> wrote:
> I can reproduce, too.
> But strangely, it don't occur in case of loading acpiphp driver
> to the guest VM on below environment.
>
>  Host : RHEL6.0
>  Guest: RHEL5.5
>
> Unfortunately, I'm not familiar with qemu-kvm.
> I investigated below questions about this problem, but I couldn't resolve them.
>
>  - How to call qdev_free() asynchronously. (How should we fix this problem)
>  - Why it don't occur with acpiphp driver
>
> If anyone knows answer of above questions or its clue, please let me know.

If fact this is not a bug.
`qdev_free` is called when the acpi detach succeed in `pciej_write`.
The virtual machine has to correctly support acpi signals.
Please read the explanation from Markus Armbruster on
http://lists.nongnu.org/archive/html/qemu-devel/2011-02/msg02637.html

Regards,
Minoru Usui - Feb. 25, 2011, 4:52 a.m.
Hi, William, Markus and other people.

On Wed, 23 Feb 2011 10:42:02 +0100
William Dauchy <wdauchy@gmail.com> wrote:

> Hi Minoru,
> 
> On Tue, Feb 15, 2011 at 3:32 AM, Minoru Usui <usui@mxm.nes.nec.co.jp> wrote:
> > I can reproduce, too.
> > But strangely, it don't occur in case of loading acpiphp driver
> > to the guest VM on below environment.
> >
> >  Host : RHEL6.0
> >  Guest: RHEL5.5
> >
> > Unfortunately, I'm not familiar with qemu-kvm.
> > I investigated below questions about this problem, but I couldn't resolve them.
> >
> >  - How to call qdev_free() asynchronously. (How should we fix this problem)
> >  - Why it don't occur with acpiphp driver
> >
> > If anyone knows answer of above questions or its clue, please let me know.
> 
> If fact this is not a bug.
> `qdev_free` is called when the acpi detach succeed in `pciej_write`.
> The virtual machine has to correctly support acpi signals.
> Please read the explanation from Markus Armbruster on
> http://lists.nongnu.org/archive/html/qemu-devel/2011-02/msg02637.html

William, Thank you for your help and telling me about it.

Markus, Thank you for your detailed explanation.
Basically, I understand behaviour of device_del command.
The result of pci hotunplug depends on behaviour of guest OS,
but device_del command doesn't wait hotunplug's result.

May I ask you a question?
Which device does qemu_device_opts manage?
just hotplugged to virtual machine? Or hotplugged to guest OS?

By the present implementation, device_add command adds qemu_device_opts immediately, 
whether guest OS can hotplug the device or not.
Nevertheless, device_del command waits for the device appropriately 
until it is hotunplugged by the guest OS.

By Markus's explanation, device_del command can't wait for the device
which hotunplugged from guest OS.
So, I feel it's better that qemu_device_opts manages the device
which hotplugged to guest OS.

If I am wrong, please let me know.
Markus Armbruster - Feb. 25, 2011, 9:40 a.m.
Minoru Usui <usui@mxm.nes.nec.co.jp> writes:

> Hi, William, Markus and other people.
>
> On Wed, 23 Feb 2011 10:42:02 +0100
> William Dauchy <wdauchy@gmail.com> wrote:
>
>> Hi Minoru,
>> 
>> On Tue, Feb 15, 2011 at 3:32 AM, Minoru Usui <usui@mxm.nes.nec.co.jp> wrote:
>> > I can reproduce, too.
>> > But strangely, it don't occur in case of loading acpiphp driver
>> > to the guest VM on below environment.
>> >
>> >  Host : RHEL6.0
>> >  Guest: RHEL5.5
>> >
>> > Unfortunately, I'm not familiar with qemu-kvm.
>> > I investigated below questions about this problem, but I couldn't resolve them.
>> >
>> >  - How to call qdev_free() asynchronously. (How should we fix this problem)
>> >  - Why it don't occur with acpiphp driver
>> >
>> > If anyone knows answer of above questions or its clue, please let me know.
>> 
>> If fact this is not a bug.
>> `qdev_free` is called when the acpi detach succeed in `pciej_write`.
>> The virtual machine has to correctly support acpi signals.
>> Please read the explanation from Markus Armbruster on
>> http://lists.nongnu.org/archive/html/qemu-devel/2011-02/msg02637.html
>
> William, Thank you for your help and telling me about it.
>
> Markus, Thank you for your detailed explanation.
> Basically, I understand behaviour of device_del command.
> The result of pci hotunplug depends on behaviour of guest OS,
> but device_del command doesn't wait hotunplug's result.
>
> May I ask you a question?
> Which device does qemu_device_opts manage?
> just hotplugged to virtual machine? Or hotplugged to guest OS?
>
> By the present implementation, device_add command adds qemu_device_opts immediately, 
> whether guest OS can hotplug the device or not.
> Nevertheless, device_del command waits for the device appropriately 
> until it is hotunplugged by the guest OS.
>
> By Markus's explanation, device_del command can't wait for the device
> which hotunplugged from guest OS.
> So, I feel it's better that qemu_device_opts manages the device
> which hotplugged to guest OS.
>
> If I am wrong, please let me know.

qemu_device_opts holds the currently defined device configurations.  A
device configuration becomes defined the moment its QemuOpts get created
(for -device and device_add: right when the argument gets parsed, which
is *before* the device gets created, let alone plugged).  It ceases to
be defined when device creation fails, or when the device is deleted
after unplug completed.

qemu_device_opts is *not* the set of devices currently plugged in.  That
information is encoded in the device tree.

Patch

--- a/hw/qdev.c	2011-01-27 17:42:25.000000000 +0900
+++ b/hw/qdev.c	2011-01-27 17:43:46.000000000 +0900
@@ -905,6 +905,8 @@  int do_device_del(Monitor *mon, const QD
         qerror_report(QERR_DEVICE_NOT_FOUND, id);
         return -1;
     }
+    qemu_opts_del(qemu_opts_find(&qemu_device_opts, id));
+
     return qdev_unplug(dev);
 }