Hi,
I was looking at the StorageManagerImpl.storagePoolHasEnoughSpace method
(partially listed right below).
It doesn't seem like this would work.
First, it collects all of the used space of the storage pool from the capacity
manager and stores it in allocatedSizeWithtemplate.
Next, it loops through all volumes we want to newly add to the pool.
For each volume, it checks to see if there is an associated template.
Now...I'm assuming in this list of volumes, at most one can be associated with
a template because - otherwise - we will just keep overwriting the
allocatedSizeWithtemplate variable with the latest call to
CapacityManagerImpl.getAllocatedPoolCapacity.
Assuming that's correct (at most one volume is actually associated with a
template), if you look at the implementation of getAllocatedPoolCapacity, it
doesn't seem to do anything useful with the template that's passed into it.
It has a bit of logic in an "if" statement concerning the template. However, it
doesn't really matter how the "if" statement resolves (true or false). In
either case, it still collects the size of the template we are currently
iterating over and adds this size to totalAllocatedSize, which is eventually
returned.
I'm thinking the intent was to add the size of templateForVmCreation to
totalAllocatedSize if templateForVmCreation was not encountered in
templatePoolVOs.
That would seem to make sense because I believe the intent is to discover how
much space would be needed in the storage pool for the new template (and then
there's other code in StoragePoolImpl that adds on the size of the new volume).
Can anyone confirm or deny this for me?
Thanks!
Mike
StoragePoolImpl - Part of storagePoolHasEnoughSpace
// allocated space includes template of specified volume
StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
long allocatedSizeWithtemplate =
_capacityMgr.getAllocatedPoolCapacity(poolVO, null);
long totalAskingSize = 0;
for (Volume volume : volumes) {
if (volume.getTemplateId() != null) {
VMTemplateVO tmpl =
_templateDao.findByIdIncludingRemoved(volume.getTemplateId());
if (tmpl != null && tmpl.getFormat() != ImageFormat.ISO) {
allocatedSizeWithtemplate =
_capacityMgr.getAllocatedPoolCapacity(poolVO, tmpl);
}
}
if (volume.getState() != Volume.State.Ready) {
totalAskingSize = totalAskingSize +
getVolumeSizeIncludingHypervisorSnapshotReserve(volume, pool);
}
}
CapacityManagerImpl.getAllocatedPoolCapacity
@Override
public long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO
templateForVmCreation) {
long totalAllocatedSize = 0;
// if the storage pool is managed, the used bytes can be larger than
the sum of the sizes of all of the non-destroyed volumes
// in this case, call getUsedBytes(StoragePoolVO)
if (pool.isManaged()) {
return getUsedBytes(pool);
}
else {
// Get size for all the non-destroyed volumes
Pair<Long, Long> sizes =
_volumeDao.getNonDestroyedCountAndTotalByPool(pool.getId());
totalAllocatedSize = sizes.second() + sizes.first() *
_extraBytesPerVolume;
}
// Get size for VM Snapshots
totalAllocatedSize = totalAllocatedSize +
_volumeDao.getVMSnapshotSizeByPool(pool.getId());
// Iterate through all templates on this storage pool
boolean tmpinstalled = false;
List<VMTemplateStoragePoolVO> templatePoolVOs;
templatePoolVOs = _templatePoolDao.listByPoolId(pool.getId());
for (VMTemplateStoragePoolVO templatePoolVO : templatePoolVOs) {
if ((templateForVmCreation != null) && !tmpinstalled &&
(templatePoolVO.getTemplateId() == templateForVmCreation.getId())) {
tmpinstalled = true;
}
long templateSize = templatePoolVO.getTemplateSize();
totalAllocatedSize += templateSize + _extraBytesPerVolume;
}
return totalAllocatedSize;
}