]> xenbits.xensource.com Git - libvirt.git/commitdiff
Create a shallow copy for volume building only if supported
authorJán Tomko <jtomko@redhat.com>
Thu, 24 Sep 2015 15:12:02 +0000 (17:12 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 29 Sep 2015 08:45:01 +0000 (10:45 +0200)
Since the previous commit, the shallow copy is only used inside
the if (backend->buildVol) if.

src/storage/storage_driver.c

index 16d0b6c71f3857b5b90df4749eb060f040183c64..7aaa060e202c648a3e346f6a3d866099367f9b8f 100644 (file)
@@ -1766,7 +1766,6 @@ storageVolCreateXML(virStoragePoolPtr obj,
     virStorageBackendPtr backend;
     virStorageVolDefPtr voldef = NULL;
     virStorageVolPtr ret = NULL, volobj = NULL;
-    virStorageVolDefPtr buildvoldef = NULL;
 
     virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
 
@@ -1828,19 +1827,21 @@ storageVolCreateXML(virStoragePoolPtr obj,
         goto cleanup;
     }
 
-    if (VIR_ALLOC(buildvoldef) < 0) {
-        voldef = NULL;
-        goto cleanup;
-    }
-
-    /* Make a shallow copy of the 'defined' volume definition, since the
-     * original allocation value will change as the user polls 'info',
-     * but we only need the initial requested values
-     */
-    memcpy(buildvoldef, voldef, sizeof(*voldef));
 
     if (backend->buildVol) {
         int buildret;
+        virStorageVolDefPtr buildvoldef = NULL;
+
+        if (VIR_ALLOC(buildvoldef) < 0) {
+            voldef = NULL;
+            goto cleanup;
+        }
+
+        /* Make a shallow copy of the 'defined' volume definition, since the
+         * original allocation value will change as the user polls 'info',
+         * but we only need the initial requested values
+         */
+        memcpy(buildvoldef, voldef, sizeof(*voldef));
 
         /* Drop the pool lock during volume allocation */
         pool->asyncjobs++;
@@ -1891,7 +1892,6 @@ storageVolCreateXML(virStoragePoolPtr obj,
  cleanup:
     virObjectUnref(volobj);
     virStorageVolDefFree(voldef);
-    VIR_FREE(buildvoldef);
     if (pool)
         virStoragePoolObjUnlock(pool);
     return ret;