Clear sysfs path before reading current ioscheduler from sysfs
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Mon, 8 Jun 2015 10:19:02 +0000 (19:19 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Mon, 8 Jun 2015 14:35:39 +0000 (23:35 +0900)
commitb44b9e45cf382dbfc2a7d18408b87a2e57316519
tree46b35a67708a51cdc5208141050b3f8e767af5cd
parentc44ff5115df69f0040aef9677bf48966d72adb81
Clear sysfs path before reading current ioscheduler from sysfs

switch_ioscheduler() function has a local buffer tmp[] to store
both sysfs path (e.g. /sys/block/`device`/queue/scheduler) and
content of that sysfs path.

In order to properly test strstr() after writing a ioscheduler
string (e.g. "deadline") to sysfs, it needs to memset(0) first.
Otherwise if the content of sysfs path (below (b)) is shorter
than the existing sysfs path in tmp[] (below (a)), then tmp[]
after storing the content of sysfs (below (c) and *haystack of
strstr()) contains remaining part of the sysfs path.

(a) "/sys/block/sdb/queue/scheduler"
(b) "noop [deadline] cfq \n"
(c) "noop [deadline] cfq \nscheduler"

strstr() will result the same given that the remaining part of
the sysfs path is unlikely to contain ioscheduler string, but
the remaining part should still be cleared first.
backend.c