Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7e841526 | 2 | md.h : kernel internal structure of the Linux MD driver |
1da177e4 LT |
3 | Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2, or (at your option) | |
8 | any later version. | |
9 | ||
10 | You should have received a copy of the GNU General Public License | |
11 | (for example /usr/src/linux/COPYING); if not, write to the Free | |
12 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
13 | */ | |
14 | ||
63fe0817 CH |
15 | #ifndef _MD_MD_H |
16 | #define _MD_MD_H | |
17 | ||
18 | #include <linux/blkdev.h> | |
19 | #include <linux/kobject.h> | |
20 | #include <linux/list.h> | |
21 | #include <linux/mm.h> | |
22 | #include <linux/mutex.h> | |
23 | #include <linux/timer.h> | |
24 | #include <linux/wait.h> | |
25 | #include <linux/workqueue.h> | |
9361401e | 26 | |
1da177e4 | 27 | #define MaxSector (~(sector_t)0) |
1da177e4 | 28 | |
1da177e4 | 29 | typedef struct mddev_s mddev_t; |
1da177e4 | 30 | |
2230dfe4 N |
31 | /* Bad block numbers are stored sorted in a single page. |
32 | * 64bits is used for each block or extent. | |
33 | * 54 bits are sector number, 9 bits are extent size, | |
34 | * 1 bit is an 'acknowledged' flag. | |
35 | */ | |
36 | #define MD_MAX_BADBLOCKS (PAGE_SIZE/8) | |
37 | ||
1da177e4 LT |
38 | /* |
39 | * MD's 'extended' device | |
40 | */ | |
3cb03002 | 41 | struct md_rdev { |
1da177e4 LT |
42 | struct list_head same_set; /* RAID devices within the same set */ |
43 | ||
dd8ac336 | 44 | sector_t sectors; /* Device size (in 512bytes sectors) */ |
1da177e4 | 45 | mddev_t *mddev; /* RAID array if running */ |
eea1bf38 | 46 | int last_events; /* IO event timestamp */ |
1da177e4 | 47 | |
a6ff7e08 JB |
48 | /* |
49 | * If meta_bdev is non-NULL, it means that a separate device is | |
50 | * being used to store the metadata (superblock/bitmap) which | |
51 | * would otherwise be contained on the same device as the data (bdev). | |
52 | */ | |
53 | struct block_device *meta_bdev; | |
1da177e4 LT |
54 | struct block_device *bdev; /* block device handle */ |
55 | ||
2699b672 | 56 | struct page *sb_page, *bb_page; |
1da177e4 | 57 | int sb_loaded; |
42543769 | 58 | __u64 sb_events; |
1da177e4 | 59 | sector_t data_offset; /* start of data in array */ |
0f420358 | 60 | sector_t sb_start; /* offset of the super block (in 512byte sectors) */ |
0002b271 | 61 | int sb_size; /* bytes in the superblock */ |
1da177e4 LT |
62 | int preferred_minor; /* autorun support */ |
63 | ||
86e6ffdd N |
64 | struct kobject kobj; |
65 | ||
1da177e4 LT |
66 | /* A device can be in one of three states based on two flags: |
67 | * Not working: faulty==1 in_sync==0 | |
68 | * Fully working: faulty==0 in_sync==1 | |
69 | * Working, but not | |
70 | * in sync with array | |
71 | * faulty==0 in_sync==0 | |
72 | * | |
73 | * It can never have faulty==1, in_sync==1 | |
74 | * This reduces the burden of testing multiple flags in many cases | |
75 | */ | |
1da177e4 | 76 | |
b2d444d7 N |
77 | unsigned long flags; |
78 | #define Faulty 1 /* device is known to have a fault */ | |
79 | #define In_sync 2 /* device is in_sync with rest of array */ | |
8ddf9efe | 80 | #define WriteMostly 4 /* Avoid reading if at all possible */ |
d0fae18f | 81 | #define AutoDetected 7 /* added by auto-detect */ |
de393cde N |
82 | #define Blocked 8 /* An error occurred but has not yet |
83 | * been acknowledged by the metadata | |
84 | * handler, so don't allow writes | |
6bfe0b49 | 85 | * until it is cleared */ |
d7a9d443 N |
86 | #define WriteErrorSeen 9 /* A write error has been seen on this |
87 | * device | |
88 | */ | |
de393cde N |
89 | #define FaultRecorded 10 /* Intermediate state for clearing |
90 | * Blocked. The Fault is/will-be | |
91 | * recorded in the metadata, but that | |
92 | * metadata hasn't been stored safely | |
93 | * on disk yet. | |
94 | */ | |
95 | #define BlockedBadBlocks 11 /* A writer is blocked because they | |
96 | * found an unacknowledged bad-block. | |
97 | * This can safely be cleared at any | |
98 | * time, and the writer will re-check. | |
99 | * It may be set at any time, and at | |
100 | * worst the writer will timeout and | |
101 | * re-check. So setting it as | |
102 | * accurately as possible is good, but | |
103 | * not absolutely critical. | |
104 | */ | |
6bfe0b49 | 105 | wait_queue_head_t blocked_wait; |
8ddf9efe | 106 | |
1da177e4 LT |
107 | int desc_nr; /* descriptor index in the superblock */ |
108 | int raid_disk; /* role of device in array */ | |
e93f68a1 N |
109 | int new_raid_disk; /* role that the device will have in |
110 | * the array after a level-change completes. | |
111 | */ | |
41158c7e N |
112 | int saved_raid_disk; /* role that device used to have in the |
113 | * array and could again if we did a partial | |
114 | * resync from the bitmap | |
115 | */ | |
5fd6c1dc N |
116 | sector_t recovery_offset;/* If this device has been partially |
117 | * recovered, this is where we were | |
118 | * up to. | |
119 | */ | |
1da177e4 LT |
120 | |
121 | atomic_t nr_pending; /* number of pending requests. | |
122 | * only maintained for arrays that | |
123 | * support hot removal | |
124 | */ | |
ba22dcbf N |
125 | atomic_t read_errors; /* number of consecutive read errors that |
126 | * we have tried to ignore. | |
127 | */ | |
1e50915f RB |
128 | struct timespec last_read_error; /* monotonic time since our |
129 | * last read error | |
130 | */ | |
4dbcdc75 N |
131 | atomic_t corrected_errors; /* number of corrected read errors, |
132 | * for reporting to userspace and storing | |
133 | * in superblock. | |
134 | */ | |
5792a285 | 135 | struct work_struct del_work; /* used for delayed sysfs removal */ |
3c0ee63a N |
136 | |
137 | struct sysfs_dirent *sysfs_state; /* handle for 'state' | |
138 | * sysfs entry */ | |
2230dfe4 N |
139 | |
140 | struct badblocks { | |
141 | int count; /* count of bad blocks */ | |
de393cde N |
142 | int unacked_exist; /* there probably are unacknowledged |
143 | * bad blocks. This is only cleared | |
144 | * when a read discovers none | |
145 | */ | |
2230dfe4 N |
146 | int shift; /* shift from sectors to block size |
147 | * a -ve shift means badblocks are | |
148 | * disabled.*/ | |
149 | u64 *page; /* badblock list */ | |
150 | int changed; | |
151 | seqlock_t lock; | |
2699b672 N |
152 | |
153 | sector_t sector; | |
154 | sector_t size; /* in sectors */ | |
2230dfe4 | 155 | } badblocks; |
1da177e4 LT |
156 | }; |
157 | ||
2230dfe4 N |
158 | #define BB_LEN_MASK (0x00000000000001FFULL) |
159 | #define BB_OFFSET_MASK (0x7FFFFFFFFFFFFE00ULL) | |
160 | #define BB_ACK_MASK (0x8000000000000000ULL) | |
161 | #define BB_MAX_LEN 512 | |
162 | #define BB_OFFSET(x) (((x) & BB_OFFSET_MASK) >> 9) | |
163 | #define BB_LEN(x) (((x) & BB_LEN_MASK) + 1) | |
164 | #define BB_ACK(x) (!!((x) & BB_ACK_MASK)) | |
165 | #define BB_MAKE(a, l, ack) (((a)<<9) | ((l)-1) | ((u64)(!!(ack)) << 63)) | |
166 | ||
167 | extern int md_is_badblock(struct badblocks *bb, sector_t s, int sectors, | |
168 | sector_t *first_bad, int *bad_sectors); | |
3cb03002 | 169 | static inline int is_badblock(struct md_rdev *rdev, sector_t s, int sectors, |
2230dfe4 N |
170 | sector_t *first_bad, int *bad_sectors) |
171 | { | |
172 | if (unlikely(rdev->badblocks.count)) { | |
173 | int rv = md_is_badblock(&rdev->badblocks, rdev->data_offset + s, | |
174 | sectors, | |
175 | first_bad, bad_sectors); | |
176 | if (rv) | |
177 | *first_bad -= rdev->data_offset; | |
178 | return rv; | |
179 | } | |
180 | return 0; | |
181 | } | |
3cb03002 | 182 | extern int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors, |
2230dfe4 | 183 | int acknowledged); |
3cb03002 | 184 | extern int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors); |
2230dfe4 N |
185 | extern void md_ack_all_badblocks(struct badblocks *bb); |
186 | ||
1da177e4 LT |
187 | struct mddev_s |
188 | { | |
189 | void *private; | |
2604b703 | 190 | struct mdk_personality *pers; |
1da177e4 LT |
191 | dev_t unit; |
192 | int md_minor; | |
193 | struct list_head disks; | |
850b2b42 N |
194 | unsigned long flags; |
195 | #define MD_CHANGE_DEVS 0 /* Some device status has changed */ | |
196 | #define MD_CHANGE_CLEAN 1 /* transition to or from 'clean' */ | |
070dc6dd | 197 | #define MD_CHANGE_PENDING 2 /* switch from 'clean' to 'active' in progress */ |
9c81075f | 198 | #define MD_ARRAY_FIRST_USE 3 /* First use of array, needs initialization */ |
850b2b42 | 199 | |
409c57f3 N |
200 | int suspended; |
201 | atomic_t active_io; | |
1da177e4 | 202 | int ro; |
bb4f1e9d N |
203 | int sysfs_active; /* set when sysfs deletes |
204 | * are happening, so run/ | |
205 | * takeover/stop are not safe | |
206 | */ | |
0ca69886 N |
207 | int ready; /* See when safe to pass |
208 | * IO requests down */ | |
1da177e4 LT |
209 | struct gendisk *gendisk; |
210 | ||
eae1701f | 211 | struct kobject kobj; |
d3374825 N |
212 | int hold_active; |
213 | #define UNTIL_IOCTL 1 | |
efeb53c0 | 214 | #define UNTIL_STOP 2 |
eae1701f | 215 | |
1da177e4 LT |
216 | /* Superblock information */ |
217 | int major_version, | |
218 | minor_version, | |
219 | patch_version; | |
220 | int persistent; | |
e691063a N |
221 | int external; /* metadata is |
222 | * managed externally */ | |
223 | char metadata_type[17]; /* externally set*/ | |
9d8f0363 | 224 | int chunk_sectors; |
1da177e4 LT |
225 | time_t ctime, utime; |
226 | int level, layout; | |
d9d166c2 | 227 | char clevel[16]; |
1da177e4 LT |
228 | int raid_disks; |
229 | int max_disks; | |
58c0fed4 AN |
230 | sector_t dev_sectors; /* used size of |
231 | * component devices */ | |
f233ea5c | 232 | sector_t array_sectors; /* exported array size */ |
b522adcd DW |
233 | int external_size; /* size managed |
234 | * externally */ | |
1da177e4 | 235 | __u64 events; |
a8707c08 N |
236 | /* If the last 'event' was simply a clean->dirty transition, and |
237 | * we didn't write it to the spares, then it is safe and simple | |
238 | * to just decrement the event count on a dirty->clean transition. | |
239 | * So we record that possibility here. | |
240 | */ | |
241 | int can_decrease_events; | |
1da177e4 LT |
242 | |
243 | char uuid[16]; | |
244 | ||
f6705578 N |
245 | /* If the array is being reshaped, we need to record the |
246 | * new shape and an indication of where we are up to. | |
247 | * This is written to the superblock. | |
248 | * If reshape_position is MaxSector, then no reshape is happening (yet). | |
249 | */ | |
250 | sector_t reshape_position; | |
664e7c41 AN |
251 | int delta_disks, new_level, new_layout; |
252 | int new_chunk_sectors; | |
f6705578 | 253 | |
97658cdd N |
254 | atomic_t plug_cnt; /* If device is expecting |
255 | * more bios soon. | |
256 | */ | |
1da177e4 LT |
257 | struct mdk_thread_s *thread; /* management thread */ |
258 | struct mdk_thread_s *sync_thread; /* doing resync or reconstruct */ | |
ff4e8d9a | 259 | sector_t curr_resync; /* last block scheduled */ |
97e4f42d N |
260 | /* As resync requests can complete out of order, we cannot easily track |
261 | * how much resync has been completed. So we occasionally pause until | |
262 | * everything completes, then set curr_resync_completed to curr_resync. | |
263 | * As such it may be well behind the real resync mark, but it is a value | |
264 | * we are certain of. | |
265 | */ | |
266 | sector_t curr_resync_completed; | |
1da177e4 LT |
267 | unsigned long resync_mark; /* a recent timestamp */ |
268 | sector_t resync_mark_cnt;/* blocks written at resync_mark */ | |
ff4e8d9a | 269 | sector_t curr_mark_cnt; /* blocks scheduled now */ |
1da177e4 LT |
270 | |
271 | sector_t resync_max_sectors; /* may be set by personality */ | |
9d88883e N |
272 | |
273 | sector_t resync_mismatches; /* count of sectors where | |
274 | * parity/replica mismatch found | |
275 | */ | |
e464eafd N |
276 | |
277 | /* allow user-space to request suspension of IO to regions of the array */ | |
278 | sector_t suspend_lo; | |
279 | sector_t suspend_hi; | |
88202a0c N |
280 | /* if zero, use the system-wide default */ |
281 | int sync_speed_min; | |
282 | int sync_speed_max; | |
283 | ||
90b08710 BS |
284 | /* resync even though the same disks are shared among md-devices */ |
285 | int parallel_resync; | |
286 | ||
6ff8d8ec | 287 | int ok_start_degraded; |
1da177e4 LT |
288 | /* recovery/resync flags |
289 | * NEEDED: we might need to start a resync/recover | |
290 | * RUNNING: a thread is running, or about to be started | |
291 | * SYNC: actually doing a resync, not a recovery | |
72a23c21 | 292 | * RECOVER: doing recovery, or need to try it. |
dfc70645 | 293 | * INTR: resync needs to be aborted for some reason |
1da177e4 | 294 | * DONE: thread is done and is waiting to be reaped |
24dd469d | 295 | * REQUEST: user-space has requested a sync (used with SYNC) |
411c9403 | 296 | * CHECK: user-space request for check-only, no repair |
ccfcc3c1 N |
297 | * RESHAPE: A reshape is happening |
298 | * | |
299 | * If neither SYNC or RESHAPE are set, then it is a recovery. | |
1da177e4 LT |
300 | */ |
301 | #define MD_RECOVERY_RUNNING 0 | |
302 | #define MD_RECOVERY_SYNC 1 | |
72a23c21 | 303 | #define MD_RECOVERY_RECOVER 2 |
1da177e4 LT |
304 | #define MD_RECOVERY_INTR 3 |
305 | #define MD_RECOVERY_DONE 4 | |
306 | #define MD_RECOVERY_NEEDED 5 | |
24dd469d N |
307 | #define MD_RECOVERY_REQUESTED 6 |
308 | #define MD_RECOVERY_CHECK 7 | |
ccfcc3c1 | 309 | #define MD_RECOVERY_RESHAPE 8 |
5fd6c1dc N |
310 | #define MD_RECOVERY_FROZEN 9 |
311 | ||
1da177e4 | 312 | unsigned long recovery; |
5389042f N |
313 | /* If a RAID personality determines that recovery (of a particular |
314 | * device) will fail due to a read error on the source device, it | |
315 | * takes a copy of this number and does not attempt recovery again | |
316 | * until this number changes. | |
317 | */ | |
318 | int recovery_disabled; | |
1da177e4 LT |
319 | |
320 | int in_sync; /* know to not need resync */ | |
c8c00a69 N |
321 | /* 'open_mutex' avoids races between 'md_open' and 'do_md_stop', so |
322 | * that we are never stopping an array while it is open. | |
323 | * 'reconfig_mutex' protects all other reconfiguration. | |
324 | * These locks are separate due to conflicting interactions | |
325 | * with bdev->bd_mutex. | |
326 | * Lock ordering is: | |
327 | * reconfig_mutex -> bd_mutex : e.g. do_md_run -> revalidate_disk | |
328 | * bd_mutex -> open_mutex: e.g. __blkdev_get -> md_open | |
329 | */ | |
330 | struct mutex open_mutex; | |
df5b89b3 | 331 | struct mutex reconfig_mutex; |
f2ea68cf N |
332 | atomic_t active; /* general refcount */ |
333 | atomic_t openers; /* number of active opens */ | |
1da177e4 | 334 | |
f0b4f7e2 N |
335 | int changed; /* True if we might need to |
336 | * reread partition info */ | |
1da177e4 LT |
337 | int degraded; /* whether md should consider |
338 | * adding a spare | |
339 | */ | |
340 | ||
341 | atomic_t recovery_active; /* blocks scheduled, but not written */ | |
342 | wait_queue_head_t recovery_wait; | |
343 | sector_t recovery_cp; | |
5e96ee65 NB |
344 | sector_t resync_min; /* user requested sync |
345 | * starts here */ | |
c6207277 N |
346 | sector_t resync_max; /* resync should pause |
347 | * when it gets here */ | |
06d91a5f | 348 | |
b62b7590 N |
349 | struct sysfs_dirent *sysfs_state; /* handle for 'array_state' |
350 | * file in sysfs. | |
351 | */ | |
0c3573f1 | 352 | struct sysfs_dirent *sysfs_action; /* handle for 'sync_action' */ |
b62b7590 | 353 | |
d3374825 N |
354 | struct work_struct del_work; /* used for delayed sysfs removal */ |
355 | ||
06d91a5f | 356 | spinlock_t write_lock; |
3d310eb7 | 357 | wait_queue_head_t sb_wait; /* for waiting on superblock updates */ |
7bfa19f2 | 358 | atomic_t pending_writes; /* number of active superblock writes */ |
06d91a5f | 359 | |
1da177e4 LT |
360 | unsigned int safemode; /* if set, update "clean" superblock |
361 | * when no writes pending. | |
362 | */ | |
363 | unsigned int safemode_delay; | |
364 | struct timer_list safemode_timer; | |
365 | atomic_t writes_pending; | |
165125e1 | 366 | struct request_queue *queue; /* for plugging ... */ |
1da177e4 | 367 | |
32a7627c | 368 | struct bitmap *bitmap; /* the bitmap for the device */ |
c3d9714e N |
369 | struct { |
370 | struct file *file; /* the bitmap file */ | |
f6af949c | 371 | loff_t offset; /* offset from superblock of |
c3d9714e N |
372 | * start of bitmap. May be |
373 | * negative, but not '0' | |
f6af949c N |
374 | * For external metadata, offset |
375 | * from start of device. | |
c3d9714e | 376 | */ |
f6af949c | 377 | loff_t default_offset; /* this is the offset to use when |
c3d9714e N |
378 | * hot-adding a bitmap. It should |
379 | * eventually be settable by sysfs. | |
380 | */ | |
381 | struct mutex mutex; | |
42a04b50 | 382 | unsigned long chunksize; |
ac2f40be | 383 | unsigned long daemon_sleep; /* how many jiffies between updates? */ |
42a04b50 | 384 | unsigned long max_write_behind; /* write-behind mode */ |
ece5cff0 | 385 | int external; |
c3d9714e | 386 | } bitmap_info; |
32a7627c | 387 | |
1e50915f | 388 | atomic_t max_corr_read_errors; /* max read retries */ |
1da177e4 | 389 | struct list_head all_mddevs; |
a2826aa9 | 390 | |
a64c876f | 391 | struct attribute_group *to_remove; |
252ac522 | 392 | |
a167f663 N |
393 | struct bio_set *bio_set; |
394 | ||
e9c7469b TH |
395 | /* Generic flush handling. |
396 | * The last to finish preflush schedules a worker to submit | |
397 | * the rest of the request (without the REQ_FLUSH flag). | |
a2826aa9 | 398 | */ |
e9c7469b | 399 | struct bio *flush_bio; |
a2826aa9 | 400 | atomic_t flush_pending; |
e9c7469b | 401 | struct work_struct flush_work; |
768a418d | 402 | struct work_struct event_work; /* used by dm to report failure event */ |
3cb03002 | 403 | void (*sync_super)(mddev_t *mddev, struct md_rdev *rdev); |
1da177e4 LT |
404 | }; |
405 | ||
406 | ||
3cb03002 | 407 | static inline void rdev_dec_pending(struct md_rdev *rdev, mddev_t *mddev) |
1da177e4 | 408 | { |
b2d444d7 | 409 | int faulty = test_bit(Faulty, &rdev->flags); |
1da177e4 LT |
410 | if (atomic_dec_and_test(&rdev->nr_pending) && faulty) |
411 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | |
412 | } | |
413 | ||
414 | static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors) | |
415 | { | |
416 | atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io); | |
417 | } | |
418 | ||
2604b703 | 419 | struct mdk_personality |
1da177e4 LT |
420 | { |
421 | char *name; | |
2604b703 N |
422 | int level; |
423 | struct list_head list; | |
1da177e4 | 424 | struct module *owner; |
21a52c6d | 425 | int (*make_request)(mddev_t *mddev, struct bio *bio); |
1da177e4 LT |
426 | int (*run)(mddev_t *mddev); |
427 | int (*stop)(mddev_t *mddev); | |
428 | void (*status)(struct seq_file *seq, mddev_t *mddev); | |
429 | /* error_handler must set ->faulty and clear ->in_sync | |
430 | * if appropriate, and should abort recovery if needed | |
431 | */ | |
3cb03002 N |
432 | void (*error_handler)(mddev_t *mddev, struct md_rdev *rdev); |
433 | int (*hot_add_disk) (mddev_t *mddev, struct md_rdev *rdev); | |
1da177e4 LT |
434 | int (*hot_remove_disk) (mddev_t *mddev, int number); |
435 | int (*spare_active) (mddev_t *mddev); | |
57afd89f | 436 | sector_t (*sync_request)(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster); |
1da177e4 | 437 | int (*resize) (mddev_t *mddev, sector_t sectors); |
80c3a6ce | 438 | sector_t (*size) (mddev_t *mddev, sector_t sectors, int raid_disks); |
63c70c4f N |
439 | int (*check_reshape) (mddev_t *mddev); |
440 | int (*start_reshape) (mddev_t *mddev); | |
cea9c228 | 441 | void (*finish_reshape) (mddev_t *mddev); |
36fa3063 N |
442 | /* quiesce moves between quiescence states |
443 | * 0 - fully active | |
444 | * 1 - no new requests allowed | |
445 | * others - reserved | |
446 | */ | |
447 | void (*quiesce) (mddev_t *mddev, int state); | |
245f46c2 N |
448 | /* takeover is used to transition an array from one |
449 | * personality to another. The new personality must be able | |
450 | * to handle the data in the current layout. | |
451 | * e.g. 2drive raid1 -> 2drive raid5 | |
452 | * ndrive raid5 -> degraded n+1drive raid6 with special layout | |
453 | * If the takeover succeeds, a new 'private' structure is returned. | |
454 | * This needs to be installed and then ->run used to activate the | |
455 | * array. | |
456 | */ | |
457 | void *(*takeover) (mddev_t *mddev); | |
1da177e4 LT |
458 | }; |
459 | ||
460 | ||
007583c9 N |
461 | struct md_sysfs_entry { |
462 | struct attribute attr; | |
463 | ssize_t (*show)(mddev_t *, char *); | |
464 | ssize_t (*store)(mddev_t *, const char *, size_t); | |
465 | }; | |
43a70507 | 466 | extern struct attribute_group md_bitmap_group; |
007583c9 | 467 | |
00bcb4ac N |
468 | static inline struct sysfs_dirent *sysfs_get_dirent_safe(struct sysfs_dirent *sd, char *name) |
469 | { | |
470 | if (sd) | |
471 | return sysfs_get_dirent(sd, NULL, name); | |
472 | return sd; | |
473 | } | |
474 | static inline void sysfs_notify_dirent_safe(struct sysfs_dirent *sd) | |
475 | { | |
476 | if (sd) | |
477 | sysfs_notify_dirent(sd); | |
478 | } | |
479 | ||
1da177e4 LT |
480 | static inline char * mdname (mddev_t * mddev) |
481 | { | |
482 | return mddev->gendisk ? mddev->gendisk->disk_name : "mdX"; | |
483 | } | |
484 | ||
3cb03002 | 485 | static inline int sysfs_link_rdev(mddev_t *mddev, struct md_rdev *rdev) |
36fad858 NK |
486 | { |
487 | char nm[20]; | |
488 | sprintf(nm, "rd%d", rdev->raid_disk); | |
489 | return sysfs_create_link(&mddev->kobj, &rdev->kobj, nm); | |
490 | } | |
491 | ||
3cb03002 | 492 | static inline void sysfs_unlink_rdev(mddev_t *mddev, struct md_rdev *rdev) |
36fad858 NK |
493 | { |
494 | char nm[20]; | |
495 | sprintf(nm, "rd%d", rdev->raid_disk); | |
496 | sysfs_remove_link(&mddev->kobj, nm); | |
497 | } | |
498 | ||
1da177e4 LT |
499 | /* |
500 | * iterates through some rdev ringlist. It's safe to remove the | |
501 | * current 'rdev'. Dont touch 'tmp' though. | |
502 | */ | |
159ec1fc CR |
503 | #define rdev_for_each_list(rdev, tmp, head) \ |
504 | list_for_each_entry_safe(rdev, tmp, head, same_set) | |
505 | ||
1da177e4 LT |
506 | /* |
507 | * iterates through the 'same array disks' ringlist | |
508 | */ | |
d089c6af | 509 | #define rdev_for_each(rdev, tmp, mddev) \ |
159ec1fc | 510 | list_for_each_entry_safe(rdev, tmp, &((mddev)->disks), same_set) |
1da177e4 | 511 | |
4b80991c N |
512 | #define rdev_for_each_rcu(rdev, mddev) \ |
513 | list_for_each_entry_rcu(rdev, &((mddev)->disks), same_set) | |
514 | ||
1da177e4 LT |
515 | typedef struct mdk_thread_s { |
516 | void (*run) (mddev_t *mddev); | |
517 | mddev_t *mddev; | |
518 | wait_queue_head_t wqueue; | |
519 | unsigned long flags; | |
1da177e4 | 520 | struct task_struct *tsk; |
32a7627c | 521 | unsigned long timeout; |
1da177e4 LT |
522 | } mdk_thread_t; |
523 | ||
524 | #define THREAD_WAKEUP 0 | |
525 | ||
526 | #define __wait_event_lock_irq(wq, condition, lock, cmd) \ | |
527 | do { \ | |
528 | wait_queue_t __wait; \ | |
529 | init_waitqueue_entry(&__wait, current); \ | |
530 | \ | |
531 | add_wait_queue(&wq, &__wait); \ | |
532 | for (;;) { \ | |
533 | set_current_state(TASK_UNINTERRUPTIBLE); \ | |
534 | if (condition) \ | |
535 | break; \ | |
536 | spin_unlock_irq(&lock); \ | |
537 | cmd; \ | |
538 | schedule(); \ | |
539 | spin_lock_irq(&lock); \ | |
540 | } \ | |
541 | current->state = TASK_RUNNING; \ | |
542 | remove_wait_queue(&wq, &__wait); \ | |
543 | } while (0) | |
544 | ||
545 | #define wait_event_lock_irq(wq, condition, lock, cmd) \ | |
546 | do { \ | |
547 | if (condition) \ | |
548 | break; \ | |
549 | __wait_event_lock_irq(wq, condition, lock, cmd); \ | |
550 | } while (0) | |
551 | ||
1345b1d8 N |
552 | static inline void safe_put_page(struct page *p) |
553 | { | |
554 | if (p) put_page(p); | |
555 | } | |
556 | ||
92022950 N |
557 | extern int register_md_personality(struct mdk_personality *p); |
558 | extern int unregister_md_personality(struct mdk_personality *p); | |
559 | extern mdk_thread_t * md_register_thread(void (*run) (mddev_t *mddev), | |
560 | mddev_t *mddev, const char *name); | |
01f96c0a | 561 | extern void md_unregister_thread(mdk_thread_t **threadp); |
92022950 N |
562 | extern void md_wakeup_thread(mdk_thread_t *thread); |
563 | extern void md_check_recovery(mddev_t *mddev); | |
564 | extern void md_write_start(mddev_t *mddev, struct bio *bi); | |
565 | extern void md_write_end(mddev_t *mddev); | |
566 | extern void md_done_sync(mddev_t *mddev, int blocks, int ok); | |
3cb03002 | 567 | extern void md_error(mddev_t *mddev, struct md_rdev *rdev); |
92022950 | 568 | |
3fa841d7 | 569 | extern int mddev_congested(mddev_t *mddev, int bits); |
e9c7469b | 570 | extern void md_flush_request(mddev_t *mddev, struct bio *bio); |
3cb03002 | 571 | extern void md_super_write(mddev_t *mddev, struct md_rdev *rdev, |
92022950 N |
572 | sector_t sector, int size, struct page *page); |
573 | extern void md_super_wait(mddev_t *mddev); | |
3cb03002 | 574 | extern int sync_page_io(struct md_rdev *rdev, sector_t sector, int size, |
ccebd4c4 | 575 | struct page *page, int rw, bool metadata_op); |
92022950 N |
576 | extern void md_do_sync(mddev_t *mddev); |
577 | extern void md_new_event(mddev_t *mddev); | |
578 | extern int md_allow_write(mddev_t *mddev); | |
3cb03002 | 579 | extern void md_wait_for_blocked_rdev(struct md_rdev *rdev, mddev_t *mddev); |
1f403624 | 580 | extern void md_set_array_sectors(mddev_t *mddev, sector_t array_sectors); |
0894cc30 | 581 | extern int md_check_no_bitmap(mddev_t *mddev); |
ac5e7113 | 582 | extern int md_integrity_register(mddev_t *mddev); |
3cb03002 | 583 | extern void md_integrity_add_rdev(struct md_rdev *rdev, mddev_t *mddev); |
72e02075 | 584 | extern int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale); |
43a70507 | 585 | extern void restore_bitmap_write_access(struct file *file); |
63fe0817 | 586 | |
390ee602 N |
587 | extern void mddev_init(mddev_t *mddev); |
588 | extern int md_run(mddev_t *mddev); | |
589 | extern void md_stop(mddev_t *mddev); | |
590 | extern void md_stop_writes(mddev_t *mddev); | |
3cb03002 | 591 | extern int md_rdev_init(struct md_rdev *rdev); |
63fe0817 | 592 | |
390ee602 N |
593 | extern void mddev_suspend(mddev_t *mddev); |
594 | extern void mddev_resume(mddev_t *mddev); | |
a167f663 N |
595 | extern struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask, |
596 | mddev_t *mddev); | |
597 | extern struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs, | |
598 | mddev_t *mddev); | |
97658cdd | 599 | extern int mddev_check_plugged(mddev_t *mddev); |
d2eb35ac | 600 | extern void md_trim_bio(struct bio *bio, int offset, int size); |
63fe0817 | 601 | #endif /* _MD_MD_H */ |