Blame SOURCES/0011-saveconfig-dump-control-string-containing-control-va.patch

4959d3
From eff378068812503ee2394baffba37b5cadd9a0f7 Mon Sep 17 00:00:00 2001
4959d3
From: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
4959d3
Date: Fri, 6 Apr 2018 13:03:28 +0530
4959d3
Subject: [PATCH] saveconfig: dump control string containing control=value
4959d3
 tuples
4959d3
4959d3
Problem:
4959d3
-------
4959d3
$ targetcli /backstores/user:glfs create blockX1 1073741824 \
4959d3
  test@192.168.124.227/block-store/e59309bb-d591-4121-a891-e98ff3416446,max_data_area_mb=32
4959d3
4959d3
$ targetcli / saveconfig
4959d3
4959d3
$ cat /etc/target/saveconfig.json
4959d3
{
4959d3
  "storage_objects": [
4959d3
    {
4959d3
      "alua_tpgs": [],
4959d3
      "attributes": {
4959d3
        ...
4959d3
      },
4959d3
      "config": "glfs/test@192.168.124.227/block-store/e59309bb-d591-4121-a891-e98ff3416446",
4959d3
      "hw_max_sectors": 128,
4959d3
      "name": "blockX1",
4959d3
      "plugin": "user",
4959d3
      "size": 1073741824,
4959d3
      "wwn": "3aa072d6-a007-45a3-8eac-e85b53655515"
4959d3
    }
4959d3
  ],
4959d3
  "targets": []
4959d3
}
4959d3
4959d3
Note max_data_area_mb is not dumped into the configfile and hence on restart of
4959d3
target service or node reboot this storageObject property is lost.
4959d3
4959d3
Fix:
4959d3
----
4959d3
This patch make sure to dump control string containing control=value tuples, like:
4959d3
$ cat /etc/target/saveconfig.json
4959d3
{
4959d3
  ...
4959d3
  "config": "glfs/test@192.168.124.227/block-store/e59309bb-d591-4121-a891-e98ff3416446",
4959d3
  "control": "max_data_area_mb=32",
4959d3
  ...
4959d3
}
4959d3
4959d3
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
4959d3
---
4959d3
 rtslib/tcm.py | 14 ++++++++++++++
4959d3
 1 file changed, 14 insertions(+)
4959d3
4959d3
diff --git a/rtslib/tcm.py b/rtslib/tcm.py
4959d3
index efe685a..4feb738 100644
4959d3
--- a/rtslib/tcm.py
4959d3
+++ b/rtslib/tcm.py
4959d3
@@ -845,6 +845,17 @@ class UserBackedStorageObject(StorageObject):
4959d3
         self._check_self()
4959d3
         return int(self._parse_info('HwMaxSectors'))
4959d3
 
4959d3
+    def _get_control_tuples(self):
4959d3
+        self._check_self()
4959d3
+        tuples = []
4959d3
+        # 1. max_data_area_mb
4959d3
+        val = self._parse_info('MaxDataAreaMB')
4959d3
+        if val != "NULL":
4959d3
+            tuples.append("max_data_area_mb=%s" % val)
4959d3
+        # 2. add next ...
4959d3
+
4959d3
+        return ",".join(tuples)
4959d3
+
4959d3
     def _get_config(self):
4959d3
         self._check_self()
4959d3
         val = self._parse_info('Config')
4959d3
@@ -858,6 +869,8 @@ class UserBackedStorageObject(StorageObject):
4959d3
 
4959d3
     hw_max_sectors = property(_get_hw_max_sectors,
4959d3
             doc="Get the max sectors per command.")
4959d3
+    control_tuples = property(_get_control_tuples,
4959d3
+            doc="Get the comma separated string containing control=value tuples.")
4959d3
     size = property(_get_size,
4959d3
             doc="Get the size in bytes.")
4959d3
     config = property(_get_config,
4959d3
@@ -871,6 +884,7 @@ class UserBackedStorageObject(StorageObject):
4959d3
         d['size'] = self.size
4959d3
         d['config'] = self.config
4959d3
         d['hw_max_sectors'] = self.hw_max_sectors
4959d3
+        d['control'] = self.control_tuples
4959d3
 
4959d3
         return d
4959d3
 
4959d3
-- 
4959d3
1.8.3.1
4959d3