mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
fix patch disks from reproducing like rabbits
RB: https://reviews.apache.org/r/7040 Signed-off-by: Edison Su <sudison@gmail.com>
This commit is contained in:
parent
651ac2a83b
commit
4c3ab1afb6
@ -2585,8 +2585,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
if (result == null) {
|
||||
for (DiskDef disk : disks) {
|
||||
if (disk.getDeviceType() == DiskDef.deviceType.CDROM
|
||||
&& disk.getDiskPath() != null)
|
||||
&& disk.getDiskPath() != null) {
|
||||
cleanupDisk(conn, disk);
|
||||
} else if (disk.getDiskPath().contains(vmName + "-patchdisk")
|
||||
&& vmName.matches("^[rsv]-\\d+-VM$")) {
|
||||
if (!_storagePoolMgr.deleteVbdByPath(disk.getDiskPath())) {
|
||||
s_logger.warn("failed to delete patch disk " + disk.getDiskPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2947,29 +2953,45 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
List<DiskDef> disks = vm.getDevices().getDisks();
|
||||
DiskDef rootDisk = disks.get(0);
|
||||
VolumeTO rootVol = getVolume(vmSpec, Volume.Type.ROOT);
|
||||
KVMStoragePool pool = _storagePoolMgr.getStoragePool(rootVol
|
||||
.getPoolUuid());
|
||||
KVMPhysicalDisk disk = pool.createPhysicalDisk(UUID.randomUUID()
|
||||
.toString(), KVMPhysicalDisk.PhysicalDiskFormat.RAW,
|
||||
String patchName = vmName + "-patchdisk";
|
||||
KVMStoragePool pool = _storagePoolMgr.getStoragePool(rootVol.getPoolUuid());
|
||||
String patchDiskPath = pool.getLocalPath() + "/" + patchName;
|
||||
|
||||
List<KVMPhysicalDisk> phyDisks = pool.listPhysicalDisks();
|
||||
boolean foundDisk = false;
|
||||
|
||||
for (KVMPhysicalDisk phyDisk : phyDisks) {
|
||||
if (phyDisk.getPath().equals(patchDiskPath)) {
|
||||
foundDisk = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundDisk) {
|
||||
s_logger.debug("generating new patch disk for " + vmName + " since none was found");
|
||||
KVMPhysicalDisk disk = pool.createPhysicalDisk(patchName, KVMPhysicalDisk.PhysicalDiskFormat.RAW,
|
||||
10L * 1024 * 1024);
|
||||
} else {
|
||||
s_logger.debug("found existing patch disk at " + patchDiskPath + " using it for " + vmName);
|
||||
}
|
||||
|
||||
/* Format/create fs on this disk */
|
||||
final Script command = new Script(_createvmPath, _timeout, s_logger);
|
||||
command.add("-f", disk.getPath());
|
||||
command.add("-f", patchDiskPath);
|
||||
String result = command.execute();
|
||||
if (result != null) {
|
||||
s_logger.debug("Failed to create data disk: " + result);
|
||||
throw new InternalErrorException("Failed to create data disk: "
|
||||
+ result);
|
||||
}
|
||||
String datadiskPath = disk.getPath();
|
||||
|
||||
/* add patch disk */
|
||||
DiskDef patchDisk = new DiskDef();
|
||||
|
||||
if (pool.getType() == StoragePoolType.CLVM) {
|
||||
patchDisk.defBlockBasedDisk(datadiskPath, 1, rootDisk.getBusType());
|
||||
patchDisk.defBlockBasedDisk(patchDiskPath, 1, rootDisk.getBusType());
|
||||
} else {
|
||||
patchDisk.defFileBasedDisk(datadiskPath, 1, rootDisk.getBusType(),
|
||||
patchDisk.defFileBasedDisk(patchDiskPath, 1, rootDisk.getBusType(),
|
||||
DiskDef.diskFmtType.RAW);
|
||||
}
|
||||
|
||||
@ -2977,7 +2999,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
|
||||
String bootArgs = vmSpec.getBootArgs();
|
||||
|
||||
patchSystemVm(bootArgs, datadiskPath, vmName);
|
||||
patchSystemVm(bootArgs, patchDiskPath, vmName);
|
||||
}
|
||||
|
||||
private void createVif(LibvirtVMDef vm, NicTO nic)
|
||||
|
||||
@ -73,6 +73,10 @@ public class KVMStoragePoolManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean deleteVbdByPath(String diskPath) {
|
||||
return this._storageAdaptor.deleteVbdByPath(diskPath);
|
||||
}
|
||||
|
||||
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, String name,
|
||||
KVMStoragePool destPool) {
|
||||
if (destPool.getType() == StoragePoolType.RBD) {
|
||||
|
||||
@ -882,4 +882,21 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean deleteVbdByPath(String diskPath) {
|
||||
Connect conn;
|
||||
try {
|
||||
conn = LibvirtConnection.getConnection();
|
||||
StorageVol vol = conn.storageVolLookupByPath(diskPath);
|
||||
if(vol != null) {
|
||||
s_logger.debug("requested delete disk " + diskPath);
|
||||
vol.delete(0);
|
||||
}
|
||||
} catch (LibvirtException e) {
|
||||
s_logger.debug("Libvirt error in attempting to find and delete patch disk:" + e.toString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -65,4 +65,6 @@ public interface StorageAdaptor {
|
||||
|
||||
public boolean createFolder(String uuid, String path);
|
||||
|
||||
public boolean deleteVbdByPath(String path);
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user