[libvirt-users] virsh attach-disk with cache=none and io=native for raw devices (online)

Frido Roose fr.roose at gmail.com
Wed Apr 11 09:52:31 UTC 2012


On Thursday 5 April 2012 at 11:40, Daniel P. Berrange wrote:
> On Thu, Apr 05, 2012 at 11:36:55AM +0200, Frido Roose wrote:
> > Hello, 
> > 
> > I see there is an option with virsh attach-disk to set the cache to "none" for raw devices, but I can't find how to attach the disk with io=native (needed for performance reasons).
> > The goal is to attach a disk online, directly with the proper performance settings.
> 
> 
> 
> virsh attach-disk is just a wrapper around the more general
> command virsh attach-device. So if there's stuff you can't
> set with attach-disk, you can always pass the complete XML
> to attach-device to set everything
> 

Thanks for the tip...

I made a little shell script that allows me to hot-add a device with cache=none and io=native, similar to attack-disk, and it seems to work!

Best regards,
Frido Roose


# cat virsh-attach-disk.sh 

#!/bin/bash
VM=$1
VDX=$2
DEV=$3
if [ -z "$VDX" ]
then
# try to find out next available vdx device
echo "Usage: $0 <vmname> <vdx> <dev>"
exit 1
fi

XMLFILE=/tmp/virsh-attach-disk.$$.xml
echo "
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='$DEV'/>
<target dev='$VDX' bus='virtio'/>
</disk>
" >$XMLFILE

echo "About to add the following disk config:"
cat $XMLFILE

echo
echo " # virsh attach-device $VM $XMLFILE --persistent"
echo
echo -n "Apply? [y/n] "
read answer
if [ "$answer" == "y" -o "$answer" == "Y" ]
then
virsh attach-device $VM $XMLFILE --persistent
else
echo "Aborted!"
fi
rm -f $XMLFILE







More information about the libvirt-users mailing list