]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Error out earlier if the volume target path already exists
authorOsier Yang <jyang@redhat.com>
Wed, 5 Dec 2012 04:44:11 +0000 (12:44 +0800)
committerOsier Yang <jyang@redhat.com>
Wed, 5 Dec 2012 17:10:00 +0000 (01:10 +0800)
https://bugzilla.redhat.com/show_bug.cgi?id=832302

It's odd to fall through to buildVol, and the existed file is
removed when buildVol fails. This checks if the volume target
path already exists in createVol. The reason for not using
error like "Volume already exists" is that there isn't volume
maintained by libvirt for the path until a operation like
pool-refresh, using error like that will just cause confusion.

src/storage/storage_backend_fs.c

index 4e6ebbf3117e2e7e5db0eefdd51638c26f5e8001..6cddad00dd05b8571b0675bd5405c432a35992dd 100644 (file)
@@ -1000,6 +1000,13 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
         return -1;
     }
 
+    if (virFileExists(vol->target.path)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("volume target path '%s' already exists"),
+                       vol->target.path);
+        return -1;
+    }
+
     VIR_FREE(vol->key);
     vol->key = strdup(vol->target.path);
     if (vol->key == NULL) {