]> git.ipfire.org Git - thirdparty/kernel/linux.git/blobdiff - block/blk-throttle.h
blk-throttle: delay initialization until configuration
[thirdparty/kernel/linux.git] / block / blk-throttle.h
index 32503fd83a846e9f2d2517c69944fcdb5f453627..393c3d134b9673356920e4cc9ed7e8ce166e6ac9 100644 (file)
@@ -150,23 +150,33 @@ static inline struct throtl_grp *blkg_to_tg(struct blkcg_gq *blkg)
  * Internal throttling interface
  */
 #ifndef CONFIG_BLK_DEV_THROTTLING
-static inline int blk_throtl_init(struct gendisk *disk) { return 0; }
 static inline void blk_throtl_exit(struct gendisk *disk) { }
-static inline void blk_throtl_register(struct gendisk *disk) { }
 static inline bool blk_throtl_bio(struct bio *bio) { return false; }
 static inline void blk_throtl_cancel_bios(struct gendisk *disk) { }
 #else /* CONFIG_BLK_DEV_THROTTLING */
-int blk_throtl_init(struct gendisk *disk);
 void blk_throtl_exit(struct gendisk *disk);
-void blk_throtl_register(struct gendisk *disk);
 bool __blk_throtl_bio(struct bio *bio);
 void blk_throtl_cancel_bios(struct gendisk *disk);
 
+static inline bool blk_throtl_activated(struct request_queue *q)
+{
+       return q->td != NULL;
+}
+
 static inline bool blk_should_throtl(struct bio *bio)
 {
-       struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg);
+       struct throtl_grp *tg;
        int rw = bio_data_dir(bio);
 
+       /*
+        * This is called under bio_queue_enter(), and it's synchronized with
+        * the activation of blk-throtl, which is protected by
+        * blk_mq_freeze_queue().
+        */
+       if (!blk_throtl_activated(bio->bi_bdev->bd_queue))
+               return false;
+
+       tg = blkg_to_tg(bio->bi_blkg);
        if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) {
                if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
                        bio_set_flag(bio, BIO_CGROUP_ACCT);