Enable protocol switch between ipmi and redfish for hwmon

1) Switch bmc protocol between ipmi and redfish for hwmon.
2) Get power status provided by mtc through below file
   /var/run/bmc/<hostname>

Story: 2005861
Task: 35815

Change-Id: Ie577f7f9265b7cdb5c985dcc0861a90e74508026
Signed-off-by: zhipengl <zhipengs.liu@intel.com>
This commit is contained in:
zhipengl 2019-08-29 00:19:25 +08:00 committed by Eric MacDonald
parent edb65ce1e4
commit 2fd91856d0
9 changed files with 349 additions and 140 deletions

View File

@ -17,7 +17,7 @@ using namespace std;
#include "nodeBase.h" /* for ... mtce-common node definitions */
#include "hostUtil.h" /* for ... mtce-common host definitions */
#include "bmcUtil.h" /* for ... mtce-common bmc utility header */
#include "jsonUtil.h" /* for ... json_tokener_parse */
/**********************************************************************
*
@ -93,6 +93,31 @@ string bmcUtil_getProtocol_str ( bmc_protocol_enum protocol )
}
}
/**********************************************************************
*
* Name : bmcUtil_chop_system_req
*
* Purpose : logging ; reduce the length of the system call
* request for logging purposes.
*
* Warning : Do not use the chopped string to make the system
* call request. Only use it for logging.
*
* Description: return the chopped string.
*
**********************************************************************/
string bmcUtil_chop_system_req ( string request )
{
string chopped_request = "" ;
size_t found = request.find(" > ") ;
if ( found != string::npos )
chopped_request = request.substr(9,found-9);
else
chopped_request = request.substr(9);
return (chopped_request);
}
/*************************************************************************
*
* Name : bmcUtil_init
@ -109,6 +134,7 @@ string bmcUtil_getProtocol_str ( bmc_protocol_enum protocol )
int bmcUtil_init ( void )
{
daemon_make_dir(BMC_OUTPUT_DIR) ;
daemon_make_dir(BMC_HWMON_TMP_DIR) ;
ipmiUtil_init ();
redfishUtil_init ();
@ -223,6 +249,97 @@ void bmcUtil_hwmon_info ( string hostname,
daemon_log ( bmc_info_path_n_filename.data(), info_str.data() );
}
/*****************************************************************************
*
* Name : bmcUtil_read_bmc_info
* Description : Read power status and protocol from bmc info file
* Parameters : hostname - host name
power_state - read from file
protocol - read from file
* Return : true - file exist
false - file not exist
*
*****************************************************************************/
bool bmcUtil_read_bmc_info( string hostname,
string & power_state,
bmc_protocol_enum & protocol )
{
struct json_object *json_obj = NULL;
string bmc_info_path_n_filename = BMC_OUTPUT_DIR + hostname ;
if ( ! daemon_is_file_present ( bmc_info_path_n_filename.data() ))
return (false);
string filedata = daemon_read_file (bmc_info_path_n_filename.data()) ;
blog ("%s data:%s\n", hostname.c_str(), filedata.data());
json_obj = json_tokener_parse ( (char *)filedata.data() );
if ( json_obj )
{
power_state = jsonUtil_get_key_value_string ( json_obj, "power_state" );
if ( strcmp (power_state.data(), BMC_POWER_ON_STATUS) )
power_state = BMC_POWER_OFF_STATUS ;
string protocol_str = jsonUtil_get_key_value_string ( json_obj, "protocol" );
if ( strcmp (protocol_str.data(), BMC_PROTOCOL__REDFISHTOOL_STR) )
protocol = BMC_PROTOCOL__IPMITOOL ;
else
protocol = BMC_PROTOCOL__REDFISHTOOL ;
json_object_put(json_obj);
return (true);
}
else
{
/* Set to default value for power state and protocol */
power_state = BMC_POWER_OFF_STATUS ;
protocol = BMC_PROTOCOL__IPMITOOL ;
blog ("%s failed to parse bmc info! set to ipmitool by default!\n", hostname.c_str());
return (false);
}
}
/*****************************************************************************
*
* Name : bmcUtil_read_hwmond_protocol
* Description : Read hwmon protocol from hwmon_hostname_protocol file
* Parameters : hostname - host name
* Return : bmc protocol
*
*****************************************************************************/
bmc_protocol_enum bmcUtil_read_hwmond_protocol ( string hostname )
{
bmc_protocol_enum protocol = BMC_PROTOCOL__IPMITOOL ;
string hwmond_proto_filename = BMC_HWMON_TMP_DIR + hostname ;
string proto_str = daemon_read_file ( hwmond_proto_filename.data() ) ;
if ( strcmp (proto_str.data(), BMC_PROTOCOL__REDFISHTOOL_STR) )
protocol = BMC_PROTOCOL__REDFISHTOOL ;
return protocol;
}
/*****************************************************************************
*
* Name : bmcUtil_write_hwmond_protocol
* Description : Write hwmon protocol to hwmon_hostname_protocol file
* Parameters : hostname - host name
protocol - protocol stored to the file
*
*****************************************************************************/
void bmcUtil_write_hwmond_protocol ( string hostname,
bmc_protocol_enum protocol )
{
string hwmond_proto_filename = BMC_HWMON_TMP_DIR + hostname ;
/* remove old file if present and write current protocol to the file*/
daemon_remove_file ( hwmond_proto_filename.data() );
string proto_str = bmcUtil_getProtocol_str ( protocol ) ;
daemon_log ( hwmond_proto_filename.data(), proto_str.data() );
}
/*************************************************************************
*
* Name : bmcUtil_create_pw_file

View File

@ -20,7 +20,8 @@ using namespace std;
#include "nodeBase.h" /* for ... */
#include "threadUtil.h" /* for ... thread_info_type and utilities */
#define BMC_OUTPUT_DIR ((const char *)("/var/run/bmc/"))
#define BMC_OUTPUT_DIR ((const char *)("/var/run/bmc/"))
#define BMC_HWMON_TMP_DIR ((const char *)("/etc/mtc/tmp/hwmon/"))
/* supported protocol strings */
#define BMC_PROTOCOL__IPMITOOL_STR ((const char *)("ipmitool"))
@ -96,12 +97,16 @@ typedef enum
#define BMC_POWER_STATUS_FILE_SUFFIX ((const char *)("_power_status"))
#define BMC_SENSOR_OUTPUT_FILE_SUFFIX ((const char *)("_sensor_data"))
#define BMC_POWER_ON_STATUS ((const char *)("on"))
#define BMC_POWER_OFF_STATUS ((const char *)("off"))
#define BMC_MAX_RECV_RETRIES (10)
/* get the thread command name string */
string bmcUtil_getCmd_str ( int command );
string bmcUtil_getAction_str ( int action );
string bmcUtil_getProtocol_str ( bmc_protocol_enum protocol );
string bmcUtil_chop_system_req ( string request );
/* module initialization */
int bmcUtil_init ( void );
@ -119,6 +124,16 @@ string bmcUtil_create_data_fn ( string & hostname,
string file_suffix,
bmc_protocol_enum protocol );
/* Read power status and protocol from bmc info file */
bool bmcUtil_read_bmc_info ( string hostname,
string & power_state,
bmc_protocol_enum & protocol);
bmc_protocol_enum bmcUtil_read_hwmond_protocol ( string hostname );
void bmcUtil_write_hwmond_protocol ( string hostname,
bmc_protocol_enum protocol );
/* this utility creates the bmc info file for hardware monitor */
void bmcUtil_hwmon_info ( string hostname,
bmc_protocol_enum proto,

View File

@ -122,6 +122,40 @@ void threadUtil_fini ( void )
; // ilog ("called\n");
}
/*****************************************************************************
*
* Name : threadUtil_bmcSystemCall
*
* Description: Execute a bmc system call using the supplied request string.
*
* If the call takes longer than the supplied latency threshold
* then print a log indicating how long it took.
*
* Returns : the system call's return code.
*
****************************************************************************/
#ifndef NSEC_TO_SEC
#define NSEC_TO_SEC (1000000000)
#endif
int threadUtil_bmcSystemCall (string hostname,
string request,
unsigned long long latency_threshold_secs)
{
unsigned long long before_time = gettime_monotonic_nsec () ;
int rc = system ( request.data()) ;
unsigned long long after_time = gettime_monotonic_nsec () ;
unsigned long long delta_time = after_time-before_time ;
if ( delta_time > (latency_threshold_secs*1000000000))
{
wlog ("%s bmc system call took %2llu.%-8llu sec", hostname.c_str(),
(delta_time > NSEC_TO_SEC) ? (delta_time/NSEC_TO_SEC) : 0,
(delta_time > NSEC_TO_SEC) ? (delta_time%NSEC_TO_SEC) : 0);
}
return (rc);
}
/*****************************************************************************
*
* Name : _stage_change

View File

@ -259,6 +259,11 @@ typedef struct
void threadUtil_fini ( void );
int threadUtil_init ( void (*handler)(int, siginfo_t*, void* ));
#define DEFAULT_SYSTEM_REQUEST_LATENCY_SECS (unsigned long long)(15)
int threadUtil_bmcSystemCall (string hostname,
string request,
unsigned long long latency_threshold_secs);
void threadUtil_setstack_size ( void );
/* Onetime thread init setup */

View File

@ -734,7 +734,7 @@ int hwmonHostClass::add_host ( node_inv_type & inv )
thread_init ( host_ptr->bmc_thread_ctrl,
host_ptr->bmc_thread_info,
&host_ptr->thread_extra_info,
hwmonThread_ipmitool,
hwmonThread_bmc,
DEFAULT_THREAD_TIMEOUT_SECS,
host_ptr->hostname,
THREAD_NAME__BMC);
@ -757,6 +757,11 @@ int hwmonHostClass::add_host ( node_inv_type & inv )
host_ptr->group_index = 0 ;
/* Set default BMC protocol */
host_ptr->protocol = BMC_PROTOCOL__IPMITOOL ;
host_ptr->bmc_thread_info.proto = BMC_PROTOCOL__IPMITOOL ;
bmcUtil_write_hwmond_protocol ( host_ptr->hostname, BMC_PROTOCOL__IPMITOOL ) ;
/* Init sensor model relearn controls, state and status */
host_ptr->relearn = false ;
host_ptr->relearn_request = false ;

View File

@ -81,6 +81,9 @@ class hwmonHostClass
/* throttle degrade audit logs */
int degrade_audit_log_throttle ;
/* throttle log stating its waiting for prococol from mtce */
int general_log_throttle ;
/** set to the protocol used to communicate with this server's BMC */
bmc_protocol_enum protocol ;

View File

@ -446,11 +446,38 @@ int hwmonHostClass::add_host_handler ( struct hwmonHostClass::hwmon_host * host_
mtcTimer_start ( host_ptr->addTimer, hwmonTimer_handler, delay );
break ;
}
/* get protocol used for last relearn from the file */
host_ptr->protocol = bmcUtil_read_hwmond_protocol ( host_ptr->hostname ) ;
}
else
{
ilog ("%s no sensor model in database ; must be learned\n",
host_ptr->hostname.c_str());
string power_state ;
bmc_protocol_enum protocol ;
if ( bmcUtil_read_bmc_info( host_ptr->hostname, power_state, protocol ))
{
ilog ("%s no sensor model in database ; must be learned\n",
host_ptr->hostname.c_str());
if ( protocol != host_ptr->protocol)
{
ilog ("%s bmc protocol changed to %s",
host_ptr->hostname.c_str(),
bmcUtil_getProtocol_str(protocol).c_str());
}
host_ptr->protocol = protocol ;
bmcUtil_write_hwmond_protocol ( host_ptr->hostname, protocol ) ;
host_ptr->general_log_throttle = 0 ;
}
else
{
/* mtc has not yet determined bmc protocol */
mtcTimer_start ( host_ptr->addTimer, hwmonTimer_handler, MTC_SECS_5 );
/* log every minute ; 5*12 */
ilog_throttled (host_ptr->general_log_throttle, 12,
"%s waiting for bmc protocol from mtce ; %d seconds between retries\n",
host_ptr->hostname.c_str(), MTC_SECS_5);
break;
}
}
addStageChange ( host_ptr , HWMON_ADD__DONE );
}
@ -691,14 +718,29 @@ int hwmonHostClass::bmc_sensor_monitor ( struct hwmonHostClass::hwmon_host * hos
/* enter relearn mode */
host_ptr->relearn = true ;
/* Update bmc protocol and hwmond_hostname_protocol file */
string power_state;
bmc_protocol_enum protocol;
bmcUtil_read_bmc_info ( host_ptr->hostname, power_state, protocol ) ;
if ( protocol != host_ptr->protocol)
{
ilog ("%s bmc protocol changed to %s",
host_ptr->hostname.c_str(),
bmcUtil_getProtocol_str(protocol).c_str());
}
host_ptr->protocol = protocol ;
bmcUtil_write_hwmond_protocol ( host_ptr->hostname, protocol ) ;
/* exit relearn request mode.
* allow the relearn operation to proceed */
host_ptr->relearn_request = false ;
host_ptr->relearn_done_date = future_time ( relearn_time );
ilog ("%s next relearn permitted after %s\n",
ilog ("%s next relearn permitted after %s (%s)\n",
host_ptr->hostname.c_str(),
host_ptr->relearn_done_date.c_str());
host_ptr->relearn_done_date.c_str(),
bmcUtil_getProtocol_str(host_ptr->protocol).c_str());
this->monitor_soon ( host_ptr );
@ -796,6 +838,7 @@ int hwmonHostClass::bmc_sensor_monitor ( struct hwmonHostClass::hwmon_host * hos
host_ptr->bmc_thread_info.id = 0 ;
host_ptr->bmc_thread_info.signal = 0 ;
host_ptr->bmc_thread_info.command = BMC_THREAD_CMD__POWER_STATUS ;
host_ptr->bmc_thread_info.proto = host_ptr->protocol ;
/* Update / Setup the BMC query credentials */
host_ptr->thread_extra_info.bm_ip = host_ptr->bm_ip ;
@ -852,7 +895,7 @@ int hwmonHostClass::bmc_sensor_monitor ( struct hwmonHostClass::hwmon_host * hos
else
{
host_ptr->interval_changed = true ;
wlog ("%s audit interval is zero ; auto correcting\n", host_ptr->hostname.c_str());
blog ("%s audit interval is zero ; auto correcting\n", host_ptr->hostname.c_str());
break ;
}
}
@ -943,19 +986,17 @@ int hwmonHostClass::bmc_sensor_monitor ( struct hwmonHostClass::hwmon_host * hos
wlog ("%s power query status empty ; retrying query\n",
host_ptr->hostname.c_str());
}
else if ( host_ptr->bmc_thread_info.data.find (IPMITOOL_POWER_ON_STATUS) == string::npos )
else if ( host_ptr->bmc_thread_info.data.find (BMC_POWER_ON_STATUS) == string::npos )
{
ilog ("%s %s\n", host_ptr->hostname.c_str(),
host_ptr->bmc_thread_info.data.c_str());
wlog ("%s sensor learning delayed ; need power on\n",
host_ptr->hostname.c_str());
wlog ("%s power %s sensor learning delayed ; need power on\n",
host_ptr->hostname.c_str(),
host_ptr->bmc_thread_info.data.c_str());
}
else
{
ilog ("%s %s\n", host_ptr->hostname.c_str(),
host_ptr->bmc_thread_info.data.c_str());
/* OK, this is what we have been waiting for */
host_ptr->poweron = true ;
}
@ -1083,13 +1124,13 @@ int hwmonHostClass::bmc_sensor_monitor ( struct hwmonHostClass::hwmon_host * hos
host_ptr->bmc_thread_info.id = 0 ;
host_ptr->bmc_thread_info.signal = 0 ;
host_ptr->bmc_thread_info.command = BMC_THREAD_CMD__READ_SENSORS ;
host_ptr->bmc_thread_info.proto = host_ptr->protocol ;
/* Update / Setup the BMC query credentials */
host_ptr->thread_extra_info.bm_ip = host_ptr->bm_ip ;
host_ptr->thread_extra_info.bm_un = host_ptr->bm_un ;
host_ptr->thread_extra_info.bm_pw = host_ptr->bm_pw ;
rc = thread_launch ( host_ptr->bmc_thread_ctrl, host_ptr->bmc_thread_info ) ;
if ( rc != PASS )
{

View File

@ -362,25 +362,25 @@ void * hwmonThread_ipmitool ( void * arg )
info_ptr->password_file.c_str());
/*************** Create the output filename ***************/
string ipmitool_datafile =
string datafile =
bmcUtil_create_data_fn (info_ptr->hostname,
BMC_POWER_STATUS_FILE_SUFFIX,
BMC_PROTOCOL__IPMITOOL ) ;
dlog_t ("%s power query filename : %s\n",
info_ptr->log_prefix,
ipmitool_datafile.c_str());
datafile.c_str());
/************** Create the ipmitool request **************/
string ipmitool_request =
string request =
ipmiUtil_create_request ( command,
extra_ptr->bm_ip,
extra_ptr->bm_un,
info_ptr->password_file,
ipmitool_datafile );
datafile );
dlog_t ("%s power status query cmd: %s\n",
info_ptr->log_prefix,
ipmitool_request.c_str());
request.c_str());
if ( daemon_is_file_present ( MTC_CMD_FIT__POWER_STATUS ))
{
@ -390,7 +390,7 @@ void * hwmonThread_ipmitool ( void * arg )
else
{
/* Make the request */
rc = system ( ipmitool_request.data()) ;
rc = system ( request.data()) ;
}
unlink(info_ptr->password_file.data());
@ -400,29 +400,29 @@ void * hwmonThread_ipmitool ( void * arg )
if ( rc != PASS )
{
info_ptr->status_string = "failed power status query ; " ;
info_ptr->status_string.append(ipmitool_request);
info_ptr->status_string.append(request);
info_ptr->status = FAIL_SYSTEM_CALL ;
}
else
{
bool ipmitool_datafile_present = false ;
bool datafile_present = false ;
/* look for the output data file */
for ( int i = 0 ; i < 10 ; i++ )
{
pthread_signal_handler ( info_ptr );
if ( daemon_is_file_present ( ipmitool_datafile.data() ))
if ( daemon_is_file_present ( datafile.data() ))
{
ipmitool_datafile_present = true ;
datafile_present = true ;
break ;
}
info_ptr->progress++ ;
sleep (1);
}
if ( ipmitool_datafile_present )
if ( datafile_present )
{
info_ptr->data = daemon_read_file (ipmitool_datafile.data()) ;
info_ptr->data = daemon_read_file (datafile.data()) ;
dlog_t ("%s data:%s\n",
info_ptr->hostname.c_str(),
info_ptr->data.data());
@ -950,18 +950,18 @@ static int _parse_redfish_sensor_data( char * json_str_ptr, thread_info_type * i
* Name : _redfishUtil_send_request
* Description : Construct redfishtool request and send it out
* Parameters : info_ptr - thread info
redfishtool_datafile - date file used for storing redfishtool comand response
file_suffix - file suffix for redfishtool_datafile name
datafile - date file used for storing redfishtool comand response
file_suffix - file suffix for datafile name
redfish_cmd_str - redfish command string
* Returns : PASS if command sent out successfully.
*
*****************************************************************************/
static int _redfishUtil_send_request( thread_info_type * info_ptr, string & redfishtool_datafile,
static int _redfishUtil_send_request( thread_info_type * info_ptr, string & datafile,
const char * file_suffix, const char * redfish_cmd_str )
{
string redfishtool_request = "" ;
string pw_file_content = "" ;
string request = "" ;
string config_file_content = "" ;
int rc = PASS ;
thread_extra_info_type * extra_ptr = (thread_extra_info_type*)info_ptr->extra_info_ptr ;
@ -976,13 +976,15 @@ static int _redfishUtil_send_request( thread_info_type * info_ptr, string & redf
}
/**************** Create the password file *****************/
pw_file_content = "{\"user\" : \"" ;
pw_file_content.append(extra_ptr->bm_un) ;
pw_file_content.append("\", \"password\" : \"") ;
pw_file_content.append(extra_ptr->bm_pw) ;
pw_file_content.append("\"}") ;
config_file_content = "{\"username\":\"" ;
config_file_content.append(extra_ptr->bm_un) ;
config_file_content.append("\",\"user\":\"") ;
config_file_content.append(extra_ptr->bm_un) ;
config_file_content.append("\",\"password\":\"") ;
config_file_content.append(extra_ptr->bm_pw) ;
config_file_content.append("\"}") ;
bmcUtil_create_pw_file ( info_ptr, pw_file_content, BMC_PROTOCOL__REDFISHTOOL ) ;
bmcUtil_create_pw_file ( info_ptr, config_file_content, BMC_PROTOCOL__REDFISHTOOL ) ;
if ( info_ptr->password_file.empty() )
{
info_ptr->status_string = "failed to get a temporary password filename" ;
@ -995,69 +997,54 @@ static int _redfishUtil_send_request( thread_info_type * info_ptr, string & redf
info_ptr->password_file.c_str());
/*************** Create the output filename ***************/
redfishtool_datafile =
bmcUtil_create_data_fn (info_ptr->hostname, file_suffix, BMC_PROTOCOL__REDFISHTOOL ) ;
dlog_t ("%s create data filename : %s\n",
info_ptr->log_prefix,
redfishtool_datafile.c_str());
datafile = bmcUtil_create_data_fn (info_ptr->hostname, file_suffix, BMC_PROTOCOL__REDFISHTOOL ) ;
dlog_t ("%s create data filename : %s\n", info_ptr->log_prefix, datafile.c_str());
/************** Create the redfishtool request **************/
redfishtool_request =
redfishUtil_create_request ( redfish_cmd_str,
extra_ptr->bm_ip,
info_ptr->password_file,
redfishtool_datafile );
request = redfishUtil_create_request ( redfish_cmd_str,
extra_ptr->bm_ip,
info_ptr->password_file,
datafile );
dlog_t ("%s query cmd: %s\n",
info_ptr->log_prefix,
redfishtool_request.c_str());
request.c_str());
if ( ( info_ptr->command == BMC_THREAD_CMD__BMC_INFO
&& daemon_is_file_present ( MTC_CMD_FIT__MC_INFO ) )
|| ( info_ptr->command == BMC_THREAD_CMD__POWER_STATUS
&& daemon_is_file_present ( MTC_CMD_FIT__POWER_STATUS ) ) )
if (( info_ptr->command == BMC_THREAD_CMD__READ_SENSORS ) &&
( daemon_is_file_present ( MTC_CMD_FIT__SENSOR_DATA )))
{
slog ("%s FIT CMD %s\n", info_ptr->hostname.c_str(), redfish_cmd_str);
rc = PASS ;
}
else if ( info_ptr->command == BMC_THREAD_CMD__READ_SENSORS )
{
if( daemon_is_file_present ( MTC_CMD_FIT__SENSOR_DATA ))
{
rc = PASS ;
}
#ifdef WANT_FIT_TESTING
else if ( daemon_want_fit ( FIT_CODE__HWMON__AVOID_SENSOR_QUERY, info_ptr->hostname ))
{
rc = PASS ; // ilog ("%s FIT Avoiding Sensor Query\n", info_ptr->hostname.c_str());
}
else if ( daemon_want_fit ( FIT_CODE__AVOID_N_FAIL_BMC_REQUEST, info_ptr->hostname ))
{
rc = FAIL ; // ilog ("%s FIT Avoiding Sensor Query\n", info_ptr->hostname.c_str());
}
else
{
/* Make the request */
rc = system ( redfishtool_request.data()) ;
}
#endif
}
else
{
/* Make the request */
rc = system ( redfishtool_request.data()) ;
daemon_remove_file ( datafile.data() ) ;
rc = threadUtil_bmcSystemCall (info_ptr->hostname, request,
DEFAULT_SYSTEM_REQUEST_LATENCY_SECS) ;
if ( rc != PASS )
{
/* crop garbage from the command to reduce log length */
string cmd_only = bmcUtil_chop_system_req ( request ) ;
elog_t ("%s system call failed [%s] (%d:%d:%m)\n",
info_ptr->hostname.c_str(),
cmd_only.c_str(),
rc, errno );
info_ptr->status = FAIL_SYSTEM_CALL ;
if ( daemon_is_file_present ( datafile.data() ))
{
/* load in the error. stdio is redirected to the datafile */
info_ptr->status_string = daemon_read_file(datafile.data());
}
else
{
info_ptr->status_string = "system call failed for info query ; " ;
info_ptr->status_string.append(request);
}
}
}
unlink(info_ptr->password_file.data());
daemon_remove_file (info_ptr->password_file.data());
/* check for system call error case */
if ( rc != PASS )
{
info_ptr->status_string = "system call failed for info query ; " ;
info_ptr->status_string.append(redfishtool_request);
info_ptr->status = FAIL_SYSTEM_CALL ;
}
return (rc) ;
}
@ -1065,20 +1052,20 @@ static int _redfishUtil_send_request( thread_info_type * info_ptr, string & redf
*
* Name : wait_for_command_output
* Description : Wait for some time to check if redfishtool command output is available.
* Parameters : info_ptr - thread info
redfishtool_datafile - date file used for storing redfishtool comand response
* Parameters : info_ptr - thread info
datafile - date file used for storing redfishtool comand response
* Returns : True if command response file is availalbe
False if command response file is unavailable after timeout.
*
*****************************************************************************/
static bool _wait_for_command_output( thread_info_type * info_ptr, string & redfishtool_datafile )
static bool _wait_for_command_output( thread_info_type * info_ptr, string & datafile )
{
/* look for the output data file */
for ( int i = 0 ; i < 10 ; i++ )
{
pthread_signal_handler ( info_ptr );
if ( daemon_is_file_present ( redfishtool_datafile.data() ))
if ( daemon_is_file_present ( datafile.data() ))
{
return true ;
}
@ -1097,7 +1084,7 @@ static bool _wait_for_command_output( thread_info_type * info_ptr, string & redf
* Description : Parse power and thermal sensor data
* Parameters : info_ptr - thread info
sensor_group - power & thermal group
redfishtool_datafile - date file used for storing redfishtool comand response
datafile - date file used for storing redfishtool comand response
samples - sensor data index for _sample_list array.
* Returns : PASS if file access is OK
*
@ -1105,10 +1092,10 @@ static bool _wait_for_command_output( thread_info_type * info_ptr, string & redf
static int _parse_redfish_sensor_data_output_file( thread_info_type * info_ptr,
int sensor_group,
string & redfishtool_datafile,
string & datafile,
int & samples )
{
FILE * _fp = fopen ( redfishtool_datafile.data(), "r" );
FILE * _fp = fopen ( datafile.data(), "r" );
if ( _fp )
{
@ -1160,7 +1147,7 @@ static int _parse_redfish_sensor_data_output_file( thread_info_type * info_ptr,
{
info_ptr->status = FAIL_FILE_ACCESS ;
info_ptr->status_string = "failed to open sensor data file: ";
info_ptr->status_string.append(redfishtool_datafile);
info_ptr->status_string.append(datafile);
}
return FAIL ;
@ -1180,7 +1167,7 @@ void * hwmonThread_redfish ( void * arg )
thread_info_type * info_ptr ;
thread_extra_info_type * extra_ptr ;
string redfishtool_datafile = "";
string datafile = "";
/* Pointer Error Detection and Handling */
if ( !arg )
@ -1217,15 +1204,15 @@ void * hwmonThread_redfish ( void * arg )
case BMC_THREAD_CMD__READ_SENSORS:
{
blog2_t ("%s read power sensors \n", info_ptr->log_prefix);
if ( _redfishUtil_send_request( info_ptr, redfishtool_datafile,
if ( _redfishUtil_send_request( info_ptr, datafile,
BMC_SENSOR_OUTPUT_FILE_SUFFIX,
REDFISHTOOL_READ_POWER_SENSORS_CMD ) == PASS )
{
/* look for the output data file */
if( _wait_for_command_output(info_ptr, redfishtool_datafile) )
if( _wait_for_command_output(info_ptr, datafile) )
{
_parse_redfish_sensor_data_output_file( info_ptr, BMC_SENSOR_POWER_GROUP,
redfishtool_datafile, samples );
datafile, samples );
}
else
{
@ -1234,15 +1221,15 @@ void * hwmonThread_redfish ( void * arg )
}
blog2_t ("%s read thermal sensors \n", info_ptr->log_prefix);
if (_redfishUtil_send_request( info_ptr, redfishtool_datafile,
if (_redfishUtil_send_request( info_ptr, datafile,
BMC_SENSOR_OUTPUT_FILE_SUFFIX,
REDFISHTOOL_READ_THERMAL_SENSORS_CMD ) == PASS )
{
/* look for the output data file */
if( _wait_for_command_output(info_ptr, redfishtool_datafile) )
if( _wait_for_command_output(info_ptr, datafile) )
{
_parse_redfish_sensor_data_output_file( info_ptr, BMC_SENSOR_THERMAL_GROUP,
redfishtool_datafile, samples );
datafile, samples );
}
}
@ -1259,46 +1246,22 @@ void * hwmonThread_redfish ( void * arg )
}
break ;
}
case BMC_THREAD_CMD__BMC_INFO:
{
blog2_t ("%s query BMC info\n", info_ptr->log_prefix);
if (_redfishUtil_send_request( info_ptr, redfishtool_datafile,
BMC_INFO_FILE_SUFFIX, REDFISHTOOL_BMC_INFO_CMD )
== PASS )
{
/* look for the output data file */
if( _wait_for_command_output(info_ptr, redfishtool_datafile) )
{
info_ptr->data = daemon_read_file (redfishtool_datafile.data()) ;
dlog_t ("%s data:%s\n",
info_ptr->hostname.c_str(),
info_ptr->data.data());
info_ptr->status_string = "pass" ;
info_ptr->status = PASS ;
}
}
break ;
}
case BMC_THREAD_CMD__POWER_STATUS:
{
string power_status = "" ;
bmc_protocol_enum protocol ;
blog2_t ("%s query power status info\n", info_ptr->log_prefix);
if ( _redfishUtil_send_request( info_ptr, redfishtool_datafile,
BMC_POWER_STATUS_FILE_SUFFIX,
REDFISHTOOL_POWER_STATUS_CMD ) == PASS )
bmcUtil_read_bmc_info (info_ptr->hostname, power_status, protocol);
if (power_status.find (BMC_POWER_ON_STATUS) == string::npos)
{
/* look for the output data file */
if( _wait_for_command_output(info_ptr, redfishtool_datafile) )
{
info_ptr->data = daemon_read_file (redfishtool_datafile.data()) ;
dlog_t ("%s data:%s\n",
info_ptr->hostname.c_str(),
info_ptr->data.data());
info_ptr->status_string = "pass" ;
info_ptr->status = PASS ;
}
info_ptr->data = BMC_POWER_OFF_STATUS ;
}
else
{
info_ptr->data = BMC_POWER_ON_STATUS ;
}
info_ptr->status_string = "pass" ;
info_ptr->status = PASS ;
break ;
}
default:
@ -1336,3 +1299,31 @@ redfishtool_thread_done:
pthread_exit (&info_ptr->status );
return NULL ;
}
/*****************************************************************************
*
* Name : hwmonThread_bmc
* Purpose : This thread used for sending bmc command
* Description : hwmon thread main function
*
*****************************************************************************/
void * hwmonThread_bmc ( void * arg )
{
string power_status = "";
string protocol = "";
/* cast pointers from arg */
thread_info_type * info_ptr = (thread_info_type*)arg ;
if (info_ptr->proto == BMC_PROTOCOL__REDFISHTOOL )
{
hwmonThread_redfish ( arg );
}
else
{
hwmonThread_ipmitool ( arg );
}
return NULL ;
}

View File

@ -42,8 +42,8 @@
#define BMC_SENSOR_POWER_GROUP 0
#define BMC_SENSOR_THERMAL_GROUP 1
void * hwmonThread_ipmitool ( void * );
void * hwmonThread_redfish ( void * );
void * hwmonThread_bmc ( void * );
/* --------------------
* ipmitool_sensor_data: outgoing message
* --------------------
@ -162,10 +162,8 @@ using namespace std;
#define BMC_SENSOR_OUTPUT_FILE_SUFFIX ((const char *)("_sensor_data"))
/* TBD */
#define REDFISHTOOL_READ_POWER_SENSORS_CMD ((const char *)("Chassis Power"))
#define REDFISHTOOL_READ_THERMAL_SENSORS_CMD ((const char *)("Chassis Thermal"))
#define REDFISHTOOL_POWER_STATUS_CMD ((const char *)(" "))
typedef struct
{