Skip to content

Commit 05d3f86

Browse files
author
Marcus Sorensen
committed
Summary: Fix orphaned patch disks for system VMs on KVM
Detail: This patch deletes any patchdisk found when deleting root volume for system VM. BUG-ID: CLOUDSTACK-566 Bugfix-for: 4.0.1 Signed-off-by: Marcus Sorensen <marcus@betterservers.com> 1354222335 -0700
1 parent 5aad7cc commit 05d3f86

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,25 @@ public Answer execute(DestroyCommand cmd) {
12711271
KVMStoragePool pool = _storagePoolMgr.getStoragePool(vol
12721272
.getPoolUuid());
12731273
pool.deletePhysicalDisk(vol.getPath());
1274+
String vmName = cmd.getVmName();
1275+
String poolPath = pool.getLocalPath();
1276+
1277+
/* if vol is a root disk for a system vm, try to remove accompanying patch disk as well
1278+
this is a bit tricky since the patchdisk is only a LibvirtComputingResource construct
1279+
and not tracked anywhere in cloudstack */
1280+
if (vol.getType() == Volume.Type.ROOT && vmName.matches("^[rsv]-\\d+-.+$")) {
1281+
File patchVbd = new File(poolPath + File.separator + vmName + "-patchdisk");
1282+
if(patchVbd.exists()){
1283+
try {
1284+
_storagePoolMgr.deleteVbdByPath(patchVbd.getAbsolutePath());
1285+
} catch(CloudRuntimeException e) {
1286+
s_logger.warn("unable to destroy patch disk '" + patchVbd.getAbsolutePath() +
1287+
"' while removing root disk for " + vmName + " : " + e);
1288+
}
1289+
} else {
1290+
s_logger.debug("file '" +patchVbd.getAbsolutePath()+ "' not found");
1291+
}
1292+
}
12741293

12751294
return new Answer(cmd, true, "Success");
12761295
} catch (CloudRuntimeException e) {
@@ -2651,14 +2670,7 @@ protected Answer execute(StopCommand cmd) {
26512670
if (disk.getDeviceType() == DiskDef.deviceType.CDROM
26522671
&& disk.getDiskPath() != null) {
26532672
cleanupDisk(conn, disk);
2654-
} /* The clean up of patch disks should probably be done in expunge
2655-
else if (disk.getDiskPath() != null
2656-
&& disk.getDiskPath().contains(vmName + "-patchdisk")
2657-
&& vmName.matches("^[rsv]-\\d+-VM$")) {
2658-
if (!_storagePoolMgr.deleteVbdByPath(disk.getDiskPath())) {
2659-
s_logger.warn("failed to delete patch disk " + disk.getDiskPath());
2660-
}
2661-
}*/
2673+
}
26622674
}
26632675
for (InterfaceDef iface: ifaces) {
26642676
_vifDriver.unplug(iface);

0 commit comments

Comments
 (0)