[RFC 05/12] block: implement ->get_dma_device callback
Pavel Begunkov
asml.silence at gmail.com
Fri Jun 27 08:10:32 PDT 2025
Implement the ->get_dma_device callback for block files by forwarding it
to drivers via a new blk-mq ops callback.
Signed-off-by: Pavel Begunkov <asml.silence at gmail.com>
---
block/bdev.c | 11 +++++++++++
block/fops.c | 1 +
include/linux/blk-mq.h | 2 ++
include/linux/blkdev.h | 2 ++
4 files changed, 16 insertions(+)
diff --git a/block/bdev.c b/block/bdev.c
index b77ddd12dc06..28850cc0125c 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -61,6 +61,17 @@ struct block_device *file_bdev(struct file *bdev_file)
}
EXPORT_SYMBOL(file_bdev);
+struct device *block_get_dma_device(struct file *file)
+{
+ struct request_queue *q = bdev_get_queue(file_bdev(file));
+
+ if (!(file->f_flags & O_DIRECT))
+ return ERR_PTR(-EINVAL);
+ if (q->mq_ops && q->mq_ops->get_dma_device)
+ return q->mq_ops->get_dma_device(q);
+ return ERR_PTR(-EINVAL);
+}
+
static void bdev_write_inode(struct block_device *bdev)
{
struct inode *inode = BD_INODE(bdev);
diff --git a/block/fops.c b/block/fops.c
index 388acfe82b6c..cb22ffdec7ef 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -941,6 +941,7 @@ const struct file_operations def_blk_fops = {
.fallocate = blkdev_fallocate,
.uring_cmd = blkdev_uring_cmd,
.fop_flags = FOP_BUFFER_RASYNC,
+ .get_dma_device = block_get_dma_device,
};
static __init int blkdev_init(void)
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index de8c85a03bb7..1c878b9f5b4c 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -656,6 +656,8 @@ struct blk_mq_ops {
*/
void (*map_queues)(struct blk_mq_tag_set *set);
+ struct device *(*get_dma_device)(struct request_queue *q);
+
#ifdef CONFIG_BLK_DEBUG_FS
/**
* @show_rq: Used by the debugfs implementation to show driver-specific
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index a59880c809c7..54630e23a419 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1720,6 +1720,8 @@ struct block_device *file_bdev(struct file *bdev_file);
bool disk_live(struct gendisk *disk);
unsigned int block_size(struct block_device *bdev);
+struct device *block_get_dma_device(struct file *file);
+
#ifdef CONFIG_BLOCK
void invalidate_bdev(struct block_device *bdev);
int sync_blockdev(struct block_device *bdev);
--
2.49.0
More information about the Linux-nvme
mailing list