aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/md.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r--drivers/md/md.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 7da6ec244e15..827824a9f3e9 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1105,7 +1105,11 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1105 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256; 1105 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
1106 bmask = queue_hardsect_size(rdev->bdev->bd_disk->queue)-1; 1106 bmask = queue_hardsect_size(rdev->bdev->bd_disk->queue)-1;
1107 if (rdev->sb_size & bmask) 1107 if (rdev->sb_size & bmask)
1108 rdev-> sb_size = (rdev->sb_size | bmask)+1; 1108 rdev->sb_size = (rdev->sb_size | bmask) + 1;
1109
1110 if (minor_version
1111 && rdev->data_offset < sb_offset + (rdev->sb_size/512))
1112 return -EINVAL;
1109 1113
1110 if (sb->level == cpu_to_le32(LEVEL_MULTIPATH)) 1114 if (sb->level == cpu_to_le32(LEVEL_MULTIPATH))
1111 rdev->desc_nr = -1; 1115 rdev->desc_nr = -1;
@@ -1137,7 +1141,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1137 else 1141 else
1138 ret = 0; 1142 ret = 0;
1139 } 1143 }
1140 if (minor_version) 1144 if (minor_version)
1141 rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2; 1145 rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2;
1142 else 1146 else
1143 rdev->size = rdev->sb_offset; 1147 rdev->size = rdev->sb_offset;
@@ -1499,7 +1503,8 @@ static void export_rdev(mdk_rdev_t * rdev)
1499 free_disk_sb(rdev); 1503 free_disk_sb(rdev);
1500 list_del_init(&rdev->same_set); 1504 list_del_init(&rdev->same_set);
1501#ifndef MODULE 1505#ifndef MODULE
1502 md_autodetect_dev(rdev->bdev->bd_dev); 1506 if (test_bit(AutoDetected, &rdev->flags))
1507 md_autodetect_dev(rdev->bdev->bd_dev);
1503#endif 1508#endif
1504 unlock_rdev(rdev); 1509 unlock_rdev(rdev);
1505 kobject_put(&rdev->kobj); 1510 kobject_put(&rdev->kobj);
@@ -1996,9 +2001,11 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1996 char *e; 2001 char *e;
1997 unsigned long long size = simple_strtoull(buf, &e, 10); 2002 unsigned long long size = simple_strtoull(buf, &e, 10);
1998 unsigned long long oldsize = rdev->size; 2003 unsigned long long oldsize = rdev->size;
2004 mddev_t *my_mddev = rdev->mddev;
2005
1999 if (e==buf || (*e && *e != '\n')) 2006 if (e==buf || (*e && *e != '\n'))
2000 return -EINVAL; 2007 return -EINVAL;
2001 if (rdev->mddev->pers) 2008 if (my_mddev->pers)
2002 return -EBUSY; 2009 return -EBUSY;
2003 rdev->size = size; 2010 rdev->size = size;
2004 if (size > oldsize && rdev->mddev->external) { 2011 if (size > oldsize && rdev->mddev->external) {
@@ -2011,7 +2018,7 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2011 int overlap = 0; 2018 int overlap = 0;
2012 struct list_head *tmp, *tmp2; 2019 struct list_head *tmp, *tmp2;
2013 2020
2014 mddev_unlock(rdev->mddev); 2021 mddev_unlock(my_mddev);
2015 for_each_mddev(mddev, tmp) { 2022 for_each_mddev(mddev, tmp) {
2016 mdk_rdev_t *rdev2; 2023 mdk_rdev_t *rdev2;
2017 2024
@@ -2031,7 +2038,7 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2031 break; 2038 break;
2032 } 2039 }
2033 } 2040 }
2034 mddev_lock(rdev->mddev); 2041 mddev_lock(my_mddev);
2035 if (overlap) { 2042 if (overlap) {
2036 /* Someone else could have slipped in a size 2043 /* Someone else could have slipped in a size
2037 * change here, but doing so is just silly. 2044 * change here, but doing so is just silly.
@@ -2043,8 +2050,8 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2043 return -EBUSY; 2050 return -EBUSY;
2044 } 2051 }
2045 } 2052 }
2046 if (size < rdev->mddev->size || rdev->mddev->size == 0) 2053 if (size < my_mddev->size || my_mddev->size == 0)
2047 rdev->mddev->size = size; 2054 my_mddev->size = size;
2048 return len; 2055 return len;
2049} 2056}
2050 2057
@@ -2065,10 +2072,21 @@ rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
2065{ 2072{
2066 struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); 2073 struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr);
2067 mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); 2074 mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj);
2075 mddev_t *mddev = rdev->mddev;
2076 ssize_t rv;
2068 2077
2069 if (!entry->show) 2078 if (!entry->show)
2070 return -EIO; 2079 return -EIO;
2071 return entry->show(rdev, page); 2080
2081 rv = mddev ? mddev_lock(mddev) : -EBUSY;
2082 if (!rv) {
2083 if (rdev->mddev == NULL)
2084 rv = -EBUSY;
2085 else
2086 rv = entry->show(rdev, page);
2087 mddev_unlock(mddev);
2088 }
2089 return rv;
2072} 2090}
2073 2091
2074static ssize_t 2092static ssize_t
@@ -2077,15 +2095,19 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr,
2077{ 2095{
2078 struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); 2096 struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr);
2079 mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); 2097 mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj);
2080 int rv; 2098 ssize_t rv;
2099 mddev_t *mddev = rdev->mddev;
2081 2100
2082 if (!entry->store) 2101 if (!entry->store)
2083 return -EIO; 2102 return -EIO;
2084 if (!capable(CAP_SYS_ADMIN)) 2103 if (!capable(CAP_SYS_ADMIN))
2085 return -EACCES; 2104 return -EACCES;
2086 rv = mddev_lock(rdev->mddev); 2105 rv = mddev ? mddev_lock(mddev): -EBUSY;
2087 if (!rv) { 2106 if (!rv) {
2088 rv = entry->store(rdev, page, length); 2107 if (rdev->mddev == NULL)
2108 rv = -EBUSY;
2109 else
2110 rv = entry->store(rdev, page, length);
2089 mddev_unlock(rdev->mddev); 2111 mddev_unlock(rdev->mddev);
2090 } 2112 }
2091 return rv; 2113 return rv;
@@ -5351,6 +5373,7 @@ void md_write_start(mddev_t *mddev, struct bio *bi)
5351 mddev->ro = 0; 5373 mddev->ro = 0;
5352 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 5374 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5353 md_wakeup_thread(mddev->thread); 5375 md_wakeup_thread(mddev->thread);
5376 md_wakeup_thread(mddev->sync_thread);
5354 } 5377 }
5355 atomic_inc(&mddev->writes_pending); 5378 atomic_inc(&mddev->writes_pending);
5356 if (mddev->in_sync) { 5379 if (mddev->in_sync) {
@@ -6021,6 +6044,7 @@ static void autostart_arrays(int part)
6021 MD_BUG(); 6044 MD_BUG();
6022 continue; 6045 continue;
6023 } 6046 }
6047 set_bit(AutoDetected, &rdev->flags);
6024 list_add(&rdev->same_set, &pending_raid_disks); 6048 list_add(&rdev->same_set, &pending_raid_disks);
6025 i_passed++; 6049 i_passed++;
6026 } 6050 }