md_k.h 9.6 KB

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