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 | |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 35 | #include <linux/kthread.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 36 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/sysctl.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 38 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/buffer_head.h> /* for invalidate_bdev */ |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 40 | #include <linux/poll.h> |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 41 | #include <linux/ctype.h> |
NeilBrown | fb4d8c7 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 42 | #include <linux/hdreg.h> |
| 43 | #include <linux/proc_fs.h> |
| 44 | #include <linux/random.h> |
| 45 | #include <linux/reboot.h> |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 46 | #include <linux/file.h> |
Stephen Rothwell | 2557072 | 2008-10-15 09:09:21 +1100 | [diff] [blame] | 47 | #include <linux/delay.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 48 | #include <linux/raid/md_p.h> |
| 49 | #include <linux/raid/md_u.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 50 | #include "md.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 51 | #include "bitmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | #define DEBUG 0 |
| 54 | #define dprintk(x...) ((void)(DEBUG && printk(x))) |
| 55 | |
| 56 | |
| 57 | #ifndef MODULE |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 58 | static void autostart_arrays(int part); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #endif |
| 60 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 61 | static LIST_HEAD(pers_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static DEFINE_SPINLOCK(pers_lock); |
| 63 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 64 | static void md_print_devices(void); |
| 65 | |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 66 | static DECLARE_WAIT_QUEUE_HEAD(resync_wait); |
| 67 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 68 | #define MD_BUG(x...) { printk("md: bug in file %s, line %d\n", __FILE__, __LINE__); md_print_devices(); } |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Current RAID-1,4,5 parallel reconstruction 'guaranteed speed limit' |
| 72 | * is 1000 KB/sec, so the extra system load does not show up that much. |
| 73 | * Increase it if you want to have more _guaranteed_ speed. Note that |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 74 | * the RAID driver will use the maximum available bandwidth if the IO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * subsystem is idle. There is also an 'absolute maximum' reconstruction |
| 76 | * speed limit - in case reconstruction slows down your system despite |
| 77 | * idle IO detection. |
| 78 | * |
| 79 | * 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] | 80 | * or /sys/block/mdX/md/sync_speed_{min,max} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | */ |
| 82 | |
| 83 | static int sysctl_speed_limit_min = 1000; |
| 84 | static int sysctl_speed_limit_max = 200000; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 85 | static inline int speed_min(mddev_t *mddev) |
| 86 | { |
| 87 | return mddev->sync_speed_min ? |
| 88 | mddev->sync_speed_min : sysctl_speed_limit_min; |
| 89 | } |
| 90 | |
| 91 | static inline int speed_max(mddev_t *mddev) |
| 92 | { |
| 93 | return mddev->sync_speed_max ? |
| 94 | mddev->sync_speed_max : sysctl_speed_limit_max; |
| 95 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | static struct ctl_table_header *raid_table_header; |
| 98 | |
| 99 | static ctl_table raid_table[] = { |
| 100 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | .procname = "speed_limit_min", |
| 102 | .data = &sysctl_speed_limit_min, |
| 103 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 104 | .mode = S_IRUGO|S_IWUSR, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 105 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }, |
| 107 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | .procname = "speed_limit_max", |
| 109 | .data = &sysctl_speed_limit_max, |
| 110 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 111 | .mode = S_IRUGO|S_IWUSR, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 112 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 114 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | static ctl_table raid_dir_table[] = { |
| 118 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | .procname = "raid", |
| 120 | .maxlen = 0, |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 121 | .mode = S_IRUGO|S_IXUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | .child = raid_table, |
| 123 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 124 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | static ctl_table raid_root_table[] = { |
| 128 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | .procname = "dev", |
| 130 | .maxlen = 0, |
| 131 | .mode = 0555, |
| 132 | .child = raid_dir_table, |
| 133 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 134 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 137 | static const struct block_device_operations md_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 139 | static int start_readonly; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 142 | * We have a system wide 'event count' that is incremented |
| 143 | * on any 'interesting' event, and readers of /proc/mdstat |
| 144 | * can use 'poll' or 'select' to find out when the event |
| 145 | * count increases. |
| 146 | * |
| 147 | * Events are: |
| 148 | * start array, stop array, error, add device, remove device, |
| 149 | * start build, activate spare |
| 150 | */ |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 151 | static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 152 | static atomic_t md_event_count; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 153 | void md_new_event(mddev_t *mddev) |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 154 | { |
| 155 | atomic_inc(&md_event_count); |
| 156 | wake_up(&md_event_waiters); |
| 157 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 158 | EXPORT_SYMBOL_GPL(md_new_event); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 159 | |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 160 | /* Alternate version that can be called from interrupts |
| 161 | * when calling sysfs_notify isn't needed. |
| 162 | */ |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 163 | static void md_new_event_inintr(mddev_t *mddev) |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 164 | { |
| 165 | atomic_inc(&md_event_count); |
| 166 | wake_up(&md_event_waiters); |
| 167 | } |
| 168 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 169 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | * Enables to iterate over all existing md arrays |
| 171 | * all_mddevs_lock protects this list. |
| 172 | */ |
| 173 | static LIST_HEAD(all_mddevs); |
| 174 | static DEFINE_SPINLOCK(all_mddevs_lock); |
| 175 | |
| 176 | |
| 177 | /* |
| 178 | * iterates through all used mddevs in the system. |
| 179 | * We take care to grab the all_mddevs_lock whenever navigating |
| 180 | * the list, and to always hold a refcount when unlocked. |
| 181 | * Any code which breaks out of this loop while own |
| 182 | * a reference to the current mddev and must mddev_put it. |
| 183 | */ |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 184 | #define for_each_mddev(mddev,tmp) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | \ |
| 186 | for (({ spin_lock(&all_mddevs_lock); \ |
| 187 | tmp = all_mddevs.next; \ |
| 188 | mddev = NULL;}); \ |
| 189 | ({ if (tmp != &all_mddevs) \ |
| 190 | mddev_get(list_entry(tmp, mddev_t, all_mddevs));\ |
| 191 | spin_unlock(&all_mddevs_lock); \ |
| 192 | if (mddev) mddev_put(mddev); \ |
| 193 | mddev = list_entry(tmp, mddev_t, all_mddevs); \ |
| 194 | tmp != &all_mddevs;}); \ |
| 195 | ({ spin_lock(&all_mddevs_lock); \ |
| 196 | tmp = tmp->next;}) \ |
| 197 | ) |
| 198 | |
| 199 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 200 | /* Rather than calling directly into the personality make_request function, |
| 201 | * IO requests come here first so that we can check if the device is |
| 202 | * being suspended pending a reconfiguration. |
| 203 | * We hold a refcount over the call to ->make_request. By the time that |
| 204 | * call has finished, the bio has been linked into some internal structure |
| 205 | * and so is visible to ->quiesce(), so we don't need the refcount any more. |
| 206 | */ |
| 207 | static int md_make_request(struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 209 | mddev_t *mddev = q->queuedata; |
| 210 | int rv; |
| 211 | if (mddev == NULL || mddev->pers == NULL) { |
| 212 | bio_io_error(bio); |
| 213 | return 0; |
| 214 | } |
| 215 | rcu_read_lock(); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 216 | if (mddev->suspended || mddev->barrier) { |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 217 | DEFINE_WAIT(__wait); |
| 218 | for (;;) { |
| 219 | prepare_to_wait(&mddev->sb_wait, &__wait, |
| 220 | TASK_UNINTERRUPTIBLE); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 221 | if (!mddev->suspended && !mddev->barrier) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 222 | break; |
| 223 | rcu_read_unlock(); |
| 224 | schedule(); |
| 225 | rcu_read_lock(); |
| 226 | } |
| 227 | finish_wait(&mddev->sb_wait, &__wait); |
| 228 | } |
| 229 | atomic_inc(&mddev->active_io); |
| 230 | rcu_read_unlock(); |
| 231 | rv = mddev->pers->make_request(q, bio); |
| 232 | if (atomic_dec_and_test(&mddev->active_io) && mddev->suspended) |
| 233 | wake_up(&mddev->sb_wait); |
| 234 | |
| 235 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 238 | static void mddev_suspend(mddev_t *mddev) |
| 239 | { |
| 240 | BUG_ON(mddev->suspended); |
| 241 | mddev->suspended = 1; |
| 242 | synchronize_rcu(); |
| 243 | wait_event(mddev->sb_wait, atomic_read(&mddev->active_io) == 0); |
| 244 | mddev->pers->quiesce(mddev, 1); |
| 245 | md_unregister_thread(mddev->thread); |
| 246 | mddev->thread = NULL; |
| 247 | /* we now know that no code is executing in the personality module, |
| 248 | * except possibly the tail end of a ->bi_end_io function, but that |
| 249 | * is certain to complete before the module has a chance to get |
| 250 | * unloaded |
| 251 | */ |
| 252 | } |
| 253 | |
| 254 | static void mddev_resume(mddev_t *mddev) |
| 255 | { |
| 256 | mddev->suspended = 0; |
| 257 | wake_up(&mddev->sb_wait); |
| 258 | mddev->pers->quiesce(mddev, 0); |
| 259 | } |
| 260 | |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 261 | int mddev_congested(mddev_t *mddev, int bits) |
| 262 | { |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 263 | if (mddev->barrier) |
| 264 | return 1; |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 265 | return mddev->suspended; |
| 266 | } |
| 267 | EXPORT_SYMBOL(mddev_congested); |
| 268 | |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 269 | /* |
| 270 | * Generic barrier handling for md |
| 271 | */ |
| 272 | |
| 273 | #define POST_REQUEST_BARRIER ((void*)1) |
| 274 | |
| 275 | static void md_end_barrier(struct bio *bio, int err) |
| 276 | { |
| 277 | mdk_rdev_t *rdev = bio->bi_private; |
| 278 | mddev_t *mddev = rdev->mddev; |
| 279 | if (err == -EOPNOTSUPP && mddev->barrier != POST_REQUEST_BARRIER) |
| 280 | set_bit(BIO_EOPNOTSUPP, &mddev->barrier->bi_flags); |
| 281 | |
| 282 | rdev_dec_pending(rdev, mddev); |
| 283 | |
| 284 | if (atomic_dec_and_test(&mddev->flush_pending)) { |
| 285 | if (mddev->barrier == POST_REQUEST_BARRIER) { |
| 286 | /* This was a post-request barrier */ |
| 287 | mddev->barrier = NULL; |
| 288 | wake_up(&mddev->sb_wait); |
| 289 | } else |
| 290 | /* The pre-request barrier has finished */ |
| 291 | schedule_work(&mddev->barrier_work); |
| 292 | } |
| 293 | bio_put(bio); |
| 294 | } |
| 295 | |
| 296 | static void submit_barriers(mddev_t *mddev) |
| 297 | { |
| 298 | mdk_rdev_t *rdev; |
| 299 | |
| 300 | rcu_read_lock(); |
| 301 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
| 302 | if (rdev->raid_disk >= 0 && |
| 303 | !test_bit(Faulty, &rdev->flags)) { |
| 304 | /* Take two references, one is dropped |
| 305 | * when request finishes, one after |
| 306 | * we reclaim rcu_read_lock |
| 307 | */ |
| 308 | struct bio *bi; |
| 309 | atomic_inc(&rdev->nr_pending); |
| 310 | atomic_inc(&rdev->nr_pending); |
| 311 | rcu_read_unlock(); |
| 312 | bi = bio_alloc(GFP_KERNEL, 0); |
| 313 | bi->bi_end_io = md_end_barrier; |
| 314 | bi->bi_private = rdev; |
| 315 | bi->bi_bdev = rdev->bdev; |
| 316 | atomic_inc(&mddev->flush_pending); |
| 317 | submit_bio(WRITE_BARRIER, bi); |
| 318 | rcu_read_lock(); |
| 319 | rdev_dec_pending(rdev, mddev); |
| 320 | } |
| 321 | rcu_read_unlock(); |
| 322 | } |
| 323 | |
| 324 | static void md_submit_barrier(struct work_struct *ws) |
| 325 | { |
| 326 | mddev_t *mddev = container_of(ws, mddev_t, barrier_work); |
| 327 | struct bio *bio = mddev->barrier; |
| 328 | |
| 329 | atomic_set(&mddev->flush_pending, 1); |
| 330 | |
| 331 | if (test_bit(BIO_EOPNOTSUPP, &bio->bi_flags)) |
| 332 | bio_endio(bio, -EOPNOTSUPP); |
| 333 | else if (bio->bi_size == 0) |
| 334 | /* an empty barrier - all done */ |
| 335 | bio_endio(bio, 0); |
| 336 | else { |
| 337 | bio->bi_rw &= ~(1<<BIO_RW_BARRIER); |
| 338 | if (mddev->pers->make_request(mddev->queue, bio)) |
| 339 | generic_make_request(bio); |
| 340 | mddev->barrier = POST_REQUEST_BARRIER; |
| 341 | submit_barriers(mddev); |
| 342 | } |
| 343 | if (atomic_dec_and_test(&mddev->flush_pending)) { |
| 344 | mddev->barrier = NULL; |
| 345 | wake_up(&mddev->sb_wait); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | void md_barrier_request(mddev_t *mddev, struct bio *bio) |
| 350 | { |
| 351 | spin_lock_irq(&mddev->write_lock); |
| 352 | wait_event_lock_irq(mddev->sb_wait, |
| 353 | !mddev->barrier, |
| 354 | mddev->write_lock, /*nothing*/); |
| 355 | mddev->barrier = bio; |
| 356 | spin_unlock_irq(&mddev->write_lock); |
| 357 | |
| 358 | atomic_set(&mddev->flush_pending, 1); |
| 359 | INIT_WORK(&mddev->barrier_work, md_submit_barrier); |
| 360 | |
| 361 | submit_barriers(mddev); |
| 362 | |
| 363 | if (atomic_dec_and_test(&mddev->flush_pending)) |
| 364 | schedule_work(&mddev->barrier_work); |
| 365 | } |
| 366 | EXPORT_SYMBOL(md_barrier_request); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | static inline mddev_t *mddev_get(mddev_t *mddev) |
| 369 | { |
| 370 | atomic_inc(&mddev->active); |
| 371 | return mddev; |
| 372 | } |
| 373 | |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 374 | static void mddev_delayed_delete(struct work_struct *ws); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | static void mddev_put(mddev_t *mddev) |
| 377 | { |
| 378 | if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock)) |
| 379 | return; |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 380 | if (!mddev->raid_disks && list_empty(&mddev->disks) && |
| 381 | !mddev->hold_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | list_del(&mddev->all_mddevs); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 383 | if (mddev->gendisk) { |
| 384 | /* we did a probe so need to clean up. |
| 385 | * Call schedule_work inside the spinlock |
| 386 | * so that flush_scheduled_work() after |
| 387 | * mddev_find will succeed in waiting for the |
| 388 | * work to be done. |
| 389 | */ |
| 390 | INIT_WORK(&mddev->del_work, mddev_delayed_delete); |
| 391 | schedule_work(&mddev->del_work); |
| 392 | } else |
| 393 | kfree(mddev); |
| 394 | } |
| 395 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | static mddev_t * mddev_find(dev_t unit) |
| 399 | { |
| 400 | mddev_t *mddev, *new = NULL; |
| 401 | |
| 402 | retry: |
| 403 | spin_lock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 405 | if (unit) { |
| 406 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 407 | if (mddev->unit == unit) { |
| 408 | mddev_get(mddev); |
| 409 | spin_unlock(&all_mddevs_lock); |
| 410 | kfree(new); |
| 411 | return mddev; |
| 412 | } |
| 413 | |
| 414 | if (new) { |
| 415 | list_add(&new->all_mddevs, &all_mddevs); |
| 416 | spin_unlock(&all_mddevs_lock); |
| 417 | new->hold_active = UNTIL_IOCTL; |
| 418 | return new; |
| 419 | } |
| 420 | } else if (new) { |
| 421 | /* find an unused unit number */ |
| 422 | static int next_minor = 512; |
| 423 | int start = next_minor; |
| 424 | int is_free = 0; |
| 425 | int dev = 0; |
| 426 | while (!is_free) { |
| 427 | dev = MKDEV(MD_MAJOR, next_minor); |
| 428 | next_minor++; |
| 429 | if (next_minor > MINORMASK) |
| 430 | next_minor = 0; |
| 431 | if (next_minor == start) { |
| 432 | /* Oh dear, all in use. */ |
| 433 | spin_unlock(&all_mddevs_lock); |
| 434 | kfree(new); |
| 435 | return NULL; |
| 436 | } |
| 437 | |
| 438 | is_free = 1; |
| 439 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 440 | if (mddev->unit == dev) { |
| 441 | is_free = 0; |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | new->unit = dev; |
| 446 | new->md_minor = MINOR(dev); |
| 447 | new->hold_active = UNTIL_STOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | list_add(&new->all_mddevs, &all_mddevs); |
| 449 | spin_unlock(&all_mddevs_lock); |
| 450 | return new; |
| 451 | } |
| 452 | spin_unlock(&all_mddevs_lock); |
| 453 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 454 | new = kzalloc(sizeof(*new), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | if (!new) |
| 456 | return NULL; |
| 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | new->unit = unit; |
| 459 | if (MAJOR(unit) == MD_MAJOR) |
| 460 | new->md_minor = MINOR(unit); |
| 461 | else |
| 462 | new->md_minor = MINOR(unit) >> MdpMinorShift; |
| 463 | |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 464 | mutex_init(&new->open_mutex); |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 465 | mutex_init(&new->reconfig_mutex); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 466 | mutex_init(&new->bitmap_info.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | INIT_LIST_HEAD(&new->disks); |
| 468 | INIT_LIST_HEAD(&new->all_mddevs); |
| 469 | init_timer(&new->safemode_timer); |
| 470 | atomic_set(&new->active, 1); |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 471 | atomic_set(&new->openers, 0); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 472 | atomic_set(&new->active_io, 0); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 473 | spin_lock_init(&new->write_lock); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 474 | atomic_set(&new->flush_pending, 0); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 475 | init_waitqueue_head(&new->sb_wait); |
Dan Williams | a6d8113 | 2008-06-05 22:45:53 -0700 | [diff] [blame] | 476 | init_waitqueue_head(&new->recovery_wait); |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 477 | new->reshape_position = MaxSector; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 478 | new->resync_min = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 479 | new->resync_max = MaxSector; |
NeilBrown | d897dbf | 2008-04-30 00:52:29 -0700 | [diff] [blame] | 480 | new->level = LEVEL_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | goto retry; |
| 483 | } |
| 484 | |
| 485 | static inline int mddev_lock(mddev_t * mddev) |
| 486 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 487 | return mutex_lock_interruptible(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 490 | static inline int mddev_is_locked(mddev_t *mddev) |
| 491 | { |
| 492 | return mutex_is_locked(&mddev->reconfig_mutex); |
| 493 | } |
| 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | static inline int mddev_trylock(mddev_t * mddev) |
| 496 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 497 | return mutex_trylock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static inline void mddev_unlock(mddev_t * mddev) |
| 501 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 502 | mutex_unlock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 504 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 507 | static mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 509 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 511 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | if (rdev->desc_nr == nr) |
| 513 | return rdev; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | return NULL; |
| 516 | } |
| 517 | |
| 518 | static mdk_rdev_t * find_rdev(mddev_t * mddev, dev_t dev) |
| 519 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | mdk_rdev_t *rdev; |
| 521 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 522 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | if (rdev->bdev->bd_dev == dev) |
| 524 | return rdev; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | return NULL; |
| 527 | } |
| 528 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 529 | static struct mdk_personality *find_pers(int level, char *clevel) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 530 | { |
| 531 | struct mdk_personality *pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 532 | list_for_each_entry(pers, &pers_list, list) { |
| 533 | if (level != LEVEL_NONE && pers->level == level) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 534 | return pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 535 | if (strcmp(pers->name, clevel)==0) |
| 536 | return pers; |
| 537 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 538 | return NULL; |
| 539 | } |
| 540 | |
Andre Noll | b73df2d | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 541 | /* return the offset of the super block in 512byte sectors */ |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 542 | static inline sector_t calc_dev_sboffset(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
Andre Noll | b73df2d | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 544 | sector_t num_sectors = bdev->bd_inode->i_size / 512; |
| 545 | return MD_NEW_SIZE_SECTORS(num_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | static int alloc_disk_sb(mdk_rdev_t * rdev) |
| 549 | { |
| 550 | if (rdev->sb_page) |
| 551 | MD_BUG(); |
| 552 | |
| 553 | rdev->sb_page = alloc_page(GFP_KERNEL); |
| 554 | if (!rdev->sb_page) { |
| 555 | printk(KERN_ALERT "md: out of memory.\n"); |
Andre Noll | ebc2433 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 556 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | static void free_disk_sb(mdk_rdev_t * rdev) |
| 563 | { |
| 564 | if (rdev->sb_page) { |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 565 | put_page(rdev->sb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | rdev->sb_loaded = 0; |
| 567 | rdev->sb_page = NULL; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 568 | rdev->sb_start = 0; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 569 | rdev->sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | |
| 573 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 574 | static void super_written(struct bio *bio, int error) |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 575 | { |
| 576 | mdk_rdev_t *rdev = bio->bi_private; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 577 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 578 | |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 579 | if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) { |
| 580 | printk("md: super_written gets error=%d, uptodate=%d\n", |
| 581 | error, test_bit(BIO_UPTODATE, &bio->bi_flags)); |
| 582 | WARN_ON(test_bit(BIO_UPTODATE, &bio->bi_flags)); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 583 | md_error(mddev, rdev); |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 584 | } |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 585 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 586 | if (atomic_dec_and_test(&mddev->pending_writes)) |
| 587 | wake_up(&mddev->sb_wait); |
Neil Brown | f8b58ed | 2005-06-27 22:29:34 -0700 | [diff] [blame] | 588 | bio_put(bio); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 589 | } |
| 590 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 591 | static void super_written_barrier(struct bio *bio, int error) |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 592 | { |
| 593 | struct bio *bio2 = bio->bi_private; |
| 594 | mdk_rdev_t *rdev = bio2->bi_private; |
| 595 | mddev_t *mddev = rdev->mddev; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 596 | |
| 597 | if (!test_bit(BIO_UPTODATE, &bio->bi_flags) && |
| 598 | error == -EOPNOTSUPP) { |
| 599 | unsigned long flags; |
| 600 | /* barriers don't appear to be supported :-( */ |
| 601 | set_bit(BarriersNotsupp, &rdev->flags); |
| 602 | mddev->barriers_work = 0; |
| 603 | spin_lock_irqsave(&mddev->write_lock, flags); |
| 604 | bio2->bi_next = mddev->biolist; |
| 605 | mddev->biolist = bio2; |
| 606 | spin_unlock_irqrestore(&mddev->write_lock, flags); |
| 607 | wake_up(&mddev->sb_wait); |
| 608 | bio_put(bio); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 609 | } else { |
| 610 | bio_put(bio2); |
| 611 | bio->bi_private = rdev; |
| 612 | super_written(bio, error); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 613 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 614 | } |
| 615 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 616 | void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev, |
| 617 | sector_t sector, int size, struct page *page) |
| 618 | { |
| 619 | /* write first size bytes of page to sector of rdev |
| 620 | * Increment mddev->pending_writes before returning |
| 621 | * and decrement it on completion, waking up sb_wait |
| 622 | * if zero is reached. |
| 623 | * If an error occurred, call md_error |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 624 | * |
| 625 | * As we might need to resubmit the request if BIO_RW_BARRIER |
| 626 | * causes ENOTSUPP, we allocate a spare bio... |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 627 | */ |
| 628 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
Jens Axboe | 93dbb39 | 2009-02-16 10:25:40 +0100 | [diff] [blame] | 629 | int rw = (1<<BIO_RW) | (1<<BIO_RW_SYNCIO) | (1<<BIO_RW_UNPLUG); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 630 | |
| 631 | bio->bi_bdev = rdev->bdev; |
| 632 | bio->bi_sector = sector; |
| 633 | bio_add_page(bio, page, size, 0); |
| 634 | bio->bi_private = rdev; |
| 635 | bio->bi_end_io = super_written; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 636 | bio->bi_rw = rw; |
| 637 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 638 | atomic_inc(&mddev->pending_writes); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 639 | if (!test_bit(BarriersNotsupp, &rdev->flags)) { |
| 640 | struct bio *rbio; |
| 641 | rw |= (1<<BIO_RW_BARRIER); |
| 642 | rbio = bio_clone(bio, GFP_NOIO); |
| 643 | rbio->bi_private = bio; |
| 644 | rbio->bi_end_io = super_written_barrier; |
| 645 | submit_bio(rw, rbio); |
| 646 | } else |
| 647 | submit_bio(rw, bio); |
| 648 | } |
| 649 | |
| 650 | void md_super_wait(mddev_t *mddev) |
| 651 | { |
| 652 | /* wait for all superblock writes that were scheduled to complete. |
| 653 | * if any had to be retried (due to BARRIER problems), retry them |
| 654 | */ |
| 655 | DEFINE_WAIT(wq); |
| 656 | for(;;) { |
| 657 | prepare_to_wait(&mddev->sb_wait, &wq, TASK_UNINTERRUPTIBLE); |
| 658 | if (atomic_read(&mddev->pending_writes)==0) |
| 659 | break; |
| 660 | while (mddev->biolist) { |
| 661 | struct bio *bio; |
| 662 | spin_lock_irq(&mddev->write_lock); |
| 663 | bio = mddev->biolist; |
| 664 | mddev->biolist = bio->bi_next ; |
| 665 | bio->bi_next = NULL; |
| 666 | spin_unlock_irq(&mddev->write_lock); |
| 667 | submit_bio(bio->bi_rw, bio); |
| 668 | } |
| 669 | schedule(); |
| 670 | } |
| 671 | finish_wait(&mddev->sb_wait, &wq); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 672 | } |
| 673 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 674 | static void bi_complete(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | complete((struct completion*)bio->bi_private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } |
| 678 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 679 | 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] | 680 | struct page *page, int rw) |
| 681 | { |
Neil Brown | baaa2c5 | 2005-04-16 15:23:54 -0700 | [diff] [blame] | 682 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | struct completion event; |
| 684 | int ret; |
| 685 | |
Jens Axboe | 93dbb39 | 2009-02-16 10:25:40 +0100 | [diff] [blame] | 686 | rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
| 688 | bio->bi_bdev = bdev; |
| 689 | bio->bi_sector = sector; |
| 690 | bio_add_page(bio, page, size, 0); |
| 691 | init_completion(&event); |
| 692 | bio->bi_private = &event; |
| 693 | bio->bi_end_io = bi_complete; |
| 694 | submit_bio(rw, bio); |
| 695 | wait_for_completion(&event); |
| 696 | |
| 697 | ret = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 698 | bio_put(bio); |
| 699 | return ret; |
| 700 | } |
NeilBrown | a8745db | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 701 | EXPORT_SYMBOL_GPL(sync_page_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 703 | static int read_disk_sb(mdk_rdev_t * rdev, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | { |
| 705 | char b[BDEVNAME_SIZE]; |
| 706 | if (!rdev->sb_page) { |
| 707 | MD_BUG(); |
| 708 | return -EINVAL; |
| 709 | } |
| 710 | if (rdev->sb_loaded) |
| 711 | return 0; |
| 712 | |
| 713 | |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 714 | if (!sync_page_io(rdev->bdev, rdev->sb_start, size, rdev->sb_page, READ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | goto fail; |
| 716 | rdev->sb_loaded = 1; |
| 717 | return 0; |
| 718 | |
| 719 | fail: |
| 720 | printk(KERN_WARNING "md: disabled device %s, could not read superblock.\n", |
| 721 | bdevname(rdev->bdev,b)); |
| 722 | return -EINVAL; |
| 723 | } |
| 724 | |
| 725 | static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 726 | { |
Andre Noll | 0571046 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 727 | return sb1->set_uuid0 == sb2->set_uuid0 && |
| 728 | sb1->set_uuid1 == sb2->set_uuid1 && |
| 729 | sb1->set_uuid2 == sb2->set_uuid2 && |
| 730 | sb1->set_uuid3 == sb2->set_uuid3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 734 | { |
| 735 | int ret; |
| 736 | mdp_super_t *tmp1, *tmp2; |
| 737 | |
| 738 | tmp1 = kmalloc(sizeof(*tmp1),GFP_KERNEL); |
| 739 | tmp2 = kmalloc(sizeof(*tmp2),GFP_KERNEL); |
| 740 | |
| 741 | if (!tmp1 || !tmp2) { |
| 742 | ret = 0; |
Andre Noll | 35020f1 | 2008-03-23 15:10:33 +0100 | [diff] [blame] | 743 | printk(KERN_INFO "md.c sb_equal(): failed to allocate memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | goto abort; |
| 745 | } |
| 746 | |
| 747 | *tmp1 = *sb1; |
| 748 | *tmp2 = *sb2; |
| 749 | |
| 750 | /* |
| 751 | * nr_disks is not constant |
| 752 | */ |
| 753 | tmp1->nr_disks = 0; |
| 754 | tmp2->nr_disks = 0; |
| 755 | |
Andre Noll | ce0c8e0 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 756 | ret = (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | abort: |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 758 | kfree(tmp1); |
| 759 | kfree(tmp2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | return ret; |
| 761 | } |
| 762 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 763 | |
| 764 | static u32 md_csum_fold(u32 csum) |
| 765 | { |
| 766 | csum = (csum & 0xffff) + (csum >> 16); |
| 767 | return (csum & 0xffff) + (csum >> 16); |
| 768 | } |
| 769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | static unsigned int calc_sb_csum(mdp_super_t * sb) |
| 771 | { |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 772 | u64 newcsum = 0; |
| 773 | u32 *sb32 = (u32*)sb; |
| 774 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | unsigned int disk_csum, csum; |
| 776 | |
| 777 | disk_csum = sb->sb_csum; |
| 778 | sb->sb_csum = 0; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 779 | |
| 780 | for (i = 0; i < MD_SB_BYTES/4 ; i++) |
| 781 | newcsum += sb32[i]; |
| 782 | csum = (newcsum & 0xffffffff) + (newcsum>>32); |
| 783 | |
| 784 | |
| 785 | #ifdef CONFIG_ALPHA |
| 786 | /* This used to use csum_partial, which was wrong for several |
| 787 | * reasons including that different results are returned on |
| 788 | * different architectures. It isn't critical that we get exactly |
| 789 | * the same return value as before (we always csum_fold before |
| 790 | * testing, and that removes any differences). However as we |
| 791 | * know that csum_partial always returned a 16bit value on |
| 792 | * alphas, do a fold to maximise conformity to previous behaviour. |
| 793 | */ |
| 794 | sb->sb_csum = md_csum_fold(disk_csum); |
| 795 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | sb->sb_csum = disk_csum; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 797 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | return csum; |
| 799 | } |
| 800 | |
| 801 | |
| 802 | /* |
| 803 | * Handle superblock details. |
| 804 | * We want to be able to handle multiple superblock formats |
| 805 | * so we have a common interface to them all, and an array of |
| 806 | * different handlers. |
| 807 | * We rely on user-space to write the initial superblock, and support |
| 808 | * reading and updating of superblocks. |
| 809 | * Interface methods are: |
| 810 | * int load_super(mdk_rdev_t *dev, mdk_rdev_t *refdev, int minor_version) |
| 811 | * loads and validates a superblock on dev. |
| 812 | * if refdev != NULL, compare superblocks on both devices |
| 813 | * Return: |
| 814 | * 0 - dev has a superblock that is compatible with refdev |
| 815 | * 1 - dev has a superblock that is compatible and newer than refdev |
| 816 | * so dev should be used as the refdev in future |
| 817 | * -EINVAL superblock incompatible or invalid |
| 818 | * -othererror e.g. -EIO |
| 819 | * |
| 820 | * int validate_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 821 | * Verify that dev is acceptable into mddev. |
| 822 | * The first time, mddev->raid_disks will be 0, and data from |
| 823 | * dev should be merged in. Subsequent calls check that dev |
| 824 | * is new enough. Return 0 or -EINVAL |
| 825 | * |
| 826 | * void sync_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 827 | * Update the superblock for rdev with data in mddev |
| 828 | * This does not write to disc. |
| 829 | * |
| 830 | */ |
| 831 | |
| 832 | struct super_type { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 833 | char *name; |
| 834 | struct module *owner; |
| 835 | int (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev, |
| 836 | int minor_version); |
| 837 | int (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 838 | void (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 839 | unsigned long long (*rdev_size_change)(mdk_rdev_t *rdev, |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 840 | sector_t num_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | }; |
| 842 | |
| 843 | /* |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 844 | * Check that the given mddev has no bitmap. |
| 845 | * |
| 846 | * This function is called from the run method of all personalities that do not |
| 847 | * support bitmaps. It prints an error message and returns non-zero if mddev |
| 848 | * has a bitmap. Otherwise, it returns 0. |
| 849 | * |
| 850 | */ |
| 851 | int md_check_no_bitmap(mddev_t *mddev) |
| 852 | { |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 853 | if (!mddev->bitmap_info.file && !mddev->bitmap_info.offset) |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 854 | return 0; |
| 855 | printk(KERN_ERR "%s: bitmaps are not supported for %s\n", |
| 856 | mdname(mddev), mddev->pers->name); |
| 857 | return 1; |
| 858 | } |
| 859 | EXPORT_SYMBOL(md_check_no_bitmap); |
| 860 | |
| 861 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | * load_super for 0.90.0 |
| 863 | */ |
| 864 | static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 865 | { |
| 866 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 867 | mdp_super_t *sb; |
| 868 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | /* |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 871 | * Calculate the position of the superblock (512byte sectors), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | * it's at the end of the disk. |
| 873 | * |
| 874 | * It also happens to be a multiple of 4Kb. |
| 875 | */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 876 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 878 | ret = read_disk_sb(rdev, MD_SB_BYTES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | if (ret) return ret; |
| 880 | |
| 881 | ret = -EINVAL; |
| 882 | |
| 883 | bdevname(rdev->bdev, b); |
| 884 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 885 | |
| 886 | if (sb->md_magic != MD_SB_MAGIC) { |
| 887 | printk(KERN_ERR "md: invalid raid superblock magic on %s\n", |
| 888 | b); |
| 889 | goto abort; |
| 890 | } |
| 891 | |
| 892 | if (sb->major_version != 0 || |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 893 | sb->minor_version < 90 || |
| 894 | sb->minor_version > 91) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | printk(KERN_WARNING "Bad version number %d.%d on %s\n", |
| 896 | sb->major_version, sb->minor_version, |
| 897 | b); |
| 898 | goto abort; |
| 899 | } |
| 900 | |
| 901 | if (sb->raid_disks <= 0) |
| 902 | goto abort; |
| 903 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 904 | 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] | 905 | printk(KERN_WARNING "md: invalid superblock checksum on %s\n", |
| 906 | b); |
| 907 | goto abort; |
| 908 | } |
| 909 | |
| 910 | rdev->preferred_minor = sb->md_minor; |
| 911 | rdev->data_offset = 0; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 912 | rdev->sb_size = MD_SB_BYTES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | if (sb->level == LEVEL_MULTIPATH) |
| 915 | rdev->desc_nr = -1; |
| 916 | else |
| 917 | rdev->desc_nr = sb->this_disk.number; |
| 918 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 919 | if (!refdev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 921 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | __u64 ev1, ev2; |
| 923 | mdp_super_t *refsb = (mdp_super_t*)page_address(refdev->sb_page); |
| 924 | if (!uuid_equal(refsb, sb)) { |
| 925 | printk(KERN_WARNING "md: %s has different UUID to %s\n", |
| 926 | b, bdevname(refdev->bdev,b2)); |
| 927 | goto abort; |
| 928 | } |
| 929 | if (!sb_equal(refsb, sb)) { |
| 930 | printk(KERN_WARNING "md: %s has same UUID" |
| 931 | " but different superblock to %s\n", |
| 932 | b, bdevname(refdev->bdev, b2)); |
| 933 | goto abort; |
| 934 | } |
| 935 | ev1 = md_event(sb); |
| 936 | ev2 = md_event(refsb); |
| 937 | if (ev1 > ev2) |
| 938 | ret = 1; |
| 939 | else |
| 940 | ret = 0; |
| 941 | } |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 942 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 944 | if (rdev->sectors < sb->size * 2 && sb->level > 1) |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 945 | /* "this cannot possibly happen" ... */ |
| 946 | ret = -EINVAL; |
| 947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | abort: |
| 949 | return ret; |
| 950 | } |
| 951 | |
| 952 | /* |
| 953 | * validate_super for 0.90.0 |
| 954 | */ |
| 955 | static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 956 | { |
| 957 | mdp_disk_t *desc; |
| 958 | mdp_super_t *sb = (mdp_super_t *)page_address(rdev->sb_page); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 959 | __u64 ev1 = md_event(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 961 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 962 | clear_bit(Faulty, &rdev->flags); |
| 963 | clear_bit(In_sync, &rdev->flags); |
| 964 | clear_bit(WriteMostly, &rdev->flags); |
| 965 | clear_bit(BarriersNotsupp, &rdev->flags); |
| 966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | if (mddev->raid_disks == 0) { |
| 968 | mddev->major_version = 0; |
| 969 | mddev->minor_version = sb->minor_version; |
| 970 | mddev->patch_version = sb->patch_version; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 971 | mddev->external = 0; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 972 | mddev->chunk_sectors = sb->chunk_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | mddev->ctime = sb->ctime; |
| 974 | mddev->utime = sb->utime; |
| 975 | mddev->level = sb->level; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 976 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | mddev->layout = sb->layout; |
| 978 | mddev->raid_disks = sb->raid_disks; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 979 | mddev->dev_sectors = sb->size * 2; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 980 | mddev->events = ev1; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 981 | mddev->bitmap_info.offset = 0; |
| 982 | mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 984 | if (mddev->minor_version >= 91) { |
| 985 | mddev->reshape_position = sb->reshape_position; |
| 986 | mddev->delta_disks = sb->delta_disks; |
| 987 | mddev->new_level = sb->new_level; |
| 988 | mddev->new_layout = sb->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 989 | mddev->new_chunk_sectors = sb->new_chunk >> 9; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 990 | } else { |
| 991 | mddev->reshape_position = MaxSector; |
| 992 | mddev->delta_disks = 0; |
| 993 | mddev->new_level = mddev->level; |
| 994 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 995 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 996 | } |
| 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | if (sb->state & (1<<MD_SB_CLEAN)) |
| 999 | mddev->recovery_cp = MaxSector; |
| 1000 | else { |
| 1001 | if (sb->events_hi == sb->cp_events_hi && |
| 1002 | sb->events_lo == sb->cp_events_lo) { |
| 1003 | mddev->recovery_cp = sb->recovery_cp; |
| 1004 | } else |
| 1005 | mddev->recovery_cp = 0; |
| 1006 | } |
| 1007 | |
| 1008 | memcpy(mddev->uuid+0, &sb->set_uuid0, 4); |
| 1009 | memcpy(mddev->uuid+4, &sb->set_uuid1, 4); |
| 1010 | memcpy(mddev->uuid+8, &sb->set_uuid2, 4); |
| 1011 | memcpy(mddev->uuid+12,&sb->set_uuid3, 4); |
| 1012 | |
| 1013 | mddev->max_disks = MD_SB_DISKS; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1014 | |
| 1015 | if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1016 | mddev->bitmap_info.file == NULL) |
| 1017 | mddev->bitmap_info.offset = |
| 1018 | mddev->bitmap_info.default_offset; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1019 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1020 | } else if (mddev->pers == NULL) { |
| 1021 | /* Insist on good event counter while assembling */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | ++ev1; |
| 1023 | if (ev1 < mddev->events) |
| 1024 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1025 | } else if (mddev->bitmap) { |
| 1026 | /* if adding to array with a bitmap, then we can accept an |
| 1027 | * older device ... but not too old. |
| 1028 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1029 | if (ev1 < mddev->bitmap->events_cleared) |
| 1030 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1031 | } else { |
| 1032 | if (ev1 < mddev->events) |
| 1033 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1034 | return 0; |
| 1035 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | if (mddev->level != LEVEL_MULTIPATH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | desc = sb->disks + rdev->desc_nr; |
| 1039 | |
| 1040 | if (desc->state & (1<<MD_DISK_FAULTY)) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1041 | set_bit(Faulty, &rdev->flags); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 1042 | else if (desc->state & (1<<MD_DISK_SYNC) /* && |
| 1043 | desc->raid_disk < mddev->raid_disks */) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1044 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | rdev->raid_disk = desc->raid_disk; |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1046 | } else if (desc->state & (1<<MD_DISK_ACTIVE)) { |
| 1047 | /* active but not in sync implies recovery up to |
| 1048 | * reshape position. We don't know exactly where |
| 1049 | * that is, so set to zero for now */ |
| 1050 | if (mddev->minor_version >= 91) { |
| 1051 | rdev->recovery_offset = 0; |
| 1052 | rdev->raid_disk = desc->raid_disk; |
| 1053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1055 | if (desc->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 1056 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1057 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1058 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | /* |
| 1063 | * sync_super for 0.90.0 |
| 1064 | */ |
| 1065 | static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1066 | { |
| 1067 | mdp_super_t *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | mdk_rdev_t *rdev2; |
| 1069 | int next_spare = mddev->raid_disks; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
| 1072 | /* make rdev->sb match mddev data.. |
| 1073 | * |
| 1074 | * 1/ zero out disks |
| 1075 | * 2/ Add info for each disk, keeping track of highest desc_nr (next_spare); |
| 1076 | * 3/ any empty disks < next_spare become removed |
| 1077 | * |
| 1078 | * disks[0] gets initialised to REMOVED because |
| 1079 | * we cannot be sure from other fields if it has |
| 1080 | * been initialised or not. |
| 1081 | */ |
| 1082 | int i; |
| 1083 | int active=0, working=0,failed=0,spare=0,nr_disks=0; |
| 1084 | |
NeilBrown | 6118156 | 2005-09-09 16:24:02 -0700 | [diff] [blame] | 1085 | rdev->sb_size = MD_SB_BYTES; |
| 1086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 1088 | |
| 1089 | memset(sb, 0, sizeof(*sb)); |
| 1090 | |
| 1091 | sb->md_magic = MD_SB_MAGIC; |
| 1092 | sb->major_version = mddev->major_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | sb->patch_version = mddev->patch_version; |
| 1094 | sb->gvalid_words = 0; /* ignored */ |
| 1095 | memcpy(&sb->set_uuid0, mddev->uuid+0, 4); |
| 1096 | memcpy(&sb->set_uuid1, mddev->uuid+4, 4); |
| 1097 | memcpy(&sb->set_uuid2, mddev->uuid+8, 4); |
| 1098 | memcpy(&sb->set_uuid3, mddev->uuid+12,4); |
| 1099 | |
| 1100 | sb->ctime = mddev->ctime; |
| 1101 | sb->level = mddev->level; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1102 | sb->size = mddev->dev_sectors / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | sb->raid_disks = mddev->raid_disks; |
| 1104 | sb->md_minor = mddev->md_minor; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1105 | sb->not_persistent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | sb->utime = mddev->utime; |
| 1107 | sb->state = 0; |
| 1108 | sb->events_hi = (mddev->events>>32); |
| 1109 | sb->events_lo = (u32)mddev->events; |
| 1110 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1111 | if (mddev->reshape_position == MaxSector) |
| 1112 | sb->minor_version = 90; |
| 1113 | else { |
| 1114 | sb->minor_version = 91; |
| 1115 | sb->reshape_position = mddev->reshape_position; |
| 1116 | sb->new_level = mddev->new_level; |
| 1117 | sb->delta_disks = mddev->delta_disks; |
| 1118 | sb->new_layout = mddev->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1119 | sb->new_chunk = mddev->new_chunk_sectors << 9; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1120 | } |
| 1121 | mddev->minor_version = sb->minor_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | if (mddev->in_sync) |
| 1123 | { |
| 1124 | sb->recovery_cp = mddev->recovery_cp; |
| 1125 | sb->cp_events_hi = (mddev->events>>32); |
| 1126 | sb->cp_events_lo = (u32)mddev->events; |
| 1127 | if (mddev->recovery_cp == MaxSector) |
| 1128 | sb->state = (1<< MD_SB_CLEAN); |
| 1129 | } else |
| 1130 | sb->recovery_cp = 0; |
| 1131 | |
| 1132 | sb->layout = mddev->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1133 | sb->chunk_size = mddev->chunk_sectors << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1135 | if (mddev->bitmap && mddev->bitmap_info.file == NULL) |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1136 | sb->state |= (1<<MD_SB_BITMAP_PRESENT); |
| 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | sb->disks[0].state = (1<<MD_DISK_REMOVED); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1139 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | mdp_disk_t *d; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1141 | int desc_nr; |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1142 | int is_active = test_bit(In_sync, &rdev2->flags); |
| 1143 | |
| 1144 | if (rdev2->raid_disk >= 0 && |
| 1145 | sb->minor_version >= 91) |
| 1146 | /* we have nowhere to store the recovery_offset, |
| 1147 | * but if it is not below the reshape_position, |
| 1148 | * we can piggy-back on that. |
| 1149 | */ |
| 1150 | is_active = 1; |
| 1151 | if (rdev2->raid_disk < 0 || |
| 1152 | test_bit(Faulty, &rdev2->flags)) |
| 1153 | is_active = 0; |
| 1154 | if (is_active) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1155 | desc_nr = rdev2->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | else |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1157 | desc_nr = next_spare++; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1158 | rdev2->desc_nr = desc_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | d = &sb->disks[rdev2->desc_nr]; |
| 1160 | nr_disks++; |
| 1161 | d->number = rdev2->desc_nr; |
| 1162 | d->major = MAJOR(rdev2->bdev->bd_dev); |
| 1163 | d->minor = MINOR(rdev2->bdev->bd_dev); |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1164 | if (is_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | d->raid_disk = rdev2->raid_disk; |
| 1166 | else |
| 1167 | d->raid_disk = rdev2->desc_nr; /* compatibility */ |
NeilBrown | 1be7892 | 2006-03-27 01:18:03 -0800 | [diff] [blame] | 1168 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | d->state = (1<<MD_DISK_FAULTY); |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1170 | else if (is_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | d->state = (1<<MD_DISK_ACTIVE); |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1172 | if (test_bit(In_sync, &rdev2->flags)) |
| 1173 | d->state |= (1<<MD_DISK_SYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | active++; |
| 1175 | working++; |
| 1176 | } else { |
| 1177 | d->state = 0; |
| 1178 | spare++; |
| 1179 | working++; |
| 1180 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1181 | if (test_bit(WriteMostly, &rdev2->flags)) |
| 1182 | d->state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | /* now set the "removed" and "faulty" bits on any missing devices */ |
| 1185 | for (i=0 ; i < mddev->raid_disks ; i++) { |
| 1186 | mdp_disk_t *d = &sb->disks[i]; |
| 1187 | if (d->state == 0 && d->number == 0) { |
| 1188 | d->number = i; |
| 1189 | d->raid_disk = i; |
| 1190 | d->state = (1<<MD_DISK_REMOVED); |
| 1191 | d->state |= (1<<MD_DISK_FAULTY); |
| 1192 | failed++; |
| 1193 | } |
| 1194 | } |
| 1195 | sb->nr_disks = nr_disks; |
| 1196 | sb->active_disks = active; |
| 1197 | sb->working_disks = working; |
| 1198 | sb->failed_disks = failed; |
| 1199 | sb->spare_disks = spare; |
| 1200 | |
| 1201 | sb->this_disk = sb->disks[rdev->desc_nr]; |
| 1202 | sb->sb_csum = calc_sb_csum(sb); |
| 1203 | } |
| 1204 | |
| 1205 | /* |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1206 | * rdev_size_change for 0.90.0 |
| 1207 | */ |
| 1208 | static unsigned long long |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1209 | super_90_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1210 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1211 | if (num_sectors && num_sectors < rdev->mddev->dev_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1212 | return 0; /* component must fit device */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1213 | if (rdev->mddev->bitmap_info.offset) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1214 | return 0; /* can't move bitmap */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1215 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1216 | if (!num_sectors || num_sectors > rdev->sb_start) |
| 1217 | num_sectors = rdev->sb_start; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1218 | md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1219 | rdev->sb_page); |
| 1220 | md_super_wait(rdev->mddev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1221 | return num_sectors / 2; /* kB for sysfs */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | * version 1 superblock |
| 1227 | */ |
| 1228 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1229 | static __le32 calc_sb_1_csum(struct mdp_superblock_1 * sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | { |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1231 | __le32 disk_csum; |
| 1232 | u32 csum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | unsigned long long newcsum; |
| 1234 | int size = 256 + le32_to_cpu(sb->max_dev)*2; |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1235 | __le32 *isuper = (__le32*)sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | int i; |
| 1237 | |
| 1238 | disk_csum = sb->sb_csum; |
| 1239 | sb->sb_csum = 0; |
| 1240 | newcsum = 0; |
| 1241 | for (i=0; size>=4; size -= 4 ) |
| 1242 | newcsum += le32_to_cpu(*isuper++); |
| 1243 | |
| 1244 | if (size == 2) |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1245 | newcsum += le16_to_cpu(*(__le16*) isuper); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
| 1247 | csum = (newcsum & 0xffffffff) + (newcsum >> 32); |
| 1248 | sb->sb_csum = disk_csum; |
| 1249 | return cpu_to_le32(csum); |
| 1250 | } |
| 1251 | |
| 1252 | static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 1253 | { |
| 1254 | struct mdp_superblock_1 *sb; |
| 1255 | int ret; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1256 | sector_t sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1258 | int bmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
| 1260 | /* |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1261 | * Calculate the position of the superblock in 512byte sectors. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | * It is always aligned to a 4K boundary and |
| 1263 | * depeding on minor_version, it can be: |
| 1264 | * 0: At least 8K, but less than 12K, from end of device |
| 1265 | * 1: At start of device |
| 1266 | * 2: 4K from start of device. |
| 1267 | */ |
| 1268 | switch(minor_version) { |
| 1269 | case 0: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1270 | sb_start = rdev->bdev->bd_inode->i_size >> 9; |
| 1271 | sb_start -= 8*2; |
| 1272 | sb_start &= ~(sector_t)(4*2-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | break; |
| 1274 | case 1: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1275 | sb_start = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | break; |
| 1277 | case 2: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1278 | sb_start = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | break; |
| 1280 | default: |
| 1281 | return -EINVAL; |
| 1282 | } |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1283 | rdev->sb_start = sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1285 | /* superblock is rarely larger than 1K, but it can be larger, |
| 1286 | * and it is safe to read 4k, so we do that |
| 1287 | */ |
| 1288 | ret = read_disk_sb(rdev, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | if (ret) return ret; |
| 1290 | |
| 1291 | |
| 1292 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1293 | |
| 1294 | if (sb->magic != cpu_to_le32(MD_SB_MAGIC) || |
| 1295 | sb->major_version != cpu_to_le32(1) || |
| 1296 | le32_to_cpu(sb->max_dev) > (4096-256)/2 || |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1297 | le64_to_cpu(sb->super_offset) != rdev->sb_start || |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1298 | (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | return -EINVAL; |
| 1300 | |
| 1301 | if (calc_sb_1_csum(sb) != sb->sb_csum) { |
| 1302 | printk("md: invalid superblock checksum on %s\n", |
| 1303 | bdevname(rdev->bdev,b)); |
| 1304 | return -EINVAL; |
| 1305 | } |
| 1306 | if (le64_to_cpu(sb->data_size) < 10) { |
| 1307 | printk("md: data_size too small on %s\n", |
| 1308 | bdevname(rdev->bdev,b)); |
| 1309 | return -EINVAL; |
| 1310 | } |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | rdev->preferred_minor = 0xffff; |
| 1313 | rdev->data_offset = le64_to_cpu(sb->data_offset); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1314 | atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1316 | rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256; |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 1317 | bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1318 | if (rdev->sb_size & bmask) |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1319 | rdev->sb_size = (rdev->sb_size | bmask) + 1; |
| 1320 | |
| 1321 | if (minor_version |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1322 | && rdev->data_offset < sb_start + (rdev->sb_size/512)) |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1323 | return -EINVAL; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1324 | |
NeilBrown | 31b65a0 | 2006-07-10 04:44:14 -0700 | [diff] [blame] | 1325 | if (sb->level == cpu_to_le32(LEVEL_MULTIPATH)) |
| 1326 | rdev->desc_nr = -1; |
| 1327 | else |
| 1328 | rdev->desc_nr = le32_to_cpu(sb->dev_number); |
| 1329 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1330 | if (!refdev) { |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1331 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1332 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | __u64 ev1, ev2; |
| 1334 | struct mdp_superblock_1 *refsb = |
| 1335 | (struct mdp_superblock_1*)page_address(refdev->sb_page); |
| 1336 | |
| 1337 | if (memcmp(sb->set_uuid, refsb->set_uuid, 16) != 0 || |
| 1338 | sb->level != refsb->level || |
| 1339 | sb->layout != refsb->layout || |
| 1340 | sb->chunksize != refsb->chunksize) { |
| 1341 | printk(KERN_WARNING "md: %s has strangely different" |
| 1342 | " superblock to %s\n", |
| 1343 | bdevname(rdev->bdev,b), |
| 1344 | bdevname(refdev->bdev,b2)); |
| 1345 | return -EINVAL; |
| 1346 | } |
| 1347 | ev1 = le64_to_cpu(sb->events); |
| 1348 | ev2 = le64_to_cpu(refsb->events); |
| 1349 | |
| 1350 | if (ev1 > ev2) |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1351 | ret = 1; |
| 1352 | else |
| 1353 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | } |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1355 | if (minor_version) |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1356 | rdev->sectors = (rdev->bdev->bd_inode->i_size >> 9) - |
| 1357 | le64_to_cpu(sb->data_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | else |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1359 | rdev->sectors = rdev->sb_start; |
| 1360 | if (rdev->sectors < le64_to_cpu(sb->data_size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | return -EINVAL; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1362 | rdev->sectors = le64_to_cpu(sb->data_size); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1363 | if (le64_to_cpu(sb->size) > rdev->sectors) |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1364 | return -EINVAL; |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1365 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1369 | { |
| 1370 | 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] | 1371 | __u64 ev1 = le64_to_cpu(sb->events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1373 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1374 | clear_bit(Faulty, &rdev->flags); |
| 1375 | clear_bit(In_sync, &rdev->flags); |
| 1376 | clear_bit(WriteMostly, &rdev->flags); |
| 1377 | clear_bit(BarriersNotsupp, &rdev->flags); |
| 1378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | if (mddev->raid_disks == 0) { |
| 1380 | mddev->major_version = 1; |
| 1381 | mddev->patch_version = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1382 | mddev->external = 0; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1383 | mddev->chunk_sectors = le32_to_cpu(sb->chunksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | mddev->ctime = le64_to_cpu(sb->ctime) & ((1ULL << 32)-1); |
| 1385 | mddev->utime = le64_to_cpu(sb->utime) & ((1ULL << 32)-1); |
| 1386 | mddev->level = le32_to_cpu(sb->level); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 1387 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | mddev->layout = le32_to_cpu(sb->layout); |
| 1389 | mddev->raid_disks = le32_to_cpu(sb->raid_disks); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1390 | mddev->dev_sectors = le64_to_cpu(sb->size); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1391 | mddev->events = ev1; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1392 | mddev->bitmap_info.offset = 0; |
| 1393 | mddev->bitmap_info.default_offset = 1024 >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
| 1395 | mddev->recovery_cp = le64_to_cpu(sb->resync_offset); |
| 1396 | memcpy(mddev->uuid, sb->set_uuid, 16); |
| 1397 | |
| 1398 | mddev->max_disks = (4096-256)/2; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1399 | |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1400 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1401 | mddev->bitmap_info.file == NULL ) |
| 1402 | mddev->bitmap_info.offset = |
| 1403 | (__s32)le32_to_cpu(sb->bitmap_offset); |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1404 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1405 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) { |
| 1406 | mddev->reshape_position = le64_to_cpu(sb->reshape_position); |
| 1407 | mddev->delta_disks = le32_to_cpu(sb->delta_disks); |
| 1408 | mddev->new_level = le32_to_cpu(sb->new_level); |
| 1409 | mddev->new_layout = le32_to_cpu(sb->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1410 | mddev->new_chunk_sectors = le32_to_cpu(sb->new_chunk); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1411 | } else { |
| 1412 | mddev->reshape_position = MaxSector; |
| 1413 | mddev->delta_disks = 0; |
| 1414 | mddev->new_level = mddev->level; |
| 1415 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1416 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1417 | } |
| 1418 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1419 | } else if (mddev->pers == NULL) { |
| 1420 | /* Insist of good event counter while assembling */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | ++ev1; |
| 1422 | if (ev1 < mddev->events) |
| 1423 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1424 | } else if (mddev->bitmap) { |
| 1425 | /* If adding to array with a bitmap, then we can accept an |
| 1426 | * older device, but not too old. |
| 1427 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1428 | if (ev1 < mddev->bitmap->events_cleared) |
| 1429 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1430 | } else { |
| 1431 | if (ev1 < mddev->events) |
| 1432 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1433 | return 0; |
| 1434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | if (mddev->level != LEVEL_MULTIPATH) { |
| 1436 | int role; |
NeilBrown | 3673f30 | 2009-08-03 10:59:56 +1000 | [diff] [blame] | 1437 | if (rdev->desc_nr < 0 || |
| 1438 | rdev->desc_nr >= le32_to_cpu(sb->max_dev)) { |
| 1439 | role = 0xffff; |
| 1440 | rdev->desc_nr = -1; |
| 1441 | } else |
| 1442 | role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | switch(role) { |
| 1444 | case 0xffff: /* spare */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | case 0xfffe: /* faulty */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1447 | set_bit(Faulty, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | break; |
| 1449 | default: |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1450 | if ((le32_to_cpu(sb->feature_map) & |
| 1451 | MD_FEATURE_RECOVERY_OFFSET)) |
| 1452 | rdev->recovery_offset = le64_to_cpu(sb->recovery_offset); |
| 1453 | else |
| 1454 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | rdev->raid_disk = role; |
| 1456 | break; |
| 1457 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1458 | if (sb->devflags & WriteMostly1) |
| 1459 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1460 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1461 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | return 0; |
| 1464 | } |
| 1465 | |
| 1466 | static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1467 | { |
| 1468 | struct mdp_superblock_1 *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | mdk_rdev_t *rdev2; |
| 1470 | int max_dev, i; |
| 1471 | /* make rdev->sb match mddev and rdev data. */ |
| 1472 | |
| 1473 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1474 | |
| 1475 | sb->feature_map = 0; |
| 1476 | sb->pad0 = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1477 | sb->recovery_offset = cpu_to_le64(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | memset(sb->pad1, 0, sizeof(sb->pad1)); |
| 1479 | memset(sb->pad2, 0, sizeof(sb->pad2)); |
| 1480 | memset(sb->pad3, 0, sizeof(sb->pad3)); |
| 1481 | |
| 1482 | sb->utime = cpu_to_le64((__u64)mddev->utime); |
| 1483 | sb->events = cpu_to_le64(mddev->events); |
| 1484 | if (mddev->in_sync) |
| 1485 | sb->resync_offset = cpu_to_le64(mddev->recovery_cp); |
| 1486 | else |
| 1487 | sb->resync_offset = cpu_to_le64(0); |
| 1488 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1489 | sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors)); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1490 | |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1491 | sb->raid_disks = cpu_to_le32(mddev->raid_disks); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1492 | sb->size = cpu_to_le64(mddev->dev_sectors); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1493 | sb->chunksize = cpu_to_le32(mddev->chunk_sectors); |
NeilBrown | 62e1e38 | 2009-05-26 09:40:59 +1000 | [diff] [blame] | 1494 | sb->level = cpu_to_le32(mddev->level); |
| 1495 | sb->layout = cpu_to_le32(mddev->layout); |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1496 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1497 | if (mddev->bitmap && mddev->bitmap_info.file == NULL) { |
| 1498 | sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_info.offset); |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1499 | sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1500 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1501 | |
| 1502 | if (rdev->raid_disk >= 0 && |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1503 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1504 | if (rdev->recovery_offset > 0) { |
| 1505 | sb->feature_map |= |
| 1506 | cpu_to_le32(MD_FEATURE_RECOVERY_OFFSET); |
| 1507 | sb->recovery_offset = |
| 1508 | cpu_to_le64(rdev->recovery_offset); |
| 1509 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1512 | if (mddev->reshape_position != MaxSector) { |
| 1513 | sb->feature_map |= cpu_to_le32(MD_FEATURE_RESHAPE_ACTIVE); |
| 1514 | sb->reshape_position = cpu_to_le64(mddev->reshape_position); |
| 1515 | sb->new_layout = cpu_to_le32(mddev->new_layout); |
| 1516 | sb->delta_disks = cpu_to_le32(mddev->delta_disks); |
| 1517 | sb->new_level = cpu_to_le32(mddev->new_level); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1518 | sb->new_chunk = cpu_to_le32(mddev->new_chunk_sectors); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1519 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | max_dev = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1522 | list_for_each_entry(rdev2, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | if (rdev2->desc_nr+1 > max_dev) |
| 1524 | max_dev = rdev2->desc_nr+1; |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1525 | |
NeilBrown | 70471da | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 1526 | if (max_dev > le32_to_cpu(sb->max_dev)) { |
| 1527 | int bmask; |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1528 | sb->max_dev = cpu_to_le32(max_dev); |
NeilBrown | 70471da | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 1529 | rdev->sb_size = max_dev * 2 + 256; |
| 1530 | bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1; |
| 1531 | if (rdev->sb_size & bmask) |
| 1532 | rdev->sb_size = (rdev->sb_size | bmask) + 1; |
| 1533 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | for (i=0; i<max_dev;i++) |
| 1535 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
| 1536 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1537 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | i = rdev2->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1539 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1541 | else if (test_bit(In_sync, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1543 | else if (rdev2->raid_disk >= 0 && rdev2->recovery_offset > 0) |
| 1544 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | else |
| 1546 | sb->dev_roles[i] = cpu_to_le16(0xffff); |
| 1547 | } |
| 1548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | sb->sb_csum = calc_sb_1_csum(sb); |
| 1550 | } |
| 1551 | |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1552 | static unsigned long long |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1553 | super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1554 | { |
| 1555 | struct mdp_superblock_1 *sb; |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1556 | sector_t max_sectors; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1557 | if (num_sectors && num_sectors < rdev->mddev->dev_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1558 | return 0; /* component must fit device */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1559 | if (rdev->sb_start < rdev->data_offset) { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1560 | /* minor versions 1 and 2; superblock before data */ |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1561 | max_sectors = rdev->bdev->bd_inode->i_size >> 9; |
| 1562 | max_sectors -= rdev->data_offset; |
| 1563 | if (!num_sectors || num_sectors > max_sectors) |
| 1564 | num_sectors = max_sectors; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1565 | } else if (rdev->mddev->bitmap_info.offset) { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1566 | /* minor version 0 with bitmap we can't move */ |
| 1567 | return 0; |
| 1568 | } else { |
| 1569 | /* minor version 0; superblock after data */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1570 | sector_t sb_start; |
| 1571 | sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2; |
| 1572 | sb_start &= ~(sector_t)(4*2 - 1); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1573 | max_sectors = rdev->sectors + sb_start - rdev->sb_start; |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1574 | if (!num_sectors || num_sectors > max_sectors) |
| 1575 | num_sectors = max_sectors; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1576 | rdev->sb_start = sb_start; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1577 | } |
| 1578 | sb = (struct mdp_superblock_1 *) page_address(rdev->sb_page); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1579 | sb->data_size = cpu_to_le64(num_sectors); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1580 | sb->super_offset = rdev->sb_start; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1581 | sb->sb_csum = calc_sb_1_csum(sb); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1582 | md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1583 | rdev->sb_page); |
| 1584 | md_super_wait(rdev->mddev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1585 | return num_sectors / 2; /* kB for sysfs */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 1588 | static struct super_type super_types[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | [0] = { |
| 1590 | .name = "0.90.0", |
| 1591 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1592 | .load_super = super_90_load, |
| 1593 | .validate_super = super_90_validate, |
| 1594 | .sync_super = super_90_sync, |
| 1595 | .rdev_size_change = super_90_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | }, |
| 1597 | [1] = { |
| 1598 | .name = "md-1", |
| 1599 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1600 | .load_super = super_1_load, |
| 1601 | .validate_super = super_1_validate, |
| 1602 | .sync_super = super_1_sync, |
| 1603 | .rdev_size_change = super_1_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | }, |
| 1605 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | |
| 1607 | static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2) |
| 1608 | { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1609 | mdk_rdev_t *rdev, *rdev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1611 | rcu_read_lock(); |
| 1612 | rdev_for_each_rcu(rdev, mddev1) |
| 1613 | rdev_for_each_rcu(rdev2, mddev2) |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1614 | if (rdev->bdev->bd_contains == |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1615 | rdev2->bdev->bd_contains) { |
| 1616 | rcu_read_unlock(); |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1617 | return 1; |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1618 | } |
| 1619 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | return 0; |
| 1621 | } |
| 1622 | |
| 1623 | static LIST_HEAD(pending_raid_disks); |
| 1624 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1625 | /* |
| 1626 | * Try to register data integrity profile for an mddev |
| 1627 | * |
| 1628 | * This is called when an array is started and after a disk has been kicked |
| 1629 | * from the array. It only succeeds if all working and active component devices |
| 1630 | * are integrity capable with matching profiles. |
| 1631 | */ |
| 1632 | int md_integrity_register(mddev_t *mddev) |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1633 | { |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1634 | mdk_rdev_t *rdev, *reference = NULL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1635 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1636 | if (list_empty(&mddev->disks)) |
| 1637 | return 0; /* nothing to do */ |
| 1638 | if (blk_get_integrity(mddev->gendisk)) |
| 1639 | return 0; /* already registered */ |
| 1640 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 1641 | /* skip spares and non-functional disks */ |
| 1642 | if (test_bit(Faulty, &rdev->flags)) |
| 1643 | continue; |
| 1644 | if (rdev->raid_disk < 0) |
| 1645 | continue; |
| 1646 | /* |
| 1647 | * If at least one rdev is not integrity capable, we can not |
| 1648 | * enable data integrity for the md device. |
| 1649 | */ |
| 1650 | if (!bdev_get_integrity(rdev->bdev)) |
| 1651 | return -EINVAL; |
| 1652 | if (!reference) { |
| 1653 | /* Use the first rdev as the reference */ |
| 1654 | reference = rdev; |
| 1655 | continue; |
| 1656 | } |
| 1657 | /* does this rdev's profile match the reference profile? */ |
| 1658 | if (blk_integrity_compare(reference->bdev->bd_disk, |
| 1659 | rdev->bdev->bd_disk) < 0) |
| 1660 | return -EINVAL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1661 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1662 | /* |
| 1663 | * All component devices are integrity capable and have matching |
| 1664 | * profiles, register the common profile for the md device. |
| 1665 | */ |
| 1666 | if (blk_integrity_register(mddev->gendisk, |
| 1667 | bdev_get_integrity(reference->bdev)) != 0) { |
| 1668 | printk(KERN_ERR "md: failed to register integrity for %s\n", |
| 1669 | mdname(mddev)); |
| 1670 | return -EINVAL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1671 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1672 | printk(KERN_NOTICE "md: data integrity on %s enabled\n", |
| 1673 | mdname(mddev)); |
| 1674 | return 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1675 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1676 | EXPORT_SYMBOL(md_integrity_register); |
| 1677 | |
| 1678 | /* Disable data integrity if non-capable/non-matching disk is being added */ |
| 1679 | void md_integrity_add_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 1680 | { |
| 1681 | struct blk_integrity *bi_rdev = bdev_get_integrity(rdev->bdev); |
| 1682 | struct blk_integrity *bi_mddev = blk_get_integrity(mddev->gendisk); |
| 1683 | |
| 1684 | if (!bi_mddev) /* nothing to do */ |
| 1685 | return; |
| 1686 | if (rdev->raid_disk < 0) /* skip spares */ |
| 1687 | return; |
| 1688 | if (bi_rdev && blk_integrity_compare(mddev->gendisk, |
| 1689 | rdev->bdev->bd_disk) >= 0) |
| 1690 | return; |
| 1691 | printk(KERN_NOTICE "disabling data integrity on %s\n", mdname(mddev)); |
| 1692 | blk_integrity_unregister(mddev->gendisk); |
| 1693 | } |
| 1694 | EXPORT_SYMBOL(md_integrity_add_rdev); |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1695 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) |
| 1697 | { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1698 | char b[BDEVNAME_SIZE]; |
NeilBrown | f637b9f | 2005-11-08 21:39:37 -0800 | [diff] [blame] | 1699 | struct kobject *ko; |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1700 | char *s; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1701 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | |
| 1703 | if (rdev->mddev) { |
| 1704 | MD_BUG(); |
| 1705 | return -EINVAL; |
| 1706 | } |
Dan Williams | 11e2ede | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1707 | |
| 1708 | /* prevent duplicates */ |
| 1709 | if (find_rdev(mddev, rdev->bdev->bd_dev)) |
| 1710 | return -EEXIST; |
| 1711 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1712 | /* make sure rdev->sectors exceeds mddev->dev_sectors */ |
| 1713 | if (rdev->sectors && (mddev->dev_sectors == 0 || |
| 1714 | rdev->sectors < mddev->dev_sectors)) { |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1715 | if (mddev->pers) { |
| 1716 | /* Cannot change size, so fail |
| 1717 | * If mddev->level <= 0, then we don't care |
| 1718 | * about aligning sizes (e.g. linear) |
| 1719 | */ |
| 1720 | if (mddev->level > 0) |
| 1721 | return -ENOSPC; |
| 1722 | } else |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1723 | mddev->dev_sectors = rdev->sectors; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1724 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | |
| 1726 | /* Verify rdev->desc_nr is unique. |
| 1727 | * If it is -1, assign a free number, else |
| 1728 | * check number is not in use |
| 1729 | */ |
| 1730 | if (rdev->desc_nr < 0) { |
| 1731 | int choice = 0; |
| 1732 | if (mddev->pers) choice = mddev->raid_disks; |
| 1733 | while (find_rdev_nr(mddev, choice)) |
| 1734 | choice++; |
| 1735 | rdev->desc_nr = choice; |
| 1736 | } else { |
| 1737 | if (find_rdev_nr(mddev, rdev->desc_nr)) |
| 1738 | return -EBUSY; |
| 1739 | } |
NeilBrown | de01dfa | 2009-02-06 18:02:46 +1100 | [diff] [blame] | 1740 | if (mddev->max_disks && rdev->desc_nr >= mddev->max_disks) { |
| 1741 | printk(KERN_WARNING "md: %s: array is limited to %d devices\n", |
| 1742 | mdname(mddev), mddev->max_disks); |
| 1743 | return -EBUSY; |
| 1744 | } |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1745 | bdevname(rdev->bdev,b); |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1746 | while ( (s=strchr(b, '/')) != NULL) |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1747 | *s = '!'; |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | rdev->mddev = mddev; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1750 | printk(KERN_INFO "md: bind<%s>\n", b); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1751 | |
Greg Kroah-Hartman | b2d6db5 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1752 | if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b))) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1753 | goto fail; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1754 | |
Tejun Heo | 0762b8b | 2008-08-25 19:56:12 +0900 | [diff] [blame] | 1755 | ko = &part_to_dev(rdev->bdev->bd_part)->kobj; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1756 | if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) { |
| 1757 | kobject_del(&rdev->kobj); |
| 1758 | goto fail; |
| 1759 | } |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 1760 | rdev->sysfs_state = sysfs_get_dirent(rdev->kobj.sd, "state"); |
| 1761 | |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1762 | list_add_rcu(&rdev->same_set, &mddev->disks); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1763 | bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); |
NeilBrown | 4044ba5 | 2009-01-09 08:31:11 +1100 | [diff] [blame] | 1764 | |
| 1765 | /* May as well allow recovery to be retried once */ |
| 1766 | mddev->recovery_disabled = 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | return 0; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1769 | |
| 1770 | fail: |
| 1771 | printk(KERN_WARNING "md: failed to register dev-%s for %s\n", |
| 1772 | b, mdname(mddev)); |
| 1773 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1776 | static void md_delayed_delete(struct work_struct *ws) |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1777 | { |
| 1778 | mdk_rdev_t *rdev = container_of(ws, mdk_rdev_t, del_work); |
| 1779 | kobject_del(&rdev->kobj); |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1780 | kobject_put(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | static void unbind_rdev_from_array(mdk_rdev_t * rdev) |
| 1784 | { |
| 1785 | char b[BDEVNAME_SIZE]; |
| 1786 | if (!rdev->mddev) { |
| 1787 | MD_BUG(); |
| 1788 | return; |
| 1789 | } |
Jun'ichi Nomura | 5463c79 | 2006-03-27 01:17:58 -0800 | [diff] [blame] | 1790 | bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk); |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1791 | list_del_rcu(&rdev->same_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); |
| 1793 | rdev->mddev = NULL; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1794 | sysfs_remove_link(&rdev->kobj, "block"); |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 1795 | sysfs_put(rdev->sysfs_state); |
| 1796 | rdev->sysfs_state = NULL; |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1797 | /* We need to delay this, otherwise we can deadlock when |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1798 | * writing to 'remove' to "dev/state". We also need |
| 1799 | * to delay it due to rcu usage. |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1800 | */ |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1801 | synchronize_rcu(); |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1802 | INIT_WORK(&rdev->del_work, md_delayed_delete); |
| 1803 | kobject_get(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1804 | schedule_work(&rdev->del_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | /* |
| 1808 | * prevent the device from being mounted, repartitioned or |
| 1809 | * otherwise reused by a RAID array (or any other kernel |
| 1810 | * subsystem), by bd_claiming the device. |
| 1811 | */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1812 | 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] | 1813 | { |
| 1814 | int err = 0; |
| 1815 | struct block_device *bdev; |
| 1816 | char b[BDEVNAME_SIZE]; |
| 1817 | |
Peter Zijlstra | 2e7b651 | 2006-12-08 02:36:13 -0800 | [diff] [blame] | 1818 | bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | if (IS_ERR(bdev)) { |
| 1820 | printk(KERN_ERR "md: could not open %s.\n", |
| 1821 | __bdevname(dev, b)); |
| 1822 | return PTR_ERR(bdev); |
| 1823 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1824 | err = bd_claim(bdev, shared ? (mdk_rdev_t *)lock_rdev : rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | if (err) { |
| 1826 | printk(KERN_ERR "md: could not bd_claim %s.\n", |
| 1827 | bdevname(bdev, b)); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 1828 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | return err; |
| 1830 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1831 | if (!shared) |
| 1832 | set_bit(AllReserved, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | rdev->bdev = bdev; |
| 1834 | return err; |
| 1835 | } |
| 1836 | |
| 1837 | static void unlock_rdev(mdk_rdev_t *rdev) |
| 1838 | { |
| 1839 | struct block_device *bdev = rdev->bdev; |
| 1840 | rdev->bdev = NULL; |
| 1841 | if (!bdev) |
| 1842 | MD_BUG(); |
| 1843 | bd_release(bdev); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 1844 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | void md_autodetect_dev(dev_t dev); |
| 1848 | |
| 1849 | static void export_rdev(mdk_rdev_t * rdev) |
| 1850 | { |
| 1851 | char b[BDEVNAME_SIZE]; |
| 1852 | printk(KERN_INFO "md: export_rdev(%s)\n", |
| 1853 | bdevname(rdev->bdev,b)); |
| 1854 | if (rdev->mddev) |
| 1855 | MD_BUG(); |
| 1856 | free_disk_sb(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | #ifndef MODULE |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1858 | if (test_bit(AutoDetected, &rdev->flags)) |
| 1859 | md_autodetect_dev(rdev->bdev->bd_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | #endif |
| 1861 | unlock_rdev(rdev); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1862 | kobject_put(&rdev->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | static void kick_rdev_from_array(mdk_rdev_t * rdev) |
| 1866 | { |
| 1867 | unbind_rdev_from_array(rdev); |
| 1868 | export_rdev(rdev); |
| 1869 | } |
| 1870 | |
| 1871 | static void export_array(mddev_t *mddev) |
| 1872 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1873 | mdk_rdev_t *rdev, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1875 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | if (!rdev->mddev) { |
| 1877 | MD_BUG(); |
| 1878 | continue; |
| 1879 | } |
| 1880 | kick_rdev_from_array(rdev); |
| 1881 | } |
| 1882 | if (!list_empty(&mddev->disks)) |
| 1883 | MD_BUG(); |
| 1884 | mddev->raid_disks = 0; |
| 1885 | mddev->major_version = 0; |
| 1886 | } |
| 1887 | |
| 1888 | static void print_desc(mdp_disk_t *desc) |
| 1889 | { |
| 1890 | printk(" DISK<N:%d,(%d,%d),R:%d,S:%d>\n", desc->number, |
| 1891 | desc->major,desc->minor,desc->raid_disk,desc->state); |
| 1892 | } |
| 1893 | |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1894 | static void print_sb_90(mdp_super_t *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | { |
| 1896 | int i; |
| 1897 | |
| 1898 | printk(KERN_INFO |
| 1899 | "md: SB: (V:%d.%d.%d) ID:<%08x.%08x.%08x.%08x> CT:%08x\n", |
| 1900 | sb->major_version, sb->minor_version, sb->patch_version, |
| 1901 | sb->set_uuid0, sb->set_uuid1, sb->set_uuid2, sb->set_uuid3, |
| 1902 | sb->ctime); |
| 1903 | printk(KERN_INFO "md: L%d S%08d ND:%d RD:%d md%d LO:%d CS:%d\n", |
| 1904 | sb->level, sb->size, sb->nr_disks, sb->raid_disks, |
| 1905 | sb->md_minor, sb->layout, sb->chunk_size); |
| 1906 | printk(KERN_INFO "md: UT:%08x ST:%d AD:%d WD:%d" |
| 1907 | " FD:%d SD:%d CSUM:%08x E:%08lx\n", |
| 1908 | sb->utime, sb->state, sb->active_disks, sb->working_disks, |
| 1909 | sb->failed_disks, sb->spare_disks, |
| 1910 | sb->sb_csum, (unsigned long)sb->events_lo); |
| 1911 | |
| 1912 | printk(KERN_INFO); |
| 1913 | for (i = 0; i < MD_SB_DISKS; i++) { |
| 1914 | mdp_disk_t *desc; |
| 1915 | |
| 1916 | desc = sb->disks + i; |
| 1917 | if (desc->number || desc->major || desc->minor || |
| 1918 | desc->raid_disk || (desc->state && (desc->state != 4))) { |
| 1919 | printk(" D %2d: ", i); |
| 1920 | print_desc(desc); |
| 1921 | } |
| 1922 | } |
| 1923 | printk(KERN_INFO "md: THIS: "); |
| 1924 | print_desc(&sb->this_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1927 | static void print_sb_1(struct mdp_superblock_1 *sb) |
| 1928 | { |
| 1929 | __u8 *uuid; |
| 1930 | |
| 1931 | uuid = sb->set_uuid; |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 1932 | printk(KERN_INFO |
| 1933 | "md: SB: (V:%u) (F:0x%08x) Array-ID:<%02x%02x%02x%02x" |
| 1934 | ":%02x%02x:%02x%02x:%02x%02x:%02x%02x%02x%02x%02x%02x>\n" |
| 1935 | "md: Name: \"%s\" CT:%llu\n", |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1936 | le32_to_cpu(sb->major_version), |
| 1937 | le32_to_cpu(sb->feature_map), |
| 1938 | uuid[0], uuid[1], uuid[2], uuid[3], |
| 1939 | uuid[4], uuid[5], uuid[6], uuid[7], |
| 1940 | uuid[8], uuid[9], uuid[10], uuid[11], |
| 1941 | uuid[12], uuid[13], uuid[14], uuid[15], |
| 1942 | sb->set_name, |
| 1943 | (unsigned long long)le64_to_cpu(sb->ctime) |
| 1944 | & MD_SUPERBLOCK_1_TIME_SEC_MASK); |
| 1945 | |
| 1946 | uuid = sb->device_uuid; |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 1947 | printk(KERN_INFO |
| 1948 | "md: L%u SZ%llu RD:%u LO:%u CS:%u DO:%llu DS:%llu SO:%llu" |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1949 | " RO:%llu\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 1950 | "md: Dev:%08x UUID: %02x%02x%02x%02x:%02x%02x:%02x%02x:%02x%02x" |
| 1951 | ":%02x%02x%02x%02x%02x%02x\n" |
| 1952 | "md: (F:0x%08x) UT:%llu Events:%llu ResyncOffset:%llu CSUM:0x%08x\n" |
| 1953 | "md: (MaxDev:%u) \n", |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1954 | le32_to_cpu(sb->level), |
| 1955 | (unsigned long long)le64_to_cpu(sb->size), |
| 1956 | le32_to_cpu(sb->raid_disks), |
| 1957 | le32_to_cpu(sb->layout), |
| 1958 | le32_to_cpu(sb->chunksize), |
| 1959 | (unsigned long long)le64_to_cpu(sb->data_offset), |
| 1960 | (unsigned long long)le64_to_cpu(sb->data_size), |
| 1961 | (unsigned long long)le64_to_cpu(sb->super_offset), |
| 1962 | (unsigned long long)le64_to_cpu(sb->recovery_offset), |
| 1963 | le32_to_cpu(sb->dev_number), |
| 1964 | uuid[0], uuid[1], uuid[2], uuid[3], |
| 1965 | uuid[4], uuid[5], uuid[6], uuid[7], |
| 1966 | uuid[8], uuid[9], uuid[10], uuid[11], |
| 1967 | uuid[12], uuid[13], uuid[14], uuid[15], |
| 1968 | sb->devflags, |
| 1969 | (unsigned long long)le64_to_cpu(sb->utime) & MD_SUPERBLOCK_1_TIME_SEC_MASK, |
| 1970 | (unsigned long long)le64_to_cpu(sb->events), |
| 1971 | (unsigned long long)le64_to_cpu(sb->resync_offset), |
| 1972 | le32_to_cpu(sb->sb_csum), |
| 1973 | le32_to_cpu(sb->max_dev) |
| 1974 | ); |
| 1975 | } |
| 1976 | |
| 1977 | static void print_rdev(mdk_rdev_t *rdev, int major_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | { |
| 1979 | char b[BDEVNAME_SIZE]; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1980 | printk(KERN_INFO "md: rdev %s, Sect:%08llu F:%d S:%d DN:%u\n", |
| 1981 | bdevname(rdev->bdev, b), (unsigned long long)rdev->sectors, |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1982 | test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags), |
| 1983 | rdev->desc_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | if (rdev->sb_loaded) { |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1985 | printk(KERN_INFO "md: rdev superblock (MJ:%d):\n", major_version); |
| 1986 | switch (major_version) { |
| 1987 | case 0: |
| 1988 | print_sb_90((mdp_super_t*)page_address(rdev->sb_page)); |
| 1989 | break; |
| 1990 | case 1: |
| 1991 | print_sb_1((struct mdp_superblock_1 *)page_address(rdev->sb_page)); |
| 1992 | break; |
| 1993 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | } else |
| 1995 | printk(KERN_INFO "md: no rdev superblock!\n"); |
| 1996 | } |
| 1997 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 1998 | static void md_print_devices(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2000 | struct list_head *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | mdk_rdev_t *rdev; |
| 2002 | mddev_t *mddev; |
| 2003 | char b[BDEVNAME_SIZE]; |
| 2004 | |
| 2005 | printk("\n"); |
| 2006 | printk("md: **********************************\n"); |
| 2007 | printk("md: * <COMPLETE RAID STATE PRINTOUT> *\n"); |
| 2008 | printk("md: **********************************\n"); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 2009 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 2011 | if (mddev->bitmap) |
| 2012 | bitmap_print_sb(mddev->bitmap); |
| 2013 | else |
| 2014 | printk("%s: ", mdname(mddev)); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2015 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 2017 | printk("\n"); |
| 2018 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2019 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2020 | print_rdev(rdev, mddev->major_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | } |
| 2022 | printk("md: **********************************\n"); |
| 2023 | printk("\n"); |
| 2024 | } |
| 2025 | |
| 2026 | |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2027 | static void sync_sbs(mddev_t * mddev, int nospares) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2029 | /* Update each superblock (in-memory image), but |
| 2030 | * if we are allowed to, skip spares which already |
| 2031 | * have the right event counter, or have one earlier |
| 2032 | * (which would mean they aren't being marked as dirty |
| 2033 | * with the rest of the array) |
| 2034 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | |
NeilBrown | 5e86510 | 2009-11-12 12:08:04 +1100 | [diff] [blame] | 2037 | /* First make sure individual recovery_offsets are correct */ |
| 2038 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 2039 | if (rdev->raid_disk >= 0 && |
| 2040 | !test_bit(In_sync, &rdev->flags) && |
| 2041 | mddev->curr_resync_completed > rdev->recovery_offset) |
| 2042 | rdev->recovery_offset = mddev->curr_resync_completed; |
| 2043 | |
| 2044 | } |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2045 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2046 | if (rdev->sb_events == mddev->events || |
| 2047 | (nospares && |
| 2048 | rdev->raid_disk < 0 && |
| 2049 | (rdev->sb_events&1)==0 && |
| 2050 | rdev->sb_events+1 == mddev->events)) { |
| 2051 | /* Don't update this superblock */ |
| 2052 | rdev->sb_loaded = 2; |
| 2053 | } else { |
| 2054 | super_types[mddev->major_version]. |
| 2055 | sync_super(mddev, rdev); |
| 2056 | rdev->sb_loaded = 1; |
| 2057 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | } |
| 2059 | } |
| 2060 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2061 | static void md_update_sb(mddev_t * mddev, int force_change) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | mdk_rdev_t *rdev; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2064 | int sync_req; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2065 | int nospares = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | |
NeilBrown | 1b57f13 | 2009-06-18 08:48:19 +1000 | [diff] [blame] | 2067 | mddev->utime = get_seconds(); |
NeilBrown | 8377bc8 | 2008-04-30 00:52:28 -0700 | [diff] [blame] | 2068 | if (mddev->external) |
| 2069 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | repeat: |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2071 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2072 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2073 | set_bit(MD_CHANGE_PENDING, &mddev->flags); |
| 2074 | if (test_and_clear_bit(MD_CHANGE_DEVS, &mddev->flags)) |
| 2075 | force_change = 1; |
| 2076 | if (test_and_clear_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 2077 | /* just a clean<-> dirty transition, possibly leave spares alone, |
| 2078 | * though if events isn't the right even/odd, we will have to do |
| 2079 | * spares after all |
| 2080 | */ |
| 2081 | nospares = 1; |
| 2082 | if (force_change) |
| 2083 | nospares = 0; |
| 2084 | if (mddev->degraded) |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2085 | /* If the array is degraded, then skipping spares is both |
| 2086 | * dangerous and fairly pointless. |
| 2087 | * Dangerous because a device that was removed from the array |
| 2088 | * might have a event_count that still looks up-to-date, |
| 2089 | * so it can be re-added without a resync. |
| 2090 | * Pointless because if there are any spares to skip, |
| 2091 | * then a recovery will happen and soon that array won't |
| 2092 | * be degraded any more and the spare can go back to sleep then. |
| 2093 | */ |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2094 | nospares = 0; |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2095 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2096 | sync_req = mddev->in_sync; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2097 | |
| 2098 | /* If this is just a dirty<->clean transition, and the array is clean |
| 2099 | * and 'events' is odd, we can roll back to the previous clean state */ |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2100 | if (nospares |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2101 | && (mddev->in_sync && mddev->recovery_cp == MaxSector) |
NeilBrown | 1031be7 | 2007-01-26 00:57:02 -0800 | [diff] [blame] | 2102 | && (mddev->events & 1) |
| 2103 | && mddev->events != 1) |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2104 | mddev->events--; |
| 2105 | else { |
| 2106 | /* otherwise we have to go forward and ... */ |
| 2107 | mddev->events ++; |
| 2108 | if (!mddev->in_sync || mddev->recovery_cp != MaxSector) { /* not clean */ |
NeilBrown | 51d5668 | 2009-08-13 09:54:02 +1000 | [diff] [blame] | 2109 | /* .. if the array isn't clean, an 'even' event must also go |
| 2110 | * to spares. */ |
| 2111 | if ((mddev->events&1)==0) |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2112 | nospares = 0; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2113 | } else { |
NeilBrown | 51d5668 | 2009-08-13 09:54:02 +1000 | [diff] [blame] | 2114 | /* otherwise an 'odd' event must go to spares */ |
| 2115 | if ((mddev->events&1)) |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2116 | nospares = 0; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2117 | } |
| 2118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | |
| 2120 | if (!mddev->events) { |
| 2121 | /* |
| 2122 | * oops, this 64-bit counter should never wrap. |
| 2123 | * Either we are in around ~1 trillion A.C., assuming |
| 2124 | * 1 reboot per second, or we have a bug: |
| 2125 | */ |
| 2126 | MD_BUG(); |
| 2127 | mddev->events --; |
| 2128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | |
| 2130 | /* |
| 2131 | * do not write anything to disk if using |
| 2132 | * nonpersistent superblocks |
| 2133 | */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2134 | if (!mddev->persistent) { |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2135 | if (!mddev->external) |
| 2136 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
| 2137 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2138 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 2139 | wake_up(&mddev->sb_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2141 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2142 | sync_sbs(mddev, nospares); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2143 | spin_unlock_irq(&mddev->write_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | |
| 2145 | dprintk(KERN_INFO |
| 2146 | "md: updating %s RAID superblock on device (in sync %d)\n", |
| 2147 | mdname(mddev),mddev->in_sync); |
| 2148 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 2149 | bitmap_update_sb(mddev->bitmap); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2150 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | char b[BDEVNAME_SIZE]; |
| 2152 | dprintk(KERN_INFO "md: "); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2153 | if (rdev->sb_loaded != 1) |
| 2154 | continue; /* no noise on spare devices */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2155 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | dprintk("(skipping faulty "); |
| 2157 | |
| 2158 | dprintk("%s ", bdevname(rdev->bdev,b)); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2159 | if (!test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2160 | md_super_write(mddev,rdev, |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 2161 | rdev->sb_start, rdev->sb_size, |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2162 | rdev->sb_page); |
| 2163 | dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", |
| 2164 | bdevname(rdev->bdev,b), |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 2165 | (unsigned long long)rdev->sb_start); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2166 | rdev->sb_events = mddev->events; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | } else |
| 2169 | dprintk(")\n"); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2170 | if (mddev->level == LEVEL_MULTIPATH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | /* only need to write one superblock... */ |
| 2172 | break; |
| 2173 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2174 | md_super_wait(mddev); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2175 | /* 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] | 2176 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2177 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2178 | if (mddev->in_sync != sync_req || |
| 2179 | test_bit(MD_CHANGE_DEVS, &mddev->flags)) { |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2180 | /* have to write it out again */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2181 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2182 | goto repeat; |
| 2183 | } |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2184 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2185 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 2186 | wake_up(&mddev->sb_wait); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 2187 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 2188 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
Andre Noll | 7f6ce76 | 2008-03-23 18:34:54 +0100 | [diff] [blame] | 2192 | /* words written to sysfs files may, or may not, be \n terminated. |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 2193 | * We want to accept with case. For this we use cmd_match. |
| 2194 | */ |
| 2195 | static int cmd_match(const char *cmd, const char *str) |
| 2196 | { |
| 2197 | /* See if cmd, written into a sysfs file, matches |
| 2198 | * str. They must either be the same, or cmd can |
| 2199 | * have a trailing newline |
| 2200 | */ |
| 2201 | while (*cmd && *str && *cmd == *str) { |
| 2202 | cmd++; |
| 2203 | str++; |
| 2204 | } |
| 2205 | if (*cmd == '\n') |
| 2206 | cmd++; |
| 2207 | if (*str || *cmd) |
| 2208 | return 0; |
| 2209 | return 1; |
| 2210 | } |
| 2211 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2212 | struct rdev_sysfs_entry { |
| 2213 | struct attribute attr; |
| 2214 | ssize_t (*show)(mdk_rdev_t *, char *); |
| 2215 | ssize_t (*store)(mdk_rdev_t *, const char *, size_t); |
| 2216 | }; |
| 2217 | |
| 2218 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2219 | state_show(mdk_rdev_t *rdev, char *page) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2220 | { |
| 2221 | char *sep = ""; |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2222 | size_t len = 0; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2223 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2224 | if (test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2225 | len+= sprintf(page+len, "%sfaulty",sep); |
| 2226 | sep = ","; |
| 2227 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2228 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2229 | len += sprintf(page+len, "%sin_sync",sep); |
| 2230 | sep = ","; |
| 2231 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2232 | if (test_bit(WriteMostly, &rdev->flags)) { |
| 2233 | len += sprintf(page+len, "%swrite_mostly",sep); |
| 2234 | sep = ","; |
| 2235 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2236 | if (test_bit(Blocked, &rdev->flags)) { |
| 2237 | len += sprintf(page+len, "%sblocked", sep); |
| 2238 | sep = ","; |
| 2239 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2240 | if (!test_bit(Faulty, &rdev->flags) && |
| 2241 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2242 | len += sprintf(page+len, "%sspare", sep); |
| 2243 | sep = ","; |
| 2244 | } |
| 2245 | return len+sprintf(page+len, "\n"); |
| 2246 | } |
| 2247 | |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2248 | static ssize_t |
| 2249 | state_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2250 | { |
| 2251 | /* can write |
| 2252 | * faulty - simulates and error |
| 2253 | * remove - disconnects the device |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2254 | * writemostly - sets write_mostly |
| 2255 | * -writemostly - clears write_mostly |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2256 | * blocked - sets the Blocked flag |
| 2257 | * -blocked - clears the Blocked flag |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2258 | * insync - sets Insync providing device isn't active |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2259 | */ |
| 2260 | int err = -EINVAL; |
| 2261 | if (cmd_match(buf, "faulty") && rdev->mddev->pers) { |
| 2262 | md_error(rdev->mddev, rdev); |
| 2263 | err = 0; |
| 2264 | } else if (cmd_match(buf, "remove")) { |
| 2265 | if (rdev->raid_disk >= 0) |
| 2266 | err = -EBUSY; |
| 2267 | else { |
| 2268 | mddev_t *mddev = rdev->mddev; |
| 2269 | kick_rdev_from_array(rdev); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 2270 | if (mddev->pers) |
| 2271 | md_update_sb(mddev, 1); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2272 | md_new_event(mddev); |
| 2273 | err = 0; |
| 2274 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2275 | } else if (cmd_match(buf, "writemostly")) { |
| 2276 | set_bit(WriteMostly, &rdev->flags); |
| 2277 | err = 0; |
| 2278 | } else if (cmd_match(buf, "-writemostly")) { |
| 2279 | clear_bit(WriteMostly, &rdev->flags); |
| 2280 | err = 0; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2281 | } else if (cmd_match(buf, "blocked")) { |
| 2282 | set_bit(Blocked, &rdev->flags); |
| 2283 | err = 0; |
| 2284 | } else if (cmd_match(buf, "-blocked")) { |
| 2285 | clear_bit(Blocked, &rdev->flags); |
| 2286 | wake_up(&rdev->blocked_wait); |
| 2287 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 2288 | md_wakeup_thread(rdev->mddev->thread); |
| 2289 | |
| 2290 | err = 0; |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2291 | } else if (cmd_match(buf, "insync") && rdev->raid_disk == -1) { |
| 2292 | set_bit(In_sync, &rdev->flags); |
| 2293 | err = 0; |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2294 | } |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 2295 | if (!err && rdev->sysfs_state) |
| 2296 | sysfs_notify_dirent(rdev->sysfs_state); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2297 | return err ? err : len; |
| 2298 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2299 | static struct rdev_sysfs_entry rdev_state = |
| 2300 | __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2301 | |
| 2302 | static ssize_t |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2303 | errors_show(mdk_rdev_t *rdev, char *page) |
| 2304 | { |
| 2305 | return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors)); |
| 2306 | } |
| 2307 | |
| 2308 | static ssize_t |
| 2309 | errors_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2310 | { |
| 2311 | char *e; |
| 2312 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 2313 | if (*buf && (*e == 0 || *e == '\n')) { |
| 2314 | atomic_set(&rdev->corrected_errors, n); |
| 2315 | return len; |
| 2316 | } |
| 2317 | return -EINVAL; |
| 2318 | } |
| 2319 | static struct rdev_sysfs_entry rdev_errors = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2320 | __ATTR(errors, S_IRUGO|S_IWUSR, errors_show, errors_store); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2321 | |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2322 | static ssize_t |
| 2323 | slot_show(mdk_rdev_t *rdev, char *page) |
| 2324 | { |
| 2325 | if (rdev->raid_disk < 0) |
| 2326 | return sprintf(page, "none\n"); |
| 2327 | else |
| 2328 | return sprintf(page, "%d\n", rdev->raid_disk); |
| 2329 | } |
| 2330 | |
| 2331 | static ssize_t |
| 2332 | slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2333 | { |
| 2334 | char *e; |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2335 | int err; |
| 2336 | char nm[20]; |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2337 | int slot = simple_strtoul(buf, &e, 10); |
| 2338 | if (strncmp(buf, "none", 4)==0) |
| 2339 | slot = -1; |
| 2340 | else if (e==buf || (*e && *e!= '\n')) |
| 2341 | return -EINVAL; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2342 | if (rdev->mddev->pers && slot == -1) { |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2343 | /* Setting 'slot' on an active array requires also |
| 2344 | * updating the 'rd%d' link, and communicating |
| 2345 | * with the personality with ->hot_*_disk. |
| 2346 | * For now we only support removing |
| 2347 | * failed/spare devices. This normally happens automatically, |
| 2348 | * but not when the metadata is externally managed. |
| 2349 | */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2350 | if (rdev->raid_disk == -1) |
| 2351 | return -EEXIST; |
| 2352 | /* personality does all needed checks */ |
| 2353 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 2354 | return -EINVAL; |
| 2355 | err = rdev->mddev->pers-> |
| 2356 | hot_remove_disk(rdev->mddev, rdev->raid_disk); |
| 2357 | if (err) |
| 2358 | return err; |
| 2359 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2360 | sysfs_remove_link(&rdev->mddev->kobj, nm); |
| 2361 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 2362 | md_wakeup_thread(rdev->mddev->thread); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2363 | } else if (rdev->mddev->pers) { |
| 2364 | mdk_rdev_t *rdev2; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2365 | /* Activating a spare .. or possibly reactivating |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2366 | * if we ever get bitmaps working here. |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2367 | */ |
| 2368 | |
| 2369 | if (rdev->raid_disk != -1) |
| 2370 | return -EBUSY; |
| 2371 | |
| 2372 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 2373 | return -EINVAL; |
| 2374 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2375 | list_for_each_entry(rdev2, &rdev->mddev->disks, same_set) |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2376 | if (rdev2->raid_disk == slot) |
| 2377 | return -EEXIST; |
| 2378 | |
| 2379 | rdev->raid_disk = slot; |
| 2380 | if (test_bit(In_sync, &rdev->flags)) |
| 2381 | rdev->saved_raid_disk = slot; |
| 2382 | else |
| 2383 | rdev->saved_raid_disk = -1; |
| 2384 | err = rdev->mddev->pers-> |
| 2385 | hot_add_disk(rdev->mddev, rdev); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 2386 | if (err) { |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2387 | rdev->raid_disk = -1; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2388 | return err; |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 2389 | } else |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 2390 | sysfs_notify_dirent(rdev->sysfs_state); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2391 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2392 | if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) |
| 2393 | printk(KERN_WARNING |
| 2394 | "md: cannot register " |
| 2395 | "%s for %s\n", |
| 2396 | nm, mdname(rdev->mddev)); |
| 2397 | |
| 2398 | /* don't wakeup anyone, leave that to userspace. */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2399 | } else { |
| 2400 | if (slot >= rdev->mddev->raid_disks) |
| 2401 | return -ENOSPC; |
| 2402 | rdev->raid_disk = slot; |
| 2403 | /* assume it is working */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2404 | clear_bit(Faulty, &rdev->flags); |
| 2405 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2406 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 2407 | sysfs_notify_dirent(rdev->sysfs_state); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2408 | } |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2409 | return len; |
| 2410 | } |
| 2411 | |
| 2412 | |
| 2413 | static struct rdev_sysfs_entry rdev_slot = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2414 | __ATTR(slot, S_IRUGO|S_IWUSR, slot_show, slot_store); |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2415 | |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2416 | static ssize_t |
| 2417 | offset_show(mdk_rdev_t *rdev, char *page) |
| 2418 | { |
Andrew Morton | 6961ece | 2006-01-06 00:20:59 -0800 | [diff] [blame] | 2419 | return sprintf(page, "%llu\n", (unsigned long long)rdev->data_offset); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | static ssize_t |
| 2423 | offset_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2424 | { |
| 2425 | char *e; |
| 2426 | unsigned long long offset = simple_strtoull(buf, &e, 10); |
| 2427 | if (e==buf || (*e && *e != '\n')) |
| 2428 | return -EINVAL; |
Neil Brown | 8ed0a52 | 2008-06-28 08:31:29 +1000 | [diff] [blame] | 2429 | if (rdev->mddev->pers && rdev->raid_disk >= 0) |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2430 | return -EBUSY; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2431 | if (rdev->sectors && rdev->mddev->external) |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2432 | /* Must set offset before size, so overlap checks |
| 2433 | * can be sane */ |
| 2434 | return -EBUSY; |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2435 | rdev->data_offset = offset; |
| 2436 | return len; |
| 2437 | } |
| 2438 | |
| 2439 | static struct rdev_sysfs_entry rdev_offset = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2440 | __ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2441 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2442 | static ssize_t |
| 2443 | rdev_size_show(mdk_rdev_t *rdev, char *page) |
| 2444 | { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2445 | return sprintf(page, "%llu\n", (unsigned long long)rdev->sectors / 2); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2446 | } |
| 2447 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2448 | static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2) |
| 2449 | { |
| 2450 | /* check if two start/length pairs overlap */ |
| 2451 | if (s1+l1 <= s2) |
| 2452 | return 0; |
| 2453 | if (s2+l2 <= s1) |
| 2454 | return 0; |
| 2455 | return 1; |
| 2456 | } |
| 2457 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2458 | static int strict_blocks_to_sectors(const char *buf, sector_t *sectors) |
| 2459 | { |
| 2460 | unsigned long long blocks; |
| 2461 | sector_t new; |
| 2462 | |
| 2463 | if (strict_strtoull(buf, 10, &blocks) < 0) |
| 2464 | return -EINVAL; |
| 2465 | |
| 2466 | if (blocks & 1ULL << (8 * sizeof(blocks) - 1)) |
| 2467 | return -EINVAL; /* sector conversion overflow */ |
| 2468 | |
| 2469 | new = blocks * 2; |
| 2470 | if (new != blocks * 2) |
| 2471 | return -EINVAL; /* unsigned long long to sector_t overflow */ |
| 2472 | |
| 2473 | *sectors = new; |
| 2474 | return 0; |
| 2475 | } |
| 2476 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2477 | static ssize_t |
| 2478 | rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2479 | { |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2480 | mddev_t *my_mddev = rdev->mddev; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2481 | sector_t oldsectors = rdev->sectors; |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2482 | sector_t sectors; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2483 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2484 | if (strict_blocks_to_sectors(buf, §ors) < 0) |
Neil Brown | d702745 | 2008-07-12 10:37:50 +1000 | [diff] [blame] | 2485 | return -EINVAL; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2486 | if (my_mddev->pers && rdev->raid_disk >= 0) { |
Neil Brown | d702745 | 2008-07-12 10:37:50 +1000 | [diff] [blame] | 2487 | if (my_mddev->persistent) { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2488 | sectors = super_types[my_mddev->major_version]. |
| 2489 | rdev_size_change(rdev, sectors); |
| 2490 | if (!sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2491 | return -EBUSY; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2492 | } else if (!sectors) |
| 2493 | sectors = (rdev->bdev->bd_inode->i_size >> 9) - |
| 2494 | rdev->data_offset; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2495 | } |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2496 | if (sectors < my_mddev->dev_sectors) |
Chris Webb | 7d3c6f8 | 2008-10-13 11:55:11 +1100 | [diff] [blame] | 2497 | return -EINVAL; /* component must fit device */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2498 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2499 | rdev->sectors = sectors; |
| 2500 | if (sectors > oldsectors && my_mddev->external) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2501 | /* need to check that all other rdevs with the same ->bdev |
| 2502 | * do not overlap. We need to unlock the mddev to avoid |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2503 | * a deadlock. We have already changed rdev->sectors, and if |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2504 | * we have to change it back, we will have the lock again. |
| 2505 | */ |
| 2506 | mddev_t *mddev; |
| 2507 | int overlap = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2508 | struct list_head *tmp; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2509 | |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2510 | mddev_unlock(my_mddev); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 2511 | for_each_mddev(mddev, tmp) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2512 | mdk_rdev_t *rdev2; |
| 2513 | |
| 2514 | mddev_lock(mddev); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2515 | list_for_each_entry(rdev2, &mddev->disks, same_set) |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2516 | if (test_bit(AllReserved, &rdev2->flags) || |
| 2517 | (rdev->bdev == rdev2->bdev && |
| 2518 | rdev != rdev2 && |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2519 | overlaps(rdev->data_offset, rdev->sectors, |
Andre Noll | d07bd3b | 2008-07-21 14:42:07 +1000 | [diff] [blame] | 2520 | rdev2->data_offset, |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2521 | rdev2->sectors))) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2522 | overlap = 1; |
| 2523 | break; |
| 2524 | } |
| 2525 | mddev_unlock(mddev); |
| 2526 | if (overlap) { |
| 2527 | mddev_put(mddev); |
| 2528 | break; |
| 2529 | } |
| 2530 | } |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2531 | mddev_lock(my_mddev); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2532 | if (overlap) { |
| 2533 | /* Someone else could have slipped in a size |
| 2534 | * change here, but doing so is just silly. |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2535 | * We put oldsectors back because we *know* it is |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2536 | * safe, and trust userspace not to race with |
| 2537 | * itself |
| 2538 | */ |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2539 | rdev->sectors = oldsectors; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2540 | return -EBUSY; |
| 2541 | } |
| 2542 | } |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2543 | return len; |
| 2544 | } |
| 2545 | |
| 2546 | static struct rdev_sysfs_entry rdev_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2547 | __ATTR(size, S_IRUGO|S_IWUSR, rdev_size_show, rdev_size_store); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2548 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2549 | static struct attribute *rdev_default_attrs[] = { |
| 2550 | &rdev_state.attr, |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2551 | &rdev_errors.attr, |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2552 | &rdev_slot.attr, |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2553 | &rdev_offset.attr, |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2554 | &rdev_size.attr, |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2555 | NULL, |
| 2556 | }; |
| 2557 | static ssize_t |
| 2558 | rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 2559 | { |
| 2560 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2561 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2562 | mddev_t *mddev = rdev->mddev; |
| 2563 | ssize_t rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2564 | |
| 2565 | if (!entry->show) |
| 2566 | return -EIO; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2567 | |
| 2568 | rv = mddev ? mddev_lock(mddev) : -EBUSY; |
| 2569 | if (!rv) { |
| 2570 | if (rdev->mddev == NULL) |
| 2571 | rv = -EBUSY; |
| 2572 | else |
| 2573 | rv = entry->show(rdev, page); |
| 2574 | mddev_unlock(mddev); |
| 2575 | } |
| 2576 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | static ssize_t |
| 2580 | rdev_attr_store(struct kobject *kobj, struct attribute *attr, |
| 2581 | const char *page, size_t length) |
| 2582 | { |
| 2583 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2584 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2585 | ssize_t rv; |
| 2586 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2587 | |
| 2588 | if (!entry->store) |
| 2589 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 2590 | if (!capable(CAP_SYS_ADMIN)) |
| 2591 | return -EACCES; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2592 | rv = mddev ? mddev_lock(mddev): -EBUSY; |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2593 | if (!rv) { |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2594 | if (rdev->mddev == NULL) |
| 2595 | rv = -EBUSY; |
| 2596 | else |
| 2597 | rv = entry->store(rdev, page, length); |
Dan Williams | 6a51830 | 2008-04-30 00:52:28 -0700 | [diff] [blame] | 2598 | mddev_unlock(mddev); |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2599 | } |
| 2600 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | static void rdev_free(struct kobject *ko) |
| 2604 | { |
| 2605 | mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj); |
| 2606 | kfree(rdev); |
| 2607 | } |
| 2608 | static struct sysfs_ops rdev_sysfs_ops = { |
| 2609 | .show = rdev_attr_show, |
| 2610 | .store = rdev_attr_store, |
| 2611 | }; |
| 2612 | static struct kobj_type rdev_ktype = { |
| 2613 | .release = rdev_free, |
| 2614 | .sysfs_ops = &rdev_sysfs_ops, |
| 2615 | .default_attrs = rdev_default_attrs, |
| 2616 | }; |
| 2617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | /* |
| 2619 | * Import a device. If 'super_format' >= 0, then sanity check the superblock |
| 2620 | * |
| 2621 | * mark the device faulty if: |
| 2622 | * |
| 2623 | * - the device is nonexistent (zero size) |
| 2624 | * - the device has no valid superblock |
| 2625 | * |
| 2626 | * a faulty rdev _never_ has rdev->sb set. |
| 2627 | */ |
| 2628 | static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_minor) |
| 2629 | { |
| 2630 | char b[BDEVNAME_SIZE]; |
| 2631 | int err; |
| 2632 | mdk_rdev_t *rdev; |
| 2633 | sector_t size; |
| 2634 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 2635 | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | if (!rdev) { |
| 2637 | printk(KERN_ERR "md: could not alloc mem for new device!\n"); |
| 2638 | return ERR_PTR(-ENOMEM); |
| 2639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | |
| 2641 | if ((err = alloc_disk_sb(rdev))) |
| 2642 | goto abort_free; |
| 2643 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2644 | err = lock_rdev(rdev, newdev, super_format == -2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | if (err) |
| 2646 | goto abort_free; |
| 2647 | |
Greg Kroah-Hartman | f9cb074 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 2648 | kobject_init(&rdev->kobj, &rdev_ktype); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | rdev->desc_nr = -1; |
NeilBrown | 2b6e845 | 2006-10-28 10:38:30 -0700 | [diff] [blame] | 2651 | rdev->saved_raid_disk = -1; |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 2652 | rdev->raid_disk = -1; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2653 | rdev->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | rdev->data_offset = 0; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2655 | rdev->sb_events = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | atomic_set(&rdev->nr_pending, 0); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2657 | atomic_set(&rdev->read_errors, 0); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2658 | atomic_set(&rdev->corrected_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | |
| 2660 | size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 2661 | if (!size) { |
| 2662 | printk(KERN_WARNING |
| 2663 | "md: %s has zero or unknown size, marking faulty!\n", |
| 2664 | bdevname(rdev->bdev,b)); |
| 2665 | err = -EINVAL; |
| 2666 | goto abort_free; |
| 2667 | } |
| 2668 | |
| 2669 | if (super_format >= 0) { |
| 2670 | err = super_types[super_format]. |
| 2671 | load_super(rdev, NULL, super_minor); |
| 2672 | if (err == -EINVAL) { |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 2673 | printk(KERN_WARNING |
| 2674 | "md: %s does not have a valid v%d.%d " |
| 2675 | "superblock, not importing!\n", |
| 2676 | bdevname(rdev->bdev,b), |
| 2677 | super_format, super_minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | goto abort_free; |
| 2679 | } |
| 2680 | if (err < 0) { |
| 2681 | printk(KERN_WARNING |
| 2682 | "md: could not read %s's sb, not importing!\n", |
| 2683 | bdevname(rdev->bdev,b)); |
| 2684 | goto abort_free; |
| 2685 | } |
| 2686 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | INIT_LIST_HEAD(&rdev->same_set); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2689 | init_waitqueue_head(&rdev->blocked_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | |
| 2691 | return rdev; |
| 2692 | |
| 2693 | abort_free: |
| 2694 | if (rdev->sb_page) { |
| 2695 | if (rdev->bdev) |
| 2696 | unlock_rdev(rdev); |
| 2697 | free_disk_sb(rdev); |
| 2698 | } |
| 2699 | kfree(rdev); |
| 2700 | return ERR_PTR(err); |
| 2701 | } |
| 2702 | |
| 2703 | /* |
| 2704 | * Check a full RAID array for plausibility |
| 2705 | */ |
| 2706 | |
| 2707 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 2708 | static void analyze_sbs(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | { |
| 2710 | int i; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2711 | mdk_rdev_t *rdev, *freshest, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | char b[BDEVNAME_SIZE]; |
| 2713 | |
| 2714 | freshest = NULL; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2715 | rdev_for_each(rdev, tmp, mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | switch (super_types[mddev->major_version]. |
| 2717 | load_super(rdev, freshest, mddev->minor_version)) { |
| 2718 | case 1: |
| 2719 | freshest = rdev; |
| 2720 | break; |
| 2721 | case 0: |
| 2722 | break; |
| 2723 | default: |
| 2724 | printk( KERN_ERR \ |
| 2725 | "md: fatal superblock inconsistency in %s" |
| 2726 | " -- removing from array\n", |
| 2727 | bdevname(rdev->bdev,b)); |
| 2728 | kick_rdev_from_array(rdev); |
| 2729 | } |
| 2730 | |
| 2731 | |
| 2732 | super_types[mddev->major_version]. |
| 2733 | validate_super(mddev, freshest); |
| 2734 | |
| 2735 | i = 0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2736 | rdev_for_each(rdev, tmp, mddev) { |
NeilBrown | de01dfa | 2009-02-06 18:02:46 +1100 | [diff] [blame] | 2737 | if (rdev->desc_nr >= mddev->max_disks || |
| 2738 | i > mddev->max_disks) { |
| 2739 | printk(KERN_WARNING |
| 2740 | "md: %s: %s: only %d devices permitted\n", |
| 2741 | mdname(mddev), bdevname(rdev->bdev, b), |
| 2742 | mddev->max_disks); |
| 2743 | kick_rdev_from_array(rdev); |
| 2744 | continue; |
| 2745 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | if (rdev != freshest) |
| 2747 | if (super_types[mddev->major_version]. |
| 2748 | validate_super(mddev, rdev)) { |
| 2749 | printk(KERN_WARNING "md: kicking non-fresh %s" |
| 2750 | " from array!\n", |
| 2751 | bdevname(rdev->bdev,b)); |
| 2752 | kick_rdev_from_array(rdev); |
| 2753 | continue; |
| 2754 | } |
| 2755 | if (mddev->level == LEVEL_MULTIPATH) { |
| 2756 | rdev->desc_nr = i++; |
| 2757 | rdev->raid_disk = rdev->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2758 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 2759 | } else if (rdev->raid_disk >= (mddev->raid_disks - min(0, mddev->delta_disks))) { |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 2760 | rdev->raid_disk = -1; |
| 2761 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | } |
| 2763 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
NeilBrown | 72e0207 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2766 | /* Read a fixed-point number. |
| 2767 | * Numbers in sysfs attributes should be in "standard" units where |
| 2768 | * possible, so time should be in seconds. |
| 2769 | * However we internally use a a much smaller unit such as |
| 2770 | * milliseconds or jiffies. |
| 2771 | * This function takes a decimal number with a possible fractional |
| 2772 | * component, and produces an integer which is the result of |
| 2773 | * multiplying that number by 10^'scale'. |
| 2774 | * all without any floating-point arithmetic. |
| 2775 | */ |
| 2776 | int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale) |
| 2777 | { |
| 2778 | unsigned long result = 0; |
| 2779 | long decimals = -1; |
| 2780 | while (isdigit(*cp) || (*cp == '.' && decimals < 0)) { |
| 2781 | if (*cp == '.') |
| 2782 | decimals = 0; |
| 2783 | else if (decimals < scale) { |
| 2784 | unsigned int value; |
| 2785 | value = *cp - '0'; |
| 2786 | result = result * 10 + value; |
| 2787 | if (decimals >= 0) |
| 2788 | decimals++; |
| 2789 | } |
| 2790 | cp++; |
| 2791 | } |
| 2792 | if (*cp == '\n') |
| 2793 | cp++; |
| 2794 | if (*cp) |
| 2795 | return -EINVAL; |
| 2796 | if (decimals < 0) |
| 2797 | decimals = 0; |
| 2798 | while (decimals < scale) { |
| 2799 | result *= 10; |
| 2800 | decimals ++; |
| 2801 | } |
| 2802 | *res = result; |
| 2803 | return 0; |
| 2804 | } |
| 2805 | |
| 2806 | |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2807 | static void md_safemode_timeout(unsigned long data); |
| 2808 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2809 | static ssize_t |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2810 | safe_delay_show(mddev_t *mddev, char *page) |
| 2811 | { |
| 2812 | int msec = (mddev->safemode_delay*1000)/HZ; |
| 2813 | return sprintf(page, "%d.%03d\n", msec/1000, msec%1000); |
| 2814 | } |
| 2815 | static ssize_t |
| 2816 | safe_delay_store(mddev_t *mddev, const char *cbuf, size_t len) |
| 2817 | { |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2818 | unsigned long msec; |
Dan Williams | 97ce0a7 | 2008-09-24 22:48:19 -0700 | [diff] [blame] | 2819 | |
NeilBrown | 72e0207 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2820 | if (strict_strtoul_scaled(cbuf, &msec, 3) < 0) |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2821 | return -EINVAL; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2822 | if (msec == 0) |
| 2823 | mddev->safemode_delay = 0; |
| 2824 | else { |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2825 | unsigned long old_delay = mddev->safemode_delay; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2826 | mddev->safemode_delay = (msec*HZ)/1000; |
| 2827 | if (mddev->safemode_delay == 0) |
| 2828 | mddev->safemode_delay = 1; |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2829 | if (mddev->safemode_delay < old_delay) |
| 2830 | md_safemode_timeout((unsigned long)mddev); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2831 | } |
| 2832 | return len; |
| 2833 | } |
| 2834 | static struct md_sysfs_entry md_safe_delay = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2835 | __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] | 2836 | |
| 2837 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2838 | level_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2839 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2840 | struct mdk_personality *p = mddev->pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2841 | if (p) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2842 | return sprintf(page, "%s\n", p->name); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2843 | else if (mddev->clevel[0]) |
| 2844 | return sprintf(page, "%s\n", mddev->clevel); |
| 2845 | else if (mddev->level != LEVEL_NONE) |
| 2846 | return sprintf(page, "%d\n", mddev->level); |
| 2847 | else |
| 2848 | return 0; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2849 | } |
| 2850 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2851 | static ssize_t |
| 2852 | level_store(mddev_t *mddev, const char *buf, size_t len) |
| 2853 | { |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2854 | char level[16]; |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2855 | ssize_t rv = len; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2856 | struct mdk_personality *pers; |
| 2857 | void *priv; |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 2858 | mdk_rdev_t *rdev; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2859 | |
| 2860 | if (mddev->pers == NULL) { |
| 2861 | if (len == 0) |
| 2862 | return 0; |
| 2863 | if (len >= sizeof(mddev->clevel)) |
| 2864 | return -ENOSPC; |
| 2865 | strncpy(mddev->clevel, buf, len); |
| 2866 | if (mddev->clevel[len-1] == '\n') |
| 2867 | len--; |
| 2868 | mddev->clevel[len] = 0; |
| 2869 | mddev->level = LEVEL_NONE; |
| 2870 | return rv; |
| 2871 | } |
| 2872 | |
| 2873 | /* request to change the personality. Need to ensure: |
| 2874 | * - array is not engaged in resync/recovery/reshape |
| 2875 | * - old personality can be suspended |
| 2876 | * - new personality will access other array. |
| 2877 | */ |
| 2878 | |
| 2879 | if (mddev->sync_thread || mddev->reshape_position != MaxSector) |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2880 | return -EBUSY; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2881 | |
| 2882 | if (!mddev->pers->quiesce) { |
| 2883 | printk(KERN_WARNING "md: %s: %s does not support online personality change\n", |
| 2884 | mdname(mddev), mddev->pers->name); |
| 2885 | return -EINVAL; |
| 2886 | } |
| 2887 | |
| 2888 | /* Now find the new personality */ |
| 2889 | if (len == 0 || len >= sizeof(level)) |
| 2890 | return -EINVAL; |
| 2891 | strncpy(level, buf, len); |
| 2892 | if (level[len-1] == '\n') |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2893 | len--; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2894 | level[len] = 0; |
| 2895 | |
| 2896 | request_module("md-%s", level); |
| 2897 | spin_lock(&pers_lock); |
| 2898 | pers = find_pers(LEVEL_NONE, level); |
| 2899 | if (!pers || !try_module_get(pers->owner)) { |
| 2900 | spin_unlock(&pers_lock); |
| 2901 | printk(KERN_WARNING "md: personality %s not loaded\n", level); |
| 2902 | return -EINVAL; |
| 2903 | } |
| 2904 | spin_unlock(&pers_lock); |
| 2905 | |
| 2906 | if (pers == mddev->pers) { |
| 2907 | /* Nothing to do! */ |
| 2908 | module_put(pers->owner); |
| 2909 | return rv; |
| 2910 | } |
| 2911 | if (!pers->takeover) { |
| 2912 | module_put(pers->owner); |
| 2913 | printk(KERN_WARNING "md: %s: %s does not support personality takeover\n", |
| 2914 | mdname(mddev), level); |
| 2915 | return -EINVAL; |
| 2916 | } |
| 2917 | |
| 2918 | /* ->takeover must set new_* and/or delta_disks |
| 2919 | * if it succeeds, and may set them when it fails. |
| 2920 | */ |
| 2921 | priv = pers->takeover(mddev); |
| 2922 | if (IS_ERR(priv)) { |
| 2923 | mddev->new_level = mddev->level; |
| 2924 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 2925 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2926 | mddev->raid_disks -= mddev->delta_disks; |
| 2927 | mddev->delta_disks = 0; |
| 2928 | module_put(pers->owner); |
| 2929 | printk(KERN_WARNING "md: %s: %s would not accept array\n", |
| 2930 | mdname(mddev), level); |
| 2931 | return PTR_ERR(priv); |
| 2932 | } |
| 2933 | |
| 2934 | /* Looks like we have a winner */ |
| 2935 | mddev_suspend(mddev); |
| 2936 | mddev->pers->stop(mddev); |
| 2937 | module_put(mddev->pers->owner); |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 2938 | /* Invalidate devices that are now superfluous */ |
| 2939 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 2940 | if (rdev->raid_disk >= mddev->raid_disks) { |
| 2941 | rdev->raid_disk = -1; |
| 2942 | clear_bit(In_sync, &rdev->flags); |
| 2943 | } |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2944 | mddev->pers = pers; |
| 2945 | mddev->private = priv; |
| 2946 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
| 2947 | mddev->level = mddev->new_level; |
| 2948 | mddev->layout = mddev->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 2949 | mddev->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2950 | mddev->delta_disks = 0; |
| 2951 | pers->run(mddev); |
| 2952 | mddev_resume(mddev); |
| 2953 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 2954 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 2955 | md_wakeup_thread(mddev->thread); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2956 | return rv; |
| 2957 | } |
| 2958 | |
| 2959 | static struct md_sysfs_entry md_level = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2960 | __ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2961 | |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2962 | |
| 2963 | static ssize_t |
| 2964 | layout_show(mddev_t *mddev, char *page) |
| 2965 | { |
| 2966 | /* just a number, not meaningful for all levels */ |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 2967 | if (mddev->reshape_position != MaxSector && |
| 2968 | mddev->layout != mddev->new_layout) |
| 2969 | return sprintf(page, "%d (%d)\n", |
| 2970 | mddev->new_layout, mddev->layout); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2971 | return sprintf(page, "%d\n", mddev->layout); |
| 2972 | } |
| 2973 | |
| 2974 | static ssize_t |
| 2975 | layout_store(mddev_t *mddev, const char *buf, size_t len) |
| 2976 | { |
| 2977 | char *e; |
| 2978 | unsigned long n = simple_strtoul(buf, &e, 10); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2979 | |
| 2980 | if (!*buf || (*e && *e != '\n')) |
| 2981 | return -EINVAL; |
| 2982 | |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 2983 | if (mddev->pers) { |
| 2984 | int err; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 2985 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 2986 | return -EBUSY; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 2987 | mddev->new_layout = n; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 2988 | err = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 2989 | if (err) { |
| 2990 | mddev->new_layout = mddev->layout; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 2991 | return err; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 2992 | } |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 2993 | } else { |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 2994 | mddev->new_layout = n; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 2995 | if (mddev->reshape_position == MaxSector) |
| 2996 | mddev->layout = n; |
| 2997 | } |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 2998 | return len; |
| 2999 | } |
| 3000 | static struct md_sysfs_entry md_layout = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3001 | __ATTR(layout, S_IRUGO|S_IWUSR, layout_show, layout_store); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3002 | |
| 3003 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3004 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3005 | raid_disks_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3006 | { |
NeilBrown | bb63654 | 2005-11-08 21:39:45 -0800 | [diff] [blame] | 3007 | if (mddev->raid_disks == 0) |
| 3008 | return 0; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3009 | if (mddev->reshape_position != MaxSector && |
| 3010 | mddev->delta_disks != 0) |
| 3011 | return sprintf(page, "%d (%d)\n", mddev->raid_disks, |
| 3012 | mddev->raid_disks - mddev->delta_disks); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3013 | return sprintf(page, "%d\n", mddev->raid_disks); |
| 3014 | } |
| 3015 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3016 | static int update_raid_disks(mddev_t *mddev, int raid_disks); |
| 3017 | |
| 3018 | static ssize_t |
| 3019 | raid_disks_store(mddev_t *mddev, const char *buf, size_t len) |
| 3020 | { |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3021 | char *e; |
| 3022 | int rv = 0; |
| 3023 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3024 | |
| 3025 | if (!*buf || (*e && *e != '\n')) |
| 3026 | return -EINVAL; |
| 3027 | |
| 3028 | if (mddev->pers) |
| 3029 | rv = update_raid_disks(mddev, n); |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3030 | else if (mddev->reshape_position != MaxSector) { |
| 3031 | int olddisks = mddev->raid_disks - mddev->delta_disks; |
| 3032 | mddev->delta_disks = n - olddisks; |
| 3033 | mddev->raid_disks = n; |
| 3034 | } else |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3035 | mddev->raid_disks = n; |
| 3036 | return rv ? rv : len; |
| 3037 | } |
| 3038 | static struct md_sysfs_entry md_raid_disks = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3039 | __ATTR(raid_disks, S_IRUGO|S_IWUSR, raid_disks_show, raid_disks_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3040 | |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3041 | static ssize_t |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3042 | chunk_size_show(mddev_t *mddev, char *page) |
| 3043 | { |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3044 | if (mddev->reshape_position != MaxSector && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3045 | mddev->chunk_sectors != mddev->new_chunk_sectors) |
| 3046 | return sprintf(page, "%d (%d)\n", |
| 3047 | mddev->new_chunk_sectors << 9, |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3048 | mddev->chunk_sectors << 9); |
| 3049 | return sprintf(page, "%d\n", mddev->chunk_sectors << 9); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | static ssize_t |
| 3053 | chunk_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 3054 | { |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3055 | char *e; |
| 3056 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3057 | |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3058 | if (!*buf || (*e && *e != '\n')) |
| 3059 | return -EINVAL; |
| 3060 | |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3061 | if (mddev->pers) { |
| 3062 | int err; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3063 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3064 | return -EBUSY; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3065 | mddev->new_chunk_sectors = n >> 9; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3066 | err = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3067 | if (err) { |
| 3068 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3069 | return err; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3070 | } |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3071 | } else { |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3072 | mddev->new_chunk_sectors = n >> 9; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3073 | if (mddev->reshape_position == MaxSector) |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3074 | mddev->chunk_sectors = n >> 9; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3075 | } |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3076 | return len; |
| 3077 | } |
| 3078 | static struct md_sysfs_entry md_chunk_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3079 | __ATTR(chunk_size, S_IRUGO|S_IWUSR, chunk_size_show, chunk_size_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3080 | |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3081 | static ssize_t |
| 3082 | resync_start_show(mddev_t *mddev, char *page) |
| 3083 | { |
NeilBrown | d1a7c50 | 2009-03-31 15:24:32 +1100 | [diff] [blame] | 3084 | if (mddev->recovery_cp == MaxSector) |
| 3085 | return sprintf(page, "none\n"); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3086 | return sprintf(page, "%llu\n", (unsigned long long)mddev->recovery_cp); |
| 3087 | } |
| 3088 | |
| 3089 | static ssize_t |
| 3090 | resync_start_store(mddev_t *mddev, const char *buf, size_t len) |
| 3091 | { |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3092 | char *e; |
| 3093 | unsigned long long n = simple_strtoull(buf, &e, 10); |
| 3094 | |
| 3095 | if (mddev->pers) |
| 3096 | return -EBUSY; |
| 3097 | if (!*buf || (*e && *e != '\n')) |
| 3098 | return -EINVAL; |
| 3099 | |
| 3100 | mddev->recovery_cp = n; |
| 3101 | return len; |
| 3102 | } |
| 3103 | static struct md_sysfs_entry md_resync_start = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3104 | __ATTR(resync_start, S_IRUGO|S_IWUSR, resync_start_show, resync_start_store); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3105 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3106 | /* |
| 3107 | * The array state can be: |
| 3108 | * |
| 3109 | * clear |
| 3110 | * No devices, no size, no level |
| 3111 | * Equivalent to STOP_ARRAY ioctl |
| 3112 | * inactive |
| 3113 | * May have some settings, but array is not active |
| 3114 | * all IO results in error |
| 3115 | * When written, doesn't tear down array, but just stops it |
| 3116 | * suspended (not supported yet) |
| 3117 | * All IO requests will block. The array can be reconfigured. |
Andre Noll | 910d8cb | 2008-03-25 21:00:53 +0100 | [diff] [blame] | 3118 | * Writing this, if accepted, will block until array is quiescent |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3119 | * readonly |
| 3120 | * no resync can happen. no superblocks get written. |
| 3121 | * write requests fail |
| 3122 | * read-auto |
| 3123 | * like readonly, but behaves like 'clean' on a write request. |
| 3124 | * |
| 3125 | * clean - no pending writes, but otherwise active. |
| 3126 | * When written to inactive array, starts without resync |
| 3127 | * If a write request arrives then |
| 3128 | * if metadata is known, mark 'dirty' and switch to 'active'. |
| 3129 | * if not known, block and switch to write-pending |
| 3130 | * If written to an active array that has pending writes, then fails. |
| 3131 | * active |
| 3132 | * fully active: IO and resync can be happening. |
| 3133 | * When written to inactive array, starts with resync |
| 3134 | * |
| 3135 | * write-pending |
| 3136 | * clean, but writes are blocked waiting for 'active' to be written. |
| 3137 | * |
| 3138 | * active-idle |
| 3139 | * like active, but no writes have been seen for a while (100msec). |
| 3140 | * |
| 3141 | */ |
| 3142 | enum array_state { clear, inactive, suspended, readonly, read_auto, clean, active, |
| 3143 | write_pending, active_idle, bad_word}; |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 3144 | static char *array_states[] = { |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3145 | "clear", "inactive", "suspended", "readonly", "read-auto", "clean", "active", |
| 3146 | "write-pending", "active-idle", NULL }; |
| 3147 | |
| 3148 | static int match_word(const char *word, char **list) |
| 3149 | { |
| 3150 | int n; |
| 3151 | for (n=0; list[n]; n++) |
| 3152 | if (cmd_match(word, list[n])) |
| 3153 | break; |
| 3154 | return n; |
| 3155 | } |
| 3156 | |
| 3157 | static ssize_t |
| 3158 | array_state_show(mddev_t *mddev, char *page) |
| 3159 | { |
| 3160 | enum array_state st = inactive; |
| 3161 | |
| 3162 | if (mddev->pers) |
| 3163 | switch(mddev->ro) { |
| 3164 | case 1: |
| 3165 | st = readonly; |
| 3166 | break; |
| 3167 | case 2: |
| 3168 | st = read_auto; |
| 3169 | break; |
| 3170 | case 0: |
| 3171 | if (mddev->in_sync) |
| 3172 | st = clean; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3173 | else if (test_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 3174 | st = write_pending; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3175 | else if (mddev->safemode) |
| 3176 | st = active_idle; |
| 3177 | else |
| 3178 | st = active; |
| 3179 | } |
| 3180 | else { |
| 3181 | if (list_empty(&mddev->disks) && |
| 3182 | mddev->raid_disks == 0 && |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3183 | mddev->dev_sectors == 0) |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3184 | st = clear; |
| 3185 | else |
| 3186 | st = inactive; |
| 3187 | } |
| 3188 | return sprintf(page, "%s\n", array_states[st]); |
| 3189 | } |
| 3190 | |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3191 | static int do_md_stop(mddev_t * mddev, int ro, int is_open); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3192 | static int do_md_run(mddev_t * mddev); |
| 3193 | static int restart_array(mddev_t *mddev); |
| 3194 | |
| 3195 | static ssize_t |
| 3196 | array_state_store(mddev_t *mddev, const char *buf, size_t len) |
| 3197 | { |
| 3198 | int err = -EINVAL; |
| 3199 | enum array_state st = match_word(buf, array_states); |
| 3200 | switch(st) { |
| 3201 | case bad_word: |
| 3202 | break; |
| 3203 | case clear: |
| 3204 | /* stopping an active array */ |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 3205 | if (atomic_read(&mddev->openers) > 0) |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3206 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3207 | err = do_md_stop(mddev, 0, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3208 | break; |
| 3209 | case inactive: |
| 3210 | /* stopping an active array */ |
| 3211 | if (mddev->pers) { |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 3212 | if (atomic_read(&mddev->openers) > 0) |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3213 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3214 | err = do_md_stop(mddev, 2, 0); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3215 | } else |
| 3216 | err = 0; /* already inactive */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3217 | break; |
| 3218 | case suspended: |
| 3219 | break; /* not supported yet */ |
| 3220 | case readonly: |
| 3221 | if (mddev->pers) |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3222 | err = do_md_stop(mddev, 1, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3223 | else { |
| 3224 | mddev->ro = 1; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3225 | set_disk_ro(mddev->gendisk, 1); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3226 | err = do_md_run(mddev); |
| 3227 | } |
| 3228 | break; |
| 3229 | case read_auto: |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3230 | if (mddev->pers) { |
NeilBrown | 80268ee | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 3231 | if (mddev->ro == 0) |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3232 | err = do_md_stop(mddev, 1, 0); |
NeilBrown | 80268ee | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 3233 | else if (mddev->ro == 1) |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3234 | err = restart_array(mddev); |
| 3235 | if (err == 0) { |
| 3236 | mddev->ro = 2; |
| 3237 | set_disk_ro(mddev->gendisk, 0); |
| 3238 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3239 | } else { |
| 3240 | mddev->ro = 2; |
| 3241 | err = do_md_run(mddev); |
| 3242 | } |
| 3243 | break; |
| 3244 | case clean: |
| 3245 | if (mddev->pers) { |
| 3246 | restart_array(mddev); |
| 3247 | spin_lock_irq(&mddev->write_lock); |
| 3248 | if (atomic_read(&mddev->writes_pending) == 0) { |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3249 | if (mddev->in_sync == 0) { |
| 3250 | mddev->in_sync = 1; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3251 | if (mddev->safemode == 1) |
| 3252 | mddev->safemode = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3253 | if (mddev->persistent) |
| 3254 | set_bit(MD_CHANGE_CLEAN, |
| 3255 | &mddev->flags); |
| 3256 | } |
| 3257 | err = 0; |
| 3258 | } else |
| 3259 | err = -EBUSY; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3260 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 5bf2959 | 2009-05-07 12:50:57 +1000 | [diff] [blame] | 3261 | } else |
| 3262 | err = -EINVAL; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3263 | break; |
| 3264 | case active: |
| 3265 | if (mddev->pers) { |
| 3266 | restart_array(mddev); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3267 | if (mddev->external) |
| 3268 | clear_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3269 | wake_up(&mddev->sb_wait); |
| 3270 | err = 0; |
| 3271 | } else { |
| 3272 | mddev->ro = 0; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3273 | set_disk_ro(mddev->gendisk, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3274 | err = do_md_run(mddev); |
| 3275 | } |
| 3276 | break; |
| 3277 | case write_pending: |
| 3278 | case active_idle: |
| 3279 | /* these cannot be set */ |
| 3280 | break; |
| 3281 | } |
| 3282 | if (err) |
| 3283 | return err; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3284 | else { |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 3285 | sysfs_notify_dirent(mddev->sysfs_state); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3286 | return len; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3287 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3288 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3289 | static struct md_sysfs_entry md_array_state = |
| 3290 | __ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3291 | |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3292 | static ssize_t |
| 3293 | null_show(mddev_t *mddev, char *page) |
| 3294 | { |
| 3295 | return -EINVAL; |
| 3296 | } |
| 3297 | |
| 3298 | static ssize_t |
| 3299 | new_dev_store(mddev_t *mddev, const char *buf, size_t len) |
| 3300 | { |
| 3301 | /* buf must be %d:%d\n? giving major and minor numbers */ |
| 3302 | /* The new device is added to the array. |
| 3303 | * If the array has a persistent superblock, we read the |
| 3304 | * superblock to initialise info and check validity. |
| 3305 | * Otherwise, only checking done is that in bind_rdev_to_array, |
| 3306 | * which mainly checks size. |
| 3307 | */ |
| 3308 | char *e; |
| 3309 | int major = simple_strtoul(buf, &e, 10); |
| 3310 | int minor; |
| 3311 | dev_t dev; |
| 3312 | mdk_rdev_t *rdev; |
| 3313 | int err; |
| 3314 | |
| 3315 | if (!*buf || *e != ':' || !e[1] || e[1] == '\n') |
| 3316 | return -EINVAL; |
| 3317 | minor = simple_strtoul(e+1, &e, 10); |
| 3318 | if (*e && *e != '\n') |
| 3319 | return -EINVAL; |
| 3320 | dev = MKDEV(major, minor); |
| 3321 | if (major != MAJOR(dev) || |
| 3322 | minor != MINOR(dev)) |
| 3323 | return -EOVERFLOW; |
| 3324 | |
| 3325 | |
| 3326 | if (mddev->persistent) { |
| 3327 | rdev = md_import_device(dev, mddev->major_version, |
| 3328 | mddev->minor_version); |
| 3329 | if (!IS_ERR(rdev) && !list_empty(&mddev->disks)) { |
| 3330 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 3331 | mdk_rdev_t, same_set); |
| 3332 | err = super_types[mddev->major_version] |
| 3333 | .load_super(rdev, rdev0, mddev->minor_version); |
| 3334 | if (err < 0) |
| 3335 | goto out; |
| 3336 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 3337 | } else if (mddev->external) |
| 3338 | rdev = md_import_device(dev, -2, -1); |
| 3339 | else |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3340 | rdev = md_import_device(dev, -1, -1); |
| 3341 | |
| 3342 | if (IS_ERR(rdev)) |
| 3343 | return PTR_ERR(rdev); |
| 3344 | err = bind_rdev_to_array(rdev, mddev); |
| 3345 | out: |
| 3346 | if (err) |
| 3347 | export_rdev(rdev); |
| 3348 | return err ? err : len; |
| 3349 | } |
| 3350 | |
| 3351 | static struct md_sysfs_entry md_new_device = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3352 | __ATTR(new_dev, S_IWUSR, null_show, new_dev_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3353 | |
| 3354 | static ssize_t |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 3355 | bitmap_store(mddev_t *mddev, const char *buf, size_t len) |
| 3356 | { |
| 3357 | char *end; |
| 3358 | unsigned long chunk, end_chunk; |
| 3359 | |
| 3360 | if (!mddev->bitmap) |
| 3361 | goto out; |
| 3362 | /* buf should be <chunk> <chunk> ... or <chunk>-<chunk> ... (range) */ |
| 3363 | while (*buf) { |
| 3364 | chunk = end_chunk = simple_strtoul(buf, &end, 0); |
| 3365 | if (buf == end) break; |
| 3366 | if (*end == '-') { /* range */ |
| 3367 | buf = end + 1; |
| 3368 | end_chunk = simple_strtoul(buf, &end, 0); |
| 3369 | if (buf == end) break; |
| 3370 | } |
| 3371 | if (*end && !isspace(*end)) break; |
| 3372 | bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk); |
| 3373 | buf = end; |
| 3374 | while (isspace(*buf)) buf++; |
| 3375 | } |
| 3376 | bitmap_unplug(mddev->bitmap); /* flush the bits to disk */ |
| 3377 | out: |
| 3378 | return len; |
| 3379 | } |
| 3380 | |
| 3381 | static struct md_sysfs_entry md_bitmap = |
| 3382 | __ATTR(bitmap_set_bits, S_IWUSR, null_show, bitmap_store); |
| 3383 | |
| 3384 | static ssize_t |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3385 | size_show(mddev_t *mddev, char *page) |
| 3386 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3387 | return sprintf(page, "%llu\n", |
| 3388 | (unsigned long long)mddev->dev_sectors / 2); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3389 | } |
| 3390 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3391 | static int update_size(mddev_t *mddev, sector_t num_sectors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3392 | |
| 3393 | static ssize_t |
| 3394 | size_store(mddev_t *mddev, const char *buf, size_t len) |
| 3395 | { |
| 3396 | /* If array is inactive, we can reduce the component size, but |
| 3397 | * not increase it (except from 0). |
| 3398 | * If array is active, we can try an on-line resize |
| 3399 | */ |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 3400 | sector_t sectors; |
| 3401 | int err = strict_blocks_to_sectors(buf, §ors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3402 | |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3403 | if (err < 0) |
| 3404 | return err; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3405 | if (mddev->pers) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3406 | err = update_size(mddev, sectors); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 3407 | md_update_sb(mddev, 1); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3408 | } else { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3409 | if (mddev->dev_sectors == 0 || |
| 3410 | mddev->dev_sectors > sectors) |
| 3411 | mddev->dev_sectors = sectors; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3412 | else |
| 3413 | err = -ENOSPC; |
| 3414 | } |
| 3415 | return err ? err : len; |
| 3416 | } |
| 3417 | |
| 3418 | static struct md_sysfs_entry md_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3419 | __ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3420 | |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3421 | |
| 3422 | /* Metdata version. |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3423 | * This is one of |
| 3424 | * 'none' for arrays with no metadata (good luck...) |
| 3425 | * 'external' for arrays with externally managed metadata, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3426 | * or N.M for internally known formats |
| 3427 | */ |
| 3428 | static ssize_t |
| 3429 | metadata_show(mddev_t *mddev, char *page) |
| 3430 | { |
| 3431 | if (mddev->persistent) |
| 3432 | return sprintf(page, "%d.%d\n", |
| 3433 | mddev->major_version, mddev->minor_version); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3434 | else if (mddev->external) |
| 3435 | return sprintf(page, "external:%s\n", mddev->metadata_type); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3436 | else |
| 3437 | return sprintf(page, "none\n"); |
| 3438 | } |
| 3439 | |
| 3440 | static ssize_t |
| 3441 | metadata_store(mddev_t *mddev, const char *buf, size_t len) |
| 3442 | { |
| 3443 | int major, minor; |
| 3444 | char *e; |
NeilBrown | ea43ddd | 2008-10-13 11:55:11 +1100 | [diff] [blame] | 3445 | /* Changing the details of 'external' metadata is |
| 3446 | * always permitted. Otherwise there must be |
| 3447 | * no devices attached to the array. |
| 3448 | */ |
| 3449 | if (mddev->external && strncmp(buf, "external:", 9) == 0) |
| 3450 | ; |
| 3451 | else if (!list_empty(&mddev->disks)) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3452 | return -EBUSY; |
| 3453 | |
| 3454 | if (cmd_match(buf, "none")) { |
| 3455 | mddev->persistent = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3456 | mddev->external = 0; |
| 3457 | mddev->major_version = 0; |
| 3458 | mddev->minor_version = 90; |
| 3459 | return len; |
| 3460 | } |
| 3461 | if (strncmp(buf, "external:", 9) == 0) { |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 3462 | size_t namelen = len-9; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3463 | if (namelen >= sizeof(mddev->metadata_type)) |
| 3464 | namelen = sizeof(mddev->metadata_type)-1; |
| 3465 | strncpy(mddev->metadata_type, buf+9, namelen); |
| 3466 | mddev->metadata_type[namelen] = 0; |
| 3467 | if (namelen && mddev->metadata_type[namelen-1] == '\n') |
| 3468 | mddev->metadata_type[--namelen] = 0; |
| 3469 | mddev->persistent = 0; |
| 3470 | mddev->external = 1; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3471 | mddev->major_version = 0; |
| 3472 | mddev->minor_version = 90; |
| 3473 | return len; |
| 3474 | } |
| 3475 | major = simple_strtoul(buf, &e, 10); |
| 3476 | if (e==buf || *e != '.') |
| 3477 | return -EINVAL; |
| 3478 | buf = e+1; |
| 3479 | minor = simple_strtoul(buf, &e, 10); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 3480 | if (e==buf || (*e && *e != '\n') ) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3481 | return -EINVAL; |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 3482 | if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3483 | return -ENOENT; |
| 3484 | mddev->major_version = major; |
| 3485 | mddev->minor_version = minor; |
| 3486 | mddev->persistent = 1; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3487 | mddev->external = 0; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3488 | return len; |
| 3489 | } |
| 3490 | |
| 3491 | static struct md_sysfs_entry md_metadata = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3492 | __ATTR(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3493 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3494 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3495 | action_show(mddev_t *mddev, char *page) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3496 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3497 | char *type = "idle"; |
NeilBrown | b6a9ce6 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 3498 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 3499 | type = "frozen"; |
| 3500 | else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
NeilBrown | 2b12ab6 | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 3501 | (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3502 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 3503 | type = "reshape"; |
| 3504 | else if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3505 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 3506 | type = "resync"; |
| 3507 | else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 3508 | type = "check"; |
| 3509 | else |
| 3510 | type = "repair"; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3511 | } else if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3512 | type = "recover"; |
| 3513 | } |
| 3514 | return sprintf(page, "%s\n", type); |
| 3515 | } |
| 3516 | |
| 3517 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3518 | action_store(mddev_t *mddev, const char *page, size_t len) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3519 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3520 | if (!mddev->pers || !mddev->pers->sync_request) |
| 3521 | return -EINVAL; |
| 3522 | |
NeilBrown | b6a9ce6 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 3523 | if (cmd_match(page, "frozen")) |
| 3524 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3525 | else |
| 3526 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3527 | |
| 3528 | if (cmd_match(page, "idle") || cmd_match(page, "frozen")) { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3529 | if (mddev->sync_thread) { |
| 3530 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 3531 | md_unregister_thread(mddev->sync_thread); |
| 3532 | mddev->sync_thread = NULL; |
| 3533 | mddev->recovery = 0; |
| 3534 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3535 | } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 3536 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3537 | return -EBUSY; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3538 | else if (cmd_match(page, "resync")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3539 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3540 | else if (cmd_match(page, "recover")) { |
| 3541 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
| 3542 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3543 | } else if (cmd_match(page, "reshape")) { |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3544 | int err; |
| 3545 | if (mddev->pers->start_reshape == NULL) |
| 3546 | return -EINVAL; |
| 3547 | err = mddev->pers->start_reshape(mddev); |
| 3548 | if (err) |
| 3549 | return err; |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 3550 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3551 | } else { |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 3552 | if (cmd_match(page, "check")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3553 | set_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
NeilBrown | 2adc7d4 | 2006-05-20 14:59:57 -0700 | [diff] [blame] | 3554 | else if (!cmd_match(page, "repair")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3555 | return -EINVAL; |
| 3556 | set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
| 3557 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3558 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3559 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3560 | md_wakeup_thread(mddev->thread); |
NeilBrown | 0c3573f | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 3561 | sysfs_notify_dirent(mddev->sysfs_action); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3562 | return len; |
| 3563 | } |
| 3564 | |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3565 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3566 | mismatch_cnt_show(mddev_t *mddev, char *page) |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3567 | { |
| 3568 | return sprintf(page, "%llu\n", |
| 3569 | (unsigned long long) mddev->resync_mismatches); |
| 3570 | } |
| 3571 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3572 | static struct md_sysfs_entry md_scan_mode = |
| 3573 | __ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3574 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3575 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3576 | static struct md_sysfs_entry md_mismatches = __ATTR_RO(mismatch_cnt); |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3577 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3578 | static ssize_t |
| 3579 | sync_min_show(mddev_t *mddev, char *page) |
| 3580 | { |
| 3581 | return sprintf(page, "%d (%s)\n", speed_min(mddev), |
| 3582 | mddev->sync_speed_min ? "local": "system"); |
| 3583 | } |
| 3584 | |
| 3585 | static ssize_t |
| 3586 | sync_min_store(mddev_t *mddev, const char *buf, size_t len) |
| 3587 | { |
| 3588 | int min; |
| 3589 | char *e; |
| 3590 | if (strncmp(buf, "system", 6)==0) { |
| 3591 | mddev->sync_speed_min = 0; |
| 3592 | return len; |
| 3593 | } |
| 3594 | min = simple_strtoul(buf, &e, 10); |
| 3595 | if (buf == e || (*e && *e != '\n') || min <= 0) |
| 3596 | return -EINVAL; |
| 3597 | mddev->sync_speed_min = min; |
| 3598 | return len; |
| 3599 | } |
| 3600 | |
| 3601 | static struct md_sysfs_entry md_sync_min = |
| 3602 | __ATTR(sync_speed_min, S_IRUGO|S_IWUSR, sync_min_show, sync_min_store); |
| 3603 | |
| 3604 | static ssize_t |
| 3605 | sync_max_show(mddev_t *mddev, char *page) |
| 3606 | { |
| 3607 | return sprintf(page, "%d (%s)\n", speed_max(mddev), |
| 3608 | mddev->sync_speed_max ? "local": "system"); |
| 3609 | } |
| 3610 | |
| 3611 | static ssize_t |
| 3612 | sync_max_store(mddev_t *mddev, const char *buf, size_t len) |
| 3613 | { |
| 3614 | int max; |
| 3615 | char *e; |
| 3616 | if (strncmp(buf, "system", 6)==0) { |
| 3617 | mddev->sync_speed_max = 0; |
| 3618 | return len; |
| 3619 | } |
| 3620 | max = simple_strtoul(buf, &e, 10); |
| 3621 | if (buf == e || (*e && *e != '\n') || max <= 0) |
| 3622 | return -EINVAL; |
| 3623 | mddev->sync_speed_max = max; |
| 3624 | return len; |
| 3625 | } |
| 3626 | |
| 3627 | static struct md_sysfs_entry md_sync_max = |
| 3628 | __ATTR(sync_speed_max, S_IRUGO|S_IWUSR, sync_max_show, sync_max_store); |
| 3629 | |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 3630 | static ssize_t |
| 3631 | degraded_show(mddev_t *mddev, char *page) |
| 3632 | { |
| 3633 | return sprintf(page, "%d\n", mddev->degraded); |
| 3634 | } |
| 3635 | static struct md_sysfs_entry md_degraded = __ATTR_RO(degraded); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3636 | |
| 3637 | static ssize_t |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 3638 | sync_force_parallel_show(mddev_t *mddev, char *page) |
| 3639 | { |
| 3640 | return sprintf(page, "%d\n", mddev->parallel_resync); |
| 3641 | } |
| 3642 | |
| 3643 | static ssize_t |
| 3644 | sync_force_parallel_store(mddev_t *mddev, const char *buf, size_t len) |
| 3645 | { |
| 3646 | long n; |
| 3647 | |
| 3648 | if (strict_strtol(buf, 10, &n)) |
| 3649 | return -EINVAL; |
| 3650 | |
| 3651 | if (n != 0 && n != 1) |
| 3652 | return -EINVAL; |
| 3653 | |
| 3654 | mddev->parallel_resync = n; |
| 3655 | |
| 3656 | if (mddev->sync_thread) |
| 3657 | wake_up(&resync_wait); |
| 3658 | |
| 3659 | return len; |
| 3660 | } |
| 3661 | |
| 3662 | /* force parallel resync, even with shared block devices */ |
| 3663 | static struct md_sysfs_entry md_sync_force_parallel = |
| 3664 | __ATTR(sync_force_parallel, S_IRUGO|S_IWUSR, |
| 3665 | sync_force_parallel_show, sync_force_parallel_store); |
| 3666 | |
| 3667 | static ssize_t |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3668 | sync_speed_show(mddev_t *mddev, char *page) |
| 3669 | { |
| 3670 | unsigned long resync, dt, db; |
NeilBrown | d1a7c50 | 2009-03-31 15:24:32 +1100 | [diff] [blame] | 3671 | if (mddev->curr_resync == 0) |
| 3672 | return sprintf(page, "none\n"); |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3673 | resync = mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active); |
| 3674 | dt = (jiffies - mddev->resync_mark) / HZ; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3675 | if (!dt) dt++; |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3676 | db = resync - mddev->resync_mark_cnt; |
| 3677 | return sprintf(page, "%lu\n", db/dt/2); /* K/sec */ |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3678 | } |
| 3679 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3680 | static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3681 | |
| 3682 | static ssize_t |
| 3683 | sync_completed_show(mddev_t *mddev, char *page) |
| 3684 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3685 | unsigned long max_sectors, resync; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3686 | |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 3687 | if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3688 | return sprintf(page, "none\n"); |
| 3689 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3690 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3691 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3692 | else |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3693 | max_sectors = mddev->dev_sectors; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3694 | |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 3695 | resync = mddev->curr_resync_completed; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3696 | return sprintf(page, "%lu / %lu\n", resync, max_sectors); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3697 | } |
| 3698 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3699 | static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3700 | |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3701 | static ssize_t |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3702 | min_sync_show(mddev_t *mddev, char *page) |
| 3703 | { |
| 3704 | return sprintf(page, "%llu\n", |
| 3705 | (unsigned long long)mddev->resync_min); |
| 3706 | } |
| 3707 | static ssize_t |
| 3708 | min_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3709 | { |
| 3710 | unsigned long long min; |
| 3711 | if (strict_strtoull(buf, 10, &min)) |
| 3712 | return -EINVAL; |
| 3713 | if (min > mddev->resync_max) |
| 3714 | return -EINVAL; |
| 3715 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3716 | return -EBUSY; |
| 3717 | |
| 3718 | /* Must be a multiple of chunk_size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3719 | if (mddev->chunk_sectors) { |
raz ben yehuda | 2ac06c3 | 2009-06-16 17:01:42 +1000 | [diff] [blame] | 3720 | sector_t temp = min; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3721 | if (sector_div(temp, mddev->chunk_sectors)) |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3722 | return -EINVAL; |
| 3723 | } |
| 3724 | mddev->resync_min = min; |
| 3725 | |
| 3726 | return len; |
| 3727 | } |
| 3728 | |
| 3729 | static struct md_sysfs_entry md_min_sync = |
| 3730 | __ATTR(sync_min, S_IRUGO|S_IWUSR, min_sync_show, min_sync_store); |
| 3731 | |
| 3732 | static ssize_t |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3733 | max_sync_show(mddev_t *mddev, char *page) |
| 3734 | { |
| 3735 | if (mddev->resync_max == MaxSector) |
| 3736 | return sprintf(page, "max\n"); |
| 3737 | else |
| 3738 | return sprintf(page, "%llu\n", |
| 3739 | (unsigned long long)mddev->resync_max); |
| 3740 | } |
| 3741 | static ssize_t |
| 3742 | max_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3743 | { |
| 3744 | if (strncmp(buf, "max", 3) == 0) |
| 3745 | mddev->resync_max = MaxSector; |
| 3746 | else { |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3747 | unsigned long long max; |
| 3748 | if (strict_strtoull(buf, 10, &max)) |
| 3749 | return -EINVAL; |
| 3750 | if (max < mddev->resync_min) |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3751 | return -EINVAL; |
| 3752 | if (max < mddev->resync_max && |
NeilBrown | 4d484a4 | 2009-08-13 10:41:50 +1000 | [diff] [blame] | 3753 | mddev->ro == 0 && |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3754 | test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3755 | return -EBUSY; |
| 3756 | |
| 3757 | /* Must be a multiple of chunk_size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3758 | if (mddev->chunk_sectors) { |
raz ben yehuda | 2ac06c3 | 2009-06-16 17:01:42 +1000 | [diff] [blame] | 3759 | sector_t temp = max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3760 | if (sector_div(temp, mddev->chunk_sectors)) |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3761 | return -EINVAL; |
| 3762 | } |
| 3763 | mddev->resync_max = max; |
| 3764 | } |
| 3765 | wake_up(&mddev->recovery_wait); |
| 3766 | return len; |
| 3767 | } |
| 3768 | |
| 3769 | static struct md_sysfs_entry md_max_sync = |
| 3770 | __ATTR(sync_max, S_IRUGO|S_IWUSR, max_sync_show, max_sync_store); |
| 3771 | |
| 3772 | static ssize_t |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3773 | suspend_lo_show(mddev_t *mddev, char *page) |
| 3774 | { |
| 3775 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_lo); |
| 3776 | } |
| 3777 | |
| 3778 | static ssize_t |
| 3779 | suspend_lo_store(mddev_t *mddev, const char *buf, size_t len) |
| 3780 | { |
| 3781 | char *e; |
| 3782 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 3783 | |
NeilBrown | b8d966e | 2009-07-01 11:14:04 +1000 | [diff] [blame] | 3784 | if (mddev->pers == NULL || |
| 3785 | mddev->pers->quiesce == NULL) |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3786 | return -EINVAL; |
| 3787 | if (buf == e || (*e && *e != '\n')) |
| 3788 | return -EINVAL; |
| 3789 | if (new >= mddev->suspend_hi || |
| 3790 | (new > mddev->suspend_lo && new < mddev->suspend_hi)) { |
| 3791 | mddev->suspend_lo = new; |
| 3792 | mddev->pers->quiesce(mddev, 2); |
| 3793 | return len; |
| 3794 | } else |
| 3795 | return -EINVAL; |
| 3796 | } |
| 3797 | static struct md_sysfs_entry md_suspend_lo = |
| 3798 | __ATTR(suspend_lo, S_IRUGO|S_IWUSR, suspend_lo_show, suspend_lo_store); |
| 3799 | |
| 3800 | |
| 3801 | static ssize_t |
| 3802 | suspend_hi_show(mddev_t *mddev, char *page) |
| 3803 | { |
| 3804 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_hi); |
| 3805 | } |
| 3806 | |
| 3807 | static ssize_t |
| 3808 | suspend_hi_store(mddev_t *mddev, const char *buf, size_t len) |
| 3809 | { |
| 3810 | char *e; |
| 3811 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 3812 | |
NeilBrown | b8d966e | 2009-07-01 11:14:04 +1000 | [diff] [blame] | 3813 | if (mddev->pers == NULL || |
| 3814 | mddev->pers->quiesce == NULL) |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3815 | return -EINVAL; |
| 3816 | if (buf == e || (*e && *e != '\n')) |
| 3817 | return -EINVAL; |
| 3818 | if ((new <= mddev->suspend_lo && mddev->suspend_lo >= mddev->suspend_hi) || |
| 3819 | (new > mddev->suspend_lo && new > mddev->suspend_hi)) { |
| 3820 | mddev->suspend_hi = new; |
| 3821 | mddev->pers->quiesce(mddev, 1); |
| 3822 | mddev->pers->quiesce(mddev, 0); |
| 3823 | return len; |
| 3824 | } else |
| 3825 | return -EINVAL; |
| 3826 | } |
| 3827 | static struct md_sysfs_entry md_suspend_hi = |
| 3828 | __ATTR(suspend_hi, S_IRUGO|S_IWUSR, suspend_hi_show, suspend_hi_store); |
| 3829 | |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3830 | static ssize_t |
| 3831 | reshape_position_show(mddev_t *mddev, char *page) |
| 3832 | { |
| 3833 | if (mddev->reshape_position != MaxSector) |
| 3834 | return sprintf(page, "%llu\n", |
| 3835 | (unsigned long long)mddev->reshape_position); |
| 3836 | strcpy(page, "none\n"); |
| 3837 | return 5; |
| 3838 | } |
| 3839 | |
| 3840 | static ssize_t |
| 3841 | reshape_position_store(mddev_t *mddev, const char *buf, size_t len) |
| 3842 | { |
| 3843 | char *e; |
| 3844 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 3845 | if (mddev->pers) |
| 3846 | return -EBUSY; |
| 3847 | if (buf == e || (*e && *e != '\n')) |
| 3848 | return -EINVAL; |
| 3849 | mddev->reshape_position = new; |
| 3850 | mddev->delta_disks = 0; |
| 3851 | mddev->new_level = mddev->level; |
| 3852 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3853 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3854 | return len; |
| 3855 | } |
| 3856 | |
| 3857 | static struct md_sysfs_entry md_reshape_position = |
| 3858 | __ATTR(reshape_position, S_IRUGO|S_IWUSR, reshape_position_show, |
| 3859 | reshape_position_store); |
| 3860 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 3861 | static ssize_t |
| 3862 | array_size_show(mddev_t *mddev, char *page) |
| 3863 | { |
| 3864 | if (mddev->external_size) |
| 3865 | return sprintf(page, "%llu\n", |
| 3866 | (unsigned long long)mddev->array_sectors/2); |
| 3867 | else |
| 3868 | return sprintf(page, "default\n"); |
| 3869 | } |
| 3870 | |
| 3871 | static ssize_t |
| 3872 | array_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 3873 | { |
| 3874 | sector_t sectors; |
| 3875 | |
| 3876 | if (strncmp(buf, "default", 7) == 0) { |
| 3877 | if (mddev->pers) |
| 3878 | sectors = mddev->pers->size(mddev, 0, 0); |
| 3879 | else |
| 3880 | sectors = mddev->array_sectors; |
| 3881 | |
| 3882 | mddev->external_size = 0; |
| 3883 | } else { |
| 3884 | if (strict_blocks_to_sectors(buf, §ors) < 0) |
| 3885 | return -EINVAL; |
| 3886 | if (mddev->pers && mddev->pers->size(mddev, 0, 0) < sectors) |
NeilBrown | 2b69c83 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 3887 | return -E2BIG; |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 3888 | |
| 3889 | mddev->external_size = 1; |
| 3890 | } |
| 3891 | |
| 3892 | mddev->array_sectors = sectors; |
| 3893 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 3894 | if (mddev->pers) |
| 3895 | revalidate_disk(mddev->gendisk); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 3896 | |
| 3897 | return len; |
| 3898 | } |
| 3899 | |
| 3900 | static struct md_sysfs_entry md_array_size = |
| 3901 | __ATTR(array_size, S_IRUGO|S_IWUSR, array_size_show, |
| 3902 | array_size_store); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3903 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3904 | static struct attribute *md_default_attrs[] = { |
| 3905 | &md_level.attr, |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3906 | &md_layout.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3907 | &md_raid_disks.attr, |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3908 | &md_chunk_size.attr, |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3909 | &md_size.attr, |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3910 | &md_resync_start.attr, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3911 | &md_metadata.attr, |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3912 | &md_new_device.attr, |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 3913 | &md_safe_delay.attr, |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3914 | &md_array_state.attr, |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3915 | &md_reshape_position.attr, |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 3916 | &md_array_size.attr, |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 3917 | NULL, |
| 3918 | }; |
| 3919 | |
| 3920 | static struct attribute *md_redundancy_attrs[] = { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3921 | &md_scan_mode.attr, |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3922 | &md_mismatches.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3923 | &md_sync_min.attr, |
| 3924 | &md_sync_max.attr, |
| 3925 | &md_sync_speed.attr, |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 3926 | &md_sync_force_parallel.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3927 | &md_sync_completed.attr, |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3928 | &md_min_sync.attr, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3929 | &md_max_sync.attr, |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3930 | &md_suspend_lo.attr, |
| 3931 | &md_suspend_hi.attr, |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 3932 | &md_bitmap.attr, |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 3933 | &md_degraded.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3934 | NULL, |
| 3935 | }; |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 3936 | static struct attribute_group md_redundancy_group = { |
| 3937 | .name = NULL, |
| 3938 | .attrs = md_redundancy_attrs, |
| 3939 | }; |
| 3940 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3941 | |
| 3942 | static ssize_t |
| 3943 | md_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 3944 | { |
| 3945 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 3946 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3947 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3948 | |
| 3949 | if (!entry->show) |
| 3950 | return -EIO; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 3951 | rv = mddev_lock(mddev); |
| 3952 | if (!rv) { |
| 3953 | rv = entry->show(mddev, page); |
| 3954 | mddev_unlock(mddev); |
| 3955 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3956 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | static ssize_t |
| 3960 | md_attr_store(struct kobject *kobj, struct attribute *attr, |
| 3961 | const char *page, size_t length) |
| 3962 | { |
| 3963 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 3964 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3965 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3966 | |
| 3967 | if (!entry->store) |
| 3968 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 3969 | if (!capable(CAP_SYS_ADMIN)) |
| 3970 | return -EACCES; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 3971 | rv = mddev_lock(mddev); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 3972 | if (mddev->hold_active == UNTIL_IOCTL) |
| 3973 | mddev->hold_active = 0; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 3974 | if (!rv) { |
| 3975 | rv = entry->store(mddev, page, length); |
| 3976 | mddev_unlock(mddev); |
| 3977 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3978 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | static void md_free(struct kobject *ko) |
| 3982 | { |
| 3983 | mddev_t *mddev = container_of(ko, mddev_t, kobj); |
NeilBrown | a21d150 | 2009-01-09 08:31:09 +1100 | [diff] [blame] | 3984 | |
| 3985 | if (mddev->sysfs_state) |
| 3986 | sysfs_put(mddev->sysfs_state); |
| 3987 | |
| 3988 | if (mddev->gendisk) { |
| 3989 | del_gendisk(mddev->gendisk); |
| 3990 | put_disk(mddev->gendisk); |
| 3991 | } |
| 3992 | if (mddev->queue) |
| 3993 | blk_cleanup_queue(mddev->queue); |
| 3994 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3995 | kfree(mddev); |
| 3996 | } |
| 3997 | |
| 3998 | static struct sysfs_ops md_sysfs_ops = { |
| 3999 | .show = md_attr_show, |
| 4000 | .store = md_attr_store, |
| 4001 | }; |
| 4002 | static struct kobj_type md_ktype = { |
| 4003 | .release = md_free, |
| 4004 | .sysfs_ops = &md_sysfs_ops, |
| 4005 | .default_attrs = md_default_attrs, |
| 4006 | }; |
| 4007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | int mdp_major = 0; |
| 4009 | |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 4010 | static void mddev_delayed_delete(struct work_struct *ws) |
| 4011 | { |
| 4012 | mddev_t *mddev = container_of(ws, mddev_t, del_work); |
| 4013 | |
| 4014 | if (mddev->private == &md_redundancy_group) { |
| 4015 | sysfs_remove_group(&mddev->kobj, &md_redundancy_group); |
| 4016 | if (mddev->sysfs_action) |
| 4017 | sysfs_put(mddev->sysfs_action); |
| 4018 | mddev->sysfs_action = NULL; |
| 4019 | mddev->private = NULL; |
| 4020 | } |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame^] | 4021 | sysfs_remove_group(&mddev->kobj, &md_bitmap_group); |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 4022 | kobject_del(&mddev->kobj); |
| 4023 | kobject_put(&mddev->kobj); |
| 4024 | } |
| 4025 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4026 | static int md_alloc(dev_t dev, char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 4028 | static DEFINE_MUTEX(disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | mddev_t *mddev = mddev_find(dev); |
| 4030 | struct gendisk *disk; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4031 | int partitioned; |
| 4032 | int shift; |
| 4033 | int unit; |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 4034 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | |
| 4036 | if (!mddev) |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4037 | return -ENODEV; |
| 4038 | |
| 4039 | partitioned = (MAJOR(mddev->unit) != MD_MAJOR); |
| 4040 | shift = partitioned ? MdpMinorShift : 0; |
| 4041 | unit = MINOR(mddev->unit) >> shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4043 | /* wait for any previous instance if this device |
| 4044 | * to be completed removed (mddev_delayed_delete). |
| 4045 | */ |
| 4046 | flush_scheduled_work(); |
| 4047 | |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 4048 | mutex_lock(&disks_mutex); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4049 | error = -EEXIST; |
| 4050 | if (mddev->gendisk) |
| 4051 | goto abort; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4052 | |
| 4053 | if (name) { |
| 4054 | /* Need to ensure that 'name' is not a duplicate. |
| 4055 | */ |
| 4056 | mddev_t *mddev2; |
| 4057 | spin_lock(&all_mddevs_lock); |
| 4058 | |
| 4059 | list_for_each_entry(mddev2, &all_mddevs, all_mddevs) |
| 4060 | if (mddev2->gendisk && |
| 4061 | strcmp(mddev2->gendisk->disk_name, name) == 0) { |
| 4062 | spin_unlock(&all_mddevs_lock); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4063 | goto abort; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4064 | } |
| 4065 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | } |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4067 | |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4068 | error = -ENOMEM; |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4069 | mddev->queue = blk_alloc_queue(GFP_KERNEL); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4070 | if (!mddev->queue) |
| 4071 | goto abort; |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4072 | mddev->queue->queuedata = mddev; |
| 4073 | |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4074 | /* Can be unlocked because the queue is new: no concurrency */ |
| 4075 | queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, mddev->queue); |
| 4076 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4077 | blk_queue_make_request(mddev->queue, md_make_request); |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | disk = alloc_disk(1 << shift); |
| 4080 | if (!disk) { |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4081 | blk_cleanup_queue(mddev->queue); |
| 4082 | mddev->queue = NULL; |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4083 | goto abort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | } |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4085 | disk->major = MAJOR(mddev->unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | disk->first_minor = unit << shift; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4087 | if (name) |
| 4088 | strcpy(disk->disk_name, name); |
| 4089 | else if (partitioned) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | sprintf(disk->disk_name, "md_d%d", unit); |
Greg Kroah-Hartman | ce7b0f4 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 4091 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | sprintf(disk->disk_name, "md%d", unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | disk->fops = &md_fops; |
| 4094 | disk->private_data = mddev; |
| 4095 | disk->queue = mddev->queue; |
NeilBrown | 92850bb | 2008-10-21 13:25:32 +1100 | [diff] [blame] | 4096 | /* Allow extended partitions. This makes the |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4097 | * 'mdp' device redundant, but we can't really |
NeilBrown | 92850bb | 2008-10-21 13:25:32 +1100 | [diff] [blame] | 4098 | * remove it now. |
| 4099 | */ |
| 4100 | disk->flags |= GENHD_FL_EXT_DEVT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | add_disk(disk); |
| 4102 | mddev->gendisk = disk; |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 4103 | error = kobject_init_and_add(&mddev->kobj, &md_ktype, |
| 4104 | &disk_to_dev(disk)->kobj, "%s", "md"); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4105 | if (error) { |
| 4106 | /* This isn't possible, but as kobject_init_and_add is marked |
| 4107 | * __must_check, we must do something with the result |
| 4108 | */ |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4109 | printk(KERN_WARNING "md: cannot register %s/md - name in use\n", |
| 4110 | disk->disk_name); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4111 | error = 0; |
| 4112 | } |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame^] | 4113 | if (sysfs_create_group(&mddev->kobj, &md_bitmap_group)) |
| 4114 | printk(KERN_DEBUG "pointless warning\n"); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4115 | abort: |
| 4116 | mutex_unlock(&disks_mutex); |
| 4117 | if (!error) { |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 4118 | kobject_uevent(&mddev->kobj, KOBJ_ADD); |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 4119 | mddev->sysfs_state = sysfs_get_dirent(mddev->kobj.sd, "array_state"); |
| 4120 | } |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4121 | mddev_put(mddev); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4122 | return error; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | static struct kobject *md_probe(dev_t dev, int *part, void *data) |
| 4126 | { |
| 4127 | md_alloc(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | return NULL; |
| 4129 | } |
| 4130 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4131 | static int add_named_array(const char *val, struct kernel_param *kp) |
| 4132 | { |
| 4133 | /* val must be "md_*" where * is not all digits. |
| 4134 | * We allocate an array with a large free minor number, and |
| 4135 | * set the name to val. val must not already be an active name. |
| 4136 | */ |
| 4137 | int len = strlen(val); |
| 4138 | char buf[DISK_NAME_LEN]; |
| 4139 | |
| 4140 | while (len && val[len-1] == '\n') |
| 4141 | len--; |
| 4142 | if (len >= DISK_NAME_LEN) |
| 4143 | return -E2BIG; |
| 4144 | strlcpy(buf, val, len+1); |
| 4145 | if (strncmp(buf, "md_", 3) != 0) |
| 4146 | return -EINVAL; |
| 4147 | return md_alloc(0, buf); |
| 4148 | } |
| 4149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | static void md_safemode_timeout(unsigned long data) |
| 4151 | { |
| 4152 | mddev_t *mddev = (mddev_t *) data; |
| 4153 | |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 4154 | if (!atomic_read(&mddev->writes_pending)) { |
| 4155 | mddev->safemode = 1; |
| 4156 | if (mddev->external) |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 4157 | sysfs_notify_dirent(mddev->sysfs_state); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 4158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | md_wakeup_thread(mddev->thread); |
| 4160 | } |
| 4161 | |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4162 | static int start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | |
| 4164 | static int do_md_run(mddev_t * mddev) |
| 4165 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4166 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | mdk_rdev_t *rdev; |
| 4168 | struct gendisk *disk; |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4169 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4171 | if (list_empty(&mddev->disks)) |
| 4172 | /* cannot run an array with no devices.. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | |
| 4175 | if (mddev->pers) |
| 4176 | return -EBUSY; |
| 4177 | |
| 4178 | /* |
| 4179 | * Analyze all RAID superblock(s) |
| 4180 | */ |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4181 | if (!mddev->raid_disks) { |
| 4182 | if (!mddev->persistent) |
| 4183 | return -EINVAL; |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4184 | analyze_sbs(mddev); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4187 | if (mddev->level != LEVEL_NONE) |
| 4188 | request_module("md-level-%d", mddev->level); |
| 4189 | else if (mddev->clevel[0]) |
| 4190 | request_module("md-%s", mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | |
| 4192 | /* |
| 4193 | * Drop all container device buffers, from now on |
| 4194 | * the only valid external interface is through the md |
| 4195 | * device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4197 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4198 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4199 | continue; |
| 4200 | sync_blockdev(rdev->bdev); |
Peter Zijlstra | f98393a | 2007-05-06 14:49:54 -0700 | [diff] [blame] | 4201 | invalidate_bdev(rdev->bdev); |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4202 | |
| 4203 | /* perform some consistency tests on the device. |
| 4204 | * We don't want the data to overlap the metadata, |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4205 | * Internal Bitmap issues have been handled elsewhere. |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4206 | */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4207 | if (rdev->data_offset < rdev->sb_start) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4208 | if (mddev->dev_sectors && |
| 4209 | rdev->data_offset + mddev->dev_sectors |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4210 | > rdev->sb_start) { |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4211 | printk("md: %s: data overlaps metadata\n", |
| 4212 | mdname(mddev)); |
| 4213 | return -EINVAL; |
| 4214 | } |
| 4215 | } else { |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4216 | if (rdev->sb_start + rdev->sb_size/512 |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4217 | > rdev->data_offset) { |
| 4218 | printk("md: %s: metadata overlaps data\n", |
| 4219 | mdname(mddev)); |
| 4220 | return -EINVAL; |
| 4221 | } |
| 4222 | } |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 4223 | sysfs_notify_dirent(rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | } |
| 4225 | |
| 4226 | md_probe(mddev->unit, NULL, NULL); |
| 4227 | disk = mddev->gendisk; |
| 4228 | if (!disk) |
| 4229 | return -ENOMEM; |
| 4230 | |
| 4231 | spin_lock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4232 | pers = find_pers(mddev->level, mddev->clevel); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4233 | if (!pers || !try_module_get(pers->owner)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | spin_unlock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4235 | if (mddev->level != LEVEL_NONE) |
| 4236 | printk(KERN_WARNING "md: personality for level %d is not loaded!\n", |
| 4237 | mddev->level); |
| 4238 | else |
| 4239 | printk(KERN_WARNING "md: personality for level %s is not loaded!\n", |
| 4240 | mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | return -EINVAL; |
| 4242 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4243 | mddev->pers = pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | spin_unlock(&pers_lock); |
NeilBrown | 34817e8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4245 | if (mddev->level != pers->level) { |
| 4246 | mddev->level = pers->level; |
| 4247 | mddev->new_level = pers->level; |
| 4248 | } |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4249 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4251 | if (mddev->reshape_position != MaxSector && |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4252 | pers->start_reshape == NULL) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4253 | /* This personality cannot handle reshaping... */ |
| 4254 | mddev->pers = NULL; |
| 4255 | module_put(pers->owner); |
| 4256 | return -EINVAL; |
| 4257 | } |
| 4258 | |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4259 | if (pers->sync_request) { |
| 4260 | /* Warn if this is a potentially silly |
| 4261 | * configuration. |
| 4262 | */ |
| 4263 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 4264 | mdk_rdev_t *rdev2; |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4265 | int warned = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4266 | |
| 4267 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 4268 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4269 | if (rdev < rdev2 && |
| 4270 | rdev->bdev->bd_contains == |
| 4271 | rdev2->bdev->bd_contains) { |
| 4272 | printk(KERN_WARNING |
| 4273 | "%s: WARNING: %s appears to be" |
| 4274 | " on the same physical disk as" |
| 4275 | " %s.\n", |
| 4276 | mdname(mddev), |
| 4277 | bdevname(rdev->bdev,b), |
| 4278 | bdevname(rdev2->bdev,b2)); |
| 4279 | warned = 1; |
| 4280 | } |
| 4281 | } |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4282 | |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4283 | if (warned) |
| 4284 | printk(KERN_WARNING |
| 4285 | "True protection against single-disk" |
| 4286 | " failure might be compromised.\n"); |
| 4287 | } |
| 4288 | |
NeilBrown | 657390d | 2005-08-26 18:34:16 -0700 | [diff] [blame] | 4289 | mddev->recovery = 0; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4290 | /* may be over-ridden by personality */ |
| 4291 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 4292 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 4293 | mddev->barriers_work = 1; |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4294 | mddev->ok_start_degraded = start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4296 | if (start_readonly) |
| 4297 | mddev->ro = 2; /* read-only, but switch on first write */ |
| 4298 | |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 4299 | err = mddev->pers->run(mddev); |
Andre Noll | 13e53df | 2008-03-26 00:07:03 +0100 | [diff] [blame] | 4300 | if (err) |
| 4301 | printk(KERN_ERR "md: pers->run() failed ...\n"); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4302 | else if (mddev->pers->size(mddev, 0, 0) < mddev->array_sectors) { |
| 4303 | WARN_ONCE(!mddev->external_size, "%s: default size too small," |
| 4304 | " but 'external_size' not in effect?\n", __func__); |
| 4305 | printk(KERN_ERR |
| 4306 | "md: invalid array_size %llu > default size %llu\n", |
| 4307 | (unsigned long long)mddev->array_sectors / 2, |
| 4308 | (unsigned long long)mddev->pers->size(mddev, 0, 0) / 2); |
| 4309 | err = -EINVAL; |
| 4310 | mddev->pers->stop(mddev); |
| 4311 | } |
| 4312 | if (err == 0 && mddev->pers->sync_request) { |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 4313 | err = bitmap_create(mddev); |
| 4314 | if (err) { |
| 4315 | printk(KERN_ERR "%s: failed to create bitmap (%d)\n", |
| 4316 | mdname(mddev), err); |
| 4317 | mddev->pers->stop(mddev); |
| 4318 | } |
| 4319 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | module_put(mddev->pers->owner); |
| 4322 | mddev->pers = NULL; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4323 | bitmap_destroy(mddev); |
| 4324 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | } |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4326 | if (mddev->pers->sync_request) { |
| 4327 | if (sysfs_create_group(&mddev->kobj, &md_redundancy_group)) |
| 4328 | printk(KERN_WARNING |
| 4329 | "md: cannot register extra attributes for %s\n", |
| 4330 | mdname(mddev)); |
NeilBrown | 0c3573f | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 4331 | mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, "sync_action"); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4332 | } else if (mddev->ro == 2) /* auto-readonly not meaningful */ |
NeilBrown | fd9d49c | 2005-11-08 21:39:42 -0800 | [diff] [blame] | 4333 | mddev->ro = 0; |
| 4334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | atomic_set(&mddev->writes_pending,0); |
| 4336 | mddev->safemode = 0; |
| 4337 | mddev->safemode_timer.function = md_safemode_timeout; |
| 4338 | mddev->safemode_timer.data = (unsigned long) mddev; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 4339 | mddev->safemode_delay = (200 * HZ)/1000 +1; /* 200 msec delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | mddev->in_sync = 1; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4341 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4342 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4343 | if (rdev->raid_disk >= 0) { |
| 4344 | char nm[20]; |
| 4345 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4346 | if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) |
| 4347 | printk("md: cannot register %s for %s\n", |
| 4348 | nm, mdname(mddev)); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4349 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | |
| 4351 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4352 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4353 | if (mddev->flags) |
| 4354 | md_update_sb(mddev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 4356 | set_capacity(disk, mddev->array_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4358 | /* If there is a partially-recovered drive we need to |
| 4359 | * start recovery here. If we leave it to md_check_recovery, |
| 4360 | * it will remove the drives and not do the right thing |
| 4361 | */ |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 4362 | if (mddev->degraded && !mddev->sync_thread) { |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4363 | int spares = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4364 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4365 | if (rdev->raid_disk >= 0 && |
| 4366 | !test_bit(In_sync, &rdev->flags) && |
| 4367 | !test_bit(Faulty, &rdev->flags)) |
| 4368 | /* complete an interrupted recovery */ |
| 4369 | spares++; |
| 4370 | if (spares && mddev->pers->sync_request) { |
| 4371 | mddev->recovery = 0; |
| 4372 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 4373 | mddev->sync_thread = md_register_thread(md_do_sync, |
| 4374 | mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 4375 | "resync"); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4376 | if (!mddev->sync_thread) { |
| 4377 | printk(KERN_ERR "%s: could not start resync" |
| 4378 | " thread...\n", |
| 4379 | mdname(mddev)); |
| 4380 | /* leave the spares where they are, it shouldn't hurt */ |
| 4381 | mddev->recovery = 0; |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 4382 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4383 | } |
| 4384 | } |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 4385 | md_wakeup_thread(mddev->thread); |
| 4386 | md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4387 | |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4388 | revalidate_disk(mddev->gendisk); |
Linus Torvalds | 44ce629 | 2007-05-09 18:51:36 -0700 | [diff] [blame] | 4389 | mddev->changed = 1; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4390 | md_new_event(mddev); |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 4391 | sysfs_notify_dirent(mddev->sysfs_state); |
NeilBrown | 0c3573f | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 4392 | if (mddev->sysfs_action) |
| 4393 | sysfs_notify_dirent(mddev->sysfs_action); |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 4394 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 4395 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | return 0; |
| 4397 | } |
| 4398 | |
| 4399 | static int restart_array(mddev_t *mddev) |
| 4400 | { |
| 4401 | struct gendisk *disk = mddev->gendisk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4403 | /* Complain if it has no devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | if (list_empty(&mddev->disks)) |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4405 | return -ENXIO; |
| 4406 | if (!mddev->pers) |
| 4407 | return -EINVAL; |
| 4408 | if (!mddev->ro) |
| 4409 | return -EBUSY; |
| 4410 | mddev->safemode = 0; |
| 4411 | mddev->ro = 0; |
| 4412 | set_disk_ro(disk, 0); |
| 4413 | printk(KERN_INFO "md: %s switched to read-write mode.\n", |
| 4414 | mdname(mddev)); |
| 4415 | /* Kick recovery or resync if necessary */ |
| 4416 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4417 | md_wakeup_thread(mddev->thread); |
| 4418 | md_wakeup_thread(mddev->sync_thread); |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 4419 | sysfs_notify_dirent(mddev->sysfs_state); |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4420 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | } |
| 4422 | |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4423 | /* similar to deny_write_access, but accounts for our holding a reference |
| 4424 | * to the file ourselves */ |
| 4425 | static int deny_bitmap_write_access(struct file * file) |
| 4426 | { |
| 4427 | struct inode *inode = file->f_mapping->host; |
| 4428 | |
| 4429 | spin_lock(&inode->i_lock); |
| 4430 | if (atomic_read(&inode->i_writecount) > 1) { |
| 4431 | spin_unlock(&inode->i_lock); |
| 4432 | return -ETXTBSY; |
| 4433 | } |
| 4434 | atomic_set(&inode->i_writecount, -1); |
| 4435 | spin_unlock(&inode->i_lock); |
| 4436 | |
| 4437 | return 0; |
| 4438 | } |
| 4439 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame^] | 4440 | void restore_bitmap_write_access(struct file *file) |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4441 | { |
| 4442 | struct inode *inode = file->f_mapping->host; |
| 4443 | |
| 4444 | spin_lock(&inode->i_lock); |
| 4445 | atomic_set(&inode->i_writecount, 1); |
| 4446 | spin_unlock(&inode->i_lock); |
| 4447 | } |
| 4448 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4449 | /* mode: |
| 4450 | * 0 - completely stop and dis-assemble array |
| 4451 | * 1 - switch to readonly |
| 4452 | * 2 - stop but do not disassemble array |
| 4453 | */ |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4454 | 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] | 4455 | { |
| 4456 | int err = 0; |
| 4457 | struct gendisk *disk = mddev->gendisk; |
NeilBrown | c464729 | 2009-05-07 12:51:06 +1000 | [diff] [blame] | 4458 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 4460 | mutex_lock(&mddev->open_mutex); |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 4461 | if (atomic_read(&mddev->openers) > is_open) { |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4462 | printk("md: %s still in use.\n",mdname(mddev)); |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 4463 | err = -EBUSY; |
| 4464 | } else if (mddev->pers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | |
| 4466 | if (mddev->sync_thread) { |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4467 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 4469 | md_unregister_thread(mddev->sync_thread); |
| 4470 | mddev->sync_thread = NULL; |
| 4471 | } |
| 4472 | |
| 4473 | del_timer_sync(&mddev->safemode_timer); |
| 4474 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4475 | switch(mode) { |
| 4476 | case 1: /* readonly */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | err = -ENXIO; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4478 | if (mddev->ro==1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | goto out; |
| 4480 | mddev->ro = 1; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4481 | break; |
| 4482 | case 0: /* disassemble */ |
| 4483 | case 2: /* stop */ |
NeilBrown | 6b8b3e8 | 2005-08-04 12:53:35 -0700 | [diff] [blame] | 4484 | bitmap_flush(mddev); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 4485 | md_super_wait(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 | if (mddev->ro) |
| 4487 | set_disk_ro(disk, 0); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | mddev->pers->stop(mddev); |
NeilBrown | d1b5380 | 2007-02-28 20:11:42 -0800 | [diff] [blame] | 4490 | mddev->queue->merge_bvec_fn = NULL; |
| 4491 | mddev->queue->unplug_fn = NULL; |
NeilBrown | 041ae52 | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4492 | mddev->queue->backing_dev_info.congested_fn = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | module_put(mddev->pers->owner); |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 4494 | if (mddev->pers->sync_request) |
| 4495 | mddev->private = &md_redundancy_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | mddev->pers = NULL; |
Dan Williams | 4f54b0e | 2008-05-23 13:04:37 -0700 | [diff] [blame] | 4497 | /* tell userspace to handle 'inactive' */ |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 4498 | sysfs_notify_dirent(mddev->sysfs_state); |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4499 | |
NeilBrown | c464729 | 2009-05-07 12:51:06 +1000 | [diff] [blame] | 4500 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 4501 | if (rdev->raid_disk >= 0) { |
| 4502 | char nm[20]; |
| 4503 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 4504 | sysfs_remove_link(&mddev->kobj, nm); |
| 4505 | } |
| 4506 | |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4507 | set_capacity(disk, 0); |
Linus Torvalds | 44ce629 | 2007-05-09 18:51:36 -0700 | [diff] [blame] | 4508 | mddev->changed = 1; |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | if (mddev->ro) |
| 4511 | mddev->ro = 0; |
| 4512 | } |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4513 | if (!mddev->in_sync || mddev->flags) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | /* mark array as shutdown cleanly */ |
| 4515 | mddev->in_sync = 1; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4516 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4518 | if (mode == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | set_disk_ro(disk, 1); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4520 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
NeilBrown | 80ffb3c | 2009-08-18 10:35:26 +1000 | [diff] [blame] | 4521 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | } |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 4523 | out: |
| 4524 | mutex_unlock(&mddev->open_mutex); |
| 4525 | if (err) |
| 4526 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | /* |
| 4528 | * Free resources if final stop |
| 4529 | */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4530 | if (mode == 0) { |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); |
| 4533 | |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4534 | bitmap_destroy(mddev); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4535 | if (mddev->bitmap_info.file) { |
| 4536 | restore_bitmap_write_access(mddev->bitmap_info.file); |
| 4537 | fput(mddev->bitmap_info.file); |
| 4538 | mddev->bitmap_info.file = NULL; |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4539 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4540 | mddev->bitmap_info.offset = 0; |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4541 | |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 4542 | /* make sure all md_delayed_delete calls have finished */ |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 4543 | flush_scheduled_work(); |
| 4544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | export_array(mddev); |
| 4546 | |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 4547 | mddev->array_sectors = 0; |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4548 | mddev->external_size = 0; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4549 | mddev->dev_sectors = 0; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4550 | mddev->raid_disks = 0; |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 4551 | mddev->recovery_cp = 0; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 4552 | mddev->resync_min = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4553 | mddev->resync_max = MaxSector; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 4554 | mddev->reshape_position = MaxSector; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 4555 | mddev->external = 0; |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4556 | mddev->persistent = 0; |
NeilBrown | d897dbf | 2008-04-30 00:52:29 -0700 | [diff] [blame] | 4557 | mddev->level = LEVEL_NONE; |
| 4558 | mddev->clevel[0] = 0; |
| 4559 | mddev->flags = 0; |
| 4560 | mddev->ro = 0; |
| 4561 | mddev->metadata_type[0] = 0; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4562 | mddev->chunk_sectors = 0; |
NeilBrown | d897dbf | 2008-04-30 00:52:29 -0700 | [diff] [blame] | 4563 | mddev->ctime = mddev->utime = 0; |
| 4564 | mddev->layout = 0; |
| 4565 | mddev->max_disks = 0; |
| 4566 | mddev->events = 0; |
| 4567 | mddev->delta_disks = 0; |
| 4568 | mddev->new_level = LEVEL_NONE; |
| 4569 | mddev->new_layout = 0; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4570 | mddev->new_chunk_sectors = 0; |
NeilBrown | d897dbf | 2008-04-30 00:52:29 -0700 | [diff] [blame] | 4571 | mddev->curr_resync = 0; |
| 4572 | mddev->resync_mismatches = 0; |
| 4573 | mddev->suspend_lo = mddev->suspend_hi = 0; |
| 4574 | mddev->sync_speed_min = mddev->sync_speed_max = 0; |
| 4575 | mddev->recovery = 0; |
| 4576 | mddev->in_sync = 0; |
| 4577 | mddev->changed = 0; |
| 4578 | mddev->degraded = 0; |
| 4579 | mddev->barriers_work = 0; |
| 4580 | mddev->safemode = 0; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4581 | mddev->bitmap_info.offset = 0; |
| 4582 | mddev->bitmap_info.default_offset = 0; |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 4583 | mddev->bitmap_info.chunksize = 0; |
| 4584 | mddev->bitmap_info.daemon_sleep = 0; |
| 4585 | mddev->bitmap_info.max_write_behind = 0; |
NeilBrown | 934d9c2 | 2008-10-28 17:01:23 +1100 | [diff] [blame] | 4586 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4587 | if (mddev->hold_active == UNTIL_STOP) |
| 4588 | mddev->hold_active = 0; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4589 | |
NeilBrown | a8a55c3 | 2006-06-26 00:27:39 -0700 | [diff] [blame] | 4590 | } else if (mddev->pers) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | printk(KERN_INFO "md: %s switched to read-only mode.\n", |
| 4592 | mdname(mddev)); |
| 4593 | err = 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 4594 | blk_integrity_unregister(disk); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4595 | md_new_event(mddev); |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 4596 | sysfs_notify_dirent(mddev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | return err; |
| 4598 | } |
| 4599 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 4600 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | static void autorun_array(mddev_t *mddev) |
| 4602 | { |
| 4603 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4604 | int err; |
| 4605 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4606 | if (list_empty(&mddev->disks)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | |
| 4609 | printk(KERN_INFO "md: running: "); |
| 4610 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4611 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | char b[BDEVNAME_SIZE]; |
| 4613 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 4614 | } |
| 4615 | printk("\n"); |
| 4616 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4617 | err = do_md_run(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | if (err) { |
| 4619 | printk(KERN_WARNING "md: do_md_run() returned %d\n", err); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4620 | do_md_stop(mddev, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | /* |
| 4625 | * lets try to run arrays based on all disks that have arrived |
| 4626 | * until now. (those are in pending_raid_disks) |
| 4627 | * |
| 4628 | * the method: pick the first pending disk, collect all disks with |
| 4629 | * the same UUID, remove all from the pending list and put them into |
| 4630 | * the 'same_array' list. Then order this list based on superblock |
| 4631 | * update time (freshest comes first), kick out 'old' disks and |
| 4632 | * compare superblocks. If everything's fine then run it. |
| 4633 | * |
| 4634 | * If "unit" is allocated, then bump its reference count |
| 4635 | */ |
| 4636 | static void autorun_devices(int part) |
| 4637 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4638 | mdk_rdev_t *rdev0, *rdev, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | mddev_t *mddev; |
| 4640 | char b[BDEVNAME_SIZE]; |
| 4641 | |
| 4642 | printk(KERN_INFO "md: autorun ...\n"); |
| 4643 | while (!list_empty(&pending_raid_disks)) { |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4644 | int unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | dev_t dev; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 4646 | LIST_HEAD(candidates); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | rdev0 = list_entry(pending_raid_disks.next, |
| 4648 | mdk_rdev_t, same_set); |
| 4649 | |
| 4650 | printk(KERN_INFO "md: considering %s ...\n", |
| 4651 | bdevname(rdev0->bdev,b)); |
| 4652 | INIT_LIST_HEAD(&candidates); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4653 | rdev_for_each_list(rdev, tmp, &pending_raid_disks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | if (super_90_load(rdev, rdev0, 0) >= 0) { |
| 4655 | printk(KERN_INFO "md: adding %s ...\n", |
| 4656 | bdevname(rdev->bdev,b)); |
| 4657 | list_move(&rdev->same_set, &candidates); |
| 4658 | } |
| 4659 | /* |
| 4660 | * now we have a set of devices, with all of them having |
| 4661 | * mostly sane superblocks. It's time to allocate the |
| 4662 | * mddev. |
| 4663 | */ |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4664 | if (part) { |
| 4665 | dev = MKDEV(mdp_major, |
| 4666 | rdev0->preferred_minor << MdpMinorShift); |
| 4667 | unit = MINOR(dev) >> MdpMinorShift; |
| 4668 | } else { |
| 4669 | dev = MKDEV(MD_MAJOR, rdev0->preferred_minor); |
| 4670 | unit = MINOR(dev); |
| 4671 | } |
| 4672 | if (rdev0->preferred_minor != unit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | printk(KERN_INFO "md: unit number in %s is bad: %d\n", |
| 4674 | bdevname(rdev0->bdev, b), rdev0->preferred_minor); |
| 4675 | break; |
| 4676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | |
| 4678 | md_probe(dev, NULL, NULL); |
| 4679 | mddev = mddev_find(dev); |
Neil Brown | 9bbbca3 | 2008-06-28 08:31:17 +1000 | [diff] [blame] | 4680 | if (!mddev || !mddev->gendisk) { |
| 4681 | if (mddev) |
| 4682 | mddev_put(mddev); |
| 4683 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | "md: cannot allocate memory for md drive.\n"); |
| 4685 | break; |
| 4686 | } |
| 4687 | if (mddev_lock(mddev)) |
| 4688 | printk(KERN_WARNING "md: %s locked, cannot run\n", |
| 4689 | mdname(mddev)); |
| 4690 | else if (mddev->raid_disks || mddev->major_version |
| 4691 | || !list_empty(&mddev->disks)) { |
| 4692 | printk(KERN_WARNING |
| 4693 | "md: %s already running, cannot run %s\n", |
| 4694 | mdname(mddev), bdevname(rdev0->bdev,b)); |
| 4695 | mddev_unlock(mddev); |
| 4696 | } else { |
| 4697 | printk(KERN_INFO "md: created %s\n", mdname(mddev)); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4698 | mddev->persistent = 1; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4699 | rdev_for_each_list(rdev, tmp, &candidates) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | list_del_init(&rdev->same_set); |
| 4701 | if (bind_rdev_to_array(rdev, mddev)) |
| 4702 | export_rdev(rdev); |
| 4703 | } |
| 4704 | autorun_array(mddev); |
| 4705 | mddev_unlock(mddev); |
| 4706 | } |
| 4707 | /* on success, candidates will be empty, on error |
| 4708 | * it won't... |
| 4709 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4710 | rdev_for_each_list(rdev, tmp, &candidates) { |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 4711 | list_del_init(&rdev->same_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | export_rdev(rdev); |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 4713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | mddev_put(mddev); |
| 4715 | } |
| 4716 | printk(KERN_INFO "md: ... autorun DONE.\n"); |
| 4717 | } |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 4718 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | static int get_version(void __user * arg) |
| 4721 | { |
| 4722 | mdu_version_t ver; |
| 4723 | |
| 4724 | ver.major = MD_MAJOR_VERSION; |
| 4725 | ver.minor = MD_MINOR_VERSION; |
| 4726 | ver.patchlevel = MD_PATCHLEVEL_VERSION; |
| 4727 | |
| 4728 | if (copy_to_user(arg, &ver, sizeof(ver))) |
| 4729 | return -EFAULT; |
| 4730 | |
| 4731 | return 0; |
| 4732 | } |
| 4733 | |
| 4734 | static int get_array_info(mddev_t * mddev, void __user * arg) |
| 4735 | { |
| 4736 | mdu_array_info_t info; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4737 | int nr,working,insync,failed,spare; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4740 | nr=working=insync=failed=spare=0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4741 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4742 | nr++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4743 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | failed++; |
| 4745 | else { |
| 4746 | working++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4747 | if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4748 | insync++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | else |
| 4750 | spare++; |
| 4751 | } |
| 4752 | } |
| 4753 | |
| 4754 | info.major_version = mddev->major_version; |
| 4755 | info.minor_version = mddev->minor_version; |
| 4756 | info.patch_version = MD_PATCHLEVEL_VERSION; |
| 4757 | info.ctime = mddev->ctime; |
| 4758 | info.level = mddev->level; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4759 | info.size = mddev->dev_sectors / 2; |
| 4760 | if (info.size != mddev->dev_sectors / 2) /* overflow */ |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 4761 | info.size = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | info.nr_disks = nr; |
| 4763 | info.raid_disks = mddev->raid_disks; |
| 4764 | info.md_minor = mddev->md_minor; |
| 4765 | info.not_persistent= !mddev->persistent; |
| 4766 | |
| 4767 | info.utime = mddev->utime; |
| 4768 | info.state = 0; |
| 4769 | if (mddev->in_sync) |
| 4770 | info.state = (1<<MD_SB_CLEAN); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4771 | if (mddev->bitmap && mddev->bitmap_info.offset) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4772 | info.state = (1<<MD_SB_BITMAP_PRESENT); |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4773 | info.active_disks = insync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | info.working_disks = working; |
| 4775 | info.failed_disks = failed; |
| 4776 | info.spare_disks = spare; |
| 4777 | |
| 4778 | info.layout = mddev->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4779 | info.chunk_size = mddev->chunk_sectors << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4780 | |
| 4781 | if (copy_to_user(arg, &info, sizeof(info))) |
| 4782 | return -EFAULT; |
| 4783 | |
| 4784 | return 0; |
| 4785 | } |
| 4786 | |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 4787 | static int get_bitmap_file(mddev_t * mddev, void __user * arg) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4788 | { |
| 4789 | mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ |
| 4790 | char *ptr, *buf = NULL; |
| 4791 | int err = -ENOMEM; |
| 4792 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4793 | if (md_allow_write(mddev)) |
| 4794 | file = kmalloc(sizeof(*file), GFP_NOIO); |
| 4795 | else |
| 4796 | file = kmalloc(sizeof(*file), GFP_KERNEL); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 4797 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4798 | if (!file) |
| 4799 | goto out; |
| 4800 | |
| 4801 | /* bitmap disabled, zero the first byte and copy out */ |
| 4802 | if (!mddev->bitmap || !mddev->bitmap->file) { |
| 4803 | file->pathname[0] = '\0'; |
| 4804 | goto copy_out; |
| 4805 | } |
| 4806 | |
| 4807 | buf = kmalloc(sizeof(file->pathname), GFP_KERNEL); |
| 4808 | if (!buf) |
| 4809 | goto out; |
| 4810 | |
Christoph Hellwig | 6bcfd60 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 4811 | ptr = d_path(&mddev->bitmap->file->f_path, buf, sizeof(file->pathname)); |
| 4812 | if (IS_ERR(ptr)) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4813 | goto out; |
| 4814 | |
| 4815 | strcpy(file->pathname, ptr); |
| 4816 | |
| 4817 | copy_out: |
| 4818 | err = 0; |
| 4819 | if (copy_to_user(arg, file, sizeof(*file))) |
| 4820 | err = -EFAULT; |
| 4821 | out: |
| 4822 | kfree(buf); |
| 4823 | kfree(file); |
| 4824 | return err; |
| 4825 | } |
| 4826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | static int get_disk_info(mddev_t * mddev, void __user * arg) |
| 4828 | { |
| 4829 | mdu_disk_info_t info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4830 | mdk_rdev_t *rdev; |
| 4831 | |
| 4832 | if (copy_from_user(&info, arg, sizeof(info))) |
| 4833 | return -EFAULT; |
| 4834 | |
Andre Noll | 26ef379 | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4835 | rdev = find_rdev_nr(mddev, info.number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | if (rdev) { |
| 4837 | info.major = MAJOR(rdev->bdev->bd_dev); |
| 4838 | info.minor = MINOR(rdev->bdev->bd_dev); |
| 4839 | info.raid_disk = rdev->raid_disk; |
| 4840 | info.state = 0; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4841 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | info.state |= (1<<MD_DISK_FAULTY); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4843 | else if (test_bit(In_sync, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | info.state |= (1<<MD_DISK_ACTIVE); |
| 4845 | info.state |= (1<<MD_DISK_SYNC); |
| 4846 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4847 | if (test_bit(WriteMostly, &rdev->flags)) |
| 4848 | info.state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | } else { |
| 4850 | info.major = info.minor = 0; |
| 4851 | info.raid_disk = -1; |
| 4852 | info.state = (1<<MD_DISK_REMOVED); |
| 4853 | } |
| 4854 | |
| 4855 | if (copy_to_user(arg, &info, sizeof(info))) |
| 4856 | return -EFAULT; |
| 4857 | |
| 4858 | return 0; |
| 4859 | } |
| 4860 | |
| 4861 | static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) |
| 4862 | { |
| 4863 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 4864 | mdk_rdev_t *rdev; |
| 4865 | dev_t dev = MKDEV(info->major,info->minor); |
| 4866 | |
| 4867 | if (info->major != MAJOR(dev) || info->minor != MINOR(dev)) |
| 4868 | return -EOVERFLOW; |
| 4869 | |
| 4870 | if (!mddev->raid_disks) { |
| 4871 | int err; |
| 4872 | /* expecting a device which has a superblock */ |
| 4873 | rdev = md_import_device(dev, mddev->major_version, mddev->minor_version); |
| 4874 | if (IS_ERR(rdev)) { |
| 4875 | printk(KERN_WARNING |
| 4876 | "md: md_import_device returned %ld\n", |
| 4877 | PTR_ERR(rdev)); |
| 4878 | return PTR_ERR(rdev); |
| 4879 | } |
| 4880 | if (!list_empty(&mddev->disks)) { |
| 4881 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 4882 | mdk_rdev_t, same_set); |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4883 | err = super_types[mddev->major_version] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | .load_super(rdev, rdev0, mddev->minor_version); |
| 4885 | if (err < 0) { |
| 4886 | printk(KERN_WARNING |
| 4887 | "md: %s has different UUID to %s\n", |
| 4888 | bdevname(rdev->bdev,b), |
| 4889 | bdevname(rdev0->bdev,b2)); |
| 4890 | export_rdev(rdev); |
| 4891 | return -EINVAL; |
| 4892 | } |
| 4893 | } |
| 4894 | err = bind_rdev_to_array(rdev, mddev); |
| 4895 | if (err) |
| 4896 | export_rdev(rdev); |
| 4897 | return err; |
| 4898 | } |
| 4899 | |
| 4900 | /* |
| 4901 | * add_new_disk can be used once the array is assembled |
| 4902 | * to add "hot spares". They must already have a superblock |
| 4903 | * written |
| 4904 | */ |
| 4905 | if (mddev->pers) { |
| 4906 | int err; |
| 4907 | if (!mddev->pers->hot_add_disk) { |
| 4908 | printk(KERN_WARNING |
| 4909 | "%s: personality does not support diskops!\n", |
| 4910 | mdname(mddev)); |
| 4911 | return -EINVAL; |
| 4912 | } |
NeilBrown | 7b1e35f | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 4913 | if (mddev->persistent) |
| 4914 | rdev = md_import_device(dev, mddev->major_version, |
| 4915 | mddev->minor_version); |
| 4916 | else |
| 4917 | rdev = md_import_device(dev, -1, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | if (IS_ERR(rdev)) { |
| 4919 | printk(KERN_WARNING |
| 4920 | "md: md_import_device returned %ld\n", |
| 4921 | PTR_ERR(rdev)); |
| 4922 | return PTR_ERR(rdev); |
| 4923 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 4924 | /* set save_raid_disk if appropriate */ |
| 4925 | if (!mddev->persistent) { |
| 4926 | if (info->state & (1<<MD_DISK_SYNC) && |
| 4927 | info->raid_disk < mddev->raid_disks) |
| 4928 | rdev->raid_disk = info->raid_disk; |
| 4929 | else |
| 4930 | rdev->raid_disk = -1; |
| 4931 | } else |
| 4932 | super_types[mddev->major_version]. |
| 4933 | validate_super(mddev, rdev); |
| 4934 | rdev->saved_raid_disk = rdev->raid_disk; |
| 4935 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4936 | clear_bit(In_sync, &rdev->flags); /* just to be sure */ |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4937 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 4938 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 575a80f | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4939 | else |
| 4940 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | rdev->raid_disk = -1; |
| 4943 | err = bind_rdev_to_array(rdev, mddev); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 4944 | if (!err && !mddev->pers->hot_remove_disk) { |
| 4945 | /* If there is hot_add_disk but no hot_remove_disk |
| 4946 | * then added disks for geometry changes, |
| 4947 | * and should be added immediately. |
| 4948 | */ |
| 4949 | super_types[mddev->major_version]. |
| 4950 | validate_super(mddev, rdev); |
| 4951 | err = mddev->pers->hot_add_disk(mddev, rdev); |
| 4952 | if (err) |
| 4953 | unbind_rdev_from_array(rdev); |
| 4954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4955 | if (err) |
| 4956 | export_rdev(rdev); |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 4957 | else |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 4958 | sysfs_notify_dirent(rdev->sysfs_state); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 4959 | |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 4960 | md_update_sb(mddev, 1); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 4961 | if (mddev->degraded) |
| 4962 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 4963 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 4964 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 | return err; |
| 4966 | } |
| 4967 | |
| 4968 | /* otherwise, add_new_disk is only allowed |
| 4969 | * for major_version==0 superblocks |
| 4970 | */ |
| 4971 | if (mddev->major_version != 0) { |
| 4972 | printk(KERN_WARNING "%s: ADD_NEW_DISK not supported\n", |
| 4973 | mdname(mddev)); |
| 4974 | return -EINVAL; |
| 4975 | } |
| 4976 | |
| 4977 | if (!(info->state & (1<<MD_DISK_FAULTY))) { |
| 4978 | int err; |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4979 | rdev = md_import_device(dev, -1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | if (IS_ERR(rdev)) { |
| 4981 | printk(KERN_WARNING |
| 4982 | "md: error, md_import_device() returned %ld\n", |
| 4983 | PTR_ERR(rdev)); |
| 4984 | return PTR_ERR(rdev); |
| 4985 | } |
| 4986 | rdev->desc_nr = info->number; |
| 4987 | if (info->raid_disk < mddev->raid_disks) |
| 4988 | rdev->raid_disk = info->raid_disk; |
| 4989 | else |
| 4990 | rdev->raid_disk = -1; |
| 4991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | if (rdev->raid_disk < mddev->raid_disks) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4993 | if (info->state & (1<<MD_DISK_SYNC)) |
| 4994 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4996 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 4997 | set_bit(WriteMostly, &rdev->flags); |
| 4998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | if (!mddev->persistent) { |
| 5000 | printk(KERN_INFO "md: nonpersistent superblock ...\n"); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5001 | rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | } else |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5003 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 5004 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 5006 | err = bind_rdev_to_array(rdev, mddev); |
| 5007 | if (err) { |
| 5008 | export_rdev(rdev); |
| 5009 | return err; |
| 5010 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | } |
| 5012 | |
| 5013 | return 0; |
| 5014 | } |
| 5015 | |
| 5016 | static int hot_remove_disk(mddev_t * mddev, dev_t dev) |
| 5017 | { |
| 5018 | char b[BDEVNAME_SIZE]; |
| 5019 | mdk_rdev_t *rdev; |
| 5020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | rdev = find_rdev(mddev, dev); |
| 5022 | if (!rdev) |
| 5023 | return -ENXIO; |
| 5024 | |
| 5025 | if (rdev->raid_disk >= 0) |
| 5026 | goto busy; |
| 5027 | |
| 5028 | kick_rdev_from_array(rdev); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5029 | md_update_sb(mddev, 1); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5030 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | |
| 5032 | return 0; |
| 5033 | busy: |
Nick Andrew | fdefa4d | 2008-04-21 22:42:58 +0000 | [diff] [blame] | 5034 | printk(KERN_WARNING "md: cannot remove active disk %s from %s ...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 5036 | return -EBUSY; |
| 5037 | } |
| 5038 | |
| 5039 | static int hot_add_disk(mddev_t * mddev, dev_t dev) |
| 5040 | { |
| 5041 | char b[BDEVNAME_SIZE]; |
| 5042 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | mdk_rdev_t *rdev; |
| 5044 | |
| 5045 | if (!mddev->pers) |
| 5046 | return -ENODEV; |
| 5047 | |
| 5048 | if (mddev->major_version != 0) { |
| 5049 | printk(KERN_WARNING "%s: HOT_ADD may only be used with" |
| 5050 | " version-0 superblocks.\n", |
| 5051 | mdname(mddev)); |
| 5052 | return -EINVAL; |
| 5053 | } |
| 5054 | if (!mddev->pers->hot_add_disk) { |
| 5055 | printk(KERN_WARNING |
| 5056 | "%s: personality does not support diskops!\n", |
| 5057 | mdname(mddev)); |
| 5058 | return -EINVAL; |
| 5059 | } |
| 5060 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5061 | rdev = md_import_device(dev, -1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | if (IS_ERR(rdev)) { |
| 5063 | printk(KERN_WARNING |
| 5064 | "md: error, md_import_device() returned %ld\n", |
| 5065 | PTR_ERR(rdev)); |
| 5066 | return -EINVAL; |
| 5067 | } |
| 5068 | |
| 5069 | if (mddev->persistent) |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5070 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | else |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5072 | rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 5074 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5075 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5076 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | printk(KERN_WARNING |
| 5078 | "md: can not hot-add faulty %s disk to %s!\n", |
| 5079 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 5080 | err = -EINVAL; |
| 5081 | goto abort_export; |
| 5082 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5083 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5084 | rdev->desc_nr = -1; |
NeilBrown | 5842730 | 2006-10-06 00:44:04 -0700 | [diff] [blame] | 5085 | rdev->saved_raid_disk = -1; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 5086 | err = bind_rdev_to_array(rdev, mddev); |
| 5087 | if (err) |
| 5088 | goto abort_export; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5089 | |
| 5090 | /* |
| 5091 | * The rest should better be atomic, we can have disk failures |
| 5092 | * noticed in interrupt contexts ... |
| 5093 | */ |
| 5094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | rdev->raid_disk = -1; |
| 5096 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5097 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | |
| 5099 | /* |
| 5100 | * Kick recovery, maybe this spare has to be added to the |
| 5101 | * array immediately. |
| 5102 | */ |
| 5103 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5104 | md_wakeup_thread(mddev->thread); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5105 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | return 0; |
| 5107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | abort_export: |
| 5109 | export_rdev(rdev); |
| 5110 | return err; |
| 5111 | } |
| 5112 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5113 | static int set_bitmap_file(mddev_t *mddev, int fd) |
| 5114 | { |
| 5115 | int err; |
| 5116 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5117 | if (mddev->pers) { |
| 5118 | if (!mddev->pers->quiesce) |
| 5119 | return -EBUSY; |
| 5120 | if (mddev->recovery || mddev->sync_thread) |
| 5121 | return -EBUSY; |
| 5122 | /* we should be able to change the bitmap.. */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5123 | } |
| 5124 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5125 | |
| 5126 | if (fd >= 0) { |
| 5127 | if (mddev->bitmap) |
| 5128 | return -EEXIST; /* cannot add when bitmap is present */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5129 | mddev->bitmap_info.file = fget(fd); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5130 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5131 | if (mddev->bitmap_info.file == NULL) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5132 | printk(KERN_ERR "%s: error: failed to get bitmap file\n", |
| 5133 | mdname(mddev)); |
| 5134 | return -EBADF; |
| 5135 | } |
| 5136 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5137 | err = deny_bitmap_write_access(mddev->bitmap_info.file); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5138 | if (err) { |
| 5139 | printk(KERN_ERR "%s: error: bitmap file is already in use\n", |
| 5140 | mdname(mddev)); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5141 | fput(mddev->bitmap_info.file); |
| 5142 | mddev->bitmap_info.file = NULL; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5143 | return err; |
| 5144 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5145 | mddev->bitmap_info.offset = 0; /* file overrides offset */ |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5146 | } else if (mddev->bitmap == NULL) |
| 5147 | return -ENOENT; /* cannot remove what isn't there */ |
| 5148 | err = 0; |
| 5149 | if (mddev->pers) { |
| 5150 | mddev->pers->quiesce(mddev, 1); |
| 5151 | if (fd >= 0) |
| 5152 | err = bitmap_create(mddev); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5153 | if (fd < 0 || err) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5154 | bitmap_destroy(mddev); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5155 | fd = -1; /* make sure to put the file */ |
| 5156 | } |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5157 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5158 | } |
| 5159 | if (fd < 0) { |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5160 | if (mddev->bitmap_info.file) { |
| 5161 | restore_bitmap_write_access(mddev->bitmap_info.file); |
| 5162 | fput(mddev->bitmap_info.file); |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 5163 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5164 | mddev->bitmap_info.file = NULL; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5165 | } |
| 5166 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5167 | return err; |
| 5168 | } |
| 5169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5170 | /* |
| 5171 | * set_array_info is used two different ways |
| 5172 | * The original usage is when creating a new array. |
| 5173 | * In this usage, raid_disks is > 0 and it together with |
| 5174 | * level, size, not_persistent,layout,chunksize determine the |
| 5175 | * shape of the array. |
| 5176 | * This will always create an array with a type-0.90.0 superblock. |
| 5177 | * The newer usage is when assembling an array. |
| 5178 | * In this case raid_disks will be 0, and the major_version field is |
| 5179 | * use to determine which style super-blocks are to be found on the devices. |
| 5180 | * The minor and patch _version numbers are also kept incase the |
| 5181 | * super_block handler wishes to interpret them. |
| 5182 | */ |
| 5183 | static int set_array_info(mddev_t * mddev, mdu_array_info_t *info) |
| 5184 | { |
| 5185 | |
| 5186 | if (info->raid_disks == 0) { |
| 5187 | /* just setting version number for superblock loading */ |
| 5188 | if (info->major_version < 0 || |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 5189 | info->major_version >= ARRAY_SIZE(super_types) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | super_types[info->major_version].name == NULL) { |
| 5191 | /* maybe try to auto-load a module? */ |
| 5192 | printk(KERN_INFO |
| 5193 | "md: superblock version %d not known\n", |
| 5194 | info->major_version); |
| 5195 | return -EINVAL; |
| 5196 | } |
| 5197 | mddev->major_version = info->major_version; |
| 5198 | mddev->minor_version = info->minor_version; |
| 5199 | mddev->patch_version = info->patch_version; |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 5200 | mddev->persistent = !info->not_persistent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5201 | return 0; |
| 5202 | } |
| 5203 | mddev->major_version = MD_MAJOR_VERSION; |
| 5204 | mddev->minor_version = MD_MINOR_VERSION; |
| 5205 | mddev->patch_version = MD_PATCHLEVEL_VERSION; |
| 5206 | mddev->ctime = get_seconds(); |
| 5207 | |
| 5208 | mddev->level = info->level; |
NeilBrown | 17115e0 | 2006-01-16 22:14:57 -0800 | [diff] [blame] | 5209 | mddev->clevel[0] = 0; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5210 | mddev->dev_sectors = 2 * (sector_t)info->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5211 | mddev->raid_disks = info->raid_disks; |
| 5212 | /* don't set md_minor, it is determined by which /dev/md* was |
| 5213 | * openned |
| 5214 | */ |
| 5215 | if (info->state & (1<<MD_SB_CLEAN)) |
| 5216 | mddev->recovery_cp = MaxSector; |
| 5217 | else |
| 5218 | mddev->recovery_cp = 0; |
| 5219 | mddev->persistent = ! info->not_persistent; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 5220 | mddev->external = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5221 | |
| 5222 | mddev->layout = info->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5223 | mddev->chunk_sectors = info->chunk_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | |
| 5225 | mddev->max_disks = MD_SB_DISKS; |
| 5226 | |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 5227 | if (mddev->persistent) |
| 5228 | mddev->flags = 0; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5229 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5231 | mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9; |
| 5232 | mddev->bitmap_info.offset = 0; |
NeilBrown | b2a2703 | 2005-11-28 13:44:12 -0800 | [diff] [blame] | 5233 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5234 | mddev->reshape_position = MaxSector; |
| 5235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | /* |
| 5237 | * Generate a 128 bit UUID |
| 5238 | */ |
| 5239 | get_random_bytes(mddev->uuid, 16); |
| 5240 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5241 | mddev->new_level = mddev->level; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5242 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5243 | mddev->new_layout = mddev->layout; |
| 5244 | mddev->delta_disks = 0; |
| 5245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5246 | return 0; |
| 5247 | } |
| 5248 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5249 | void md_set_array_sectors(mddev_t *mddev, sector_t array_sectors) |
| 5250 | { |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5251 | WARN(!mddev_is_locked(mddev), "%s: unlocked mddev!\n", __func__); |
| 5252 | |
| 5253 | if (mddev->external_size) |
| 5254 | return; |
| 5255 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5256 | mddev->array_sectors = array_sectors; |
| 5257 | } |
| 5258 | EXPORT_SYMBOL(md_set_array_sectors); |
| 5259 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5260 | static int update_size(mddev_t *mddev, sector_t num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5261 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5262 | mdk_rdev_t *rdev; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5263 | int rv; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5264 | int fit = (num_sectors == 0); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5265 | |
| 5266 | if (mddev->pers->resize == NULL) |
| 5267 | return -EINVAL; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5268 | /* The "num_sectors" is the number of sectors of each device that |
| 5269 | * is used. This can only make sense for arrays with redundancy. |
| 5270 | * linear and raid0 always use whatever space is available. We can only |
| 5271 | * consider changing this number if no resync or reconstruction is |
| 5272 | * happening, and if the new size is acceptable. It must fit before the |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5273 | * sb_start or, if that is <data_offset, it must fit before the size |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5274 | * of each device. If num_sectors is zero, we find the largest size |
| 5275 | * that fits. |
| 5276 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5277 | */ |
| 5278 | if (mddev->sync_thread) |
| 5279 | return -EBUSY; |
NeilBrown | dba034e | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 5280 | if (mddev->bitmap) |
| 5281 | /* Sorry, cannot grow a bitmap yet, just remove it, |
| 5282 | * grow, and re-add. |
| 5283 | */ |
| 5284 | return -EBUSY; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5285 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5286 | sector_t avail = rdev->sectors; |
NeilBrown | 01ab566 | 2006-10-28 10:38:30 -0700 | [diff] [blame] | 5287 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5288 | if (fit && (num_sectors == 0 || num_sectors > avail)) |
| 5289 | num_sectors = avail; |
| 5290 | if (avail < num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5291 | return -ENOSPC; |
| 5292 | } |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5293 | rv = mddev->pers->resize(mddev, num_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5294 | if (!rv) |
| 5295 | revalidate_disk(mddev->gendisk); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5296 | return rv; |
| 5297 | } |
| 5298 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5299 | static int update_raid_disks(mddev_t *mddev, int raid_disks) |
| 5300 | { |
| 5301 | int rv; |
| 5302 | /* change the number of raid disks */ |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5303 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5304 | return -EINVAL; |
| 5305 | if (raid_disks <= 0 || |
| 5306 | raid_disks >= mddev->max_disks) |
| 5307 | return -EINVAL; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5308 | if (mddev->sync_thread || mddev->reshape_position != MaxSector) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5309 | return -EBUSY; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5310 | mddev->delta_disks = raid_disks - mddev->raid_disks; |
| 5311 | |
| 5312 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5313 | return rv; |
| 5314 | } |
| 5315 | |
| 5316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5317 | /* |
| 5318 | * update_array_info is used to change the configuration of an |
| 5319 | * on-line array. |
| 5320 | * The version, ctime,level,size,raid_disks,not_persistent, layout,chunk_size |
| 5321 | * fields in the info are checked against the array. |
| 5322 | * Any differences that cannot be handled will cause an error. |
| 5323 | * Normally, only one change can be managed at a time. |
| 5324 | */ |
| 5325 | static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) |
| 5326 | { |
| 5327 | int rv = 0; |
| 5328 | int cnt = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5329 | int state = 0; |
| 5330 | |
| 5331 | /* calculate expected state,ignoring low bits */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5332 | if (mddev->bitmap && mddev->bitmap_info.offset) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5333 | state |= (1 << MD_SB_BITMAP_PRESENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 | |
| 5335 | if (mddev->major_version != info->major_version || |
| 5336 | mddev->minor_version != info->minor_version || |
| 5337 | /* mddev->patch_version != info->patch_version || */ |
| 5338 | mddev->ctime != info->ctime || |
| 5339 | mddev->level != info->level || |
| 5340 | /* mddev->layout != info->layout || */ |
| 5341 | !mddev->persistent != info->not_persistent|| |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5342 | mddev->chunk_sectors != info->chunk_size >> 9 || |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5343 | /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */ |
| 5344 | ((state^info->state) & 0xfffffe00) |
| 5345 | ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5346 | return -EINVAL; |
| 5347 | /* Check there is only one change */ |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5348 | if (info->size >= 0 && mddev->dev_sectors / 2 != info->size) |
| 5349 | cnt++; |
| 5350 | if (mddev->raid_disks != info->raid_disks) |
| 5351 | cnt++; |
| 5352 | if (mddev->layout != info->layout) |
| 5353 | cnt++; |
| 5354 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) |
| 5355 | cnt++; |
| 5356 | if (cnt == 0) |
| 5357 | return 0; |
| 5358 | if (cnt > 1) |
| 5359 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | |
| 5361 | if (mddev->layout != info->layout) { |
| 5362 | /* Change layout |
| 5363 | * we don't need to do anything at the md level, the |
| 5364 | * personality will take care of it all. |
| 5365 | */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5366 | if (mddev->pers->check_reshape == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5367 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5368 | else { |
| 5369 | mddev->new_layout = info->layout; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5370 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5371 | if (rv) |
| 5372 | mddev->new_layout = mddev->layout; |
| 5373 | return rv; |
| 5374 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5375 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5376 | if (info->size >= 0 && mddev->dev_sectors / 2 != info->size) |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5377 | rv = update_size(mddev, (sector_t)info->size * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5379 | if (mddev->raid_disks != info->raid_disks) |
| 5380 | rv = update_raid_disks(mddev, info->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5381 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5382 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) { |
| 5383 | if (mddev->pers->quiesce == NULL) |
| 5384 | return -EINVAL; |
| 5385 | if (mddev->recovery || mddev->sync_thread) |
| 5386 | return -EBUSY; |
| 5387 | if (info->state & (1<<MD_SB_BITMAP_PRESENT)) { |
| 5388 | /* add the bitmap */ |
| 5389 | if (mddev->bitmap) |
| 5390 | return -EEXIST; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5391 | if (mddev->bitmap_info.default_offset == 0) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5392 | return -EINVAL; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5393 | mddev->bitmap_info.offset = |
| 5394 | mddev->bitmap_info.default_offset; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5395 | mddev->pers->quiesce(mddev, 1); |
| 5396 | rv = bitmap_create(mddev); |
| 5397 | if (rv) |
| 5398 | bitmap_destroy(mddev); |
| 5399 | mddev->pers->quiesce(mddev, 0); |
| 5400 | } else { |
| 5401 | /* remove the bitmap */ |
| 5402 | if (!mddev->bitmap) |
| 5403 | return -ENOENT; |
| 5404 | if (mddev->bitmap->file) |
| 5405 | return -EINVAL; |
| 5406 | mddev->pers->quiesce(mddev, 1); |
| 5407 | bitmap_destroy(mddev); |
| 5408 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5409 | mddev->bitmap_info.offset = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5410 | } |
| 5411 | } |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5412 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5413 | return rv; |
| 5414 | } |
| 5415 | |
| 5416 | static int set_disk_faulty(mddev_t *mddev, dev_t dev) |
| 5417 | { |
| 5418 | mdk_rdev_t *rdev; |
| 5419 | |
| 5420 | if (mddev->pers == NULL) |
| 5421 | return -ENODEV; |
| 5422 | |
| 5423 | rdev = find_rdev(mddev, dev); |
| 5424 | if (!rdev) |
| 5425 | return -ENODEV; |
| 5426 | |
| 5427 | md_error(mddev, rdev); |
| 5428 | return 0; |
| 5429 | } |
| 5430 | |
Andre Noll | 2f9618c | 2008-04-25 18:57:58 +0200 | [diff] [blame] | 5431 | /* |
| 5432 | * We have a problem here : there is no easy way to give a CHS |
| 5433 | * virtual geometry. We currently pretend that we have a 2 heads |
| 5434 | * 4 sectors (with a BIG number of cylinders...). This drives |
| 5435 | * dosfs just mad... ;-) |
| 5436 | */ |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5437 | static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 5438 | { |
| 5439 | mddev_t *mddev = bdev->bd_disk->private_data; |
| 5440 | |
| 5441 | geo->heads = 2; |
| 5442 | geo->sectors = 4; |
| 5443 | geo->cylinders = get_capacity(mddev->gendisk) / 8; |
| 5444 | return 0; |
| 5445 | } |
| 5446 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5447 | static int md_ioctl(struct block_device *bdev, fmode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | unsigned int cmd, unsigned long arg) |
| 5449 | { |
| 5450 | int err = 0; |
| 5451 | void __user *argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | mddev_t *mddev = NULL; |
| 5453 | |
| 5454 | if (!capable(CAP_SYS_ADMIN)) |
| 5455 | return -EACCES; |
| 5456 | |
| 5457 | /* |
| 5458 | * Commands dealing with the RAID driver but not any |
| 5459 | * particular array: |
| 5460 | */ |
| 5461 | switch (cmd) |
| 5462 | { |
| 5463 | case RAID_VERSION: |
| 5464 | err = get_version(argp); |
| 5465 | goto done; |
| 5466 | |
| 5467 | case PRINT_RAID_DEBUG: |
| 5468 | err = 0; |
| 5469 | md_print_devices(); |
| 5470 | goto done; |
| 5471 | |
| 5472 | #ifndef MODULE |
| 5473 | case RAID_AUTORUN: |
| 5474 | err = 0; |
| 5475 | autostart_arrays(arg); |
| 5476 | goto done; |
| 5477 | #endif |
| 5478 | default:; |
| 5479 | } |
| 5480 | |
| 5481 | /* |
| 5482 | * Commands creating/starting a new array: |
| 5483 | */ |
| 5484 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5485 | mddev = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5486 | |
| 5487 | if (!mddev) { |
| 5488 | BUG(); |
| 5489 | goto abort; |
| 5490 | } |
| 5491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | err = mddev_lock(mddev); |
| 5493 | if (err) { |
| 5494 | printk(KERN_INFO |
| 5495 | "md: ioctl lock interrupted, reason %d, cmd %d\n", |
| 5496 | err, cmd); |
| 5497 | goto abort; |
| 5498 | } |
| 5499 | |
| 5500 | switch (cmd) |
| 5501 | { |
| 5502 | case SET_ARRAY_INFO: |
| 5503 | { |
| 5504 | mdu_array_info_t info; |
| 5505 | if (!arg) |
| 5506 | memset(&info, 0, sizeof(info)); |
| 5507 | else if (copy_from_user(&info, argp, sizeof(info))) { |
| 5508 | err = -EFAULT; |
| 5509 | goto abort_unlock; |
| 5510 | } |
| 5511 | if (mddev->pers) { |
| 5512 | err = update_array_info(mddev, &info); |
| 5513 | if (err) { |
| 5514 | printk(KERN_WARNING "md: couldn't update" |
| 5515 | " array info. %d\n", err); |
| 5516 | goto abort_unlock; |
| 5517 | } |
| 5518 | goto done_unlock; |
| 5519 | } |
| 5520 | if (!list_empty(&mddev->disks)) { |
| 5521 | printk(KERN_WARNING |
| 5522 | "md: array %s already has disks!\n", |
| 5523 | mdname(mddev)); |
| 5524 | err = -EBUSY; |
| 5525 | goto abort_unlock; |
| 5526 | } |
| 5527 | if (mddev->raid_disks) { |
| 5528 | printk(KERN_WARNING |
| 5529 | "md: array %s already initialised!\n", |
| 5530 | mdname(mddev)); |
| 5531 | err = -EBUSY; |
| 5532 | goto abort_unlock; |
| 5533 | } |
| 5534 | err = set_array_info(mddev, &info); |
| 5535 | if (err) { |
| 5536 | printk(KERN_WARNING "md: couldn't set" |
| 5537 | " array info. %d\n", err); |
| 5538 | goto abort_unlock; |
| 5539 | } |
| 5540 | } |
| 5541 | goto done_unlock; |
| 5542 | |
| 5543 | default:; |
| 5544 | } |
| 5545 | |
| 5546 | /* |
| 5547 | * Commands querying/configuring an existing array: |
| 5548 | */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5549 | /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY, |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 5550 | * RUN_ARRAY, and GET_ and SET_BITMAP_FILE are allowed */ |
NeilBrown | a17184a | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 5551 | if ((!mddev->raid_disks && !mddev->external) |
| 5552 | && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY |
| 5553 | && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE |
| 5554 | && cmd != GET_BITMAP_FILE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5555 | err = -ENODEV; |
| 5556 | goto abort_unlock; |
| 5557 | } |
| 5558 | |
| 5559 | /* |
| 5560 | * Commands even a read-only array can execute: |
| 5561 | */ |
| 5562 | switch (cmd) |
| 5563 | { |
| 5564 | case GET_ARRAY_INFO: |
| 5565 | err = get_array_info(mddev, argp); |
| 5566 | goto done_unlock; |
| 5567 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5568 | case GET_BITMAP_FILE: |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 5569 | err = get_bitmap_file(mddev, argp); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5570 | goto done_unlock; |
| 5571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5572 | case GET_DISK_INFO: |
| 5573 | err = get_disk_info(mddev, argp); |
| 5574 | goto done_unlock; |
| 5575 | |
| 5576 | case RESTART_ARRAY_RW: |
| 5577 | err = restart_array(mddev); |
| 5578 | goto done_unlock; |
| 5579 | |
| 5580 | case STOP_ARRAY: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5581 | err = do_md_stop(mddev, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5582 | goto done_unlock; |
| 5583 | |
| 5584 | case STOP_ARRAY_RO: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5585 | err = do_md_stop(mddev, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5586 | goto done_unlock; |
| 5587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5588 | } |
| 5589 | |
| 5590 | /* |
| 5591 | * The remaining ioctls are changing the state of the |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5592 | * superblock, so we do not allow them on read-only arrays. |
| 5593 | * However non-MD ioctls (e.g. get-size) will still come through |
| 5594 | * here and hit the 'default' below, so only disallow |
| 5595 | * 'md' ioctls, and switch to rw mode if started auto-readonly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5596 | */ |
Andre Noll | bb57fc6 | 2008-04-25 19:06:35 +0200 | [diff] [blame] | 5597 | if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5598 | if (mddev->ro == 2) { |
| 5599 | mddev->ro = 0; |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 5600 | sysfs_notify_dirent(mddev->sysfs_state); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 5601 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5602 | md_wakeup_thread(mddev->thread); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5603 | } else { |
| 5604 | err = -EROFS; |
| 5605 | goto abort_unlock; |
| 5606 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5607 | } |
| 5608 | |
| 5609 | switch (cmd) |
| 5610 | { |
| 5611 | case ADD_NEW_DISK: |
| 5612 | { |
| 5613 | mdu_disk_info_t info; |
| 5614 | if (copy_from_user(&info, argp, sizeof(info))) |
| 5615 | err = -EFAULT; |
| 5616 | else |
| 5617 | err = add_new_disk(mddev, &info); |
| 5618 | goto done_unlock; |
| 5619 | } |
| 5620 | |
| 5621 | case HOT_REMOVE_DISK: |
| 5622 | err = hot_remove_disk(mddev, new_decode_dev(arg)); |
| 5623 | goto done_unlock; |
| 5624 | |
| 5625 | case HOT_ADD_DISK: |
| 5626 | err = hot_add_disk(mddev, new_decode_dev(arg)); |
| 5627 | goto done_unlock; |
| 5628 | |
| 5629 | case SET_DISK_FAULTY: |
| 5630 | err = set_disk_faulty(mddev, new_decode_dev(arg)); |
| 5631 | goto done_unlock; |
| 5632 | |
| 5633 | case RUN_ARRAY: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5634 | err = do_md_run(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | goto done_unlock; |
| 5636 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5637 | case SET_BITMAP_FILE: |
| 5638 | err = set_bitmap_file(mddev, (int)arg); |
| 5639 | goto done_unlock; |
| 5640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5641 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | err = -EINVAL; |
| 5643 | goto abort_unlock; |
| 5644 | } |
| 5645 | |
| 5646 | done_unlock: |
| 5647 | abort_unlock: |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5648 | if (mddev->hold_active == UNTIL_IOCTL && |
| 5649 | err != -EINVAL) |
| 5650 | mddev->hold_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | mddev_unlock(mddev); |
| 5652 | |
| 5653 | return err; |
| 5654 | done: |
| 5655 | if (err) |
| 5656 | MD_BUG(); |
| 5657 | abort: |
| 5658 | return err; |
| 5659 | } |
| 5660 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5661 | static int md_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5662 | { |
| 5663 | /* |
| 5664 | * Succeed if we can lock the mddev, which confirms that |
| 5665 | * it isn't being stopped right now. |
| 5666 | */ |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5667 | mddev_t *mddev = mddev_find(bdev->bd_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5668 | int err; |
| 5669 | |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5670 | if (mddev->gendisk != bdev->bd_disk) { |
| 5671 | /* we are racing with mddev_put which is discarding this |
| 5672 | * bd_disk. |
| 5673 | */ |
| 5674 | mddev_put(mddev); |
| 5675 | /* Wait until bdev->bd_disk is definitely gone */ |
| 5676 | flush_scheduled_work(); |
| 5677 | /* Then retry the open from the top */ |
| 5678 | return -ERESTARTSYS; |
| 5679 | } |
| 5680 | BUG_ON(mddev != bdev->bd_disk->private_data); |
| 5681 | |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 5682 | if ((err = mutex_lock_interruptible(&mddev->open_mutex))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | goto out; |
| 5684 | |
| 5685 | err = 0; |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 5686 | atomic_inc(&mddev->openers); |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 5687 | mutex_unlock(&mddev->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5689 | check_disk_change(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5690 | out: |
| 5691 | return err; |
| 5692 | } |
| 5693 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5694 | static int md_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5695 | { |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5696 | mddev_t *mddev = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5697 | |
Eric Sesterhenn | 52e5f9d | 2006-10-03 23:33:23 +0200 | [diff] [blame] | 5698 | BUG_ON(!mddev); |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 5699 | atomic_dec(&mddev->openers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | mddev_put(mddev); |
| 5701 | |
| 5702 | return 0; |
| 5703 | } |
| 5704 | |
Linus Torvalds | 44ce629 | 2007-05-09 18:51:36 -0700 | [diff] [blame] | 5705 | static int md_media_changed(struct gendisk *disk) |
| 5706 | { |
| 5707 | mddev_t *mddev = disk->private_data; |
| 5708 | |
| 5709 | return mddev->changed; |
| 5710 | } |
| 5711 | |
| 5712 | static int md_revalidate(struct gendisk *disk) |
| 5713 | { |
| 5714 | mddev_t *mddev = disk->private_data; |
| 5715 | |
| 5716 | mddev->changed = 0; |
| 5717 | return 0; |
| 5718 | } |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 5719 | static const struct block_device_operations md_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5720 | { |
| 5721 | .owner = THIS_MODULE, |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5722 | .open = md_open, |
| 5723 | .release = md_release, |
NeilBrown | b492b85 | 2009-05-26 12:57:36 +1000 | [diff] [blame] | 5724 | .ioctl = md_ioctl, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5725 | .getgeo = md_getgeo, |
Linus Torvalds | 44ce629 | 2007-05-09 18:51:36 -0700 | [diff] [blame] | 5726 | .media_changed = md_media_changed, |
| 5727 | .revalidate_disk= md_revalidate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | }; |
| 5729 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 5730 | static int md_thread(void * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5731 | { |
| 5732 | mdk_thread_t *thread = arg; |
| 5733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5734 | /* |
| 5735 | * md_thread is a 'system-thread', it's priority should be very |
| 5736 | * high. We avoid resource deadlocks individually in each |
| 5737 | * raid personality. (RAID5 does preallocation) We also use RR and |
| 5738 | * the very same RT priority as kswapd, thus we will never get |
| 5739 | * into a priority inversion deadlock. |
| 5740 | * |
| 5741 | * we definitely have to have equal or higher priority than |
| 5742 | * bdflush, otherwise bdflush will deadlock if there are too |
| 5743 | * many dirty RAID5 blocks. |
| 5744 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 5746 | allow_signal(SIGKILL); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5747 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5748 | |
NeilBrown | 93588e2 | 2005-11-15 00:09:12 -0800 | [diff] [blame] | 5749 | /* We need to wait INTERRUPTIBLE so that |
| 5750 | * we don't add to the load-average. |
| 5751 | * That means we need to be sure no signals are |
| 5752 | * pending |
| 5753 | */ |
| 5754 | if (signal_pending(current)) |
| 5755 | flush_signals(current); |
| 5756 | |
| 5757 | wait_event_interruptible_timeout |
| 5758 | (thread->wqueue, |
| 5759 | test_bit(THREAD_WAKEUP, &thread->flags) |
| 5760 | || kthread_should_stop(), |
| 5761 | thread->timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5762 | |
| 5763 | clear_bit(THREAD_WAKEUP, &thread->flags); |
| 5764 | |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 5765 | thread->run(thread->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5766 | } |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5768 | return 0; |
| 5769 | } |
| 5770 | |
| 5771 | void md_wakeup_thread(mdk_thread_t *thread) |
| 5772 | { |
| 5773 | if (thread) { |
| 5774 | dprintk("md: waking up MD thread %s.\n", thread->tsk->comm); |
| 5775 | set_bit(THREAD_WAKEUP, &thread->flags); |
| 5776 | wake_up(&thread->wqueue); |
| 5777 | } |
| 5778 | } |
| 5779 | |
| 5780 | mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, |
| 5781 | const char *name) |
| 5782 | { |
| 5783 | mdk_thread_t *thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 5785 | thread = kzalloc(sizeof(mdk_thread_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 | if (!thread) |
| 5787 | return NULL; |
| 5788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5789 | init_waitqueue_head(&thread->wqueue); |
| 5790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5791 | thread->run = run; |
| 5792 | thread->mddev = mddev; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5793 | thread->timeout = MAX_SCHEDULE_TIMEOUT; |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5794 | thread->tsk = kthread_run(md_thread, thread, |
| 5795 | "%s_%s", |
| 5796 | mdname(thread->mddev), |
| 5797 | name ?: mddev->pers->name); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5798 | if (IS_ERR(thread->tsk)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5799 | kfree(thread); |
| 5800 | return NULL; |
| 5801 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5802 | return thread; |
| 5803 | } |
| 5804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5805 | void md_unregister_thread(mdk_thread_t *thread) |
| 5806 | { |
NeilBrown | e0cf8f0 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5807 | if (!thread) |
| 5808 | return; |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 5809 | dprintk("interrupting MD-thread pid %d\n", task_pid_nr(thread->tsk)); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5810 | |
| 5811 | kthread_stop(thread->tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5812 | kfree(thread); |
| 5813 | } |
| 5814 | |
| 5815 | void md_error(mddev_t *mddev, mdk_rdev_t *rdev) |
| 5816 | { |
| 5817 | if (!mddev) { |
| 5818 | MD_BUG(); |
| 5819 | return; |
| 5820 | } |
| 5821 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5822 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5823 | return; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 5824 | |
| 5825 | if (mddev->external) |
| 5826 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5827 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5828 | dprintk("md_error dev:%s, rdev:(%d:%d), (caller: %p,%p,%p,%p).\n", |
| 5829 | mdname(mddev), |
| 5830 | MAJOR(rdev->bdev->bd_dev), MINOR(rdev->bdev->bd_dev), |
| 5831 | __builtin_return_address(0),__builtin_return_address(1), |
| 5832 | __builtin_return_address(2),__builtin_return_address(3)); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5833 | */ |
Andrew Morton | d0a0a5e | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 5834 | if (!mddev->pers) |
| 5835 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | if (!mddev->pers->error_handler) |
| 5837 | return; |
| 5838 | mddev->pers->error_handler(mddev,rdev); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 5839 | if (mddev->degraded) |
| 5840 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 5841 | set_bit(StateChanged, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 5843 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5844 | md_wakeup_thread(mddev->thread); |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 5845 | md_new_event_inintr(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | /* seq_file implementation /proc/mdstat */ |
| 5849 | |
| 5850 | static void status_unused(struct seq_file *seq) |
| 5851 | { |
| 5852 | int i = 0; |
| 5853 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5854 | |
| 5855 | seq_printf(seq, "unused devices: "); |
| 5856 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5857 | list_for_each_entry(rdev, &pending_raid_disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | char b[BDEVNAME_SIZE]; |
| 5859 | i++; |
| 5860 | seq_printf(seq, "%s ", |
| 5861 | bdevname(rdev->bdev,b)); |
| 5862 | } |
| 5863 | if (!i) |
| 5864 | seq_printf(seq, "<none>"); |
| 5865 | |
| 5866 | seq_printf(seq, "\n"); |
| 5867 | } |
| 5868 | |
| 5869 | |
| 5870 | static void status_resync(struct seq_file *seq, mddev_t * mddev) |
| 5871 | { |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5872 | sector_t max_sectors, resync, res; |
| 5873 | unsigned long dt, db; |
| 5874 | sector_t rt; |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5875 | int scale; |
| 5876 | unsigned int per_milli; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5877 | |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5878 | resync = mddev->curr_resync - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5879 | |
| 5880 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5881 | max_sectors = mddev->resync_max_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5882 | else |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5883 | max_sectors = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5884 | |
| 5885 | /* |
| 5886 | * Should not happen. |
| 5887 | */ |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5888 | if (!max_sectors) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5889 | MD_BUG(); |
| 5890 | return; |
| 5891 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5892 | /* Pick 'scale' such that (resync>>scale)*1000 will fit |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5893 | * in a sector_t, and (max_sectors>>scale) will fit in a |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5894 | * u32, as those are the requirements for sector_div. |
| 5895 | * Thus 'scale' must be at least 10 |
| 5896 | */ |
| 5897 | scale = 10; |
| 5898 | if (sizeof(sector_t) > sizeof(unsigned long)) { |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5899 | while ( max_sectors/2 > (1ULL<<(scale+32))) |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5900 | scale++; |
| 5901 | } |
| 5902 | res = (resync>>scale)*1000; |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5903 | sector_div(res, (u32)((max_sectors>>scale)+1)); |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5904 | |
| 5905 | per_milli = res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5906 | { |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5907 | int i, x = per_milli/50, y = 20-x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5908 | seq_printf(seq, "["); |
| 5909 | for (i = 0; i < x; i++) |
| 5910 | seq_printf(seq, "="); |
| 5911 | seq_printf(seq, ">"); |
| 5912 | for (i = 0; i < y; i++) |
| 5913 | seq_printf(seq, "."); |
| 5914 | seq_printf(seq, "] "); |
| 5915 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 5916 | seq_printf(seq, " %s =%3u.%u%% (%llu/%llu)", |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 5917 | (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)? |
| 5918 | "reshape" : |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 5919 | (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)? |
| 5920 | "check" : |
| 5921 | (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ? |
| 5922 | "resync" : "recovery"))), |
| 5923 | per_milli/10, per_milli % 10, |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5924 | (unsigned long long) resync/2, |
| 5925 | (unsigned long long) max_sectors/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | |
| 5927 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5928 | * dt: time from mark until now |
| 5929 | * db: blocks written from mark until now |
| 5930 | * rt: remaining time |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5931 | * |
| 5932 | * rt is a sector_t, so could be 32bit or 64bit. |
| 5933 | * So we divide before multiply in case it is 32bit and close |
| 5934 | * to the limit. |
| 5935 | * We scale the divisor (db) by 32 to avoid loosing precision |
| 5936 | * near the end of resync when the number of remaining sectors |
| 5937 | * is close to 'db'. |
| 5938 | * We then divide rt by 32 after multiplying by db to compensate. |
| 5939 | * The '+1' avoids division by zero if db is very small. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5940 | */ |
| 5941 | dt = ((jiffies - mddev->resync_mark) / HZ); |
| 5942 | if (!dt) dt++; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 5943 | db = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active)) |
| 5944 | - mddev->resync_mark_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5945 | |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 5946 | rt = max_sectors - resync; /* number of remaining sectors */ |
| 5947 | sector_div(rt, db/32+1); |
| 5948 | rt *= dt; |
| 5949 | rt >>= 5; |
| 5950 | |
| 5951 | seq_printf(seq, " finish=%lu.%lumin", (unsigned long)rt / 60, |
| 5952 | ((unsigned long)rt % 60)/6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5953 | |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 5954 | seq_printf(seq, " speed=%ldK/sec", db/2/dt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5955 | } |
| 5956 | |
| 5957 | static void *md_seq_start(struct seq_file *seq, loff_t *pos) |
| 5958 | { |
| 5959 | struct list_head *tmp; |
| 5960 | loff_t l = *pos; |
| 5961 | mddev_t *mddev; |
| 5962 | |
| 5963 | if (l >= 0x10000) |
| 5964 | return NULL; |
| 5965 | if (!l--) |
| 5966 | /* header */ |
| 5967 | return (void*)1; |
| 5968 | |
| 5969 | spin_lock(&all_mddevs_lock); |
| 5970 | list_for_each(tmp,&all_mddevs) |
| 5971 | if (!l--) { |
| 5972 | mddev = list_entry(tmp, mddev_t, all_mddevs); |
| 5973 | mddev_get(mddev); |
| 5974 | spin_unlock(&all_mddevs_lock); |
| 5975 | return mddev; |
| 5976 | } |
| 5977 | spin_unlock(&all_mddevs_lock); |
| 5978 | if (!l--) |
| 5979 | return (void*)2;/* tail */ |
| 5980 | return NULL; |
| 5981 | } |
| 5982 | |
| 5983 | static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 5984 | { |
| 5985 | struct list_head *tmp; |
| 5986 | mddev_t *next_mddev, *mddev = v; |
| 5987 | |
| 5988 | ++*pos; |
| 5989 | if (v == (void*)2) |
| 5990 | return NULL; |
| 5991 | |
| 5992 | spin_lock(&all_mddevs_lock); |
| 5993 | if (v == (void*)1) |
| 5994 | tmp = all_mddevs.next; |
| 5995 | else |
| 5996 | tmp = mddev->all_mddevs.next; |
| 5997 | if (tmp != &all_mddevs) |
| 5998 | next_mddev = mddev_get(list_entry(tmp,mddev_t,all_mddevs)); |
| 5999 | else { |
| 6000 | next_mddev = (void*)2; |
| 6001 | *pos = 0x10000; |
| 6002 | } |
| 6003 | spin_unlock(&all_mddevs_lock); |
| 6004 | |
| 6005 | if (v != (void*)1) |
| 6006 | mddev_put(mddev); |
| 6007 | return next_mddev; |
| 6008 | |
| 6009 | } |
| 6010 | |
| 6011 | static void md_seq_stop(struct seq_file *seq, void *v) |
| 6012 | { |
| 6013 | mddev_t *mddev = v; |
| 6014 | |
| 6015 | if (mddev && v != (void*)1 && v != (void*)2) |
| 6016 | mddev_put(mddev); |
| 6017 | } |
| 6018 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6019 | struct mdstat_info { |
| 6020 | int event; |
| 6021 | }; |
| 6022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6023 | static int md_seq_show(struct seq_file *seq, void *v) |
| 6024 | { |
| 6025 | mddev_t *mddev = v; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6026 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6027 | mdk_rdev_t *rdev; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6028 | struct mdstat_info *mi = seq->private; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6029 | struct bitmap *bitmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6030 | |
| 6031 | if (v == (void*)1) { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6032 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6033 | seq_printf(seq, "Personalities : "); |
| 6034 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6035 | list_for_each_entry(pers, &pers_list, list) |
| 6036 | seq_printf(seq, "[%s] ", pers->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6037 | |
| 6038 | spin_unlock(&pers_lock); |
| 6039 | seq_printf(seq, "\n"); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6040 | mi->event = atomic_read(&md_event_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6041 | return 0; |
| 6042 | } |
| 6043 | if (v == (void*)2) { |
| 6044 | status_unused(seq); |
| 6045 | return 0; |
| 6046 | } |
| 6047 | |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 6048 | if (mddev_lock(mddev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6049 | return -EINTR; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 6050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6051 | if (mddev->pers || mddev->raid_disks || !list_empty(&mddev->disks)) { |
| 6052 | seq_printf(seq, "%s : %sactive", mdname(mddev), |
| 6053 | mddev->pers ? "" : "in"); |
| 6054 | if (mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6055 | if (mddev->ro==1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6056 | seq_printf(seq, " (read-only)"); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6057 | if (mddev->ro==2) |
NeilBrown | 52720ae | 2008-03-10 11:43:47 -0700 | [diff] [blame] | 6058 | seq_printf(seq, " (auto-read-only)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6059 | seq_printf(seq, " %s", mddev->pers->name); |
| 6060 | } |
| 6061 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6062 | sectors = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6063 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6064 | char b[BDEVNAME_SIZE]; |
| 6065 | seq_printf(seq, " %s[%d]", |
| 6066 | bdevname(rdev->bdev,b), rdev->desc_nr); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 6067 | if (test_bit(WriteMostly, &rdev->flags)) |
| 6068 | seq_printf(seq, "(W)"); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6069 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6070 | seq_printf(seq, "(F)"); |
| 6071 | continue; |
NeilBrown | b325a32 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6072 | } else if (rdev->raid_disk < 0) |
| 6073 | seq_printf(seq, "(S)"); /* spare */ |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6074 | sectors += rdev->sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | if (!list_empty(&mddev->disks)) { |
| 6078 | if (mddev->pers) |
| 6079 | seq_printf(seq, "\n %llu blocks", |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 6080 | (unsigned long long) |
| 6081 | mddev->array_sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6082 | else |
| 6083 | seq_printf(seq, "\n %llu blocks", |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6084 | (unsigned long long)sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6085 | } |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6086 | if (mddev->persistent) { |
| 6087 | if (mddev->major_version != 0 || |
| 6088 | mddev->minor_version != 90) { |
| 6089 | seq_printf(seq," super %d.%d", |
| 6090 | mddev->major_version, |
| 6091 | mddev->minor_version); |
| 6092 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 6093 | } else if (mddev->external) |
| 6094 | seq_printf(seq, " super external:%s", |
| 6095 | mddev->metadata_type); |
| 6096 | else |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6097 | seq_printf(seq, " super non-persistent"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6098 | |
| 6099 | if (mddev->pers) { |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6100 | mddev->pers->status(seq, mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6101 | seq_printf(seq, "\n "); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 6102 | if (mddev->pers->sync_request) { |
| 6103 | if (mddev->curr_resync > 2) { |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6104 | status_resync(seq, mddev); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 6105 | seq_printf(seq, "\n "); |
| 6106 | } else if (mddev->curr_resync == 1 || mddev->curr_resync == 2) |
| 6107 | seq_printf(seq, "\tresync=DELAYED\n "); |
| 6108 | else if (mddev->recovery_cp < MaxSector) |
| 6109 | seq_printf(seq, "\tresync=PENDING\n "); |
| 6110 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6111 | } else |
| 6112 | seq_printf(seq, "\n "); |
| 6113 | |
| 6114 | if ((bitmap = mddev->bitmap)) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6115 | unsigned long chunk_kb; |
| 6116 | unsigned long flags; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6117 | spin_lock_irqsave(&bitmap->lock, flags); |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 6118 | chunk_kb = mddev->bitmap_info.chunksize >> 10; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6119 | seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], " |
| 6120 | "%lu%s chunk", |
| 6121 | bitmap->pages - bitmap->missing_pages, |
| 6122 | bitmap->pages, |
| 6123 | (bitmap->pages - bitmap->missing_pages) |
| 6124 | << (PAGE_SHIFT - 10), |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 6125 | chunk_kb ? chunk_kb : mddev->bitmap_info.chunksize, |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6126 | chunk_kb ? "KB" : "B"); |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 6127 | if (bitmap->file) { |
| 6128 | seq_printf(seq, ", file: "); |
Jan Blunck | c32c2f6 | 2008-02-14 19:38:43 -0800 | [diff] [blame] | 6129 | seq_path(seq, &bitmap->file->f_path, " \t\n"); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6130 | } |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 6131 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6132 | seq_printf(seq, "\n"); |
| 6133 | spin_unlock_irqrestore(&bitmap->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | seq_printf(seq, "\n"); |
| 6137 | } |
| 6138 | mddev_unlock(mddev); |
| 6139 | |
| 6140 | return 0; |
| 6141 | } |
| 6142 | |
Jan Engelhardt | 110518b | 2009-05-07 12:49:37 +1000 | [diff] [blame] | 6143 | static const struct seq_operations md_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | .start = md_seq_start, |
| 6145 | .next = md_seq_next, |
| 6146 | .stop = md_seq_stop, |
| 6147 | .show = md_seq_show, |
| 6148 | }; |
| 6149 | |
| 6150 | static int md_seq_open(struct inode *inode, struct file *file) |
| 6151 | { |
| 6152 | int error; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6153 | struct mdstat_info *mi = kmalloc(sizeof(*mi), GFP_KERNEL); |
| 6154 | if (mi == NULL) |
| 6155 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6156 | |
| 6157 | error = seq_open(file, &md_seq_ops); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6158 | if (error) |
| 6159 | kfree(mi); |
| 6160 | else { |
| 6161 | struct seq_file *p = file->private_data; |
| 6162 | p->private = mi; |
| 6163 | mi->event = atomic_read(&md_event_count); |
| 6164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6165 | return error; |
| 6166 | } |
| 6167 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6168 | static unsigned int mdstat_poll(struct file *filp, poll_table *wait) |
| 6169 | { |
| 6170 | struct seq_file *m = filp->private_data; |
| 6171 | struct mdstat_info *mi = m->private; |
| 6172 | int mask; |
| 6173 | |
| 6174 | poll_wait(filp, &md_event_waiters, wait); |
| 6175 | |
| 6176 | /* always allow read */ |
| 6177 | mask = POLLIN | POLLRDNORM; |
| 6178 | |
| 6179 | if (mi->event != atomic_read(&md_event_count)) |
| 6180 | mask |= POLLERR | POLLPRI; |
| 6181 | return mask; |
| 6182 | } |
| 6183 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 6184 | static const struct file_operations md_seq_fops = { |
Akinobu Mita | e24650c | 2006-10-17 00:09:38 -0700 | [diff] [blame] | 6185 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6186 | .open = md_seq_open, |
| 6187 | .read = seq_read, |
| 6188 | .llseek = seq_lseek, |
Martin Peschke | c3f94b40 | 2007-05-09 02:35:35 -0700 | [diff] [blame] | 6189 | .release = seq_release_private, |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6190 | .poll = mdstat_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6191 | }; |
| 6192 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6193 | int register_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6194 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6195 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6196 | list_add_tail(&p->list, &pers_list); |
| 6197 | 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] | 6198 | spin_unlock(&pers_lock); |
| 6199 | return 0; |
| 6200 | } |
| 6201 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6202 | int unregister_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6203 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6204 | printk(KERN_INFO "md: %s personality unregistered\n", p->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6206 | list_del_init(&p->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6207 | spin_unlock(&pers_lock); |
| 6208 | return 0; |
| 6209 | } |
| 6210 | |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6211 | static int is_mddev_idle(mddev_t *mddev, int init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6212 | { |
| 6213 | mdk_rdev_t * rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6214 | int idle; |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6215 | int curr_events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6216 | |
| 6217 | idle = 1; |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 6218 | rcu_read_lock(); |
| 6219 | rdev_for_each_rcu(rdev, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6220 | struct gendisk *disk = rdev->bdev->bd_contains->bd_disk; |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6221 | curr_events = (int)part_stat_read(&disk->part0, sectors[0]) + |
| 6222 | (int)part_stat_read(&disk->part0, sectors[1]) - |
| 6223 | atomic_read(&disk->sync_io); |
NeilBrown | 713f6ab | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 6224 | /* sync IO will cause sync_io to increase before the disk_stats |
| 6225 | * as sync_io is counted when a request starts, and |
| 6226 | * disk_stats is counted when it completes. |
| 6227 | * So resync activity will cause curr_events to be smaller than |
| 6228 | * when there was no such activity. |
| 6229 | * non-sync IO will cause disk_stat to increase without |
| 6230 | * increasing sync_io so curr_events will (eventually) |
| 6231 | * be larger than it was before. Once it becomes |
| 6232 | * substantially larger, the test below will cause |
| 6233 | * the array to appear non-idle, and resync will slow |
| 6234 | * down. |
| 6235 | * If there is a lot of outstanding resync activity when |
| 6236 | * we set last_event to curr_events, then all that activity |
| 6237 | * completing might cause the array to appear non-idle |
| 6238 | * and resync will be slowed down even though there might |
| 6239 | * not have been non-resync activity. This will only |
| 6240 | * happen once though. 'last_events' will soon reflect |
| 6241 | * the state where there is little or no outstanding |
| 6242 | * resync requests, and further resync activity will |
| 6243 | * always make curr_events less than last_events. |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 6244 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6245 | */ |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6246 | if (init || curr_events - rdev->last_events > 64) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6247 | rdev->last_events = curr_events; |
| 6248 | idle = 0; |
| 6249 | } |
| 6250 | } |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 6251 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6252 | return idle; |
| 6253 | } |
| 6254 | |
| 6255 | void md_done_sync(mddev_t *mddev, int blocks, int ok) |
| 6256 | { |
| 6257 | /* another "blocks" (512byte) blocks have been synced */ |
| 6258 | atomic_sub(blocks, &mddev->recovery_active); |
| 6259 | wake_up(&mddev->recovery_wait); |
| 6260 | if (!ok) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6261 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6262 | md_wakeup_thread(mddev->thread); |
| 6263 | // stop recovery, signal do_sync .... |
| 6264 | } |
| 6265 | } |
| 6266 | |
| 6267 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6268 | /* md_write_start(mddev, bi) |
| 6269 | * If we need to update some array metadata (e.g. 'active' flag |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6270 | * in superblock) before writing, schedule a superblock update |
| 6271 | * and wait for it to complete. |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6272 | */ |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6273 | void md_write_start(mddev_t *mddev, struct bio *bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6274 | { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6275 | int did_change = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6276 | if (bio_data_dir(bi) != WRITE) |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6277 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6278 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6279 | BUG_ON(mddev->ro == 1); |
| 6280 | if (mddev->ro == 2) { |
| 6281 | /* need to switch to read/write */ |
| 6282 | mddev->ro = 0; |
| 6283 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6284 | md_wakeup_thread(mddev->thread); |
NeilBrown | 2515619 | 2008-03-04 14:29:32 -0800 | [diff] [blame] | 6285 | md_wakeup_thread(mddev->sync_thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6286 | did_change = 1; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6287 | } |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6288 | atomic_inc(&mddev->writes_pending); |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6289 | if (mddev->safemode == 1) |
| 6290 | mddev->safemode = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6291 | if (mddev->in_sync) { |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 6292 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6293 | if (mddev->in_sync) { |
| 6294 | mddev->in_sync = 0; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6295 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6296 | md_wakeup_thread(mddev->thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6297 | did_change = 1; |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6298 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 6299 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6300 | } |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6301 | if (did_change) |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 6302 | sysfs_notify_dirent(mddev->sysfs_state); |
NeilBrown | 09a44cc | 2008-05-23 13:04:36 -0700 | [diff] [blame] | 6303 | wait_event(mddev->sb_wait, |
| 6304 | !test_bit(MD_CHANGE_CLEAN, &mddev->flags) && |
| 6305 | !test_bit(MD_CHANGE_PENDING, &mddev->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6306 | } |
| 6307 | |
| 6308 | void md_write_end(mddev_t *mddev) |
| 6309 | { |
| 6310 | if (atomic_dec_and_test(&mddev->writes_pending)) { |
| 6311 | if (mddev->safemode == 2) |
| 6312 | md_wakeup_thread(mddev->thread); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 6313 | else if (mddev->safemode_delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6314 | mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay); |
| 6315 | } |
| 6316 | } |
| 6317 | |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6318 | /* md_allow_write(mddev) |
| 6319 | * Calling this ensures that the array is marked 'active' so that writes |
| 6320 | * may proceed without blocking. It is important to call this before |
| 6321 | * attempting a GFP_KERNEL allocation while holding the mddev lock. |
| 6322 | * Must be called with mddev_lock held. |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6323 | * |
| 6324 | * In the ->external case MD_CHANGE_CLEAN can not be cleared until mddev->lock |
| 6325 | * is dropped, so return -EAGAIN after notifying userspace. |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6326 | */ |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6327 | int md_allow_write(mddev_t *mddev) |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6328 | { |
| 6329 | if (!mddev->pers) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6330 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6331 | if (mddev->ro) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6332 | return 0; |
Neil Brown | 1a0fd49 | 2008-06-28 08:31:27 +1000 | [diff] [blame] | 6333 | if (!mddev->pers->sync_request) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6334 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6335 | |
| 6336 | spin_lock_irq(&mddev->write_lock); |
| 6337 | if (mddev->in_sync) { |
| 6338 | mddev->in_sync = 0; |
| 6339 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
| 6340 | if (mddev->safemode_delay && |
| 6341 | mddev->safemode == 0) |
| 6342 | mddev->safemode = 1; |
| 6343 | spin_unlock_irq(&mddev->write_lock); |
| 6344 | md_update_sb(mddev, 0); |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 6345 | sysfs_notify_dirent(mddev->sysfs_state); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6346 | } else |
| 6347 | spin_unlock_irq(&mddev->write_lock); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6348 | |
| 6349 | if (test_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 6350 | return -EAGAIN; |
| 6351 | else |
| 6352 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6353 | } |
| 6354 | EXPORT_SYMBOL_GPL(md_allow_write); |
| 6355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6356 | #define SYNC_MARKS 10 |
| 6357 | #define SYNC_MARK_STEP (3*HZ) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6358 | void md_do_sync(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6359 | { |
| 6360 | mddev_t *mddev2; |
| 6361 | unsigned int currspeed = 0, |
| 6362 | window; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6363 | sector_t max_sectors,j, io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6364 | unsigned long mark[SYNC_MARKS]; |
| 6365 | sector_t mark_cnt[SYNC_MARKS]; |
| 6366 | int last_mark,m; |
| 6367 | struct list_head *tmp; |
| 6368 | sector_t last_check; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6369 | int skipped = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6370 | mdk_rdev_t *rdev; |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6371 | char *desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6372 | |
| 6373 | /* just incase thread restarts... */ |
| 6374 | if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) |
| 6375 | return; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6376 | if (mddev->ro) /* never try to sync a read-only array */ |
| 6377 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6378 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6379 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 6380 | if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 6381 | desc = "data-check"; |
| 6382 | else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6383 | desc = "requested-resync"; |
| 6384 | else |
| 6385 | desc = "resync"; |
| 6386 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 6387 | desc = "reshape"; |
| 6388 | else |
| 6389 | desc = "recovery"; |
| 6390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6391 | /* we overload curr_resync somewhat here. |
| 6392 | * 0 == not engaged in resync at all |
| 6393 | * 2 == checking that there is no conflict with another sync |
| 6394 | * 1 == like 2, but have yielded to allow conflicting resync to |
| 6395 | * commense |
| 6396 | * other == active in resync - this many blocks |
| 6397 | * |
| 6398 | * Before starting a resync we must have set curr_resync to |
| 6399 | * 2, and then checked that every "conflicting" array has curr_resync |
| 6400 | * less than ours. When we find one that is the same or higher |
| 6401 | * we wait on resync_wait. To avoid deadlock, we reduce curr_resync |
| 6402 | * to 1 if we choose to yield (based arbitrarily on address of mddev structure). |
| 6403 | * This will mean we have to start checking from the beginning again. |
| 6404 | * |
| 6405 | */ |
| 6406 | |
| 6407 | do { |
| 6408 | mddev->curr_resync = 2; |
| 6409 | |
| 6410 | try_again: |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 6411 | if (kthread_should_stop()) { |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 6412 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6413 | goto skip; |
| 6414 | } |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 6415 | for_each_mddev(mddev2, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6416 | if (mddev2 == mddev) |
| 6417 | continue; |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 6418 | if (!mddev->parallel_resync |
| 6419 | && mddev2->curr_resync |
| 6420 | && match_mddev_units(mddev, mddev2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6421 | DEFINE_WAIT(wq); |
| 6422 | if (mddev < mddev2 && mddev->curr_resync == 2) { |
| 6423 | /* arbitrarily yield */ |
| 6424 | mddev->curr_resync = 1; |
| 6425 | wake_up(&resync_wait); |
| 6426 | } |
| 6427 | if (mddev > mddev2 && mddev->curr_resync == 1) |
| 6428 | /* no need to wait here, we can wait the next |
| 6429 | * time 'round when curr_resync == 2 |
| 6430 | */ |
| 6431 | continue; |
NeilBrown | 9744197 | 2008-09-19 11:49:54 +1000 | [diff] [blame] | 6432 | /* We need to wait 'interruptible' so as not to |
| 6433 | * contribute to the load average, and not to |
| 6434 | * be caught by 'softlockup' |
| 6435 | */ |
| 6436 | prepare_to_wait(&resync_wait, &wq, TASK_INTERRUPTIBLE); |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 6437 | if (!kthread_should_stop() && |
NeilBrown | 8712e55 | 2005-10-26 01:58:58 -0700 | [diff] [blame] | 6438 | mddev2->curr_resync >= mddev->curr_resync) { |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6439 | printk(KERN_INFO "md: delaying %s of %s" |
| 6440 | " until %s has finished (they" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6441 | " share one or more physical units)\n", |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6442 | desc, mdname(mddev), mdname(mddev2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6443 | mddev_put(mddev2); |
NeilBrown | 9744197 | 2008-09-19 11:49:54 +1000 | [diff] [blame] | 6444 | if (signal_pending(current)) |
| 6445 | flush_signals(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6446 | schedule(); |
| 6447 | finish_wait(&resync_wait, &wq); |
| 6448 | goto try_again; |
| 6449 | } |
| 6450 | finish_wait(&resync_wait, &wq); |
| 6451 | } |
| 6452 | } |
| 6453 | } while (mddev->curr_resync < 2); |
| 6454 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6455 | j = 0; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6456 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6457 | /* resync follows the size requested by the personality, |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6458 | * which defaults to physical size, but can be virtual size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6459 | */ |
| 6460 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6461 | mddev->resync_mismatches = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6462 | /* we don't use the checkpoint if there's a bitmap */ |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 6463 | if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6464 | j = mddev->resync_min; |
| 6465 | else if (!mddev->bitmap) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6466 | j = mddev->recovery_cp; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 6467 | |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 6468 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6469 | max_sectors = mddev->dev_sectors; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6470 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6471 | /* recovery follows the physical size of devices */ |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6472 | max_sectors = mddev->dev_sectors; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6473 | j = MaxSector; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6474 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6475 | if (rdev->raid_disk >= 0 && |
| 6476 | !test_bit(Faulty, &rdev->flags) && |
| 6477 | !test_bit(In_sync, &rdev->flags) && |
| 6478 | rdev->recovery_offset < j) |
| 6479 | j = rdev->recovery_offset; |
| 6480 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6481 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6482 | printk(KERN_INFO "md: %s of RAID array %s\n", desc, mdname(mddev)); |
| 6483 | printk(KERN_INFO "md: minimum _guaranteed_ speed:" |
| 6484 | " %d KB/sec/disk.\n", speed_min(mddev)); |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 6485 | printk(KERN_INFO "md: using maximum available idle IO bandwidth " |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6486 | "(but not more than %d KB/sec) for %s.\n", |
| 6487 | speed_max(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6488 | |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6489 | is_mddev_idle(mddev, 1); /* this initializes IO event counters */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6490 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6491 | io_sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6492 | for (m = 0; m < SYNC_MARKS; m++) { |
| 6493 | mark[m] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6494 | mark_cnt[m] = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6495 | } |
| 6496 | last_mark = 0; |
| 6497 | mddev->resync_mark = mark[last_mark]; |
| 6498 | mddev->resync_mark_cnt = mark_cnt[last_mark]; |
| 6499 | |
| 6500 | /* |
| 6501 | * Tune reconstruction: |
| 6502 | */ |
| 6503 | window = 32*(PAGE_SIZE/512); |
| 6504 | printk(KERN_INFO "md: using %dk window, over a total of %llu blocks.\n", |
| 6505 | window/2,(unsigned long long) max_sectors/2); |
| 6506 | |
| 6507 | atomic_set(&mddev->recovery_active, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6508 | last_check = 0; |
| 6509 | |
| 6510 | if (j>2) { |
| 6511 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6512 | "md: resuming %s of %s from checkpoint.\n", |
| 6513 | desc, mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6514 | mddev->curr_resync = j; |
| 6515 | } |
NeilBrown | efa5933 | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 6516 | mddev->curr_resync_completed = mddev->curr_resync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6517 | |
| 6518 | while (j < max_sectors) { |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6519 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6520 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6521 | skipped = 0; |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6522 | |
NeilBrown | 7a91ee1 | 2009-05-26 12:57:21 +1000 | [diff] [blame] | 6523 | if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && |
| 6524 | ((mddev->curr_resync > mddev->curr_resync_completed && |
| 6525 | (mddev->curr_resync - mddev->curr_resync_completed) |
| 6526 | > (max_sectors >> 4)) || |
| 6527 | (j - mddev->curr_resync_completed)*2 |
| 6528 | >= mddev->resync_max - mddev->curr_resync_completed |
| 6529 | )) { |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6530 | /* time to update curr_resync_completed */ |
| 6531 | blk_unplug(mddev->queue); |
| 6532 | wait_event(mddev->recovery_wait, |
| 6533 | atomic_read(&mddev->recovery_active) == 0); |
| 6534 | mddev->curr_resync_completed = |
| 6535 | mddev->curr_resync; |
| 6536 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6537 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6538 | } |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6539 | |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 6540 | while (j >= mddev->resync_max && !kthread_should_stop()) { |
| 6541 | /* As this condition is controlled by user-space, |
| 6542 | * we can block indefinitely, so use '_interruptible' |
| 6543 | * to avoid triggering warnings. |
| 6544 | */ |
| 6545 | flush_signals(current); /* just in case */ |
| 6546 | wait_event_interruptible(mddev->recovery_wait, |
| 6547 | mddev->resync_max > j |
| 6548 | || kthread_should_stop()); |
| 6549 | } |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6550 | |
| 6551 | if (kthread_should_stop()) |
| 6552 | goto interrupted; |
| 6553 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6554 | sectors = mddev->pers->sync_request(mddev, j, &skipped, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6555 | currspeed < speed_min(mddev)); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6556 | if (sectors == 0) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6557 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6558 | goto out; |
| 6559 | } |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6560 | |
| 6561 | if (!skipped) { /* actual IO requested */ |
| 6562 | io_sectors += sectors; |
| 6563 | atomic_add(sectors, &mddev->recovery_active); |
| 6564 | } |
| 6565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | j += sectors; |
| 6567 | if (j>1) mddev->curr_resync = j; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6568 | mddev->curr_mark_cnt = io_sectors; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6569 | if (last_check == 0) |
| 6570 | /* this is the earliers that rebuilt will be |
| 6571 | * visible in /proc/mdstat |
| 6572 | */ |
| 6573 | md_new_event(mddev); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6574 | |
| 6575 | if (last_check + window > io_sectors || j == max_sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6576 | continue; |
| 6577 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6578 | last_check = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6579 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6580 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6581 | break; |
| 6582 | |
| 6583 | repeat: |
| 6584 | if (time_after_eq(jiffies, mark[last_mark] + SYNC_MARK_STEP )) { |
| 6585 | /* step marks */ |
| 6586 | int next = (last_mark+1) % SYNC_MARKS; |
| 6587 | |
| 6588 | mddev->resync_mark = mark[next]; |
| 6589 | mddev->resync_mark_cnt = mark_cnt[next]; |
| 6590 | mark[next] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6591 | mark_cnt[next] = io_sectors - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6592 | last_mark = next; |
| 6593 | } |
| 6594 | |
| 6595 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6596 | if (kthread_should_stop()) |
| 6597 | goto interrupted; |
| 6598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6599 | |
| 6600 | /* |
| 6601 | * this loop exits only if either when we are slower than |
| 6602 | * the 'hard' speed limit, or the system was IO-idle for |
| 6603 | * a jiffy. |
| 6604 | * the system might be non-idle CPU-wise, but we only care |
| 6605 | * about not overloading the IO subsystem. (things like an |
| 6606 | * e2fsck being done on the RAID array should execute fast) |
| 6607 | */ |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 6608 | blk_unplug(mddev->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6609 | cond_resched(); |
| 6610 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6611 | currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2 |
| 6612 | /((jiffies-mddev->resync_mark)/HZ +1) +1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6613 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 6614 | if (currspeed > speed_min(mddev)) { |
| 6615 | if ((currspeed > speed_max(mddev)) || |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6616 | !is_mddev_idle(mddev, 0)) { |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 6617 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6618 | goto repeat; |
| 6619 | } |
| 6620 | } |
| 6621 | } |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6622 | printk(KERN_INFO "md: %s: %s done.\n",mdname(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6623 | /* |
| 6624 | * this also signals 'finished resyncing' to md_stop |
| 6625 | */ |
| 6626 | out: |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 6627 | blk_unplug(mddev->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6628 | |
| 6629 | wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); |
| 6630 | |
| 6631 | /* tell personality that we are finished */ |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6632 | mddev->pers->sync_request(mddev, max_sectors, &skipped, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6633 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6634 | if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) && |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6635 | mddev->curr_resync > 2) { |
| 6636 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 6637 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6638 | if (mddev->curr_resync >= mddev->recovery_cp) { |
| 6639 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6640 | "md: checkpointing %s of %s.\n", |
| 6641 | desc, mdname(mddev)); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6642 | mddev->recovery_cp = mddev->curr_resync; |
| 6643 | } |
| 6644 | } else |
| 6645 | mddev->recovery_cp = MaxSector; |
| 6646 | } else { |
| 6647 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 6648 | mddev->curr_resync = MaxSector; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6649 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6650 | if (rdev->raid_disk >= 0 && |
| 6651 | !test_bit(Faulty, &rdev->flags) && |
| 6652 | !test_bit(In_sync, &rdev->flags) && |
| 6653 | rdev->recovery_offset < mddev->curr_resync) |
| 6654 | rdev->recovery_offset = mddev->curr_resync; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6655 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6656 | } |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 6657 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6659 | skip: |
NeilBrown | c07b70a | 2009-12-14 12:49:48 +1100 | [diff] [blame] | 6660 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6661 | /* We completed so min/max setting can be forgotten if used. */ |
| 6662 | if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6663 | mddev->resync_min = 0; |
| 6664 | mddev->resync_max = MaxSector; |
| 6665 | } else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6666 | mddev->resync_min = mddev->curr_resync_completed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6667 | mddev->curr_resync = 0; |
NeilBrown | efa5933 | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 6668 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 6669 | mddev->curr_resync_completed = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6670 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6671 | wake_up(&resync_wait); |
| 6672 | set_bit(MD_RECOVERY_DONE, &mddev->recovery); |
| 6673 | md_wakeup_thread(mddev->thread); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6674 | return; |
| 6675 | |
| 6676 | interrupted: |
| 6677 | /* |
| 6678 | * got a signal, exit. |
| 6679 | */ |
| 6680 | printk(KERN_INFO |
| 6681 | "md: md_do_sync() got signal ... exiting\n"); |
| 6682 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 6683 | goto out; |
| 6684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6685 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6686 | EXPORT_SYMBOL_GPL(md_do_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6687 | |
| 6688 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6689 | static int remove_and_add_spares(mddev_t *mddev) |
| 6690 | { |
| 6691 | mdk_rdev_t *rdev; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6692 | int spares = 0; |
| 6693 | |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6694 | mddev->curr_resync_completed = 0; |
| 6695 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6696 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6697 | if (rdev->raid_disk >= 0 && |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 6698 | !test_bit(Blocked, &rdev->flags) && |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6699 | (test_bit(Faulty, &rdev->flags) || |
| 6700 | ! test_bit(In_sync, &rdev->flags)) && |
| 6701 | atomic_read(&rdev->nr_pending)==0) { |
| 6702 | if (mddev->pers->hot_remove_disk( |
| 6703 | mddev, rdev->raid_disk)==0) { |
| 6704 | char nm[20]; |
| 6705 | sprintf(nm,"rd%d", rdev->raid_disk); |
| 6706 | sysfs_remove_link(&mddev->kobj, nm); |
| 6707 | rdev->raid_disk = -1; |
| 6708 | } |
| 6709 | } |
| 6710 | |
NeilBrown | 4044ba5 | 2009-01-09 08:31:11 +1100 | [diff] [blame] | 6711 | if (mddev->degraded && ! mddev->ro && !mddev->recovery_disabled) { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6712 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6713 | if (rdev->raid_disk >= 0 && |
Dan Williams | e542713 | 2008-07-28 23:28:06 -0700 | [diff] [blame] | 6714 | !test_bit(In_sync, &rdev->flags) && |
| 6715 | !test_bit(Blocked, &rdev->flags)) |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6716 | spares++; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6717 | if (rdev->raid_disk < 0 |
| 6718 | && !test_bit(Faulty, &rdev->flags)) { |
| 6719 | rdev->recovery_offset = 0; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 6720 | if (mddev->pers-> |
| 6721 | hot_add_disk(mddev, rdev) == 0) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6722 | char nm[20]; |
| 6723 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 6724 | if (sysfs_create_link(&mddev->kobj, |
| 6725 | &rdev->kobj, nm)) |
| 6726 | printk(KERN_WARNING |
| 6727 | "md: cannot register " |
| 6728 | "%s for %s\n", |
| 6729 | nm, mdname(mddev)); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6730 | spares++; |
| 6731 | md_new_event(mddev); |
| 6732 | } else |
| 6733 | break; |
| 6734 | } |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6735 | } |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6736 | } |
| 6737 | return spares; |
| 6738 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6739 | /* |
| 6740 | * This routine is regularly called by all per-raid-array threads to |
| 6741 | * deal with generic issues like resync and super-block update. |
| 6742 | * Raid personalities that don't have a thread (linear/raid0) do not |
| 6743 | * need this as they never do any recovery or update the superblock. |
| 6744 | * |
| 6745 | * It does not do any resync itself, but rather "forks" off other threads |
| 6746 | * to do that as needed. |
| 6747 | * When it is determined that resync is needed, we set MD_RECOVERY_RUNNING in |
| 6748 | * "->recovery" and create a thread at ->sync_thread. |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6749 | * When the thread finishes it sets MD_RECOVERY_DONE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6750 | * and wakeups up this thread which will reap the thread and finish up. |
| 6751 | * This thread also removes any faulty devices (with nr_pending == 0). |
| 6752 | * |
| 6753 | * The overall approach is: |
| 6754 | * 1/ if the superblock needs updating, update it. |
| 6755 | * 2/ If a recovery thread is running, don't do anything else. |
| 6756 | * 3/ If recovery has finished, clean up, possibly marking spares active. |
| 6757 | * 4/ If there are any faulty devices, remove them. |
| 6758 | * 5/ If array is degraded, try to add spares devices |
| 6759 | * 6/ If array has spares or is not in-sync, start a resync thread. |
| 6760 | */ |
| 6761 | void md_check_recovery(mddev_t *mddev) |
| 6762 | { |
| 6763 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6764 | |
| 6765 | |
NeilBrown | 5f40402 | 2005-06-21 17:17:16 -0700 | [diff] [blame] | 6766 | if (mddev->bitmap) |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 6767 | bitmap_daemon_work(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6768 | |
| 6769 | if (mddev->ro) |
| 6770 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6771 | |
| 6772 | if (signal_pending(current)) { |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6773 | if (mddev->pers->sync_request && !mddev->external) { |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6774 | printk(KERN_INFO "md: %s in immediate safe mode\n", |
| 6775 | mdname(mddev)); |
| 6776 | mddev->safemode = 2; |
| 6777 | } |
| 6778 | flush_signals(current); |
| 6779 | } |
| 6780 | |
NeilBrown | c89a8ee | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 6781 | if (mddev->ro && !test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
| 6782 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6783 | if ( ! ( |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 6784 | (mddev->flags && !mddev->external) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6785 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6786 | test_bit(MD_RECOVERY_DONE, &mddev->recovery) || |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6787 | (mddev->external == 0 && mddev->safemode == 1) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6788 | (mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending) |
| 6789 | && !mddev->in_sync && mddev->recovery_cp == MaxSector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6790 | )) |
| 6791 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6792 | |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 6793 | if (mddev_trylock(mddev)) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6794 | int spares = 0; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6795 | |
NeilBrown | c89a8ee | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 6796 | if (mddev->ro) { |
| 6797 | /* Only thing we do on a ro array is remove |
| 6798 | * failed devices. |
| 6799 | */ |
| 6800 | remove_and_add_spares(mddev); |
| 6801 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6802 | goto unlock; |
| 6803 | } |
| 6804 | |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6805 | if (!mddev->external) { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6806 | int did_change = 0; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6807 | spin_lock_irq(&mddev->write_lock); |
| 6808 | if (mddev->safemode && |
| 6809 | !atomic_read(&mddev->writes_pending) && |
| 6810 | !mddev->in_sync && |
| 6811 | mddev->recovery_cp == MaxSector) { |
| 6812 | mddev->in_sync = 1; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6813 | did_change = 1; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6814 | if (mddev->persistent) |
| 6815 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
| 6816 | } |
| 6817 | if (mddev->safemode == 1) |
| 6818 | mddev->safemode = 0; |
| 6819 | spin_unlock_irq(&mddev->write_lock); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6820 | if (did_change) |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 6821 | sysfs_notify_dirent(mddev->sysfs_state); |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6822 | } |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6823 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6824 | if (mddev->flags) |
| 6825 | md_update_sb(mddev, 0); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6826 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6827 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 6828 | if (test_and_clear_bit(StateChanged, &rdev->flags)) |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 6829 | sysfs_notify_dirent(rdev->sysfs_state); |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 6830 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6832 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && |
| 6833 | !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) { |
| 6834 | /* resync/recovery still happening */ |
| 6835 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6836 | goto unlock; |
| 6837 | } |
| 6838 | if (mddev->sync_thread) { |
| 6839 | /* resync has finished, collect result */ |
| 6840 | md_unregister_thread(mddev->sync_thread); |
| 6841 | mddev->sync_thread = NULL; |
Dan Williams | 56ac36d | 2008-08-07 10:02:47 -0700 | [diff] [blame] | 6842 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery) && |
| 6843 | !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6844 | /* success...*/ |
| 6845 | /* activate any spares */ |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 6846 | if (mddev->pers->spare_active(mddev)) |
| 6847 | sysfs_notify(&mddev->kobj, NULL, |
| 6848 | "degraded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6849 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6850 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && |
| 6851 | mddev->pers->finish_reshape) |
| 6852 | mddev->pers->finish_reshape(mddev); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6853 | md_update_sb(mddev, 1); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 6854 | |
| 6855 | /* if array is no-longer degraded, then any saved_raid_disk |
| 6856 | * information must be scrapped |
| 6857 | */ |
| 6858 | if (!mddev->degraded) |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6859 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 6860 | rdev->saved_raid_disk = -1; |
| 6861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6862 | mddev->recovery = 0; |
| 6863 | /* flag recovery needed just to double check */ |
| 6864 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 0c3573f | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 6865 | sysfs_notify_dirent(mddev->sysfs_action); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6866 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6867 | goto unlock; |
| 6868 | } |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6869 | /* Set RUNNING before clearing NEEDED to avoid |
| 6870 | * any transients in the value of "sync_action". |
| 6871 | */ |
| 6872 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 6873 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6874 | /* Clear some bits that don't mean anything, but |
| 6875 | * might be left set |
| 6876 | */ |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6877 | clear_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 6878 | clear_bit(MD_RECOVERY_DONE, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6879 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6880 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 6881 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6882 | /* no recovery is running. |
| 6883 | * remove any failed drives, then |
| 6884 | * add spares if possible. |
| 6885 | * Spare are also removed and re-added, to allow |
| 6886 | * the personality to fail the re-add. |
| 6887 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6888 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6889 | if (mddev->reshape_position != MaxSector) { |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6890 | if (mddev->pers->check_reshape == NULL || |
| 6891 | mddev->pers->check_reshape(mddev) != 0) |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6892 | /* Cannot proceed */ |
| 6893 | goto unlock; |
| 6894 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6895 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6896 | } else if ((spares = remove_and_add_spares(mddev))) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6897 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 6898 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
Dan Williams | 56ac36d | 2008-08-07 10:02:47 -0700 | [diff] [blame] | 6899 | clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6900 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6901 | } else if (mddev->recovery_cp < MaxSector) { |
| 6902 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6903 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6904 | } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 6905 | /* nothing to be done ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6906 | goto unlock; |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6908 | if (mddev->pers->sync_request) { |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 6909 | if (spares && mddev->bitmap && ! mddev->bitmap->file) { |
| 6910 | /* We are adding a device or devices to an array |
| 6911 | * which has the bitmap stored on all devices. |
| 6912 | * So make sure all bitmap pages get written |
| 6913 | */ |
| 6914 | bitmap_write_all(mddev->bitmap); |
| 6915 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6916 | mddev->sync_thread = md_register_thread(md_do_sync, |
| 6917 | mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 6918 | "resync"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6919 | if (!mddev->sync_thread) { |
| 6920 | printk(KERN_ERR "%s: could not start resync" |
| 6921 | " thread...\n", |
| 6922 | mdname(mddev)); |
| 6923 | /* leave the spares where they are, it shouldn't hurt */ |
| 6924 | mddev->recovery = 0; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6925 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6926 | md_wakeup_thread(mddev->sync_thread); |
NeilBrown | 0c3573f | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 6927 | sysfs_notify_dirent(mddev->sysfs_action); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6928 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6929 | } |
| 6930 | unlock: |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6931 | if (!mddev->sync_thread) { |
| 6932 | clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 6933 | if (test_and_clear_bit(MD_RECOVERY_RECOVER, |
| 6934 | &mddev->recovery)) |
NeilBrown | 0c3573f | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 6935 | if (mddev->sysfs_action) |
| 6936 | sysfs_notify_dirent(mddev->sysfs_action); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6937 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6938 | mddev_unlock(mddev); |
| 6939 | } |
| 6940 | } |
| 6941 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 6942 | void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 6943 | { |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 6944 | sysfs_notify_dirent(rdev->sysfs_state); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 6945 | wait_event_timeout(rdev->blocked_wait, |
| 6946 | !test_bit(Blocked, &rdev->flags), |
| 6947 | msecs_to_jiffies(5000)); |
| 6948 | rdev_dec_pending(rdev, mddev); |
| 6949 | } |
| 6950 | EXPORT_SYMBOL(md_wait_for_blocked_rdev); |
| 6951 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 6952 | static int md_notify_reboot(struct notifier_block *this, |
| 6953 | unsigned long code, void *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6954 | { |
| 6955 | struct list_head *tmp; |
| 6956 | mddev_t *mddev; |
| 6957 | |
| 6958 | if ((code == SYS_DOWN) || (code == SYS_HALT) || (code == SYS_POWER_OFF)) { |
| 6959 | |
| 6960 | printk(KERN_INFO "md: stopping all md devices.\n"); |
| 6961 | |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 6962 | for_each_mddev(mddev, tmp) |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 6963 | if (mddev_trylock(mddev)) { |
NeilBrown | 2b25000 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 6964 | /* Force a switch to readonly even array |
| 6965 | * appears to still be in use. Hence |
| 6966 | * the '100'. |
| 6967 | */ |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6968 | do_md_stop(mddev, 1, 100); |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 6969 | mddev_unlock(mddev); |
| 6970 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6971 | /* |
| 6972 | * certain more exotic SCSI devices are known to be |
| 6973 | * volatile wrt too early system reboots. While the |
| 6974 | * right place to handle this issue is the given |
| 6975 | * driver, we do want to have a safe RAID driver ... |
| 6976 | */ |
| 6977 | mdelay(1000*1); |
| 6978 | } |
| 6979 | return NOTIFY_DONE; |
| 6980 | } |
| 6981 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 6982 | static struct notifier_block md_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6983 | .notifier_call = md_notify_reboot, |
| 6984 | .next = NULL, |
| 6985 | .priority = INT_MAX, /* before any real devices */ |
| 6986 | }; |
| 6987 | |
| 6988 | static void md_geninit(void) |
| 6989 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6990 | dprintk("md: sizeof(mdp_super_t) = %d\n", (int)sizeof(mdp_super_t)); |
| 6991 | |
Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 6992 | proc_create("mdstat", S_IRUGO, NULL, &md_seq_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6993 | } |
| 6994 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 6995 | static int __init md_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6996 | { |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6997 | if (register_blkdev(MD_MAJOR, "md")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6998 | return -1; |
| 6999 | if ((mdp_major=register_blkdev(0, "mdp"))<=0) { |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7000 | unregister_blkdev(MD_MAJOR, "md"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7001 | return -1; |
| 7002 | } |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7003 | blk_register_region(MKDEV(MD_MAJOR, 0), 1UL<<MINORBITS, THIS_MODULE, |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 7004 | md_probe, NULL, NULL); |
| 7005 | blk_register_region(MKDEV(mdp_major, 0), 1UL<<MINORBITS, THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7006 | md_probe, NULL, NULL); |
| 7007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7008 | register_reboot_notifier(&md_notifier); |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 7009 | raid_table_header = register_sysctl_table(raid_root_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7010 | |
| 7011 | md_geninit(); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 7012 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7013 | } |
| 7014 | |
| 7015 | |
| 7016 | #ifndef MODULE |
| 7017 | |
| 7018 | /* |
| 7019 | * Searches all registered partitions for autorun RAID arrays |
| 7020 | * at boot time. |
| 7021 | */ |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7022 | |
| 7023 | static LIST_HEAD(all_detected_devices); |
| 7024 | struct detected_devices_node { |
| 7025 | struct list_head list; |
| 7026 | dev_t dev; |
| 7027 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7028 | |
| 7029 | void md_autodetect_dev(dev_t dev) |
| 7030 | { |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7031 | struct detected_devices_node *node_detected_dev; |
| 7032 | |
| 7033 | node_detected_dev = kzalloc(sizeof(*node_detected_dev), GFP_KERNEL); |
| 7034 | if (node_detected_dev) { |
| 7035 | node_detected_dev->dev = dev; |
| 7036 | list_add_tail(&node_detected_dev->list, &all_detected_devices); |
| 7037 | } else { |
| 7038 | printk(KERN_CRIT "md: md_autodetect_dev: kzalloc failed" |
| 7039 | ", skipping dev(%d,%d)\n", MAJOR(dev), MINOR(dev)); |
| 7040 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7041 | } |
| 7042 | |
| 7043 | |
| 7044 | static void autostart_arrays(int part) |
| 7045 | { |
| 7046 | mdk_rdev_t *rdev; |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7047 | struct detected_devices_node *node_detected_dev; |
| 7048 | dev_t dev; |
| 7049 | int i_scanned, i_passed; |
| 7050 | |
| 7051 | i_scanned = 0; |
| 7052 | i_passed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7053 | |
| 7054 | printk(KERN_INFO "md: Autodetecting RAID arrays.\n"); |
| 7055 | |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7056 | while (!list_empty(&all_detected_devices) && i_scanned < INT_MAX) { |
| 7057 | i_scanned++; |
| 7058 | node_detected_dev = list_entry(all_detected_devices.next, |
| 7059 | struct detected_devices_node, list); |
| 7060 | list_del(&node_detected_dev->list); |
| 7061 | dev = node_detected_dev->dev; |
| 7062 | kfree(node_detected_dev); |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 7063 | rdev = md_import_device(dev,0, 90); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7064 | if (IS_ERR(rdev)) |
| 7065 | continue; |
| 7066 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 7067 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7068 | MD_BUG(); |
| 7069 | continue; |
| 7070 | } |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 7071 | set_bit(AutoDetected, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7072 | list_add(&rdev->same_set, &pending_raid_disks); |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7073 | i_passed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7074 | } |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7075 | |
| 7076 | printk(KERN_INFO "md: Scanned %d and added %d devices.\n", |
| 7077 | i_scanned, i_passed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7078 | |
| 7079 | autorun_devices(part); |
| 7080 | } |
| 7081 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 7082 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7083 | |
| 7084 | static __exit void md_exit(void) |
| 7085 | { |
| 7086 | mddev_t *mddev; |
| 7087 | struct list_head *tmp; |
Greg Kroah-Hartman | 8ab5e4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 7088 | |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7089 | blk_unregister_region(MKDEV(MD_MAJOR,0), 1U << MINORBITS); |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 7090 | blk_unregister_region(MKDEV(mdp_major,0), 1U << MINORBITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7091 | |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7092 | unregister_blkdev(MD_MAJOR,"md"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7093 | unregister_blkdev(mdp_major, "mdp"); |
| 7094 | unregister_reboot_notifier(&md_notifier); |
| 7095 | unregister_sysctl_table(raid_table_header); |
| 7096 | remove_proc_entry("mdstat", NULL); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 7097 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7098 | export_array(mddev); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 7099 | mddev->hold_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7100 | } |
| 7101 | } |
| 7102 | |
Dan Williams | 685784a | 2007-07-09 11:56:42 -0700 | [diff] [blame] | 7103 | subsys_initcall(md_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7104 | module_exit(md_exit) |
| 7105 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7106 | static int get_ro(char *buffer, struct kernel_param *kp) |
| 7107 | { |
| 7108 | return sprintf(buffer, "%d", start_readonly); |
| 7109 | } |
| 7110 | static int set_ro(const char *val, struct kernel_param *kp) |
| 7111 | { |
| 7112 | char *e; |
| 7113 | int num = simple_strtoul(val, &e, 10); |
| 7114 | if (*val && (*e == '\0' || *e == '\n')) { |
| 7115 | start_readonly = num; |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 7116 | return 0; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7117 | } |
| 7118 | return -EINVAL; |
| 7119 | } |
| 7120 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 7121 | module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); |
| 7122 | module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR); |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 7123 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 7124 | module_param_call(new_array, add_named_array, NULL, NULL, S_IWUSR); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7126 | EXPORT_SYMBOL(register_md_personality); |
| 7127 | EXPORT_SYMBOL(unregister_md_personality); |
| 7128 | EXPORT_SYMBOL(md_error); |
| 7129 | EXPORT_SYMBOL(md_done_sync); |
| 7130 | EXPORT_SYMBOL(md_write_start); |
| 7131 | EXPORT_SYMBOL(md_write_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7132 | EXPORT_SYMBOL(md_register_thread); |
| 7133 | EXPORT_SYMBOL(md_unregister_thread); |
| 7134 | EXPORT_SYMBOL(md_wakeup_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7135 | EXPORT_SYMBOL(md_check_recovery); |
| 7136 | MODULE_LICENSE("GPL"); |
NeilBrown | aa1595e | 2005-08-04 12:53:32 -0700 | [diff] [blame] | 7137 | MODULE_ALIAS("md"); |
NeilBrown | 7200865 | 2005-08-26 18:34:15 -0700 | [diff] [blame] | 7138 | MODULE_ALIAS_BLOCKDEV_MAJOR(MD_MAJOR); |