From 56014bdd4a4935ecf9fc099f2acbbd56921d2d15 Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Thu, 9 May 2024 17:10:54 +0700 Subject: [PATCH] LU-17836 build: allow builds without libpthread Configure currently allows for --disable-libpthread it is not frequently used but may be needed for some users. Test-Parameters: trivial Signed-off-by: Shaun Tancheff Change-Id: I32049bab8e0f278b4c80fe37839c8c90c45d4c74 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55062 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Petros Koutoupis Reviewed-by: Oleg Drokin --- lustre/tests/rw_seq_cst_vs_drop_caches.c | 13 +++++++++++-- lustre/utils/lctl_thread.c | 25 ++++++++++--------------- lustre/utils/lctl_thread.h | 20 +++++++++++++++++++- lustre/utils/obd.c | 8 +++++--- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/lustre/tests/rw_seq_cst_vs_drop_caches.c b/lustre/tests/rw_seq_cst_vs_drop_caches.c index e428fb0..c0f7ded 100644 --- a/lustre/tests/rw_seq_cst_vs_drop_caches.c +++ b/lustre/tests/rw_seq_cst_vs_drop_caches.c @@ -8,7 +8,9 @@ #include #include #include +#ifdef HAVE_LIBPTHREAD #include +#endif /* * Usage: rw_seq_cst_vs_drop_caches [-m] /mnt/lustre/file0 /mnt/lustre2/file0 @@ -36,9 +38,11 @@ static int fd[2] = { -1, -1 }; * contending with constant reads */ static uint64_t u, u_max = UINT64_MAX / 2; -static uint64_t v[2]; char *ptr; +#ifdef HAVE_LIBPTHREAD +static uint64_t v[2]; + static void *access_thread_start(void *unused) { char *ptr2 = NULL; @@ -72,13 +76,14 @@ static void *access_thread_start(void *unused) munmap(ptr2, sizeof(v[i])); abort(); } +#endif static char stderr_buf[4096]; int main(int argc, char *argv[]) { int drop_caches_fd = -1; - pthread_t access_thread; + pthread_t access_thread __attribute__ ((unused)); struct stat st[2]; ssize_t rc; int i, ch; @@ -140,9 +145,11 @@ int main(int argc, char *argv[]) handle_error("pwrite"); } +#ifdef HAVE_LIBPTHREAD rc = pthread_create(&access_thread, NULL, &access_thread_start, NULL); if (rc != 0) handle_error("pthread_create"); +#endif for (u = 1; u <= u_max; u++) { if (mmap_mode) { @@ -158,6 +165,7 @@ int main(int argc, char *argv[]) handle_error("drop caches"); } +#ifdef HAVE_LIBPTHREAD rc = pthread_cancel(access_thread); if (rc != 0) handle_error("pthread_cancel"); @@ -165,6 +173,7 @@ int main(int argc, char *argv[]) rc = pthread_join(access_thread, NULL); if (rc != 0) handle_error("pthread_join"); +#endif if (mmap_mode) munmap(ptr, sizeof(u)); diff --git a/lustre/utils/lctl_thread.c b/lustre/utils/lctl_thread.c index f4bd5d7..29b4e45 100644 --- a/lustre/utils/lctl_thread.c +++ b/lustre/utils/lctl_thread.c @@ -26,13 +26,15 @@ * * Author: Rajeev Mishra */ - #include - #include - #include - #include - #include "lctl_thread.h" - #include - #include + +#include +#include +#include +#include +#include "lctl_thread.h" +#include +#include + #if HAVE_LIBPTHREAD /** * Initialize the given set_param work queue. @@ -298,12 +300,5 @@ out_free: free(sp_threads); return rc; } -#else -#define popt_is_parallel(popt) 0 -#define spwq_init(wq, popt) 0 -#define spwq_expand(wq, num_items) 0 -#define spwq_add_item(wq, path, param_name, value) 0 -#define sp_run_threads(wq) 0 -#define spwq_destroy(wq) 0 -struct sp_workq { int unused; } + #endif /* HAVE_LIBPTHREAD */ diff --git a/lustre/utils/lctl_thread.h b/lustre/utils/lctl_thread.h index c9f32af..ae64041 100644 --- a/lustre/utils/lctl_thread.h +++ b/lustre/utils/lctl_thread.h @@ -49,9 +49,10 @@ struct param_opts { unsigned int po_header:1; unsigned int po_parallel_threads; }; -#define popt_is_parallel(popt) ((popt).po_parallel_threads > 0) #ifdef HAVE_LIBPTHREAD +#define popt_is_parallel(popt) ((popt).po_parallel_threads > 0) + int write_param(const char *path, const char *param_name, struct param_opts *popt, const char *value); @@ -96,4 +97,21 @@ int spwq_expand(struct sp_workq *wq, size_t num_items); int spwq_add_item(struct sp_workq *wq, char *path, char *param_name, char *value); int sp_run_threads(struct sp_workq *wq); +#else +#define popt_is_parallel(popt) 0 + +struct sp_workq { int unused; }; + +static inline int spwq_init(struct sp_workq *wq, struct param_opts *popt) +{ return 0; } +static inline int spwq_destroy(struct sp_workq *wq) +{ return 0; } +static inline int spwq_expand(struct sp_workq *wq, size_t num_items) +{ return 0; } +static inline int spwq_add_item(struct sp_workq *wq, char *path, + char *param_name, char *value) +{ return 0; } +static inline int sp_run_threads(struct sp_workq *wq) +{ return 0; } + #endif diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index 81e7cd1..d731156 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -2004,16 +2004,18 @@ int jt_obd_test_brw(int argc, char **argv) struct obd_ioctl_data data; struct timeval start, next_time; char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; - __u64 count, next_count, len, stride, thr_offset = 0, objid = 3; + __u64 count, next_count, len, thr_offset = 0, objid = 3; int write = 0, verbose = 1, cmd, i, rc = 0, pages = 1; int offset_pages = 0; long n; int repeat_offset = 0; unsigned long long ull; - int nthr_per_obj = 0; int verify = 1; - int obj_idx = 0; char *end; + __u64 stride __attribute__ ((unused)); + int nthr_per_obj __attribute__ ((unused)) = 0; + int obj_idx __attribute__ ((unused)) = 0; + if (argc < 2 || argc > 7) { fprintf(stderr, "error: %s: bad number of arguments: %d\n", -- 1.8.3.1