From a5af5bcf70fe721e92e6e6d8c11a73e8ddb5c6c8 Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Mon, 9 Mar 2026 10:11:18 +0100 Subject: [PATCH] zcrypt: 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 to chzcrypt, lszcrypt and zcryptstats. Acked-by: Steffen Eiden Reviewed-by: Jan Höppner Signed-off-by: Szabina Korbai Signed-off-by: Jan Höppner --- .gitignore | 6 ++ zconf/zcrypt/Makefile | 5 + zconf/zcrypt/autocompletion_generator_host.c | 20 ++++ zconf/zcrypt/chzcrypt.c | 92 +--------------- zconf/zcrypt/chzcrypt_cli.h | 101 +++++++++++++++++ zconf/zcrypt/lszcrypt.c | 65 +---------- zconf/zcrypt/lszcrypt_cli.h | 74 +++++++++++++ zconf/zcrypt/zcryptstats.c | 100 +---------------- zconf/zcrypt/zcryptstats_cli.h | 108 +++++++++++++++++++ 9 files changed, 321 insertions(+), 250 deletions(-) create mode 100644 zconf/zcrypt/autocompletion_generator_host.c create mode 100644 zconf/zcrypt/chzcrypt_cli.h create mode 100644 zconf/zcrypt/lszcrypt_cli.h create mode 100644 zconf/zcrypt/zcryptstats_cli.h diff --git a/.gitignore b/.gitignore index f7cfc1e4..36a2c851 100644 --- a/.gitignore +++ b/.gitignore @@ -137,9 +137,15 @@ zconf/scm/lsscm zconf/scm/_lsscm zconf/scm/lsscm.bash zconf/zcrypt/chzcrypt +zconf/zcrypt/_chzcrypt +zconf/zcrypt/chzcrypt.bash zconf/zcrypt/lszcrypt +zconf/zcrypt/_lszcrypt +zconf/zcrypt/lszcrypt.bash zconf/zcrypt/zcryptctl zconf/zcrypt/zcryptstats +zconf/zcrypt/_zcryptstats +zconf/zcrypt/zcryptstats.bash zdev/src/chzdev zdev/src/chzdev_usage.h zdev/src/lszdev diff --git a/zconf/zcrypt/Makefile b/zconf/zcrypt/Makefile index f6797757..042811db 100644 --- a/zconf/zcrypt/Makefile +++ b/zconf/zcrypt/Makefile @@ -1,5 +1,10 @@ include ../../common.mak +zsh-completions = _chzcrypt _lszcrypt _zcryptstats +bash-completions = chzcrypt.bash lszcrypt.bash zcryptstats.bash + +include ../../common_autocomp.mak + all: chzcrypt lszcrypt zcryptctl zcryptstats libs = $(rootdir)/libutil/libutil.a diff --git a/zconf/zcrypt/autocompletion_generator_host.c b/zconf/zcrypt/autocompletion_generator_host.c new file mode 100644 index 00000000..b9034ca5 --- /dev/null +++ b/zconf/zcrypt/autocompletion_generator_host.c @@ -0,0 +1,20 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "chzcrypt_cli.h" +#include "lszcrypt_cli.h" +#include "zcryptstats_cli.h" + +int main(void) +{ + generate_autocomp(chzcrypt_opt_vec, "chzcrypt"); + generate_autocomp(lszcrypt_opt_vec, "lszcrypt"); + generate_autocomp(zcryptstats_opt_vec, "zcryptstats"); + + return 0; +} diff --git a/zconf/zcrypt/chzcrypt.c b/zconf/zcrypt/chzcrypt.c index 922dba56..e879d490 100644 --- a/zconf/zcrypt/chzcrypt.c +++ b/zconf/zcrypt/chzcrypt.c @@ -26,6 +26,7 @@ #include "lib/util_scandir.h" #include "lib/zt_common.h" +#include "chzcrypt_cli.h" #include "misc.h" /* max seconds the se-association command will wait for completion */ @@ -57,95 +58,6 @@ static const struct util_prg prg = { } }; -/* - * Configuration of command line options - */ - -#define OPT_CONFIG_ON 0x80 -#define OPT_CONFIG_OFF 0x81 -#define OPT_SE_ASSOC 0x82 -#define OPT_SE_BIND 0x83 -#define OPT_SE_UNBIND 0x84 - -static struct util_opt opt_vec[] = { - { - .option = { "enable", no_argument, NULL, 'e'}, - .argument = "DEVICE_IDS", - .desc = "Set the given cryptographic device(s) online" - }, - { - .option = { "disable", no_argument, NULL, 'd'}, - .argument = "DEVICE_IDS", - .desc = "Set the given cryptographic device(s) offline", - }, - { - .option = { "all", no_argument, NULL, 'a'}, - .desc = "Set all available cryptographic device(s) " - "online/offline, must be used in conjunction " - "with the enable or disable option", - }, - { - .option = { "config-on", no_argument, NULL, OPT_CONFIG_ON}, - .argument = "DEVICE_IDS", - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Set the given cryptographic card device(s) configured" - }, - { - .option = { "config-off", no_argument, NULL, OPT_CONFIG_OFF}, - .argument = "DEVICE_IDS", - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Set the given cryptographic card device(s) deconfigured" - }, - { - .option = { "poll-thread-enable", no_argument, NULL, 'p'}, - .desc = "Enable zcrypt's poll thread", - }, - { - .option = { "poll-thread-disable", no_argument, NULL, 'n'}, - .desc = "Disable zcrypt's poll thread", - }, - { - .option = { "config-time", required_argument, NULL, 'c'}, - .argument = "TIMEOUT", - .desc = "Set configuration timer for re-scanning the AP bus " - "to TIMEOUT seconds", - }, - { - .option = { "poll-timeout", required_argument, NULL, 't'}, - .argument = "TIMEOUT", - .desc = "Set poll timer to run poll tasklet all TIMEOUT " - "nanoseconds after a request has been queued", - }, - { - .option = { "default-domain", required_argument, NULL, 'q'}, - .argument = "DOMAIN", - .desc = "Set new default domain to DOMAIN", - }, - { - .option = { "verbose", no_argument, NULL, 'V'}, - .desc = "Print verbose messages", - }, - { - .option = { "se-associate", required_argument, NULL, OPT_SE_ASSOC}, - .argument = "assoc_idx", - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "SE guest with AP support only: Associate the given queue device", - }, - { - .option = { "se-bind", no_argument, NULL, OPT_SE_BIND}, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "SE guest with AP support only: Bind the given queue device", - }, - { - .option = { "se-unbind", no_argument, NULL, OPT_SE_UNBIND}, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "SE guest with AP support only: Unbind the given queue device", - }, - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END -}; - /* * Print if verbose is set */ @@ -643,7 +555,7 @@ int main(int argc, char *argv[]) argv[i][j] = '-'; util_prg_init(&prg); - util_opt_init(opt_vec, NULL); + util_opt_init(chzcrypt_opt_vec, NULL); while (1) { c = util_opt_getopt_long(argc, argv); if (c == -1) diff --git a/zconf/zcrypt/chzcrypt_cli.h b/zconf/zcrypt/chzcrypt_cli.h new file mode 100644 index 00000000..c5aa168e --- /dev/null +++ b/zconf/zcrypt/chzcrypt_cli.h @@ -0,0 +1,101 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef CHZCRYPT_CLI_H +#define CHZCRYPT_CLI_H + +#include "lib/util_opt.h" + +/* + * Configuration of command line options + */ + +#define OPT_CONFIG_ON 0x80 +#define OPT_CONFIG_OFF 0x81 +#define OPT_SE_ASSOC 0x82 +#define OPT_SE_BIND 0x83 +#define OPT_SE_UNBIND 0x84 + +static struct util_opt chzcrypt_opt_vec[] = { + { + .option = { "enable", no_argument, NULL, 'e'}, + .argument = "DEVICE_IDS", + .desc = "Set the given cryptographic device(s) online" + }, + { + .option = { "disable", no_argument, NULL, 'd'}, + .argument = "DEVICE_IDS", + .desc = "Set the given cryptographic device(s) offline", + }, + { + .option = { "all", no_argument, NULL, 'a'}, + .desc = "Set all available cryptographic device(s) " + "online/offline, must be used in conjunction " + "with the enable or disable option", + }, + { + .option = { "config-on", no_argument, NULL, OPT_CONFIG_ON}, + .argument = "DEVICE_IDS", + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Set the given cryptographic card device(s) configured" + }, + { + .option = { "config-off", no_argument, NULL, OPT_CONFIG_OFF}, + .argument = "DEVICE_IDS", + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Set the given cryptographic card device(s) deconfigured" + }, + { + .option = { "poll-thread-enable", no_argument, NULL, 'p'}, + .desc = "Enable zcrypt's poll thread", + }, + { + .option = { "poll-thread-disable", no_argument, NULL, 'n'}, + .desc = "Disable zcrypt's poll thread", + }, + { + .option = { "config-time", required_argument, NULL, 'c'}, + .argument = "TIMEOUT", + .desc = "Set configuration timer for re-scanning the AP bus " + "to TIMEOUT seconds", + }, + { + .option = { "poll-timeout", required_argument, NULL, 't'}, + .argument = "TIMEOUT", + .desc = "Set poll timer to run poll tasklet all TIMEOUT " + "nanoseconds after a request has been queued", + }, + { + .option = { "default-domain", required_argument, NULL, 'q'}, + .argument = "DOMAIN", + .desc = "Set new default domain to DOMAIN", + }, + { + .option = { "verbose", no_argument, NULL, 'V'}, + .desc = "Print verbose messages", + }, + { + .option = { "se-associate", required_argument, NULL, OPT_SE_ASSOC}, + .argument = "assoc_idx", + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "SE guest with AP support only: Associate the given queue device", + }, + { + .option = { "se-bind", no_argument, NULL, OPT_SE_BIND}, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "SE guest with AP support only: Bind the given queue device", + }, + { + .option = { "se-unbind", no_argument, NULL, OPT_SE_UNBIND}, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "SE guest with AP support only: Unbind the given queue device", + }, + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END +}; + +#endif diff --git a/zconf/zcrypt/lszcrypt.c b/zconf/zcrypt/lszcrypt.c index 7030e0e3..65278350 100644 --- a/zconf/zcrypt/lszcrypt.c +++ b/zconf/zcrypt/lszcrypt.c @@ -23,6 +23,7 @@ #include "lib/zt_common.h" #include "lib/ap.h" +#include "lszcrypt_cli.h" #include "misc.h" /* @@ -104,68 +105,6 @@ static const struct util_prg prg = { } }; -/* - * Configuration of command line options - */ - -#define OPT_ACCELONLY 0x81 -#define OPT_CCAONLY 0x82 -#define OPT_EP11ONLY 0x83 -#define OPT_CARDONLY 0x84 -#define OPT_QUEUEONLY 0x85 - -static struct util_opt opt_vec[] = { - { - .option = {"bus", 0, NULL, 'b'}, - .desc = "Show AP bus attributes then exit", - }, - { - .option = { "capability", required_argument, NULL, 'c'}, - .argument = "DEVICE_ID", - .desc = "Show the capabilities of a cryptographic device", - }, - { - .option = {"domains", 0, NULL, 'd'}, - .desc = "Show the configured AP usage and control domains", - }, - { - .option = {"verbose", 0, NULL, 'V'}, - .desc = "Print verbose messages", - }, - { - .option = {"accelonly", 0, NULL, OPT_ACCELONLY}, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Show only information from cards/queues in Accelerator mode", - }, - { - .option = {"ccaonly", 0, NULL, OPT_CCAONLY}, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Show only information from cards/queues in CCA-Coprocessor mode", - }, - { - .option = {"ep11only", 0, NULL, OPT_EP11ONLY}, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Show only information from cards/queues in EP11-Coprocessor mode", - }, - { - .option = {"cardonly", 0, NULL, OPT_CARDONLY}, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Show only information from cards but no queue info", - }, - { - .option = {"queueonly", 0, NULL, OPT_QUEUEONLY}, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Show only information from queues but no card info", - }, - { - .option = {"serial", 0, NULL, 's'}, - .desc = "Show the serial numbers for CCA and EP11 crypto cards", - }, - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END -}; - /* * Show bus */ @@ -1086,7 +1025,7 @@ int main(int argc, char **argv) int c; util_prg_init(&prg); - util_opt_init(opt_vec, NULL); + util_opt_init(lszcrypt_opt_vec, NULL); while (1) { c = util_opt_getopt_long(argc, argv); if (c == -1) diff --git a/zconf/zcrypt/lszcrypt_cli.h b/zconf/zcrypt/lszcrypt_cli.h new file mode 100644 index 00000000..2cfafece --- /dev/null +++ b/zconf/zcrypt/lszcrypt_cli.h @@ -0,0 +1,74 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef LSZCRYPT_CLI_H +#define LSZCRYPT_CLI_H + +#include "lib/util_opt.h" + +/* + * Configuration of command line options + */ + +#define OPT_ACCELONLY 0x81 +#define OPT_CCAONLY 0x82 +#define OPT_EP11ONLY 0x83 +#define OPT_CARDONLY 0x84 +#define OPT_QUEUEONLY 0x85 + +static struct util_opt lszcrypt_opt_vec[] = { + { + .option = {"bus", 0, NULL, 'b'}, + .desc = "Show AP bus attributes then exit", + }, + { + .option = { "capability", required_argument, NULL, 'c'}, + .argument = "DEVICE_ID", + .desc = "Show the capabilities of a cryptographic device", + }, + { + .option = {"domains", 0, NULL, 'd'}, + .desc = "Show the configured AP usage and control domains", + }, + { + .option = {"verbose", 0, NULL, 'V'}, + .desc = "Print verbose messages", + }, + { + .option = {"accelonly", 0, NULL, OPT_ACCELONLY}, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Show only information from cards/queues in Accelerator mode", + }, + { + .option = {"ccaonly", 0, NULL, OPT_CCAONLY}, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Show only information from cards/queues in CCA-Coprocessor mode", + }, + { + .option = {"ep11only", 0, NULL, OPT_EP11ONLY}, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Show only information from cards/queues in EP11-Coprocessor mode", + }, + { + .option = {"cardonly", 0, NULL, OPT_CARDONLY}, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Show only information from cards but no queue info", + }, + { + .option = {"queueonly", 0, NULL, OPT_QUEUEONLY}, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Show only information from queues but no card info", + }, + { + .option = {"serial", 0, NULL, 's'}, + .desc = "Show the serial numbers for CCA and EP11 crypto cards", + }, + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END +}; + +#endif diff --git a/zconf/zcrypt/zcryptstats.c b/zconf/zcrypt/zcryptstats.c index b81d1cee..0e0c251e 100644 --- a/zconf/zcrypt/zcryptstats.c +++ b/zconf/zcrypt/zcryptstats.c @@ -33,6 +33,8 @@ #include "lib/util_scandir.h" #include "lib/zt_common.h" +#include "zcryptstats_cli.h" + #ifndef offsetof #define offsetof(type, member) ((size_t) &((type *)0)->member) #endif @@ -485,102 +487,6 @@ static struct zcryptstats_globals { static volatile bool quit; -/* - * Configuration of command line options - */ -static struct util_opt opt_vec[] = { - /***********************************************************/ - { - .flags = UTIL_OPT_FLAG_SECTION, - .desc = "OPTIONS", - }, - { - .option = {"interval", required_argument, NULL, 'i'}, - .argument = "INTERVAL", - .desc = "Specifies the interval time in seconds. If omitted, a " - "default interval of 10 seconds is used", - }, - { - .option = {"count", required_argument, NULL, 'c'}, - .argument = "COUNT", - .desc = "Specifies the number of reports that are generated " - "at INTERVAL seconds apart. If omitted, reports are " - "generated continuously, until stopped with control-C", - }, - { - .option = {"output", required_argument, NULL, 'o'}, - .argument = "JSON|TABLE|CSV", - .desc = "Displays the statistics in the specified format. If " - "this option is omitted, a comprehensive report is " - "displayed. Supported output formats are: JSON, TABLE, " - "CSV. With TABLE and CSV the display of the individual " - "counters are omitted, and only the totals are " - "displayed. CSV and TABLE output formats imply option " - "--only-totals", - }, - { - .option = {"no-totals", 0, NULL, 't'}, - .desc = "Excludes the totals of all counters of a card " - "device or queue device (APQN). It can not be " - "specified together with option --only-totals or " - "option --output TABLE|CSV", - }, - { - .option = {"only-totals", 0, NULL, 'T'}, - .desc = "Displays only the totals of all counters of a card " - "device or a queue device (APQN), but not the " - "individual counters. This option is implied with " - "option --output TABLE|CSV", - }, - { - .option = {"no-apqn", 0, NULL, 'a'}, - .desc = "Displays only the counters of the card device, but " - "omits the counters of the queue device (APQN). If the " - "system does not support obtaining cryptographic " - "performance measurement data on the queue devices, " - "then this option is implied", - }, - { - .option = {"map-type", required_argument, NULL, 'M'}, - .argument = "MAPPING", - .desc = "Maps unknown cryptographic device types and modes to " - "known types and modes. This option should only be " - "used when new, so far unknown cryptographic devices " - "are found. You can then map them to known devices and " - "modes, provided that the new cryptographic devices " - "report the same counters as the known cryptographic " - "device to which it is mapped. The mapping " - "specification consists of a comma-separated list of " - "FROM-TYPE:FROM-MODE=TO-TYPE:TO-MODE specifications. " - "The type and mode values must be specified in decimal " - "notation", - }, - { - .option = {"all", 0, NULL, 'A'}, - .desc = "Displays all cards devices and queue devices (APQNs), " - "not only those that are available to the Linux " - "system. Using this option additional cryptographic " - "devices that are available in the CEC, but not " - "available to the Linux system are also monitored. " - "This option can not be specified together with option " - "--only-online", - }, - { - .option = {"only-online", 0, NULL, 'O'}, - .desc = "Displays only online cards devices and queue devices " - "(APQNs). This option can not be specified together " - "with option --all" - }, - { - .option = {"verbose", 0, NULL, 'V'}, - .desc = "Prints additional information messages during " - "processing", - }, - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END -}; - #define pr_verbose(fmt...) do { \ if (g.verbose) \ warnx(fmt); \ @@ -2283,7 +2189,7 @@ int main(int argc, char *argv[]) int c, rc; util_prg_init(&prg); - util_opt_init(opt_vec, NULL); + util_opt_init(zcryptstats_opt_vec, NULL); while (1) { c = util_opt_getopt_long(argc, argv); diff --git a/zconf/zcrypt/zcryptstats_cli.h b/zconf/zcrypt/zcryptstats_cli.h new file mode 100644 index 00000000..e0d6c92b --- /dev/null +++ b/zconf/zcrypt/zcryptstats_cli.h @@ -0,0 +1,108 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef ZCRYPTSTATS_CLI_H +#define ZCRYPTSTATS_CLI_H + +#include "lib/util_opt.h" + +/* + * Configuration of command line options + */ +static struct util_opt zcryptstats_opt_vec[] = { + /***********************************************************/ + { + .flags = UTIL_OPT_FLAG_SECTION, + .desc = "OPTIONS", + }, + { + .option = {"interval", required_argument, NULL, 'i'}, + .argument = "INTERVAL", + .desc = "Specifies the interval time in seconds. If omitted, a " + "default interval of 10 seconds is used", + }, + { + .option = {"count", required_argument, NULL, 'c'}, + .argument = "COUNT", + .desc = "Specifies the number of reports that are generated " + "at INTERVAL seconds apart. If omitted, reports are " + "generated continuously, until stopped with control-C", + }, + { + .option = {"output", required_argument, NULL, 'o'}, + .argument = "JSON|TABLE|CSV", + .desc = "Displays the statistics in the specified format. If " + "this option is omitted, a comprehensive report is " + "displayed. Supported output formats are: JSON, TABLE, " + "CSV. With TABLE and CSV the display of the individual " + "counters are omitted, and only the totals are " + "displayed. CSV and TABLE output formats imply option " + "--only-totals", + }, + { + .option = {"no-totals", 0, NULL, 't'}, + .desc = "Excludes the totals of all counters of a card " + "device or queue device (APQN). It can not be " + "specified together with option --only-totals or " + "option --output TABLE|CSV", + }, + { + .option = {"only-totals", 0, NULL, 'T'}, + .desc = "Displays only the totals of all counters of a card " + "device or a queue device (APQN), but not the " + "individual counters. This option is implied with " + "option --output TABLE|CSV", + }, + { + .option = {"no-apqn", 0, NULL, 'a'}, + .desc = "Displays only the counters of the card device, but " + "omits the counters of the queue device (APQN). If the " + "system does not support obtaining cryptographic " + "performance measurement data on the queue devices, " + "then this option is implied", + }, + { + .option = {"map-type", required_argument, NULL, 'M'}, + .argument = "MAPPING", + .desc = "Maps unknown cryptographic device types and modes to " + "known types and modes. This option should only be " + "used when new, so far unknown cryptographic devices " + "are found. You can then map them to known devices and " + "modes, provided that the new cryptographic devices " + "report the same counters as the known cryptographic " + "device to which it is mapped. The mapping " + "specification consists of a comma-separated list of " + "FROM-TYPE:FROM-MODE=TO-TYPE:TO-MODE specifications. " + "The type and mode values must be specified in decimal " + "notation", + }, + { + .option = {"all", 0, NULL, 'A'}, + .desc = "Displays all cards devices and queue devices (APQNs), " + "not only those that are available to the Linux " + "system. Using this option additional cryptographic " + "devices that are available in the CEC, but not " + "available to the Linux system are also monitored. " + "This option can not be specified together with option " + "--only-online", + }, + { + .option = {"only-online", 0, NULL, 'O'}, + .desc = "Displays only online cards devices and queue devices " + "(APQNs). This option can not be specified together " + "with option --all" + }, + { + .option = {"verbose", 0, NULL, 'V'}, + .desc = "Prints additional information messages during " + "processing", + }, + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END +}; + +#endif