From 5bc48bd428303aabe19c196a47d1d89a605397be Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 3 May 2020 19:21:17 +0100 Subject: [PATCH] Fix building on musl * Add missing linux/stddef.h includes * Explicitly cast PAGE_SIZE to size_t. PAGE_SIZE is defined without UL suffix in musl * Musl doesn't define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, so initialize the mutexes with pthread_once. --- include/linux/slab.h | 2 +- libbcachefs/bcachefs.h | 1 + libbcachefs/bcachefs_format.h | 1 + libbcachefs/siphash.c | 1 + linux/preempt.c | 11 ++++++++++- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 5a9e7afd..d77b7683 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -22,7 +22,7 @@ static inline void *kmalloc(size_t size, gfp_t flags) p = size ? aligned_alloc(min(rounddown_pow_of_two(size), - PAGE_SIZE), size) + (size_t)PAGE_SIZE), size) : malloc(0); if (p && (flags & __GFP_ZERO)) memset(p, 0, size); diff --git a/libbcachefs/bcachefs.h b/libbcachefs/bcachefs.h index fa959376..d9c09b4f 100644 --- a/libbcachefs/bcachefs.h +++ b/libbcachefs/bcachefs.h @@ -179,6 +179,7 @@ #undef pr_fmt #define pr_fmt(fmt) "bcachefs: %s() " fmt "\n", __func__ +#include #include #include #include diff --git a/libbcachefs/bcachefs_format.h b/libbcachefs/bcachefs_format.h index 616863ef..0772c586 100644 --- a/libbcachefs/bcachefs_format.h +++ b/libbcachefs/bcachefs_format.h @@ -72,6 +72,7 @@ * inode number, 64 bit offset, 96 bit version field, etc.) for negligible cost. */ +#include #include #include #include diff --git a/libbcachefs/siphash.c b/libbcachefs/siphash.c index c062edb3..4565a843 100644 --- a/libbcachefs/siphash.c +++ b/libbcachefs/siphash.c @@ -44,6 +44,7 @@ * https://131002.net/siphash/ */ +#include #include #include #include diff --git a/linux/preempt.c b/linux/preempt.c index aa092c1d..72eceed3 100644 --- a/linux/preempt.c +++ b/linux/preempt.c @@ -15,7 +15,16 @@ * correct to instead guarantee mutual exclusion for the critical sections. */ -static pthread_mutex_t preempt_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +static pthread_mutex_t preempt_lock; + +__attribute__((constructor)) +static void preempt_init(void) { + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&preempt_lock, &attr); + pthread_mutexattr_destroy(&attr); +} void preempt_disable(void) {