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
In case of .uploadVol, we have to additionaly update DiskDescriptor.xml Signed-off-by: Olga Krishtal <okrish...@virtuozzo.com> --- src/storage/storage_backend.c | 66 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 9f0e020..ac44fdf 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -2023,12 +2023,63 @@ virStorageBackendVolUploadLocal(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned long long len, unsigned int flags) { + char *path = NULL; + char *target_path = vol->target.path; + int ret; + virCommandPtr cmd = NULL; + char *create_tool = NULL; + virCheckFlags(0, -1); /* Not using O_CREAT because the file is required to already exist at * this point */ - return virFDStreamOpenBlockDevice(stream, vol->target.path, + if (vol->target.format != VIR_STORAGE_FILE_PLOOP) { + return virFDStreamOpenBlockDevice(stream, target_path, offset, len, O_WRONLY); + } else { + if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0) + return -1; + target_path = path; + ret = virFDStreamOpenBlockDevice(stream, target_path, + offset, len, O_WRONLY); + if (ret < 0) { + goto cleanup; + } + + create_tool = virFindFileInPath("ploop"); + if (!create_tool) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("unable to find ploop, please install " + "ploop tools")); + ret = -1; + goto cleanup; + } + cmd = virCommandNewArgList(create_tool, "restore-descriptor", + vol->target.path, target_path, NULL); + VIR_FREE(path); + if (virAsprintf(&path, "%s/DiskDescriptor.xml", + vol->target.path) < 0) { + ret = -1; + goto cleanup; + } + if (virFileExists(path)) { + if (virFileRemove(path, 0, 0) < 0) { + ret = -1; + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable " + "to delete existing DiskDescriptor.xml")); + goto cleanup; + } + } + if (virCommandRun(cmd, NULL) < 0) { + ret = -1; + goto cleanup; + } + } + + cleanup: + VIR_FREE(cmd); + VIR_FREE(path); + return ret; } int @@ -2040,10 +2091,21 @@ virStorageBackendVolDownloadLocal(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->target.format == VIR_STORAGE_FILE_PLOOP) { + if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0) + return -1; + target_path = path; + } - return virFDStreamOpenBlockDevice(stream, vol->target.path, + ret = virFDStreamOpenBlockDevice(stream, target_path, offset, len, O_RDONLY); + VIR_FREE(path); + return ret; } -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list