]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/raid/md_k.h
[PATCH] md: improvements to raid5 handling of read errors
[net-next-2.6.git] / include / linux / raid / md_k.h
CommitLineData
1da177e4
LT
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
06d91a5f
N
18/* and dm-bio-list.h is not under include/linux because.... ??? */
19#include "../../../drivers/md/dm-bio-list.h"
20
1da177e4
LT
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
41static 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
59static 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
77typedef struct mddev_s mddev_t;
78typedef 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
1da177e4
LT
88/*
89 * MD's 'extended' device
90 */
91struct 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;
0002b271 105 int sb_size; /* bytes in the superblock */
1da177e4
LT
106 int preferred_minor; /* autorun support */
107
86e6ffdd
N
108 struct kobject kobj;
109
1da177e4
LT
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 */
120 int faulty; /* if faulty do not issue IO requests */
121 int in_sync; /* device is a full member of the array */
122
8ddf9efe
N
123 unsigned long flags; /* Should include faulty and in_sync here. */
124#define WriteMostly 4 /* Avoid reading if at all possible */
125
1da177e4
LT
126 int desc_nr; /* descriptor index in the superblock */
127 int raid_disk; /* role of device in array */
41158c7e
N
128 int saved_raid_disk; /* role that device used to have in the
129 * array and could again if we did a partial
130 * resync from the bitmap
131 */
1da177e4
LT
132
133 atomic_t nr_pending; /* number of pending requests.
134 * only maintained for arrays that
135 * support hot removal
136 */
ba22dcbf
N
137 atomic_t read_errors; /* number of consecutive read errors that
138 * we have tried to ignore.
139 */
1da177e4
LT
140};
141
142typedef struct mdk_personality_s mdk_personality_t;
143
144struct mddev_s
145{
146 void *private;
147 mdk_personality_t *pers;
148 dev_t unit;
149 int md_minor;
150 struct list_head disks;
151 int sb_dirty;
152 int ro;
153
154 struct gendisk *gendisk;
155
eae1701f
N
156 struct kobject kobj;
157
1da177e4
LT
158 /* Superblock information */
159 int major_version,
160 minor_version,
161 patch_version;
162 int persistent;
163 int chunk_size;
164 time_t ctime, utime;
165 int level, layout;
166 int raid_disks;
167 int max_disks;
168 sector_t size; /* used size of component devices */
169 sector_t array_size; /* exported array size */
170 __u64 events;
171
172 char uuid[16];
173
174 struct mdk_thread_s *thread; /* management thread */
175 struct mdk_thread_s *sync_thread; /* doing resync or reconstruct */
176 sector_t curr_resync; /* blocks scheduled */
177 unsigned long resync_mark; /* a recent timestamp */
178 sector_t resync_mark_cnt;/* blocks written at resync_mark */
179
180 sector_t resync_max_sectors; /* may be set by personality */
9d88883e
N
181
182 sector_t resync_mismatches; /* count of sectors where
183 * parity/replica mismatch found
184 */
1da177e4
LT
185 /* recovery/resync flags
186 * NEEDED: we might need to start a resync/recover
187 * RUNNING: a thread is running, or about to be started
188 * SYNC: actually doing a resync, not a recovery
189 * ERR: and IO error was detected - abort the resync/recovery
190 * INTR: someone requested a (clean) early abort.
191 * DONE: thread is done and is waiting to be reaped
24dd469d
N
192 * REQUEST: user-space has requested a sync (used with SYNC)
193 * CHECK: user-space request for for check-only, no repair
1da177e4
LT
194 */
195#define MD_RECOVERY_RUNNING 0
196#define MD_RECOVERY_SYNC 1
197#define MD_RECOVERY_ERR 2
198#define MD_RECOVERY_INTR 3
199#define MD_RECOVERY_DONE 4
200#define MD_RECOVERY_NEEDED 5
24dd469d
N
201#define MD_RECOVERY_REQUESTED 6
202#define MD_RECOVERY_CHECK 7
1da177e4
LT
203 unsigned long recovery;
204
205 int in_sync; /* know to not need resync */
206 struct semaphore reconfig_sem;
207 atomic_t active;
208
209 int changed; /* true if we might need to reread partition info */
210 int degraded; /* whether md should consider
211 * adding a spare
212 */
213
214 atomic_t recovery_active; /* blocks scheduled, but not written */
215 wait_queue_head_t recovery_wait;
216 sector_t recovery_cp;
06d91a5f
N
217
218 spinlock_t write_lock;
3d310eb7 219 wait_queue_head_t sb_wait; /* for waiting on superblock updates */
7bfa19f2 220 atomic_t pending_writes; /* number of active superblock writes */
06d91a5f 221
1da177e4
LT
222 unsigned int safemode; /* if set, update "clean" superblock
223 * when no writes pending.
224 */
225 unsigned int safemode_delay;
226 struct timer_list safemode_timer;
227 atomic_t writes_pending;
228 request_queue_t *queue; /* for plugging ... */
229
4b6d287f
N
230 atomic_t write_behind; /* outstanding async IO */
231 unsigned int max_write_behind; /* 0 = sync */
232
32a7627c
N
233 struct bitmap *bitmap; /* the bitmap for the device */
234 struct file *bitmap_file; /* the bitmap file */
a654b9d8
N
235 long bitmap_offset; /* offset from superblock of
236 * start of bitmap. May be
237 * negative, but not '0'
238 */
36fa3063
N
239 long default_bitmap_offset; /* this is the offset to use when
240 * hot-adding a bitmap. It should
241 * eventually be settable by sysfs.
242 */
32a7627c 243
1da177e4
LT
244 struct list_head all_mddevs;
245};
246
247
248static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
249{
250 int faulty = rdev->faulty;
251 if (atomic_dec_and_test(&rdev->nr_pending) && faulty)
252 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
253}
254
255static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
256{
257 atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
258}
259
260struct mdk_personality_s
261{
262 char *name;
263 struct module *owner;
264 int (*make_request)(request_queue_t *q, struct bio *bio);
265 int (*run)(mddev_t *mddev);
266 int (*stop)(mddev_t *mddev);
267 void (*status)(struct seq_file *seq, mddev_t *mddev);
268 /* error_handler must set ->faulty and clear ->in_sync
269 * if appropriate, and should abort recovery if needed
270 */
271 void (*error_handler)(mddev_t *mddev, mdk_rdev_t *rdev);
272 int (*hot_add_disk) (mddev_t *mddev, mdk_rdev_t *rdev);
273 int (*hot_remove_disk) (mddev_t *mddev, int number);
274 int (*spare_active) (mddev_t *mddev);
57afd89f 275 sector_t (*sync_request)(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster);
1da177e4
LT
276 int (*resize) (mddev_t *mddev, sector_t sectors);
277 int (*reshape) (mddev_t *mddev, int raid_disks);
278 int (*reconfig) (mddev_t *mddev, int layout, int chunk_size);
36fa3063
N
279 /* quiesce moves between quiescence states
280 * 0 - fully active
281 * 1 - no new requests allowed
282 * others - reserved
283 */
284 void (*quiesce) (mddev_t *mddev, int state);
1da177e4
LT
285};
286
287
007583c9
N
288struct md_sysfs_entry {
289 struct attribute attr;
290 ssize_t (*show)(mddev_t *, char *);
291 ssize_t (*store)(mddev_t *, const char *, size_t);
292};
293
294
1da177e4
LT
295static inline char * mdname (mddev_t * mddev)
296{
297 return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
298}
299
300extern mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr);
301
302/*
303 * iterates through some rdev ringlist. It's safe to remove the
304 * current 'rdev'. Dont touch 'tmp' though.
305 */
306#define ITERATE_RDEV_GENERIC(head,rdev,tmp) \
307 \
308 for ((tmp) = (head).next; \
309 (rdev) = (list_entry((tmp), mdk_rdev_t, same_set)), \
310 (tmp) = (tmp)->next, (tmp)->prev != &(head) \
311 ; )
312/*
313 * iterates through the 'same array disks' ringlist
314 */
315#define ITERATE_RDEV(mddev,rdev,tmp) \
316 ITERATE_RDEV_GENERIC((mddev)->disks,rdev,tmp)
317
318/*
319 * Iterates through 'pending RAID disks'
320 */
321#define ITERATE_RDEV_PENDING(rdev,tmp) \
322 ITERATE_RDEV_GENERIC(pending_raid_disks,rdev,tmp)
323
324typedef struct mdk_thread_s {
325 void (*run) (mddev_t *mddev);
326 mddev_t *mddev;
327 wait_queue_head_t wqueue;
328 unsigned long flags;
329 struct completion *event;
330 struct task_struct *tsk;
32a7627c 331 unsigned long timeout;
1da177e4
LT
332 const char *name;
333} mdk_thread_t;
334
335#define THREAD_WAKEUP 0
336
337#define __wait_event_lock_irq(wq, condition, lock, cmd) \
338do { \
339 wait_queue_t __wait; \
340 init_waitqueue_entry(&__wait, current); \
341 \
342 add_wait_queue(&wq, &__wait); \
343 for (;;) { \
344 set_current_state(TASK_UNINTERRUPTIBLE); \
345 if (condition) \
346 break; \
347 spin_unlock_irq(&lock); \
348 cmd; \
349 schedule(); \
350 spin_lock_irq(&lock); \
351 } \
352 current->state = TASK_RUNNING; \
353 remove_wait_queue(&wq, &__wait); \
354} while (0)
355
356#define wait_event_lock_irq(wq, condition, lock, cmd) \
357do { \
358 if (condition) \
359 break; \
360 __wait_event_lock_irq(wq, condition, lock, cmd); \
361} while (0)
362
363#endif
364