md.h 28 KB

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