]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: blockcopy: reuse storage driver APIs to pre-create copy target
authorPeter Krempa <pkrempa@redhat.com>
Mon, 29 Feb 2016 12:36:16 +0000 (13:36 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 20 Jul 2017 08:07:48 +0000 (10:07 +0200)
Rather than using the local-file only implementation 'qemuOpenFile'
switch to the imagelabel aware storage driver implementation.

src/qemu/qemu_driver.c

index 3ab31764c52ac502c213296d1eec5a7f5fc86f92..f9ae0120ecda06da57e8ff925e45842d3a6d15dc 100644 (file)
@@ -16785,6 +16785,10 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
                        _("non-file destination not supported yet"));
         goto endjob;
     }
+
+    if (qemuDomainStorageFileInit(driver, vm, mirror) < 0)
+        goto endjob;
+
     if (stat(mirror->path, &st) < 0) {
         if (errno != ENOENT) {
             virReportSystemError(errno, _("unable to stat for disk %s: %s"),
@@ -16832,12 +16836,12 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
 
     /* pre-create the image file */
     if (!reuse) {
-        int fd = qemuOpenFile(driver, vm, mirror->path,
-                              O_WRONLY | O_TRUNC | O_CREAT,
-                              &need_unlink, NULL);
-        if (fd < 0)
+        if (virStorageFileCreate(mirror) < 0) {
+            virReportSystemError(errno, "%s", _("failed to create copy target"));
             goto endjob;
-        VIR_FORCE_CLOSE(fd);
+        }
+
+        need_unlink = true;
     }
 
     if (mirror->format > 0)
@@ -16869,6 +16873,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
 
     /* Update vm in place to match changes.  */
     need_unlink = false;
+    virStorageFileDeinit(mirror);
     disk->mirror = mirror;
     mirror = NULL;
     disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY;
@@ -16879,8 +16884,9 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
                  vm->def->name);
 
  endjob:
-    if (need_unlink && unlink(mirror->path))
-        VIR_WARN("unable to unlink just-created %s", mirror->path);
+    if (need_unlink && virStorageFileUnlink(mirror) < 0)
+        VIR_WARN("%s", _("unable to remove just-created copy target"));
+    virStorageFileDeinit(mirror);
     qemuDomainObjEndJob(driver, vm);
     if (monitor_error) {
         virSetError(monitor_error);