Skip to content

Commit

Permalink
Various xha bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
edwintorok committed Feb 19, 2025
9 parents 0bfdd6d + 96bd482 + cd21878 + b71d462 + 6d2c46f + 127c0d6 + 49fe454 + 8249c33 + a5c11c3 commit c2098f5
Show file tree
Hide file tree
Showing 11 changed files with 587 additions and 98 deletions.
2 changes: 1 addition & 1 deletion commands/cleanupwatchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ do_watchdog_disable(uint32_t *id)

hypercall.op = __HYPERVISOR_sched_op;
hypercall.arg[0] = SCHEDOP_watchdog;
hypercall.arg[1] = (__u64) (unsigned int) &arg; // pointer to u64
hypercall.arg[1] = (__u64) (uintptr_t) &arg; // pointer to u64
arg.id = *id;
arg.timeout = 0;

Expand Down
1 change: 1 addition & 0 deletions daemon/bond_mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ bm_initialize(
com_close(bm_object);
bm_object = HA_COMMON_OBJECT_INVALID_HANDLE_VALUE;
#endif
ret = MTC_ERROR_INVALID_PARAMETER;

break;
}
Expand Down
35 changes: 23 additions & 12 deletions daemon/com.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ typedef struct ha_common_object
MTC_U32 in_use;
MTC_U32 ref_count;
MTC_U32 checksum; // to detect modification by reader
pthread_mutex_t thread_id_record_table_mutex;
THREAD_ID_RECORD thread_id_record_table[THREAD_ID_RECORD_NUM];
} HA_COMMON_OBJECT;

Expand Down Expand Up @@ -536,6 +537,7 @@ set_thread_id_record(
clock_gettime(CLOCK_MONOTONIC, &ts);
now = tstoms(ts);

pthread_mutex_lock(&object->thread_id_record_table_mutex);
switch (lock_state) {
case LOCK_STATE_READER_ACQUIREING:
case LOCK_STATE_WRITER_ACQUIREING:
Expand All @@ -550,6 +552,7 @@ set_thread_id_record(
object->thread_id_record_table[i].lock_state = lock_state;
object->thread_id_record_table[i].thread_id = self;
object->thread_id_record_table[i].changed_time = now;
pthread_mutex_unlock(&object->thread_id_record_table_mutex);
return;
}
}
Expand All @@ -570,12 +573,14 @@ set_thread_id_record(
//
object->thread_id_record_table[i].lock_state = lock_state;
object->thread_id_record_table[i].changed_time = now;
pthread_mutex_unlock(&object->thread_id_record_table_mutex);
return;
}
}
log_message(MTC_LOG_WARNING, "COM: thread_id %d not found in thraed_id_record_table.\n", self);
break;
}
pthread_mutex_unlock(&object->thread_id_record_table_mutex);
assert(FALSE);
return ;
}
Expand Down Expand Up @@ -754,6 +759,13 @@ com_create(
handle = (HA_COMMON_OBJECT_HANDLE_INTERNAL *) *object_handle;
object->ref_count ++;
handle->object->in_use++;
pthread_ret = pthread_mutex_init(&handle->object->thread_id_record_table_mutex, NULL);
if (pthread_ret != 0)
{
log_internal(MTC_LOG_ERR, "COM: (%s) pthread_mutex_init failed (sys %d).\n", __func__, pthread_ret);
ret = MTC_ERROR_COM_PTHREAD;
goto error_return;
}
set_thread_id_record(handle->object, LOCK_STATE_WRITER_ACQUIREING);
LEAVE_CS;

Expand All @@ -769,6 +781,7 @@ com_create(

pthread_ret = pthread_rwlock_wrlock(&handle->object->rwlock);
if (fist_on("com.pthread")) pthread_ret = FIST_PTHREAD_ERRCODE;


ENTER_CS;
set_thread_id_record(handle->object, LOCK_STATE_WRITER_ACQUIRED);
Expand Down Expand Up @@ -937,6 +950,7 @@ com_close(
{
log_message(MTC_LOG_WARNING, "COM: pthread_rwlock_destroy failed (sys %d).\n", pthread_ret);
}
pthread_ret = pthread_mutex_destroy(&object->thread_id_record_table_mutex);
free_object(object);
}
error_return:
Expand Down Expand Up @@ -1097,20 +1111,19 @@ com_writer_lock(
HA_COMMON_OBJECT_HANDLE_INTERNAL *handle = object_handle;
int pthread_ret;

ENTER_CS;
if (!valid_object_handle(handle))
{
log_internal(MTC_LOG_ERR, "COM: (%s) invalid handle.\n", __func__);
assert(FALSE);
ret = MTC_ERROR_COM_INVALID_HANDLE;
goto error_return;
}
ENTER_CS;
handle->object->in_use++;
set_thread_id_record(handle->object, LOCK_STATE_WRITER_ACQUIREING);
LEAVE_CS;
set_thread_id_record(handle->object, LOCK_STATE_WRITER_ACQUIREING);
pthread_ret = pthread_rwlock_wrlock(&handle->object->rwlock);
if (fist_on("com.pthread")) pthread_ret = FIST_PTHREAD_ERRCODE;
ENTER_CS;
set_thread_id_record(handle->object, LOCK_STATE_WRITER_ACQUIRED);
if (pthread_ret != 0)
{
Expand All @@ -1122,7 +1135,6 @@ com_writer_lock(
*buffer = handle->object->buffer;

error_return:
LEAVE_CS;
if (ret != MTC_SUCCESS)
{
log_status(ret, NULL);
Expand Down Expand Up @@ -1157,7 +1169,6 @@ com_writer_unlock(
int pthread_ret;
HA_COMMON_OBJECT_CALLBACK_LIST_ITEM *c;

ENTER_CS;
if (!valid_object_handle(handle))
{
log_internal(MTC_LOG_ERR, "COM: (%s) invalid handle.\n", __func__);
Expand All @@ -1166,6 +1177,7 @@ com_writer_unlock(
goto error_return;
}

ENTER_CS;
for (c = handle->object->callback_list_head; c != NULL; c = c->next)
{
c->func(c->object_handle, handle->object->buffer);
Expand All @@ -1176,6 +1188,8 @@ com_writer_unlock(


handle->object->in_use--;
LEAVE_CS;

set_thread_id_record(handle->object, LOCK_STATE_NONE);
pthread_ret = pthread_rwlock_unlock(&handle->object->rwlock);
if (fist_on("com.pthread")) pthread_ret = FIST_PTHREAD_ERRCODE;
Expand All @@ -1187,7 +1201,6 @@ com_writer_unlock(
}

error_return:
LEAVE_CS;
if (ret != MTC_SUCCESS)
{
log_status(ret, NULL);
Expand Down Expand Up @@ -1224,20 +1237,19 @@ com_reader_lock(
HA_COMMON_OBJECT_HANDLE_INTERNAL *handle = object_handle;
int pthread_ret;

ENTER_CS;
if (!valid_object_handle(handle))
{
log_internal(MTC_LOG_ERR, "COM: (%s) invalid handle.\n", __func__);
assert(FALSE);
ret = MTC_ERROR_COM_INVALID_HANDLE;
goto error_return;
}
ENTER_CS;
handle->object->in_use++;
set_thread_id_record(handle->object, LOCK_STATE_READER_ACQUIREING);
LEAVE_CS;
set_thread_id_record(handle->object, LOCK_STATE_READER_ACQUIREING);
pthread_ret = pthread_rwlock_rdlock(&handle->object->rwlock);
if (fist_on("com.pthread")) pthread_ret = FIST_PTHREAD_ERRCODE;
ENTER_CS;
set_thread_id_record(handle->object, LOCK_STATE_READER_ACQUIRED);
if (pthread_ret != 0)
{
Expand All @@ -1248,7 +1260,6 @@ com_reader_lock(
*buffer = handle->object->buffer;

error_return:
LEAVE_CS;
if (ret != MTC_SUCCESS)
{
log_status(ret, NULL);
Expand Down Expand Up @@ -1281,7 +1292,6 @@ com_reader_unlock(
HA_COMMON_OBJECT_HANDLE_INTERNAL *handle = object_handle;
int pthread_ret;

ENTER_CS;
if (!valid_object_handle(handle))
{
log_internal(MTC_LOG_ERR, "COM: (%s) invalid handle.\n", __func__);
Expand All @@ -1290,10 +1300,12 @@ com_reader_unlock(
goto error_return;
}

ENTER_CS;
#ifndef NDEBUG
assert(handle->object->checksum == calc_checksum_object_buffer(handle->object));
#endif //NDEBUG
handle->object->in_use--;
LEAVE_CS;
set_thread_id_record(handle->object, LOCK_STATE_NONE);
pthread_ret = pthread_rwlock_unlock(&handle->object->rwlock);
if (fist_on("com.pthread")) pthread_ret = FIST_PTHREAD_ERRCODE;
Expand All @@ -1305,7 +1317,6 @@ com_reader_unlock(
}

error_return:
LEAVE_CS;
if (ret != MTC_SUCCESS)
{
log_status(ret, NULL);
Expand Down
53 changes: 16 additions & 37 deletions daemon/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <execinfo.h>
#include <unistd.h>


Expand Down Expand Up @@ -447,60 +449,37 @@ log_logmask(void)
//
//

#define BACKTRACE_SIZE 10
#define FILL_RETURN_ADDRESS(x) \
if (__builtin_frame_address(x) == 0) \
{ \
return_address[x] = NULL; \
goto end_fill; \
} \
return_address[x] = __builtin_return_address(x); \


#define BACKTRACE_SIZE 10

void
log_backtrace(MTC_S32 priority)
{
int level;
Dl_info dli;
void *return_address[BACKTRACE_SIZE] = {NULL};

void* return_address[BACKTRACE_SIZE] = {NULL};

level = 0;

FILL_RETURN_ADDRESS(0);
FILL_RETURN_ADDRESS(1);
FILL_RETURN_ADDRESS(2);
FILL_RETURN_ADDRESS(3);
FILL_RETURN_ADDRESS(4);
FILL_RETURN_ADDRESS(5);
FILL_RETURN_ADDRESS(6);
FILL_RETURN_ADDRESS(7);
FILL_RETURN_ADDRESS(8);
FILL_RETURN_ADDRESS(9);
end_fill:

log_message(priority, "backtrace -------------\n");
int nptrs = backtrace(return_address, sizeof(return_address) / sizeof(return_address[0]));
if (nptrs <= 0 || nptrs > sizeof(return_address) / sizeof(return_address[0])) {
log_message(priority, "Cannot get backtrace");
return;
}
char** symbols = backtrace_symbols(return_address, sizeof(return_address) / sizeof(return_address[0]));

for (level = 0;
level < BACKTRACE_SIZE;
level < nptrs;
level ++)
{
int err;

if (return_address[level] == NULL)
{
break;
if (symbols && symbols[level]) {
log_message(priority, " %2d: (%p) %s\n", level, return_address[level], symbols[level]);
}
err = dladdr(return_address[level], &dli);
if (err == 0 || dli.dli_sname == NULL)
else
{
log_message(priority, " %2d: (%p) --\n", level, return_address[level]);
}
else
{
log_message(priority, " %2d: (%p) %s\n", level, return_address[level], dli.dli_sname);
}
}
free(symbols);
log_message(priority, "backtrace -------------\n");
return;
}
Expand Down
Loading

0 comments on commit c2098f5

Please sign in to comment.