Gris Ge
2014-09-01 06:16:24 UTC
* Just convert UUID(vpd 0x80) to WWID(vpd 0x83) base on the LIO kernel code.
Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/targetd/targetd.py | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/plugin/targetd/targetd.py b/plugin/targetd/targetd.py
index 26537a5..a39d7b9 100644
--- a/plugin/targetd/targetd.py
+++ b/plugin/targetd/targetd.py
@@ -29,6 +29,7 @@ import json
import time
import urlparse
import socket
+import re
DEFAULT_USER = "admin"
DEFAULT_PORT = 18700
@@ -157,14 +158,32 @@ class TargetdStorage(IStorageAreaNetwork, INfs):
def job_free(self, job_id, flags=0):
raise LsmError(ErrorNumber.NO_SUPPORT, "Not supported")
+ @staticmethod
+ def _lio_uuid_to_vpd83(uuid):
+ """
+ This convension is based on linux kernel code:
+ drivers/target/target_core_spc.c:
+ spc_emulate_evpd_83()
+ spc_parse_naa_6h_vendor_specific()
+ Convert UUID (VPD 0x80) to VPD 0x83 32 hex digitals.
+ """
+ vpd83 = '6001405'
+ vpd83 += re.sub(r"""[^a-f0-9]""", '', uuid.lower())[0:25]
+ print vpd83
+ # Fill up with zero.
+ if len(vpd83) <= 32:
+ vpd83 += '0' * ( 32 - len(vpd83))
+ return vpd83
+
@handle_errors
def volumes(self, search_key=None, search_value=None, flags=0):
volumes = []
for p_name in (p['name'] for p in self._jsonrequest("pool_list") if
p['type'] == 'block'):
for vol in self._jsonrequest("vol_list", dict(pool=p_name)):
+ vpd83 = TargetdStorage._lio_uuid_to_vpd83(vol['uuid'])
volumes.append(
- Volume(vol['uuid'], vol['name'], vol['uuid'], 512,
+ Volume(vol['uuid'], vol['name'], vpd83, 512,
long(vol['size'] / 512),
Volume.ADMIN_STATE_ENABLED,
self.system.id, p_name))
Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/targetd/targetd.py | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/plugin/targetd/targetd.py b/plugin/targetd/targetd.py
index 26537a5..a39d7b9 100644
--- a/plugin/targetd/targetd.py
+++ b/plugin/targetd/targetd.py
@@ -29,6 +29,7 @@ import json
import time
import urlparse
import socket
+import re
DEFAULT_USER = "admin"
DEFAULT_PORT = 18700
@@ -157,14 +158,32 @@ class TargetdStorage(IStorageAreaNetwork, INfs):
def job_free(self, job_id, flags=0):
raise LsmError(ErrorNumber.NO_SUPPORT, "Not supported")
+ @staticmethod
+ def _lio_uuid_to_vpd83(uuid):
+ """
+ This convension is based on linux kernel code:
+ drivers/target/target_core_spc.c:
+ spc_emulate_evpd_83()
+ spc_parse_naa_6h_vendor_specific()
+ Convert UUID (VPD 0x80) to VPD 0x83 32 hex digitals.
+ """
+ vpd83 = '6001405'
+ vpd83 += re.sub(r"""[^a-f0-9]""", '', uuid.lower())[0:25]
+ print vpd83
+ # Fill up with zero.
+ if len(vpd83) <= 32:
+ vpd83 += '0' * ( 32 - len(vpd83))
+ return vpd83
+
@handle_errors
def volumes(self, search_key=None, search_value=None, flags=0):
volumes = []
for p_name in (p['name'] for p in self._jsonrequest("pool_list") if
p['type'] == 'block'):
for vol in self._jsonrequest("vol_list", dict(pool=p_name)):
+ vpd83 = TargetdStorage._lio_uuid_to_vpd83(vol['uuid'])
volumes.append(
- Volume(vol['uuid'], vol['name'], vol['uuid'], 512,
+ Volume(vol['uuid'], vol['name'], vpd83, 512,
long(vol['size'] / 512),
Volume.ADMIN_STATE_ENABLED,
self.system.id, p_name))
--
2.1.0
2.1.0