blk-rq-qos.c (9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e) blk-rq-qos.c (a13bd91be22318768d55470cbc0b0f4488ef9edf)
1// SPDX-License-Identifier: GPL-2.0
2
3#include "blk-rq-qos.h"
4
5/*
6 * Increment 'v', if 'v' is below 'below'. Returns true if we succeeded,
7 * false if 'v' + 1 would be bigger than 'below'.
8 */

--- 274 unchanged lines hidden (view full) ---

283 has_sleeper = true;
284 set_current_state(TASK_UNINTERRUPTIBLE);
285 } while (1);
286 finish_wait(&rqw->wait, &data.wq);
287}
288
289void rq_qos_exit(struct request_queue *q)
290{
1// SPDX-License-Identifier: GPL-2.0
2
3#include "blk-rq-qos.h"
4
5/*
6 * Increment 'v', if 'v' is below 'below'. Returns true if we succeeded,
7 * false if 'v' + 1 would be bigger than 'below'.
8 */

--- 274 unchanged lines hidden (view full) ---

283 has_sleeper = true;
284 set_current_state(TASK_UNINTERRUPTIBLE);
285 } while (1);
286 finish_wait(&rqw->wait, &data.wq);
287}
288
289void rq_qos_exit(struct request_queue *q)
290{
291 mutex_lock(&q->rq_qos_mutex);
291 while (q->rq_qos) {
292 struct rq_qos *rqos = q->rq_qos;
293 q->rq_qos = rqos->next;
294 rqos->ops->exit(rqos);
295 }
292 while (q->rq_qos) {
293 struct rq_qos *rqos = q->rq_qos;
294 q->rq_qos = rqos->next;
295 rqos->ops->exit(rqos);
296 }
297 mutex_unlock(&q->rq_qos_mutex);
296}
297
298int rq_qos_add(struct rq_qos *rqos, struct gendisk *disk, enum rq_qos_id id,
299 const struct rq_qos_ops *ops)
300{
301 struct request_queue *q = disk->queue;
302
298}
299
300int rq_qos_add(struct rq_qos *rqos, struct gendisk *disk, enum rq_qos_id id,
301 const struct rq_qos_ops *ops)
302{
303 struct request_queue *q = disk->queue;
304
305 lockdep_assert_held(&q->rq_qos_mutex);
306
303 rqos->disk = disk;
304 rqos->id = id;
305 rqos->ops = ops;
306
307 /*
308 * No IO can be in-flight when adding rqos, so freeze queue, which
309 * is fine since we only support rq_qos for blk-mq queue.
307 rqos->disk = disk;
308 rqos->id = id;
309 rqos->ops = ops;
310
311 /*
312 * No IO can be in-flight when adding rqos, so freeze queue, which
313 * is fine since we only support rq_qos for blk-mq queue.
310 *
311 * Reuse ->queue_lock for protecting against other concurrent
312 * rq_qos adding/deleting
313 */
314 blk_mq_freeze_queue(q);
315
314 */
315 blk_mq_freeze_queue(q);
316
316 spin_lock_irq(&q->queue_lock);
317 if (rq_qos_id(q, rqos->id))
318 goto ebusy;
319 rqos->next = q->rq_qos;
320 q->rq_qos = rqos;
317 if (rq_qos_id(q, rqos->id))
318 goto ebusy;
319 rqos->next = q->rq_qos;
320 q->rq_qos = rqos;
321 spin_unlock_irq(&q->queue_lock);
322
323 blk_mq_unfreeze_queue(q);
324
325 if (rqos->ops->debugfs_attrs) {
326 mutex_lock(&q->debugfs_mutex);
327 blk_mq_debugfs_register_rqos(rqos);
328 mutex_unlock(&q->debugfs_mutex);
329 }
330
331 return 0;
332ebusy:
321
322 blk_mq_unfreeze_queue(q);
323
324 if (rqos->ops->debugfs_attrs) {
325 mutex_lock(&q->debugfs_mutex);
326 blk_mq_debugfs_register_rqos(rqos);
327 mutex_unlock(&q->debugfs_mutex);
328 }
329
330 return 0;
331ebusy:
333 spin_unlock_irq(&q->queue_lock);
334 blk_mq_unfreeze_queue(q);
335 return -EBUSY;
336}
337
338void rq_qos_del(struct rq_qos *rqos)
339{
340 struct request_queue *q = rqos->disk->queue;
341 struct rq_qos **cur;
342
332 blk_mq_unfreeze_queue(q);
333 return -EBUSY;
334}
335
336void rq_qos_del(struct rq_qos *rqos)
337{
338 struct request_queue *q = rqos->disk->queue;
339 struct rq_qos **cur;
340
343 /*
344 * See comment in rq_qos_add() about freezing queue & using
345 * ->queue_lock.
346 */
347 blk_mq_freeze_queue(q);
341 lockdep_assert_held(&q->rq_qos_mutex);
348
342
349 spin_lock_irq(&q->queue_lock);
343 blk_mq_freeze_queue(q);
350 for (cur = &q->rq_qos; *cur; cur = &(*cur)->next) {
351 if (*cur == rqos) {
352 *cur = rqos->next;
353 break;
354 }
355 }
344 for (cur = &q->rq_qos; *cur; cur = &(*cur)->next) {
345 if (*cur == rqos) {
346 *cur = rqos->next;
347 break;
348 }
349 }
356 spin_unlock_irq(&q->queue_lock);
357
358 blk_mq_unfreeze_queue(q);
359
360 mutex_lock(&q->debugfs_mutex);
361 blk_mq_debugfs_unregister_rqos(rqos);
362 mutex_unlock(&q->debugfs_mutex);
363}
350 blk_mq_unfreeze_queue(q);
351
352 mutex_lock(&q->debugfs_mutex);
353 blk_mq_debugfs_unregister_rqos(rqos);
354 mutex_unlock(&q->debugfs_mutex);
355}