From: Yufen Yu <yuyufen@huawei.com>
To: song@kernel.org
Cc: linux-raid@vger.kernel.org, neilb@suse.com,
guoqing.jiang@cloud.ionos.com, houtao1@huawei.com,
yuyufen@huawei.com
Subject: [PATCH v4 12/15] md/raid5: support config stripe_size by sysfs entry
Date: Fri, 12 Jun 2020 19:42:17 +0800 [thread overview]
Message-ID: <20200612114220.13126-13-yuyufen@huawei.com> (raw)
In-Reply-To: <20200612114220.13126-1-yuyufen@huawei.com>
After this patch, we can adjust stripe_size by writing value into sysfs
entry, likely, set stripe_size as 16KB:
echo 16384 > /sys/block/md1/md/stripe_size
stripe_size should not be bigger than PAGE_SIZE, and it requires to be
multiple of 4096.
Signed-off-by: Yufen Yu <yuyufen@huawei.com>
---
drivers/md/raid5.c | 66 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 65 insertions(+), 1 deletion(-)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 455a22c22b5d..8d940c1c12de 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6709,7 +6709,71 @@ raid5_show_stripe_size(struct mddev *mddev, char *page)
static ssize_t
raid5_store_stripe_size(struct mddev *mddev, const char *page, size_t len)
{
- return -EINVAL;
+ struct r5conf *conf = mddev->private;
+ unsigned int new;
+ int err;
+ int nr;
+
+ if (len >= PAGE_SIZE)
+ return -EINVAL;
+ if (kstrtouint(page, 10, &new))
+ return -EINVAL;
+ if (!conf)
+ return -ENODEV;
+ if (new == conf->stripe_size)
+ return len;
+
+ /*
+ * When PAGE_SZIE is 4096, we don't need to modify stripe_size.
+ * And the value should not be bigger than PAGE_SIZE.
+ * It requires to be multiple of 4096.
+ */
+ if (PAGE_SIZE == 4096 || new % 4096 != 0 ||
+ new > PAGE_SIZE || new == 0)
+ return -EINVAL;
+
+ pr_debug("md/raid: change stripe_size from %u to %u\n",
+ conf->stripe_size, new);
+
+ err = mddev_lock(mddev);
+ if (err)
+ return err;
+
+ if (mddev->sync_thread ||
+ test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
+ mddev->reshape_position != MaxSector ||
+ mddev->sysfs_active) {
+ err = -EBUSY;
+ goto out_unlock;
+ }
+
+ nr = conf->max_nr_stripes;
+
+ /* 1. suspend raid array */
+ mddev_suspend(mddev);
+
+ /* 2. free all old stripe_head */
+ mutex_lock(&conf->cache_size_mutex);
+ shrink_stripes(conf);
+ BUG_ON(conf->max_nr_stripes != 0);
+
+ /* 3. set new stripe_size */
+ conf->stripe_size = new;
+ conf->stripe_shift = ilog2(new) - 9;
+ conf->stripe_sectors = new >> 9;
+
+ /* 4. allocate new stripe_head */
+ if (grow_stripes(conf, nr))
+ pr_warn("md/raid:%s: couldn't allocate buffers\n",
+ mdname(mddev));
+ mutex_unlock(&conf->cache_size_mutex);
+
+ /* 5. resume raid array */
+ mddev_resume(mddev);
+
+out_unlock:
+ mddev_unlock(mddev);
+ return err ?: len;
}
static struct md_sysfs_entry
--
2.21.3
next prev parent reply other threads:[~2020-06-12 11:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-12 11:42 [PATCH v4 00/15] md/raid5: set STRIPE_SIZE as a configurable value Yufen Yu
2020-06-12 11:42 ` [PATCH v4 01/15] md/raid456: covert macro define of STRIPE_* as members of struct r5conf Yufen Yu
2020-06-14 2:28 ` Xiao Ni
2020-06-15 7:17 ` Yufen Yu
2020-06-12 11:42 ` [PATCH v4 02/15] md/raid5: add sysfs entry to set and show stripe_size Yufen Yu
2020-06-12 11:42 ` [PATCH v4 03/15] md/raid5: set default stripe_size as 4096 Yufen Yu
2020-06-12 11:42 ` [PATCH v4 04/15] md/raid5: add a member of r5pages for struct stripe_head Yufen Yu
2020-06-12 11:42 ` [PATCH v4 05/15] md/raid5: allocate and free shared pages of r5pages Yufen Yu
2020-06-12 11:42 ` [PATCH v4 06/15] md/raid5: set correct page offset for bi_io_vec in ops_run_io() Yufen Yu
2020-06-12 11:42 ` [PATCH v4 07/15] md/raid5: set correct page offset for async_copy_data() Yufen Yu
2020-06-12 11:42 ` [PATCH v4 08/15] md/raid5: resize stripes and set correct offset when reshape array Yufen Yu
2020-06-12 11:42 ` [PATCH v4 09/15] md/raid5: add new xor function to support different page offset Yufen Yu
2020-06-12 11:42 ` [PATCH v4 10/15] md/raid5: add offset array in scribble buffer Yufen Yu
2020-06-12 11:42 ` [PATCH v4 11/15] md/raid5: compute xor with correct page offset Yufen Yu
2020-06-12 11:42 ` Yufen Yu [this message]
2020-06-12 11:42 ` [PATCH v4 13/15] md/raid6: let syndrome computor support different " Yufen Yu
2020-06-12 11:42 ` [PATCH v4 14/15] md/raid6: compute syndrome with correct " Yufen Yu
2020-06-12 11:42 ` [PATCH v4 15/15] raid6test: adaptation with syndrome function Yufen Yu
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=20200612114220.13126-13-yuyufen@huawei.com \
--to=yuyufen@huawei.com \
--cc=guoqing.jiang@cloud.ionos.com \
--cc=houtao1@huawei.com \
--cc=linux-raid@vger.kernel.org \
--cc=neilb@suse.com \
--cc=song@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox