[PATCHv2 5/7] conf: track sizes directly in source struct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile.  As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file.  This sets up the fields for
the tracking, although it does not modify XML to display any
new information.

* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
---
 src/conf/storage_conf.c                | 10 ++++-----
 src/conf/storage_conf.h                |  3 ---
 src/esx/esx_storage_backend_iscsi.c    |  5 +++--
 src/esx/esx_storage_backend_vmfs.c     | 20 ++++++++---------
 src/parallels/parallels_driver.c       |  2 +-
 src/parallels/parallels_storage.c      | 22 +++++++++----------
 src/phyp/phyp_driver.c                 |  4 ++--
 src/storage/storage_backend.c          | 24 ++++++++++----------
 src/storage/storage_backend_disk.c     |  6 ++---
 src/storage/storage_backend_fs.c       |  6 ++---
 src/storage/storage_backend_gluster.c  |  6 ++---
 src/storage/storage_backend_logical.c  | 10 +++++----
 src/storage/storage_backend_mpath.c    |  6 ++---
 src/storage/storage_backend_rbd.c      | 11 +++++-----
 src/storage/storage_backend_scsi.c     |  4 ++--
 src/storage/storage_backend_sheepdog.c | 10 ++++-----
 src/storage/storage_driver.c           | 40 +++++++++++++++++-----------------
 src/test/test_driver.c                 | 16 +++++++-------
 src/util/virstoragefile.h              |  2 ++
 src/vbox/vbox_tmpl.c                   | 11 +++++-----
 tests/storagebackendsheepdogtest.c     |  5 +++--
 21 files changed, 114 insertions(+), 109 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index a96f4d6..ebd42c2 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1317,17 +1317,17 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
                        _("missing capacity element"));
         goto error;
     }
-    if (virStorageSize(unit, capacity, &ret->capacity) < 0)
+    if (virStorageSize(unit, capacity, &ret->target.capacity) < 0)
         goto error;
     VIR_FREE(unit);

     allocation = virXPathString("string(./allocation)", ctxt);
     if (allocation) {
         unit = virXPathString("string(./allocation/@unit)", ctxt);
-        if (virStorageSize(unit, allocation, &ret->allocation) < 0)
+        if (virStorageSize(unit, allocation, &ret->target.allocation) < 0)
             goto error;
     } else {
-        ret->allocation = ret->capacity;
+        ret->target.allocation = ret->target.capacity;
     }

     ret->target.path = virXPathString("string(./target/path)", ctxt);
@@ -1644,9 +1644,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
     virBufferAddLit(&buf, "</source>\n");

     virBufferAsprintf(&buf, "<capacity unit='bytes'>%llu</capacity>\n",
-                      def->capacity);
+                      def->target.capacity);
     virBufferAsprintf(&buf, "<allocation unit='bytes'>%llu</allocation>\n",
-                      def->allocation);
+                      def->target.allocation);

     if (virStorageVolTargetDefFormat(options, &buf,
                                      &def->target, "target") < 0)
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 66b5a3b..9ad38e1 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -65,9 +65,6 @@ struct _virStorageVolDef {

     unsigned int building;

-    unsigned long long allocation; /* bytes */
-    unsigned long long capacity; /* bytes */
-
     virStorageVolSource source;
     virStorageSource target;
     virStorageSource backingStore;
diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c
index bd9f3b4..5509429 100644
--- a/src/esx/esx_storage_backend_iscsi.c
+++ b/src/esx/esx_storage_backend_iscsi.c
@@ -1,6 +1,7 @@
 /*
  * esx_storage_backend_iscsi.c: ESX storage backend for iSCSI handling
  *
+ * Copyright (C) 2014 Red Hat, Inc.
  * Copyright (C) 2012 Ata E Husain Bohra <ata.husain@xxxxxxxxxxx>
  *
  * This library is free software; you can redistribute it and/or
@@ -677,10 +678,10 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,

     def.target.path = hostScsiDisk->devicePath;

-    def.capacity = hostScsiDisk->capacity->block->value *
+    def.target.capacity = hostScsiDisk->capacity->block->value *
                    hostScsiDisk->capacity->blockSize->value;

-    def.allocation = def.capacity;
+    def.target.allocation = def.target.capacity;

     /* iSCSI LUN(s) hosting a datastore will be auto-mounted by ESX host */
     def.target.format = VIR_STORAGE_FILE_RAW;
diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index db4d480..6bed3ce 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -2,7 +2,7 @@
  * esx_storage_backend_vmfs.c: ESX storage driver backend for
  *                             managing VMFS datastores
  *
- * Copyright (C) 2010-2011, 2013 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
  * Copyright (C) 2010-2012 Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>
  * Copyright (C) 2012 Ata E Husain Bohra <ata.husain@xxxxxxxxxxx>
  *
@@ -954,13 +954,13 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
         }

         /* From the vSphere API documentation about VirtualDiskType ... */
-        if (def->allocation == def->capacity) {
+        if (def->target.allocation == def->target.capacity) {
             /*
              * "A preallocated disk has all space allocated at creation time
              *  and the space is zeroed on demand as the space is used."
              */
             virtualDiskSpec->diskType = (char *)"preallocated";
-        } else if (def->allocation == 0) {
+        } else if (def->target.allocation == 0) {
             /*
              * "Space required for thin-provisioned virtual disk is allocated
              *  and zeroed on demand as the space is used."
@@ -980,7 +980,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
         virtualDiskSpec->adapterType = (char *)"busLogic";

         virtualDiskSpec->capacityKb->value =
-          VIR_DIV_UP(def->capacity, 1024); /* Scale from byte to kilobyte */
+          VIR_DIV_UP(def->target.capacity, 1024); /* Scale from byte to kilobyte */

         if (esxVI_CreateVirtualDisk_Task
               (priv->primary, datastorePath,
@@ -1424,18 +1424,18 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,

     if (vmDiskFileInfo) {
         /* Scale from kilobyte to byte */
-        def.capacity = vmDiskFileInfo->capacityKb->value * 1024;
-        def.allocation = vmDiskFileInfo->fileSize->value;
+        def.target.capacity = vmDiskFileInfo->capacityKb->value * 1024;
+        def.target.allocation = vmDiskFileInfo->fileSize->value;

         def.target.format = VIR_STORAGE_FILE_VMDK;
     } else if (isoImageFileInfo) {
-        def.capacity = fileInfo->fileSize->value;
-        def.allocation = fileInfo->fileSize->value;
+        def.target.capacity = fileInfo->fileSize->value;
+        def.target.allocation = fileInfo->fileSize->value;

         def.target.format = VIR_STORAGE_FILE_ISO;
     } else if (floppyImageFileInfo) {
-        def.capacity = fileInfo->fileSize->value;
-        def.allocation = fileInfo->fileSize->value;
+        def.target.capacity = fileInfo->fileSize->value;
+        def.target.allocation = fileInfo->fileSize->value;

         def.target.format = VIR_STORAGE_FILE_RAW;
     } else {
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index a0d5f8c..848ed9f 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1613,7 +1613,7 @@ static int parallelsAddHddByVolume(parallelsDomObjPtr pdom,

     virCommandPtr cmd = virCommandNewArgList(PRLCTL, "set", pdom->uuid,
                                              "--device-add", "hdd", NULL);
-    virCommandAddArgFormat(cmd, "--size=%lluM", voldef->capacity >> 20);
+    virCommandAddArgFormat(cmd, "--size=%lluM", voldef->target.capacity >> 20);

     if (!(strbus = parallelsGetDiskBusName(disk->bus))) {
         virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c
index e1579d2..736d060 100644
--- a/src/parallels/parallels_storage.c
+++ b/src/parallels/parallels_storage.c
@@ -2,7 +2,7 @@
  * parallels_storage.c: core driver functions for managing
  * Parallels Cloud Server hosts
  *
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (C) 2013-2014 Red Hat, Inc.
  * Copyright (C) 2012 Parallels, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -257,15 +257,15 @@ static int parallelsDiskDescParseNode(xmlDocPtr xml,
     ctxt->node = root;

     if (virXPathULongLong("string(./Disk_Parameters/Disk_size)",
-                          ctxt, &def->capacity) < 0) {
+                          ctxt, &def->target.capacity) < 0) {
         virReportError(VIR_ERR_XML_ERROR,
                        "%s", _("failed to get disk size from "
                                "the disk descriptor xml"));
         goto cleanup;
     }

-    def->capacity <<= 9;
-    def->allocation = def->capacity;
+    def->target.capacity <<= 9;
+    def->target.allocation = def->target.capacity;
     ret = 0;
  cleanup:
     xmlXPathFreeContext(ctxt);
@@ -1218,7 +1218,7 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool,

     if (is_new) {
         /* Make sure enough space */
-        if ((pool->def->allocation + privvol->allocation) >
+        if ((pool->def->allocation + privvol->target.allocation) >
             pool->def->capacity) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Not enough free space in pool for volume '%s'"),
@@ -1245,7 +1245,7 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool,
             goto cleanup;
         }

-        pool->def->allocation += privvol->allocation;
+        pool->def->allocation += privvol->target.allocation;
         pool->def->available = (pool->def->capacity -
                                 pool->def->allocation);
     }
@@ -1349,7 +1349,7 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool,
     }

     /* Make sure enough space */
-    if ((privpool->def->allocation + privvol->allocation) >
+    if ((privpool->def->allocation + privvol->target.allocation) >
         privpool->def->capacity) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Not enough free space in pool for volume '%s'"),
@@ -1366,7 +1366,7 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool,
     if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
         goto cleanup;

-    privpool->def->allocation += privvol->allocation;
+    privpool->def->allocation += privvol->target.allocation;
     privpool->def->available = (privpool->def->capacity -
                                 privpool->def->allocation);

@@ -1393,7 +1393,7 @@ int parallelsStorageVolDefRemove(virStoragePoolObjPtr privpool,
     char *xml_path = NULL;
     size_t i;

-    privpool->def->allocation -= privvol->allocation;
+    privpool->def->allocation -= privvol->target.allocation;
     privpool->def->available = (privpool->def->capacity -
                                 privpool->def->allocation);

@@ -1516,8 +1516,8 @@ parallelsStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info)

     memset(info, 0, sizeof(*info));
     info->type = parallelsStorageVolTypeForPool(privpool->def->type);
-    info->capacity = privvol->capacity;
-    info->allocation = privvol->allocation;
+    info->capacity = privvol->target.capacity;
+    info->allocation = privvol->target.allocation;
     ret = 0;

  cleanup:
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 3a5eefd..508e4c0 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -2007,13 +2007,13 @@ phypStorageVolCreateXML(virStoragePoolPtr pool,
         goto err;
     }

-    if (!voldef->capacity) {
+    if (!voldef->target.capacity) {
         VIR_ERROR(_("Capacity cannot be empty."));
         goto err;
     }

     key = phypBuildVolume(pool->conn, voldef->name, spdef->name,
-                          voldef->capacity);
+                          voldef->target.capacity);

     if (key == NULL)
         goto err;
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 9abaccd..c8cf50e 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -287,7 +287,7 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED,
         goto cleanup;
     }

-    remain = vol->allocation;
+    remain = vol->target.allocation;

     if (inputvol) {
         int res = virStorageBackendCopyToFD(vol, inputvol,
@@ -344,7 +344,7 @@ createRawFile(int fd, virStorageVolDefPtr vol,

     /* Seek to the final size, so the capacity is available upfront
      * for progress reporting */
-    if (ftruncate(fd, vol->capacity) < 0) {
+    if (ftruncate(fd, vol->target.capacity) < 0) {
         ret = -errno;
         virReportSystemError(errno,
                              _("cannot extend file '%s'"),
@@ -361,27 +361,27 @@ createRawFile(int fd, virStorageVolDefPtr vol,
      * to writing zeroes block by block in case fallocate isn't
      * available, and since we're going to copy data from another
      * file it doesn't make sense to write the file twice. */
-    if (vol->allocation) {
-        if (fallocate(fd, 0, 0, vol->allocation) == 0) {
+    if (vol->target.allocation) {
+        if (fallocate(fd, 0, 0, vol->target.allocation) == 0) {
             need_alloc = false;
         } else if (errno != ENOSYS && errno != EOPNOTSUPP) {
             ret = -errno;
             virReportSystemError(errno,
                                  _("cannot allocate %llu bytes in file '%s'"),
-                                 vol->allocation, vol->target.path);
+                                 vol->target.allocation, vol->target.path);
             goto cleanup;
         }
     }
 #endif

-    remain = vol->allocation;
+    remain = vol->target.allocation;

     if (inputvol) {
         /* allow zero blocks to be skipped if we've requested sparse
          * allocation (allocation < capacity) or we have already
          * been able to allocate the required space. */
         bool want_sparse = !need_alloc ||
-                           (vol->allocation < inputvol->capacity);
+            (vol->target.allocation < inputvol->target.capacity);

         ret = virStorageBackendCopyToFD(vol, inputvol, fd, &remain, want_sparse);
         if (ret < 0) {
@@ -390,7 +390,7 @@ createRawFile(int fd, virStorageVolDefPtr vol,
     }

     if (remain && need_alloc) {
-        if (safezero(fd, vol->allocation - remain, remain) < 0) {
+        if (safezero(fd, vol->target.allocation - remain, remain) < 0) {
             ret = -errno;
             virReportSystemError(errno, _("cannot fill file '%s'"),
                                  vol->target.path);
@@ -924,7 +924,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
     }

     /* Size in KB */
-    size_arg = VIR_DIV_UP(vol->capacity, 1024);
+    size_arg = VIR_DIV_UP(vol->target.capacity, 1024);

     cmd = virCommandNew(create_tool);

@@ -1070,7 +1070,7 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED,

     /* Size in MB - yes different units to qemu-img :-( */
     if (virAsprintf(&size, "%llu",
-                    VIR_DIV_UP(vol->capacity, (1024 * 1024))) < 0)
+                    VIR_DIV_UP(vol->target.capacity, (1024 * 1024))) < 0)
         return -1;

     cmd = virCommandNewArgList("qcow-create", size, vol->target.path, NULL);
@@ -1424,8 +1424,8 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
     int ret;

     if ((ret = virStorageBackendUpdateVolTargetInfo(&vol->target,
-                                    &vol->allocation,
-                                    withCapacity ? &vol->capacity : NULL,
+                                    &vol->target.allocation,
+                                    withCapacity ? &vol->target.capacity : NULL,
                                     withBlockVolFormat,
                                     openflags)) < 0)
         return ret;
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 01f1b17..13336fc 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -131,11 +131,11 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,

     /* The above gets allocation wrong for
      * extended partitions, so overwrite it */
-    vol->allocation = vol->capacity =
+    vol->target.allocation = vol->target.capacity =
         (vol->source.extents[0].end - vol->source.extents[0].start);

     if (STRNEQ(groups[2], "metadata"))
-        pool->def->allocation += vol->allocation;
+        pool->def->allocation += vol->target.allocation;
     if (vol->source.extents[0].end > pool->def->capacity)
         pool->def->capacity = vol->source.extents[0].end;

@@ -649,7 +649,7 @@ virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,

     if (virStorageBackendDiskPartBoundaries(pool, &startOffset,
                                             &endOffset,
-                                            vol->capacity) != 0) {
+                                            vol->target.capacity) != 0) {
         goto cleanup;
     }

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 113593b..e8617cb 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -880,8 +880,8 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
         if ((ret = virStorageBackendProbeTarget(&vol->target,
                                                 &backingStore,
                                                 &backingStoreFormat,
-                                                &vol->allocation,
-                                                &vol->capacity,
+                                                &vol->target.allocation,
+                                                &vol->target.capacity,
                                                 &vol->target.encryption)) < 0) {
             if (ret == -2) {
                 /* Silently ignore non-regular files,
@@ -1280,7 +1280,7 @@ virStorageBackendFileSystemVolResize(virConnectPtr conn ATTRIBUTE_UNUSED,

     if (vol->target.format == VIR_STORAGE_FILE_RAW) {
         return virStorageFileResize(vol->target.path, capacity,
-                                    vol->allocation, pre_allocate);
+                                    vol->target.allocation, pre_allocate);
     } else {
         if (pre_allocate) {
             virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 19e6a3b..6eed3ec 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -268,8 +268,8 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
         goto cleanup;

     if (virStorageBackendUpdateVolTargetInfoFD(&vol->target, -1, st,
-                                               &vol->allocation,
-                                               &vol->capacity) < 0)
+                                               &vol->target.allocation,
+                                               &vol->target.capacity) < 0)
         goto cleanup;

     if (virStorageBackendGlusterSetMetadata(state, vol, name) < 0)
@@ -311,7 +311,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
             vol->backingStore.format = VIR_STORAGE_FILE_RAW;
     }
     if (meta->capacity)
-        vol->capacity = meta->capacity;
+        vol->target.capacity = meta->capacity;
     if (meta->encrypted) {
         if (VIR_ALLOC(vol->target.encryption) < 0)
             goto cleanup;
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index aea624e..a597e67 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -177,7 +177,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
                        "%s", _("malformed volume extent size value"));
         goto cleanup;
     }
-    if (virStrToLong_ull(groups[8], NULL, 10, &vol->allocation) < 0) {
+    if (virStrToLong_ull(groups[8], NULL, 10, &vol->target.allocation) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("malformed volume allocation value"));
         goto cleanup;
@@ -744,12 +744,14 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
                                "--name", vol->name,
                                NULL);
     virCommandAddArg(cmd, "-L");
-    if (vol->capacity != vol->allocation) {
+    if (vol->target.capacity != vol->target.allocation) {
         virCommandAddArgFormat(cmd, "%lluK",
-                VIR_DIV_UP(vol->allocation ? vol->allocation : 1, 1024));
+                               VIR_DIV_UP(vol->target.allocation
+                                          ? vol->target.allocation : 1, 1024));
         virCommandAddArg(cmd, "--virtualsize");
     }
-    virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->capacity, 1024));
+    virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.capacity,
+                                                    1024));
     if (vol->backingStore.path)
         virCommandAddArgList(cmd, "-s", vol->backingStore.path, NULL);
     else
diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c
index 1242150..8c3b0df 100644
--- a/src/storage/storage_backend_mpath.c
+++ b/src/storage/storage_backend_mpath.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend_mpath.c: storage backend for multipath handling
  *
- * Copyright (C) 2009-2011, 2013 Red Hat, Inc.
+ * Copyright (C) 2009-2014 Red Hat, Inc.
  * Copyright (C) 2009-2008 Dave Allan
  *
  * This library is free software; you can redistribute it and/or
@@ -71,8 +71,8 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,

     if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, vol) < 0)
         goto cleanup;
-    pool->def->capacity += vol->capacity;
-    pool->def->allocation += vol->allocation;
+    pool->def->capacity += vol->target.capacity;
+    pool->def->allocation += vol->target.allocation;
     ret = 0;

  cleanup:
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 34e6f45..029d2f0 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend_rbd.c: storage backend for RBD (RADOS Block Device) handling
  *
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (C) 2013-2014 Red Hat, Inc.
  * Copyright (C) 2012 Wido den Hollander
  *
  * This library is free software; you can redistribute it and/or
@@ -300,8 +300,8 @@ static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
               (unsigned long long)info.obj_size,
               (unsigned long long)info.num_objs);

-    vol->capacity = info.size;
-    vol->allocation = info.obj_size * info.num_objs;
+    vol->target.capacity = info.size;
+    vol->target.allocation = info.obj_size * info.num_objs;
     vol->type = VIR_STORAGE_VOL_NETWORK;

     VIR_FREE(vol->target.path);
@@ -516,7 +516,7 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,

     VIR_DEBUG("Creating RBD image %s/%s with size %llu",
               pool->def->source.name,
-              vol->name, vol->capacity);
+              vol->name, vol->target.capacity);

     virCheckFlags(0, -1);

@@ -532,7 +532,8 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,
         goto cleanup;
     }

-    r = virStorageBackendRBDCreateImage(ptr.ioctx, vol->name, vol->capacity);
+    r = virStorageBackendRBDCreateImage(ptr.ioctx, vol->name,
+                                        vol->target.capacity);
     if (r < 0) {
         virReportSystemError(-r, _("failed to create volume '%s/%s'"),
                              pool->def->source.name,
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index 4c2484d..6652a6a 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -213,8 +213,8 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
         goto free_vol;
     }

-    pool->def->capacity += vol->capacity;
-    pool->def->allocation += vol->allocation;
+    pool->def->capacity += vol->target.capacity;
+    pool->def->allocation += vol->target.allocation;

     if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) {
         retval = -1;
diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
index df86916..9419859 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend_sheepdog.c: storage backend for Sheepdog handling
  *
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (C) 2013-2014 Red Hat, Inc.
  * Copyright (C) 2012 Wido den Hollander
  * Copyright (C) 2012 Frank Spijkerman
  * Copyright (C) 2012 Sebastian Wiedenroth
@@ -267,7 +267,7 @@ virStorageBackendSheepdogBuildVol(virConnectPtr conn,
     virCheckFlags(0, -1);

     virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "create", vol->name, NULL);
-    virCommandAddArgFormat(cmd, "%llu", vol->capacity);
+    virCommandAddArgFormat(cmd, "%llu", vol->target.capacity);
     virStorageBackendSheepdogAddHostArg(cmd, pool);
     if (virCommandRun(cmd, NULL) < 0)
         goto cleanup;
@@ -298,7 +298,7 @@ virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
     int id;
     const char *p, *next;

-    vol->allocation = vol->capacity = 0;
+    vol->target.allocation = vol->target.capacity = 0;

     p = output;
     do {
@@ -329,12 +329,12 @@ virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,

         p = end + 1;

-        if (virStrToLong_ull(p, &end, 10, &vol->capacity) < 0)
+        if (virStrToLong_ull(p, &end, 10, &vol->target.capacity) < 0)
             return -1;

         p = end + 1;

-        if (virStrToLong_ull(p, &end, 10, &vol->allocation) < 0)
+        if (virStrToLong_ull(p, &end, 10, &vol->target.allocation) < 0)
             return -1;

         return 0;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 6fca3d2..2f98f78 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1613,8 +1613,8 @@ storageVolDelete(virStorageVolPtr obj,
         goto cleanup;

     /* Update pool metadata */
-    pool->def->allocation -= vol->allocation;
-    pool->def->available += vol->allocation;
+    pool->def->allocation -= vol->target.allocation;
+    pool->def->available += vol->target.allocation;

     for (i = 0; i < pool->volumes.count; i++) {
         if (pool->volumes.objs[i] == vol) {
@@ -1747,8 +1747,8 @@ storageVolCreateXML(virStoragePoolPtr obj,
     }

     /* Update pool metadata */
-    pool->def->allocation += buildvoldef->allocation;
-    pool->def->available -= buildvoldef->allocation;
+    pool->def->allocation += buildvoldef->target.allocation;
+    pool->def->available -= buildvoldef->target.allocation;

     VIR_INFO("Creating volume '%s' in storage pool '%s'",
              volobj->name, pool->def->name);
@@ -1841,13 +1841,13 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
     }

     /* Is there ever a valid case for this? */
-    if (newvol->capacity < origvol->capacity)
-        newvol->capacity = origvol->capacity;
+    if (newvol->target.capacity < origvol->target.capacity)
+        newvol->target.capacity = origvol->target.capacity;

     /* Make sure allocation is at least as large as the destination cap,
      * to make absolutely sure we copy all possible contents */
-    if (newvol->allocation < origvol->capacity)
-        newvol->allocation = origvol->capacity;
+    if (newvol->target.allocation < origvol->target.capacity)
+        newvol->target.allocation = origvol->target.capacity;

     if (!backend->buildVolFrom) {
         virReportError(VIR_ERR_NO_SUPPORT,
@@ -1907,7 +1907,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,

     origvol->building = 0;
     newvol->building = 0;
-    allocation = newvol->allocation;
+    allocation = newvol->target.allocation;
     newvol = NULL;
     pool->asyncjobs--;

@@ -2152,20 +2152,20 @@ storageVolResize(virStorageVolPtr obj,
     }

     if (flags & VIR_STORAGE_VOL_RESIZE_DELTA) {
-        abs_capacity = vol->capacity + capacity;
+        abs_capacity = vol->target.capacity + capacity;
         flags &= ~VIR_STORAGE_VOL_RESIZE_DELTA;
     } else {
         abs_capacity = capacity;
     }

-    if (abs_capacity < vol->allocation) {
+    if (abs_capacity < vol->target.allocation) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("can't shrink capacity below "
                          "existing allocation"));
         goto cleanup;
     }

-    if (abs_capacity < vol->capacity &&
+    if (abs_capacity < vol->target.capacity &&
         !(flags & VIR_STORAGE_VOL_RESIZE_SHRINK)) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("Can't shrink capacity below current "
@@ -2173,7 +2173,7 @@ storageVolResize(virStorageVolPtr obj,
         goto cleanup;
     }

-    if (abs_capacity > vol->capacity + pool->def->available) {
+    if (abs_capacity > vol->target.capacity + pool->def->available) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                        _("Not enough space left on storage pool"));
         goto cleanup;
@@ -2189,13 +2189,13 @@ storageVolResize(virStorageVolPtr obj,
     if (backend->resizeVol(obj->conn, pool, vol, abs_capacity, flags) < 0)
         goto cleanup;

-    vol->capacity = abs_capacity;
+    vol->target.capacity = abs_capacity;
     if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE)
-        vol->allocation = abs_capacity;
+        vol->target.allocation = abs_capacity;

     /* Update pool metadata */
-    pool->def->allocation += (abs_capacity - vol->capacity);
-    pool->def->available -= (abs_capacity - vol->capacity);
+    pool->def->allocation += (abs_capacity - vol->target.capacity);
+    pool->def->available -= (abs_capacity - vol->target.capacity);

     ret = 0;

@@ -2388,7 +2388,7 @@ storageVolWipeInternal(virStorageVolDefPtr def,
             ret = storageWipeExtent(def,
                                     fd,
                                     0,
-                                    def->allocation,
+                                    def->target.allocation,
                                     writebuf,
                                     st.st_blksize,
                                     &bytes_wiped);
@@ -2529,8 +2529,8 @@ storageVolGetInfo(virStorageVolPtr obj,

     memset(info, 0, sizeof(*info));
     info->type = vol->type;
-    info->capacity = vol->capacity;
-    info->allocation = vol->allocation;
+    info->capacity = vol->target.capacity;
+    info->allocation = vol->target.allocation;
     ret = 0;

  cleanup:
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index ef88d4b..77e30b2 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1260,7 +1260,7 @@ testOpenVolumesForPool(const char *file,
         if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, def) < 0)
             goto error;

-        pool->def->allocation += def->allocation;
+        pool->def->allocation += def->target.allocation;
         pool->def->available = (pool->def->capacity -
                                 pool->def->allocation);
         def = NULL;
@@ -5511,7 +5511,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
     }

     /* Make sure enough space */
-    if ((privpool->def->allocation + privvol->allocation) >
+    if ((privpool->def->allocation + privvol->target.allocation) >
          privpool->def->capacity) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Not enough free space in pool for volume '%s'"),
@@ -5529,7 +5529,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
                                 privpool->volumes.count, privvol) < 0)
         goto cleanup;

-    privpool->def->allocation += privvol->allocation;
+    privpool->def->allocation += privvol->target.allocation;
     privpool->def->available = (privpool->def->capacity -
                                 privpool->def->allocation);

@@ -5593,7 +5593,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
     }

     /* Make sure enough space */
-    if ((privpool->def->allocation + privvol->allocation) >
+    if ((privpool->def->allocation + privvol->target.allocation) >
          privpool->def->capacity) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Not enough free space in pool for volume '%s'"),
@@ -5613,7 +5613,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
                                 privpool->volumes.count, privvol) < 0)
         goto cleanup;

-    privpool->def->allocation += privvol->allocation;
+    privpool->def->allocation += privvol->target.allocation;
     privpool->def->available = (privpool->def->capacity -
                                 privpool->def->allocation);

@@ -5668,7 +5668,7 @@ testStorageVolDelete(virStorageVolPtr vol,
     }


-    privpool->def->allocation -= privvol->allocation;
+    privpool->def->allocation -= privvol->target.allocation;
     privpool->def->available = (privpool->def->capacity -
                                 privpool->def->allocation);

@@ -5738,8 +5738,8 @@ testStorageVolGetInfo(virStorageVolPtr vol,

     memset(info, 0, sizeof(*info));
     info->type = testStorageVolumeTypeForPool(privpool->def->type);
-    info->capacity = privvol->capacity;
-    info->allocation = privvol->allocation;
+    info->capacity = privvol->target.capacity;
+    info->allocation = privvol->target.allocation;
     ret = 0;

  cleanup:
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 00d5456..aa06d41 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -234,6 +234,8 @@ struct _virStorageSource {

     virStoragePermsPtr perms;
     virStorageTimestampsPtr timestamps;
+    unsigned long long allocation; /* in bytes, 0 if unknown */
+    unsigned long long capacity; /* in bytes, 0 if unknown */
     size_t nseclabels;
     virSecurityDeviceLabelDefPtr *seclabels;
 };
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4eed78e..a305fe2 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -8786,10 +8786,11 @@ static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
         rc = data->vboxObj->vtbl->CreateHardDisk(data->vboxObj, hddFormatUtf16, hddNameUtf16, &hardDisk);
         if (NS_SUCCEEDED(rc)) {
             IProgress *progress    = NULL;
-            PRUint64   logicalSize = VIR_DIV_UP(def->capacity, 1024 * 1024);
+            PRUint64   logicalSize = VIR_DIV_UP(def->target.capacity,
+                                                1024 * 1024);
             PRUint32   variant     = HardDiskVariant_Standard;

-            if (def->capacity == def->allocation)
+            if (def->target.capacity == def->target.allocation)
                 variant = HardDiskVariant_Fixed;

 #if VBOX_API_VERSION < 4003000
@@ -9142,16 +9143,16 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
             rc = hardDisk->vtbl->GetLogicalSize(hardDisk, &hddLogicalSize);
             if (NS_SUCCEEDED(rc) && defOk) {
 #if VBOX_API_VERSION < 4000000
-                def.capacity = hddLogicalSize * 1024 * 1024; /* MB => Bytes */
+                def.target.capacity = hddLogicalSize * 1024 * 1024; /* MB => Bytes */
 #else /* VBOX_API_VERSION >= 4000000 */
-                def.capacity = hddLogicalSize;
+                def.target.capacity = hddLogicalSize;
 #endif /* VBOX_API_VERSION >= 4000000 */
             } else
                 defOk = 0;

             rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetSize, &hddActualSize);
             if (NS_SUCCEEDED(rc) && defOk)
-                def.allocation = hddActualSize;
+                def.target.allocation = hddActualSize;
             else
                 defOk = 0;

diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c
index e219acb..14fc76d 100644
--- a/tests/storagebackendsheepdogtest.c
+++ b/tests/storagebackendsheepdogtest.c
@@ -1,6 +1,7 @@
 /*
  * storagebackendsheepdogtest.c: storage backend for Sheepdog handling
  *
+ * Copyright (C) 2014 Red Hat, Inc.
  * Copyright (C) 2012 Sebastian Wiedenroth
  *
  * This library is free software; you can redistribute it and/or
@@ -114,8 +115,8 @@ test_vdi_list_parser(collie_test test, char *poolxml, char *volxml)
         goto cleanup;
     }

-    if (vol->capacity == test.expected_capacity &&
-        vol->allocation == test.expected_allocation)
+    if (vol->target.capacity == test.expected_capacity &&
+        vol->target.allocation == test.expected_allocation)
         ret = 0;

  cleanup:
-- 
1.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]