conf: track sizes directly in source struct

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.
This commit is contained in:
Eric Blake 2014-04-01 17:43:36 -06:00
parent df17611525
commit cce2410a27
21 changed files with 114 additions and 109 deletions

View File

@ -1317,17 +1317,17 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
_("missing capacity element")); _("missing capacity element"));
goto error; goto error;
} }
if (virStorageSize(unit, capacity, &ret->capacity) < 0) if (virStorageSize(unit, capacity, &ret->target.capacity) < 0)
goto error; goto error;
VIR_FREE(unit); VIR_FREE(unit);
allocation = virXPathString("string(./allocation)", ctxt); allocation = virXPathString("string(./allocation)", ctxt);
if (allocation) { if (allocation) {
unit = virXPathString("string(./allocation/@unit)", ctxt); unit = virXPathString("string(./allocation/@unit)", ctxt);
if (virStorageSize(unit, allocation, &ret->allocation) < 0) if (virStorageSize(unit, allocation, &ret->target.allocation) < 0)
goto error; goto error;
} else { } else {
ret->allocation = ret->capacity; ret->target.allocation = ret->target.capacity;
} }
ret->target.path = virXPathString("string(./target/path)", ctxt); ret->target.path = virXPathString("string(./target/path)", ctxt);
@ -1644,9 +1644,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
virBufferAddLit(&buf, "</source>\n"); virBufferAddLit(&buf, "</source>\n");
virBufferAsprintf(&buf, "<capacity unit='bytes'>%llu</capacity>\n", virBufferAsprintf(&buf, "<capacity unit='bytes'>%llu</capacity>\n",
def->capacity); def->target.capacity);
virBufferAsprintf(&buf, "<allocation unit='bytes'>%llu</allocation>\n", virBufferAsprintf(&buf, "<allocation unit='bytes'>%llu</allocation>\n",
def->allocation); def->target.allocation);
if (virStorageVolTargetDefFormat(options, &buf, if (virStorageVolTargetDefFormat(options, &buf,
&def->target, "target") < 0) &def->target, "target") < 0)

View File

@ -65,9 +65,6 @@ struct _virStorageVolDef {
unsigned int building; unsigned int building;
unsigned long long allocation; /* bytes */
unsigned long long capacity; /* bytes */
virStorageVolSource source; virStorageVolSource source;
virStorageSource target; virStorageSource target;
virStorageSource backingStore; virStorageSource backingStore;

View File

@ -1,6 +1,7 @@
/* /*
* esx_storage_backend_iscsi.c: ESX storage backend for iSCSI handling * 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@hotmail.com> * Copyright (C) 2012 Ata E Husain Bohra <ata.husain@hotmail.com>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -677,10 +678,10 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
def.target.path = hostScsiDisk->devicePath; def.target.path = hostScsiDisk->devicePath;
def.capacity = hostScsiDisk->capacity->block->value * def.target.capacity = hostScsiDisk->capacity->block->value *
hostScsiDisk->capacity->blockSize->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 */ /* iSCSI LUN(s) hosting a datastore will be auto-mounted by ESX host */
def.target.format = VIR_STORAGE_FILE_RAW; def.target.format = VIR_STORAGE_FILE_RAW;

View File

@ -2,7 +2,7 @@
* esx_storage_backend_vmfs.c: ESX storage driver backend for * esx_storage_backend_vmfs.c: ESX storage driver backend for
* managing VMFS datastores * 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@googlemail.com> * Copyright (C) 2010-2012 Matthias Bolte <matthias.bolte@googlemail.com>
* Copyright (C) 2012 Ata E Husain Bohra <ata.husain@hotmail.com> * Copyright (C) 2012 Ata E Husain Bohra <ata.husain@hotmail.com>
* *
@ -954,13 +954,13 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
} }
/* From the vSphere API documentation about VirtualDiskType ... */ /* 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 * "A preallocated disk has all space allocated at creation time
* and the space is zeroed on demand as the space is used." * and the space is zeroed on demand as the space is used."
*/ */
virtualDiskSpec->diskType = (char *)"preallocated"; virtualDiskSpec->diskType = (char *)"preallocated";
} else if (def->allocation == 0) { } else if (def->target.allocation == 0) {
/* /*
* "Space required for thin-provisioned virtual disk is allocated * "Space required for thin-provisioned virtual disk is allocated
* and zeroed on demand as the space is used." * and zeroed on demand as the space is used."
@ -980,7 +980,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
virtualDiskSpec->adapterType = (char *)"busLogic"; virtualDiskSpec->adapterType = (char *)"busLogic";
virtualDiskSpec->capacityKb->value = 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 if (esxVI_CreateVirtualDisk_Task
(priv->primary, datastorePath, (priv->primary, datastorePath,
@ -1424,18 +1424,18 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
if (vmDiskFileInfo) { if (vmDiskFileInfo) {
/* Scale from kilobyte to byte */ /* Scale from kilobyte to byte */
def.capacity = vmDiskFileInfo->capacityKb->value * 1024; def.target.capacity = vmDiskFileInfo->capacityKb->value * 1024;
def.allocation = vmDiskFileInfo->fileSize->value; def.target.allocation = vmDiskFileInfo->fileSize->value;
def.target.format = VIR_STORAGE_FILE_VMDK; def.target.format = VIR_STORAGE_FILE_VMDK;
} else if (isoImageFileInfo) { } else if (isoImageFileInfo) {
def.capacity = fileInfo->fileSize->value; def.target.capacity = fileInfo->fileSize->value;
def.allocation = fileInfo->fileSize->value; def.target.allocation = fileInfo->fileSize->value;
def.target.format = VIR_STORAGE_FILE_ISO; def.target.format = VIR_STORAGE_FILE_ISO;
} else if (floppyImageFileInfo) { } else if (floppyImageFileInfo) {
def.capacity = fileInfo->fileSize->value; def.target.capacity = fileInfo->fileSize->value;
def.allocation = fileInfo->fileSize->value; def.target.allocation = fileInfo->fileSize->value;
def.target.format = VIR_STORAGE_FILE_RAW; def.target.format = VIR_STORAGE_FILE_RAW;
} else { } else {

View File

@ -1613,7 +1613,7 @@ static int parallelsAddHddByVolume(parallelsDomObjPtr pdom,
virCommandPtr cmd = virCommandNewArgList(PRLCTL, "set", pdom->uuid, virCommandPtr cmd = virCommandNewArgList(PRLCTL, "set", pdom->uuid,
"--device-add", "hdd", NULL); "--device-add", "hdd", NULL);
virCommandAddArgFormat(cmd, "--size=%lluM", voldef->capacity >> 20); virCommandAddArgFormat(cmd, "--size=%lluM", voldef->target.capacity >> 20);
if (!(strbus = parallelsGetDiskBusName(disk->bus))) { if (!(strbus = parallelsGetDiskBusName(disk->bus))) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,

View File

@ -2,7 +2,7 @@
* parallels_storage.c: core driver functions for managing * parallels_storage.c: core driver functions for managing
* Parallels Cloud Server hosts * Parallels Cloud Server hosts
* *
* Copyright (C) 2013 Red Hat, Inc. * Copyright (C) 2013-2014 Red Hat, Inc.
* Copyright (C) 2012 Parallels, Inc. * Copyright (C) 2012 Parallels, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -257,15 +257,15 @@ static int parallelsDiskDescParseNode(xmlDocPtr xml,
ctxt->node = root; ctxt->node = root;
if (virXPathULongLong("string(./Disk_Parameters/Disk_size)", if (virXPathULongLong("string(./Disk_Parameters/Disk_size)",
ctxt, &def->capacity) < 0) { ctxt, &def->target.capacity) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
"%s", _("failed to get disk size from " "%s", _("failed to get disk size from "
"the disk descriptor xml")); "the disk descriptor xml"));
goto cleanup; goto cleanup;
} }
def->capacity <<= 9; def->target.capacity <<= 9;
def->allocation = def->capacity; def->target.allocation = def->target.capacity;
ret = 0; ret = 0;
cleanup: cleanup:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
@ -1218,7 +1218,7 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool,
if (is_new) { if (is_new) {
/* Make sure enough space */ /* Make sure enough space */
if ((pool->def->allocation + privvol->allocation) > if ((pool->def->allocation + privvol->target.allocation) >
pool->def->capacity) { pool->def->capacity) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not enough free space in pool for volume '%s'"), _("Not enough free space in pool for volume '%s'"),
@ -1245,7 +1245,7 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool,
goto cleanup; goto cleanup;
} }
pool->def->allocation += privvol->allocation; pool->def->allocation += privvol->target.allocation;
pool->def->available = (pool->def->capacity - pool->def->available = (pool->def->capacity -
pool->def->allocation); pool->def->allocation);
} }
@ -1349,7 +1349,7 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool,
} }
/* Make sure enough space */ /* Make sure enough space */
if ((privpool->def->allocation + privvol->allocation) > if ((privpool->def->allocation + privvol->target.allocation) >
privpool->def->capacity) { privpool->def->capacity) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not enough free space in pool for volume '%s'"), _("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) if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
goto cleanup; goto cleanup;
privpool->def->allocation += privvol->allocation; privpool->def->allocation += privvol->target.allocation;
privpool->def->available = (privpool->def->capacity - privpool->def->available = (privpool->def->capacity -
privpool->def->allocation); privpool->def->allocation);
@ -1393,7 +1393,7 @@ int parallelsStorageVolDefRemove(virStoragePoolObjPtr privpool,
char *xml_path = NULL; char *xml_path = NULL;
size_t i; size_t i;
privpool->def->allocation -= privvol->allocation; privpool->def->allocation -= privvol->target.allocation;
privpool->def->available = (privpool->def->capacity - privpool->def->available = (privpool->def->capacity -
privpool->def->allocation); privpool->def->allocation);
@ -1516,8 +1516,8 @@ parallelsStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info)
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
info->type = parallelsStorageVolTypeForPool(privpool->def->type); info->type = parallelsStorageVolTypeForPool(privpool->def->type);
info->capacity = privvol->capacity; info->capacity = privvol->target.capacity;
info->allocation = privvol->allocation; info->allocation = privvol->target.allocation;
ret = 0; ret = 0;
cleanup: cleanup:

View File

@ -2007,13 +2007,13 @@ phypStorageVolCreateXML(virStoragePoolPtr pool,
goto err; goto err;
} }
if (!voldef->capacity) { if (!voldef->target.capacity) {
VIR_ERROR(_("Capacity cannot be empty.")); VIR_ERROR(_("Capacity cannot be empty."));
goto err; goto err;
} }
key = phypBuildVolume(pool->conn, voldef->name, spdef->name, key = phypBuildVolume(pool->conn, voldef->name, spdef->name,
voldef->capacity); voldef->target.capacity);
if (key == NULL) if (key == NULL)
goto err; goto err;

View File

@ -287,7 +287,7 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED,
goto cleanup; goto cleanup;
} }
remain = vol->allocation; remain = vol->target.allocation;
if (inputvol) { if (inputvol) {
int res = virStorageBackendCopyToFD(vol, 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 /* Seek to the final size, so the capacity is available upfront
* for progress reporting */ * for progress reporting */
if (ftruncate(fd, vol->capacity) < 0) { if (ftruncate(fd, vol->target.capacity) < 0) {
ret = -errno; ret = -errno;
virReportSystemError(errno, virReportSystemError(errno,
_("cannot extend file '%s'"), _("cannot extend file '%s'"),
@ -361,27 +361,27 @@ createRawFile(int fd, virStorageVolDefPtr vol,
* to writing zeroes block by block in case fallocate isn't * to writing zeroes block by block in case fallocate isn't
* available, and since we're going to copy data from another * available, and since we're going to copy data from another
* file it doesn't make sense to write the file twice. */ * file it doesn't make sense to write the file twice. */
if (vol->allocation) { if (vol->target.allocation) {
if (fallocate(fd, 0, 0, vol->allocation) == 0) { if (fallocate(fd, 0, 0, vol->target.allocation) == 0) {
need_alloc = false; need_alloc = false;
} else if (errno != ENOSYS && errno != EOPNOTSUPP) { } else if (errno != ENOSYS && errno != EOPNOTSUPP) {
ret = -errno; ret = -errno;
virReportSystemError(errno, virReportSystemError(errno,
_("cannot allocate %llu bytes in file '%s'"), _("cannot allocate %llu bytes in file '%s'"),
vol->allocation, vol->target.path); vol->target.allocation, vol->target.path);
goto cleanup; goto cleanup;
} }
} }
#endif #endif
remain = vol->allocation; remain = vol->target.allocation;
if (inputvol) { if (inputvol) {
/* allow zero blocks to be skipped if we've requested sparse /* allow zero blocks to be skipped if we've requested sparse
* allocation (allocation < capacity) or we have already * allocation (allocation < capacity) or we have already
* been able to allocate the required space. */ * been able to allocate the required space. */
bool want_sparse = !need_alloc || bool want_sparse = !need_alloc ||
(vol->allocation < inputvol->capacity); (vol->target.allocation < inputvol->target.capacity);
ret = virStorageBackendCopyToFD(vol, inputvol, fd, &remain, want_sparse); ret = virStorageBackendCopyToFD(vol, inputvol, fd, &remain, want_sparse);
if (ret < 0) { if (ret < 0) {
@ -390,7 +390,7 @@ createRawFile(int fd, virStorageVolDefPtr vol,
} }
if (remain && need_alloc) { if (remain && need_alloc) {
if (safezero(fd, vol->allocation - remain, remain) < 0) { if (safezero(fd, vol->target.allocation - remain, remain) < 0) {
ret = -errno; ret = -errno;
virReportSystemError(errno, _("cannot fill file '%s'"), virReportSystemError(errno, _("cannot fill file '%s'"),
vol->target.path); vol->target.path);
@ -924,7 +924,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
} }
/* Size in KB */ /* Size in KB */
size_arg = VIR_DIV_UP(vol->capacity, 1024); size_arg = VIR_DIV_UP(vol->target.capacity, 1024);
cmd = virCommandNew(create_tool); cmd = virCommandNew(create_tool);
@ -1070,7 +1070,7 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
/* Size in MB - yes different units to qemu-img :-( */ /* Size in MB - yes different units to qemu-img :-( */
if (virAsprintf(&size, "%llu", if (virAsprintf(&size, "%llu",
VIR_DIV_UP(vol->capacity, (1024 * 1024))) < 0) VIR_DIV_UP(vol->target.capacity, (1024 * 1024))) < 0)
return -1; return -1;
cmd = virCommandNewArgList("qcow-create", size, vol->target.path, NULL); cmd = virCommandNewArgList("qcow-create", size, vol->target.path, NULL);
@ -1424,8 +1424,8 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
int ret; int ret;
if ((ret = virStorageBackendUpdateVolTargetInfo(&vol->target, if ((ret = virStorageBackendUpdateVolTargetInfo(&vol->target,
&vol->allocation, &vol->target.allocation,
withCapacity ? &vol->capacity : NULL, withCapacity ? &vol->target.capacity : NULL,
withBlockVolFormat, withBlockVolFormat,
openflags)) < 0) openflags)) < 0)
return ret; return ret;

View File

@ -131,11 +131,11 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
/* The above gets allocation wrong for /* The above gets allocation wrong for
* extended partitions, so overwrite it */ * 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); (vol->source.extents[0].end - vol->source.extents[0].start);
if (STRNEQ(groups[2], "metadata")) 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) if (vol->source.extents[0].end > pool->def->capacity)
pool->def->capacity = vol->source.extents[0].end; pool->def->capacity = vol->source.extents[0].end;
@ -649,7 +649,7 @@ virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
if (virStorageBackendDiskPartBoundaries(pool, &startOffset, if (virStorageBackendDiskPartBoundaries(pool, &startOffset,
&endOffset, &endOffset,
vol->capacity) != 0) { vol->target.capacity) != 0) {
goto cleanup; goto cleanup;
} }

View File

@ -880,8 +880,8 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
if ((ret = virStorageBackendProbeTarget(&vol->target, if ((ret = virStorageBackendProbeTarget(&vol->target,
&backingStore, &backingStore,
&backingStoreFormat, &backingStoreFormat,
&vol->allocation, &vol->target.allocation,
&vol->capacity, &vol->target.capacity,
&vol->target.encryption)) < 0) { &vol->target.encryption)) < 0) {
if (ret == -2) { if (ret == -2) {
/* Silently ignore non-regular files, /* Silently ignore non-regular files,
@ -1280,7 +1280,7 @@ virStorageBackendFileSystemVolResize(virConnectPtr conn ATTRIBUTE_UNUSED,
if (vol->target.format == VIR_STORAGE_FILE_RAW) { if (vol->target.format == VIR_STORAGE_FILE_RAW) {
return virStorageFileResize(vol->target.path, capacity, return virStorageFileResize(vol->target.path, capacity,
vol->allocation, pre_allocate); vol->target.allocation, pre_allocate);
} else { } else {
if (pre_allocate) { if (pre_allocate) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",

View File

@ -268,8 +268,8 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
goto cleanup; goto cleanup;
if (virStorageBackendUpdateVolTargetInfoFD(&vol->target, -1, st, if (virStorageBackendUpdateVolTargetInfoFD(&vol->target, -1, st,
&vol->allocation, &vol->target.allocation,
&vol->capacity) < 0) &vol->target.capacity) < 0)
goto cleanup; goto cleanup;
if (virStorageBackendGlusterSetMetadata(state, vol, name) < 0) if (virStorageBackendGlusterSetMetadata(state, vol, name) < 0)
@ -311,7 +311,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
vol->backingStore.format = VIR_STORAGE_FILE_RAW; vol->backingStore.format = VIR_STORAGE_FILE_RAW;
} }
if (meta->capacity) if (meta->capacity)
vol->capacity = meta->capacity; vol->target.capacity = meta->capacity;
if (meta->encrypted) { if (meta->encrypted) {
if (VIR_ALLOC(vol->target.encryption) < 0) if (VIR_ALLOC(vol->target.encryption) < 0)
goto cleanup; goto cleanup;

View File

@ -177,7 +177,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
"%s", _("malformed volume extent size value")); "%s", _("malformed volume extent size value"));
goto cleanup; 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, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed volume allocation value")); "%s", _("malformed volume allocation value"));
goto cleanup; goto cleanup;
@ -744,12 +744,14 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
"--name", vol->name, "--name", vol->name,
NULL); NULL);
virCommandAddArg(cmd, "-L"); virCommandAddArg(cmd, "-L");
if (vol->capacity != vol->allocation) { if (vol->target.capacity != vol->target.allocation) {
virCommandAddArgFormat(cmd, "%lluK", 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"); 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) if (vol->backingStore.path)
virCommandAddArgList(cmd, "-s", vol->backingStore.path, NULL); virCommandAddArgList(cmd, "-s", vol->backingStore.path, NULL);
else else

View File

@ -1,7 +1,7 @@
/* /*
* storage_backend_mpath.c: storage backend for multipath handling * 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 * Copyright (C) 2009-2008 Dave Allan
* *
* This library is free software; you can redistribute it and/or * 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) if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, vol) < 0)
goto cleanup; goto cleanup;
pool->def->capacity += vol->capacity; pool->def->capacity += vol->target.capacity;
pool->def->allocation += vol->allocation; pool->def->allocation += vol->target.allocation;
ret = 0; ret = 0;
cleanup: cleanup:

View File

@ -1,7 +1,7 @@
/* /*
* storage_backend_rbd.c: storage backend for RBD (RADOS Block Device) handling * 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 * Copyright (C) 2012 Wido den Hollander
* *
* This library is free software; you can redistribute it and/or * 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.obj_size,
(unsigned long long)info.num_objs); (unsigned long long)info.num_objs);
vol->capacity = info.size; vol->target.capacity = info.size;
vol->allocation = info.obj_size * info.num_objs; vol->target.allocation = info.obj_size * info.num_objs;
vol->type = VIR_STORAGE_VOL_NETWORK; vol->type = VIR_STORAGE_VOL_NETWORK;
VIR_FREE(vol->target.path); VIR_FREE(vol->target.path);
@ -516,7 +516,7 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,
VIR_DEBUG("Creating RBD image %s/%s with size %llu", VIR_DEBUG("Creating RBD image %s/%s with size %llu",
pool->def->source.name, pool->def->source.name,
vol->name, vol->capacity); vol->name, vol->target.capacity);
virCheckFlags(0, -1); virCheckFlags(0, -1);
@ -532,7 +532,8 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
r = virStorageBackendRBDCreateImage(ptr.ioctx, vol->name, vol->capacity); r = virStorageBackendRBDCreateImage(ptr.ioctx, vol->name,
vol->target.capacity);
if (r < 0) { if (r < 0) {
virReportSystemError(-r, _("failed to create volume '%s/%s'"), virReportSystemError(-r, _("failed to create volume '%s/%s'"),
pool->def->source.name, pool->def->source.name,

View File

@ -213,8 +213,8 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
goto free_vol; goto free_vol;
} }
pool->def->capacity += vol->capacity; pool->def->capacity += vol->target.capacity;
pool->def->allocation += vol->allocation; pool->def->allocation += vol->target.allocation;
if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) { if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) {
retval = -1; retval = -1;

View File

@ -1,7 +1,7 @@
/* /*
* storage_backend_sheepdog.c: storage backend for Sheepdog handling * 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 Wido den Hollander
* Copyright (C) 2012 Frank Spijkerman * Copyright (C) 2012 Frank Spijkerman
* Copyright (C) 2012 Sebastian Wiedenroth * Copyright (C) 2012 Sebastian Wiedenroth
@ -267,7 +267,7 @@ virStorageBackendSheepdogBuildVol(virConnectPtr conn,
virCheckFlags(0, -1); virCheckFlags(0, -1);
virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "create", vol->name, NULL); virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "create", vol->name, NULL);
virCommandAddArgFormat(cmd, "%llu", vol->capacity); virCommandAddArgFormat(cmd, "%llu", vol->target.capacity);
virStorageBackendSheepdogAddHostArg(cmd, pool); virStorageBackendSheepdogAddHostArg(cmd, pool);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; goto cleanup;
@ -298,7 +298,7 @@ virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
int id; int id;
const char *p, *next; const char *p, *next;
vol->allocation = vol->capacity = 0; vol->target.allocation = vol->target.capacity = 0;
p = output; p = output;
do { do {
@ -329,12 +329,12 @@ virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
p = end + 1; p = end + 1;
if (virStrToLong_ull(p, &end, 10, &vol->capacity) < 0) if (virStrToLong_ull(p, &end, 10, &vol->target.capacity) < 0)
return -1; return -1;
p = end + 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 -1;
return 0; return 0;

View File

@ -1613,8 +1613,8 @@ storageVolDelete(virStorageVolPtr obj,
goto cleanup; goto cleanup;
/* Update pool metadata */ /* Update pool metadata */
pool->def->allocation -= vol->allocation; pool->def->allocation -= vol->target.allocation;
pool->def->available += vol->allocation; pool->def->available += vol->target.allocation;
for (i = 0; i < pool->volumes.count; i++) { for (i = 0; i < pool->volumes.count; i++) {
if (pool->volumes.objs[i] == vol) { if (pool->volumes.objs[i] == vol) {
@ -1747,8 +1747,8 @@ storageVolCreateXML(virStoragePoolPtr obj,
} }
/* Update pool metadata */ /* Update pool metadata */
pool->def->allocation += buildvoldef->allocation; pool->def->allocation += buildvoldef->target.allocation;
pool->def->available -= buildvoldef->allocation; pool->def->available -= buildvoldef->target.allocation;
VIR_INFO("Creating volume '%s' in storage pool '%s'", VIR_INFO("Creating volume '%s' in storage pool '%s'",
volobj->name, pool->def->name); volobj->name, pool->def->name);
@ -1841,13 +1841,13 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
} }
/* Is there ever a valid case for this? */ /* Is there ever a valid case for this? */
if (newvol->capacity < origvol->capacity) if (newvol->target.capacity < origvol->target.capacity)
newvol->capacity = origvol->capacity; newvol->target.capacity = origvol->target.capacity;
/* Make sure allocation is at least as large as the destination cap, /* Make sure allocation is at least as large as the destination cap,
* to make absolutely sure we copy all possible contents */ * to make absolutely sure we copy all possible contents */
if (newvol->allocation < origvol->capacity) if (newvol->target.allocation < origvol->target.capacity)
newvol->allocation = origvol->capacity; newvol->target.allocation = origvol->target.capacity;
if (!backend->buildVolFrom) { if (!backend->buildVolFrom) {
virReportError(VIR_ERR_NO_SUPPORT, virReportError(VIR_ERR_NO_SUPPORT,
@ -1907,7 +1907,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
origvol->building = 0; origvol->building = 0;
newvol->building = 0; newvol->building = 0;
allocation = newvol->allocation; allocation = newvol->target.allocation;
newvol = NULL; newvol = NULL;
pool->asyncjobs--; pool->asyncjobs--;
@ -2152,20 +2152,20 @@ storageVolResize(virStorageVolPtr obj,
} }
if (flags & VIR_STORAGE_VOL_RESIZE_DELTA) { if (flags & VIR_STORAGE_VOL_RESIZE_DELTA) {
abs_capacity = vol->capacity + capacity; abs_capacity = vol->target.capacity + capacity;
flags &= ~VIR_STORAGE_VOL_RESIZE_DELTA; flags &= ~VIR_STORAGE_VOL_RESIZE_DELTA;
} else { } else {
abs_capacity = capacity; abs_capacity = capacity;
} }
if (abs_capacity < vol->allocation) { if (abs_capacity < vol->target.allocation) {
virReportError(VIR_ERR_INVALID_ARG, "%s", virReportError(VIR_ERR_INVALID_ARG, "%s",
_("can't shrink capacity below " _("can't shrink capacity below "
"existing allocation")); "existing allocation"));
goto cleanup; goto cleanup;
} }
if (abs_capacity < vol->capacity && if (abs_capacity < vol->target.capacity &&
!(flags & VIR_STORAGE_VOL_RESIZE_SHRINK)) { !(flags & VIR_STORAGE_VOL_RESIZE_SHRINK)) {
virReportError(VIR_ERR_INVALID_ARG, "%s", virReportError(VIR_ERR_INVALID_ARG, "%s",
_("Can't shrink capacity below current " _("Can't shrink capacity below current "
@ -2173,7 +2173,7 @@ storageVolResize(virStorageVolPtr obj,
goto cleanup; 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", virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("Not enough space left on storage pool")); _("Not enough space left on storage pool"));
goto cleanup; goto cleanup;
@ -2189,13 +2189,13 @@ storageVolResize(virStorageVolPtr obj,
if (backend->resizeVol(obj->conn, pool, vol, abs_capacity, flags) < 0) if (backend->resizeVol(obj->conn, pool, vol, abs_capacity, flags) < 0)
goto cleanup; goto cleanup;
vol->capacity = abs_capacity; vol->target.capacity = abs_capacity;
if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE) if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE)
vol->allocation = abs_capacity; vol->target.allocation = abs_capacity;
/* Update pool metadata */ /* Update pool metadata */
pool->def->allocation += (abs_capacity - vol->capacity); pool->def->allocation += (abs_capacity - vol->target.capacity);
pool->def->available -= (abs_capacity - vol->capacity); pool->def->available -= (abs_capacity - vol->target.capacity);
ret = 0; ret = 0;
@ -2388,7 +2388,7 @@ storageVolWipeInternal(virStorageVolDefPtr def,
ret = storageWipeExtent(def, ret = storageWipeExtent(def,
fd, fd,
0, 0,
def->allocation, def->target.allocation,
writebuf, writebuf,
st.st_blksize, st.st_blksize,
&bytes_wiped); &bytes_wiped);
@ -2529,8 +2529,8 @@ storageVolGetInfo(virStorageVolPtr obj,
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
info->type = vol->type; info->type = vol->type;
info->capacity = vol->capacity; info->capacity = vol->target.capacity;
info->allocation = vol->allocation; info->allocation = vol->target.allocation;
ret = 0; ret = 0;
cleanup: cleanup:

View File

@ -1260,7 +1260,7 @@ testOpenVolumesForPool(const char *file,
if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, def) < 0) if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, def) < 0)
goto error; goto error;
pool->def->allocation += def->allocation; pool->def->allocation += def->target.allocation;
pool->def->available = (pool->def->capacity - pool->def->available = (pool->def->capacity -
pool->def->allocation); pool->def->allocation);
def = NULL; def = NULL;
@ -5511,7 +5511,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
} }
/* Make sure enough space */ /* Make sure enough space */
if ((privpool->def->allocation + privvol->allocation) > if ((privpool->def->allocation + privvol->target.allocation) >
privpool->def->capacity) { privpool->def->capacity) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not enough free space in pool for volume '%s'"), _("Not enough free space in pool for volume '%s'"),
@ -5529,7 +5529,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
privpool->volumes.count, privvol) < 0) privpool->volumes.count, privvol) < 0)
goto cleanup; goto cleanup;
privpool->def->allocation += privvol->allocation; privpool->def->allocation += privvol->target.allocation;
privpool->def->available = (privpool->def->capacity - privpool->def->available = (privpool->def->capacity -
privpool->def->allocation); privpool->def->allocation);
@ -5593,7 +5593,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
} }
/* Make sure enough space */ /* Make sure enough space */
if ((privpool->def->allocation + privvol->allocation) > if ((privpool->def->allocation + privvol->target.allocation) >
privpool->def->capacity) { privpool->def->capacity) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not enough free space in pool for volume '%s'"), _("Not enough free space in pool for volume '%s'"),
@ -5613,7 +5613,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
privpool->volumes.count, privvol) < 0) privpool->volumes.count, privvol) < 0)
goto cleanup; goto cleanup;
privpool->def->allocation += privvol->allocation; privpool->def->allocation += privvol->target.allocation;
privpool->def->available = (privpool->def->capacity - privpool->def->available = (privpool->def->capacity -
privpool->def->allocation); 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->available = (privpool->def->capacity -
privpool->def->allocation); privpool->def->allocation);
@ -5738,8 +5738,8 @@ testStorageVolGetInfo(virStorageVolPtr vol,
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
info->type = testStorageVolumeTypeForPool(privpool->def->type); info->type = testStorageVolumeTypeForPool(privpool->def->type);
info->capacity = privvol->capacity; info->capacity = privvol->target.capacity;
info->allocation = privvol->allocation; info->allocation = privvol->target.allocation;
ret = 0; ret = 0;
cleanup: cleanup:

View File

@ -234,6 +234,8 @@ struct _virStorageSource {
virStoragePermsPtr perms; virStoragePermsPtr perms;
virStorageTimestampsPtr timestamps; virStorageTimestampsPtr timestamps;
unsigned long long allocation; /* in bytes, 0 if unknown */
unsigned long long capacity; /* in bytes, 0 if unknown */
size_t nseclabels; size_t nseclabels;
virSecurityDeviceLabelDefPtr *seclabels; virSecurityDeviceLabelDefPtr *seclabels;
}; };

View File

@ -8786,10 +8786,11 @@ static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
rc = data->vboxObj->vtbl->CreateHardDisk(data->vboxObj, hddFormatUtf16, hddNameUtf16, &hardDisk); rc = data->vboxObj->vtbl->CreateHardDisk(data->vboxObj, hddFormatUtf16, hddNameUtf16, &hardDisk);
if (NS_SUCCEEDED(rc)) { if (NS_SUCCEEDED(rc)) {
IProgress *progress = NULL; 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; PRUint32 variant = HardDiskVariant_Standard;
if (def->capacity == def->allocation) if (def->target.capacity == def->target.allocation)
variant = HardDiskVariant_Fixed; variant = HardDiskVariant_Fixed;
#if VBOX_API_VERSION < 4003000 #if VBOX_API_VERSION < 4003000
@ -9142,16 +9143,16 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
rc = hardDisk->vtbl->GetLogicalSize(hardDisk, &hddLogicalSize); rc = hardDisk->vtbl->GetLogicalSize(hardDisk, &hddLogicalSize);
if (NS_SUCCEEDED(rc) && defOk) { if (NS_SUCCEEDED(rc) && defOk) {
#if VBOX_API_VERSION < 4000000 #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 */ #else /* VBOX_API_VERSION >= 4000000 */
def.capacity = hddLogicalSize; def.target.capacity = hddLogicalSize;
#endif /* VBOX_API_VERSION >= 4000000 */ #endif /* VBOX_API_VERSION >= 4000000 */
} else } else
defOk = 0; defOk = 0;
rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetSize, &hddActualSize); rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetSize, &hddActualSize);
if (NS_SUCCEEDED(rc) && defOk) if (NS_SUCCEEDED(rc) && defOk)
def.allocation = hddActualSize; def.target.allocation = hddActualSize;
else else
defOk = 0; defOk = 0;

View File

@ -1,6 +1,7 @@
/* /*
* storagebackendsheepdogtest.c: storage backend for Sheepdog handling * storagebackendsheepdogtest.c: storage backend for Sheepdog handling
* *
* Copyright (C) 2014 Red Hat, Inc.
* Copyright (C) 2012 Sebastian Wiedenroth * Copyright (C) 2012 Sebastian Wiedenroth
* *
* This library is free software; you can redistribute it and/or * 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; goto cleanup;
} }
if (vol->capacity == test.expected_capacity && if (vol->target.capacity == test.expected_capacity &&
vol->allocation == test.expected_allocation) vol->target.allocation == test.expected_allocation)
ret = 0; ret = 0;
cleanup: cleanup: