nvmet: add metadata characteristics for a namespace
authorIsrael Rukshin <israelr@mellanox.com>
Tue, 19 May 2020 14:05:57 +0000 (17:05 +0300)
committerChristoph Hellwig <hch@lst.de>
Wed, 27 May 2020 05:12:39 +0000 (07:12 +0200)
Fill those namespace fields from the block device format for adding
metadata (T10-PI) over fabric support with block devices.

Signed-off-by: Israel Rukshin <israelr@mellanox.com>
Signed-off-by: Max Gurtovoy <maxg@mellanox.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/Kconfig
drivers/nvme/target/io-cmd-bdev.c
drivers/nvme/target/nvmet.h

index d7f48c0..4474952 100644 (file)
@@ -4,6 +4,7 @@ config NVME_TARGET
        tristate "NVMe Target support"
        depends on BLOCK
        depends on CONFIGFS_FS
+       select BLK_DEV_INTEGRITY_T10 if BLK_DEV_INTEGRITY
        select SGL_ALLOC
        help
          This enabled target side support for the NVMe protocol, that is
index 0427e04..e518bb9 100644 (file)
@@ -47,6 +47,22 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
        id->nows = to0based(ql->io_opt / ql->logical_block_size);
 }
 
+static void nvmet_bdev_ns_enable_integrity(struct nvmet_ns *ns)
+{
+       struct blk_integrity *bi = bdev_get_integrity(ns->bdev);
+
+       if (bi) {
+               ns->metadata_size = bi->tuple_size;
+               if (bi->profile == &t10_pi_type1_crc)
+                       ns->pi_type = NVME_NS_DPS_PI_TYPE1;
+               else if (bi->profile == &t10_pi_type3_crc)
+                       ns->pi_type = NVME_NS_DPS_PI_TYPE3;
+               else
+                       /* Unsupported metadata type */
+                       ns->metadata_size = 0;
+       }
+}
+
 int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
 {
        int ret;
@@ -64,6 +80,12 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
        }
        ns->size = i_size_read(ns->bdev->bd_inode);
        ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
+
+       ns->pi_type = 0;
+       ns->metadata_size = 0;
+       if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY_T10))
+               nvmet_bdev_ns_enable_integrity(ns);
+
        return 0;
 }
 
index 93e0c2a..daef06a 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/rcupdate.h>
 #include <linux/blkdev.h>
 #include <linux/radix-tree.h>
+#include <linux/t10-pi.h>
 
 #define NVMET_ASYNC_EVENTS             4
 #define NVMET_ERROR_LOG_SLOTS          128
@@ -77,6 +78,8 @@ struct nvmet_ns {
 
        int                     use_p2pmem;
        struct pci_dev          *p2p_dev;
+       int                     pi_type;
+       int                     metadata_size;
 };
 
 static inline struct nvmet_ns *to_nvmet_ns(struct config_item *item)