此文来自于我在libvirt mail-list 中提的一个问题:
写道
hi,all
I use Java api `domain.attachDeviceFlags(xml, 0);` to add a disk for domain. the xml file like this:
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/dev/sp1353486595267/v1353488096262'/>
<target dev='vdb' bus='virtio'/>
</disk>
then I use command `virsh detach-disk $domain vdb` to remove the disk.
what I said above have no any errors.but the problem is when I restart this vm ,the disk still exist,because I see it from the command `virsh dumpxml $domain` ,how to remove the disk from this domain persistently.
thanks in advance.
>zhijun
随后Eric Blake给我做了详细的回答:
写道
Use the flags argument. By passing '0' (aka
VIR_DOMAIN_AFFECT_CURRENT
in the C API counterpart), you are explicitly requesting that only the
current configuration be modified (
for a running domain, that means you
are doing a one-time hotplug, but not to remember it for the next boot).
If you want to simultaneously hotplug _and_ affect the next boot, you
need to instead pass whatever the Java binding is for the underlying
flags VIR_DOMAIN_AFFECT_LIVE|VIR_DOMAIN_AFFECT_CONFIG of the C API
(sorry, I don't know the Java binding well enough to know what that
binding is).
三个参数的区别:
VIR_DOMAIN_AFFECT_CURRENT: specifies that the device allocation is made based on current domain state.for a running domain, that means you are doing a one-time hotplug, but not to remember it for the next boot. ·virsh detach-disk ·只在当前状态下有效,重启后又会attach上disk
VIR_DOMAIN_AFFECT_LIVE: specifies that the device shall be allocated to the active domain instance only and is not added to the persisted domain configuration(并不会持久到xml文件中)
VIR_DOMAIN_AFFECT_CONFIG: specifies that the device shall be allocated to the persisted domain configuration only (虚拟机在关机状态下,disk会持久化到配置文件中,如果是开机的状态,disk并不会写到配置文件中,相当于 VIR_DOMAIN_AFFECT_LIVE)
卸载卷时需要加上参数(pesistent)
virsh detach-disk vdx --persistent
非常感谢他的回答。
参考:http://libvirt.org/html/libvirt-libvirt.html#virDomainAttachDeviceFlags