aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/raid
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/linux/raid
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/linux/raid')
-rw-r--r--include/linux/raid/linear.h27
-rw-r--r--include/linux/raid/md.h84
-rw-r--r--include/linux/raid/md_k.h369
-rw-r--r--include/linux/raid/md_p.h230
-rw-r--r--include/linux/raid/md_u.h117
-rw-r--r--include/linux/raid/multipath.h42
-rw-r--r--include/linux/raid/raid0.h30
-rw-r--r--include/linux/raid/raid1.h98
-rw-r--r--include/linux/raid/raid10.h103
-rw-r--r--include/linux/raid/raid5.h243
-rw-r--r--include/linux/raid/xor.h23
11 files changed, 1366 insertions, 0 deletions
diff --git a/include/linux/raid/linear.h b/include/linux/raid/linear.h
new file mode 100644
index 000000000000..e04c4fe45b53
--- /dev/null
+++ b/include/linux/raid/linear.h
@@ -0,0 +1,27 @@
1#ifndef _LINEAR_H
2#define _LINEAR_H
3
4#include <linux/raid/md.h>
5
6struct dev_info {
7 mdk_rdev_t *rdev;
8 sector_t size;
9 sector_t offset;
10};
11
12typedef struct dev_info dev_info_t;
13
14struct linear_private_data
15{
16 dev_info_t **hash_table;
17 dev_info_t *smallest;
18 int nr_zones;
19 dev_info_t disks[0];
20};
21
22
23typedef struct linear_private_data linear_conf_t;
24
25#define mddev_to_conf(mddev) ((linear_conf_t *) mddev->private)
26
27#endif
diff --git a/include/linux/raid/md.h b/include/linux/raid/md.h
new file mode 100644
index 000000000000..a6a67d102bfa
--- /dev/null
+++ b/include/linux/raid/md.h
@@ -0,0 +1,84 @@
1/*
2 md.h : Multiple Devices driver for Linux
3 Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman
4 Copyright (C) 1994-96 Marc ZYNGIER
5 <zyngier@ufr-info-p7.ibp.fr> or
6 <maz@gloups.fdn.fr>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 You should have received a copy of the GNU General Public License
14 (for example /usr/src/linux/COPYING); if not, write to the Free
15 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16*/
17
18#ifndef _MD_H
19#define _MD_H
20
21#include <linux/blkdev.h>
22#include <asm/semaphore.h>
23#include <linux/major.h>
24#include <linux/ioctl.h>
25#include <linux/types.h>
26#include <linux/bitops.h>
27#include <linux/module.h>
28#include <linux/hdreg.h>
29#include <linux/proc_fs.h>
30#include <linux/seq_file.h>
31#include <linux/smp_lock.h>
32#include <linux/delay.h>
33#include <net/checksum.h>
34#include <linux/random.h>
35#include <linux/kernel_stat.h>
36#include <asm/io.h>
37#include <linux/completion.h>
38#include <linux/mempool.h>
39#include <linux/list.h>
40#include <linux/reboot.h>
41#include <linux/vmalloc.h>
42#include <linux/blkpg.h>
43#include <linux/bio.h>
44
45/*
46 * 'md_p.h' holds the 'physical' layout of RAID devices
47 * 'md_u.h' holds the user <=> kernel API
48 *
49 * 'md_k.h' holds kernel internal definitions
50 */
51
52#include <linux/raid/md_p.h>
53#include <linux/raid/md_u.h>
54#include <linux/raid/md_k.h>
55
56/*
57 * Different major versions are not compatible.
58 * Different minor versions are only downward compatible.
59 * Different patchlevel versions are downward and upward compatible.
60 */
61#define MD_MAJOR_VERSION 0
62#define MD_MINOR_VERSION 90
63#define MD_PATCHLEVEL_VERSION 1
64
65extern int register_md_personality (int p_num, mdk_personality_t *p);
66extern int unregister_md_personality (int p_num);
67extern mdk_thread_t * md_register_thread (void (*run) (mddev_t *mddev),
68 mddev_t *mddev, const char *name);
69extern void md_unregister_thread (mdk_thread_t *thread);
70extern void md_wakeup_thread(mdk_thread_t *thread);
71extern void md_check_recovery(mddev_t *mddev);
72extern void md_write_start(mddev_t *mddev);
73extern void md_write_end(mddev_t *mddev);
74extern void md_handle_safemode(mddev_t *mddev);
75extern void md_done_sync(mddev_t *mddev, int blocks, int ok);
76extern void md_error (mddev_t *mddev, mdk_rdev_t *rdev);
77extern void md_unplug_mddev(mddev_t *mddev);
78
79extern void md_print_devices (void);
80
81#define MD_BUG(x...) { printk("md: bug in file %s, line %d\n", __FILE__, __LINE__); md_print_devices(); }
82
83#endif
84
diff --git a/include/linux/raid/md_k.h b/include/linux/raid/md_k.h
new file mode 100644
index 000000000000..c9a0d4013be7
--- /dev/null
+++ b/include/linux/raid/md_k.h
@@ -0,0 +1,369 @@
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
18#define MD_RESERVED 0UL
19#define LINEAR 1UL
20#define RAID0 2UL
21#define RAID1 3UL
22#define RAID5 4UL
23#define TRANSLUCENT 5UL
24#define HSM 6UL
25#define MULTIPATH 7UL
26#define RAID6 8UL
27#define RAID10 9UL
28#define FAULTY 10UL
29#define MAX_PERSONALITY 11UL
30
31#define LEVEL_MULTIPATH (-4)
32#define LEVEL_LINEAR (-1)
33#define LEVEL_FAULTY (-5)
34
35#define MaxSector (~(sector_t)0)
36#define MD_THREAD_NAME_MAX 14
37
38static inline int pers_to_level (int pers)
39{
40 switch (pers) {
41 case FAULTY: return LEVEL_FAULTY;
42 case MULTIPATH: return LEVEL_MULTIPATH;
43 case HSM: return -3;
44 case TRANSLUCENT: return -2;
45 case LINEAR: return LEVEL_LINEAR;
46 case RAID0: return 0;
47 case RAID1: return 1;
48 case RAID5: return 5;
49 case RAID6: return 6;
50 case RAID10: return 10;
51 }
52 BUG();
53 return MD_RESERVED;
54}
55
56static inline int level_to_pers (int level)
57{
58 switch (level) {
59 case LEVEL_FAULTY: return FAULTY;
60 case LEVEL_MULTIPATH: return MULTIPATH;
61 case -3: return HSM;
62 case -2: return TRANSLUCENT;
63 case LEVEL_LINEAR: return LINEAR;
64 case 0: return RAID0;
65 case 1: return RAID1;
66 case 4:
67 case 5: return RAID5;
68 case 6: return RAID6;
69 case 10: return RAID10;
70 }
71 return MD_RESERVED;
72}
73
74typedef struct mddev_s mddev_t;
75typedef struct mdk_rdev_s mdk_rdev_t;
76
77#define MAX_MD_DEVS 256 /* Max number of md dev */
78
79/*
80 * options passed in raidrun:
81 */
82
83#define MAX_CHUNK_SIZE (4096*1024)
84
85/*
86 * default readahead
87 */
88
89static inline int disk_faulty(mdp_disk_t * d)
90{
91 return d->state & (1 << MD_DISK_FAULTY);
92}
93
94static inline int disk_active(mdp_disk_t * d)
95{
96 return d->state & (1 << MD_DISK_ACTIVE);
97}
98
99static inline int disk_sync(mdp_disk_t * d)
100{
101 return d->state & (1 << MD_DISK_SYNC);
102}
103
104static inline int disk_spare(mdp_disk_t * d)
105{
106 return !disk_sync(d) && !disk_active(d) && !disk_faulty(d);
107}
108
109static inline int disk_removed(mdp_disk_t * d)
110{
111 return d->state & (1 << MD_DISK_REMOVED);
112}
113
114static inline void mark_disk_faulty(mdp_disk_t * d)
115{
116 d->state |= (1 << MD_DISK_FAULTY);
117}
118
119static inline void mark_disk_active(mdp_disk_t * d)
120{
121 d->state |= (1 << MD_DISK_ACTIVE);
122}
123
124static inline void mark_disk_sync(mdp_disk_t * d)
125{
126 d->state |= (1 << MD_DISK_SYNC);
127}
128
129static inline void mark_disk_spare(mdp_disk_t * d)
130{
131 d->state = 0;
132}
133
134static inline void mark_disk_removed(mdp_disk_t * d)
135{
136 d->state = (1 << MD_DISK_FAULTY) | (1 << MD_DISK_REMOVED);
137}
138
139static inline void mark_disk_inactive(mdp_disk_t * d)
140{
141 d->state &= ~(1 << MD_DISK_ACTIVE);
142}
143
144static inline void mark_disk_nonsync(mdp_disk_t * d)
145{
146 d->state &= ~(1 << MD_DISK_SYNC);
147}
148
149/*
150 * MD's 'extended' device
151 */
152struct mdk_rdev_s
153{
154 struct list_head same_set; /* RAID devices within the same set */
155
156 sector_t size; /* Device size (in blocks) */
157 mddev_t *mddev; /* RAID array if running */
158 unsigned long last_events; /* IO event timestamp */
159
160 struct block_device *bdev; /* block device handle */
161
162 struct page *sb_page;
163 int sb_loaded;
164 sector_t data_offset; /* start of data in array */
165 sector_t sb_offset;
166 int preferred_minor; /* autorun support */
167
168 /* A device can be in one of three states based on two flags:
169 * Not working: faulty==1 in_sync==0
170 * Fully working: faulty==0 in_sync==1
171 * Working, but not
172 * in sync with array
173 * faulty==0 in_sync==0
174 *
175 * It can never have faulty==1, in_sync==1
176 * This reduces the burden of testing multiple flags in many cases
177 */
178 int faulty; /* if faulty do not issue IO requests */
179 int in_sync; /* device is a full member of the array */
180
181 int desc_nr; /* descriptor index in the superblock */
182 int raid_disk; /* role of device in array */
183
184 atomic_t nr_pending; /* number of pending requests.
185 * only maintained for arrays that
186 * support hot removal
187 */
188};
189
190typedef struct mdk_personality_s mdk_personality_t;
191
192struct mddev_s
193{
194 void *private;
195 mdk_personality_t *pers;
196 dev_t unit;
197 int md_minor;
198 struct list_head disks;
199 int sb_dirty;
200 int ro;
201
202 struct gendisk *gendisk;
203
204 /* Superblock information */
205 int major_version,
206 minor_version,
207 patch_version;
208 int persistent;
209 int chunk_size;
210 time_t ctime, utime;
211 int level, layout;
212 int raid_disks;
213 int max_disks;
214 sector_t size; /* used size of component devices */
215 sector_t array_size; /* exported array size */
216 __u64 events;
217
218 char uuid[16];
219
220 struct mdk_thread_s *thread; /* management thread */
221 struct mdk_thread_s *sync_thread; /* doing resync or reconstruct */
222 sector_t curr_resync; /* blocks scheduled */
223 unsigned long resync_mark; /* a recent timestamp */
224 sector_t resync_mark_cnt;/* blocks written at resync_mark */
225
226 sector_t resync_max_sectors; /* may be set by personality */
227 /* recovery/resync flags
228 * NEEDED: we might need to start a resync/recover
229 * RUNNING: a thread is running, or about to be started
230 * SYNC: actually doing a resync, not a recovery
231 * ERR: and IO error was detected - abort the resync/recovery
232 * INTR: someone requested a (clean) early abort.
233 * DONE: thread is done and is waiting to be reaped
234 */
235#define MD_RECOVERY_RUNNING 0
236#define MD_RECOVERY_SYNC 1
237#define MD_RECOVERY_ERR 2
238#define MD_RECOVERY_INTR 3
239#define MD_RECOVERY_DONE 4
240#define MD_RECOVERY_NEEDED 5
241 unsigned long recovery;
242
243 int in_sync; /* know to not need resync */
244 struct semaphore reconfig_sem;
245 atomic_t active;
246
247 int changed; /* true if we might need to reread partition info */
248 int degraded; /* whether md should consider
249 * adding a spare
250 */
251
252 atomic_t recovery_active; /* blocks scheduled, but not written */
253 wait_queue_head_t recovery_wait;
254 sector_t recovery_cp;
255 unsigned int safemode; /* if set, update "clean" superblock
256 * when no writes pending.
257 */
258 unsigned int safemode_delay;
259 struct timer_list safemode_timer;
260 atomic_t writes_pending;
261 request_queue_t *queue; /* for plugging ... */
262
263 struct list_head all_mddevs;
264};
265
266
267static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
268{
269 int faulty = rdev->faulty;
270 if (atomic_dec_and_test(&rdev->nr_pending) && faulty)
271 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
272}
273
274static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
275{
276 atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
277}
278
279struct mdk_personality_s
280{
281 char *name;
282 struct module *owner;
283 int (*make_request)(request_queue_t *q, struct bio *bio);
284 int (*run)(mddev_t *mddev);
285 int (*stop)(mddev_t *mddev);
286 void (*status)(struct seq_file *seq, mddev_t *mddev);
287 /* error_handler must set ->faulty and clear ->in_sync
288 * if appropriate, and should abort recovery if needed
289 */
290 void (*error_handler)(mddev_t *mddev, mdk_rdev_t *rdev);
291 int (*hot_add_disk) (mddev_t *mddev, mdk_rdev_t *rdev);
292 int (*hot_remove_disk) (mddev_t *mddev, int number);
293 int (*spare_active) (mddev_t *mddev);
294 int (*sync_request)(mddev_t *mddev, sector_t sector_nr, int go_faster);
295 int (*resize) (mddev_t *mddev, sector_t sectors);
296 int (*reshape) (mddev_t *mddev, int raid_disks);
297 int (*reconfig) (mddev_t *mddev, int layout, int chunk_size);
298};
299
300
301static inline char * mdname (mddev_t * mddev)
302{
303 return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
304}
305
306extern mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr);
307
308/*
309 * iterates through some rdev ringlist. It's safe to remove the
310 * current 'rdev'. Dont touch 'tmp' though.
311 */
312#define ITERATE_RDEV_GENERIC(head,rdev,tmp) \
313 \
314 for ((tmp) = (head).next; \
315 (rdev) = (list_entry((tmp), mdk_rdev_t, same_set)), \
316 (tmp) = (tmp)->next, (tmp)->prev != &(head) \
317 ; )
318/*
319 * iterates through the 'same array disks' ringlist
320 */
321#define ITERATE_RDEV(mddev,rdev,tmp) \
322 ITERATE_RDEV_GENERIC((mddev)->disks,rdev,tmp)
323
324/*
325 * Iterates through 'pending RAID disks'
326 */
327#define ITERATE_RDEV_PENDING(rdev,tmp) \
328 ITERATE_RDEV_GENERIC(pending_raid_disks,rdev,tmp)
329
330typedef struct mdk_thread_s {
331 void (*run) (mddev_t *mddev);
332 mddev_t *mddev;
333 wait_queue_head_t wqueue;
334 unsigned long flags;
335 struct completion *event;
336 struct task_struct *tsk;
337 const char *name;
338} mdk_thread_t;
339
340#define THREAD_WAKEUP 0
341
342#define __wait_event_lock_irq(wq, condition, lock, cmd) \
343do { \
344 wait_queue_t __wait; \
345 init_waitqueue_entry(&__wait, current); \
346 \
347 add_wait_queue(&wq, &__wait); \
348 for (;;) { \
349 set_current_state(TASK_UNINTERRUPTIBLE); \
350 if (condition) \
351 break; \
352 spin_unlock_irq(&lock); \
353 cmd; \
354 schedule(); \
355 spin_lock_irq(&lock); \
356 } \
357 current->state = TASK_RUNNING; \
358 remove_wait_queue(&wq, &__wait); \
359} while (0)
360
361#define wait_event_lock_irq(wq, condition, lock, cmd) \
362do { \
363 if (condition) \
364 break; \
365 __wait_event_lock_irq(wq, condition, lock, cmd); \
366} while (0)
367
368#endif
369
diff --git a/include/linux/raid/md_p.h b/include/linux/raid/md_p.h
new file mode 100644
index 000000000000..8ba95d67329f
--- /dev/null
+++ b/include/linux/raid/md_p.h
@@ -0,0 +1,230 @@
1/*
2 md_p.h : physical layout of Linux RAID devices
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_P_H
16#define _MD_P_H
17
18/*
19 * RAID superblock.
20 *
21 * The RAID superblock maintains some statistics on each RAID configuration.
22 * Each real device in the RAID set contains it near the end of the device.
23 * Some of the ideas are copied from the ext2fs implementation.
24 *
25 * We currently use 4096 bytes as follows:
26 *
27 * word offset function
28 *
29 * 0 - 31 Constant generic RAID device information.
30 * 32 - 63 Generic state information.
31 * 64 - 127 Personality specific information.
32 * 128 - 511 12 32-words descriptors of the disks in the raid set.
33 * 512 - 911 Reserved.
34 * 912 - 1023 Disk specific descriptor.
35 */
36
37/*
38 * If x is the real device size in bytes, we return an apparent size of:
39 *
40 * y = (x & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES
41 *
42 * and place the 4kB superblock at offset y.
43 */
44#define MD_RESERVED_BYTES (64 * 1024)
45#define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512)
46#define MD_RESERVED_BLOCKS (MD_RESERVED_BYTES / BLOCK_SIZE)
47
48#define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)
49#define MD_NEW_SIZE_BLOCKS(x) ((x & ~(MD_RESERVED_BLOCKS - 1)) - MD_RESERVED_BLOCKS)
50
51#define MD_SB_BYTES 4096
52#define MD_SB_WORDS (MD_SB_BYTES / 4)
53#define MD_SB_BLOCKS (MD_SB_BYTES / BLOCK_SIZE)
54#define MD_SB_SECTORS (MD_SB_BYTES / 512)
55
56/*
57 * The following are counted in 32-bit words
58 */
59#define MD_SB_GENERIC_OFFSET 0
60#define MD_SB_PERSONALITY_OFFSET 64
61#define MD_SB_DISKS_OFFSET 128
62#define MD_SB_DESCRIPTOR_OFFSET 992
63
64#define MD_SB_GENERIC_CONSTANT_WORDS 32
65#define MD_SB_GENERIC_STATE_WORDS 32
66#define MD_SB_GENERIC_WORDS (MD_SB_GENERIC_CONSTANT_WORDS + MD_SB_GENERIC_STATE_WORDS)
67#define MD_SB_PERSONALITY_WORDS 64
68#define MD_SB_DESCRIPTOR_WORDS 32
69#define MD_SB_DISKS 27
70#define MD_SB_DISKS_WORDS (MD_SB_DISKS*MD_SB_DESCRIPTOR_WORDS)
71#define MD_SB_RESERVED_WORDS (1024 - MD_SB_GENERIC_WORDS - MD_SB_PERSONALITY_WORDS - MD_SB_DISKS_WORDS - MD_SB_DESCRIPTOR_WORDS)
72#define MD_SB_EQUAL_WORDS (MD_SB_GENERIC_WORDS + MD_SB_PERSONALITY_WORDS + MD_SB_DISKS_WORDS)
73
74/*
75 * Device "operational" state bits
76 */
77#define MD_DISK_FAULTY 0 /* disk is faulty / operational */
78#define MD_DISK_ACTIVE 1 /* disk is running or spare disk */
79#define MD_DISK_SYNC 2 /* disk is in sync with the raid set */
80#define MD_DISK_REMOVED 3 /* disk is in sync with the raid set */
81
82typedef struct mdp_device_descriptor_s {
83 __u32 number; /* 0 Device number in the entire set */
84 __u32 major; /* 1 Device major number */
85 __u32 minor; /* 2 Device minor number */
86 __u32 raid_disk; /* 3 The role of the device in the raid set */
87 __u32 state; /* 4 Operational state */
88 __u32 reserved[MD_SB_DESCRIPTOR_WORDS - 5];
89} mdp_disk_t;
90
91#define MD_SB_MAGIC 0xa92b4efc
92
93/*
94 * Superblock state bits
95 */
96#define MD_SB_CLEAN 0
97#define MD_SB_ERRORS 1
98
99typedef struct mdp_superblock_s {
100 /*
101 * Constant generic information
102 */
103 __u32 md_magic; /* 0 MD identifier */
104 __u32 major_version; /* 1 major version to which the set conforms */
105 __u32 minor_version; /* 2 minor version ... */
106 __u32 patch_version; /* 3 patchlevel version ... */
107 __u32 gvalid_words; /* 4 Number of used words in this section */
108 __u32 set_uuid0; /* 5 Raid set identifier */
109 __u32 ctime; /* 6 Creation time */
110 __u32 level; /* 7 Raid personality */
111 __u32 size; /* 8 Apparent size of each individual disk */
112 __u32 nr_disks; /* 9 total disks in the raid set */
113 __u32 raid_disks; /* 10 disks in a fully functional raid set */
114 __u32 md_minor; /* 11 preferred MD minor device number */
115 __u32 not_persistent; /* 12 does it have a persistent superblock */
116 __u32 set_uuid1; /* 13 Raid set identifier #2 */
117 __u32 set_uuid2; /* 14 Raid set identifier #3 */
118 __u32 set_uuid3; /* 15 Raid set identifier #4 */
119 __u32 gstate_creserved[MD_SB_GENERIC_CONSTANT_WORDS - 16];
120
121 /*
122 * Generic state information
123 */
124 __u32 utime; /* 0 Superblock update time */
125 __u32 state; /* 1 State bits (clean, ...) */
126 __u32 active_disks; /* 2 Number of currently active disks */
127 __u32 working_disks; /* 3 Number of working disks */
128 __u32 failed_disks; /* 4 Number of failed disks */
129 __u32 spare_disks; /* 5 Number of spare disks */
130 __u32 sb_csum; /* 6 checksum of the whole superblock */
131#ifdef __BIG_ENDIAN
132 __u32 events_hi; /* 7 high-order of superblock update count */
133 __u32 events_lo; /* 8 low-order of superblock update count */
134 __u32 cp_events_hi; /* 9 high-order of checkpoint update count */
135 __u32 cp_events_lo; /* 10 low-order of checkpoint update count */
136#else
137 __u32 events_lo; /* 7 low-order of superblock update count */
138 __u32 events_hi; /* 8 high-order of superblock update count */
139 __u32 cp_events_lo; /* 9 low-order of checkpoint update count */
140 __u32 cp_events_hi; /* 10 high-order of checkpoint update count */
141#endif
142 __u32 recovery_cp; /* 11 recovery checkpoint sector count */
143 __u32 gstate_sreserved[MD_SB_GENERIC_STATE_WORDS - 12];
144
145 /*
146 * Personality information
147 */
148 __u32 layout; /* 0 the array's physical layout */
149 __u32 chunk_size; /* 1 chunk size in bytes */
150 __u32 root_pv; /* 2 LV root PV */
151 __u32 root_block; /* 3 LV root block */
152 __u32 pstate_reserved[MD_SB_PERSONALITY_WORDS - 4];
153
154 /*
155 * Disks information
156 */
157 mdp_disk_t disks[MD_SB_DISKS];
158
159 /*
160 * Reserved
161 */
162 __u32 reserved[MD_SB_RESERVED_WORDS];
163
164 /*
165 * Active descriptor
166 */
167 mdp_disk_t this_disk;
168
169} mdp_super_t;
170
171static inline __u64 md_event(mdp_super_t *sb) {
172 __u64 ev = sb->events_hi;
173 return (ev<<32)| sb->events_lo;
174}
175
176/*
177 * The version-1 superblock :
178 * All numeric fields are little-endian.
179 *
180 * total size: 256 bytes plus 2 per device.
181 * 1K allows 384 devices.
182 */
183struct mdp_superblock_1 {
184 /* constant array information - 128 bytes */
185 __u32 magic; /* MD_SB_MAGIC: 0xa92b4efc - little endian */
186 __u32 major_version; /* 1 */
187 __u32 feature_map; /* 0 for now */
188 __u32 pad0; /* always set to 0 when writing */
189
190 __u8 set_uuid[16]; /* user-space generated. */
191 char set_name[32]; /* set and interpreted by user-space */
192
193 __u64 ctime; /* lo 40 bits are seconds, top 24 are microseconds or 0*/
194 __u32 level; /* -4 (multipath), -1 (linear), 0,1,4,5 */
195 __u32 layout; /* only for raid5 currently */
196 __u64 size; /* used size of component devices, in 512byte sectors */
197
198 __u32 chunksize; /* in 512byte sectors */
199 __u32 raid_disks;
200 __u8 pad1[128-96]; /* set to 0 when written */
201
202 /* constant this-device information - 64 bytes */
203 __u64 data_offset; /* sector start of data, often 0 */
204 __u64 data_size; /* sectors in this device that can be used for data */
205 __u64 super_offset; /* sector start of this superblock */
206 __u64 recovery_offset;/* sectors before this offset (from data_offset) have been recovered */
207 __u32 dev_number; /* permanent identifier of this device - not role in raid */
208 __u32 cnt_corrected_read; /* number of read errors that were corrected by re-writing */
209 __u8 device_uuid[16]; /* user-space setable, ignored by kernel */
210 __u8 pad2[64-56]; /* set to 0 when writing */
211
212 /* array state information - 64 bytes */
213 __u64 utime; /* 40 bits second, 24 btes microseconds */
214 __u64 events; /* incremented when superblock updated */
215 __u64 resync_offset; /* data before this offset (from data_offset) known to be in sync */
216 __u32 sb_csum; /* checksum upto devs[max_dev] */
217 __u32 max_dev; /* size of devs[] array to consider */
218 __u8 pad3[64-32]; /* set to 0 when writing */
219
220 /* device state information. Indexed by dev_number.
221 * 2 bytes per device
222 * Note there are no per-device state flags. State information is rolled
223 * into the 'roles' value. If a device is spare or faulty, then it doesn't
224 * have a meaningful role.
225 */
226 __u16 dev_roles[0]; /* role in array, or 0xffff for a spare, or 0xfffe for faulty */
227};
228
229#endif
230
diff --git a/include/linux/raid/md_u.h b/include/linux/raid/md_u.h
new file mode 100644
index 000000000000..a2df5c2a42af
--- /dev/null
+++ b/include/linux/raid/md_u.h
@@ -0,0 +1,117 @@
1/*
2 md_u.h : user <=> kernel API between Linux raidtools and RAID drivers
3 Copyright (C) 1998 Ingo Molnar
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_U_H
16#define _MD_U_H
17
18/* ioctls */
19
20/* status */
21#define RAID_VERSION _IOR (MD_MAJOR, 0x10, mdu_version_t)
22#define GET_ARRAY_INFO _IOR (MD_MAJOR, 0x11, mdu_array_info_t)
23#define GET_DISK_INFO _IOR (MD_MAJOR, 0x12, mdu_disk_info_t)
24#define PRINT_RAID_DEBUG _IO (MD_MAJOR, 0x13)
25#define RAID_AUTORUN _IO (MD_MAJOR, 0x14)
26
27/* configuration */
28#define CLEAR_ARRAY _IO (MD_MAJOR, 0x20)
29#define ADD_NEW_DISK _IOW (MD_MAJOR, 0x21, mdu_disk_info_t)
30#define HOT_REMOVE_DISK _IO (MD_MAJOR, 0x22)
31#define SET_ARRAY_INFO _IOW (MD_MAJOR, 0x23, mdu_array_info_t)
32#define SET_DISK_INFO _IO (MD_MAJOR, 0x24)
33#define WRITE_RAID_INFO _IO (MD_MAJOR, 0x25)
34#define UNPROTECT_ARRAY _IO (MD_MAJOR, 0x26)
35#define PROTECT_ARRAY _IO (MD_MAJOR, 0x27)
36#define HOT_ADD_DISK _IO (MD_MAJOR, 0x28)
37#define SET_DISK_FAULTY _IO (MD_MAJOR, 0x29)
38#define HOT_GENERATE_ERROR _IO (MD_MAJOR, 0x2a)
39
40/* usage */
41#define RUN_ARRAY _IOW (MD_MAJOR, 0x30, mdu_param_t)
42#define START_ARRAY _IO (MD_MAJOR, 0x31)
43#define STOP_ARRAY _IO (MD_MAJOR, 0x32)
44#define STOP_ARRAY_RO _IO (MD_MAJOR, 0x33)
45#define RESTART_ARRAY_RW _IO (MD_MAJOR, 0x34)
46
47typedef struct mdu_version_s {
48 int major;
49 int minor;
50 int patchlevel;
51} mdu_version_t;
52
53typedef struct mdu_array_info_s {
54 /*
55 * Generic constant information
56 */
57 int major_version;
58 int minor_version;
59 int patch_version;
60 int ctime;
61 int level;
62 int size;
63 int nr_disks;
64 int raid_disks;
65 int md_minor;
66 int not_persistent;
67
68 /*
69 * Generic state information
70 */
71 int utime; /* 0 Superblock update time */
72 int state; /* 1 State bits (clean, ...) */
73 int active_disks; /* 2 Number of currently active disks */
74 int working_disks; /* 3 Number of working disks */
75 int failed_disks; /* 4 Number of failed disks */
76 int spare_disks; /* 5 Number of spare disks */
77
78 /*
79 * Personality information
80 */
81 int layout; /* 0 the array's physical layout */
82 int chunk_size; /* 1 chunk size in bytes */
83
84} mdu_array_info_t;
85
86typedef struct mdu_disk_info_s {
87 /*
88 * configuration/status of one particular disk
89 */
90 int number;
91 int major;
92 int minor;
93 int raid_disk;
94 int state;
95
96} mdu_disk_info_t;
97
98typedef struct mdu_start_info_s {
99 /*
100 * configuration/status of one particular disk
101 */
102 int major;
103 int minor;
104 int raid_disk;
105 int state;
106
107} mdu_start_info_t;
108
109typedef struct mdu_param_s
110{
111 int personality; /* 1,2,3,4 */
112 int chunk_size; /* in bytes */
113 int max_fault; /* unused for now */
114} mdu_param_t;
115
116#endif
117
diff --git a/include/linux/raid/multipath.h b/include/linux/raid/multipath.h
new file mode 100644
index 000000000000..6f53fc177a47
--- /dev/null
+++ b/include/linux/raid/multipath.h
@@ -0,0 +1,42 @@
1#ifndef _MULTIPATH_H
2#define _MULTIPATH_H
3
4#include <linux/raid/md.h>
5
6struct multipath_info {
7 mdk_rdev_t *rdev;
8};
9
10struct multipath_private_data {
11 mddev_t *mddev;
12 struct multipath_info *multipaths;
13 int raid_disks;
14 int working_disks;
15 spinlock_t device_lock;
16 struct list_head retry_list;
17
18 mempool_t *pool;
19};
20
21typedef struct multipath_private_data multipath_conf_t;
22
23/*
24 * this is the only point in the RAID code where we violate
25 * C type safety. mddev->private is an 'opaque' pointer.
26 */
27#define mddev_to_conf(mddev) ((multipath_conf_t *) mddev->private)
28
29/*
30 * this is our 'private' 'collective' MULTIPATH buffer head.
31 * it contains information about what kind of IO operations were started
32 * for this MULTIPATH operation, and about their status:
33 */
34
35struct multipath_bh {
36 mddev_t *mddev;
37 struct bio *master_bio;
38 struct bio bio;
39 int path;
40 struct list_head retry_list;
41};
42#endif
diff --git a/include/linux/raid/raid0.h b/include/linux/raid/raid0.h
new file mode 100644
index 000000000000..1b2dda035f8e
--- /dev/null
+++ b/include/linux/raid/raid0.h
@@ -0,0 +1,30 @@
1#ifndef _RAID0_H
2#define _RAID0_H
3
4#include <linux/raid/md.h>
5
6struct strip_zone
7{
8 sector_t zone_offset; /* Zone offset in md_dev */
9 sector_t dev_offset; /* Zone offset in real dev */
10 sector_t size; /* Zone size */
11 int nb_dev; /* # of devices attached to the zone */
12 mdk_rdev_t **dev; /* Devices attached to the zone */
13};
14
15struct raid0_private_data
16{
17 struct strip_zone **hash_table; /* Table of indexes into strip_zone */
18 struct strip_zone *strip_zone;
19 mdk_rdev_t **devlist; /* lists of rdevs, pointed to by strip_zone->dev */
20 int nr_strip_zones;
21
22 sector_t hash_spacing;
23 int preshift; /* shift this before divide by hash_spacing */
24};
25
26typedef struct raid0_private_data raid0_conf_t;
27
28#define mddev_to_conf(mddev) ((raid0_conf_t *) mddev->private)
29
30#endif
diff --git a/include/linux/raid/raid1.h b/include/linux/raid/raid1.h
new file mode 100644
index 000000000000..abbfdd9afe1e
--- /dev/null
+++ b/include/linux/raid/raid1.h
@@ -0,0 +1,98 @@
1#ifndef _RAID1_H
2#define _RAID1_H
3
4#include <linux/raid/md.h>
5
6typedef struct mirror_info mirror_info_t;
7
8struct mirror_info {
9 mdk_rdev_t *rdev;
10 sector_t head_position;
11};
12
13/*
14 * memory pools need a pointer to the mddev, so they can force an unplug
15 * when memory is tight, and a count of the number of drives that the
16 * pool was allocated for, so they know how much to allocate and free.
17 * mddev->raid_disks cannot be used, as it can change while a pool is active
18 * These two datums are stored in a kmalloced struct.
19 */
20
21struct pool_info {
22 mddev_t *mddev;
23 int raid_disks;
24};
25
26
27typedef struct r1bio_s r1bio_t;
28
29struct r1_private_data_s {
30 mddev_t *mddev;
31 mirror_info_t *mirrors;
32 int raid_disks;
33 int working_disks;
34 int last_used;
35 sector_t next_seq_sect;
36 spinlock_t device_lock;
37
38 struct list_head retry_list;
39 /* for use when syncing mirrors: */
40
41 spinlock_t resync_lock;
42 int nr_pending;
43 int barrier;
44 sector_t next_resync;
45
46 wait_queue_head_t wait_idle;
47 wait_queue_head_t wait_resume;
48
49 struct pool_info *poolinfo;
50
51 mempool_t *r1bio_pool;
52 mempool_t *r1buf_pool;
53};
54
55typedef struct r1_private_data_s conf_t;
56
57/*
58 * this is the only point in the RAID code where we violate
59 * C type safety. mddev->private is an 'opaque' pointer.
60 */
61#define mddev_to_conf(mddev) ((conf_t *) mddev->private)
62
63/*
64 * this is our 'private' RAID1 bio.
65 *
66 * it contains information about what kind of IO operations were started
67 * for this RAID1 operation, and about their status:
68 */
69
70struct r1bio_s {
71 atomic_t remaining; /* 'have we finished' count,
72 * used from IRQ handlers
73 */
74 sector_t sector;
75 int sectors;
76 unsigned long state;
77 mddev_t *mddev;
78 /*
79 * original bio going to /dev/mdx
80 */
81 struct bio *master_bio;
82 /*
83 * if the IO is in READ direction, then this is where we read
84 */
85 int read_disk;
86
87 struct list_head retry_list;
88 /*
89 * if the IO is in WRITE direction, then multiple bios are used.
90 * We choose the number when they are allocated.
91 */
92 struct bio *bios[0];
93};
94
95/* bits for r1bio.state */
96#define R1BIO_Uptodate 0
97#define R1BIO_IsSync 1
98#endif
diff --git a/include/linux/raid/raid10.h b/include/linux/raid/raid10.h
new file mode 100644
index 000000000000..60708789c8f9
--- /dev/null
+++ b/include/linux/raid/raid10.h
@@ -0,0 +1,103 @@
1#ifndef _RAID10_H
2#define _RAID10_H
3
4#include <linux/raid/md.h>
5
6typedef struct mirror_info mirror_info_t;
7
8struct mirror_info {
9 mdk_rdev_t *rdev;
10 sector_t head_position;
11};
12
13typedef struct r10bio_s r10bio_t;
14
15struct r10_private_data_s {
16 mddev_t *mddev;
17 mirror_info_t *mirrors;
18 int raid_disks;
19 int working_disks;
20 spinlock_t device_lock;
21
22 /* geometry */
23 int near_copies; /* number of copies layed out raid0 style */
24 int far_copies; /* number of copies layed out
25 * at large strides across drives
26 */
27 int copies; /* near_copies * far_copies.
28 * must be <= raid_disks
29 */
30 sector_t stride; /* distance between far copies.
31 * This is size / far_copies
32 */
33
34 int chunk_shift; /* shift from chunks to sectors */
35 sector_t chunk_mask;
36
37 struct list_head retry_list;
38 /* for use when syncing mirrors: */
39
40 spinlock_t resync_lock;
41 int nr_pending;
42 int barrier;
43 sector_t next_resync;
44
45 wait_queue_head_t wait_idle;
46 wait_queue_head_t wait_resume;
47
48 mempool_t *r10bio_pool;
49 mempool_t *r10buf_pool;
50};
51
52typedef struct r10_private_data_s conf_t;
53
54/*
55 * this is the only point in the RAID code where we violate
56 * C type safety. mddev->private is an 'opaque' pointer.
57 */
58#define mddev_to_conf(mddev) ((conf_t *) mddev->private)
59
60/*
61 * this is our 'private' RAID10 bio.
62 *
63 * it contains information about what kind of IO operations were started
64 * for this RAID10 operation, and about their status:
65 */
66
67struct r10bio_s {
68 atomic_t remaining; /* 'have we finished' count,
69 * used from IRQ handlers
70 */
71 sector_t sector; /* virtual sector number */
72 int sectors;
73 unsigned long state;
74 mddev_t *mddev;
75 /*
76 * original bio going to /dev/mdx
77 */
78 struct bio *master_bio;
79 /*
80 * if the IO is in READ direction, then this is where we read
81 */
82 int read_slot;
83
84 struct list_head retry_list;
85 /*
86 * if the IO is in WRITE direction, then multiple bios are used,
87 * one for each copy.
88 * When resyncing we also use one for each copy.
89 * When reconstructing, we use 2 bios, one for read, one for write.
90 * We choose the number when they are allocated.
91 */
92 struct {
93 struct bio *bio;
94 sector_t addr;
95 int devnum;
96 } devs[0];
97};
98
99/* bits for r10bio.state */
100#define R10BIO_Uptodate 0
101#define R10BIO_IsSync 1
102#define R10BIO_IsRecover 2
103#endif
diff --git a/include/linux/raid/raid5.h b/include/linux/raid/raid5.h
new file mode 100644
index 000000000000..d63ddcb4afad
--- /dev/null
+++ b/include/linux/raid/raid5.h
@@ -0,0 +1,243 @@
1#ifndef _RAID5_H
2#define _RAID5_H
3
4#include <linux/raid/md.h>
5#include <linux/raid/xor.h>
6
7/*
8 *
9 * Each stripe contains one buffer per disc. Each buffer can be in
10 * one of a number of states stored in "flags". Changes between
11 * these states happen *almost* exclusively under a per-stripe
12 * spinlock. Some very specific changes can happen in bi_end_io, and
13 * these are not protected by the spin lock.
14 *
15 * The flag bits that are used to represent these states are:
16 * R5_UPTODATE and R5_LOCKED
17 *
18 * State Empty == !UPTODATE, !LOCK
19 * We have no data, and there is no active request
20 * State Want == !UPTODATE, LOCK
21 * A read request is being submitted for this block
22 * State Dirty == UPTODATE, LOCK
23 * Some new data is in this buffer, and it is being written out
24 * State Clean == UPTODATE, !LOCK
25 * We have valid data which is the same as on disc
26 *
27 * The possible state transitions are:
28 *
29 * Empty -> Want - on read or write to get old data for parity calc
30 * Empty -> Dirty - on compute_parity to satisfy write/sync request.(RECONSTRUCT_WRITE)
31 * Empty -> Clean - on compute_block when computing a block for failed drive
32 * Want -> Empty - on failed read
33 * Want -> Clean - on successful completion of read request
34 * Dirty -> Clean - on successful completion of write request
35 * Dirty -> Clean - on failed write
36 * Clean -> Dirty - on compute_parity to satisfy write/sync (RECONSTRUCT or RMW)
37 *
38 * The Want->Empty, Want->Clean, Dirty->Clean, transitions
39 * all happen in b_end_io at interrupt time.
40 * Each sets the Uptodate bit before releasing the Lock bit.
41 * This leaves one multi-stage transition:
42 * Want->Dirty->Clean
43 * This is safe because thinking that a Clean buffer is actually dirty
44 * will at worst delay some action, and the stripe will be scheduled
45 * for attention after the transition is complete.
46 *
47 * There is one possibility that is not covered by these states. That
48 * is if one drive has failed and there is a spare being rebuilt. We
49 * can't distinguish between a clean block that has been generated
50 * from parity calculations, and a clean block that has been
51 * successfully written to the spare ( or to parity when resyncing).
52 * To distingush these states we have a stripe bit STRIPE_INSYNC that
53 * is set whenever a write is scheduled to the spare, or to the parity
54 * disc if there is no spare. A sync request clears this bit, and
55 * when we find it set with no buffers locked, we know the sync is
56 * complete.
57 *
58 * Buffers for the md device that arrive via make_request are attached
59 * to the appropriate stripe in one of two lists linked on b_reqnext.
60 * One list (bh_read) for read requests, one (bh_write) for write.
61 * There should never be more than one buffer on the two lists
62 * together, but we are not guaranteed of that so we allow for more.
63 *
64 * If a buffer is on the read list when the associated cache buffer is
65 * Uptodate, the data is copied into the read buffer and it's b_end_io
66 * routine is called. This may happen in the end_request routine only
67 * if the buffer has just successfully been read. end_request should
68 * remove the buffers from the list and then set the Uptodate bit on
69 * the buffer. Other threads may do this only if they first check
70 * that the Uptodate bit is set. Once they have checked that they may
71 * take buffers off the read queue.
72 *
73 * When a buffer on the write list is committed for write it is copied
74 * into the cache buffer, which is then marked dirty, and moved onto a
75 * third list, the written list (bh_written). Once both the parity
76 * block and the cached buffer are successfully written, any buffer on
77 * a written list can be returned with b_end_io.
78 *
79 * The write list and read list both act as fifos. The read list is
80 * protected by the device_lock. The write and written lists are
81 * protected by the stripe lock. The device_lock, which can be
82 * claimed while the stipe lock is held, is only for list
83 * manipulations and will only be held for a very short time. It can
84 * be claimed from interrupts.
85 *
86 *
87 * Stripes in the stripe cache can be on one of two lists (or on
88 * neither). The "inactive_list" contains stripes which are not
89 * currently being used for any request. They can freely be reused
90 * for another stripe. The "handle_list" contains stripes that need
91 * to be handled in some way. Both of these are fifo queues. Each
92 * stripe is also (potentially) linked to a hash bucket in the hash
93 * table so that it can be found by sector number. Stripes that are
94 * not hashed must be on the inactive_list, and will normally be at
95 * the front. All stripes start life this way.
96 *
97 * The inactive_list, handle_list and hash bucket lists are all protected by the
98 * device_lock.
99 * - stripes on the inactive_list never have their stripe_lock held.
100 * - stripes have a reference counter. If count==0, they are on a list.
101 * - If a stripe might need handling, STRIPE_HANDLE is set.
102 * - When refcount reaches zero, then if STRIPE_HANDLE it is put on
103 * handle_list else inactive_list
104 *
105 * This, combined with the fact that STRIPE_HANDLE is only ever
106 * cleared while a stripe has a non-zero count means that if the
107 * refcount is 0 and STRIPE_HANDLE is set, then it is on the
108 * handle_list and if recount is 0 and STRIPE_HANDLE is not set, then
109 * the stripe is on inactive_list.
110 *
111 * The possible transitions are:
112 * activate an unhashed/inactive stripe (get_active_stripe())
113 * lockdev check-hash unlink-stripe cnt++ clean-stripe hash-stripe unlockdev
114 * activate a hashed, possibly active stripe (get_active_stripe())
115 * lockdev check-hash if(!cnt++)unlink-stripe unlockdev
116 * attach a request to an active stripe (add_stripe_bh())
117 * lockdev attach-buffer unlockdev
118 * handle a stripe (handle_stripe())
119 * lockstripe clrSTRIPE_HANDLE ... (lockdev check-buffers unlockdev) .. change-state .. record io needed unlockstripe schedule io
120 * release an active stripe (release_stripe())
121 * lockdev if (!--cnt) { if STRIPE_HANDLE, add to handle_list else add to inactive-list } unlockdev
122 *
123 * The refcount counts each thread that have activated the stripe,
124 * plus raid5d if it is handling it, plus one for each active request
125 * on a cached buffer.
126 */
127
128struct stripe_head {
129 struct stripe_head *hash_next, **hash_pprev; /* hash pointers */
130 struct list_head lru; /* inactive_list or handle_list */
131 struct raid5_private_data *raid_conf;
132 sector_t sector; /* sector of this row */
133 int pd_idx; /* parity disk index */
134 unsigned long state; /* state flags */
135 atomic_t count; /* nr of active thread/requests */
136 spinlock_t lock;
137 struct r5dev {
138 struct bio req;
139 struct bio_vec vec;
140 struct page *page;
141 struct bio *toread, *towrite, *written;
142 sector_t sector; /* sector of this page */
143 unsigned long flags;
144 } dev[1]; /* allocated with extra space depending of RAID geometry */
145};
146/* Flags */
147#define R5_UPTODATE 0 /* page contains current data */
148#define R5_LOCKED 1 /* IO has been submitted on "req" */
149#define R5_OVERWRITE 2 /* towrite covers whole page */
150/* and some that are internal to handle_stripe */
151#define R5_Insync 3 /* rdev && rdev->in_sync at start */
152#define R5_Wantread 4 /* want to schedule a read */
153#define R5_Wantwrite 5
154#define R5_Syncio 6 /* this io need to be accounted as resync io */
155#define R5_Overlap 7 /* There is a pending overlapping request on this block */
156
157/*
158 * Write method
159 */
160#define RECONSTRUCT_WRITE 1
161#define READ_MODIFY_WRITE 2
162/* not a write method, but a compute_parity mode */
163#define CHECK_PARITY 3
164
165/*
166 * Stripe state
167 */
168#define STRIPE_ERROR 1
169#define STRIPE_HANDLE 2
170#define STRIPE_SYNCING 3
171#define STRIPE_INSYNC 4
172#define STRIPE_PREREAD_ACTIVE 5
173#define STRIPE_DELAYED 6
174
175/*
176 * Plugging:
177 *
178 * To improve write throughput, we need to delay the handling of some
179 * stripes until there has been a chance that several write requests
180 * for the one stripe have all been collected.
181 * In particular, any write request that would require pre-reading
182 * is put on a "delayed" queue until there are no stripes currently
183 * in a pre-read phase. Further, if the "delayed" queue is empty when
184 * a stripe is put on it then we "plug" the queue and do not process it
185 * until an unplug call is made. (the unplug_io_fn() is called).
186 *
187 * When preread is initiated on a stripe, we set PREREAD_ACTIVE and add
188 * it to the count of prereading stripes.
189 * When write is initiated, or the stripe refcnt == 0 (just in case) we
190 * clear the PREREAD_ACTIVE flag and decrement the count
191 * Whenever the delayed queue is empty and the device is not plugged, we
192 * move any strips from delayed to handle and clear the DELAYED flag and set PREREAD_ACTIVE.
193 * In stripe_handle, if we find pre-reading is necessary, we do it if
194 * PREREAD_ACTIVE is set, else we set DELAYED which will send it to the delayed queue.
195 * HANDLE gets cleared if stripe_handle leave nothing locked.
196 */
197
198
199struct disk_info {
200 mdk_rdev_t *rdev;
201};
202
203struct raid5_private_data {
204 struct stripe_head **stripe_hashtbl;
205 mddev_t *mddev;
206 struct disk_info *spare;
207 int chunk_size, level, algorithm;
208 int raid_disks, working_disks, failed_disks;
209 int max_nr_stripes;
210
211 struct list_head handle_list; /* stripes needing handling */
212 struct list_head delayed_list; /* stripes that have plugged requests */
213 atomic_t preread_active_stripes; /* stripes with scheduled io */
214
215 char cache_name[20];
216 kmem_cache_t *slab_cache; /* for allocating stripes */
217 /*
218 * Free stripes pool
219 */
220 atomic_t active_stripes;
221 struct list_head inactive_list;
222 wait_queue_head_t wait_for_stripe;
223 wait_queue_head_t wait_for_overlap;
224 int inactive_blocked; /* release of inactive stripes blocked,
225 * waiting for 25% to be free
226 */
227 spinlock_t device_lock;
228 struct disk_info disks[0];
229};
230
231typedef struct raid5_private_data raid5_conf_t;
232
233#define mddev_to_conf(mddev) ((raid5_conf_t *) mddev->private)
234
235/*
236 * Our supported algorithms
237 */
238#define ALGORITHM_LEFT_ASYMMETRIC 0
239#define ALGORITHM_RIGHT_ASYMMETRIC 1
240#define ALGORITHM_LEFT_SYMMETRIC 2
241#define ALGORITHM_RIGHT_SYMMETRIC 3
242
243#endif
diff --git a/include/linux/raid/xor.h b/include/linux/raid/xor.h
new file mode 100644
index 000000000000..f0d67cbdea40
--- /dev/null
+++ b/include/linux/raid/xor.h
@@ -0,0 +1,23 @@
1#ifndef _XOR_H
2#define _XOR_H
3
4#include <linux/raid/md.h>
5
6#define MAX_XOR_BLOCKS 5
7
8extern void xor_block(unsigned int count, unsigned int bytes, void **ptr);
9
10struct xor_block_template {
11 struct xor_block_template *next;
12 const char *name;
13 int speed;
14 void (*do_2)(unsigned long, unsigned long *, unsigned long *);
15 void (*do_3)(unsigned long, unsigned long *, unsigned long *,
16 unsigned long *);
17 void (*do_4)(unsigned long, unsigned long *, unsigned long *,
18 unsigned long *, unsigned long *);
19 void (*do_5)(unsigned long, unsigned long *, unsigned long *,
20 unsigned long *, unsigned long *, unsigned long *);
21};
22
23#endif