From 8e92d68db371124e2c4b088f2fb0a5be81a4799c Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Thu, 4 Jul 2024 11:48:18 +0200 Subject: [PATCH 1/9] Ledctl: add command to retrieve best controller Add new command to ledctl, which enables to print the best available controller for given device. Output from this can be helpful when user must specify controller in other ledctl commands. Fixes #189 Signed-off-by: Kinga Stefaniuk --- src/ledctl/ledctl.c | 28 ++++++++++++++++++++++++++++ src/lib/utils.c | 1 + src/lib/utils.h | 1 + 3 files changed, 30 insertions(+) diff --git a/src/ledctl/ledctl.c b/src/ledctl/ledctl.c index 7646cc6f..de1c8050 100644 --- a/src/ledctl/ledctl.c +++ b/src/ledctl/ledctl.c @@ -162,6 +162,7 @@ static int possible_params_modes[] = { OPT_SET_SLOT, OPT_LIST_SLOTS, OPT_LIST_CTRL, + OPT_BEST_CTRL, OPT_IBPI }; @@ -169,6 +170,11 @@ static int possible_params_list_ctrl[] = { COMMON_GETOPT_ARGS }; +static int possible_params_best_ctrl[] = { + OPT_DEVICE, + COMMON_GETOPT_ARGS +}; + static int possible_params_set_slot[] = { OPT_CNTRL_TYPE, OPT_DEVICE, @@ -541,6 +547,9 @@ void _cmdline_parse_modes(int argc, char *argv[], struct request *req) case 'L': req->chosen_opt = OPT_LIST_CTRL; break; + case 'B': + req->chosen_opt = OPT_BEST_CTRL; + break; case 'I': req->chosen_opt = OPT_IBPI; break; @@ -581,6 +590,10 @@ bool _setup_mode_options(struct request * const req, char **shortopts, struct op setup_options(longopts, shortopts, possible_params_list_ctrl, ARRAY_SIZE(possible_params_list_ctrl)); break; + case OPT_BEST_CTRL: + setup_options(longopts, shortopts, possible_params_best_ctrl, + ARRAY_SIZE(possible_params_best_ctrl)); + break; case OPT_IBPI: setup_options(longopts, shortopts, possible_params_ibpi, ARRAY_SIZE(possible_params_ibpi)); @@ -756,6 +769,13 @@ static led_status_t verify_request(struct led_ctx *ctx, struct request *req) { if (req->chosen_opt == OPT_LIST_CTRL) return LED_STATUS_SUCCESS; + if (req->chosen_opt == OPT_BEST_CTRL) { + if (!req->device[0]) { + log_error("Device is missing, aborting."); + return LED_STATUS_CMDLINE_ERROR; + } else + return LED_STATUS_SUCCESS; + } if (req->cntrl == LED_CNTRL_TYPE_UNKNOWN) { log_error("Invalid controller in the request."); return LED_STATUS_INVALID_CONTROLLER; @@ -858,6 +878,14 @@ led_status_t execute_request(struct led_ctx *ctx, struct request *req) if (req->chosen_opt == OPT_LIST_SLOTS) return list_slots(req->cntrl); + if (req->chosen_opt == OPT_BEST_CTRL) { + char device_path[PATH_MAX]; + + led_device_name_lookup(ctx, req->device, device_path); + printf("%s\n", led_cntrl_type_to_string( + led_is_management_supported(ctx, device_path))); + return STATUS_SUCCESS; + } if (req->chosen_opt == OPT_LIST_CTRL) { struct led_cntrl_list_entry *cntrl = NULL; diff --git a/src/lib/utils.c b/src/lib/utils.c index a6ee29ba..8b5ae867 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -573,6 +573,7 @@ struct option longopt_all[] = { [OPT_SLOT] = {"slot", required_argument, NULL, 'p'}, [OPT_STATE] = {"state", required_argument, NULL, 's'}, [OPT_PRINT_PARAM] = {"print", required_argument, NULL, 'r'}, + [OPT_BEST_CTRL] = {"best-controller", no_argument, NULL, 'B'}, [OPT_TEST] = {"test", no_argument, NULL, 'T'}, [OPT_IBPI] = {"ibpi", no_argument, NULL, 'I' }, [OPT_NULL_ELEMENT] = {NULL, no_argument, NULL, '\0'} diff --git a/src/lib/utils.h b/src/lib/utils.h index cfecd688..a7c91f7e 100644 --- a/src/lib/utils.h +++ b/src/lib/utils.h @@ -472,6 +472,7 @@ enum opt { OPT_STATE, OPT_PRINT_PARAM, OPT_IBPI, + OPT_BEST_CTRL, OPT_TEST, OPT_NULL_ELEMENT }; From 88325128cddd49e7b8341628ef3904aecada9902 Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Thu, 22 Aug 2024 15:31:12 +0200 Subject: [PATCH 2/9] tests: align tests and use --best-controller Add parameter tests for new command: --best-controller. Use new method to choose best controller for device. It is especially needed when VMD and NPEM are available on one platform. Skip IBPI test when drives are connected to better controller, than used to test. Test multipath drives only with best controller connected. Signed-off-by: Kinga Stefaniuk --- tests/ledctl/ledctl_cmd.py | 11 ++++++++++ tests/ledctl/parameters_test.py | 3 ++- tests/ledctl/slot_test.py | 38 ++++++++++++++++++--------------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/tests/ledctl/ledctl_cmd.py b/tests/ledctl/ledctl_cmd.py index f6a22e56..db248cf5 100644 --- a/tests/ledctl/ledctl_cmd.py +++ b/tests/ledctl/ledctl_cmd.py @@ -105,6 +105,17 @@ def get_slot_by_device(self, slot: Slot): ]).stdout return self.parse_slot_line(slot.cntrl_type, out) + def get_slot_by_device_cntrl(self, dev_node, cntrl): + out = self.run_ledctl_cmd_valid( + ["--get-slot", "--controller-type", cntrl, "--device", + dev_node]).stdout + return self.parse_slot_line(cntrl, out) + + def best_controller_by_device(self, dev_node): + result = self.run_ledctl_cmd_valid( + ["--best-controller", "--device", dev_node]).stdout + return result.rstrip() + def list_slots(self, controller_type): rc = [] out = self.run_ledctl_cmd_valid( diff --git a/tests/ledctl/parameters_test.py b/tests/ledctl/parameters_test.py index 32cbf59b..1da01757 100644 --- a/tests/ledctl/parameters_test.py +++ b/tests/ledctl/parameters_test.py @@ -33,7 +33,8 @@ def test_parameters_are_valid_long_test_flag(ledctl_binary): "-G -n vmd -p 1 -r state -T", "--get-slot --controller-type=vmd --slot=1 --print=state -T", "-S -n vmd -p 1 -s normal -T", - "--set-slot --controller-type=vmd --slot=1 --state=normal -T" + "--set-slot --controller-type=vmd --slot=1 --state=normal -T", + "-B -d /dev/nvme0n1 -T", "--best-controller --device /dev/nvme0n1 -T" ], ) def test_parameters_are_valid_short_test_flag(ledctl_binary, diff --git a/tests/ledctl/slot_test.py b/tests/ledctl/slot_test.py index 21a82c02..be0d4ecb 100644 --- a/tests/ledctl/slot_test.py +++ b/tests/ledctl/slot_test.py @@ -27,6 +27,14 @@ def get_slots_with_device_or_skip(cmd: LedctlCmd, cntrl): return slots_with_device_node +def filter_by_best_controller(cmd: LedctlCmd, slots_to_test): + for slot in slots_to_test: + best_cntrl = cmd.best_controller_by_device(slot.device_node) + if best_cntrl != slot.cntrl_type: + slots_to_test.remove(slot) + return slots_to_test + + def verify_state(slot, current, expected, msg): if slot.cntrl_type == "SCSI" and expected == "rebuild": # No good way to validate this one as read value won't match what we sent down. @@ -43,9 +51,15 @@ def test_ibpi(ledctl_binary, slot_filters, controller_filters, cntrl): """ cmd = LedctlCmd(ledctl_binary, slot_filters, controller_filters) - slots_with_device_node = get_slots_with_device_or_skip(cmd, cntrl) + slots_to_test = get_slots_with_device_or_skip(cmd, cntrl) + slots_to_test = filter_by_best_controller(cmd, slots_to_test) - for slot in slots_with_device_node: + if not slots_to_test: + pytest.skip( + "Devices detected but this is not primary controller for any drive, skipping" + ) + + for slot in slots_to_test: for state in LedctlCmd.base_states: cmd.set_ibpi(slot.device_node, state) cur = cmd.get_slot(slot) @@ -105,9 +119,8 @@ def test_set_slot_by_device(ledctl_binary, slot_filters, controller_filters, slot_set_and_get_by_device_all(cmd, slot) -@pytest.mark.parametrize("cntrl", ["VMD", "NPEM"]) -def test_nvme_multipath_drives(ledctl_binary, slot_filters, controller_filters, - cntrl): +def test_nvme_multipath_drives(ledctl_binary, slot_filters, + controller_filters): """ Special test for multipath drives using both set methods and get via device. We need to check if ledctl provides nvme multipath minimal support. @@ -118,15 +131,9 @@ def test_nvme_multipath_drives(ledctl_binary, slot_filters, controller_filters, if len(mp_drives) == 0: pytest.skip("No nvme multipath drives found") - slots_with_device_node = get_slots_with_device_or_skip(cmd, cntrl) - any_found = False - - for slot in slots_with_device_node: - if slot.device_node not in mp_drives: - continue - any_found = True - - LOGGER.debug(f"Found nvme multipath drive {slot}") + for mp_drive in mp_drives: + mp_cntrl = cmd.best_controller_by_device(mp_drive) + slot = cmd.get_slot_by_device_cntrl(mp_drive, mp_cntrl) for state in cmd.base_states: cmd.set_ibpi(slot.device_node, state) @@ -137,6 +144,3 @@ def test_nvme_multipath_drives(ledctl_binary, slot_filters, controller_filters, ) slot_set_and_get_by_device_all(cmd, slot) - - if not any_found: - pytest.skip("Multipath drives are not connected to tested controller") From 150c7a2229c019c10b86388207e97d1fc787e86f Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Tue, 10 Sep 2024 13:15:26 +0200 Subject: [PATCH 3/9] ledctl_cmd: check if controller is not filtered out Add checking if controller used to find slot is not filtered out. It is needed to be checked for tests which are using drives instead of slots. Signed-off-by: Kinga Stefaniuk --- tests/ledctl/ledctl_cmd.py | 5 +++++ tests/ledctl/slot_test.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/tests/ledctl/ledctl_cmd.py b/tests/ledctl/ledctl_cmd.py index db248cf5..d0e54738 100644 --- a/tests/ledctl/ledctl_cmd.py +++ b/tests/ledctl/ledctl_cmd.py @@ -106,6 +106,11 @@ def get_slot_by_device(self, slot: Slot): return self.parse_slot_line(slot.cntrl_type, out) def get_slot_by_device_cntrl(self, dev_node, cntrl): + # While using this method controllers may be not filtered out. + # Do not return slot for controller removed from test. + if cntrl not in self.slot_ctrls: + return None + out = self.run_ledctl_cmd_valid( ["--get-slot", "--controller-type", cntrl, "--device", dev_node]).stdout diff --git a/tests/ledctl/slot_test.py b/tests/ledctl/slot_test.py index be0d4ecb..c6a6dae8 100644 --- a/tests/ledctl/slot_test.py +++ b/tests/ledctl/slot_test.py @@ -134,6 +134,8 @@ def test_nvme_multipath_drives(ledctl_binary, slot_filters, for mp_drive in mp_drives: mp_cntrl = cmd.best_controller_by_device(mp_drive) slot = cmd.get_slot_by_device_cntrl(mp_drive, mp_cntrl) + if slot is None: + continue for state in cmd.base_states: cmd.set_ibpi(slot.device_node, state) From 73d268af38e5592b562c89455f2277961cc6d5e6 Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Wed, 11 Sep 2024 10:48:44 +0200 Subject: [PATCH 4/9] Fixes after review - Print "unsupported controller type" instead of "?" when ledctl is not able to find supported controller for device - Add help option for "--best-controller" command - Align tests to new help mode Signed-off-by: Kinga Stefaniuk --- src/ledctl/help.c | 10 ++++++++++ src/ledctl/ledctl.c | 10 ++++++++-- tests/ledctl/parameters_test.py | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ledctl/help.c b/src/ledctl/help.c index 71919341..b4a29b8d 100644 --- a/src/ledctl/help.c +++ b/src/ledctl/help.c @@ -81,6 +81,12 @@ static struct help_option LIST_CTRL_HELP_OPTS[] = { HELP_OPTION_LOG_LEVEL, }; +static struct help_option BEST_CTRL_HELP_OPTS[] = { + HELP_OPTION_DEVICE, + HELP_OPTION_HELP, + HELP_OPTION_LOG_LEVEL, +}; + struct help_mode { enum opt option_id; struct option *opt; @@ -121,6 +127,9 @@ static struct help_mode modes[] = { HELP_MODE(SET_SLOT, "Set given state for given slot or device under the given controller.\n" "Options \"--slot\" and \"--device\" cannot be used simultaneously."), + + HELP_MODE(BEST_CTRL, + "Print the controller with the highest priority for given device."), }; /** @@ -285,6 +294,7 @@ static struct help_option GENERAL_HELP_OPTS[] = { {NULL, "Print slot details for device/slot.", &longopt_all[OPT_GET_SLOT]}, {NULL, "Indicate IBPI mode, it is used as default.", &longopt_all[OPT_IBPI]}, {NULL, "Display list of controllers recognizable by ledctl.", &longopt_all[OPT_LIST_CTRL]}, + {NULL, "Print best supported controller for device.", &longopt_all[OPT_BEST_CTRL]}, {NULL, "Print all slots for a controller requested.", &longopt_all[OPT_LIST_SLOTS]}, {NULL, "Set state for slot/device by controller requested.", &longopt_all[OPT_SET_SLOT]} }; diff --git a/src/ledctl/ledctl.c b/src/ledctl/ledctl.c index de1c8050..5a86902b 100644 --- a/src/ledctl/ledctl.c +++ b/src/ledctl/ledctl.c @@ -879,11 +879,17 @@ led_status_t execute_request(struct led_ctx *ctx, struct request *req) if (req->chosen_opt == OPT_LIST_SLOTS) return list_slots(req->cntrl); if (req->chosen_opt == OPT_BEST_CTRL) { + enum led_cntrl_type cntrl_type; char device_path[PATH_MAX]; led_device_name_lookup(ctx, req->device, device_path); - printf("%s\n", led_cntrl_type_to_string( - led_is_management_supported(ctx, device_path))); + cntrl_type = led_is_management_supported(ctx, device_path); + + if (cntrl_type == LED_CNTRL_TYPE_UNKNOWN) + printf("Unsupported controller type\n"); + else + printf("%s\n", led_cntrl_type_to_string(cntrl_type)); + return STATUS_SUCCESS; } diff --git a/tests/ledctl/parameters_test.py b/tests/ledctl/parameters_test.py index 1da01757..af834205 100644 --- a/tests/ledctl/parameters_test.py +++ b/tests/ledctl/parameters_test.py @@ -153,7 +153,8 @@ def parse_help(lines): "--help", "-h", "--help --badflag", "-hd", "-h -s", "--set-slot --help", "-S -h --badflag", "-Sh --badflag", "--get-slot --help", "-Ghb", "--list-controllers --help", - "--ibpi --help", "--list-slots --help", "-L -h" + "--ibpi --help", "--list-slots --help", "-L -h", + "--best-controller --help", "-Bh", ], ) # Check formatting, header and footer. From d75da3a5055216c2c20542faaac23de1d51d9138 Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Wed, 11 Sep 2024 10:52:59 +0200 Subject: [PATCH 5/9] ledctl.pod: add --best-controller to manual Describe "--best-controller" option in ledctl manual. Signed-off-by: Kinga Stefaniuk --- doc/ledctl.pod | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/ledctl.pod b/doc/ledctl.pod index 92ca1d21..f2f2044f 100644 --- a/doc/ledctl.pod +++ b/doc/ledctl.pod @@ -306,6 +306,11 @@ Suppresses default behavior, changes state only on devices listed in CLI. It is Prints information (system path and type) of all controllers detected. +=head2 B<-B> or B<--best-controller> + +Prints information about controller supported for this device with the highest priority. +Must be followed by B<--device>, for which controller will be printed. + =head2 B<-P> or B<--list-slots> Prints all slots for the controller type. Must be followed by B<--controller-type>. From ad160d4cce1262bb2cce2acf738594e175aa8b0c Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Wed, 11 Sep 2024 11:28:22 +0200 Subject: [PATCH 6/9] parameters_test: fix formatting Fix formatting error reported by YAPF. Signed-off-by: Kinga Stefaniuk --- tests/ledctl/parameters_test.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/ledctl/parameters_test.py b/tests/ledctl/parameters_test.py index af834205..e95b4e3f 100644 --- a/tests/ledctl/parameters_test.py +++ b/tests/ledctl/parameters_test.py @@ -150,11 +150,22 @@ def parse_help(lines): @pytest.mark.parametrize( "help_cmd", [ - "--help", "-h", "--help --badflag", "-hd", "-h -s", - "--set-slot --help", "-S -h --badflag", "-Sh --badflag", - "--get-slot --help", "-Ghb", "--list-controllers --help", - "--ibpi --help", "--list-slots --help", "-L -h", - "--best-controller --help", "-Bh", + "--help", + "-h", + "--help --badflag", + "-hd", + "-h -s", + "--set-slot --help", + "-S -h --badflag", + "-Sh --badflag", + "--get-slot --help", + "-Ghb", + "--list-controllers --help", + "--ibpi --help", + "--list-slots --help", + "-L -h", + "--best-controller --help", + "-Bh", ], ) # Check formatting, header and footer. From 355e00c07b6c8efcf054a78b9f9dc8fcd64648dc Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Wed, 18 Sep 2024 12:09:36 +0200 Subject: [PATCH 7/9] Fixes after review - change message for device without best controller Signed-off-by: Kinga Stefaniuk --- src/ledctl/help.c | 2 +- src/ledctl/ledctl.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ledctl/help.c b/src/ledctl/help.c index b4a29b8d..c94b2108 100644 --- a/src/ledctl/help.c +++ b/src/ledctl/help.c @@ -294,7 +294,7 @@ static struct help_option GENERAL_HELP_OPTS[] = { {NULL, "Print slot details for device/slot.", &longopt_all[OPT_GET_SLOT]}, {NULL, "Indicate IBPI mode, it is used as default.", &longopt_all[OPT_IBPI]}, {NULL, "Display list of controllers recognizable by ledctl.", &longopt_all[OPT_LIST_CTRL]}, - {NULL, "Print best supported controller for device.", &longopt_all[OPT_BEST_CTRL]}, + {NULL, "Print the best supported controller for device.", &longopt_all[OPT_BEST_CTRL]}, {NULL, "Print all slots for a controller requested.", &longopt_all[OPT_LIST_SLOTS]}, {NULL, "Set state for slot/device by controller requested.", &longopt_all[OPT_SET_SLOT]} }; diff --git a/src/ledctl/ledctl.c b/src/ledctl/ledctl.c index 5a86902b..6b2e48f0 100644 --- a/src/ledctl/ledctl.c +++ b/src/ledctl/ledctl.c @@ -886,7 +886,7 @@ led_status_t execute_request(struct led_ctx *ctx, struct request *req) cntrl_type = led_is_management_supported(ctx, device_path); if (cntrl_type == LED_CNTRL_TYPE_UNKNOWN) - printf("Unsupported controller type\n"); + printf("Unable to find controller for device\n"); else printf("%s\n", led_cntrl_type_to_string(cntrl_type)); From cd2be1fa534b879384e11eb50891f73e275a2cdd Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Mon, 23 Sep 2024 09:34:28 +0200 Subject: [PATCH 8/9] Fixes after review Update ledctl.pod. Signed-off-by: Kinga Stefaniuk --- doc/ledctl.pod | 7 ++++++- tests/ledctl/slot_test.py | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/ledctl.pod b/doc/ledctl.pod index f2f2044f..7eb532f8 100644 --- a/doc/ledctl.pod +++ b/doc/ledctl.pod @@ -308,7 +308,12 @@ Prints information (system path and type) of all controllers detected. =head2 B<-B> or B<--best-controller> -Prints information about controller supported for this device with the highest priority. +There is a possibility that device is supported by more than one controller (e.g. NPEM and VMD). +In that case, this command can be used to query ledctl to return preferred controller type. +The returned controller type is used by subset of routines which not taking controller type +directly (ledctl IBPI mode, ledmon daemon). + +Prints preferred controller type which should be used to control LED for this device. Must be followed by B<--device>, for which controller will be printed. =head2 B<-P> or B<--list-slots> diff --git a/tests/ledctl/slot_test.py b/tests/ledctl/slot_test.py index c6a6dae8..8c6d7674 100644 --- a/tests/ledctl/slot_test.py +++ b/tests/ledctl/slot_test.py @@ -28,11 +28,12 @@ def get_slots_with_device_or_skip(cmd: LedctlCmd, cntrl): def filter_by_best_controller(cmd: LedctlCmd, slots_to_test): + filtered_slots = [] for slot in slots_to_test: best_cntrl = cmd.best_controller_by_device(slot.device_node) - if best_cntrl != slot.cntrl_type: - slots_to_test.remove(slot) - return slots_to_test + if best_cntrl == slot.cntrl_type: + filtered_slots.append(slot) + return filtered_slots def verify_state(slot, current, expected, msg): From bc62780287f306c78db7ff0aea7833af2c8e236d Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Tue, 8 Oct 2024 15:17:36 +0200 Subject: [PATCH 9/9] Rename best to default Rename --best-controller to --default-controller. Signed-off-by: Kinga Stefaniuk --- doc/ledctl.pod | 6 +++--- src/ledctl/help.c | 7 ++++--- src/ledctl/ledctl.c | 19 ++++++++++--------- src/lib/utils.c | 2 +- src/lib/utils.h | 2 +- tests/ledctl/ledctl_cmd.py | 4 ++-- tests/ledctl/parameters_test.py | 5 +++-- tests/ledctl/slot_test.py | 10 +++++----- 8 files changed, 29 insertions(+), 26 deletions(-) diff --git a/doc/ledctl.pod b/doc/ledctl.pod index 7eb532f8..3e35a06c 100644 --- a/doc/ledctl.pod +++ b/doc/ledctl.pod @@ -306,12 +306,12 @@ Suppresses default behavior, changes state only on devices listed in CLI. It is Prints information (system path and type) of all controllers detected. -=head2 B<-B> or B<--best-controller> +=head2 B<-B> or B<--default-controller> There is a possibility that device is supported by more than one controller (e.g. NPEM and VMD). In that case, this command can be used to query ledctl to return preferred controller type. -The returned controller type is used by subset of routines which not taking controller type -directly (ledctl IBPI mode, ledmon daemon). +The returned controller type is used by subset of routines which do not take controller type +directly (e.g. --get-slot, --list-slots, --set-slot). Prints preferred controller type which should be used to control LED for this device. Must be followed by B<--device>, for which controller will be printed. diff --git a/src/ledctl/help.c b/src/ledctl/help.c index c94b2108..bb284b4a 100644 --- a/src/ledctl/help.c +++ b/src/ledctl/help.c @@ -81,7 +81,7 @@ static struct help_option LIST_CTRL_HELP_OPTS[] = { HELP_OPTION_LOG_LEVEL, }; -static struct help_option BEST_CTRL_HELP_OPTS[] = { +static struct help_option DEFAULT_CTRL_HELP_OPTS[] = { HELP_OPTION_DEVICE, HELP_OPTION_HELP, HELP_OPTION_LOG_LEVEL, @@ -128,7 +128,7 @@ static struct help_mode modes[] = { "Set given state for given slot or device under the given controller.\n" "Options \"--slot\" and \"--device\" cannot be used simultaneously."), - HELP_MODE(BEST_CTRL, + HELP_MODE(DEFAULT_CTRL, "Print the controller with the highest priority for given device."), }; @@ -294,7 +294,8 @@ static struct help_option GENERAL_HELP_OPTS[] = { {NULL, "Print slot details for device/slot.", &longopt_all[OPT_GET_SLOT]}, {NULL, "Indicate IBPI mode, it is used as default.", &longopt_all[OPT_IBPI]}, {NULL, "Display list of controllers recognizable by ledctl.", &longopt_all[OPT_LIST_CTRL]}, - {NULL, "Print the best supported controller for device.", &longopt_all[OPT_BEST_CTRL]}, + {NULL, "Print the preferred supported controller for device.", + &longopt_all[OPT_DEFAULT_CTRL]}, {NULL, "Print all slots for a controller requested.", &longopt_all[OPT_LIST_SLOTS]}, {NULL, "Set state for slot/device by controller requested.", &longopt_all[OPT_SET_SLOT]} }; diff --git a/src/ledctl/ledctl.c b/src/ledctl/ledctl.c index 6b2e48f0..30adc747 100644 --- a/src/ledctl/ledctl.c +++ b/src/ledctl/ledctl.c @@ -162,7 +162,7 @@ static int possible_params_modes[] = { OPT_SET_SLOT, OPT_LIST_SLOTS, OPT_LIST_CTRL, - OPT_BEST_CTRL, + OPT_DEFAULT_CTRL, OPT_IBPI }; @@ -170,7 +170,7 @@ static int possible_params_list_ctrl[] = { COMMON_GETOPT_ARGS }; -static int possible_params_best_ctrl[] = { +static int possible_params_default_ctrl[] = { OPT_DEVICE, COMMON_GETOPT_ARGS }; @@ -548,7 +548,7 @@ void _cmdline_parse_modes(int argc, char *argv[], struct request *req) req->chosen_opt = OPT_LIST_CTRL; break; case 'B': - req->chosen_opt = OPT_BEST_CTRL; + req->chosen_opt = OPT_DEFAULT_CTRL; break; case 'I': req->chosen_opt = OPT_IBPI; @@ -590,9 +590,9 @@ bool _setup_mode_options(struct request * const req, char **shortopts, struct op setup_options(longopts, shortopts, possible_params_list_ctrl, ARRAY_SIZE(possible_params_list_ctrl)); break; - case OPT_BEST_CTRL: - setup_options(longopts, shortopts, possible_params_best_ctrl, - ARRAY_SIZE(possible_params_best_ctrl)); + case OPT_DEFAULT_CTRL: + setup_options(longopts, shortopts, possible_params_default_ctrl, + ARRAY_SIZE(possible_params_default_ctrl)); break; case OPT_IBPI: setup_options(longopts, shortopts, possible_params_ibpi, @@ -769,7 +769,7 @@ static led_status_t verify_request(struct led_ctx *ctx, struct request *req) { if (req->chosen_opt == OPT_LIST_CTRL) return LED_STATUS_SUCCESS; - if (req->chosen_opt == OPT_BEST_CTRL) { + if (req->chosen_opt == OPT_DEFAULT_CTRL) { if (!req->device[0]) { log_error("Device is missing, aborting."); return LED_STATUS_CMDLINE_ERROR; @@ -878,7 +878,7 @@ led_status_t execute_request(struct led_ctx *ctx, struct request *req) if (req->chosen_opt == OPT_LIST_SLOTS) return list_slots(req->cntrl); - if (req->chosen_opt == OPT_BEST_CTRL) { + if (req->chosen_opt == OPT_DEFAULT_CTRL) { enum led_cntrl_type cntrl_type; char device_path[PATH_MAX]; @@ -886,7 +886,8 @@ led_status_t execute_request(struct led_ctx *ctx, struct request *req) cntrl_type = led_is_management_supported(ctx, device_path); if (cntrl_type == LED_CNTRL_TYPE_UNKNOWN) - printf("Unable to find controller for device\n"); + lib_log(ctx, LED_LOG_LEVEL_ERROR, + "Unable to determine controller for device\n"); else printf("%s\n", led_cntrl_type_to_string(cntrl_type)); diff --git a/src/lib/utils.c b/src/lib/utils.c index 8b5ae867..bad35eb4 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -573,7 +573,7 @@ struct option longopt_all[] = { [OPT_SLOT] = {"slot", required_argument, NULL, 'p'}, [OPT_STATE] = {"state", required_argument, NULL, 's'}, [OPT_PRINT_PARAM] = {"print", required_argument, NULL, 'r'}, - [OPT_BEST_CTRL] = {"best-controller", no_argument, NULL, 'B'}, + [OPT_DEFAULT_CTRL] = {"default-controller", no_argument, NULL, 'B'}, [OPT_TEST] = {"test", no_argument, NULL, 'T'}, [OPT_IBPI] = {"ibpi", no_argument, NULL, 'I' }, [OPT_NULL_ELEMENT] = {NULL, no_argument, NULL, '\0'} diff --git a/src/lib/utils.h b/src/lib/utils.h index a7c91f7e..f3b9a054 100644 --- a/src/lib/utils.h +++ b/src/lib/utils.h @@ -472,7 +472,7 @@ enum opt { OPT_STATE, OPT_PRINT_PARAM, OPT_IBPI, - OPT_BEST_CTRL, + OPT_DEFAULT_CTRL, OPT_TEST, OPT_NULL_ELEMENT }; diff --git a/tests/ledctl/ledctl_cmd.py b/tests/ledctl/ledctl_cmd.py index d0e54738..12a1b336 100644 --- a/tests/ledctl/ledctl_cmd.py +++ b/tests/ledctl/ledctl_cmd.py @@ -116,9 +116,9 @@ def get_slot_by_device_cntrl(self, dev_node, cntrl): dev_node]).stdout return self.parse_slot_line(cntrl, out) - def best_controller_by_device(self, dev_node): + def default_controller_by_device(self, dev_node): result = self.run_ledctl_cmd_valid( - ["--best-controller", "--device", dev_node]).stdout + ["--default-controller", "--device", dev_node]).stdout return result.rstrip() def list_slots(self, controller_type): diff --git a/tests/ledctl/parameters_test.py b/tests/ledctl/parameters_test.py index e95b4e3f..935accaf 100644 --- a/tests/ledctl/parameters_test.py +++ b/tests/ledctl/parameters_test.py @@ -34,7 +34,8 @@ def test_parameters_are_valid_long_test_flag(ledctl_binary): "--get-slot --controller-type=vmd --slot=1 --print=state -T", "-S -n vmd -p 1 -s normal -T", "--set-slot --controller-type=vmd --slot=1 --state=normal -T", - "-B -d /dev/nvme0n1 -T", "--best-controller --device /dev/nvme0n1 -T" + "-B -d /dev/nvme0n1 -T", + "--default-controller --device /dev/nvme0n1 -T" ], ) def test_parameters_are_valid_short_test_flag(ledctl_binary, @@ -164,7 +165,7 @@ def parse_help(lines): "--ibpi --help", "--list-slots --help", "-L -h", - "--best-controller --help", + "--default-controller --help", "-Bh", ], ) diff --git a/tests/ledctl/slot_test.py b/tests/ledctl/slot_test.py index 8c6d7674..9188b554 100644 --- a/tests/ledctl/slot_test.py +++ b/tests/ledctl/slot_test.py @@ -27,11 +27,11 @@ def get_slots_with_device_or_skip(cmd: LedctlCmd, cntrl): return slots_with_device_node -def filter_by_best_controller(cmd: LedctlCmd, slots_to_test): +def filter_by_default_controller(cmd: LedctlCmd, slots_to_test): filtered_slots = [] for slot in slots_to_test: - best_cntrl = cmd.best_controller_by_device(slot.device_node) - if best_cntrl == slot.cntrl_type: + default_cntrl = cmd.default_controller_by_device(slot.device_node) + if default_cntrl == slot.cntrl_type: filtered_slots.append(slot) return filtered_slots @@ -53,7 +53,7 @@ def test_ibpi(ledctl_binary, slot_filters, controller_filters, cntrl): cmd = LedctlCmd(ledctl_binary, slot_filters, controller_filters) slots_to_test = get_slots_with_device_or_skip(cmd, cntrl) - slots_to_test = filter_by_best_controller(cmd, slots_to_test) + slots_to_test = filter_by_default_controller(cmd, slots_to_test) if not slots_to_test: pytest.skip( @@ -133,7 +133,7 @@ def test_nvme_multipath_drives(ledctl_binary, slot_filters, pytest.skip("No nvme multipath drives found") for mp_drive in mp_drives: - mp_cntrl = cmd.best_controller_by_device(mp_drive) + mp_cntrl = cmd.default_controller_by_device(mp_drive) slot = cmd.get_slot_by_device_cntrl(mp_drive, mp_cntrl) if slot is None: continue