[Kimchi-devel] [PATCH] [Kimchi] Implement image rebase to avoid backing file dependency

Aline Manera alinefm at linux.vnet.ibm.com
Mon May 9 15:34:00 UTC 2016



On 05/05/2016 05:42 PM, Jose Ricardo Ziviani wrote:
>   - Runs a rebase on the image that has created using backing file to
>     avoid such dependency. It's slower than using the backing file
>     itself but faster than clonning and more reliable than trusting in
>     backing files.

I tested this patch and it takes really long time to create a guest 
based on IMG.

Why do not keep using backing store and fix the issues related to that?

>
> Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
> ---
>   i18n.py            |  1 +
>   model/templates.py |  8 ++++++++
>   utils.py           | 16 +++++++++++++++-
>   3 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/i18n.py b/i18n.py
> index 39f5e57..bcc8b96 100644
> --- a/i18n.py
> +++ b/i18n.py
> @@ -292,6 +292,7 @@ messages = {
>
>       "KCHUTILS0003E": _("Unable to choose a virtual machine name"),
>       "KCHUTILS0006E": _("Cannot upgrade objectstore data."),
> +    "KCHUTILS0007E": _("Impossible to rebase the image: %(error)s"),
>
>       "KCHVMSTOR0002E": _("Invalid storage type. Types supported: 'cdrom', 'disk'"),
>       "KCHVMSTOR0003E": _("The path '%(value)s' is not a valid local/remote path for the device"),
> diff --git a/model/templates.py b/model/templates.py
> index 131f86b..e8b9e51 100644
> --- a/model/templates.py
> +++ b/model/templates.py
> @@ -34,6 +34,7 @@ from wok.xmlutils.utils import xpath_get_text
>   from wok.plugins.kimchi.config import get_kimchi_version
>   from wok.plugins.kimchi.kvmusertests import UserTests
>   from wok.plugins.kimchi.model.cpuinfo import CPUInfoModel
> +from wok.plugins.kimchi.utils import image_rebase
>   from wok.plugins.kimchi.utils import pool_name_from_uri
>   from wok.plugins.kimchi.vmtemplate import VMTemplate
>
> @@ -400,6 +401,13 @@ class LibvirtVMTemplate(VMTemplate):
>                   pool = self._get_storage_pool(v['pool'])
>                   # outgoing text to libvirt, encode('utf-8')
>                   pool.createXML(v['xml'].encode('utf-8'), 0)
> +
> +                # if using backing image, rebase the image to remove the
> +                # dependency on that backing image
> +                if 'base' in v \
> +                   and 'path' in v['base'] \
> +                   and 'path' in v:
> +                    image_rebase(v['path'])
>           except libvirt.libvirtError as e:
>               raise OperationFailed("KCHVMSTOR0008E", {'error': e.message})
>           return vol_list
> diff --git a/utils.py b/utils.py
> index c4cd07d..9b9a4dc 100644
> --- a/utils.py
> +++ b/utils.py
> @@ -30,12 +30,26 @@ from urlparse import urlparse
>   from wok.exception import InvalidParameter, OperationFailed
>   from wok.plugins.kimchi import config
>   from wok.plugins.kimchi.osinfo import get_template_default
> -from wok.utils import wok_log
> +from wok.utils import run_command, wok_log
>   from wok.xmlutils.utils import xpath_get_text
>
>   MAX_REDIRECTION_ALLOWED = 5
>
>
> +def image_rebase(image_path):
> +    wok_log.info('starting to rebase image %s' % image_path)
> +    _, err, rc = run_command(['qemu-img',
> +                              'rebase',
> +                              '-b',
> +                              '',
> +                              image_path])
> +    if rc or err:
> +        error = '%s - %s' % (str(rc), err)
> +        raise OperationFailed("KCHUTILS0007E", {'error': error})
> +
> +    wok_log.info('image rebased successfully')
> +
> +
>   def _uri_to_name(collection, uri):
>       expr = '/plugins/kimchi/%s/(.*?)$' % collection
>       m = re.match(expr, uri)




More information about the Kimchi-devel mailing list