md.h 26 KB

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