From 28cf985a74fd2161b1f64d9939f1d114b3453d02 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Thu, 17 Mar 2011 22:30:45 +0000
Subject: [PATCH] BLUEGENE - Added debug flags for compiling C++ code and also
 added logging to another file for the bridge

---
 auxdir/x_ac_bluegene.m4                       |  29 ++-
 auxdir/x_ac_debug.m4                          |   1 +
 configure                                     |  64 ++++---
 .../select/bluegene/ba_bgq/block_allocator.c  |   5 +
 src/plugins/select/bluegene/bg_read_config.c  |   2 -
 .../select/bluegene/bl_bgq/bridge_helper.cc   |   4 +-
 .../select/bluegene/bl_bgq/bridge_helper.h    |   1 +
 .../select/bluegene/bl_bgq/bridge_linker.cc   | 176 +++++++++++++-----
 .../select/bluegene/bl_bgq/bridge_status.cc   |   8 -
 src/plugins/select/bluegene/bridge_linker.h   |   2 +-
 10 files changed, 202 insertions(+), 90 deletions(-)

diff --git a/auxdir/x_ac_bluegene.m4 b/auxdir/x_ac_bluegene.m4
index a9306d16e47..d5fae34fe36 100644
--- a/auxdir/x_ac_bluegene.m4
+++ b/auxdir/x_ac_bluegene.m4
@@ -223,10 +223,11 @@ AC_DEFUN([X_AC_BGQ],
 		ac_bluegene_loaded=yes
 		ac_bgq_loaded=yes
 	else
-		bg_default_dirs="/bgsys/drivers/ppcfloor/hlcs"
+		bg_default_dirs="/bgsys/drivers/ppcfloor"
 	fi
 
 	libname=bgsched
+	loglibname=log4cxx
 
    	for bg_dir in $trydb2dir "" $bg_default_dirs; do
       	# Skip directories that don't exist
@@ -234,18 +235,28 @@ AC_DEFUN([X_AC_BGQ],
 			continue;
       		fi
 
-		soloc=$bg_dir/lib/lib$libname.so
+		soloc=$bg_dir/hlcs/lib/lib$libname.so
       		# Search for required BG API libraries in the directory
       		if test -z "$have_bg_ar" -a -f "$soloc" ; then
 			have_bgq_ar=yes
-			bg_ldflags="$bg_ldflags -Wl,-rpath -Wl,$bg_dir/lib -L$bg_dir/lib -l$libname"
+			bg_ldflags="$bg_ldflags -Wl,-rpath -Wl,$bg_dir/hlcs/lib -L$bg_dir/hlcs/lib -l$libname"
+		fi
+
+  		soloc=$bg_dir/extlib/lib/lib$loglibname.so
+    		if test -z "$have_bg_ar" -a -f "$soloc" ; then
+			have_bgq_ar=yes
+			bg_ldflags="$bg_ldflags -Wl,-rpath -Wl,$bg_dir/extlib/lib -L$bg_dir/extlib/lib -l$loglibname"
 		fi
 
       		# Search for headers in the directory
-      		if test -z "$have_bg_hdr" -a -f "$bg_dir/include/bgsched/bgsched.h" ; then
+      		if test -z "$have_bg_hdr" -a -f "$bg_dir/hlcs/include/bgsched/bgsched.h" ; then
 			have_bgq_hdr=yes
-			bg_includes="-I$bg_dir/include"
+			bg_includes="-I$bg_dir/hlcs/include"
       		fi
+     		if test -z "$have_bg_hdr" -a -f "$bg_dir/extlib/include/log4cxx/logger.h" ; then
+			have_bgq_hdr=yes
+			bg_includes="$bg_includes -I$bg_dir/extlib/include"
+    		fi
    	done
 
    	if test ! -z "$have_bgq_ar" -a ! -z "$have_bgq_hdr" ; then
@@ -254,7 +265,13 @@ AC_DEFUN([X_AC_BGQ],
 		saved_LDFLAGS="$LDFLAGS"
       	 	LDFLAGS="$saved_LDFLAGS $bg_ldflags -m64 $bg_includes"
 		AC_LANG_PUSH(C++)
-		AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <bgsched/bgsched.h>]], [[ bgsched::init(""); ]])],[have_bgq_files=yes],[AC_MSG_ERROR(There is a problem linking to the BG/Q api.)])
+		AC_LINK_IFELSE([AC_LANG_PROGRAM(
+                                [[#include <bgsched/bgsched.h>
+#include <log4cxx/logger.h>]],
+				[[ bgsched::init("");
+ log4cxx::LoggerPtr logger_ptr(log4cxx::Logger::getLogger( "ibm" ));]])],
+			        [have_bgq_files=yes],
+				[AC_MSG_ERROR(There is a problem linking to the BG/Q api.)])
 		AC_LANG_POP(C++)
 		LDFLAGS="$saved_LDFLAGS"
    	fi
diff --git a/auxdir/x_ac_debug.m4 b/auxdir/x_ac_debug.m4
index 077bd2eed93..27345408943 100644
--- a/auxdir/x_ac_debug.m4
+++ b/auxdir/x_ac_debug.m4
@@ -33,6 +33,7 @@ AC_DEFUN([X_AC_DEBUG], [
   )
   if test "$x_ac_debug" = yes; then
     test "$GCC" = yes && CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
+    test "$GXX" = yes && CXXFLAGS="$CXXFLAGS -Wall -fno-strict-aliasing"
   else
     AC_DEFINE([NDEBUG], [1],
       [Define to 1 if you are building a production release.]
diff --git a/configure b/configure
index 32276884c7a..f12621cbbeb 100755
--- a/configure
+++ b/configure
@@ -5236,10 +5236,11 @@ $as_echo "$as_me: Running in BG/Q emulation mode" >&6;}
 		ac_bluegene_loaded=yes
 		ac_bgq_loaded=yes
 	else
-		bg_default_dirs="/bgsys/drivers/ppcfloor/hlcs"
+		bg_default_dirs="/bgsys/drivers/ppcfloor"
 	fi
 
 	libname=bgsched
+	loglibname=log4cxx
 
    	for bg_dir in $trydb2dir "" $bg_default_dirs; do
       	# Skip directories that don't exist
@@ -5247,18 +5248,28 @@ $as_echo "$as_me: Running in BG/Q emulation mode" >&6;}
 			continue;
       		fi
 
-		soloc=$bg_dir/lib/lib$libname.so
+		soloc=$bg_dir/hlcs/lib/lib$libname.so
       		# Search for required BG API libraries in the directory
       		if test -z "$have_bg_ar" -a -f "$soloc" ; then
 			have_bgq_ar=yes
-			bg_ldflags="$bg_ldflags -Wl,-rpath -Wl,$bg_dir/lib -L$bg_dir/lib -l$libname"
+			bg_ldflags="$bg_ldflags -Wl,-rpath -Wl,$bg_dir/hlcs/lib -L$bg_dir/hlcs/lib -l$libname"
+		fi
+
+  		soloc=$bg_dir/extlib/lib/lib$loglibname.so
+    		if test -z "$have_bg_ar" -a -f "$soloc" ; then
+			have_bgq_ar=yes
+			bg_ldflags="$bg_ldflags -Wl,-rpath -Wl,$bg_dir/extlib/lib -L$bg_dir/extlib/lib -l$loglibname"
 		fi
 
       		# Search for headers in the directory
-      		if test -z "$have_bg_hdr" -a -f "$bg_dir/include/bgsched/bgsched.h" ; then
+      		if test -z "$have_bg_hdr" -a -f "$bg_dir/hlcs/include/bgsched/bgsched.h" ; then
 			have_bgq_hdr=yes
-			bg_includes="-I$bg_dir/include"
+			bg_includes="-I$bg_dir/hlcs/include"
       		fi
+     		if test -z "$have_bg_hdr" -a -f "$bg_dir/extlib/include/log4cxx/logger.h" ; then
+			have_bgq_hdr=yes
+			bg_includes="$bg_includes -I$bg_dir/extlib/include"
+    		fi
    	done
 
    	if test ! -z "$have_bgq_ar" -a ! -z "$have_bgq_hdr" ; then
@@ -5275,10 +5286,12 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <bgsched/bgsched.h>
+#include <log4cxx/logger.h>
 int
 main ()
 {
  bgsched::init("");
+ log4cxx::LoggerPtr logger_ptr(log4cxx::Logger::getLogger( "ibm" ));
   ;
   return 0;
 }
@@ -7646,13 +7659,13 @@ if test "${lt_cv_nm_interface+set}" = set; then :
 else
   lt_cv_nm_interface="BSD nm"
   echo "int some_variable = 0;" > conftest.$ac_ext
-  (eval echo "\"\$as_me:7649: $ac_compile\"" >&5)
+  (eval echo "\"\$as_me:7662: $ac_compile\"" >&5)
   (eval "$ac_compile" 2>conftest.err)
   cat conftest.err >&5
-  (eval echo "\"\$as_me:7652: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+  (eval echo "\"\$as_me:7665: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
   (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
   cat conftest.err >&5
-  (eval echo "\"\$as_me:7655: output\"" >&5)
+  (eval echo "\"\$as_me:7668: output\"" >&5)
   cat conftest.out >&5
   if $GREP 'External.*some_variable' conftest.out > /dev/null; then
     lt_cv_nm_interface="MS dumpbin"
@@ -8857,7 +8870,7 @@ ia64-*-hpux*)
   ;;
 *-*-irix6*)
   # Find out which ABI we are using.
-  echo '#line 8860 "configure"' > conftest.$ac_ext
+  echo '#line 8873 "configure"' > conftest.$ac_ext
   if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
@@ -10645,11 +10658,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:10648: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:10661: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:10652: \$? = $ac_status" >&5
+   echo "$as_me:10665: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -10984,11 +10997,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:10987: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:11000: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:10991: \$? = $ac_status" >&5
+   echo "$as_me:11004: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -11089,11 +11102,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:11092: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:11105: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:11096: \$? = $ac_status" >&5
+   echo "$as_me:11109: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -11144,11 +11157,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:11147: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:11160: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:11151: \$? = $ac_status" >&5
+   echo "$as_me:11164: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -13528,7 +13541,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 13531 "configure"
+#line 13544 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13624,7 +13637,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 13627 "configure"
+#line 13640 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15580,11 +15593,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:15583: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:15596: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:15587: \$? = $ac_status" >&5
+   echo "$as_me:15600: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -15679,11 +15692,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:15682: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:15695: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:15686: \$? = $ac_status" >&5
+   echo "$as_me:15699: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -15731,11 +15744,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:15734: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:15747: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:15738: \$? = $ac_status" >&5
+   echo "$as_me:15751: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -19891,6 +19904,7 @@ fi
 
   if test "$x_ac_debug" = yes; then
     test "$GCC" = yes && CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
+    test "$GXX" = yes && CXXFLAGS="$CXXFLAGS -Wall -fno-strict-aliasing"
   else
 
 $as_echo "#define NDEBUG 1" >>confdefs.h
diff --git a/src/plugins/select/bluegene/ba_bgq/block_allocator.c b/src/plugins/select/bluegene/ba_bgq/block_allocator.c
index b1311e4eeae..dbe963d2ec9 100644
--- a/src/plugins/select/bluegene/ba_bgq/block_allocator.c
+++ b/src/plugins/select/bluegene/ba_bgq/block_allocator.c
@@ -1060,6 +1060,9 @@ static int _finish_torus(List results, int level, uint16_t *block_start,
 	}
 	start_mp = curr_mp;
 
+	/* info("_finish_torus: starting with %s", */
+	/*      curr_mp->coord_str); */
+
 	for (dim=0; dim<cluster_dims; dim++) {
 		if (conn_type[dim] != SELECT_TORUS)
 			continue;
@@ -1111,6 +1114,8 @@ static int _finish_torus(List results, int level, uint16_t *block_start,
 					     curr_mp->alter_switch[dim].usage));
 			curr_mp = curr_mp->next_mp[dim];
 		}
+		/* info("_finish_torus: ended with %s(%d)", */
+		/*      curr_mp->coord_str, dim); */
 	}
 
 	return 1;
diff --git a/src/plugins/select/bluegene/bg_read_config.c b/src/plugins/select/bluegene/bg_read_config.c
index b9f11b05ddf..1b1e4984bde 100644
--- a/src/plugins/select/bluegene/bg_read_config.c
+++ b/src/plugins/select/bluegene/bg_read_config.c
@@ -79,7 +79,6 @@ static int _reopen_bridge_log(void)
 {
 	int rc = SLURM_SUCCESS;
 
-#if defined HAVE_BG_L_P
 	if (bg_conf->bridge_api_file == NULL)
 		return rc;
 
@@ -90,7 +89,6 @@ static int _reopen_bridge_log(void)
 	if (bg_conf->slurm_debug_flags & DEBUG_FLAG_SELECT_TYPE)
 		info("Bridge api file set to %s, verbose level %d",
 		     bg_conf->bridge_api_file, bg_conf->bridge_api_verb);
-#endif
 	return rc;
 }
 
diff --git a/src/plugins/select/bluegene/bl_bgq/bridge_helper.cc b/src/plugins/select/bluegene/bl_bgq/bridge_helper.cc
index 97ffec63b38..e61ac8cc715 100644
--- a/src/plugins/select/bluegene/bl_bgq/bridge_helper.cc
+++ b/src/plugins/select/bluegene/bl_bgq/bridge_helper.cc
@@ -233,8 +233,8 @@ extern int bridge_handle_runtime_errors(const char *function,
 	case bgsched::RuntimeErrors::InvalidBlockState:
 		/* not a real error */
 		rc = BG_ERROR_INVALID_STATE;
-		error("%s: Error can't perform task with block %s in state %s"
-		      "incorrect %s.", function, bg_record->bg_block_id,
+		error("%s: Error can't perform task with block %s in state %s",
+		      function, bg_record->bg_block_id,
 		      bg_block_state_string(bg_record->state));
 		break;
 	case bgsched::RuntimeErrors::DimensionOutOfRange:
diff --git a/src/plugins/select/bluegene/bl_bgq/bridge_helper.h b/src/plugins/select/bluegene/bl_bgq/bridge_helper.h
index af59dc60c38..8dcd10962f6 100644
--- a/src/plugins/select/bluegene/bl_bgq/bridge_helper.h
+++ b/src/plugins/select/bluegene/bl_bgq/bridge_helper.h
@@ -55,6 +55,7 @@ extern "C" {
 #include <bgsched/bgsched.h>
 #include <bgsched/Block.h>
 #include <bgsched/core/core.h>
+
 #include <boost/foreach.hpp>
 
 using namespace std;
diff --git a/src/plugins/select/bluegene/bl_bgq/bridge_linker.cc b/src/plugins/select/bluegene/bl_bgq/bridge_linker.cc
index 5dce92cd491..4ac076aa19c 100644
--- a/src/plugins/select/bluegene/bl_bgq/bridge_linker.cc
+++ b/src/plugins/select/bluegene/bl_bgq/bridge_linker.cc
@@ -36,6 +36,23 @@
  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
 \*****************************************************************************/
 
+#if HAVE_CONFIG_H
+/* needed to figure out if HAVE_BG_FILES is set */
+#  include "config.h"
+#endif
+
+#ifdef HAVE_BG_FILES
+/* These need to be the first declared since on line 187 of
+ * /bgsys/drivers/ppcfloor/extlib/include/log4cxx/helpers/transcoder.h
+ * there is a nice generic BUFSIZE declared and the BUFSIZE declared
+ * elsewhere in SLURM will cause errors when compiling.
+ */
+#include <log4cxx/fileappender.h>
+#include <log4cxx/logger.h>
+#include <log4cxx/patternlayout.h>
+
+#endif
+
 extern "C" {
 #include "../ba_bgq/block_allocator.h"
 #include "../bg_record_functions.h"
@@ -178,6 +195,8 @@ extern int bridge_init(char *properties_file)
 		return 0;
 
 #ifdef HAVE_BG_FILES
+	if (!properties_file)
+		properties_file = (char *)"";
 	bgsched::init(properties_file);
 #endif
 	bridge_status_init();
@@ -200,8 +219,6 @@ extern int bridge_get_size(int *size)
 #ifdef HAVE_BG_FILES
         Midplane::Coordinates bgq_size;
 	Dimension dim;
-#else
-	int dim;
 #endif
 	if (!bridge_init(NULL))
 		return SLURM_ERROR;
@@ -243,7 +260,6 @@ extern int bridge_setup_system()
 
 extern int bridge_block_create(bg_record_t *bg_record)
 {
-	ListIterator itr = NULL;
 	int rc = SLURM_SUCCESS;
 
 #ifdef HAVE_BG_FILES
@@ -333,14 +349,14 @@ extern int bridge_block_create(bg_record_t *bg_record)
 				return rc;
 		}
 	} else {
-		itr = list_iterator_create(bg_record->ba_mp_list);
+		ListIterator itr = list_iterator_create(bg_record->ba_mp_list);
 		while ((ba_mp = (ba_mp_t *)list_next(itr))) {
 			/* Since the midplane locations aren't set up in the
 			   copy of this pointer we need to go out a get the
 			   real one from the system and use it.
 			*/
 			ba_mp_t *main_mp = coord2ba_mp(ba_mp->coord);
-			//info("got %s(%s) %d", main_mp->coord_str, main_mp->loc, ba_mp->used);
+			info("got %s(%s) %d", main_mp->coord_str, main_mp->loc, ba_mp->used);
 			if (ba_mp->used)
 				midplanes.push_back(main_mp->loc);
 			else
@@ -367,8 +383,10 @@ extern int bridge_block_create(bg_record_t *bg_record)
 				"Block::create",
 				err.getError().toValue(),
 				bg_record);
-			if (rc != SLURM_SUCCESS)
+			if (rc != SLURM_SUCCESS) {
+				assert(0);
 				return rc;
+			}
 		}
 	}
 
@@ -456,7 +474,7 @@ extern int bridge_block_boot(bg_record_t *bg_record)
 		if (!Block::isIOConnected(bg_record->bg_block_id, &mp_vec)) {
 			error("block %s is not IOConnected, "
 			      "contact your admin. Midplanes not "
-			      "connected are ...");
+			      "connected are ...", bg_record->bg_block_id);
 			BOOST_FOREACH(const std::string& mp, mp_vec) {
 				error("%s", mp.c_str());
 			}
@@ -769,16 +787,22 @@ extern int bridge_blocks_load_curr(List curr_block_list)
 		bg_record->state = bridge_translate_status(
 			block_ptr->getStatus().toValue());
 
-		if (bg_record->state == BG_BLOCK_BOOTING)
-			bg_record->boot_state = 1;
-
 		debug3("Block %s is in state %d",
 		       bg_record->bg_block_id,
 		       bg_record->state);
 
+		bg_record->job_running = NO_JOB_RUNNING;
+		/* we are just going to go and destroy this block so
+		   just throw get the name and continue. */
+		if (!bg_recover)
+			continue;
+
+		if (bg_record->state == BG_BLOCK_BOOTING)
+			bg_record->boot_state = 1;
+
 		bg_record->node_cnt = block_ptr->getComputeNodeCount();
 		bg_record->cpu_cnt = bg_conf->cpu_ratio * bg_record->node_cnt;
-		bg_record->job_running = NO_JOB_RUNNING;
+
 		if (block_ptr->isSmall()) {
 			char bitstring[BITSIZE];
 			int io_cnt, io_start, len;
@@ -934,40 +958,100 @@ extern void bridge_block_post_job(char *bg_block_id)
 	_remove_jobs_on_block_and_reset(bg_block_id);
 }
 
-// extern int bridge_set_log_params(char *api_file_name, unsigned int level)
-// {
-// 	static FILE *fp = NULL;
-//         FILE *fp2 = NULL;
-// 	int rc = SLURM_SUCCESS;
-
-// 	if (!bridge_init())
-// 		return SLURM_ERROR;
-
-// 	slurm_mutex_lock(&api_file_mutex);
-// 	if (fp)
-// 		fp2 = fp;
-
-// 	fp = fopen(api_file_name, "a");
-
-// 	if (fp == NULL) {
-// 		error("can't open file for bridgeapi.log at %s: %m",
-// 		      api_file_name);
-// 		rc = SLURM_ERROR;
-// 		goto end_it;
-// 	}
-
-
-// 	(*(bridge_api.set_log_params))(fp, level);
-// 	/* In the libraries linked to from the bridge there are stderr
-// 	   messages send which we would miss unless we dup this to the
-// 	   log */
-// 	//(void)dup2(fileno(fp), STDERR_FILENO);
-
-// 	if (fp2)
-// 		fclose(fp2);
-// end_it:
-// 	slurm_mutex_unlock(&api_file_mutex);
-//  	return rc;
-// }
+extern int bridge_set_log_params(char *api_file_name, unsigned int level)
+{
+	if (!bridge_init(NULL))
+		return SLURM_ERROR;
+
+	if (!bg_conf->bridge_api_file)
+		return SLURM_SUCCESS;
+
+#ifdef HAVE_BG_FILES
+	// Scheduler APIs use the loggers under ibm.
+	log4cxx::LoggerPtr logger_ptr(log4cxx::Logger::getLogger("ibm"));
+	// Set the pattern for output.
+	log4cxx::LayoutPtr layout_ptr(
+		new log4cxx::PatternLayout(
+			"[%d{yyyy-MM-ddTHH:mm:ss}] %p: %c: %m [%t]%n"));
+	// Set the log file
+	log4cxx::AppenderPtr appender_ptr(
+		new log4cxx::FileAppender(layout_ptr,
+					  bg_conf->bridge_api_file));
+	log4cxx::LevelPtr level_ptr;
+
+	// Get rid of the console appender.
+	logger_ptr->removeAllAppenders();
+
+	switch (level) {
+	case 0:
+		level_ptr = log4cxx::Level::getOff();
+		break;
+	case 1:
+		level_ptr = log4cxx::Level::getFatal();
+		break;
+	case 2:
+		level_ptr = log4cxx::Level::getError();
+		break;
+	case 3:
+		level_ptr = log4cxx::Level::getWarn();
+		break;
+	case 4:
+		level_ptr = log4cxx::Level::getInfo();
+		break;
+	case 5:
+		level_ptr = log4cxx::Level::getDebug();
+		break;
+	case 6:
+		level_ptr = log4cxx::Level::getTrace();
+		break;
+	case 7:
+		level_ptr = log4cxx::Level::getAll();
+		break;
+	default:
+		level_ptr = log4cxx::Level::getDebug();
+		break;
+	}
+	// Now set the level of debug
+	logger_ptr->setLevel(level_ptr);
+	// Add the appender to the ibm logger.
+	logger_ptr->addAppender(appender_ptr);
+
+	// for (int i=1; i<7; i++) {
+	// switch (i) {
+	// case 0:
+	// 	level_ptr = log4cxx::Level::getOff();
+	// 	break;
+	// case 1:
+	// 	level_ptr = log4cxx::Level::getFatal();
+	// 	break;
+	// case 2:
+	// 	level_ptr = log4cxx::Level::getError();
+	// 	break;
+	// case 3:
+	// 	level_ptr = log4cxx::Level::getWarn();
+	// 	break;
+	// case 4:
+	// 	level_ptr = log4cxx::Level::getInfo();
+	// 	break;
+	// case 5:
+	// 	level_ptr = log4cxx::Level::getDebug();
+	// 	break;
+	// case 6:
+	// 	level_ptr = log4cxx::Level::getTrace();
+	// 	break;
+	// case 7:
+	// 	level_ptr = log4cxx::Level::getAll();
+	// 	break;
+	// default:
+	// 	level_ptr = log4cxx::Level::getDebug();
+	// 	break;
+	// }
+	// if (logger_ptr->isEnabledFor(level_ptr))
+	// 	info("we are doing %d", i);
+	// }
+
+#endif
+	return SLURM_SUCCESS;
+}
 
 
diff --git a/src/plugins/select/bluegene/bl_bgq/bridge_status.cc b/src/plugins/select/bluegene/bl_bgq/bridge_status.cc
index d9cfadce96d..4401534d0ed 100644
--- a/src/plugins/select/bluegene/bl_bgq/bridge_status.cc
+++ b/src/plugins/select/bluegene/bl_bgq/bridge_status.cc
@@ -225,8 +225,6 @@ void event_handler::handleMidplaneStateChangedRealtimeEvent(
 void event_handler::handleSwitchStateChangedRealtimeEvent(
 	const SwitchStateChangedEventInfo& event)
 {
-	char bg_down_node[128];
-
 	const char *midplane = event.getMidplaneId().c_str();
 	ba_mp_t *ba_mp = loc2ba_mp(midplane);
 
@@ -257,12 +255,9 @@ void event_handler::handleSwitchStateChangedRealtimeEvent(
 void event_handler::handleNodeBoardStateChangedRealtimeEvent(
 	const NodeBoardStateChangedEventInfo& event)
 {
-	int rc = SLURM_ERROR;
-
 	const char *mp_name = event.getMidplaneId().c_str();
 	const char *nb_name = event.getNodeBoardId().c_str();
 	ba_mp_t *ba_mp = loc2ba_mp(mp_name);
-	int io_start = 0;
 
 	if (!ba_mp) {
 		error("Nodeboard '%s' on Midplane %s, state went from %d to %d,"
@@ -442,9 +437,6 @@ static void _handle_midplane_update(ComputeHardware::ConstPtr bgq,
 static void _do_hardware_poll(void)
 {
 #if defined HAVE_BG_FILES
-	ListIterator itr;
-	int updated = 0;
-
 	if (!ba_main_grid)
 		return;
 
diff --git a/src/plugins/select/bluegene/bridge_linker.h b/src/plugins/select/bluegene/bridge_linker.h
index d64f3b5980f..53bdb46918c 100644
--- a/src/plugins/select/bluegene/bridge_linker.h
+++ b/src/plugins/select/bluegene/bridge_linker.h
@@ -108,13 +108,13 @@ extern int bridge_blocks_load_curr(List curr_block_list);
 
 extern void bridge_reset_block_list(List block_list);
 extern void bridge_block_post_job(char *bg_block_id);
+extern int bridge_set_log_params(char *api_file_name, unsigned int level);
 
 #if defined HAVE_BG_FILES && defined HAVE_BG_L_P
 extern bool have_db2;
 
 extern status_t bridge_get_bg(my_bluegene_t **bg);
 extern status_t bridge_free_bg(my_bluegene_t *bg);
-extern int bridge_set_log_params(char *api_file_name, unsigned int level);
 extern status_t bridge_get_data(rm_element_t* element,
 				enum rm_specification field, void *data);
 extern status_t bridge_set_data(rm_element_t* element,
-- 
GitLab