md.h 27 KB

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