Skip to content

Ensure ordered namespace registration during async scan

Maurizio Lombardi linux-nvme linux-scsi oe-kbuild-all 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 15 repliesIn review
  2. v23 patches 3 repliesSuperseded
  3. v1 RFC1 patch 3 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3lib: Introduce completion chain helperinclude/linux/compl_chain.h lib/Makefile lib/compl_chain.c+154 -10 replies
2/3nvme-core: register namespaces in order during async scandrivers/nvme/host/core.c drivers/nvme/host/nvme.h+62 -340 replies
3/3scsi: Convert async scanning to use the completion chain helperdrivers/scsi/scsi_priv.h drivers/scsi/scsi_scan.c+9 -610 replies

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

PatchChristoph Hellwig
1/3R-b
2/3R-b
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH V3 0/3] Ensure ordered namespace registration during async scan

The NVMe fully asynchronous namespace scanning introduced in commit 4e893ca81170 ("nvme-core: scan namespaces asynchronously") significantly improved discovery times. However, it also introduced non-deterministic ordering for namespace registration.

While kernel device names (/dev/nvmeXnY) are not guaranteed to be stable across reboots, this unpredictable ordering has caused considerable user confusion and has been perceived as a regression, leading to multiple bug reports.

This series introduces a solution to enforce strict sequential registration based on NSID order, entirely preserving the performance benefits of the asynchronous scan approach.

Instead of adding an NVMe-specific hack, this series abstracts the serialization mechanism currently open-coded in the SCSI subsystem (drivers/scsi/scsi_scan.c) into a generic library helper called the completion chain (compl_chain).

By enforcing a strict First-In, First-Out (FIFO) completion order for asynchronous tasks, we can ensure that namespaces are allocated and registered sequentially without blocking the underlying parallel discovery processes.

PATCH 3 Refactors the existing SCSI asynchronous scanning implementation to use the new compl_chain helper, stripping out the custom, open-coded task list and reducing code duplication.

Original code:

$ nvme list
Node                  Generic               Namespace
--------------------- --------------------- ----------
/dev/nvme0n1          /dev/ng0n1            0x2
/dev/nvme0n2          /dev/ng0n2            0x1
/dev/nvme0n3          /dev/ng0n3            0x5
/dev/nvme0n4          /dev/ng0n4            0x3
/dev/nvme0n5          /dev/ng0n5            0x4
[...]
/dev/nvme0n10         /dev/ng0n10           0xa
/dev/nvme0n11         /dev/ng0n11           0x8
/dev/nvme0n12         /dev/ng0n12           0x12
/dev/nvme0n13         /dev/ng0n13           0x17
/dev/nvme0n14         /dev/ng0n14           0xc
/dev/nvme0n15         /dev/ng0n15           0x11
/dev/nvme0n16         /dev/ng0n16           0x14
/dev/nvme0n17         /dev/ng0n17           0x13
/dev/nvme0n18         /dev/ng0n18           0xe
/dev/nvme0n19         /dev/ng0n19           0xf

With this patch:

$ nvme list
Node                  Generic               Namespace
--------------------- --------------------- ----------
/dev/nvme0n1          /dev/ng0n1            0x1
/dev/nvme0n2          /dev/ng0n2            0x2
/dev/nvme0n3          /dev/ng0n3            0x3
/dev/nvme0n4          /dev/ng0n4            0x4
/dev/nvme0n5          /dev/ng0n5            0x5
/dev/nvme0n6          /dev/ng0n6            0x6
[...]
/dev/nvme0n10         /dev/ng0n10           0xa
/dev/nvme0n11         /dev/ng0n11           0xb
/dev/nvme0n12         /dev/ng0n12           0xc
/dev/nvme0n13         /dev/ng0n13           0xd
/dev/nvme0n14         /dev/ng0n14           0xe
/dev/nvme0n15         /dev/ng0n15           0xf
/dev/nvme0n16         /dev/ng0n16           0x10
/dev/nvme0n17         /dev/ng0n17           0x11
/dev/nvme0n18         /dev/ng0n18           0x12
/dev/nvme0n19         /dev/ng0n19           0x13

V3: fixed some comments
PATCH 3: declare scanning_hosts as static remove "extern" keyword from scsi_complete_async_scans() prototype declaration

V2: create the compl_chain helper that both SCSI and NVMe can share

Maurizio Lombardi (3):
lib: Introduce completion chain helper
nvme-core: register namespaces in order during async scan
scsi: Convert async scanning to use the completion chain helper

 drivers/nvme/host/core.c    |  94 +++++++++++++++++-----------
 drivers/nvme/host/nvme.h    |   2 +
 drivers/scsi/scsi_priv.h    |   2 +-
 drivers/scsi/scsi_scan.c    |  68 +++------------------
 include/linux/compl_chain.h |  35 +++++++++++
 lib/Makefile                |   2 +-
 lib/compl_chain.c           | 118 ++++++++++++++++++++++++++++++++++++
 7 files changed, 225 insertions(+), 96 deletions(-)
 create mode 100644 include/linux/compl_chain.h
 create mode 100644 lib/compl_chain.c
Signature · 1 line
2.53.0