Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add struct for mapping ibpi statuses to strings. #211

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 9 additions & 79 deletions src/ledctl/ledctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,75 +376,12 @@ static struct ibpi_state *_ibpi_find(const struct list *ibpi_local_list,
*/
static struct ibpi_state *_ibpi_state_get(const char *name)
{
enum led_ibpi_pattern ibpi = string2ibpi(name);
struct ibpi_state *state = NULL;
enum led_ibpi_pattern ibpi;

if (strcmp(name, "locate") == 0) {
ibpi = LED_IBPI_PATTERN_LOCATE;
} else if (strcmp(name, "locate_off") == 0) {
ibpi = LED_IBPI_PATTERN_LOCATE_OFF;
} else if (strcmp(name, "normal") == 0) {
ibpi = LED_IBPI_PATTERN_NORMAL;
} else if (strcmp(name, "off") == 0) {
ibpi = LED_IBPI_PATTERN_NORMAL;
} else if ((strcmp(name, "ica") == 0) ||
(strcmp(name, "degraded") == 0)) {
ibpi = LED_IBPI_PATTERN_DEGRADED;
} else if (strcmp(name, "rebuild") == 0) {
ibpi = LED_IBPI_PATTERN_REBUILD;
} else if ((strcmp(name, "ifa") == 0) ||
(strcmp(name, "failed_array") == 0)) {
ibpi = LED_IBPI_PATTERN_FAILED_ARRAY;
} else if (strcmp(name, "hotspare") == 0) {
ibpi = LED_IBPI_PATTERN_HOTSPARE;
} else if (strcmp(name, "pfa") == 0) {
ibpi = LED_IBPI_PATTERN_PFA;
} else if ((strcmp(name, "failure") == 0) ||
(strcmp(name, "disk_failed") == 0)) {
ibpi = LED_IBPI_PATTERN_FAILED_DRIVE;
} else if (strcmp(name, "locate_and_failure") == 0) {
ibpi = LED_IBPI_PATTERN_LOCATE_AND_FAILED_DRIVE;
} else if (strcmp(name, "ses_abort") == 0) {
ibpi = LED_SES_REQ_ABORT;
} else if (strcmp(name, "ses_rebuild") == 0) {
ibpi = LED_SES_REQ_REBUILD;
} else if (strcmp(name, "ses_ifa") == 0) {
ibpi = LED_SES_REQ_IFA;
} else if (strcmp(name, "ses_ica") == 0) {
ibpi = LED_SES_REQ_ICA;
} else if (strcmp(name, "ses_cons_check") == 0) {
ibpi = LED_SES_REQ_CONS_CHECK;
} else if (strcmp(name, "ses_hotspare") == 0) {
ibpi = LED_SES_REQ_HOTSPARE;
} else if (strcmp(name, "ses_rsvd_dev") == 0) {
ibpi = LED_SES_REQ_RSVD_DEV;
} else if (strcmp(name, "ses_ok") == 0) {
ibpi = LED_SES_REQ_OK;
} else if (strcmp(name, "ses_ident") == 0) {
ibpi = LED_SES_REQ_IDENT;
} else if (strcmp(name, "ses_rm") == 0) {
ibpi = LED_SES_REQ_RM;
} else if (strcmp(name, "ses_insert") == 0) {
ibpi = LED_SES_REQ_INS;
} else if (strcmp(name, "ses_missing") == 0) {
ibpi = LED_SES_REQ_MISSING;
} else if (strcmp(name, "ses_dnr") == 0) {
ibpi = LED_SES_REQ_DNR;
} else if (strcmp(name, "ses_active") == 0) {
ibpi = LED_SES_REQ_ACTIVE;
} else if (strcmp(name, "ses_enable_bb") == 0) {
ibpi = LED_SES_REQ_EN_BB;
} else if (strcmp(name, "ses_enable_ba") == 0) {
ibpi = LED_SES_REQ_EN_BA;
} else if (strcmp(name, "ses_devoff") == 0) {
ibpi = LED_SES_REQ_DEV_OFF;
} else if (strcmp(name, "ses_fault") == 0) {
ibpi = LED_SES_REQ_FAULT;
} else if (strcmp(name, "ses_prdfail") == 0) {
ibpi = LED_SES_REQ_PRDFAIL;
} else {
if (ibpi == LED_IBPI_PATTERN_UNKNOWN)
return NULL;
}

state = _ibpi_find(&ibpi_list, ibpi);
if (state == NULL)
state = _ibpi_state_init(ibpi);
Expand Down Expand Up @@ -499,9 +436,7 @@ static led_status_t _ibpi_state_add_block(struct ibpi_state *state, char *name)
return LED_STATUS_OUT_OF_MEMORY;
}
} else {
char buf[IPBI2STR_BUFF_SIZE];
log_info("%s: %s: device already on the list.",
ibpi2str(state->ibpi, buf, sizeof(buf)), path);
log_info("%s: %s: device already on the list.", ibpi2str(state->ibpi), path);
}
return LED_STATUS_SUCCESS;
}
Expand All @@ -510,14 +445,11 @@ static led_status_t verify_block_lists(void)
{
if (!list_is_empty(&ibpi_list)) {
struct ibpi_state *state;
char buf[IPBI2STR_BUFF_SIZE];

list_for_each(&ibpi_list, state) {
if (list_is_empty(&state->block_list)) {
list_for_each(&ibpi_list, state)
if (list_is_empty(&state->block_list))
log_warning("IBPI %s: missing block device(s)... pattern ignored.",
ibpi2str(state->ibpi, buf, sizeof(buf)));
}
}
ibpi2str(state->ibpi));
} else {
log_error("missing operand(s)... run %s --help for details.", progname);
return LED_STATUS_LIST_EMPTY;
Expand Down Expand Up @@ -896,10 +828,9 @@ static led_status_t verify_request(struct led_ctx *ctx, struct request *req)

static void print_slot(struct led_slot_list_entry *s, enum print_param to_print)
{
char buf[IPBI2STR_BUFF_SIZE];
const char *device_name = led_slot_device(s);
const char *slot_id = basename(led_slot_id(s));
const char *ibpi_str = ibpi2str(led_slot_state(s), buf, sizeof(buf));
const char *ibpi_str = ibpi2str(led_slot_state(s));

if (!device_name)
device_name = "(empty)";
Expand Down Expand Up @@ -1002,12 +933,11 @@ led_status_t execute_request(struct led_ctx *ctx, struct request *req)
case OPT_SET_SLOT:
{
led_status_t set_rc = LED_STATUS_SUCCESS;
char buf[IPBI2STR_BUFF_SIZE];

if (req->state != LED_IBPI_PATTERN_LOCATE_OFF
&& led_slot_state(slot) == req->state) {
log_warning("Led state: %s is already set for the slot.",
ibpi2str(req->state, buf, sizeof(buf)));
ibpi2str(req->state));
} else {
set_rc = led_slot_set(ctx, slot, req->state);
}
Expand Down
46 changes: 9 additions & 37 deletions src/ledmon/ledmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,6 @@ static char *ledmon_conf_path;
*/
static int foreground;

/**
* @brief Name of IBPI patterns.
*
* This is internal array with names of IBPI patterns. Logging routines use this
* entries to translate enumeration type into the string.
*/
const char *ibpi_str_ledmon[] = {
[LED_IBPI_PATTERN_UNKNOWN] = "None",
[LED_IBPI_PATTERN_NORMAL] = "Off",
[LED_IBPI_PATTERN_ONESHOT_NORMAL] = "Oneshot Off",
[LED_IBPI_PATTERN_DEGRADED] = "In a Critical Array",
[LED_IBPI_PATTERN_REBUILD] = "Rebuild",
[LED_IBPI_PATTERN_FAILED_ARRAY] = "In a Failed Array",
[LED_IBPI_PATTERN_HOTSPARE] = "Hotspare",
[LED_IBPI_PATTERN_PFA] = "Predicted Failure Analysis",
[LED_IBPI_PATTERN_FAILED_DRIVE] = "Failure",
[LED_IBPI_PATTERN_LOCATE] = "Locate",
[LED_IBPI_PATTERN_LOCATE_OFF] = "Locate Off",
[LED_IBPI_PATTERN_ADDED] = "Added",
[LED_IBPI_PATTERN_REMOVED] = "Removed"
};

/**
* Internal variable of monitor service. It is the pattern used to print out
* information about the version of monitor service.
Expand Down Expand Up @@ -680,7 +658,6 @@ static void _handle_fail_state(struct block_device *block,
static void _add_block(struct block_device *block)
{
struct block_device *temp = NULL;
char buf[IPBI2STR_BUFF_SIZE];

list_for_each(&ledmon_block_list, temp) {
if (block_compare(temp, block))
Expand Down Expand Up @@ -715,12 +692,10 @@ static void _add_block(struct block_device *block)

_handle_fail_state(block, temp);

if (ibpi != temp->ibpi && ibpi <= LED_IBPI_PATTERN_REMOVED) {
log_info("CHANGE %s: from '%s' to '%s'.",
temp->sysfs_path,
ibpi2str_table(ibpi, ibpi_str_ledmon, buf, sizeof(buf)),
ibpi2str_table(temp->ibpi, ibpi_str_ledmon, buf, sizeof(buf)));
}
if (ibpi != temp->ibpi && ibpi <= LED_IBPI_PATTERN_REMOVED)
log_info("CHANGE %s: from '%s' to '%s'", temp->sysfs_path, ibpi2str(ibpi),
ibpi2str(temp->ibpi));

/* Check if name of the device changed.*/
if (strcmp(temp->sysfs_path, block->sysfs_path)) {
log_info("NAME CHANGED %s to %s",
Expand All @@ -736,8 +711,8 @@ static void _add_block(struct block_device *block)
/* Device not found, it's a new one! */
temp = block_device_duplicate(block);
if (temp != NULL) {
log_info("NEW %s: state '%s'.", temp->sysfs_path,
ibpi2str_table(temp->ibpi, ibpi_str_ledmon, buf, sizeof(buf)));
log_info("NEW %s: state '%s'.", temp->sysfs_path, ibpi2str(temp->ibpi));

if (!list_append(&ledmon_block_list, temp)) {
log_error("Memory allocation error!");
exit(1);
Expand All @@ -763,7 +738,6 @@ static void _add_block(struct block_device *block)
*/
static void _send_msg(struct block_device *block)
{
char buf[IPBI2STR_BUFF_SIZE];
if (!block->cntrl) {
log_debug("Missing cntrl for dev: %s. Not sending anything.",
strstr(block->sysfs_path, "host"));
Expand All @@ -772,11 +746,9 @@ static void _send_msg(struct block_device *block)
if (block->timestamp != timestamp ||
block->ibpi == LED_IBPI_PATTERN_REMOVED) {
if (block->ibpi != LED_IBPI_PATTERN_FAILED_DRIVE) {
log_info("CHANGE %s: from '%s' to '%s'.",
block->sysfs_path,
ibpi2str_table(block->ibpi, ibpi_str_ledmon, buf, sizeof(buf)),
ibpi2str_table(LED_IBPI_PATTERN_FAILED_DRIVE, ibpi_str_ledmon,
buf, sizeof(buf)));
log_info("CHANGE %s: from '%s' to '%s'.", block->sysfs_path,
ibpi2str(block->ibpi), ibpi2str(LED_IBPI_PATTERN_FAILED_DRIVE));

block->ibpi = LED_IBPI_PATTERN_FAILED_DRIVE;
} else {
char *host = strstr(block->sysfs_path, "host");
Expand Down
6 changes: 2 additions & 4 deletions src/lib/ahci.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ int ahci_sgpio_write(struct block_device *device, enum led_ibpi_pattern ibpi)
ibpi2val = get_by_ibpi(ibpi, ibpi2sgpio, ARRAY_SIZE(ibpi2sgpio));

if (ibpi2val->ibpi == LED_IBPI_PATTERN_UNKNOWN) {
char buf[IPBI2STR_BUFF_SIZE];

lib_log(device->cntrl->ctx, LED_LOG_LEVEL_INFO,
"AHCI: Controller doesn't support %s pattern\n",
ibpi2str(ibpi, buf, sizeof(buf)));
"AHCI: Controller doesn't support %s pattern\n", ibpi2str(ibpi));

__set_errno_and_return(ERANGE);
}

Expand Down
12 changes: 4 additions & 8 deletions src/lib/amd_ipmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,17 @@ static int _enable_smbus_control(struct amd_drive *drive)

static int _change_ibpi_state(struct amd_drive *drive, enum led_ibpi_pattern ibpi, bool enable)
{
char buf[IPBI2STR_BUFF_SIZE];
const struct ibpi2value *ibpi2val = get_by_ibpi(ibpi, ibpi2amd_ipmi,
ARRAY_SIZE(ibpi2amd_ipmi));

if (ibpi2val->ibpi == LED_IBPI_PATTERN_UNKNOWN) {
lib_log(drive->ctx, LED_LOG_LEVEL_INFO,
"AMD_IPMI: Controller doesn't support %s pattern\n",
ibpi2str(ibpi, buf, sizeof(buf)));
"AMD_IPMI: Controller doesn't support %s pattern\n", ibpi2str(ibpi));
return LED_STATUS_INVALID_STATE;
}

lib_log(drive->ctx, LED_LOG_LEVEL_DEBUG, "%s %s LED\n",
(enable) ? "Enabling":"Disabling", ibpi2str(ibpi, buf, sizeof(buf)));
lib_log(drive->ctx, LED_LOG_LEVEL_DEBUG, "%s %s LED\n", (enable) ? "Enabling" : "Disabling",
ibpi2str(ibpi));

return _set_ipmi_register(enable, ibpi2val->value, drive);
}
Expand Down Expand Up @@ -442,14 +440,12 @@ int _amd_ipmi_write(struct block_device *device, enum led_ibpi_pattern ibpi)
{
int rc;
struct amd_drive drive;
char buf[IPBI2STR_BUFF_SIZE];

memset(&drive, 0, sizeof(struct amd_drive));
drive.ctx = device->cntrl->ctx;

lib_log(drive.ctx, LED_LOG_LEVEL_INFO, "\n");
lib_log(drive.ctx, LED_LOG_LEVEL_INFO, "Setting %s...",
ibpi2str(ibpi, buf, sizeof(buf)));
lib_log(drive.ctx, LED_LOG_LEVEL_INFO, "Setting %s...", ibpi2str(ibpi));

rc = _get_amd_ipmi_drive(device->cntrl_path, &drive);
if (rc)
Expand Down
4 changes: 1 addition & 3 deletions src/lib/amd_sgpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,12 @@ static int _set_ibpi(struct block_device *device, enum led_ibpi_pattern ibpi)
struct transmit_register tx_reg;
struct cache_entry *cache;
struct cache_entry cache_dup;
char buf[IPBI2STR_BUFF_SIZE];

memset(&drive, 0, sizeof(struct amd_drive));
drive.ctx = device->cntrl->ctx;

lib_log(drive.ctx, LED_LOG_LEVEL_INFO, "\n");
lib_log(drive.ctx, LED_LOG_LEVEL_INFO, "Setting %s...",
ibpi2str(ibpi, buf, sizeof(buf)));
lib_log(drive.ctx, LED_LOG_LEVEL_INFO, "Setting %s...", ibpi2str(ibpi));
lib_log(drive.ctx, LED_LOG_LEVEL_DEBUG, "\tdevice: ...%s",
strstr(device->sysfs_path, "/ata"));
lib_log(drive.ctx, LED_LOG_LEVEL_DEBUG, "\tbuffer: ...%s",
Expand Down
4 changes: 1 addition & 3 deletions src/lib/dellssd.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,9 @@ int dellssd_write(struct block_device *device, enum led_ibpi_pattern ibpi)
ibpi2val = get_by_ibpi(ibpi, ibpi2ssd, ARRAY_SIZE(ibpi2ssd));

if (ibpi2val->ibpi == LED_IBPI_PATTERN_UNKNOWN) {
char buf[IPBI2STR_BUFF_SIZE];

lib_log(device->cntrl->ctx, LED_LOG_LEVEL_INFO,
"SSD: Controller doesn't support %s pattern\n",
ibpi2str(ibpi, buf, sizeof(buf)));
"SSD: Controller doesn't support %s pattern\n", ibpi2str(ibpi));
__set_errno_and_return(EINVAL);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/include/led/libled.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ enum led_ibpi_pattern {
LED_IBPI_PATTERN_LOCATE_OFF = 11,
LED_IBPI_PATTERN_ADDED = 12,
LED_IBPI_PATTERN_REMOVED = 13,
LED_IBPI_PATTERN_LOCATE_AND_FAILED_DRIVE = 14,
LED_IBPI_PATTERN_LOCATE_AND_FAIL = 14,
/*
* Below are SES-2 codes. Note that by default most IBPI messages are
* translated into SES when needed but SES codes can be added also.
Expand Down
8 changes: 3 additions & 5 deletions src/lib/npem.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ status_t npem_set_slot(struct led_ctx *ctx, const char *sysfs_path, enum led_ibp
struct pci_dev *pdev = NULL;
struct pci_access *pacc = get_pci_access();
const struct ibpi2value *ibpi2val;
char buf[IPBI2STR_BUFF_SIZE];

u32 val;
u32 reg;
Expand All @@ -248,8 +247,7 @@ status_t npem_set_slot(struct led_ctx *ctx, const char *sysfs_path, enum led_ibp

if (ibpi2val->ibpi == LED_IBPI_PATTERN_UNKNOWN) {
lib_log(ctx, LED_LOG_LEVEL_INFO,
"NPEM: Controller doesn't support %s pattern\n",
ibpi2str(state, buf, sizeof(buf)));
"NPEM: Controller doesn't support %s pattern\n", ibpi2str(state));
return STATUS_INVALID_STATE;
}
cap = (u32)ibpi2val->value;
Expand All @@ -270,8 +268,8 @@ status_t npem_set_slot(struct led_ctx *ctx, const char *sysfs_path, enum led_ibp

if (!is_mask_set(pdev, PCI_NPEM_CAP_REG, cap)) {
lib_log(ctx, LED_LOG_LEVEL_INFO,
"NPEM: Controller %s doesn't support %s pattern\n",
sysfs_path, ibpi2str(state, buf, sizeof(buf)));
"NPEM: Controller %s doesn't support %s pattern\n", sysfs_path,
ibpi2str(state));
pci_free_dev(pdev);
pci_cleanup(pacc);
return STATUS_INVALID_STATE;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ses.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static enum led_ibpi_pattern ibpi_to_ses(enum led_ibpi_pattern ibpi)
return LED_SES_REQ_HOTSPARE;
case LED_IBPI_PATTERN_PFA:
return LED_SES_REQ_PRDFAIL;
case LED_IBPI_PATTERN_LOCATE_AND_FAILED_DRIVE:
case LED_IBPI_PATTERN_LOCATE_AND_FAIL:
return LED_SES_REQ_IDENT_AND_FAULT;
default:
return ibpi;
Expand Down Expand Up @@ -482,7 +482,7 @@ static void get_led_status(struct ses_pages *sp, int idx, enum led_ibpi_pattern
*led_status = LED_IBPI_PATTERN_NORMAL;

if ((desc_element->b2 & 0x02) && (desc_element->b3 & 0x60))
*led_status = LED_IBPI_PATTERN_LOCATE_AND_FAILED_DRIVE;
*led_status = LED_IBPI_PATTERN_LOCATE_AND_FAIL;
else if (desc_element->b2 & 0x02)
*led_status = LED_IBPI_PATTERN_LOCATE;
else if (desc_element->b3 & 0x60)
Expand Down
9 changes: 4 additions & 5 deletions src/lib/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,16 +452,15 @@ int scsi_smp_fill_buffer(struct block_device *device, enum led_ibpi_pattern ibpi
}

if (device->cntrl->isci_present && !ibpi2sgpio[ibpi].support_mask) {
char buf[IPBI2STR_BUFF_SIZE];
char *c = strrchr(device->sysfs_path, '/');

if (c++) {
lib_log(device->cntrl->ctx, LED_LOG_LEVEL_DEBUG,
"pattern %s not supported for device (/dev/%s)",
ibpi2str(ibpi, buf, sizeof(buf)), c);
"pattern %s not supported for device (/dev/%s)", ibpi2str(ibpi), c);
} else {
lib_log(device->cntrl->ctx, LED_LOG_LEVEL_DEBUG,
"pattern %s not supported for device %s",
ibpi2str(ibpi, buf, sizeof(buf)), device->sysfs_path);
"pattern %s not supported for device %s", ibpi2str(ibpi),
device->sysfs_path);
}
__set_errno_and_return(ENOTSUP);
}
Expand Down
4 changes: 1 addition & 3 deletions src/lib/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,11 @@ static int _is_failed_array(struct raid_device *raid)
*/
static void _set_block_state(struct block_device *block, enum led_ibpi_pattern ibpi)
{
char buf[IPBI2STR_BUFF_SIZE];
char *debug_dev = strrchr(block->sysfs_path, '/');
debug_dev = debug_dev ? debug_dev + 1 : block->sysfs_path;

lib_log(block->cntrl->ctx, LED_LOG_LEVEL_DEBUG,
"(%s): device: %s, state: %s", __func__, debug_dev,
ibpi2str(ibpi, buf, sizeof(buf)));
"(%s): device: %s, state: %s", __func__, debug_dev, ibpi2str(ibpi));
if (block->ibpi < ibpi)
block->ibpi = ibpi;
}
Expand Down
Loading
Loading