Message ID | 20200327171545.98970-3-maxg@mellanox.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | [01/17] nvme: introduce namespace features flag | expand |
On Fri, Mar 27, 2020 at 08:15:29PM +0300, Max Gurtovoy wrote: > From: Israel Rukshin <israelr@mellanox.com> > > Centralize all the metadata checks to one place and make the code more > readable. Introduce a new enum nvme_ns_features for that matter. > The features flag description: > - NVME_NS_EXT_LBAS - NVMe namespace supports extended LBA format. > - NVME_NS_MD_HOST_SUPPORTED - NVMe namespace supports getting metadata > from host's block layer. > - NVME_NS_MD_CTRL_SUPPORTED - NVMe namespace supports metadata actions > by the controller (generate/strip). So whole I like the ->features flag, the defintion of these two metadata related features really confuses me. Here are my vague ideas to improve the situation: > -static inline bool nvme_ns_has_pi(struct nvme_ns *ns) > -{ > - return ns->pi_type && ns->ms == sizeof(struct t10_pi_tuple); > -} This function I think is generally useful, I'd rather keep iţ, document it with a comment and remove the new NVME_NS_MD_CTRL_SUPPORTED flag. > - if (ns->ms && !ns->ext && > - (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) > + if (ns->features & NVME_NS_MD_HOST_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) > + > + if ((ns->ms && !(ns->features & NVME_NS_MD_CTRL_SUPPORTED) && > + !(ns->features & NVME_NS_MD_HOST_SUPPORTED) && > + !blk_get_integrity(disk)) || ns->lba_shift > PAGE_SHIFT) > capacity = 0; I find this very confusing. Can we do something like: /* * 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 Typ 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_MD_HOST_SUPPORTED)) nvme_init_integrity(disk, ns->ms, ns->pi_type); else if (!nvme_ns_has_pi(ns)) capacity = 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. > + */ > + if (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED) { > + if (!(ns->features & NVME_NS_EXT_LBAS)) > + ns->features |= NVME_NS_MD_HOST_SUPPORTED; > + } Maybe: > + 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. > + */ > + if (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED) { > + if (!(ns->features & NVME_NS_EXT_LBAS)) > + ns->features |= NVME_NS_MD_HOST_SUPPORTED; > + } This looks a little strange now, but I guess it will make more sense with the fabrics addition. I'll take another look later in the series. > +enum nvme_ns_features { > + NVME_NS_EXT_LBAS = 1 << 0, > + NVME_NS_MD_HOST_SUPPORTED = 1 << 1, > + NVME_NS_MD_CTRL_SUPPORTED = 1 << 2, > +}; Please document the meaning of each flag. I also suspect that just moving ext to a flag first and than adding the NVME_NS_MD_HOST_SUPPORTED bit might make more sense. I'd also rename NVME_NS_MD_HOST_SUPPORTED to NVME_NS_METADATA_SUPPORTED.
On 4/21/2020 4:59 AM, Christoph Hellwig wrote: > On Fri, Mar 27, 2020 at 08:15:29PM +0300, Max Gurtovoy wrote: >> From: Israel Rukshin <israelr@mellanox.com> >> >> Centralize all the metadata checks to one place and make the code more >> readable. Introduce a new enum nvme_ns_features for that matter. >> The features flag description: >> - NVME_NS_EXT_LBAS - NVMe namespace supports extended LBA format. >> - NVME_NS_MD_HOST_SUPPORTED - NVMe namespace supports getting metadata >> from host's block layer. >> - NVME_NS_MD_CTRL_SUPPORTED - NVMe namespace supports metadata actions >> by the controller (generate/strip). > So whole I like the ->features flag, the defintion of these two > metadata related features really confuses me. > > Here are my vague ideas to improve the situation: > Care to look at any of the RFC items I posted on 2/24 - which does things a little differently ? Perhaps find a common ground with Max's patches. http://lists.infradead.org/pipermail/linux-nvme/2020-February/029066.html Granted I've tweaked what I sent a little as there was no need to make nvme_ns_has_pi accessible to the transport. -- james
On Tue, Apr 21, 2020 at 08:53:18AM -0700, James Smart wrote: > Care to look at any of the RFC items I posted on 2/24 - which does things a > little differently ? Perhaps find a common ground with Max's patches. > http://lists.infradead.org/pipermail/linux-nvme/2020-February/029066.html > > Granted I've tweaked what I sent a little as there was no need to make > nvme_ns_has_pi accessible to the transport. I've replied to the series.
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 1cab3c6..f3a184f 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -203,11 +203,6 @@ static void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) nvme_put_ctrl(ctrl); } -static inline bool nvme_ns_has_pi(struct nvme_ns *ns) -{ - return ns->pi_type && ns->ms == sizeof(struct t10_pi_tuple); -} - static blk_status_t nvme_error_status(u16 status) { switch (status & 0x7ff) { @@ -706,7 +701,8 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, * namespace capacity to zero to prevent any I/O. */ if (!blk_integrity_rq(req)) { - if (WARN_ON_ONCE(!nvme_ns_has_pi(ns))) + if (WARN_ON_ONCE(!(ns->features & + NVME_NS_MD_CTRL_SUPPORTED))) return BLK_STS_NOTSUPP; control |= NVME_RW_PRINFO_PRACT; } @@ -1277,7 +1273,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio) meta_len = (io.nblocks + 1) * ns->ms; metadata = (void __user *)(uintptr_t)io.metadata; - if (ns->ext) { + if (ns->features & NVME_NS_EXT_LBAS) { length += meta_len; meta_len = 0; } else if (meta_len) { @@ -1837,11 +1833,12 @@ 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->ext && - (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) + if (ns->features & NVME_NS_MD_HOST_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) + + if ((ns->ms && !(ns->features & NVME_NS_MD_CTRL_SUPPORTED) && + !(ns->features & NVME_NS_MD_HOST_SUPPORTED) && + !blk_get_integrity(disk)) || ns->lba_shift > PAGE_SHIFT) capacity = 0; set_capacity(disk, capacity); @@ -1870,12 +1867,29 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) ns->lba_shift = 9; ns->noiob = le16_to_cpu(id->noiob); ns->ms = le16_to_cpu(id->lbaf[id->flbas & NVME_NS_FLBAS_LBA_MASK].ms); - ns->ext = ns->ms && (id->flbas & NVME_NS_FLBAS_META_EXT); + ns->features = 0; /* 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; - else + if (ns->pi_type) + ns->features |= NVME_NS_MD_CTRL_SUPPORTED; + } 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. + */ + if (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED) { + if (!(ns->features & NVME_NS_EXT_LBAS)) + ns->features |= NVME_NS_MD_HOST_SUPPORTED; + } + } if (ns->noiob) nvme_set_chunk_size(ns); diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 2e04a36..83296d0 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -363,6 +363,12 @@ struct nvme_ns_head { #endif }; +enum nvme_ns_features { + NVME_NS_EXT_LBAS = 1 << 0, + NVME_NS_MD_HOST_SUPPORTED = 1 << 1, + NVME_NS_MD_CTRL_SUPPORTED = 1 << 2, +}; + struct nvme_ns { struct list_head list; @@ -382,8 +388,8 @@ struct nvme_ns { u16 ms; u16 sgs; u32 sws; - bool ext; u8 pi_type; + unsigned long features; unsigned long flags; #define NVME_NS_REMOVING 0 #define NVME_NS_DEAD 1