Skip to content

Commit

Permalink
[handle] remove knet handle tracker
Browse files Browse the repository at this point in the history
reload of shlib should be done on a per handle base to avoid complex
global functions.

For example, if you application is using 2 knet_h and you need to reload
libbz2, then switch both knet_h to use another compression method (or none)
and switch back to libbz2.

Similar can be done with nss/openssl once openssl support is added.

A global function to reload all library would a very complex error reporting
mechanism and could leave some handles improperly configured.

The application would have a better understanding of the needs at any given
time.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Sep 14, 2017
1 parent c2732cd commit fbc5c5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 51 deletions.
56 changes: 6 additions & 50 deletions libknet/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,13 @@ static pthread_mutex_t handle_config_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_rwlock_t shlib_rwlock;
static uint8_t shlib_wrlock_init = 0;

/*
* UINT8_MAX knet_handles need more than 20GB of RAM
* and you need to tune ulimit for tons of open file
* descriptors.
*/
static knet_handle_t *knet_handle_tracker[UINT8_MAX];
static uint8_t knet_ref = 0;
static uint32_t knet_ref = 0;

static int _init_handles_tracker(knet_handle_t knet_h)
static int _init_shlib_tracker(knet_handle_t knet_h)
{
int savederrno = 0;
uint8_t idx = 0;

if (!shlib_wrlock_init) {
for (idx = 0; idx < UINT8_MAX; idx++) {
knet_handle_tracker[idx] = NULL;
}
savederrno = pthread_rwlock_init(&shlib_rwlock, NULL);
if (savederrno) {
log_err(knet_h, KNET_SUB_HANDLE, "Unable to initialize shared lib rwlock: %s",
Expand All @@ -68,7 +58,7 @@ static int _init_handles_tracker(knet_handle_t knet_h)
return 0;
}

static void _fini_handles_tracker(void)
static void _fini_shlib_tracker(void)
{
if (knet_ref == 0) {
pthread_rwlock_destroy(&shlib_rwlock);
Expand All @@ -77,31 +67,6 @@ static void _fini_handles_tracker(void)
return;
}

static int _register_handle(knet_handle_t knet_h)
{
uint8_t idx = 0;

knet_h->this_knet_h_id = UINT8_MAX;
for (idx = 0; idx < UINT8_MAX; idx++) {
if (knet_handle_tracker[idx] == NULL) {
knet_handle_tracker[idx] = &knet_h;
knet_h->this_knet_h_id = idx;
return 0;
}
}

errno = EBUSY;
return -1;
}

static void _unregister_handle(knet_handle_t knet_h)
{
if (knet_h->this_knet_h_id != UINT8_MAX) {
knet_handle_tracker[knet_h->this_knet_h_id] = NULL;
}
return;
}

static int _init_locks(knet_handle_t knet_h)
{
int savederrno = 0;
Expand Down Expand Up @@ -677,24 +642,16 @@ knet_handle_t knet_handle_new(knet_node_id_t host_id,
knet_h->stats.rx_crypt_time_min = UINT64_MAX;

/*
* init global handles tracker
* init global shlib tracker
*/
if (_init_handles_tracker(knet_h) < 0) {
if (_init_shlib_tracker(knet_h) < 0) {
savederrno = errno;
log_err(knet_h, KNET_SUB_HANDLE, "Unable to init handles traceker: %s",
strerror(savederrno));
errno = savederrno;
goto exit_fail;
}

if (_register_handle(knet_h) < 0) {
savederrno = errno;
log_err(knet_h, KNET_SUB_HANDLE, "Unable to register handle: %s",
strerror(savederrno));
errno = savederrno;
goto exit_fail;
}

/*
* init main locking structures
*/
Expand Down Expand Up @@ -820,13 +777,12 @@ int knet_handle_free(knet_handle_t knet_h)
crypto_fini(knet_h);
compress_fini(knet_h);
_destroy_locks(knet_h);
_unregister_handle(knet_h);

exit_nolock:
free(knet_h);
knet_h = NULL;
knet_ref--;
_fini_handles_tracker();
_fini_shlib_tracker();
pthread_mutex_unlock(&handle_config_mutex);
return 0;
}
Expand Down
1 change: 0 additions & 1 deletion libknet/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ struct knet_handle {
int error,
int errorno);
int fini_in_progress;
uint8_t this_knet_h_id;
};

extern pthread_rwlock_t shlib_rwlock; /* global shared lib load/unload lock */
Expand Down

0 comments on commit fbc5c5d

Please sign in to comment.