ec_iface: Store PyECLibEnum objects in ECDriver

.. also explicitly specify init() arguments

Signed-off-by: Tushar Gohad <tushar.gohad@intel.com>
This commit is contained in:
Tushar Gohad 2014-06-23 13:27:48 -07:00
parent eafb1b721b
commit dc2bf58d21
2 changed files with 29 additions and 31 deletions

View File

@ -21,7 +21,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from ec_iface import PyECLib_EC_Types
from ec_iface import PyECLib_HDRCHKSUM_Types
import math
import pyeclib_c
@ -29,11 +28,8 @@ import sys
pyver = float('%s.%s' % sys.version_info[:2])
#
# Generic ECPyECLibException
#
class ECPyECLibException(Exception):
def __init__(self, error_str):
@ -45,35 +41,24 @@ class ECPyECLibException(Exception):
class ECPyECLibDriver(object):
def __init__(self, k, m, ec_type, chksum_type="none"):
def __init__(self, k, m, ec_type,
chksum_type=PyECLib_HDRCHKSUM_Types.inline):
self.k = k
self.m = m
if PyECLib_EC_Types.is_member(ec_type):
self.ec_type = ec_type
else:
raise ECPyECLibException("%s is not a valid EC type for PyECLib!" %
ec_type)
if PyECLib_HDRCHKSUM_Types.is_member(chksum_type):
self.chksum_type = chksum_type
else:
raise ECPyECLibException(
"%s is not a valid checksum type for PyECLib!")
self.ec_type = ec_type
self.chksum_type = chksum_type
self.inline_chksum = 0
self.algsig_chksum = 0
if self.chksum_type == PyECLib_HDRCHKSUM_Types.inline:
if self.chksum_type is PyECLib_HDRCHKSUM_Types.inline:
self.inline_chksum = 1
self.algsig_chksum = 0
elif self.chksum_type == PyECLib_HDRCHKSUM_Types.algsig:
self.inline_chksum = 0
elif self.chksum_type is PyECLib_HDRCHKSUM_Types.algsig:
self.algsig_chksum = 1
self.handle = pyeclib_c.init(
self.k,
self.m,
self.ec_type,
self.ec_type.name,
self.inline_chksum,
self.algsig_chksum)
@ -140,7 +125,7 @@ class ECPyECLibDriver(object):
class ECNullDriver(object):
def __init__(self, k, m):
def __init__(self, k, m, ec_type=None, chksum_type=None):
self.k = k
self.m = m
@ -173,7 +158,7 @@ class ECNullDriver(object):
#
class ECStripingDriver(object):
def __init__(self, k, m):
def __init__(self, k, m, 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

View File

@ -100,6 +100,8 @@ class ECDriver(object):
def __init__(self, library_import_str, *args, **kwargs):
self.k = -1
self.m = -1
self.ec_type = None
self.chksum_type = None
self.library_import_str = None
for (key, value) in kwargs.items():
if key == "k":
@ -115,9 +117,19 @@ class ECDriver(object):
raise ECDriverError(
"Invalid number of data fragments (m)")
elif key == "ec_type":
self.ec_type = value
if PyECLib_EC_Types.has_enum(value):
self.ec_type = \
PyECLib_EC_Types.get_by_name(value)
else:
raise ECDriverError(
"%s is not a valid EC type for PyECLib!" % value)
elif key == "chksum_type":
self.chksum_type = value
if PyECLib_HDRCHKSUM_Types.has_enum(value):
self.chksum_type = \
PyECLib_HDRCHKSUM_Types.get_by_name(value)
else:
raise ECDriverError(
"%s is not a valid checksum type for PyECLib!" % value)
if library_import_str is not None:
self.library_import_str = library_import_str
@ -126,13 +138,14 @@ class ECDriver(object):
"Library import string (library_import_str) was not specified "
"and is a required argument!")
#
# We require keyword arguments to prevent ambiguity between EC libs
# Instantiate EC backend driver
#
self.ec_lib_reference = create_instance(
library_import_str,
*args,
**kwargs)
k=self.k,
m=self.m,
ec_type=self.ec_type,
chksum_type=self.chksum_type)
#
# Verify that the imported library implements the required functions
#