md_k.h 11 KB

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