Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | md.c : Multiple Devices driver for Linux |
| 3 | Copyright (C) 1998, 1999, 2000 Ingo Molnar |
| 4 | |
| 5 | completely rewritten, based on the MD driver code from Marc Zyngier |
| 6 | |
| 7 | Changes: |
| 8 | |
| 9 | - RAID-1/RAID-5 extensions by Miguel de Icaza, Gadi Oxman, Ingo Molnar |
| 10 | - RAID-6 extensions by H. Peter Anvin <hpa@zytor.com> |
| 11 | - boot support for linear and striped mode by Harald Hoyer <HarryH@Royal.Net> |
| 12 | - kerneld support by Boris Tobotras <boris@xtalk.msk.su> |
| 13 | - kmod support by: Cyrus Durgin |
| 14 | - RAID0 bugfixes: Mark Anthony Lisher <markal@iname.com> |
| 15 | - Devfs support by Richard Gooch <rgooch@atnf.csiro.au> |
| 16 | |
| 17 | - lots of fixes and improvements to the RAID1/RAID5 and generic |
| 18 | RAID code (such as request based resynchronization): |
| 19 | |
| 20 | Neil Brown <neilb@cse.unsw.edu.au>. |
| 21 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 22 | - persistent bitmap code |
| 23 | Copyright (C) 2003-2004, Paul Clements, SteelEye Technology, Inc. |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | This program is free software; you can redistribute it and/or modify |
| 26 | it under the terms of the GNU General Public License as published by |
| 27 | the Free Software Foundation; either version 2, or (at your option) |
| 28 | any later version. |
| 29 | |
| 30 | You should have received a copy of the GNU General Public License |
| 31 | (for example /usr/src/linux/COPYING); if not, write to the Free |
| 32 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 33 | */ |
| 34 | |
| 35 | #include <linux/module.h> |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 36 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/linkage.h> |
| 38 | #include <linux/raid/md.h> |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 39 | #include <linux/raid/bitmap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/sysctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/buffer_head.h> /* for invalidate_bdev */ |
| 42 | #include <linux/suspend.h> |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 43 | #include <linux/poll.h> |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 44 | #include <linux/mutex.h> |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 45 | #include <linux/ctype.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #include <linux/init.h> |
| 48 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 49 | #include <linux/file.h> |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #ifdef CONFIG_KMOD |
| 52 | #include <linux/kmod.h> |
| 53 | #endif |
| 54 | |
| 55 | #include <asm/unaligned.h> |
| 56 | |
| 57 | #define MAJOR_NR MD_MAJOR |
| 58 | #define MD_DRIVER |
| 59 | |
| 60 | /* 63 partitions with the alternate major number (mdp) */ |
| 61 | #define MdpMinorShift 6 |
| 62 | |
| 63 | #define DEBUG 0 |
| 64 | #define dprintk(x...) ((void)(DEBUG && printk(x))) |
| 65 | |
| 66 | |
| 67 | #ifndef MODULE |
| 68 | static void autostart_arrays (int part); |
| 69 | #endif |
| 70 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 71 | static LIST_HEAD(pers_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static DEFINE_SPINLOCK(pers_lock); |
| 73 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 74 | static void md_print_devices(void); |
| 75 | |
| 76 | #define MD_BUG(x...) { printk("md: bug in file %s, line %d\n", __FILE__, __LINE__); md_print_devices(); } |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | /* |
| 79 | * Current RAID-1,4,5 parallel reconstruction 'guaranteed speed limit' |
| 80 | * is 1000 KB/sec, so the extra system load does not show up that much. |
| 81 | * Increase it if you want to have more _guaranteed_ speed. Note that |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 82 | * the RAID driver will use the maximum available bandwidth if the IO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | * subsystem is idle. There is also an 'absolute maximum' reconstruction |
| 84 | * speed limit - in case reconstruction slows down your system despite |
| 85 | * idle IO detection. |
| 86 | * |
| 87 | * you can change it via /proc/sys/dev/raid/speed_limit_min and _max. |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 88 | * or /sys/block/mdX/md/sync_speed_{min,max} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | */ |
| 90 | |
| 91 | static int sysctl_speed_limit_min = 1000; |
| 92 | static int sysctl_speed_limit_max = 200000; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 93 | static inline int speed_min(mddev_t *mddev) |
| 94 | { |
| 95 | return mddev->sync_speed_min ? |
| 96 | mddev->sync_speed_min : sysctl_speed_limit_min; |
| 97 | } |
| 98 | |
| 99 | static inline int speed_max(mddev_t *mddev) |
| 100 | { |
| 101 | return mddev->sync_speed_max ? |
| 102 | mddev->sync_speed_max : sysctl_speed_limit_max; |
| 103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | static struct ctl_table_header *raid_table_header; |
| 106 | |
| 107 | static ctl_table raid_table[] = { |
| 108 | { |
| 109 | .ctl_name = DEV_RAID_SPEED_LIMIT_MIN, |
| 110 | .procname = "speed_limit_min", |
| 111 | .data = &sysctl_speed_limit_min, |
| 112 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 113 | .mode = S_IRUGO|S_IWUSR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | .proc_handler = &proc_dointvec, |
| 115 | }, |
| 116 | { |
| 117 | .ctl_name = DEV_RAID_SPEED_LIMIT_MAX, |
| 118 | .procname = "speed_limit_max", |
| 119 | .data = &sysctl_speed_limit_max, |
| 120 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 121 | .mode = S_IRUGO|S_IWUSR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | .proc_handler = &proc_dointvec, |
| 123 | }, |
| 124 | { .ctl_name = 0 } |
| 125 | }; |
| 126 | |
| 127 | static ctl_table raid_dir_table[] = { |
| 128 | { |
| 129 | .ctl_name = DEV_RAID, |
| 130 | .procname = "raid", |
| 131 | .maxlen = 0, |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 132 | .mode = S_IRUGO|S_IXUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | .child = raid_table, |
| 134 | }, |
| 135 | { .ctl_name = 0 } |
| 136 | }; |
| 137 | |
| 138 | static ctl_table raid_root_table[] = { |
| 139 | { |
| 140 | .ctl_name = CTL_DEV, |
| 141 | .procname = "dev", |
| 142 | .maxlen = 0, |
| 143 | .mode = 0555, |
| 144 | .child = raid_dir_table, |
| 145 | }, |
| 146 | { .ctl_name = 0 } |
| 147 | }; |
| 148 | |
| 149 | static struct block_device_operations md_fops; |
| 150 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 151 | static int start_readonly; |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 154 | * We have a system wide 'event count' that is incremented |
| 155 | * on any 'interesting' event, and readers of /proc/mdstat |
| 156 | * can use 'poll' or 'select' to find out when the event |
| 157 | * count increases. |
| 158 | * |
| 159 | * Events are: |
| 160 | * start array, stop array, error, add device, remove device, |
| 161 | * start build, activate spare |
| 162 | */ |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 163 | static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 164 | static atomic_t md_event_count; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 165 | void md_new_event(mddev_t *mddev) |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 166 | { |
| 167 | atomic_inc(&md_event_count); |
| 168 | wake_up(&md_event_waiters); |
NeilBrown | 4508a7a | 2006-03-20 17:53:53 +1100 | [diff] [blame] | 169 | sysfs_notify(&mddev->kobj, NULL, "sync_action"); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 170 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 171 | EXPORT_SYMBOL_GPL(md_new_event); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 172 | |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 173 | /* Alternate version that can be called from interrupts |
| 174 | * when calling sysfs_notify isn't needed. |
| 175 | */ |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 176 | static void md_new_event_inintr(mddev_t *mddev) |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 177 | { |
| 178 | atomic_inc(&md_event_count); |
| 179 | wake_up(&md_event_waiters); |
| 180 | } |
| 181 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 182 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | * Enables to iterate over all existing md arrays |
| 184 | * all_mddevs_lock protects this list. |
| 185 | */ |
| 186 | static LIST_HEAD(all_mddevs); |
| 187 | static DEFINE_SPINLOCK(all_mddevs_lock); |
| 188 | |
| 189 | |
| 190 | /* |
| 191 | * iterates through all used mddevs in the system. |
| 192 | * We take care to grab the all_mddevs_lock whenever navigating |
| 193 | * the list, and to always hold a refcount when unlocked. |
| 194 | * Any code which breaks out of this loop while own |
| 195 | * a reference to the current mddev and must mddev_put it. |
| 196 | */ |
| 197 | #define ITERATE_MDDEV(mddev,tmp) \ |
| 198 | \ |
| 199 | for (({ spin_lock(&all_mddevs_lock); \ |
| 200 | tmp = all_mddevs.next; \ |
| 201 | mddev = NULL;}); \ |
| 202 | ({ if (tmp != &all_mddevs) \ |
| 203 | mddev_get(list_entry(tmp, mddev_t, all_mddevs));\ |
| 204 | spin_unlock(&all_mddevs_lock); \ |
| 205 | if (mddev) mddev_put(mddev); \ |
| 206 | mddev = list_entry(tmp, mddev_t, all_mddevs); \ |
| 207 | tmp != &all_mddevs;}); \ |
| 208 | ({ spin_lock(&all_mddevs_lock); \ |
| 209 | tmp = tmp->next;}) \ |
| 210 | ) |
| 211 | |
| 212 | |
| 213 | static int md_fail_request (request_queue_t *q, struct bio *bio) |
| 214 | { |
| 215 | bio_io_error(bio, bio->bi_size); |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static inline mddev_t *mddev_get(mddev_t *mddev) |
| 220 | { |
| 221 | atomic_inc(&mddev->active); |
| 222 | return mddev; |
| 223 | } |
| 224 | |
| 225 | static void mddev_put(mddev_t *mddev) |
| 226 | { |
| 227 | if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock)) |
| 228 | return; |
| 229 | if (!mddev->raid_disks && list_empty(&mddev->disks)) { |
| 230 | list_del(&mddev->all_mddevs); |
NeilBrown | 926ce2d | 2006-03-31 02:32:02 -0800 | [diff] [blame] | 231 | spin_unlock(&all_mddevs_lock); |
Al Viro | 1312f40 | 2006-03-12 11:02:03 -0500 | [diff] [blame] | 232 | blk_cleanup_queue(mddev->queue); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 233 | kobject_unregister(&mddev->kobj); |
NeilBrown | 926ce2d | 2006-03-31 02:32:02 -0800 | [diff] [blame] | 234 | } else |
| 235 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static mddev_t * mddev_find(dev_t unit) |
| 239 | { |
| 240 | mddev_t *mddev, *new = NULL; |
| 241 | |
| 242 | retry: |
| 243 | spin_lock(&all_mddevs_lock); |
| 244 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 245 | if (mddev->unit == unit) { |
| 246 | mddev_get(mddev); |
| 247 | spin_unlock(&all_mddevs_lock); |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 248 | kfree(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return mddev; |
| 250 | } |
| 251 | |
| 252 | if (new) { |
| 253 | list_add(&new->all_mddevs, &all_mddevs); |
| 254 | spin_unlock(&all_mddevs_lock); |
| 255 | return new; |
| 256 | } |
| 257 | spin_unlock(&all_mddevs_lock); |
| 258 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 259 | new = kzalloc(sizeof(*new), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (!new) |
| 261 | return NULL; |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | new->unit = unit; |
| 264 | if (MAJOR(unit) == MD_MAJOR) |
| 265 | new->md_minor = MINOR(unit); |
| 266 | else |
| 267 | new->md_minor = MINOR(unit) >> MdpMinorShift; |
| 268 | |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 269 | mutex_init(&new->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | INIT_LIST_HEAD(&new->disks); |
| 271 | INIT_LIST_HEAD(&new->all_mddevs); |
| 272 | init_timer(&new->safemode_timer); |
| 273 | atomic_set(&new->active, 1); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 274 | spin_lock_init(&new->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 275 | init_waitqueue_head(&new->sb_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | new->queue = blk_alloc_queue(GFP_KERNEL); |
| 278 | if (!new->queue) { |
| 279 | kfree(new); |
| 280 | return NULL; |
| 281 | } |
NeilBrown | 89e5c8b | 2006-03-27 01:18:02 -0800 | [diff] [blame] | 282 | set_bit(QUEUE_FLAG_CLUSTER, &new->queue->queue_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | blk_queue_make_request(new->queue, md_fail_request); |
| 285 | |
| 286 | goto retry; |
| 287 | } |
| 288 | |
| 289 | static inline int mddev_lock(mddev_t * mddev) |
| 290 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 291 | return mutex_lock_interruptible(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | static inline int mddev_trylock(mddev_t * mddev) |
| 295 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 296 | return mutex_trylock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static inline void mddev_unlock(mddev_t * mddev) |
| 300 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 301 | mutex_unlock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 303 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 306 | static mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
| 308 | mdk_rdev_t * rdev; |
| 309 | struct list_head *tmp; |
| 310 | |
| 311 | ITERATE_RDEV(mddev,rdev,tmp) { |
| 312 | if (rdev->desc_nr == nr) |
| 313 | return rdev; |
| 314 | } |
| 315 | return NULL; |
| 316 | } |
| 317 | |
| 318 | static mdk_rdev_t * find_rdev(mddev_t * mddev, dev_t dev) |
| 319 | { |
| 320 | struct list_head *tmp; |
| 321 | mdk_rdev_t *rdev; |
| 322 | |
| 323 | ITERATE_RDEV(mddev,rdev,tmp) { |
| 324 | if (rdev->bdev->bd_dev == dev) |
| 325 | return rdev; |
| 326 | } |
| 327 | return NULL; |
| 328 | } |
| 329 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 330 | static struct mdk_personality *find_pers(int level, char *clevel) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 331 | { |
| 332 | struct mdk_personality *pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 333 | list_for_each_entry(pers, &pers_list, list) { |
| 334 | if (level != LEVEL_NONE && pers->level == level) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 335 | return pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 336 | if (strcmp(pers->name, clevel)==0) |
| 337 | return pers; |
| 338 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 339 | return NULL; |
| 340 | } |
| 341 | |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 342 | static inline sector_t calc_dev_sboffset(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
| 344 | sector_t size = bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 345 | return MD_NEW_SIZE_BLOCKS(size); |
| 346 | } |
| 347 | |
| 348 | static sector_t calc_dev_size(mdk_rdev_t *rdev, unsigned chunk_size) |
| 349 | { |
| 350 | sector_t size; |
| 351 | |
| 352 | size = rdev->sb_offset; |
| 353 | |
| 354 | if (chunk_size) |
| 355 | size &= ~((sector_t)chunk_size/1024 - 1); |
| 356 | return size; |
| 357 | } |
| 358 | |
| 359 | static int alloc_disk_sb(mdk_rdev_t * rdev) |
| 360 | { |
| 361 | if (rdev->sb_page) |
| 362 | MD_BUG(); |
| 363 | |
| 364 | rdev->sb_page = alloc_page(GFP_KERNEL); |
| 365 | if (!rdev->sb_page) { |
| 366 | printk(KERN_ALERT "md: out of memory.\n"); |
| 367 | return -EINVAL; |
| 368 | } |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | static void free_disk_sb(mdk_rdev_t * rdev) |
| 374 | { |
| 375 | if (rdev->sb_page) { |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 376 | put_page(rdev->sb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | rdev->sb_loaded = 0; |
| 378 | rdev->sb_page = NULL; |
| 379 | rdev->sb_offset = 0; |
| 380 | rdev->size = 0; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 385 | static int super_written(struct bio *bio, unsigned int bytes_done, int error) |
| 386 | { |
| 387 | mdk_rdev_t *rdev = bio->bi_private; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 388 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 389 | if (bio->bi_size) |
| 390 | return 1; |
| 391 | |
| 392 | if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 393 | md_error(mddev, rdev); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 394 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 395 | if (atomic_dec_and_test(&mddev->pending_writes)) |
| 396 | wake_up(&mddev->sb_wait); |
Neil Brown | f8b58ed | 2005-06-27 22:29:34 -0700 | [diff] [blame] | 397 | bio_put(bio); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 401 | static int super_written_barrier(struct bio *bio, unsigned int bytes_done, int error) |
| 402 | { |
| 403 | struct bio *bio2 = bio->bi_private; |
| 404 | mdk_rdev_t *rdev = bio2->bi_private; |
| 405 | mddev_t *mddev = rdev->mddev; |
| 406 | if (bio->bi_size) |
| 407 | return 1; |
| 408 | |
| 409 | if (!test_bit(BIO_UPTODATE, &bio->bi_flags) && |
| 410 | error == -EOPNOTSUPP) { |
| 411 | unsigned long flags; |
| 412 | /* barriers don't appear to be supported :-( */ |
| 413 | set_bit(BarriersNotsupp, &rdev->flags); |
| 414 | mddev->barriers_work = 0; |
| 415 | spin_lock_irqsave(&mddev->write_lock, flags); |
| 416 | bio2->bi_next = mddev->biolist; |
| 417 | mddev->biolist = bio2; |
| 418 | spin_unlock_irqrestore(&mddev->write_lock, flags); |
| 419 | wake_up(&mddev->sb_wait); |
| 420 | bio_put(bio); |
| 421 | return 0; |
| 422 | } |
| 423 | bio_put(bio2); |
| 424 | bio->bi_private = rdev; |
| 425 | return super_written(bio, bytes_done, error); |
| 426 | } |
| 427 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 428 | void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev, |
| 429 | sector_t sector, int size, struct page *page) |
| 430 | { |
| 431 | /* write first size bytes of page to sector of rdev |
| 432 | * Increment mddev->pending_writes before returning |
| 433 | * and decrement it on completion, waking up sb_wait |
| 434 | * if zero is reached. |
| 435 | * If an error occurred, call md_error |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 436 | * |
| 437 | * As we might need to resubmit the request if BIO_RW_BARRIER |
| 438 | * causes ENOTSUPP, we allocate a spare bio... |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 439 | */ |
| 440 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 441 | int rw = (1<<BIO_RW) | (1<<BIO_RW_SYNC); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 442 | |
| 443 | bio->bi_bdev = rdev->bdev; |
| 444 | bio->bi_sector = sector; |
| 445 | bio_add_page(bio, page, size, 0); |
| 446 | bio->bi_private = rdev; |
| 447 | bio->bi_end_io = super_written; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 448 | bio->bi_rw = rw; |
| 449 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 450 | atomic_inc(&mddev->pending_writes); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 451 | if (!test_bit(BarriersNotsupp, &rdev->flags)) { |
| 452 | struct bio *rbio; |
| 453 | rw |= (1<<BIO_RW_BARRIER); |
| 454 | rbio = bio_clone(bio, GFP_NOIO); |
| 455 | rbio->bi_private = bio; |
| 456 | rbio->bi_end_io = super_written_barrier; |
| 457 | submit_bio(rw, rbio); |
| 458 | } else |
| 459 | submit_bio(rw, bio); |
| 460 | } |
| 461 | |
| 462 | void md_super_wait(mddev_t *mddev) |
| 463 | { |
| 464 | /* wait for all superblock writes that were scheduled to complete. |
| 465 | * if any had to be retried (due to BARRIER problems), retry them |
| 466 | */ |
| 467 | DEFINE_WAIT(wq); |
| 468 | for(;;) { |
| 469 | prepare_to_wait(&mddev->sb_wait, &wq, TASK_UNINTERRUPTIBLE); |
| 470 | if (atomic_read(&mddev->pending_writes)==0) |
| 471 | break; |
| 472 | while (mddev->biolist) { |
| 473 | struct bio *bio; |
| 474 | spin_lock_irq(&mddev->write_lock); |
| 475 | bio = mddev->biolist; |
| 476 | mddev->biolist = bio->bi_next ; |
| 477 | bio->bi_next = NULL; |
| 478 | spin_unlock_irq(&mddev->write_lock); |
| 479 | submit_bio(bio->bi_rw, bio); |
| 480 | } |
| 481 | schedule(); |
| 482 | } |
| 483 | finish_wait(&mddev->sb_wait, &wq); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | static int bi_complete(struct bio *bio, unsigned int bytes_done, int error) |
| 487 | { |
| 488 | if (bio->bi_size) |
| 489 | return 1; |
| 490 | |
| 491 | complete((struct completion*)bio->bi_private); |
| 492 | return 0; |
| 493 | } |
| 494 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 495 | int sync_page_io(struct block_device *bdev, sector_t sector, int size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | struct page *page, int rw) |
| 497 | { |
Neil Brown | baaa2c5 | 2005-04-16 15:23:54 -0700 | [diff] [blame] | 498 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | struct completion event; |
| 500 | int ret; |
| 501 | |
| 502 | rw |= (1 << BIO_RW_SYNC); |
| 503 | |
| 504 | bio->bi_bdev = bdev; |
| 505 | bio->bi_sector = sector; |
| 506 | bio_add_page(bio, page, size, 0); |
| 507 | init_completion(&event); |
| 508 | bio->bi_private = &event; |
| 509 | bio->bi_end_io = bi_complete; |
| 510 | submit_bio(rw, bio); |
| 511 | wait_for_completion(&event); |
| 512 | |
| 513 | ret = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 514 | bio_put(bio); |
| 515 | return ret; |
| 516 | } |
NeilBrown | a8745db | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 517 | EXPORT_SYMBOL_GPL(sync_page_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 519 | static int read_disk_sb(mdk_rdev_t * rdev, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
| 521 | char b[BDEVNAME_SIZE]; |
| 522 | if (!rdev->sb_page) { |
| 523 | MD_BUG(); |
| 524 | return -EINVAL; |
| 525 | } |
| 526 | if (rdev->sb_loaded) |
| 527 | return 0; |
| 528 | |
| 529 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 530 | if (!sync_page_io(rdev->bdev, rdev->sb_offset<<1, size, rdev->sb_page, READ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | goto fail; |
| 532 | rdev->sb_loaded = 1; |
| 533 | return 0; |
| 534 | |
| 535 | fail: |
| 536 | printk(KERN_WARNING "md: disabled device %s, could not read superblock.\n", |
| 537 | bdevname(rdev->bdev,b)); |
| 538 | return -EINVAL; |
| 539 | } |
| 540 | |
| 541 | static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 542 | { |
| 543 | if ( (sb1->set_uuid0 == sb2->set_uuid0) && |
| 544 | (sb1->set_uuid1 == sb2->set_uuid1) && |
| 545 | (sb1->set_uuid2 == sb2->set_uuid2) && |
| 546 | (sb1->set_uuid3 == sb2->set_uuid3)) |
| 547 | |
| 548 | return 1; |
| 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | |
| 554 | static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 555 | { |
| 556 | int ret; |
| 557 | mdp_super_t *tmp1, *tmp2; |
| 558 | |
| 559 | tmp1 = kmalloc(sizeof(*tmp1),GFP_KERNEL); |
| 560 | tmp2 = kmalloc(sizeof(*tmp2),GFP_KERNEL); |
| 561 | |
| 562 | if (!tmp1 || !tmp2) { |
| 563 | ret = 0; |
| 564 | printk(KERN_INFO "md.c: sb1 is not equal to sb2!\n"); |
| 565 | goto abort; |
| 566 | } |
| 567 | |
| 568 | *tmp1 = *sb1; |
| 569 | *tmp2 = *sb2; |
| 570 | |
| 571 | /* |
| 572 | * nr_disks is not constant |
| 573 | */ |
| 574 | tmp1->nr_disks = 0; |
| 575 | tmp2->nr_disks = 0; |
| 576 | |
| 577 | if (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4)) |
| 578 | ret = 0; |
| 579 | else |
| 580 | ret = 1; |
| 581 | |
| 582 | abort: |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 583 | kfree(tmp1); |
| 584 | kfree(tmp2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | return ret; |
| 586 | } |
| 587 | |
| 588 | static unsigned int calc_sb_csum(mdp_super_t * sb) |
| 589 | { |
| 590 | unsigned int disk_csum, csum; |
| 591 | |
| 592 | disk_csum = sb->sb_csum; |
| 593 | sb->sb_csum = 0; |
| 594 | csum = csum_partial((void *)sb, MD_SB_BYTES, 0); |
| 595 | sb->sb_csum = disk_csum; |
| 596 | return csum; |
| 597 | } |
| 598 | |
| 599 | |
| 600 | /* |
| 601 | * Handle superblock details. |
| 602 | * We want to be able to handle multiple superblock formats |
| 603 | * so we have a common interface to them all, and an array of |
| 604 | * different handlers. |
| 605 | * We rely on user-space to write the initial superblock, and support |
| 606 | * reading and updating of superblocks. |
| 607 | * Interface methods are: |
| 608 | * int load_super(mdk_rdev_t *dev, mdk_rdev_t *refdev, int minor_version) |
| 609 | * loads and validates a superblock on dev. |
| 610 | * if refdev != NULL, compare superblocks on both devices |
| 611 | * Return: |
| 612 | * 0 - dev has a superblock that is compatible with refdev |
| 613 | * 1 - dev has a superblock that is compatible and newer than refdev |
| 614 | * so dev should be used as the refdev in future |
| 615 | * -EINVAL superblock incompatible or invalid |
| 616 | * -othererror e.g. -EIO |
| 617 | * |
| 618 | * int validate_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 619 | * Verify that dev is acceptable into mddev. |
| 620 | * The first time, mddev->raid_disks will be 0, and data from |
| 621 | * dev should be merged in. Subsequent calls check that dev |
| 622 | * is new enough. Return 0 or -EINVAL |
| 623 | * |
| 624 | * void sync_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 625 | * Update the superblock for rdev with data in mddev |
| 626 | * This does not write to disc. |
| 627 | * |
| 628 | */ |
| 629 | |
| 630 | struct super_type { |
| 631 | char *name; |
| 632 | struct module *owner; |
| 633 | int (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version); |
| 634 | int (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 635 | void (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 636 | }; |
| 637 | |
| 638 | /* |
| 639 | * load_super for 0.90.0 |
| 640 | */ |
| 641 | static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 642 | { |
| 643 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 644 | mdp_super_t *sb; |
| 645 | int ret; |
| 646 | sector_t sb_offset; |
| 647 | |
| 648 | /* |
| 649 | * Calculate the position of the superblock, |
| 650 | * it's at the end of the disk. |
| 651 | * |
| 652 | * It also happens to be a multiple of 4Kb. |
| 653 | */ |
| 654 | sb_offset = calc_dev_sboffset(rdev->bdev); |
| 655 | rdev->sb_offset = sb_offset; |
| 656 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 657 | ret = read_disk_sb(rdev, MD_SB_BYTES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | if (ret) return ret; |
| 659 | |
| 660 | ret = -EINVAL; |
| 661 | |
| 662 | bdevname(rdev->bdev, b); |
| 663 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 664 | |
| 665 | if (sb->md_magic != MD_SB_MAGIC) { |
| 666 | printk(KERN_ERR "md: invalid raid superblock magic on %s\n", |
| 667 | b); |
| 668 | goto abort; |
| 669 | } |
| 670 | |
| 671 | if (sb->major_version != 0 || |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 672 | sb->minor_version < 90 || |
| 673 | sb->minor_version > 91) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | printk(KERN_WARNING "Bad version number %d.%d on %s\n", |
| 675 | sb->major_version, sb->minor_version, |
| 676 | b); |
| 677 | goto abort; |
| 678 | } |
| 679 | |
| 680 | if (sb->raid_disks <= 0) |
| 681 | goto abort; |
| 682 | |
| 683 | if (csum_fold(calc_sb_csum(sb)) != csum_fold(sb->sb_csum)) { |
| 684 | printk(KERN_WARNING "md: invalid superblock checksum on %s\n", |
| 685 | b); |
| 686 | goto abort; |
| 687 | } |
| 688 | |
| 689 | rdev->preferred_minor = sb->md_minor; |
| 690 | rdev->data_offset = 0; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 691 | rdev->sb_size = MD_SB_BYTES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
| 693 | if (sb->level == LEVEL_MULTIPATH) |
| 694 | rdev->desc_nr = -1; |
| 695 | else |
| 696 | rdev->desc_nr = sb->this_disk.number; |
| 697 | |
| 698 | if (refdev == 0) |
| 699 | ret = 1; |
| 700 | else { |
| 701 | __u64 ev1, ev2; |
| 702 | mdp_super_t *refsb = (mdp_super_t*)page_address(refdev->sb_page); |
| 703 | if (!uuid_equal(refsb, sb)) { |
| 704 | printk(KERN_WARNING "md: %s has different UUID to %s\n", |
| 705 | b, bdevname(refdev->bdev,b2)); |
| 706 | goto abort; |
| 707 | } |
| 708 | if (!sb_equal(refsb, sb)) { |
| 709 | printk(KERN_WARNING "md: %s has same UUID" |
| 710 | " but different superblock to %s\n", |
| 711 | b, bdevname(refdev->bdev, b2)); |
| 712 | goto abort; |
| 713 | } |
| 714 | ev1 = md_event(sb); |
| 715 | ev2 = md_event(refsb); |
| 716 | if (ev1 > ev2) |
| 717 | ret = 1; |
| 718 | else |
| 719 | ret = 0; |
| 720 | } |
| 721 | rdev->size = calc_dev_size(rdev, sb->chunk_size); |
| 722 | |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 723 | if (rdev->size < sb->size && sb->level > 1) |
| 724 | /* "this cannot possibly happen" ... */ |
| 725 | ret = -EINVAL; |
| 726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | abort: |
| 728 | return ret; |
| 729 | } |
| 730 | |
| 731 | /* |
| 732 | * validate_super for 0.90.0 |
| 733 | */ |
| 734 | static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 735 | { |
| 736 | mdp_disk_t *desc; |
| 737 | mdp_super_t *sb = (mdp_super_t *)page_address(rdev->sb_page); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 738 | __u64 ev1 = md_event(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 740 | rdev->raid_disk = -1; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 741 | rdev->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | if (mddev->raid_disks == 0) { |
| 743 | mddev->major_version = 0; |
| 744 | mddev->minor_version = sb->minor_version; |
| 745 | mddev->patch_version = sb->patch_version; |
| 746 | mddev->persistent = ! sb->not_persistent; |
| 747 | mddev->chunk_size = sb->chunk_size; |
| 748 | mddev->ctime = sb->ctime; |
| 749 | mddev->utime = sb->utime; |
| 750 | mddev->level = sb->level; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 751 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | mddev->layout = sb->layout; |
| 753 | mddev->raid_disks = sb->raid_disks; |
| 754 | mddev->size = sb->size; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 755 | mddev->events = ev1; |
NeilBrown | 9223214 | 2005-08-18 11:24:16 -0700 | [diff] [blame] | 756 | mddev->bitmap_offset = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 757 | mddev->default_bitmap_offset = MD_SB_BYTES >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 759 | if (mddev->minor_version >= 91) { |
| 760 | mddev->reshape_position = sb->reshape_position; |
| 761 | mddev->delta_disks = sb->delta_disks; |
| 762 | mddev->new_level = sb->new_level; |
| 763 | mddev->new_layout = sb->new_layout; |
| 764 | mddev->new_chunk = sb->new_chunk; |
| 765 | } else { |
| 766 | mddev->reshape_position = MaxSector; |
| 767 | mddev->delta_disks = 0; |
| 768 | mddev->new_level = mddev->level; |
| 769 | mddev->new_layout = mddev->layout; |
| 770 | mddev->new_chunk = mddev->chunk_size; |
| 771 | } |
| 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | if (sb->state & (1<<MD_SB_CLEAN)) |
| 774 | mddev->recovery_cp = MaxSector; |
| 775 | else { |
| 776 | if (sb->events_hi == sb->cp_events_hi && |
| 777 | sb->events_lo == sb->cp_events_lo) { |
| 778 | mddev->recovery_cp = sb->recovery_cp; |
| 779 | } else |
| 780 | mddev->recovery_cp = 0; |
| 781 | } |
| 782 | |
| 783 | memcpy(mddev->uuid+0, &sb->set_uuid0, 4); |
| 784 | memcpy(mddev->uuid+4, &sb->set_uuid1, 4); |
| 785 | memcpy(mddev->uuid+8, &sb->set_uuid2, 4); |
| 786 | memcpy(mddev->uuid+12,&sb->set_uuid3, 4); |
| 787 | |
| 788 | mddev->max_disks = MD_SB_DISKS; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 789 | |
| 790 | if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && |
| 791 | mddev->bitmap_file == NULL) { |
NeilBrown | c5a10f6 | 2006-03-27 01:18:03 -0800 | [diff] [blame] | 792 | if (mddev->level != 1 && mddev->level != 4 |
| 793 | && mddev->level != 5 && mddev->level != 6 |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 794 | && mddev->level != 10) { |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 795 | /* FIXME use a better test */ |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 796 | printk(KERN_WARNING "md: bitmaps not supported for this level.\n"); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 797 | return -EINVAL; |
| 798 | } |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 799 | mddev->bitmap_offset = mddev->default_bitmap_offset; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 800 | } |
| 801 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 802 | } else if (mddev->pers == NULL) { |
| 803 | /* Insist on good event counter while assembling */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | ++ev1; |
| 805 | if (ev1 < mddev->events) |
| 806 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 807 | } else if (mddev->bitmap) { |
| 808 | /* if adding to array with a bitmap, then we can accept an |
| 809 | * older device ... but not too old. |
| 810 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 811 | if (ev1 < mddev->bitmap->events_cleared) |
| 812 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 813 | } else { |
| 814 | if (ev1 < mddev->events) |
| 815 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 816 | return 0; |
| 817 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | if (mddev->level != LEVEL_MULTIPATH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | desc = sb->disks + rdev->desc_nr; |
| 821 | |
| 822 | if (desc->state & (1<<MD_DISK_FAULTY)) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 823 | set_bit(Faulty, &rdev->flags); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 824 | else if (desc->state & (1<<MD_DISK_SYNC) /* && |
| 825 | desc->raid_disk < mddev->raid_disks */) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 826 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | rdev->raid_disk = desc->raid_disk; |
| 828 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 829 | if (desc->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 830 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 831 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 832 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | /* |
| 837 | * sync_super for 0.90.0 |
| 838 | */ |
| 839 | static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 840 | { |
| 841 | mdp_super_t *sb; |
| 842 | struct list_head *tmp; |
| 843 | mdk_rdev_t *rdev2; |
| 844 | int next_spare = mddev->raid_disks; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
| 847 | /* make rdev->sb match mddev data.. |
| 848 | * |
| 849 | * 1/ zero out disks |
| 850 | * 2/ Add info for each disk, keeping track of highest desc_nr (next_spare); |
| 851 | * 3/ any empty disks < next_spare become removed |
| 852 | * |
| 853 | * disks[0] gets initialised to REMOVED because |
| 854 | * we cannot be sure from other fields if it has |
| 855 | * been initialised or not. |
| 856 | */ |
| 857 | int i; |
| 858 | int active=0, working=0,failed=0,spare=0,nr_disks=0; |
| 859 | |
NeilBrown | 6118156 | 2005-09-09 16:24:02 -0700 | [diff] [blame] | 860 | rdev->sb_size = MD_SB_BYTES; |
| 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 863 | |
| 864 | memset(sb, 0, sizeof(*sb)); |
| 865 | |
| 866 | sb->md_magic = MD_SB_MAGIC; |
| 867 | sb->major_version = mddev->major_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | sb->patch_version = mddev->patch_version; |
| 869 | sb->gvalid_words = 0; /* ignored */ |
| 870 | memcpy(&sb->set_uuid0, mddev->uuid+0, 4); |
| 871 | memcpy(&sb->set_uuid1, mddev->uuid+4, 4); |
| 872 | memcpy(&sb->set_uuid2, mddev->uuid+8, 4); |
| 873 | memcpy(&sb->set_uuid3, mddev->uuid+12,4); |
| 874 | |
| 875 | sb->ctime = mddev->ctime; |
| 876 | sb->level = mddev->level; |
| 877 | sb->size = mddev->size; |
| 878 | sb->raid_disks = mddev->raid_disks; |
| 879 | sb->md_minor = mddev->md_minor; |
| 880 | sb->not_persistent = !mddev->persistent; |
| 881 | sb->utime = mddev->utime; |
| 882 | sb->state = 0; |
| 883 | sb->events_hi = (mddev->events>>32); |
| 884 | sb->events_lo = (u32)mddev->events; |
| 885 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 886 | if (mddev->reshape_position == MaxSector) |
| 887 | sb->minor_version = 90; |
| 888 | else { |
| 889 | sb->minor_version = 91; |
| 890 | sb->reshape_position = mddev->reshape_position; |
| 891 | sb->new_level = mddev->new_level; |
| 892 | sb->delta_disks = mddev->delta_disks; |
| 893 | sb->new_layout = mddev->new_layout; |
| 894 | sb->new_chunk = mddev->new_chunk; |
| 895 | } |
| 896 | mddev->minor_version = sb->minor_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | if (mddev->in_sync) |
| 898 | { |
| 899 | sb->recovery_cp = mddev->recovery_cp; |
| 900 | sb->cp_events_hi = (mddev->events>>32); |
| 901 | sb->cp_events_lo = (u32)mddev->events; |
| 902 | if (mddev->recovery_cp == MaxSector) |
| 903 | sb->state = (1<< MD_SB_CLEAN); |
| 904 | } else |
| 905 | sb->recovery_cp = 0; |
| 906 | |
| 907 | sb->layout = mddev->layout; |
| 908 | sb->chunk_size = mddev->chunk_size; |
| 909 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 910 | if (mddev->bitmap && mddev->bitmap_file == NULL) |
| 911 | sb->state |= (1<<MD_SB_BITMAP_PRESENT); |
| 912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | sb->disks[0].state = (1<<MD_DISK_REMOVED); |
| 914 | ITERATE_RDEV(mddev,rdev2,tmp) { |
| 915 | mdp_disk_t *d; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 916 | int desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 917 | if (rdev2->raid_disk >= 0 && test_bit(In_sync, &rdev2->flags) |
| 918 | && !test_bit(Faulty, &rdev2->flags)) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 919 | desc_nr = rdev2->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | else |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 921 | desc_nr = next_spare++; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 922 | rdev2->desc_nr = desc_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | d = &sb->disks[rdev2->desc_nr]; |
| 924 | nr_disks++; |
| 925 | d->number = rdev2->desc_nr; |
| 926 | d->major = MAJOR(rdev2->bdev->bd_dev); |
| 927 | d->minor = MINOR(rdev2->bdev->bd_dev); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 928 | if (rdev2->raid_disk >= 0 && test_bit(In_sync, &rdev2->flags) |
| 929 | && !test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | d->raid_disk = rdev2->raid_disk; |
| 931 | else |
| 932 | d->raid_disk = rdev2->desc_nr; /* compatibility */ |
NeilBrown | 1be7892 | 2006-03-27 01:18:03 -0800 | [diff] [blame] | 933 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | d->state = (1<<MD_DISK_FAULTY); |
NeilBrown | 1be7892 | 2006-03-27 01:18:03 -0800 | [diff] [blame] | 935 | else if (test_bit(In_sync, &rdev2->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | d->state = (1<<MD_DISK_ACTIVE); |
| 937 | d->state |= (1<<MD_DISK_SYNC); |
| 938 | active++; |
| 939 | working++; |
| 940 | } else { |
| 941 | d->state = 0; |
| 942 | spare++; |
| 943 | working++; |
| 944 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 945 | if (test_bit(WriteMostly, &rdev2->flags)) |
| 946 | d->state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | /* now set the "removed" and "faulty" bits on any missing devices */ |
| 949 | for (i=0 ; i < mddev->raid_disks ; i++) { |
| 950 | mdp_disk_t *d = &sb->disks[i]; |
| 951 | if (d->state == 0 && d->number == 0) { |
| 952 | d->number = i; |
| 953 | d->raid_disk = i; |
| 954 | d->state = (1<<MD_DISK_REMOVED); |
| 955 | d->state |= (1<<MD_DISK_FAULTY); |
| 956 | failed++; |
| 957 | } |
| 958 | } |
| 959 | sb->nr_disks = nr_disks; |
| 960 | sb->active_disks = active; |
| 961 | sb->working_disks = working; |
| 962 | sb->failed_disks = failed; |
| 963 | sb->spare_disks = spare; |
| 964 | |
| 965 | sb->this_disk = sb->disks[rdev->desc_nr]; |
| 966 | sb->sb_csum = calc_sb_csum(sb); |
| 967 | } |
| 968 | |
| 969 | /* |
| 970 | * version 1 superblock |
| 971 | */ |
| 972 | |
| 973 | static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb) |
| 974 | { |
| 975 | unsigned int disk_csum, csum; |
| 976 | unsigned long long newcsum; |
| 977 | int size = 256 + le32_to_cpu(sb->max_dev)*2; |
| 978 | unsigned int *isuper = (unsigned int*)sb; |
| 979 | int i; |
| 980 | |
| 981 | disk_csum = sb->sb_csum; |
| 982 | sb->sb_csum = 0; |
| 983 | newcsum = 0; |
| 984 | for (i=0; size>=4; size -= 4 ) |
| 985 | newcsum += le32_to_cpu(*isuper++); |
| 986 | |
| 987 | if (size == 2) |
| 988 | newcsum += le16_to_cpu(*(unsigned short*) isuper); |
| 989 | |
| 990 | csum = (newcsum & 0xffffffff) + (newcsum >> 32); |
| 991 | sb->sb_csum = disk_csum; |
| 992 | return cpu_to_le32(csum); |
| 993 | } |
| 994 | |
| 995 | static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 996 | { |
| 997 | struct mdp_superblock_1 *sb; |
| 998 | int ret; |
| 999 | sector_t sb_offset; |
| 1000 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1001 | int bmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
| 1003 | /* |
| 1004 | * Calculate the position of the superblock. |
| 1005 | * It is always aligned to a 4K boundary and |
| 1006 | * depeding on minor_version, it can be: |
| 1007 | * 0: At least 8K, but less than 12K, from end of device |
| 1008 | * 1: At start of device |
| 1009 | * 2: 4K from start of device. |
| 1010 | */ |
| 1011 | switch(minor_version) { |
| 1012 | case 0: |
| 1013 | sb_offset = rdev->bdev->bd_inode->i_size >> 9; |
| 1014 | sb_offset -= 8*2; |
NeilBrown | 3973096 | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1015 | sb_offset &= ~(sector_t)(4*2-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | /* convert from sectors to K */ |
| 1017 | sb_offset /= 2; |
| 1018 | break; |
| 1019 | case 1: |
| 1020 | sb_offset = 0; |
| 1021 | break; |
| 1022 | case 2: |
| 1023 | sb_offset = 4; |
| 1024 | break; |
| 1025 | default: |
| 1026 | return -EINVAL; |
| 1027 | } |
| 1028 | rdev->sb_offset = sb_offset; |
| 1029 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1030 | /* superblock is rarely larger than 1K, but it can be larger, |
| 1031 | * and it is safe to read 4k, so we do that |
| 1032 | */ |
| 1033 | ret = read_disk_sb(rdev, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | if (ret) return ret; |
| 1035 | |
| 1036 | |
| 1037 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1038 | |
| 1039 | if (sb->magic != cpu_to_le32(MD_SB_MAGIC) || |
| 1040 | sb->major_version != cpu_to_le32(1) || |
| 1041 | le32_to_cpu(sb->max_dev) > (4096-256)/2 || |
| 1042 | le64_to_cpu(sb->super_offset) != (rdev->sb_offset<<1) || |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1043 | (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | return -EINVAL; |
| 1045 | |
| 1046 | if (calc_sb_1_csum(sb) != sb->sb_csum) { |
| 1047 | printk("md: invalid superblock checksum on %s\n", |
| 1048 | bdevname(rdev->bdev,b)); |
| 1049 | return -EINVAL; |
| 1050 | } |
| 1051 | if (le64_to_cpu(sb->data_size) < 10) { |
| 1052 | printk("md: data_size too small on %s\n", |
| 1053 | bdevname(rdev->bdev,b)); |
| 1054 | return -EINVAL; |
| 1055 | } |
| 1056 | rdev->preferred_minor = 0xffff; |
| 1057 | rdev->data_offset = le64_to_cpu(sb->data_offset); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1058 | atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1060 | rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256; |
NeilBrown | 720a3dc | 2005-09-09 16:23:59 -0700 | [diff] [blame] | 1061 | bmask = queue_hardsect_size(rdev->bdev->bd_disk->queue)-1; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1062 | if (rdev->sb_size & bmask) |
| 1063 | rdev-> sb_size = (rdev->sb_size | bmask)+1; |
| 1064 | |
NeilBrown | 31b65a0 | 2006-07-10 04:44:14 -0700 | [diff] [blame] | 1065 | if (sb->level == cpu_to_le32(LEVEL_MULTIPATH)) |
| 1066 | rdev->desc_nr = -1; |
| 1067 | else |
| 1068 | rdev->desc_nr = le32_to_cpu(sb->dev_number); |
| 1069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | if (refdev == 0) |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1071 | ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | else { |
| 1073 | __u64 ev1, ev2; |
| 1074 | struct mdp_superblock_1 *refsb = |
| 1075 | (struct mdp_superblock_1*)page_address(refdev->sb_page); |
| 1076 | |
| 1077 | if (memcmp(sb->set_uuid, refsb->set_uuid, 16) != 0 || |
| 1078 | sb->level != refsb->level || |
| 1079 | sb->layout != refsb->layout || |
| 1080 | sb->chunksize != refsb->chunksize) { |
| 1081 | printk(KERN_WARNING "md: %s has strangely different" |
| 1082 | " superblock to %s\n", |
| 1083 | bdevname(rdev->bdev,b), |
| 1084 | bdevname(refdev->bdev,b2)); |
| 1085 | return -EINVAL; |
| 1086 | } |
| 1087 | ev1 = le64_to_cpu(sb->events); |
| 1088 | ev2 = le64_to_cpu(refsb->events); |
| 1089 | |
| 1090 | if (ev1 > ev2) |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1091 | ret = 1; |
| 1092 | else |
| 1093 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | } |
| 1095 | if (minor_version) |
| 1096 | rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2; |
| 1097 | else |
| 1098 | rdev->size = rdev->sb_offset; |
| 1099 | if (rdev->size < le64_to_cpu(sb->data_size)/2) |
| 1100 | return -EINVAL; |
| 1101 | rdev->size = le64_to_cpu(sb->data_size)/2; |
| 1102 | if (le32_to_cpu(sb->chunksize)) |
| 1103 | rdev->size &= ~((sector_t)le32_to_cpu(sb->chunksize)/2 - 1); |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1104 | |
| 1105 | if (le32_to_cpu(sb->size) > rdev->size*2) |
| 1106 | return -EINVAL; |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1107 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1111 | { |
| 1112 | struct mdp_superblock_1 *sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1113 | __u64 ev1 = le64_to_cpu(sb->events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1115 | rdev->raid_disk = -1; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1116 | rdev->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | if (mddev->raid_disks == 0) { |
| 1118 | mddev->major_version = 1; |
| 1119 | mddev->patch_version = 0; |
| 1120 | mddev->persistent = 1; |
| 1121 | mddev->chunk_size = le32_to_cpu(sb->chunksize) << 9; |
| 1122 | mddev->ctime = le64_to_cpu(sb->ctime) & ((1ULL << 32)-1); |
| 1123 | mddev->utime = le64_to_cpu(sb->utime) & ((1ULL << 32)-1); |
| 1124 | mddev->level = le32_to_cpu(sb->level); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 1125 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | mddev->layout = le32_to_cpu(sb->layout); |
| 1127 | mddev->raid_disks = le32_to_cpu(sb->raid_disks); |
| 1128 | mddev->size = le64_to_cpu(sb->size)/2; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1129 | mddev->events = ev1; |
NeilBrown | 9223214 | 2005-08-18 11:24:16 -0700 | [diff] [blame] | 1130 | mddev->bitmap_offset = 0; |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1131 | mddev->default_bitmap_offset = 1024 >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
| 1133 | mddev->recovery_cp = le64_to_cpu(sb->resync_offset); |
| 1134 | memcpy(mddev->uuid, sb->set_uuid, 16); |
| 1135 | |
| 1136 | mddev->max_disks = (4096-256)/2; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1137 | |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1138 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1139 | mddev->bitmap_file == NULL ) { |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1140 | if (mddev->level != 1 && mddev->level != 5 && mddev->level != 6 |
| 1141 | && mddev->level != 10) { |
| 1142 | printk(KERN_WARNING "md: bitmaps not supported for this level.\n"); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1143 | return -EINVAL; |
| 1144 | } |
| 1145 | mddev->bitmap_offset = (__s32)le32_to_cpu(sb->bitmap_offset); |
| 1146 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1147 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) { |
| 1148 | mddev->reshape_position = le64_to_cpu(sb->reshape_position); |
| 1149 | mddev->delta_disks = le32_to_cpu(sb->delta_disks); |
| 1150 | mddev->new_level = le32_to_cpu(sb->new_level); |
| 1151 | mddev->new_layout = le32_to_cpu(sb->new_layout); |
| 1152 | mddev->new_chunk = le32_to_cpu(sb->new_chunk)<<9; |
| 1153 | } else { |
| 1154 | mddev->reshape_position = MaxSector; |
| 1155 | mddev->delta_disks = 0; |
| 1156 | mddev->new_level = mddev->level; |
| 1157 | mddev->new_layout = mddev->layout; |
| 1158 | mddev->new_chunk = mddev->chunk_size; |
| 1159 | } |
| 1160 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1161 | } else if (mddev->pers == NULL) { |
| 1162 | /* Insist of good event counter while assembling */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | ++ev1; |
| 1164 | if (ev1 < mddev->events) |
| 1165 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1166 | } else if (mddev->bitmap) { |
| 1167 | /* If adding to array with a bitmap, then we can accept an |
| 1168 | * older device, but not too old. |
| 1169 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1170 | if (ev1 < mddev->bitmap->events_cleared) |
| 1171 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1172 | } else { |
| 1173 | if (ev1 < mddev->events) |
| 1174 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1175 | return 0; |
| 1176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | if (mddev->level != LEVEL_MULTIPATH) { |
| 1178 | int role; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]); |
| 1180 | switch(role) { |
| 1181 | case 0xffff: /* spare */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | break; |
| 1183 | case 0xfffe: /* faulty */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1184 | set_bit(Faulty, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | break; |
| 1186 | default: |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1187 | if ((le32_to_cpu(sb->feature_map) & |
| 1188 | MD_FEATURE_RECOVERY_OFFSET)) |
| 1189 | rdev->recovery_offset = le64_to_cpu(sb->recovery_offset); |
| 1190 | else |
| 1191 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | rdev->raid_disk = role; |
| 1193 | break; |
| 1194 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1195 | if (sb->devflags & WriteMostly1) |
| 1196 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1197 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1198 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1204 | { |
| 1205 | struct mdp_superblock_1 *sb; |
| 1206 | struct list_head *tmp; |
| 1207 | mdk_rdev_t *rdev2; |
| 1208 | int max_dev, i; |
| 1209 | /* make rdev->sb match mddev and rdev data. */ |
| 1210 | |
| 1211 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1212 | |
| 1213 | sb->feature_map = 0; |
| 1214 | sb->pad0 = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1215 | sb->recovery_offset = cpu_to_le64(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | memset(sb->pad1, 0, sizeof(sb->pad1)); |
| 1217 | memset(sb->pad2, 0, sizeof(sb->pad2)); |
| 1218 | memset(sb->pad3, 0, sizeof(sb->pad3)); |
| 1219 | |
| 1220 | sb->utime = cpu_to_le64((__u64)mddev->utime); |
| 1221 | sb->events = cpu_to_le64(mddev->events); |
| 1222 | if (mddev->in_sync) |
| 1223 | sb->resync_offset = cpu_to_le64(mddev->recovery_cp); |
| 1224 | else |
| 1225 | sb->resync_offset = cpu_to_le64(0); |
| 1226 | |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1227 | sb->cnt_corrected_read = atomic_read(&rdev->corrected_errors); |
| 1228 | |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1229 | sb->raid_disks = cpu_to_le32(mddev->raid_disks); |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1230 | sb->size = cpu_to_le64(mddev->size<<1); |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1231 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1232 | if (mddev->bitmap && mddev->bitmap_file == NULL) { |
| 1233 | sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset); |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1234 | sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1235 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1236 | |
| 1237 | if (rdev->raid_disk >= 0 && |
| 1238 | !test_bit(In_sync, &rdev->flags) && |
| 1239 | rdev->recovery_offset > 0) { |
| 1240 | sb->feature_map |= cpu_to_le32(MD_FEATURE_RECOVERY_OFFSET); |
| 1241 | sb->recovery_offset = cpu_to_le64(rdev->recovery_offset); |
| 1242 | } |
| 1243 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1244 | if (mddev->reshape_position != MaxSector) { |
| 1245 | sb->feature_map |= cpu_to_le32(MD_FEATURE_RESHAPE_ACTIVE); |
| 1246 | sb->reshape_position = cpu_to_le64(mddev->reshape_position); |
| 1247 | sb->new_layout = cpu_to_le32(mddev->new_layout); |
| 1248 | sb->delta_disks = cpu_to_le32(mddev->delta_disks); |
| 1249 | sb->new_level = cpu_to_le32(mddev->new_level); |
| 1250 | sb->new_chunk = cpu_to_le32(mddev->new_chunk>>9); |
| 1251 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | max_dev = 0; |
| 1254 | ITERATE_RDEV(mddev,rdev2,tmp) |
| 1255 | if (rdev2->desc_nr+1 > max_dev) |
| 1256 | max_dev = rdev2->desc_nr+1; |
| 1257 | |
| 1258 | sb->max_dev = cpu_to_le32(max_dev); |
| 1259 | for (i=0; i<max_dev;i++) |
| 1260 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
| 1261 | |
| 1262 | ITERATE_RDEV(mddev,rdev2,tmp) { |
| 1263 | i = rdev2->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1264 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1266 | else if (test_bit(In_sync, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1268 | else if (rdev2->raid_disk >= 0 && rdev2->recovery_offset > 0) |
| 1269 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | else |
| 1271 | sb->dev_roles[i] = cpu_to_le16(0xffff); |
| 1272 | } |
| 1273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | sb->sb_csum = calc_sb_1_csum(sb); |
| 1275 | } |
| 1276 | |
| 1277 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 1278 | static struct super_type super_types[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | [0] = { |
| 1280 | .name = "0.90.0", |
| 1281 | .owner = THIS_MODULE, |
| 1282 | .load_super = super_90_load, |
| 1283 | .validate_super = super_90_validate, |
| 1284 | .sync_super = super_90_sync, |
| 1285 | }, |
| 1286 | [1] = { |
| 1287 | .name = "md-1", |
| 1288 | .owner = THIS_MODULE, |
| 1289 | .load_super = super_1_load, |
| 1290 | .validate_super = super_1_validate, |
| 1291 | .sync_super = super_1_sync, |
| 1292 | }, |
| 1293 | }; |
| 1294 | |
| 1295 | static mdk_rdev_t * match_dev_unit(mddev_t *mddev, mdk_rdev_t *dev) |
| 1296 | { |
| 1297 | struct list_head *tmp; |
| 1298 | mdk_rdev_t *rdev; |
| 1299 | |
| 1300 | ITERATE_RDEV(mddev,rdev,tmp) |
| 1301 | if (rdev->bdev->bd_contains == dev->bdev->bd_contains) |
| 1302 | return rdev; |
| 1303 | |
| 1304 | return NULL; |
| 1305 | } |
| 1306 | |
| 1307 | static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2) |
| 1308 | { |
| 1309 | struct list_head *tmp; |
| 1310 | mdk_rdev_t *rdev; |
| 1311 | |
| 1312 | ITERATE_RDEV(mddev1,rdev,tmp) |
| 1313 | if (match_dev_unit(mddev2, rdev)) |
| 1314 | return 1; |
| 1315 | |
| 1316 | return 0; |
| 1317 | } |
| 1318 | |
| 1319 | static LIST_HEAD(pending_raid_disks); |
| 1320 | |
| 1321 | static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) |
| 1322 | { |
| 1323 | mdk_rdev_t *same_pdev; |
| 1324 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
NeilBrown | f637b9f | 2005-11-08 21:39:37 -0800 | [diff] [blame] | 1325 | struct kobject *ko; |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1326 | char *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
| 1328 | if (rdev->mddev) { |
| 1329 | MD_BUG(); |
| 1330 | return -EINVAL; |
| 1331 | } |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1332 | /* make sure rdev->size exceeds mddev->size */ |
| 1333 | if (rdev->size && (mddev->size == 0 || rdev->size < mddev->size)) { |
| 1334 | if (mddev->pers) |
| 1335 | /* Cannot change size, so fail */ |
| 1336 | return -ENOSPC; |
| 1337 | else |
| 1338 | mddev->size = rdev->size; |
| 1339 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | same_pdev = match_dev_unit(mddev, rdev); |
| 1341 | if (same_pdev) |
| 1342 | printk(KERN_WARNING |
| 1343 | "%s: WARNING: %s appears to be on the same physical" |
| 1344 | " disk as %s. True\n protection against single-disk" |
| 1345 | " failure might be compromised.\n", |
| 1346 | mdname(mddev), bdevname(rdev->bdev,b), |
| 1347 | bdevname(same_pdev->bdev,b2)); |
| 1348 | |
| 1349 | /* Verify rdev->desc_nr is unique. |
| 1350 | * If it is -1, assign a free number, else |
| 1351 | * check number is not in use |
| 1352 | */ |
| 1353 | if (rdev->desc_nr < 0) { |
| 1354 | int choice = 0; |
| 1355 | if (mddev->pers) choice = mddev->raid_disks; |
| 1356 | while (find_rdev_nr(mddev, choice)) |
| 1357 | choice++; |
| 1358 | rdev->desc_nr = choice; |
| 1359 | } else { |
| 1360 | if (find_rdev_nr(mddev, rdev->desc_nr)) |
| 1361 | return -EBUSY; |
| 1362 | } |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1363 | bdevname(rdev->bdev,b); |
| 1364 | if (kobject_set_name(&rdev->kobj, "dev-%s", b) < 0) |
| 1365 | return -ENOMEM; |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1366 | while ( (s=strchr(rdev->kobj.k_name, '/')) != NULL) |
| 1367 | *s = '!'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | |
| 1369 | list_add(&rdev->same_set, &mddev->disks); |
| 1370 | rdev->mddev = mddev; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1371 | printk(KERN_INFO "md: bind<%s>\n", b); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1372 | |
NeilBrown | 9c79197 | 2005-11-08 21:39:28 -0800 | [diff] [blame] | 1373 | rdev->kobj.parent = &mddev->kobj; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1374 | kobject_add(&rdev->kobj); |
| 1375 | |
NeilBrown | f637b9f | 2005-11-08 21:39:37 -0800 | [diff] [blame] | 1376 | if (rdev->bdev->bd_part) |
| 1377 | ko = &rdev->bdev->bd_part->kobj; |
| 1378 | else |
| 1379 | ko = &rdev->bdev->bd_disk->kobj; |
| 1380 | sysfs_create_link(&rdev->kobj, ko, "block"); |
Jun'ichi Nomura | 5463c79 | 2006-03-27 01:17:58 -0800 | [diff] [blame] | 1381 | bd_claim_by_disk(rdev->bdev, rdev, mddev->gendisk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | return 0; |
| 1383 | } |
| 1384 | |
| 1385 | static void unbind_rdev_from_array(mdk_rdev_t * rdev) |
| 1386 | { |
| 1387 | char b[BDEVNAME_SIZE]; |
| 1388 | if (!rdev->mddev) { |
| 1389 | MD_BUG(); |
| 1390 | return; |
| 1391 | } |
Jun'ichi Nomura | 5463c79 | 2006-03-27 01:17:58 -0800 | [diff] [blame] | 1392 | bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | list_del_init(&rdev->same_set); |
| 1394 | printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); |
| 1395 | rdev->mddev = NULL; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1396 | sysfs_remove_link(&rdev->kobj, "block"); |
| 1397 | kobject_del(&rdev->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /* |
| 1401 | * prevent the device from being mounted, repartitioned or |
| 1402 | * otherwise reused by a RAID array (or any other kernel |
| 1403 | * subsystem), by bd_claiming the device. |
| 1404 | */ |
| 1405 | static int lock_rdev(mdk_rdev_t *rdev, dev_t dev) |
| 1406 | { |
| 1407 | int err = 0; |
| 1408 | struct block_device *bdev; |
| 1409 | char b[BDEVNAME_SIZE]; |
| 1410 | |
Ingo Molnar | 663d440 | 2006-07-03 00:25:33 -0700 | [diff] [blame] | 1411 | bdev = open_partition_by_devnum(dev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | if (IS_ERR(bdev)) { |
| 1413 | printk(KERN_ERR "md: could not open %s.\n", |
| 1414 | __bdevname(dev, b)); |
| 1415 | return PTR_ERR(bdev); |
| 1416 | } |
| 1417 | err = bd_claim(bdev, rdev); |
| 1418 | if (err) { |
| 1419 | printk(KERN_ERR "md: could not bd_claim %s.\n", |
| 1420 | bdevname(bdev, b)); |
Ingo Molnar | 663d440 | 2006-07-03 00:25:33 -0700 | [diff] [blame] | 1421 | blkdev_put_partition(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | return err; |
| 1423 | } |
| 1424 | rdev->bdev = bdev; |
| 1425 | return err; |
| 1426 | } |
| 1427 | |
| 1428 | static void unlock_rdev(mdk_rdev_t *rdev) |
| 1429 | { |
| 1430 | struct block_device *bdev = rdev->bdev; |
| 1431 | rdev->bdev = NULL; |
| 1432 | if (!bdev) |
| 1433 | MD_BUG(); |
| 1434 | bd_release(bdev); |
Ingo Molnar | 663d440 | 2006-07-03 00:25:33 -0700 | [diff] [blame] | 1435 | blkdev_put_partition(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | void md_autodetect_dev(dev_t dev); |
| 1439 | |
| 1440 | static void export_rdev(mdk_rdev_t * rdev) |
| 1441 | { |
| 1442 | char b[BDEVNAME_SIZE]; |
| 1443 | printk(KERN_INFO "md: export_rdev(%s)\n", |
| 1444 | bdevname(rdev->bdev,b)); |
| 1445 | if (rdev->mddev) |
| 1446 | MD_BUG(); |
| 1447 | free_disk_sb(rdev); |
| 1448 | list_del_init(&rdev->same_set); |
| 1449 | #ifndef MODULE |
| 1450 | md_autodetect_dev(rdev->bdev->bd_dev); |
| 1451 | #endif |
| 1452 | unlock_rdev(rdev); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1453 | kobject_put(&rdev->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | static void kick_rdev_from_array(mdk_rdev_t * rdev) |
| 1457 | { |
| 1458 | unbind_rdev_from_array(rdev); |
| 1459 | export_rdev(rdev); |
| 1460 | } |
| 1461 | |
| 1462 | static void export_array(mddev_t *mddev) |
| 1463 | { |
| 1464 | struct list_head *tmp; |
| 1465 | mdk_rdev_t *rdev; |
| 1466 | |
| 1467 | ITERATE_RDEV(mddev,rdev,tmp) { |
| 1468 | if (!rdev->mddev) { |
| 1469 | MD_BUG(); |
| 1470 | continue; |
| 1471 | } |
| 1472 | kick_rdev_from_array(rdev); |
| 1473 | } |
| 1474 | if (!list_empty(&mddev->disks)) |
| 1475 | MD_BUG(); |
| 1476 | mddev->raid_disks = 0; |
| 1477 | mddev->major_version = 0; |
| 1478 | } |
| 1479 | |
| 1480 | static void print_desc(mdp_disk_t *desc) |
| 1481 | { |
| 1482 | printk(" DISK<N:%d,(%d,%d),R:%d,S:%d>\n", desc->number, |
| 1483 | desc->major,desc->minor,desc->raid_disk,desc->state); |
| 1484 | } |
| 1485 | |
| 1486 | static void print_sb(mdp_super_t *sb) |
| 1487 | { |
| 1488 | int i; |
| 1489 | |
| 1490 | printk(KERN_INFO |
| 1491 | "md: SB: (V:%d.%d.%d) ID:<%08x.%08x.%08x.%08x> CT:%08x\n", |
| 1492 | sb->major_version, sb->minor_version, sb->patch_version, |
| 1493 | sb->set_uuid0, sb->set_uuid1, sb->set_uuid2, sb->set_uuid3, |
| 1494 | sb->ctime); |
| 1495 | printk(KERN_INFO "md: L%d S%08d ND:%d RD:%d md%d LO:%d CS:%d\n", |
| 1496 | sb->level, sb->size, sb->nr_disks, sb->raid_disks, |
| 1497 | sb->md_minor, sb->layout, sb->chunk_size); |
| 1498 | printk(KERN_INFO "md: UT:%08x ST:%d AD:%d WD:%d" |
| 1499 | " FD:%d SD:%d CSUM:%08x E:%08lx\n", |
| 1500 | sb->utime, sb->state, sb->active_disks, sb->working_disks, |
| 1501 | sb->failed_disks, sb->spare_disks, |
| 1502 | sb->sb_csum, (unsigned long)sb->events_lo); |
| 1503 | |
| 1504 | printk(KERN_INFO); |
| 1505 | for (i = 0; i < MD_SB_DISKS; i++) { |
| 1506 | mdp_disk_t *desc; |
| 1507 | |
| 1508 | desc = sb->disks + i; |
| 1509 | if (desc->number || desc->major || desc->minor || |
| 1510 | desc->raid_disk || (desc->state && (desc->state != 4))) { |
| 1511 | printk(" D %2d: ", i); |
| 1512 | print_desc(desc); |
| 1513 | } |
| 1514 | } |
| 1515 | printk(KERN_INFO "md: THIS: "); |
| 1516 | print_desc(&sb->this_disk); |
| 1517 | |
| 1518 | } |
| 1519 | |
| 1520 | static void print_rdev(mdk_rdev_t *rdev) |
| 1521 | { |
| 1522 | char b[BDEVNAME_SIZE]; |
| 1523 | printk(KERN_INFO "md: rdev %s, SZ:%08llu F:%d S:%d DN:%u\n", |
| 1524 | bdevname(rdev->bdev,b), (unsigned long long)rdev->size, |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1525 | test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags), |
| 1526 | rdev->desc_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | if (rdev->sb_loaded) { |
| 1528 | printk(KERN_INFO "md: rdev superblock:\n"); |
| 1529 | print_sb((mdp_super_t*)page_address(rdev->sb_page)); |
| 1530 | } else |
| 1531 | printk(KERN_INFO "md: no rdev superblock!\n"); |
| 1532 | } |
| 1533 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 1534 | static void md_print_devices(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | { |
| 1536 | struct list_head *tmp, *tmp2; |
| 1537 | mdk_rdev_t *rdev; |
| 1538 | mddev_t *mddev; |
| 1539 | char b[BDEVNAME_SIZE]; |
| 1540 | |
| 1541 | printk("\n"); |
| 1542 | printk("md: **********************************\n"); |
| 1543 | printk("md: * <COMPLETE RAID STATE PRINTOUT> *\n"); |
| 1544 | printk("md: **********************************\n"); |
| 1545 | ITERATE_MDDEV(mddev,tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1547 | if (mddev->bitmap) |
| 1548 | bitmap_print_sb(mddev->bitmap); |
| 1549 | else |
| 1550 | printk("%s: ", mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | ITERATE_RDEV(mddev,rdev,tmp2) |
| 1552 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 1553 | printk("\n"); |
| 1554 | |
| 1555 | ITERATE_RDEV(mddev,rdev,tmp2) |
| 1556 | print_rdev(rdev); |
| 1557 | } |
| 1558 | printk("md: **********************************\n"); |
| 1559 | printk("\n"); |
| 1560 | } |
| 1561 | |
| 1562 | |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1563 | static void sync_sbs(mddev_t * mddev, int nospares) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1565 | /* Update each superblock (in-memory image), but |
| 1566 | * if we are allowed to, skip spares which already |
| 1567 | * have the right event counter, or have one earlier |
| 1568 | * (which would mean they aren't being marked as dirty |
| 1569 | * with the rest of the array) |
| 1570 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | mdk_rdev_t *rdev; |
| 1572 | struct list_head *tmp; |
| 1573 | |
| 1574 | ITERATE_RDEV(mddev,rdev,tmp) { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1575 | if (rdev->sb_events == mddev->events || |
| 1576 | (nospares && |
| 1577 | rdev->raid_disk < 0 && |
| 1578 | (rdev->sb_events&1)==0 && |
| 1579 | rdev->sb_events+1 == mddev->events)) { |
| 1580 | /* Don't update this superblock */ |
| 1581 | rdev->sb_loaded = 2; |
| 1582 | } else { |
| 1583 | super_types[mddev->major_version]. |
| 1584 | sync_super(mddev, rdev); |
| 1585 | rdev->sb_loaded = 1; |
| 1586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1590 | void md_update_sb(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | { |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1592 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | struct list_head *tmp; |
| 1594 | mdk_rdev_t *rdev; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1595 | int sync_req; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1596 | int nospares = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | repeat: |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1599 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1600 | sync_req = mddev->in_sync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | mddev->utime = get_seconds(); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1602 | if (mddev->sb_dirty == 3) |
| 1603 | /* just a clean<-> dirty transition, possibly leave spares alone, |
| 1604 | * though if events isn't the right even/odd, we will have to do |
| 1605 | * spares after all |
| 1606 | */ |
| 1607 | nospares = 1; |
| 1608 | |
| 1609 | /* If this is just a dirty<->clean transition, and the array is clean |
| 1610 | * and 'events' is odd, we can roll back to the previous clean state */ |
| 1611 | if (mddev->sb_dirty == 3 |
| 1612 | && (mddev->in_sync && mddev->recovery_cp == MaxSector) |
| 1613 | && (mddev->events & 1)) |
| 1614 | mddev->events--; |
| 1615 | else { |
| 1616 | /* otherwise we have to go forward and ... */ |
| 1617 | mddev->events ++; |
| 1618 | if (!mddev->in_sync || mddev->recovery_cp != MaxSector) { /* not clean */ |
| 1619 | /* .. if the array isn't clean, insist on an odd 'events' */ |
| 1620 | if ((mddev->events&1)==0) { |
| 1621 | mddev->events++; |
| 1622 | nospares = 0; |
| 1623 | } |
| 1624 | } else { |
| 1625 | /* otherwise insist on an even 'events' (for clean states) */ |
| 1626 | if ((mddev->events&1)) { |
| 1627 | mddev->events++; |
| 1628 | nospares = 0; |
| 1629 | } |
| 1630 | } |
| 1631 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | |
| 1633 | if (!mddev->events) { |
| 1634 | /* |
| 1635 | * oops, this 64-bit counter should never wrap. |
| 1636 | * Either we are in around ~1 trillion A.C., assuming |
| 1637 | * 1 reboot per second, or we have a bug: |
| 1638 | */ |
| 1639 | MD_BUG(); |
| 1640 | mddev->events --; |
| 1641 | } |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1642 | mddev->sb_dirty = 2; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1643 | sync_sbs(mddev, nospares); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | |
| 1645 | /* |
| 1646 | * do not write anything to disk if using |
| 1647 | * nonpersistent superblocks |
| 1648 | */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1649 | if (!mddev->persistent) { |
| 1650 | mddev->sb_dirty = 0; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1651 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 1652 | wake_up(&mddev->sb_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1654 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1655 | spin_unlock_irq(&mddev->write_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | |
| 1657 | dprintk(KERN_INFO |
| 1658 | "md: updating %s RAID superblock on device (in sync %d)\n", |
| 1659 | mdname(mddev),mddev->in_sync); |
| 1660 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1661 | err = bitmap_update_sb(mddev->bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | ITERATE_RDEV(mddev,rdev,tmp) { |
| 1663 | char b[BDEVNAME_SIZE]; |
| 1664 | dprintk(KERN_INFO "md: "); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1665 | if (rdev->sb_loaded != 1) |
| 1666 | continue; /* no noise on spare devices */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1667 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | dprintk("(skipping faulty "); |
| 1669 | |
| 1670 | dprintk("%s ", bdevname(rdev->bdev,b)); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1671 | if (!test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1672 | md_super_write(mddev,rdev, |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1673 | rdev->sb_offset<<1, rdev->sb_size, |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1674 | rdev->sb_page); |
| 1675 | dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", |
| 1676 | bdevname(rdev->bdev,b), |
| 1677 | (unsigned long long)rdev->sb_offset); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1678 | rdev->sb_events = mddev->events; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | } else |
| 1681 | dprintk(")\n"); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1682 | if (mddev->level == LEVEL_MULTIPATH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | /* only need to write one superblock... */ |
| 1684 | break; |
| 1685 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1686 | md_super_wait(mddev); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1687 | /* if there was a failure, sb_dirty was set to 1, and we re-write super */ |
| 1688 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1689 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1690 | if (mddev->in_sync != sync_req|| mddev->sb_dirty == 1) { |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1691 | /* have to write it out again */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1692 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1693 | goto repeat; |
| 1694 | } |
| 1695 | mddev->sb_dirty = 0; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1696 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 1697 | wake_up(&mddev->sb_wait); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1700 | EXPORT_SYMBOL_GPL(md_update_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 1702 | /* words written to sysfs files may, or my not, be \n terminated. |
| 1703 | * We want to accept with case. For this we use cmd_match. |
| 1704 | */ |
| 1705 | static int cmd_match(const char *cmd, const char *str) |
| 1706 | { |
| 1707 | /* See if cmd, written into a sysfs file, matches |
| 1708 | * str. They must either be the same, or cmd can |
| 1709 | * have a trailing newline |
| 1710 | */ |
| 1711 | while (*cmd && *str && *cmd == *str) { |
| 1712 | cmd++; |
| 1713 | str++; |
| 1714 | } |
| 1715 | if (*cmd == '\n') |
| 1716 | cmd++; |
| 1717 | if (*str || *cmd) |
| 1718 | return 0; |
| 1719 | return 1; |
| 1720 | } |
| 1721 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1722 | struct rdev_sysfs_entry { |
| 1723 | struct attribute attr; |
| 1724 | ssize_t (*show)(mdk_rdev_t *, char *); |
| 1725 | ssize_t (*store)(mdk_rdev_t *, const char *, size_t); |
| 1726 | }; |
| 1727 | |
| 1728 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 1729 | state_show(mdk_rdev_t *rdev, char *page) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1730 | { |
| 1731 | char *sep = ""; |
| 1732 | int len=0; |
| 1733 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1734 | if (test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1735 | len+= sprintf(page+len, "%sfaulty",sep); |
| 1736 | sep = ","; |
| 1737 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1738 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1739 | len += sprintf(page+len, "%sin_sync",sep); |
| 1740 | sep = ","; |
| 1741 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 1742 | if (test_bit(WriteMostly, &rdev->flags)) { |
| 1743 | len += sprintf(page+len, "%swrite_mostly",sep); |
| 1744 | sep = ","; |
| 1745 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1746 | if (!test_bit(Faulty, &rdev->flags) && |
| 1747 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1748 | len += sprintf(page+len, "%sspare", sep); |
| 1749 | sep = ","; |
| 1750 | } |
| 1751 | return len+sprintf(page+len, "\n"); |
| 1752 | } |
| 1753 | |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 1754 | static ssize_t |
| 1755 | state_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 1756 | { |
| 1757 | /* can write |
| 1758 | * faulty - simulates and error |
| 1759 | * remove - disconnects the device |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 1760 | * writemostly - sets write_mostly |
| 1761 | * -writemostly - clears write_mostly |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 1762 | */ |
| 1763 | int err = -EINVAL; |
| 1764 | if (cmd_match(buf, "faulty") && rdev->mddev->pers) { |
| 1765 | md_error(rdev->mddev, rdev); |
| 1766 | err = 0; |
| 1767 | } else if (cmd_match(buf, "remove")) { |
| 1768 | if (rdev->raid_disk >= 0) |
| 1769 | err = -EBUSY; |
| 1770 | else { |
| 1771 | mddev_t *mddev = rdev->mddev; |
| 1772 | kick_rdev_from_array(rdev); |
| 1773 | md_update_sb(mddev); |
| 1774 | md_new_event(mddev); |
| 1775 | err = 0; |
| 1776 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 1777 | } else if (cmd_match(buf, "writemostly")) { |
| 1778 | set_bit(WriteMostly, &rdev->flags); |
| 1779 | err = 0; |
| 1780 | } else if (cmd_match(buf, "-writemostly")) { |
| 1781 | clear_bit(WriteMostly, &rdev->flags); |
| 1782 | err = 0; |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 1783 | } |
| 1784 | return err ? err : len; |
| 1785 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 1786 | static struct rdev_sysfs_entry rdev_state = |
| 1787 | __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1788 | |
| 1789 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 1790 | super_show(mdk_rdev_t *rdev, char *page) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1791 | { |
| 1792 | if (rdev->sb_loaded && rdev->sb_size) { |
| 1793 | memcpy(page, page_address(rdev->sb_page), rdev->sb_size); |
| 1794 | return rdev->sb_size; |
| 1795 | } else |
| 1796 | return 0; |
| 1797 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 1798 | static struct rdev_sysfs_entry rdev_super = __ATTR_RO(super); |
| 1799 | |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1800 | static ssize_t |
| 1801 | errors_show(mdk_rdev_t *rdev, char *page) |
| 1802 | { |
| 1803 | return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors)); |
| 1804 | } |
| 1805 | |
| 1806 | static ssize_t |
| 1807 | errors_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 1808 | { |
| 1809 | char *e; |
| 1810 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 1811 | if (*buf && (*e == 0 || *e == '\n')) { |
| 1812 | atomic_set(&rdev->corrected_errors, n); |
| 1813 | return len; |
| 1814 | } |
| 1815 | return -EINVAL; |
| 1816 | } |
| 1817 | static struct rdev_sysfs_entry rdev_errors = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 1818 | __ATTR(errors, S_IRUGO|S_IWUSR, errors_show, errors_store); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1819 | |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1820 | static ssize_t |
| 1821 | slot_show(mdk_rdev_t *rdev, char *page) |
| 1822 | { |
| 1823 | if (rdev->raid_disk < 0) |
| 1824 | return sprintf(page, "none\n"); |
| 1825 | else |
| 1826 | return sprintf(page, "%d\n", rdev->raid_disk); |
| 1827 | } |
| 1828 | |
| 1829 | static ssize_t |
| 1830 | slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 1831 | { |
| 1832 | char *e; |
| 1833 | int slot = simple_strtoul(buf, &e, 10); |
| 1834 | if (strncmp(buf, "none", 4)==0) |
| 1835 | slot = -1; |
| 1836 | else if (e==buf || (*e && *e!= '\n')) |
| 1837 | return -EINVAL; |
| 1838 | if (rdev->mddev->pers) |
| 1839 | /* Cannot set slot in active array (yet) */ |
| 1840 | return -EBUSY; |
| 1841 | if (slot >= rdev->mddev->raid_disks) |
| 1842 | return -ENOSPC; |
| 1843 | rdev->raid_disk = slot; |
| 1844 | /* assume it is working */ |
| 1845 | rdev->flags = 0; |
| 1846 | set_bit(In_sync, &rdev->flags); |
| 1847 | return len; |
| 1848 | } |
| 1849 | |
| 1850 | |
| 1851 | static struct rdev_sysfs_entry rdev_slot = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 1852 | __ATTR(slot, S_IRUGO|S_IWUSR, slot_show, slot_store); |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1853 | |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 1854 | static ssize_t |
| 1855 | offset_show(mdk_rdev_t *rdev, char *page) |
| 1856 | { |
Andrew Morton | 6961ece | 2006-01-06 00:20:59 -0800 | [diff] [blame] | 1857 | return sprintf(page, "%llu\n", (unsigned long long)rdev->data_offset); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | static ssize_t |
| 1861 | offset_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 1862 | { |
| 1863 | char *e; |
| 1864 | unsigned long long offset = simple_strtoull(buf, &e, 10); |
| 1865 | if (e==buf || (*e && *e != '\n')) |
| 1866 | return -EINVAL; |
| 1867 | if (rdev->mddev->pers) |
| 1868 | return -EBUSY; |
| 1869 | rdev->data_offset = offset; |
| 1870 | return len; |
| 1871 | } |
| 1872 | |
| 1873 | static struct rdev_sysfs_entry rdev_offset = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 1874 | __ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 1875 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 1876 | static ssize_t |
| 1877 | rdev_size_show(mdk_rdev_t *rdev, char *page) |
| 1878 | { |
| 1879 | return sprintf(page, "%llu\n", (unsigned long long)rdev->size); |
| 1880 | } |
| 1881 | |
| 1882 | static ssize_t |
| 1883 | rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 1884 | { |
| 1885 | char *e; |
| 1886 | unsigned long long size = simple_strtoull(buf, &e, 10); |
| 1887 | if (e==buf || (*e && *e != '\n')) |
| 1888 | return -EINVAL; |
| 1889 | if (rdev->mddev->pers) |
| 1890 | return -EBUSY; |
| 1891 | rdev->size = size; |
| 1892 | if (size < rdev->mddev->size || rdev->mddev->size == 0) |
| 1893 | rdev->mddev->size = size; |
| 1894 | return len; |
| 1895 | } |
| 1896 | |
| 1897 | static struct rdev_sysfs_entry rdev_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 1898 | __ATTR(size, S_IRUGO|S_IWUSR, rdev_size_show, rdev_size_store); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 1899 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1900 | static struct attribute *rdev_default_attrs[] = { |
| 1901 | &rdev_state.attr, |
| 1902 | &rdev_super.attr, |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1903 | &rdev_errors.attr, |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1904 | &rdev_slot.attr, |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 1905 | &rdev_offset.attr, |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 1906 | &rdev_size.attr, |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1907 | NULL, |
| 1908 | }; |
| 1909 | static ssize_t |
| 1910 | rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 1911 | { |
| 1912 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 1913 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
| 1914 | |
| 1915 | if (!entry->show) |
| 1916 | return -EIO; |
| 1917 | return entry->show(rdev, page); |
| 1918 | } |
| 1919 | |
| 1920 | static ssize_t |
| 1921 | rdev_attr_store(struct kobject *kobj, struct attribute *attr, |
| 1922 | const char *page, size_t length) |
| 1923 | { |
| 1924 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 1925 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
| 1926 | |
| 1927 | if (!entry->store) |
| 1928 | return -EIO; |
| 1929 | return entry->store(rdev, page, length); |
| 1930 | } |
| 1931 | |
| 1932 | static void rdev_free(struct kobject *ko) |
| 1933 | { |
| 1934 | mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj); |
| 1935 | kfree(rdev); |
| 1936 | } |
| 1937 | static struct sysfs_ops rdev_sysfs_ops = { |
| 1938 | .show = rdev_attr_show, |
| 1939 | .store = rdev_attr_store, |
| 1940 | }; |
| 1941 | static struct kobj_type rdev_ktype = { |
| 1942 | .release = rdev_free, |
| 1943 | .sysfs_ops = &rdev_sysfs_ops, |
| 1944 | .default_attrs = rdev_default_attrs, |
| 1945 | }; |
| 1946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | /* |
| 1948 | * Import a device. If 'super_format' >= 0, then sanity check the superblock |
| 1949 | * |
| 1950 | * mark the device faulty if: |
| 1951 | * |
| 1952 | * - the device is nonexistent (zero size) |
| 1953 | * - the device has no valid superblock |
| 1954 | * |
| 1955 | * a faulty rdev _never_ has rdev->sb set. |
| 1956 | */ |
| 1957 | static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_minor) |
| 1958 | { |
| 1959 | char b[BDEVNAME_SIZE]; |
| 1960 | int err; |
| 1961 | mdk_rdev_t *rdev; |
| 1962 | sector_t size; |
| 1963 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 1964 | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | if (!rdev) { |
| 1966 | printk(KERN_ERR "md: could not alloc mem for new device!\n"); |
| 1967 | return ERR_PTR(-ENOMEM); |
| 1968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | |
| 1970 | if ((err = alloc_disk_sb(rdev))) |
| 1971 | goto abort_free; |
| 1972 | |
| 1973 | err = lock_rdev(rdev, newdev); |
| 1974 | if (err) |
| 1975 | goto abort_free; |
| 1976 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1977 | rdev->kobj.parent = NULL; |
| 1978 | rdev->kobj.ktype = &rdev_ktype; |
| 1979 | kobject_init(&rdev->kobj); |
| 1980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | rdev->desc_nr = -1; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1982 | rdev->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | rdev->data_offset = 0; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1984 | rdev->sb_events = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | atomic_set(&rdev->nr_pending, 0); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1986 | atomic_set(&rdev->read_errors, 0); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1987 | atomic_set(&rdev->corrected_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | |
| 1989 | size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 1990 | if (!size) { |
| 1991 | printk(KERN_WARNING |
| 1992 | "md: %s has zero or unknown size, marking faulty!\n", |
| 1993 | bdevname(rdev->bdev,b)); |
| 1994 | err = -EINVAL; |
| 1995 | goto abort_free; |
| 1996 | } |
| 1997 | |
| 1998 | if (super_format >= 0) { |
| 1999 | err = super_types[super_format]. |
| 2000 | load_super(rdev, NULL, super_minor); |
| 2001 | if (err == -EINVAL) { |
| 2002 | printk(KERN_WARNING |
| 2003 | "md: %s has invalid sb, not importing!\n", |
| 2004 | bdevname(rdev->bdev,b)); |
| 2005 | goto abort_free; |
| 2006 | } |
| 2007 | if (err < 0) { |
| 2008 | printk(KERN_WARNING |
| 2009 | "md: could not read %s's sb, not importing!\n", |
| 2010 | bdevname(rdev->bdev,b)); |
| 2011 | goto abort_free; |
| 2012 | } |
| 2013 | } |
| 2014 | INIT_LIST_HEAD(&rdev->same_set); |
| 2015 | |
| 2016 | return rdev; |
| 2017 | |
| 2018 | abort_free: |
| 2019 | if (rdev->sb_page) { |
| 2020 | if (rdev->bdev) |
| 2021 | unlock_rdev(rdev); |
| 2022 | free_disk_sb(rdev); |
| 2023 | } |
| 2024 | kfree(rdev); |
| 2025 | return ERR_PTR(err); |
| 2026 | } |
| 2027 | |
| 2028 | /* |
| 2029 | * Check a full RAID array for plausibility |
| 2030 | */ |
| 2031 | |
| 2032 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 2033 | static void analyze_sbs(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | { |
| 2035 | int i; |
| 2036 | struct list_head *tmp; |
| 2037 | mdk_rdev_t *rdev, *freshest; |
| 2038 | char b[BDEVNAME_SIZE]; |
| 2039 | |
| 2040 | freshest = NULL; |
| 2041 | ITERATE_RDEV(mddev,rdev,tmp) |
| 2042 | switch (super_types[mddev->major_version]. |
| 2043 | load_super(rdev, freshest, mddev->minor_version)) { |
| 2044 | case 1: |
| 2045 | freshest = rdev; |
| 2046 | break; |
| 2047 | case 0: |
| 2048 | break; |
| 2049 | default: |
| 2050 | printk( KERN_ERR \ |
| 2051 | "md: fatal superblock inconsistency in %s" |
| 2052 | " -- removing from array\n", |
| 2053 | bdevname(rdev->bdev,b)); |
| 2054 | kick_rdev_from_array(rdev); |
| 2055 | } |
| 2056 | |
| 2057 | |
| 2058 | super_types[mddev->major_version]. |
| 2059 | validate_super(mddev, freshest); |
| 2060 | |
| 2061 | i = 0; |
| 2062 | ITERATE_RDEV(mddev,rdev,tmp) { |
| 2063 | if (rdev != freshest) |
| 2064 | if (super_types[mddev->major_version]. |
| 2065 | validate_super(mddev, rdev)) { |
| 2066 | printk(KERN_WARNING "md: kicking non-fresh %s" |
| 2067 | " from array!\n", |
| 2068 | bdevname(rdev->bdev,b)); |
| 2069 | kick_rdev_from_array(rdev); |
| 2070 | continue; |
| 2071 | } |
| 2072 | if (mddev->level == LEVEL_MULTIPATH) { |
| 2073 | rdev->desc_nr = i++; |
| 2074 | rdev->raid_disk = rdev->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2075 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | |
| 2080 | |
| 2081 | if (mddev->recovery_cp != MaxSector && |
| 2082 | mddev->level >= 1) |
| 2083 | printk(KERN_ERR "md: %s: raid array is not clean" |
| 2084 | " -- starting background reconstruction\n", |
| 2085 | mdname(mddev)); |
| 2086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2089 | static ssize_t |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2090 | safe_delay_show(mddev_t *mddev, char *page) |
| 2091 | { |
| 2092 | int msec = (mddev->safemode_delay*1000)/HZ; |
| 2093 | return sprintf(page, "%d.%03d\n", msec/1000, msec%1000); |
| 2094 | } |
| 2095 | static ssize_t |
| 2096 | safe_delay_store(mddev_t *mddev, const char *cbuf, size_t len) |
| 2097 | { |
| 2098 | int scale=1; |
| 2099 | int dot=0; |
| 2100 | int i; |
| 2101 | unsigned long msec; |
| 2102 | char buf[30]; |
| 2103 | char *e; |
| 2104 | /* remove a period, and count digits after it */ |
| 2105 | if (len >= sizeof(buf)) |
| 2106 | return -EINVAL; |
| 2107 | strlcpy(buf, cbuf, len); |
| 2108 | buf[len] = 0; |
| 2109 | for (i=0; i<len; i++) { |
| 2110 | if (dot) { |
| 2111 | if (isdigit(buf[i])) { |
| 2112 | buf[i-1] = buf[i]; |
| 2113 | scale *= 10; |
| 2114 | } |
| 2115 | buf[i] = 0; |
| 2116 | } else if (buf[i] == '.') { |
| 2117 | dot=1; |
| 2118 | buf[i] = 0; |
| 2119 | } |
| 2120 | } |
| 2121 | msec = simple_strtoul(buf, &e, 10); |
| 2122 | if (e == buf || (*e && *e != '\n')) |
| 2123 | return -EINVAL; |
| 2124 | msec = (msec * 1000) / scale; |
| 2125 | if (msec == 0) |
| 2126 | mddev->safemode_delay = 0; |
| 2127 | else { |
| 2128 | mddev->safemode_delay = (msec*HZ)/1000; |
| 2129 | if (mddev->safemode_delay == 0) |
| 2130 | mddev->safemode_delay = 1; |
| 2131 | } |
| 2132 | return len; |
| 2133 | } |
| 2134 | static struct md_sysfs_entry md_safe_delay = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2135 | __ATTR(safe_mode_delay, S_IRUGO|S_IWUSR,safe_delay_show, safe_delay_store); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2136 | |
| 2137 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2138 | level_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2139 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2140 | struct mdk_personality *p = mddev->pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2141 | if (p) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2142 | return sprintf(page, "%s\n", p->name); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2143 | else if (mddev->clevel[0]) |
| 2144 | return sprintf(page, "%s\n", mddev->clevel); |
| 2145 | else if (mddev->level != LEVEL_NONE) |
| 2146 | return sprintf(page, "%d\n", mddev->level); |
| 2147 | else |
| 2148 | return 0; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2149 | } |
| 2150 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2151 | static ssize_t |
| 2152 | level_store(mddev_t *mddev, const char *buf, size_t len) |
| 2153 | { |
| 2154 | int rv = len; |
| 2155 | if (mddev->pers) |
| 2156 | return -EBUSY; |
| 2157 | if (len == 0) |
| 2158 | return 0; |
| 2159 | if (len >= sizeof(mddev->clevel)) |
| 2160 | return -ENOSPC; |
| 2161 | strncpy(mddev->clevel, buf, len); |
| 2162 | if (mddev->clevel[len-1] == '\n') |
| 2163 | len--; |
| 2164 | mddev->clevel[len] = 0; |
| 2165 | mddev->level = LEVEL_NONE; |
| 2166 | return rv; |
| 2167 | } |
| 2168 | |
| 2169 | static struct md_sysfs_entry md_level = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2170 | __ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2171 | |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2172 | |
| 2173 | static ssize_t |
| 2174 | layout_show(mddev_t *mddev, char *page) |
| 2175 | { |
| 2176 | /* just a number, not meaningful for all levels */ |
| 2177 | return sprintf(page, "%d\n", mddev->layout); |
| 2178 | } |
| 2179 | |
| 2180 | static ssize_t |
| 2181 | layout_store(mddev_t *mddev, const char *buf, size_t len) |
| 2182 | { |
| 2183 | char *e; |
| 2184 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 2185 | if (mddev->pers) |
| 2186 | return -EBUSY; |
| 2187 | |
| 2188 | if (!*buf || (*e && *e != '\n')) |
| 2189 | return -EINVAL; |
| 2190 | |
| 2191 | mddev->layout = n; |
| 2192 | return len; |
| 2193 | } |
| 2194 | static struct md_sysfs_entry md_layout = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2195 | __ATTR(layout, S_IRUGO|S_IWUSR, layout_show, layout_store); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2196 | |
| 2197 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2198 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2199 | raid_disks_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2200 | { |
NeilBrown | bb63654 | 2005-11-08 21:39:45 -0800 | [diff] [blame] | 2201 | if (mddev->raid_disks == 0) |
| 2202 | return 0; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2203 | return sprintf(page, "%d\n", mddev->raid_disks); |
| 2204 | } |
| 2205 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 2206 | static int update_raid_disks(mddev_t *mddev, int raid_disks); |
| 2207 | |
| 2208 | static ssize_t |
| 2209 | raid_disks_store(mddev_t *mddev, const char *buf, size_t len) |
| 2210 | { |
| 2211 | /* can only set raid_disks if array is not yet active */ |
| 2212 | char *e; |
| 2213 | int rv = 0; |
| 2214 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 2215 | |
| 2216 | if (!*buf || (*e && *e != '\n')) |
| 2217 | return -EINVAL; |
| 2218 | |
| 2219 | if (mddev->pers) |
| 2220 | rv = update_raid_disks(mddev, n); |
| 2221 | else |
| 2222 | mddev->raid_disks = n; |
| 2223 | return rv ? rv : len; |
| 2224 | } |
| 2225 | static struct md_sysfs_entry md_raid_disks = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2226 | __ATTR(raid_disks, S_IRUGO|S_IWUSR, raid_disks_show, raid_disks_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2227 | |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2228 | static ssize_t |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2229 | chunk_size_show(mddev_t *mddev, char *page) |
| 2230 | { |
| 2231 | return sprintf(page, "%d\n", mddev->chunk_size); |
| 2232 | } |
| 2233 | |
| 2234 | static ssize_t |
| 2235 | chunk_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 2236 | { |
| 2237 | /* can only set chunk_size if array is not yet active */ |
| 2238 | char *e; |
| 2239 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 2240 | |
| 2241 | if (mddev->pers) |
| 2242 | return -EBUSY; |
| 2243 | if (!*buf || (*e && *e != '\n')) |
| 2244 | return -EINVAL; |
| 2245 | |
| 2246 | mddev->chunk_size = n; |
| 2247 | return len; |
| 2248 | } |
| 2249 | static struct md_sysfs_entry md_chunk_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2250 | __ATTR(chunk_size, S_IRUGO|S_IWUSR, chunk_size_show, chunk_size_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2251 | |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 2252 | static ssize_t |
| 2253 | resync_start_show(mddev_t *mddev, char *page) |
| 2254 | { |
| 2255 | return sprintf(page, "%llu\n", (unsigned long long)mddev->recovery_cp); |
| 2256 | } |
| 2257 | |
| 2258 | static ssize_t |
| 2259 | resync_start_store(mddev_t *mddev, const char *buf, size_t len) |
| 2260 | { |
| 2261 | /* can only set chunk_size if array is not yet active */ |
| 2262 | char *e; |
| 2263 | unsigned long long n = simple_strtoull(buf, &e, 10); |
| 2264 | |
| 2265 | if (mddev->pers) |
| 2266 | return -EBUSY; |
| 2267 | if (!*buf || (*e && *e != '\n')) |
| 2268 | return -EINVAL; |
| 2269 | |
| 2270 | mddev->recovery_cp = n; |
| 2271 | return len; |
| 2272 | } |
| 2273 | static struct md_sysfs_entry md_resync_start = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2274 | __ATTR(resync_start, S_IRUGO|S_IWUSR, resync_start_show, resync_start_store); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 2275 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2276 | /* |
| 2277 | * The array state can be: |
| 2278 | * |
| 2279 | * clear |
| 2280 | * No devices, no size, no level |
| 2281 | * Equivalent to STOP_ARRAY ioctl |
| 2282 | * inactive |
| 2283 | * May have some settings, but array is not active |
| 2284 | * all IO results in error |
| 2285 | * When written, doesn't tear down array, but just stops it |
| 2286 | * suspended (not supported yet) |
| 2287 | * All IO requests will block. The array can be reconfigured. |
| 2288 | * Writing this, if accepted, will block until array is quiessent |
| 2289 | * readonly |
| 2290 | * no resync can happen. no superblocks get written. |
| 2291 | * write requests fail |
| 2292 | * read-auto |
| 2293 | * like readonly, but behaves like 'clean' on a write request. |
| 2294 | * |
| 2295 | * clean - no pending writes, but otherwise active. |
| 2296 | * When written to inactive array, starts without resync |
| 2297 | * If a write request arrives then |
| 2298 | * if metadata is known, mark 'dirty' and switch to 'active'. |
| 2299 | * if not known, block and switch to write-pending |
| 2300 | * If written to an active array that has pending writes, then fails. |
| 2301 | * active |
| 2302 | * fully active: IO and resync can be happening. |
| 2303 | * When written to inactive array, starts with resync |
| 2304 | * |
| 2305 | * write-pending |
| 2306 | * clean, but writes are blocked waiting for 'active' to be written. |
| 2307 | * |
| 2308 | * active-idle |
| 2309 | * like active, but no writes have been seen for a while (100msec). |
| 2310 | * |
| 2311 | */ |
| 2312 | enum array_state { clear, inactive, suspended, readonly, read_auto, clean, active, |
| 2313 | write_pending, active_idle, bad_word}; |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2314 | static char *array_states[] = { |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2315 | "clear", "inactive", "suspended", "readonly", "read-auto", "clean", "active", |
| 2316 | "write-pending", "active-idle", NULL }; |
| 2317 | |
| 2318 | static int match_word(const char *word, char **list) |
| 2319 | { |
| 2320 | int n; |
| 2321 | for (n=0; list[n]; n++) |
| 2322 | if (cmd_match(word, list[n])) |
| 2323 | break; |
| 2324 | return n; |
| 2325 | } |
| 2326 | |
| 2327 | static ssize_t |
| 2328 | array_state_show(mddev_t *mddev, char *page) |
| 2329 | { |
| 2330 | enum array_state st = inactive; |
| 2331 | |
| 2332 | if (mddev->pers) |
| 2333 | switch(mddev->ro) { |
| 2334 | case 1: |
| 2335 | st = readonly; |
| 2336 | break; |
| 2337 | case 2: |
| 2338 | st = read_auto; |
| 2339 | break; |
| 2340 | case 0: |
| 2341 | if (mddev->in_sync) |
| 2342 | st = clean; |
| 2343 | else if (mddev->safemode) |
| 2344 | st = active_idle; |
| 2345 | else |
| 2346 | st = active; |
| 2347 | } |
| 2348 | else { |
| 2349 | if (list_empty(&mddev->disks) && |
| 2350 | mddev->raid_disks == 0 && |
| 2351 | mddev->size == 0) |
| 2352 | st = clear; |
| 2353 | else |
| 2354 | st = inactive; |
| 2355 | } |
| 2356 | return sprintf(page, "%s\n", array_states[st]); |
| 2357 | } |
| 2358 | |
| 2359 | static int do_md_stop(mddev_t * mddev, int ro); |
| 2360 | static int do_md_run(mddev_t * mddev); |
| 2361 | static int restart_array(mddev_t *mddev); |
| 2362 | |
| 2363 | static ssize_t |
| 2364 | array_state_store(mddev_t *mddev, const char *buf, size_t len) |
| 2365 | { |
| 2366 | int err = -EINVAL; |
| 2367 | enum array_state st = match_word(buf, array_states); |
| 2368 | switch(st) { |
| 2369 | case bad_word: |
| 2370 | break; |
| 2371 | case clear: |
| 2372 | /* stopping an active array */ |
| 2373 | if (mddev->pers) { |
| 2374 | if (atomic_read(&mddev->active) > 1) |
| 2375 | return -EBUSY; |
| 2376 | err = do_md_stop(mddev, 0); |
| 2377 | } |
| 2378 | break; |
| 2379 | case inactive: |
| 2380 | /* stopping an active array */ |
| 2381 | if (mddev->pers) { |
| 2382 | if (atomic_read(&mddev->active) > 1) |
| 2383 | return -EBUSY; |
| 2384 | err = do_md_stop(mddev, 2); |
| 2385 | } |
| 2386 | break; |
| 2387 | case suspended: |
| 2388 | break; /* not supported yet */ |
| 2389 | case readonly: |
| 2390 | if (mddev->pers) |
| 2391 | err = do_md_stop(mddev, 1); |
| 2392 | else { |
| 2393 | mddev->ro = 1; |
| 2394 | err = do_md_run(mddev); |
| 2395 | } |
| 2396 | break; |
| 2397 | case read_auto: |
| 2398 | /* stopping an active array */ |
| 2399 | if (mddev->pers) { |
| 2400 | err = do_md_stop(mddev, 1); |
| 2401 | if (err == 0) |
| 2402 | mddev->ro = 2; /* FIXME mark devices writable */ |
| 2403 | } else { |
| 2404 | mddev->ro = 2; |
| 2405 | err = do_md_run(mddev); |
| 2406 | } |
| 2407 | break; |
| 2408 | case clean: |
| 2409 | if (mddev->pers) { |
| 2410 | restart_array(mddev); |
| 2411 | spin_lock_irq(&mddev->write_lock); |
| 2412 | if (atomic_read(&mddev->writes_pending) == 0) { |
| 2413 | mddev->in_sync = 1; |
| 2414 | mddev->sb_dirty = 1; |
| 2415 | } |
| 2416 | spin_unlock_irq(&mddev->write_lock); |
| 2417 | } else { |
| 2418 | mddev->ro = 0; |
| 2419 | mddev->recovery_cp = MaxSector; |
| 2420 | err = do_md_run(mddev); |
| 2421 | } |
| 2422 | break; |
| 2423 | case active: |
| 2424 | if (mddev->pers) { |
| 2425 | restart_array(mddev); |
| 2426 | mddev->sb_dirty = 0; |
| 2427 | wake_up(&mddev->sb_wait); |
| 2428 | err = 0; |
| 2429 | } else { |
| 2430 | mddev->ro = 0; |
| 2431 | err = do_md_run(mddev); |
| 2432 | } |
| 2433 | break; |
| 2434 | case write_pending: |
| 2435 | case active_idle: |
| 2436 | /* these cannot be set */ |
| 2437 | break; |
| 2438 | } |
| 2439 | if (err) |
| 2440 | return err; |
| 2441 | else |
| 2442 | return len; |
| 2443 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2444 | static struct md_sysfs_entry md_array_state = |
| 2445 | __ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2446 | |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 2447 | static ssize_t |
| 2448 | null_show(mddev_t *mddev, char *page) |
| 2449 | { |
| 2450 | return -EINVAL; |
| 2451 | } |
| 2452 | |
| 2453 | static ssize_t |
| 2454 | new_dev_store(mddev_t *mddev, const char *buf, size_t len) |
| 2455 | { |
| 2456 | /* buf must be %d:%d\n? giving major and minor numbers */ |
| 2457 | /* The new device is added to the array. |
| 2458 | * If the array has a persistent superblock, we read the |
| 2459 | * superblock to initialise info and check validity. |
| 2460 | * Otherwise, only checking done is that in bind_rdev_to_array, |
| 2461 | * which mainly checks size. |
| 2462 | */ |
| 2463 | char *e; |
| 2464 | int major = simple_strtoul(buf, &e, 10); |
| 2465 | int minor; |
| 2466 | dev_t dev; |
| 2467 | mdk_rdev_t *rdev; |
| 2468 | int err; |
| 2469 | |
| 2470 | if (!*buf || *e != ':' || !e[1] || e[1] == '\n') |
| 2471 | return -EINVAL; |
| 2472 | minor = simple_strtoul(e+1, &e, 10); |
| 2473 | if (*e && *e != '\n') |
| 2474 | return -EINVAL; |
| 2475 | dev = MKDEV(major, minor); |
| 2476 | if (major != MAJOR(dev) || |
| 2477 | minor != MINOR(dev)) |
| 2478 | return -EOVERFLOW; |
| 2479 | |
| 2480 | |
| 2481 | if (mddev->persistent) { |
| 2482 | rdev = md_import_device(dev, mddev->major_version, |
| 2483 | mddev->minor_version); |
| 2484 | if (!IS_ERR(rdev) && !list_empty(&mddev->disks)) { |
| 2485 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 2486 | mdk_rdev_t, same_set); |
| 2487 | err = super_types[mddev->major_version] |
| 2488 | .load_super(rdev, rdev0, mddev->minor_version); |
| 2489 | if (err < 0) |
| 2490 | goto out; |
| 2491 | } |
| 2492 | } else |
| 2493 | rdev = md_import_device(dev, -1, -1); |
| 2494 | |
| 2495 | if (IS_ERR(rdev)) |
| 2496 | return PTR_ERR(rdev); |
| 2497 | err = bind_rdev_to_array(rdev, mddev); |
| 2498 | out: |
| 2499 | if (err) |
| 2500 | export_rdev(rdev); |
| 2501 | return err ? err : len; |
| 2502 | } |
| 2503 | |
| 2504 | static struct md_sysfs_entry md_new_device = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2505 | __ATTR(new_dev, S_IWUSR, null_show, new_dev_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2506 | |
| 2507 | static ssize_t |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 2508 | size_show(mddev_t *mddev, char *page) |
| 2509 | { |
| 2510 | return sprintf(page, "%llu\n", (unsigned long long)mddev->size); |
| 2511 | } |
| 2512 | |
| 2513 | static int update_size(mddev_t *mddev, unsigned long size); |
| 2514 | |
| 2515 | static ssize_t |
| 2516 | size_store(mddev_t *mddev, const char *buf, size_t len) |
| 2517 | { |
| 2518 | /* If array is inactive, we can reduce the component size, but |
| 2519 | * not increase it (except from 0). |
| 2520 | * If array is active, we can try an on-line resize |
| 2521 | */ |
| 2522 | char *e; |
| 2523 | int err = 0; |
| 2524 | unsigned long long size = simple_strtoull(buf, &e, 10); |
| 2525 | if (!*buf || *buf == '\n' || |
| 2526 | (*e && *e != '\n')) |
| 2527 | return -EINVAL; |
| 2528 | |
| 2529 | if (mddev->pers) { |
| 2530 | err = update_size(mddev, size); |
| 2531 | md_update_sb(mddev); |
| 2532 | } else { |
| 2533 | if (mddev->size == 0 || |
| 2534 | mddev->size > size) |
| 2535 | mddev->size = size; |
| 2536 | else |
| 2537 | err = -ENOSPC; |
| 2538 | } |
| 2539 | return err ? err : len; |
| 2540 | } |
| 2541 | |
| 2542 | static struct md_sysfs_entry md_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2543 | __ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 2544 | |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2545 | |
| 2546 | /* Metdata version. |
| 2547 | * This is either 'none' for arrays with externally managed metadata, |
| 2548 | * or N.M for internally known formats |
| 2549 | */ |
| 2550 | static ssize_t |
| 2551 | metadata_show(mddev_t *mddev, char *page) |
| 2552 | { |
| 2553 | if (mddev->persistent) |
| 2554 | return sprintf(page, "%d.%d\n", |
| 2555 | mddev->major_version, mddev->minor_version); |
| 2556 | else |
| 2557 | return sprintf(page, "none\n"); |
| 2558 | } |
| 2559 | |
| 2560 | static ssize_t |
| 2561 | metadata_store(mddev_t *mddev, const char *buf, size_t len) |
| 2562 | { |
| 2563 | int major, minor; |
| 2564 | char *e; |
| 2565 | if (!list_empty(&mddev->disks)) |
| 2566 | return -EBUSY; |
| 2567 | |
| 2568 | if (cmd_match(buf, "none")) { |
| 2569 | mddev->persistent = 0; |
| 2570 | mddev->major_version = 0; |
| 2571 | mddev->minor_version = 90; |
| 2572 | return len; |
| 2573 | } |
| 2574 | major = simple_strtoul(buf, &e, 10); |
| 2575 | if (e==buf || *e != '.') |
| 2576 | return -EINVAL; |
| 2577 | buf = e+1; |
| 2578 | minor = simple_strtoul(buf, &e, 10); |
| 2579 | if (e==buf || *e != '\n') |
| 2580 | return -EINVAL; |
| 2581 | if (major >= sizeof(super_types)/sizeof(super_types[0]) || |
| 2582 | super_types[major].name == NULL) |
| 2583 | return -ENOENT; |
| 2584 | mddev->major_version = major; |
| 2585 | mddev->minor_version = minor; |
| 2586 | mddev->persistent = 1; |
| 2587 | return len; |
| 2588 | } |
| 2589 | |
| 2590 | static struct md_sysfs_entry md_metadata = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2591 | __ATTR(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2592 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 2593 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2594 | action_show(mddev_t *mddev, char *page) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2595 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2596 | char *type = "idle"; |
NeilBrown | 31399d9 | 2005-11-08 21:39:29 -0800 | [diff] [blame] | 2597 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 2598 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2599 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 2600 | type = "reshape"; |
| 2601 | else if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2602 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 2603 | type = "resync"; |
| 2604 | else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 2605 | type = "check"; |
| 2606 | else |
| 2607 | type = "repair"; |
| 2608 | } else |
| 2609 | type = "recover"; |
| 2610 | } |
| 2611 | return sprintf(page, "%s\n", type); |
| 2612 | } |
| 2613 | |
| 2614 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2615 | action_store(mddev_t *mddev, const char *page, size_t len) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2616 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2617 | if (!mddev->pers || !mddev->pers->sync_request) |
| 2618 | return -EINVAL; |
| 2619 | |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 2620 | if (cmd_match(page, "idle")) { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2621 | if (mddev->sync_thread) { |
| 2622 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 2623 | md_unregister_thread(mddev->sync_thread); |
| 2624 | mddev->sync_thread = NULL; |
| 2625 | mddev->recovery = 0; |
| 2626 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 2627 | } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 2628 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2629 | return -EBUSY; |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 2630 | else if (cmd_match(page, "resync") || cmd_match(page, "recover")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2631 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 2632 | else if (cmd_match(page, "reshape")) { |
| 2633 | int err; |
| 2634 | if (mddev->pers->start_reshape == NULL) |
| 2635 | return -EINVAL; |
| 2636 | err = mddev->pers->start_reshape(mddev); |
| 2637 | if (err) |
| 2638 | return err; |
| 2639 | } else { |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 2640 | if (cmd_match(page, "check")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2641 | set_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
NeilBrown | 2adc7d4 | 2006-05-20 14:59:57 -0700 | [diff] [blame] | 2642 | else if (!cmd_match(page, "repair")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2643 | return -EINVAL; |
| 2644 | set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
| 2645 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2646 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 2647 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2648 | md_wakeup_thread(mddev->thread); |
| 2649 | return len; |
| 2650 | } |
| 2651 | |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2652 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2653 | mismatch_cnt_show(mddev_t *mddev, char *page) |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2654 | { |
| 2655 | return sprintf(page, "%llu\n", |
| 2656 | (unsigned long long) mddev->resync_mismatches); |
| 2657 | } |
| 2658 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2659 | static struct md_sysfs_entry md_scan_mode = |
| 2660 | __ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2661 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2662 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2663 | static struct md_sysfs_entry md_mismatches = __ATTR_RO(mismatch_cnt); |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2664 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 2665 | static ssize_t |
| 2666 | sync_min_show(mddev_t *mddev, char *page) |
| 2667 | { |
| 2668 | return sprintf(page, "%d (%s)\n", speed_min(mddev), |
| 2669 | mddev->sync_speed_min ? "local": "system"); |
| 2670 | } |
| 2671 | |
| 2672 | static ssize_t |
| 2673 | sync_min_store(mddev_t *mddev, const char *buf, size_t len) |
| 2674 | { |
| 2675 | int min; |
| 2676 | char *e; |
| 2677 | if (strncmp(buf, "system", 6)==0) { |
| 2678 | mddev->sync_speed_min = 0; |
| 2679 | return len; |
| 2680 | } |
| 2681 | min = simple_strtoul(buf, &e, 10); |
| 2682 | if (buf == e || (*e && *e != '\n') || min <= 0) |
| 2683 | return -EINVAL; |
| 2684 | mddev->sync_speed_min = min; |
| 2685 | return len; |
| 2686 | } |
| 2687 | |
| 2688 | static struct md_sysfs_entry md_sync_min = |
| 2689 | __ATTR(sync_speed_min, S_IRUGO|S_IWUSR, sync_min_show, sync_min_store); |
| 2690 | |
| 2691 | static ssize_t |
| 2692 | sync_max_show(mddev_t *mddev, char *page) |
| 2693 | { |
| 2694 | return sprintf(page, "%d (%s)\n", speed_max(mddev), |
| 2695 | mddev->sync_speed_max ? "local": "system"); |
| 2696 | } |
| 2697 | |
| 2698 | static ssize_t |
| 2699 | sync_max_store(mddev_t *mddev, const char *buf, size_t len) |
| 2700 | { |
| 2701 | int max; |
| 2702 | char *e; |
| 2703 | if (strncmp(buf, "system", 6)==0) { |
| 2704 | mddev->sync_speed_max = 0; |
| 2705 | return len; |
| 2706 | } |
| 2707 | max = simple_strtoul(buf, &e, 10); |
| 2708 | if (buf == e || (*e && *e != '\n') || max <= 0) |
| 2709 | return -EINVAL; |
| 2710 | mddev->sync_speed_max = max; |
| 2711 | return len; |
| 2712 | } |
| 2713 | |
| 2714 | static struct md_sysfs_entry md_sync_max = |
| 2715 | __ATTR(sync_speed_max, S_IRUGO|S_IWUSR, sync_max_show, sync_max_store); |
| 2716 | |
| 2717 | |
| 2718 | static ssize_t |
| 2719 | sync_speed_show(mddev_t *mddev, char *page) |
| 2720 | { |
| 2721 | unsigned long resync, dt, db; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 2722 | resync = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active)); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 2723 | dt = ((jiffies - mddev->resync_mark) / HZ); |
| 2724 | if (!dt) dt++; |
| 2725 | db = resync - (mddev->resync_mark_cnt); |
| 2726 | return sprintf(page, "%ld\n", db/dt/2); /* K/sec */ |
| 2727 | } |
| 2728 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2729 | static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 2730 | |
| 2731 | static ssize_t |
| 2732 | sync_completed_show(mddev_t *mddev, char *page) |
| 2733 | { |
| 2734 | unsigned long max_blocks, resync; |
| 2735 | |
| 2736 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 2737 | max_blocks = mddev->resync_max_sectors; |
| 2738 | else |
| 2739 | max_blocks = mddev->size << 1; |
| 2740 | |
| 2741 | resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active)); |
| 2742 | return sprintf(page, "%lu / %lu\n", resync, max_blocks); |
| 2743 | } |
| 2744 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 2745 | static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 2746 | |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 2747 | static ssize_t |
| 2748 | suspend_lo_show(mddev_t *mddev, char *page) |
| 2749 | { |
| 2750 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_lo); |
| 2751 | } |
| 2752 | |
| 2753 | static ssize_t |
| 2754 | suspend_lo_store(mddev_t *mddev, const char *buf, size_t len) |
| 2755 | { |
| 2756 | char *e; |
| 2757 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 2758 | |
| 2759 | if (mddev->pers->quiesce == NULL) |
| 2760 | return -EINVAL; |
| 2761 | if (buf == e || (*e && *e != '\n')) |
| 2762 | return -EINVAL; |
| 2763 | if (new >= mddev->suspend_hi || |
| 2764 | (new > mddev->suspend_lo && new < mddev->suspend_hi)) { |
| 2765 | mddev->suspend_lo = new; |
| 2766 | mddev->pers->quiesce(mddev, 2); |
| 2767 | return len; |
| 2768 | } else |
| 2769 | return -EINVAL; |
| 2770 | } |
| 2771 | static struct md_sysfs_entry md_suspend_lo = |
| 2772 | __ATTR(suspend_lo, S_IRUGO|S_IWUSR, suspend_lo_show, suspend_lo_store); |
| 2773 | |
| 2774 | |
| 2775 | static ssize_t |
| 2776 | suspend_hi_show(mddev_t *mddev, char *page) |
| 2777 | { |
| 2778 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_hi); |
| 2779 | } |
| 2780 | |
| 2781 | static ssize_t |
| 2782 | suspend_hi_store(mddev_t *mddev, const char *buf, size_t len) |
| 2783 | { |
| 2784 | char *e; |
| 2785 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 2786 | |
| 2787 | if (mddev->pers->quiesce == NULL) |
| 2788 | return -EINVAL; |
| 2789 | if (buf == e || (*e && *e != '\n')) |
| 2790 | return -EINVAL; |
| 2791 | if ((new <= mddev->suspend_lo && mddev->suspend_lo >= mddev->suspend_hi) || |
| 2792 | (new > mddev->suspend_lo && new > mddev->suspend_hi)) { |
| 2793 | mddev->suspend_hi = new; |
| 2794 | mddev->pers->quiesce(mddev, 1); |
| 2795 | mddev->pers->quiesce(mddev, 0); |
| 2796 | return len; |
| 2797 | } else |
| 2798 | return -EINVAL; |
| 2799 | } |
| 2800 | static struct md_sysfs_entry md_suspend_hi = |
| 2801 | __ATTR(suspend_hi, S_IRUGO|S_IWUSR, suspend_hi_show, suspend_hi_store); |
| 2802 | |
| 2803 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2804 | static struct attribute *md_default_attrs[] = { |
| 2805 | &md_level.attr, |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2806 | &md_layout.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2807 | &md_raid_disks.attr, |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2808 | &md_chunk_size.attr, |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 2809 | &md_size.attr, |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 2810 | &md_resync_start.attr, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2811 | &md_metadata.attr, |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 2812 | &md_new_device.attr, |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2813 | &md_safe_delay.attr, |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2814 | &md_array_state.attr, |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 2815 | NULL, |
| 2816 | }; |
| 2817 | |
| 2818 | static struct attribute *md_redundancy_attrs[] = { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2819 | &md_scan_mode.attr, |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2820 | &md_mismatches.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 2821 | &md_sync_min.attr, |
| 2822 | &md_sync_max.attr, |
| 2823 | &md_sync_speed.attr, |
| 2824 | &md_sync_completed.attr, |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 2825 | &md_suspend_lo.attr, |
| 2826 | &md_suspend_hi.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2827 | NULL, |
| 2828 | }; |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 2829 | static struct attribute_group md_redundancy_group = { |
| 2830 | .name = NULL, |
| 2831 | .attrs = md_redundancy_attrs, |
| 2832 | }; |
| 2833 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2834 | |
| 2835 | static ssize_t |
| 2836 | md_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 2837 | { |
| 2838 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 2839 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2840 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2841 | |
| 2842 | if (!entry->show) |
| 2843 | return -EIO; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 2844 | rv = mddev_lock(mddev); |
| 2845 | if (!rv) { |
| 2846 | rv = entry->show(mddev, page); |
| 2847 | mddev_unlock(mddev); |
| 2848 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2849 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | static ssize_t |
| 2853 | md_attr_store(struct kobject *kobj, struct attribute *attr, |
| 2854 | const char *page, size_t length) |
| 2855 | { |
| 2856 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 2857 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2858 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2859 | |
| 2860 | if (!entry->store) |
| 2861 | return -EIO; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 2862 | rv = mddev_lock(mddev); |
| 2863 | if (!rv) { |
| 2864 | rv = entry->store(mddev, page, length); |
| 2865 | mddev_unlock(mddev); |
| 2866 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2867 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | static void md_free(struct kobject *ko) |
| 2871 | { |
| 2872 | mddev_t *mddev = container_of(ko, mddev_t, kobj); |
| 2873 | kfree(mddev); |
| 2874 | } |
| 2875 | |
| 2876 | static struct sysfs_ops md_sysfs_ops = { |
| 2877 | .show = md_attr_show, |
| 2878 | .store = md_attr_store, |
| 2879 | }; |
| 2880 | static struct kobj_type md_ktype = { |
| 2881 | .release = md_free, |
| 2882 | .sysfs_ops = &md_sysfs_ops, |
| 2883 | .default_attrs = md_default_attrs, |
| 2884 | }; |
| 2885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | int mdp_major = 0; |
| 2887 | |
| 2888 | static struct kobject *md_probe(dev_t dev, int *part, void *data) |
| 2889 | { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 2890 | static DEFINE_MUTEX(disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | mddev_t *mddev = mddev_find(dev); |
| 2892 | struct gendisk *disk; |
| 2893 | int partitioned = (MAJOR(dev) != MD_MAJOR); |
| 2894 | int shift = partitioned ? MdpMinorShift : 0; |
| 2895 | int unit = MINOR(dev) >> shift; |
| 2896 | |
| 2897 | if (!mddev) |
| 2898 | return NULL; |
| 2899 | |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 2900 | mutex_lock(&disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | if (mddev->gendisk) { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 2902 | mutex_unlock(&disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | mddev_put(mddev); |
| 2904 | return NULL; |
| 2905 | } |
| 2906 | disk = alloc_disk(1 << shift); |
| 2907 | if (!disk) { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 2908 | mutex_unlock(&disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | mddev_put(mddev); |
| 2910 | return NULL; |
| 2911 | } |
| 2912 | disk->major = MAJOR(dev); |
| 2913 | disk->first_minor = unit << shift; |
Greg Kroah-Hartman | ce7b0f4 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2914 | if (partitioned) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | sprintf(disk->disk_name, "md_d%d", unit); |
Greg Kroah-Hartman | ce7b0f4 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 2916 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | sprintf(disk->disk_name, "md%d", unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | disk->fops = &md_fops; |
| 2919 | disk->private_data = mddev; |
| 2920 | disk->queue = mddev->queue; |
| 2921 | add_disk(disk); |
| 2922 | mddev->gendisk = disk; |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 2923 | mutex_unlock(&disks_mutex); |
NeilBrown | 9c79197 | 2005-11-08 21:39:28 -0800 | [diff] [blame] | 2924 | mddev->kobj.parent = &disk->kobj; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2925 | mddev->kobj.k_name = NULL; |
| 2926 | snprintf(mddev->kobj.name, KOBJ_NAME_LEN, "%s", "md"); |
| 2927 | mddev->kobj.ktype = &md_ktype; |
| 2928 | kobject_register(&mddev->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | return NULL; |
| 2930 | } |
| 2931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | static void md_safemode_timeout(unsigned long data) |
| 2933 | { |
| 2934 | mddev_t *mddev = (mddev_t *) data; |
| 2935 | |
| 2936 | mddev->safemode = 1; |
| 2937 | md_wakeup_thread(mddev->thread); |
| 2938 | } |
| 2939 | |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 2940 | static int start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | |
| 2942 | static int do_md_run(mddev_t * mddev) |
| 2943 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2944 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | int chunk_size; |
| 2946 | struct list_head *tmp; |
| 2947 | mdk_rdev_t *rdev; |
| 2948 | struct gendisk *disk; |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2949 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | char b[BDEVNAME_SIZE]; |
| 2951 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 2952 | if (list_empty(&mddev->disks)) |
| 2953 | /* cannot run an array with no devices.. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | |
| 2956 | if (mddev->pers) |
| 2957 | return -EBUSY; |
| 2958 | |
| 2959 | /* |
| 2960 | * Analyze all RAID superblock(s) |
| 2961 | */ |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 2962 | if (!mddev->raid_disks) |
| 2963 | analyze_sbs(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | |
| 2965 | chunk_size = mddev->chunk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2967 | if (chunk_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | if (chunk_size > MAX_CHUNK_SIZE) { |
| 2969 | printk(KERN_ERR "too big chunk_size: %d > %d\n", |
| 2970 | chunk_size, MAX_CHUNK_SIZE); |
| 2971 | return -EINVAL; |
| 2972 | } |
| 2973 | /* |
| 2974 | * chunk-size has to be a power of 2 and multiples of PAGE_SIZE |
| 2975 | */ |
| 2976 | if ( (1 << ffz(~chunk_size)) != chunk_size) { |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 2977 | printk(KERN_ERR "chunk_size of %d not valid\n", chunk_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | return -EINVAL; |
| 2979 | } |
| 2980 | if (chunk_size < PAGE_SIZE) { |
| 2981 | printk(KERN_ERR "too small chunk_size: %d < %ld\n", |
| 2982 | chunk_size, PAGE_SIZE); |
| 2983 | return -EINVAL; |
| 2984 | } |
| 2985 | |
| 2986 | /* devices must have minimum size of one chunk */ |
| 2987 | ITERATE_RDEV(mddev,rdev,tmp) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2988 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | continue; |
| 2990 | if (rdev->size < chunk_size / 1024) { |
| 2991 | printk(KERN_WARNING |
| 2992 | "md: Dev %s smaller than chunk_size:" |
| 2993 | " %lluk < %dk\n", |
| 2994 | bdevname(rdev->bdev,b), |
| 2995 | (unsigned long long)rdev->size, |
| 2996 | chunk_size / 1024); |
| 2997 | return -EINVAL; |
| 2998 | } |
| 2999 | } |
| 3000 | } |
| 3001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | #ifdef CONFIG_KMOD |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3003 | if (mddev->level != LEVEL_NONE) |
| 3004 | request_module("md-level-%d", mddev->level); |
| 3005 | else if (mddev->clevel[0]) |
| 3006 | request_module("md-%s", mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | #endif |
| 3008 | |
| 3009 | /* |
| 3010 | * Drop all container device buffers, from now on |
| 3011 | * the only valid external interface is through the md |
| 3012 | * device. |
| 3013 | * Also find largest hardsector size |
| 3014 | */ |
| 3015 | ITERATE_RDEV(mddev,rdev,tmp) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3016 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | continue; |
| 3018 | sync_blockdev(rdev->bdev); |
| 3019 | invalidate_bdev(rdev->bdev, 0); |
| 3020 | } |
| 3021 | |
| 3022 | md_probe(mddev->unit, NULL, NULL); |
| 3023 | disk = mddev->gendisk; |
| 3024 | if (!disk) |
| 3025 | return -ENOMEM; |
| 3026 | |
| 3027 | spin_lock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3028 | pers = find_pers(mddev->level, mddev->clevel); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3029 | if (!pers || !try_module_get(pers->owner)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | spin_unlock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3031 | if (mddev->level != LEVEL_NONE) |
| 3032 | printk(KERN_WARNING "md: personality for level %d is not loaded!\n", |
| 3033 | mddev->level); |
| 3034 | else |
| 3035 | printk(KERN_WARNING "md: personality for level %s is not loaded!\n", |
| 3036 | mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | return -EINVAL; |
| 3038 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3039 | mddev->pers = pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | spin_unlock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3041 | mddev->level = pers->level; |
| 3042 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 3044 | if (mddev->reshape_position != MaxSector && |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3045 | pers->start_reshape == NULL) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 3046 | /* This personality cannot handle reshaping... */ |
| 3047 | mddev->pers = NULL; |
| 3048 | module_put(pers->owner); |
| 3049 | return -EINVAL; |
| 3050 | } |
| 3051 | |
NeilBrown | 657390d | 2005-08-26 18:34:16 -0700 | [diff] [blame] | 3052 | mddev->recovery = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | mddev->resync_max_sectors = mddev->size << 1; /* may be over-ridden by personality */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 3054 | mddev->barriers_work = 1; |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 3055 | mddev->ok_start_degraded = start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 3057 | if (start_readonly) |
| 3058 | mddev->ro = 2; /* read-only, but switch on first write */ |
| 3059 | |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 3060 | err = mddev->pers->run(mddev); |
| 3061 | if (!err && mddev->pers->sync_request) { |
| 3062 | err = bitmap_create(mddev); |
| 3063 | if (err) { |
| 3064 | printk(KERN_ERR "%s: failed to create bitmap (%d)\n", |
| 3065 | mdname(mddev), err); |
| 3066 | mddev->pers->stop(mddev); |
| 3067 | } |
| 3068 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | if (err) { |
| 3070 | printk(KERN_ERR "md: pers->run() failed ...\n"); |
| 3071 | module_put(mddev->pers->owner); |
| 3072 | mddev->pers = NULL; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 3073 | bitmap_destroy(mddev); |
| 3074 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | } |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 3076 | if (mddev->pers->sync_request) |
| 3077 | sysfs_create_group(&mddev->kobj, &md_redundancy_group); |
NeilBrown | fd9d49c | 2005-11-08 21:39:42 -0800 | [diff] [blame] | 3078 | else if (mddev->ro == 2) /* auto-readonly not meaningful */ |
| 3079 | mddev->ro = 0; |
| 3080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | atomic_set(&mddev->writes_pending,0); |
| 3082 | mddev->safemode = 0; |
| 3083 | mddev->safemode_timer.function = md_safemode_timeout; |
| 3084 | mddev->safemode_timer.data = (unsigned long) mddev; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 3085 | mddev->safemode_delay = (200 * HZ)/1000 +1; /* 200 msec delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | mddev->in_sync = 1; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 3087 | |
| 3088 | ITERATE_RDEV(mddev,rdev,tmp) |
| 3089 | if (rdev->raid_disk >= 0) { |
| 3090 | char nm[20]; |
| 3091 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 3092 | sysfs_create_link(&mddev->kobj, &rdev->kobj, nm); |
| 3093 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | |
| 3095 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3096 | |
| 3097 | if (mddev->sb_dirty) |
| 3098 | md_update_sb(mddev); |
| 3099 | |
| 3100 | set_capacity(disk, mddev->array_size<<1); |
| 3101 | |
| 3102 | /* If we call blk_queue_make_request here, it will |
| 3103 | * re-initialise max_sectors etc which may have been |
| 3104 | * refined inside -> run. So just set the bits we need to set. |
| 3105 | * Most initialisation happended when we called |
| 3106 | * blk_queue_make_request(..., md_fail_request) |
| 3107 | * earlier. |
| 3108 | */ |
| 3109 | mddev->queue->queuedata = mddev; |
| 3110 | mddev->queue->make_request_fn = mddev->pers->make_request; |
| 3111 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3112 | /* If there is a partially-recovered drive we need to |
| 3113 | * start recovery here. If we leave it to md_check_recovery, |
| 3114 | * it will remove the drives and not do the right thing |
| 3115 | */ |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 3116 | if (mddev->degraded && !mddev->sync_thread) { |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3117 | struct list_head *rtmp; |
| 3118 | int spares = 0; |
| 3119 | ITERATE_RDEV(mddev,rdev,rtmp) |
| 3120 | if (rdev->raid_disk >= 0 && |
| 3121 | !test_bit(In_sync, &rdev->flags) && |
| 3122 | !test_bit(Faulty, &rdev->flags)) |
| 3123 | /* complete an interrupted recovery */ |
| 3124 | spares++; |
| 3125 | if (spares && mddev->pers->sync_request) { |
| 3126 | mddev->recovery = 0; |
| 3127 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 3128 | mddev->sync_thread = md_register_thread(md_do_sync, |
| 3129 | mddev, |
| 3130 | "%s_resync"); |
| 3131 | if (!mddev->sync_thread) { |
| 3132 | printk(KERN_ERR "%s: could not start resync" |
| 3133 | " thread...\n", |
| 3134 | mdname(mddev)); |
| 3135 | /* leave the spares where they are, it shouldn't hurt */ |
| 3136 | mddev->recovery = 0; |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 3137 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3138 | } |
| 3139 | } |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 3140 | md_wakeup_thread(mddev->thread); |
| 3141 | md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | mddev->changed = 1; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 3144 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | return 0; |
| 3146 | } |
| 3147 | |
| 3148 | static int restart_array(mddev_t *mddev) |
| 3149 | { |
| 3150 | struct gendisk *disk = mddev->gendisk; |
| 3151 | int err; |
| 3152 | |
| 3153 | /* |
| 3154 | * Complain if it has no devices |
| 3155 | */ |
| 3156 | err = -ENXIO; |
| 3157 | if (list_empty(&mddev->disks)) |
| 3158 | goto out; |
| 3159 | |
| 3160 | if (mddev->pers) { |
| 3161 | err = -EBUSY; |
| 3162 | if (!mddev->ro) |
| 3163 | goto out; |
| 3164 | |
| 3165 | mddev->safemode = 0; |
| 3166 | mddev->ro = 0; |
| 3167 | set_disk_ro(disk, 0); |
| 3168 | |
| 3169 | printk(KERN_INFO "md: %s switched to read-write mode.\n", |
| 3170 | mdname(mddev)); |
| 3171 | /* |
| 3172 | * Kick recovery or resync if necessary |
| 3173 | */ |
| 3174 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3175 | md_wakeup_thread(mddev->thread); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3176 | md_wakeup_thread(mddev->sync_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | err = 0; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3178 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | |
| 3181 | out: |
| 3182 | return err; |
| 3183 | } |
| 3184 | |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 3185 | /* similar to deny_write_access, but accounts for our holding a reference |
| 3186 | * to the file ourselves */ |
| 3187 | static int deny_bitmap_write_access(struct file * file) |
| 3188 | { |
| 3189 | struct inode *inode = file->f_mapping->host; |
| 3190 | |
| 3191 | spin_lock(&inode->i_lock); |
| 3192 | if (atomic_read(&inode->i_writecount) > 1) { |
| 3193 | spin_unlock(&inode->i_lock); |
| 3194 | return -ETXTBSY; |
| 3195 | } |
| 3196 | atomic_set(&inode->i_writecount, -1); |
| 3197 | spin_unlock(&inode->i_lock); |
| 3198 | |
| 3199 | return 0; |
| 3200 | } |
| 3201 | |
| 3202 | static void restore_bitmap_write_access(struct file *file) |
| 3203 | { |
| 3204 | struct inode *inode = file->f_mapping->host; |
| 3205 | |
| 3206 | spin_lock(&inode->i_lock); |
| 3207 | atomic_set(&inode->i_writecount, 1); |
| 3208 | spin_unlock(&inode->i_lock); |
| 3209 | } |
| 3210 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3211 | /* mode: |
| 3212 | * 0 - completely stop and dis-assemble array |
| 3213 | * 1 - switch to readonly |
| 3214 | * 2 - stop but do not disassemble array |
| 3215 | */ |
| 3216 | static int do_md_stop(mddev_t * mddev, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | { |
| 3218 | int err = 0; |
| 3219 | struct gendisk *disk = mddev->gendisk; |
| 3220 | |
| 3221 | if (mddev->pers) { |
| 3222 | if (atomic_read(&mddev->active)>2) { |
| 3223 | printk("md: %s still in use.\n",mdname(mddev)); |
| 3224 | return -EBUSY; |
| 3225 | } |
| 3226 | |
| 3227 | if (mddev->sync_thread) { |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3228 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 3230 | md_unregister_thread(mddev->sync_thread); |
| 3231 | mddev->sync_thread = NULL; |
| 3232 | } |
| 3233 | |
| 3234 | del_timer_sync(&mddev->safemode_timer); |
| 3235 | |
| 3236 | invalidate_partition(disk, 0); |
| 3237 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3238 | switch(mode) { |
| 3239 | case 1: /* readonly */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | err = -ENXIO; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 3241 | if (mddev->ro==1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | goto out; |
| 3243 | mddev->ro = 1; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3244 | break; |
| 3245 | case 0: /* disassemble */ |
| 3246 | case 2: /* stop */ |
NeilBrown | 6b8b3e8 | 2005-08-04 12:53:35 -0700 | [diff] [blame] | 3247 | bitmap_flush(mddev); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 3248 | md_super_wait(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | if (mddev->ro) |
| 3250 | set_disk_ro(disk, 0); |
| 3251 | blk_queue_make_request(mddev->queue, md_fail_request); |
| 3252 | mddev->pers->stop(mddev); |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 3253 | if (mddev->pers->sync_request) |
| 3254 | sysfs_remove_group(&mddev->kobj, &md_redundancy_group); |
| 3255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | module_put(mddev->pers->owner); |
| 3257 | mddev->pers = NULL; |
| 3258 | if (mddev->ro) |
| 3259 | mddev->ro = 0; |
| 3260 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3261 | if (!mddev->in_sync || mddev->sb_dirty) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | /* mark array as shutdown cleanly */ |
| 3263 | mddev->in_sync = 1; |
| 3264 | md_update_sb(mddev); |
| 3265 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3266 | if (mode == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | set_disk_ro(disk, 1); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3268 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 3270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | /* |
| 3272 | * Free resources if final stop |
| 3273 | */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3274 | if (mode == 0) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 3275 | mdk_rdev_t *rdev; |
| 3276 | struct list_head *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | struct gendisk *disk; |
| 3278 | printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); |
| 3279 | |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 3280 | bitmap_destroy(mddev); |
| 3281 | if (mddev->bitmap_file) { |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 3282 | restore_bitmap_write_access(mddev->bitmap_file); |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 3283 | fput(mddev->bitmap_file); |
| 3284 | mddev->bitmap_file = NULL; |
| 3285 | } |
| 3286 | mddev->bitmap_offset = 0; |
| 3287 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 3288 | ITERATE_RDEV(mddev,rdev,tmp) |
| 3289 | if (rdev->raid_disk >= 0) { |
| 3290 | char nm[20]; |
| 3291 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 3292 | sysfs_remove_link(&mddev->kobj, nm); |
| 3293 | } |
| 3294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | export_array(mddev); |
| 3296 | |
| 3297 | mddev->array_size = 0; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3298 | mddev->size = 0; |
| 3299 | mddev->raid_disks = 0; |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3300 | mddev->recovery_cp = 0; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | disk = mddev->gendisk; |
| 3303 | if (disk) |
| 3304 | set_capacity(disk, 0); |
| 3305 | mddev->changed = 1; |
NeilBrown | a8a55c3 | 2006-06-26 00:27:39 -0700 | [diff] [blame] | 3306 | } else if (mddev->pers) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | printk(KERN_INFO "md: %s switched to read-only mode.\n", |
| 3308 | mdname(mddev)); |
| 3309 | err = 0; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 3310 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | out: |
| 3312 | return err; |
| 3313 | } |
| 3314 | |
| 3315 | static void autorun_array(mddev_t *mddev) |
| 3316 | { |
| 3317 | mdk_rdev_t *rdev; |
| 3318 | struct list_head *tmp; |
| 3319 | int err; |
| 3320 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 3321 | if (list_empty(&mddev->disks)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | |
| 3324 | printk(KERN_INFO "md: running: "); |
| 3325 | |
| 3326 | ITERATE_RDEV(mddev,rdev,tmp) { |
| 3327 | char b[BDEVNAME_SIZE]; |
| 3328 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 3329 | } |
| 3330 | printk("\n"); |
| 3331 | |
| 3332 | err = do_md_run (mddev); |
| 3333 | if (err) { |
| 3334 | printk(KERN_WARNING "md: do_md_run() returned %d\n", err); |
| 3335 | do_md_stop (mddev, 0); |
| 3336 | } |
| 3337 | } |
| 3338 | |
| 3339 | /* |
| 3340 | * lets try to run arrays based on all disks that have arrived |
| 3341 | * until now. (those are in pending_raid_disks) |
| 3342 | * |
| 3343 | * the method: pick the first pending disk, collect all disks with |
| 3344 | * the same UUID, remove all from the pending list and put them into |
| 3345 | * the 'same_array' list. Then order this list based on superblock |
| 3346 | * update time (freshest comes first), kick out 'old' disks and |
| 3347 | * compare superblocks. If everything's fine then run it. |
| 3348 | * |
| 3349 | * If "unit" is allocated, then bump its reference count |
| 3350 | */ |
| 3351 | static void autorun_devices(int part) |
| 3352 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | struct list_head *tmp; |
| 3354 | mdk_rdev_t *rdev0, *rdev; |
| 3355 | mddev_t *mddev; |
| 3356 | char b[BDEVNAME_SIZE]; |
| 3357 | |
| 3358 | printk(KERN_INFO "md: autorun ...\n"); |
| 3359 | while (!list_empty(&pending_raid_disks)) { |
| 3360 | dev_t dev; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 3361 | LIST_HEAD(candidates); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | rdev0 = list_entry(pending_raid_disks.next, |
| 3363 | mdk_rdev_t, same_set); |
| 3364 | |
| 3365 | printk(KERN_INFO "md: considering %s ...\n", |
| 3366 | bdevname(rdev0->bdev,b)); |
| 3367 | INIT_LIST_HEAD(&candidates); |
| 3368 | ITERATE_RDEV_PENDING(rdev,tmp) |
| 3369 | if (super_90_load(rdev, rdev0, 0) >= 0) { |
| 3370 | printk(KERN_INFO "md: adding %s ...\n", |
| 3371 | bdevname(rdev->bdev,b)); |
| 3372 | list_move(&rdev->same_set, &candidates); |
| 3373 | } |
| 3374 | /* |
| 3375 | * now we have a set of devices, with all of them having |
| 3376 | * mostly sane superblocks. It's time to allocate the |
| 3377 | * mddev. |
| 3378 | */ |
| 3379 | if (rdev0->preferred_minor < 0 || rdev0->preferred_minor >= MAX_MD_DEVS) { |
| 3380 | printk(KERN_INFO "md: unit number in %s is bad: %d\n", |
| 3381 | bdevname(rdev0->bdev, b), rdev0->preferred_minor); |
| 3382 | break; |
| 3383 | } |
| 3384 | if (part) |
| 3385 | dev = MKDEV(mdp_major, |
| 3386 | rdev0->preferred_minor << MdpMinorShift); |
| 3387 | else |
| 3388 | dev = MKDEV(MD_MAJOR, rdev0->preferred_minor); |
| 3389 | |
| 3390 | md_probe(dev, NULL, NULL); |
| 3391 | mddev = mddev_find(dev); |
| 3392 | if (!mddev) { |
| 3393 | printk(KERN_ERR |
| 3394 | "md: cannot allocate memory for md drive.\n"); |
| 3395 | break; |
| 3396 | } |
| 3397 | if (mddev_lock(mddev)) |
| 3398 | printk(KERN_WARNING "md: %s locked, cannot run\n", |
| 3399 | mdname(mddev)); |
| 3400 | else if (mddev->raid_disks || mddev->major_version |
| 3401 | || !list_empty(&mddev->disks)) { |
| 3402 | printk(KERN_WARNING |
| 3403 | "md: %s already running, cannot run %s\n", |
| 3404 | mdname(mddev), bdevname(rdev0->bdev,b)); |
| 3405 | mddev_unlock(mddev); |
| 3406 | } else { |
| 3407 | printk(KERN_INFO "md: created %s\n", mdname(mddev)); |
| 3408 | ITERATE_RDEV_GENERIC(candidates,rdev,tmp) { |
| 3409 | list_del_init(&rdev->same_set); |
| 3410 | if (bind_rdev_to_array(rdev, mddev)) |
| 3411 | export_rdev(rdev); |
| 3412 | } |
| 3413 | autorun_array(mddev); |
| 3414 | mddev_unlock(mddev); |
| 3415 | } |
| 3416 | /* on success, candidates will be empty, on error |
| 3417 | * it won't... |
| 3418 | */ |
| 3419 | ITERATE_RDEV_GENERIC(candidates,rdev,tmp) |
| 3420 | export_rdev(rdev); |
| 3421 | mddev_put(mddev); |
| 3422 | } |
| 3423 | printk(KERN_INFO "md: ... autorun DONE.\n"); |
| 3424 | } |
| 3425 | |
| 3426 | /* |
| 3427 | * import RAID devices based on one partition |
| 3428 | * if possible, the array gets run as well. |
| 3429 | */ |
| 3430 | |
| 3431 | static int autostart_array(dev_t startdev) |
| 3432 | { |
| 3433 | char b[BDEVNAME_SIZE]; |
| 3434 | int err = -EINVAL, i; |
| 3435 | mdp_super_t *sb = NULL; |
| 3436 | mdk_rdev_t *start_rdev = NULL, *rdev; |
| 3437 | |
| 3438 | start_rdev = md_import_device(startdev, 0, 0); |
| 3439 | if (IS_ERR(start_rdev)) |
| 3440 | return err; |
| 3441 | |
| 3442 | |
| 3443 | /* NOTE: this can only work for 0.90.0 superblocks */ |
| 3444 | sb = (mdp_super_t*)page_address(start_rdev->sb_page); |
| 3445 | if (sb->major_version != 0 || |
| 3446 | sb->minor_version != 90 ) { |
| 3447 | printk(KERN_WARNING "md: can only autostart 0.90.0 arrays\n"); |
| 3448 | export_rdev(start_rdev); |
| 3449 | return err; |
| 3450 | } |
| 3451 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3452 | if (test_bit(Faulty, &start_rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | printk(KERN_WARNING |
| 3454 | "md: can not autostart based on faulty %s!\n", |
| 3455 | bdevname(start_rdev->bdev,b)); |
| 3456 | export_rdev(start_rdev); |
| 3457 | return err; |
| 3458 | } |
| 3459 | list_add(&start_rdev->same_set, &pending_raid_disks); |
| 3460 | |
| 3461 | for (i = 0; i < MD_SB_DISKS; i++) { |
| 3462 | mdp_disk_t *desc = sb->disks + i; |
| 3463 | dev_t dev = MKDEV(desc->major, desc->minor); |
| 3464 | |
| 3465 | if (!dev) |
| 3466 | continue; |
| 3467 | if (dev == startdev) |
| 3468 | continue; |
| 3469 | if (MAJOR(dev) != desc->major || MINOR(dev) != desc->minor) |
| 3470 | continue; |
| 3471 | rdev = md_import_device(dev, 0, 0); |
| 3472 | if (IS_ERR(rdev)) |
| 3473 | continue; |
| 3474 | |
| 3475 | list_add(&rdev->same_set, &pending_raid_disks); |
| 3476 | } |
| 3477 | |
| 3478 | /* |
| 3479 | * possibly return codes |
| 3480 | */ |
| 3481 | autorun_devices(0); |
| 3482 | return 0; |
| 3483 | |
| 3484 | } |
| 3485 | |
| 3486 | |
| 3487 | static int get_version(void __user * arg) |
| 3488 | { |
| 3489 | mdu_version_t ver; |
| 3490 | |
| 3491 | ver.major = MD_MAJOR_VERSION; |
| 3492 | ver.minor = MD_MINOR_VERSION; |
| 3493 | ver.patchlevel = MD_PATCHLEVEL_VERSION; |
| 3494 | |
| 3495 | if (copy_to_user(arg, &ver, sizeof(ver))) |
| 3496 | return -EFAULT; |
| 3497 | |
| 3498 | return 0; |
| 3499 | } |
| 3500 | |
| 3501 | static int get_array_info(mddev_t * mddev, void __user * arg) |
| 3502 | { |
| 3503 | mdu_array_info_t info; |
| 3504 | int nr,working,active,failed,spare; |
| 3505 | mdk_rdev_t *rdev; |
| 3506 | struct list_head *tmp; |
| 3507 | |
| 3508 | nr=working=active=failed=spare=0; |
| 3509 | ITERATE_RDEV(mddev,rdev,tmp) { |
| 3510 | nr++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3511 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | failed++; |
| 3513 | else { |
| 3514 | working++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3515 | if (test_bit(In_sync, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | active++; |
| 3517 | else |
| 3518 | spare++; |
| 3519 | } |
| 3520 | } |
| 3521 | |
| 3522 | info.major_version = mddev->major_version; |
| 3523 | info.minor_version = mddev->minor_version; |
| 3524 | info.patch_version = MD_PATCHLEVEL_VERSION; |
| 3525 | info.ctime = mddev->ctime; |
| 3526 | info.level = mddev->level; |
| 3527 | info.size = mddev->size; |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 3528 | if (info.size != mddev->size) /* overflow */ |
| 3529 | info.size = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | info.nr_disks = nr; |
| 3531 | info.raid_disks = mddev->raid_disks; |
| 3532 | info.md_minor = mddev->md_minor; |
| 3533 | info.not_persistent= !mddev->persistent; |
| 3534 | |
| 3535 | info.utime = mddev->utime; |
| 3536 | info.state = 0; |
| 3537 | if (mddev->in_sync) |
| 3538 | info.state = (1<<MD_SB_CLEAN); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3539 | if (mddev->bitmap && mddev->bitmap_offset) |
| 3540 | info.state = (1<<MD_SB_BITMAP_PRESENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | info.active_disks = active; |
| 3542 | info.working_disks = working; |
| 3543 | info.failed_disks = failed; |
| 3544 | info.spare_disks = spare; |
| 3545 | |
| 3546 | info.layout = mddev->layout; |
| 3547 | info.chunk_size = mddev->chunk_size; |
| 3548 | |
| 3549 | if (copy_to_user(arg, &info, sizeof(info))) |
| 3550 | return -EFAULT; |
| 3551 | |
| 3552 | return 0; |
| 3553 | } |
| 3554 | |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 3555 | static int get_bitmap_file(mddev_t * mddev, void __user * arg) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 3556 | { |
| 3557 | mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ |
| 3558 | char *ptr, *buf = NULL; |
| 3559 | int err = -ENOMEM; |
| 3560 | |
| 3561 | file = kmalloc(sizeof(*file), GFP_KERNEL); |
| 3562 | if (!file) |
| 3563 | goto out; |
| 3564 | |
| 3565 | /* bitmap disabled, zero the first byte and copy out */ |
| 3566 | if (!mddev->bitmap || !mddev->bitmap->file) { |
| 3567 | file->pathname[0] = '\0'; |
| 3568 | goto copy_out; |
| 3569 | } |
| 3570 | |
| 3571 | buf = kmalloc(sizeof(file->pathname), GFP_KERNEL); |
| 3572 | if (!buf) |
| 3573 | goto out; |
| 3574 | |
| 3575 | ptr = file_path(mddev->bitmap->file, buf, sizeof(file->pathname)); |
| 3576 | if (!ptr) |
| 3577 | goto out; |
| 3578 | |
| 3579 | strcpy(file->pathname, ptr); |
| 3580 | |
| 3581 | copy_out: |
| 3582 | err = 0; |
| 3583 | if (copy_to_user(arg, file, sizeof(*file))) |
| 3584 | err = -EFAULT; |
| 3585 | out: |
| 3586 | kfree(buf); |
| 3587 | kfree(file); |
| 3588 | return err; |
| 3589 | } |
| 3590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | static int get_disk_info(mddev_t * mddev, void __user * arg) |
| 3592 | { |
| 3593 | mdu_disk_info_t info; |
| 3594 | unsigned int nr; |
| 3595 | mdk_rdev_t *rdev; |
| 3596 | |
| 3597 | if (copy_from_user(&info, arg, sizeof(info))) |
| 3598 | return -EFAULT; |
| 3599 | |
| 3600 | nr = info.number; |
| 3601 | |
| 3602 | rdev = find_rdev_nr(mddev, nr); |
| 3603 | if (rdev) { |
| 3604 | info.major = MAJOR(rdev->bdev->bd_dev); |
| 3605 | info.minor = MINOR(rdev->bdev->bd_dev); |
| 3606 | info.raid_disk = rdev->raid_disk; |
| 3607 | info.state = 0; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3608 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | info.state |= (1<<MD_DISK_FAULTY); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3610 | else if (test_bit(In_sync, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | info.state |= (1<<MD_DISK_ACTIVE); |
| 3612 | info.state |= (1<<MD_DISK_SYNC); |
| 3613 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3614 | if (test_bit(WriteMostly, &rdev->flags)) |
| 3615 | info.state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | } else { |
| 3617 | info.major = info.minor = 0; |
| 3618 | info.raid_disk = -1; |
| 3619 | info.state = (1<<MD_DISK_REMOVED); |
| 3620 | } |
| 3621 | |
| 3622 | if (copy_to_user(arg, &info, sizeof(info))) |
| 3623 | return -EFAULT; |
| 3624 | |
| 3625 | return 0; |
| 3626 | } |
| 3627 | |
| 3628 | static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) |
| 3629 | { |
| 3630 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 3631 | mdk_rdev_t *rdev; |
| 3632 | dev_t dev = MKDEV(info->major,info->minor); |
| 3633 | |
| 3634 | if (info->major != MAJOR(dev) || info->minor != MINOR(dev)) |
| 3635 | return -EOVERFLOW; |
| 3636 | |
| 3637 | if (!mddev->raid_disks) { |
| 3638 | int err; |
| 3639 | /* expecting a device which has a superblock */ |
| 3640 | rdev = md_import_device(dev, mddev->major_version, mddev->minor_version); |
| 3641 | if (IS_ERR(rdev)) { |
| 3642 | printk(KERN_WARNING |
| 3643 | "md: md_import_device returned %ld\n", |
| 3644 | PTR_ERR(rdev)); |
| 3645 | return PTR_ERR(rdev); |
| 3646 | } |
| 3647 | if (!list_empty(&mddev->disks)) { |
| 3648 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 3649 | mdk_rdev_t, same_set); |
| 3650 | int err = super_types[mddev->major_version] |
| 3651 | .load_super(rdev, rdev0, mddev->minor_version); |
| 3652 | if (err < 0) { |
| 3653 | printk(KERN_WARNING |
| 3654 | "md: %s has different UUID to %s\n", |
| 3655 | bdevname(rdev->bdev,b), |
| 3656 | bdevname(rdev0->bdev,b2)); |
| 3657 | export_rdev(rdev); |
| 3658 | return -EINVAL; |
| 3659 | } |
| 3660 | } |
| 3661 | err = bind_rdev_to_array(rdev, mddev); |
| 3662 | if (err) |
| 3663 | export_rdev(rdev); |
| 3664 | return err; |
| 3665 | } |
| 3666 | |
| 3667 | /* |
| 3668 | * add_new_disk can be used once the array is assembled |
| 3669 | * to add "hot spares". They must already have a superblock |
| 3670 | * written |
| 3671 | */ |
| 3672 | if (mddev->pers) { |
| 3673 | int err; |
| 3674 | if (!mddev->pers->hot_add_disk) { |
| 3675 | printk(KERN_WARNING |
| 3676 | "%s: personality does not support diskops!\n", |
| 3677 | mdname(mddev)); |
| 3678 | return -EINVAL; |
| 3679 | } |
NeilBrown | 7b1e35f | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 3680 | if (mddev->persistent) |
| 3681 | rdev = md_import_device(dev, mddev->major_version, |
| 3682 | mddev->minor_version); |
| 3683 | else |
| 3684 | rdev = md_import_device(dev, -1, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | if (IS_ERR(rdev)) { |
| 3686 | printk(KERN_WARNING |
| 3687 | "md: md_import_device returned %ld\n", |
| 3688 | PTR_ERR(rdev)); |
| 3689 | return PTR_ERR(rdev); |
| 3690 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 3691 | /* set save_raid_disk if appropriate */ |
| 3692 | if (!mddev->persistent) { |
| 3693 | if (info->state & (1<<MD_DISK_SYNC) && |
| 3694 | info->raid_disk < mddev->raid_disks) |
| 3695 | rdev->raid_disk = info->raid_disk; |
| 3696 | else |
| 3697 | rdev->raid_disk = -1; |
| 3698 | } else |
| 3699 | super_types[mddev->major_version]. |
| 3700 | validate_super(mddev, rdev); |
| 3701 | rdev->saved_raid_disk = rdev->raid_disk; |
| 3702 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3703 | clear_bit(In_sync, &rdev->flags); /* just to be sure */ |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3704 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 3705 | set_bit(WriteMostly, &rdev->flags); |
| 3706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | rdev->raid_disk = -1; |
| 3708 | err = bind_rdev_to_array(rdev, mddev); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 3709 | if (!err && !mddev->pers->hot_remove_disk) { |
| 3710 | /* If there is hot_add_disk but no hot_remove_disk |
| 3711 | * then added disks for geometry changes, |
| 3712 | * and should be added immediately. |
| 3713 | */ |
| 3714 | super_types[mddev->major_version]. |
| 3715 | validate_super(mddev, rdev); |
| 3716 | err = mddev->pers->hot_add_disk(mddev, rdev); |
| 3717 | if (err) |
| 3718 | unbind_rdev_from_array(rdev); |
| 3719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | if (err) |
| 3721 | export_rdev(rdev); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 3722 | |
| 3723 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 3724 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | return err; |
| 3726 | } |
| 3727 | |
| 3728 | /* otherwise, add_new_disk is only allowed |
| 3729 | * for major_version==0 superblocks |
| 3730 | */ |
| 3731 | if (mddev->major_version != 0) { |
| 3732 | printk(KERN_WARNING "%s: ADD_NEW_DISK not supported\n", |
| 3733 | mdname(mddev)); |
| 3734 | return -EINVAL; |
| 3735 | } |
| 3736 | |
| 3737 | if (!(info->state & (1<<MD_DISK_FAULTY))) { |
| 3738 | int err; |
| 3739 | rdev = md_import_device (dev, -1, 0); |
| 3740 | if (IS_ERR(rdev)) { |
| 3741 | printk(KERN_WARNING |
| 3742 | "md: error, md_import_device() returned %ld\n", |
| 3743 | PTR_ERR(rdev)); |
| 3744 | return PTR_ERR(rdev); |
| 3745 | } |
| 3746 | rdev->desc_nr = info->number; |
| 3747 | if (info->raid_disk < mddev->raid_disks) |
| 3748 | rdev->raid_disk = info->raid_disk; |
| 3749 | else |
| 3750 | rdev->raid_disk = -1; |
| 3751 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3752 | rdev->flags = 0; |
| 3753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | if (rdev->raid_disk < mddev->raid_disks) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3755 | if (info->state & (1<<MD_DISK_SYNC)) |
| 3756 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3758 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 3759 | set_bit(WriteMostly, &rdev->flags); |
| 3760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | if (!mddev->persistent) { |
| 3762 | printk(KERN_INFO "md: nonpersistent superblock ...\n"); |
| 3763 | rdev->sb_offset = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 3764 | } else |
| 3765 | rdev->sb_offset = calc_dev_sboffset(rdev->bdev); |
| 3766 | rdev->size = calc_dev_size(rdev, mddev->chunk_size); |
| 3767 | |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 3768 | err = bind_rdev_to_array(rdev, mddev); |
| 3769 | if (err) { |
| 3770 | export_rdev(rdev); |
| 3771 | return err; |
| 3772 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | return 0; |
| 3776 | } |
| 3777 | |
| 3778 | static int hot_remove_disk(mddev_t * mddev, dev_t dev) |
| 3779 | { |
| 3780 | char b[BDEVNAME_SIZE]; |
| 3781 | mdk_rdev_t *rdev; |
| 3782 | |
| 3783 | if (!mddev->pers) |
| 3784 | return -ENODEV; |
| 3785 | |
| 3786 | rdev = find_rdev(mddev, dev); |
| 3787 | if (!rdev) |
| 3788 | return -ENXIO; |
| 3789 | |
| 3790 | if (rdev->raid_disk >= 0) |
| 3791 | goto busy; |
| 3792 | |
| 3793 | kick_rdev_from_array(rdev); |
| 3794 | md_update_sb(mddev); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 3795 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | |
| 3797 | return 0; |
| 3798 | busy: |
| 3799 | printk(KERN_WARNING "md: cannot remove active disk %s from %s ... \n", |
| 3800 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 3801 | return -EBUSY; |
| 3802 | } |
| 3803 | |
| 3804 | static int hot_add_disk(mddev_t * mddev, dev_t dev) |
| 3805 | { |
| 3806 | char b[BDEVNAME_SIZE]; |
| 3807 | int err; |
| 3808 | unsigned int size; |
| 3809 | mdk_rdev_t *rdev; |
| 3810 | |
| 3811 | if (!mddev->pers) |
| 3812 | return -ENODEV; |
| 3813 | |
| 3814 | if (mddev->major_version != 0) { |
| 3815 | printk(KERN_WARNING "%s: HOT_ADD may only be used with" |
| 3816 | " version-0 superblocks.\n", |
| 3817 | mdname(mddev)); |
| 3818 | return -EINVAL; |
| 3819 | } |
| 3820 | if (!mddev->pers->hot_add_disk) { |
| 3821 | printk(KERN_WARNING |
| 3822 | "%s: personality does not support diskops!\n", |
| 3823 | mdname(mddev)); |
| 3824 | return -EINVAL; |
| 3825 | } |
| 3826 | |
| 3827 | rdev = md_import_device (dev, -1, 0); |
| 3828 | if (IS_ERR(rdev)) { |
| 3829 | printk(KERN_WARNING |
| 3830 | "md: error, md_import_device() returned %ld\n", |
| 3831 | PTR_ERR(rdev)); |
| 3832 | return -EINVAL; |
| 3833 | } |
| 3834 | |
| 3835 | if (mddev->persistent) |
| 3836 | rdev->sb_offset = calc_dev_sboffset(rdev->bdev); |
| 3837 | else |
| 3838 | rdev->sb_offset = |
| 3839 | rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 3840 | |
| 3841 | size = calc_dev_size(rdev, mddev->chunk_size); |
| 3842 | rdev->size = size; |
| 3843 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3844 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | printk(KERN_WARNING |
| 3846 | "md: can not hot-add faulty %s disk to %s!\n", |
| 3847 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 3848 | err = -EINVAL; |
| 3849 | goto abort_export; |
| 3850 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3851 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | rdev->desc_nr = -1; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 3853 | err = bind_rdev_to_array(rdev, mddev); |
| 3854 | if (err) |
| 3855 | goto abort_export; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | |
| 3857 | /* |
| 3858 | * The rest should better be atomic, we can have disk failures |
| 3859 | * noticed in interrupt contexts ... |
| 3860 | */ |
| 3861 | |
| 3862 | if (rdev->desc_nr == mddev->max_disks) { |
| 3863 | printk(KERN_WARNING "%s: can not hot-add to full array!\n", |
| 3864 | mdname(mddev)); |
| 3865 | err = -EBUSY; |
| 3866 | goto abort_unbind_export; |
| 3867 | } |
| 3868 | |
| 3869 | rdev->raid_disk = -1; |
| 3870 | |
| 3871 | md_update_sb(mddev); |
| 3872 | |
| 3873 | /* |
| 3874 | * Kick recovery, maybe this spare has to be added to the |
| 3875 | * array immediately. |
| 3876 | */ |
| 3877 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3878 | md_wakeup_thread(mddev->thread); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 3879 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | return 0; |
| 3881 | |
| 3882 | abort_unbind_export: |
| 3883 | unbind_rdev_from_array(rdev); |
| 3884 | |
| 3885 | abort_export: |
| 3886 | export_rdev(rdev); |
| 3887 | return err; |
| 3888 | } |
| 3889 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 3890 | static int set_bitmap_file(mddev_t *mddev, int fd) |
| 3891 | { |
| 3892 | int err; |
| 3893 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3894 | if (mddev->pers) { |
| 3895 | if (!mddev->pers->quiesce) |
| 3896 | return -EBUSY; |
| 3897 | if (mddev->recovery || mddev->sync_thread) |
| 3898 | return -EBUSY; |
| 3899 | /* we should be able to change the bitmap.. */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 3900 | } |
| 3901 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3902 | |
| 3903 | if (fd >= 0) { |
| 3904 | if (mddev->bitmap) |
| 3905 | return -EEXIST; /* cannot add when bitmap is present */ |
| 3906 | mddev->bitmap_file = fget(fd); |
| 3907 | |
| 3908 | if (mddev->bitmap_file == NULL) { |
| 3909 | printk(KERN_ERR "%s: error: failed to get bitmap file\n", |
| 3910 | mdname(mddev)); |
| 3911 | return -EBADF; |
| 3912 | } |
| 3913 | |
| 3914 | err = deny_bitmap_write_access(mddev->bitmap_file); |
| 3915 | if (err) { |
| 3916 | printk(KERN_ERR "%s: error: bitmap file is already in use\n", |
| 3917 | mdname(mddev)); |
| 3918 | fput(mddev->bitmap_file); |
| 3919 | mddev->bitmap_file = NULL; |
| 3920 | return err; |
| 3921 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 3922 | mddev->bitmap_offset = 0; /* file overrides offset */ |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3923 | } else if (mddev->bitmap == NULL) |
| 3924 | return -ENOENT; /* cannot remove what isn't there */ |
| 3925 | err = 0; |
| 3926 | if (mddev->pers) { |
| 3927 | mddev->pers->quiesce(mddev, 1); |
| 3928 | if (fd >= 0) |
| 3929 | err = bitmap_create(mddev); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3930 | if (fd < 0 || err) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3931 | bitmap_destroy(mddev); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3932 | fd = -1; /* make sure to put the file */ |
| 3933 | } |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3934 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3935 | } |
| 3936 | if (fd < 0) { |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 3937 | if (mddev->bitmap_file) { |
| 3938 | restore_bitmap_write_access(mddev->bitmap_file); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3939 | fput(mddev->bitmap_file); |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 3940 | } |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 3941 | mddev->bitmap_file = NULL; |
| 3942 | } |
| 3943 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 3944 | return err; |
| 3945 | } |
| 3946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | /* |
| 3948 | * set_array_info is used two different ways |
| 3949 | * The original usage is when creating a new array. |
| 3950 | * In this usage, raid_disks is > 0 and it together with |
| 3951 | * level, size, not_persistent,layout,chunksize determine the |
| 3952 | * shape of the array. |
| 3953 | * This will always create an array with a type-0.90.0 superblock. |
| 3954 | * The newer usage is when assembling an array. |
| 3955 | * In this case raid_disks will be 0, and the major_version field is |
| 3956 | * use to determine which style super-blocks are to be found on the devices. |
| 3957 | * The minor and patch _version numbers are also kept incase the |
| 3958 | * super_block handler wishes to interpret them. |
| 3959 | */ |
| 3960 | static int set_array_info(mddev_t * mddev, mdu_array_info_t *info) |
| 3961 | { |
| 3962 | |
| 3963 | if (info->raid_disks == 0) { |
| 3964 | /* just setting version number for superblock loading */ |
| 3965 | if (info->major_version < 0 || |
| 3966 | info->major_version >= sizeof(super_types)/sizeof(super_types[0]) || |
| 3967 | super_types[info->major_version].name == NULL) { |
| 3968 | /* maybe try to auto-load a module? */ |
| 3969 | printk(KERN_INFO |
| 3970 | "md: superblock version %d not known\n", |
| 3971 | info->major_version); |
| 3972 | return -EINVAL; |
| 3973 | } |
| 3974 | mddev->major_version = info->major_version; |
| 3975 | mddev->minor_version = info->minor_version; |
| 3976 | mddev->patch_version = info->patch_version; |
| 3977 | return 0; |
| 3978 | } |
| 3979 | mddev->major_version = MD_MAJOR_VERSION; |
| 3980 | mddev->minor_version = MD_MINOR_VERSION; |
| 3981 | mddev->patch_version = MD_PATCHLEVEL_VERSION; |
| 3982 | mddev->ctime = get_seconds(); |
| 3983 | |
| 3984 | mddev->level = info->level; |
NeilBrown | 17115e0 | 2006-01-16 22:14:57 -0800 | [diff] [blame] | 3985 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | mddev->size = info->size; |
| 3987 | mddev->raid_disks = info->raid_disks; |
| 3988 | /* don't set md_minor, it is determined by which /dev/md* was |
| 3989 | * openned |
| 3990 | */ |
| 3991 | if (info->state & (1<<MD_SB_CLEAN)) |
| 3992 | mddev->recovery_cp = MaxSector; |
| 3993 | else |
| 3994 | mddev->recovery_cp = 0; |
| 3995 | mddev->persistent = ! info->not_persistent; |
| 3996 | |
| 3997 | mddev->layout = info->layout; |
| 3998 | mddev->chunk_size = info->chunk_size; |
| 3999 | |
| 4000 | mddev->max_disks = MD_SB_DISKS; |
| 4001 | |
| 4002 | mddev->sb_dirty = 1; |
| 4003 | |
NeilBrown | b2a2703 | 2005-11-28 13:44:12 -0800 | [diff] [blame] | 4004 | mddev->default_bitmap_offset = MD_SB_BYTES >> 9; |
| 4005 | mddev->bitmap_offset = 0; |
| 4006 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4007 | mddev->reshape_position = MaxSector; |
| 4008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | /* |
| 4010 | * Generate a 128 bit UUID |
| 4011 | */ |
| 4012 | get_random_bytes(mddev->uuid, 16); |
| 4013 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4014 | mddev->new_level = mddev->level; |
| 4015 | mddev->new_chunk = mddev->chunk_size; |
| 4016 | mddev->new_layout = mddev->layout; |
| 4017 | mddev->delta_disks = 0; |
| 4018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | return 0; |
| 4020 | } |
| 4021 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4022 | static int update_size(mddev_t *mddev, unsigned long size) |
| 4023 | { |
| 4024 | mdk_rdev_t * rdev; |
| 4025 | int rv; |
| 4026 | struct list_head *tmp; |
NeilBrown | 8ddeeae | 2006-03-27 01:18:18 -0800 | [diff] [blame] | 4027 | int fit = (size == 0); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4028 | |
| 4029 | if (mddev->pers->resize == NULL) |
| 4030 | return -EINVAL; |
| 4031 | /* The "size" is the amount of each device that is used. |
| 4032 | * This can only make sense for arrays with redundancy. |
| 4033 | * linear and raid0 always use whatever space is available |
| 4034 | * We can only consider changing the size if no resync |
| 4035 | * or reconstruction is happening, and if the new size |
| 4036 | * is acceptable. It must fit before the sb_offset or, |
| 4037 | * if that is <data_offset, it must fit before the |
| 4038 | * size of each device. |
| 4039 | * If size is zero, we find the largest size that fits. |
| 4040 | */ |
| 4041 | if (mddev->sync_thread) |
| 4042 | return -EBUSY; |
| 4043 | ITERATE_RDEV(mddev,rdev,tmp) { |
| 4044 | sector_t avail; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4045 | if (rdev->sb_offset > rdev->data_offset) |
| 4046 | avail = (rdev->sb_offset*2) - rdev->data_offset; |
| 4047 | else |
| 4048 | avail = get_capacity(rdev->bdev->bd_disk) |
| 4049 | - rdev->data_offset; |
| 4050 | if (fit && (size == 0 || size > avail/2)) |
| 4051 | size = avail/2; |
| 4052 | if (avail < ((sector_t)size << 1)) |
| 4053 | return -ENOSPC; |
| 4054 | } |
| 4055 | rv = mddev->pers->resize(mddev, (sector_t)size *2); |
| 4056 | if (!rv) { |
| 4057 | struct block_device *bdev; |
| 4058 | |
| 4059 | bdev = bdget_disk(mddev->gendisk, 0); |
| 4060 | if (bdev) { |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 4061 | mutex_lock(&bdev->bd_inode->i_mutex); |
NeilBrown | 6d89332 | 2006-02-02 14:28:03 -0800 | [diff] [blame] | 4062 | i_size_write(bdev->bd_inode, (loff_t)mddev->array_size << 10); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 4063 | mutex_unlock(&bdev->bd_inode->i_mutex); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4064 | bdput(bdev); |
| 4065 | } |
| 4066 | } |
| 4067 | return rv; |
| 4068 | } |
| 4069 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4070 | static int update_raid_disks(mddev_t *mddev, int raid_disks) |
| 4071 | { |
| 4072 | int rv; |
| 4073 | /* change the number of raid disks */ |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4074 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4075 | return -EINVAL; |
| 4076 | if (raid_disks <= 0 || |
| 4077 | raid_disks >= mddev->max_disks) |
| 4078 | return -EINVAL; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4079 | if (mddev->sync_thread || mddev->reshape_position != MaxSector) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4080 | return -EBUSY; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4081 | mddev->delta_disks = raid_disks - mddev->raid_disks; |
| 4082 | |
| 4083 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4084 | return rv; |
| 4085 | } |
| 4086 | |
| 4087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | /* |
| 4089 | * update_array_info is used to change the configuration of an |
| 4090 | * on-line array. |
| 4091 | * The version, ctime,level,size,raid_disks,not_persistent, layout,chunk_size |
| 4092 | * fields in the info are checked against the array. |
| 4093 | * Any differences that cannot be handled will cause an error. |
| 4094 | * Normally, only one change can be managed at a time. |
| 4095 | */ |
| 4096 | static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) |
| 4097 | { |
| 4098 | int rv = 0; |
| 4099 | int cnt = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4100 | int state = 0; |
| 4101 | |
| 4102 | /* calculate expected state,ignoring low bits */ |
| 4103 | if (mddev->bitmap && mddev->bitmap_offset) |
| 4104 | state |= (1 << MD_SB_BITMAP_PRESENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | |
| 4106 | if (mddev->major_version != info->major_version || |
| 4107 | mddev->minor_version != info->minor_version || |
| 4108 | /* mddev->patch_version != info->patch_version || */ |
| 4109 | mddev->ctime != info->ctime || |
| 4110 | mddev->level != info->level || |
| 4111 | /* mddev->layout != info->layout || */ |
| 4112 | !mddev->persistent != info->not_persistent|| |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4113 | mddev->chunk_size != info->chunk_size || |
| 4114 | /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */ |
| 4115 | ((state^info->state) & 0xfffffe00) |
| 4116 | ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | return -EINVAL; |
| 4118 | /* Check there is only one change */ |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 4119 | if (info->size >= 0 && mddev->size != info->size) cnt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | if (mddev->raid_disks != info->raid_disks) cnt++; |
| 4121 | if (mddev->layout != info->layout) cnt++; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4122 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) cnt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | if (cnt == 0) return 0; |
| 4124 | if (cnt > 1) return -EINVAL; |
| 4125 | |
| 4126 | if (mddev->layout != info->layout) { |
| 4127 | /* Change layout |
| 4128 | * we don't need to do anything at the md level, the |
| 4129 | * personality will take care of it all. |
| 4130 | */ |
| 4131 | if (mddev->pers->reconfig == NULL) |
| 4132 | return -EINVAL; |
| 4133 | else |
| 4134 | return mddev->pers->reconfig(mddev, info->layout, -1); |
| 4135 | } |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 4136 | if (info->size >= 0 && mddev->size != info->size) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4137 | rv = update_size(mddev, info->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4139 | if (mddev->raid_disks != info->raid_disks) |
| 4140 | rv = update_raid_disks(mddev, info->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4142 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) { |
| 4143 | if (mddev->pers->quiesce == NULL) |
| 4144 | return -EINVAL; |
| 4145 | if (mddev->recovery || mddev->sync_thread) |
| 4146 | return -EBUSY; |
| 4147 | if (info->state & (1<<MD_SB_BITMAP_PRESENT)) { |
| 4148 | /* add the bitmap */ |
| 4149 | if (mddev->bitmap) |
| 4150 | return -EEXIST; |
| 4151 | if (mddev->default_bitmap_offset == 0) |
| 4152 | return -EINVAL; |
| 4153 | mddev->bitmap_offset = mddev->default_bitmap_offset; |
| 4154 | mddev->pers->quiesce(mddev, 1); |
| 4155 | rv = bitmap_create(mddev); |
| 4156 | if (rv) |
| 4157 | bitmap_destroy(mddev); |
| 4158 | mddev->pers->quiesce(mddev, 0); |
| 4159 | } else { |
| 4160 | /* remove the bitmap */ |
| 4161 | if (!mddev->bitmap) |
| 4162 | return -ENOENT; |
| 4163 | if (mddev->bitmap->file) |
| 4164 | return -EINVAL; |
| 4165 | mddev->pers->quiesce(mddev, 1); |
| 4166 | bitmap_destroy(mddev); |
| 4167 | mddev->pers->quiesce(mddev, 0); |
| 4168 | mddev->bitmap_offset = 0; |
| 4169 | } |
| 4170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | md_update_sb(mddev); |
| 4172 | return rv; |
| 4173 | } |
| 4174 | |
| 4175 | static int set_disk_faulty(mddev_t *mddev, dev_t dev) |
| 4176 | { |
| 4177 | mdk_rdev_t *rdev; |
| 4178 | |
| 4179 | if (mddev->pers == NULL) |
| 4180 | return -ENODEV; |
| 4181 | |
| 4182 | rdev = find_rdev(mddev, dev); |
| 4183 | if (!rdev) |
| 4184 | return -ENODEV; |
| 4185 | |
| 4186 | md_error(mddev, rdev); |
| 4187 | return 0; |
| 4188 | } |
| 4189 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 4190 | static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 4191 | { |
| 4192 | mddev_t *mddev = bdev->bd_disk->private_data; |
| 4193 | |
| 4194 | geo->heads = 2; |
| 4195 | geo->sectors = 4; |
| 4196 | geo->cylinders = get_capacity(mddev->gendisk) / 8; |
| 4197 | return 0; |
| 4198 | } |
| 4199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | static int md_ioctl(struct inode *inode, struct file *file, |
| 4201 | unsigned int cmd, unsigned long arg) |
| 4202 | { |
| 4203 | int err = 0; |
| 4204 | void __user *argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | mddev_t *mddev = NULL; |
| 4206 | |
| 4207 | if (!capable(CAP_SYS_ADMIN)) |
| 4208 | return -EACCES; |
| 4209 | |
| 4210 | /* |
| 4211 | * Commands dealing with the RAID driver but not any |
| 4212 | * particular array: |
| 4213 | */ |
| 4214 | switch (cmd) |
| 4215 | { |
| 4216 | case RAID_VERSION: |
| 4217 | err = get_version(argp); |
| 4218 | goto done; |
| 4219 | |
| 4220 | case PRINT_RAID_DEBUG: |
| 4221 | err = 0; |
| 4222 | md_print_devices(); |
| 4223 | goto done; |
| 4224 | |
| 4225 | #ifndef MODULE |
| 4226 | case RAID_AUTORUN: |
| 4227 | err = 0; |
| 4228 | autostart_arrays(arg); |
| 4229 | goto done; |
| 4230 | #endif |
| 4231 | default:; |
| 4232 | } |
| 4233 | |
| 4234 | /* |
| 4235 | * Commands creating/starting a new array: |
| 4236 | */ |
| 4237 | |
| 4238 | mddev = inode->i_bdev->bd_disk->private_data; |
| 4239 | |
| 4240 | if (!mddev) { |
| 4241 | BUG(); |
| 4242 | goto abort; |
| 4243 | } |
| 4244 | |
| 4245 | |
| 4246 | if (cmd == START_ARRAY) { |
| 4247 | /* START_ARRAY doesn't need to lock the array as autostart_array |
| 4248 | * does the locking, and it could even be a different array |
| 4249 | */ |
| 4250 | static int cnt = 3; |
| 4251 | if (cnt > 0 ) { |
| 4252 | printk(KERN_WARNING |
| 4253 | "md: %s(pid %d) used deprecated START_ARRAY ioctl. " |
NeilBrown | e8a0033 | 2005-11-15 00:09:11 -0800 | [diff] [blame] | 4254 | "This will not be supported beyond July 2006\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | current->comm, current->pid); |
| 4256 | cnt--; |
| 4257 | } |
| 4258 | err = autostart_array(new_decode_dev(arg)); |
| 4259 | if (err) { |
| 4260 | printk(KERN_WARNING "md: autostart failed!\n"); |
| 4261 | goto abort; |
| 4262 | } |
| 4263 | goto done; |
| 4264 | } |
| 4265 | |
| 4266 | err = mddev_lock(mddev); |
| 4267 | if (err) { |
| 4268 | printk(KERN_INFO |
| 4269 | "md: ioctl lock interrupted, reason %d, cmd %d\n", |
| 4270 | err, cmd); |
| 4271 | goto abort; |
| 4272 | } |
| 4273 | |
| 4274 | switch (cmd) |
| 4275 | { |
| 4276 | case SET_ARRAY_INFO: |
| 4277 | { |
| 4278 | mdu_array_info_t info; |
| 4279 | if (!arg) |
| 4280 | memset(&info, 0, sizeof(info)); |
| 4281 | else if (copy_from_user(&info, argp, sizeof(info))) { |
| 4282 | err = -EFAULT; |
| 4283 | goto abort_unlock; |
| 4284 | } |
| 4285 | if (mddev->pers) { |
| 4286 | err = update_array_info(mddev, &info); |
| 4287 | if (err) { |
| 4288 | printk(KERN_WARNING "md: couldn't update" |
| 4289 | " array info. %d\n", err); |
| 4290 | goto abort_unlock; |
| 4291 | } |
| 4292 | goto done_unlock; |
| 4293 | } |
| 4294 | if (!list_empty(&mddev->disks)) { |
| 4295 | printk(KERN_WARNING |
| 4296 | "md: array %s already has disks!\n", |
| 4297 | mdname(mddev)); |
| 4298 | err = -EBUSY; |
| 4299 | goto abort_unlock; |
| 4300 | } |
| 4301 | if (mddev->raid_disks) { |
| 4302 | printk(KERN_WARNING |
| 4303 | "md: array %s already initialised!\n", |
| 4304 | mdname(mddev)); |
| 4305 | err = -EBUSY; |
| 4306 | goto abort_unlock; |
| 4307 | } |
| 4308 | err = set_array_info(mddev, &info); |
| 4309 | if (err) { |
| 4310 | printk(KERN_WARNING "md: couldn't set" |
| 4311 | " array info. %d\n", err); |
| 4312 | goto abort_unlock; |
| 4313 | } |
| 4314 | } |
| 4315 | goto done_unlock; |
| 4316 | |
| 4317 | default:; |
| 4318 | } |
| 4319 | |
| 4320 | /* |
| 4321 | * Commands querying/configuring an existing array: |
| 4322 | */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4323 | /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY, |
| 4324 | * RUN_ARRAY, and SET_BITMAP_FILE are allowed */ |
| 4325 | if (!mddev->raid_disks && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY |
| 4326 | && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | err = -ENODEV; |
| 4328 | goto abort_unlock; |
| 4329 | } |
| 4330 | |
| 4331 | /* |
| 4332 | * Commands even a read-only array can execute: |
| 4333 | */ |
| 4334 | switch (cmd) |
| 4335 | { |
| 4336 | case GET_ARRAY_INFO: |
| 4337 | err = get_array_info(mddev, argp); |
| 4338 | goto done_unlock; |
| 4339 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4340 | case GET_BITMAP_FILE: |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 4341 | err = get_bitmap_file(mddev, argp); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4342 | goto done_unlock; |
| 4343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | case GET_DISK_INFO: |
| 4345 | err = get_disk_info(mddev, argp); |
| 4346 | goto done_unlock; |
| 4347 | |
| 4348 | case RESTART_ARRAY_RW: |
| 4349 | err = restart_array(mddev); |
| 4350 | goto done_unlock; |
| 4351 | |
| 4352 | case STOP_ARRAY: |
| 4353 | err = do_md_stop (mddev, 0); |
| 4354 | goto done_unlock; |
| 4355 | |
| 4356 | case STOP_ARRAY_RO: |
| 4357 | err = do_md_stop (mddev, 1); |
| 4358 | goto done_unlock; |
| 4359 | |
| 4360 | /* |
| 4361 | * We have a problem here : there is no easy way to give a CHS |
| 4362 | * virtual geometry. We currently pretend that we have a 2 heads |
| 4363 | * 4 sectors (with a BIG number of cylinders...). This drives |
| 4364 | * dosfs just mad... ;-) |
| 4365 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | /* |
| 4369 | * The remaining ioctls are changing the state of the |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4370 | * superblock, so we do not allow them on read-only arrays. |
| 4371 | * However non-MD ioctls (e.g. get-size) will still come through |
| 4372 | * here and hit the 'default' below, so only disallow |
| 4373 | * 'md' ioctls, and switch to rw mode if started auto-readonly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | */ |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4375 | if (_IOC_TYPE(cmd) == MD_MAJOR && |
| 4376 | mddev->ro && mddev->pers) { |
| 4377 | if (mddev->ro == 2) { |
| 4378 | mddev->ro = 0; |
| 4379 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4380 | md_wakeup_thread(mddev->thread); |
| 4381 | |
| 4382 | } else { |
| 4383 | err = -EROFS; |
| 4384 | goto abort_unlock; |
| 4385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | switch (cmd) |
| 4389 | { |
| 4390 | case ADD_NEW_DISK: |
| 4391 | { |
| 4392 | mdu_disk_info_t info; |
| 4393 | if (copy_from_user(&info, argp, sizeof(info))) |
| 4394 | err = -EFAULT; |
| 4395 | else |
| 4396 | err = add_new_disk(mddev, &info); |
| 4397 | goto done_unlock; |
| 4398 | } |
| 4399 | |
| 4400 | case HOT_REMOVE_DISK: |
| 4401 | err = hot_remove_disk(mddev, new_decode_dev(arg)); |
| 4402 | goto done_unlock; |
| 4403 | |
| 4404 | case HOT_ADD_DISK: |
| 4405 | err = hot_add_disk(mddev, new_decode_dev(arg)); |
| 4406 | goto done_unlock; |
| 4407 | |
| 4408 | case SET_DISK_FAULTY: |
| 4409 | err = set_disk_faulty(mddev, new_decode_dev(arg)); |
| 4410 | goto done_unlock; |
| 4411 | |
| 4412 | case RUN_ARRAY: |
| 4413 | err = do_md_run (mddev); |
| 4414 | goto done_unlock; |
| 4415 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4416 | case SET_BITMAP_FILE: |
| 4417 | err = set_bitmap_file(mddev, (int)arg); |
| 4418 | goto done_unlock; |
| 4419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | err = -EINVAL; |
| 4422 | goto abort_unlock; |
| 4423 | } |
| 4424 | |
| 4425 | done_unlock: |
| 4426 | abort_unlock: |
| 4427 | mddev_unlock(mddev); |
| 4428 | |
| 4429 | return err; |
| 4430 | done: |
| 4431 | if (err) |
| 4432 | MD_BUG(); |
| 4433 | abort: |
| 4434 | return err; |
| 4435 | } |
| 4436 | |
| 4437 | static int md_open(struct inode *inode, struct file *file) |
| 4438 | { |
| 4439 | /* |
| 4440 | * Succeed if we can lock the mddev, which confirms that |
| 4441 | * it isn't being stopped right now. |
| 4442 | */ |
| 4443 | mddev_t *mddev = inode->i_bdev->bd_disk->private_data; |
| 4444 | int err; |
| 4445 | |
| 4446 | if ((err = mddev_lock(mddev))) |
| 4447 | goto out; |
| 4448 | |
| 4449 | err = 0; |
| 4450 | mddev_get(mddev); |
| 4451 | mddev_unlock(mddev); |
| 4452 | |
| 4453 | check_disk_change(inode->i_bdev); |
| 4454 | out: |
| 4455 | return err; |
| 4456 | } |
| 4457 | |
| 4458 | static int md_release(struct inode *inode, struct file * file) |
| 4459 | { |
| 4460 | mddev_t *mddev = inode->i_bdev->bd_disk->private_data; |
| 4461 | |
| 4462 | if (!mddev) |
| 4463 | BUG(); |
| 4464 | mddev_put(mddev); |
| 4465 | |
| 4466 | return 0; |
| 4467 | } |
| 4468 | |
| 4469 | static int md_media_changed(struct gendisk *disk) |
| 4470 | { |
| 4471 | mddev_t *mddev = disk->private_data; |
| 4472 | |
| 4473 | return mddev->changed; |
| 4474 | } |
| 4475 | |
| 4476 | static int md_revalidate(struct gendisk *disk) |
| 4477 | { |
| 4478 | mddev_t *mddev = disk->private_data; |
| 4479 | |
| 4480 | mddev->changed = 0; |
| 4481 | return 0; |
| 4482 | } |
| 4483 | static struct block_device_operations md_fops = |
| 4484 | { |
| 4485 | .owner = THIS_MODULE, |
| 4486 | .open = md_open, |
| 4487 | .release = md_release, |
| 4488 | .ioctl = md_ioctl, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 4489 | .getgeo = md_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | .media_changed = md_media_changed, |
| 4491 | .revalidate_disk= md_revalidate, |
| 4492 | }; |
| 4493 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 4494 | static int md_thread(void * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | { |
| 4496 | mdk_thread_t *thread = arg; |
| 4497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | /* |
| 4499 | * md_thread is a 'system-thread', it's priority should be very |
| 4500 | * high. We avoid resource deadlocks individually in each |
| 4501 | * raid personality. (RAID5 does preallocation) We also use RR and |
| 4502 | * the very same RT priority as kswapd, thus we will never get |
| 4503 | * into a priority inversion deadlock. |
| 4504 | * |
| 4505 | * we definitely have to have equal or higher priority than |
| 4506 | * bdflush, otherwise bdflush will deadlock if there are too |
| 4507 | * many dirty RAID5 blocks. |
| 4508 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 4510 | allow_signal(SIGKILL); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 4511 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | |
NeilBrown | 93588e2 | 2005-11-15 00:09:12 -0800 | [diff] [blame] | 4513 | /* We need to wait INTERRUPTIBLE so that |
| 4514 | * we don't add to the load-average. |
| 4515 | * That means we need to be sure no signals are |
| 4516 | * pending |
| 4517 | */ |
| 4518 | if (signal_pending(current)) |
| 4519 | flush_signals(current); |
| 4520 | |
| 4521 | wait_event_interruptible_timeout |
| 4522 | (thread->wqueue, |
| 4523 | test_bit(THREAD_WAKEUP, &thread->flags) |
| 4524 | || kthread_should_stop(), |
| 4525 | thread->timeout); |
Christoph Lameter | 3e1d1d2 | 2005-06-24 23:13:50 -0700 | [diff] [blame] | 4526 | try_to_freeze(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | |
| 4528 | clear_bit(THREAD_WAKEUP, &thread->flags); |
| 4529 | |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 4530 | thread->run(thread->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | } |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 4532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | return 0; |
| 4534 | } |
| 4535 | |
| 4536 | void md_wakeup_thread(mdk_thread_t *thread) |
| 4537 | { |
| 4538 | if (thread) { |
| 4539 | dprintk("md: waking up MD thread %s.\n", thread->tsk->comm); |
| 4540 | set_bit(THREAD_WAKEUP, &thread->flags); |
| 4541 | wake_up(&thread->wqueue); |
| 4542 | } |
| 4543 | } |
| 4544 | |
| 4545 | mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, |
| 4546 | const char *name) |
| 4547 | { |
| 4548 | mdk_thread_t *thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 4550 | thread = kzalloc(sizeof(mdk_thread_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | if (!thread) |
| 4552 | return NULL; |
| 4553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | init_waitqueue_head(&thread->wqueue); |
| 4555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | thread->run = run; |
| 4557 | thread->mddev = mddev; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4558 | thread->timeout = MAX_SCHEDULE_TIMEOUT; |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 4559 | thread->tsk = kthread_run(md_thread, thread, name, mdname(thread->mddev)); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 4560 | if (IS_ERR(thread->tsk)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | kfree(thread); |
| 4562 | return NULL; |
| 4563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | return thread; |
| 4565 | } |
| 4566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | void md_unregister_thread(mdk_thread_t *thread) |
| 4568 | { |
NeilBrown | d28446f | 2005-04-16 15:26:41 -0700 | [diff] [blame] | 4569 | dprintk("interrupting MD-thread pid %d\n", thread->tsk->pid); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 4570 | |
| 4571 | kthread_stop(thread->tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | kfree(thread); |
| 4573 | } |
| 4574 | |
| 4575 | void md_error(mddev_t *mddev, mdk_rdev_t *rdev) |
| 4576 | { |
| 4577 | if (!mddev) { |
| 4578 | MD_BUG(); |
| 4579 | return; |
| 4580 | } |
| 4581 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4582 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4583 | return; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4584 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | dprintk("md_error dev:%s, rdev:(%d:%d), (caller: %p,%p,%p,%p).\n", |
| 4586 | mdname(mddev), |
| 4587 | MAJOR(rdev->bdev->bd_dev), MINOR(rdev->bdev->bd_dev), |
| 4588 | __builtin_return_address(0),__builtin_return_address(1), |
| 4589 | __builtin_return_address(2),__builtin_return_address(3)); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4590 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | if (!mddev->pers->error_handler) |
| 4592 | return; |
| 4593 | mddev->pers->error_handler(mddev,rdev); |
| 4594 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 4595 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4596 | md_wakeup_thread(mddev->thread); |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 4597 | md_new_event_inintr(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
| 4600 | /* seq_file implementation /proc/mdstat */ |
| 4601 | |
| 4602 | static void status_unused(struct seq_file *seq) |
| 4603 | { |
| 4604 | int i = 0; |
| 4605 | mdk_rdev_t *rdev; |
| 4606 | struct list_head *tmp; |
| 4607 | |
| 4608 | seq_printf(seq, "unused devices: "); |
| 4609 | |
| 4610 | ITERATE_RDEV_PENDING(rdev,tmp) { |
| 4611 | char b[BDEVNAME_SIZE]; |
| 4612 | i++; |
| 4613 | seq_printf(seq, "%s ", |
| 4614 | bdevname(rdev->bdev,b)); |
| 4615 | } |
| 4616 | if (!i) |
| 4617 | seq_printf(seq, "<none>"); |
| 4618 | |
| 4619 | seq_printf(seq, "\n"); |
| 4620 | } |
| 4621 | |
| 4622 | |
| 4623 | static void status_resync(struct seq_file *seq, mddev_t * mddev) |
| 4624 | { |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 4625 | sector_t max_blocks, resync, res; |
| 4626 | unsigned long dt, db, rt; |
| 4627 | int scale; |
| 4628 | unsigned int per_milli; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | |
| 4630 | resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active))/2; |
| 4631 | |
| 4632 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 4633 | max_blocks = mddev->resync_max_sectors >> 1; |
| 4634 | else |
| 4635 | max_blocks = mddev->size; |
| 4636 | |
| 4637 | /* |
| 4638 | * Should not happen. |
| 4639 | */ |
| 4640 | if (!max_blocks) { |
| 4641 | MD_BUG(); |
| 4642 | return; |
| 4643 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 4644 | /* Pick 'scale' such that (resync>>scale)*1000 will fit |
| 4645 | * in a sector_t, and (max_blocks>>scale) will fit in a |
| 4646 | * u32, as those are the requirements for sector_div. |
| 4647 | * Thus 'scale' must be at least 10 |
| 4648 | */ |
| 4649 | scale = 10; |
| 4650 | if (sizeof(sector_t) > sizeof(unsigned long)) { |
| 4651 | while ( max_blocks/2 > (1ULL<<(scale+32))) |
| 4652 | scale++; |
| 4653 | } |
| 4654 | res = (resync>>scale)*1000; |
| 4655 | sector_div(res, (u32)((max_blocks>>scale)+1)); |
| 4656 | |
| 4657 | per_milli = res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | { |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 4659 | int i, x = per_milli/50, y = 20-x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | seq_printf(seq, "["); |
| 4661 | for (i = 0; i < x; i++) |
| 4662 | seq_printf(seq, "="); |
| 4663 | seq_printf(seq, ">"); |
| 4664 | for (i = 0; i < y; i++) |
| 4665 | seq_printf(seq, "."); |
| 4666 | seq_printf(seq, "] "); |
| 4667 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 4668 | seq_printf(seq, " %s =%3u.%u%% (%llu/%llu)", |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4669 | (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)? |
| 4670 | "reshape" : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ? |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4672 | "resync" : "recovery")), |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 4673 | per_milli/10, per_milli % 10, |
| 4674 | (unsigned long long) resync, |
| 4675 | (unsigned long long) max_blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | |
| 4677 | /* |
| 4678 | * We do not want to overflow, so the order of operands and |
| 4679 | * the * 100 / 100 trick are important. We do a +1 to be |
| 4680 | * safe against division by zero. We only estimate anyway. |
| 4681 | * |
| 4682 | * dt: time from mark until now |
| 4683 | * db: blocks written from mark until now |
| 4684 | * rt: remaining time |
| 4685 | */ |
| 4686 | dt = ((jiffies - mddev->resync_mark) / HZ); |
| 4687 | if (!dt) dt++; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 4688 | db = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active)) |
| 4689 | - mddev->resync_mark_cnt; |
| 4690 | rt = (dt * ((unsigned long)(max_blocks-resync) / (db/2/100+1)))/100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | |
| 4692 | seq_printf(seq, " finish=%lu.%lumin", rt / 60, (rt % 60)/6); |
| 4693 | |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 4694 | seq_printf(seq, " speed=%ldK/sec", db/2/dt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | static void *md_seq_start(struct seq_file *seq, loff_t *pos) |
| 4698 | { |
| 4699 | struct list_head *tmp; |
| 4700 | loff_t l = *pos; |
| 4701 | mddev_t *mddev; |
| 4702 | |
| 4703 | if (l >= 0x10000) |
| 4704 | return NULL; |
| 4705 | if (!l--) |
| 4706 | /* header */ |
| 4707 | return (void*)1; |
| 4708 | |
| 4709 | spin_lock(&all_mddevs_lock); |
| 4710 | list_for_each(tmp,&all_mddevs) |
| 4711 | if (!l--) { |
| 4712 | mddev = list_entry(tmp, mddev_t, all_mddevs); |
| 4713 | mddev_get(mddev); |
| 4714 | spin_unlock(&all_mddevs_lock); |
| 4715 | return mddev; |
| 4716 | } |
| 4717 | spin_unlock(&all_mddevs_lock); |
| 4718 | if (!l--) |
| 4719 | return (void*)2;/* tail */ |
| 4720 | return NULL; |
| 4721 | } |
| 4722 | |
| 4723 | static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 4724 | { |
| 4725 | struct list_head *tmp; |
| 4726 | mddev_t *next_mddev, *mddev = v; |
| 4727 | |
| 4728 | ++*pos; |
| 4729 | if (v == (void*)2) |
| 4730 | return NULL; |
| 4731 | |
| 4732 | spin_lock(&all_mddevs_lock); |
| 4733 | if (v == (void*)1) |
| 4734 | tmp = all_mddevs.next; |
| 4735 | else |
| 4736 | tmp = mddev->all_mddevs.next; |
| 4737 | if (tmp != &all_mddevs) |
| 4738 | next_mddev = mddev_get(list_entry(tmp,mddev_t,all_mddevs)); |
| 4739 | else { |
| 4740 | next_mddev = (void*)2; |
| 4741 | *pos = 0x10000; |
| 4742 | } |
| 4743 | spin_unlock(&all_mddevs_lock); |
| 4744 | |
| 4745 | if (v != (void*)1) |
| 4746 | mddev_put(mddev); |
| 4747 | return next_mddev; |
| 4748 | |
| 4749 | } |
| 4750 | |
| 4751 | static void md_seq_stop(struct seq_file *seq, void *v) |
| 4752 | { |
| 4753 | mddev_t *mddev = v; |
| 4754 | |
| 4755 | if (mddev && v != (void*)1 && v != (void*)2) |
| 4756 | mddev_put(mddev); |
| 4757 | } |
| 4758 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4759 | struct mdstat_info { |
| 4760 | int event; |
| 4761 | }; |
| 4762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | static int md_seq_show(struct seq_file *seq, void *v) |
| 4764 | { |
| 4765 | mddev_t *mddev = v; |
| 4766 | sector_t size; |
| 4767 | struct list_head *tmp2; |
| 4768 | mdk_rdev_t *rdev; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4769 | struct mdstat_info *mi = seq->private; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4770 | struct bitmap *bitmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | |
| 4772 | if (v == (void*)1) { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4773 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | seq_printf(seq, "Personalities : "); |
| 4775 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4776 | list_for_each_entry(pers, &pers_list, list) |
| 4777 | seq_printf(seq, "[%s] ", pers->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4778 | |
| 4779 | spin_unlock(&pers_lock); |
| 4780 | seq_printf(seq, "\n"); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4781 | mi->event = atomic_read(&md_event_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | return 0; |
| 4783 | } |
| 4784 | if (v == (void*)2) { |
| 4785 | status_unused(seq); |
| 4786 | return 0; |
| 4787 | } |
| 4788 | |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4789 | if (mddev_lock(mddev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | return -EINTR; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4791 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | if (mddev->pers || mddev->raid_disks || !list_empty(&mddev->disks)) { |
| 4793 | seq_printf(seq, "%s : %sactive", mdname(mddev), |
| 4794 | mddev->pers ? "" : "in"); |
| 4795 | if (mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4796 | if (mddev->ro==1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | seq_printf(seq, " (read-only)"); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4798 | if (mddev->ro==2) |
| 4799 | seq_printf(seq, "(auto-read-only)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | seq_printf(seq, " %s", mddev->pers->name); |
| 4801 | } |
| 4802 | |
| 4803 | size = 0; |
| 4804 | ITERATE_RDEV(mddev,rdev,tmp2) { |
| 4805 | char b[BDEVNAME_SIZE]; |
| 4806 | seq_printf(seq, " %s[%d]", |
| 4807 | bdevname(rdev->bdev,b), rdev->desc_nr); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4808 | if (test_bit(WriteMostly, &rdev->flags)) |
| 4809 | seq_printf(seq, "(W)"); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4810 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | seq_printf(seq, "(F)"); |
| 4812 | continue; |
NeilBrown | b325a32 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 4813 | } else if (rdev->raid_disk < 0) |
| 4814 | seq_printf(seq, "(S)"); /* spare */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4815 | size += rdev->size; |
| 4816 | } |
| 4817 | |
| 4818 | if (!list_empty(&mddev->disks)) { |
| 4819 | if (mddev->pers) |
| 4820 | seq_printf(seq, "\n %llu blocks", |
| 4821 | (unsigned long long)mddev->array_size); |
| 4822 | else |
| 4823 | seq_printf(seq, "\n %llu blocks", |
| 4824 | (unsigned long long)size); |
| 4825 | } |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 4826 | if (mddev->persistent) { |
| 4827 | if (mddev->major_version != 0 || |
| 4828 | mddev->minor_version != 90) { |
| 4829 | seq_printf(seq," super %d.%d", |
| 4830 | mddev->major_version, |
| 4831 | mddev->minor_version); |
| 4832 | } |
| 4833 | } else |
| 4834 | seq_printf(seq, " super non-persistent"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | |
| 4836 | if (mddev->pers) { |
| 4837 | mddev->pers->status (seq, mddev); |
| 4838 | seq_printf(seq, "\n "); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 4839 | if (mddev->pers->sync_request) { |
| 4840 | if (mddev->curr_resync > 2) { |
| 4841 | status_resync (seq, mddev); |
| 4842 | seq_printf(seq, "\n "); |
| 4843 | } else if (mddev->curr_resync == 1 || mddev->curr_resync == 2) |
| 4844 | seq_printf(seq, "\tresync=DELAYED\n "); |
| 4845 | else if (mddev->recovery_cp < MaxSector) |
| 4846 | seq_printf(seq, "\tresync=PENDING\n "); |
| 4847 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4848 | } else |
| 4849 | seq_printf(seq, "\n "); |
| 4850 | |
| 4851 | if ((bitmap = mddev->bitmap)) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4852 | unsigned long chunk_kb; |
| 4853 | unsigned long flags; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4854 | spin_lock_irqsave(&bitmap->lock, flags); |
| 4855 | chunk_kb = bitmap->chunksize >> 10; |
| 4856 | seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], " |
| 4857 | "%lu%s chunk", |
| 4858 | bitmap->pages - bitmap->missing_pages, |
| 4859 | bitmap->pages, |
| 4860 | (bitmap->pages - bitmap->missing_pages) |
| 4861 | << (PAGE_SHIFT - 10), |
| 4862 | chunk_kb ? chunk_kb : bitmap->chunksize, |
| 4863 | chunk_kb ? "KB" : "B"); |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 4864 | if (bitmap->file) { |
| 4865 | seq_printf(seq, ", file: "); |
| 4866 | seq_path(seq, bitmap->file->f_vfsmnt, |
| 4867 | bitmap->file->f_dentry," \t\n"); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4868 | } |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 4869 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4870 | seq_printf(seq, "\n"); |
| 4871 | spin_unlock_irqrestore(&bitmap->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | seq_printf(seq, "\n"); |
| 4875 | } |
| 4876 | mddev_unlock(mddev); |
| 4877 | |
| 4878 | return 0; |
| 4879 | } |
| 4880 | |
| 4881 | static struct seq_operations md_seq_ops = { |
| 4882 | .start = md_seq_start, |
| 4883 | .next = md_seq_next, |
| 4884 | .stop = md_seq_stop, |
| 4885 | .show = md_seq_show, |
| 4886 | }; |
| 4887 | |
| 4888 | static int md_seq_open(struct inode *inode, struct file *file) |
| 4889 | { |
| 4890 | int error; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4891 | struct mdstat_info *mi = kmalloc(sizeof(*mi), GFP_KERNEL); |
| 4892 | if (mi == NULL) |
| 4893 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | |
| 4895 | error = seq_open(file, &md_seq_ops); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4896 | if (error) |
| 4897 | kfree(mi); |
| 4898 | else { |
| 4899 | struct seq_file *p = file->private_data; |
| 4900 | p->private = mi; |
| 4901 | mi->event = atomic_read(&md_event_count); |
| 4902 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4903 | return error; |
| 4904 | } |
| 4905 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4906 | static int md_seq_release(struct inode *inode, struct file *file) |
| 4907 | { |
| 4908 | struct seq_file *m = file->private_data; |
| 4909 | struct mdstat_info *mi = m->private; |
| 4910 | m->private = NULL; |
| 4911 | kfree(mi); |
| 4912 | return seq_release(inode, file); |
| 4913 | } |
| 4914 | |
| 4915 | static unsigned int mdstat_poll(struct file *filp, poll_table *wait) |
| 4916 | { |
| 4917 | struct seq_file *m = filp->private_data; |
| 4918 | struct mdstat_info *mi = m->private; |
| 4919 | int mask; |
| 4920 | |
| 4921 | poll_wait(filp, &md_event_waiters, wait); |
| 4922 | |
| 4923 | /* always allow read */ |
| 4924 | mask = POLLIN | POLLRDNORM; |
| 4925 | |
| 4926 | if (mi->event != atomic_read(&md_event_count)) |
| 4927 | mask |= POLLERR | POLLPRI; |
| 4928 | return mask; |
| 4929 | } |
| 4930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4931 | static struct file_operations md_seq_fops = { |
| 4932 | .open = md_seq_open, |
| 4933 | .read = seq_read, |
| 4934 | .llseek = seq_lseek, |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4935 | .release = md_seq_release, |
| 4936 | .poll = mdstat_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | }; |
| 4938 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4939 | int register_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4942 | list_add_tail(&p->list, &pers_list); |
| 4943 | printk(KERN_INFO "md: %s personality registered for level %d\n", p->name, p->level); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | spin_unlock(&pers_lock); |
| 4945 | return 0; |
| 4946 | } |
| 4947 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4948 | int unregister_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4950 | printk(KERN_INFO "md: %s personality unregistered\n", p->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4952 | list_del_init(&p->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | spin_unlock(&pers_lock); |
| 4954 | return 0; |
| 4955 | } |
| 4956 | |
| 4957 | static int is_mddev_idle(mddev_t *mddev) |
| 4958 | { |
| 4959 | mdk_rdev_t * rdev; |
| 4960 | struct list_head *tmp; |
| 4961 | int idle; |
| 4962 | unsigned long curr_events; |
| 4963 | |
| 4964 | idle = 1; |
| 4965 | ITERATE_RDEV(mddev,rdev,tmp) { |
| 4966 | struct gendisk *disk = rdev->bdev->bd_contains->bd_disk; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 4967 | curr_events = disk_stat_read(disk, sectors[0]) + |
| 4968 | disk_stat_read(disk, sectors[1]) - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | atomic_read(&disk->sync_io); |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 4970 | /* The difference between curr_events and last_events |
| 4971 | * will be affected by any new non-sync IO (making |
| 4972 | * curr_events bigger) and any difference in the amount of |
| 4973 | * in-flight syncio (making current_events bigger or smaller) |
| 4974 | * The amount in-flight is currently limited to |
| 4975 | * 32*64K in raid1/10 and 256*PAGE_SIZE in raid5/6 |
| 4976 | * which is at most 4096 sectors. |
| 4977 | * These numbers are fairly fragile and should be made |
| 4978 | * more robust, probably by enforcing the |
| 4979 | * 'window size' that md_do_sync sort-of uses. |
| 4980 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | * Note: the following is an unsigned comparison. |
| 4982 | */ |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 4983 | if ((curr_events - rdev->last_events + 4096) > 8192) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4984 | rdev->last_events = curr_events; |
| 4985 | idle = 0; |
| 4986 | } |
| 4987 | } |
| 4988 | return idle; |
| 4989 | } |
| 4990 | |
| 4991 | void md_done_sync(mddev_t *mddev, int blocks, int ok) |
| 4992 | { |
| 4993 | /* another "blocks" (512byte) blocks have been synced */ |
| 4994 | atomic_sub(blocks, &mddev->recovery_active); |
| 4995 | wake_up(&mddev->recovery_wait); |
| 4996 | if (!ok) { |
| 4997 | set_bit(MD_RECOVERY_ERR, &mddev->recovery); |
| 4998 | md_wakeup_thread(mddev->thread); |
| 4999 | // stop recovery, signal do_sync .... |
| 5000 | } |
| 5001 | } |
| 5002 | |
| 5003 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5004 | /* md_write_start(mddev, bi) |
| 5005 | * If we need to update some array metadata (e.g. 'active' flag |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5006 | * in superblock) before writing, schedule a superblock update |
| 5007 | * and wait for it to complete. |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5008 | */ |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5009 | void md_write_start(mddev_t *mddev, struct bio *bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | { |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5011 | if (bio_data_dir(bi) != WRITE) |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5012 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5013 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5014 | BUG_ON(mddev->ro == 1); |
| 5015 | if (mddev->ro == 2) { |
| 5016 | /* need to switch to read/write */ |
| 5017 | mddev->ro = 0; |
| 5018 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5019 | md_wakeup_thread(mddev->thread); |
| 5020 | } |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5021 | atomic_inc(&mddev->writes_pending); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5022 | if (mddev->in_sync) { |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 5023 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5024 | if (mddev->in_sync) { |
| 5025 | mddev->in_sync = 0; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 5026 | mddev->sb_dirty = 3; |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5027 | md_wakeup_thread(mddev->thread); |
| 5028 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 5029 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5030 | } |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5031 | wait_event(mddev->sb_wait, mddev->sb_dirty==0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | void md_write_end(mddev_t *mddev) |
| 5035 | { |
| 5036 | if (atomic_dec_and_test(&mddev->writes_pending)) { |
| 5037 | if (mddev->safemode == 2) |
| 5038 | md_wakeup_thread(mddev->thread); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 5039 | else if (mddev->safemode_delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay); |
| 5041 | } |
| 5042 | } |
| 5043 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 5044 | static DECLARE_WAIT_QUEUE_HEAD(resync_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | |
| 5046 | #define SYNC_MARKS 10 |
| 5047 | #define SYNC_MARK_STEP (3*HZ) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5048 | void md_do_sync(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5049 | { |
| 5050 | mddev_t *mddev2; |
| 5051 | unsigned int currspeed = 0, |
| 5052 | window; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5053 | sector_t max_sectors,j, io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5054 | unsigned long mark[SYNC_MARKS]; |
| 5055 | sector_t mark_cnt[SYNC_MARKS]; |
| 5056 | int last_mark,m; |
| 5057 | struct list_head *tmp; |
| 5058 | sector_t last_check; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5059 | int skipped = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5060 | struct list_head *rtmp; |
| 5061 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | |
| 5063 | /* just incase thread restarts... */ |
| 5064 | if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) |
| 5065 | return; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5066 | if (mddev->ro) /* never try to sync a read-only array */ |
| 5067 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | |
| 5069 | /* we overload curr_resync somewhat here. |
| 5070 | * 0 == not engaged in resync at all |
| 5071 | * 2 == checking that there is no conflict with another sync |
| 5072 | * 1 == like 2, but have yielded to allow conflicting resync to |
| 5073 | * commense |
| 5074 | * other == active in resync - this many blocks |
| 5075 | * |
| 5076 | * Before starting a resync we must have set curr_resync to |
| 5077 | * 2, and then checked that every "conflicting" array has curr_resync |
| 5078 | * less than ours. When we find one that is the same or higher |
| 5079 | * we wait on resync_wait. To avoid deadlock, we reduce curr_resync |
| 5080 | * to 1 if we choose to yield (based arbitrarily on address of mddev structure). |
| 5081 | * This will mean we have to start checking from the beginning again. |
| 5082 | * |
| 5083 | */ |
| 5084 | |
| 5085 | do { |
| 5086 | mddev->curr_resync = 2; |
| 5087 | |
| 5088 | try_again: |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 5089 | if (kthread_should_stop()) { |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 5090 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5091 | goto skip; |
| 5092 | } |
| 5093 | ITERATE_MDDEV(mddev2,tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5094 | if (mddev2 == mddev) |
| 5095 | continue; |
| 5096 | if (mddev2->curr_resync && |
| 5097 | match_mddev_units(mddev,mddev2)) { |
| 5098 | DEFINE_WAIT(wq); |
| 5099 | if (mddev < mddev2 && mddev->curr_resync == 2) { |
| 5100 | /* arbitrarily yield */ |
| 5101 | mddev->curr_resync = 1; |
| 5102 | wake_up(&resync_wait); |
| 5103 | } |
| 5104 | if (mddev > mddev2 && mddev->curr_resync == 1) |
| 5105 | /* no need to wait here, we can wait the next |
| 5106 | * time 'round when curr_resync == 2 |
| 5107 | */ |
| 5108 | continue; |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 5109 | prepare_to_wait(&resync_wait, &wq, TASK_UNINTERRUPTIBLE); |
| 5110 | if (!kthread_should_stop() && |
NeilBrown | 8712e55 | 2005-10-26 01:58:58 -0700 | [diff] [blame] | 5111 | mddev2->curr_resync >= mddev->curr_resync) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5112 | printk(KERN_INFO "md: delaying resync of %s" |
| 5113 | " until %s has finished resync (they" |
| 5114 | " share one or more physical units)\n", |
| 5115 | mdname(mddev), mdname(mddev2)); |
| 5116 | mddev_put(mddev2); |
| 5117 | schedule(); |
| 5118 | finish_wait(&resync_wait, &wq); |
| 5119 | goto try_again; |
| 5120 | } |
| 5121 | finish_wait(&resync_wait, &wq); |
| 5122 | } |
| 5123 | } |
| 5124 | } while (mddev->curr_resync < 2); |
| 5125 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5126 | j = 0; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 5127 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | /* resync follows the size requested by the personality, |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5129 | * which defaults to physical size, but can be virtual size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | */ |
| 5131 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 5132 | mddev->resync_mismatches = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5133 | /* we don't use the checkpoint if there's a bitmap */ |
| 5134 | if (!mddev->bitmap && |
| 5135 | !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 5136 | j = mddev->recovery_cp; |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 5137 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 5138 | max_sectors = mddev->size << 1; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5139 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5140 | /* recovery follows the physical size of devices */ |
| 5141 | max_sectors = mddev->size << 1; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5142 | j = MaxSector; |
| 5143 | ITERATE_RDEV(mddev,rdev,rtmp) |
| 5144 | if (rdev->raid_disk >= 0 && |
| 5145 | !test_bit(Faulty, &rdev->flags) && |
| 5146 | !test_bit(In_sync, &rdev->flags) && |
| 5147 | rdev->recovery_offset < j) |
| 5148 | j = rdev->recovery_offset; |
| 5149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5150 | |
| 5151 | printk(KERN_INFO "md: syncing RAID array %s\n", mdname(mddev)); |
| 5152 | printk(KERN_INFO "md: minimum _guaranteed_ reconstruction speed:" |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 5153 | " %d KB/sec/disc.\n", speed_min(mddev)); |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 5154 | printk(KERN_INFO "md: using maximum available idle IO bandwidth " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | "(but not more than %d KB/sec) for reconstruction.\n", |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 5156 | speed_max(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | |
| 5158 | is_mddev_idle(mddev); /* this also initializes IO event counters */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5159 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5160 | io_sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | for (m = 0; m < SYNC_MARKS; m++) { |
| 5162 | mark[m] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5163 | mark_cnt[m] = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | } |
| 5165 | last_mark = 0; |
| 5166 | mddev->resync_mark = mark[last_mark]; |
| 5167 | mddev->resync_mark_cnt = mark_cnt[last_mark]; |
| 5168 | |
| 5169 | /* |
| 5170 | * Tune reconstruction: |
| 5171 | */ |
| 5172 | window = 32*(PAGE_SIZE/512); |
| 5173 | printk(KERN_INFO "md: using %dk window, over a total of %llu blocks.\n", |
| 5174 | window/2,(unsigned long long) max_sectors/2); |
| 5175 | |
| 5176 | atomic_set(&mddev->recovery_active, 0); |
| 5177 | init_waitqueue_head(&mddev->recovery_wait); |
| 5178 | last_check = 0; |
| 5179 | |
| 5180 | if (j>2) { |
| 5181 | printk(KERN_INFO |
| 5182 | "md: resuming recovery of %s from checkpoint.\n", |
| 5183 | mdname(mddev)); |
| 5184 | mddev->curr_resync = j; |
| 5185 | } |
| 5186 | |
| 5187 | while (j < max_sectors) { |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5188 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5190 | skipped = 0; |
| 5191 | sectors = mddev->pers->sync_request(mddev, j, &skipped, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 5192 | currspeed < speed_min(mddev)); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5193 | if (sectors == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5194 | set_bit(MD_RECOVERY_ERR, &mddev->recovery); |
| 5195 | goto out; |
| 5196 | } |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5197 | |
| 5198 | if (!skipped) { /* actual IO requested */ |
| 5199 | io_sectors += sectors; |
| 5200 | atomic_add(sectors, &mddev->recovery_active); |
| 5201 | } |
| 5202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | j += sectors; |
| 5204 | if (j>1) mddev->curr_resync = j; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 5205 | mddev->curr_mark_cnt = io_sectors; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5206 | if (last_check == 0) |
| 5207 | /* this is the earliers that rebuilt will be |
| 5208 | * visible in /proc/mdstat |
| 5209 | */ |
| 5210 | md_new_event(mddev); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5211 | |
| 5212 | if (last_check + window > io_sectors || j == max_sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | continue; |
| 5214 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5215 | last_check = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5216 | |
| 5217 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery) || |
| 5218 | test_bit(MD_RECOVERY_ERR, &mddev->recovery)) |
| 5219 | break; |
| 5220 | |
| 5221 | repeat: |
| 5222 | if (time_after_eq(jiffies, mark[last_mark] + SYNC_MARK_STEP )) { |
| 5223 | /* step marks */ |
| 5224 | int next = (last_mark+1) % SYNC_MARKS; |
| 5225 | |
| 5226 | mddev->resync_mark = mark[next]; |
| 5227 | mddev->resync_mark_cnt = mark_cnt[next]; |
| 5228 | mark[next] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5229 | mark_cnt[next] = io_sectors - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | last_mark = next; |
| 5231 | } |
| 5232 | |
| 5233 | |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 5234 | if (kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5235 | /* |
| 5236 | * got a signal, exit. |
| 5237 | */ |
| 5238 | printk(KERN_INFO |
| 5239 | "md: md_do_sync() got signal ... exiting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 5241 | goto out; |
| 5242 | } |
| 5243 | |
| 5244 | /* |
| 5245 | * this loop exits only if either when we are slower than |
| 5246 | * the 'hard' speed limit, or the system was IO-idle for |
| 5247 | * a jiffy. |
| 5248 | * the system might be non-idle CPU-wise, but we only care |
| 5249 | * about not overloading the IO subsystem. (things like an |
| 5250 | * e2fsck being done on the RAID array should execute fast) |
| 5251 | */ |
| 5252 | mddev->queue->unplug_fn(mddev->queue); |
| 5253 | cond_resched(); |
| 5254 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5255 | currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2 |
| 5256 | /((jiffies-mddev->resync_mark)/HZ +1) +1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5257 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 5258 | if (currspeed > speed_min(mddev)) { |
| 5259 | if ((currspeed > speed_max(mddev)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5260 | !is_mddev_idle(mddev)) { |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 5261 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | goto repeat; |
| 5263 | } |
| 5264 | } |
| 5265 | } |
| 5266 | printk(KERN_INFO "md: %s: sync done.\n",mdname(mddev)); |
| 5267 | /* |
| 5268 | * this also signals 'finished resyncing' to md_stop |
| 5269 | */ |
| 5270 | out: |
| 5271 | mddev->queue->unplug_fn(mddev->queue); |
| 5272 | |
| 5273 | wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); |
| 5274 | |
| 5275 | /* tell personality that we are finished */ |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5276 | mddev->pers->sync_request(mddev, max_sectors, &skipped, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | |
| 5278 | if (!test_bit(MD_RECOVERY_ERR, &mddev->recovery) && |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 5279 | test_bit(MD_RECOVERY_SYNC, &mddev->recovery) && |
| 5280 | !test_bit(MD_RECOVERY_CHECK, &mddev->recovery) && |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5281 | mddev->curr_resync > 2) { |
| 5282 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 5283 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 5284 | if (mddev->curr_resync >= mddev->recovery_cp) { |
| 5285 | printk(KERN_INFO |
| 5286 | "md: checkpointing recovery of %s.\n", |
| 5287 | mdname(mddev)); |
| 5288 | mddev->recovery_cp = mddev->curr_resync; |
| 5289 | } |
| 5290 | } else |
| 5291 | mddev->recovery_cp = MaxSector; |
| 5292 | } else { |
| 5293 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 5294 | mddev->curr_resync = MaxSector; |
| 5295 | ITERATE_RDEV(mddev,rdev,rtmp) |
| 5296 | if (rdev->raid_disk >= 0 && |
| 5297 | !test_bit(Faulty, &rdev->flags) && |
| 5298 | !test_bit(In_sync, &rdev->flags) && |
| 5299 | rdev->recovery_offset < mddev->curr_resync) |
| 5300 | rdev->recovery_offset = mddev->curr_resync; |
| 5301 | mddev->sb_dirty = 1; |
| 5302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5303 | } |
| 5304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | skip: |
| 5306 | mddev->curr_resync = 0; |
| 5307 | wake_up(&resync_wait); |
| 5308 | set_bit(MD_RECOVERY_DONE, &mddev->recovery); |
| 5309 | md_wakeup_thread(mddev->thread); |
| 5310 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5311 | EXPORT_SYMBOL_GPL(md_do_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5312 | |
| 5313 | |
| 5314 | /* |
| 5315 | * This routine is regularly called by all per-raid-array threads to |
| 5316 | * deal with generic issues like resync and super-block update. |
| 5317 | * Raid personalities that don't have a thread (linear/raid0) do not |
| 5318 | * need this as they never do any recovery or update the superblock. |
| 5319 | * |
| 5320 | * It does not do any resync itself, but rather "forks" off other threads |
| 5321 | * to do that as needed. |
| 5322 | * When it is determined that resync is needed, we set MD_RECOVERY_RUNNING in |
| 5323 | * "->recovery" and create a thread at ->sync_thread. |
| 5324 | * When the thread finishes it sets MD_RECOVERY_DONE (and might set MD_RECOVERY_ERR) |
| 5325 | * and wakeups up this thread which will reap the thread and finish up. |
| 5326 | * This thread also removes any faulty devices (with nr_pending == 0). |
| 5327 | * |
| 5328 | * The overall approach is: |
| 5329 | * 1/ if the superblock needs updating, update it. |
| 5330 | * 2/ If a recovery thread is running, don't do anything else. |
| 5331 | * 3/ If recovery has finished, clean up, possibly marking spares active. |
| 5332 | * 4/ If there are any faulty devices, remove them. |
| 5333 | * 5/ If array is degraded, try to add spares devices |
| 5334 | * 6/ If array has spares or is not in-sync, start a resync thread. |
| 5335 | */ |
| 5336 | void md_check_recovery(mddev_t *mddev) |
| 5337 | { |
| 5338 | mdk_rdev_t *rdev; |
| 5339 | struct list_head *rtmp; |
| 5340 | |
| 5341 | |
NeilBrown | 5f40402 | 2005-06-21 17:17:16 -0700 | [diff] [blame] | 5342 | if (mddev->bitmap) |
| 5343 | bitmap_daemon_work(mddev->bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | |
| 5345 | if (mddev->ro) |
| 5346 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 5347 | |
| 5348 | if (signal_pending(current)) { |
| 5349 | if (mddev->pers->sync_request) { |
| 5350 | printk(KERN_INFO "md: %s in immediate safe mode\n", |
| 5351 | mdname(mddev)); |
| 5352 | mddev->safemode = 2; |
| 5353 | } |
| 5354 | flush_signals(current); |
| 5355 | } |
| 5356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | if ( ! ( |
| 5358 | mddev->sb_dirty || |
| 5359 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 5360 | test_bit(MD_RECOVERY_DONE, &mddev->recovery) || |
| 5361 | (mddev->safemode == 1) || |
| 5362 | (mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending) |
| 5363 | && !mddev->in_sync && mddev->recovery_cp == MaxSector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5364 | )) |
| 5365 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 5366 | |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 5367 | if (mddev_trylock(mddev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5368 | int spares =0; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 5369 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 5370 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 5371 | if (mddev->safemode && !atomic_read(&mddev->writes_pending) && |
| 5372 | !mddev->in_sync && mddev->recovery_cp == MaxSector) { |
| 5373 | mddev->in_sync = 1; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 5374 | mddev->sb_dirty = 3; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 5375 | } |
| 5376 | if (mddev->safemode == 1) |
| 5377 | mddev->safemode = 0; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 5378 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 5379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5380 | if (mddev->sb_dirty) |
| 5381 | md_update_sb(mddev); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5382 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5384 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && |
| 5385 | !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) { |
| 5386 | /* resync/recovery still happening */ |
| 5387 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5388 | goto unlock; |
| 5389 | } |
| 5390 | if (mddev->sync_thread) { |
| 5391 | /* resync has finished, collect result */ |
| 5392 | md_unregister_thread(mddev->sync_thread); |
| 5393 | mddev->sync_thread = NULL; |
| 5394 | if (!test_bit(MD_RECOVERY_ERR, &mddev->recovery) && |
| 5395 | !test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 5396 | /* success...*/ |
| 5397 | /* activate any spares */ |
| 5398 | mddev->pers->spare_active(mddev); |
| 5399 | } |
| 5400 | md_update_sb(mddev); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 5401 | |
| 5402 | /* if array is no-longer degraded, then any saved_raid_disk |
| 5403 | * information must be scrapped |
| 5404 | */ |
| 5405 | if (!mddev->degraded) |
| 5406 | ITERATE_RDEV(mddev,rdev,rtmp) |
| 5407 | rdev->saved_raid_disk = -1; |
| 5408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5409 | mddev->recovery = 0; |
| 5410 | /* flag recovery needed just to double check */ |
| 5411 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5412 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5413 | goto unlock; |
| 5414 | } |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 5415 | /* Clear some bits that don't mean anything, but |
| 5416 | * might be left set |
| 5417 | */ |
| 5418 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5419 | clear_bit(MD_RECOVERY_ERR, &mddev->recovery); |
| 5420 | clear_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 5421 | clear_bit(MD_RECOVERY_DONE, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5422 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5423 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 5424 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5425 | /* no recovery is running. |
| 5426 | * remove any failed drives, then |
| 5427 | * add spares if possible. |
| 5428 | * Spare are also removed and re-added, to allow |
| 5429 | * the personality to fail the re-add. |
| 5430 | */ |
| 5431 | ITERATE_RDEV(mddev,rdev,rtmp) |
| 5432 | if (rdev->raid_disk >= 0 && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5433 | (test_bit(Faulty, &rdev->flags) || ! test_bit(In_sync, &rdev->flags)) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5434 | atomic_read(&rdev->nr_pending)==0) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 5435 | if (mddev->pers->hot_remove_disk(mddev, rdev->raid_disk)==0) { |
| 5436 | char nm[20]; |
| 5437 | sprintf(nm,"rd%d", rdev->raid_disk); |
| 5438 | sysfs_remove_link(&mddev->kobj, nm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5439 | rdev->raid_disk = -1; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 5440 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5441 | } |
| 5442 | |
| 5443 | if (mddev->degraded) { |
| 5444 | ITERATE_RDEV(mddev,rdev,rtmp) |
| 5445 | if (rdev->raid_disk < 0 |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5446 | && !test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5447 | rdev->recovery_offset = 0; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 5448 | if (mddev->pers->hot_add_disk(mddev,rdev)) { |
| 5449 | char nm[20]; |
| 5450 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 5451 | sysfs_create_link(&mddev->kobj, &rdev->kobj, nm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | spares++; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5453 | md_new_event(mddev); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 5454 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5455 | break; |
| 5456 | } |
| 5457 | } |
| 5458 | |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 5459 | if (spares) { |
| 5460 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5461 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5462 | } else if (mddev->recovery_cp < MaxSector) { |
| 5463 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5464 | } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 5465 | /* nothing to be done ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5466 | goto unlock; |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 5467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5468 | if (mddev->pers->sync_request) { |
| 5469 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 5470 | if (spares && mddev->bitmap && ! mddev->bitmap->file) { |
| 5471 | /* We are adding a device or devices to an array |
| 5472 | * which has the bitmap stored on all devices. |
| 5473 | * So make sure all bitmap pages get written |
| 5474 | */ |
| 5475 | bitmap_write_all(mddev->bitmap); |
| 5476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | mddev->sync_thread = md_register_thread(md_do_sync, |
| 5478 | mddev, |
| 5479 | "%s_resync"); |
| 5480 | if (!mddev->sync_thread) { |
| 5481 | printk(KERN_ERR "%s: could not start resync" |
| 5482 | " thread...\n", |
| 5483 | mdname(mddev)); |
| 5484 | /* leave the spares where they are, it shouldn't hurt */ |
| 5485 | mddev->recovery = 0; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5486 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | md_wakeup_thread(mddev->sync_thread); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5488 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | } |
| 5490 | unlock: |
| 5491 | mddev_unlock(mddev); |
| 5492 | } |
| 5493 | } |
| 5494 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 5495 | static int md_notify_reboot(struct notifier_block *this, |
| 5496 | unsigned long code, void *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | { |
| 5498 | struct list_head *tmp; |
| 5499 | mddev_t *mddev; |
| 5500 | |
| 5501 | if ((code == SYS_DOWN) || (code == SYS_HALT) || (code == SYS_POWER_OFF)) { |
| 5502 | |
| 5503 | printk(KERN_INFO "md: stopping all md devices.\n"); |
| 5504 | |
| 5505 | ITERATE_MDDEV(mddev,tmp) |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 5506 | if (mddev_trylock(mddev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5507 | do_md_stop (mddev, 1); |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 5508 | mddev_unlock(mddev); |
| 5509 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | /* |
| 5511 | * certain more exotic SCSI devices are known to be |
| 5512 | * volatile wrt too early system reboots. While the |
| 5513 | * right place to handle this issue is the given |
| 5514 | * driver, we do want to have a safe RAID driver ... |
| 5515 | */ |
| 5516 | mdelay(1000*1); |
| 5517 | } |
| 5518 | return NOTIFY_DONE; |
| 5519 | } |
| 5520 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 5521 | static struct notifier_block md_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | .notifier_call = md_notify_reboot, |
| 5523 | .next = NULL, |
| 5524 | .priority = INT_MAX, /* before any real devices */ |
| 5525 | }; |
| 5526 | |
| 5527 | static void md_geninit(void) |
| 5528 | { |
| 5529 | struct proc_dir_entry *p; |
| 5530 | |
| 5531 | dprintk("md: sizeof(mdp_super_t) = %d\n", (int)sizeof(mdp_super_t)); |
| 5532 | |
| 5533 | p = create_proc_entry("mdstat", S_IRUGO, NULL); |
| 5534 | if (p) |
| 5535 | p->proc_fops = &md_seq_fops; |
| 5536 | } |
| 5537 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 5538 | static int __init md_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | printk(KERN_INFO "md: md driver %d.%d.%d MAX_MD_DEVS=%d," |
| 5541 | " MD_SB_DISKS=%d\n", |
| 5542 | MD_MAJOR_VERSION, MD_MINOR_VERSION, |
| 5543 | MD_PATCHLEVEL_VERSION, MAX_MD_DEVS, MD_SB_DISKS); |
NeilBrown | bd926c6 | 2005-11-08 21:39:32 -0800 | [diff] [blame] | 5544 | printk(KERN_INFO "md: bitmap version %d.%d\n", BITMAP_MAJOR_HI, |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5545 | BITMAP_MINOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5546 | |
| 5547 | if (register_blkdev(MAJOR_NR, "md")) |
| 5548 | return -1; |
| 5549 | if ((mdp_major=register_blkdev(0, "mdp"))<=0) { |
| 5550 | unregister_blkdev(MAJOR_NR, "md"); |
| 5551 | return -1; |
| 5552 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | blk_register_region(MKDEV(MAJOR_NR, 0), MAX_MD_DEVS, THIS_MODULE, |
| 5554 | md_probe, NULL, NULL); |
| 5555 | blk_register_region(MKDEV(mdp_major, 0), MAX_MD_DEVS<<MdpMinorShift, THIS_MODULE, |
| 5556 | md_probe, NULL, NULL); |
| 5557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5558 | register_reboot_notifier(&md_notifier); |
| 5559 | raid_table_header = register_sysctl_table(raid_root_table, 1); |
| 5560 | |
| 5561 | md_geninit(); |
| 5562 | return (0); |
| 5563 | } |
| 5564 | |
| 5565 | |
| 5566 | #ifndef MODULE |
| 5567 | |
| 5568 | /* |
| 5569 | * Searches all registered partitions for autorun RAID arrays |
| 5570 | * at boot time. |
| 5571 | */ |
| 5572 | static dev_t detected_devices[128]; |
| 5573 | static int dev_cnt; |
| 5574 | |
| 5575 | void md_autodetect_dev(dev_t dev) |
| 5576 | { |
| 5577 | if (dev_cnt >= 0 && dev_cnt < 127) |
| 5578 | detected_devices[dev_cnt++] = dev; |
| 5579 | } |
| 5580 | |
| 5581 | |
| 5582 | static void autostart_arrays(int part) |
| 5583 | { |
| 5584 | mdk_rdev_t *rdev; |
| 5585 | int i; |
| 5586 | |
| 5587 | printk(KERN_INFO "md: Autodetecting RAID arrays.\n"); |
| 5588 | |
| 5589 | for (i = 0; i < dev_cnt; i++) { |
| 5590 | dev_t dev = detected_devices[i]; |
| 5591 | |
| 5592 | rdev = md_import_device(dev,0, 0); |
| 5593 | if (IS_ERR(rdev)) |
| 5594 | continue; |
| 5595 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5596 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | MD_BUG(); |
| 5598 | continue; |
| 5599 | } |
| 5600 | list_add(&rdev->same_set, &pending_raid_disks); |
| 5601 | } |
| 5602 | dev_cnt = 0; |
| 5603 | |
| 5604 | autorun_devices(part); |
| 5605 | } |
| 5606 | |
| 5607 | #endif |
| 5608 | |
| 5609 | static __exit void md_exit(void) |
| 5610 | { |
| 5611 | mddev_t *mddev; |
| 5612 | struct list_head *tmp; |
Greg Kroah-Hartman | 8ab5e4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 5613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | blk_unregister_region(MKDEV(MAJOR_NR,0), MAX_MD_DEVS); |
| 5615 | blk_unregister_region(MKDEV(mdp_major,0), MAX_MD_DEVS << MdpMinorShift); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | |
| 5617 | unregister_blkdev(MAJOR_NR,"md"); |
| 5618 | unregister_blkdev(mdp_major, "mdp"); |
| 5619 | unregister_reboot_notifier(&md_notifier); |
| 5620 | unregister_sysctl_table(raid_table_header); |
| 5621 | remove_proc_entry("mdstat", NULL); |
| 5622 | ITERATE_MDDEV(mddev,tmp) { |
| 5623 | struct gendisk *disk = mddev->gendisk; |
| 5624 | if (!disk) |
| 5625 | continue; |
| 5626 | export_array(mddev); |
| 5627 | del_gendisk(disk); |
| 5628 | put_disk(disk); |
| 5629 | mddev->gendisk = NULL; |
| 5630 | mddev_put(mddev); |
| 5631 | } |
| 5632 | } |
| 5633 | |
| 5634 | module_init(md_init) |
| 5635 | module_exit(md_exit) |
| 5636 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5637 | static int get_ro(char *buffer, struct kernel_param *kp) |
| 5638 | { |
| 5639 | return sprintf(buffer, "%d", start_readonly); |
| 5640 | } |
| 5641 | static int set_ro(const char *val, struct kernel_param *kp) |
| 5642 | { |
| 5643 | char *e; |
| 5644 | int num = simple_strtoul(val, &e, 10); |
| 5645 | if (*val && (*e == '\0' || *e == '\n')) { |
| 5646 | start_readonly = num; |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 5647 | return 0; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5648 | } |
| 5649 | return -EINVAL; |
| 5650 | } |
| 5651 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame^] | 5652 | module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); |
| 5653 | module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR); |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5654 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | EXPORT_SYMBOL(register_md_personality); |
| 5657 | EXPORT_SYMBOL(unregister_md_personality); |
| 5658 | EXPORT_SYMBOL(md_error); |
| 5659 | EXPORT_SYMBOL(md_done_sync); |
| 5660 | EXPORT_SYMBOL(md_write_start); |
| 5661 | EXPORT_SYMBOL(md_write_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5662 | EXPORT_SYMBOL(md_register_thread); |
| 5663 | EXPORT_SYMBOL(md_unregister_thread); |
| 5664 | EXPORT_SYMBOL(md_wakeup_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5665 | EXPORT_SYMBOL(md_check_recovery); |
| 5666 | MODULE_LICENSE("GPL"); |
NeilBrown | aa1595e | 2005-08-04 12:53:32 -0700 | [diff] [blame] | 5667 | MODULE_ALIAS("md"); |
NeilBrown | 7200865 | 2005-08-26 18:34:15 -0700 | [diff] [blame] | 5668 | MODULE_ALIAS_BLOCKDEV_MAJOR(MD_MAJOR); |