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