throw new CloudRuntimeException("RBD volumes do not support snapshotting");
}
ManageSnapshotCommand cmd = new ManageSnapshotCommand(snapshotId, volume.getPath(), srcPool, preSnapshotPath, snapshot.getName(), vmName);
ManageSnapshotAnswer answer = (ManageSnapshotAnswer) sendToPool(volume, cmd);
// Update the snapshot in the database
if ((answer != null) && answer.getResult()) {
// The snapshot was successfully created
if (preSnapshotPath != null && preSnapshotPath.equals(answer.getSnapshotPath())) {
// empty snapshot
s_logger.debug("CreateSnapshot: this is empty snapshot ");
snapshot.setPath(preSnapshotPath);
snapshot.setBackupSnapshotId(preSnapshotVO.getBackupSnapshotId());
snapshot.setSwiftId(preSnapshotVO.getSwiftId());
snapshot.setStatus(Snapshot.Status.BackedUp);
snapshot.setPrevSnapshotId(preId);
snapshot.setSecHostId(preSnapshotVO.getSecHostId());
_snapshotDao.update(snapshotId, snapshot);
} else {
long preSnapshotId = 0;
if (preSnapshotVO != null && preSnapshotVO.getBackupSnapshotId() != null) {
preSnapshotId = preId;
// default delta snap number is 16
int deltaSnap = _deltaSnapshotMax;
int i;
for (i = 1; i < deltaSnap; i++) {
String prevBackupUuid = preSnapshotVO.getBackupSnapshotId();
// previous snapshot doesn't have backup, create a full snapshot
if (prevBackupUuid == null) {
preSnapshotId = 0;
break;
}
long preSSId = preSnapshotVO.getPrevSnapshotId();
if (preSSId == 0) {
break;
}
preSnapshotVO = _snapshotDao.findByIdIncludingRemoved(preSSId);
}
if (i >= deltaSnap) {
preSnapshotId = 0;
}
}
//If the volume is moved around, backup a full snapshot to secondary storage
if (volume.getLastPoolId() != null && !volume.getLastPoolId().equals(volume.getPoolId())) {
preSnapshotId = 0;
volume.setLastPoolId(volume.getPoolId());
_volumeDao.update(volume.getId(), volume);
}
snapshot = updateDBOnCreate(snapshotId, answer.getSnapshotPath(), preSnapshotId);
}
// Get the snapshot_schedule table entry for this snapshot and
// policy id.
// Set the snapshotId to retrieve it back later.
if (policyId != Snapshot.MANUAL_POLICY_ID) {
SnapshotScheduleVO snapshotSchedule = _snapshotScheduleDao.getCurrentSchedule(volumeId, policyId, true);
assert snapshotSchedule != null;
snapshotSchedule.setSnapshotId(snapshotId);
_snapshotScheduleDao.update(snapshotSchedule.getId(), snapshotSchedule);
}
} else {
if (answer != null) {
s_logger.error(answer.getDetails());
}
throw new CloudRuntimeException("Creating snapshot for volume " + volumeId + " on primary storage failed.");
}
return snapshot;