Skip to content

Commit

Permalink
[logging] drop locking inside log_msg (part 1)
Browse files Browse the repository at this point in the history
looking at the code, there are only few calls to log_msg happening outside
of locking context (error reports when failing to grab the lock).
Everything else appears to be safe.

drop the attempt to lock inside log_msg for now, part 2 will address those
few calls that can happen outside of locking context.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Jul 29, 2018
1 parent bbb0f7b commit 01de0d1
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions libknet/logging.c
Expand Up @@ -207,24 +207,15 @@ void log_msg(knet_handle_t knet_h, uint8_t subsystem, uint8_t msglevel,
va_list ap;
struct knet_log_msg msg;
size_t byte_cnt = 0;
int len, err;
int len;

if ((!knet_h) ||
(subsystem == KNET_MAX_SUBSYSTEMS) ||
(msglevel > knet_h->log_levels[subsystem]))
return;

/*
* most logging calls will take place with locking in place.
* if we get an EINVAL and locking is initialized, then
* we are getting a real error and we need to stop
*/
err = pthread_rwlock_tryrdlock(&knet_h->global_rwlock);
if ((err == EAGAIN) && (knet_h->lock_init_done))
return;

if (knet_h->logfd <= 0)
goto out_unlock;
goto out;

memset(&msg, 0, sizeof(struct knet_log_msg));
msg.subsystem = subsystem;
Expand All @@ -244,18 +235,12 @@ void log_msg(knet_handle_t knet_h, uint8_t subsystem, uint8_t msglevel,
while (byte_cnt < sizeof(struct knet_log_msg)) {
len = write(knet_h->logfd, &msg, sizeof(struct knet_log_msg) - byte_cnt);
if (len <= 0) {
goto out_unlock;
goto out;
}

byte_cnt += len;
}

out_unlock:
/*
* unlock only if we are holding the lock
*/
if (!err)
pthread_rwlock_unlock(&knet_h->global_rwlock);

out:
return;
}

0 comments on commit 01de0d1

Please sign in to comment.