md_k.h 12 KB

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