md.h 22 KB

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