From: Andre Noll <maan@systemlinux.org>
To: Dan Williams <dan.j.williams@intel.com>
Cc: neilb@suse.de, linux-raid@vger.kernel.org,
ed.ciechanowski@intel.com, jacek.danecki@intel.com
Subject: Re: [PATCH 3/3] md: 'array_size' sysfs attribute
Date: Fri, 6 Mar 2009 17:15:59 +0100 [thread overview]
Message-ID: <20090306161559.GJ32416@skl-net.de> (raw)
In-Reply-To: <20090306002458.9882.82188.stgit@dwillia2-linux.ch.intel.com>
[-- Attachment #1: Type: text/plain, Size: 3203 bytes --]
On 17:24, Dan Williams wrote:
> Allow userspace to set the size of the array according to the following
> semantics:
>
> 1/ size must be <= to the size returned by mddev->pers->size(mddev, 0, 0)
> a) If size is set before the array is running, do_md_run will fail
> if size is greater than the default size
> b) A reshape attempt that reduces the default size to less than the set
> array size should be blocked
> 2/ once userspace sets the size the kernel will not change it
This holds only until the array is stopped and reassembled (for
example due to a reboot). Is that correct and intended?
> +static ssize_t
> +array_size_store(mddev_t *mddev, const char *buf, size_t len)
> +{
> + unsigned long long sectors;
> + struct block_device *bdev;
> +
> + if (strncmp(buf, "default", 7) == 0) {
> + if (mddev->pers)
> + sectors = mddev->pers->size(mddev, 0, 0);
> + else
> + sectors = mddev->array_sectors;
> +
> + mddev->external_size = 0;
> + } else {
> + int err;
> + sector_t new;
> +
> + err = strict_strtoull(buf, 10, §ors);
> + if (err < 0)
> + return err;
> + sectors *= 2;
> + new = sectors;
> + if (new != sectors) /* overflow */
> + return -EINVAL;
Is it possible that already the "sectors *= 2" overflows? If this
happens a much too small value is going to be stored by set_capacity()
later.
> + mddev->array_sectors = sectors;
> + set_capacity(mddev->gendisk, mddev->array_sectors);
> + if (mddev->pers) {
> + bdev = bdget_disk(mddev->gendisk, 0);
> + if (bdev) {
> + mutex_lock(&bdev->bd_inode->i_mutex);
> + i_size_write(bdev->bd_inode,
> + (loff_t)mddev->array_sectors << 9);
> + mutex_unlock(&bdev->bd_inode->i_mutex);
> + bdput(bdev);
> + }
> + }
bdev is only used inside the if (mddev->pers). No need to define it at
the top of the function.
> @@ -4043,7 +4108,17 @@ static int do_md_run(mddev_t * mddev)
> err = mddev->pers->run(mddev);
> if (err)
> printk(KERN_ERR "md: pers->run() failed ...\n");
> - else if (mddev->pers->sync_request) {
> + else if (mddev->pers->size(mddev, 0, 0) < mddev->array_sectors) {
> + WARN_ONCE(!mddev->external_size, "%s: default size too small,"
> + " but 'external_size' not in effect?\n", __func__);
> + printk(KERN_ERR
> + "md: invalid array_size %llu > default size %llu\n",
> + (unsigned long long)mddev->array_sectors / 2,
> + (unsigned long long)mddev->pers->size(mddev, 0, 0) / 2);
> + err = -EINVAL;
> + mddev->pers->stop(mddev);
> + }
What's the point of the WARN_ONCE() if it is followed by a printk() that
is always being printed?
> void md_set_size(mddev_t *mddev, sector_t array_sectors)
> {
> + WARN(!mddev_is_locked(mddev), "%s: unlocked mddev!\n", __func__);
An unlocked mddev would actually be a bug, no? Also, the name
"md_set_size" is a bit unfortunate as an exported function name because
it's not clear from the name that the size should be specified in
sectors. "md_set_sector_count" or "md_set_array_sectors" is probably
clearer.
Regards
Andre
--
The only person who always got his work done by Friday was Robinson Crusoe
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2009-03-06 16:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-06 0:24 [PATCH 0/3] Support setting the array size from userspace Dan Williams
2009-03-06 0:24 ` [PATCH 1/3] md: add 'size' as a personality method Dan Williams
2009-03-06 16:15 ` Andre Noll
2009-03-06 17:55 ` Dan Williams
2009-03-06 0:24 ` [PATCH 2/3] md: centralize ->array_sectors modifications Dan Williams
2009-03-06 0:24 ` [PATCH 3/3] md: 'array_size' sysfs attribute Dan Williams
2009-03-06 16:15 ` Andre Noll [this message]
2009-03-06 18:20 ` Dan Williams
2009-03-07 6:28 ` Dan Williams
2009-03-09 10:12 ` Andre Noll
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=20090306161559.GJ32416@skl-net.de \
--to=maan@systemlinux.org \
--cc=dan.j.williams@intel.com \
--cc=ed.ciechanowski@intel.com \
--cc=jacek.danecki@intel.com \
--cc=linux-raid@vger.kernel.org \
--cc=neilb@suse.de \
/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;
as well as URLs for NNTP newsgroup(s).