rx/rxkad: Move rxkad initialisation into rxkad

When the RX pthread conversion was done, the initialisation of rxkad
mutexes was incorporated into the rx library itself. This is a layering
violation (it breaks the relatively clean security object abstraction),
and means that you can't actually use RX without the rxkad library.

So, remove all of this initialisation from RX. As security libraries
don't have an explicit initialisation function, we setup our various
mutexes using a pthread_once function called from the NewSecurityObject
functions.

This has the added bonus that it removes the final error in rx.c for
pthread builds, and so another bit of warning suppression can be
removed.

Change-Id: I3cf9b2404a03fb58534c5f41afd77aa5ba5e2256
Reviewed-on: http://gerrit.openafs.org/5361
Reviewed-by: Derrick Brashear <shadow@dementix.org>
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
This commit is contained in:
Simon Wilkinson 2011-07-05 09:20:15 +01:00 committed by Jeffrey Altman
parent ca0f1946a2
commit 327762071b
9 changed files with 40 additions and 21 deletions

View File

@ -57,7 +57,6 @@ libadmin/kas/afs_kasAdmin.c: all : Ubik_Call nonsense
libadmin/samples/rxstat_query_peer.c : all : util_RPCStatsStateGet types
libadmin/samples/rxstat_query_process.c : all : util_RPCStatsStateGet types
libadmin/test/client.c : all : util_RPCStatsStateGet types
rx/rx.c : all (pthread) : rxkad_global_stats_init not proto'd
rxkad/ticket5.c : all : v5gen.c has set-but-unused variables
ubik/ubikclient.c : strict-protos : ubik_Call
volser/vol-dump.c : format : afs_sfsize_t

View File

@ -134,7 +134,6 @@ rx_user.o: ${RX}/rx_user.c
rx_pthread.o: ${RX}/rx_pthread.c
$(AFS_CCRULE) $(RX)/rx_pthread.c
CFLAGS_rx.o = @CFLAGS_NOERROR@
rx.o: ${RX}/rx.c
$(AFS_CCRULE) $(RX)/rx.c

View File

@ -193,8 +193,6 @@ extern afs_kmutex_t event_handler_mutex;
extern afs_kmutex_t listener_mutex;
extern afs_kmutex_t rx_if_init_mutex;
extern afs_kmutex_t rx_if_mutex;
extern afs_kmutex_t rxkad_client_uid_mutex;
extern afs_kmutex_t rxkad_random_mutex;
extern afs_kcondvar_t rx_event_handler_cond;
extern afs_kcondvar_t rx_listener_cond;
@ -222,8 +220,6 @@ rxi_InitPthread(void)
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);
MUTEX_INIT(&rxkad_client_uid_mutex, "uid", MUTEX_DEFAULT, 0);
MUTEX_INIT(&rxkad_random_mutex, "rxkad random", MUTEX_DEFAULT, 0);
MUTEX_INIT(&rx_debug_mutex, "debug", MUTEX_DEFAULT, 0);
CV_INIT(&rx_event_handler_cond, "evhand", CV_DEFAULT, 0);
@ -232,8 +228,6 @@ rxi_InitPthread(void)
osi_Assert(pthread_key_create(&rx_thread_id_key, NULL) == 0);
osi_Assert(pthread_key_create(&rx_ts_info_key, NULL) == 0);
rxkad_global_stats_init();
MUTEX_INIT(&rx_rpc_stats, "rx_rpc_stats", MUTEX_DEFAULT, 0);
MUTEX_INIT(&rx_freePktQ_lock, "rx_freePktQ_lock", MUTEX_DEFAULT, 0);
#ifdef RX_ENABLE_LOCKS

View File

@ -33,14 +33,13 @@
#endif /* !UKERNEL */
#else /* ! KERNEL */
#include <roken.h>
#ifdef AFS_PTHREAD_ENV
#include "rx/rxkad.h"
#endif /* AFS_PTHREAD_ENV */
#endif /* KERNEL */
#include <rx/rx.h>
#include <rx/xdr.h>
#include "rxkad.h"
#include "stats.h"
#include "private_data.h"
#define XPRT_RXKAD_CLIENT
@ -157,6 +156,8 @@ rxkad_NewClientSecurityObject(rxkad_level level,
int code;
int size, psize;
rxkad_Init();
size = sizeof(struct rx_securityClass);
tsc = rxi_Alloc(size);
memset((void *)tsc, 0, size);

View File

@ -67,6 +67,32 @@ struct rxkad_stats rxkad_stats = { { 0 } };
#endif /* AFS_PTHREAD_ENV */
#ifdef AFS_PTHREAD_ENV
/* Pthread initialisation */
static pthread_once_t rxkad_once_init = PTHREAD_ONCE_INIT;
extern pthread_mutex_t rxkad_client_uid_mutex;
extern pthread_mutex_t rxkad_random_mutex;
static void
rxkad_global_stats_init(void)
{
osi_Assert(pthread_mutex_init(&rxkad_global_stats_lock, (const pthread_mutexattr_t *)0) == 0);
osi_Assert(pthread_key_create(&rxkad_stats_key, NULL) == 0);
memset(&rxkad_global_stats, 0, sizeof(rxkad_global_stats));
}
static void
rxkad_InitPthread(void) {
MUTEX_INIT(&rxkad_client_uid_mutex, "uid", MUTEX_DEFAULT, 0);
MUTEX_INIT(&rxkad_random_mutex, "rxkad random", MUTEX_DEFAULT, 0);
rxkad_global_stats_init();
}
void
rxkad_Init(void) {
osi_Assert(pthread_once(&rxkad_once_init, rxkad_InitPthread) == 0);
}
/* rxkad_stats related stuff */
/*
@ -84,12 +110,6 @@ struct rxkad_stats rxkad_stats = { { 0 } };
osi_Assert((head) && ((head)->prev == NULL)); \
} while(0)
void rxkad_global_stats_init(void) {
osi_Assert(pthread_mutex_init(&rxkad_global_stats_lock, (const pthread_mutexattr_t *)0) == 0);
osi_Assert(pthread_key_create(&rxkad_stats_key, NULL) == 0);
memset(&rxkad_global_stats, 0, sizeof(rxkad_global_stats));
}
rxkad_stats_t *
rxkad_thr_stats_init(void) {
rxkad_stats_t * rxkad_stats;
@ -163,6 +183,12 @@ int rxkad_stats_agg(rxkad_stats_t * rxkad_stats) {
RXKAD_GLOBAL_STATS_UNLOCK;
return 0;
}
#else
void
rxkad_Init(void)
{
return;
}
#endif /* AFS_PTHREAD_ENV */
/* static prototypes */

View File

@ -52,6 +52,8 @@ extern int rxkad_GetResponse(struct rx_securityClass *aobj,
extern void rxkad_ResetState(void);
/* rxkad_common.c */
extern void rxkad_Init(void);
struct rxkad_endpoint;
extern int rxkad_SetupEndpoint(struct rx_connection *aconnp,
struct rxkad_endpoint *aendpointp);
@ -80,8 +82,6 @@ extern int rxkad_GetStats(struct rx_securityClass *aobj,
extern rxkad_level rxkad_StringToLevel(char *string);
extern char *rxkad_LevelToString(rxkad_level level);
extern void rxkad_global_stats_init(void);
/* rxkad_errs.c */
/* rxkad_server.c */

View File

@ -137,6 +137,8 @@ rxkad_NewServerSecurityObject(rxkad_level level, void *get_key_rock,
struct rxkad_sprivate *tsp;
int size;
rxkad_Init();
if (!get_key)
return 0;

View File

@ -69,7 +69,6 @@ struct rxkad_global_stats {
extern pthread_mutex_t rxkad_global_stats_lock;
extern pthread_key_t rxkad_stats_key;
extern void rxkad_global_stats_init(void);
extern rxkad_stats_t * rxkad_thr_stats_init(void);
extern int rxkad_stats_agg(rxkad_stats_t *);

View File

@ -155,7 +155,6 @@ rx_user.o: ${RX}/rx_user.c
rx_pthread.o: ${RX}/rx_pthread.c
$(AFS_CCRULE) $(RX)/rx_pthread.c
CFLAGS_rx.o = @CFLAGS_NOERROR@
rx.o: ${RX}/rx.c
$(AFS_CCRULE) $(RX)/rx.c