md_k.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. md_k.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_K_H
  13. #define _MD_K_H
  14. /* and dm-bio-list.h is not under include/linux because.... ??? */
  15. #include "../../../drivers/md/dm-bio-list.h"
  16. #ifdef CONFIG_BLOCK
  17. #define MaxSector (~(sector_t)0)
  18. typedef struct mddev_s mddev_t;
  19. typedef struct mdk_rdev_s mdk_rdev_t;
  20. /*
  21. * options passed in raidrun:
  22. */
  23. /* Currently this must fit in an 'int' */
  24. #define MAX_CHUNK_SIZE (1<<30)
  25. /*
  26. * MD's 'extended' device
  27. */
  28. struct mdk_rdev_s
  29. {
  30. struct list_head same_set; /* RAID devices within the same set */
  31. sector_t size; /* Device size (in blocks) */
  32. mddev_t *mddev; /* RAID array if running */
  33. int last_events; /* IO event timestamp */
  34. struct block_device *bdev; /* block device handle */
  35. struct page *sb_page;
  36. int sb_loaded;
  37. __u64 sb_events;
  38. sector_t data_offset; /* start of data in array */
  39. sector_t sb_start; /* offset of the super block (in 512byte sectors) */
  40. int sb_size; /* bytes in the superblock */
  41. int preferred_minor; /* autorun support */
  42. struct kobject kobj;
  43. /* A device can be in one of three states based on two flags:
  44. * Not working: faulty==1 in_sync==0
  45. * Fully working: faulty==0 in_sync==1
  46. * Working, but not
  47. * in sync with array
  48. * faulty==0 in_sync==0
  49. *
  50. * It can never have faulty==1, in_sync==1
  51. * This reduces the burden of testing multiple flags in many cases
  52. */
  53. unsigned long flags;
  54. #define Faulty 1 /* device is known to have a fault */
  55. #define In_sync 2 /* device is in_sync with rest of array */
  56. #define WriteMostly 4 /* Avoid reading if at all possible */
  57. #define BarriersNotsupp 5 /* BIO_RW_BARRIER is not supported */
  58. #define AllReserved 6 /* If whole device is reserved for
  59. * one array */
  60. #define AutoDetected 7 /* added by auto-detect */
  61. #define Blocked 8 /* An error occured on an externally
  62. * managed array, don't allow writes
  63. * until it is cleared */
  64. #define StateChanged 9 /* Faulty or Blocked has changed during
  65. * interrupt, so it needs to be
  66. * notified by the thread */
  67. wait_queue_head_t blocked_wait;
  68. int desc_nr; /* descriptor index in the superblock */
  69. int raid_disk; /* role of device in array */
  70. int saved_raid_disk; /* role that device used to have in the
  71. * array and could again if we did a partial
  72. * resync from the bitmap
  73. */
  74. sector_t recovery_offset;/* If this device has been partially
  75. * recovered, this is where we were
  76. * up to.
  77. */
  78. atomic_t nr_pending; /* number of pending requests.
  79. * only maintained for arrays that
  80. * support hot removal
  81. */
  82. atomic_t read_errors; /* number of consecutive read errors that
  83. * we have tried to ignore.
  84. */
  85. atomic_t corrected_errors; /* number of corrected read errors,
  86. * for reporting to userspace and storing
  87. * in superblock.
  88. */
  89. struct work_struct del_work; /* used for delayed sysfs removal */
  90. struct sysfs_dirent *sysfs_state; /* handle for 'state'
  91. * sysfs entry */
  92. };
  93. struct mddev_s
  94. {
  95. void *private;
  96. struct mdk_personality *pers;
  97. dev_t unit;
  98. int md_minor;
  99. struct list_head disks;
  100. unsigned long flags;
  101. #define MD_CHANGE_DEVS 0 /* Some device status has changed */
  102. #define MD_CHANGE_CLEAN 1 /* transition to or from 'clean' */
  103. #define MD_CHANGE_PENDING 2 /* superblock update in progress */
  104. int ro;
  105. struct gendisk *gendisk;
  106. struct kobject kobj;
  107. int hold_active;
  108. #define UNTIL_IOCTL 1
  109. #define UNTIL_STOP 2
  110. /* Superblock information */
  111. int major_version,
  112. minor_version,
  113. patch_version;
  114. int persistent;
  115. int external; /* metadata is
  116. * managed externally */
  117. char metadata_type[17]; /* externally set*/
  118. int chunk_size;
  119. time_t ctime, utime;
  120. int level, layout;
  121. char clevel[16];
  122. int raid_disks;
  123. int max_disks;
  124. sector_t size; /* used size of component devices */
  125. sector_t array_sectors; /* exported array size */
  126. __u64 events;
  127. char uuid[16];
  128. /* If the array is being reshaped, we need to record the
  129. * new shape and an indication of where we are up to.
  130. * This is written to the superblock.
  131. * If reshape_position is MaxSector, then no reshape is happening (yet).
  132. */
  133. sector_t reshape_position;
  134. int delta_disks, new_level, new_layout, new_chunk;
  135. struct mdk_thread_s *thread; /* management thread */
  136. struct mdk_thread_s *sync_thread; /* doing resync or reconstruct */
  137. sector_t curr_resync; /* last block scheduled */
  138. unsigned long resync_mark; /* a recent timestamp */
  139. sector_t resync_mark_cnt;/* blocks written at resync_mark */
  140. sector_t curr_mark_cnt; /* blocks scheduled now */
  141. sector_t resync_max_sectors; /* may be set by personality */
  142. sector_t resync_mismatches; /* count of sectors where
  143. * parity/replica mismatch found
  144. */
  145. /* allow user-space to request suspension of IO to regions of the array */
  146. sector_t suspend_lo;
  147. sector_t suspend_hi;
  148. /* if zero, use the system-wide default */
  149. int sync_speed_min;
  150. int sync_speed_max;
  151. /* resync even though the same disks are shared among md-devices */
  152. int parallel_resync;
  153. int ok_start_degraded;
  154. /* recovery/resync flags
  155. * NEEDED: we might need to start a resync/recover
  156. * RUNNING: a thread is running, or about to be started
  157. * SYNC: actually doing a resync, not a recovery
  158. * RECOVER: doing recovery, or need to try it.
  159. * INTR: resync needs to be aborted for some reason
  160. * DONE: thread is done and is waiting to be reaped
  161. * REQUEST: user-space has requested a sync (used with SYNC)
  162. * CHECK: user-space request for for check-only, no repair
  163. * RESHAPE: A reshape is happening
  164. *
  165. * If neither SYNC or RESHAPE are set, then it is a recovery.
  166. */
  167. #define MD_RECOVERY_RUNNING 0
  168. #define MD_RECOVERY_SYNC 1
  169. #define MD_RECOVERY_RECOVER 2
  170. #define MD_RECOVERY_INTR 3
  171. #define MD_RECOVERY_DONE 4
  172. #define MD_RECOVERY_NEEDED 5
  173. #define MD_RECOVERY_REQUESTED 6
  174. #define MD_RECOVERY_CHECK 7
  175. #define MD_RECOVERY_RESHAPE 8
  176. #define MD_RECOVERY_FROZEN 9
  177. unsigned long recovery;
  178. int recovery_disabled; /* if we detect that recovery
  179. * will always fail, set this
  180. * so we don't loop trying */
  181. int in_sync; /* know to not need resync */
  182. struct mutex reconfig_mutex;
  183. atomic_t active; /* general refcount */
  184. atomic_t openers; /* number of active opens */
  185. int changed; /* true if we might need to reread partition info */
  186. int degraded; /* whether md should consider
  187. * adding a spare
  188. */
  189. int barriers_work; /* initialised to true, cleared as soon
  190. * as a barrier request to slave
  191. * fails. Only supported
  192. */
  193. struct bio *biolist; /* bios that need to be retried
  194. * because BIO_RW_BARRIER is not supported
  195. */
  196. atomic_t recovery_active; /* blocks scheduled, but not written */
  197. wait_queue_head_t recovery_wait;
  198. sector_t recovery_cp;
  199. sector_t resync_min; /* user requested sync
  200. * starts here */
  201. sector_t resync_max; /* resync should pause
  202. * when it gets here */
  203. struct sysfs_dirent *sysfs_state; /* handle for 'array_state'
  204. * file in sysfs.
  205. */
  206. struct sysfs_dirent *sysfs_action; /* handle for 'sync_action' */
  207. struct work_struct del_work; /* used for delayed sysfs removal */
  208. spinlock_t write_lock;
  209. wait_queue_head_t sb_wait; /* for waiting on superblock updates */
  210. atomic_t pending_writes; /* number of active superblock writes */
  211. unsigned int safemode; /* if set, update "clean" superblock
  212. * when no writes pending.
  213. */
  214. unsigned int safemode_delay;
  215. struct timer_list safemode_timer;
  216. atomic_t writes_pending;
  217. struct request_queue *queue; /* for plugging ... */
  218. atomic_t write_behind; /* outstanding async IO */
  219. unsigned int max_write_behind; /* 0 = sync */
  220. struct bitmap *bitmap; /* the bitmap for the device */
  221. struct file *bitmap_file; /* the bitmap file */
  222. long bitmap_offset; /* offset from superblock of
  223. * start of bitmap. May be
  224. * negative, but not '0'
  225. */
  226. long default_bitmap_offset; /* this is the offset to use when
  227. * hot-adding a bitmap. It should
  228. * eventually be settable by sysfs.
  229. */
  230. struct list_head all_mddevs;
  231. };
  232. static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
  233. {
  234. int faulty = test_bit(Faulty, &rdev->flags);
  235. if (atomic_dec_and_test(&rdev->nr_pending) && faulty)
  236. set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  237. }
  238. static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
  239. {
  240. atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
  241. }
  242. struct mdk_personality
  243. {
  244. char *name;
  245. int level;
  246. struct list_head list;
  247. struct module *owner;
  248. int (*make_request)(struct request_queue *q, struct bio *bio);
  249. int (*run)(mddev_t *mddev);
  250. int (*stop)(mddev_t *mddev);
  251. void (*status)(struct seq_file *seq, mddev_t *mddev);
  252. /* error_handler must set ->faulty and clear ->in_sync
  253. * if appropriate, and should abort recovery if needed
  254. */
  255. void (*error_handler)(mddev_t *mddev, mdk_rdev_t *rdev);
  256. int (*hot_add_disk) (mddev_t *mddev, mdk_rdev_t *rdev);
  257. int (*hot_remove_disk) (mddev_t *mddev, int number);
  258. int (*spare_active) (mddev_t *mddev);
  259. sector_t (*sync_request)(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster);
  260. int (*resize) (mddev_t *mddev, sector_t sectors);
  261. int (*check_reshape) (mddev_t *mddev);
  262. int (*start_reshape) (mddev_t *mddev);
  263. int (*reconfig) (mddev_t *mddev, int layout, int chunk_size);
  264. /* quiesce moves between quiescence states
  265. * 0 - fully active
  266. * 1 - no new requests allowed
  267. * others - reserved
  268. */
  269. void (*quiesce) (mddev_t *mddev, int state);
  270. };
  271. struct md_sysfs_entry {
  272. struct attribute attr;
  273. ssize_t (*show)(mddev_t *, char *);
  274. ssize_t (*store)(mddev_t *, const char *, size_t);
  275. };
  276. static inline char * mdname (mddev_t * mddev)
  277. {
  278. return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
  279. }
  280. /*
  281. * iterates through some rdev ringlist. It's safe to remove the
  282. * current 'rdev'. Dont touch 'tmp' though.
  283. */
  284. #define rdev_for_each_list(rdev, tmp, head) \
  285. list_for_each_entry_safe(rdev, tmp, head, same_set)
  286. /*
  287. * iterates through the 'same array disks' ringlist
  288. */
  289. #define rdev_for_each(rdev, tmp, mddev) \
  290. list_for_each_entry_safe(rdev, tmp, &((mddev)->disks), same_set)
  291. #define rdev_for_each_rcu(rdev, mddev) \
  292. list_for_each_entry_rcu(rdev, &((mddev)->disks), same_set)
  293. typedef struct mdk_thread_s {
  294. void (*run) (mddev_t *mddev);
  295. mddev_t *mddev;
  296. wait_queue_head_t wqueue;
  297. unsigned long flags;
  298. struct task_struct *tsk;
  299. unsigned long timeout;
  300. } mdk_thread_t;
  301. #define THREAD_WAKEUP 0
  302. #define __wait_event_lock_irq(wq, condition, lock, cmd) \
  303. do { \
  304. wait_queue_t __wait; \
  305. init_waitqueue_entry(&__wait, current); \
  306. \
  307. add_wait_queue(&wq, &__wait); \
  308. for (;;) { \
  309. set_current_state(TASK_UNINTERRUPTIBLE); \
  310. if (condition) \
  311. break; \
  312. spin_unlock_irq(&lock); \
  313. cmd; \
  314. schedule(); \
  315. spin_lock_irq(&lock); \
  316. } \
  317. current->state = TASK_RUNNING; \
  318. remove_wait_queue(&wq, &__wait); \
  319. } while (0)
  320. #define wait_event_lock_irq(wq, condition, lock, cmd) \
  321. do { \
  322. if (condition) \
  323. break; \
  324. __wait_event_lock_irq(wq, condition, lock, cmd); \
  325. } while (0)
  326. static inline void safe_put_page(struct page *p)
  327. {
  328. if (p) put_page(p);
  329. }
  330. #endif /* CONFIG_BLOCK */
  331. #endif
  332. extern int register_md_personality(struct mdk_personality *p);
  333. extern int unregister_md_personality(struct mdk_personality *p);
  334. extern mdk_thread_t * md_register_thread(void (*run) (mddev_t *mddev),
  335. mddev_t *mddev, const char *name);
  336. extern void md_unregister_thread(mdk_thread_t *thread);
  337. extern void md_wakeup_thread(mdk_thread_t *thread);
  338. extern void md_check_recovery(mddev_t *mddev);
  339. extern void md_write_start(mddev_t *mddev, struct bio *bi);
  340. extern void md_write_end(mddev_t *mddev);
  341. extern void md_done_sync(mddev_t *mddev, int blocks, int ok);
  342. extern void md_error(mddev_t *mddev, mdk_rdev_t *rdev);
  343. extern void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev,
  344. sector_t sector, int size, struct page *page);
  345. extern void md_super_wait(mddev_t *mddev);
  346. extern int sync_page_io(struct block_device *bdev, sector_t sector, int size,
  347. struct page *page, int rw);
  348. extern void md_do_sync(mddev_t *mddev);
  349. extern void md_new_event(mddev_t *mddev);
  350. extern int md_allow_write(mddev_t *mddev);
  351. extern void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev);