sensor: Refactor ipmi_sensor_print_fc_threshold()

Break the function into smaller pieces to reduce
complexity.
This commit is contained in:
eyjhbb@gmail.com 2018-09-24 15:41:00 +02:00 committed by Alexander Amelkin
parent 9d49a6edfe
commit 6f336d04f1

View File

@ -260,34 +260,13 @@ print_thresh_setting(struct sdr_record_full_sensor *full,
}
}
static int
ipmi_sensor_print_fc_threshold(struct ipmi_intf *intf,
struct sdr_record_common_sensor *sensor,
uint8_t sdr_record_type)
static void
dump_sensor_fc_thredshold_csv(
int thresh_available,
const char *thresh_status,
struct ipmi_rs *rsp,
struct sensor_reading *sr)
{
int thresh_available = 1;
struct ipmi_rs *rsp;
struct sensor_reading *sr;
sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr_record_type, 3);
if (!sr) {
return -1;
}
const char *thresh_status = ipmi_sdr_get_thresh_status(sr, "ns");
/*
* Get sensor thresholds
*/
rsp = ipmi_sdr_get_sensor_thresholds(intf,
sensor->keys.sensor_num, sensor->keys.owner_id,
sensor->keys.lun, sensor->keys.channel);
if (!rsp || rsp->ccode || !rsp->data_len)
thresh_available = 0;
if (csv_output) {
printf("%s", sr->s_id);
if (sr->s_reading_valid) {
if (sr->s_has_analog_value)
@ -317,11 +296,18 @@ print_thresh_setting(sr->full, rsp->data[0] & (bit), \
"na", "na", "na", "na", "na", "na");
}
printf("\n");
} else {
if (verbose == 0) {
}
/* output format
* id value units status thresholds....
*/
static void
dump_sensor_fc_thredshold(
int thresh_available,
const char *thresh_status,
struct ipmi_rs *rsp,
struct sensor_reading *sr)
{
printf("%-16s ", sr->s_id);
if (sr->s_reading_valid) {
if (sr->s_has_analog_value)
@ -352,7 +338,17 @@ print_thresh_setting(sr->full, rsp->data[0] & (bit), \
}
printf("\n");
} else {
}
static void
dump_sensor_fc_thredshold_verbose(
int thresh_available,
const char *thresh_status,
struct ipmi_intf *intf,
struct sdr_record_common_sensor *sensor,
struct ipmi_rs *rsp,
struct sensor_reading *sr)
{
printf("Sensor ID : %s (0x%x)\n",
sr->s_id, sensor->keys.sensor_num);
@ -360,8 +356,7 @@ print_thresh_setting(sr->full, rsp->data[0] & (bit), \
sensor->entity.id, sensor->entity.instance);
printf(" Sensor Type (Threshold) : %s\n",
ipmi_get_sensor_type(intf, sensor->sensor.
type));
ipmi_get_sensor_type(intf, sensor->sensor.type));
printf(" Sensor Reading : ");
if (sr->s_reading_valid) {
@ -384,8 +379,8 @@ print_thresh_setting(sr->full, rsp->data[0] & (bit), \
sr->s_a_units);
}
} else {
printf("0x%x %s\n", sr->s_reading,
sr->s_a_units);
printf("0x%x %s\n",
sr->s_reading, sr->s_a_units);
}
printf(" Status : %s\n", thresh_status);
@ -396,7 +391,6 @@ print_thresh_setting(sr->full, rsp->data[0] & (bit), \
rsp->data[(dataidx)], \
(str), "%.3f\n", "0x%x\n", "%s\n"); \
}
PTS(LOWER_NON_RECOV_SPECIFIED, 3, " Lower Non-Recoverable : ");
PTS(LOWER_CRIT_SPECIFIED, 2, " Lower Critical : ");
PTS(LOWER_NON_CRIT_SPECIFIED, 1, " Lower Non-Critical : ");
@ -443,6 +437,43 @@ print_thresh_setting(sr->full, rsp->data[0] & (bit), \
printf("\n");
}
static int
ipmi_sensor_print_fc_threshold(struct ipmi_intf *intf,
struct sdr_record_common_sensor *sensor,
uint8_t sdr_record_type)
{
int thresh_available = 1;
struct ipmi_rs *rsp;
struct sensor_reading *sr;
sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr_record_type, 3);
if (!sr) {
return -1;
}
const char *thresh_status = ipmi_sdr_get_thresh_status(sr, "ns");
/*
* Get sensor thresholds
*/
rsp = ipmi_sdr_get_sensor_thresholds(intf,
sensor->keys.sensor_num, sensor->keys.owner_id,
sensor->keys.lun, sensor->keys.channel);
if (!rsp || rsp->ccode || !rsp->data_len)
thresh_available = 0;
if (csv_output) {
dump_sensor_fc_thredshold_csv(thresh_available, thresh_status, rsp, sr);
} else {
if (verbose == 0) {
dump_sensor_fc_thredshold(thresh_available, thresh_status, rsp, sr);
} else {
dump_sensor_fc_thredshold_verbose(thresh_available, thresh_status,
intf, sensor, rsp, sr);
}
}
return (sr->s_reading_valid ? 0 : -1 );