blob: b1bcd36ca963db3fbed33583dcfc0f30d540606c [file] [log] [blame]
NeilBrown32a76272005-06-21 17:17:14 -07001/*
2 * bitmap.c two-level bitmap (C) Peter T. Breuer (ptb@ot.uc3m.es) 2003
3 *
4 * bitmap_create - sets up the bitmap structure
5 * bitmap_destroy - destroys the bitmap structure
6 *
7 * additions, Copyright (C) 2003-2004, Paul Clements, SteelEye Technology, Inc.:
8 * - added disk storage for bitmap
9 * - changes to allow various bitmap chunk sizes
NeilBrown32a76272005-06-21 17:17:14 -070010 */
11
12/*
13 * Still to do:
14 *
15 * flush after percent set rather than just time based. (maybe both).
16 * wait if count gets too high, wake when it drops to half.
NeilBrown32a76272005-06-21 17:17:14 -070017 */
18
NeilBrownbff61972009-03-31 14:33:13 +110019#include <linux/blkdev.h>
NeilBrown32a76272005-06-21 17:17:14 -070020#include <linux/module.h>
NeilBrown32a76272005-06-21 17:17:14 -070021#include <linux/errno.h>
22#include <linux/slab.h>
23#include <linux/init.h>
NeilBrown32a76272005-06-21 17:17:14 -070024#include <linux/timer.h>
25#include <linux/sched.h>
26#include <linux/list.h>
27#include <linux/file.h>
28#include <linux/mount.h>
29#include <linux/buffer_head.h>
NeilBrown43b2e5d2009-03-31 14:33:13 +110030#include "md.h"
Christoph Hellwigef740c32009-03-31 14:27:03 +110031#include "bitmap.h"
NeilBrown32a76272005-06-21 17:17:14 -070032
33/* debug macros */
34
35#define DEBUG 0
36
37#if DEBUG
38/* these are for debugging purposes only! */
39
40/* define one and only one of these */
41#define INJECT_FAULTS_1 0 /* cause bitmap_alloc_page to fail always */
42#define INJECT_FAULTS_2 0 /* cause bitmap file to be kicked when first bit set*/
43#define INJECT_FAULTS_3 0 /* treat bitmap file as kicked at init time */
44#define INJECT_FAULTS_4 0 /* undef */
45#define INJECT_FAULTS_5 0 /* undef */
46#define INJECT_FAULTS_6 0
47
48/* if these are defined, the driver will fail! debug only */
49#define INJECT_FATAL_FAULT_1 0 /* fail kmalloc, causing bitmap_create to fail */
50#define INJECT_FATAL_FAULT_2 0 /* undef */
51#define INJECT_FATAL_FAULT_3 0 /* undef */
52#endif
53
54//#define DPRINTK PRINTK /* set this NULL to avoid verbose debug output */
55#define DPRINTK(x...) do { } while(0)
56
57#ifndef PRINTK
58# if DEBUG > 0
59# define PRINTK(x...) printk(KERN_DEBUG x)
60# else
61# define PRINTK(x...)
62# endif
63#endif
64
65static inline char * bmname(struct bitmap *bitmap)
66{
67 return bitmap->mddev ? mdname(bitmap->mddev) : "mdX";
68}
69
NeilBrown32a76272005-06-21 17:17:14 -070070
71/*
72 * just a placeholder - calls kmalloc for bitmap pages
73 */
74static unsigned char *bitmap_alloc_page(struct bitmap *bitmap)
75{
76 unsigned char *page;
77
Olaf Hering44456d32005-07-27 11:45:17 -070078#ifdef INJECT_FAULTS_1
NeilBrown32a76272005-06-21 17:17:14 -070079 page = NULL;
80#else
81 page = kmalloc(PAGE_SIZE, GFP_NOIO);
82#endif
83 if (!page)
84 printk("%s: bitmap_alloc_page FAILED\n", bmname(bitmap));
85 else
NeilBrowna654b9d82005-06-21 17:17:27 -070086 PRINTK("%s: bitmap_alloc_page: allocated page at %p\n",
NeilBrown32a76272005-06-21 17:17:14 -070087 bmname(bitmap), page);
88 return page;
89}
90
91/*
92 * for now just a placeholder -- just calls kfree for bitmap pages
93 */
94static void bitmap_free_page(struct bitmap *bitmap, unsigned char *page)
95{
96 PRINTK("%s: bitmap_free_page: free page %p\n", bmname(bitmap), page);
97 kfree(page);
98}
99
100/*
101 * check a page and, if necessary, allocate it (or hijack it if the alloc fails)
102 *
103 * 1) check to see if this page is allocated, if it's not then try to alloc
104 * 2) if the alloc fails, set the page's hijacked flag so we'll use the
105 * page pointer directly as a counter
106 *
107 * if we find our page, we increment the page's refcount so that it stays
108 * allocated while we're using it
109 */
110static int bitmap_checkpage(struct bitmap *bitmap, unsigned long page, int create)
NeilBrownee305ac2009-09-23 18:06:44 +1000111__releases(bitmap->lock)
112__acquires(bitmap->lock)
NeilBrown32a76272005-06-21 17:17:14 -0700113{
114 unsigned char *mappage;
115
116 if (page >= bitmap->pages) {
NeilBrown1187cf02009-03-31 14:27:02 +1100117 /* This can happen if bitmap_start_sync goes beyond
118 * End-of-device while looking for a whole page.
119 * It is harmless.
120 */
NeilBrown32a76272005-06-21 17:17:14 -0700121 return -EINVAL;
122 }
123
124
125 if (bitmap->bp[page].hijacked) /* it's hijacked, don't try to alloc */
126 return 0;
127
128 if (bitmap->bp[page].map) /* page is already allocated, just return */
129 return 0;
130
131 if (!create)
132 return -ENOENT;
133
134 spin_unlock_irq(&bitmap->lock);
135
136 /* this page has not been allocated yet */
137
138 if ((mappage = bitmap_alloc_page(bitmap)) == NULL) {
139 PRINTK("%s: bitmap map page allocation failed, hijacking\n",
140 bmname(bitmap));
141 /* failed - set the hijacked flag so that we can use the
142 * pointer as a counter */
143 spin_lock_irq(&bitmap->lock);
144 if (!bitmap->bp[page].map)
145 bitmap->bp[page].hijacked = 1;
146 goto out;
147 }
148
149 /* got a page */
150
151 spin_lock_irq(&bitmap->lock);
152
153 /* recheck the page */
154
155 if (bitmap->bp[page].map || bitmap->bp[page].hijacked) {
156 /* somebody beat us to getting the page */
157 bitmap_free_page(bitmap, mappage);
158 return 0;
159 }
160
161 /* no page was in place and we have one, so install it */
162
163 memset(mappage, 0, PAGE_SIZE);
164 bitmap->bp[page].map = mappage;
165 bitmap->missing_pages--;
166out:
167 return 0;
168}
169
170
171/* if page is completely empty, put it back on the free list, or dealloc it */
172/* if page was hijacked, unmark the flag so it might get alloced next time */
173/* Note: lock should be held when calling this */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800174static void bitmap_checkfree(struct bitmap *bitmap, unsigned long page)
NeilBrown32a76272005-06-21 17:17:14 -0700175{
176 char *ptr;
177
178 if (bitmap->bp[page].count) /* page is still busy */
179 return;
180
181 /* page is no longer in use, it can be released */
182
183 if (bitmap->bp[page].hijacked) { /* page was hijacked, undo this now */
184 bitmap->bp[page].hijacked = 0;
185 bitmap->bp[page].map = NULL;
186 return;
187 }
188
189 /* normal case, free the page */
190
191#if 0
192/* actually ... let's not. We will probably need the page again exactly when
193 * memory is tight and we are flusing to disk
194 */
195 return;
196#else
197 ptr = bitmap->bp[page].map;
198 bitmap->bp[page].map = NULL;
199 bitmap->missing_pages++;
200 bitmap_free_page(bitmap, ptr);
201 return;
202#endif
203}
204
205
206/*
207 * bitmap file handling - read and write the bitmap file and its superblock
208 */
209
NeilBrown32a76272005-06-21 17:17:14 -0700210/*
211 * basic page I/O operations
212 */
213
NeilBrowna654b9d82005-06-21 17:17:27 -0700214/* IO operations when bitmap is stored near all superblocks */
NeilBrowna2ed9612008-12-19 16:25:01 +1100215static struct page *read_sb_page(mddev_t *mddev, long offset,
216 struct page *page,
217 unsigned long index, int size)
NeilBrowna654b9d82005-06-21 17:17:27 -0700218{
219 /* choose a good rdev and read the page from there */
220
221 mdk_rdev_t *rdev;
NeilBrowna654b9d82005-06-21 17:17:27 -0700222 sector_t target;
223
224 if (!page)
NeilBrowna2ed9612008-12-19 16:25:01 +1100225 page = alloc_page(GFP_KERNEL);
226 if (!page)
NeilBrowna654b9d82005-06-21 17:17:27 -0700227 return ERR_PTR(-ENOMEM);
NeilBrowna654b9d82005-06-21 17:17:27 -0700228
Cheng Renquan159ec1f2009-01-09 08:31:08 +1100229 list_for_each_entry(rdev, &mddev->disks, same_set) {
NeilBrownb2d444d2005-11-08 21:39:31 -0800230 if (! test_bit(In_sync, &rdev->flags)
231 || test_bit(Faulty, &rdev->flags))
NeilBrownab904d62005-09-09 16:23:52 -0700232 continue;
233
Andre Noll0f420352008-07-11 22:02:23 +1000234 target = rdev->sb_start + offset + index * (PAGE_SIZE/512);
NeilBrowna654b9d82005-06-21 17:17:27 -0700235
NeilBrowna2ed9612008-12-19 16:25:01 +1100236 if (sync_page_io(rdev->bdev, target,
Martin K. Petersene1defc42009-05-22 17:17:49 -0400237 roundup(size, bdev_logical_block_size(rdev->bdev)),
NeilBrowna2ed9612008-12-19 16:25:01 +1100238 page, READ)) {
NeilBrownab904d62005-09-09 16:23:52 -0700239 page->index = index;
NeilBrownce25c312006-06-26 00:27:49 -0700240 attach_page_buffers(page, NULL); /* so that free_buffer will
241 * quietly no-op */
NeilBrownab904d62005-09-09 16:23:52 -0700242 return page;
243 }
244 }
245 return ERR_PTR(-EIO);
NeilBrowna654b9d82005-06-21 17:17:27 -0700246
NeilBrowna654b9d82005-06-21 17:17:27 -0700247}
248
NeilBrownb2d2c4c2008-09-01 12:48:13 +1000249static mdk_rdev_t *next_active_rdev(mdk_rdev_t *rdev, mddev_t *mddev)
250{
251 /* Iterate the disks of an mddev, using rcu to protect access to the
252 * linked list, and raising the refcount of devices we return to ensure
253 * they don't disappear while in use.
254 * As devices are only added or removed when raid_disk is < 0 and
255 * nr_pending is 0 and In_sync is clear, the entries we return will
256 * still be in the same position on the list when we re-enter
257 * list_for_each_continue_rcu.
258 */
259 struct list_head *pos;
260 rcu_read_lock();
261 if (rdev == NULL)
262 /* start at the beginning */
263 pos = &mddev->disks;
264 else {
265 /* release the previous rdev and start from there. */
266 rdev_dec_pending(rdev, mddev);
267 pos = &rdev->same_set;
268 }
269 list_for_each_continue_rcu(pos, &mddev->disks) {
270 rdev = list_entry(pos, mdk_rdev_t, same_set);
271 if (rdev->raid_disk >= 0 &&
NeilBrownb2d2c4c2008-09-01 12:48:13 +1000272 !test_bit(Faulty, &rdev->flags)) {
273 /* this is a usable devices */
274 atomic_inc(&rdev->nr_pending);
275 rcu_read_unlock();
276 return rdev;
277 }
278 }
279 rcu_read_unlock();
280 return NULL;
281}
282
NeilBrownab6085c2007-05-23 13:58:10 -0700283static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
NeilBrowna654b9d82005-06-21 17:17:27 -0700284{
NeilBrownb2d2c4c2008-09-01 12:48:13 +1000285 mdk_rdev_t *rdev = NULL;
NeilBrownab6085c2007-05-23 13:58:10 -0700286 mddev_t *mddev = bitmap->mddev;
NeilBrowna654b9d82005-06-21 17:17:27 -0700287
NeilBrownb2d2c4c2008-09-01 12:48:13 +1000288 while ((rdev = next_active_rdev(rdev, mddev)) != NULL) {
NeilBrownab6085c2007-05-23 13:58:10 -0700289 int size = PAGE_SIZE;
NeilBrown42a04b52009-12-14 12:49:53 +1100290 long offset = mddev->bitmap_info.offset;
NeilBrownab6085c2007-05-23 13:58:10 -0700291 if (page->index == bitmap->file_pages-1)
292 size = roundup(bitmap->last_page_size,
Martin K. Petersene1defc42009-05-22 17:17:49 -0400293 bdev_logical_block_size(rdev->bdev));
NeilBrownf0d76d72007-07-17 04:06:12 -0700294 /* Just make sure we aren't corrupting data or
295 * metadata
296 */
NeilBrown42a04b52009-12-14 12:49:53 +1100297 if (offset < 0) {
NeilBrownf0d76d72007-07-17 04:06:12 -0700298 /* DATA BITMAP METADATA */
NeilBrown42a04b52009-12-14 12:49:53 +1100299 if (offset
NeilBrown85bfb4d2007-10-22 20:45:11 -0700300 + (long)(page->index * (PAGE_SIZE/512))
NeilBrownf0d76d72007-07-17 04:06:12 -0700301 + size/512 > 0)
302 /* bitmap runs in to metadata */
NeilBrown4b809912008-07-21 17:05:25 +1000303 goto bad_alignment;
Andre Noll58c0fed2009-03-31 14:33:13 +1100304 if (rdev->data_offset + mddev->dev_sectors
NeilBrown42a04b52009-12-14 12:49:53 +1100305 > rdev->sb_start + offset)
NeilBrownf0d76d72007-07-17 04:06:12 -0700306 /* data runs in to bitmap */
NeilBrown4b809912008-07-21 17:05:25 +1000307 goto bad_alignment;
Andre Noll0f420352008-07-11 22:02:23 +1000308 } else if (rdev->sb_start < rdev->data_offset) {
NeilBrownf0d76d72007-07-17 04:06:12 -0700309 /* METADATA BITMAP DATA */
Andre Noll0f420352008-07-11 22:02:23 +1000310 if (rdev->sb_start
NeilBrown42a04b52009-12-14 12:49:53 +1100311 + offset
NeilBrownf0d76d72007-07-17 04:06:12 -0700312 + page->index*(PAGE_SIZE/512) + size/512
313 > rdev->data_offset)
314 /* bitmap runs in to data */
NeilBrown4b809912008-07-21 17:05:25 +1000315 goto bad_alignment;
NeilBrownf0d76d72007-07-17 04:06:12 -0700316 } else {
317 /* DATA METADATA BITMAP - no problems */
318 }
NeilBrowna654b9d82005-06-21 17:17:27 -0700319 md_super_write(mddev, rdev,
NeilBrown42a04b52009-12-14 12:49:53 +1100320 rdev->sb_start + offset
NeilBrowna654b9d82005-06-21 17:17:27 -0700321 + page->index * (PAGE_SIZE/512),
NeilBrownab6085c2007-05-23 13:58:10 -0700322 size,
NeilBrowna654b9d82005-06-21 17:17:27 -0700323 page);
NeilBrownb2d2c4c2008-09-01 12:48:13 +1000324 }
NeilBrowna654b9d82005-06-21 17:17:27 -0700325
326 if (wait)
NeilBrowna9701a32005-11-08 21:39:34 -0800327 md_super_wait(mddev);
NeilBrowna654b9d82005-06-21 17:17:27 -0700328 return 0;
NeilBrown4b809912008-07-21 17:05:25 +1000329
330 bad_alignment:
NeilBrown4b809912008-07-21 17:05:25 +1000331 return -EINVAL;
NeilBrowna654b9d82005-06-21 17:17:27 -0700332}
333
NeilBrown4ad13662007-07-17 04:06:13 -0700334static void bitmap_file_kick(struct bitmap *bitmap);
NeilBrown32a76272005-06-21 17:17:14 -0700335/*
NeilBrowna654b9d82005-06-21 17:17:27 -0700336 * write out a page to a file
NeilBrown32a76272005-06-21 17:17:14 -0700337 */
NeilBrown4ad13662007-07-17 04:06:13 -0700338static void write_page(struct bitmap *bitmap, struct page *page, int wait)
NeilBrown32a76272005-06-21 17:17:14 -0700339{
NeilBrownd785a062006-06-26 00:27:48 -0700340 struct buffer_head *bh;
NeilBrown32a76272005-06-21 17:17:14 -0700341
NeilBrownf0d76d72007-07-17 04:06:12 -0700342 if (bitmap->file == NULL) {
343 switch (write_sb_page(bitmap, page, wait)) {
344 case -EINVAL:
345 bitmap->flags |= BITMAP_WRITE_ERROR;
NeilBrownf0d76d72007-07-17 04:06:12 -0700346 }
NeilBrown4ad13662007-07-17 04:06:13 -0700347 } else {
NeilBrowna654b9d82005-06-21 17:17:27 -0700348
NeilBrown4ad13662007-07-17 04:06:13 -0700349 bh = page_buffers(page);
NeilBrownc7084432006-01-06 00:20:45 -0800350
NeilBrown4ad13662007-07-17 04:06:13 -0700351 while (bh && bh->b_blocknr) {
352 atomic_inc(&bitmap->pending_writes);
353 set_buffer_locked(bh);
354 set_buffer_mapped(bh);
355 submit_bh(WRITE, bh);
356 bh = bh->b_this_page;
357 }
NeilBrown32a76272005-06-21 17:17:14 -0700358
NeilBrown4ad13662007-07-17 04:06:13 -0700359 if (wait) {
360 wait_event(bitmap->write_wait,
361 atomic_read(&bitmap->pending_writes)==0);
362 }
NeilBrown32a76272005-06-21 17:17:14 -0700363 }
NeilBrown4ad13662007-07-17 04:06:13 -0700364 if (bitmap->flags & BITMAP_WRITE_ERROR)
365 bitmap_file_kick(bitmap);
NeilBrown32a76272005-06-21 17:17:14 -0700366}
367
NeilBrownd785a062006-06-26 00:27:48 -0700368static void end_bitmap_write(struct buffer_head *bh, int uptodate)
NeilBrown32a76272005-06-21 17:17:14 -0700369{
NeilBrownd785a062006-06-26 00:27:48 -0700370 struct bitmap *bitmap = bh->b_private;
371 unsigned long flags;
372
373 if (!uptodate) {
374 spin_lock_irqsave(&bitmap->lock, flags);
375 bitmap->flags |= BITMAP_WRITE_ERROR;
376 spin_unlock_irqrestore(&bitmap->lock, flags);
377 }
378 if (atomic_dec_and_test(&bitmap->pending_writes))
379 wake_up(&bitmap->write_wait);
380}
381
382/* copied from buffer.c */
383static void
384__clear_page_buffers(struct page *page)
385{
386 ClearPagePrivate(page);
387 set_page_private(page, 0);
388 page_cache_release(page);
389}
390static void free_buffers(struct page *page)
391{
392 struct buffer_head *bh = page_buffers(page);
393
394 while (bh) {
395 struct buffer_head *next = bh->b_this_page;
396 free_buffer_head(bh);
397 bh = next;
398 }
399 __clear_page_buffers(page);
400 put_page(page);
401}
402
403/* read a page from a file.
404 * We both read the page, and attach buffers to the page to record the
405 * address of each block (using bmap). These addresses will be used
406 * to write the block later, completely bypassing the filesystem.
407 * This usage is similar to how swap files are handled, and allows us
408 * to write to a file with no concerns of memory allocation failing.
409 */
410static struct page *read_page(struct file *file, unsigned long index,
411 struct bitmap *bitmap,
412 unsigned long count)
413{
NeilBrown32a76272005-06-21 17:17:14 -0700414 struct page *page = NULL;
Josef Sipekc649bb92006-12-08 02:37:19 -0800415 struct inode *inode = file->f_path.dentry->d_inode;
NeilBrownd785a062006-06-26 00:27:48 -0700416 struct buffer_head *bh;
417 sector_t block;
NeilBrown32a76272005-06-21 17:17:14 -0700418
NeilBrown2d1f3b52006-01-06 00:20:31 -0800419 PRINTK("read bitmap file (%dB @ %Lu)\n", (int)PAGE_SIZE,
420 (unsigned long long)index << PAGE_SHIFT);
NeilBrown32a76272005-06-21 17:17:14 -0700421
NeilBrownd785a062006-06-26 00:27:48 -0700422 page = alloc_page(GFP_KERNEL);
423 if (!page)
424 page = ERR_PTR(-ENOMEM);
NeilBrown32a76272005-06-21 17:17:14 -0700425 if (IS_ERR(page))
426 goto out;
NeilBrownd785a062006-06-26 00:27:48 -0700427
NeilBrownd785a062006-06-26 00:27:48 -0700428 bh = alloc_page_buffers(page, 1<<inode->i_blkbits, 0);
429 if (!bh) {
430 put_page(page);
431 page = ERR_PTR(-ENOMEM);
432 goto out;
433 }
434 attach_page_buffers(page, bh);
435 block = index << (PAGE_SHIFT - inode->i_blkbits);
436 while (bh) {
437 if (count == 0)
438 bh->b_blocknr = 0;
439 else {
440 bh->b_blocknr = bmap(inode, block);
441 if (bh->b_blocknr == 0) {
442 /* Cannot use this file! */
443 free_buffers(page);
444 page = ERR_PTR(-EINVAL);
445 goto out;
446 }
447 bh->b_bdev = inode->i_sb->s_bdev;
448 if (count < (1<<inode->i_blkbits))
449 count = 0;
450 else
451 count -= (1<<inode->i_blkbits);
NeilBrown32a76272005-06-21 17:17:14 -0700452
NeilBrownd785a062006-06-26 00:27:48 -0700453 bh->b_end_io = end_bitmap_write;
454 bh->b_private = bitmap;
NeilBrownce25c312006-06-26 00:27:49 -0700455 atomic_inc(&bitmap->pending_writes);
456 set_buffer_locked(bh);
457 set_buffer_mapped(bh);
458 submit_bh(READ, bh);
NeilBrownd785a062006-06-26 00:27:48 -0700459 }
460 block++;
461 bh = bh->b_this_page;
462 }
NeilBrownd785a062006-06-26 00:27:48 -0700463 page->index = index;
NeilBrownce25c312006-06-26 00:27:49 -0700464
465 wait_event(bitmap->write_wait,
466 atomic_read(&bitmap->pending_writes)==0);
467 if (bitmap->flags & BITMAP_WRITE_ERROR) {
468 free_buffers(page);
469 page = ERR_PTR(-EIO);
470 }
NeilBrown32a76272005-06-21 17:17:14 -0700471out:
472 if (IS_ERR(page))
473 printk(KERN_ALERT "md: bitmap read error: (%dB @ %Lu): %ld\n",
NeilBrown2d1f3b52006-01-06 00:20:31 -0800474 (int)PAGE_SIZE,
475 (unsigned long long)index << PAGE_SHIFT,
NeilBrown32a76272005-06-21 17:17:14 -0700476 PTR_ERR(page));
477 return page;
478}
479
480/*
481 * bitmap file superblock operations
482 */
483
484/* update the event counter and sync the superblock to disk */
NeilBrown4ad13662007-07-17 04:06:13 -0700485void bitmap_update_sb(struct bitmap *bitmap)
NeilBrown32a76272005-06-21 17:17:14 -0700486{
487 bitmap_super_t *sb;
488 unsigned long flags;
489
490 if (!bitmap || !bitmap->mddev) /* no bitmap for this array */
NeilBrown4ad13662007-07-17 04:06:13 -0700491 return;
NeilBrown32a76272005-06-21 17:17:14 -0700492 spin_lock_irqsave(&bitmap->lock, flags);
493 if (!bitmap->sb_page) { /* no superblock */
494 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrown4ad13662007-07-17 04:06:13 -0700495 return;
NeilBrown32a76272005-06-21 17:17:14 -0700496 }
NeilBrown32a76272005-06-21 17:17:14 -0700497 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrownea03aff2006-01-06 00:20:34 -0800498 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0);
NeilBrown32a76272005-06-21 17:17:14 -0700499 sb->events = cpu_to_le64(bitmap->mddev->events);
Neil Browna0da84f2008-06-28 08:31:22 +1000500 if (bitmap->mddev->events < bitmap->events_cleared) {
501 /* rocking back to read-only */
502 bitmap->events_cleared = bitmap->mddev->events;
503 sb->events_cleared = cpu_to_le64(bitmap->events_cleared);
504 }
NeilBrownea03aff2006-01-06 00:20:34 -0800505 kunmap_atomic(sb, KM_USER0);
NeilBrown4ad13662007-07-17 04:06:13 -0700506 write_page(bitmap, bitmap->sb_page, 1);
NeilBrown32a76272005-06-21 17:17:14 -0700507}
508
509/* print out the bitmap file superblock */
510void bitmap_print_sb(struct bitmap *bitmap)
511{
512 bitmap_super_t *sb;
513
514 if (!bitmap || !bitmap->sb_page)
515 return;
NeilBrownea03aff2006-01-06 00:20:34 -0800516 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0);
NeilBrown32a76272005-06-21 17:17:14 -0700517 printk(KERN_DEBUG "%s: bitmap file superblock:\n", bmname(bitmap));
NeilBrowna2cff262005-06-21 17:17:20 -0700518 printk(KERN_DEBUG " magic: %08x\n", le32_to_cpu(sb->magic));
519 printk(KERN_DEBUG " version: %d\n", le32_to_cpu(sb->version));
520 printk(KERN_DEBUG " uuid: %08x.%08x.%08x.%08x\n",
NeilBrown32a76272005-06-21 17:17:14 -0700521 *(__u32 *)(sb->uuid+0),
522 *(__u32 *)(sb->uuid+4),
523 *(__u32 *)(sb->uuid+8),
524 *(__u32 *)(sb->uuid+12));
NeilBrowna2cff262005-06-21 17:17:20 -0700525 printk(KERN_DEBUG " events: %llu\n",
NeilBrown32a76272005-06-21 17:17:14 -0700526 (unsigned long long) le64_to_cpu(sb->events));
NeilBrowna2cff262005-06-21 17:17:20 -0700527 printk(KERN_DEBUG "events cleared: %llu\n",
NeilBrown32a76272005-06-21 17:17:14 -0700528 (unsigned long long) le64_to_cpu(sb->events_cleared));
NeilBrowna2cff262005-06-21 17:17:20 -0700529 printk(KERN_DEBUG " state: %08x\n", le32_to_cpu(sb->state));
530 printk(KERN_DEBUG " chunksize: %d B\n", le32_to_cpu(sb->chunksize));
531 printk(KERN_DEBUG " daemon sleep: %ds\n", le32_to_cpu(sb->daemon_sleep));
532 printk(KERN_DEBUG " sync size: %llu KB\n",
533 (unsigned long long)le64_to_cpu(sb->sync_size)/2);
NeilBrown4b6d2872005-09-09 16:23:47 -0700534 printk(KERN_DEBUG "max write behind: %d\n", le32_to_cpu(sb->write_behind));
NeilBrownea03aff2006-01-06 00:20:34 -0800535 kunmap_atomic(sb, KM_USER0);
NeilBrown32a76272005-06-21 17:17:14 -0700536}
537
538/* read the superblock from the bitmap file and initialize some bitmap fields */
539static int bitmap_read_sb(struct bitmap *bitmap)
540{
541 char *reason = NULL;
542 bitmap_super_t *sb;
NeilBrown4b6d2872005-09-09 16:23:47 -0700543 unsigned long chunksize, daemon_sleep, write_behind;
NeilBrown32a76272005-06-21 17:17:14 -0700544 unsigned long long events;
545 int err = -EINVAL;
546
547 /* page 0 is the superblock, read it... */
NeilBrownf49d5e62007-01-26 00:57:03 -0800548 if (bitmap->file) {
549 loff_t isize = i_size_read(bitmap->file->f_mapping->host);
550 int bytes = isize > PAGE_SIZE ? PAGE_SIZE : isize;
551
552 bitmap->sb_page = read_page(bitmap->file, 0, bitmap, bytes);
553 } else {
NeilBrown42a04b52009-12-14 12:49:53 +1100554 bitmap->sb_page = read_sb_page(bitmap->mddev,
555 bitmap->mddev->bitmap_info.offset,
NeilBrowna2ed9612008-12-19 16:25:01 +1100556 NULL,
557 0, sizeof(bitmap_super_t));
NeilBrowna654b9d82005-06-21 17:17:27 -0700558 }
NeilBrown32a76272005-06-21 17:17:14 -0700559 if (IS_ERR(bitmap->sb_page)) {
560 err = PTR_ERR(bitmap->sb_page);
561 bitmap->sb_page = NULL;
562 return err;
563 }
564
NeilBrownea03aff2006-01-06 00:20:34 -0800565 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0);
NeilBrown32a76272005-06-21 17:17:14 -0700566
NeilBrown32a76272005-06-21 17:17:14 -0700567 chunksize = le32_to_cpu(sb->chunksize);
NeilBrown1b04be92009-12-14 12:49:53 +1100568 daemon_sleep = le32_to_cpu(sb->daemon_sleep) * HZ;
NeilBrown4b6d2872005-09-09 16:23:47 -0700569 write_behind = le32_to_cpu(sb->write_behind);
NeilBrown32a76272005-06-21 17:17:14 -0700570
571 /* verify that the bitmap-specific fields are valid */
572 if (sb->magic != cpu_to_le32(BITMAP_MAGIC))
573 reason = "bad magic";
NeilBrownbd926c62005-11-08 21:39:32 -0800574 else if (le32_to_cpu(sb->version) < BITMAP_MAJOR_LO ||
575 le32_to_cpu(sb->version) > BITMAP_MAJOR_HI)
NeilBrown32a76272005-06-21 17:17:14 -0700576 reason = "unrecognized superblock version";
NeilBrown1187cf02009-03-31 14:27:02 +1100577 else if (chunksize < 512)
NeilBrown7dd5d342006-01-06 00:20:39 -0800578 reason = "bitmap chunksize too small";
NeilBrown32a76272005-06-21 17:17:14 -0700579 else if ((1 << ffz(~chunksize)) != chunksize)
580 reason = "bitmap chunksize not a power of 2";
NeilBrown1b04be92009-12-14 12:49:53 +1100581 else if (daemon_sleep < 1 || daemon_sleep > MAX_SCHEDULE_TIMEOUT)
NeilBrown7dd5d342006-01-06 00:20:39 -0800582 reason = "daemon sleep period out of range";
NeilBrown4b6d2872005-09-09 16:23:47 -0700583 else if (write_behind > COUNTER_MAX)
584 reason = "write-behind limit out of range (0 - 16383)";
NeilBrown32a76272005-06-21 17:17:14 -0700585 if (reason) {
586 printk(KERN_INFO "%s: invalid bitmap file superblock: %s\n",
587 bmname(bitmap), reason);
588 goto out;
589 }
590
591 /* keep the array size field of the bitmap superblock up to date */
592 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors);
593
594 if (!bitmap->mddev->persistent)
595 goto success;
596
597 /*
598 * if we have a persistent array superblock, compare the
599 * bitmap's UUID and event counter to the mddev's
600 */
601 if (memcmp(sb->uuid, bitmap->mddev->uuid, 16)) {
602 printk(KERN_INFO "%s: bitmap superblock UUID mismatch\n",
603 bmname(bitmap));
604 goto out;
605 }
606 events = le64_to_cpu(sb->events);
607 if (events < bitmap->mddev->events) {
608 printk(KERN_INFO "%s: bitmap file is out of date (%llu < %llu) "
609 "-- forcing full recovery\n", bmname(bitmap), events,
610 (unsigned long long) bitmap->mddev->events);
NeilBrown4f2e6392006-10-21 10:24:09 -0700611 sb->state |= cpu_to_le32(BITMAP_STALE);
NeilBrown32a76272005-06-21 17:17:14 -0700612 }
613success:
614 /* assign fields using values from superblock */
NeilBrown42a04b52009-12-14 12:49:53 +1100615 bitmap->mddev->bitmap_info.chunksize = chunksize;
616 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep;
NeilBrown585f0dd2005-09-09 16:23:49 -0700617 bitmap->daemon_lastrun = jiffies;
NeilBrown42a04b52009-12-14 12:49:53 +1100618 bitmap->mddev->bitmap_info.max_write_behind = write_behind;
NeilBrown4f2e6392006-10-21 10:24:09 -0700619 bitmap->flags |= le32_to_cpu(sb->state);
NeilBrownbd926c62005-11-08 21:39:32 -0800620 if (le32_to_cpu(sb->version) == BITMAP_MAJOR_HOSTENDIAN)
621 bitmap->flags |= BITMAP_HOSTENDIAN;
NeilBrown32a76272005-06-21 17:17:14 -0700622 bitmap->events_cleared = le64_to_cpu(sb->events_cleared);
NeilBrown4f2e6392006-10-21 10:24:09 -0700623 if (sb->state & cpu_to_le32(BITMAP_STALE))
NeilBrown6a079972005-09-09 16:23:44 -0700624 bitmap->events_cleared = bitmap->mddev->events;
NeilBrown32a76272005-06-21 17:17:14 -0700625 err = 0;
626out:
NeilBrownea03aff2006-01-06 00:20:34 -0800627 kunmap_atomic(sb, KM_USER0);
NeilBrown32a76272005-06-21 17:17:14 -0700628 if (err)
629 bitmap_print_sb(bitmap);
630 return err;
631}
632
633enum bitmap_mask_op {
634 MASK_SET,
635 MASK_UNSET
636};
637
NeilBrown4ad13662007-07-17 04:06:13 -0700638/* record the state of the bitmap in the superblock. Return the old value */
639static int bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits,
640 enum bitmap_mask_op op)
NeilBrown32a76272005-06-21 17:17:14 -0700641{
642 bitmap_super_t *sb;
643 unsigned long flags;
NeilBrown4ad13662007-07-17 04:06:13 -0700644 int old;
NeilBrown32a76272005-06-21 17:17:14 -0700645
646 spin_lock_irqsave(&bitmap->lock, flags);
Adrian Bunk7e317652006-03-25 03:07:51 -0800647 if (!bitmap->sb_page) { /* can't set the state */
NeilBrown32a76272005-06-21 17:17:14 -0700648 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrown4ad13662007-07-17 04:06:13 -0700649 return 0;
NeilBrown32a76272005-06-21 17:17:14 -0700650 }
NeilBrown32a76272005-06-21 17:17:14 -0700651 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrownea03aff2006-01-06 00:20:34 -0800652 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0);
NeilBrown4ad13662007-07-17 04:06:13 -0700653 old = le32_to_cpu(sb->state) & bits;
NeilBrown32a76272005-06-21 17:17:14 -0700654 switch (op) {
NeilBrown4f2e6392006-10-21 10:24:09 -0700655 case MASK_SET: sb->state |= cpu_to_le32(bits);
NeilBrown32a76272005-06-21 17:17:14 -0700656 break;
NeilBrown4f2e6392006-10-21 10:24:09 -0700657 case MASK_UNSET: sb->state &= cpu_to_le32(~bits);
NeilBrown32a76272005-06-21 17:17:14 -0700658 break;
659 default: BUG();
660 }
NeilBrownea03aff2006-01-06 00:20:34 -0800661 kunmap_atomic(sb, KM_USER0);
NeilBrown4ad13662007-07-17 04:06:13 -0700662 return old;
NeilBrown32a76272005-06-21 17:17:14 -0700663}
664
665/*
666 * general bitmap file operations
667 */
668
669/* calculate the index of the page that contains this bit */
670static inline unsigned long file_page_index(unsigned long chunk)
671{
672 return CHUNK_BIT_OFFSET(chunk) >> PAGE_BIT_SHIFT;
673}
674
675/* calculate the (bit) offset of this bit within a page */
676static inline unsigned long file_page_offset(unsigned long chunk)
677{
678 return CHUNK_BIT_OFFSET(chunk) & (PAGE_BITS - 1);
679}
680
681/*
682 * return a pointer to the page in the filemap that contains the given bit
683 *
684 * this lookup is complicated by the fact that the bitmap sb might be exactly
685 * 1 page (e.g., x86) or less than 1 page -- so the bitmap might start on page
686 * 0 or page 1
687 */
688static inline struct page *filemap_get_page(struct bitmap *bitmap,
689 unsigned long chunk)
690{
Paul Clements9b1d1da2006-10-03 01:15:49 -0700691 if (file_page_index(chunk) >= bitmap->file_pages) return NULL;
NeilBrown32a76272005-06-21 17:17:14 -0700692 return bitmap->filemap[file_page_index(chunk) - file_page_index(0)];
693}
694
695
696static void bitmap_file_unmap(struct bitmap *bitmap)
697{
698 struct page **map, *sb_page;
699 unsigned long *attr;
700 int pages;
701 unsigned long flags;
702
703 spin_lock_irqsave(&bitmap->lock, flags);
704 map = bitmap->filemap;
705 bitmap->filemap = NULL;
706 attr = bitmap->filemap_attr;
707 bitmap->filemap_attr = NULL;
708 pages = bitmap->file_pages;
709 bitmap->file_pages = 0;
710 sb_page = bitmap->sb_page;
711 bitmap->sb_page = NULL;
712 spin_unlock_irqrestore(&bitmap->lock, flags);
713
714 while (pages--)
715 if (map[pages]->index != 0) /* 0 is sb_page, release it below */
NeilBrownd785a062006-06-26 00:27:48 -0700716 free_buffers(map[pages]);
NeilBrown32a76272005-06-21 17:17:14 -0700717 kfree(map);
718 kfree(attr);
719
NeilBrownd785a062006-06-26 00:27:48 -0700720 if (sb_page)
721 free_buffers(sb_page);
NeilBrown32a76272005-06-21 17:17:14 -0700722}
723
724static void bitmap_file_put(struct bitmap *bitmap)
725{
726 struct file *file;
NeilBrown32a76272005-06-21 17:17:14 -0700727 unsigned long flags;
728
729 spin_lock_irqsave(&bitmap->lock, flags);
730 file = bitmap->file;
731 bitmap->file = NULL;
732 spin_unlock_irqrestore(&bitmap->lock, flags);
733
NeilBrownd785a062006-06-26 00:27:48 -0700734 if (file)
735 wait_event(bitmap->write_wait,
736 atomic_read(&bitmap->pending_writes)==0);
NeilBrown32a76272005-06-21 17:17:14 -0700737 bitmap_file_unmap(bitmap);
738
NeilBrownd785a062006-06-26 00:27:48 -0700739 if (file) {
Josef Sipekc649bb92006-12-08 02:37:19 -0800740 struct inode *inode = file->f_path.dentry->d_inode;
Andrew Mortonfc0ecff2007-02-10 01:45:39 -0800741 invalidate_mapping_pages(inode->i_mapping, 0, -1);
NeilBrown32a76272005-06-21 17:17:14 -0700742 fput(file);
NeilBrownd785a062006-06-26 00:27:48 -0700743 }
NeilBrown32a76272005-06-21 17:17:14 -0700744}
745
746
747/*
748 * bitmap_file_kick - if an error occurs while manipulating the bitmap file
749 * then it is no longer reliable, so we stop using it and we mark the file
750 * as failed in the superblock
751 */
752static void bitmap_file_kick(struct bitmap *bitmap)
753{
754 char *path, *ptr = NULL;
755
NeilBrown4ad13662007-07-17 04:06:13 -0700756 if (bitmap_mask_state(bitmap, BITMAP_STALE, MASK_SET) == 0) {
757 bitmap_update_sb(bitmap);
NeilBrown32a76272005-06-21 17:17:14 -0700758
NeilBrown4ad13662007-07-17 04:06:13 -0700759 if (bitmap->file) {
760 path = kmalloc(PAGE_SIZE, GFP_KERNEL);
761 if (path)
Christoph Hellwig6bcfd602008-05-23 13:04:34 -0700762 ptr = d_path(&bitmap->file->f_path, path,
763 PAGE_SIZE);
764
NeilBrown32a76272005-06-21 17:17:14 -0700765
NeilBrown4ad13662007-07-17 04:06:13 -0700766 printk(KERN_ALERT
767 "%s: kicking failed bitmap file %s from array!\n",
Christoph Hellwig6bcfd602008-05-23 13:04:34 -0700768 bmname(bitmap), IS_ERR(ptr) ? "" : ptr);
NeilBrown32a76272005-06-21 17:17:14 -0700769
NeilBrown4ad13662007-07-17 04:06:13 -0700770 kfree(path);
771 } else
772 printk(KERN_ALERT
773 "%s: disabling internal bitmap due to errors\n",
774 bmname(bitmap));
NeilBrowna654b9d82005-06-21 17:17:27 -0700775 }
NeilBrown32a76272005-06-21 17:17:14 -0700776
777 bitmap_file_put(bitmap);
778
779 return;
780}
781
782enum bitmap_page_attr {
NeilBrowne16b68b2006-06-26 00:27:45 -0700783 BITMAP_PAGE_DIRTY = 0, // there are set bits that need to be synced
784 BITMAP_PAGE_CLEAN = 1, // there are bits that might need to be cleared
785 BITMAP_PAGE_NEEDWRITE=2, // there are cleared bits that need to be synced
NeilBrown32a76272005-06-21 17:17:14 -0700786};
787
788static inline void set_page_attr(struct bitmap *bitmap, struct page *page,
789 enum bitmap_page_attr attr)
790{
NeilBrowne16b68b2006-06-26 00:27:45 -0700791 __set_bit((page->index<<2) + attr, bitmap->filemap_attr);
NeilBrown32a76272005-06-21 17:17:14 -0700792}
793
794static inline void clear_page_attr(struct bitmap *bitmap, struct page *page,
795 enum bitmap_page_attr attr)
796{
NeilBrowne16b68b2006-06-26 00:27:45 -0700797 __clear_bit((page->index<<2) + attr, bitmap->filemap_attr);
NeilBrown32a76272005-06-21 17:17:14 -0700798}
799
NeilBrownec7a3192006-06-26 00:27:45 -0700800static inline unsigned long test_page_attr(struct bitmap *bitmap, struct page *page,
801 enum bitmap_page_attr attr)
NeilBrown32a76272005-06-21 17:17:14 -0700802{
NeilBrowne16b68b2006-06-26 00:27:45 -0700803 return test_bit((page->index<<2) + attr, bitmap->filemap_attr);
NeilBrown32a76272005-06-21 17:17:14 -0700804}
805
806/*
807 * bitmap_file_set_bit -- called before performing a write to the md device
808 * to set (and eventually sync) a particular bit in the bitmap file
809 *
810 * we set the bit immediately, then we record the page number so that
811 * when an unplug occurs, we can flush the dirty pages out to disk
812 */
813static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
814{
815 unsigned long bit;
816 struct page *page;
817 void *kaddr;
818 unsigned long chunk = block >> CHUNK_BLOCK_SHIFT(bitmap);
819
NeilBrowna654b9d82005-06-21 17:17:27 -0700820 if (!bitmap->filemap) {
NeilBrown32a76272005-06-21 17:17:14 -0700821 return;
822 }
823
824 page = filemap_get_page(bitmap, chunk);
Paul Clements9b1d1da2006-10-03 01:15:49 -0700825 if (!page) return;
NeilBrown32a76272005-06-21 17:17:14 -0700826 bit = file_page_offset(chunk);
827
NeilBrown32a76272005-06-21 17:17:14 -0700828 /* set the bit */
829 kaddr = kmap_atomic(page, KM_USER0);
NeilBrownbd926c62005-11-08 21:39:32 -0800830 if (bitmap->flags & BITMAP_HOSTENDIAN)
831 set_bit(bit, kaddr);
832 else
833 ext2_set_bit(bit, kaddr);
NeilBrown32a76272005-06-21 17:17:14 -0700834 kunmap_atomic(kaddr, KM_USER0);
835 PRINTK("set file bit %lu page %lu\n", bit, page->index);
836
837 /* record page number so it gets flushed to disk when unplug occurs */
838 set_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
839
840}
841
842/* this gets called when the md device is ready to unplug its underlying
843 * (slave) device queues -- before we let any writes go down, we need to
844 * sync the dirty pages of the bitmap file to disk */
NeilBrown4ad13662007-07-17 04:06:13 -0700845void bitmap_unplug(struct bitmap *bitmap)
NeilBrown32a76272005-06-21 17:17:14 -0700846{
NeilBrownec7a3192006-06-26 00:27:45 -0700847 unsigned long i, flags;
848 int dirty, need_write;
NeilBrown32a76272005-06-21 17:17:14 -0700849 struct page *page;
850 int wait = 0;
851
852 if (!bitmap)
NeilBrown4ad13662007-07-17 04:06:13 -0700853 return;
NeilBrown32a76272005-06-21 17:17:14 -0700854
855 /* look at each page to see if there are any set bits that need to be
856 * flushed out to disk */
857 for (i = 0; i < bitmap->file_pages; i++) {
858 spin_lock_irqsave(&bitmap->lock, flags);
NeilBrowna654b9d82005-06-21 17:17:27 -0700859 if (!bitmap->filemap) {
NeilBrown32a76272005-06-21 17:17:14 -0700860 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrown4ad13662007-07-17 04:06:13 -0700861 return;
NeilBrown32a76272005-06-21 17:17:14 -0700862 }
863 page = bitmap->filemap[i];
NeilBrownec7a3192006-06-26 00:27:45 -0700864 dirty = test_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
865 need_write = test_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
NeilBrown32a76272005-06-21 17:17:14 -0700866 clear_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
867 clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
NeilBrownec7a3192006-06-26 00:27:45 -0700868 if (dirty)
NeilBrown32a76272005-06-21 17:17:14 -0700869 wait = 1;
870 spin_unlock_irqrestore(&bitmap->lock, flags);
871
NeilBrownd785a062006-06-26 00:27:48 -0700872 if (dirty | need_write)
NeilBrown4ad13662007-07-17 04:06:13 -0700873 write_page(bitmap, page, 0);
NeilBrown32a76272005-06-21 17:17:14 -0700874 }
875 if (wait) { /* if any writes were performed, we need to wait on them */
NeilBrown0b79ccf2006-06-26 00:27:44 -0700876 if (bitmap->file)
NeilBrownd785a062006-06-26 00:27:48 -0700877 wait_event(bitmap->write_wait,
878 atomic_read(&bitmap->pending_writes)==0);
NeilBrown0b79ccf2006-06-26 00:27:44 -0700879 else
NeilBrowna9701a32005-11-08 21:39:34 -0800880 md_super_wait(bitmap->mddev);
NeilBrown32a76272005-06-21 17:17:14 -0700881 }
NeilBrownd785a062006-06-26 00:27:48 -0700882 if (bitmap->flags & BITMAP_WRITE_ERROR)
883 bitmap_file_kick(bitmap);
NeilBrown32a76272005-06-21 17:17:14 -0700884}
885
NeilBrown6a079972005-09-09 16:23:44 -0700886static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
NeilBrown32a76272005-06-21 17:17:14 -0700887/* * bitmap_init_from_disk -- called at bitmap_create time to initialize
888 * the in-memory bitmap from the on-disk bitmap -- also, sets up the
889 * memory mapping of the bitmap file
890 * Special cases:
891 * if there's no bitmap file, or if the bitmap file had been
892 * previously kicked from the array, we mark all the bits as
893 * 1's in order to cause a full resync.
NeilBrown6a079972005-09-09 16:23:44 -0700894 *
895 * We ignore all bits for sectors that end earlier than 'start'.
896 * This is used when reading an out-of-date bitmap...
NeilBrown32a76272005-06-21 17:17:14 -0700897 */
NeilBrown6a079972005-09-09 16:23:44 -0700898static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
NeilBrown32a76272005-06-21 17:17:14 -0700899{
900 unsigned long i, chunks, index, oldindex, bit;
901 struct page *page = NULL, *oldpage = NULL;
902 unsigned long num_pages, bit_cnt = 0;
903 struct file *file;
NeilBrownd785a062006-06-26 00:27:48 -0700904 unsigned long bytes, offset;
NeilBrown32a76272005-06-21 17:17:14 -0700905 int outofdate;
906 int ret = -ENOSPC;
NeilBrownea03aff2006-01-06 00:20:34 -0800907 void *paddr;
NeilBrown32a76272005-06-21 17:17:14 -0700908
909 chunks = bitmap->chunks;
910 file = bitmap->file;
911
NeilBrown42a04b52009-12-14 12:49:53 +1100912 BUG_ON(!file && !bitmap->mddev->bitmap_info.offset);
NeilBrown32a76272005-06-21 17:17:14 -0700913
Olaf Hering44456d32005-07-27 11:45:17 -0700914#ifdef INJECT_FAULTS_3
NeilBrown32a76272005-06-21 17:17:14 -0700915 outofdate = 1;
916#else
917 outofdate = bitmap->flags & BITMAP_STALE;
918#endif
919 if (outofdate)
920 printk(KERN_INFO "%s: bitmap file is out of date, doing full "
921 "recovery\n", bmname(bitmap));
922
923 bytes = (chunks + 7) / 8;
NeilBrownbc7f77d2005-06-21 17:17:17 -0700924
NeilBrowncdbb4cc2005-06-21 17:17:18 -0700925 num_pages = (bytes + sizeof(bitmap_super_t) + PAGE_SIZE - 1) / PAGE_SIZE;
NeilBrownbc7f77d2005-06-21 17:17:17 -0700926
NeilBrowna654b9d82005-06-21 17:17:27 -0700927 if (file && i_size_read(file->f_mapping->host) < bytes + sizeof(bitmap_super_t)) {
NeilBrown32a76272005-06-21 17:17:14 -0700928 printk(KERN_INFO "%s: bitmap file too short %lu < %lu\n",
929 bmname(bitmap),
930 (unsigned long) i_size_read(file->f_mapping->host),
931 bytes + sizeof(bitmap_super_t));
NeilBrown4ad13662007-07-17 04:06:13 -0700932 goto err;
NeilBrown32a76272005-06-21 17:17:14 -0700933 }
NeilBrownbc7f77d2005-06-21 17:17:17 -0700934
935 ret = -ENOMEM;
936
NeilBrown32a76272005-06-21 17:17:14 -0700937 bitmap->filemap = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
NeilBrownbc7f77d2005-06-21 17:17:17 -0700938 if (!bitmap->filemap)
NeilBrown4ad13662007-07-17 04:06:13 -0700939 goto err;
NeilBrown32a76272005-06-21 17:17:14 -0700940
NeilBrowne16b68b2006-06-26 00:27:45 -0700941 /* We need 4 bits per page, rounded up to a multiple of sizeof(unsigned long) */
942 bitmap->filemap_attr = kzalloc(
Neil Brown505fa2c2007-04-11 23:28:44 -0700943 roundup( DIV_ROUND_UP(num_pages*4, 8), sizeof(unsigned long)),
NeilBrowne16b68b2006-06-26 00:27:45 -0700944 GFP_KERNEL);
NeilBrownbc7f77d2005-06-21 17:17:17 -0700945 if (!bitmap->filemap_attr)
NeilBrown4ad13662007-07-17 04:06:13 -0700946 goto err;
NeilBrown32a76272005-06-21 17:17:14 -0700947
NeilBrown32a76272005-06-21 17:17:14 -0700948 oldindex = ~0L;
949
950 for (i = 0; i < chunks; i++) {
NeilBrownbd926c62005-11-08 21:39:32 -0800951 int b;
NeilBrown32a76272005-06-21 17:17:14 -0700952 index = file_page_index(i);
953 bit = file_page_offset(i);
954 if (index != oldindex) { /* this is a new page, read it in */
NeilBrownd785a062006-06-26 00:27:48 -0700955 int count;
NeilBrown32a76272005-06-21 17:17:14 -0700956 /* unmap the old page, we're done with it */
NeilBrownd785a062006-06-26 00:27:48 -0700957 if (index == num_pages-1)
NeilBrownf49d5e62007-01-26 00:57:03 -0800958 count = bytes + sizeof(bitmap_super_t)
959 - index * PAGE_SIZE;
NeilBrownd785a062006-06-26 00:27:48 -0700960 else
961 count = PAGE_SIZE;
NeilBrown32a76272005-06-21 17:17:14 -0700962 if (index == 0) {
963 /*
964 * if we're here then the superblock page
965 * contains some bits (PAGE_SIZE != sizeof sb)
966 * we've already read it in, so just use it
967 */
968 page = bitmap->sb_page;
969 offset = sizeof(bitmap_super_t);
NeilBrown53845272009-01-09 08:31:05 +1100970 if (!file)
971 read_sb_page(bitmap->mddev,
NeilBrown42a04b52009-12-14 12:49:53 +1100972 bitmap->mddev->bitmap_info.offset,
NeilBrown53845272009-01-09 08:31:05 +1100973 page,
974 index, count);
NeilBrowna654b9d82005-06-21 17:17:27 -0700975 } else if (file) {
NeilBrownd785a062006-06-26 00:27:48 -0700976 page = read_page(file, index, bitmap, count);
NeilBrowna654b9d82005-06-21 17:17:27 -0700977 offset = 0;
978 } else {
NeilBrown42a04b52009-12-14 12:49:53 +1100979 page = read_sb_page(bitmap->mddev,
980 bitmap->mddev->bitmap_info.offset,
NeilBrowna2ed9612008-12-19 16:25:01 +1100981 NULL,
982 index, count);
NeilBrown32a76272005-06-21 17:17:14 -0700983 offset = 0;
984 }
NeilBrowna654b9d82005-06-21 17:17:27 -0700985 if (IS_ERR(page)) { /* read error */
986 ret = PTR_ERR(page);
NeilBrown4ad13662007-07-17 04:06:13 -0700987 goto err;
NeilBrowna654b9d82005-06-21 17:17:27 -0700988 }
989
NeilBrown32a76272005-06-21 17:17:14 -0700990 oldindex = index;
991 oldpage = page;
NeilBrown32a76272005-06-21 17:17:14 -0700992
NeilBrownb74fd282009-05-07 12:47:19 +1000993 bitmap->filemap[bitmap->file_pages++] = page;
994 bitmap->last_page_size = count;
995
NeilBrown32a76272005-06-21 17:17:14 -0700996 if (outofdate) {
997 /*
998 * if bitmap is out of date, dirty the
999 * whole page and write it out
1000 */
NeilBrownea03aff2006-01-06 00:20:34 -08001001 paddr = kmap_atomic(page, KM_USER0);
1002 memset(paddr + offset, 0xff,
NeilBrown6a079972005-09-09 16:23:44 -07001003 PAGE_SIZE - offset);
NeilBrownea03aff2006-01-06 00:20:34 -08001004 kunmap_atomic(paddr, KM_USER0);
NeilBrown4ad13662007-07-17 04:06:13 -07001005 write_page(bitmap, page, 1);
1006
1007 ret = -EIO;
NeilBrownb74fd282009-05-07 12:47:19 +10001008 if (bitmap->flags & BITMAP_WRITE_ERROR)
NeilBrown4ad13662007-07-17 04:06:13 -07001009 goto err;
NeilBrown32a76272005-06-21 17:17:14 -07001010 }
NeilBrown32a76272005-06-21 17:17:14 -07001011 }
NeilBrownea03aff2006-01-06 00:20:34 -08001012 paddr = kmap_atomic(page, KM_USER0);
NeilBrownbd926c62005-11-08 21:39:32 -08001013 if (bitmap->flags & BITMAP_HOSTENDIAN)
NeilBrownea03aff2006-01-06 00:20:34 -08001014 b = test_bit(bit, paddr);
NeilBrownbd926c62005-11-08 21:39:32 -08001015 else
NeilBrownea03aff2006-01-06 00:20:34 -08001016 b = ext2_test_bit(bit, paddr);
1017 kunmap_atomic(paddr, KM_USER0);
NeilBrownbd926c62005-11-08 21:39:32 -08001018 if (b) {
NeilBrown32a76272005-06-21 17:17:14 -07001019 /* if the disk bit is set, set the memory bit */
NeilBrowndb305e52009-05-07 12:49:06 +10001020 int needed = ((sector_t)(i+1) << (CHUNK_BLOCK_SHIFT(bitmap))
1021 >= start);
1022 bitmap_set_memory_bits(bitmap,
1023 (sector_t)i << CHUNK_BLOCK_SHIFT(bitmap),
1024 needed);
NeilBrown32a76272005-06-21 17:17:14 -07001025 bit_cnt++;
NeilBrown6a079972005-09-09 16:23:44 -07001026 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
NeilBrown32a76272005-06-21 17:17:14 -07001027 }
NeilBrown32a76272005-06-21 17:17:14 -07001028 }
1029
1030 /* everything went OK */
1031 ret = 0;
1032 bitmap_mask_state(bitmap, BITMAP_STALE, MASK_UNSET);
1033
NeilBrown32a76272005-06-21 17:17:14 -07001034 if (bit_cnt) { /* Kick recovery if any bits were set */
1035 set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery);
1036 md_wakeup_thread(bitmap->mddev->thread);
1037 }
1038
NeilBrown32a76272005-06-21 17:17:14 -07001039 printk(KERN_INFO "%s: bitmap initialized from disk: "
NeilBrown4ad13662007-07-17 04:06:13 -07001040 "read %lu/%lu pages, set %lu bits\n",
1041 bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt);
NeilBrown32a76272005-06-21 17:17:14 -07001042
NeilBrown4ad13662007-07-17 04:06:13 -07001043 return 0;
1044
1045 err:
1046 printk(KERN_INFO "%s: bitmap initialisation failed: %d\n",
1047 bmname(bitmap), ret);
NeilBrown32a76272005-06-21 17:17:14 -07001048 return ret;
1049}
1050
NeilBrowna654b9d82005-06-21 17:17:27 -07001051void bitmap_write_all(struct bitmap *bitmap)
1052{
1053 /* We don't actually write all bitmap blocks here,
1054 * just flag them as needing to be written
1055 */
NeilBrownec7a3192006-06-26 00:27:45 -07001056 int i;
NeilBrowna654b9d82005-06-21 17:17:27 -07001057
NeilBrownec7a3192006-06-26 00:27:45 -07001058 for (i=0; i < bitmap->file_pages; i++)
1059 set_page_attr(bitmap, bitmap->filemap[i],
1060 BITMAP_PAGE_NEEDWRITE);
NeilBrowna654b9d82005-06-21 17:17:27 -07001061}
1062
NeilBrown32a76272005-06-21 17:17:14 -07001063
1064static void bitmap_count_page(struct bitmap *bitmap, sector_t offset, int inc)
1065{
1066 sector_t chunk = offset >> CHUNK_BLOCK_SHIFT(bitmap);
1067 unsigned long page = chunk >> PAGE_COUNTER_SHIFT;
1068 bitmap->bp[page].count += inc;
1069/*
1070 if (page == 0) printk("count page 0, offset %llu: %d gives %d\n",
1071 (unsigned long long)offset, inc, bitmap->bp[page].count);
1072*/
1073 bitmap_checkfree(bitmap, page);
1074}
1075static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
1076 sector_t offset, int *blocks,
1077 int create);
1078
1079/*
1080 * bitmap daemon -- periodically wakes up to clean bits and flush pages
1081 * out to disk
1082 */
1083
NeilBrownaa5cbd12009-12-14 12:49:46 +11001084void bitmap_daemon_work(mddev_t *mddev)
NeilBrown32a76272005-06-21 17:17:14 -07001085{
NeilBrownaa5cbd12009-12-14 12:49:46 +11001086 struct bitmap *bitmap;
NeilBrownaa3163f2005-06-21 17:17:22 -07001087 unsigned long j;
NeilBrown32a76272005-06-21 17:17:14 -07001088 unsigned long flags;
1089 struct page *page = NULL, *lastpage = NULL;
NeilBrown32a76272005-06-21 17:17:14 -07001090 int blocks;
NeilBrownea03aff2006-01-06 00:20:34 -08001091 void *paddr;
NeilBrown32a76272005-06-21 17:17:14 -07001092
NeilBrownaa5cbd12009-12-14 12:49:46 +11001093 /* Use a mutex to guard daemon_work against
1094 * bitmap_destroy.
1095 */
NeilBrownc3d97142009-12-14 12:49:52 +11001096 mutex_lock(&mddev->bitmap_info.mutex);
NeilBrownaa5cbd12009-12-14 12:49:46 +11001097 bitmap = mddev->bitmap;
1098 if (bitmap == NULL) {
NeilBrownc3d97142009-12-14 12:49:52 +11001099 mutex_unlock(&mddev->bitmap_info.mutex);
NeilBrown4ad13662007-07-17 04:06:13 -07001100 return;
NeilBrownaa5cbd12009-12-14 12:49:46 +11001101 }
NeilBrown42a04b52009-12-14 12:49:53 +11001102 if (time_before(jiffies, bitmap->daemon_lastrun
NeilBrown1b04be92009-12-14 12:49:53 +11001103 + bitmap->mddev->bitmap_info.daemon_sleep))
NeilBrown7be3dfe2008-03-10 11:43:48 -07001104 goto done;
1105
NeilBrown32a76272005-06-21 17:17:14 -07001106 bitmap->daemon_lastrun = jiffies;
NeilBrown8311c292008-03-04 14:29:30 -08001107 if (bitmap->allclean) {
1108 bitmap->mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
NeilBrownaa5cbd12009-12-14 12:49:46 +11001109 goto done;
NeilBrown8311c292008-03-04 14:29:30 -08001110 }
1111 bitmap->allclean = 1;
NeilBrown32a76272005-06-21 17:17:14 -07001112
NeilBrownbe512692009-05-26 09:41:17 +10001113 spin_lock_irqsave(&bitmap->lock, flags);
NeilBrown32a76272005-06-21 17:17:14 -07001114 for (j = 0; j < bitmap->chunks; j++) {
1115 bitmap_counter_t *bmc;
NeilBrownbe512692009-05-26 09:41:17 +10001116 if (!bitmap->filemap)
NeilBrown32a76272005-06-21 17:17:14 -07001117 /* error or shutdown */
NeilBrown32a76272005-06-21 17:17:14 -07001118 break;
NeilBrown32a76272005-06-21 17:17:14 -07001119
1120 page = filemap_get_page(bitmap, j);
NeilBrown32a76272005-06-21 17:17:14 -07001121
1122 if (page != lastpage) {
NeilBrownaa3163f2005-06-21 17:17:22 -07001123 /* skip this page unless it's marked as needing cleaning */
NeilBrownec7a3192006-06-26 00:27:45 -07001124 if (!test_page_attr(bitmap, page, BITMAP_PAGE_CLEAN)) {
1125 int need_write = test_page_attr(bitmap, page,
1126 BITMAP_PAGE_NEEDWRITE);
NeilBrowna647e4b2006-06-26 00:27:46 -07001127 if (need_write)
NeilBrownaa3163f2005-06-21 17:17:22 -07001128 clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
NeilBrowna647e4b2006-06-26 00:27:46 -07001129
NeilBrownaa3163f2005-06-21 17:17:22 -07001130 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrown8311c292008-03-04 14:29:30 -08001131 if (need_write) {
NeilBrown4ad13662007-07-17 04:06:13 -07001132 write_page(bitmap, page, 0);
NeilBrown8311c292008-03-04 14:29:30 -08001133 bitmap->allclean = 0;
1134 }
NeilBrownbe512692009-05-26 09:41:17 +10001135 spin_lock_irqsave(&bitmap->lock, flags);
1136 j |= (PAGE_BITS - 1);
NeilBrownaa3163f2005-06-21 17:17:22 -07001137 continue;
1138 }
1139
NeilBrown32a76272005-06-21 17:17:14 -07001140 /* grab the new page, sync and release the old */
NeilBrown32a76272005-06-21 17:17:14 -07001141 if (lastpage != NULL) {
NeilBrownec7a3192006-06-26 00:27:45 -07001142 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) {
NeilBrown32a76272005-06-21 17:17:14 -07001143 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1144 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrown4ad13662007-07-17 04:06:13 -07001145 write_page(bitmap, lastpage, 0);
NeilBrown32a76272005-06-21 17:17:14 -07001146 } else {
1147 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1148 spin_unlock_irqrestore(&bitmap->lock, flags);
1149 }
NeilBrown32a76272005-06-21 17:17:14 -07001150 } else
1151 spin_unlock_irqrestore(&bitmap->lock, flags);
1152 lastpage = page;
Neil Browna0da84f2008-06-28 08:31:22 +10001153
1154 /* We are possibly going to clear some bits, so make
1155 * sure that events_cleared is up-to-date.
1156 */
1157 if (bitmap->need_sync) {
1158 bitmap_super_t *sb;
1159 bitmap->need_sync = 0;
1160 sb = kmap_atomic(bitmap->sb_page, KM_USER0);
1161 sb->events_cleared =
1162 cpu_to_le64(bitmap->events_cleared);
1163 kunmap_atomic(sb, KM_USER0);
1164 write_page(bitmap, bitmap->sb_page, 1);
1165 }
NeilBrown32a76272005-06-21 17:17:14 -07001166 spin_lock_irqsave(&bitmap->lock, flags);
1167 clear_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
1168 }
NeilBrowndb305e52009-05-07 12:49:06 +10001169 bmc = bitmap_get_counter(bitmap,
1170 (sector_t)j << CHUNK_BLOCK_SHIFT(bitmap),
1171 &blocks, 0);
NeilBrown32a76272005-06-21 17:17:14 -07001172 if (bmc) {
1173/*
1174 if (j < 100) printk("bitmap: j=%lu, *bmc = 0x%x\n", j, *bmc);
1175*/
NeilBrown8311c292008-03-04 14:29:30 -08001176 if (*bmc)
1177 bitmap->allclean = 0;
1178
NeilBrown32a76272005-06-21 17:17:14 -07001179 if (*bmc == 2) {
1180 *bmc=1; /* maybe clear the bit next time */
1181 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
1182 } else if (*bmc == 1) {
1183 /* we can clear the bit */
1184 *bmc = 0;
NeilBrowndb305e52009-05-07 12:49:06 +10001185 bitmap_count_page(bitmap,
1186 (sector_t)j << CHUNK_BLOCK_SHIFT(bitmap),
NeilBrown32a76272005-06-21 17:17:14 -07001187 -1);
1188
1189 /* clear the bit */
NeilBrownea03aff2006-01-06 00:20:34 -08001190 paddr = kmap_atomic(page, KM_USER0);
NeilBrownbd926c62005-11-08 21:39:32 -08001191 if (bitmap->flags & BITMAP_HOSTENDIAN)
NeilBrownea03aff2006-01-06 00:20:34 -08001192 clear_bit(file_page_offset(j), paddr);
NeilBrownbd926c62005-11-08 21:39:32 -08001193 else
NeilBrownea03aff2006-01-06 00:20:34 -08001194 ext2_clear_bit(file_page_offset(j), paddr);
1195 kunmap_atomic(paddr, KM_USER0);
NeilBrown32a76272005-06-21 17:17:14 -07001196 }
NeilBrownbe512692009-05-26 09:41:17 +10001197 } else
1198 j |= PAGE_COUNTER_MASK;
NeilBrown32a76272005-06-21 17:17:14 -07001199 }
NeilBrownbe512692009-05-26 09:41:17 +10001200 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrown32a76272005-06-21 17:17:14 -07001201
1202 /* now sync the final page */
1203 if (lastpage != NULL) {
NeilBrown32a76272005-06-21 17:17:14 -07001204 spin_lock_irqsave(&bitmap->lock, flags);
NeilBrownec7a3192006-06-26 00:27:45 -07001205 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) {
NeilBrown32a76272005-06-21 17:17:14 -07001206 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1207 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrown4ad13662007-07-17 04:06:13 -07001208 write_page(bitmap, lastpage, 0);
NeilBrown32a76272005-06-21 17:17:14 -07001209 } else {
1210 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1211 spin_unlock_irqrestore(&bitmap->lock, flags);
1212 }
NeilBrown32a76272005-06-21 17:17:14 -07001213 }
1214
NeilBrown7be3dfe2008-03-10 11:43:48 -07001215 done:
NeilBrown8311c292008-03-04 14:29:30 -08001216 if (bitmap->allclean == 0)
NeilBrown42a04b52009-12-14 12:49:53 +11001217 bitmap->mddev->thread->timeout =
NeilBrown1b04be92009-12-14 12:49:53 +11001218 bitmap->mddev->bitmap_info.daemon_sleep;
NeilBrownc3d97142009-12-14 12:49:52 +11001219 mutex_unlock(&mddev->bitmap_info.mutex);
NeilBrown32a76272005-06-21 17:17:14 -07001220}
1221
NeilBrown32a76272005-06-21 17:17:14 -07001222static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
1223 sector_t offset, int *blocks,
1224 int create)
NeilBrownee305ac2009-09-23 18:06:44 +10001225__releases(bitmap->lock)
1226__acquires(bitmap->lock)
NeilBrown32a76272005-06-21 17:17:14 -07001227{
1228 /* If 'create', we might release the lock and reclaim it.
1229 * The lock must have been taken with interrupts enabled.
1230 * If !create, we don't release the lock.
1231 */
1232 sector_t chunk = offset >> CHUNK_BLOCK_SHIFT(bitmap);
1233 unsigned long page = chunk >> PAGE_COUNTER_SHIFT;
1234 unsigned long pageoff = (chunk & PAGE_COUNTER_MASK) << COUNTER_BYTE_SHIFT;
1235 sector_t csize;
1236
1237 if (bitmap_checkpage(bitmap, page, create) < 0) {
1238 csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap));
1239 *blocks = csize - (offset & (csize- 1));
1240 return NULL;
1241 }
1242 /* now locked ... */
1243
1244 if (bitmap->bp[page].hijacked) { /* hijacked pointer */
1245 /* should we use the first or second counter field
1246 * of the hijacked pointer? */
1247 int hi = (pageoff > PAGE_COUNTER_MASK);
1248 csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap) +
1249 PAGE_COUNTER_SHIFT - 1);
1250 *blocks = csize - (offset & (csize- 1));
1251 return &((bitmap_counter_t *)
1252 &bitmap->bp[page].map)[hi];
1253 } else { /* page is allocated */
1254 csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap));
1255 *blocks = csize - (offset & (csize- 1));
1256 return (bitmap_counter_t *)
1257 &(bitmap->bp[page].map[pageoff]);
1258 }
1259}
1260
NeilBrown4b6d2872005-09-09 16:23:47 -07001261int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind)
NeilBrown32a76272005-06-21 17:17:14 -07001262{
1263 if (!bitmap) return 0;
NeilBrown4b6d2872005-09-09 16:23:47 -07001264
1265 if (behind) {
1266 atomic_inc(&bitmap->behind_writes);
1267 PRINTK(KERN_DEBUG "inc write-behind count %d/%d\n",
1268 atomic_read(&bitmap->behind_writes), bitmap->max_write_behind);
1269 }
1270
NeilBrown32a76272005-06-21 17:17:14 -07001271 while (sectors) {
1272 int blocks;
1273 bitmap_counter_t *bmc;
1274
1275 spin_lock_irq(&bitmap->lock);
1276 bmc = bitmap_get_counter(bitmap, offset, &blocks, 1);
1277 if (!bmc) {
1278 spin_unlock_irq(&bitmap->lock);
1279 return 0;
1280 }
1281
Neil Brownda6e1a32007-02-08 14:20:37 -08001282 if (unlikely((*bmc & COUNTER_MAX) == COUNTER_MAX)) {
1283 DEFINE_WAIT(__wait);
1284 /* note that it is safe to do the prepare_to_wait
1285 * after the test as long as we do it before dropping
1286 * the spinlock.
1287 */
1288 prepare_to_wait(&bitmap->overflow_wait, &__wait,
1289 TASK_UNINTERRUPTIBLE);
1290 spin_unlock_irq(&bitmap->lock);
Alan D. Brunelle2ad8b1e2007-11-07 14:26:56 -05001291 blk_unplug(bitmap->mddev->queue);
Neil Brownda6e1a32007-02-08 14:20:37 -08001292 schedule();
1293 finish_wait(&bitmap->overflow_wait, &__wait);
1294 continue;
1295 }
1296
NeilBrown32a76272005-06-21 17:17:14 -07001297 switch(*bmc) {
1298 case 0:
1299 bitmap_file_set_bit(bitmap, offset);
1300 bitmap_count_page(bitmap,offset, 1);
Jens Axboe93769f52008-08-01 20:32:31 +02001301 blk_plug_device_unlocked(bitmap->mddev->queue);
NeilBrown32a76272005-06-21 17:17:14 -07001302 /* fall through */
1303 case 1:
1304 *bmc = 2;
1305 }
Neil Brownda6e1a32007-02-08 14:20:37 -08001306
NeilBrown32a76272005-06-21 17:17:14 -07001307 (*bmc)++;
1308
1309 spin_unlock_irq(&bitmap->lock);
1310
1311 offset += blocks;
1312 if (sectors > blocks)
1313 sectors -= blocks;
1314 else sectors = 0;
1315 }
NeilBrown8311c292008-03-04 14:29:30 -08001316 bitmap->allclean = 0;
NeilBrown32a76272005-06-21 17:17:14 -07001317 return 0;
1318}
1319
1320void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors,
NeilBrown4b6d2872005-09-09 16:23:47 -07001321 int success, int behind)
NeilBrown32a76272005-06-21 17:17:14 -07001322{
1323 if (!bitmap) return;
NeilBrown4b6d2872005-09-09 16:23:47 -07001324 if (behind) {
1325 atomic_dec(&bitmap->behind_writes);
1326 PRINTK(KERN_DEBUG "dec write-behind count %d/%d\n",
1327 atomic_read(&bitmap->behind_writes), bitmap->max_write_behind);
1328 }
NeilBrownd0a4bb42009-03-31 14:27:02 +11001329 if (bitmap->mddev->degraded)
1330 /* Never clear bits or update events_cleared when degraded */
1331 success = 0;
NeilBrown4b6d2872005-09-09 16:23:47 -07001332
NeilBrown32a76272005-06-21 17:17:14 -07001333 while (sectors) {
1334 int blocks;
1335 unsigned long flags;
1336 bitmap_counter_t *bmc;
1337
1338 spin_lock_irqsave(&bitmap->lock, flags);
1339 bmc = bitmap_get_counter(bitmap, offset, &blocks, 0);
1340 if (!bmc) {
1341 spin_unlock_irqrestore(&bitmap->lock, flags);
1342 return;
1343 }
1344
Neil Browna0da84f2008-06-28 08:31:22 +10001345 if (success &&
1346 bitmap->events_cleared < bitmap->mddev->events) {
1347 bitmap->events_cleared = bitmap->mddev->events;
1348 bitmap->need_sync = 1;
1349 }
1350
NeilBrown32a76272005-06-21 17:17:14 -07001351 if (!success && ! (*bmc & NEEDED_MASK))
1352 *bmc |= NEEDED_MASK;
1353
Neil Brownda6e1a32007-02-08 14:20:37 -08001354 if ((*bmc & COUNTER_MAX) == COUNTER_MAX)
1355 wake_up(&bitmap->overflow_wait);
1356
NeilBrown32a76272005-06-21 17:17:14 -07001357 (*bmc)--;
1358 if (*bmc <= 2) {
1359 set_page_attr(bitmap,
1360 filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)),
1361 BITMAP_PAGE_CLEAN);
1362 }
1363 spin_unlock_irqrestore(&bitmap->lock, flags);
1364 offset += blocks;
1365 if (sectors > blocks)
1366 sectors -= blocks;
1367 else sectors = 0;
1368 }
1369}
1370
NeilBrown1187cf02009-03-31 14:27:02 +11001371static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks,
1372 int degraded)
NeilBrown32a76272005-06-21 17:17:14 -07001373{
1374 bitmap_counter_t *bmc;
1375 int rv;
1376 if (bitmap == NULL) {/* FIXME or bitmap set as 'failed' */
1377 *blocks = 1024;
1378 return 1; /* always resync if no bitmap */
1379 }
1380 spin_lock_irq(&bitmap->lock);
1381 bmc = bitmap_get_counter(bitmap, offset, blocks, 0);
1382 rv = 0;
1383 if (bmc) {
1384 /* locked */
1385 if (RESYNC(*bmc))
1386 rv = 1;
1387 else if (NEEDED(*bmc)) {
1388 rv = 1;
NeilBrown6a806c52005-07-15 03:56:35 -07001389 if (!degraded) { /* don't set/clear bits if degraded */
1390 *bmc |= RESYNC_MASK;
1391 *bmc &= ~NEEDED_MASK;
1392 }
NeilBrown32a76272005-06-21 17:17:14 -07001393 }
1394 }
1395 spin_unlock_irq(&bitmap->lock);
NeilBrown8311c292008-03-04 14:29:30 -08001396 bitmap->allclean = 0;
NeilBrown32a76272005-06-21 17:17:14 -07001397 return rv;
1398}
1399
NeilBrown1187cf02009-03-31 14:27:02 +11001400int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks,
1401 int degraded)
1402{
1403 /* bitmap_start_sync must always report on multiples of whole
1404 * pages, otherwise resync (which is very PAGE_SIZE based) will
1405 * get confused.
1406 * So call __bitmap_start_sync repeatedly (if needed) until
1407 * At least PAGE_SIZE>>9 blocks are covered.
1408 * Return the 'or' of the result.
1409 */
1410 int rv = 0;
1411 int blocks1;
1412
1413 *blocks = 0;
1414 while (*blocks < (PAGE_SIZE>>9)) {
1415 rv |= __bitmap_start_sync(bitmap, offset,
1416 &blocks1, degraded);
1417 offset += blocks1;
1418 *blocks += blocks1;
1419 }
1420 return rv;
1421}
1422
NeilBrown32a76272005-06-21 17:17:14 -07001423void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted)
1424{
1425 bitmap_counter_t *bmc;
1426 unsigned long flags;
1427/*
1428 if (offset == 0) printk("bitmap_end_sync 0 (%d)\n", aborted);
1429*/ if (bitmap == NULL) {
1430 *blocks = 1024;
1431 return;
1432 }
1433 spin_lock_irqsave(&bitmap->lock, flags);
1434 bmc = bitmap_get_counter(bitmap, offset, blocks, 0);
1435 if (bmc == NULL)
1436 goto unlock;
1437 /* locked */
1438/*
1439 if (offset == 0) printk("bitmap_end sync found 0x%x, blocks %d\n", *bmc, *blocks);
1440*/
1441 if (RESYNC(*bmc)) {
1442 *bmc &= ~RESYNC_MASK;
1443
1444 if (!NEEDED(*bmc) && aborted)
1445 *bmc |= NEEDED_MASK;
1446 else {
1447 if (*bmc <= 2) {
1448 set_page_attr(bitmap,
1449 filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)),
1450 BITMAP_PAGE_CLEAN);
1451 }
1452 }
1453 }
1454 unlock:
1455 spin_unlock_irqrestore(&bitmap->lock, flags);
NeilBrown8311c292008-03-04 14:29:30 -08001456 bitmap->allclean = 0;
NeilBrown32a76272005-06-21 17:17:14 -07001457}
1458
1459void bitmap_close_sync(struct bitmap *bitmap)
1460{
1461 /* Sync has finished, and any bitmap chunks that weren't synced
1462 * properly have been aborted. It remains to us to clear the
1463 * RESYNC bit wherever it is still on
1464 */
1465 sector_t sector = 0;
1466 int blocks;
NeilBrownb47490c2008-02-06 01:39:50 -08001467 if (!bitmap)
1468 return;
NeilBrown32a76272005-06-21 17:17:14 -07001469 while (sector < bitmap->mddev->resync_max_sectors) {
1470 bitmap_end_sync(bitmap, sector, &blocks, 0);
NeilBrownb47490c2008-02-06 01:39:50 -08001471 sector += blocks;
NeilBrown32a76272005-06-21 17:17:14 -07001472 }
1473}
1474
NeilBrownb47490c2008-02-06 01:39:50 -08001475void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector)
1476{
1477 sector_t s = 0;
1478 int blocks;
1479
1480 if (!bitmap)
1481 return;
1482 if (sector == 0) {
1483 bitmap->last_end_sync = jiffies;
1484 return;
1485 }
1486 if (time_before(jiffies, (bitmap->last_end_sync
NeilBrown1b04be92009-12-14 12:49:53 +11001487 + bitmap->mddev->bitmap_info.daemon_sleep)))
NeilBrownb47490c2008-02-06 01:39:50 -08001488 return;
1489 wait_event(bitmap->mddev->recovery_wait,
1490 atomic_read(&bitmap->mddev->recovery_active) == 0);
1491
NeilBrown97e4f422009-03-31 14:33:13 +11001492 bitmap->mddev->curr_resync_completed = bitmap->mddev->curr_resync;
1493 set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags);
NeilBrownb47490c2008-02-06 01:39:50 -08001494 sector &= ~((1ULL << CHUNK_BLOCK_SHIFT(bitmap)) - 1);
1495 s = 0;
1496 while (s < sector && s < bitmap->mddev->resync_max_sectors) {
1497 bitmap_end_sync(bitmap, s, &blocks, 0);
1498 s += blocks;
1499 }
1500 bitmap->last_end_sync = jiffies;
NeilBrownacb180b2009-04-14 16:28:34 +10001501 sysfs_notify(&bitmap->mddev->kobj, NULL, "sync_completed");
NeilBrownb47490c2008-02-06 01:39:50 -08001502}
1503
NeilBrown6a079972005-09-09 16:23:44 -07001504static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed)
NeilBrown32a76272005-06-21 17:17:14 -07001505{
1506 /* For each chunk covered by any of these sectors, set the
NeilBrown193f1c92005-08-04 12:53:33 -07001507 * counter to 1 and set resync_needed. They should all
NeilBrown32a76272005-06-21 17:17:14 -07001508 * be 0 at this point
1509 */
NeilBrown193f1c92005-08-04 12:53:33 -07001510
1511 int secs;
1512 bitmap_counter_t *bmc;
1513 spin_lock_irq(&bitmap->lock);
1514 bmc = bitmap_get_counter(bitmap, offset, &secs, 1);
1515 if (!bmc) {
NeilBrown32a76272005-06-21 17:17:14 -07001516 spin_unlock_irq(&bitmap->lock);
NeilBrown193f1c92005-08-04 12:53:33 -07001517 return;
NeilBrown32a76272005-06-21 17:17:14 -07001518 }
NeilBrown193f1c92005-08-04 12:53:33 -07001519 if (! *bmc) {
1520 struct page *page;
NeilBrown6a079972005-09-09 16:23:44 -07001521 *bmc = 1 | (needed?NEEDED_MASK:0);
NeilBrown193f1c92005-08-04 12:53:33 -07001522 bitmap_count_page(bitmap, offset, 1);
1523 page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap));
1524 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
1525 }
1526 spin_unlock_irq(&bitmap->lock);
NeilBrown8311c292008-03-04 14:29:30 -08001527 bitmap->allclean = 0;
NeilBrown32a76272005-06-21 17:17:14 -07001528}
1529
Paul Clements9b1d1da2006-10-03 01:15:49 -07001530/* dirty the memory and file bits for bitmap chunks "s" to "e" */
1531void bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e)
1532{
1533 unsigned long chunk;
1534
1535 for (chunk = s; chunk <= e; chunk++) {
NeilBrowndb305e52009-05-07 12:49:06 +10001536 sector_t sec = (sector_t)chunk << CHUNK_BLOCK_SHIFT(bitmap);
Paul Clements9b1d1da2006-10-03 01:15:49 -07001537 bitmap_set_memory_bits(bitmap, sec, 1);
1538 bitmap_file_set_bit(bitmap, sec);
1539 }
1540}
1541
NeilBrown32a76272005-06-21 17:17:14 -07001542/*
NeilBrown6b8b3e82005-08-04 12:53:35 -07001543 * flush out any pending updates
1544 */
1545void bitmap_flush(mddev_t *mddev)
1546{
1547 struct bitmap *bitmap = mddev->bitmap;
NeilBrown42a04b52009-12-14 12:49:53 +11001548 long sleep;
NeilBrown6b8b3e82005-08-04 12:53:35 -07001549
1550 if (!bitmap) /* there was no bitmap */
1551 return;
1552
1553 /* run the daemon_work three time to ensure everything is flushed
1554 * that can be
1555 */
NeilBrown1b04be92009-12-14 12:49:53 +11001556 sleep = mddev->bitmap_info.daemon_sleep * 2;
NeilBrown42a04b52009-12-14 12:49:53 +11001557 bitmap->daemon_lastrun -= sleep;
NeilBrownaa5cbd12009-12-14 12:49:46 +11001558 bitmap_daemon_work(mddev);
NeilBrown42a04b52009-12-14 12:49:53 +11001559 bitmap->daemon_lastrun -= sleep;
NeilBrownaa5cbd12009-12-14 12:49:46 +11001560 bitmap_daemon_work(mddev);
NeilBrown42a04b52009-12-14 12:49:53 +11001561 bitmap->daemon_lastrun -= sleep;
NeilBrownaa5cbd12009-12-14 12:49:46 +11001562 bitmap_daemon_work(mddev);
NeilBrown6b8b3e82005-08-04 12:53:35 -07001563 bitmap_update_sb(bitmap);
1564}
1565
1566/*
NeilBrown32a76272005-06-21 17:17:14 -07001567 * free memory that was allocated
1568 */
NeilBrown3178b0d2005-09-09 16:23:50 -07001569static void bitmap_free(struct bitmap *bitmap)
NeilBrown32a76272005-06-21 17:17:14 -07001570{
1571 unsigned long k, pages;
1572 struct bitmap_page *bp;
NeilBrown32a76272005-06-21 17:17:14 -07001573
1574 if (!bitmap) /* there was no bitmap */
1575 return;
1576
NeilBrown32a76272005-06-21 17:17:14 -07001577 /* release the bitmap file and kill the daemon */
1578 bitmap_file_put(bitmap);
1579
1580 bp = bitmap->bp;
1581 pages = bitmap->pages;
1582
1583 /* free all allocated memory */
1584
NeilBrown32a76272005-06-21 17:17:14 -07001585 if (bp) /* deallocate the page memory */
1586 for (k = 0; k < pages; k++)
1587 if (bp[k].map && !bp[k].hijacked)
1588 kfree(bp[k].map);
1589 kfree(bp);
1590 kfree(bitmap);
1591}
NeilBrownaa5cbd12009-12-14 12:49:46 +11001592
NeilBrown3178b0d2005-09-09 16:23:50 -07001593void bitmap_destroy(mddev_t *mddev)
1594{
1595 struct bitmap *bitmap = mddev->bitmap;
1596
1597 if (!bitmap) /* there was no bitmap */
1598 return;
1599
NeilBrownc3d97142009-12-14 12:49:52 +11001600 mutex_lock(&mddev->bitmap_info.mutex);
NeilBrown3178b0d2005-09-09 16:23:50 -07001601 mddev->bitmap = NULL; /* disconnect from the md device */
NeilBrownc3d97142009-12-14 12:49:52 +11001602 mutex_unlock(&mddev->bitmap_info.mutex);
NeilBrownb15c2e52006-01-06 00:20:16 -08001603 if (mddev->thread)
1604 mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
NeilBrown3178b0d2005-09-09 16:23:50 -07001605
1606 bitmap_free(bitmap);
1607}
NeilBrown32a76272005-06-21 17:17:14 -07001608
1609/*
1610 * initialize the bitmap structure
1611 * if this returns an error, bitmap_destroy must be called to do clean up
1612 */
1613int bitmap_create(mddev_t *mddev)
1614{
1615 struct bitmap *bitmap;
NeilBrown1f593902009-04-20 11:50:24 +10001616 sector_t blocks = mddev->resync_max_sectors;
NeilBrown32a76272005-06-21 17:17:14 -07001617 unsigned long chunks;
1618 unsigned long pages;
NeilBrownc3d97142009-12-14 12:49:52 +11001619 struct file *file = mddev->bitmap_info.file;
NeilBrown32a76272005-06-21 17:17:14 -07001620 int err;
NeilBrown6a079972005-09-09 16:23:44 -07001621 sector_t start;
NeilBrown32a76272005-06-21 17:17:14 -07001622
Alexey Dobriyan5f6e3c832006-10-11 01:22:26 -07001623 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256);
NeilBrown32a76272005-06-21 17:17:14 -07001624
NeilBrownc3d97142009-12-14 12:49:52 +11001625 if (!file && !mddev->bitmap_info.offset) /* bitmap disabled, nothing to do */
NeilBrown32a76272005-06-21 17:17:14 -07001626 return 0;
1627
NeilBrownc3d97142009-12-14 12:49:52 +11001628 BUG_ON(file && mddev->bitmap_info.offset);
NeilBrowna654b9d82005-06-21 17:17:27 -07001629
NeilBrown9ffae0c2006-01-06 00:20:32 -08001630 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL);
NeilBrown32a76272005-06-21 17:17:14 -07001631 if (!bitmap)
1632 return -ENOMEM;
1633
NeilBrown32a76272005-06-21 17:17:14 -07001634 spin_lock_init(&bitmap->lock);
NeilBrownce25c312006-06-26 00:27:49 -07001635 atomic_set(&bitmap->pending_writes, 0);
1636 init_waitqueue_head(&bitmap->write_wait);
Neil Brownda6e1a32007-02-08 14:20:37 -08001637 init_waitqueue_head(&bitmap->overflow_wait);
NeilBrownce25c312006-06-26 00:27:49 -07001638
NeilBrown32a76272005-06-21 17:17:14 -07001639 bitmap->mddev = mddev;
NeilBrown32a76272005-06-21 17:17:14 -07001640
NeilBrown32a76272005-06-21 17:17:14 -07001641 bitmap->file = file;
NeilBrownce25c312006-06-26 00:27:49 -07001642 if (file) {
1643 get_file(file);
NeilBrownae8fa282009-10-16 15:56:01 +11001644 /* As future accesses to this file will use bmap,
1645 * and bypass the page cache, we must sync the file
1646 * first.
1647 */
1648 vfs_fsync(file, file->f_dentry, 1);
NeilBrownce25c312006-06-26 00:27:49 -07001649 }
NeilBrown42a04b52009-12-14 12:49:53 +11001650 /* read superblock from bitmap file (this sets mddev->bitmap_info.chunksize) */
NeilBrown32a76272005-06-21 17:17:14 -07001651 err = bitmap_read_sb(bitmap);
1652 if (err)
NeilBrown3178b0d2005-09-09 16:23:50 -07001653 goto error;
NeilBrown32a76272005-06-21 17:17:14 -07001654
NeilBrown42a04b52009-12-14 12:49:53 +11001655 bitmap->chunkshift = ffz(~mddev->bitmap_info.chunksize);
NeilBrown32a76272005-06-21 17:17:14 -07001656
1657 /* now that chunksize and chunkshift are set, we can use these macros */
NeilBrown1f593902009-04-20 11:50:24 +10001658 chunks = (blocks + CHUNK_BLOCK_RATIO(bitmap) - 1) >>
1659 CHUNK_BLOCK_SHIFT(bitmap);
NeilBrown32a76272005-06-21 17:17:14 -07001660 pages = (chunks + PAGE_COUNTER_RATIO - 1) / PAGE_COUNTER_RATIO;
1661
1662 BUG_ON(!pages);
1663
1664 bitmap->chunks = chunks;
1665 bitmap->pages = pages;
1666 bitmap->missing_pages = pages;
1667 bitmap->counter_bits = COUNTER_BITS;
1668
1669 bitmap->syncchunk = ~0UL;
1670
Olaf Hering44456d32005-07-27 11:45:17 -07001671#ifdef INJECT_FATAL_FAULT_1
NeilBrown32a76272005-06-21 17:17:14 -07001672 bitmap->bp = NULL;
1673#else
NeilBrown9ffae0c2006-01-06 00:20:32 -08001674 bitmap->bp = kzalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL);
NeilBrown32a76272005-06-21 17:17:14 -07001675#endif
NeilBrown3178b0d2005-09-09 16:23:50 -07001676 err = -ENOMEM;
NeilBrown32a76272005-06-21 17:17:14 -07001677 if (!bitmap->bp)
NeilBrown3178b0d2005-09-09 16:23:50 -07001678 goto error;
NeilBrown32a76272005-06-21 17:17:14 -07001679
NeilBrown32a76272005-06-21 17:17:14 -07001680 /* now that we have some pages available, initialize the in-memory
1681 * bitmap from the on-disk bitmap */
NeilBrown6a079972005-09-09 16:23:44 -07001682 start = 0;
1683 if (mddev->degraded == 0
1684 || bitmap->events_cleared == mddev->events)
1685 /* no need to keep dirty bits to optimise a re-add of a missing device */
1686 start = mddev->recovery_cp;
1687 err = bitmap_init_from_disk(bitmap, start);
NeilBrown193f1c92005-08-04 12:53:33 -07001688
NeilBrown32a76272005-06-21 17:17:14 -07001689 if (err)
NeilBrown3178b0d2005-09-09 16:23:50 -07001690 goto error;
NeilBrown32a76272005-06-21 17:17:14 -07001691
1692 printk(KERN_INFO "created bitmap (%lu pages) for device %s\n",
1693 pages, bmname(bitmap));
1694
NeilBrown3178b0d2005-09-09 16:23:50 -07001695 mddev->bitmap = bitmap;
1696
NeilBrown1b04be92009-12-14 12:49:53 +11001697 mddev->thread->timeout = mddev->bitmap_info.daemon_sleep;
NeilBrown9cd30fd2009-12-14 12:49:54 +11001698 md_wakeup_thread(mddev->thread);
NeilBrownb15c2e52006-01-06 00:20:16 -08001699
NeilBrown4ad13662007-07-17 04:06:13 -07001700 bitmap_update_sb(bitmap);
1701
1702 return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0;
NeilBrown3178b0d2005-09-09 16:23:50 -07001703
1704 error:
1705 bitmap_free(bitmap);
1706 return err;
NeilBrown32a76272005-06-21 17:17:14 -07001707}
1708
1709/* the bitmap API -- for raid personalities */
1710EXPORT_SYMBOL(bitmap_startwrite);
1711EXPORT_SYMBOL(bitmap_endwrite);
1712EXPORT_SYMBOL(bitmap_start_sync);
1713EXPORT_SYMBOL(bitmap_end_sync);
1714EXPORT_SYMBOL(bitmap_unplug);
1715EXPORT_SYMBOL(bitmap_close_sync);
NeilBrownb47490c2008-02-06 01:39:50 -08001716EXPORT_SYMBOL(bitmap_cond_end_sync);