Remove trailing newline in elevator switch error message
PATCH 1/1 Remove trailing newline in elevator switch error message
Trying to switch to a non-existing elevator currently results in garbled dmesg output, e.g.:
# echo "foo" > /sys/block/sda/queue/scheduler
elevator: type foo not found
elevator: switch to foo
failed
(note the unintended line break.)
Fix by stripping the trailing newline.
block/elevator.c +4 -1
@@ -1112,6 +1112,7 @@ static inline bool elv_support_iosched(struct request_queue *q)ssize_t elv_iosched_store (struct request_queue *q,const char *name,size_t count) { +char elevator_name[ELV_NAME_MAX ];int ret;if (!(q->mq_ops || q->request_fn) || !elv_support_iosched (q))
@@ -1121,7 +1122,9 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,if (!ret)return count; -printk (KERN_ERR "elevator: switch to %s failed\n" , name); +strlcpy (elevator_name, name,sizeof (elevator_name)); +strstrip (elevator_name); +printk (KERN_ERR "elevator: switch to %s failed\n" , elevator_name);return ret; }
Signature · 1 line
Markus
block/elevator.c static inline bool elv_support_iosched(struct reque=
Quoted 18 lines · Markus Trippelsdorf
Trying to switch to a non-existing elevator currently results in garbled dmesg output, e.g.:
=20# echo "foo" > /sys/block/sda/queue/scheduler=20 =20 elevator: type foo not found elevator: switch to foo failed =20 (note the unintended line break.) =20 Fix by stripping the trailing newline. =20block/elevator.c +0
-0@@ -1112,6 +1112,7 @@ static inline bool elv_support_iosched(struct reque=
st_queue *q)
block/elevator.c ssize_t elv_iosched_store(struct request_queue *q, =
Quoted 8 lines
block/elevator.c +1
-0ssize_t elv_iosched_store (struct request_queue *q,const char *name,size_t count) { +char elevator_name[ELV_NAME_MAX ];int ret;=20
block/elevator.c +0
-0if (!(q->mq_ops || q->request_fn) || !elv_support_iosched (q))@@ -1121,7 +1122,9 @@ ssize_t elv_iosched_store(struct request_queue *q, =
const char *name,
block/elevator.c ssize_t elv_iosched_store(struct request_queue *q, const char *name, · line 1129
Quoted 9 lines
block/elevator.c +0
-0if (!ret)return count;=20
block/elevator.c +3
-1-printk (KERN_ERR "elevator: switch to %s failed\n" , name); +strlcpy (elevator_name, name,sizeof (elevator_name)); +strstrip (elevator_name); +printk (KERN_ERR "elevator: switch to %s failed\n" , elevator_name);return ret; }
Hello Markus,
Your patch duplicates the code to remove trailing whitespace which is not very elegant. Please move the code that removes trailing whitespace from __elevator_change() into elv_iosched_store() instead of duplicating it.
Thanks,
Bart.=20
Quoted 39 lines · Bart Van Assche
Quoted 26 lines · Markus Trippelsdorf
Trying to switch to a non-existing elevator currently results in garbled dmesg output, e.g.:
# echo "foo" > /sys/block/sda/queue/schedulerelevator: type foo not found
elevator: switch to foo
failed(note the unintended line break.)
Fix by stripping the trailing newline.
block/elevator.c +1
-0@@ -1112,6 +1112,7 @@ static inline bool elv_support_iosched(struct request_queue *q)ssize_t elv_iosched_store (struct request_queue *q,const char *name,size_t count) { +char elevator_name[ELV_NAME_MAX ];int ret;if (!(q->mq_ops || q->request_fn) || !elv_support_iosched (q))block/elevator.c ssize_t elv_iosched_store(struct request_queue *q, const char *name, · line 1129
Quoted 9 lines
block/elevator.c +3
-1@@ -1121,7 +1122,9 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,if (!ret)return count; -printk (KERN_ERR "elevator: switch to %s failed\n" , name); +strlcpy (elevator_name, name,sizeof (elevator_name)); +strstrip (elevator_name); +printk (KERN_ERR "elevator: switch to %s failed\n" , elevator_name);return ret; }Hello Markus,
Quoted 3 lines
Your patch duplicates the code to remove trailing whitespace which is not very elegant. Please move the code that removes trailing whitespace from
__elevator_change()intoelv_iosched_store()instead of duplicating it.
Yes, I thought about it, but the problem is that elevator_change() calls __elevator_change(), too.
Signature · 1 line
Markus
Quoted 2 lines · On Mon, 2017-05-01 at 17:49 +0200, [email protected] wrote:
Quoted 1 line · Bart Van Assche
Your patch duplicates the code to remove trailing whitespace which is n=
ot
Quoted 1 line
Quoted 1 line
very elegant. Please move the code that removes trailing whitespace fro=
m
Quoted 1 line
Quoted 1 line
__elevator_change()intoelv_iosched_store()instead of duplicating it=
.
Quoted 2 lines
=20
Yes, I thought about it, but the problem is thatelevator_change()calls=
=20
Quoted 1 line
__elevator_change(), too.
Hello Markus,
In kernel v4.11 elevator_change() only has a single caller and that caller passes an elevator name with no trailing whitespace. I am aware that the elevator_change() function is exported and hence could be used by out-of-tr= ee
kernel drivers. However, we do not care about potential behavior changes fo= r
out-of-tree drivers.
Bart.=
Trying to switch to a non-existing elevator currently results in garbled dmesg output, e.g.:
# echo "foo" > /sys/block/sda/queue/scheduler
elevator: type foo not found
elevator: switch to foo
failed
(note the unintended line break.)
Fix by stripping the trailing newline.
block/elevator.c +8 -7
@@ -1054,7 +1054,6 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)*/ static int __elevator_change (struct request_queue *q,const char *name) { -char elevator_name[ELV_NAME_MAX ];struct elevator_type *e;/*
@@ -1063,15 +1062,14 @@ static int __elevator_change(struct request_queue *q, const char *name)if (q->mq_ops && !strncmp (name,"none" ,4 ))return elevator_switch (q,NULL ); -strlcpy (elevator_name, name,sizeof (elevator_name)); - e =elevator_get (strstrip (elevator_name), true); + e =elevator_get (name, true);if (!e) { -printk (KERN_ERR "elevator: type %s not found\n" , elevator_name); +printk (KERN_ERR "elevator: type %s not found\n" , name);return -EINVAL ; }if (q->elevator && - !strcmp (elevator_name, q->elevator->type->elevator_name)) { + !strcmp (name, q->elevator->type->elevator_name)) {elevator_put (e);return 0 ; }
@@ -1112,16 +1110,19 @@ static inline bool elv_support_iosched(struct request_queue *q)ssize_t elv_iosched_store (struct request_queue *q,const char *name,size_t count) { +char elevator_name[ELV_NAME_MAX ];int ret;if (!(q->mq_ops || q->request_fn) || !elv_support_iosched (q))return count; - ret =__elevator_change (q, name); +strlcpy (elevator_name, name,sizeof (elevator_name)); +strstrip (elevator_name); + ret =__elevator_change (q, elevator_name);if (!ret)return count; -printk (KERN_ERR "elevator: switch to %s failed\n" , name); +printk (KERN_ERR "elevator: switch to %s failed\n" , elevator_name);return ret; }
Signature · 1 line
Markus
block/elevator.c static inline bool elv_support_iosched(struct request_queue *q)
Quoted 3 lines · On Mon, 2017-05-01 at 18:29 +0200, [email protected] wrote:
block/elevator.c +3
-0+strlcpy (elevator_name, name,sizeof (elevator_name)); +strstrip (elevator_name); + ret =3D __elevator_change(q, elevator_name);
Hello Markus,
Are you aware that the current implementation of __elevator_change() strips leading whitespace but that with your patch applied leading whitespace is n= o
longer removed from the elevator name? If you have a look at strim() in lib/string.c you will see that in case of leading whitespace that function does not remove the leading whitespace but returns a pointer to the first non-whitespace character.
Otherwise this patch looks fine to me.
Bart.=
Quoted 12 lines · Bart Van Assche
block/elevator.c static inline bool elv_support_iosched(struct request_queue *q) · line 1121
Quoted 3 lines · On Mon, 2017-05-01 at 18:29 +0200, [email protected] wrote:
block/elevator.c +3
-0+strlcpy (elevator_name, name,sizeof (elevator_name)); +strstrip (elevator_name); + ret =__elevator_change (q, elevator_name);Are you aware that the current implementation of
__elevator_change()strips leading whitespace but that with your patch applied leading whitespace is no longer removed from the elevator name? If you have a look atstrim()inlib/string.cyou will see that in case of leading whitespace that function does not remove the leading whitespace but returns a pointer to the first non-whitespace character.
Well, only in the call to elevator_get(). The dmesg output does contain leading whitespace. But the fix is simple. I will send a new patch.
Signature · 1 line
Markus