mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	CLOUDSTACK-7315: Set LXC volumes format as DIR. Use rm command to delete LXC volumes. Libvirt delete volume does not handle directories
This commit is contained in:
		
							parent
							
								
									9ab78b7eb2
								
							
						
					
					
						commit
						30ecf935e8
					
				| @ -32,7 +32,8 @@ public class Storage { | |||||||
|         BAREMETAL(false, false, false, "BAREMETAL"), |         BAREMETAL(false, false, false, "BAREMETAL"), | ||||||
|         VMDK(true, true, false, "vmdk"), |         VMDK(true, true, false, "vmdk"), | ||||||
|         VDI(true, true, false, "vdi"), |         VDI(true, true, false, "vdi"), | ||||||
|         TAR(false, false, false, "tar"); |         TAR(false, false, false, "tar"), | ||||||
|  |         DIR(false, false, false, "dir"); | ||||||
| 
 | 
 | ||||||
|         private final boolean supportThinProvisioning; |         private final boolean supportThinProvisioning; | ||||||
|         private final boolean supportSparse; |         private final boolean supportSparse; | ||||||
|  | |||||||
| @ -1908,10 +1908,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv | |||||||
| 
 | 
 | ||||||
|     public Answer execute(DestroyCommand cmd) { |     public Answer execute(DestroyCommand cmd) { | ||||||
|         VolumeTO vol = cmd.getVolume(); |         VolumeTO vol = cmd.getVolume(); | ||||||
| 
 |  | ||||||
|         try { |         try { | ||||||
|             KVMStoragePool pool = _storagePoolMgr.getStoragePool(vol.getPoolType(), vol.getPoolUuid()); |             KVMStoragePool pool = _storagePoolMgr.getStoragePool(vol.getPoolType(), vol.getPoolUuid()); | ||||||
|             pool.deletePhysicalDisk(vol.getPath()); |             pool.deletePhysicalDisk(vol.getPath(), null); | ||||||
|             return new Answer(cmd, true, "Success"); |             return new Answer(cmd, true, "Success"); | ||||||
|         } catch (CloudRuntimeException e) { |         } catch (CloudRuntimeException e) { | ||||||
|             s_logger.debug("Failed to delete volume: " + e.toString()); |             s_logger.debug("Failed to delete volume: " + e.toString()); | ||||||
|  | |||||||
| @ -327,7 +327,7 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean deletePhysicalDisk(String volumeUuid, KVMStoragePool pool) { |     public boolean deletePhysicalDisk(String volumeUuid, KVMStoragePool pool, Storage.ImageFormat format) { | ||||||
|         throw new UnsupportedOperationException("Deleting a physical disk is not supported."); |         throw new UnsupportedOperationException("Deleting a physical disk is not supported."); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -115,8 +115,8 @@ public class IscsiAdmStoragePool implements KVMStoragePool { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean deletePhysicalDisk(String volumeUuid) { |     public boolean deletePhysicalDisk(String volumeUuid, Storage.ImageFormat format) { | ||||||
|         return this._storageAdaptor.deletePhysicalDisk(volumeUuid, this); |         return this._storageAdaptor.deletePhysicalDisk(volumeUuid, this, format); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // does not apply for iScsiAdmStoragePool |     // does not apply for iScsiAdmStoragePool | ||||||
|  | |||||||
| @ -35,7 +35,7 @@ public interface KVMStoragePool { | |||||||
| 
 | 
 | ||||||
|     public boolean disconnectPhysicalDisk(String volumeUuid); |     public boolean disconnectPhysicalDisk(String volumeUuid); | ||||||
| 
 | 
 | ||||||
|     public boolean deletePhysicalDisk(String volumeUuid); |     public boolean deletePhysicalDisk(String volumeUuid, Storage.ImageFormat format); | ||||||
| 
 | 
 | ||||||
|     public List<KVMPhysicalDisk> listPhysicalDisks(); |     public List<KVMPhysicalDisk> listPhysicalDisks(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -347,6 +347,8 @@ public class KVMStorageProcessor implements StorageProcessor { | |||||||
|                 newVol.setFormat(ImageFormat.RAW); |                 newVol.setFormat(ImageFormat.RAW); | ||||||
|             } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) { |             } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) { | ||||||
|                 newVol.setFormat(ImageFormat.QCOW2); |                 newVol.setFormat(ImageFormat.QCOW2); | ||||||
|  |             } else if (vol.getFormat() == PhysicalDiskFormat.DIR) { | ||||||
|  |                 newVol.setFormat(ImageFormat.DIR); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             return new CopyCmdAnswer(newVol); |             return new CopyCmdAnswer(newVol); | ||||||
| @ -1203,7 +1205,7 @@ public class KVMStorageProcessor implements StorageProcessor { | |||||||
|                 s_logger.debug("can't find volume: " + vol.getPath() + ", return true"); |                 s_logger.debug("can't find volume: " + vol.getPath() + ", return true"); | ||||||
|                 return new Answer(null); |                 return new Answer(null); | ||||||
|             } |             } | ||||||
|             pool.deletePhysicalDisk(vol.getPath()); |             pool.deletePhysicalDisk(vol.getPath(), vol.getFormat()); | ||||||
|             return new Answer(null); |             return new Answer(null); | ||||||
|         } catch (CloudRuntimeException e) { |         } catch (CloudRuntimeException e) { | ||||||
|             s_logger.debug("Failed to delete volume: ", e); |             s_logger.debug("Failed to delete volume: ", e); | ||||||
|  | |||||||
| @ -796,7 +796,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool) { |     public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.ImageFormat format) { | ||||||
| 
 | 
 | ||||||
|         s_logger.info("Attempting to remove volume " + uuid + " from pool " + pool.getUuid()); |         s_logger.info("Attempting to remove volume " + uuid + " from pool " + pool.getUuid()); | ||||||
| 
 | 
 | ||||||
| @ -849,7 +849,11 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { | |||||||
|         try { |         try { | ||||||
|             StorageVol vol = getVolume(libvirtPool.getPool(), uuid); |             StorageVol vol = getVolume(libvirtPool.getPool(), uuid); | ||||||
|             s_logger.debug("Instructing libvirt to remove volume " + uuid + " from pool " + pool.getUuid()); |             s_logger.debug("Instructing libvirt to remove volume " + uuid + " from pool " + pool.getUuid()); | ||||||
|  |             if(Storage.ImageFormat.DIR.equals(format)){ | ||||||
|  |                 deleteDirVol(libvirtPool, vol); | ||||||
|  |             } else { | ||||||
|                 deleteVol(libvirtPool, vol); |                 deleteVol(libvirtPool, vol); | ||||||
|  |             } | ||||||
|             vol.free(); |             vol.free(); | ||||||
|             return true; |             return true; | ||||||
|         } catch (LibvirtException e) { |         } catch (LibvirtException e) { | ||||||
| @ -1315,4 +1319,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { | |||||||
|         vol.delete(0); |         vol.delete(0); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private void deleteDirVol(LibvirtStoragePool pool, StorageVol vol) throws LibvirtException { | ||||||
|  |         Script.runSimpleBashScript("rm -r --interactive=never " + vol.getPath()); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -171,8 +171,8 @@ public class LibvirtStoragePool implements KVMStoragePool { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean deletePhysicalDisk(String uuid) { |     public boolean deletePhysicalDisk(String uuid, Storage.ImageFormat format) { | ||||||
|         return this._storageAdaptor.deletePhysicalDisk(uuid, this); |         return this._storageAdaptor.deletePhysicalDisk(uuid, this, format); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | |||||||
| @ -49,7 +49,7 @@ public interface StorageAdaptor { | |||||||
|     // handled by your adaptor, return false if not. 2) clean up device, return true |     // handled by your adaptor, return false if not. 2) clean up device, return true | ||||||
|     public boolean disconnectPhysicalDiskByPath(String localPath); |     public boolean disconnectPhysicalDiskByPath(String localPath); | ||||||
| 
 | 
 | ||||||
|     public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool); |     public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.ImageFormat format); | ||||||
| 
 | 
 | ||||||
|     public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, |     public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, | ||||||
|             String name, PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, |             String name, PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user