CLOUDSTACK-2972: due to change on master, using name instead of uuid to find vm name, so break object_store branch

This commit is contained in:
Edison Su 2013-06-14 17:35:53 -07:00
parent c2da4eac89
commit 619ec12f61

View File

@ -88,6 +88,7 @@ public class KVMStorageProcessor implements StorageProcessor {
private String _createTmplPath; private String _createTmplPath;
private String _manageSnapshotPath; private String _manageSnapshotPath;
private int _cmdsTimeout; private int _cmdsTimeout;
public KVMStorageProcessor(KVMStoragePoolManager storagePoolMgr, LibvirtComputingResource resource) { public KVMStorageProcessor(KVMStoragePoolManager storagePoolMgr, LibvirtComputingResource resource) {
this.storagePoolMgr = storagePoolMgr; this.storagePoolMgr = storagePoolMgr;
this.resource = resource; this.resource = resource;
@ -97,8 +98,7 @@ public class KVMStorageProcessor implements StorageProcessor {
return "scripts/storage/qcow2"; return "scripts/storage/qcow2";
} }
public boolean configure(String name, Map<String, Object> params) public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
throws ConfigurationException {
storageLayer = new JavaStorageLayer(); storageLayer = new JavaStorageLayer();
storageLayer.configure("StorageLayer", params); storageLayer.configure("StorageLayer", params);
@ -107,18 +107,14 @@ public class KVMStorageProcessor implements StorageProcessor {
storageScriptsDir = getDefaultStorageScriptsDir(); storageScriptsDir = getDefaultStorageScriptsDir();
} }
_createTmplPath = Script _createTmplPath = Script.findScript(storageScriptsDir, "createtmplt.sh");
.findScript(storageScriptsDir, "createtmplt.sh");
if (_createTmplPath == null) { if (_createTmplPath == null) {
throw new ConfigurationException( throw new ConfigurationException("Unable to find the createtmplt.sh");
"Unable to find the createtmplt.sh");
} }
_manageSnapshotPath = Script.findScript(storageScriptsDir, _manageSnapshotPath = Script.findScript(storageScriptsDir, "managesnapshot.sh");
"managesnapshot.sh");
if (_manageSnapshotPath == null) { if (_manageSnapshotPath == null) {
throw new ConfigurationException( throw new ConfigurationException("Unable to find the managesnapshot.sh");
"Unable to find the managesnapshot.sh");
} }
String value = (String) params.get("cmds.timeout"); String value = (String) params.get("cmds.timeout");
@ -158,8 +154,7 @@ public class KVMStorageProcessor implements StorageProcessor {
secondaryPool.refresh(); secondaryPool.refresh();
List<KVMPhysicalDisk> disks = secondaryPool.listPhysicalDisks(); List<KVMPhysicalDisk> disks = secondaryPool.listPhysicalDisks();
if (disks == null || disks.isEmpty()) { if (disks == null || disks.isEmpty()) {
return new PrimaryStorageDownloadAnswer( return new PrimaryStorageDownloadAnswer("Failed to get volumes from pool: "
"Failed to get volumes from pool: "
+ secondaryPool.getUuid()); + secondaryPool.getUuid());
} }
for (KVMPhysicalDisk disk : disks) { for (KVMPhysicalDisk disk : disks) {
@ -169,8 +164,7 @@ public class KVMStorageProcessor implements StorageProcessor {
} }
} }
if (tmplVol == null) { if (tmplVol == null) {
return new PrimaryStorageDownloadAnswer( return new PrimaryStorageDownloadAnswer("Failed to get template from pool: "
"Failed to get template from pool: "
+ secondaryPool.getUuid()); + secondaryPool.getUuid());
} }
} else { } else {
@ -178,12 +172,11 @@ public class KVMStorageProcessor implements StorageProcessor {
} }
/* Copy volume to primary storage */ /* Copy volume to primary storage */
KVMStoragePool primaryPool = storagePoolMgr.getStoragePool( KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(),
primaryStore.getPoolType(),
primaryStore.getUuid()); primaryStore.getUuid());
KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk( KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(),
tmplVol, UUID.randomUUID().toString(), primaryPool); primaryPool);
TemplateObjectTO newTemplate = new TemplateObjectTO(); TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(primaryVol.getName()); newTemplate.setPath(primaryVol.getName());
@ -235,7 +228,8 @@ public class KVMStorageProcessor implements StorageProcessor {
/* Copy volume to primary storage */ /* Copy volume to primary storage */
KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(templateVol, UUID.randomUUID().toString(), primaryPool); KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(templateVol, UUID.randomUUID().toString(),
primaryPool);
return primaryVol; return primaryVol;
} catch (CloudRuntimeException e) { } catch (CloudRuntimeException e) {
s_logger.error("Failed to download template to primary storage", e); s_logger.error("Failed to download template to primary storage", e);
@ -260,8 +254,7 @@ public class KVMStorageProcessor implements StorageProcessor {
KVMPhysicalDisk vol = null; KVMPhysicalDisk vol = null;
try { try {
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
primaryStore.getUuid());
String templatePath = template.getPath(); String templatePath = template.getPath();
@ -269,12 +262,10 @@ public class KVMStorageProcessor implements StorageProcessor {
vol = templateToPrimaryDownload(templatePath, primaryPool); vol = templateToPrimaryDownload(templatePath, primaryPool);
} else { } else {
BaseVol = primaryPool.getPhysicalDisk(templatePath); BaseVol = primaryPool.getPhysicalDisk(templatePath);
vol = storagePoolMgr.createDiskFromTemplate(BaseVol, UUID vol = storagePoolMgr.createDiskFromTemplate(BaseVol, UUID.randomUUID().toString(), primaryPool);
.randomUUID().toString(), primaryPool);
} }
if (vol == null) { if (vol == null) {
return new CopyCmdAnswer( return new CopyCmdAnswer(" Can't create storage volume on storage pool");
" Can't create storage volume on storage pool");
} }
VolumeObjectTO newVol = new VolumeObjectTO(); VolumeObjectTO newVol = new VolumeObjectTO();
@ -319,27 +310,21 @@ public class KVMStorageProcessor implements StorageProcessor {
try { try {
String templateFolder = template.getPath(); String templateFolder = template.getPath();
secondaryStorage = storagePoolMgr.getStoragePoolByURI( secondaryStorage = storagePoolMgr.getStoragePoolByURI(nfsImageStore.getUrl());
nfsImageStore.getUrl());
try { try {
primary = storagePoolMgr.getStoragePool( primary = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
primaryStore.getPoolType(),
primaryStore.getUuid());
} catch (CloudRuntimeException e) { } catch (CloudRuntimeException e) {
if (e.getMessage().contains("not found")) { if (e.getMessage().contains("not found")) {
primary = storagePoolMgr.createStoragePool(primaryStore.getUuid(), primary = storagePoolMgr.createStoragePool(primaryStore.getUuid(), primaryStore.getHost(),
primaryStore.getHost(), primaryStore.getPort(), primaryStore.getPort(), primaryStore.getPath(), null, primaryStore.getPoolType());
primaryStore.getPath(), null,
primaryStore.getPoolType());
} else { } else {
return new CopyCmdAnswer(e.getMessage()); return new CopyCmdAnswer(e.getMessage());
} }
} }
KVMPhysicalDisk disk = primary.getPhysicalDisk(volume.getPath()); KVMPhysicalDisk disk = primary.getPhysicalDisk(volume.getPath());
String tmpltPath = secondaryStorage.getLocalPath() + File.separator String tmpltPath = secondaryStorage.getLocalPath() + File.separator + templateFolder;
+ templateFolder;
this.storageLayer.mkdirs(tmpltPath); this.storageLayer.mkdirs(tmpltPath);
String templateName = UUID.randomUUID().toString(); String templateName = UUID.randomUUID().toString();
@ -359,10 +344,7 @@ public class KVMStorageProcessor implements StorageProcessor {
s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + templateName); s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + templateName);
QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(), QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(),
primary.getSourcePort(), primary.getSourcePort(), primary.getAuthUserName(), primary.getAuthSecret(), disk.getPath()));
primary.getAuthUserName(),
primary.getAuthSecret(),
disk.getPath()));
srcFile.setFormat(PhysicalDiskFormat.RAW); srcFile.setFormat(PhysicalDiskFormat.RAW);
QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + templateName + ".qcow2"); QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + templateName + ".qcow2");
@ -372,8 +354,8 @@ public class KVMStorageProcessor implements StorageProcessor {
try { try {
q.convert(srcFile, destFile); q.convert(srcFile, destFile);
} catch (QemuImgException e) { } catch (QemuImgException e) {
s_logger.error("Failed to create new template while converting " s_logger.error("Failed to create new template while converting " + srcFile.getFileName() + " to "
+ srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); + destFile.getFileName() + " the error was: " + e.getMessage());
} }
File templateProp = new File(tmpltPath + "/template.properties"); File templateProp = new File(tmpltPath + "/template.properties");
@ -399,8 +381,7 @@ public class KVMStorageProcessor implements StorageProcessor {
qcow2Processor.configure("QCOW2 Processor", params); qcow2Processor.configure("QCOW2 Processor", params);
FormatInfo info = qcow2Processor.process(tmpltPath, null, FormatInfo info = qcow2Processor.process(tmpltPath, null, templateName);
templateName);
TemplateLocation loc = new TemplateLocation(this.storageLayer, tmpltPath); TemplateLocation loc = new TemplateLocation(this.storageLayer, tmpltPath);
loc.create(1, true, templateName); loc.create(1, true, templateName);
@ -450,19 +431,16 @@ public class KVMStorageProcessor implements StorageProcessor {
try { try {
Connect conn = LibvirtConnection.getConnectionByVmName(vmName); Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI( secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStoragePoolUrl);
secondaryStoragePoolUrl);
String ssPmountPath = secondaryStoragePool.getLocalPath(); String ssPmountPath = secondaryStoragePool.getLocalPath();
snapshotRelPath = destSnapshot.getPath(); snapshotRelPath = destSnapshot.getPath();
snapshotDestPath = ssPmountPath + File.separator + snapshotRelPath; snapshotDestPath = ssPmountPath + File.separator + snapshotRelPath;
KVMStoragePool primaryPool = storagePoolMgr.getStoragePool( KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(),
primaryStore.getPoolType(),
primaryStore.getUuid()); primaryStore.getUuid());
KVMPhysicalDisk snapshotDisk = primaryPool.getPhysicalDisk(volumePath); KVMPhysicalDisk snapshotDisk = primaryPool.getPhysicalDisk(volumePath);
Script command = new Script(_manageSnapshotPath, _cmdsTimeout, Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger);
s_logger);
command.add("-b", snapshotDisk.getPath()); command.add("-b", snapshotDisk.getPath());
command.add("-n", snapshotName); command.add("-n", snapshotName);
command.add("-p", snapshotDestPath); command.add("-p", snapshotDestPath);
@ -485,11 +463,9 @@ public class KVMStorageProcessor implements StorageProcessor {
} }
} }
KVMStoragePool primaryStorage = storagePoolMgr.getStoragePool( KVMStoragePool primaryStorage = storagePoolMgr.getStoragePool(primaryStore.getPoolType(),
primaryStore.getPoolType(),
primaryStore.getUuid()); primaryStore.getUuid());
if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING && !primaryStorage.isExternalSnapshot()) {
&& !primaryStorage.isExternalSnapshot()) {
DomainSnapshot snap = vm.snapshotLookupByName(snapshotName); DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
snap.delete(0); snap.delete(0);
@ -503,21 +479,18 @@ public class KVMStorageProcessor implements StorageProcessor {
vm.resume(); vm.resume();
} }
} else { } else {
command = new Script(_manageSnapshotPath, _cmdsTimeout, command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger);
s_logger);
command.add("-d", snapshotDisk.getPath()); command.add("-d", snapshotDisk.getPath());
command.add("-n", snapshotName); command.add("-n", snapshotName);
result = command.execute(); result = command.execute();
if (result != null) { if (result != null) {
s_logger.debug("Failed to backup snapshot: " + result); s_logger.debug("Failed to backup snapshot: " + result);
return new CopyCmdAnswer( return new CopyCmdAnswer("Failed to backup snapshot: " + result);
"Failed to backup snapshot: " + result);
} }
} }
SnapshotObjectTO newSnapshot = new SnapshotObjectTO(); SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
newSnapshot.setPath(snapshotRelPath newSnapshot.setPath(snapshotRelPath + File.separator + snapshotName);
+ File.separator + snapshotName);
return new CopyCmdAnswer(newSnapshot); return new CopyCmdAnswer(newSnapshot);
} catch (LibvirtException e) { } catch (LibvirtException e) {
s_logger.debug("Failed to backup snapshot: " + e.toString()); s_logger.debug("Failed to backup snapshot: " + e.toString());
@ -532,16 +505,14 @@ public class KVMStorageProcessor implements StorageProcessor {
} }
} }
protected synchronized String attachOrDetachISO(Connect conn, protected synchronized String attachOrDetachISO(Connect conn, String vmName, String isoPath, boolean isAttach)
String vmName, String isoPath, boolean isAttach)
throws LibvirtException, URISyntaxException, InternalErrorException { throws LibvirtException, URISyntaxException, InternalErrorException {
String isoXml = null; String isoXml = null;
if (isoPath != null && isAttach) { if (isoPath != null && isAttach) {
int index = isoPath.lastIndexOf("/"); int index = isoPath.lastIndexOf("/");
String path = isoPath.substring(0, index); String path = isoPath.substring(0, index);
String name = isoPath.substring(index + 1); String name = isoPath.substring(index + 1);
KVMStoragePool secondaryPool = storagePoolMgr.getStoragePoolByURI( KVMStoragePool secondaryPool = storagePoolMgr.getStoragePoolByURI(path);
path);
KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name); KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
isoPath = isoVol.getPath(); isoPath = isoVol.getPath();
@ -566,6 +537,7 @@ public class KVMStorageProcessor implements StorageProcessor {
} }
return result; return result;
} }
@Override @Override
public Answer attachIso(AttachCommand cmd) { public Answer attachIso(AttachCommand cmd) {
DiskTO disk = cmd.getDisk(); DiskTO disk = cmd.getDisk();
@ -577,8 +549,7 @@ public class KVMStorageProcessor implements StorageProcessor {
NfsTO nfsStore = (NfsTO) store; NfsTO nfsStore = (NfsTO) store;
try { try {
Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName()); Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
attachOrDetachISO(conn, cmd.getVmName(), nfsStore.getUrl() + File.separator + isoTO.getPath(), attachOrDetachISO(conn, cmd.getVmName(), nfsStore.getUrl() + File.separator + isoTO.getPath(), true);
true);
} catch (LibvirtException e) { } catch (LibvirtException e) {
return new Answer(cmd, false, e.toString()); return new Answer(cmd, false, e.toString());
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
@ -590,13 +561,11 @@ public class KVMStorageProcessor implements StorageProcessor {
return new Answer(cmd); return new Answer(cmd);
} }
protected synchronized String attachOrDetachDevice(Connect conn, protected synchronized String attachOrDetachDevice(Connect conn, boolean attach, String vmName, String xml)
boolean attach, String vmName, String xml) throws LibvirtException, throws LibvirtException, InternalErrorException {
InternalErrorException {
Domain dm = null; Domain dm = null;
try { try {
dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes((vmName dm = conn.domainLookupByName(vmName);
.getBytes())));
if (attach) { if (attach) {
s_logger.debug("Attaching device: " + xml); s_logger.debug("Attaching device: " + xml);
@ -607,11 +576,9 @@ public class KVMStorageProcessor implements StorageProcessor {
} }
} catch (LibvirtException e) { } catch (LibvirtException e) {
if (attach) { if (attach) {
s_logger.warn("Failed to attach device to " + vmName + ": " s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage());
+ e.getMessage());
} else { } else {
s_logger.warn("Failed to detach device from " + vmName + ": " s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage());
+ e.getMessage());
} }
throw e; throw e;
} finally { } finally {
@ -627,16 +594,14 @@ public class KVMStorageProcessor implements StorageProcessor {
return null; return null;
} }
protected synchronized String attachOrDetachDisk(Connect conn, protected synchronized String attachOrDetachDisk(Connect conn, boolean attach, String vmName,
boolean attach, String vmName, KVMPhysicalDisk attachingDisk, KVMPhysicalDisk attachingDisk, int devId) throws LibvirtException, InternalErrorException {
int devId) throws LibvirtException, InternalErrorException {
List<DiskDef> disks = null; List<DiskDef> disks = null;
Domain dm = null; Domain dm = null;
DiskDef diskdef = null; DiskDef diskdef = null;
try { try {
if (!attach) { if (!attach) {
dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName dm = conn.domainLookupByName(vmName);
.getBytes()));
LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser(); LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
String xml = dm.getXMLDesc(0); String xml = dm.getXMLDesc(0);
parser.parseDomainXML(xml); parser.parseDomainXML(xml);
@ -644,25 +609,21 @@ public class KVMStorageProcessor implements StorageProcessor {
for (DiskDef disk : disks) { for (DiskDef disk : disks) {
String file = disk.getDiskPath(); String file = disk.getDiskPath();
if (file != null if (file != null && file.equalsIgnoreCase(attachingDisk.getPath())) {
&& file.equalsIgnoreCase(attachingDisk.getPath())) {
diskdef = disk; diskdef = disk;
break; break;
} }
} }
if (diskdef == null) { if (diskdef == null) {
throw new InternalErrorException("disk: " throw new InternalErrorException("disk: " + attachingDisk.getPath() + " is not attached before");
+ attachingDisk.getPath()
+ " is not attached before");
} }
} else { } else {
diskdef = new DiskDef(); diskdef = new DiskDef();
if (attachingDisk.getFormat() == PhysicalDiskFormat.QCOW2) { if (attachingDisk.getFormat() == PhysicalDiskFormat.QCOW2) {
diskdef.defFileBasedDisk(attachingDisk.getPath(), devId, diskdef.defFileBasedDisk(attachingDisk.getPath(), devId, DiskDef.diskBus.VIRTIO,
DiskDef.diskBus.VIRTIO, DiskDef.diskFmtType.QCOW2); DiskDef.diskFmtType.QCOW2);
} else if (attachingDisk.getFormat() == PhysicalDiskFormat.RAW) { } else if (attachingDisk.getFormat() == PhysicalDiskFormat.RAW) {
diskdef.defBlockBasedDisk(attachingDisk.getPath(), devId, diskdef.defBlockBasedDisk(attachingDisk.getPath(), devId, DiskDef.diskBus.VIRTIO);
DiskDef.diskBus.VIRTIO);
} }
} }
@ -683,13 +644,10 @@ public class KVMStorageProcessor implements StorageProcessor {
String vmName = cmd.getVmName(); String vmName = cmd.getVmName();
try { try {
Connect conn = LibvirtConnection.getConnectionByVmName(vmName); Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
KVMStoragePool primary = storagePoolMgr.getStoragePool( KVMStoragePool primary = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
primaryStore.getPoolType(),
primaryStore.getUuid());
KVMPhysicalDisk phyDisk = primary.getPhysicalDisk(vol.getPath()); KVMPhysicalDisk phyDisk = primary.getPhysicalDisk(vol.getPath());
attachOrDetachDisk(conn, true, vmName, phyDisk, attachOrDetachDisk(conn, true, vmName, phyDisk, disk.getDiskSeq().intValue());
disk.getDiskSeq().intValue());
return new AttachAnswer(disk); return new AttachAnswer(disk);
} catch (LibvirtException e) { } catch (LibvirtException e) {
@ -715,13 +673,10 @@ public class KVMStorageProcessor implements StorageProcessor {
String vmName = cmd.getVmName(); String vmName = cmd.getVmName();
try { try {
Connect conn = LibvirtConnection.getConnectionByVmName(vmName); Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
KVMStoragePool primary = storagePoolMgr.getStoragePool( KVMStoragePool primary = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
primaryStore.getPoolType(),
primaryStore.getUuid());
KVMPhysicalDisk phyDisk = primary.getPhysicalDisk(vol.getPath()); KVMPhysicalDisk phyDisk = primary.getPhysicalDisk(vol.getPath());
attachOrDetachDisk(conn, false, vmName, phyDisk, attachOrDetachDisk(conn, false, vmName, phyDisk, disk.getDiskSeq().intValue());
disk.getDiskSeq().intValue());
return new DettachAnswer(disk); return new DettachAnswer(disk);
} catch (LibvirtException e) { } catch (LibvirtException e) {
@ -742,12 +697,10 @@ public class KVMStorageProcessor implements StorageProcessor {
KVMPhysicalDisk vol = null; KVMPhysicalDisk vol = null;
long disksize; long disksize;
try { try {
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
primaryStore.getUuid());
disksize = volume.getSize(); disksize = volume.getSize();
vol = primaryPool.createPhysicalDisk(UUID.randomUUID() vol = primaryPool.createPhysicalDisk(UUID.randomUUID().toString(), disksize);
.toString(), disksize);
VolumeObjectTO newVol = new VolumeObjectTO(); VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(vol.getName()); newVol.setPath(vol.getName());
@ -759,10 +712,8 @@ public class KVMStorageProcessor implements StorageProcessor {
} }
} }
protected static MessageFormat SnapshotXML = new MessageFormat( protected static MessageFormat SnapshotXML = new MessageFormat(" <domainsnapshot>" + " <name>{0}</name>"
" <domainsnapshot>" + " <name>{0}</name>" + " <domain>" + " <domain>" + " <uuid>{1}</uuid>" + " </domain>" + " </domainsnapshot>");
+ " <uuid>{1}</uuid>" + " </domain>"
+ " </domainsnapshot>");
@Override @Override
public Answer createSnapshot(CreateObjectCommand cmd) { public Answer createSnapshot(CreateObjectCommand cmd) {
@ -784,19 +735,16 @@ public class KVMStorageProcessor implements StorageProcessor {
} }
} }
KVMStoragePool primaryPool = storagePoolMgr.getStoragePool( KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(),
primaryStore.getPoolType(),
primaryStore.getUuid()); primaryStore.getUuid());
if (primaryPool.getType() == StoragePoolType.RBD) { if (primaryPool.getType() == StoragePoolType.RBD) {
s_logger.debug("Snapshots are not supported on RBD volumes"); s_logger.debug("Snapshots are not supported on RBD volumes");
return new CreateObjectAnswer( return new CreateObjectAnswer("Snapshots are not supported on RBD volumes");
"Snapshots are not supported on RBD volumes");
} }
KVMPhysicalDisk disk = primaryPool.getPhysicalDisk(volume.getPath()); KVMPhysicalDisk disk = primaryPool.getPhysicalDisk(volume.getPath());
if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING && !primaryPool.isExternalSnapshot()) {
&& !primaryPool.isExternalSnapshot()) {
String vmUuid = vm.getUUIDString(); String vmUuid = vm.getUUIDString();
Object[] args = new Object[] { snapshotName, vmUuid }; Object[] args = new Object[] { snapshotName, vmUuid };
String snapshot = SnapshotXML.format(args); String snapshot = SnapshotXML.format(args);
@ -815,15 +763,13 @@ public class KVMStorageProcessor implements StorageProcessor {
} else { } else {
/* VM is not running, create a snapshot by ourself */ /* VM is not running, create a snapshot by ourself */
final Script command = new Script(_manageSnapshotPath, final Script command = new Script(_manageSnapshotPath, this._cmdsTimeout, s_logger);
this._cmdsTimeout, s_logger);
command.add("-c", disk.getPath()); command.add("-c", disk.getPath());
command.add("-n", snapshotName); command.add("-n", snapshotName);
String result = command.execute(); String result = command.execute();
if (result != null) { if (result != null) {
s_logger.debug("Failed to manage snapshot: " + result); s_logger.debug("Failed to manage snapshot: " + result);
return new CreateObjectAnswer( return new CreateObjectAnswer("Failed to manage snapshot: " + result);
"Failed to manage snapshot: " + result);
} }
} }
@ -833,8 +779,7 @@ public class KVMStorageProcessor implements StorageProcessor {
return new CreateObjectAnswer(newSnapshot); return new CreateObjectAnswer(newSnapshot);
} catch (LibvirtException e) { } catch (LibvirtException e) {
s_logger.debug("Failed to manage snapshot: " + e.toString()); s_logger.debug("Failed to manage snapshot: " + e.toString());
return new CreateObjectAnswer( return new CreateObjectAnswer("Failed to manage snapshot: " + e.toString());
"Failed to manage snapshot: " + e.toString());
} }
} }
@ -843,9 +788,7 @@ public class KVMStorageProcessor implements StorageProcessor {
VolumeObjectTO vol = (VolumeObjectTO) cmd.getData(); VolumeObjectTO vol = (VolumeObjectTO) cmd.getData();
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) vol.getDataStore(); PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) vol.getDataStore();
try { try {
KVMStoragePool pool = storagePoolMgr.getStoragePool( KVMStoragePool pool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
primaryStore.getPoolType(),
primaryStore.getUuid());
try { try {
pool.getPhysicalDisk(vol.getPath()); pool.getPhysicalDisk(vol.getPath());
} catch (Exception e) { } catch (Exception e) {
@ -869,7 +812,6 @@ public class KVMStorageProcessor implements StorageProcessor {
PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore(); PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
DataStoreTO imageStore = srcData.getDataStore(); DataStoreTO imageStore = srcData.getDataStore();
if (!(imageStore instanceof NfsTO)) { if (!(imageStore instanceof NfsTO)) {
return new CopyCmdAnswer("unsupported protocol"); return new CopyCmdAnswer("unsupported protocol");
} }
@ -880,25 +822,20 @@ public class KVMStorageProcessor implements StorageProcessor {
int index = snapshotPath.lastIndexOf("/"); int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index); snapshotPath = snapshotPath.substring(0, index);
String snapshotName = snapshotPath.substring(index + 1); String snapshotName = snapshotPath.substring(index + 1);
KVMStoragePool secondaryPool = storagePoolMgr.getStoragePoolByURI( KVMStoragePool secondaryPool = storagePoolMgr.getStoragePoolByURI(nfsImageStore.getUrl() + File.separator
nfsImageStore.getUrl() + File.separator + snapshotPath); + snapshotPath);
KVMPhysicalDisk snapshotDisk = secondaryPool.getPhysicalDisk(snapshotName); KVMPhysicalDisk snapshotDisk = secondaryPool.getPhysicalDisk(snapshotName);
String primaryUuid = pool.getUuid(); String primaryUuid = pool.getUuid();
KVMStoragePool primaryPool = storagePoolMgr KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(pool.getPoolType(), primaryUuid);
.getStoragePool(pool.getPoolType(),
primaryUuid);
String volUuid = UUID.randomUUID().toString(); String volUuid = UUID.randomUUID().toString();
KVMPhysicalDisk disk = storagePoolMgr.copyPhysicalDisk(snapshotDisk, KVMPhysicalDisk disk = storagePoolMgr.copyPhysicalDisk(snapshotDisk, volUuid, primaryPool);
volUuid, primaryPool);
VolumeObjectTO newVol = new VolumeObjectTO(); VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(disk.getName()); newVol.setPath(disk.getName());
newVol.setSize(disk.getVirtualSize()); newVol.setSize(disk.getVirtualSize());
return new CopyCmdAnswer( return new CopyCmdAnswer(newVol);
newVol);
} catch (CloudRuntimeException e) { } catch (CloudRuntimeException e) {
return new CopyCmdAnswer(e.toString() return new CopyCmdAnswer(e.toString());
);
} }
} }