summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar Gohad <tushar.gohad@intel.com>2015-09-08 02:04:01 -0700
committerTushar Gohad <tushar.gohad@intel.com>2015-09-08 02:04:01 -0700
commitb77449ef90e48507ecda8fd859848156ca4dc4dc (patch)
tree141dc56bdabcab2939442f9dde92f9d3e8e85c9d
parentb1c63c6a34cfa0a3679c5081c95a50ba324c5004 (diff)
downloadpyeclib-flat_xor_hd_4.tar.gz
Allow 'flat_xor_hd_4' from external APIflat_xor_hd_4
Add 'hd' argument back to the internal API
-rw-r--r--pyeclib/core.py17
-rw-r--r--pyeclib/ec_iface.py14
-rw-r--r--test/test_pyeclib_api.py14
3 files changed, 28 insertions, 17 deletions
diff --git a/pyeclib/core.py b/pyeclib/core.py
index e4a2d3c..e233915 100644
--- a/pyeclib/core.py
+++ b/pyeclib/core.py
@@ -34,13 +34,13 @@ pyver = float('%s.%s' % sys.version_info[:2])
class ECPyECLibDriver(object):
- def __init__(self, k, m, ec_type,
+ def __init__(self, k, m, hd, ec_type,
chksum_type=PyECLib_FRAGHDRCHKSUM_Types.none):
self.k = k
self.m = m
+ self.hd = hd
self.ec_type = ec_type
self.chksum_type = chksum_type
- hd = m
self.inline_chksum = 0
self.algsig_chksum = 0
@@ -50,16 +50,11 @@ class ECPyECLibDriver(object):
name = self.ec_type.name
- if name == "flat_xor_hd" or name == "flat_xor_hd_3":
- hd = 3
- if name == "flat_xor_hd_4":
- hd = 4
-
self.handle = pyeclib_c.init(
self.k,
self.m,
ec_type.value,
- hd,
+ self.hd,
self.inline_chksum,
self.algsig_chksum)
@@ -141,9 +136,10 @@ class ECPyECLibDriver(object):
class ECNullDriver(object):
- def __init__(self, k, m, ec_type=None, chksum_type=None):
+ def __init__(self, k, m, hd, ec_type=None, chksum_type=None):
self.k = k
self.m = m
+ self.hd = hd
def encode(self, data_bytes):
pass
@@ -177,7 +173,7 @@ class ECNullDriver(object):
#
class ECStripingDriver(object):
- def __init__(self, k, m, ec_type=None, chksum_type=None):
+ def __init__(self, k, m, hd, ec_type=None, chksum_type=None):
"""Stripe an arbitrary-sized string into k fragments
:param k: the number of data fragments to stripe
:param m: the number of parity fragments to stripe
@@ -189,6 +185,7 @@ class ECStripingDriver(object):
raise ECDriverError("This driver only supports m=0")
self.m = m
+ self.hd = hd
def encode(self, data_bytes):
"""Stripe an arbitrary-sized string into k fragments
diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py
index 2c67848..29bd63b 100644
--- a/pyeclib/ec_iface.py
+++ b/pyeclib/ec_iface.py
@@ -117,6 +117,7 @@ class ECDriver(object):
def __init__(self, *args, **kwargs):
self.k = -1
self.m = -1
+ self.hd = -1
self.ec_type = None
self.chksum_type = None
for (key, value) in kwargs.items():
@@ -133,11 +134,14 @@ class ECDriver(object):
raise ECDriverError(
"Invalid number of data fragments (m)")
elif key == "ec_type":
- if value in ["flat_xor_hd_3", "flat_xor_hd_4"]:
+ if value in ["flat_xor_hd", "flat_xor_hd_3", "flat_xor_hd_4"]:
+ if value == "flat_xor_hd" or value == "flat_xor_hd_3":
+ self.hd = 3
+ elif value == "flat_xor_hd_4":
+ self.hd = 4
value = "flat_xor_hd"
if PyECLib_EC_Types.has_enum(value):
- self.ec_type = \
- PyECLib_EC_Types.get_by_name(value)
+ self.ec_type = PyECLib_EC_Types.get_by_name(value)
else:
raise ECBackendNotSupported(
"%s is not a valid EC type for PyECLib!" % value)
@@ -149,6 +153,9 @@ class ECDriver(object):
raise ECDriverError(
"%s is not a valid checksum type for PyECLib!" % value)
+ if self.hd == -1:
+ self.hd = self.m
+
self.library_import_str = kwargs.pop('library_import_str',
'pyeclib.core.ECPyECLibDriver')
#
@@ -158,6 +165,7 @@ class ECDriver(object):
self.library_import_str,
k=self.k,
m=self.m,
+ hd=self.hd,
ec_type=self.ec_type,
chksum_type=self.chksum_type)
#
diff --git a/test/test_pyeclib_api.py b/test/test_pyeclib_api.py
index f16ecbc..3244bcd 100644
--- a/test/test_pyeclib_api.py
+++ b/test/test_pyeclib_api.py
@@ -150,11 +150,17 @@ class TestPyECLibDriver(unittest.TestCase):
chksum_type=csum))
pyeclib_drivers.append(ECDriver(k=8, m=4, ec_type=_type2,
chksum_type=csum))
- _type3 = 'flat_xor_hd'
- if _type3 in _available_backends:
- pyeclib_drivers.append(ECDriver(k=12, m=6, ec_type=_type3,
+ _type3_1 = 'flat_xor_hd'
+ if _type3_1 in _available_backends:
+ pyeclib_drivers.append(ECDriver(k=12, m=6, ec_type=_type3_1,
chksum_type=csum))
- pyeclib_drivers.append(ECDriver(k=10, m=5, ec_type=_type3,
+ pyeclib_drivers.append(ECDriver(k=10, m=5, ec_type=_type3_1,
+ chksum_type=csum))
+ _type3_2 = 'flat_xor_hd_4'
+ if _type3_2 in _available_backends:
+ pyeclib_drivers.append(ECDriver(k=12, m=6, ec_type=_type3_2,
+ chksum_type=csum))
+ pyeclib_drivers.append(ECDriver(k=10, m=5, ec_type=_type3_2,
chksum_type=csum))
_type4 = 'shss'
if _type4 in _available_backends: