Blame SOURCES/BZ_1524490_fix_megaraid_cache.patch

ad4da3
From 7ecf84e7958cd901b5190073afb6204f1d9c73e7 Mon Sep 17 00:00:00 2001
ad4da3
From: Gris Ge <fge@redhat.com>
ad4da3
Date: Fri, 8 Dec 2017 19:03:42 +0800
ad4da3
Subject: [PATCH 1/3] MegaRAID plugin: Fix cache information query.
ad4da3
ad4da3
 * MegaRAID always enable read cache. Old code treat that as read ahead
ad4da3
   cache which is not what we defined in API document.
ad4da3
ad4da3
 * Fix the write cache set function to handle 'Cache I/O'.
ad4da3
ad4da3
 * Inform user via volume_read_cache_policy_update(): read cache is
ad4da3
   always enabled, if they are looking for read ahead cache setting, they
ad4da3
   should use storcli/perccli.
ad4da3
ad4da3
Signed-off-by: Gris Ge <fge@redhat.com>
ad4da3
---
ad4da3
 plugin/megaraid/megaraid.py | 77 ++++++++++++++++++++++++++++-----------------
ad4da3
 1 file changed, 48 insertions(+), 29 deletions(-)
ad4da3
ad4da3
diff --git a/plugin/megaraid/megaraid.py b/plugin/megaraid/megaraid.py
ad4da3
index 8982ff9a..25b900da 100644
ad4da3
--- a/plugin/megaraid/megaraid.py
ad4da3
+++ b/plugin/megaraid/megaraid.py
ad4da3
@@ -1067,9 +1067,6 @@ def volume_cache_info(self, volume, flags=Client.FLAG_RSVD):
ad4da3
         sys_all_output = self._storcli_exec(
ad4da3
             ["/%s" % vd_path.split('/')[1], "show", "all"])
ad4da3
 
ad4da3
-        write_cache_status = Volume.WRITE_CACHE_STATUS_WRITE_THROUGH
ad4da3
-        read_cache_status = Volume.READ_CACHE_STATUS_DISABLED
ad4da3
-
ad4da3
         ram_size = _mega_size_to_lsm(
ad4da3
             sys_all_output['HwCfg'].get('On Board Memory Size', '0 KB'))
ad4da3
         if ram_size > 0:
ad4da3
@@ -1081,36 +1078,42 @@ def volume_cache_info(self, volume, flags=Client.FLAG_RSVD):
ad4da3
                 flag_battery_ok = True
ad4da3
 
ad4da3
         lsi_cache_setting = vd_basic_info['Cache']
ad4da3
-        if lsi_cache_setting[0] == 'R':
ad4da3
-            read_cache_policy = Volume.READ_CACHE_POLICY_ENABLED
ad4da3
-            if flag_has_ram:
ad4da3
-                read_cache_status = Volume.READ_CACHE_STATUS_ENABLED
ad4da3
-        elif lsi_cache_setting[0:2] == 'NR':
ad4da3
-            read_cache_policy = Volume.READ_CACHE_POLICY_DISABLED
ad4da3
-        else:
ad4da3
-            raise LsmError(
ad4da3
-                ErrorNumber.PLUGIN_BUG,
ad4da3
-                "Unknown read cache %s for volume %s" %
ad4da3
-                (lsi_cache_setting, vd_path))
ad4da3
+        # According to MegaRAID document, read I/O is always cached for direct
ad4da3
+        # I/O and cache I/O.
ad4da3
+        read_cache_policy = Volume.READ_CACHE_POLICY_ENABLED
ad4da3
+        write_cache_status = Volume.WRITE_CACHE_STATUS_WRITE_THROUGH
ad4da3
+        read_cache_status = Volume.READ_CACHE_STATUS_DISABLED
ad4da3
 
ad4da3
-        if 'AWB' in lsi_cache_setting:
ad4da3
+        if lsi_cache_setting.endswith('D'):
ad4da3
+            # Direct I/O
ad4da3
+            if 'AWB' in lsi_cache_setting:
ad4da3
+                write_cache_policy = Volume.WRITE_CACHE_POLICY_WRITE_BACK
ad4da3
+            elif 'WB' in lsi_cache_setting:
ad4da3
+                write_cache_policy = Volume.WRITE_CACHE_POLICY_AUTO
ad4da3
+            elif 'WT' in lsi_cache_setting:
ad4da3
+                write_cache_policy = Volume.WRITE_CACHE_POLICY_WRITE_THROUGH
ad4da3
+            else:
ad4da3
+                raise LsmError(
ad4da3
+                    ErrorNumber.PLUGIN_BUG,
ad4da3
+                    "Unknown write cache %s for volume %s" %
ad4da3
+                    (lsi_cache_setting, vd_path))
ad4da3
+        elif lsi_cache_setting.endswith('C'):
ad4da3
+            # cache I/O always caches write and read and ignore changes.
ad4da3
             write_cache_policy = Volume.WRITE_CACHE_POLICY_WRITE_BACK
ad4da3
-            if flag_has_ram:
ad4da3
-                write_cache_status = Volume.WRITE_CACHE_STATUS_WRITE_BACK
ad4da3
-        elif 'WB' in lsi_cache_setting:
ad4da3
-            # This mode means enable write cache when battery or CacheVault
ad4da3
-            # is healthy.
ad4da3
-            write_cache_policy = Volume.WRITE_CACHE_POLICY_AUTO
ad4da3
-            if flag_has_ram and flag_battery_ok:
ad4da3
-                write_cache_status = Volume.WRITE_CACHE_STATUS_WRITE_BACK
ad4da3
-        elif 'WT' in lsi_cache_setting:
ad4da3
-            write_cache_policy = Volume.WRITE_CACHE_POLICY_WRITE_THROUGH
ad4da3
         else:
ad4da3
             raise LsmError(
ad4da3
                 ErrorNumber.PLUGIN_BUG,
ad4da3
-                "Unknown write cache %s for volume %s" %
ad4da3
+                "Unknown I/O type %s for volume %s" %
ad4da3
                 (lsi_cache_setting, vd_path))
ad4da3
 
ad4da3
+        if flag_has_ram:
ad4da3
+            read_cache_status = Volume.READ_CACHE_STATUS_ENABLED
ad4da3
+            if write_cache_policy == Volume.WRITE_CACHE_POLICY_WRITE_BACK:
ad4da3
+                write_cache_status = Volume.WRITE_CACHE_STATUS_WRITE_BACK
ad4da3
+            elif write_cache_policy == Volume.WRITE_CACHE_POLICY_AUTO:
ad4da3
+                if flag_battery_ok:
ad4da3
+                    write_cache_status = Volume.WRITE_CACHE_STATUS_WRITE_BACK
ad4da3
+
ad4da3
         # TODO(Gris Ge): When 'Block SSD Write Disk Cache Change' of
ad4da3
         #                'Supported Adapter Operations' is 'Yes'
ad4da3
         lsi_disk_cache_setting = vd_prop_info['Disk Cache Policy']
ad4da3
@@ -1162,12 +1165,27 @@ def volume_write_cache_policy_update(self, volume, wcp,
ad4da3
         """
ad4da3
         Depending on "storcli /c0/vX set wrcache=<wt|wb|awb>" command.
ad4da3
         """
ad4da3
-        cmd = [_vd_path_of_lsm_vol(volume), "set"]
ad4da3
+        vd_path = _vd_path_of_lsm_vol(volume)
ad4da3
+        # Check whether we are working on cache I/O which ignore write cache
ad4da3
+        # setting and always cache write.
ad4da3
+        vol_show_output = self._storcli_exec([vd_path, "show", "all"])
ad4da3
+        vd_basic_info = vol_show_output[vd_path][0]
ad4da3
+        lsi_cache_setting = vd_basic_info['Cache']
ad4da3
+        if lsi_cache_setting.endswith('C'):
ad4da3
+            flag_cache_io = True
ad4da3
+        else:
ad4da3
+            flag_cache_io = False
ad4da3
+
ad4da3
+        cmd = [vd_path, "set"]
ad4da3
         if wcp == Volume.WRITE_CACHE_POLICY_WRITE_BACK:
ad4da3
             cmd.append("wrcache=awb")
ad4da3
         elif wcp == Volume.WRITE_CACHE_POLICY_AUTO:
ad4da3
+            if flag_cache_io:
ad4da3
+                self._storcli_exec([vd_path, "set", "iopolicy=Direct"])
ad4da3
             cmd.append("wrcache=wb")
ad4da3
         elif wcp == Volume.WRITE_CACHE_POLICY_WRITE_THROUGH:
ad4da3
+            if flag_cache_io:
ad4da3
+                self._storcli_exec([vd_path, "set", "iopolicy=Direct"])
ad4da3
             cmd.append("wrcache=wt")
ad4da3
         else:
ad4da3
             raise LsmError(ErrorNumber.PLUGIN_BUG,
ad4da3
@@ -1181,8 +1199,9 @@ def volume_read_cache_policy_update(self, volume, rcp,
ad4da3
         storcli always enable read cache and no way to change it
ad4da3
         """
ad4da3
         raise LsmError(ErrorNumber.NO_SUPPORT,
ad4da3
-                       "LSI MegaRAID always enable read cache and refused to "
ad4da3
-                       "change that.")
ad4da3
+                       "MegaRAID always enable read cache and refused to "
ad4da3
+                       "change that. You can change read ahead cache "
ad4da3
+                       "setting via storcli/perccli")
ad4da3
 
ad4da3
     @_handle_errors
ad4da3
     def volume_delete(self, volume, flags=Client.FLAG_RSVD):
ad4da3
ad4da3
From 9502647282e4ccb18aa41933cb8471c61240fa36 Mon Sep 17 00:00:00 2001
ad4da3
From: Gris Ge <fge@redhat.com>
ad4da3
Date: Fri, 8 Dec 2017 19:04:45 +0800
ad4da3
Subject: [PATCH 2/3] MegaRAID plugin: PEP8 clean up
ad4da3
ad4da3
Signed-off-by: Gris Ge <fge@redhat.com>
ad4da3
---
ad4da3
 plugin/megaraid/megaraid.py | 6 ++++--
ad4da3
 1 file changed, 4 insertions(+), 2 deletions(-)
ad4da3
ad4da3
diff --git a/plugin/megaraid/megaraid.py b/plugin/megaraid/megaraid.py
ad4da3
index 25b900da..c317c11d 100644
ad4da3
--- a/plugin/megaraid/megaraid.py
ad4da3
+++ b/plugin/megaraid/megaraid.py
ad4da3
@@ -85,6 +85,7 @@ def _disk_type_of(disk_show_basic_dict):
ad4da3
 
ad4da3
     return Disk.TYPE_UNKNOWN
ad4da3
 
ad4da3
+
ad4da3
 _DISK_STATE_MAP = {
ad4da3
     'Onln': Disk.STATUS_OK,
ad4da3
     'Offln': Disk.STATUS_ERROR,
ad4da3
@@ -409,7 +410,7 @@ def plugin_info(self, flags=Client.FLAG_RSVD):
ad4da3
 
ad4da3
     @_handle_errors
ad4da3
     def time_out_set(self, ms, flags=Client.FLAG_RSVD):
ad4da3
-        self._tmo_ms = ms # TODO(Gris Ge): Not implemented yet.
ad4da3
+        self._tmo_ms = ms  # TODO(Gris Ge): Not implemented yet.
ad4da3
 
ad4da3
     @_handle_errors
ad4da3
     def time_out_get(self, flags=Client.FLAG_RSVD):
ad4da3
@@ -874,7 +875,8 @@ def _vcr_cap_get(self, mega_sys_path):
ad4da3
         supported_strip_sizes = list(
ad4da3
             min_strip_size * (2 ** i)
ad4da3
             for i in range(
ad4da3
-                0, int(math.log(int_div(max_strip_size, min_strip_size), 2) + 1)))
ad4da3
+                0, int(math.log(int_div(max_strip_size, min_strip_size), 2)
ad4da3
+                       + 1)))
ad4da3
 
ad4da3
         # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ad4da3
         # The math above is to generate a list like:
ad4da3
ad4da3
From 0dd64bd71093cf480317251628f66bd4b99ca2a1 Mon Sep 17 00:00:00 2001
ad4da3
From: Gris Ge <fge@redhat.com>
ad4da3
Date: Fri, 8 Dec 2017 19:05:16 +0800
ad4da3
Subject: [PATCH 3/3] MegaRAID plugin: Be consistent on vd_path extraction.
ad4da3
ad4da3
 * Always use _vd_path_of_lsm_vol() to extract private data to vd_path.
ad4da3
ad4da3
Signed-off-by: Gris Ge <fge@redhat.com>
ad4da3
---
ad4da3
 plugin/megaraid/megaraid.py | 2 +-
ad4da3
 1 file changed, 1 insertion(+), 1 deletion(-)
ad4da3
ad4da3
diff --git a/plugin/megaraid/megaraid.py b/plugin/megaraid/megaraid.py
ad4da3
index c317c11d..13c05b52 100644
ad4da3
--- a/plugin/megaraid/megaraid.py
ad4da3
+++ b/plugin/megaraid/megaraid.py
ad4da3
@@ -760,7 +760,7 @@ def volume_raid_info(self, volume, flags=Client.FLAG_RSVD):
ad4da3
                 ErrorNumber.INVALID_ARGUMENT,
ad4da3
                 "Ilegal input volume argument: missing plugin_data property")
ad4da3
 
ad4da3
-        vd_path = volume.plugin_data
ad4da3
+        vd_path = _vd_path_of_lsm_vol(volume)
ad4da3
         vol_show_output = self._storcli_exec([vd_path, "show", "all"])
ad4da3
         vd_basic_info = vol_show_output[vd_path][0]
ad4da3
         vd_id = int(vd_basic_info['DG/VD'].split('/')[-1])