]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
zram: extend comp_algorithm attr write handling
authorSergey Senozhatsky <senozhatsky@chromium.org>
Fri, 12 Jul 2024 05:18:26 +0000 (14:18 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 17 Aug 2024 00:52:30 +0000 (17:52 -0700)
Previously comp_algorithm device attr would accept only
algorithm name param, however in order to enabled comp
configuration we need to extend comp_algorithm_store()
with param=value support.

Link: https://lkml.kernel.org/r/20240712051850.484318-16-senozhatsky@chromium.org
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/block/zram/zram_drv.c

index 84757f0c8166773dd6ef625016dd90cf4d7af2cf..a2c23ca033b59635eff9237cf70645f9b0e394fd 100644 (file)
@@ -998,6 +998,12 @@ static int __comp_algorithm_store(struct zram *zram, u32 prio, const char *buf)
        return 0;
 }
 
+static int comp_params_store(struct zram *zram, u32 prio, s32 level)
+{
+       zram->params[prio].level = level;
+       return 0;
+}
+
 static ssize_t comp_algorithm_show(struct device *dev,
                                   struct device_attribute *attr,
                                   char *buf)
@@ -1013,9 +1019,43 @@ static ssize_t comp_algorithm_store(struct device *dev,
                                    size_t len)
 {
        struct zram *zram = dev_to_zram(dev);
+       char *args, *param, *val;
+       char *alg = NULL;
+       s32 level = ZCOMP_PARAM_NO_LEVEL;
        int ret;
 
-       ret = __comp_algorithm_store(zram, ZRAM_PRIMARY_COMP, buf);
+       args = skip_spaces(buf);
+       while (*args) {
+               args = next_arg(args, &param, &val);
+
+               /*
+                * We need to support 'param' without value, which is an
+                * old format for this attr (algorithm name only).
+                */
+               if (!val || !*val) {
+                       alg = param;
+                       continue;
+               }
+
+               if (!strcmp(param, "algo")) {
+                       alg = val;
+                       continue;
+               }
+
+               if (!strcmp(param, "level")) {
+                       ret = kstrtoint(val, 10, &level);
+                       if (ret)
+                               return ret;
+                       continue;
+               }
+       }
+
+       if (!alg)
+               return -EINVAL;
+
+       ret = comp_params_store(zram, ZRAM_PRIMARY_COMP, level);
+       if (!ret)
+               ret = __comp_algorithm_store(zram, ZRAM_PRIMARY_COMP, alg);
        return ret ? ret : len;
 }
 
@@ -1048,6 +1088,7 @@ static ssize_t recomp_algorithm_store(struct device *dev,
        int prio = ZRAM_SECONDARY_COMP;
        char *args, *param, *val;
        char *alg = NULL;
+       s32 level = ZCOMP_PARAM_NO_LEVEL;
        int ret;
 
        args = skip_spaces(buf);
@@ -1068,6 +1109,13 @@ static ssize_t recomp_algorithm_store(struct device *dev,
                                return ret;
                        continue;
                }
+
+               if (!strcmp(param, "level")) {
+                       ret = kstrtoint(val, 10, &level);
+                       if (ret)
+                               return ret;
+                       continue;
+               }
        }
 
        if (!alg)
@@ -1076,7 +1124,9 @@ static ssize_t recomp_algorithm_store(struct device *dev,
        if (prio < ZRAM_SECONDARY_COMP || prio >= ZRAM_MAX_COMPS)
                return -EINVAL;
 
-       ret = __comp_algorithm_store(zram, prio, alg);
+       ret = comp_params_store(zram, prio, level);
+       if (!ret)
+               ret = __comp_algorithm_store(zram, prio, alg);
        return ret ? ret : len;
 }
 #endif