fix creating ssvm data disk

This commit is contained in:
Edison Su 2011-01-31 16:01:56 -05:00
parent 5c319bab91
commit 200da6d39d
2 changed files with 16 additions and 6 deletions

View File

@ -2111,13 +2111,24 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
createPatchVbd(conn, vmName, vm, vmSpec);
}
}
private VolumeTO getVolume(VirtualMachineTO vmSpec, VolumeType type) {
VolumeTO volumes[] = vmSpec.getDisks();
for (VolumeTO volume : volumes) {
if (volume.getType() == type) {
return volume;
}
}
return null;
}
private void createPatchVbd(Connect conn, String vmName, LibvirtVMDef vm, VirtualMachineTO vmSpec) throws LibvirtException, InternalErrorException {
List<DiskDef> disks = vm.getDevices().getDisks();
DiskDef rootDisk = disks.get(0);
StorageVol tmplVol = _storageResource.createTmplDataDisk(conn, rootDisk.getDiskPath(), 10L * 1024 * 1024);
VolumeTO rootVol = getVolume(vmSpec, VolumeType.ROOT);
StoragePool pool = _storageResource.getStoragePool(conn, rootVol.getPoolUuid());
StorageVol tmplVol = _storageResource.createTmplDataDisk(conn, pool, 10L * 1024 * 1024);
String datadiskPath = tmplVol.getKey();
/*add patch disk*/

View File

@ -16,6 +16,7 @@ import org.libvirt.StorageVol;
import org.libvirt.StoragePoolInfo.StoragePoolState;
import com.cloud.agent.api.to.StorageFilerTO;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.agent.resource.computing.KVMHABase.PoolType;
import com.cloud.agent.resource.computing.LibvirtStoragePoolDef.poolType;
import com.cloud.agent.resource.computing.LibvirtStorageVolumeDef.volFormat;
@ -148,12 +149,10 @@ public class LibvirtStorageResource {
}
public StorageVol createTmplDataDisk(Connect conn, String rootkPath, long size) throws LibvirtException, InternalErrorException {
public StorageVol createTmplDataDisk(Connect conn, StoragePool pool, long size) throws LibvirtException, InternalErrorException {
/*create a templ data disk, to contain patches*/
StorageVol rootVol = conn.storageVolLookupByKey(rootkPath);
StoragePool rootPool = rootVol.storagePoolLookupByVolume();
LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), size, volFormat.RAW, null, null);
StorageVol dataVol = rootPool.storageVolCreateXML(volDef.toString(), 0);
StorageVol dataVol = pool.storageVolCreateXML(volDef.toString(), 0);
/*Format/create fs on this disk*/
final Script command = new Script(_createvmPath, _timeout, s_logger);