diff options
author | Christoph Hellwig <hch@lst.de> | 2009-03-30 23:27:03 -0400 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2009-03-30 23:27:03 -0400 |
commit | ef740c372dfd80e706dbf955d4e4aedda6c0c148 (patch) | |
tree | 8d9ef9db346ee1ba319a125c9de83cdde049510d /drivers | |
parent | 2a40a8aed083d988df6822bb9b1b08fb7ce21e1d (diff) |
md: move headers out of include/linux/raid/
Move the headers with the local structures for the disciplines and
bitmap.h into drivers/md/ so that they are more easily grepable for
hacking and not far away. md.h is left where it is for now as there
are some uses from the outside.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/md/bitmap.c | 2 | ||||
-rw-r--r-- | drivers/md/bitmap.h | 288 | ||||
-rw-r--r-- | drivers/md/linear.c | 2 | ||||
-rw-r--r-- | drivers/md/linear.h | 31 | ||||
-rw-r--r-- | drivers/md/md.c | 2 | ||||
-rw-r--r-- | drivers/md/multipath.c | 2 | ||||
-rw-r--r-- | drivers/md/multipath.h | 42 | ||||
-rw-r--r-- | drivers/md/raid0.c | 2 | ||||
-rw-r--r-- | drivers/md/raid0.h | 30 | ||||
-rw-r--r-- | drivers/md/raid1.c | 4 | ||||
-rw-r--r-- | drivers/md/raid1.h | 134 | ||||
-rw-r--r-- | drivers/md/raid10.c | 4 | ||||
-rw-r--r-- | drivers/md/raid10.h | 123 | ||||
-rw-r--r-- | drivers/md/raid5.c | 5 | ||||
-rw-r--r-- | drivers/md/raid5.h | 402 | ||||
-rw-r--r-- | drivers/md/raid6.h | 2 |
16 files changed, 1062 insertions, 13 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c index 27f978dfe6a3..7666117738c7 100644 --- a/drivers/md/bitmap.c +++ b/drivers/md/bitmap.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include <linux/mount.h> | 27 | #include <linux/mount.h> |
28 | #include <linux/buffer_head.h> | 28 | #include <linux/buffer_head.h> |
29 | #include <linux/raid/md.h> | 29 | #include <linux/raid/md.h> |
30 | #include <linux/raid/bitmap.h> | 30 | #include "bitmap.h" |
31 | 31 | ||
32 | /* debug macros */ | 32 | /* debug macros */ |
33 | 33 | ||
diff --git a/drivers/md/bitmap.h b/drivers/md/bitmap.h new file mode 100644 index 000000000000..e98900671ca9 --- /dev/null +++ b/drivers/md/bitmap.h | |||
@@ -0,0 +1,288 @@ | |||
1 | /* | ||
2 | * bitmap.h: Copyright (C) Peter T. Breuer (ptb@ot.uc3m.es) 2003 | ||
3 | * | ||
4 | * additions: Copyright (C) 2003-2004, Paul Clements, SteelEye Technology, Inc. | ||
5 | */ | ||
6 | #ifndef BITMAP_H | ||
7 | #define BITMAP_H 1 | ||
8 | |||
9 | #define BITMAP_MAJOR_LO 3 | ||
10 | /* version 4 insists the bitmap is in little-endian order | ||
11 | * with version 3, it is host-endian which is non-portable | ||
12 | */ | ||
13 | #define BITMAP_MAJOR_HI 4 | ||
14 | #define BITMAP_MAJOR_HOSTENDIAN 3 | ||
15 | |||
16 | #define BITMAP_MINOR 39 | ||
17 | |||
18 | /* | ||
19 | * in-memory bitmap: | ||
20 | * | ||
21 | * Use 16 bit block counters to track pending writes to each "chunk". | ||
22 | * The 2 high order bits are special-purpose, the first is a flag indicating | ||
23 | * whether a resync is needed. The second is a flag indicating whether a | ||
24 | * resync is active. | ||
25 | * This means that the counter is actually 14 bits: | ||
26 | * | ||
27 | * +--------+--------+------------------------------------------------+ | ||
28 | * | resync | resync | counter | | ||
29 | * | needed | active | | | ||
30 | * | (0-1) | (0-1) | (0-16383) | | ||
31 | * +--------+--------+------------------------------------------------+ | ||
32 | * | ||
33 | * The "resync needed" bit is set when: | ||
34 | * a '1' bit is read from storage at startup. | ||
35 | * a write request fails on some drives | ||
36 | * a resync is aborted on a chunk with 'resync active' set | ||
37 | * It is cleared (and resync-active set) when a resync starts across all drives | ||
38 | * of the chunk. | ||
39 | * | ||
40 | * | ||
41 | * The "resync active" bit is set when: | ||
42 | * a resync is started on all drives, and resync_needed is set. | ||
43 | * resync_needed will be cleared (as long as resync_active wasn't already set). | ||
44 | * It is cleared when a resync completes. | ||
45 | * | ||
46 | * The counter counts pending write requests, plus the on-disk bit. | ||
47 | * When the counter is '1' and the resync bits are clear, the on-disk | ||
48 | * bit can be cleared aswell, thus setting the counter to 0. | ||
49 | * When we set a bit, or in the counter (to start a write), if the fields is | ||
50 | * 0, we first set the disk bit and set the counter to 1. | ||
51 | * | ||
52 | * If the counter is 0, the on-disk bit is clear and the stipe is clean | ||
53 | * Anything that dirties the stipe pushes the counter to 2 (at least) | ||
54 | * and sets the on-disk bit (lazily). | ||
55 | * If a periodic sweep find the counter at 2, it is decremented to 1. | ||
56 | * If the sweep find the counter at 1, the on-disk bit is cleared and the | ||
57 | * counter goes to zero. | ||
58 | * | ||
59 | * Also, we'll hijack the "map" pointer itself and use it as two 16 bit block | ||
60 | * counters as a fallback when "page" memory cannot be allocated: | ||
61 | * | ||
62 | * Normal case (page memory allocated): | ||
63 | * | ||
64 | * page pointer (32-bit) | ||
65 | * | ||
66 | * [ ] ------+ | ||
67 | * | | ||
68 | * +-------> [ ][ ]..[ ] (4096 byte page == 2048 counters) | ||
69 | * c1 c2 c2048 | ||
70 | * | ||
71 | * Hijacked case (page memory allocation failed): | ||
72 | * | ||
73 | * hijacked page pointer (32-bit) | ||
74 | * | ||
75 | * [ ][ ] (no page memory allocated) | ||
76 | * counter #1 (16-bit) counter #2 (16-bit) | ||
77 | * | ||
78 | */ | ||
79 | |||
80 | #ifdef __KERNEL__ | ||
81 | |||
82 | #define PAGE_BITS (PAGE_SIZE << 3) | ||
83 | #define PAGE_BIT_SHIFT (PAGE_SHIFT + 3) | ||
84 | |||
85 | typedef __u16 bitmap_counter_t; | ||
86 | #define COUNTER_BITS 16 | ||
87 | #define COUNTER_BIT_SHIFT 4 | ||
88 | #define COUNTER_BYTE_RATIO (COUNTER_BITS / 8) | ||
89 | #define COUNTER_BYTE_SHIFT (COUNTER_BIT_SHIFT - 3) | ||
90 | |||
91 | #define NEEDED_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 1))) | ||
92 | #define RESYNC_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 2))) | ||
93 | #define COUNTER_MAX ((bitmap_counter_t) RESYNC_MASK - 1) | ||
94 | #define NEEDED(x) (((bitmap_counter_t) x) & NEEDED_MASK) | ||
95 | #define RESYNC(x) (((bitmap_counter_t) x) & RESYNC_MASK) | ||
96 | #define COUNTER(x) (((bitmap_counter_t) x) & COUNTER_MAX) | ||
97 | |||
98 | /* how many counters per page? */ | ||
99 | #define PAGE_COUNTER_RATIO (PAGE_BITS / COUNTER_BITS) | ||
100 | /* same, except a shift value for more efficient bitops */ | ||
101 | #define PAGE_COUNTER_SHIFT (PAGE_BIT_SHIFT - COUNTER_BIT_SHIFT) | ||
102 | /* same, except a mask value for more efficient bitops */ | ||
103 | #define PAGE_COUNTER_MASK (PAGE_COUNTER_RATIO - 1) | ||
104 | |||
105 | #define BITMAP_BLOCK_SIZE 512 | ||
106 | #define BITMAP_BLOCK_SHIFT 9 | ||
107 | |||
108 | /* how many blocks per chunk? (this is variable) */ | ||
109 | #define CHUNK_BLOCK_RATIO(bitmap) ((bitmap)->chunksize >> BITMAP_BLOCK_SHIFT) | ||
110 | #define CHUNK_BLOCK_SHIFT(bitmap) ((bitmap)->chunkshift - BITMAP_BLOCK_SHIFT) | ||
111 | #define CHUNK_BLOCK_MASK(bitmap) (CHUNK_BLOCK_RATIO(bitmap) - 1) | ||
112 | |||
113 | /* when hijacked, the counters and bits represent even larger "chunks" */ | ||
114 | /* there will be 1024 chunks represented by each counter in the page pointers */ | ||
115 | #define PAGEPTR_BLOCK_RATIO(bitmap) \ | ||
116 | (CHUNK_BLOCK_RATIO(bitmap) << PAGE_COUNTER_SHIFT >> 1) | ||
117 | #define PAGEPTR_BLOCK_SHIFT(bitmap) \ | ||
118 | (CHUNK_BLOCK_SHIFT(bitmap) + PAGE_COUNTER_SHIFT - 1) | ||
119 | #define PAGEPTR_BLOCK_MASK(bitmap) (PAGEPTR_BLOCK_RATIO(bitmap) - 1) | ||
120 | |||
121 | /* | ||
122 | * on-disk bitmap: | ||
123 | * | ||
124 | * Use one bit per "chunk" (block set). We do the disk I/O on the bitmap | ||
125 | * file a page at a time. There's a superblock at the start of the file. | ||
126 | */ | ||
127 | |||
128 | /* map chunks (bits) to file pages - offset by the size of the superblock */ | ||
129 | #define CHUNK_BIT_OFFSET(chunk) ((chunk) + (sizeof(bitmap_super_t) << 3)) | ||
130 | |||
131 | #endif | ||
132 | |||
133 | /* | ||
134 | * bitmap structures: | ||
135 | */ | ||
136 | |||
137 | #define BITMAP_MAGIC 0x6d746962 | ||
138 | |||
139 | /* use these for bitmap->flags and bitmap->sb->state bit-fields */ | ||
140 | enum bitmap_state { | ||
141 | BITMAP_STALE = 0x002, /* the bitmap file is out of date or had -EIO */ | ||
142 | BITMAP_WRITE_ERROR = 0x004, /* A write error has occurred */ | ||
143 | BITMAP_HOSTENDIAN = 0x8000, | ||
144 | }; | ||
145 | |||
146 | /* the superblock at the front of the bitmap file -- little endian */ | ||
147 | typedef struct bitmap_super_s { | ||
148 | __le32 magic; /* 0 BITMAP_MAGIC */ | ||
149 | __le32 version; /* 4 the bitmap major for now, could change... */ | ||
150 | __u8 uuid[16]; /* 8 128 bit uuid - must match md device uuid */ | ||
151 | __le64 events; /* 24 event counter for the bitmap (1)*/ | ||
152 | __le64 events_cleared;/*32 event counter when last bit cleared (2) */ | ||
153 | __le64 sync_size; /* 40 the size of the md device's sync range(3) */ | ||
154 | __le32 state; /* 48 bitmap state information */ | ||
155 | __le32 chunksize; /* 52 the bitmap chunk size in bytes */ | ||
156 | __le32 daemon_sleep; /* 56 seconds between disk flushes */ | ||
157 | __le32 write_behind; /* 60 number of outstanding write-behind writes */ | ||
158 | |||
159 | __u8 pad[256 - 64]; /* set to zero */ | ||
160 | } bitmap_super_t; | ||
161 | |||
162 | /* notes: | ||
163 | * (1) This event counter is updated before the eventcounter in the md superblock | ||
164 | * When a bitmap is loaded, it is only accepted if this event counter is equal | ||
165 | * to, or one greater than, the event counter in the superblock. | ||
166 | * (2) This event counter is updated when the other one is *if*and*only*if* the | ||
167 | * array is not degraded. As bits are not cleared when the array is degraded, | ||
168 | * this represents the last time that any bits were cleared. | ||
169 | * If a device is being added that has an event count with this value or | ||
170 | * higher, it is accepted as conforming to the bitmap. | ||
171 | * (3)This is the number of sectors represented by the bitmap, and is the range that | ||
172 | * resync happens across. For raid1 and raid5/6 it is the size of individual | ||
173 | * devices. For raid10 it is the size of the array. | ||
174 | */ | ||
175 | |||
176 | #ifdef __KERNEL__ | ||
177 | |||
178 | /* the in-memory bitmap is represented by bitmap_pages */ | ||
179 | struct bitmap_page { | ||
180 | /* | ||
181 | * map points to the actual memory page | ||
182 | */ | ||
183 | char *map; | ||
184 | /* | ||
185 | * in emergencies (when map cannot be alloced), hijack the map | ||
186 | * pointer and use it as two counters itself | ||
187 | */ | ||
188 | unsigned int hijacked:1; | ||
189 | /* | ||
190 | * count of dirty bits on the page | ||
191 | */ | ||
192 | unsigned int count:31; | ||
193 | }; | ||
194 | |||
195 | /* keep track of bitmap file pages that have pending writes on them */ | ||
196 | struct page_list { | ||
197 | struct list_head list; | ||
198 | struct page *page; | ||
199 | }; | ||
200 | |||
201 | /* the main bitmap structure - one per mddev */ | ||
202 | struct bitmap { | ||
203 | struct bitmap_page *bp; | ||
204 | unsigned long pages; /* total number of pages in the bitmap */ | ||
205 | unsigned long missing_pages; /* number of pages not yet allocated */ | ||
206 | |||
207 | mddev_t *mddev; /* the md device that the bitmap is for */ | ||
208 | |||
209 | int counter_bits; /* how many bits per block counter */ | ||
210 | |||
211 | /* bitmap chunksize -- how much data does each bit represent? */ | ||
212 | unsigned long chunksize; | ||
213 | unsigned long chunkshift; /* chunksize = 2^chunkshift (for bitops) */ | ||
214 | unsigned long chunks; /* total number of data chunks for the array */ | ||
215 | |||
216 | /* We hold a count on the chunk currently being synced, and drop | ||
217 | * it when the last block is started. If the resync is aborted | ||
218 | * midway, we need to be able to drop that count, so we remember | ||
219 | * the counted chunk.. | ||
220 | */ | ||
221 | unsigned long syncchunk; | ||
222 | |||
223 | __u64 events_cleared; | ||
224 | int need_sync; | ||
225 | |||
226 | /* bitmap spinlock */ | ||
227 | spinlock_t lock; | ||
228 | |||
229 | long offset; /* offset from superblock if file is NULL */ | ||
230 | struct file *file; /* backing disk file */ | ||
231 | struct page *sb_page; /* cached copy of the bitmap file superblock */ | ||
232 | struct page **filemap; /* list of cache pages for the file */ | ||
233 | unsigned long *filemap_attr; /* attributes associated w/ filemap pages */ | ||
234 | unsigned long file_pages; /* number of pages in the file */ | ||
235 | int last_page_size; /* bytes in the last page */ | ||
236 | |||
237 | unsigned long flags; | ||
238 | |||
239 | int allclean; | ||
240 | |||
241 | unsigned long max_write_behind; /* write-behind mode */ | ||
242 | atomic_t behind_writes; | ||
243 | |||
244 | /* | ||
245 | * the bitmap daemon - periodically wakes up and sweeps the bitmap | ||
246 | * file, cleaning up bits and flushing out pages to disk as necessary | ||
247 | */ | ||
248 | unsigned long daemon_lastrun; /* jiffies of last run */ | ||
249 | unsigned long daemon_sleep; /* how many seconds between updates? */ | ||
250 | unsigned long last_end_sync; /* when we lasted called end_sync to | ||
251 | * update bitmap with resync progress */ | ||
252 | |||
253 | atomic_t pending_writes; /* pending writes to the bitmap file */ | ||
254 | wait_queue_head_t write_wait; | ||
255 | wait_queue_head_t overflow_wait; | ||
256 | |||
257 | }; | ||
258 | |||
259 | /* the bitmap API */ | ||
260 | |||
261 | /* these are used only by md/bitmap */ | ||
262 | int bitmap_create(mddev_t *mddev); | ||
263 | void bitmap_flush(mddev_t *mddev); | ||
264 | void bitmap_destroy(mddev_t *mddev); | ||
265 | |||
266 | void bitmap_print_sb(struct bitmap *bitmap); | ||
267 | void bitmap_update_sb(struct bitmap *bitmap); | ||
268 | |||
269 | int bitmap_setallbits(struct bitmap *bitmap); | ||
270 | void bitmap_write_all(struct bitmap *bitmap); | ||
271 | |||
272 | void bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e); | ||
273 | |||
274 | /* these are exported */ | ||
275 | int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, | ||
276 | unsigned long sectors, int behind); | ||
277 | void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, | ||
278 | unsigned long sectors, int success, int behind); | ||
279 | int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int degraded); | ||
280 | void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted); | ||
281 | void bitmap_close_sync(struct bitmap *bitmap); | ||
282 | void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector); | ||
283 | |||
284 | void bitmap_unplug(struct bitmap *bitmap); | ||
285 | void bitmap_daemon_work(struct bitmap *bitmap); | ||
286 | #endif | ||
287 | |||
288 | #endif | ||
diff --git a/drivers/md/linear.c b/drivers/md/linear.c index 09658b218474..3603ffa9edc5 100644 --- a/drivers/md/linear.c +++ b/drivers/md/linear.c | |||
@@ -16,7 +16,7 @@ | |||
16 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/raid/linear.h> | 19 | #include "linear.h" |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * find which device holds a particular offset | 22 | * find which device holds a particular offset |
diff --git a/drivers/md/linear.h b/drivers/md/linear.h new file mode 100644 index 000000000000..f38b9c586afb --- /dev/null +++ b/drivers/md/linear.h | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef _LINEAR_H | ||
2 | #define _LINEAR_H | ||
3 | |||
4 | #include <linux/raid/md.h> | ||
5 | |||
6 | struct dev_info { | ||
7 | mdk_rdev_t *rdev; | ||
8 | sector_t num_sectors; | ||
9 | sector_t start_sector; | ||
10 | }; | ||
11 | |||
12 | typedef struct dev_info dev_info_t; | ||
13 | |||
14 | struct linear_private_data | ||
15 | { | ||
16 | struct linear_private_data *prev; /* earlier version */ | ||
17 | dev_info_t **hash_table; | ||
18 | sector_t spacing; | ||
19 | sector_t array_sectors; | ||
20 | int sector_shift; /* shift before dividing | ||
21 | * by spacing | ||
22 | */ | ||
23 | dev_info_t disks[0]; | ||
24 | }; | ||
25 | |||
26 | |||
27 | typedef struct linear_private_data linear_conf_t; | ||
28 | |||
29 | #define mddev_to_conf(mddev) ((linear_conf_t *) mddev->private) | ||
30 | |||
31 | #endif | ||
diff --git a/drivers/md/md.c b/drivers/md/md.c index 3efc0bceada2..9a3214c8585f 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
@@ -34,7 +34,6 @@ | |||
34 | 34 | ||
35 | #include <linux/kthread.h> | 35 | #include <linux/kthread.h> |
36 | #include <linux/raid/md.h> | 36 | #include <linux/raid/md.h> |
37 | #include <linux/raid/bitmap.h> | ||
38 | #include <linux/sysctl.h> | 37 | #include <linux/sysctl.h> |
39 | #include <linux/buffer_head.h> /* for invalidate_bdev */ | 38 | #include <linux/buffer_head.h> /* for invalidate_bdev */ |
40 | #include <linux/poll.h> | 39 | #include <linux/poll.h> |
@@ -45,6 +44,7 @@ | |||
45 | #include <linux/reboot.h> | 44 | #include <linux/reboot.h> |
46 | #include <linux/file.h> | 45 | #include <linux/file.h> |
47 | #include <linux/delay.h> | 46 | #include <linux/delay.h> |
47 | #include "bitmap.h" | ||
48 | 48 | ||
49 | /* 63 partitions with the alternate major number (mdp) */ | 49 | /* 63 partitions with the alternate major number (mdp) */ |
50 | #define MdpMinorShift 6 | 50 | #define MdpMinorShift 6 |
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c index f6d08f241671..547df09a7af3 100644 --- a/drivers/md/multipath.c +++ b/drivers/md/multipath.c | |||
@@ -19,7 +19,7 @@ | |||
19 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 19 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <linux/raid/multipath.h> | 22 | #include "multipath.h" |
23 | 23 | ||
24 | #define MAX_WORK_PER_DISK 128 | 24 | #define MAX_WORK_PER_DISK 128 |
25 | 25 | ||
diff --git a/drivers/md/multipath.h b/drivers/md/multipath.h new file mode 100644 index 000000000000..6f53fc177a47 --- /dev/null +++ b/drivers/md/multipath.h | |||
@@ -0,0 +1,42 @@ | |||
1 | #ifndef _MULTIPATH_H | ||
2 | #define _MULTIPATH_H | ||
3 | |||
4 | #include <linux/raid/md.h> | ||
5 | |||
6 | struct multipath_info { | ||
7 | mdk_rdev_t *rdev; | ||
8 | }; | ||
9 | |||
10 | struct 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 | |||
21 | typedef 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 | |||
35 | struct 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/drivers/md/raid0.c b/drivers/md/raid0.c index c605ba805586..ef09ed04864e 100644 --- a/drivers/md/raid0.c +++ b/drivers/md/raid0.c | |||
@@ -18,7 +18,7 @@ | |||
18 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 18 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/raid/raid0.h> | 21 | #include "raid0.h" |
22 | 22 | ||
23 | static void raid0_unplug(struct request_queue *q) | 23 | static void raid0_unplug(struct request_queue *q) |
24 | { | 24 | { |
diff --git a/drivers/md/raid0.h b/drivers/md/raid0.h new file mode 100644 index 000000000000..fd42aa87c391 --- /dev/null +++ b/drivers/md/raid0.h | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef _RAID0_H | ||
2 | #define _RAID0_H | ||
3 | |||
4 | #include <linux/raid/md.h> | ||
5 | |||
6 | struct strip_zone | ||
7 | { | ||
8 | sector_t zone_start; /* Zone offset in md_dev (in sectors) */ | ||
9 | sector_t dev_start; /* Zone offset in real dev (in sectors) */ | ||
10 | sector_t sectors; /* Zone size in sectors */ | ||
11 | int nb_dev; /* # of devices attached to the zone */ | ||
12 | mdk_rdev_t **dev; /* Devices attached to the zone */ | ||
13 | }; | ||
14 | |||
15 | struct 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 spacing; | ||
23 | int sector_shift; /* shift this before divide by spacing */ | ||
24 | }; | ||
25 | |||
26 | typedef 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/drivers/md/raid1.c b/drivers/md/raid1.c index e2466425d9ca..bff32285f8bb 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c | |||
@@ -33,8 +33,8 @@ | |||
33 | 33 | ||
34 | #include "dm-bio-list.h" | 34 | #include "dm-bio-list.h" |
35 | #include <linux/delay.h> | 35 | #include <linux/delay.h> |
36 | #include <linux/raid/raid1.h> | 36 | #include "raid1.h" |
37 | #include <linux/raid/bitmap.h> | 37 | #include "bitmap.h" |
38 | 38 | ||
39 | #define DEBUG 0 | 39 | #define DEBUG 0 |
40 | #if DEBUG | 40 | #if DEBUG |
diff --git a/drivers/md/raid1.h b/drivers/md/raid1.h new file mode 100644 index 000000000000..0a9ba7c3302e --- /dev/null +++ b/drivers/md/raid1.h | |||
@@ -0,0 +1,134 @@ | |||
1 | #ifndef _RAID1_H | ||
2 | #define _RAID1_H | ||
3 | |||
4 | #include <linux/raid/md.h> | ||
5 | |||
6 | typedef struct mirror_info mirror_info_t; | ||
7 | |||
8 | struct 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 | |||
21 | struct pool_info { | ||
22 | mddev_t *mddev; | ||
23 | int raid_disks; | ||
24 | }; | ||
25 | |||
26 | |||
27 | typedef struct r1bio_s r1bio_t; | ||
28 | |||
29 | struct r1_private_data_s { | ||
30 | mddev_t *mddev; | ||
31 | mirror_info_t *mirrors; | ||
32 | int raid_disks; | ||
33 | int last_used; | ||
34 | sector_t next_seq_sect; | ||
35 | spinlock_t device_lock; | ||
36 | |||
37 | struct list_head retry_list; | ||
38 | /* queue pending writes and submit them on unplug */ | ||
39 | struct bio_list pending_bio_list; | ||
40 | /* queue of writes that have been unplugged */ | ||
41 | struct bio_list flushing_bio_list; | ||
42 | |||
43 | /* for use when syncing mirrors: */ | ||
44 | |||
45 | spinlock_t resync_lock; | ||
46 | int nr_pending; | ||
47 | int nr_waiting; | ||
48 | int nr_queued; | ||
49 | int barrier; | ||
50 | sector_t next_resync; | ||
51 | int fullsync; /* set to 1 if a full sync is needed, | ||
52 | * (fresh device added). | ||
53 | * Cleared when a sync completes. | ||
54 | */ | ||
55 | |||
56 | wait_queue_head_t wait_barrier; | ||
57 | |||
58 | struct pool_info *poolinfo; | ||
59 | |||
60 | struct page *tmppage; | ||
61 | |||
62 | mempool_t *r1bio_pool; | ||
63 | mempool_t *r1buf_pool; | ||
64 | }; | ||
65 | |||
66 | typedef struct r1_private_data_s conf_t; | ||
67 | |||
68 | /* | ||
69 | * this is the only point in the RAID code where we violate | ||
70 | * C type safety. mddev->private is an 'opaque' pointer. | ||
71 | */ | ||
72 | #define mddev_to_conf(mddev) ((conf_t *) mddev->private) | ||
73 | |||
74 | /* | ||
75 | * this is our 'private' RAID1 bio. | ||
76 | * | ||
77 | * it contains information about what kind of IO operations were started | ||
78 | * for this RAID1 operation, and about their status: | ||
79 | */ | ||
80 | |||
81 | struct r1bio_s { | ||
82 | atomic_t remaining; /* 'have we finished' count, | ||
83 | * used from IRQ handlers | ||
84 | */ | ||
85 | atomic_t behind_remaining; /* number of write-behind ios remaining | ||
86 | * in this BehindIO request | ||
87 | */ | ||
88 | sector_t sector; | ||
89 | int sectors; | ||
90 | unsigned long state; | ||
91 | mddev_t *mddev; | ||
92 | /* | ||
93 | * original bio going to /dev/mdx | ||
94 | */ | ||
95 | struct bio *master_bio; | ||
96 | /* | ||
97 | * if the IO is in READ direction, then this is where we read | ||
98 | */ | ||
99 | int read_disk; | ||
100 | |||
101 | struct list_head retry_list; | ||
102 | struct bitmap_update *bitmap_update; | ||
103 | /* | ||
104 | * if the IO is in WRITE direction, then multiple bios are used. | ||
105 | * We choose the number when they are allocated. | ||
106 | */ | ||
107 | struct bio *bios[0]; | ||
108 | /* DO NOT PUT ANY NEW FIELDS HERE - bios array is contiguously alloced*/ | ||
109 | }; | ||
110 | |||
111 | /* when we get a read error on a read-only array, we redirect to another | ||
112 | * device without failing the first device, or trying to over-write to | ||
113 | * correct the read error. To keep track of bad blocks on a per-bio | ||
114 | * level, we store IO_BLOCKED in the appropriate 'bios' pointer | ||
115 | */ | ||
116 | #define IO_BLOCKED ((struct bio*)1) | ||
117 | |||
118 | /* bits for r1bio.state */ | ||
119 | #define R1BIO_Uptodate 0 | ||
120 | #define R1BIO_IsSync 1 | ||
121 | #define R1BIO_Degraded 2 | ||
122 | #define R1BIO_BehindIO 3 | ||
123 | #define R1BIO_Barrier 4 | ||
124 | #define R1BIO_BarrierRetry 5 | ||
125 | /* For write-behind requests, we call bi_end_io when | ||
126 | * the last non-write-behind device completes, providing | ||
127 | * any write was successful. Otherwise we call when | ||
128 | * any write-behind write succeeds, otherwise we call | ||
129 | * with failure when last write completes (and all failed). | ||
130 | * Record that bi_end_io was called with this flag... | ||
131 | */ | ||
132 | #define R1BIO_Returned 6 | ||
133 | |||
134 | #endif | ||
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 7301631abe04..f03dd70d12a5 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c | |||
@@ -20,8 +20,8 @@ | |||
20 | 20 | ||
21 | #include "dm-bio-list.h" | 21 | #include "dm-bio-list.h" |
22 | #include <linux/delay.h> | 22 | #include <linux/delay.h> |
23 | #include <linux/raid/raid10.h> | 23 | #include "raid10.h" |
24 | #include <linux/raid/bitmap.h> | 24 | #include "bitmap.h" |
25 | 25 | ||
26 | /* | 26 | /* |
27 | * RAID10 provides a combination of RAID0 and RAID1 functionality. | 27 | * RAID10 provides a combination of RAID0 and RAID1 functionality. |
diff --git a/drivers/md/raid10.h b/drivers/md/raid10.h new file mode 100644 index 000000000000..e9091cfeb286 --- /dev/null +++ b/drivers/md/raid10.h | |||
@@ -0,0 +1,123 @@ | |||
1 | #ifndef _RAID10_H | ||
2 | #define _RAID10_H | ||
3 | |||
4 | #include <linux/raid/md.h> | ||
5 | |||
6 | typedef struct mirror_info mirror_info_t; | ||
7 | |||
8 | struct mirror_info { | ||
9 | mdk_rdev_t *rdev; | ||
10 | sector_t head_position; | ||
11 | }; | ||
12 | |||
13 | typedef struct r10bio_s r10bio_t; | ||
14 | |||
15 | struct r10_private_data_s { | ||
16 | mddev_t *mddev; | ||
17 | mirror_info_t *mirrors; | ||
18 | int raid_disks; | ||
19 | spinlock_t device_lock; | ||
20 | |||
21 | /* geometry */ | ||
22 | int near_copies; /* number of copies layed out raid0 style */ | ||
23 | int far_copies; /* number of copies layed out | ||
24 | * at large strides across drives | ||
25 | */ | ||
26 | int far_offset; /* far_copies are offset by 1 stripe | ||
27 | * instead of many | ||
28 | */ | ||
29 | int copies; /* near_copies * far_copies. | ||
30 | * must be <= raid_disks | ||
31 | */ | ||
32 | sector_t stride; /* distance between far copies. | ||
33 | * This is size / far_copies unless | ||
34 | * far_offset, in which case it is | ||
35 | * 1 stripe. | ||
36 | */ | ||
37 | |||
38 | int chunk_shift; /* shift from chunks to sectors */ | ||
39 | sector_t chunk_mask; | ||
40 | |||
41 | struct list_head retry_list; | ||
42 | /* queue pending writes and submit them on unplug */ | ||
43 | struct bio_list pending_bio_list; | ||
44 | |||
45 | |||
46 | spinlock_t resync_lock; | ||
47 | int nr_pending; | ||
48 | int nr_waiting; | ||
49 | int nr_queued; | ||
50 | int barrier; | ||
51 | sector_t next_resync; | ||
52 | int fullsync; /* set to 1 if a full sync is needed, | ||
53 | * (fresh device added). | ||
54 | * Cleared when a sync completes. | ||
55 | */ | ||
56 | |||
57 | wait_queue_head_t wait_barrier; | ||
58 | |||
59 | mempool_t *r10bio_pool; | ||
60 | mempool_t *r10buf_pool; | ||
61 | struct page *tmppage; | ||
62 | }; | ||
63 | |||
64 | typedef struct r10_private_data_s conf_t; | ||
65 | |||
66 | /* | ||
67 | * this is the only point in the RAID code where we violate | ||
68 | * C type safety. mddev->private is an 'opaque' pointer. | ||
69 | */ | ||
70 | #define mddev_to_conf(mddev) ((conf_t *) mddev->private) | ||
71 | |||
72 | /* | ||
73 | * this is our 'private' RAID10 bio. | ||
74 | * | ||
75 | * it contains information about what kind of IO operations were started | ||
76 | * for this RAID10 operation, and about their status: | ||
77 | */ | ||
78 | |||
79 | struct r10bio_s { | ||
80 | atomic_t remaining; /* 'have we finished' count, | ||
81 | * used from IRQ handlers | ||
82 | */ | ||
83 | sector_t sector; /* virtual sector number */ | ||
84 | int sectors; | ||
85 | unsigned long state; | ||
86 | mddev_t *mddev; | ||
87 | /* | ||
88 | * original bio going to /dev/mdx | ||
89 | */ | ||
90 | struct bio *master_bio; | ||
91 | /* | ||
92 | * if the IO is in READ direction, then this is where we read | ||
93 | */ | ||
94 | int read_slot; | ||
95 | |||
96 | struct list_head retry_list; | ||
97 | /* | ||
98 | * if the IO is in WRITE direction, then multiple bios are used, | ||
99 | * one for each copy. | ||
100 | * When resyncing we also use one for each copy. | ||
101 | * When reconstructing, we use 2 bios, one for read, one for write. | ||
102 | * We choose the number when they are allocated. | ||
103 | */ | ||
104 | struct { | ||
105 | struct bio *bio; | ||
106 | sector_t addr; | ||
107 | int devnum; | ||
108 | } devs[0]; | ||
109 | }; | ||
110 | |||
111 | /* when we get a read error on a read-only array, we redirect to another | ||
112 | * device without failing the first device, or trying to over-write to | ||
113 | * correct the read error. To keep track of bad blocks on a per-bio | ||
114 | * level, we store IO_BLOCKED in the appropriate 'bios' pointer | ||
115 | */ | ||
116 | #define IO_BLOCKED ((struct bio*)1) | ||
117 | |||
118 | /* bits for r10bio.state */ | ||
119 | #define R10BIO_Uptodate 0 | ||
120 | #define R10BIO_IsSync 1 | ||
121 | #define R10BIO_IsRecover 2 | ||
122 | #define R10BIO_Degraded 3 | ||
123 | #endif | ||
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index a5ba080d303b..f75698b1f63d 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c | |||
@@ -44,10 +44,9 @@ | |||
44 | */ | 44 | */ |
45 | 45 | ||
46 | #include <linux/kthread.h> | 46 | #include <linux/kthread.h> |
47 | #include "raid6.h" | ||
48 | |||
49 | #include <linux/raid/bitmap.h> | ||
50 | #include <linux/async_tx.h> | 47 | #include <linux/async_tx.h> |
48 | #include "raid6.h" | ||
49 | #include "bitmap.h" | ||
51 | 50 | ||
52 | /* | 51 | /* |
53 | * Stripe cache | 52 | * Stripe cache |
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h new file mode 100644 index 000000000000..40f1d0335c74 --- /dev/null +++ b/drivers/md/raid5.h | |||
@@ -0,0 +1,402 @@ | |||
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 ... | ||
120 | * (lockdev check-buffers unlockdev) .. | ||
121 | * change-state .. | ||
122 | * record io/ops needed unlockstripe schedule io/ops | ||
123 | * release an active stripe (release_stripe()) | ||
124 | * lockdev if (!--cnt) { if STRIPE_HANDLE, add to handle_list else add to inactive-list } unlockdev | ||
125 | * | ||
126 | * The refcount counts each thread that have activated the stripe, | ||
127 | * plus raid5d if it is handling it, plus one for each active request | ||
128 | * on a cached buffer, and plus one if the stripe is undergoing stripe | ||
129 | * operations. | ||
130 | * | ||
131 | * Stripe operations are performed outside the stripe lock, | ||
132 | * the stripe operations are: | ||
133 | * -copying data between the stripe cache and user application buffers | ||
134 | * -computing blocks to save a disk access, or to recover a missing block | ||
135 | * -updating the parity on a write operation (reconstruct write and | ||
136 | * read-modify-write) | ||
137 | * -checking parity correctness | ||
138 | * -running i/o to disk | ||
139 | * These operations are carried out by raid5_run_ops which uses the async_tx | ||
140 | * api to (optionally) offload operations to dedicated hardware engines. | ||
141 | * When requesting an operation handle_stripe sets the pending bit for the | ||
142 | * operation and increments the count. raid5_run_ops is then run whenever | ||
143 | * the count is non-zero. | ||
144 | * There are some critical dependencies between the operations that prevent some | ||
145 | * from being requested while another is in flight. | ||
146 | * 1/ Parity check operations destroy the in cache version of the parity block, | ||
147 | * so we prevent parity dependent operations like writes and compute_blocks | ||
148 | * from starting while a check is in progress. Some dma engines can perform | ||
149 | * the check without damaging the parity block, in these cases the parity | ||
150 | * block is re-marked up to date (assuming the check was successful) and is | ||
151 | * not re-read from disk. | ||
152 | * 2/ When a write operation is requested we immediately lock the affected | ||
153 | * blocks, and mark them as not up to date. This causes new read requests | ||
154 | * to be held off, as well as parity checks and compute block operations. | ||
155 | * 3/ Once a compute block operation has been requested handle_stripe treats | ||
156 | * that block as if it is up to date. raid5_run_ops guaruntees that any | ||
157 | * operation that is dependent on the compute block result is initiated after | ||
158 | * the compute block completes. | ||
159 | */ | ||
160 | |||
161 | /* | ||
162 | * Operations state - intermediate states that are visible outside of sh->lock | ||
163 | * In general _idle indicates nothing is running, _run indicates a data | ||
164 | * processing operation is active, and _result means the data processing result | ||
165 | * is stable and can be acted upon. For simple operations like biofill and | ||
166 | * compute that only have an _idle and _run state they are indicated with | ||
167 | * sh->state flags (STRIPE_BIOFILL_RUN and STRIPE_COMPUTE_RUN) | ||
168 | */ | ||
169 | /** | ||
170 | * enum check_states - handles syncing / repairing a stripe | ||
171 | * @check_state_idle - check operations are quiesced | ||
172 | * @check_state_run - check operation is running | ||
173 | * @check_state_result - set outside lock when check result is valid | ||
174 | * @check_state_compute_run - check failed and we are repairing | ||
175 | * @check_state_compute_result - set outside lock when compute result is valid | ||
176 | */ | ||
177 | enum check_states { | ||
178 | check_state_idle = 0, | ||
179 | check_state_run, /* parity check */ | ||
180 | check_state_check_result, | ||
181 | check_state_compute_run, /* parity repair */ | ||
182 | check_state_compute_result, | ||
183 | }; | ||
184 | |||
185 | /** | ||
186 | * enum reconstruct_states - handles writing or expanding a stripe | ||
187 | */ | ||
188 | enum reconstruct_states { | ||
189 | reconstruct_state_idle = 0, | ||
190 | reconstruct_state_prexor_drain_run, /* prexor-write */ | ||
191 | reconstruct_state_drain_run, /* write */ | ||
192 | reconstruct_state_run, /* expand */ | ||
193 | reconstruct_state_prexor_drain_result, | ||
194 | reconstruct_state_drain_result, | ||
195 | reconstruct_state_result, | ||
196 | }; | ||
197 | |||
198 | struct stripe_head { | ||
199 | struct hlist_node hash; | ||
200 | struct list_head lru; /* inactive_list or handle_list */ | ||
201 | struct raid5_private_data *raid_conf; | ||
202 | sector_t sector; /* sector of this row */ | ||
203 | int pd_idx; /* parity disk index */ | ||
204 | unsigned long state; /* state flags */ | ||
205 | atomic_t count; /* nr of active thread/requests */ | ||
206 | spinlock_t lock; | ||
207 | int bm_seq; /* sequence number for bitmap flushes */ | ||
208 | int disks; /* disks in stripe */ | ||
209 | enum check_states check_state; | ||
210 | enum reconstruct_states reconstruct_state; | ||
211 | /* stripe_operations | ||
212 | * @target - STRIPE_OP_COMPUTE_BLK target | ||
213 | */ | ||
214 | struct stripe_operations { | ||
215 | int target; | ||
216 | u32 zero_sum_result; | ||
217 | } ops; | ||
218 | struct r5dev { | ||
219 | struct bio req; | ||
220 | struct bio_vec vec; | ||
221 | struct page *page; | ||
222 | struct bio *toread, *read, *towrite, *written; | ||
223 | sector_t sector; /* sector of this page */ | ||
224 | unsigned long flags; | ||
225 | } dev[1]; /* allocated with extra space depending of RAID geometry */ | ||
226 | }; | ||
227 | |||
228 | /* stripe_head_state - collects and tracks the dynamic state of a stripe_head | ||
229 | * for handle_stripe. It is only valid under spin_lock(sh->lock); | ||
230 | */ | ||
231 | struct stripe_head_state { | ||
232 | int syncing, expanding, expanded; | ||
233 | int locked, uptodate, to_read, to_write, failed, written; | ||
234 | int to_fill, compute, req_compute, non_overwrite; | ||
235 | int failed_num; | ||
236 | unsigned long ops_request; | ||
237 | }; | ||
238 | |||
239 | /* r6_state - extra state data only relevant to r6 */ | ||
240 | struct r6_state { | ||
241 | int p_failed, q_failed, qd_idx, failed_num[2]; | ||
242 | }; | ||
243 | |||
244 | /* Flags */ | ||
245 | #define R5_UPTODATE 0 /* page contains current data */ | ||
246 | #define R5_LOCKED 1 /* IO has been submitted on "req" */ | ||
247 | #define R5_OVERWRITE 2 /* towrite covers whole page */ | ||
248 | /* and some that are internal to handle_stripe */ | ||
249 | #define R5_Insync 3 /* rdev && rdev->in_sync at start */ | ||
250 | #define R5_Wantread 4 /* want to schedule a read */ | ||
251 | #define R5_Wantwrite 5 | ||
252 | #define R5_Overlap 7 /* There is a pending overlapping request on this block */ | ||
253 | #define R5_ReadError 8 /* seen a read error here recently */ | ||
254 | #define R5_ReWrite 9 /* have tried to over-write the readerror */ | ||
255 | |||
256 | #define R5_Expanded 10 /* This block now has post-expand data */ | ||
257 | #define R5_Wantcompute 11 /* compute_block in progress treat as | ||
258 | * uptodate | ||
259 | */ | ||
260 | #define R5_Wantfill 12 /* dev->toread contains a bio that needs | ||
261 | * filling | ||
262 | */ | ||
263 | #define R5_Wantdrain 13 /* dev->towrite needs to be drained */ | ||
264 | /* | ||
265 | * Write method | ||
266 | */ | ||
267 | #define RECONSTRUCT_WRITE 1 | ||
268 | #define READ_MODIFY_WRITE 2 | ||
269 | /* not a write method, but a compute_parity mode */ | ||
270 | #define CHECK_PARITY 3 | ||
271 | |||
272 | /* | ||
273 | * Stripe state | ||
274 | */ | ||
275 | #define STRIPE_HANDLE 2 | ||
276 | #define STRIPE_SYNCING 3 | ||
277 | #define STRIPE_INSYNC 4 | ||
278 | #define STRIPE_PREREAD_ACTIVE 5 | ||
279 | #define STRIPE_DELAYED 6 | ||
280 | #define STRIPE_DEGRADED 7 | ||
281 | #define STRIPE_BIT_DELAY 8 | ||
282 | #define STRIPE_EXPANDING 9 | ||
283 | #define STRIPE_EXPAND_SOURCE 10 | ||
284 | #define STRIPE_EXPAND_READY 11 | ||
285 | #define STRIPE_IO_STARTED 12 /* do not count towards 'bypass_count' */ | ||
286 | #define STRIPE_FULL_WRITE 13 /* all blocks are set to be overwritten */ | ||
287 | #define STRIPE_BIOFILL_RUN 14 | ||
288 | #define STRIPE_COMPUTE_RUN 15 | ||
289 | /* | ||
290 | * Operation request flags | ||
291 | */ | ||
292 | #define STRIPE_OP_BIOFILL 0 | ||
293 | #define STRIPE_OP_COMPUTE_BLK 1 | ||
294 | #define STRIPE_OP_PREXOR 2 | ||
295 | #define STRIPE_OP_BIODRAIN 3 | ||
296 | #define STRIPE_OP_POSTXOR 4 | ||
297 | #define STRIPE_OP_CHECK 5 | ||
298 | |||
299 | /* | ||
300 | * Plugging: | ||
301 | * | ||
302 | * To improve write throughput, we need to delay the handling of some | ||
303 | * stripes until there has been a chance that several write requests | ||
304 | * for the one stripe have all been collected. | ||
305 | * In particular, any write request that would require pre-reading | ||
306 | * is put on a "delayed" queue until there are no stripes currently | ||
307 | * in a pre-read phase. Further, if the "delayed" queue is empty when | ||
308 | * a stripe is put on it then we "plug" the queue and do not process it | ||
309 | * until an unplug call is made. (the unplug_io_fn() is called). | ||
310 | * | ||
311 | * When preread is initiated on a stripe, we set PREREAD_ACTIVE and add | ||
312 | * it to the count of prereading stripes. | ||
313 | * When write is initiated, or the stripe refcnt == 0 (just in case) we | ||
314 | * clear the PREREAD_ACTIVE flag and decrement the count | ||
315 | * Whenever the 'handle' queue is empty and the device is not plugged, we | ||
316 | * move any strips from delayed to handle and clear the DELAYED flag and set | ||
317 | * PREREAD_ACTIVE. | ||
318 | * In stripe_handle, if we find pre-reading is necessary, we do it if | ||
319 | * PREREAD_ACTIVE is set, else we set DELAYED which will send it to the delayed queue. | ||
320 | * HANDLE gets cleared if stripe_handle leave nothing locked. | ||
321 | */ | ||
322 | |||
323 | |||
324 | struct disk_info { | ||
325 | mdk_rdev_t *rdev; | ||
326 | }; | ||
327 | |||
328 | struct raid5_private_data { | ||
329 | struct hlist_head *stripe_hashtbl; | ||
330 | mddev_t *mddev; | ||
331 | struct disk_info *spare; | ||
332 | int chunk_size, level, algorithm; | ||
333 | int max_degraded; | ||
334 | int raid_disks; | ||
335 | int max_nr_stripes; | ||
336 | |||
337 | /* used during an expand */ | ||
338 | sector_t expand_progress; /* MaxSector when no expand happening */ | ||
339 | sector_t expand_lo; /* from here up to expand_progress it out-of-bounds | ||
340 | * as we haven't flushed the metadata yet | ||
341 | */ | ||
342 | int previous_raid_disks; | ||
343 | |||
344 | struct list_head handle_list; /* stripes needing handling */ | ||
345 | struct list_head hold_list; /* preread ready stripes */ | ||
346 | struct list_head delayed_list; /* stripes that have plugged requests */ | ||
347 | struct list_head bitmap_list; /* stripes delaying awaiting bitmap update */ | ||
348 | struct bio *retry_read_aligned; /* currently retrying aligned bios */ | ||
349 | struct bio *retry_read_aligned_list; /* aligned bios retry list */ | ||
350 | atomic_t preread_active_stripes; /* stripes with scheduled io */ | ||
351 | atomic_t active_aligned_reads; | ||
352 | atomic_t pending_full_writes; /* full write backlog */ | ||
353 | int bypass_count; /* bypassed prereads */ | ||
354 | int bypass_threshold; /* preread nice */ | ||
355 | struct list_head *last_hold; /* detect hold_list promotions */ | ||
356 | |||
357 | atomic_t reshape_stripes; /* stripes with pending writes for reshape */ | ||
358 | /* unfortunately we need two cache names as we temporarily have | ||
359 | * two caches. | ||
360 | */ | ||
361 | int active_name; | ||
362 | char cache_name[2][20]; | ||
363 | struct kmem_cache *slab_cache; /* for allocating stripes */ | ||
364 | |||
365 | int seq_flush, seq_write; | ||
366 | int quiesce; | ||
367 | |||
368 | int fullsync; /* set to 1 if a full sync is needed, | ||
369 | * (fresh device added). | ||
370 | * Cleared when a sync completes. | ||
371 | */ | ||
372 | |||
373 | struct page *spare_page; /* Used when checking P/Q in raid6 */ | ||
374 | |||
375 | /* | ||
376 | * Free stripes pool | ||
377 | */ | ||
378 | atomic_t active_stripes; | ||
379 | struct list_head inactive_list; | ||
380 | wait_queue_head_t wait_for_stripe; | ||
381 | wait_queue_head_t wait_for_overlap; | ||
382 | int inactive_blocked; /* release of inactive stripes blocked, | ||
383 | * waiting for 25% to be free | ||
384 | */ | ||
385 | int pool_size; /* number of disks in stripeheads in pool */ | ||
386 | spinlock_t device_lock; | ||
387 | struct disk_info *disks; | ||
388 | }; | ||
389 | |||
390 | typedef struct raid5_private_data raid5_conf_t; | ||
391 | |||
392 | #define mddev_to_conf(mddev) ((raid5_conf_t *) mddev->private) | ||
393 | |||
394 | /* | ||
395 | * Our supported algorithms | ||
396 | */ | ||
397 | #define ALGORITHM_LEFT_ASYMMETRIC 0 | ||
398 | #define ALGORITHM_RIGHT_ASYMMETRIC 1 | ||
399 | #define ALGORITHM_LEFT_SYMMETRIC 2 | ||
400 | #define ALGORITHM_RIGHT_SYMMETRIC 3 | ||
401 | |||
402 | #endif | ||
diff --git a/drivers/md/raid6.h b/drivers/md/raid6.h index 98dcde88470e..f6c13af65002 100644 --- a/drivers/md/raid6.h +++ b/drivers/md/raid6.h | |||
@@ -19,7 +19,7 @@ | |||
19 | #define RAID6_USE_EMPTY_ZERO_PAGE 0 | 19 | #define RAID6_USE_EMPTY_ZERO_PAGE 0 |
20 | 20 | ||
21 | #include <linux/raid/md.h> | 21 | #include <linux/raid/md.h> |
22 | #include <linux/raid/raid5.h> | 22 | #include "raid5.h" |
23 | 23 | ||
24 | typedef raid5_conf_t raid6_conf_t; /* Same configuration */ | 24 | typedef raid5_conf_t raid6_conf_t; /* Same configuration */ |
25 | 25 | ||