From: Yu Kuai <yukuai@kernel.org>
To: Tejun Heo <tj@kernel.org>, Josef Bacik <josef@toxicpanda.com>,
Jens Axboe <axboe@kernel.dk>
Cc: Zheng Qixing <zhengqixing@huawei.com>,
Christoph Hellwig <hch@lst.de>,
Tang Yizhou <yizhou.tang@shopee.com>,
Nilay Shroff <nilay@linux.ibm.com>,
Ming Lei <ming.lei@redhat.com>,
cgroups@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] md/linear: add fault-tolerant mode for unraid-like setups
Date: Wed, 24 Jun 2026 14:46:19 +0800 [thread overview]
Message-ID: <20260624064625.1743650-1-yukuai@kernel.org> (raw)
From: Yu Kuai <yukuai@fnnas.com>
Add a module parameter 'fault_tolerant' that changes how md-linear
handles disk failures. When enabled:
- Disk failures are isolated instead of failing the entire array
- I/O to failed disks returns -EIO while healthy disks continue
- The array remains operational with reduced capacity
- Failed disk count is tracked and shown in /proc/mdstat
This enables unraid-like functionality where individual disk failures
don't bring down the entire array, allowing continued access to data
on healthy disks.
The fault_tolerant parameter can be set at module load time or
dynamically via /sys/module/md_linear/parameters/fault_tolerant.
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
---
drivers/md/md-linear.c | 63 ++++++++++++++++++++++++++++++++++++------
1 file changed, 55 insertions(+), 8 deletions(-)
diff --git a/drivers/md/md-linear.c b/drivers/md/md-linear.c
index 8d7b82c4a723..8afc6665cfde 100644
--- a/drivers/md/md-linear.c
+++ b/drivers/md/md-linear.c
@@ -2,6 +2,10 @@
/*
* linear.c : Multiple Devices driver for Linux Copyright (C) 1994-96 Marc
* ZYNGIER <zyngier@ufr-info-p7.ibp.fr> or <maz@gloups.fdn.fr>
+ *
+ * Fault-tolerant mode added for unraid-like setups.
+ * When fault_tolerant=1, disk failures are isolated - I/O to failed disks
+ * returns -EIO while healthy disks continue operating normally.
*/
#include <linux/blkdev.h>
@@ -21,9 +25,15 @@ struct linear_conf {
sector_t array_sectors;
/* a copy of mddev->raid_disks */
int raid_disks;
+ atomic_t failed_disks; /* count of failed disks */
struct dev_info disks[] __counted_by(raid_disks);
};
+static bool fault_tolerant;
+module_param(fault_tolerant, bool, 0644);
+MODULE_PARM_DESC(fault_tolerant,
+ "Enable fault-tolerant mode: isolate disk failures instead of failing array (default: false)");
+
/*
* find which device holds a particular offset
*/
@@ -96,6 +106,8 @@ static struct linear_conf *linear_conf(struct mddev *mddev, int raid_disks)
if (!conf)
return ERR_PTR(-ENOMEM);
+ atomic_set(&conf->failed_disks, 0);
+
/*
* conf->raid_disks is copy of mddev->raid_disks. The reason to
* keep a copy of mddev->raid_disks in struct linear_conf is,
@@ -251,7 +263,8 @@ static bool linear_make_request(struct mddev *mddev, struct bio *bio)
bio_sector < start_sector))
goto out_of_bounds;
- if (unlikely(is_rdev_broken(tmp_dev->rdev))) {
+ if (unlikely(is_rdev_broken(tmp_dev->rdev) ||
+ test_bit(Faulty, &tmp_dev->rdev->flags))) {
md_error(mddev, tmp_dev->rdev);
bio_io_error(bio);
return true;
@@ -296,16 +309,47 @@ static bool linear_make_request(struct mddev *mddev, struct bio *bio)
static void linear_status(struct seq_file *seq, struct mddev *mddev)
{
+ struct linear_conf *conf = mddev->private;
+
seq_printf(seq, " %dk rounding", mddev->chunk_sectors / 2);
+ if (fault_tolerant) {
+ int failed = atomic_read(&conf->failed_disks);
+
+ seq_puts(seq, " fault-tolerant");
+ if (failed)
+ seq_printf(seq, " [%d failed]", failed);
+ }
}
static void linear_error(struct mddev *mddev, struct md_rdev *rdev)
{
- if (!test_and_set_bit(MD_BROKEN, &mddev->flags)) {
- char *md_name = mdname(mddev);
-
- pr_crit("md/linear%s: Disk failure on %pg detected, failing array.\n",
- md_name, rdev->bdev);
+ char *md_name = mdname(mddev);
+
+ if (fault_tolerant) {
+ /*
+ * Fault-tolerant mode: isolate the failed disk instead of
+ * failing the entire array. I/O to this disk will return -EIO
+ * but other disks continue operating normally.
+ */
+ if (!test_and_set_bit(Faulty, &rdev->flags)) {
+ struct linear_conf *conf = mddev->private;
+
+ atomic_inc(&conf->failed_disks);
+ pr_warn("md/linear%s: Disk failure on %pg detected, isolating device (fault-tolerant mode).\n",
+ md_name, rdev->bdev);
+ pr_warn("md/linear%s: %d disk(s) now failed, array continues with reduced capacity.\n",
+ md_name, atomic_read(&conf->failed_disks));
+ /* Notify userspace about the state change */
+ sysfs_notify_dirent_safe(rdev->sysfs_state);
+ }
+ } else {
+ /*
+ * Standard mode: fail the entire array on any disk failure.
+ */
+ if (!test_and_set_bit(MD_BROKEN, &mddev->flags)) {
+ pr_crit("md/linear%s: Disk failure on %pg detected, failing array.\n",
+ md_name, rdev->bdev);
+ }
}
}
@@ -344,7 +388,7 @@ static void linear_exit(void)
module_init(linear_init);
module_exit(linear_exit);
MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Linear device concatenation personality for MD (deprecated)");
+MODULE_DESCRIPTION("Linear device concatenation personality for MD with optional fault-tolerant mode");
MODULE_ALIAS("md-personality-1"); /* LINEAR - deprecated*/
MODULE_ALIAS("md-linear");
MODULE_ALIAS("md-level--1");
--
2.43.0
next reply other threads:[~2026-06-24 6:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 6:46 Yu Kuai [this message]
2026-06-24 6:46 ` [PATCH 2/2] ext4: add unraid mount option for single-disk-per-group mode Yu Kuai
2026-06-24 6:46 ` [PATCH v2 0/4] blk-cgroup: fix blkg list and policy data races Yu Kuai
2026-06-24 6:46 ` [PATCH v2 1/4] blk-cgroup: protect q->blkg_list iteration in blkg_destroy_all() with blkcg_mutex Yu Kuai
2026-06-24 6:46 ` [PATCH v2 2/4] blk-cgroup: fix race between policy activation and blkg destruction Yu Kuai
2026-06-25 15:08 ` Nilay Shroff
2026-06-26 1:50 ` yu kuai
2026-06-26 1:52 ` yu kuai
2026-06-26 6:12 ` Nilay Shroff
2026-06-27 4:13 ` yu kuai
2026-06-29 5:33 ` Nilay Shroff
2026-06-29 9:03 ` yu kuai
2026-06-24 6:46 ` [PATCH v2 3/4] blk-cgroup: skip dying blkg in blkcg_activate_policy() Yu Kuai
2026-06-24 6:46 ` [PATCH v2 4/4] blk-cgroup: factor policy pd teardown loop into helper Yu Kuai
2026-06-24 6:55 ` [PATCH 1/2] md/linear: add fault-tolerant mode for unraid-like setups yu kuai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260624064625.1743650-1-yukuai@kernel.org \
--to=yukuai@kernel.org \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nilay@linux.ibm.com \
--cc=tj@kernel.org \
--cc=yizhou.tang@shopee.com \
--cc=zhengqixing@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.