zram: check comp algorithm availability earlier
Subsystems (2)
PATCH 1/1 zram: check comp algorithm availability earlier
Improvement idea by Marcin Jabrzyk.
comp_algorithm_store() silently accepts any supplied algorithm name, because zram performs algorithm availability check later, during the device configuration phase in disksize_store() and prints
"zram: Cannot initialise %s compressing backend"
to syslog. this error line is somewhat generic and, besides, can indicate a failed attempt to allocate compression backend's working buffers.
make algorithm availability check earlier, in comp_algorithm_store(), and be move verbose:
echo lzz > /sys/block/zram0/comp_algorithm
-bash: echo: write error: Invalid argument
dmesg:
zram: Error: unavailable compression algorithm: lzz
--- drivers/block/zram/zcomp.c | 5 +++++ drivers/block/zram/zcomp.h | 1 + drivers/block/zram/zram_drv.c | 6 ++++++ 3 files changed, 12 insertions(+)
drivers/block/zram/zcomp.c +5 -0
@@ -320,6 +320,11 @@ void zcomp_destroy(struct zcomp *comp)kfree (comp); } +bool zcomp_available_algorithm (const char *comp) +{ +return find_backend (comp) !=NULL ; +} +/* * search available compressors for requested algorithm. * allocate new zcomp and initialize it. return compressing
drivers/block/zram/zcomp.h +1 -0
@@ -51,6 +51,7 @@ struct zcomp { };ssize_t zcomp_available_show (const char *comp,char *buf); +bool zcomp_available_algorithm (const char *comp);struct zcomp *zcomp_create (const char *comp,int max_strm);void zcomp_destroy (struct zcomp *comp);
drivers/block/zram/zram_drv.c +6 -0
@@ -378,6 +378,12 @@ 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)) { +pr_err ("Error: unavailable compression algorithm: %s\n" , + zram->compressor); + len = -EINVAL ; + } +up_write (&zram->init_lock);return len; }
Signature · 1 line
2.4.1.314.g9532ead
Minchan Kim
maintainerHello Sergey,
Quoted 61 lines · Sergey Senozhatsky
Improvement idea by Marcin Jabrzyk.
comp_algorithm_store()silently accepts any supplied algorithm name, because zram performs algorithm availability check later, during the device configuration phase indisksize_store()and prints
"zram: Cannot initialise %s compressing backend"
to syslog. this error line is somewhat generic and, besides, can indicate a failed attempt to allocate compression backend's working buffers.make algorithm availability check earlier, in
comp_algorithm_store(), and be move verbose:echo lzz >
/sys/block/zram0/comp_algorithm
-bash: echo: write error: Invalid argumentdmesg:
zram: Error: unavailable compression algorithm: lzzSigned-off-by Sergey Senozhatsky <[email protected]>Reported-by Marcin Jabrzyk <[email protected]>--- drivers/block/zram/zcomp.c | 5 +++++ drivers/block/zram/zcomp.h | 1 + drivers/block/zram/zram_drv.c | 6 ++++++ 3 files changed, 12 insertions(+)drivers/block/zram/zcomp.c +5
-0@@ -320,6 +320,11 @@ void zcomp_destroy(struct zcomp *comp)kfree (comp); } +bool zcomp_available_algorithm (const char *comp) +{ +return find_backend (comp) !=NULL ; +} +/* * search available compressors for requested algorithm. * allocate new zcomp and initialize it. return compressing drivers/block/zram/zcomp.h +1
-0@@ -51,6 +51,7 @@ struct zcomp { };ssize_t zcomp_available_show (const char *comp,char *buf); +bool zcomp_available_algorithm (const char *comp);struct zcomp *zcomp_create (const char *comp,int max_strm);void zcomp_destroy (struct zcomp *comp);drivers/block/zram/zram_drv.c +0
-0
drivers/block/zram/zram_drv.c static ssize_t comp_algorithm_store(struct device *dev, · line 386
Quoted 9 lines
drivers/block/zram/zram_drv.c +6
-0@@ -378,6 +378,12 @@ 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)) { +pr_err ("Error: unavailable compression algorithm: %s\n" , + zram->compressor); + len = -EINVAL ; + } +
I'm not against this patch because it's better than old. But let's think more about the pr_err part.
If user try to set wrong algo name, he can see EINVAL. Isn't it enough?
I think every sane admin can think he passed wrong argument if he sees -EINVAL.
So, I don't think we need to emit pr_err in here.
The reason I am paranoid about that is that I really don't want to argue with syslog info which is part of ABI or not in future. If possible, I don't want to depend on pr_xxx.
Quoted 6 lines
drivers/block/zram/zram_drv.c +0
-0up_write (&zram->init_lock);return len; }Signature · 1 line
2.4.1.314.g9532ead
Signature · 2 lines
Kind regards, Minchan Kim
On (05/27/15 12:51), Minchan Kim wrote:
[..]
Quoted 14 lines
drivers/block/zram/zram_drv.c static ssize_t comp_algorithm_store(struct device *dev, · line 386
Quoted 10 lines
drivers/block/zram/zram_drv.c +6
-0@@ -378,6 +378,12 @@ 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)) { +pr_err ("Error: unavailable compression algorithm: %s\n" , + zram->compressor); + len = -EINVAL ; + } +I'm not against this patch because it's better than old. But let's think more about the
pr_errpart.
Quoted 7 lines
If user try to set wrong algo name, he can see EINVAL. Isn't it enough?
I think every sane admin can think he passed wrong argument if he sees
-EINVAL.
So, I don't think we need to emitpr_errin here.
well, it's here simply to make failure investigation easier. one surely will know that supplied string was not recognized as a compression algorithm name, but what was it.. "$3 instead of $2... or, wait, did $i contain something wrong?". zram knew what was wrong.
/* and you asked to put this warn here in your previous email. */
sure, can remove it.
Quoted 4 lines
The reason I am paranoid about that is that I really don't want to argue with syslog info which is part of ABI or not in future. If possible, I don't want to depend on
pr_xxx.
just for the record... I don't understand this part.
ok. I'll resend later today.
-ss
Minchan Kim
maintainerQuoted 24 lines · Sergey Senozhatsky
On (05/27/15 12:51), Minchan Kim wrote:
[..]Quoted 14 lines
drivers/block/zram/zram_drv.c static ssize_t comp_algorithm_store(struct device *dev, · line 386
Quoted 10 lines
drivers/block/zram/zram_drv.c +6
-0@@ -378,6 +378,12 @@ 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)) { +pr_err ("Error: unavailable compression algorithm: %s\n" , + zram->compressor); + len = -EINVAL ; + } +I'm not against this patch because it's better than old. But let's think more about the
pr_errpart.Quoted 7 lines
If user try to set wrong algo name, he can see EINVAL. Isn't it enough?
I think every sane admin can think he passed wrong argument if he sees
-EINVAL.
So, I don't think we need to emitpr_errin here.
Quoted 7 lines
well, it's here simply to make failure investigation easier. one surely will know that supplied string was not recognized as a compression algorithm name, but what was it.. "$3 instead of $2... or, wait, did $i contain something wrong?". zram knew what was wrong.
/* and you asked to put this warn here in your previous email. */
Yes, Sorry about that. At that time, you put the warning in find_backend and I didn't like it. Instead, I want to move it to in there. But more thinking about it, I don't feel we need it.
Quoted 11 lines
sure, can remove it.
Quoted 4 lines
The reason I am paranoid about that is that I really don't want to argue with syslog info which is part of ABI or not in future. If possible, I don't want to depend on
pr_xxx.just for the record... I don't understand this part.
I meant if we remove the pr_err in future by some reason, someone might shout
"No, it's ABI so if you guys removes it, it will break user interface's semantic". Maybe he seems to depends on parse on dmesg.
That is not what I want.
Quoted 5 lines
ok. I'll resend later today.
-ss
Signature · 2 lines
Kind regards, Minchan Kim
Quoted 17 lines · Minchan Kim
Quoted 17 lines
Quoted 10 lines
I'm not against this patch because it's better than old. But let's think more about the
pr_errpart.If user try to set wrong algo name, he can see EINVAL. Isn't it enough?
I think every sane admin can think he passed wrong argument if he sees
-EINVAL.
So, I don't think we need to emitpr_errin here.well, it's here simply to make failure investigation easier. one surely will know that supplied string was not recognized as a compression algorithm name, but what was it.. "$3 instead of $2... or, wait, did $i contain something wrong?". zram knew what was wrong.
Quoted 6 lines
Quoted 1 line
/* and you asked to put this warn here in your previous email. */
Yes, Sorry about that. At that time, you put the warning in
find_backendand I didn't like it. Instead, I want to move it to in there. But more thinking about it, I don't feel we need it.
no problem.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
The reason I am paranoid about that is that I really don't want to argue with syslog info which is part of ABI or not in future. If possible, I don't want to depend on
pr_xxx.
Quoted 8 lines
Quoted 1 line
just for the record... I don't understand this part.
I meant if we remove the
pr_errin future by some reason, someone might shout"No, it's ABI so if you guys removes it, it will break user interface's semantic". Maybe he seems to depends on parse on dmesg.
ah, I see. well, hopefully no one does this. anyway, will remove it.
hm, I was thinking about some sort of a troubleshooting section in zram documentation, where we can `decrypt' some of the errors that we return back. but still did not convince myself that it will be of any use, just doubt that people read documentation that often.
speaking of docs,
mentioning zramctl in zram docs is actully not entirely bad idea, I think. zramctl has been in util-linux for (almost) a year now and sooner or later will be widely available.
-ss