md_k.h 10 KB

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