[libvirt] [PATCH 4/6] storage:dir: .resizeVol callback for ploop volume

Olga Krishtal okrishtal at virtuozzo.com
Thu Feb 18 10:58:11 UTC 2016


On 18/02/16 11:15, Nikolay Shirokovskiy wrote:
>
> On 17.02.2016 14:40, Olga Krishtal wrote:
>> To change the size of ploop image file we use ploop resize cmd that takes
>> 2 args: new size and path/to/DiskDescriptor.xml
>>
>> Signed-off-by: Olga Krishtal <okrishtal at virtuozzo.com>
>> ---
>>   src/storage/storage_backend.c    | 33 +++++++++++++++++++++++++++++++++
>>   src/storage/storage_backend.h    |  3 +++
>>   src/storage/storage_backend_fs.c |  2 ++
>>   3 files changed, 38 insertions(+)
>>
>> diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
>> index ac44fdf..18d414c 100644
>> --- a/src/storage/storage_backend.c
>> +++ b/src/storage/storage_backend.c
>> @@ -875,6 +875,39 @@ int virStorageBackendDeletePloop(virStorageVolDefPtr vol)
>>       return virFileDeleteTree(vol->target.path);
>>   }
>>   
>> +int virStoragePloopResize(virStorageVolDefPtr vol,
>> +                          unsigned long long capacity)
>> +{
>> +    int ret = -1;
>> +    char *path = NULL;
>> +    char *size = NULL;
>> +    virCommandPtr cmd = NULL;
>> +    char *create_tool = NULL;
> strange name
Strange? This name is widely used in code.
>
>> +
>> +    create_tool = virFindFileInPath("ploop");
>> +    if (!create_tool) {
>> +        virReportError(VIR_ERR_INTERNAL_ERROR,
>> +                       "%s", _("unable to find ploop, please install "
>> +                       "ploop tools"));
>> +        return -1;
>> +    }
>> +    if (virAsprintf(&path, "%s/DiskDescriptor.xml", vol->target.path) < 0)
>> +        return -1;
>> +
>> +    if (virAsprintf(&size, "%lluM", VIR_DIV_UP(capacity, (1024 * 1024))) < 0)
>> +        goto cleanup;
> use virCommandAddArgFormat
Ok
>> +
>> +    cmd = virCommandNewArgList(create_tool, "resize", "-s", size, path, NULL);
>> +
>> +    ret = virCommandRun(cmd, NULL);
>> +
>> + cleanup:
>> +    virCommandFree(cmd);
>> +    VIR_FREE(path);
>> +    VIR_FREE(size);
>> +    return ret;
> you need to free 'create_tool' as well
Ok
>> +}
>> +
>>   enum {
>>       QEMU_IMG_BACKING_FORMAT_NONE = 0,
>>       QEMU_IMG_BACKING_FORMAT_FLAG,
>> diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
>> index 3529755..65e91dc 100644
>> --- a/src/storage/storage_backend.h
>> +++ b/src/storage/storage_backend.h
>> @@ -117,6 +117,9 @@ int virStorageBackendCreatePloop(virConnectPtr conn,
>>   
>>   int virStorageBackendDeletePloop(virStorageVolDefPtr vol);
>>   
>> +int virStoragePloopResize(virStorageVolDefPtr vol,
>> +                          unsigned long long capacity);
>> +
>>   virStorageBackendBuildVolFrom
>>   virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
>>                                            virStorageVolDefPtr inputvol);
>> diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
>> index f494fd2..abb6e47 100644
>> --- a/src/storage/storage_backend_fs.c
>> +++ b/src/storage/storage_backend_fs.c
>> @@ -1378,6 +1378,8 @@ virStorageBackendFileSystemVolResize(virConnectPtr conn ATTRIBUTE_UNUSED,
>>       if (vol->target.format == VIR_STORAGE_FILE_RAW) {
>>           return virStorageFileResize(vol->target.path, capacity,
>>                                       vol->target.allocation, pre_allocate);
>> +    } else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
>> +        return virStoragePloopResize(vol, capacity);
>>       } else {
>>           if (pre_allocate) {
>>               virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
>>




More information about the libvir-list mailing list