Skip to content

Commit deb701b

Browse files
committed
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
1 parent 76e2836 commit deb701b

5 files changed

Lines changed: 25 additions & 8 deletions

File tree

‎engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
public class HostScope extends AbstractScope {
2424
private Long hostId;
25+
private Long clusterId;
2526
private Long zoneId;
2627

27-
public HostScope(Long hostId, Long zoneId) {
28+
public HostScope(Long hostId, Long clusterId, Long zoneId) {
2829
super();
2930
this.hostId = hostId;
31+
this.clusterId = clusterId;
3032
this.zoneId = zoneId;
3133
}
3234

@@ -40,8 +42,11 @@ public Long getScopeId() {
4042
return this.hostId;
4143
}
4244

45+
public Long getClusterId() {
46+
return clusterId;
47+
}
48+
4349
public Long getZoneId() {
4450
return zoneId;
4551
}
46-
4752
}

‎engine/api/test/org/apache/cloudstack/engine/subsystem/api/storage/ScopeTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public void testClusterScope() {
4848

4949
@Test
5050
public void testHostScope() {
51-
HostScope hostScope = new HostScope(1L, 1L);
52-
HostScope hostScope2 = new HostScope(1L, 1L);
53-
HostScope hostScope3 = new HostScope(2L, 1L);
51+
HostScope hostScope = new HostScope(1L, 1L, 1L);
52+
HostScope hostScope2 = new HostScope(1L, 1L, 1L);
53+
HostScope hostScope3 = new HostScope(2L, 1L, 1L);
5454

5555
Assert.assertTrue(hostScope.isSameScope(hostScope2));
5656
Assert.assertFalse(hostScope.isSameScope(hostScope3));

‎engine/storage/volume/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public Scope getScope() {
159159
} else if (vo.getScope() == ScopeType.HOST) {
160160
List<StoragePoolHostVO> poolHosts = poolHostDao.listByPoolId(vo.getId());
161161
if (poolHosts.size() > 0) {
162-
return new HostScope(poolHosts.get(0).getHostId(), vo.getDataCenterId());
162+
return new HostScope(poolHosts.get(0).getHostId(), vo.getClusterId(), vo.getDataCenterId());
163163
}
164164
s_logger.debug("can't find a local storage in pool host table: " + vo.getId());
165165
}

‎server/src/com/cloud/storage/StorageManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws Con
625625
store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
626626
}
627627

628-
HostScope scope = new HostScope(host.getId(), host.getDataCenterId());
628+
HostScope scope = new HostScope(host.getId(), host.getClusterId(), host.getDataCenterId());
629629
lifeCycle.attachHost(store, scope, pInfo);
630630
} catch (Exception e) {
631631
s_logger.warn("Unable to setup the local storage pool for " + host, e);

‎server/src/com/cloud/storage/VolumeManagerImpl.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.apache.commons.lang.StringUtils;
3535
import org.apache.log4j.Logger;
3636
import org.springframework.stereotype.Component;
37-
3837
import org.apache.cloudstack.api.BaseCmd;
3938
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
4039
import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
@@ -49,6 +48,7 @@
4948
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
5049
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
5150
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
51+
import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
5252
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
5353
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
5454
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
@@ -1589,6 +1589,18 @@ private boolean needMoveVolume(VolumeVO rootVolumeOfVm, VolumeInfo volume) {
15891589
}
15901590

15911591
if (storeForRootStoreScope.getScopeType() != storeForDataStoreScope.getScopeType()) {
1592+
if (storeForDataStoreScope.getScopeType() == ScopeType.CLUSTER && storeForRootStoreScope.getScopeType() == ScopeType.HOST) {
1593+
HostScope hs = (HostScope)storeForRootStoreScope;
1594+
if (storeForDataStoreScope.getScopeId().equals(hs.getClusterId())) {
1595+
return false;
1596+
}
1597+
}
1598+
if (storeForRootStoreScope.getScopeType() == ScopeType.CLUSTER && storeForDataStoreScope.getScopeType() == ScopeType.HOST) {
1599+
HostScope hs = (HostScope)storeForDataStoreScope;
1600+
if (storeForRootStoreScope.getScopeId().equals(hs.getClusterId())) {
1601+
return false;
1602+
}
1603+
}
15921604
throw new CloudRuntimeException("Can't move volume between scope: " + storeForDataStoreScope.getScopeType() + " and " + storeForRootStoreScope.getScopeType());
15931605
}
15941606

0 commit comments

Comments
 (0)