md.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  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. /* change UNSUPPORTED_MDDEV_FLAGS for each array type if new flag is added */
  217. enum mddev_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
  220. * it then */
  221. MD_JOURNAL_CLEAN, /* A raid with journal is already clean */
  222. MD_HAS_JOURNAL, /* The raid array has journal feature set */
  223. MD_CLUSTER_RESYNC_LOCKED, /* cluster raid only, which means node
  224. * already took resync lock, need to
  225. * release the lock */
  226. MD_FAILFAST_SUPPORTED, /* Using MD_FAILFAST on metadata writes is
  227. * supported as calls to md_error() will
  228. * never cause the array to become failed.
  229. */
  230. MD_HAS_PPL, /* The raid array has PPL feature set */
  231. MD_HAS_MULTIPLE_PPLS, /* The raid array has multiple PPLs feature set */
  232. MD_ALLOW_SB_UPDATE, /* md_check_recovery is allowed to update
  233. * the metadata without taking reconfig_mutex.
  234. */
  235. MD_UPDATING_SB, /* md_check_recovery is updating the metadata
  236. * without explicitly holding reconfig_mutex.
  237. */
  238. MD_NOT_READY, /* do_md_run() is active, so 'array_state'
  239. * must not report that array is ready yet
  240. */
  241. MD_BROKEN, /* This is used in RAID-0/LINEAR only, to stop
  242. * I/O in case an array member is gone/failed.
  243. */
  244. };
  245. enum mddev_sb_flags {
  246. MD_SB_CHANGE_DEVS, /* Some device status has changed */
  247. MD_SB_CHANGE_CLEAN, /* transition to or from 'clean' */
  248. MD_SB_CHANGE_PENDING, /* switch from 'clean' to 'active' in progress */
  249. MD_SB_NEED_REWRITE, /* metadata write needs to be repeated */
  250. };
  251. #define NR_SERIAL_INFOS 8
  252. /* record current range of serialize IOs */
  253. struct serial_info {
  254. struct rb_node node;
  255. sector_t start; /* start sector of rb node */
  256. sector_t last; /* end sector of rb node */
  257. sector_t _subtree_last; /* highest sector in subtree of rb node */
  258. };
  259. struct mddev {
  260. void *private;
  261. struct md_personality *pers;
  262. dev_t unit;
  263. int md_minor;
  264. struct list_head disks;
  265. unsigned long flags;
  266. unsigned long sb_flags;
  267. int suspended;
  268. atomic_t active_io;
  269. int ro;
  270. int sysfs_active; /* set when sysfs deletes
  271. * are happening, so run/
  272. * takeover/stop are not safe
  273. */
  274. struct gendisk *gendisk;
  275. struct kobject kobj;
  276. int hold_active;
  277. #define UNTIL_IOCTL 1
  278. #define UNTIL_STOP 2
  279. /* Superblock information */
  280. int major_version,
  281. minor_version,
  282. patch_version;
  283. int persistent;
  284. int external; /* metadata is
  285. * managed externally */
  286. char metadata_type[17]; /* externally set*/
  287. int chunk_sectors;
  288. time64_t ctime, utime;
  289. int level, layout;
  290. char clevel[16];
  291. int raid_disks;
  292. int max_disks;
  293. sector_t dev_sectors; /* used size of
  294. * component devices */
  295. sector_t array_sectors; /* exported array size */
  296. int external_size; /* size managed
  297. * externally */
  298. __u64 events;
  299. /* If the last 'event' was simply a clean->dirty transition, and
  300. * we didn't write it to the spares, then it is safe and simple
  301. * to just decrement the event count on a dirty->clean transition.
  302. * So we record that possibility here.
  303. */
  304. int can_decrease_events;
  305. char uuid[16];
  306. /* If the array is being reshaped, we need to record the
  307. * new shape and an indication of where we are up to.
  308. * This is written to the superblock.
  309. * If reshape_position is MaxSector, then no reshape is happening (yet).
  310. */
  311. sector_t reshape_position;
  312. int delta_disks, new_level, new_layout;
  313. int new_chunk_sectors;
  314. int reshape_backwards;
  315. struct md_thread *thread; /* management thread */
  316. struct md_thread *sync_thread; /* doing resync or reconstruct */
  317. /* 'last_sync_action' is initialized to "none". It is set when a
  318. * sync operation (i.e "data-check", "requested-resync", "resync",
  319. * "recovery", or "reshape") is started. It holds this value even
  320. * when the sync thread is "frozen" (interrupted) or "idle" (stopped
  321. * or finished). It is overwritten when a new sync operation is begun.
  322. */
  323. char *last_sync_action;
  324. sector_t curr_resync; /* last block scheduled */
  325. /* As resync requests can complete out of order, we cannot easily track
  326. * how much resync has been completed. So we occasionally pause until
  327. * everything completes, then set curr_resync_completed to curr_resync.
  328. * As such it may be well behind the real resync mark, but it is a value
  329. * we are certain of.
  330. */
  331. sector_t curr_resync_completed;
  332. unsigned long resync_mark; /* a recent timestamp */
  333. sector_t resync_mark_cnt;/* blocks written at resync_mark */
  334. sector_t curr_mark_cnt; /* blocks scheduled now */
  335. sector_t resync_max_sectors; /* may be set by personality */
  336. atomic64_t resync_mismatches; /* count of sectors where
  337. * parity/replica mismatch found
  338. */
  339. /* allow user-space to request suspension of IO to regions of the array */
  340. sector_t suspend_lo;
  341. sector_t suspend_hi;
  342. /* if zero, use the system-wide default */
  343. int sync_speed_min;
  344. int sync_speed_max;
  345. /* resync even though the same disks are shared among md-devices */
  346. int parallel_resync;
  347. int ok_start_degraded;
  348. unsigned long recovery;
  349. /* If a RAID personality determines that recovery (of a particular
  350. * device) will fail due to a read error on the source device, it
  351. * takes a copy of this number and does not attempt recovery again
  352. * until this number changes.
  353. */
  354. int recovery_disabled;
  355. int in_sync; /* know to not need resync */
  356. /* 'open_mutex' avoids races between 'md_open' and 'do_md_stop', so
  357. * that we are never stopping an array while it is open.
  358. * 'reconfig_mutex' protects all other reconfiguration.
  359. * These locks are separate due to conflicting interactions
  360. * with bdev->bd_mutex.
  361. * Lock ordering is:
  362. * reconfig_mutex -> bd_mutex
  363. * bd_mutex -> open_mutex: e.g. __blkdev_get -> md_open
  364. */
  365. struct mutex open_mutex;
  366. struct mutex reconfig_mutex;
  367. atomic_t active; /* general refcount */
  368. atomic_t openers; /* number of active opens */
  369. int changed; /* True if we might need to
  370. * reread partition info */
  371. int degraded; /* whether md should consider
  372. * adding a spare
  373. */
  374. atomic_t recovery_active; /* blocks scheduled, but not written */
  375. wait_queue_head_t recovery_wait;
  376. sector_t recovery_cp;
  377. sector_t resync_min; /* user requested sync
  378. * starts here */
  379. sector_t resync_max; /* resync should pause
  380. * when it gets here */
  381. struct kernfs_node *sysfs_state; /* handle for 'array_state'
  382. * file in sysfs.
  383. */
  384. struct kernfs_node *sysfs_action; /* handle for 'sync_action' */
  385. struct kernfs_node *sysfs_completed; /*handle for 'sync_completed' */
  386. struct kernfs_node *sysfs_degraded; /*handle for 'degraded' */
  387. struct kernfs_node *sysfs_level; /*handle for 'level' */
  388. struct work_struct del_work; /* used for delayed sysfs removal */
  389. /* "lock" protects:
  390. * flush_bio transition from NULL to !NULL
  391. * rdev superblocks, events
  392. * clearing MD_CHANGE_*
  393. * in_sync - and related safemode and MD_CHANGE changes
  394. * pers (also protected by reconfig_mutex and pending IO).
  395. * clearing ->bitmap
  396. * clearing ->bitmap_info.file
  397. * changing ->resync_{min,max}
  398. * setting MD_RECOVERY_RUNNING (which interacts with resync_{min,max})
  399. */
  400. spinlock_t lock;
  401. wait_queue_head_t sb_wait; /* for waiting on superblock updates */
  402. atomic_t pending_writes; /* number of active superblock writes */
  403. unsigned int safemode; /* if set, update "clean" superblock
  404. * when no writes pending.
  405. */
  406. unsigned int safemode_delay;
  407. struct timer_list safemode_timer;
  408. struct percpu_ref writes_pending;
  409. int sync_checkers; /* # of threads checking writes_pending */
  410. struct request_queue *queue; /* for plugging ... */
  411. struct bitmap *bitmap; /* the bitmap for the device */
  412. struct {
  413. struct file *file; /* the bitmap file */
  414. loff_t offset; /* offset from superblock of
  415. * start of bitmap. May be
  416. * negative, but not '0'
  417. * For external metadata, offset
  418. * from start of device.
  419. */
  420. unsigned long space; /* space available at this offset */
  421. loff_t default_offset; /* this is the offset to use when
  422. * hot-adding a bitmap. It should
  423. * eventually be settable by sysfs.
  424. */
  425. unsigned long default_space; /* space available at
  426. * default offset */
  427. struct mutex mutex;
  428. unsigned long chunksize;
  429. unsigned long daemon_sleep; /* how many jiffies between updates? */
  430. unsigned long max_write_behind; /* write-behind mode */
  431. int external;
  432. int nodes; /* Maximum number of nodes in the cluster */
  433. char cluster_name[64]; /* Name of the cluster */
  434. } bitmap_info;
  435. atomic_t max_corr_read_errors; /* max read retries */
  436. struct list_head all_mddevs;
  437. struct attribute_group *to_remove;
  438. struct bio_set bio_set;
  439. struct bio_set sync_set; /* for sync operations like
  440. * metadata and bitmap writes
  441. */
  442. /* Generic flush handling.
  443. * The last to finish preflush schedules a worker to submit
  444. * the rest of the request (without the REQ_PREFLUSH flag).
  445. */
  446. struct bio *flush_bio;
  447. atomic_t flush_pending;
  448. ktime_t start_flush, last_flush; /* last_flush is when the last completed
  449. * flush was started.
  450. */
  451. struct work_struct flush_work;
  452. struct work_struct event_work; /* used by dm to report failure event */
  453. mempool_t *serial_info_pool;
  454. void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev);
  455. struct md_cluster_info *cluster_info;
  456. unsigned int good_device_nr; /* good device num within cluster raid */
  457. unsigned int noio_flag; /* for memalloc scope API */
  458. bool has_superblocks:1;
  459. bool fail_last_dev:1;
  460. bool serialize_policy:1;
  461. };
  462. enum recovery_flags {
  463. /*
  464. * If neither SYNC or RESHAPE are set, then it is a recovery.
  465. */
  466. MD_RECOVERY_RUNNING, /* a thread is running, or about to be started */
  467. MD_RECOVERY_SYNC, /* actually doing a resync, not a recovery */
  468. MD_RECOVERY_RECOVER, /* doing recovery, or need to try it. */
  469. MD_RECOVERY_INTR, /* resync needs to be aborted for some reason */
  470. MD_RECOVERY_DONE, /* thread is done and is waiting to be reaped */
  471. MD_RECOVERY_NEEDED, /* we might need to start a resync/recover */
  472. MD_RECOVERY_REQUESTED, /* user-space has requested a sync (used with SYNC) */
  473. MD_RECOVERY_CHECK, /* user-space request for check-only, no repair */
  474. MD_RECOVERY_RESHAPE, /* A reshape is happening */
  475. MD_RECOVERY_FROZEN, /* User request to abort, and not restart, any action */
  476. MD_RECOVERY_ERROR, /* sync-action interrupted because io-error */
  477. MD_RECOVERY_WAIT, /* waiting for pers->start() to finish */
  478. MD_RESYNCING_REMOTE, /* remote node is running resync thread */
  479. };
  480. static inline int __must_check mddev_lock(struct mddev *mddev)
  481. {
  482. return mutex_lock_interruptible(&mddev->reconfig_mutex);
  483. }
  484. /* Sometimes we need to take the lock in a situation where
  485. * failure due to interrupts is not acceptable.
  486. */
  487. static inline void mddev_lock_nointr(struct mddev *mddev)
  488. {
  489. mutex_lock(&mddev->reconfig_mutex);
  490. }
  491. static inline int mddev_trylock(struct mddev *mddev)
  492. {
  493. return mutex_trylock(&mddev->reconfig_mutex);
  494. }
  495. extern void mddev_unlock(struct mddev *mddev);
  496. static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
  497. {
  498. atomic_add(nr_sectors, &bdev->bd_disk->sync_io);
  499. }
  500. static inline void md_sync_acct_bio(struct bio *bio, unsigned long nr_sectors)
  501. {
  502. atomic_add(nr_sectors, &bio->bi_disk->sync_io);
  503. }
  504. struct md_personality
  505. {
  506. char *name;
  507. int level;
  508. struct list_head list;
  509. struct module *owner;
  510. bool __must_check (*make_request)(struct mddev *mddev, struct bio *bio);
  511. /*
  512. * start up works that do NOT require md_thread. tasks that
  513. * requires md_thread should go into start()
  514. */
  515. int (*run)(struct mddev *mddev);
  516. /* start up works that require md threads */
  517. int (*start)(struct mddev *mddev);
  518. void (*free)(struct mddev *mddev, void *priv);
  519. void (*status)(struct seq_file *seq, struct mddev *mddev);
  520. /* error_handler must set ->faulty and clear ->in_sync
  521. * if appropriate, and should abort recovery if needed
  522. */
  523. void (*error_handler)(struct mddev *mddev, struct md_rdev *rdev);
  524. int (*hot_add_disk) (struct mddev *mddev, struct md_rdev *rdev);
  525. int (*hot_remove_disk) (struct mddev *mddev, struct md_rdev *rdev);
  526. int (*spare_active) (struct mddev *mddev);
  527. sector_t (*sync_request)(struct mddev *mddev, sector_t sector_nr, int *skipped);
  528. int (*resize) (struct mddev *mddev, sector_t sectors);
  529. sector_t (*size) (struct mddev *mddev, sector_t sectors, int raid_disks);
  530. int (*check_reshape) (struct mddev *mddev);
  531. int (*start_reshape) (struct mddev *mddev);
  532. void (*finish_reshape) (struct mddev *mddev);
  533. void (*update_reshape_pos) (struct mddev *mddev);
  534. /* quiesce suspends or resumes internal processing.
  535. * 1 - stop new actions and wait for action io to complete
  536. * 0 - return to normal behaviour
  537. */
  538. void (*quiesce) (struct mddev *mddev, int quiesce);
  539. /* takeover is used to transition an array from one
  540. * personality to another. The new personality must be able
  541. * to handle the data in the current layout.
  542. * e.g. 2drive raid1 -> 2drive raid5
  543. * ndrive raid5 -> degraded n+1drive raid6 with special layout
  544. * If the takeover succeeds, a new 'private' structure is returned.
  545. * This needs to be installed and then ->run used to activate the
  546. * array.
  547. */
  548. void *(*takeover) (struct mddev *mddev);
  549. /* Changes the consistency policy of an active array. */
  550. int (*change_consistency_policy)(struct mddev *mddev, const char *buf);
  551. };
  552. struct md_sysfs_entry {
  553. struct attribute attr;
  554. ssize_t (*show)(struct mddev *, char *);
  555. ssize_t (*store)(struct mddev *, const char *, size_t);
  556. };
  557. extern struct attribute_group md_bitmap_group;
  558. static inline struct kernfs_node *sysfs_get_dirent_safe(struct kernfs_node *sd, char *name)
  559. {
  560. if (sd)
  561. return sysfs_get_dirent(sd, name);
  562. return sd;
  563. }
  564. static inline void sysfs_notify_dirent_safe(struct kernfs_node *sd)
  565. {
  566. if (sd)
  567. sysfs_notify_dirent(sd);
  568. }
  569. static inline char * mdname (struct mddev * mddev)
  570. {
  571. return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
  572. }
  573. static inline int sysfs_link_rdev(struct mddev *mddev, struct md_rdev *rdev)
  574. {
  575. char nm[20];
  576. if (!test_bit(Replacement, &rdev->flags) &&
  577. !test_bit(Journal, &rdev->flags) &&
  578. mddev->kobj.sd) {
  579. sprintf(nm, "rd%d", rdev->raid_disk);
  580. return sysfs_create_link(&mddev->kobj, &rdev->kobj, nm);
  581. } else
  582. return 0;
  583. }
  584. static inline void sysfs_unlink_rdev(struct mddev *mddev, struct md_rdev *rdev)
  585. {
  586. char nm[20];
  587. if (!test_bit(Replacement, &rdev->flags) &&
  588. !test_bit(Journal, &rdev->flags) &&
  589. mddev->kobj.sd) {
  590. sprintf(nm, "rd%d", rdev->raid_disk);
  591. sysfs_remove_link(&mddev->kobj, nm);
  592. }
  593. }
  594. /*
  595. * iterates through some rdev ringlist. It's safe to remove the
  596. * current 'rdev'. Dont touch 'tmp' though.
  597. */
  598. #define rdev_for_each_list(rdev, tmp, head) \
  599. list_for_each_entry_safe(rdev, tmp, head, same_set)
  600. /*
  601. * iterates through the 'same array disks' ringlist
  602. */
  603. #define rdev_for_each(rdev, mddev) \
  604. list_for_each_entry(rdev, &((mddev)->disks), same_set)
  605. #define rdev_for_each_safe(rdev, tmp, mddev) \
  606. list_for_each_entry_safe(rdev, tmp, &((mddev)->disks), same_set)
  607. #define rdev_for_each_rcu(rdev, mddev) \
  608. list_for_each_entry_rcu(rdev, &((mddev)->disks), same_set)
  609. struct md_thread {
  610. void (*run) (struct md_thread *thread);
  611. struct mddev *mddev;
  612. wait_queue_head_t wqueue;
  613. unsigned long flags;
  614. struct task_struct *tsk;
  615. unsigned long timeout;
  616. void *private;
  617. };
  618. #define THREAD_WAKEUP 0
  619. static inline void safe_put_page(struct page *p)
  620. {
  621. if (p) put_page(p);
  622. }
  623. extern int register_md_personality(struct md_personality *p);
  624. extern int unregister_md_personality(struct md_personality *p);
  625. extern int register_md_cluster_operations(struct md_cluster_operations *ops,
  626. struct module *module);
  627. extern int unregister_md_cluster_operations(void);
  628. extern int md_setup_cluster(struct mddev *mddev, int nodes);
  629. extern void md_cluster_stop(struct mddev *mddev);
  630. extern struct md_thread *md_register_thread(
  631. void (*run)(struct md_thread *thread),
  632. struct mddev *mddev,
  633. const char *name);
  634. extern void md_unregister_thread(struct md_thread **threadp);
  635. extern void md_wakeup_thread(struct md_thread *thread);
  636. extern void md_check_recovery(struct mddev *mddev);
  637. extern void md_reap_sync_thread(struct mddev *mddev);
  638. extern int mddev_init_writes_pending(struct mddev *mddev);
  639. extern bool md_write_start(struct mddev *mddev, struct bio *bi);
  640. extern void md_write_inc(struct mddev *mddev, struct bio *bi);
  641. extern void md_write_end(struct mddev *mddev);
  642. extern void md_done_sync(struct mddev *mddev, int blocks, int ok);
  643. extern void md_error(struct mddev *mddev, struct md_rdev *rdev);
  644. extern void md_finish_reshape(struct mddev *mddev);
  645. extern bool __must_check md_flush_request(struct mddev *mddev, struct bio *bio);
  646. extern void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
  647. sector_t sector, int size, struct page *page);
  648. extern int md_super_wait(struct mddev *mddev);
  649. extern int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
  650. struct page *page, int op, int op_flags,
  651. bool metadata_op);
  652. extern void md_do_sync(struct md_thread *thread);
  653. extern void md_new_event(struct mddev *mddev);
  654. extern void md_allow_write(struct mddev *mddev);
  655. extern void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev);
  656. extern void md_set_array_sectors(struct mddev *mddev, sector_t array_sectors);
  657. extern int md_check_no_bitmap(struct mddev *mddev);
  658. extern int md_integrity_register(struct mddev *mddev);
  659. extern int md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev);
  660. extern int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale);
  661. extern void mddev_init(struct mddev *mddev);
  662. extern int md_run(struct mddev *mddev);
  663. extern int md_start(struct mddev *mddev);
  664. extern void md_stop(struct mddev *mddev);
  665. extern void md_stop_writes(struct mddev *mddev);
  666. extern int md_rdev_init(struct md_rdev *rdev);
  667. extern void md_rdev_clear(struct md_rdev *rdev);
  668. extern void md_handle_request(struct mddev *mddev, struct bio *bio);
  669. extern void mddev_suspend(struct mddev *mddev);
  670. extern void mddev_resume(struct mddev *mddev);
  671. extern struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs,
  672. struct mddev *mddev);
  673. extern void md_reload_sb(struct mddev *mddev, int raid_disk);
  674. extern void md_update_sb(struct mddev *mddev, int force);
  675. extern void md_kick_rdev_from_array(struct md_rdev * rdev);
  676. extern void mddev_create_serial_pool(struct mddev *mddev, struct md_rdev *rdev,
  677. bool is_suspend);
  678. extern void mddev_destroy_serial_pool(struct mddev *mddev, struct md_rdev *rdev,
  679. bool is_suspend);
  680. struct md_rdev *md_find_rdev_nr_rcu(struct mddev *mddev, int nr);
  681. struct md_rdev *md_find_rdev_rcu(struct mddev *mddev, dev_t dev);
  682. static inline bool is_mddev_broken(struct md_rdev *rdev, const char *md_type)
  683. {
  684. int flags = rdev->bdev->bd_disk->flags;
  685. if (!(flags & GENHD_FL_UP)) {
  686. if (!test_and_set_bit(MD_BROKEN, &rdev->mddev->flags))
  687. pr_warn("md: %s: %s array has a missing/failed member\n",
  688. mdname(rdev->mddev), md_type);
  689. return true;
  690. }
  691. return false;
  692. }
  693. static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
  694. {
  695. int faulty = test_bit(Faulty, &rdev->flags);
  696. if (atomic_dec_and_test(&rdev->nr_pending) && faulty) {
  697. set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  698. md_wakeup_thread(mddev->thread);
  699. }
  700. }
  701. extern struct md_cluster_operations *md_cluster_ops;
  702. static inline int mddev_is_clustered(struct mddev *mddev)
  703. {
  704. return mddev->cluster_info && mddev->bitmap_info.nodes > 1;
  705. }
  706. /* clear unsupported mddev_flags */
  707. static inline void mddev_clear_unsupported_flags(struct mddev *mddev,
  708. unsigned long unsupported_flags)
  709. {
  710. mddev->flags &= ~unsupported_flags;
  711. }
  712. static inline void mddev_check_writesame(struct mddev *mddev, struct bio *bio)
  713. {
  714. if (bio_op(bio) == REQ_OP_WRITE_SAME &&
  715. !bio->bi_disk->queue->limits.max_write_same_sectors)
  716. mddev->queue->limits.max_write_same_sectors = 0;
  717. }
  718. static inline void mddev_check_write_zeroes(struct mddev *mddev, struct bio *bio)
  719. {
  720. if (bio_op(bio) == REQ_OP_WRITE_ZEROES &&
  721. !bio->bi_disk->queue->limits.max_write_zeroes_sectors)
  722. mddev->queue->limits.max_write_zeroes_sectors = 0;
  723. }
  724. struct mdu_array_info_s;
  725. struct mdu_disk_info_s;
  726. extern int mdp_major;
  727. void md_autostart_arrays(int part);
  728. int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info);
  729. int md_add_new_disk(struct mddev *mddev, struct mdu_disk_info_s *info);
  730. int do_md_run(struct mddev *mddev);
  731. extern const struct block_device_operations md_fops;
  732. #endif /* _MD_MD_H */