[libvirt] [PATCH 4/7] storage:dir: adapts .uploadVol .dowloadVol for ploop volume

Mikhail Feoktistov mfeoktistov at virtuozzo.com
Mon Feb 8 12:19:17 UTC 2016



On 05.02.2016 19:23, Olga Krishtal wrote:
> In case of ploop volume, target path of the volume is the path to the
> directory that contains image file named root.hds and DiskDescriptor.xml.
> While using uploadVol and downloadVol callbacks we need to open root.hds
> itself. To accomplish this goal we must change path from
> path/to/ploop directory to path/to/ploop/root.hds
>
> Signed-off-by: Olga Krishtal <okrishtal at virtuozzo.com>
> ---
>   src/storage/storage_backend.c | 27 ++++++++++++++++++++++++---
>   1 file changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
> index 1b4ffbc..2afcc7c 100644
> --- a/src/storage/storage_backend.c
> +++ b/src/storage/storage_backend.c
> @@ -2016,12 +2016,23 @@ virStorageBackendVolUploadLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
>                                   unsigned long long len,
>                                   unsigned int flags)
>   {
> +    char *path = NULL;
> +    char *target_path = vol->target.path;
> +    int ret;
> +
>       virCheckFlags(0, -1);
> +    if (vol->type == VIR_STORAGE_VOL_PLOOP) {
> +        if (virAsprintf(&path, "%s/%s", vol->target.path, "root.hds") < 0)
> +            return -1;
> +        target_path = path;
> +    }
>   
>       /* Not using O_CREAT because the file is required to already exist at
>        * this point */
> -    return virFDStreamOpenBlockDevice(stream, vol->target.path,
> +    ret =  virFDStreamOpenBlockDevice(stream, target_path,
Delete one space after "="
>                                         offset, len, O_WRONLY);
> +    VIR_FREE(path);
> +    return ret;
>   }
>   
>   int
> @@ -2033,10 +2044,20 @@ virStorageBackendVolDownloadLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
>                                     unsigned long long len,
>                                     unsigned int flags)
>   {
> -    virCheckFlags(0, -1);
> +    char *path = NULL;
> +    char *target_path = vol->target.path;
> +    int ret;
> +    if (vol->type == VIR_STORAGE_VOL_PLOOP) {
> +        if (virAsprintf(&path, "%s/%s", vol->target.path, "root.hds") < 0)
> +            return -1;
> +        target_path = path;
> +    }
>   
> -    return virFDStreamOpenBlockDevice(stream, vol->target.path,
> +    virCheckFlags(0, -1);
> +    ret = virFDStreamOpenBlockDevice(stream, target_path,
>                                         offset, len, O_RDONLY);
> +    VIR_FREE(path);
> +    return ret;
>   }
Memory leak.
If virCheckFlags fails than we do not free "path" memory
>   
>   




More information about the libvir-list mailing list