md.h 24 KB

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