[openib-general] [PATCH] Opensm - enabling erase of log file flag

Yael Kalka yael at mellanox.co.il
Tue Oct 11 05:24:49 PDT 2005


Hi Hal,

Currently the osm log file is accumulative. I've added an option to
erase the log file before starting to write it.
By default, still, the log is still accumulative.
Attached is a patch for that.

Thanks,
Yael

Signed-off-by:  Yael Kalka <yael at mellanox.co.il>

Index: include/opensm/osm_subnet.h
===================================================================
--- include/opensm/osm_subnet.h	(revision 3704)
+++ include/opensm/osm_subnet.h	(working copy)
@@ -220,6 +220,7 @@ typedef struct _osm_subn_opt
   uint8_t                  log_flags;
   char *                   dump_files_dir;
   char *                   log_file;
+  boolean_t                accum_log_file;
   cl_map_t                 port_pro_ignore_guids;
   boolean_t                port_profile_switch_nodes;
   uint32_t                 max_port_profile;
@@ -319,6 +320,10 @@ typedef struct _osm_subn_opt
 *  log_file
 *     Name of the log file (or NULL) for stdout.
 *
+*  accum_log_file
+*     If TRUE (default) - the log file will be accumulated.
+*     If FALSE - the log file will be erased before starting current opensm run.
+*
 *  port_pro_ignore_guids
 *     A map of guids to be ignored by port profiling.
 *
Index: include/opensm/osm_log.h
===================================================================
--- include/opensm/osm_log.h	(revision 3704)
+++ include/opensm/osm_log.h	(working copy)
@@ -218,7 +218,8 @@ osm_log_init(
   IN osm_log_t* const p_log,
   IN const boolean_t flush,
   IN const uint8_t log_flags,
-  IN const char *log_file)
+  IN const char *log_file,
+  IN const boolean_t accum_log_file )
 {
   p_log->level = log_flags;
   p_log->flush = flush;
@@ -229,10 +230,18 @@ osm_log_init(
   }
   else
   {
+    if (accum_log_file)
     p_log->out_port = fopen(log_file,"a+");
+    else
+      p_log->out_port = fopen(log_file,"w+");
+    
     if (!p_log->out_port)
     {
+      if (accum_log_file)
       printf("Cannot open %s for appending. Permission denied\n", log_file);
+      else
+        printf("Cannot open %s for writing. Permission denied\n", log_file);
+
       return(IB_UNKNOWN_ERROR);
     }
   }
Index: complib/cl_event_wheel.c
===================================================================
--- complib/cl_event_wheel.c	(revision 3704)
+++ complib/cl_event_wheel.c	(working copy)
@@ -597,7 +597,7 @@ main ()
   cl_event_wheel_construct( &event_wheel );
 
   /* init */
-  osm_log_init( &log, TRUE, 0xff, NULL);
+  osm_log_init( &log, TRUE, 0xff, NULL, FALSE);
   cl_event_wheel_init( &event_wheel, &log );
 
   /* Start Playing */
Index: osmtest/osmtest.c
===================================================================
--- osmtest/osmtest.c	(revision 3704)
+++ osmtest/osmtest.c	(working copy)
@@ -507,7 +507,7 @@ osmtest_init( IN osmtest_t * const p_osm
   osmtest_construct( p_osmt );
 
   status = osm_log_init( &p_osmt->log, p_opt->force_log_flush,
-                         0x0001, p_opt->log_file );
+                         0x0001, p_opt->log_file, TRUE );
   if( status != IB_SUCCESS )
     return ( status );
   /* but we do not want any extra staff here */
Index: opensm/osm_subnet.c
===================================================================
--- opensm/osm_subnet.c	(revision 3704)
+++ opensm/osm_subnet.c	(working copy)
@@ -427,6 +427,7 @@ osm_subn_set_default_opt(
     p_opt->dump_files_dir = OSM_DEFAULT_TMP_DIR;
 
   p_opt->log_file = OSM_DEFAULT_LOG_FILE;
+  p_opt->accum_log_file = TRUE;
   p_opt->port_profile_switch_nodes = FALSE;
   p_opt->max_port_profile = 0xffffffff;
   p_opt->pfn_ui_pre_lid_assign = NULL;
@@ -754,6 +755,10 @@ osm_subn_parse_conf_file(
       __osm_subn_opts_unpack_charp(
         "log_file" , p_key, p_val, &p_opts->log_file);
 
+      __osm_subn_opts_unpack_boolean(
+        "accum_log_file",
+        p_key, p_val, &p_opts->accum_log_file);
+
       __osm_subn_opts_unpack_charp(
         "dump_files_dir" ,
         p_key, p_val, &p_opts->dump_files_dir);
@@ -920,6 +925,7 @@ osm_subn_write_conf_file(
     "force_log_flush %s\n\n"
     "# Log file to be used\n"
     "log_file %s\n\n" 
+    "accum_log_file %s\n\n"
     "# The directory to hold the file OpenSM dumps\n"
     "dump_files_dir %s\n\n"
     "# If TRUE if OpenSM should disable multicast support\n"
@@ -929,6 +935,7 @@ osm_subn_write_conf_file(
     p_opts->log_flags,
     p_opts->force_log_flush ? "TRUE" : "FALSE",
     p_opts->log_file,
+    p_opts->accum_log_file,
     p_opts->dump_files_dir,
     p_opts->no_multicast_option ? "TRUE" : "FALSE",
     p_opts->disable_multicast ? "TRUE" : "FALSE"
Index: opensm/osm_db_files.c
===================================================================
--- opensm/osm_db_files.c	(revision 3704)
+++ opensm/osm_db_files.c	(working copy)
@@ -673,7 +673,7 @@ main(int argc, char **argv)
   cl_list_construct( &keys );
   cl_list_init( &keys, 10 );
 
-  osm_log_init( &log, TRUE, 0xff, "/tmp/test_osm_db.log");
+  osm_log_init( &log, TRUE, 0xff, "/tmp/test_osm_db.log", FALSE);
 
   osm_db_construct(&db);
   if (osm_db_init(&db, &log))
Index: opensm/osm_opensm.c
===================================================================
--- opensm/osm_opensm.c	(revision 3704)
+++ opensm/osm_opensm.c	(working copy)
@@ -205,7 +205,7 @@ osm_opensm_init(
    osm_opensm_construct( p_osm );
 
    status = osm_log_init( &p_osm->log, p_opt->force_log_flush,
-                          p_opt->log_flags, p_opt->log_file );
+                          p_opt->log_flags, p_opt->log_file, p_opt->accum_log_file );
    if( status != IB_SUCCESS )
       return ( status );
 
Index: opensm/main.c
===================================================================
--- opensm/main.c	(revision 3704)
+++ opensm/main.c	(working copy)
@@ -167,6 +167,11 @@ show_usage(void)
           "          This option defines the log to be the given file.\n"
           "          By default the log goes to /var/log/osm.log.\n"
           "          For the log to go to standard output use -f stdout.\n\n");
+  printf( "-e\n"
+          "--erase_log_file\n"
+          "          This option will cause deletion of the log file \n"
+          "          (if it previously exists). By default, the log file \n"
+          "          is accumulative.\n\n");
   printf( "-v\n"
           "--verbose\n"
           "          This option increases the log verbosity level.\n"
@@ -447,7 +452,7 @@ main(
   boolean_t             cache_options = FALSE;
   char                 *ignore_guids_file_name = NULL;
   uint32_t              val;
-  const char * const    short_option = "i:f:d:g:l:s:t:vVhorc";
+  const char * const    short_option = "i:f:ed:g:l:s:t:vVhorc";
 
   /*
     In the array below, the 2nd parameter specified the number
@@ -467,6 +472,7 @@ main(
       {  "verbose",       0, NULL, 'v'},
       {  "D",             1, NULL, 'D'},
       {  "log_file",      1, NULL, 'f'},
+      {  "erase_log_file",0, NULL, 'e'},
       {  "maxsmps",       1, NULL, 'n'},
       {  "V",             0, NULL, 'V'},
       {  "help",          0, NULL, 'h'},
@@ -636,6 +642,11 @@ main(
         opt.log_file = optarg;
       break;
 
+    case 'e':
+      opt.accum_log_file = FALSE;
+      printf(" Creating new log file\n");
+      break;
+
     case 'v':
       log_flags = (log_flags <<1 )|1;
       printf(" Verbose option -v (log flags = 0x%X)\n", log_flags );




More information about the general mailing list