Skip to content

Commit

Permalink
elevator: acquire q->sysfs_lock in elevator_change()
Browse files Browse the repository at this point in the history
Add locking of q->sysfs_lock into elevator_change() (an exported function)
to ensure it is held to protect q->elevator from elevator_init(), even if
elevator_change() is called from non-sysfs paths.
sysfs path (elv_iosched_store) uses __elevator_change(), non-locking
version, as the lock is already taken by elv_iosched_store().

Signed-off-by: Tomoki Sekiyama <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
tsekiyama authored and axboe committed Nov 8, 2013
1 parent eb1c160 commit 7c8a367
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions block/elevator.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
/*
* Switch this queue to the given IO scheduler.
*/
int elevator_change(struct request_queue *q, const char *name)
static int __elevator_change(struct request_queue *q, const char *name)
{
char elevator_name[ELV_NAME_MAX];
struct elevator_type *e;
Expand All @@ -987,6 +987,18 @@ int elevator_change(struct request_queue *q, const char *name)

return elevator_switch(q, e);
}

int elevator_change(struct request_queue *q, const char *name)
{
int ret;

/* Protect q->elevator from elevator_init() */
mutex_lock(&q->sysfs_lock);
ret = __elevator_change(q, name);
mutex_unlock(&q->sysfs_lock);

return ret;
}
EXPORT_SYMBOL(elevator_change);

ssize_t elv_iosched_store(struct request_queue *q, const char *name,
Expand All @@ -997,7 +1009,7 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
if (!q->elevator)
return count;

ret = elevator_change(q, name);
ret = __elevator_change(q, name);
if (!ret)
return count;

Expand Down

0 comments on commit 7c8a367

Please sign in to comment.