[PATCH v2] nvme: invalidate paths during rescan
Sagi Grimberg
sagi at grimberg.me
Tue Aug 10 18:18:01 PDT 2021
On 7/30/21 12:10 AM, Daniel Wagner wrote:
> From: Hannes Reinecke <hare at suse.de>
>
> When triggering a rescan due to a namespace resize we will be
> receiving AENs on every controller, triggering a rescan of all
> attached namespaces. If multipath is active only the current path and
> the ns_head disk will be updated, the other paths will still refer to
> the old size until AENs for the remaining controllers are received.
>
> If I/O comes in before that it might be routed to one of the old
> paths, triggering an I/O failure with 'access beyond end of device'.
> With this patch the old paths are skipped from multipath path
> selection until the controller serving these paths has been rescanned.
>
> Signed-off-by: Hannes Reinecke <hare at suse.de>
> Tested-by: Daniel Wagner <dwagner at suse.de>
> Signed-off-by: Daniel Wagner <dwagner at suse.de>
> ---
> v2:
> - removed churn from failed rebase.
> v1:
> - https://lore.kernel.org/linux-nvme/20210729194630.i5mhvvgb73duojqq@beryllium.lan/
>
> drivers/nvme/host/core.c | 2 ++
> drivers/nvme/host/multipath.c | 16 ++++++++++++++++
> drivers/nvme/host/nvme.h | 5 +++++
> 3 files changed, 23 insertions(+)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index dfd9dec0c1f6..20a079083129 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1877,6 +1877,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)
> goto out_unfreeze;
> }
>
> + clear_bit(NVME_NS_INVALIDATED, &ns->flags);
> blk_mq_unfreeze_queue(ns->disk->queue);
>
> if (blk_queue_is_zoned(ns->queue)) {
> @@ -1888,6 +1889,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)
> if (nvme_ns_head_multipath(ns->head)) {
> blk_mq_freeze_queue(ns->head->disk->queue);
> nvme_update_disk_info(ns->head->disk, ns, id);
> + nvme_mpath_invalidate_paths(ns);
> blk_stack_limits(&ns->head->disk->queue->limits,
> &ns->queue->limits, 0);
> blk_queue_update_readahead(ns->head->disk->queue);
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 3f32c5e86bfc..579020ae058d 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -147,6 +147,21 @@ void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl)
> mutex_unlock(&ctrl->scan_lock);
> }
>
> +void nvme_mpath_invalidate_paths(struct nvme_ns *ns)
invalidate is not a great name for this very specific case here.
> +{
> + struct nvme_ns_head *head = ns->head;
> + sector_t capacity = get_capacity(head->disk);
> + int node;
> +
> + for_each_node(node)
> + rcu_assign_pointer(head->current_path[node], NULL);
Here the ns can get re-selected as the current path.
> +
> + list_for_each_entry_rcu(ns, &head->list, siblings) {
> + if (capacity != get_capacity(ns->disk))
> + set_bit(NVME_NS_INVALIDATED, &ns->flags);
maybe instead of invalidated reverse the polarity with
NVME_NS_READY? clear it here and set it in update_ns_info?
More information about the Linux-nvme
mailing list