diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java index f37e2c5437c..9de02fd6119 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -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 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*/ diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtStorageResource.java index 4783bb060cc..c26a029bbbe 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtStorageResource.java @@ -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);