From 4f278195a42ea0f254114c92043b6ba6ecdc6b0a Mon Sep 17 00:00:00 2001 From: Timur Alperovich Date: Mon, 7 Mar 2016 15:09:20 -0800 Subject: [PATCH] Use the check_backend_available function. Eliminates the spurrious syslog messages and is a cleaner mechanism for querying all of the available backends on a system. --- pyeclib/ec_iface.py | 19 ++++++++----------- src/c/pyeclib_c/pyeclib_c.c | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py index d4775e2..9310ae7 100644 --- a/pyeclib/ec_iface.py +++ b/pyeclib/ec_iface.py @@ -26,6 +26,7 @@ from .enum import Enum from .enum import unique from .utils import create_instance from .utils import positive_int_value +from pyeclib_c import check_backend_available def PyECLibVersion(z, y, x): @@ -476,18 +477,14 @@ ALL_EC_TYPES = [ def _PyECLibValidECTypes(): available_ec_types = [] for _type in ALL_EC_TYPES: - driver = None - try: - if _type is 'shss': - _m = 4 - else: - _m = 5 - driver = ECDriver(k=10, m=_m, ec_type=_type, validate=True) - if driver: - available_ec_types.append(_type) - except: - # ignore any errors, assume backend not available + if _type.startswith('flat_xor_hd'): + int_type = PyECLib_EC_Types.get_by_name('flat_xor_hd') + else: + int_type = PyECLib_EC_Types.get_by_name(_type) + if not int_type: continue + if check_backend_available(int_type.value): + available_ec_types.append(_type) return available_ec_types diff --git a/src/c/pyeclib_c/pyeclib_c.c b/src/c/pyeclib_c/pyeclib_c.c index 8b359f1..01fc13d 100644 --- a/src/c/pyeclib_c/pyeclib_c.c +++ b/src/c/pyeclib_c/pyeclib_c.c @@ -1172,6 +1172,22 @@ exit: return ret_obj; } +static PyObject* +pyeclib_c_check_backend_available(PyObject *self, PyObject *args) +{ + const ec_backend_id_t backend_id; + + if (!PyArg_ParseTuple(args, "i", &backend_id)) { + pyeclib_c_seterr(-EINVALIDPARAMS, "pyeclib_c_check_backend_available ERROR: "); + return NULL; + } + + if (liberasurecode_backend_available(backend_id)) { + Py_RETURN_TRUE; + } + + Py_RETURN_FALSE; +} static PyMethodDef PyECLibMethods[] = { {"init", pyeclib_c_init, METH_VARARGS, "Initialize a new erasure encoder/decoder"}, @@ -1182,6 +1198,7 @@ static PyMethodDef PyECLibMethods[] = { {"get_segment_info", pyeclib_c_get_segment_info, METH_VARARGS, "Return segment and fragment size information needed when encoding a segmented stream"}, {"get_metadata", pyeclib_c_get_metadata, METH_VARARGS, "Get the integrity checking metadata for a fragment"}, {"check_metadata", pyeclib_c_check_metadata, METH_VARARGS, "Check the integrity checking metadata for a set of fragments"}, + {"check_backend_available", pyeclib_c_check_backend_available, METH_VARARGS, "Check if a backend is available"}, {NULL, NULL, 0, NULL} /* Sentinel */ };