mirror of https://github.com/apache/cloudstack.git
Manage snapshot deletion for KVM + NFS (primary storage)
This commit is contained in:
parent
e109949e3a
commit
d31ecb8cfc
|
|
@ -127,6 +127,14 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
private String _createTmplPath;
|
||||
private String _manageSnapshotPath;
|
||||
private int _cmdsTimeout;
|
||||
|
||||
private static final String MANAGE_SNAPSTHOT_CREATE = "-c";
|
||||
private static final String MANAGE_SNAPSTHOT_DESTROY = "-d";
|
||||
private static final String NAME = "-n";
|
||||
private static final String CEPH_MON_HOST = "mon_host";
|
||||
private static final String CEPH_AUTH_KEY = "key";
|
||||
private static final String CEPH_CLIENT_MOUNT_TIMEOUT = "client_mount_timeout";
|
||||
private static final String CEPH_DEFAULT_MOUNT_TIMEOUT = "30";
|
||||
|
||||
public KVMStorageProcessor(final KVMStoragePoolManager storagePoolMgr, final LibvirtComputingResource resource) {
|
||||
this.storagePoolMgr = storagePoolMgr;
|
||||
|
|
@ -563,7 +571,7 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
final Script command = new Script(_createTmplPath, wait, s_logger);
|
||||
command.add("-f", disk.getPath());
|
||||
command.add("-t", tmpltPath);
|
||||
command.add("-n", templateName + ".qcow2");
|
||||
command.add(NAME, templateName + ".qcow2");
|
||||
|
||||
final String result = command.execute();
|
||||
|
||||
|
|
@ -949,7 +957,7 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
} else {
|
||||
final Script command = new Script(_manageSnapshotPath, cmd.getWaitInMillSeconds(), s_logger);
|
||||
command.add("-b", snapshotDisk.getPath());
|
||||
command.add("-n", snapshotName);
|
||||
command.add(NAME, snapshotName);
|
||||
command.add("-p", snapshotDestPath);
|
||||
if (isCreatedFromVmSnapshot) {
|
||||
descName = UUID.randomUUID().toString();
|
||||
|
|
@ -1010,14 +1018,7 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
}
|
||||
} else {
|
||||
if (primaryPool.getType() != StoragePoolType.RBD) {
|
||||
final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger);
|
||||
command.add("-d", snapshotDisk.getPath());
|
||||
command.add("-n", snapshotName);
|
||||
final String result = command.execute();
|
||||
if (result != null) {
|
||||
s_logger.debug("Failed to delete snapshot on primary: " + result);
|
||||
// return new CopyCmdAnswer("Failed to backup snapshot: " + result);
|
||||
}
|
||||
deleteSnapshotViaManageSnapshotScript(snapshotName, snapshotDisk);
|
||||
}
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
|
|
@ -1035,6 +1036,16 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private void deleteSnapshotViaManageSnapshotScript(final String snapshotName, KVMPhysicalDisk snapshotDisk) {
|
||||
final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger);
|
||||
command.add(MANAGE_SNAPSTHOT_DESTROY, snapshotDisk.getPath());
|
||||
command.add(NAME, snapshotName);
|
||||
final String result = command.execute();
|
||||
if (result != null) {
|
||||
s_logger.debug("Failed to delete snapshot on primary: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
protected synchronized String attachOrDetachISO(final Connect conn, final String vmName, String isoPath, final boolean isAttach) throws LibvirtException, URISyntaxException,
|
||||
InternalErrorException {
|
||||
String isoXml = null;
|
||||
|
|
@ -1489,12 +1500,7 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
*/
|
||||
if (primaryPool.getType() == StoragePoolType.RBD) {
|
||||
try {
|
||||
final 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"));
|
||||
Rados r = radosConnect(primaryPool);
|
||||
|
||||
final IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
|
||||
final Rbd rbd = new Rbd(io);
|
||||
|
|
@ -1511,8 +1517,8 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
} else {
|
||||
/* VM is not running, create a snapshot by ourself */
|
||||
final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger);
|
||||
command.add("-c", disk.getPath());
|
||||
command.add("-n", snapshotName);
|
||||
command.add(MANAGE_SNAPSTHOT_CREATE, disk.getPath());
|
||||
command.add(NAME, snapshotName);
|
||||
final String result = command.execute();
|
||||
if (result != null) {
|
||||
s_logger.debug("Failed to manage snapshot: " + result);
|
||||
|
|
@ -1531,6 +1537,16 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private Rados radosConnect(final KVMStoragePool primaryPool) throws RadosException {
|
||||
Rados r = new Rados(primaryPool.getAuthUserName());
|
||||
r.confSet(CEPH_MON_HOST, primaryPool.getSourceHost() + ":" + primaryPool.getSourcePort());
|
||||
r.confSet(CEPH_AUTH_KEY, primaryPool.getAuthSecret());
|
||||
r.confSet(CEPH_CLIENT_MOUNT_TIMEOUT, CEPH_DEFAULT_MOUNT_TIMEOUT);
|
||||
r.connect();
|
||||
s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet(CEPH_MON_HOST));
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer deleteVolume(final DeleteCommand cmd) {
|
||||
final VolumeObjectTO vol = (VolumeObjectTO)cmd.getData();
|
||||
|
|
@ -1619,12 +1635,7 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
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"));
|
||||
Rados r = radosConnect(primaryPool);
|
||||
IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
|
||||
Rbd rbd = new Rbd(io);
|
||||
RbdImage image = rbd.open(disk.getName());
|
||||
|
|
@ -1644,6 +1655,9 @@ public class KVMStorageProcessor implements StorageProcessor {
|
|||
rbd.close(image);
|
||||
r.ioCtxDestroy(io);
|
||||
}
|
||||
} else if (primaryPool.getType() == StoragePoolType.NetworkFilesystem) {
|
||||
s_logger.info(String.format("Attempting to remove snapshot on primary storage (id=%s, snapshot=%s, storage type=%s)", snapshotTO.getId(), snap_full_name, primaryPool.getType()));
|
||||
deleteSnapshotViaManageSnapshotScript(snapshotName, disk);
|
||||
} 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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue