CA-280322: Space requirement calculation error in migration wizard. (#1934)

* CA-280322: Space requirement calculation error in migration wizard.

* Fix comments.

Signed-off-by: Michael Zhao <michael.zhao@citrix.com>
This commit is contained in:
Michael 2018-02-05 18:07:24 +08:00 committed by Mihaela Stoica
parent 0f31a6f857
commit 6a6931dbd5
5 changed files with 68 additions and 24 deletions

View File

@ -62,10 +62,20 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
return sr != null && !sr.HBALunPerVDI();
}
/// <summary>
/// Gets the page's title (headline)
/// </summary>
public override string PageTitle { get { return Messages.CPM_WIZARD_SELECT_STORAGE_PAGE_TITLE; } }
protected override bool IsExtraSpaceNeeded(XenRef<SR> sourceRef, XenRef<SR> targetRef)
{
// No extra space is needed for Migrate or Move operation on same SR.
if (targetRef.Equals(sourceRef) &&
((wizardMode == WizardMode.Migrate) || (wizardMode == WizardMode.Move)))
return false;
else
return true;
}
/// <summary>
/// Gets the page's title (headline)
/// </summary>
public override string PageTitle { get { return Messages.CPM_WIZARD_SELECT_STORAGE_PAGE_TITLE; } }
/// <summary>
/// Gets the page's label in the (left hand side) wizard progress panel

View File

@ -83,7 +83,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
get { return vdi.opaque_ref; }
}
public bool SRTypeInvalid
public bool SRTypeInvalid
{
get { return false;}
}
@ -97,6 +97,11 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
{
get { return Convert.ToUInt64(vdi.physical_utilisation); }
}
}
public XenRef<SR> SR
{
get { return vdi.SR; }
}
}
}

View File

@ -53,7 +53,10 @@ namespace XenAdmin.Wizards.GenericPages
private class StorageDetail
{
public string SysId { get; set; }
public ulong RequiredSpace { get; set; }
public IStorageResource ResourceData { get; set; }
public ulong RequiredSpace {
get { return (ResourceData == null) ? 0 : ResourceData.RequiredDiskCapacity; }
}
}
private class EnableableSrComboboxItem : IEnableableXenObjectComboBoxItem
@ -98,7 +101,6 @@ namespace XenAdmin.Wizards.GenericPages
#region Private fields
private Dictionary<string, ulong> m_spaceRequirements = new Dictionary<string, ulong>();
private ulong m_totalSpaceRequired;
private Dictionary<string, VmMapping> m_vmMappings;
private bool m_buttonNextEnabled;
private bool m_buttonPreviousEnabled;
@ -196,9 +198,14 @@ namespace XenAdmin.Wizards.GenericPages
return true;
}
public override void PopulatePage()
protected virtual bool IsExtraSpaceNeeded(XenRef<SR> sourceRef, XenRef<SR> targetRef)
{
return true;
}
public override void PopulatePage()
{
m_totalSpaceRequired = 0;
m_dataGridView.Rows.Clear();
m_ctrlError.HideError();
bool checkSpaceRequirements = true;
@ -220,8 +227,6 @@ namespace XenAdmin.Wizards.GenericPages
if(!resourceData.CanCalculateDiskCapacity)
continue;
m_totalSpaceRequired += resourceData.RequiredDiskCapacity;
string disklabel = !string.IsNullOrEmpty(resourceData.DiskLabel)
? string.Format("{0} - {1}", vmMapping.VmNameLabel, resourceData.DiskLabel)
: string.Format("{0} - {1} {2}", vmMapping.VmNameLabel, Messages.STORAGE_DISK, i);
@ -229,7 +234,7 @@ namespace XenAdmin.Wizards.GenericPages
var cellVmDisk = new DataGridViewTextBoxCell
{
Tag = new StorageDetail
{RequiredSpace = resourceData.RequiredDiskCapacity, SysId = sysId},
{SysId = sysId, ResourceData = resourceData},
Value = FormatDiskValueText(resourceData, disklabel)
};
@ -284,9 +289,23 @@ namespace XenAdmin.Wizards.GenericPages
private void PopulateSrComboBox(List<ToStringWrapper<SR>> commonSRs)
{
List<EnableableSrComboboxItem> listToAdd =
commonSRs.Select(toStringWrapper => new EnableableSrComboboxItem(toStringWrapper, m_totalSpaceRequired)).ToList();
List<EnableableSrComboboxItem> listToAdd = new List<EnableableSrComboboxItem>();
foreach (var toStringWrapper in commonSRs)
{
ulong requiredSpace = 0;
foreach (var kvp in m_vmMappings)
{
foreach (IStorageResource resourceData in ResourceData(kvp.Key))
{
if (IsExtraSpaceNeeded(resourceData.SR, new XenRef<SR>(toStringWrapper.item)))
{
requiredSpace += resourceData.RequiredDiskCapacity;
}
}
}
listToAdd.Add(new EnableableSrComboboxItem(toStringWrapper, requiredSpace));
}
if (listToAdd.Any(item => item.Enabled))
{
var sortedlistToAdd = from item in listToAdd
@ -409,11 +428,15 @@ namespace XenAdmin.Wizards.GenericPages
var storageDetail = (StorageDetail)row.Cells[0].Tag;
string uuid = selectedItem.item.uuid;
ulong requiredSpace =
IsExtraSpaceNeeded(storageDetail.ResourceData.SR, new XenRef<SR>(selectedItem.item))
? storageDetail.RequiredSpace
: 0;
if (m_spaceRequirements.ContainsKey(uuid))
m_spaceRequirements[uuid] += storageDetail.RequiredSpace;
m_spaceRequirements[uuid] += requiredSpace;
else
m_spaceRequirements.Add(uuid, storageDetail.RequiredSpace);
m_spaceRequirements.Add(uuid, requiredSpace);
if ((ulong)selectedItem.item.FreeSpace() <= m_spaceRequirements[uuid])
{
@ -444,8 +467,8 @@ namespace XenAdmin.Wizards.GenericPages
continue;
bool srOnHost = pbd.host != null && pbd.host.Equals(xenRef);
if ((sr.shared || srOnHost) && (ulong)sr.FreeSpace() > resource.RequiredDiskCapacity && SrIsSuitable(sr))
if ((sr.shared || srOnHost) && (!IsExtraSpaceNeeded(resource.SR, pbd.SR) || (ulong)sr.FreeSpace() > resource.RequiredDiskCapacity) && SrIsSuitable(sr))
{
var count = (from ToStringWrapper<SR> existingItem in cb.Items
where existingItem.item.opaque_ref == sr.opaque_ref
@ -460,8 +483,6 @@ namespace XenAdmin.Wizards.GenericPages
cb.Value = newItem;
//store items to populate the m_comboBoxSr
//note that at this point the m_totalSpaceRequired is not the final value yet,
//but we can add the check to get a smaller list
if ((sr.shared || (targetRefs.Count == 1 && srOnHost && targetRefs[0].Equals(xenRef))))
{

View File

@ -30,6 +30,7 @@
*/
using System.Collections;
using XenAPI;
namespace XenAdmin.Wizards.GenericPages
{
@ -40,6 +41,7 @@ namespace XenAdmin.Wizards.GenericPages
bool SRTypeInvalid { get; }
ulong RequiredDiskCapacity { get; }
bool CanCalculateDiskCapacity { get; }
XenRef<SR> SR { get; }
}
public abstract class StorageResourceContainer : IEnumerable

View File

@ -31,6 +31,7 @@
using System;
using XenAdmin.Wizards.GenericPages;
using XenAPI;
using XenOvf;
using XenOvf.Definitions;
@ -114,5 +115,10 @@ namespace XenAdmin.Wizards.ImportWizard
: file.size;
}
}
}
public XenRef<SR> SR
{
get { return null; }
}
}
}