Add lock ordering assertions in debug builds (#370)
* Add lock ordering assertions for psql_lock → file mutex * Add missing psql.h include to pfs.h * Fix debug build conditional compilation for lock ordering assertions * Fix function declaration order for pfs_debug_check_lock_order --------- Co-authored-by: Levi Neely <lkn@darkstar.example.net>
This commit is contained in:
parent
d0c213f181
commit
8276034f70
|
|
@ -45,3 +45,10 @@ void pfs_debug_register_signal_handlers() {
|
||||||
sa.sa_flags = 0;
|
sa.sa_flags = 0;
|
||||||
sigaction(SIGUSR1, &sa, NULL);
|
sigaction(SIGUSR1, &sa, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pfs_debug_check_lock_order(const char *file, unsigned long line) {
|
||||||
|
if (!psql_locked()) {
|
||||||
|
pdbg_logf(D_ERROR, "lock ordering violation: pfs_lock_file called without psql_lock at %s:%lu", file, line);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ __attribute__((weak)) void pfs_debug_init_file_mutex(pthread_mutex_t *m) {
|
||||||
}
|
}
|
||||||
__attribute__((weak)) void pfs_debug_dump_internals() {}
|
__attribute__((weak)) void pfs_debug_dump_internals() {}
|
||||||
__attribute__((weak)) void pfs_debug_register_signal_handlers() {}
|
__attribute__((weak)) void pfs_debug_register_signal_handlers() {}
|
||||||
|
__attribute__((weak)) void pfs_debug_check_lock_order(const char *file, unsigned long line) {}
|
||||||
|
|
||||||
static int pfs_ftruncate_of_locked(psync_openfile_t *of, fuse_off_t size);
|
static int pfs_ftruncate_of_locked(psync_openfile_t *of, fuse_off_t size);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@
|
||||||
#include "pfoldersync.h"
|
#include "pfoldersync.h"
|
||||||
#include "ptimer.h"
|
#include "ptimer.h"
|
||||||
#include "ptree.h"
|
#include "ptree.h"
|
||||||
|
#include "psql.h"
|
||||||
|
|
||||||
#define pfs_need_per_folder_refresh() pfs_need_per_folder_refresh_f()
|
#define pfs_need_per_folder_refresh() pfs_need_per_folder_refresh_f()
|
||||||
#define pfs_need_per_folder_refresh_const() 1
|
#define pfs_need_per_folder_refresh_const() 1
|
||||||
|
|
@ -137,6 +138,8 @@ typedef struct {
|
||||||
int dummy[0];
|
int dummy[0];
|
||||||
} pfs_index_header;
|
} pfs_index_header;
|
||||||
|
|
||||||
|
void pfs_debug_check_lock_order(const char *file, unsigned long line);
|
||||||
|
|
||||||
#if IS_DEBUG
|
#if IS_DEBUG
|
||||||
#define pfs_lock_file(of) pfs_do_lock_file(of, __FILE__, __LINE__)
|
#define pfs_lock_file(of) pfs_do_lock_file(of, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
|
@ -145,6 +148,7 @@ typedef struct {
|
||||||
extern PSYNC_THREAD const char *psync_thread_name;
|
extern PSYNC_THREAD const char *psync_thread_name;
|
||||||
static inline int pfs_do_lock_file(psync_openfile_t *of, const char *file,
|
static inline int pfs_do_lock_file(psync_openfile_t *of, const char *file,
|
||||||
unsigned long line) {
|
unsigned long line) {
|
||||||
|
pfs_debug_check_lock_order(file, line);
|
||||||
if (unlikely(pthread_mutex_trylock(&of->mutex))) {
|
if (unlikely(pthread_mutex_trylock(&of->mutex))) {
|
||||||
struct timespec tm;
|
struct timespec tm;
|
||||||
clock_gettime(CLOCK_REALTIME, &tm);
|
clock_gettime(CLOCK_REALTIME, &tm);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue