cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sw...@apache.org
Subject [1/2] git commit: updated refs/heads/master to c9319e2
Date Wed, 04 May 2016 14:26:26 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master b8286548b -> c9319e21f


CLOUDSTACK-8302 - Cleanup snapshot on KVM with RBD
Snapshot removing implemented on RBD.
1. On management side: when created new shanpshot we checking if our primary storage is RBD,
then do not remove record from cloud.snapshot_store_ref with link to Ceph
image via 'install_path' field.
2. On management side: when removing snapshot, also send command to agent 'DeleteCommand'.
3. On agent side: method implemented 'public Answer deleteSnapshot(final DeleteCommand cmd)'


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

Branch: refs/heads/master
Commit: 10ae2aff28cae69f0199fa2820472bb9cd7f3ebc
Parents: d518b61
Author: Dmytro Shevchenko <dshevchenko.mail@gmail.com>
Authored: Sat Dec 12 16:44:09 2015 +0200
Committer: Dmytro Shevchenko <dshevchenko.mail@gmail.com>
Committed: Mon Apr 25 22:14:48 2016 +0300

----------------------------------------------------------------------
 engine/storage/snapshot/pom.xml                 |  5 +++
 .../snapshot/XenserverSnapshotStrategy.java     | 26 ++++++++----
 .../kvm/storage/KVMStorageProcessor.java        | 43 +++++++++++++++++++-
 3 files changed, 64 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/10ae2aff/engine/storage/snapshot/pom.xml
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/pom.xml b/engine/storage/snapshot/pom.xml
index 97ca7f2..eda47be 100644
--- a/engine/storage/snapshot/pom.xml
+++ b/engine/storage/snapshot/pom.xml
@@ -37,6 +37,11 @@
           <type>test-jar</type>
           <scope>test</scope>
       </dependency>
+      <dependency>
+          <groupId>org.apache.cloudstack</groupId>
+          <artifactId>cloud-engine-storage-volume</artifactId>
+          <version>${project.version}</version>
+      </dependency>
   </dependencies>
     <build>
         <plugins>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/10ae2aff/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
index edd194e..99fc161 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
@@ -36,6 +36,7 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.storage.command.CreateObjectAnswer;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStoreImpl;
 import org.apache.cloudstack.storage.to.SnapshotObjectTO;
 
 import com.cloud.exception.InvalidParameterValueException;
@@ -53,6 +54,7 @@ import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.storage.snapshot.SnapshotManager;
 import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.exception.CloudRuntimeException;
@@ -263,6 +265,10 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
                 //snapshot is deleted on backup storage, need to delete it on primary storage
                 SnapshotDataStoreVO snapshotOnPrimary = snapshotStoreDao.findBySnapshot(snapshotId,
DataStoreRole.Primary);
                 if (snapshotOnPrimary != null) {
+                    SnapshotInfo snapshotOnPrimaryInfo = snapshotDataFactory.getSnapshot(snapshotId,
DataStoreRole.Primary);
+                    if (((PrimaryDataStoreImpl)snapshotOnPrimaryInfo.getDataStore()).getPoolType()
== StoragePoolType.RBD) {
+                        snapshotSvr.deleteSnapshot(snapshotOnPrimaryInfo);
+                    }
                     snapshotOnPrimary.setState(State.Destroyed);
                     snapshotStoreDao.update(snapshotOnPrimary.getId(), snapshotOnPrimary);
                 }
@@ -371,15 +377,17 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase
{
 
             try {
                 SnapshotInfo parent = snapshot.getParent();
-                if (backupedSnapshot != null && parent != null) {
-                    Long parentSnapshotId = parent.getId();
-                    while (parentSnapshotId != null && parentSnapshotId != 0L) {
-                        SnapshotDataStoreVO snapshotDataStoreVO = snapshotStoreDao.findByStoreSnapshot(primaryStore.getRole(),
primaryStore.getId(), parentSnapshotId);
-                        if (snapshotDataStoreVO != null) {
-                            parentSnapshotId = snapshotDataStoreVO.getParentSnapshotId();
-                            snapshotStoreDao.remove(snapshotDataStoreVO.getId());
-                        } else {
-                            parentSnapshotId = null;
+                if (backupedSnapshot != null && parent != null && primaryStore
instanceof PrimaryDataStoreImpl) {
+                    if (((PrimaryDataStoreImpl)primaryStore).getPoolType() != StoragePoolType.RBD)
{
+                        Long parentSnapshotId = parent.getId();
+                        while (parentSnapshotId != null && parentSnapshotId != 0L)
{
+                            SnapshotDataStoreVO snapshotDataStoreVO = snapshotStoreDao.findByStoreSnapshot(primaryStore.getRole(),
primaryStore.getId(), parentSnapshotId);
+                            if (snapshotDataStoreVO != null) {
+                                parentSnapshotId = snapshotDataStoreVO.getParentSnapshotId();
+                                snapshotStoreDao.remove(snapshotDataStoreVO.getId());
+                            } else {
+                                parentSnapshotId = null;
+                            }
                         }
                     }
                     SnapshotDataStoreVO snapshotDataStoreVO = snapshotStoreDao.findByStoreSnapshot(primaryStore.getRole(),
primaryStore.getId(), snapshot.getId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/10ae2aff/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
index 51931db..92e985e 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
@@ -1274,7 +1274,48 @@ public class KVMStorageProcessor implements StorageProcessor {
 
     @Override
     public Answer deleteSnapshot(final DeleteCommand cmd) {
-        return new Answer(cmd);
+        String snap_full_name = "";
+        try {
+            SnapshotObjectTO snapshotTO = (SnapshotObjectTO) cmd.getData();
+            PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) snapshotTO.getDataStore();
+            VolumeObjectTO volume = snapshotTO.getVolume();
+            KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(),
primaryStore.getUuid());
+            KVMPhysicalDisk disk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(),
primaryStore.getUuid(), volume.getPath());
+            String snapshotFullPath = snapshotTO.getPath();
+            String snapshotName = snapshotFullPath.substring(snapshotFullPath.lastIndexOf("/")
+ 1);
+            snap_full_name = disk.getName() + "@" + snapshotName;
+            if (primaryPool.getType() == StoragePoolType.RBD) {
+                Rados r = new Rados(primaryPool.getAuthUserName());
+                r.confSet("mon_host", primaryPool.getSourceHost() + ":" + primaryPool.getSourcePort());
+                r.confSet("key", primaryPool.getAuthSecret());
+                r.confSet("client_mount_timeout", "30");
+                r.connect();
+                s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));
+                IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
+                Rbd rbd = new Rbd(io);
+                RbdImage image = rbd.open(disk.getName());
+                try {
+                    s_logger.info("Attempting to remove RBD snapshot " + snap_full_name);
+                    if (image.snapIsProtected(snapshotName)) {
+                        s_logger.debug("Unprotecting RBD snapshot " + snap_full_name);
+                        image.snapUnprotect(snapshotName);
+                    }
+                    image.snapRemove(snapshotName);
+                    s_logger.info("Snapshot " + snap_full_name + " successfully removed from
" +
+                            primaryPool.getType().toString() + "  pool.");
+                } finally {
+                    rbd.close(image);
+                    r.ioCtxDestroy(io);
+                }
+            } else {
+                s_logger.warn("Operation not implemented for storage pool type of " + primaryPool.getType().toString());
+                throw new InternalErrorException("Operation not implemented for storage pool
type of " + primaryPool.getType().toString());
+            }
+            return new Answer(cmd, true, "Snapshot " + snap_full_name + " removed successfully.");
+        } catch (Exception e) {
+            s_logger.error(e.getMessage());
+            return new Answer(cmd, false, "Failed to remove snapshot " + snap_full_name);
+        }
     }
 
     @Override


Mime
View raw message