Whamcloud - gitweb
. fixed ia64 format warnings
[fs/lustre-release.git] / lnet / ulnds / socklnd / proclib.c
index 99afe66..2627253 100644 (file)
@@ -2,6 +2,7 @@
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
  *  Copyright (c) 2002 Cray Inc.
+ *  Copyright (c) 2003 Cluster File Systems, Inc.
  *
  *   This file is part of Lustre, http://www.lustre.org.
  *
 #include <stdio.h>
 #include <stdarg.h>
 #include <unistd.h>
-#include <syscall.h>
 #include <procbridge.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
 #include <errno.h>
 #include <timer.h>
-//#include <util/pqtimer.h>
 #include <dispatch.h>
 
 /* the following functions are stubs to satisfy the nal definition
@@ -48,7 +47,7 @@ static int nal_write(nal_cb_t *nal,
                      void *private,
                      user_ptr dst_addr,
                      void *src_addr,
-                     ptl_size_t len)
+                     size_t len)
 {
     memcpy(dst_addr, src_addr, len);
     return 0;
@@ -65,7 +64,7 @@ static int nal_read(nal_cb_t * nal,
 }
 
 static void *nal_malloc(nal_cb_t *nal,
-                        ptl_size_t len)
+                        size_t len)
 {
     void *buf =  malloc(len);
     return buf;
@@ -73,7 +72,7 @@ static void *nal_malloc(nal_cb_t *nal,
 
 static void nal_free(nal_cb_t *nal,
                      void *buf,
-                     ptl_size_t len)
+                     size_t len)
 {
     free(buf);
 }
@@ -93,12 +92,20 @@ static void nal_printf(nal_cb_t *nal,
 static void nal_cli(nal_cb_t *nal,
                     unsigned long *flags)
 {
+    bridge b = (bridge) nal->nal_data;
+    procbridge p = (procbridge) b->local;
+
+    pthread_mutex_lock(&p->nal_cb_lock);
 }
 
 
 static void nal_sti(nal_cb_t *nal,
                     unsigned long *flags)
 {
+    bridge b = (bridge)nal->nal_data;
+    procbridge p = (procbridge) b->local;
+
+    pthread_mutex_unlock(&p->nal_cb_lock);
 }
 
 
@@ -108,69 +115,22 @@ static int nal_dist(nal_cb_t *nal,
 {
     return 0;
 }
-    
-
-
-/* Function:  data_from_api
- * Arguments: t: the nal state for this interface
- * Returns: whether to continue reading from the pipe
- *
- *   data_from_api() reads data from the api side in response
- *   to a select.
- *
- *   We define data_failure() for syntactic convenience
- *   of unix error reporting.
- */
-
-#define data_failure(operand,fd,buffer,length)\
-       if(syscall(SYS_##operand,fd,buffer,length)!=length){\
-          lib_fini(b->nal_cb);\
-          return(0);\
-       }
-static int data_from_api(void *arg)
-{
-        bridge b = arg;
-    procbridge p=(procbridge)b->local;
-    /* where are these two sizes derived from ??*/
-    char arg_block[ 256 ];
-    char ret_block[ 128 ];
-    ptl_size_t arg_len,ret_len;
-    int fd=p->to_lib[0];
-    int index;
-
-    data_failure(read,fd, &index, sizeof(index));
-
-    if (index==PTL_FINI) {
-        lib_fini(b->nal_cb);
-        if (b->shutdown) (*b->shutdown)(b);
-        syscall(SYS_write, p->from_lib[1],&b->alive,sizeof(b->alive));
-
-        /* a heavy-handed but convenient way of shutting down
-           the lower side thread */
-        pthread_exit(0);
-    }
-
-    data_failure(read,fd, &arg_len, sizeof(arg_len));
-    data_failure(read,fd, &ret_len, sizeof(ret_len));
-    data_failure(read,fd, arg_block, arg_len);
-
-    lib_dispatch(b->nal_cb, NULL, index, arg_block, ret_block);
-
-    data_failure(write,p->from_lib[1],ret_block, ret_len);
-    return(1);
-}
-#undef data_failure
-
-
 
 static void wakeup_topside(void *z)
 {
-    bridge b=z;
-    procbridge p=b->local;
+    bridge b = z;
+    procbridge p = b->local;
+    int stop;
 
     pthread_mutex_lock(&p->mutex);
+    stop = p->nal_flags & NAL_FLAG_STOPPING;
+    if (stop)
+        p->nal_flags |= NAL_FLAG_STOPPED;
     pthread_cond_broadcast(&p->cond);
     pthread_mutex_unlock(&p->mutex);
+
+    if (stop)
+        pthread_exit(0);
 }
 
 
@@ -195,7 +155,8 @@ nal_initialize nal_table[PTL_IFACE_MAX]={0,tcpnal_init,0};
 
 void *nal_thread(void *z)
 {
-    bridge b=z;
+    nal_init_args_t *args = (nal_init_args_t *) z;
+    bridge b = args->nia_bridge;
     procbridge p=b->local;
     int rc;
     ptl_pid_t pid_request;
@@ -216,15 +177,9 @@ void *nal_thread(void *z)
     b->nal_cb->cb_sti=nal_sti;
     b->nal_cb->cb_dist=nal_dist;
 
-
-    register_io_handler(p->to_lib[0],READ_HANDLER,data_from_api,(void *)b);
-
-    if(!(rc = syscall(SYS_read, p->to_lib[0], &pid_request, sizeof(pid_request))))
-        perror("procbridge read from api");
-    if(!(rc = syscall(SYS_read, p->to_lib[0], &desired, sizeof(ptl_ni_limits_t))))
-        perror("procbridge read from api");
-    if(!(rc = syscall(SYS_read, p->to_lib[0], &nal_type, sizeof(nal_type))))
-        perror("procbridge read from api");
+    pid_request = args->nia_requested_pid;
+    desired = *args->nia_limits;
+    nal_type = args->nia_nal_type;
 
     actual = desired;
     LIMIT(desired.max_match_entries,actual.max_match_entries,MAX_MES);
@@ -251,12 +206,12 @@ void *nal_thread(void *z)
      * it is non-zero since something went wrong.
      */
     /* this should perform error checking */
-#if 0
-    write(p->from_lib[1], &actual, sizeof(ptl_ni_limits_t));
-#endif
-    syscall(SYS_write, p->from_lib[1], &rc, sizeof(rc));
-    
-    if(!rc) {
+    pthread_mutex_lock(&p->mutex);
+    p->nal_flags |= rc ? NAL_FLAG_STOPPED : NAL_FLAG_RUNNING;
+    pthread_cond_broadcast(&p->cond);
+    pthread_mutex_unlock(&p->mutex);
+
+    if (!rc) {
         /* the thunk function is called each time the timer loop
            performs an operation and returns to blocking mode. we
            overload this function to inform the api side that
@@ -267,4 +222,3 @@ void *nal_thread(void *z)
     return(0);
 }
 #undef LIMIT
-