From deb701b7e09f486b233bba6372878fa4a9f0d93b Mon Sep 17 00:00:00 2001 From: Koushik Das Date: Thu, 25 Jul 2013 17:10:20 +0530 Subject: [PATCH] CLOUDSTACK-3493: [storage ref] Attach volume to VM is failing in case of Primary-Localstorage . Some existing scenarios for root and data volume combination was not working. These are a. Local root + Shared data b. Shared root + Local data Enabled these scenarios as part of this fix --- .../engine/subsystem/api/storage/HostScope.java | 9 +++++++-- .../engine/subsystem/api/storage/ScopeTest.java | 6 +++--- .../storage/datastore/PrimaryDataStoreImpl.java | 2 +- .../src/com/cloud/storage/StorageManagerImpl.java | 2 +- .../src/com/cloud/storage/VolumeManagerImpl.java | 14 +++++++++++++- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java index 1ff381872e6..6e0bc618bfe 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java @@ -22,11 +22,13 @@ import com.cloud.storage.ScopeType; public class HostScope extends AbstractScope { private Long hostId; + private Long clusterId; private Long zoneId; - public HostScope(Long hostId, Long zoneId) { + public HostScope(Long hostId, Long clusterId, Long zoneId) { super(); this.hostId = hostId; + this.clusterId = clusterId; this.zoneId = zoneId; } @@ -40,8 +42,11 @@ public class HostScope extends AbstractScope { return this.hostId; } + public Long getClusterId() { + return clusterId; + } + public Long getZoneId() { return zoneId; } - } diff --git a/engine/api/test/org/apache/cloudstack/engine/subsystem/api/storage/ScopeTest.java b/engine/api/test/org/apache/cloudstack/engine/subsystem/api/storage/ScopeTest.java index 4b6b361ba07..473877f9610 100644 --- a/engine/api/test/org/apache/cloudstack/engine/subsystem/api/storage/ScopeTest.java +++ b/engine/api/test/org/apache/cloudstack/engine/subsystem/api/storage/ScopeTest.java @@ -48,9 +48,9 @@ public class ScopeTest { @Test public void testHostScope() { - HostScope hostScope = new HostScope(1L, 1L); - HostScope hostScope2 = new HostScope(1L, 1L); - HostScope hostScope3 = new HostScope(2L, 1L); + HostScope hostScope = new HostScope(1L, 1L, 1L); + HostScope hostScope2 = new HostScope(1L, 1L, 1L); + HostScope hostScope3 = new HostScope(2L, 1L, 1L); Assert.assertTrue(hostScope.isSameScope(hostScope2)); Assert.assertFalse(hostScope.isSameScope(hostScope3)); diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java index 420fd2922f4..b20d53443ce 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java @@ -159,7 +159,7 @@ public class PrimaryDataStoreImpl implements PrimaryDataStore { } else if (vo.getScope() == ScopeType.HOST) { List poolHosts = poolHostDao.listByPoolId(vo.getId()); if (poolHosts.size() > 0) { - return new HostScope(poolHosts.get(0).getHostId(), vo.getDataCenterId()); + return new HostScope(poolHosts.get(0).getHostId(), vo.getClusterId(), vo.getDataCenterId()); } s_logger.debug("can't find a local storage in pool host table: " + vo.getId()); } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index cd966cdd565..40117512457 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -625,7 +625,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); } - HostScope scope = new HostScope(host.getId(), host.getDataCenterId()); + HostScope scope = new HostScope(host.getId(), host.getClusterId(), host.getDataCenterId()); lifeCycle.attachHost(store, scope, pInfo); } catch (Exception e) { s_logger.warn("Unable to setup the local storage pool for " + host, e); diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index c4ffc1b4161..c2d581b33c8 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -34,7 +34,6 @@ import javax.naming.ConfigurationException; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; - import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd; import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd; @@ -49,6 +48,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; +import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo; import org.apache.cloudstack.engine.subsystem.api.storage.Scope; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; @@ -1589,6 +1589,18 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { } if (storeForRootStoreScope.getScopeType() != storeForDataStoreScope.getScopeType()) { + if (storeForDataStoreScope.getScopeType() == ScopeType.CLUSTER && storeForRootStoreScope.getScopeType() == ScopeType.HOST) { + HostScope hs = (HostScope)storeForRootStoreScope; + if (storeForDataStoreScope.getScopeId().equals(hs.getClusterId())) { + return false; + } + } + if (storeForRootStoreScope.getScopeType() == ScopeType.CLUSTER && storeForDataStoreScope.getScopeType() == ScopeType.HOST) { + HostScope hs = (HostScope)storeForDataStoreScope; + if (storeForRootStoreScope.getScopeId().equals(hs.getClusterId())) { + return false; + } + } throw new CloudRuntimeException("Can't move volume between scope: " + storeForDataStoreScope.getScopeType() + " and " + storeForRootStoreScope.getScopeType()); }