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