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


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b29265f1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b29265f1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b29265f1

Branch: refs/heads/hotfix/CLOUDSTACK-7776
Commit: b29265f159aea8d6abd5985ac39e426fcb97168a
Parents: 0cea034
Author: Mike Tutkowski <mike.tutkow...@solidfire.com>
Authored: Sun Oct 19 21:17:54 2014 -0600
Committer: Mike Tutkowski <mike.tutkow...@solidfire.com>
Committed: Tue Oct 21 16:01:14 2014 -0600

----------------------------------------------------------------------
 api/src/com/cloud/agent/api/to/DiskTO.java      |  1 +
 .../snapshot/StorageSystemSnapshotStrategy.java | 50 ++++++++++++++++++--
 .../driver/SolidFirePrimaryDataStoreDriver.java |  4 +-
 3 files changed, 49 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b29265f1/api/src/com/cloud/agent/api/to/DiskTO.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/to/DiskTO.java 
b/api/src/com/cloud/agent/api/to/DiskTO.java
index 9e4dfd9..fcd2aaa 100644
--- a/api/src/com/cloud/agent/api/to/DiskTO.java
+++ b/api/src/com/cloud/agent/api/to/DiskTO.java
@@ -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;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b29265f1/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
index dd6c654..09c5d5f 100644
--- 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
+++ 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
@@ -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;
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b29265f1/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java
----------------------------------------------------------------------
diff --git 
a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java
 
b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java
index 17fc4ba..94c9595 100644
--- 
a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java
+++ 
b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java
@@ -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());
 

Reply via email to