Gris Ge
2015-05-01 14:44:51 UTC
* The Volume.vpd83 property is designed to match Linux SCSI ID.
In practice, it should match "ID_WWN" value of udev information.
It could be check via command:
udevadm info --query=all /dev/sda
* In udev code, the "ID_WWN" is VPD 0x83 NAA (identifier type 3) information.
* In SPC-3 and later version, the VPD 0x83 NAA is allowed in these formats:
Type | Type Name | Size | Code Set
-----+--------------------------+-------+--------------
2h | IEEE Extended | 08h | 1h(binary)
3h | Local Assigned | 08h | 1h(binary)
5h | IEEE Registered | 08h | 1h(binary)
6h | IEEE Registered Extended | 10h | 1h(binary)
Note: The '3h(local assigned)' is defined in SPC-4.
In spc4r37.pdf, page 757, section 7.8.6.6 NAA designator format.
* It's clear our VPD 0x83 string verification method is incorrect.
This patch is to enforce above limitation:
1. String start with 6 should with string size 32.
2. String start with 2,3,5 should with string size 16.
3. String not start with 2,3,5,6 is illegal.
Signed-off-by: Gris Ge <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 19 ++++++++++++-------
python_binding/lsm/_data.py | 6 +++---
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index cbe57fe..6e6d8a6 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -118,15 +118,20 @@ int lsm_volume_vpd83_verify( const char *vpd83 )
int rc = LSM_ERR_INVALID_ARGUMENT;
int i;
- if( vpd83 && strlen(vpd83) == 32 ) {
- for(i = 0; i < 32; ++i) {
- char v = vpd83[i];
- // 0-9 || a-f is OK
- if( !((v >= 48 && v <= 57) || (v >= 97 && v <= 102)) ) {
- return rc;
+ if( vpd83 ){
+ if( (strlen(vpd83) == 32 && vpd83[0] == '6' ) ||
+ (strlen(vpd83) == 16 && vpd83[0] == '2' ) ||
+ (strlen(vpd83) == 16 && vpd83[0] == '3' ) ||
+ (strlen(vpd83) == 16 && vpd83[0] == '5' ) {
+ for(i = 0; i < strlen(vpd83); ++i) {
+ char v = vpd83[i];
+ // 0-9 || a-f is OK
+ if( !((v >= 48 && v <= 57) || (v >= 97 && v <= 102)) ) {
+ return rc;
+ }
}
+ rc = LSM_ERR_OK;
}
- rc = LSM_ERR_OK;
}
return rc;
}
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 0e16311..7b470ff 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -232,7 +232,7 @@ def __str__(self):
# Lets do this once outside of the class to minimize the number of
# times it needs to be compiled.
-_vol_regex_vpd83 = re.compile('^[0-9a-f]{32}$')
+_vol_regex_vpd83 = re.compile('(?:^6[0-9a-f]{31})|(?:^[2356][0-9a-f]{15})$')
@default_property('id', doc="Unique identifier")
@@ -314,8 +314,8 @@ def __init__(self, _id, _name, _vpd83, _block_size, _num_of_blocks,
self._name = _name # Human recognisable name
if _vpd83 and not Volume.vpd83_verify(_vpd83):
raise LsmError(ErrorNumber.INVALID_ARGUMENT,
- "Incorrect format of VPD 0x83 string: '%s', "
- "expecting 32 lower case hex characters" %
+ "Incorrect format of VPD 0x83 NAA(3) string: '%s', "
+ "expecting 32 or 16 lower case hex characters" %
_vpd83)
self._vpd83 = _vpd83 # SCSI page 83 unique ID
self._block_size = _block_size # Block size
In practice, it should match "ID_WWN" value of udev information.
It could be check via command:
udevadm info --query=all /dev/sda
* In udev code, the "ID_WWN" is VPD 0x83 NAA (identifier type 3) information.
* In SPC-3 and later version, the VPD 0x83 NAA is allowed in these formats:
Type | Type Name | Size | Code Set
-----+--------------------------+-------+--------------
2h | IEEE Extended | 08h | 1h(binary)
3h | Local Assigned | 08h | 1h(binary)
5h | IEEE Registered | 08h | 1h(binary)
6h | IEEE Registered Extended | 10h | 1h(binary)
Note: The '3h(local assigned)' is defined in SPC-4.
In spc4r37.pdf, page 757, section 7.8.6.6 NAA designator format.
* It's clear our VPD 0x83 string verification method is incorrect.
This patch is to enforce above limitation:
1. String start with 6 should with string size 32.
2. String start with 2,3,5 should with string size 16.
3. String not start with 2,3,5,6 is illegal.
Signed-off-by: Gris Ge <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 19 ++++++++++++-------
python_binding/lsm/_data.py | 6 +++---
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index cbe57fe..6e6d8a6 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -118,15 +118,20 @@ int lsm_volume_vpd83_verify( const char *vpd83 )
int rc = LSM_ERR_INVALID_ARGUMENT;
int i;
- if( vpd83 && strlen(vpd83) == 32 ) {
- for(i = 0; i < 32; ++i) {
- char v = vpd83[i];
- // 0-9 || a-f is OK
- if( !((v >= 48 && v <= 57) || (v >= 97 && v <= 102)) ) {
- return rc;
+ if( vpd83 ){
+ if( (strlen(vpd83) == 32 && vpd83[0] == '6' ) ||
+ (strlen(vpd83) == 16 && vpd83[0] == '2' ) ||
+ (strlen(vpd83) == 16 && vpd83[0] == '3' ) ||
+ (strlen(vpd83) == 16 && vpd83[0] == '5' ) {
+ for(i = 0; i < strlen(vpd83); ++i) {
+ char v = vpd83[i];
+ // 0-9 || a-f is OK
+ if( !((v >= 48 && v <= 57) || (v >= 97 && v <= 102)) ) {
+ return rc;
+ }
}
+ rc = LSM_ERR_OK;
}
- rc = LSM_ERR_OK;
}
return rc;
}
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 0e16311..7b470ff 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -232,7 +232,7 @@ def __str__(self):
# Lets do this once outside of the class to minimize the number of
# times it needs to be compiled.
-_vol_regex_vpd83 = re.compile('^[0-9a-f]{32}$')
+_vol_regex_vpd83 = re.compile('(?:^6[0-9a-f]{31})|(?:^[2356][0-9a-f]{15})$')
@default_property('id', doc="Unique identifier")
@@ -314,8 +314,8 @@ def __init__(self, _id, _name, _vpd83, _block_size, _num_of_blocks,
self._name = _name # Human recognisable name
if _vpd83 and not Volume.vpd83_verify(_vpd83):
raise LsmError(ErrorNumber.INVALID_ARGUMENT,
- "Incorrect format of VPD 0x83 string: '%s', "
- "expecting 32 lower case hex characters" %
+ "Incorrect format of VPD 0x83 NAA(3) string: '%s', "
+ "expecting 32 or 16 lower case hex characters" %
_vpd83)
self._vpd83 = _vpd83 # SCSI page 83 unique ID
self._block_size = _block_size # Block size
--
1.8.3.1
1.8.3.1