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 sb_size; /* bytes in the superblock */
106 int preferred_minor; /* autorun support */
108 /* A device can be in one of three states based on two flags:
109 * Not working: faulty==1 in_sync==0
110 * Fully working: faulty==0 in_sync==1
113 * faulty==0 in_sync==0
115 * It can never have faulty==1, in_sync==1
116 * This reduces the burden of testing multiple flags in many cases
118 int faulty; /* if faulty do not issue IO requests */
119 int in_sync; /* device is a full member of the array */
121 unsigned long flags; /* Should include faulty and in_sync here. */
122 #define WriteMostly 4 /* Avoid reading if at all possible */
124 int desc_nr; /* descriptor index in the superblock */
125 int raid_disk; /* role of device in array */
126 int saved_raid_disk; /* role that device used to have in the
127 * array and could again if we did a partial
128 * resync from the bitmap
131 atomic_t nr_pending; /* number of pending requests.
132 * only maintained for arrays that
133 * support hot removal
137 typedef struct mdk_personality_s mdk_personality_t;
142 mdk_personality_t *pers;
145 struct list_head disks;
149 struct gendisk *gendisk;
153 /* Superblock information */
163 sector_t size; /* used size of component devices */
164 sector_t array_size; /* exported array size */
169 struct mdk_thread_s *thread; /* management thread */
170 struct mdk_thread_s *sync_thread; /* doing resync or reconstruct */
171 sector_t curr_resync; /* blocks scheduled */
172 unsigned long resync_mark; /* a recent timestamp */
173 sector_t resync_mark_cnt;/* blocks written at resync_mark */
175 sector_t resync_max_sectors; /* may be set by personality */
176 /* recovery/resync flags
177 * NEEDED: we might need to start a resync/recover
178 * RUNNING: a thread is running, or about to be started
179 * SYNC: actually doing a resync, not a recovery
180 * ERR: and IO error was detected - abort the resync/recovery
181 * INTR: someone requested a (clean) early abort.
182 * DONE: thread is done and is waiting to be reaped
184 #define MD_RECOVERY_RUNNING 0
185 #define MD_RECOVERY_SYNC 1
186 #define MD_RECOVERY_ERR 2
187 #define MD_RECOVERY_INTR 3
188 #define MD_RECOVERY_DONE 4
189 #define MD_RECOVERY_NEEDED 5
190 unsigned long recovery;
192 int in_sync; /* know to not need resync */
193 struct semaphore reconfig_sem;
196 int changed; /* true if we might need to reread partition info */
197 int degraded; /* whether md should consider
201 atomic_t recovery_active; /* blocks scheduled, but not written */
202 wait_queue_head_t recovery_wait;
203 sector_t recovery_cp;
205 spinlock_t write_lock;
206 wait_queue_head_t sb_wait; /* for waiting on superblock updates */
207 atomic_t pending_writes; /* number of active superblock writes */
209 unsigned int safemode; /* if set, update "clean" superblock
210 * when no writes pending.
212 unsigned int safemode_delay;
213 struct timer_list safemode_timer;
214 atomic_t writes_pending;
215 request_queue_t *queue; /* for plugging ... */
217 atomic_t write_behind; /* outstanding async IO */
218 unsigned int max_write_behind; /* 0 = sync */
220 struct bitmap *bitmap; /* the bitmap for the device */
221 struct file *bitmap_file; /* the bitmap file */
222 long bitmap_offset; /* offset from superblock of
223 * start of bitmap. May be
224 * negative, but not '0'
226 long default_bitmap_offset; /* this is the offset to use when
227 * hot-adding a bitmap. It should
228 * eventually be settable by sysfs.
231 struct list_head all_mddevs;
235 static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
237 int faulty = rdev->faulty;
238 if (atomic_dec_and_test(&rdev->nr_pending) && faulty)
239 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
242 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
244 atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
247 struct mdk_personality_s
250 struct module *owner;
251 int (*make_request)(request_queue_t *q, struct bio *bio);
252 int (*run)(mddev_t *mddev);
253 int (*stop)(mddev_t *mddev);
254 void (*status)(struct seq_file *seq, mddev_t *mddev);
255 /* error_handler must set ->faulty and clear ->in_sync
256 * if appropriate, and should abort recovery if needed
258 void (*error_handler)(mddev_t *mddev, mdk_rdev_t *rdev);
259 int (*hot_add_disk) (mddev_t *mddev, mdk_rdev_t *rdev);
260 int (*hot_remove_disk) (mddev_t *mddev, int number);
261 int (*spare_active) (mddev_t *mddev);
262 sector_t (*sync_request)(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster);
263 int (*resize) (mddev_t *mddev, sector_t sectors);
264 int (*reshape) (mddev_t *mddev, int raid_disks);
265 int (*reconfig) (mddev_t *mddev, int layout, int chunk_size);
266 /* quiesce moves between quiescence states
268 * 1 - no new requests allowed
271 void (*quiesce) (mddev_t *mddev, int state);
275 static inline char * mdname (mddev_t * mddev)
277 return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
280 extern mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr);
283 * iterates through some rdev ringlist. It's safe to remove the
284 * current 'rdev'. Dont touch 'tmp' though.
286 #define ITERATE_RDEV_GENERIC(head,rdev,tmp) \
288 for ((tmp) = (head).next; \
289 (rdev) = (list_entry((tmp), mdk_rdev_t, same_set)), \
290 (tmp) = (tmp)->next, (tmp)->prev != &(head) \
293 * iterates through the 'same array disks' ringlist
295 #define ITERATE_RDEV(mddev,rdev,tmp) \
296 ITERATE_RDEV_GENERIC((mddev)->disks,rdev,tmp)
299 * Iterates through 'pending RAID disks'
301 #define ITERATE_RDEV_PENDING(rdev,tmp) \
302 ITERATE_RDEV_GENERIC(pending_raid_disks,rdev,tmp)
304 typedef struct mdk_thread_s {
305 void (*run) (mddev_t *mddev);
307 wait_queue_head_t wqueue;
309 struct completion *event;
310 struct task_struct *tsk;
311 unsigned long timeout;
315 #define THREAD_WAKEUP 0
317 #define __wait_event_lock_irq(wq, condition, lock, cmd) \
319 wait_queue_t __wait; \
320 init_waitqueue_entry(&__wait, current); \
322 add_wait_queue(&wq, &__wait); \
324 set_current_state(TASK_UNINTERRUPTIBLE); \
327 spin_unlock_irq(&lock); \
330 spin_lock_irq(&lock); \
332 current->state = TASK_RUNNING; \
333 remove_wait_queue(&wq, &__wait); \
336 #define wait_event_lock_irq(wq, condition, lock, cmd) \
340 __wait_event_lock_irq(wq, condition, lock, cmd); \