After a successful qemu-img/qcow-create of the backing file, if we
fail to stat the file, change it owner/group, or mode, then the
cleanup path should delete the file.

Also moved the virCommandSetUID/virCommandSetGID inside the condition
used to actually run the command rather than randomly setting and not
using it if the file had been created.  The 'cmd' buffer is only used
if we need to create.

Signed-off-by: John Ferlan <[email protected]>
---
 src/storage/storage_backend.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index a375fe0..7d0de63 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -698,13 +698,16 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr 
pool,
         }
     }
 
-    /* don't change uid/gid if we retry */
-    virCommandSetUID(cmd, -1);
-    virCommandSetGID(cmd, -1);
-
     if (!filecreated) {
+        /* don't change uid/gid if we retry */
+        virCommandSetUID(cmd, -1);
+        virCommandSetGID(cmd, -1);
+
         if (virCommandRun(cmd, NULL) < 0)
             goto cleanup;
+
+        filecreated = true;
+
         if (stat(vol->target.path, &st) < 0) {
             virReportSystemError(errno,
                                  _("failed to create %s"), vol->target.path);
@@ -737,6 +740,8 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr 
pool,
     ret = 0;
 
  cleanup:
+    if (ret < 0 && filecreated)
+        unlink(vol->target.path);
     return ret;
 }
 
-- 
2.1.0

--
libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to