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> |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 42 | #include <linux/string.h> |
NeilBrown | fb4d8c7 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 43 | #include <linux/hdreg.h> |
| 44 | #include <linux/proc_fs.h> |
| 45 | #include <linux/random.h> |
| 46 | #include <linux/reboot.h> |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 47 | #include <linux/file.h> |
Arnd Bergmann | aa98aa3 | 2009-12-14 12:50:05 +1100 | [diff] [blame] | 48 | #include <linux/compat.h> |
Stephen Rothwell | 2557072 | 2008-10-15 09:09:21 +1100 | [diff] [blame] | 49 | #include <linux/delay.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 50 | #include <linux/raid/md_p.h> |
| 51 | #include <linux/raid/md_u.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 52 | #include <linux/slab.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 53 | #include "md.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 54 | #include "bitmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | #define DEBUG 0 |
| 57 | #define dprintk(x...) ((void)(DEBUG && printk(x))) |
| 58 | |
| 59 | |
| 60 | #ifndef MODULE |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 61 | static void autostart_arrays(int part); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #endif |
| 63 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 64 | static LIST_HEAD(pers_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static DEFINE_SPINLOCK(pers_lock); |
| 66 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 67 | static void md_print_devices(void); |
| 68 | |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 69 | static DECLARE_WAIT_QUEUE_HEAD(resync_wait); |
| 70 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 71 | #define MD_BUG(x...) { printk("md: bug in file %s, line %d\n", __FILE__, __LINE__); md_print_devices(); } |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 74 | * Default number of read corrections we'll attempt on an rdev |
| 75 | * before ejecting it from the array. We divide the read error |
| 76 | * count by 2 for every hour elapsed between read errors. |
| 77 | */ |
| 78 | #define MD_DEFAULT_MAX_CORRECTED_READ_ERRORS 20 |
| 79 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | * Current RAID-1,4,5 parallel reconstruction 'guaranteed speed limit' |
| 81 | * is 1000 KB/sec, so the extra system load does not show up that much. |
| 82 | * Increase it if you want to have more _guaranteed_ speed. Note that |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 83 | * the RAID driver will use the maximum available bandwidth if the IO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | * subsystem is idle. There is also an 'absolute maximum' reconstruction |
| 85 | * speed limit - in case reconstruction slows down your system despite |
| 86 | * idle IO detection. |
| 87 | * |
| 88 | * you can change it via /proc/sys/dev/raid/speed_limit_min and _max. |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 89 | * or /sys/block/mdX/md/sync_speed_{min,max} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | */ |
| 91 | |
| 92 | static int sysctl_speed_limit_min = 1000; |
| 93 | static int sysctl_speed_limit_max = 200000; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 94 | static inline int speed_min(mddev_t *mddev) |
| 95 | { |
| 96 | return mddev->sync_speed_min ? |
| 97 | mddev->sync_speed_min : sysctl_speed_limit_min; |
| 98 | } |
| 99 | |
| 100 | static inline int speed_max(mddev_t *mddev) |
| 101 | { |
| 102 | return mddev->sync_speed_max ? |
| 103 | mddev->sync_speed_max : sysctl_speed_limit_max; |
| 104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | static struct ctl_table_header *raid_table_header; |
| 107 | |
| 108 | static ctl_table raid_table[] = { |
| 109 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | .procname = "speed_limit_min", |
| 111 | .data = &sysctl_speed_limit_min, |
| 112 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 113 | .mode = S_IRUGO|S_IWUSR, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 114 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | }, |
| 116 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .procname = "speed_limit_max", |
| 118 | .data = &sysctl_speed_limit_max, |
| 119 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 120 | .mode = S_IRUGO|S_IWUSR, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 121 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 123 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | static ctl_table raid_dir_table[] = { |
| 127 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | .procname = "raid", |
| 129 | .maxlen = 0, |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 130 | .mode = S_IRUGO|S_IXUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | .child = raid_table, |
| 132 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 133 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | static ctl_table raid_root_table[] = { |
| 137 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | .procname = "dev", |
| 139 | .maxlen = 0, |
| 140 | .mode = 0555, |
| 141 | .child = raid_dir_table, |
| 142 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 143 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 146 | static const struct block_device_operations md_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 148 | static int start_readonly; |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 151 | * We have a system wide 'event count' that is incremented |
| 152 | * on any 'interesting' event, and readers of /proc/mdstat |
| 153 | * can use 'poll' or 'select' to find out when the event |
| 154 | * count increases. |
| 155 | * |
| 156 | * Events are: |
| 157 | * start array, stop array, error, add device, remove device, |
| 158 | * start build, activate spare |
| 159 | */ |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 160 | static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 161 | static atomic_t md_event_count; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 162 | void md_new_event(mddev_t *mddev) |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 163 | { |
| 164 | atomic_inc(&md_event_count); |
| 165 | wake_up(&md_event_waiters); |
| 166 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 167 | EXPORT_SYMBOL_GPL(md_new_event); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 168 | |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 169 | /* Alternate version that can be called from interrupts |
| 170 | * when calling sysfs_notify isn't needed. |
| 171 | */ |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 172 | static void md_new_event_inintr(mddev_t *mddev) |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 173 | { |
| 174 | atomic_inc(&md_event_count); |
| 175 | wake_up(&md_event_waiters); |
| 176 | } |
| 177 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 178 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | * Enables to iterate over all existing md arrays |
| 180 | * all_mddevs_lock protects this list. |
| 181 | */ |
| 182 | static LIST_HEAD(all_mddevs); |
| 183 | static DEFINE_SPINLOCK(all_mddevs_lock); |
| 184 | |
| 185 | |
| 186 | /* |
| 187 | * iterates through all used mddevs in the system. |
| 188 | * We take care to grab the all_mddevs_lock whenever navigating |
| 189 | * the list, and to always hold a refcount when unlocked. |
| 190 | * Any code which breaks out of this loop while own |
| 191 | * a reference to the current mddev and must mddev_put it. |
| 192 | */ |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 193 | #define for_each_mddev(mddev,tmp) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | \ |
| 195 | for (({ spin_lock(&all_mddevs_lock); \ |
| 196 | tmp = all_mddevs.next; \ |
| 197 | mddev = NULL;}); \ |
| 198 | ({ if (tmp != &all_mddevs) \ |
| 199 | mddev_get(list_entry(tmp, mddev_t, all_mddevs));\ |
| 200 | spin_unlock(&all_mddevs_lock); \ |
| 201 | if (mddev) mddev_put(mddev); \ |
| 202 | mddev = list_entry(tmp, mddev_t, all_mddevs); \ |
| 203 | tmp != &all_mddevs;}); \ |
| 204 | ({ spin_lock(&all_mddevs_lock); \ |
| 205 | tmp = tmp->next;}) \ |
| 206 | ) |
| 207 | |
| 208 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 209 | /* Rather than calling directly into the personality make_request function, |
| 210 | * IO requests come here first so that we can check if the device is |
| 211 | * being suspended pending a reconfiguration. |
| 212 | * We hold a refcount over the call to ->make_request. By the time that |
| 213 | * call has finished, the bio has been linked into some internal structure |
| 214 | * and so is visible to ->quiesce(), so we don't need the refcount any more. |
| 215 | */ |
| 216 | static int md_make_request(struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 218 | const int rw = bio_data_dir(bio); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 219 | mddev_t *mddev = q->queuedata; |
| 220 | int rv; |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 221 | int cpu; |
| 222 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 223 | if (mddev == NULL || mddev->pers == NULL) { |
| 224 | bio_io_error(bio); |
| 225 | return 0; |
| 226 | } |
| 227 | rcu_read_lock(); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 228 | if (mddev->suspended || mddev->barrier) { |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 229 | DEFINE_WAIT(__wait); |
| 230 | for (;;) { |
| 231 | prepare_to_wait(&mddev->sb_wait, &__wait, |
| 232 | TASK_UNINTERRUPTIBLE); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 233 | if (!mddev->suspended && !mddev->barrier) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 234 | break; |
| 235 | rcu_read_unlock(); |
| 236 | schedule(); |
| 237 | rcu_read_lock(); |
| 238 | } |
| 239 | finish_wait(&mddev->sb_wait, &__wait); |
| 240 | } |
| 241 | atomic_inc(&mddev->active_io); |
| 242 | rcu_read_unlock(); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 243 | |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 244 | rv = mddev->pers->make_request(mddev, bio); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 245 | |
| 246 | cpu = part_stat_lock(); |
| 247 | part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]); |
| 248 | part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw], |
| 249 | bio_sectors(bio)); |
| 250 | part_stat_unlock(); |
| 251 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 252 | if (atomic_dec_and_test(&mddev->active_io) && mddev->suspended) |
| 253 | wake_up(&mddev->sb_wait); |
| 254 | |
| 255 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
NeilBrown | 9e35b99 | 2010-04-06 14:23:02 +1000 | [diff] [blame] | 258 | /* mddev_suspend makes sure no new requests are submitted |
| 259 | * to the device, and that any requests that have been submitted |
| 260 | * are completely handled. |
| 261 | * Once ->stop is called and completes, the module will be completely |
| 262 | * unused. |
| 263 | */ |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 264 | void mddev_suspend(mddev_t *mddev) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 265 | { |
| 266 | BUG_ON(mddev->suspended); |
| 267 | mddev->suspended = 1; |
| 268 | synchronize_rcu(); |
| 269 | wait_event(mddev->sb_wait, atomic_read(&mddev->active_io) == 0); |
| 270 | mddev->pers->quiesce(mddev, 1); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 271 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 272 | EXPORT_SYMBOL_GPL(mddev_suspend); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 273 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 274 | void mddev_resume(mddev_t *mddev) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 275 | { |
| 276 | mddev->suspended = 0; |
| 277 | wake_up(&mddev->sb_wait); |
| 278 | mddev->pers->quiesce(mddev, 0); |
| 279 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 280 | EXPORT_SYMBOL_GPL(mddev_resume); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 281 | |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 282 | int mddev_congested(mddev_t *mddev, int bits) |
| 283 | { |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 284 | if (mddev->barrier) |
| 285 | return 1; |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 286 | return mddev->suspended; |
| 287 | } |
| 288 | EXPORT_SYMBOL(mddev_congested); |
| 289 | |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 290 | /* |
| 291 | * Generic barrier handling for md |
| 292 | */ |
| 293 | |
| 294 | #define POST_REQUEST_BARRIER ((void*)1) |
| 295 | |
| 296 | static void md_end_barrier(struct bio *bio, int err) |
| 297 | { |
| 298 | mdk_rdev_t *rdev = bio->bi_private; |
| 299 | mddev_t *mddev = rdev->mddev; |
| 300 | if (err == -EOPNOTSUPP && mddev->barrier != POST_REQUEST_BARRIER) |
| 301 | set_bit(BIO_EOPNOTSUPP, &mddev->barrier->bi_flags); |
| 302 | |
| 303 | rdev_dec_pending(rdev, mddev); |
| 304 | |
| 305 | if (atomic_dec_and_test(&mddev->flush_pending)) { |
| 306 | if (mddev->barrier == POST_REQUEST_BARRIER) { |
| 307 | /* This was a post-request barrier */ |
| 308 | mddev->barrier = NULL; |
| 309 | wake_up(&mddev->sb_wait); |
| 310 | } else |
| 311 | /* The pre-request barrier has finished */ |
| 312 | schedule_work(&mddev->barrier_work); |
| 313 | } |
| 314 | bio_put(bio); |
| 315 | } |
| 316 | |
| 317 | static void submit_barriers(mddev_t *mddev) |
| 318 | { |
| 319 | mdk_rdev_t *rdev; |
| 320 | |
| 321 | rcu_read_lock(); |
| 322 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
| 323 | if (rdev->raid_disk >= 0 && |
| 324 | !test_bit(Faulty, &rdev->flags)) { |
| 325 | /* Take two references, one is dropped |
| 326 | * when request finishes, one after |
| 327 | * we reclaim rcu_read_lock |
| 328 | */ |
| 329 | struct bio *bi; |
| 330 | atomic_inc(&rdev->nr_pending); |
| 331 | atomic_inc(&rdev->nr_pending); |
| 332 | rcu_read_unlock(); |
| 333 | bi = bio_alloc(GFP_KERNEL, 0); |
| 334 | bi->bi_end_io = md_end_barrier; |
| 335 | bi->bi_private = rdev; |
| 336 | bi->bi_bdev = rdev->bdev; |
| 337 | atomic_inc(&mddev->flush_pending); |
| 338 | submit_bio(WRITE_BARRIER, bi); |
| 339 | rcu_read_lock(); |
| 340 | rdev_dec_pending(rdev, mddev); |
| 341 | } |
| 342 | rcu_read_unlock(); |
| 343 | } |
| 344 | |
| 345 | static void md_submit_barrier(struct work_struct *ws) |
| 346 | { |
| 347 | mddev_t *mddev = container_of(ws, mddev_t, barrier_work); |
| 348 | struct bio *bio = mddev->barrier; |
| 349 | |
| 350 | atomic_set(&mddev->flush_pending, 1); |
| 351 | |
| 352 | if (test_bit(BIO_EOPNOTSUPP, &bio->bi_flags)) |
| 353 | bio_endio(bio, -EOPNOTSUPP); |
| 354 | else if (bio->bi_size == 0) |
| 355 | /* an empty barrier - all done */ |
| 356 | bio_endio(bio, 0); |
| 357 | else { |
| 358 | bio->bi_rw &= ~(1<<BIO_RW_BARRIER); |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 359 | if (mddev->pers->make_request(mddev, bio)) |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 360 | generic_make_request(bio); |
| 361 | mddev->barrier = POST_REQUEST_BARRIER; |
| 362 | submit_barriers(mddev); |
| 363 | } |
| 364 | if (atomic_dec_and_test(&mddev->flush_pending)) { |
| 365 | mddev->barrier = NULL; |
| 366 | wake_up(&mddev->sb_wait); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | void md_barrier_request(mddev_t *mddev, struct bio *bio) |
| 371 | { |
| 372 | spin_lock_irq(&mddev->write_lock); |
| 373 | wait_event_lock_irq(mddev->sb_wait, |
| 374 | !mddev->barrier, |
| 375 | mddev->write_lock, /*nothing*/); |
| 376 | mddev->barrier = bio; |
| 377 | spin_unlock_irq(&mddev->write_lock); |
| 378 | |
| 379 | atomic_set(&mddev->flush_pending, 1); |
| 380 | INIT_WORK(&mddev->barrier_work, md_submit_barrier); |
| 381 | |
| 382 | submit_barriers(mddev); |
| 383 | |
| 384 | if (atomic_dec_and_test(&mddev->flush_pending)) |
| 385 | schedule_work(&mddev->barrier_work); |
| 386 | } |
| 387 | EXPORT_SYMBOL(md_barrier_request); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 388 | |
NeilBrown | 2ac8740 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 389 | /* Support for plugging. |
| 390 | * This mirrors the plugging support in request_queue, but does not |
| 391 | * require having a whole queue |
| 392 | */ |
| 393 | static void plugger_work(struct work_struct *work) |
| 394 | { |
| 395 | struct plug_handle *plug = |
| 396 | container_of(work, struct plug_handle, unplug_work); |
| 397 | plug->unplug_fn(plug); |
| 398 | } |
| 399 | static void plugger_timeout(unsigned long data) |
| 400 | { |
| 401 | struct plug_handle *plug = (void *)data; |
| 402 | kblockd_schedule_work(NULL, &plug->unplug_work); |
| 403 | } |
| 404 | void plugger_init(struct plug_handle *plug, |
| 405 | void (*unplug_fn)(struct plug_handle *)) |
| 406 | { |
| 407 | plug->unplug_flag = 0; |
| 408 | plug->unplug_fn = unplug_fn; |
| 409 | init_timer(&plug->unplug_timer); |
| 410 | plug->unplug_timer.function = plugger_timeout; |
| 411 | plug->unplug_timer.data = (unsigned long)plug; |
| 412 | INIT_WORK(&plug->unplug_work, plugger_work); |
| 413 | } |
| 414 | EXPORT_SYMBOL_GPL(plugger_init); |
| 415 | |
| 416 | void plugger_set_plug(struct plug_handle *plug) |
| 417 | { |
| 418 | if (!test_and_set_bit(PLUGGED_FLAG, &plug->unplug_flag)) |
| 419 | mod_timer(&plug->unplug_timer, jiffies + msecs_to_jiffies(3)+1); |
| 420 | } |
| 421 | EXPORT_SYMBOL_GPL(plugger_set_plug); |
| 422 | |
| 423 | int plugger_remove_plug(struct plug_handle *plug) |
| 424 | { |
| 425 | if (test_and_clear_bit(PLUGGED_FLAG, &plug->unplug_flag)) { |
| 426 | del_timer(&plug->unplug_timer); |
| 427 | return 1; |
| 428 | } else |
| 429 | return 0; |
| 430 | } |
| 431 | EXPORT_SYMBOL_GPL(plugger_remove_plug); |
| 432 | |
| 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | static inline mddev_t *mddev_get(mddev_t *mddev) |
| 435 | { |
| 436 | atomic_inc(&mddev->active); |
| 437 | return mddev; |
| 438 | } |
| 439 | |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 440 | static void mddev_delayed_delete(struct work_struct *ws); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | static void mddev_put(mddev_t *mddev) |
| 443 | { |
| 444 | if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock)) |
| 445 | return; |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 446 | if (!mddev->raid_disks && list_empty(&mddev->disks) && |
NeilBrown | cbd1998 | 2009-12-30 12:08:49 +1100 | [diff] [blame] | 447 | mddev->ctime == 0 && !mddev->hold_active) { |
| 448 | /* Array is not configured at all, and not held active, |
| 449 | * so destroy it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | list_del(&mddev->all_mddevs); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 451 | if (mddev->gendisk) { |
| 452 | /* we did a probe so need to clean up. |
| 453 | * Call schedule_work inside the spinlock |
| 454 | * so that flush_scheduled_work() after |
| 455 | * mddev_find will succeed in waiting for the |
| 456 | * work to be done. |
| 457 | */ |
| 458 | INIT_WORK(&mddev->del_work, mddev_delayed_delete); |
| 459 | schedule_work(&mddev->del_work); |
| 460 | } else |
| 461 | kfree(mddev); |
| 462 | } |
| 463 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 466 | void mddev_init(mddev_t *mddev) |
NeilBrown | fafd7fb | 2010-04-01 15:55:30 +1100 | [diff] [blame] | 467 | { |
| 468 | mutex_init(&mddev->open_mutex); |
| 469 | mutex_init(&mddev->reconfig_mutex); |
| 470 | mutex_init(&mddev->bitmap_info.mutex); |
| 471 | INIT_LIST_HEAD(&mddev->disks); |
| 472 | INIT_LIST_HEAD(&mddev->all_mddevs); |
| 473 | init_timer(&mddev->safemode_timer); |
| 474 | atomic_set(&mddev->active, 1); |
| 475 | atomic_set(&mddev->openers, 0); |
| 476 | atomic_set(&mddev->active_io, 0); |
| 477 | spin_lock_init(&mddev->write_lock); |
| 478 | atomic_set(&mddev->flush_pending, 0); |
| 479 | init_waitqueue_head(&mddev->sb_wait); |
| 480 | init_waitqueue_head(&mddev->recovery_wait); |
| 481 | mddev->reshape_position = MaxSector; |
| 482 | mddev->resync_min = 0; |
| 483 | mddev->resync_max = MaxSector; |
| 484 | mddev->level = LEVEL_NONE; |
| 485 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 486 | EXPORT_SYMBOL_GPL(mddev_init); |
NeilBrown | fafd7fb | 2010-04-01 15:55:30 +1100 | [diff] [blame] | 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | static mddev_t * mddev_find(dev_t unit) |
| 489 | { |
| 490 | mddev_t *mddev, *new = NULL; |
| 491 | |
| 492 | retry: |
| 493 | spin_lock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 495 | if (unit) { |
| 496 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 497 | if (mddev->unit == unit) { |
| 498 | mddev_get(mddev); |
| 499 | spin_unlock(&all_mddevs_lock); |
| 500 | kfree(new); |
| 501 | return mddev; |
| 502 | } |
| 503 | |
| 504 | if (new) { |
| 505 | list_add(&new->all_mddevs, &all_mddevs); |
| 506 | spin_unlock(&all_mddevs_lock); |
| 507 | new->hold_active = UNTIL_IOCTL; |
| 508 | return new; |
| 509 | } |
| 510 | } else if (new) { |
| 511 | /* find an unused unit number */ |
| 512 | static int next_minor = 512; |
| 513 | int start = next_minor; |
| 514 | int is_free = 0; |
| 515 | int dev = 0; |
| 516 | while (!is_free) { |
| 517 | dev = MKDEV(MD_MAJOR, next_minor); |
| 518 | next_minor++; |
| 519 | if (next_minor > MINORMASK) |
| 520 | next_minor = 0; |
| 521 | if (next_minor == start) { |
| 522 | /* Oh dear, all in use. */ |
| 523 | spin_unlock(&all_mddevs_lock); |
| 524 | kfree(new); |
| 525 | return NULL; |
| 526 | } |
| 527 | |
| 528 | is_free = 1; |
| 529 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 530 | if (mddev->unit == dev) { |
| 531 | is_free = 0; |
| 532 | break; |
| 533 | } |
| 534 | } |
| 535 | new->unit = dev; |
| 536 | new->md_minor = MINOR(dev); |
| 537 | new->hold_active = UNTIL_STOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | list_add(&new->all_mddevs, &all_mddevs); |
| 539 | spin_unlock(&all_mddevs_lock); |
| 540 | return new; |
| 541 | } |
| 542 | spin_unlock(&all_mddevs_lock); |
| 543 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 544 | new = kzalloc(sizeof(*new), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | if (!new) |
| 546 | return NULL; |
| 547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | new->unit = unit; |
| 549 | if (MAJOR(unit) == MD_MAJOR) |
| 550 | new->md_minor = MINOR(unit); |
| 551 | else |
| 552 | new->md_minor = MINOR(unit) >> MdpMinorShift; |
| 553 | |
NeilBrown | fafd7fb | 2010-04-01 15:55:30 +1100 | [diff] [blame] | 554 | mddev_init(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | goto retry; |
| 557 | } |
| 558 | |
| 559 | static inline int mddev_lock(mddev_t * mddev) |
| 560 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 561 | return mutex_lock_interruptible(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 564 | static inline int mddev_is_locked(mddev_t *mddev) |
| 565 | { |
| 566 | return mutex_is_locked(&mddev->reconfig_mutex); |
| 567 | } |
| 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | static inline int mddev_trylock(mddev_t * mddev) |
| 570 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 571 | return mutex_trylock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } |
| 573 | |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 574 | static struct attribute_group md_redundancy_group; |
| 575 | |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 576 | static void mddev_unlock(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 578 | if (mddev->to_remove) { |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 579 | /* These cannot be removed under reconfig_mutex as |
| 580 | * an access to the files will try to take reconfig_mutex |
| 581 | * while holding the file unremovable, which leads to |
| 582 | * a deadlock. |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame^] | 583 | * So hold set sysfs_active while the remove in happeing, |
| 584 | * and anything else which might set ->to_remove or my |
| 585 | * otherwise change the sysfs namespace will fail with |
| 586 | * -EBUSY if sysfs_active is still set. |
| 587 | * We set sysfs_active under reconfig_mutex and elsewhere |
| 588 | * test it under the same mutex to ensure its correct value |
| 589 | * is seen. |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 590 | */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 591 | struct attribute_group *to_remove = mddev->to_remove; |
| 592 | mddev->to_remove = NULL; |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame^] | 593 | mddev->sysfs_active = 1; |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 594 | mutex_unlock(&mddev->reconfig_mutex); |
| 595 | |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 596 | if (mddev->kobj.sd) { |
| 597 | if (to_remove != &md_redundancy_group) |
| 598 | sysfs_remove_group(&mddev->kobj, to_remove); |
| 599 | if (mddev->pers == NULL || |
| 600 | mddev->pers->sync_request == NULL) { |
| 601 | sysfs_remove_group(&mddev->kobj, &md_redundancy_group); |
| 602 | if (mddev->sysfs_action) |
| 603 | sysfs_put(mddev->sysfs_action); |
| 604 | mddev->sysfs_action = NULL; |
| 605 | } |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 606 | } |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame^] | 607 | mddev->sysfs_active = 0; |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 608 | } else |
| 609 | mutex_unlock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 611 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 614 | static mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 616 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 618 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | if (rdev->desc_nr == nr) |
| 620 | return rdev; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | return NULL; |
| 623 | } |
| 624 | |
| 625 | static mdk_rdev_t * find_rdev(mddev_t * mddev, dev_t dev) |
| 626 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | mdk_rdev_t *rdev; |
| 628 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 629 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | if (rdev->bdev->bd_dev == dev) |
| 631 | return rdev; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | return NULL; |
| 634 | } |
| 635 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 636 | static struct mdk_personality *find_pers(int level, char *clevel) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 637 | { |
| 638 | struct mdk_personality *pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 639 | list_for_each_entry(pers, &pers_list, list) { |
| 640 | if (level != LEVEL_NONE && pers->level == level) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 641 | return pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 642 | if (strcmp(pers->name, clevel)==0) |
| 643 | return pers; |
| 644 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 645 | return NULL; |
| 646 | } |
| 647 | |
Andre Noll | b73df2d | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 648 | /* return the offset of the super block in 512byte sectors */ |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 649 | static inline sector_t calc_dev_sboffset(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
Andre Noll | b73df2d | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 651 | sector_t num_sectors = bdev->bd_inode->i_size / 512; |
| 652 | return MD_NEW_SIZE_SECTORS(num_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | static int alloc_disk_sb(mdk_rdev_t * rdev) |
| 656 | { |
| 657 | if (rdev->sb_page) |
| 658 | MD_BUG(); |
| 659 | |
| 660 | rdev->sb_page = alloc_page(GFP_KERNEL); |
| 661 | if (!rdev->sb_page) { |
| 662 | printk(KERN_ALERT "md: out of memory.\n"); |
Andre Noll | ebc2433 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 663 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | static void free_disk_sb(mdk_rdev_t * rdev) |
| 670 | { |
| 671 | if (rdev->sb_page) { |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 672 | put_page(rdev->sb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | rdev->sb_loaded = 0; |
| 674 | rdev->sb_page = NULL; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 675 | rdev->sb_start = 0; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 676 | rdev->sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| 680 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 681 | static void super_written(struct bio *bio, int error) |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 682 | { |
| 683 | mdk_rdev_t *rdev = bio->bi_private; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 684 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 685 | |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 686 | if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) { |
| 687 | printk("md: super_written gets error=%d, uptodate=%d\n", |
| 688 | error, test_bit(BIO_UPTODATE, &bio->bi_flags)); |
| 689 | WARN_ON(test_bit(BIO_UPTODATE, &bio->bi_flags)); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 690 | md_error(mddev, rdev); |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 691 | } |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 692 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 693 | if (atomic_dec_and_test(&mddev->pending_writes)) |
| 694 | wake_up(&mddev->sb_wait); |
Neil Brown | f8b58ed | 2005-06-27 22:29:34 -0700 | [diff] [blame] | 695 | bio_put(bio); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 696 | } |
| 697 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 698 | static void super_written_barrier(struct bio *bio, int error) |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 699 | { |
| 700 | struct bio *bio2 = bio->bi_private; |
| 701 | mdk_rdev_t *rdev = bio2->bi_private; |
| 702 | mddev_t *mddev = rdev->mddev; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 703 | |
| 704 | if (!test_bit(BIO_UPTODATE, &bio->bi_flags) && |
| 705 | error == -EOPNOTSUPP) { |
| 706 | unsigned long flags; |
| 707 | /* barriers don't appear to be supported :-( */ |
| 708 | set_bit(BarriersNotsupp, &rdev->flags); |
| 709 | mddev->barriers_work = 0; |
| 710 | spin_lock_irqsave(&mddev->write_lock, flags); |
| 711 | bio2->bi_next = mddev->biolist; |
| 712 | mddev->biolist = bio2; |
| 713 | spin_unlock_irqrestore(&mddev->write_lock, flags); |
| 714 | wake_up(&mddev->sb_wait); |
| 715 | bio_put(bio); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 716 | } else { |
| 717 | bio_put(bio2); |
| 718 | bio->bi_private = rdev; |
| 719 | super_written(bio, error); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 720 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 721 | } |
| 722 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 723 | void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev, |
| 724 | sector_t sector, int size, struct page *page) |
| 725 | { |
| 726 | /* write first size bytes of page to sector of rdev |
| 727 | * Increment mddev->pending_writes before returning |
| 728 | * and decrement it on completion, waking up sb_wait |
| 729 | * if zero is reached. |
| 730 | * If an error occurred, call md_error |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 731 | * |
| 732 | * As we might need to resubmit the request if BIO_RW_BARRIER |
| 733 | * causes ENOTSUPP, we allocate a spare bio... |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 734 | */ |
| 735 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
Jens Axboe | 93dbb39 | 2009-02-16 10:25:40 +0100 | [diff] [blame] | 736 | int rw = (1<<BIO_RW) | (1<<BIO_RW_SYNCIO) | (1<<BIO_RW_UNPLUG); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 737 | |
| 738 | bio->bi_bdev = rdev->bdev; |
| 739 | bio->bi_sector = sector; |
| 740 | bio_add_page(bio, page, size, 0); |
| 741 | bio->bi_private = rdev; |
| 742 | bio->bi_end_io = super_written; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 743 | bio->bi_rw = rw; |
| 744 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 745 | atomic_inc(&mddev->pending_writes); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 746 | if (!test_bit(BarriersNotsupp, &rdev->flags)) { |
| 747 | struct bio *rbio; |
| 748 | rw |= (1<<BIO_RW_BARRIER); |
| 749 | rbio = bio_clone(bio, GFP_NOIO); |
| 750 | rbio->bi_private = bio; |
| 751 | rbio->bi_end_io = super_written_barrier; |
| 752 | submit_bio(rw, rbio); |
| 753 | } else |
| 754 | submit_bio(rw, bio); |
| 755 | } |
| 756 | |
| 757 | void md_super_wait(mddev_t *mddev) |
| 758 | { |
| 759 | /* wait for all superblock writes that were scheduled to complete. |
| 760 | * if any had to be retried (due to BARRIER problems), retry them |
| 761 | */ |
| 762 | DEFINE_WAIT(wq); |
| 763 | for(;;) { |
| 764 | prepare_to_wait(&mddev->sb_wait, &wq, TASK_UNINTERRUPTIBLE); |
| 765 | if (atomic_read(&mddev->pending_writes)==0) |
| 766 | break; |
| 767 | while (mddev->biolist) { |
| 768 | struct bio *bio; |
| 769 | spin_lock_irq(&mddev->write_lock); |
| 770 | bio = mddev->biolist; |
| 771 | mddev->biolist = bio->bi_next ; |
| 772 | bio->bi_next = NULL; |
| 773 | spin_unlock_irq(&mddev->write_lock); |
| 774 | submit_bio(bio->bi_rw, bio); |
| 775 | } |
| 776 | schedule(); |
| 777 | } |
| 778 | finish_wait(&mddev->sb_wait, &wq); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 779 | } |
| 780 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 781 | static void bi_complete(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | complete((struct completion*)bio->bi_private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | } |
| 785 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 786 | 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] | 787 | struct page *page, int rw) |
| 788 | { |
Neil Brown | baaa2c5 | 2005-04-16 15:23:54 -0700 | [diff] [blame] | 789 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | struct completion event; |
| 791 | int ret; |
| 792 | |
Jens Axboe | 93dbb39 | 2009-02-16 10:25:40 +0100 | [diff] [blame] | 793 | rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | bio->bi_bdev = bdev; |
| 796 | bio->bi_sector = sector; |
| 797 | bio_add_page(bio, page, size, 0); |
| 798 | init_completion(&event); |
| 799 | bio->bi_private = &event; |
| 800 | bio->bi_end_io = bi_complete; |
| 801 | submit_bio(rw, bio); |
| 802 | wait_for_completion(&event); |
| 803 | |
| 804 | ret = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 805 | bio_put(bio); |
| 806 | return ret; |
| 807 | } |
NeilBrown | a8745db | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 808 | EXPORT_SYMBOL_GPL(sync_page_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 810 | static int read_disk_sb(mdk_rdev_t * rdev, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | { |
| 812 | char b[BDEVNAME_SIZE]; |
| 813 | if (!rdev->sb_page) { |
| 814 | MD_BUG(); |
| 815 | return -EINVAL; |
| 816 | } |
| 817 | if (rdev->sb_loaded) |
| 818 | return 0; |
| 819 | |
| 820 | |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 821 | 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] | 822 | goto fail; |
| 823 | rdev->sb_loaded = 1; |
| 824 | return 0; |
| 825 | |
| 826 | fail: |
| 827 | printk(KERN_WARNING "md: disabled device %s, could not read superblock.\n", |
| 828 | bdevname(rdev->bdev,b)); |
| 829 | return -EINVAL; |
| 830 | } |
| 831 | |
| 832 | static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 833 | { |
Andre Noll | 0571046 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 834 | return sb1->set_uuid0 == sb2->set_uuid0 && |
| 835 | sb1->set_uuid1 == sb2->set_uuid1 && |
| 836 | sb1->set_uuid2 == sb2->set_uuid2 && |
| 837 | sb1->set_uuid3 == sb2->set_uuid3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 841 | { |
| 842 | int ret; |
| 843 | mdp_super_t *tmp1, *tmp2; |
| 844 | |
| 845 | tmp1 = kmalloc(sizeof(*tmp1),GFP_KERNEL); |
| 846 | tmp2 = kmalloc(sizeof(*tmp2),GFP_KERNEL); |
| 847 | |
| 848 | if (!tmp1 || !tmp2) { |
| 849 | ret = 0; |
Andre Noll | 35020f1 | 2008-03-23 15:10:33 +0100 | [diff] [blame] | 850 | printk(KERN_INFO "md.c sb_equal(): failed to allocate memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | goto abort; |
| 852 | } |
| 853 | |
| 854 | *tmp1 = *sb1; |
| 855 | *tmp2 = *sb2; |
| 856 | |
| 857 | /* |
| 858 | * nr_disks is not constant |
| 859 | */ |
| 860 | tmp1->nr_disks = 0; |
| 861 | tmp2->nr_disks = 0; |
| 862 | |
Andre Noll | ce0c8e0 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 863 | ret = (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | abort: |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 865 | kfree(tmp1); |
| 866 | kfree(tmp2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | return ret; |
| 868 | } |
| 869 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 870 | |
| 871 | static u32 md_csum_fold(u32 csum) |
| 872 | { |
| 873 | csum = (csum & 0xffff) + (csum >> 16); |
| 874 | return (csum & 0xffff) + (csum >> 16); |
| 875 | } |
| 876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | static unsigned int calc_sb_csum(mdp_super_t * sb) |
| 878 | { |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 879 | u64 newcsum = 0; |
| 880 | u32 *sb32 = (u32*)sb; |
| 881 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | unsigned int disk_csum, csum; |
| 883 | |
| 884 | disk_csum = sb->sb_csum; |
| 885 | sb->sb_csum = 0; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 886 | |
| 887 | for (i = 0; i < MD_SB_BYTES/4 ; i++) |
| 888 | newcsum += sb32[i]; |
| 889 | csum = (newcsum & 0xffffffff) + (newcsum>>32); |
| 890 | |
| 891 | |
| 892 | #ifdef CONFIG_ALPHA |
| 893 | /* This used to use csum_partial, which was wrong for several |
| 894 | * reasons including that different results are returned on |
| 895 | * different architectures. It isn't critical that we get exactly |
| 896 | * the same return value as before (we always csum_fold before |
| 897 | * testing, and that removes any differences). However as we |
| 898 | * know that csum_partial always returned a 16bit value on |
| 899 | * alphas, do a fold to maximise conformity to previous behaviour. |
| 900 | */ |
| 901 | sb->sb_csum = md_csum_fold(disk_csum); |
| 902 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | sb->sb_csum = disk_csum; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 904 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | return csum; |
| 906 | } |
| 907 | |
| 908 | |
| 909 | /* |
| 910 | * Handle superblock details. |
| 911 | * We want to be able to handle multiple superblock formats |
| 912 | * so we have a common interface to them all, and an array of |
| 913 | * different handlers. |
| 914 | * We rely on user-space to write the initial superblock, and support |
| 915 | * reading and updating of superblocks. |
| 916 | * Interface methods are: |
| 917 | * int load_super(mdk_rdev_t *dev, mdk_rdev_t *refdev, int minor_version) |
| 918 | * loads and validates a superblock on dev. |
| 919 | * if refdev != NULL, compare superblocks on both devices |
| 920 | * Return: |
| 921 | * 0 - dev has a superblock that is compatible with refdev |
| 922 | * 1 - dev has a superblock that is compatible and newer than refdev |
| 923 | * so dev should be used as the refdev in future |
| 924 | * -EINVAL superblock incompatible or invalid |
| 925 | * -othererror e.g. -EIO |
| 926 | * |
| 927 | * int validate_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 928 | * Verify that dev is acceptable into mddev. |
| 929 | * The first time, mddev->raid_disks will be 0, and data from |
| 930 | * dev should be merged in. Subsequent calls check that dev |
| 931 | * is new enough. Return 0 or -EINVAL |
| 932 | * |
| 933 | * void sync_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 934 | * Update the superblock for rdev with data in mddev |
| 935 | * This does not write to disc. |
| 936 | * |
| 937 | */ |
| 938 | |
| 939 | struct super_type { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 940 | char *name; |
| 941 | struct module *owner; |
| 942 | int (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev, |
| 943 | int minor_version); |
| 944 | int (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 945 | void (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 946 | unsigned long long (*rdev_size_change)(mdk_rdev_t *rdev, |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 947 | sector_t num_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | }; |
| 949 | |
| 950 | /* |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 951 | * Check that the given mddev has no bitmap. |
| 952 | * |
| 953 | * This function is called from the run method of all personalities that do not |
| 954 | * support bitmaps. It prints an error message and returns non-zero if mddev |
| 955 | * has a bitmap. Otherwise, it returns 0. |
| 956 | * |
| 957 | */ |
| 958 | int md_check_no_bitmap(mddev_t *mddev) |
| 959 | { |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 960 | if (!mddev->bitmap_info.file && !mddev->bitmap_info.offset) |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 961 | return 0; |
| 962 | printk(KERN_ERR "%s: bitmaps are not supported for %s\n", |
| 963 | mdname(mddev), mddev->pers->name); |
| 964 | return 1; |
| 965 | } |
| 966 | EXPORT_SYMBOL(md_check_no_bitmap); |
| 967 | |
| 968 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | * load_super for 0.90.0 |
| 970 | */ |
| 971 | static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 972 | { |
| 973 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 974 | mdp_super_t *sb; |
| 975 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
| 977 | /* |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 978 | * Calculate the position of the superblock (512byte sectors), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | * it's at the end of the disk. |
| 980 | * |
| 981 | * It also happens to be a multiple of 4Kb. |
| 982 | */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 983 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 985 | ret = read_disk_sb(rdev, MD_SB_BYTES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | if (ret) return ret; |
| 987 | |
| 988 | ret = -EINVAL; |
| 989 | |
| 990 | bdevname(rdev->bdev, b); |
| 991 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 992 | |
| 993 | if (sb->md_magic != MD_SB_MAGIC) { |
| 994 | printk(KERN_ERR "md: invalid raid superblock magic on %s\n", |
| 995 | b); |
| 996 | goto abort; |
| 997 | } |
| 998 | |
| 999 | if (sb->major_version != 0 || |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1000 | sb->minor_version < 90 || |
| 1001 | sb->minor_version > 91) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | printk(KERN_WARNING "Bad version number %d.%d on %s\n", |
| 1003 | sb->major_version, sb->minor_version, |
| 1004 | b); |
| 1005 | goto abort; |
| 1006 | } |
| 1007 | |
| 1008 | if (sb->raid_disks <= 0) |
| 1009 | goto abort; |
| 1010 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 1011 | 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] | 1012 | printk(KERN_WARNING "md: invalid superblock checksum on %s\n", |
| 1013 | b); |
| 1014 | goto abort; |
| 1015 | } |
| 1016 | |
| 1017 | rdev->preferred_minor = sb->md_minor; |
| 1018 | rdev->data_offset = 0; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1019 | rdev->sb_size = MD_SB_BYTES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
| 1021 | if (sb->level == LEVEL_MULTIPATH) |
| 1022 | rdev->desc_nr = -1; |
| 1023 | else |
| 1024 | rdev->desc_nr = sb->this_disk.number; |
| 1025 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1026 | if (!refdev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1028 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | __u64 ev1, ev2; |
| 1030 | mdp_super_t *refsb = (mdp_super_t*)page_address(refdev->sb_page); |
| 1031 | if (!uuid_equal(refsb, sb)) { |
| 1032 | printk(KERN_WARNING "md: %s has different UUID to %s\n", |
| 1033 | b, bdevname(refdev->bdev,b2)); |
| 1034 | goto abort; |
| 1035 | } |
| 1036 | if (!sb_equal(refsb, sb)) { |
| 1037 | printk(KERN_WARNING "md: %s has same UUID" |
| 1038 | " but different superblock to %s\n", |
| 1039 | b, bdevname(refdev->bdev, b2)); |
| 1040 | goto abort; |
| 1041 | } |
| 1042 | ev1 = md_event(sb); |
| 1043 | ev2 = md_event(refsb); |
| 1044 | if (ev1 > ev2) |
| 1045 | ret = 1; |
| 1046 | else |
| 1047 | ret = 0; |
| 1048 | } |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 1049 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1051 | if (rdev->sectors < sb->size * 2 && sb->level > 1) |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1052 | /* "this cannot possibly happen" ... */ |
| 1053 | ret = -EINVAL; |
| 1054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | abort: |
| 1056 | return ret; |
| 1057 | } |
| 1058 | |
| 1059 | /* |
| 1060 | * validate_super for 0.90.0 |
| 1061 | */ |
| 1062 | static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1063 | { |
| 1064 | mdp_disk_t *desc; |
| 1065 | mdp_super_t *sb = (mdp_super_t *)page_address(rdev->sb_page); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1066 | __u64 ev1 = md_event(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1068 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1069 | clear_bit(Faulty, &rdev->flags); |
| 1070 | clear_bit(In_sync, &rdev->flags); |
| 1071 | clear_bit(WriteMostly, &rdev->flags); |
| 1072 | clear_bit(BarriersNotsupp, &rdev->flags); |
| 1073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | if (mddev->raid_disks == 0) { |
| 1075 | mddev->major_version = 0; |
| 1076 | mddev->minor_version = sb->minor_version; |
| 1077 | mddev->patch_version = sb->patch_version; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1078 | mddev->external = 0; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1079 | mddev->chunk_sectors = sb->chunk_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | mddev->ctime = sb->ctime; |
| 1081 | mddev->utime = sb->utime; |
| 1082 | mddev->level = sb->level; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 1083 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | mddev->layout = sb->layout; |
| 1085 | mddev->raid_disks = sb->raid_disks; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1086 | mddev->dev_sectors = sb->size * 2; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1087 | mddev->events = ev1; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1088 | mddev->bitmap_info.offset = 0; |
| 1089 | mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1091 | if (mddev->minor_version >= 91) { |
| 1092 | mddev->reshape_position = sb->reshape_position; |
| 1093 | mddev->delta_disks = sb->delta_disks; |
| 1094 | mddev->new_level = sb->new_level; |
| 1095 | mddev->new_layout = sb->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1096 | mddev->new_chunk_sectors = sb->new_chunk >> 9; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1097 | } else { |
| 1098 | mddev->reshape_position = MaxSector; |
| 1099 | mddev->delta_disks = 0; |
| 1100 | mddev->new_level = mddev->level; |
| 1101 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1102 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1103 | } |
| 1104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | if (sb->state & (1<<MD_SB_CLEAN)) |
| 1106 | mddev->recovery_cp = MaxSector; |
| 1107 | else { |
| 1108 | if (sb->events_hi == sb->cp_events_hi && |
| 1109 | sb->events_lo == sb->cp_events_lo) { |
| 1110 | mddev->recovery_cp = sb->recovery_cp; |
| 1111 | } else |
| 1112 | mddev->recovery_cp = 0; |
| 1113 | } |
| 1114 | |
| 1115 | memcpy(mddev->uuid+0, &sb->set_uuid0, 4); |
| 1116 | memcpy(mddev->uuid+4, &sb->set_uuid1, 4); |
| 1117 | memcpy(mddev->uuid+8, &sb->set_uuid2, 4); |
| 1118 | memcpy(mddev->uuid+12,&sb->set_uuid3, 4); |
| 1119 | |
| 1120 | mddev->max_disks = MD_SB_DISKS; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1121 | |
| 1122 | if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1123 | mddev->bitmap_info.file == NULL) |
| 1124 | mddev->bitmap_info.offset = |
| 1125 | mddev->bitmap_info.default_offset; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1126 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1127 | } else if (mddev->pers == NULL) { |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1128 | /* Insist on good event counter while assembling, except |
| 1129 | * for spares (which don't need an event count) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | ++ev1; |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1131 | if (sb->disks[rdev->desc_nr].state & ( |
| 1132 | (1<<MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE))) |
| 1133 | if (ev1 < mddev->events) |
| 1134 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1135 | } else if (mddev->bitmap) { |
| 1136 | /* if adding to array with a bitmap, then we can accept an |
| 1137 | * older device ... but not too old. |
| 1138 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1139 | if (ev1 < mddev->bitmap->events_cleared) |
| 1140 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1141 | } else { |
| 1142 | if (ev1 < mddev->events) |
| 1143 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1144 | return 0; |
| 1145 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | if (mddev->level != LEVEL_MULTIPATH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | desc = sb->disks + rdev->desc_nr; |
| 1149 | |
| 1150 | if (desc->state & (1<<MD_DISK_FAULTY)) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1151 | set_bit(Faulty, &rdev->flags); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 1152 | else if (desc->state & (1<<MD_DISK_SYNC) /* && |
| 1153 | desc->raid_disk < mddev->raid_disks */) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1154 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | rdev->raid_disk = desc->raid_disk; |
NeilBrown | 0261cd9 | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1156 | } else if (desc->state & (1<<MD_DISK_ACTIVE)) { |
| 1157 | /* active but not in sync implies recovery up to |
| 1158 | * reshape position. We don't know exactly where |
| 1159 | * that is, so set to zero for now */ |
| 1160 | if (mddev->minor_version >= 91) { |
| 1161 | rdev->recovery_offset = 0; |
| 1162 | rdev->raid_disk = desc->raid_disk; |
| 1163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1165 | if (desc->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 1166 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1167 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1168 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | /* |
| 1173 | * sync_super for 0.90.0 |
| 1174 | */ |
| 1175 | static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1176 | { |
| 1177 | mdp_super_t *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | mdk_rdev_t *rdev2; |
| 1179 | int next_spare = mddev->raid_disks; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | |
| 1182 | /* make rdev->sb match mddev data.. |
| 1183 | * |
| 1184 | * 1/ zero out disks |
| 1185 | * 2/ Add info for each disk, keeping track of highest desc_nr (next_spare); |
| 1186 | * 3/ any empty disks < next_spare become removed |
| 1187 | * |
| 1188 | * disks[0] gets initialised to REMOVED because |
| 1189 | * we cannot be sure from other fields if it has |
| 1190 | * been initialised or not. |
| 1191 | */ |
| 1192 | int i; |
| 1193 | int active=0, working=0,failed=0,spare=0,nr_disks=0; |
| 1194 | |
NeilBrown | 6118156 | 2005-09-09 16:24:02 -0700 | [diff] [blame] | 1195 | rdev->sb_size = MD_SB_BYTES; |
| 1196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 1198 | |
| 1199 | memset(sb, 0, sizeof(*sb)); |
| 1200 | |
| 1201 | sb->md_magic = MD_SB_MAGIC; |
| 1202 | sb->major_version = mddev->major_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | sb->patch_version = mddev->patch_version; |
| 1204 | sb->gvalid_words = 0; /* ignored */ |
| 1205 | memcpy(&sb->set_uuid0, mddev->uuid+0, 4); |
| 1206 | memcpy(&sb->set_uuid1, mddev->uuid+4, 4); |
| 1207 | memcpy(&sb->set_uuid2, mddev->uuid+8, 4); |
| 1208 | memcpy(&sb->set_uuid3, mddev->uuid+12,4); |
| 1209 | |
| 1210 | sb->ctime = mddev->ctime; |
| 1211 | sb->level = mddev->level; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1212 | sb->size = mddev->dev_sectors / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | sb->raid_disks = mddev->raid_disks; |
| 1214 | sb->md_minor = mddev->md_minor; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1215 | sb->not_persistent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | sb->utime = mddev->utime; |
| 1217 | sb->state = 0; |
| 1218 | sb->events_hi = (mddev->events>>32); |
| 1219 | sb->events_lo = (u32)mddev->events; |
| 1220 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1221 | if (mddev->reshape_position == MaxSector) |
| 1222 | sb->minor_version = 90; |
| 1223 | else { |
| 1224 | sb->minor_version = 91; |
| 1225 | sb->reshape_position = mddev->reshape_position; |
| 1226 | sb->new_level = mddev->new_level; |
| 1227 | sb->delta_disks = mddev->delta_disks; |
| 1228 | sb->new_layout = mddev->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1229 | sb->new_chunk = mddev->new_chunk_sectors << 9; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1230 | } |
| 1231 | mddev->minor_version = sb->minor_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | if (mddev->in_sync) |
| 1233 | { |
| 1234 | sb->recovery_cp = mddev->recovery_cp; |
| 1235 | sb->cp_events_hi = (mddev->events>>32); |
| 1236 | sb->cp_events_lo = (u32)mddev->events; |
| 1237 | if (mddev->recovery_cp == MaxSector) |
| 1238 | sb->state = (1<< MD_SB_CLEAN); |
| 1239 | } else |
| 1240 | sb->recovery_cp = 0; |
| 1241 | |
| 1242 | sb->layout = mddev->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1243 | sb->chunk_size = mddev->chunk_sectors << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1245 | if (mddev->bitmap && mddev->bitmap_info.file == NULL) |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1246 | sb->state |= (1<<MD_SB_BITMAP_PRESENT); |
| 1247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | sb->disks[0].state = (1<<MD_DISK_REMOVED); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1249 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | mdp_disk_t *d; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1251 | int desc_nr; |
NeilBrown | 0261cd9 | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1252 | int is_active = test_bit(In_sync, &rdev2->flags); |
| 1253 | |
| 1254 | if (rdev2->raid_disk >= 0 && |
| 1255 | sb->minor_version >= 91) |
| 1256 | /* we have nowhere to store the recovery_offset, |
| 1257 | * but if it is not below the reshape_position, |
| 1258 | * we can piggy-back on that. |
| 1259 | */ |
| 1260 | is_active = 1; |
| 1261 | if (rdev2->raid_disk < 0 || |
| 1262 | test_bit(Faulty, &rdev2->flags)) |
| 1263 | is_active = 0; |
| 1264 | if (is_active) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1265 | desc_nr = rdev2->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | else |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1267 | desc_nr = next_spare++; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1268 | rdev2->desc_nr = desc_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | d = &sb->disks[rdev2->desc_nr]; |
| 1270 | nr_disks++; |
| 1271 | d->number = rdev2->desc_nr; |
| 1272 | d->major = MAJOR(rdev2->bdev->bd_dev); |
| 1273 | d->minor = MINOR(rdev2->bdev->bd_dev); |
NeilBrown | 0261cd9 | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1274 | if (is_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | d->raid_disk = rdev2->raid_disk; |
| 1276 | else |
| 1277 | d->raid_disk = rdev2->desc_nr; /* compatibility */ |
NeilBrown | 1be7892 | 2006-03-27 01:18:03 -0800 | [diff] [blame] | 1278 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | d->state = (1<<MD_DISK_FAULTY); |
NeilBrown | 0261cd9 | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1280 | else if (is_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | d->state = (1<<MD_DISK_ACTIVE); |
NeilBrown | 0261cd9 | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1282 | if (test_bit(In_sync, &rdev2->flags)) |
| 1283 | d->state |= (1<<MD_DISK_SYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | active++; |
| 1285 | working++; |
| 1286 | } else { |
| 1287 | d->state = 0; |
| 1288 | spare++; |
| 1289 | working++; |
| 1290 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1291 | if (test_bit(WriteMostly, &rdev2->flags)) |
| 1292 | d->state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | /* now set the "removed" and "faulty" bits on any missing devices */ |
| 1295 | for (i=0 ; i < mddev->raid_disks ; i++) { |
| 1296 | mdp_disk_t *d = &sb->disks[i]; |
| 1297 | if (d->state == 0 && d->number == 0) { |
| 1298 | d->number = i; |
| 1299 | d->raid_disk = i; |
| 1300 | d->state = (1<<MD_DISK_REMOVED); |
| 1301 | d->state |= (1<<MD_DISK_FAULTY); |
| 1302 | failed++; |
| 1303 | } |
| 1304 | } |
| 1305 | sb->nr_disks = nr_disks; |
| 1306 | sb->active_disks = active; |
| 1307 | sb->working_disks = working; |
| 1308 | sb->failed_disks = failed; |
| 1309 | sb->spare_disks = spare; |
| 1310 | |
| 1311 | sb->this_disk = sb->disks[rdev->desc_nr]; |
| 1312 | sb->sb_csum = calc_sb_csum(sb); |
| 1313 | } |
| 1314 | |
| 1315 | /* |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1316 | * rdev_size_change for 0.90.0 |
| 1317 | */ |
| 1318 | static unsigned long long |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1319 | 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] | 1320 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1321 | if (num_sectors && num_sectors < rdev->mddev->dev_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1322 | return 0; /* component must fit device */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1323 | if (rdev->mddev->bitmap_info.offset) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1324 | return 0; /* can't move bitmap */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1325 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1326 | if (!num_sectors || num_sectors > rdev->sb_start) |
| 1327 | num_sectors = rdev->sb_start; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1328 | md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1329 | rdev->sb_page); |
| 1330 | md_super_wait(rdev->mddev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1331 | return num_sectors / 2; /* kB for sysfs */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | * version 1 superblock |
| 1337 | */ |
| 1338 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1339 | static __le32 calc_sb_1_csum(struct mdp_superblock_1 * sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | { |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1341 | __le32 disk_csum; |
| 1342 | u32 csum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | unsigned long long newcsum; |
| 1344 | int size = 256 + le32_to_cpu(sb->max_dev)*2; |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1345 | __le32 *isuper = (__le32*)sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | int i; |
| 1347 | |
| 1348 | disk_csum = sb->sb_csum; |
| 1349 | sb->sb_csum = 0; |
| 1350 | newcsum = 0; |
| 1351 | for (i=0; size>=4; size -= 4 ) |
| 1352 | newcsum += le32_to_cpu(*isuper++); |
| 1353 | |
| 1354 | if (size == 2) |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1355 | newcsum += le16_to_cpu(*(__le16*) isuper); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
| 1357 | csum = (newcsum & 0xffffffff) + (newcsum >> 32); |
| 1358 | sb->sb_csum = disk_csum; |
| 1359 | return cpu_to_le32(csum); |
| 1360 | } |
| 1361 | |
| 1362 | static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 1363 | { |
| 1364 | struct mdp_superblock_1 *sb; |
| 1365 | int ret; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1366 | sector_t sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1368 | int bmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
| 1370 | /* |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1371 | * Calculate the position of the superblock in 512byte sectors. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | * It is always aligned to a 4K boundary and |
| 1373 | * depeding on minor_version, it can be: |
| 1374 | * 0: At least 8K, but less than 12K, from end of device |
| 1375 | * 1: At start of device |
| 1376 | * 2: 4K from start of device. |
| 1377 | */ |
| 1378 | switch(minor_version) { |
| 1379 | case 0: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1380 | sb_start = rdev->bdev->bd_inode->i_size >> 9; |
| 1381 | sb_start -= 8*2; |
| 1382 | sb_start &= ~(sector_t)(4*2-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | break; |
| 1384 | case 1: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1385 | sb_start = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | break; |
| 1387 | case 2: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1388 | sb_start = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | break; |
| 1390 | default: |
| 1391 | return -EINVAL; |
| 1392 | } |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1393 | rdev->sb_start = sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1395 | /* superblock is rarely larger than 1K, but it can be larger, |
| 1396 | * and it is safe to read 4k, so we do that |
| 1397 | */ |
| 1398 | ret = read_disk_sb(rdev, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | if (ret) return ret; |
| 1400 | |
| 1401 | |
| 1402 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1403 | |
| 1404 | if (sb->magic != cpu_to_le32(MD_SB_MAGIC) || |
| 1405 | sb->major_version != cpu_to_le32(1) || |
| 1406 | le32_to_cpu(sb->max_dev) > (4096-256)/2 || |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1407 | le64_to_cpu(sb->super_offset) != rdev->sb_start || |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1408 | (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | return -EINVAL; |
| 1410 | |
| 1411 | if (calc_sb_1_csum(sb) != sb->sb_csum) { |
| 1412 | printk("md: invalid superblock checksum on %s\n", |
| 1413 | bdevname(rdev->bdev,b)); |
| 1414 | return -EINVAL; |
| 1415 | } |
| 1416 | if (le64_to_cpu(sb->data_size) < 10) { |
| 1417 | printk("md: data_size too small on %s\n", |
| 1418 | bdevname(rdev->bdev,b)); |
| 1419 | return -EINVAL; |
| 1420 | } |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | rdev->preferred_minor = 0xffff; |
| 1423 | rdev->data_offset = le64_to_cpu(sb->data_offset); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1424 | atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1426 | rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256; |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 1427 | bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1428 | if (rdev->sb_size & bmask) |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1429 | rdev->sb_size = (rdev->sb_size | bmask) + 1; |
| 1430 | |
| 1431 | if (minor_version |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1432 | && rdev->data_offset < sb_start + (rdev->sb_size/512)) |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1433 | return -EINVAL; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1434 | |
NeilBrown | 31b65a0 | 2006-07-10 04:44:14 -0700 | [diff] [blame] | 1435 | if (sb->level == cpu_to_le32(LEVEL_MULTIPATH)) |
| 1436 | rdev->desc_nr = -1; |
| 1437 | else |
| 1438 | rdev->desc_nr = le32_to_cpu(sb->dev_number); |
| 1439 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1440 | if (!refdev) { |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1441 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1442 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | __u64 ev1, ev2; |
| 1444 | struct mdp_superblock_1 *refsb = |
| 1445 | (struct mdp_superblock_1*)page_address(refdev->sb_page); |
| 1446 | |
| 1447 | if (memcmp(sb->set_uuid, refsb->set_uuid, 16) != 0 || |
| 1448 | sb->level != refsb->level || |
| 1449 | sb->layout != refsb->layout || |
| 1450 | sb->chunksize != refsb->chunksize) { |
| 1451 | printk(KERN_WARNING "md: %s has strangely different" |
| 1452 | " superblock to %s\n", |
| 1453 | bdevname(rdev->bdev,b), |
| 1454 | bdevname(refdev->bdev,b2)); |
| 1455 | return -EINVAL; |
| 1456 | } |
| 1457 | ev1 = le64_to_cpu(sb->events); |
| 1458 | ev2 = le64_to_cpu(refsb->events); |
| 1459 | |
| 1460 | if (ev1 > ev2) |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1461 | ret = 1; |
| 1462 | else |
| 1463 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | } |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1465 | if (minor_version) |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1466 | rdev->sectors = (rdev->bdev->bd_inode->i_size >> 9) - |
| 1467 | le64_to_cpu(sb->data_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | else |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1469 | rdev->sectors = rdev->sb_start; |
| 1470 | if (rdev->sectors < le64_to_cpu(sb->data_size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | return -EINVAL; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1472 | rdev->sectors = le64_to_cpu(sb->data_size); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1473 | if (le64_to_cpu(sb->size) > rdev->sectors) |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1474 | return -EINVAL; |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1475 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1479 | { |
| 1480 | 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] | 1481 | __u64 ev1 = le64_to_cpu(sb->events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1483 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1484 | clear_bit(Faulty, &rdev->flags); |
| 1485 | clear_bit(In_sync, &rdev->flags); |
| 1486 | clear_bit(WriteMostly, &rdev->flags); |
| 1487 | clear_bit(BarriersNotsupp, &rdev->flags); |
| 1488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | if (mddev->raid_disks == 0) { |
| 1490 | mddev->major_version = 1; |
| 1491 | mddev->patch_version = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1492 | mddev->external = 0; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1493 | mddev->chunk_sectors = le32_to_cpu(sb->chunksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | mddev->ctime = le64_to_cpu(sb->ctime) & ((1ULL << 32)-1); |
| 1495 | mddev->utime = le64_to_cpu(sb->utime) & ((1ULL << 32)-1); |
| 1496 | mddev->level = le32_to_cpu(sb->level); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 1497 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | mddev->layout = le32_to_cpu(sb->layout); |
| 1499 | mddev->raid_disks = le32_to_cpu(sb->raid_disks); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1500 | mddev->dev_sectors = le64_to_cpu(sb->size); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1501 | mddev->events = ev1; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1502 | mddev->bitmap_info.offset = 0; |
| 1503 | mddev->bitmap_info.default_offset = 1024 >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | |
| 1505 | mddev->recovery_cp = le64_to_cpu(sb->resync_offset); |
| 1506 | memcpy(mddev->uuid, sb->set_uuid, 16); |
| 1507 | |
| 1508 | mddev->max_disks = (4096-256)/2; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1509 | |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1510 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1511 | mddev->bitmap_info.file == NULL ) |
| 1512 | mddev->bitmap_info.offset = |
| 1513 | (__s32)le32_to_cpu(sb->bitmap_offset); |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1514 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1515 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) { |
| 1516 | mddev->reshape_position = le64_to_cpu(sb->reshape_position); |
| 1517 | mddev->delta_disks = le32_to_cpu(sb->delta_disks); |
| 1518 | mddev->new_level = le32_to_cpu(sb->new_level); |
| 1519 | mddev->new_layout = le32_to_cpu(sb->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1520 | mddev->new_chunk_sectors = le32_to_cpu(sb->new_chunk); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1521 | } else { |
| 1522 | mddev->reshape_position = MaxSector; |
| 1523 | mddev->delta_disks = 0; |
| 1524 | mddev->new_level = mddev->level; |
| 1525 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1526 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1527 | } |
| 1528 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1529 | } else if (mddev->pers == NULL) { |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1530 | /* Insist of good event counter while assembling, except for |
| 1531 | * spares (which don't need an event count) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | ++ev1; |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1533 | if (rdev->desc_nr >= 0 && |
| 1534 | rdev->desc_nr < le32_to_cpu(sb->max_dev) && |
| 1535 | le16_to_cpu(sb->dev_roles[rdev->desc_nr]) < 0xfffe) |
| 1536 | if (ev1 < mddev->events) |
| 1537 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1538 | } else if (mddev->bitmap) { |
| 1539 | /* If adding to array with a bitmap, then we can accept an |
| 1540 | * older device, but not too old. |
| 1541 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1542 | if (ev1 < mddev->bitmap->events_cleared) |
| 1543 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1544 | } else { |
| 1545 | if (ev1 < mddev->events) |
| 1546 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1547 | return 0; |
| 1548 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | if (mddev->level != LEVEL_MULTIPATH) { |
| 1550 | int role; |
NeilBrown | 3673f30 | 2009-08-03 10:59:56 +1000 | [diff] [blame] | 1551 | if (rdev->desc_nr < 0 || |
| 1552 | rdev->desc_nr >= le32_to_cpu(sb->max_dev)) { |
| 1553 | role = 0xffff; |
| 1554 | rdev->desc_nr = -1; |
| 1555 | } else |
| 1556 | role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | switch(role) { |
| 1558 | case 0xffff: /* spare */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | break; |
| 1560 | case 0xfffe: /* faulty */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1561 | set_bit(Faulty, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | break; |
| 1563 | default: |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1564 | if ((le32_to_cpu(sb->feature_map) & |
| 1565 | MD_FEATURE_RECOVERY_OFFSET)) |
| 1566 | rdev->recovery_offset = le64_to_cpu(sb->recovery_offset); |
| 1567 | else |
| 1568 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | rdev->raid_disk = role; |
| 1570 | break; |
| 1571 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1572 | if (sb->devflags & WriteMostly1) |
| 1573 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1574 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1575 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1581 | { |
| 1582 | struct mdp_superblock_1 *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | mdk_rdev_t *rdev2; |
| 1584 | int max_dev, i; |
| 1585 | /* make rdev->sb match mddev and rdev data. */ |
| 1586 | |
| 1587 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1588 | |
| 1589 | sb->feature_map = 0; |
| 1590 | sb->pad0 = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1591 | sb->recovery_offset = cpu_to_le64(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | memset(sb->pad1, 0, sizeof(sb->pad1)); |
| 1593 | memset(sb->pad2, 0, sizeof(sb->pad2)); |
| 1594 | memset(sb->pad3, 0, sizeof(sb->pad3)); |
| 1595 | |
| 1596 | sb->utime = cpu_to_le64((__u64)mddev->utime); |
| 1597 | sb->events = cpu_to_le64(mddev->events); |
| 1598 | if (mddev->in_sync) |
| 1599 | sb->resync_offset = cpu_to_le64(mddev->recovery_cp); |
| 1600 | else |
| 1601 | sb->resync_offset = cpu_to_le64(0); |
| 1602 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1603 | sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors)); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1604 | |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1605 | sb->raid_disks = cpu_to_le32(mddev->raid_disks); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1606 | sb->size = cpu_to_le64(mddev->dev_sectors); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1607 | sb->chunksize = cpu_to_le32(mddev->chunk_sectors); |
NeilBrown | 62e1e38 | 2009-05-26 09:40:59 +1000 | [diff] [blame] | 1608 | sb->level = cpu_to_le32(mddev->level); |
| 1609 | sb->layout = cpu_to_le32(mddev->layout); |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1610 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1611 | if (mddev->bitmap && mddev->bitmap_info.file == NULL) { |
| 1612 | sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_info.offset); |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1613 | sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1614 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1615 | |
| 1616 | if (rdev->raid_disk >= 0 && |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1617 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 93be75f | 2009-12-14 12:50:06 +1100 | [diff] [blame] | 1618 | sb->feature_map |= |
| 1619 | cpu_to_le32(MD_FEATURE_RECOVERY_OFFSET); |
| 1620 | sb->recovery_offset = |
| 1621 | cpu_to_le64(rdev->recovery_offset); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1624 | if (mddev->reshape_position != MaxSector) { |
| 1625 | sb->feature_map |= cpu_to_le32(MD_FEATURE_RESHAPE_ACTIVE); |
| 1626 | sb->reshape_position = cpu_to_le64(mddev->reshape_position); |
| 1627 | sb->new_layout = cpu_to_le32(mddev->new_layout); |
| 1628 | sb->delta_disks = cpu_to_le32(mddev->delta_disks); |
| 1629 | sb->new_level = cpu_to_le32(mddev->new_level); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1630 | sb->new_chunk = cpu_to_le32(mddev->new_chunk_sectors); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1631 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | max_dev = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1634 | list_for_each_entry(rdev2, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | if (rdev2->desc_nr+1 > max_dev) |
| 1636 | max_dev = rdev2->desc_nr+1; |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1637 | |
NeilBrown | 70471da | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 1638 | if (max_dev > le32_to_cpu(sb->max_dev)) { |
| 1639 | int bmask; |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1640 | sb->max_dev = cpu_to_le32(max_dev); |
NeilBrown | 70471da | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 1641 | rdev->sb_size = max_dev * 2 + 256; |
| 1642 | bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1; |
| 1643 | if (rdev->sb_size & bmask) |
| 1644 | rdev->sb_size = (rdev->sb_size | bmask) + 1; |
| 1645 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | for (i=0; i<max_dev;i++) |
| 1647 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
| 1648 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1649 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | i = rdev2->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1651 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1653 | else if (test_bit(In_sync, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
NeilBrown | 93be75f | 2009-12-14 12:50:06 +1100 | [diff] [blame] | 1655 | else if (rdev2->raid_disk >= 0) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1656 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | else |
| 1658 | sb->dev_roles[i] = cpu_to_le16(0xffff); |
| 1659 | } |
| 1660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | sb->sb_csum = calc_sb_1_csum(sb); |
| 1662 | } |
| 1663 | |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1664 | static unsigned long long |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1665 | 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] | 1666 | { |
| 1667 | struct mdp_superblock_1 *sb; |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1668 | sector_t max_sectors; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1669 | if (num_sectors && num_sectors < rdev->mddev->dev_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1670 | return 0; /* component must fit device */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1671 | if (rdev->sb_start < rdev->data_offset) { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1672 | /* minor versions 1 and 2; superblock before data */ |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1673 | max_sectors = rdev->bdev->bd_inode->i_size >> 9; |
| 1674 | max_sectors -= rdev->data_offset; |
| 1675 | if (!num_sectors || num_sectors > max_sectors) |
| 1676 | num_sectors = max_sectors; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1677 | } else if (rdev->mddev->bitmap_info.offset) { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1678 | /* minor version 0 with bitmap we can't move */ |
| 1679 | return 0; |
| 1680 | } else { |
| 1681 | /* minor version 0; superblock after data */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1682 | sector_t sb_start; |
| 1683 | sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2; |
| 1684 | sb_start &= ~(sector_t)(4*2 - 1); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1685 | max_sectors = rdev->sectors + sb_start - rdev->sb_start; |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1686 | if (!num_sectors || num_sectors > max_sectors) |
| 1687 | num_sectors = max_sectors; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1688 | rdev->sb_start = sb_start; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1689 | } |
| 1690 | sb = (struct mdp_superblock_1 *) page_address(rdev->sb_page); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1691 | sb->data_size = cpu_to_le64(num_sectors); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1692 | sb->super_offset = rdev->sb_start; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1693 | sb->sb_csum = calc_sb_1_csum(sb); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1694 | md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1695 | rdev->sb_page); |
| 1696 | md_super_wait(rdev->mddev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1697 | return num_sectors / 2; /* kB for sysfs */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1698 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 1700 | static struct super_type super_types[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | [0] = { |
| 1702 | .name = "0.90.0", |
| 1703 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1704 | .load_super = super_90_load, |
| 1705 | .validate_super = super_90_validate, |
| 1706 | .sync_super = super_90_sync, |
| 1707 | .rdev_size_change = super_90_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | }, |
| 1709 | [1] = { |
| 1710 | .name = "md-1", |
| 1711 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1712 | .load_super = super_1_load, |
| 1713 | .validate_super = super_1_validate, |
| 1714 | .sync_super = super_1_sync, |
| 1715 | .rdev_size_change = super_1_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | }, |
| 1717 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | |
| 1719 | static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2) |
| 1720 | { |
NeilBrown | 7dd5e7c | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1721 | mdk_rdev_t *rdev, *rdev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1723 | rcu_read_lock(); |
| 1724 | rdev_for_each_rcu(rdev, mddev1) |
| 1725 | rdev_for_each_rcu(rdev2, mddev2) |
NeilBrown | 7dd5e7c | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1726 | if (rdev->bdev->bd_contains == |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1727 | rdev2->bdev->bd_contains) { |
| 1728 | rcu_read_unlock(); |
NeilBrown | 7dd5e7c | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1729 | return 1; |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1730 | } |
| 1731 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | return 0; |
| 1733 | } |
| 1734 | |
| 1735 | static LIST_HEAD(pending_raid_disks); |
| 1736 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1737 | /* |
| 1738 | * Try to register data integrity profile for an mddev |
| 1739 | * |
| 1740 | * This is called when an array is started and after a disk has been kicked |
| 1741 | * from the array. It only succeeds if all working and active component devices |
| 1742 | * are integrity capable with matching profiles. |
| 1743 | */ |
| 1744 | int md_integrity_register(mddev_t *mddev) |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1745 | { |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1746 | mdk_rdev_t *rdev, *reference = NULL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1747 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1748 | if (list_empty(&mddev->disks)) |
| 1749 | return 0; /* nothing to do */ |
| 1750 | if (blk_get_integrity(mddev->gendisk)) |
| 1751 | return 0; /* already registered */ |
| 1752 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 1753 | /* skip spares and non-functional disks */ |
| 1754 | if (test_bit(Faulty, &rdev->flags)) |
| 1755 | continue; |
| 1756 | if (rdev->raid_disk < 0) |
| 1757 | continue; |
| 1758 | /* |
| 1759 | * If at least one rdev is not integrity capable, we can not |
| 1760 | * enable data integrity for the md device. |
| 1761 | */ |
| 1762 | if (!bdev_get_integrity(rdev->bdev)) |
| 1763 | return -EINVAL; |
| 1764 | if (!reference) { |
| 1765 | /* Use the first rdev as the reference */ |
| 1766 | reference = rdev; |
| 1767 | continue; |
| 1768 | } |
| 1769 | /* does this rdev's profile match the reference profile? */ |
| 1770 | if (blk_integrity_compare(reference->bdev->bd_disk, |
| 1771 | rdev->bdev->bd_disk) < 0) |
| 1772 | return -EINVAL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1773 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1774 | /* |
| 1775 | * All component devices are integrity capable and have matching |
| 1776 | * profiles, register the common profile for the md device. |
| 1777 | */ |
| 1778 | if (blk_integrity_register(mddev->gendisk, |
| 1779 | bdev_get_integrity(reference->bdev)) != 0) { |
| 1780 | printk(KERN_ERR "md: failed to register integrity for %s\n", |
| 1781 | mdname(mddev)); |
| 1782 | return -EINVAL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1783 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1784 | printk(KERN_NOTICE "md: data integrity on %s enabled\n", |
| 1785 | mdname(mddev)); |
| 1786 | return 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1787 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1788 | EXPORT_SYMBOL(md_integrity_register); |
| 1789 | |
| 1790 | /* Disable data integrity if non-capable/non-matching disk is being added */ |
| 1791 | void md_integrity_add_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 1792 | { |
| 1793 | struct blk_integrity *bi_rdev = bdev_get_integrity(rdev->bdev); |
| 1794 | struct blk_integrity *bi_mddev = blk_get_integrity(mddev->gendisk); |
| 1795 | |
| 1796 | if (!bi_mddev) /* nothing to do */ |
| 1797 | return; |
| 1798 | if (rdev->raid_disk < 0) /* skip spares */ |
| 1799 | return; |
| 1800 | if (bi_rdev && blk_integrity_compare(mddev->gendisk, |
| 1801 | rdev->bdev->bd_disk) >= 0) |
| 1802 | return; |
| 1803 | printk(KERN_NOTICE "disabling data integrity on %s\n", mdname(mddev)); |
| 1804 | blk_integrity_unregister(mddev->gendisk); |
| 1805 | } |
| 1806 | EXPORT_SYMBOL(md_integrity_add_rdev); |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) |
| 1809 | { |
NeilBrown | 7dd5e7c | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1810 | char b[BDEVNAME_SIZE]; |
NeilBrown | f637b9f | 2005-11-08 21:39:37 -0800 | [diff] [blame] | 1811 | struct kobject *ko; |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1812 | char *s; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1813 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | |
| 1815 | if (rdev->mddev) { |
| 1816 | MD_BUG(); |
| 1817 | return -EINVAL; |
| 1818 | } |
Dan Williams | 11e2ede | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1819 | |
| 1820 | /* prevent duplicates */ |
| 1821 | if (find_rdev(mddev, rdev->bdev->bd_dev)) |
| 1822 | return -EEXIST; |
| 1823 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1824 | /* make sure rdev->sectors exceeds mddev->dev_sectors */ |
| 1825 | if (rdev->sectors && (mddev->dev_sectors == 0 || |
| 1826 | rdev->sectors < mddev->dev_sectors)) { |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1827 | if (mddev->pers) { |
| 1828 | /* Cannot change size, so fail |
| 1829 | * If mddev->level <= 0, then we don't care |
| 1830 | * about aligning sizes (e.g. linear) |
| 1831 | */ |
| 1832 | if (mddev->level > 0) |
| 1833 | return -ENOSPC; |
| 1834 | } else |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1835 | mddev->dev_sectors = rdev->sectors; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1836 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | |
| 1838 | /* Verify rdev->desc_nr is unique. |
| 1839 | * If it is -1, assign a free number, else |
| 1840 | * check number is not in use |
| 1841 | */ |
| 1842 | if (rdev->desc_nr < 0) { |
| 1843 | int choice = 0; |
| 1844 | if (mddev->pers) choice = mddev->raid_disks; |
| 1845 | while (find_rdev_nr(mddev, choice)) |
| 1846 | choice++; |
| 1847 | rdev->desc_nr = choice; |
| 1848 | } else { |
| 1849 | if (find_rdev_nr(mddev, rdev->desc_nr)) |
| 1850 | return -EBUSY; |
| 1851 | } |
NeilBrown | de01dfa | 2009-02-06 18:02:46 +1100 | [diff] [blame] | 1852 | if (mddev->max_disks && rdev->desc_nr >= mddev->max_disks) { |
| 1853 | printk(KERN_WARNING "md: %s: array is limited to %d devices\n", |
| 1854 | mdname(mddev), mddev->max_disks); |
| 1855 | return -EBUSY; |
| 1856 | } |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1857 | bdevname(rdev->bdev,b); |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1858 | while ( (s=strchr(b, '/')) != NULL) |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1859 | *s = '!'; |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | rdev->mddev = mddev; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1862 | printk(KERN_INFO "md: bind<%s>\n", b); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1863 | |
Greg Kroah-Hartman | b2d6db5 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1864 | if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b))) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1865 | goto fail; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1866 | |
Tejun Heo | 0762b8b | 2008-08-25 19:56:12 +0900 | [diff] [blame] | 1867 | ko = &part_to_dev(rdev->bdev->bd_part)->kobj; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 1868 | if (sysfs_create_link(&rdev->kobj, ko, "block")) |
| 1869 | /* failure here is OK */; |
| 1870 | rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state"); |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 1871 | |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1872 | list_add_rcu(&rdev->same_set, &mddev->disks); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1873 | bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); |
NeilBrown | 4044ba5 | 2009-01-09 08:31:11 +1100 | [diff] [blame] | 1874 | |
| 1875 | /* May as well allow recovery to be retried once */ |
| 1876 | mddev->recovery_disabled = 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | return 0; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1879 | |
| 1880 | fail: |
| 1881 | printk(KERN_WARNING "md: failed to register dev-%s for %s\n", |
| 1882 | b, mdname(mddev)); |
| 1883 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1886 | static void md_delayed_delete(struct work_struct *ws) |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1887 | { |
| 1888 | mdk_rdev_t *rdev = container_of(ws, mdk_rdev_t, del_work); |
| 1889 | kobject_del(&rdev->kobj); |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1890 | kobject_put(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | static void unbind_rdev_from_array(mdk_rdev_t * rdev) |
| 1894 | { |
| 1895 | char b[BDEVNAME_SIZE]; |
| 1896 | if (!rdev->mddev) { |
| 1897 | MD_BUG(); |
| 1898 | return; |
| 1899 | } |
Jun'ichi Nomura | 5463c79 | 2006-03-27 01:17:58 -0800 | [diff] [blame] | 1900 | bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk); |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1901 | list_del_rcu(&rdev->same_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); |
| 1903 | rdev->mddev = NULL; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1904 | sysfs_remove_link(&rdev->kobj, "block"); |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 1905 | sysfs_put(rdev->sysfs_state); |
| 1906 | rdev->sysfs_state = NULL; |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1907 | /* We need to delay this, otherwise we can deadlock when |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1908 | * writing to 'remove' to "dev/state". We also need |
| 1909 | * to delay it due to rcu usage. |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1910 | */ |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1911 | synchronize_rcu(); |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1912 | INIT_WORK(&rdev->del_work, md_delayed_delete); |
| 1913 | kobject_get(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1914 | schedule_work(&rdev->del_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | /* |
| 1918 | * prevent the device from being mounted, repartitioned or |
| 1919 | * otherwise reused by a RAID array (or any other kernel |
| 1920 | * subsystem), by bd_claiming the device. |
| 1921 | */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1922 | 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] | 1923 | { |
| 1924 | int err = 0; |
| 1925 | struct block_device *bdev; |
| 1926 | char b[BDEVNAME_SIZE]; |
| 1927 | |
Peter Zijlstra | 2e7b651 | 2006-12-08 02:36:13 -0800 | [diff] [blame] | 1928 | bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | if (IS_ERR(bdev)) { |
| 1930 | printk(KERN_ERR "md: could not open %s.\n", |
| 1931 | __bdevname(dev, b)); |
| 1932 | return PTR_ERR(bdev); |
| 1933 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1934 | err = bd_claim(bdev, shared ? (mdk_rdev_t *)lock_rdev : rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | if (err) { |
| 1936 | printk(KERN_ERR "md: could not bd_claim %s.\n", |
| 1937 | bdevname(bdev, b)); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 1938 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | return err; |
| 1940 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1941 | if (!shared) |
| 1942 | set_bit(AllReserved, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | rdev->bdev = bdev; |
| 1944 | return err; |
| 1945 | } |
| 1946 | |
| 1947 | static void unlock_rdev(mdk_rdev_t *rdev) |
| 1948 | { |
| 1949 | struct block_device *bdev = rdev->bdev; |
| 1950 | rdev->bdev = NULL; |
| 1951 | if (!bdev) |
| 1952 | MD_BUG(); |
| 1953 | bd_release(bdev); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 1954 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | void md_autodetect_dev(dev_t dev); |
| 1958 | |
| 1959 | static void export_rdev(mdk_rdev_t * rdev) |
| 1960 | { |
| 1961 | char b[BDEVNAME_SIZE]; |
| 1962 | printk(KERN_INFO "md: export_rdev(%s)\n", |
| 1963 | bdevname(rdev->bdev,b)); |
| 1964 | if (rdev->mddev) |
| 1965 | MD_BUG(); |
| 1966 | free_disk_sb(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | #ifndef MODULE |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1968 | if (test_bit(AutoDetected, &rdev->flags)) |
| 1969 | md_autodetect_dev(rdev->bdev->bd_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | #endif |
| 1971 | unlock_rdev(rdev); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1972 | kobject_put(&rdev->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | static void kick_rdev_from_array(mdk_rdev_t * rdev) |
| 1976 | { |
| 1977 | unbind_rdev_from_array(rdev); |
| 1978 | export_rdev(rdev); |
| 1979 | } |
| 1980 | |
| 1981 | static void export_array(mddev_t *mddev) |
| 1982 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1983 | mdk_rdev_t *rdev, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1985 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | if (!rdev->mddev) { |
| 1987 | MD_BUG(); |
| 1988 | continue; |
| 1989 | } |
| 1990 | kick_rdev_from_array(rdev); |
| 1991 | } |
| 1992 | if (!list_empty(&mddev->disks)) |
| 1993 | MD_BUG(); |
| 1994 | mddev->raid_disks = 0; |
| 1995 | mddev->major_version = 0; |
| 1996 | } |
| 1997 | |
| 1998 | static void print_desc(mdp_disk_t *desc) |
| 1999 | { |
| 2000 | printk(" DISK<N:%d,(%d,%d),R:%d,S:%d>\n", desc->number, |
| 2001 | desc->major,desc->minor,desc->raid_disk,desc->state); |
| 2002 | } |
| 2003 | |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2004 | static void print_sb_90(mdp_super_t *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | { |
| 2006 | int i; |
| 2007 | |
| 2008 | printk(KERN_INFO |
| 2009 | "md: SB: (V:%d.%d.%d) ID:<%08x.%08x.%08x.%08x> CT:%08x\n", |
| 2010 | sb->major_version, sb->minor_version, sb->patch_version, |
| 2011 | sb->set_uuid0, sb->set_uuid1, sb->set_uuid2, sb->set_uuid3, |
| 2012 | sb->ctime); |
| 2013 | printk(KERN_INFO "md: L%d S%08d ND:%d RD:%d md%d LO:%d CS:%d\n", |
| 2014 | sb->level, sb->size, sb->nr_disks, sb->raid_disks, |
| 2015 | sb->md_minor, sb->layout, sb->chunk_size); |
| 2016 | printk(KERN_INFO "md: UT:%08x ST:%d AD:%d WD:%d" |
| 2017 | " FD:%d SD:%d CSUM:%08x E:%08lx\n", |
| 2018 | sb->utime, sb->state, sb->active_disks, sb->working_disks, |
| 2019 | sb->failed_disks, sb->spare_disks, |
| 2020 | sb->sb_csum, (unsigned long)sb->events_lo); |
| 2021 | |
| 2022 | printk(KERN_INFO); |
| 2023 | for (i = 0; i < MD_SB_DISKS; i++) { |
| 2024 | mdp_disk_t *desc; |
| 2025 | |
| 2026 | desc = sb->disks + i; |
| 2027 | if (desc->number || desc->major || desc->minor || |
| 2028 | desc->raid_disk || (desc->state && (desc->state != 4))) { |
| 2029 | printk(" D %2d: ", i); |
| 2030 | print_desc(desc); |
| 2031 | } |
| 2032 | } |
| 2033 | printk(KERN_INFO "md: THIS: "); |
| 2034 | print_desc(&sb->this_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2037 | static void print_sb_1(struct mdp_superblock_1 *sb) |
| 2038 | { |
| 2039 | __u8 *uuid; |
| 2040 | |
| 2041 | uuid = sb->set_uuid; |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 2042 | printk(KERN_INFO |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 2043 | "md: SB: (V:%u) (F:0x%08x) Array-ID:<%pU>\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 2044 | "md: Name: \"%s\" CT:%llu\n", |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2045 | le32_to_cpu(sb->major_version), |
| 2046 | le32_to_cpu(sb->feature_map), |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 2047 | uuid, |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2048 | sb->set_name, |
| 2049 | (unsigned long long)le64_to_cpu(sb->ctime) |
| 2050 | & MD_SUPERBLOCK_1_TIME_SEC_MASK); |
| 2051 | |
| 2052 | uuid = sb->device_uuid; |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 2053 | printk(KERN_INFO |
| 2054 | "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] | 2055 | " RO:%llu\n" |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 2056 | "md: Dev:%08x UUID: %pU\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 2057 | "md: (F:0x%08x) UT:%llu Events:%llu ResyncOffset:%llu CSUM:0x%08x\n" |
| 2058 | "md: (MaxDev:%u) \n", |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2059 | le32_to_cpu(sb->level), |
| 2060 | (unsigned long long)le64_to_cpu(sb->size), |
| 2061 | le32_to_cpu(sb->raid_disks), |
| 2062 | le32_to_cpu(sb->layout), |
| 2063 | le32_to_cpu(sb->chunksize), |
| 2064 | (unsigned long long)le64_to_cpu(sb->data_offset), |
| 2065 | (unsigned long long)le64_to_cpu(sb->data_size), |
| 2066 | (unsigned long long)le64_to_cpu(sb->super_offset), |
| 2067 | (unsigned long long)le64_to_cpu(sb->recovery_offset), |
| 2068 | le32_to_cpu(sb->dev_number), |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 2069 | uuid, |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2070 | sb->devflags, |
| 2071 | (unsigned long long)le64_to_cpu(sb->utime) & MD_SUPERBLOCK_1_TIME_SEC_MASK, |
| 2072 | (unsigned long long)le64_to_cpu(sb->events), |
| 2073 | (unsigned long long)le64_to_cpu(sb->resync_offset), |
| 2074 | le32_to_cpu(sb->sb_csum), |
| 2075 | le32_to_cpu(sb->max_dev) |
| 2076 | ); |
| 2077 | } |
| 2078 | |
| 2079 | static void print_rdev(mdk_rdev_t *rdev, int major_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | { |
| 2081 | char b[BDEVNAME_SIZE]; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2082 | printk(KERN_INFO "md: rdev %s, Sect:%08llu F:%d S:%d DN:%u\n", |
| 2083 | bdevname(rdev->bdev, b), (unsigned long long)rdev->sectors, |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2084 | test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags), |
| 2085 | rdev->desc_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | if (rdev->sb_loaded) { |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2087 | printk(KERN_INFO "md: rdev superblock (MJ:%d):\n", major_version); |
| 2088 | switch (major_version) { |
| 2089 | case 0: |
| 2090 | print_sb_90((mdp_super_t*)page_address(rdev->sb_page)); |
| 2091 | break; |
| 2092 | case 1: |
| 2093 | print_sb_1((struct mdp_superblock_1 *)page_address(rdev->sb_page)); |
| 2094 | break; |
| 2095 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | } else |
| 2097 | printk(KERN_INFO "md: no rdev superblock!\n"); |
| 2098 | } |
| 2099 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 2100 | static void md_print_devices(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2102 | struct list_head *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | mdk_rdev_t *rdev; |
| 2104 | mddev_t *mddev; |
| 2105 | char b[BDEVNAME_SIZE]; |
| 2106 | |
| 2107 | printk("\n"); |
| 2108 | printk("md: **********************************\n"); |
| 2109 | printk("md: * <COMPLETE RAID STATE PRINTOUT> *\n"); |
| 2110 | printk("md: **********************************\n"); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 2111 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 2113 | if (mddev->bitmap) |
| 2114 | bitmap_print_sb(mddev->bitmap); |
| 2115 | else |
| 2116 | printk("%s: ", mdname(mddev)); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2117 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 2119 | printk("\n"); |
| 2120 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2121 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2122 | print_rdev(rdev, mddev->major_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | } |
| 2124 | printk("md: **********************************\n"); |
| 2125 | printk("\n"); |
| 2126 | } |
| 2127 | |
| 2128 | |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2129 | static void sync_sbs(mddev_t * mddev, int nospares) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2131 | /* Update each superblock (in-memory image), but |
| 2132 | * if we are allowed to, skip spares which already |
| 2133 | * have the right event counter, or have one earlier |
| 2134 | * (which would mean they aren't being marked as dirty |
| 2135 | * with the rest of the array) |
| 2136 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | |
NeilBrown | 5e86510 | 2009-11-12 12:08:04 +1100 | [diff] [blame] | 2139 | /* First make sure individual recovery_offsets are correct */ |
| 2140 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 2141 | if (rdev->raid_disk >= 0 && |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 2142 | mddev->delta_disks >= 0 && |
NeilBrown | 5e86510 | 2009-11-12 12:08:04 +1100 | [diff] [blame] | 2143 | !test_bit(In_sync, &rdev->flags) && |
| 2144 | mddev->curr_resync_completed > rdev->recovery_offset) |
| 2145 | rdev->recovery_offset = mddev->curr_resync_completed; |
| 2146 | |
| 2147 | } |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2148 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2149 | if (rdev->sb_events == mddev->events || |
| 2150 | (nospares && |
| 2151 | rdev->raid_disk < 0 && |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2152 | rdev->sb_events+1 == mddev->events)) { |
| 2153 | /* Don't update this superblock */ |
| 2154 | rdev->sb_loaded = 2; |
| 2155 | } else { |
| 2156 | super_types[mddev->major_version]. |
| 2157 | sync_super(mddev, rdev); |
| 2158 | rdev->sb_loaded = 1; |
| 2159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | } |
| 2161 | } |
| 2162 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2163 | static void md_update_sb(mddev_t * mddev, int force_change) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | mdk_rdev_t *rdev; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2166 | int sync_req; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2167 | int nospares = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | |
NeilBrown | 1b57f13 | 2009-06-18 08:48:19 +1000 | [diff] [blame] | 2169 | mddev->utime = get_seconds(); |
NeilBrown | 8377bc8 | 2008-04-30 00:52:28 -0700 | [diff] [blame] | 2170 | if (mddev->external) |
| 2171 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | repeat: |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2173 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2174 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2175 | set_bit(MD_CHANGE_PENDING, &mddev->flags); |
| 2176 | if (test_and_clear_bit(MD_CHANGE_DEVS, &mddev->flags)) |
| 2177 | force_change = 1; |
| 2178 | if (test_and_clear_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 2179 | /* just a clean<-> dirty transition, possibly leave spares alone, |
| 2180 | * though if events isn't the right even/odd, we will have to do |
| 2181 | * spares after all |
| 2182 | */ |
| 2183 | nospares = 1; |
| 2184 | if (force_change) |
| 2185 | nospares = 0; |
| 2186 | if (mddev->degraded) |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2187 | /* If the array is degraded, then skipping spares is both |
| 2188 | * dangerous and fairly pointless. |
| 2189 | * Dangerous because a device that was removed from the array |
| 2190 | * might have a event_count that still looks up-to-date, |
| 2191 | * so it can be re-added without a resync. |
| 2192 | * Pointless because if there are any spares to skip, |
| 2193 | * then a recovery will happen and soon that array won't |
| 2194 | * be degraded any more and the spare can go back to sleep then. |
| 2195 | */ |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2196 | nospares = 0; |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2197 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2198 | sync_req = mddev->in_sync; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2199 | |
| 2200 | /* If this is just a dirty<->clean transition, and the array is clean |
| 2201 | * and 'events' is odd, we can roll back to the previous clean state */ |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2202 | if (nospares |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2203 | && (mddev->in_sync && mddev->recovery_cp == MaxSector) |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 2204 | && mddev->can_decrease_events |
| 2205 | && mddev->events != 1) { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2206 | mddev->events--; |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 2207 | mddev->can_decrease_events = 0; |
| 2208 | } else { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2209 | /* otherwise we have to go forward and ... */ |
| 2210 | mddev->events ++; |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 2211 | mddev->can_decrease_events = nospares; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2212 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | |
| 2214 | if (!mddev->events) { |
| 2215 | /* |
| 2216 | * oops, this 64-bit counter should never wrap. |
| 2217 | * Either we are in around ~1 trillion A.C., assuming |
| 2218 | * 1 reboot per second, or we have a bug: |
| 2219 | */ |
| 2220 | MD_BUG(); |
| 2221 | mddev->events --; |
| 2222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | |
| 2224 | /* |
| 2225 | * do not write anything to disk if using |
| 2226 | * nonpersistent superblocks |
| 2227 | */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2228 | if (!mddev->persistent) { |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2229 | if (!mddev->external) |
| 2230 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
| 2231 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2232 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 2233 | wake_up(&mddev->sb_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2235 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2236 | sync_sbs(mddev, nospares); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2237 | spin_unlock_irq(&mddev->write_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | |
| 2239 | dprintk(KERN_INFO |
| 2240 | "md: updating %s RAID superblock on device (in sync %d)\n", |
| 2241 | mdname(mddev),mddev->in_sync); |
| 2242 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 2243 | bitmap_update_sb(mddev->bitmap); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2244 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | char b[BDEVNAME_SIZE]; |
| 2246 | dprintk(KERN_INFO "md: "); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2247 | if (rdev->sb_loaded != 1) |
| 2248 | continue; /* no noise on spare devices */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2249 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | dprintk("(skipping faulty "); |
| 2251 | |
| 2252 | dprintk("%s ", bdevname(rdev->bdev,b)); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2253 | if (!test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2254 | md_super_write(mddev,rdev, |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 2255 | rdev->sb_start, rdev->sb_size, |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2256 | rdev->sb_page); |
| 2257 | dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", |
| 2258 | bdevname(rdev->bdev,b), |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 2259 | (unsigned long long)rdev->sb_start); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2260 | rdev->sb_events = mddev->events; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | } else |
| 2263 | dprintk(")\n"); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2264 | if (mddev->level == LEVEL_MULTIPATH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | /* only need to write one superblock... */ |
| 2266 | break; |
| 2267 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2268 | md_super_wait(mddev); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2269 | /* 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] | 2270 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2271 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2272 | if (mddev->in_sync != sync_req || |
| 2273 | test_bit(MD_CHANGE_DEVS, &mddev->flags)) { |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2274 | /* have to write it out again */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2275 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2276 | goto repeat; |
| 2277 | } |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2278 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2279 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 2280 | wake_up(&mddev->sb_wait); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 2281 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 2282 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
Andre Noll | 7f6ce76 | 2008-03-23 18:34:54 +0100 | [diff] [blame] | 2286 | /* words written to sysfs files may, or may not, be \n terminated. |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 2287 | * We want to accept with case. For this we use cmd_match. |
| 2288 | */ |
| 2289 | static int cmd_match(const char *cmd, const char *str) |
| 2290 | { |
| 2291 | /* See if cmd, written into a sysfs file, matches |
| 2292 | * str. They must either be the same, or cmd can |
| 2293 | * have a trailing newline |
| 2294 | */ |
| 2295 | while (*cmd && *str && *cmd == *str) { |
| 2296 | cmd++; |
| 2297 | str++; |
| 2298 | } |
| 2299 | if (*cmd == '\n') |
| 2300 | cmd++; |
| 2301 | if (*str || *cmd) |
| 2302 | return 0; |
| 2303 | return 1; |
| 2304 | } |
| 2305 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2306 | struct rdev_sysfs_entry { |
| 2307 | struct attribute attr; |
| 2308 | ssize_t (*show)(mdk_rdev_t *, char *); |
| 2309 | ssize_t (*store)(mdk_rdev_t *, const char *, size_t); |
| 2310 | }; |
| 2311 | |
| 2312 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2313 | state_show(mdk_rdev_t *rdev, char *page) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2314 | { |
| 2315 | char *sep = ""; |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2316 | size_t len = 0; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2317 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2318 | if (test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2319 | len+= sprintf(page+len, "%sfaulty",sep); |
| 2320 | sep = ","; |
| 2321 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2322 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2323 | len += sprintf(page+len, "%sin_sync",sep); |
| 2324 | sep = ","; |
| 2325 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2326 | if (test_bit(WriteMostly, &rdev->flags)) { |
| 2327 | len += sprintf(page+len, "%swrite_mostly",sep); |
| 2328 | sep = ","; |
| 2329 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2330 | if (test_bit(Blocked, &rdev->flags)) { |
| 2331 | len += sprintf(page+len, "%sblocked", sep); |
| 2332 | sep = ","; |
| 2333 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2334 | if (!test_bit(Faulty, &rdev->flags) && |
| 2335 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2336 | len += sprintf(page+len, "%sspare", sep); |
| 2337 | sep = ","; |
| 2338 | } |
| 2339 | return len+sprintf(page+len, "\n"); |
| 2340 | } |
| 2341 | |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2342 | static ssize_t |
| 2343 | state_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2344 | { |
| 2345 | /* can write |
| 2346 | * faulty - simulates and error |
| 2347 | * remove - disconnects the device |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2348 | * writemostly - sets write_mostly |
| 2349 | * -writemostly - clears write_mostly |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2350 | * blocked - sets the Blocked flag |
| 2351 | * -blocked - clears the Blocked flag |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2352 | * insync - sets Insync providing device isn't active |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2353 | */ |
| 2354 | int err = -EINVAL; |
| 2355 | if (cmd_match(buf, "faulty") && rdev->mddev->pers) { |
| 2356 | md_error(rdev->mddev, rdev); |
| 2357 | err = 0; |
| 2358 | } else if (cmd_match(buf, "remove")) { |
| 2359 | if (rdev->raid_disk >= 0) |
| 2360 | err = -EBUSY; |
| 2361 | else { |
| 2362 | mddev_t *mddev = rdev->mddev; |
| 2363 | kick_rdev_from_array(rdev); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 2364 | if (mddev->pers) |
| 2365 | md_update_sb(mddev, 1); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2366 | md_new_event(mddev); |
| 2367 | err = 0; |
| 2368 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2369 | } else if (cmd_match(buf, "writemostly")) { |
| 2370 | set_bit(WriteMostly, &rdev->flags); |
| 2371 | err = 0; |
| 2372 | } else if (cmd_match(buf, "-writemostly")) { |
| 2373 | clear_bit(WriteMostly, &rdev->flags); |
| 2374 | err = 0; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2375 | } else if (cmd_match(buf, "blocked")) { |
| 2376 | set_bit(Blocked, &rdev->flags); |
| 2377 | err = 0; |
| 2378 | } else if (cmd_match(buf, "-blocked")) { |
| 2379 | clear_bit(Blocked, &rdev->flags); |
| 2380 | wake_up(&rdev->blocked_wait); |
| 2381 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 2382 | md_wakeup_thread(rdev->mddev->thread); |
| 2383 | |
| 2384 | err = 0; |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2385 | } else if (cmd_match(buf, "insync") && rdev->raid_disk == -1) { |
| 2386 | set_bit(In_sync, &rdev->flags); |
| 2387 | err = 0; |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2388 | } |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2389 | if (!err) |
| 2390 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2391 | return err ? err : len; |
| 2392 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2393 | static struct rdev_sysfs_entry rdev_state = |
| 2394 | __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2395 | |
| 2396 | static ssize_t |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2397 | errors_show(mdk_rdev_t *rdev, char *page) |
| 2398 | { |
| 2399 | return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors)); |
| 2400 | } |
| 2401 | |
| 2402 | static ssize_t |
| 2403 | errors_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2404 | { |
| 2405 | char *e; |
| 2406 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 2407 | if (*buf && (*e == 0 || *e == '\n')) { |
| 2408 | atomic_set(&rdev->corrected_errors, n); |
| 2409 | return len; |
| 2410 | } |
| 2411 | return -EINVAL; |
| 2412 | } |
| 2413 | static struct rdev_sysfs_entry rdev_errors = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2414 | __ATTR(errors, S_IRUGO|S_IWUSR, errors_show, errors_store); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2415 | |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2416 | static ssize_t |
| 2417 | slot_show(mdk_rdev_t *rdev, char *page) |
| 2418 | { |
| 2419 | if (rdev->raid_disk < 0) |
| 2420 | return sprintf(page, "none\n"); |
| 2421 | else |
| 2422 | return sprintf(page, "%d\n", rdev->raid_disk); |
| 2423 | } |
| 2424 | |
| 2425 | static ssize_t |
| 2426 | slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2427 | { |
| 2428 | char *e; |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2429 | int err; |
| 2430 | char nm[20]; |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2431 | int slot = simple_strtoul(buf, &e, 10); |
| 2432 | if (strncmp(buf, "none", 4)==0) |
| 2433 | slot = -1; |
| 2434 | else if (e==buf || (*e && *e!= '\n')) |
| 2435 | return -EINVAL; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2436 | if (rdev->mddev->pers && slot == -1) { |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2437 | /* Setting 'slot' on an active array requires also |
| 2438 | * updating the 'rd%d' link, and communicating |
| 2439 | * with the personality with ->hot_*_disk. |
| 2440 | * For now we only support removing |
| 2441 | * failed/spare devices. This normally happens automatically, |
| 2442 | * but not when the metadata is externally managed. |
| 2443 | */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2444 | if (rdev->raid_disk == -1) |
| 2445 | return -EEXIST; |
| 2446 | /* personality does all needed checks */ |
| 2447 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 2448 | return -EINVAL; |
| 2449 | err = rdev->mddev->pers-> |
| 2450 | hot_remove_disk(rdev->mddev, rdev->raid_disk); |
| 2451 | if (err) |
| 2452 | return err; |
| 2453 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2454 | sysfs_remove_link(&rdev->mddev->kobj, nm); |
Maciej Trela | b710310 | 2010-04-14 16:58:16 +1000 | [diff] [blame] | 2455 | rdev->raid_disk = -1; |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2456 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 2457 | md_wakeup_thread(rdev->mddev->thread); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2458 | } else if (rdev->mddev->pers) { |
| 2459 | mdk_rdev_t *rdev2; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2460 | /* Activating a spare .. or possibly reactivating |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2461 | * if we ever get bitmaps working here. |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2462 | */ |
| 2463 | |
| 2464 | if (rdev->raid_disk != -1) |
| 2465 | return -EBUSY; |
| 2466 | |
| 2467 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 2468 | return -EINVAL; |
| 2469 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2470 | list_for_each_entry(rdev2, &rdev->mddev->disks, same_set) |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2471 | if (rdev2->raid_disk == slot) |
| 2472 | return -EEXIST; |
| 2473 | |
| 2474 | rdev->raid_disk = slot; |
| 2475 | if (test_bit(In_sync, &rdev->flags)) |
| 2476 | rdev->saved_raid_disk = slot; |
| 2477 | else |
| 2478 | rdev->saved_raid_disk = -1; |
| 2479 | err = rdev->mddev->pers-> |
| 2480 | hot_add_disk(rdev->mddev, rdev); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 2481 | if (err) { |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2482 | rdev->raid_disk = -1; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2483 | return err; |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 2484 | } else |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2485 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2486 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2487 | if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2488 | /* failure here is OK */; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2489 | /* don't wakeup anyone, leave that to userspace. */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2490 | } else { |
| 2491 | if (slot >= rdev->mddev->raid_disks) |
| 2492 | return -ENOSPC; |
| 2493 | rdev->raid_disk = slot; |
| 2494 | /* assume it is working */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2495 | clear_bit(Faulty, &rdev->flags); |
| 2496 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2497 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2498 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2499 | } |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2500 | return len; |
| 2501 | } |
| 2502 | |
| 2503 | |
| 2504 | static struct rdev_sysfs_entry rdev_slot = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2505 | __ATTR(slot, S_IRUGO|S_IWUSR, slot_show, slot_store); |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2506 | |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2507 | static ssize_t |
| 2508 | offset_show(mdk_rdev_t *rdev, char *page) |
| 2509 | { |
Andrew Morton | 6961ece | 2006-01-06 00:20:59 -0800 | [diff] [blame] | 2510 | return sprintf(page, "%llu\n", (unsigned long long)rdev->data_offset); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | static ssize_t |
| 2514 | offset_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2515 | { |
| 2516 | char *e; |
| 2517 | unsigned long long offset = simple_strtoull(buf, &e, 10); |
| 2518 | if (e==buf || (*e && *e != '\n')) |
| 2519 | return -EINVAL; |
Neil Brown | 8ed0a52 | 2008-06-28 08:31:29 +1000 | [diff] [blame] | 2520 | if (rdev->mddev->pers && rdev->raid_disk >= 0) |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2521 | return -EBUSY; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2522 | if (rdev->sectors && rdev->mddev->external) |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2523 | /* Must set offset before size, so overlap checks |
| 2524 | * can be sane */ |
| 2525 | return -EBUSY; |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2526 | rdev->data_offset = offset; |
| 2527 | return len; |
| 2528 | } |
| 2529 | |
| 2530 | static struct rdev_sysfs_entry rdev_offset = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2531 | __ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2532 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2533 | static ssize_t |
| 2534 | rdev_size_show(mdk_rdev_t *rdev, char *page) |
| 2535 | { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2536 | return sprintf(page, "%llu\n", (unsigned long long)rdev->sectors / 2); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2537 | } |
| 2538 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2539 | static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2) |
| 2540 | { |
| 2541 | /* check if two start/length pairs overlap */ |
| 2542 | if (s1+l1 <= s2) |
| 2543 | return 0; |
| 2544 | if (s2+l2 <= s1) |
| 2545 | return 0; |
| 2546 | return 1; |
| 2547 | } |
| 2548 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2549 | static int strict_blocks_to_sectors(const char *buf, sector_t *sectors) |
| 2550 | { |
| 2551 | unsigned long long blocks; |
| 2552 | sector_t new; |
| 2553 | |
| 2554 | if (strict_strtoull(buf, 10, &blocks) < 0) |
| 2555 | return -EINVAL; |
| 2556 | |
| 2557 | if (blocks & 1ULL << (8 * sizeof(blocks) - 1)) |
| 2558 | return -EINVAL; /* sector conversion overflow */ |
| 2559 | |
| 2560 | new = blocks * 2; |
| 2561 | if (new != blocks * 2) |
| 2562 | return -EINVAL; /* unsigned long long to sector_t overflow */ |
| 2563 | |
| 2564 | *sectors = new; |
| 2565 | return 0; |
| 2566 | } |
| 2567 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2568 | static ssize_t |
| 2569 | rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2570 | { |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2571 | mddev_t *my_mddev = rdev->mddev; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2572 | sector_t oldsectors = rdev->sectors; |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2573 | sector_t sectors; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2574 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2575 | if (strict_blocks_to_sectors(buf, §ors) < 0) |
Neil Brown | d702745 | 2008-07-12 10:37:50 +1000 | [diff] [blame] | 2576 | return -EINVAL; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2577 | if (my_mddev->pers && rdev->raid_disk >= 0) { |
Neil Brown | d702745 | 2008-07-12 10:37:50 +1000 | [diff] [blame] | 2578 | if (my_mddev->persistent) { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2579 | sectors = super_types[my_mddev->major_version]. |
| 2580 | rdev_size_change(rdev, sectors); |
| 2581 | if (!sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2582 | return -EBUSY; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2583 | } else if (!sectors) |
| 2584 | sectors = (rdev->bdev->bd_inode->i_size >> 9) - |
| 2585 | rdev->data_offset; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2586 | } |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2587 | if (sectors < my_mddev->dev_sectors) |
Chris Webb | 7d3c6f8 | 2008-10-13 11:55:11 +1100 | [diff] [blame] | 2588 | return -EINVAL; /* component must fit device */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2589 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2590 | rdev->sectors = sectors; |
| 2591 | if (sectors > oldsectors && my_mddev->external) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2592 | /* need to check that all other rdevs with the same ->bdev |
| 2593 | * do not overlap. We need to unlock the mddev to avoid |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2594 | * a deadlock. We have already changed rdev->sectors, and if |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2595 | * we have to change it back, we will have the lock again. |
| 2596 | */ |
| 2597 | mddev_t *mddev; |
| 2598 | int overlap = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2599 | struct list_head *tmp; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2600 | |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2601 | mddev_unlock(my_mddev); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 2602 | for_each_mddev(mddev, tmp) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2603 | mdk_rdev_t *rdev2; |
| 2604 | |
| 2605 | mddev_lock(mddev); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2606 | list_for_each_entry(rdev2, &mddev->disks, same_set) |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2607 | if (test_bit(AllReserved, &rdev2->flags) || |
| 2608 | (rdev->bdev == rdev2->bdev && |
| 2609 | rdev != rdev2 && |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2610 | overlaps(rdev->data_offset, rdev->sectors, |
Andre Noll | d07bd3b | 2008-07-21 14:42:07 +1000 | [diff] [blame] | 2611 | rdev2->data_offset, |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2612 | rdev2->sectors))) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2613 | overlap = 1; |
| 2614 | break; |
| 2615 | } |
| 2616 | mddev_unlock(mddev); |
| 2617 | if (overlap) { |
| 2618 | mddev_put(mddev); |
| 2619 | break; |
| 2620 | } |
| 2621 | } |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2622 | mddev_lock(my_mddev); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2623 | if (overlap) { |
| 2624 | /* Someone else could have slipped in a size |
| 2625 | * change here, but doing so is just silly. |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2626 | * We put oldsectors back because we *know* it is |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2627 | * safe, and trust userspace not to race with |
| 2628 | * itself |
| 2629 | */ |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2630 | rdev->sectors = oldsectors; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2631 | return -EBUSY; |
| 2632 | } |
| 2633 | } |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2634 | return len; |
| 2635 | } |
| 2636 | |
| 2637 | static struct rdev_sysfs_entry rdev_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2638 | __ATTR(size, S_IRUGO|S_IWUSR, rdev_size_show, rdev_size_store); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2639 | |
Dan Williams | 06e3c81 | 2009-12-12 21:17:12 -0700 | [diff] [blame] | 2640 | |
| 2641 | static ssize_t recovery_start_show(mdk_rdev_t *rdev, char *page) |
| 2642 | { |
| 2643 | unsigned long long recovery_start = rdev->recovery_offset; |
| 2644 | |
| 2645 | if (test_bit(In_sync, &rdev->flags) || |
| 2646 | recovery_start == MaxSector) |
| 2647 | return sprintf(page, "none\n"); |
| 2648 | |
| 2649 | return sprintf(page, "%llu\n", recovery_start); |
| 2650 | } |
| 2651 | |
| 2652 | static ssize_t recovery_start_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2653 | { |
| 2654 | unsigned long long recovery_start; |
| 2655 | |
| 2656 | if (cmd_match(buf, "none")) |
| 2657 | recovery_start = MaxSector; |
| 2658 | else if (strict_strtoull(buf, 10, &recovery_start)) |
| 2659 | return -EINVAL; |
| 2660 | |
| 2661 | if (rdev->mddev->pers && |
| 2662 | rdev->raid_disk >= 0) |
| 2663 | return -EBUSY; |
| 2664 | |
| 2665 | rdev->recovery_offset = recovery_start; |
| 2666 | if (recovery_start == MaxSector) |
| 2667 | set_bit(In_sync, &rdev->flags); |
| 2668 | else |
| 2669 | clear_bit(In_sync, &rdev->flags); |
| 2670 | return len; |
| 2671 | } |
| 2672 | |
| 2673 | static struct rdev_sysfs_entry rdev_recovery_start = |
| 2674 | __ATTR(recovery_start, S_IRUGO|S_IWUSR, recovery_start_show, recovery_start_store); |
| 2675 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2676 | static struct attribute *rdev_default_attrs[] = { |
| 2677 | &rdev_state.attr, |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2678 | &rdev_errors.attr, |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2679 | &rdev_slot.attr, |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2680 | &rdev_offset.attr, |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2681 | &rdev_size.attr, |
Dan Williams | 06e3c81 | 2009-12-12 21:17:12 -0700 | [diff] [blame] | 2682 | &rdev_recovery_start.attr, |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2683 | NULL, |
| 2684 | }; |
| 2685 | static ssize_t |
| 2686 | rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 2687 | { |
| 2688 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2689 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2690 | mddev_t *mddev = rdev->mddev; |
| 2691 | ssize_t rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2692 | |
| 2693 | if (!entry->show) |
| 2694 | return -EIO; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2695 | |
| 2696 | rv = mddev ? mddev_lock(mddev) : -EBUSY; |
| 2697 | if (!rv) { |
| 2698 | if (rdev->mddev == NULL) |
| 2699 | rv = -EBUSY; |
| 2700 | else |
| 2701 | rv = entry->show(rdev, page); |
| 2702 | mddev_unlock(mddev); |
| 2703 | } |
| 2704 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | static ssize_t |
| 2708 | rdev_attr_store(struct kobject *kobj, struct attribute *attr, |
| 2709 | const char *page, size_t length) |
| 2710 | { |
| 2711 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2712 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2713 | ssize_t rv; |
| 2714 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2715 | |
| 2716 | if (!entry->store) |
| 2717 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 2718 | if (!capable(CAP_SYS_ADMIN)) |
| 2719 | return -EACCES; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2720 | rv = mddev ? mddev_lock(mddev): -EBUSY; |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2721 | if (!rv) { |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2722 | if (rdev->mddev == NULL) |
| 2723 | rv = -EBUSY; |
| 2724 | else |
| 2725 | rv = entry->store(rdev, page, length); |
Dan Williams | 6a51830 | 2008-04-30 00:52:28 -0700 | [diff] [blame] | 2726 | mddev_unlock(mddev); |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2727 | } |
| 2728 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | static void rdev_free(struct kobject *ko) |
| 2732 | { |
| 2733 | mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj); |
| 2734 | kfree(rdev); |
| 2735 | } |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 2736 | static const struct sysfs_ops rdev_sysfs_ops = { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2737 | .show = rdev_attr_show, |
| 2738 | .store = rdev_attr_store, |
| 2739 | }; |
| 2740 | static struct kobj_type rdev_ktype = { |
| 2741 | .release = rdev_free, |
| 2742 | .sysfs_ops = &rdev_sysfs_ops, |
| 2743 | .default_attrs = rdev_default_attrs, |
| 2744 | }; |
| 2745 | |
NeilBrown | e8bb9a8 | 2010-06-01 19:37:26 +1000 | [diff] [blame] | 2746 | void md_rdev_init(mdk_rdev_t *rdev) |
| 2747 | { |
| 2748 | rdev->desc_nr = -1; |
| 2749 | rdev->saved_raid_disk = -1; |
| 2750 | rdev->raid_disk = -1; |
| 2751 | rdev->flags = 0; |
| 2752 | rdev->data_offset = 0; |
| 2753 | rdev->sb_events = 0; |
| 2754 | rdev->last_read_error.tv_sec = 0; |
| 2755 | rdev->last_read_error.tv_nsec = 0; |
| 2756 | atomic_set(&rdev->nr_pending, 0); |
| 2757 | atomic_set(&rdev->read_errors, 0); |
| 2758 | atomic_set(&rdev->corrected_errors, 0); |
| 2759 | |
| 2760 | INIT_LIST_HEAD(&rdev->same_set); |
| 2761 | init_waitqueue_head(&rdev->blocked_wait); |
| 2762 | } |
| 2763 | EXPORT_SYMBOL_GPL(md_rdev_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | /* |
| 2765 | * Import a device. If 'super_format' >= 0, then sanity check the superblock |
| 2766 | * |
| 2767 | * mark the device faulty if: |
| 2768 | * |
| 2769 | * - the device is nonexistent (zero size) |
| 2770 | * - the device has no valid superblock |
| 2771 | * |
| 2772 | * a faulty rdev _never_ has rdev->sb set. |
| 2773 | */ |
| 2774 | static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_minor) |
| 2775 | { |
| 2776 | char b[BDEVNAME_SIZE]; |
| 2777 | int err; |
| 2778 | mdk_rdev_t *rdev; |
| 2779 | sector_t size; |
| 2780 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 2781 | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | if (!rdev) { |
| 2783 | printk(KERN_ERR "md: could not alloc mem for new device!\n"); |
| 2784 | return ERR_PTR(-ENOMEM); |
| 2785 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | |
NeilBrown | e8bb9a8 | 2010-06-01 19:37:26 +1000 | [diff] [blame] | 2787 | md_rdev_init(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | if ((err = alloc_disk_sb(rdev))) |
| 2789 | goto abort_free; |
| 2790 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2791 | err = lock_rdev(rdev, newdev, super_format == -2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | if (err) |
| 2793 | goto abort_free; |
| 2794 | |
Greg Kroah-Hartman | f9cb074 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 2795 | kobject_init(&rdev->kobj, &rdev_ktype); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 2798 | if (!size) { |
| 2799 | printk(KERN_WARNING |
| 2800 | "md: %s has zero or unknown size, marking faulty!\n", |
| 2801 | bdevname(rdev->bdev,b)); |
| 2802 | err = -EINVAL; |
| 2803 | goto abort_free; |
| 2804 | } |
| 2805 | |
| 2806 | if (super_format >= 0) { |
| 2807 | err = super_types[super_format]. |
| 2808 | load_super(rdev, NULL, super_minor); |
| 2809 | if (err == -EINVAL) { |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 2810 | printk(KERN_WARNING |
| 2811 | "md: %s does not have a valid v%d.%d " |
| 2812 | "superblock, not importing!\n", |
| 2813 | bdevname(rdev->bdev,b), |
| 2814 | super_format, super_minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | goto abort_free; |
| 2816 | } |
| 2817 | if (err < 0) { |
| 2818 | printk(KERN_WARNING |
| 2819 | "md: could not read %s's sb, not importing!\n", |
| 2820 | bdevname(rdev->bdev,b)); |
| 2821 | goto abort_free; |
| 2822 | } |
| 2823 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | return rdev; |
| 2826 | |
| 2827 | abort_free: |
| 2828 | if (rdev->sb_page) { |
| 2829 | if (rdev->bdev) |
| 2830 | unlock_rdev(rdev); |
| 2831 | free_disk_sb(rdev); |
| 2832 | } |
| 2833 | kfree(rdev); |
| 2834 | return ERR_PTR(err); |
| 2835 | } |
| 2836 | |
| 2837 | /* |
| 2838 | * Check a full RAID array for plausibility |
| 2839 | */ |
| 2840 | |
| 2841 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 2842 | static void analyze_sbs(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | { |
| 2844 | int i; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2845 | mdk_rdev_t *rdev, *freshest, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | char b[BDEVNAME_SIZE]; |
| 2847 | |
| 2848 | freshest = NULL; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2849 | rdev_for_each(rdev, tmp, mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | switch (super_types[mddev->major_version]. |
| 2851 | load_super(rdev, freshest, mddev->minor_version)) { |
| 2852 | case 1: |
| 2853 | freshest = rdev; |
| 2854 | break; |
| 2855 | case 0: |
| 2856 | break; |
| 2857 | default: |
| 2858 | printk( KERN_ERR \ |
| 2859 | "md: fatal superblock inconsistency in %s" |
| 2860 | " -- removing from array\n", |
| 2861 | bdevname(rdev->bdev,b)); |
| 2862 | kick_rdev_from_array(rdev); |
| 2863 | } |
| 2864 | |
| 2865 | |
| 2866 | super_types[mddev->major_version]. |
| 2867 | validate_super(mddev, freshest); |
| 2868 | |
| 2869 | i = 0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2870 | rdev_for_each(rdev, tmp, mddev) { |
NeilBrown | 233fca3 | 2010-04-14 17:02:09 +1000 | [diff] [blame] | 2871 | if (mddev->max_disks && |
| 2872 | (rdev->desc_nr >= mddev->max_disks || |
| 2873 | i > mddev->max_disks)) { |
NeilBrown | de01dfa | 2009-02-06 18:02:46 +1100 | [diff] [blame] | 2874 | printk(KERN_WARNING |
| 2875 | "md: %s: %s: only %d devices permitted\n", |
| 2876 | mdname(mddev), bdevname(rdev->bdev, b), |
| 2877 | mddev->max_disks); |
| 2878 | kick_rdev_from_array(rdev); |
| 2879 | continue; |
| 2880 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | if (rdev != freshest) |
| 2882 | if (super_types[mddev->major_version]. |
| 2883 | validate_super(mddev, rdev)) { |
| 2884 | printk(KERN_WARNING "md: kicking non-fresh %s" |
| 2885 | " from array!\n", |
| 2886 | bdevname(rdev->bdev,b)); |
| 2887 | kick_rdev_from_array(rdev); |
| 2888 | continue; |
| 2889 | } |
| 2890 | if (mddev->level == LEVEL_MULTIPATH) { |
| 2891 | rdev->desc_nr = i++; |
| 2892 | rdev->raid_disk = rdev->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2893 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 2894 | } else if (rdev->raid_disk >= (mddev->raid_disks - min(0, mddev->delta_disks))) { |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 2895 | rdev->raid_disk = -1; |
| 2896 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | } |
| 2898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
NeilBrown | 72e0207 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2901 | /* Read a fixed-point number. |
| 2902 | * Numbers in sysfs attributes should be in "standard" units where |
| 2903 | * possible, so time should be in seconds. |
| 2904 | * However we internally use a a much smaller unit such as |
| 2905 | * milliseconds or jiffies. |
| 2906 | * This function takes a decimal number with a possible fractional |
| 2907 | * component, and produces an integer which is the result of |
| 2908 | * multiplying that number by 10^'scale'. |
| 2909 | * all without any floating-point arithmetic. |
| 2910 | */ |
| 2911 | int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale) |
| 2912 | { |
| 2913 | unsigned long result = 0; |
| 2914 | long decimals = -1; |
| 2915 | while (isdigit(*cp) || (*cp == '.' && decimals < 0)) { |
| 2916 | if (*cp == '.') |
| 2917 | decimals = 0; |
| 2918 | else if (decimals < scale) { |
| 2919 | unsigned int value; |
| 2920 | value = *cp - '0'; |
| 2921 | result = result * 10 + value; |
| 2922 | if (decimals >= 0) |
| 2923 | decimals++; |
| 2924 | } |
| 2925 | cp++; |
| 2926 | } |
| 2927 | if (*cp == '\n') |
| 2928 | cp++; |
| 2929 | if (*cp) |
| 2930 | return -EINVAL; |
| 2931 | if (decimals < 0) |
| 2932 | decimals = 0; |
| 2933 | while (decimals < scale) { |
| 2934 | result *= 10; |
| 2935 | decimals ++; |
| 2936 | } |
| 2937 | *res = result; |
| 2938 | return 0; |
| 2939 | } |
| 2940 | |
| 2941 | |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2942 | static void md_safemode_timeout(unsigned long data); |
| 2943 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2944 | static ssize_t |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2945 | safe_delay_show(mddev_t *mddev, char *page) |
| 2946 | { |
| 2947 | int msec = (mddev->safemode_delay*1000)/HZ; |
| 2948 | return sprintf(page, "%d.%03d\n", msec/1000, msec%1000); |
| 2949 | } |
| 2950 | static ssize_t |
| 2951 | safe_delay_store(mddev_t *mddev, const char *cbuf, size_t len) |
| 2952 | { |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2953 | unsigned long msec; |
Dan Williams | 97ce0a7 | 2008-09-24 22:48:19 -0700 | [diff] [blame] | 2954 | |
NeilBrown | 72e0207 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2955 | if (strict_strtoul_scaled(cbuf, &msec, 3) < 0) |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2956 | return -EINVAL; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2957 | if (msec == 0) |
| 2958 | mddev->safemode_delay = 0; |
| 2959 | else { |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2960 | unsigned long old_delay = mddev->safemode_delay; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2961 | mddev->safemode_delay = (msec*HZ)/1000; |
| 2962 | if (mddev->safemode_delay == 0) |
| 2963 | mddev->safemode_delay = 1; |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2964 | if (mddev->safemode_delay < old_delay) |
| 2965 | md_safemode_timeout((unsigned long)mddev); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2966 | } |
| 2967 | return len; |
| 2968 | } |
| 2969 | static struct md_sysfs_entry md_safe_delay = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2970 | __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] | 2971 | |
| 2972 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2973 | level_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2974 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2975 | struct mdk_personality *p = mddev->pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2976 | if (p) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2977 | return sprintf(page, "%s\n", p->name); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2978 | else if (mddev->clevel[0]) |
| 2979 | return sprintf(page, "%s\n", mddev->clevel); |
| 2980 | else if (mddev->level != LEVEL_NONE) |
| 2981 | return sprintf(page, "%d\n", mddev->level); |
| 2982 | else |
| 2983 | return 0; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2984 | } |
| 2985 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2986 | static ssize_t |
| 2987 | level_store(mddev_t *mddev, const char *buf, size_t len) |
| 2988 | { |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2989 | char clevel[16]; |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2990 | ssize_t rv = len; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2991 | struct mdk_personality *pers; |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2992 | long level; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2993 | void *priv; |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 2994 | mdk_rdev_t *rdev; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2995 | |
| 2996 | if (mddev->pers == NULL) { |
| 2997 | if (len == 0) |
| 2998 | return 0; |
| 2999 | if (len >= sizeof(mddev->clevel)) |
| 3000 | return -ENOSPC; |
| 3001 | strncpy(mddev->clevel, buf, len); |
| 3002 | if (mddev->clevel[len-1] == '\n') |
| 3003 | len--; |
| 3004 | mddev->clevel[len] = 0; |
| 3005 | mddev->level = LEVEL_NONE; |
| 3006 | return rv; |
| 3007 | } |
| 3008 | |
| 3009 | /* request to change the personality. Need to ensure: |
| 3010 | * - array is not engaged in resync/recovery/reshape |
| 3011 | * - old personality can be suspended |
| 3012 | * - new personality will access other array. |
| 3013 | */ |
| 3014 | |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame^] | 3015 | if (mddev->sync_thread || |
| 3016 | mddev->reshape_position != MaxSector || |
| 3017 | mddev->sysfs_active) |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3018 | return -EBUSY; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3019 | |
| 3020 | if (!mddev->pers->quiesce) { |
| 3021 | printk(KERN_WARNING "md: %s: %s does not support online personality change\n", |
| 3022 | mdname(mddev), mddev->pers->name); |
| 3023 | return -EINVAL; |
| 3024 | } |
| 3025 | |
| 3026 | /* Now find the new personality */ |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3027 | if (len == 0 || len >= sizeof(clevel)) |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3028 | return -EINVAL; |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3029 | strncpy(clevel, buf, len); |
| 3030 | if (clevel[len-1] == '\n') |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3031 | len--; |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3032 | clevel[len] = 0; |
| 3033 | if (strict_strtol(clevel, 10, &level)) |
| 3034 | level = LEVEL_NONE; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3035 | |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3036 | if (request_module("md-%s", clevel) != 0) |
| 3037 | request_module("md-level-%s", clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3038 | spin_lock(&pers_lock); |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3039 | pers = find_pers(level, clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3040 | if (!pers || !try_module_get(pers->owner)) { |
| 3041 | spin_unlock(&pers_lock); |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3042 | printk(KERN_WARNING "md: personality %s not loaded\n", clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3043 | return -EINVAL; |
| 3044 | } |
| 3045 | spin_unlock(&pers_lock); |
| 3046 | |
| 3047 | if (pers == mddev->pers) { |
| 3048 | /* Nothing to do! */ |
| 3049 | module_put(pers->owner); |
| 3050 | return rv; |
| 3051 | } |
| 3052 | if (!pers->takeover) { |
| 3053 | module_put(pers->owner); |
| 3054 | printk(KERN_WARNING "md: %s: %s does not support personality takeover\n", |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3055 | mdname(mddev), clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3056 | return -EINVAL; |
| 3057 | } |
| 3058 | |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3059 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 3060 | rdev->new_raid_disk = rdev->raid_disk; |
| 3061 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3062 | /* ->takeover must set new_* and/or delta_disks |
| 3063 | * if it succeeds, and may set them when it fails. |
| 3064 | */ |
| 3065 | priv = pers->takeover(mddev); |
| 3066 | if (IS_ERR(priv)) { |
| 3067 | mddev->new_level = mddev->level; |
| 3068 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3069 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3070 | mddev->raid_disks -= mddev->delta_disks; |
| 3071 | mddev->delta_disks = 0; |
| 3072 | module_put(pers->owner); |
| 3073 | printk(KERN_WARNING "md: %s: %s would not accept array\n", |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3074 | mdname(mddev), clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3075 | return PTR_ERR(priv); |
| 3076 | } |
| 3077 | |
| 3078 | /* Looks like we have a winner */ |
| 3079 | mddev_suspend(mddev); |
| 3080 | mddev->pers->stop(mddev); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 3081 | |
| 3082 | if (mddev->pers->sync_request == NULL && |
| 3083 | pers->sync_request != NULL) { |
| 3084 | /* need to add the md_redundancy_group */ |
| 3085 | if (sysfs_create_group(&mddev->kobj, &md_redundancy_group)) |
| 3086 | printk(KERN_WARNING |
| 3087 | "md: cannot register extra attributes for %s\n", |
| 3088 | mdname(mddev)); |
NeilBrown | 19fdb9e | 2010-05-22 08:31:36 +1000 | [diff] [blame] | 3089 | mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, NULL, "sync_action"); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 3090 | } |
| 3091 | if (mddev->pers->sync_request != NULL && |
| 3092 | pers->sync_request == NULL) { |
| 3093 | /* need to remove the md_redundancy_group */ |
| 3094 | if (mddev->to_remove == NULL) |
| 3095 | mddev->to_remove = &md_redundancy_group; |
| 3096 | } |
| 3097 | |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 3098 | if (mddev->pers->sync_request == NULL && |
| 3099 | mddev->external) { |
| 3100 | /* We are converting from a no-redundancy array |
| 3101 | * to a redundancy array and metadata is managed |
| 3102 | * externally so we need to be sure that writes |
| 3103 | * won't block due to a need to transition |
| 3104 | * clean->dirty |
| 3105 | * until external management is started. |
| 3106 | */ |
| 3107 | mddev->in_sync = 0; |
| 3108 | mddev->safemode_delay = 0; |
| 3109 | mddev->safemode = 0; |
| 3110 | } |
| 3111 | |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3112 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 3113 | char nm[20]; |
| 3114 | if (rdev->raid_disk < 0) |
| 3115 | continue; |
| 3116 | if (rdev->new_raid_disk > mddev->raid_disks) |
| 3117 | rdev->new_raid_disk = -1; |
| 3118 | if (rdev->new_raid_disk == rdev->raid_disk) |
| 3119 | continue; |
| 3120 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 3121 | sysfs_remove_link(&mddev->kobj, nm); |
| 3122 | } |
| 3123 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 3124 | if (rdev->raid_disk < 0) |
| 3125 | continue; |
| 3126 | if (rdev->new_raid_disk == rdev->raid_disk) |
| 3127 | continue; |
| 3128 | rdev->raid_disk = rdev->new_raid_disk; |
| 3129 | if (rdev->raid_disk < 0) |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 3130 | clear_bit(In_sync, &rdev->flags); |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3131 | else { |
| 3132 | char nm[20]; |
| 3133 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 3134 | if(sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) |
| 3135 | printk("md: cannot register %s for %s after level change\n", |
| 3136 | nm, mdname(mddev)); |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 3137 | } |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | module_put(mddev->pers->owner); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3141 | mddev->pers = pers; |
| 3142 | mddev->private = priv; |
| 3143 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
| 3144 | mddev->level = mddev->new_level; |
| 3145 | mddev->layout = mddev->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3146 | mddev->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3147 | mddev->delta_disks = 0; |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 3148 | if (mddev->pers->sync_request == NULL) { |
| 3149 | /* this is now an array without redundancy, so |
| 3150 | * it must always be in_sync |
| 3151 | */ |
| 3152 | mddev->in_sync = 1; |
| 3153 | del_timer_sync(&mddev->safemode_timer); |
| 3154 | } |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3155 | pers->run(mddev); |
| 3156 | mddev_resume(mddev); |
| 3157 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 3158 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3159 | md_wakeup_thread(mddev->thread); |
Maciej Trela | 5cac7861 | 2010-04-14 17:17:39 +1000 | [diff] [blame] | 3160 | sysfs_notify(&mddev->kobj, NULL, "level"); |
Dan Williams | bb7f8d2 | 2010-05-01 18:14:57 -0700 | [diff] [blame] | 3161 | md_new_event(mddev); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3162 | return rv; |
| 3163 | } |
| 3164 | |
| 3165 | static struct md_sysfs_entry md_level = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3166 | __ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3167 | |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3168 | |
| 3169 | static ssize_t |
| 3170 | layout_show(mddev_t *mddev, char *page) |
| 3171 | { |
| 3172 | /* just a number, not meaningful for all levels */ |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3173 | if (mddev->reshape_position != MaxSector && |
| 3174 | mddev->layout != mddev->new_layout) |
| 3175 | return sprintf(page, "%d (%d)\n", |
| 3176 | mddev->new_layout, mddev->layout); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3177 | return sprintf(page, "%d\n", mddev->layout); |
| 3178 | } |
| 3179 | |
| 3180 | static ssize_t |
| 3181 | layout_store(mddev_t *mddev, const char *buf, size_t len) |
| 3182 | { |
| 3183 | char *e; |
| 3184 | unsigned long n = simple_strtoul(buf, &e, 10); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3185 | |
| 3186 | if (!*buf || (*e && *e != '\n')) |
| 3187 | return -EINVAL; |
| 3188 | |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3189 | if (mddev->pers) { |
| 3190 | int err; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3191 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3192 | return -EBUSY; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3193 | mddev->new_layout = n; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3194 | err = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3195 | if (err) { |
| 3196 | mddev->new_layout = mddev->layout; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3197 | return err; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3198 | } |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3199 | } else { |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3200 | mddev->new_layout = n; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3201 | if (mddev->reshape_position == MaxSector) |
| 3202 | mddev->layout = n; |
| 3203 | } |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3204 | return len; |
| 3205 | } |
| 3206 | static struct md_sysfs_entry md_layout = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3207 | __ATTR(layout, S_IRUGO|S_IWUSR, layout_show, layout_store); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3208 | |
| 3209 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3210 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3211 | raid_disks_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3212 | { |
NeilBrown | bb63654 | 2005-11-08 21:39:45 -0800 | [diff] [blame] | 3213 | if (mddev->raid_disks == 0) |
| 3214 | return 0; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3215 | if (mddev->reshape_position != MaxSector && |
| 3216 | mddev->delta_disks != 0) |
| 3217 | return sprintf(page, "%d (%d)\n", mddev->raid_disks, |
| 3218 | mddev->raid_disks - mddev->delta_disks); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3219 | return sprintf(page, "%d\n", mddev->raid_disks); |
| 3220 | } |
| 3221 | |
NeilBrown | da943b9 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3222 | static int update_raid_disks(mddev_t *mddev, int raid_disks); |
| 3223 | |
| 3224 | static ssize_t |
| 3225 | raid_disks_store(mddev_t *mddev, const char *buf, size_t len) |
| 3226 | { |
NeilBrown | da943b9 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3227 | char *e; |
| 3228 | int rv = 0; |
| 3229 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3230 | |
| 3231 | if (!*buf || (*e && *e != '\n')) |
| 3232 | return -EINVAL; |
| 3233 | |
| 3234 | if (mddev->pers) |
| 3235 | rv = update_raid_disks(mddev, n); |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3236 | else if (mddev->reshape_position != MaxSector) { |
| 3237 | int olddisks = mddev->raid_disks - mddev->delta_disks; |
| 3238 | mddev->delta_disks = n - olddisks; |
| 3239 | mddev->raid_disks = n; |
| 3240 | } else |
NeilBrown | da943b9 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3241 | mddev->raid_disks = n; |
| 3242 | return rv ? rv : len; |
| 3243 | } |
| 3244 | static struct md_sysfs_entry md_raid_disks = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3245 | __ATTR(raid_disks, S_IRUGO|S_IWUSR, raid_disks_show, raid_disks_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3246 | |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3247 | static ssize_t |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3248 | chunk_size_show(mddev_t *mddev, char *page) |
| 3249 | { |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3250 | if (mddev->reshape_position != MaxSector && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3251 | mddev->chunk_sectors != mddev->new_chunk_sectors) |
| 3252 | return sprintf(page, "%d (%d)\n", |
| 3253 | mddev->new_chunk_sectors << 9, |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3254 | mddev->chunk_sectors << 9); |
| 3255 | return sprintf(page, "%d\n", mddev->chunk_sectors << 9); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | static ssize_t |
| 3259 | chunk_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 3260 | { |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3261 | char *e; |
| 3262 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3263 | |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3264 | if (!*buf || (*e && *e != '\n')) |
| 3265 | return -EINVAL; |
| 3266 | |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3267 | if (mddev->pers) { |
| 3268 | int err; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3269 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3270 | return -EBUSY; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3271 | mddev->new_chunk_sectors = n >> 9; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3272 | err = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3273 | if (err) { |
| 3274 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3275 | return err; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3276 | } |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3277 | } else { |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3278 | mddev->new_chunk_sectors = n >> 9; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3279 | if (mddev->reshape_position == MaxSector) |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3280 | mddev->chunk_sectors = n >> 9; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3281 | } |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3282 | return len; |
| 3283 | } |
| 3284 | static struct md_sysfs_entry md_chunk_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3285 | __ATTR(chunk_size, S_IRUGO|S_IWUSR, chunk_size_show, chunk_size_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3286 | |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3287 | static ssize_t |
| 3288 | resync_start_show(mddev_t *mddev, char *page) |
| 3289 | { |
NeilBrown | d1a7c50 | 2009-03-31 15:24:32 +1100 | [diff] [blame] | 3290 | if (mddev->recovery_cp == MaxSector) |
| 3291 | return sprintf(page, "none\n"); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3292 | return sprintf(page, "%llu\n", (unsigned long long)mddev->recovery_cp); |
| 3293 | } |
| 3294 | |
| 3295 | static ssize_t |
| 3296 | resync_start_store(mddev_t *mddev, const char *buf, size_t len) |
| 3297 | { |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3298 | char *e; |
| 3299 | unsigned long long n = simple_strtoull(buf, &e, 10); |
| 3300 | |
| 3301 | if (mddev->pers) |
| 3302 | return -EBUSY; |
Dan Williams | 06e3c81 | 2009-12-12 21:17:12 -0700 | [diff] [blame] | 3303 | if (cmd_match(buf, "none")) |
| 3304 | n = MaxSector; |
| 3305 | else if (!*buf || (*e && *e != '\n')) |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3306 | return -EINVAL; |
| 3307 | |
| 3308 | mddev->recovery_cp = n; |
| 3309 | return len; |
| 3310 | } |
| 3311 | static struct md_sysfs_entry md_resync_start = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3312 | __ATTR(resync_start, S_IRUGO|S_IWUSR, resync_start_show, resync_start_store); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3313 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3314 | /* |
| 3315 | * The array state can be: |
| 3316 | * |
| 3317 | * clear |
| 3318 | * No devices, no size, no level |
| 3319 | * Equivalent to STOP_ARRAY ioctl |
| 3320 | * inactive |
| 3321 | * May have some settings, but array is not active |
| 3322 | * all IO results in error |
| 3323 | * When written, doesn't tear down array, but just stops it |
| 3324 | * suspended (not supported yet) |
| 3325 | * All IO requests will block. The array can be reconfigured. |
Andre Noll | 910d8cb | 2008-03-25 21:00:53 +0100 | [diff] [blame] | 3326 | * Writing this, if accepted, will block until array is quiescent |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3327 | * readonly |
| 3328 | * no resync can happen. no superblocks get written. |
| 3329 | * write requests fail |
| 3330 | * read-auto |
| 3331 | * like readonly, but behaves like 'clean' on a write request. |
| 3332 | * |
| 3333 | * clean - no pending writes, but otherwise active. |
| 3334 | * When written to inactive array, starts without resync |
| 3335 | * If a write request arrives then |
| 3336 | * if metadata is known, mark 'dirty' and switch to 'active'. |
| 3337 | * if not known, block and switch to write-pending |
| 3338 | * If written to an active array that has pending writes, then fails. |
| 3339 | * active |
| 3340 | * fully active: IO and resync can be happening. |
| 3341 | * When written to inactive array, starts with resync |
| 3342 | * |
| 3343 | * write-pending |
| 3344 | * clean, but writes are blocked waiting for 'active' to be written. |
| 3345 | * |
| 3346 | * active-idle |
| 3347 | * like active, but no writes have been seen for a while (100msec). |
| 3348 | * |
| 3349 | */ |
| 3350 | enum array_state { clear, inactive, suspended, readonly, read_auto, clean, active, |
| 3351 | write_pending, active_idle, bad_word}; |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 3352 | static char *array_states[] = { |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3353 | "clear", "inactive", "suspended", "readonly", "read-auto", "clean", "active", |
| 3354 | "write-pending", "active-idle", NULL }; |
| 3355 | |
| 3356 | static int match_word(const char *word, char **list) |
| 3357 | { |
| 3358 | int n; |
| 3359 | for (n=0; list[n]; n++) |
| 3360 | if (cmd_match(word, list[n])) |
| 3361 | break; |
| 3362 | return n; |
| 3363 | } |
| 3364 | |
| 3365 | static ssize_t |
| 3366 | array_state_show(mddev_t *mddev, char *page) |
| 3367 | { |
| 3368 | enum array_state st = inactive; |
| 3369 | |
| 3370 | if (mddev->pers) |
| 3371 | switch(mddev->ro) { |
| 3372 | case 1: |
| 3373 | st = readonly; |
| 3374 | break; |
| 3375 | case 2: |
| 3376 | st = read_auto; |
| 3377 | break; |
| 3378 | case 0: |
| 3379 | if (mddev->in_sync) |
| 3380 | st = clean; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3381 | else if (test_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 3382 | st = write_pending; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3383 | else if (mddev->safemode) |
| 3384 | st = active_idle; |
| 3385 | else |
| 3386 | st = active; |
| 3387 | } |
| 3388 | else { |
| 3389 | if (list_empty(&mddev->disks) && |
| 3390 | mddev->raid_disks == 0 && |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3391 | mddev->dev_sectors == 0) |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3392 | st = clear; |
| 3393 | else |
| 3394 | st = inactive; |
| 3395 | } |
| 3396 | return sprintf(page, "%s\n", array_states[st]); |
| 3397 | } |
| 3398 | |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3399 | static int do_md_stop(mddev_t * mddev, int ro, int is_open); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 3400 | static int md_set_readonly(mddev_t * mddev, int is_open); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3401 | static int do_md_run(mddev_t * mddev); |
| 3402 | static int restart_array(mddev_t *mddev); |
| 3403 | |
| 3404 | static ssize_t |
| 3405 | array_state_store(mddev_t *mddev, const char *buf, size_t len) |
| 3406 | { |
| 3407 | int err = -EINVAL; |
| 3408 | enum array_state st = match_word(buf, array_states); |
| 3409 | switch(st) { |
| 3410 | case bad_word: |
| 3411 | break; |
| 3412 | case clear: |
| 3413 | /* stopping an active array */ |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 3414 | if (atomic_read(&mddev->openers) > 0) |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3415 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3416 | err = do_md_stop(mddev, 0, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3417 | break; |
| 3418 | case inactive: |
| 3419 | /* stopping an active array */ |
| 3420 | if (mddev->pers) { |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 3421 | if (atomic_read(&mddev->openers) > 0) |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3422 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3423 | err = do_md_stop(mddev, 2, 0); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3424 | } else |
| 3425 | err = 0; /* already inactive */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3426 | break; |
| 3427 | case suspended: |
| 3428 | break; /* not supported yet */ |
| 3429 | case readonly: |
| 3430 | if (mddev->pers) |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 3431 | err = md_set_readonly(mddev, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3432 | else { |
| 3433 | mddev->ro = 1; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3434 | set_disk_ro(mddev->gendisk, 1); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3435 | err = do_md_run(mddev); |
| 3436 | } |
| 3437 | break; |
| 3438 | case read_auto: |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3439 | if (mddev->pers) { |
NeilBrown | 80268ee | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 3440 | if (mddev->ro == 0) |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 3441 | err = md_set_readonly(mddev, 0); |
NeilBrown | 80268ee | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 3442 | else if (mddev->ro == 1) |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3443 | err = restart_array(mddev); |
| 3444 | if (err == 0) { |
| 3445 | mddev->ro = 2; |
| 3446 | set_disk_ro(mddev->gendisk, 0); |
| 3447 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3448 | } else { |
| 3449 | mddev->ro = 2; |
| 3450 | err = do_md_run(mddev); |
| 3451 | } |
| 3452 | break; |
| 3453 | case clean: |
| 3454 | if (mddev->pers) { |
| 3455 | restart_array(mddev); |
| 3456 | spin_lock_irq(&mddev->write_lock); |
| 3457 | if (atomic_read(&mddev->writes_pending) == 0) { |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3458 | if (mddev->in_sync == 0) { |
| 3459 | mddev->in_sync = 1; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3460 | if (mddev->safemode == 1) |
| 3461 | mddev->safemode = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3462 | if (mddev->persistent) |
| 3463 | set_bit(MD_CHANGE_CLEAN, |
| 3464 | &mddev->flags); |
| 3465 | } |
| 3466 | err = 0; |
| 3467 | } else |
| 3468 | err = -EBUSY; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3469 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 5bf2959 | 2009-05-07 12:50:57 +1000 | [diff] [blame] | 3470 | } else |
| 3471 | err = -EINVAL; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3472 | break; |
| 3473 | case active: |
| 3474 | if (mddev->pers) { |
| 3475 | restart_array(mddev); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3476 | if (mddev->external) |
| 3477 | clear_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3478 | wake_up(&mddev->sb_wait); |
| 3479 | err = 0; |
| 3480 | } else { |
| 3481 | mddev->ro = 0; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3482 | set_disk_ro(mddev->gendisk, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3483 | err = do_md_run(mddev); |
| 3484 | } |
| 3485 | break; |
| 3486 | case write_pending: |
| 3487 | case active_idle: |
| 3488 | /* these cannot be set */ |
| 3489 | break; |
| 3490 | } |
| 3491 | if (err) |
| 3492 | return err; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3493 | else { |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 3494 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3495 | return len; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3496 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3497 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3498 | static struct md_sysfs_entry md_array_state = |
| 3499 | __ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3500 | |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3501 | static ssize_t |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 3502 | max_corrected_read_errors_show(mddev_t *mddev, char *page) { |
| 3503 | return sprintf(page, "%d\n", |
| 3504 | atomic_read(&mddev->max_corr_read_errors)); |
| 3505 | } |
| 3506 | |
| 3507 | static ssize_t |
| 3508 | max_corrected_read_errors_store(mddev_t *mddev, const char *buf, size_t len) |
| 3509 | { |
| 3510 | char *e; |
| 3511 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3512 | |
| 3513 | if (*buf && (*e == 0 || *e == '\n')) { |
| 3514 | atomic_set(&mddev->max_corr_read_errors, n); |
| 3515 | return len; |
| 3516 | } |
| 3517 | return -EINVAL; |
| 3518 | } |
| 3519 | |
| 3520 | static struct md_sysfs_entry max_corr_read_errors = |
| 3521 | __ATTR(max_read_errors, S_IRUGO|S_IWUSR, max_corrected_read_errors_show, |
| 3522 | max_corrected_read_errors_store); |
| 3523 | |
| 3524 | static ssize_t |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3525 | null_show(mddev_t *mddev, char *page) |
| 3526 | { |
| 3527 | return -EINVAL; |
| 3528 | } |
| 3529 | |
| 3530 | static ssize_t |
| 3531 | new_dev_store(mddev_t *mddev, const char *buf, size_t len) |
| 3532 | { |
| 3533 | /* buf must be %d:%d\n? giving major and minor numbers */ |
| 3534 | /* The new device is added to the array. |
| 3535 | * If the array has a persistent superblock, we read the |
| 3536 | * superblock to initialise info and check validity. |
| 3537 | * Otherwise, only checking done is that in bind_rdev_to_array, |
| 3538 | * which mainly checks size. |
| 3539 | */ |
| 3540 | char *e; |
| 3541 | int major = simple_strtoul(buf, &e, 10); |
| 3542 | int minor; |
| 3543 | dev_t dev; |
| 3544 | mdk_rdev_t *rdev; |
| 3545 | int err; |
| 3546 | |
| 3547 | if (!*buf || *e != ':' || !e[1] || e[1] == '\n') |
| 3548 | return -EINVAL; |
| 3549 | minor = simple_strtoul(e+1, &e, 10); |
| 3550 | if (*e && *e != '\n') |
| 3551 | return -EINVAL; |
| 3552 | dev = MKDEV(major, minor); |
| 3553 | if (major != MAJOR(dev) || |
| 3554 | minor != MINOR(dev)) |
| 3555 | return -EOVERFLOW; |
| 3556 | |
| 3557 | |
| 3558 | if (mddev->persistent) { |
| 3559 | rdev = md_import_device(dev, mddev->major_version, |
| 3560 | mddev->minor_version); |
| 3561 | if (!IS_ERR(rdev) && !list_empty(&mddev->disks)) { |
| 3562 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 3563 | mdk_rdev_t, same_set); |
| 3564 | err = super_types[mddev->major_version] |
| 3565 | .load_super(rdev, rdev0, mddev->minor_version); |
| 3566 | if (err < 0) |
| 3567 | goto out; |
| 3568 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 3569 | } else if (mddev->external) |
| 3570 | rdev = md_import_device(dev, -2, -1); |
| 3571 | else |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3572 | rdev = md_import_device(dev, -1, -1); |
| 3573 | |
| 3574 | if (IS_ERR(rdev)) |
| 3575 | return PTR_ERR(rdev); |
| 3576 | err = bind_rdev_to_array(rdev, mddev); |
| 3577 | out: |
| 3578 | if (err) |
| 3579 | export_rdev(rdev); |
| 3580 | return err ? err : len; |
| 3581 | } |
| 3582 | |
| 3583 | static struct md_sysfs_entry md_new_device = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3584 | __ATTR(new_dev, S_IWUSR, null_show, new_dev_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3585 | |
| 3586 | static ssize_t |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 3587 | bitmap_store(mddev_t *mddev, const char *buf, size_t len) |
| 3588 | { |
| 3589 | char *end; |
| 3590 | unsigned long chunk, end_chunk; |
| 3591 | |
| 3592 | if (!mddev->bitmap) |
| 3593 | goto out; |
| 3594 | /* buf should be <chunk> <chunk> ... or <chunk>-<chunk> ... (range) */ |
| 3595 | while (*buf) { |
| 3596 | chunk = end_chunk = simple_strtoul(buf, &end, 0); |
| 3597 | if (buf == end) break; |
| 3598 | if (*end == '-') { /* range */ |
| 3599 | buf = end + 1; |
| 3600 | end_chunk = simple_strtoul(buf, &end, 0); |
| 3601 | if (buf == end) break; |
| 3602 | } |
| 3603 | if (*end && !isspace(*end)) break; |
| 3604 | bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk); |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 3605 | buf = skip_spaces(end); |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 3606 | } |
| 3607 | bitmap_unplug(mddev->bitmap); /* flush the bits to disk */ |
| 3608 | out: |
| 3609 | return len; |
| 3610 | } |
| 3611 | |
| 3612 | static struct md_sysfs_entry md_bitmap = |
| 3613 | __ATTR(bitmap_set_bits, S_IWUSR, null_show, bitmap_store); |
| 3614 | |
| 3615 | static ssize_t |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3616 | size_show(mddev_t *mddev, char *page) |
| 3617 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3618 | return sprintf(page, "%llu\n", |
| 3619 | (unsigned long long)mddev->dev_sectors / 2); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3620 | } |
| 3621 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3622 | static int update_size(mddev_t *mddev, sector_t num_sectors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3623 | |
| 3624 | static ssize_t |
| 3625 | size_store(mddev_t *mddev, const char *buf, size_t len) |
| 3626 | { |
| 3627 | /* If array is inactive, we can reduce the component size, but |
| 3628 | * not increase it (except from 0). |
| 3629 | * If array is active, we can try an on-line resize |
| 3630 | */ |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 3631 | sector_t sectors; |
| 3632 | int err = strict_blocks_to_sectors(buf, §ors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3633 | |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3634 | if (err < 0) |
| 3635 | return err; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3636 | if (mddev->pers) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3637 | err = update_size(mddev, sectors); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 3638 | md_update_sb(mddev, 1); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3639 | } else { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3640 | if (mddev->dev_sectors == 0 || |
| 3641 | mddev->dev_sectors > sectors) |
| 3642 | mddev->dev_sectors = sectors; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3643 | else |
| 3644 | err = -ENOSPC; |
| 3645 | } |
| 3646 | return err ? err : len; |
| 3647 | } |
| 3648 | |
| 3649 | static struct md_sysfs_entry md_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3650 | __ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3651 | |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3652 | |
| 3653 | /* Metdata version. |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3654 | * This is one of |
| 3655 | * 'none' for arrays with no metadata (good luck...) |
| 3656 | * 'external' for arrays with externally managed metadata, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3657 | * or N.M for internally known formats |
| 3658 | */ |
| 3659 | static ssize_t |
| 3660 | metadata_show(mddev_t *mddev, char *page) |
| 3661 | { |
| 3662 | if (mddev->persistent) |
| 3663 | return sprintf(page, "%d.%d\n", |
| 3664 | mddev->major_version, mddev->minor_version); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3665 | else if (mddev->external) |
| 3666 | return sprintf(page, "external:%s\n", mddev->metadata_type); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3667 | else |
| 3668 | return sprintf(page, "none\n"); |
| 3669 | } |
| 3670 | |
| 3671 | static ssize_t |
| 3672 | metadata_store(mddev_t *mddev, const char *buf, size_t len) |
| 3673 | { |
| 3674 | int major, minor; |
| 3675 | char *e; |
NeilBrown | ea43ddd | 2008-10-13 11:55:11 +1100 | [diff] [blame] | 3676 | /* Changing the details of 'external' metadata is |
| 3677 | * always permitted. Otherwise there must be |
| 3678 | * no devices attached to the array. |
| 3679 | */ |
| 3680 | if (mddev->external && strncmp(buf, "external:", 9) == 0) |
| 3681 | ; |
| 3682 | else if (!list_empty(&mddev->disks)) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3683 | return -EBUSY; |
| 3684 | |
| 3685 | if (cmd_match(buf, "none")) { |
| 3686 | mddev->persistent = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3687 | mddev->external = 0; |
| 3688 | mddev->major_version = 0; |
| 3689 | mddev->minor_version = 90; |
| 3690 | return len; |
| 3691 | } |
| 3692 | if (strncmp(buf, "external:", 9) == 0) { |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 3693 | size_t namelen = len-9; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3694 | if (namelen >= sizeof(mddev->metadata_type)) |
| 3695 | namelen = sizeof(mddev->metadata_type)-1; |
| 3696 | strncpy(mddev->metadata_type, buf+9, namelen); |
| 3697 | mddev->metadata_type[namelen] = 0; |
| 3698 | if (namelen && mddev->metadata_type[namelen-1] == '\n') |
| 3699 | mddev->metadata_type[--namelen] = 0; |
| 3700 | mddev->persistent = 0; |
| 3701 | mddev->external = 1; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3702 | mddev->major_version = 0; |
| 3703 | mddev->minor_version = 90; |
| 3704 | return len; |
| 3705 | } |
| 3706 | major = simple_strtoul(buf, &e, 10); |
| 3707 | if (e==buf || *e != '.') |
| 3708 | return -EINVAL; |
| 3709 | buf = e+1; |
| 3710 | minor = simple_strtoul(buf, &e, 10); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 3711 | if (e==buf || (*e && *e != '\n') ) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3712 | return -EINVAL; |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 3713 | if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3714 | return -ENOENT; |
| 3715 | mddev->major_version = major; |
| 3716 | mddev->minor_version = minor; |
| 3717 | mddev->persistent = 1; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3718 | mddev->external = 0; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3719 | return len; |
| 3720 | } |
| 3721 | |
| 3722 | static struct md_sysfs_entry md_metadata = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3723 | __ATTR(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3724 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3725 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3726 | action_show(mddev_t *mddev, char *page) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3727 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3728 | char *type = "idle"; |
NeilBrown | b6a9ce6 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 3729 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 3730 | type = "frozen"; |
| 3731 | else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
NeilBrown | 2b12ab6 | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 3732 | (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3733 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 3734 | type = "reshape"; |
| 3735 | else if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3736 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 3737 | type = "resync"; |
| 3738 | else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 3739 | type = "check"; |
| 3740 | else |
| 3741 | type = "repair"; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3742 | } else if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3743 | type = "recover"; |
| 3744 | } |
| 3745 | return sprintf(page, "%s\n", type); |
| 3746 | } |
| 3747 | |
| 3748 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3749 | action_store(mddev_t *mddev, const char *page, size_t len) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3750 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3751 | if (!mddev->pers || !mddev->pers->sync_request) |
| 3752 | return -EINVAL; |
| 3753 | |
NeilBrown | b6a9ce6 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 3754 | if (cmd_match(page, "frozen")) |
| 3755 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3756 | else |
| 3757 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3758 | |
| 3759 | if (cmd_match(page, "idle") || cmd_match(page, "frozen")) { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3760 | if (mddev->sync_thread) { |
| 3761 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 3762 | md_unregister_thread(mddev->sync_thread); |
| 3763 | mddev->sync_thread = NULL; |
| 3764 | mddev->recovery = 0; |
| 3765 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3766 | } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 3767 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3768 | return -EBUSY; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3769 | else if (cmd_match(page, "resync")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3770 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3771 | else if (cmd_match(page, "recover")) { |
| 3772 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
| 3773 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3774 | } else if (cmd_match(page, "reshape")) { |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3775 | int err; |
| 3776 | if (mddev->pers->start_reshape == NULL) |
| 3777 | return -EINVAL; |
| 3778 | err = mddev->pers->start_reshape(mddev); |
| 3779 | if (err) |
| 3780 | return err; |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 3781 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3782 | } else { |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 3783 | if (cmd_match(page, "check")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3784 | set_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
NeilBrown | 2adc7d4 | 2006-05-20 14:59:57 -0700 | [diff] [blame] | 3785 | else if (!cmd_match(page, "repair")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3786 | return -EINVAL; |
| 3787 | set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
| 3788 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3789 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3790 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3791 | md_wakeup_thread(mddev->thread); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 3792 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3793 | return len; |
| 3794 | } |
| 3795 | |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3796 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3797 | mismatch_cnt_show(mddev_t *mddev, char *page) |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3798 | { |
| 3799 | return sprintf(page, "%llu\n", |
| 3800 | (unsigned long long) mddev->resync_mismatches); |
| 3801 | } |
| 3802 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3803 | static struct md_sysfs_entry md_scan_mode = |
| 3804 | __ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3805 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3806 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3807 | static struct md_sysfs_entry md_mismatches = __ATTR_RO(mismatch_cnt); |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3808 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3809 | static ssize_t |
| 3810 | sync_min_show(mddev_t *mddev, char *page) |
| 3811 | { |
| 3812 | return sprintf(page, "%d (%s)\n", speed_min(mddev), |
| 3813 | mddev->sync_speed_min ? "local": "system"); |
| 3814 | } |
| 3815 | |
| 3816 | static ssize_t |
| 3817 | sync_min_store(mddev_t *mddev, const char *buf, size_t len) |
| 3818 | { |
| 3819 | int min; |
| 3820 | char *e; |
| 3821 | if (strncmp(buf, "system", 6)==0) { |
| 3822 | mddev->sync_speed_min = 0; |
| 3823 | return len; |
| 3824 | } |
| 3825 | min = simple_strtoul(buf, &e, 10); |
| 3826 | if (buf == e || (*e && *e != '\n') || min <= 0) |
| 3827 | return -EINVAL; |
| 3828 | mddev->sync_speed_min = min; |
| 3829 | return len; |
| 3830 | } |
| 3831 | |
| 3832 | static struct md_sysfs_entry md_sync_min = |
| 3833 | __ATTR(sync_speed_min, S_IRUGO|S_IWUSR, sync_min_show, sync_min_store); |
| 3834 | |
| 3835 | static ssize_t |
| 3836 | sync_max_show(mddev_t *mddev, char *page) |
| 3837 | { |
| 3838 | return sprintf(page, "%d (%s)\n", speed_max(mddev), |
| 3839 | mddev->sync_speed_max ? "local": "system"); |
| 3840 | } |
| 3841 | |
| 3842 | static ssize_t |
| 3843 | sync_max_store(mddev_t *mddev, const char *buf, size_t len) |
| 3844 | { |
| 3845 | int max; |
| 3846 | char *e; |
| 3847 | if (strncmp(buf, "system", 6)==0) { |
| 3848 | mddev->sync_speed_max = 0; |
| 3849 | return len; |
| 3850 | } |
| 3851 | max = simple_strtoul(buf, &e, 10); |
| 3852 | if (buf == e || (*e && *e != '\n') || max <= 0) |
| 3853 | return -EINVAL; |
| 3854 | mddev->sync_speed_max = max; |
| 3855 | return len; |
| 3856 | } |
| 3857 | |
| 3858 | static struct md_sysfs_entry md_sync_max = |
| 3859 | __ATTR(sync_speed_max, S_IRUGO|S_IWUSR, sync_max_show, sync_max_store); |
| 3860 | |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 3861 | static ssize_t |
| 3862 | degraded_show(mddev_t *mddev, char *page) |
| 3863 | { |
| 3864 | return sprintf(page, "%d\n", mddev->degraded); |
| 3865 | } |
| 3866 | static struct md_sysfs_entry md_degraded = __ATTR_RO(degraded); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3867 | |
| 3868 | static ssize_t |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 3869 | sync_force_parallel_show(mddev_t *mddev, char *page) |
| 3870 | { |
| 3871 | return sprintf(page, "%d\n", mddev->parallel_resync); |
| 3872 | } |
| 3873 | |
| 3874 | static ssize_t |
| 3875 | sync_force_parallel_store(mddev_t *mddev, const char *buf, size_t len) |
| 3876 | { |
| 3877 | long n; |
| 3878 | |
| 3879 | if (strict_strtol(buf, 10, &n)) |
| 3880 | return -EINVAL; |
| 3881 | |
| 3882 | if (n != 0 && n != 1) |
| 3883 | return -EINVAL; |
| 3884 | |
| 3885 | mddev->parallel_resync = n; |
| 3886 | |
| 3887 | if (mddev->sync_thread) |
| 3888 | wake_up(&resync_wait); |
| 3889 | |
| 3890 | return len; |
| 3891 | } |
| 3892 | |
| 3893 | /* force parallel resync, even with shared block devices */ |
| 3894 | static struct md_sysfs_entry md_sync_force_parallel = |
| 3895 | __ATTR(sync_force_parallel, S_IRUGO|S_IWUSR, |
| 3896 | sync_force_parallel_show, sync_force_parallel_store); |
| 3897 | |
| 3898 | static ssize_t |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3899 | sync_speed_show(mddev_t *mddev, char *page) |
| 3900 | { |
| 3901 | unsigned long resync, dt, db; |
NeilBrown | d1a7c50 | 2009-03-31 15:24:32 +1100 | [diff] [blame] | 3902 | if (mddev->curr_resync == 0) |
| 3903 | return sprintf(page, "none\n"); |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3904 | resync = mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active); |
| 3905 | dt = (jiffies - mddev->resync_mark) / HZ; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3906 | if (!dt) dt++; |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3907 | db = resync - mddev->resync_mark_cnt; |
| 3908 | return sprintf(page, "%lu\n", db/dt/2); /* K/sec */ |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3909 | } |
| 3910 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3911 | static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3912 | |
| 3913 | static ssize_t |
| 3914 | sync_completed_show(mddev_t *mddev, char *page) |
| 3915 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3916 | unsigned long max_sectors, resync; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3917 | |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 3918 | if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3919 | return sprintf(page, "none\n"); |
| 3920 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3921 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3922 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3923 | else |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3924 | max_sectors = mddev->dev_sectors; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3925 | |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 3926 | resync = mddev->curr_resync_completed; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3927 | return sprintf(page, "%lu / %lu\n", resync, max_sectors); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3928 | } |
| 3929 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3930 | static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3931 | |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3932 | static ssize_t |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3933 | min_sync_show(mddev_t *mddev, char *page) |
| 3934 | { |
| 3935 | return sprintf(page, "%llu\n", |
| 3936 | (unsigned long long)mddev->resync_min); |
| 3937 | } |
| 3938 | static ssize_t |
| 3939 | min_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3940 | { |
| 3941 | unsigned long long min; |
| 3942 | if (strict_strtoull(buf, 10, &min)) |
| 3943 | return -EINVAL; |
| 3944 | if (min > mddev->resync_max) |
| 3945 | return -EINVAL; |
| 3946 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3947 | return -EBUSY; |
| 3948 | |
| 3949 | /* Must be a multiple of chunk_size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3950 | if (mddev->chunk_sectors) { |
raz ben yehuda | 2ac06c3 | 2009-06-16 17:01:42 +1000 | [diff] [blame] | 3951 | sector_t temp = min; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3952 | if (sector_div(temp, mddev->chunk_sectors)) |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3953 | return -EINVAL; |
| 3954 | } |
| 3955 | mddev->resync_min = min; |
| 3956 | |
| 3957 | return len; |
| 3958 | } |
| 3959 | |
| 3960 | static struct md_sysfs_entry md_min_sync = |
| 3961 | __ATTR(sync_min, S_IRUGO|S_IWUSR, min_sync_show, min_sync_store); |
| 3962 | |
| 3963 | static ssize_t |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3964 | max_sync_show(mddev_t *mddev, char *page) |
| 3965 | { |
| 3966 | if (mddev->resync_max == MaxSector) |
| 3967 | return sprintf(page, "max\n"); |
| 3968 | else |
| 3969 | return sprintf(page, "%llu\n", |
| 3970 | (unsigned long long)mddev->resync_max); |
| 3971 | } |
| 3972 | static ssize_t |
| 3973 | max_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3974 | { |
| 3975 | if (strncmp(buf, "max", 3) == 0) |
| 3976 | mddev->resync_max = MaxSector; |
| 3977 | else { |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3978 | unsigned long long max; |
| 3979 | if (strict_strtoull(buf, 10, &max)) |
| 3980 | return -EINVAL; |
| 3981 | if (max < mddev->resync_min) |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3982 | return -EINVAL; |
| 3983 | if (max < mddev->resync_max && |
NeilBrown | 4d484a4 | 2009-08-13 10:41:50 +1000 | [diff] [blame] | 3984 | mddev->ro == 0 && |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3985 | test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3986 | return -EBUSY; |
| 3987 | |
| 3988 | /* Must be a multiple of chunk_size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3989 | if (mddev->chunk_sectors) { |
raz ben yehuda | 2ac06c3 | 2009-06-16 17:01:42 +1000 | [diff] [blame] | 3990 | sector_t temp = max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3991 | if (sector_div(temp, mddev->chunk_sectors)) |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3992 | return -EINVAL; |
| 3993 | } |
| 3994 | mddev->resync_max = max; |
| 3995 | } |
| 3996 | wake_up(&mddev->recovery_wait); |
| 3997 | return len; |
| 3998 | } |
| 3999 | |
| 4000 | static struct md_sysfs_entry md_max_sync = |
| 4001 | __ATTR(sync_max, S_IRUGO|S_IWUSR, max_sync_show, max_sync_store); |
| 4002 | |
| 4003 | static ssize_t |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4004 | suspend_lo_show(mddev_t *mddev, char *page) |
| 4005 | { |
| 4006 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_lo); |
| 4007 | } |
| 4008 | |
| 4009 | static ssize_t |
| 4010 | suspend_lo_store(mddev_t *mddev, const char *buf, size_t len) |
| 4011 | { |
| 4012 | char *e; |
| 4013 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 4014 | |
NeilBrown | b8d966e | 2009-07-01 11:14:04 +1000 | [diff] [blame] | 4015 | if (mddev->pers == NULL || |
| 4016 | mddev->pers->quiesce == NULL) |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4017 | return -EINVAL; |
| 4018 | if (buf == e || (*e && *e != '\n')) |
| 4019 | return -EINVAL; |
| 4020 | if (new >= mddev->suspend_hi || |
| 4021 | (new > mddev->suspend_lo && new < mddev->suspend_hi)) { |
| 4022 | mddev->suspend_lo = new; |
| 4023 | mddev->pers->quiesce(mddev, 2); |
| 4024 | return len; |
| 4025 | } else |
| 4026 | return -EINVAL; |
| 4027 | } |
| 4028 | static struct md_sysfs_entry md_suspend_lo = |
| 4029 | __ATTR(suspend_lo, S_IRUGO|S_IWUSR, suspend_lo_show, suspend_lo_store); |
| 4030 | |
| 4031 | |
| 4032 | static ssize_t |
| 4033 | suspend_hi_show(mddev_t *mddev, char *page) |
| 4034 | { |
| 4035 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_hi); |
| 4036 | } |
| 4037 | |
| 4038 | static ssize_t |
| 4039 | suspend_hi_store(mddev_t *mddev, const char *buf, size_t len) |
| 4040 | { |
| 4041 | char *e; |
| 4042 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 4043 | |
NeilBrown | b8d966e | 2009-07-01 11:14:04 +1000 | [diff] [blame] | 4044 | if (mddev->pers == NULL || |
| 4045 | mddev->pers->quiesce == NULL) |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4046 | return -EINVAL; |
| 4047 | if (buf == e || (*e && *e != '\n')) |
| 4048 | return -EINVAL; |
| 4049 | if ((new <= mddev->suspend_lo && mddev->suspend_lo >= mddev->suspend_hi) || |
| 4050 | (new > mddev->suspend_lo && new > mddev->suspend_hi)) { |
| 4051 | mddev->suspend_hi = new; |
| 4052 | mddev->pers->quiesce(mddev, 1); |
| 4053 | mddev->pers->quiesce(mddev, 0); |
| 4054 | return len; |
| 4055 | } else |
| 4056 | return -EINVAL; |
| 4057 | } |
| 4058 | static struct md_sysfs_entry md_suspend_hi = |
| 4059 | __ATTR(suspend_hi, S_IRUGO|S_IWUSR, suspend_hi_show, suspend_hi_store); |
| 4060 | |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 4061 | static ssize_t |
| 4062 | reshape_position_show(mddev_t *mddev, char *page) |
| 4063 | { |
| 4064 | if (mddev->reshape_position != MaxSector) |
| 4065 | return sprintf(page, "%llu\n", |
| 4066 | (unsigned long long)mddev->reshape_position); |
| 4067 | strcpy(page, "none\n"); |
| 4068 | return 5; |
| 4069 | } |
| 4070 | |
| 4071 | static ssize_t |
| 4072 | reshape_position_store(mddev_t *mddev, const char *buf, size_t len) |
| 4073 | { |
| 4074 | char *e; |
| 4075 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 4076 | if (mddev->pers) |
| 4077 | return -EBUSY; |
| 4078 | if (buf == e || (*e && *e != '\n')) |
| 4079 | return -EINVAL; |
| 4080 | mddev->reshape_position = new; |
| 4081 | mddev->delta_disks = 0; |
| 4082 | mddev->new_level = mddev->level; |
| 4083 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4084 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 4085 | return len; |
| 4086 | } |
| 4087 | |
| 4088 | static struct md_sysfs_entry md_reshape_position = |
| 4089 | __ATTR(reshape_position, S_IRUGO|S_IWUSR, reshape_position_show, |
| 4090 | reshape_position_store); |
| 4091 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4092 | static ssize_t |
| 4093 | array_size_show(mddev_t *mddev, char *page) |
| 4094 | { |
| 4095 | if (mddev->external_size) |
| 4096 | return sprintf(page, "%llu\n", |
| 4097 | (unsigned long long)mddev->array_sectors/2); |
| 4098 | else |
| 4099 | return sprintf(page, "default\n"); |
| 4100 | } |
| 4101 | |
| 4102 | static ssize_t |
| 4103 | array_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 4104 | { |
| 4105 | sector_t sectors; |
| 4106 | |
| 4107 | if (strncmp(buf, "default", 7) == 0) { |
| 4108 | if (mddev->pers) |
| 4109 | sectors = mddev->pers->size(mddev, 0, 0); |
| 4110 | else |
| 4111 | sectors = mddev->array_sectors; |
| 4112 | |
| 4113 | mddev->external_size = 0; |
| 4114 | } else { |
| 4115 | if (strict_blocks_to_sectors(buf, §ors) < 0) |
| 4116 | return -EINVAL; |
| 4117 | if (mddev->pers && mddev->pers->size(mddev, 0, 0) < sectors) |
NeilBrown | 2b69c83 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 4118 | return -E2BIG; |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4119 | |
| 4120 | mddev->external_size = 1; |
| 4121 | } |
| 4122 | |
| 4123 | mddev->array_sectors = sectors; |
| 4124 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4125 | if (mddev->pers) |
| 4126 | revalidate_disk(mddev->gendisk); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4127 | |
| 4128 | return len; |
| 4129 | } |
| 4130 | |
| 4131 | static struct md_sysfs_entry md_array_size = |
| 4132 | __ATTR(array_size, S_IRUGO|S_IWUSR, array_size_show, |
| 4133 | array_size_store); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4134 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4135 | static struct attribute *md_default_attrs[] = { |
| 4136 | &md_level.attr, |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 4137 | &md_layout.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4138 | &md_raid_disks.attr, |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 4139 | &md_chunk_size.attr, |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4140 | &md_size.attr, |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 4141 | &md_resync_start.attr, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 4142 | &md_metadata.attr, |
NeilBrown | 6d7ff73 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 4143 | &md_new_device.attr, |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 4144 | &md_safe_delay.attr, |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4145 | &md_array_state.attr, |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 4146 | &md_reshape_position.attr, |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4147 | &md_array_size.attr, |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 4148 | &max_corr_read_errors.attr, |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 4149 | NULL, |
| 4150 | }; |
| 4151 | |
| 4152 | static struct attribute *md_redundancy_attrs[] = { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 4153 | &md_scan_mode.attr, |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 4154 | &md_mismatches.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 4155 | &md_sync_min.attr, |
| 4156 | &md_sync_max.attr, |
| 4157 | &md_sync_speed.attr, |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 4158 | &md_sync_force_parallel.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 4159 | &md_sync_completed.attr, |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 4160 | &md_min_sync.attr, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4161 | &md_max_sync.attr, |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4162 | &md_suspend_lo.attr, |
| 4163 | &md_suspend_hi.attr, |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 4164 | &md_bitmap.attr, |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 4165 | &md_degraded.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4166 | NULL, |
| 4167 | }; |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 4168 | static struct attribute_group md_redundancy_group = { |
| 4169 | .name = NULL, |
| 4170 | .attrs = md_redundancy_attrs, |
| 4171 | }; |
| 4172 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4173 | |
| 4174 | static ssize_t |
| 4175 | md_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 4176 | { |
| 4177 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 4178 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4179 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4180 | |
| 4181 | if (!entry->show) |
| 4182 | return -EIO; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4183 | rv = mddev_lock(mddev); |
| 4184 | if (!rv) { |
| 4185 | rv = entry->show(mddev, page); |
| 4186 | mddev_unlock(mddev); |
| 4187 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4188 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | static ssize_t |
| 4192 | md_attr_store(struct kobject *kobj, struct attribute *attr, |
| 4193 | const char *page, size_t length) |
| 4194 | { |
| 4195 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 4196 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4197 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4198 | |
| 4199 | if (!entry->store) |
| 4200 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 4201 | if (!capable(CAP_SYS_ADMIN)) |
| 4202 | return -EACCES; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4203 | rv = mddev_lock(mddev); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4204 | if (mddev->hold_active == UNTIL_IOCTL) |
| 4205 | mddev->hold_active = 0; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4206 | if (!rv) { |
| 4207 | rv = entry->store(mddev, page, length); |
| 4208 | mddev_unlock(mddev); |
| 4209 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4210 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | static void md_free(struct kobject *ko) |
| 4214 | { |
| 4215 | mddev_t *mddev = container_of(ko, mddev_t, kobj); |
NeilBrown | a21d150 | 2009-01-09 08:31:09 +1100 | [diff] [blame] | 4216 | |
| 4217 | if (mddev->sysfs_state) |
| 4218 | sysfs_put(mddev->sysfs_state); |
| 4219 | |
| 4220 | if (mddev->gendisk) { |
| 4221 | del_gendisk(mddev->gendisk); |
| 4222 | put_disk(mddev->gendisk); |
| 4223 | } |
| 4224 | if (mddev->queue) |
| 4225 | blk_cleanup_queue(mddev->queue); |
| 4226 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4227 | kfree(mddev); |
| 4228 | } |
| 4229 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 4230 | static const struct sysfs_ops md_sysfs_ops = { |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4231 | .show = md_attr_show, |
| 4232 | .store = md_attr_store, |
| 4233 | }; |
| 4234 | static struct kobj_type md_ktype = { |
| 4235 | .release = md_free, |
| 4236 | .sysfs_ops = &md_sysfs_ops, |
| 4237 | .default_attrs = md_default_attrs, |
| 4238 | }; |
| 4239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | int mdp_major = 0; |
| 4241 | |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 4242 | static void mddev_delayed_delete(struct work_struct *ws) |
| 4243 | { |
| 4244 | mddev_t *mddev = container_of(ws, mddev_t, del_work); |
| 4245 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 4246 | sysfs_remove_group(&mddev->kobj, &md_bitmap_group); |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 4247 | kobject_del(&mddev->kobj); |
| 4248 | kobject_put(&mddev->kobj); |
| 4249 | } |
| 4250 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4251 | static int md_alloc(dev_t dev, char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 4253 | static DEFINE_MUTEX(disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | mddev_t *mddev = mddev_find(dev); |
| 4255 | struct gendisk *disk; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4256 | int partitioned; |
| 4257 | int shift; |
| 4258 | int unit; |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 4259 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | |
| 4261 | if (!mddev) |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4262 | return -ENODEV; |
| 4263 | |
| 4264 | partitioned = (MAJOR(mddev->unit) != MD_MAJOR); |
| 4265 | shift = partitioned ? MdpMinorShift : 0; |
| 4266 | unit = MINOR(mddev->unit) >> shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4268 | /* wait for any previous instance if this device |
| 4269 | * to be completed removed (mddev_delayed_delete). |
| 4270 | */ |
| 4271 | flush_scheduled_work(); |
| 4272 | |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 4273 | mutex_lock(&disks_mutex); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4274 | error = -EEXIST; |
| 4275 | if (mddev->gendisk) |
| 4276 | goto abort; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4277 | |
| 4278 | if (name) { |
| 4279 | /* Need to ensure that 'name' is not a duplicate. |
| 4280 | */ |
| 4281 | mddev_t *mddev2; |
| 4282 | spin_lock(&all_mddevs_lock); |
| 4283 | |
| 4284 | list_for_each_entry(mddev2, &all_mddevs, all_mddevs) |
| 4285 | if (mddev2->gendisk && |
| 4286 | strcmp(mddev2->gendisk->disk_name, name) == 0) { |
| 4287 | spin_unlock(&all_mddevs_lock); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4288 | goto abort; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4289 | } |
| 4290 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | } |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4292 | |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4293 | error = -ENOMEM; |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4294 | mddev->queue = blk_alloc_queue(GFP_KERNEL); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4295 | if (!mddev->queue) |
| 4296 | goto abort; |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4297 | mddev->queue->queuedata = mddev; |
| 4298 | |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4299 | /* Can be unlocked because the queue is new: no concurrency */ |
| 4300 | queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, mddev->queue); |
| 4301 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4302 | blk_queue_make_request(mddev->queue, md_make_request); |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | disk = alloc_disk(1 << shift); |
| 4305 | if (!disk) { |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4306 | blk_cleanup_queue(mddev->queue); |
| 4307 | mddev->queue = NULL; |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4308 | goto abort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | } |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4310 | disk->major = MAJOR(mddev->unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | disk->first_minor = unit << shift; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4312 | if (name) |
| 4313 | strcpy(disk->disk_name, name); |
| 4314 | else if (partitioned) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | sprintf(disk->disk_name, "md_d%d", unit); |
Greg Kroah-Hartman | ce7b0f4 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 4316 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | sprintf(disk->disk_name, "md%d", unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | disk->fops = &md_fops; |
| 4319 | disk->private_data = mddev; |
| 4320 | disk->queue = mddev->queue; |
NeilBrown | 92850bb | 2008-10-21 13:25:32 +1100 | [diff] [blame] | 4321 | /* Allow extended partitions. This makes the |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4322 | * 'mdp' device redundant, but we can't really |
NeilBrown | 92850bb | 2008-10-21 13:25:32 +1100 | [diff] [blame] | 4323 | * remove it now. |
| 4324 | */ |
| 4325 | disk->flags |= GENHD_FL_EXT_DEVT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | add_disk(disk); |
| 4327 | mddev->gendisk = disk; |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 4328 | error = kobject_init_and_add(&mddev->kobj, &md_ktype, |
| 4329 | &disk_to_dev(disk)->kobj, "%s", "md"); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4330 | if (error) { |
| 4331 | /* This isn't possible, but as kobject_init_and_add is marked |
| 4332 | * __must_check, we must do something with the result |
| 4333 | */ |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4334 | printk(KERN_WARNING "md: cannot register %s/md - name in use\n", |
| 4335 | disk->disk_name); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4336 | error = 0; |
| 4337 | } |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4338 | if (mddev->kobj.sd && |
| 4339 | sysfs_create_group(&mddev->kobj, &md_bitmap_group)) |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 4340 | printk(KERN_DEBUG "pointless warning\n"); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4341 | abort: |
| 4342 | mutex_unlock(&disks_mutex); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4343 | if (!error && mddev->kobj.sd) { |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 4344 | kobject_uevent(&mddev->kobj, KOBJ_ADD); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4345 | mddev->sysfs_state = sysfs_get_dirent_safe(mddev->kobj.sd, "array_state"); |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 4346 | } |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4347 | mddev_put(mddev); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4348 | return error; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | static struct kobject *md_probe(dev_t dev, int *part, void *data) |
| 4352 | { |
| 4353 | md_alloc(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | return NULL; |
| 4355 | } |
| 4356 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4357 | static int add_named_array(const char *val, struct kernel_param *kp) |
| 4358 | { |
| 4359 | /* val must be "md_*" where * is not all digits. |
| 4360 | * We allocate an array with a large free minor number, and |
| 4361 | * set the name to val. val must not already be an active name. |
| 4362 | */ |
| 4363 | int len = strlen(val); |
| 4364 | char buf[DISK_NAME_LEN]; |
| 4365 | |
| 4366 | while (len && val[len-1] == '\n') |
| 4367 | len--; |
| 4368 | if (len >= DISK_NAME_LEN) |
| 4369 | return -E2BIG; |
| 4370 | strlcpy(buf, val, len+1); |
| 4371 | if (strncmp(buf, "md_", 3) != 0) |
| 4372 | return -EINVAL; |
| 4373 | return md_alloc(0, buf); |
| 4374 | } |
| 4375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | static void md_safemode_timeout(unsigned long data) |
| 4377 | { |
| 4378 | mddev_t *mddev = (mddev_t *) data; |
| 4379 | |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 4380 | if (!atomic_read(&mddev->writes_pending)) { |
| 4381 | mddev->safemode = 1; |
| 4382 | if (mddev->external) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4383 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 4384 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | md_wakeup_thread(mddev->thread); |
| 4386 | } |
| 4387 | |
NeilBrown | 6ff8d8e | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4388 | static int start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4390 | int md_run(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4392 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | mdk_rdev_t *rdev; |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4394 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4396 | if (list_empty(&mddev->disks)) |
| 4397 | /* cannot run an array with no devices.. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | |
| 4400 | if (mddev->pers) |
| 4401 | return -EBUSY; |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame^] | 4402 | /* Cannot run until previous stop completes properly */ |
| 4403 | if (mddev->sysfs_active) |
| 4404 | return -EBUSY; |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 4405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | /* |
| 4407 | * Analyze all RAID superblock(s) |
| 4408 | */ |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4409 | if (!mddev->raid_disks) { |
| 4410 | if (!mddev->persistent) |
| 4411 | return -EINVAL; |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4412 | analyze_sbs(mddev); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4415 | if (mddev->level != LEVEL_NONE) |
| 4416 | request_module("md-level-%d", mddev->level); |
| 4417 | else if (mddev->clevel[0]) |
| 4418 | request_module("md-%s", mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | |
| 4420 | /* |
| 4421 | * Drop all container device buffers, from now on |
| 4422 | * the only valid external interface is through the md |
| 4423 | * device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4425 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4426 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | continue; |
| 4428 | sync_blockdev(rdev->bdev); |
Peter Zijlstra | f98393a | 2007-05-06 14:49:54 -0700 | [diff] [blame] | 4429 | invalidate_bdev(rdev->bdev); |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4430 | |
| 4431 | /* perform some consistency tests on the device. |
| 4432 | * We don't want the data to overlap the metadata, |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4433 | * Internal Bitmap issues have been handled elsewhere. |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4434 | */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4435 | if (rdev->data_offset < rdev->sb_start) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4436 | if (mddev->dev_sectors && |
| 4437 | rdev->data_offset + mddev->dev_sectors |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4438 | > rdev->sb_start) { |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4439 | printk("md: %s: data overlaps metadata\n", |
| 4440 | mdname(mddev)); |
| 4441 | return -EINVAL; |
| 4442 | } |
| 4443 | } else { |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4444 | if (rdev->sb_start + rdev->sb_size/512 |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4445 | > rdev->data_offset) { |
| 4446 | printk("md: %s: metadata overlaps data\n", |
| 4447 | mdname(mddev)); |
| 4448 | return -EINVAL; |
| 4449 | } |
| 4450 | } |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4451 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | } |
| 4453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | spin_lock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4455 | pers = find_pers(mddev->level, mddev->clevel); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4456 | if (!pers || !try_module_get(pers->owner)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | spin_unlock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4458 | if (mddev->level != LEVEL_NONE) |
| 4459 | printk(KERN_WARNING "md: personality for level %d is not loaded!\n", |
| 4460 | mddev->level); |
| 4461 | else |
| 4462 | printk(KERN_WARNING "md: personality for level %s is not loaded!\n", |
| 4463 | mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | return -EINVAL; |
| 4465 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4466 | mddev->pers = pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | spin_unlock(&pers_lock); |
NeilBrown | 34817e8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4468 | if (mddev->level != pers->level) { |
| 4469 | mddev->level = pers->level; |
| 4470 | mddev->new_level = pers->level; |
| 4471 | } |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4472 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4474 | if (mddev->reshape_position != MaxSector && |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4475 | pers->start_reshape == NULL) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4476 | /* This personality cannot handle reshaping... */ |
| 4477 | mddev->pers = NULL; |
| 4478 | module_put(pers->owner); |
| 4479 | return -EINVAL; |
| 4480 | } |
| 4481 | |
NeilBrown | 7dd5e7c | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4482 | if (pers->sync_request) { |
| 4483 | /* Warn if this is a potentially silly |
| 4484 | * configuration. |
| 4485 | */ |
| 4486 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 4487 | mdk_rdev_t *rdev2; |
NeilBrown | 7dd5e7c | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4488 | int warned = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4489 | |
| 4490 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 4491 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
NeilBrown | 7dd5e7c | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4492 | if (rdev < rdev2 && |
| 4493 | rdev->bdev->bd_contains == |
| 4494 | rdev2->bdev->bd_contains) { |
| 4495 | printk(KERN_WARNING |
| 4496 | "%s: WARNING: %s appears to be" |
| 4497 | " on the same physical disk as" |
| 4498 | " %s.\n", |
| 4499 | mdname(mddev), |
| 4500 | bdevname(rdev->bdev,b), |
| 4501 | bdevname(rdev2->bdev,b2)); |
| 4502 | warned = 1; |
| 4503 | } |
| 4504 | } |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4505 | |
NeilBrown | 7dd5e7c | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4506 | if (warned) |
| 4507 | printk(KERN_WARNING |
| 4508 | "True protection against single-disk" |
| 4509 | " failure might be compromised.\n"); |
| 4510 | } |
| 4511 | |
NeilBrown | 657390d | 2005-08-26 18:34:16 -0700 | [diff] [blame] | 4512 | mddev->recovery = 0; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4513 | /* may be over-ridden by personality */ |
| 4514 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 4515 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 4516 | mddev->barriers_work = 1; |
NeilBrown | 6ff8d8e | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4517 | mddev->ok_start_degraded = start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | |
NeilBrown | 0f9552b | 2009-12-30 12:08:50 +1100 | [diff] [blame] | 4519 | if (start_readonly && mddev->ro == 0) |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4520 | mddev->ro = 2; /* read-only, but switch on first write */ |
| 4521 | |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 4522 | err = mddev->pers->run(mddev); |
Andre Noll | 13e53df | 2008-03-26 00:07:03 +0100 | [diff] [blame] | 4523 | if (err) |
| 4524 | printk(KERN_ERR "md: pers->run() failed ...\n"); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4525 | else if (mddev->pers->size(mddev, 0, 0) < mddev->array_sectors) { |
| 4526 | WARN_ONCE(!mddev->external_size, "%s: default size too small," |
| 4527 | " but 'external_size' not in effect?\n", __func__); |
| 4528 | printk(KERN_ERR |
| 4529 | "md: invalid array_size %llu > default size %llu\n", |
| 4530 | (unsigned long long)mddev->array_sectors / 2, |
| 4531 | (unsigned long long)mddev->pers->size(mddev, 0, 0) / 2); |
| 4532 | err = -EINVAL; |
| 4533 | mddev->pers->stop(mddev); |
| 4534 | } |
| 4535 | if (err == 0 && mddev->pers->sync_request) { |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 4536 | err = bitmap_create(mddev); |
| 4537 | if (err) { |
| 4538 | printk(KERN_ERR "%s: failed to create bitmap (%d)\n", |
| 4539 | mdname(mddev), err); |
| 4540 | mddev->pers->stop(mddev); |
| 4541 | } |
| 4542 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | module_put(mddev->pers->owner); |
| 4545 | mddev->pers = NULL; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4546 | bitmap_destroy(mddev); |
| 4547 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | } |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4549 | if (mddev->pers->sync_request) { |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4550 | if (mddev->kobj.sd && |
| 4551 | sysfs_create_group(&mddev->kobj, &md_redundancy_group)) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4552 | printk(KERN_WARNING |
| 4553 | "md: cannot register extra attributes for %s\n", |
| 4554 | mdname(mddev)); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4555 | mddev->sysfs_action = sysfs_get_dirent_safe(mddev->kobj.sd, "sync_action"); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4556 | } else if (mddev->ro == 2) /* auto-readonly not meaningful */ |
NeilBrown | fd9d49c | 2005-11-08 21:39:42 -0800 | [diff] [blame] | 4557 | mddev->ro = 0; |
| 4558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | atomic_set(&mddev->writes_pending,0); |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 4560 | atomic_set(&mddev->max_corr_read_errors, |
| 4561 | MD_DEFAULT_MAX_CORRECTED_READ_ERRORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | mddev->safemode = 0; |
| 4563 | mddev->safemode_timer.function = md_safemode_timeout; |
| 4564 | mddev->safemode_timer.data = (unsigned long) mddev; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 4565 | mddev->safemode_delay = (200 * HZ)/1000 +1; /* 200 msec delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | mddev->in_sync = 1; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4567 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4568 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4569 | if (rdev->raid_disk >= 0) { |
| 4570 | char nm[20]; |
| 4571 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4572 | if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4573 | /* failure here is OK */; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4574 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | |
| 4576 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4577 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4578 | if (mddev->flags) |
| 4579 | md_update_sb(mddev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 4581 | md_wakeup_thread(mddev->thread); |
| 4582 | md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4583 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4584 | md_new_event(mddev); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4585 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
| 4586 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 4587 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | return 0; |
| 4589 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4590 | EXPORT_SYMBOL_GPL(md_run); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | |
NeilBrown | fe60b01 | 2010-03-29 11:10:42 +1100 | [diff] [blame] | 4592 | static int do_md_run(mddev_t *mddev) |
| 4593 | { |
| 4594 | int err; |
| 4595 | |
| 4596 | err = md_run(mddev); |
| 4597 | if (err) |
| 4598 | goto out; |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 4599 | err = bitmap_load(mddev); |
| 4600 | if (err) { |
| 4601 | bitmap_destroy(mddev); |
| 4602 | goto out; |
| 4603 | } |
NeilBrown | fe60b01 | 2010-03-29 11:10:42 +1100 | [diff] [blame] | 4604 | set_capacity(mddev->gendisk, mddev->array_sectors); |
| 4605 | revalidate_disk(mddev->gendisk); |
| 4606 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
| 4607 | out: |
| 4608 | return err; |
| 4609 | } |
| 4610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | static int restart_array(mddev_t *mddev) |
| 4612 | { |
| 4613 | struct gendisk *disk = mddev->gendisk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4614 | |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4615 | /* Complain if it has no devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4616 | if (list_empty(&mddev->disks)) |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4617 | return -ENXIO; |
| 4618 | if (!mddev->pers) |
| 4619 | return -EINVAL; |
| 4620 | if (!mddev->ro) |
| 4621 | return -EBUSY; |
| 4622 | mddev->safemode = 0; |
| 4623 | mddev->ro = 0; |
| 4624 | set_disk_ro(disk, 0); |
| 4625 | printk(KERN_INFO "md: %s switched to read-write mode.\n", |
| 4626 | mdname(mddev)); |
| 4627 | /* Kick recovery or resync if necessary */ |
| 4628 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4629 | md_wakeup_thread(mddev->thread); |
| 4630 | md_wakeup_thread(mddev->sync_thread); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4631 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4632 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | } |
| 4634 | |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4635 | /* similar to deny_write_access, but accounts for our holding a reference |
| 4636 | * to the file ourselves */ |
| 4637 | static int deny_bitmap_write_access(struct file * file) |
| 4638 | { |
| 4639 | struct inode *inode = file->f_mapping->host; |
| 4640 | |
| 4641 | spin_lock(&inode->i_lock); |
| 4642 | if (atomic_read(&inode->i_writecount) > 1) { |
| 4643 | spin_unlock(&inode->i_lock); |
| 4644 | return -ETXTBSY; |
| 4645 | } |
| 4646 | atomic_set(&inode->i_writecount, -1); |
| 4647 | spin_unlock(&inode->i_lock); |
| 4648 | |
| 4649 | return 0; |
| 4650 | } |
| 4651 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 4652 | void restore_bitmap_write_access(struct file *file) |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4653 | { |
| 4654 | struct inode *inode = file->f_mapping->host; |
| 4655 | |
| 4656 | spin_lock(&inode->i_lock); |
| 4657 | atomic_set(&inode->i_writecount, 1); |
| 4658 | spin_unlock(&inode->i_lock); |
| 4659 | } |
| 4660 | |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4661 | static void md_clean(mddev_t *mddev) |
| 4662 | { |
| 4663 | mddev->array_sectors = 0; |
| 4664 | mddev->external_size = 0; |
| 4665 | mddev->dev_sectors = 0; |
| 4666 | mddev->raid_disks = 0; |
| 4667 | mddev->recovery_cp = 0; |
| 4668 | mddev->resync_min = 0; |
| 4669 | mddev->resync_max = MaxSector; |
| 4670 | mddev->reshape_position = MaxSector; |
| 4671 | mddev->external = 0; |
| 4672 | mddev->persistent = 0; |
| 4673 | mddev->level = LEVEL_NONE; |
| 4674 | mddev->clevel[0] = 0; |
| 4675 | mddev->flags = 0; |
| 4676 | mddev->ro = 0; |
| 4677 | mddev->metadata_type[0] = 0; |
| 4678 | mddev->chunk_sectors = 0; |
| 4679 | mddev->ctime = mddev->utime = 0; |
| 4680 | mddev->layout = 0; |
| 4681 | mddev->max_disks = 0; |
| 4682 | mddev->events = 0; |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 4683 | mddev->can_decrease_events = 0; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4684 | mddev->delta_disks = 0; |
| 4685 | mddev->new_level = LEVEL_NONE; |
| 4686 | mddev->new_layout = 0; |
| 4687 | mddev->new_chunk_sectors = 0; |
| 4688 | mddev->curr_resync = 0; |
| 4689 | mddev->resync_mismatches = 0; |
| 4690 | mddev->suspend_lo = mddev->suspend_hi = 0; |
| 4691 | mddev->sync_speed_min = mddev->sync_speed_max = 0; |
| 4692 | mddev->recovery = 0; |
| 4693 | mddev->in_sync = 0; |
| 4694 | mddev->degraded = 0; |
| 4695 | mddev->barriers_work = 0; |
| 4696 | mddev->safemode = 0; |
| 4697 | mddev->bitmap_info.offset = 0; |
| 4698 | mddev->bitmap_info.default_offset = 0; |
| 4699 | mddev->bitmap_info.chunksize = 0; |
| 4700 | mddev->bitmap_info.daemon_sleep = 0; |
| 4701 | mddev->bitmap_info.max_write_behind = 0; |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 4702 | mddev->plug = NULL; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4703 | } |
| 4704 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4705 | void md_stop_writes(mddev_t *mddev) |
NeilBrown | a047e12 | 2010-03-29 12:07:53 +1100 | [diff] [blame] | 4706 | { |
| 4707 | if (mddev->sync_thread) { |
| 4708 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 4709 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 4710 | md_unregister_thread(mddev->sync_thread); |
| 4711 | mddev->sync_thread = NULL; |
| 4712 | } |
| 4713 | |
| 4714 | del_timer_sync(&mddev->safemode_timer); |
| 4715 | |
| 4716 | bitmap_flush(mddev); |
| 4717 | md_super_wait(mddev); |
| 4718 | |
| 4719 | if (!mddev->in_sync || mddev->flags) { |
| 4720 | /* mark array as shutdown cleanly */ |
| 4721 | mddev->in_sync = 1; |
| 4722 | md_update_sb(mddev, 1); |
| 4723 | } |
| 4724 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4725 | EXPORT_SYMBOL_GPL(md_stop_writes); |
NeilBrown | a047e12 | 2010-03-29 12:07:53 +1100 | [diff] [blame] | 4726 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4727 | void md_stop(mddev_t *mddev) |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4728 | { |
| 4729 | mddev->pers->stop(mddev); |
| 4730 | if (mddev->pers->sync_request && mddev->to_remove == NULL) |
| 4731 | mddev->to_remove = &md_redundancy_group; |
| 4732 | module_put(mddev->pers->owner); |
| 4733 | mddev->pers = NULL; |
NeilBrown | cca9cf9 | 2010-04-01 12:08:16 +1100 | [diff] [blame] | 4734 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4735 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4736 | EXPORT_SYMBOL_GPL(md_stop); |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4737 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4738 | static int md_set_readonly(mddev_t *mddev, int is_open) |
| 4739 | { |
| 4740 | int err = 0; |
| 4741 | mutex_lock(&mddev->open_mutex); |
| 4742 | if (atomic_read(&mddev->openers) > is_open) { |
| 4743 | printk("md: %s still in use.\n",mdname(mddev)); |
| 4744 | err = -EBUSY; |
| 4745 | goto out; |
| 4746 | } |
| 4747 | if (mddev->pers) { |
| 4748 | md_stop_writes(mddev); |
| 4749 | |
| 4750 | err = -ENXIO; |
| 4751 | if (mddev->ro==1) |
| 4752 | goto out; |
| 4753 | mddev->ro = 1; |
| 4754 | set_disk_ro(mddev->gendisk, 1); |
| 4755 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4756 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4757 | err = 0; |
| 4758 | } |
| 4759 | out: |
| 4760 | mutex_unlock(&mddev->open_mutex); |
| 4761 | return err; |
| 4762 | } |
| 4763 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4764 | /* mode: |
| 4765 | * 0 - completely stop and dis-assemble array |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4766 | * 2 - stop but do not disassemble array |
| 4767 | */ |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4768 | 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] | 4769 | { |
Dan Williams | 147e0b6 | 2010-08-06 18:01:59 -0700 | [diff] [blame] | 4770 | int err = 0, revalidate = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | struct gendisk *disk = mddev->gendisk; |
NeilBrown | c464729 | 2009-05-07 12:51:06 +1000 | [diff] [blame] | 4772 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 4774 | mutex_lock(&mddev->open_mutex); |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame^] | 4775 | if (atomic_read(&mddev->openers) > is_open || |
| 4776 | mddev->sysfs_active) { |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4777 | printk("md: %s still in use.\n",mdname(mddev)); |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 4778 | err = -EBUSY; |
| 4779 | } else if (mddev->pers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4780 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4781 | if (mddev->ro) |
| 4782 | set_disk_ro(disk, 0); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4783 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4784 | md_stop_writes(mddev); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4785 | md_stop(mddev); |
| 4786 | mddev->queue->merge_bvec_fn = NULL; |
| 4787 | mddev->queue->unplug_fn = NULL; |
| 4788 | mddev->queue->backing_dev_info.congested_fn = NULL; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4789 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4790 | /* tell userspace to handle 'inactive' */ |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4791 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4792 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4793 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 4794 | if (rdev->raid_disk >= 0) { |
| 4795 | char nm[20]; |
| 4796 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 4797 | sysfs_remove_link(&mddev->kobj, nm); |
| 4798 | } |
NeilBrown | c464729 | 2009-05-07 12:51:06 +1000 | [diff] [blame] | 4799 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4800 | set_capacity(disk, 0); |
Dan Williams | 147e0b6 | 2010-08-06 18:01:59 -0700 | [diff] [blame] | 4801 | revalidate = 1; |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4802 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4803 | if (mddev->ro) |
| 4804 | mddev->ro = 0; |
| 4805 | |
NeilBrown | 80ffb3c | 2009-08-18 10:35:26 +1000 | [diff] [blame] | 4806 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4807 | } |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 4808 | mutex_unlock(&mddev->open_mutex); |
Dan Williams | 147e0b6 | 2010-08-06 18:01:59 -0700 | [diff] [blame] | 4809 | if (revalidate) |
| 4810 | revalidate_disk(disk); |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 4811 | if (err) |
| 4812 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 | /* |
| 4814 | * Free resources if final stop |
| 4815 | */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4816 | if (mode == 0) { |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); |
| 4819 | |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4820 | bitmap_destroy(mddev); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4821 | if (mddev->bitmap_info.file) { |
| 4822 | restore_bitmap_write_access(mddev->bitmap_info.file); |
| 4823 | fput(mddev->bitmap_info.file); |
| 4824 | mddev->bitmap_info.file = NULL; |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4825 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4826 | mddev->bitmap_info.offset = 0; |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | export_array(mddev); |
| 4829 | |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4830 | md_clean(mddev); |
NeilBrown | 934d9c2 | 2008-10-28 17:01:23 +1100 | [diff] [blame] | 4831 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4832 | if (mddev->hold_active == UNTIL_STOP) |
| 4833 | mddev->hold_active = 0; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4834 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4835 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | err = 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 4837 | blk_integrity_unregister(disk); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4838 | md_new_event(mddev); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4839 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | return err; |
| 4841 | } |
| 4842 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 4843 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | static void autorun_array(mddev_t *mddev) |
| 4845 | { |
| 4846 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | int err; |
| 4848 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4849 | if (list_empty(&mddev->disks)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | |
| 4852 | printk(KERN_INFO "md: running: "); |
| 4853 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4854 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | char b[BDEVNAME_SIZE]; |
| 4856 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 4857 | } |
| 4858 | printk("\n"); |
| 4859 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4860 | err = do_md_run(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | if (err) { |
| 4862 | printk(KERN_WARNING "md: do_md_run() returned %d\n", err); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4863 | do_md_stop(mddev, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | /* |
| 4868 | * lets try to run arrays based on all disks that have arrived |
| 4869 | * until now. (those are in pending_raid_disks) |
| 4870 | * |
| 4871 | * the method: pick the first pending disk, collect all disks with |
| 4872 | * the same UUID, remove all from the pending list and put them into |
| 4873 | * the 'same_array' list. Then order this list based on superblock |
| 4874 | * update time (freshest comes first), kick out 'old' disks and |
| 4875 | * compare superblocks. If everything's fine then run it. |
| 4876 | * |
| 4877 | * If "unit" is allocated, then bump its reference count |
| 4878 | */ |
| 4879 | static void autorun_devices(int part) |
| 4880 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4881 | mdk_rdev_t *rdev0, *rdev, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | mddev_t *mddev; |
| 4883 | char b[BDEVNAME_SIZE]; |
| 4884 | |
| 4885 | printk(KERN_INFO "md: autorun ...\n"); |
| 4886 | while (!list_empty(&pending_raid_disks)) { |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4887 | int unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | dev_t dev; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 4889 | LIST_HEAD(candidates); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | rdev0 = list_entry(pending_raid_disks.next, |
| 4891 | mdk_rdev_t, same_set); |
| 4892 | |
| 4893 | printk(KERN_INFO "md: considering %s ...\n", |
| 4894 | bdevname(rdev0->bdev,b)); |
| 4895 | INIT_LIST_HEAD(&candidates); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4896 | rdev_for_each_list(rdev, tmp, &pending_raid_disks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | if (super_90_load(rdev, rdev0, 0) >= 0) { |
| 4898 | printk(KERN_INFO "md: adding %s ...\n", |
| 4899 | bdevname(rdev->bdev,b)); |
| 4900 | list_move(&rdev->same_set, &candidates); |
| 4901 | } |
| 4902 | /* |
| 4903 | * now we have a set of devices, with all of them having |
| 4904 | * mostly sane superblocks. It's time to allocate the |
| 4905 | * mddev. |
| 4906 | */ |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4907 | if (part) { |
| 4908 | dev = MKDEV(mdp_major, |
| 4909 | rdev0->preferred_minor << MdpMinorShift); |
| 4910 | unit = MINOR(dev) >> MdpMinorShift; |
| 4911 | } else { |
| 4912 | dev = MKDEV(MD_MAJOR, rdev0->preferred_minor); |
| 4913 | unit = MINOR(dev); |
| 4914 | } |
| 4915 | if (rdev0->preferred_minor != unit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | printk(KERN_INFO "md: unit number in %s is bad: %d\n", |
| 4917 | bdevname(rdev0->bdev, b), rdev0->preferred_minor); |
| 4918 | break; |
| 4919 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | |
| 4921 | md_probe(dev, NULL, NULL); |
| 4922 | mddev = mddev_find(dev); |
Neil Brown | 9bbbca3 | 2008-06-28 08:31:17 +1000 | [diff] [blame] | 4923 | if (!mddev || !mddev->gendisk) { |
| 4924 | if (mddev) |
| 4925 | mddev_put(mddev); |
| 4926 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | "md: cannot allocate memory for md drive.\n"); |
| 4928 | break; |
| 4929 | } |
| 4930 | if (mddev_lock(mddev)) |
| 4931 | printk(KERN_WARNING "md: %s locked, cannot run\n", |
| 4932 | mdname(mddev)); |
| 4933 | else if (mddev->raid_disks || mddev->major_version |
| 4934 | || !list_empty(&mddev->disks)) { |
| 4935 | printk(KERN_WARNING |
| 4936 | "md: %s already running, cannot run %s\n", |
| 4937 | mdname(mddev), bdevname(rdev0->bdev,b)); |
| 4938 | mddev_unlock(mddev); |
| 4939 | } else { |
| 4940 | printk(KERN_INFO "md: created %s\n", mdname(mddev)); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4941 | mddev->persistent = 1; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4942 | rdev_for_each_list(rdev, tmp, &candidates) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | list_del_init(&rdev->same_set); |
| 4944 | if (bind_rdev_to_array(rdev, mddev)) |
| 4945 | export_rdev(rdev); |
| 4946 | } |
| 4947 | autorun_array(mddev); |
| 4948 | mddev_unlock(mddev); |
| 4949 | } |
| 4950 | /* on success, candidates will be empty, on error |
| 4951 | * it won't... |
| 4952 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4953 | rdev_for_each_list(rdev, tmp, &candidates) { |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 4954 | list_del_init(&rdev->same_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4955 | export_rdev(rdev); |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 4956 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | mddev_put(mddev); |
| 4958 | } |
| 4959 | printk(KERN_INFO "md: ... autorun DONE.\n"); |
| 4960 | } |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 4961 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | static int get_version(void __user * arg) |
| 4964 | { |
| 4965 | mdu_version_t ver; |
| 4966 | |
| 4967 | ver.major = MD_MAJOR_VERSION; |
| 4968 | ver.minor = MD_MINOR_VERSION; |
| 4969 | ver.patchlevel = MD_PATCHLEVEL_VERSION; |
| 4970 | |
| 4971 | if (copy_to_user(arg, &ver, sizeof(ver))) |
| 4972 | return -EFAULT; |
| 4973 | |
| 4974 | return 0; |
| 4975 | } |
| 4976 | |
| 4977 | static int get_array_info(mddev_t * mddev, void __user * arg) |
| 4978 | { |
| 4979 | mdu_array_info_t info; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4980 | int nr,working,insync,failed,spare; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4983 | nr=working=insync=failed=spare=0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4984 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | nr++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4986 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4987 | failed++; |
| 4988 | else { |
| 4989 | working++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4990 | if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4991 | insync++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | else |
| 4993 | spare++; |
| 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | info.major_version = mddev->major_version; |
| 4998 | info.minor_version = mddev->minor_version; |
| 4999 | info.patch_version = MD_PATCHLEVEL_VERSION; |
| 5000 | info.ctime = mddev->ctime; |
| 5001 | info.level = mddev->level; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5002 | info.size = mddev->dev_sectors / 2; |
| 5003 | if (info.size != mddev->dev_sectors / 2) /* overflow */ |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 5004 | info.size = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | info.nr_disks = nr; |
| 5006 | info.raid_disks = mddev->raid_disks; |
| 5007 | info.md_minor = mddev->md_minor; |
| 5008 | info.not_persistent= !mddev->persistent; |
| 5009 | |
| 5010 | info.utime = mddev->utime; |
| 5011 | info.state = 0; |
| 5012 | if (mddev->in_sync) |
| 5013 | info.state = (1<<MD_SB_CLEAN); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5014 | if (mddev->bitmap && mddev->bitmap_info.offset) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5015 | info.state = (1<<MD_SB_BITMAP_PRESENT); |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5016 | info.active_disks = insync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | info.working_disks = working; |
| 5018 | info.failed_disks = failed; |
| 5019 | info.spare_disks = spare; |
| 5020 | |
| 5021 | info.layout = mddev->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5022 | info.chunk_size = mddev->chunk_sectors << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | |
| 5024 | if (copy_to_user(arg, &info, sizeof(info))) |
| 5025 | return -EFAULT; |
| 5026 | |
| 5027 | return 0; |
| 5028 | } |
| 5029 | |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 5030 | static int get_bitmap_file(mddev_t * mddev, void __user * arg) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5031 | { |
| 5032 | mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ |
| 5033 | char *ptr, *buf = NULL; |
| 5034 | int err = -ENOMEM; |
| 5035 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5036 | if (md_allow_write(mddev)) |
| 5037 | file = kmalloc(sizeof(*file), GFP_NOIO); |
| 5038 | else |
| 5039 | file = kmalloc(sizeof(*file), GFP_KERNEL); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 5040 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5041 | if (!file) |
| 5042 | goto out; |
| 5043 | |
| 5044 | /* bitmap disabled, zero the first byte and copy out */ |
| 5045 | if (!mddev->bitmap || !mddev->bitmap->file) { |
| 5046 | file->pathname[0] = '\0'; |
| 5047 | goto copy_out; |
| 5048 | } |
| 5049 | |
| 5050 | buf = kmalloc(sizeof(file->pathname), GFP_KERNEL); |
| 5051 | if (!buf) |
| 5052 | goto out; |
| 5053 | |
Christoph Hellwig | 6bcfd60 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 5054 | ptr = d_path(&mddev->bitmap->file->f_path, buf, sizeof(file->pathname)); |
| 5055 | if (IS_ERR(ptr)) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5056 | goto out; |
| 5057 | |
| 5058 | strcpy(file->pathname, ptr); |
| 5059 | |
| 5060 | copy_out: |
| 5061 | err = 0; |
| 5062 | if (copy_to_user(arg, file, sizeof(*file))) |
| 5063 | err = -EFAULT; |
| 5064 | out: |
| 5065 | kfree(buf); |
| 5066 | kfree(file); |
| 5067 | return err; |
| 5068 | } |
| 5069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | static int get_disk_info(mddev_t * mddev, void __user * arg) |
| 5071 | { |
| 5072 | mdu_disk_info_t info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | mdk_rdev_t *rdev; |
| 5074 | |
| 5075 | if (copy_from_user(&info, arg, sizeof(info))) |
| 5076 | return -EFAULT; |
| 5077 | |
Andre Noll | 26ef379 | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 5078 | rdev = find_rdev_nr(mddev, info.number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | if (rdev) { |
| 5080 | info.major = MAJOR(rdev->bdev->bd_dev); |
| 5081 | info.minor = MINOR(rdev->bdev->bd_dev); |
| 5082 | info.raid_disk = rdev->raid_disk; |
| 5083 | info.state = 0; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5084 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | info.state |= (1<<MD_DISK_FAULTY); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5086 | else if (test_bit(In_sync, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5087 | info.state |= (1<<MD_DISK_ACTIVE); |
| 5088 | info.state |= (1<<MD_DISK_SYNC); |
| 5089 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5090 | if (test_bit(WriteMostly, &rdev->flags)) |
| 5091 | info.state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | } else { |
| 5093 | info.major = info.minor = 0; |
| 5094 | info.raid_disk = -1; |
| 5095 | info.state = (1<<MD_DISK_REMOVED); |
| 5096 | } |
| 5097 | |
| 5098 | if (copy_to_user(arg, &info, sizeof(info))) |
| 5099 | return -EFAULT; |
| 5100 | |
| 5101 | return 0; |
| 5102 | } |
| 5103 | |
| 5104 | static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) |
| 5105 | { |
| 5106 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 5107 | mdk_rdev_t *rdev; |
| 5108 | dev_t dev = MKDEV(info->major,info->minor); |
| 5109 | |
| 5110 | if (info->major != MAJOR(dev) || info->minor != MINOR(dev)) |
| 5111 | return -EOVERFLOW; |
| 5112 | |
| 5113 | if (!mddev->raid_disks) { |
| 5114 | int err; |
| 5115 | /* expecting a device which has a superblock */ |
| 5116 | rdev = md_import_device(dev, mddev->major_version, mddev->minor_version); |
| 5117 | if (IS_ERR(rdev)) { |
| 5118 | printk(KERN_WARNING |
| 5119 | "md: md_import_device returned %ld\n", |
| 5120 | PTR_ERR(rdev)); |
| 5121 | return PTR_ERR(rdev); |
| 5122 | } |
| 5123 | if (!list_empty(&mddev->disks)) { |
| 5124 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 5125 | mdk_rdev_t, same_set); |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5126 | err = super_types[mddev->major_version] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | .load_super(rdev, rdev0, mddev->minor_version); |
| 5128 | if (err < 0) { |
| 5129 | printk(KERN_WARNING |
| 5130 | "md: %s has different UUID to %s\n", |
| 5131 | bdevname(rdev->bdev,b), |
| 5132 | bdevname(rdev0->bdev,b2)); |
| 5133 | export_rdev(rdev); |
| 5134 | return -EINVAL; |
| 5135 | } |
| 5136 | } |
| 5137 | err = bind_rdev_to_array(rdev, mddev); |
| 5138 | if (err) |
| 5139 | export_rdev(rdev); |
| 5140 | return err; |
| 5141 | } |
| 5142 | |
| 5143 | /* |
| 5144 | * add_new_disk can be used once the array is assembled |
| 5145 | * to add "hot spares". They must already have a superblock |
| 5146 | * written |
| 5147 | */ |
| 5148 | if (mddev->pers) { |
| 5149 | int err; |
| 5150 | if (!mddev->pers->hot_add_disk) { |
| 5151 | printk(KERN_WARNING |
| 5152 | "%s: personality does not support diskops!\n", |
| 5153 | mdname(mddev)); |
| 5154 | return -EINVAL; |
| 5155 | } |
NeilBrown | 7b1e35f | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 5156 | if (mddev->persistent) |
| 5157 | rdev = md_import_device(dev, mddev->major_version, |
| 5158 | mddev->minor_version); |
| 5159 | else |
| 5160 | rdev = md_import_device(dev, -1, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | if (IS_ERR(rdev)) { |
| 5162 | printk(KERN_WARNING |
| 5163 | "md: md_import_device returned %ld\n", |
| 5164 | PTR_ERR(rdev)); |
| 5165 | return PTR_ERR(rdev); |
| 5166 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 5167 | /* set save_raid_disk if appropriate */ |
| 5168 | if (!mddev->persistent) { |
| 5169 | if (info->state & (1<<MD_DISK_SYNC) && |
| 5170 | info->raid_disk < mddev->raid_disks) |
| 5171 | rdev->raid_disk = info->raid_disk; |
| 5172 | else |
| 5173 | rdev->raid_disk = -1; |
| 5174 | } else |
| 5175 | super_types[mddev->major_version]. |
| 5176 | validate_super(mddev, rdev); |
| 5177 | rdev->saved_raid_disk = rdev->raid_disk; |
| 5178 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5179 | clear_bit(In_sync, &rdev->flags); /* just to be sure */ |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5180 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 5181 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 575a80f | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5182 | else |
| 5183 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 | rdev->raid_disk = -1; |
| 5186 | err = bind_rdev_to_array(rdev, mddev); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 5187 | if (!err && !mddev->pers->hot_remove_disk) { |
| 5188 | /* If there is hot_add_disk but no hot_remove_disk |
| 5189 | * then added disks for geometry changes, |
| 5190 | * and should be added immediately. |
| 5191 | */ |
| 5192 | super_types[mddev->major_version]. |
| 5193 | validate_super(mddev, rdev); |
| 5194 | err = mddev->pers->hot_add_disk(mddev, rdev); |
| 5195 | if (err) |
| 5196 | unbind_rdev_from_array(rdev); |
| 5197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | if (err) |
| 5199 | export_rdev(rdev); |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 5200 | else |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 5201 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 5202 | |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 5203 | md_update_sb(mddev, 1); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 5204 | if (mddev->degraded) |
| 5205 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 5206 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 5207 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | return err; |
| 5209 | } |
| 5210 | |
| 5211 | /* otherwise, add_new_disk is only allowed |
| 5212 | * for major_version==0 superblocks |
| 5213 | */ |
| 5214 | if (mddev->major_version != 0) { |
| 5215 | printk(KERN_WARNING "%s: ADD_NEW_DISK not supported\n", |
| 5216 | mdname(mddev)); |
| 5217 | return -EINVAL; |
| 5218 | } |
| 5219 | |
| 5220 | if (!(info->state & (1<<MD_DISK_FAULTY))) { |
| 5221 | int err; |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5222 | rdev = md_import_device(dev, -1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5223 | if (IS_ERR(rdev)) { |
| 5224 | printk(KERN_WARNING |
| 5225 | "md: error, md_import_device() returned %ld\n", |
| 5226 | PTR_ERR(rdev)); |
| 5227 | return PTR_ERR(rdev); |
| 5228 | } |
| 5229 | rdev->desc_nr = info->number; |
| 5230 | if (info->raid_disk < mddev->raid_disks) |
| 5231 | rdev->raid_disk = info->raid_disk; |
| 5232 | else |
| 5233 | rdev->raid_disk = -1; |
| 5234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5235 | if (rdev->raid_disk < mddev->raid_disks) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5236 | if (info->state & (1<<MD_DISK_SYNC)) |
| 5237 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5238 | |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5239 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 5240 | set_bit(WriteMostly, &rdev->flags); |
| 5241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | if (!mddev->persistent) { |
| 5243 | printk(KERN_INFO "md: nonpersistent superblock ...\n"); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5244 | rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5245 | } else |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5246 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 5247 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 5249 | err = bind_rdev_to_array(rdev, mddev); |
| 5250 | if (err) { |
| 5251 | export_rdev(rdev); |
| 5252 | return err; |
| 5253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | } |
| 5255 | |
| 5256 | return 0; |
| 5257 | } |
| 5258 | |
| 5259 | static int hot_remove_disk(mddev_t * mddev, dev_t dev) |
| 5260 | { |
| 5261 | char b[BDEVNAME_SIZE]; |
| 5262 | mdk_rdev_t *rdev; |
| 5263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5264 | rdev = find_rdev(mddev, dev); |
| 5265 | if (!rdev) |
| 5266 | return -ENXIO; |
| 5267 | |
| 5268 | if (rdev->raid_disk >= 0) |
| 5269 | goto busy; |
| 5270 | |
| 5271 | kick_rdev_from_array(rdev); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5272 | md_update_sb(mddev, 1); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5273 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5274 | |
| 5275 | return 0; |
| 5276 | busy: |
Nick Andrew | fdefa4d | 2008-04-21 22:42:58 +0000 | [diff] [blame] | 5277 | printk(KERN_WARNING "md: cannot remove active disk %s from %s ...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5278 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 5279 | return -EBUSY; |
| 5280 | } |
| 5281 | |
| 5282 | static int hot_add_disk(mddev_t * mddev, dev_t dev) |
| 5283 | { |
| 5284 | char b[BDEVNAME_SIZE]; |
| 5285 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5286 | mdk_rdev_t *rdev; |
| 5287 | |
| 5288 | if (!mddev->pers) |
| 5289 | return -ENODEV; |
| 5290 | |
| 5291 | if (mddev->major_version != 0) { |
| 5292 | printk(KERN_WARNING "%s: HOT_ADD may only be used with" |
| 5293 | " version-0 superblocks.\n", |
| 5294 | mdname(mddev)); |
| 5295 | return -EINVAL; |
| 5296 | } |
| 5297 | if (!mddev->pers->hot_add_disk) { |
| 5298 | printk(KERN_WARNING |
| 5299 | "%s: personality does not support diskops!\n", |
| 5300 | mdname(mddev)); |
| 5301 | return -EINVAL; |
| 5302 | } |
| 5303 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5304 | rdev = md_import_device(dev, -1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | if (IS_ERR(rdev)) { |
| 5306 | printk(KERN_WARNING |
| 5307 | "md: error, md_import_device() returned %ld\n", |
| 5308 | PTR_ERR(rdev)); |
| 5309 | return -EINVAL; |
| 5310 | } |
| 5311 | |
| 5312 | if (mddev->persistent) |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5313 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5314 | else |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5315 | rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5316 | |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 5317 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5319 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | printk(KERN_WARNING |
| 5321 | "md: can not hot-add faulty %s disk to %s!\n", |
| 5322 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 5323 | err = -EINVAL; |
| 5324 | goto abort_export; |
| 5325 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5326 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | rdev->desc_nr = -1; |
NeilBrown | 5842730 | 2006-10-06 00:44:04 -0700 | [diff] [blame] | 5328 | rdev->saved_raid_disk = -1; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 5329 | err = bind_rdev_to_array(rdev, mddev); |
| 5330 | if (err) |
| 5331 | goto abort_export; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5332 | |
| 5333 | /* |
| 5334 | * The rest should better be atomic, we can have disk failures |
| 5335 | * noticed in interrupt contexts ... |
| 5336 | */ |
| 5337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5338 | rdev->raid_disk = -1; |
| 5339 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5340 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5341 | |
| 5342 | /* |
| 5343 | * Kick recovery, maybe this spare has to be added to the |
| 5344 | * array immediately. |
| 5345 | */ |
| 5346 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5347 | md_wakeup_thread(mddev->thread); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5348 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | return 0; |
| 5350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5351 | abort_export: |
| 5352 | export_rdev(rdev); |
| 5353 | return err; |
| 5354 | } |
| 5355 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5356 | static int set_bitmap_file(mddev_t *mddev, int fd) |
| 5357 | { |
| 5358 | int err; |
| 5359 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5360 | if (mddev->pers) { |
| 5361 | if (!mddev->pers->quiesce) |
| 5362 | return -EBUSY; |
| 5363 | if (mddev->recovery || mddev->sync_thread) |
| 5364 | return -EBUSY; |
| 5365 | /* we should be able to change the bitmap.. */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5366 | } |
| 5367 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5368 | |
| 5369 | if (fd >= 0) { |
| 5370 | if (mddev->bitmap) |
| 5371 | return -EEXIST; /* cannot add when bitmap is present */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5372 | mddev->bitmap_info.file = fget(fd); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5373 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5374 | if (mddev->bitmap_info.file == NULL) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5375 | printk(KERN_ERR "%s: error: failed to get bitmap file\n", |
| 5376 | mdname(mddev)); |
| 5377 | return -EBADF; |
| 5378 | } |
| 5379 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5380 | err = deny_bitmap_write_access(mddev->bitmap_info.file); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5381 | if (err) { |
| 5382 | printk(KERN_ERR "%s: error: bitmap file is already in use\n", |
| 5383 | mdname(mddev)); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5384 | fput(mddev->bitmap_info.file); |
| 5385 | mddev->bitmap_info.file = NULL; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5386 | return err; |
| 5387 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5388 | mddev->bitmap_info.offset = 0; /* file overrides offset */ |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5389 | } else if (mddev->bitmap == NULL) |
| 5390 | return -ENOENT; /* cannot remove what isn't there */ |
| 5391 | err = 0; |
| 5392 | if (mddev->pers) { |
| 5393 | mddev->pers->quiesce(mddev, 1); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 5394 | if (fd >= 0) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5395 | err = bitmap_create(mddev); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 5396 | if (!err) |
| 5397 | err = bitmap_load(mddev); |
| 5398 | } |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5399 | if (fd < 0 || err) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5400 | bitmap_destroy(mddev); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5401 | fd = -1; /* make sure to put the file */ |
| 5402 | } |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5403 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5404 | } |
| 5405 | if (fd < 0) { |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5406 | if (mddev->bitmap_info.file) { |
| 5407 | restore_bitmap_write_access(mddev->bitmap_info.file); |
| 5408 | fput(mddev->bitmap_info.file); |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 5409 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5410 | mddev->bitmap_info.file = NULL; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5411 | } |
| 5412 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5413 | return err; |
| 5414 | } |
| 5415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | /* |
| 5417 | * set_array_info is used two different ways |
| 5418 | * The original usage is when creating a new array. |
| 5419 | * In this usage, raid_disks is > 0 and it together with |
| 5420 | * level, size, not_persistent,layout,chunksize determine the |
| 5421 | * shape of the array. |
| 5422 | * This will always create an array with a type-0.90.0 superblock. |
| 5423 | * The newer usage is when assembling an array. |
| 5424 | * In this case raid_disks will be 0, and the major_version field is |
| 5425 | * use to determine which style super-blocks are to be found on the devices. |
| 5426 | * The minor and patch _version numbers are also kept incase the |
| 5427 | * super_block handler wishes to interpret them. |
| 5428 | */ |
| 5429 | static int set_array_info(mddev_t * mddev, mdu_array_info_t *info) |
| 5430 | { |
| 5431 | |
| 5432 | if (info->raid_disks == 0) { |
| 5433 | /* just setting version number for superblock loading */ |
| 5434 | if (info->major_version < 0 || |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 5435 | info->major_version >= ARRAY_SIZE(super_types) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5436 | super_types[info->major_version].name == NULL) { |
| 5437 | /* maybe try to auto-load a module? */ |
| 5438 | printk(KERN_INFO |
| 5439 | "md: superblock version %d not known\n", |
| 5440 | info->major_version); |
| 5441 | return -EINVAL; |
| 5442 | } |
| 5443 | mddev->major_version = info->major_version; |
| 5444 | mddev->minor_version = info->minor_version; |
| 5445 | mddev->patch_version = info->patch_version; |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 5446 | mddev->persistent = !info->not_persistent; |
NeilBrown | cbd1998 | 2009-12-30 12:08:49 +1100 | [diff] [blame] | 5447 | /* ensure mddev_put doesn't delete this now that there |
| 5448 | * is some minimal configuration. |
| 5449 | */ |
| 5450 | mddev->ctime = get_seconds(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5451 | return 0; |
| 5452 | } |
| 5453 | mddev->major_version = MD_MAJOR_VERSION; |
| 5454 | mddev->minor_version = MD_MINOR_VERSION; |
| 5455 | mddev->patch_version = MD_PATCHLEVEL_VERSION; |
| 5456 | mddev->ctime = get_seconds(); |
| 5457 | |
| 5458 | mddev->level = info->level; |
NeilBrown | 17115e0 | 2006-01-16 22:14:57 -0800 | [diff] [blame] | 5459 | mddev->clevel[0] = 0; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5460 | mddev->dev_sectors = 2 * (sector_t)info->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 | mddev->raid_disks = info->raid_disks; |
| 5462 | /* don't set md_minor, it is determined by which /dev/md* was |
| 5463 | * openned |
| 5464 | */ |
| 5465 | if (info->state & (1<<MD_SB_CLEAN)) |
| 5466 | mddev->recovery_cp = MaxSector; |
| 5467 | else |
| 5468 | mddev->recovery_cp = 0; |
| 5469 | mddev->persistent = ! info->not_persistent; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 5470 | mddev->external = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | |
| 5472 | mddev->layout = info->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5473 | mddev->chunk_sectors = info->chunk_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | |
| 5475 | mddev->max_disks = MD_SB_DISKS; |
| 5476 | |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 5477 | if (mddev->persistent) |
| 5478 | mddev->flags = 0; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5479 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5481 | mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9; |
| 5482 | mddev->bitmap_info.offset = 0; |
NeilBrown | b2a2703 | 2005-11-28 13:44:12 -0800 | [diff] [blame] | 5483 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5484 | mddev->reshape_position = MaxSector; |
| 5485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5486 | /* |
| 5487 | * Generate a 128 bit UUID |
| 5488 | */ |
| 5489 | get_random_bytes(mddev->uuid, 16); |
| 5490 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5491 | mddev->new_level = mddev->level; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5492 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5493 | mddev->new_layout = mddev->layout; |
| 5494 | mddev->delta_disks = 0; |
| 5495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | return 0; |
| 5497 | } |
| 5498 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5499 | void md_set_array_sectors(mddev_t *mddev, sector_t array_sectors) |
| 5500 | { |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5501 | WARN(!mddev_is_locked(mddev), "%s: unlocked mddev!\n", __func__); |
| 5502 | |
| 5503 | if (mddev->external_size) |
| 5504 | return; |
| 5505 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5506 | mddev->array_sectors = array_sectors; |
| 5507 | } |
| 5508 | EXPORT_SYMBOL(md_set_array_sectors); |
| 5509 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5510 | static int update_size(mddev_t *mddev, sector_t num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5511 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5512 | mdk_rdev_t *rdev; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5513 | int rv; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5514 | int fit = (num_sectors == 0); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5515 | |
| 5516 | if (mddev->pers->resize == NULL) |
| 5517 | return -EINVAL; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5518 | /* The "num_sectors" is the number of sectors of each device that |
| 5519 | * is used. This can only make sense for arrays with redundancy. |
| 5520 | * linear and raid0 always use whatever space is available. We can only |
| 5521 | * consider changing this number if no resync or reconstruction is |
| 5522 | * 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] | 5523 | * 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] | 5524 | * of each device. If num_sectors is zero, we find the largest size |
| 5525 | * that fits. |
| 5526 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5527 | */ |
| 5528 | if (mddev->sync_thread) |
| 5529 | return -EBUSY; |
NeilBrown | dba034e | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 5530 | if (mddev->bitmap) |
| 5531 | /* Sorry, cannot grow a bitmap yet, just remove it, |
| 5532 | * grow, and re-add. |
| 5533 | */ |
| 5534 | return -EBUSY; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5535 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5536 | sector_t avail = rdev->sectors; |
NeilBrown | 01ab566 | 2006-10-28 10:38:30 -0700 | [diff] [blame] | 5537 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5538 | if (fit && (num_sectors == 0 || num_sectors > avail)) |
| 5539 | num_sectors = avail; |
| 5540 | if (avail < num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5541 | return -ENOSPC; |
| 5542 | } |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5543 | rv = mddev->pers->resize(mddev, num_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5544 | if (!rv) |
| 5545 | revalidate_disk(mddev->gendisk); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5546 | return rv; |
| 5547 | } |
| 5548 | |
NeilBrown | da943b9 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5549 | static int update_raid_disks(mddev_t *mddev, int raid_disks) |
| 5550 | { |
| 5551 | int rv; |
| 5552 | /* change the number of raid disks */ |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5553 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | da943b9 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5554 | return -EINVAL; |
| 5555 | if (raid_disks <= 0 || |
NeilBrown | 233fca3 | 2010-04-14 17:02:09 +1000 | [diff] [blame] | 5556 | (mddev->max_disks && raid_disks >= mddev->max_disks)) |
NeilBrown | da943b9 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5557 | return -EINVAL; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5558 | if (mddev->sync_thread || mddev->reshape_position != MaxSector) |
NeilBrown | da943b9 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5559 | return -EBUSY; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5560 | mddev->delta_disks = raid_disks - mddev->raid_disks; |
| 5561 | |
| 5562 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | da943b9 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5563 | return rv; |
| 5564 | } |
| 5565 | |
| 5566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | /* |
| 5568 | * update_array_info is used to change the configuration of an |
| 5569 | * on-line array. |
| 5570 | * The version, ctime,level,size,raid_disks,not_persistent, layout,chunk_size |
| 5571 | * fields in the info are checked against the array. |
| 5572 | * Any differences that cannot be handled will cause an error. |
| 5573 | * Normally, only one change can be managed at a time. |
| 5574 | */ |
| 5575 | static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) |
| 5576 | { |
| 5577 | int rv = 0; |
| 5578 | int cnt = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5579 | int state = 0; |
| 5580 | |
| 5581 | /* calculate expected state,ignoring low bits */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5582 | if (mddev->bitmap && mddev->bitmap_info.offset) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5583 | state |= (1 << MD_SB_BITMAP_PRESENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | |
| 5585 | if (mddev->major_version != info->major_version || |
| 5586 | mddev->minor_version != info->minor_version || |
| 5587 | /* mddev->patch_version != info->patch_version || */ |
| 5588 | mddev->ctime != info->ctime || |
| 5589 | mddev->level != info->level || |
| 5590 | /* mddev->layout != info->layout || */ |
| 5591 | !mddev->persistent != info->not_persistent|| |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5592 | mddev->chunk_sectors != info->chunk_size >> 9 || |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5593 | /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */ |
| 5594 | ((state^info->state) & 0xfffffe00) |
| 5595 | ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5596 | return -EINVAL; |
| 5597 | /* Check there is only one change */ |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5598 | if (info->size >= 0 && mddev->dev_sectors / 2 != info->size) |
| 5599 | cnt++; |
| 5600 | if (mddev->raid_disks != info->raid_disks) |
| 5601 | cnt++; |
| 5602 | if (mddev->layout != info->layout) |
| 5603 | cnt++; |
| 5604 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) |
| 5605 | cnt++; |
| 5606 | if (cnt == 0) |
| 5607 | return 0; |
| 5608 | if (cnt > 1) |
| 5609 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | |
| 5611 | if (mddev->layout != info->layout) { |
| 5612 | /* Change layout |
| 5613 | * we don't need to do anything at the md level, the |
| 5614 | * personality will take care of it all. |
| 5615 | */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5616 | if (mddev->pers->check_reshape == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5618 | else { |
| 5619 | mddev->new_layout = info->layout; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5620 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5621 | if (rv) |
| 5622 | mddev->new_layout = mddev->layout; |
| 5623 | return rv; |
| 5624 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5625 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5626 | if (info->size >= 0 && mddev->dev_sectors / 2 != info->size) |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5627 | rv = update_size(mddev, (sector_t)info->size * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | |
NeilBrown | da943b9 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5629 | if (mddev->raid_disks != info->raid_disks) |
| 5630 | rv = update_raid_disks(mddev, info->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5631 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5632 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) { |
| 5633 | if (mddev->pers->quiesce == NULL) |
| 5634 | return -EINVAL; |
| 5635 | if (mddev->recovery || mddev->sync_thread) |
| 5636 | return -EBUSY; |
| 5637 | if (info->state & (1<<MD_SB_BITMAP_PRESENT)) { |
| 5638 | /* add the bitmap */ |
| 5639 | if (mddev->bitmap) |
| 5640 | return -EEXIST; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5641 | if (mddev->bitmap_info.default_offset == 0) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5642 | return -EINVAL; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5643 | mddev->bitmap_info.offset = |
| 5644 | mddev->bitmap_info.default_offset; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5645 | mddev->pers->quiesce(mddev, 1); |
| 5646 | rv = bitmap_create(mddev); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 5647 | if (!rv) |
| 5648 | rv = bitmap_load(mddev); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5649 | if (rv) |
| 5650 | bitmap_destroy(mddev); |
| 5651 | mddev->pers->quiesce(mddev, 0); |
| 5652 | } else { |
| 5653 | /* remove the bitmap */ |
| 5654 | if (!mddev->bitmap) |
| 5655 | return -ENOENT; |
| 5656 | if (mddev->bitmap->file) |
| 5657 | return -EINVAL; |
| 5658 | mddev->pers->quiesce(mddev, 1); |
| 5659 | bitmap_destroy(mddev); |
| 5660 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5661 | mddev->bitmap_info.offset = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5662 | } |
| 5663 | } |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5664 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5665 | return rv; |
| 5666 | } |
| 5667 | |
| 5668 | static int set_disk_faulty(mddev_t *mddev, dev_t dev) |
| 5669 | { |
| 5670 | mdk_rdev_t *rdev; |
| 5671 | |
| 5672 | if (mddev->pers == NULL) |
| 5673 | return -ENODEV; |
| 5674 | |
| 5675 | rdev = find_rdev(mddev, dev); |
| 5676 | if (!rdev) |
| 5677 | return -ENODEV; |
| 5678 | |
| 5679 | md_error(mddev, rdev); |
| 5680 | return 0; |
| 5681 | } |
| 5682 | |
Andre Noll | 2f9618c | 2008-04-25 18:57:58 +0200 | [diff] [blame] | 5683 | /* |
| 5684 | * We have a problem here : there is no easy way to give a CHS |
| 5685 | * virtual geometry. We currently pretend that we have a 2 heads |
| 5686 | * 4 sectors (with a BIG number of cylinders...). This drives |
| 5687 | * dosfs just mad... ;-) |
| 5688 | */ |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5689 | static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 5690 | { |
| 5691 | mddev_t *mddev = bdev->bd_disk->private_data; |
| 5692 | |
| 5693 | geo->heads = 2; |
| 5694 | geo->sectors = 4; |
NeilBrown | 49ce6ce | 2010-03-29 10:51:42 +1100 | [diff] [blame] | 5695 | geo->cylinders = mddev->array_sectors / 8; |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5696 | return 0; |
| 5697 | } |
| 5698 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5699 | static int md_ioctl(struct block_device *bdev, fmode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | unsigned int cmd, unsigned long arg) |
| 5701 | { |
| 5702 | int err = 0; |
| 5703 | void __user *argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | mddev_t *mddev = NULL; |
Dan Williams | e221835 | 2010-05-12 08:25:37 +1000 | [diff] [blame] | 5705 | int ro; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5706 | |
| 5707 | if (!capable(CAP_SYS_ADMIN)) |
| 5708 | return -EACCES; |
| 5709 | |
| 5710 | /* |
| 5711 | * Commands dealing with the RAID driver but not any |
| 5712 | * particular array: |
| 5713 | */ |
| 5714 | switch (cmd) |
| 5715 | { |
| 5716 | case RAID_VERSION: |
| 5717 | err = get_version(argp); |
| 5718 | goto done; |
| 5719 | |
| 5720 | case PRINT_RAID_DEBUG: |
| 5721 | err = 0; |
| 5722 | md_print_devices(); |
| 5723 | goto done; |
| 5724 | |
| 5725 | #ifndef MODULE |
| 5726 | case RAID_AUTORUN: |
| 5727 | err = 0; |
| 5728 | autostart_arrays(arg); |
| 5729 | goto done; |
| 5730 | #endif |
| 5731 | default:; |
| 5732 | } |
| 5733 | |
| 5734 | /* |
| 5735 | * Commands creating/starting a new array: |
| 5736 | */ |
| 5737 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5738 | mddev = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5739 | |
| 5740 | if (!mddev) { |
| 5741 | BUG(); |
| 5742 | goto abort; |
| 5743 | } |
| 5744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | err = mddev_lock(mddev); |
| 5746 | if (err) { |
| 5747 | printk(KERN_INFO |
| 5748 | "md: ioctl lock interrupted, reason %d, cmd %d\n", |
| 5749 | err, cmd); |
| 5750 | goto abort; |
| 5751 | } |
| 5752 | |
| 5753 | switch (cmd) |
| 5754 | { |
| 5755 | case SET_ARRAY_INFO: |
| 5756 | { |
| 5757 | mdu_array_info_t info; |
| 5758 | if (!arg) |
| 5759 | memset(&info, 0, sizeof(info)); |
| 5760 | else if (copy_from_user(&info, argp, sizeof(info))) { |
| 5761 | err = -EFAULT; |
| 5762 | goto abort_unlock; |
| 5763 | } |
| 5764 | if (mddev->pers) { |
| 5765 | err = update_array_info(mddev, &info); |
| 5766 | if (err) { |
| 5767 | printk(KERN_WARNING "md: couldn't update" |
| 5768 | " array info. %d\n", err); |
| 5769 | goto abort_unlock; |
| 5770 | } |
| 5771 | goto done_unlock; |
| 5772 | } |
| 5773 | if (!list_empty(&mddev->disks)) { |
| 5774 | printk(KERN_WARNING |
| 5775 | "md: array %s already has disks!\n", |
| 5776 | mdname(mddev)); |
| 5777 | err = -EBUSY; |
| 5778 | goto abort_unlock; |
| 5779 | } |
| 5780 | if (mddev->raid_disks) { |
| 5781 | printk(KERN_WARNING |
| 5782 | "md: array %s already initialised!\n", |
| 5783 | mdname(mddev)); |
| 5784 | err = -EBUSY; |
| 5785 | goto abort_unlock; |
| 5786 | } |
| 5787 | err = set_array_info(mddev, &info); |
| 5788 | if (err) { |
| 5789 | printk(KERN_WARNING "md: couldn't set" |
| 5790 | " array info. %d\n", err); |
| 5791 | goto abort_unlock; |
| 5792 | } |
| 5793 | } |
| 5794 | goto done_unlock; |
| 5795 | |
| 5796 | default:; |
| 5797 | } |
| 5798 | |
| 5799 | /* |
| 5800 | * Commands querying/configuring an existing array: |
| 5801 | */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5802 | /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY, |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 5803 | * RUN_ARRAY, and GET_ and SET_BITMAP_FILE are allowed */ |
NeilBrown | a17184a | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 5804 | if ((!mddev->raid_disks && !mddev->external) |
| 5805 | && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY |
| 5806 | && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE |
| 5807 | && cmd != GET_BITMAP_FILE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | err = -ENODEV; |
| 5809 | goto abort_unlock; |
| 5810 | } |
| 5811 | |
| 5812 | /* |
| 5813 | * Commands even a read-only array can execute: |
| 5814 | */ |
| 5815 | switch (cmd) |
| 5816 | { |
| 5817 | case GET_ARRAY_INFO: |
| 5818 | err = get_array_info(mddev, argp); |
| 5819 | goto done_unlock; |
| 5820 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5821 | case GET_BITMAP_FILE: |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 5822 | err = get_bitmap_file(mddev, argp); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5823 | goto done_unlock; |
| 5824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | case GET_DISK_INFO: |
| 5826 | err = get_disk_info(mddev, argp); |
| 5827 | goto done_unlock; |
| 5828 | |
| 5829 | case RESTART_ARRAY_RW: |
| 5830 | err = restart_array(mddev); |
| 5831 | goto done_unlock; |
| 5832 | |
| 5833 | case STOP_ARRAY: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5834 | err = do_md_stop(mddev, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5835 | goto done_unlock; |
| 5836 | |
| 5837 | case STOP_ARRAY_RO: |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 5838 | err = md_set_readonly(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5839 | goto done_unlock; |
| 5840 | |
Dan Williams | e221835 | 2010-05-12 08:25:37 +1000 | [diff] [blame] | 5841 | case BLKROSET: |
| 5842 | if (get_user(ro, (int __user *)(arg))) { |
| 5843 | err = -EFAULT; |
| 5844 | goto done_unlock; |
| 5845 | } |
| 5846 | err = -EINVAL; |
| 5847 | |
| 5848 | /* if the bdev is going readonly the value of mddev->ro |
| 5849 | * does not matter, no writes are coming |
| 5850 | */ |
| 5851 | if (ro) |
| 5852 | goto done_unlock; |
| 5853 | |
| 5854 | /* are we are already prepared for writes? */ |
| 5855 | if (mddev->ro != 1) |
| 5856 | goto done_unlock; |
| 5857 | |
| 5858 | /* transitioning to readauto need only happen for |
| 5859 | * arrays that call md_write_start |
| 5860 | */ |
| 5861 | if (mddev->pers) { |
| 5862 | err = restart_array(mddev); |
| 5863 | if (err == 0) { |
| 5864 | mddev->ro = 2; |
| 5865 | set_disk_ro(mddev->gendisk, 0); |
| 5866 | } |
| 5867 | } |
| 5868 | goto done_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | /* |
| 5872 | * The remaining ioctls are changing the state of the |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5873 | * superblock, so we do not allow them on read-only arrays. |
| 5874 | * However non-MD ioctls (e.g. get-size) will still come through |
| 5875 | * here and hit the 'default' below, so only disallow |
| 5876 | * 'md' ioctls, and switch to rw mode if started auto-readonly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5877 | */ |
Andre Noll | bb57fc6 | 2008-04-25 19:06:35 +0200 | [diff] [blame] | 5878 | if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5879 | if (mddev->ro == 2) { |
| 5880 | mddev->ro = 0; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 5881 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 5882 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5883 | md_wakeup_thread(mddev->thread); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5884 | } else { |
| 5885 | err = -EROFS; |
| 5886 | goto abort_unlock; |
| 5887 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5888 | } |
| 5889 | |
| 5890 | switch (cmd) |
| 5891 | { |
| 5892 | case ADD_NEW_DISK: |
| 5893 | { |
| 5894 | mdu_disk_info_t info; |
| 5895 | if (copy_from_user(&info, argp, sizeof(info))) |
| 5896 | err = -EFAULT; |
| 5897 | else |
| 5898 | err = add_new_disk(mddev, &info); |
| 5899 | goto done_unlock; |
| 5900 | } |
| 5901 | |
| 5902 | case HOT_REMOVE_DISK: |
| 5903 | err = hot_remove_disk(mddev, new_decode_dev(arg)); |
| 5904 | goto done_unlock; |
| 5905 | |
| 5906 | case HOT_ADD_DISK: |
| 5907 | err = hot_add_disk(mddev, new_decode_dev(arg)); |
| 5908 | goto done_unlock; |
| 5909 | |
| 5910 | case SET_DISK_FAULTY: |
| 5911 | err = set_disk_faulty(mddev, new_decode_dev(arg)); |
| 5912 | goto done_unlock; |
| 5913 | |
| 5914 | case RUN_ARRAY: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5915 | err = do_md_run(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5916 | goto done_unlock; |
| 5917 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5918 | case SET_BITMAP_FILE: |
| 5919 | err = set_bitmap_file(mddev, (int)arg); |
| 5920 | goto done_unlock; |
| 5921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5923 | err = -EINVAL; |
| 5924 | goto abort_unlock; |
| 5925 | } |
| 5926 | |
| 5927 | done_unlock: |
| 5928 | abort_unlock: |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5929 | if (mddev->hold_active == UNTIL_IOCTL && |
| 5930 | err != -EINVAL) |
| 5931 | mddev->hold_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5932 | mddev_unlock(mddev); |
| 5933 | |
| 5934 | return err; |
| 5935 | done: |
| 5936 | if (err) |
| 5937 | MD_BUG(); |
| 5938 | abort: |
| 5939 | return err; |
| 5940 | } |
Arnd Bergmann | aa98aa3 | 2009-12-14 12:50:05 +1100 | [diff] [blame] | 5941 | #ifdef CONFIG_COMPAT |
| 5942 | static int md_compat_ioctl(struct block_device *bdev, fmode_t mode, |
| 5943 | unsigned int cmd, unsigned long arg) |
| 5944 | { |
| 5945 | switch (cmd) { |
| 5946 | case HOT_REMOVE_DISK: |
| 5947 | case HOT_ADD_DISK: |
| 5948 | case SET_DISK_FAULTY: |
| 5949 | case SET_BITMAP_FILE: |
| 5950 | /* These take in integer arg, do not convert */ |
| 5951 | break; |
| 5952 | default: |
| 5953 | arg = (unsigned long)compat_ptr(arg); |
| 5954 | break; |
| 5955 | } |
| 5956 | |
| 5957 | return md_ioctl(bdev, mode, cmd, arg); |
| 5958 | } |
| 5959 | #endif /* CONFIG_COMPAT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5960 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5961 | static int md_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5962 | { |
| 5963 | /* |
| 5964 | * Succeed if we can lock the mddev, which confirms that |
| 5965 | * it isn't being stopped right now. |
| 5966 | */ |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5967 | mddev_t *mddev = mddev_find(bdev->bd_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5968 | int err; |
| 5969 | |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5970 | if (mddev->gendisk != bdev->bd_disk) { |
| 5971 | /* we are racing with mddev_put which is discarding this |
| 5972 | * bd_disk. |
| 5973 | */ |
| 5974 | mddev_put(mddev); |
| 5975 | /* Wait until bdev->bd_disk is definitely gone */ |
| 5976 | flush_scheduled_work(); |
| 5977 | /* Then retry the open from the top */ |
| 5978 | return -ERESTARTSYS; |
| 5979 | } |
| 5980 | BUG_ON(mddev != bdev->bd_disk->private_data); |
| 5981 | |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 5982 | if ((err = mutex_lock_interruptible(&mddev->open_mutex))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5983 | goto out; |
| 5984 | |
| 5985 | err = 0; |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 5986 | atomic_inc(&mddev->openers); |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 5987 | mutex_unlock(&mddev->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5988 | |
NeilBrown | f3b99be | 2010-06-24 13:31:03 +1000 | [diff] [blame] | 5989 | check_disk_size_change(mddev->gendisk, bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5990 | out: |
| 5991 | return err; |
| 5992 | } |
| 5993 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5994 | static int md_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5995 | { |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5996 | mddev_t *mddev = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5997 | |
Eric Sesterhenn | 52e5f9d | 2006-10-03 23:33:23 +0200 | [diff] [blame] | 5998 | BUG_ON(!mddev); |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 5999 | atomic_dec(&mddev->openers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6000 | mddev_put(mddev); |
| 6001 | |
| 6002 | return 0; |
| 6003 | } |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 6004 | static const struct block_device_operations md_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6005 | { |
| 6006 | .owner = THIS_MODULE, |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 6007 | .open = md_open, |
| 6008 | .release = md_release, |
NeilBrown | b492b85 | 2009-05-26 12:57:36 +1000 | [diff] [blame] | 6009 | .ioctl = md_ioctl, |
Arnd Bergmann | aa98aa3 | 2009-12-14 12:50:05 +1100 | [diff] [blame] | 6010 | #ifdef CONFIG_COMPAT |
| 6011 | .compat_ioctl = md_compat_ioctl, |
| 6012 | #endif |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 6013 | .getgeo = md_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6014 | }; |
| 6015 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 6016 | static int md_thread(void * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6017 | { |
| 6018 | mdk_thread_t *thread = arg; |
| 6019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | /* |
| 6021 | * md_thread is a 'system-thread', it's priority should be very |
| 6022 | * high. We avoid resource deadlocks individually in each |
| 6023 | * raid personality. (RAID5 does preallocation) We also use RR and |
| 6024 | * the very same RT priority as kswapd, thus we will never get |
| 6025 | * into a priority inversion deadlock. |
| 6026 | * |
| 6027 | * we definitely have to have equal or higher priority than |
| 6028 | * bdflush, otherwise bdflush will deadlock if there are too |
| 6029 | * many dirty RAID5 blocks. |
| 6030 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6031 | |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 6032 | allow_signal(SIGKILL); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6033 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6034 | |
NeilBrown | 93588e2 | 2005-11-15 00:09:12 -0800 | [diff] [blame] | 6035 | /* We need to wait INTERRUPTIBLE so that |
| 6036 | * we don't add to the load-average. |
| 6037 | * That means we need to be sure no signals are |
| 6038 | * pending |
| 6039 | */ |
| 6040 | if (signal_pending(current)) |
| 6041 | flush_signals(current); |
| 6042 | |
| 6043 | wait_event_interruptible_timeout |
| 6044 | (thread->wqueue, |
| 6045 | test_bit(THREAD_WAKEUP, &thread->flags) |
| 6046 | || kthread_should_stop(), |
| 6047 | thread->timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6048 | |
| 6049 | clear_bit(THREAD_WAKEUP, &thread->flags); |
| 6050 | |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 6051 | thread->run(thread->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6052 | } |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6054 | return 0; |
| 6055 | } |
| 6056 | |
| 6057 | void md_wakeup_thread(mdk_thread_t *thread) |
| 6058 | { |
| 6059 | if (thread) { |
| 6060 | dprintk("md: waking up MD thread %s.\n", thread->tsk->comm); |
| 6061 | set_bit(THREAD_WAKEUP, &thread->flags); |
| 6062 | wake_up(&thread->wqueue); |
| 6063 | } |
| 6064 | } |
| 6065 | |
| 6066 | mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, |
| 6067 | const char *name) |
| 6068 | { |
| 6069 | mdk_thread_t *thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6070 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 6071 | thread = kzalloc(sizeof(mdk_thread_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6072 | if (!thread) |
| 6073 | return NULL; |
| 6074 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6075 | init_waitqueue_head(&thread->wqueue); |
| 6076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6077 | thread->run = run; |
| 6078 | thread->mddev = mddev; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6079 | thread->timeout = MAX_SCHEDULE_TIMEOUT; |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 6080 | thread->tsk = kthread_run(md_thread, thread, |
| 6081 | "%s_%s", |
| 6082 | mdname(thread->mddev), |
| 6083 | name ?: mddev->pers->name); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6084 | if (IS_ERR(thread->tsk)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6085 | kfree(thread); |
| 6086 | return NULL; |
| 6087 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6088 | return thread; |
| 6089 | } |
| 6090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6091 | void md_unregister_thread(mdk_thread_t *thread) |
| 6092 | { |
NeilBrown | e0cf8f0 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6093 | if (!thread) |
| 6094 | return; |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 6095 | dprintk("interrupting MD-thread pid %d\n", task_pid_nr(thread->tsk)); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6096 | |
| 6097 | kthread_stop(thread->tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6098 | kfree(thread); |
| 6099 | } |
| 6100 | |
| 6101 | void md_error(mddev_t *mddev, mdk_rdev_t *rdev) |
| 6102 | { |
| 6103 | if (!mddev) { |
| 6104 | MD_BUG(); |
| 6105 | return; |
| 6106 | } |
| 6107 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6108 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6109 | return; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 6110 | |
| 6111 | if (mddev->external) |
| 6112 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6113 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6114 | dprintk("md_error dev:%s, rdev:(%d:%d), (caller: %p,%p,%p,%p).\n", |
| 6115 | mdname(mddev), |
| 6116 | MAJOR(rdev->bdev->bd_dev), MINOR(rdev->bdev->bd_dev), |
| 6117 | __builtin_return_address(0),__builtin_return_address(1), |
| 6118 | __builtin_return_address(2),__builtin_return_address(3)); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6119 | */ |
Andrew Morton | d0a0a5e | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 6120 | if (!mddev->pers) |
| 6121 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6122 | if (!mddev->pers->error_handler) |
| 6123 | return; |
| 6124 | mddev->pers->error_handler(mddev,rdev); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6125 | if (mddev->degraded) |
| 6126 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6127 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6128 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 6129 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6130 | md_wakeup_thread(mddev->thread); |
NeilBrown | 768a418 | 2010-07-26 11:49:55 +1000 | [diff] [blame] | 6131 | if (mddev->event_work.func) |
| 6132 | schedule_work(&mddev->event_work); |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 6133 | md_new_event_inintr(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | /* seq_file implementation /proc/mdstat */ |
| 6137 | |
| 6138 | static void status_unused(struct seq_file *seq) |
| 6139 | { |
| 6140 | int i = 0; |
| 6141 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6142 | |
| 6143 | seq_printf(seq, "unused devices: "); |
| 6144 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6145 | list_for_each_entry(rdev, &pending_raid_disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6146 | char b[BDEVNAME_SIZE]; |
| 6147 | i++; |
| 6148 | seq_printf(seq, "%s ", |
| 6149 | bdevname(rdev->bdev,b)); |
| 6150 | } |
| 6151 | if (!i) |
| 6152 | seq_printf(seq, "<none>"); |
| 6153 | |
| 6154 | seq_printf(seq, "\n"); |
| 6155 | } |
| 6156 | |
| 6157 | |
| 6158 | static void status_resync(struct seq_file *seq, mddev_t * mddev) |
| 6159 | { |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6160 | sector_t max_sectors, resync, res; |
| 6161 | unsigned long dt, db; |
| 6162 | sector_t rt; |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6163 | int scale; |
| 6164 | unsigned int per_milli; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6165 | |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6166 | resync = mddev->curr_resync - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6167 | |
| 6168 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6169 | max_sectors = mddev->resync_max_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6170 | else |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6171 | max_sectors = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6172 | |
| 6173 | /* |
| 6174 | * Should not happen. |
| 6175 | */ |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6176 | if (!max_sectors) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6177 | MD_BUG(); |
| 6178 | return; |
| 6179 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6180 | /* Pick 'scale' such that (resync>>scale)*1000 will fit |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6181 | * in a sector_t, and (max_sectors>>scale) will fit in a |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6182 | * u32, as those are the requirements for sector_div. |
| 6183 | * Thus 'scale' must be at least 10 |
| 6184 | */ |
| 6185 | scale = 10; |
| 6186 | if (sizeof(sector_t) > sizeof(unsigned long)) { |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6187 | while ( max_sectors/2 > (1ULL<<(scale+32))) |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6188 | scale++; |
| 6189 | } |
| 6190 | res = (resync>>scale)*1000; |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6191 | sector_div(res, (u32)((max_sectors>>scale)+1)); |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6192 | |
| 6193 | per_milli = res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6194 | { |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6195 | int i, x = per_milli/50, y = 20-x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6196 | seq_printf(seq, "["); |
| 6197 | for (i = 0; i < x; i++) |
| 6198 | seq_printf(seq, "="); |
| 6199 | seq_printf(seq, ">"); |
| 6200 | for (i = 0; i < y; i++) |
| 6201 | seq_printf(seq, "."); |
| 6202 | seq_printf(seq, "] "); |
| 6203 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6204 | seq_printf(seq, " %s =%3u.%u%% (%llu/%llu)", |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 6205 | (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)? |
| 6206 | "reshape" : |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6207 | (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)? |
| 6208 | "check" : |
| 6209 | (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ? |
| 6210 | "resync" : "recovery"))), |
| 6211 | per_milli/10, per_milli % 10, |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6212 | (unsigned long long) resync/2, |
| 6213 | (unsigned long long) max_sectors/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6214 | |
| 6215 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6216 | * dt: time from mark until now |
| 6217 | * db: blocks written from mark until now |
| 6218 | * rt: remaining time |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6219 | * |
| 6220 | * rt is a sector_t, so could be 32bit or 64bit. |
| 6221 | * So we divide before multiply in case it is 32bit and close |
| 6222 | * to the limit. |
| 6223 | * We scale the divisor (db) by 32 to avoid loosing precision |
| 6224 | * near the end of resync when the number of remaining sectors |
| 6225 | * is close to 'db'. |
| 6226 | * We then divide rt by 32 after multiplying by db to compensate. |
| 6227 | * The '+1' avoids division by zero if db is very small. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | */ |
| 6229 | dt = ((jiffies - mddev->resync_mark) / HZ); |
| 6230 | if (!dt) dt++; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6231 | db = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active)) |
| 6232 | - mddev->resync_mark_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6233 | |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6234 | rt = max_sectors - resync; /* number of remaining sectors */ |
| 6235 | sector_div(rt, db/32+1); |
| 6236 | rt *= dt; |
| 6237 | rt >>= 5; |
| 6238 | |
| 6239 | seq_printf(seq, " finish=%lu.%lumin", (unsigned long)rt / 60, |
| 6240 | ((unsigned long)rt % 60)/6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6242 | seq_printf(seq, " speed=%ldK/sec", db/2/dt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | } |
| 6244 | |
| 6245 | static void *md_seq_start(struct seq_file *seq, loff_t *pos) |
| 6246 | { |
| 6247 | struct list_head *tmp; |
| 6248 | loff_t l = *pos; |
| 6249 | mddev_t *mddev; |
| 6250 | |
| 6251 | if (l >= 0x10000) |
| 6252 | return NULL; |
| 6253 | if (!l--) |
| 6254 | /* header */ |
| 6255 | return (void*)1; |
| 6256 | |
| 6257 | spin_lock(&all_mddevs_lock); |
| 6258 | list_for_each(tmp,&all_mddevs) |
| 6259 | if (!l--) { |
| 6260 | mddev = list_entry(tmp, mddev_t, all_mddevs); |
| 6261 | mddev_get(mddev); |
| 6262 | spin_unlock(&all_mddevs_lock); |
| 6263 | return mddev; |
| 6264 | } |
| 6265 | spin_unlock(&all_mddevs_lock); |
| 6266 | if (!l--) |
| 6267 | return (void*)2;/* tail */ |
| 6268 | return NULL; |
| 6269 | } |
| 6270 | |
| 6271 | static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 6272 | { |
| 6273 | struct list_head *tmp; |
| 6274 | mddev_t *next_mddev, *mddev = v; |
| 6275 | |
| 6276 | ++*pos; |
| 6277 | if (v == (void*)2) |
| 6278 | return NULL; |
| 6279 | |
| 6280 | spin_lock(&all_mddevs_lock); |
| 6281 | if (v == (void*)1) |
| 6282 | tmp = all_mddevs.next; |
| 6283 | else |
| 6284 | tmp = mddev->all_mddevs.next; |
| 6285 | if (tmp != &all_mddevs) |
| 6286 | next_mddev = mddev_get(list_entry(tmp,mddev_t,all_mddevs)); |
| 6287 | else { |
| 6288 | next_mddev = (void*)2; |
| 6289 | *pos = 0x10000; |
| 6290 | } |
| 6291 | spin_unlock(&all_mddevs_lock); |
| 6292 | |
| 6293 | if (v != (void*)1) |
| 6294 | mddev_put(mddev); |
| 6295 | return next_mddev; |
| 6296 | |
| 6297 | } |
| 6298 | |
| 6299 | static void md_seq_stop(struct seq_file *seq, void *v) |
| 6300 | { |
| 6301 | mddev_t *mddev = v; |
| 6302 | |
| 6303 | if (mddev && v != (void*)1 && v != (void*)2) |
| 6304 | mddev_put(mddev); |
| 6305 | } |
| 6306 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6307 | struct mdstat_info { |
| 6308 | int event; |
| 6309 | }; |
| 6310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6311 | static int md_seq_show(struct seq_file *seq, void *v) |
| 6312 | { |
| 6313 | mddev_t *mddev = v; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6314 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6315 | mdk_rdev_t *rdev; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6316 | struct mdstat_info *mi = seq->private; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6317 | struct bitmap *bitmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6318 | |
| 6319 | if (v == (void*)1) { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6320 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6321 | seq_printf(seq, "Personalities : "); |
| 6322 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6323 | list_for_each_entry(pers, &pers_list, list) |
| 6324 | seq_printf(seq, "[%s] ", pers->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6325 | |
| 6326 | spin_unlock(&pers_lock); |
| 6327 | seq_printf(seq, "\n"); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6328 | mi->event = atomic_read(&md_event_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6329 | return 0; |
| 6330 | } |
| 6331 | if (v == (void*)2) { |
| 6332 | status_unused(seq); |
| 6333 | return 0; |
| 6334 | } |
| 6335 | |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 6336 | if (mddev_lock(mddev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6337 | return -EINTR; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 6338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6339 | if (mddev->pers || mddev->raid_disks || !list_empty(&mddev->disks)) { |
| 6340 | seq_printf(seq, "%s : %sactive", mdname(mddev), |
| 6341 | mddev->pers ? "" : "in"); |
| 6342 | if (mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6343 | if (mddev->ro==1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6344 | seq_printf(seq, " (read-only)"); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6345 | if (mddev->ro==2) |
NeilBrown | 52720ae | 2008-03-10 11:43:47 -0700 | [diff] [blame] | 6346 | seq_printf(seq, " (auto-read-only)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6347 | seq_printf(seq, " %s", mddev->pers->name); |
| 6348 | } |
| 6349 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6350 | sectors = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6351 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6352 | char b[BDEVNAME_SIZE]; |
| 6353 | seq_printf(seq, " %s[%d]", |
| 6354 | bdevname(rdev->bdev,b), rdev->desc_nr); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 6355 | if (test_bit(WriteMostly, &rdev->flags)) |
| 6356 | seq_printf(seq, "(W)"); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6357 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6358 | seq_printf(seq, "(F)"); |
| 6359 | continue; |
NeilBrown | b325a32 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6360 | } else if (rdev->raid_disk < 0) |
| 6361 | seq_printf(seq, "(S)"); /* spare */ |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6362 | sectors += rdev->sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | if (!list_empty(&mddev->disks)) { |
| 6366 | if (mddev->pers) |
| 6367 | seq_printf(seq, "\n %llu blocks", |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 6368 | (unsigned long long) |
| 6369 | mddev->array_sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6370 | else |
| 6371 | seq_printf(seq, "\n %llu blocks", |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6372 | (unsigned long long)sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6373 | } |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6374 | if (mddev->persistent) { |
| 6375 | if (mddev->major_version != 0 || |
| 6376 | mddev->minor_version != 90) { |
| 6377 | seq_printf(seq," super %d.%d", |
| 6378 | mddev->major_version, |
| 6379 | mddev->minor_version); |
| 6380 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 6381 | } else if (mddev->external) |
| 6382 | seq_printf(seq, " super external:%s", |
| 6383 | mddev->metadata_type); |
| 6384 | else |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6385 | seq_printf(seq, " super non-persistent"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6386 | |
| 6387 | if (mddev->pers) { |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6388 | mddev->pers->status(seq, mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6389 | seq_printf(seq, "\n "); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 6390 | if (mddev->pers->sync_request) { |
| 6391 | if (mddev->curr_resync > 2) { |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6392 | status_resync(seq, mddev); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 6393 | seq_printf(seq, "\n "); |
| 6394 | } else if (mddev->curr_resync == 1 || mddev->curr_resync == 2) |
| 6395 | seq_printf(seq, "\tresync=DELAYED\n "); |
| 6396 | else if (mddev->recovery_cp < MaxSector) |
| 6397 | seq_printf(seq, "\tresync=PENDING\n "); |
| 6398 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6399 | } else |
| 6400 | seq_printf(seq, "\n "); |
| 6401 | |
| 6402 | if ((bitmap = mddev->bitmap)) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6403 | unsigned long chunk_kb; |
| 6404 | unsigned long flags; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6405 | spin_lock_irqsave(&bitmap->lock, flags); |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 6406 | chunk_kb = mddev->bitmap_info.chunksize >> 10; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6407 | seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], " |
| 6408 | "%lu%s chunk", |
| 6409 | bitmap->pages - bitmap->missing_pages, |
| 6410 | bitmap->pages, |
| 6411 | (bitmap->pages - bitmap->missing_pages) |
| 6412 | << (PAGE_SHIFT - 10), |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 6413 | chunk_kb ? chunk_kb : mddev->bitmap_info.chunksize, |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6414 | chunk_kb ? "KB" : "B"); |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 6415 | if (bitmap->file) { |
| 6416 | seq_printf(seq, ", file: "); |
Jan Blunck | c32c2f6 | 2008-02-14 19:38:43 -0800 | [diff] [blame] | 6417 | seq_path(seq, &bitmap->file->f_path, " \t\n"); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6418 | } |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 6419 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6420 | seq_printf(seq, "\n"); |
| 6421 | spin_unlock_irqrestore(&bitmap->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | seq_printf(seq, "\n"); |
| 6425 | } |
| 6426 | mddev_unlock(mddev); |
| 6427 | |
| 6428 | return 0; |
| 6429 | } |
| 6430 | |
Jan Engelhardt | 110518b | 2009-05-07 12:49:37 +1000 | [diff] [blame] | 6431 | static const struct seq_operations md_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6432 | .start = md_seq_start, |
| 6433 | .next = md_seq_next, |
| 6434 | .stop = md_seq_stop, |
| 6435 | .show = md_seq_show, |
| 6436 | }; |
| 6437 | |
| 6438 | static int md_seq_open(struct inode *inode, struct file *file) |
| 6439 | { |
| 6440 | int error; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6441 | struct mdstat_info *mi = kmalloc(sizeof(*mi), GFP_KERNEL); |
| 6442 | if (mi == NULL) |
| 6443 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6444 | |
| 6445 | error = seq_open(file, &md_seq_ops); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6446 | if (error) |
| 6447 | kfree(mi); |
| 6448 | else { |
| 6449 | struct seq_file *p = file->private_data; |
| 6450 | p->private = mi; |
| 6451 | mi->event = atomic_read(&md_event_count); |
| 6452 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6453 | return error; |
| 6454 | } |
| 6455 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6456 | static unsigned int mdstat_poll(struct file *filp, poll_table *wait) |
| 6457 | { |
| 6458 | struct seq_file *m = filp->private_data; |
| 6459 | struct mdstat_info *mi = m->private; |
| 6460 | int mask; |
| 6461 | |
| 6462 | poll_wait(filp, &md_event_waiters, wait); |
| 6463 | |
| 6464 | /* always allow read */ |
| 6465 | mask = POLLIN | POLLRDNORM; |
| 6466 | |
| 6467 | if (mi->event != atomic_read(&md_event_count)) |
| 6468 | mask |= POLLERR | POLLPRI; |
| 6469 | return mask; |
| 6470 | } |
| 6471 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 6472 | static const struct file_operations md_seq_fops = { |
Akinobu Mita | e24650c | 2006-10-17 00:09:38 -0700 | [diff] [blame] | 6473 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6474 | .open = md_seq_open, |
| 6475 | .read = seq_read, |
| 6476 | .llseek = seq_lseek, |
Martin Peschke | c3f94b4 | 2007-05-09 02:35:35 -0700 | [diff] [blame] | 6477 | .release = seq_release_private, |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6478 | .poll = mdstat_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6479 | }; |
| 6480 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6481 | int register_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6482 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6483 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6484 | list_add_tail(&p->list, &pers_list); |
| 6485 | 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] | 6486 | spin_unlock(&pers_lock); |
| 6487 | return 0; |
| 6488 | } |
| 6489 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6490 | int unregister_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6491 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6492 | printk(KERN_INFO "md: %s personality unregistered\n", p->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6493 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6494 | list_del_init(&p->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6495 | spin_unlock(&pers_lock); |
| 6496 | return 0; |
| 6497 | } |
| 6498 | |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6499 | static int is_mddev_idle(mddev_t *mddev, int init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6500 | { |
| 6501 | mdk_rdev_t * rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6502 | int idle; |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6503 | int curr_events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6504 | |
| 6505 | idle = 1; |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 6506 | rcu_read_lock(); |
| 6507 | rdev_for_each_rcu(rdev, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6508 | struct gendisk *disk = rdev->bdev->bd_contains->bd_disk; |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6509 | curr_events = (int)part_stat_read(&disk->part0, sectors[0]) + |
| 6510 | (int)part_stat_read(&disk->part0, sectors[1]) - |
| 6511 | atomic_read(&disk->sync_io); |
NeilBrown | 713f6ab | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 6512 | /* sync IO will cause sync_io to increase before the disk_stats |
| 6513 | * as sync_io is counted when a request starts, and |
| 6514 | * disk_stats is counted when it completes. |
| 6515 | * So resync activity will cause curr_events to be smaller than |
| 6516 | * when there was no such activity. |
| 6517 | * non-sync IO will cause disk_stat to increase without |
| 6518 | * increasing sync_io so curr_events will (eventually) |
| 6519 | * be larger than it was before. Once it becomes |
| 6520 | * substantially larger, the test below will cause |
| 6521 | * the array to appear non-idle, and resync will slow |
| 6522 | * down. |
| 6523 | * If there is a lot of outstanding resync activity when |
| 6524 | * we set last_event to curr_events, then all that activity |
| 6525 | * completing might cause the array to appear non-idle |
| 6526 | * and resync will be slowed down even though there might |
| 6527 | * not have been non-resync activity. This will only |
| 6528 | * happen once though. 'last_events' will soon reflect |
| 6529 | * the state where there is little or no outstanding |
| 6530 | * resync requests, and further resync activity will |
| 6531 | * always make curr_events less than last_events. |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 6532 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6533 | */ |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6534 | if (init || curr_events - rdev->last_events > 64) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6535 | rdev->last_events = curr_events; |
| 6536 | idle = 0; |
| 6537 | } |
| 6538 | } |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 6539 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6540 | return idle; |
| 6541 | } |
| 6542 | |
| 6543 | void md_done_sync(mddev_t *mddev, int blocks, int ok) |
| 6544 | { |
| 6545 | /* another "blocks" (512byte) blocks have been synced */ |
| 6546 | atomic_sub(blocks, &mddev->recovery_active); |
| 6547 | wake_up(&mddev->recovery_wait); |
| 6548 | if (!ok) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6549 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6550 | md_wakeup_thread(mddev->thread); |
| 6551 | // stop recovery, signal do_sync .... |
| 6552 | } |
| 6553 | } |
| 6554 | |
| 6555 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6556 | /* md_write_start(mddev, bi) |
| 6557 | * If we need to update some array metadata (e.g. 'active' flag |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6558 | * in superblock) before writing, schedule a superblock update |
| 6559 | * and wait for it to complete. |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6560 | */ |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6561 | void md_write_start(mddev_t *mddev, struct bio *bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6562 | { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6563 | int did_change = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6564 | if (bio_data_dir(bi) != WRITE) |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6565 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6566 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6567 | BUG_ON(mddev->ro == 1); |
| 6568 | if (mddev->ro == 2) { |
| 6569 | /* need to switch to read/write */ |
| 6570 | mddev->ro = 0; |
| 6571 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6572 | md_wakeup_thread(mddev->thread); |
NeilBrown | 2515619 | 2008-03-04 14:29:32 -0800 | [diff] [blame] | 6573 | md_wakeup_thread(mddev->sync_thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6574 | did_change = 1; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6575 | } |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6576 | atomic_inc(&mddev->writes_pending); |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6577 | if (mddev->safemode == 1) |
| 6578 | mddev->safemode = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6579 | if (mddev->in_sync) { |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 6580 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6581 | if (mddev->in_sync) { |
| 6582 | mddev->in_sync = 0; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6583 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6584 | md_wakeup_thread(mddev->thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6585 | did_change = 1; |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6586 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 6587 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6588 | } |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6589 | if (did_change) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6590 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 09a44cc | 2008-05-23 13:04:36 -0700 | [diff] [blame] | 6591 | wait_event(mddev->sb_wait, |
| 6592 | !test_bit(MD_CHANGE_CLEAN, &mddev->flags) && |
| 6593 | !test_bit(MD_CHANGE_PENDING, &mddev->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6594 | } |
| 6595 | |
| 6596 | void md_write_end(mddev_t *mddev) |
| 6597 | { |
| 6598 | if (atomic_dec_and_test(&mddev->writes_pending)) { |
| 6599 | if (mddev->safemode == 2) |
| 6600 | md_wakeup_thread(mddev->thread); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 6601 | else if (mddev->safemode_delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6602 | mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay); |
| 6603 | } |
| 6604 | } |
| 6605 | |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6606 | /* md_allow_write(mddev) |
| 6607 | * Calling this ensures that the array is marked 'active' so that writes |
| 6608 | * may proceed without blocking. It is important to call this before |
| 6609 | * attempting a GFP_KERNEL allocation while holding the mddev lock. |
| 6610 | * Must be called with mddev_lock held. |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6611 | * |
| 6612 | * In the ->external case MD_CHANGE_CLEAN can not be cleared until mddev->lock |
| 6613 | * is dropped, so return -EAGAIN after notifying userspace. |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6614 | */ |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6615 | int md_allow_write(mddev_t *mddev) |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6616 | { |
| 6617 | if (!mddev->pers) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6618 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6619 | if (mddev->ro) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6620 | return 0; |
Neil Brown | 1a0fd49 | 2008-06-28 08:31:27 +1000 | [diff] [blame] | 6621 | if (!mddev->pers->sync_request) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6622 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6623 | |
| 6624 | spin_lock_irq(&mddev->write_lock); |
| 6625 | if (mddev->in_sync) { |
| 6626 | mddev->in_sync = 0; |
| 6627 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
| 6628 | if (mddev->safemode_delay && |
| 6629 | mddev->safemode == 0) |
| 6630 | mddev->safemode = 1; |
| 6631 | spin_unlock_irq(&mddev->write_lock); |
| 6632 | md_update_sb(mddev, 0); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6633 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6634 | } else |
| 6635 | spin_unlock_irq(&mddev->write_lock); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6636 | |
| 6637 | if (test_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 6638 | return -EAGAIN; |
| 6639 | else |
| 6640 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6641 | } |
| 6642 | EXPORT_SYMBOL_GPL(md_allow_write); |
| 6643 | |
NeilBrown | b63d7c2 | 2010-06-01 19:37:33 +1000 | [diff] [blame] | 6644 | void md_unplug(mddev_t *mddev) |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6645 | { |
| 6646 | if (mddev->queue) |
| 6647 | blk_unplug(mddev->queue); |
| 6648 | if (mddev->plug) |
| 6649 | mddev->plug->unplug_fn(mddev->plug); |
| 6650 | } |
| 6651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6652 | #define SYNC_MARKS 10 |
| 6653 | #define SYNC_MARK_STEP (3*HZ) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6654 | void md_do_sync(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6655 | { |
| 6656 | mddev_t *mddev2; |
| 6657 | unsigned int currspeed = 0, |
| 6658 | window; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6659 | sector_t max_sectors,j, io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6660 | unsigned long mark[SYNC_MARKS]; |
| 6661 | sector_t mark_cnt[SYNC_MARKS]; |
| 6662 | int last_mark,m; |
| 6663 | struct list_head *tmp; |
| 6664 | sector_t last_check; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6665 | int skipped = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6666 | mdk_rdev_t *rdev; |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6667 | char *desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6668 | |
| 6669 | /* just incase thread restarts... */ |
| 6670 | if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) |
| 6671 | return; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6672 | if (mddev->ro) /* never try to sync a read-only array */ |
| 6673 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6674 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6675 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 6676 | if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 6677 | desc = "data-check"; |
| 6678 | else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6679 | desc = "requested-resync"; |
| 6680 | else |
| 6681 | desc = "resync"; |
| 6682 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 6683 | desc = "reshape"; |
| 6684 | else |
| 6685 | desc = "recovery"; |
| 6686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6687 | /* we overload curr_resync somewhat here. |
| 6688 | * 0 == not engaged in resync at all |
| 6689 | * 2 == checking that there is no conflict with another sync |
| 6690 | * 1 == like 2, but have yielded to allow conflicting resync to |
| 6691 | * commense |
| 6692 | * other == active in resync - this many blocks |
| 6693 | * |
| 6694 | * Before starting a resync we must have set curr_resync to |
| 6695 | * 2, and then checked that every "conflicting" array has curr_resync |
| 6696 | * less than ours. When we find one that is the same or higher |
| 6697 | * we wait on resync_wait. To avoid deadlock, we reduce curr_resync |
| 6698 | * to 1 if we choose to yield (based arbitrarily on address of mddev structure). |
| 6699 | * This will mean we have to start checking from the beginning again. |
| 6700 | * |
| 6701 | */ |
| 6702 | |
| 6703 | do { |
| 6704 | mddev->curr_resync = 2; |
| 6705 | |
| 6706 | try_again: |
NeilBrown | 404e4b4 | 2009-12-30 15:25:23 +1100 | [diff] [blame] | 6707 | if (kthread_should_stop()) |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 6708 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
NeilBrown | 404e4b4 | 2009-12-30 15:25:23 +1100 | [diff] [blame] | 6709 | |
| 6710 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6711 | goto skip; |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 6712 | for_each_mddev(mddev2, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6713 | if (mddev2 == mddev) |
| 6714 | continue; |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 6715 | if (!mddev->parallel_resync |
| 6716 | && mddev2->curr_resync |
| 6717 | && match_mddev_units(mddev, mddev2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6718 | DEFINE_WAIT(wq); |
| 6719 | if (mddev < mddev2 && mddev->curr_resync == 2) { |
| 6720 | /* arbitrarily yield */ |
| 6721 | mddev->curr_resync = 1; |
| 6722 | wake_up(&resync_wait); |
| 6723 | } |
| 6724 | if (mddev > mddev2 && mddev->curr_resync == 1) |
| 6725 | /* no need to wait here, we can wait the next |
| 6726 | * time 'round when curr_resync == 2 |
| 6727 | */ |
| 6728 | continue; |
NeilBrown | 9744197 | 2008-09-19 11:49:54 +1000 | [diff] [blame] | 6729 | /* We need to wait 'interruptible' so as not to |
| 6730 | * contribute to the load average, and not to |
| 6731 | * be caught by 'softlockup' |
| 6732 | */ |
| 6733 | prepare_to_wait(&resync_wait, &wq, TASK_INTERRUPTIBLE); |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 6734 | if (!kthread_should_stop() && |
NeilBrown | 8712e55 | 2005-10-26 01:58:58 -0700 | [diff] [blame] | 6735 | mddev2->curr_resync >= mddev->curr_resync) { |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6736 | printk(KERN_INFO "md: delaying %s of %s" |
| 6737 | " until %s has finished (they" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6738 | " share one or more physical units)\n", |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6739 | desc, mdname(mddev), mdname(mddev2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6740 | mddev_put(mddev2); |
NeilBrown | 9744197 | 2008-09-19 11:49:54 +1000 | [diff] [blame] | 6741 | if (signal_pending(current)) |
| 6742 | flush_signals(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6743 | schedule(); |
| 6744 | finish_wait(&resync_wait, &wq); |
| 6745 | goto try_again; |
| 6746 | } |
| 6747 | finish_wait(&resync_wait, &wq); |
| 6748 | } |
| 6749 | } |
| 6750 | } while (mddev->curr_resync < 2); |
| 6751 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6752 | j = 0; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6753 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6754 | /* resync follows the size requested by the personality, |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6755 | * which defaults to physical size, but can be virtual size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6756 | */ |
| 6757 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6758 | mddev->resync_mismatches = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6759 | /* we don't use the checkpoint if there's a bitmap */ |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 6760 | if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6761 | j = mddev->resync_min; |
| 6762 | else if (!mddev->bitmap) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6763 | j = mddev->recovery_cp; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 6764 | |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 6765 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6766 | max_sectors = mddev->dev_sectors; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6767 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6768 | /* recovery follows the physical size of devices */ |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6769 | max_sectors = mddev->dev_sectors; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6770 | j = MaxSector; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6771 | rcu_read_lock(); |
| 6772 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6773 | if (rdev->raid_disk >= 0 && |
| 6774 | !test_bit(Faulty, &rdev->flags) && |
| 6775 | !test_bit(In_sync, &rdev->flags) && |
| 6776 | rdev->recovery_offset < j) |
| 6777 | j = rdev->recovery_offset; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6778 | rcu_read_unlock(); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6779 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6780 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6781 | printk(KERN_INFO "md: %s of RAID array %s\n", desc, mdname(mddev)); |
| 6782 | printk(KERN_INFO "md: minimum _guaranteed_ speed:" |
| 6783 | " %d KB/sec/disk.\n", speed_min(mddev)); |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 6784 | printk(KERN_INFO "md: using maximum available idle IO bandwidth " |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6785 | "(but not more than %d KB/sec) for %s.\n", |
| 6786 | speed_max(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6787 | |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6788 | is_mddev_idle(mddev, 1); /* this initializes IO event counters */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6789 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6790 | io_sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6791 | for (m = 0; m < SYNC_MARKS; m++) { |
| 6792 | mark[m] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6793 | mark_cnt[m] = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6794 | } |
| 6795 | last_mark = 0; |
| 6796 | mddev->resync_mark = mark[last_mark]; |
| 6797 | mddev->resync_mark_cnt = mark_cnt[last_mark]; |
| 6798 | |
| 6799 | /* |
| 6800 | * Tune reconstruction: |
| 6801 | */ |
| 6802 | window = 32*(PAGE_SIZE/512); |
| 6803 | printk(KERN_INFO "md: using %dk window, over a total of %llu blocks.\n", |
| 6804 | window/2,(unsigned long long) max_sectors/2); |
| 6805 | |
| 6806 | atomic_set(&mddev->recovery_active, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6807 | last_check = 0; |
| 6808 | |
| 6809 | if (j>2) { |
| 6810 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6811 | "md: resuming %s of %s from checkpoint.\n", |
| 6812 | desc, mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6813 | mddev->curr_resync = j; |
| 6814 | } |
NeilBrown | efa5933 | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 6815 | mddev->curr_resync_completed = mddev->curr_resync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6816 | |
| 6817 | while (j < max_sectors) { |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6818 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6819 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6820 | skipped = 0; |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6821 | |
NeilBrown | 7a91ee1 | 2009-05-26 12:57:21 +1000 | [diff] [blame] | 6822 | if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && |
| 6823 | ((mddev->curr_resync > mddev->curr_resync_completed && |
| 6824 | (mddev->curr_resync - mddev->curr_resync_completed) |
| 6825 | > (max_sectors >> 4)) || |
| 6826 | (j - mddev->curr_resync_completed)*2 |
| 6827 | >= mddev->resync_max - mddev->curr_resync_completed |
| 6828 | )) { |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6829 | /* time to update curr_resync_completed */ |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6830 | md_unplug(mddev); |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6831 | wait_event(mddev->recovery_wait, |
| 6832 | atomic_read(&mddev->recovery_active) == 0); |
| 6833 | mddev->curr_resync_completed = |
| 6834 | mddev->curr_resync; |
NeilBrown | 676e42d | 2010-06-01 19:37:26 +1000 | [diff] [blame] | 6835 | if (mddev->persistent) |
| 6836 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6837 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6838 | } |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6839 | |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 6840 | while (j >= mddev->resync_max && !kthread_should_stop()) { |
| 6841 | /* As this condition is controlled by user-space, |
| 6842 | * we can block indefinitely, so use '_interruptible' |
| 6843 | * to avoid triggering warnings. |
| 6844 | */ |
| 6845 | flush_signals(current); /* just in case */ |
| 6846 | wait_event_interruptible(mddev->recovery_wait, |
| 6847 | mddev->resync_max > j |
| 6848 | || kthread_should_stop()); |
| 6849 | } |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6850 | |
| 6851 | if (kthread_should_stop()) |
| 6852 | goto interrupted; |
| 6853 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6854 | sectors = mddev->pers->sync_request(mddev, j, &skipped, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6855 | currspeed < speed_min(mddev)); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6856 | if (sectors == 0) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6857 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6858 | goto out; |
| 6859 | } |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6860 | |
| 6861 | if (!skipped) { /* actual IO requested */ |
| 6862 | io_sectors += sectors; |
| 6863 | atomic_add(sectors, &mddev->recovery_active); |
| 6864 | } |
| 6865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | j += sectors; |
| 6867 | if (j>1) mddev->curr_resync = j; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6868 | mddev->curr_mark_cnt = io_sectors; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6869 | if (last_check == 0) |
| 6870 | /* this is the earliers that rebuilt will be |
| 6871 | * visible in /proc/mdstat |
| 6872 | */ |
| 6873 | md_new_event(mddev); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6874 | |
| 6875 | if (last_check + window > io_sectors || j == max_sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6876 | continue; |
| 6877 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6878 | last_check = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6879 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6880 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6881 | break; |
| 6882 | |
| 6883 | repeat: |
| 6884 | if (time_after_eq(jiffies, mark[last_mark] + SYNC_MARK_STEP )) { |
| 6885 | /* step marks */ |
| 6886 | int next = (last_mark+1) % SYNC_MARKS; |
| 6887 | |
| 6888 | mddev->resync_mark = mark[next]; |
| 6889 | mddev->resync_mark_cnt = mark_cnt[next]; |
| 6890 | mark[next] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6891 | mark_cnt[next] = io_sectors - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6892 | last_mark = next; |
| 6893 | } |
| 6894 | |
| 6895 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6896 | if (kthread_should_stop()) |
| 6897 | goto interrupted; |
| 6898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6899 | |
| 6900 | /* |
| 6901 | * this loop exits only if either when we are slower than |
| 6902 | * the 'hard' speed limit, or the system was IO-idle for |
| 6903 | * a jiffy. |
| 6904 | * the system might be non-idle CPU-wise, but we only care |
| 6905 | * about not overloading the IO subsystem. (things like an |
| 6906 | * e2fsck being done on the RAID array should execute fast) |
| 6907 | */ |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6908 | md_unplug(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6909 | cond_resched(); |
| 6910 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6911 | currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2 |
| 6912 | /((jiffies-mddev->resync_mark)/HZ +1) +1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6913 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 6914 | if (currspeed > speed_min(mddev)) { |
| 6915 | if ((currspeed > speed_max(mddev)) || |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6916 | !is_mddev_idle(mddev, 0)) { |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 6917 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6918 | goto repeat; |
| 6919 | } |
| 6920 | } |
| 6921 | } |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6922 | printk(KERN_INFO "md: %s: %s done.\n",mdname(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6923 | /* |
| 6924 | * this also signals 'finished resyncing' to md_stop |
| 6925 | */ |
| 6926 | out: |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6927 | md_unplug(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6928 | |
| 6929 | wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); |
| 6930 | |
| 6931 | /* tell personality that we are finished */ |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6932 | mddev->pers->sync_request(mddev, max_sectors, &skipped, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6933 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6934 | if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) && |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6935 | mddev->curr_resync > 2) { |
| 6936 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 6937 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6938 | if (mddev->curr_resync >= mddev->recovery_cp) { |
| 6939 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6940 | "md: checkpointing %s of %s.\n", |
| 6941 | desc, mdname(mddev)); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6942 | mddev->recovery_cp = mddev->curr_resync; |
| 6943 | } |
| 6944 | } else |
| 6945 | mddev->recovery_cp = MaxSector; |
| 6946 | } else { |
| 6947 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 6948 | mddev->curr_resync = MaxSector; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6949 | rcu_read_lock(); |
| 6950 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6951 | if (rdev->raid_disk >= 0 && |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 6952 | mddev->delta_disks >= 0 && |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6953 | !test_bit(Faulty, &rdev->flags) && |
| 6954 | !test_bit(In_sync, &rdev->flags) && |
| 6955 | rdev->recovery_offset < mddev->curr_resync) |
| 6956 | rdev->recovery_offset = mddev->curr_resync; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6957 | rcu_read_unlock(); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6959 | } |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 6960 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6962 | skip: |
NeilBrown | c07b70a | 2009-12-14 12:49:48 +1100 | [diff] [blame] | 6963 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6964 | /* We completed so min/max setting can be forgotten if used. */ |
| 6965 | if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6966 | mddev->resync_min = 0; |
| 6967 | mddev->resync_max = MaxSector; |
| 6968 | } else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6969 | mddev->resync_min = mddev->curr_resync_completed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6970 | mddev->curr_resync = 0; |
NeilBrown | efa5933 | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 6971 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 6972 | mddev->curr_resync_completed = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6973 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6974 | wake_up(&resync_wait); |
| 6975 | set_bit(MD_RECOVERY_DONE, &mddev->recovery); |
| 6976 | md_wakeup_thread(mddev->thread); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6977 | return; |
| 6978 | |
| 6979 | interrupted: |
| 6980 | /* |
| 6981 | * got a signal, exit. |
| 6982 | */ |
| 6983 | printk(KERN_INFO |
| 6984 | "md: md_do_sync() got signal ... exiting\n"); |
| 6985 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 6986 | goto out; |
| 6987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6988 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6989 | EXPORT_SYMBOL_GPL(md_do_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6990 | |
| 6991 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6992 | static int remove_and_add_spares(mddev_t *mddev) |
| 6993 | { |
| 6994 | mdk_rdev_t *rdev; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6995 | int spares = 0; |
| 6996 | |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6997 | mddev->curr_resync_completed = 0; |
| 6998 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6999 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7000 | if (rdev->raid_disk >= 0 && |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 7001 | !test_bit(Blocked, &rdev->flags) && |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7002 | (test_bit(Faulty, &rdev->flags) || |
| 7003 | ! test_bit(In_sync, &rdev->flags)) && |
| 7004 | atomic_read(&rdev->nr_pending)==0) { |
| 7005 | if (mddev->pers->hot_remove_disk( |
| 7006 | mddev, rdev->raid_disk)==0) { |
| 7007 | char nm[20]; |
| 7008 | sprintf(nm,"rd%d", rdev->raid_disk); |
| 7009 | sysfs_remove_link(&mddev->kobj, nm); |
| 7010 | rdev->raid_disk = -1; |
| 7011 | } |
| 7012 | } |
| 7013 | |
NeilBrown | 4044ba5 | 2009-01-09 08:31:11 +1100 | [diff] [blame] | 7014 | if (mddev->degraded && ! mddev->ro && !mddev->recovery_disabled) { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 7015 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 7016 | if (rdev->raid_disk >= 0 && |
Dan Williams | e542713 | 2008-07-28 23:28:06 -0700 | [diff] [blame] | 7017 | !test_bit(In_sync, &rdev->flags) && |
| 7018 | !test_bit(Blocked, &rdev->flags)) |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 7019 | spares++; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7020 | if (rdev->raid_disk < 0 |
| 7021 | && !test_bit(Faulty, &rdev->flags)) { |
| 7022 | rdev->recovery_offset = 0; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 7023 | if (mddev->pers-> |
| 7024 | hot_add_disk(mddev, rdev) == 0) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7025 | char nm[20]; |
| 7026 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 7027 | if (sysfs_create_link(&mddev->kobj, |
| 7028 | &rdev->kobj, nm)) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7029 | /* failure here is OK */; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7030 | spares++; |
| 7031 | md_new_event(mddev); |
NeilBrown | 93be75f | 2009-12-14 12:50:06 +1100 | [diff] [blame] | 7032 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7033 | } else |
| 7034 | break; |
| 7035 | } |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 7036 | } |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7037 | } |
| 7038 | return spares; |
| 7039 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7040 | /* |
| 7041 | * This routine is regularly called by all per-raid-array threads to |
| 7042 | * deal with generic issues like resync and super-block update. |
| 7043 | * Raid personalities that don't have a thread (linear/raid0) do not |
| 7044 | * need this as they never do any recovery or update the superblock. |
| 7045 | * |
| 7046 | * It does not do any resync itself, but rather "forks" off other threads |
| 7047 | * to do that as needed. |
| 7048 | * When it is determined that resync is needed, we set MD_RECOVERY_RUNNING in |
| 7049 | * "->recovery" and create a thread at ->sync_thread. |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 7050 | * When the thread finishes it sets MD_RECOVERY_DONE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7051 | * and wakeups up this thread which will reap the thread and finish up. |
| 7052 | * This thread also removes any faulty devices (with nr_pending == 0). |
| 7053 | * |
| 7054 | * The overall approach is: |
| 7055 | * 1/ if the superblock needs updating, update it. |
| 7056 | * 2/ If a recovery thread is running, don't do anything else. |
| 7057 | * 3/ If recovery has finished, clean up, possibly marking spares active. |
| 7058 | * 4/ If there are any faulty devices, remove them. |
| 7059 | * 5/ If array is degraded, try to add spares devices |
| 7060 | * 6/ If array has spares or is not in-sync, start a resync thread. |
| 7061 | */ |
| 7062 | void md_check_recovery(mddev_t *mddev) |
| 7063 | { |
| 7064 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7065 | |
| 7066 | |
NeilBrown | 5f40402 | 2005-06-21 17:17:16 -0700 | [diff] [blame] | 7067 | if (mddev->bitmap) |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 7068 | bitmap_daemon_work(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7069 | |
| 7070 | if (mddev->ro) |
| 7071 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7072 | |
| 7073 | if (signal_pending(current)) { |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7074 | if (mddev->pers->sync_request && !mddev->external) { |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7075 | printk(KERN_INFO "md: %s in immediate safe mode\n", |
| 7076 | mdname(mddev)); |
| 7077 | mddev->safemode = 2; |
| 7078 | } |
| 7079 | flush_signals(current); |
| 7080 | } |
| 7081 | |
NeilBrown | c89a8ee | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 7082 | if (mddev->ro && !test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
| 7083 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7084 | if ( ! ( |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 7085 | (mddev->flags && !mddev->external) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7086 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7087 | test_bit(MD_RECOVERY_DONE, &mddev->recovery) || |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7088 | (mddev->external == 0 && mddev->safemode == 1) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7089 | (mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending) |
| 7090 | && !mddev->in_sync && mddev->recovery_cp == MaxSector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7091 | )) |
| 7092 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7093 | |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 7094 | if (mddev_trylock(mddev)) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7095 | int spares = 0; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7096 | |
NeilBrown | c89a8ee | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 7097 | if (mddev->ro) { |
| 7098 | /* Only thing we do on a ro array is remove |
| 7099 | * failed devices. |
| 7100 | */ |
| 7101 | remove_and_add_spares(mddev); |
| 7102 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 7103 | goto unlock; |
| 7104 | } |
| 7105 | |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7106 | if (!mddev->external) { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 7107 | int did_change = 0; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7108 | spin_lock_irq(&mddev->write_lock); |
| 7109 | if (mddev->safemode && |
| 7110 | !atomic_read(&mddev->writes_pending) && |
| 7111 | !mddev->in_sync && |
| 7112 | mddev->recovery_cp == MaxSector) { |
| 7113 | mddev->in_sync = 1; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 7114 | did_change = 1; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7115 | if (mddev->persistent) |
| 7116 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
| 7117 | } |
| 7118 | if (mddev->safemode == 1) |
| 7119 | mddev->safemode = 0; |
| 7120 | spin_unlock_irq(&mddev->write_lock); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 7121 | if (did_change) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7122 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7123 | } |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7124 | |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 7125 | if (mddev->flags) |
| 7126 | md_update_sb(mddev, 0); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 7127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7128 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && |
| 7129 | !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) { |
| 7130 | /* resync/recovery still happening */ |
| 7131 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 7132 | goto unlock; |
| 7133 | } |
| 7134 | if (mddev->sync_thread) { |
| 7135 | /* resync has finished, collect result */ |
| 7136 | md_unregister_thread(mddev->sync_thread); |
| 7137 | mddev->sync_thread = NULL; |
Dan Williams | 56ac36d | 2008-08-07 10:02:47 -0700 | [diff] [blame] | 7138 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery) && |
| 7139 | !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7140 | /* success...*/ |
| 7141 | /* activate any spares */ |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 7142 | if (mddev->pers->spare_active(mddev)) |
| 7143 | sysfs_notify(&mddev->kobj, NULL, |
| 7144 | "degraded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7145 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 7146 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && |
| 7147 | mddev->pers->finish_reshape) |
| 7148 | mddev->pers->finish_reshape(mddev); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 7149 | md_update_sb(mddev, 1); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 7150 | |
| 7151 | /* if array is no-longer degraded, then any saved_raid_disk |
| 7152 | * information must be scrapped |
| 7153 | */ |
| 7154 | if (!mddev->degraded) |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 7155 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 7156 | rdev->saved_raid_disk = -1; |
| 7157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7158 | mddev->recovery = 0; |
| 7159 | /* flag recovery needed just to double check */ |
| 7160 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7161 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 7162 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7163 | goto unlock; |
| 7164 | } |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7165 | /* Set RUNNING before clearing NEEDED to avoid |
| 7166 | * any transients in the value of "sync_action". |
| 7167 | */ |
| 7168 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 7169 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7170 | /* Clear some bits that don't mean anything, but |
| 7171 | * might be left set |
| 7172 | */ |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7173 | clear_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 7174 | clear_bit(MD_RECOVERY_DONE, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7175 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 7176 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 7177 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7178 | /* no recovery is running. |
| 7179 | * remove any failed drives, then |
| 7180 | * add spares if possible. |
| 7181 | * Spare are also removed and re-added, to allow |
| 7182 | * the personality to fail the re-add. |
| 7183 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7184 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7185 | if (mddev->reshape_position != MaxSector) { |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 7186 | if (mddev->pers->check_reshape == NULL || |
| 7187 | mddev->pers->check_reshape(mddev) != 0) |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7188 | /* Cannot proceed */ |
| 7189 | goto unlock; |
| 7190 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7191 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7192 | } else if ((spares = remove_and_add_spares(mddev))) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7193 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 7194 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
Dan Williams | 56ac36d | 2008-08-07 10:02:47 -0700 | [diff] [blame] | 7195 | clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7196 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7197 | } else if (mddev->recovery_cp < MaxSector) { |
| 7198 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7199 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7200 | } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 7201 | /* nothing to be done ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7202 | goto unlock; |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7204 | if (mddev->pers->sync_request) { |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 7205 | if (spares && mddev->bitmap && ! mddev->bitmap->file) { |
| 7206 | /* We are adding a device or devices to an array |
| 7207 | * which has the bitmap stored on all devices. |
| 7208 | * So make sure all bitmap pages get written |
| 7209 | */ |
| 7210 | bitmap_write_all(mddev->bitmap); |
| 7211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7212 | mddev->sync_thread = md_register_thread(md_do_sync, |
| 7213 | mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 7214 | "resync"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7215 | if (!mddev->sync_thread) { |
| 7216 | printk(KERN_ERR "%s: could not start resync" |
| 7217 | " thread...\n", |
| 7218 | mdname(mddev)); |
| 7219 | /* leave the spares where they are, it shouldn't hurt */ |
| 7220 | mddev->recovery = 0; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 7221 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7222 | md_wakeup_thread(mddev->sync_thread); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7223 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 7224 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7225 | } |
| 7226 | unlock: |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7227 | if (!mddev->sync_thread) { |
| 7228 | clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 7229 | if (test_and_clear_bit(MD_RECOVERY_RECOVER, |
| 7230 | &mddev->recovery)) |
NeilBrown | 0c3573f | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 7231 | if (mddev->sysfs_action) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7232 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7233 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7234 | mddev_unlock(mddev); |
| 7235 | } |
| 7236 | } |
| 7237 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 7238 | void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 7239 | { |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7240 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 7241 | wait_event_timeout(rdev->blocked_wait, |
| 7242 | !test_bit(Blocked, &rdev->flags), |
| 7243 | msecs_to_jiffies(5000)); |
| 7244 | rdev_dec_pending(rdev, mddev); |
| 7245 | } |
| 7246 | EXPORT_SYMBOL(md_wait_for_blocked_rdev); |
| 7247 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 7248 | static int md_notify_reboot(struct notifier_block *this, |
| 7249 | unsigned long code, void *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7250 | { |
| 7251 | struct list_head *tmp; |
| 7252 | mddev_t *mddev; |
| 7253 | |
| 7254 | if ((code == SYS_DOWN) || (code == SYS_HALT) || (code == SYS_POWER_OFF)) { |
| 7255 | |
| 7256 | printk(KERN_INFO "md: stopping all md devices.\n"); |
| 7257 | |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 7258 | for_each_mddev(mddev, tmp) |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 7259 | if (mddev_trylock(mddev)) { |
NeilBrown | 2b25000 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 7260 | /* Force a switch to readonly even array |
| 7261 | * appears to still be in use. Hence |
| 7262 | * the '100'. |
| 7263 | */ |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 7264 | md_set_readonly(mddev, 100); |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 7265 | mddev_unlock(mddev); |
| 7266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7267 | /* |
| 7268 | * certain more exotic SCSI devices are known to be |
| 7269 | * volatile wrt too early system reboots. While the |
| 7270 | * right place to handle this issue is the given |
| 7271 | * driver, we do want to have a safe RAID driver ... |
| 7272 | */ |
| 7273 | mdelay(1000*1); |
| 7274 | } |
| 7275 | return NOTIFY_DONE; |
| 7276 | } |
| 7277 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 7278 | static struct notifier_block md_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7279 | .notifier_call = md_notify_reboot, |
| 7280 | .next = NULL, |
| 7281 | .priority = INT_MAX, /* before any real devices */ |
| 7282 | }; |
| 7283 | |
| 7284 | static void md_geninit(void) |
| 7285 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7286 | dprintk("md: sizeof(mdp_super_t) = %d\n", (int)sizeof(mdp_super_t)); |
| 7287 | |
Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 7288 | proc_create("mdstat", S_IRUGO, NULL, &md_seq_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7289 | } |
| 7290 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 7291 | static int __init md_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7292 | { |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7293 | if (register_blkdev(MD_MAJOR, "md")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7294 | return -1; |
| 7295 | if ((mdp_major=register_blkdev(0, "mdp"))<=0) { |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7296 | unregister_blkdev(MD_MAJOR, "md"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7297 | return -1; |
| 7298 | } |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7299 | blk_register_region(MKDEV(MD_MAJOR, 0), 1UL<<MINORBITS, THIS_MODULE, |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 7300 | md_probe, NULL, NULL); |
| 7301 | blk_register_region(MKDEV(mdp_major, 0), 1UL<<MINORBITS, THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7302 | md_probe, NULL, NULL); |
| 7303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7304 | register_reboot_notifier(&md_notifier); |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 7305 | raid_table_header = register_sysctl_table(raid_root_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7306 | |
| 7307 | md_geninit(); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 7308 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7309 | } |
| 7310 | |
| 7311 | |
| 7312 | #ifndef MODULE |
| 7313 | |
| 7314 | /* |
| 7315 | * Searches all registered partitions for autorun RAID arrays |
| 7316 | * at boot time. |
| 7317 | */ |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7318 | |
| 7319 | static LIST_HEAD(all_detected_devices); |
| 7320 | struct detected_devices_node { |
| 7321 | struct list_head list; |
| 7322 | dev_t dev; |
| 7323 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7324 | |
| 7325 | void md_autodetect_dev(dev_t dev) |
| 7326 | { |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7327 | struct detected_devices_node *node_detected_dev; |
| 7328 | |
| 7329 | node_detected_dev = kzalloc(sizeof(*node_detected_dev), GFP_KERNEL); |
| 7330 | if (node_detected_dev) { |
| 7331 | node_detected_dev->dev = dev; |
| 7332 | list_add_tail(&node_detected_dev->list, &all_detected_devices); |
| 7333 | } else { |
| 7334 | printk(KERN_CRIT "md: md_autodetect_dev: kzalloc failed" |
| 7335 | ", skipping dev(%d,%d)\n", MAJOR(dev), MINOR(dev)); |
| 7336 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7337 | } |
| 7338 | |
| 7339 | |
| 7340 | static void autostart_arrays(int part) |
| 7341 | { |
| 7342 | mdk_rdev_t *rdev; |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7343 | struct detected_devices_node *node_detected_dev; |
| 7344 | dev_t dev; |
| 7345 | int i_scanned, i_passed; |
| 7346 | |
| 7347 | i_scanned = 0; |
| 7348 | i_passed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7349 | |
| 7350 | printk(KERN_INFO "md: Autodetecting RAID arrays.\n"); |
| 7351 | |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7352 | while (!list_empty(&all_detected_devices) && i_scanned < INT_MAX) { |
| 7353 | i_scanned++; |
| 7354 | node_detected_dev = list_entry(all_detected_devices.next, |
| 7355 | struct detected_devices_node, list); |
| 7356 | list_del(&node_detected_dev->list); |
| 7357 | dev = node_detected_dev->dev; |
| 7358 | kfree(node_detected_dev); |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 7359 | rdev = md_import_device(dev,0, 90); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7360 | if (IS_ERR(rdev)) |
| 7361 | continue; |
| 7362 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 7363 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7364 | MD_BUG(); |
| 7365 | continue; |
| 7366 | } |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 7367 | set_bit(AutoDetected, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7368 | list_add(&rdev->same_set, &pending_raid_disks); |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7369 | i_passed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7370 | } |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7371 | |
| 7372 | printk(KERN_INFO "md: Scanned %d and added %d devices.\n", |
| 7373 | i_scanned, i_passed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7374 | |
| 7375 | autorun_devices(part); |
| 7376 | } |
| 7377 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 7378 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7379 | |
| 7380 | static __exit void md_exit(void) |
| 7381 | { |
| 7382 | mddev_t *mddev; |
| 7383 | struct list_head *tmp; |
Greg Kroah-Hartman | 8ab5e4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 7384 | |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7385 | blk_unregister_region(MKDEV(MD_MAJOR,0), 1U << MINORBITS); |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 7386 | blk_unregister_region(MKDEV(mdp_major,0), 1U << MINORBITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7387 | |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7388 | unregister_blkdev(MD_MAJOR,"md"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7389 | unregister_blkdev(mdp_major, "mdp"); |
| 7390 | unregister_reboot_notifier(&md_notifier); |
| 7391 | unregister_sysctl_table(raid_table_header); |
| 7392 | remove_proc_entry("mdstat", NULL); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 7393 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7394 | export_array(mddev); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 7395 | mddev->hold_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7396 | } |
| 7397 | } |
| 7398 | |
Dan Williams | 685784a | 2007-07-09 11:56:42 -0700 | [diff] [blame] | 7399 | subsys_initcall(md_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7400 | module_exit(md_exit) |
| 7401 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7402 | static int get_ro(char *buffer, struct kernel_param *kp) |
| 7403 | { |
| 7404 | return sprintf(buffer, "%d", start_readonly); |
| 7405 | } |
| 7406 | static int set_ro(const char *val, struct kernel_param *kp) |
| 7407 | { |
| 7408 | char *e; |
| 7409 | int num = simple_strtoul(val, &e, 10); |
| 7410 | if (*val && (*e == '\0' || *e == '\n')) { |
| 7411 | start_readonly = num; |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 7412 | return 0; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7413 | } |
| 7414 | return -EINVAL; |
| 7415 | } |
| 7416 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 7417 | module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); |
| 7418 | module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR); |
NeilBrown | 6ff8d8e | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 7419 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 7420 | module_param_call(new_array, add_named_array, NULL, NULL, S_IWUSR); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7422 | EXPORT_SYMBOL(register_md_personality); |
| 7423 | EXPORT_SYMBOL(unregister_md_personality); |
| 7424 | EXPORT_SYMBOL(md_error); |
| 7425 | EXPORT_SYMBOL(md_done_sync); |
| 7426 | EXPORT_SYMBOL(md_write_start); |
| 7427 | EXPORT_SYMBOL(md_write_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7428 | EXPORT_SYMBOL(md_register_thread); |
| 7429 | EXPORT_SYMBOL(md_unregister_thread); |
| 7430 | EXPORT_SYMBOL(md_wakeup_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7431 | EXPORT_SYMBOL(md_check_recovery); |
| 7432 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 7433 | MODULE_DESCRIPTION("MD RAID framework"); |
NeilBrown | aa1595e | 2005-08-04 12:53:32 -0700 | [diff] [blame] | 7434 | MODULE_ALIAS("md"); |
NeilBrown | 7200865 | 2005-08-26 18:34:15 -0700 | [diff] [blame] | 7435 | MODULE_ALIAS_BLOCKDEV_MAJOR(MD_MAJOR); |