]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Track backing store of a volume in the target struct
authorPeter Krempa <pkrempa@redhat.com>
Mon, 14 Jul 2014 13:19:49 +0000 (15:19 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 16 Jul 2014 09:42:51 +0000 (11:42 +0200)
As we have a nested pointer for storing the backing store of a volume
there's no need to store it in a separate struct.

src/conf/storage_conf.c
src/conf/storage_conf.h
src/storage/storage_backend.c
src/storage/storage_backend_fs.c
src/storage/storage_backend_gluster.c
src/storage/storage_backend_logical.c

index aa2965833fb9700dd22aab2ccaed503e08dd15f3..c79aebd0a4234a83811592e5288ca00f188b1da3 100644 (file)
@@ -331,7 +331,6 @@ virStorageVolDefFree(virStorageVolDefPtr def)
     VIR_FREE(def->source.extents);
 
     virStorageSourceClear(&def->target);
-    virStorageSourceClear(&def->backingStore);
     VIR_FREE(def);
 }
 
@@ -1168,6 +1167,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
     char *allocation = NULL;
     char *capacity = NULL;
     char *unit = NULL;
+    char *backingStore = NULL;
     xmlNodePtr node;
     xmlNodePtr *nodes = NULL;
     size_t i;
@@ -1252,21 +1252,35 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
             goto error;
     }
 
-    ret->backingStore.path = virXPathString("string(./backingStore/path)", ctxt);
-    if (options->formatFromString) {
-        char *format = virXPathString("string(./backingStore/format/@type)", ctxt);
-        if (format == NULL)
-            ret->backingStore.format = options->defaultFormat;
-        else
-            ret->backingStore.format = (options->formatFromString)(format);
+    if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
+        if (VIR_ALLOC(ret->target.backingStore) < 0)
+            goto error;
 
-        if (ret->backingStore.format < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown volume format type %s"), format);
+        ret->target.backingStore->path = backingStore;
+        backingStore = NULL;
+
+        if (options->formatFromString) {
+            char *format = virXPathString("string(./backingStore/format/@type)", ctxt);
+            if (format == NULL)
+                ret->target.backingStore->format = options->defaultFormat;
+            else
+                ret->target.backingStore->format = (options->formatFromString)(format);
+
+            if (ret->target.backingStore->format < 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("unknown volume format type %s"), format);
+                VIR_FREE(format);
+                goto error;
+            }
             VIR_FREE(format);
-            goto error;
         }
-        VIR_FREE(format);
+
+        if (VIR_ALLOC(ret->target.backingStore->perms) < 0)
+            goto error;
+        if (virStorageDefParsePerms(ctxt, ret->target.backingStore->perms,
+                                    "./backingStore/permissions",
+                                    DEFAULT_VOL_PERM_MODE) < 0)
+            goto error;
     }
 
     ret->target.compat = virXPathString("string(./target/compat)", ctxt);
@@ -1308,19 +1322,13 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
         VIR_FREE(nodes);
     }
 
-    if (VIR_ALLOC(ret->backingStore.perms) < 0)
-        goto error;
-    if (virStorageDefParsePerms(ctxt, ret->backingStore.perms,
-                                "./backingStore/permissions",
-                                DEFAULT_VOL_PERM_MODE) < 0)
-        goto error;
-
  cleanup:
     VIR_FREE(nodes);
     VIR_FREE(allocation);
     VIR_FREE(capacity);
     VIR_FREE(unit);
     VIR_FREE(type);
+    VIR_FREE(backingStore);
     return ret;
 
  error:
@@ -1544,9 +1552,10 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
                                      &def->target, "target") < 0)
         goto cleanup;
 
-    if (def->backingStore.path &&
+    if (def->target.backingStore &&
         virStorageVolTargetDefFormat(options, &buf,
-                                     &def->backingStore, "backingStore") < 0)
+                                     def->target.backingStore,
+                                     "backingStore") < 0)
         goto cleanup;
 
     virBufferAdjustIndent(&buf, -2);
index 47f769b8833a1162fbfcdfb3585ab420a7b22baf..badf7a37413d036949eb7052c093fc9e27f31e0c 100644 (file)
@@ -68,7 +68,6 @@ struct _virStorageVolDef {
 
     virStorageVolSource source;
     virStorageSource target;
-    virStorageSource backingStore;
 };
 
 typedef struct _virStorageVolDefList virStorageVolDefList;
index a36996f609d8e87183d0980d28f8833bd0c519eb..f5bfdee3dc31c5322681f57c9d1e6f7d07cdbf99 100644 (file)
@@ -844,11 +844,11 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
 
     }
 
-    if (vol->backingStore.path) {
+    if (vol->target.backingStore) {
         int accessRetCode = -1;
         char *absolutePath = NULL;
 
-        backingType = virStorageFileFormatTypeToString(vol->backingStore.format);
+        backingType = virStorageFileFormatTypeToString(vol->target.backingStore->format);
 
         if (preallocate) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -862,7 +862,8 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
          * may cause issues with lvm. Untested essentially.
          */
         if (inputvol &&
-            STRNEQ_NULLABLE(inputvol->backingStore.path, vol->backingStore.path)) {
+            STRNEQ_NULLABLE(inputvol->target.backingStore->path,
+                            vol->target.backingStore->path)) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("a different backing store cannot be specified."));
             return NULL;
@@ -871,24 +872,24 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
         if (backingType == NULL) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unknown storage vol backing store type %d"),
-                           vol->backingStore.format);
+                           vol->target.backingStore->format);
             return NULL;
         }
 
         /* Convert relative backing store paths to absolute paths for access
          * validation.
          */
-        if ('/' != *(vol->backingStore.path) &&
+        if ('/' != *(vol->target.backingStore->path) &&
             virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
-                        vol->backingStore.path) < 0)
+                        vol->target.backingStore->path) < 0)
             return NULL;
         accessRetCode = access(absolutePath ? absolutePath
-                               : vol->backingStore.path, R_OK);
+                               : vol->target.backingStore->path, R_OK);
         VIR_FREE(absolutePath);
         if (accessRetCode != 0) {
             virReportSystemError(errno,
                                  _("inaccessible backing store volume %s"),
-                                 vol->backingStore.path);
+                                 vol->target.backingStore->path);
             return NULL;
         }
     }
@@ -929,7 +930,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
     cmd = virCommandNew(create_tool);
 
     convert = !!inputvol;
-    backing = !inputvol && vol->backingStore.path;
+    backing = !inputvol && vol->target.backingStore;
 
     if (convert)
         virCommandAddArgList(cmd, "convert", "-f", inputType, "-O", type, NULL);
@@ -937,7 +938,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
         virCommandAddArgList(cmd, "create", "-f", type, NULL);
 
     if (backing)
-        virCommandAddArgList(cmd, "-b", vol->backingStore.path, NULL);
+        virCommandAddArgList(cmd, "-b", vol->target.backingStore->path, NULL);
 
     if (imgformat >= QEMU_IMG_BACKING_FORMAT_OPTIONS) {
         if (vol->target.format == VIR_STORAGE_FILE_QCOW2 && !compat &&
@@ -1055,7 +1056,7 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
                        vol->target.format);
         return -1;
     }
-    if (vol->backingStore.path != NULL) {
+    if (vol->target.backingStore != NULL) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("copy-on-write image not supported with "
                          "qcow-create"));
@@ -1460,8 +1461,8 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
                                                     openflags)) < 0)
         return ret;
 
-    if (vol->backingStore.path &&
-        (ret = virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
+    if (vol->target.backingStore &&
+        (ret = virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
                                                     updateCapacity,
                                                     withBlockVolFormat,
                                                     VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0)
index 76da96a4386e13be2c699b94a4ec8bf40afcefa0..55ed1be0741cc4228bfc08cbf48e02c7b1eb5930 100644 (file)
@@ -890,10 +890,13 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
             vol->type = VIR_STORAGE_VOL_DIR;
 
         if (backingStore != NULL) {
-            vol->backingStore.path = backingStore;
-            vol->backingStore.format = backingStoreFormat;
+            if (VIR_ALLOC(vol->target.backingStore) < 0)
+                goto cleanup;
+
+            vol->target.backingStore->path = backingStore;
+            vol->target.backingStore->format = backingStoreFormat;
 
-            ignore_value(virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
+            ignore_value(virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
                                                               true, false,
                                                               VIR_STORAGE_VOL_OPEN_DEFAULT));
             /* If this failed, the backing file is currently unavailable,
index 76d2461cf1ca1dfb56f80df904399dbaa1c6b972..0f8f0f34f8fb50d51d9b66fa76be92211c226e48 100644 (file)
@@ -246,6 +246,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     virStorageSourcePtr meta = NULL;
     char *header = NULL;
     ssize_t len = VIR_STORAGE_MAX_HEADER;
+    int backingFormat;
 
     *volptr = NULL;
 
@@ -295,16 +296,23 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
 
     if (!(meta = virStorageFileGetMetadataFromBuf(name, header, len,
                                                   VIR_STORAGE_FILE_AUTO,
-                                                  &vol->backingStore.format)))
+                                                  &backingFormat)))
         goto cleanup;
 
-    vol->backingStore.path = meta->backingStoreRaw;
-    meta->backingStoreRaw = NULL;
+    if (meta->backingStoreRaw) {
+        if (VIR_ALLOC(vol->target.backingStore) < 0)
+            goto cleanup;
+
+        vol->target.backingStore->path = meta->backingStoreRaw;
+
+        if (backingFormat < 0)
+            vol->target.backingStore->format = VIR_STORAGE_FILE_RAW;
+        else
+            vol->target.backingStore->format = backingFormat;
+        meta->backingStoreRaw = NULL;
+    }
 
     vol->target.format = meta->format;
-    if (vol->backingStore.path &&
-        vol->backingStore.format < 0)
-        vol->backingStore.format = VIR_STORAGE_FILE_RAW;
     if (meta->capacity)
         vol->target.capacity = meta->capacity;
     if (meta->encryption) {
index faa9a4b7f24c766b03638c98124dd301b442a756..60ad5f2f55ccdce674927f2d73fba211df876989 100644 (file)
@@ -139,11 +139,14 @@ virStorageBackendLogicalMakeVol(char **const groups,
      *  lv is created with "--virtualsize").
      */
     if (groups[1] && !STREQ(groups[1], "") && (groups[1][0] != '[')) {
-        if (virAsprintf(&vol->backingStore.path, "%s/%s",
+        if (VIR_ALLOC(vol->target.backingStore) < 0)
+            goto cleanup;
+
+        if (virAsprintf(&vol->target.backingStore->path, "%s/%s",
                         pool->def->target.path, groups[1]) < 0)
             goto cleanup;
 
-        vol->backingStore.format = VIR_STORAGE_POOL_LOGICAL_LVM2;
+        vol->target.backingStore->format = VIR_STORAGE_POOL_LOGICAL_LVM2;
     }
 
     if (!vol->key && VIR_STRDUP(vol->key, groups[2]) < 0)
@@ -752,8 +755,8 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
     }
     virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.capacity,
                                                     1024));
-    if (vol->backingStore.path)
-        virCommandAddArgList(cmd, "-s", vol->backingStore.path, NULL);
+    if (vol->target.backingStore)
+        virCommandAddArgList(cmd, "-s", vol->target.backingStore->path, NULL);
     else
         virCommandAddArg(cmd, pool->def->source.name);