md.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. time64_t 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. ClusterRemove,
  150. RemoveSynchronized, /* synchronize_rcu() was called after
  151. * this device was known to be faulty,
  152. * so it is safe to remove without
  153. * another synchronize_rcu() call.
  154. */
  155. };
  156. static inline int is_badblock(struct md_rdev *rdev, sector_t s, int sectors,
  157. sector_t *first_bad, int *bad_sectors)
  158. {
  159. if (unlikely(rdev->badblocks.count)) {
  160. int rv = badblocks_check(&rdev->badblocks, rdev->data_offset + s,
  161. sectors,
  162. first_bad, bad_sectors);
  163. if (rv)
  164. *first_bad -= rdev->data_offset;
  165. return rv;
  166. }
  167. return 0;
  168. }
  169. extern int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
  170. int is_new);
  171. extern int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
  172. int is_new);
  173. struct md_cluster_info;
  174. struct mddev {
  175. void *private;
  176. struct md_personality *pers;
  177. dev_t unit;
  178. int md_minor;
  179. struct list_head disks;
  180. unsigned long flags;
  181. #define MD_CHANGE_DEVS 0 /* Some device status has changed */
  182. #define MD_CHANGE_CLEAN 1 /* transition to or from 'clean' */
  183. #define MD_CHANGE_PENDING 2 /* switch from 'clean' to 'active' in progress */
  184. #define MD_UPDATE_SB_FLAGS (1 | 2 | 4) /* If these are set, md_update_sb needed */
  185. #define MD_ARRAY_FIRST_USE 3 /* First use of array, needs initialization */
  186. #define MD_STILL_CLOSED 4 /* If set, then array has not been opened since
  187. * md_ioctl checked on it.
  188. */
  189. #define MD_JOURNAL_CLEAN 5 /* A raid with journal is already clean */
  190. #define MD_HAS_JOURNAL 6 /* The raid array has journal feature set */
  191. #define MD_RELOAD_SB 7 /* Reload the superblock because another node
  192. * updated it.
  193. */
  194. #define MD_CLUSTER_RESYNC_LOCKED 8 /* cluster raid only, which means node
  195. * already took resync lock, need to
  196. * release the lock */
  197. int suspended;
  198. atomic_t active_io;
  199. int ro;
  200. int sysfs_active; /* set when sysfs deletes
  201. * are happening, so run/
  202. * takeover/stop are not safe
  203. */
  204. struct gendisk *gendisk;
  205. struct kobject kobj;
  206. int hold_active;
  207. #define UNTIL_IOCTL 1
  208. #define UNTIL_STOP 2
  209. /* Superblock information */
  210. int major_version,
  211. minor_version,
  212. patch_version;
  213. int persistent;
  214. int external; /* metadata is
  215. * managed externally */
  216. char metadata_type[17]; /* externally set*/
  217. int chunk_sectors;
  218. time64_t ctime, utime;
  219. int level, layout;
  220. char clevel[16];
  221. int raid_disks;
  222. int max_disks;
  223. sector_t dev_sectors; /* used size of
  224. * component devices */
  225. sector_t array_sectors; /* exported array size */
  226. int external_size; /* size managed
  227. * externally */
  228. __u64 events;
  229. /* If the last 'event' was simply a clean->dirty transition, and
  230. * we didn't write it to the spares, then it is safe and simple
  231. * to just decrement the event count on a dirty->clean transition.
  232. * So we record that possibility here.
  233. */
  234. int can_decrease_events;
  235. char uuid[16];
  236. /* If the array is being reshaped, we need to record the
  237. * new shape and an indication of where we are up to.
  238. * This is written to the superblock.
  239. * If reshape_position is MaxSector, then no reshape is happening (yet).
  240. */
  241. sector_t reshape_position;
  242. int delta_disks, new_level, new_layout;
  243. int new_chunk_sectors;
  244. int reshape_backwards;
  245. struct md_thread *thread; /* management thread */
  246. struct md_thread *sync_thread; /* doing resync or reconstruct */
  247. /* 'last_sync_action' is initialized to "none". It is set when a
  248. * sync operation (i.e "data-check", "requested-resync", "resync",
  249. * "recovery", or "reshape") is started. It holds this value even
  250. * when the sync thread is "frozen" (interrupted) or "idle" (stopped
  251. * or finished). It is overwritten when a new sync operation is begun.
  252. */
  253. char *last_sync_action;
  254. sector_t curr_resync; /* last block scheduled */
  255. /* As resync requests can complete out of order, we cannot easily track
  256. * how much resync has been completed. So we occasionally pause until
  257. * everything completes, then set curr_resync_completed to curr_resync.
  258. * As such it may be well behind the real resync mark, but it is a value
  259. * we are certain of.
  260. */
  261. sector_t curr_resync_completed;
  262. unsigned long resync_mark; /* a recent timestamp */
  263. sector_t resync_mark_cnt;/* blocks written at resync_mark */
  264. sector_t curr_mark_cnt; /* blocks scheduled now */
  265. sector_t resync_max_sectors; /* may be set by personality */
  266. atomic64_t resync_mismatches; /* count of sectors where
  267. * parity/replica mismatch found
  268. */
  269. /* allow user-space to request suspension of IO to regions of the array */
  270. sector_t suspend_lo;
  271. sector_t suspend_hi;
  272. /* if zero, use the system-wide default */
  273. int sync_speed_min;
  274. int sync_speed_max;
  275. /* resync even though the same disks are shared among md-devices */
  276. int parallel_resync;
  277. int ok_start_degraded;
  278. /* recovery/resync flags
  279. * NEEDED: we might need to start a resync/recover
  280. * RUNNING: a thread is running, or about to be started
  281. * SYNC: actually doing a resync, not a recovery
  282. * RECOVER: doing recovery, or need to try it.
  283. * INTR: resync needs to be aborted for some reason
  284. * DONE: thread is done and is waiting to be reaped
  285. * REQUEST: user-space has requested a sync (used with SYNC)
  286. * CHECK: user-space request for check-only, no repair
  287. * RESHAPE: A reshape is happening
  288. * ERROR: sync-action interrupted because io-error
  289. *
  290. * If neither SYNC or RESHAPE are set, then it is a recovery.
  291. */
  292. #define MD_RECOVERY_RUNNING 0
  293. #define MD_RECOVERY_SYNC 1
  294. #define MD_RECOVERY_RECOVER 2
  295. #define MD_RECOVERY_INTR 3
  296. #define MD_RECOVERY_DONE 4
  297. #define MD_RECOVERY_NEEDED 5
  298. #define MD_RECOVERY_REQUESTED 6
  299. #define MD_RECOVERY_CHECK 7
  300. #define MD_RECOVERY_RESHAPE 8
  301. #define MD_RECOVERY_FROZEN 9
  302. #define MD_RECOVERY_ERROR 10
  303. unsigned long recovery;
  304. /* If a RAID personality determines that recovery (of a particular
  305. * device) will fail due to a read error on the source device, it
  306. * takes a copy of this number and does not attempt recovery again
  307. * until this number changes.
  308. */
  309. int recovery_disabled;
  310. int in_sync; /* know to not need resync */
  311. /* 'open_mutex' avoids races between 'md_open' and 'do_md_stop', so
  312. * that we are never stopping an array while it is open.
  313. * 'reconfig_mutex' protects all other reconfiguration.
  314. * These locks are separate due to conflicting interactions
  315. * with bdev->bd_mutex.
  316. * Lock ordering is:
  317. * reconfig_mutex -> bd_mutex : e.g. do_md_run -> revalidate_disk
  318. * bd_mutex -> open_mutex: e.g. __blkdev_get -> md_open
  319. */
  320. struct mutex open_mutex;
  321. struct mutex reconfig_mutex;
  322. atomic_t active; /* general refcount */
  323. atomic_t openers; /* number of active opens */
  324. int changed; /* True if we might need to
  325. * reread partition info */
  326. int degraded; /* whether md should consider
  327. * adding a spare
  328. */
  329. atomic_t recovery_active; /* blocks scheduled, but not written */
  330. wait_queue_head_t recovery_wait;
  331. sector_t recovery_cp;
  332. sector_t resync_min; /* user requested sync
  333. * starts here */
  334. sector_t resync_max; /* resync should pause
  335. * when it gets here */
  336. struct kernfs_node *sysfs_state; /* handle for 'array_state'
  337. * file in sysfs.
  338. */
  339. struct kernfs_node *sysfs_action; /* handle for 'sync_action' */
  340. struct work_struct del_work; /* used for delayed sysfs removal */
  341. /* "lock" protects:
  342. * flush_bio transition from NULL to !NULL
  343. * rdev superblocks, events
  344. * clearing MD_CHANGE_*
  345. * in_sync - and related safemode and MD_CHANGE changes
  346. * pers (also protected by reconfig_mutex and pending IO).
  347. * clearing ->bitmap
  348. * clearing ->bitmap_info.file
  349. * changing ->resync_{min,max}
  350. * setting MD_RECOVERY_RUNNING (which interacts with resync_{min,max})
  351. */
  352. spinlock_t lock;
  353. wait_queue_head_t sb_wait; /* for waiting on superblock updates */
  354. atomic_t pending_writes; /* number of active superblock writes */
  355. unsigned int safemode; /* if set, update "clean" superblock
  356. * when no writes pending.
  357. */
  358. unsigned int safemode_delay;
  359. struct timer_list safemode_timer;
  360. atomic_t writes_pending;
  361. struct request_queue *queue; /* for plugging ... */
  362. struct bitmap *bitmap; /* the bitmap for the device */
  363. struct {
  364. struct file *file; /* the bitmap file */
  365. loff_t offset; /* offset from superblock of
  366. * start of bitmap. May be
  367. * negative, but not '0'
  368. * For external metadata, offset
  369. * from start of device.
  370. */
  371. unsigned long space; /* space available at this offset */
  372. loff_t default_offset; /* this is the offset to use when
  373. * hot-adding a bitmap. It should
  374. * eventually be settable by sysfs.
  375. */
  376. unsigned long default_space; /* space available at
  377. * default offset */
  378. struct mutex mutex;
  379. unsigned long chunksize;
  380. unsigned long daemon_sleep; /* how many jiffies between updates? */
  381. unsigned long max_write_behind; /* write-behind mode */
  382. int external;
  383. int nodes; /* Maximum number of nodes in the cluster */
  384. char cluster_name[64]; /* Name of the cluster */
  385. } bitmap_info;
  386. atomic_t max_corr_read_errors; /* max read retries */
  387. struct list_head all_mddevs;
  388. struct attribute_group *to_remove;
  389. struct bio_set *bio_set;
  390. /* Generic flush handling.
  391. * The last to finish preflush schedules a worker to submit
  392. * the rest of the request (without the REQ_PREFLUSH flag).
  393. */
  394. struct bio *flush_bio;
  395. atomic_t flush_pending;
  396. struct work_struct flush_work;
  397. struct work_struct event_work; /* used by dm to report failure event */
  398. void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev);
  399. struct md_cluster_info *cluster_info;
  400. unsigned int good_device_nr; /* good device num within cluster raid */
  401. };
  402. static inline int __must_check mddev_lock(struct mddev *mddev)
  403. {
  404. return mutex_lock_interruptible(&mddev->reconfig_mutex);
  405. }
  406. /* Sometimes we need to take the lock in a situation where
  407. * failure due to interrupts is not acceptable.
  408. */
  409. static inline void mddev_lock_nointr(struct mddev *mddev)
  410. {
  411. mutex_lock(&mddev->reconfig_mutex);
  412. }
  413. static inline int mddev_is_locked(struct mddev *mddev)
  414. {
  415. return mutex_is_locked(&mddev->reconfig_mutex);
  416. }
  417. static inline int mddev_trylock(struct mddev *mddev)
  418. {
  419. return mutex_trylock(&mddev->reconfig_mutex);
  420. }
  421. extern void mddev_unlock(struct mddev *mddev);
  422. static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
  423. {
  424. atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
  425. }
  426. struct md_personality
  427. {
  428. char *name;
  429. int level;
  430. struct list_head list;
  431. struct module *owner;
  432. void (*make_request)(struct mddev *mddev, struct bio *bio);
  433. int (*run)(struct mddev *mddev);
  434. void (*free)(struct mddev *mddev, void *priv);
  435. void (*status)(struct seq_file *seq, struct mddev *mddev);
  436. /* error_handler must set ->faulty and clear ->in_sync
  437. * if appropriate, and should abort recovery if needed
  438. */
  439. void (*error_handler)(struct mddev *mddev, struct md_rdev *rdev);
  440. int (*hot_add_disk) (struct mddev *mddev, struct md_rdev *rdev);
  441. int (*hot_remove_disk) (struct mddev *mddev, struct md_rdev *rdev);
  442. int (*spare_active) (struct mddev *mddev);
  443. sector_t (*sync_request)(struct mddev *mddev, sector_t sector_nr, int *skipped);
  444. int (*resize) (struct mddev *mddev, sector_t sectors);
  445. sector_t (*size) (struct mddev *mddev, sector_t sectors, int raid_disks);
  446. int (*check_reshape) (struct mddev *mddev);
  447. int (*start_reshape) (struct mddev *mddev);
  448. void (*finish_reshape) (struct mddev *mddev);
  449. /* quiesce moves between quiescence states
  450. * 0 - fully active
  451. * 1 - no new requests allowed
  452. * others - reserved
  453. */
  454. void (*quiesce) (struct mddev *mddev, int state);
  455. /* takeover is used to transition an array from one
  456. * personality to another. The new personality must be able
  457. * to handle the data in the current layout.
  458. * e.g. 2drive raid1 -> 2drive raid5
  459. * ndrive raid5 -> degraded n+1drive raid6 with special layout
  460. * If the takeover succeeds, a new 'private' structure is returned.
  461. * This needs to be installed and then ->run used to activate the
  462. * array.
  463. */
  464. void *(*takeover) (struct mddev *mddev);
  465. /* congested implements bdi.congested_fn().
  466. * Will not be called while array is 'suspended' */
  467. int (*congested)(struct mddev *mddev, int bits);
  468. };
  469. struct md_sysfs_entry {
  470. struct attribute attr;
  471. ssize_t (*show)(struct mddev *, char *);
  472. ssize_t (*store)(struct mddev *, const char *, size_t);
  473. };
  474. extern struct attribute_group md_bitmap_group;
  475. static inline struct kernfs_node *sysfs_get_dirent_safe(struct kernfs_node *sd, char *name)
  476. {
  477. if (sd)
  478. return sysfs_get_dirent(sd, name);
  479. return sd;
  480. }
  481. static inline void sysfs_notify_dirent_safe(struct kernfs_node *sd)
  482. {
  483. if (sd)
  484. sysfs_notify_dirent(sd);
  485. }
  486. static inline char * mdname (struct mddev * mddev)
  487. {
  488. return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
  489. }
  490. static inline int sysfs_link_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. return sysfs_create_link(&mddev->kobj, &rdev->kobj, nm);
  498. } else
  499. return 0;
  500. }
  501. static inline void sysfs_unlink_rdev(struct mddev *mddev, struct md_rdev *rdev)
  502. {
  503. char nm[20];
  504. if (!test_bit(Replacement, &rdev->flags) &&
  505. !test_bit(Journal, &rdev->flags) &&
  506. mddev->kobj.sd) {
  507. sprintf(nm, "rd%d", rdev->raid_disk);
  508. sysfs_remove_link(&mddev->kobj, nm);
  509. }
  510. }
  511. /*
  512. * iterates through some rdev ringlist. It's safe to remove the
  513. * current 'rdev'. Dont touch 'tmp' though.
  514. */
  515. #define rdev_for_each_list(rdev, tmp, head) \
  516. list_for_each_entry_safe(rdev, tmp, head, same_set)
  517. /*
  518. * iterates through the 'same array disks' ringlist
  519. */
  520. #define rdev_for_each(rdev, mddev) \
  521. list_for_each_entry(rdev, &((mddev)->disks), same_set)
  522. #define rdev_for_each_safe(rdev, tmp, mddev) \
  523. list_for_each_entry_safe(rdev, tmp, &((mddev)->disks), same_set)
  524. #define rdev_for_each_rcu(rdev, mddev) \
  525. list_for_each_entry_rcu(rdev, &((mddev)->disks), same_set)
  526. struct md_thread {
  527. void (*run) (struct md_thread *thread);
  528. struct mddev *mddev;
  529. wait_queue_head_t wqueue;
  530. unsigned long flags;
  531. struct task_struct *tsk;
  532. unsigned long timeout;
  533. void *private;
  534. };
  535. #define THREAD_WAKEUP 0
  536. static inline void safe_put_page(struct page *p)
  537. {
  538. if (p) put_page(p);
  539. }
  540. extern int register_md_personality(struct md_personality *p);
  541. extern int unregister_md_personality(struct md_personality *p);
  542. extern int register_md_cluster_operations(struct md_cluster_operations *ops,
  543. struct module *module);
  544. extern int unregister_md_cluster_operations(void);
  545. extern int md_setup_cluster(struct mddev *mddev, int nodes);
  546. extern void md_cluster_stop(struct mddev *mddev);
  547. extern struct md_thread *md_register_thread(
  548. void (*run)(struct md_thread *thread),
  549. struct mddev *mddev,
  550. const char *name);
  551. extern void md_unregister_thread(struct md_thread **threadp);
  552. extern void md_wakeup_thread(struct md_thread *thread);
  553. extern void md_check_recovery(struct mddev *mddev);
  554. extern void md_reap_sync_thread(struct mddev *mddev);
  555. extern void md_write_start(struct mddev *mddev, struct bio *bi);
  556. extern void md_write_end(struct mddev *mddev);
  557. extern void md_done_sync(struct mddev *mddev, int blocks, int ok);
  558. extern void md_error(struct mddev *mddev, struct md_rdev *rdev);
  559. extern void md_finish_reshape(struct mddev *mddev);
  560. extern int mddev_congested(struct mddev *mddev, int bits);
  561. extern void md_flush_request(struct mddev *mddev, struct bio *bio);
  562. extern void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
  563. sector_t sector, int size, struct page *page);
  564. extern void md_super_wait(struct mddev *mddev);
  565. extern int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
  566. struct page *page, int op, int op_flags,
  567. bool metadata_op);
  568. extern void md_do_sync(struct md_thread *thread);
  569. extern void md_new_event(struct mddev *mddev);
  570. extern int md_allow_write(struct mddev *mddev);
  571. extern void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev);
  572. extern void md_set_array_sectors(struct mddev *mddev, sector_t array_sectors);
  573. extern int md_check_no_bitmap(struct mddev *mddev);
  574. extern int md_integrity_register(struct mddev *mddev);
  575. extern int md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev);
  576. extern int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale);
  577. extern void mddev_init(struct mddev *mddev);
  578. extern int md_run(struct mddev *mddev);
  579. extern void md_stop(struct mddev *mddev);
  580. extern void md_stop_writes(struct mddev *mddev);
  581. extern int md_rdev_init(struct md_rdev *rdev);
  582. extern void md_rdev_clear(struct md_rdev *rdev);
  583. extern void mddev_suspend(struct mddev *mddev);
  584. extern void mddev_resume(struct mddev *mddev);
  585. extern struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask,
  586. struct mddev *mddev);
  587. extern struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs,
  588. struct mddev *mddev);
  589. extern void md_unplug(struct blk_plug_cb *cb, bool from_schedule);
  590. extern void md_reload_sb(struct mddev *mddev, int raid_disk);
  591. extern void md_update_sb(struct mddev *mddev, int force);
  592. extern void md_kick_rdev_from_array(struct md_rdev * rdev);
  593. struct md_rdev *md_find_rdev_nr_rcu(struct mddev *mddev, int nr);
  594. static inline int mddev_check_plugged(struct mddev *mddev)
  595. {
  596. return !!blk_check_plugged(md_unplug, mddev,
  597. sizeof(struct blk_plug_cb));
  598. }
  599. static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
  600. {
  601. int faulty = test_bit(Faulty, &rdev->flags);
  602. if (atomic_dec_and_test(&rdev->nr_pending) && faulty) {
  603. set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  604. md_wakeup_thread(mddev->thread);
  605. }
  606. }
  607. extern struct md_cluster_operations *md_cluster_ops;
  608. static inline int mddev_is_clustered(struct mddev *mddev)
  609. {
  610. return mddev->cluster_info && mddev->bitmap_info.nodes > 1;
  611. }
  612. #endif /* _MD_MD_H */