]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
md: Add new_level sysfs interface
authorXiao Ni <xni@redhat.com>
Wed, 4 Sep 2024 23:54:53 +0000 (07:54 +0800)
committerSong Liu <song@kernel.org>
Fri, 6 Sep 2024 17:31:12 +0000 (10:31 -0700)
Now reshape supports two ways: with backup file or without backup file.
For the situation without backup file, it needs to change data offset.
It doesn't need systemd service mdadm-grow-continue. So it can finish
the reshape job in one process environment. It can know the new level
from mdadm --grow command and can change to new level after reshape
finishes.

For the situation with backup file, it needs systemd service
mdadm-grow-continue to monitor reshape progress. So there are two process
envolved. One is mdadm --grow command whick kicks off reshape and wakes
up mdadm-grow-continue service. The second process is the service, which
doesn't know the new level from the first process.

In kernel space mddev->new_level is used to record the new level when
doing reshape. This patch adds a new interface to help mdadm update
new_level and sync it to metadata. Then mdadm-grow-continue can read the
right new_level.

Commit log revised by Song Liu. Please refer to the link for more details.

Signed-off-by: Xiao Ni <xni@redhat.com>
Link: https://lore.kernel.org/r/20240904235453.99120-1-xni@redhat.com
Signed-off-by: Song Liu <song@kernel.org>
drivers/md/md.c

index b669971d47822c309245be1b982dc91d9ebab3ce..179ee4afe9376610db586d253982892be0512252 100644 (file)
@@ -4052,6 +4052,34 @@ out_unlock:
 static struct md_sysfs_entry md_level =
 __ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store);
 
+static ssize_t
+new_level_show(struct mddev *mddev, char *page)
+{
+       return sprintf(page, "%d\n", mddev->new_level);
+}
+
+static ssize_t
+new_level_store(struct mddev *mddev, const char *buf, size_t len)
+{
+       unsigned int n;
+       int err;
+
+       err = kstrtouint(buf, 10, &n);
+       if (err < 0)
+               return err;
+       err = mddev_lock(mddev);
+       if (err)
+               return err;
+
+       mddev->new_level = n;
+       md_update_sb(mddev, 1);
+
+       mddev_unlock(mddev);
+       return len;
+}
+static struct md_sysfs_entry md_new_level =
+__ATTR(new_level, 0664, new_level_show, new_level_store);
+
 static ssize_t
 layout_show(struct mddev *mddev, char *page)
 {
@@ -5583,6 +5611,7 @@ __ATTR(serialize_policy, S_IRUGO | S_IWUSR, serialize_policy_show,
 
 static struct attribute *md_default_attrs[] = {
        &md_level.attr,
+       &md_new_level.attr,
        &md_layout.attr,
        &md_raid_disks.attr,
        &md_uuid.attr,