Logic around granting and revoking access to the volume that backs the snapshot

This commit is contained in:
Mike Tutkowski 2014-10-19 21:17:54 -06:00
parent 0cea0346ae
commit b29265f159
3 changed files with 49 additions and 6 deletions

View File

@ -35,6 +35,7 @@ public class DiskTO {
public static final String MOUNT_POINT = "mountpoint";
public static final String PROTOCOL_TYPE = "protocoltype";
public static final String PATH = "path";
public static final String VOLUME_ID = "volumeId";
private DataTO data;
private Long diskSeq;

View File

@ -206,8 +206,11 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
sourceDetails = getSourceDetails(volumeInfo);
}
HostVO hostVO = getHostId(hostId, volumeVO);
long storagePoolId = volumeVO.getPoolId();
StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePoolId);
DataStore dataStore = _dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
Map<String, String> destDetails = getDestDetails(storagePoolVO, snapshotInfo);
@ -216,11 +219,49 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
SnapshotAndCopyAnswer snapshotAndCopyAnswer = null;
try {
snapshotAndCopyAnswer = (SnapshotAndCopyAnswer)_agentMgr.send(getHostId(hostId, volumeVO), snapshotAndCopyCommand);
// if sourceDetails != null, we need to connect the host(s) to the volume
if (sourceDetails != null) {
_volService.connectVolumeToHost(volumeInfo, hostVO, dataStore);
}
VolumeVO volume = _volumeDao.findById(volumeInfo.getId());
// the Folder field is used by connectVolumeToHost(VolumeInfo, Host, DataStore) when that method
// connects the host(s) to the volume
// this Folder change is NOT to be written to the DB; it is only temporarily used here so that
// the connect method can be passed in the expected data and do its work (on the volume that backs
// the snapshot)
volume.setFolder(destDetails.get(DiskTO.VOLUME_ID));
_volService.connectVolumeToHost(volumeInfo, hostVO, dataStore);
snapshotAndCopyAnswer = (SnapshotAndCopyAnswer)_agentMgr.send(hostVO.getId(), snapshotAndCopyCommand);
}
catch (Exception e) {
throw new CloudRuntimeException(e.getMessage());
}
finally {
try {
VolumeVO volume = _volumeDao.findById(volumeInfo.getId());
// the Folder field is used by disconnectVolumeFromHost(VolumeInfo, Host, DataStore) when that method
// disconnects the host(s) from the volume
// this Folder change is NOT to be written to the DB; it is only temporarily used here so that
// the disconnect method can be passed in the expected data and do its work (on the volume that backs
// the snapshot)
volume.setFolder(destDetails.get(DiskTO.VOLUME_ID));
_volService.disconnectVolumeFromHost(volumeInfo, hostVO, dataStore);
// if sourceDetails != null, we need to disconnect the host(s) from the volume
if (sourceDetails != null) {
_volService.disconnectVolumeFromHost(volumeInfo, hostVO, dataStore);
}
}
catch (Exception ex) {
s_logger.debug(ex.getMessage(), ex);
}
}
String path = snapshotAndCopyAnswer.getPath(); // for XenServer, this is the VDI's UUID
@ -283,6 +324,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
long snapshotId = snapshotInfo.getId();
destDetails.put(DiskTO.VOLUME_ID, getProperty(snapshotId, DiskTO.VOLUME_ID));
destDetails.put(DiskTO.IQN, getProperty(snapshotId, DiskTO.IQN));
destDetails.put(DiskTO.CHAP_INITIATOR_USERNAME, getProperty(snapshotId, DiskTO.CHAP_INITIATOR_USERNAME));
@ -303,11 +345,11 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
return null;
}
private Long getHostId(Long hostId, VolumeVO volumeVO) {
private HostVO getHostId(Long hostId, VolumeVO volumeVO) {
HostVO hostVO = _hostDao.findById(hostId);
if (hostVO != null) {
return hostId;
return hostVO;
}
// pick a host in any XenServer cluster that's in the applicable zone
@ -327,7 +369,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
if (hosts != null) {
for (HostVO host : hosts) {
if (host.getResourceState() == ResourceState.Enabled) {
return host.getId();
return host;
}
}
}

View File

@ -555,7 +555,7 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
private void updateSnapshotDetails(long csSnapshotId, long sfNewVolumeId, long storagePoolId, long sfNewVolumeSize, String sfNewVolumeIqn) {
SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(csSnapshotId,
SolidFireUtil.VOLUME_ID,
DiskTO.VOLUME_ID,
String.valueOf(sfNewVolumeId),
false);
@ -592,7 +592,7 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
try {
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, _storagePoolDetailsDao);
SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshotId, SolidFireUtil.VOLUME_ID);
SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshotId, DiskTO.VOLUME_ID);
long volumeId = Long.parseLong(snapshotDetails.getValue());