From 7583f97d5f19aa2d207f8a35a1a3a8b76f672e30 Mon Sep 17 00:00:00 2001 From: Benjamin Kaduk Date: Wed, 15 Oct 2014 15:03:36 -0400 Subject: [PATCH] Allow compiling with KERNEL and AFS_PTHREAD_ENV Add the necessary preprocessor conditionals to allow building libuafs with AFS_PTHREAD_ENV defined. A follow-up commit will switch to building libuafs using libtool, which will set the pthread compiler/linker flags. UKERNEL is already using the pthread primitives for its internal kernel synchronization, so there should not be any harm from additionally specifying the pthread build arguments. This change was produced mostly in a mechanical fashion, attempting to perform such a build, and eliminating compiler and linker errors in an iterative process. No concerted effort has been made to audit the whole kernel codebase for correctness of conditionals, but the linktest executable does link (that is, the overall build succeeds). Change-Id: I14a3ab5fce72812d92ba5657c734783dbd086ee3 Reviewed-on: http://gerrit.openafs.org/11546 Reviewed-by: D Brashear Tested-by: BuildBot --- src/rx/rx.c | 20 ++++++++++++++------ src/rx/rx_globals.h | 4 ++-- src/rxkad/rxkad_common.c | 12 ++++++------ src/rxkad/stats.h | 18 +++++++++--------- src/util/pthread_glock.h | 6 +++--- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/rx/rx.c b/src/rx/rx.c index a333c39..338e3a6 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -256,6 +256,7 @@ extern afs_kmutex_t rx_packets_mutex; extern afs_kmutex_t rx_refcnt_mutex; extern afs_kmutex_t des_init_mutex; extern afs_kmutex_t des_random_mutex; +#ifndef KERNEL extern afs_kmutex_t rx_clock_mutex; extern afs_kmutex_t rxi_connCacheMutex; extern afs_kmutex_t event_handler_mutex; @@ -265,6 +266,7 @@ extern afs_kmutex_t rx_if_mutex; extern afs_kcondvar_t rx_event_handler_cond; extern afs_kcondvar_t rx_listener_cond; +#endif /* !KERNEL */ static afs_kmutex_t epoch_mutex; static afs_kmutex_t rx_init_mutex; @@ -274,24 +276,28 @@ static afs_kmutex_t rx_rpc_stats; static void rxi_InitPthread(void) { - MUTEX_INIT(&rx_clock_mutex, "clock", MUTEX_DEFAULT, 0); - MUTEX_INIT(&rx_stats_mutex, "stats", MUTEX_DEFAULT, 0); - MUTEX_INIT(&rx_atomic_mutex, "atomic", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_quota_mutex, "quota", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_pthread_mutex, "pthread", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_packets_mutex, "packets", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_refcnt_mutex, "refcnts", MUTEX_DEFAULT, 0); - MUTEX_INIT(&epoch_mutex, "epoch", MUTEX_DEFAULT, 0); - MUTEX_INIT(&rx_init_mutex, "init", MUTEX_DEFAULT, 0); - MUTEX_INIT(&event_handler_mutex, "event handler", MUTEX_DEFAULT, 0); +#ifndef KERNEL + MUTEX_INIT(&rx_clock_mutex, "clock", MUTEX_DEFAULT, 0); MUTEX_INIT(&rxi_connCacheMutex, "conn cache", MUTEX_DEFAULT, 0); + MUTEX_INIT(&event_handler_mutex, "event handler", MUTEX_DEFAULT, 0); MUTEX_INIT(&listener_mutex, "listener", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_if_init_mutex, "if init", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_if_mutex, "if", MUTEX_DEFAULT, 0); +#endif + MUTEX_INIT(&rx_stats_mutex, "stats", MUTEX_DEFAULT, 0); + MUTEX_INIT(&rx_atomic_mutex, "atomic", MUTEX_DEFAULT, 0); + MUTEX_INIT(&epoch_mutex, "epoch", MUTEX_DEFAULT, 0); + MUTEX_INIT(&rx_init_mutex, "init", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_debug_mutex, "debug", MUTEX_DEFAULT, 0); +#ifndef KERNEL CV_INIT(&rx_event_handler_cond, "evhand", CV_DEFAULT, 0); CV_INIT(&rx_listener_cond, "rxlisten", CV_DEFAULT, 0); +#endif osi_Assert(pthread_key_create(&rx_thread_id_key, NULL) == 0); osi_Assert(pthread_key_create(&rx_ts_info_key, NULL) == 0); @@ -312,7 +318,9 @@ rxi_InitPthread(void) MUTEX_INIT(&rx_connHashTable_lock, "rx_connHashTable_lock", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_serverPool_lock, "rx_serverPool_lock", MUTEX_DEFAULT, 0); +#ifndef KERNEL MUTEX_INIT(&rxi_keyCreate_lock, "rxi_keyCreate_lock", MUTEX_DEFAULT, 0); +#endif #endif /* RX_ENABLE_LOCKS */ } diff --git a/src/rx/rx_globals.h b/src/rx/rx_globals.h index 1566878..5d459c3 100644 --- a/src/rx/rx_globals.h +++ b/src/rx/rx_globals.h @@ -235,7 +235,7 @@ EXT struct opr_queue rx_freePacketQueue; EXT afs_kmutex_t rx_freePktQ_lock; #endif /* RX_ENABLE_LOCKS */ -#if defined(AFS_PTHREAD_ENV) +#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL) #define RX_ENABLE_TSFPQ EXT int rx_TSFPQGlobSize GLOBALSINIT(3); /* number of packets to transfer between global and local queues in one op */ EXT int rx_TSFPQLocalMax GLOBALSINIT(15); /* max number of packets on local FPQ before returning a glob to the global pool */ @@ -417,7 +417,7 @@ EXT int rx_TSFPQMaxProcs GLOBALSINIT(0); /* max number of threads expected */ (rx_ts_info_p)->_FPQ.checkin_ops++; \ (rx_ts_info_p)->_FPQ.checkin_xfer += (num_transfer); \ } while(0) -#endif /* AFS_PTHREAD_ENV */ +#endif /* AFS_PTHREAD_ENV && !KERNEL */ /* Number of free packets */ EXT int rx_nFreePackets GLOBALSINIT(0); diff --git a/src/rxkad/rxkad_common.c b/src/rxkad/rxkad_common.c index 463573c..1e46efb 100644 --- a/src/rxkad/rxkad_common.c +++ b/src/rxkad/rxkad_common.c @@ -59,15 +59,15 @@ #endif /* variable initialization for the benefit of darwin compiler; if it causes problems elsewhere, conditionalize for darwin or fc_test compile breaks */ -#ifdef AFS_PTHREAD_ENV +#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL) struct rxkad_global_stats rxkad_global_stats; pthread_mutex_t rxkad_global_stats_lock; pthread_key_t rxkad_stats_key; -#else /* AFS_PTHREAD_ENV */ +#else /* AFS_PTHREAD_ENV && !KERNEL */ struct rxkad_stats rxkad_stats; -#endif /* AFS_PTHREAD_ENV */ +#endif /* AFS_PTHREAD_ENV && !KERNEL */ -#ifdef AFS_PTHREAD_ENV +#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL) /* Pthread initialisation */ static pthread_once_t rxkad_once_init = PTHREAD_ONCE_INIT; extern pthread_mutex_t rxkad_random_mutex; @@ -181,13 +181,13 @@ int rxkad_stats_agg(rxkad_stats_t * rxkad_stats) { RXKAD_GLOBAL_STATS_UNLOCK; return 0; } -#else +#else /* AFS_PTHREAD_ENV && !KERNEL */ void rxkad_Init(void) { return; } -#endif /* AFS_PTHREAD_ENV */ +#endif /* AFS_PTHREAD_ENV && !KERNEL */ /* static prototypes */ static afs_int32 ComputeSum(struct rx_packet *apacket, diff --git a/src/rxkad/stats.h b/src/rxkad/stats.h index dd65f75..faff969 100644 --- a/src/rxkad/stats.h +++ b/src/rxkad/stats.h @@ -20,7 +20,7 @@ live with the nearly accurate aggregation (e.g. you might miss a few increments, but the resulting aggregation should be almost correct). */ -#ifdef AFS_PTHREAD_ENV +#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL) typedef struct rxkad_stats_t { #else struct rxkad_stats { @@ -47,19 +47,19 @@ struct rxkad_stats { afs_uint32 clientObjects; afs_uint32 serverObjects; long spares[8]; -#ifdef AFS_PTHREAD_ENV +#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL) struct rxkad_stats_t * next; struct rxkad_stats_t * prev; } rxkad_stats_t; /* put these here for convenience */ -#else /* AFS_PTHREAD_ENV */ +#else /* AFS_PTHREAD_ENV && !KERNEL */ }; #ifdef AFS_NT40_ENV struct rxkad_stats rxkad_stats; /* put this here for convenience */ #endif -#endif /* AFS_PTHREAD_ENV */ +#endif /* AFS_PTHREAD_ENV && !KERNEL*/ -#ifdef AFS_PTHREAD_ENV +#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL) struct rxkad_global_stats { rxkad_stats_t * first; rxkad_stats_t * last; @@ -128,13 +128,13 @@ extern int rxkad_stats_agg(rxkad_stats_t *); #define ADD_RXKAD_STATS(stats_elem, inc_value) #define SUB_RXKAD_STATS(stats_elem, dec_value) #endif /* AFS_OBSD38_ENV */ -#else /* AFS_PTHREAD_ENV */ +#else /* AFS_PTHREAD_ENV && !KERNEL*/ #define INC_RXKAD_STATS(stats_elem) rxkad_stats.stats_elem++ #define DEC_RXKAD_STATS(stats_elem) rxkad_stats.stats_elem-- #define ADD_RXKAD_STATS(stats_elem, inc_value) rxkad_stats.stats_elem += (inc_value) #define SUB_RXKAD_STATS(stats_elem, dec_value) rxkad_stats.stats_elem -= (dec_value) #define GET_RXKAD_STATS(stats) memcpy((stats), &rxkad_stats, sizeof(rxkad_stats)) -#endif /* AFS_PTHREAD_ENV */ +#endif /* AFS_PTHREAD_ENV && !KERNEL */ #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV) @@ -145,9 +145,9 @@ extern int rxkad_stats_agg(rxkad_stats_t *); #define RXKAD_STATS_DECLSPEC extern #endif -#ifdef AFS_PTHREAD_ENV +#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL) RXKAD_STATS_DECLSPEC struct rxkad_global_stats rxkad_global_stats; -#else /* AFS_PTHREAD_ENV */ +#else /* AFS_PTHREAD_ENV && !KERNEL */ RXKAD_STATS_DECLSPEC struct rxkad_stats rxkad_stats; #endif diff --git a/src/util/pthread_glock.h b/src/util/pthread_glock.h index e323e3f..2ef26cd 100644 --- a/src/util/pthread_glock.h +++ b/src/util/pthread_glock.h @@ -10,7 +10,7 @@ #ifndef _AFS_PTHREAD_GLOCK_H_ #define _AFS_PTHREAD_GLOCK_H_ -#ifdef AFS_PTHREAD_ENV +#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL) #include #include @@ -40,11 +40,11 @@ extern int pthread_recursive_mutex_unlock(pthread_recursive_mutex_p); #define UNLOCK_GLOBAL_MUTEX \ opr_Verify(pthread_recursive_mutex_unlock(&grmutex)==0) -#else +#else /* AFS_PTHREAD_ENV && !KERNEL */ #define LOCK_GLOBAL_MUTEX #define UNLOCK_GLOBAL_MUTEX -#endif /* AFS_PTHREAD_ENV */ +#endif /* AFS_PTHREAD_ENV && !KERNEL */ #endif /* _AFS_PTHREAD_GLOCK_H_ */ -- 1.9.4