Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | md_k.h : kernel internal structure of the Linux MD driver |
| 3 | Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2, or (at your option) |
| 8 | any later version. |
| 9 | |
| 10 | You should have received a copy of the GNU General Public License |
| 11 | (for example /usr/src/linux/COPYING); if not, write to the Free |
| 12 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 13 | */ |
| 14 | |
| 15 | #ifndef _MD_K_H |
| 16 | #define _MD_K_H |
| 17 | |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 18 | /* and dm-bio-list.h is not under include/linux because.... ??? */ |
| 19 | #include "../../../drivers/md/dm-bio-list.h" |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #define MD_RESERVED 0UL |
| 22 | #define LINEAR 1UL |
| 23 | #define RAID0 2UL |
| 24 | #define RAID1 3UL |
| 25 | #define RAID5 4UL |
| 26 | #define TRANSLUCENT 5UL |
| 27 | #define HSM 6UL |
| 28 | #define MULTIPATH 7UL |
| 29 | #define RAID6 8UL |
| 30 | #define RAID10 9UL |
| 31 | #define FAULTY 10UL |
| 32 | #define MAX_PERSONALITY 11UL |
| 33 | |
| 34 | #define LEVEL_MULTIPATH (-4) |
| 35 | #define LEVEL_LINEAR (-1) |
| 36 | #define LEVEL_FAULTY (-5) |
| 37 | |
| 38 | #define MaxSector (~(sector_t)0) |
| 39 | #define MD_THREAD_NAME_MAX 14 |
| 40 | |
| 41 | static inline int pers_to_level (int pers) |
| 42 | { |
| 43 | switch (pers) { |
| 44 | case FAULTY: return LEVEL_FAULTY; |
| 45 | case MULTIPATH: return LEVEL_MULTIPATH; |
| 46 | case HSM: return -3; |
| 47 | case TRANSLUCENT: return -2; |
| 48 | case LINEAR: return LEVEL_LINEAR; |
| 49 | case RAID0: return 0; |
| 50 | case RAID1: return 1; |
| 51 | case RAID5: return 5; |
| 52 | case RAID6: return 6; |
| 53 | case RAID10: return 10; |
| 54 | } |
| 55 | BUG(); |
| 56 | return MD_RESERVED; |
| 57 | } |
| 58 | |
| 59 | static inline int level_to_pers (int level) |
| 60 | { |
| 61 | switch (level) { |
| 62 | case LEVEL_FAULTY: return FAULTY; |
| 63 | case LEVEL_MULTIPATH: return MULTIPATH; |
| 64 | case -3: return HSM; |
| 65 | case -2: return TRANSLUCENT; |
| 66 | case LEVEL_LINEAR: return LINEAR; |
| 67 | case 0: return RAID0; |
| 68 | case 1: return RAID1; |
| 69 | case 4: |
| 70 | case 5: return RAID5; |
| 71 | case 6: return RAID6; |
| 72 | case 10: return RAID10; |
| 73 | } |
| 74 | return MD_RESERVED; |
| 75 | } |
| 76 | |
| 77 | typedef struct mddev_s mddev_t; |
| 78 | typedef struct mdk_rdev_s mdk_rdev_t; |
| 79 | |
| 80 | #define MAX_MD_DEVS 256 /* Max number of md dev */ |
| 81 | |
| 82 | /* |
| 83 | * options passed in raidrun: |
| 84 | */ |
| 85 | |
| 86 | #define MAX_CHUNK_SIZE (4096*1024) |
| 87 | |
| 88 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | * MD's 'extended' device |
| 90 | */ |
| 91 | struct mdk_rdev_s |
| 92 | { |
| 93 | struct list_head same_set; /* RAID devices within the same set */ |
| 94 | |
| 95 | sector_t size; /* Device size (in blocks) */ |
| 96 | mddev_t *mddev; /* RAID array if running */ |
| 97 | unsigned long last_events; /* IO event timestamp */ |
| 98 | |
| 99 | struct block_device *bdev; /* block device handle */ |
| 100 | |
| 101 | struct page *sb_page; |
| 102 | int sb_loaded; |
| 103 | sector_t data_offset; /* start of data in array */ |
| 104 | sector_t sb_offset; |
NeilBrown | 0002b27 | 2005-09-09 16:23:53 -0700 | [diff] [blame] | 105 | int sb_size; /* bytes in the superblock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | int preferred_minor; /* autorun support */ |
| 107 | |
NeilBrown | 86e6ffd | 2005-11-08 21:39:24 -0800 | [diff] [blame] | 108 | struct kobject kobj; |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* A device can be in one of three states based on two flags: |
| 111 | * Not working: faulty==1 in_sync==0 |
| 112 | * Fully working: faulty==0 in_sync==1 |
| 113 | * Working, but not |
| 114 | * in sync with array |
| 115 | * faulty==0 in_sync==0 |
| 116 | * |
| 117 | * It can never have faulty==1, in_sync==1 |
| 118 | * This reduces the burden of testing multiple flags in many cases |
| 119 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 121 | unsigned long flags; |
| 122 | #define Faulty 1 /* device is known to have a fault */ |
| 123 | #define In_sync 2 /* device is in_sync with rest of array */ |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 124 | #define WriteMostly 4 /* Avoid reading if at all possible */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 125 | #define BarriersNotsupp 5 /* BIO_RW_BARRIER is not supported */ |
NeilBrown | 8ddf9ef | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int desc_nr; /* descriptor index in the superblock */ |
| 128 | int raid_disk; /* role of device in array */ |
NeilBrown | 41158c7 | 2005-06-21 17:17:25 -0700 | [diff] [blame] | 129 | int saved_raid_disk; /* role that device used to have in the |
| 130 | * array and could again if we did a partial |
| 131 | * resync from the bitmap |
| 132 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | atomic_t nr_pending; /* number of pending requests. |
| 135 | * only maintained for arrays that |
| 136 | * support hot removal |
| 137 | */ |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 138 | atomic_t read_errors; /* number of consecutive read errors that |
| 139 | * we have tried to ignore. |
| 140 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | typedef struct mdk_personality_s mdk_personality_t; |
| 144 | |
| 145 | struct mddev_s |
| 146 | { |
| 147 | void *private; |
| 148 | mdk_personality_t *pers; |
| 149 | dev_t unit; |
| 150 | int md_minor; |
| 151 | struct list_head disks; |
| 152 | int sb_dirty; |
| 153 | int ro; |
| 154 | |
| 155 | struct gendisk *gendisk; |
| 156 | |
NeilBrown | eae1701 | 2005-11-08 21:39:23 -0800 | [diff] [blame] | 157 | struct kobject kobj; |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* Superblock information */ |
| 160 | int major_version, |
| 161 | minor_version, |
| 162 | patch_version; |
| 163 | int persistent; |
| 164 | int chunk_size; |
| 165 | time_t ctime, utime; |
| 166 | int level, layout; |
| 167 | int raid_disks; |
| 168 | int max_disks; |
| 169 | sector_t size; /* used size of component devices */ |
| 170 | sector_t array_size; /* exported array size */ |
| 171 | __u64 events; |
| 172 | |
| 173 | char uuid[16]; |
| 174 | |
| 175 | struct mdk_thread_s *thread; /* management thread */ |
| 176 | struct mdk_thread_s *sync_thread; /* doing resync or reconstruct */ |
| 177 | sector_t curr_resync; /* blocks scheduled */ |
| 178 | unsigned long resync_mark; /* a recent timestamp */ |
| 179 | sector_t resync_mark_cnt;/* blocks written at resync_mark */ |
| 180 | |
| 181 | sector_t resync_max_sectors; /* may be set by personality */ |
NeilBrown | 9d88883 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 182 | |
| 183 | sector_t resync_mismatches; /* count of sectors where |
| 184 | * parity/replica mismatch found |
| 185 | */ |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame^] | 186 | int ok_start_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | /* recovery/resync flags |
| 188 | * NEEDED: we might need to start a resync/recover |
| 189 | * RUNNING: a thread is running, or about to be started |
| 190 | * SYNC: actually doing a resync, not a recovery |
| 191 | * ERR: and IO error was detected - abort the resync/recovery |
| 192 | * INTR: someone requested a (clean) early abort. |
| 193 | * DONE: thread is done and is waiting to be reaped |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 194 | * REQUEST: user-space has requested a sync (used with SYNC) |
| 195 | * CHECK: user-space request for for check-only, no repair |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | */ |
| 197 | #define MD_RECOVERY_RUNNING 0 |
| 198 | #define MD_RECOVERY_SYNC 1 |
| 199 | #define MD_RECOVERY_ERR 2 |
| 200 | #define MD_RECOVERY_INTR 3 |
| 201 | #define MD_RECOVERY_DONE 4 |
| 202 | #define MD_RECOVERY_NEEDED 5 |
NeilBrown | 24dd469 | 2005-11-08 21:39:26 -0800 | [diff] [blame] | 203 | #define MD_RECOVERY_REQUESTED 6 |
| 204 | #define MD_RECOVERY_CHECK 7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | unsigned long recovery; |
| 206 | |
| 207 | int in_sync; /* know to not need resync */ |
| 208 | struct semaphore reconfig_sem; |
| 209 | atomic_t active; |
| 210 | |
| 211 | int changed; /* true if we might need to reread partition info */ |
| 212 | int degraded; /* whether md should consider |
| 213 | * adding a spare |
| 214 | */ |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 215 | int barriers_work; /* initialised to true, cleared as soon |
| 216 | * as a barrier request to slave |
| 217 | * fails. Only supported |
| 218 | */ |
| 219 | struct bio *biolist; /* bios that need to be retried |
| 220 | * because BIO_RW_BARRIER is not supported |
| 221 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | atomic_t recovery_active; /* blocks scheduled, but not written */ |
| 224 | wait_queue_head_t recovery_wait; |
| 225 | sector_t recovery_cp; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 226 | |
| 227 | spinlock_t write_lock; |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 228 | wait_queue_head_t sb_wait; /* for waiting on superblock updates */ |
NeilBrown | 7bfa19f | 2005-06-21 17:17:28 -0700 | [diff] [blame] | 229 | atomic_t pending_writes; /* number of active superblock writes */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | unsigned int safemode; /* if set, update "clean" superblock |
| 232 | * when no writes pending. |
| 233 | */ |
| 234 | unsigned int safemode_delay; |
| 235 | struct timer_list safemode_timer; |
| 236 | atomic_t writes_pending; |
| 237 | request_queue_t *queue; /* for plugging ... */ |
| 238 | |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 239 | atomic_t write_behind; /* outstanding async IO */ |
| 240 | unsigned int max_write_behind; /* 0 = sync */ |
| 241 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 242 | struct bitmap *bitmap; /* the bitmap for the device */ |
| 243 | struct file *bitmap_file; /* the bitmap file */ |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 244 | long bitmap_offset; /* offset from superblock of |
| 245 | * start of bitmap. May be |
| 246 | * negative, but not '0' |
| 247 | */ |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 248 | long default_bitmap_offset; /* this is the offset to use when |
| 249 | * hot-adding a bitmap. It should |
| 250 | * eventually be settable by sysfs. |
| 251 | */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | struct list_head all_mddevs; |
| 254 | }; |
| 255 | |
| 256 | |
| 257 | static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev) |
| 258 | { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 259 | int faulty = test_bit(Faulty, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (atomic_dec_and_test(&rdev->nr_pending) && faulty) |
| 261 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 262 | } |
| 263 | |
| 264 | static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors) |
| 265 | { |
| 266 | atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io); |
| 267 | } |
| 268 | |
| 269 | struct mdk_personality_s |
| 270 | { |
| 271 | char *name; |
| 272 | struct module *owner; |
| 273 | int (*make_request)(request_queue_t *q, struct bio *bio); |
| 274 | int (*run)(mddev_t *mddev); |
| 275 | int (*stop)(mddev_t *mddev); |
| 276 | void (*status)(struct seq_file *seq, mddev_t *mddev); |
| 277 | /* error_handler must set ->faulty and clear ->in_sync |
| 278 | * if appropriate, and should abort recovery if needed |
| 279 | */ |
| 280 | void (*error_handler)(mddev_t *mddev, mdk_rdev_t *rdev); |
| 281 | int (*hot_add_disk) (mddev_t *mddev, mdk_rdev_t *rdev); |
| 282 | int (*hot_remove_disk) (mddev_t *mddev, int number); |
| 283 | int (*spare_active) (mddev_t *mddev); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 284 | sector_t (*sync_request)(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | int (*resize) (mddev_t *mddev, sector_t sectors); |
| 286 | int (*reshape) (mddev_t *mddev, int raid_disks); |
| 287 | int (*reconfig) (mddev_t *mddev, int layout, int chunk_size); |
NeilBrown | 36fa306 | 2005-09-09 16:23:45 -0700 | [diff] [blame] | 288 | /* quiesce moves between quiescence states |
| 289 | * 0 - fully active |
| 290 | * 1 - no new requests allowed |
| 291 | * others - reserved |
| 292 | */ |
| 293 | void (*quiesce) (mddev_t *mddev, int state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | }; |
| 295 | |
| 296 | |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 297 | struct md_sysfs_entry { |
| 298 | struct attribute attr; |
| 299 | ssize_t (*show)(mddev_t *, char *); |
| 300 | ssize_t (*store)(mddev_t *, const char *, size_t); |
| 301 | }; |
| 302 | |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | static inline char * mdname (mddev_t * mddev) |
| 305 | { |
| 306 | return mddev->gendisk ? mddev->gendisk->disk_name : "mdX"; |
| 307 | } |
| 308 | |
| 309 | extern mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr); |
| 310 | |
| 311 | /* |
| 312 | * iterates through some rdev ringlist. It's safe to remove the |
| 313 | * current 'rdev'. Dont touch 'tmp' though. |
| 314 | */ |
| 315 | #define ITERATE_RDEV_GENERIC(head,rdev,tmp) \ |
| 316 | \ |
| 317 | for ((tmp) = (head).next; \ |
| 318 | (rdev) = (list_entry((tmp), mdk_rdev_t, same_set)), \ |
| 319 | (tmp) = (tmp)->next, (tmp)->prev != &(head) \ |
| 320 | ; ) |
| 321 | /* |
| 322 | * iterates through the 'same array disks' ringlist |
| 323 | */ |
| 324 | #define ITERATE_RDEV(mddev,rdev,tmp) \ |
| 325 | ITERATE_RDEV_GENERIC((mddev)->disks,rdev,tmp) |
| 326 | |
| 327 | /* |
| 328 | * Iterates through 'pending RAID disks' |
| 329 | */ |
| 330 | #define ITERATE_RDEV_PENDING(rdev,tmp) \ |
| 331 | ITERATE_RDEV_GENERIC(pending_raid_disks,rdev,tmp) |
| 332 | |
| 333 | typedef struct mdk_thread_s { |
| 334 | void (*run) (mddev_t *mddev); |
| 335 | mddev_t *mddev; |
| 336 | wait_queue_head_t wqueue; |
| 337 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | struct task_struct *tsk; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 339 | unsigned long timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } mdk_thread_t; |
| 341 | |
| 342 | #define THREAD_WAKEUP 0 |
| 343 | |
| 344 | #define __wait_event_lock_irq(wq, condition, lock, cmd) \ |
| 345 | do { \ |
| 346 | wait_queue_t __wait; \ |
| 347 | init_waitqueue_entry(&__wait, current); \ |
| 348 | \ |
| 349 | add_wait_queue(&wq, &__wait); \ |
| 350 | for (;;) { \ |
| 351 | set_current_state(TASK_UNINTERRUPTIBLE); \ |
| 352 | if (condition) \ |
| 353 | break; \ |
| 354 | spin_unlock_irq(&lock); \ |
| 355 | cmd; \ |
| 356 | schedule(); \ |
| 357 | spin_lock_irq(&lock); \ |
| 358 | } \ |
| 359 | current->state = TASK_RUNNING; \ |
| 360 | remove_wait_queue(&wq, &__wait); \ |
| 361 | } while (0) |
| 362 | |
| 363 | #define wait_event_lock_irq(wq, condition, lock, cmd) \ |
| 364 | do { \ |
| 365 | if (condition) \ |
| 366 | break; \ |
| 367 | __wait_event_lock_irq(wq, condition, lock, cmd); \ |
| 368 | } while (0) |
| 369 | |
| 370 | #endif |
| 371 | |