HADOOP-12955. Fix bugs in the initialization of the ISA-L library JNI bindings (Kai Zheng via cmccabe)

This commit is contained in:
Colin Patrick Mccabe 2016-03-31 15:09:11 -07:00
parent 12b11e2e68
commit 19639785f5
5 changed files with 36 additions and 40 deletions

View File

@ -95,12 +95,12 @@ public class NativeLibraryChecker {
snappyLibraryName = SnappyCodec.getLibraryName();
}
try {
isalDetail = ErasureCodeNative.getLoadingFailureReason();
isalDetail = ErasureCodeNative.getLoadingFailureReason();
if (isalDetail != null) {
isalLoaded = false;
} else {
isalDetail = ErasureCodeNative.getLibraryName();
isalLoaded = true;
} catch (UnsatisfiedLinkError e) {
isalLoaded = false;
}
openSslDetail = OpensslCipher.getLoadingFailureReason();

View File

@ -19,6 +19,7 @@
#include "erasure_code.h"
#include "gf_util.h"
#include "erasure_coder.h"
#include "dump.h"
#include <stdio.h>
#include <stdlib.h>

View File

@ -78,6 +78,12 @@ static const char* load_functions() {
void load_erasurecode_lib(char* err, size_t err_len) {
const char* errMsg;
const char* library = NULL;
#ifdef UNIX
Dl_info dl_info;
#else
LPTSTR filename = NULL;
#endif
err[0] = '\0';
@ -111,6 +117,22 @@ void load_erasurecode_lib(char* err, size_t err_len) {
if (errMsg != NULL) {
snprintf(err, err_len, "Loading functions from ISA-L failed: %s", errMsg);
}
#ifdef UNIX
if(dladdr(isaLoader->ec_encode_data, &dl_info)) {
library = dl_info.dli_fname;
}
#else
if (GetModuleFileName(isaLoader->libec, filename, 256) > 0) {
library = filename;
}
#endif
if (library == NULL) {
library = HADOOP_ISAL_LIBRARY;
}
isaLoader->libname = strdup(library);
}
int build_support_erasurecode() {
@ -119,30 +141,4 @@ int build_support_erasurecode() {
#else
return 0;
#endif
}
const char* get_library_name() {
#ifdef UNIX
Dl_info dl_info;
if (isaLoader->ec_encode_data == NULL) {
return HADOOP_ISAL_LIBRARY;
}
if(dladdr(isaLoader->ec_encode_data, &dl_info)) {
return dl_info.dli_fname;
}
#else
LPTSTR filename = NULL;
if (isaLoader->libec == NULL) {
return HADOOP_ISAL_LIBRARY;
}
if (GetModuleFileName(isaLoader->libec, filename, 256) > 0) {
return filename;
}
#endif
return NULL;
}
}

View File

@ -78,6 +78,7 @@ typedef void (__cdecl *__d_ec_encode_data_update)(int, int, int, int, unsigned c
typedef struct __IsaLibLoader {
// The loaded library handle
void* libec;
char* libname;
__d_gf_mul gf_mul;
__d_gf_inv gf_inv;
@ -133,11 +134,6 @@ static FARPROC WINAPI myDlsym(HMODULE handle, LPCSTR symbol) {
*/
int build_support_erasurecode();
/**
* Get the library name possibly of full path.
*/
const char* get_library_name();
/**
* Initialize and load erasure code library, returning error message if any.
*

View File

@ -22,6 +22,7 @@
#include "org_apache_hadoop.h"
#include "jni_common.h"
#include "isal_load.h"
#include "org_apache_hadoop_io_erasurecode_ErasureCodeNative.h"
#ifdef UNIX
@ -37,9 +38,11 @@ Java_org_apache_hadoop_io_erasurecode_ErasureCodeNative_loadLibrary
JNIEXPORT jstring JNICALL
Java_org_apache_hadoop_io_erasurecode_ErasureCodeNative_getLibraryName
(JNIEnv *env, jclass myclass) {
char* libName = get_library_name();
if (libName == NULL) {
libName = "Unavailable";
if (isaLoader == NULL) {
THROW(env, "java/lang/UnsatisfiedLinkError",
"Unavailable: library not loaded yet");
return (jstring)NULL;
}
return (*env)->NewStringUTF(env, libName);
return (*env)->NewStringUTF(env, isaLoader->libname);
}