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

From: Abd-Alrhman Masalkhi

Date: Thu Oct 01 2026 - 09:23:10 EST


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 new control device is not tied to any md array. Each request
identifies the target array by name, UUID, or device number, and
carries a flags field. Unknown flags are rejected with -ENOTTY. The new
commands mirror the existing md block-device ioctls, with STOP_ARRAY_RO
represented by MD_STOP_ARRAY with MD_RO_FLAG set.

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 md block-device ioctl interface remains unchanged.
A warning is emitted when it is used to recommend upgrading mdadm to
use the new control interface.

The mdadm has been modified correspondingly:
Link: https://lore.kernel.org/linux-raid/20260928211849.3602414-1-abd.masalkhi@xxxxxxxxx

This is an RFC because the new UAPI (struct mdu_ioctl, mdu_array_info64,
mdu_disk_info64, mdu_param64, mdu_bitmap_file64, and mdu_version64 and
the new command set). I am thinking about adding a new command
MD_NEW_ARRAY or MD_CREATE_ARRAY to create a new array. Feedback on the
interface is welcome.

I am aslo considering adding a command to create a new array
MD_NEW_ARRAY/MD_CREATE_ARRAY.

I am thinking of adding a new command MD_NEW_ARRAY or MD_CREATE_ARRAY
to create a new array.

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/20260928201224.3602262-1-abd.masalkhi@xxxxxxxxx

Abd-Alrhman Masalkhi

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 | 700 ++++++++++++++++++++++++++++++++-
drivers/md/md.h | 17 +-
include/uapi/linux/raid/md_u.h | 119 ++++++
4 files changed, 820 insertions(+), 20 deletions(-)


base-commit: 5c2f4115051d064ad79b0b4edac70a2b62528d9d
--
2.43.0