[Kimchi-devel] [PATCH] create a VM from an scsi pool template

Aline Manera alinefm at linux.vnet.ibm.com
Tue Mar 25 19:27:12 UTC 2014


Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>

On 03/25/2014 09:49 AM, shaohef at linux.vnet.ibm.com wrote:
> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>
> support to create a VM from a scsi pool template.
>
>  From the libvirt document:
> we can create a lun disk for vm by two format:
>      <disk type='volume' device='disk'>
>        <driver name='qemu' type='raw'/>
>        <source pool='scsi-pool' volume='unit:0:0:0' />
>        <target dev='vda' bus='virtio'/>
>      </disk>
> and
>      <disk type='block' device='lun'>
>        <driver name='qemu' type='raw' cache='none'/>
>        <source dev='/dev/disk'/>
>        <target dev='sda' bus='scsi'/>
>      </disk>
>
> The later, VM disk is "block" and the device "lun", except that
> generic SCSI commands from the guest are accepted and passed through to
> the physical device, and this will only be recognized for actual raw devices.
> This is high performance than the former.
>
> But later, disk device='lun' is only valid for block type disk source.
> It does not support a volume from a pool formate like:
> <source pool='scsi-pool' volume='unit:0:0:0' />
>
> So I assign the disk source is block instead of volume from a pool
> in both passthrough or non-passthrough.
>
> 1. how to test this patch:
> create a scsi pool named "my-scsi" by virsh
>
> 2.get the volumes name of this pool:
> $ sudo virsh vol-list my-scsi
> Name                 Path
> -----------------------------------------
> unit:0:0:0 /dev/disk/by-id/wwn-0x60014056aefaef96d4e4033953d9627d
>
> 3. create a template with this pool like this:
> $ curl -u <user> -H "Content-Type: application/json" \
> -H  "Accept: application/json" \
> http://localhost:8000/templates/ -X POST  -d '
> {
>      "cpus": 1,
>      "cdrom":"/home/shhfeng/iso/f17.iso",
>      "name":"F17-SCSI",
>      "storagepool":"/storagepools/my-scsi",
>      "disks":[
>       {
>         "index":0,
>         "volume":"unit:0:0:0"
>       }
>     ]
> }'
>
> 4. create a VM with this template and start it.
>
> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> ---
>   src/kimchi/model/vms.py  |  2 +-
>   src/kimchi/vmtemplate.py | 11 ++++++++---
>   2 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
> index 483b9ae..ef1d617 100644
> --- a/src/kimchi/model/vms.py
> +++ b/src/kimchi/model/vms.py
> @@ -184,7 +184,7 @@ class VMsModel(object):
>           # If storagepool is SCSI, volumes will be LUNs and must be passed by
>           # the user from UI or manually.
>           vol_list = []
> -        if t._get_storage_type() == "iscsi":
> +        if t._get_storage_type() in ["iscsi", "scsi"]:
>               vol_list = []
>           elif t._get_storage_type() in READONLY_POOL_TYPE:
>               if not params.get('volumes'):
> diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
> index 4ecba6e..e753ec2 100644
> --- a/src/kimchi/vmtemplate.py
> +++ b/src/kimchi/vmtemplate.py
> @@ -181,7 +181,10 @@ class VMTemplate(object):
>               graphics_xml = graphics_xml + spicevmc_xml
>           return graphics_xml
>
> -    def _get_scsi_disks_xml(self, luns):
> +    def _get_scsi_disks_xml(self):
> +        luns = [disk['volume'] for disk in self.info.get('disks', {})
> +                if 'volume' in disk]
> +
>           ret = ""
>           # Passthrough configuration
>           disk_xml = """
> @@ -193,8 +196,10 @@ class VMTemplate(object):
>           if not self.fc_host_support:
>               disk_xml = disk_xml.replace('volume','block')
>
> +        pool = self._storage_validate()
>           # Creating disk xml for each lun passed
> -        for index,(lun, path) in enumerate(luns):
> +        for index, lun in enumerate(luns):
> +            path = pool.storageVolLookupByName(lun).path()
>               dev = "sd%s" % string.lowercase[index]
>               params = {'src': path, 'dev': dev}
>               ret = ret + disk_xml % params
> @@ -309,7 +314,7 @@ class VMTemplate(object):
>           if storage_type == "iscsi":
>               params['disks'] = self._get_iscsi_disks_xml()
>           elif storage_type == "scsi":
> -            params['disks'] = self._get_scsi_disks_xml(kwargs.get('volumes'))
> +            params['disks'] = self._get_scsi_disks_xml()
>           else:
>               params['disks'] = self._get_disks_xml(vm_uuid)
>




More information about the Kimchi-devel mailing list