diff --git a/server/src/com/cloud/storage/allocator/FirstFitStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/FirstFitStoragePoolAllocator.java index 73783bb32e8..e3f23102b9a 100644 --- a/server/src/com/cloud/storage/allocator/FirstFitStoragePoolAllocator.java +++ b/server/src/com/cloud/storage/allocator/FirstFitStoragePoolAllocator.java @@ -26,6 +26,7 @@ import org.apache.log4j.Logger; import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.offering.ServiceOffering; import com.cloud.server.StatsCollector; import com.cloud.storage.StoragePool; import com.cloud.storage.StoragePoolHostVO; @@ -73,23 +74,11 @@ public class FirstFitStoragePoolAllocator extends AbstractStoragePoolAllocator { s_logger.debug("Looking for pools in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId); } - List pools = null; - // volume is shared "or" vm is not known "or" no host associated then go here - if (!dskCh.useLocalStorage() || vmProfile.getVirtualMachine() == null || vmProfile.getVirtualMachine().getHostId() == null) { - pools = _storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags(), !dskCh.useLocalStorage()); - } else { // volume is local and vm host id is known - pools = new ArrayList(); - List hostPools = _poolHostDao.listByHostId(vmProfile.getVirtualMachine().getHostId()); - for (StoragePoolHostVO hostPool: hostPools) { - StoragePoolVO pool = _storagePoolDao.findById(hostPool.getPoolId()); - if (pool != null && pool.isLocal()) { - pools.add(pool); - } - } - } + List pools = _storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags(), null); if (pools.size() == 0) { if (s_logger.isDebugEnabled()) { - s_logger.debug("No storage pools available for " + (dskCh.useLocalStorage() ? "local" : "shared") + " volume allocation, returning"); + String storageType = dskCh.useLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString(); + s_logger.debug("No storage pools available for " + storageType + " volume allocation, returning"); } return suitablePools; } diff --git a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java index 28f28e8fce9..93d93319449 100644 --- a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java +++ b/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java @@ -31,6 +31,8 @@ import com.cloud.offering.ServiceOffering; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.StoragePool; import com.cloud.storage.StoragePoolHostVO; +import com.cloud.storage.StoragePoolVO; +import com.cloud.storage.Volume; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.utils.DateUtil; @@ -97,18 +99,34 @@ public class LocalStoragePoolAllocator extends FirstFitStoragePoolAllocator { s_logger.debug("LocalStoragePoolAllocator trying to find storage pool to fit the vm"); } - List availablePool; - while (!(availablePool = super.allocateToPool(dskCh, vmProfile, plan, myAvoids, 1)).isEmpty()) { - StoragePool pool = availablePool.get(0); - myAvoids.addPool(pool.getId()); - List hostsInSPool = _poolHostDao.listByPoolId(pool.getId()); - assert (hostsInSPool.size() == 1) : "Local storage pool should be one host per pool"; + // data disk and host identified from deploying vm (attach volume case) + if (dskCh.getType() == Volume.Type.DATADISK && vmProfile.getVirtualMachine() != null && vmProfile.getVirtualMachine().getHostId() != null) { + List hostPools = _poolHostDao.listByHostId(vmProfile.getVirtualMachine().getHostId()); + for (StoragePoolHostVO hostPool: hostPools) { + StoragePoolVO pool = _storagePoolDao.findById(hostPool.getPoolId()); + if (pool != null && pool.isLocal()) { + s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list"); + suitablePools.add(pool); + } - s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list"); - suitablePools.add(pool); + if (suitablePools.size() == returnUpTo) { + break; + } + } + } else { + List availablePool; + while (!(availablePool = super.allocateToPool(dskCh, vmProfile, plan, myAvoids, 1)).isEmpty()) { + StoragePool pool = availablePool.get(0); + myAvoids.addPool(pool.getId()); + List hostsInSPool = _poolHostDao.listByPoolId(pool.getId()); + assert (hostsInSPool.size() == 1) : "Local storage pool should be one host per pool"; - if (suitablePools.size() == returnUpTo) { - break; + s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list"); + suitablePools.add(pool); + + if (suitablePools.size() == returnUpTo) { + break; + } } }