From: LiviaMedeiros Date: Sat, 7 Dec 2024 09:00:39 +0000 (+0800) Subject: zramctl: add support for `algorithm_params` X-Git-Tag: v2.42-start~122^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c27f692414f584d74cab65dfd6ee8cc3e0079943;p=thirdparty%2Futil-linux.git zramctl: add support for `algorithm_params` --- diff --git a/sys-utils/zramctl.8.adoc b/sys-utils/zramctl.8.adoc index 6fb7cf8cc..6aa4b42d1 100644 --- a/sys-utils/zramctl.8.adoc +++ b/sys-utils/zramctl.8.adoc @@ -54,6 +54,9 @@ Define the status output columns to be used. If no output arrangement is specifi + The default list of columns may be extended if _list_ is specified in the format _+list_ (e.g., *zramctl -o+COMP-RATIO*). +*-p*, *--params*:: +Set the algorithm parameters, for example, *level=9 dict=/etc/dictionary* to set compression level and pre-trained dictionary. Parameters are algorithm specific. + *--output-all*:: Output all available columns. diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c index 75fdfa334..54ae64483 100644 --- a/sys-utils/zramctl.c +++ b/sys-utils/zramctl.c @@ -587,6 +587,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -n, --noheadings don't print headings\n"), out); fputs(_(" -o, --output columns to use for status output\n"), out); fputs(_(" --output-all output all columns\n"), out); + fputs(_(" -p, --params algorithm parameters to use\n"), out); fputs(_(" --raw use raw status output format\n"), out); fputs(_(" -r, --reset reset all specified devices\n"), out); fputs(_(" -s, --size device size\n"), out); @@ -623,6 +624,7 @@ int main(int argc, char **argv) { uintmax_t size = 0, nstreams = 0; char *algorithm = NULL; + char *algorithm_params = NULL; int rc = 0, c, find = 0, act = A_NONE; struct zram *zram = NULL; char *outarg = NULL; @@ -639,6 +641,7 @@ int main(int argc, char **argv) { "help", no_argument, NULL, 'h' }, { "output", required_argument, NULL, 'o' }, { "output-all",no_argument, NULL, OPT_LIST_TYPES }, + { "params", required_argument, NULL, 'p' }, { "noheadings",no_argument, NULL, 'n' }, { "reset", no_argument, NULL, 'r' }, { "raw", no_argument, NULL, OPT_RAW }, @@ -660,7 +663,7 @@ int main(int argc, char **argv) textdomain(PACKAGE); close_stdout_atexit(); - while ((c = getopt_long(argc, argv, "a:bfho:nrs:t:V", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "a:bfho:p:nrs:t:V", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -681,6 +684,9 @@ int main(int argc, char **argv) for (ncolumns = 0; ncolumns < ARRAY_SIZE(infos); ncolumns++) columns[ncolumns] = ncolumns; break; + case 'p': + algorithm_params = optarg; + break; case 's': size = strtosize_or_err(optarg, _("failed to parse size")); act = A_CREATE; @@ -716,8 +722,8 @@ int main(int argc, char **argv) if (act != A_RESET && optind + 1 < argc) errx(EXIT_FAILURE, _("only one at a time is allowed")); - if ((act == A_STATUS || act == A_FINDONLY) && (algorithm || nstreams)) - errx(EXIT_FAILURE, _("options --algorithm and --streams " + if ((act == A_STATUS || act == A_FINDONLY) && (algorithm || algorithm_params || nstreams)) + errx(EXIT_FAILURE, _("options --algorithm, --params, and --streams " "must be combined with --size")); ul_path_init_debug(); @@ -795,6 +801,10 @@ int main(int argc, char **argv) zram_set_strparm(zram, "comp_algorithm", algorithm)) err(EXIT_FAILURE, _("%s: failed to set algorithm"), zram->devname); + if (algorithm_params && + zram_set_strparm(zram, "algorithm_params", algorithm_params)) + err(EXIT_FAILURE, _("%s: failed to set algorithm params"), zram->devname); + if (zram_set_u64parm(zram, "disksize", size)) err(EXIT_FAILURE, _("%s: failed to set disksize (%ju bytes)"), zram->devname, size);