Skip to content

Commit a831ad1

Browse files
committed
Fix detach volume on stopped Vms
1 parent d119a5d commit a831ad1

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,31 +2054,35 @@ private Volume orchestrateDetachVolumeFromVM(long vmId, long volumeId) {
20542054
if (!sendCommand || (answer != null && answer.getResult())) {
20552055
// Mark the volume as detached
20562056
_volsDao.detachVolume(volume.getId());
2057-
String datastoreName = answer.getContextParam("datastoreName");
2058-
if (datastoreName != null) {
2059-
StoragePoolVO storagePoolVO = _storagePoolDao.findByUuid(datastoreName);
2060-
if (storagePoolVO != null) {
2057+
2058+
if (answer != null) {
2059+
String datastoreName = answer.getContextParam("datastoreName");
2060+
if (datastoreName != null) {
2061+
StoragePoolVO storagePoolVO = _storagePoolDao.findByUuid(datastoreName);
2062+
if (storagePoolVO != null) {
2063+
VolumeVO volumeVO = _volsDao.findById(volumeId);
2064+
volumeVO.setPoolId(storagePoolVO.getId());
2065+
_volsDao.update(volumeVO.getId(), volumeVO);
2066+
} else {
2067+
s_logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreName, volumeId));
2068+
}
2069+
}
2070+
2071+
String volumePath = answer.getContextParam("volumePath");
2072+
if (volumePath != null) {
20612073
VolumeVO volumeVO = _volsDao.findById(volumeId);
2062-
volumeVO.setPoolId(storagePoolVO.getId());
2074+
volumeVO.setPath(volumePath);
20632075
_volsDao.update(volumeVO.getId(), volumeVO);
2064-
} else {
2065-
s_logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreName, volumeId));
20662076
}
2067-
}
20682077

2069-
String volumePath = answer.getContextParam("volumePath");
2070-
if (volumePath != null) {
2071-
VolumeVO volumeVO = _volsDao.findById(volumeId);
2072-
volumeVO.setPath(volumePath);
2073-
_volsDao.update(volumeVO.getId(), volumeVO);
2078+
String chainInfo = answer.getContextParam("chainInfo");
2079+
if (chainInfo != null) {
2080+
VolumeVO volumeVO = _volsDao.findById(volumeId);
2081+
volumeVO.setChainInfo(chainInfo);
2082+
_volsDao.update(volumeVO.getId(), volumeVO);
2083+
}
20742084
}
20752085

2076-
String chainInfo = answer.getContextParam("chainInfo");
2077-
if (chainInfo != null) {
2078-
VolumeVO volumeVO = _volsDao.findById(volumeId);
2079-
volumeVO.setChainInfo(chainInfo);
2080-
_volsDao.update(volumeVO.getId(), volumeVO);
2081-
}
20822086
// volume.getPoolId() should be null if the VM we are detaching the disk from has never been started before
20832087
if (volume.getPoolId() != null) {
20842088
DataStore dataStore = dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary);

0 commit comments

Comments
 (0)