From 5a2e4fd0a22bc18594e9bac2e15fb4bc8804fa82 Mon Sep 17 00:00:00 2001 From: Devdeep Singh Date: Mon, 30 Dec 2013 23:46:56 +0530 Subject: [PATCH] CLOUDSTACK-5560: Reattach of data disk fails for hyperv. When a data disk is attached a hard disk drive is created on the scsi controller. On detach the data disk is removed from the drive but the disk drive is left behind. On reattach the agent was again trying to create a disk drive while it was already present. Fixed the agent code to look up for disk drive while attaching and if one is not found then only to create the drive for attaching a data disk. --- .../HypervResource/WmiCallsV2.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs index 6830fe338b7..2e3aca59675 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs @@ -591,7 +591,11 @@ namespace HypervResource } else { - ManagementPath newDrivePath = AttachDiskDriveToScsiController(vm, addressOnController); + ManagementPath newDrivePath = GetDiskDriveOnScsiController(vm, addressOnController); + if (newDrivePath == null) + { + newDrivePath = AttachDiskDriveToScsiController(vm, addressOnController); + } InsertDiskImage(vm, diskPath, HARDDISK_DISK, newDrivePath); } } @@ -779,10 +783,21 @@ namespace HypervResource return newResourcePaths[0]; } - private ManagementPath GetDiskDriveToScsiController(ComputerSystem vm, string addrOnController) + private ManagementPath GetDiskDriveOnScsiController(ComputerSystem vm, string addrOnController) { VirtualSystemSettingData vmSettings = GetVmSettings(vm); - var ctrller = GetScsiControllerSettings(vmSettings); + var wmiObjCollection = GetResourceAllocationSettings(vmSettings); + foreach (ResourceAllocationSettingData wmiObj in wmiObjCollection) + { + if (wmiObj.ResourceSubType == HARDDISK_DRIVE) + { + ResourceAllocationSettingData parent = new ResourceAllocationSettingData(new ManagementObject(wmiObj.Parent)); + if (parent.ResourceSubType == SCSI_CONTROLLER && wmiObj.AddressOnParent == addrOnController) + { + return wmiObj.Path; + } + } + } return null; }