summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar Gohad <tushar.gohad@intel.com>2015-11-22 15:58:01 +0000
committerroot <root@abb953331337.(none)>2015-11-23 00:33:11 +0000
commit9b46e826daeea3adc426597bbaa77205934122f8 (patch)
tree482e501c1ded5c9e23103c42c945dd3e31fc0c38
parentb14ac48319554d1399820268e2d81317e072e552 (diff)
downloadpyeclib-9b46e826daeea3adc426597bbaa77205934122f8.tar.gz
Disable error reporting during VALID_EC_TYPES eval
... this should not be required after upstream liberasurecode has more configurable logging
-rw-r--r--pyeclib/core.py12
-rw-r--r--pyeclib/ec_iface.py19
-rw-r--r--src/c/pyeclib_c/pyeclib_c.c62
3 files changed, 70 insertions, 23 deletions
diff --git a/pyeclib/core.py b/pyeclib/core.py
index e233915..a0174e1 100644
--- a/pyeclib/core.py
+++ b/pyeclib/core.py
@@ -35,7 +35,8 @@ pyver = float('%s.%s' % sys.version_info[:2])
class ECPyECLibDriver(object):
def __init__(self, k, m, hd, ec_type,
- chksum_type=PyECLib_FRAGHDRCHKSUM_Types.none):
+ chksum_type=PyECLib_FRAGHDRCHKSUM_Types.none,
+ validate=False):
self.k = k
self.m = m
self.hd = hd
@@ -56,7 +57,8 @@ class ECPyECLibDriver(object):
ec_type.value,
self.hd,
self.inline_chksum,
- self.algsig_chksum)
+ self.algsig_chksum,
+ validate)
def encode(self, data_bytes):
return pyeclib_c.encode(self.handle, data_bytes)
@@ -136,7 +138,8 @@ class ECPyECLibDriver(object):
class ECNullDriver(object):
- def __init__(self, k, m, hd, ec_type=None, chksum_type=None):
+ def __init__(self, k, m, hd, ec_type=None, chksum_type=None,
+ validate=False):
self.k = k
self.m = m
self.hd = hd
@@ -173,7 +176,8 @@ class ECNullDriver(object):
#
class ECStripingDriver(object):
- def __init__(self, k, m, hd, ec_type=None, chksum_type=None):
+ def __init__(self, k, m, hd, ec_type=None, chksum_type=None,
+ validate=False):
"""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
diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py
index 2b459d6..202657d 100644
--- a/pyeclib/ec_iface.py
+++ b/pyeclib/ec_iface.py
@@ -112,6 +112,7 @@ class ECDriver(object):
self.hd = -1
self.ec_type = None
self.chksum_type = None
+ self.validate = False
for (key, value) in kwargs.items():
if key == "k":
try:
@@ -144,6 +145,9 @@ class ECDriver(object):
else:
raise ECDriverError(
"%s is not a valid checksum type for PyECLib!" % value)
+ elif key == "validate":
+ # validate if the ec type is available (runtime check)
+ self.validate = value
if self.hd == -1:
self.hd = self.m
@@ -159,7 +163,10 @@ class ECDriver(object):
m=self.m,
hd=self.hd,
ec_type=self.ec_type,
- chksum_type=self.chksum_type)
+ chksum_type=self.chksum_type,
+ validate=int(self.validate)
+ )
+
#
# Verify that the imported library implements the required functions
#
@@ -471,12 +478,14 @@ def _PyECLibValidECTypes():
for _type in ALL_EC_TYPES:
try:
if _type is 'shss':
- ECDriver(k=10, m=4, ec_type=_type)
+ _m = 4
else:
- ECDriver(k=10, m=5, ec_type=_type)
+ _m = 5
+ driver = ECDriver(k=10, m=_m, ec_type=_type, validate=True)
available_ec_types.append(_type)
- except Exception:
- pass
+ except:
+ # ignore any errors, assume backend not available
+ continue
return available_ec_types
diff --git a/src/c/pyeclib_c/pyeclib_c.c b/src/c/pyeclib_c/pyeclib_c.c
index ea6ac30..d96681d 100644
--- a/src/c/pyeclib_c/pyeclib_c.c
+++ b/src/c/pyeclib_c/pyeclib_c.c
@@ -24,6 +24,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <stdio.h>
+#include <paths.h>
#include <Python.h>
#include <math.h>
#include <bytesobject.h>
@@ -188,13 +190,39 @@ pyeclib_c_seterr(int ret, const char * prefix)
PyErr_SetString(eo, err);
}
+static int stderr_fd;
+static fpos_t stderr_fpos;
+#ifndef _PATH_DEVNULL
+#define _PATH_DEVNULL "/dev/null"
+#endif
+
+static void redirect_stderr(void)
+{
+ fflush(stderr);
+ fgetpos(stderr, &stderr_fpos);
+ stderr_fd = dup(fileno(stderr));
+ freopen(_PATH_DEVNULL, "w", stderr);
+}
+
+static void restore_stderr(void)
+{
+ fflush(stderr);
+ dup2(stderr_fd, fileno(stderr));
+ close(stderr_fd);
+ clearerr(stderr);
+ fsetpos(stderr, &stderr_fpos); /* for C9X */
+}
+
/**
* Constructor method for creating a new pyeclib object using the given parameters.
*
* @param k integer number of data elements
* @param m integer number of checksum elements
- * @param w integer word size in bytes
+ * @param hd hamming distance
* @param backend_id erasure coding backend
+ * @param use_inline_chksum type of inline fragment header checksum
+ * @param use_algsig_chksum use algorithmic signature for fragment header checksum
+ * @param validate only validate backend and params, close handle immediately
* @return pointer to PyObject or NULL on error
*/
static PyObject *
@@ -202,12 +230,14 @@ pyeclib_c_init(PyObject *self, PyObject *args)
{
pyeclib_t *pyeclib_handle = NULL;
PyObject *pyeclib_obj_handle = NULL;
- int k, m, hd=0;
+ int k, m, hd = 0, validate = 0;
int use_inline_chksum = 0, use_algsig_chksum = 0;
const ec_backend_id_t backend_id;
/* Obtain and validate the method parameters */
- if (!PyArg_ParseTuple(args, "iii|iii", &k, &m, &backend_id, &hd, &use_inline_chksum, &use_algsig_chksum)) {
+ if (!PyArg_ParseTuple(args, "iii|iiiii",
+ &k, &m, &backend_id, &hd, &use_inline_chksum,
+ &use_algsig_chksum, &validate)) {
pyeclib_c_seterr(-EINVALIDPARAMS, "pyeclib_c_init ERROR: ");
return NULL;
}
@@ -216,7 +246,7 @@ pyeclib_c_init(PyObject *self, PyObject *args)
pyeclib_handle = (pyeclib_t *) alloc_zeroed_buffer(sizeof(pyeclib_t));
if (NULL == pyeclib_handle) {
pyeclib_c_seterr(-ENOMEM, "pyeclib_c_init ERROR: ");
- goto error;
+ goto cleanup;
}
pyeclib_handle->ec_args.k = k;
@@ -224,10 +254,13 @@ pyeclib_c_init(PyObject *self, PyObject *args)
pyeclib_handle->ec_args.hd = hd;
pyeclib_handle->ec_args.ct = use_inline_chksum ? CHKSUM_CRC32 : CHKSUM_NONE;
+ if (validate)
+ redirect_stderr();
+
pyeclib_handle->ec_desc = liberasurecode_instance_create(backend_id, &(pyeclib_handle->ec_args));
if (pyeclib_handle->ec_desc <= 0) {
pyeclib_c_seterr(-EINVALIDPARAMS, "pyeclib_c_init ERROR: ");
- goto error;
+ goto cleanup;
}
/* Prepare the python object to return */
@@ -235,27 +268,28 @@ pyeclib_c_init(PyObject *self, PyObject *args)
pyeclib_obj_handle = PyCapsule_New(pyeclib_handle, PYECC_HANDLE_NAME,
pyeclib_c_destructor);
#else
- pyeclib_obj_handle = PyCObject_FromVoidPtrAndDesc(pyeclib_handle,
- (void *) PYECC_HANDLE_NAME,
- pyeclib_c_destructor);
+ pyeclib_obj_handle = PyCObject_FromVoidPtrAndDesc(
+ pyeclib_handle, (void *) PYECC_HANDLE_NAME,
+ pyeclib_c_destructor);
#endif /* Py_CAPSULE_H */
/* Clean up the allocated memory on error, or update the ref count */
if (pyeclib_obj_handle == NULL) {
pyeclib_c_seterr(-EINVALIDPARAMS, "pyeclib_c_init ERROR: ");
- goto error;
+ goto cleanup;
} else {
Py_INCREF(pyeclib_obj_handle);
}
- goto exit;
+exit:
+ if (validate)
+ restore_stderr();
+ return pyeclib_obj_handle;
-error:
+cleanup:
check_and_free_buffer(pyeclib_handle);
pyeclib_obj_handle = NULL;
-
-exit:
- return pyeclib_obj_handle;
+ goto exit;
}