]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
rx service specific data
authorMatt Benjamin <matt@linuxbox.com>
Tue, 8 Jun 2010 22:29:13 +0000 (18:29 -0400)
committerDerrick Brashear <shadow@dementia.org>
Thu, 10 Jun 2010 22:13:46 +0000 (15:13 -0700)
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 <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
src/rx/rx.c
src/rx/rx.h
src/rx/rx_globals.h
src/rx/rx_prototypes.h

index ea68d73c8c52a564b34f6f9f90c309bd8f8d170b..407b03c40f5895ccc34741eb0f65ecf3a8694a2d 100644 (file)
@@ -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 */
 
 /*
index c9c902390cf02e19b18e21449a929770575219ad..81e419017a26c705f403398f62dd0cbcf7e7cf00 100644 (file)
@@ -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 */
index a8d3c24492fd1263fb32d3f5329ad24bb8ef55e1..40a477d018a5cb896d2218d315a42029fbad1185 100644 (file)
@@ -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))
index 48fb89f58fa89e79e2dc581ebe7234fc2c6a6726..58f2c94de0bb5a21bba1546e592e34854677a15e 100644 (file)
@@ -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,