Skip to content

RFC md: add a control device for array management

Abd-Alrhman Masalkhi linux-raid lkml sashiko-reviews 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 RFC Latest4 patches 1 replyIn review
  2. v2 RFC4 patches 1 replySuperseded
  3. v12 patches 0 repliesSuperseded

Changes in v5 from the cover letter

- Add MD_CTL_LOOKUP_ARRAY command.
- Improve the warning message in md_ioctl()
- Rename convert_to_array_info64() to array_info_to_64()
- Rename convert_to_disk_info64() to disk_info_to_64()
- Documented the fields on mdu_ioctl in md_u.h
- Link-v4: https://lore.kernel.org/linux-raid/[email protected]/

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4md: add uapi definitions for the md control deviceinclude/uapi/linux/raid/md_u.h+119 -00 replies
2/4md: pass struct mdu_disk_info64 to md_add_new_disk()drivers/md/md-autodetect.c drivers/md/md.c drivers/md/md.h+23 -80 replies
3/4md: use struct mdu_array_info64 for SET_ARRAY_INFOdrivers/md/md-autodetect.c drivers/md/md.c drivers/md/md.h+34 -90 replies
4/4md: add a control device for array managementdrivers/md/md.c drivers/md/md.h+638 -31 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [RFC PATCH v5 0/4] md: add a control device for array management

Hi,

This series adds a new /dev/md-control misc character device for managing md arrays without opening the corresponding md block device.

Currently, md management ioctls are issued on the md block device itself, which requires the caller to hold the array open while configuring or stopping it.

This is a problem for STOP_ARRAY and STOP_ARRAY_RO. Before the array is stopped, the page cache must be flushed, and no other task may have the device open or be writing to it. The issue arises when several tasks share the same file descriptor table, as they count as a single opener. Consequently, one task may still be writing while another task flushes the page cache and stops the array. A write within this window can race with the stop operation.

The solution was suggested by Yu Kuai and Zhihao Cheng. See the following discussions:

https://lore.kernel.org/linux-raid/[email protected]/
https://lore.kernel.org/linux-raid/[email protected]/

The new control device is not tied to any md array. Each request identifies the target array by name, UUID (it is only available for arrays with native metadata), or device number, and carries a flags field. Unknown flags are rejected with -ENOTTY.

The commands mirror the existing block device ioctls. They use the MD_MAJOR ioctl type, with numbers starting at 0x40, grouped like the old ones: status at 0x40, configuration at 0x50 and usage at 0x60.

STOP_ARRAY_RO has no separate command: MD_CTL_STOP_ARRAY with MD_CTL_RO_FLAG set switches the array to read-only mode instead of stopping it.

MD_CTL_LOOKUP_ARRAY has no equivalent among the legacy ioctls. Given the kernel name, device number, or UUID of an array, it returns all three identifiers. It also indicates whether the array exists, even if it has not yet been configured. It returns ENODEV only if no such MD device exists. For arrays using external metadata or having no superblock, the UUID is returned as all zeros.

New 64-bit structures, including mdu_ioctl, are introduced (mdu_array_info64, mdu_disk_info64, mdu_param64, mdu_bitmap_file64, and mdu_version64) to resolve padding and overflow issues in fields such as size, ctime, and utime.

The existing ioctl on the md block device is unchanged, but a warning message will be printed to recommend using the md control node and indicate that the per-array MD ioctls will be removed in the future.

This is an RFC because the new UAPI (struct mdu_ioctl, mdu_array_info64, mdu_disk_info64, mdu_param64, and mdu_version64 and the new command set).

Testing:

mdadm test suite on qemu-system-aarch64 without KVM (Cortex-A57, 4 CPUs, Yocto kirkstone), using:

  ./test --keep-going --skip-broken --skip-bigcase

mdadm builds:

- upstream: commit c940aae94ac5
- patched: https://github.com/masalkhi/mdadm

Test configurations:

- Linux v7.3-rc2 (5c2f4115051d) + this series:
- patched mdadm, using /dev/md-control
- patched mdadm with MDADM_NO_CTL_NODE=1 (legacy ioctls)
- upstream mdadm (legacy ioctls)
- Linux v7.3-rc2 (5c2f4115051d) without this series:
- patched mdadm (no control node, so legacy ioctls)

All runs give the same result with upstream mdadm.

Changes in v5:
- Add MD_CTL_LOOKUP_ARRAY command.
- Improve the warning message in md_ioctl()
- Rename convert_to_array_info64() to array_info_to_64()
- Rename convert_to_disk_info64() to disk_info_to_64()
- Documented the fields on mdu_ioctl in md_u.h
- Link-v4: https://lore.kernel.org/linux-raid/[email protected]/

Changes in v4:
- Drop struct mdu_bitmap_file64 and keep using mdu_bitmap_file_t.
- Remove MD_RAID_AUTORUN, since the kernel has not supported
the corresponding RAID_AUTORUN since v5.9
- Rename the ioctl commands from MD_* to MD_CTL_*
- Fix MD_CTL_CLOSING mutual exclusion in mdctl_ioctl, reported by
Sashiko AI: https://sashiko.dev/#/patchset/[email protected]?part=4
- Link-v3: https://lore.kernel.org/linux-raid/[email protected]

Changes in v3:
- Fix the issues reported by sashiko-bot, Link: https://sashiko.dev/#/patchset/[email protected]?part=4
- Link-v2: https://lore.kernel.org/linux-raid/[email protected]/

Changes in v2:
- Move the code from md-ctl.c into md.c and remove md-ctl.c.
- Handle the new commands directly in mdctl_ioctl() instead of
converting them to the old ioctls.
- Use a dynamic misc minor number for /dev/md-control.
- Drop the devname module alias, which only works with a fixed minor.
- Fix the issues reported by sashiko-bot.
- Take disks_mutex around the lookups, so that they never see an
mddev that md_alloc() has not finished.
- Clear hold_active only when a command succeeds.
- Link-v1: https://lore.kernel.org/linux-raid/[email protected]

Abd-Alrhman Masalkhi (4):
md: add uapi definitions for the md control device
md: pass struct mdu_disk_info64 to md_add_new_disk()
md: use struct mdu_array_info64 for SET_ARRAY_INFO
md: add a control device for array management

 drivers/md/md-autodetect.c     |   4 +-
 drivers/md/md.c                | 694 ++++++++++++++++++++++++++++++++-
 drivers/md/md.h                |  17 +-
 include/uapi/linux/raid/md_u.h | 119 ++++++
 4 files changed, 814 insertions(+), 20 deletions(-)

base-commit: 5c2f4115051d064ad79b0b4edac70a2b62528d9d

Signature · 1 line
2.43.0