]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
zramctl: add support for `algorithm_params`
authorLiviaMedeiros <livia@cirno.name>
Sat, 7 Dec 2024 09:00:39 +0000 (17:00 +0800)
committerLiviaMedeiros <livia@cirno.name>
Sat, 7 Dec 2024 09:16:31 +0000 (17:16 +0800)
sys-utils/zramctl.8.adoc
sys-utils/zramctl.c

index 6fb7cf8ccb2a5ee4b8d41c16f89adc591584112d..6aa4b42d12ca9a011d2ca619b75b4ea98cca5e38 100644 (file)
@@ -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.
 
index 75fdfa33424ccc51d9181304a3cce47699ca78d4..54ae64483b6efbfada094a44807bdf9d48a8e8a6 100644 (file)
@@ -587,6 +587,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -n, --noheadings          don't print headings\n"), out);
        fputs(_(" -o, --output <list>       columns to use for status output\n"), out);
        fputs(_("     --output-all          output all columns\n"), out);
+       fputs(_(" -p, --params <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 <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 <device> 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);