Skip to content

Commit e7d6580

Browse files
hreineckeChristoph Hellwig
authored andcommitted
nvme-multipath: revalidate paths during rescan
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 <[email protected]> [dwagner: - introduce NVME_NS_READY flag instead of NVME_NS_INVALIDATE - use 'revalidate' instead of 'invalidate' which follows the zoned device code path. - clear NVME_NS_READY before clearing current_path] Signed-off-by: Daniel Wagner <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent d32d3d0 commit e7d6580

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

drivers/nvme/host/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)
18741874
goto out_unfreeze;
18751875
}
18761876

1877+
set_bit(NVME_NS_READY, &ns->flags);
18771878
blk_mq_unfreeze_queue(ns->disk->queue);
18781879

18791880
if (blk_queue_is_zoned(ns->queue)) {
@@ -1885,6 +1886,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)
18851886
if (nvme_ns_head_multipath(ns->head)) {
18861887
blk_mq_freeze_queue(ns->head->disk->queue);
18871888
nvme_update_disk_info(ns->head->disk, ns, id);
1889+
nvme_mpath_revalidate_paths(ns);
18881890
blk_stack_limits(&ns->head->disk->queue->limits,
18891891
&ns->queue->limits, 0);
18901892
disk_update_readahead(ns->head->disk);
@@ -3795,6 +3797,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)
37953797
if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags))
37963798
return;
37973799

3800+
clear_bit(NVME_NS_READY, &ns->flags);
37983801
set_capacity(ns->disk, 0);
37993802
nvme_fault_inject_fini(&ns->fault_inject);
38003803

drivers/nvme/host/multipath.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl)
147147
mutex_unlock(&ctrl->scan_lock);
148148
}
149149

150+
void nvme_mpath_revalidate_paths(struct nvme_ns *ns)
151+
{
152+
struct nvme_ns_head *head = ns->head;
153+
sector_t capacity = get_capacity(head->disk);
154+
int node;
155+
156+
list_for_each_entry_rcu(ns, &head->list, siblings) {
157+
if (capacity != get_capacity(ns->disk))
158+
clear_bit(NVME_NS_READY, &ns->flags);
159+
}
160+
161+
for_each_node(node)
162+
rcu_assign_pointer(head->current_path[node], NULL);
163+
}
164+
150165
static bool nvme_path_is_disabled(struct nvme_ns *ns)
151166
{
152167
/*
@@ -158,7 +173,7 @@ static bool nvme_path_is_disabled(struct nvme_ns *ns)
158173
ns->ctrl->state != NVME_CTRL_DELETING)
159174
return true;
160175
if (test_bit(NVME_NS_ANA_PENDING, &ns->flags) ||
161-
test_bit(NVME_NS_REMOVING, &ns->flags))
176+
!test_bit(NVME_NS_READY, &ns->flags))
162177
return true;
163178
return false;
164179
}

drivers/nvme/host/nvme.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ struct nvme_ns {
456456
#define NVME_NS_DEAD 1
457457
#define NVME_NS_ANA_PENDING 2
458458
#define NVME_NS_FORCE_RO 3
459+
#define NVME_NS_READY 4
459460

460461
struct cdev cdev;
461462
struct device cdev_device;
@@ -748,6 +749,7 @@ void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl);
748749
void nvme_mpath_uninit(struct nvme_ctrl *ctrl);
749750
void nvme_mpath_stop(struct nvme_ctrl *ctrl);
750751
bool nvme_mpath_clear_current_path(struct nvme_ns *ns);
752+
void nvme_mpath_revalidate_paths(struct nvme_ns *ns);
751753
void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl);
752754
void nvme_mpath_shutdown_disk(struct nvme_ns_head *head);
753755

@@ -795,6 +797,9 @@ static inline bool nvme_mpath_clear_current_path(struct nvme_ns *ns)
795797
{
796798
return false;
797799
}
800+
static inline void nvme_mpath_revalidate_paths(struct nvme_ns *ns)
801+
{
802+
}
798803
static inline void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl)
799804
{
800805
}

0 commit comments

Comments
 (0)