]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
[opensm] Base service status on results that were received from opensm log messages.
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 17 Aug 2006 08:12:37 +0000 (08:12 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 17 Aug 2006 08:12:37 +0000 (08:12 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1@458 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

trunk/ulp/opensm/user/ibtrapgen/main.c
trunk/ulp/opensm/user/libopensm/osm_log.c
trunk/ulp/opensm/user/opensm/main.c
trunk/ulp/opensm/user/osmtest/main.c

index bb23326c38a46c58e117cd1935ae1c97ed24e9a8..f7f1de7d10ccd1b8f4299528b4bb03a82ab6de0f 100644 (file)
@@ -245,7 +245,9 @@ str2gid(
   *p_gid = temp;
   return 0;
 }
-
+void OsmReportState(IN const char *p_str)
+{
+}
 /**********************************************************************
  **********************************************************************/
 int OSM_CDECL
index 9034cdf741d5f737e181c1bd295d15fa2857e81b..3f6be6a2b7ef1f3270b2791380b6ccb2c7099058 100644 (file)
@@ -75,6 +75,8 @@ static char *month_str[] = {
   "Nov",
   "Dec"
 };
+#else 
+void OsmReportState(IN const char *p_str);
 #endif /* ndef WIN32 */
 
 void
@@ -125,6 +127,8 @@ osm_log(
     fprintf( p_log->out_port, "[%02d:%02d:%02d:%03d][%04X] -> %s",
                      st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
                      pid, buffer);
+    OsmReportState(buffer);
+
 #else
     fprintf( p_log->out_port, "%s %02d %02d:%02d:%02d %06d [%04X] -> %s\n",
              (result.tm_mon < 12 ? month_str[result.tm_mon] : "???"),
index 168b334ab82f5300bc9e187ce377370333192840..f688f0670b15f24282c65d5496fcc75e7cf11b0e 100644 (file)
@@ -67,6 +67,7 @@
 */
 osm_opensm_t osm;
 volatile unsigned int osm_exit_flag = 0;
+HANDLE osm_exit_event = NULL;
 
 #define GUID_ARRAY_SIZE 64
 #define INVALID_GUID (0xFFFFFFFFFFFFFFFFULL)
@@ -79,6 +80,45 @@ typedef struct _osm_main_args_t
 
 osm_main_args_t osm_main_args;
 
+enum service_state {
+  SERVICE_STATE_STARTING,
+  SERVICE_STATE_STARTED_OK,
+  SERVICE_STATE_START_FAILED
+};
+
+enum service_state g_service_state = SERVICE_STATE_STARTING;
+
+void OsmReportState(IN const char *p_str)
+{
+  if (!strcmp(p_str, "SUBNET UP\n") ||
+      (!strcmp(p_str, "SM port is down\n")) ||
+      (!strcmp(p_str, "Errors during initialization\n")) ||
+      (!strcmp(p_str, "Entering STANDBY state\n")))
+  {
+    InterlockedCompareExchange((LONG *)&g_service_state , SERVICE_STATE_STARTED_OK, SERVICE_STATE_STARTING);
+    return;
+  }
+
+  if (!strcmp(p_str, "Found remote SM with non-matching sm_key. Exiting\n") ||
+      (!strcmp(p_str, "Errors on subnet. Duplicate GUID found ""by link from a port to itself. ""See osm log for more details\n")) ||
+      (!strcmp(p_str, "Errors on subnet. SM found duplicated guids or 12x ""link with lane reversal badly configured. ""See osm log for more details\n")) ||
+      (!strcmp(p_str, "Fatal: Error restoring Guid-to-Lid persistent database\n")))
+
+  {
+    InterlockedCompareExchange((LONG *)&g_service_state , SERVICE_STATE_START_FAILED, SERVICE_STATE_STARTING);
+    return;
+  }
+
+  if(!strcmp(p_str, "OpenSM Rev:openib-1.2.0\n") || 
+     (!strcmp(p_str, "Entering MASTER state\n"))||
+     (!strcmp(p_str, "Exiting SM\n")))
+  {
+    // This are messages that it is safe to ignore
+    return;
+  }
+  CL_ASSERT(FALSE);
+
+}
 
 /**********************************************************************
  **********************************************************************/
@@ -244,7 +284,7 @@ show_usage(void)
   printf( "-?\n"
           "          Display this usage info then exit.\n\n" );
   fflush( stdout );
-  osm_exit_flag = 1;
+  osm_exit_flag = TRUE;
 }
 
 /**********************************************************************
@@ -498,6 +538,7 @@ opensm_main(
   uint32_t              val;
   const char * const    short_option = "i:f:ed:g:l:s:t:a:uvVhorcyx";
 
+
   /*
     In the array below, the 2nd parameter specified the number
     of arguments as follows:
@@ -532,7 +573,6 @@ opensm_main(
       {  "honor_guid2lid", 0, NULL, 'x'},
       {  NULL,            0, NULL,  0 }  /* Required at the end of the array */
     };
-
   printf("-------------------------------------------------\n");
   printf("%s\n", OSM_VERSION);
 
@@ -739,6 +779,7 @@ opensm_main(
     case '?':
     case ':':
       show_usage();
+      return 0;
       break;
 
     case -1:
@@ -749,9 +790,6 @@ opensm_main(
   }
   while(next_option != -1);
 
-  if (osm_exit_flag) {
-    return( 0 );
-  }
   if (opt.log_file != NULL )
     printf(" Log File: %s\n", opt.log_file );
   /* Done with options description */
@@ -823,21 +861,24 @@ opensm_main(
       goto Exit;
     }
 
-  if( run_once_flag == TRUE )
-  {
-    status = osm_opensm_wait_for_subnet_up(
+  status = osm_opensm_wait_for_subnet_up(
       &osm, EVENT_NO_TIMEOUT, TRUE );
-    osm_exit_flag = 1;
+
+  if( status != CL_SUCCESS )
+  {
+    printf( "\nError from osm_opensm_wait_for_subnet_up (0x%X)\n", status );
+    goto Exit;
   }
-  else
+
+  if( run_once_flag == FALSE )
   {
     /*
       Sit here forever
       In the future, some sort of console interactivity could
       be implemented in this loop.
     */
-    while( !osm_exit_flag )
-      cl_thread_suspend( 10000 );
+      WaitForSingleObject(osm_exit_event, INFINITE);
+      osm_exit_flag = TRUE;
   }
 
   /* wait for all transactions to end */
@@ -859,6 +900,7 @@ opensm_main(
             osm.mad_pool.mads_out);
 
  Exit:
+  g_service_state = SERVICE_STATE_START_FAILED;
   osm_opensm_destroy( &osm );
 
   if (mem_track) cl_mem_display();
@@ -876,7 +918,7 @@ __stdcall OsmServiceStart (DWORD argc, LPTSTR *argv);
 DWORD OsmServiceInitialization (DWORD argc, LPTSTR *argv, 
         DWORD *specificError); 
 
-void __cdecl
+int __cdecl
 main (
   int                   argc,
   char*                 argv[] )
@@ -893,10 +935,18 @@ main (
       run_as_service = TRUE;
       break;
     }
+    osm_exit_event = CreateEvent(NULL, FALSE, FALSE, NULL);
+    if(osm_exit_event == NULL)
+    {
+      printf( "\nCreateEvent failed gle=%d\n", GetLastError());
+      return( 1 );      
+    }
 
   if (!run_as_service)
+  {
     /* Running as executable */
-    opensm_main(&osm_main_args);
+    return opensm_main(&osm_main_args);
+  }
   else
   {
     /* Running as service */
@@ -905,7 +955,9 @@ main (
        { "OsmService", OsmServiceStart      }, 
        { NULL,              NULL          } 
      }; 
-     
+     // Give older versions of opensm a chance to stop
+     Sleep(3000); 
      if (!StartServiceCtrlDispatcher( DispatchTable)) 
      { 
        SvcDebugOut(" [OSM_SERVICE] StartServiceCtrlDispatcher (%d)\n", 
@@ -933,7 +985,8 @@ VOID WINAPI OsmServiceCtrlHandler (DWORD Opcode)
           case SERVICE_CONTROL_SHUTDOWN: 
           case SERVICE_CONTROL_STOP: 
       // Do whatever it takes to stop here. 
-        osm_exit_flag = TRUE;
+         osm_exit_flag = TRUE;
+         SetEvent(osm_exit_event);
          OsmServiceStatus.dwWin32ExitCode = 0; 
          OsmServiceStatus.dwCurrentState  = SERVICE_STOPPED; 
          OsmServiceStatus.dwCheckPoint    = 0; 
@@ -981,7 +1034,7 @@ __stdcall  OsmServiceStart (DWORD argc, LPTSTR *argv)
     OsmServiceStatus.dwWin32ExitCode      = 0; 
     OsmServiceStatus.dwServiceSpecificExitCode = 0; 
     OsmServiceStatus.dwCheckPoint         = 0; 
-    OsmServiceStatus.dwWaitHint           = 0; 
+    OsmServiceStatus.dwWaitHint           = 2000; 
 
     OsmServiceStatusHandle = RegisterServiceCtrlHandler( 
         "OsmService", 
@@ -992,12 +1045,26 @@ __stdcall  OsmServiceStart (DWORD argc, LPTSTR *argv)
         SvcDebugOut(" [OSM_SERVICE] RegisterServiceCtrlHandler failed %d\n", GetLastError()); 
         return 0; 
     } 
+
     // Initialization code goes here. 
     status = OsmServiceInitialization(argc,argv, &specificError); 
+    while (status == NO_ERROR && g_service_state == SERVICE_STATE_STARTING)
+    {
+        Sleep(1000);
+        OsmServiceStatus.dwCheckPoint++;
+        if (!SetServiceStatus (OsmServiceStatusHandle, &OsmServiceStatus)) 
+        { 
+          status = GetLastError(); 
+          SvcDebugOut(" [OSM_SERVICE] SetServiceStatus error %ld\n",status); 
+        } 
+
+    }
+    CL_ASSERT(g_service_state == SERVICE_STATE_STARTED_OK ||
+              g_service_state == SERVICE_STATE_START_FAILED ||
+              status != NO_ERROR);
  
     // Handle error condition 
-    if (status != NO_ERROR) 
+    if (status != NO_ERROR || g_service_state == SERVICE_STATE_START_FAILED
     { 
         OsmServiceStatus.dwCurrentState       = SERVICE_STOPPED; 
         OsmServiceStatus.dwCheckPoint         = 0; 
index b78caaac5fceaceefdcd4b6dad892bd424d33793..f1c8403e74682bf03c86460e1695c3a77e948a33 100644 (file)
@@ -218,7 +218,9 @@ show_menu(  )
        printf( "\n------- Interactive Menu -------\n" );
        printf( "X - Exit.\n\n" );
 }
-
+void OsmReportState(IN const char *p_str)
+{
+}
 
 /**********************************************************************
  **********************************************************************/