From af99efaab265935c6a09f888ad685fd3769f6c86 Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 14:37:44 +0100 Subject: [PATCH] tunedasd: Implement zsh and bash autocompletion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add generation of shell autocompletion scripts. Acked-by: Steffen Eiden Reviewed-by: Jan Höppner Signed-off-by: Szabina Korbai Signed-off-by: Jan Höppner --- .gitignore | 2 + tunedasd/include/tunedasd_cli.h | 104 +++++++++++++++++++ tunedasd/src/Makefile | 5 + tunedasd/src/autocompletion_generator_host.c | 16 +++ tunedasd/src/tunedasd.c | 93 +---------------- 5 files changed, 128 insertions(+), 92 deletions(-) create mode 100644 tunedasd/include/tunedasd_cli.h create mode 100644 tunedasd/src/autocompletion_generator_host.c diff --git a/.gitignore b/.gitignore index 2d6920fc..5453275d 100644 --- a/.gitignore +++ b/.gitignore @@ -112,6 +112,8 @@ systemd/cpacfstatsd.service systemd/iucvtty-login@.service systemd/ttyrun-getty@.service tunedasd/src/tunedasd +tunedasd/src/_tunedasd +tunedasd/src/tunedasd.bash vmcp/vmcp vmur/vmur zconf/chp/chchp diff --git a/tunedasd/include/tunedasd_cli.h b/tunedasd/include/tunedasd_cli.h new file mode 100644 index 00000000..af7e29d5 --- /dev/null +++ b/tunedasd/include/tunedasd_cli.h @@ -0,0 +1,104 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef TUNEDASD_CLI_H +#define TUNEDASD_CLI_H + +#include "lib/util_opt.h" + +/* Defines for options with no short command */ +#define OPT_PATH_RESET_ALL 128 +#define OPT_ENABLE_STATS 129 +#define OPT_DISABLE_STATS 130 + +static struct util_opt opt_vec[] = { + UTIL_OPT_SECTION("CACHING MODES (ECKD ONLY)"), + { + .option = { "cache", required_argument, NULL, 'c' }, + .argument = "BEHAVIOUR", + .desc = "Specify caching behaviour on storage server: " + "normal, bypass, inhibit, sequential, prestage, or record", + }, + { + .option = { "no_cyl", required_argument, NULL, 'n' }, + .argument = "NUM", + .desc = "NUM cylinders to be cached (only valid with -c/--cache)", + }, + { + .option = { "get_cache", no_argument, NULL, 'g' }, + .desc = "Get current storage server caching behaviour", + }, + UTIL_OPT_SECTION("RESERVE / RELEASE"), + { + .option = { "release", no_argument, NULL, 'L' }, + .desc = "Release device", + }, + { + .option = { "slock", no_argument, NULL, 'O' }, + .desc = "Unconditional reservce device\n" + "NOTE: Use with care, this breaks an existing lock", + }, + { + .option = { "query_reserve", no_argument, NULL, 'Q' }, + .desc = "Print reserve status of device", + }, + { + .option = { "reserve", no_argument, NULL, 'S' }, + .desc = "Reserve device", + }, + UTIL_OPT_SECTION("PERFORMANCE STATISTICS"), + { + .option = { + "enable-stats", no_argument, NULL, OPT_ENABLE_STATS + }, + .desc = "Enable performance statistics globally", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { + "disable-stats", no_argument, NULL, OPT_DISABLE_STATS + }, + .desc = "Disable performance statistics globally", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "prof_item", required_argument, NULL, 'I' }, + .argument = "ROW", + .desc = "Print single profile item: reqs, sects, sizes, total, " + "totsect, start, irq, irqsect, end, or queue", + }, + { + .option = { "profile", no_argument, NULL, 'P' }, + .desc = "Print profile info of device", + }, + { + .option = { "reset_prof", no_argument, NULL, 'R' }, + .desc = "Reset profile info of device", + }, + UTIL_OPT_SECTION("MISC"), + { + .option = { "path_reset", required_argument, NULL, 'p' }, + .argument = "CHPID", + .desc = "Reset channel path CHPID of a device", + }, + { + .option = { + "path_reset_all", no_argument, NULL, OPT_PATH_RESET_ALL + }, + .desc = "Reset all channel paths of a device", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "copy-pair-swap", required_argument, NULL, 's' }, + .argument = "COPY_PAIR", + .desc = "Swap a specified, comma separated copy pair.", + }, + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END +}; + +#endif diff --git a/tunedasd/src/Makefile b/tunedasd/src/Makefile index 48043f7c..4c85b653 100644 --- a/tunedasd/src/Makefile +++ b/tunedasd/src/Makefile @@ -1,5 +1,10 @@ include ../../common.mak +zsh-completions = _tunedasd +bash-completions = tunedasd.bash + +include ../../common_autocomp.mak + ALL_CPPFLAGS += -I../include libs = $(rootdir)/libdasd/libdasd.a \ diff --git a/tunedasd/src/autocompletion_generator_host.c b/tunedasd/src/autocompletion_generator_host.c new file mode 100644 index 00000000..eb632dab --- /dev/null +++ b/tunedasd/src/autocompletion_generator_host.c @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "../include/tunedasd_cli.h" + +int main(void) +{ + generate_autocomp(opt_vec, "tunedasd"); + + return 0; +} diff --git a/tunedasd/src/tunedasd.c b/tunedasd/src/tunedasd.c index 84a20a37..a91a8d82 100644 --- a/tunedasd/src/tunedasd.c +++ b/tunedasd/src/tunedasd.c @@ -21,6 +21,7 @@ #include "disk.h" #include "tunedasd.h" +#include "tunedasd_cli.h" static const struct util_prg prg = { .desc = "Adjust tunable DASD parameters. More than one DEVICE node can " @@ -36,98 +37,6 @@ static const struct util_prg prg = { } }; -/* Defines for options with no short command */ -#define OPT_PATH_RESET_ALL 128 -#define OPT_ENABLE_STATS 129 -#define OPT_DISABLE_STATS 130 - -static struct util_opt opt_vec[] = { - UTIL_OPT_SECTION("CACHING MODES (ECKD ONLY)"), - { - .option = { "cache", required_argument, NULL, 'c' }, - .argument = "BEHAVIOUR", - .desc = "Specify caching behaviour on storage server: " - "normal, bypass, inhibit, sequential, prestage, or record", - }, - { - .option = { "no_cyl", required_argument, NULL, 'n' }, - .argument = "NUM", - .desc = "NUM cylinders to be cached (only valid with -c/--cache)", - }, - { - .option = { "get_cache", no_argument, NULL, 'g' }, - .desc = "Get current storage server caching behaviour", - }, - UTIL_OPT_SECTION("RESERVE / RELEASE"), - { - .option = { "release", no_argument, NULL, 'L' }, - .desc = "Release device", - }, - { - .option = { "slock", no_argument, NULL, 'O' }, - .desc = "Unconditional reservce device\n" - "NOTE: Use with care, this breaks an existing lock", - }, - { - .option = { "query_reserve", no_argument, NULL, 'Q' }, - .desc = "Print reserve status of device", - }, - { - .option = { "reserve", no_argument, NULL, 'S' }, - .desc = "Reserve device", - }, - UTIL_OPT_SECTION("PERFORMANCE STATISTICS"), - { - .option = { - "enable-stats", no_argument, NULL, OPT_ENABLE_STATS - }, - .desc = "Enable performance statistics globally", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { - "disable-stats", no_argument, NULL, OPT_DISABLE_STATS - }, - .desc = "Disable performance statistics globally", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "prof_item", required_argument, NULL, 'I' }, - .argument = "ROW", - .desc = "Print single profile item: reqs, sects, sizes, total, " - "totsect, start, irq, irqsect, end, or queue", - }, - { - .option = { "profile", no_argument, NULL, 'P' }, - .desc = "Print profile info of device", - }, - { - .option = { "reset_prof", no_argument, NULL, 'R' }, - .desc = "Reset profile info of device", - }, - UTIL_OPT_SECTION("MISC"), - { - .option = { "path_reset", required_argument, NULL, 'p' }, - .argument = "CHPID", - .desc = "Reset channel path CHPID of a device", - }, - { - .option = { - "path_reset_all", no_argument, NULL, OPT_PATH_RESET_ALL - }, - .desc = "Reset all channel paths of a device", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "copy-pair-swap", required_argument, NULL, 's' }, - .argument = "COPY_PAIR", - .desc = "Swap a specified, comma separated copy pair.", - }, - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END -}; - #define CMD_KEYWORD_NUM 17 #define DEVICES_NUM 256