mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Persist disk chain info when we detach a volume, check disk chain info when we attach a volume, this is required when snapshot operations are involved in vwmare
This commit is contained in:
parent
54e53f2037
commit
cc7dc5e6be
@ -1338,7 +1338,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||
vol = primaryPool.storageVolCreateXML(volDef.toString(), 0);
|
||||
|
||||
}
|
||||
VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(), getStorageResourceType(), pool.getType(), pool.getPath(), vol.getName(),vol.getKey(), disksize);
|
||||
VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(), getStorageResourceType(), pool.getType(), pool.getPath(), vol.getName(),vol.getKey(), disksize, null);
|
||||
return new CreateAnswer(cmd, volume);
|
||||
} catch (LibvirtException e) {
|
||||
|
||||
|
||||
@ -37,8 +37,9 @@ public class VolumeTO {
|
||||
private StoragePoolType storagePoolType;
|
||||
private long poolId;
|
||||
private int deviceId;
|
||||
private String chainInfo;
|
||||
|
||||
public VolumeTO(long id, Volume.VolumeType type, Storage.StorageResourceType resourceType, StoragePoolType poolType, String name, String mountPoint, String path, long size) {
|
||||
public VolumeTO(long id, Volume.VolumeType type, Storage.StorageResourceType resourceType, StoragePoolType poolType, String name, String mountPoint, String path, long size, String chainInfo) {
|
||||
this.id = id;
|
||||
this.name= name;
|
||||
this.path = path;
|
||||
@ -47,6 +48,7 @@ public class VolumeTO {
|
||||
this.resourceType = resourceType;
|
||||
this.storagePoolType = poolType;
|
||||
this.mountPoint = mountPoint;
|
||||
this.chainInfo = chainInfo;
|
||||
}
|
||||
|
||||
public VolumeTO(Volume volume, StoragePool pool) {
|
||||
@ -58,6 +60,7 @@ public class VolumeTO {
|
||||
this.resourceType = volume.getStorageResourceType();
|
||||
this.storagePoolType = pool.getPoolType();
|
||||
this.mountPoint = volume.getFolder();
|
||||
this.chainInfo = volume.getChainInfo();
|
||||
}
|
||||
|
||||
|
||||
@ -97,6 +100,10 @@ public class VolumeTO {
|
||||
return storagePoolType;
|
||||
}
|
||||
|
||||
public String getChainInfo() {
|
||||
return chainInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("Vol[").append(id).append("|").append(type).append("|").append(path).append("|").append(size).append("]").toString();
|
||||
|
||||
@ -161,4 +161,6 @@ public interface Volume extends ControlledEntity, BasedOn {
|
||||
boolean getDestroyed();
|
||||
|
||||
long getDiskOfferingId();
|
||||
|
||||
String getChainInfo();
|
||||
}
|
||||
|
||||
@ -4,6 +4,6 @@
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/console"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/console-common"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/console"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/console-common"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/xmlrpc-common-3.1.3.jar"/>
|
||||
|
||||
@ -20,6 +20,7 @@ package com.cloud.agent.api;
|
||||
|
||||
public class AttachVolumeAnswer extends Answer {
|
||||
private Long deviceId;
|
||||
private String chainInfo;
|
||||
|
||||
protected AttachVolumeAnswer() {
|
||||
|
||||
@ -40,10 +41,19 @@ public class AttachVolumeAnswer extends Answer {
|
||||
super(cmd);
|
||||
this.deviceId = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the deviceId
|
||||
*/
|
||||
public Long getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setChainInfo(String chainInfo) {
|
||||
this.chainInfo = chainInfo;
|
||||
}
|
||||
|
||||
public String getChainInfo() {
|
||||
return chainInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,11 +30,12 @@ public class AttachVolumeCommand extends Command {
|
||||
String volumePath;
|
||||
String volumeName;
|
||||
Long deviceId;
|
||||
String chainInfo;
|
||||
|
||||
protected AttachVolumeCommand() {
|
||||
}
|
||||
|
||||
public AttachVolumeCommand(boolean attach, String vmName, StoragePoolType pooltype, String volumeFolder, String volumePath, String volumeName, Long deviceId) {
|
||||
public AttachVolumeCommand(boolean attach, String vmName, StoragePoolType pooltype, String volumeFolder, String volumePath, String volumeName, Long deviceId, String chainInfo) {
|
||||
this.attach = attach;
|
||||
this.vmName = vmName;
|
||||
this.pooltype = pooltype;
|
||||
@ -42,6 +43,7 @@ public class AttachVolumeCommand extends Command {
|
||||
this.volumePath = volumePath;
|
||||
this.volumeName = volumeName;
|
||||
this.deviceId = deviceId;
|
||||
this.chainInfo = chainInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,4 +94,8 @@ public class AttachVolumeCommand extends Command {
|
||||
public void setPoolUuid(String poolUuid) {
|
||||
this.poolUuid = poolUuid;
|
||||
}
|
||||
|
||||
public String getChainInfo() {
|
||||
return chainInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,8 @@ public class DestroyCommand extends StorageCommand {
|
||||
}
|
||||
|
||||
public DestroyCommand(StoragePoolVO pool, VMTemplateStoragePoolVO templatePoolRef) {
|
||||
volume = new VolumeTO(templatePoolRef.getId(), null, Storage.StorageResourceType.STORAGE_POOL, pool.getPoolType(), null, pool.getPath(), templatePoolRef.getInstallPath(), templatePoolRef.getTemplateSize());
|
||||
volume = new VolumeTO(templatePoolRef.getId(), null, Storage.StorageResourceType.STORAGE_POOL, pool.getPoolType(), null,
|
||||
pool.getPath(), templatePoolRef.getInstallPath(), templatePoolRef.getTemplateSize(), null);
|
||||
}
|
||||
|
||||
public VolumeTO getVolume() {
|
||||
|
||||
@ -4710,7 +4710,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
|
||||
s_logger.debug("Succesfully created VDI for " + cmd + ". Uuid = " + vdir.uuid);
|
||||
|
||||
VolumeTO vol = new VolumeTO(cmd.getVolumeId(), dskch.getType(), Storage.StorageResourceType.STORAGE_POOL, pool.getType(), vdir.nameLabel, pool.getPath(), vdir.uuid,
|
||||
vdir.virtualSize);
|
||||
vdir.virtualSize, null);
|
||||
return new CreateAnswer(cmd, vol);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to create volume; Pool=" + pool + "; Disk: " + dskch, e);
|
||||
|
||||
@ -160,6 +160,9 @@ public class VolumeVO implements Volume {
|
||||
@Column(name="source_id")
|
||||
Long sourceId;
|
||||
|
||||
@Column(name="chain_info")
|
||||
String chainInfo;
|
||||
|
||||
/**
|
||||
* Constructor for data disk.
|
||||
* @param type
|
||||
@ -559,5 +562,13 @@ public class VolumeVO implements Volume {
|
||||
public void setAttached(Date attached){
|
||||
this.attached = attached;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getChainInfo() {
|
||||
return this.chainInfo;
|
||||
}
|
||||
|
||||
public void setChainInfo(String chainInfo) {
|
||||
this.chainInfo = chainInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@ -561,7 +561,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
||||
|
||||
if (sendCommand) {
|
||||
StoragePoolVO volumePool = _storagePoolDao.findById(volume.getPoolId());
|
||||
AttachVolumeCommand cmd = new AttachVolumeCommand(true, vm.getInstanceName(), volume.getPoolType(), volume.getFolder(), volume.getPath(), volume.getName(), deviceId);
|
||||
AttachVolumeCommand cmd = new AttachVolumeCommand(true, vm.getInstanceName(), volume.getPoolType(), volume.getFolder(), volume.getPath(), volume.getName(), deviceId, volume.getChainInfo());
|
||||
cmd.setPoolUuid(volumePool.getUuid());
|
||||
|
||||
try {
|
||||
@ -694,7 +694,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
||||
Answer answer = null;
|
||||
|
||||
if (sendCommand) {
|
||||
AttachVolumeCommand cmd = new AttachVolumeCommand(false, vm.getInstanceName(), volume.getPoolType(), volume.getFolder(), volume.getPath(), volume.getName(), cmmd.getDeviceId() != null ? cmmd.getDeviceId() : volume.getDeviceId());
|
||||
AttachVolumeCommand cmd = new AttachVolumeCommand(false, vm.getInstanceName(), volume.getPoolType(), volume.getFolder(), volume.getPath(), volume.getName(),
|
||||
cmmd.getDeviceId() != null ? cmmd.getDeviceId() : volume.getDeviceId(), volume.getChainInfo());
|
||||
|
||||
StoragePoolVO volumePool = _storagePoolDao.findById(volume.getPoolId());
|
||||
cmd.setPoolUuid(volumePool.getUuid());
|
||||
@ -715,11 +716,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
||||
if (!sendCommand || (answer != null && answer.getResult())) {
|
||||
// Mark the volume as detached
|
||||
_volsDao.detachVolume(volume.getId());
|
||||
if(!vm.getHostName().equals(vm.getDisplayName())) {
|
||||
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getHostName()+"("+vm.getDisplayName()+")");
|
||||
} else {
|
||||
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getHostName());
|
||||
}
|
||||
if(answer != null && answer instanceof AttachVolumeAnswer) {
|
||||
volume.setChainInfo(((AttachVolumeAnswer)answer).getChainInfo());
|
||||
_volsDao.update(volume.getId(), volume);
|
||||
}
|
||||
|
||||
if(!vm.getHostName().equals(vm.getDisplayName()))
|
||||
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getHostName()+"("+vm.getDisplayName()+")");
|
||||
else
|
||||
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getHostName());
|
||||
event.setLevel(EventVO.LEVEL_INFO);
|
||||
_eventDao.persist(event);
|
||||
|
||||
|
||||
@ -322,6 +322,7 @@ CREATE TABLE `cloud`.`volumes` (
|
||||
`state` varchar(32) COMMENT 'State machine',
|
||||
`source_id` bigint unsigned COMMENT 'id for the source',
|
||||
`source_type` varchar(32) COMMENT 'source from which the volume is created -- snapshot, diskoffering, template, blank',
|
||||
`chain_info` text COMMENT 'save possible disk chain info in primary storage',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user