nvmet: allow bdev in buffered_io mode
authorChaitanya Kulkarni <kch@nvidia.com>
Wed, 2 Feb 2022 09:04:45 +0000 (01:04 -0800)
committerChristoph Hellwig <hch@lst.de>
Mon, 28 Feb 2022 11:45:05 +0000 (13:45 +0200)
Allow block device to be configured in the buffered I/O mode by using
the file backend. In this way now we can use cache for the block
device namespace which shows significant performance improvement.

We update the block device ns enable function and return early when
buffered_io flag is set.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/io-cmd-bdev.c

index 95c2bbb0b2f5f2ada18897e891a39cf14fc8defc..e9194804ddee4577903fb35c45b425fa2751c423 100644 (file)
@@ -76,6 +76,14 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
 {
        int ret;
 
+       /*
+        * When buffered_io namespace attribute is enabled that means user want
+        * this block device to be used as a file, so block device can take
+        * an advantage of cache.
+        */
+       if (ns->buffered_io)
+               return -ENOTBLK;
+
        ns->bdev = blkdev_get_by_path(ns->device_path,
                        FMODE_READ | FMODE_WRITE, NULL);
        if (IS_ERR(ns->bdev)) {