Whamcloud - gitweb
b=15870
[fs/lustre-release.git] / lnet / lnet / api-ni.c
index 82c1d75..8a86dcc 100644 (file)
@@ -61,8 +61,8 @@ lnet_get_networks(void)
         int     rc;
 
         if (*networks != 0 && *ip2nets != 0) {
-                LCONSOLE_ERROR("Please specify EITHER 'networks' or 'ip2nets'"
-                               " but not both at once\n");
+                LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
+                                   "'ip2nets' but not both at once\n");
                 return NULL;
         }
         
@@ -94,8 +94,8 @@ lnet_get_portals_compatibility(void)
                 LCONSOLE_WARN("Starting in strong portals-compatible mode\n");
         } 
 
-        LCONSOLE_ERROR("portals_compatibility=\"%s\" not supported\n",
-                       portals_compatibility);
+        LCONSOLE_ERROR_MSG(0x102, "portals_compatibility=\"%s\" not supported\n",
+                           portals_compatibility);
         return -EINVAL;
 }
 
@@ -138,8 +138,8 @@ lnet_get_networks (void)
 
 #ifdef NOT_YET
         if (networks != NULL && ip2nets != NULL) {
-                LCONSOLE_ERROR("Please set EITHER 'LNET_NETWORKS' or "
-                               "'LNET_IP2NETS' but not both at once\n");
+                LCONSOLE_ERROR_MSG(0x103, "Please set EITHER 'LNET_NETWORKS' or"
+                                   " 'LNET_IP2NETS' but not both at once\n");
                 return NULL;
         }
 
@@ -186,7 +186,7 @@ lnet_get_portals_compatibility(void)
         return 0;
 }
 
-# if !HAVE_LIBPTHREAD
+# ifndef HAVE_LIBPTHREAD
 
 void lnet_init_locks(void)
 {
@@ -615,6 +615,17 @@ lnet_fini_finalizers(void)
         LASSERT (list_empty(&the_lnet.ln_finalizeq));
 }
 
+#ifndef __KERNEL__
+/* Temporary workaround to allow uOSS and test programs force server
+ * mode in userspace. See comments near ln_server_mode_flag in
+ * lnet/lib-types.h */
+
+void
+lnet_server_mode() {
+        the_lnet.ln_server_mode_flag = 1;
+}
+#endif        
+
 int
 lnet_prepare(lnet_pid_t requested_pid)
 {
@@ -630,8 +641,18 @@ lnet_prepare(lnet_pid_t requested_pid)
         LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
         the_lnet.ln_pid = requested_pid;
 #else
-        /* My PID must be unique on this node and flag I'm userspace */
-        the_lnet.ln_pid = getpid() | LNET_PID_USERFLAG;
+        if (the_lnet.ln_server_mode_flag) {/* server case (uOSS) */
+                LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
+                
+                if (cfs_curproc_uid())/* Only root can run user-space server */
+                        return -EPERM;
+                the_lnet.ln_pid = requested_pid;
+
+        } else {/* client case (liblustre) */
+
+                /* My PID must be unique on this node and flag I'm userspace */
+                the_lnet.ln_pid = getpid() | LNET_PID_USERFLAG;
+        }        
 #endif
 
         rc = lnet_descriptor_setup();
@@ -713,8 +734,6 @@ lnet_unprepare (void)
         LASSERT (the_lnet.ln_nzombie_nis == 0);
                
         for (idx = 0; idx < the_lnet.ln_nportals; idx++) {
-
-                LNetClearLazyPortal(idx);
                 LASSERT (list_empty(&the_lnet.ln_portals[idx].ptl_msgq));
 
                 while (!list_empty (&the_lnet.ln_portals[idx].ptl_ml)) {
@@ -751,6 +770,7 @@ lnet_unprepare (void)
 
                 CERROR ("Active msg %p on exit\n", msg);
                 LASSERT (msg->msg_onactivelist);
+                msg->msg_onactivelist = 0;
                 list_del (&msg->msg_activelist);
                 lnet_msg_free (msg);
         }
@@ -838,7 +858,7 @@ lnet_count_acceptor_nis (lnet_ni_t **first_ni)
          * *first_ni so the acceptor can pass it connections "blind" to retain
          * binary compatibility. */
         int                count = 0;
-#ifdef __KERNEL__
+#if defined(__KERNEL__) || defined(HAVE_LIBPTHREAD)
         struct list_head  *tmp;
         lnet_ni_t         *ni;
 
@@ -857,7 +877,8 @@ lnet_count_acceptor_nis (lnet_ni_t **first_ni)
         }
         
         LNET_UNLOCK();
-#endif
+
+#endif /* defined(__KERNEL__) || defined(HAVE_LIBPTHREAD) */
         return count;
 }
 
@@ -903,9 +924,14 @@ lnet_shutdown_lndnis (void)
         }
 
         LNET_UNLOCK();
+
+        /* Clear lazy portals and drop delayed messages which hold refs
+         * on their lnet_msg_t::msg_rxpeer */
+        for (i = 0; i < the_lnet.ln_nportals; i++)
+                LNetClearLazyPortal(i);
+
         /* Clear the peer table and wait for all peers to go (they hold refs on
          * their NIs) */
-
         lnet_clear_peer_table();
 
         LNET_LOCK();
@@ -970,7 +996,7 @@ lnet_startup_lndnis (void)
         int                nicount = 0;
         char              *nets = lnet_get_networks();
 
-        INIT_LIST_HEAD(&nilist);
+        CFS_INIT_LIST_HEAD(&nilist);
 
         if (nets == NULL)
                 goto failed;
@@ -1001,9 +1027,9 @@ lnet_startup_lndnis (void)
                                        libcfs_lnd2str(lnd_type),
                                        libcfs_lnd2modname(lnd_type), rc);
 #ifndef CONFIG_KMOD
-                                LCONSOLE_ERROR("Your kernel must be compiled "
-                                               "with CONFIG_KMOD set for "
-                                               "automatic module loading.");
+                                LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
+                                         "compiled with CONFIG_KMOD set for "
+                                         "automatic module loading.");
 #endif
                                 goto failed;
                         }
@@ -1030,8 +1056,9 @@ lnet_startup_lndnis (void)
                 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
 
                 if (rc != 0) {
-                        LCONSOLE_ERROR("Error %d starting up LNI %s\n",
-                                       rc, libcfs_lnd2str(lnd->lnd_type));
+                        LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s"
+                                           "\n",
+                                           rc, libcfs_lnd2str(lnd->lnd_type));
                         LNET_LOCK();
                         lnd->lnd_refcount--;
                         LNET_UNLOCK();
@@ -1058,20 +1085,20 @@ lnet_startup_lndnis (void)
                                 the_lnet.ln_eqwaitni = ni;
                         }
                 } else {
-# if !HAVE_LIBPTHREAD
-                        LCONSOLE_ERROR("LND %s not supported in a "
-                                       "single-threaded runtime\n",
-                                       libcfs_lnd2str(lnd_type));
+# ifndef HAVE_LIBPTHREAD
+                        LCONSOLE_ERROR_MSG(0x106, "LND %s not supported in a "
+                                           "single-threaded runtime\n",
+                                           libcfs_lnd2str(lnd_type));
                         goto failed;
 # endif
                 }
 #endif
                 if (ni->ni_peertxcredits == 0 ||
                     ni->ni_maxtxcredits == 0) {
-                        LCONSOLE_ERROR("LNI %s has no %scredits\n",
-                                       libcfs_lnd2str(lnd->lnd_type),
-                                       ni->ni_peertxcredits == 0 ?
-                                       "" : "per-peer ");
+                        LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
+                                           libcfs_lnd2str(lnd->lnd_type),
+                                           ni->ni_peertxcredits == 0 ?
+                                           "" : "per-peer ");
                         goto failed;
                 }
 
@@ -1084,8 +1111,9 @@ lnet_startup_lndnis (void)
                 /* Handle nidstrings for network 0 just like this one */
                 if (the_lnet.ln_ptlcompat > 0) {
                         if (nicount > 0) {
-                                LCONSOLE_ERROR("Can't run > 1 network when "
-                                               "portals_compatibility is set\n");
+                                LCONSOLE_ERROR_MSG(0x108, "Can't run > 1 "
+                                       "network when portals_compatibility is "
+                                       "set\n");
                                 goto failed;
                         }
                         libcfs_setnet0alias(lnd->lnd_type);
@@ -1096,8 +1124,9 @@ lnet_startup_lndnis (void)
 
         if (the_lnet.ln_eqwaitni != NULL && nicount > 1) {
                 lnd_type = the_lnet.ln_eqwaitni->ni_lnd->lnd_type;
-                LCONSOLE_ERROR("LND %s can only run single-network\n",
-                               libcfs_lnd2str(lnd_type));
+                LCONSOLE_ERROR_MSG(0x109, "LND %s can only run single-network"
+                                   "\n",
+                                   libcfs_lnd2str(lnd_type));
                 goto failed;
         }
 
@@ -1145,7 +1174,7 @@ LNetInit(void)
 # ifdef CRAY_XT3
         LNET_REGISTER_ULND(the_ptllnd);
 # endif
-# if HAVE_LIBPTHREAD
+# ifdef HAVE_LIBPTHREAD
         LNET_REGISTER_ULND(the_tcplnd);
 # endif
 #endif