2 md_k.h : kernel internal structure of the Linux MD driver
3 Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman
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)
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.
18 /* and dm-bio-list.h is not under include/linux because.... ??? */
19 #include "../../../drivers/md/dm-bio-list.h"
21 #define MD_RESERVED 0UL
26 #define TRANSLUCENT 5UL
32 #define MAX_PERSONALITY 11UL
34 #define LEVEL_MULTIPATH (-4)
35 #define LEVEL_LINEAR (-1)
36 #define LEVEL_FAULTY (-5)
38 #define MaxSector (~(sector_t)0)
39 #define MD_THREAD_NAME_MAX 14
41 static inline int pers_to_level (int pers)
44 case FAULTY: return LEVEL_FAULTY;
45 case MULTIPATH: return LEVEL_MULTIPATH;
47 case TRANSLUCENT: return -2;
48 case LINEAR: return LEVEL_LINEAR;
53 case RAID10: return 10;
59 static inline int level_to_pers (int level)
62 case LEVEL_FAULTY: return FAULTY;
63 case LEVEL_MULTIPATH: return MULTIPATH;
65 case -2: return TRANSLUCENT;
66 case LEVEL_LINEAR: return LINEAR;
72 case 10: return RAID10;
77 typedef struct mddev_s mddev_t;
78 typedef struct mdk_rdev_s mdk_rdev_t;
80 #define MAX_MD_DEVS 256 /* Max number of md dev */
83 * options passed in raidrun:
86 #define MAX_CHUNK_SIZE (4096*1024)
89 * MD's 'extended' device
93 struct list_head same_set; /* RAID devices within the same set */
95 sector_t size; /* Device size (in blocks) */
96 mddev_t *mddev; /* RAID array if running */
97 unsigned long last_events; /* IO event timestamp */
99 struct block_device *bdev; /* block device handle */
101 struct page *sb_page;
103 sector_t data_offset; /* start of data in array */
105 int preferred_minor; /* autorun support */
107 /* A device can be in one of three states based on two flags:
108 * Not working: faulty==1 in_sync==0
109 * Fully working: faulty==0 in_sync==1
112 * faulty==0 in_sync==0
114 * It can never have faulty==1, in_sync==1
115 * This reduces the burden of testing multiple flags in many cases
117 int faulty; /* if faulty do not issue IO requests */
118 int in_sync; /* device is a full member of the array */
120 unsigned long flags; /* Should include faulty and in_sync here. */
121 #define WriteMostly 4 /* Avoid reading if at all possible */
123 int desc_nr; /* descriptor index in the superblock */
124 int raid_disk; /* role of device in array */
125 int saved_raid_disk; /* role that device used to have in the
126 * array and could again if we did a partial
127 * resync from the bitmap
130 atomic_t nr_pending; /* number of pending requests.
131 * only maintained for arrays that
132 * support hot removal
136 typedef struct mdk_personality_s mdk_personality_t;
141 mdk_personality_t *pers;
144 struct list_head disks;
148 struct gendisk *gendisk;
150 /* Superblock information */
160 sector_t size; /* used size of component devices */
161 sector_t array_size; /* exported array size */
166 struct mdk_thread_s *thread; /* management thread */
167 struct mdk_thread_s *sync_thread; /* doing resync or reconstruct */
168 sector_t curr_resync; /* blocks scheduled */
169 unsigned long resync_mark; /* a recent timestamp */
170 sector_t resync_mark_cnt;/* blocks written at resync_mark */
172 sector_t resync_max_sectors; /* may be set by personality */
173 /* recovery/resync flags
174 * NEEDED: we might need to start a resync/recover
175 * RUNNING: a thread is running, or about to be started
176 * SYNC: actually doing a resync, not a recovery
177 * ERR: and IO error was detected - abort the resync/recovery
178 * INTR: someone requested a (clean) early abort.
179 * DONE: thread is done and is waiting to be reaped
181 #define MD_RECOVERY_RUNNING 0
182 #define MD_RECOVERY_SYNC 1
183 #define MD_RECOVERY_ERR 2
184 #define MD_RECOVERY_INTR 3
185 #define MD_RECOVERY_DONE 4
186 #define MD_RECOVERY_NEEDED 5
187 unsigned long recovery;
189 int in_sync; /* know to not need resync */
190 struct semaphore reconfig_sem;
193 int changed; /* true if we might need to reread partition info */
194 int degraded; /* whether md should consider
198 atomic_t recovery_active; /* blocks scheduled, but not written */
199 wait_queue_head_t recovery_wait;
200 sector_t recovery_cp;
202 spinlock_t write_lock;
203 wait_queue_head_t sb_wait; /* for waiting on superblock updates */
204 atomic_t pending_writes; /* number of active superblock writes */
206 unsigned int safemode; /* if set, update "clean" superblock
207 * when no writes pending.
209 unsigned int safemode_delay;
210 struct timer_list safemode_timer;
211 atomic_t writes_pending;
212 request_queue_t *queue; /* for plugging ... */
214 atomic_t write_behind; /* outstanding async IO */
215 unsigned int max_write_behind; /* 0 = sync */
217 struct bitmap *bitmap; /* the bitmap for the device */
218 struct file *bitmap_file; /* the bitmap file */
219 long bitmap_offset; /* offset from superblock of
220 * start of bitmap. May be
221 * negative, but not '0'
223 long default_bitmap_offset; /* this is the offset to use when
224 * hot-adding a bitmap. It should
225 * eventually be settable by sysfs.
228 struct list_head all_mddevs;
232 static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
234 int faulty = rdev->faulty;
235 if (atomic_dec_and_test(&rdev->nr_pending) && faulty)
236 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
239 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
241 atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
244 struct mdk_personality_s
247 struct module *owner;
248 int (*make_request)(request_queue_t *q, struct bio *bio);
249 int (*run)(mddev_t *mddev);
250 int (*stop)(mddev_t *mddev);
251 void (*status)(struct seq_file *seq, mddev_t *mddev);
252 /* error_handler must set ->faulty and clear ->in_sync
253 * if appropriate, and should abort recovery if needed
255 void (*error_handler)(mddev_t *mddev, mdk_rdev_t *rdev);
256 int (*hot_add_disk) (mddev_t *mddev, mdk_rdev_t *rdev);
257 int (*hot_remove_disk) (mddev_t *mddev, int number);
258 int (*spare_active) (mddev_t *mddev);
259 sector_t (*sync_request)(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster);
260 int (*resize) (mddev_t *mddev, sector_t sectors);
261 int (*reshape) (mddev_t *mddev, int raid_disks);
262 int (*reconfig) (mddev_t *mddev, int layout, int chunk_size);
263 /* quiesce moves between quiescence states
265 * 1 - no new requests allowed
268 void (*quiesce) (mddev_t *mddev, int state);
272 static inline char * mdname (mddev_t * mddev)
274 return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
277 extern mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr);
280 * iterates through some rdev ringlist. It's safe to remove the
281 * current 'rdev'. Dont touch 'tmp' though.
283 #define ITERATE_RDEV_GENERIC(head,rdev,tmp) \
285 for ((tmp) = (head).next; \
286 (rdev) = (list_entry((tmp), mdk_rdev_t, same_set)), \
287 (tmp) = (tmp)->next, (tmp)->prev != &(head) \
290 * iterates through the 'same array disks' ringlist
292 #define ITERATE_RDEV(mddev,rdev,tmp) \
293 ITERATE_RDEV_GENERIC((mddev)->disks,rdev,tmp)
296 * Iterates through 'pending RAID disks'
298 #define ITERATE_RDEV_PENDING(rdev,tmp) \
299 ITERATE_RDEV_GENERIC(pending_raid_disks,rdev,tmp)
301 typedef struct mdk_thread_s {
302 void (*run) (mddev_t *mddev);
304 wait_queue_head_t wqueue;
306 struct completion *event;
307 struct task_struct *tsk;
308 unsigned long timeout;
312 #define THREAD_WAKEUP 0
314 #define __wait_event_lock_irq(wq, condition, lock, cmd) \
316 wait_queue_t __wait; \
317 init_waitqueue_entry(&__wait, current); \
319 add_wait_queue(&wq, &__wait); \
321 set_current_state(TASK_UNINTERRUPTIBLE); \
324 spin_unlock_irq(&lock); \
327 spin_lock_irq(&lock); \
329 current->state = TASK_RUNNING; \
330 remove_wait_queue(&wq, &__wait); \
333 #define wait_event_lock_irq(wq, condition, lock, cmd) \
337 __wait_event_lock_irq(wq, condition, lock, cmd); \