Skip to content

Commit 2ae2fab

Browse files
Remove allocated snapshots / vm snapshots on start
1 parent 25f93b1 commit 2ae2fab

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ public interface VMSnapshotDao extends GenericDao<VMSnapshotVO, Long>, StateDao<
3838
VMSnapshotVO findByName(Long vmId, String name);
3939

4040
List<VMSnapshotVO> listByAccountId(Long accountId);
41+
42+
List<VMSnapshotVO> listAllByStatus(VMSnapshot.State... status);
4143
}

engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Date;
2121
import java.util.List;
2222

23-
2423
import org.apache.log4j.Logger;
2524
import org.springframework.stereotype.Component;
2625

@@ -125,6 +124,13 @@ public List<VMSnapshotVO> listByAccountId(Long accountId) {
125124
return listBy(sc, null);
126125
}
127126

127+
@Override
128+
public List<VMSnapshotVO> listAllByStatus(VMSnapshot.State... status) {
129+
SearchCriteria<VMSnapshotVO> sc = SnapshotStatusSearch.create();
130+
sc.setParameters("status", (Object[])status);
131+
return listBy(sc, null);
132+
}
133+
128134
@Override
129135
public boolean updateState(State currentState, Event event, State nextState, VMSnapshot vo, Object data) {
130136

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,11 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
15161516

15171517
@Override
15181518
public boolean start() {
1519+
//remove snapshots in allocated state
1520+
List<SnapshotVO> allocatedSnapshots = _snapshotDao.listAllByStatus(Snapshot.State.Allocated);
1521+
for (SnapshotVO snapshot : allocatedSnapshots) {
1522+
_snapshotDao.remove(snapshot.getId());
1523+
}
15191524
//destroy snapshots in destroying state
15201525
List<SnapshotVO> snapshots = _snapshotDao.listAllByStatus(Snapshot.State.Destroying);
15211526
for (SnapshotVO snapshotVO : snapshots) {

server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
200200

201201
@Override
202202
public boolean start() {
203+
//Remove VM Snapshots in allocated state
204+
List<VMSnapshotVO> allocatedVMSnapshots = _vmSnapshotDao.listAllByStatus(VMSnapshot.State.Allocated);
205+
for (VMSnapshotVO vmSnapshot : allocatedVMSnapshots) {
206+
_vmSnapshotDao.remove(vmSnapshot.getId());
207+
}
203208
return true;
204209
}
205210

0 commit comments

Comments
 (0)