CA-324782: Select the right memory SR otherwise the PVS cache appears as not configured.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2019-08-06 09:34:12 +01:00 committed by Mihaela Stoica
parent 9cfc7ff8d3
commit c0d6b409e2

View File

@ -69,26 +69,18 @@ namespace XenAdmin.Controls
MAX_CACHE_SIZE_GB);
origCacheSizeGb = numericUpDownCacheSize.Value;
PopulateCacheSrCombobox();
ReadOnly = OrigPvsCacheStorage != null && OrigPvsCacheStorage.IsInUse();
comboBoxCacheSr.Enabled = numericUpDownCacheSize.Enabled = !ReadOnly;
}
private void PopulateCacheSrCombobox()
{
comboBoxCacheSr.Items.Clear();
// add the "Not configured" item first
var notConfiguredItem = new SrComboBoxItem(null, Messages.PVS_CACHE_NOT_CONFIGURED);
comboBoxCacheSr.Items.Add(notConfiguredItem);
comboBoxCacheSr.SelectedItem = notConfiguredItem;
// add Memeory SR; if no memory SR found, add a placeholder (we will create the memory SR in ConfigurePvsCacheAction)
var memorySr =
Host.Connection.Cache.SRs.FirstOrDefault(
s => s.GetSRType(false) == SR.SRTypes.tmpfs && s.CanBeSeenFrom(Host));
// add Memory SR; if no memory SR found, add a placeholder (we will create the memory SR in ConfigurePvsCacheAction)
var memorySrs = Host.Connection.Cache.SRs.Where(s => s.GetSRType(false) == SR.SRTypes.tmpfs && s.CanBeSeenFrom(Host)).ToList();
if (memorySr == null)
SR memorySr = null;
if (memorySrs.Count == 0)
{
// create a placeholder for the memory SR
memorySr = new SR
@ -99,11 +91,20 @@ namespace XenAdmin.Controls
opaque_ref = Helper.NullOpaqueRef
};
}
else
{
if (OrigPvsCacheStorage != null)
memorySr = memorySrs.FirstOrDefault(sr => sr.opaque_ref == OrigPvsCacheStorage.SR.opaque_ref);
if (memorySr == null)
memorySr = memorySrs.First();
}
var enabled = Host.dom0_memory_extra() >= MIN_CACHE_SIZE_GB * Util.BINARY_GIGA;
var label = enabled ? Messages.PVS_CACHE_MEMORY_ONLY : Messages.PVS_CACHE_MEMORY_ONLY_DISABLED;
var memorySrItem = new SrComboBoxItem(memorySr, label, enabled);
comboBoxCacheSr.Items.Add(memorySrItem);
if (OrigPvsCacheStorage != null && memorySr.opaque_ref == OrigPvsCacheStorage.SR.opaque_ref)
comboBoxCacheSr.SelectedItem = memorySrItem;
@ -117,6 +118,12 @@ namespace XenAdmin.Controls
if (OrigPvsCacheStorage != null && sr.opaque_ref == OrigPvsCacheStorage.SR.opaque_ref)
comboBoxCacheSr.SelectedItem = newItem;
}
if (comboBoxCacheSr.SelectedItem == null)
comboBoxCacheSr.SelectedItem = notConfiguredItem;
ReadOnly = OrigPvsCacheStorage != null && OrigPvsCacheStorage.IsInUse();
comboBoxCacheSr.Enabled = numericUpDownCacheSize.Enabled = !ReadOnly;
}
private bool SrIsSuitableForPvsCache(SR sr)