Commit d7027458d68b2f1752a28016dcf2ffd0a7e8f567

Authored by Neil Brown
Committed by NeilBrown
1 parent 7e93a89251

md: Tidy up rdev_size_store a bit:

- used strict_strtoull in place of simple_strtoull
 - use my_mddev in place of rdev->mddev (they have the same value)
and more significantly,
 - don't adjust mddev->size to fit, rather reject changes which make
   rdev->size smaller than mddev->size

Adjusting mddev->size is a hangover from bind_rdev_to_array which
does a similar thing.  But it really is a better design to insist that
mddev->size is set as required, then the rdev->sizes are set to allow
for that.  The previous way invites confusion.

Signed-off-by: NeilBrown <neilb@suse.de>

Showing 2 changed files with 9 additions and 10 deletions Side-by-side Diff

Documentation/md.txt
... ... @@ -347,7 +347,7 @@
347 347 for storage of data. This will normally be the same as the
348 348 component_size. This can be written while assembling an
349 349 array. If a value less than the current component_size is
350   - written, component_size will be reduced to this value.
  350 + written, it will be rejected.
351 351  
352 352  
353 353 An active md device will also contain and entry for each active device
... ... @@ -2101,16 +2101,17 @@
2101 2101 static ssize_t
2102 2102 rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2103 2103 {
2104   - char *e;
2105   - unsigned long long size = simple_strtoull(buf, &e, 10);
  2104 + unsigned long long size;
2106 2105 unsigned long long oldsize = rdev->size;
2107 2106 mddev_t *my_mddev = rdev->mddev;
2108 2107  
2109   - if (e==buf || (*e && *e != '\n'))
  2108 + if (strict_strtoull(buf, 10, &size) < 0)
2110 2109 return -EINVAL;
  2110 + if (size < my_mddev->size)
  2111 + return -EINVAL;
2111 2112 if (my_mddev->pers && rdev->raid_disk >= 0) {
2112   - if (rdev->mddev->persistent) {
2113   - size = super_types[rdev->mddev->major_version].
  2113 + if (my_mddev->persistent) {
  2114 + size = super_types[my_mddev->major_version].
2114 2115 rdev_size_change(rdev, size);
2115 2116 if (!size)
2116 2117 return -EBUSY;
2117 2118  
... ... @@ -2118,12 +2119,12 @@
2118 2119 size = (rdev->bdev->bd_inode->i_size >> 10);
2119 2120 size -= rdev->data_offset/2;
2120 2121 }
2121   - if (size < rdev->mddev->size)
  2122 + if (size < my_mddev->size)
2122 2123 return -EINVAL; /* component must fit device */
2123 2124 }
2124 2125  
2125 2126 rdev->size = size;
2126   - if (size > oldsize && rdev->mddev->external) {
  2127 + if (size > oldsize && my_mddev->external) {
2127 2128 /* need to check that all other rdevs with the same ->bdev
2128 2129 * do not overlap. We need to unlock the mddev to avoid
2129 2130 * a deadlock. We have already changed rdev->size, and if
... ... @@ -2165,8 +2166,6 @@
2165 2166 return -EBUSY;
2166 2167 }
2167 2168 }
2168   - if (size < my_mddev->size || my_mddev->size == 0)
2169   - my_mddev->size = size;
2170 2169 return len;
2171 2170 }
2172 2171