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 | |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 77 | static DECLARE_WAIT_QUEUE_HEAD(resync_wait); |
| 78 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 79 | #define MD_BUG(x...) { printk("md: bug in file %s, line %d\n", __FILE__, __LINE__); md_print_devices(); } |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | /* |
| 82 | * Current RAID-1,4,5 parallel reconstruction 'guaranteed speed limit' |
| 83 | * is 1000 KB/sec, so the extra system load does not show up that much. |
| 84 | * Increase it if you want to have more _guaranteed_ speed. Note that |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 85 | * the RAID driver will use the maximum available bandwidth if the IO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * subsystem is idle. There is also an 'absolute maximum' reconstruction |
| 87 | * speed limit - in case reconstruction slows down your system despite |
| 88 | * idle IO detection. |
| 89 | * |
| 90 | * 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] | 91 | * or /sys/block/mdX/md/sync_speed_{min,max} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | */ |
| 93 | |
| 94 | static int sysctl_speed_limit_min = 1000; |
| 95 | static int sysctl_speed_limit_max = 200000; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 96 | static inline int speed_min(mddev_t *mddev) |
| 97 | { |
| 98 | return mddev->sync_speed_min ? |
| 99 | mddev->sync_speed_min : sysctl_speed_limit_min; |
| 100 | } |
| 101 | |
| 102 | static inline int speed_max(mddev_t *mddev) |
| 103 | { |
| 104 | return mddev->sync_speed_max ? |
| 105 | mddev->sync_speed_max : sysctl_speed_limit_max; |
| 106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | static struct ctl_table_header *raid_table_header; |
| 109 | |
| 110 | static ctl_table raid_table[] = { |
| 111 | { |
| 112 | .ctl_name = DEV_RAID_SPEED_LIMIT_MIN, |
| 113 | .procname = "speed_limit_min", |
| 114 | .data = &sysctl_speed_limit_min, |
| 115 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 116 | .mode = S_IRUGO|S_IWUSR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .proc_handler = &proc_dointvec, |
| 118 | }, |
| 119 | { |
| 120 | .ctl_name = DEV_RAID_SPEED_LIMIT_MAX, |
| 121 | .procname = "speed_limit_max", |
| 122 | .data = &sysctl_speed_limit_max, |
| 123 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 124 | .mode = S_IRUGO|S_IWUSR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | .proc_handler = &proc_dointvec, |
| 126 | }, |
| 127 | { .ctl_name = 0 } |
| 128 | }; |
| 129 | |
| 130 | static ctl_table raid_dir_table[] = { |
| 131 | { |
| 132 | .ctl_name = DEV_RAID, |
| 133 | .procname = "raid", |
| 134 | .maxlen = 0, |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 135 | .mode = S_IRUGO|S_IXUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | .child = raid_table, |
| 137 | }, |
| 138 | { .ctl_name = 0 } |
| 139 | }; |
| 140 | |
| 141 | static ctl_table raid_root_table[] = { |
| 142 | { |
| 143 | .ctl_name = CTL_DEV, |
| 144 | .procname = "dev", |
| 145 | .maxlen = 0, |
| 146 | .mode = 0555, |
| 147 | .child = raid_dir_table, |
| 148 | }, |
| 149 | { .ctl_name = 0 } |
| 150 | }; |
| 151 | |
| 152 | static struct block_device_operations md_fops; |
| 153 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 154 | static int start_readonly; |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 157 | * We have a system wide 'event count' that is incremented |
| 158 | * on any 'interesting' event, and readers of /proc/mdstat |
| 159 | * can use 'poll' or 'select' to find out when the event |
| 160 | * count increases. |
| 161 | * |
| 162 | * Events are: |
| 163 | * start array, stop array, error, add device, remove device, |
| 164 | * start build, activate spare |
| 165 | */ |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 166 | static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 167 | static atomic_t md_event_count; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 168 | void md_new_event(mddev_t *mddev) |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 169 | { |
| 170 | atomic_inc(&md_event_count); |
| 171 | wake_up(&md_event_waiters); |
| 172 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 173 | EXPORT_SYMBOL_GPL(md_new_event); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 174 | |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 175 | /* Alternate version that can be called from interrupts |
| 176 | * when calling sysfs_notify isn't needed. |
| 177 | */ |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 178 | static void md_new_event_inintr(mddev_t *mddev) |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 179 | { |
| 180 | atomic_inc(&md_event_count); |
| 181 | wake_up(&md_event_waiters); |
| 182 | } |
| 183 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 184 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | * Enables to iterate over all existing md arrays |
| 186 | * all_mddevs_lock protects this list. |
| 187 | */ |
| 188 | static LIST_HEAD(all_mddevs); |
| 189 | static DEFINE_SPINLOCK(all_mddevs_lock); |
| 190 | |
| 191 | |
| 192 | /* |
| 193 | * iterates through all used mddevs in the system. |
| 194 | * We take care to grab the all_mddevs_lock whenever navigating |
| 195 | * the list, and to always hold a refcount when unlocked. |
| 196 | * Any code which breaks out of this loop while own |
| 197 | * a reference to the current mddev and must mddev_put it. |
| 198 | */ |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 199 | #define for_each_mddev(mddev,tmp) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | \ |
| 201 | for (({ spin_lock(&all_mddevs_lock); \ |
| 202 | tmp = all_mddevs.next; \ |
| 203 | mddev = NULL;}); \ |
| 204 | ({ if (tmp != &all_mddevs) \ |
| 205 | mddev_get(list_entry(tmp, mddev_t, all_mddevs));\ |
| 206 | spin_unlock(&all_mddevs_lock); \ |
| 207 | if (mddev) mddev_put(mddev); \ |
| 208 | mddev = list_entry(tmp, mddev_t, all_mddevs); \ |
| 209 | tmp != &all_mddevs;}); \ |
| 210 | ({ spin_lock(&all_mddevs_lock); \ |
| 211 | tmp = tmp->next;}) \ |
| 212 | ) |
| 213 | |
| 214 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 215 | static int md_fail_request (struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 217 | bio_io_error(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static inline mddev_t *mddev_get(mddev_t *mddev) |
| 222 | { |
| 223 | atomic_inc(&mddev->active); |
| 224 | return mddev; |
| 225 | } |
| 226 | |
| 227 | static void mddev_put(mddev_t *mddev) |
| 228 | { |
| 229 | if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock)) |
| 230 | return; |
| 231 | if (!mddev->raid_disks && list_empty(&mddev->disks)) { |
| 232 | list_del(&mddev->all_mddevs); |
NeilBrown | 926ce2d | 2006-03-31 02:32:02 -0800 | [diff] [blame] | 233 | spin_unlock(&all_mddevs_lock); |
Al Viro | 1312f40 | 2006-03-12 11:02:03 -0500 | [diff] [blame] | 234 | blk_cleanup_queue(mddev->queue); |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 235 | kobject_put(&mddev->kobj); |
NeilBrown | 926ce2d | 2006-03-31 02:32:02 -0800 | [diff] [blame] | 236 | } else |
| 237 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static mddev_t * mddev_find(dev_t unit) |
| 241 | { |
| 242 | mddev_t *mddev, *new = NULL; |
| 243 | |
| 244 | retry: |
| 245 | spin_lock(&all_mddevs_lock); |
| 246 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 247 | if (mddev->unit == unit) { |
| 248 | mddev_get(mddev); |
| 249 | spin_unlock(&all_mddevs_lock); |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 250 | kfree(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | return mddev; |
| 252 | } |
| 253 | |
| 254 | if (new) { |
| 255 | list_add(&new->all_mddevs, &all_mddevs); |
| 256 | spin_unlock(&all_mddevs_lock); |
| 257 | return new; |
| 258 | } |
| 259 | spin_unlock(&all_mddevs_lock); |
| 260 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 261 | new = kzalloc(sizeof(*new), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | if (!new) |
| 263 | return NULL; |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | new->unit = unit; |
| 266 | if (MAJOR(unit) == MD_MAJOR) |
| 267 | new->md_minor = MINOR(unit); |
| 268 | else |
| 269 | new->md_minor = MINOR(unit) >> MdpMinorShift; |
| 270 | |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 271 | mutex_init(&new->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | INIT_LIST_HEAD(&new->disks); |
| 273 | INIT_LIST_HEAD(&new->all_mddevs); |
| 274 | init_timer(&new->safemode_timer); |
| 275 | atomic_set(&new->active, 1); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 276 | spin_lock_init(&new->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 277 | init_waitqueue_head(&new->sb_wait); |
Dan Williams | a6d8113 | 2008-06-05 22:45:53 -0700 | [diff] [blame] | 278 | init_waitqueue_head(&new->recovery_wait); |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 279 | new->reshape_position = MaxSector; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 280 | new->resync_min = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 281 | new->resync_max = MaxSector; |
NeilBrown | d897dbf | 2008-04-30 00:52:29 -0700 | [diff] [blame] | 282 | new->level = LEVEL_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | new->queue = blk_alloc_queue(GFP_KERNEL); |
| 285 | if (!new->queue) { |
| 286 | kfree(new); |
| 287 | return NULL; |
| 288 | } |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 289 | /* Can be unlocked because the queue is new: no concurrency */ |
| 290 | queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, new->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | blk_queue_make_request(new->queue, md_fail_request); |
| 293 | |
| 294 | goto retry; |
| 295 | } |
| 296 | |
| 297 | static inline int mddev_lock(mddev_t * mddev) |
| 298 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 299 | return mutex_lock_interruptible(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | static inline int mddev_trylock(mddev_t * mddev) |
| 303 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 304 | return mutex_trylock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static inline void mddev_unlock(mddev_t * mddev) |
| 308 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 309 | mutex_unlock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 311 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 314 | static mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
| 316 | mdk_rdev_t * rdev; |
| 317 | struct list_head *tmp; |
| 318 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 319 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | if (rdev->desc_nr == nr) |
| 321 | return rdev; |
| 322 | } |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | static mdk_rdev_t * find_rdev(mddev_t * mddev, dev_t dev) |
| 327 | { |
| 328 | struct list_head *tmp; |
| 329 | mdk_rdev_t *rdev; |
| 330 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 331 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if (rdev->bdev->bd_dev == dev) |
| 333 | return rdev; |
| 334 | } |
| 335 | return NULL; |
| 336 | } |
| 337 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 338 | static struct mdk_personality *find_pers(int level, char *clevel) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 339 | { |
| 340 | struct mdk_personality *pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 341 | list_for_each_entry(pers, &pers_list, list) { |
| 342 | if (level != LEVEL_NONE && pers->level == level) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 343 | return pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 344 | if (strcmp(pers->name, clevel)==0) |
| 345 | return pers; |
| 346 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 347 | return NULL; |
| 348 | } |
| 349 | |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 350 | static inline sector_t calc_dev_sboffset(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
| 352 | sector_t size = bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 353 | return MD_NEW_SIZE_BLOCKS(size); |
| 354 | } |
| 355 | |
Andre Noll | e7debaa | 2008-07-11 22:02:23 +1000 | [diff] [blame^] | 356 | static sector_t calc_num_sectors(mdk_rdev_t *rdev, unsigned chunk_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Andre Noll | e7debaa | 2008-07-11 22:02:23 +1000 | [diff] [blame^] | 358 | sector_t num_sectors = rdev->sb_offset * 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | if (chunk_size) |
Andre Noll | e7debaa | 2008-07-11 22:02:23 +1000 | [diff] [blame^] | 361 | num_sectors &= ~((sector_t)chunk_size/512 - 1); |
| 362 | return num_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static int alloc_disk_sb(mdk_rdev_t * rdev) |
| 366 | { |
| 367 | if (rdev->sb_page) |
| 368 | MD_BUG(); |
| 369 | |
| 370 | rdev->sb_page = alloc_page(GFP_KERNEL); |
| 371 | if (!rdev->sb_page) { |
| 372 | printk(KERN_ALERT "md: out of memory.\n"); |
Andre Noll | ebc2433 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 373 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static void free_disk_sb(mdk_rdev_t * rdev) |
| 380 | { |
| 381 | if (rdev->sb_page) { |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 382 | put_page(rdev->sb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | rdev->sb_loaded = 0; |
| 384 | rdev->sb_page = NULL; |
| 385 | rdev->sb_offset = 0; |
| 386 | rdev->size = 0; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 391 | static void super_written(struct bio *bio, int error) |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 392 | { |
| 393 | mdk_rdev_t *rdev = bio->bi_private; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 394 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 395 | |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 396 | if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) { |
| 397 | printk("md: super_written gets error=%d, uptodate=%d\n", |
| 398 | error, test_bit(BIO_UPTODATE, &bio->bi_flags)); |
| 399 | WARN_ON(test_bit(BIO_UPTODATE, &bio->bi_flags)); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 400 | md_error(mddev, rdev); |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 401 | } |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 402 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 403 | if (atomic_dec_and_test(&mddev->pending_writes)) |
| 404 | wake_up(&mddev->sb_wait); |
Neil Brown | f8b58ed | 2005-06-27 22:29:34 -0700 | [diff] [blame] | 405 | bio_put(bio); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 406 | } |
| 407 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 408 | static void super_written_barrier(struct bio *bio, int error) |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 409 | { |
| 410 | struct bio *bio2 = bio->bi_private; |
| 411 | mdk_rdev_t *rdev = bio2->bi_private; |
| 412 | mddev_t *mddev = rdev->mddev; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 413 | |
| 414 | if (!test_bit(BIO_UPTODATE, &bio->bi_flags) && |
| 415 | error == -EOPNOTSUPP) { |
| 416 | unsigned long flags; |
| 417 | /* barriers don't appear to be supported :-( */ |
| 418 | set_bit(BarriersNotsupp, &rdev->flags); |
| 419 | mddev->barriers_work = 0; |
| 420 | spin_lock_irqsave(&mddev->write_lock, flags); |
| 421 | bio2->bi_next = mddev->biolist; |
| 422 | mddev->biolist = bio2; |
| 423 | spin_unlock_irqrestore(&mddev->write_lock, flags); |
| 424 | wake_up(&mddev->sb_wait); |
| 425 | bio_put(bio); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 426 | } else { |
| 427 | bio_put(bio2); |
| 428 | bio->bi_private = rdev; |
| 429 | super_written(bio, error); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 430 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 431 | } |
| 432 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 433 | void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev, |
| 434 | sector_t sector, int size, struct page *page) |
| 435 | { |
| 436 | /* write first size bytes of page to sector of rdev |
| 437 | * Increment mddev->pending_writes before returning |
| 438 | * and decrement it on completion, waking up sb_wait |
| 439 | * if zero is reached. |
| 440 | * If an error occurred, call md_error |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 441 | * |
| 442 | * As we might need to resubmit the request if BIO_RW_BARRIER |
| 443 | * causes ENOTSUPP, we allocate a spare bio... |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 444 | */ |
| 445 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 446 | int rw = (1<<BIO_RW) | (1<<BIO_RW_SYNC); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 447 | |
| 448 | bio->bi_bdev = rdev->bdev; |
| 449 | bio->bi_sector = sector; |
| 450 | bio_add_page(bio, page, size, 0); |
| 451 | bio->bi_private = rdev; |
| 452 | bio->bi_end_io = super_written; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 453 | bio->bi_rw = rw; |
| 454 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 455 | atomic_inc(&mddev->pending_writes); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 456 | if (!test_bit(BarriersNotsupp, &rdev->flags)) { |
| 457 | struct bio *rbio; |
| 458 | rw |= (1<<BIO_RW_BARRIER); |
| 459 | rbio = bio_clone(bio, GFP_NOIO); |
| 460 | rbio->bi_private = bio; |
| 461 | rbio->bi_end_io = super_written_barrier; |
| 462 | submit_bio(rw, rbio); |
| 463 | } else |
| 464 | submit_bio(rw, bio); |
| 465 | } |
| 466 | |
| 467 | void md_super_wait(mddev_t *mddev) |
| 468 | { |
| 469 | /* wait for all superblock writes that were scheduled to complete. |
| 470 | * if any had to be retried (due to BARRIER problems), retry them |
| 471 | */ |
| 472 | DEFINE_WAIT(wq); |
| 473 | for(;;) { |
| 474 | prepare_to_wait(&mddev->sb_wait, &wq, TASK_UNINTERRUPTIBLE); |
| 475 | if (atomic_read(&mddev->pending_writes)==0) |
| 476 | break; |
| 477 | while (mddev->biolist) { |
| 478 | struct bio *bio; |
| 479 | spin_lock_irq(&mddev->write_lock); |
| 480 | bio = mddev->biolist; |
| 481 | mddev->biolist = bio->bi_next ; |
| 482 | bio->bi_next = NULL; |
| 483 | spin_unlock_irq(&mddev->write_lock); |
| 484 | submit_bio(bio->bi_rw, bio); |
| 485 | } |
| 486 | schedule(); |
| 487 | } |
| 488 | finish_wait(&mddev->sb_wait, &wq); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 489 | } |
| 490 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 491 | static void bi_complete(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | complete((struct completion*)bio->bi_private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 496 | 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] | 497 | struct page *page, int rw) |
| 498 | { |
Neil Brown | baaa2c5 | 2005-04-16 15:23:54 -0700 | [diff] [blame] | 499 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | struct completion event; |
| 501 | int ret; |
| 502 | |
| 503 | rw |= (1 << BIO_RW_SYNC); |
| 504 | |
| 505 | bio->bi_bdev = bdev; |
| 506 | bio->bi_sector = sector; |
| 507 | bio_add_page(bio, page, size, 0); |
| 508 | init_completion(&event); |
| 509 | bio->bi_private = &event; |
| 510 | bio->bi_end_io = bi_complete; |
| 511 | submit_bio(rw, bio); |
| 512 | wait_for_completion(&event); |
| 513 | |
| 514 | ret = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 515 | bio_put(bio); |
| 516 | return ret; |
| 517 | } |
NeilBrown | a8745db | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 518 | EXPORT_SYMBOL_GPL(sync_page_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 520 | static int read_disk_sb(mdk_rdev_t * rdev, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
| 522 | char b[BDEVNAME_SIZE]; |
| 523 | if (!rdev->sb_page) { |
| 524 | MD_BUG(); |
| 525 | return -EINVAL; |
| 526 | } |
| 527 | if (rdev->sb_loaded) |
| 528 | return 0; |
| 529 | |
| 530 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 531 | 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] | 532 | goto fail; |
| 533 | rdev->sb_loaded = 1; |
| 534 | return 0; |
| 535 | |
| 536 | fail: |
| 537 | printk(KERN_WARNING "md: disabled device %s, could not read superblock.\n", |
| 538 | bdevname(rdev->bdev,b)); |
| 539 | return -EINVAL; |
| 540 | } |
| 541 | |
| 542 | static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 543 | { |
Andre Noll | 0571046 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 544 | return sb1->set_uuid0 == sb2->set_uuid0 && |
| 545 | sb1->set_uuid1 == sb2->set_uuid1 && |
| 546 | sb1->set_uuid2 == sb2->set_uuid2 && |
| 547 | sb1->set_uuid3 == sb2->set_uuid3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 551 | { |
| 552 | int ret; |
| 553 | mdp_super_t *tmp1, *tmp2; |
| 554 | |
| 555 | tmp1 = kmalloc(sizeof(*tmp1),GFP_KERNEL); |
| 556 | tmp2 = kmalloc(sizeof(*tmp2),GFP_KERNEL); |
| 557 | |
| 558 | if (!tmp1 || !tmp2) { |
| 559 | ret = 0; |
Andre Noll | 35020f1 | 2008-03-23 15:10:33 +0100 | [diff] [blame] | 560 | printk(KERN_INFO "md.c sb_equal(): failed to allocate memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | goto abort; |
| 562 | } |
| 563 | |
| 564 | *tmp1 = *sb1; |
| 565 | *tmp2 = *sb2; |
| 566 | |
| 567 | /* |
| 568 | * nr_disks is not constant |
| 569 | */ |
| 570 | tmp1->nr_disks = 0; |
| 571 | tmp2->nr_disks = 0; |
| 572 | |
Andre Noll | ce0c8e0 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 573 | ret = (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | abort: |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 575 | kfree(tmp1); |
| 576 | kfree(tmp2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return ret; |
| 578 | } |
| 579 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 580 | |
| 581 | static u32 md_csum_fold(u32 csum) |
| 582 | { |
| 583 | csum = (csum & 0xffff) + (csum >> 16); |
| 584 | return (csum & 0xffff) + (csum >> 16); |
| 585 | } |
| 586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | static unsigned int calc_sb_csum(mdp_super_t * sb) |
| 588 | { |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 589 | u64 newcsum = 0; |
| 590 | u32 *sb32 = (u32*)sb; |
| 591 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | unsigned int disk_csum, csum; |
| 593 | |
| 594 | disk_csum = sb->sb_csum; |
| 595 | sb->sb_csum = 0; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 596 | |
| 597 | for (i = 0; i < MD_SB_BYTES/4 ; i++) |
| 598 | newcsum += sb32[i]; |
| 599 | csum = (newcsum & 0xffffffff) + (newcsum>>32); |
| 600 | |
| 601 | |
| 602 | #ifdef CONFIG_ALPHA |
| 603 | /* This used to use csum_partial, which was wrong for several |
| 604 | * reasons including that different results are returned on |
| 605 | * different architectures. It isn't critical that we get exactly |
| 606 | * the same return value as before (we always csum_fold before |
| 607 | * testing, and that removes any differences). However as we |
| 608 | * know that csum_partial always returned a 16bit value on |
| 609 | * alphas, do a fold to maximise conformity to previous behaviour. |
| 610 | */ |
| 611 | sb->sb_csum = md_csum_fold(disk_csum); |
| 612 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | sb->sb_csum = disk_csum; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 614 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | return csum; |
| 616 | } |
| 617 | |
| 618 | |
| 619 | /* |
| 620 | * Handle superblock details. |
| 621 | * We want to be able to handle multiple superblock formats |
| 622 | * so we have a common interface to them all, and an array of |
| 623 | * different handlers. |
| 624 | * We rely on user-space to write the initial superblock, and support |
| 625 | * reading and updating of superblocks. |
| 626 | * Interface methods are: |
| 627 | * int load_super(mdk_rdev_t *dev, mdk_rdev_t *refdev, int minor_version) |
| 628 | * loads and validates a superblock on dev. |
| 629 | * if refdev != NULL, compare superblocks on both devices |
| 630 | * Return: |
| 631 | * 0 - dev has a superblock that is compatible with refdev |
| 632 | * 1 - dev has a superblock that is compatible and newer than refdev |
| 633 | * so dev should be used as the refdev in future |
| 634 | * -EINVAL superblock incompatible or invalid |
| 635 | * -othererror e.g. -EIO |
| 636 | * |
| 637 | * int validate_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 638 | * Verify that dev is acceptable into mddev. |
| 639 | * The first time, mddev->raid_disks will be 0, and data from |
| 640 | * dev should be merged in. Subsequent calls check that dev |
| 641 | * is new enough. Return 0 or -EINVAL |
| 642 | * |
| 643 | * void sync_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 644 | * Update the superblock for rdev with data in mddev |
| 645 | * This does not write to disc. |
| 646 | * |
| 647 | */ |
| 648 | |
| 649 | struct super_type { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 650 | char *name; |
| 651 | struct module *owner; |
| 652 | int (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev, |
| 653 | int minor_version); |
| 654 | int (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 655 | void (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 656 | unsigned long long (*rdev_size_change)(mdk_rdev_t *rdev, |
| 657 | unsigned long long size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | }; |
| 659 | |
| 660 | /* |
| 661 | * load_super for 0.90.0 |
| 662 | */ |
| 663 | static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 664 | { |
| 665 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 666 | mdp_super_t *sb; |
| 667 | int ret; |
| 668 | sector_t sb_offset; |
| 669 | |
| 670 | /* |
| 671 | * Calculate the position of the superblock, |
| 672 | * it's at the end of the disk. |
| 673 | * |
| 674 | * It also happens to be a multiple of 4Kb. |
| 675 | */ |
| 676 | sb_offset = calc_dev_sboffset(rdev->bdev); |
| 677 | rdev->sb_offset = sb_offset; |
| 678 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 679 | ret = read_disk_sb(rdev, MD_SB_BYTES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | if (ret) return ret; |
| 681 | |
| 682 | ret = -EINVAL; |
| 683 | |
| 684 | bdevname(rdev->bdev, b); |
| 685 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 686 | |
| 687 | if (sb->md_magic != MD_SB_MAGIC) { |
| 688 | printk(KERN_ERR "md: invalid raid superblock magic on %s\n", |
| 689 | b); |
| 690 | goto abort; |
| 691 | } |
| 692 | |
| 693 | if (sb->major_version != 0 || |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 694 | sb->minor_version < 90 || |
| 695 | sb->minor_version > 91) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | printk(KERN_WARNING "Bad version number %d.%d on %s\n", |
| 697 | sb->major_version, sb->minor_version, |
| 698 | b); |
| 699 | goto abort; |
| 700 | } |
| 701 | |
| 702 | if (sb->raid_disks <= 0) |
| 703 | goto abort; |
| 704 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 705 | 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] | 706 | printk(KERN_WARNING "md: invalid superblock checksum on %s\n", |
| 707 | b); |
| 708 | goto abort; |
| 709 | } |
| 710 | |
| 711 | rdev->preferred_minor = sb->md_minor; |
| 712 | rdev->data_offset = 0; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 713 | rdev->sb_size = MD_SB_BYTES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 715 | if (sb->state & (1<<MD_SB_BITMAP_PRESENT)) { |
| 716 | if (sb->level != 1 && sb->level != 4 |
| 717 | && sb->level != 5 && sb->level != 6 |
| 718 | && sb->level != 10) { |
| 719 | /* FIXME use a better test */ |
| 720 | printk(KERN_WARNING |
| 721 | "md: bitmaps not supported for this level.\n"); |
| 722 | goto abort; |
| 723 | } |
| 724 | } |
| 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | if (sb->level == LEVEL_MULTIPATH) |
| 727 | rdev->desc_nr = -1; |
| 728 | else |
| 729 | rdev->desc_nr = sb->this_disk.number; |
| 730 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 731 | if (!refdev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 733 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | __u64 ev1, ev2; |
| 735 | mdp_super_t *refsb = (mdp_super_t*)page_address(refdev->sb_page); |
| 736 | if (!uuid_equal(refsb, sb)) { |
| 737 | printk(KERN_WARNING "md: %s has different UUID to %s\n", |
| 738 | b, bdevname(refdev->bdev,b2)); |
| 739 | goto abort; |
| 740 | } |
| 741 | if (!sb_equal(refsb, sb)) { |
| 742 | printk(KERN_WARNING "md: %s has same UUID" |
| 743 | " but different superblock to %s\n", |
| 744 | b, bdevname(refdev->bdev, b2)); |
| 745 | goto abort; |
| 746 | } |
| 747 | ev1 = md_event(sb); |
| 748 | ev2 = md_event(refsb); |
| 749 | if (ev1 > ev2) |
| 750 | ret = 1; |
| 751 | else |
| 752 | ret = 0; |
| 753 | } |
Andre Noll | e7debaa | 2008-07-11 22:02:23 +1000 | [diff] [blame^] | 754 | rdev->size = calc_num_sectors(rdev, sb->chunk_size) / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 756 | if (rdev->size < sb->size && sb->level > 1) |
| 757 | /* "this cannot possibly happen" ... */ |
| 758 | ret = -EINVAL; |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | abort: |
| 761 | return ret; |
| 762 | } |
| 763 | |
| 764 | /* |
| 765 | * validate_super for 0.90.0 |
| 766 | */ |
| 767 | static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 768 | { |
| 769 | mdp_disk_t *desc; |
| 770 | mdp_super_t *sb = (mdp_super_t *)page_address(rdev->sb_page); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 771 | __u64 ev1 = md_event(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 773 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 774 | clear_bit(Faulty, &rdev->flags); |
| 775 | clear_bit(In_sync, &rdev->flags); |
| 776 | clear_bit(WriteMostly, &rdev->flags); |
| 777 | clear_bit(BarriersNotsupp, &rdev->flags); |
| 778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | if (mddev->raid_disks == 0) { |
| 780 | mddev->major_version = 0; |
| 781 | mddev->minor_version = sb->minor_version; |
| 782 | mddev->patch_version = sb->patch_version; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 783 | mddev->external = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | mddev->chunk_size = sb->chunk_size; |
| 785 | mddev->ctime = sb->ctime; |
| 786 | mddev->utime = sb->utime; |
| 787 | mddev->level = sb->level; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 788 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | mddev->layout = sb->layout; |
| 790 | mddev->raid_disks = sb->raid_disks; |
| 791 | mddev->size = sb->size; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 792 | mddev->events = ev1; |
NeilBrown | 9223214 | 2005-08-18 11:24:16 -0700 | [diff] [blame] | 793 | mddev->bitmap_offset = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 794 | mddev->default_bitmap_offset = MD_SB_BYTES >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 796 | if (mddev->minor_version >= 91) { |
| 797 | mddev->reshape_position = sb->reshape_position; |
| 798 | mddev->delta_disks = sb->delta_disks; |
| 799 | mddev->new_level = sb->new_level; |
| 800 | mddev->new_layout = sb->new_layout; |
| 801 | mddev->new_chunk = sb->new_chunk; |
| 802 | } else { |
| 803 | mddev->reshape_position = MaxSector; |
| 804 | mddev->delta_disks = 0; |
| 805 | mddev->new_level = mddev->level; |
| 806 | mddev->new_layout = mddev->layout; |
| 807 | mddev->new_chunk = mddev->chunk_size; |
| 808 | } |
| 809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | if (sb->state & (1<<MD_SB_CLEAN)) |
| 811 | mddev->recovery_cp = MaxSector; |
| 812 | else { |
| 813 | if (sb->events_hi == sb->cp_events_hi && |
| 814 | sb->events_lo == sb->cp_events_lo) { |
| 815 | mddev->recovery_cp = sb->recovery_cp; |
| 816 | } else |
| 817 | mddev->recovery_cp = 0; |
| 818 | } |
| 819 | |
| 820 | memcpy(mddev->uuid+0, &sb->set_uuid0, 4); |
| 821 | memcpy(mddev->uuid+4, &sb->set_uuid1, 4); |
| 822 | memcpy(mddev->uuid+8, &sb->set_uuid2, 4); |
| 823 | memcpy(mddev->uuid+12,&sb->set_uuid3, 4); |
| 824 | |
| 825 | mddev->max_disks = MD_SB_DISKS; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 826 | |
| 827 | if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 828 | mddev->bitmap_file == NULL) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 829 | mddev->bitmap_offset = mddev->default_bitmap_offset; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 830 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 831 | } else if (mddev->pers == NULL) { |
| 832 | /* Insist on good event counter while assembling */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | ++ev1; |
| 834 | if (ev1 < mddev->events) |
| 835 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 836 | } else if (mddev->bitmap) { |
| 837 | /* if adding to array with a bitmap, then we can accept an |
| 838 | * older device ... but not too old. |
| 839 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 840 | if (ev1 < mddev->bitmap->events_cleared) |
| 841 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 842 | } else { |
| 843 | if (ev1 < mddev->events) |
| 844 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 845 | return 0; |
| 846 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | if (mddev->level != LEVEL_MULTIPATH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | desc = sb->disks + rdev->desc_nr; |
| 850 | |
| 851 | if (desc->state & (1<<MD_DISK_FAULTY)) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 852 | set_bit(Faulty, &rdev->flags); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 853 | else if (desc->state & (1<<MD_DISK_SYNC) /* && |
| 854 | desc->raid_disk < mddev->raid_disks */) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 855 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | rdev->raid_disk = desc->raid_disk; |
| 857 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 858 | if (desc->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 859 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 860 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 861 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | return 0; |
| 863 | } |
| 864 | |
| 865 | /* |
| 866 | * sync_super for 0.90.0 |
| 867 | */ |
| 868 | static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 869 | { |
| 870 | mdp_super_t *sb; |
| 871 | struct list_head *tmp; |
| 872 | mdk_rdev_t *rdev2; |
| 873 | int next_spare = mddev->raid_disks; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
| 876 | /* make rdev->sb match mddev data.. |
| 877 | * |
| 878 | * 1/ zero out disks |
| 879 | * 2/ Add info for each disk, keeping track of highest desc_nr (next_spare); |
| 880 | * 3/ any empty disks < next_spare become removed |
| 881 | * |
| 882 | * disks[0] gets initialised to REMOVED because |
| 883 | * we cannot be sure from other fields if it has |
| 884 | * been initialised or not. |
| 885 | */ |
| 886 | int i; |
| 887 | int active=0, working=0,failed=0,spare=0,nr_disks=0; |
| 888 | |
NeilBrown | 6118156 | 2005-09-09 16:24:02 -0700 | [diff] [blame] | 889 | rdev->sb_size = MD_SB_BYTES; |
| 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 892 | |
| 893 | memset(sb, 0, sizeof(*sb)); |
| 894 | |
| 895 | sb->md_magic = MD_SB_MAGIC; |
| 896 | sb->major_version = mddev->major_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | sb->patch_version = mddev->patch_version; |
| 898 | sb->gvalid_words = 0; /* ignored */ |
| 899 | memcpy(&sb->set_uuid0, mddev->uuid+0, 4); |
| 900 | memcpy(&sb->set_uuid1, mddev->uuid+4, 4); |
| 901 | memcpy(&sb->set_uuid2, mddev->uuid+8, 4); |
| 902 | memcpy(&sb->set_uuid3, mddev->uuid+12,4); |
| 903 | |
| 904 | sb->ctime = mddev->ctime; |
| 905 | sb->level = mddev->level; |
| 906 | sb->size = mddev->size; |
| 907 | sb->raid_disks = mddev->raid_disks; |
| 908 | sb->md_minor = mddev->md_minor; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 909 | sb->not_persistent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | sb->utime = mddev->utime; |
| 911 | sb->state = 0; |
| 912 | sb->events_hi = (mddev->events>>32); |
| 913 | sb->events_lo = (u32)mddev->events; |
| 914 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 915 | if (mddev->reshape_position == MaxSector) |
| 916 | sb->minor_version = 90; |
| 917 | else { |
| 918 | sb->minor_version = 91; |
| 919 | sb->reshape_position = mddev->reshape_position; |
| 920 | sb->new_level = mddev->new_level; |
| 921 | sb->delta_disks = mddev->delta_disks; |
| 922 | sb->new_layout = mddev->new_layout; |
| 923 | sb->new_chunk = mddev->new_chunk; |
| 924 | } |
| 925 | mddev->minor_version = sb->minor_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | if (mddev->in_sync) |
| 927 | { |
| 928 | sb->recovery_cp = mddev->recovery_cp; |
| 929 | sb->cp_events_hi = (mddev->events>>32); |
| 930 | sb->cp_events_lo = (u32)mddev->events; |
| 931 | if (mddev->recovery_cp == MaxSector) |
| 932 | sb->state = (1<< MD_SB_CLEAN); |
| 933 | } else |
| 934 | sb->recovery_cp = 0; |
| 935 | |
| 936 | sb->layout = mddev->layout; |
| 937 | sb->chunk_size = mddev->chunk_size; |
| 938 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 939 | if (mddev->bitmap && mddev->bitmap_file == NULL) |
| 940 | sb->state |= (1<<MD_SB_BITMAP_PRESENT); |
| 941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | sb->disks[0].state = (1<<MD_DISK_REMOVED); |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 943 | rdev_for_each(rdev2, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | mdp_disk_t *d; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 945 | int desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 946 | if (rdev2->raid_disk >= 0 && test_bit(In_sync, &rdev2->flags) |
| 947 | && !test_bit(Faulty, &rdev2->flags)) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 948 | desc_nr = rdev2->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | else |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 950 | desc_nr = next_spare++; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 951 | rdev2->desc_nr = desc_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | d = &sb->disks[rdev2->desc_nr]; |
| 953 | nr_disks++; |
| 954 | d->number = rdev2->desc_nr; |
| 955 | d->major = MAJOR(rdev2->bdev->bd_dev); |
| 956 | d->minor = MINOR(rdev2->bdev->bd_dev); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 957 | if (rdev2->raid_disk >= 0 && test_bit(In_sync, &rdev2->flags) |
| 958 | && !test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | d->raid_disk = rdev2->raid_disk; |
| 960 | else |
| 961 | d->raid_disk = rdev2->desc_nr; /* compatibility */ |
NeilBrown | 1be7892 | 2006-03-27 01:18:03 -0800 | [diff] [blame] | 962 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | d->state = (1<<MD_DISK_FAULTY); |
NeilBrown | 1be7892 | 2006-03-27 01:18:03 -0800 | [diff] [blame] | 964 | else if (test_bit(In_sync, &rdev2->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | d->state = (1<<MD_DISK_ACTIVE); |
| 966 | d->state |= (1<<MD_DISK_SYNC); |
| 967 | active++; |
| 968 | working++; |
| 969 | } else { |
| 970 | d->state = 0; |
| 971 | spare++; |
| 972 | working++; |
| 973 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 974 | if (test_bit(WriteMostly, &rdev2->flags)) |
| 975 | d->state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | /* now set the "removed" and "faulty" bits on any missing devices */ |
| 978 | for (i=0 ; i < mddev->raid_disks ; i++) { |
| 979 | mdp_disk_t *d = &sb->disks[i]; |
| 980 | if (d->state == 0 && d->number == 0) { |
| 981 | d->number = i; |
| 982 | d->raid_disk = i; |
| 983 | d->state = (1<<MD_DISK_REMOVED); |
| 984 | d->state |= (1<<MD_DISK_FAULTY); |
| 985 | failed++; |
| 986 | } |
| 987 | } |
| 988 | sb->nr_disks = nr_disks; |
| 989 | sb->active_disks = active; |
| 990 | sb->working_disks = working; |
| 991 | sb->failed_disks = failed; |
| 992 | sb->spare_disks = spare; |
| 993 | |
| 994 | sb->this_disk = sb->disks[rdev->desc_nr]; |
| 995 | sb->sb_csum = calc_sb_csum(sb); |
| 996 | } |
| 997 | |
| 998 | /* |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 999 | * rdev_size_change for 0.90.0 |
| 1000 | */ |
| 1001 | static unsigned long long |
| 1002 | super_90_rdev_size_change(mdk_rdev_t *rdev, unsigned long long size) |
| 1003 | { |
| 1004 | if (size && size < rdev->mddev->size) |
| 1005 | return 0; /* component must fit device */ |
| 1006 | size *= 2; /* convert to sectors */ |
| 1007 | if (rdev->mddev->bitmap_offset) |
| 1008 | return 0; /* can't move bitmap */ |
| 1009 | rdev->sb_offset = calc_dev_sboffset(rdev->bdev); |
| 1010 | if (!size || size > rdev->sb_offset*2) |
| 1011 | size = rdev->sb_offset*2; |
| 1012 | md_super_write(rdev->mddev, rdev, rdev->sb_offset << 1, rdev->sb_size, |
| 1013 | rdev->sb_page); |
| 1014 | md_super_wait(rdev->mddev); |
| 1015 | return size/2; /* kB for sysfs */ |
| 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | * version 1 superblock |
| 1021 | */ |
| 1022 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1023 | static __le32 calc_sb_1_csum(struct mdp_superblock_1 * sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | { |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1025 | __le32 disk_csum; |
| 1026 | u32 csum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | unsigned long long newcsum; |
| 1028 | int size = 256 + le32_to_cpu(sb->max_dev)*2; |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1029 | __le32 *isuper = (__le32*)sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | int i; |
| 1031 | |
| 1032 | disk_csum = sb->sb_csum; |
| 1033 | sb->sb_csum = 0; |
| 1034 | newcsum = 0; |
| 1035 | for (i=0; size>=4; size -= 4 ) |
| 1036 | newcsum += le32_to_cpu(*isuper++); |
| 1037 | |
| 1038 | if (size == 2) |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1039 | newcsum += le16_to_cpu(*(__le16*) isuper); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | |
| 1041 | csum = (newcsum & 0xffffffff) + (newcsum >> 32); |
| 1042 | sb->sb_csum = disk_csum; |
| 1043 | return cpu_to_le32(csum); |
| 1044 | } |
| 1045 | |
| 1046 | static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 1047 | { |
| 1048 | struct mdp_superblock_1 *sb; |
| 1049 | int ret; |
| 1050 | sector_t sb_offset; |
| 1051 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1052 | int bmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
| 1054 | /* |
| 1055 | * Calculate the position of the superblock. |
| 1056 | * It is always aligned to a 4K boundary and |
| 1057 | * depeding on minor_version, it can be: |
| 1058 | * 0: At least 8K, but less than 12K, from end of device |
| 1059 | * 1: At start of device |
| 1060 | * 2: 4K from start of device. |
| 1061 | */ |
| 1062 | switch(minor_version) { |
| 1063 | case 0: |
| 1064 | sb_offset = rdev->bdev->bd_inode->i_size >> 9; |
| 1065 | sb_offset -= 8*2; |
NeilBrown | 3973096 | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1066 | sb_offset &= ~(sector_t)(4*2-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | /* convert from sectors to K */ |
| 1068 | sb_offset /= 2; |
| 1069 | break; |
| 1070 | case 1: |
| 1071 | sb_offset = 0; |
| 1072 | break; |
| 1073 | case 2: |
| 1074 | sb_offset = 4; |
| 1075 | break; |
| 1076 | default: |
| 1077 | return -EINVAL; |
| 1078 | } |
| 1079 | rdev->sb_offset = sb_offset; |
| 1080 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1081 | /* superblock is rarely larger than 1K, but it can be larger, |
| 1082 | * and it is safe to read 4k, so we do that |
| 1083 | */ |
| 1084 | ret = read_disk_sb(rdev, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | if (ret) return ret; |
| 1086 | |
| 1087 | |
| 1088 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1089 | |
| 1090 | if (sb->magic != cpu_to_le32(MD_SB_MAGIC) || |
| 1091 | sb->major_version != cpu_to_le32(1) || |
| 1092 | le32_to_cpu(sb->max_dev) > (4096-256)/2 || |
| 1093 | le64_to_cpu(sb->super_offset) != (rdev->sb_offset<<1) || |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1094 | (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | return -EINVAL; |
| 1096 | |
| 1097 | if (calc_sb_1_csum(sb) != sb->sb_csum) { |
| 1098 | printk("md: invalid superblock checksum on %s\n", |
| 1099 | bdevname(rdev->bdev,b)); |
| 1100 | return -EINVAL; |
| 1101 | } |
| 1102 | if (le64_to_cpu(sb->data_size) < 10) { |
| 1103 | printk("md: data_size too small on %s\n", |
| 1104 | bdevname(rdev->bdev,b)); |
| 1105 | return -EINVAL; |
| 1106 | } |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1107 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET)) { |
| 1108 | if (sb->level != cpu_to_le32(1) && |
| 1109 | sb->level != cpu_to_le32(4) && |
| 1110 | sb->level != cpu_to_le32(5) && |
| 1111 | sb->level != cpu_to_le32(6) && |
| 1112 | sb->level != cpu_to_le32(10)) { |
| 1113 | printk(KERN_WARNING |
| 1114 | "md: bitmaps not supported for this level.\n"); |
| 1115 | return -EINVAL; |
| 1116 | } |
| 1117 | } |
| 1118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | rdev->preferred_minor = 0xffff; |
| 1120 | rdev->data_offset = le64_to_cpu(sb->data_offset); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1121 | atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1123 | rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256; |
NeilBrown | 720a3dc | 2005-09-09 16:23:59 -0700 | [diff] [blame] | 1124 | bmask = queue_hardsect_size(rdev->bdev->bd_disk->queue)-1; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1125 | if (rdev->sb_size & bmask) |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1126 | rdev->sb_size = (rdev->sb_size | bmask) + 1; |
| 1127 | |
| 1128 | if (minor_version |
| 1129 | && rdev->data_offset < sb_offset + (rdev->sb_size/512)) |
| 1130 | return -EINVAL; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1131 | |
NeilBrown | 31b65a0 | 2006-07-10 04:44:14 -0700 | [diff] [blame] | 1132 | if (sb->level == cpu_to_le32(LEVEL_MULTIPATH)) |
| 1133 | rdev->desc_nr = -1; |
| 1134 | else |
| 1135 | rdev->desc_nr = le32_to_cpu(sb->dev_number); |
| 1136 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1137 | if (!refdev) { |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1138 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1139 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | __u64 ev1, ev2; |
| 1141 | struct mdp_superblock_1 *refsb = |
| 1142 | (struct mdp_superblock_1*)page_address(refdev->sb_page); |
| 1143 | |
| 1144 | if (memcmp(sb->set_uuid, refsb->set_uuid, 16) != 0 || |
| 1145 | sb->level != refsb->level || |
| 1146 | sb->layout != refsb->layout || |
| 1147 | sb->chunksize != refsb->chunksize) { |
| 1148 | printk(KERN_WARNING "md: %s has strangely different" |
| 1149 | " superblock to %s\n", |
| 1150 | bdevname(rdev->bdev,b), |
| 1151 | bdevname(refdev->bdev,b2)); |
| 1152 | return -EINVAL; |
| 1153 | } |
| 1154 | ev1 = le64_to_cpu(sb->events); |
| 1155 | ev2 = le64_to_cpu(refsb->events); |
| 1156 | |
| 1157 | if (ev1 > ev2) |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1158 | ret = 1; |
| 1159 | else |
| 1160 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | } |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1162 | if (minor_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2; |
| 1164 | else |
| 1165 | rdev->size = rdev->sb_offset; |
| 1166 | if (rdev->size < le64_to_cpu(sb->data_size)/2) |
| 1167 | return -EINVAL; |
| 1168 | rdev->size = le64_to_cpu(sb->data_size)/2; |
| 1169 | if (le32_to_cpu(sb->chunksize)) |
| 1170 | rdev->size &= ~((sector_t)le32_to_cpu(sb->chunksize)/2 - 1); |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1171 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1172 | if (le64_to_cpu(sb->size) > rdev->size*2) |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1173 | return -EINVAL; |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1174 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1178 | { |
| 1179 | 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] | 1180 | __u64 ev1 = le64_to_cpu(sb->events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1182 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1183 | clear_bit(Faulty, &rdev->flags); |
| 1184 | clear_bit(In_sync, &rdev->flags); |
| 1185 | clear_bit(WriteMostly, &rdev->flags); |
| 1186 | clear_bit(BarriersNotsupp, &rdev->flags); |
| 1187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | if (mddev->raid_disks == 0) { |
| 1189 | mddev->major_version = 1; |
| 1190 | mddev->patch_version = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1191 | mddev->external = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | mddev->chunk_size = le32_to_cpu(sb->chunksize) << 9; |
| 1193 | mddev->ctime = le64_to_cpu(sb->ctime) & ((1ULL << 32)-1); |
| 1194 | mddev->utime = le64_to_cpu(sb->utime) & ((1ULL << 32)-1); |
| 1195 | mddev->level = le32_to_cpu(sb->level); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 1196 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | mddev->layout = le32_to_cpu(sb->layout); |
| 1198 | mddev->raid_disks = le32_to_cpu(sb->raid_disks); |
| 1199 | mddev->size = le64_to_cpu(sb->size)/2; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1200 | mddev->events = ev1; |
NeilBrown | 9223214 | 2005-08-18 11:24:16 -0700 | [diff] [blame] | 1201 | mddev->bitmap_offset = 0; |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1202 | mddev->default_bitmap_offset = 1024 >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
| 1204 | mddev->recovery_cp = le64_to_cpu(sb->resync_offset); |
| 1205 | memcpy(mddev->uuid, sb->set_uuid, 16); |
| 1206 | |
| 1207 | mddev->max_disks = (4096-256)/2; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1208 | |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1209 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1210 | mddev->bitmap_file == NULL ) |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1211 | mddev->bitmap_offset = (__s32)le32_to_cpu(sb->bitmap_offset); |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1212 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1213 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) { |
| 1214 | mddev->reshape_position = le64_to_cpu(sb->reshape_position); |
| 1215 | mddev->delta_disks = le32_to_cpu(sb->delta_disks); |
| 1216 | mddev->new_level = le32_to_cpu(sb->new_level); |
| 1217 | mddev->new_layout = le32_to_cpu(sb->new_layout); |
| 1218 | mddev->new_chunk = le32_to_cpu(sb->new_chunk)<<9; |
| 1219 | } else { |
| 1220 | mddev->reshape_position = MaxSector; |
| 1221 | mddev->delta_disks = 0; |
| 1222 | mddev->new_level = mddev->level; |
| 1223 | mddev->new_layout = mddev->layout; |
| 1224 | mddev->new_chunk = mddev->chunk_size; |
| 1225 | } |
| 1226 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1227 | } else if (mddev->pers == NULL) { |
| 1228 | /* Insist of good event counter while assembling */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | ++ev1; |
| 1230 | if (ev1 < mddev->events) |
| 1231 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1232 | } else if (mddev->bitmap) { |
| 1233 | /* If adding to array with a bitmap, then we can accept an |
| 1234 | * older device, but not too old. |
| 1235 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1236 | if (ev1 < mddev->bitmap->events_cleared) |
| 1237 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1238 | } else { |
| 1239 | if (ev1 < mddev->events) |
| 1240 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1241 | return 0; |
| 1242 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | if (mddev->level != LEVEL_MULTIPATH) { |
| 1244 | int role; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]); |
| 1246 | switch(role) { |
| 1247 | case 0xffff: /* spare */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | break; |
| 1249 | case 0xfffe: /* faulty */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1250 | set_bit(Faulty, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | break; |
| 1252 | default: |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1253 | if ((le32_to_cpu(sb->feature_map) & |
| 1254 | MD_FEATURE_RECOVERY_OFFSET)) |
| 1255 | rdev->recovery_offset = le64_to_cpu(sb->recovery_offset); |
| 1256 | else |
| 1257 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | rdev->raid_disk = role; |
| 1259 | break; |
| 1260 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1261 | if (sb->devflags & WriteMostly1) |
| 1262 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1263 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1264 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1270 | { |
| 1271 | struct mdp_superblock_1 *sb; |
| 1272 | struct list_head *tmp; |
| 1273 | mdk_rdev_t *rdev2; |
| 1274 | int max_dev, i; |
| 1275 | /* make rdev->sb match mddev and rdev data. */ |
| 1276 | |
| 1277 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1278 | |
| 1279 | sb->feature_map = 0; |
| 1280 | sb->pad0 = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1281 | sb->recovery_offset = cpu_to_le64(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | memset(sb->pad1, 0, sizeof(sb->pad1)); |
| 1283 | memset(sb->pad2, 0, sizeof(sb->pad2)); |
| 1284 | memset(sb->pad3, 0, sizeof(sb->pad3)); |
| 1285 | |
| 1286 | sb->utime = cpu_to_le64((__u64)mddev->utime); |
| 1287 | sb->events = cpu_to_le64(mddev->events); |
| 1288 | if (mddev->in_sync) |
| 1289 | sb->resync_offset = cpu_to_le64(mddev->recovery_cp); |
| 1290 | else |
| 1291 | sb->resync_offset = cpu_to_le64(0); |
| 1292 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1293 | sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors)); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1294 | |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1295 | sb->raid_disks = cpu_to_le32(mddev->raid_disks); |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1296 | sb->size = cpu_to_le64(mddev->size<<1); |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1297 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1298 | if (mddev->bitmap && mddev->bitmap_file == NULL) { |
| 1299 | sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset); |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1300 | sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1301 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1302 | |
| 1303 | if (rdev->raid_disk >= 0 && |
| 1304 | !test_bit(In_sync, &rdev->flags) && |
| 1305 | rdev->recovery_offset > 0) { |
| 1306 | sb->feature_map |= cpu_to_le32(MD_FEATURE_RECOVERY_OFFSET); |
| 1307 | sb->recovery_offset = cpu_to_le64(rdev->recovery_offset); |
| 1308 | } |
| 1309 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1310 | if (mddev->reshape_position != MaxSector) { |
| 1311 | sb->feature_map |= cpu_to_le32(MD_FEATURE_RESHAPE_ACTIVE); |
| 1312 | sb->reshape_position = cpu_to_le64(mddev->reshape_position); |
| 1313 | sb->new_layout = cpu_to_le32(mddev->new_layout); |
| 1314 | sb->delta_disks = cpu_to_le32(mddev->delta_disks); |
| 1315 | sb->new_level = cpu_to_le32(mddev->new_level); |
| 1316 | sb->new_chunk = cpu_to_le32(mddev->new_chunk>>9); |
| 1317 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | max_dev = 0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1320 | rdev_for_each(rdev2, tmp, mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | if (rdev2->desc_nr+1 > max_dev) |
| 1322 | max_dev = rdev2->desc_nr+1; |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1323 | |
| 1324 | if (max_dev > le32_to_cpu(sb->max_dev)) |
| 1325 | sb->max_dev = cpu_to_le32(max_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | for (i=0; i<max_dev;i++) |
| 1327 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
| 1328 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1329 | rdev_for_each(rdev2, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | i = rdev2->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1331 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1333 | else if (test_bit(In_sync, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1335 | else if (rdev2->raid_disk >= 0 && rdev2->recovery_offset > 0) |
| 1336 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | else |
| 1338 | sb->dev_roles[i] = cpu_to_le16(0xffff); |
| 1339 | } |
| 1340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | sb->sb_csum = calc_sb_1_csum(sb); |
| 1342 | } |
| 1343 | |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1344 | static unsigned long long |
| 1345 | super_1_rdev_size_change(mdk_rdev_t *rdev, unsigned long long size) |
| 1346 | { |
| 1347 | struct mdp_superblock_1 *sb; |
| 1348 | unsigned long long max_size; |
| 1349 | if (size && size < rdev->mddev->size) |
| 1350 | return 0; /* component must fit device */ |
| 1351 | size *= 2; /* convert to sectors */ |
| 1352 | if (rdev->sb_offset < rdev->data_offset/2) { |
| 1353 | /* minor versions 1 and 2; superblock before data */ |
| 1354 | max_size = (rdev->bdev->bd_inode->i_size >> 9); |
| 1355 | max_size -= rdev->data_offset; |
| 1356 | if (!size || size > max_size) |
| 1357 | size = max_size; |
| 1358 | } else if (rdev->mddev->bitmap_offset) { |
| 1359 | /* minor version 0 with bitmap we can't move */ |
| 1360 | return 0; |
| 1361 | } else { |
| 1362 | /* minor version 0; superblock after data */ |
| 1363 | sector_t sb_offset; |
| 1364 | sb_offset = (rdev->bdev->bd_inode->i_size >> 9) - 8*2; |
| 1365 | sb_offset &= ~(sector_t)(4*2 - 1); |
| 1366 | max_size = rdev->size*2 + sb_offset - rdev->sb_offset*2; |
| 1367 | if (!size || size > max_size) |
| 1368 | size = max_size; |
| 1369 | rdev->sb_offset = sb_offset/2; |
| 1370 | } |
| 1371 | sb = (struct mdp_superblock_1 *) page_address(rdev->sb_page); |
| 1372 | sb->data_size = cpu_to_le64(size); |
| 1373 | sb->super_offset = rdev->sb_offset*2; |
| 1374 | sb->sb_csum = calc_sb_1_csum(sb); |
| 1375 | md_super_write(rdev->mddev, rdev, rdev->sb_offset << 1, rdev->sb_size, |
| 1376 | rdev->sb_page); |
| 1377 | md_super_wait(rdev->mddev); |
| 1378 | return size/2; /* kB for sysfs */ |
| 1379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 1381 | static struct super_type super_types[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | [0] = { |
| 1383 | .name = "0.90.0", |
| 1384 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1385 | .load_super = super_90_load, |
| 1386 | .validate_super = super_90_validate, |
| 1387 | .sync_super = super_90_sync, |
| 1388 | .rdev_size_change = super_90_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | }, |
| 1390 | [1] = { |
| 1391 | .name = "md-1", |
| 1392 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1393 | .load_super = super_1_load, |
| 1394 | .validate_super = super_1_validate, |
| 1395 | .sync_super = super_1_sync, |
| 1396 | .rdev_size_change = super_1_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | }, |
| 1398 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | |
| 1400 | static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2) |
| 1401 | { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1402 | struct list_head *tmp, *tmp2; |
| 1403 | mdk_rdev_t *rdev, *rdev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1405 | rdev_for_each(rdev, tmp, mddev1) |
| 1406 | rdev_for_each(rdev2, tmp2, mddev2) |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1407 | if (rdev->bdev->bd_contains == |
| 1408 | rdev2->bdev->bd_contains) |
| 1409 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | |
| 1411 | return 0; |
| 1412 | } |
| 1413 | |
| 1414 | static LIST_HEAD(pending_raid_disks); |
| 1415 | |
| 1416 | static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) |
| 1417 | { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1418 | char b[BDEVNAME_SIZE]; |
NeilBrown | f637b9f | 2005-11-08 21:39:37 -0800 | [diff] [blame] | 1419 | struct kobject *ko; |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1420 | char *s; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1421 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
| 1423 | if (rdev->mddev) { |
| 1424 | MD_BUG(); |
| 1425 | return -EINVAL; |
| 1426 | } |
Dan Williams | 11e2ede | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1427 | |
| 1428 | /* prevent duplicates */ |
| 1429 | if (find_rdev(mddev, rdev->bdev->bd_dev)) |
| 1430 | return -EEXIST; |
| 1431 | |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1432 | /* make sure rdev->size exceeds mddev->size */ |
| 1433 | if (rdev->size && (mddev->size == 0 || rdev->size < mddev->size)) { |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1434 | if (mddev->pers) { |
| 1435 | /* Cannot change size, so fail |
| 1436 | * If mddev->level <= 0, then we don't care |
| 1437 | * about aligning sizes (e.g. linear) |
| 1438 | */ |
| 1439 | if (mddev->level > 0) |
| 1440 | return -ENOSPC; |
| 1441 | } else |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1442 | mddev->size = rdev->size; |
| 1443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | |
| 1445 | /* Verify rdev->desc_nr is unique. |
| 1446 | * If it is -1, assign a free number, else |
| 1447 | * check number is not in use |
| 1448 | */ |
| 1449 | if (rdev->desc_nr < 0) { |
| 1450 | int choice = 0; |
| 1451 | if (mddev->pers) choice = mddev->raid_disks; |
| 1452 | while (find_rdev_nr(mddev, choice)) |
| 1453 | choice++; |
| 1454 | rdev->desc_nr = choice; |
| 1455 | } else { |
| 1456 | if (find_rdev_nr(mddev, rdev->desc_nr)) |
| 1457 | return -EBUSY; |
| 1458 | } |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1459 | bdevname(rdev->bdev,b); |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1460 | while ( (s=strchr(b, '/')) != NULL) |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1461 | *s = '!'; |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | rdev->mddev = mddev; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1464 | printk(KERN_INFO "md: bind<%s>\n", b); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1465 | |
Greg Kroah-Hartman | b2d6db5 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1466 | if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b))) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1467 | goto fail; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1468 | |
NeilBrown | f637b9f | 2005-11-08 21:39:37 -0800 | [diff] [blame] | 1469 | if (rdev->bdev->bd_part) |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 1470 | ko = &rdev->bdev->bd_part->dev.kobj; |
NeilBrown | f637b9f | 2005-11-08 21:39:37 -0800 | [diff] [blame] | 1471 | else |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 1472 | ko = &rdev->bdev->bd_disk->dev.kobj; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1473 | if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) { |
| 1474 | kobject_del(&rdev->kobj); |
| 1475 | goto fail; |
| 1476 | } |
| 1477 | list_add(&rdev->same_set, &mddev->disks); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1478 | bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | return 0; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1480 | |
| 1481 | fail: |
| 1482 | printk(KERN_WARNING "md: failed to register dev-%s for %s\n", |
| 1483 | b, mdname(mddev)); |
| 1484 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1487 | static void md_delayed_delete(struct work_struct *ws) |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1488 | { |
| 1489 | mdk_rdev_t *rdev = container_of(ws, mdk_rdev_t, del_work); |
| 1490 | kobject_del(&rdev->kobj); |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1491 | kobject_put(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | static void unbind_rdev_from_array(mdk_rdev_t * rdev) |
| 1495 | { |
| 1496 | char b[BDEVNAME_SIZE]; |
| 1497 | if (!rdev->mddev) { |
| 1498 | MD_BUG(); |
| 1499 | return; |
| 1500 | } |
Jun'ichi Nomura | 5463c79 | 2006-03-27 01:17:58 -0800 | [diff] [blame] | 1501 | bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | list_del_init(&rdev->same_set); |
| 1503 | printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); |
| 1504 | rdev->mddev = NULL; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1505 | sysfs_remove_link(&rdev->kobj, "block"); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1506 | |
| 1507 | /* We need to delay this, otherwise we can deadlock when |
| 1508 | * writing to 'remove' to "dev/state" |
| 1509 | */ |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1510 | INIT_WORK(&rdev->del_work, md_delayed_delete); |
| 1511 | kobject_get(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1512 | schedule_work(&rdev->del_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | /* |
| 1516 | * prevent the device from being mounted, repartitioned or |
| 1517 | * otherwise reused by a RAID array (or any other kernel |
| 1518 | * subsystem), by bd_claiming the device. |
| 1519 | */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1520 | 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] | 1521 | { |
| 1522 | int err = 0; |
| 1523 | struct block_device *bdev; |
| 1524 | char b[BDEVNAME_SIZE]; |
| 1525 | |
Peter Zijlstra | 2e7b651 | 2006-12-08 02:36:13 -0800 | [diff] [blame] | 1526 | bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | if (IS_ERR(bdev)) { |
| 1528 | printk(KERN_ERR "md: could not open %s.\n", |
| 1529 | __bdevname(dev, b)); |
| 1530 | return PTR_ERR(bdev); |
| 1531 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1532 | err = bd_claim(bdev, shared ? (mdk_rdev_t *)lock_rdev : rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | if (err) { |
| 1534 | printk(KERN_ERR "md: could not bd_claim %s.\n", |
| 1535 | bdevname(bdev, b)); |
Peter Zijlstra | 2e7b651 | 2006-12-08 02:36:13 -0800 | [diff] [blame] | 1536 | blkdev_put(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | return err; |
| 1538 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1539 | if (!shared) |
| 1540 | set_bit(AllReserved, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | rdev->bdev = bdev; |
| 1542 | return err; |
| 1543 | } |
| 1544 | |
| 1545 | static void unlock_rdev(mdk_rdev_t *rdev) |
| 1546 | { |
| 1547 | struct block_device *bdev = rdev->bdev; |
| 1548 | rdev->bdev = NULL; |
| 1549 | if (!bdev) |
| 1550 | MD_BUG(); |
| 1551 | bd_release(bdev); |
Peter Zijlstra | 2e7b651 | 2006-12-08 02:36:13 -0800 | [diff] [blame] | 1552 | blkdev_put(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | void md_autodetect_dev(dev_t dev); |
| 1556 | |
| 1557 | static void export_rdev(mdk_rdev_t * rdev) |
| 1558 | { |
| 1559 | char b[BDEVNAME_SIZE]; |
| 1560 | printk(KERN_INFO "md: export_rdev(%s)\n", |
| 1561 | bdevname(rdev->bdev,b)); |
| 1562 | if (rdev->mddev) |
| 1563 | MD_BUG(); |
| 1564 | free_disk_sb(rdev); |
| 1565 | list_del_init(&rdev->same_set); |
| 1566 | #ifndef MODULE |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1567 | if (test_bit(AutoDetected, &rdev->flags)) |
| 1568 | md_autodetect_dev(rdev->bdev->bd_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | #endif |
| 1570 | unlock_rdev(rdev); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1571 | kobject_put(&rdev->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | static void kick_rdev_from_array(mdk_rdev_t * rdev) |
| 1575 | { |
| 1576 | unbind_rdev_from_array(rdev); |
| 1577 | export_rdev(rdev); |
| 1578 | } |
| 1579 | |
| 1580 | static void export_array(mddev_t *mddev) |
| 1581 | { |
| 1582 | struct list_head *tmp; |
| 1583 | mdk_rdev_t *rdev; |
| 1584 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1585 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | if (!rdev->mddev) { |
| 1587 | MD_BUG(); |
| 1588 | continue; |
| 1589 | } |
| 1590 | kick_rdev_from_array(rdev); |
| 1591 | } |
| 1592 | if (!list_empty(&mddev->disks)) |
| 1593 | MD_BUG(); |
| 1594 | mddev->raid_disks = 0; |
| 1595 | mddev->major_version = 0; |
| 1596 | } |
| 1597 | |
| 1598 | static void print_desc(mdp_disk_t *desc) |
| 1599 | { |
| 1600 | printk(" DISK<N:%d,(%d,%d),R:%d,S:%d>\n", desc->number, |
| 1601 | desc->major,desc->minor,desc->raid_disk,desc->state); |
| 1602 | } |
| 1603 | |
| 1604 | static void print_sb(mdp_super_t *sb) |
| 1605 | { |
| 1606 | int i; |
| 1607 | |
| 1608 | printk(KERN_INFO |
| 1609 | "md: SB: (V:%d.%d.%d) ID:<%08x.%08x.%08x.%08x> CT:%08x\n", |
| 1610 | sb->major_version, sb->minor_version, sb->patch_version, |
| 1611 | sb->set_uuid0, sb->set_uuid1, sb->set_uuid2, sb->set_uuid3, |
| 1612 | sb->ctime); |
| 1613 | printk(KERN_INFO "md: L%d S%08d ND:%d RD:%d md%d LO:%d CS:%d\n", |
| 1614 | sb->level, sb->size, sb->nr_disks, sb->raid_disks, |
| 1615 | sb->md_minor, sb->layout, sb->chunk_size); |
| 1616 | printk(KERN_INFO "md: UT:%08x ST:%d AD:%d WD:%d" |
| 1617 | " FD:%d SD:%d CSUM:%08x E:%08lx\n", |
| 1618 | sb->utime, sb->state, sb->active_disks, sb->working_disks, |
| 1619 | sb->failed_disks, sb->spare_disks, |
| 1620 | sb->sb_csum, (unsigned long)sb->events_lo); |
| 1621 | |
| 1622 | printk(KERN_INFO); |
| 1623 | for (i = 0; i < MD_SB_DISKS; i++) { |
| 1624 | mdp_disk_t *desc; |
| 1625 | |
| 1626 | desc = sb->disks + i; |
| 1627 | if (desc->number || desc->major || desc->minor || |
| 1628 | desc->raid_disk || (desc->state && (desc->state != 4))) { |
| 1629 | printk(" D %2d: ", i); |
| 1630 | print_desc(desc); |
| 1631 | } |
| 1632 | } |
| 1633 | printk(KERN_INFO "md: THIS: "); |
| 1634 | print_desc(&sb->this_disk); |
| 1635 | |
| 1636 | } |
| 1637 | |
| 1638 | static void print_rdev(mdk_rdev_t *rdev) |
| 1639 | { |
| 1640 | char b[BDEVNAME_SIZE]; |
| 1641 | printk(KERN_INFO "md: rdev %s, SZ:%08llu F:%d S:%d DN:%u\n", |
| 1642 | bdevname(rdev->bdev,b), (unsigned long long)rdev->size, |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1643 | test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags), |
| 1644 | rdev->desc_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | if (rdev->sb_loaded) { |
| 1646 | printk(KERN_INFO "md: rdev superblock:\n"); |
| 1647 | print_sb((mdp_super_t*)page_address(rdev->sb_page)); |
| 1648 | } else |
| 1649 | printk(KERN_INFO "md: no rdev superblock!\n"); |
| 1650 | } |
| 1651 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 1652 | static void md_print_devices(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | { |
| 1654 | struct list_head *tmp, *tmp2; |
| 1655 | mdk_rdev_t *rdev; |
| 1656 | mddev_t *mddev; |
| 1657 | char b[BDEVNAME_SIZE]; |
| 1658 | |
| 1659 | printk("\n"); |
| 1660 | printk("md: **********************************\n"); |
| 1661 | printk("md: * <COMPLETE RAID STATE PRINTOUT> *\n"); |
| 1662 | printk("md: **********************************\n"); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 1663 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1665 | if (mddev->bitmap) |
| 1666 | bitmap_print_sb(mddev->bitmap); |
| 1667 | else |
| 1668 | printk("%s: ", mdname(mddev)); |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1669 | rdev_for_each(rdev, tmp2, mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 1671 | printk("\n"); |
| 1672 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1673 | rdev_for_each(rdev, tmp2, mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | print_rdev(rdev); |
| 1675 | } |
| 1676 | printk("md: **********************************\n"); |
| 1677 | printk("\n"); |
| 1678 | } |
| 1679 | |
| 1680 | |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1681 | static void sync_sbs(mddev_t * mddev, int nospares) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1683 | /* Update each superblock (in-memory image), but |
| 1684 | * if we are allowed to, skip spares which already |
| 1685 | * have the right event counter, or have one earlier |
| 1686 | * (which would mean they aren't being marked as dirty |
| 1687 | * with the rest of the array) |
| 1688 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | mdk_rdev_t *rdev; |
| 1690 | struct list_head *tmp; |
| 1691 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1692 | rdev_for_each(rdev, tmp, mddev) { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1693 | if (rdev->sb_events == mddev->events || |
| 1694 | (nospares && |
| 1695 | rdev->raid_disk < 0 && |
| 1696 | (rdev->sb_events&1)==0 && |
| 1697 | rdev->sb_events+1 == mddev->events)) { |
| 1698 | /* Don't update this superblock */ |
| 1699 | rdev->sb_loaded = 2; |
| 1700 | } else { |
| 1701 | super_types[mddev->major_version]. |
| 1702 | sync_super(mddev, rdev); |
| 1703 | rdev->sb_loaded = 1; |
| 1704 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | } |
| 1706 | } |
| 1707 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1708 | static void md_update_sb(mddev_t * mddev, int force_change) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | struct list_head *tmp; |
| 1711 | mdk_rdev_t *rdev; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1712 | int sync_req; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1713 | int nospares = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | |
NeilBrown | 8377bc8 | 2008-04-30 00:52:28 -0700 | [diff] [blame] | 1715 | if (mddev->external) |
| 1716 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | repeat: |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1718 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 1719 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1720 | set_bit(MD_CHANGE_PENDING, &mddev->flags); |
| 1721 | if (test_and_clear_bit(MD_CHANGE_DEVS, &mddev->flags)) |
| 1722 | force_change = 1; |
| 1723 | if (test_and_clear_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 1724 | /* just a clean<-> dirty transition, possibly leave spares alone, |
| 1725 | * though if events isn't the right even/odd, we will have to do |
| 1726 | * spares after all |
| 1727 | */ |
| 1728 | nospares = 1; |
| 1729 | if (force_change) |
| 1730 | nospares = 0; |
| 1731 | if (mddev->degraded) |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 1732 | /* If the array is degraded, then skipping spares is both |
| 1733 | * dangerous and fairly pointless. |
| 1734 | * Dangerous because a device that was removed from the array |
| 1735 | * might have a event_count that still looks up-to-date, |
| 1736 | * so it can be re-added without a resync. |
| 1737 | * Pointless because if there are any spares to skip, |
| 1738 | * then a recovery will happen and soon that array won't |
| 1739 | * be degraded any more and the spare can go back to sleep then. |
| 1740 | */ |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1741 | nospares = 0; |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 1742 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1743 | sync_req = mddev->in_sync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | mddev->utime = get_seconds(); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1745 | |
| 1746 | /* If this is just a dirty<->clean transition, and the array is clean |
| 1747 | * and 'events' is odd, we can roll back to the previous clean state */ |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1748 | if (nospares |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1749 | && (mddev->in_sync && mddev->recovery_cp == MaxSector) |
NeilBrown | 1031be7 | 2007-01-26 00:57:02 -0800 | [diff] [blame] | 1750 | && (mddev->events & 1) |
| 1751 | && mddev->events != 1) |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1752 | mddev->events--; |
| 1753 | else { |
| 1754 | /* otherwise we have to go forward and ... */ |
| 1755 | mddev->events ++; |
| 1756 | if (!mddev->in_sync || mddev->recovery_cp != MaxSector) { /* not clean */ |
| 1757 | /* .. if the array isn't clean, insist on an odd 'events' */ |
| 1758 | if ((mddev->events&1)==0) { |
| 1759 | mddev->events++; |
| 1760 | nospares = 0; |
| 1761 | } |
| 1762 | } else { |
| 1763 | /* otherwise insist on an even 'events' (for clean states) */ |
| 1764 | if ((mddev->events&1)) { |
| 1765 | mddev->events++; |
| 1766 | nospares = 0; |
| 1767 | } |
| 1768 | } |
| 1769 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | |
| 1771 | if (!mddev->events) { |
| 1772 | /* |
| 1773 | * oops, this 64-bit counter should never wrap. |
| 1774 | * Either we are in around ~1 trillion A.C., assuming |
| 1775 | * 1 reboot per second, or we have a bug: |
| 1776 | */ |
| 1777 | MD_BUG(); |
| 1778 | mddev->events --; |
| 1779 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | |
| 1781 | /* |
| 1782 | * do not write anything to disk if using |
| 1783 | * nonpersistent superblocks |
| 1784 | */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1785 | if (!mddev->persistent) { |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1786 | if (!mddev->external) |
| 1787 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
| 1788 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1789 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 1790 | wake_up(&mddev->sb_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1792 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1793 | sync_sbs(mddev, nospares); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1794 | spin_unlock_irq(&mddev->write_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | |
| 1796 | dprintk(KERN_INFO |
| 1797 | "md: updating %s RAID superblock on device (in sync %d)\n", |
| 1798 | mdname(mddev),mddev->in_sync); |
| 1799 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1800 | bitmap_update_sb(mddev->bitmap); |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1801 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | char b[BDEVNAME_SIZE]; |
| 1803 | dprintk(KERN_INFO "md: "); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1804 | if (rdev->sb_loaded != 1) |
| 1805 | continue; /* no noise on spare devices */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1806 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | dprintk("(skipping faulty "); |
| 1808 | |
| 1809 | dprintk("%s ", bdevname(rdev->bdev,b)); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1810 | if (!test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1811 | md_super_write(mddev,rdev, |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1812 | rdev->sb_offset<<1, rdev->sb_size, |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1813 | rdev->sb_page); |
| 1814 | dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", |
| 1815 | bdevname(rdev->bdev,b), |
| 1816 | (unsigned long long)rdev->sb_offset); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 1817 | rdev->sb_events = mddev->events; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | } else |
| 1820 | dprintk(")\n"); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 1821 | if (mddev->level == LEVEL_MULTIPATH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | /* only need to write one superblock... */ |
| 1823 | break; |
| 1824 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1825 | md_super_wait(mddev); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1826 | /* 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] | 1827 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1828 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1829 | if (mddev->in_sync != sync_req || |
| 1830 | test_bit(MD_CHANGE_DEVS, &mddev->flags)) { |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1831 | /* have to write it out again */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1832 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1833 | goto repeat; |
| 1834 | } |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1835 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 1836 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 1837 | wake_up(&mddev->sb_wait); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
Andre Noll | 7f6ce76 | 2008-03-23 18:34:54 +0100 | [diff] [blame] | 1841 | /* words written to sysfs files may, or may not, be \n terminated. |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 1842 | * We want to accept with case. For this we use cmd_match. |
| 1843 | */ |
| 1844 | static int cmd_match(const char *cmd, const char *str) |
| 1845 | { |
| 1846 | /* See if cmd, written into a sysfs file, matches |
| 1847 | * str. They must either be the same, or cmd can |
| 1848 | * have a trailing newline |
| 1849 | */ |
| 1850 | while (*cmd && *str && *cmd == *str) { |
| 1851 | cmd++; |
| 1852 | str++; |
| 1853 | } |
| 1854 | if (*cmd == '\n') |
| 1855 | cmd++; |
| 1856 | if (*str || *cmd) |
| 1857 | return 0; |
| 1858 | return 1; |
| 1859 | } |
| 1860 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1861 | struct rdev_sysfs_entry { |
| 1862 | struct attribute attr; |
| 1863 | ssize_t (*show)(mdk_rdev_t *, char *); |
| 1864 | ssize_t (*store)(mdk_rdev_t *, const char *, size_t); |
| 1865 | }; |
| 1866 | |
| 1867 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 1868 | state_show(mdk_rdev_t *rdev, char *page) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1869 | { |
| 1870 | char *sep = ""; |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 1871 | size_t len = 0; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1872 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1873 | if (test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1874 | len+= sprintf(page+len, "%sfaulty",sep); |
| 1875 | sep = ","; |
| 1876 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1877 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1878 | len += sprintf(page+len, "%sin_sync",sep); |
| 1879 | sep = ","; |
| 1880 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 1881 | if (test_bit(WriteMostly, &rdev->flags)) { |
| 1882 | len += sprintf(page+len, "%swrite_mostly",sep); |
| 1883 | sep = ","; |
| 1884 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1885 | if (test_bit(Blocked, &rdev->flags)) { |
| 1886 | len += sprintf(page+len, "%sblocked", sep); |
| 1887 | sep = ","; |
| 1888 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1889 | if (!test_bit(Faulty, &rdev->flags) && |
| 1890 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1891 | len += sprintf(page+len, "%sspare", sep); |
| 1892 | sep = ","; |
| 1893 | } |
| 1894 | return len+sprintf(page+len, "\n"); |
| 1895 | } |
| 1896 | |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 1897 | static ssize_t |
| 1898 | state_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 1899 | { |
| 1900 | /* can write |
| 1901 | * faulty - simulates and error |
| 1902 | * remove - disconnects the device |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 1903 | * writemostly - sets write_mostly |
| 1904 | * -writemostly - clears write_mostly |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1905 | * blocked - sets the Blocked flag |
| 1906 | * -blocked - clears the Blocked flag |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 1907 | */ |
| 1908 | int err = -EINVAL; |
| 1909 | if (cmd_match(buf, "faulty") && rdev->mddev->pers) { |
| 1910 | md_error(rdev->mddev, rdev); |
| 1911 | err = 0; |
| 1912 | } else if (cmd_match(buf, "remove")) { |
| 1913 | if (rdev->raid_disk >= 0) |
| 1914 | err = -EBUSY; |
| 1915 | else { |
| 1916 | mddev_t *mddev = rdev->mddev; |
| 1917 | kick_rdev_from_array(rdev); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 1918 | if (mddev->pers) |
| 1919 | md_update_sb(mddev, 1); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 1920 | md_new_event(mddev); |
| 1921 | err = 0; |
| 1922 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 1923 | } else if (cmd_match(buf, "writemostly")) { |
| 1924 | set_bit(WriteMostly, &rdev->flags); |
| 1925 | err = 0; |
| 1926 | } else if (cmd_match(buf, "-writemostly")) { |
| 1927 | clear_bit(WriteMostly, &rdev->flags); |
| 1928 | err = 0; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1929 | } else if (cmd_match(buf, "blocked")) { |
| 1930 | set_bit(Blocked, &rdev->flags); |
| 1931 | err = 0; |
| 1932 | } else if (cmd_match(buf, "-blocked")) { |
| 1933 | clear_bit(Blocked, &rdev->flags); |
| 1934 | wake_up(&rdev->blocked_wait); |
| 1935 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 1936 | md_wakeup_thread(rdev->mddev->thread); |
| 1937 | |
| 1938 | err = 0; |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 1939 | } |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 1940 | if (!err) |
| 1941 | sysfs_notify(&rdev->kobj, NULL, "state"); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 1942 | return err ? err : len; |
| 1943 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 1944 | static struct rdev_sysfs_entry rdev_state = |
| 1945 | __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1946 | |
| 1947 | static ssize_t |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1948 | errors_show(mdk_rdev_t *rdev, char *page) |
| 1949 | { |
| 1950 | return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors)); |
| 1951 | } |
| 1952 | |
| 1953 | static ssize_t |
| 1954 | errors_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 1955 | { |
| 1956 | char *e; |
| 1957 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 1958 | if (*buf && (*e == 0 || *e == '\n')) { |
| 1959 | atomic_set(&rdev->corrected_errors, n); |
| 1960 | return len; |
| 1961 | } |
| 1962 | return -EINVAL; |
| 1963 | } |
| 1964 | static struct rdev_sysfs_entry rdev_errors = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 1965 | __ATTR(errors, S_IRUGO|S_IWUSR, errors_show, errors_store); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1966 | |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1967 | static ssize_t |
| 1968 | slot_show(mdk_rdev_t *rdev, char *page) |
| 1969 | { |
| 1970 | if (rdev->raid_disk < 0) |
| 1971 | return sprintf(page, "none\n"); |
| 1972 | else |
| 1973 | return sprintf(page, "%d\n", rdev->raid_disk); |
| 1974 | } |
| 1975 | |
| 1976 | static ssize_t |
| 1977 | slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 1978 | { |
| 1979 | char *e; |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1980 | int err; |
| 1981 | char nm[20]; |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1982 | int slot = simple_strtoul(buf, &e, 10); |
| 1983 | if (strncmp(buf, "none", 4)==0) |
| 1984 | slot = -1; |
| 1985 | else if (e==buf || (*e && *e!= '\n')) |
| 1986 | return -EINVAL; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 1987 | if (rdev->mddev->pers && slot == -1) { |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1988 | /* Setting 'slot' on an active array requires also |
| 1989 | * updating the 'rd%d' link, and communicating |
| 1990 | * with the personality with ->hot_*_disk. |
| 1991 | * For now we only support removing |
| 1992 | * failed/spare devices. This normally happens automatically, |
| 1993 | * but not when the metadata is externally managed. |
| 1994 | */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1995 | if (rdev->raid_disk == -1) |
| 1996 | return -EEXIST; |
| 1997 | /* personality does all needed checks */ |
| 1998 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 1999 | return -EINVAL; |
| 2000 | err = rdev->mddev->pers-> |
| 2001 | hot_remove_disk(rdev->mddev, rdev->raid_disk); |
| 2002 | if (err) |
| 2003 | return err; |
| 2004 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2005 | sysfs_remove_link(&rdev->mddev->kobj, nm); |
| 2006 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 2007 | md_wakeup_thread(rdev->mddev->thread); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2008 | } else if (rdev->mddev->pers) { |
| 2009 | mdk_rdev_t *rdev2; |
| 2010 | struct list_head *tmp; |
| 2011 | /* Activating a spare .. or possibly reactivating |
| 2012 | * if we every get bitmaps working here. |
| 2013 | */ |
| 2014 | |
| 2015 | if (rdev->raid_disk != -1) |
| 2016 | return -EBUSY; |
| 2017 | |
| 2018 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 2019 | return -EINVAL; |
| 2020 | |
| 2021 | rdev_for_each(rdev2, tmp, rdev->mddev) |
| 2022 | if (rdev2->raid_disk == slot) |
| 2023 | return -EEXIST; |
| 2024 | |
| 2025 | rdev->raid_disk = slot; |
| 2026 | if (test_bit(In_sync, &rdev->flags)) |
| 2027 | rdev->saved_raid_disk = slot; |
| 2028 | else |
| 2029 | rdev->saved_raid_disk = -1; |
| 2030 | err = rdev->mddev->pers-> |
| 2031 | hot_add_disk(rdev->mddev, rdev); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 2032 | if (err) { |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2033 | rdev->raid_disk = -1; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2034 | return err; |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 2035 | } else |
| 2036 | sysfs_notify(&rdev->kobj, NULL, "state"); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2037 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2038 | if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) |
| 2039 | printk(KERN_WARNING |
| 2040 | "md: cannot register " |
| 2041 | "%s for %s\n", |
| 2042 | nm, mdname(rdev->mddev)); |
| 2043 | |
| 2044 | /* don't wakeup anyone, leave that to userspace. */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2045 | } else { |
| 2046 | if (slot >= rdev->mddev->raid_disks) |
| 2047 | return -ENOSPC; |
| 2048 | rdev->raid_disk = slot; |
| 2049 | /* assume it is working */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2050 | clear_bit(Faulty, &rdev->flags); |
| 2051 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2052 | set_bit(In_sync, &rdev->flags); |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 2053 | sysfs_notify(&rdev->kobj, NULL, "state"); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2054 | } |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2055 | return len; |
| 2056 | } |
| 2057 | |
| 2058 | |
| 2059 | static struct rdev_sysfs_entry rdev_slot = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2060 | __ATTR(slot, S_IRUGO|S_IWUSR, slot_show, slot_store); |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2061 | |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2062 | static ssize_t |
| 2063 | offset_show(mdk_rdev_t *rdev, char *page) |
| 2064 | { |
Andrew Morton | 6961ece | 2006-01-06 00:20:59 -0800 | [diff] [blame] | 2065 | return sprintf(page, "%llu\n", (unsigned long long)rdev->data_offset); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | static ssize_t |
| 2069 | offset_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2070 | { |
| 2071 | char *e; |
| 2072 | unsigned long long offset = simple_strtoull(buf, &e, 10); |
| 2073 | if (e==buf || (*e && *e != '\n')) |
| 2074 | return -EINVAL; |
Neil Brown | 8ed0a52 | 2008-06-28 08:31:29 +1000 | [diff] [blame] | 2075 | if (rdev->mddev->pers && rdev->raid_disk >= 0) |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2076 | return -EBUSY; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2077 | if (rdev->size && rdev->mddev->external) |
| 2078 | /* Must set offset before size, so overlap checks |
| 2079 | * can be sane */ |
| 2080 | return -EBUSY; |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2081 | rdev->data_offset = offset; |
| 2082 | return len; |
| 2083 | } |
| 2084 | |
| 2085 | static struct rdev_sysfs_entry rdev_offset = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2086 | __ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2087 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2088 | static ssize_t |
| 2089 | rdev_size_show(mdk_rdev_t *rdev, char *page) |
| 2090 | { |
| 2091 | return sprintf(page, "%llu\n", (unsigned long long)rdev->size); |
| 2092 | } |
| 2093 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2094 | static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2) |
| 2095 | { |
| 2096 | /* check if two start/length pairs overlap */ |
| 2097 | if (s1+l1 <= s2) |
| 2098 | return 0; |
| 2099 | if (s2+l2 <= s1) |
| 2100 | return 0; |
| 2101 | return 1; |
| 2102 | } |
| 2103 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2104 | static ssize_t |
| 2105 | rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2106 | { |
| 2107 | char *e; |
| 2108 | unsigned long long size = simple_strtoull(buf, &e, 10); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2109 | unsigned long long oldsize = rdev->size; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2110 | mddev_t *my_mddev = rdev->mddev; |
| 2111 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2112 | if (e==buf || (*e && *e != '\n')) |
| 2113 | return -EINVAL; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2114 | if (my_mddev->pers && rdev->raid_disk >= 0) { |
| 2115 | if (rdev->mddev->persistent) { |
| 2116 | size = super_types[rdev->mddev->major_version]. |
| 2117 | rdev_size_change(rdev, size); |
| 2118 | if (!size) |
| 2119 | return -EBUSY; |
| 2120 | } else if (!size) { |
| 2121 | size = (rdev->bdev->bd_inode->i_size >> 10); |
| 2122 | size -= rdev->data_offset/2; |
| 2123 | } |
| 2124 | if (size < rdev->mddev->size) |
| 2125 | return -EINVAL; /* component must fit device */ |
| 2126 | } |
| 2127 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2128 | rdev->size = size; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2129 | if (size > oldsize && rdev->mddev->external) { |
| 2130 | /* need to check that all other rdevs with the same ->bdev |
| 2131 | * do not overlap. We need to unlock the mddev to avoid |
| 2132 | * a deadlock. We have already changed rdev->size, and if |
| 2133 | * we have to change it back, we will have the lock again. |
| 2134 | */ |
| 2135 | mddev_t *mddev; |
| 2136 | int overlap = 0; |
| 2137 | struct list_head *tmp, *tmp2; |
| 2138 | |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2139 | mddev_unlock(my_mddev); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 2140 | for_each_mddev(mddev, tmp) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2141 | mdk_rdev_t *rdev2; |
| 2142 | |
| 2143 | mddev_lock(mddev); |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2144 | rdev_for_each(rdev2, tmp2, mddev) |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2145 | if (test_bit(AllReserved, &rdev2->flags) || |
| 2146 | (rdev->bdev == rdev2->bdev && |
| 2147 | rdev != rdev2 && |
| 2148 | overlaps(rdev->data_offset, rdev->size, |
| 2149 | rdev2->data_offset, rdev2->size))) { |
| 2150 | overlap = 1; |
| 2151 | break; |
| 2152 | } |
| 2153 | mddev_unlock(mddev); |
| 2154 | if (overlap) { |
| 2155 | mddev_put(mddev); |
| 2156 | break; |
| 2157 | } |
| 2158 | } |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2159 | mddev_lock(my_mddev); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2160 | if (overlap) { |
| 2161 | /* Someone else could have slipped in a size |
| 2162 | * change here, but doing so is just silly. |
| 2163 | * We put oldsize back because we *know* it is |
| 2164 | * safe, and trust userspace not to race with |
| 2165 | * itself |
| 2166 | */ |
| 2167 | rdev->size = oldsize; |
| 2168 | return -EBUSY; |
| 2169 | } |
| 2170 | } |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2171 | if (size < my_mddev->size || my_mddev->size == 0) |
| 2172 | my_mddev->size = size; |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2173 | return len; |
| 2174 | } |
| 2175 | |
| 2176 | static struct rdev_sysfs_entry rdev_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2177 | __ATTR(size, S_IRUGO|S_IWUSR, rdev_size_show, rdev_size_store); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2178 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2179 | static struct attribute *rdev_default_attrs[] = { |
| 2180 | &rdev_state.attr, |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2181 | &rdev_errors.attr, |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2182 | &rdev_slot.attr, |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2183 | &rdev_offset.attr, |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2184 | &rdev_size.attr, |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2185 | NULL, |
| 2186 | }; |
| 2187 | static ssize_t |
| 2188 | rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 2189 | { |
| 2190 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2191 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2192 | mddev_t *mddev = rdev->mddev; |
| 2193 | ssize_t rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2194 | |
| 2195 | if (!entry->show) |
| 2196 | return -EIO; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2197 | |
| 2198 | rv = mddev ? mddev_lock(mddev) : -EBUSY; |
| 2199 | if (!rv) { |
| 2200 | if (rdev->mddev == NULL) |
| 2201 | rv = -EBUSY; |
| 2202 | else |
| 2203 | rv = entry->show(rdev, page); |
| 2204 | mddev_unlock(mddev); |
| 2205 | } |
| 2206 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | static ssize_t |
| 2210 | rdev_attr_store(struct kobject *kobj, struct attribute *attr, |
| 2211 | const char *page, size_t length) |
| 2212 | { |
| 2213 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2214 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2215 | ssize_t rv; |
| 2216 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2217 | |
| 2218 | if (!entry->store) |
| 2219 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 2220 | if (!capable(CAP_SYS_ADMIN)) |
| 2221 | return -EACCES; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2222 | rv = mddev ? mddev_lock(mddev): -EBUSY; |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2223 | if (!rv) { |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2224 | if (rdev->mddev == NULL) |
| 2225 | rv = -EBUSY; |
| 2226 | else |
| 2227 | rv = entry->store(rdev, page, length); |
Dan Williams | 6a51830 | 2008-04-30 00:52:28 -0700 | [diff] [blame] | 2228 | mddev_unlock(mddev); |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2229 | } |
| 2230 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | static void rdev_free(struct kobject *ko) |
| 2234 | { |
| 2235 | mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj); |
| 2236 | kfree(rdev); |
| 2237 | } |
| 2238 | static struct sysfs_ops rdev_sysfs_ops = { |
| 2239 | .show = rdev_attr_show, |
| 2240 | .store = rdev_attr_store, |
| 2241 | }; |
| 2242 | static struct kobj_type rdev_ktype = { |
| 2243 | .release = rdev_free, |
| 2244 | .sysfs_ops = &rdev_sysfs_ops, |
| 2245 | .default_attrs = rdev_default_attrs, |
| 2246 | }; |
| 2247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | /* |
| 2249 | * Import a device. If 'super_format' >= 0, then sanity check the superblock |
| 2250 | * |
| 2251 | * mark the device faulty if: |
| 2252 | * |
| 2253 | * - the device is nonexistent (zero size) |
| 2254 | * - the device has no valid superblock |
| 2255 | * |
| 2256 | * a faulty rdev _never_ has rdev->sb set. |
| 2257 | */ |
| 2258 | static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_minor) |
| 2259 | { |
| 2260 | char b[BDEVNAME_SIZE]; |
| 2261 | int err; |
| 2262 | mdk_rdev_t *rdev; |
| 2263 | sector_t size; |
| 2264 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 2265 | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | if (!rdev) { |
| 2267 | printk(KERN_ERR "md: could not alloc mem for new device!\n"); |
| 2268 | return ERR_PTR(-ENOMEM); |
| 2269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | |
| 2271 | if ((err = alloc_disk_sb(rdev))) |
| 2272 | goto abort_free; |
| 2273 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2274 | err = lock_rdev(rdev, newdev, super_format == -2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | if (err) |
| 2276 | goto abort_free; |
| 2277 | |
Greg Kroah-Hartman | f9cb074 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 2278 | kobject_init(&rdev->kobj, &rdev_ktype); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | rdev->desc_nr = -1; |
NeilBrown | 2b6e845 | 2006-10-28 10:38:30 -0700 | [diff] [blame] | 2281 | rdev->saved_raid_disk = -1; |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 2282 | rdev->raid_disk = -1; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2283 | rdev->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | rdev->data_offset = 0; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2285 | rdev->sb_events = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | atomic_set(&rdev->nr_pending, 0); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2287 | atomic_set(&rdev->read_errors, 0); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2288 | atomic_set(&rdev->corrected_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | |
| 2290 | size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 2291 | if (!size) { |
| 2292 | printk(KERN_WARNING |
| 2293 | "md: %s has zero or unknown size, marking faulty!\n", |
| 2294 | bdevname(rdev->bdev,b)); |
| 2295 | err = -EINVAL; |
| 2296 | goto abort_free; |
| 2297 | } |
| 2298 | |
| 2299 | if (super_format >= 0) { |
| 2300 | err = super_types[super_format]. |
| 2301 | load_super(rdev, NULL, super_minor); |
| 2302 | if (err == -EINVAL) { |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 2303 | printk(KERN_WARNING |
| 2304 | "md: %s does not have a valid v%d.%d " |
| 2305 | "superblock, not importing!\n", |
| 2306 | bdevname(rdev->bdev,b), |
| 2307 | super_format, super_minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | goto abort_free; |
| 2309 | } |
| 2310 | if (err < 0) { |
| 2311 | printk(KERN_WARNING |
| 2312 | "md: could not read %s's sb, not importing!\n", |
| 2313 | bdevname(rdev->bdev,b)); |
| 2314 | goto abort_free; |
| 2315 | } |
| 2316 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | INIT_LIST_HEAD(&rdev->same_set); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2319 | init_waitqueue_head(&rdev->blocked_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | |
| 2321 | return rdev; |
| 2322 | |
| 2323 | abort_free: |
| 2324 | if (rdev->sb_page) { |
| 2325 | if (rdev->bdev) |
| 2326 | unlock_rdev(rdev); |
| 2327 | free_disk_sb(rdev); |
| 2328 | } |
| 2329 | kfree(rdev); |
| 2330 | return ERR_PTR(err); |
| 2331 | } |
| 2332 | |
| 2333 | /* |
| 2334 | * Check a full RAID array for plausibility |
| 2335 | */ |
| 2336 | |
| 2337 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 2338 | static void analyze_sbs(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | { |
| 2340 | int i; |
| 2341 | struct list_head *tmp; |
| 2342 | mdk_rdev_t *rdev, *freshest; |
| 2343 | char b[BDEVNAME_SIZE]; |
| 2344 | |
| 2345 | freshest = NULL; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2346 | rdev_for_each(rdev, tmp, mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | switch (super_types[mddev->major_version]. |
| 2348 | load_super(rdev, freshest, mddev->minor_version)) { |
| 2349 | case 1: |
| 2350 | freshest = rdev; |
| 2351 | break; |
| 2352 | case 0: |
| 2353 | break; |
| 2354 | default: |
| 2355 | printk( KERN_ERR \ |
| 2356 | "md: fatal superblock inconsistency in %s" |
| 2357 | " -- removing from array\n", |
| 2358 | bdevname(rdev->bdev,b)); |
| 2359 | kick_rdev_from_array(rdev); |
| 2360 | } |
| 2361 | |
| 2362 | |
| 2363 | super_types[mddev->major_version]. |
| 2364 | validate_super(mddev, freshest); |
| 2365 | |
| 2366 | i = 0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2367 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | if (rdev != freshest) |
| 2369 | if (super_types[mddev->major_version]. |
| 2370 | validate_super(mddev, rdev)) { |
| 2371 | printk(KERN_WARNING "md: kicking non-fresh %s" |
| 2372 | " from array!\n", |
| 2373 | bdevname(rdev->bdev,b)); |
| 2374 | kick_rdev_from_array(rdev); |
| 2375 | continue; |
| 2376 | } |
| 2377 | if (mddev->level == LEVEL_MULTIPATH) { |
| 2378 | rdev->desc_nr = i++; |
| 2379 | rdev->raid_disk = rdev->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2380 | set_bit(In_sync, &rdev->flags); |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 2381 | } else if (rdev->raid_disk >= mddev->raid_disks) { |
| 2382 | rdev->raid_disk = -1; |
| 2383 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | |
| 2388 | |
| 2389 | if (mddev->recovery_cp != MaxSector && |
| 2390 | mddev->level >= 1) |
| 2391 | printk(KERN_ERR "md: %s: raid array is not clean" |
| 2392 | " -- starting background reconstruction\n", |
| 2393 | mdname(mddev)); |
| 2394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2397 | static ssize_t |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2398 | safe_delay_show(mddev_t *mddev, char *page) |
| 2399 | { |
| 2400 | int msec = (mddev->safemode_delay*1000)/HZ; |
| 2401 | return sprintf(page, "%d.%03d\n", msec/1000, msec%1000); |
| 2402 | } |
| 2403 | static ssize_t |
| 2404 | safe_delay_store(mddev_t *mddev, const char *cbuf, size_t len) |
| 2405 | { |
| 2406 | int scale=1; |
| 2407 | int dot=0; |
| 2408 | int i; |
| 2409 | unsigned long msec; |
| 2410 | char buf[30]; |
| 2411 | char *e; |
| 2412 | /* remove a period, and count digits after it */ |
| 2413 | if (len >= sizeof(buf)) |
| 2414 | return -EINVAL; |
| 2415 | strlcpy(buf, cbuf, len); |
| 2416 | buf[len] = 0; |
| 2417 | for (i=0; i<len; i++) { |
| 2418 | if (dot) { |
| 2419 | if (isdigit(buf[i])) { |
| 2420 | buf[i-1] = buf[i]; |
| 2421 | scale *= 10; |
| 2422 | } |
| 2423 | buf[i] = 0; |
| 2424 | } else if (buf[i] == '.') { |
| 2425 | dot=1; |
| 2426 | buf[i] = 0; |
| 2427 | } |
| 2428 | } |
| 2429 | msec = simple_strtoul(buf, &e, 10); |
| 2430 | if (e == buf || (*e && *e != '\n')) |
| 2431 | return -EINVAL; |
| 2432 | msec = (msec * 1000) / scale; |
| 2433 | if (msec == 0) |
| 2434 | mddev->safemode_delay = 0; |
| 2435 | else { |
| 2436 | mddev->safemode_delay = (msec*HZ)/1000; |
| 2437 | if (mddev->safemode_delay == 0) |
| 2438 | mddev->safemode_delay = 1; |
| 2439 | } |
| 2440 | return len; |
| 2441 | } |
| 2442 | static struct md_sysfs_entry md_safe_delay = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2443 | __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] | 2444 | |
| 2445 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2446 | level_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2447 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2448 | struct mdk_personality *p = mddev->pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2449 | if (p) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2450 | return sprintf(page, "%s\n", p->name); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2451 | else if (mddev->clevel[0]) |
| 2452 | return sprintf(page, "%s\n", mddev->clevel); |
| 2453 | else if (mddev->level != LEVEL_NONE) |
| 2454 | return sprintf(page, "%d\n", mddev->level); |
| 2455 | else |
| 2456 | return 0; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2457 | } |
| 2458 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2459 | static ssize_t |
| 2460 | level_store(mddev_t *mddev, const char *buf, size_t len) |
| 2461 | { |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2462 | ssize_t rv = len; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2463 | if (mddev->pers) |
| 2464 | return -EBUSY; |
| 2465 | if (len == 0) |
| 2466 | return 0; |
| 2467 | if (len >= sizeof(mddev->clevel)) |
| 2468 | return -ENOSPC; |
| 2469 | strncpy(mddev->clevel, buf, len); |
| 2470 | if (mddev->clevel[len-1] == '\n') |
| 2471 | len--; |
| 2472 | mddev->clevel[len] = 0; |
| 2473 | mddev->level = LEVEL_NONE; |
| 2474 | return rv; |
| 2475 | } |
| 2476 | |
| 2477 | static struct md_sysfs_entry md_level = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2478 | __ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2479 | |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2480 | |
| 2481 | static ssize_t |
| 2482 | layout_show(mddev_t *mddev, char *page) |
| 2483 | { |
| 2484 | /* just a number, not meaningful for all levels */ |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 2485 | if (mddev->reshape_position != MaxSector && |
| 2486 | mddev->layout != mddev->new_layout) |
| 2487 | return sprintf(page, "%d (%d)\n", |
| 2488 | mddev->new_layout, mddev->layout); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2489 | return sprintf(page, "%d\n", mddev->layout); |
| 2490 | } |
| 2491 | |
| 2492 | static ssize_t |
| 2493 | layout_store(mddev_t *mddev, const char *buf, size_t len) |
| 2494 | { |
| 2495 | char *e; |
| 2496 | unsigned long n = simple_strtoul(buf, &e, 10); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2497 | |
| 2498 | if (!*buf || (*e && *e != '\n')) |
| 2499 | return -EINVAL; |
| 2500 | |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 2501 | if (mddev->pers) |
| 2502 | return -EBUSY; |
| 2503 | if (mddev->reshape_position != MaxSector) |
| 2504 | mddev->new_layout = n; |
| 2505 | else |
| 2506 | mddev->layout = n; |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2507 | return len; |
| 2508 | } |
| 2509 | static struct md_sysfs_entry md_layout = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2510 | __ATTR(layout, S_IRUGO|S_IWUSR, layout_show, layout_store); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2511 | |
| 2512 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2513 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2514 | raid_disks_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2515 | { |
NeilBrown | bb63654 | 2005-11-08 21:39:45 -0800 | [diff] [blame] | 2516 | if (mddev->raid_disks == 0) |
| 2517 | return 0; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 2518 | if (mddev->reshape_position != MaxSector && |
| 2519 | mddev->delta_disks != 0) |
| 2520 | return sprintf(page, "%d (%d)\n", mddev->raid_disks, |
| 2521 | mddev->raid_disks - mddev->delta_disks); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2522 | return sprintf(page, "%d\n", mddev->raid_disks); |
| 2523 | } |
| 2524 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 2525 | static int update_raid_disks(mddev_t *mddev, int raid_disks); |
| 2526 | |
| 2527 | static ssize_t |
| 2528 | raid_disks_store(mddev_t *mddev, const char *buf, size_t len) |
| 2529 | { |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 2530 | char *e; |
| 2531 | int rv = 0; |
| 2532 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 2533 | |
| 2534 | if (!*buf || (*e && *e != '\n')) |
| 2535 | return -EINVAL; |
| 2536 | |
| 2537 | if (mddev->pers) |
| 2538 | rv = update_raid_disks(mddev, n); |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 2539 | else if (mddev->reshape_position != MaxSector) { |
| 2540 | int olddisks = mddev->raid_disks - mddev->delta_disks; |
| 2541 | mddev->delta_disks = n - olddisks; |
| 2542 | mddev->raid_disks = n; |
| 2543 | } else |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 2544 | mddev->raid_disks = n; |
| 2545 | return rv ? rv : len; |
| 2546 | } |
| 2547 | static struct md_sysfs_entry md_raid_disks = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2548 | __ATTR(raid_disks, S_IRUGO|S_IWUSR, raid_disks_show, raid_disks_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2549 | |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2550 | static ssize_t |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2551 | chunk_size_show(mddev_t *mddev, char *page) |
| 2552 | { |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 2553 | if (mddev->reshape_position != MaxSector && |
| 2554 | mddev->chunk_size != mddev->new_chunk) |
| 2555 | return sprintf(page, "%d (%d)\n", mddev->new_chunk, |
| 2556 | mddev->chunk_size); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2557 | return sprintf(page, "%d\n", mddev->chunk_size); |
| 2558 | } |
| 2559 | |
| 2560 | static ssize_t |
| 2561 | chunk_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 2562 | { |
| 2563 | /* can only set chunk_size if array is not yet active */ |
| 2564 | char *e; |
| 2565 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 2566 | |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2567 | if (!*buf || (*e && *e != '\n')) |
| 2568 | return -EINVAL; |
| 2569 | |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 2570 | if (mddev->pers) |
| 2571 | return -EBUSY; |
| 2572 | else if (mddev->reshape_position != MaxSector) |
| 2573 | mddev->new_chunk = n; |
| 2574 | else |
| 2575 | mddev->chunk_size = n; |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2576 | return len; |
| 2577 | } |
| 2578 | static struct md_sysfs_entry md_chunk_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2579 | __ATTR(chunk_size, S_IRUGO|S_IWUSR, chunk_size_show, chunk_size_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2580 | |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 2581 | static ssize_t |
| 2582 | resync_start_show(mddev_t *mddev, char *page) |
| 2583 | { |
| 2584 | return sprintf(page, "%llu\n", (unsigned long long)mddev->recovery_cp); |
| 2585 | } |
| 2586 | |
| 2587 | static ssize_t |
| 2588 | resync_start_store(mddev_t *mddev, const char *buf, size_t len) |
| 2589 | { |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 2590 | char *e; |
| 2591 | unsigned long long n = simple_strtoull(buf, &e, 10); |
| 2592 | |
| 2593 | if (mddev->pers) |
| 2594 | return -EBUSY; |
| 2595 | if (!*buf || (*e && *e != '\n')) |
| 2596 | return -EINVAL; |
| 2597 | |
| 2598 | mddev->recovery_cp = n; |
| 2599 | return len; |
| 2600 | } |
| 2601 | static struct md_sysfs_entry md_resync_start = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2602 | __ATTR(resync_start, S_IRUGO|S_IWUSR, resync_start_show, resync_start_store); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 2603 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2604 | /* |
| 2605 | * The array state can be: |
| 2606 | * |
| 2607 | * clear |
| 2608 | * No devices, no size, no level |
| 2609 | * Equivalent to STOP_ARRAY ioctl |
| 2610 | * inactive |
| 2611 | * May have some settings, but array is not active |
| 2612 | * all IO results in error |
| 2613 | * When written, doesn't tear down array, but just stops it |
| 2614 | * suspended (not supported yet) |
| 2615 | * All IO requests will block. The array can be reconfigured. |
Andre Noll | 910d8cb | 2008-03-25 21:00:53 +0100 | [diff] [blame] | 2616 | * Writing this, if accepted, will block until array is quiescent |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2617 | * readonly |
| 2618 | * no resync can happen. no superblocks get written. |
| 2619 | * write requests fail |
| 2620 | * read-auto |
| 2621 | * like readonly, but behaves like 'clean' on a write request. |
| 2622 | * |
| 2623 | * clean - no pending writes, but otherwise active. |
| 2624 | * When written to inactive array, starts without resync |
| 2625 | * If a write request arrives then |
| 2626 | * if metadata is known, mark 'dirty' and switch to 'active'. |
| 2627 | * if not known, block and switch to write-pending |
| 2628 | * If written to an active array that has pending writes, then fails. |
| 2629 | * active |
| 2630 | * fully active: IO and resync can be happening. |
| 2631 | * When written to inactive array, starts with resync |
| 2632 | * |
| 2633 | * write-pending |
| 2634 | * clean, but writes are blocked waiting for 'active' to be written. |
| 2635 | * |
| 2636 | * active-idle |
| 2637 | * like active, but no writes have been seen for a while (100msec). |
| 2638 | * |
| 2639 | */ |
| 2640 | enum array_state { clear, inactive, suspended, readonly, read_auto, clean, active, |
| 2641 | write_pending, active_idle, bad_word}; |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2642 | static char *array_states[] = { |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2643 | "clear", "inactive", "suspended", "readonly", "read-auto", "clean", "active", |
| 2644 | "write-pending", "active-idle", NULL }; |
| 2645 | |
| 2646 | static int match_word(const char *word, char **list) |
| 2647 | { |
| 2648 | int n; |
| 2649 | for (n=0; list[n]; n++) |
| 2650 | if (cmd_match(word, list[n])) |
| 2651 | break; |
| 2652 | return n; |
| 2653 | } |
| 2654 | |
| 2655 | static ssize_t |
| 2656 | array_state_show(mddev_t *mddev, char *page) |
| 2657 | { |
| 2658 | enum array_state st = inactive; |
| 2659 | |
| 2660 | if (mddev->pers) |
| 2661 | switch(mddev->ro) { |
| 2662 | case 1: |
| 2663 | st = readonly; |
| 2664 | break; |
| 2665 | case 2: |
| 2666 | st = read_auto; |
| 2667 | break; |
| 2668 | case 0: |
| 2669 | if (mddev->in_sync) |
| 2670 | st = clean; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2671 | else if (test_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 2672 | st = write_pending; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2673 | else if (mddev->safemode) |
| 2674 | st = active_idle; |
| 2675 | else |
| 2676 | st = active; |
| 2677 | } |
| 2678 | else { |
| 2679 | if (list_empty(&mddev->disks) && |
| 2680 | mddev->raid_disks == 0 && |
| 2681 | mddev->size == 0) |
| 2682 | st = clear; |
| 2683 | else |
| 2684 | st = inactive; |
| 2685 | } |
| 2686 | return sprintf(page, "%s\n", array_states[st]); |
| 2687 | } |
| 2688 | |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 2689 | static int do_md_stop(mddev_t * mddev, int ro, int is_open); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2690 | static int do_md_run(mddev_t * mddev); |
| 2691 | static int restart_array(mddev_t *mddev); |
| 2692 | |
| 2693 | static ssize_t |
| 2694 | array_state_store(mddev_t *mddev, const char *buf, size_t len) |
| 2695 | { |
| 2696 | int err = -EINVAL; |
| 2697 | enum array_state st = match_word(buf, array_states); |
| 2698 | switch(st) { |
| 2699 | case bad_word: |
| 2700 | break; |
| 2701 | case clear: |
| 2702 | /* stopping an active array */ |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2703 | if (atomic_read(&mddev->active) > 1) |
| 2704 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 2705 | err = do_md_stop(mddev, 0, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2706 | break; |
| 2707 | case inactive: |
| 2708 | /* stopping an active array */ |
| 2709 | if (mddev->pers) { |
| 2710 | if (atomic_read(&mddev->active) > 1) |
| 2711 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 2712 | err = do_md_stop(mddev, 2, 0); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2713 | } else |
| 2714 | err = 0; /* already inactive */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2715 | break; |
| 2716 | case suspended: |
| 2717 | break; /* not supported yet */ |
| 2718 | case readonly: |
| 2719 | if (mddev->pers) |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 2720 | err = do_md_stop(mddev, 1, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2721 | else { |
| 2722 | mddev->ro = 1; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 2723 | set_disk_ro(mddev->gendisk, 1); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2724 | err = do_md_run(mddev); |
| 2725 | } |
| 2726 | break; |
| 2727 | case read_auto: |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2728 | if (mddev->pers) { |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 2729 | if (mddev->ro != 1) |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 2730 | err = do_md_stop(mddev, 1, 0); |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 2731 | else |
| 2732 | err = restart_array(mddev); |
| 2733 | if (err == 0) { |
| 2734 | mddev->ro = 2; |
| 2735 | set_disk_ro(mddev->gendisk, 0); |
| 2736 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2737 | } else { |
| 2738 | mddev->ro = 2; |
| 2739 | err = do_md_run(mddev); |
| 2740 | } |
| 2741 | break; |
| 2742 | case clean: |
| 2743 | if (mddev->pers) { |
| 2744 | restart_array(mddev); |
| 2745 | spin_lock_irq(&mddev->write_lock); |
| 2746 | if (atomic_read(&mddev->writes_pending) == 0) { |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2747 | if (mddev->in_sync == 0) { |
| 2748 | mddev->in_sync = 1; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 2749 | if (mddev->safemode == 1) |
| 2750 | mddev->safemode = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2751 | if (mddev->persistent) |
| 2752 | set_bit(MD_CHANGE_CLEAN, |
| 2753 | &mddev->flags); |
| 2754 | } |
| 2755 | err = 0; |
| 2756 | } else |
| 2757 | err = -EBUSY; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2758 | spin_unlock_irq(&mddev->write_lock); |
| 2759 | } else { |
| 2760 | mddev->ro = 0; |
| 2761 | mddev->recovery_cp = MaxSector; |
| 2762 | err = do_md_run(mddev); |
| 2763 | } |
| 2764 | break; |
| 2765 | case active: |
| 2766 | if (mddev->pers) { |
| 2767 | restart_array(mddev); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2768 | if (mddev->external) |
| 2769 | clear_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2770 | wake_up(&mddev->sb_wait); |
| 2771 | err = 0; |
| 2772 | } else { |
| 2773 | mddev->ro = 0; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 2774 | set_disk_ro(mddev->gendisk, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2775 | err = do_md_run(mddev); |
| 2776 | } |
| 2777 | break; |
| 2778 | case write_pending: |
| 2779 | case active_idle: |
| 2780 | /* these cannot be set */ |
| 2781 | break; |
| 2782 | } |
| 2783 | if (err) |
| 2784 | return err; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 2785 | else { |
| 2786 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2787 | return len; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 2788 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2789 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2790 | static struct md_sysfs_entry md_array_state = |
| 2791 | __ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2792 | |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 2793 | static ssize_t |
| 2794 | null_show(mddev_t *mddev, char *page) |
| 2795 | { |
| 2796 | return -EINVAL; |
| 2797 | } |
| 2798 | |
| 2799 | static ssize_t |
| 2800 | new_dev_store(mddev_t *mddev, const char *buf, size_t len) |
| 2801 | { |
| 2802 | /* buf must be %d:%d\n? giving major and minor numbers */ |
| 2803 | /* The new device is added to the array. |
| 2804 | * If the array has a persistent superblock, we read the |
| 2805 | * superblock to initialise info and check validity. |
| 2806 | * Otherwise, only checking done is that in bind_rdev_to_array, |
| 2807 | * which mainly checks size. |
| 2808 | */ |
| 2809 | char *e; |
| 2810 | int major = simple_strtoul(buf, &e, 10); |
| 2811 | int minor; |
| 2812 | dev_t dev; |
| 2813 | mdk_rdev_t *rdev; |
| 2814 | int err; |
| 2815 | |
| 2816 | if (!*buf || *e != ':' || !e[1] || e[1] == '\n') |
| 2817 | return -EINVAL; |
| 2818 | minor = simple_strtoul(e+1, &e, 10); |
| 2819 | if (*e && *e != '\n') |
| 2820 | return -EINVAL; |
| 2821 | dev = MKDEV(major, minor); |
| 2822 | if (major != MAJOR(dev) || |
| 2823 | minor != MINOR(dev)) |
| 2824 | return -EOVERFLOW; |
| 2825 | |
| 2826 | |
| 2827 | if (mddev->persistent) { |
| 2828 | rdev = md_import_device(dev, mddev->major_version, |
| 2829 | mddev->minor_version); |
| 2830 | if (!IS_ERR(rdev) && !list_empty(&mddev->disks)) { |
| 2831 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 2832 | mdk_rdev_t, same_set); |
| 2833 | err = super_types[mddev->major_version] |
| 2834 | .load_super(rdev, rdev0, mddev->minor_version); |
| 2835 | if (err < 0) |
| 2836 | goto out; |
| 2837 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2838 | } else if (mddev->external) |
| 2839 | rdev = md_import_device(dev, -2, -1); |
| 2840 | else |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 2841 | rdev = md_import_device(dev, -1, -1); |
| 2842 | |
| 2843 | if (IS_ERR(rdev)) |
| 2844 | return PTR_ERR(rdev); |
| 2845 | err = bind_rdev_to_array(rdev, mddev); |
| 2846 | out: |
| 2847 | if (err) |
| 2848 | export_rdev(rdev); |
| 2849 | return err ? err : len; |
| 2850 | } |
| 2851 | |
| 2852 | static struct md_sysfs_entry md_new_device = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2853 | __ATTR(new_dev, S_IWUSR, null_show, new_dev_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 2854 | |
| 2855 | static ssize_t |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 2856 | bitmap_store(mddev_t *mddev, const char *buf, size_t len) |
| 2857 | { |
| 2858 | char *end; |
| 2859 | unsigned long chunk, end_chunk; |
| 2860 | |
| 2861 | if (!mddev->bitmap) |
| 2862 | goto out; |
| 2863 | /* buf should be <chunk> <chunk> ... or <chunk>-<chunk> ... (range) */ |
| 2864 | while (*buf) { |
| 2865 | chunk = end_chunk = simple_strtoul(buf, &end, 0); |
| 2866 | if (buf == end) break; |
| 2867 | if (*end == '-') { /* range */ |
| 2868 | buf = end + 1; |
| 2869 | end_chunk = simple_strtoul(buf, &end, 0); |
| 2870 | if (buf == end) break; |
| 2871 | } |
| 2872 | if (*end && !isspace(*end)) break; |
| 2873 | bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk); |
| 2874 | buf = end; |
| 2875 | while (isspace(*buf)) buf++; |
| 2876 | } |
| 2877 | bitmap_unplug(mddev->bitmap); /* flush the bits to disk */ |
| 2878 | out: |
| 2879 | return len; |
| 2880 | } |
| 2881 | |
| 2882 | static struct md_sysfs_entry md_bitmap = |
| 2883 | __ATTR(bitmap_set_bits, S_IWUSR, null_show, bitmap_store); |
| 2884 | |
| 2885 | static ssize_t |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 2886 | size_show(mddev_t *mddev, char *page) |
| 2887 | { |
| 2888 | return sprintf(page, "%llu\n", (unsigned long long)mddev->size); |
| 2889 | } |
| 2890 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 2891 | static int update_size(mddev_t *mddev, sector_t num_sectors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 2892 | |
| 2893 | static ssize_t |
| 2894 | size_store(mddev_t *mddev, const char *buf, size_t len) |
| 2895 | { |
| 2896 | /* If array is inactive, we can reduce the component size, but |
| 2897 | * not increase it (except from 0). |
| 2898 | * If array is active, we can try an on-line resize |
| 2899 | */ |
| 2900 | char *e; |
| 2901 | int err = 0; |
| 2902 | unsigned long long size = simple_strtoull(buf, &e, 10); |
| 2903 | if (!*buf || *buf == '\n' || |
| 2904 | (*e && *e != '\n')) |
| 2905 | return -EINVAL; |
| 2906 | |
| 2907 | if (mddev->pers) { |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 2908 | err = update_size(mddev, size * 2); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2909 | md_update_sb(mddev, 1); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 2910 | } else { |
| 2911 | if (mddev->size == 0 || |
| 2912 | mddev->size > size) |
| 2913 | mddev->size = size; |
| 2914 | else |
| 2915 | err = -ENOSPC; |
| 2916 | } |
| 2917 | return err ? err : len; |
| 2918 | } |
| 2919 | |
| 2920 | static struct md_sysfs_entry md_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2921 | __ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 2922 | |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2923 | |
| 2924 | /* Metdata version. |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2925 | * This is one of |
| 2926 | * 'none' for arrays with no metadata (good luck...) |
| 2927 | * 'external' for arrays with externally managed metadata, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2928 | * or N.M for internally known formats |
| 2929 | */ |
| 2930 | static ssize_t |
| 2931 | metadata_show(mddev_t *mddev, char *page) |
| 2932 | { |
| 2933 | if (mddev->persistent) |
| 2934 | return sprintf(page, "%d.%d\n", |
| 2935 | mddev->major_version, mddev->minor_version); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2936 | else if (mddev->external) |
| 2937 | return sprintf(page, "external:%s\n", mddev->metadata_type); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2938 | else |
| 2939 | return sprintf(page, "none\n"); |
| 2940 | } |
| 2941 | |
| 2942 | static ssize_t |
| 2943 | metadata_store(mddev_t *mddev, const char *buf, size_t len) |
| 2944 | { |
| 2945 | int major, minor; |
| 2946 | char *e; |
| 2947 | if (!list_empty(&mddev->disks)) |
| 2948 | return -EBUSY; |
| 2949 | |
| 2950 | if (cmd_match(buf, "none")) { |
| 2951 | mddev->persistent = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2952 | mddev->external = 0; |
| 2953 | mddev->major_version = 0; |
| 2954 | mddev->minor_version = 90; |
| 2955 | return len; |
| 2956 | } |
| 2957 | if (strncmp(buf, "external:", 9) == 0) { |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2958 | size_t namelen = len-9; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2959 | if (namelen >= sizeof(mddev->metadata_type)) |
| 2960 | namelen = sizeof(mddev->metadata_type)-1; |
| 2961 | strncpy(mddev->metadata_type, buf+9, namelen); |
| 2962 | mddev->metadata_type[namelen] = 0; |
| 2963 | if (namelen && mddev->metadata_type[namelen-1] == '\n') |
| 2964 | mddev->metadata_type[--namelen] = 0; |
| 2965 | mddev->persistent = 0; |
| 2966 | mddev->external = 1; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2967 | mddev->major_version = 0; |
| 2968 | mddev->minor_version = 90; |
| 2969 | return len; |
| 2970 | } |
| 2971 | major = simple_strtoul(buf, &e, 10); |
| 2972 | if (e==buf || *e != '.') |
| 2973 | return -EINVAL; |
| 2974 | buf = e+1; |
| 2975 | minor = simple_strtoul(buf, &e, 10); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 2976 | if (e==buf || (*e && *e != '\n') ) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2977 | return -EINVAL; |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 2978 | if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2979 | return -ENOENT; |
| 2980 | mddev->major_version = major; |
| 2981 | mddev->minor_version = minor; |
| 2982 | mddev->persistent = 1; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2983 | mddev->external = 0; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2984 | return len; |
| 2985 | } |
| 2986 | |
| 2987 | static struct md_sysfs_entry md_metadata = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2988 | __ATTR(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 2989 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 2990 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2991 | action_show(mddev_t *mddev, char *page) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2992 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 2993 | char *type = "idle"; |
NeilBrown | 31399d9 | 2005-11-08 21:39:29 -0800 | [diff] [blame] | 2994 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
NeilBrown | 2b12ab6 | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 2995 | (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2996 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 2997 | type = "reshape"; |
| 2998 | else if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 2999 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 3000 | type = "resync"; |
| 3001 | else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 3002 | type = "check"; |
| 3003 | else |
| 3004 | type = "repair"; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3005 | } else if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3006 | type = "recover"; |
| 3007 | } |
| 3008 | return sprintf(page, "%s\n", type); |
| 3009 | } |
| 3010 | |
| 3011 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3012 | action_store(mddev_t *mddev, const char *page, size_t len) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3013 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3014 | if (!mddev->pers || !mddev->pers->sync_request) |
| 3015 | return -EINVAL; |
| 3016 | |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 3017 | if (cmd_match(page, "idle")) { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3018 | if (mddev->sync_thread) { |
| 3019 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 3020 | md_unregister_thread(mddev->sync_thread); |
| 3021 | mddev->sync_thread = NULL; |
| 3022 | mddev->recovery = 0; |
| 3023 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3024 | } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 3025 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3026 | return -EBUSY; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3027 | else if (cmd_match(page, "resync")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3028 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3029 | else if (cmd_match(page, "recover")) { |
| 3030 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
| 3031 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3032 | } else if (cmd_match(page, "reshape")) { |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3033 | int err; |
| 3034 | if (mddev->pers->start_reshape == NULL) |
| 3035 | return -EINVAL; |
| 3036 | err = mddev->pers->start_reshape(mddev); |
| 3037 | if (err) |
| 3038 | return err; |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 3039 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3040 | } else { |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 3041 | if (cmd_match(page, "check")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3042 | set_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
NeilBrown | 2adc7d4 | 2006-05-20 14:59:57 -0700 | [diff] [blame] | 3043 | else if (!cmd_match(page, "repair")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3044 | return -EINVAL; |
| 3045 | set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
| 3046 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3047 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3048 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3049 | md_wakeup_thread(mddev->thread); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3050 | sysfs_notify(&mddev->kobj, NULL, "sync_action"); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3051 | return len; |
| 3052 | } |
| 3053 | |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3054 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3055 | mismatch_cnt_show(mddev_t *mddev, char *page) |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3056 | { |
| 3057 | return sprintf(page, "%llu\n", |
| 3058 | (unsigned long long) mddev->resync_mismatches); |
| 3059 | } |
| 3060 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3061 | static struct md_sysfs_entry md_scan_mode = |
| 3062 | __ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3063 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3064 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3065 | static struct md_sysfs_entry md_mismatches = __ATTR_RO(mismatch_cnt); |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3066 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3067 | static ssize_t |
| 3068 | sync_min_show(mddev_t *mddev, char *page) |
| 3069 | { |
| 3070 | return sprintf(page, "%d (%s)\n", speed_min(mddev), |
| 3071 | mddev->sync_speed_min ? "local": "system"); |
| 3072 | } |
| 3073 | |
| 3074 | static ssize_t |
| 3075 | sync_min_store(mddev_t *mddev, const char *buf, size_t len) |
| 3076 | { |
| 3077 | int min; |
| 3078 | char *e; |
| 3079 | if (strncmp(buf, "system", 6)==0) { |
| 3080 | mddev->sync_speed_min = 0; |
| 3081 | return len; |
| 3082 | } |
| 3083 | min = simple_strtoul(buf, &e, 10); |
| 3084 | if (buf == e || (*e && *e != '\n') || min <= 0) |
| 3085 | return -EINVAL; |
| 3086 | mddev->sync_speed_min = min; |
| 3087 | return len; |
| 3088 | } |
| 3089 | |
| 3090 | static struct md_sysfs_entry md_sync_min = |
| 3091 | __ATTR(sync_speed_min, S_IRUGO|S_IWUSR, sync_min_show, sync_min_store); |
| 3092 | |
| 3093 | static ssize_t |
| 3094 | sync_max_show(mddev_t *mddev, char *page) |
| 3095 | { |
| 3096 | return sprintf(page, "%d (%s)\n", speed_max(mddev), |
| 3097 | mddev->sync_speed_max ? "local": "system"); |
| 3098 | } |
| 3099 | |
| 3100 | static ssize_t |
| 3101 | sync_max_store(mddev_t *mddev, const char *buf, size_t len) |
| 3102 | { |
| 3103 | int max; |
| 3104 | char *e; |
| 3105 | if (strncmp(buf, "system", 6)==0) { |
| 3106 | mddev->sync_speed_max = 0; |
| 3107 | return len; |
| 3108 | } |
| 3109 | max = simple_strtoul(buf, &e, 10); |
| 3110 | if (buf == e || (*e && *e != '\n') || max <= 0) |
| 3111 | return -EINVAL; |
| 3112 | mddev->sync_speed_max = max; |
| 3113 | return len; |
| 3114 | } |
| 3115 | |
| 3116 | static struct md_sysfs_entry md_sync_max = |
| 3117 | __ATTR(sync_speed_max, S_IRUGO|S_IWUSR, sync_max_show, sync_max_store); |
| 3118 | |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 3119 | static ssize_t |
| 3120 | degraded_show(mddev_t *mddev, char *page) |
| 3121 | { |
| 3122 | return sprintf(page, "%d\n", mddev->degraded); |
| 3123 | } |
| 3124 | static struct md_sysfs_entry md_degraded = __ATTR_RO(degraded); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3125 | |
| 3126 | static ssize_t |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 3127 | sync_force_parallel_show(mddev_t *mddev, char *page) |
| 3128 | { |
| 3129 | return sprintf(page, "%d\n", mddev->parallel_resync); |
| 3130 | } |
| 3131 | |
| 3132 | static ssize_t |
| 3133 | sync_force_parallel_store(mddev_t *mddev, const char *buf, size_t len) |
| 3134 | { |
| 3135 | long n; |
| 3136 | |
| 3137 | if (strict_strtol(buf, 10, &n)) |
| 3138 | return -EINVAL; |
| 3139 | |
| 3140 | if (n != 0 && n != 1) |
| 3141 | return -EINVAL; |
| 3142 | |
| 3143 | mddev->parallel_resync = n; |
| 3144 | |
| 3145 | if (mddev->sync_thread) |
| 3146 | wake_up(&resync_wait); |
| 3147 | |
| 3148 | return len; |
| 3149 | } |
| 3150 | |
| 3151 | /* force parallel resync, even with shared block devices */ |
| 3152 | static struct md_sysfs_entry md_sync_force_parallel = |
| 3153 | __ATTR(sync_force_parallel, S_IRUGO|S_IWUSR, |
| 3154 | sync_force_parallel_show, sync_force_parallel_store); |
| 3155 | |
| 3156 | static ssize_t |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3157 | sync_speed_show(mddev_t *mddev, char *page) |
| 3158 | { |
| 3159 | unsigned long resync, dt, db; |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3160 | resync = mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active); |
| 3161 | dt = (jiffies - mddev->resync_mark) / HZ; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3162 | if (!dt) dt++; |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3163 | db = resync - mddev->resync_mark_cnt; |
| 3164 | return sprintf(page, "%lu\n", db/dt/2); /* K/sec */ |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3165 | } |
| 3166 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3167 | static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3168 | |
| 3169 | static ssize_t |
| 3170 | sync_completed_show(mddev_t *mddev, char *page) |
| 3171 | { |
| 3172 | unsigned long max_blocks, resync; |
| 3173 | |
| 3174 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 3175 | max_blocks = mddev->resync_max_sectors; |
| 3176 | else |
| 3177 | max_blocks = mddev->size << 1; |
| 3178 | |
| 3179 | resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active)); |
| 3180 | return sprintf(page, "%lu / %lu\n", resync, max_blocks); |
| 3181 | } |
| 3182 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3183 | static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3184 | |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3185 | static ssize_t |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3186 | min_sync_show(mddev_t *mddev, char *page) |
| 3187 | { |
| 3188 | return sprintf(page, "%llu\n", |
| 3189 | (unsigned long long)mddev->resync_min); |
| 3190 | } |
| 3191 | static ssize_t |
| 3192 | min_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3193 | { |
| 3194 | unsigned long long min; |
| 3195 | if (strict_strtoull(buf, 10, &min)) |
| 3196 | return -EINVAL; |
| 3197 | if (min > mddev->resync_max) |
| 3198 | return -EINVAL; |
| 3199 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3200 | return -EBUSY; |
| 3201 | |
| 3202 | /* Must be a multiple of chunk_size */ |
| 3203 | if (mddev->chunk_size) { |
| 3204 | if (min & (sector_t)((mddev->chunk_size>>9)-1)) |
| 3205 | return -EINVAL; |
| 3206 | } |
| 3207 | mddev->resync_min = min; |
| 3208 | |
| 3209 | return len; |
| 3210 | } |
| 3211 | |
| 3212 | static struct md_sysfs_entry md_min_sync = |
| 3213 | __ATTR(sync_min, S_IRUGO|S_IWUSR, min_sync_show, min_sync_store); |
| 3214 | |
| 3215 | static ssize_t |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3216 | max_sync_show(mddev_t *mddev, char *page) |
| 3217 | { |
| 3218 | if (mddev->resync_max == MaxSector) |
| 3219 | return sprintf(page, "max\n"); |
| 3220 | else |
| 3221 | return sprintf(page, "%llu\n", |
| 3222 | (unsigned long long)mddev->resync_max); |
| 3223 | } |
| 3224 | static ssize_t |
| 3225 | max_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3226 | { |
| 3227 | if (strncmp(buf, "max", 3) == 0) |
| 3228 | mddev->resync_max = MaxSector; |
| 3229 | else { |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3230 | unsigned long long max; |
| 3231 | if (strict_strtoull(buf, 10, &max)) |
| 3232 | return -EINVAL; |
| 3233 | if (max < mddev->resync_min) |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3234 | return -EINVAL; |
| 3235 | if (max < mddev->resync_max && |
| 3236 | test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3237 | return -EBUSY; |
| 3238 | |
| 3239 | /* Must be a multiple of chunk_size */ |
| 3240 | if (mddev->chunk_size) { |
| 3241 | if (max & (sector_t)((mddev->chunk_size>>9)-1)) |
| 3242 | return -EINVAL; |
| 3243 | } |
| 3244 | mddev->resync_max = max; |
| 3245 | } |
| 3246 | wake_up(&mddev->recovery_wait); |
| 3247 | return len; |
| 3248 | } |
| 3249 | |
| 3250 | static struct md_sysfs_entry md_max_sync = |
| 3251 | __ATTR(sync_max, S_IRUGO|S_IWUSR, max_sync_show, max_sync_store); |
| 3252 | |
| 3253 | static ssize_t |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3254 | suspend_lo_show(mddev_t *mddev, char *page) |
| 3255 | { |
| 3256 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_lo); |
| 3257 | } |
| 3258 | |
| 3259 | static ssize_t |
| 3260 | suspend_lo_store(mddev_t *mddev, const char *buf, size_t len) |
| 3261 | { |
| 3262 | char *e; |
| 3263 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 3264 | |
| 3265 | if (mddev->pers->quiesce == NULL) |
| 3266 | return -EINVAL; |
| 3267 | if (buf == e || (*e && *e != '\n')) |
| 3268 | return -EINVAL; |
| 3269 | if (new >= mddev->suspend_hi || |
| 3270 | (new > mddev->suspend_lo && new < mddev->suspend_hi)) { |
| 3271 | mddev->suspend_lo = new; |
| 3272 | mddev->pers->quiesce(mddev, 2); |
| 3273 | return len; |
| 3274 | } else |
| 3275 | return -EINVAL; |
| 3276 | } |
| 3277 | static struct md_sysfs_entry md_suspend_lo = |
| 3278 | __ATTR(suspend_lo, S_IRUGO|S_IWUSR, suspend_lo_show, suspend_lo_store); |
| 3279 | |
| 3280 | |
| 3281 | static ssize_t |
| 3282 | suspend_hi_show(mddev_t *mddev, char *page) |
| 3283 | { |
| 3284 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_hi); |
| 3285 | } |
| 3286 | |
| 3287 | static ssize_t |
| 3288 | suspend_hi_store(mddev_t *mddev, const char *buf, size_t len) |
| 3289 | { |
| 3290 | char *e; |
| 3291 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 3292 | |
| 3293 | if (mddev->pers->quiesce == NULL) |
| 3294 | return -EINVAL; |
| 3295 | if (buf == e || (*e && *e != '\n')) |
| 3296 | return -EINVAL; |
| 3297 | if ((new <= mddev->suspend_lo && mddev->suspend_lo >= mddev->suspend_hi) || |
| 3298 | (new > mddev->suspend_lo && new > mddev->suspend_hi)) { |
| 3299 | mddev->suspend_hi = new; |
| 3300 | mddev->pers->quiesce(mddev, 1); |
| 3301 | mddev->pers->quiesce(mddev, 0); |
| 3302 | return len; |
| 3303 | } else |
| 3304 | return -EINVAL; |
| 3305 | } |
| 3306 | static struct md_sysfs_entry md_suspend_hi = |
| 3307 | __ATTR(suspend_hi, S_IRUGO|S_IWUSR, suspend_hi_show, suspend_hi_store); |
| 3308 | |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3309 | static ssize_t |
| 3310 | reshape_position_show(mddev_t *mddev, char *page) |
| 3311 | { |
| 3312 | if (mddev->reshape_position != MaxSector) |
| 3313 | return sprintf(page, "%llu\n", |
| 3314 | (unsigned long long)mddev->reshape_position); |
| 3315 | strcpy(page, "none\n"); |
| 3316 | return 5; |
| 3317 | } |
| 3318 | |
| 3319 | static ssize_t |
| 3320 | reshape_position_store(mddev_t *mddev, const char *buf, size_t len) |
| 3321 | { |
| 3322 | char *e; |
| 3323 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 3324 | if (mddev->pers) |
| 3325 | return -EBUSY; |
| 3326 | if (buf == e || (*e && *e != '\n')) |
| 3327 | return -EINVAL; |
| 3328 | mddev->reshape_position = new; |
| 3329 | mddev->delta_disks = 0; |
| 3330 | mddev->new_level = mddev->level; |
| 3331 | mddev->new_layout = mddev->layout; |
| 3332 | mddev->new_chunk = mddev->chunk_size; |
| 3333 | return len; |
| 3334 | } |
| 3335 | |
| 3336 | static struct md_sysfs_entry md_reshape_position = |
| 3337 | __ATTR(reshape_position, S_IRUGO|S_IWUSR, reshape_position_show, |
| 3338 | reshape_position_store); |
| 3339 | |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3340 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3341 | static struct attribute *md_default_attrs[] = { |
| 3342 | &md_level.attr, |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3343 | &md_layout.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3344 | &md_raid_disks.attr, |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3345 | &md_chunk_size.attr, |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3346 | &md_size.attr, |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3347 | &md_resync_start.attr, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3348 | &md_metadata.attr, |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3349 | &md_new_device.attr, |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 3350 | &md_safe_delay.attr, |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3351 | &md_array_state.attr, |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3352 | &md_reshape_position.attr, |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 3353 | NULL, |
| 3354 | }; |
| 3355 | |
| 3356 | static struct attribute *md_redundancy_attrs[] = { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3357 | &md_scan_mode.attr, |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3358 | &md_mismatches.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3359 | &md_sync_min.attr, |
| 3360 | &md_sync_max.attr, |
| 3361 | &md_sync_speed.attr, |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 3362 | &md_sync_force_parallel.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3363 | &md_sync_completed.attr, |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3364 | &md_min_sync.attr, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3365 | &md_max_sync.attr, |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3366 | &md_suspend_lo.attr, |
| 3367 | &md_suspend_hi.attr, |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 3368 | &md_bitmap.attr, |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 3369 | &md_degraded.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3370 | NULL, |
| 3371 | }; |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 3372 | static struct attribute_group md_redundancy_group = { |
| 3373 | .name = NULL, |
| 3374 | .attrs = md_redundancy_attrs, |
| 3375 | }; |
| 3376 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3377 | |
| 3378 | static ssize_t |
| 3379 | md_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 3380 | { |
| 3381 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 3382 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3383 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3384 | |
| 3385 | if (!entry->show) |
| 3386 | return -EIO; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 3387 | rv = mddev_lock(mddev); |
| 3388 | if (!rv) { |
| 3389 | rv = entry->show(mddev, page); |
| 3390 | mddev_unlock(mddev); |
| 3391 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3392 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3393 | } |
| 3394 | |
| 3395 | static ssize_t |
| 3396 | md_attr_store(struct kobject *kobj, struct attribute *attr, |
| 3397 | const char *page, size_t length) |
| 3398 | { |
| 3399 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 3400 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3401 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3402 | |
| 3403 | if (!entry->store) |
| 3404 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 3405 | if (!capable(CAP_SYS_ADMIN)) |
| 3406 | return -EACCES; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 3407 | rv = mddev_lock(mddev); |
| 3408 | if (!rv) { |
| 3409 | rv = entry->store(mddev, page, length); |
| 3410 | mddev_unlock(mddev); |
| 3411 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3412 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | static void md_free(struct kobject *ko) |
| 3416 | { |
| 3417 | mddev_t *mddev = container_of(ko, mddev_t, kobj); |
| 3418 | kfree(mddev); |
| 3419 | } |
| 3420 | |
| 3421 | static struct sysfs_ops md_sysfs_ops = { |
| 3422 | .show = md_attr_show, |
| 3423 | .store = md_attr_store, |
| 3424 | }; |
| 3425 | static struct kobj_type md_ktype = { |
| 3426 | .release = md_free, |
| 3427 | .sysfs_ops = &md_sysfs_ops, |
| 3428 | .default_attrs = md_default_attrs, |
| 3429 | }; |
| 3430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | int mdp_major = 0; |
| 3432 | |
| 3433 | static struct kobject *md_probe(dev_t dev, int *part, void *data) |
| 3434 | { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 3435 | static DEFINE_MUTEX(disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | mddev_t *mddev = mddev_find(dev); |
| 3437 | struct gendisk *disk; |
| 3438 | int partitioned = (MAJOR(dev) != MD_MAJOR); |
| 3439 | int shift = partitioned ? MdpMinorShift : 0; |
| 3440 | int unit = MINOR(dev) >> shift; |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 3441 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | |
| 3443 | if (!mddev) |
| 3444 | return NULL; |
| 3445 | |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 3446 | mutex_lock(&disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | if (mddev->gendisk) { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 3448 | mutex_unlock(&disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | mddev_put(mddev); |
| 3450 | return NULL; |
| 3451 | } |
| 3452 | disk = alloc_disk(1 << shift); |
| 3453 | if (!disk) { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 3454 | mutex_unlock(&disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | mddev_put(mddev); |
| 3456 | return NULL; |
| 3457 | } |
| 3458 | disk->major = MAJOR(dev); |
| 3459 | disk->first_minor = unit << shift; |
Greg Kroah-Hartman | ce7b0f4 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 3460 | if (partitioned) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | sprintf(disk->disk_name, "md_d%d", unit); |
Greg Kroah-Hartman | ce7b0f4 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 3462 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | sprintf(disk->disk_name, "md%d", unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | disk->fops = &md_fops; |
| 3465 | disk->private_data = mddev; |
| 3466 | disk->queue = mddev->queue; |
| 3467 | add_disk(disk); |
| 3468 | mddev->gendisk = disk; |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 3469 | 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] | 3470 | "%s", "md"); |
Neil Brown | f48ed53 | 2008-06-28 08:31:26 +1000 | [diff] [blame] | 3471 | mutex_unlock(&disks_mutex); |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 3472 | if (error) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 3473 | printk(KERN_WARNING "md: cannot register %s/md - name in use\n", |
| 3474 | disk->disk_name); |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 3475 | else |
| 3476 | kobject_uevent(&mddev->kobj, KOBJ_ADD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | return NULL; |
| 3478 | } |
| 3479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | static void md_safemode_timeout(unsigned long data) |
| 3481 | { |
| 3482 | mddev_t *mddev = (mddev_t *) data; |
| 3483 | |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3484 | if (!atomic_read(&mddev->writes_pending)) { |
| 3485 | mddev->safemode = 1; |
| 3486 | if (mddev->external) |
| 3487 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
| 3488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | md_wakeup_thread(mddev->thread); |
| 3490 | } |
| 3491 | |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 3492 | static int start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | |
| 3494 | static int do_md_run(mddev_t * mddev) |
| 3495 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3496 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | int chunk_size; |
| 3498 | struct list_head *tmp; |
| 3499 | mdk_rdev_t *rdev; |
| 3500 | struct gendisk *disk; |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3501 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | char b[BDEVNAME_SIZE]; |
| 3503 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 3504 | if (list_empty(&mddev->disks)) |
| 3505 | /* cannot run an array with no devices.. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | |
| 3508 | if (mddev->pers) |
| 3509 | return -EBUSY; |
| 3510 | |
| 3511 | /* |
| 3512 | * Analyze all RAID superblock(s) |
| 3513 | */ |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 3514 | if (!mddev->raid_disks) { |
| 3515 | if (!mddev->persistent) |
| 3516 | return -EINVAL; |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 3517 | analyze_sbs(mddev); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 3518 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | |
| 3520 | chunk_size = mddev->chunk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3522 | if (chunk_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | if (chunk_size > MAX_CHUNK_SIZE) { |
| 3524 | printk(KERN_ERR "too big chunk_size: %d > %d\n", |
| 3525 | chunk_size, MAX_CHUNK_SIZE); |
| 3526 | return -EINVAL; |
| 3527 | } |
| 3528 | /* |
| 3529 | * chunk-size has to be a power of 2 and multiples of PAGE_SIZE |
| 3530 | */ |
| 3531 | if ( (1 << ffz(~chunk_size)) != chunk_size) { |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 3532 | printk(KERN_ERR "chunk_size of %d not valid\n", chunk_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | return -EINVAL; |
| 3534 | } |
| 3535 | if (chunk_size < PAGE_SIZE) { |
| 3536 | printk(KERN_ERR "too small chunk_size: %d < %ld\n", |
| 3537 | chunk_size, PAGE_SIZE); |
| 3538 | return -EINVAL; |
| 3539 | } |
| 3540 | |
| 3541 | /* devices must have minimum size of one chunk */ |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 3542 | rdev_for_each(rdev, tmp, mddev) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3543 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | continue; |
| 3545 | if (rdev->size < chunk_size / 1024) { |
| 3546 | printk(KERN_WARNING |
| 3547 | "md: Dev %s smaller than chunk_size:" |
| 3548 | " %lluk < %dk\n", |
| 3549 | bdevname(rdev->bdev,b), |
| 3550 | (unsigned long long)rdev->size, |
| 3551 | chunk_size / 1024); |
| 3552 | return -EINVAL; |
| 3553 | } |
| 3554 | } |
| 3555 | } |
| 3556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | #ifdef CONFIG_KMOD |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3558 | if (mddev->level != LEVEL_NONE) |
| 3559 | request_module("md-level-%d", mddev->level); |
| 3560 | else if (mddev->clevel[0]) |
| 3561 | request_module("md-%s", mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | #endif |
| 3563 | |
| 3564 | /* |
| 3565 | * Drop all container device buffers, from now on |
| 3566 | * the only valid external interface is through the md |
| 3567 | * device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | */ |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 3569 | rdev_for_each(rdev, tmp, mddev) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3570 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | continue; |
| 3572 | sync_blockdev(rdev->bdev); |
Peter Zijlstra | f98393a | 2007-05-06 14:49:54 -0700 | [diff] [blame] | 3573 | invalidate_bdev(rdev->bdev); |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 3574 | |
| 3575 | /* perform some consistency tests on the device. |
| 3576 | * We don't want the data to overlap the metadata, |
| 3577 | * Internal Bitmap issues has handled elsewhere. |
| 3578 | */ |
| 3579 | if (rdev->data_offset < rdev->sb_offset) { |
| 3580 | if (mddev->size && |
| 3581 | rdev->data_offset + mddev->size*2 |
| 3582 | > rdev->sb_offset*2) { |
| 3583 | printk("md: %s: data overlaps metadata\n", |
| 3584 | mdname(mddev)); |
| 3585 | return -EINVAL; |
| 3586 | } |
| 3587 | } else { |
| 3588 | if (rdev->sb_offset*2 + rdev->sb_size/512 |
| 3589 | > rdev->data_offset) { |
| 3590 | printk("md: %s: metadata overlaps data\n", |
| 3591 | mdname(mddev)); |
| 3592 | return -EINVAL; |
| 3593 | } |
| 3594 | } |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 3595 | sysfs_notify(&rdev->kobj, NULL, "state"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | md_probe(mddev->unit, NULL, NULL); |
| 3599 | disk = mddev->gendisk; |
| 3600 | if (!disk) |
| 3601 | return -ENOMEM; |
| 3602 | |
| 3603 | spin_lock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3604 | pers = find_pers(mddev->level, mddev->clevel); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3605 | if (!pers || !try_module_get(pers->owner)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | spin_unlock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3607 | if (mddev->level != LEVEL_NONE) |
| 3608 | printk(KERN_WARNING "md: personality for level %d is not loaded!\n", |
| 3609 | mddev->level); |
| 3610 | else |
| 3611 | printk(KERN_WARNING "md: personality for level %s is not loaded!\n", |
| 3612 | mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | return -EINVAL; |
| 3614 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3615 | mddev->pers = pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | spin_unlock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3617 | mddev->level = pers->level; |
| 3618 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 3620 | if (mddev->reshape_position != MaxSector && |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3621 | pers->start_reshape == NULL) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 3622 | /* This personality cannot handle reshaping... */ |
| 3623 | mddev->pers = NULL; |
| 3624 | module_put(pers->owner); |
| 3625 | return -EINVAL; |
| 3626 | } |
| 3627 | |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 3628 | if (pers->sync_request) { |
| 3629 | /* Warn if this is a potentially silly |
| 3630 | * configuration. |
| 3631 | */ |
| 3632 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 3633 | mdk_rdev_t *rdev2; |
| 3634 | struct list_head *tmp2; |
| 3635 | int warned = 0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 3636 | rdev_for_each(rdev, tmp, mddev) { |
| 3637 | rdev_for_each(rdev2, tmp2, mddev) { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 3638 | if (rdev < rdev2 && |
| 3639 | rdev->bdev->bd_contains == |
| 3640 | rdev2->bdev->bd_contains) { |
| 3641 | printk(KERN_WARNING |
| 3642 | "%s: WARNING: %s appears to be" |
| 3643 | " on the same physical disk as" |
| 3644 | " %s.\n", |
| 3645 | mdname(mddev), |
| 3646 | bdevname(rdev->bdev,b), |
| 3647 | bdevname(rdev2->bdev,b2)); |
| 3648 | warned = 1; |
| 3649 | } |
| 3650 | } |
| 3651 | } |
| 3652 | if (warned) |
| 3653 | printk(KERN_WARNING |
| 3654 | "True protection against single-disk" |
| 3655 | " failure might be compromised.\n"); |
| 3656 | } |
| 3657 | |
NeilBrown | 657390d | 2005-08-26 18:34:16 -0700 | [diff] [blame] | 3658 | mddev->recovery = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | mddev->resync_max_sectors = mddev->size << 1; /* may be over-ridden by personality */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 3660 | mddev->barriers_work = 1; |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 3661 | mddev->ok_start_degraded = start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 3663 | if (start_readonly) |
| 3664 | mddev->ro = 2; /* read-only, but switch on first write */ |
| 3665 | |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 3666 | err = mddev->pers->run(mddev); |
Andre Noll | 13e53df | 2008-03-26 00:07:03 +0100 | [diff] [blame] | 3667 | if (err) |
| 3668 | printk(KERN_ERR "md: pers->run() failed ...\n"); |
| 3669 | else if (mddev->pers->sync_request) { |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 3670 | err = bitmap_create(mddev); |
| 3671 | if (err) { |
| 3672 | printk(KERN_ERR "%s: failed to create bitmap (%d)\n", |
| 3673 | mdname(mddev), err); |
| 3674 | mddev->pers->stop(mddev); |
| 3675 | } |
| 3676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | module_put(mddev->pers->owner); |
| 3679 | mddev->pers = NULL; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 3680 | bitmap_destroy(mddev); |
| 3681 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | } |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 3683 | if (mddev->pers->sync_request) { |
| 3684 | if (sysfs_create_group(&mddev->kobj, &md_redundancy_group)) |
| 3685 | printk(KERN_WARNING |
| 3686 | "md: cannot register extra attributes for %s\n", |
| 3687 | mdname(mddev)); |
| 3688 | } else if (mddev->ro == 2) /* auto-readonly not meaningful */ |
NeilBrown | fd9d49c | 2005-11-08 21:39:42 -0800 | [diff] [blame] | 3689 | mddev->ro = 0; |
| 3690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | atomic_set(&mddev->writes_pending,0); |
| 3692 | mddev->safemode = 0; |
| 3693 | mddev->safemode_timer.function = md_safemode_timeout; |
| 3694 | mddev->safemode_timer.data = (unsigned long) mddev; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 3695 | mddev->safemode_delay = (200 * HZ)/1000 +1; /* 200 msec delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | mddev->in_sync = 1; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 3697 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 3698 | rdev_for_each(rdev, tmp, mddev) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 3699 | if (rdev->raid_disk >= 0) { |
| 3700 | char nm[20]; |
| 3701 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 3702 | if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) |
| 3703 | printk("md: cannot register %s for %s\n", |
| 3704 | nm, mdname(mddev)); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 3705 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | |
| 3707 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3708 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 3709 | if (mddev->flags) |
| 3710 | md_update_sb(mddev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | |
| 3712 | set_capacity(disk, mddev->array_size<<1); |
| 3713 | |
| 3714 | /* If we call blk_queue_make_request here, it will |
| 3715 | * re-initialise max_sectors etc which may have been |
| 3716 | * refined inside -> run. So just set the bits we need to set. |
| 3717 | * Most initialisation happended when we called |
| 3718 | * blk_queue_make_request(..., md_fail_request) |
| 3719 | * earlier. |
| 3720 | */ |
| 3721 | mddev->queue->queuedata = mddev; |
| 3722 | mddev->queue->make_request_fn = mddev->pers->make_request; |
| 3723 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3724 | /* If there is a partially-recovered drive we need to |
| 3725 | * start recovery here. If we leave it to md_check_recovery, |
| 3726 | * it will remove the drives and not do the right thing |
| 3727 | */ |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 3728 | if (mddev->degraded && !mddev->sync_thread) { |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3729 | struct list_head *rtmp; |
| 3730 | int spares = 0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 3731 | rdev_for_each(rdev, rtmp, mddev) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3732 | if (rdev->raid_disk >= 0 && |
| 3733 | !test_bit(In_sync, &rdev->flags) && |
| 3734 | !test_bit(Faulty, &rdev->flags)) |
| 3735 | /* complete an interrupted recovery */ |
| 3736 | spares++; |
| 3737 | if (spares && mddev->pers->sync_request) { |
| 3738 | mddev->recovery = 0; |
| 3739 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 3740 | mddev->sync_thread = md_register_thread(md_do_sync, |
| 3741 | mddev, |
| 3742 | "%s_resync"); |
| 3743 | if (!mddev->sync_thread) { |
| 3744 | printk(KERN_ERR "%s: could not start resync" |
| 3745 | " thread...\n", |
| 3746 | mdname(mddev)); |
| 3747 | /* leave the spares where they are, it shouldn't hurt */ |
| 3748 | mddev->recovery = 0; |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 3749 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3750 | } |
| 3751 | } |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 3752 | md_wakeup_thread(mddev->thread); |
| 3753 | md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3754 | |
Linus Torvalds | 44ce6294 | 2007-05-09 18:51:36 -0700 | [diff] [blame] | 3755 | mddev->changed = 1; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 3756 | md_new_event(mddev); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3757 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3758 | sysfs_notify(&mddev->kobj, NULL, "sync_action"); |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 3759 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 3760 | kobject_uevent(&mddev->gendisk->dev.kobj, KOBJ_CHANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | return 0; |
| 3762 | } |
| 3763 | |
| 3764 | static int restart_array(mddev_t *mddev) |
| 3765 | { |
| 3766 | struct gendisk *disk = mddev->gendisk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 3768 | /* Complain if it has no devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | if (list_empty(&mddev->disks)) |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 3770 | return -ENXIO; |
| 3771 | if (!mddev->pers) |
| 3772 | return -EINVAL; |
| 3773 | if (!mddev->ro) |
| 3774 | return -EBUSY; |
| 3775 | mddev->safemode = 0; |
| 3776 | mddev->ro = 0; |
| 3777 | set_disk_ro(disk, 0); |
| 3778 | printk(KERN_INFO "md: %s switched to read-write mode.\n", |
| 3779 | mdname(mddev)); |
| 3780 | /* Kick recovery or resync if necessary */ |
| 3781 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3782 | md_wakeup_thread(mddev->thread); |
| 3783 | md_wakeup_thread(mddev->sync_thread); |
| 3784 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
| 3785 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | } |
| 3787 | |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 3788 | /* similar to deny_write_access, but accounts for our holding a reference |
| 3789 | * to the file ourselves */ |
| 3790 | static int deny_bitmap_write_access(struct file * file) |
| 3791 | { |
| 3792 | struct inode *inode = file->f_mapping->host; |
| 3793 | |
| 3794 | spin_lock(&inode->i_lock); |
| 3795 | if (atomic_read(&inode->i_writecount) > 1) { |
| 3796 | spin_unlock(&inode->i_lock); |
| 3797 | return -ETXTBSY; |
| 3798 | } |
| 3799 | atomic_set(&inode->i_writecount, -1); |
| 3800 | spin_unlock(&inode->i_lock); |
| 3801 | |
| 3802 | return 0; |
| 3803 | } |
| 3804 | |
| 3805 | static void restore_bitmap_write_access(struct file *file) |
| 3806 | { |
| 3807 | struct inode *inode = file->f_mapping->host; |
| 3808 | |
| 3809 | spin_lock(&inode->i_lock); |
| 3810 | atomic_set(&inode->i_writecount, 1); |
| 3811 | spin_unlock(&inode->i_lock); |
| 3812 | } |
| 3813 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3814 | /* mode: |
| 3815 | * 0 - completely stop and dis-assemble array |
| 3816 | * 1 - switch to readonly |
| 3817 | * 2 - stop but do not disassemble array |
| 3818 | */ |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3819 | static int do_md_stop(mddev_t * mddev, int mode, int is_open) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | { |
| 3821 | int err = 0; |
| 3822 | struct gendisk *disk = mddev->gendisk; |
| 3823 | |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3824 | if (atomic_read(&mddev->active) > 1 + is_open) { |
| 3825 | printk("md: %s still in use.\n",mdname(mddev)); |
| 3826 | return -EBUSY; |
| 3827 | } |
| 3828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | if (mddev->pers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | |
| 3831 | if (mddev->sync_thread) { |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3832 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 3834 | md_unregister_thread(mddev->sync_thread); |
| 3835 | mddev->sync_thread = NULL; |
| 3836 | } |
| 3837 | |
| 3838 | del_timer_sync(&mddev->safemode_timer); |
| 3839 | |
| 3840 | invalidate_partition(disk, 0); |
| 3841 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3842 | switch(mode) { |
| 3843 | case 1: /* readonly */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | err = -ENXIO; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 3845 | if (mddev->ro==1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | goto out; |
| 3847 | mddev->ro = 1; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3848 | break; |
| 3849 | case 0: /* disassemble */ |
| 3850 | case 2: /* stop */ |
NeilBrown | 6b8b3e8 | 2005-08-04 12:53:35 -0700 | [diff] [blame] | 3851 | bitmap_flush(mddev); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 3852 | md_super_wait(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3853 | if (mddev->ro) |
| 3854 | set_disk_ro(disk, 0); |
| 3855 | blk_queue_make_request(mddev->queue, md_fail_request); |
| 3856 | mddev->pers->stop(mddev); |
NeilBrown | d1b5380 | 2007-02-28 20:11:42 -0800 | [diff] [blame] | 3857 | mddev->queue->merge_bvec_fn = NULL; |
| 3858 | mddev->queue->unplug_fn = NULL; |
NeilBrown | 041ae52 | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 3859 | mddev->queue->backing_dev_info.congested_fn = NULL; |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 3860 | if (mddev->pers->sync_request) |
| 3861 | sysfs_remove_group(&mddev->kobj, &md_redundancy_group); |
| 3862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | module_put(mddev->pers->owner); |
| 3864 | mddev->pers = NULL; |
Dan Williams | 4f54b0e | 2008-05-23 13:04:37 -0700 | [diff] [blame] | 3865 | /* tell userspace to handle 'inactive' */ |
| 3866 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 3867 | |
| 3868 | set_capacity(disk, 0); |
Linus Torvalds | 44ce6294 | 2007-05-09 18:51:36 -0700 | [diff] [blame] | 3869 | mddev->changed = 1; |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 3870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | if (mddev->ro) |
| 3872 | mddev->ro = 0; |
| 3873 | } |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 3874 | if (!mddev->in_sync || mddev->flags) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | /* mark array as shutdown cleanly */ |
| 3876 | mddev->in_sync = 1; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 3877 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3879 | if (mode == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | set_disk_ro(disk, 1); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3881 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 3883 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | /* |
| 3885 | * Free resources if final stop |
| 3886 | */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3887 | if (mode == 0) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 3888 | mdk_rdev_t *rdev; |
| 3889 | struct list_head *tmp; |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 3890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); |
| 3892 | |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 3893 | bitmap_destroy(mddev); |
| 3894 | if (mddev->bitmap_file) { |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 3895 | restore_bitmap_write_access(mddev->bitmap_file); |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 3896 | fput(mddev->bitmap_file); |
| 3897 | mddev->bitmap_file = NULL; |
| 3898 | } |
| 3899 | mddev->bitmap_offset = 0; |
| 3900 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 3901 | rdev_for_each(rdev, tmp, mddev) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 3902 | if (rdev->raid_disk >= 0) { |
| 3903 | char nm[20]; |
| 3904 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 3905 | sysfs_remove_link(&mddev->kobj, nm); |
| 3906 | } |
| 3907 | |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 3908 | /* make sure all md_delayed_delete calls have finished */ |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 3909 | flush_scheduled_work(); |
| 3910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | export_array(mddev); |
| 3912 | |
| 3913 | mddev->array_size = 0; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3914 | mddev->size = 0; |
| 3915 | mddev->raid_disks = 0; |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3916 | mddev->recovery_cp = 0; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3917 | mddev->resync_min = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3918 | mddev->resync_max = MaxSector; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3919 | mddev->reshape_position = MaxSector; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3920 | mddev->external = 0; |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 3921 | mddev->persistent = 0; |
NeilBrown | d897dbf | 2008-04-30 00:52:29 -0700 | [diff] [blame] | 3922 | mddev->level = LEVEL_NONE; |
| 3923 | mddev->clevel[0] = 0; |
| 3924 | mddev->flags = 0; |
| 3925 | mddev->ro = 0; |
| 3926 | mddev->metadata_type[0] = 0; |
| 3927 | mddev->chunk_size = 0; |
| 3928 | mddev->ctime = mddev->utime = 0; |
| 3929 | mddev->layout = 0; |
| 3930 | mddev->max_disks = 0; |
| 3931 | mddev->events = 0; |
| 3932 | mddev->delta_disks = 0; |
| 3933 | mddev->new_level = LEVEL_NONE; |
| 3934 | mddev->new_layout = 0; |
| 3935 | mddev->new_chunk = 0; |
| 3936 | mddev->curr_resync = 0; |
| 3937 | mddev->resync_mismatches = 0; |
| 3938 | mddev->suspend_lo = mddev->suspend_hi = 0; |
| 3939 | mddev->sync_speed_min = mddev->sync_speed_max = 0; |
| 3940 | mddev->recovery = 0; |
| 3941 | mddev->in_sync = 0; |
| 3942 | mddev->changed = 0; |
| 3943 | mddev->degraded = 0; |
| 3944 | mddev->barriers_work = 0; |
| 3945 | mddev->safemode = 0; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3946 | |
NeilBrown | a8a55c3 | 2006-06-26 00:27:39 -0700 | [diff] [blame] | 3947 | } else if (mddev->pers) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | printk(KERN_INFO "md: %s switched to read-only mode.\n", |
| 3949 | mdname(mddev)); |
| 3950 | err = 0; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 3951 | md_new_event(mddev); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3952 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | out: |
| 3954 | return err; |
| 3955 | } |
| 3956 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 3957 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | static void autorun_array(mddev_t *mddev) |
| 3959 | { |
| 3960 | mdk_rdev_t *rdev; |
| 3961 | struct list_head *tmp; |
| 3962 | int err; |
| 3963 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 3964 | if (list_empty(&mddev->disks)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | |
| 3967 | printk(KERN_INFO "md: running: "); |
| 3968 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 3969 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | char b[BDEVNAME_SIZE]; |
| 3971 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 3972 | } |
| 3973 | printk("\n"); |
| 3974 | |
| 3975 | err = do_md_run (mddev); |
| 3976 | if (err) { |
| 3977 | printk(KERN_WARNING "md: do_md_run() returned %d\n", err); |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3978 | do_md_stop (mddev, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3979 | } |
| 3980 | } |
| 3981 | |
| 3982 | /* |
| 3983 | * lets try to run arrays based on all disks that have arrived |
| 3984 | * until now. (those are in pending_raid_disks) |
| 3985 | * |
| 3986 | * the method: pick the first pending disk, collect all disks with |
| 3987 | * the same UUID, remove all from the pending list and put them into |
| 3988 | * the 'same_array' list. Then order this list based on superblock |
| 3989 | * update time (freshest comes first), kick out 'old' disks and |
| 3990 | * compare superblocks. If everything's fine then run it. |
| 3991 | * |
| 3992 | * If "unit" is allocated, then bump its reference count |
| 3993 | */ |
| 3994 | static void autorun_devices(int part) |
| 3995 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | struct list_head *tmp; |
| 3997 | mdk_rdev_t *rdev0, *rdev; |
| 3998 | mddev_t *mddev; |
| 3999 | char b[BDEVNAME_SIZE]; |
| 4000 | |
| 4001 | printk(KERN_INFO "md: autorun ...\n"); |
| 4002 | while (!list_empty(&pending_raid_disks)) { |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4003 | int unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | dev_t dev; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 4005 | LIST_HEAD(candidates); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | rdev0 = list_entry(pending_raid_disks.next, |
| 4007 | mdk_rdev_t, same_set); |
| 4008 | |
| 4009 | printk(KERN_INFO "md: considering %s ...\n", |
| 4010 | bdevname(rdev0->bdev,b)); |
| 4011 | INIT_LIST_HEAD(&candidates); |
NeilBrown | 73c3443 | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 4012 | rdev_for_each_list(rdev, tmp, pending_raid_disks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | if (super_90_load(rdev, rdev0, 0) >= 0) { |
| 4014 | printk(KERN_INFO "md: adding %s ...\n", |
| 4015 | bdevname(rdev->bdev,b)); |
| 4016 | list_move(&rdev->same_set, &candidates); |
| 4017 | } |
| 4018 | /* |
| 4019 | * now we have a set of devices, with all of them having |
| 4020 | * mostly sane superblocks. It's time to allocate the |
| 4021 | * mddev. |
| 4022 | */ |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4023 | if (part) { |
| 4024 | dev = MKDEV(mdp_major, |
| 4025 | rdev0->preferred_minor << MdpMinorShift); |
| 4026 | unit = MINOR(dev) >> MdpMinorShift; |
| 4027 | } else { |
| 4028 | dev = MKDEV(MD_MAJOR, rdev0->preferred_minor); |
| 4029 | unit = MINOR(dev); |
| 4030 | } |
| 4031 | if (rdev0->preferred_minor != unit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | printk(KERN_INFO "md: unit number in %s is bad: %d\n", |
| 4033 | bdevname(rdev0->bdev, b), rdev0->preferred_minor); |
| 4034 | break; |
| 4035 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | |
| 4037 | md_probe(dev, NULL, NULL); |
| 4038 | mddev = mddev_find(dev); |
Neil Brown | 9bbbca3 | 2008-06-28 08:31:17 +1000 | [diff] [blame] | 4039 | if (!mddev || !mddev->gendisk) { |
| 4040 | if (mddev) |
| 4041 | mddev_put(mddev); |
| 4042 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | "md: cannot allocate memory for md drive.\n"); |
| 4044 | break; |
| 4045 | } |
| 4046 | if (mddev_lock(mddev)) |
| 4047 | printk(KERN_WARNING "md: %s locked, cannot run\n", |
| 4048 | mdname(mddev)); |
| 4049 | else if (mddev->raid_disks || mddev->major_version |
| 4050 | || !list_empty(&mddev->disks)) { |
| 4051 | printk(KERN_WARNING |
| 4052 | "md: %s already running, cannot run %s\n", |
| 4053 | mdname(mddev), bdevname(rdev0->bdev,b)); |
| 4054 | mddev_unlock(mddev); |
| 4055 | } else { |
| 4056 | printk(KERN_INFO "md: created %s\n", mdname(mddev)); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4057 | mddev->persistent = 1; |
NeilBrown | 73c3443 | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 4058 | rdev_for_each_list(rdev, tmp, candidates) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | list_del_init(&rdev->same_set); |
| 4060 | if (bind_rdev_to_array(rdev, mddev)) |
| 4061 | export_rdev(rdev); |
| 4062 | } |
| 4063 | autorun_array(mddev); |
| 4064 | mddev_unlock(mddev); |
| 4065 | } |
| 4066 | /* on success, candidates will be empty, on error |
| 4067 | * it won't... |
| 4068 | */ |
NeilBrown | 73c3443 | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 4069 | rdev_for_each_list(rdev, tmp, candidates) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | export_rdev(rdev); |
| 4071 | mddev_put(mddev); |
| 4072 | } |
| 4073 | printk(KERN_INFO "md: ... autorun DONE.\n"); |
| 4074 | } |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 4075 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | static int get_version(void __user * arg) |
| 4078 | { |
| 4079 | mdu_version_t ver; |
| 4080 | |
| 4081 | ver.major = MD_MAJOR_VERSION; |
| 4082 | ver.minor = MD_MINOR_VERSION; |
| 4083 | ver.patchlevel = MD_PATCHLEVEL_VERSION; |
| 4084 | |
| 4085 | if (copy_to_user(arg, &ver, sizeof(ver))) |
| 4086 | return -EFAULT; |
| 4087 | |
| 4088 | return 0; |
| 4089 | } |
| 4090 | |
| 4091 | static int get_array_info(mddev_t * mddev, void __user * arg) |
| 4092 | { |
| 4093 | mdu_array_info_t info; |
| 4094 | int nr,working,active,failed,spare; |
| 4095 | mdk_rdev_t *rdev; |
| 4096 | struct list_head *tmp; |
| 4097 | |
| 4098 | nr=working=active=failed=spare=0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 4099 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | nr++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4101 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | failed++; |
| 4103 | else { |
| 4104 | working++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4105 | if (test_bit(In_sync, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | active++; |
| 4107 | else |
| 4108 | spare++; |
| 4109 | } |
| 4110 | } |
| 4111 | |
| 4112 | info.major_version = mddev->major_version; |
| 4113 | info.minor_version = mddev->minor_version; |
| 4114 | info.patch_version = MD_PATCHLEVEL_VERSION; |
| 4115 | info.ctime = mddev->ctime; |
| 4116 | info.level = mddev->level; |
| 4117 | info.size = mddev->size; |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 4118 | if (info.size != mddev->size) /* overflow */ |
| 4119 | info.size = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | info.nr_disks = nr; |
| 4121 | info.raid_disks = mddev->raid_disks; |
| 4122 | info.md_minor = mddev->md_minor; |
| 4123 | info.not_persistent= !mddev->persistent; |
| 4124 | |
| 4125 | info.utime = mddev->utime; |
| 4126 | info.state = 0; |
| 4127 | if (mddev->in_sync) |
| 4128 | info.state = (1<<MD_SB_CLEAN); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4129 | if (mddev->bitmap && mddev->bitmap_offset) |
| 4130 | info.state = (1<<MD_SB_BITMAP_PRESENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | info.active_disks = active; |
| 4132 | info.working_disks = working; |
| 4133 | info.failed_disks = failed; |
| 4134 | info.spare_disks = spare; |
| 4135 | |
| 4136 | info.layout = mddev->layout; |
| 4137 | info.chunk_size = mddev->chunk_size; |
| 4138 | |
| 4139 | if (copy_to_user(arg, &info, sizeof(info))) |
| 4140 | return -EFAULT; |
| 4141 | |
| 4142 | return 0; |
| 4143 | } |
| 4144 | |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 4145 | static int get_bitmap_file(mddev_t * mddev, void __user * arg) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4146 | { |
| 4147 | mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ |
| 4148 | char *ptr, *buf = NULL; |
| 4149 | int err = -ENOMEM; |
| 4150 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4151 | if (md_allow_write(mddev)) |
| 4152 | file = kmalloc(sizeof(*file), GFP_NOIO); |
| 4153 | else |
| 4154 | file = kmalloc(sizeof(*file), GFP_KERNEL); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 4155 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4156 | if (!file) |
| 4157 | goto out; |
| 4158 | |
| 4159 | /* bitmap disabled, zero the first byte and copy out */ |
| 4160 | if (!mddev->bitmap || !mddev->bitmap->file) { |
| 4161 | file->pathname[0] = '\0'; |
| 4162 | goto copy_out; |
| 4163 | } |
| 4164 | |
| 4165 | buf = kmalloc(sizeof(file->pathname), GFP_KERNEL); |
| 4166 | if (!buf) |
| 4167 | goto out; |
| 4168 | |
Christoph Hellwig | 6bcfd60 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 4169 | ptr = d_path(&mddev->bitmap->file->f_path, buf, sizeof(file->pathname)); |
| 4170 | if (IS_ERR(ptr)) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4171 | goto out; |
| 4172 | |
| 4173 | strcpy(file->pathname, ptr); |
| 4174 | |
| 4175 | copy_out: |
| 4176 | err = 0; |
| 4177 | if (copy_to_user(arg, file, sizeof(*file))) |
| 4178 | err = -EFAULT; |
| 4179 | out: |
| 4180 | kfree(buf); |
| 4181 | kfree(file); |
| 4182 | return err; |
| 4183 | } |
| 4184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | static int get_disk_info(mddev_t * mddev, void __user * arg) |
| 4186 | { |
| 4187 | mdu_disk_info_t info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | mdk_rdev_t *rdev; |
| 4189 | |
| 4190 | if (copy_from_user(&info, arg, sizeof(info))) |
| 4191 | return -EFAULT; |
| 4192 | |
Andre Noll | 26ef379 | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4193 | rdev = find_rdev_nr(mddev, info.number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | if (rdev) { |
| 4195 | info.major = MAJOR(rdev->bdev->bd_dev); |
| 4196 | info.minor = MINOR(rdev->bdev->bd_dev); |
| 4197 | info.raid_disk = rdev->raid_disk; |
| 4198 | info.state = 0; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4199 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | info.state |= (1<<MD_DISK_FAULTY); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4201 | else if (test_bit(In_sync, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | info.state |= (1<<MD_DISK_ACTIVE); |
| 4203 | info.state |= (1<<MD_DISK_SYNC); |
| 4204 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4205 | if (test_bit(WriteMostly, &rdev->flags)) |
| 4206 | info.state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | } else { |
| 4208 | info.major = info.minor = 0; |
| 4209 | info.raid_disk = -1; |
| 4210 | info.state = (1<<MD_DISK_REMOVED); |
| 4211 | } |
| 4212 | |
| 4213 | if (copy_to_user(arg, &info, sizeof(info))) |
| 4214 | return -EFAULT; |
| 4215 | |
| 4216 | return 0; |
| 4217 | } |
| 4218 | |
| 4219 | static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) |
| 4220 | { |
| 4221 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 4222 | mdk_rdev_t *rdev; |
| 4223 | dev_t dev = MKDEV(info->major,info->minor); |
| 4224 | |
| 4225 | if (info->major != MAJOR(dev) || info->minor != MINOR(dev)) |
| 4226 | return -EOVERFLOW; |
| 4227 | |
| 4228 | if (!mddev->raid_disks) { |
| 4229 | int err; |
| 4230 | /* expecting a device which has a superblock */ |
| 4231 | rdev = md_import_device(dev, mddev->major_version, mddev->minor_version); |
| 4232 | if (IS_ERR(rdev)) { |
| 4233 | printk(KERN_WARNING |
| 4234 | "md: md_import_device returned %ld\n", |
| 4235 | PTR_ERR(rdev)); |
| 4236 | return PTR_ERR(rdev); |
| 4237 | } |
| 4238 | if (!list_empty(&mddev->disks)) { |
| 4239 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 4240 | mdk_rdev_t, same_set); |
| 4241 | int err = super_types[mddev->major_version] |
| 4242 | .load_super(rdev, rdev0, mddev->minor_version); |
| 4243 | if (err < 0) { |
| 4244 | printk(KERN_WARNING |
| 4245 | "md: %s has different UUID to %s\n", |
| 4246 | bdevname(rdev->bdev,b), |
| 4247 | bdevname(rdev0->bdev,b2)); |
| 4248 | export_rdev(rdev); |
| 4249 | return -EINVAL; |
| 4250 | } |
| 4251 | } |
| 4252 | err = bind_rdev_to_array(rdev, mddev); |
| 4253 | if (err) |
| 4254 | export_rdev(rdev); |
| 4255 | return err; |
| 4256 | } |
| 4257 | |
| 4258 | /* |
| 4259 | * add_new_disk can be used once the array is assembled |
| 4260 | * to add "hot spares". They must already have a superblock |
| 4261 | * written |
| 4262 | */ |
| 4263 | if (mddev->pers) { |
| 4264 | int err; |
| 4265 | if (!mddev->pers->hot_add_disk) { |
| 4266 | printk(KERN_WARNING |
| 4267 | "%s: personality does not support diskops!\n", |
| 4268 | mdname(mddev)); |
| 4269 | return -EINVAL; |
| 4270 | } |
NeilBrown | 7b1e35f | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 4271 | if (mddev->persistent) |
| 4272 | rdev = md_import_device(dev, mddev->major_version, |
| 4273 | mddev->minor_version); |
| 4274 | else |
| 4275 | rdev = md_import_device(dev, -1, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | if (IS_ERR(rdev)) { |
| 4277 | printk(KERN_WARNING |
| 4278 | "md: md_import_device returned %ld\n", |
| 4279 | PTR_ERR(rdev)); |
| 4280 | return PTR_ERR(rdev); |
| 4281 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 4282 | /* set save_raid_disk if appropriate */ |
| 4283 | if (!mddev->persistent) { |
| 4284 | if (info->state & (1<<MD_DISK_SYNC) && |
| 4285 | info->raid_disk < mddev->raid_disks) |
| 4286 | rdev->raid_disk = info->raid_disk; |
| 4287 | else |
| 4288 | rdev->raid_disk = -1; |
| 4289 | } else |
| 4290 | super_types[mddev->major_version]. |
| 4291 | validate_super(mddev, rdev); |
| 4292 | rdev->saved_raid_disk = rdev->raid_disk; |
| 4293 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4294 | clear_bit(In_sync, &rdev->flags); /* just to be sure */ |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4295 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 4296 | set_bit(WriteMostly, &rdev->flags); |
| 4297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | rdev->raid_disk = -1; |
| 4299 | err = bind_rdev_to_array(rdev, mddev); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 4300 | if (!err && !mddev->pers->hot_remove_disk) { |
| 4301 | /* If there is hot_add_disk but no hot_remove_disk |
| 4302 | * then added disks for geometry changes, |
| 4303 | * and should be added immediately. |
| 4304 | */ |
| 4305 | super_types[mddev->major_version]. |
| 4306 | validate_super(mddev, rdev); |
| 4307 | err = mddev->pers->hot_add_disk(mddev, rdev); |
| 4308 | if (err) |
| 4309 | unbind_rdev_from_array(rdev); |
| 4310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | if (err) |
| 4312 | export_rdev(rdev); |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 4313 | else |
| 4314 | sysfs_notify(&rdev->kobj, NULL, "state"); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 4315 | |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 4316 | md_update_sb(mddev, 1); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 4317 | if (mddev->degraded) |
| 4318 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 4319 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 4320 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | return err; |
| 4322 | } |
| 4323 | |
| 4324 | /* otherwise, add_new_disk is only allowed |
| 4325 | * for major_version==0 superblocks |
| 4326 | */ |
| 4327 | if (mddev->major_version != 0) { |
| 4328 | printk(KERN_WARNING "%s: ADD_NEW_DISK not supported\n", |
| 4329 | mdname(mddev)); |
| 4330 | return -EINVAL; |
| 4331 | } |
| 4332 | |
| 4333 | if (!(info->state & (1<<MD_DISK_FAULTY))) { |
| 4334 | int err; |
| 4335 | rdev = md_import_device (dev, -1, 0); |
| 4336 | if (IS_ERR(rdev)) { |
| 4337 | printk(KERN_WARNING |
| 4338 | "md: error, md_import_device() returned %ld\n", |
| 4339 | PTR_ERR(rdev)); |
| 4340 | return PTR_ERR(rdev); |
| 4341 | } |
| 4342 | rdev->desc_nr = info->number; |
| 4343 | if (info->raid_disk < mddev->raid_disks) |
| 4344 | rdev->raid_disk = info->raid_disk; |
| 4345 | else |
| 4346 | rdev->raid_disk = -1; |
| 4347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | if (rdev->raid_disk < mddev->raid_disks) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4349 | if (info->state & (1<<MD_DISK_SYNC)) |
| 4350 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4352 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 4353 | set_bit(WriteMostly, &rdev->flags); |
| 4354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | if (!mddev->persistent) { |
| 4356 | printk(KERN_INFO "md: nonpersistent superblock ...\n"); |
| 4357 | rdev->sb_offset = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 4358 | } else |
| 4359 | rdev->sb_offset = calc_dev_sboffset(rdev->bdev); |
Andre Noll | e7debaa | 2008-07-11 22:02:23 +1000 | [diff] [blame^] | 4360 | rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 4362 | err = bind_rdev_to_array(rdev, mddev); |
| 4363 | if (err) { |
| 4364 | export_rdev(rdev); |
| 4365 | return err; |
| 4366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | return 0; |
| 4370 | } |
| 4371 | |
| 4372 | static int hot_remove_disk(mddev_t * mddev, dev_t dev) |
| 4373 | { |
| 4374 | char b[BDEVNAME_SIZE]; |
| 4375 | mdk_rdev_t *rdev; |
| 4376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | rdev = find_rdev(mddev, dev); |
| 4378 | if (!rdev) |
| 4379 | return -ENXIO; |
| 4380 | |
| 4381 | if (rdev->raid_disk >= 0) |
| 4382 | goto busy; |
| 4383 | |
| 4384 | kick_rdev_from_array(rdev); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4385 | md_update_sb(mddev, 1); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4386 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | |
| 4388 | return 0; |
| 4389 | busy: |
Nick Andrew | fdefa4d | 2008-04-21 22:42:58 +0000 | [diff] [blame] | 4390 | printk(KERN_WARNING "md: cannot remove active disk %s from %s ...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 4392 | return -EBUSY; |
| 4393 | } |
| 4394 | |
| 4395 | static int hot_add_disk(mddev_t * mddev, dev_t dev) |
| 4396 | { |
| 4397 | char b[BDEVNAME_SIZE]; |
| 4398 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | mdk_rdev_t *rdev; |
| 4400 | |
| 4401 | if (!mddev->pers) |
| 4402 | return -ENODEV; |
| 4403 | |
| 4404 | if (mddev->major_version != 0) { |
| 4405 | printk(KERN_WARNING "%s: HOT_ADD may only be used with" |
| 4406 | " version-0 superblocks.\n", |
| 4407 | mdname(mddev)); |
| 4408 | return -EINVAL; |
| 4409 | } |
| 4410 | if (!mddev->pers->hot_add_disk) { |
| 4411 | printk(KERN_WARNING |
| 4412 | "%s: personality does not support diskops!\n", |
| 4413 | mdname(mddev)); |
| 4414 | return -EINVAL; |
| 4415 | } |
| 4416 | |
| 4417 | rdev = md_import_device (dev, -1, 0); |
| 4418 | if (IS_ERR(rdev)) { |
| 4419 | printk(KERN_WARNING |
| 4420 | "md: error, md_import_device() returned %ld\n", |
| 4421 | PTR_ERR(rdev)); |
| 4422 | return -EINVAL; |
| 4423 | } |
| 4424 | |
| 4425 | if (mddev->persistent) |
| 4426 | rdev->sb_offset = calc_dev_sboffset(rdev->bdev); |
| 4427 | else |
| 4428 | rdev->sb_offset = |
| 4429 | rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 4430 | |
Andre Noll | e7debaa | 2008-07-11 22:02:23 +1000 | [diff] [blame^] | 4431 | rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4433 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | printk(KERN_WARNING |
| 4435 | "md: can not hot-add faulty %s disk to %s!\n", |
| 4436 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 4437 | err = -EINVAL; |
| 4438 | goto abort_export; |
| 4439 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4440 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | rdev->desc_nr = -1; |
NeilBrown | 5842730 | 2006-10-06 00:44:04 -0700 | [diff] [blame] | 4442 | rdev->saved_raid_disk = -1; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 4443 | err = bind_rdev_to_array(rdev, mddev); |
| 4444 | if (err) |
| 4445 | goto abort_export; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4446 | |
| 4447 | /* |
| 4448 | * The rest should better be atomic, we can have disk failures |
| 4449 | * noticed in interrupt contexts ... |
| 4450 | */ |
| 4451 | |
| 4452 | if (rdev->desc_nr == mddev->max_disks) { |
| 4453 | printk(KERN_WARNING "%s: can not hot-add to full array!\n", |
| 4454 | mdname(mddev)); |
| 4455 | err = -EBUSY; |
| 4456 | goto abort_unbind_export; |
| 4457 | } |
| 4458 | |
| 4459 | rdev->raid_disk = -1; |
| 4460 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4461 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | |
| 4463 | /* |
| 4464 | * Kick recovery, maybe this spare has to be added to the |
| 4465 | * array immediately. |
| 4466 | */ |
| 4467 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4468 | md_wakeup_thread(mddev->thread); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4469 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | return 0; |
| 4471 | |
| 4472 | abort_unbind_export: |
| 4473 | unbind_rdev_from_array(rdev); |
| 4474 | |
| 4475 | abort_export: |
| 4476 | export_rdev(rdev); |
| 4477 | return err; |
| 4478 | } |
| 4479 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4480 | static int set_bitmap_file(mddev_t *mddev, int fd) |
| 4481 | { |
| 4482 | int err; |
| 4483 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4484 | if (mddev->pers) { |
| 4485 | if (!mddev->pers->quiesce) |
| 4486 | return -EBUSY; |
| 4487 | if (mddev->recovery || mddev->sync_thread) |
| 4488 | return -EBUSY; |
| 4489 | /* we should be able to change the bitmap.. */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4492 | |
| 4493 | if (fd >= 0) { |
| 4494 | if (mddev->bitmap) |
| 4495 | return -EEXIST; /* cannot add when bitmap is present */ |
| 4496 | mddev->bitmap_file = fget(fd); |
| 4497 | |
| 4498 | if (mddev->bitmap_file == NULL) { |
| 4499 | printk(KERN_ERR "%s: error: failed to get bitmap file\n", |
| 4500 | mdname(mddev)); |
| 4501 | return -EBADF; |
| 4502 | } |
| 4503 | |
| 4504 | err = deny_bitmap_write_access(mddev->bitmap_file); |
| 4505 | if (err) { |
| 4506 | printk(KERN_ERR "%s: error: bitmap file is already in use\n", |
| 4507 | mdname(mddev)); |
| 4508 | fput(mddev->bitmap_file); |
| 4509 | mddev->bitmap_file = NULL; |
| 4510 | return err; |
| 4511 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 4512 | mddev->bitmap_offset = 0; /* file overrides offset */ |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4513 | } else if (mddev->bitmap == NULL) |
| 4514 | return -ENOENT; /* cannot remove what isn't there */ |
| 4515 | err = 0; |
| 4516 | if (mddev->pers) { |
| 4517 | mddev->pers->quiesce(mddev, 1); |
| 4518 | if (fd >= 0) |
| 4519 | err = bitmap_create(mddev); |
NeilBrown | d7375ab32 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4520 | if (fd < 0 || err) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4521 | bitmap_destroy(mddev); |
NeilBrown | d7375ab32 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4522 | fd = -1; /* make sure to put the file */ |
| 4523 | } |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4524 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | d7375ab32 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4525 | } |
| 4526 | if (fd < 0) { |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4527 | if (mddev->bitmap_file) { |
| 4528 | restore_bitmap_write_access(mddev->bitmap_file); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4529 | fput(mddev->bitmap_file); |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4530 | } |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4531 | mddev->bitmap_file = NULL; |
| 4532 | } |
| 4533 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4534 | return err; |
| 4535 | } |
| 4536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | /* |
| 4538 | * set_array_info is used two different ways |
| 4539 | * The original usage is when creating a new array. |
| 4540 | * In this usage, raid_disks is > 0 and it together with |
| 4541 | * level, size, not_persistent,layout,chunksize determine the |
| 4542 | * shape of the array. |
| 4543 | * This will always create an array with a type-0.90.0 superblock. |
| 4544 | * The newer usage is when assembling an array. |
| 4545 | * In this case raid_disks will be 0, and the major_version field is |
| 4546 | * use to determine which style super-blocks are to be found on the devices. |
| 4547 | * The minor and patch _version numbers are also kept incase the |
| 4548 | * super_block handler wishes to interpret them. |
| 4549 | */ |
| 4550 | static int set_array_info(mddev_t * mddev, mdu_array_info_t *info) |
| 4551 | { |
| 4552 | |
| 4553 | if (info->raid_disks == 0) { |
| 4554 | /* just setting version number for superblock loading */ |
| 4555 | if (info->major_version < 0 || |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 4556 | info->major_version >= ARRAY_SIZE(super_types) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | super_types[info->major_version].name == NULL) { |
| 4558 | /* maybe try to auto-load a module? */ |
| 4559 | printk(KERN_INFO |
| 4560 | "md: superblock version %d not known\n", |
| 4561 | info->major_version); |
| 4562 | return -EINVAL; |
| 4563 | } |
| 4564 | mddev->major_version = info->major_version; |
| 4565 | mddev->minor_version = info->minor_version; |
| 4566 | mddev->patch_version = info->patch_version; |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 4567 | mddev->persistent = !info->not_persistent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | return 0; |
| 4569 | } |
| 4570 | mddev->major_version = MD_MAJOR_VERSION; |
| 4571 | mddev->minor_version = MD_MINOR_VERSION; |
| 4572 | mddev->patch_version = MD_PATCHLEVEL_VERSION; |
| 4573 | mddev->ctime = get_seconds(); |
| 4574 | |
| 4575 | mddev->level = info->level; |
NeilBrown | 17115e0 | 2006-01-16 22:14:57 -0800 | [diff] [blame] | 4576 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | mddev->size = info->size; |
| 4578 | mddev->raid_disks = info->raid_disks; |
| 4579 | /* don't set md_minor, it is determined by which /dev/md* was |
| 4580 | * openned |
| 4581 | */ |
| 4582 | if (info->state & (1<<MD_SB_CLEAN)) |
| 4583 | mddev->recovery_cp = MaxSector; |
| 4584 | else |
| 4585 | mddev->recovery_cp = 0; |
| 4586 | mddev->persistent = ! info->not_persistent; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 4587 | mddev->external = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | |
| 4589 | mddev->layout = info->layout; |
| 4590 | mddev->chunk_size = info->chunk_size; |
| 4591 | |
| 4592 | mddev->max_disks = MD_SB_DISKS; |
| 4593 | |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 4594 | if (mddev->persistent) |
| 4595 | mddev->flags = 0; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4596 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | |
NeilBrown | b2a2703 | 2005-11-28 13:44:12 -0800 | [diff] [blame] | 4598 | mddev->default_bitmap_offset = MD_SB_BYTES >> 9; |
| 4599 | mddev->bitmap_offset = 0; |
| 4600 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4601 | mddev->reshape_position = MaxSector; |
| 4602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | /* |
| 4604 | * Generate a 128 bit UUID |
| 4605 | */ |
| 4606 | get_random_bytes(mddev->uuid, 16); |
| 4607 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4608 | mddev->new_level = mddev->level; |
| 4609 | mddev->new_chunk = mddev->chunk_size; |
| 4610 | mddev->new_layout = mddev->layout; |
| 4611 | mddev->delta_disks = 0; |
| 4612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | return 0; |
| 4614 | } |
| 4615 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4616 | static int update_size(mddev_t *mddev, sector_t num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4617 | { |
| 4618 | mdk_rdev_t * rdev; |
| 4619 | int rv; |
| 4620 | struct list_head *tmp; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4621 | int fit = (num_sectors == 0); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4622 | |
| 4623 | if (mddev->pers->resize == NULL) |
| 4624 | return -EINVAL; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4625 | /* The "num_sectors" is the number of sectors of each device that |
| 4626 | * is used. This can only make sense for arrays with redundancy. |
| 4627 | * linear and raid0 always use whatever space is available. We can only |
| 4628 | * consider changing this number if no resync or reconstruction is |
| 4629 | * happening, and if the new size is acceptable. It must fit before the |
| 4630 | * sb_offset or, if that is <data_offset, it must fit before the size |
| 4631 | * of each device. If num_sectors is zero, we find the largest size |
| 4632 | * that fits. |
| 4633 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4634 | */ |
| 4635 | if (mddev->sync_thread) |
| 4636 | return -EBUSY; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 4637 | rdev_for_each(rdev, tmp, mddev) { |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4638 | sector_t avail; |
NeilBrown | 01ab566 | 2006-10-28 10:38:30 -0700 | [diff] [blame] | 4639 | avail = rdev->size * 2; |
| 4640 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4641 | if (fit && (num_sectors == 0 || num_sectors > avail)) |
| 4642 | num_sectors = avail; |
| 4643 | if (avail < num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4644 | return -ENOSPC; |
| 4645 | } |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4646 | rv = mddev->pers->resize(mddev, num_sectors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4647 | if (!rv) { |
| 4648 | struct block_device *bdev; |
| 4649 | |
| 4650 | bdev = bdget_disk(mddev->gendisk, 0); |
| 4651 | if (bdev) { |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 4652 | mutex_lock(&bdev->bd_inode->i_mutex); |
NeilBrown | 6d89332 | 2006-02-02 14:28:03 -0800 | [diff] [blame] | 4653 | i_size_write(bdev->bd_inode, (loff_t)mddev->array_size << 10); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 4654 | mutex_unlock(&bdev->bd_inode->i_mutex); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4655 | bdput(bdev); |
| 4656 | } |
| 4657 | } |
| 4658 | return rv; |
| 4659 | } |
| 4660 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4661 | static int update_raid_disks(mddev_t *mddev, int raid_disks) |
| 4662 | { |
| 4663 | int rv; |
| 4664 | /* change the number of raid disks */ |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4665 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4666 | return -EINVAL; |
| 4667 | if (raid_disks <= 0 || |
| 4668 | raid_disks >= mddev->max_disks) |
| 4669 | return -EINVAL; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4670 | if (mddev->sync_thread || mddev->reshape_position != MaxSector) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4671 | return -EBUSY; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4672 | mddev->delta_disks = raid_disks - mddev->raid_disks; |
| 4673 | |
| 4674 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4675 | return rv; |
| 4676 | } |
| 4677 | |
| 4678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | /* |
| 4680 | * update_array_info is used to change the configuration of an |
| 4681 | * on-line array. |
| 4682 | * The version, ctime,level,size,raid_disks,not_persistent, layout,chunk_size |
| 4683 | * fields in the info are checked against the array. |
| 4684 | * Any differences that cannot be handled will cause an error. |
| 4685 | * Normally, only one change can be managed at a time. |
| 4686 | */ |
| 4687 | static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) |
| 4688 | { |
| 4689 | int rv = 0; |
| 4690 | int cnt = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4691 | int state = 0; |
| 4692 | |
| 4693 | /* calculate expected state,ignoring low bits */ |
| 4694 | if (mddev->bitmap && mddev->bitmap_offset) |
| 4695 | state |= (1 << MD_SB_BITMAP_PRESENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | |
| 4697 | if (mddev->major_version != info->major_version || |
| 4698 | mddev->minor_version != info->minor_version || |
| 4699 | /* mddev->patch_version != info->patch_version || */ |
| 4700 | mddev->ctime != info->ctime || |
| 4701 | mddev->level != info->level || |
| 4702 | /* mddev->layout != info->layout || */ |
| 4703 | !mddev->persistent != info->not_persistent|| |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4704 | mddev->chunk_size != info->chunk_size || |
| 4705 | /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */ |
| 4706 | ((state^info->state) & 0xfffffe00) |
| 4707 | ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | return -EINVAL; |
| 4709 | /* Check there is only one change */ |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 4710 | if (info->size >= 0 && mddev->size != info->size) cnt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | if (mddev->raid_disks != info->raid_disks) cnt++; |
| 4712 | if (mddev->layout != info->layout) cnt++; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4713 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) cnt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | if (cnt == 0) return 0; |
| 4715 | if (cnt > 1) return -EINVAL; |
| 4716 | |
| 4717 | if (mddev->layout != info->layout) { |
| 4718 | /* Change layout |
| 4719 | * we don't need to do anything at the md level, the |
| 4720 | * personality will take care of it all. |
| 4721 | */ |
| 4722 | if (mddev->pers->reconfig == NULL) |
| 4723 | return -EINVAL; |
| 4724 | else |
| 4725 | return mddev->pers->reconfig(mddev, info->layout, -1); |
| 4726 | } |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 4727 | if (info->size >= 0 && mddev->size != info->size) |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4728 | rv = update_size(mddev, (sector_t)info->size * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4729 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 4730 | if (mddev->raid_disks != info->raid_disks) |
| 4731 | rv = update_raid_disks(mddev, info->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4733 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) { |
| 4734 | if (mddev->pers->quiesce == NULL) |
| 4735 | return -EINVAL; |
| 4736 | if (mddev->recovery || mddev->sync_thread) |
| 4737 | return -EBUSY; |
| 4738 | if (info->state & (1<<MD_SB_BITMAP_PRESENT)) { |
| 4739 | /* add the bitmap */ |
| 4740 | if (mddev->bitmap) |
| 4741 | return -EEXIST; |
| 4742 | if (mddev->default_bitmap_offset == 0) |
| 4743 | return -EINVAL; |
| 4744 | mddev->bitmap_offset = mddev->default_bitmap_offset; |
| 4745 | mddev->pers->quiesce(mddev, 1); |
| 4746 | rv = bitmap_create(mddev); |
| 4747 | if (rv) |
| 4748 | bitmap_destroy(mddev); |
| 4749 | mddev->pers->quiesce(mddev, 0); |
| 4750 | } else { |
| 4751 | /* remove the bitmap */ |
| 4752 | if (!mddev->bitmap) |
| 4753 | return -ENOENT; |
| 4754 | if (mddev->bitmap->file) |
| 4755 | return -EINVAL; |
| 4756 | mddev->pers->quiesce(mddev, 1); |
| 4757 | bitmap_destroy(mddev); |
| 4758 | mddev->pers->quiesce(mddev, 0); |
| 4759 | mddev->bitmap_offset = 0; |
| 4760 | } |
| 4761 | } |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4762 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | return rv; |
| 4764 | } |
| 4765 | |
| 4766 | static int set_disk_faulty(mddev_t *mddev, dev_t dev) |
| 4767 | { |
| 4768 | mdk_rdev_t *rdev; |
| 4769 | |
| 4770 | if (mddev->pers == NULL) |
| 4771 | return -ENODEV; |
| 4772 | |
| 4773 | rdev = find_rdev(mddev, dev); |
| 4774 | if (!rdev) |
| 4775 | return -ENODEV; |
| 4776 | |
| 4777 | md_error(mddev, rdev); |
| 4778 | return 0; |
| 4779 | } |
| 4780 | |
Andre Noll | 2f9618c | 2008-04-25 18:57:58 +0200 | [diff] [blame] | 4781 | /* |
| 4782 | * We have a problem here : there is no easy way to give a CHS |
| 4783 | * virtual geometry. We currently pretend that we have a 2 heads |
| 4784 | * 4 sectors (with a BIG number of cylinders...). This drives |
| 4785 | * dosfs just mad... ;-) |
| 4786 | */ |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 4787 | static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 4788 | { |
| 4789 | mddev_t *mddev = bdev->bd_disk->private_data; |
| 4790 | |
| 4791 | geo->heads = 2; |
| 4792 | geo->sectors = 4; |
| 4793 | geo->cylinders = get_capacity(mddev->gendisk) / 8; |
| 4794 | return 0; |
| 4795 | } |
| 4796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | static int md_ioctl(struct inode *inode, struct file *file, |
| 4798 | unsigned int cmd, unsigned long arg) |
| 4799 | { |
| 4800 | int err = 0; |
| 4801 | void __user *argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | mddev_t *mddev = NULL; |
| 4803 | |
| 4804 | if (!capable(CAP_SYS_ADMIN)) |
| 4805 | return -EACCES; |
| 4806 | |
| 4807 | /* |
| 4808 | * Commands dealing with the RAID driver but not any |
| 4809 | * particular array: |
| 4810 | */ |
| 4811 | switch (cmd) |
| 4812 | { |
| 4813 | case RAID_VERSION: |
| 4814 | err = get_version(argp); |
| 4815 | goto done; |
| 4816 | |
| 4817 | case PRINT_RAID_DEBUG: |
| 4818 | err = 0; |
| 4819 | md_print_devices(); |
| 4820 | goto done; |
| 4821 | |
| 4822 | #ifndef MODULE |
| 4823 | case RAID_AUTORUN: |
| 4824 | err = 0; |
| 4825 | autostart_arrays(arg); |
| 4826 | goto done; |
| 4827 | #endif |
| 4828 | default:; |
| 4829 | } |
| 4830 | |
| 4831 | /* |
| 4832 | * Commands creating/starting a new array: |
| 4833 | */ |
| 4834 | |
| 4835 | mddev = inode->i_bdev->bd_disk->private_data; |
| 4836 | |
| 4837 | if (!mddev) { |
| 4838 | BUG(); |
| 4839 | goto abort; |
| 4840 | } |
| 4841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | err = mddev_lock(mddev); |
| 4843 | if (err) { |
| 4844 | printk(KERN_INFO |
| 4845 | "md: ioctl lock interrupted, reason %d, cmd %d\n", |
| 4846 | err, cmd); |
| 4847 | goto abort; |
| 4848 | } |
| 4849 | |
| 4850 | switch (cmd) |
| 4851 | { |
| 4852 | case SET_ARRAY_INFO: |
| 4853 | { |
| 4854 | mdu_array_info_t info; |
| 4855 | if (!arg) |
| 4856 | memset(&info, 0, sizeof(info)); |
| 4857 | else if (copy_from_user(&info, argp, sizeof(info))) { |
| 4858 | err = -EFAULT; |
| 4859 | goto abort_unlock; |
| 4860 | } |
| 4861 | if (mddev->pers) { |
| 4862 | err = update_array_info(mddev, &info); |
| 4863 | if (err) { |
| 4864 | printk(KERN_WARNING "md: couldn't update" |
| 4865 | " array info. %d\n", err); |
| 4866 | goto abort_unlock; |
| 4867 | } |
| 4868 | goto done_unlock; |
| 4869 | } |
| 4870 | if (!list_empty(&mddev->disks)) { |
| 4871 | printk(KERN_WARNING |
| 4872 | "md: array %s already has disks!\n", |
| 4873 | mdname(mddev)); |
| 4874 | err = -EBUSY; |
| 4875 | goto abort_unlock; |
| 4876 | } |
| 4877 | if (mddev->raid_disks) { |
| 4878 | printk(KERN_WARNING |
| 4879 | "md: array %s already initialised!\n", |
| 4880 | mdname(mddev)); |
| 4881 | err = -EBUSY; |
| 4882 | goto abort_unlock; |
| 4883 | } |
| 4884 | err = set_array_info(mddev, &info); |
| 4885 | if (err) { |
| 4886 | printk(KERN_WARNING "md: couldn't set" |
| 4887 | " array info. %d\n", err); |
| 4888 | goto abort_unlock; |
| 4889 | } |
| 4890 | } |
| 4891 | goto done_unlock; |
| 4892 | |
| 4893 | default:; |
| 4894 | } |
| 4895 | |
| 4896 | /* |
| 4897 | * Commands querying/configuring an existing array: |
| 4898 | */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4899 | /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY, |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 4900 | * RUN_ARRAY, and GET_ and SET_BITMAP_FILE are allowed */ |
NeilBrown | a17184a | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 4901 | if ((!mddev->raid_disks && !mddev->external) |
| 4902 | && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY |
| 4903 | && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE |
| 4904 | && cmd != GET_BITMAP_FILE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | err = -ENODEV; |
| 4906 | goto abort_unlock; |
| 4907 | } |
| 4908 | |
| 4909 | /* |
| 4910 | * Commands even a read-only array can execute: |
| 4911 | */ |
| 4912 | switch (cmd) |
| 4913 | { |
| 4914 | case GET_ARRAY_INFO: |
| 4915 | err = get_array_info(mddev, argp); |
| 4916 | goto done_unlock; |
| 4917 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4918 | case GET_BITMAP_FILE: |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 4919 | err = get_bitmap_file(mddev, argp); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4920 | goto done_unlock; |
| 4921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | case GET_DISK_INFO: |
| 4923 | err = get_disk_info(mddev, argp); |
| 4924 | goto done_unlock; |
| 4925 | |
| 4926 | case RESTART_ARRAY_RW: |
| 4927 | err = restart_array(mddev); |
| 4928 | goto done_unlock; |
| 4929 | |
| 4930 | case STOP_ARRAY: |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4931 | err = do_md_stop (mddev, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | goto done_unlock; |
| 4933 | |
| 4934 | case STOP_ARRAY_RO: |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4935 | err = do_md_stop (mddev, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4936 | goto done_unlock; |
| 4937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
| 4940 | /* |
| 4941 | * The remaining ioctls are changing the state of the |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4942 | * superblock, so we do not allow them on read-only arrays. |
| 4943 | * However non-MD ioctls (e.g. get-size) will still come through |
| 4944 | * here and hit the 'default' below, so only disallow |
| 4945 | * 'md' ioctls, and switch to rw mode if started auto-readonly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | */ |
Andre Noll | bb57fc6 | 2008-04-25 19:06:35 +0200 | [diff] [blame] | 4947 | if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4948 | if (mddev->ro == 2) { |
| 4949 | mddev->ro = 0; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 4950 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
| 4951 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4952 | md_wakeup_thread(mddev->thread); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4953 | } else { |
| 4954 | err = -EROFS; |
| 4955 | goto abort_unlock; |
| 4956 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | switch (cmd) |
| 4960 | { |
| 4961 | case ADD_NEW_DISK: |
| 4962 | { |
| 4963 | mdu_disk_info_t info; |
| 4964 | if (copy_from_user(&info, argp, sizeof(info))) |
| 4965 | err = -EFAULT; |
| 4966 | else |
| 4967 | err = add_new_disk(mddev, &info); |
| 4968 | goto done_unlock; |
| 4969 | } |
| 4970 | |
| 4971 | case HOT_REMOVE_DISK: |
| 4972 | err = hot_remove_disk(mddev, new_decode_dev(arg)); |
| 4973 | goto done_unlock; |
| 4974 | |
| 4975 | case HOT_ADD_DISK: |
| 4976 | err = hot_add_disk(mddev, new_decode_dev(arg)); |
| 4977 | goto done_unlock; |
| 4978 | |
| 4979 | case SET_DISK_FAULTY: |
| 4980 | err = set_disk_faulty(mddev, new_decode_dev(arg)); |
| 4981 | goto done_unlock; |
| 4982 | |
| 4983 | case RUN_ARRAY: |
| 4984 | err = do_md_run (mddev); |
| 4985 | goto done_unlock; |
| 4986 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4987 | case SET_BITMAP_FILE: |
| 4988 | err = set_bitmap_file(mddev, (int)arg); |
| 4989 | goto done_unlock; |
| 4990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4991 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | err = -EINVAL; |
| 4993 | goto abort_unlock; |
| 4994 | } |
| 4995 | |
| 4996 | done_unlock: |
| 4997 | abort_unlock: |
| 4998 | mddev_unlock(mddev); |
| 4999 | |
| 5000 | return err; |
| 5001 | done: |
| 5002 | if (err) |
| 5003 | MD_BUG(); |
| 5004 | abort: |
| 5005 | return err; |
| 5006 | } |
| 5007 | |
| 5008 | static int md_open(struct inode *inode, struct file *file) |
| 5009 | { |
| 5010 | /* |
| 5011 | * Succeed if we can lock the mddev, which confirms that |
| 5012 | * it isn't being stopped right now. |
| 5013 | */ |
| 5014 | mddev_t *mddev = inode->i_bdev->bd_disk->private_data; |
| 5015 | int err; |
| 5016 | |
NeilBrown | d63a5a7 | 2006-12-08 02:36:17 -0800 | [diff] [blame] | 5017 | if ((err = mutex_lock_interruptible_nested(&mddev->reconfig_mutex, 1))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5018 | goto out; |
| 5019 | |
| 5020 | err = 0; |
| 5021 | mddev_get(mddev); |
| 5022 | mddev_unlock(mddev); |
| 5023 | |
| 5024 | check_disk_change(inode->i_bdev); |
| 5025 | out: |
| 5026 | return err; |
| 5027 | } |
| 5028 | |
| 5029 | static int md_release(struct inode *inode, struct file * file) |
| 5030 | { |
| 5031 | mddev_t *mddev = inode->i_bdev->bd_disk->private_data; |
| 5032 | |
Eric Sesterhenn | 52e5f9d | 2006-10-03 23:33:23 +0200 | [diff] [blame] | 5033 | BUG_ON(!mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | mddev_put(mddev); |
| 5035 | |
| 5036 | return 0; |
| 5037 | } |
| 5038 | |
Linus Torvalds | 44ce6294 | 2007-05-09 18:51:36 -0700 | [diff] [blame] | 5039 | static int md_media_changed(struct gendisk *disk) |
| 5040 | { |
| 5041 | mddev_t *mddev = disk->private_data; |
| 5042 | |
| 5043 | return mddev->changed; |
| 5044 | } |
| 5045 | |
| 5046 | static int md_revalidate(struct gendisk *disk) |
| 5047 | { |
| 5048 | mddev_t *mddev = disk->private_data; |
| 5049 | |
| 5050 | mddev->changed = 0; |
| 5051 | return 0; |
| 5052 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | static struct block_device_operations md_fops = |
| 5054 | { |
| 5055 | .owner = THIS_MODULE, |
| 5056 | .open = md_open, |
| 5057 | .release = md_release, |
| 5058 | .ioctl = md_ioctl, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5059 | .getgeo = md_getgeo, |
Linus Torvalds | 44ce6294 | 2007-05-09 18:51:36 -0700 | [diff] [blame] | 5060 | .media_changed = md_media_changed, |
| 5061 | .revalidate_disk= md_revalidate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | }; |
| 5063 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 5064 | static int md_thread(void * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | { |
| 5066 | mdk_thread_t *thread = arg; |
| 5067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | /* |
| 5069 | * md_thread is a 'system-thread', it's priority should be very |
| 5070 | * high. We avoid resource deadlocks individually in each |
| 5071 | * raid personality. (RAID5 does preallocation) We also use RR and |
| 5072 | * the very same RT priority as kswapd, thus we will never get |
| 5073 | * into a priority inversion deadlock. |
| 5074 | * |
| 5075 | * we definitely have to have equal or higher priority than |
| 5076 | * bdflush, otherwise bdflush will deadlock if there are too |
| 5077 | * many dirty RAID5 blocks. |
| 5078 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 5080 | allow_signal(SIGKILL); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5081 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | |
NeilBrown | 93588e2 | 2005-11-15 00:09:12 -0800 | [diff] [blame] | 5083 | /* We need to wait INTERRUPTIBLE so that |
| 5084 | * we don't add to the load-average. |
| 5085 | * That means we need to be sure no signals are |
| 5086 | * pending |
| 5087 | */ |
| 5088 | if (signal_pending(current)) |
| 5089 | flush_signals(current); |
| 5090 | |
| 5091 | wait_event_interruptible_timeout |
| 5092 | (thread->wqueue, |
| 5093 | test_bit(THREAD_WAKEUP, &thread->flags) |
| 5094 | || kthread_should_stop(), |
| 5095 | thread->timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | |
| 5097 | clear_bit(THREAD_WAKEUP, &thread->flags); |
| 5098 | |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 5099 | thread->run(thread->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5100 | } |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5102 | return 0; |
| 5103 | } |
| 5104 | |
| 5105 | void md_wakeup_thread(mdk_thread_t *thread) |
| 5106 | { |
| 5107 | if (thread) { |
| 5108 | dprintk("md: waking up MD thread %s.\n", thread->tsk->comm); |
| 5109 | set_bit(THREAD_WAKEUP, &thread->flags); |
| 5110 | wake_up(&thread->wqueue); |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, |
| 5115 | const char *name) |
| 5116 | { |
| 5117 | mdk_thread_t *thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 5119 | thread = kzalloc(sizeof(mdk_thread_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5120 | if (!thread) |
| 5121 | return NULL; |
| 5122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | init_waitqueue_head(&thread->wqueue); |
| 5124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | thread->run = run; |
| 5126 | thread->mddev = mddev; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5127 | thread->timeout = MAX_SCHEDULE_TIMEOUT; |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 5128 | thread->tsk = kthread_run(md_thread, thread, name, mdname(thread->mddev)); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5129 | if (IS_ERR(thread->tsk)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | kfree(thread); |
| 5131 | return NULL; |
| 5132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | return thread; |
| 5134 | } |
| 5135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5136 | void md_unregister_thread(mdk_thread_t *thread) |
| 5137 | { |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 5138 | dprintk("interrupting MD-thread pid %d\n", task_pid_nr(thread->tsk)); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5139 | |
| 5140 | kthread_stop(thread->tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5141 | kfree(thread); |
| 5142 | } |
| 5143 | |
| 5144 | void md_error(mddev_t *mddev, mdk_rdev_t *rdev) |
| 5145 | { |
| 5146 | if (!mddev) { |
| 5147 | MD_BUG(); |
| 5148 | return; |
| 5149 | } |
| 5150 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5151 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | return; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 5153 | |
| 5154 | if (mddev->external) |
| 5155 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5156 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | dprintk("md_error dev:%s, rdev:(%d:%d), (caller: %p,%p,%p,%p).\n", |
| 5158 | mdname(mddev), |
| 5159 | MAJOR(rdev->bdev->bd_dev), MINOR(rdev->bdev->bd_dev), |
| 5160 | __builtin_return_address(0),__builtin_return_address(1), |
| 5161 | __builtin_return_address(2),__builtin_return_address(3)); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5162 | */ |
Andrew Morton | d0a0a5e | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 5163 | if (!mddev->pers) |
| 5164 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | if (!mddev->pers->error_handler) |
| 5166 | return; |
| 5167 | mddev->pers->error_handler(mddev,rdev); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 5168 | if (mddev->degraded) |
| 5169 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 5170 | set_bit(StateChanged, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5171 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 5172 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5173 | md_wakeup_thread(mddev->thread); |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 5174 | md_new_event_inintr(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5175 | } |
| 5176 | |
| 5177 | /* seq_file implementation /proc/mdstat */ |
| 5178 | |
| 5179 | static void status_unused(struct seq_file *seq) |
| 5180 | { |
| 5181 | int i = 0; |
| 5182 | mdk_rdev_t *rdev; |
| 5183 | struct list_head *tmp; |
| 5184 | |
| 5185 | seq_printf(seq, "unused devices: "); |
| 5186 | |
NeilBrown | 73c3443 | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 5187 | rdev_for_each_list(rdev, tmp, pending_raid_disks) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5188 | char b[BDEVNAME_SIZE]; |
| 5189 | i++; |
| 5190 | seq_printf(seq, "%s ", |
| 5191 | bdevname(rdev->bdev,b)); |
| 5192 | } |
| 5193 | if (!i) |
| 5194 | seq_printf(seq, "<none>"); |
| 5195 | |
| 5196 | seq_printf(seq, "\n"); |
| 5197 | } |
| 5198 | |
| 5199 | |
| 5200 | static void status_resync(struct seq_file *seq, mddev_t * mddev) |
| 5201 | { |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5202 | sector_t max_blocks, resync, res; |
| 5203 | unsigned long dt, db, rt; |
| 5204 | int scale; |
| 5205 | unsigned int per_milli; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | |
| 5207 | resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active))/2; |
| 5208 | |
| 5209 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 5210 | max_blocks = mddev->resync_max_sectors >> 1; |
| 5211 | else |
| 5212 | max_blocks = mddev->size; |
| 5213 | |
| 5214 | /* |
| 5215 | * Should not happen. |
| 5216 | */ |
| 5217 | if (!max_blocks) { |
| 5218 | MD_BUG(); |
| 5219 | return; |
| 5220 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5221 | /* Pick 'scale' such that (resync>>scale)*1000 will fit |
| 5222 | * in a sector_t, and (max_blocks>>scale) will fit in a |
| 5223 | * u32, as those are the requirements for sector_div. |
| 5224 | * Thus 'scale' must be at least 10 |
| 5225 | */ |
| 5226 | scale = 10; |
| 5227 | if (sizeof(sector_t) > sizeof(unsigned long)) { |
| 5228 | while ( max_blocks/2 > (1ULL<<(scale+32))) |
| 5229 | scale++; |
| 5230 | } |
| 5231 | res = (resync>>scale)*1000; |
| 5232 | sector_div(res, (u32)((max_blocks>>scale)+1)); |
| 5233 | |
| 5234 | per_milli = res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5235 | { |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5236 | int i, x = per_milli/50, y = 20-x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5237 | seq_printf(seq, "["); |
| 5238 | for (i = 0; i < x; i++) |
| 5239 | seq_printf(seq, "="); |
| 5240 | seq_printf(seq, ">"); |
| 5241 | for (i = 0; i < y; i++) |
| 5242 | seq_printf(seq, "."); |
| 5243 | seq_printf(seq, "] "); |
| 5244 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5245 | seq_printf(seq, " %s =%3u.%u%% (%llu/%llu)", |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 5246 | (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)? |
| 5247 | "reshape" : |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5248 | (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)? |
| 5249 | "check" : |
| 5250 | (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ? |
| 5251 | "resync" : "recovery"))), |
| 5252 | per_milli/10, per_milli % 10, |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5253 | (unsigned long long) resync, |
| 5254 | (unsigned long long) max_blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5255 | |
| 5256 | /* |
| 5257 | * We do not want to overflow, so the order of operands and |
| 5258 | * the * 100 / 100 trick are important. We do a +1 to be |
| 5259 | * safe against division by zero. We only estimate anyway. |
| 5260 | * |
| 5261 | * dt: time from mark until now |
| 5262 | * db: blocks written from mark until now |
| 5263 | * rt: remaining time |
| 5264 | */ |
| 5265 | dt = ((jiffies - mddev->resync_mark) / HZ); |
| 5266 | if (!dt) dt++; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 5267 | db = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active)) |
| 5268 | - mddev->resync_mark_cnt; |
| 5269 | rt = (dt * ((unsigned long)(max_blocks-resync) / (db/2/100+1)))/100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5270 | |
| 5271 | seq_printf(seq, " finish=%lu.%lumin", rt / 60, (rt % 60)/6); |
| 5272 | |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 5273 | seq_printf(seq, " speed=%ldK/sec", db/2/dt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | static void *md_seq_start(struct seq_file *seq, loff_t *pos) |
| 5277 | { |
| 5278 | struct list_head *tmp; |
| 5279 | loff_t l = *pos; |
| 5280 | mddev_t *mddev; |
| 5281 | |
| 5282 | if (l >= 0x10000) |
| 5283 | return NULL; |
| 5284 | if (!l--) |
| 5285 | /* header */ |
| 5286 | return (void*)1; |
| 5287 | |
| 5288 | spin_lock(&all_mddevs_lock); |
| 5289 | list_for_each(tmp,&all_mddevs) |
| 5290 | if (!l--) { |
| 5291 | mddev = list_entry(tmp, mddev_t, all_mddevs); |
| 5292 | mddev_get(mddev); |
| 5293 | spin_unlock(&all_mddevs_lock); |
| 5294 | return mddev; |
| 5295 | } |
| 5296 | spin_unlock(&all_mddevs_lock); |
| 5297 | if (!l--) |
| 5298 | return (void*)2;/* tail */ |
| 5299 | return NULL; |
| 5300 | } |
| 5301 | |
| 5302 | static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 5303 | { |
| 5304 | struct list_head *tmp; |
| 5305 | mddev_t *next_mddev, *mddev = v; |
| 5306 | |
| 5307 | ++*pos; |
| 5308 | if (v == (void*)2) |
| 5309 | return NULL; |
| 5310 | |
| 5311 | spin_lock(&all_mddevs_lock); |
| 5312 | if (v == (void*)1) |
| 5313 | tmp = all_mddevs.next; |
| 5314 | else |
| 5315 | tmp = mddev->all_mddevs.next; |
| 5316 | if (tmp != &all_mddevs) |
| 5317 | next_mddev = mddev_get(list_entry(tmp,mddev_t,all_mddevs)); |
| 5318 | else { |
| 5319 | next_mddev = (void*)2; |
| 5320 | *pos = 0x10000; |
| 5321 | } |
| 5322 | spin_unlock(&all_mddevs_lock); |
| 5323 | |
| 5324 | if (v != (void*)1) |
| 5325 | mddev_put(mddev); |
| 5326 | return next_mddev; |
| 5327 | |
| 5328 | } |
| 5329 | |
| 5330 | static void md_seq_stop(struct seq_file *seq, void *v) |
| 5331 | { |
| 5332 | mddev_t *mddev = v; |
| 5333 | |
| 5334 | if (mddev && v != (void*)1 && v != (void*)2) |
| 5335 | mddev_put(mddev); |
| 5336 | } |
| 5337 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5338 | struct mdstat_info { |
| 5339 | int event; |
| 5340 | }; |
| 5341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | static int md_seq_show(struct seq_file *seq, void *v) |
| 5343 | { |
| 5344 | mddev_t *mddev = v; |
| 5345 | sector_t size; |
| 5346 | struct list_head *tmp2; |
| 5347 | mdk_rdev_t *rdev; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5348 | struct mdstat_info *mi = seq->private; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5349 | struct bitmap *bitmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5350 | |
| 5351 | if (v == (void*)1) { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5352 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5353 | seq_printf(seq, "Personalities : "); |
| 5354 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5355 | list_for_each_entry(pers, &pers_list, list) |
| 5356 | seq_printf(seq, "[%s] ", pers->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | |
| 5358 | spin_unlock(&pers_lock); |
| 5359 | seq_printf(seq, "\n"); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5360 | mi->event = atomic_read(&md_event_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | return 0; |
| 5362 | } |
| 5363 | if (v == (void*)2) { |
| 5364 | status_unused(seq); |
| 5365 | return 0; |
| 5366 | } |
| 5367 | |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 5368 | if (mddev_lock(mddev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | return -EINTR; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 5370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5371 | if (mddev->pers || mddev->raid_disks || !list_empty(&mddev->disks)) { |
| 5372 | seq_printf(seq, "%s : %sactive", mdname(mddev), |
| 5373 | mddev->pers ? "" : "in"); |
| 5374 | if (mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5375 | if (mddev->ro==1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5376 | seq_printf(seq, " (read-only)"); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5377 | if (mddev->ro==2) |
NeilBrown | 52720ae | 2008-03-10 11:43:47 -0700 | [diff] [blame] | 5378 | seq_printf(seq, " (auto-read-only)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5379 | seq_printf(seq, " %s", mddev->pers->name); |
| 5380 | } |
| 5381 | |
| 5382 | size = 0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 5383 | rdev_for_each(rdev, tmp2, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5384 | char b[BDEVNAME_SIZE]; |
| 5385 | seq_printf(seq, " %s[%d]", |
| 5386 | bdevname(rdev->bdev,b), rdev->desc_nr); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5387 | if (test_bit(WriteMostly, &rdev->flags)) |
| 5388 | seq_printf(seq, "(W)"); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5389 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | seq_printf(seq, "(F)"); |
| 5391 | continue; |
NeilBrown | b325a32 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 5392 | } else if (rdev->raid_disk < 0) |
| 5393 | seq_printf(seq, "(S)"); /* spare */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5394 | size += rdev->size; |
| 5395 | } |
| 5396 | |
| 5397 | if (!list_empty(&mddev->disks)) { |
| 5398 | if (mddev->pers) |
| 5399 | seq_printf(seq, "\n %llu blocks", |
| 5400 | (unsigned long long)mddev->array_size); |
| 5401 | else |
| 5402 | seq_printf(seq, "\n %llu blocks", |
| 5403 | (unsigned long long)size); |
| 5404 | } |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 5405 | if (mddev->persistent) { |
| 5406 | if (mddev->major_version != 0 || |
| 5407 | mddev->minor_version != 90) { |
| 5408 | seq_printf(seq," super %d.%d", |
| 5409 | mddev->major_version, |
| 5410 | mddev->minor_version); |
| 5411 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 5412 | } else if (mddev->external) |
| 5413 | seq_printf(seq, " super external:%s", |
| 5414 | mddev->metadata_type); |
| 5415 | else |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 5416 | seq_printf(seq, " super non-persistent"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 | |
| 5418 | if (mddev->pers) { |
| 5419 | mddev->pers->status (seq, mddev); |
| 5420 | seq_printf(seq, "\n "); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 5421 | if (mddev->pers->sync_request) { |
| 5422 | if (mddev->curr_resync > 2) { |
| 5423 | status_resync (seq, mddev); |
| 5424 | seq_printf(seq, "\n "); |
| 5425 | } else if (mddev->curr_resync == 1 || mddev->curr_resync == 2) |
| 5426 | seq_printf(seq, "\tresync=DELAYED\n "); |
| 5427 | else if (mddev->recovery_cp < MaxSector) |
| 5428 | seq_printf(seq, "\tresync=PENDING\n "); |
| 5429 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5430 | } else |
| 5431 | seq_printf(seq, "\n "); |
| 5432 | |
| 5433 | if ((bitmap = mddev->bitmap)) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5434 | unsigned long chunk_kb; |
| 5435 | unsigned long flags; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5436 | spin_lock_irqsave(&bitmap->lock, flags); |
| 5437 | chunk_kb = bitmap->chunksize >> 10; |
| 5438 | seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], " |
| 5439 | "%lu%s chunk", |
| 5440 | bitmap->pages - bitmap->missing_pages, |
| 5441 | bitmap->pages, |
| 5442 | (bitmap->pages - bitmap->missing_pages) |
| 5443 | << (PAGE_SHIFT - 10), |
| 5444 | chunk_kb ? chunk_kb : bitmap->chunksize, |
| 5445 | chunk_kb ? "KB" : "B"); |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 5446 | if (bitmap->file) { |
| 5447 | seq_printf(seq, ", file: "); |
Jan Blunck | c32c2f6 | 2008-02-14 19:38:43 -0800 | [diff] [blame] | 5448 | seq_path(seq, &bitmap->file->f_path, " \t\n"); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5449 | } |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 5450 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5451 | seq_printf(seq, "\n"); |
| 5452 | spin_unlock_irqrestore(&bitmap->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5453 | } |
| 5454 | |
| 5455 | seq_printf(seq, "\n"); |
| 5456 | } |
| 5457 | mddev_unlock(mddev); |
| 5458 | |
| 5459 | return 0; |
| 5460 | } |
| 5461 | |
| 5462 | static struct seq_operations md_seq_ops = { |
| 5463 | .start = md_seq_start, |
| 5464 | .next = md_seq_next, |
| 5465 | .stop = md_seq_stop, |
| 5466 | .show = md_seq_show, |
| 5467 | }; |
| 5468 | |
| 5469 | static int md_seq_open(struct inode *inode, struct file *file) |
| 5470 | { |
| 5471 | int error; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5472 | struct mdstat_info *mi = kmalloc(sizeof(*mi), GFP_KERNEL); |
| 5473 | if (mi == NULL) |
| 5474 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | |
| 5476 | error = seq_open(file, &md_seq_ops); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5477 | if (error) |
| 5478 | kfree(mi); |
| 5479 | else { |
| 5480 | struct seq_file *p = file->private_data; |
| 5481 | p->private = mi; |
| 5482 | mi->event = atomic_read(&md_event_count); |
| 5483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5484 | return error; |
| 5485 | } |
| 5486 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5487 | static unsigned int mdstat_poll(struct file *filp, poll_table *wait) |
| 5488 | { |
| 5489 | struct seq_file *m = filp->private_data; |
| 5490 | struct mdstat_info *mi = m->private; |
| 5491 | int mask; |
| 5492 | |
| 5493 | poll_wait(filp, &md_event_waiters, wait); |
| 5494 | |
| 5495 | /* always allow read */ |
| 5496 | mask = POLLIN | POLLRDNORM; |
| 5497 | |
| 5498 | if (mi->event != atomic_read(&md_event_count)) |
| 5499 | mask |= POLLERR | POLLPRI; |
| 5500 | return mask; |
| 5501 | } |
| 5502 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 5503 | static const struct file_operations md_seq_fops = { |
Akinobu Mita | e24650c | 2006-10-17 00:09:38 -0700 | [diff] [blame] | 5504 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | .open = md_seq_open, |
| 5506 | .read = seq_read, |
| 5507 | .llseek = seq_lseek, |
Martin Peschke | c3f94b40 | 2007-05-09 02:35:35 -0700 | [diff] [blame] | 5508 | .release = seq_release_private, |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5509 | .poll = mdstat_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | }; |
| 5511 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5512 | int register_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5513 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5515 | list_add_tail(&p->list, &pers_list); |
| 5516 | 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] | 5517 | spin_unlock(&pers_lock); |
| 5518 | return 0; |
| 5519 | } |
| 5520 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5521 | int unregister_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5523 | printk(KERN_INFO "md: %s personality unregistered\n", p->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5525 | list_del_init(&p->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | spin_unlock(&pers_lock); |
| 5527 | return 0; |
| 5528 | } |
| 5529 | |
| 5530 | static int is_mddev_idle(mddev_t *mddev) |
| 5531 | { |
| 5532 | mdk_rdev_t * rdev; |
| 5533 | struct list_head *tmp; |
| 5534 | int idle; |
NeilBrown | 713f6ab | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 5535 | long curr_events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 | |
| 5537 | idle = 1; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 5538 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | struct gendisk *disk = rdev->bdev->bd_contains->bd_disk; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 5540 | curr_events = disk_stat_read(disk, sectors[0]) + |
| 5541 | disk_stat_read(disk, sectors[1]) - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | atomic_read(&disk->sync_io); |
NeilBrown | 713f6ab | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 5543 | /* sync IO will cause sync_io to increase before the disk_stats |
| 5544 | * as sync_io is counted when a request starts, and |
| 5545 | * disk_stats is counted when it completes. |
| 5546 | * So resync activity will cause curr_events to be smaller than |
| 5547 | * when there was no such activity. |
| 5548 | * non-sync IO will cause disk_stat to increase without |
| 5549 | * increasing sync_io so curr_events will (eventually) |
| 5550 | * be larger than it was before. Once it becomes |
| 5551 | * substantially larger, the test below will cause |
| 5552 | * the array to appear non-idle, and resync will slow |
| 5553 | * down. |
| 5554 | * If there is a lot of outstanding resync activity when |
| 5555 | * we set last_event to curr_events, then all that activity |
| 5556 | * completing might cause the array to appear non-idle |
| 5557 | * and resync will be slowed down even though there might |
| 5558 | * not have been non-resync activity. This will only |
| 5559 | * happen once though. 'last_events' will soon reflect |
| 5560 | * the state where there is little or no outstanding |
| 5561 | * resync requests, and further resync activity will |
| 5562 | * always make curr_events less than last_events. |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 5563 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | */ |
NeilBrown | 713f6ab | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 5565 | if (curr_events - rdev->last_events > 4096) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | rdev->last_events = curr_events; |
| 5567 | idle = 0; |
| 5568 | } |
| 5569 | } |
| 5570 | return idle; |
| 5571 | } |
| 5572 | |
| 5573 | void md_done_sync(mddev_t *mddev, int blocks, int ok) |
| 5574 | { |
| 5575 | /* another "blocks" (512byte) blocks have been synced */ |
| 5576 | atomic_sub(blocks, &mddev->recovery_active); |
| 5577 | wake_up(&mddev->recovery_wait); |
| 5578 | if (!ok) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5579 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | md_wakeup_thread(mddev->thread); |
| 5581 | // stop recovery, signal do_sync .... |
| 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5586 | /* md_write_start(mddev, bi) |
| 5587 | * If we need to update some array metadata (e.g. 'active' flag |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5588 | * in superblock) before writing, schedule a superblock update |
| 5589 | * and wait for it to complete. |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5590 | */ |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5591 | void md_write_start(mddev_t *mddev, struct bio *bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 5593 | int did_change = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5594 | if (bio_data_dir(bi) != WRITE) |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5595 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5596 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5597 | BUG_ON(mddev->ro == 1); |
| 5598 | if (mddev->ro == 2) { |
| 5599 | /* need to switch to read/write */ |
| 5600 | mddev->ro = 0; |
| 5601 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5602 | md_wakeup_thread(mddev->thread); |
NeilBrown | 2515619 | 2008-03-04 14:29:32 -0800 | [diff] [blame] | 5603 | md_wakeup_thread(mddev->sync_thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 5604 | did_change = 1; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5605 | } |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5606 | atomic_inc(&mddev->writes_pending); |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 5607 | if (mddev->safemode == 1) |
| 5608 | mddev->safemode = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5609 | if (mddev->in_sync) { |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 5610 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5611 | if (mddev->in_sync) { |
| 5612 | mddev->in_sync = 0; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5613 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5614 | md_wakeup_thread(mddev->thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 5615 | did_change = 1; |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5616 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 5617 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5618 | } |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 5619 | if (did_change) |
| 5620 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
NeilBrown | 09a44cc | 2008-05-23 13:04:36 -0700 | [diff] [blame] | 5621 | wait_event(mddev->sb_wait, |
| 5622 | !test_bit(MD_CHANGE_CLEAN, &mddev->flags) && |
| 5623 | !test_bit(MD_CHANGE_PENDING, &mddev->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | void md_write_end(mddev_t *mddev) |
| 5627 | { |
| 5628 | if (atomic_dec_and_test(&mddev->writes_pending)) { |
| 5629 | if (mddev->safemode == 2) |
| 5630 | md_wakeup_thread(mddev->thread); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 5631 | else if (mddev->safemode_delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5632 | mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay); |
| 5633 | } |
| 5634 | } |
| 5635 | |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 5636 | /* md_allow_write(mddev) |
| 5637 | * Calling this ensures that the array is marked 'active' so that writes |
| 5638 | * may proceed without blocking. It is important to call this before |
| 5639 | * attempting a GFP_KERNEL allocation while holding the mddev lock. |
| 5640 | * Must be called with mddev_lock held. |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5641 | * |
| 5642 | * In the ->external case MD_CHANGE_CLEAN can not be cleared until mddev->lock |
| 5643 | * is dropped, so return -EAGAIN after notifying userspace. |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 5644 | */ |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5645 | int md_allow_write(mddev_t *mddev) |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 5646 | { |
| 5647 | if (!mddev->pers) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5648 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 5649 | if (mddev->ro) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5650 | return 0; |
Neil Brown | 1a0fd49 | 2008-06-28 08:31:27 +1000 | [diff] [blame] | 5651 | if (!mddev->pers->sync_request) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5652 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 5653 | |
| 5654 | spin_lock_irq(&mddev->write_lock); |
| 5655 | if (mddev->in_sync) { |
| 5656 | mddev->in_sync = 0; |
| 5657 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
| 5658 | if (mddev->safemode_delay && |
| 5659 | mddev->safemode == 0) |
| 5660 | mddev->safemode = 1; |
| 5661 | spin_unlock_irq(&mddev->write_lock); |
| 5662 | md_update_sb(mddev, 0); |
NeilBrown | 09a44cc | 2008-05-23 13:04:36 -0700 | [diff] [blame] | 5663 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 5664 | } else |
| 5665 | spin_unlock_irq(&mddev->write_lock); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5666 | |
| 5667 | if (test_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 5668 | return -EAGAIN; |
| 5669 | else |
| 5670 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 5671 | } |
| 5672 | EXPORT_SYMBOL_GPL(md_allow_write); |
| 5673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5674 | #define SYNC_MARKS 10 |
| 5675 | #define SYNC_MARK_STEP (3*HZ) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5676 | void md_do_sync(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | { |
| 5678 | mddev_t *mddev2; |
| 5679 | unsigned int currspeed = 0, |
| 5680 | window; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5681 | sector_t max_sectors,j, io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | unsigned long mark[SYNC_MARKS]; |
| 5683 | sector_t mark_cnt[SYNC_MARKS]; |
| 5684 | int last_mark,m; |
| 5685 | struct list_head *tmp; |
| 5686 | sector_t last_check; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5687 | int skipped = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5688 | struct list_head *rtmp; |
| 5689 | mdk_rdev_t *rdev; |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5690 | char *desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5691 | |
| 5692 | /* just incase thread restarts... */ |
| 5693 | if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) |
| 5694 | return; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5695 | if (mddev->ro) /* never try to sync a read-only array */ |
| 5696 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5697 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5698 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 5699 | if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 5700 | desc = "data-check"; |
| 5701 | else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 5702 | desc = "requested-resync"; |
| 5703 | else |
| 5704 | desc = "resync"; |
| 5705 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 5706 | desc = "reshape"; |
| 5707 | else |
| 5708 | desc = "recovery"; |
| 5709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5710 | /* we overload curr_resync somewhat here. |
| 5711 | * 0 == not engaged in resync at all |
| 5712 | * 2 == checking that there is no conflict with another sync |
| 5713 | * 1 == like 2, but have yielded to allow conflicting resync to |
| 5714 | * commense |
| 5715 | * other == active in resync - this many blocks |
| 5716 | * |
| 5717 | * Before starting a resync we must have set curr_resync to |
| 5718 | * 2, and then checked that every "conflicting" array has curr_resync |
| 5719 | * less than ours. When we find one that is the same or higher |
| 5720 | * we wait on resync_wait. To avoid deadlock, we reduce curr_resync |
| 5721 | * to 1 if we choose to yield (based arbitrarily on address of mddev structure). |
| 5722 | * This will mean we have to start checking from the beginning again. |
| 5723 | * |
| 5724 | */ |
| 5725 | |
| 5726 | do { |
| 5727 | mddev->curr_resync = 2; |
| 5728 | |
| 5729 | try_again: |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 5730 | if (kthread_should_stop()) { |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 5731 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | goto skip; |
| 5733 | } |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 5734 | for_each_mddev(mddev2, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | if (mddev2 == mddev) |
| 5736 | continue; |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 5737 | if (!mddev->parallel_resync |
| 5738 | && mddev2->curr_resync |
| 5739 | && match_mddev_units(mddev, mddev2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5740 | DEFINE_WAIT(wq); |
| 5741 | if (mddev < mddev2 && mddev->curr_resync == 2) { |
| 5742 | /* arbitrarily yield */ |
| 5743 | mddev->curr_resync = 1; |
| 5744 | wake_up(&resync_wait); |
| 5745 | } |
| 5746 | if (mddev > mddev2 && mddev->curr_resync == 1) |
| 5747 | /* no need to wait here, we can wait the next |
| 5748 | * time 'round when curr_resync == 2 |
| 5749 | */ |
| 5750 | continue; |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 5751 | prepare_to_wait(&resync_wait, &wq, TASK_UNINTERRUPTIBLE); |
| 5752 | if (!kthread_should_stop() && |
NeilBrown | 8712e55 | 2005-10-26 01:58:58 -0700 | [diff] [blame] | 5753 | mddev2->curr_resync >= mddev->curr_resync) { |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5754 | printk(KERN_INFO "md: delaying %s of %s" |
| 5755 | " until %s has finished (they" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5756 | " share one or more physical units)\n", |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5757 | desc, mdname(mddev), mdname(mddev2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | mddev_put(mddev2); |
| 5759 | schedule(); |
| 5760 | finish_wait(&resync_wait, &wq); |
| 5761 | goto try_again; |
| 5762 | } |
| 5763 | finish_wait(&resync_wait, &wq); |
| 5764 | } |
| 5765 | } |
| 5766 | } while (mddev->curr_resync < 2); |
| 5767 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5768 | j = 0; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 5769 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5770 | /* resync follows the size requested by the personality, |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5771 | * which defaults to physical size, but can be virtual size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5772 | */ |
| 5773 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 5774 | mddev->resync_mismatches = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5775 | /* we don't use the checkpoint if there's a bitmap */ |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 5776 | if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 5777 | j = mddev->resync_min; |
| 5778 | else if (!mddev->bitmap) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5779 | j = mddev->recovery_cp; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 5780 | |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 5781 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 5782 | max_sectors = mddev->size << 1; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5783 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | /* recovery follows the physical size of devices */ |
| 5785 | max_sectors = mddev->size << 1; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5786 | j = MaxSector; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 5787 | rdev_for_each(rdev, rtmp, mddev) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5788 | if (rdev->raid_disk >= 0 && |
| 5789 | !test_bit(Faulty, &rdev->flags) && |
| 5790 | !test_bit(In_sync, &rdev->flags) && |
| 5791 | rdev->recovery_offset < j) |
| 5792 | j = rdev->recovery_offset; |
| 5793 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5795 | printk(KERN_INFO "md: %s of RAID array %s\n", desc, mdname(mddev)); |
| 5796 | printk(KERN_INFO "md: minimum _guaranteed_ speed:" |
| 5797 | " %d KB/sec/disk.\n", speed_min(mddev)); |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 5798 | printk(KERN_INFO "md: using maximum available idle IO bandwidth " |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5799 | "(but not more than %d KB/sec) for %s.\n", |
| 5800 | speed_max(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5801 | |
| 5802 | is_mddev_idle(mddev); /* this also initializes IO event counters */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5803 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5804 | io_sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5805 | for (m = 0; m < SYNC_MARKS; m++) { |
| 5806 | mark[m] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5807 | mark_cnt[m] = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | } |
| 5809 | last_mark = 0; |
| 5810 | mddev->resync_mark = mark[last_mark]; |
| 5811 | mddev->resync_mark_cnt = mark_cnt[last_mark]; |
| 5812 | |
| 5813 | /* |
| 5814 | * Tune reconstruction: |
| 5815 | */ |
| 5816 | window = 32*(PAGE_SIZE/512); |
| 5817 | printk(KERN_INFO "md: using %dk window, over a total of %llu blocks.\n", |
| 5818 | window/2,(unsigned long long) max_sectors/2); |
| 5819 | |
| 5820 | atomic_set(&mddev->recovery_active, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5821 | last_check = 0; |
| 5822 | |
| 5823 | if (j>2) { |
| 5824 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5825 | "md: resuming %s of %s from checkpoint.\n", |
| 5826 | desc, mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5827 | mddev->curr_resync = j; |
| 5828 | } |
| 5829 | |
| 5830 | while (j < max_sectors) { |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5831 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5832 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5833 | skipped = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5834 | if (j >= mddev->resync_max) { |
| 5835 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
| 5836 | wait_event(mddev->recovery_wait, |
| 5837 | mddev->resync_max > j |
| 5838 | || kthread_should_stop()); |
| 5839 | } |
| 5840 | if (kthread_should_stop()) |
| 5841 | goto interrupted; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5842 | sectors = mddev->pers->sync_request(mddev, j, &skipped, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5843 | currspeed < speed_min(mddev)); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5844 | if (sectors == 0) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5845 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5846 | goto out; |
| 5847 | } |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5848 | |
| 5849 | if (!skipped) { /* actual IO requested */ |
| 5850 | io_sectors += sectors; |
| 5851 | atomic_add(sectors, &mddev->recovery_active); |
| 5852 | } |
| 5853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5854 | j += sectors; |
| 5855 | if (j>1) mddev->curr_resync = j; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 5856 | mddev->curr_mark_cnt = io_sectors; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5857 | if (last_check == 0) |
| 5858 | /* this is the earliers that rebuilt will be |
| 5859 | * visible in /proc/mdstat |
| 5860 | */ |
| 5861 | md_new_event(mddev); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5862 | |
| 5863 | if (last_check + window > io_sectors || j == max_sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5864 | continue; |
| 5865 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5866 | last_check = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5867 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5868 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5869 | break; |
| 5870 | |
| 5871 | repeat: |
| 5872 | if (time_after_eq(jiffies, mark[last_mark] + SYNC_MARK_STEP )) { |
| 5873 | /* step marks */ |
| 5874 | int next = (last_mark+1) % SYNC_MARKS; |
| 5875 | |
| 5876 | mddev->resync_mark = mark[next]; |
| 5877 | mddev->resync_mark_cnt = mark_cnt[next]; |
| 5878 | mark[next] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5879 | mark_cnt[next] = io_sectors - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | last_mark = next; |
| 5881 | } |
| 5882 | |
| 5883 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5884 | if (kthread_should_stop()) |
| 5885 | goto interrupted; |
| 5886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5887 | |
| 5888 | /* |
| 5889 | * this loop exits only if either when we are slower than |
| 5890 | * the 'hard' speed limit, or the system was IO-idle for |
| 5891 | * a jiffy. |
| 5892 | * the system might be non-idle CPU-wise, but we only care |
| 5893 | * about not overloading the IO subsystem. (things like an |
| 5894 | * e2fsck being done on the RAID array should execute fast) |
| 5895 | */ |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 5896 | blk_unplug(mddev->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5897 | cond_resched(); |
| 5898 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5899 | currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2 |
| 5900 | /((jiffies-mddev->resync_mark)/HZ +1) +1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5901 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 5902 | if (currspeed > speed_min(mddev)) { |
| 5903 | if ((currspeed > speed_max(mddev)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5904 | !is_mddev_idle(mddev)) { |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 5905 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5906 | goto repeat; |
| 5907 | } |
| 5908 | } |
| 5909 | } |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5910 | printk(KERN_INFO "md: %s: %s done.\n",mdname(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5911 | /* |
| 5912 | * this also signals 'finished resyncing' to md_stop |
| 5913 | */ |
| 5914 | out: |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 5915 | blk_unplug(mddev->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5916 | |
| 5917 | wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); |
| 5918 | |
| 5919 | /* tell personality that we are finished */ |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 5920 | mddev->pers->sync_request(mddev, max_sectors, &skipped, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5921 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5922 | if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) && |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5923 | mddev->curr_resync > 2) { |
| 5924 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 5925 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 5926 | if (mddev->curr_resync >= mddev->recovery_cp) { |
| 5927 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5928 | "md: checkpointing %s of %s.\n", |
| 5929 | desc, mdname(mddev)); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5930 | mddev->recovery_cp = mddev->curr_resync; |
| 5931 | } |
| 5932 | } else |
| 5933 | mddev->recovery_cp = MaxSector; |
| 5934 | } else { |
| 5935 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 5936 | mddev->curr_resync = MaxSector; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 5937 | rdev_for_each(rdev, rtmp, mddev) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5938 | if (rdev->raid_disk >= 0 && |
| 5939 | !test_bit(Faulty, &rdev->flags) && |
| 5940 | !test_bit(In_sync, &rdev->flags) && |
| 5941 | rdev->recovery_offset < mddev->curr_resync) |
| 5942 | rdev->recovery_offset = mddev->curr_resync; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 5943 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5944 | } |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 5945 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5947 | skip: |
| 5948 | mddev->curr_resync = 0; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 5949 | mddev->resync_min = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5950 | mddev->resync_max = MaxSector; |
| 5951 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5952 | wake_up(&resync_wait); |
| 5953 | set_bit(MD_RECOVERY_DONE, &mddev->recovery); |
| 5954 | md_wakeup_thread(mddev->thread); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5955 | return; |
| 5956 | |
| 5957 | interrupted: |
| 5958 | /* |
| 5959 | * got a signal, exit. |
| 5960 | */ |
| 5961 | printk(KERN_INFO |
| 5962 | "md: md_do_sync() got signal ... exiting\n"); |
| 5963 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 5964 | goto out; |
| 5965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5966 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5967 | EXPORT_SYMBOL_GPL(md_do_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5968 | |
| 5969 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 5970 | static int remove_and_add_spares(mddev_t *mddev) |
| 5971 | { |
| 5972 | mdk_rdev_t *rdev; |
| 5973 | struct list_head *rtmp; |
| 5974 | int spares = 0; |
| 5975 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 5976 | rdev_for_each(rdev, rtmp, mddev) |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 5977 | if (rdev->raid_disk >= 0 && |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 5978 | !test_bit(Blocked, &rdev->flags) && |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 5979 | (test_bit(Faulty, &rdev->flags) || |
| 5980 | ! test_bit(In_sync, &rdev->flags)) && |
| 5981 | atomic_read(&rdev->nr_pending)==0) { |
| 5982 | if (mddev->pers->hot_remove_disk( |
| 5983 | mddev, rdev->raid_disk)==0) { |
| 5984 | char nm[20]; |
| 5985 | sprintf(nm,"rd%d", rdev->raid_disk); |
| 5986 | sysfs_remove_link(&mddev->kobj, nm); |
| 5987 | rdev->raid_disk = -1; |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | if (mddev->degraded) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5992 | rdev_for_each(rdev, rtmp, mddev) { |
| 5993 | if (rdev->raid_disk >= 0 && |
| 5994 | !test_bit(In_sync, &rdev->flags)) |
| 5995 | spares++; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 5996 | if (rdev->raid_disk < 0 |
| 5997 | && !test_bit(Faulty, &rdev->flags)) { |
| 5998 | rdev->recovery_offset = 0; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5999 | if (mddev->pers-> |
| 6000 | hot_add_disk(mddev, rdev) == 0) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6001 | char nm[20]; |
| 6002 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 6003 | if (sysfs_create_link(&mddev->kobj, |
| 6004 | &rdev->kobj, nm)) |
| 6005 | printk(KERN_WARNING |
| 6006 | "md: cannot register " |
| 6007 | "%s for %s\n", |
| 6008 | nm, mdname(mddev)); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6009 | spares++; |
| 6010 | md_new_event(mddev); |
| 6011 | } else |
| 6012 | break; |
| 6013 | } |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6014 | } |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6015 | } |
| 6016 | return spares; |
| 6017 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6018 | /* |
| 6019 | * This routine is regularly called by all per-raid-array threads to |
| 6020 | * deal with generic issues like resync and super-block update. |
| 6021 | * Raid personalities that don't have a thread (linear/raid0) do not |
| 6022 | * need this as they never do any recovery or update the superblock. |
| 6023 | * |
| 6024 | * It does not do any resync itself, but rather "forks" off other threads |
| 6025 | * to do that as needed. |
| 6026 | * When it is determined that resync is needed, we set MD_RECOVERY_RUNNING in |
| 6027 | * "->recovery" and create a thread at ->sync_thread. |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6028 | * When the thread finishes it sets MD_RECOVERY_DONE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | * and wakeups up this thread which will reap the thread and finish up. |
| 6030 | * This thread also removes any faulty devices (with nr_pending == 0). |
| 6031 | * |
| 6032 | * The overall approach is: |
| 6033 | * 1/ if the superblock needs updating, update it. |
| 6034 | * 2/ If a recovery thread is running, don't do anything else. |
| 6035 | * 3/ If recovery has finished, clean up, possibly marking spares active. |
| 6036 | * 4/ If there are any faulty devices, remove them. |
| 6037 | * 5/ If array is degraded, try to add spares devices |
| 6038 | * 6/ If array has spares or is not in-sync, start a resync thread. |
| 6039 | */ |
| 6040 | void md_check_recovery(mddev_t *mddev) |
| 6041 | { |
| 6042 | mdk_rdev_t *rdev; |
| 6043 | struct list_head *rtmp; |
| 6044 | |
| 6045 | |
NeilBrown | 5f40402 | 2005-06-21 17:17:16 -0700 | [diff] [blame] | 6046 | if (mddev->bitmap) |
| 6047 | bitmap_daemon_work(mddev->bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6048 | |
| 6049 | if (mddev->ro) |
| 6050 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6051 | |
| 6052 | if (signal_pending(current)) { |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6053 | if (mddev->pers->sync_request && !mddev->external) { |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6054 | printk(KERN_INFO "md: %s in immediate safe mode\n", |
| 6055 | mdname(mddev)); |
| 6056 | mddev->safemode = 2; |
| 6057 | } |
| 6058 | flush_signals(current); |
| 6059 | } |
| 6060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6061 | if ( ! ( |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 6062 | (mddev->flags && !mddev->external) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6063 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6064 | test_bit(MD_RECOVERY_DONE, &mddev->recovery) || |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6065 | (mddev->external == 0 && mddev->safemode == 1) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6066 | (mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending) |
| 6067 | && !mddev->in_sync && mddev->recovery_cp == MaxSector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6068 | )) |
| 6069 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6070 | |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 6071 | if (mddev_trylock(mddev)) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6072 | int spares = 0; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6073 | |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6074 | if (!mddev->external) { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6075 | int did_change = 0; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6076 | spin_lock_irq(&mddev->write_lock); |
| 6077 | if (mddev->safemode && |
| 6078 | !atomic_read(&mddev->writes_pending) && |
| 6079 | !mddev->in_sync && |
| 6080 | mddev->recovery_cp == MaxSector) { |
| 6081 | mddev->in_sync = 1; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6082 | did_change = 1; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6083 | if (mddev->persistent) |
| 6084 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
| 6085 | } |
| 6086 | if (mddev->safemode == 1) |
| 6087 | mddev->safemode = 0; |
| 6088 | spin_unlock_irq(&mddev->write_lock); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6089 | if (did_change) |
| 6090 | sysfs_notify(&mddev->kobj, NULL, "array_state"); |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6091 | } |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6092 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6093 | if (mddev->flags) |
| 6094 | md_update_sb(mddev, 0); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6095 | |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 6096 | rdev_for_each(rdev, rtmp, mddev) |
| 6097 | if (test_and_clear_bit(StateChanged, &rdev->flags)) |
| 6098 | sysfs_notify(&rdev->kobj, NULL, "state"); |
| 6099 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6101 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && |
| 6102 | !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) { |
| 6103 | /* resync/recovery still happening */ |
| 6104 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6105 | goto unlock; |
| 6106 | } |
| 6107 | if (mddev->sync_thread) { |
| 6108 | /* resync has finished, collect result */ |
| 6109 | md_unregister_thread(mddev->sync_thread); |
| 6110 | mddev->sync_thread = NULL; |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6111 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6112 | /* success...*/ |
| 6113 | /* activate any spares */ |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 6114 | if (mddev->pers->spare_active(mddev)) |
| 6115 | sysfs_notify(&mddev->kobj, NULL, |
| 6116 | "degraded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6117 | } |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6118 | md_update_sb(mddev, 1); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 6119 | |
| 6120 | /* if array is no-longer degraded, then any saved_raid_disk |
| 6121 | * information must be scrapped |
| 6122 | */ |
| 6123 | if (!mddev->degraded) |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 6124 | rdev_for_each(rdev, rtmp, mddev) |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 6125 | rdev->saved_raid_disk = -1; |
| 6126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6127 | mddev->recovery = 0; |
| 6128 | /* flag recovery needed just to double check */ |
| 6129 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6130 | sysfs_notify(&mddev->kobj, NULL, "sync_action"); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6131 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6132 | goto unlock; |
| 6133 | } |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6134 | /* Set RUNNING before clearing NEEDED to avoid |
| 6135 | * any transients in the value of "sync_action". |
| 6136 | */ |
| 6137 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 6138 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6139 | /* Clear some bits that don't mean anything, but |
| 6140 | * might be left set |
| 6141 | */ |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6142 | clear_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 6143 | clear_bit(MD_RECOVERY_DONE, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6145 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 6146 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6147 | /* no recovery is running. |
| 6148 | * remove any failed drives, then |
| 6149 | * add spares if possible. |
| 6150 | * Spare are also removed and re-added, to allow |
| 6151 | * the personality to fail the re-add. |
| 6152 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6153 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6154 | if (mddev->reshape_position != MaxSector) { |
| 6155 | if (mddev->pers->check_reshape(mddev) != 0) |
| 6156 | /* Cannot proceed */ |
| 6157 | goto unlock; |
| 6158 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6159 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6160 | } else if ((spares = remove_and_add_spares(mddev))) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6161 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 6162 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6163 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6164 | } else if (mddev->recovery_cp < MaxSector) { |
| 6165 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6166 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6167 | } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 6168 | /* nothing to be done ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6169 | goto unlock; |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6171 | if (mddev->pers->sync_request) { |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 6172 | if (spares && mddev->bitmap && ! mddev->bitmap->file) { |
| 6173 | /* We are adding a device or devices to an array |
| 6174 | * which has the bitmap stored on all devices. |
| 6175 | * So make sure all bitmap pages get written |
| 6176 | */ |
| 6177 | bitmap_write_all(mddev->bitmap); |
| 6178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6179 | mddev->sync_thread = md_register_thread(md_do_sync, |
| 6180 | mddev, |
| 6181 | "%s_resync"); |
| 6182 | if (!mddev->sync_thread) { |
| 6183 | printk(KERN_ERR "%s: could not start resync" |
| 6184 | " thread...\n", |
| 6185 | mdname(mddev)); |
| 6186 | /* leave the spares where they are, it shouldn't hurt */ |
| 6187 | mddev->recovery = 0; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6188 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6189 | md_wakeup_thread(mddev->sync_thread); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6190 | sysfs_notify(&mddev->kobj, NULL, "sync_action"); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6191 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6192 | } |
| 6193 | unlock: |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6194 | if (!mddev->sync_thread) { |
| 6195 | clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 6196 | if (test_and_clear_bit(MD_RECOVERY_RECOVER, |
| 6197 | &mddev->recovery)) |
| 6198 | sysfs_notify(&mddev->kobj, NULL, "sync_action"); |
| 6199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6200 | mddev_unlock(mddev); |
| 6201 | } |
| 6202 | } |
| 6203 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 6204 | void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 6205 | { |
| 6206 | sysfs_notify(&rdev->kobj, NULL, "state"); |
| 6207 | wait_event_timeout(rdev->blocked_wait, |
| 6208 | !test_bit(Blocked, &rdev->flags), |
| 6209 | msecs_to_jiffies(5000)); |
| 6210 | rdev_dec_pending(rdev, mddev); |
| 6211 | } |
| 6212 | EXPORT_SYMBOL(md_wait_for_blocked_rdev); |
| 6213 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 6214 | static int md_notify_reboot(struct notifier_block *this, |
| 6215 | unsigned long code, void *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6216 | { |
| 6217 | struct list_head *tmp; |
| 6218 | mddev_t *mddev; |
| 6219 | |
| 6220 | if ((code == SYS_DOWN) || (code == SYS_HALT) || (code == SYS_POWER_OFF)) { |
| 6221 | |
| 6222 | printk(KERN_INFO "md: stopping all md devices.\n"); |
| 6223 | |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 6224 | for_each_mddev(mddev, tmp) |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 6225 | if (mddev_trylock(mddev)) { |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 6226 | do_md_stop (mddev, 1, 0); |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 6227 | mddev_unlock(mddev); |
| 6228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6229 | /* |
| 6230 | * certain more exotic SCSI devices are known to be |
| 6231 | * volatile wrt too early system reboots. While the |
| 6232 | * right place to handle this issue is the given |
| 6233 | * driver, we do want to have a safe RAID driver ... |
| 6234 | */ |
| 6235 | mdelay(1000*1); |
| 6236 | } |
| 6237 | return NOTIFY_DONE; |
| 6238 | } |
| 6239 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 6240 | static struct notifier_block md_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | .notifier_call = md_notify_reboot, |
| 6242 | .next = NULL, |
| 6243 | .priority = INT_MAX, /* before any real devices */ |
| 6244 | }; |
| 6245 | |
| 6246 | static void md_geninit(void) |
| 6247 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6248 | dprintk("md: sizeof(mdp_super_t) = %d\n", (int)sizeof(mdp_super_t)); |
| 6249 | |
Denis V. Lunev | c7705f344 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 6250 | proc_create("mdstat", S_IRUGO, NULL, &md_seq_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6251 | } |
| 6252 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 6253 | static int __init md_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6254 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6255 | if (register_blkdev(MAJOR_NR, "md")) |
| 6256 | return -1; |
| 6257 | if ((mdp_major=register_blkdev(0, "mdp"))<=0) { |
| 6258 | unregister_blkdev(MAJOR_NR, "md"); |
| 6259 | return -1; |
| 6260 | } |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 6261 | blk_register_region(MKDEV(MAJOR_NR, 0), 1UL<<MINORBITS, THIS_MODULE, |
| 6262 | md_probe, NULL, NULL); |
| 6263 | blk_register_region(MKDEV(mdp_major, 0), 1UL<<MINORBITS, THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6264 | md_probe, NULL, NULL); |
| 6265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6266 | register_reboot_notifier(&md_notifier); |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 6267 | raid_table_header = register_sysctl_table(raid_root_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6268 | |
| 6269 | md_geninit(); |
| 6270 | return (0); |
| 6271 | } |
| 6272 | |
| 6273 | |
| 6274 | #ifndef MODULE |
| 6275 | |
| 6276 | /* |
| 6277 | * Searches all registered partitions for autorun RAID arrays |
| 6278 | * at boot time. |
| 6279 | */ |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 6280 | |
| 6281 | static LIST_HEAD(all_detected_devices); |
| 6282 | struct detected_devices_node { |
| 6283 | struct list_head list; |
| 6284 | dev_t dev; |
| 6285 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6286 | |
| 6287 | void md_autodetect_dev(dev_t dev) |
| 6288 | { |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 6289 | struct detected_devices_node *node_detected_dev; |
| 6290 | |
| 6291 | node_detected_dev = kzalloc(sizeof(*node_detected_dev), GFP_KERNEL); |
| 6292 | if (node_detected_dev) { |
| 6293 | node_detected_dev->dev = dev; |
| 6294 | list_add_tail(&node_detected_dev->list, &all_detected_devices); |
| 6295 | } else { |
| 6296 | printk(KERN_CRIT "md: md_autodetect_dev: kzalloc failed" |
| 6297 | ", skipping dev(%d,%d)\n", MAJOR(dev), MINOR(dev)); |
| 6298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | |
| 6302 | static void autostart_arrays(int part) |
| 6303 | { |
| 6304 | mdk_rdev_t *rdev; |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 6305 | struct detected_devices_node *node_detected_dev; |
| 6306 | dev_t dev; |
| 6307 | int i_scanned, i_passed; |
| 6308 | |
| 6309 | i_scanned = 0; |
| 6310 | i_passed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6311 | |
| 6312 | printk(KERN_INFO "md: Autodetecting RAID arrays.\n"); |
| 6313 | |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 6314 | while (!list_empty(&all_detected_devices) && i_scanned < INT_MAX) { |
| 6315 | i_scanned++; |
| 6316 | node_detected_dev = list_entry(all_detected_devices.next, |
| 6317 | struct detected_devices_node, list); |
| 6318 | list_del(&node_detected_dev->list); |
| 6319 | dev = node_detected_dev->dev; |
| 6320 | kfree(node_detected_dev); |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 6321 | rdev = md_import_device(dev,0, 90); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | if (IS_ERR(rdev)) |
| 6323 | continue; |
| 6324 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6325 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6326 | MD_BUG(); |
| 6327 | continue; |
| 6328 | } |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 6329 | set_bit(AutoDetected, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6330 | list_add(&rdev->same_set, &pending_raid_disks); |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 6331 | i_passed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6332 | } |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 6333 | |
| 6334 | printk(KERN_INFO "md: Scanned %d and added %d devices.\n", |
| 6335 | i_scanned, i_passed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | |
| 6337 | autorun_devices(part); |
| 6338 | } |
| 6339 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 6340 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6341 | |
| 6342 | static __exit void md_exit(void) |
| 6343 | { |
| 6344 | mddev_t *mddev; |
| 6345 | struct list_head *tmp; |
Greg Kroah-Hartman | 8ab5e4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 6346 | |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 6347 | blk_unregister_region(MKDEV(MAJOR_NR,0), 1U << MINORBITS); |
| 6348 | blk_unregister_region(MKDEV(mdp_major,0), 1U << MINORBITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6349 | |
| 6350 | unregister_blkdev(MAJOR_NR,"md"); |
| 6351 | unregister_blkdev(mdp_major, "mdp"); |
| 6352 | unregister_reboot_notifier(&md_notifier); |
| 6353 | unregister_sysctl_table(raid_table_header); |
| 6354 | remove_proc_entry("mdstat", NULL); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 6355 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6356 | struct gendisk *disk = mddev->gendisk; |
| 6357 | if (!disk) |
| 6358 | continue; |
| 6359 | export_array(mddev); |
| 6360 | del_gendisk(disk); |
| 6361 | put_disk(disk); |
| 6362 | mddev->gendisk = NULL; |
| 6363 | mddev_put(mddev); |
| 6364 | } |
| 6365 | } |
| 6366 | |
Dan Williams | 685784a | 2007-07-09 11:56:42 -0700 | [diff] [blame] | 6367 | subsys_initcall(md_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6368 | module_exit(md_exit) |
| 6369 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6370 | static int get_ro(char *buffer, struct kernel_param *kp) |
| 6371 | { |
| 6372 | return sprintf(buffer, "%d", start_readonly); |
| 6373 | } |
| 6374 | static int set_ro(const char *val, struct kernel_param *kp) |
| 6375 | { |
| 6376 | char *e; |
| 6377 | int num = simple_strtoul(val, &e, 10); |
| 6378 | if (*val && (*e == '\0' || *e == '\n')) { |
| 6379 | start_readonly = num; |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 6380 | return 0; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6381 | } |
| 6382 | return -EINVAL; |
| 6383 | } |
| 6384 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 6385 | module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); |
| 6386 | module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR); |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 6387 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6389 | EXPORT_SYMBOL(register_md_personality); |
| 6390 | EXPORT_SYMBOL(unregister_md_personality); |
| 6391 | EXPORT_SYMBOL(md_error); |
| 6392 | EXPORT_SYMBOL(md_done_sync); |
| 6393 | EXPORT_SYMBOL(md_write_start); |
| 6394 | EXPORT_SYMBOL(md_write_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6395 | EXPORT_SYMBOL(md_register_thread); |
| 6396 | EXPORT_SYMBOL(md_unregister_thread); |
| 6397 | EXPORT_SYMBOL(md_wakeup_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6398 | EXPORT_SYMBOL(md_check_recovery); |
| 6399 | MODULE_LICENSE("GPL"); |
NeilBrown | aa1595e | 2005-08-04 12:53:32 -0700 | [diff] [blame] | 6400 | MODULE_ALIAS("md"); |
NeilBrown | 7200865 | 2005-08-26 18:34:15 -0700 | [diff] [blame] | 6401 | MODULE_ALIAS_BLOCKDEV_MAJOR(MD_MAJOR); |