enable snapshot for rhel

This commit is contained in:
Edison Su 2011-01-08 11:08:15 -05:00
parent 9d060db757
commit d2dab22437
2 changed files with 43 additions and 10 deletions

View File

@ -3003,7 +3003,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
long speed = 0;
long cpus = 0;
long ram = 0;
String osType = null;
String cap = null;
try {
final NodeInfo hosts = _conn.nodeInfo();
@ -3016,17 +3016,21 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
for(String s : oss) {
/*Even host supports guest os type more than hvm, we only report hvm to management server*/
if (s.equalsIgnoreCase("hvm")) {
osType = "hvm";
cap = "hvm";
}
}
} catch (LibvirtException e) {
}
if (isSnapshotSupported()) {
cap = cap + ",snapshot";
}
info.add((int)cpus);
info.add(speed);
info.add(ram);
info.add(osType);
info.add(cap);
long dom0ram = Math.min(ram/10, 768*1024*1024L);//save a maximum of 10% of system ram or 768M
dom0ram = Math.max(dom0ram, _dom0MinMem);
info.add(dom0ram);
@ -3846,5 +3850,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
return states;
}
/*online snapshot supported by enhanced qemu-kvm*/
private boolean isSnapshotSupported() {
File f =new File("/usr/bin/cloud-qemu-system-x86_64");
if (f.exists()) {
return true;
} else {
f = new File("/usr/libexec/cloud-qemu-kvm");
if (f.exists()) {
return true;
}
}
return false;
}
}

View File

@ -349,21 +349,18 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volumeId + " is being used, try it later ");
}
}
if (_volsDao.getHypervisorType(volume.getId()).equals(HypervisorType.KVM)) {
/*for kvm, only Fedora supports snapshot, currently*/
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
ClusterVO cluster = _clusterDao.findById(storagePool.getClusterId());
List<HostVO> hosts = _hostDao.listByCluster(cluster.getId());
if (hosts != null && !hosts.isEmpty()) {
HostVO host = hosts.get(0);
_hostDao.loadDetails(host);
String hostOS = host.getDetail("Host.OS");
String hostOSVersion = host.getDetail("Host.OS.Version");
if (! (hostOS != null && hostOS.equalsIgnoreCase("Fedora") && hostOSVersion != null && Integer.parseInt(hostOSVersion) >= 13)) {
throw new CloudRuntimeException("KVM Snapshot is not supported on:" + hostOS + ": " + hostOSVersion + ". Please install Fedora 13 and above to enable snapshot");
}
if (!hostSupportSnapsthot(host))
throw new CloudRuntimeException("KVM Snapshot is not supported on cluster: " + host.getId());
}
}
SnapshotVO snapshot = null;
boolean backedUp = false;
try {
@ -1248,6 +1245,24 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
return success;
}
private boolean hostSupportSnapsthot(HostVO host) {
if (host.getHypervisorType() != HypervisorType.KVM) {
return true;
}
// Determine host capabilities
String caps = host.getCapabilities();
if (caps != null) {
String[] tokens = caps.split(",");
for (String token : tokens) {
if (token.contains("snapshot")) {
return true;
}
}
}
return false;
}
}