From a6f6b775fdf74ff19d7b463f05415b0a769a09c2 Mon Sep 17 00:00:00 2001 From: Stephen Turner Date: Mon, 16 Mar 2015 19:54:55 +0000 Subject: [PATCH] CA-163782: Read the read-caching reason from the server --- XenAdmin/TabPages/GeneralTabPage.cs | 4 ++- XenModel/Messages.Designer.cs | 28 ++++++++++++--- XenModel/Messages.resx | 18 ++++++---- XenModel/XenAPI-Extensions/VDI.cs | 27 +++++++++++---- XenModel/XenAPI-Extensions/VM.cs | 53 ++++++++++++++++++----------- 5 files changed, 92 insertions(+), 38 deletions(-) diff --git a/XenAdmin/TabPages/GeneralTabPage.cs b/XenAdmin/TabPages/GeneralTabPage.cs index 230e02258..8292667f3 100644 --- a/XenAdmin/TabPages/GeneralTabPage.cs +++ b/XenAdmin/TabPages/GeneralTabPage.cs @@ -1400,7 +1400,9 @@ namespace XenAdmin.TabPages else { s.AddEntry(FriendlyName("VM.read_caching_status"), Messages.VM_READ_CACHING_DISABLED); - s.AddEntry(FriendlyName("VM.read_caching_reason"), vm.ReadCachingDisabledReason); + var reason = vm.ReadCachingDisabledReason; + if (reason != null) + s.AddEntry(FriendlyName("VM.read_caching_reason"), reason); } } diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 412c40c5f..1de89f0b7 100644 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -33884,7 +33884,7 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to This VM is not using Read Caching. + /// Looks up a localized string similar to This VM is not using read caching. /// public static string VM_READ_CACHING_DISABLED { get { @@ -33893,7 +33893,7 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to Not licensed for Read Caching. + /// Looks up a localized string similar to This pool is not licensed for read caching. /// public static string VM_READ_CACHING_DISABLED_REASON_LICENSE { get { @@ -33902,7 +33902,25 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to Read Caching is not supported on any of the Storage Repositories used by this VM. + /// Looks up a localized string similar to This VM does not have any read-only disks or disks with a read-only parent. + /// + public static string VM_READ_CACHING_DISABLED_REASON_NO_RO_IMAGE { + get { + return ResourceManager.GetString("VM_READ_CACHING_DISABLED_REASON_NO_RO_IMAGE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to This pool was not licensed for read caching when the VM was started. + /// + public static string VM_READ_CACHING_DISABLED_REASON_PREV_LICENSE { + get { + return ResourceManager.GetString("VM_READ_CACHING_DISABLED_REASON_PREV_LICENSE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Read caching is not supported on the type of Storage Repository used by this VM. /// public static string VM_READ_CACHING_DISABLED_REASON_SR_TYPE { get { @@ -33911,7 +33929,7 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to Read Caching is disabled on all supported Storage Repositories used by this VM. + /// Looks up a localized string similar to Read caching has been disabled on the Storage Repository used by this VM. /// public static string VM_READ_CACHING_DISABLED_REASON_TURNED_OFF { get { @@ -33920,7 +33938,7 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to This VM has Read Caching enabled. + /// Looks up a localized string similar to This VM is using read caching. /// public static string VM_READ_CACHING_ENABLED { get { diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 0eb51c1be..3b2cdabb7 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -11736,19 +11736,25 @@ To learn more about the XenServer Dynamic Workload Balancing feature or to start Succeeded - This VM is not using Read Caching + This VM is not using read caching - Not licensed for Read Caching + This pool is not licensed for read caching + + + This VM does not have any read-only disks or disks with a read-only parent + + + This pool was not licensed for read caching when the VM was started - Read Caching is not supported on any of the Storage Repositories used by this VM + Read caching is not supported on the type of Storage Repository used by this VM - Read Caching is disabled on all supported Storage Repositories used by this VM + Read caching has been disabled on the Storage Repository used by this VM - This VM has Read Caching enabled + This VM is using read caching Using read caching @@ -12680,4 +12686,4 @@ You will need to navigate to the Console on each of the selected VMs to complete You are here - + \ No newline at end of file diff --git a/XenModel/XenAPI-Extensions/VDI.cs b/XenModel/XenAPI-Extensions/VDI.cs index 0a8b3510b..34956ca9e 100644 --- a/XenModel/XenAPI-Extensions/VDI.cs +++ b/XenModel/XenAPI-Extensions/VDI.cs @@ -335,16 +335,31 @@ namespace XenAPI } /// - /// Whether read caching is supported on this disk + /// ... and if not, why not /// - public bool ReadCachingSupported + public ReadCachingDisabledReasonCode ReadCachingDisabledReason(Host host) { - get + string reasonstr; + if (sm_config.TryGetValue("read-caching-reason-" + host.uuid, out reasonstr)) { - var sr = Connection.Resolve(SR); - var srType = sr != null ? sr.GetSRType(false) : XenAPI.SR.SRTypes.unknown; - return srType == XenAPI.SR.SRTypes.ext || srType == XenAPI.SR.SRTypes.nfs; + ReadCachingDisabledReasonCode reason; + if (Enum.TryParse(reasonstr, out reason)) + return reason; } + return ReadCachingDisabledReasonCode.UNKNOWN; + } + + /// + /// Possible reasons for read caching being disabled + /// If there are multiple reasons, the topmost reason will be returned + /// + public enum ReadCachingDisabledReasonCode + { + UNKNOWN, // catch-all, shouldn't occur if read caching is disabled + LICENSE_RESTRICTION, // self-explanatory + SR_NOT_SUPPORTED, // the SR is not NFS or EXT + NO_RO_IMAGE, // no part of the VDI is read-only => nothing to cache + SR_OVERRIDE, // the feature has been explicitly disabled for the VDI's SR } } } diff --git a/XenModel/XenAPI-Extensions/VM.cs b/XenModel/XenAPI-Extensions/VM.cs index 2a9c3a383..c00ef0eb9 100644 --- a/XenModel/XenAPI-Extensions/VM.cs +++ b/XenModel/XenAPI-Extensions/VM.cs @@ -1760,32 +1760,45 @@ namespace XenAPI } } - /// - /// Whether the Read Caching is supported on any of the VDIs - /// - public bool ReadCachingSupported + public string ReadCachingDisabledReason { - get + // The code in VDI.ReadCachingDisabledReason returns the first matching reason from the list + // (LICENSE_RESTRICTION, SR_NOT_SUPPORTED, NO_RO_IMAGE, SR_OVERRIDE). In the case that there + // are several VDIs with different reasons, this function returns the last matching reason, + // because that is the VDI that is nearest to being read-cachable in some sense. As the reasons + // are stored in an enum, we can just use greater-than to find the last reason + get { + var ans = VDI.ReadCachingDisabledReasonCode.UNKNOWN; foreach (var vbd in Connection.ResolveAll(VBDs).Where(vbd => vbd != null && vbd.currently_attached)) { var vdi = Connection.Resolve(vbd.VDI); - if (vdi != null && vdi.ReadCachingSupported) - return true; + var resident_host = Connection.Resolve(resident_on); + if (vdi != null && resident_host != null && !vdi.ReadCachingEnabled(resident_host)) + { + var reason = vdi.ReadCachingDisabledReason(resident_host); + if (reason > ans) + ans = reason; + } + } + + switch (ans) + { + case VDI.ReadCachingDisabledReasonCode.LICENSE_RESTRICTION: + if (Helpers.FeatureForbidden(Connection, Host.RestrictReadCaching)) + return Messages.VM_READ_CACHING_DISABLED_REASON_LICENSE; + else + return Messages.VM_READ_CACHING_DISABLED_REASON_PREV_LICENSE; + case VDI.ReadCachingDisabledReasonCode.SR_NOT_SUPPORTED: + return Messages.VM_READ_CACHING_DISABLED_REASON_SR_TYPE; + case VDI.ReadCachingDisabledReasonCode.NO_RO_IMAGE: + return Messages.VM_READ_CACHING_DISABLED_REASON_NO_RO_IMAGE; + case VDI.ReadCachingDisabledReasonCode.SR_OVERRIDE: + return Messages.VM_READ_CACHING_DISABLED_REASON_TURNED_OFF; + default: + // should only happen transiently + return null; } - return false; - } - } - - public string ReadCachingDisabledReason - { - get - { - if (Helpers.FeatureForbidden(Connection, Host.RestrictReadCaching)) - return Messages.VM_READ_CACHING_DISABLED_REASON_LICENSE; - if (!ReadCachingSupported) - return Messages.VM_READ_CACHING_DISABLED_REASON_SR_TYPE; - return Messages.VM_READ_CACHING_DISABLED_REASON_TURNED_OFF; } } }