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 | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 39 | #include <linux/mutex.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 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 60 | static DEFINE_MUTEX(md_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #ifndef MODULE |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 63 | static void autostart_arrays(int part); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #endif |
| 65 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 66 | static LIST_HEAD(pers_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static DEFINE_SPINLOCK(pers_lock); |
| 68 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 69 | static void md_print_devices(void); |
| 70 | |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 71 | static DECLARE_WAIT_QUEUE_HEAD(resync_wait); |
| 72 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 73 | #define MD_BUG(x...) { printk("md: bug in file %s, line %d\n", __FILE__, __LINE__); md_print_devices(); } |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | /* |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 76 | * Default number of read corrections we'll attempt on an rdev |
| 77 | * before ejecting it from the array. We divide the read error |
| 78 | * count by 2 for every hour elapsed between read errors. |
| 79 | */ |
| 80 | #define MD_DEFAULT_MAX_CORRECTED_READ_ERRORS 20 |
| 81 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * Current RAID-1,4,5 parallel reconstruction 'guaranteed speed limit' |
| 83 | * is 1000 KB/sec, so the extra system load does not show up that much. |
| 84 | * Increase it if you want to have more _guaranteed_ speed. Note that |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 85 | * the RAID driver will use the maximum available bandwidth if the IO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * subsystem is idle. There is also an 'absolute maximum' reconstruction |
| 87 | * speed limit - in case reconstruction slows down your system despite |
| 88 | * idle IO detection. |
| 89 | * |
| 90 | * you can change it via /proc/sys/dev/raid/speed_limit_min and _max. |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 91 | * or /sys/block/mdX/md/sync_speed_{min,max} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | */ |
| 93 | |
| 94 | static int sysctl_speed_limit_min = 1000; |
| 95 | static int sysctl_speed_limit_max = 200000; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 96 | static inline int speed_min(mddev_t *mddev) |
| 97 | { |
| 98 | return mddev->sync_speed_min ? |
| 99 | mddev->sync_speed_min : sysctl_speed_limit_min; |
| 100 | } |
| 101 | |
| 102 | static inline int speed_max(mddev_t *mddev) |
| 103 | { |
| 104 | return mddev->sync_speed_max ? |
| 105 | mddev->sync_speed_max : sysctl_speed_limit_max; |
| 106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | static struct ctl_table_header *raid_table_header; |
| 109 | |
| 110 | static ctl_table raid_table[] = { |
| 111 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | .procname = "speed_limit_min", |
| 113 | .data = &sysctl_speed_limit_min, |
| 114 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 115 | .mode = S_IRUGO|S_IWUSR, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 116 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | }, |
| 118 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | .procname = "speed_limit_max", |
| 120 | .data = &sysctl_speed_limit_max, |
| 121 | .maxlen = sizeof(int), |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 122 | .mode = S_IRUGO|S_IWUSR, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 123 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 125 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | static ctl_table raid_dir_table[] = { |
| 129 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | .procname = "raid", |
| 131 | .maxlen = 0, |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 132 | .mode = S_IRUGO|S_IXUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | .child = raid_table, |
| 134 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 135 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | static ctl_table raid_root_table[] = { |
| 139 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | .procname = "dev", |
| 141 | .maxlen = 0, |
| 142 | .mode = 0555, |
| 143 | .child = raid_dir_table, |
| 144 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 145 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 148 | static const struct block_device_operations md_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 150 | static int start_readonly; |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 153 | * We have a system wide 'event count' that is incremented |
| 154 | * on any 'interesting' event, and readers of /proc/mdstat |
| 155 | * can use 'poll' or 'select' to find out when the event |
| 156 | * count increases. |
| 157 | * |
| 158 | * Events are: |
| 159 | * start array, stop array, error, add device, remove device, |
| 160 | * start build, activate spare |
| 161 | */ |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 162 | static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 163 | static atomic_t md_event_count; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 164 | void md_new_event(mddev_t *mddev) |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 165 | { |
| 166 | atomic_inc(&md_event_count); |
| 167 | wake_up(&md_event_waiters); |
| 168 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 169 | EXPORT_SYMBOL_GPL(md_new_event); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 170 | |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 171 | /* Alternate version that can be called from interrupts |
| 172 | * when calling sysfs_notify isn't needed. |
| 173 | */ |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 174 | static void md_new_event_inintr(mddev_t *mddev) |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 175 | { |
| 176 | atomic_inc(&md_event_count); |
| 177 | wake_up(&md_event_waiters); |
| 178 | } |
| 179 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 180 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | * Enables to iterate over all existing md arrays |
| 182 | * all_mddevs_lock protects this list. |
| 183 | */ |
| 184 | static LIST_HEAD(all_mddevs); |
| 185 | static DEFINE_SPINLOCK(all_mddevs_lock); |
| 186 | |
| 187 | |
| 188 | /* |
| 189 | * iterates through all used mddevs in the system. |
| 190 | * We take care to grab the all_mddevs_lock whenever navigating |
| 191 | * the list, and to always hold a refcount when unlocked. |
| 192 | * Any code which breaks out of this loop while own |
| 193 | * a reference to the current mddev and must mddev_put it. |
| 194 | */ |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 195 | #define for_each_mddev(mddev,tmp) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | \ |
| 197 | for (({ spin_lock(&all_mddevs_lock); \ |
| 198 | tmp = all_mddevs.next; \ |
| 199 | mddev = NULL;}); \ |
| 200 | ({ if (tmp != &all_mddevs) \ |
| 201 | mddev_get(list_entry(tmp, mddev_t, all_mddevs));\ |
| 202 | spin_unlock(&all_mddevs_lock); \ |
| 203 | if (mddev) mddev_put(mddev); \ |
| 204 | mddev = list_entry(tmp, mddev_t, all_mddevs); \ |
| 205 | tmp != &all_mddevs;}); \ |
| 206 | ({ spin_lock(&all_mddevs_lock); \ |
| 207 | tmp = tmp->next;}) \ |
| 208 | ) |
| 209 | |
| 210 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 211 | /* Rather than calling directly into the personality make_request function, |
| 212 | * IO requests come here first so that we can check if the device is |
| 213 | * being suspended pending a reconfiguration. |
| 214 | * We hold a refcount over the call to ->make_request. By the time that |
| 215 | * call has finished, the bio has been linked into some internal structure |
| 216 | * and so is visible to ->quiesce(), so we don't need the refcount any more. |
| 217 | */ |
| 218 | static int md_make_request(struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 220 | const int rw = bio_data_dir(bio); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 221 | mddev_t *mddev = q->queuedata; |
| 222 | int rv; |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 223 | int cpu; |
| 224 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 225 | if (mddev == NULL || mddev->pers == NULL) { |
| 226 | bio_io_error(bio); |
| 227 | return 0; |
| 228 | } |
| 229 | rcu_read_lock(); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 230 | if (mddev->suspended) { |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 231 | DEFINE_WAIT(__wait); |
| 232 | for (;;) { |
| 233 | prepare_to_wait(&mddev->sb_wait, &__wait, |
| 234 | TASK_UNINTERRUPTIBLE); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 235 | if (!mddev->suspended) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 236 | break; |
| 237 | rcu_read_unlock(); |
| 238 | schedule(); |
| 239 | rcu_read_lock(); |
| 240 | } |
| 241 | finish_wait(&mddev->sb_wait, &__wait); |
| 242 | } |
| 243 | atomic_inc(&mddev->active_io); |
| 244 | rcu_read_unlock(); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 245 | |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 246 | rv = mddev->pers->make_request(mddev, bio); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 247 | |
| 248 | cpu = part_stat_lock(); |
| 249 | part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]); |
| 250 | part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw], |
| 251 | bio_sectors(bio)); |
| 252 | part_stat_unlock(); |
| 253 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 254 | if (atomic_dec_and_test(&mddev->active_io) && mddev->suspended) |
| 255 | wake_up(&mddev->sb_wait); |
| 256 | |
| 257 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
NeilBrown | 9e35b99 | 2010-04-06 14:23:02 +1000 | [diff] [blame] | 260 | /* mddev_suspend makes sure no new requests are submitted |
| 261 | * to the device, and that any requests that have been submitted |
| 262 | * are completely handled. |
| 263 | * Once ->stop is called and completes, the module will be completely |
| 264 | * unused. |
| 265 | */ |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 266 | void mddev_suspend(mddev_t *mddev) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 267 | { |
| 268 | BUG_ON(mddev->suspended); |
| 269 | mddev->suspended = 1; |
| 270 | synchronize_rcu(); |
| 271 | wait_event(mddev->sb_wait, atomic_read(&mddev->active_io) == 0); |
| 272 | mddev->pers->quiesce(mddev, 1); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 273 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 274 | EXPORT_SYMBOL_GPL(mddev_suspend); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 275 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 276 | void mddev_resume(mddev_t *mddev) |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 277 | { |
| 278 | mddev->suspended = 0; |
| 279 | wake_up(&mddev->sb_wait); |
| 280 | mddev->pers->quiesce(mddev, 0); |
| 281 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 282 | EXPORT_SYMBOL_GPL(mddev_resume); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 283 | |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 284 | int mddev_congested(mddev_t *mddev, int bits) |
| 285 | { |
| 286 | return mddev->suspended; |
| 287 | } |
| 288 | EXPORT_SYMBOL(mddev_congested); |
| 289 | |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 290 | /* |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 291 | * Generic flush handling for md |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 292 | */ |
| 293 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 294 | static void md_end_flush(struct bio *bio, int err) |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 295 | { |
| 296 | mdk_rdev_t *rdev = bio->bi_private; |
| 297 | mddev_t *mddev = rdev->mddev; |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 298 | |
| 299 | rdev_dec_pending(rdev, mddev); |
| 300 | |
| 301 | if (atomic_dec_and_test(&mddev->flush_pending)) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 302 | /* The pre-request flush has finished */ |
| 303 | schedule_work(&mddev->flush_work); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 304 | } |
| 305 | bio_put(bio); |
| 306 | } |
| 307 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 308 | static void submit_flushes(mddev_t *mddev) |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 309 | { |
| 310 | mdk_rdev_t *rdev; |
| 311 | |
| 312 | rcu_read_lock(); |
| 313 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
| 314 | if (rdev->raid_disk >= 0 && |
| 315 | !test_bit(Faulty, &rdev->flags)) { |
| 316 | /* Take two references, one is dropped |
| 317 | * when request finishes, one after |
| 318 | * we reclaim rcu_read_lock |
| 319 | */ |
| 320 | struct bio *bi; |
| 321 | atomic_inc(&rdev->nr_pending); |
| 322 | atomic_inc(&rdev->nr_pending); |
| 323 | rcu_read_unlock(); |
| 324 | bi = bio_alloc(GFP_KERNEL, 0); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 325 | bi->bi_end_io = md_end_flush; |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 326 | bi->bi_private = rdev; |
| 327 | bi->bi_bdev = rdev->bdev; |
| 328 | atomic_inc(&mddev->flush_pending); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 329 | submit_bio(WRITE_FLUSH, bi); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 330 | rcu_read_lock(); |
| 331 | rdev_dec_pending(rdev, mddev); |
| 332 | } |
| 333 | rcu_read_unlock(); |
| 334 | } |
| 335 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 336 | static void md_submit_flush_data(struct work_struct *ws) |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 337 | { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 338 | mddev_t *mddev = container_of(ws, mddev_t, flush_work); |
| 339 | struct bio *bio = mddev->flush_bio; |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 340 | |
| 341 | atomic_set(&mddev->flush_pending, 1); |
| 342 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 343 | if (bio->bi_size == 0) |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 344 | /* an empty barrier - all done */ |
| 345 | bio_endio(bio, 0); |
| 346 | else { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 347 | bio->bi_rw &= ~REQ_FLUSH; |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 348 | if (mddev->pers->make_request(mddev, bio)) |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 349 | generic_make_request(bio); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 350 | } |
| 351 | if (atomic_dec_and_test(&mddev->flush_pending)) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 352 | mddev->flush_bio = NULL; |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 353 | wake_up(&mddev->sb_wait); |
| 354 | } |
| 355 | } |
| 356 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 357 | void md_flush_request(mddev_t *mddev, struct bio *bio) |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 358 | { |
| 359 | spin_lock_irq(&mddev->write_lock); |
| 360 | wait_event_lock_irq(mddev->sb_wait, |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 361 | !mddev->flush_bio, |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 362 | mddev->write_lock, /*nothing*/); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 363 | mddev->flush_bio = bio; |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 364 | spin_unlock_irq(&mddev->write_lock); |
| 365 | |
| 366 | atomic_set(&mddev->flush_pending, 1); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 367 | INIT_WORK(&mddev->flush_work, md_submit_flush_data); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 368 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 369 | submit_flushes(mddev); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 370 | |
| 371 | if (atomic_dec_and_test(&mddev->flush_pending)) |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 372 | schedule_work(&mddev->flush_work); |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 373 | } |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 374 | EXPORT_SYMBOL(md_flush_request); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 375 | |
NeilBrown | 2ac8740 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 376 | /* Support for plugging. |
| 377 | * This mirrors the plugging support in request_queue, but does not |
| 378 | * require having a whole queue |
| 379 | */ |
| 380 | static void plugger_work(struct work_struct *work) |
| 381 | { |
| 382 | struct plug_handle *plug = |
| 383 | container_of(work, struct plug_handle, unplug_work); |
| 384 | plug->unplug_fn(plug); |
| 385 | } |
| 386 | static void plugger_timeout(unsigned long data) |
| 387 | { |
| 388 | struct plug_handle *plug = (void *)data; |
| 389 | kblockd_schedule_work(NULL, &plug->unplug_work); |
| 390 | } |
| 391 | void plugger_init(struct plug_handle *plug, |
| 392 | void (*unplug_fn)(struct plug_handle *)) |
| 393 | { |
| 394 | plug->unplug_flag = 0; |
| 395 | plug->unplug_fn = unplug_fn; |
| 396 | init_timer(&plug->unplug_timer); |
| 397 | plug->unplug_timer.function = plugger_timeout; |
| 398 | plug->unplug_timer.data = (unsigned long)plug; |
| 399 | INIT_WORK(&plug->unplug_work, plugger_work); |
| 400 | } |
| 401 | EXPORT_SYMBOL_GPL(plugger_init); |
| 402 | |
| 403 | void plugger_set_plug(struct plug_handle *plug) |
| 404 | { |
| 405 | if (!test_and_set_bit(PLUGGED_FLAG, &plug->unplug_flag)) |
| 406 | mod_timer(&plug->unplug_timer, jiffies + msecs_to_jiffies(3)+1); |
| 407 | } |
| 408 | EXPORT_SYMBOL_GPL(plugger_set_plug); |
| 409 | |
| 410 | int plugger_remove_plug(struct plug_handle *plug) |
| 411 | { |
| 412 | if (test_and_clear_bit(PLUGGED_FLAG, &plug->unplug_flag)) { |
| 413 | del_timer(&plug->unplug_timer); |
| 414 | return 1; |
| 415 | } else |
| 416 | return 0; |
| 417 | } |
| 418 | EXPORT_SYMBOL_GPL(plugger_remove_plug); |
| 419 | |
| 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | static inline mddev_t *mddev_get(mddev_t *mddev) |
| 422 | { |
| 423 | atomic_inc(&mddev->active); |
| 424 | return mddev; |
| 425 | } |
| 426 | |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 427 | static void mddev_delayed_delete(struct work_struct *ws); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | static void mddev_put(mddev_t *mddev) |
| 430 | { |
| 431 | if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock)) |
| 432 | return; |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 433 | if (!mddev->raid_disks && list_empty(&mddev->disks) && |
NeilBrown | cbd1998 | 2009-12-30 12:08:49 +1100 | [diff] [blame] | 434 | mddev->ctime == 0 && !mddev->hold_active) { |
| 435 | /* Array is not configured at all, and not held active, |
| 436 | * so destroy it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | list_del(&mddev->all_mddevs); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 438 | if (mddev->gendisk) { |
| 439 | /* we did a probe so need to clean up. |
| 440 | * Call schedule_work inside the spinlock |
| 441 | * so that flush_scheduled_work() after |
| 442 | * mddev_find will succeed in waiting for the |
| 443 | * work to be done. |
| 444 | */ |
| 445 | INIT_WORK(&mddev->del_work, mddev_delayed_delete); |
| 446 | schedule_work(&mddev->del_work); |
| 447 | } else |
| 448 | kfree(mddev); |
| 449 | } |
| 450 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 453 | void mddev_init(mddev_t *mddev) |
NeilBrown | fafd7fb | 2010-04-01 15:55:30 +1100 | [diff] [blame] | 454 | { |
| 455 | mutex_init(&mddev->open_mutex); |
| 456 | mutex_init(&mddev->reconfig_mutex); |
| 457 | mutex_init(&mddev->bitmap_info.mutex); |
| 458 | INIT_LIST_HEAD(&mddev->disks); |
| 459 | INIT_LIST_HEAD(&mddev->all_mddevs); |
| 460 | init_timer(&mddev->safemode_timer); |
| 461 | atomic_set(&mddev->active, 1); |
| 462 | atomic_set(&mddev->openers, 0); |
| 463 | atomic_set(&mddev->active_io, 0); |
| 464 | spin_lock_init(&mddev->write_lock); |
| 465 | atomic_set(&mddev->flush_pending, 0); |
| 466 | init_waitqueue_head(&mddev->sb_wait); |
| 467 | init_waitqueue_head(&mddev->recovery_wait); |
| 468 | mddev->reshape_position = MaxSector; |
| 469 | mddev->resync_min = 0; |
| 470 | mddev->resync_max = MaxSector; |
| 471 | mddev->level = LEVEL_NONE; |
| 472 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 473 | EXPORT_SYMBOL_GPL(mddev_init); |
NeilBrown | fafd7fb | 2010-04-01 15:55:30 +1100 | [diff] [blame] | 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | static mddev_t * mddev_find(dev_t unit) |
| 476 | { |
| 477 | mddev_t *mddev, *new = NULL; |
| 478 | |
| 479 | retry: |
| 480 | spin_lock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 482 | if (unit) { |
| 483 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 484 | if (mddev->unit == unit) { |
| 485 | mddev_get(mddev); |
| 486 | spin_unlock(&all_mddevs_lock); |
| 487 | kfree(new); |
| 488 | return mddev; |
| 489 | } |
| 490 | |
| 491 | if (new) { |
| 492 | list_add(&new->all_mddevs, &all_mddevs); |
| 493 | spin_unlock(&all_mddevs_lock); |
| 494 | new->hold_active = UNTIL_IOCTL; |
| 495 | return new; |
| 496 | } |
| 497 | } else if (new) { |
| 498 | /* find an unused unit number */ |
| 499 | static int next_minor = 512; |
| 500 | int start = next_minor; |
| 501 | int is_free = 0; |
| 502 | int dev = 0; |
| 503 | while (!is_free) { |
| 504 | dev = MKDEV(MD_MAJOR, next_minor); |
| 505 | next_minor++; |
| 506 | if (next_minor > MINORMASK) |
| 507 | next_minor = 0; |
| 508 | if (next_minor == start) { |
| 509 | /* Oh dear, all in use. */ |
| 510 | spin_unlock(&all_mddevs_lock); |
| 511 | kfree(new); |
| 512 | return NULL; |
| 513 | } |
| 514 | |
| 515 | is_free = 1; |
| 516 | list_for_each_entry(mddev, &all_mddevs, all_mddevs) |
| 517 | if (mddev->unit == dev) { |
| 518 | is_free = 0; |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | new->unit = dev; |
| 523 | new->md_minor = MINOR(dev); |
| 524 | new->hold_active = UNTIL_STOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | list_add(&new->all_mddevs, &all_mddevs); |
| 526 | spin_unlock(&all_mddevs_lock); |
| 527 | return new; |
| 528 | } |
| 529 | spin_unlock(&all_mddevs_lock); |
| 530 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 531 | new = kzalloc(sizeof(*new), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | if (!new) |
| 533 | return NULL; |
| 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | new->unit = unit; |
| 536 | if (MAJOR(unit) == MD_MAJOR) |
| 537 | new->md_minor = MINOR(unit); |
| 538 | else |
| 539 | new->md_minor = MINOR(unit) >> MdpMinorShift; |
| 540 | |
NeilBrown | fafd7fb | 2010-04-01 15:55:30 +1100 | [diff] [blame] | 541 | mddev_init(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | goto retry; |
| 544 | } |
| 545 | |
| 546 | static inline int mddev_lock(mddev_t * mddev) |
| 547 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 548 | return mutex_lock_interruptible(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 551 | static inline int mddev_is_locked(mddev_t *mddev) |
| 552 | { |
| 553 | return mutex_is_locked(&mddev->reconfig_mutex); |
| 554 | } |
| 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | static inline int mddev_trylock(mddev_t * mddev) |
| 557 | { |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 558 | return mutex_trylock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
| 560 | |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 561 | static struct attribute_group md_redundancy_group; |
| 562 | |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 563 | static void mddev_unlock(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 565 | if (mddev->to_remove) { |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 566 | /* These cannot be removed under reconfig_mutex as |
| 567 | * an access to the files will try to take reconfig_mutex |
| 568 | * while holding the file unremovable, which leads to |
| 569 | * a deadlock. |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 570 | * So hold set sysfs_active while the remove in happeing, |
| 571 | * and anything else which might set ->to_remove or my |
| 572 | * otherwise change the sysfs namespace will fail with |
| 573 | * -EBUSY if sysfs_active is still set. |
| 574 | * We set sysfs_active under reconfig_mutex and elsewhere |
| 575 | * test it under the same mutex to ensure its correct value |
| 576 | * is seen. |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 577 | */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 578 | struct attribute_group *to_remove = mddev->to_remove; |
| 579 | mddev->to_remove = NULL; |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 580 | mddev->sysfs_active = 1; |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 581 | mutex_unlock(&mddev->reconfig_mutex); |
| 582 | |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 583 | if (mddev->kobj.sd) { |
| 584 | if (to_remove != &md_redundancy_group) |
| 585 | sysfs_remove_group(&mddev->kobj, to_remove); |
| 586 | if (mddev->pers == NULL || |
| 587 | mddev->pers->sync_request == NULL) { |
| 588 | sysfs_remove_group(&mddev->kobj, &md_redundancy_group); |
| 589 | if (mddev->sysfs_action) |
| 590 | sysfs_put(mddev->sysfs_action); |
| 591 | mddev->sysfs_action = NULL; |
| 592 | } |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 593 | } |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 594 | mddev->sysfs_active = 0; |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 595 | } else |
| 596 | mutex_unlock(&mddev->reconfig_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 598 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
NeilBrown | 2989ddb | 2006-01-06 00:20:43 -0800 | [diff] [blame] | 601 | static mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 603 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 605 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | if (rdev->desc_nr == nr) |
| 607 | return rdev; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | return NULL; |
| 610 | } |
| 611 | |
| 612 | static mdk_rdev_t * find_rdev(mddev_t * mddev, dev_t dev) |
| 613 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | mdk_rdev_t *rdev; |
| 615 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 616 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | if (rdev->bdev->bd_dev == dev) |
| 618 | return rdev; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | return NULL; |
| 621 | } |
| 622 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 623 | static struct mdk_personality *find_pers(int level, char *clevel) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 624 | { |
| 625 | struct mdk_personality *pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 626 | list_for_each_entry(pers, &pers_list, list) { |
| 627 | if (level != LEVEL_NONE && pers->level == level) |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 628 | return pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 629 | if (strcmp(pers->name, clevel)==0) |
| 630 | return pers; |
| 631 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 632 | return NULL; |
| 633 | } |
| 634 | |
Andre Noll | b73df2d | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 635 | /* return the offset of the super block in 512byte sectors */ |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 636 | static inline sector_t calc_dev_sboffset(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | { |
Andre Noll | b73df2d | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 638 | sector_t num_sectors = bdev->bd_inode->i_size / 512; |
| 639 | return MD_NEW_SIZE_SECTORS(num_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | static int alloc_disk_sb(mdk_rdev_t * rdev) |
| 643 | { |
| 644 | if (rdev->sb_page) |
| 645 | MD_BUG(); |
| 646 | |
| 647 | rdev->sb_page = alloc_page(GFP_KERNEL); |
| 648 | if (!rdev->sb_page) { |
| 649 | printk(KERN_ALERT "md: out of memory.\n"); |
Andre Noll | ebc2433 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 650 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | static void free_disk_sb(mdk_rdev_t * rdev) |
| 657 | { |
| 658 | if (rdev->sb_page) { |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 659 | put_page(rdev->sb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | rdev->sb_loaded = 0; |
| 661 | rdev->sb_page = NULL; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 662 | rdev->sb_start = 0; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 663 | rdev->sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
| 667 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 668 | static void super_written(struct bio *bio, int error) |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 669 | { |
| 670 | mdk_rdev_t *rdev = bio->bi_private; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 671 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 672 | |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 673 | if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) { |
| 674 | printk("md: super_written gets error=%d, uptodate=%d\n", |
| 675 | error, test_bit(BIO_UPTODATE, &bio->bi_flags)); |
| 676 | WARN_ON(test_bit(BIO_UPTODATE, &bio->bi_flags)); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 677 | md_error(mddev, rdev); |
NeilBrown | 3a0f5bb | 2006-10-03 01:16:03 -0700 | [diff] [blame] | 678 | } |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 679 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 680 | if (atomic_dec_and_test(&mddev->pending_writes)) |
| 681 | wake_up(&mddev->sb_wait); |
Neil Brown | f8b58ed | 2005-06-27 22:29:34 -0700 | [diff] [blame] | 682 | bio_put(bio); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev, |
| 686 | sector_t sector, int size, struct page *page) |
| 687 | { |
| 688 | /* write first size bytes of page to sector of rdev |
| 689 | * Increment mddev->pending_writes before returning |
| 690 | * and decrement it on completion, waking up sb_wait |
| 691 | * if zero is reached. |
| 692 | * If an error occurred, call md_error |
| 693 | */ |
| 694 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
| 695 | |
| 696 | bio->bi_bdev = rdev->bdev; |
| 697 | bio->bi_sector = sector; |
| 698 | bio_add_page(bio, page, size, 0); |
| 699 | bio->bi_private = rdev; |
| 700 | bio->bi_end_io = super_written; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 701 | |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 702 | atomic_inc(&mddev->pending_writes); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 703 | submit_bio(REQ_WRITE | REQ_SYNC | REQ_UNPLUG | REQ_FLUSH | REQ_FUA, |
| 704 | bio); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | void md_super_wait(mddev_t *mddev) |
| 708 | { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 709 | /* wait for all superblock writes that were scheduled to complete */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 710 | DEFINE_WAIT(wq); |
| 711 | for(;;) { |
| 712 | prepare_to_wait(&mddev->sb_wait, &wq, TASK_UNINTERRUPTIBLE); |
| 713 | if (atomic_read(&mddev->pending_writes)==0) |
| 714 | break; |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 715 | schedule(); |
| 716 | } |
| 717 | finish_wait(&mddev->sb_wait, &wq); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 718 | } |
| 719 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 720 | static void bi_complete(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | complete((struct completion*)bio->bi_private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 725 | 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] | 726 | struct page *page, int rw) |
| 727 | { |
Neil Brown | baaa2c5 | 2005-04-16 15:23:54 -0700 | [diff] [blame] | 728 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | struct completion event; |
| 730 | int ret; |
| 731 | |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 732 | rw |= REQ_SYNC | REQ_UNPLUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | bio->bi_bdev = bdev; |
| 735 | bio->bi_sector = sector; |
| 736 | bio_add_page(bio, page, size, 0); |
| 737 | init_completion(&event); |
| 738 | bio->bi_private = &event; |
| 739 | bio->bi_end_io = bi_complete; |
| 740 | submit_bio(rw, bio); |
| 741 | wait_for_completion(&event); |
| 742 | |
| 743 | ret = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 744 | bio_put(bio); |
| 745 | return ret; |
| 746 | } |
NeilBrown | a8745db | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 747 | EXPORT_SYMBOL_GPL(sync_page_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 749 | static int read_disk_sb(mdk_rdev_t * rdev, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | { |
| 751 | char b[BDEVNAME_SIZE]; |
| 752 | if (!rdev->sb_page) { |
| 753 | MD_BUG(); |
| 754 | return -EINVAL; |
| 755 | } |
| 756 | if (rdev->sb_loaded) |
| 757 | return 0; |
| 758 | |
| 759 | |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 760 | 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] | 761 | goto fail; |
| 762 | rdev->sb_loaded = 1; |
| 763 | return 0; |
| 764 | |
| 765 | fail: |
| 766 | printk(KERN_WARNING "md: disabled device %s, could not read superblock.\n", |
| 767 | bdevname(rdev->bdev,b)); |
| 768 | return -EINVAL; |
| 769 | } |
| 770 | |
| 771 | static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 772 | { |
Andre Noll | 0571046 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 773 | return sb1->set_uuid0 == sb2->set_uuid0 && |
| 774 | sb1->set_uuid1 == sb2->set_uuid1 && |
| 775 | sb1->set_uuid2 == sb2->set_uuid2 && |
| 776 | sb1->set_uuid3 == sb2->set_uuid3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2) |
| 780 | { |
| 781 | int ret; |
| 782 | mdp_super_t *tmp1, *tmp2; |
| 783 | |
| 784 | tmp1 = kmalloc(sizeof(*tmp1),GFP_KERNEL); |
| 785 | tmp2 = kmalloc(sizeof(*tmp2),GFP_KERNEL); |
| 786 | |
| 787 | if (!tmp1 || !tmp2) { |
| 788 | ret = 0; |
Andre Noll | 35020f1 | 2008-03-23 15:10:33 +0100 | [diff] [blame] | 789 | printk(KERN_INFO "md.c sb_equal(): failed to allocate memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | goto abort; |
| 791 | } |
| 792 | |
| 793 | *tmp1 = *sb1; |
| 794 | *tmp2 = *sb2; |
| 795 | |
| 796 | /* |
| 797 | * nr_disks is not constant |
| 798 | */ |
| 799 | tmp1->nr_disks = 0; |
| 800 | tmp2->nr_disks = 0; |
| 801 | |
Andre Noll | ce0c8e0 | 2008-07-11 22:02:20 +1000 | [diff] [blame] | 802 | ret = (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | abort: |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 804 | kfree(tmp1); |
| 805 | kfree(tmp2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | return ret; |
| 807 | } |
| 808 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 809 | |
| 810 | static u32 md_csum_fold(u32 csum) |
| 811 | { |
| 812 | csum = (csum & 0xffff) + (csum >> 16); |
| 813 | return (csum & 0xffff) + (csum >> 16); |
| 814 | } |
| 815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | static unsigned int calc_sb_csum(mdp_super_t * sb) |
| 817 | { |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 818 | u64 newcsum = 0; |
| 819 | u32 *sb32 = (u32*)sb; |
| 820 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | unsigned int disk_csum, csum; |
| 822 | |
| 823 | disk_csum = sb->sb_csum; |
| 824 | sb->sb_csum = 0; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 825 | |
| 826 | for (i = 0; i < MD_SB_BYTES/4 ; i++) |
| 827 | newcsum += sb32[i]; |
| 828 | csum = (newcsum & 0xffffffff) + (newcsum>>32); |
| 829 | |
| 830 | |
| 831 | #ifdef CONFIG_ALPHA |
| 832 | /* This used to use csum_partial, which was wrong for several |
| 833 | * reasons including that different results are returned on |
| 834 | * different architectures. It isn't critical that we get exactly |
| 835 | * the same return value as before (we always csum_fold before |
| 836 | * testing, and that removes any differences). However as we |
| 837 | * know that csum_partial always returned a 16bit value on |
| 838 | * alphas, do a fold to maximise conformity to previous behaviour. |
| 839 | */ |
| 840 | sb->sb_csum = md_csum_fold(disk_csum); |
| 841 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | sb->sb_csum = disk_csum; |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 843 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | return csum; |
| 845 | } |
| 846 | |
| 847 | |
| 848 | /* |
| 849 | * Handle superblock details. |
| 850 | * We want to be able to handle multiple superblock formats |
| 851 | * so we have a common interface to them all, and an array of |
| 852 | * different handlers. |
| 853 | * We rely on user-space to write the initial superblock, and support |
| 854 | * reading and updating of superblocks. |
| 855 | * Interface methods are: |
| 856 | * int load_super(mdk_rdev_t *dev, mdk_rdev_t *refdev, int minor_version) |
| 857 | * loads and validates a superblock on dev. |
| 858 | * if refdev != NULL, compare superblocks on both devices |
| 859 | * Return: |
| 860 | * 0 - dev has a superblock that is compatible with refdev |
| 861 | * 1 - dev has a superblock that is compatible and newer than refdev |
| 862 | * so dev should be used as the refdev in future |
| 863 | * -EINVAL superblock incompatible or invalid |
| 864 | * -othererror e.g. -EIO |
| 865 | * |
| 866 | * int validate_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 867 | * Verify that dev is acceptable into mddev. |
| 868 | * The first time, mddev->raid_disks will be 0, and data from |
| 869 | * dev should be merged in. Subsequent calls check that dev |
| 870 | * is new enough. Return 0 or -EINVAL |
| 871 | * |
| 872 | * void sync_super(mddev_t *mddev, mdk_rdev_t *dev) |
| 873 | * Update the superblock for rdev with data in mddev |
| 874 | * This does not write to disc. |
| 875 | * |
| 876 | */ |
| 877 | |
| 878 | struct super_type { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 879 | char *name; |
| 880 | struct module *owner; |
| 881 | int (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev, |
| 882 | int minor_version); |
| 883 | int (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 884 | void (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 885 | unsigned long long (*rdev_size_change)(mdk_rdev_t *rdev, |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 886 | sector_t num_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | }; |
| 888 | |
| 889 | /* |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 890 | * Check that the given mddev has no bitmap. |
| 891 | * |
| 892 | * This function is called from the run method of all personalities that do not |
| 893 | * support bitmaps. It prints an error message and returns non-zero if mddev |
| 894 | * has a bitmap. Otherwise, it returns 0. |
| 895 | * |
| 896 | */ |
| 897 | int md_check_no_bitmap(mddev_t *mddev) |
| 898 | { |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 899 | if (!mddev->bitmap_info.file && !mddev->bitmap_info.offset) |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 900 | return 0; |
| 901 | printk(KERN_ERR "%s: bitmaps are not supported for %s\n", |
| 902 | mdname(mddev), mddev->pers->name); |
| 903 | return 1; |
| 904 | } |
| 905 | EXPORT_SYMBOL(md_check_no_bitmap); |
| 906 | |
| 907 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | * load_super for 0.90.0 |
| 909 | */ |
| 910 | static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 911 | { |
| 912 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 913 | mdp_super_t *sb; |
| 914 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | /* |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 917 | * Calculate the position of the superblock (512byte sectors), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | * it's at the end of the disk. |
| 919 | * |
| 920 | * It also happens to be a multiple of 4Kb. |
| 921 | */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 922 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 924 | ret = read_disk_sb(rdev, MD_SB_BYTES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | if (ret) return ret; |
| 926 | |
| 927 | ret = -EINVAL; |
| 928 | |
| 929 | bdevname(rdev->bdev, b); |
| 930 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 931 | |
| 932 | if (sb->md_magic != MD_SB_MAGIC) { |
| 933 | printk(KERN_ERR "md: invalid raid superblock magic on %s\n", |
| 934 | b); |
| 935 | goto abort; |
| 936 | } |
| 937 | |
| 938 | if (sb->major_version != 0 || |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 939 | sb->minor_version < 90 || |
| 940 | sb->minor_version > 91) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | printk(KERN_WARNING "Bad version number %d.%d on %s\n", |
| 942 | sb->major_version, sb->minor_version, |
| 943 | b); |
| 944 | goto abort; |
| 945 | } |
| 946 | |
| 947 | if (sb->raid_disks <= 0) |
| 948 | goto abort; |
| 949 | |
NeilBrown | 4d167f0 | 2007-05-09 02:35:37 -0700 | [diff] [blame] | 950 | 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] | 951 | printk(KERN_WARNING "md: invalid superblock checksum on %s\n", |
| 952 | b); |
| 953 | goto abort; |
| 954 | } |
| 955 | |
| 956 | rdev->preferred_minor = sb->md_minor; |
| 957 | rdev->data_offset = 0; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 958 | rdev->sb_size = MD_SB_BYTES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
| 960 | if (sb->level == LEVEL_MULTIPATH) |
| 961 | rdev->desc_nr = -1; |
| 962 | else |
| 963 | rdev->desc_nr = sb->this_disk.number; |
| 964 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 965 | if (!refdev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 967 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | __u64 ev1, ev2; |
| 969 | mdp_super_t *refsb = (mdp_super_t*)page_address(refdev->sb_page); |
| 970 | if (!uuid_equal(refsb, sb)) { |
| 971 | printk(KERN_WARNING "md: %s has different UUID to %s\n", |
| 972 | b, bdevname(refdev->bdev,b2)); |
| 973 | goto abort; |
| 974 | } |
| 975 | if (!sb_equal(refsb, sb)) { |
| 976 | printk(KERN_WARNING "md: %s has same UUID" |
| 977 | " but different superblock to %s\n", |
| 978 | b, bdevname(refdev->bdev, b2)); |
| 979 | goto abort; |
| 980 | } |
| 981 | ev1 = md_event(sb); |
| 982 | ev2 = md_event(refsb); |
| 983 | if (ev1 > ev2) |
| 984 | ret = 1; |
| 985 | else |
| 986 | ret = 0; |
| 987 | } |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 988 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 990 | if (rdev->sectors < sb->size * 2 && sb->level > 1) |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 991 | /* "this cannot possibly happen" ... */ |
| 992 | ret = -EINVAL; |
| 993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | abort: |
| 995 | return ret; |
| 996 | } |
| 997 | |
| 998 | /* |
| 999 | * validate_super for 0.90.0 |
| 1000 | */ |
| 1001 | static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1002 | { |
| 1003 | mdp_disk_t *desc; |
| 1004 | mdp_super_t *sb = (mdp_super_t *)page_address(rdev->sb_page); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1005 | __u64 ev1 = md_event(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1007 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1008 | clear_bit(Faulty, &rdev->flags); |
| 1009 | clear_bit(In_sync, &rdev->flags); |
| 1010 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | if (mddev->raid_disks == 0) { |
| 1013 | mddev->major_version = 0; |
| 1014 | mddev->minor_version = sb->minor_version; |
| 1015 | mddev->patch_version = sb->patch_version; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1016 | mddev->external = 0; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1017 | mddev->chunk_sectors = sb->chunk_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | mddev->ctime = sb->ctime; |
| 1019 | mddev->utime = sb->utime; |
| 1020 | mddev->level = sb->level; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 1021 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | mddev->layout = sb->layout; |
| 1023 | mddev->raid_disks = sb->raid_disks; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1024 | mddev->dev_sectors = sb->size * 2; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1025 | mddev->events = ev1; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1026 | mddev->bitmap_info.offset = 0; |
| 1027 | mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1029 | if (mddev->minor_version >= 91) { |
| 1030 | mddev->reshape_position = sb->reshape_position; |
| 1031 | mddev->delta_disks = sb->delta_disks; |
| 1032 | mddev->new_level = sb->new_level; |
| 1033 | mddev->new_layout = sb->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1034 | mddev->new_chunk_sectors = sb->new_chunk >> 9; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1035 | } else { |
| 1036 | mddev->reshape_position = MaxSector; |
| 1037 | mddev->delta_disks = 0; |
| 1038 | mddev->new_level = mddev->level; |
| 1039 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1040 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | if (sb->state & (1<<MD_SB_CLEAN)) |
| 1044 | mddev->recovery_cp = MaxSector; |
| 1045 | else { |
| 1046 | if (sb->events_hi == sb->cp_events_hi && |
| 1047 | sb->events_lo == sb->cp_events_lo) { |
| 1048 | mddev->recovery_cp = sb->recovery_cp; |
| 1049 | } else |
| 1050 | mddev->recovery_cp = 0; |
| 1051 | } |
| 1052 | |
| 1053 | memcpy(mddev->uuid+0, &sb->set_uuid0, 4); |
| 1054 | memcpy(mddev->uuid+4, &sb->set_uuid1, 4); |
| 1055 | memcpy(mddev->uuid+8, &sb->set_uuid2, 4); |
| 1056 | memcpy(mddev->uuid+12,&sb->set_uuid3, 4); |
| 1057 | |
| 1058 | mddev->max_disks = MD_SB_DISKS; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1059 | |
| 1060 | if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1061 | mddev->bitmap_info.file == NULL) |
| 1062 | mddev->bitmap_info.offset = |
| 1063 | mddev->bitmap_info.default_offset; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1064 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1065 | } else if (mddev->pers == NULL) { |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1066 | /* Insist on good event counter while assembling, except |
| 1067 | * for spares (which don't need an event count) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | ++ev1; |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1069 | if (sb->disks[rdev->desc_nr].state & ( |
| 1070 | (1<<MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE))) |
| 1071 | if (ev1 < mddev->events) |
| 1072 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1073 | } else if (mddev->bitmap) { |
| 1074 | /* if adding to array with a bitmap, then we can accept an |
| 1075 | * older device ... but not too old. |
| 1076 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1077 | if (ev1 < mddev->bitmap->events_cleared) |
| 1078 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1079 | } else { |
| 1080 | if (ev1 < mddev->events) |
| 1081 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1082 | return 0; |
| 1083 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | if (mddev->level != LEVEL_MULTIPATH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | desc = sb->disks + rdev->desc_nr; |
| 1087 | |
| 1088 | if (desc->state & (1<<MD_DISK_FAULTY)) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1089 | set_bit(Faulty, &rdev->flags); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 1090 | else if (desc->state & (1<<MD_DISK_SYNC) /* && |
| 1091 | desc->raid_disk < mddev->raid_disks */) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1092 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | rdev->raid_disk = desc->raid_disk; |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1094 | } else if (desc->state & (1<<MD_DISK_ACTIVE)) { |
| 1095 | /* active but not in sync implies recovery up to |
| 1096 | * reshape position. We don't know exactly where |
| 1097 | * that is, so set to zero for now */ |
| 1098 | if (mddev->minor_version >= 91) { |
| 1099 | rdev->recovery_offset = 0; |
| 1100 | rdev->raid_disk = desc->raid_disk; |
| 1101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1103 | if (desc->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 1104 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1105 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1106 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | /* |
| 1111 | * sync_super for 0.90.0 |
| 1112 | */ |
| 1113 | static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1114 | { |
| 1115 | mdp_super_t *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | mdk_rdev_t *rdev2; |
| 1117 | int next_spare = mddev->raid_disks; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
| 1120 | /* make rdev->sb match mddev data.. |
| 1121 | * |
| 1122 | * 1/ zero out disks |
| 1123 | * 2/ Add info for each disk, keeping track of highest desc_nr (next_spare); |
| 1124 | * 3/ any empty disks < next_spare become removed |
| 1125 | * |
| 1126 | * disks[0] gets initialised to REMOVED because |
| 1127 | * we cannot be sure from other fields if it has |
| 1128 | * been initialised or not. |
| 1129 | */ |
| 1130 | int i; |
| 1131 | int active=0, working=0,failed=0,spare=0,nr_disks=0; |
| 1132 | |
NeilBrown | 6118156 | 2005-09-09 16:24:02 -0700 | [diff] [blame] | 1133 | rdev->sb_size = MD_SB_BYTES; |
| 1134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | sb = (mdp_super_t*)page_address(rdev->sb_page); |
| 1136 | |
| 1137 | memset(sb, 0, sizeof(*sb)); |
| 1138 | |
| 1139 | sb->md_magic = MD_SB_MAGIC; |
| 1140 | sb->major_version = mddev->major_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | sb->patch_version = mddev->patch_version; |
| 1142 | sb->gvalid_words = 0; /* ignored */ |
| 1143 | memcpy(&sb->set_uuid0, mddev->uuid+0, 4); |
| 1144 | memcpy(&sb->set_uuid1, mddev->uuid+4, 4); |
| 1145 | memcpy(&sb->set_uuid2, mddev->uuid+8, 4); |
| 1146 | memcpy(&sb->set_uuid3, mddev->uuid+12,4); |
| 1147 | |
| 1148 | sb->ctime = mddev->ctime; |
| 1149 | sb->level = mddev->level; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1150 | sb->size = mddev->dev_sectors / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | sb->raid_disks = mddev->raid_disks; |
| 1152 | sb->md_minor = mddev->md_minor; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1153 | sb->not_persistent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | sb->utime = mddev->utime; |
| 1155 | sb->state = 0; |
| 1156 | sb->events_hi = (mddev->events>>32); |
| 1157 | sb->events_lo = (u32)mddev->events; |
| 1158 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1159 | if (mddev->reshape_position == MaxSector) |
| 1160 | sb->minor_version = 90; |
| 1161 | else { |
| 1162 | sb->minor_version = 91; |
| 1163 | sb->reshape_position = mddev->reshape_position; |
| 1164 | sb->new_level = mddev->new_level; |
| 1165 | sb->delta_disks = mddev->delta_disks; |
| 1166 | sb->new_layout = mddev->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1167 | sb->new_chunk = mddev->new_chunk_sectors << 9; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1168 | } |
| 1169 | mddev->minor_version = sb->minor_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | if (mddev->in_sync) |
| 1171 | { |
| 1172 | sb->recovery_cp = mddev->recovery_cp; |
| 1173 | sb->cp_events_hi = (mddev->events>>32); |
| 1174 | sb->cp_events_lo = (u32)mddev->events; |
| 1175 | if (mddev->recovery_cp == MaxSector) |
| 1176 | sb->state = (1<< MD_SB_CLEAN); |
| 1177 | } else |
| 1178 | sb->recovery_cp = 0; |
| 1179 | |
| 1180 | sb->layout = mddev->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1181 | sb->chunk_size = mddev->chunk_sectors << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1183 | if (mddev->bitmap && mddev->bitmap_info.file == NULL) |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1184 | sb->state |= (1<<MD_SB_BITMAP_PRESENT); |
| 1185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | sb->disks[0].state = (1<<MD_DISK_REMOVED); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1187 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | mdp_disk_t *d; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1189 | int desc_nr; |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1190 | int is_active = test_bit(In_sync, &rdev2->flags); |
| 1191 | |
| 1192 | if (rdev2->raid_disk >= 0 && |
| 1193 | sb->minor_version >= 91) |
| 1194 | /* we have nowhere to store the recovery_offset, |
| 1195 | * but if it is not below the reshape_position, |
| 1196 | * we can piggy-back on that. |
| 1197 | */ |
| 1198 | is_active = 1; |
| 1199 | if (rdev2->raid_disk < 0 || |
| 1200 | test_bit(Faulty, &rdev2->flags)) |
| 1201 | is_active = 0; |
| 1202 | if (is_active) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1203 | desc_nr = rdev2->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | else |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1205 | desc_nr = next_spare++; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1206 | rdev2->desc_nr = desc_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | d = &sb->disks[rdev2->desc_nr]; |
| 1208 | nr_disks++; |
| 1209 | d->number = rdev2->desc_nr; |
| 1210 | d->major = MAJOR(rdev2->bdev->bd_dev); |
| 1211 | d->minor = MINOR(rdev2->bdev->bd_dev); |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1212 | if (is_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | d->raid_disk = rdev2->raid_disk; |
| 1214 | else |
| 1215 | d->raid_disk = rdev2->desc_nr; /* compatibility */ |
NeilBrown | 1be7892 | 2006-03-27 01:18:03 -0800 | [diff] [blame] | 1216 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | d->state = (1<<MD_DISK_FAULTY); |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1218 | else if (is_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | d->state = (1<<MD_DISK_ACTIVE); |
NeilBrown | 0261cd9f | 2009-11-13 17:40:48 +1100 | [diff] [blame] | 1220 | if (test_bit(In_sync, &rdev2->flags)) |
| 1221 | d->state |= (1<<MD_DISK_SYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | active++; |
| 1223 | working++; |
| 1224 | } else { |
| 1225 | d->state = 0; |
| 1226 | spare++; |
| 1227 | working++; |
| 1228 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1229 | if (test_bit(WriteMostly, &rdev2->flags)) |
| 1230 | d->state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | /* now set the "removed" and "faulty" bits on any missing devices */ |
| 1233 | for (i=0 ; i < mddev->raid_disks ; i++) { |
| 1234 | mdp_disk_t *d = &sb->disks[i]; |
| 1235 | if (d->state == 0 && d->number == 0) { |
| 1236 | d->number = i; |
| 1237 | d->raid_disk = i; |
| 1238 | d->state = (1<<MD_DISK_REMOVED); |
| 1239 | d->state |= (1<<MD_DISK_FAULTY); |
| 1240 | failed++; |
| 1241 | } |
| 1242 | } |
| 1243 | sb->nr_disks = nr_disks; |
| 1244 | sb->active_disks = active; |
| 1245 | sb->working_disks = working; |
| 1246 | sb->failed_disks = failed; |
| 1247 | sb->spare_disks = spare; |
| 1248 | |
| 1249 | sb->this_disk = sb->disks[rdev->desc_nr]; |
| 1250 | sb->sb_csum = calc_sb_csum(sb); |
| 1251 | } |
| 1252 | |
| 1253 | /* |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1254 | * rdev_size_change for 0.90.0 |
| 1255 | */ |
| 1256 | static unsigned long long |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1257 | 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] | 1258 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1259 | if (num_sectors && num_sectors < rdev->mddev->dev_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1260 | return 0; /* component must fit device */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1261 | if (rdev->mddev->bitmap_info.offset) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1262 | return 0; /* can't move bitmap */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1263 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1264 | if (!num_sectors || num_sectors > rdev->sb_start) |
| 1265 | num_sectors = rdev->sb_start; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1266 | md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1267 | rdev->sb_page); |
| 1268 | md_super_wait(rdev->mddev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1269 | return num_sectors / 2; /* kB for sysfs */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | |
| 1273 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | * version 1 superblock |
| 1275 | */ |
| 1276 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1277 | static __le32 calc_sb_1_csum(struct mdp_superblock_1 * sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | { |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1279 | __le32 disk_csum; |
| 1280 | u32 csum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | unsigned long long newcsum; |
| 1282 | int size = 256 + le32_to_cpu(sb->max_dev)*2; |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1283 | __le32 *isuper = (__le32*)sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | int i; |
| 1285 | |
| 1286 | disk_csum = sb->sb_csum; |
| 1287 | sb->sb_csum = 0; |
| 1288 | newcsum = 0; |
| 1289 | for (i=0; size>=4; size -= 4 ) |
| 1290 | newcsum += le32_to_cpu(*isuper++); |
| 1291 | |
| 1292 | if (size == 2) |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1293 | newcsum += le16_to_cpu(*(__le16*) isuper); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
| 1295 | csum = (newcsum & 0xffffffff) + (newcsum >> 32); |
| 1296 | sb->sb_csum = disk_csum; |
| 1297 | return cpu_to_le32(csum); |
| 1298 | } |
| 1299 | |
| 1300 | static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) |
| 1301 | { |
| 1302 | struct mdp_superblock_1 *sb; |
| 1303 | int ret; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1304 | sector_t sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1306 | int bmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | |
| 1308 | /* |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1309 | * Calculate the position of the superblock in 512byte sectors. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | * It is always aligned to a 4K boundary and |
| 1311 | * depeding on minor_version, it can be: |
| 1312 | * 0: At least 8K, but less than 12K, from end of device |
| 1313 | * 1: At start of device |
| 1314 | * 2: 4K from start of device. |
| 1315 | */ |
| 1316 | switch(minor_version) { |
| 1317 | case 0: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1318 | sb_start = rdev->bdev->bd_inode->i_size >> 9; |
| 1319 | sb_start -= 8*2; |
| 1320 | sb_start &= ~(sector_t)(4*2-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | break; |
| 1322 | case 1: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1323 | sb_start = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | break; |
| 1325 | case 2: |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1326 | sb_start = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | break; |
| 1328 | default: |
| 1329 | return -EINVAL; |
| 1330 | } |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1331 | rdev->sb_start = sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1333 | /* superblock is rarely larger than 1K, but it can be larger, |
| 1334 | * and it is safe to read 4k, so we do that |
| 1335 | */ |
| 1336 | ret = read_disk_sb(rdev, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | if (ret) return ret; |
| 1338 | |
| 1339 | |
| 1340 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1341 | |
| 1342 | if (sb->magic != cpu_to_le32(MD_SB_MAGIC) || |
| 1343 | sb->major_version != cpu_to_le32(1) || |
| 1344 | le32_to_cpu(sb->max_dev) > (4096-256)/2 || |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1345 | le64_to_cpu(sb->super_offset) != rdev->sb_start || |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1346 | (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | return -EINVAL; |
| 1348 | |
| 1349 | if (calc_sb_1_csum(sb) != sb->sb_csum) { |
| 1350 | printk("md: invalid superblock checksum on %s\n", |
| 1351 | bdevname(rdev->bdev,b)); |
| 1352 | return -EINVAL; |
| 1353 | } |
| 1354 | if (le64_to_cpu(sb->data_size) < 10) { |
| 1355 | printk("md: data_size too small on %s\n", |
| 1356 | bdevname(rdev->bdev,b)); |
| 1357 | return -EINVAL; |
| 1358 | } |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | rdev->preferred_minor = 0xffff; |
| 1361 | rdev->data_offset = le64_to_cpu(sb->data_offset); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1362 | atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1364 | rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256; |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 1365 | bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1366 | if (rdev->sb_size & bmask) |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1367 | rdev->sb_size = (rdev->sb_size | bmask) + 1; |
| 1368 | |
| 1369 | if (minor_version |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1370 | && rdev->data_offset < sb_start + (rdev->sb_size/512)) |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1371 | return -EINVAL; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 1372 | |
NeilBrown | 31b65a0 | 2006-07-10 04:44:14 -0700 | [diff] [blame] | 1373 | if (sb->level == cpu_to_le32(LEVEL_MULTIPATH)) |
| 1374 | rdev->desc_nr = -1; |
| 1375 | else |
| 1376 | rdev->desc_nr = le32_to_cpu(sb->dev_number); |
| 1377 | |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1378 | if (!refdev) { |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1379 | ret = 1; |
Harvey Harrison | 9a7b2b0 | 2008-04-28 02:15:49 -0700 | [diff] [blame] | 1380 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | __u64 ev1, ev2; |
| 1382 | struct mdp_superblock_1 *refsb = |
| 1383 | (struct mdp_superblock_1*)page_address(refdev->sb_page); |
| 1384 | |
| 1385 | if (memcmp(sb->set_uuid, refsb->set_uuid, 16) != 0 || |
| 1386 | sb->level != refsb->level || |
| 1387 | sb->layout != refsb->layout || |
| 1388 | sb->chunksize != refsb->chunksize) { |
| 1389 | printk(KERN_WARNING "md: %s has strangely different" |
| 1390 | " superblock to %s\n", |
| 1391 | bdevname(rdev->bdev,b), |
| 1392 | bdevname(refdev->bdev,b2)); |
| 1393 | return -EINVAL; |
| 1394 | } |
| 1395 | ev1 = le64_to_cpu(sb->events); |
| 1396 | ev2 = le64_to_cpu(refsb->events); |
| 1397 | |
| 1398 | if (ev1 > ev2) |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1399 | ret = 1; |
| 1400 | else |
| 1401 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | } |
NeilBrown | a1801f8 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1403 | if (minor_version) |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1404 | rdev->sectors = (rdev->bdev->bd_inode->i_size >> 9) - |
| 1405 | le64_to_cpu(sb->data_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | else |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1407 | rdev->sectors = rdev->sb_start; |
| 1408 | if (rdev->sectors < le64_to_cpu(sb->data_size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | return -EINVAL; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1410 | rdev->sectors = le64_to_cpu(sb->data_size); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1411 | if (le64_to_cpu(sb->size) > rdev->sectors) |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1412 | return -EINVAL; |
NeilBrown | 8ed7546 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1413 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1417 | { |
| 1418 | 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] | 1419 | __u64 ev1 = le64_to_cpu(sb->events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1421 | rdev->raid_disk = -1; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1422 | clear_bit(Faulty, &rdev->flags); |
| 1423 | clear_bit(In_sync, &rdev->flags); |
| 1424 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | if (mddev->raid_disks == 0) { |
| 1427 | mddev->major_version = 1; |
| 1428 | mddev->patch_version = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 1429 | mddev->external = 0; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1430 | mddev->chunk_sectors = le32_to_cpu(sb->chunksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | mddev->ctime = le64_to_cpu(sb->ctime) & ((1ULL << 32)-1); |
| 1432 | mddev->utime = le64_to_cpu(sb->utime) & ((1ULL << 32)-1); |
| 1433 | mddev->level = le32_to_cpu(sb->level); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 1434 | mddev->clevel[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | mddev->layout = le32_to_cpu(sb->layout); |
| 1436 | mddev->raid_disks = le32_to_cpu(sb->raid_disks); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1437 | mddev->dev_sectors = le64_to_cpu(sb->size); |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1438 | mddev->events = ev1; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1439 | mddev->bitmap_info.offset = 0; |
| 1440 | mddev->bitmap_info.default_offset = 1024 >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | |
| 1442 | mddev->recovery_cp = le64_to_cpu(sb->resync_offset); |
| 1443 | memcpy(mddev->uuid, sb->set_uuid, 16); |
| 1444 | |
| 1445 | mddev->max_disks = (4096-256)/2; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1446 | |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1447 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1448 | mddev->bitmap_info.file == NULL ) |
| 1449 | mddev->bitmap_info.offset = |
| 1450 | (__s32)le32_to_cpu(sb->bitmap_offset); |
NeilBrown | e11e93f | 2007-05-09 02:35:36 -0700 | [diff] [blame] | 1451 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1452 | if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) { |
| 1453 | mddev->reshape_position = le64_to_cpu(sb->reshape_position); |
| 1454 | mddev->delta_disks = le32_to_cpu(sb->delta_disks); |
| 1455 | mddev->new_level = le32_to_cpu(sb->new_level); |
| 1456 | mddev->new_layout = le32_to_cpu(sb->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1457 | mddev->new_chunk_sectors = le32_to_cpu(sb->new_chunk); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1458 | } else { |
| 1459 | mddev->reshape_position = MaxSector; |
| 1460 | mddev->delta_disks = 0; |
| 1461 | mddev->new_level = mddev->level; |
| 1462 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1463 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1466 | } else if (mddev->pers == NULL) { |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1467 | /* Insist of good event counter while assembling, except for |
| 1468 | * spares (which don't need an event count) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | ++ev1; |
NeilBrown | be6800a | 2010-05-18 10:17:09 +1000 | [diff] [blame] | 1470 | if (rdev->desc_nr >= 0 && |
| 1471 | rdev->desc_nr < le32_to_cpu(sb->max_dev) && |
| 1472 | le16_to_cpu(sb->dev_roles[rdev->desc_nr]) < 0xfffe) |
| 1473 | if (ev1 < mddev->events) |
| 1474 | return -EINVAL; |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1475 | } else if (mddev->bitmap) { |
| 1476 | /* If adding to array with a bitmap, then we can accept an |
| 1477 | * older device, but not too old. |
| 1478 | */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1479 | if (ev1 < mddev->bitmap->events_cleared) |
| 1480 | return 0; |
NeilBrown | 07d84d10 | 2006-06-26 00:27:56 -0700 | [diff] [blame] | 1481 | } else { |
| 1482 | if (ev1 < mddev->events) |
| 1483 | /* just a hot-add of a new device, leave raid_disk at -1 */ |
| 1484 | return 0; |
| 1485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | if (mddev->level != LEVEL_MULTIPATH) { |
| 1487 | int role; |
NeilBrown | 3673f30 | 2009-08-03 10:59:56 +1000 | [diff] [blame] | 1488 | if (rdev->desc_nr < 0 || |
| 1489 | rdev->desc_nr >= le32_to_cpu(sb->max_dev)) { |
| 1490 | role = 0xffff; |
| 1491 | rdev->desc_nr = -1; |
| 1492 | } else |
| 1493 | role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | switch(role) { |
| 1495 | case 0xffff: /* spare */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | break; |
| 1497 | case 0xfffe: /* faulty */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1498 | set_bit(Faulty, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | break; |
| 1500 | default: |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1501 | if ((le32_to_cpu(sb->feature_map) & |
| 1502 | MD_FEATURE_RECOVERY_OFFSET)) |
| 1503 | rdev->recovery_offset = le64_to_cpu(sb->recovery_offset); |
| 1504 | else |
| 1505 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | rdev->raid_disk = role; |
| 1507 | break; |
| 1508 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 1509 | if (sb->devflags & WriteMostly1) |
| 1510 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1511 | } else /* MULTIPATH are always insync */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1512 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 1513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | return 0; |
| 1515 | } |
| 1516 | |
| 1517 | static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1518 | { |
| 1519 | struct mdp_superblock_1 *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | mdk_rdev_t *rdev2; |
| 1521 | int max_dev, i; |
| 1522 | /* make rdev->sb match mddev and rdev data. */ |
| 1523 | |
| 1524 | sb = (struct mdp_superblock_1*)page_address(rdev->sb_page); |
| 1525 | |
| 1526 | sb->feature_map = 0; |
| 1527 | sb->pad0 = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1528 | sb->recovery_offset = cpu_to_le64(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | memset(sb->pad1, 0, sizeof(sb->pad1)); |
| 1530 | memset(sb->pad2, 0, sizeof(sb->pad2)); |
| 1531 | memset(sb->pad3, 0, sizeof(sb->pad3)); |
| 1532 | |
| 1533 | sb->utime = cpu_to_le64((__u64)mddev->utime); |
| 1534 | sb->events = cpu_to_le64(mddev->events); |
| 1535 | if (mddev->in_sync) |
| 1536 | sb->resync_offset = cpu_to_le64(mddev->recovery_cp); |
| 1537 | else |
| 1538 | sb->resync_offset = cpu_to_le64(0); |
| 1539 | |
NeilBrown | 1c05b4b | 2006-10-21 10:24:08 -0700 | [diff] [blame] | 1540 | sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors)); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1541 | |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1542 | sb->raid_disks = cpu_to_le32(mddev->raid_disks); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1543 | sb->size = cpu_to_le64(mddev->dev_sectors); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1544 | sb->chunksize = cpu_to_le32(mddev->chunk_sectors); |
NeilBrown | 62e1e38 | 2009-05-26 09:40:59 +1000 | [diff] [blame] | 1545 | sb->level = cpu_to_le32(mddev->level); |
| 1546 | sb->layout = cpu_to_le32(mddev->layout); |
NeilBrown | f0ca340 | 2006-02-02 14:28:04 -0800 | [diff] [blame] | 1547 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1548 | if (mddev->bitmap && mddev->bitmap_info.file == NULL) { |
| 1549 | sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_info.offset); |
NeilBrown | 71c0805 | 2005-09-09 16:23:51 -0700 | [diff] [blame] | 1550 | sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1551 | } |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1552 | |
| 1553 | if (rdev->raid_disk >= 0 && |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1554 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 93be75f | 2009-12-14 12:50:06 +1100 | [diff] [blame] | 1555 | sb->feature_map |= |
| 1556 | cpu_to_le32(MD_FEATURE_RECOVERY_OFFSET); |
| 1557 | sb->recovery_offset = |
| 1558 | cpu_to_le64(rdev->recovery_offset); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1559 | } |
| 1560 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1561 | if (mddev->reshape_position != MaxSector) { |
| 1562 | sb->feature_map |= cpu_to_le32(MD_FEATURE_RESHAPE_ACTIVE); |
| 1563 | sb->reshape_position = cpu_to_le64(mddev->reshape_position); |
| 1564 | sb->new_layout = cpu_to_le32(mddev->new_layout); |
| 1565 | sb->delta_disks = cpu_to_le32(mddev->delta_disks); |
| 1566 | sb->new_level = cpu_to_le32(mddev->new_level); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 1567 | sb->new_chunk = cpu_to_le32(mddev->new_chunk_sectors); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 1568 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | max_dev = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1571 | list_for_each_entry(rdev2, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | if (rdev2->desc_nr+1 > max_dev) |
| 1573 | max_dev = rdev2->desc_nr+1; |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1574 | |
NeilBrown | 70471da | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 1575 | if (max_dev > le32_to_cpu(sb->max_dev)) { |
| 1576 | int bmask; |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1577 | sb->max_dev = cpu_to_le32(max_dev); |
NeilBrown | 70471da | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 1578 | rdev->sb_size = max_dev * 2 + 256; |
| 1579 | bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1; |
| 1580 | if (rdev->sb_size & bmask) |
| 1581 | rdev->sb_size = (rdev->sb_size | bmask) + 1; |
NeilBrown | ddcf352 | 2010-09-08 16:48:17 +1000 | [diff] [blame] | 1582 | } else |
| 1583 | max_dev = le32_to_cpu(sb->max_dev); |
| 1584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | for (i=0; i<max_dev;i++) |
| 1586 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
| 1587 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1588 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | i = rdev2->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1590 | if (test_bit(Faulty, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | sb->dev_roles[i] = cpu_to_le16(0xfffe); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1592 | else if (test_bit(In_sync, &rdev2->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
NeilBrown | 93be75f | 2009-12-14 12:50:06 +1100 | [diff] [blame] | 1594 | else if (rdev2->raid_disk >= 0) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 1595 | sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | else |
| 1597 | sb->dev_roles[i] = cpu_to_le16(0xffff); |
| 1598 | } |
| 1599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | sb->sb_csum = calc_sb_1_csum(sb); |
| 1601 | } |
| 1602 | |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1603 | static unsigned long long |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1604 | 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] | 1605 | { |
| 1606 | struct mdp_superblock_1 *sb; |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1607 | sector_t max_sectors; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1608 | if (num_sectors && num_sectors < rdev->mddev->dev_sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1609 | return 0; /* component must fit device */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1610 | if (rdev->sb_start < rdev->data_offset) { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1611 | /* minor versions 1 and 2; superblock before data */ |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1612 | max_sectors = rdev->bdev->bd_inode->i_size >> 9; |
| 1613 | max_sectors -= rdev->data_offset; |
| 1614 | if (!num_sectors || num_sectors > max_sectors) |
| 1615 | num_sectors = max_sectors; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1616 | } else if (rdev->mddev->bitmap_info.offset) { |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1617 | /* minor version 0 with bitmap we can't move */ |
| 1618 | return 0; |
| 1619 | } else { |
| 1620 | /* minor version 0; superblock after data */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1621 | sector_t sb_start; |
| 1622 | sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2; |
| 1623 | sb_start &= ~(sector_t)(4*2 - 1); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1624 | max_sectors = rdev->sectors + sb_start - rdev->sb_start; |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1625 | if (!num_sectors || num_sectors > max_sectors) |
| 1626 | num_sectors = max_sectors; |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1627 | rdev->sb_start = sb_start; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1628 | } |
| 1629 | sb = (struct mdp_superblock_1 *) page_address(rdev->sb_page); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1630 | sb->data_size = cpu_to_le64(num_sectors); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1631 | sb->super_offset = rdev->sb_start; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1632 | sb->sb_csum = calc_sb_1_csum(sb); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 1633 | md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1634 | rdev->sb_page); |
| 1635 | md_super_wait(rdev->mddev); |
Andre Noll | 15f4a5f | 2008-07-21 14:42:12 +1000 | [diff] [blame] | 1636 | return num_sectors / 2; /* kB for sysfs */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 1639 | static struct super_type super_types[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | [0] = { |
| 1641 | .name = "0.90.0", |
| 1642 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1643 | .load_super = super_90_load, |
| 1644 | .validate_super = super_90_validate, |
| 1645 | .sync_super = super_90_sync, |
| 1646 | .rdev_size_change = super_90_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | }, |
| 1648 | [1] = { |
| 1649 | .name = "md-1", |
| 1650 | .owner = THIS_MODULE, |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 1651 | .load_super = super_1_load, |
| 1652 | .validate_super = super_1_validate, |
| 1653 | .sync_super = super_1_sync, |
| 1654 | .rdev_size_change = super_1_rdev_size_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | }, |
| 1656 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
| 1658 | static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2) |
| 1659 | { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1660 | mdk_rdev_t *rdev, *rdev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1662 | rcu_read_lock(); |
| 1663 | rdev_for_each_rcu(rdev, mddev1) |
| 1664 | rdev_for_each_rcu(rdev2, mddev2) |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1665 | if (rdev->bdev->bd_contains == |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1666 | rdev2->bdev->bd_contains) { |
| 1667 | rcu_read_unlock(); |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1668 | return 1; |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1669 | } |
| 1670 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | return 0; |
| 1672 | } |
| 1673 | |
| 1674 | static LIST_HEAD(pending_raid_disks); |
| 1675 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1676 | /* |
| 1677 | * Try to register data integrity profile for an mddev |
| 1678 | * |
| 1679 | * This is called when an array is started and after a disk has been kicked |
| 1680 | * from the array. It only succeeds if all working and active component devices |
| 1681 | * are integrity capable with matching profiles. |
| 1682 | */ |
| 1683 | int md_integrity_register(mddev_t *mddev) |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1684 | { |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1685 | mdk_rdev_t *rdev, *reference = NULL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1686 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1687 | if (list_empty(&mddev->disks)) |
| 1688 | return 0; /* nothing to do */ |
| 1689 | if (blk_get_integrity(mddev->gendisk)) |
| 1690 | return 0; /* already registered */ |
| 1691 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 1692 | /* skip spares and non-functional disks */ |
| 1693 | if (test_bit(Faulty, &rdev->flags)) |
| 1694 | continue; |
| 1695 | if (rdev->raid_disk < 0) |
| 1696 | continue; |
| 1697 | /* |
| 1698 | * If at least one rdev is not integrity capable, we can not |
| 1699 | * enable data integrity for the md device. |
| 1700 | */ |
| 1701 | if (!bdev_get_integrity(rdev->bdev)) |
| 1702 | return -EINVAL; |
| 1703 | if (!reference) { |
| 1704 | /* Use the first rdev as the reference */ |
| 1705 | reference = rdev; |
| 1706 | continue; |
| 1707 | } |
| 1708 | /* does this rdev's profile match the reference profile? */ |
| 1709 | if (blk_integrity_compare(reference->bdev->bd_disk, |
| 1710 | rdev->bdev->bd_disk) < 0) |
| 1711 | return -EINVAL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1712 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1713 | /* |
| 1714 | * All component devices are integrity capable and have matching |
| 1715 | * profiles, register the common profile for the md device. |
| 1716 | */ |
| 1717 | if (blk_integrity_register(mddev->gendisk, |
| 1718 | bdev_get_integrity(reference->bdev)) != 0) { |
| 1719 | printk(KERN_ERR "md: failed to register integrity for %s\n", |
| 1720 | mdname(mddev)); |
| 1721 | return -EINVAL; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1722 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1723 | printk(KERN_NOTICE "md: data integrity on %s enabled\n", |
| 1724 | mdname(mddev)); |
| 1725 | return 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1726 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1727 | EXPORT_SYMBOL(md_integrity_register); |
| 1728 | |
| 1729 | /* Disable data integrity if non-capable/non-matching disk is being added */ |
| 1730 | void md_integrity_add_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 1731 | { |
| 1732 | struct blk_integrity *bi_rdev = bdev_get_integrity(rdev->bdev); |
| 1733 | struct blk_integrity *bi_mddev = blk_get_integrity(mddev->gendisk); |
| 1734 | |
| 1735 | if (!bi_mddev) /* nothing to do */ |
| 1736 | return; |
| 1737 | if (rdev->raid_disk < 0) /* skip spares */ |
| 1738 | return; |
| 1739 | if (bi_rdev && blk_integrity_compare(mddev->gendisk, |
| 1740 | rdev->bdev->bd_disk) >= 0) |
| 1741 | return; |
| 1742 | printk(KERN_NOTICE "disabling data integrity on %s\n", mdname(mddev)); |
| 1743 | blk_integrity_unregister(mddev->gendisk); |
| 1744 | } |
| 1745 | EXPORT_SYMBOL(md_integrity_add_rdev); |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) |
| 1748 | { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 1749 | char b[BDEVNAME_SIZE]; |
NeilBrown | f637b9f | 2005-11-08 21:39:37 -0800 | [diff] [blame] | 1750 | struct kobject *ko; |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1751 | char *s; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1752 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
| 1754 | if (rdev->mddev) { |
| 1755 | MD_BUG(); |
| 1756 | return -EINVAL; |
| 1757 | } |
Dan Williams | 11e2ede | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1758 | |
| 1759 | /* prevent duplicates */ |
| 1760 | if (find_rdev(mddev, rdev->bdev->bd_dev)) |
| 1761 | return -EEXIST; |
| 1762 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1763 | /* make sure rdev->sectors exceeds mddev->dev_sectors */ |
| 1764 | if (rdev->sectors && (mddev->dev_sectors == 0 || |
| 1765 | rdev->sectors < mddev->dev_sectors)) { |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 1766 | if (mddev->pers) { |
| 1767 | /* Cannot change size, so fail |
| 1768 | * If mddev->level <= 0, then we don't care |
| 1769 | * about aligning sizes (e.g. linear) |
| 1770 | */ |
| 1771 | if (mddev->level > 0) |
| 1772 | return -ENOSPC; |
| 1773 | } else |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1774 | mddev->dev_sectors = rdev->sectors; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 1775 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | |
| 1777 | /* Verify rdev->desc_nr is unique. |
| 1778 | * If it is -1, assign a free number, else |
| 1779 | * check number is not in use |
| 1780 | */ |
| 1781 | if (rdev->desc_nr < 0) { |
| 1782 | int choice = 0; |
| 1783 | if (mddev->pers) choice = mddev->raid_disks; |
| 1784 | while (find_rdev_nr(mddev, choice)) |
| 1785 | choice++; |
| 1786 | rdev->desc_nr = choice; |
| 1787 | } else { |
| 1788 | if (find_rdev_nr(mddev, rdev->desc_nr)) |
| 1789 | return -EBUSY; |
| 1790 | } |
NeilBrown | de01dfa | 2009-02-06 18:02:46 +1100 | [diff] [blame] | 1791 | if (mddev->max_disks && rdev->desc_nr >= mddev->max_disks) { |
| 1792 | printk(KERN_WARNING "md: %s: array is limited to %d devices\n", |
| 1793 | mdname(mddev), mddev->max_disks); |
| 1794 | return -EBUSY; |
| 1795 | } |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1796 | bdevname(rdev->bdev,b); |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1797 | while ( (s=strchr(b, '/')) != NULL) |
Neil Brown | 1edf80d | 2006-01-12 01:05:23 -0800 | [diff] [blame] | 1798 | *s = '!'; |
Greg Kroah-Hartman | 649316b | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | rdev->mddev = mddev; |
NeilBrown | 19133a4 | 2005-11-08 21:39:35 -0800 | [diff] [blame] | 1801 | printk(KERN_INFO "md: bind<%s>\n", b); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1802 | |
Greg Kroah-Hartman | b2d6db5 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 1803 | if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b))) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1804 | goto fail; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1805 | |
Tejun Heo | 0762b8b | 2008-08-25 19:56:12 +0900 | [diff] [blame] | 1806 | ko = &part_to_dev(rdev->bdev->bd_part)->kobj; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 1807 | if (sysfs_create_link(&rdev->kobj, ko, "block")) |
| 1808 | /* failure here is OK */; |
| 1809 | rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state"); |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 1810 | |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1811 | list_add_rcu(&rdev->same_set, &mddev->disks); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1812 | bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); |
NeilBrown | 4044ba5 | 2009-01-09 08:31:11 +1100 | [diff] [blame] | 1813 | |
| 1814 | /* May as well allow recovery to be retried once */ |
| 1815 | mddev->recovery_disabled = 0; |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | return 0; |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 1818 | |
| 1819 | fail: |
| 1820 | printk(KERN_WARNING "md: failed to register dev-%s for %s\n", |
| 1821 | b, mdname(mddev)); |
| 1822 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1825 | static void md_delayed_delete(struct work_struct *ws) |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1826 | { |
| 1827 | mdk_rdev_t *rdev = container_of(ws, mdk_rdev_t, del_work); |
| 1828 | kobject_del(&rdev->kobj); |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1829 | kobject_put(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | static void unbind_rdev_from_array(mdk_rdev_t * rdev) |
| 1833 | { |
| 1834 | char b[BDEVNAME_SIZE]; |
| 1835 | if (!rdev->mddev) { |
| 1836 | MD_BUG(); |
| 1837 | return; |
| 1838 | } |
Jun'ichi Nomura | 5463c79 | 2006-03-27 01:17:58 -0800 | [diff] [blame] | 1839 | bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk); |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1840 | list_del_rcu(&rdev->same_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); |
| 1842 | rdev->mddev = NULL; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1843 | sysfs_remove_link(&rdev->kobj, "block"); |
NeilBrown | 3c0ee63 | 2008-10-21 13:25:28 +1100 | [diff] [blame] | 1844 | sysfs_put(rdev->sysfs_state); |
| 1845 | rdev->sysfs_state = NULL; |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1846 | /* We need to delay this, otherwise we can deadlock when |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1847 | * writing to 'remove' to "dev/state". We also need |
| 1848 | * to delay it due to rcu usage. |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1849 | */ |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 1850 | synchronize_rcu(); |
NeilBrown | 177a99b | 2008-02-06 01:39:56 -0800 | [diff] [blame] | 1851 | INIT_WORK(&rdev->del_work, md_delayed_delete); |
| 1852 | kobject_get(&rdev->kobj); |
NeilBrown | 5792a28 | 2007-04-04 19:08:18 -0700 | [diff] [blame] | 1853 | schedule_work(&rdev->del_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | /* |
| 1857 | * prevent the device from being mounted, repartitioned or |
| 1858 | * otherwise reused by a RAID array (or any other kernel |
| 1859 | * subsystem), by bd_claiming the device. |
| 1860 | */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1861 | 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] | 1862 | { |
| 1863 | int err = 0; |
| 1864 | struct block_device *bdev; |
| 1865 | char b[BDEVNAME_SIZE]; |
| 1866 | |
Peter Zijlstra | 2e7b651 | 2006-12-08 02:36:13 -0800 | [diff] [blame] | 1867 | bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | if (IS_ERR(bdev)) { |
| 1869 | printk(KERN_ERR "md: could not open %s.\n", |
| 1870 | __bdevname(dev, b)); |
| 1871 | return PTR_ERR(bdev); |
| 1872 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1873 | err = bd_claim(bdev, shared ? (mdk_rdev_t *)lock_rdev : rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | if (err) { |
| 1875 | printk(KERN_ERR "md: could not bd_claim %s.\n", |
| 1876 | bdevname(bdev, b)); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 1877 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | return err; |
| 1879 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 1880 | if (!shared) |
| 1881 | set_bit(AllReserved, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | rdev->bdev = bdev; |
| 1883 | return err; |
| 1884 | } |
| 1885 | |
| 1886 | static void unlock_rdev(mdk_rdev_t *rdev) |
| 1887 | { |
| 1888 | struct block_device *bdev = rdev->bdev; |
| 1889 | rdev->bdev = NULL; |
| 1890 | if (!bdev) |
| 1891 | MD_BUG(); |
| 1892 | bd_release(bdev); |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 1893 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | void md_autodetect_dev(dev_t dev); |
| 1897 | |
| 1898 | static void export_rdev(mdk_rdev_t * rdev) |
| 1899 | { |
| 1900 | char b[BDEVNAME_SIZE]; |
| 1901 | printk(KERN_INFO "md: export_rdev(%s)\n", |
| 1902 | bdevname(rdev->bdev,b)); |
| 1903 | if (rdev->mddev) |
| 1904 | MD_BUG(); |
| 1905 | free_disk_sb(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | #ifndef MODULE |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 1907 | if (test_bit(AutoDetected, &rdev->flags)) |
| 1908 | md_autodetect_dev(rdev->bdev->bd_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | #endif |
| 1910 | unlock_rdev(rdev); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 1911 | kobject_put(&rdev->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | static void kick_rdev_from_array(mdk_rdev_t * rdev) |
| 1915 | { |
| 1916 | unbind_rdev_from_array(rdev); |
| 1917 | export_rdev(rdev); |
| 1918 | } |
| 1919 | |
| 1920 | static void export_array(mddev_t *mddev) |
| 1921 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1922 | mdk_rdev_t *rdev, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 1924 | rdev_for_each(rdev, tmp, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | if (!rdev->mddev) { |
| 1926 | MD_BUG(); |
| 1927 | continue; |
| 1928 | } |
| 1929 | kick_rdev_from_array(rdev); |
| 1930 | } |
| 1931 | if (!list_empty(&mddev->disks)) |
| 1932 | MD_BUG(); |
| 1933 | mddev->raid_disks = 0; |
| 1934 | mddev->major_version = 0; |
| 1935 | } |
| 1936 | |
| 1937 | static void print_desc(mdp_disk_t *desc) |
| 1938 | { |
| 1939 | printk(" DISK<N:%d,(%d,%d),R:%d,S:%d>\n", desc->number, |
| 1940 | desc->major,desc->minor,desc->raid_disk,desc->state); |
| 1941 | } |
| 1942 | |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1943 | static void print_sb_90(mdp_super_t *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | { |
| 1945 | int i; |
| 1946 | |
| 1947 | printk(KERN_INFO |
| 1948 | "md: SB: (V:%d.%d.%d) ID:<%08x.%08x.%08x.%08x> CT:%08x\n", |
| 1949 | sb->major_version, sb->minor_version, sb->patch_version, |
| 1950 | sb->set_uuid0, sb->set_uuid1, sb->set_uuid2, sb->set_uuid3, |
| 1951 | sb->ctime); |
| 1952 | printk(KERN_INFO "md: L%d S%08d ND:%d RD:%d md%d LO:%d CS:%d\n", |
| 1953 | sb->level, sb->size, sb->nr_disks, sb->raid_disks, |
| 1954 | sb->md_minor, sb->layout, sb->chunk_size); |
| 1955 | printk(KERN_INFO "md: UT:%08x ST:%d AD:%d WD:%d" |
| 1956 | " FD:%d SD:%d CSUM:%08x E:%08lx\n", |
| 1957 | sb->utime, sb->state, sb->active_disks, sb->working_disks, |
| 1958 | sb->failed_disks, sb->spare_disks, |
| 1959 | sb->sb_csum, (unsigned long)sb->events_lo); |
| 1960 | |
| 1961 | printk(KERN_INFO); |
| 1962 | for (i = 0; i < MD_SB_DISKS; i++) { |
| 1963 | mdp_disk_t *desc; |
| 1964 | |
| 1965 | desc = sb->disks + i; |
| 1966 | if (desc->number || desc->major || desc->minor || |
| 1967 | desc->raid_disk || (desc->state && (desc->state != 4))) { |
| 1968 | printk(" D %2d: ", i); |
| 1969 | print_desc(desc); |
| 1970 | } |
| 1971 | } |
| 1972 | printk(KERN_INFO "md: THIS: "); |
| 1973 | print_desc(&sb->this_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1976 | static void print_sb_1(struct mdp_superblock_1 *sb) |
| 1977 | { |
| 1978 | __u8 *uuid; |
| 1979 | |
| 1980 | uuid = sb->set_uuid; |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 1981 | printk(KERN_INFO |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 1982 | "md: SB: (V:%u) (F:0x%08x) Array-ID:<%pU>\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 1983 | "md: Name: \"%s\" CT:%llu\n", |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1984 | le32_to_cpu(sb->major_version), |
| 1985 | le32_to_cpu(sb->feature_map), |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 1986 | uuid, |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1987 | sb->set_name, |
| 1988 | (unsigned long long)le64_to_cpu(sb->ctime) |
| 1989 | & MD_SUPERBLOCK_1_TIME_SEC_MASK); |
| 1990 | |
| 1991 | uuid = sb->device_uuid; |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 1992 | printk(KERN_INFO |
| 1993 | "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] | 1994 | " RO:%llu\n" |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 1995 | "md: Dev:%08x UUID: %pU\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 1996 | "md: (F:0x%08x) UT:%llu Events:%llu ResyncOffset:%llu CSUM:0x%08x\n" |
| 1997 | "md: (MaxDev:%u) \n", |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 1998 | le32_to_cpu(sb->level), |
| 1999 | (unsigned long long)le64_to_cpu(sb->size), |
| 2000 | le32_to_cpu(sb->raid_disks), |
| 2001 | le32_to_cpu(sb->layout), |
| 2002 | le32_to_cpu(sb->chunksize), |
| 2003 | (unsigned long long)le64_to_cpu(sb->data_offset), |
| 2004 | (unsigned long long)le64_to_cpu(sb->data_size), |
| 2005 | (unsigned long long)le64_to_cpu(sb->super_offset), |
| 2006 | (unsigned long long)le64_to_cpu(sb->recovery_offset), |
| 2007 | le32_to_cpu(sb->dev_number), |
Joe Perches | 7b75c2f | 2009-12-14 18:01:12 -0800 | [diff] [blame] | 2008 | uuid, |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2009 | sb->devflags, |
| 2010 | (unsigned long long)le64_to_cpu(sb->utime) & MD_SUPERBLOCK_1_TIME_SEC_MASK, |
| 2011 | (unsigned long long)le64_to_cpu(sb->events), |
| 2012 | (unsigned long long)le64_to_cpu(sb->resync_offset), |
| 2013 | le32_to_cpu(sb->sb_csum), |
| 2014 | le32_to_cpu(sb->max_dev) |
| 2015 | ); |
| 2016 | } |
| 2017 | |
| 2018 | static void print_rdev(mdk_rdev_t *rdev, int major_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | { |
| 2020 | char b[BDEVNAME_SIZE]; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2021 | printk(KERN_INFO "md: rdev %s, Sect:%08llu F:%d S:%d DN:%u\n", |
| 2022 | bdevname(rdev->bdev, b), (unsigned long long)rdev->sectors, |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2023 | test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags), |
| 2024 | rdev->desc_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | if (rdev->sb_loaded) { |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2026 | printk(KERN_INFO "md: rdev superblock (MJ:%d):\n", major_version); |
| 2027 | switch (major_version) { |
| 2028 | case 0: |
| 2029 | print_sb_90((mdp_super_t*)page_address(rdev->sb_page)); |
| 2030 | break; |
| 2031 | case 1: |
| 2032 | print_sb_1((struct mdp_superblock_1 *)page_address(rdev->sb_page)); |
| 2033 | break; |
| 2034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } else |
| 2036 | printk(KERN_INFO "md: no rdev superblock!\n"); |
| 2037 | } |
| 2038 | |
Adrian Bunk | 5e56341 | 2006-06-26 00:27:42 -0700 | [diff] [blame] | 2039 | static void md_print_devices(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2041 | struct list_head *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | mdk_rdev_t *rdev; |
| 2043 | mddev_t *mddev; |
| 2044 | char b[BDEVNAME_SIZE]; |
| 2045 | |
| 2046 | printk("\n"); |
| 2047 | printk("md: **********************************\n"); |
| 2048 | printk("md: * <COMPLETE RAID STATE PRINTOUT> *\n"); |
| 2049 | printk("md: **********************************\n"); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 2050 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 2052 | if (mddev->bitmap) |
| 2053 | bitmap_print_sb(mddev->bitmap); |
| 2054 | else |
| 2055 | printk("%s: ", mdname(mddev)); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2056 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 2058 | printk("\n"); |
| 2059 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2060 | list_for_each_entry(rdev, &mddev->disks, same_set) |
Cheng Renquan | cd2ac93 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2061 | print_rdev(rdev, mddev->major_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | } |
| 2063 | printk("md: **********************************\n"); |
| 2064 | printk("\n"); |
| 2065 | } |
| 2066 | |
| 2067 | |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2068 | static void sync_sbs(mddev_t * mddev, int nospares) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2070 | /* Update each superblock (in-memory image), but |
| 2071 | * if we are allowed to, skip spares which already |
| 2072 | * have the right event counter, or have one earlier |
| 2073 | * (which would mean they aren't being marked as dirty |
| 2074 | * with the rest of the array) |
| 2075 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | mdk_rdev_t *rdev; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2077 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2078 | if (rdev->sb_events == mddev->events || |
| 2079 | (nospares && |
| 2080 | rdev->raid_disk < 0 && |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2081 | rdev->sb_events+1 == mddev->events)) { |
| 2082 | /* Don't update this superblock */ |
| 2083 | rdev->sb_loaded = 2; |
| 2084 | } else { |
| 2085 | super_types[mddev->major_version]. |
| 2086 | sync_super(mddev, rdev); |
| 2087 | rdev->sb_loaded = 1; |
| 2088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | } |
| 2090 | } |
| 2091 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2092 | static void md_update_sb(mddev_t * mddev, int force_change) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | mdk_rdev_t *rdev; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2095 | int sync_req; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2096 | int nospares = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | repeat: |
NeilBrown | 3a3a5dd | 2010-08-16 18:09:31 +1000 | [diff] [blame] | 2099 | /* First make sure individual recovery_offsets are correct */ |
| 2100 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 2101 | if (rdev->raid_disk >= 0 && |
| 2102 | mddev->delta_disks >= 0 && |
| 2103 | !test_bit(In_sync, &rdev->flags) && |
| 2104 | mddev->curr_resync_completed > rdev->recovery_offset) |
| 2105 | rdev->recovery_offset = mddev->curr_resync_completed; |
| 2106 | |
| 2107 | } |
Dan Williams | bd52b74 | 2010-08-30 17:33:33 +1000 | [diff] [blame] | 2108 | if (!mddev->persistent) { |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 2109 | clear_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 3a3a5dd | 2010-08-16 18:09:31 +1000 | [diff] [blame] | 2110 | clear_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | d97a41d | 2010-10-28 17:30:20 +1100 | [diff] [blame^] | 2111 | if (!mddev->external) |
| 2112 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
NeilBrown | 3a3a5dd | 2010-08-16 18:09:31 +1000 | [diff] [blame] | 2113 | wake_up(&mddev->sb_wait); |
| 2114 | return; |
| 2115 | } |
| 2116 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2117 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2118 | |
NeilBrown | 3a3a5dd | 2010-08-16 18:09:31 +1000 | [diff] [blame] | 2119 | mddev->utime = get_seconds(); |
| 2120 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2121 | if (test_and_clear_bit(MD_CHANGE_DEVS, &mddev->flags)) |
| 2122 | force_change = 1; |
| 2123 | if (test_and_clear_bit(MD_CHANGE_CLEAN, &mddev->flags)) |
| 2124 | /* just a clean<-> dirty transition, possibly leave spares alone, |
| 2125 | * though if events isn't the right even/odd, we will have to do |
| 2126 | * spares after all |
| 2127 | */ |
| 2128 | nospares = 1; |
| 2129 | if (force_change) |
| 2130 | nospares = 0; |
| 2131 | if (mddev->degraded) |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2132 | /* If the array is degraded, then skipping spares is both |
| 2133 | * dangerous and fairly pointless. |
| 2134 | * Dangerous because a device that was removed from the array |
| 2135 | * might have a event_count that still looks up-to-date, |
| 2136 | * so it can be re-added without a resync. |
| 2137 | * Pointless because if there are any spares to skip, |
| 2138 | * then a recovery will happen and soon that array won't |
| 2139 | * be degraded any more and the spare can go back to sleep then. |
| 2140 | */ |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2141 | nospares = 0; |
NeilBrown | 8469219 | 2006-08-27 01:23:49 -0700 | [diff] [blame] | 2142 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2143 | sync_req = mddev->in_sync; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2144 | |
| 2145 | /* If this is just a dirty<->clean transition, and the array is clean |
| 2146 | * and 'events' is odd, we can roll back to the previous clean state */ |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2147 | if (nospares |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2148 | && (mddev->in_sync && mddev->recovery_cp == MaxSector) |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 2149 | && mddev->can_decrease_events |
| 2150 | && mddev->events != 1) { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2151 | mddev->events--; |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 2152 | mddev->can_decrease_events = 0; |
| 2153 | } else { |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2154 | /* otherwise we have to go forward and ... */ |
| 2155 | mddev->events ++; |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 2156 | mddev->can_decrease_events = nospares; |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2157 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | |
| 2159 | if (!mddev->events) { |
| 2160 | /* |
| 2161 | * oops, this 64-bit counter should never wrap. |
| 2162 | * Either we are in around ~1 trillion A.C., assuming |
| 2163 | * 1 reboot per second, or we have a bug: |
| 2164 | */ |
| 2165 | MD_BUG(); |
| 2166 | mddev->events --; |
| 2167 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2168 | sync_sbs(mddev, nospares); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2169 | spin_unlock_irq(&mddev->write_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | |
| 2171 | dprintk(KERN_INFO |
| 2172 | "md: updating %s RAID superblock on device (in sync %d)\n", |
| 2173 | mdname(mddev),mddev->in_sync); |
| 2174 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 2175 | bitmap_update_sb(mddev->bitmap); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2176 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | char b[BDEVNAME_SIZE]; |
| 2178 | dprintk(KERN_INFO "md: "); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2179 | if (rdev->sb_loaded != 1) |
| 2180 | continue; /* no noise on spare devices */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2181 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | dprintk("(skipping faulty "); |
| 2183 | |
| 2184 | dprintk("%s ", bdevname(rdev->bdev,b)); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2185 | if (!test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2186 | md_super_write(mddev,rdev, |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 2187 | rdev->sb_start, rdev->sb_size, |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2188 | rdev->sb_page); |
| 2189 | dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", |
| 2190 | bdevname(rdev->bdev,b), |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 2191 | (unsigned long long)rdev->sb_start); |
NeilBrown | 4254376 | 2006-06-26 00:27:57 -0700 | [diff] [blame] | 2192 | rdev->sb_events = mddev->events; |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | } else |
| 2195 | dprintk(")\n"); |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 2196 | if (mddev->level == LEVEL_MULTIPATH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | /* only need to write one superblock... */ |
| 2198 | break; |
| 2199 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2200 | md_super_wait(mddev); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2201 | /* 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] | 2202 | |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2203 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2204 | if (mddev->in_sync != sync_req || |
| 2205 | test_bit(MD_CHANGE_DEVS, &mddev->flags)) { |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2206 | /* have to write it out again */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2207 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2208 | goto repeat; |
| 2209 | } |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 2210 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 2211 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 2212 | wake_up(&mddev->sb_wait); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 2213 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 2214 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 2215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | } |
| 2217 | |
Andre Noll | 7f6ce76 | 2008-03-23 18:34:54 +0100 | [diff] [blame] | 2218 | /* words written to sysfs files may, or may not, be \n terminated. |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 2219 | * We want to accept with case. For this we use cmd_match. |
| 2220 | */ |
| 2221 | static int cmd_match(const char *cmd, const char *str) |
| 2222 | { |
| 2223 | /* See if cmd, written into a sysfs file, matches |
| 2224 | * str. They must either be the same, or cmd can |
| 2225 | * have a trailing newline |
| 2226 | */ |
| 2227 | while (*cmd && *str && *cmd == *str) { |
| 2228 | cmd++; |
| 2229 | str++; |
| 2230 | } |
| 2231 | if (*cmd == '\n') |
| 2232 | cmd++; |
| 2233 | if (*str || *cmd) |
| 2234 | return 0; |
| 2235 | return 1; |
| 2236 | } |
| 2237 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2238 | struct rdev_sysfs_entry { |
| 2239 | struct attribute attr; |
| 2240 | ssize_t (*show)(mdk_rdev_t *, char *); |
| 2241 | ssize_t (*store)(mdk_rdev_t *, const char *, size_t); |
| 2242 | }; |
| 2243 | |
| 2244 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2245 | state_show(mdk_rdev_t *rdev, char *page) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2246 | { |
| 2247 | char *sep = ""; |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2248 | size_t len = 0; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2249 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2250 | if (test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2251 | len+= sprintf(page+len, "%sfaulty",sep); |
| 2252 | sep = ","; |
| 2253 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2254 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2255 | len += sprintf(page+len, "%sin_sync",sep); |
| 2256 | sep = ","; |
| 2257 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2258 | if (test_bit(WriteMostly, &rdev->flags)) { |
| 2259 | len += sprintf(page+len, "%swrite_mostly",sep); |
| 2260 | sep = ","; |
| 2261 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2262 | if (test_bit(Blocked, &rdev->flags)) { |
| 2263 | len += sprintf(page+len, "%sblocked", sep); |
| 2264 | sep = ","; |
| 2265 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2266 | if (!test_bit(Faulty, &rdev->flags) && |
| 2267 | !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2268 | len += sprintf(page+len, "%sspare", sep); |
| 2269 | sep = ","; |
| 2270 | } |
| 2271 | return len+sprintf(page+len, "\n"); |
| 2272 | } |
| 2273 | |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2274 | static ssize_t |
| 2275 | state_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2276 | { |
| 2277 | /* can write |
| 2278 | * faulty - simulates and error |
| 2279 | * remove - disconnects the device |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2280 | * writemostly - sets write_mostly |
| 2281 | * -writemostly - clears write_mostly |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2282 | * blocked - sets the Blocked flag |
| 2283 | * -blocked - clears the Blocked flag |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2284 | * insync - sets Insync providing device isn't active |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2285 | */ |
| 2286 | int err = -EINVAL; |
| 2287 | if (cmd_match(buf, "faulty") && rdev->mddev->pers) { |
| 2288 | md_error(rdev->mddev, rdev); |
| 2289 | err = 0; |
| 2290 | } else if (cmd_match(buf, "remove")) { |
| 2291 | if (rdev->raid_disk >= 0) |
| 2292 | err = -EBUSY; |
| 2293 | else { |
| 2294 | mddev_t *mddev = rdev->mddev; |
| 2295 | kick_rdev_from_array(rdev); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 2296 | if (mddev->pers) |
| 2297 | md_update_sb(mddev, 1); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2298 | md_new_event(mddev); |
| 2299 | err = 0; |
| 2300 | } |
NeilBrown | f655675 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 2301 | } else if (cmd_match(buf, "writemostly")) { |
| 2302 | set_bit(WriteMostly, &rdev->flags); |
| 2303 | err = 0; |
| 2304 | } else if (cmd_match(buf, "-writemostly")) { |
| 2305 | clear_bit(WriteMostly, &rdev->flags); |
| 2306 | err = 0; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2307 | } else if (cmd_match(buf, "blocked")) { |
| 2308 | set_bit(Blocked, &rdev->flags); |
| 2309 | err = 0; |
| 2310 | } else if (cmd_match(buf, "-blocked")) { |
| 2311 | clear_bit(Blocked, &rdev->flags); |
| 2312 | wake_up(&rdev->blocked_wait); |
| 2313 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 2314 | md_wakeup_thread(rdev->mddev->thread); |
| 2315 | |
| 2316 | err = 0; |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2317 | } else if (cmd_match(buf, "insync") && rdev->raid_disk == -1) { |
| 2318 | set_bit(In_sync, &rdev->flags); |
| 2319 | err = 0; |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2320 | } |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2321 | if (!err) |
| 2322 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
NeilBrown | 45dc2de | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 2323 | return err ? err : len; |
| 2324 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2325 | static struct rdev_sysfs_entry rdev_state = |
| 2326 | __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2327 | |
| 2328 | static ssize_t |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2329 | errors_show(mdk_rdev_t *rdev, char *page) |
| 2330 | { |
| 2331 | return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors)); |
| 2332 | } |
| 2333 | |
| 2334 | static ssize_t |
| 2335 | errors_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2336 | { |
| 2337 | char *e; |
| 2338 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 2339 | if (*buf && (*e == 0 || *e == '\n')) { |
| 2340 | atomic_set(&rdev->corrected_errors, n); |
| 2341 | return len; |
| 2342 | } |
| 2343 | return -EINVAL; |
| 2344 | } |
| 2345 | static struct rdev_sysfs_entry rdev_errors = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2346 | __ATTR(errors, S_IRUGO|S_IWUSR, errors_show, errors_store); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2347 | |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2348 | static ssize_t |
| 2349 | slot_show(mdk_rdev_t *rdev, char *page) |
| 2350 | { |
| 2351 | if (rdev->raid_disk < 0) |
| 2352 | return sprintf(page, "none\n"); |
| 2353 | else |
| 2354 | return sprintf(page, "%d\n", rdev->raid_disk); |
| 2355 | } |
| 2356 | |
| 2357 | static ssize_t |
| 2358 | slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2359 | { |
| 2360 | char *e; |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2361 | int err; |
| 2362 | char nm[20]; |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2363 | int slot = simple_strtoul(buf, &e, 10); |
| 2364 | if (strncmp(buf, "none", 4)==0) |
| 2365 | slot = -1; |
| 2366 | else if (e==buf || (*e && *e!= '\n')) |
| 2367 | return -EINVAL; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2368 | if (rdev->mddev->pers && slot == -1) { |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2369 | /* Setting 'slot' on an active array requires also |
| 2370 | * updating the 'rd%d' link, and communicating |
| 2371 | * with the personality with ->hot_*_disk. |
| 2372 | * For now we only support removing |
| 2373 | * failed/spare devices. This normally happens automatically, |
| 2374 | * but not when the metadata is externally managed. |
| 2375 | */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2376 | if (rdev->raid_disk == -1) |
| 2377 | return -EEXIST; |
| 2378 | /* personality does all needed checks */ |
| 2379 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 2380 | return -EINVAL; |
| 2381 | err = rdev->mddev->pers-> |
| 2382 | hot_remove_disk(rdev->mddev, rdev->raid_disk); |
| 2383 | if (err) |
| 2384 | return err; |
| 2385 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2386 | sysfs_remove_link(&rdev->mddev->kobj, nm); |
Maciej Trela | b710310 | 2010-04-14 16:58:16 +1000 | [diff] [blame] | 2387 | rdev->raid_disk = -1; |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2388 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
| 2389 | md_wakeup_thread(rdev->mddev->thread); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2390 | } else if (rdev->mddev->pers) { |
| 2391 | mdk_rdev_t *rdev2; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2392 | /* Activating a spare .. or possibly reactivating |
NeilBrown | 6d56e27 | 2009-04-14 12:01:57 +1000 | [diff] [blame] | 2393 | * if we ever get bitmaps working here. |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2394 | */ |
| 2395 | |
| 2396 | if (rdev->raid_disk != -1) |
| 2397 | return -EBUSY; |
| 2398 | |
| 2399 | if (rdev->mddev->pers->hot_add_disk == NULL) |
| 2400 | return -EINVAL; |
| 2401 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2402 | list_for_each_entry(rdev2, &rdev->mddev->disks, same_set) |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2403 | if (rdev2->raid_disk == slot) |
| 2404 | return -EEXIST; |
| 2405 | |
| 2406 | rdev->raid_disk = slot; |
| 2407 | if (test_bit(In_sync, &rdev->flags)) |
| 2408 | rdev->saved_raid_disk = slot; |
| 2409 | else |
| 2410 | rdev->saved_raid_disk = -1; |
| 2411 | err = rdev->mddev->pers-> |
| 2412 | hot_add_disk(rdev->mddev, rdev); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 2413 | if (err) { |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2414 | rdev->raid_disk = -1; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2415 | return err; |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 2416 | } else |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2417 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2418 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 2419 | if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2420 | /* failure here is OK */; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 2421 | /* don't wakeup anyone, leave that to userspace. */ |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2422 | } else { |
| 2423 | if (slot >= rdev->mddev->raid_disks) |
| 2424 | return -ENOSPC; |
| 2425 | rdev->raid_disk = slot; |
| 2426 | /* assume it is working */ |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2427 | clear_bit(Faulty, &rdev->flags); |
| 2428 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2429 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 2430 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
NeilBrown | c303da6 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 2431 | } |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2432 | return len; |
| 2433 | } |
| 2434 | |
| 2435 | |
| 2436 | static struct rdev_sysfs_entry rdev_slot = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2437 | __ATTR(slot, S_IRUGO|S_IWUSR, slot_show, slot_store); |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2438 | |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2439 | static ssize_t |
| 2440 | offset_show(mdk_rdev_t *rdev, char *page) |
| 2441 | { |
Andrew Morton | 6961ece | 2006-01-06 00:20:59 -0800 | [diff] [blame] | 2442 | return sprintf(page, "%llu\n", (unsigned long long)rdev->data_offset); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | static ssize_t |
| 2446 | offset_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2447 | { |
| 2448 | char *e; |
| 2449 | unsigned long long offset = simple_strtoull(buf, &e, 10); |
| 2450 | if (e==buf || (*e && *e != '\n')) |
| 2451 | return -EINVAL; |
Neil Brown | 8ed0a52 | 2008-06-28 08:31:29 +1000 | [diff] [blame] | 2452 | if (rdev->mddev->pers && rdev->raid_disk >= 0) |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2453 | return -EBUSY; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2454 | if (rdev->sectors && rdev->mddev->external) |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2455 | /* Must set offset before size, so overlap checks |
| 2456 | * can be sane */ |
| 2457 | return -EBUSY; |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2458 | rdev->data_offset = offset; |
| 2459 | return len; |
| 2460 | } |
| 2461 | |
| 2462 | static struct rdev_sysfs_entry rdev_offset = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2463 | __ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store); |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2464 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2465 | static ssize_t |
| 2466 | rdev_size_show(mdk_rdev_t *rdev, char *page) |
| 2467 | { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2468 | return sprintf(page, "%llu\n", (unsigned long long)rdev->sectors / 2); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2469 | } |
| 2470 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2471 | static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2) |
| 2472 | { |
| 2473 | /* check if two start/length pairs overlap */ |
| 2474 | if (s1+l1 <= s2) |
| 2475 | return 0; |
| 2476 | if (s2+l2 <= s1) |
| 2477 | return 0; |
| 2478 | return 1; |
| 2479 | } |
| 2480 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2481 | static int strict_blocks_to_sectors(const char *buf, sector_t *sectors) |
| 2482 | { |
| 2483 | unsigned long long blocks; |
| 2484 | sector_t new; |
| 2485 | |
| 2486 | if (strict_strtoull(buf, 10, &blocks) < 0) |
| 2487 | return -EINVAL; |
| 2488 | |
| 2489 | if (blocks & 1ULL << (8 * sizeof(blocks) - 1)) |
| 2490 | return -EINVAL; /* sector conversion overflow */ |
| 2491 | |
| 2492 | new = blocks * 2; |
| 2493 | if (new != blocks * 2) |
| 2494 | return -EINVAL; /* unsigned long long to sector_t overflow */ |
| 2495 | |
| 2496 | *sectors = new; |
| 2497 | return 0; |
| 2498 | } |
| 2499 | |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2500 | static ssize_t |
| 2501 | rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2502 | { |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2503 | mddev_t *my_mddev = rdev->mddev; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2504 | sector_t oldsectors = rdev->sectors; |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2505 | sector_t sectors; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2506 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2507 | if (strict_blocks_to_sectors(buf, §ors) < 0) |
Neil Brown | d702745 | 2008-07-12 10:37:50 +1000 | [diff] [blame] | 2508 | return -EINVAL; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2509 | if (my_mddev->pers && rdev->raid_disk >= 0) { |
Neil Brown | d702745 | 2008-07-12 10:37:50 +1000 | [diff] [blame] | 2510 | if (my_mddev->persistent) { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2511 | sectors = super_types[my_mddev->major_version]. |
| 2512 | rdev_size_change(rdev, sectors); |
| 2513 | if (!sectors) |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2514 | return -EBUSY; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2515 | } else if (!sectors) |
| 2516 | sectors = (rdev->bdev->bd_inode->i_size >> 9) - |
| 2517 | rdev->data_offset; |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2518 | } |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2519 | if (sectors < my_mddev->dev_sectors) |
Chris Webb | 7d3c6f8 | 2008-10-13 11:55:11 +1100 | [diff] [blame] | 2520 | return -EINVAL; /* component must fit device */ |
Chris Webb | 0cd17fe | 2008-06-28 08:31:46 +1000 | [diff] [blame] | 2521 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2522 | rdev->sectors = sectors; |
| 2523 | if (sectors > oldsectors && my_mddev->external) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2524 | /* need to check that all other rdevs with the same ->bdev |
| 2525 | * do not overlap. We need to unlock the mddev to avoid |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2526 | * a deadlock. We have already changed rdev->sectors, and if |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2527 | * we have to change it back, we will have the lock again. |
| 2528 | */ |
| 2529 | mddev_t *mddev; |
| 2530 | int overlap = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2531 | struct list_head *tmp; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2532 | |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2533 | mddev_unlock(my_mddev); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 2534 | for_each_mddev(mddev, tmp) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2535 | mdk_rdev_t *rdev2; |
| 2536 | |
| 2537 | mddev_lock(mddev); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2538 | list_for_each_entry(rdev2, &mddev->disks, same_set) |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2539 | if (test_bit(AllReserved, &rdev2->flags) || |
| 2540 | (rdev->bdev == rdev2->bdev && |
| 2541 | rdev != rdev2 && |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2542 | overlaps(rdev->data_offset, rdev->sectors, |
Andre Noll | d07bd3b | 2008-07-21 14:42:07 +1000 | [diff] [blame] | 2543 | rdev2->data_offset, |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2544 | rdev2->sectors))) { |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2545 | overlap = 1; |
| 2546 | break; |
| 2547 | } |
| 2548 | mddev_unlock(mddev); |
| 2549 | if (overlap) { |
| 2550 | mddev_put(mddev); |
| 2551 | break; |
| 2552 | } |
| 2553 | } |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2554 | mddev_lock(my_mddev); |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2555 | if (overlap) { |
| 2556 | /* Someone else could have slipped in a size |
| 2557 | * change here, but doing so is just silly. |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2558 | * We put oldsectors back because we *know* it is |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2559 | * safe, and trust userspace not to race with |
| 2560 | * itself |
| 2561 | */ |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2562 | rdev->sectors = oldsectors; |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2563 | return -EBUSY; |
| 2564 | } |
| 2565 | } |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2566 | return len; |
| 2567 | } |
| 2568 | |
| 2569 | static struct rdev_sysfs_entry rdev_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2570 | __ATTR(size, S_IRUGO|S_IWUSR, rdev_size_show, rdev_size_store); |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2571 | |
Dan Williams | 06e3c81 | 2009-12-12 21:17:12 -0700 | [diff] [blame] | 2572 | |
| 2573 | static ssize_t recovery_start_show(mdk_rdev_t *rdev, char *page) |
| 2574 | { |
| 2575 | unsigned long long recovery_start = rdev->recovery_offset; |
| 2576 | |
| 2577 | if (test_bit(In_sync, &rdev->flags) || |
| 2578 | recovery_start == MaxSector) |
| 2579 | return sprintf(page, "none\n"); |
| 2580 | |
| 2581 | return sprintf(page, "%llu\n", recovery_start); |
| 2582 | } |
| 2583 | |
| 2584 | static ssize_t recovery_start_store(mdk_rdev_t *rdev, const char *buf, size_t len) |
| 2585 | { |
| 2586 | unsigned long long recovery_start; |
| 2587 | |
| 2588 | if (cmd_match(buf, "none")) |
| 2589 | recovery_start = MaxSector; |
| 2590 | else if (strict_strtoull(buf, 10, &recovery_start)) |
| 2591 | return -EINVAL; |
| 2592 | |
| 2593 | if (rdev->mddev->pers && |
| 2594 | rdev->raid_disk >= 0) |
| 2595 | return -EBUSY; |
| 2596 | |
| 2597 | rdev->recovery_offset = recovery_start; |
| 2598 | if (recovery_start == MaxSector) |
| 2599 | set_bit(In_sync, &rdev->flags); |
| 2600 | else |
| 2601 | clear_bit(In_sync, &rdev->flags); |
| 2602 | return len; |
| 2603 | } |
| 2604 | |
| 2605 | static struct rdev_sysfs_entry rdev_recovery_start = |
| 2606 | __ATTR(recovery_start, S_IRUGO|S_IWUSR, recovery_start_show, recovery_start_store); |
| 2607 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2608 | static struct attribute *rdev_default_attrs[] = { |
| 2609 | &rdev_state.attr, |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 2610 | &rdev_errors.attr, |
NeilBrown | 014236d | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 2611 | &rdev_slot.attr, |
NeilBrown | 93c8cad | 2006-01-06 00:20:56 -0800 | [diff] [blame] | 2612 | &rdev_offset.attr, |
NeilBrown | 83303b6 | 2006-01-06 00:21:06 -0800 | [diff] [blame] | 2613 | &rdev_size.attr, |
Dan Williams | 06e3c81 | 2009-12-12 21:17:12 -0700 | [diff] [blame] | 2614 | &rdev_recovery_start.attr, |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2615 | NULL, |
| 2616 | }; |
| 2617 | static ssize_t |
| 2618 | rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 2619 | { |
| 2620 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2621 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2622 | mddev_t *mddev = rdev->mddev; |
| 2623 | ssize_t rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2624 | |
| 2625 | if (!entry->show) |
| 2626 | return -EIO; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2627 | |
| 2628 | rv = mddev ? mddev_lock(mddev) : -EBUSY; |
| 2629 | if (!rv) { |
| 2630 | if (rdev->mddev == NULL) |
| 2631 | rv = -EBUSY; |
| 2632 | else |
| 2633 | rv = entry->show(rdev, page); |
| 2634 | mddev_unlock(mddev); |
| 2635 | } |
| 2636 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | static ssize_t |
| 2640 | rdev_attr_store(struct kobject *kobj, struct attribute *attr, |
| 2641 | const char *page, size_t length) |
| 2642 | { |
| 2643 | struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); |
| 2644 | mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj); |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2645 | ssize_t rv; |
| 2646 | mddev_t *mddev = rdev->mddev; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2647 | |
| 2648 | if (!entry->store) |
| 2649 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 2650 | if (!capable(CAP_SYS_ADMIN)) |
| 2651 | return -EACCES; |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2652 | rv = mddev ? mddev_lock(mddev): -EBUSY; |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2653 | if (!rv) { |
NeilBrown | 27c529b | 2008-03-04 14:29:33 -0800 | [diff] [blame] | 2654 | if (rdev->mddev == NULL) |
| 2655 | rv = -EBUSY; |
| 2656 | else |
| 2657 | rv = entry->store(rdev, page, length); |
Dan Williams | 6a51830 | 2008-04-30 00:52:28 -0700 | [diff] [blame] | 2658 | mddev_unlock(mddev); |
NeilBrown | ca38805 | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 2659 | } |
| 2660 | return rv; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | static void rdev_free(struct kobject *ko) |
| 2664 | { |
| 2665 | mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj); |
| 2666 | kfree(rdev); |
| 2667 | } |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 2668 | static const struct sysfs_ops rdev_sysfs_ops = { |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2669 | .show = rdev_attr_show, |
| 2670 | .store = rdev_attr_store, |
| 2671 | }; |
| 2672 | static struct kobj_type rdev_ktype = { |
| 2673 | .release = rdev_free, |
| 2674 | .sysfs_ops = &rdev_sysfs_ops, |
| 2675 | .default_attrs = rdev_default_attrs, |
| 2676 | }; |
| 2677 | |
NeilBrown | e8bb9a8 | 2010-06-01 19:37:26 +1000 | [diff] [blame] | 2678 | void md_rdev_init(mdk_rdev_t *rdev) |
| 2679 | { |
| 2680 | rdev->desc_nr = -1; |
| 2681 | rdev->saved_raid_disk = -1; |
| 2682 | rdev->raid_disk = -1; |
| 2683 | rdev->flags = 0; |
| 2684 | rdev->data_offset = 0; |
| 2685 | rdev->sb_events = 0; |
| 2686 | rdev->last_read_error.tv_sec = 0; |
| 2687 | rdev->last_read_error.tv_nsec = 0; |
| 2688 | atomic_set(&rdev->nr_pending, 0); |
| 2689 | atomic_set(&rdev->read_errors, 0); |
| 2690 | atomic_set(&rdev->corrected_errors, 0); |
| 2691 | |
| 2692 | INIT_LIST_HEAD(&rdev->same_set); |
| 2693 | init_waitqueue_head(&rdev->blocked_wait); |
| 2694 | } |
| 2695 | EXPORT_SYMBOL_GPL(md_rdev_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | /* |
| 2697 | * Import a device. If 'super_format' >= 0, then sanity check the superblock |
| 2698 | * |
| 2699 | * mark the device faulty if: |
| 2700 | * |
| 2701 | * - the device is nonexistent (zero size) |
| 2702 | * - the device has no valid superblock |
| 2703 | * |
| 2704 | * a faulty rdev _never_ has rdev->sb set. |
| 2705 | */ |
| 2706 | static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_minor) |
| 2707 | { |
| 2708 | char b[BDEVNAME_SIZE]; |
| 2709 | int err; |
| 2710 | mdk_rdev_t *rdev; |
| 2711 | sector_t size; |
| 2712 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 2713 | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | if (!rdev) { |
| 2715 | printk(KERN_ERR "md: could not alloc mem for new device!\n"); |
| 2716 | return ERR_PTR(-ENOMEM); |
| 2717 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | |
NeilBrown | e8bb9a8 | 2010-06-01 19:37:26 +1000 | [diff] [blame] | 2719 | md_rdev_init(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | if ((err = alloc_disk_sb(rdev))) |
| 2721 | goto abort_free; |
| 2722 | |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 2723 | err = lock_rdev(rdev, newdev, super_format == -2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | if (err) |
| 2725 | goto abort_free; |
| 2726 | |
Greg Kroah-Hartman | f9cb074 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 2727 | kobject_init(&rdev->kobj, &rdev_ktype); |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 2728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
| 2730 | if (!size) { |
| 2731 | printk(KERN_WARNING |
| 2732 | "md: %s has zero or unknown size, marking faulty!\n", |
| 2733 | bdevname(rdev->bdev,b)); |
| 2734 | err = -EINVAL; |
| 2735 | goto abort_free; |
| 2736 | } |
| 2737 | |
| 2738 | if (super_format >= 0) { |
| 2739 | err = super_types[super_format]. |
| 2740 | load_super(rdev, NULL, super_minor); |
| 2741 | if (err == -EINVAL) { |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 2742 | printk(KERN_WARNING |
| 2743 | "md: %s does not have a valid v%d.%d " |
| 2744 | "superblock, not importing!\n", |
| 2745 | bdevname(rdev->bdev,b), |
| 2746 | super_format, super_minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | goto abort_free; |
| 2748 | } |
| 2749 | if (err < 0) { |
| 2750 | printk(KERN_WARNING |
| 2751 | "md: could not read %s's sb, not importing!\n", |
| 2752 | bdevname(rdev->bdev,b)); |
| 2753 | goto abort_free; |
| 2754 | } |
| 2755 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | return rdev; |
| 2758 | |
| 2759 | abort_free: |
| 2760 | if (rdev->sb_page) { |
| 2761 | if (rdev->bdev) |
| 2762 | unlock_rdev(rdev); |
| 2763 | free_disk_sb(rdev); |
| 2764 | } |
| 2765 | kfree(rdev); |
| 2766 | return ERR_PTR(err); |
| 2767 | } |
| 2768 | |
| 2769 | /* |
| 2770 | * Check a full RAID array for plausibility |
| 2771 | */ |
| 2772 | |
| 2773 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 2774 | static void analyze_sbs(mddev_t * mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | { |
| 2776 | int i; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2777 | mdk_rdev_t *rdev, *freshest, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | char b[BDEVNAME_SIZE]; |
| 2779 | |
| 2780 | freshest = NULL; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2781 | rdev_for_each(rdev, tmp, mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | switch (super_types[mddev->major_version]. |
| 2783 | load_super(rdev, freshest, mddev->minor_version)) { |
| 2784 | case 1: |
| 2785 | freshest = rdev; |
| 2786 | break; |
| 2787 | case 0: |
| 2788 | break; |
| 2789 | default: |
| 2790 | printk( KERN_ERR \ |
| 2791 | "md: fatal superblock inconsistency in %s" |
| 2792 | " -- removing from array\n", |
| 2793 | bdevname(rdev->bdev,b)); |
| 2794 | kick_rdev_from_array(rdev); |
| 2795 | } |
| 2796 | |
| 2797 | |
| 2798 | super_types[mddev->major_version]. |
| 2799 | validate_super(mddev, freshest); |
| 2800 | |
| 2801 | i = 0; |
NeilBrown | d089c6a | 2008-02-06 01:39:59 -0800 | [diff] [blame] | 2802 | rdev_for_each(rdev, tmp, mddev) { |
NeilBrown | 233fca3 | 2010-04-14 17:02:09 +1000 | [diff] [blame] | 2803 | if (mddev->max_disks && |
| 2804 | (rdev->desc_nr >= mddev->max_disks || |
| 2805 | i > mddev->max_disks)) { |
NeilBrown | de01dfa | 2009-02-06 18:02:46 +1100 | [diff] [blame] | 2806 | printk(KERN_WARNING |
| 2807 | "md: %s: %s: only %d devices permitted\n", |
| 2808 | mdname(mddev), bdevname(rdev->bdev, b), |
| 2809 | mddev->max_disks); |
| 2810 | kick_rdev_from_array(rdev); |
| 2811 | continue; |
| 2812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | if (rdev != freshest) |
| 2814 | if (super_types[mddev->major_version]. |
| 2815 | validate_super(mddev, rdev)) { |
| 2816 | printk(KERN_WARNING "md: kicking non-fresh %s" |
| 2817 | " from array!\n", |
| 2818 | bdevname(rdev->bdev,b)); |
| 2819 | kick_rdev_from_array(rdev); |
| 2820 | continue; |
| 2821 | } |
| 2822 | if (mddev->level == LEVEL_MULTIPATH) { |
| 2823 | rdev->desc_nr = i++; |
| 2824 | rdev->raid_disk = rdev->desc_nr; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2825 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 2826 | } else if (rdev->raid_disk >= (mddev->raid_disks - min(0, mddev->delta_disks))) { |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 2827 | rdev->raid_disk = -1; |
| 2828 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | } |
| 2830 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
NeilBrown | 72e0207 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2833 | /* Read a fixed-point number. |
| 2834 | * Numbers in sysfs attributes should be in "standard" units where |
| 2835 | * possible, so time should be in seconds. |
| 2836 | * However we internally use a a much smaller unit such as |
| 2837 | * milliseconds or jiffies. |
| 2838 | * This function takes a decimal number with a possible fractional |
| 2839 | * component, and produces an integer which is the result of |
| 2840 | * multiplying that number by 10^'scale'. |
| 2841 | * all without any floating-point arithmetic. |
| 2842 | */ |
| 2843 | int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale) |
| 2844 | { |
| 2845 | unsigned long result = 0; |
| 2846 | long decimals = -1; |
| 2847 | while (isdigit(*cp) || (*cp == '.' && decimals < 0)) { |
| 2848 | if (*cp == '.') |
| 2849 | decimals = 0; |
| 2850 | else if (decimals < scale) { |
| 2851 | unsigned int value; |
| 2852 | value = *cp - '0'; |
| 2853 | result = result * 10 + value; |
| 2854 | if (decimals >= 0) |
| 2855 | decimals++; |
| 2856 | } |
| 2857 | cp++; |
| 2858 | } |
| 2859 | if (*cp == '\n') |
| 2860 | cp++; |
| 2861 | if (*cp) |
| 2862 | return -EINVAL; |
| 2863 | if (decimals < 0) |
| 2864 | decimals = 0; |
| 2865 | while (decimals < scale) { |
| 2866 | result *= 10; |
| 2867 | decimals ++; |
| 2868 | } |
| 2869 | *res = result; |
| 2870 | return 0; |
| 2871 | } |
| 2872 | |
| 2873 | |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2874 | static void md_safemode_timeout(unsigned long data); |
| 2875 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2876 | static ssize_t |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2877 | safe_delay_show(mddev_t *mddev, char *page) |
| 2878 | { |
| 2879 | int msec = (mddev->safemode_delay*1000)/HZ; |
| 2880 | return sprintf(page, "%d.%03d\n", msec/1000, msec%1000); |
| 2881 | } |
| 2882 | static ssize_t |
| 2883 | safe_delay_store(mddev_t *mddev, const char *cbuf, size_t len) |
| 2884 | { |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2885 | unsigned long msec; |
Dan Williams | 97ce0a7 | 2008-09-24 22:48:19 -0700 | [diff] [blame] | 2886 | |
NeilBrown | 72e0207 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2887 | if (strict_strtoul_scaled(cbuf, &msec, 3) < 0) |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2888 | return -EINVAL; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2889 | if (msec == 0) |
| 2890 | mddev->safemode_delay = 0; |
| 2891 | else { |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2892 | unsigned long old_delay = mddev->safemode_delay; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2893 | mddev->safemode_delay = (msec*HZ)/1000; |
| 2894 | if (mddev->safemode_delay == 0) |
| 2895 | mddev->safemode_delay = 1; |
NeilBrown | 19052c0 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 2896 | if (mddev->safemode_delay < old_delay) |
| 2897 | md_safemode_timeout((unsigned long)mddev); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 2898 | } |
| 2899 | return len; |
| 2900 | } |
| 2901 | static struct md_sysfs_entry md_safe_delay = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 2902 | __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] | 2903 | |
| 2904 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 2905 | level_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2906 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2907 | struct mdk_personality *p = mddev->pers; |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2908 | if (p) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2909 | return sprintf(page, "%s\n", p->name); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2910 | else if (mddev->clevel[0]) |
| 2911 | return sprintf(page, "%s\n", mddev->clevel); |
| 2912 | else if (mddev->level != LEVEL_NONE) |
| 2913 | return sprintf(page, "%d\n", mddev->level); |
| 2914 | else |
| 2915 | return 0; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 2916 | } |
| 2917 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2918 | static ssize_t |
| 2919 | level_store(mddev_t *mddev, const char *buf, size_t len) |
| 2920 | { |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2921 | char clevel[16]; |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 2922 | ssize_t rv = len; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2923 | struct mdk_personality *pers; |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2924 | long level; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2925 | void *priv; |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 2926 | mdk_rdev_t *rdev; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2927 | |
| 2928 | if (mddev->pers == NULL) { |
| 2929 | if (len == 0) |
| 2930 | return 0; |
| 2931 | if (len >= sizeof(mddev->clevel)) |
| 2932 | return -ENOSPC; |
| 2933 | strncpy(mddev->clevel, buf, len); |
| 2934 | if (mddev->clevel[len-1] == '\n') |
| 2935 | len--; |
| 2936 | mddev->clevel[len] = 0; |
| 2937 | mddev->level = LEVEL_NONE; |
| 2938 | return rv; |
| 2939 | } |
| 2940 | |
| 2941 | /* request to change the personality. Need to ensure: |
| 2942 | * - array is not engaged in resync/recovery/reshape |
| 2943 | * - old personality can be suspended |
| 2944 | * - new personality will access other array. |
| 2945 | */ |
| 2946 | |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 2947 | if (mddev->sync_thread || |
| 2948 | mddev->reshape_position != MaxSector || |
| 2949 | mddev->sysfs_active) |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2950 | return -EBUSY; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2951 | |
| 2952 | if (!mddev->pers->quiesce) { |
| 2953 | printk(KERN_WARNING "md: %s: %s does not support online personality change\n", |
| 2954 | mdname(mddev), mddev->pers->name); |
| 2955 | return -EINVAL; |
| 2956 | } |
| 2957 | |
| 2958 | /* Now find the new personality */ |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2959 | if (len == 0 || len >= sizeof(clevel)) |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2960 | return -EINVAL; |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2961 | strncpy(clevel, buf, len); |
| 2962 | if (clevel[len-1] == '\n') |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2963 | len--; |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2964 | clevel[len] = 0; |
| 2965 | if (strict_strtol(clevel, 10, &level)) |
| 2966 | level = LEVEL_NONE; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2967 | |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2968 | if (request_module("md-%s", clevel) != 0) |
| 2969 | request_module("md-level-%s", clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2970 | spin_lock(&pers_lock); |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2971 | pers = find_pers(level, clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2972 | if (!pers || !try_module_get(pers->owner)) { |
| 2973 | spin_unlock(&pers_lock); |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2974 | printk(KERN_WARNING "md: personality %s not loaded\n", clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2975 | return -EINVAL; |
| 2976 | } |
| 2977 | spin_unlock(&pers_lock); |
| 2978 | |
| 2979 | if (pers == mddev->pers) { |
| 2980 | /* Nothing to do! */ |
| 2981 | module_put(pers->owner); |
| 2982 | return rv; |
| 2983 | } |
| 2984 | if (!pers->takeover) { |
| 2985 | module_put(pers->owner); |
| 2986 | printk(KERN_WARNING "md: %s: %s does not support personality takeover\n", |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 2987 | mdname(mddev), clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2988 | return -EINVAL; |
| 2989 | } |
| 2990 | |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 2991 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 2992 | rdev->new_raid_disk = rdev->raid_disk; |
| 2993 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2994 | /* ->takeover must set new_* and/or delta_disks |
| 2995 | * if it succeeds, and may set them when it fails. |
| 2996 | */ |
| 2997 | priv = pers->takeover(mddev); |
| 2998 | if (IS_ERR(priv)) { |
| 2999 | mddev->new_level = mddev->level; |
| 3000 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3001 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3002 | mddev->raid_disks -= mddev->delta_disks; |
| 3003 | mddev->delta_disks = 0; |
| 3004 | module_put(pers->owner); |
| 3005 | printk(KERN_WARNING "md: %s: %s would not accept array\n", |
Dan Williams | f2859af | 2010-05-02 10:04:16 -0700 | [diff] [blame] | 3006 | mdname(mddev), clevel); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3007 | return PTR_ERR(priv); |
| 3008 | } |
| 3009 | |
| 3010 | /* Looks like we have a winner */ |
| 3011 | mddev_suspend(mddev); |
| 3012 | mddev->pers->stop(mddev); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 3013 | |
| 3014 | if (mddev->pers->sync_request == NULL && |
| 3015 | pers->sync_request != NULL) { |
| 3016 | /* need to add the md_redundancy_group */ |
| 3017 | if (sysfs_create_group(&mddev->kobj, &md_redundancy_group)) |
| 3018 | printk(KERN_WARNING |
| 3019 | "md: cannot register extra attributes for %s\n", |
| 3020 | mdname(mddev)); |
NeilBrown | 19fdb9e | 2010-05-22 08:31:36 +1000 | [diff] [blame] | 3021 | mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, NULL, "sync_action"); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 3022 | } |
| 3023 | if (mddev->pers->sync_request != NULL && |
| 3024 | pers->sync_request == NULL) { |
| 3025 | /* need to remove the md_redundancy_group */ |
| 3026 | if (mddev->to_remove == NULL) |
| 3027 | mddev->to_remove = &md_redundancy_group; |
| 3028 | } |
| 3029 | |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 3030 | if (mddev->pers->sync_request == NULL && |
| 3031 | mddev->external) { |
| 3032 | /* We are converting from a no-redundancy array |
| 3033 | * to a redundancy array and metadata is managed |
| 3034 | * externally so we need to be sure that writes |
| 3035 | * won't block due to a need to transition |
| 3036 | * clean->dirty |
| 3037 | * until external management is started. |
| 3038 | */ |
| 3039 | mddev->in_sync = 0; |
| 3040 | mddev->safemode_delay = 0; |
| 3041 | mddev->safemode = 0; |
| 3042 | } |
| 3043 | |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3044 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 3045 | char nm[20]; |
| 3046 | if (rdev->raid_disk < 0) |
| 3047 | continue; |
| 3048 | if (rdev->new_raid_disk > mddev->raid_disks) |
| 3049 | rdev->new_raid_disk = -1; |
| 3050 | if (rdev->new_raid_disk == rdev->raid_disk) |
| 3051 | continue; |
| 3052 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 3053 | sysfs_remove_link(&mddev->kobj, nm); |
| 3054 | } |
| 3055 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 3056 | if (rdev->raid_disk < 0) |
| 3057 | continue; |
| 3058 | if (rdev->new_raid_disk == rdev->raid_disk) |
| 3059 | continue; |
| 3060 | rdev->raid_disk = rdev->new_raid_disk; |
| 3061 | if (rdev->raid_disk < 0) |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 3062 | clear_bit(In_sync, &rdev->flags); |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3063 | else { |
| 3064 | char nm[20]; |
| 3065 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 3066 | if(sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) |
| 3067 | printk("md: cannot register %s for %s after level change\n", |
| 3068 | nm, mdname(mddev)); |
NeilBrown | 3a981b0 | 2009-08-03 10:59:55 +1000 | [diff] [blame] | 3069 | } |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | module_put(mddev->pers->owner); |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3073 | mddev->pers = pers; |
| 3074 | mddev->private = priv; |
| 3075 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
| 3076 | mddev->level = mddev->new_level; |
| 3077 | mddev->layout = mddev->new_layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3078 | mddev->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3079 | mddev->delta_disks = 0; |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 3080 | if (mddev->pers->sync_request == NULL) { |
| 3081 | /* this is now an array without redundancy, so |
| 3082 | * it must always be in_sync |
| 3083 | */ |
| 3084 | mddev->in_sync = 1; |
| 3085 | del_timer_sync(&mddev->safemode_timer); |
| 3086 | } |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3087 | pers->run(mddev); |
| 3088 | mddev_resume(mddev); |
| 3089 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 3090 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3091 | md_wakeup_thread(mddev->thread); |
Maciej Trela | 5cac7861 | 2010-04-14 17:17:39 +1000 | [diff] [blame] | 3092 | sysfs_notify(&mddev->kobj, NULL, "level"); |
Dan Williams | bb7f8d2 | 2010-05-01 18:14:57 -0700 | [diff] [blame] | 3093 | md_new_event(mddev); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3094 | return rv; |
| 3095 | } |
| 3096 | |
| 3097 | static struct md_sysfs_entry md_level = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3098 | __ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3099 | |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3100 | |
| 3101 | static ssize_t |
| 3102 | layout_show(mddev_t *mddev, char *page) |
| 3103 | { |
| 3104 | /* just a number, not meaningful for all levels */ |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3105 | if (mddev->reshape_position != MaxSector && |
| 3106 | mddev->layout != mddev->new_layout) |
| 3107 | return sprintf(page, "%d (%d)\n", |
| 3108 | mddev->new_layout, mddev->layout); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3109 | return sprintf(page, "%d\n", mddev->layout); |
| 3110 | } |
| 3111 | |
| 3112 | static ssize_t |
| 3113 | layout_store(mddev_t *mddev, const char *buf, size_t len) |
| 3114 | { |
| 3115 | char *e; |
| 3116 | unsigned long n = simple_strtoul(buf, &e, 10); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3117 | |
| 3118 | if (!*buf || (*e && *e != '\n')) |
| 3119 | return -EINVAL; |
| 3120 | |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3121 | if (mddev->pers) { |
| 3122 | int err; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3123 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3124 | return -EBUSY; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3125 | mddev->new_layout = n; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3126 | err = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3127 | if (err) { |
| 3128 | mddev->new_layout = mddev->layout; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3129 | return err; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3130 | } |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3131 | } else { |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3132 | mddev->new_layout = n; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3133 | if (mddev->reshape_position == MaxSector) |
| 3134 | mddev->layout = n; |
| 3135 | } |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3136 | return len; |
| 3137 | } |
| 3138 | static struct md_sysfs_entry md_layout = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3139 | __ATTR(layout, S_IRUGO|S_IWUSR, layout_show, layout_store); |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 3140 | |
| 3141 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3142 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3143 | raid_disks_show(mddev_t *mddev, char *page) |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3144 | { |
NeilBrown | bb63654 | 2005-11-08 21:39:45 -0800 | [diff] [blame] | 3145 | if (mddev->raid_disks == 0) |
| 3146 | return 0; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3147 | if (mddev->reshape_position != MaxSector && |
| 3148 | mddev->delta_disks != 0) |
| 3149 | return sprintf(page, "%d (%d)\n", mddev->raid_disks, |
| 3150 | mddev->raid_disks - mddev->delta_disks); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3151 | return sprintf(page, "%d\n", mddev->raid_disks); |
| 3152 | } |
| 3153 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3154 | static int update_raid_disks(mddev_t *mddev, int raid_disks); |
| 3155 | |
| 3156 | static ssize_t |
| 3157 | raid_disks_store(mddev_t *mddev, const char *buf, size_t len) |
| 3158 | { |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3159 | char *e; |
| 3160 | int rv = 0; |
| 3161 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3162 | |
| 3163 | if (!*buf || (*e && *e != '\n')) |
| 3164 | return -EINVAL; |
| 3165 | |
| 3166 | if (mddev->pers) |
| 3167 | rv = update_raid_disks(mddev, n); |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3168 | else if (mddev->reshape_position != MaxSector) { |
| 3169 | int olddisks = mddev->raid_disks - mddev->delta_disks; |
| 3170 | mddev->delta_disks = n - olddisks; |
| 3171 | mddev->raid_disks = n; |
| 3172 | } else |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 3173 | mddev->raid_disks = n; |
| 3174 | return rv ? rv : len; |
| 3175 | } |
| 3176 | static struct md_sysfs_entry md_raid_disks = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3177 | __ATTR(raid_disks, S_IRUGO|S_IWUSR, raid_disks_show, raid_disks_store); |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 3178 | |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3179 | static ssize_t |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3180 | chunk_size_show(mddev_t *mddev, char *page) |
| 3181 | { |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3182 | if (mddev->reshape_position != MaxSector && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3183 | mddev->chunk_sectors != mddev->new_chunk_sectors) |
| 3184 | return sprintf(page, "%d (%d)\n", |
| 3185 | mddev->new_chunk_sectors << 9, |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3186 | mddev->chunk_sectors << 9); |
| 3187 | return sprintf(page, "%d\n", mddev->chunk_sectors << 9); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3188 | } |
| 3189 | |
| 3190 | static ssize_t |
| 3191 | chunk_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 3192 | { |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3193 | char *e; |
| 3194 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3195 | |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3196 | if (!*buf || (*e && *e != '\n')) |
| 3197 | return -EINVAL; |
| 3198 | |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3199 | if (mddev->pers) { |
| 3200 | int err; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3201 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3202 | return -EBUSY; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3203 | mddev->new_chunk_sectors = n >> 9; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 3204 | err = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3205 | if (err) { |
| 3206 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3207 | return err; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 3208 | } |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3209 | } else { |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3210 | mddev->new_chunk_sectors = n >> 9; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3211 | if (mddev->reshape_position == MaxSector) |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3212 | mddev->chunk_sectors = n >> 9; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 3213 | } |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3214 | return len; |
| 3215 | } |
| 3216 | static struct md_sysfs_entry md_chunk_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3217 | __ATTR(chunk_size, S_IRUGO|S_IWUSR, chunk_size_show, chunk_size_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3218 | |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3219 | static ssize_t |
| 3220 | resync_start_show(mddev_t *mddev, char *page) |
| 3221 | { |
NeilBrown | d1a7c50 | 2009-03-31 15:24:32 +1100 | [diff] [blame] | 3222 | if (mddev->recovery_cp == MaxSector) |
| 3223 | return sprintf(page, "none\n"); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3224 | return sprintf(page, "%llu\n", (unsigned long long)mddev->recovery_cp); |
| 3225 | } |
| 3226 | |
| 3227 | static ssize_t |
| 3228 | resync_start_store(mddev_t *mddev, const char *buf, size_t len) |
| 3229 | { |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3230 | char *e; |
| 3231 | unsigned long long n = simple_strtoull(buf, &e, 10); |
| 3232 | |
| 3233 | if (mddev->pers) |
| 3234 | return -EBUSY; |
Dan Williams | 06e3c81 | 2009-12-12 21:17:12 -0700 | [diff] [blame] | 3235 | if (cmd_match(buf, "none")) |
| 3236 | n = MaxSector; |
| 3237 | else if (!*buf || (*e && *e != '\n')) |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3238 | return -EINVAL; |
| 3239 | |
| 3240 | mddev->recovery_cp = n; |
| 3241 | return len; |
| 3242 | } |
| 3243 | static struct md_sysfs_entry md_resync_start = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3244 | __ATTR(resync_start, S_IRUGO|S_IWUSR, resync_start_show, resync_start_store); |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 3245 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3246 | /* |
| 3247 | * The array state can be: |
| 3248 | * |
| 3249 | * clear |
| 3250 | * No devices, no size, no level |
| 3251 | * Equivalent to STOP_ARRAY ioctl |
| 3252 | * inactive |
| 3253 | * May have some settings, but array is not active |
| 3254 | * all IO results in error |
| 3255 | * When written, doesn't tear down array, but just stops it |
| 3256 | * suspended (not supported yet) |
| 3257 | * All IO requests will block. The array can be reconfigured. |
Andre Noll | 910d8cb | 2008-03-25 21:00:53 +0100 | [diff] [blame] | 3258 | * Writing this, if accepted, will block until array is quiescent |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3259 | * readonly |
| 3260 | * no resync can happen. no superblocks get written. |
| 3261 | * write requests fail |
| 3262 | * read-auto |
| 3263 | * like readonly, but behaves like 'clean' on a write request. |
| 3264 | * |
| 3265 | * clean - no pending writes, but otherwise active. |
| 3266 | * When written to inactive array, starts without resync |
| 3267 | * If a write request arrives then |
| 3268 | * if metadata is known, mark 'dirty' and switch to 'active'. |
| 3269 | * if not known, block and switch to write-pending |
| 3270 | * If written to an active array that has pending writes, then fails. |
| 3271 | * active |
| 3272 | * fully active: IO and resync can be happening. |
| 3273 | * When written to inactive array, starts with resync |
| 3274 | * |
| 3275 | * write-pending |
| 3276 | * clean, but writes are blocked waiting for 'active' to be written. |
| 3277 | * |
| 3278 | * active-idle |
| 3279 | * like active, but no writes have been seen for a while (100msec). |
| 3280 | * |
| 3281 | */ |
| 3282 | enum array_state { clear, inactive, suspended, readonly, read_auto, clean, active, |
| 3283 | write_pending, active_idle, bad_word}; |
Adrian Bunk | 0538195 | 2006-06-26 00:28:01 -0700 | [diff] [blame] | 3284 | static char *array_states[] = { |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3285 | "clear", "inactive", "suspended", "readonly", "read-auto", "clean", "active", |
| 3286 | "write-pending", "active-idle", NULL }; |
| 3287 | |
| 3288 | static int match_word(const char *word, char **list) |
| 3289 | { |
| 3290 | int n; |
| 3291 | for (n=0; list[n]; n++) |
| 3292 | if (cmd_match(word, list[n])) |
| 3293 | break; |
| 3294 | return n; |
| 3295 | } |
| 3296 | |
| 3297 | static ssize_t |
| 3298 | array_state_show(mddev_t *mddev, char *page) |
| 3299 | { |
| 3300 | enum array_state st = inactive; |
| 3301 | |
| 3302 | if (mddev->pers) |
| 3303 | switch(mddev->ro) { |
| 3304 | case 1: |
| 3305 | st = readonly; |
| 3306 | break; |
| 3307 | case 2: |
| 3308 | st = read_auto; |
| 3309 | break; |
| 3310 | case 0: |
| 3311 | if (mddev->in_sync) |
| 3312 | st = clean; |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 3313 | else if (test_bit(MD_CHANGE_PENDING, &mddev->flags)) |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3314 | st = write_pending; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3315 | else if (mddev->safemode) |
| 3316 | st = active_idle; |
| 3317 | else |
| 3318 | st = active; |
| 3319 | } |
| 3320 | else { |
| 3321 | if (list_empty(&mddev->disks) && |
| 3322 | mddev->raid_disks == 0 && |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3323 | mddev->dev_sectors == 0) |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3324 | st = clear; |
| 3325 | else |
| 3326 | st = inactive; |
| 3327 | } |
| 3328 | return sprintf(page, "%s\n", array_states[st]); |
| 3329 | } |
| 3330 | |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3331 | static int do_md_stop(mddev_t * mddev, int ro, int is_open); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 3332 | static int md_set_readonly(mddev_t * mddev, int is_open); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3333 | static int do_md_run(mddev_t * mddev); |
| 3334 | static int restart_array(mddev_t *mddev); |
| 3335 | |
| 3336 | static ssize_t |
| 3337 | array_state_store(mddev_t *mddev, const char *buf, size_t len) |
| 3338 | { |
| 3339 | int err = -EINVAL; |
| 3340 | enum array_state st = match_word(buf, array_states); |
| 3341 | switch(st) { |
| 3342 | case bad_word: |
| 3343 | break; |
| 3344 | case clear: |
| 3345 | /* stopping an active array */ |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 3346 | if (atomic_read(&mddev->openers) > 0) |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3347 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3348 | err = do_md_stop(mddev, 0, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3349 | break; |
| 3350 | case inactive: |
| 3351 | /* stopping an active array */ |
| 3352 | if (mddev->pers) { |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 3353 | if (atomic_read(&mddev->openers) > 0) |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3354 | return -EBUSY; |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3355 | err = do_md_stop(mddev, 2, 0); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3356 | } else |
| 3357 | err = 0; /* already inactive */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3358 | break; |
| 3359 | case suspended: |
| 3360 | break; /* not supported yet */ |
| 3361 | case readonly: |
| 3362 | if (mddev->pers) |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 3363 | err = md_set_readonly(mddev, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3364 | else { |
| 3365 | mddev->ro = 1; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3366 | set_disk_ro(mddev->gendisk, 1); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3367 | err = do_md_run(mddev); |
| 3368 | } |
| 3369 | break; |
| 3370 | case read_auto: |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3371 | if (mddev->pers) { |
NeilBrown | 80268ee | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 3372 | if (mddev->ro == 0) |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 3373 | err = md_set_readonly(mddev, 0); |
NeilBrown | 80268ee | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 3374 | else if (mddev->ro == 1) |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3375 | err = restart_array(mddev); |
| 3376 | if (err == 0) { |
| 3377 | mddev->ro = 2; |
| 3378 | set_disk_ro(mddev->gendisk, 0); |
| 3379 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3380 | } else { |
| 3381 | mddev->ro = 2; |
| 3382 | err = do_md_run(mddev); |
| 3383 | } |
| 3384 | break; |
| 3385 | case clean: |
| 3386 | if (mddev->pers) { |
| 3387 | restart_array(mddev); |
| 3388 | spin_lock_irq(&mddev->write_lock); |
| 3389 | if (atomic_read(&mddev->writes_pending) == 0) { |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3390 | if (mddev->in_sync == 0) { |
| 3391 | mddev->in_sync = 1; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3392 | if (mddev->safemode == 1) |
| 3393 | mddev->safemode = 0; |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 3394 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3395 | } |
| 3396 | err = 0; |
| 3397 | } else |
| 3398 | err = -EBUSY; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3399 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 5bf2959 | 2009-05-07 12:50:57 +1000 | [diff] [blame] | 3400 | } else |
| 3401 | err = -EINVAL; |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3402 | break; |
| 3403 | case active: |
| 3404 | if (mddev->pers) { |
| 3405 | restart_array(mddev); |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 3406 | clear_bit(MD_CHANGE_PENDING, &mddev->flags); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3407 | wake_up(&mddev->sb_wait); |
| 3408 | err = 0; |
| 3409 | } else { |
| 3410 | mddev->ro = 0; |
NeilBrown | 648b629 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 3411 | set_disk_ro(mddev->gendisk, 0); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3412 | err = do_md_run(mddev); |
| 3413 | } |
| 3414 | break; |
| 3415 | case write_pending: |
| 3416 | case active_idle: |
| 3417 | /* these cannot be set */ |
| 3418 | break; |
| 3419 | } |
| 3420 | if (err) |
| 3421 | return err; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3422 | else { |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 3423 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3424 | return len; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 3425 | } |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3426 | } |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3427 | static struct md_sysfs_entry md_array_state = |
| 3428 | __ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store); |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 3429 | |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3430 | static ssize_t |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 3431 | max_corrected_read_errors_show(mddev_t *mddev, char *page) { |
| 3432 | return sprintf(page, "%d\n", |
| 3433 | atomic_read(&mddev->max_corr_read_errors)); |
| 3434 | } |
| 3435 | |
| 3436 | static ssize_t |
| 3437 | max_corrected_read_errors_store(mddev_t *mddev, const char *buf, size_t len) |
| 3438 | { |
| 3439 | char *e; |
| 3440 | unsigned long n = simple_strtoul(buf, &e, 10); |
| 3441 | |
| 3442 | if (*buf && (*e == 0 || *e == '\n')) { |
| 3443 | atomic_set(&mddev->max_corr_read_errors, n); |
| 3444 | return len; |
| 3445 | } |
| 3446 | return -EINVAL; |
| 3447 | } |
| 3448 | |
| 3449 | static struct md_sysfs_entry max_corr_read_errors = |
| 3450 | __ATTR(max_read_errors, S_IRUGO|S_IWUSR, max_corrected_read_errors_show, |
| 3451 | max_corrected_read_errors_store); |
| 3452 | |
| 3453 | static ssize_t |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3454 | null_show(mddev_t *mddev, char *page) |
| 3455 | { |
| 3456 | return -EINVAL; |
| 3457 | } |
| 3458 | |
| 3459 | static ssize_t |
| 3460 | new_dev_store(mddev_t *mddev, const char *buf, size_t len) |
| 3461 | { |
| 3462 | /* buf must be %d:%d\n? giving major and minor numbers */ |
| 3463 | /* The new device is added to the array. |
| 3464 | * If the array has a persistent superblock, we read the |
| 3465 | * superblock to initialise info and check validity. |
| 3466 | * Otherwise, only checking done is that in bind_rdev_to_array, |
| 3467 | * which mainly checks size. |
| 3468 | */ |
| 3469 | char *e; |
| 3470 | int major = simple_strtoul(buf, &e, 10); |
| 3471 | int minor; |
| 3472 | dev_t dev; |
| 3473 | mdk_rdev_t *rdev; |
| 3474 | int err; |
| 3475 | |
| 3476 | if (!*buf || *e != ':' || !e[1] || e[1] == '\n') |
| 3477 | return -EINVAL; |
| 3478 | minor = simple_strtoul(e+1, &e, 10); |
| 3479 | if (*e && *e != '\n') |
| 3480 | return -EINVAL; |
| 3481 | dev = MKDEV(major, minor); |
| 3482 | if (major != MAJOR(dev) || |
| 3483 | minor != MINOR(dev)) |
| 3484 | return -EOVERFLOW; |
| 3485 | |
| 3486 | |
| 3487 | if (mddev->persistent) { |
| 3488 | rdev = md_import_device(dev, mddev->major_version, |
| 3489 | mddev->minor_version); |
| 3490 | if (!IS_ERR(rdev) && !list_empty(&mddev->disks)) { |
| 3491 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 3492 | mdk_rdev_t, same_set); |
| 3493 | err = super_types[mddev->major_version] |
| 3494 | .load_super(rdev, rdev0, mddev->minor_version); |
| 3495 | if (err < 0) |
| 3496 | goto out; |
| 3497 | } |
NeilBrown | c5d79ad | 2008-02-06 01:39:54 -0800 | [diff] [blame] | 3498 | } else if (mddev->external) |
| 3499 | rdev = md_import_device(dev, -2, -1); |
| 3500 | else |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 3501 | rdev = md_import_device(dev, -1, -1); |
| 3502 | |
| 3503 | if (IS_ERR(rdev)) |
| 3504 | return PTR_ERR(rdev); |
| 3505 | err = bind_rdev_to_array(rdev, mddev); |
| 3506 | out: |
| 3507 | if (err) |
| 3508 | export_rdev(rdev); |
| 3509 | return err ? err : len; |
| 3510 | } |
| 3511 | |
| 3512 | static struct md_sysfs_entry md_new_device = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3513 | __ATTR(new_dev, S_IWUSR, null_show, new_dev_store); |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 3514 | |
| 3515 | static ssize_t |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 3516 | bitmap_store(mddev_t *mddev, const char *buf, size_t len) |
| 3517 | { |
| 3518 | char *end; |
| 3519 | unsigned long chunk, end_chunk; |
| 3520 | |
| 3521 | if (!mddev->bitmap) |
| 3522 | goto out; |
| 3523 | /* buf should be <chunk> <chunk> ... or <chunk>-<chunk> ... (range) */ |
| 3524 | while (*buf) { |
| 3525 | chunk = end_chunk = simple_strtoul(buf, &end, 0); |
| 3526 | if (buf == end) break; |
| 3527 | if (*end == '-') { /* range */ |
| 3528 | buf = end + 1; |
| 3529 | end_chunk = simple_strtoul(buf, &end, 0); |
| 3530 | if (buf == end) break; |
| 3531 | } |
| 3532 | if (*end && !isspace(*end)) break; |
| 3533 | bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk); |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 3534 | buf = skip_spaces(end); |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 3535 | } |
| 3536 | bitmap_unplug(mddev->bitmap); /* flush the bits to disk */ |
| 3537 | out: |
| 3538 | return len; |
| 3539 | } |
| 3540 | |
| 3541 | static struct md_sysfs_entry md_bitmap = |
| 3542 | __ATTR(bitmap_set_bits, S_IWUSR, null_show, bitmap_store); |
| 3543 | |
| 3544 | static ssize_t |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3545 | size_show(mddev_t *mddev, char *page) |
| 3546 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3547 | return sprintf(page, "%llu\n", |
| 3548 | (unsigned long long)mddev->dev_sectors / 2); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3549 | } |
| 3550 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 3551 | static int update_size(mddev_t *mddev, sector_t num_sectors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3552 | |
| 3553 | static ssize_t |
| 3554 | size_store(mddev_t *mddev, const char *buf, size_t len) |
| 3555 | { |
| 3556 | /* If array is inactive, we can reduce the component size, but |
| 3557 | * not increase it (except from 0). |
| 3558 | * If array is active, we can try an on-line resize |
| 3559 | */ |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 3560 | sector_t sectors; |
| 3561 | int err = strict_blocks_to_sectors(buf, §ors); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3562 | |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3563 | if (err < 0) |
| 3564 | return err; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3565 | if (mddev->pers) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3566 | err = update_size(mddev, sectors); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 3567 | md_update_sb(mddev, 1); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3568 | } else { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3569 | if (mddev->dev_sectors == 0 || |
| 3570 | mddev->dev_sectors > sectors) |
| 3571 | mddev->dev_sectors = sectors; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3572 | else |
| 3573 | err = -ENOSPC; |
| 3574 | } |
| 3575 | return err ? err : len; |
| 3576 | } |
| 3577 | |
| 3578 | static struct md_sysfs_entry md_size = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3579 | __ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3580 | |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3581 | |
| 3582 | /* Metdata version. |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3583 | * This is one of |
| 3584 | * 'none' for arrays with no metadata (good luck...) |
| 3585 | * 'external' for arrays with externally managed metadata, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3586 | * or N.M for internally known formats |
| 3587 | */ |
| 3588 | static ssize_t |
| 3589 | metadata_show(mddev_t *mddev, char *page) |
| 3590 | { |
| 3591 | if (mddev->persistent) |
| 3592 | return sprintf(page, "%d.%d\n", |
| 3593 | mddev->major_version, mddev->minor_version); |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3594 | else if (mddev->external) |
| 3595 | return sprintf(page, "external:%s\n", mddev->metadata_type); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3596 | else |
| 3597 | return sprintf(page, "none\n"); |
| 3598 | } |
| 3599 | |
| 3600 | static ssize_t |
| 3601 | metadata_store(mddev_t *mddev, const char *buf, size_t len) |
| 3602 | { |
| 3603 | int major, minor; |
| 3604 | char *e; |
NeilBrown | ea43ddd | 2008-10-13 11:55:11 +1100 | [diff] [blame] | 3605 | /* Changing the details of 'external' metadata is |
| 3606 | * always permitted. Otherwise there must be |
| 3607 | * no devices attached to the array. |
| 3608 | */ |
| 3609 | if (mddev->external && strncmp(buf, "external:", 9) == 0) |
| 3610 | ; |
| 3611 | else if (!list_empty(&mddev->disks)) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3612 | return -EBUSY; |
| 3613 | |
| 3614 | if (cmd_match(buf, "none")) { |
| 3615 | mddev->persistent = 0; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3616 | mddev->external = 0; |
| 3617 | mddev->major_version = 0; |
| 3618 | mddev->minor_version = 90; |
| 3619 | return len; |
| 3620 | } |
| 3621 | if (strncmp(buf, "external:", 9) == 0) { |
NeilBrown | 20a49ff | 2008-02-06 01:39:57 -0800 | [diff] [blame] | 3622 | size_t namelen = len-9; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3623 | if (namelen >= sizeof(mddev->metadata_type)) |
| 3624 | namelen = sizeof(mddev->metadata_type)-1; |
| 3625 | strncpy(mddev->metadata_type, buf+9, namelen); |
| 3626 | mddev->metadata_type[namelen] = 0; |
| 3627 | if (namelen && mddev->metadata_type[namelen-1] == '\n') |
| 3628 | mddev->metadata_type[--namelen] = 0; |
| 3629 | mddev->persistent = 0; |
| 3630 | mddev->external = 1; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3631 | mddev->major_version = 0; |
| 3632 | mddev->minor_version = 90; |
| 3633 | return len; |
| 3634 | } |
| 3635 | major = simple_strtoul(buf, &e, 10); |
| 3636 | if (e==buf || *e != '.') |
| 3637 | return -EINVAL; |
| 3638 | buf = e+1; |
| 3639 | minor = simple_strtoul(buf, &e, 10); |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 3640 | if (e==buf || (*e && *e != '\n') ) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3641 | return -EINVAL; |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 3642 | if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL) |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3643 | return -ENOENT; |
| 3644 | mddev->major_version = major; |
| 3645 | mddev->minor_version = minor; |
| 3646 | mddev->persistent = 1; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 3647 | mddev->external = 0; |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3648 | return len; |
| 3649 | } |
| 3650 | |
| 3651 | static struct md_sysfs_entry md_metadata = |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3652 | __ATTR(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store); |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 3653 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 3654 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3655 | action_show(mddev_t *mddev, char *page) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3656 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3657 | char *type = "idle"; |
NeilBrown | b6a9ce6 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 3658 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 3659 | type = "frozen"; |
| 3660 | else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
NeilBrown | 2b12ab6 | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 3661 | (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3662 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 3663 | type = "reshape"; |
| 3664 | else if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3665 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 3666 | type = "resync"; |
| 3667 | else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 3668 | type = "check"; |
| 3669 | else |
| 3670 | type = "repair"; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3671 | } else if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3672 | type = "recover"; |
| 3673 | } |
| 3674 | return sprintf(page, "%s\n", type); |
| 3675 | } |
| 3676 | |
| 3677 | static ssize_t |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3678 | action_store(mddev_t *mddev, const char *page, size_t len) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3679 | { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3680 | if (!mddev->pers || !mddev->pers->sync_request) |
| 3681 | return -EINVAL; |
| 3682 | |
NeilBrown | b6a9ce6 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 3683 | if (cmd_match(page, "frozen")) |
| 3684 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3685 | else |
| 3686 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3687 | |
| 3688 | if (cmd_match(page, "idle") || cmd_match(page, "frozen")) { |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3689 | if (mddev->sync_thread) { |
| 3690 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 3691 | md_unregister_thread(mddev->sync_thread); |
| 3692 | mddev->sync_thread = NULL; |
| 3693 | mddev->recovery = 0; |
| 3694 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3695 | } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 3696 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3697 | return -EBUSY; |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3698 | else if (cmd_match(page, "resync")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3699 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 3700 | else if (cmd_match(page, "recover")) { |
| 3701 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
| 3702 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 3703 | } else if (cmd_match(page, "reshape")) { |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3704 | int err; |
| 3705 | if (mddev->pers->start_reshape == NULL) |
| 3706 | return -EINVAL; |
| 3707 | err = mddev->pers->start_reshape(mddev); |
| 3708 | if (err) |
| 3709 | return err; |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 3710 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
NeilBrown | 16484bf | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 3711 | } else { |
NeilBrown | bce74da | 2006-01-06 00:20:41 -0800 | [diff] [blame] | 3712 | if (cmd_match(page, "check")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3713 | set_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
NeilBrown | 2adc7d4 | 2006-05-20 14:59:57 -0700 | [diff] [blame] | 3714 | else if (!cmd_match(page, "repair")) |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3715 | return -EINVAL; |
| 3716 | set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
| 3717 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
NeilBrown | 7eec314 | 2005-11-08 21:39:44 -0800 | [diff] [blame] | 3718 | } |
NeilBrown | 03c902e | 2006-01-06 00:20:46 -0800 | [diff] [blame] | 3719 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3720 | md_wakeup_thread(mddev->thread); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 3721 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3722 | return len; |
| 3723 | } |
| 3724 | |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3725 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3726 | mismatch_cnt_show(mddev_t *mddev, char *page) |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3727 | { |
| 3728 | return sprintf(page, "%llu\n", |
| 3729 | (unsigned long long) mddev->resync_mismatches); |
| 3730 | } |
| 3731 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3732 | static struct md_sysfs_entry md_scan_mode = |
| 3733 | __ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3734 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 3735 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3736 | static struct md_sysfs_entry md_mismatches = __ATTR_RO(mismatch_cnt); |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 3737 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3738 | static ssize_t |
| 3739 | sync_min_show(mddev_t *mddev, char *page) |
| 3740 | { |
| 3741 | return sprintf(page, "%d (%s)\n", speed_min(mddev), |
| 3742 | mddev->sync_speed_min ? "local": "system"); |
| 3743 | } |
| 3744 | |
| 3745 | static ssize_t |
| 3746 | sync_min_store(mddev_t *mddev, const char *buf, size_t len) |
| 3747 | { |
| 3748 | int min; |
| 3749 | char *e; |
| 3750 | if (strncmp(buf, "system", 6)==0) { |
| 3751 | mddev->sync_speed_min = 0; |
| 3752 | return len; |
| 3753 | } |
| 3754 | min = simple_strtoul(buf, &e, 10); |
| 3755 | if (buf == e || (*e && *e != '\n') || min <= 0) |
| 3756 | return -EINVAL; |
| 3757 | mddev->sync_speed_min = min; |
| 3758 | return len; |
| 3759 | } |
| 3760 | |
| 3761 | static struct md_sysfs_entry md_sync_min = |
| 3762 | __ATTR(sync_speed_min, S_IRUGO|S_IWUSR, sync_min_show, sync_min_store); |
| 3763 | |
| 3764 | static ssize_t |
| 3765 | sync_max_show(mddev_t *mddev, char *page) |
| 3766 | { |
| 3767 | return sprintf(page, "%d (%s)\n", speed_max(mddev), |
| 3768 | mddev->sync_speed_max ? "local": "system"); |
| 3769 | } |
| 3770 | |
| 3771 | static ssize_t |
| 3772 | sync_max_store(mddev_t *mddev, const char *buf, size_t len) |
| 3773 | { |
| 3774 | int max; |
| 3775 | char *e; |
| 3776 | if (strncmp(buf, "system", 6)==0) { |
| 3777 | mddev->sync_speed_max = 0; |
| 3778 | return len; |
| 3779 | } |
| 3780 | max = simple_strtoul(buf, &e, 10); |
| 3781 | if (buf == e || (*e && *e != '\n') || max <= 0) |
| 3782 | return -EINVAL; |
| 3783 | mddev->sync_speed_max = max; |
| 3784 | return len; |
| 3785 | } |
| 3786 | |
| 3787 | static struct md_sysfs_entry md_sync_max = |
| 3788 | __ATTR(sync_speed_max, S_IRUGO|S_IWUSR, sync_max_show, sync_max_store); |
| 3789 | |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 3790 | static ssize_t |
| 3791 | degraded_show(mddev_t *mddev, char *page) |
| 3792 | { |
| 3793 | return sprintf(page, "%d\n", mddev->degraded); |
| 3794 | } |
| 3795 | static struct md_sysfs_entry md_degraded = __ATTR_RO(degraded); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3796 | |
| 3797 | static ssize_t |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 3798 | sync_force_parallel_show(mddev_t *mddev, char *page) |
| 3799 | { |
| 3800 | return sprintf(page, "%d\n", mddev->parallel_resync); |
| 3801 | } |
| 3802 | |
| 3803 | static ssize_t |
| 3804 | sync_force_parallel_store(mddev_t *mddev, const char *buf, size_t len) |
| 3805 | { |
| 3806 | long n; |
| 3807 | |
| 3808 | if (strict_strtol(buf, 10, &n)) |
| 3809 | return -EINVAL; |
| 3810 | |
| 3811 | if (n != 0 && n != 1) |
| 3812 | return -EINVAL; |
| 3813 | |
| 3814 | mddev->parallel_resync = n; |
| 3815 | |
| 3816 | if (mddev->sync_thread) |
| 3817 | wake_up(&resync_wait); |
| 3818 | |
| 3819 | return len; |
| 3820 | } |
| 3821 | |
| 3822 | /* force parallel resync, even with shared block devices */ |
| 3823 | static struct md_sysfs_entry md_sync_force_parallel = |
| 3824 | __ATTR(sync_force_parallel, S_IRUGO|S_IWUSR, |
| 3825 | sync_force_parallel_show, sync_force_parallel_store); |
| 3826 | |
| 3827 | static ssize_t |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3828 | sync_speed_show(mddev_t *mddev, char *page) |
| 3829 | { |
| 3830 | unsigned long resync, dt, db; |
NeilBrown | d1a7c50 | 2009-03-31 15:24:32 +1100 | [diff] [blame] | 3831 | if (mddev->curr_resync == 0) |
| 3832 | return sprintf(page, "none\n"); |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3833 | resync = mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active); |
| 3834 | dt = (jiffies - mddev->resync_mark) / HZ; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3835 | if (!dt) dt++; |
Andre Noll | 9687a60 | 2008-03-25 22:24:09 +0100 | [diff] [blame] | 3836 | db = resync - mddev->resync_mark_cnt; |
| 3837 | return sprintf(page, "%lu\n", db/dt/2); /* K/sec */ |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3838 | } |
| 3839 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3840 | static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3841 | |
| 3842 | static ssize_t |
| 3843 | sync_completed_show(mddev_t *mddev, char *page) |
| 3844 | { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3845 | unsigned long max_sectors, resync; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3846 | |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 3847 | if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3848 | return sprintf(page, "none\n"); |
| 3849 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3850 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3851 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3852 | else |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3853 | max_sectors = mddev->dev_sectors; |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3854 | |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 3855 | resync = mddev->curr_resync_completed; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3856 | return sprintf(page, "%lu / %lu\n", resync, max_sectors); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3857 | } |
| 3858 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 3859 | static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed); |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 3860 | |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3861 | static ssize_t |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3862 | min_sync_show(mddev_t *mddev, char *page) |
| 3863 | { |
| 3864 | return sprintf(page, "%llu\n", |
| 3865 | (unsigned long long)mddev->resync_min); |
| 3866 | } |
| 3867 | static ssize_t |
| 3868 | min_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3869 | { |
| 3870 | unsigned long long min; |
| 3871 | if (strict_strtoull(buf, 10, &min)) |
| 3872 | return -EINVAL; |
| 3873 | if (min > mddev->resync_max) |
| 3874 | return -EINVAL; |
| 3875 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3876 | return -EBUSY; |
| 3877 | |
| 3878 | /* Must be a multiple of chunk_size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3879 | if (mddev->chunk_sectors) { |
raz ben yehuda | 2ac06c3 | 2009-06-16 17:01:42 +1000 | [diff] [blame] | 3880 | sector_t temp = min; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3881 | if (sector_div(temp, mddev->chunk_sectors)) |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3882 | return -EINVAL; |
| 3883 | } |
| 3884 | mddev->resync_min = min; |
| 3885 | |
| 3886 | return len; |
| 3887 | } |
| 3888 | |
| 3889 | static struct md_sysfs_entry md_min_sync = |
| 3890 | __ATTR(sync_min, S_IRUGO|S_IWUSR, min_sync_show, min_sync_store); |
| 3891 | |
| 3892 | static ssize_t |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3893 | max_sync_show(mddev_t *mddev, char *page) |
| 3894 | { |
| 3895 | if (mddev->resync_max == MaxSector) |
| 3896 | return sprintf(page, "max\n"); |
| 3897 | else |
| 3898 | return sprintf(page, "%llu\n", |
| 3899 | (unsigned long long)mddev->resync_max); |
| 3900 | } |
| 3901 | static ssize_t |
| 3902 | max_sync_store(mddev_t *mddev, const char *buf, size_t len) |
| 3903 | { |
| 3904 | if (strncmp(buf, "max", 3) == 0) |
| 3905 | mddev->resync_max = MaxSector; |
| 3906 | else { |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 3907 | unsigned long long max; |
| 3908 | if (strict_strtoull(buf, 10, &max)) |
| 3909 | return -EINVAL; |
| 3910 | if (max < mddev->resync_min) |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3911 | return -EINVAL; |
| 3912 | if (max < mddev->resync_max && |
NeilBrown | 4d484a4 | 2009-08-13 10:41:50 +1000 | [diff] [blame] | 3913 | mddev->ro == 0 && |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3914 | test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
| 3915 | return -EBUSY; |
| 3916 | |
| 3917 | /* Must be a multiple of chunk_size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3918 | if (mddev->chunk_sectors) { |
raz ben yehuda | 2ac06c3 | 2009-06-16 17:01:42 +1000 | [diff] [blame] | 3919 | sector_t temp = max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3920 | if (sector_div(temp, mddev->chunk_sectors)) |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 3921 | return -EINVAL; |
| 3922 | } |
| 3923 | mddev->resync_max = max; |
| 3924 | } |
| 3925 | wake_up(&mddev->recovery_wait); |
| 3926 | return len; |
| 3927 | } |
| 3928 | |
| 3929 | static struct md_sysfs_entry md_max_sync = |
| 3930 | __ATTR(sync_max, S_IRUGO|S_IWUSR, max_sync_show, max_sync_store); |
| 3931 | |
| 3932 | static ssize_t |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3933 | suspend_lo_show(mddev_t *mddev, char *page) |
| 3934 | { |
| 3935 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_lo); |
| 3936 | } |
| 3937 | |
| 3938 | static ssize_t |
| 3939 | suspend_lo_store(mddev_t *mddev, const char *buf, size_t len) |
| 3940 | { |
| 3941 | char *e; |
| 3942 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 3943 | |
NeilBrown | b8d966e | 2009-07-01 11:14:04 +1000 | [diff] [blame] | 3944 | if (mddev->pers == NULL || |
| 3945 | mddev->pers->quiesce == NULL) |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3946 | return -EINVAL; |
| 3947 | if (buf == e || (*e && *e != '\n')) |
| 3948 | return -EINVAL; |
| 3949 | if (new >= mddev->suspend_hi || |
| 3950 | (new > mddev->suspend_lo && new < mddev->suspend_hi)) { |
| 3951 | mddev->suspend_lo = new; |
| 3952 | mddev->pers->quiesce(mddev, 2); |
| 3953 | return len; |
| 3954 | } else |
| 3955 | return -EINVAL; |
| 3956 | } |
| 3957 | static struct md_sysfs_entry md_suspend_lo = |
| 3958 | __ATTR(suspend_lo, S_IRUGO|S_IWUSR, suspend_lo_show, suspend_lo_store); |
| 3959 | |
| 3960 | |
| 3961 | static ssize_t |
| 3962 | suspend_hi_show(mddev_t *mddev, char *page) |
| 3963 | { |
| 3964 | return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_hi); |
| 3965 | } |
| 3966 | |
| 3967 | static ssize_t |
| 3968 | suspend_hi_store(mddev_t *mddev, const char *buf, size_t len) |
| 3969 | { |
| 3970 | char *e; |
| 3971 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 3972 | |
NeilBrown | b8d966e | 2009-07-01 11:14:04 +1000 | [diff] [blame] | 3973 | if (mddev->pers == NULL || |
| 3974 | mddev->pers->quiesce == NULL) |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3975 | return -EINVAL; |
| 3976 | if (buf == e || (*e && *e != '\n')) |
| 3977 | return -EINVAL; |
| 3978 | if ((new <= mddev->suspend_lo && mddev->suspend_lo >= mddev->suspend_hi) || |
| 3979 | (new > mddev->suspend_lo && new > mddev->suspend_hi)) { |
| 3980 | mddev->suspend_hi = new; |
| 3981 | mddev->pers->quiesce(mddev, 1); |
| 3982 | mddev->pers->quiesce(mddev, 0); |
| 3983 | return len; |
| 3984 | } else |
| 3985 | return -EINVAL; |
| 3986 | } |
| 3987 | static struct md_sysfs_entry md_suspend_hi = |
| 3988 | __ATTR(suspend_hi, S_IRUGO|S_IWUSR, suspend_hi_show, suspend_hi_store); |
| 3989 | |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 3990 | static ssize_t |
| 3991 | reshape_position_show(mddev_t *mddev, char *page) |
| 3992 | { |
| 3993 | if (mddev->reshape_position != MaxSector) |
| 3994 | return sprintf(page, "%llu\n", |
| 3995 | (unsigned long long)mddev->reshape_position); |
| 3996 | strcpy(page, "none\n"); |
| 3997 | return 5; |
| 3998 | } |
| 3999 | |
| 4000 | static ssize_t |
| 4001 | reshape_position_store(mddev_t *mddev, const char *buf, size_t len) |
| 4002 | { |
| 4003 | char *e; |
| 4004 | unsigned long long new = simple_strtoull(buf, &e, 10); |
| 4005 | if (mddev->pers) |
| 4006 | return -EBUSY; |
| 4007 | if (buf == e || (*e && *e != '\n')) |
| 4008 | return -EINVAL; |
| 4009 | mddev->reshape_position = new; |
| 4010 | mddev->delta_disks = 0; |
| 4011 | mddev->new_level = mddev->level; |
| 4012 | mddev->new_layout = mddev->layout; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4013 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 4014 | return len; |
| 4015 | } |
| 4016 | |
| 4017 | static struct md_sysfs_entry md_reshape_position = |
| 4018 | __ATTR(reshape_position, S_IRUGO|S_IWUSR, reshape_position_show, |
| 4019 | reshape_position_store); |
| 4020 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4021 | static ssize_t |
| 4022 | array_size_show(mddev_t *mddev, char *page) |
| 4023 | { |
| 4024 | if (mddev->external_size) |
| 4025 | return sprintf(page, "%llu\n", |
| 4026 | (unsigned long long)mddev->array_sectors/2); |
| 4027 | else |
| 4028 | return sprintf(page, "default\n"); |
| 4029 | } |
| 4030 | |
| 4031 | static ssize_t |
| 4032 | array_size_store(mddev_t *mddev, const char *buf, size_t len) |
| 4033 | { |
| 4034 | sector_t sectors; |
| 4035 | |
| 4036 | if (strncmp(buf, "default", 7) == 0) { |
| 4037 | if (mddev->pers) |
| 4038 | sectors = mddev->pers->size(mddev, 0, 0); |
| 4039 | else |
| 4040 | sectors = mddev->array_sectors; |
| 4041 | |
| 4042 | mddev->external_size = 0; |
| 4043 | } else { |
| 4044 | if (strict_blocks_to_sectors(buf, §ors) < 0) |
| 4045 | return -EINVAL; |
| 4046 | if (mddev->pers && mddev->pers->size(mddev, 0, 0) < sectors) |
NeilBrown | 2b69c83 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 4047 | return -E2BIG; |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4048 | |
| 4049 | mddev->external_size = 1; |
| 4050 | } |
| 4051 | |
| 4052 | mddev->array_sectors = sectors; |
| 4053 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4054 | if (mddev->pers) |
| 4055 | revalidate_disk(mddev->gendisk); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4056 | |
| 4057 | return len; |
| 4058 | } |
| 4059 | |
| 4060 | static struct md_sysfs_entry md_array_size = |
| 4061 | __ATTR(array_size, S_IRUGO|S_IWUSR, array_size_show, |
| 4062 | array_size_store); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4063 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4064 | static struct attribute *md_default_attrs[] = { |
| 4065 | &md_level.attr, |
NeilBrown | d4dbd02 | 2006-06-26 00:27:59 -0700 | [diff] [blame] | 4066 | &md_layout.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4067 | &md_raid_disks.attr, |
NeilBrown | 3b34380 | 2006-01-06 00:20:47 -0800 | [diff] [blame] | 4068 | &md_chunk_size.attr, |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 4069 | &md_size.attr, |
NeilBrown | a94213b | 2006-06-26 00:28:00 -0700 | [diff] [blame] | 4070 | &md_resync_start.attr, |
NeilBrown | 8bb93aa | 2006-01-06 00:20:50 -0800 | [diff] [blame] | 4071 | &md_metadata.attr, |
NeilBrown | 6d7ff738 | 2006-01-06 00:21:16 -0800 | [diff] [blame] | 4072 | &md_new_device.attr, |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 4073 | &md_safe_delay.attr, |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4074 | &md_array_state.attr, |
NeilBrown | 08a02ec | 2007-05-09 02:35:38 -0700 | [diff] [blame] | 4075 | &md_reshape_position.attr, |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4076 | &md_array_size.attr, |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 4077 | &max_corr_read_errors.attr, |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 4078 | NULL, |
| 4079 | }; |
| 4080 | |
| 4081 | static struct attribute *md_redundancy_attrs[] = { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 4082 | &md_scan_mode.attr, |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 4083 | &md_mismatches.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 4084 | &md_sync_min.attr, |
| 4085 | &md_sync_max.attr, |
| 4086 | &md_sync_speed.attr, |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 4087 | &md_sync_force_parallel.attr, |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 4088 | &md_sync_completed.attr, |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 4089 | &md_min_sync.attr, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4090 | &md_max_sync.attr, |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4091 | &md_suspend_lo.attr, |
| 4092 | &md_suspend_hi.attr, |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 4093 | &md_bitmap.attr, |
Iustin Pop | d7f3d29 | 2007-10-16 23:30:54 -0700 | [diff] [blame] | 4094 | &md_degraded.attr, |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4095 | NULL, |
| 4096 | }; |
NeilBrown | 411036f | 2005-11-08 21:39:40 -0800 | [diff] [blame] | 4097 | static struct attribute_group md_redundancy_group = { |
| 4098 | .name = NULL, |
| 4099 | .attrs = md_redundancy_attrs, |
| 4100 | }; |
| 4101 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4102 | |
| 4103 | static ssize_t |
| 4104 | md_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 4105 | { |
| 4106 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 4107 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4108 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4109 | |
| 4110 | if (!entry->show) |
| 4111 | return -EIO; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4112 | rv = mddev_lock(mddev); |
| 4113 | if (!rv) { |
| 4114 | rv = entry->show(mddev, page); |
| 4115 | mddev_unlock(mddev); |
| 4116 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4117 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | static ssize_t |
| 4121 | md_attr_store(struct kobject *kobj, struct attribute *attr, |
| 4122 | const char *page, size_t length) |
| 4123 | { |
| 4124 | struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr); |
| 4125 | mddev_t *mddev = container_of(kobj, struct mddev_s, kobj); |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4126 | ssize_t rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4127 | |
| 4128 | if (!entry->store) |
| 4129 | return -EIO; |
NeilBrown | 67463ac | 2006-07-10 04:44:19 -0700 | [diff] [blame] | 4130 | if (!capable(CAP_SYS_ADMIN)) |
| 4131 | return -EACCES; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4132 | rv = mddev_lock(mddev); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4133 | if (mddev->hold_active == UNTIL_IOCTL) |
| 4134 | mddev->hold_active = 0; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 4135 | if (!rv) { |
| 4136 | rv = entry->store(mddev, page, length); |
| 4137 | mddev_unlock(mddev); |
| 4138 | } |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4139 | return rv; |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | static void md_free(struct kobject *ko) |
| 4143 | { |
| 4144 | mddev_t *mddev = container_of(ko, mddev_t, kobj); |
NeilBrown | a21d150 | 2009-01-09 08:31:09 +1100 | [diff] [blame] | 4145 | |
| 4146 | if (mddev->sysfs_state) |
| 4147 | sysfs_put(mddev->sysfs_state); |
| 4148 | |
| 4149 | if (mddev->gendisk) { |
| 4150 | del_gendisk(mddev->gendisk); |
| 4151 | put_disk(mddev->gendisk); |
| 4152 | } |
| 4153 | if (mddev->queue) |
| 4154 | blk_cleanup_queue(mddev->queue); |
| 4155 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4156 | kfree(mddev); |
| 4157 | } |
| 4158 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 4159 | static const struct sysfs_ops md_sysfs_ops = { |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 4160 | .show = md_attr_show, |
| 4161 | .store = md_attr_store, |
| 4162 | }; |
| 4163 | static struct kobj_type md_ktype = { |
| 4164 | .release = md_free, |
| 4165 | .sysfs_ops = &md_sysfs_ops, |
| 4166 | .default_attrs = md_default_attrs, |
| 4167 | }; |
| 4168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | int mdp_major = 0; |
| 4170 | |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 4171 | static void mddev_delayed_delete(struct work_struct *ws) |
| 4172 | { |
| 4173 | mddev_t *mddev = container_of(ws, mddev_t, del_work); |
| 4174 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 4175 | sysfs_remove_group(&mddev->kobj, &md_bitmap_group); |
Dan Williams | 5fd3a17 | 2009-03-04 00:57:25 -0700 | [diff] [blame] | 4176 | kobject_del(&mddev->kobj); |
| 4177 | kobject_put(&mddev->kobj); |
| 4178 | } |
| 4179 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4180 | static int md_alloc(dev_t dev, char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | { |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 4182 | static DEFINE_MUTEX(disks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | mddev_t *mddev = mddev_find(dev); |
| 4184 | struct gendisk *disk; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4185 | int partitioned; |
| 4186 | int shift; |
| 4187 | int unit; |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 4188 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | |
| 4190 | if (!mddev) |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4191 | return -ENODEV; |
| 4192 | |
| 4193 | partitioned = (MAJOR(mddev->unit) != MD_MAJOR); |
| 4194 | shift = partitioned ? MdpMinorShift : 0; |
| 4195 | unit = MINOR(mddev->unit) >> shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4197 | /* wait for any previous instance if this device |
| 4198 | * to be completed removed (mddev_delayed_delete). |
| 4199 | */ |
| 4200 | flush_scheduled_work(); |
| 4201 | |
Arjan van de Ven | 48c9c27 | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 4202 | mutex_lock(&disks_mutex); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4203 | error = -EEXIST; |
| 4204 | if (mddev->gendisk) |
| 4205 | goto abort; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4206 | |
| 4207 | if (name) { |
| 4208 | /* Need to ensure that 'name' is not a duplicate. |
| 4209 | */ |
| 4210 | mddev_t *mddev2; |
| 4211 | spin_lock(&all_mddevs_lock); |
| 4212 | |
| 4213 | list_for_each_entry(mddev2, &all_mddevs, all_mddevs) |
| 4214 | if (mddev2->gendisk && |
| 4215 | strcmp(mddev2->gendisk->disk_name, name) == 0) { |
| 4216 | spin_unlock(&all_mddevs_lock); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4217 | goto abort; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4218 | } |
| 4219 | spin_unlock(&all_mddevs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | } |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4221 | |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4222 | error = -ENOMEM; |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4223 | mddev->queue = blk_alloc_queue(GFP_KERNEL); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4224 | if (!mddev->queue) |
| 4225 | goto abort; |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4226 | mddev->queue->queuedata = mddev; |
| 4227 | |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4228 | /* Can be unlocked because the queue is new: no concurrency */ |
| 4229 | queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, mddev->queue); |
| 4230 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4231 | blk_queue_make_request(mddev->queue, md_make_request); |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | disk = alloc_disk(1 << shift); |
| 4234 | if (!disk) { |
NeilBrown | 8b76539 | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4235 | blk_cleanup_queue(mddev->queue); |
| 4236 | mddev->queue = NULL; |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4237 | goto abort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | } |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4239 | disk->major = MAJOR(mddev->unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | disk->first_minor = unit << shift; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4241 | if (name) |
| 4242 | strcpy(disk->disk_name, name); |
| 4243 | else if (partitioned) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | sprintf(disk->disk_name, "md_d%d", unit); |
Greg Kroah-Hartman | ce7b0f46 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 4245 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | sprintf(disk->disk_name, "md%d", unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | disk->fops = &md_fops; |
| 4248 | disk->private_data = mddev; |
| 4249 | disk->queue = mddev->queue; |
NeilBrown | 92850bb | 2008-10-21 13:25:32 +1100 | [diff] [blame] | 4250 | /* Allow extended partitions. This makes the |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4251 | * 'mdp' device redundant, but we can't really |
NeilBrown | 92850bb | 2008-10-21 13:25:32 +1100 | [diff] [blame] | 4252 | * remove it now. |
| 4253 | */ |
| 4254 | disk->flags |= GENHD_FL_EXT_DEVT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | add_disk(disk); |
| 4256 | mddev->gendisk = disk; |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 4257 | error = kobject_init_and_add(&mddev->kobj, &md_ktype, |
| 4258 | &disk_to_dev(disk)->kobj, "%s", "md"); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4259 | if (error) { |
| 4260 | /* This isn't possible, but as kobject_init_and_add is marked |
| 4261 | * __must_check, we must do something with the result |
| 4262 | */ |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4263 | printk(KERN_WARNING "md: cannot register %s/md - name in use\n", |
| 4264 | disk->disk_name); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4265 | error = 0; |
| 4266 | } |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4267 | if (mddev->kobj.sd && |
| 4268 | sysfs_create_group(&mddev->kobj, &md_bitmap_group)) |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 4269 | printk(KERN_DEBUG "pointless warning\n"); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4270 | abort: |
| 4271 | mutex_unlock(&disks_mutex); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4272 | if (!error && mddev->kobj.sd) { |
Greg Kroah-Hartman | 3830c62 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 4273 | kobject_uevent(&mddev->kobj, KOBJ_ADD); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4274 | mddev->sysfs_state = sysfs_get_dirent_safe(mddev->kobj.sd, "array_state"); |
NeilBrown | b62b759 | 2008-10-21 13:25:21 +1100 | [diff] [blame] | 4275 | } |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4276 | mddev_put(mddev); |
NeilBrown | 0909dc4 | 2009-07-01 12:27:21 +1000 | [diff] [blame] | 4277 | return error; |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | static struct kobject *md_probe(dev_t dev, int *part, void *data) |
| 4281 | { |
| 4282 | md_alloc(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | return NULL; |
| 4284 | } |
| 4285 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4286 | static int add_named_array(const char *val, struct kernel_param *kp) |
| 4287 | { |
| 4288 | /* val must be "md_*" where * is not all digits. |
| 4289 | * We allocate an array with a large free minor number, and |
| 4290 | * set the name to val. val must not already be an active name. |
| 4291 | */ |
| 4292 | int len = strlen(val); |
| 4293 | char buf[DISK_NAME_LEN]; |
| 4294 | |
| 4295 | while (len && val[len-1] == '\n') |
| 4296 | len--; |
| 4297 | if (len >= DISK_NAME_LEN) |
| 4298 | return -E2BIG; |
| 4299 | strlcpy(buf, val, len+1); |
| 4300 | if (strncmp(buf, "md_", 3) != 0) |
| 4301 | return -EINVAL; |
| 4302 | return md_alloc(0, buf); |
| 4303 | } |
| 4304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | static void md_safemode_timeout(unsigned long data) |
| 4306 | { |
| 4307 | mddev_t *mddev = (mddev_t *) data; |
| 4308 | |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 4309 | if (!atomic_read(&mddev->writes_pending)) { |
| 4310 | mddev->safemode = 1; |
| 4311 | if (mddev->external) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4312 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 4313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | md_wakeup_thread(mddev->thread); |
| 4315 | } |
| 4316 | |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4317 | static int start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4319 | int md_run(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4321 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | mdk_rdev_t *rdev; |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4323 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4325 | if (list_empty(&mddev->disks)) |
| 4326 | /* cannot run an array with no devices.. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | |
| 4329 | if (mddev->pers) |
| 4330 | return -EBUSY; |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 4331 | /* Cannot run until previous stop completes properly */ |
| 4332 | if (mddev->sysfs_active) |
| 4333 | return -EBUSY; |
NeilBrown | b6eb127 | 2010-04-15 10:13:47 +1000 | [diff] [blame] | 4334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | /* |
| 4336 | * Analyze all RAID superblock(s) |
| 4337 | */ |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4338 | if (!mddev->raid_disks) { |
| 4339 | if (!mddev->persistent) |
| 4340 | return -EINVAL; |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4341 | analyze_sbs(mddev); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4342 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4344 | if (mddev->level != LEVEL_NONE) |
| 4345 | request_module("md-level-%d", mddev->level); |
| 4346 | else if (mddev->clevel[0]) |
| 4347 | request_module("md-%s", mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | |
| 4349 | /* |
| 4350 | * Drop all container device buffers, from now on |
| 4351 | * the only valid external interface is through the md |
| 4352 | * device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4354 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4355 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | continue; |
| 4357 | sync_blockdev(rdev->bdev); |
Peter Zijlstra | f98393a | 2007-05-06 14:49:54 -0700 | [diff] [blame] | 4358 | invalidate_bdev(rdev->bdev); |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4359 | |
| 4360 | /* perform some consistency tests on the device. |
| 4361 | * We don't want the data to overlap the metadata, |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4362 | * Internal Bitmap issues have been handled elsewhere. |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4363 | */ |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4364 | if (rdev->data_offset < rdev->sb_start) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4365 | if (mddev->dev_sectors && |
| 4366 | rdev->data_offset + mddev->dev_sectors |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4367 | > rdev->sb_start) { |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4368 | printk("md: %s: data overlaps metadata\n", |
| 4369 | mdname(mddev)); |
| 4370 | return -EINVAL; |
| 4371 | } |
| 4372 | } else { |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 4373 | if (rdev->sb_start + rdev->sb_size/512 |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 4374 | > rdev->data_offset) { |
| 4375 | printk("md: %s: metadata overlaps data\n", |
| 4376 | mdname(mddev)); |
| 4377 | return -EINVAL; |
| 4378 | } |
| 4379 | } |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4380 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | spin_lock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4384 | pers = find_pers(mddev->level, mddev->clevel); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4385 | if (!pers || !try_module_get(pers->owner)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | spin_unlock(&pers_lock); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4387 | if (mddev->level != LEVEL_NONE) |
| 4388 | printk(KERN_WARNING "md: personality for level %d is not loaded!\n", |
| 4389 | mddev->level); |
| 4390 | else |
| 4391 | printk(KERN_WARNING "md: personality for level %s is not loaded!\n", |
| 4392 | mddev->clevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | return -EINVAL; |
| 4394 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 4395 | mddev->pers = pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | spin_unlock(&pers_lock); |
NeilBrown | 34817e8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4397 | if (mddev->level != pers->level) { |
| 4398 | mddev->level = pers->level; |
| 4399 | mddev->new_level = pers->level; |
| 4400 | } |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 4401 | strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4403 | if (mddev->reshape_position != MaxSector && |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 4404 | pers->start_reshape == NULL) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4405 | /* This personality cannot handle reshaping... */ |
| 4406 | mddev->pers = NULL; |
| 4407 | module_put(pers->owner); |
| 4408 | return -EINVAL; |
| 4409 | } |
| 4410 | |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4411 | if (pers->sync_request) { |
| 4412 | /* Warn if this is a potentially silly |
| 4413 | * configuration. |
| 4414 | */ |
| 4415 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 4416 | mdk_rdev_t *rdev2; |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4417 | int warned = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4418 | |
| 4419 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 4420 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4421 | if (rdev < rdev2 && |
| 4422 | rdev->bdev->bd_contains == |
| 4423 | rdev2->bdev->bd_contains) { |
| 4424 | printk(KERN_WARNING |
| 4425 | "%s: WARNING: %s appears to be" |
| 4426 | " on the same physical disk as" |
| 4427 | " %s.\n", |
| 4428 | mdname(mddev), |
| 4429 | bdevname(rdev->bdev,b), |
| 4430 | bdevname(rdev2->bdev,b2)); |
| 4431 | warned = 1; |
| 4432 | } |
| 4433 | } |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4434 | |
NeilBrown | 7dd5e7c3 | 2007-02-28 20:11:35 -0800 | [diff] [blame] | 4435 | if (warned) |
| 4436 | printk(KERN_WARNING |
| 4437 | "True protection against single-disk" |
| 4438 | " failure might be compromised.\n"); |
| 4439 | } |
| 4440 | |
NeilBrown | 657390d | 2005-08-26 18:34:16 -0700 | [diff] [blame] | 4441 | mddev->recovery = 0; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4442 | /* may be over-ridden by personality */ |
| 4443 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 4444 | |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4445 | mddev->ok_start_degraded = start_dirty_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4446 | |
NeilBrown | 0f9552b5 | 2009-12-30 12:08:50 +1100 | [diff] [blame] | 4447 | if (start_readonly && mddev->ro == 0) |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 4448 | mddev->ro = 2; /* read-only, but switch on first write */ |
| 4449 | |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 4450 | err = mddev->pers->run(mddev); |
Andre Noll | 13e53df | 2008-03-26 00:07:03 +0100 | [diff] [blame] | 4451 | if (err) |
| 4452 | printk(KERN_ERR "md: pers->run() failed ...\n"); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4453 | else if (mddev->pers->size(mddev, 0, 0) < mddev->array_sectors) { |
| 4454 | WARN_ONCE(!mddev->external_size, "%s: default size too small," |
| 4455 | " but 'external_size' not in effect?\n", __func__); |
| 4456 | printk(KERN_ERR |
| 4457 | "md: invalid array_size %llu > default size %llu\n", |
| 4458 | (unsigned long long)mddev->array_sectors / 2, |
| 4459 | (unsigned long long)mddev->pers->size(mddev, 0, 0) / 2); |
| 4460 | err = -EINVAL; |
| 4461 | mddev->pers->stop(mddev); |
| 4462 | } |
| 4463 | if (err == 0 && mddev->pers->sync_request) { |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 4464 | err = bitmap_create(mddev); |
| 4465 | if (err) { |
| 4466 | printk(KERN_ERR "%s: failed to create bitmap (%d)\n", |
| 4467 | mdname(mddev), err); |
| 4468 | mddev->pers->stop(mddev); |
| 4469 | } |
| 4470 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | module_put(mddev->pers->owner); |
| 4473 | mddev->pers = NULL; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4474 | bitmap_destroy(mddev); |
| 4475 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4476 | } |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4477 | if (mddev->pers->sync_request) { |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4478 | if (mddev->kobj.sd && |
| 4479 | sysfs_create_group(&mddev->kobj, &md_redundancy_group)) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4480 | printk(KERN_WARNING |
| 4481 | "md: cannot register extra attributes for %s\n", |
| 4482 | mdname(mddev)); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4483 | mddev->sysfs_action = sysfs_get_dirent_safe(mddev->kobj.sd, "sync_action"); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4484 | } else if (mddev->ro == 2) /* auto-readonly not meaningful */ |
NeilBrown | fd9d49c | 2005-11-08 21:39:42 -0800 | [diff] [blame] | 4485 | mddev->ro = 0; |
| 4486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | atomic_set(&mddev->writes_pending,0); |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 4488 | atomic_set(&mddev->max_corr_read_errors, |
| 4489 | MD_DEFAULT_MAX_CORRECTED_READ_ERRORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | mddev->safemode = 0; |
| 4491 | mddev->safemode_timer.function = md_safemode_timeout; |
| 4492 | mddev->safemode_timer.data = (unsigned long) mddev; |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 4493 | mddev->safemode_delay = (200 * HZ)/1000 +1; /* 200 msec delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | mddev->in_sync = 1; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4495 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4496 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4497 | if (rdev->raid_disk >= 0) { |
| 4498 | char nm[20]; |
| 4499 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4500 | if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4501 | /* failure here is OK */; |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 4502 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | |
| 4504 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4505 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4506 | if (mddev->flags) |
| 4507 | md_update_sb(mddev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | |
NeilBrown | 0b8c9de | 2006-07-10 04:44:15 -0700 | [diff] [blame] | 4509 | md_wakeup_thread(mddev->thread); |
| 4510 | md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 4511 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4512 | md_new_event(mddev); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4513 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
| 4514 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 4515 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | return 0; |
| 4517 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4518 | EXPORT_SYMBOL_GPL(md_run); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | |
NeilBrown | fe60b01 | 2010-03-29 11:10:42 +1100 | [diff] [blame] | 4520 | static int do_md_run(mddev_t *mddev) |
| 4521 | { |
| 4522 | int err; |
| 4523 | |
| 4524 | err = md_run(mddev); |
| 4525 | if (err) |
| 4526 | goto out; |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 4527 | err = bitmap_load(mddev); |
| 4528 | if (err) { |
| 4529 | bitmap_destroy(mddev); |
| 4530 | goto out; |
| 4531 | } |
NeilBrown | fe60b01 | 2010-03-29 11:10:42 +1100 | [diff] [blame] | 4532 | set_capacity(mddev->gendisk, mddev->array_sectors); |
| 4533 | revalidate_disk(mddev->gendisk); |
| 4534 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
| 4535 | out: |
| 4536 | return err; |
| 4537 | } |
| 4538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | static int restart_array(mddev_t *mddev) |
| 4540 | { |
| 4541 | struct gendisk *disk = mddev->gendisk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4543 | /* Complain if it has no devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | if (list_empty(&mddev->disks)) |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4545 | return -ENXIO; |
| 4546 | if (!mddev->pers) |
| 4547 | return -EINVAL; |
| 4548 | if (!mddev->ro) |
| 4549 | return -EBUSY; |
| 4550 | mddev->safemode = 0; |
| 4551 | mddev->ro = 0; |
| 4552 | set_disk_ro(disk, 0); |
| 4553 | printk(KERN_INFO "md: %s switched to read-write mode.\n", |
| 4554 | mdname(mddev)); |
| 4555 | /* Kick recovery or resync if necessary */ |
| 4556 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 4557 | md_wakeup_thread(mddev->thread); |
| 4558 | md_wakeup_thread(mddev->sync_thread); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4559 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Andre Noll | 80fab1d | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4560 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | } |
| 4562 | |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4563 | /* similar to deny_write_access, but accounts for our holding a reference |
| 4564 | * to the file ourselves */ |
| 4565 | static int deny_bitmap_write_access(struct file * file) |
| 4566 | { |
| 4567 | struct inode *inode = file->f_mapping->host; |
| 4568 | |
| 4569 | spin_lock(&inode->i_lock); |
| 4570 | if (atomic_read(&inode->i_writecount) > 1) { |
| 4571 | spin_unlock(&inode->i_lock); |
| 4572 | return -ETXTBSY; |
| 4573 | } |
| 4574 | atomic_set(&inode->i_writecount, -1); |
| 4575 | spin_unlock(&inode->i_lock); |
| 4576 | |
| 4577 | return 0; |
| 4578 | } |
| 4579 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 4580 | void restore_bitmap_write_access(struct file *file) |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 4581 | { |
| 4582 | struct inode *inode = file->f_mapping->host; |
| 4583 | |
| 4584 | spin_lock(&inode->i_lock); |
| 4585 | atomic_set(&inode->i_writecount, 1); |
| 4586 | spin_unlock(&inode->i_lock); |
| 4587 | } |
| 4588 | |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4589 | static void md_clean(mddev_t *mddev) |
| 4590 | { |
| 4591 | mddev->array_sectors = 0; |
| 4592 | mddev->external_size = 0; |
| 4593 | mddev->dev_sectors = 0; |
| 4594 | mddev->raid_disks = 0; |
| 4595 | mddev->recovery_cp = 0; |
| 4596 | mddev->resync_min = 0; |
| 4597 | mddev->resync_max = MaxSector; |
| 4598 | mddev->reshape_position = MaxSector; |
| 4599 | mddev->external = 0; |
| 4600 | mddev->persistent = 0; |
| 4601 | mddev->level = LEVEL_NONE; |
| 4602 | mddev->clevel[0] = 0; |
| 4603 | mddev->flags = 0; |
| 4604 | mddev->ro = 0; |
| 4605 | mddev->metadata_type[0] = 0; |
| 4606 | mddev->chunk_sectors = 0; |
| 4607 | mddev->ctime = mddev->utime = 0; |
| 4608 | mddev->layout = 0; |
| 4609 | mddev->max_disks = 0; |
| 4610 | mddev->events = 0; |
NeilBrown | a8707c0 | 2010-05-18 09:28:43 +1000 | [diff] [blame] | 4611 | mddev->can_decrease_events = 0; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4612 | mddev->delta_disks = 0; |
| 4613 | mddev->new_level = LEVEL_NONE; |
| 4614 | mddev->new_layout = 0; |
| 4615 | mddev->new_chunk_sectors = 0; |
| 4616 | mddev->curr_resync = 0; |
| 4617 | mddev->resync_mismatches = 0; |
| 4618 | mddev->suspend_lo = mddev->suspend_hi = 0; |
| 4619 | mddev->sync_speed_min = mddev->sync_speed_max = 0; |
| 4620 | mddev->recovery = 0; |
| 4621 | mddev->in_sync = 0; |
| 4622 | mddev->degraded = 0; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4623 | mddev->safemode = 0; |
| 4624 | mddev->bitmap_info.offset = 0; |
| 4625 | mddev->bitmap_info.default_offset = 0; |
| 4626 | mddev->bitmap_info.chunksize = 0; |
| 4627 | mddev->bitmap_info.daemon_sleep = 0; |
| 4628 | mddev->bitmap_info.max_write_behind = 0; |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 4629 | mddev->plug = NULL; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4630 | } |
| 4631 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4632 | void md_stop_writes(mddev_t *mddev) |
NeilBrown | a047e12 | 2010-03-29 12:07:53 +1100 | [diff] [blame] | 4633 | { |
| 4634 | if (mddev->sync_thread) { |
| 4635 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 4636 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 4637 | md_unregister_thread(mddev->sync_thread); |
| 4638 | mddev->sync_thread = NULL; |
| 4639 | } |
| 4640 | |
| 4641 | del_timer_sync(&mddev->safemode_timer); |
| 4642 | |
| 4643 | bitmap_flush(mddev); |
| 4644 | md_super_wait(mddev); |
| 4645 | |
| 4646 | if (!mddev->in_sync || mddev->flags) { |
| 4647 | /* mark array as shutdown cleanly */ |
| 4648 | mddev->in_sync = 1; |
| 4649 | md_update_sb(mddev, 1); |
| 4650 | } |
| 4651 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4652 | EXPORT_SYMBOL_GPL(md_stop_writes); |
NeilBrown | a047e12 | 2010-03-29 12:07:53 +1100 | [diff] [blame] | 4653 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4654 | void md_stop(mddev_t *mddev) |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4655 | { |
| 4656 | mddev->pers->stop(mddev); |
| 4657 | if (mddev->pers->sync_request && mddev->to_remove == NULL) |
| 4658 | mddev->to_remove = &md_redundancy_group; |
| 4659 | module_put(mddev->pers->owner); |
| 4660 | mddev->pers = NULL; |
NeilBrown | cca9cf9 | 2010-04-01 12:08:16 +1100 | [diff] [blame] | 4661 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4662 | } |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4663 | EXPORT_SYMBOL_GPL(md_stop); |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4664 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4665 | static int md_set_readonly(mddev_t *mddev, int is_open) |
| 4666 | { |
| 4667 | int err = 0; |
| 4668 | mutex_lock(&mddev->open_mutex); |
| 4669 | if (atomic_read(&mddev->openers) > is_open) { |
| 4670 | printk("md: %s still in use.\n",mdname(mddev)); |
| 4671 | err = -EBUSY; |
| 4672 | goto out; |
| 4673 | } |
| 4674 | if (mddev->pers) { |
| 4675 | md_stop_writes(mddev); |
| 4676 | |
| 4677 | err = -ENXIO; |
| 4678 | if (mddev->ro==1) |
| 4679 | goto out; |
| 4680 | mddev->ro = 1; |
| 4681 | set_disk_ro(mddev->gendisk, 1); |
| 4682 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4683 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4684 | err = 0; |
| 4685 | } |
| 4686 | out: |
| 4687 | mutex_unlock(&mddev->open_mutex); |
| 4688 | return err; |
| 4689 | } |
| 4690 | |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4691 | /* mode: |
| 4692 | * 0 - completely stop and dis-assemble array |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4693 | * 2 - stop but do not disassemble array |
| 4694 | */ |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4695 | 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] | 4696 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | struct gendisk *disk = mddev->gendisk; |
NeilBrown | c464729 | 2009-05-07 12:51:06 +1000 | [diff] [blame] | 4698 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 4700 | mutex_lock(&mddev->open_mutex); |
NeilBrown | bb4f1e9 | 2010-08-08 21:18:03 +1000 | [diff] [blame] | 4701 | if (atomic_read(&mddev->openers) > is_open || |
| 4702 | mddev->sysfs_active) { |
Neil Brown | df5b20c | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 4703 | printk("md: %s still in use.\n",mdname(mddev)); |
NeilBrown | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4704 | mutex_unlock(&mddev->open_mutex); |
| 4705 | return -EBUSY; |
| 4706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | |
NeilBrown | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4708 | if (mddev->pers) { |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4709 | if (mddev->ro) |
| 4710 | set_disk_ro(disk, 0); |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4711 | |
NeilBrown | 390ee60 | 2010-06-01 19:37:27 +1000 | [diff] [blame] | 4712 | md_stop_writes(mddev); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4713 | md_stop(mddev); |
| 4714 | mddev->queue->merge_bvec_fn = NULL; |
| 4715 | mddev->queue->unplug_fn = NULL; |
| 4716 | mddev->queue->backing_dev_info.congested_fn = NULL; |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4717 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4718 | /* tell userspace to handle 'inactive' */ |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4719 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4720 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4721 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 4722 | if (rdev->raid_disk >= 0) { |
| 4723 | char nm[20]; |
| 4724 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 4725 | sysfs_remove_link(&mddev->kobj, nm); |
| 4726 | } |
NeilBrown | c464729 | 2009-05-07 12:51:06 +1000 | [diff] [blame] | 4727 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4728 | set_capacity(disk, 0); |
NeilBrown | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4729 | mutex_unlock(&mddev->open_mutex); |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4730 | revalidate_disk(disk); |
NeilBrown | 0d4ca60 | 2006-12-10 02:20:44 -0800 | [diff] [blame] | 4731 | |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4732 | if (mddev->ro) |
| 4733 | mddev->ro = 0; |
NeilBrown | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4734 | } else |
| 4735 | mutex_unlock(&mddev->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | /* |
| 4737 | * Free resources if final stop |
| 4738 | */ |
NeilBrown | 9e653b6 | 2006-06-26 00:27:58 -0700 | [diff] [blame] | 4739 | if (mode == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); |
| 4741 | |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4742 | bitmap_destroy(mddev); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4743 | if (mddev->bitmap_info.file) { |
| 4744 | restore_bitmap_write_access(mddev->bitmap_info.file); |
| 4745 | fput(mddev->bitmap_info.file); |
| 4746 | mddev->bitmap_info.file = NULL; |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4747 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4748 | mddev->bitmap_info.offset = 0; |
NeilBrown | 978f946 | 2006-02-02 14:28:05 -0800 | [diff] [blame] | 4749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | export_array(mddev); |
| 4751 | |
NeilBrown | 6177b47 | 2010-03-29 11:37:13 +1100 | [diff] [blame] | 4752 | md_clean(mddev); |
NeilBrown | 934d9c2 | 2008-10-28 17:01:23 +1100 | [diff] [blame] | 4753 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 4754 | if (mddev->hold_active == UNTIL_STOP) |
| 4755 | mddev->hold_active = 0; |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 4756 | } |
Martin K. Petersen | 3f9d99c | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 4757 | blk_integrity_unregister(disk); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 4758 | md_new_event(mddev); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4759 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 6e17b02 | 2010-08-07 21:41:19 +1000 | [diff] [blame] | 4760 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4761 | } |
| 4762 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 4763 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | static void autorun_array(mddev_t *mddev) |
| 4765 | { |
| 4766 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | int err; |
| 4768 | |
NeilBrown | a757e64 | 2005-04-16 15:26:42 -0700 | [diff] [blame] | 4769 | if (list_empty(&mddev->disks)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | |
| 4772 | printk(KERN_INFO "md: running: "); |
| 4773 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4774 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | char b[BDEVNAME_SIZE]; |
| 4776 | printk("<%s>", bdevname(rdev->bdev,b)); |
| 4777 | } |
| 4778 | printk("\n"); |
| 4779 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4780 | err = do_md_run(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | if (err) { |
| 4782 | printk(KERN_WARNING "md: do_md_run() returned %d\n", err); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4783 | do_md_stop(mddev, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | } |
| 4785 | } |
| 4786 | |
| 4787 | /* |
| 4788 | * lets try to run arrays based on all disks that have arrived |
| 4789 | * until now. (those are in pending_raid_disks) |
| 4790 | * |
| 4791 | * the method: pick the first pending disk, collect all disks with |
| 4792 | * the same UUID, remove all from the pending list and put them into |
| 4793 | * the 'same_array' list. Then order this list based on superblock |
| 4794 | * update time (freshest comes first), kick out 'old' disks and |
| 4795 | * compare superblocks. If everything's fine then run it. |
| 4796 | * |
| 4797 | * If "unit" is allocated, then bump its reference count |
| 4798 | */ |
| 4799 | static void autorun_devices(int part) |
| 4800 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4801 | mdk_rdev_t *rdev0, *rdev, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | mddev_t *mddev; |
| 4803 | char b[BDEVNAME_SIZE]; |
| 4804 | |
| 4805 | printk(KERN_INFO "md: autorun ...\n"); |
| 4806 | while (!list_empty(&pending_raid_disks)) { |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4807 | int unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | dev_t dev; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 4809 | LIST_HEAD(candidates); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | rdev0 = list_entry(pending_raid_disks.next, |
| 4811 | mdk_rdev_t, same_set); |
| 4812 | |
| 4813 | printk(KERN_INFO "md: considering %s ...\n", |
| 4814 | bdevname(rdev0->bdev,b)); |
| 4815 | INIT_LIST_HEAD(&candidates); |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4816 | rdev_for_each_list(rdev, tmp, &pending_raid_disks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | if (super_90_load(rdev, rdev0, 0) >= 0) { |
| 4818 | printk(KERN_INFO "md: adding %s ...\n", |
| 4819 | bdevname(rdev->bdev,b)); |
| 4820 | list_move(&rdev->same_set, &candidates); |
| 4821 | } |
| 4822 | /* |
| 4823 | * now we have a set of devices, with all of them having |
| 4824 | * mostly sane superblocks. It's time to allocate the |
| 4825 | * mddev. |
| 4826 | */ |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 4827 | if (part) { |
| 4828 | dev = MKDEV(mdp_major, |
| 4829 | rdev0->preferred_minor << MdpMinorShift); |
| 4830 | unit = MINOR(dev) >> MdpMinorShift; |
| 4831 | } else { |
| 4832 | dev = MKDEV(MD_MAJOR, rdev0->preferred_minor); |
| 4833 | unit = MINOR(dev); |
| 4834 | } |
| 4835 | if (rdev0->preferred_minor != unit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | printk(KERN_INFO "md: unit number in %s is bad: %d\n", |
| 4837 | bdevname(rdev0->bdev, b), rdev0->preferred_minor); |
| 4838 | break; |
| 4839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | |
| 4841 | md_probe(dev, NULL, NULL); |
| 4842 | mddev = mddev_find(dev); |
Neil Brown | 9bbbca3 | 2008-06-28 08:31:17 +1000 | [diff] [blame] | 4843 | if (!mddev || !mddev->gendisk) { |
| 4844 | if (mddev) |
| 4845 | mddev_put(mddev); |
| 4846 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | "md: cannot allocate memory for md drive.\n"); |
| 4848 | break; |
| 4849 | } |
| 4850 | if (mddev_lock(mddev)) |
| 4851 | printk(KERN_WARNING "md: %s locked, cannot run\n", |
| 4852 | mdname(mddev)); |
| 4853 | else if (mddev->raid_disks || mddev->major_version |
| 4854 | || !list_empty(&mddev->disks)) { |
| 4855 | printk(KERN_WARNING |
| 4856 | "md: %s already running, cannot run %s\n", |
| 4857 | mdname(mddev), bdevname(rdev0->bdev,b)); |
| 4858 | mddev_unlock(mddev); |
| 4859 | } else { |
| 4860 | printk(KERN_INFO "md: created %s\n", mdname(mddev)); |
NeilBrown | 1ec4a93 | 2008-02-06 01:39:53 -0800 | [diff] [blame] | 4861 | mddev->persistent = 1; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4862 | rdev_for_each_list(rdev, tmp, &candidates) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | list_del_init(&rdev->same_set); |
| 4864 | if (bind_rdev_to_array(rdev, mddev)) |
| 4865 | export_rdev(rdev); |
| 4866 | } |
| 4867 | autorun_array(mddev); |
| 4868 | mddev_unlock(mddev); |
| 4869 | } |
| 4870 | /* on success, candidates will be empty, on error |
| 4871 | * it won't... |
| 4872 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4873 | rdev_for_each_list(rdev, tmp, &candidates) { |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 4874 | list_del_init(&rdev->same_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | export_rdev(rdev); |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 4876 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | mddev_put(mddev); |
| 4878 | } |
| 4879 | printk(KERN_INFO "md: ... autorun DONE.\n"); |
| 4880 | } |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 4881 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | static int get_version(void __user * arg) |
| 4884 | { |
| 4885 | mdu_version_t ver; |
| 4886 | |
| 4887 | ver.major = MD_MAJOR_VERSION; |
| 4888 | ver.minor = MD_MINOR_VERSION; |
| 4889 | ver.patchlevel = MD_PATCHLEVEL_VERSION; |
| 4890 | |
| 4891 | if (copy_to_user(arg, &ver, sizeof(ver))) |
| 4892 | return -EFAULT; |
| 4893 | |
| 4894 | return 0; |
| 4895 | } |
| 4896 | |
| 4897 | static int get_array_info(mddev_t * mddev, void __user * arg) |
| 4898 | { |
| 4899 | mdu_array_info_t info; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4900 | int nr,working,insync,failed,spare; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4903 | nr=working=insync=failed=spare=0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 4904 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | nr++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4906 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | failed++; |
| 4908 | else { |
| 4909 | working++; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4910 | if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4911 | insync++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | else |
| 4913 | spare++; |
| 4914 | } |
| 4915 | } |
| 4916 | |
| 4917 | info.major_version = mddev->major_version; |
| 4918 | info.minor_version = mddev->minor_version; |
| 4919 | info.patch_version = MD_PATCHLEVEL_VERSION; |
| 4920 | info.ctime = mddev->ctime; |
| 4921 | info.level = mddev->level; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4922 | info.size = mddev->dev_sectors / 2; |
| 4923 | if (info.size != mddev->dev_sectors / 2) /* overflow */ |
NeilBrown | 284ae7c | 2006-02-03 03:03:40 -0800 | [diff] [blame] | 4924 | info.size = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | info.nr_disks = nr; |
| 4926 | info.raid_disks = mddev->raid_disks; |
| 4927 | info.md_minor = mddev->md_minor; |
| 4928 | info.not_persistent= !mddev->persistent; |
| 4929 | |
| 4930 | info.utime = mddev->utime; |
| 4931 | info.state = 0; |
| 4932 | if (mddev->in_sync) |
| 4933 | info.state = (1<<MD_SB_CLEAN); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 4934 | if (mddev->bitmap && mddev->bitmap_info.offset) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 4935 | info.state = (1<<MD_SB_BITMAP_PRESENT); |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4936 | info.active_disks = insync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | info.working_disks = working; |
| 4938 | info.failed_disks = failed; |
| 4939 | info.spare_disks = spare; |
| 4940 | |
| 4941 | info.layout = mddev->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4942 | info.chunk_size = mddev->chunk_sectors << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | |
| 4944 | if (copy_to_user(arg, &info, sizeof(info))) |
| 4945 | return -EFAULT; |
| 4946 | |
| 4947 | return 0; |
| 4948 | } |
| 4949 | |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 4950 | static int get_bitmap_file(mddev_t * mddev, void __user * arg) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4951 | { |
| 4952 | mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ |
| 4953 | char *ptr, *buf = NULL; |
| 4954 | int err = -ENOMEM; |
| 4955 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4956 | if (md_allow_write(mddev)) |
| 4957 | file = kmalloc(sizeof(*file), GFP_NOIO); |
| 4958 | else |
| 4959 | file = kmalloc(sizeof(*file), GFP_KERNEL); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 4960 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4961 | if (!file) |
| 4962 | goto out; |
| 4963 | |
| 4964 | /* bitmap disabled, zero the first byte and copy out */ |
| 4965 | if (!mddev->bitmap || !mddev->bitmap->file) { |
| 4966 | file->pathname[0] = '\0'; |
| 4967 | goto copy_out; |
| 4968 | } |
| 4969 | |
| 4970 | buf = kmalloc(sizeof(file->pathname), GFP_KERNEL); |
| 4971 | if (!buf) |
| 4972 | goto out; |
| 4973 | |
Christoph Hellwig | 6bcfd60 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 4974 | ptr = d_path(&mddev->bitmap->file->f_path, buf, sizeof(file->pathname)); |
| 4975 | if (IS_ERR(ptr)) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 4976 | goto out; |
| 4977 | |
| 4978 | strcpy(file->pathname, ptr); |
| 4979 | |
| 4980 | copy_out: |
| 4981 | err = 0; |
| 4982 | if (copy_to_user(arg, file, sizeof(*file))) |
| 4983 | err = -EFAULT; |
| 4984 | out: |
| 4985 | kfree(buf); |
| 4986 | kfree(file); |
| 4987 | return err; |
| 4988 | } |
| 4989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | static int get_disk_info(mddev_t * mddev, void __user * arg) |
| 4991 | { |
| 4992 | mdu_disk_info_t info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | mdk_rdev_t *rdev; |
| 4994 | |
| 4995 | if (copy_from_user(&info, arg, sizeof(info))) |
| 4996 | return -EFAULT; |
| 4997 | |
Andre Noll | 26ef379 | 2008-07-11 22:02:21 +1000 | [diff] [blame] | 4998 | rdev = find_rdev_nr(mddev, info.number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | if (rdev) { |
| 5000 | info.major = MAJOR(rdev->bdev->bd_dev); |
| 5001 | info.minor = MINOR(rdev->bdev->bd_dev); |
| 5002 | info.raid_disk = rdev->raid_disk; |
| 5003 | info.state = 0; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5004 | if (test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | info.state |= (1<<MD_DISK_FAULTY); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5006 | else if (test_bit(In_sync, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | info.state |= (1<<MD_DISK_ACTIVE); |
| 5008 | info.state |= (1<<MD_DISK_SYNC); |
| 5009 | } |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5010 | if (test_bit(WriteMostly, &rdev->flags)) |
| 5011 | info.state |= (1<<MD_DISK_WRITEMOSTLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | } else { |
| 5013 | info.major = info.minor = 0; |
| 5014 | info.raid_disk = -1; |
| 5015 | info.state = (1<<MD_DISK_REMOVED); |
| 5016 | } |
| 5017 | |
| 5018 | if (copy_to_user(arg, &info, sizeof(info))) |
| 5019 | return -EFAULT; |
| 5020 | |
| 5021 | return 0; |
| 5022 | } |
| 5023 | |
| 5024 | static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) |
| 5025 | { |
| 5026 | char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; |
| 5027 | mdk_rdev_t *rdev; |
| 5028 | dev_t dev = MKDEV(info->major,info->minor); |
| 5029 | |
| 5030 | if (info->major != MAJOR(dev) || info->minor != MINOR(dev)) |
| 5031 | return -EOVERFLOW; |
| 5032 | |
| 5033 | if (!mddev->raid_disks) { |
| 5034 | int err; |
| 5035 | /* expecting a device which has a superblock */ |
| 5036 | rdev = md_import_device(dev, mddev->major_version, mddev->minor_version); |
| 5037 | if (IS_ERR(rdev)) { |
| 5038 | printk(KERN_WARNING |
| 5039 | "md: md_import_device returned %ld\n", |
| 5040 | PTR_ERR(rdev)); |
| 5041 | return PTR_ERR(rdev); |
| 5042 | } |
| 5043 | if (!list_empty(&mddev->disks)) { |
| 5044 | mdk_rdev_t *rdev0 = list_entry(mddev->disks.next, |
| 5045 | mdk_rdev_t, same_set); |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5046 | err = super_types[mddev->major_version] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | .load_super(rdev, rdev0, mddev->minor_version); |
| 5048 | if (err < 0) { |
| 5049 | printk(KERN_WARNING |
| 5050 | "md: %s has different UUID to %s\n", |
| 5051 | bdevname(rdev->bdev,b), |
| 5052 | bdevname(rdev0->bdev,b2)); |
| 5053 | export_rdev(rdev); |
| 5054 | return -EINVAL; |
| 5055 | } |
| 5056 | } |
| 5057 | err = bind_rdev_to_array(rdev, mddev); |
| 5058 | if (err) |
| 5059 | export_rdev(rdev); |
| 5060 | return err; |
| 5061 | } |
| 5062 | |
| 5063 | /* |
| 5064 | * add_new_disk can be used once the array is assembled |
| 5065 | * to add "hot spares". They must already have a superblock |
| 5066 | * written |
| 5067 | */ |
| 5068 | if (mddev->pers) { |
| 5069 | int err; |
| 5070 | if (!mddev->pers->hot_add_disk) { |
| 5071 | printk(KERN_WARNING |
| 5072 | "%s: personality does not support diskops!\n", |
| 5073 | mdname(mddev)); |
| 5074 | return -EINVAL; |
| 5075 | } |
NeilBrown | 7b1e35f | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 5076 | if (mddev->persistent) |
| 5077 | rdev = md_import_device(dev, mddev->major_version, |
| 5078 | mddev->minor_version); |
| 5079 | else |
| 5080 | rdev = md_import_device(dev, -1, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | if (IS_ERR(rdev)) { |
| 5082 | printk(KERN_WARNING |
| 5083 | "md: md_import_device returned %ld\n", |
| 5084 | PTR_ERR(rdev)); |
| 5085 | return PTR_ERR(rdev); |
| 5086 | } |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 5087 | /* set save_raid_disk if appropriate */ |
| 5088 | if (!mddev->persistent) { |
| 5089 | if (info->state & (1<<MD_DISK_SYNC) && |
| 5090 | info->raid_disk < mddev->raid_disks) |
| 5091 | rdev->raid_disk = info->raid_disk; |
| 5092 | else |
| 5093 | rdev->raid_disk = -1; |
| 5094 | } else |
| 5095 | super_types[mddev->major_version]. |
| 5096 | validate_super(mddev, rdev); |
| 5097 | rdev->saved_raid_disk = rdev->raid_disk; |
| 5098 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5099 | clear_bit(In_sync, &rdev->flags); /* just to be sure */ |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5100 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 5101 | set_bit(WriteMostly, &rdev->flags); |
NeilBrown | 575a80f | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5102 | else |
| 5103 | clear_bit(WriteMostly, &rdev->flags); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5105 | rdev->raid_disk = -1; |
| 5106 | err = bind_rdev_to_array(rdev, mddev); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 5107 | if (!err && !mddev->pers->hot_remove_disk) { |
| 5108 | /* If there is hot_add_disk but no hot_remove_disk |
| 5109 | * then added disks for geometry changes, |
| 5110 | * and should be added immediately. |
| 5111 | */ |
| 5112 | super_types[mddev->major_version]. |
| 5113 | validate_super(mddev, rdev); |
| 5114 | err = mddev->pers->hot_add_disk(mddev, rdev); |
| 5115 | if (err) |
| 5116 | unbind_rdev_from_array(rdev); |
| 5117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | if (err) |
| 5119 | export_rdev(rdev); |
Neil Brown | 5266473 | 2008-06-28 08:31:44 +1000 | [diff] [blame] | 5120 | else |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 5121 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 5122 | |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 5123 | md_update_sb(mddev, 1); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 5124 | if (mddev->degraded) |
| 5125 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | c361777 | 2005-06-21 17:17:10 -0700 | [diff] [blame] | 5126 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 005eca5 | 2005-08-22 13:11:08 -0700 | [diff] [blame] | 5127 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | return err; |
| 5129 | } |
| 5130 | |
| 5131 | /* otherwise, add_new_disk is only allowed |
| 5132 | * for major_version==0 superblocks |
| 5133 | */ |
| 5134 | if (mddev->major_version != 0) { |
| 5135 | printk(KERN_WARNING "%s: ADD_NEW_DISK not supported\n", |
| 5136 | mdname(mddev)); |
| 5137 | return -EINVAL; |
| 5138 | } |
| 5139 | |
| 5140 | if (!(info->state & (1<<MD_DISK_FAULTY))) { |
| 5141 | int err; |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5142 | rdev = md_import_device(dev, -1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | if (IS_ERR(rdev)) { |
| 5144 | printk(KERN_WARNING |
| 5145 | "md: error, md_import_device() returned %ld\n", |
| 5146 | PTR_ERR(rdev)); |
| 5147 | return PTR_ERR(rdev); |
| 5148 | } |
| 5149 | rdev->desc_nr = info->number; |
| 5150 | if (info->raid_disk < mddev->raid_disks) |
| 5151 | rdev->raid_disk = info->raid_disk; |
| 5152 | else |
| 5153 | rdev->raid_disk = -1; |
| 5154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | if (rdev->raid_disk < mddev->raid_disks) |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5156 | if (info->state & (1<<MD_DISK_SYNC)) |
| 5157 | set_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5159 | if (info->state & (1<<MD_DISK_WRITEMOSTLY)) |
| 5160 | set_bit(WriteMostly, &rdev->flags); |
| 5161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | if (!mddev->persistent) { |
| 5163 | printk(KERN_INFO "md: nonpersistent superblock ...\n"); |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5164 | rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | } else |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5166 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 5167 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5168 | |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 5169 | err = bind_rdev_to_array(rdev, mddev); |
| 5170 | if (err) { |
| 5171 | export_rdev(rdev); |
| 5172 | return err; |
| 5173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | return 0; |
| 5177 | } |
| 5178 | |
| 5179 | static int hot_remove_disk(mddev_t * mddev, dev_t dev) |
| 5180 | { |
| 5181 | char b[BDEVNAME_SIZE]; |
| 5182 | mdk_rdev_t *rdev; |
| 5183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | rdev = find_rdev(mddev, dev); |
| 5185 | if (!rdev) |
| 5186 | return -ENXIO; |
| 5187 | |
| 5188 | if (rdev->raid_disk >= 0) |
| 5189 | goto busy; |
| 5190 | |
| 5191 | kick_rdev_from_array(rdev); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5192 | md_update_sb(mddev, 1); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5193 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5194 | |
| 5195 | return 0; |
| 5196 | busy: |
Nick Andrew | fdefa4d | 2008-04-21 22:42:58 +0000 | [diff] [blame] | 5197 | printk(KERN_WARNING "md: cannot remove active disk %s from %s ...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 5199 | return -EBUSY; |
| 5200 | } |
| 5201 | |
| 5202 | static int hot_add_disk(mddev_t * mddev, dev_t dev) |
| 5203 | { |
| 5204 | char b[BDEVNAME_SIZE]; |
| 5205 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | mdk_rdev_t *rdev; |
| 5207 | |
| 5208 | if (!mddev->pers) |
| 5209 | return -ENODEV; |
| 5210 | |
| 5211 | if (mddev->major_version != 0) { |
| 5212 | printk(KERN_WARNING "%s: HOT_ADD may only be used with" |
| 5213 | " version-0 superblocks.\n", |
| 5214 | mdname(mddev)); |
| 5215 | return -EINVAL; |
| 5216 | } |
| 5217 | if (!mddev->pers->hot_add_disk) { |
| 5218 | printk(KERN_WARNING |
| 5219 | "%s: personality does not support diskops!\n", |
| 5220 | mdname(mddev)); |
| 5221 | return -EINVAL; |
| 5222 | } |
| 5223 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5224 | rdev = md_import_device(dev, -1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5225 | if (IS_ERR(rdev)) { |
| 5226 | printk(KERN_WARNING |
| 5227 | "md: error, md_import_device() returned %ld\n", |
| 5228 | PTR_ERR(rdev)); |
| 5229 | return -EINVAL; |
| 5230 | } |
| 5231 | |
| 5232 | if (mddev->persistent) |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5233 | rdev->sb_start = calc_dev_sboffset(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | else |
Andre Noll | 0f42035 | 2008-07-11 22:02:23 +1000 | [diff] [blame] | 5235 | rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | |
NeilBrown | 8190e75 | 2009-06-18 08:48:58 +1000 | [diff] [blame] | 5237 | rdev->sectors = rdev->sb_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5238 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5239 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | printk(KERN_WARNING |
| 5241 | "md: can not hot-add faulty %s disk to %s!\n", |
| 5242 | bdevname(rdev->bdev,b), mdname(mddev)); |
| 5243 | err = -EINVAL; |
| 5244 | goto abort_export; |
| 5245 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5246 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5247 | rdev->desc_nr = -1; |
NeilBrown | 5842730 | 2006-10-06 00:44:04 -0700 | [diff] [blame] | 5248 | rdev->saved_raid_disk = -1; |
NeilBrown | 2bf071b | 2006-01-06 00:20:55 -0800 | [diff] [blame] | 5249 | err = bind_rdev_to_array(rdev, mddev); |
| 5250 | if (err) |
| 5251 | goto abort_export; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5252 | |
| 5253 | /* |
| 5254 | * The rest should better be atomic, we can have disk failures |
| 5255 | * noticed in interrupt contexts ... |
| 5256 | */ |
| 5257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | rdev->raid_disk = -1; |
| 5259 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5260 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | |
| 5262 | /* |
| 5263 | * Kick recovery, maybe this spare has to be added to the |
| 5264 | * array immediately. |
| 5265 | */ |
| 5266 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5267 | md_wakeup_thread(mddev->thread); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 5268 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | return 0; |
| 5270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5271 | abort_export: |
| 5272 | export_rdev(rdev); |
| 5273 | return err; |
| 5274 | } |
| 5275 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5276 | static int set_bitmap_file(mddev_t *mddev, int fd) |
| 5277 | { |
| 5278 | int err; |
| 5279 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5280 | if (mddev->pers) { |
| 5281 | if (!mddev->pers->quiesce) |
| 5282 | return -EBUSY; |
| 5283 | if (mddev->recovery || mddev->sync_thread) |
| 5284 | return -EBUSY; |
| 5285 | /* we should be able to change the bitmap.. */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5286 | } |
| 5287 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5288 | |
| 5289 | if (fd >= 0) { |
| 5290 | if (mddev->bitmap) |
| 5291 | return -EEXIST; /* cannot add when bitmap is present */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5292 | mddev->bitmap_info.file = fget(fd); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5293 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5294 | if (mddev->bitmap_info.file == NULL) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5295 | printk(KERN_ERR "%s: error: failed to get bitmap file\n", |
| 5296 | mdname(mddev)); |
| 5297 | return -EBADF; |
| 5298 | } |
| 5299 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5300 | err = deny_bitmap_write_access(mddev->bitmap_info.file); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5301 | if (err) { |
| 5302 | printk(KERN_ERR "%s: error: bitmap file is already in use\n", |
| 5303 | mdname(mddev)); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5304 | fput(mddev->bitmap_info.file); |
| 5305 | mddev->bitmap_info.file = NULL; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5306 | return err; |
| 5307 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5308 | mddev->bitmap_info.offset = 0; /* file overrides offset */ |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5309 | } else if (mddev->bitmap == NULL) |
| 5310 | return -ENOENT; /* cannot remove what isn't there */ |
| 5311 | err = 0; |
| 5312 | if (mddev->pers) { |
| 5313 | mddev->pers->quiesce(mddev, 1); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 5314 | if (fd >= 0) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5315 | err = bitmap_create(mddev); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 5316 | if (!err) |
| 5317 | err = bitmap_load(mddev); |
| 5318 | } |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5319 | if (fd < 0 || err) { |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5320 | bitmap_destroy(mddev); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5321 | fd = -1; /* make sure to put the file */ |
| 5322 | } |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5323 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | d7375ab | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5324 | } |
| 5325 | if (fd < 0) { |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5326 | if (mddev->bitmap_info.file) { |
| 5327 | restore_bitmap_write_access(mddev->bitmap_info.file); |
| 5328 | fput(mddev->bitmap_info.file); |
NeilBrown | acc55e2 | 2006-06-26 00:27:47 -0700 | [diff] [blame] | 5329 | } |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5330 | mddev->bitmap_info.file = NULL; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5331 | } |
| 5332 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5333 | return err; |
| 5334 | } |
| 5335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5336 | /* |
| 5337 | * set_array_info is used two different ways |
| 5338 | * The original usage is when creating a new array. |
| 5339 | * In this usage, raid_disks is > 0 and it together with |
| 5340 | * level, size, not_persistent,layout,chunksize determine the |
| 5341 | * shape of the array. |
| 5342 | * This will always create an array with a type-0.90.0 superblock. |
| 5343 | * The newer usage is when assembling an array. |
| 5344 | * In this case raid_disks will be 0, and the major_version field is |
| 5345 | * use to determine which style super-blocks are to be found on the devices. |
| 5346 | * The minor and patch _version numbers are also kept incase the |
| 5347 | * super_block handler wishes to interpret them. |
| 5348 | */ |
| 5349 | static int set_array_info(mddev_t * mddev, mdu_array_info_t *info) |
| 5350 | { |
| 5351 | |
| 5352 | if (info->raid_disks == 0) { |
| 5353 | /* just setting version number for superblock loading */ |
| 5354 | if (info->major_version < 0 || |
Ahmed S. Darwish | 50511da | 2007-05-09 02:35:34 -0700 | [diff] [blame] | 5355 | info->major_version >= ARRAY_SIZE(super_types) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | super_types[info->major_version].name == NULL) { |
| 5357 | /* maybe try to auto-load a module? */ |
| 5358 | printk(KERN_INFO |
| 5359 | "md: superblock version %d not known\n", |
| 5360 | info->major_version); |
| 5361 | return -EINVAL; |
| 5362 | } |
| 5363 | mddev->major_version = info->major_version; |
| 5364 | mddev->minor_version = info->minor_version; |
| 5365 | mddev->patch_version = info->patch_version; |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 5366 | mddev->persistent = !info->not_persistent; |
NeilBrown | cbd1998 | 2009-12-30 12:08:49 +1100 | [diff] [blame] | 5367 | /* ensure mddev_put doesn't delete this now that there |
| 5368 | * is some minimal configuration. |
| 5369 | */ |
| 5370 | mddev->ctime = get_seconds(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5371 | return 0; |
| 5372 | } |
| 5373 | mddev->major_version = MD_MAJOR_VERSION; |
| 5374 | mddev->minor_version = MD_MINOR_VERSION; |
| 5375 | mddev->patch_version = MD_PATCHLEVEL_VERSION; |
| 5376 | mddev->ctime = get_seconds(); |
| 5377 | |
| 5378 | mddev->level = info->level; |
NeilBrown | 17115e0 | 2006-01-16 22:14:57 -0800 | [diff] [blame] | 5379 | mddev->clevel[0] = 0; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5380 | mddev->dev_sectors = 2 * (sector_t)info->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5381 | mddev->raid_disks = info->raid_disks; |
| 5382 | /* don't set md_minor, it is determined by which /dev/md* was |
| 5383 | * openned |
| 5384 | */ |
| 5385 | if (info->state & (1<<MD_SB_CLEAN)) |
| 5386 | mddev->recovery_cp = MaxSector; |
| 5387 | else |
| 5388 | mddev->recovery_cp = 0; |
| 5389 | mddev->persistent = ! info->not_persistent; |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 5390 | mddev->external = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | |
| 5392 | mddev->layout = info->layout; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5393 | mddev->chunk_sectors = info->chunk_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5394 | |
| 5395 | mddev->max_disks = MD_SB_DISKS; |
| 5396 | |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 5397 | if (mddev->persistent) |
| 5398 | mddev->flags = 0; |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5399 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5401 | mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9; |
| 5402 | mddev->bitmap_info.offset = 0; |
NeilBrown | b2a2703 | 2005-11-28 13:44:12 -0800 | [diff] [blame] | 5403 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5404 | mddev->reshape_position = MaxSector; |
| 5405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5406 | /* |
| 5407 | * Generate a 128 bit UUID |
| 5408 | */ |
| 5409 | get_random_bytes(mddev->uuid, 16); |
| 5410 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5411 | mddev->new_level = mddev->level; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5412 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5413 | mddev->new_layout = mddev->layout; |
| 5414 | mddev->delta_disks = 0; |
| 5415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | return 0; |
| 5417 | } |
| 5418 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5419 | void md_set_array_sectors(mddev_t *mddev, sector_t array_sectors) |
| 5420 | { |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5421 | WARN(!mddev_is_locked(mddev), "%s: unlocked mddev!\n", __func__); |
| 5422 | |
| 5423 | if (mddev->external_size) |
| 5424 | return; |
| 5425 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5426 | mddev->array_sectors = array_sectors; |
| 5427 | } |
| 5428 | EXPORT_SYMBOL(md_set_array_sectors); |
| 5429 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5430 | static int update_size(mddev_t *mddev, sector_t num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5431 | { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5432 | mdk_rdev_t *rdev; |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5433 | int rv; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5434 | int fit = (num_sectors == 0); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5435 | |
| 5436 | if (mddev->pers->resize == NULL) |
| 5437 | return -EINVAL; |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5438 | /* The "num_sectors" is the number of sectors of each device that |
| 5439 | * is used. This can only make sense for arrays with redundancy. |
| 5440 | * linear and raid0 always use whatever space is available. We can only |
| 5441 | * consider changing this number if no resync or reconstruction is |
| 5442 | * 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] | 5443 | * 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] | 5444 | * of each device. If num_sectors is zero, we find the largest size |
| 5445 | * that fits. |
| 5446 | |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5447 | */ |
| 5448 | if (mddev->sync_thread) |
| 5449 | return -EBUSY; |
NeilBrown | dba034e | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 5450 | if (mddev->bitmap) |
| 5451 | /* Sorry, cannot grow a bitmap yet, just remove it, |
| 5452 | * grow, and re-add. |
| 5453 | */ |
| 5454 | return -EBUSY; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5455 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5456 | sector_t avail = rdev->sectors; |
NeilBrown | 01ab566 | 2006-10-28 10:38:30 -0700 | [diff] [blame] | 5457 | |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5458 | if (fit && (num_sectors == 0 || num_sectors > avail)) |
| 5459 | num_sectors = avail; |
| 5460 | if (avail < num_sectors) |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5461 | return -ENOSPC; |
| 5462 | } |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5463 | rv = mddev->pers->resize(mddev, num_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5464 | if (!rv) |
| 5465 | revalidate_disk(mddev->gendisk); |
NeilBrown | a35b0d6 | 2006-01-06 00:20:49 -0800 | [diff] [blame] | 5466 | return rv; |
| 5467 | } |
| 5468 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5469 | static int update_raid_disks(mddev_t *mddev, int raid_disks) |
| 5470 | { |
| 5471 | int rv; |
| 5472 | /* change the number of raid disks */ |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5473 | if (mddev->pers->check_reshape == NULL) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5474 | return -EINVAL; |
| 5475 | if (raid_disks <= 0 || |
NeilBrown | 233fca3 | 2010-04-14 17:02:09 +1000 | [diff] [blame] | 5476 | (mddev->max_disks && raid_disks >= mddev->max_disks)) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5477 | return -EINVAL; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5478 | if (mddev->sync_thread || mddev->reshape_position != MaxSector) |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5479 | return -EBUSY; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5480 | mddev->delta_disks = raid_disks - mddev->raid_disks; |
| 5481 | |
| 5482 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5483 | return rv; |
| 5484 | } |
| 5485 | |
| 5486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | /* |
| 5488 | * update_array_info is used to change the configuration of an |
| 5489 | * on-line array. |
| 5490 | * The version, ctime,level,size,raid_disks,not_persistent, layout,chunk_size |
| 5491 | * fields in the info are checked against the array. |
| 5492 | * Any differences that cannot be handled will cause an error. |
| 5493 | * Normally, only one change can be managed at a time. |
| 5494 | */ |
| 5495 | static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) |
| 5496 | { |
| 5497 | int rv = 0; |
| 5498 | int cnt = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5499 | int state = 0; |
| 5500 | |
| 5501 | /* calculate expected state,ignoring low bits */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5502 | if (mddev->bitmap && mddev->bitmap_info.offset) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5503 | state |= (1 << MD_SB_BITMAP_PRESENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | |
| 5505 | if (mddev->major_version != info->major_version || |
| 5506 | mddev->minor_version != info->minor_version || |
| 5507 | /* mddev->patch_version != info->patch_version || */ |
| 5508 | mddev->ctime != info->ctime || |
| 5509 | mddev->level != info->level || |
| 5510 | /* mddev->layout != info->layout || */ |
| 5511 | !mddev->persistent != info->not_persistent|| |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5512 | mddev->chunk_sectors != info->chunk_size >> 9 || |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5513 | /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */ |
| 5514 | ((state^info->state) & 0xfffffe00) |
| 5515 | ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | return -EINVAL; |
| 5517 | /* Check there is only one change */ |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5518 | if (info->size >= 0 && mddev->dev_sectors / 2 != info->size) |
| 5519 | cnt++; |
| 5520 | if (mddev->raid_disks != info->raid_disks) |
| 5521 | cnt++; |
| 5522 | if (mddev->layout != info->layout) |
| 5523 | cnt++; |
| 5524 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) |
| 5525 | cnt++; |
| 5526 | if (cnt == 0) |
| 5527 | return 0; |
| 5528 | if (cnt > 1) |
| 5529 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5530 | |
| 5531 | if (mddev->layout != info->layout) { |
| 5532 | /* Change layout |
| 5533 | * we don't need to do anything at the md level, the |
| 5534 | * personality will take care of it all. |
| 5535 | */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5536 | if (mddev->pers->check_reshape == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5538 | else { |
| 5539 | mddev->new_layout = info->layout; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5540 | rv = mddev->pers->check_reshape(mddev); |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5541 | if (rv) |
| 5542 | mddev->new_layout = mddev->layout; |
| 5543 | return rv; |
| 5544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5545 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5546 | if (info->size >= 0 && mddev->dev_sectors / 2 != info->size) |
Andre Noll | d71f9f8 | 2008-07-11 22:02:22 +1000 | [diff] [blame] | 5547 | rv = update_size(mddev, (sector_t)info->size * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5548 | |
NeilBrown | da943b99 | 2006-01-06 00:20:54 -0800 | [diff] [blame] | 5549 | if (mddev->raid_disks != info->raid_disks) |
| 5550 | rv = update_raid_disks(mddev, info->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5551 | |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5552 | if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) { |
| 5553 | if (mddev->pers->quiesce == NULL) |
| 5554 | return -EINVAL; |
| 5555 | if (mddev->recovery || mddev->sync_thread) |
| 5556 | return -EBUSY; |
| 5557 | if (info->state & (1<<MD_SB_BITMAP_PRESENT)) { |
| 5558 | /* add the bitmap */ |
| 5559 | if (mddev->bitmap) |
| 5560 | return -EEXIST; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5561 | if (mddev->bitmap_info.default_offset == 0) |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5562 | return -EINVAL; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5563 | mddev->bitmap_info.offset = |
| 5564 | mddev->bitmap_info.default_offset; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5565 | mddev->pers->quiesce(mddev, 1); |
| 5566 | rv = bitmap_create(mddev); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 5567 | if (!rv) |
| 5568 | rv = bitmap_load(mddev); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5569 | if (rv) |
| 5570 | bitmap_destroy(mddev); |
| 5571 | mddev->pers->quiesce(mddev, 0); |
| 5572 | } else { |
| 5573 | /* remove the bitmap */ |
| 5574 | if (!mddev->bitmap) |
| 5575 | return -ENOENT; |
| 5576 | if (mddev->bitmap->file) |
| 5577 | return -EINVAL; |
| 5578 | mddev->pers->quiesce(mddev, 1); |
| 5579 | bitmap_destroy(mddev); |
| 5580 | mddev->pers->quiesce(mddev, 0); |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 5581 | mddev->bitmap_info.offset = 0; |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 5582 | } |
| 5583 | } |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5584 | md_update_sb(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5585 | return rv; |
| 5586 | } |
| 5587 | |
| 5588 | static int set_disk_faulty(mddev_t *mddev, dev_t dev) |
| 5589 | { |
| 5590 | mdk_rdev_t *rdev; |
| 5591 | |
| 5592 | if (mddev->pers == NULL) |
| 5593 | return -ENODEV; |
| 5594 | |
| 5595 | rdev = find_rdev(mddev, dev); |
| 5596 | if (!rdev) |
| 5597 | return -ENODEV; |
| 5598 | |
| 5599 | md_error(mddev, rdev); |
| 5600 | return 0; |
| 5601 | } |
| 5602 | |
Andre Noll | 2f9618c | 2008-04-25 18:57:58 +0200 | [diff] [blame] | 5603 | /* |
| 5604 | * We have a problem here : there is no easy way to give a CHS |
| 5605 | * virtual geometry. We currently pretend that we have a 2 heads |
| 5606 | * 4 sectors (with a BIG number of cylinders...). This drives |
| 5607 | * dosfs just mad... ;-) |
| 5608 | */ |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5609 | static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 5610 | { |
| 5611 | mddev_t *mddev = bdev->bd_disk->private_data; |
| 5612 | |
| 5613 | geo->heads = 2; |
| 5614 | geo->sectors = 4; |
NeilBrown | 49ce6ce | 2010-03-29 10:51:42 +1100 | [diff] [blame] | 5615 | geo->cylinders = mddev->array_sectors / 8; |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5616 | return 0; |
| 5617 | } |
| 5618 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5619 | static int md_ioctl(struct block_device *bdev, fmode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | unsigned int cmd, unsigned long arg) |
| 5621 | { |
| 5622 | int err = 0; |
| 5623 | void __user *argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | mddev_t *mddev = NULL; |
Dan Williams | e221835 | 2010-05-12 08:25:37 +1000 | [diff] [blame] | 5625 | int ro; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5626 | |
| 5627 | if (!capable(CAP_SYS_ADMIN)) |
| 5628 | return -EACCES; |
| 5629 | |
| 5630 | /* |
| 5631 | * Commands dealing with the RAID driver but not any |
| 5632 | * particular array: |
| 5633 | */ |
| 5634 | switch (cmd) |
| 5635 | { |
| 5636 | case RAID_VERSION: |
| 5637 | err = get_version(argp); |
| 5638 | goto done; |
| 5639 | |
| 5640 | case PRINT_RAID_DEBUG: |
| 5641 | err = 0; |
| 5642 | md_print_devices(); |
| 5643 | goto done; |
| 5644 | |
| 5645 | #ifndef MODULE |
| 5646 | case RAID_AUTORUN: |
| 5647 | err = 0; |
| 5648 | autostart_arrays(arg); |
| 5649 | goto done; |
| 5650 | #endif |
| 5651 | default:; |
| 5652 | } |
| 5653 | |
| 5654 | /* |
| 5655 | * Commands creating/starting a new array: |
| 5656 | */ |
| 5657 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5658 | mddev = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | |
| 5660 | if (!mddev) { |
| 5661 | BUG(); |
| 5662 | goto abort; |
| 5663 | } |
| 5664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5665 | err = mddev_lock(mddev); |
| 5666 | if (err) { |
| 5667 | printk(KERN_INFO |
| 5668 | "md: ioctl lock interrupted, reason %d, cmd %d\n", |
| 5669 | err, cmd); |
| 5670 | goto abort; |
| 5671 | } |
| 5672 | |
| 5673 | switch (cmd) |
| 5674 | { |
| 5675 | case SET_ARRAY_INFO: |
| 5676 | { |
| 5677 | mdu_array_info_t info; |
| 5678 | if (!arg) |
| 5679 | memset(&info, 0, sizeof(info)); |
| 5680 | else if (copy_from_user(&info, argp, sizeof(info))) { |
| 5681 | err = -EFAULT; |
| 5682 | goto abort_unlock; |
| 5683 | } |
| 5684 | if (mddev->pers) { |
| 5685 | err = update_array_info(mddev, &info); |
| 5686 | if (err) { |
| 5687 | printk(KERN_WARNING "md: couldn't update" |
| 5688 | " array info. %d\n", err); |
| 5689 | goto abort_unlock; |
| 5690 | } |
| 5691 | goto done_unlock; |
| 5692 | } |
| 5693 | if (!list_empty(&mddev->disks)) { |
| 5694 | printk(KERN_WARNING |
| 5695 | "md: array %s already has disks!\n", |
| 5696 | mdname(mddev)); |
| 5697 | err = -EBUSY; |
| 5698 | goto abort_unlock; |
| 5699 | } |
| 5700 | if (mddev->raid_disks) { |
| 5701 | printk(KERN_WARNING |
| 5702 | "md: array %s already initialised!\n", |
| 5703 | mdname(mddev)); |
| 5704 | err = -EBUSY; |
| 5705 | goto abort_unlock; |
| 5706 | } |
| 5707 | err = set_array_info(mddev, &info); |
| 5708 | if (err) { |
| 5709 | printk(KERN_WARNING "md: couldn't set" |
| 5710 | " array info. %d\n", err); |
| 5711 | goto abort_unlock; |
| 5712 | } |
| 5713 | } |
| 5714 | goto done_unlock; |
| 5715 | |
| 5716 | default:; |
| 5717 | } |
| 5718 | |
| 5719 | /* |
| 5720 | * Commands querying/configuring an existing array: |
| 5721 | */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5722 | /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY, |
NeilBrown | 3f9d7b0 | 2006-12-22 01:11:41 -0800 | [diff] [blame] | 5723 | * RUN_ARRAY, and GET_ and SET_BITMAP_FILE are allowed */ |
NeilBrown | a17184a | 2008-02-06 01:39:55 -0800 | [diff] [blame] | 5724 | if ((!mddev->raid_disks && !mddev->external) |
| 5725 | && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY |
| 5726 | && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE |
| 5727 | && cmd != GET_BITMAP_FILE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | err = -ENODEV; |
| 5729 | goto abort_unlock; |
| 5730 | } |
| 5731 | |
| 5732 | /* |
| 5733 | * Commands even a read-only array can execute: |
| 5734 | */ |
| 5735 | switch (cmd) |
| 5736 | { |
| 5737 | case GET_ARRAY_INFO: |
| 5738 | err = get_array_info(mddev, argp); |
| 5739 | goto done_unlock; |
| 5740 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5741 | case GET_BITMAP_FILE: |
viro@ZenIV.linux.org.uk | 87162a2 | 2005-09-09 20:36:43 +0100 | [diff] [blame] | 5742 | err = get_bitmap_file(mddev, argp); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5743 | goto done_unlock; |
| 5744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | case GET_DISK_INFO: |
| 5746 | err = get_disk_info(mddev, argp); |
| 5747 | goto done_unlock; |
| 5748 | |
| 5749 | case RESTART_ARRAY_RW: |
| 5750 | err = restart_array(mddev); |
| 5751 | goto done_unlock; |
| 5752 | |
| 5753 | case STOP_ARRAY: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5754 | err = do_md_stop(mddev, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5755 | goto done_unlock; |
| 5756 | |
| 5757 | case STOP_ARRAY_RO: |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 5758 | err = md_set_readonly(mddev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5759 | goto done_unlock; |
| 5760 | |
Dan Williams | e221835 | 2010-05-12 08:25:37 +1000 | [diff] [blame] | 5761 | case BLKROSET: |
| 5762 | if (get_user(ro, (int __user *)(arg))) { |
| 5763 | err = -EFAULT; |
| 5764 | goto done_unlock; |
| 5765 | } |
| 5766 | err = -EINVAL; |
| 5767 | |
| 5768 | /* if the bdev is going readonly the value of mddev->ro |
| 5769 | * does not matter, no writes are coming |
| 5770 | */ |
| 5771 | if (ro) |
| 5772 | goto done_unlock; |
| 5773 | |
| 5774 | /* are we are already prepared for writes? */ |
| 5775 | if (mddev->ro != 1) |
| 5776 | goto done_unlock; |
| 5777 | |
| 5778 | /* transitioning to readauto need only happen for |
| 5779 | * arrays that call md_write_start |
| 5780 | */ |
| 5781 | if (mddev->pers) { |
| 5782 | err = restart_array(mddev); |
| 5783 | if (err == 0) { |
| 5784 | mddev->ro = 2; |
| 5785 | set_disk_ro(mddev->gendisk, 0); |
| 5786 | } |
| 5787 | } |
| 5788 | goto done_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | /* |
| 5792 | * The remaining ioctls are changing the state of the |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5793 | * superblock, so we do not allow them on read-only arrays. |
| 5794 | * However non-MD ioctls (e.g. get-size) will still come through |
| 5795 | * here and hit the 'default' below, so only disallow |
| 5796 | * 'md' ioctls, and switch to rw mode if started auto-readonly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5797 | */ |
Andre Noll | bb57fc6 | 2008-04-25 19:06:35 +0200 | [diff] [blame] | 5798 | if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5799 | if (mddev->ro == 2) { |
| 5800 | mddev->ro = 0; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 5801 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 5802 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5803 | md_wakeup_thread(mddev->thread); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 5804 | } else { |
| 5805 | err = -EROFS; |
| 5806 | goto abort_unlock; |
| 5807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | switch (cmd) |
| 5811 | { |
| 5812 | case ADD_NEW_DISK: |
| 5813 | { |
| 5814 | mdu_disk_info_t info; |
| 5815 | if (copy_from_user(&info, argp, sizeof(info))) |
| 5816 | err = -EFAULT; |
| 5817 | else |
| 5818 | err = add_new_disk(mddev, &info); |
| 5819 | goto done_unlock; |
| 5820 | } |
| 5821 | |
| 5822 | case HOT_REMOVE_DISK: |
| 5823 | err = hot_remove_disk(mddev, new_decode_dev(arg)); |
| 5824 | goto done_unlock; |
| 5825 | |
| 5826 | case HOT_ADD_DISK: |
| 5827 | err = hot_add_disk(mddev, new_decode_dev(arg)); |
| 5828 | goto done_unlock; |
| 5829 | |
| 5830 | case SET_DISK_FAULTY: |
| 5831 | err = set_disk_faulty(mddev, new_decode_dev(arg)); |
| 5832 | goto done_unlock; |
| 5833 | |
| 5834 | case RUN_ARRAY: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5835 | err = do_md_run(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | goto done_unlock; |
| 5837 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 5838 | case SET_BITMAP_FILE: |
| 5839 | err = set_bitmap_file(mddev, (int)arg); |
| 5840 | goto done_unlock; |
| 5841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5843 | err = -EINVAL; |
| 5844 | goto abort_unlock; |
| 5845 | } |
| 5846 | |
| 5847 | done_unlock: |
| 5848 | abort_unlock: |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5849 | if (mddev->hold_active == UNTIL_IOCTL && |
| 5850 | err != -EINVAL) |
| 5851 | mddev->hold_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5852 | mddev_unlock(mddev); |
| 5853 | |
| 5854 | return err; |
| 5855 | done: |
| 5856 | if (err) |
| 5857 | MD_BUG(); |
| 5858 | abort: |
| 5859 | return err; |
| 5860 | } |
Arnd Bergmann | aa98aa3 | 2009-12-14 12:50:05 +1100 | [diff] [blame] | 5861 | #ifdef CONFIG_COMPAT |
| 5862 | static int md_compat_ioctl(struct block_device *bdev, fmode_t mode, |
| 5863 | unsigned int cmd, unsigned long arg) |
| 5864 | { |
| 5865 | switch (cmd) { |
| 5866 | case HOT_REMOVE_DISK: |
| 5867 | case HOT_ADD_DISK: |
| 5868 | case SET_DISK_FAULTY: |
| 5869 | case SET_BITMAP_FILE: |
| 5870 | /* These take in integer arg, do not convert */ |
| 5871 | break; |
| 5872 | default: |
| 5873 | arg = (unsigned long)compat_ptr(arg); |
| 5874 | break; |
| 5875 | } |
| 5876 | |
| 5877 | return md_ioctl(bdev, mode, cmd, arg); |
| 5878 | } |
| 5879 | #endif /* CONFIG_COMPAT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5881 | static int md_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5882 | { |
| 5883 | /* |
| 5884 | * Succeed if we can lock the mddev, which confirms that |
| 5885 | * it isn't being stopped right now. |
| 5886 | */ |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5887 | mddev_t *mddev = mddev_find(bdev->bd_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5888 | int err; |
| 5889 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 5890 | mutex_lock(&md_mutex); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5891 | if (mddev->gendisk != bdev->bd_disk) { |
| 5892 | /* we are racing with mddev_put which is discarding this |
| 5893 | * bd_disk. |
| 5894 | */ |
| 5895 | mddev_put(mddev); |
| 5896 | /* Wait until bdev->bd_disk is definitely gone */ |
| 5897 | flush_scheduled_work(); |
| 5898 | /* Then retry the open from the top */ |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 5899 | mutex_unlock(&md_mutex); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 5900 | return -ERESTARTSYS; |
| 5901 | } |
| 5902 | BUG_ON(mddev != bdev->bd_disk->private_data); |
| 5903 | |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 5904 | if ((err = mutex_lock_interruptible(&mddev->open_mutex))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5905 | goto out; |
| 5906 | |
| 5907 | err = 0; |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 5908 | atomic_inc(&mddev->openers); |
NeilBrown | c8c00a6 | 2009-08-10 12:50:52 +1000 | [diff] [blame] | 5909 | mutex_unlock(&mddev->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5910 | |
NeilBrown | f3b99be | 2010-06-24 13:31:03 +1000 | [diff] [blame] | 5911 | check_disk_size_change(mddev->gendisk, bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5912 | out: |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 5913 | mutex_unlock(&md_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5914 | return err; |
| 5915 | } |
| 5916 | |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5917 | static int md_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5918 | { |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5919 | mddev_t *mddev = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5920 | |
Eric Sesterhenn | 52e5f9d | 2006-10-03 23:33:23 +0200 | [diff] [blame] | 5921 | BUG_ON(!mddev); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 5922 | mutex_lock(&md_mutex); |
NeilBrown | f2ea68c | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 5923 | atomic_dec(&mddev->openers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5924 | mddev_put(mddev); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 5925 | mutex_unlock(&md_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | |
| 5927 | return 0; |
| 5928 | } |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 5929 | static const struct block_device_operations md_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5930 | { |
| 5931 | .owner = THIS_MODULE, |
Al Viro | a39907f | 2008-03-02 10:31:15 -0500 | [diff] [blame] | 5932 | .open = md_open, |
| 5933 | .release = md_release, |
NeilBrown | b492b85 | 2009-05-26 12:57:36 +1000 | [diff] [blame] | 5934 | .ioctl = md_ioctl, |
Arnd Bergmann | aa98aa3 | 2009-12-14 12:50:05 +1100 | [diff] [blame] | 5935 | #ifdef CONFIG_COMPAT |
| 5936 | .compat_ioctl = md_compat_ioctl, |
| 5937 | #endif |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 5938 | .getgeo = md_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | }; |
| 5940 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 5941 | static int md_thread(void * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5942 | { |
| 5943 | mdk_thread_t *thread = arg; |
| 5944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5945 | /* |
| 5946 | * md_thread is a 'system-thread', it's priority should be very |
| 5947 | * high. We avoid resource deadlocks individually in each |
| 5948 | * raid personality. (RAID5 does preallocation) We also use RR and |
| 5949 | * the very same RT priority as kswapd, thus we will never get |
| 5950 | * into a priority inversion deadlock. |
| 5951 | * |
| 5952 | * we definitely have to have equal or higher priority than |
| 5953 | * bdflush, otherwise bdflush will deadlock if there are too |
| 5954 | * many dirty RAID5 blocks. |
| 5955 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5956 | |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 5957 | allow_signal(SIGKILL); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5958 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5959 | |
NeilBrown | 93588e2 | 2005-11-15 00:09:12 -0800 | [diff] [blame] | 5960 | /* We need to wait INTERRUPTIBLE so that |
| 5961 | * we don't add to the load-average. |
| 5962 | * That means we need to be sure no signals are |
| 5963 | * pending |
| 5964 | */ |
| 5965 | if (signal_pending(current)) |
| 5966 | flush_signals(current); |
| 5967 | |
| 5968 | wait_event_interruptible_timeout |
| 5969 | (thread->wqueue, |
| 5970 | test_bit(THREAD_WAKEUP, &thread->flags) |
| 5971 | || kthread_should_stop(), |
| 5972 | thread->timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5973 | |
| 5974 | clear_bit(THREAD_WAKEUP, &thread->flags); |
| 5975 | |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 5976 | thread->run(thread->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5977 | } |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 5978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5979 | return 0; |
| 5980 | } |
| 5981 | |
| 5982 | void md_wakeup_thread(mdk_thread_t *thread) |
| 5983 | { |
| 5984 | if (thread) { |
| 5985 | dprintk("md: waking up MD thread %s.\n", thread->tsk->comm); |
| 5986 | set_bit(THREAD_WAKEUP, &thread->flags); |
| 5987 | wake_up(&thread->wqueue); |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, |
| 5992 | const char *name) |
| 5993 | { |
| 5994 | mdk_thread_t *thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5995 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 5996 | thread = kzalloc(sizeof(mdk_thread_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5997 | if (!thread) |
| 5998 | return NULL; |
| 5999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6000 | init_waitqueue_head(&thread->wqueue); |
| 6001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6002 | thread->run = run; |
| 6003 | thread->mddev = mddev; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6004 | thread->timeout = MAX_SCHEDULE_TIMEOUT; |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 6005 | thread->tsk = kthread_run(md_thread, thread, |
| 6006 | "%s_%s", |
| 6007 | mdname(thread->mddev), |
| 6008 | name ?: mddev->pers->name); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6009 | if (IS_ERR(thread->tsk)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | kfree(thread); |
| 6011 | return NULL; |
| 6012 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | return thread; |
| 6014 | } |
| 6015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | void md_unregister_thread(mdk_thread_t *thread) |
| 6017 | { |
NeilBrown | e0cf8f0 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6018 | if (!thread) |
| 6019 | return; |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 6020 | dprintk("interrupting MD-thread pid %d\n", task_pid_nr(thread->tsk)); |
NeilBrown | a6fb093 | 2005-09-09 16:23:56 -0700 | [diff] [blame] | 6021 | |
| 6022 | kthread_stop(thread->tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6023 | kfree(thread); |
| 6024 | } |
| 6025 | |
| 6026 | void md_error(mddev_t *mddev, mdk_rdev_t *rdev) |
| 6027 | { |
| 6028 | if (!mddev) { |
| 6029 | MD_BUG(); |
| 6030 | return; |
| 6031 | } |
| 6032 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6033 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6034 | return; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 6035 | |
| 6036 | if (mddev->external) |
| 6037 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6038 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6039 | dprintk("md_error dev:%s, rdev:(%d:%d), (caller: %p,%p,%p,%p).\n", |
| 6040 | mdname(mddev), |
| 6041 | MAJOR(rdev->bdev->bd_dev), MINOR(rdev->bdev->bd_dev), |
| 6042 | __builtin_return_address(0),__builtin_return_address(1), |
| 6043 | __builtin_return_address(2),__builtin_return_address(3)); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6044 | */ |
Andrew Morton | d0a0a5e | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 6045 | if (!mddev->pers) |
| 6046 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6047 | if (!mddev->pers->error_handler) |
| 6048 | return; |
| 6049 | mddev->pers->error_handler(mddev,rdev); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 6050 | if (mddev->degraded) |
| 6051 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6052 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6053 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 6054 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6055 | md_wakeup_thread(mddev->thread); |
NeilBrown | 768a418 | 2010-07-26 11:49:55 +1000 | [diff] [blame] | 6056 | if (mddev->event_work.func) |
| 6057 | schedule_work(&mddev->event_work); |
NeilBrown | c331eb0 | 2006-05-30 21:27:13 -0700 | [diff] [blame] | 6058 | md_new_event_inintr(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6059 | } |
| 6060 | |
| 6061 | /* seq_file implementation /proc/mdstat */ |
| 6062 | |
| 6063 | static void status_unused(struct seq_file *seq) |
| 6064 | { |
| 6065 | int i = 0; |
| 6066 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6067 | |
| 6068 | seq_printf(seq, "unused devices: "); |
| 6069 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6070 | list_for_each_entry(rdev, &pending_raid_disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6071 | char b[BDEVNAME_SIZE]; |
| 6072 | i++; |
| 6073 | seq_printf(seq, "%s ", |
| 6074 | bdevname(rdev->bdev,b)); |
| 6075 | } |
| 6076 | if (!i) |
| 6077 | seq_printf(seq, "<none>"); |
| 6078 | |
| 6079 | seq_printf(seq, "\n"); |
| 6080 | } |
| 6081 | |
| 6082 | |
| 6083 | static void status_resync(struct seq_file *seq, mddev_t * mddev) |
| 6084 | { |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6085 | sector_t max_sectors, resync, res; |
| 6086 | unsigned long dt, db; |
| 6087 | sector_t rt; |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6088 | int scale; |
| 6089 | unsigned int per_milli; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6090 | |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6091 | resync = mddev->curr_resync - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6092 | |
| 6093 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6094 | max_sectors = mddev->resync_max_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6095 | else |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6096 | max_sectors = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6097 | |
| 6098 | /* |
| 6099 | * Should not happen. |
| 6100 | */ |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6101 | if (!max_sectors) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6102 | MD_BUG(); |
| 6103 | return; |
| 6104 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6105 | /* Pick 'scale' such that (resync>>scale)*1000 will fit |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6106 | * in a sector_t, and (max_sectors>>scale) will fit in a |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6107 | * u32, as those are the requirements for sector_div. |
| 6108 | * Thus 'scale' must be at least 10 |
| 6109 | */ |
| 6110 | scale = 10; |
| 6111 | if (sizeof(sector_t) > sizeof(unsigned long)) { |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6112 | while ( max_sectors/2 > (1ULL<<(scale+32))) |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6113 | scale++; |
| 6114 | } |
| 6115 | res = (resync>>scale)*1000; |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6116 | sector_div(res, (u32)((max_sectors>>scale)+1)); |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6117 | |
| 6118 | per_milli = res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6119 | { |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6120 | int i, x = per_milli/50, y = 20-x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | seq_printf(seq, "["); |
| 6122 | for (i = 0; i < x; i++) |
| 6123 | seq_printf(seq, "="); |
| 6124 | seq_printf(seq, ">"); |
| 6125 | for (i = 0; i < y; i++) |
| 6126 | seq_printf(seq, "."); |
| 6127 | seq_printf(seq, "] "); |
| 6128 | } |
NeilBrown | 4588b42 | 2006-03-27 01:18:04 -0800 | [diff] [blame] | 6129 | seq_printf(seq, " %s =%3u.%u%% (%llu/%llu)", |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 6130 | (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)? |
| 6131 | "reshape" : |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6132 | (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)? |
| 6133 | "check" : |
| 6134 | (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ? |
| 6135 | "resync" : "recovery"))), |
| 6136 | per_milli/10, per_milli % 10, |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6137 | (unsigned long long) resync/2, |
| 6138 | (unsigned long long) max_sectors/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6139 | |
| 6140 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6141 | * dt: time from mark until now |
| 6142 | * db: blocks written from mark until now |
| 6143 | * rt: remaining time |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6144 | * |
| 6145 | * rt is a sector_t, so could be 32bit or 64bit. |
| 6146 | * So we divide before multiply in case it is 32bit and close |
| 6147 | * to the limit. |
| 6148 | * We scale the divisor (db) by 32 to avoid loosing precision |
| 6149 | * near the end of resync when the number of remaining sectors |
| 6150 | * is close to 'db'. |
| 6151 | * We then divide rt by 32 after multiplying by db to compensate. |
| 6152 | * The '+1' avoids division by zero if db is very small. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6153 | */ |
| 6154 | dt = ((jiffies - mddev->resync_mark) / HZ); |
| 6155 | if (!dt) dt++; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6156 | db = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active)) |
| 6157 | - mddev->resync_mark_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6158 | |
NeilBrown | dd71cf6 | 2009-05-07 12:49:35 +1000 | [diff] [blame] | 6159 | rt = max_sectors - resync; /* number of remaining sectors */ |
| 6160 | sector_div(rt, db/32+1); |
| 6161 | rt *= dt; |
| 6162 | rt >>= 5; |
| 6163 | |
| 6164 | seq_printf(seq, " finish=%lu.%lumin", (unsigned long)rt / 60, |
| 6165 | ((unsigned long)rt % 60)/6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6166 | |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6167 | seq_printf(seq, " speed=%ldK/sec", db/2/dt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6168 | } |
| 6169 | |
| 6170 | static void *md_seq_start(struct seq_file *seq, loff_t *pos) |
| 6171 | { |
| 6172 | struct list_head *tmp; |
| 6173 | loff_t l = *pos; |
| 6174 | mddev_t *mddev; |
| 6175 | |
| 6176 | if (l >= 0x10000) |
| 6177 | return NULL; |
| 6178 | if (!l--) |
| 6179 | /* header */ |
| 6180 | return (void*)1; |
| 6181 | |
| 6182 | spin_lock(&all_mddevs_lock); |
| 6183 | list_for_each(tmp,&all_mddevs) |
| 6184 | if (!l--) { |
| 6185 | mddev = list_entry(tmp, mddev_t, all_mddevs); |
| 6186 | mddev_get(mddev); |
| 6187 | spin_unlock(&all_mddevs_lock); |
| 6188 | return mddev; |
| 6189 | } |
| 6190 | spin_unlock(&all_mddevs_lock); |
| 6191 | if (!l--) |
| 6192 | return (void*)2;/* tail */ |
| 6193 | return NULL; |
| 6194 | } |
| 6195 | |
| 6196 | static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 6197 | { |
| 6198 | struct list_head *tmp; |
| 6199 | mddev_t *next_mddev, *mddev = v; |
| 6200 | |
| 6201 | ++*pos; |
| 6202 | if (v == (void*)2) |
| 6203 | return NULL; |
| 6204 | |
| 6205 | spin_lock(&all_mddevs_lock); |
| 6206 | if (v == (void*)1) |
| 6207 | tmp = all_mddevs.next; |
| 6208 | else |
| 6209 | tmp = mddev->all_mddevs.next; |
| 6210 | if (tmp != &all_mddevs) |
| 6211 | next_mddev = mddev_get(list_entry(tmp,mddev_t,all_mddevs)); |
| 6212 | else { |
| 6213 | next_mddev = (void*)2; |
| 6214 | *pos = 0x10000; |
| 6215 | } |
| 6216 | spin_unlock(&all_mddevs_lock); |
| 6217 | |
| 6218 | if (v != (void*)1) |
| 6219 | mddev_put(mddev); |
| 6220 | return next_mddev; |
| 6221 | |
| 6222 | } |
| 6223 | |
| 6224 | static void md_seq_stop(struct seq_file *seq, void *v) |
| 6225 | { |
| 6226 | mddev_t *mddev = v; |
| 6227 | |
| 6228 | if (mddev && v != (void*)1 && v != (void*)2) |
| 6229 | mddev_put(mddev); |
| 6230 | } |
| 6231 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6232 | struct mdstat_info { |
| 6233 | int event; |
| 6234 | }; |
| 6235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6236 | static int md_seq_show(struct seq_file *seq, void *v) |
| 6237 | { |
| 6238 | mddev_t *mddev = v; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6239 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6240 | mdk_rdev_t *rdev; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6241 | struct mdstat_info *mi = seq->private; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6242 | struct bitmap *bitmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | |
| 6244 | if (v == (void*)1) { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6245 | struct mdk_personality *pers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6246 | seq_printf(seq, "Personalities : "); |
| 6247 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6248 | list_for_each_entry(pers, &pers_list, list) |
| 6249 | seq_printf(seq, "[%s] ", pers->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6250 | |
| 6251 | spin_unlock(&pers_lock); |
| 6252 | seq_printf(seq, "\n"); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6253 | mi->event = atomic_read(&md_event_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6254 | return 0; |
| 6255 | } |
| 6256 | if (v == (void*)2) { |
| 6257 | status_unused(seq); |
| 6258 | return 0; |
| 6259 | } |
| 6260 | |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 6261 | if (mddev_lock(mddev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6262 | return -EINTR; |
Ingo Molnar | 5dc5cf7 | 2006-04-20 02:43:23 -0700 | [diff] [blame] | 6263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6264 | if (mddev->pers || mddev->raid_disks || !list_empty(&mddev->disks)) { |
| 6265 | seq_printf(seq, "%s : %sactive", mdname(mddev), |
| 6266 | mddev->pers ? "" : "in"); |
| 6267 | if (mddev->pers) { |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6268 | if (mddev->ro==1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | seq_printf(seq, " (read-only)"); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6270 | if (mddev->ro==2) |
NeilBrown | 52720ae | 2008-03-10 11:43:47 -0700 | [diff] [blame] | 6271 | seq_printf(seq, " (auto-read-only)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6272 | seq_printf(seq, " %s", mddev->pers->name); |
| 6273 | } |
| 6274 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6275 | sectors = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6276 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6277 | char b[BDEVNAME_SIZE]; |
| 6278 | seq_printf(seq, " %s[%d]", |
| 6279 | bdevname(rdev->bdev,b), rdev->desc_nr); |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 6280 | if (test_bit(WriteMostly, &rdev->flags)) |
| 6281 | seq_printf(seq, "(W)"); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6282 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6283 | seq_printf(seq, "(F)"); |
| 6284 | continue; |
NeilBrown | b325a32 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6285 | } else if (rdev->raid_disk < 0) |
| 6286 | seq_printf(seq, "(S)"); /* spare */ |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6287 | sectors += rdev->sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | if (!list_empty(&mddev->disks)) { |
| 6291 | if (mddev->pers) |
| 6292 | seq_printf(seq, "\n %llu blocks", |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 6293 | (unsigned long long) |
| 6294 | mddev->array_sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6295 | else |
| 6296 | seq_printf(seq, "\n %llu blocks", |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6297 | (unsigned long long)sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | } |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6299 | if (mddev->persistent) { |
| 6300 | if (mddev->major_version != 0 || |
| 6301 | mddev->minor_version != 90) { |
| 6302 | seq_printf(seq," super %d.%d", |
| 6303 | mddev->major_version, |
| 6304 | mddev->minor_version); |
| 6305 | } |
NeilBrown | e691063 | 2008-02-06 01:39:51 -0800 | [diff] [blame] | 6306 | } else if (mddev->external) |
| 6307 | seq_printf(seq, " super external:%s", |
| 6308 | mddev->metadata_type); |
| 6309 | else |
NeilBrown | 1cd6bf1 | 2005-09-09 16:24:00 -0700 | [diff] [blame] | 6310 | seq_printf(seq, " super non-persistent"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6311 | |
| 6312 | if (mddev->pers) { |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6313 | mddev->pers->status(seq, mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6314 | seq_printf(seq, "\n "); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 6315 | if (mddev->pers->sync_request) { |
| 6316 | if (mddev->curr_resync > 2) { |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6317 | status_resync(seq, mddev); |
NeilBrown | 8e1b39d | 2005-11-08 21:39:41 -0800 | [diff] [blame] | 6318 | seq_printf(seq, "\n "); |
| 6319 | } else if (mddev->curr_resync == 1 || mddev->curr_resync == 2) |
| 6320 | seq_printf(seq, "\tresync=DELAYED\n "); |
| 6321 | else if (mddev->recovery_cp < MaxSector) |
| 6322 | seq_printf(seq, "\tresync=PENDING\n "); |
| 6323 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6324 | } else |
| 6325 | seq_printf(seq, "\n "); |
| 6326 | |
| 6327 | if ((bitmap = mddev->bitmap)) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6328 | unsigned long chunk_kb; |
| 6329 | unsigned long flags; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6330 | spin_lock_irqsave(&bitmap->lock, flags); |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 6331 | chunk_kb = mddev->bitmap_info.chunksize >> 10; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6332 | seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], " |
| 6333 | "%lu%s chunk", |
| 6334 | bitmap->pages - bitmap->missing_pages, |
| 6335 | bitmap->pages, |
| 6336 | (bitmap->pages - bitmap->missing_pages) |
| 6337 | << (PAGE_SHIFT - 10), |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 6338 | chunk_kb ? chunk_kb : mddev->bitmap_info.chunksize, |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6339 | chunk_kb ? "KB" : "B"); |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 6340 | if (bitmap->file) { |
| 6341 | seq_printf(seq, ", file: "); |
Jan Blunck | c32c2f6 | 2008-02-14 19:38:43 -0800 | [diff] [blame] | 6342 | seq_path(seq, &bitmap->file->f_path, " \t\n"); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6343 | } |
NeilBrown | 78d742d | 2005-06-21 17:17:15 -0700 | [diff] [blame] | 6344 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 6345 | seq_printf(seq, "\n"); |
| 6346 | spin_unlock_irqrestore(&bitmap->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6347 | } |
| 6348 | |
| 6349 | seq_printf(seq, "\n"); |
| 6350 | } |
| 6351 | mddev_unlock(mddev); |
| 6352 | |
| 6353 | return 0; |
| 6354 | } |
| 6355 | |
Jan Engelhardt | 110518b | 2009-05-07 12:49:37 +1000 | [diff] [blame] | 6356 | static const struct seq_operations md_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6357 | .start = md_seq_start, |
| 6358 | .next = md_seq_next, |
| 6359 | .stop = md_seq_stop, |
| 6360 | .show = md_seq_show, |
| 6361 | }; |
| 6362 | |
| 6363 | static int md_seq_open(struct inode *inode, struct file *file) |
| 6364 | { |
| 6365 | int error; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6366 | struct mdstat_info *mi = kmalloc(sizeof(*mi), GFP_KERNEL); |
| 6367 | if (mi == NULL) |
| 6368 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6369 | |
| 6370 | error = seq_open(file, &md_seq_ops); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6371 | if (error) |
| 6372 | kfree(mi); |
| 6373 | else { |
| 6374 | struct seq_file *p = file->private_data; |
| 6375 | p->private = mi; |
| 6376 | mi->event = atomic_read(&md_event_count); |
| 6377 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6378 | return error; |
| 6379 | } |
| 6380 | |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6381 | static unsigned int mdstat_poll(struct file *filp, poll_table *wait) |
| 6382 | { |
| 6383 | struct seq_file *m = filp->private_data; |
| 6384 | struct mdstat_info *mi = m->private; |
| 6385 | int mask; |
| 6386 | |
| 6387 | poll_wait(filp, &md_event_waiters, wait); |
| 6388 | |
| 6389 | /* always allow read */ |
| 6390 | mask = POLLIN | POLLRDNORM; |
| 6391 | |
| 6392 | if (mi->event != atomic_read(&md_event_count)) |
| 6393 | mask |= POLLERR | POLLPRI; |
| 6394 | return mask; |
| 6395 | } |
| 6396 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 6397 | static const struct file_operations md_seq_fops = { |
Akinobu Mita | e24650c | 2006-10-17 00:09:38 -0700 | [diff] [blame] | 6398 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6399 | .open = md_seq_open, |
| 6400 | .read = seq_read, |
| 6401 | .llseek = seq_lseek, |
Martin Peschke | c3f94b40 | 2007-05-09 02:35:35 -0700 | [diff] [blame] | 6402 | .release = seq_release_private, |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6403 | .poll = mdstat_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6404 | }; |
| 6405 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6406 | int register_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6407 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6408 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6409 | list_add_tail(&p->list, &pers_list); |
| 6410 | 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] | 6411 | spin_unlock(&pers_lock); |
| 6412 | return 0; |
| 6413 | } |
| 6414 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6415 | int unregister_md_personality(struct mdk_personality *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6416 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6417 | printk(KERN_INFO "md: %s personality unregistered\n", p->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6418 | spin_lock(&pers_lock); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6419 | list_del_init(&p->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6420 | spin_unlock(&pers_lock); |
| 6421 | return 0; |
| 6422 | } |
| 6423 | |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6424 | static int is_mddev_idle(mddev_t *mddev, int init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6425 | { |
| 6426 | mdk_rdev_t * rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6427 | int idle; |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6428 | int curr_events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6429 | |
| 6430 | idle = 1; |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 6431 | rcu_read_lock(); |
| 6432 | rdev_for_each_rcu(rdev, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6433 | struct gendisk *disk = rdev->bdev->bd_contains->bd_disk; |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6434 | curr_events = (int)part_stat_read(&disk->part0, sectors[0]) + |
| 6435 | (int)part_stat_read(&disk->part0, sectors[1]) - |
| 6436 | atomic_read(&disk->sync_io); |
NeilBrown | 713f6ab | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 6437 | /* sync IO will cause sync_io to increase before the disk_stats |
| 6438 | * as sync_io is counted when a request starts, and |
| 6439 | * disk_stats is counted when it completes. |
| 6440 | * So resync activity will cause curr_events to be smaller than |
| 6441 | * when there was no such activity. |
| 6442 | * non-sync IO will cause disk_stat to increase without |
| 6443 | * increasing sync_io so curr_events will (eventually) |
| 6444 | * be larger than it was before. Once it becomes |
| 6445 | * substantially larger, the test below will cause |
| 6446 | * the array to appear non-idle, and resync will slow |
| 6447 | * down. |
| 6448 | * If there is a lot of outstanding resync activity when |
| 6449 | * we set last_event to curr_events, then all that activity |
| 6450 | * completing might cause the array to appear non-idle |
| 6451 | * and resync will be slowed down even though there might |
| 6452 | * not have been non-resync activity. This will only |
| 6453 | * happen once though. 'last_events' will soon reflect |
| 6454 | * the state where there is little or no outstanding |
| 6455 | * resync requests, and further resync activity will |
| 6456 | * always make curr_events less than last_events. |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 6457 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6458 | */ |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6459 | if (init || curr_events - rdev->last_events > 64) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6460 | rdev->last_events = curr_events; |
| 6461 | idle = 0; |
| 6462 | } |
| 6463 | } |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 6464 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6465 | return idle; |
| 6466 | } |
| 6467 | |
| 6468 | void md_done_sync(mddev_t *mddev, int blocks, int ok) |
| 6469 | { |
| 6470 | /* another "blocks" (512byte) blocks have been synced */ |
| 6471 | atomic_sub(blocks, &mddev->recovery_active); |
| 6472 | wake_up(&mddev->recovery_wait); |
| 6473 | if (!ok) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6474 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6475 | md_wakeup_thread(mddev->thread); |
| 6476 | // stop recovery, signal do_sync .... |
| 6477 | } |
| 6478 | } |
| 6479 | |
| 6480 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6481 | /* md_write_start(mddev, bi) |
| 6482 | * If we need to update some array metadata (e.g. 'active' flag |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6483 | * in superblock) before writing, schedule a superblock update |
| 6484 | * and wait for it to complete. |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6485 | */ |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6486 | void md_write_start(mddev_t *mddev, struct bio *bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6487 | { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6488 | int did_change = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6489 | if (bio_data_dir(bi) != WRITE) |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6490 | return; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6491 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6492 | BUG_ON(mddev->ro == 1); |
| 6493 | if (mddev->ro == 2) { |
| 6494 | /* need to switch to read/write */ |
| 6495 | mddev->ro = 0; |
| 6496 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6497 | md_wakeup_thread(mddev->thread); |
NeilBrown | 2515619 | 2008-03-04 14:29:32 -0800 | [diff] [blame] | 6498 | md_wakeup_thread(mddev->sync_thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6499 | did_change = 1; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 6500 | } |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6501 | atomic_inc(&mddev->writes_pending); |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6502 | if (mddev->safemode == 1) |
| 6503 | mddev->safemode = 0; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6504 | if (mddev->in_sync) { |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 6505 | spin_lock_irq(&mddev->write_lock); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6506 | if (mddev->in_sync) { |
| 6507 | mddev->in_sync = 0; |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6508 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 6509 | set_bit(MD_CHANGE_PENDING, &mddev->flags); |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6510 | md_wakeup_thread(mddev->thread); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6511 | did_change = 1; |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 6512 | } |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 6513 | spin_unlock_irq(&mddev->write_lock); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 6514 | } |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 6515 | if (did_change) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6516 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 09a44cc | 2008-05-23 13:04:36 -0700 | [diff] [blame] | 6517 | wait_event(mddev->sb_wait, |
NeilBrown | 09a44cc | 2008-05-23 13:04:36 -0700 | [diff] [blame] | 6518 | !test_bit(MD_CHANGE_PENDING, &mddev->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6519 | } |
| 6520 | |
| 6521 | void md_write_end(mddev_t *mddev) |
| 6522 | { |
| 6523 | if (atomic_dec_and_test(&mddev->writes_pending)) { |
| 6524 | if (mddev->safemode == 2) |
| 6525 | md_wakeup_thread(mddev->thread); |
NeilBrown | 16f17b3 | 2006-06-26 00:27:37 -0700 | [diff] [blame] | 6526 | else if (mddev->safemode_delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6527 | mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay); |
| 6528 | } |
| 6529 | } |
| 6530 | |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6531 | /* md_allow_write(mddev) |
| 6532 | * Calling this ensures that the array is marked 'active' so that writes |
| 6533 | * may proceed without blocking. It is important to call this before |
| 6534 | * attempting a GFP_KERNEL allocation while holding the mddev lock. |
| 6535 | * Must be called with mddev_lock held. |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6536 | * |
| 6537 | * In the ->external case MD_CHANGE_CLEAN can not be cleared until mddev->lock |
| 6538 | * is dropped, so return -EAGAIN after notifying userspace. |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6539 | */ |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6540 | int md_allow_write(mddev_t *mddev) |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6541 | { |
| 6542 | if (!mddev->pers) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6543 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6544 | if (mddev->ro) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6545 | return 0; |
Neil Brown | 1a0fd49 | 2008-06-28 08:31:27 +1000 | [diff] [blame] | 6546 | if (!mddev->pers->sync_request) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6547 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6548 | |
| 6549 | spin_lock_irq(&mddev->write_lock); |
| 6550 | if (mddev->in_sync) { |
| 6551 | mddev->in_sync = 0; |
| 6552 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 6553 | set_bit(MD_CHANGE_PENDING, &mddev->flags); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6554 | if (mddev->safemode_delay && |
| 6555 | mddev->safemode == 0) |
| 6556 | mddev->safemode = 1; |
| 6557 | spin_unlock_irq(&mddev->write_lock); |
| 6558 | md_update_sb(mddev, 0); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6559 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6560 | } else |
| 6561 | spin_unlock_irq(&mddev->write_lock); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6562 | |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 6563 | if (test_bit(MD_CHANGE_PENDING, &mddev->flags)) |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6564 | return -EAGAIN; |
| 6565 | else |
| 6566 | return 0; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 6567 | } |
| 6568 | EXPORT_SYMBOL_GPL(md_allow_write); |
| 6569 | |
NeilBrown | b63d7c2 | 2010-06-01 19:37:33 +1000 | [diff] [blame] | 6570 | void md_unplug(mddev_t *mddev) |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6571 | { |
| 6572 | if (mddev->queue) |
| 6573 | blk_unplug(mddev->queue); |
| 6574 | if (mddev->plug) |
| 6575 | mddev->plug->unplug_fn(mddev->plug); |
| 6576 | } |
| 6577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6578 | #define SYNC_MARKS 10 |
| 6579 | #define SYNC_MARK_STEP (3*HZ) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6580 | void md_do_sync(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6581 | { |
| 6582 | mddev_t *mddev2; |
| 6583 | unsigned int currspeed = 0, |
| 6584 | window; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6585 | sector_t max_sectors,j, io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6586 | unsigned long mark[SYNC_MARKS]; |
| 6587 | sector_t mark_cnt[SYNC_MARKS]; |
| 6588 | int last_mark,m; |
| 6589 | struct list_head *tmp; |
| 6590 | sector_t last_check; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6591 | int skipped = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6592 | mdk_rdev_t *rdev; |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6593 | char *desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6594 | |
| 6595 | /* just incase thread restarts... */ |
| 6596 | if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) |
| 6597 | return; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6598 | if (mddev->ro) /* never try to sync a read-only array */ |
| 6599 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6600 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6601 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 6602 | if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 6603 | desc = "data-check"; |
| 6604 | else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6605 | desc = "requested-resync"; |
| 6606 | else |
| 6607 | desc = "resync"; |
| 6608 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 6609 | desc = "reshape"; |
| 6610 | else |
| 6611 | desc = "recovery"; |
| 6612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6613 | /* we overload curr_resync somewhat here. |
| 6614 | * 0 == not engaged in resync at all |
| 6615 | * 2 == checking that there is no conflict with another sync |
| 6616 | * 1 == like 2, but have yielded to allow conflicting resync to |
| 6617 | * commense |
| 6618 | * other == active in resync - this many blocks |
| 6619 | * |
| 6620 | * Before starting a resync we must have set curr_resync to |
| 6621 | * 2, and then checked that every "conflicting" array has curr_resync |
| 6622 | * less than ours. When we find one that is the same or higher |
| 6623 | * we wait on resync_wait. To avoid deadlock, we reduce curr_resync |
| 6624 | * to 1 if we choose to yield (based arbitrarily on address of mddev structure). |
| 6625 | * This will mean we have to start checking from the beginning again. |
| 6626 | * |
| 6627 | */ |
| 6628 | |
| 6629 | do { |
| 6630 | mddev->curr_resync = 2; |
| 6631 | |
| 6632 | try_again: |
NeilBrown | 404e4b4 | 2009-12-30 15:25:23 +1100 | [diff] [blame] | 6633 | if (kthread_should_stop()) |
NeilBrown | 6985c43 | 2005-10-19 21:23:47 -0700 | [diff] [blame] | 6634 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
NeilBrown | 404e4b4 | 2009-12-30 15:25:23 +1100 | [diff] [blame] | 6635 | |
| 6636 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6637 | goto skip; |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 6638 | for_each_mddev(mddev2, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6639 | if (mddev2 == mddev) |
| 6640 | continue; |
Bernd Schubert | 90b0871 | 2008-05-23 13:04:38 -0700 | [diff] [blame] | 6641 | if (!mddev->parallel_resync |
| 6642 | && mddev2->curr_resync |
| 6643 | && match_mddev_units(mddev, mddev2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6644 | DEFINE_WAIT(wq); |
| 6645 | if (mddev < mddev2 && mddev->curr_resync == 2) { |
| 6646 | /* arbitrarily yield */ |
| 6647 | mddev->curr_resync = 1; |
| 6648 | wake_up(&resync_wait); |
| 6649 | } |
| 6650 | if (mddev > mddev2 && mddev->curr_resync == 1) |
| 6651 | /* no need to wait here, we can wait the next |
| 6652 | * time 'round when curr_resync == 2 |
| 6653 | */ |
| 6654 | continue; |
NeilBrown | 9744197 | 2008-09-19 11:49:54 +1000 | [diff] [blame] | 6655 | /* We need to wait 'interruptible' so as not to |
| 6656 | * contribute to the load average, and not to |
| 6657 | * be caught by 'softlockup' |
| 6658 | */ |
| 6659 | prepare_to_wait(&resync_wait, &wq, TASK_INTERRUPTIBLE); |
NeilBrown | 787453c | 2005-11-08 21:39:43 -0800 | [diff] [blame] | 6660 | if (!kthread_should_stop() && |
NeilBrown | 8712e55 | 2005-10-26 01:58:58 -0700 | [diff] [blame] | 6661 | mddev2->curr_resync >= mddev->curr_resync) { |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6662 | printk(KERN_INFO "md: delaying %s of %s" |
| 6663 | " until %s has finished (they" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6664 | " share one or more physical units)\n", |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6665 | desc, mdname(mddev), mdname(mddev2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6666 | mddev_put(mddev2); |
NeilBrown | 9744197 | 2008-09-19 11:49:54 +1000 | [diff] [blame] | 6667 | if (signal_pending(current)) |
| 6668 | flush_signals(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6669 | schedule(); |
| 6670 | finish_wait(&resync_wait, &wq); |
| 6671 | goto try_again; |
| 6672 | } |
| 6673 | finish_wait(&resync_wait, &wq); |
| 6674 | } |
| 6675 | } |
| 6676 | } while (mddev->curr_resync < 2); |
| 6677 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6678 | j = 0; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6679 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6680 | /* resync follows the size requested by the personality, |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6681 | * which defaults to physical size, but can be virtual size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6682 | */ |
| 6683 | max_sectors = mddev->resync_max_sectors; |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 6684 | mddev->resync_mismatches = 0; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6685 | /* we don't use the checkpoint if there's a bitmap */ |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 6686 | if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6687 | j = mddev->resync_min; |
| 6688 | else if (!mddev->bitmap) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6689 | j = mddev->recovery_cp; |
Neil Brown | 5e96ee6 | 2008-06-28 08:31:24 +1000 | [diff] [blame] | 6690 | |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 6691 | } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6692 | max_sectors = mddev->dev_sectors; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6693 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6694 | /* recovery follows the physical size of devices */ |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6695 | max_sectors = mddev->dev_sectors; |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6696 | j = MaxSector; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6697 | rcu_read_lock(); |
| 6698 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6699 | if (rdev->raid_disk >= 0 && |
| 6700 | !test_bit(Faulty, &rdev->flags) && |
| 6701 | !test_bit(In_sync, &rdev->flags) && |
| 6702 | rdev->recovery_offset < j) |
| 6703 | j = rdev->recovery_offset; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6704 | rcu_read_unlock(); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6705 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6706 | |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6707 | printk(KERN_INFO "md: %s of RAID array %s\n", desc, mdname(mddev)); |
| 6708 | printk(KERN_INFO "md: minimum _guaranteed_ speed:" |
| 6709 | " %d KB/sec/disk.\n", speed_min(mddev)); |
Adrian Bunk | 338cec3 | 2005-09-10 00:26:54 -0700 | [diff] [blame] | 6710 | printk(KERN_INFO "md: using maximum available idle IO bandwidth " |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6711 | "(but not more than %d KB/sec) for %s.\n", |
| 6712 | speed_max(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6713 | |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6714 | is_mddev_idle(mddev, 1); /* this initializes IO event counters */ |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6715 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6716 | io_sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6717 | for (m = 0; m < SYNC_MARKS; m++) { |
| 6718 | mark[m] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6719 | mark_cnt[m] = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6720 | } |
| 6721 | last_mark = 0; |
| 6722 | mddev->resync_mark = mark[last_mark]; |
| 6723 | mddev->resync_mark_cnt = mark_cnt[last_mark]; |
| 6724 | |
| 6725 | /* |
| 6726 | * Tune reconstruction: |
| 6727 | */ |
| 6728 | window = 32*(PAGE_SIZE/512); |
| 6729 | printk(KERN_INFO "md: using %dk window, over a total of %llu blocks.\n", |
| 6730 | window/2,(unsigned long long) max_sectors/2); |
| 6731 | |
| 6732 | atomic_set(&mddev->recovery_active, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6733 | last_check = 0; |
| 6734 | |
| 6735 | if (j>2) { |
| 6736 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6737 | "md: resuming %s of %s from checkpoint.\n", |
| 6738 | desc, mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6739 | mddev->curr_resync = j; |
| 6740 | } |
NeilBrown | efa5933 | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 6741 | mddev->curr_resync_completed = mddev->curr_resync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6742 | |
| 6743 | while (j < max_sectors) { |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6744 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6745 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6746 | skipped = 0; |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6747 | |
NeilBrown | 7a91ee1 | 2009-05-26 12:57:21 +1000 | [diff] [blame] | 6748 | if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && |
| 6749 | ((mddev->curr_resync > mddev->curr_resync_completed && |
| 6750 | (mddev->curr_resync - mddev->curr_resync_completed) |
| 6751 | > (max_sectors >> 4)) || |
| 6752 | (j - mddev->curr_resync_completed)*2 |
| 6753 | >= mddev->resync_max - mddev->curr_resync_completed |
| 6754 | )) { |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6755 | /* time to update curr_resync_completed */ |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6756 | md_unplug(mddev); |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6757 | wait_event(mddev->recovery_wait, |
| 6758 | atomic_read(&mddev->recovery_active) == 0); |
| 6759 | mddev->curr_resync_completed = |
| 6760 | mddev->curr_resync; |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 6761 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6762 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6763 | } |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6764 | |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 6765 | while (j >= mddev->resync_max && !kthread_should_stop()) { |
| 6766 | /* As this condition is controlled by user-space, |
| 6767 | * we can block indefinitely, so use '_interruptible' |
| 6768 | * to avoid triggering warnings. |
| 6769 | */ |
| 6770 | flush_signals(current); /* just in case */ |
| 6771 | wait_event_interruptible(mddev->recovery_wait, |
| 6772 | mddev->resync_max > j |
| 6773 | || kthread_should_stop()); |
| 6774 | } |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 6775 | |
| 6776 | if (kthread_should_stop()) |
| 6777 | goto interrupted; |
| 6778 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6779 | sectors = mddev->pers->sync_request(mddev, j, &skipped, |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6780 | currspeed < speed_min(mddev)); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6781 | if (sectors == 0) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6782 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6783 | goto out; |
| 6784 | } |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6785 | |
| 6786 | if (!skipped) { /* actual IO requested */ |
| 6787 | io_sectors += sectors; |
| 6788 | atomic_add(sectors, &mddev->recovery_active); |
| 6789 | } |
| 6790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6791 | j += sectors; |
| 6792 | if (j>1) mddev->curr_resync = j; |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 6793 | mddev->curr_mark_cnt = io_sectors; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 6794 | if (last_check == 0) |
| 6795 | /* this is the earliers that rebuilt will be |
| 6796 | * visible in /proc/mdstat |
| 6797 | */ |
| 6798 | md_new_event(mddev); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6799 | |
| 6800 | if (last_check + window > io_sectors || j == max_sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6801 | continue; |
| 6802 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6803 | last_check = io_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6804 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6805 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6806 | break; |
| 6807 | |
| 6808 | repeat: |
| 6809 | if (time_after_eq(jiffies, mark[last_mark] + SYNC_MARK_STEP )) { |
| 6810 | /* step marks */ |
| 6811 | int next = (last_mark+1) % SYNC_MARKS; |
| 6812 | |
| 6813 | mddev->resync_mark = mark[next]; |
| 6814 | mddev->resync_mark_cnt = mark_cnt[next]; |
| 6815 | mark[next] = jiffies; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6816 | mark_cnt[next] = io_sectors - atomic_read(&mddev->recovery_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6817 | last_mark = next; |
| 6818 | } |
| 6819 | |
| 6820 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6821 | if (kthread_should_stop()) |
| 6822 | goto interrupted; |
| 6823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6824 | |
| 6825 | /* |
| 6826 | * this loop exits only if either when we are slower than |
| 6827 | * the 'hard' speed limit, or the system was IO-idle for |
| 6828 | * a jiffy. |
| 6829 | * the system might be non-idle CPU-wise, but we only care |
| 6830 | * about not overloading the IO subsystem. (things like an |
| 6831 | * e2fsck being done on the RAID array should execute fast) |
| 6832 | */ |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6833 | md_unplug(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6834 | cond_resched(); |
| 6835 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6836 | currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2 |
| 6837 | /((jiffies-mddev->resync_mark)/HZ +1) +1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6838 | |
NeilBrown | 88202a0 | 2006-01-06 00:21:36 -0800 | [diff] [blame] | 6839 | if (currspeed > speed_min(mddev)) { |
| 6840 | if ((currspeed > speed_max(mddev)) || |
NeilBrown | eea1bf3 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 6841 | !is_mddev_idle(mddev, 0)) { |
NeilBrown | c0e4852 | 2005-11-18 01:11:01 -0800 | [diff] [blame] | 6842 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6843 | goto repeat; |
| 6844 | } |
| 6845 | } |
| 6846 | } |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6847 | printk(KERN_INFO "md: %s: %s done.\n",mdname(mddev), desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6848 | /* |
| 6849 | * this also signals 'finished resyncing' to md_stop |
| 6850 | */ |
| 6851 | out: |
NeilBrown | 252ac52 | 2010-06-01 19:37:29 +1000 | [diff] [blame] | 6852 | md_unplug(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6853 | |
| 6854 | wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); |
| 6855 | |
| 6856 | /* tell personality that we are finished */ |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6857 | mddev->pers->sync_request(mddev, max_sectors, &skipped, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6858 | |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6859 | if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) && |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6860 | mddev->curr_resync > 2) { |
| 6861 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 6862 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6863 | if (mddev->curr_resync >= mddev->recovery_cp) { |
| 6864 | printk(KERN_INFO |
NeilBrown | 61df9d9 | 2006-10-03 01:15:57 -0700 | [diff] [blame] | 6865 | "md: checkpointing %s of %s.\n", |
| 6866 | desc, mdname(mddev)); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6867 | mddev->recovery_cp = mddev->curr_resync; |
| 6868 | } |
| 6869 | } else |
| 6870 | mddev->recovery_cp = MaxSector; |
| 6871 | } else { |
| 6872 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 6873 | mddev->curr_resync = MaxSector; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6874 | rcu_read_lock(); |
| 6875 | list_for_each_entry_rcu(rdev, &mddev->disks, same_set) |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6876 | if (rdev->raid_disk >= 0 && |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 6877 | mddev->delta_disks >= 0 && |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6878 | !test_bit(Faulty, &rdev->flags) && |
| 6879 | !test_bit(In_sync, &rdev->flags) && |
| 6880 | rdev->recovery_offset < mddev->curr_resync) |
| 6881 | rdev->recovery_offset = mddev->curr_resync; |
Dan Williams | 4e59ca7 | 2009-12-12 21:17:06 -0700 | [diff] [blame] | 6882 | rcu_read_unlock(); |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 6883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6884 | } |
NeilBrown | 1757128 | 2006-12-10 02:20:52 -0800 | [diff] [blame] | 6885 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6887 | skip: |
NeilBrown | c07b70a | 2009-12-14 12:49:48 +1100 | [diff] [blame] | 6888 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6889 | /* We completed so min/max setting can be forgotten if used. */ |
| 6890 | if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6891 | mddev->resync_min = 0; |
| 6892 | mddev->resync_max = MaxSector; |
| 6893 | } else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 6894 | mddev->resync_min = mddev->curr_resync_completed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6895 | mddev->curr_resync = 0; |
NeilBrown | efa5933 | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 6896 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 6897 | mddev->curr_resync_completed = 0; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6898 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6899 | wake_up(&resync_wait); |
| 6900 | set_bit(MD_RECOVERY_DONE, &mddev->recovery); |
| 6901 | md_wakeup_thread(mddev->thread); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6902 | return; |
| 6903 | |
| 6904 | interrupted: |
| 6905 | /* |
| 6906 | * got a signal, exit. |
| 6907 | */ |
| 6908 | printk(KERN_INFO |
| 6909 | "md: md_do_sync() got signal ... exiting\n"); |
| 6910 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 6911 | goto out; |
| 6912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6913 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6914 | EXPORT_SYMBOL_GPL(md_do_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6915 | |
| 6916 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6917 | static int remove_and_add_spares(mddev_t *mddev) |
| 6918 | { |
| 6919 | mdk_rdev_t *rdev; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6920 | int spares = 0; |
| 6921 | |
NeilBrown | 97e4f42 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6922 | mddev->curr_resync_completed = 0; |
| 6923 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6924 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6925 | if (rdev->raid_disk >= 0 && |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 6926 | !test_bit(Blocked, &rdev->flags) && |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6927 | (test_bit(Faulty, &rdev->flags) || |
| 6928 | ! test_bit(In_sync, &rdev->flags)) && |
| 6929 | atomic_read(&rdev->nr_pending)==0) { |
| 6930 | if (mddev->pers->hot_remove_disk( |
| 6931 | mddev, rdev->raid_disk)==0) { |
| 6932 | char nm[20]; |
| 6933 | sprintf(nm,"rd%d", rdev->raid_disk); |
| 6934 | sysfs_remove_link(&mddev->kobj, nm); |
| 6935 | rdev->raid_disk = -1; |
| 6936 | } |
| 6937 | } |
| 6938 | |
NeilBrown | 4044ba5 | 2009-01-09 08:31:11 +1100 | [diff] [blame] | 6939 | if (mddev->degraded && ! mddev->ro && !mddev->recovery_disabled) { |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 6940 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6941 | if (rdev->raid_disk >= 0 && |
Dan Williams | e542713 | 2008-07-28 23:28:06 -0700 | [diff] [blame] | 6942 | !test_bit(In_sync, &rdev->flags) && |
| 6943 | !test_bit(Blocked, &rdev->flags)) |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6944 | spares++; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6945 | if (rdev->raid_disk < 0 |
| 6946 | && !test_bit(Faulty, &rdev->flags)) { |
| 6947 | rdev->recovery_offset = 0; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 6948 | if (mddev->pers-> |
| 6949 | hot_add_disk(mddev, rdev) == 0) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6950 | char nm[20]; |
| 6951 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 6952 | if (sysfs_create_link(&mddev->kobj, |
| 6953 | &rdev->kobj, nm)) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 6954 | /* failure here is OK */; |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6955 | spares++; |
| 6956 | md_new_event(mddev); |
NeilBrown | 93be75f | 2009-12-14 12:50:06 +1100 | [diff] [blame] | 6957 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6958 | } else |
| 6959 | break; |
| 6960 | } |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6961 | } |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 6962 | } |
| 6963 | return spares; |
| 6964 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6965 | /* |
| 6966 | * This routine is regularly called by all per-raid-array threads to |
| 6967 | * deal with generic issues like resync and super-block update. |
| 6968 | * Raid personalities that don't have a thread (linear/raid0) do not |
| 6969 | * need this as they never do any recovery or update the superblock. |
| 6970 | * |
| 6971 | * It does not do any resync itself, but rather "forks" off other threads |
| 6972 | * to do that as needed. |
| 6973 | * When it is determined that resync is needed, we set MD_RECOVERY_RUNNING in |
| 6974 | * "->recovery" and create a thread at ->sync_thread. |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 6975 | * When the thread finishes it sets MD_RECOVERY_DONE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6976 | * and wakeups up this thread which will reap the thread and finish up. |
| 6977 | * This thread also removes any faulty devices (with nr_pending == 0). |
| 6978 | * |
| 6979 | * The overall approach is: |
| 6980 | * 1/ if the superblock needs updating, update it. |
| 6981 | * 2/ If a recovery thread is running, don't do anything else. |
| 6982 | * 3/ If recovery has finished, clean up, possibly marking spares active. |
| 6983 | * 4/ If there are any faulty devices, remove them. |
| 6984 | * 5/ If array is degraded, try to add spares devices |
| 6985 | * 6/ If array has spares or is not in-sync, start a resync thread. |
| 6986 | */ |
| 6987 | void md_check_recovery(mddev_t *mddev) |
| 6988 | { |
| 6989 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6990 | |
| 6991 | |
NeilBrown | 5f40402 | 2005-06-21 17:17:16 -0700 | [diff] [blame] | 6992 | if (mddev->bitmap) |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 6993 | bitmap_daemon_work(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6994 | |
| 6995 | if (mddev->ro) |
| 6996 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 6997 | |
| 6998 | if (signal_pending(current)) { |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 6999 | if (mddev->pers->sync_request && !mddev->external) { |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7000 | printk(KERN_INFO "md: %s in immediate safe mode\n", |
| 7001 | mdname(mddev)); |
| 7002 | mddev->safemode = 2; |
| 7003 | } |
| 7004 | flush_signals(current); |
| 7005 | } |
| 7006 | |
NeilBrown | c89a8ee | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 7007 | if (mddev->ro && !test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
| 7008 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7009 | if ( ! ( |
NeilBrown | 126925c | 2010-09-07 17:02:47 +1000 | [diff] [blame] | 7010 | (mddev->flags & ~ (1<<MD_CHANGE_PENDING)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7011 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7012 | test_bit(MD_RECOVERY_DONE, &mddev->recovery) || |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7013 | (mddev->external == 0 && mddev->safemode == 1) || |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7014 | (mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending) |
| 7015 | && !mddev->in_sync && mddev->recovery_cp == MaxSector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7016 | )) |
| 7017 | return; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7018 | |
NeilBrown | df5b89b | 2006-03-27 01:18:20 -0800 | [diff] [blame] | 7019 | if (mddev_trylock(mddev)) { |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7020 | int spares = 0; |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7021 | |
NeilBrown | c89a8ee | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 7022 | if (mddev->ro) { |
| 7023 | /* Only thing we do on a ro array is remove |
| 7024 | * failed devices. |
| 7025 | */ |
| 7026 | remove_and_add_spares(mddev); |
| 7027 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 7028 | goto unlock; |
| 7029 | } |
| 7030 | |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7031 | if (!mddev->external) { |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 7032 | int did_change = 0; |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7033 | spin_lock_irq(&mddev->write_lock); |
| 7034 | if (mddev->safemode && |
| 7035 | !atomic_read(&mddev->writes_pending) && |
| 7036 | !mddev->in_sync && |
| 7037 | mddev->recovery_cp == MaxSector) { |
| 7038 | mddev->in_sync = 1; |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 7039 | did_change = 1; |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 7040 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); |
NeilBrown | 31a59e3 | 2008-04-30 00:52:30 -0700 | [diff] [blame] | 7041 | } |
| 7042 | if (mddev->safemode == 1) |
| 7043 | mddev->safemode = 0; |
| 7044 | spin_unlock_irq(&mddev->write_lock); |
Neil Brown | 0fd62b8 | 2008-06-28 08:31:36 +1000 | [diff] [blame] | 7045 | if (did_change) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7046 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7047 | } |
NeilBrown | fca4d84 | 2005-06-21 17:17:11 -0700 | [diff] [blame] | 7048 | |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 7049 | if (mddev->flags) |
| 7050 | md_update_sb(mddev, 0); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 7051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7052 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && |
| 7053 | !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) { |
| 7054 | /* resync/recovery still happening */ |
| 7055 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 7056 | goto unlock; |
| 7057 | } |
| 7058 | if (mddev->sync_thread) { |
| 7059 | /* resync has finished, collect result */ |
| 7060 | md_unregister_thread(mddev->sync_thread); |
| 7061 | mddev->sync_thread = NULL; |
Dan Williams | 56ac36d | 2008-08-07 10:02:47 -0700 | [diff] [blame] | 7062 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery) && |
| 7063 | !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7064 | /* success...*/ |
| 7065 | /* activate any spares */ |
Neil Brown | a99ac97 | 2008-06-28 08:31:43 +1000 | [diff] [blame] | 7066 | if (mddev->pers->spare_active(mddev)) |
| 7067 | sysfs_notify(&mddev->kobj, NULL, |
| 7068 | "degraded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7069 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 7070 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && |
| 7071 | mddev->pers->finish_reshape) |
| 7072 | mddev->pers->finish_reshape(mddev); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 7073 | md_update_sb(mddev, 1); |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 7074 | |
| 7075 | /* if array is no-longer degraded, then any saved_raid_disk |
| 7076 | * information must be scrapped |
| 7077 | */ |
| 7078 | if (!mddev->degraded) |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 7079 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 7080 | rdev->saved_raid_disk = -1; |
| 7081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7082 | mddev->recovery = 0; |
| 7083 | /* flag recovery needed just to double check */ |
| 7084 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7085 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 7086 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7087 | goto unlock; |
| 7088 | } |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7089 | /* Set RUNNING before clearing NEEDED to avoid |
| 7090 | * any transients in the value of "sync_action". |
| 7091 | */ |
| 7092 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 7093 | clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7094 | /* Clear some bits that don't mean anything, but |
| 7095 | * might be left set |
| 7096 | */ |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7097 | clear_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 7098 | clear_bit(MD_RECOVERY_DONE, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7099 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 7100 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 7101 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7102 | /* no recovery is running. |
| 7103 | * remove any failed drives, then |
| 7104 | * add spares if possible. |
| 7105 | * Spare are also removed and re-added, to allow |
| 7106 | * the personality to fail the re-add. |
| 7107 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7108 | |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7109 | if (mddev->reshape_position != MaxSector) { |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 7110 | if (mddev->pers->check_reshape == NULL || |
| 7111 | mddev->pers->check_reshape(mddev) != 0) |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7112 | /* Cannot proceed */ |
| 7113 | goto unlock; |
| 7114 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7115 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | b4c4c7b | 2007-02-28 20:11:48 -0800 | [diff] [blame] | 7116 | } else if ((spares = remove_and_add_spares(mddev))) { |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7117 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 7118 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
Dan Williams | 56ac36d | 2008-08-07 10:02:47 -0700 | [diff] [blame] | 7119 | clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7120 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7121 | } else if (mddev->recovery_cp < MaxSector) { |
| 7122 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7123 | clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7124 | } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 7125 | /* nothing to be done ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7126 | goto unlock; |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 7127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7128 | if (mddev->pers->sync_request) { |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 7129 | if (spares && mddev->bitmap && ! mddev->bitmap->file) { |
| 7130 | /* We are adding a device or devices to an array |
| 7131 | * which has the bitmap stored on all devices. |
| 7132 | * So make sure all bitmap pages get written |
| 7133 | */ |
| 7134 | bitmap_write_all(mddev->bitmap); |
| 7135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7136 | mddev->sync_thread = md_register_thread(md_do_sync, |
| 7137 | mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 7138 | "resync"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7139 | if (!mddev->sync_thread) { |
| 7140 | printk(KERN_ERR "%s: could not start resync" |
| 7141 | " thread...\n", |
| 7142 | mdname(mddev)); |
| 7143 | /* leave the spares where they are, it shouldn't hurt */ |
| 7144 | mddev->recovery = 0; |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 7145 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7146 | md_wakeup_thread(mddev->sync_thread); |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7147 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
NeilBrown | d7603b7 | 2006-01-06 00:20:30 -0800 | [diff] [blame] | 7148 | md_new_event(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7149 | } |
| 7150 | unlock: |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7151 | if (!mddev->sync_thread) { |
| 7152 | clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 7153 | if (test_and_clear_bit(MD_RECOVERY_RECOVER, |
| 7154 | &mddev->recovery)) |
NeilBrown | 0c3573f | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 7155 | if (mddev->sysfs_action) |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7156 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
Neil Brown | 72a23c2 | 2008-06-28 08:31:41 +1000 | [diff] [blame] | 7157 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7158 | mddev_unlock(mddev); |
| 7159 | } |
| 7160 | } |
| 7161 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 7162 | void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 7163 | { |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7164 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 7165 | wait_event_timeout(rdev->blocked_wait, |
| 7166 | !test_bit(Blocked, &rdev->flags), |
| 7167 | msecs_to_jiffies(5000)); |
| 7168 | rdev_dec_pending(rdev, mddev); |
| 7169 | } |
| 7170 | EXPORT_SYMBOL(md_wait_for_blocked_rdev); |
| 7171 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 7172 | static int md_notify_reboot(struct notifier_block *this, |
| 7173 | unsigned long code, void *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7174 | { |
| 7175 | struct list_head *tmp; |
| 7176 | mddev_t *mddev; |
| 7177 | |
| 7178 | if ((code == SYS_DOWN) || (code == SYS_HALT) || (code == SYS_POWER_OFF)) { |
| 7179 | |
| 7180 | printk(KERN_INFO "md: stopping all md devices.\n"); |
| 7181 | |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 7182 | for_each_mddev(mddev, tmp) |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 7183 | if (mddev_trylock(mddev)) { |
NeilBrown | 2b25000 | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 7184 | /* Force a switch to readonly even array |
| 7185 | * appears to still be in use. Hence |
| 7186 | * the '100'. |
| 7187 | */ |
NeilBrown | a4bd82d | 2010-03-29 13:23:10 +1100 | [diff] [blame] | 7188 | md_set_readonly(mddev, 100); |
Neil Brown | c71d488 | 2006-05-26 10:39:25 +1000 | [diff] [blame] | 7189 | mddev_unlock(mddev); |
| 7190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7191 | /* |
| 7192 | * certain more exotic SCSI devices are known to be |
| 7193 | * volatile wrt too early system reboots. While the |
| 7194 | * right place to handle this issue is the given |
| 7195 | * driver, we do want to have a safe RAID driver ... |
| 7196 | */ |
| 7197 | mdelay(1000*1); |
| 7198 | } |
| 7199 | return NOTIFY_DONE; |
| 7200 | } |
| 7201 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 7202 | static struct notifier_block md_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7203 | .notifier_call = md_notify_reboot, |
| 7204 | .next = NULL, |
| 7205 | .priority = INT_MAX, /* before any real devices */ |
| 7206 | }; |
| 7207 | |
| 7208 | static void md_geninit(void) |
| 7209 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7210 | dprintk("md: sizeof(mdp_super_t) = %d\n", (int)sizeof(mdp_super_t)); |
| 7211 | |
Denis V. Lunev | c7705f344 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 7212 | proc_create("mdstat", S_IRUGO, NULL, &md_seq_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7213 | } |
| 7214 | |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 7215 | static int __init md_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7216 | { |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7217 | if (register_blkdev(MD_MAJOR, "md")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7218 | return -1; |
| 7219 | if ((mdp_major=register_blkdev(0, "mdp"))<=0) { |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7220 | unregister_blkdev(MD_MAJOR, "md"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7221 | return -1; |
| 7222 | } |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7223 | blk_register_region(MKDEV(MD_MAJOR, 0), 1UL<<MINORBITS, THIS_MODULE, |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 7224 | md_probe, NULL, NULL); |
| 7225 | blk_register_region(MKDEV(mdp_major, 0), 1UL<<MINORBITS, THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7226 | md_probe, NULL, NULL); |
| 7227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7228 | register_reboot_notifier(&md_notifier); |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 7229 | raid_table_header = register_sysctl_table(raid_root_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7230 | |
| 7231 | md_geninit(); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 7232 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7233 | } |
| 7234 | |
| 7235 | |
| 7236 | #ifndef MODULE |
| 7237 | |
| 7238 | /* |
| 7239 | * Searches all registered partitions for autorun RAID arrays |
| 7240 | * at boot time. |
| 7241 | */ |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7242 | |
| 7243 | static LIST_HEAD(all_detected_devices); |
| 7244 | struct detected_devices_node { |
| 7245 | struct list_head list; |
| 7246 | dev_t dev; |
| 7247 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7248 | |
| 7249 | void md_autodetect_dev(dev_t dev) |
| 7250 | { |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7251 | struct detected_devices_node *node_detected_dev; |
| 7252 | |
| 7253 | node_detected_dev = kzalloc(sizeof(*node_detected_dev), GFP_KERNEL); |
| 7254 | if (node_detected_dev) { |
| 7255 | node_detected_dev->dev = dev; |
| 7256 | list_add_tail(&node_detected_dev->list, &all_detected_devices); |
| 7257 | } else { |
| 7258 | printk(KERN_CRIT "md: md_autodetect_dev: kzalloc failed" |
| 7259 | ", skipping dev(%d,%d)\n", MAJOR(dev), MINOR(dev)); |
| 7260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7261 | } |
| 7262 | |
| 7263 | |
| 7264 | static void autostart_arrays(int part) |
| 7265 | { |
| 7266 | mdk_rdev_t *rdev; |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7267 | struct detected_devices_node *node_detected_dev; |
| 7268 | dev_t dev; |
| 7269 | int i_scanned, i_passed; |
| 7270 | |
| 7271 | i_scanned = 0; |
| 7272 | i_passed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7273 | |
| 7274 | printk(KERN_INFO "md: Autodetecting RAID arrays.\n"); |
| 7275 | |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7276 | while (!list_empty(&all_detected_devices) && i_scanned < INT_MAX) { |
| 7277 | i_scanned++; |
| 7278 | node_detected_dev = list_entry(all_detected_devices.next, |
| 7279 | struct detected_devices_node, list); |
| 7280 | list_del(&node_detected_dev->list); |
| 7281 | dev = node_detected_dev->dev; |
| 7282 | kfree(node_detected_dev); |
NeilBrown | df968c4 | 2007-07-17 04:06:11 -0700 | [diff] [blame] | 7283 | rdev = md_import_device(dev,0, 90); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7284 | if (IS_ERR(rdev)) |
| 7285 | continue; |
| 7286 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 7287 | if (test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7288 | MD_BUG(); |
| 7289 | continue; |
| 7290 | } |
NeilBrown | d0fae18 | 2008-03-04 14:29:31 -0800 | [diff] [blame] | 7291 | set_bit(AutoDetected, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7292 | list_add(&rdev->same_set, &pending_raid_disks); |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7293 | i_passed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7294 | } |
Michael J. Evans | 4d936ec | 2007-10-16 23:30:52 -0700 | [diff] [blame] | 7295 | |
| 7296 | printk(KERN_INFO "md: Scanned %d and added %d devices.\n", |
| 7297 | i_scanned, i_passed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7298 | |
| 7299 | autorun_devices(part); |
| 7300 | } |
| 7301 | |
Jeff Garzik | fdee8ae | 2006-12-10 02:20:50 -0800 | [diff] [blame] | 7302 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7303 | |
| 7304 | static __exit void md_exit(void) |
| 7305 | { |
| 7306 | mddev_t *mddev; |
| 7307 | struct list_head *tmp; |
Greg Kroah-Hartman | 8ab5e4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 7308 | |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7309 | blk_unregister_region(MKDEV(MD_MAJOR,0), 1U << MINORBITS); |
NeilBrown | e8703fe | 2006-10-03 01:15:59 -0700 | [diff] [blame] | 7310 | blk_unregister_region(MKDEV(mdp_major,0), 1U << MINORBITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7311 | |
Christoph Hellwig | 3dbd8c2 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 7312 | unregister_blkdev(MD_MAJOR,"md"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7313 | unregister_blkdev(mdp_major, "mdp"); |
| 7314 | unregister_reboot_notifier(&md_notifier); |
| 7315 | unregister_sysctl_table(raid_table_header); |
| 7316 | remove_proc_entry("mdstat", NULL); |
NeilBrown | 29ac4aa | 2008-02-06 01:39:58 -0800 | [diff] [blame] | 7317 | for_each_mddev(mddev, tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7318 | export_array(mddev); |
NeilBrown | d337482 | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 7319 | mddev->hold_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7320 | } |
| 7321 | } |
| 7322 | |
Dan Williams | 685784a | 2007-07-09 11:56:42 -0700 | [diff] [blame] | 7323 | subsys_initcall(md_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7324 | module_exit(md_exit) |
| 7325 | |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7326 | static int get_ro(char *buffer, struct kernel_param *kp) |
| 7327 | { |
| 7328 | return sprintf(buffer, "%d", start_readonly); |
| 7329 | } |
| 7330 | static int set_ro(const char *val, struct kernel_param *kp) |
| 7331 | { |
| 7332 | char *e; |
| 7333 | int num = simple_strtoul(val, &e, 10); |
| 7334 | if (*val && (*e == '\0' || *e == '\n')) { |
| 7335 | start_readonly = num; |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 7336 | return 0; |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7337 | } |
| 7338 | return -EINVAL; |
| 7339 | } |
| 7340 | |
NeilBrown | 80ca3a4 | 2006-07-10 04:44:18 -0700 | [diff] [blame] | 7341 | module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); |
| 7342 | module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR); |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 7343 | |
NeilBrown | efeb53c | 2009-01-09 08:31:10 +1100 | [diff] [blame] | 7344 | module_param_call(new_array, add_named_array, NULL, NULL, S_IWUSR); |
NeilBrown | f91de92 | 2005-11-08 21:39:36 -0800 | [diff] [blame] | 7345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7346 | EXPORT_SYMBOL(register_md_personality); |
| 7347 | EXPORT_SYMBOL(unregister_md_personality); |
| 7348 | EXPORT_SYMBOL(md_error); |
| 7349 | EXPORT_SYMBOL(md_done_sync); |
| 7350 | EXPORT_SYMBOL(md_write_start); |
| 7351 | EXPORT_SYMBOL(md_write_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7352 | EXPORT_SYMBOL(md_register_thread); |
| 7353 | EXPORT_SYMBOL(md_unregister_thread); |
| 7354 | EXPORT_SYMBOL(md_wakeup_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7355 | EXPORT_SYMBOL(md_check_recovery); |
| 7356 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 7357 | MODULE_DESCRIPTION("MD RAID framework"); |
NeilBrown | aa1595e | 2005-08-04 12:53:32 -0700 | [diff] [blame] | 7358 | MODULE_ALIAS("md"); |
NeilBrown | 7200865 | 2005-08-26 18:34:15 -0700 | [diff] [blame] | 7359 | MODULE_ALIAS_BLOCKDEV_MAJOR(MD_MAJOR); |