nvme cleanups in preparation for the multipath code
Subsystems (2)
Christoph Hellwig
maintainerHi all,
below are a couple cleanup patches to prepare for the next version of the nvme multipath code.
Christoph Hellwig
maintainerPATCH 1/6 nvme: move the dying queue check from cancel to completion
With multipath we don't want a hard DNR bit on a request that is cancelled by a controller reset, but instead want to be able to retry it on another patch. To archive this don't always set the DNR bit when the queue is dying in nvme_cancel_request, but defer that decision to nvme_req_needs_retry. Note that it applies to any command there and not just cancelled commands, but one the queue is dying that is the right thing to do anyway.
--- drivers/nvme/host/core.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +3 -6
@@ -172,6 +172,8 @@ static inline bool nvme_req_needs_retry(struct request *req)return false;if (nvme_req (req)->retries >= nvme_max_retries)return false; +if (blk_queue_dying (req->q)) +return false;return true; }
@@ -189,18 +191,13 @@ EXPORT_SYMBOL_GPL(nvme_complete_rq);void nvme_cancel_request (struct request *req,void *data,bool reserved) { -int status; -if (!blk_mq_request_started (req))return ;dev_dbg_ratelimited (((struct nvme_ctrl *) data)->device,"Cancelling I/O %d" , req->tag); - status =NVME_SC_ABORT_REQ ; -if (blk_queue_dying (req->q)) - status |=NVME_SC_DNR ; -nvme_req (req)->status = status; +nvme_req (req)->status =NVME_SC_ABORT_REQ ;blk_mq_complete_request (req); }
Signature · 1 line
2.14.2
Re: [PATCH 1/6] nvme: move the dying queue check from cancel to completion
Re: [PATCH 1/6] nvme: move the dying queue check from cancel to completion
In reply to Christoph HellwigLooks good.
Christoph Hellwig
maintainerPATCH 2/6 nvme: always unregister the integrity profile in __nvme_revalidate_disk
In reply to Christoph HellwigThis is safe because the queue is always frozen when we revalidate, and it simplifies both the existing code as well as the multipath implementation.
--- drivers/nvme/host/core.c | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-)
drivers/nvme/host/core.c +10 -30
@@ -1081,29 +1081,6 @@ static int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo) }#ifdef CONFIG_BLK_DEV_INTEGRITY -static void nvme_prep_integrity (struct gendisk *disk,struct nvme_id_ns *id, -u16 bs) -{ -struct nvme_ns *ns = disk->private_data; -u16 old_ms = ns->ms; -u8 pi_type =0 ; - - 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 ); - -/* PI implementation requires metadata equal t10 pi tuple size */ -if (ns->ms ==sizeof (struct t10_pi_tuple )) - pi_type = id->dps &NVME_NS_DPS_PI_MASK ; - -if (blk_get_integrity (disk) && - (ns->pi_type != pi_type || ns->ms != old_ms || - bs !=queue_logical_block_size (disk->queue) || - (ns->ms && ns->ext))) -blk_integrity_unregister (disk); - - ns->pi_type = pi_type; -} -static void nvme_init_integrity (struct nvme_ns *ns) {struct blk_integrity integrity;
@@ -1130,10 +1107,6 @@ static void nvme_init_integrity(struct nvme_ns *ns) blk_queue_max_integrity_segments(ns->queue, 1); }#else -static void nvme_prep_integrity (struct gendisk *disk,struct nvme_id_ns *id, -u16 bs) -{ -}static void nvme_init_integrity (struct nvme_ns *ns) { }
@@ -1202,15 +1175,22 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) ns->lba_shift =9 ; bs =1 << ns->lba_shift; ns->noiob =le16_to_cpu (id->noiob); + ns->ext = ns->ms && (id->flbas &NVME_NS_FLBAS_META_EXT ); + ns->ms =le16_to_cpu (id->lbaf[id->flbas &NVME_NS_FLBAS_LBA_MASK ].ms); +/* 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 ;blk_mq_freeze_queue (disk->queue); +blk_integrity_unregister (disk); -if (ctrl->ops->flags &NVME_F_METADATA_SUPPORTED ) -nvme_prep_integrity (disk, id, bs);blk_queue_logical_block_size (ns->queue, bs);if (ns->noiob)nvme_set_chunk_size (ns); -if (ns->ms && !blk_get_integrity (disk) && !ns->ext) +if (ns->ms && !ns->ext && + (ctrl->ops->flags &NVME_F_METADATA_SUPPORTED ))nvme_init_integrity (ns);if (ns->ms && !(ns->ms ==8 && ns->pi_type) && !blk_get_integrity (disk))set_capacity (disk,0 );
Signature · 1 line
2.14.2
Re: [PATCH 2/6] nvme: always unregister the integrity profile in __nvme_revalidate_disk
Re: [PATCH 2/6] nvme: always unregister the integrity profile in __nvme_revalidate_disk
In reply to Christoph HellwigLooks good.
Christoph Hellwig
maintainerPATCH 3/6 nvme: don't pass struct nvme_ns to nvme_init_integrity
In reply to Christoph HellwigTo allow reusing this function for the multipath node.
--- drivers/nvme/host/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/nvme/host/core.c +7 -7
@@ -1081,12 +1081,12 @@ static int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo) }#ifdef CONFIG_BLK_DEV_INTEGRITY -static void nvme_init_integrity (struct nvme_ns *ns) +static void nvme_init_integrity (struct gendisk *disk,u16 ms,u8 pi_type) {struct blk_integrity integrity;memset (&integrity,0 ,sizeof (integrity)); -switch (ns->pi_type) { +switch (pi_type) {case NVME_NS_DPS_PI_TYPE3 : integrity.profile = &t10_pi_type3_crc; integrity.tag_size =sizeof (u16) +sizeof (u32);
@@ -1102,12 +1102,12 @@ static void nvme_init_integrity(struct nvme_ns *ns) integrity.profile =NULL ; break; } - integrity.tuple_size = ns->ms; -blk_integrity_register (ns->disk, &integrity); -blk_queue_max_integrity_segments (ns->queue,1 ); + integrity.tuple_size = ms; +blk_integrity_register (disk, &integrity); +blk_queue_max_integrity_segments (disk->queue,1 ); }#else -static void nvme_init_integrity (struct nvme_ns *ns) +static void nvme_init_integrity (struct gendisk *disk,u16 ms,u8 pi_type) { }#endif /* CONFIG_BLK_DEV_INTEGRITY */
@@ -1191,7 +1191,7 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)nvme_set_chunk_size (ns);if (ns->ms && !ns->ext && (ctrl->ops->flags &NVME_F_METADATA_SUPPORTED )) -nvme_init_integrity (ns); +nvme_init_integrity (disk, ns->ms, ns->pi_type);if (ns->ms && !(ns->ms ==8 && ns->pi_type) && !blk_get_integrity (disk))set_capacity (disk,0 );else
Signature · 1 line
2.14.2
Re: [PATCH 3/6] nvme: don't pass struct nvme_ns to nvme_init_integrity
Re: [PATCH 3/6] nvme: don't pass struct nvme_ns to nvme_init_integrity
In reply to Christoph HellwigLooks good.
Christoph Hellwig
maintainerPATCH 4/6 nvme: don't pass struct nvme_ns to nvme_config_discard
In reply to Christoph HellwigTo allow reusing this function for the multipath node.
--- drivers/nvme/host/core.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
drivers/nvme/host/core.c +17 -16
@@ -1118,29 +1118,26 @@ static void nvme_set_chunk_size(struct nvme_ns *ns)blk_queue_chunk_sectors (ns->queue,rounddown_pow_of_two (chunk_size)); } -static void nvme_config_discard (struct nvme_ns *ns) +static void nvme_config_discard (struct nvme_ctrl *ctrl, +unsigned stream_alignment,struct request_queue *queue) { -struct nvme_ctrl *ctrl = ns->ctrl; -u32 logical_block_size =queue_logical_block_size (ns->queue); +u32 size =queue_logical_block_size (queue); + +if (stream_alignment) + size *= stream_alignment;BUILD_BUG_ON (PAGE_SIZE /sizeof (struct nvme_dsm_range ) <NVME_DSM_MAX_RANGES ); -if (ctrl->nr_streams && ns->sws && ns->sgs) { -unsigned int sz = logical_block_size * ns->sws * ns->sgs; + queue->limits.discard_alignment = size; + queue->limits.discard_granularity = size; - ns->queue->limits.discard_alignment = sz; - ns->queue->limits.discard_granularity = sz; - }else { - ns->queue->limits.discard_alignment = logical_block_size; - ns->queue->limits.discard_granularity = logical_block_size; - } -blk_queue_max_discard_sectors (ns->queue,UINT_MAX ); -blk_queue_max_discard_segments (ns->queue,NVME_DSM_MAX_RANGES ); -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , ns->queue); +blk_queue_max_discard_sectors (queue,UINT_MAX ); +blk_queue_max_discard_segments (queue,NVME_DSM_MAX_RANGES ); +queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , queue);if (ctrl->quirks &NVME_QUIRK_DEALLOCATE_ZEROES ) -blk_queue_max_write_zeroes_sectors (ns->queue,UINT_MAX ); +blk_queue_max_write_zeroes_sectors (queue,UINT_MAX ); } static void nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid,
@@ -1164,6 +1161,7 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) {struct nvme_ns *ns = disk->private_data;struct nvme_ctrl *ctrl = ns->ctrl; +unsigned stream_alignment =0 ;u16 bs;/*
@@ -1183,6 +1181,9 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)else ns->pi_type =0 ; +if (ctrl->nr_streams && ns->sws && ns->sgs) + stream_alignment = ns->sws * ns->sgs; +blk_mq_freeze_queue (disk->queue);blk_integrity_unregister (disk);
@@ -1198,7 +1199,7 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)set_capacity (disk,le64_to_cpup (&id->nsze) << (ns->lba_shift -9 ));if (ctrl->oncs &NVME_CTRL_ONCS_DSM ) -nvme_config_discard (ns); +nvme_config_discard (ctrl, stream_alignment, disk->queue);blk_mq_unfreeze_queue (disk->queue); }
Signature · 1 line
2.14.2
Re: [PATCH 4/6] nvme: don't pass struct nvme_ns to nvme_config_discard
Looks good.
Christoph Hellwig
maintainerPATCH 5/6 nvme: set the chunk size before freezing the queue
In reply to Christoph HellwigWe don't need a frozen queue to update the chunk_size, which just is a hint, and moving it a little earlier will allow for some better code reuse with the multipath code.
--- drivers/nvme/host/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +3 -2
@@ -1184,12 +1184,13 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)if (ctrl->nr_streams && ns->sws && ns->sgs) stream_alignment = ns->sws * ns->sgs; +if (ns->noiob) +nvme_set_chunk_size (ns); +blk_mq_freeze_queue (disk->queue);blk_integrity_unregister (disk);blk_queue_logical_block_size (ns->queue, bs); -if (ns->noiob) -nvme_set_chunk_size (ns);if (ns->ms && !ns->ext && (ctrl->ops->flags &NVME_F_METADATA_SUPPORTED ))nvme_init_integrity (disk, ns->ms, ns->pi_type);
Signature · 1 line
2.14.2
Re: [PATCH 5/6] nvme: set the chunk size before freezing the queue
Looks fine.
Christoph Hellwig
maintainerPATCH 6/6 nvme: split __nvme_revalidate_disk
In reply to Christoph HellwigSplit out the code that applies the calculate value to a given disk/queue into new helper that can be reused by the multipath code.
--- drivers/nvme/host/core.c | 49 +++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-)
drivers/nvme/host/core.c +26 -23
@@ -1157,12 +1157,34 @@ static void nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid, } } +static void nvme_update_disk_info (struct gendisk *disk, +struct nvme_ns *ns,struct nvme_id_ns *id) +{ +sector_t capacity =le64_to_cpup (&id->nsze) << (ns->lba_shift -9 ); +unsigned stream_alignment =0 ; + +if (ns->ctrl->nr_streams && ns->sws && ns->sgs) + stream_alignment = ns->sws * ns->sgs; + +blk_mq_freeze_queue (disk->queue); +blk_integrity_unregister (disk); + +blk_queue_logical_block_size (disk->queue,1 << ns->lba_shift); +if (ns->ms && !ns->ext && + (ns->ctrl->ops->flags &NVME_F_METADATA_SUPPORTED )) +nvme_init_integrity (disk, ns->ms, ns->pi_type); +if (ns->ms && !(ns->ms ==8 && ns->pi_type) && !blk_get_integrity (disk)) + capacity =0 ; +set_capacity (disk, capacity); + +if (ns->ctrl->oncs &NVME_CTRL_ONCS_DSM ) +nvme_config_discard (ns->ctrl, stream_alignment, disk->queue); +blk_mq_unfreeze_queue (disk->queue); +} +static void __nvme_revalidate_disk (struct gendisk *disk,struct nvme_id_ns *id) {struct nvme_ns *ns = disk->private_data; -struct nvme_ctrl *ctrl = ns->ctrl; -unsigned stream_alignment =0 ; -u16 bs;/* * If identify namespace failed, use default 512 byte block size so
@@ -1171,7 +1193,6 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) ns->lba_shift = id->lbaf[id->flbas &NVME_NS_FLBAS_LBA_MASK ].ds;if (ns->lba_shift ==0 ) ns->lba_shift =9 ; - bs =1 << ns->lba_shift; ns->noiob =le16_to_cpu (id->noiob); ns->ext = ns->ms && (id->flbas &NVME_NS_FLBAS_META_EXT ); ns->ms =le16_to_cpu (id->lbaf[id->flbas &NVME_NS_FLBAS_LBA_MASK ].ms);
@@ -1181,27 +1202,9 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)else ns->pi_type =0 ; -if (ctrl->nr_streams && ns->sws && ns->sgs) - stream_alignment = ns->sws * ns->sgs; -if (ns->noiob)nvme_set_chunk_size (ns); - -blk_mq_freeze_queue (disk->queue); -blk_integrity_unregister (disk); - -blk_queue_logical_block_size (ns->queue, bs); -if (ns->ms && !ns->ext && - (ctrl->ops->flags &NVME_F_METADATA_SUPPORTED )) -nvme_init_integrity (disk, ns->ms, ns->pi_type); -if (ns->ms && !(ns->ms ==8 && ns->pi_type) && !blk_get_integrity (disk)) -set_capacity (disk,0 ); -else -set_capacity (disk,le64_to_cpup (&id->nsze) << (ns->lba_shift -9 )); - -if (ctrl->oncs &NVME_CTRL_ONCS_DSM ) -nvme_config_discard (ctrl, stream_alignment, disk->queue); -blk_mq_unfreeze_queue (disk->queue); +nvme_update_disk_info (disk, ns, id); }static int nvme_revalidate_disk (struct gendisk *disk)
Signature · 1 line
2.14.2
Re: [PATCH 6/6] nvme: split __nvme_revalidate_disk
Re: [PATCH 6/6] nvme: split __nvme_revalidate_disk
In reply to Christoph HellwigLooks good.