]> git.baikalelectronics.ru Git - kernel.git/commitdiff
block: add a bdev_write_cache helper
authorChristoph Hellwig <hch@lst.de>
Fri, 15 Apr 2022 04:52:43 +0000 (06:52 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 18 Apr 2022 01:49:59 +0000 (19:49 -0600)
Add a helper to check the write cache flag based on the block_device
instead of having to poke into the block layer internal request_queue.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Acked-by: David Sterba <dsterba@suse.com> [btrfs]
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20220415045258.199825-13-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/rnbd/rnbd-srv.c
drivers/block/xen-blkback/xenbus.c
drivers/target/target_core_iblock.c
fs/btrfs/disk-io.c
include/linux/blkdev.h

index f04df6294650b6f31b4009eb790b2ace72427b6d..f8cc3c5fecb4bdb2ce193b2cb260a9750e5838c0 100644 (file)
@@ -558,7 +558,7 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
        rsp->secure_discard =
                cpu_to_le16(rnbd_dev_get_secure_discard(rnbd_dev));
        rsp->cache_policy = 0;
-       if (test_bit(QUEUE_FLAG_WC, &q->queue_flags))
+       if (bdev_write_cache(rnbd_dev->bdev))
                rsp->cache_policy |= RNBD_WRITEBACK;
        if (blk_queue_fua(q))
                rsp->cache_policy |= RNBD_FUA;
index f09040435e2e541730e05748e08622ad57d0cbc1..8b691fe50475fb38c07f41fe16ddc9fa9d664fbb 100644 (file)
@@ -517,7 +517,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
                vbd->type |= VDISK_REMOVABLE;
 
        q = bdev_get_queue(bdev);
-       if (q && test_bit(QUEUE_FLAG_WC, &q->queue_flags))
+       if (bdev_write_cache(bdev))
                vbd->flush_support = true;
 
        if (q && blk_queue_secure_erase(q))
index b41ee5c3b5b82a037c097bdb437db0a5a964ee68..03013e85ffc0384cfd799160c5a41a0b68b28bc8 100644 (file)
@@ -737,7 +737,7 @@ iblock_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
                if (test_bit(QUEUE_FLAG_FUA, &q->queue_flags)) {
                        if (cmd->se_cmd_flags & SCF_FUA)
                                opf |= REQ_FUA;
-                       else if (!test_bit(QUEUE_FLAG_WC, &q->queue_flags))
+                       else if (!bdev_write_cache(ib_dev->ibd_bd))
                                opf |= REQ_FUA;
                }
        } else {
@@ -886,11 +886,7 @@ iblock_parse_cdb(struct se_cmd *cmd)
 
 static bool iblock_get_write_cache(struct se_device *dev)
 {
-       struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
-       struct block_device *bd = ib_dev->ibd_bd;
-       struct request_queue *q = bdev_get_queue(bd);
-
-       return test_bit(QUEUE_FLAG_WC, &q->queue_flags);
+       return bdev_write_cache(IBLOCK_DEV(dev)->ibd_bd);
 }
 
 static const struct target_backend_ops iblock_ops = {
index cf9b5e214d6fd2f901203a9454c81240ba656e3e..0611bdf1cce7fd28f091b118733ebb4cc547d5f8 100644 (file)
@@ -4249,8 +4249,7 @@ static void write_dev_flush(struct btrfs_device *device)
         * of simplicity, since this is a debug tool and not meant for use in
         * non-debug builds.
         */
-       struct request_queue *q = bdev_get_queue(device->bdev);
-       if (!test_bit(QUEUE_FLAG_WC, &q->queue_flags))
+       if (!bdev_write_cache(device->bdev))
                return;
 #endif
 
index 3a9578e14a6b0301c6926fb15e779fcad1838cc7..807a49aa5a27ae0d7810602818774b7f22fab47b 100644 (file)
@@ -1331,6 +1331,11 @@ static inline bool bdev_nonrot(struct block_device *bdev)
        return blk_queue_nonrot(bdev_get_queue(bdev));
 }
 
+static inline bool bdev_write_cache(struct block_device *bdev)
+{
+       return test_bit(QUEUE_FLAG_WC, &bdev_get_queue(bdev)->queue_flags);
+}
+
 static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev)
 {
        struct request_queue *q = bdev_get_queue(bdev);