nvme: introduce NVME_NS_METADATA_SUPPORTED flag

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>
This commit is contained in:
Max Gurtovoy 2020-05-19 17:05:50 +03:00 committed by Christoph Hellwig
parent ffc89b1d3c
commit b29f84857a
2 changed files with 35 additions and 7 deletions

View 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_min(disk->queue, phys_bs);
blk_queue_io_opt(disk->queue, io_opt); 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)) * The block layer can't support LBA sizes larger than the page size
nvme_init_integrity(disk, ns->ms, ns->pi_type); * yet, so catch this early and don't allow block I/O.
if ((ns->ms && !nvme_ns_has_pi(ns) && !blk_get_integrity(disk)) || */
ns->lba_shift > PAGE_SHIFT) if (ns->lba_shift > PAGE_SHIFT)
capacity = 0; 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); set_capacity_revalidate_and_notify(disk, capacity, false);
nvme_config_discard(disk, ns); 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->features = 0;
ns->ms = le16_to_cpu(id->lbaf[id->flbas & NVME_NS_FLBAS_LBA_MASK].ms); 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 */ /* the PI implementation requires metadata equal t10 pi tuple size */
if (ns->ms == sizeof(struct t10_pi_tuple)) if (ns->ms == sizeof(struct t10_pi_tuple))
ns->pi_type = id->dps & NVME_NS_DPS_PI_MASK; ns->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
else else
ns->pi_type = 0; 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) if (iob)
blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(iob)); blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(iob));
nvme_update_disk_info(disk, ns, id); nvme_update_disk_info(disk, ns, id);

View File

@ -366,6 +366,7 @@ struct nvme_ns_head {
enum nvme_ns_features { enum nvme_ns_features {
NVME_NS_EXT_LBAS = 1 << 0, /* support extended LBA format */ NVME_NS_EXT_LBAS = 1 << 0, /* support extended LBA format */
NVME_NS_METADATA_SUPPORTED = 1 << 1, /* support getting generated md */
}; };
struct nvme_ns { struct nvme_ns {