nvme: introduce NVME_NS_METADATA_SUPPORTED flag
authorMax Gurtovoy <maxg@mellanox.com>
Tue, 19 May 2020 14:05:50 +0000 (17:05 +0300)
committerChristoph Hellwig <hch@lst.de>
Wed, 27 May 2020 05:12:38 +0000 (07:12 +0200)
This is a preparation for adding support for metadata in fabric
controllers. New flag will imply that NVMe namespace supports getting
metadata that was originally generated by host's block layer.

Signed-off-by: Max Gurtovoy <maxg@mellanox.com>
Reviewed-by: Israel Rukshin <israelr@mellanox.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: James Smart <james.smart@broadcom.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h

index fecf484..aa168dd 100644 (file)
@@ -1885,13 +1885,27 @@ static void nvme_update_disk_info(struct gendisk *disk,
        blk_queue_io_min(disk->queue, phys_bs);
        blk_queue_io_opt(disk->queue, io_opt);
 
-       if (ns->ms && !(ns->features & NVME_NS_EXT_LBAS) &&
-           (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED))
-               nvme_init_integrity(disk, ns->ms, ns->pi_type);
-       if ((ns->ms && !nvme_ns_has_pi(ns) && !blk_get_integrity(disk)) ||
-           ns->lba_shift > PAGE_SHIFT)
+       /*
+        * The block layer can't support LBA sizes larger than the page size
+        * yet, so catch this early and don't allow block I/O.
+        */
+       if (ns->lba_shift > PAGE_SHIFT)
                capacity = 0;
 
+       /*
+        * Register a metadata profile for PI, or the plain non-integrity NVMe
+        * metadata masquerading as Type 0 if supported, otherwise reject block
+        * I/O to namespaces with metadata except when the namespace supports
+        * PI, as it can strip/insert in that case.
+        */
+       if (ns->ms) {
+               if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
+                   (ns->features & NVME_NS_METADATA_SUPPORTED))
+                       nvme_init_integrity(disk, ns->ms, ns->pi_type);
+               else if (!nvme_ns_has_pi(ns))
+                       capacity = 0;
+       }
+
        set_capacity_revalidate_and_notify(disk, capacity, false);
 
        nvme_config_discard(disk, ns);
@@ -1926,14 +1940,27 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
 
        ns->features = 0;
        ns->ms = le16_to_cpu(id->lbaf[id->flbas & NVME_NS_FLBAS_LBA_MASK].ms);
-       if (ns->ms && (id->flbas & NVME_NS_FLBAS_META_EXT))
-               ns->features |= NVME_NS_EXT_LBAS;
        /* the PI implementation requires metadata equal t10 pi tuple size */
        if (ns->ms == sizeof(struct t10_pi_tuple))
                ns->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
        else
                ns->pi_type = 0;
 
+       if (ns->ms) {
+               if (id->flbas & NVME_NS_FLBAS_META_EXT)
+                       ns->features |= NVME_NS_EXT_LBAS;
+
+               /*
+                * For PCI, Extended logical block will be generated by the
+                * controller. Non-extended format can be generated by the
+                * block layer.
+                */
+               if (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED) {
+                       if (!(ns->features & NVME_NS_EXT_LBAS))
+                               ns->features |= NVME_NS_METADATA_SUPPORTED;
+               }
+       }
+
        if (iob)
                blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(iob));
        nvme_update_disk_info(disk, ns, id);
index 58ae6eb..9ed6a3d 100644 (file)
@@ -366,6 +366,7 @@ struct nvme_ns_head {
 
 enum nvme_ns_features {
        NVME_NS_EXT_LBAS = 1 << 0, /* support extended LBA format */
+       NVME_NS_METADATA_SUPPORTED = 1 << 1, /* support getting generated md */
 };
 
 struct nvme_ns {