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
 
        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;
        }
        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;
 }
 
 
 #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
 
        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)