]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
zram: introduce comp algorithm fallback functionality
authorLuis Henriques <luis.henriques@canonical.com>
Sat, 7 Nov 2015 00:29:01 +0000 (16:29 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 7 Nov 2015 01:50:42 +0000 (17:50 -0800)
When the user supplies an unsupported compression algorithm, keep the
previously selected one (knowingly supported) or the default one (if the
compression algorithm hasn't been changed yet).

Note that previously this operation (i.e. setting an invalid algorithm)
would result in no algorithm being selected, which means that this
represents a small change in the default behaviour.

Minchan said:

For initializing zram, we need to set up 3 optional parameters in advance.

1. the number of compression streams
2. memory limitation
3. compression algorithm

Although user pass completely wrong value to set up for 1 and 2
parameters, it's okay because they have default value so zram will be
initialized with the default value (of course, when user passes a wrong
value via *echo*, sysfs returns -EINVAL so the user can notice it).

But 3 is not consistent with other optional parameters.  IOW, if the
user passes a wrong value to set up 3 parameter, zram's initialization
would fail unlike other optional parameters.

So this patch makes them consistent.

Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/block/zram/zram_drv.c

index 9fa15bb9d118ee5ad2d9f34e23aab6777d09d105..c93aeb876125cab52f882eb37cdc6626b3524996 100644 (file)
@@ -365,6 +365,9 @@ static ssize_t comp_algorithm_store(struct device *dev,
        struct zram *zram = dev_to_zram(dev);
        size_t sz;
 
+       if (!zcomp_available_algorithm(buf))
+               return -EINVAL;
+
        down_write(&zram->init_lock);
        if (init_done(zram)) {
                up_write(&zram->init_lock);
@@ -378,9 +381,6 @@ static ssize_t comp_algorithm_store(struct device *dev,
        if (sz > 0 && zram->compressor[sz - 1] == '\n')
                zram->compressor[sz - 1] = 0x00;
 
-       if (!zcomp_available_algorithm(zram->compressor))
-               len = -EINVAL;
-
        up_write(&zram->init_lock);
        return len;
 }