diff options
author | Minchan Kim <minchan@kernel.org> | 2014-04-07 18:38:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-07 19:36:02 -0400 |
commit | 60a726e33375a1096e85399cfa1327081b4c38be (patch) | |
tree | 3316be45cfc8844bdec5e742cac59f1ebc0dab2f /drivers/block/zram | |
parent | fcfa8d95cacf5cbbe6dee6b8d229fe86142266e0 (diff) |
zram: propagate error to user
When we initialized zcomp with single, we couldn't change
max_comp_streams without zram reset but current interface doesn't show
any error to user and even it changes max_comp_streams's value without
any effect so it would make user very confusing.
This patch prevents max_comp_streams's change when zcomp was initialized
as single zcomp and emit the error to user(ex, echo).
[akpm@linux-foundation.org: don't return with the lock held, per Sergey]
[fengguang.wu@intel.com: fix coccinelle warnings]
Signed-off-by: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Jerome Marchand <jmarchan@redhat.com>
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/zram')
-rw-r--r-- | drivers/block/zram/zcomp.c | 10 | ||||
-rw-r--r-- | drivers/block/zram/zcomp.h | 4 | ||||
-rw-r--r-- | drivers/block/zram/zram_drv.c | 17 |
3 files changed, 20 insertions, 11 deletions
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 5647d8fe1dc1..b0e7592c44d8 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c | |||
@@ -153,7 +153,7 @@ static void zcomp_strm_multi_release(struct zcomp *comp, struct zcomp_strm *zstr | |||
153 | } | 153 | } |
154 | 154 | ||
155 | /* change max_strm limit */ | 155 | /* change max_strm limit */ |
156 | static int zcomp_strm_multi_set_max_streams(struct zcomp *comp, int num_strm) | 156 | static bool zcomp_strm_multi_set_max_streams(struct zcomp *comp, int num_strm) |
157 | { | 157 | { |
158 | struct zcomp_strm_multi *zs = comp->stream; | 158 | struct zcomp_strm_multi *zs = comp->stream; |
159 | struct zcomp_strm *zstrm; | 159 | struct zcomp_strm *zstrm; |
@@ -172,7 +172,7 @@ static int zcomp_strm_multi_set_max_streams(struct zcomp *comp, int num_strm) | |||
172 | zs->avail_strm--; | 172 | zs->avail_strm--; |
173 | } | 173 | } |
174 | spin_unlock(&zs->strm_lock); | 174 | spin_unlock(&zs->strm_lock); |
175 | return 0; | 175 | return true; |
176 | } | 176 | } |
177 | 177 | ||
178 | static void zcomp_strm_multi_destroy(struct zcomp *comp) | 178 | static void zcomp_strm_multi_destroy(struct zcomp *comp) |
@@ -232,10 +232,10 @@ static void zcomp_strm_single_release(struct zcomp *comp, | |||
232 | mutex_unlock(&zs->strm_lock); | 232 | mutex_unlock(&zs->strm_lock); |
233 | } | 233 | } |
234 | 234 | ||
235 | static int zcomp_strm_single_set_max_streams(struct zcomp *comp, int num_strm) | 235 | static bool zcomp_strm_single_set_max_streams(struct zcomp *comp, int num_strm) |
236 | { | 236 | { |
237 | /* zcomp_strm_single support only max_comp_streams == 1 */ | 237 | /* zcomp_strm_single support only max_comp_streams == 1 */ |
238 | return -ENOTSUPP; | 238 | return false; |
239 | } | 239 | } |
240 | 240 | ||
241 | static void zcomp_strm_single_destroy(struct zcomp *comp) | 241 | static void zcomp_strm_single_destroy(struct zcomp *comp) |
@@ -284,7 +284,7 @@ ssize_t zcomp_available_show(const char *comp, char *buf) | |||
284 | return sz; | 284 | return sz; |
285 | } | 285 | } |
286 | 286 | ||
287 | int zcomp_set_max_streams(struct zcomp *comp, int num_strm) | 287 | bool zcomp_set_max_streams(struct zcomp *comp, int num_strm) |
288 | { | 288 | { |
289 | return comp->set_max_streams(comp, num_strm); | 289 | return comp->set_max_streams(comp, num_strm); |
290 | } | 290 | } |
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index 8b8997f8613b..c59d1fca72c0 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h | |||
@@ -46,7 +46,7 @@ struct zcomp { | |||
46 | 46 | ||
47 | struct zcomp_strm *(*strm_find)(struct zcomp *comp); | 47 | struct zcomp_strm *(*strm_find)(struct zcomp *comp); |
48 | void (*strm_release)(struct zcomp *comp, struct zcomp_strm *zstrm); | 48 | void (*strm_release)(struct zcomp *comp, struct zcomp_strm *zstrm); |
49 | int (*set_max_streams)(struct zcomp *comp, int num_strm); | 49 | bool (*set_max_streams)(struct zcomp *comp, int num_strm); |
50 | void (*destroy)(struct zcomp *comp); | 50 | void (*destroy)(struct zcomp *comp); |
51 | }; | 51 | }; |
52 | 52 | ||
@@ -64,5 +64,5 @@ int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, | |||
64 | int zcomp_decompress(struct zcomp *comp, const unsigned char *src, | 64 | int zcomp_decompress(struct zcomp *comp, const unsigned char *src, |
65 | size_t src_len, unsigned char *dst); | 65 | size_t src_len, unsigned char *dst); |
66 | 66 | ||
67 | int zcomp_set_max_streams(struct zcomp *comp, int num_strm); | 67 | bool zcomp_set_max_streams(struct zcomp *comp, int num_strm); |
68 | #endif /* _ZCOMP_H_ */ | 68 | #endif /* _ZCOMP_H_ */ |
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 6b462d27e7d7..80a1cfca1bf0 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c | |||
@@ -127,19 +127,28 @@ static ssize_t max_comp_streams_store(struct device *dev, | |||
127 | { | 127 | { |
128 | int num; | 128 | int num; |
129 | struct zram *zram = dev_to_zram(dev); | 129 | struct zram *zram = dev_to_zram(dev); |
130 | int ret; | ||
130 | 131 | ||
131 | if (kstrtoint(buf, 0, &num)) | 132 | ret = kstrtoint(buf, 0, &num); |
132 | return -EINVAL; | 133 | if (ret < 0) |
134 | return ret; | ||
133 | if (num < 1) | 135 | if (num < 1) |
134 | return -EINVAL; | 136 | return -EINVAL; |
137 | |||
135 | down_write(&zram->init_lock); | 138 | down_write(&zram->init_lock); |
136 | if (init_done(zram)) { | 139 | if (init_done(zram)) { |
137 | if (zcomp_set_max_streams(zram->comp, num)) | 140 | if (!zcomp_set_max_streams(zram->comp, num)) { |
138 | pr_info("Cannot change max compression streams\n"); | 141 | pr_info("Cannot change max compression streams\n"); |
142 | ret = -EINVAL; | ||
143 | goto out; | ||
144 | } | ||
139 | } | 145 | } |
146 | |||
140 | zram->max_comp_streams = num; | 147 | zram->max_comp_streams = num; |
148 | ret = len; | ||
149 | out: | ||
141 | up_write(&zram->init_lock); | 150 | up_write(&zram->init_lock); |
142 | return len; | 151 | return ret; |
143 | } | 152 | } |
144 | 153 | ||
145 | static ssize_t comp_algorithm_show(struct device *dev, | 154 | static ssize_t comp_algorithm_show(struct device *dev, |