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> |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 39 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/buffer_head.h> /* for invalidate_bdev */ |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 41 | #include <linux/poll.h> |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 42 | #include <linux/ctype.h> |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 43 | #include <linux/string.h> |
NeilBrown | fb4d8c7 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 44 | #include <linux/hdreg.h> |
| 45 | #include <linux/proc_fs.h> |
| 46 | #include <linux/random.h> |
| 47 | #include <linux/reboot.h> |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 48 | #include <linux/file.h> |
Arnd Bergmann | aa98aa3 | 2009-12-14 12:50:05 +1100 | [diff] [blame] | 49 | #include <linux/compat.h> |
Stephen Rothwell | 2557072 | 2008-10-15 09:09:21 +1100 | [diff] [blame] | 50 | #include <linux/delay.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 51 | #include <linux/raid/md_p.h> |
| 52 | #include <linux/raid/md_u.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 53 | #include <linux/slab.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 54 | #include "md.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 55 | #include "bitmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | #define DEBUG 0 |
| 58 | #define dprintk(x...) ((void)(DEBUG && printk(x))) |
| 59 | |
| 60 | |
| 61 | #ifndef MODULE |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 62 | static void autostart_arrays(int part); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #endif |
| 64 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 65 | static LIST_HEAD(pers_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static DEFINE_SPINLOCK(pers_lock); |
| 67 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 68 | static void md_print_devices(void); |
| 69 | |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 70 | static DECLARE_WAIT_QUEUE_HEAD(resync_wait); |
| 71 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 72 | #define MD_BUG(x...) { printk("md: bug in file %s, line %d\n", __FILE__, __LINE__); md_print_devices(); } |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 75 | * Default number of read corrections we'll attempt on an rdev |
| 76 | * before ejecting it from the array. We divide the read error |
| 77 | * count by 2 for every hour elapsed between read errors. |
| 78 | */ |
| 79 | #define MD_DEFAULT_MAX_CORRECTED_READ_ERRORS 20 |
| 80 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | * Current RAID-1,4,5 parallel reconstruction 'guaranteed speed limit' |
| 82 | * is 1000 KB/sec, so the extra system load does not show up that much. |
| 83 | * Increase it if you want to have more _guaranteed_ speed. Note that |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 84 | * the RAID driver will use the maximum available bandwidth if the IO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | * subsystem is idle. There is also an 'absolute maximum' reconstruction |
| 86 | * speed limit - in case reconstruction slows down your system despite |
| 87 | * idle IO detection. |
| 88 | * |
| 89 | * 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] | 90 | * or /sys/block/mdX/md/sync_speed_{min,max} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | */ |
| 92 | |
| 93 | static int sysctl_speed_limit_min = 1000; |
| 94 | static int sysctl_speed_limit_max = 200000; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 95 | static inline int speed_min(mddev_t *mddev) |
| 96 | { |
| 97 | return mddev->sync_speed_min ? |
| 98 | mddev->sync_speed_min : sysctl_speed_limit_min; |
| 99 | } |
| 100 | |
| 101 | static inline int speed_max(mddev_t *mddev) |
| 102 | { |
| 103 | return mddev->sync_speed_max ? |
| 104 | mddev->sync_speed_max : sysctl_speed_limit_max; |
| 105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | static struct ctl_table_header *raid_table_header; |
| 108 | |
| 109 | static ctl_table raid_table[] = { |
| 110 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | .procname = "speed_limit_min", |
| 112 | .data = &sysctl_speed_limit_min, |
| 113 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 114 | .mode = S_IRUGO|S_IWUSR, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 115 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | }, |
| 117 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | .procname = "speed_limit_max", |
| 119 | .data = &sysctl_speed_limit_max, |
| 120 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 121 | .mode = S_IRUGO|S_IWUSR, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 122 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 124 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | static ctl_table raid_dir_table[] = { |
| 128 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | .procname = "raid", |
| 130 | .maxlen = 0, |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 131 | .mode = S_IRUGO|S_IXUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | .child = raid_table, |
| 133 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 134 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | static ctl_table raid_root_table[] = { |
| 138 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | .procname = "dev", |
| 140 | .maxlen = 0, |
| 141 | .mode = 0555, |
| 142 | .child = raid_dir_table, |
| 143 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 144 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 147 | static const struct block_device_operations md_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 149 | static int start_readonly; |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 152 | * We have a system wide 'event count' that is incremented |
| 153 | * on any 'interesting' event, and readers of /proc/mdstat |
| 154 | * can use 'poll' or 'select' to find out when the event |
| 155 | * count increases. |
| 156 | * |
| 157 | * Events are: |
| 158 | * start array, stop array, error, add device, remove device, |
| 159 | * start build, activate spare |
| 160 | */ |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 161 | static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 162 | static atomic_t md_event_count; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 163 | void md_new_event(mddev_t *mddev) |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 164 | { |
| 165 | atomic_inc(&md_event_count); |
| 166 | wake_up(&md_event_waiters); |
| 167 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 168 | EXPORT_SYMBOL_GPL(md_new_event); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 169 | |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 170 | /* Alternate version that can be called from interrupts |
| 171 | * when calling sysfs_notify isn't needed. |
| 172 | */ |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 173 | static void md_new_event_inintr(mddev_t *mddev) |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 174 | { |
| 175 | atomic_inc(&md_event_count); |
| 176 | wake_up(&md_event_waiters); |
| 177 | } |
| 178 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 179 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | * Enables to iterate over all existing md arrays |
| 181 | * all_mddevs_lock protects this list. |
| 182 | */ |
| 183 | static LIST_HEAD(all_mddevs); |
| 184 | static DEFINE_SPINLOCK(all_mddevs_lock); |
| 185 | |
| 186 | |
| 187 | /* |
| 188 | * iterates through all used mddevs in the system. |
| 189 | * We take care to grab the all_mddevs_lock whenever navigating |
| 190 | * the list, and to always hold a refcount when unlocked. |
| 191 | * Any code which breaks out of this loop while own |
| 192 | * a reference to the current mddev and must mddev_put it. |
| 193 | */ |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 194 | #define for_each_mddev(mddev,tmp) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | \ |
| 196 | for (({ spin_lock(&all_mddevs_lock); \ |
| 197 | tmp = all_mddevs.next; \ |
| 198 | mddev = NULL;}); \ |
| 199 | ({ if (tmp != &all_mddevs) \ |
| 200 | mddev_get(list_entry(tmp, mddev_t, all_mddevs));\ |
| 201 | spin_unlock(&all_mddevs_lock); \ |
| 202 | if (mddev) mddev_put(mddev); \ |
| 203 | mddev = list_entry(tmp, mddev_t, all_mddevs); \ |
| 204 | tmp != &all_mddevs;}); \ |
| 205 | ({ spin_lock(&all_mddevs_lock); \ |
| 206 | tmp = tmp->next;}) \ |
| 207 | ) |
| 208 | |
| 209 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 210 | /* Rather than calling directly into the personality make_request function, |
| 211 | * IO requests come here first so that we can check if the device is |
| 212 | * being suspended pending a reconfiguration. |
| 213 | * We hold a refcount over the call to ->make_request. By the time that |
| 214 | * call has finished, the bio has been linked into some internal structure |
| 215 | * and so is visible to ->quiesce(), so we don't need the refcount any more. |
| 216 | */ |
| 217 | static int md_make_request(struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 219 | const int rw = bio_data_dir(bio); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 220 | mddev_t *mddev = q->queuedata; |
| 221 | int rv; |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 222 | int cpu; |
| 223 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 224 | if (mddev == NULL || mddev->pers == NULL) { |
| 225 | bio_io_error(bio); |
| 226 | return 0; |
| 227 | } |
| 228 | rcu_read_lock(); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 229 | if (mddev->suspended || mddev->barrier) { |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 230 | DEFINE_WAIT(__wait); |
| 231 | for (;;) { |
| 232 | prepare_to_wait(&mddev->sb_wait, &__wait, |
| 233 | TASK_UNINTERRUPTIBLE); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 234 | if (!mddev->suspended && !mddev->barrier) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 235 | break; |
| 236 | rcu_read_unlock(); |
| 237 | schedule(); |
| 238 | rcu_read_lock(); |
| 239 | } |
| 240 | finish_wait(&mddev->sb_wait, &__wait); |
| 241 | } |
| 242 | atomic_inc(&mddev->active_io); |
| 243 | rcu_read_unlock(); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 244 | |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 245 | rv = mddev->pers->make_request(mddev, bio); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 246 | |
| 247 | cpu = part_stat_lock(); |
| 248 | part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]); |
| 249 | part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw], |
| 250 | bio_sectors(bio)); |
| 251 | part_stat_unlock(); |
| 252 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 253 | if (atomic_dec_and_test(&mddev->active_io) && mddev->suspended) |
| 254 | wake_up(&mddev->sb_wait); |
| 255 | |
| 256 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
NeilBrown | 9e35b99 | 2010-04-06 14:23:02 +1000 | [diff] [blame] | 259 | /* mddev_suspend makes sure no new requests are submitted |
| 260 | * to the device, and that any requests that have been submitted |
| 261 | * are completely handled. |
| 262 | * Once ->stop is called and completes, the module will be completely |
| 263 | * unused. |
| 264 | */ |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 265 | void mddev_suspend(mddev_t *mddev) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 266 | { |
| 267 | BUG_ON(mddev->suspended); |
| 268 | mddev->suspended = 1; |
| 269 | synchronize_rcu(); |
| 270 | wait_event(mddev->sb_wait, atomic_read(&mddev->active_io) == 0); |
| 271 | mddev->pers->quiesce(mddev, 1); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 272 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 273 | EXPORT_SYMBOL_GPL(mddev_suspend); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 274 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 275 | void mddev_resume(mddev_t *mddev) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 276 | { |
| 277 | mddev->suspended = 0; |
| 278 | wake_up(&mddev->sb_wait); |
| 279 | mddev->pers->quiesce(mddev, 0); |
| 280 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 281 | EXPORT_SYMBOL_GPL(mddev_resume); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 282 | |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 283 | int mddev_congested(mddev_t *mddev, int bits) |
| 284 | { |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 285 | if (mddev->barrier) |
| 286 | return 1; |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 287 | return mddev->suspended; |
| 288 | } |
| 289 | EXPORT_SYMBOL(mddev_congested); |
| 290 | |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 291 | /* |
| 292 | * Generic barrier handling for md |
| 293 | */ |
| 294 | |
| 295 | #define POST_REQUEST_BARRIER ((void*)1) |
| 296 | |
| 297 | static void md_end_barrier(struct bio *bio, int err) |
| 298 | { |
| 299 | mdk_rdev_t *rdev = bio->bi_private; |
| 300 | mddev_t *mddev = rdev->mddev; |
| 301 | if (err == -EOPNOTSUPP && mddev->barrier != POST_REQUEST_BARRIER) |
| 302 | set_bit(BIO_EOPNOTSUPP, &mddev->barrier->bi_flags); |
| 303 | |
| 304 | rdev_dec_pending(rdev, mddev); |
| 305 | |
| 306 | if (atomic_dec_and_test(&mddev->flush_pending)) { |
| 307 | if (mddev->barrier == POST_REQUEST_BARRIER) { |
| 308 | /* This was a post-request barrier */ |
| 309 | mddev->barrier = NULL; |
| 310 | wake_up(&mddev->sb_wait); |
| 311 | } else |
| 312 | /* The pre-request barrier has finished */ |
| 313 | schedule_work(&mddev->barrier_work); |
| 314 | } |
| 315 | bio_put(bio); |
| 316 | } |
| 317 | |
| 318 | static void submit_barriers(mddev_t *mddev) |
| 319 | { |
| 320 | mdk_rdev_t *rdev; |
| 321 | |
| 322 | rcu_read_lock(); |
| 323 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
| 324 | if (rdev->raid_disk >= 0 && |
| 325 | !test_bit(Faulty, &rdev->flags)) { |
| 326 | /* Take two references, one is dropped |
| 327 | * when request finishes, one after |
| 328 | * we reclaim rcu_read_lock |
| 329 | */ |
| 330 | struct bio *bi; |
| 331 | atomic_inc(&rdev->nr_pending); |
| 332 | atomic_inc(&rdev->nr_pending); |
| 333 | rcu_read_unlock(); |
| 334 | bi = bio_alloc(GFP_KERNEL, 0); |
| 335 | bi->bi_end_io = md_end_barrier; |
| 336 | bi->bi_private = rdev; |
| 337 | bi->bi_bdev = rdev->bdev; |
| 338 | atomic_inc(&mddev->flush_pending); |
| 339 | submit_bio(WRITE_BARRIER, bi); |
| 340 | rcu_read_lock(); |
| 341 | rdev_dec_pending(rdev, mddev); |
| 342 | } |
| 343 | rcu_read_unlock(); |
| 344 | } |
| 345 | |
| 346 | static void md_submit_barrier(struct work_struct *ws) |
| 347 | { |
| 348 | mddev_t *mddev = container_of(ws, mddev_t, barrier_work); |
| 349 | struct bio *bio = mddev->barrier; |
| 350 | |
| 351 | atomic_set(&mddev->flush_pending, 1); |
| 352 | |
| 353 | if (test_bit(BIO_EOPNOTSUPP, &bio->bi_flags)) |
| 354 | bio_endio(bio, -EOPNOTSUPP); |
| 355 | else if (bio->bi_size == 0) |
| 356 | /* an empty barrier - all done */ |
| 357 | bio_endio(bio, 0); |
| 358 | else { |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 359 | bio->bi_rw &= ~REQ_HARDBARRIER; |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 360 | if (mddev->pers->make_request(mddev, bio)) |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 361 | generic_make_request(bio); |
| 362 | mddev->barrier = POST_REQUEST_BARRIER; |
| 363 | submit_barriers(mddev); |
| 364 | } |
| 365 | if (atomic_dec_and_test(&mddev->flush_pending)) { |
| 366 | mddev->barrier = NULL; |
| 367 | wake_up(&mddev->sb_wait); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | void md_barrier_request(mddev_t *mddev, struct bio *bio) |
| 372 | { |
| 373 | spin_lock_irq(&mddev->write_lock); |
| 374 | wait_event_lock_irq(mddev->sb_wait, |
| 375 | !mddev->barrier, |
| 376 | mddev->write_lock, /*nothing*/); |
| 377 | mddev->barrier = bio; |
| 378 | spin_unlock_irq(&mddev->write_lock); |
| 379 | |
| 380 | atomic_set(&mddev->flush_pending, 1); |
| 381 | INIT_WORK(&mddev->barrier_work, md_submit_barrier); |
| 382 | |
| 383 | submit_barriers(mddev); |
| 384 | |
| 385 | if (atomic_dec_and_test(&mddev->flush_pending)) |
| 386 | schedule_work(&mddev->barrier_work); |
| 387 | } |
| 388 | EXPORT_SYMBOL(md_barrier_request); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 389 | |
NeilBrown | 2ac8740 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 390 | /* Support for plugging. |
| 391 | * This mirrors the plugging support in request_queue, but does not |
| 392 | * require having a whole queue |
| 393 | */ |
| 394 | static void plugger_work(struct work_struct *work) |
| 395 | { |
| 396 | struct plug_handle *plug = |
| 397 | container_of(work, struct plug_handle, unplug_work); |
| 398 | plug->unplug_fn(plug); |
| 399 | } |
| 400 | static void plugger_timeout(unsigned long data) |
| 401 | { |
| 402 | struct plug_handle *plug = (void *)data; |
| 403 | kblockd_schedule_work(NULL, &plug->unplug_work); |
| 404 | } |
| 405 | void plugger_init(struct plug_handle *plug, |
| 406 | void (*unplug_fn)(struct plug_handle *)) |
| 407 | { |
| 408 | plug->unplug_flag = 0; |
| 409 | plug->unplug_fn = unplug_fn; |
| 410 | init_timer(&plug->unplug_timer); |
| 411 | plug->unplug_timer.function = plugger_timeout; |
| 412 | plug->unplug_timer.data = (unsigned long)plug; |
| 413 | INIT_WORK(&plug->unplug_work, plugger_work); |
| 414 | } |
| 415 | EXPORT_SYMBOL_GPL(plugger_init); |
| 416 | |
| 417 | void plugger_set_plug(struct plug_handle *plug) |
| 418 | { |
| 419 | if (!test_and_set_bit(PLUGGED_FLAG, &plug->unplug_flag)) |
| 420 | mod_timer(&plug->unplug_timer, jiffies + msecs_to_jiffies(3)+1); |
| 421 | } |
| 422 | EXPORT_SYMBOL_GPL(plugger_set_plug); |
| 423 | |
| 424 | int plugger_remove_plug(struct plug_handle *plug) |
| 425 | { |
| 426 | if (test_and_clear_bit(PLUGGED_FLAG, &plug->unplug_flag)) { |
| 427 | del_timer(&plug->unplug_timer); |
| 428 | return 1; |
| 429 | } else |
| 430 | return 0; |
| 431 | } |
| 432 | EXPORT_SYMBOL_GPL(plugger_remove_plug); |
| 433 | |
| 434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | static inline mddev_t *mddev_get(mddev_t *mddev) |
| 436 | { |
| 437 | atomic_inc(&mddev->active); |
| 438 | return mddev; |
| 439 | } |
| 440 | |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 441 | static void mddev_delayed_delete(struct work_struct *ws); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | static void mddev_put(mddev_t *mddev) |
| 444 | { |
| 445 | if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock)) |
| 446 | return; |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 447 | if (!mddev->raid_disks && list_empty(&mddev->disks) && |
NeilBrown | cbd1998 | 2009-12-30 12:08:49 +1100 | [diff] [blame] | 448 | mddev->ctime == 0 && !mddev->hold_active) { |
| 449 | /* Array is not configured at all, and not held active, |
| 450 | * so destroy it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | list_del(&mddev->all_mddevs); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 452 | if (mddev->gendisk) { |
| 453 | /* we did a probe so need to clean up. |
| 454 | * Call schedule_work inside the spinlock |
| 455 | * so that flush_scheduled_work() after |
| 456 | * mddev_find will succeed in waiting for the |
| 457 | * work to be done. |
| 458 | */ |
| 459 | INIT_WORK(&mddev->del_work, mddev_delayed_delete); |
| 460 | schedule_work(&mddev->del_work); |
| 461 | } else |
| 462 | kfree(mddev); |
| 463 | } |
| 464 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 467 | void mddev_init(mddev_t *mddev) |
NeilBrown | fafd7fb | 2010-04-01 15:55:30 +1100 | [diff] [blame] | 468 | { |
| 469 | mutex_init(&mddev->open_mutex); |
| 470 | mutex_init(&mddev->reconfig_mutex); |
| 471 | mutex_init(&mddev->bitmap_info.mutex); |
| 472 | INIT_LIST_HEAD(&mddev->disks); |
| 473 | INIT_LIST_HEAD(&mddev->all_mddevs); |
| 474 | init_timer(&mddev->safemode_timer); |
| 475 | atomic_set(&mddev->active, 1); |
| 476 | atomic_set(&mddev->openers, 0); |
| 477 | atomic_set(&mddev->active_io, 0); |
| 478 | spin_lock_init(&mddev->write_lock); |
| 479 | atomic_set(&mddev->flush_pending, 0); |
| 480 | init_waitqueue_head(&mddev->sb_wait); |
| 481 | init_waitqueue_head(&mddev->recovery_wait); |
| 482 | mddev->reshape_position = MaxSector; |
| 483 | mddev->resync_min = 0; |
| 484 | mddev->resync_max = MaxSector; |
| 485 | mddev->level = LEVEL_NONE; |
| 486 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 487 | EXPORT_SYMBOL_GPL(mddev_init); |
NeilBrown | fafd7fb | 2010-04-01 15:55:30 +1100 | [diff] [blame] | 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | static mddev_t * mddev_find(dev_t unit) |
| 490 | { |
| 491 | mddev_t *mddev, *new = NULL; |
| 492 | |
| 493 | retry: |
| 494 | spin_lock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 496 | if (unit) { |
| 497 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 498 | if (mddev->unit == unit) { |
| 499 | mddev_get(mddev); |
| 500 | spin_unlock(&all_mddevs_lock); |
| 501 | kfree(new); |
| 502 | return mddev; |
| 503 | } |
| 504 | |
| 505 | if (new) { |
| 506 | list_add(&new->all_mddevs, &all_mddevs); |
| 507 | spin_unlock(&all_mddevs_lock); |
| 508 | new->hold_active = UNTIL_IOCTL; |
| 509 | return new; |
| 510 | } |
| 511 | } else if (new) { |
| 512 | /* find an unused unit number */ |
| 513 | static int next_minor = 512; |
| 514 | int start = next_minor; |
| 515 | int is_free = 0; |
| 516 | int dev = 0; |
| 517 | while (!is_free) { |
| 518 | dev = MKDEV(MD_MAJOR, next_minor); |
| 519 | next_minor++; |
| 520 | if (next_minor > MINORMASK) |
| 521 | next_minor = 0; |
| 522 | if (next_minor == start) { |
| 523 | /* Oh dear, all in use. */ |
| 524 | spin_unlock(&all_mddevs_lock); |
| 525 | kfree(new); |
| 526 | return NULL; |
| 527 | } |
| 528 | |
| 529 | is_free = 1; |
| 530 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 531 | if (mddev->unit == dev) { |
| 532 | is_free = 0; |
| 533 | break; |
| 534 | } |
| 535 | } |
| 536 | new->unit = dev; |
| 537 | new->md_minor = MINOR(dev); |
| 538 | new->hold_active = UNTIL_STOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | list_add(&new->all_mddevs, &all_mddevs); |
| 540 | spin_unlock(&all_mddevs_lock); |
| 541 | return new; |
| 542 | } |
| 543 | spin_unlock(&all_mddevs_lock); |
| 544 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 545 | new = kzalloc(sizeof(*new), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | if (!new) |
| 547 | return NULL; |
| 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | new->unit = unit; |
| 550 | if (MAJOR(unit) == MD_MAJOR) |
| 551 | new->md_minor = MINOR(unit); |
| 552 | else |
| 553 | new->md_minor = MINOR(unit) >> MdpMinorShift; |
| 554 | |
NeilBrown | fafd7fb | 2010-04-01 15:55:30 +1100 | [diff] [blame] | 555 | mddev_init(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | goto retry; |
| 558 | } |
| 559 | |
| 560 | static inline int mddev_lock(mddev_t * mddev) |
| 561 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 562 | return mutex_lock_interruptible(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 565 | static inline int mddev_is_locked(mddev_t *mddev) |
| 566 | { |
| 567 | return mutex_is_locked(&mddev->reconfig_mutex); |
| 568 | } |
| 569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | static inline int mddev_trylock(mddev_t * mddev) |
| 571 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 572 | return mutex_trylock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 575 | static struct attribute_group md_redundancy_group; |
| 576 | |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 577 | static void mddev_unlock(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 579 | if (mddev->to_remove) { |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 580 | /* These cannot be removed under reconfig_mutex as |
| 581 | * an access to the files will try to take reconfig_mutex |
| 582 | * while holding the file unremovable, which leads to |
| 583 | * a deadlock. |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 584 | * So hold set sysfs_active while the remove in happeing, |
| 585 | * and anything else which might set ->to_remove or my |
| 586 | * otherwise change the sysfs namespace will fail with |
| 587 | * -EBUSY if sysfs_active is still set. |
| 588 | * We set sysfs_active under reconfig_mutex and elsewhere |
| 589 | * test it under the same mutex to ensure its correct value |
| 590 | * is seen. |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 591 | */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 592 | struct attribute_group *to_remove = mddev->to_remove; |
| 593 | mddev->to_remove = NULL; |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 594 | mddev->sysfs_active = 1; |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 595 | mutex_unlock(&mddev->reconfig_mutex); |
| 596 | |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 597 | if (mddev->kobj.sd) { |
| 598 | if (to_remove != &md_redundancy_group) |
| 599 | sysfs_remove_group(&mddev->kobj, to_remove); |
| 600 | if (mddev->pers == NULL || |
| 601 | mddev->pers->sync_request == NULL) { |
| 602 | sysfs_remove_group(&mddev->kobj, &md_redundancy_group); |
| 603 | if (mddev->sysfs_action) |
| 604 | sysfs_put(mddev->sysfs_action); |
| 605 | mddev->sysfs_action = NULL; |
| 606 | } |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 607 | } |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 608 | mddev->sysfs_active = 0; |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 609 | } else |
| 610 | mutex_unlock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 612 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 615 | static mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 617 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 619 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | if (rdev->desc_nr == nr) |
| 621 | return rdev; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | return NULL; |
| 624 | } |
| 625 | |
| 626 | static mdk_rdev_t * find_rdev(mddev_t * mddev, dev_t dev) |
| 627 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | mdk_rdev_t *rdev; |
| 629 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 630 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | if (rdev->bdev->bd_dev == dev) |
| 632 | return rdev; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | return NULL; |
| 635 | } |
| 636 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 637 | static struct mdk_personality *find_pers(int level, char *clevel) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 638 | { |
| 639 | struct mdk_personality *pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 640 | list_for_each_entry(pers, &pers_list, list) { |
| 641 | if (level != LEVEL_NONE && pers->level == level) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 642 | return pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 643 | if (strcmp(pers->name, clevel)==0) |
| 644 | return pers; |
| 645 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 646 | return NULL; |
| 647 | } |
| 648 | |
Andre Noll | b73df2d | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 649 | /* return the offset of the super block in 512byte sectors */ |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 650 | static inline sector_t calc_dev_sboffset(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
Andre Noll | b73df2d | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 652 | sector_t num_sectors = bdev->bd_inode->i_size / 512; |
| 653 | return MD_NEW_SIZE_SECTORS(num_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | static int alloc_disk_sb(mdk_rdev_t * rdev) |
| 657 | { |
| 658 | if (rdev->sb_page) |
| 659 | MD_BUG(); |
| 660 | |
| 661 | rdev->sb_page = alloc_page(GFP_KERNEL); |
| 662 | if (!rdev->sb_page) { |
| 663 | printk(KERN_ALERT "md: out of memory.\n"); |
Andre Noll | ebc2433 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 664 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | static void free_disk_sb(mdk_rdev_t * rdev) |
| 671 | { |
| 672 | if (rdev->sb_page) { |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 673 | put_page(rdev->sb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | rdev->sb_loaded = 0; |
| 675 | rdev->sb_page = NULL; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 676 | rdev->sb_start = 0; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 677 | rdev->sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
| 681 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 682 | static void super_written(struct bio *bio, int error) |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 683 | { |
| 684 | mdk_rdev_t *rdev = bio->bi_private; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 685 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 686 | |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 687 | if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) { |
| 688 | printk("md: super_written gets error=%d, uptodate=%d\n", |
| 689 | error, test_bit(BIO_UPTODATE, &bio->bi_flags)); |
| 690 | WARN_ON(test_bit(BIO_UPTODATE, &bio->bi_flags)); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 691 | md_error(mddev, rdev); |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 692 | } |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 693 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 694 | if (atomic_dec_and_test(&mddev->pending_writes)) |
| 695 | wake_up(&mddev->sb_wait); |
Neil Brown | f8b58ed | 2005-06-27 22:29:34 -0700 | [diff] [blame] | 696 | bio_put(bio); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 697 | } |
| 698 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 699 | static void super_written_barrier(struct bio *bio, int error) |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 700 | { |
| 701 | struct bio *bio2 = bio->bi_private; |
| 702 | mdk_rdev_t *rdev = bio2->bi_private; |
| 703 | mddev_t *mddev = rdev->mddev; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 704 | |
| 705 | if (!test_bit(BIO_UPTODATE, &bio->bi_flags) && |
| 706 | error == -EOPNOTSUPP) { |
| 707 | unsigned long flags; |
| 708 | /* barriers don't appear to be supported :-( */ |
| 709 | set_bit(BarriersNotsupp, &rdev->flags); |
| 710 | mddev->barriers_work = 0; |
| 711 | spin_lock_irqsave(&mddev->write_lock, flags); |
| 712 | bio2->bi_next = mddev->biolist; |
| 713 | mddev->biolist = bio2; |
| 714 | spin_unlock_irqrestore(&mddev->write_lock, flags); |
| 715 | wake_up(&mddev->sb_wait); |
| 716 | bio_put(bio); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 717 | } else { |
| 718 | bio_put(bio2); |
| 719 | bio->bi_private = rdev; |
| 720 | super_written(bio, error); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 721 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 722 | } |
| 723 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 724 | void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev, |
| 725 | sector_t sector, int size, struct page *page) |
| 726 | { |
| 727 | /* write first size bytes of page to sector of rdev |
| 728 | * Increment mddev->pending_writes before returning |
| 729 | * and decrement it on completion, waking up sb_wait |
| 730 | * if zero is reached. |
| 731 | * If an error occurred, call md_error |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 732 | * |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 733 | * As we might need to resubmit the request if REQ_HARDBARRIER |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 734 | * causes ENOTSUPP, we allocate a spare bio... |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 735 | */ |
| 736 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 737 | int rw = REQ_WRITE | REQ_SYNC | REQ_UNPLUG; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 738 | |
| 739 | bio->bi_bdev = rdev->bdev; |
| 740 | bio->bi_sector = sector; |
| 741 | bio_add_page(bio, page, size, 0); |
| 742 | bio->bi_private = rdev; |
| 743 | bio->bi_end_io = super_written; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 744 | bio->bi_rw = rw; |
| 745 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 746 | atomic_inc(&mddev->pending_writes); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 747 | if (!test_bit(BarriersNotsupp, &rdev->flags)) { |
| 748 | struct bio *rbio; |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 749 | rw |= REQ_HARDBARRIER; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 750 | rbio = bio_clone(bio, GFP_NOIO); |
| 751 | rbio->bi_private = bio; |
| 752 | rbio->bi_end_io = super_written_barrier; |
| 753 | submit_bio(rw, rbio); |
| 754 | } else |
| 755 | submit_bio(rw, bio); |
| 756 | } |
| 757 | |
| 758 | void md_super_wait(mddev_t *mddev) |
| 759 | { |
| 760 | /* wait for all superblock writes that were scheduled to complete. |
| 761 | * if any had to be retried (due to BARRIER problems), retry them |
| 762 | */ |
| 763 | DEFINE_WAIT(wq); |
| 764 | for(;;) { |
| 765 | prepare_to_wait(&mddev->sb_wait, &wq, TASK_UNINTERRUPTIBLE); |
| 766 | if (atomic_read(&mddev->pending_writes)==0) |
| 767 | break; |
| 768 | while (mddev->biolist) { |
| 769 | struct bio *bio; |
| 770 | spin_lock_irq(&mddev->write_lock); |
| 771 | bio = mddev->biolist; |
| 772 | mddev->biolist = bio->bi_next ; |
| 773 | bio->bi_next = NULL; |
| 774 | spin_unlock_irq(&mddev->write_lock); |
| 775 | submit_bio(bio->bi_rw, bio); |
| 776 | } |
| 777 | schedule(); |
| 778 | } |
| 779 | finish_wait(&mddev->sb_wait, &wq); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 780 | } |
| 781 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 782 | static void bi_complete(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | complete((struct completion*)bio->bi_private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } |
| 786 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 787 | 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] | 788 | struct page *page, int rw) |
| 789 | { |
Neil Brown | baaa2c5 | 2005-04-16 15:23:54 -0700 | [diff] [blame] | 790 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | struct completion event; |
| 792 | int ret; |
| 793 | |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 794 | rw |= REQ_SYNC | REQ_UNPLUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | bio->bi_bdev = bdev; |
| 797 | bio->bi_sector = sector; |
| 798 | bio_add_page(bio, page, size, 0); |
| 799 | init_completion(&event); |
| 800 | bio->bi_private = &event; |
| 801 | bio->bi_end_io = bi_complete; |
| 802 | submit_bio(rw, bio); |
| 803 | wait_for_completion(&event); |
| 804 | |
| 805 | ret = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 806 | bio_put(bio); |
| 807 | return ret; |
| 808 | } |
NeilBrown | a8745db | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 809 | EXPORT_SYMBOL_GPL(sync_page_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 811 | static int read_disk_sb(mdk_rdev_t * rdev, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | { |
| 813 | char b[BDEVNAME_SIZE]; |
| 814 | if (!rdev->sb_page) { |
| 815 | MD_BUG(); |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | if (rdev->sb_loaded) |
| 819 | return 0; |
| 820 | |
| 821 | |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 822 | 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] | 823 | goto fail; |
| 824 | rdev->sb_loaded = 1; |
| 825 | return 0; |
| 826 | |
| 827 | fail: |
| 828 | printk(KERN_WARNING "md: disabled device %s, could not read superblock.\n", |
| 829 | bdevname(rdev->bdev,b)); |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | |
| 833 | static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 834 | { |
Andre Noll | 0571046 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 835 | return sb1->set_uuid0 == sb2->set_uuid0 && |
| 836 | sb1->set_uuid1 == sb2->set_uuid1 && |
| 837 | sb1->set_uuid2 == sb2->set_uuid2 && |
| 838 | sb1->set_uuid3 == sb2->set_uuid3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 842 | { |
| 843 | int ret; |
| 844 | mdp_super_t *tmp1, *tmp2; |
| 845 | |
| 846 | tmp1 = kmalloc(sizeof(*tmp1),GFP_KERNEL); |
| 847 | tmp2 = kmalloc(sizeof(*tmp2),GFP_KERNEL); |
| 848 | |
| 849 | if (!tmp1 || !tmp2) { |
| 850 | ret = 0; |
Andre Noll | 35020f1 | 2008-03-23 15:10:33 +0100 | [diff] [blame] | 851 | printk(KERN_INFO "md.c sb_equal(): failed to allocate memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | goto abort; |
| 853 | } |
| 854 | |
| 855 | *tmp1 = *sb1; |
| 856 | *tmp2 = *sb2; |
| 857 | |
| 858 | /* |
| 859 | * nr_disks is not constant |
| 860 | */ |
| 861 | tmp1->nr_disks = 0; |
| 862 | tmp2->nr_disks = 0; |
| 863 | |
Andre Noll | ce0c8e0 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 864 | ret = (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | abort: |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 866 | kfree(tmp1); |
| 867 | kfree(tmp2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | return ret; |
| 869 | } |
| 870 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 871 | |
| 872 | static u32 md_csum_fold(u32 csum) |
| 873 | { |
| 874 | csum = (csum & 0xffff) + (csum >> 16); |
| 875 | return (csum & 0xffff) + (csum >> 16); |
| 876 | } |
| 877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | static unsigned int calc_sb_csum(mdp_super_t * sb) |
| 879 | { |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 880 | u64 newcsum = 0; |
| 881 | u32 *sb32 = (u32*)sb; |
| 882 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | unsigned int disk_csum, csum; |
| 884 | |
| 885 | disk_csum = sb->sb_csum; |
| 886 | sb->sb_csum = 0; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 887 | |
| 888 | for (i = 0; i < MD_SB_BYTES/4 ; i++) |
| 889 | newcsum += sb32[i]; |
| 890 | csum = (newcsum & 0xffffffff) + (newcsum>>32); |
| 891 | |
| 892 | |
| 893 | #ifdef CONFIG_ALPHA |
| 894 | /* This used to use csum_partial, which was wrong for several |
| 895 | * reasons including that different results are returned on |
| 896 | * different architectures. It isn't critical that we get exactly |
| 897 | * the same return value as before (we always csum_fold before |
| 898 | * testing, and that removes any differences). However as we |
| 899 | * know that csum_partial always returned a 16bit value on |
| 900 | * alphas, do a fold to maximise conformity to previous behaviour. |
| 901 | */ |
| 902 | sb->sb_csum = md_csum_fold(disk_csum); |
| 903 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | sb->sb_csum = disk_csum; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 905 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | return csum; |
| 907 | } |
| 908 | |
| 909 | |
| 910 | /* |
| 911 | * Handle superblock details. |
| 912 | * We want to be able to handle multiple superblock formats |
| 913 | * so we have a common interface to them all, and an array of |
| 914 | * different handlers. |
| 915 | * We rely on user-space to write the initial superblock, and support |
| 916 | * reading and updating of superblocks. |
| 917 | * Interface methods are: |
| 918 | * int load_super(mdk_rdev_t *dev, mdk_rdev_t *refdev, int minor_version) |
| 919 | * loads and validates a superblock on dev. |
| 920 | * if refdev != NULL, compare superblocks on both devices |
| 921 | * Return: |
| 922 | * 0 - dev has a superblock that is compatible with refdev |
| 923 | * 1 - dev has a superblock that is compatible and newer than refdev |
| 924 | * so dev should be used as the refdev in future |
| 925 | * -EINVAL superblock incompatible or invalid |
| 926 | * -othererror e.g. -EIO |
| 927 | * |
| 928 | * int validate_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 929 | * Verify that dev is acceptable into mddev. |
| 930 | * The first time, mddev->raid_disks will be 0, and data from |
| 931 | * dev should be merged in. Subsequent calls check that dev |
| 932 | * is new enough. Return 0 or -EINVAL |
| 933 | * |
| 934 | * void sync_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 935 | * Update the superblock for rdev with data in mddev |
| 936 | * This does not write to disc. |
| 937 | * |
| 938 | */ |
| 939 | |
| 940 | struct super_type { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 941 | char *name; |
| 942 | struct module *owner; |
| 943 | int (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev, |
| 944 | int minor_version); |
| 945 | int (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 946 | void (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 947 | unsigned long long (*rdev_size_change)(mdk_rdev_t *rdev, |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 948 | sector_t num_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | }; |
| 950 | |
| 951 | /* |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 952 | * Check that the given mddev has no bitmap. |
| 953 | * |
| 954 | * This function is called from the run method of all personalities that do not |
| 955 | * support bitmaps. It prints an error message and returns non-zero if mddev |
| 956 | * has a bitmap. Otherwise, it returns 0. |
| 957 | * |
| 958 | */ |
| 959 | int md_check_no_bitmap(mddev_t *mddev) |
| 960 | { |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 961 | if (!mddev->bitmap_info.file && !mddev->bitmap_info.offset) |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 962 | return 0; |
| 963 | printk(KERN_ERR "%s: bitmaps are not supported for %s\n", |
| 964 | mdname(mddev), mddev->pers->name); |
| 965 | return 1; |
| 966 | } |
| 967 | EXPORT_SYMBOL(md_check_no_bitmap); |
| 968 | |
| 969 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | * load_super for 0.90.0 |
| 971 | */ |
| 972 | static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 973 | { |
| 974 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 975 | mdp_super_t *sb; |
| 976 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
| 978 | /* |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 979 | * Calculate the position of the superblock (512byte sectors), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | * it's at the end of the disk. |
| 981 | * |
| 982 | * It also happens to be a multiple of 4Kb. |
| 983 | */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 984 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 986 | ret = read_disk_sb(rdev, MD_SB_BYTES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | if (ret) return ret; |
| 988 | |
| 989 | ret = -EINVAL; |
| 990 | |
| 991 | bdevname(rdev->bdev, b); |
| 992 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 993 | |
| 994 | if (sb->md_magic != MD_SB_MAGIC) { |
| 995 | printk(KERN_ERR "md: invalid raid superblock magic on %s\n", |
| 996 | b); |
| 997 | goto abort; |
| 998 | } |
| 999 | |
| 1000 | if (sb->major_version != 0 || |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1001 | sb->minor_version < 90 || |
| 1002 | sb->minor_version > 91) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | printk(KERN_WARNING "Bad version number %d.%d on %s\n", |
| 1004 | sb->major_version, sb->minor_version, |
| 1005 | b); |
| 1006 | goto abort; |
| 1007 | } |
| 1008 | |
| 1009 | if (sb->raid_disks <= 0) |
| 1010 | goto abort; |
| 1011 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 1012 | 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] | 1013 | printk(KERN_WARNING "md: invalid superblock checksum on %s\n", |
| 1014 | b); |
| 1015 | goto abort; |
| 1016 | } |
| 1017 | |
| 1018 | rdev->preferred_minor = sb->md_minor; |
| 1019 | rdev->data_offset = 0; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1020 | rdev->sb_size = MD_SB_BYTES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
| 1022 | if (sb->level == LEVEL_MULTIPATH) |
| 1023 | rdev->desc_nr = -1; |
| 1024 | else |
| 1025 | rdev->desc_nr = sb->this_disk.number; |
| 1026 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1027 | if (!refdev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1029 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | __u64 ev1, ev2; |
| 1031 | mdp_super_t *refsb = (mdp_super_t*)page_address(refdev->sb_page); |
| 1032 | if (!uuid_equal(refsb, sb)) { |
| 1033 | printk(KERN_WARNING "md: %s has different UUID to %s\n", |
| 1034 | b, bdevname(refdev->bdev,b2)); |
| 1035 | goto abort; |
| 1036 | } |
| 1037 | if (!sb_equal(refsb, sb)) { |
| 1038 | printk(KERN_WARNING "md: %s has same UUID" |
| 1039 | " but different superblock to %s\n", |
| 1040 | b, bdevname(refdev->bdev, b2)); |
| 1041 | goto abort; |
| 1042 | } |
| 1043 | ev1 = md_event(sb); |
| 1044 | ev2 = md_event(refsb); |
| 1045 | if (ev1 > ev2) |
| 1046 | ret = 1; |
| 1047 | else |
| 1048 | ret = 0; |
| 1049 | } |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 1050 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1052 | if (rdev->sectors < sb->size * 2 && sb->level > 1) |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1053 | /* "this cannot possibly happen" ... */ |
| 1054 | ret = -EINVAL; |
| 1055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | abort: |
| 1057 | return ret; |
| 1058 | } |
| 1059 | |
| 1060 | /* |
| 1061 | * validate_super for 0.90.0 |
| 1062 | */ |
| 1063 | static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1064 | { |
| 1065 | mdp_disk_t *desc; |
| 1066 | mdp_super_t *sb = (mdp_super_t *)page_address(rdev->sb_page); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1067 | __u64 ev1 = md_event(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1069 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1070 | clear_bit(Faulty, &rdev->flags); |
| 1071 | clear_bit(In_sync, &rdev->flags); |
| 1072 | clear_bit(WriteMostly, &rdev->flags); |
| 1073 | clear_bit(BarriersNotsupp, &rdev->flags); |
| 1074 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | if (mddev->raid_disks == 0) { |
| 1076 | mddev->major_version = 0; |
| 1077 | mddev->minor_version = sb->minor_version; |
| 1078 | mddev->patch_version = sb->patch_version; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1079 | mddev->external = 0; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1080 | mddev->chunk_sectors = sb->chunk_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | mddev->ctime = sb->ctime; |
| 1082 | mddev->utime = sb->utime; |
| 1083 | mddev->level = sb->level; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 1084 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | mddev->layout = sb->layout; |
| 1086 | mddev->raid_disks = sb->raid_disks; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1087 | mddev->dev_sectors = sb->size * 2; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1088 | mddev->events = ev1; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1089 | mddev->bitmap_info.offset = 0; |
| 1090 | mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1092 | if (mddev->minor_version >= 91) { |
| 1093 | mddev->reshape_position = sb->reshape_position; |
| 1094 | mddev->delta_disks = sb->delta_disks; |
| 1095 | mddev->new_level = sb->new_level; |
| 1096 | mddev->new_layout = sb->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1097 | mddev->new_chunk_sectors = sb->new_chunk >> 9; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1098 | } else { |
| 1099 | mddev->reshape_position = MaxSector; |
| 1100 | mddev->delta_disks = 0; |
| 1101 | mddev->new_level = mddev->level; |
| 1102 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1103 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1104 | } |
| 1105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | if (sb->state & (1<<MD_SB_CLEAN)) |
| 1107 | mddev->recovery_cp = MaxSector; |
| 1108 | else { |
| 1109 | if (sb->events_hi == sb->cp_events_hi && |
| 1110 | sb->events_lo == sb->cp_events_lo) { |
| 1111 | mddev->recovery_cp = sb->recovery_cp; |
| 1112 | } else |
| 1113 | mddev->recovery_cp = 0; |
| 1114 | } |
| 1115 | |
| 1116 | memcpy(mddev->uuid+0, &sb->set_uuid0, 4); |
| 1117 | memcpy(mddev->uuid+4, &sb->set_uuid1, 4); |
| 1118 | memcpy(mddev->uuid+8, &sb->set_uuid2, 4); |
| 1119 | memcpy(mddev->uuid+12,&sb->set_uuid3, 4); |
| 1120 | |
| 1121 | mddev->max_disks = MD_SB_DISKS; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1122 | |
| 1123 | if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1124 | mddev->bitmap_info.file == NULL) |
| 1125 | mddev->bitmap_info.offset = |
| 1126 | mddev->bitmap_info.default_offset; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1127 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1128 | } else if (mddev->pers == NULL) { |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1129 | /* Insist on good event counter while assembling, except |
| 1130 | * for spares (which don't need an event count) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | ++ev1; |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1132 | if (sb->disks[rdev->desc_nr].state & ( |
| 1133 | (1<<MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE))) |
| 1134 | if (ev1 < mddev->events) |
| 1135 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1136 | } else if (mddev->bitmap) { |
| 1137 | /* if adding to array with a bitmap, then we can accept an |
| 1138 | * older device ... but not too old. |
| 1139 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1140 | if (ev1 < mddev->bitmap->events_cleared) |
| 1141 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1142 | } else { |
| 1143 | if (ev1 < mddev->events) |
| 1144 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1145 | return 0; |
| 1146 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | if (mddev->level != LEVEL_MULTIPATH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | desc = sb->disks + rdev->desc_nr; |
| 1150 | |
| 1151 | if (desc->state & (1<<MD_DISK_FAULTY)) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1152 | set_bit(Faulty, &rdev->flags); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 1153 | else if (desc->state & (1<<MD_DISK_SYNC) /* && |
| 1154 | desc->raid_disk < mddev->raid_disks */) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1155 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | rdev->raid_disk = desc->raid_disk; |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1157 | } else if (desc->state & (1<<MD_DISK_ACTIVE)) { |
| 1158 | /* active but not in sync implies recovery up to |
| 1159 | * reshape position. We don't know exactly where |
| 1160 | * that is, so set to zero for now */ |
| 1161 | if (mddev->minor_version >= 91) { |
| 1162 | rdev->recovery_offset = 0; |
| 1163 | rdev->raid_disk = desc->raid_disk; |
| 1164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1166 | if (desc->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 1167 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1168 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1169 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | /* |
| 1174 | * sync_super for 0.90.0 |
| 1175 | */ |
| 1176 | static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1177 | { |
| 1178 | mdp_super_t *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | mdk_rdev_t *rdev2; |
| 1180 | int next_spare = mddev->raid_disks; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | |
| 1183 | /* make rdev->sb match mddev data.. |
| 1184 | * |
| 1185 | * 1/ zero out disks |
| 1186 | * 2/ Add info for each disk, keeping track of highest desc_nr (next_spare); |
| 1187 | * 3/ any empty disks < next_spare become removed |
| 1188 | * |
| 1189 | * disks[0] gets initialised to REMOVED because |
| 1190 | * we cannot be sure from other fields if it has |
| 1191 | * been initialised or not. |
| 1192 | */ |
| 1193 | int i; |
| 1194 | int active=0, working=0,failed=0,spare=0,nr_disks=0; |
| 1195 | |
NeilBrown | 6118156 | 2005-09-09 16:24:02 -0700 | [diff] [blame] | 1196 | rdev->sb_size = MD_SB_BYTES; |
| 1197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 1199 | |
| 1200 | memset(sb, 0, sizeof(*sb)); |
| 1201 | |
| 1202 | sb->md_magic = MD_SB_MAGIC; |
| 1203 | sb->major_version = mddev->major_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | sb->patch_version = mddev->patch_version; |
| 1205 | sb->gvalid_words = 0; /* ignored */ |
| 1206 | memcpy(&sb->set_uuid0, mddev->uuid+0, 4); |
| 1207 | memcpy(&sb->set_uuid1, mddev->uuid+4, 4); |
| 1208 | memcpy(&sb->set_uuid2, mddev->uuid+8, 4); |
| 1209 | memcpy(&sb->set_uuid3, mddev->uuid+12,4); |
| 1210 | |
| 1211 | sb->ctime = mddev->ctime; |
| 1212 | sb->level = mddev->level; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1213 | sb->size = mddev->dev_sectors / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | sb->raid_disks = mddev->raid_disks; |
| 1215 | sb->md_minor = mddev->md_minor; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1216 | sb->not_persistent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | sb->utime = mddev->utime; |
| 1218 | sb->state = 0; |
| 1219 | sb->events_hi = (mddev->events>>32); |
| 1220 | sb->events_lo = (u32)mddev->events; |
| 1221 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1222 | if (mddev->reshape_position == MaxSector) |
| 1223 | sb->minor_version = 90; |
| 1224 | else { |
| 1225 | sb->minor_version = 91; |
| 1226 | sb->reshape_position = mddev->reshape_position; |
| 1227 | sb->new_level = mddev->new_level; |
| 1228 | sb->delta_disks = mddev->delta_disks; |
| 1229 | sb->new_layout = mddev->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1230 | sb->new_chunk = mddev->new_chunk_sectors << 9; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1231 | } |
| 1232 | mddev->minor_version = sb->minor_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | if (mddev->in_sync) |
| 1234 | { |
| 1235 | sb->recovery_cp = mddev->recovery_cp; |
| 1236 | sb->cp_events_hi = (mddev->events>>32); |
| 1237 | sb->cp_events_lo = (u32)mddev->events; |
| 1238 | if (mddev->recovery_cp == MaxSector) |
| 1239 | sb->state = (1<< MD_SB_CLEAN); |
| 1240 | } else |
| 1241 | sb->recovery_cp = 0; |
| 1242 | |
| 1243 | sb->layout = mddev->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1244 | sb->chunk_size = mddev->chunk_sectors << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1246 | if (mddev->bitmap && mddev->bitmap_info.file == NULL) |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1247 | sb->state |= (1<<MD_SB_BITMAP_PRESENT); |
| 1248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | sb->disks[0].state = (1<<MD_DISK_REMOVED); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1250 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | mdp_disk_t *d; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1252 | int desc_nr; |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1253 | int is_active = test_bit(In_sync, &rdev2->flags); |
| 1254 | |
| 1255 | if (rdev2->raid_disk >= 0 && |
| 1256 | sb->minor_version >= 91) |
| 1257 | /* we have nowhere to store the recovery_offset, |
| 1258 | * but if it is not below the reshape_position, |
| 1259 | * we can piggy-back on that. |
| 1260 | */ |
| 1261 | is_active = 1; |
| 1262 | if (rdev2->raid_disk < 0 || |
| 1263 | test_bit(Faulty, &rdev2->flags)) |
| 1264 | is_active = 0; |
| 1265 | if (is_active) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1266 | desc_nr = rdev2->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | else |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1268 | desc_nr = next_spare++; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1269 | rdev2->desc_nr = desc_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | d = &sb->disks[rdev2->desc_nr]; |
| 1271 | nr_disks++; |
| 1272 | d->number = rdev2->desc_nr; |
| 1273 | d->major = MAJOR(rdev2->bdev->bd_dev); |
| 1274 | d->minor = MINOR(rdev2->bdev->bd_dev); |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1275 | if (is_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | d->raid_disk = rdev2->raid_disk; |
| 1277 | else |
| 1278 | d->raid_disk = rdev2->desc_nr; /* compatibility */ |
NeilBrown | 1be7892 | 2006-03-27 01:18:03 -0800 | [diff] [blame] | 1279 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | d->state = (1<<MD_DISK_FAULTY); |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1281 | else if (is_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | d->state = (1<<MD_DISK_ACTIVE); |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1283 | if (test_bit(In_sync, &rdev2->flags)) |
| 1284 | d->state |= (1<<MD_DISK_SYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | active++; |
| 1286 | working++; |
| 1287 | } else { |
| 1288 | d->state = 0; |
| 1289 | spare++; |
| 1290 | working++; |
| 1291 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1292 | if (test_bit(WriteMostly, &rdev2->flags)) |
| 1293 | d->state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | /* now set the "removed" and "faulty" bits on any missing devices */ |
| 1296 | for (i=0 ; i < mddev->raid_disks ; i++) { |
| 1297 | mdp_disk_t *d = &sb->disks[i]; |
| 1298 | if (d->state == 0 && d->number == 0) { |
| 1299 | d->number = i; |
| 1300 | d->raid_disk = i; |
| 1301 | d->state = (1<<MD_DISK_REMOVED); |
| 1302 | d->state |= (1<<MD_DISK_FAULTY); |
| 1303 | failed++; |
| 1304 | } |
| 1305 | } |
| 1306 | sb->nr_disks = nr_disks; |
| 1307 | sb->active_disks = active; |
| 1308 | sb->working_disks = working; |
| 1309 | sb->failed_disks = failed; |
| 1310 | sb->spare_disks = spare; |
| 1311 | |
| 1312 | sb->this_disk = sb->disks[rdev->desc_nr]; |
| 1313 | sb->sb_csum = calc_sb_csum(sb); |
| 1314 | } |
| 1315 | |
| 1316 | /* |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1317 | * rdev_size_change for 0.90.0 |
| 1318 | */ |
| 1319 | static unsigned long long |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1320 | 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] | 1321 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1322 | if (num_sectors && num_sectors < rdev->mddev->dev_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1323 | return 0; /* component must fit device */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1324 | if (rdev->mddev->bitmap_info.offset) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1325 | return 0; /* can't move bitmap */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1326 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1327 | if (!num_sectors || num_sectors > rdev->sb_start) |
| 1328 | num_sectors = rdev->sb_start; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1329 | md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1330 | rdev->sb_page); |
| 1331 | md_super_wait(rdev->mddev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1332 | return num_sectors / 2; /* kB for sysfs */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | |
| 1336 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | * version 1 superblock |
| 1338 | */ |
| 1339 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1340 | static __le32 calc_sb_1_csum(struct mdp_superblock_1 * sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | { |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1342 | __le32 disk_csum; |
| 1343 | u32 csum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | unsigned long long newcsum; |
| 1345 | int size = 256 + le32_to_cpu(sb->max_dev)*2; |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1346 | __le32 *isuper = (__le32*)sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | int i; |
| 1348 | |
| 1349 | disk_csum = sb->sb_csum; |
| 1350 | sb->sb_csum = 0; |
| 1351 | newcsum = 0; |
| 1352 | for (i=0; size>=4; size -= 4 ) |
| 1353 | newcsum += le32_to_cpu(*isuper++); |
| 1354 | |
| 1355 | if (size == 2) |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1356 | newcsum += le16_to_cpu(*(__le16*) isuper); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | |
| 1358 | csum = (newcsum & 0xffffffff) + (newcsum >> 32); |
| 1359 | sb->sb_csum = disk_csum; |
| 1360 | return cpu_to_le32(csum); |
| 1361 | } |
| 1362 | |
| 1363 | static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 1364 | { |
| 1365 | struct mdp_superblock_1 *sb; |
| 1366 | int ret; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1367 | sector_t sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1369 | int bmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
| 1371 | /* |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1372 | * Calculate the position of the superblock in 512byte sectors. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | * It is always aligned to a 4K boundary and |
| 1374 | * depeding on minor_version, it can be: |
| 1375 | * 0: At least 8K, but less than 12K, from end of device |
| 1376 | * 1: At start of device |
| 1377 | * 2: 4K from start of device. |
| 1378 | */ |
| 1379 | switch(minor_version) { |
| 1380 | case 0: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1381 | sb_start = rdev->bdev->bd_inode->i_size >> 9; |
| 1382 | sb_start -= 8*2; |
| 1383 | sb_start &= ~(sector_t)(4*2-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | break; |
| 1385 | case 1: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1386 | sb_start = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | break; |
| 1388 | case 2: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1389 | sb_start = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | break; |
| 1391 | default: |
| 1392 | return -EINVAL; |
| 1393 | } |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1394 | rdev->sb_start = sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1396 | /* superblock is rarely larger than 1K, but it can be larger, |
| 1397 | * and it is safe to read 4k, so we do that |
| 1398 | */ |
| 1399 | ret = read_disk_sb(rdev, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | if (ret) return ret; |
| 1401 | |
| 1402 | |
| 1403 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1404 | |
| 1405 | if (sb->magic != cpu_to_le32(MD_SB_MAGIC) || |
| 1406 | sb->major_version != cpu_to_le32(1) || |
| 1407 | le32_to_cpu(sb->max_dev) > (4096-256)/2 || |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1408 | le64_to_cpu(sb->super_offset) != rdev->sb_start || |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1409 | (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | return -EINVAL; |
| 1411 | |
| 1412 | if (calc_sb_1_csum(sb) != sb->sb_csum) { |
| 1413 | printk("md: invalid superblock checksum on %s\n", |
| 1414 | bdevname(rdev->bdev,b)); |
| 1415 | return -EINVAL; |
| 1416 | } |
| 1417 | if (le64_to_cpu(sb->data_size) < 10) { |
| 1418 | printk("md: data_size too small on %s\n", |
| 1419 | bdevname(rdev->bdev,b)); |
| 1420 | return -EINVAL; |
| 1421 | } |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | rdev->preferred_minor = 0xffff; |
| 1424 | rdev->data_offset = le64_to_cpu(sb->data_offset); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1425 | atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1427 | rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256; |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 1428 | bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1429 | if (rdev->sb_size & bmask) |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1430 | rdev->sb_size = (rdev->sb_size | bmask) + 1; |
| 1431 | |
| 1432 | if (minor_version |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1433 | && rdev->data_offset < sb_start + (rdev->sb_size/512)) |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1434 | return -EINVAL; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1435 | |
NeilBrown | 31b65a0 | 2006-07-10 04:44:14 -0700 | [diff] [blame] | 1436 | if (sb->level == cpu_to_le32(LEVEL_MULTIPATH)) |
| 1437 | rdev->desc_nr = -1; |
| 1438 | else |
| 1439 | rdev->desc_nr = le32_to_cpu(sb->dev_number); |
| 1440 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1441 | if (!refdev) { |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1442 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1443 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | __u64 ev1, ev2; |
| 1445 | struct mdp_superblock_1 *refsb = |
| 1446 | (struct mdp_superblock_1*)page_address(refdev->sb_page); |
| 1447 | |
| 1448 | if (memcmp(sb->set_uuid, refsb->set_uuid, 16) != 0 || |
| 1449 | sb->level != refsb->level || |
| 1450 | sb->layout != refsb->layout || |
| 1451 | sb->chunksize != refsb->chunksize) { |
| 1452 | printk(KERN_WARNING "md: %s has strangely different" |
| 1453 | " superblock to %s\n", |
| 1454 | bdevname(rdev->bdev,b), |
| 1455 | bdevname(refdev->bdev,b2)); |
| 1456 | return -EINVAL; |
| 1457 | } |
| 1458 | ev1 = le64_to_cpu(sb->events); |
| 1459 | ev2 = le64_to_cpu(refsb->events); |
| 1460 | |
| 1461 | if (ev1 > ev2) |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1462 | ret = 1; |
| 1463 | else |
| 1464 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | } |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1466 | if (minor_version) |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1467 | rdev->sectors = (rdev->bdev->bd_inode->i_size >> 9) - |
| 1468 | le64_to_cpu(sb->data_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | else |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1470 | rdev->sectors = rdev->sb_start; |
| 1471 | if (rdev->sectors < le64_to_cpu(sb->data_size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | return -EINVAL; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1473 | rdev->sectors = le64_to_cpu(sb->data_size); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1474 | if (le64_to_cpu(sb->size) > rdev->sectors) |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1475 | return -EINVAL; |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1476 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1480 | { |
| 1481 | 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] | 1482 | __u64 ev1 = le64_to_cpu(sb->events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1484 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1485 | clear_bit(Faulty, &rdev->flags); |
| 1486 | clear_bit(In_sync, &rdev->flags); |
| 1487 | clear_bit(WriteMostly, &rdev->flags); |
| 1488 | clear_bit(BarriersNotsupp, &rdev->flags); |
| 1489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | if (mddev->raid_disks == 0) { |
| 1491 | mddev->major_version = 1; |
| 1492 | mddev->patch_version = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1493 | mddev->external = 0; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1494 | mddev->chunk_sectors = le32_to_cpu(sb->chunksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | mddev->ctime = le64_to_cpu(sb->ctime) & ((1ULL << 32)-1); |
| 1496 | mddev->utime = le64_to_cpu(sb->utime) & ((1ULL << 32)-1); |
| 1497 | mddev->level = le32_to_cpu(sb->level); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 1498 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | mddev->layout = le32_to_cpu(sb->layout); |
| 1500 | mddev->raid_disks = le32_to_cpu(sb->raid_disks); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1501 | mddev->dev_sectors = le64_to_cpu(sb->size); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1502 | mddev->events = ev1; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1503 | mddev->bitmap_info.offset = 0; |
| 1504 | mddev->bitmap_info.default_offset = 1024 >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
| 1506 | mddev->recovery_cp = le64_to_cpu(sb->resync_offset); |
| 1507 | memcpy(mddev->uuid, sb->set_uuid, 16); |
| 1508 | |
| 1509 | mddev->max_disks = (4096-256)/2; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1510 | |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1511 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1512 | mddev->bitmap_info.file == NULL ) |
| 1513 | mddev->bitmap_info.offset = |
| 1514 | (__s32)le32_to_cpu(sb->bitmap_offset); |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1515 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1516 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) { |
| 1517 | mddev->reshape_position = le64_to_cpu(sb->reshape_position); |
| 1518 | mddev->delta_disks = le32_to_cpu(sb->delta_disks); |
| 1519 | mddev->new_level = le32_to_cpu(sb->new_level); |
| 1520 | mddev->new_layout = le32_to_cpu(sb->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1521 | mddev->new_chunk_sectors = le32_to_cpu(sb->new_chunk); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1522 | } else { |
| 1523 | mddev->reshape_position = MaxSector; |
| 1524 | mddev->delta_disks = 0; |
| 1525 | mddev->new_level = mddev->level; |
| 1526 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1527 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1528 | } |
| 1529 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1530 | } else if (mddev->pers == NULL) { |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1531 | /* Insist of good event counter while assembling, except for |
| 1532 | * spares (which don't need an event count) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | ++ev1; |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1534 | if (rdev->desc_nr >= 0 && |
| 1535 | rdev->desc_nr < le32_to_cpu(sb->max_dev) && |
| 1536 | le16_to_cpu(sb->dev_roles[rdev->desc_nr]) < 0xfffe) |
| 1537 | if (ev1 < mddev->events) |
| 1538 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1539 | } else if (mddev->bitmap) { |
| 1540 | /* If adding to array with a bitmap, then we can accept an |
| 1541 | * older device, but not too old. |
| 1542 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1543 | if (ev1 < mddev->bitmap->events_cleared) |
| 1544 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1545 | } else { |
| 1546 | if (ev1 < mddev->events) |
| 1547 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1548 | return 0; |
| 1549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | if (mddev->level != LEVEL_MULTIPATH) { |
| 1551 | int role; |
NeilBrown | 3673f30 | 2009-08-03 10:59:56 +1000 | [diff] [blame] | 1552 | if (rdev->desc_nr < 0 || |
| 1553 | rdev->desc_nr >= le32_to_cpu(sb->max_dev)) { |
| 1554 | role = 0xffff; |
| 1555 | rdev->desc_nr = -1; |
| 1556 | } else |
| 1557 | role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | switch(role) { |
| 1559 | case 0xffff: /* spare */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | break; |
| 1561 | case 0xfffe: /* faulty */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1562 | set_bit(Faulty, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | break; |
| 1564 | default: |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1565 | if ((le32_to_cpu(sb->feature_map) & |
| 1566 | MD_FEATURE_RECOVERY_OFFSET)) |
| 1567 | rdev->recovery_offset = le64_to_cpu(sb->recovery_offset); |
| 1568 | else |
| 1569 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | rdev->raid_disk = role; |
| 1571 | break; |
| 1572 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1573 | if (sb->devflags & WriteMostly1) |
| 1574 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1575 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1576 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | return 0; |
| 1579 | } |
| 1580 | |
| 1581 | static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1582 | { |
| 1583 | struct mdp_superblock_1 *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | mdk_rdev_t *rdev2; |
| 1585 | int max_dev, i; |
| 1586 | /* make rdev->sb match mddev and rdev data. */ |
| 1587 | |
| 1588 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1589 | |
| 1590 | sb->feature_map = 0; |
| 1591 | sb->pad0 = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1592 | sb->recovery_offset = cpu_to_le64(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | memset(sb->pad1, 0, sizeof(sb->pad1)); |
| 1594 | memset(sb->pad2, 0, sizeof(sb->pad2)); |
| 1595 | memset(sb->pad3, 0, sizeof(sb->pad3)); |
| 1596 | |
| 1597 | sb->utime = cpu_to_le64((__u64)mddev->utime); |
| 1598 | sb->events = cpu_to_le64(mddev->events); |
| 1599 | if (mddev->in_sync) |
| 1600 | sb->resync_offset = cpu_to_le64(mddev->recovery_cp); |
| 1601 | else |
| 1602 | sb->resync_offset = cpu_to_le64(0); |
| 1603 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1604 | sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors)); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1605 | |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1606 | sb->raid_disks = cpu_to_le32(mddev->raid_disks); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1607 | sb->size = cpu_to_le64(mddev->dev_sectors); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1608 | sb->chunksize = cpu_to_le32(mddev->chunk_sectors); |
NeilBrown | 62e1e38 | 2009-05-26 09:40:59 +1000 | [diff] [blame] | 1609 | sb->level = cpu_to_le32(mddev->level); |
| 1610 | sb->layout = cpu_to_le32(mddev->layout); |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1611 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1612 | if (mddev->bitmap && mddev->bitmap_info.file == NULL) { |
| 1613 | sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_info.offset); |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1614 | sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1615 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1616 | |
| 1617 | if (rdev->raid_disk >= 0 && |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1618 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 93be75f | 2009-12-14 12:50:06 +1100 | [diff] [blame] | 1619 | sb->feature_map |= |
| 1620 | cpu_to_le32(MD_FEATURE_RECOVERY_OFFSET); |
| 1621 | sb->recovery_offset = |
| 1622 | cpu_to_le64(rdev->recovery_offset); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1625 | if (mddev->reshape_position != MaxSector) { |
| 1626 | sb->feature_map |= cpu_to_le32(MD_FEATURE_RESHAPE_ACTIVE); |
| 1627 | sb->reshape_position = cpu_to_le64(mddev->reshape_position); |
| 1628 | sb->new_layout = cpu_to_le32(mddev->new_layout); |
| 1629 | sb->delta_disks = cpu_to_le32(mddev->delta_disks); |
| 1630 | sb->new_level = cpu_to_le32(mddev->new_level); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1631 | sb->new_chunk = cpu_to_le32(mddev->new_chunk_sectors); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1632 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | max_dev = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1635 | list_for_each_entry(rdev2, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | if (rdev2->desc_nr+1 > max_dev) |
| 1637 | max_dev = rdev2->desc_nr+1; |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1638 | |
NeilBrown | 70471da | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 1639 | if (max_dev > le32_to_cpu(sb->max_dev)) { |
| 1640 | int bmask; |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1641 | sb->max_dev = cpu_to_le32(max_dev); |
NeilBrown | 70471da | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 1642 | rdev->sb_size = max_dev * 2 + 256; |
| 1643 | bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1; |
| 1644 | if (rdev->sb_size & bmask) |
| 1645 | rdev->sb_size = (rdev->sb_size | bmask) + 1; |
| 1646 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | for (i=0; i<max_dev;i++) |
| 1648 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
| 1649 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1650 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | i = rdev2->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1652 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1654 | else if (test_bit(In_sync, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
NeilBrown | 93be75f | 2009-12-14 12:50:06 +1100 | [diff] [blame] | 1656 | else if (rdev2->raid_disk >= 0) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1657 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | else |
| 1659 | sb->dev_roles[i] = cpu_to_le16(0xffff); |
| 1660 | } |
| 1661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | sb->sb_csum = calc_sb_1_csum(sb); |
| 1663 | } |
| 1664 | |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1665 | static unsigned long long |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1666 | 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] | 1667 | { |
| 1668 | struct mdp_superblock_1 *sb; |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1669 | sector_t max_sectors; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1670 | if (num_sectors && num_sectors < rdev->mddev->dev_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1671 | return 0; /* component must fit device */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1672 | if (rdev->sb_start < rdev->data_offset) { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1673 | /* minor versions 1 and 2; superblock before data */ |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1674 | max_sectors = rdev->bdev->bd_inode->i_size >> 9; |
| 1675 | max_sectors -= rdev->data_offset; |
| 1676 | if (!num_sectors || num_sectors > max_sectors) |
| 1677 | num_sectors = max_sectors; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1678 | } else if (rdev->mddev->bitmap_info.offset) { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1679 | /* minor version 0 with bitmap we can't move */ |
| 1680 | return 0; |
| 1681 | } else { |
| 1682 | /* minor version 0; superblock after data */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1683 | sector_t sb_start; |
| 1684 | sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2; |
| 1685 | sb_start &= ~(sector_t)(4*2 - 1); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1686 | max_sectors = rdev->sectors + sb_start - rdev->sb_start; |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1687 | if (!num_sectors || num_sectors > max_sectors) |
| 1688 | num_sectors = max_sectors; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1689 | rdev->sb_start = sb_start; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1690 | } |
| 1691 | sb = (struct mdp_superblock_1 *) page_address(rdev->sb_page); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1692 | sb->data_size = cpu_to_le64(num_sectors); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1693 | sb->super_offset = rdev->sb_start; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1694 | sb->sb_csum = calc_sb_1_csum(sb); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1695 | md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1696 | rdev->sb_page); |
| 1697 | md_super_wait(rdev->mddev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1698 | return num_sectors / 2; /* kB for sysfs */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1699 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 1701 | static struct super_type super_types[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | [0] = { |
| 1703 | .name = "0.90.0", |
| 1704 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1705 | .load_super = super_90_load, |
| 1706 | .validate_super = super_90_validate, |
| 1707 | .sync_super = super_90_sync, |
| 1708 | .rdev_size_change = super_90_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | }, |
| 1710 | [1] = { |
| 1711 | .name = "md-1", |
| 1712 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1713 | .load_super = super_1_load, |
| 1714 | .validate_super = super_1_validate, |
| 1715 | .sync_super = super_1_sync, |
| 1716 | .rdev_size_change = super_1_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | }, |
| 1718 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | |
| 1720 | static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2) |
| 1721 | { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1722 | mdk_rdev_t *rdev, *rdev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1724 | rcu_read_lock(); |
| 1725 | rdev_for_each_rcu(rdev, mddev1) |
| 1726 | rdev_for_each_rcu(rdev2, mddev2) |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1727 | if (rdev->bdev->bd_contains == |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1728 | rdev2->bdev->bd_contains) { |
| 1729 | rcu_read_unlock(); |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1730 | return 1; |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1731 | } |
| 1732 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | return 0; |
| 1734 | } |
| 1735 | |
| 1736 | static LIST_HEAD(pending_raid_disks); |
| 1737 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1738 | /* |
| 1739 | * Try to register data integrity profile for an mddev |
| 1740 | * |
| 1741 | * This is called when an array is started and after a disk has been kicked |
| 1742 | * from the array. It only succeeds if all working and active component devices |
| 1743 | * are integrity capable with matching profiles. |
| 1744 | */ |
| 1745 | int md_integrity_register(mddev_t *mddev) |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1746 | { |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1747 | mdk_rdev_t *rdev, *reference = NULL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1748 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1749 | if (list_empty(&mddev->disks)) |
| 1750 | return 0; /* nothing to do */ |
| 1751 | if (blk_get_integrity(mddev->gendisk)) |
| 1752 | return 0; /* already registered */ |
| 1753 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 1754 | /* skip spares and non-functional disks */ |
| 1755 | if (test_bit(Faulty, &rdev->flags)) |
| 1756 | continue; |
| 1757 | if (rdev->raid_disk < 0) |
| 1758 | continue; |
| 1759 | /* |
| 1760 | * If at least one rdev is not integrity capable, we can not |
| 1761 | * enable data integrity for the md device. |
| 1762 | */ |
| 1763 | if (!bdev_get_integrity(rdev->bdev)) |
| 1764 | return -EINVAL; |
| 1765 | if (!reference) { |
| 1766 | /* Use the first rdev as the reference */ |
| 1767 | reference = rdev; |
| 1768 | continue; |
| 1769 | } |
| 1770 | /* does this rdev's profile match the reference profile? */ |
| 1771 | if (blk_integrity_compare(reference->bdev->bd_disk, |
| 1772 | rdev->bdev->bd_disk) < 0) |
| 1773 | return -EINVAL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1774 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1775 | /* |
| 1776 | * All component devices are integrity capable and have matching |
| 1777 | * profiles, register the common profile for the md device. |
| 1778 | */ |
| 1779 | if (blk_integrity_register(mddev->gendisk, |
| 1780 | bdev_get_integrity(reference->bdev)) != 0) { |
| 1781 | printk(KERN_ERR "md: failed to register integrity for %s\n", |
| 1782 | mdname(mddev)); |
| 1783 | return -EINVAL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1784 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1785 | printk(KERN_NOTICE "md: data integrity on %s enabled\n", |
| 1786 | mdname(mddev)); |
| 1787 | return 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1788 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1789 | EXPORT_SYMBOL(md_integrity_register); |
| 1790 | |
| 1791 | /* Disable data integrity if non-capable/non-matching disk is being added */ |
| 1792 | void md_integrity_add_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 1793 | { |
| 1794 | struct blk_integrity *bi_rdev = bdev_get_integrity(rdev->bdev); |
| 1795 | struct blk_integrity *bi_mddev = blk_get_integrity(mddev->gendisk); |
| 1796 | |
| 1797 | if (!bi_mddev) /* nothing to do */ |
| 1798 | return; |
| 1799 | if (rdev->raid_disk < 0) /* skip spares */ |
| 1800 | return; |
| 1801 | if (bi_rdev && blk_integrity_compare(mddev->gendisk, |
| 1802 | rdev->bdev->bd_disk) >= 0) |
| 1803 | return; |
| 1804 | printk(KERN_NOTICE "disabling data integrity on %s\n", mdname(mddev)); |
| 1805 | blk_integrity_unregister(mddev->gendisk); |
| 1806 | } |
| 1807 | EXPORT_SYMBOL(md_integrity_add_rdev); |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) |
| 1810 | { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1811 | char b[BDEVNAME_SIZE]; |
NeilBrown | f637b9f | 2005-11-08 21:39:37 -0800 | [diff] [blame] | 1812 | struct kobject *ko; |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1813 | char *s; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1814 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | |
| 1816 | if (rdev->mddev) { |
| 1817 | MD_BUG(); |
| 1818 | return -EINVAL; |
| 1819 | } |
Dan Williams | 11e2ede | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1820 | |
| 1821 | /* prevent duplicates */ |
| 1822 | if (find_rdev(mddev, rdev->bdev->bd_dev)) |
| 1823 | return -EEXIST; |
| 1824 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1825 | /* make sure rdev->sectors exceeds mddev->dev_sectors */ |
| 1826 | if (rdev->sectors && (mddev->dev_sectors == 0 || |
| 1827 | rdev->sectors < mddev->dev_sectors)) { |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1828 | if (mddev->pers) { |
| 1829 | /* Cannot change size, so fail |
| 1830 | * If mddev->level <= 0, then we don't care |
| 1831 | * about aligning sizes (e.g. linear) |
| 1832 | */ |
| 1833 | if (mddev->level > 0) |
| 1834 | return -ENOSPC; |
| 1835 | } else |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1836 | mddev->dev_sectors = rdev->sectors; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1837 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | |
| 1839 | /* Verify rdev->desc_nr is unique. |
| 1840 | * If it is -1, assign a free number, else |
| 1841 | * check number is not in use |
| 1842 | */ |
| 1843 | if (rdev->desc_nr < 0) { |
| 1844 | int choice = 0; |
| 1845 | if (mddev->pers) choice = mddev->raid_disks; |
| 1846 | while (find_rdev_nr(mddev, choice)) |
| 1847 | choice++; |
| 1848 | rdev->desc_nr = choice; |
| 1849 | } else { |
| 1850 | if (find_rdev_nr(mddev, rdev->desc_nr)) |
| 1851 | return -EBUSY; |
| 1852 | } |
NeilBrown | de01dfa | 2009-02-06 18:02:46 +1100 | [diff] [blame] | 1853 | if (mddev->max_disks && rdev->desc_nr >= mddev->max_disks) { |
| 1854 | printk(KERN_WARNING "md: %s: array is limited to %d devices\n", |
| 1855 | mdname(mddev), mddev->max_disks); |
| 1856 | return -EBUSY; |
| 1857 | } |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1858 | bdevname(rdev->bdev,b); |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1859 | while ( (s=strchr(b, '/')) != NULL) |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1860 | *s = '!'; |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | rdev->mddev = mddev; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1863 | printk(KERN_INFO "md: bind<%s>\n", b); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1864 | |
Greg Kroah-Hartman | b2d6db5 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1865 | if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b))) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1866 | goto fail; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1867 | |
Tejun Heo | 0762b8b | 2008-08-25 19:56:12 +0900 | [diff] [blame] | 1868 | ko = &part_to_dev(rdev->bdev->bd_part)->kobj; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 1869 | if (sysfs_create_link(&rdev->kobj, ko, "block")) |
| 1870 | /* failure here is OK */; |
| 1871 | rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state"); |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 1872 | |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1873 | list_add_rcu(&rdev->same_set, &mddev->disks); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1874 | bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); |
NeilBrown | 4044ba5 | 2009-01-09 08:31:11 +1100 | [diff] [blame] | 1875 | |
| 1876 | /* May as well allow recovery to be retried once */ |
| 1877 | mddev->recovery_disabled = 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | return 0; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1880 | |
| 1881 | fail: |
| 1882 | printk(KERN_WARNING "md: failed to register dev-%s for %s\n", |
| 1883 | b, mdname(mddev)); |
| 1884 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1887 | static void md_delayed_delete(struct work_struct *ws) |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1888 | { |
| 1889 | mdk_rdev_t *rdev = container_of(ws, mdk_rdev_t, del_work); |
| 1890 | kobject_del(&rdev->kobj); |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1891 | kobject_put(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | static void unbind_rdev_from_array(mdk_rdev_t * rdev) |
| 1895 | { |
| 1896 | char b[BDEVNAME_SIZE]; |
| 1897 | if (!rdev->mddev) { |
| 1898 | MD_BUG(); |
| 1899 | return; |
| 1900 | } |
Jun'ichi Nomura | 5463c79 | 2006-03-27 01:17:58 -0800 | [diff] [blame] | 1901 | bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk); |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1902 | list_del_rcu(&rdev->same_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); |
| 1904 | rdev->mddev = NULL; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1905 | sysfs_remove_link(&rdev->kobj, "block"); |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 1906 | sysfs_put(rdev->sysfs_state); |
| 1907 | rdev->sysfs_state = NULL; |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1908 | /* We need to delay this, otherwise we can deadlock when |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1909 | * writing to 'remove' to "dev/state". We also need |
| 1910 | * to delay it due to rcu usage. |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1911 | */ |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1912 | synchronize_rcu(); |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1913 | INIT_WORK(&rdev->del_work, md_delayed_delete); |
| 1914 | kobject_get(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1915 | schedule_work(&rdev->del_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | /* |
| 1919 | * prevent the device from being mounted, repartitioned or |
| 1920 | * otherwise reused by a RAID array (or any other kernel |
| 1921 | * subsystem), by bd_claiming the device. |
| 1922 | */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1923 | 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] | 1924 | { |
| 1925 | int err = 0; |
| 1926 | struct block_device *bdev; |
| 1927 | char b[BDEVNAME_SIZE]; |
| 1928 | |
Peter Zijlstra | 2e7b651 | 2006-12-08 02:36:13 -0800 | [diff] [blame] | 1929 | bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | if (IS_ERR(bdev)) { |
| 1931 | printk(KERN_ERR "md: could not open %s.\n", |
| 1932 | __bdevname(dev, b)); |
| 1933 | return PTR_ERR(bdev); |
| 1934 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1935 | err = bd_claim(bdev, shared ? (mdk_rdev_t *)lock_rdev : rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | if (err) { |
| 1937 | printk(KERN_ERR "md: could not bd_claim %s.\n", |
| 1938 | bdevname(bdev, b)); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 1939 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | return err; |
| 1941 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1942 | if (!shared) |
| 1943 | set_bit(AllReserved, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | rdev->bdev = bdev; |
| 1945 | return err; |
| 1946 | } |
| 1947 | |
| 1948 | static void unlock_rdev(mdk_rdev_t *rdev) |
| 1949 | { |
| 1950 | struct block_device *bdev = rdev->bdev; |
| 1951 | rdev->bdev = NULL; |
| 1952 | if (!bdev) |
| 1953 | MD_BUG(); |
| 1954 | bd_release(bdev); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 1955 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | void md_autodetect_dev(dev_t dev); |
| 1959 | |
| 1960 | static void export_rdev(mdk_rdev_t * rdev) |
| 1961 | { |
| 1962 | char b[BDEVNAME_SIZE]; |
| 1963 | printk(KERN_INFO "md: export_rdev(%s)\n", |
| 1964 | bdevname(rdev->bdev,b)); |
| 1965 | if (rdev->mddev) |
| 1966 | MD_BUG(); |
| 1967 | free_disk_sb(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | #ifndef MODULE |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1969 | if (test_bit(AutoDetected, &rdev->flags)) |
| 1970 | md_autodetect_dev(rdev->bdev->bd_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | #endif |
| 1972 | unlock_rdev(rdev); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1973 | kobject_put(&rdev->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | static void kick_rdev_from_array(mdk_rdev_t * rdev) |
| 1977 | { |
| 1978 | unbind_rdev_from_array(rdev); |
| 1979 | export_rdev(rdev); |
| 1980 | } |
| 1981 | |
| 1982 | static void export_array(mddev_t *mddev) |
| 1983 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1984 | mdk_rdev_t *rdev, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1986 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | if (!rdev->mddev) { |
| 1988 | MD_BUG(); |
| 1989 | continue; |
| 1990 | } |
| 1991 | kick_rdev_from_array(rdev); |
| 1992 | } |
| 1993 | if (!list_empty(&mddev->disks)) |
| 1994 | MD_BUG(); |
| 1995 | mddev->raid_disks = 0; |
| 1996 | mddev->major_version = 0; |
| 1997 | } |
| 1998 | |
| 1999 | static void print_desc(mdp_disk_t *desc) |
| 2000 | { |
| 2001 | printk(" DISK<N:%d,(%d,%d),R:%d,S:%d>\n", desc->number, |
| 2002 | desc->major,desc->minor,desc->raid_disk,desc->state); |
| 2003 | } |
| 2004 | |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2005 | static void print_sb_90(mdp_super_t *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | { |
| 2007 | int i; |
| 2008 | |
| 2009 | printk(KERN_INFO |
| 2010 | "md: SB: (V:%d.%d.%d) ID:<%08x.%08x.%08x.%08x> CT:%08x\n", |
| 2011 | sb->major_version, sb->minor_version, sb->patch_version, |
| 2012 | sb->set_uuid0, sb->set_uuid1, sb->set_uuid2, sb->set_uuid3, |
| 2013 | sb->ctime); |
| 2014 | printk(KERN_INFO "md: L%d S%08d ND:%d RD:%d md%d LO:%d CS:%d\n", |
| 2015 | sb->level, sb->size, sb->nr_disks, sb->raid_disks, |
| 2016 | sb->md_minor, sb->layout, sb->chunk_size); |
| 2017 | printk(KERN_INFO "md: UT:%08x ST:%d AD:%d WD:%d" |
| 2018 | " FD:%d SD:%d CSUM:%08x E:%08lx\n", |
| 2019 | sb->utime, sb->state, sb->active_disks, sb->working_disks, |
| 2020 | sb->failed_disks, sb->spare_disks, |
| 2021 | sb->sb_csum, (unsigned long)sb->events_lo); |
| 2022 | |
| 2023 | printk(KERN_INFO); |
| 2024 | for (i = 0; i < MD_SB_DISKS; i++) { |
| 2025 | mdp_disk_t *desc; |
| 2026 | |
| 2027 | desc = sb->disks + i; |
| 2028 | if (desc->number || desc->major || desc->minor || |
| 2029 | desc->raid_disk || (desc->state && (desc->state != 4))) { |
| 2030 | printk(" D %2d: ", i); |
| 2031 | print_desc(desc); |
| 2032 | } |
| 2033 | } |
| 2034 | printk(KERN_INFO "md: THIS: "); |
| 2035 | print_desc(&sb->this_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2038 | static void print_sb_1(struct mdp_superblock_1 *sb) |
| 2039 | { |
| 2040 | __u8 *uuid; |
| 2041 | |
| 2042 | uuid = sb->set_uuid; |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 2043 | printk(KERN_INFO |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 2044 | "md: SB: (V:%u) (F:0x%08x) Array-ID:<%pU>\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 2045 | "md: Name: \"%s\" CT:%llu\n", |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2046 | le32_to_cpu(sb->major_version), |
| 2047 | le32_to_cpu(sb->feature_map), |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 2048 | uuid, |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2049 | sb->set_name, |
| 2050 | (unsigned long long)le64_to_cpu(sb->ctime) |
| 2051 | & MD_SUPERBLOCK_1_TIME_SEC_MASK); |
| 2052 | |
| 2053 | uuid = sb->device_uuid; |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 2054 | printk(KERN_INFO |
| 2055 | "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] | 2056 | " RO:%llu\n" |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 2057 | "md: Dev:%08x UUID: %pU\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 2058 | "md: (F:0x%08x) UT:%llu Events:%llu ResyncOffset:%llu CSUM:0x%08x\n" |
| 2059 | "md: (MaxDev:%u) \n", |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2060 | le32_to_cpu(sb->level), |
| 2061 | (unsigned long long)le64_to_cpu(sb->size), |
| 2062 | le32_to_cpu(sb->raid_disks), |
| 2063 | le32_to_cpu(sb->layout), |
| 2064 | le32_to_cpu(sb->chunksize), |
| 2065 | (unsigned long long)le64_to_cpu(sb->data_offset), |
| 2066 | (unsigned long long)le64_to_cpu(sb->data_size), |
| 2067 | (unsigned long long)le64_to_cpu(sb->super_offset), |
| 2068 | (unsigned long long)le64_to_cpu(sb->recovery_offset), |
| 2069 | le32_to_cpu(sb->dev_number), |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 2070 | uuid, |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2071 | sb->devflags, |
| 2072 | (unsigned long long)le64_to_cpu(sb->utime) & MD_SUPERBLOCK_1_TIME_SEC_MASK, |
| 2073 | (unsigned long long)le64_to_cpu(sb->events), |
| 2074 | (unsigned long long)le64_to_cpu(sb->resync_offset), |
| 2075 | le32_to_cpu(sb->sb_csum), |
| 2076 | le32_to_cpu(sb->max_dev) |
| 2077 | ); |
| 2078 | } |
| 2079 | |
| 2080 | static void print_rdev(mdk_rdev_t *rdev, int major_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | { |
| 2082 | char b[BDEVNAME_SIZE]; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2083 | printk(KERN_INFO "md: rdev %s, Sect:%08llu F:%d S:%d DN:%u\n", |
| 2084 | bdevname(rdev->bdev, b), (unsigned long long)rdev->sectors, |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2085 | test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags), |
| 2086 | rdev->desc_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | if (rdev->sb_loaded) { |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2088 | printk(KERN_INFO "md: rdev superblock (MJ:%d):\n", major_version); |
| 2089 | switch (major_version) { |
| 2090 | case 0: |
| 2091 | print_sb_90((mdp_super_t*)page_address(rdev->sb_page)); |
| 2092 | break; |
| 2093 | case 1: |
| 2094 | print_sb_1((struct mdp_superblock_1 *)page_address(rdev->sb_page)); |
| 2095 | break; |
| 2096 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | } else |
| 2098 | printk(KERN_INFO "md: no rdev superblock!\n"); |
| 2099 | } |
| 2100 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 2101 | static void md_print_devices(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2103 | struct list_head *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | mdk_rdev_t *rdev; |
| 2105 | mddev_t *mddev; |
| 2106 | char b[BDEVNAME_SIZE]; |
| 2107 | |
| 2108 | printk("\n"); |
| 2109 | printk("md: **********************************\n"); |
| 2110 | printk("md: * <COMPLETE RAID STATE PRINTOUT> *\n"); |
| 2111 | printk("md: **********************************\n"); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 2112 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 2114 | if (mddev->bitmap) |
| 2115 | bitmap_print_sb(mddev->bitmap); |
| 2116 | else |
| 2117 | printk("%s: ", mdname(mddev)); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2118 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 2120 | printk("\n"); |
| 2121 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2122 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2123 | print_rdev(rdev, mddev->major_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | } |
| 2125 | printk("md: **********************************\n"); |
| 2126 | printk("\n"); |
| 2127 | } |
| 2128 | |
| 2129 | |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2130 | static void sync_sbs(mddev_t * mddev, int nospares) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2132 | /* Update each superblock (in-memory image), but |
| 2133 | * if we are allowed to, skip spares which already |
| 2134 | * have the right event counter, or have one earlier |
| 2135 | * (which would mean they aren't being marked as dirty |
| 2136 | * with the rest of the array) |
| 2137 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | |
NeilBrown | 5e86510 | 2009-11-12 12:08:04 +1100 | [diff] [blame] | 2140 | /* First make sure individual recovery_offsets are correct */ |
| 2141 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 2142 | if (rdev->raid_disk >= 0 && |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 2143 | mddev->delta_disks >= 0 && |
NeilBrown | 5e86510 | 2009-11-12 12:08:04 +1100 | [diff] [blame] | 2144 | !test_bit(In_sync, &rdev->flags) && |
| 2145 | mddev->curr_resync_completed > rdev->recovery_offset) |
| 2146 | rdev->recovery_offset = mddev->curr_resync_completed; |
| 2147 | |
| 2148 | } |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2149 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2150 | if (rdev->sb_events == mddev->events || |
| 2151 | (nospares && |
| 2152 | rdev->raid_disk < 0 && |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2153 | rdev->sb_events+1 == mddev->events)) { |
| 2154 | /* Don't update this superblock */ |
| 2155 | rdev->sb_loaded = 2; |
| 2156 | } else { |
| 2157 | super_types[mddev->major_version]. |
| 2158 | sync_super(mddev, rdev); |
| 2159 | rdev->sb_loaded = 1; |
| 2160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | } |
| 2162 | } |
| 2163 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2164 | static void md_update_sb(mddev_t * mddev, int force_change) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | mdk_rdev_t *rdev; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2167 | int sync_req; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2168 | int nospares = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | |
NeilBrown | 1b57f13 | 2009-06-18 08:48:19 +1000 | [diff] [blame] | 2170 | mddev->utime = get_seconds(); |
NeilBrown | 8377bc8 | 2008-04-30 00:52:28 -0700 | [diff] [blame] | 2171 | if (mddev->external) |
| 2172 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | repeat: |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2174 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2175 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2176 | set_bit(MD_CHANGE_PENDING, &mddev->flags); |
| 2177 | if (test_and_clear_bit(MD_CHANGE_DEVS, &mddev->flags)) |
| 2178 | force_change = 1; |
| 2179 | if (test_and_clear_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 2180 | /* just a clean<-> dirty transition, possibly leave spares alone, |
| 2181 | * though if events isn't the right even/odd, we will have to do |
| 2182 | * spares after all |
| 2183 | */ |
| 2184 | nospares = 1; |
| 2185 | if (force_change) |
| 2186 | nospares = 0; |
| 2187 | if (mddev->degraded) |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2188 | /* If the array is degraded, then skipping spares is both |
| 2189 | * dangerous and fairly pointless. |
| 2190 | * Dangerous because a device that was removed from the array |
| 2191 | * might have a event_count that still looks up-to-date, |
| 2192 | * so it can be re-added without a resync. |
| 2193 | * Pointless because if there are any spares to skip, |
| 2194 | * then a recovery will happen and soon that array won't |
| 2195 | * be degraded any more and the spare can go back to sleep then. |
| 2196 | */ |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2197 | nospares = 0; |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2198 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2199 | sync_req = mddev->in_sync; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2200 | |
| 2201 | /* If this is just a dirty<->clean transition, and the array is clean |
| 2202 | * and 'events' is odd, we can roll back to the previous clean state */ |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2203 | if (nospares |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2204 | && (mddev->in_sync && mddev->recovery_cp == MaxSector) |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 2205 | && mddev->can_decrease_events |
| 2206 | && mddev->events != 1) { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2207 | mddev->events--; |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 2208 | mddev->can_decrease_events = 0; |
| 2209 | } else { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2210 | /* otherwise we have to go forward and ... */ |
| 2211 | mddev->events ++; |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 2212 | mddev->can_decrease_events = nospares; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | |
| 2215 | if (!mddev->events) { |
| 2216 | /* |
| 2217 | * oops, this 64-bit counter should never wrap. |
| 2218 | * Either we are in around ~1 trillion A.C., assuming |
| 2219 | * 1 reboot per second, or we have a bug: |
| 2220 | */ |
| 2221 | MD_BUG(); |
| 2222 | mddev->events --; |
| 2223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | |
| 2225 | /* |
| 2226 | * do not write anything to disk if using |
| 2227 | * nonpersistent superblocks |
| 2228 | */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2229 | if (!mddev->persistent) { |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2230 | if (!mddev->external) |
| 2231 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
| 2232 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2233 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 2234 | wake_up(&mddev->sb_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2236 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2237 | sync_sbs(mddev, nospares); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2238 | spin_unlock_irq(&mddev->write_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | |
| 2240 | dprintk(KERN_INFO |
| 2241 | "md: updating %s RAID superblock on device (in sync %d)\n", |
| 2242 | mdname(mddev),mddev->in_sync); |
| 2243 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 2244 | bitmap_update_sb(mddev->bitmap); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2245 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | char b[BDEVNAME_SIZE]; |
| 2247 | dprintk(KERN_INFO "md: "); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2248 | if (rdev->sb_loaded != 1) |
| 2249 | continue; /* no noise on spare devices */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2250 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | dprintk("(skipping faulty "); |
| 2252 | |
| 2253 | dprintk("%s ", bdevname(rdev->bdev,b)); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2254 | if (!test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2255 | md_super_write(mddev,rdev, |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 2256 | rdev->sb_start, rdev->sb_size, |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2257 | rdev->sb_page); |
| 2258 | dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", |
| 2259 | bdevname(rdev->bdev,b), |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 2260 | (unsigned long long)rdev->sb_start); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2261 | rdev->sb_events = mddev->events; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | } else |
| 2264 | dprintk(")\n"); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2265 | if (mddev->level == LEVEL_MULTIPATH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | /* only need to write one superblock... */ |
| 2267 | break; |
| 2268 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2269 | md_super_wait(mddev); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2270 | /* 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] | 2271 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2272 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2273 | if (mddev->in_sync != sync_req || |
| 2274 | test_bit(MD_CHANGE_DEVS, &mddev->flags)) { |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2275 | /* have to write it out again */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2276 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2277 | goto repeat; |
| 2278 | } |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2279 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2280 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 2281 | wake_up(&mddev->sb_wait); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 2282 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 2283 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
Andre Noll | 7f6ce76 | 2008-03-23 18:34:54 +0100 | [diff] [blame] | 2287 | /* words written to sysfs files may, or may not, be \n terminated. |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 2288 | * We want to accept with case. For this we use cmd_match. |
| 2289 | */ |
| 2290 | static int cmd_match(const char *cmd, const char *str) |
| 2291 | { |
| 2292 | /* See if cmd, written into a sysfs file, matches |
| 2293 | * str. They must either be the same, or cmd can |
| 2294 | * have a trailing newline |
| 2295 | */ |
| 2296 | while (*cmd && *str && *cmd == *str) { |
| 2297 | cmd++; |
| 2298 | str++; |
| 2299 | } |
| 2300 | if (*cmd == '\n') |
| 2301 | cmd++; |
| 2302 | if (*str || *cmd) |
| 2303 | return 0; |
| 2304 | return 1; |
| 2305 | } |
| 2306 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2307 | struct rdev_sysfs_entry { |
| 2308 | struct attribute attr; |
| 2309 | ssize_t (*show)(mdk_rdev_t *, char *); |
| 2310 | ssize_t (*store)(mdk_rdev_t *, const char *, size_t); |
| 2311 | }; |
| 2312 | |
| 2313 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2314 | state_show(mdk_rdev_t *rdev, char *page) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2315 | { |
| 2316 | char *sep = ""; |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2317 | size_t len = 0; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2318 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2319 | if (test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2320 | len+= sprintf(page+len, "%sfaulty",sep); |
| 2321 | sep = ","; |
| 2322 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2323 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2324 | len += sprintf(page+len, "%sin_sync",sep); |
| 2325 | sep = ","; |
| 2326 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2327 | if (test_bit(WriteMostly, &rdev->flags)) { |
| 2328 | len += sprintf(page+len, "%swrite_mostly",sep); |
| 2329 | sep = ","; |
| 2330 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2331 | if (test_bit(Blocked, &rdev->flags)) { |
| 2332 | len += sprintf(page+len, "%sblocked", sep); |
| 2333 | sep = ","; |
| 2334 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2335 | if (!test_bit(Faulty, &rdev->flags) && |
| 2336 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2337 | len += sprintf(page+len, "%sspare", sep); |
| 2338 | sep = ","; |
| 2339 | } |
| 2340 | return len+sprintf(page+len, "\n"); |
| 2341 | } |
| 2342 | |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2343 | static ssize_t |
| 2344 | state_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2345 | { |
| 2346 | /* can write |
| 2347 | * faulty - simulates and error |
| 2348 | * remove - disconnects the device |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2349 | * writemostly - sets write_mostly |
| 2350 | * -writemostly - clears write_mostly |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2351 | * blocked - sets the Blocked flag |
| 2352 | * -blocked - clears the Blocked flag |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2353 | * insync - sets Insync providing device isn't active |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2354 | */ |
| 2355 | int err = -EINVAL; |
| 2356 | if (cmd_match(buf, "faulty") && rdev->mddev->pers) { |
| 2357 | md_error(rdev->mddev, rdev); |
| 2358 | err = 0; |
| 2359 | } else if (cmd_match(buf, "remove")) { |
| 2360 | if (rdev->raid_disk >= 0) |
| 2361 | err = -EBUSY; |
| 2362 | else { |
| 2363 | mddev_t *mddev = rdev->mddev; |
| 2364 | kick_rdev_from_array(rdev); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 2365 | if (mddev->pers) |
| 2366 | md_update_sb(mddev, 1); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2367 | md_new_event(mddev); |
| 2368 | err = 0; |
| 2369 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2370 | } else if (cmd_match(buf, "writemostly")) { |
| 2371 | set_bit(WriteMostly, &rdev->flags); |
| 2372 | err = 0; |
| 2373 | } else if (cmd_match(buf, "-writemostly")) { |
| 2374 | clear_bit(WriteMostly, &rdev->flags); |
| 2375 | err = 0; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2376 | } else if (cmd_match(buf, "blocked")) { |
| 2377 | set_bit(Blocked, &rdev->flags); |
| 2378 | err = 0; |
| 2379 | } else if (cmd_match(buf, "-blocked")) { |
| 2380 | clear_bit(Blocked, &rdev->flags); |
| 2381 | wake_up(&rdev->blocked_wait); |
| 2382 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 2383 | md_wakeup_thread(rdev->mddev->thread); |
| 2384 | |
| 2385 | err = 0; |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2386 | } else if (cmd_match(buf, "insync") && rdev->raid_disk == -1) { |
| 2387 | set_bit(In_sync, &rdev->flags); |
| 2388 | err = 0; |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2389 | } |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2390 | if (!err) |
| 2391 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2392 | return err ? err : len; |
| 2393 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2394 | static struct rdev_sysfs_entry rdev_state = |
| 2395 | __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2396 | |
| 2397 | static ssize_t |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2398 | errors_show(mdk_rdev_t *rdev, char *page) |
| 2399 | { |
| 2400 | return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors)); |
| 2401 | } |
| 2402 | |
| 2403 | static ssize_t |
| 2404 | errors_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2405 | { |
| 2406 | char *e; |
| 2407 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 2408 | if (*buf && (*e == 0 || *e == '\n')) { |
| 2409 | atomic_set(&rdev->corrected_errors, n); |
| 2410 | return len; |
| 2411 | } |
| 2412 | return -EINVAL; |
| 2413 | } |
| 2414 | static struct rdev_sysfs_entry rdev_errors = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2415 | __ATTR(errors, S_IRUGO|S_IWUSR, errors_show, errors_store); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2416 | |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2417 | static ssize_t |
| 2418 | slot_show(mdk_rdev_t *rdev, char *page) |
| 2419 | { |
| 2420 | if (rdev->raid_disk < 0) |
| 2421 | return sprintf(page, "none\n"); |
| 2422 | else |
| 2423 | return sprintf(page, "%d\n", rdev->raid_disk); |
| 2424 | } |
| 2425 | |
| 2426 | static ssize_t |
| 2427 | slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2428 | { |
| 2429 | char *e; |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2430 | int err; |
| 2431 | char nm[20]; |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2432 | int slot = simple_strtoul(buf, &e, 10); |
| 2433 | if (strncmp(buf, "none", 4)==0) |
| 2434 | slot = -1; |
| 2435 | else if (e==buf || (*e && *e!= '\n')) |
| 2436 | return -EINVAL; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2437 | if (rdev->mddev->pers && slot == -1) { |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2438 | /* Setting 'slot' on an active array requires also |
| 2439 | * updating the 'rd%d' link, and communicating |
| 2440 | * with the personality with ->hot_*_disk. |
| 2441 | * For now we only support removing |
| 2442 | * failed/spare devices. This normally happens automatically, |
| 2443 | * but not when the metadata is externally managed. |
| 2444 | */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2445 | if (rdev->raid_disk == -1) |
| 2446 | return -EEXIST; |
| 2447 | /* personality does all needed checks */ |
| 2448 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 2449 | return -EINVAL; |
| 2450 | err = rdev->mddev->pers-> |
| 2451 | hot_remove_disk(rdev->mddev, rdev->raid_disk); |
| 2452 | if (err) |
| 2453 | return err; |
| 2454 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2455 | sysfs_remove_link(&rdev->mddev->kobj, nm); |
Maciej Trela | b710310 | 2010-04-14 16:58:16 +1000 | [diff] [blame] | 2456 | rdev->raid_disk = -1; |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2457 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 2458 | md_wakeup_thread(rdev->mddev->thread); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2459 | } else if (rdev->mddev->pers) { |
| 2460 | mdk_rdev_t *rdev2; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2461 | /* Activating a spare .. or possibly reactivating |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2462 | * if we ever get bitmaps working here. |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2463 | */ |
| 2464 | |
| 2465 | if (rdev->raid_disk != -1) |
| 2466 | return -EBUSY; |
| 2467 | |
| 2468 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 2469 | return -EINVAL; |
| 2470 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2471 | list_for_each_entry(rdev2, &rdev->mddev->disks, same_set) |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2472 | if (rdev2->raid_disk == slot) |
| 2473 | return -EEXIST; |
| 2474 | |
| 2475 | rdev->raid_disk = slot; |
| 2476 | if (test_bit(In_sync, &rdev->flags)) |
| 2477 | rdev->saved_raid_disk = slot; |
| 2478 | else |
| 2479 | rdev->saved_raid_disk = -1; |
| 2480 | err = rdev->mddev->pers-> |
| 2481 | hot_add_disk(rdev->mddev, rdev); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 2482 | if (err) { |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2483 | rdev->raid_disk = -1; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2484 | return err; |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 2485 | } else |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2486 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2487 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2488 | if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2489 | /* failure here is OK */; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2490 | /* don't wakeup anyone, leave that to userspace. */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2491 | } else { |
| 2492 | if (slot >= rdev->mddev->raid_disks) |
| 2493 | return -ENOSPC; |
| 2494 | rdev->raid_disk = slot; |
| 2495 | /* assume it is working */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2496 | clear_bit(Faulty, &rdev->flags); |
| 2497 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2498 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2499 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2500 | } |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2501 | return len; |
| 2502 | } |
| 2503 | |
| 2504 | |
| 2505 | static struct rdev_sysfs_entry rdev_slot = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2506 | __ATTR(slot, S_IRUGO|S_IWUSR, slot_show, slot_store); |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2507 | |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2508 | static ssize_t |
| 2509 | offset_show(mdk_rdev_t *rdev, char *page) |
| 2510 | { |
Andrew Morton | 6961ece | 2006-01-06 00:20:59 -0800 | [diff] [blame] | 2511 | return sprintf(page, "%llu\n", (unsigned long long)rdev->data_offset); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | static ssize_t |
| 2515 | offset_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2516 | { |
| 2517 | char *e; |
| 2518 | unsigned long long offset = simple_strtoull(buf, &e, 10); |
| 2519 | if (e==buf || (*e && *e != '\n')) |
| 2520 | return -EINVAL; |
Neil Brown | 8ed0a52 | 2008-06-28 08:31:29 +1000 | [diff] [blame] | 2521 | if (rdev->mddev->pers && rdev->raid_disk >= 0) |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2522 | return -EBUSY; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2523 | if (rdev->sectors && rdev->mddev->external) |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2524 | /* Must set offset before size, so overlap checks |
| 2525 | * can be sane */ |
| 2526 | return -EBUSY; |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2527 | rdev->data_offset = offset; |
| 2528 | return len; |
| 2529 | } |
| 2530 | |
| 2531 | static struct rdev_sysfs_entry rdev_offset = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2532 | __ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2533 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2534 | static ssize_t |
| 2535 | rdev_size_show(mdk_rdev_t *rdev, char *page) |
| 2536 | { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2537 | return sprintf(page, "%llu\n", (unsigned long long)rdev->sectors / 2); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2538 | } |
| 2539 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2540 | static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2) |
| 2541 | { |
| 2542 | /* check if two start/length pairs overlap */ |
| 2543 | if (s1+l1 <= s2) |
| 2544 | return 0; |
| 2545 | if (s2+l2 <= s1) |
| 2546 | return 0; |
| 2547 | return 1; |
| 2548 | } |
| 2549 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2550 | static int strict_blocks_to_sectors(const char *buf, sector_t *sectors) |
| 2551 | { |
| 2552 | unsigned long long blocks; |
| 2553 | sector_t new; |
| 2554 | |
| 2555 | if (strict_strtoull(buf, 10, &blocks) < 0) |
| 2556 | return -EINVAL; |
| 2557 | |
| 2558 | if (blocks & 1ULL << (8 * sizeof(blocks) - 1)) |
| 2559 | return -EINVAL; /* sector conversion overflow */ |
| 2560 | |
| 2561 | new = blocks * 2; |
| 2562 | if (new != blocks * 2) |
| 2563 | return -EINVAL; /* unsigned long long to sector_t overflow */ |
| 2564 | |
| 2565 | *sectors = new; |
| 2566 | return 0; |
| 2567 | } |
| 2568 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2569 | static ssize_t |
| 2570 | rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2571 | { |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2572 | mddev_t *my_mddev = rdev->mddev; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2573 | sector_t oldsectors = rdev->sectors; |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2574 | sector_t sectors; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2575 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2576 | if (strict_blocks_to_sectors(buf, §ors) < 0) |
Neil Brown | d702745 | 2008-07-12 10:37:50 +1000 | [diff] [blame] | 2577 | return -EINVAL; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2578 | if (my_mddev->pers && rdev->raid_disk >= 0) { |
Neil Brown | d702745 | 2008-07-12 10:37:50 +1000 | [diff] [blame] | 2579 | if (my_mddev->persistent) { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2580 | sectors = super_types[my_mddev->major_version]. |
| 2581 | rdev_size_change(rdev, sectors); |
| 2582 | if (!sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2583 | return -EBUSY; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2584 | } else if (!sectors) |
| 2585 | sectors = (rdev->bdev->bd_inode->i_size >> 9) - |
| 2586 | rdev->data_offset; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2587 | } |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2588 | if (sectors < my_mddev->dev_sectors) |
Chris Webb | 7d3c6f8 | 2008-10-13 11:55:11 +1100 | [diff] [blame] | 2589 | return -EINVAL; /* component must fit device */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2590 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2591 | rdev->sectors = sectors; |
| 2592 | if (sectors > oldsectors && my_mddev->external) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2593 | /* need to check that all other rdevs with the same ->bdev |
| 2594 | * do not overlap. We need to unlock the mddev to avoid |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2595 | * a deadlock. We have already changed rdev->sectors, and if |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2596 | * we have to change it back, we will have the lock again. |
| 2597 | */ |
| 2598 | mddev_t *mddev; |
| 2599 | int overlap = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2600 | struct list_head *tmp; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2601 | |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2602 | mddev_unlock(my_mddev); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 2603 | for_each_mddev(mddev, tmp) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2604 | mdk_rdev_t *rdev2; |
| 2605 | |
| 2606 | mddev_lock(mddev); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2607 | list_for_each_entry(rdev2, &mddev->disks, same_set) |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2608 | if (test_bit(AllReserved, &rdev2->flags) || |
| 2609 | (rdev->bdev == rdev2->bdev && |
| 2610 | rdev != rdev2 && |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2611 | overlaps(rdev->data_offset, rdev->sectors, |
Andre Noll | d07bd3b | 2008-07-21 14:42:07 +1000 | [diff] [blame] | 2612 | rdev2->data_offset, |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2613 | rdev2->sectors))) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2614 | overlap = 1; |
| 2615 | break; |
| 2616 | } |
| 2617 | mddev_unlock(mddev); |
| 2618 | if (overlap) { |
| 2619 | mddev_put(mddev); |
| 2620 | break; |
| 2621 | } |
| 2622 | } |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2623 | mddev_lock(my_mddev); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2624 | if (overlap) { |
| 2625 | /* Someone else could have slipped in a size |
| 2626 | * change here, but doing so is just silly. |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2627 | * We put oldsectors back because we *know* it is |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2628 | * safe, and trust userspace not to race with |
| 2629 | * itself |
| 2630 | */ |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2631 | rdev->sectors = oldsectors; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2632 | return -EBUSY; |
| 2633 | } |
| 2634 | } |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2635 | return len; |
| 2636 | } |
| 2637 | |
| 2638 | static struct rdev_sysfs_entry rdev_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2639 | __ATTR(size, S_IRUGO|S_IWUSR, rdev_size_show, rdev_size_store); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2640 | |
Dan Williams | 06e3c81 | 2009-12-12 21:17:12 -0700 | [diff] [blame] | 2641 | |
| 2642 | static ssize_t recovery_start_show(mdk_rdev_t *rdev, char *page) |
| 2643 | { |
| 2644 | unsigned long long recovery_start = rdev->recovery_offset; |
| 2645 | |
| 2646 | if (test_bit(In_sync, &rdev->flags) || |
| 2647 | recovery_start == MaxSector) |
| 2648 | return sprintf(page, "none\n"); |
| 2649 | |
| 2650 | return sprintf(page, "%llu\n", recovery_start); |
| 2651 | } |
| 2652 | |
| 2653 | static ssize_t recovery_start_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2654 | { |
| 2655 | unsigned long long recovery_start; |
| 2656 | |
| 2657 | if (cmd_match(buf, "none")) |
| 2658 | recovery_start = MaxSector; |
| 2659 | else if (strict_strtoull(buf, 10, &recovery_start)) |
| 2660 | return -EINVAL; |
| 2661 | |
| 2662 | if (rdev->mddev->pers && |
| 2663 | rdev->raid_disk >= 0) |
| 2664 | return -EBUSY; |
| 2665 | |
| 2666 | rdev->recovery_offset = recovery_start; |
| 2667 | if (recovery_start == MaxSector) |
| 2668 | set_bit(In_sync, &rdev->flags); |
| 2669 | else |
| 2670 | clear_bit(In_sync, &rdev->flags); |
| 2671 | return len; |
| 2672 | } |
| 2673 | |
| 2674 | static struct rdev_sysfs_entry rdev_recovery_start = |
| 2675 | __ATTR(recovery_start, S_IRUGO|S_IWUSR, recovery_start_show, recovery_start_store); |
| 2676 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2677 | static struct attribute *rdev_default_attrs[] = { |
| 2678 | &rdev_state.attr, |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2679 | &rdev_errors.attr, |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2680 | &rdev_slot.attr, |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2681 | &rdev_offset.attr, |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2682 | &rdev_size.attr, |
Dan Williams | 06e3c81 | 2009-12-12 21:17:12 -0700 | [diff] [blame] | 2683 | &rdev_recovery_start.attr, |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2684 | NULL, |
| 2685 | }; |
| 2686 | static ssize_t |
| 2687 | rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 2688 | { |
| 2689 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2690 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2691 | mddev_t *mddev = rdev->mddev; |
| 2692 | ssize_t rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2693 | |
| 2694 | if (!entry->show) |
| 2695 | return -EIO; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2696 | |
| 2697 | rv = mddev ? mddev_lock(mddev) : -EBUSY; |
| 2698 | if (!rv) { |
| 2699 | if (rdev->mddev == NULL) |
| 2700 | rv = -EBUSY; |
| 2701 | else |
| 2702 | rv = entry->show(rdev, page); |
| 2703 | mddev_unlock(mddev); |
| 2704 | } |
| 2705 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | static ssize_t |
| 2709 | rdev_attr_store(struct kobject *kobj, struct attribute *attr, |
| 2710 | const char *page, size_t length) |
| 2711 | { |
| 2712 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2713 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2714 | ssize_t rv; |
| 2715 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2716 | |
| 2717 | if (!entry->store) |
| 2718 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 2719 | if (!capable(CAP_SYS_ADMIN)) |
| 2720 | return -EACCES; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2721 | rv = mddev ? mddev_lock(mddev): -EBUSY; |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2722 | if (!rv) { |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2723 | if (rdev->mddev == NULL) |
| 2724 | rv = -EBUSY; |
| 2725 | else |
| 2726 | rv = entry->store(rdev, page, length); |
Dan Williams | 6a51830 | 2008-04-30 00:52:28 -0700 | [diff] [blame] | 2727 | mddev_unlock(mddev); |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2728 | } |
| 2729 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | static void rdev_free(struct kobject *ko) |
| 2733 | { |
| 2734 | mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj); |
| 2735 | kfree(rdev); |
| 2736 | } |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 2737 | static const struct sysfs_ops rdev_sysfs_ops = { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2738 | .show = rdev_attr_show, |
| 2739 | .store = rdev_attr_store, |
| 2740 | }; |
| 2741 | static struct kobj_type rdev_ktype = { |
| 2742 | .release = rdev_free, |
| 2743 | .sysfs_ops = &rdev_sysfs_ops, |
| 2744 | .default_attrs = rdev_default_attrs, |
| 2745 | }; |
| 2746 | |
NeilBrown | e8bb9a8 | 2010-06-01 19:37:26 +1000 | [diff] [blame] | 2747 | void md_rdev_init(mdk_rdev_t *rdev) |
| 2748 | { |
| 2749 | rdev->desc_nr = -1; |
| 2750 | rdev->saved_raid_disk = -1; |
| 2751 | rdev->raid_disk = -1; |
| 2752 | rdev->flags = 0; |
| 2753 | rdev->data_offset = 0; |
| 2754 | rdev->sb_events = 0; |
| 2755 | rdev->last_read_error.tv_sec = 0; |
| 2756 | rdev->last_read_error.tv_nsec = 0; |
| 2757 | atomic_set(&rdev->nr_pending, 0); |
| 2758 | atomic_set(&rdev->read_errors, 0); |
| 2759 | atomic_set(&rdev->corrected_errors, 0); |
| 2760 | |
| 2761 | INIT_LIST_HEAD(&rdev->same_set); |
| 2762 | init_waitqueue_head(&rdev->blocked_wait); |
| 2763 | } |
| 2764 | EXPORT_SYMBOL_GPL(md_rdev_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | /* |
| 2766 | * Import a device. If 'super_format' >= 0, then sanity check the superblock |
| 2767 | * |
| 2768 | * mark the device faulty if: |
| 2769 | * |
| 2770 | * - the device is nonexistent (zero size) |
| 2771 | * - the device has no valid superblock |
| 2772 | * |
| 2773 | * a faulty rdev _never_ has rdev->sb set. |
| 2774 | */ |
| 2775 | static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_minor) |
| 2776 | { |
| 2777 | char b[BDEVNAME_SIZE]; |
| 2778 | int err; |
| 2779 | mdk_rdev_t *rdev; |
| 2780 | sector_t size; |
| 2781 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 2782 | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | if (!rdev) { |
| 2784 | printk(KERN_ERR "md: could not alloc mem for new device!\n"); |
| 2785 | return ERR_PTR(-ENOMEM); |
| 2786 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | |
NeilBrown | e8bb9a8 | 2010-06-01 19:37:26 +1000 | [diff] [blame] | 2788 | md_rdev_init(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | if ((err = alloc_disk_sb(rdev))) |
| 2790 | goto abort_free; |
| 2791 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2792 | err = lock_rdev(rdev, newdev, super_format == -2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | if (err) |
| 2794 | goto abort_free; |
| 2795 | |
Greg Kroah-Hartman | f9cb074 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 2796 | kobject_init(&rdev->kobj, &rdev_ktype); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 2799 | if (!size) { |
| 2800 | printk(KERN_WARNING |
| 2801 | "md: %s has zero or unknown size, marking faulty!\n", |
| 2802 | bdevname(rdev->bdev,b)); |
| 2803 | err = -EINVAL; |
| 2804 | goto abort_free; |
| 2805 | } |
| 2806 | |
| 2807 | if (super_format >= 0) { |
| 2808 | err = super_types[super_format]. |
| 2809 | load_super(rdev, NULL, super_minor); |
| 2810 | if (err == -EINVAL) { |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 2811 | printk(KERN_WARNING |
| 2812 | "md: %s does not have a valid v%d.%d " |
| 2813 | "superblock, not importing!\n", |
| 2814 | bdevname(rdev->bdev,b), |
| 2815 | super_format, super_minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | goto abort_free; |
| 2817 | } |
| 2818 | if (err < 0) { |
| 2819 | printk(KERN_WARNING |
| 2820 | "md: could not read %s's sb, not importing!\n", |
| 2821 | bdevname(rdev->bdev,b)); |
| 2822 | goto abort_free; |
| 2823 | } |
| 2824 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | return rdev; |
| 2827 | |
| 2828 | abort_free: |
| 2829 | if (rdev->sb_page) { |
| 2830 | if (rdev->bdev) |
| 2831 | unlock_rdev(rdev); |
| 2832 | free_disk_sb(rdev); |
| 2833 | } |
| 2834 | kfree(rdev); |
| 2835 | return ERR_PTR(err); |
| 2836 | } |
| 2837 | |
| 2838 | /* |
| 2839 | * Check a full RAID array for plausibility |
| 2840 | */ |
| 2841 | |
| 2842 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 2843 | static void analyze_sbs(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | { |
| 2845 | int i; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2846 | mdk_rdev_t *rdev, *freshest, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | char b[BDEVNAME_SIZE]; |
| 2848 | |
| 2849 | freshest = NULL; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2850 | rdev_for_each(rdev, tmp, mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | switch (super_types[mddev->major_version]. |
| 2852 | load_super(rdev, freshest, mddev->minor_version)) { |
| 2853 | case 1: |
| 2854 | freshest = rdev; |
| 2855 | break; |
| 2856 | case 0: |
| 2857 | break; |
| 2858 | default: |
| 2859 | printk( KERN_ERR \ |
| 2860 | "md: fatal superblock inconsistency in %s" |
| 2861 | " -- removing from array\n", |
| 2862 | bdevname(rdev->bdev,b)); |
| 2863 | kick_rdev_from_array(rdev); |
| 2864 | } |
| 2865 | |
| 2866 | |
| 2867 | super_types[mddev->major_version]. |
| 2868 | validate_super(mddev, freshest); |
| 2869 | |
| 2870 | i = 0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2871 | rdev_for_each(rdev, tmp, mddev) { |
NeilBrown | 233fca3 | 2010-04-14 17:02:09 +1000 | [diff] [blame] | 2872 | if (mddev->max_disks && |
| 2873 | (rdev->desc_nr >= mddev->max_disks || |
| 2874 | i > mddev->max_disks)) { |
NeilBrown | de01dfa | 2009-02-06 18:02:46 +1100 | [diff] [blame] | 2875 | printk(KERN_WARNING |
| 2876 | "md: %s: %s: only %d devices permitted\n", |
| 2877 | mdname(mddev), bdevname(rdev->bdev, b), |
| 2878 | mddev->max_disks); |
| 2879 | kick_rdev_from_array(rdev); |
| 2880 | continue; |
| 2881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | if (rdev != freshest) |
| 2883 | if (super_types[mddev->major_version]. |
| 2884 | validate_super(mddev, rdev)) { |
| 2885 | printk(KERN_WARNING "md: kicking non-fresh %s" |
| 2886 | " from array!\n", |
| 2887 | bdevname(rdev->bdev,b)); |
| 2888 | kick_rdev_from_array(rdev); |
| 2889 | continue; |
| 2890 | } |
| 2891 | if (mddev->level == LEVEL_MULTIPATH) { |
| 2892 | rdev->desc_nr = i++; |
| 2893 | rdev->raid_disk = rdev->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2894 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 2895 | } else if (rdev->raid_disk >= (mddev->raid_disks - min(0, mddev->delta_disks))) { |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 2896 | rdev->raid_disk = -1; |
| 2897 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | } |
| 2899 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
NeilBrown | 72e0207 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2902 | /* Read a fixed-point number. |
| 2903 | * Numbers in sysfs attributes should be in "standard" units where |
| 2904 | * possible, so time should be in seconds. |
| 2905 | * However we internally use a a much smaller unit such as |
| 2906 | * milliseconds or jiffies. |
| 2907 | * This function takes a decimal number with a possible fractional |
| 2908 | * component, and produces an integer which is the result of |
| 2909 | * multiplying that number by 10^'scale'. |
| 2910 | * all without any floating-point arithmetic. |
| 2911 | */ |
| 2912 | int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale) |
| 2913 | { |
| 2914 | unsigned long result = 0; |
| 2915 | long decimals = -1; |
| 2916 | while (isdigit(*cp) || (*cp == '.' && decimals < 0)) { |
| 2917 | if (*cp == '.') |
| 2918 | decimals = 0; |
| 2919 | else if (decimals < scale) { |
| 2920 | unsigned int value; |
| 2921 | value = *cp - '0'; |
| 2922 | result = result * 10 + value; |
| 2923 | if (decimals >= 0) |
| 2924 | decimals++; |
| 2925 | } |
| 2926 | cp++; |
| 2927 | } |
| 2928 | if (*cp == '\n') |
| 2929 | cp++; |
| 2930 | if (*cp) |
| 2931 | return -EINVAL; |
| 2932 | if (decimals < 0) |
| 2933 | decimals = 0; |
| 2934 | while (decimals < scale) { |
| 2935 | result *= 10; |
| 2936 | decimals ++; |
| 2937 | } |
| 2938 | *res = result; |
| 2939 | return 0; |
| 2940 | } |
| 2941 | |
| 2942 | |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2943 | static void md_safemode_timeout(unsigned long data); |
| 2944 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2945 | static ssize_t |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2946 | safe_delay_show(mddev_t *mddev, char *page) |
| 2947 | { |
| 2948 | int msec = (mddev->safemode_delay*1000)/HZ; |
| 2949 | return sprintf(page, "%d.%03d\n", msec/1000, msec%1000); |
| 2950 | } |
| 2951 | static ssize_t |
| 2952 | safe_delay_store(mddev_t *mddev, const char *cbuf, size_t len) |
| 2953 | { |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2954 | unsigned long msec; |
Dan Williams | 97ce0a7 | 2008-09-24 22:48:19 -0700 | [diff] [blame] | 2955 | |
NeilBrown | 72e0207 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2956 | if (strict_strtoul_scaled(cbuf, &msec, 3) < 0) |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2957 | return -EINVAL; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2958 | if (msec == 0) |
| 2959 | mddev->safemode_delay = 0; |
| 2960 | else { |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2961 | unsigned long old_delay = mddev->safemode_delay; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2962 | mddev->safemode_delay = (msec*HZ)/1000; |
| 2963 | if (mddev->safemode_delay == 0) |
| 2964 | mddev->safemode_delay = 1; |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2965 | if (mddev->safemode_delay < old_delay) |
| 2966 | md_safemode_timeout((unsigned long)mddev); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2967 | } |
| 2968 | return len; |
| 2969 | } |
| 2970 | static struct md_sysfs_entry md_safe_delay = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2971 | __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] | 2972 | |
| 2973 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2974 | level_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2975 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2976 | struct mdk_personality *p = mddev->pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2977 | if (p) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2978 | return sprintf(page, "%s\n", p->name); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2979 | else if (mddev->clevel[0]) |
| 2980 | return sprintf(page, "%s\n", mddev->clevel); |
| 2981 | else if (mddev->level != LEVEL_NONE) |
| 2982 | return sprintf(page, "%d\n", mddev->level); |
| 2983 | else |
| 2984 | return 0; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2985 | } |
| 2986 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2987 | static ssize_t |
| 2988 | level_store(mddev_t *mddev, const char *buf, size_t len) |
| 2989 | { |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2990 | char clevel[16]; |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2991 | ssize_t rv = len; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2992 | struct mdk_personality *pers; |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2993 | long level; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2994 | void *priv; |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 2995 | mdk_rdev_t *rdev; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2996 | |
| 2997 | if (mddev->pers == NULL) { |
| 2998 | if (len == 0) |
| 2999 | return 0; |
| 3000 | if (len >= sizeof(mddev->clevel)) |
| 3001 | return -ENOSPC; |
| 3002 | strncpy(mddev->clevel, buf, len); |
| 3003 | if (mddev->clevel[len-1] == '\n') |
| 3004 | len--; |
| 3005 | mddev->clevel[len] = 0; |
| 3006 | mddev->level = LEVEL_NONE; |
| 3007 | return rv; |
| 3008 | } |
| 3009 | |
| 3010 | /* request to change the personality. Need to ensure: |
| 3011 | * - array is not engaged in resync/recovery/reshape |
| 3012 | * - old personality can be suspended |
| 3013 | * - new personality will access other array. |
| 3014 | */ |
| 3015 | |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 3016 | if (mddev->sync_thread || |
| 3017 | mddev->reshape_position != MaxSector || |
| 3018 | mddev->sysfs_active) |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3019 | return -EBUSY; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3020 | |
| 3021 | if (!mddev->pers->quiesce) { |
| 3022 | printk(KERN_WARNING "md: %s: %s does not support online personality change\n", |
| 3023 | mdname(mddev), mddev->pers->name); |
| 3024 | return -EINVAL; |
| 3025 | } |
| 3026 | |
| 3027 | /* Now find the new personality */ |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3028 | if (len == 0 || len >= sizeof(clevel)) |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3029 | return -EINVAL; |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3030 | strncpy(clevel, buf, len); |
| 3031 | if (clevel[len-1] == '\n') |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3032 | len--; |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3033 | clevel[len] = 0; |
| 3034 | if (strict_strtol(clevel, 10, &level)) |
| 3035 | level = LEVEL_NONE; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3036 | |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3037 | if (request_module("md-%s", clevel) != 0) |
| 3038 | request_module("md-level-%s", clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3039 | spin_lock(&pers_lock); |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3040 | pers = find_pers(level, clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3041 | if (!pers || !try_module_get(pers->owner)) { |
| 3042 | spin_unlock(&pers_lock); |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3043 | printk(KERN_WARNING "md: personality %s not loaded\n", clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3044 | return -EINVAL; |
| 3045 | } |
| 3046 | spin_unlock(&pers_lock); |
| 3047 | |
| 3048 | if (pers == mddev->pers) { |
| 3049 | /* Nothing to do! */ |
| 3050 | module_put(pers->owner); |
| 3051 | return rv; |
| 3052 | } |
| 3053 | if (!pers->takeover) { |
| 3054 | module_put(pers->owner); |
| 3055 | printk(KERN_WARNING "md: %s: %s does not support personality takeover\n", |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3056 | mdname(mddev), clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3057 | return -EINVAL; |
| 3058 | } |
| 3059 | |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3060 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 3061 | rdev->new_raid_disk = rdev->raid_disk; |
| 3062 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3063 | /* ->takeover must set new_* and/or delta_disks |
| 3064 | * if it succeeds, and may set them when it fails. |
| 3065 | */ |
| 3066 | priv = pers->takeover(mddev); |
| 3067 | if (IS_ERR(priv)) { |
| 3068 | mddev->new_level = mddev->level; |
| 3069 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3070 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3071 | mddev->raid_disks -= mddev->delta_disks; |
| 3072 | mddev->delta_disks = 0; |
| 3073 | module_put(pers->owner); |
| 3074 | printk(KERN_WARNING "md: %s: %s would not accept array\n", |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3075 | mdname(mddev), clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3076 | return PTR_ERR(priv); |
| 3077 | } |
| 3078 | |
| 3079 | /* Looks like we have a winner */ |
| 3080 | mddev_suspend(mddev); |
| 3081 | mddev->pers->stop(mddev); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 3082 | |
| 3083 | if (mddev->pers->sync_request == NULL && |
| 3084 | pers->sync_request != NULL) { |
| 3085 | /* need to add the md_redundancy_group */ |
| 3086 | if (sysfs_create_group(&mddev->kobj, &md_redundancy_group)) |
| 3087 | printk(KERN_WARNING |
| 3088 | "md: cannot register extra attributes for %s\n", |
| 3089 | mdname(mddev)); |
NeilBrown | 19fdb9e | 2010-05-22 08:31:36 +1000 | [diff] [blame] | 3090 | mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, NULL, "sync_action"); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 3091 | } |
| 3092 | if (mddev->pers->sync_request != NULL && |
| 3093 | pers->sync_request == NULL) { |
| 3094 | /* need to remove the md_redundancy_group */ |
| 3095 | if (mddev->to_remove == NULL) |
| 3096 | mddev->to_remove = &md_redundancy_group; |
| 3097 | } |
| 3098 | |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 3099 | if (mddev->pers->sync_request == NULL && |
| 3100 | mddev->external) { |
| 3101 | /* We are converting from a no-redundancy array |
| 3102 | * to a redundancy array and metadata is managed |
| 3103 | * externally so we need to be sure that writes |
| 3104 | * won't block due to a need to transition |
| 3105 | * clean->dirty |
| 3106 | * until external management is started. |
| 3107 | */ |
| 3108 | mddev->in_sync = 0; |
| 3109 | mddev->safemode_delay = 0; |
| 3110 | mddev->safemode = 0; |
| 3111 | } |
| 3112 | |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3113 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 3114 | char nm[20]; |
| 3115 | if (rdev->raid_disk < 0) |
| 3116 | continue; |
| 3117 | if (rdev->new_raid_disk > mddev->raid_disks) |
| 3118 | rdev->new_raid_disk = -1; |
| 3119 | if (rdev->new_raid_disk == rdev->raid_disk) |
| 3120 | continue; |
| 3121 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 3122 | sysfs_remove_link(&mddev->kobj, nm); |
| 3123 | } |
| 3124 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 3125 | if (rdev->raid_disk < 0) |
| 3126 | continue; |
| 3127 | if (rdev->new_raid_disk == rdev->raid_disk) |
| 3128 | continue; |
| 3129 | rdev->raid_disk = rdev->new_raid_disk; |
| 3130 | if (rdev->raid_disk < 0) |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 3131 | clear_bit(In_sync, &rdev->flags); |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3132 | else { |
| 3133 | char nm[20]; |
| 3134 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 3135 | if(sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) |
| 3136 | printk("md: cannot register %s for %s after level change\n", |
| 3137 | nm, mdname(mddev)); |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 3138 | } |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | module_put(mddev->pers->owner); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3142 | mddev->pers = pers; |
| 3143 | mddev->private = priv; |
| 3144 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
| 3145 | mddev->level = mddev->new_level; |
| 3146 | mddev->layout = mddev->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3147 | mddev->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3148 | mddev->delta_disks = 0; |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 3149 | if (mddev->pers->sync_request == NULL) { |
| 3150 | /* this is now an array without redundancy, so |
| 3151 | * it must always be in_sync |
| 3152 | */ |
| 3153 | mddev->in_sync = 1; |
| 3154 | del_timer_sync(&mddev->safemode_timer); |
| 3155 | } |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3156 | pers->run(mddev); |
| 3157 | mddev_resume(mddev); |
| 3158 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 3159 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3160 | md_wakeup_thread(mddev->thread); |
Maciej Trela | 5cac7861 | 2010-04-14 17:17:39 +1000 | [diff] [blame] | 3161 | sysfs_notify(&mddev->kobj, NULL, "level"); |
Dan Williams | bb7f8d2 | 2010-05-01 18:14:57 -0700 | [diff] [blame] | 3162 | md_new_event(mddev); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3163 | return rv; |
| 3164 | } |
| 3165 | |
| 3166 | static struct md_sysfs_entry md_level = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3167 | __ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3168 | |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3169 | |
| 3170 | static ssize_t |
| 3171 | layout_show(mddev_t *mddev, char *page) |
| 3172 | { |
| 3173 | /* just a number, not meaningful for all levels */ |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3174 | if (mddev->reshape_position != MaxSector && |
| 3175 | mddev->layout != mddev->new_layout) |
| 3176 | return sprintf(page, "%d (%d)\n", |
| 3177 | mddev->new_layout, mddev->layout); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3178 | return sprintf(page, "%d\n", mddev->layout); |
| 3179 | } |
| 3180 | |
| 3181 | static ssize_t |
| 3182 | layout_store(mddev_t *mddev, const char *buf, size_t len) |
| 3183 | { |
| 3184 | char *e; |
| 3185 | unsigned long n = simple_strtoul(buf, &e, 10); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3186 | |
| 3187 | if (!*buf || (*e && *e != '\n')) |
| 3188 | return -EINVAL; |
| 3189 | |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3190 | if (mddev->pers) { |
| 3191 | int err; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3192 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3193 | return -EBUSY; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3194 | mddev->new_layout = n; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3195 | err = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3196 | if (err) { |
| 3197 | mddev->new_layout = mddev->layout; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3198 | return err; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3199 | } |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3200 | } else { |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3201 | mddev->new_layout = n; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3202 | if (mddev->reshape_position == MaxSector) |
| 3203 | mddev->layout = n; |
| 3204 | } |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3205 | return len; |
| 3206 | } |
| 3207 | static struct md_sysfs_entry md_layout = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3208 | __ATTR(layout, S_IRUGO|S_IWUSR, layout_show, layout_store); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3209 | |
| 3210 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3211 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3212 | raid_disks_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3213 | { |
NeilBrown | bb63654 | 2005-11-08 21:39:45 -0800 | [diff] [blame] | 3214 | if (mddev->raid_disks == 0) |
| 3215 | return 0; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3216 | if (mddev->reshape_position != MaxSector && |
| 3217 | mddev->delta_disks != 0) |
| 3218 | return sprintf(page, "%d (%d)\n", mddev->raid_disks, |
| 3219 | mddev->raid_disks - mddev->delta_disks); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3220 | return sprintf(page, "%d\n", mddev->raid_disks); |
| 3221 | } |
| 3222 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3223 | static int update_raid_disks(mddev_t *mddev, int raid_disks); |
| 3224 | |
| 3225 | static ssize_t |
| 3226 | raid_disks_store(mddev_t *mddev, const char *buf, size_t len) |
| 3227 | { |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3228 | char *e; |
| 3229 | int rv = 0; |
| 3230 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3231 | |
| 3232 | if (!*buf || (*e && *e != '\n')) |
| 3233 | return -EINVAL; |
| 3234 | |
| 3235 | if (mddev->pers) |
| 3236 | rv = update_raid_disks(mddev, n); |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3237 | else if (mddev->reshape_position != MaxSector) { |
| 3238 | int olddisks = mddev->raid_disks - mddev->delta_disks; |
| 3239 | mddev->delta_disks = n - olddisks; |
| 3240 | mddev->raid_disks = n; |
| 3241 | } else |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3242 | mddev->raid_disks = n; |
| 3243 | return rv ? rv : len; |
| 3244 | } |
| 3245 | static struct md_sysfs_entry md_raid_disks = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3246 | __ATTR(raid_disks, S_IRUGO|S_IWUSR, raid_disks_show, raid_disks_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3247 | |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3248 | static ssize_t |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3249 | chunk_size_show(mddev_t *mddev, char *page) |
| 3250 | { |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3251 | if (mddev->reshape_position != MaxSector && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3252 | mddev->chunk_sectors != mddev->new_chunk_sectors) |
| 3253 | return sprintf(page, "%d (%d)\n", |
| 3254 | mddev->new_chunk_sectors << 9, |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3255 | mddev->chunk_sectors << 9); |
| 3256 | return sprintf(page, "%d\n", mddev->chunk_sectors << 9); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | static ssize_t |
| 3260 | chunk_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 3261 | { |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3262 | char *e; |
| 3263 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3264 | |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3265 | if (!*buf || (*e && *e != '\n')) |
| 3266 | return -EINVAL; |
| 3267 | |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3268 | if (mddev->pers) { |
| 3269 | int err; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3270 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3271 | return -EBUSY; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3272 | mddev->new_chunk_sectors = n >> 9; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3273 | err = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3274 | if (err) { |
| 3275 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3276 | return err; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3277 | } |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3278 | } else { |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3279 | mddev->new_chunk_sectors = n >> 9; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3280 | if (mddev->reshape_position == MaxSector) |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3281 | mddev->chunk_sectors = n >> 9; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3282 | } |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3283 | return len; |
| 3284 | } |
| 3285 | static struct md_sysfs_entry md_chunk_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3286 | __ATTR(chunk_size, S_IRUGO|S_IWUSR, chunk_size_show, chunk_size_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3287 | |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3288 | static ssize_t |
| 3289 | resync_start_show(mddev_t *mddev, char *page) |
| 3290 | { |
NeilBrown | d1a7c50 | 2009-03-31 15:24:32 +1100 | [diff] [blame] | 3291 | if (mddev->recovery_cp == MaxSector) |
| 3292 | return sprintf(page, "none\n"); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3293 | return sprintf(page, "%llu\n", (unsigned long long)mddev->recovery_cp); |
| 3294 | } |
| 3295 | |
| 3296 | static ssize_t |
| 3297 | resync_start_store(mddev_t *mddev, const char *buf, size_t len) |
| 3298 | { |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3299 | char *e; |
| 3300 | unsigned long long n = simple_strtoull(buf, &e, 10); |
| 3301 | |
| 3302 | if (mddev->pers) |
| 3303 | return -EBUSY; |
Dan Williams | 06e3c81 | 2009-12-12 21:17:12 -0700 | [diff] [blame] | 3304 | if (cmd_match(buf, "none")) |
| 3305 | n = MaxSector; |
| 3306 | else if (!*buf || (*e && *e != '\n')) |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3307 | return -EINVAL; |
| 3308 | |
| 3309 | mddev->recovery_cp = n; |
| 3310 | return len; |
| 3311 | } |
| 3312 | static struct md_sysfs_entry md_resync_start = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3313 | __ATTR(resync_start, S_IRUGO|S_IWUSR, resync_start_show, resync_start_store); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3314 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3315 | /* |
| 3316 | * The array state can be: |
| 3317 | * |
| 3318 | * clear |
| 3319 | * No devices, no size, no level |
| 3320 | * Equivalent to STOP_ARRAY ioctl |
| 3321 | * inactive |
| 3322 | * May have some settings, but array is not active |
| 3323 | * all IO results in error |
| 3324 | * When written, doesn't tear down array, but just stops it |
| 3325 | * suspended (not supported yet) |
| 3326 | * All IO requests will block. The array can be reconfigured. |
Andre Noll | 910d8cb | 2008-03-25 21:00:53 +0100 | [diff] [blame] | 3327 | * Writing this, if accepted, will block until array is quiescent |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3328 | * readonly |
| 3329 | * no resync can happen. no superblocks get written. |
| 3330 | * write requests fail |
| 3331 | * read-auto |
| 3332 | * like readonly, but behaves like 'clean' on a write request. |
| 3333 | * |
| 3334 | * clean - no pending writes, but otherwise active. |
| 3335 | * When written to inactive array, starts without resync |
| 3336 | * If a write request arrives then |
| 3337 | * if metadata is known, mark 'dirty' and switch to 'active'. |
| 3338 | * if not known, block and switch to write-pending |
| 3339 | * If written to an active array that has pending writes, then fails. |
| 3340 | * active |
| 3341 | * fully active: IO and resync can be happening. |
| 3342 | * When written to inactive array, starts with resync |
| 3343 | * |
| 3344 | * write-pending |
| 3345 | * clean, but writes are blocked waiting for 'active' to be written. |
| 3346 | * |
| 3347 | * active-idle |
| 3348 | * like active, but no writes have been seen for a while (100msec). |
| 3349 | * |
| 3350 | */ |
| 3351 | enum array_state { clear, inactive, suspended, readonly, read_auto, clean, active, |
| 3352 | write_pending, active_idle, bad_word}; |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 3353 | static char *array_states[] = { |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3354 | "clear", "inactive", "suspended", "readonly", "read-auto", "clean", "active", |
| 3355 | "write-pending", "active-idle", NULL }; |
| 3356 | |
| 3357 | static int match_word(const char *word, char **list) |
| 3358 | { |
| 3359 | int n; |
| 3360 | for (n=0; list[n]; n++) |
| 3361 | if (cmd_match(word, list[n])) |
| 3362 | break; |
| 3363 | return n; |
| 3364 | } |
| 3365 | |
| 3366 | static ssize_t |
| 3367 | array_state_show(mddev_t *mddev, char *page) |
| 3368 | { |
| 3369 | enum array_state st = inactive; |
| 3370 | |
| 3371 | if (mddev->pers) |
| 3372 | switch(mddev->ro) { |
| 3373 | case 1: |
| 3374 | st = readonly; |
| 3375 | break; |
| 3376 | case 2: |
| 3377 | st = read_auto; |
| 3378 | break; |
| 3379 | case 0: |
| 3380 | if (mddev->in_sync) |
| 3381 | st = clean; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3382 | else if (test_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 3383 | st = write_pending; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3384 | else if (mddev->safemode) |
| 3385 | st = active_idle; |
| 3386 | else |
| 3387 | st = active; |
| 3388 | } |
| 3389 | else { |
| 3390 | if (list_empty(&mddev->disks) && |
| 3391 | mddev->raid_disks == 0 && |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3392 | mddev->dev_sectors == 0) |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3393 | st = clear; |
| 3394 | else |
| 3395 | st = inactive; |
| 3396 | } |
| 3397 | return sprintf(page, "%s\n", array_states[st]); |
| 3398 | } |
| 3399 | |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3400 | static int do_md_stop(mddev_t * mddev, int ro, int is_open); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 3401 | static int md_set_readonly(mddev_t * mddev, int is_open); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3402 | static int do_md_run(mddev_t * mddev); |
| 3403 | static int restart_array(mddev_t *mddev); |
| 3404 | |
| 3405 | static ssize_t |
| 3406 | array_state_store(mddev_t *mddev, const char *buf, size_t len) |
| 3407 | { |
| 3408 | int err = -EINVAL; |
| 3409 | enum array_state st = match_word(buf, array_states); |
| 3410 | switch(st) { |
| 3411 | case bad_word: |
| 3412 | break; |
| 3413 | case clear: |
| 3414 | /* stopping an active array */ |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 3415 | if (atomic_read(&mddev->openers) > 0) |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3416 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3417 | err = do_md_stop(mddev, 0, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3418 | break; |
| 3419 | case inactive: |
| 3420 | /* stopping an active array */ |
| 3421 | if (mddev->pers) { |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 3422 | if (atomic_read(&mddev->openers) > 0) |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3423 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3424 | err = do_md_stop(mddev, 2, 0); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3425 | } else |
| 3426 | err = 0; /* already inactive */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3427 | break; |
| 3428 | case suspended: |
| 3429 | break; /* not supported yet */ |
| 3430 | case readonly: |
| 3431 | if (mddev->pers) |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 3432 | err = md_set_readonly(mddev, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3433 | else { |
| 3434 | mddev->ro = 1; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3435 | set_disk_ro(mddev->gendisk, 1); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3436 | err = do_md_run(mddev); |
| 3437 | } |
| 3438 | break; |
| 3439 | case read_auto: |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3440 | if (mddev->pers) { |
NeilBrown | 80268ee | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 3441 | if (mddev->ro == 0) |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 3442 | err = md_set_readonly(mddev, 0); |
NeilBrown | 80268ee | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 3443 | else if (mddev->ro == 1) |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3444 | err = restart_array(mddev); |
| 3445 | if (err == 0) { |
| 3446 | mddev->ro = 2; |
| 3447 | set_disk_ro(mddev->gendisk, 0); |
| 3448 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3449 | } else { |
| 3450 | mddev->ro = 2; |
| 3451 | err = do_md_run(mddev); |
| 3452 | } |
| 3453 | break; |
| 3454 | case clean: |
| 3455 | if (mddev->pers) { |
| 3456 | restart_array(mddev); |
| 3457 | spin_lock_irq(&mddev->write_lock); |
| 3458 | if (atomic_read(&mddev->writes_pending) == 0) { |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3459 | if (mddev->in_sync == 0) { |
| 3460 | mddev->in_sync = 1; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3461 | if (mddev->safemode == 1) |
| 3462 | mddev->safemode = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3463 | if (mddev->persistent) |
| 3464 | set_bit(MD_CHANGE_CLEAN, |
| 3465 | &mddev->flags); |
| 3466 | } |
| 3467 | err = 0; |
| 3468 | } else |
| 3469 | err = -EBUSY; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3470 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 5bf2959 | 2009-05-07 12:50:57 +1000 | [diff] [blame] | 3471 | } else |
| 3472 | err = -EINVAL; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3473 | break; |
| 3474 | case active: |
| 3475 | if (mddev->pers) { |
| 3476 | restart_array(mddev); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3477 | if (mddev->external) |
| 3478 | clear_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3479 | wake_up(&mddev->sb_wait); |
| 3480 | err = 0; |
| 3481 | } else { |
| 3482 | mddev->ro = 0; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3483 | set_disk_ro(mddev->gendisk, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3484 | err = do_md_run(mddev); |
| 3485 | } |
| 3486 | break; |
| 3487 | case write_pending: |
| 3488 | case active_idle: |
| 3489 | /* these cannot be set */ |
| 3490 | break; |
| 3491 | } |
| 3492 | if (err) |
| 3493 | return err; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3494 | else { |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 3495 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3496 | return len; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3497 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3498 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3499 | static struct md_sysfs_entry md_array_state = |
| 3500 | __ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3501 | |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3502 | static ssize_t |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 3503 | max_corrected_read_errors_show(mddev_t *mddev, char *page) { |
| 3504 | return sprintf(page, "%d\n", |
| 3505 | atomic_read(&mddev->max_corr_read_errors)); |
| 3506 | } |
| 3507 | |
| 3508 | static ssize_t |
| 3509 | max_corrected_read_errors_store(mddev_t *mddev, const char *buf, size_t len) |
| 3510 | { |
| 3511 | char *e; |
| 3512 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3513 | |
| 3514 | if (*buf && (*e == 0 || *e == '\n')) { |
| 3515 | atomic_set(&mddev->max_corr_read_errors, n); |
| 3516 | return len; |
| 3517 | } |
| 3518 | return -EINVAL; |
| 3519 | } |
| 3520 | |
| 3521 | static struct md_sysfs_entry max_corr_read_errors = |
| 3522 | __ATTR(max_read_errors, S_IRUGO|S_IWUSR, max_corrected_read_errors_show, |
| 3523 | max_corrected_read_errors_store); |
| 3524 | |
| 3525 | static ssize_t |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3526 | null_show(mddev_t *mddev, char *page) |
| 3527 | { |
| 3528 | return -EINVAL; |
| 3529 | } |
| 3530 | |
| 3531 | static ssize_t |
| 3532 | new_dev_store(mddev_t *mddev, const char *buf, size_t len) |
| 3533 | { |
| 3534 | /* buf must be %d:%d\n? giving major and minor numbers */ |
| 3535 | /* The new device is added to the array. |
| 3536 | * If the array has a persistent superblock, we read the |
| 3537 | * superblock to initialise info and check validity. |
| 3538 | * Otherwise, only checking done is that in bind_rdev_to_array, |
| 3539 | * which mainly checks size. |
| 3540 | */ |
| 3541 | char *e; |
| 3542 | int major = simple_strtoul(buf, &e, 10); |
| 3543 | int minor; |
| 3544 | dev_t dev; |
| 3545 | mdk_rdev_t *rdev; |
| 3546 | int err; |
| 3547 | |
| 3548 | if (!*buf || *e != ':' || !e[1] || e[1] == '\n') |
| 3549 | return -EINVAL; |
| 3550 | minor = simple_strtoul(e+1, &e, 10); |
| 3551 | if (*e && *e != '\n') |
| 3552 | return -EINVAL; |
| 3553 | dev = MKDEV(major, minor); |
| 3554 | if (major != MAJOR(dev) || |
| 3555 | minor != MINOR(dev)) |
| 3556 | return -EOVERFLOW; |
| 3557 | |
| 3558 | |
| 3559 | if (mddev->persistent) { |
| 3560 | rdev = md_import_device(dev, mddev->major_version, |
| 3561 | mddev->minor_version); |
| 3562 | if (!IS_ERR(rdev) && !list_empty(&mddev->disks)) { |
| 3563 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 3564 | mdk_rdev_t, same_set); |
| 3565 | err = super_types[mddev->major_version] |
| 3566 | .load_super(rdev, rdev0, mddev->minor_version); |
| 3567 | if (err < 0) |
| 3568 | goto out; |
| 3569 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 3570 | } else if (mddev->external) |
| 3571 | rdev = md_import_device(dev, -2, -1); |
| 3572 | else |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3573 | rdev = md_import_device(dev, -1, -1); |
| 3574 | |
| 3575 | if (IS_ERR(rdev)) |
| 3576 | return PTR_ERR(rdev); |
| 3577 | err = bind_rdev_to_array(rdev, mddev); |
| 3578 | out: |
| 3579 | if (err) |
| 3580 | export_rdev(rdev); |
| 3581 | return err ? err : len; |
| 3582 | } |
| 3583 | |
| 3584 | static struct md_sysfs_entry md_new_device = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3585 | __ATTR(new_dev, S_IWUSR, null_show, new_dev_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3586 | |
| 3587 | static ssize_t |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 3588 | bitmap_store(mddev_t *mddev, const char *buf, size_t len) |
| 3589 | { |
| 3590 | char *end; |
| 3591 | unsigned long chunk, end_chunk; |
| 3592 | |
| 3593 | if (!mddev->bitmap) |
| 3594 | goto out; |
| 3595 | /* buf should be <chunk> <chunk> ... or <chunk>-<chunk> ... (range) */ |
| 3596 | while (*buf) { |
| 3597 | chunk = end_chunk = simple_strtoul(buf, &end, 0); |
| 3598 | if (buf == end) break; |
| 3599 | if (*end == '-') { /* range */ |
| 3600 | buf = end + 1; |
| 3601 | end_chunk = simple_strtoul(buf, &end, 0); |
| 3602 | if (buf == end) break; |
| 3603 | } |
| 3604 | if (*end && !isspace(*end)) break; |
| 3605 | bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk); |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 3606 | buf = skip_spaces(end); |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 3607 | } |
| 3608 | bitmap_unplug(mddev->bitmap); /* flush the bits to disk */ |
| 3609 | out: |
| 3610 | return len; |
| 3611 | } |
| 3612 | |
| 3613 | static struct md_sysfs_entry md_bitmap = |
| 3614 | __ATTR(bitmap_set_bits, S_IWUSR, null_show, bitmap_store); |
| 3615 | |
| 3616 | static ssize_t |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3617 | size_show(mddev_t *mddev, char *page) |
| 3618 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3619 | return sprintf(page, "%llu\n", |
| 3620 | (unsigned long long)mddev->dev_sectors / 2); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3621 | } |
| 3622 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3623 | static int update_size(mddev_t *mddev, sector_t num_sectors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3624 | |
| 3625 | static ssize_t |
| 3626 | size_store(mddev_t *mddev, const char *buf, size_t len) |
| 3627 | { |
| 3628 | /* If array is inactive, we can reduce the component size, but |
| 3629 | * not increase it (except from 0). |
| 3630 | * If array is active, we can try an on-line resize |
| 3631 | */ |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 3632 | sector_t sectors; |
| 3633 | int err = strict_blocks_to_sectors(buf, §ors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3634 | |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3635 | if (err < 0) |
| 3636 | return err; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3637 | if (mddev->pers) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3638 | err = update_size(mddev, sectors); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 3639 | md_update_sb(mddev, 1); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3640 | } else { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3641 | if (mddev->dev_sectors == 0 || |
| 3642 | mddev->dev_sectors > sectors) |
| 3643 | mddev->dev_sectors = sectors; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3644 | else |
| 3645 | err = -ENOSPC; |
| 3646 | } |
| 3647 | return err ? err : len; |
| 3648 | } |
| 3649 | |
| 3650 | static struct md_sysfs_entry md_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3651 | __ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3652 | |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3653 | |
| 3654 | /* Metdata version. |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3655 | * This is one of |
| 3656 | * 'none' for arrays with no metadata (good luck...) |
| 3657 | * 'external' for arrays with externally managed metadata, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3658 | * or N.M for internally known formats |
| 3659 | */ |
| 3660 | static ssize_t |
| 3661 | metadata_show(mddev_t *mddev, char *page) |
| 3662 | { |
| 3663 | if (mddev->persistent) |
| 3664 | return sprintf(page, "%d.%d\n", |
| 3665 | mddev->major_version, mddev->minor_version); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3666 | else if (mddev->external) |
| 3667 | return sprintf(page, "external:%s\n", mddev->metadata_type); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3668 | else |
| 3669 | return sprintf(page, "none\n"); |
| 3670 | } |
| 3671 | |
| 3672 | static ssize_t |
| 3673 | metadata_store(mddev_t *mddev, const char *buf, size_t len) |
| 3674 | { |
| 3675 | int major, minor; |
| 3676 | char *e; |
NeilBrown | ea43ddd | 2008-10-13 11:55:11 +1100 | [diff] [blame] | 3677 | /* Changing the details of 'external' metadata is |
| 3678 | * always permitted. Otherwise there must be |
| 3679 | * no devices attached to the array. |
| 3680 | */ |
| 3681 | if (mddev->external && strncmp(buf, "external:", 9) == 0) |
| 3682 | ; |
| 3683 | else if (!list_empty(&mddev->disks)) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3684 | return -EBUSY; |
| 3685 | |
| 3686 | if (cmd_match(buf, "none")) { |
| 3687 | mddev->persistent = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3688 | mddev->external = 0; |
| 3689 | mddev->major_version = 0; |
| 3690 | mddev->minor_version = 90; |
| 3691 | return len; |
| 3692 | } |
| 3693 | if (strncmp(buf, "external:", 9) == 0) { |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 3694 | size_t namelen = len-9; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3695 | if (namelen >= sizeof(mddev->metadata_type)) |
| 3696 | namelen = sizeof(mddev->metadata_type)-1; |
| 3697 | strncpy(mddev->metadata_type, buf+9, namelen); |
| 3698 | mddev->metadata_type[namelen] = 0; |
| 3699 | if (namelen && mddev->metadata_type[namelen-1] == '\n') |
| 3700 | mddev->metadata_type[--namelen] = 0; |
| 3701 | mddev->persistent = 0; |
| 3702 | mddev->external = 1; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3703 | mddev->major_version = 0; |
| 3704 | mddev->minor_version = 90; |
| 3705 | return len; |
| 3706 | } |
| 3707 | major = simple_strtoul(buf, &e, 10); |
| 3708 | if (e==buf || *e != '.') |
| 3709 | return -EINVAL; |
| 3710 | buf = e+1; |
| 3711 | minor = simple_strtoul(buf, &e, 10); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 3712 | if (e==buf || (*e && *e != '\n') ) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3713 | return -EINVAL; |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 3714 | if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3715 | return -ENOENT; |
| 3716 | mddev->major_version = major; |
| 3717 | mddev->minor_version = minor; |
| 3718 | mddev->persistent = 1; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3719 | mddev->external = 0; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3720 | return len; |
| 3721 | } |
| 3722 | |
| 3723 | static struct md_sysfs_entry md_metadata = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3724 | __ATTR(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3725 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3726 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3727 | action_show(mddev_t *mddev, char *page) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3728 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3729 | char *type = "idle"; |
NeilBrown | b6a9ce6 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 3730 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 3731 | type = "frozen"; |
| 3732 | else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
NeilBrown | 2b12ab6 | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 3733 | (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3734 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 3735 | type = "reshape"; |
| 3736 | else if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3737 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 3738 | type = "resync"; |
| 3739 | else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 3740 | type = "check"; |
| 3741 | else |
| 3742 | type = "repair"; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3743 | } else if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3744 | type = "recover"; |
| 3745 | } |
| 3746 | return sprintf(page, "%s\n", type); |
| 3747 | } |
| 3748 | |
| 3749 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3750 | action_store(mddev_t *mddev, const char *page, size_t len) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3751 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3752 | if (!mddev->pers || !mddev->pers->sync_request) |
| 3753 | return -EINVAL; |
| 3754 | |
NeilBrown | b6a9ce6 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 3755 | if (cmd_match(page, "frozen")) |
| 3756 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3757 | else |
| 3758 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3759 | |
| 3760 | if (cmd_match(page, "idle") || cmd_match(page, "frozen")) { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3761 | if (mddev->sync_thread) { |
| 3762 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 3763 | md_unregister_thread(mddev->sync_thread); |
| 3764 | mddev->sync_thread = NULL; |
| 3765 | mddev->recovery = 0; |
| 3766 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3767 | } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 3768 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3769 | return -EBUSY; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3770 | else if (cmd_match(page, "resync")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3771 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3772 | else if (cmd_match(page, "recover")) { |
| 3773 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
| 3774 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3775 | } else if (cmd_match(page, "reshape")) { |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3776 | int err; |
| 3777 | if (mddev->pers->start_reshape == NULL) |
| 3778 | return -EINVAL; |
| 3779 | err = mddev->pers->start_reshape(mddev); |
| 3780 | if (err) |
| 3781 | return err; |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 3782 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3783 | } else { |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 3784 | if (cmd_match(page, "check")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3785 | set_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
NeilBrown | 2adc7d4 | 2006-05-20 14:59:57 -0700 | [diff] [blame] | 3786 | else if (!cmd_match(page, "repair")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3787 | return -EINVAL; |
| 3788 | set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
| 3789 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3790 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3791 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3792 | md_wakeup_thread(mddev->thread); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 3793 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3794 | return len; |
| 3795 | } |
| 3796 | |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3797 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3798 | mismatch_cnt_show(mddev_t *mddev, char *page) |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3799 | { |
| 3800 | return sprintf(page, "%llu\n", |
| 3801 | (unsigned long long) mddev->resync_mismatches); |
| 3802 | } |
| 3803 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3804 | static struct md_sysfs_entry md_scan_mode = |
| 3805 | __ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3806 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3807 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3808 | static struct md_sysfs_entry md_mismatches = __ATTR_RO(mismatch_cnt); |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3809 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3810 | static ssize_t |
| 3811 | sync_min_show(mddev_t *mddev, char *page) |
| 3812 | { |
| 3813 | return sprintf(page, "%d (%s)\n", speed_min(mddev), |
| 3814 | mddev->sync_speed_min ? "local": "system"); |
| 3815 | } |
| 3816 | |
| 3817 | static ssize_t |
| 3818 | sync_min_store(mddev_t *mddev, const char *buf, size_t len) |
| 3819 | { |
| 3820 | int min; |
| 3821 | char *e; |
| 3822 | if (strncmp(buf, "system", 6)==0) { |
| 3823 | mddev->sync_speed_min = 0; |
| 3824 | return len; |
| 3825 | } |
| 3826 | min = simple_strtoul(buf, &e, 10); |
| 3827 | if (buf == e || (*e && *e != '\n') || min <= 0) |
| 3828 | return -EINVAL; |
| 3829 | mddev->sync_speed_min = min; |
| 3830 | return len; |
| 3831 | } |
| 3832 | |
| 3833 | static struct md_sysfs_entry md_sync_min = |
| 3834 | __ATTR(sync_speed_min, S_IRUGO|S_IWUSR, sync_min_show, sync_min_store); |
| 3835 | |
| 3836 | static ssize_t |
| 3837 | sync_max_show(mddev_t *mddev, char *page) |
| 3838 | { |
| 3839 | return sprintf(page, "%d (%s)\n", speed_max(mddev), |
| 3840 | mddev->sync_speed_max ? "local": "system"); |
| 3841 | } |
| 3842 | |
| 3843 | static ssize_t |
| 3844 | sync_max_store(mddev_t *mddev, const char *buf, size_t len) |
| 3845 | { |
| 3846 | int max; |
| 3847 | char *e; |
| 3848 | if (strncmp(buf, "system", 6)==0) { |
| 3849 | mddev->sync_speed_max = 0; |
| 3850 | return len; |
| 3851 | } |
| 3852 | max = simple_strtoul(buf, &e, 10); |
| 3853 | if (buf == e || (*e && *e != '\n') || max <= 0) |
| 3854 | return -EINVAL; |
| 3855 | mddev->sync_speed_max = max; |
| 3856 | return len; |
| 3857 | } |
| 3858 | |
| 3859 | static struct md_sysfs_entry md_sync_max = |
| 3860 | __ATTR(sync_speed_max, S_IRUGO|S_IWUSR, sync_max_show, sync_max_store); |
| 3861 | |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 3862 | static ssize_t |
| 3863 | degraded_show(mddev_t *mddev, char *page) |
| 3864 | { |
| 3865 | return sprintf(page, "%d\n", mddev->degraded); |
| 3866 | } |
| 3867 | static struct md_sysfs_entry md_degraded = __ATTR_RO(degraded); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3868 | |
| 3869 | static ssize_t |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 3870 | sync_force_parallel_show(mddev_t *mddev, char *page) |
| 3871 | { |
| 3872 | return sprintf(page, "%d\n", mddev->parallel_resync); |
| 3873 | } |
| 3874 | |
| 3875 | static ssize_t |
| 3876 | sync_force_parallel_store(mddev_t *mddev, const char *buf, size_t len) |
| 3877 | { |
| 3878 | long n; |
| 3879 | |
| 3880 | if (strict_strtol(buf, 10, &n)) |
| 3881 | return -EINVAL; |
| 3882 | |
| 3883 | if (n != 0 && n != 1) |
| 3884 | return -EINVAL; |
| 3885 | |
| 3886 | mddev->parallel_resync = n; |
| 3887 | |
| 3888 | if (mddev->sync_thread) |
| 3889 | wake_up(&resync_wait); |
| 3890 | |
| 3891 | return len; |
| 3892 | } |
| 3893 | |
| 3894 | /* force parallel resync, even with shared block devices */ |
| 3895 | static struct md_sysfs_entry md_sync_force_parallel = |
| 3896 | __ATTR(sync_force_parallel, S_IRUGO|S_IWUSR, |
| 3897 | sync_force_parallel_show, sync_force_parallel_store); |
| 3898 | |
| 3899 | static ssize_t |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3900 | sync_speed_show(mddev_t *mddev, char *page) |
| 3901 | { |
| 3902 | unsigned long resync, dt, db; |
NeilBrown | d1a7c50 | 2009-03-31 15:24:32 +1100 | [diff] [blame] | 3903 | if (mddev->curr_resync == 0) |
| 3904 | return sprintf(page, "none\n"); |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3905 | resync = mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active); |
| 3906 | dt = (jiffies - mddev->resync_mark) / HZ; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3907 | if (!dt) dt++; |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3908 | db = resync - mddev->resync_mark_cnt; |
| 3909 | return sprintf(page, "%lu\n", db/dt/2); /* K/sec */ |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3910 | } |
| 3911 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3912 | static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3913 | |
| 3914 | static ssize_t |
| 3915 | sync_completed_show(mddev_t *mddev, char *page) |
| 3916 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3917 | unsigned long max_sectors, resync; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3918 | |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 3919 | if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3920 | return sprintf(page, "none\n"); |
| 3921 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3922 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3923 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3924 | else |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3925 | max_sectors = mddev->dev_sectors; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3926 | |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 3927 | resync = mddev->curr_resync_completed; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3928 | return sprintf(page, "%lu / %lu\n", resync, max_sectors); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3929 | } |
| 3930 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3931 | static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3932 | |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3933 | static ssize_t |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3934 | min_sync_show(mddev_t *mddev, char *page) |
| 3935 | { |
| 3936 | return sprintf(page, "%llu\n", |
| 3937 | (unsigned long long)mddev->resync_min); |
| 3938 | } |
| 3939 | static ssize_t |
| 3940 | min_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3941 | { |
| 3942 | unsigned long long min; |
| 3943 | if (strict_strtoull(buf, 10, &min)) |
| 3944 | return -EINVAL; |
| 3945 | if (min > mddev->resync_max) |
| 3946 | return -EINVAL; |
| 3947 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3948 | return -EBUSY; |
| 3949 | |
| 3950 | /* Must be a multiple of chunk_size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3951 | if (mddev->chunk_sectors) { |
raz ben yehuda | 2ac06c3 | 2009-06-16 17:01:42 +1000 | [diff] [blame] | 3952 | sector_t temp = min; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3953 | if (sector_div(temp, mddev->chunk_sectors)) |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3954 | return -EINVAL; |
| 3955 | } |
| 3956 | mddev->resync_min = min; |
| 3957 | |
| 3958 | return len; |
| 3959 | } |
| 3960 | |
| 3961 | static struct md_sysfs_entry md_min_sync = |
| 3962 | __ATTR(sync_min, S_IRUGO|S_IWUSR, min_sync_show, min_sync_store); |
| 3963 | |
| 3964 | static ssize_t |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3965 | max_sync_show(mddev_t *mddev, char *page) |
| 3966 | { |
| 3967 | if (mddev->resync_max == MaxSector) |
| 3968 | return sprintf(page, "max\n"); |
| 3969 | else |
| 3970 | return sprintf(page, "%llu\n", |
| 3971 | (unsigned long long)mddev->resync_max); |
| 3972 | } |
| 3973 | static ssize_t |
| 3974 | max_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3975 | { |
| 3976 | if (strncmp(buf, "max", 3) == 0) |
| 3977 | mddev->resync_max = MaxSector; |
| 3978 | else { |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3979 | unsigned long long max; |
| 3980 | if (strict_strtoull(buf, 10, &max)) |
| 3981 | return -EINVAL; |
| 3982 | if (max < mddev->resync_min) |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3983 | return -EINVAL; |
| 3984 | if (max < mddev->resync_max && |
NeilBrown | 4d484a4 | 2009-08-13 10:41:50 +1000 | [diff] [blame] | 3985 | mddev->ro == 0 && |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3986 | test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3987 | return -EBUSY; |
| 3988 | |
| 3989 | /* Must be a multiple of chunk_size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3990 | if (mddev->chunk_sectors) { |
raz ben yehuda | 2ac06c3 | 2009-06-16 17:01:42 +1000 | [diff] [blame] | 3991 | sector_t temp = max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3992 | if (sector_div(temp, mddev->chunk_sectors)) |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3993 | return -EINVAL; |
| 3994 | } |
| 3995 | mddev->resync_max = max; |
| 3996 | } |
| 3997 | wake_up(&mddev->recovery_wait); |
| 3998 | return len; |
| 3999 | } |
| 4000 | |
| 4001 | static struct md_sysfs_entry md_max_sync = |
| 4002 | __ATTR(sync_max, S_IRUGO|S_IWUSR, max_sync_show, max_sync_store); |
| 4003 | |
| 4004 | static ssize_t |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4005 | suspend_lo_show(mddev_t *mddev, char *page) |
| 4006 | { |
| 4007 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_lo); |
| 4008 | } |
| 4009 | |
| 4010 | static ssize_t |
| 4011 | suspend_lo_store(mddev_t *mddev, const char *buf, size_t len) |
| 4012 | { |
| 4013 | char *e; |
| 4014 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 4015 | |
NeilBrown | b8d966e | 2009-07-01 11:14:04 +1000 | [diff] [blame] | 4016 | if (mddev->pers == NULL || |
| 4017 | mddev->pers->quiesce == NULL) |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4018 | return -EINVAL; |
| 4019 | if (buf == e || (*e && *e != '\n')) |
| 4020 | return -EINVAL; |
| 4021 | if (new >= mddev->suspend_hi || |
| 4022 | (new > mddev->suspend_lo && new < mddev->suspend_hi)) { |
| 4023 | mddev->suspend_lo = new; |
| 4024 | mddev->pers->quiesce(mddev, 2); |
| 4025 | return len; |
| 4026 | } else |
| 4027 | return -EINVAL; |
| 4028 | } |
| 4029 | static struct md_sysfs_entry md_suspend_lo = |
| 4030 | __ATTR(suspend_lo, S_IRUGO|S_IWUSR, suspend_lo_show, suspend_lo_store); |
| 4031 | |
| 4032 | |
| 4033 | static ssize_t |
| 4034 | suspend_hi_show(mddev_t *mddev, char *page) |
| 4035 | { |
| 4036 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_hi); |
| 4037 | } |
| 4038 | |
| 4039 | static ssize_t |
| 4040 | suspend_hi_store(mddev_t *mddev, const char *buf, size_t len) |
| 4041 | { |
| 4042 | char *e; |
| 4043 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 4044 | |
NeilBrown | b8d966e | 2009-07-01 11:14:04 +1000 | [diff] [blame] | 4045 | if (mddev->pers == NULL || |
| 4046 | mddev->pers->quiesce == NULL) |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4047 | return -EINVAL; |
| 4048 | if (buf == e || (*e && *e != '\n')) |
| 4049 | return -EINVAL; |
| 4050 | if ((new <= mddev->suspend_lo && mddev->suspend_lo >= mddev->suspend_hi) || |
| 4051 | (new > mddev->suspend_lo && new > mddev->suspend_hi)) { |
| 4052 | mddev->suspend_hi = new; |
| 4053 | mddev->pers->quiesce(mddev, 1); |
| 4054 | mddev->pers->quiesce(mddev, 0); |
| 4055 | return len; |
| 4056 | } else |
| 4057 | return -EINVAL; |
| 4058 | } |
| 4059 | static struct md_sysfs_entry md_suspend_hi = |
| 4060 | __ATTR(suspend_hi, S_IRUGO|S_IWUSR, suspend_hi_show, suspend_hi_store); |
| 4061 | |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 4062 | static ssize_t |
| 4063 | reshape_position_show(mddev_t *mddev, char *page) |
| 4064 | { |
| 4065 | if (mddev->reshape_position != MaxSector) |
| 4066 | return sprintf(page, "%llu\n", |
| 4067 | (unsigned long long)mddev->reshape_position); |
| 4068 | strcpy(page, "none\n"); |
| 4069 | return 5; |
| 4070 | } |
| 4071 | |
| 4072 | static ssize_t |
| 4073 | reshape_position_store(mddev_t *mddev, const char *buf, size_t len) |
| 4074 | { |
| 4075 | char *e; |
| 4076 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 4077 | if (mddev->pers) |
| 4078 | return -EBUSY; |
| 4079 | if (buf == e || (*e && *e != '\n')) |
| 4080 | return -EINVAL; |
| 4081 | mddev->reshape_position = new; |
| 4082 | mddev->delta_disks = 0; |
| 4083 | mddev->new_level = mddev->level; |
| 4084 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4085 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 4086 | return len; |
| 4087 | } |
| 4088 | |
| 4089 | static struct md_sysfs_entry md_reshape_position = |
| 4090 | __ATTR(reshape_position, S_IRUGO|S_IWUSR, reshape_position_show, |
| 4091 | reshape_position_store); |
| 4092 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4093 | static ssize_t |
| 4094 | array_size_show(mddev_t *mddev, char *page) |
| 4095 | { |
| 4096 | if (mddev->external_size) |
| 4097 | return sprintf(page, "%llu\n", |
| 4098 | (unsigned long long)mddev->array_sectors/2); |
| 4099 | else |
| 4100 | return sprintf(page, "default\n"); |
| 4101 | } |
| 4102 | |
| 4103 | static ssize_t |
| 4104 | array_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 4105 | { |
| 4106 | sector_t sectors; |
| 4107 | |
| 4108 | if (strncmp(buf, "default", 7) == 0) { |
| 4109 | if (mddev->pers) |
| 4110 | sectors = mddev->pers->size(mddev, 0, 0); |
| 4111 | else |
| 4112 | sectors = mddev->array_sectors; |
| 4113 | |
| 4114 | mddev->external_size = 0; |
| 4115 | } else { |
| 4116 | if (strict_blocks_to_sectors(buf, §ors) < 0) |
| 4117 | return -EINVAL; |
| 4118 | if (mddev->pers && mddev->pers->size(mddev, 0, 0) < sectors) |
NeilBrown | 2b69c83 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 4119 | return -E2BIG; |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4120 | |
| 4121 | mddev->external_size = 1; |
| 4122 | } |
| 4123 | |
| 4124 | mddev->array_sectors = sectors; |
| 4125 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4126 | if (mddev->pers) |
| 4127 | revalidate_disk(mddev->gendisk); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4128 | |
| 4129 | return len; |
| 4130 | } |
| 4131 | |
| 4132 | static struct md_sysfs_entry md_array_size = |
| 4133 | __ATTR(array_size, S_IRUGO|S_IWUSR, array_size_show, |
| 4134 | array_size_store); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4135 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4136 | static struct attribute *md_default_attrs[] = { |
| 4137 | &md_level.attr, |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 4138 | &md_layout.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4139 | &md_raid_disks.attr, |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 4140 | &md_chunk_size.attr, |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4141 | &md_size.attr, |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 4142 | &md_resync_start.attr, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 4143 | &md_metadata.attr, |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 4144 | &md_new_device.attr, |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 4145 | &md_safe_delay.attr, |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4146 | &md_array_state.attr, |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 4147 | &md_reshape_position.attr, |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4148 | &md_array_size.attr, |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 4149 | &max_corr_read_errors.attr, |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 4150 | NULL, |
| 4151 | }; |
| 4152 | |
| 4153 | static struct attribute *md_redundancy_attrs[] = { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 4154 | &md_scan_mode.attr, |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 4155 | &md_mismatches.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 4156 | &md_sync_min.attr, |
| 4157 | &md_sync_max.attr, |
| 4158 | &md_sync_speed.attr, |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 4159 | &md_sync_force_parallel.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 4160 | &md_sync_completed.attr, |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 4161 | &md_min_sync.attr, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4162 | &md_max_sync.attr, |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4163 | &md_suspend_lo.attr, |
| 4164 | &md_suspend_hi.attr, |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 4165 | &md_bitmap.attr, |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 4166 | &md_degraded.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4167 | NULL, |
| 4168 | }; |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 4169 | static struct attribute_group md_redundancy_group = { |
| 4170 | .name = NULL, |
| 4171 | .attrs = md_redundancy_attrs, |
| 4172 | }; |
| 4173 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4174 | |
| 4175 | static ssize_t |
| 4176 | md_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 4177 | { |
| 4178 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 4179 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4180 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4181 | |
| 4182 | if (!entry->show) |
| 4183 | return -EIO; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4184 | rv = mddev_lock(mddev); |
| 4185 | if (!rv) { |
| 4186 | rv = entry->show(mddev, page); |
| 4187 | mddev_unlock(mddev); |
| 4188 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4189 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | static ssize_t |
| 4193 | md_attr_store(struct kobject *kobj, struct attribute *attr, |
| 4194 | const char *page, size_t length) |
| 4195 | { |
| 4196 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 4197 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4198 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4199 | |
| 4200 | if (!entry->store) |
| 4201 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 4202 | if (!capable(CAP_SYS_ADMIN)) |
| 4203 | return -EACCES; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4204 | rv = mddev_lock(mddev); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4205 | if (mddev->hold_active == UNTIL_IOCTL) |
| 4206 | mddev->hold_active = 0; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4207 | if (!rv) { |
| 4208 | rv = entry->store(mddev, page, length); |
| 4209 | mddev_unlock(mddev); |
| 4210 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4211 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | static void md_free(struct kobject *ko) |
| 4215 | { |
| 4216 | mddev_t *mddev = container_of(ko, mddev_t, kobj); |
NeilBrown | a21d150 | 2009-01-09 08:31:09 +1100 | [diff] [blame] | 4217 | |
| 4218 | if (mddev->sysfs_state) |
| 4219 | sysfs_put(mddev->sysfs_state); |
| 4220 | |
| 4221 | if (mddev->gendisk) { |
| 4222 | del_gendisk(mddev->gendisk); |
| 4223 | put_disk(mddev->gendisk); |
| 4224 | } |
| 4225 | if (mddev->queue) |
| 4226 | blk_cleanup_queue(mddev->queue); |
| 4227 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4228 | kfree(mddev); |
| 4229 | } |
| 4230 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 4231 | static const struct sysfs_ops md_sysfs_ops = { |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4232 | .show = md_attr_show, |
| 4233 | .store = md_attr_store, |
| 4234 | }; |
| 4235 | static struct kobj_type md_ktype = { |
| 4236 | .release = md_free, |
| 4237 | .sysfs_ops = &md_sysfs_ops, |
| 4238 | .default_attrs = md_default_attrs, |
| 4239 | }; |
| 4240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | int mdp_major = 0; |
| 4242 | |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 4243 | static void mddev_delayed_delete(struct work_struct *ws) |
| 4244 | { |
| 4245 | mddev_t *mddev = container_of(ws, mddev_t, del_work); |
| 4246 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 4247 | sysfs_remove_group(&mddev->kobj, &md_bitmap_group); |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 4248 | kobject_del(&mddev->kobj); |
| 4249 | kobject_put(&mddev->kobj); |
| 4250 | } |
| 4251 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4252 | static int md_alloc(dev_t dev, char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 4254 | static DEFINE_MUTEX(disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | mddev_t *mddev = mddev_find(dev); |
| 4256 | struct gendisk *disk; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4257 | int partitioned; |
| 4258 | int shift; |
| 4259 | int unit; |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 4260 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | |
| 4262 | if (!mddev) |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4263 | return -ENODEV; |
| 4264 | |
| 4265 | partitioned = (MAJOR(mddev->unit) != MD_MAJOR); |
| 4266 | shift = partitioned ? MdpMinorShift : 0; |
| 4267 | unit = MINOR(mddev->unit) >> shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4269 | /* wait for any previous instance if this device |
| 4270 | * to be completed removed (mddev_delayed_delete). |
| 4271 | */ |
| 4272 | flush_scheduled_work(); |
| 4273 | |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 4274 | mutex_lock(&disks_mutex); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4275 | error = -EEXIST; |
| 4276 | if (mddev->gendisk) |
| 4277 | goto abort; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4278 | |
| 4279 | if (name) { |
| 4280 | /* Need to ensure that 'name' is not a duplicate. |
| 4281 | */ |
| 4282 | mddev_t *mddev2; |
| 4283 | spin_lock(&all_mddevs_lock); |
| 4284 | |
| 4285 | list_for_each_entry(mddev2, &all_mddevs, all_mddevs) |
| 4286 | if (mddev2->gendisk && |
| 4287 | strcmp(mddev2->gendisk->disk_name, name) == 0) { |
| 4288 | spin_unlock(&all_mddevs_lock); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4289 | goto abort; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4290 | } |
| 4291 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | } |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4293 | |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4294 | error = -ENOMEM; |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4295 | mddev->queue = blk_alloc_queue(GFP_KERNEL); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4296 | if (!mddev->queue) |
| 4297 | goto abort; |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4298 | mddev->queue->queuedata = mddev; |
| 4299 | |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4300 | /* Can be unlocked because the queue is new: no concurrency */ |
| 4301 | queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, mddev->queue); |
| 4302 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4303 | blk_queue_make_request(mddev->queue, md_make_request); |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | disk = alloc_disk(1 << shift); |
| 4306 | if (!disk) { |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4307 | blk_cleanup_queue(mddev->queue); |
| 4308 | mddev->queue = NULL; |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4309 | goto abort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | } |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4311 | disk->major = MAJOR(mddev->unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | disk->first_minor = unit << shift; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4313 | if (name) |
| 4314 | strcpy(disk->disk_name, name); |
| 4315 | else if (partitioned) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | sprintf(disk->disk_name, "md_d%d", unit); |
Greg Kroah-Hartman | ce7b0f46 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 4317 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | sprintf(disk->disk_name, "md%d", unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | disk->fops = &md_fops; |
| 4320 | disk->private_data = mddev; |
| 4321 | disk->queue = mddev->queue; |
NeilBrown | 92850bb | 2008-10-21 13:25:32 +1100 | [diff] [blame] | 4322 | /* Allow extended partitions. This makes the |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4323 | * 'mdp' device redundant, but we can't really |
NeilBrown | 92850bb | 2008-10-21 13:25:32 +1100 | [diff] [blame] | 4324 | * remove it now. |
| 4325 | */ |
| 4326 | disk->flags |= GENHD_FL_EXT_DEVT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | add_disk(disk); |
| 4328 | mddev->gendisk = disk; |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 4329 | error = kobject_init_and_add(&mddev->kobj, &md_ktype, |
| 4330 | &disk_to_dev(disk)->kobj, "%s", "md"); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4331 | if (error) { |
| 4332 | /* This isn't possible, but as kobject_init_and_add is marked |
| 4333 | * __must_check, we must do something with the result |
| 4334 | */ |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4335 | printk(KERN_WARNING "md: cannot register %s/md - name in use\n", |
| 4336 | disk->disk_name); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4337 | error = 0; |
| 4338 | } |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4339 | if (mddev->kobj.sd && |
| 4340 | sysfs_create_group(&mddev->kobj, &md_bitmap_group)) |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 4341 | printk(KERN_DEBUG "pointless warning\n"); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4342 | abort: |
| 4343 | mutex_unlock(&disks_mutex); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4344 | if (!error && mddev->kobj.sd) { |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 4345 | kobject_uevent(&mddev->kobj, KOBJ_ADD); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4346 | mddev->sysfs_state = sysfs_get_dirent_safe(mddev->kobj.sd, "array_state"); |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 4347 | } |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4348 | mddev_put(mddev); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4349 | return error; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | static struct kobject *md_probe(dev_t dev, int *part, void *data) |
| 4353 | { |
| 4354 | md_alloc(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | return NULL; |
| 4356 | } |
| 4357 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4358 | static int add_named_array(const char *val, struct kernel_param *kp) |
| 4359 | { |
| 4360 | /* val must be "md_*" where * is not all digits. |
| 4361 | * We allocate an array with a large free minor number, and |
| 4362 | * set the name to val. val must not already be an active name. |
| 4363 | */ |
| 4364 | int len = strlen(val); |
| 4365 | char buf[DISK_NAME_LEN]; |
| 4366 | |
| 4367 | while (len && val[len-1] == '\n') |
| 4368 | len--; |
| 4369 | if (len >= DISK_NAME_LEN) |
| 4370 | return -E2BIG; |
| 4371 | strlcpy(buf, val, len+1); |
| 4372 | if (strncmp(buf, "md_", 3) != 0) |
| 4373 | return -EINVAL; |
| 4374 | return md_alloc(0, buf); |
| 4375 | } |
| 4376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | static void md_safemode_timeout(unsigned long data) |
| 4378 | { |
| 4379 | mddev_t *mddev = (mddev_t *) data; |
| 4380 | |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 4381 | if (!atomic_read(&mddev->writes_pending)) { |
| 4382 | mddev->safemode = 1; |
| 4383 | if (mddev->external) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4384 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 4385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | md_wakeup_thread(mddev->thread); |
| 4387 | } |
| 4388 | |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4389 | static int start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4391 | int md_run(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4393 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | mdk_rdev_t *rdev; |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4395 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4397 | if (list_empty(&mddev->disks)) |
| 4398 | /* cannot run an array with no devices.. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | |
| 4401 | if (mddev->pers) |
| 4402 | return -EBUSY; |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 4403 | /* Cannot run until previous stop completes properly */ |
| 4404 | if (mddev->sysfs_active) |
| 4405 | return -EBUSY; |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 4406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | /* |
| 4408 | * Analyze all RAID superblock(s) |
| 4409 | */ |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4410 | if (!mddev->raid_disks) { |
| 4411 | if (!mddev->persistent) |
| 4412 | return -EINVAL; |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4413 | analyze_sbs(mddev); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4416 | if (mddev->level != LEVEL_NONE) |
| 4417 | request_module("md-level-%d", mddev->level); |
| 4418 | else if (mddev->clevel[0]) |
| 4419 | request_module("md-%s", mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | |
| 4421 | /* |
| 4422 | * Drop all container device buffers, from now on |
| 4423 | * the only valid external interface is through the md |
| 4424 | * device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4426 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4427 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | continue; |
| 4429 | sync_blockdev(rdev->bdev); |
Peter Zijlstra | f98393a | 2007-05-06 14:49:54 -0700 | [diff] [blame] | 4430 | invalidate_bdev(rdev->bdev); |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4431 | |
| 4432 | /* perform some consistency tests on the device. |
| 4433 | * We don't want the data to overlap the metadata, |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4434 | * Internal Bitmap issues have been handled elsewhere. |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4435 | */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4436 | if (rdev->data_offset < rdev->sb_start) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4437 | if (mddev->dev_sectors && |
| 4438 | rdev->data_offset + mddev->dev_sectors |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4439 | > rdev->sb_start) { |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4440 | printk("md: %s: data overlaps metadata\n", |
| 4441 | mdname(mddev)); |
| 4442 | return -EINVAL; |
| 4443 | } |
| 4444 | } else { |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4445 | if (rdev->sb_start + rdev->sb_size/512 |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4446 | > rdev->data_offset) { |
| 4447 | printk("md: %s: metadata overlaps data\n", |
| 4448 | mdname(mddev)); |
| 4449 | return -EINVAL; |
| 4450 | } |
| 4451 | } |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4452 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | } |
| 4454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | spin_lock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4456 | pers = find_pers(mddev->level, mddev->clevel); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4457 | if (!pers || !try_module_get(pers->owner)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | spin_unlock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4459 | if (mddev->level != LEVEL_NONE) |
| 4460 | printk(KERN_WARNING "md: personality for level %d is not loaded!\n", |
| 4461 | mddev->level); |
| 4462 | else |
| 4463 | printk(KERN_WARNING "md: personality for level %s is not loaded!\n", |
| 4464 | mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | return -EINVAL; |
| 4466 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4467 | mddev->pers = pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | spin_unlock(&pers_lock); |
NeilBrown | 34817e8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4469 | if (mddev->level != pers->level) { |
| 4470 | mddev->level = pers->level; |
| 4471 | mddev->new_level = pers->level; |
| 4472 | } |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4473 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4475 | if (mddev->reshape_position != MaxSector && |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4476 | pers->start_reshape == NULL) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4477 | /* This personality cannot handle reshaping... */ |
| 4478 | mddev->pers = NULL; |
| 4479 | module_put(pers->owner); |
| 4480 | return -EINVAL; |
| 4481 | } |
| 4482 | |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4483 | if (pers->sync_request) { |
| 4484 | /* Warn if this is a potentially silly |
| 4485 | * configuration. |
| 4486 | */ |
| 4487 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 4488 | mdk_rdev_t *rdev2; |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4489 | int warned = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4490 | |
| 4491 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 4492 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4493 | if (rdev < rdev2 && |
| 4494 | rdev->bdev->bd_contains == |
| 4495 | rdev2->bdev->bd_contains) { |
| 4496 | printk(KERN_WARNING |
| 4497 | "%s: WARNING: %s appears to be" |
| 4498 | " on the same physical disk as" |
| 4499 | " %s.\n", |
| 4500 | mdname(mddev), |
| 4501 | bdevname(rdev->bdev,b), |
| 4502 | bdevname(rdev2->bdev,b2)); |
| 4503 | warned = 1; |
| 4504 | } |
| 4505 | } |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4506 | |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4507 | if (warned) |
| 4508 | printk(KERN_WARNING |
| 4509 | "True protection against single-disk" |
| 4510 | " failure might be compromised.\n"); |
| 4511 | } |
| 4512 | |
NeilBrown | 657390d | 2005-08-26 18:34:16 -0700 | [diff] [blame] | 4513 | mddev->recovery = 0; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4514 | /* may be over-ridden by personality */ |
| 4515 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 4516 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 4517 | mddev->barriers_work = 1; |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4518 | mddev->ok_start_degraded = start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | |
NeilBrown | 0f9552b5 | 2009-12-30 12:08:50 +1100 | [diff] [blame] | 4520 | if (start_readonly && mddev->ro == 0) |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4521 | mddev->ro = 2; /* read-only, but switch on first write */ |
| 4522 | |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 4523 | err = mddev->pers->run(mddev); |
Andre Noll | 13e53df | 2008-03-26 00:07:03 +0100 | [diff] [blame] | 4524 | if (err) |
| 4525 | printk(KERN_ERR "md: pers->run() failed ...\n"); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4526 | else if (mddev->pers->size(mddev, 0, 0) < mddev->array_sectors) { |
| 4527 | WARN_ONCE(!mddev->external_size, "%s: default size too small," |
| 4528 | " but 'external_size' not in effect?\n", __func__); |
| 4529 | printk(KERN_ERR |
| 4530 | "md: invalid array_size %llu > default size %llu\n", |
| 4531 | (unsigned long long)mddev->array_sectors / 2, |
| 4532 | (unsigned long long)mddev->pers->size(mddev, 0, 0) / 2); |
| 4533 | err = -EINVAL; |
| 4534 | mddev->pers->stop(mddev); |
| 4535 | } |
| 4536 | if (err == 0 && mddev->pers->sync_request) { |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 4537 | err = bitmap_create(mddev); |
| 4538 | if (err) { |
| 4539 | printk(KERN_ERR "%s: failed to create bitmap (%d)\n", |
| 4540 | mdname(mddev), err); |
| 4541 | mddev->pers->stop(mddev); |
| 4542 | } |
| 4543 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | module_put(mddev->pers->owner); |
| 4546 | mddev->pers = NULL; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4547 | bitmap_destroy(mddev); |
| 4548 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | } |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4550 | if (mddev->pers->sync_request) { |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4551 | if (mddev->kobj.sd && |
| 4552 | sysfs_create_group(&mddev->kobj, &md_redundancy_group)) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4553 | printk(KERN_WARNING |
| 4554 | "md: cannot register extra attributes for %s\n", |
| 4555 | mdname(mddev)); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4556 | mddev->sysfs_action = sysfs_get_dirent_safe(mddev->kobj.sd, "sync_action"); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4557 | } else if (mddev->ro == 2) /* auto-readonly not meaningful */ |
NeilBrown | fd9d49c | 2005-11-08 21:39:42 -0800 | [diff] [blame] | 4558 | mddev->ro = 0; |
| 4559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | atomic_set(&mddev->writes_pending,0); |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 4561 | atomic_set(&mddev->max_corr_read_errors, |
| 4562 | MD_DEFAULT_MAX_CORRECTED_READ_ERRORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | mddev->safemode = 0; |
| 4564 | mddev->safemode_timer.function = md_safemode_timeout; |
| 4565 | mddev->safemode_timer.data = (unsigned long) mddev; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 4566 | mddev->safemode_delay = (200 * HZ)/1000 +1; /* 200 msec delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | mddev->in_sync = 1; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4568 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4569 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4570 | if (rdev->raid_disk >= 0) { |
| 4571 | char nm[20]; |
| 4572 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4573 | if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4574 | /* failure here is OK */; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | |
| 4577 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4578 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4579 | if (mddev->flags) |
| 4580 | md_update_sb(mddev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 4582 | md_wakeup_thread(mddev->thread); |
| 4583 | md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4584 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4585 | md_new_event(mddev); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4586 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
| 4587 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 4588 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | return 0; |
| 4590 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4591 | EXPORT_SYMBOL_GPL(md_run); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | |
NeilBrown | fe60b01 | 2010-03-29 11:10:42 +1100 | [diff] [blame] | 4593 | static int do_md_run(mddev_t *mddev) |
| 4594 | { |
| 4595 | int err; |
| 4596 | |
| 4597 | err = md_run(mddev); |
| 4598 | if (err) |
| 4599 | goto out; |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 4600 | err = bitmap_load(mddev); |
| 4601 | if (err) { |
| 4602 | bitmap_destroy(mddev); |
| 4603 | goto out; |
| 4604 | } |
NeilBrown | fe60b01 | 2010-03-29 11:10:42 +1100 | [diff] [blame] | 4605 | set_capacity(mddev->gendisk, mddev->array_sectors); |
| 4606 | revalidate_disk(mddev->gendisk); |
| 4607 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
| 4608 | out: |
| 4609 | return err; |
| 4610 | } |
| 4611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | static int restart_array(mddev_t *mddev) |
| 4613 | { |
| 4614 | struct gendisk *disk = mddev->gendisk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4616 | /* Complain if it has no devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | if (list_empty(&mddev->disks)) |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4618 | return -ENXIO; |
| 4619 | if (!mddev->pers) |
| 4620 | return -EINVAL; |
| 4621 | if (!mddev->ro) |
| 4622 | return -EBUSY; |
| 4623 | mddev->safemode = 0; |
| 4624 | mddev->ro = 0; |
| 4625 | set_disk_ro(disk, 0); |
| 4626 | printk(KERN_INFO "md: %s switched to read-write mode.\n", |
| 4627 | mdname(mddev)); |
| 4628 | /* Kick recovery or resync if necessary */ |
| 4629 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4630 | md_wakeup_thread(mddev->thread); |
| 4631 | md_wakeup_thread(mddev->sync_thread); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4632 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4633 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4636 | /* similar to deny_write_access, but accounts for our holding a reference |
| 4637 | * to the file ourselves */ |
| 4638 | static int deny_bitmap_write_access(struct file * file) |
| 4639 | { |
| 4640 | struct inode *inode = file->f_mapping->host; |
| 4641 | |
| 4642 | spin_lock(&inode->i_lock); |
| 4643 | if (atomic_read(&inode->i_writecount) > 1) { |
| 4644 | spin_unlock(&inode->i_lock); |
| 4645 | return -ETXTBSY; |
| 4646 | } |
| 4647 | atomic_set(&inode->i_writecount, -1); |
| 4648 | spin_unlock(&inode->i_lock); |
| 4649 | |
| 4650 | return 0; |
| 4651 | } |
| 4652 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 4653 | void restore_bitmap_write_access(struct file *file) |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4654 | { |
| 4655 | struct inode *inode = file->f_mapping->host; |
| 4656 | |
| 4657 | spin_lock(&inode->i_lock); |
| 4658 | atomic_set(&inode->i_writecount, 1); |
| 4659 | spin_unlock(&inode->i_lock); |
| 4660 | } |
| 4661 | |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4662 | static void md_clean(mddev_t *mddev) |
| 4663 | { |
| 4664 | mddev->array_sectors = 0; |
| 4665 | mddev->external_size = 0; |
| 4666 | mddev->dev_sectors = 0; |
| 4667 | mddev->raid_disks = 0; |
| 4668 | mddev->recovery_cp = 0; |
| 4669 | mddev->resync_min = 0; |
| 4670 | mddev->resync_max = MaxSector; |
| 4671 | mddev->reshape_position = MaxSector; |
| 4672 | mddev->external = 0; |
| 4673 | mddev->persistent = 0; |
| 4674 | mddev->level = LEVEL_NONE; |
| 4675 | mddev->clevel[0] = 0; |
| 4676 | mddev->flags = 0; |
| 4677 | mddev->ro = 0; |
| 4678 | mddev->metadata_type[0] = 0; |
| 4679 | mddev->chunk_sectors = 0; |
| 4680 | mddev->ctime = mddev->utime = 0; |
| 4681 | mddev->layout = 0; |
| 4682 | mddev->max_disks = 0; |
| 4683 | mddev->events = 0; |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 4684 | mddev->can_decrease_events = 0; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4685 | mddev->delta_disks = 0; |
| 4686 | mddev->new_level = LEVEL_NONE; |
| 4687 | mddev->new_layout = 0; |
| 4688 | mddev->new_chunk_sectors = 0; |
| 4689 | mddev->curr_resync = 0; |
| 4690 | mddev->resync_mismatches = 0; |
| 4691 | mddev->suspend_lo = mddev->suspend_hi = 0; |
| 4692 | mddev->sync_speed_min = mddev->sync_speed_max = 0; |
| 4693 | mddev->recovery = 0; |
| 4694 | mddev->in_sync = 0; |
| 4695 | mddev->degraded = 0; |
| 4696 | mddev->barriers_work = 0; |
| 4697 | mddev->safemode = 0; |
| 4698 | mddev->bitmap_info.offset = 0; |
| 4699 | mddev->bitmap_info.default_offset = 0; |
| 4700 | mddev->bitmap_info.chunksize = 0; |
| 4701 | mddev->bitmap_info.daemon_sleep = 0; |
| 4702 | mddev->bitmap_info.max_write_behind = 0; |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 4703 | mddev->plug = NULL; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4704 | } |
| 4705 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4706 | void md_stop_writes(mddev_t *mddev) |
NeilBrown | a047e12 | 2010-03-29 12:07:53 +1100 | [diff] [blame] | 4707 | { |
| 4708 | if (mddev->sync_thread) { |
| 4709 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 4710 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 4711 | md_unregister_thread(mddev->sync_thread); |
| 4712 | mddev->sync_thread = NULL; |
| 4713 | } |
| 4714 | |
| 4715 | del_timer_sync(&mddev->safemode_timer); |
| 4716 | |
| 4717 | bitmap_flush(mddev); |
| 4718 | md_super_wait(mddev); |
| 4719 | |
| 4720 | if (!mddev->in_sync || mddev->flags) { |
| 4721 | /* mark array as shutdown cleanly */ |
| 4722 | mddev->in_sync = 1; |
| 4723 | md_update_sb(mddev, 1); |
| 4724 | } |
| 4725 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4726 | EXPORT_SYMBOL_GPL(md_stop_writes); |
NeilBrown | a047e12 | 2010-03-29 12:07:53 +1100 | [diff] [blame] | 4727 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4728 | void md_stop(mddev_t *mddev) |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4729 | { |
| 4730 | mddev->pers->stop(mddev); |
| 4731 | if (mddev->pers->sync_request && mddev->to_remove == NULL) |
| 4732 | mddev->to_remove = &md_redundancy_group; |
| 4733 | module_put(mddev->pers->owner); |
| 4734 | mddev->pers = NULL; |
NeilBrown | cca9cf9 | 2010-04-01 12:08:16 +1100 | [diff] [blame] | 4735 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4736 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4737 | EXPORT_SYMBOL_GPL(md_stop); |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4738 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4739 | static int md_set_readonly(mddev_t *mddev, int is_open) |
| 4740 | { |
| 4741 | int err = 0; |
| 4742 | mutex_lock(&mddev->open_mutex); |
| 4743 | if (atomic_read(&mddev->openers) > is_open) { |
| 4744 | printk("md: %s still in use.\n",mdname(mddev)); |
| 4745 | err = -EBUSY; |
| 4746 | goto out; |
| 4747 | } |
| 4748 | if (mddev->pers) { |
| 4749 | md_stop_writes(mddev); |
| 4750 | |
| 4751 | err = -ENXIO; |
| 4752 | if (mddev->ro==1) |
| 4753 | goto out; |
| 4754 | mddev->ro = 1; |
| 4755 | set_disk_ro(mddev->gendisk, 1); |
| 4756 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4757 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4758 | err = 0; |
| 4759 | } |
| 4760 | out: |
| 4761 | mutex_unlock(&mddev->open_mutex); |
| 4762 | return err; |
| 4763 | } |
| 4764 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4765 | /* mode: |
| 4766 | * 0 - completely stop and dis-assemble array |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4767 | * 2 - stop but do not disassemble array |
| 4768 | */ |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4769 | 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] | 4770 | { |
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 | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4778 | mutex_unlock(&mddev->open_mutex); |
| 4779 | return -EBUSY; |
| 4780 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | |
NeilBrown | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4782 | if (mddev->pers) { |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4783 | if (mddev->ro) |
| 4784 | set_disk_ro(disk, 0); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4785 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4786 | md_stop_writes(mddev); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4787 | md_stop(mddev); |
| 4788 | mddev->queue->merge_bvec_fn = NULL; |
| 4789 | mddev->queue->unplug_fn = NULL; |
| 4790 | mddev->queue->backing_dev_info.congested_fn = NULL; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4791 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4792 | /* tell userspace to handle 'inactive' */ |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4793 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4794 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4795 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 4796 | if (rdev->raid_disk >= 0) { |
| 4797 | char nm[20]; |
| 4798 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 4799 | sysfs_remove_link(&mddev->kobj, nm); |
| 4800 | } |
NeilBrown | c464729 | 2009-05-07 12:51:06 +1000 | [diff] [blame] | 4801 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4802 | set_capacity(disk, 0); |
NeilBrown | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4803 | mutex_unlock(&mddev->open_mutex); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4804 | revalidate_disk(disk); |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4805 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4806 | if (mddev->ro) |
| 4807 | mddev->ro = 0; |
NeilBrown | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4808 | } else |
| 4809 | mutex_unlock(&mddev->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | /* |
| 4811 | * Free resources if final stop |
| 4812 | */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4813 | if (mode == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); |
| 4815 | |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4816 | bitmap_destroy(mddev); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4817 | if (mddev->bitmap_info.file) { |
| 4818 | restore_bitmap_write_access(mddev->bitmap_info.file); |
| 4819 | fput(mddev->bitmap_info.file); |
| 4820 | mddev->bitmap_info.file = NULL; |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4821 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4822 | mddev->bitmap_info.offset = 0; |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4824 | export_array(mddev); |
| 4825 | |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4826 | md_clean(mddev); |
NeilBrown | 934d9c2 | 2008-10-28 17:01:23 +1100 | [diff] [blame] | 4827 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4828 | if (mddev->hold_active == UNTIL_STOP) |
| 4829 | mddev->hold_active = 0; |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4830 | } |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 4831 | blk_integrity_unregister(disk); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4832 | md_new_event(mddev); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4833 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4834 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 4837 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | static void autorun_array(mddev_t *mddev) |
| 4839 | { |
| 4840 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | int err; |
| 4842 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4843 | if (list_empty(&mddev->disks)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | |
| 4846 | printk(KERN_INFO "md: running: "); |
| 4847 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4848 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | char b[BDEVNAME_SIZE]; |
| 4850 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 4851 | } |
| 4852 | printk("\n"); |
| 4853 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4854 | err = do_md_run(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | if (err) { |
| 4856 | printk(KERN_WARNING "md: do_md_run() returned %d\n", err); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4857 | do_md_stop(mddev, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | } |
| 4859 | } |
| 4860 | |
| 4861 | /* |
| 4862 | * lets try to run arrays based on all disks that have arrived |
| 4863 | * until now. (those are in pending_raid_disks) |
| 4864 | * |
| 4865 | * the method: pick the first pending disk, collect all disks with |
| 4866 | * the same UUID, remove all from the pending list and put them into |
| 4867 | * the 'same_array' list. Then order this list based on superblock |
| 4868 | * update time (freshest comes first), kick out 'old' disks and |
| 4869 | * compare superblocks. If everything's fine then run it. |
| 4870 | * |
| 4871 | * If "unit" is allocated, then bump its reference count |
| 4872 | */ |
| 4873 | static void autorun_devices(int part) |
| 4874 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4875 | mdk_rdev_t *rdev0, *rdev, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | mddev_t *mddev; |
| 4877 | char b[BDEVNAME_SIZE]; |
| 4878 | |
| 4879 | printk(KERN_INFO "md: autorun ...\n"); |
| 4880 | while (!list_empty(&pending_raid_disks)) { |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4881 | int unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | dev_t dev; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 4883 | LIST_HEAD(candidates); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | rdev0 = list_entry(pending_raid_disks.next, |
| 4885 | mdk_rdev_t, same_set); |
| 4886 | |
| 4887 | printk(KERN_INFO "md: considering %s ...\n", |
| 4888 | bdevname(rdev0->bdev,b)); |
| 4889 | INIT_LIST_HEAD(&candidates); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4890 | rdev_for_each_list(rdev, tmp, &pending_raid_disks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | if (super_90_load(rdev, rdev0, 0) >= 0) { |
| 4892 | printk(KERN_INFO "md: adding %s ...\n", |
| 4893 | bdevname(rdev->bdev,b)); |
| 4894 | list_move(&rdev->same_set, &candidates); |
| 4895 | } |
| 4896 | /* |
| 4897 | * now we have a set of devices, with all of them having |
| 4898 | * mostly sane superblocks. It's time to allocate the |
| 4899 | * mddev. |
| 4900 | */ |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4901 | if (part) { |
| 4902 | dev = MKDEV(mdp_major, |
| 4903 | rdev0->preferred_minor << MdpMinorShift); |
| 4904 | unit = MINOR(dev) >> MdpMinorShift; |
| 4905 | } else { |
| 4906 | dev = MKDEV(MD_MAJOR, rdev0->preferred_minor); |
| 4907 | unit = MINOR(dev); |
| 4908 | } |
| 4909 | if (rdev0->preferred_minor != unit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4910 | printk(KERN_INFO "md: unit number in %s is bad: %d\n", |
| 4911 | bdevname(rdev0->bdev, b), rdev0->preferred_minor); |
| 4912 | break; |
| 4913 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | |
| 4915 | md_probe(dev, NULL, NULL); |
| 4916 | mddev = mddev_find(dev); |
Neil Brown | 9bbbca3 | 2008-06-28 08:31:17 +1000 | [diff] [blame] | 4917 | if (!mddev || !mddev->gendisk) { |
| 4918 | if (mddev) |
| 4919 | mddev_put(mddev); |
| 4920 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | "md: cannot allocate memory for md drive.\n"); |
| 4922 | break; |
| 4923 | } |
| 4924 | if (mddev_lock(mddev)) |
| 4925 | printk(KERN_WARNING "md: %s locked, cannot run\n", |
| 4926 | mdname(mddev)); |
| 4927 | else if (mddev->raid_disks || mddev->major_version |
| 4928 | || !list_empty(&mddev->disks)) { |
| 4929 | printk(KERN_WARNING |
| 4930 | "md: %s already running, cannot run %s\n", |
| 4931 | mdname(mddev), bdevname(rdev0->bdev,b)); |
| 4932 | mddev_unlock(mddev); |
| 4933 | } else { |
| 4934 | printk(KERN_INFO "md: created %s\n", mdname(mddev)); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4935 | mddev->persistent = 1; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4936 | rdev_for_each_list(rdev, tmp, &candidates) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | list_del_init(&rdev->same_set); |
| 4938 | if (bind_rdev_to_array(rdev, mddev)) |
| 4939 | export_rdev(rdev); |
| 4940 | } |
| 4941 | autorun_array(mddev); |
| 4942 | mddev_unlock(mddev); |
| 4943 | } |
| 4944 | /* on success, candidates will be empty, on error |
| 4945 | * it won't... |
| 4946 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4947 | rdev_for_each_list(rdev, tmp, &candidates) { |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 4948 | list_del_init(&rdev->same_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | export_rdev(rdev); |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 4950 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | mddev_put(mddev); |
| 4952 | } |
| 4953 | printk(KERN_INFO "md: ... autorun DONE.\n"); |
| 4954 | } |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 4955 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4956 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | static int get_version(void __user * arg) |
| 4958 | { |
| 4959 | mdu_version_t ver; |
| 4960 | |
| 4961 | ver.major = MD_MAJOR_VERSION; |
| 4962 | ver.minor = MD_MINOR_VERSION; |
| 4963 | ver.patchlevel = MD_PATCHLEVEL_VERSION; |
| 4964 | |
| 4965 | if (copy_to_user(arg, &ver, sizeof(ver))) |
| 4966 | return -EFAULT; |
| 4967 | |
| 4968 | return 0; |
| 4969 | } |
| 4970 | |
| 4971 | static int get_array_info(mddev_t * mddev, void __user * arg) |
| 4972 | { |
| 4973 | mdu_array_info_t info; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4974 | int nr,working,insync,failed,spare; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4976 | |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4977 | nr=working=insync=failed=spare=0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4978 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4979 | nr++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4980 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | failed++; |
| 4982 | else { |
| 4983 | working++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4984 | if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4985 | insync++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4986 | else |
| 4987 | spare++; |
| 4988 | } |
| 4989 | } |
| 4990 | |
| 4991 | info.major_version = mddev->major_version; |
| 4992 | info.minor_version = mddev->minor_version; |
| 4993 | info.patch_version = MD_PATCHLEVEL_VERSION; |
| 4994 | info.ctime = mddev->ctime; |
| 4995 | info.level = mddev->level; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4996 | info.size = mddev->dev_sectors / 2; |
| 4997 | if (info.size != mddev->dev_sectors / 2) /* overflow */ |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 4998 | info.size = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | info.nr_disks = nr; |
| 5000 | info.raid_disks = mddev->raid_disks; |
| 5001 | info.md_minor = mddev->md_minor; |
| 5002 | info.not_persistent= !mddev->persistent; |
| 5003 | |
| 5004 | info.utime = mddev->utime; |
| 5005 | info.state = 0; |
| 5006 | if (mddev->in_sync) |
| 5007 | info.state = (1<<MD_SB_CLEAN); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5008 | if (mddev->bitmap && mddev->bitmap_info.offset) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5009 | info.state = (1<<MD_SB_BITMAP_PRESENT); |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5010 | info.active_disks = insync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | info.working_disks = working; |
| 5012 | info.failed_disks = failed; |
| 5013 | info.spare_disks = spare; |
| 5014 | |
| 5015 | info.layout = mddev->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5016 | info.chunk_size = mddev->chunk_sectors << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | |
| 5018 | if (copy_to_user(arg, &info, sizeof(info))) |
| 5019 | return -EFAULT; |
| 5020 | |
| 5021 | return 0; |
| 5022 | } |
| 5023 | |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 5024 | static int get_bitmap_file(mddev_t * mddev, void __user * arg) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5025 | { |
| 5026 | mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ |
| 5027 | char *ptr, *buf = NULL; |
| 5028 | int err = -ENOMEM; |
| 5029 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5030 | if (md_allow_write(mddev)) |
| 5031 | file = kmalloc(sizeof(*file), GFP_NOIO); |
| 5032 | else |
| 5033 | file = kmalloc(sizeof(*file), GFP_KERNEL); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 5034 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5035 | if (!file) |
| 5036 | goto out; |
| 5037 | |
| 5038 | /* bitmap disabled, zero the first byte and copy out */ |
| 5039 | if (!mddev->bitmap || !mddev->bitmap->file) { |
| 5040 | file->pathname[0] = '\0'; |
| 5041 | goto copy_out; |
| 5042 | } |
| 5043 | |
| 5044 | buf = kmalloc(sizeof(file->pathname), GFP_KERNEL); |
| 5045 | if (!buf) |
| 5046 | goto out; |
| 5047 | |
Christoph Hellwig | 6bcfd60 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 5048 | ptr = d_path(&mddev->bitmap->file->f_path, buf, sizeof(file->pathname)); |
| 5049 | if (IS_ERR(ptr)) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5050 | goto out; |
| 5051 | |
| 5052 | strcpy(file->pathname, ptr); |
| 5053 | |
| 5054 | copy_out: |
| 5055 | err = 0; |
| 5056 | if (copy_to_user(arg, file, sizeof(*file))) |
| 5057 | err = -EFAULT; |
| 5058 | out: |
| 5059 | kfree(buf); |
| 5060 | kfree(file); |
| 5061 | return err; |
| 5062 | } |
| 5063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | static int get_disk_info(mddev_t * mddev, void __user * arg) |
| 5065 | { |
| 5066 | mdu_disk_info_t info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | mdk_rdev_t *rdev; |
| 5068 | |
| 5069 | if (copy_from_user(&info, arg, sizeof(info))) |
| 5070 | return -EFAULT; |
| 5071 | |
Andre Noll | 26ef379 | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 5072 | rdev = find_rdev_nr(mddev, info.number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | if (rdev) { |
| 5074 | info.major = MAJOR(rdev->bdev->bd_dev); |
| 5075 | info.minor = MINOR(rdev->bdev->bd_dev); |
| 5076 | info.raid_disk = rdev->raid_disk; |
| 5077 | info.state = 0; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5078 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | info.state |= (1<<MD_DISK_FAULTY); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5080 | else if (test_bit(In_sync, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | info.state |= (1<<MD_DISK_ACTIVE); |
| 5082 | info.state |= (1<<MD_DISK_SYNC); |
| 5083 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5084 | if (test_bit(WriteMostly, &rdev->flags)) |
| 5085 | info.state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | } else { |
| 5087 | info.major = info.minor = 0; |
| 5088 | info.raid_disk = -1; |
| 5089 | info.state = (1<<MD_DISK_REMOVED); |
| 5090 | } |
| 5091 | |
| 5092 | if (copy_to_user(arg, &info, sizeof(info))) |
| 5093 | return -EFAULT; |
| 5094 | |
| 5095 | return 0; |
| 5096 | } |
| 5097 | |
| 5098 | static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) |
| 5099 | { |
| 5100 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 5101 | mdk_rdev_t *rdev; |
| 5102 | dev_t dev = MKDEV(info->major,info->minor); |
| 5103 | |
| 5104 | if (info->major != MAJOR(dev) || info->minor != MINOR(dev)) |
| 5105 | return -EOVERFLOW; |
| 5106 | |
| 5107 | if (!mddev->raid_disks) { |
| 5108 | int err; |
| 5109 | /* expecting a device which has a superblock */ |
| 5110 | rdev = md_import_device(dev, mddev->major_version, mddev->minor_version); |
| 5111 | if (IS_ERR(rdev)) { |
| 5112 | printk(KERN_WARNING |
| 5113 | "md: md_import_device returned %ld\n", |
| 5114 | PTR_ERR(rdev)); |
| 5115 | return PTR_ERR(rdev); |
| 5116 | } |
| 5117 | if (!list_empty(&mddev->disks)) { |
| 5118 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 5119 | mdk_rdev_t, same_set); |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5120 | err = super_types[mddev->major_version] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5121 | .load_super(rdev, rdev0, mddev->minor_version); |
| 5122 | if (err < 0) { |
| 5123 | printk(KERN_WARNING |
| 5124 | "md: %s has different UUID to %s\n", |
| 5125 | bdevname(rdev->bdev,b), |
| 5126 | bdevname(rdev0->bdev,b2)); |
| 5127 | export_rdev(rdev); |
| 5128 | return -EINVAL; |
| 5129 | } |
| 5130 | } |
| 5131 | err = bind_rdev_to_array(rdev, mddev); |
| 5132 | if (err) |
| 5133 | export_rdev(rdev); |
| 5134 | return err; |
| 5135 | } |
| 5136 | |
| 5137 | /* |
| 5138 | * add_new_disk can be used once the array is assembled |
| 5139 | * to add "hot spares". They must already have a superblock |
| 5140 | * written |
| 5141 | */ |
| 5142 | if (mddev->pers) { |
| 5143 | int err; |
| 5144 | if (!mddev->pers->hot_add_disk) { |
| 5145 | printk(KERN_WARNING |
| 5146 | "%s: personality does not support diskops!\n", |
| 5147 | mdname(mddev)); |
| 5148 | return -EINVAL; |
| 5149 | } |
NeilBrown | 7b1e35f | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 5150 | if (mddev->persistent) |
| 5151 | rdev = md_import_device(dev, mddev->major_version, |
| 5152 | mddev->minor_version); |
| 5153 | else |
| 5154 | rdev = md_import_device(dev, -1, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | if (IS_ERR(rdev)) { |
| 5156 | printk(KERN_WARNING |
| 5157 | "md: md_import_device returned %ld\n", |
| 5158 | PTR_ERR(rdev)); |
| 5159 | return PTR_ERR(rdev); |
| 5160 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 5161 | /* set save_raid_disk if appropriate */ |
| 5162 | if (!mddev->persistent) { |
| 5163 | if (info->state & (1<<MD_DISK_SYNC) && |
| 5164 | info->raid_disk < mddev->raid_disks) |
| 5165 | rdev->raid_disk = info->raid_disk; |
| 5166 | else |
| 5167 | rdev->raid_disk = -1; |
| 5168 | } else |
| 5169 | super_types[mddev->major_version]. |
| 5170 | validate_super(mddev, rdev); |
| 5171 | rdev->saved_raid_disk = rdev->raid_disk; |
| 5172 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5173 | clear_bit(In_sync, &rdev->flags); /* just to be sure */ |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5174 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 5175 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 575a80f | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5176 | else |
| 5177 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5179 | rdev->raid_disk = -1; |
| 5180 | err = bind_rdev_to_array(rdev, mddev); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 5181 | if (!err && !mddev->pers->hot_remove_disk) { |
| 5182 | /* If there is hot_add_disk but no hot_remove_disk |
| 5183 | * then added disks for geometry changes, |
| 5184 | * and should be added immediately. |
| 5185 | */ |
| 5186 | super_types[mddev->major_version]. |
| 5187 | validate_super(mddev, rdev); |
| 5188 | err = mddev->pers->hot_add_disk(mddev, rdev); |
| 5189 | if (err) |
| 5190 | unbind_rdev_from_array(rdev); |
| 5191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | if (err) |
| 5193 | export_rdev(rdev); |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 5194 | else |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 5195 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 5196 | |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 5197 | md_update_sb(mddev, 1); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 5198 | if (mddev->degraded) |
| 5199 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 5200 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 5201 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5202 | return err; |
| 5203 | } |
| 5204 | |
| 5205 | /* otherwise, add_new_disk is only allowed |
| 5206 | * for major_version==0 superblocks |
| 5207 | */ |
| 5208 | if (mddev->major_version != 0) { |
| 5209 | printk(KERN_WARNING "%s: ADD_NEW_DISK not supported\n", |
| 5210 | mdname(mddev)); |
| 5211 | return -EINVAL; |
| 5212 | } |
| 5213 | |
| 5214 | if (!(info->state & (1<<MD_DISK_FAULTY))) { |
| 5215 | int err; |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5216 | rdev = md_import_device(dev, -1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | if (IS_ERR(rdev)) { |
| 5218 | printk(KERN_WARNING |
| 5219 | "md: error, md_import_device() returned %ld\n", |
| 5220 | PTR_ERR(rdev)); |
| 5221 | return PTR_ERR(rdev); |
| 5222 | } |
| 5223 | rdev->desc_nr = info->number; |
| 5224 | if (info->raid_disk < mddev->raid_disks) |
| 5225 | rdev->raid_disk = info->raid_disk; |
| 5226 | else |
| 5227 | rdev->raid_disk = -1; |
| 5228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | if (rdev->raid_disk < mddev->raid_disks) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5230 | if (info->state & (1<<MD_DISK_SYNC)) |
| 5231 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5232 | |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5233 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 5234 | set_bit(WriteMostly, &rdev->flags); |
| 5235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | if (!mddev->persistent) { |
| 5237 | printk(KERN_INFO "md: nonpersistent superblock ...\n"); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5238 | rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | } else |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5240 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 5241 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 5243 | err = bind_rdev_to_array(rdev, mddev); |
| 5244 | if (err) { |
| 5245 | export_rdev(rdev); |
| 5246 | return err; |
| 5247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | } |
| 5249 | |
| 5250 | return 0; |
| 5251 | } |
| 5252 | |
| 5253 | static int hot_remove_disk(mddev_t * mddev, dev_t dev) |
| 5254 | { |
| 5255 | char b[BDEVNAME_SIZE]; |
| 5256 | mdk_rdev_t *rdev; |
| 5257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | rdev = find_rdev(mddev, dev); |
| 5259 | if (!rdev) |
| 5260 | return -ENXIO; |
| 5261 | |
| 5262 | if (rdev->raid_disk >= 0) |
| 5263 | goto busy; |
| 5264 | |
| 5265 | kick_rdev_from_array(rdev); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5266 | md_update_sb(mddev, 1); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5267 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5268 | |
| 5269 | return 0; |
| 5270 | busy: |
Nick Andrew | fdefa4d | 2008-04-21 22:42:58 +0000 | [diff] [blame] | 5271 | printk(KERN_WARNING "md: cannot remove active disk %s from %s ...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 5273 | return -EBUSY; |
| 5274 | } |
| 5275 | |
| 5276 | static int hot_add_disk(mddev_t * mddev, dev_t dev) |
| 5277 | { |
| 5278 | char b[BDEVNAME_SIZE]; |
| 5279 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5280 | mdk_rdev_t *rdev; |
| 5281 | |
| 5282 | if (!mddev->pers) |
| 5283 | return -ENODEV; |
| 5284 | |
| 5285 | if (mddev->major_version != 0) { |
| 5286 | printk(KERN_WARNING "%s: HOT_ADD may only be used with" |
| 5287 | " version-0 superblocks.\n", |
| 5288 | mdname(mddev)); |
| 5289 | return -EINVAL; |
| 5290 | } |
| 5291 | if (!mddev->pers->hot_add_disk) { |
| 5292 | printk(KERN_WARNING |
| 5293 | "%s: personality does not support diskops!\n", |
| 5294 | mdname(mddev)); |
| 5295 | return -EINVAL; |
| 5296 | } |
| 5297 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5298 | rdev = md_import_device(dev, -1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | if (IS_ERR(rdev)) { |
| 5300 | printk(KERN_WARNING |
| 5301 | "md: error, md_import_device() returned %ld\n", |
| 5302 | PTR_ERR(rdev)); |
| 5303 | return -EINVAL; |
| 5304 | } |
| 5305 | |
| 5306 | if (mddev->persistent) |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5307 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5308 | else |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5309 | rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5310 | |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 5311 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5312 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5313 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5314 | printk(KERN_WARNING |
| 5315 | "md: can not hot-add faulty %s disk to %s!\n", |
| 5316 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 5317 | err = -EINVAL; |
| 5318 | goto abort_export; |
| 5319 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5320 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | rdev->desc_nr = -1; |
NeilBrown | 5842730 | 2006-10-06 00:44:04 -0700 | [diff] [blame] | 5322 | rdev->saved_raid_disk = -1; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 5323 | err = bind_rdev_to_array(rdev, mddev); |
| 5324 | if (err) |
| 5325 | goto abort_export; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | |
| 5327 | /* |
| 5328 | * The rest should better be atomic, we can have disk failures |
| 5329 | * noticed in interrupt contexts ... |
| 5330 | */ |
| 5331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5332 | rdev->raid_disk = -1; |
| 5333 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5334 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5335 | |
| 5336 | /* |
| 5337 | * Kick recovery, maybe this spare has to be added to the |
| 5338 | * array immediately. |
| 5339 | */ |
| 5340 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5341 | md_wakeup_thread(mddev->thread); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5342 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5343 | return 0; |
| 5344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5345 | abort_export: |
| 5346 | export_rdev(rdev); |
| 5347 | return err; |
| 5348 | } |
| 5349 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5350 | static int set_bitmap_file(mddev_t *mddev, int fd) |
| 5351 | { |
| 5352 | int err; |
| 5353 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5354 | if (mddev->pers) { |
| 5355 | if (!mddev->pers->quiesce) |
| 5356 | return -EBUSY; |
| 5357 | if (mddev->recovery || mddev->sync_thread) |
| 5358 | return -EBUSY; |
| 5359 | /* we should be able to change the bitmap.. */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5360 | } |
| 5361 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5362 | |
| 5363 | if (fd >= 0) { |
| 5364 | if (mddev->bitmap) |
| 5365 | return -EEXIST; /* cannot add when bitmap is present */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5366 | mddev->bitmap_info.file = fget(fd); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5367 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5368 | if (mddev->bitmap_info.file == NULL) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5369 | printk(KERN_ERR "%s: error: failed to get bitmap file\n", |
| 5370 | mdname(mddev)); |
| 5371 | return -EBADF; |
| 5372 | } |
| 5373 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5374 | err = deny_bitmap_write_access(mddev->bitmap_info.file); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5375 | if (err) { |
| 5376 | printk(KERN_ERR "%s: error: bitmap file is already in use\n", |
| 5377 | mdname(mddev)); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5378 | fput(mddev->bitmap_info.file); |
| 5379 | mddev->bitmap_info.file = NULL; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5380 | return err; |
| 5381 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5382 | mddev->bitmap_info.offset = 0; /* file overrides offset */ |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5383 | } else if (mddev->bitmap == NULL) |
| 5384 | return -ENOENT; /* cannot remove what isn't there */ |
| 5385 | err = 0; |
| 5386 | if (mddev->pers) { |
| 5387 | mddev->pers->quiesce(mddev, 1); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 5388 | if (fd >= 0) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5389 | err = bitmap_create(mddev); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 5390 | if (!err) |
| 5391 | err = bitmap_load(mddev); |
| 5392 | } |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5393 | if (fd < 0 || err) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5394 | bitmap_destroy(mddev); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5395 | fd = -1; /* make sure to put the file */ |
| 5396 | } |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5397 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5398 | } |
| 5399 | if (fd < 0) { |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5400 | if (mddev->bitmap_info.file) { |
| 5401 | restore_bitmap_write_access(mddev->bitmap_info.file); |
| 5402 | fput(mddev->bitmap_info.file); |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 5403 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5404 | mddev->bitmap_info.file = NULL; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5405 | } |
| 5406 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5407 | return err; |
| 5408 | } |
| 5409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5410 | /* |
| 5411 | * set_array_info is used two different ways |
| 5412 | * The original usage is when creating a new array. |
| 5413 | * In this usage, raid_disks is > 0 and it together with |
| 5414 | * level, size, not_persistent,layout,chunksize determine the |
| 5415 | * shape of the array. |
| 5416 | * This will always create an array with a type-0.90.0 superblock. |
| 5417 | * The newer usage is when assembling an array. |
| 5418 | * In this case raid_disks will be 0, and the major_version field is |
| 5419 | * use to determine which style super-blocks are to be found on the devices. |
| 5420 | * The minor and patch _version numbers are also kept incase the |
| 5421 | * super_block handler wishes to interpret them. |
| 5422 | */ |
| 5423 | static int set_array_info(mddev_t * mddev, mdu_array_info_t *info) |
| 5424 | { |
| 5425 | |
| 5426 | if (info->raid_disks == 0) { |
| 5427 | /* just setting version number for superblock loading */ |
| 5428 | if (info->major_version < 0 || |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 5429 | info->major_version >= ARRAY_SIZE(super_types) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5430 | super_types[info->major_version].name == NULL) { |
| 5431 | /* maybe try to auto-load a module? */ |
| 5432 | printk(KERN_INFO |
| 5433 | "md: superblock version %d not known\n", |
| 5434 | info->major_version); |
| 5435 | return -EINVAL; |
| 5436 | } |
| 5437 | mddev->major_version = info->major_version; |
| 5438 | mddev->minor_version = info->minor_version; |
| 5439 | mddev->patch_version = info->patch_version; |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 5440 | mddev->persistent = !info->not_persistent; |
NeilBrown | cbd1998 | 2009-12-30 12:08:49 +1100 | [diff] [blame] | 5441 | /* ensure mddev_put doesn't delete this now that there |
| 5442 | * is some minimal configuration. |
| 5443 | */ |
| 5444 | mddev->ctime = get_seconds(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5445 | return 0; |
| 5446 | } |
| 5447 | mddev->major_version = MD_MAJOR_VERSION; |
| 5448 | mddev->minor_version = MD_MINOR_VERSION; |
| 5449 | mddev->patch_version = MD_PATCHLEVEL_VERSION; |
| 5450 | mddev->ctime = get_seconds(); |
| 5451 | |
| 5452 | mddev->level = info->level; |
NeilBrown | 17115e0 | 2006-01-16 22:14:57 -0800 | [diff] [blame] | 5453 | mddev->clevel[0] = 0; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5454 | mddev->dev_sectors = 2 * (sector_t)info->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5455 | mddev->raid_disks = info->raid_disks; |
| 5456 | /* don't set md_minor, it is determined by which /dev/md* was |
| 5457 | * openned |
| 5458 | */ |
| 5459 | if (info->state & (1<<MD_SB_CLEAN)) |
| 5460 | mddev->recovery_cp = MaxSector; |
| 5461 | else |
| 5462 | mddev->recovery_cp = 0; |
| 5463 | mddev->persistent = ! info->not_persistent; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 5464 | mddev->external = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5465 | |
| 5466 | mddev->layout = info->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5467 | mddev->chunk_sectors = info->chunk_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5468 | |
| 5469 | mddev->max_disks = MD_SB_DISKS; |
| 5470 | |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 5471 | if (mddev->persistent) |
| 5472 | mddev->flags = 0; |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5473 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5475 | mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9; |
| 5476 | mddev->bitmap_info.offset = 0; |
NeilBrown | b2a2703 | 2005-11-28 13:44:12 -0800 | [diff] [blame] | 5477 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5478 | mddev->reshape_position = MaxSector; |
| 5479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | /* |
| 5481 | * Generate a 128 bit UUID |
| 5482 | */ |
| 5483 | get_random_bytes(mddev->uuid, 16); |
| 5484 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5485 | mddev->new_level = mddev->level; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5486 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5487 | mddev->new_layout = mddev->layout; |
| 5488 | mddev->delta_disks = 0; |
| 5489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | return 0; |
| 5491 | } |
| 5492 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5493 | void md_set_array_sectors(mddev_t *mddev, sector_t array_sectors) |
| 5494 | { |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5495 | WARN(!mddev_is_locked(mddev), "%s: unlocked mddev!\n", __func__); |
| 5496 | |
| 5497 | if (mddev->external_size) |
| 5498 | return; |
| 5499 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5500 | mddev->array_sectors = array_sectors; |
| 5501 | } |
| 5502 | EXPORT_SYMBOL(md_set_array_sectors); |
| 5503 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5504 | static int update_size(mddev_t *mddev, sector_t num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5505 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5506 | mdk_rdev_t *rdev; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5507 | int rv; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5508 | int fit = (num_sectors == 0); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5509 | |
| 5510 | if (mddev->pers->resize == NULL) |
| 5511 | return -EINVAL; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5512 | /* The "num_sectors" is the number of sectors of each device that |
| 5513 | * is used. This can only make sense for arrays with redundancy. |
| 5514 | * linear and raid0 always use whatever space is available. We can only |
| 5515 | * consider changing this number if no resync or reconstruction is |
| 5516 | * 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] | 5517 | * 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] | 5518 | * of each device. If num_sectors is zero, we find the largest size |
| 5519 | * that fits. |
| 5520 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5521 | */ |
| 5522 | if (mddev->sync_thread) |
| 5523 | return -EBUSY; |
NeilBrown | dba034e | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 5524 | if (mddev->bitmap) |
| 5525 | /* Sorry, cannot grow a bitmap yet, just remove it, |
| 5526 | * grow, and re-add. |
| 5527 | */ |
| 5528 | return -EBUSY; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5529 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5530 | sector_t avail = rdev->sectors; |
NeilBrown | 01ab566 | 2006-10-28 10:38:30 -0700 | [diff] [blame] | 5531 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5532 | if (fit && (num_sectors == 0 || num_sectors > avail)) |
| 5533 | num_sectors = avail; |
| 5534 | if (avail < num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5535 | return -ENOSPC; |
| 5536 | } |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5537 | rv = mddev->pers->resize(mddev, num_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5538 | if (!rv) |
| 5539 | revalidate_disk(mddev->gendisk); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5540 | return rv; |
| 5541 | } |
| 5542 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5543 | static int update_raid_disks(mddev_t *mddev, int raid_disks) |
| 5544 | { |
| 5545 | int rv; |
| 5546 | /* change the number of raid disks */ |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5547 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5548 | return -EINVAL; |
| 5549 | if (raid_disks <= 0 || |
NeilBrown | 233fca3 | 2010-04-14 17:02:09 +1000 | [diff] [blame] | 5550 | (mddev->max_disks && raid_disks >= mddev->max_disks)) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5551 | return -EINVAL; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5552 | if (mddev->sync_thread || mddev->reshape_position != MaxSector) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5553 | return -EBUSY; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5554 | mddev->delta_disks = raid_disks - mddev->raid_disks; |
| 5555 | |
| 5556 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5557 | return rv; |
| 5558 | } |
| 5559 | |
| 5560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5561 | /* |
| 5562 | * update_array_info is used to change the configuration of an |
| 5563 | * on-line array. |
| 5564 | * The version, ctime,level,size,raid_disks,not_persistent, layout,chunk_size |
| 5565 | * fields in the info are checked against the array. |
| 5566 | * Any differences that cannot be handled will cause an error. |
| 5567 | * Normally, only one change can be managed at a time. |
| 5568 | */ |
| 5569 | static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) |
| 5570 | { |
| 5571 | int rv = 0; |
| 5572 | int cnt = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5573 | int state = 0; |
| 5574 | |
| 5575 | /* calculate expected state,ignoring low bits */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5576 | if (mddev->bitmap && mddev->bitmap_info.offset) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5577 | state |= (1 << MD_SB_BITMAP_PRESENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | |
| 5579 | if (mddev->major_version != info->major_version || |
| 5580 | mddev->minor_version != info->minor_version || |
| 5581 | /* mddev->patch_version != info->patch_version || */ |
| 5582 | mddev->ctime != info->ctime || |
| 5583 | mddev->level != info->level || |
| 5584 | /* mddev->layout != info->layout || */ |
| 5585 | !mddev->persistent != info->not_persistent|| |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5586 | mddev->chunk_sectors != info->chunk_size >> 9 || |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5587 | /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */ |
| 5588 | ((state^info->state) & 0xfffffe00) |
| 5589 | ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | return -EINVAL; |
| 5591 | /* Check there is only one change */ |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5592 | if (info->size >= 0 && mddev->dev_sectors / 2 != info->size) |
| 5593 | cnt++; |
| 5594 | if (mddev->raid_disks != info->raid_disks) |
| 5595 | cnt++; |
| 5596 | if (mddev->layout != info->layout) |
| 5597 | cnt++; |
| 5598 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) |
| 5599 | cnt++; |
| 5600 | if (cnt == 0) |
| 5601 | return 0; |
| 5602 | if (cnt > 1) |
| 5603 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5604 | |
| 5605 | if (mddev->layout != info->layout) { |
| 5606 | /* Change layout |
| 5607 | * we don't need to do anything at the md level, the |
| 5608 | * personality will take care of it all. |
| 5609 | */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5610 | if (mddev->pers->check_reshape == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5611 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5612 | else { |
| 5613 | mddev->new_layout = info->layout; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5614 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5615 | if (rv) |
| 5616 | mddev->new_layout = mddev->layout; |
| 5617 | return rv; |
| 5618 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5620 | if (info->size >= 0 && mddev->dev_sectors / 2 != info->size) |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5621 | rv = update_size(mddev, (sector_t)info->size * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5622 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5623 | if (mddev->raid_disks != info->raid_disks) |
| 5624 | rv = update_raid_disks(mddev, info->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5625 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5626 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) { |
| 5627 | if (mddev->pers->quiesce == NULL) |
| 5628 | return -EINVAL; |
| 5629 | if (mddev->recovery || mddev->sync_thread) |
| 5630 | return -EBUSY; |
| 5631 | if (info->state & (1<<MD_SB_BITMAP_PRESENT)) { |
| 5632 | /* add the bitmap */ |
| 5633 | if (mddev->bitmap) |
| 5634 | return -EEXIST; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5635 | if (mddev->bitmap_info.default_offset == 0) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5636 | return -EINVAL; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5637 | mddev->bitmap_info.offset = |
| 5638 | mddev->bitmap_info.default_offset; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5639 | mddev->pers->quiesce(mddev, 1); |
| 5640 | rv = bitmap_create(mddev); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 5641 | if (!rv) |
| 5642 | rv = bitmap_load(mddev); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5643 | if (rv) |
| 5644 | bitmap_destroy(mddev); |
| 5645 | mddev->pers->quiesce(mddev, 0); |
| 5646 | } else { |
| 5647 | /* remove the bitmap */ |
| 5648 | if (!mddev->bitmap) |
| 5649 | return -ENOENT; |
| 5650 | if (mddev->bitmap->file) |
| 5651 | return -EINVAL; |
| 5652 | mddev->pers->quiesce(mddev, 1); |
| 5653 | bitmap_destroy(mddev); |
| 5654 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5655 | mddev->bitmap_info.offset = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5656 | } |
| 5657 | } |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5658 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | return rv; |
| 5660 | } |
| 5661 | |
| 5662 | static int set_disk_faulty(mddev_t *mddev, dev_t dev) |
| 5663 | { |
| 5664 | mdk_rdev_t *rdev; |
| 5665 | |
| 5666 | if (mddev->pers == NULL) |
| 5667 | return -ENODEV; |
| 5668 | |
| 5669 | rdev = find_rdev(mddev, dev); |
| 5670 | if (!rdev) |
| 5671 | return -ENODEV; |
| 5672 | |
| 5673 | md_error(mddev, rdev); |
| 5674 | return 0; |
| 5675 | } |
| 5676 | |
Andre Noll | 2f9618c | 2008-04-25 18:57:58 +0200 | [diff] [blame] | 5677 | /* |
| 5678 | * We have a problem here : there is no easy way to give a CHS |
| 5679 | * virtual geometry. We currently pretend that we have a 2 heads |
| 5680 | * 4 sectors (with a BIG number of cylinders...). This drives |
| 5681 | * dosfs just mad... ;-) |
| 5682 | */ |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5683 | static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 5684 | { |
| 5685 | mddev_t *mddev = bdev->bd_disk->private_data; |
| 5686 | |
| 5687 | geo->heads = 2; |
| 5688 | geo->sectors = 4; |
NeilBrown | 49ce6ce | 2010-03-29 10:51:42 +1100 | [diff] [blame] | 5689 | geo->cylinders = mddev->array_sectors / 8; |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5690 | return 0; |
| 5691 | } |
| 5692 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5693 | static int md_ioctl(struct block_device *bdev, fmode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5694 | unsigned int cmd, unsigned long arg) |
| 5695 | { |
| 5696 | int err = 0; |
| 5697 | void __user *argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | mddev_t *mddev = NULL; |
Dan Williams | e221835 | 2010-05-12 08:25:37 +1000 | [diff] [blame] | 5699 | int ro; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | |
| 5701 | if (!capable(CAP_SYS_ADMIN)) |
| 5702 | return -EACCES; |
| 5703 | |
| 5704 | /* |
| 5705 | * Commands dealing with the RAID driver but not any |
| 5706 | * particular array: |
| 5707 | */ |
| 5708 | switch (cmd) |
| 5709 | { |
| 5710 | case RAID_VERSION: |
| 5711 | err = get_version(argp); |
| 5712 | goto done; |
| 5713 | |
| 5714 | case PRINT_RAID_DEBUG: |
| 5715 | err = 0; |
| 5716 | md_print_devices(); |
| 5717 | goto done; |
| 5718 | |
| 5719 | #ifndef MODULE |
| 5720 | case RAID_AUTORUN: |
| 5721 | err = 0; |
| 5722 | autostart_arrays(arg); |
| 5723 | goto done; |
| 5724 | #endif |
| 5725 | default:; |
| 5726 | } |
| 5727 | |
| 5728 | /* |
| 5729 | * Commands creating/starting a new array: |
| 5730 | */ |
| 5731 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5732 | mddev = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5733 | |
| 5734 | if (!mddev) { |
| 5735 | BUG(); |
| 5736 | goto abort; |
| 5737 | } |
| 5738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5739 | err = mddev_lock(mddev); |
| 5740 | if (err) { |
| 5741 | printk(KERN_INFO |
| 5742 | "md: ioctl lock interrupted, reason %d, cmd %d\n", |
| 5743 | err, cmd); |
| 5744 | goto abort; |
| 5745 | } |
| 5746 | |
| 5747 | switch (cmd) |
| 5748 | { |
| 5749 | case SET_ARRAY_INFO: |
| 5750 | { |
| 5751 | mdu_array_info_t info; |
| 5752 | if (!arg) |
| 5753 | memset(&info, 0, sizeof(info)); |
| 5754 | else if (copy_from_user(&info, argp, sizeof(info))) { |
| 5755 | err = -EFAULT; |
| 5756 | goto abort_unlock; |
| 5757 | } |
| 5758 | if (mddev->pers) { |
| 5759 | err = update_array_info(mddev, &info); |
| 5760 | if (err) { |
| 5761 | printk(KERN_WARNING "md: couldn't update" |
| 5762 | " array info. %d\n", err); |
| 5763 | goto abort_unlock; |
| 5764 | } |
| 5765 | goto done_unlock; |
| 5766 | } |
| 5767 | if (!list_empty(&mddev->disks)) { |
| 5768 | printk(KERN_WARNING |
| 5769 | "md: array %s already has disks!\n", |
| 5770 | mdname(mddev)); |
| 5771 | err = -EBUSY; |
| 5772 | goto abort_unlock; |
| 5773 | } |
| 5774 | if (mddev->raid_disks) { |
| 5775 | printk(KERN_WARNING |
| 5776 | "md: array %s already initialised!\n", |
| 5777 | mdname(mddev)); |
| 5778 | err = -EBUSY; |
| 5779 | goto abort_unlock; |
| 5780 | } |
| 5781 | err = set_array_info(mddev, &info); |
| 5782 | if (err) { |
| 5783 | printk(KERN_WARNING "md: couldn't set" |
| 5784 | " array info. %d\n", err); |
| 5785 | goto abort_unlock; |
| 5786 | } |
| 5787 | } |
| 5788 | goto done_unlock; |
| 5789 | |
| 5790 | default:; |
| 5791 | } |
| 5792 | |
| 5793 | /* |
| 5794 | * Commands querying/configuring an existing array: |
| 5795 | */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5796 | /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY, |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 5797 | * RUN_ARRAY, and GET_ and SET_BITMAP_FILE are allowed */ |
NeilBrown | a17184a | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 5798 | if ((!mddev->raid_disks && !mddev->external) |
| 5799 | && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY |
| 5800 | && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE |
| 5801 | && cmd != GET_BITMAP_FILE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5802 | err = -ENODEV; |
| 5803 | goto abort_unlock; |
| 5804 | } |
| 5805 | |
| 5806 | /* |
| 5807 | * Commands even a read-only array can execute: |
| 5808 | */ |
| 5809 | switch (cmd) |
| 5810 | { |
| 5811 | case GET_ARRAY_INFO: |
| 5812 | err = get_array_info(mddev, argp); |
| 5813 | goto done_unlock; |
| 5814 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5815 | case GET_BITMAP_FILE: |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 5816 | err = get_bitmap_file(mddev, argp); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5817 | goto done_unlock; |
| 5818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5819 | case GET_DISK_INFO: |
| 5820 | err = get_disk_info(mddev, argp); |
| 5821 | goto done_unlock; |
| 5822 | |
| 5823 | case RESTART_ARRAY_RW: |
| 5824 | err = restart_array(mddev); |
| 5825 | goto done_unlock; |
| 5826 | |
| 5827 | case STOP_ARRAY: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5828 | err = do_md_stop(mddev, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | goto done_unlock; |
| 5830 | |
| 5831 | case STOP_ARRAY_RO: |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 5832 | err = md_set_readonly(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | goto done_unlock; |
| 5834 | |
Dan Williams | e221835 | 2010-05-12 08:25:37 +1000 | [diff] [blame] | 5835 | case BLKROSET: |
| 5836 | if (get_user(ro, (int __user *)(arg))) { |
| 5837 | err = -EFAULT; |
| 5838 | goto done_unlock; |
| 5839 | } |
| 5840 | err = -EINVAL; |
| 5841 | |
| 5842 | /* if the bdev is going readonly the value of mddev->ro |
| 5843 | * does not matter, no writes are coming |
| 5844 | */ |
| 5845 | if (ro) |
| 5846 | goto done_unlock; |
| 5847 | |
| 5848 | /* are we are already prepared for writes? */ |
| 5849 | if (mddev->ro != 1) |
| 5850 | goto done_unlock; |
| 5851 | |
| 5852 | /* transitioning to readauto need only happen for |
| 5853 | * arrays that call md_write_start |
| 5854 | */ |
| 5855 | if (mddev->pers) { |
| 5856 | err = restart_array(mddev); |
| 5857 | if (err == 0) { |
| 5858 | mddev->ro = 2; |
| 5859 | set_disk_ro(mddev->gendisk, 0); |
| 5860 | } |
| 5861 | } |
| 5862 | goto done_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | /* |
| 5866 | * The remaining ioctls are changing the state of the |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5867 | * superblock, so we do not allow them on read-only arrays. |
| 5868 | * However non-MD ioctls (e.g. get-size) will still come through |
| 5869 | * here and hit the 'default' below, so only disallow |
| 5870 | * 'md' ioctls, and switch to rw mode if started auto-readonly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | */ |
Andre Noll | bb57fc6 | 2008-04-25 19:06:35 +0200 | [diff] [blame] | 5872 | if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5873 | if (mddev->ro == 2) { |
| 5874 | mddev->ro = 0; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 5875 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 5876 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5877 | md_wakeup_thread(mddev->thread); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5878 | } else { |
| 5879 | err = -EROFS; |
| 5880 | goto abort_unlock; |
| 5881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5882 | } |
| 5883 | |
| 5884 | switch (cmd) |
| 5885 | { |
| 5886 | case ADD_NEW_DISK: |
| 5887 | { |
| 5888 | mdu_disk_info_t info; |
| 5889 | if (copy_from_user(&info, argp, sizeof(info))) |
| 5890 | err = -EFAULT; |
| 5891 | else |
| 5892 | err = add_new_disk(mddev, &info); |
| 5893 | goto done_unlock; |
| 5894 | } |
| 5895 | |
| 5896 | case HOT_REMOVE_DISK: |
| 5897 | err = hot_remove_disk(mddev, new_decode_dev(arg)); |
| 5898 | goto done_unlock; |
| 5899 | |
| 5900 | case HOT_ADD_DISK: |
| 5901 | err = hot_add_disk(mddev, new_decode_dev(arg)); |
| 5902 | goto done_unlock; |
| 5903 | |
| 5904 | case SET_DISK_FAULTY: |
| 5905 | err = set_disk_faulty(mddev, new_decode_dev(arg)); |
| 5906 | goto done_unlock; |
| 5907 | |
| 5908 | case RUN_ARRAY: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5909 | err = do_md_run(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5910 | goto done_unlock; |
| 5911 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5912 | case SET_BITMAP_FILE: |
| 5913 | err = set_bitmap_file(mddev, (int)arg); |
| 5914 | goto done_unlock; |
| 5915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5916 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5917 | err = -EINVAL; |
| 5918 | goto abort_unlock; |
| 5919 | } |
| 5920 | |
| 5921 | done_unlock: |
| 5922 | abort_unlock: |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5923 | if (mddev->hold_active == UNTIL_IOCTL && |
| 5924 | err != -EINVAL) |
| 5925 | mddev->hold_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | mddev_unlock(mddev); |
| 5927 | |
| 5928 | return err; |
| 5929 | done: |
| 5930 | if (err) |
| 5931 | MD_BUG(); |
| 5932 | abort: |
| 5933 | return err; |
| 5934 | } |
Arnd Bergmann | aa98aa3 | 2009-12-14 12:50:05 +1100 | [diff] [blame] | 5935 | #ifdef CONFIG_COMPAT |
| 5936 | static int md_compat_ioctl(struct block_device *bdev, fmode_t mode, |
| 5937 | unsigned int cmd, unsigned long arg) |
| 5938 | { |
| 5939 | switch (cmd) { |
| 5940 | case HOT_REMOVE_DISK: |
| 5941 | case HOT_ADD_DISK: |
| 5942 | case SET_DISK_FAULTY: |
| 5943 | case SET_BITMAP_FILE: |
| 5944 | /* These take in integer arg, do not convert */ |
| 5945 | break; |
| 5946 | default: |
| 5947 | arg = (unsigned long)compat_ptr(arg); |
| 5948 | break; |
| 5949 | } |
| 5950 | |
| 5951 | return md_ioctl(bdev, mode, cmd, arg); |
| 5952 | } |
| 5953 | #endif /* CONFIG_COMPAT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5954 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5955 | static int md_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5956 | { |
| 5957 | /* |
| 5958 | * Succeed if we can lock the mddev, which confirms that |
| 5959 | * it isn't being stopped right now. |
| 5960 | */ |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5961 | mddev_t *mddev = mddev_find(bdev->bd_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5962 | int err; |
| 5963 | |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 5964 | lock_kernel(); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5965 | if (mddev->gendisk != bdev->bd_disk) { |
| 5966 | /* we are racing with mddev_put which is discarding this |
| 5967 | * bd_disk. |
| 5968 | */ |
| 5969 | mddev_put(mddev); |
| 5970 | /* Wait until bdev->bd_disk is definitely gone */ |
| 5971 | flush_scheduled_work(); |
| 5972 | /* Then retry the open from the top */ |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 5973 | unlock_kernel(); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5974 | return -ERESTARTSYS; |
| 5975 | } |
| 5976 | BUG_ON(mddev != bdev->bd_disk->private_data); |
| 5977 | |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 5978 | if ((err = mutex_lock_interruptible(&mddev->open_mutex))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5979 | goto out; |
| 5980 | |
| 5981 | err = 0; |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 5982 | atomic_inc(&mddev->openers); |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 5983 | mutex_unlock(&mddev->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5984 | |
NeilBrown | f3b99be | 2010-06-24 13:31:03 +1000 | [diff] [blame] | 5985 | check_disk_size_change(mddev->gendisk, bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5986 | out: |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 5987 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5988 | return err; |
| 5989 | } |
| 5990 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5991 | static int md_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5992 | { |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5993 | mddev_t *mddev = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | |
Eric Sesterhenn | 52e5f9d | 2006-10-03 23:33:23 +0200 | [diff] [blame] | 5995 | BUG_ON(!mddev); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 5996 | lock_kernel(); |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 5997 | atomic_dec(&mddev->openers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5998 | mddev_put(mddev); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 5999 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6000 | |
| 6001 | return 0; |
| 6002 | } |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 6003 | static const struct block_device_operations md_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6004 | { |
| 6005 | .owner = THIS_MODULE, |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 6006 | .open = md_open, |
| 6007 | .release = md_release, |
NeilBrown | b492b85 | 2009-05-26 12:57:36 +1000 | [diff] [blame] | 6008 | .ioctl = md_ioctl, |
Arnd Bergmann | aa98aa3 | 2009-12-14 12:50:05 +1100 | [diff] [blame] | 6009 | #ifdef CONFIG_COMPAT |
| 6010 | .compat_ioctl = md_compat_ioctl, |
| 6011 | #endif |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 6012 | .getgeo = md_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | }; |
| 6014 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 6015 | static int md_thread(void * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | { |
| 6017 | mdk_thread_t *thread = arg; |
| 6018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6019 | /* |
| 6020 | * md_thread is a 'system-thread', it's priority should be very |
| 6021 | * high. We avoid resource deadlocks individually in each |
| 6022 | * raid personality. (RAID5 does preallocation) We also use RR and |
| 6023 | * the very same RT priority as kswapd, thus we will never get |
| 6024 | * into a priority inversion deadlock. |
| 6025 | * |
| 6026 | * we definitely have to have equal or higher priority than |
| 6027 | * bdflush, otherwise bdflush will deadlock if there are too |
| 6028 | * many dirty RAID5 blocks. |
| 6029 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6030 | |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 6031 | allow_signal(SIGKILL); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6032 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6033 | |
NeilBrown | 93588e2 | 2005-11-15 00:09:12 -0800 | [diff] [blame] | 6034 | /* We need to wait INTERRUPTIBLE so that |
| 6035 | * we don't add to the load-average. |
| 6036 | * That means we need to be sure no signals are |
| 6037 | * pending |
| 6038 | */ |
| 6039 | if (signal_pending(current)) |
| 6040 | flush_signals(current); |
| 6041 | |
| 6042 | wait_event_interruptible_timeout |
| 6043 | (thread->wqueue, |
| 6044 | test_bit(THREAD_WAKEUP, &thread->flags) |
| 6045 | || kthread_should_stop(), |
| 6046 | thread->timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6047 | |
| 6048 | clear_bit(THREAD_WAKEUP, &thread->flags); |
| 6049 | |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 6050 | thread->run(thread->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6051 | } |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6053 | return 0; |
| 6054 | } |
| 6055 | |
| 6056 | void md_wakeup_thread(mdk_thread_t *thread) |
| 6057 | { |
| 6058 | if (thread) { |
| 6059 | dprintk("md: waking up MD thread %s.\n", thread->tsk->comm); |
| 6060 | set_bit(THREAD_WAKEUP, &thread->flags); |
| 6061 | wake_up(&thread->wqueue); |
| 6062 | } |
| 6063 | } |
| 6064 | |
| 6065 | mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, |
| 6066 | const char *name) |
| 6067 | { |
| 6068 | mdk_thread_t *thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6069 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 6070 | thread = kzalloc(sizeof(mdk_thread_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6071 | if (!thread) |
| 6072 | return NULL; |
| 6073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6074 | init_waitqueue_head(&thread->wqueue); |
| 6075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6076 | thread->run = run; |
| 6077 | thread->mddev = mddev; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6078 | thread->timeout = MAX_SCHEDULE_TIMEOUT; |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 6079 | thread->tsk = kthread_run(md_thread, thread, |
| 6080 | "%s_%s", |
| 6081 | mdname(thread->mddev), |
| 6082 | name ?: mddev->pers->name); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6083 | if (IS_ERR(thread->tsk)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6084 | kfree(thread); |
| 6085 | return NULL; |
| 6086 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | return thread; |
| 6088 | } |
| 6089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6090 | void md_unregister_thread(mdk_thread_t *thread) |
| 6091 | { |
NeilBrown | e0cf8f0 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6092 | if (!thread) |
| 6093 | return; |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 6094 | dprintk("interrupting MD-thread pid %d\n", task_pid_nr(thread->tsk)); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6095 | |
| 6096 | kthread_stop(thread->tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6097 | kfree(thread); |
| 6098 | } |
| 6099 | |
| 6100 | void md_error(mddev_t *mddev, mdk_rdev_t *rdev) |
| 6101 | { |
| 6102 | if (!mddev) { |
| 6103 | MD_BUG(); |
| 6104 | return; |
| 6105 | } |
| 6106 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6107 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | return; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 6109 | |
| 6110 | if (mddev->external) |
| 6111 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6112 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6113 | dprintk("md_error dev:%s, rdev:(%d:%d), (caller: %p,%p,%p,%p).\n", |
| 6114 | mdname(mddev), |
| 6115 | MAJOR(rdev->bdev->bd_dev), MINOR(rdev->bdev->bd_dev), |
| 6116 | __builtin_return_address(0),__builtin_return_address(1), |
| 6117 | __builtin_return_address(2),__builtin_return_address(3)); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6118 | */ |
Andrew Morton | d0a0a5e | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 6119 | if (!mddev->pers) |
| 6120 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | if (!mddev->pers->error_handler) |
| 6122 | return; |
| 6123 | mddev->pers->error_handler(mddev,rdev); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6124 | if (mddev->degraded) |
| 6125 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6126 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6127 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 6128 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6129 | md_wakeup_thread(mddev->thread); |
NeilBrown | 768a418 | 2010-07-26 11:49:55 +1000 | [diff] [blame] | 6130 | if (mddev->event_work.func) |
| 6131 | schedule_work(&mddev->event_work); |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 6132 | md_new_event_inintr(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | /* seq_file implementation /proc/mdstat */ |
| 6136 | |
| 6137 | static void status_unused(struct seq_file *seq) |
| 6138 | { |
| 6139 | int i = 0; |
| 6140 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6141 | |
| 6142 | seq_printf(seq, "unused devices: "); |
| 6143 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6144 | list_for_each_entry(rdev, &pending_raid_disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6145 | char b[BDEVNAME_SIZE]; |
| 6146 | i++; |
| 6147 | seq_printf(seq, "%s ", |
| 6148 | bdevname(rdev->bdev,b)); |
| 6149 | } |
| 6150 | if (!i) |
| 6151 | seq_printf(seq, "<none>"); |
| 6152 | |
| 6153 | seq_printf(seq, "\n"); |
| 6154 | } |
| 6155 | |
| 6156 | |
| 6157 | static void status_resync(struct seq_file *seq, mddev_t * mddev) |
| 6158 | { |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6159 | sector_t max_sectors, resync, res; |
| 6160 | unsigned long dt, db; |
| 6161 | sector_t rt; |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6162 | int scale; |
| 6163 | unsigned int per_milli; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6164 | |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6165 | resync = mddev->curr_resync - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6166 | |
| 6167 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6168 | max_sectors = mddev->resync_max_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6169 | else |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6170 | max_sectors = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6171 | |
| 6172 | /* |
| 6173 | * Should not happen. |
| 6174 | */ |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6175 | if (!max_sectors) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6176 | MD_BUG(); |
| 6177 | return; |
| 6178 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6179 | /* Pick 'scale' such that (resync>>scale)*1000 will fit |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6180 | * in a sector_t, and (max_sectors>>scale) will fit in a |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6181 | * u32, as those are the requirements for sector_div. |
| 6182 | * Thus 'scale' must be at least 10 |
| 6183 | */ |
| 6184 | scale = 10; |
| 6185 | if (sizeof(sector_t) > sizeof(unsigned long)) { |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6186 | while ( max_sectors/2 > (1ULL<<(scale+32))) |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6187 | scale++; |
| 6188 | } |
| 6189 | res = (resync>>scale)*1000; |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6190 | sector_div(res, (u32)((max_sectors>>scale)+1)); |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6191 | |
| 6192 | per_milli = res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6193 | { |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6194 | int i, x = per_milli/50, y = 20-x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6195 | seq_printf(seq, "["); |
| 6196 | for (i = 0; i < x; i++) |
| 6197 | seq_printf(seq, "="); |
| 6198 | seq_printf(seq, ">"); |
| 6199 | for (i = 0; i < y; i++) |
| 6200 | seq_printf(seq, "."); |
| 6201 | seq_printf(seq, "] "); |
| 6202 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6203 | seq_printf(seq, " %s =%3u.%u%% (%llu/%llu)", |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 6204 | (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)? |
| 6205 | "reshape" : |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6206 | (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)? |
| 6207 | "check" : |
| 6208 | (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ? |
| 6209 | "resync" : "recovery"))), |
| 6210 | per_milli/10, per_milli % 10, |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6211 | (unsigned long long) resync/2, |
| 6212 | (unsigned long long) max_sectors/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6213 | |
| 6214 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6215 | * dt: time from mark until now |
| 6216 | * db: blocks written from mark until now |
| 6217 | * rt: remaining time |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6218 | * |
| 6219 | * rt is a sector_t, so could be 32bit or 64bit. |
| 6220 | * So we divide before multiply in case it is 32bit and close |
| 6221 | * to the limit. |
| 6222 | * We scale the divisor (db) by 32 to avoid loosing precision |
| 6223 | * near the end of resync when the number of remaining sectors |
| 6224 | * is close to 'db'. |
| 6225 | * We then divide rt by 32 after multiplying by db to compensate. |
| 6226 | * The '+1' avoids division by zero if db is very small. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6227 | */ |
| 6228 | dt = ((jiffies - mddev->resync_mark) / HZ); |
| 6229 | if (!dt) dt++; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6230 | db = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active)) |
| 6231 | - mddev->resync_mark_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6232 | |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6233 | rt = max_sectors - resync; /* number of remaining sectors */ |
| 6234 | sector_div(rt, db/32+1); |
| 6235 | rt *= dt; |
| 6236 | rt >>= 5; |
| 6237 | |
| 6238 | seq_printf(seq, " finish=%lu.%lumin", (unsigned long)rt / 60, |
| 6239 | ((unsigned long)rt % 60)/6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6240 | |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6241 | seq_printf(seq, " speed=%ldK/sec", db/2/dt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | static void *md_seq_start(struct seq_file *seq, loff_t *pos) |
| 6245 | { |
| 6246 | struct list_head *tmp; |
| 6247 | loff_t l = *pos; |
| 6248 | mddev_t *mddev; |
| 6249 | |
| 6250 | if (l >= 0x10000) |
| 6251 | return NULL; |
| 6252 | if (!l--) |
| 6253 | /* header */ |
| 6254 | return (void*)1; |
| 6255 | |
| 6256 | spin_lock(&all_mddevs_lock); |
| 6257 | list_for_each(tmp,&all_mddevs) |
| 6258 | if (!l--) { |
| 6259 | mddev = list_entry(tmp, mddev_t, all_mddevs); |
| 6260 | mddev_get(mddev); |
| 6261 | spin_unlock(&all_mddevs_lock); |
| 6262 | return mddev; |
| 6263 | } |
| 6264 | spin_unlock(&all_mddevs_lock); |
| 6265 | if (!l--) |
| 6266 | return (void*)2;/* tail */ |
| 6267 | return NULL; |
| 6268 | } |
| 6269 | |
| 6270 | static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 6271 | { |
| 6272 | struct list_head *tmp; |
| 6273 | mddev_t *next_mddev, *mddev = v; |
| 6274 | |
| 6275 | ++*pos; |
| 6276 | if (v == (void*)2) |
| 6277 | return NULL; |
| 6278 | |
| 6279 | spin_lock(&all_mddevs_lock); |
| 6280 | if (v == (void*)1) |
| 6281 | tmp = all_mddevs.next; |
| 6282 | else |
| 6283 | tmp = mddev->all_mddevs.next; |
| 6284 | if (tmp != &all_mddevs) |
| 6285 | next_mddev = mddev_get(list_entry(tmp,mddev_t,all_mddevs)); |
| 6286 | else { |
| 6287 | next_mddev = (void*)2; |
| 6288 | *pos = 0x10000; |
| 6289 | } |
| 6290 | spin_unlock(&all_mddevs_lock); |
| 6291 | |
| 6292 | if (v != (void*)1) |
| 6293 | mddev_put(mddev); |
| 6294 | return next_mddev; |
| 6295 | |
| 6296 | } |
| 6297 | |
| 6298 | static void md_seq_stop(struct seq_file *seq, void *v) |
| 6299 | { |
| 6300 | mddev_t *mddev = v; |
| 6301 | |
| 6302 | if (mddev && v != (void*)1 && v != (void*)2) |
| 6303 | mddev_put(mddev); |
| 6304 | } |
| 6305 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6306 | struct mdstat_info { |
| 6307 | int event; |
| 6308 | }; |
| 6309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6310 | static int md_seq_show(struct seq_file *seq, void *v) |
| 6311 | { |
| 6312 | mddev_t *mddev = v; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6313 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6314 | mdk_rdev_t *rdev; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6315 | struct mdstat_info *mi = seq->private; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6316 | struct bitmap *bitmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6317 | |
| 6318 | if (v == (void*)1) { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6319 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6320 | seq_printf(seq, "Personalities : "); |
| 6321 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6322 | list_for_each_entry(pers, &pers_list, list) |
| 6323 | seq_printf(seq, "[%s] ", pers->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6324 | |
| 6325 | spin_unlock(&pers_lock); |
| 6326 | seq_printf(seq, "\n"); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6327 | mi->event = atomic_read(&md_event_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6328 | return 0; |
| 6329 | } |
| 6330 | if (v == (void*)2) { |
| 6331 | status_unused(seq); |
| 6332 | return 0; |
| 6333 | } |
| 6334 | |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 6335 | if (mddev_lock(mddev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | return -EINTR; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 6337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6338 | if (mddev->pers || mddev->raid_disks || !list_empty(&mddev->disks)) { |
| 6339 | seq_printf(seq, "%s : %sactive", mdname(mddev), |
| 6340 | mddev->pers ? "" : "in"); |
| 6341 | if (mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6342 | if (mddev->ro==1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6343 | seq_printf(seq, " (read-only)"); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6344 | if (mddev->ro==2) |
NeilBrown | 52720ae | 2008-03-10 11:43:47 -0700 | [diff] [blame] | 6345 | seq_printf(seq, " (auto-read-only)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6346 | seq_printf(seq, " %s", mddev->pers->name); |
| 6347 | } |
| 6348 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6349 | sectors = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6350 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6351 | char b[BDEVNAME_SIZE]; |
| 6352 | seq_printf(seq, " %s[%d]", |
| 6353 | bdevname(rdev->bdev,b), rdev->desc_nr); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 6354 | if (test_bit(WriteMostly, &rdev->flags)) |
| 6355 | seq_printf(seq, "(W)"); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6356 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6357 | seq_printf(seq, "(F)"); |
| 6358 | continue; |
NeilBrown | b325a32 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6359 | } else if (rdev->raid_disk < 0) |
| 6360 | seq_printf(seq, "(S)"); /* spare */ |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6361 | sectors += rdev->sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6362 | } |
| 6363 | |
| 6364 | if (!list_empty(&mddev->disks)) { |
| 6365 | if (mddev->pers) |
| 6366 | seq_printf(seq, "\n %llu blocks", |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 6367 | (unsigned long long) |
| 6368 | mddev->array_sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6369 | else |
| 6370 | seq_printf(seq, "\n %llu blocks", |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6371 | (unsigned long long)sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6372 | } |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6373 | if (mddev->persistent) { |
| 6374 | if (mddev->major_version != 0 || |
| 6375 | mddev->minor_version != 90) { |
| 6376 | seq_printf(seq," super %d.%d", |
| 6377 | mddev->major_version, |
| 6378 | mddev->minor_version); |
| 6379 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 6380 | } else if (mddev->external) |
| 6381 | seq_printf(seq, " super external:%s", |
| 6382 | mddev->metadata_type); |
| 6383 | else |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6384 | seq_printf(seq, " super non-persistent"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6385 | |
| 6386 | if (mddev->pers) { |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6387 | mddev->pers->status(seq, mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6388 | seq_printf(seq, "\n "); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 6389 | if (mddev->pers->sync_request) { |
| 6390 | if (mddev->curr_resync > 2) { |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6391 | status_resync(seq, mddev); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 6392 | seq_printf(seq, "\n "); |
| 6393 | } else if (mddev->curr_resync == 1 || mddev->curr_resync == 2) |
| 6394 | seq_printf(seq, "\tresync=DELAYED\n "); |
| 6395 | else if (mddev->recovery_cp < MaxSector) |
| 6396 | seq_printf(seq, "\tresync=PENDING\n "); |
| 6397 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6398 | } else |
| 6399 | seq_printf(seq, "\n "); |
| 6400 | |
| 6401 | if ((bitmap = mddev->bitmap)) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6402 | unsigned long chunk_kb; |
| 6403 | unsigned long flags; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6404 | spin_lock_irqsave(&bitmap->lock, flags); |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 6405 | chunk_kb = mddev->bitmap_info.chunksize >> 10; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6406 | seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], " |
| 6407 | "%lu%s chunk", |
| 6408 | bitmap->pages - bitmap->missing_pages, |
| 6409 | bitmap->pages, |
| 6410 | (bitmap->pages - bitmap->missing_pages) |
| 6411 | << (PAGE_SHIFT - 10), |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 6412 | chunk_kb ? chunk_kb : mddev->bitmap_info.chunksize, |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6413 | chunk_kb ? "KB" : "B"); |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 6414 | if (bitmap->file) { |
| 6415 | seq_printf(seq, ", file: "); |
Jan Blunck | c32c2f6 | 2008-02-14 19:38:43 -0800 | [diff] [blame] | 6416 | seq_path(seq, &bitmap->file->f_path, " \t\n"); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6417 | } |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 6418 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6419 | seq_printf(seq, "\n"); |
| 6420 | spin_unlock_irqrestore(&bitmap->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6421 | } |
| 6422 | |
| 6423 | seq_printf(seq, "\n"); |
| 6424 | } |
| 6425 | mddev_unlock(mddev); |
| 6426 | |
| 6427 | return 0; |
| 6428 | } |
| 6429 | |
Jan Engelhardt | 110518b | 2009-05-07 12:49:37 +1000 | [diff] [blame] | 6430 | static const struct seq_operations md_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6431 | .start = md_seq_start, |
| 6432 | .next = md_seq_next, |
| 6433 | .stop = md_seq_stop, |
| 6434 | .show = md_seq_show, |
| 6435 | }; |
| 6436 | |
| 6437 | static int md_seq_open(struct inode *inode, struct file *file) |
| 6438 | { |
| 6439 | int error; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6440 | struct mdstat_info *mi = kmalloc(sizeof(*mi), GFP_KERNEL); |
| 6441 | if (mi == NULL) |
| 6442 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6443 | |
| 6444 | error = seq_open(file, &md_seq_ops); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6445 | if (error) |
| 6446 | kfree(mi); |
| 6447 | else { |
| 6448 | struct seq_file *p = file->private_data; |
| 6449 | p->private = mi; |
| 6450 | mi->event = atomic_read(&md_event_count); |
| 6451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6452 | return error; |
| 6453 | } |
| 6454 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6455 | static unsigned int mdstat_poll(struct file *filp, poll_table *wait) |
| 6456 | { |
| 6457 | struct seq_file *m = filp->private_data; |
| 6458 | struct mdstat_info *mi = m->private; |
| 6459 | int mask; |
| 6460 | |
| 6461 | poll_wait(filp, &md_event_waiters, wait); |
| 6462 | |
| 6463 | /* always allow read */ |
| 6464 | mask = POLLIN | POLLRDNORM; |
| 6465 | |
| 6466 | if (mi->event != atomic_read(&md_event_count)) |
| 6467 | mask |= POLLERR | POLLPRI; |
| 6468 | return mask; |
| 6469 | } |
| 6470 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 6471 | static const struct file_operations md_seq_fops = { |
Akinobu Mita | e24650c | 2006-10-17 00:09:38 -0700 | [diff] [blame] | 6472 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6473 | .open = md_seq_open, |
| 6474 | .read = seq_read, |
| 6475 | .llseek = seq_lseek, |
Martin Peschke | c3f94b40 | 2007-05-09 02:35:35 -0700 | [diff] [blame] | 6476 | .release = seq_release_private, |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6477 | .poll = mdstat_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6478 | }; |
| 6479 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6480 | int register_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6481 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6482 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6483 | list_add_tail(&p->list, &pers_list); |
| 6484 | 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] | 6485 | spin_unlock(&pers_lock); |
| 6486 | return 0; |
| 6487 | } |
| 6488 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6489 | int unregister_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6490 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6491 | printk(KERN_INFO "md: %s personality unregistered\n", p->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6492 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6493 | list_del_init(&p->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6494 | spin_unlock(&pers_lock); |
| 6495 | return 0; |
| 6496 | } |
| 6497 | |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6498 | static int is_mddev_idle(mddev_t *mddev, int init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6499 | { |
| 6500 | mdk_rdev_t * rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6501 | int idle; |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6502 | int curr_events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6503 | |
| 6504 | idle = 1; |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 6505 | rcu_read_lock(); |
| 6506 | rdev_for_each_rcu(rdev, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6507 | struct gendisk *disk = rdev->bdev->bd_contains->bd_disk; |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6508 | curr_events = (int)part_stat_read(&disk->part0, sectors[0]) + |
| 6509 | (int)part_stat_read(&disk->part0, sectors[1]) - |
| 6510 | atomic_read(&disk->sync_io); |
NeilBrown | 713f6ab | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 6511 | /* sync IO will cause sync_io to increase before the disk_stats |
| 6512 | * as sync_io is counted when a request starts, and |
| 6513 | * disk_stats is counted when it completes. |
| 6514 | * So resync activity will cause curr_events to be smaller than |
| 6515 | * when there was no such activity. |
| 6516 | * non-sync IO will cause disk_stat to increase without |
| 6517 | * increasing sync_io so curr_events will (eventually) |
| 6518 | * be larger than it was before. Once it becomes |
| 6519 | * substantially larger, the test below will cause |
| 6520 | * the array to appear non-idle, and resync will slow |
| 6521 | * down. |
| 6522 | * If there is a lot of outstanding resync activity when |
| 6523 | * we set last_event to curr_events, then all that activity |
| 6524 | * completing might cause the array to appear non-idle |
| 6525 | * and resync will be slowed down even though there might |
| 6526 | * not have been non-resync activity. This will only |
| 6527 | * happen once though. 'last_events' will soon reflect |
| 6528 | * the state where there is little or no outstanding |
| 6529 | * resync requests, and further resync activity will |
| 6530 | * always make curr_events less than last_events. |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 6531 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6532 | */ |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6533 | if (init || curr_events - rdev->last_events > 64) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6534 | rdev->last_events = curr_events; |
| 6535 | idle = 0; |
| 6536 | } |
| 6537 | } |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 6538 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6539 | return idle; |
| 6540 | } |
| 6541 | |
| 6542 | void md_done_sync(mddev_t *mddev, int blocks, int ok) |
| 6543 | { |
| 6544 | /* another "blocks" (512byte) blocks have been synced */ |
| 6545 | atomic_sub(blocks, &mddev->recovery_active); |
| 6546 | wake_up(&mddev->recovery_wait); |
| 6547 | if (!ok) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6548 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6549 | md_wakeup_thread(mddev->thread); |
| 6550 | // stop recovery, signal do_sync .... |
| 6551 | } |
| 6552 | } |
| 6553 | |
| 6554 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6555 | /* md_write_start(mddev, bi) |
| 6556 | * If we need to update some array metadata (e.g. 'active' flag |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6557 | * in superblock) before writing, schedule a superblock update |
| 6558 | * and wait for it to complete. |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6559 | */ |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6560 | void md_write_start(mddev_t *mddev, struct bio *bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6561 | { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6562 | int did_change = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6563 | if (bio_data_dir(bi) != WRITE) |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6564 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6565 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6566 | BUG_ON(mddev->ro == 1); |
| 6567 | if (mddev->ro == 2) { |
| 6568 | /* need to switch to read/write */ |
| 6569 | mddev->ro = 0; |
| 6570 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6571 | md_wakeup_thread(mddev->thread); |
NeilBrown | 2515619 | 2008-03-04 14:29:32 -0800 | [diff] [blame] | 6572 | md_wakeup_thread(mddev->sync_thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6573 | did_change = 1; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6574 | } |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6575 | atomic_inc(&mddev->writes_pending); |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6576 | if (mddev->safemode == 1) |
| 6577 | mddev->safemode = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6578 | if (mddev->in_sync) { |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 6579 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6580 | if (mddev->in_sync) { |
| 6581 | mddev->in_sync = 0; |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6582 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6583 | md_wakeup_thread(mddev->thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6584 | did_change = 1; |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6585 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 6586 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6587 | } |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6588 | if (did_change) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6589 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 09a44cc | 2008-05-23 13:04:36 -0700 | [diff] [blame] | 6590 | wait_event(mddev->sb_wait, |
| 6591 | !test_bit(MD_CHANGE_CLEAN, &mddev->flags) && |
| 6592 | !test_bit(MD_CHANGE_PENDING, &mddev->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | void md_write_end(mddev_t *mddev) |
| 6596 | { |
| 6597 | if (atomic_dec_and_test(&mddev->writes_pending)) { |
| 6598 | if (mddev->safemode == 2) |
| 6599 | md_wakeup_thread(mddev->thread); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 6600 | else if (mddev->safemode_delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6601 | mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay); |
| 6602 | } |
| 6603 | } |
| 6604 | |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6605 | /* md_allow_write(mddev) |
| 6606 | * Calling this ensures that the array is marked 'active' so that writes |
| 6607 | * may proceed without blocking. It is important to call this before |
| 6608 | * attempting a GFP_KERNEL allocation while holding the mddev lock. |
| 6609 | * Must be called with mddev_lock held. |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6610 | * |
| 6611 | * In the ->external case MD_CHANGE_CLEAN can not be cleared until mddev->lock |
| 6612 | * is dropped, so return -EAGAIN after notifying userspace. |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6613 | */ |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6614 | int md_allow_write(mddev_t *mddev) |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6615 | { |
| 6616 | if (!mddev->pers) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6617 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6618 | if (mddev->ro) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6619 | return 0; |
Neil Brown | 1a0fd49 | 2008-06-28 08:31:27 +1000 | [diff] [blame] | 6620 | if (!mddev->pers->sync_request) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6621 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6622 | |
| 6623 | spin_lock_irq(&mddev->write_lock); |
| 6624 | if (mddev->in_sync) { |
| 6625 | mddev->in_sync = 0; |
| 6626 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
| 6627 | if (mddev->safemode_delay && |
| 6628 | mddev->safemode == 0) |
| 6629 | mddev->safemode = 1; |
| 6630 | spin_unlock_irq(&mddev->write_lock); |
| 6631 | md_update_sb(mddev, 0); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6632 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6633 | } else |
| 6634 | spin_unlock_irq(&mddev->write_lock); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6635 | |
| 6636 | if (test_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 6637 | return -EAGAIN; |
| 6638 | else |
| 6639 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6640 | } |
| 6641 | EXPORT_SYMBOL_GPL(md_allow_write); |
| 6642 | |
NeilBrown | b63d7c2 | 2010-06-01 19:37:33 +1000 | [diff] [blame] | 6643 | void md_unplug(mddev_t *mddev) |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6644 | { |
| 6645 | if (mddev->queue) |
| 6646 | blk_unplug(mddev->queue); |
| 6647 | if (mddev->plug) |
| 6648 | mddev->plug->unplug_fn(mddev->plug); |
| 6649 | } |
| 6650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6651 | #define SYNC_MARKS 10 |
| 6652 | #define SYNC_MARK_STEP (3*HZ) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6653 | void md_do_sync(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6654 | { |
| 6655 | mddev_t *mddev2; |
| 6656 | unsigned int currspeed = 0, |
| 6657 | window; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6658 | sector_t max_sectors,j, io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6659 | unsigned long mark[SYNC_MARKS]; |
| 6660 | sector_t mark_cnt[SYNC_MARKS]; |
| 6661 | int last_mark,m; |
| 6662 | struct list_head *tmp; |
| 6663 | sector_t last_check; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6664 | int skipped = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6665 | mdk_rdev_t *rdev; |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6666 | char *desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6667 | |
| 6668 | /* just incase thread restarts... */ |
| 6669 | if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) |
| 6670 | return; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6671 | if (mddev->ro) /* never try to sync a read-only array */ |
| 6672 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6673 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6674 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 6675 | if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 6676 | desc = "data-check"; |
| 6677 | else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6678 | desc = "requested-resync"; |
| 6679 | else |
| 6680 | desc = "resync"; |
| 6681 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 6682 | desc = "reshape"; |
| 6683 | else |
| 6684 | desc = "recovery"; |
| 6685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6686 | /* we overload curr_resync somewhat here. |
| 6687 | * 0 == not engaged in resync at all |
| 6688 | * 2 == checking that there is no conflict with another sync |
| 6689 | * 1 == like 2, but have yielded to allow conflicting resync to |
| 6690 | * commense |
| 6691 | * other == active in resync - this many blocks |
| 6692 | * |
| 6693 | * Before starting a resync we must have set curr_resync to |
| 6694 | * 2, and then checked that every "conflicting" array has curr_resync |
| 6695 | * less than ours. When we find one that is the same or higher |
| 6696 | * we wait on resync_wait. To avoid deadlock, we reduce curr_resync |
| 6697 | * to 1 if we choose to yield (based arbitrarily on address of mddev structure). |
| 6698 | * This will mean we have to start checking from the beginning again. |
| 6699 | * |
| 6700 | */ |
| 6701 | |
| 6702 | do { |
| 6703 | mddev->curr_resync = 2; |
| 6704 | |
| 6705 | try_again: |
NeilBrown | 404e4b4 | 2009-12-30 15:25:23 +1100 | [diff] [blame] | 6706 | if (kthread_should_stop()) |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 6707 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
NeilBrown | 404e4b4 | 2009-12-30 15:25:23 +1100 | [diff] [blame] | 6708 | |
| 6709 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6710 | goto skip; |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 6711 | for_each_mddev(mddev2, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6712 | if (mddev2 == mddev) |
| 6713 | continue; |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 6714 | if (!mddev->parallel_resync |
| 6715 | && mddev2->curr_resync |
| 6716 | && match_mddev_units(mddev, mddev2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6717 | DEFINE_WAIT(wq); |
| 6718 | if (mddev < mddev2 && mddev->curr_resync == 2) { |
| 6719 | /* arbitrarily yield */ |
| 6720 | mddev->curr_resync = 1; |
| 6721 | wake_up(&resync_wait); |
| 6722 | } |
| 6723 | if (mddev > mddev2 && mddev->curr_resync == 1) |
| 6724 | /* no need to wait here, we can wait the next |
| 6725 | * time 'round when curr_resync == 2 |
| 6726 | */ |
| 6727 | continue; |
NeilBrown | 9744197 | 2008-09-19 11:49:54 +1000 | [diff] [blame] | 6728 | /* We need to wait 'interruptible' so as not to |
| 6729 | * contribute to the load average, and not to |
| 6730 | * be caught by 'softlockup' |
| 6731 | */ |
| 6732 | prepare_to_wait(&resync_wait, &wq, TASK_INTERRUPTIBLE); |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 6733 | if (!kthread_should_stop() && |
NeilBrown | 8712e55 | 2005-10-26 01:58:58 -0700 | [diff] [blame] | 6734 | mddev2->curr_resync >= mddev->curr_resync) { |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6735 | printk(KERN_INFO "md: delaying %s of %s" |
| 6736 | " until %s has finished (they" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6737 | " share one or more physical units)\n", |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6738 | desc, mdname(mddev), mdname(mddev2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6739 | mddev_put(mddev2); |
NeilBrown | 9744197 | 2008-09-19 11:49:54 +1000 | [diff] [blame] | 6740 | if (signal_pending(current)) |
| 6741 | flush_signals(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6742 | schedule(); |
| 6743 | finish_wait(&resync_wait, &wq); |
| 6744 | goto try_again; |
| 6745 | } |
| 6746 | finish_wait(&resync_wait, &wq); |
| 6747 | } |
| 6748 | } |
| 6749 | } while (mddev->curr_resync < 2); |
| 6750 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6751 | j = 0; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6752 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6753 | /* resync follows the size requested by the personality, |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6754 | * which defaults to physical size, but can be virtual size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6755 | */ |
| 6756 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6757 | mddev->resync_mismatches = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6758 | /* we don't use the checkpoint if there's a bitmap */ |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 6759 | if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6760 | j = mddev->resync_min; |
| 6761 | else if (!mddev->bitmap) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6762 | j = mddev->recovery_cp; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 6763 | |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 6764 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6765 | max_sectors = mddev->dev_sectors; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6766 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6767 | /* recovery follows the physical size of devices */ |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6768 | max_sectors = mddev->dev_sectors; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6769 | j = MaxSector; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6770 | rcu_read_lock(); |
| 6771 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6772 | if (rdev->raid_disk >= 0 && |
| 6773 | !test_bit(Faulty, &rdev->flags) && |
| 6774 | !test_bit(In_sync, &rdev->flags) && |
| 6775 | rdev->recovery_offset < j) |
| 6776 | j = rdev->recovery_offset; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6777 | rcu_read_unlock(); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6778 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6779 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6780 | printk(KERN_INFO "md: %s of RAID array %s\n", desc, mdname(mddev)); |
| 6781 | printk(KERN_INFO "md: minimum _guaranteed_ speed:" |
| 6782 | " %d KB/sec/disk.\n", speed_min(mddev)); |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 6783 | printk(KERN_INFO "md: using maximum available idle IO bandwidth " |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6784 | "(but not more than %d KB/sec) for %s.\n", |
| 6785 | speed_max(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6786 | |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6787 | is_mddev_idle(mddev, 1); /* this initializes IO event counters */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6788 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6789 | io_sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6790 | for (m = 0; m < SYNC_MARKS; m++) { |
| 6791 | mark[m] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6792 | mark_cnt[m] = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6793 | } |
| 6794 | last_mark = 0; |
| 6795 | mddev->resync_mark = mark[last_mark]; |
| 6796 | mddev->resync_mark_cnt = mark_cnt[last_mark]; |
| 6797 | |
| 6798 | /* |
| 6799 | * Tune reconstruction: |
| 6800 | */ |
| 6801 | window = 32*(PAGE_SIZE/512); |
| 6802 | printk(KERN_INFO "md: using %dk window, over a total of %llu blocks.\n", |
| 6803 | window/2,(unsigned long long) max_sectors/2); |
| 6804 | |
| 6805 | atomic_set(&mddev->recovery_active, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6806 | last_check = 0; |
| 6807 | |
| 6808 | if (j>2) { |
| 6809 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6810 | "md: resuming %s of %s from checkpoint.\n", |
| 6811 | desc, mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6812 | mddev->curr_resync = j; |
| 6813 | } |
NeilBrown | efa5933 | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 6814 | mddev->curr_resync_completed = mddev->curr_resync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6815 | |
| 6816 | while (j < max_sectors) { |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6817 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6818 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6819 | skipped = 0; |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6820 | |
NeilBrown | 7a91ee1 | 2009-05-26 12:57:21 +1000 | [diff] [blame] | 6821 | if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && |
| 6822 | ((mddev->curr_resync > mddev->curr_resync_completed && |
| 6823 | (mddev->curr_resync - mddev->curr_resync_completed) |
| 6824 | > (max_sectors >> 4)) || |
| 6825 | (j - mddev->curr_resync_completed)*2 |
| 6826 | >= mddev->resync_max - mddev->curr_resync_completed |
| 6827 | )) { |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6828 | /* time to update curr_resync_completed */ |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6829 | md_unplug(mddev); |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6830 | wait_event(mddev->recovery_wait, |
| 6831 | atomic_read(&mddev->recovery_active) == 0); |
| 6832 | mddev->curr_resync_completed = |
| 6833 | mddev->curr_resync; |
NeilBrown | 676e42d | 2010-06-01 19:37:26 +1000 | [diff] [blame] | 6834 | if (mddev->persistent) |
| 6835 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6836 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6837 | } |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6838 | |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 6839 | while (j >= mddev->resync_max && !kthread_should_stop()) { |
| 6840 | /* As this condition is controlled by user-space, |
| 6841 | * we can block indefinitely, so use '_interruptible' |
| 6842 | * to avoid triggering warnings. |
| 6843 | */ |
| 6844 | flush_signals(current); /* just in case */ |
| 6845 | wait_event_interruptible(mddev->recovery_wait, |
| 6846 | mddev->resync_max > j |
| 6847 | || kthread_should_stop()); |
| 6848 | } |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6849 | |
| 6850 | if (kthread_should_stop()) |
| 6851 | goto interrupted; |
| 6852 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6853 | sectors = mddev->pers->sync_request(mddev, j, &skipped, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6854 | currspeed < speed_min(mddev)); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6855 | if (sectors == 0) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6856 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6857 | goto out; |
| 6858 | } |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6859 | |
| 6860 | if (!skipped) { /* actual IO requested */ |
| 6861 | io_sectors += sectors; |
| 6862 | atomic_add(sectors, &mddev->recovery_active); |
| 6863 | } |
| 6864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6865 | j += sectors; |
| 6866 | if (j>1) mddev->curr_resync = j; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6867 | mddev->curr_mark_cnt = io_sectors; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6868 | if (last_check == 0) |
| 6869 | /* this is the earliers that rebuilt will be |
| 6870 | * visible in /proc/mdstat |
| 6871 | */ |
| 6872 | md_new_event(mddev); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6873 | |
| 6874 | if (last_check + window > io_sectors || j == max_sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6875 | continue; |
| 6876 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6877 | last_check = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6878 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6879 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6880 | break; |
| 6881 | |
| 6882 | repeat: |
| 6883 | if (time_after_eq(jiffies, mark[last_mark] + SYNC_MARK_STEP )) { |
| 6884 | /* step marks */ |
| 6885 | int next = (last_mark+1) % SYNC_MARKS; |
| 6886 | |
| 6887 | mddev->resync_mark = mark[next]; |
| 6888 | mddev->resync_mark_cnt = mark_cnt[next]; |
| 6889 | mark[next] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6890 | mark_cnt[next] = io_sectors - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6891 | last_mark = next; |
| 6892 | } |
| 6893 | |
| 6894 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6895 | if (kthread_should_stop()) |
| 6896 | goto interrupted; |
| 6897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6898 | |
| 6899 | /* |
| 6900 | * this loop exits only if either when we are slower than |
| 6901 | * the 'hard' speed limit, or the system was IO-idle for |
| 6902 | * a jiffy. |
| 6903 | * the system might be non-idle CPU-wise, but we only care |
| 6904 | * about not overloading the IO subsystem. (things like an |
| 6905 | * e2fsck being done on the RAID array should execute fast) |
| 6906 | */ |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6907 | md_unplug(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6908 | cond_resched(); |
| 6909 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6910 | currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2 |
| 6911 | /((jiffies-mddev->resync_mark)/HZ +1) +1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6912 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 6913 | if (currspeed > speed_min(mddev)) { |
| 6914 | if ((currspeed > speed_max(mddev)) || |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6915 | !is_mddev_idle(mddev, 0)) { |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 6916 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6917 | goto repeat; |
| 6918 | } |
| 6919 | } |
| 6920 | } |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6921 | printk(KERN_INFO "md: %s: %s done.\n",mdname(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6922 | /* |
| 6923 | * this also signals 'finished resyncing' to md_stop |
| 6924 | */ |
| 6925 | out: |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6926 | md_unplug(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6927 | |
| 6928 | wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); |
| 6929 | |
| 6930 | /* tell personality that we are finished */ |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6931 | mddev->pers->sync_request(mddev, max_sectors, &skipped, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6932 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6933 | if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) && |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6934 | mddev->curr_resync > 2) { |
| 6935 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 6936 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6937 | if (mddev->curr_resync >= mddev->recovery_cp) { |
| 6938 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6939 | "md: checkpointing %s of %s.\n", |
| 6940 | desc, mdname(mddev)); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6941 | mddev->recovery_cp = mddev->curr_resync; |
| 6942 | } |
| 6943 | } else |
| 6944 | mddev->recovery_cp = MaxSector; |
| 6945 | } else { |
| 6946 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 6947 | mddev->curr_resync = MaxSector; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6948 | rcu_read_lock(); |
| 6949 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6950 | if (rdev->raid_disk >= 0 && |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 6951 | mddev->delta_disks >= 0 && |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6952 | !test_bit(Faulty, &rdev->flags) && |
| 6953 | !test_bit(In_sync, &rdev->flags) && |
| 6954 | rdev->recovery_offset < mddev->curr_resync) |
| 6955 | rdev->recovery_offset = mddev->curr_resync; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6956 | rcu_read_unlock(); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6957 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6958 | } |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 6959 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6961 | skip: |
NeilBrown | c07b70a | 2009-12-14 12:49:48 +1100 | [diff] [blame] | 6962 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6963 | /* We completed so min/max setting can be forgotten if used. */ |
| 6964 | if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6965 | mddev->resync_min = 0; |
| 6966 | mddev->resync_max = MaxSector; |
| 6967 | } else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6968 | mddev->resync_min = mddev->curr_resync_completed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6969 | mddev->curr_resync = 0; |
NeilBrown | efa5933 | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 6970 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 6971 | mddev->curr_resync_completed = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6972 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6973 | wake_up(&resync_wait); |
| 6974 | set_bit(MD_RECOVERY_DONE, &mddev->recovery); |
| 6975 | md_wakeup_thread(mddev->thread); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6976 | return; |
| 6977 | |
| 6978 | interrupted: |
| 6979 | /* |
| 6980 | * got a signal, exit. |
| 6981 | */ |
| 6982 | printk(KERN_INFO |
| 6983 | "md: md_do_sync() got signal ... exiting\n"); |
| 6984 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 6985 | goto out; |
| 6986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6987 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6988 | EXPORT_SYMBOL_GPL(md_do_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6989 | |
| 6990 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6991 | static int remove_and_add_spares(mddev_t *mddev) |
| 6992 | { |
| 6993 | mdk_rdev_t *rdev; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6994 | int spares = 0; |
| 6995 | |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6996 | mddev->curr_resync_completed = 0; |
| 6997 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6998 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6999 | if (rdev->raid_disk >= 0 && |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 7000 | !test_bit(Blocked, &rdev->flags) && |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7001 | (test_bit(Faulty, &rdev->flags) || |
| 7002 | ! test_bit(In_sync, &rdev->flags)) && |
| 7003 | atomic_read(&rdev->nr_pending)==0) { |
| 7004 | if (mddev->pers->hot_remove_disk( |
| 7005 | mddev, rdev->raid_disk)==0) { |
| 7006 | char nm[20]; |
| 7007 | sprintf(nm,"rd%d", rdev->raid_disk); |
| 7008 | sysfs_remove_link(&mddev->kobj, nm); |
| 7009 | rdev->raid_disk = -1; |
| 7010 | } |
| 7011 | } |
| 7012 | |
NeilBrown | 4044ba5 | 2009-01-09 08:31:11 +1100 | [diff] [blame] | 7013 | if (mddev->degraded && ! mddev->ro && !mddev->recovery_disabled) { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 7014 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 7015 | if (rdev->raid_disk >= 0 && |
Dan Williams | e542713 | 2008-07-28 23:28:06 -0700 | [diff] [blame] | 7016 | !test_bit(In_sync, &rdev->flags) && |
| 7017 | !test_bit(Blocked, &rdev->flags)) |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 7018 | spares++; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7019 | if (rdev->raid_disk < 0 |
| 7020 | && !test_bit(Faulty, &rdev->flags)) { |
| 7021 | rdev->recovery_offset = 0; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 7022 | if (mddev->pers-> |
| 7023 | hot_add_disk(mddev, rdev) == 0) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7024 | char nm[20]; |
| 7025 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 7026 | if (sysfs_create_link(&mddev->kobj, |
| 7027 | &rdev->kobj, nm)) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7028 | /* failure here is OK */; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7029 | spares++; |
| 7030 | md_new_event(mddev); |
NeilBrown | 93be75f | 2009-12-14 12:50:06 +1100 | [diff] [blame] | 7031 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7032 | } else |
| 7033 | break; |
| 7034 | } |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 7035 | } |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7036 | } |
| 7037 | return spares; |
| 7038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7039 | /* |
| 7040 | * This routine is regularly called by all per-raid-array threads to |
| 7041 | * deal with generic issues like resync and super-block update. |
| 7042 | * Raid personalities that don't have a thread (linear/raid0) do not |
| 7043 | * need this as they never do any recovery or update the superblock. |
| 7044 | * |
| 7045 | * It does not do any resync itself, but rather "forks" off other threads |
| 7046 | * to do that as needed. |
| 7047 | * When it is determined that resync is needed, we set MD_RECOVERY_RUNNING in |
| 7048 | * "->recovery" and create a thread at ->sync_thread. |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 7049 | * When the thread finishes it sets MD_RECOVERY_DONE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7050 | * and wakeups up this thread which will reap the thread and finish up. |
| 7051 | * This thread also removes any faulty devices (with nr_pending == 0). |
| 7052 | * |
| 7053 | * The overall approach is: |
| 7054 | * 1/ if the superblock needs updating, update it. |
| 7055 | * 2/ If a recovery thread is running, don't do anything else. |
| 7056 | * 3/ If recovery has finished, clean up, possibly marking spares active. |
| 7057 | * 4/ If there are any faulty devices, remove them. |
| 7058 | * 5/ If array is degraded, try to add spares devices |
| 7059 | * 6/ If array has spares or is not in-sync, start a resync thread. |
| 7060 | */ |
| 7061 | void md_check_recovery(mddev_t *mddev) |
| 7062 | { |
| 7063 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7064 | |
| 7065 | |
NeilBrown | 5f40402 | 2005-06-21 17:17:16 -0700 | [diff] [blame] | 7066 | if (mddev->bitmap) |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 7067 | bitmap_daemon_work(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7068 | |
| 7069 | if (mddev->ro) |
| 7070 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7071 | |
| 7072 | if (signal_pending(current)) { |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7073 | if (mddev->pers->sync_request && !mddev->external) { |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7074 | printk(KERN_INFO "md: %s in immediate safe mode\n", |
| 7075 | mdname(mddev)); |
| 7076 | mddev->safemode = 2; |
| 7077 | } |
| 7078 | flush_signals(current); |
| 7079 | } |
| 7080 | |
NeilBrown | c89a8ee | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 7081 | if (mddev->ro && !test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
| 7082 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7083 | if ( ! ( |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 7084 | (mddev->flags && !mddev->external) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7085 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7086 | test_bit(MD_RECOVERY_DONE, &mddev->recovery) || |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7087 | (mddev->external == 0 && mddev->safemode == 1) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7088 | (mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending) |
| 7089 | && !mddev->in_sync && mddev->recovery_cp == MaxSector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7090 | )) |
| 7091 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7092 | |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 7093 | if (mddev_trylock(mddev)) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7094 | int spares = 0; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7095 | |
NeilBrown | c89a8ee | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 7096 | if (mddev->ro) { |
| 7097 | /* Only thing we do on a ro array is remove |
| 7098 | * failed devices. |
| 7099 | */ |
| 7100 | remove_and_add_spares(mddev); |
| 7101 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 7102 | goto unlock; |
| 7103 | } |
| 7104 | |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7105 | if (!mddev->external) { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 7106 | int did_change = 0; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7107 | spin_lock_irq(&mddev->write_lock); |
| 7108 | if (mddev->safemode && |
| 7109 | !atomic_read(&mddev->writes_pending) && |
| 7110 | !mddev->in_sync && |
| 7111 | mddev->recovery_cp == MaxSector) { |
| 7112 | mddev->in_sync = 1; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 7113 | did_change = 1; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7114 | if (mddev->persistent) |
| 7115 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
| 7116 | } |
| 7117 | if (mddev->safemode == 1) |
| 7118 | mddev->safemode = 0; |
| 7119 | spin_unlock_irq(&mddev->write_lock); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 7120 | if (did_change) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7121 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7122 | } |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7123 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 7124 | if (mddev->flags) |
| 7125 | md_update_sb(mddev, 0); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 7126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7127 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && |
| 7128 | !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) { |
| 7129 | /* resync/recovery still happening */ |
| 7130 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 7131 | goto unlock; |
| 7132 | } |
| 7133 | if (mddev->sync_thread) { |
| 7134 | /* resync has finished, collect result */ |
| 7135 | md_unregister_thread(mddev->sync_thread); |
| 7136 | mddev->sync_thread = NULL; |
Dan Williams | 56ac36d | 2008-08-07 10:02:47 -0700 | [diff] [blame] | 7137 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery) && |
| 7138 | !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7139 | /* success...*/ |
| 7140 | /* activate any spares */ |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 7141 | if (mddev->pers->spare_active(mddev)) |
| 7142 | sysfs_notify(&mddev->kobj, NULL, |
| 7143 | "degraded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7144 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 7145 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && |
| 7146 | mddev->pers->finish_reshape) |
| 7147 | mddev->pers->finish_reshape(mddev); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 7148 | md_update_sb(mddev, 1); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 7149 | |
| 7150 | /* if array is no-longer degraded, then any saved_raid_disk |
| 7151 | * information must be scrapped |
| 7152 | */ |
| 7153 | if (!mddev->degraded) |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 7154 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 7155 | rdev->saved_raid_disk = -1; |
| 7156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7157 | mddev->recovery = 0; |
| 7158 | /* flag recovery needed just to double check */ |
| 7159 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7160 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 7161 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7162 | goto unlock; |
| 7163 | } |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7164 | /* Set RUNNING before clearing NEEDED to avoid |
| 7165 | * any transients in the value of "sync_action". |
| 7166 | */ |
| 7167 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 7168 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7169 | /* Clear some bits that don't mean anything, but |
| 7170 | * might be left set |
| 7171 | */ |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7172 | clear_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 7173 | clear_bit(MD_RECOVERY_DONE, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7174 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 7175 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 7176 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7177 | /* no recovery is running. |
| 7178 | * remove any failed drives, then |
| 7179 | * add spares if possible. |
| 7180 | * Spare are also removed and re-added, to allow |
| 7181 | * the personality to fail the re-add. |
| 7182 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7183 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7184 | if (mddev->reshape_position != MaxSector) { |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 7185 | if (mddev->pers->check_reshape == NULL || |
| 7186 | mddev->pers->check_reshape(mddev) != 0) |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7187 | /* Cannot proceed */ |
| 7188 | goto unlock; |
| 7189 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7190 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7191 | } else if ((spares = remove_and_add_spares(mddev))) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7192 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 7193 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
Dan Williams | 56ac36d | 2008-08-07 10:02:47 -0700 | [diff] [blame] | 7194 | clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7195 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7196 | } else if (mddev->recovery_cp < MaxSector) { |
| 7197 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7198 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7199 | } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 7200 | /* nothing to be done ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7201 | goto unlock; |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7203 | if (mddev->pers->sync_request) { |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 7204 | if (spares && mddev->bitmap && ! mddev->bitmap->file) { |
| 7205 | /* We are adding a device or devices to an array |
| 7206 | * which has the bitmap stored on all devices. |
| 7207 | * So make sure all bitmap pages get written |
| 7208 | */ |
| 7209 | bitmap_write_all(mddev->bitmap); |
| 7210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7211 | mddev->sync_thread = md_register_thread(md_do_sync, |
| 7212 | mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 7213 | "resync"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7214 | if (!mddev->sync_thread) { |
| 7215 | printk(KERN_ERR "%s: could not start resync" |
| 7216 | " thread...\n", |
| 7217 | mdname(mddev)); |
| 7218 | /* leave the spares where they are, it shouldn't hurt */ |
| 7219 | mddev->recovery = 0; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 7220 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7221 | md_wakeup_thread(mddev->sync_thread); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7222 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 7223 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7224 | } |
| 7225 | unlock: |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7226 | if (!mddev->sync_thread) { |
| 7227 | clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 7228 | if (test_and_clear_bit(MD_RECOVERY_RECOVER, |
| 7229 | &mddev->recovery)) |
NeilBrown | 0c3573f | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 7230 | if (mddev->sysfs_action) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7231 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7232 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7233 | mddev_unlock(mddev); |
| 7234 | } |
| 7235 | } |
| 7236 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 7237 | void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 7238 | { |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7239 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 7240 | wait_event_timeout(rdev->blocked_wait, |
| 7241 | !test_bit(Blocked, &rdev->flags), |
| 7242 | msecs_to_jiffies(5000)); |
| 7243 | rdev_dec_pending(rdev, mddev); |
| 7244 | } |
| 7245 | EXPORT_SYMBOL(md_wait_for_blocked_rdev); |
| 7246 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 7247 | static int md_notify_reboot(struct notifier_block *this, |
| 7248 | unsigned long code, void *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7249 | { |
| 7250 | struct list_head *tmp; |
| 7251 | mddev_t *mddev; |
| 7252 | |
| 7253 | if ((code == SYS_DOWN) || (code == SYS_HALT) || (code == SYS_POWER_OFF)) { |
| 7254 | |
| 7255 | printk(KERN_INFO "md: stopping all md devices.\n"); |
| 7256 | |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 7257 | for_each_mddev(mddev, tmp) |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 7258 | if (mddev_trylock(mddev)) { |
NeilBrown | 2b25000 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 7259 | /* Force a switch to readonly even array |
| 7260 | * appears to still be in use. Hence |
| 7261 | * the '100'. |
| 7262 | */ |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 7263 | md_set_readonly(mddev, 100); |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 7264 | mddev_unlock(mddev); |
| 7265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7266 | /* |
| 7267 | * certain more exotic SCSI devices are known to be |
| 7268 | * volatile wrt too early system reboots. While the |
| 7269 | * right place to handle this issue is the given |
| 7270 | * driver, we do want to have a safe RAID driver ... |
| 7271 | */ |
| 7272 | mdelay(1000*1); |
| 7273 | } |
| 7274 | return NOTIFY_DONE; |
| 7275 | } |
| 7276 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 7277 | static struct notifier_block md_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7278 | .notifier_call = md_notify_reboot, |
| 7279 | .next = NULL, |
| 7280 | .priority = INT_MAX, /* before any real devices */ |
| 7281 | }; |
| 7282 | |
| 7283 | static void md_geninit(void) |
| 7284 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7285 | dprintk("md: sizeof(mdp_super_t) = %d\n", (int)sizeof(mdp_super_t)); |
| 7286 | |
Denis V. Lunev | c7705f344 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 7287 | proc_create("mdstat", S_IRUGO, NULL, &md_seq_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7288 | } |
| 7289 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 7290 | static int __init md_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7291 | { |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7292 | if (register_blkdev(MD_MAJOR, "md")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7293 | return -1; |
| 7294 | if ((mdp_major=register_blkdev(0, "mdp"))<=0) { |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7295 | unregister_blkdev(MD_MAJOR, "md"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7296 | return -1; |
| 7297 | } |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7298 | blk_register_region(MKDEV(MD_MAJOR, 0), 1UL<<MINORBITS, THIS_MODULE, |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 7299 | md_probe, NULL, NULL); |
| 7300 | blk_register_region(MKDEV(mdp_major, 0), 1UL<<MINORBITS, THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7301 | md_probe, NULL, NULL); |
| 7302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7303 | register_reboot_notifier(&md_notifier); |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 7304 | raid_table_header = register_sysctl_table(raid_root_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7305 | |
| 7306 | md_geninit(); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 7307 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7308 | } |
| 7309 | |
| 7310 | |
| 7311 | #ifndef MODULE |
| 7312 | |
| 7313 | /* |
| 7314 | * Searches all registered partitions for autorun RAID arrays |
| 7315 | * at boot time. |
| 7316 | */ |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7317 | |
| 7318 | static LIST_HEAD(all_detected_devices); |
| 7319 | struct detected_devices_node { |
| 7320 | struct list_head list; |
| 7321 | dev_t dev; |
| 7322 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7323 | |
| 7324 | void md_autodetect_dev(dev_t dev) |
| 7325 | { |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7326 | struct detected_devices_node *node_detected_dev; |
| 7327 | |
| 7328 | node_detected_dev = kzalloc(sizeof(*node_detected_dev), GFP_KERNEL); |
| 7329 | if (node_detected_dev) { |
| 7330 | node_detected_dev->dev = dev; |
| 7331 | list_add_tail(&node_detected_dev->list, &all_detected_devices); |
| 7332 | } else { |
| 7333 | printk(KERN_CRIT "md: md_autodetect_dev: kzalloc failed" |
| 7334 | ", skipping dev(%d,%d)\n", MAJOR(dev), MINOR(dev)); |
| 7335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7336 | } |
| 7337 | |
| 7338 | |
| 7339 | static void autostart_arrays(int part) |
| 7340 | { |
| 7341 | mdk_rdev_t *rdev; |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7342 | struct detected_devices_node *node_detected_dev; |
| 7343 | dev_t dev; |
| 7344 | int i_scanned, i_passed; |
| 7345 | |
| 7346 | i_scanned = 0; |
| 7347 | i_passed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7348 | |
| 7349 | printk(KERN_INFO "md: Autodetecting RAID arrays.\n"); |
| 7350 | |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7351 | while (!list_empty(&all_detected_devices) && i_scanned < INT_MAX) { |
| 7352 | i_scanned++; |
| 7353 | node_detected_dev = list_entry(all_detected_devices.next, |
| 7354 | struct detected_devices_node, list); |
| 7355 | list_del(&node_detected_dev->list); |
| 7356 | dev = node_detected_dev->dev; |
| 7357 | kfree(node_detected_dev); |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 7358 | rdev = md_import_device(dev,0, 90); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7359 | if (IS_ERR(rdev)) |
| 7360 | continue; |
| 7361 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 7362 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7363 | MD_BUG(); |
| 7364 | continue; |
| 7365 | } |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 7366 | set_bit(AutoDetected, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7367 | list_add(&rdev->same_set, &pending_raid_disks); |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7368 | i_passed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7369 | } |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7370 | |
| 7371 | printk(KERN_INFO "md: Scanned %d and added %d devices.\n", |
| 7372 | i_scanned, i_passed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7373 | |
| 7374 | autorun_devices(part); |
| 7375 | } |
| 7376 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 7377 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7378 | |
| 7379 | static __exit void md_exit(void) |
| 7380 | { |
| 7381 | mddev_t *mddev; |
| 7382 | struct list_head *tmp; |
Greg Kroah-Hartman | 8ab5e4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 7383 | |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7384 | blk_unregister_region(MKDEV(MD_MAJOR,0), 1U << MINORBITS); |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 7385 | blk_unregister_region(MKDEV(mdp_major,0), 1U << MINORBITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7386 | |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7387 | unregister_blkdev(MD_MAJOR,"md"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7388 | unregister_blkdev(mdp_major, "mdp"); |
| 7389 | unregister_reboot_notifier(&md_notifier); |
| 7390 | unregister_sysctl_table(raid_table_header); |
| 7391 | remove_proc_entry("mdstat", NULL); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 7392 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7393 | export_array(mddev); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 7394 | mddev->hold_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7395 | } |
| 7396 | } |
| 7397 | |
Dan Williams | 685784a | 2007-07-09 11:56:42 -0700 | [diff] [blame] | 7398 | subsys_initcall(md_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7399 | module_exit(md_exit) |
| 7400 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7401 | static int get_ro(char *buffer, struct kernel_param *kp) |
| 7402 | { |
| 7403 | return sprintf(buffer, "%d", start_readonly); |
| 7404 | } |
| 7405 | static int set_ro(const char *val, struct kernel_param *kp) |
| 7406 | { |
| 7407 | char *e; |
| 7408 | int num = simple_strtoul(val, &e, 10); |
| 7409 | if (*val && (*e == '\0' || *e == '\n')) { |
| 7410 | start_readonly = num; |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 7411 | return 0; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7412 | } |
| 7413 | return -EINVAL; |
| 7414 | } |
| 7415 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 7416 | module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); |
| 7417 | module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR); |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 7418 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 7419 | module_param_call(new_array, add_named_array, NULL, NULL, S_IWUSR); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7421 | EXPORT_SYMBOL(register_md_personality); |
| 7422 | EXPORT_SYMBOL(unregister_md_personality); |
| 7423 | EXPORT_SYMBOL(md_error); |
| 7424 | EXPORT_SYMBOL(md_done_sync); |
| 7425 | EXPORT_SYMBOL(md_write_start); |
| 7426 | EXPORT_SYMBOL(md_write_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7427 | EXPORT_SYMBOL(md_register_thread); |
| 7428 | EXPORT_SYMBOL(md_unregister_thread); |
| 7429 | EXPORT_SYMBOL(md_wakeup_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7430 | EXPORT_SYMBOL(md_check_recovery); |
| 7431 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 7432 | MODULE_DESCRIPTION("MD RAID framework"); |
NeilBrown | aa1595e | 2005-08-04 12:53:32 -0700 | [diff] [blame] | 7433 | MODULE_ALIAS("md"); |
NeilBrown | 7200865 | 2005-08-26 18:34:15 -0700 | [diff] [blame] | 7434 | MODULE_ALIAS_BLOCKDEV_MAJOR(MD_MAJOR); |