Commit 414a48b6 authored by Zhang Jingwang's avatar Zhang Jingwang Committed by Dries Kimpe
Browse files

Revert "Fix multi-thread problem in the "old" zoidfsclient."

This reverts commit dad2e6309603cee63f8743b0199784ed90ec8a0f.

The reverted patch is not the right fix. The problem should
be properly fixed by reverting the patch who changed BMI_test
to BMI_testcontext.
parent 394f7d3d
......@@ -26,6 +26,7 @@
static char *ion_name;
static BMI_addr_t * peer_addr = NULL;
static BMI_addr_t * def_peer_addr = NULL;
static bmi_context_id context;
/* addr manipulation funcs */
......@@ -44,39 +45,16 @@ void zoidfs_client_set_def_addr(BMI_addr_t * addr)
def_peer_addr = addr;
}
bmi_context_id * zoidfs_client_get_context()
{
return &context;
}
/* TLS key for tag */
static pthread_key_t ptk_tag;
static pthread_key_t ptk_context;
static unsigned int next_tag = 0;
static pthread_mutex_t tag_lock = PTHREAD_MUTEX_INITIALIZER;
static void zoidfs_client_destroy_context(void *ptr)
{
BMI_close_context(*(bmi_context_id *)ptr);
free(ptr);
}
static bmi_context_id *zoidfs_client_open_context()
{
bmi_context_id *context;
context = (bmi_context_id *) pthread_getspecific(ptk_context);
if (!context) {
int ret;
context = malloc(sizeof(bmi_context_id));
assert(context);
ret = BMI_open_context(context);
assert(ret == 0);
pthread_setspecific(ptk_context, (void *)context);
}
return context;
}
#define context (*zoidfs_client_open_context())
bmi_context_id * zoidfs_client_get_context()
{
return zoidfs_client_open_context();
}
/* conditional compilation flags */
/*#define ZFS_USE_XDR_SIZE_CACHE
#define ZFS_BMI_FASTMEMALLOC*/
......@@ -141,11 +119,11 @@ static bmi_msg_tag_t gen_tag(void)
static int zoidfs_write_pipeline(BMI_addr_t peer_addr, size_t pipeline_size,
size_t list_count, const void ** buf_list,
const bmi_size_t size_list[], bmi_msg_tag_t tag,
bmi_context_id acontext, bmi_size_t total_size);
bmi_context_id context, bmi_size_t total_size);
static int zoidfs_read_pipeline(BMI_addr_t peer_addr, size_t pipeline_size,
size_t list_count, void ** buf_list,
const bmi_size_t size_list[], bmi_msg_tag_t tag,
bmi_context_id acontext, bmi_size_t total_size);
bmi_context_id context, bmi_size_t total_size);
/*
* zoidfs message data types
......@@ -3309,7 +3287,7 @@ write_cleanup:
static int zoidfs_write_pipeline(BMI_addr_t l_peer_addr, size_t pipeline_size,
size_t list_count, const void ** buf_list,
const bmi_size_t bmi_size_list[], bmi_msg_tag_t tag,
bmi_context_id acontext, bmi_size_t total_size) {
bmi_context_id context, bmi_size_t total_size) {
int np = 0;
int ret = ZFS_OK;
bmi_size_t i;
......@@ -3398,7 +3376,7 @@ static int zoidfs_write_pipeline(BMI_addr_t l_peer_addr, size_t pipeline_size,
/* send the data */
ret = bmi_comm_send_list(l_peer_addr, p_list_count, (const void**)p_buf_list,
p_size_list, tag, acontext, p_total_size);
p_size_list, tag, context, p_total_size);
free(p_buf_list);
free(p_size_list);
......@@ -3709,7 +3687,7 @@ read_cleanup:
static int zoidfs_read_pipeline(BMI_addr_t l_peer_addr, size_t pipeline_size,
size_t list_count, void ** buf_list,
const bmi_size_t bmi_size_list[], bmi_msg_tag_t tag,
bmi_context_id acontext, bmi_size_t total_size) {
bmi_context_id context, bmi_size_t total_size) {
int np = 0;
int ret = ZFS_OK;
bmi_size_t i;
......@@ -3798,7 +3776,7 @@ static int zoidfs_read_pipeline(BMI_addr_t l_peer_addr, size_t pipeline_size,
/* recv the data */
ret = bmi_comm_recv_list(l_peer_addr, p_list_count, (void**)p_buf_list,
p_size_list, tag, acontext, p_total_size);
p_size_list, tag, context, p_total_size);
free(p_buf_list);
free(p_size_list);
......@@ -3840,6 +3818,13 @@ int zoidfs_init(zoidfs_op_hint_t * UNUSED(op_hint)) {
return ZFSERR_OTHER;
}
/* Create a new BMI context */
ret = BMI_open_context(&context);
if (ret < 0) {
fprintf(stderr, "zoidfs_init: BMI_open_context() failed.\n");
return ZFSERR_OTHER;
}
/*
* Pick up the ION hostname from an environment variable (ZOIDFS_ION_NAME).
*/
......@@ -3917,7 +3902,6 @@ int zoidfs_init(zoidfs_op_hint_t * UNUSED(op_hint)) {
/* Initialize TLS tags */
pthread_key_create (&ptk_tag, 0);
pthread_key_create (&ptk_context, zoidfs_client_destroy_context);
next_tag = 1;
return ZFS_OK;
......@@ -3929,7 +3913,6 @@ int zoidfs_init(zoidfs_op_hint_t * UNUSED(op_hint)) {
*/
int zoidfs_finalize(zoidfs_op_hint_t * UNUSED(op_hint)) {
int ret = ZFS_OK;
void *pcontext;
/* cleanup buffers */
#ifdef ZFS_BMI_FASTMEMALLOC
......@@ -3955,6 +3938,8 @@ int zoidfs_finalize(zoidfs_op_hint_t * UNUSED(op_hint)) {
peer_addr = NULL;
}
BMI_close_context(context);
/* Finalize BMI */
ret = BMI_finalize();
if (ret < 0) {
......@@ -3966,12 +3951,6 @@ int zoidfs_finalize(zoidfs_op_hint_t * UNUSED(op_hint)) {
/* Free TLS key */
pthread_key_delete (ptk_tag);
/* Clean up BMI context */
pcontext = pthread_getspecific(ptk_context);
if (pcontext) {
zoidfs_client_destroy_context(pcontext);
}
pthread_key_delete (ptk_context);
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment