From: Matt Benjamin Date: Tue, 8 Jun 2010 22:29:13 +0000 (-0400) Subject: rx service specific data X-Git-Tag: openafs-devel-1_5_75~164 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=53c9258cd7300c03be3f3e50003cad3dfc59baf3;p=packages%2Fo%2Fopenafs.git rx service specific data Adds rx_GetServiceSpecific and rx_SetServiceSpecific to the rx_service interface, conforming to the equivalent calls in the rx_connection interface. For consistency, the implementation strategy is the same. The intended use is to more cleanly support server multiplexing within an RPC-based test dispatch library. Change-Id: I6a8968484efe2c858857008321996e67328bb75c Reviewed-on: http://gerrit.openafs.org/2097 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/src/rx/rx.c b/src/rx/rx.c index ea68d73c8..407b03c40 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -1430,6 +1430,11 @@ rx_NewServiceHost(afs_uint32 host, u_short port, u_short serviceId, tservice = rxi_AllocService(); NETPRI; + +#ifdef RX_ENABLE_LOCKS + MUTEX_INIT(&tservice->svc_data_lock, "svc data lock", MUTEX_DEFAULT, 0); +#endif + for (i = 0; i < RX_MAX_SERVICES; i++) { struct rx_service *service = rx_services[i]; if (service) { @@ -1476,6 +1481,8 @@ rx_NewServiceHost(afs_uint32 host, u_short port, u_short serviceId, service->connDeadTime = rx_connDeadTime; service->executeRequestProc = serviceProc; service->checkReach = 0; + service->nSpecific = 0; + service->specific = NULL; rx_services[i] = service; /* not visible until now */ USERPRI; return service; @@ -7572,6 +7579,32 @@ rx_SetSpecific(struct rx_connection *conn, int key, void *ptr) MUTEX_EXIT(&conn->conn_data_lock); } +void +rx_SetServiceSpecific(struct rx_service *svc, int key, void *ptr) +{ + int i; + MUTEX_ENTER(&svc->svc_data_lock); + if (!svc->specific) { + svc->specific = (void **)malloc((key + 1) * sizeof(void *)); + for (i = 0; i < key; i++) + svc->specific[i] = NULL; + svc->nSpecific = key + 1; + svc->specific[key] = ptr; + } else if (key >= svc->nSpecific) { + svc->specific = (void **) + realloc(svc->specific, (key + 1) * sizeof(void *)); + for (i = svc->nSpecific; i < key; i++) + svc->specific[i] = NULL; + svc->nSpecific = key + 1; + svc->specific[key] = ptr; + } else { + if (svc->specific[key] && rxi_keyCreate_destructor[key]) + (*rxi_keyCreate_destructor[key]) (svc->specific[key]); + svc->specific[key] = ptr; + } + MUTEX_EXIT(&svc->svc_data_lock); +} + void * rx_GetSpecific(struct rx_connection *conn, int key) { @@ -7585,6 +7618,20 @@ rx_GetSpecific(struct rx_connection *conn, int key) return ptr; } +void * +rx_GetServiceSpecific(struct rx_service *svc, int key) +{ + void *ptr; + MUTEX_ENTER(&svc->svc_data_lock); + if (key >= svc->nSpecific) + ptr = NULL; + else + ptr = svc->specific[key]; + MUTEX_EXIT(&svc->svc_data_lock); + return ptr; +} + + #endif /* !KERNEL */ /* diff --git a/src/rx/rx.h b/src/rx/rx.h index c9c902390..81e419017 100644 --- a/src/rx/rx.h +++ b/src/rx/rx.h @@ -324,6 +324,12 @@ struct rx_service { u_short idleDeadTime; /* Time a server will wait for I/O to start up again */ u_char checkReach; /* Check for asymmetric clients? */ afs_int32 idleDeadErr; + int nSpecific; /* number entries in specific data */ + void **specific; /* pointer to connection specific data */ +#ifdef RX_ENABLE_LOCKS + afs_kmutex_t svc_data_lock; /* protect specific data */ +#endif + }; #endif /* KDUMP_RX_LOCK */ diff --git a/src/rx/rx_globals.h b/src/rx/rx_globals.h index a8d3c2449..40a477d01 100644 --- a/src/rx/rx_globals.h +++ b/src/rx/rx_globals.h @@ -536,7 +536,19 @@ EXT afs_kmutex_t rx_connHashTable_lock; #define rxi_AllocSecurityObject() (struct rx_securityClass *) rxi_Alloc(sizeof(struct rx_securityClass)) #define rxi_FreeSecurityObject(obj) rxi_Free(obj, sizeof(struct rx_securityClass)) #define rxi_AllocService() (struct rx_service *) rxi_Alloc(sizeof(struct rx_service)) -#define rxi_FreeService(obj) rxi_Free(obj, sizeof(struct rx_service)) +#ifdef AFS_PTHREAD_ENV +#define rxi_FreeService(obj) \ +do { \ + assert(MUTEX_DESTROY(&(obj)->svc_data_lock)==0); \ + rxi_Free((obj), sizeof(struct rx_service)); \ +} while (0) +#else +#define rxi_FreeService(obj) \ +do { \ + MUTEX_DESTROY(&(obj)->svc_data_lock); \ + rxi_Free((obj), sizeof(struct rx_service)); \ +} while (0) +#endif #define rxi_AllocPeer() (struct rx_peer *) rxi_Alloc(sizeof(struct rx_peer)) #define rxi_FreePeer(peer) rxi_Free(peer, sizeof(struct rx_peer)) #define rxi_AllocConnection() (struct rx_connection *) rxi_Alloc(sizeof(struct rx_connection)) diff --git a/src/rx/rx_prototypes.h b/src/rx/rx_prototypes.h index 48fb89f58..58f2c94de 100644 --- a/src/rx/rx_prototypes.h +++ b/src/rx/rx_prototypes.h @@ -231,6 +231,8 @@ extern int rx_KeyCreate(rx_destructor_t rtn); #endif extern void rx_SetSpecific(struct rx_connection *conn, int key, void *ptr); extern void *rx_GetSpecific(struct rx_connection *conn, int key); +extern void rx_SetServiceSpecific(struct rx_service *svc, int key, void *ptr); +extern void * rx_GetServiceSpecific(struct rx_service *svc, int key); extern void rx_IncrementTimeAndCount(struct rx_peer *peer, afs_uint32 rxInterface, afs_uint32 currentFunc,