[Kimchi-devel] [PATCH] [Kimchi] Replace backing image by clone when using template based on existing img

Aline Manera alinefm at linux.vnet.ibm.com
Tue Apr 12 18:33:56 UTC 2016



On 04/08/2016 09:52 PM, Jose Ricardo Ziviani wrote:
>   - This commit replaces the current backing image to a complete clone
>     when using a template based on an existing template.
>
> Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
> ---
>   model/templates.py | 17 ++++++++++++++++-
>   vmtemplate.py      |  8 --------
>   2 files changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/model/templates.py b/model/templates.py
> index 1e6ad30..87173d1 100644
> --- a/model/templates.py
> +++ b/model/templates.py
> @@ -361,7 +361,22 @@ class LibvirtVMTemplate(VMTemplate):
>               for v in vol_list:
>                   pool = self._get_storage_pool(v['pool'])
>                   # outgoing text to libvirt, encode('utf-8')
> -                pool.createXML(v['xml'].encode('utf-8'), 0)

> +                if 'base' in v and 'path' in v['base']:
> +                    conn = self.conn.get()
> +                    try:
> +                        volume_base = conn.storageVolLookupByPath(
> +                            v['base']['path'])
> +
> +                    except libvirt.libvirtError as e:
> +                        pool.createXML(v['xml'].encode('utf-8'), 0)
> +                        continue
> +
> +                    pool.createXMLFrom(v['xml'].encode('utf-8'),
> +                                       volume_base,
> +                                       0)
> +                else:
> +                    pool.createXML(v['xml'].encode('utf-8'), 0)

 From the libvirt documentation, I can see the createXMLFrom() will, in 
fact, clone the storage volume but seems it is not true for createXML()

We need to clone the 'base' volume when creating the guest otherwise the 
disk will not be used multiple times - when using the same Template to 
create multiple VMs.

  |  createXML(self, xmlDesc, flags=0)
  |      Create a storage volume within a pool based
  |      on an XML description. Not all pools support
  |      creation of volumes.
  |
  |      Since 1.0.1 VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA
  |      in flags can be used to get higher performance with
  |      qcow2 image files which don't support full preallocation,
  |      by creating a sparse image file with metadata.
  |
  |      virStorageVolFree should be used to free the resources after the
  |      storage volume object is no longer needed.
  |
  |  createXMLFrom(self, xmlDesc, clonevol, flags=0)
  |      Create a storage volume in the parent pool, using the
  |      'clonevol' volume as input. Information for the new
  |      volume (name, perms)  are passed via a typical volume
  |      XML description.
  |
  |      Since 1.0.1 VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA
  |      in flags can be used to get higher performance with
  |      qcow2 image files which don't support full preallocation,
  |      by creating a sparse image file with metadata.
  |
  |      virStorageVolFree should be used to free the resources after the
  |      storage volume object is no longer needed.

> +
>           except libvirt.libvirtError as e:
>               raise OperationFailed("KCHVMSTOR0008E", {'error': e.message})
>           return vol_list
> diff --git a/vmtemplate.py b/vmtemplate.py
> index a223beb..4ce5d19 100644
> --- a/vmtemplate.py
> +++ b/vmtemplate.py
> @@ -264,14 +264,6 @@ class VMTemplate(object):
>               v_tree.append(E.capacity(str(info['capacity']), unit='G'))
>
>               target_fmt = info['format']
> -            if 'base' in d:
> -                # target must be qcow2 in order to use a backing file
> -                target_fmt = 'qcow2'
> -
> -                v_tree.append(E.backingStore(
> -                    E.path(info['base']['path']),
> -                    E.format(type=info['base']['format'])))
> -
>               target = E.target(
>                   E.format(type=target_fmt), E.path(info['path']))
>               v_tree.append(target)




More information about the Kimchi-devel mailing list