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)
92 static inline int disk_faulty(mdp_disk_t
* d
)
94 return d
->state
& (1 << MD_DISK_FAULTY
);
97 static inline int disk_active(mdp_disk_t
* d
)
99 return d
->state
& (1 << MD_DISK_ACTIVE
);
102 static inline int disk_sync(mdp_disk_t
* d
)
104 return d
->state
& (1 << MD_DISK_SYNC
);
107 static inline int disk_spare(mdp_disk_t
* d
)
109 return !disk_sync(d
) && !disk_active(d
) && !disk_faulty(d
);
112 static inline int disk_removed(mdp_disk_t
* d
)
114 return d
->state
& (1 << MD_DISK_REMOVED
);
117 static inline void mark_disk_faulty(mdp_disk_t
* d
)
119 d
->state
|= (1 << MD_DISK_FAULTY
);
122 static inline void mark_disk_active(mdp_disk_t
* d
)
124 d
->state
|= (1 << MD_DISK_ACTIVE
);
127 static inline void mark_disk_sync(mdp_disk_t
* d
)
129 d
->state
|= (1 << MD_DISK_SYNC
);
132 static inline void mark_disk_spare(mdp_disk_t
* d
)
137 static inline void mark_disk_removed(mdp_disk_t
* d
)
139 d
->state
= (1 << MD_DISK_FAULTY
) | (1 << MD_DISK_REMOVED
);
142 static inline void mark_disk_inactive(mdp_disk_t
* d
)
144 d
->state
&= ~(1 << MD_DISK_ACTIVE
);
147 static inline void mark_disk_nonsync(mdp_disk_t
* d
)
149 d
->state
&= ~(1 << MD_DISK_SYNC
);
153 * MD's 'extended' device
157 struct list_head same_set
; /* RAID devices within the same set */
159 sector_t size
; /* Device size (in blocks) */
160 mddev_t
*mddev
; /* RAID array if running */
161 unsigned long last_events
; /* IO event timestamp */
163 struct block_device
*bdev
; /* block device handle */
165 struct page
*sb_page
;
167 sector_t data_offset
; /* start of data in array */
169 int preferred_minor
; /* autorun support */
171 /* A device can be in one of three states based on two flags:
172 * Not working: faulty==1 in_sync==0
173 * Fully working: faulty==0 in_sync==1
176 * faulty==0 in_sync==0
178 * It can never have faulty==1, in_sync==1
179 * This reduces the burden of testing multiple flags in many cases
181 int faulty
; /* if faulty do not issue IO requests */
182 int in_sync
; /* device is a full member of the array */
184 int desc_nr
; /* descriptor index in the superblock */
185 int raid_disk
; /* role of device in array */
186 int saved_raid_disk
; /* role that device used to have in the
187 * array and could again if we did a partial
188 * resync from the bitmap
191 atomic_t nr_pending
; /* number of pending requests.
192 * only maintained for arrays that
193 * support hot removal
197 typedef struct mdk_personality_s mdk_personality_t
;
202 mdk_personality_t
*pers
;
205 struct list_head disks
;
209 struct gendisk
*gendisk
;
211 /* Superblock information */
221 sector_t size
; /* used size of component devices */
222 sector_t array_size
; /* exported array size */
227 struct mdk_thread_s
*thread
; /* management thread */
228 struct mdk_thread_s
*sync_thread
; /* doing resync or reconstruct */
229 sector_t curr_resync
; /* blocks scheduled */
230 unsigned long resync_mark
; /* a recent timestamp */
231 sector_t resync_mark_cnt
;/* blocks written at resync_mark */
233 sector_t resync_max_sectors
; /* may be set by personality */
234 /* recovery/resync flags
235 * NEEDED: we might need to start a resync/recover
236 * RUNNING: a thread is running, or about to be started
237 * SYNC: actually doing a resync, not a recovery
238 * ERR: and IO error was detected - abort the resync/recovery
239 * INTR: someone requested a (clean) early abort.
240 * DONE: thread is done and is waiting to be reaped
242 #define MD_RECOVERY_RUNNING 0
243 #define MD_RECOVERY_SYNC 1
244 #define MD_RECOVERY_ERR 2
245 #define MD_RECOVERY_INTR 3
246 #define MD_RECOVERY_DONE 4
247 #define MD_RECOVERY_NEEDED 5
248 unsigned long recovery
;
250 int in_sync
; /* know to not need resync */
251 struct semaphore reconfig_sem
;
254 int changed
; /* true if we might need to reread partition info */
255 int degraded
; /* whether md should consider
259 atomic_t recovery_active
; /* blocks scheduled, but not written */
260 wait_queue_head_t recovery_wait
;
261 sector_t recovery_cp
;
263 spinlock_t write_lock
;
264 wait_queue_head_t sb_wait
; /* for waiting on superblock updates */
265 atomic_t pending_writes
; /* number of active superblock writes */
267 unsigned int safemode
; /* if set, update "clean" superblock
268 * when no writes pending.
270 unsigned int safemode_delay
;
271 struct timer_list safemode_timer
;
272 atomic_t writes_pending
;
273 request_queue_t
*queue
; /* for plugging ... */
275 struct bitmap
*bitmap
; /* the bitmap for the device */
276 struct file
*bitmap_file
; /* the bitmap file */
277 long bitmap_offset
; /* offset from superblock of
278 * start of bitmap. May be
279 * negative, but not '0'
282 struct list_head all_mddevs
;
286 static inline void rdev_dec_pending(mdk_rdev_t
*rdev
, mddev_t
*mddev
)
288 int faulty
= rdev
->faulty
;
289 if (atomic_dec_and_test(&rdev
->nr_pending
) && faulty
)
290 set_bit(MD_RECOVERY_NEEDED
, &mddev
->recovery
);
293 static inline void md_sync_acct(struct block_device
*bdev
, unsigned long nr_sectors
)
295 atomic_add(nr_sectors
, &bdev
->bd_contains
->bd_disk
->sync_io
);
298 struct mdk_personality_s
301 struct module
*owner
;
302 int (*make_request
)(request_queue_t
*q
, struct bio
*bio
);
303 int (*run
)(mddev_t
*mddev
);
304 int (*stop
)(mddev_t
*mddev
);
305 void (*status
)(struct seq_file
*seq
, mddev_t
*mddev
);
306 /* error_handler must set ->faulty and clear ->in_sync
307 * if appropriate, and should abort recovery if needed
309 void (*error_handler
)(mddev_t
*mddev
, mdk_rdev_t
*rdev
);
310 int (*hot_add_disk
) (mddev_t
*mddev
, mdk_rdev_t
*rdev
);
311 int (*hot_remove_disk
) (mddev_t
*mddev
, int number
);
312 int (*spare_active
) (mddev_t
*mddev
);
313 sector_t (*sync_request
)(mddev_t
*mddev
, sector_t sector_nr
, int *skipped
, int go_faster
);
314 int (*resize
) (mddev_t
*mddev
, sector_t sectors
);
315 int (*reshape
) (mddev_t
*mddev
, int raid_disks
);
316 int (*reconfig
) (mddev_t
*mddev
, int layout
, int chunk_size
);
320 static inline char * mdname (mddev_t
* mddev
)
322 return mddev
->gendisk
? mddev
->gendisk
->disk_name
: "mdX";
325 extern mdk_rdev_t
* find_rdev_nr(mddev_t
*mddev
, int nr
);
328 * iterates through some rdev ringlist. It's safe to remove the
329 * current 'rdev'. Dont touch 'tmp' though.
331 #define ITERATE_RDEV_GENERIC(head,rdev,tmp) \
333 for ((tmp) = (head).next; \
334 (rdev) = (list_entry((tmp), mdk_rdev_t, same_set)), \
335 (tmp) = (tmp)->next, (tmp)->prev != &(head) \
338 * iterates through the 'same array disks' ringlist
340 #define ITERATE_RDEV(mddev,rdev,tmp) \
341 ITERATE_RDEV_GENERIC((mddev)->disks,rdev,tmp)
344 * Iterates through 'pending RAID disks'
346 #define ITERATE_RDEV_PENDING(rdev,tmp) \
347 ITERATE_RDEV_GENERIC(pending_raid_disks,rdev,tmp)
349 typedef struct mdk_thread_s
{
350 void (*run
) (mddev_t
*mddev
);
352 wait_queue_head_t wqueue
;
354 struct completion
*event
;
355 struct task_struct
*tsk
;
356 unsigned long timeout
;
360 #define THREAD_WAKEUP 0
362 #define __wait_event_lock_irq(wq, condition, lock, cmd) \
364 wait_queue_t __wait; \
365 init_waitqueue_entry(&__wait, current); \
367 add_wait_queue(&wq, &__wait); \
369 set_current_state(TASK_UNINTERRUPTIBLE); \
372 spin_unlock_irq(&lock); \
375 spin_lock_irq(&lock); \
377 current->state = TASK_RUNNING; \
378 remove_wait_queue(&wq, &__wait); \
381 #define wait_event_lock_irq(wq, condition, lock, cmd) \
385 __wait_event_lock_irq(wq, condition, lock, cmd); \