Skip to content

Commit 190b201

Browse files
committed
clvm deletion called explicitly
1 parent 4984ee5 commit 190b201

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,16 +1425,18 @@ public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.Imag
14251425
}
14261426
}
14271427

1428+
// For CLVM pools, always use direct LVM cleanup to ensure secure zero-fill
1429+
if (pool.getType() == StoragePoolType.CLVM) {
1430+
logger.info("CLVM pool detected - using direct LVM cleanup with secure zero-fill for volume {}", uuid);
1431+
return cleanupCLVMVolume(uuid, pool);
1432+
}
1433+
1434+
// For non-CLVM pools, use libvirt deletion
14281435
LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool;
14291436
try {
14301437
StorageVol vol = getVolume(libvirtPool.getPool(), uuid);
14311438
if (vol == null) {
14321439
logger.warn("Volume {} not found in libvirt pool {}, it may have been already deleted", uuid, pool.getUuid());
1433-
1434-
// For CLVM, attempt direct LVM cleanup in case the volume exists but libvirt can't see it
1435-
if (pool.getType() == StoragePoolType.CLVM) {
1436-
return cleanupCLVMVolume(uuid, pool);
1437-
}
14381440
return true;
14391441
}
14401442
logger.debug("Instructing libvirt to remove volume {} from pool {}", uuid, pool.getUuid());
@@ -1446,11 +1448,6 @@ public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.Imag
14461448
vol.free();
14471449
return true;
14481450
} catch (LibvirtException e) {
1449-
// For CLVM, if libvirt fails, try direct LVM cleanup
1450-
if (pool.getType() == StoragePoolType.CLVM) {
1451-
logger.warn("Libvirt failed to delete CLVM volume {}, attempting direct LVM cleanup: {}", uuid, e.getMessage());
1452-
return cleanupCLVMVolume(uuid, pool);
1453-
}
14541451
throw new CloudRuntimeException(e.toString());
14551452
}
14561453
}
@@ -2043,7 +2040,6 @@ private void secureZeroFillVolume(String lvPath, String volumeUuid) {
20432040
logger.info("Successfully zero-filled CLVM volume {} using blkdiscard (TRIM)", volumeUuid);
20442041
blkdiscardSuccess = true;
20452042
} else {
2046-
// Check if the error is "Operation not supported" - common with thick LVM without TRIM support
20472043
if (result.contains("Operation not supported") || result.contains("BLKDISCARD ioctl failed")) {
20482044
logger.info("blkdiscard not supported for volume {} (device doesn't support TRIM/DISCARD), using dd fallback", volumeUuid);
20492045
} else {
@@ -2054,15 +2050,13 @@ private void secureZeroFillVolume(String lvPath, String volumeUuid) {
20542050
logger.warn("Exception during blkdiscard for volume {}: {}, will try dd fallback", volumeUuid, e.getMessage());
20552051
}
20562052

2057-
// Fallback to dd zero-fill (slow but thorough)
2053+
// Fallback to dd zero-fill (slow)
20582054
if (!blkdiscardSuccess) {
20592055
logger.info("Attempting zero-fill using dd for CLVM volume: {}", volumeUuid);
20602056
try {
2061-
// Use bash to chain commands with proper error handling
20622057
// nice -n 19: lowest CPU priority
20632058
// ionice -c 2 -n 7: best-effort I/O scheduling with lowest priority
20642059
// oflag=direct: bypass cache for more predictable performance
2065-
// || true at the end ensures the command doesn't fail even if dd returns error (which it does when disk is full - expected)
20662060
String command = String.format(
20672061
"nice -n 19 ionice -c 2 -n 7 dd if=/dev/zero of=%s bs=1M oflag=direct 2>&1 || true",
20682062
lvPath
@@ -2076,7 +2070,6 @@ private void secureZeroFillVolume(String lvPath, String volumeUuid) {
20762070
String ddResult = ddZeroFill.execute(parser);
20772071
String output = parser.getLines();
20782072

2079-
// dd writes to stderr even on success, check for completion indicators
20802073
if (output != null && (output.contains("copied") || output.contains("records in") ||
20812074
output.contains("No space left on device"))) {
20822075
logger.info("Successfully zero-filled CLVM volume {} using dd", volumeUuid);
@@ -2087,7 +2080,6 @@ private void secureZeroFillVolume(String lvPath, String volumeUuid) {
20872080
output != null ? output : ddResult);
20882081
}
20892082
} catch (Exception e) {
2090-
// Log warning but don't fail the deletion - zero-fill is a best-effort security measure
20912083
logger.warn("Failed to zero-fill CLVM volume {} before deletion: {}. Proceeding with deletion anyway.",
20922084
volumeUuid, e.getMessage());
20932085
}

0 commit comments

Comments
 (0)