NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1 | /* |
| 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 |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * Still to do: |
| 14 | * |
| 15 | * flush after percent set rather than just time based. (maybe both). |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 18 | #include <linux/blkdev.h> |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 19 | #include <linux/module.h> |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 20 | #include <linux/errno.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/init.h> |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 23 | #include <linux/timer.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include <linux/list.h> |
| 26 | #include <linux/file.h> |
| 27 | #include <linux/mount.h> |
| 28 | #include <linux/buffer_head.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 29 | #include "md.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 30 | #include "bitmap.h" |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 31 | |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 32 | #include <linux/dm-dirty-log.h> |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 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 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 54 | #ifndef PRINTK |
| 55 | # if DEBUG > 0 |
| 56 | # define PRINTK(x...) printk(KERN_DEBUG x) |
| 57 | # else |
| 58 | # define PRINTK(x...) |
| 59 | # endif |
| 60 | #endif |
| 61 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 62 | static inline char *bmname(struct bitmap *bitmap) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 63 | { |
| 64 | return bitmap->mddev ? mdname(bitmap->mddev) : "mdX"; |
| 65 | } |
| 66 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 67 | /* |
| 68 | * just a placeholder - calls kmalloc for bitmap pages |
| 69 | */ |
| 70 | static unsigned char *bitmap_alloc_page(struct bitmap *bitmap) |
| 71 | { |
| 72 | unsigned char *page; |
| 73 | |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 74 | #ifdef INJECT_FAULTS_1 |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 75 | page = NULL; |
| 76 | #else |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 77 | page = kzalloc(PAGE_SIZE, GFP_NOIO); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 78 | #endif |
| 79 | if (!page) |
| 80 | printk("%s: bitmap_alloc_page FAILED\n", bmname(bitmap)); |
| 81 | else |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 82 | PRINTK("%s: bitmap_alloc_page: allocated page at %p\n", |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 83 | bmname(bitmap), page); |
| 84 | return page; |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * for now just a placeholder -- just calls kfree for bitmap pages |
| 89 | */ |
| 90 | static void bitmap_free_page(struct bitmap *bitmap, unsigned char *page) |
| 91 | { |
| 92 | PRINTK("%s: bitmap_free_page: free page %p\n", bmname(bitmap), page); |
| 93 | kfree(page); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * check a page and, if necessary, allocate it (or hijack it if the alloc fails) |
| 98 | * |
| 99 | * 1) check to see if this page is allocated, if it's not then try to alloc |
| 100 | * 2) if the alloc fails, set the page's hijacked flag so we'll use the |
| 101 | * page pointer directly as a counter |
| 102 | * |
| 103 | * if we find our page, we increment the page's refcount so that it stays |
| 104 | * allocated while we're using it |
| 105 | */ |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 106 | static int bitmap_checkpage(struct bitmap *bitmap, |
| 107 | unsigned long page, int create) |
NeilBrown | ee305ac | 2009-09-23 18:06:44 +1000 | [diff] [blame] | 108 | __releases(bitmap->lock) |
| 109 | __acquires(bitmap->lock) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 110 | { |
| 111 | unsigned char *mappage; |
| 112 | |
| 113 | if (page >= bitmap->pages) { |
NeilBrown | 1187cf0 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 114 | /* This can happen if bitmap_start_sync goes beyond |
| 115 | * End-of-device while looking for a whole page. |
| 116 | * It is harmless. |
| 117 | */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 118 | return -EINVAL; |
| 119 | } |
| 120 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 121 | if (bitmap->bp[page].hijacked) /* it's hijacked, don't try to alloc */ |
| 122 | return 0; |
| 123 | |
| 124 | if (bitmap->bp[page].map) /* page is already allocated, just return */ |
| 125 | return 0; |
| 126 | |
| 127 | if (!create) |
| 128 | return -ENOENT; |
| 129 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 130 | /* this page has not been allocated yet */ |
| 131 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 132 | spin_unlock_irq(&bitmap->lock); |
| 133 | mappage = bitmap_alloc_page(bitmap); |
| 134 | spin_lock_irq(&bitmap->lock); |
| 135 | |
| 136 | if (mappage == NULL) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 137 | PRINTK("%s: bitmap map page allocation failed, hijacking\n", |
| 138 | bmname(bitmap)); |
| 139 | /* failed - set the hijacked flag so that we can use the |
| 140 | * pointer as a counter */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 141 | if (!bitmap->bp[page].map) |
| 142 | bitmap->bp[page].hijacked = 1; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 143 | } else if (bitmap->bp[page].map || |
| 144 | bitmap->bp[page].hijacked) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 145 | /* somebody beat us to getting the page */ |
| 146 | bitmap_free_page(bitmap, mappage); |
| 147 | return 0; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 148 | } else { |
| 149 | |
| 150 | /* no page was in place and we have one, so install it */ |
| 151 | |
| 152 | bitmap->bp[page].map = mappage; |
| 153 | bitmap->missing_pages--; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 154 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 158 | /* if page is completely empty, put it back on the free list, or dealloc it */ |
| 159 | /* if page was hijacked, unmark the flag so it might get alloced next time */ |
| 160 | /* Note: lock should be held when calling this */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 161 | static void bitmap_checkfree(struct bitmap *bitmap, unsigned long page) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 162 | { |
| 163 | char *ptr; |
| 164 | |
| 165 | if (bitmap->bp[page].count) /* page is still busy */ |
| 166 | return; |
| 167 | |
| 168 | /* page is no longer in use, it can be released */ |
| 169 | |
| 170 | if (bitmap->bp[page].hijacked) { /* page was hijacked, undo this now */ |
| 171 | bitmap->bp[page].hijacked = 0; |
| 172 | bitmap->bp[page].map = NULL; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 173 | } else { |
| 174 | /* normal case, free the page */ |
| 175 | ptr = bitmap->bp[page].map; |
| 176 | bitmap->bp[page].map = NULL; |
| 177 | bitmap->missing_pages++; |
| 178 | bitmap_free_page(bitmap, ptr); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 179 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 180 | } |
| 181 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 182 | /* |
| 183 | * bitmap file handling - read and write the bitmap file and its superblock |
| 184 | */ |
| 185 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 186 | /* |
| 187 | * basic page I/O operations |
| 188 | */ |
| 189 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 190 | /* IO operations when bitmap is stored near all superblocks */ |
NeilBrown | f6af949 | 2009-12-14 12:49:54 +1100 | [diff] [blame] | 191 | static struct page *read_sb_page(mddev_t *mddev, loff_t offset, |
NeilBrown | a2ed961 | 2008-12-19 16:25:01 +1100 | [diff] [blame] | 192 | struct page *page, |
| 193 | unsigned long index, int size) |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 194 | { |
| 195 | /* choose a good rdev and read the page from there */ |
| 196 | |
| 197 | mdk_rdev_t *rdev; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 198 | sector_t target; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 199 | int did_alloc = 0; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 200 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 201 | if (!page) { |
NeilBrown | a2ed961 | 2008-12-19 16:25:01 +1100 | [diff] [blame] | 202 | page = alloc_page(GFP_KERNEL); |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 203 | if (!page) |
| 204 | return ERR_PTR(-ENOMEM); |
| 205 | did_alloc = 1; |
| 206 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 207 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 208 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 209 | if (! test_bit(In_sync, &rdev->flags) |
| 210 | || test_bit(Faulty, &rdev->flags)) |
NeilBrown | ab904d6 | 2005-09-09 16:23:52 -0700 | [diff] [blame] | 211 | continue; |
| 212 | |
Jonathan Brassow | ccebd4c | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 213 | target = offset + index * (PAGE_SIZE/512); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 214 | |
NeilBrown | 2b19336 | 2010-10-27 15:16:40 +1100 | [diff] [blame] | 215 | if (sync_page_io(rdev, target, |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 216 | roundup(size, bdev_logical_block_size(rdev->bdev)), |
Jonathan Brassow | ccebd4c | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 217 | page, READ, true)) { |
NeilBrown | ab904d6 | 2005-09-09 16:23:52 -0700 | [diff] [blame] | 218 | page->index = index; |
NeilBrown | ce25c31 | 2006-06-26 00:27:49 -0700 | [diff] [blame] | 219 | attach_page_buffers(page, NULL); /* so that free_buffer will |
| 220 | * quietly no-op */ |
NeilBrown | ab904d6 | 2005-09-09 16:23:52 -0700 | [diff] [blame] | 221 | return page; |
| 222 | } |
| 223 | } |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 224 | if (did_alloc) |
| 225 | put_page(page); |
NeilBrown | ab904d6 | 2005-09-09 16:23:52 -0700 | [diff] [blame] | 226 | return ERR_PTR(-EIO); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 227 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 228 | } |
| 229 | |
NeilBrown | b2d2c4c | 2008-09-01 12:48:13 +1000 | [diff] [blame] | 230 | static mdk_rdev_t *next_active_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
| 231 | { |
| 232 | /* Iterate the disks of an mddev, using rcu to protect access to the |
| 233 | * linked list, and raising the refcount of devices we return to ensure |
| 234 | * they don't disappear while in use. |
| 235 | * As devices are only added or removed when raid_disk is < 0 and |
| 236 | * nr_pending is 0 and In_sync is clear, the entries we return will |
| 237 | * still be in the same position on the list when we re-enter |
| 238 | * list_for_each_continue_rcu. |
| 239 | */ |
| 240 | struct list_head *pos; |
| 241 | rcu_read_lock(); |
| 242 | if (rdev == NULL) |
| 243 | /* start at the beginning */ |
| 244 | pos = &mddev->disks; |
| 245 | else { |
| 246 | /* release the previous rdev and start from there. */ |
| 247 | rdev_dec_pending(rdev, mddev); |
| 248 | pos = &rdev->same_set; |
| 249 | } |
| 250 | list_for_each_continue_rcu(pos, &mddev->disks) { |
| 251 | rdev = list_entry(pos, mdk_rdev_t, same_set); |
| 252 | if (rdev->raid_disk >= 0 && |
NeilBrown | b2d2c4c | 2008-09-01 12:48:13 +1000 | [diff] [blame] | 253 | !test_bit(Faulty, &rdev->flags)) { |
| 254 | /* this is a usable devices */ |
| 255 | atomic_inc(&rdev->nr_pending); |
| 256 | rcu_read_unlock(); |
| 257 | return rdev; |
| 258 | } |
| 259 | } |
| 260 | rcu_read_unlock(); |
| 261 | return NULL; |
| 262 | } |
| 263 | |
NeilBrown | ab6085c | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 264 | static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait) |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 265 | { |
NeilBrown | b2d2c4c | 2008-09-01 12:48:13 +1000 | [diff] [blame] | 266 | mdk_rdev_t *rdev = NULL; |
Jonathan Brassow | a6ff7e0 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 267 | struct block_device *bdev; |
NeilBrown | ab6085c | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 268 | mddev_t *mddev = bitmap->mddev; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 269 | |
NeilBrown | b2d2c4c | 2008-09-01 12:48:13 +1000 | [diff] [blame] | 270 | while ((rdev = next_active_rdev(rdev, mddev)) != NULL) { |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 271 | int size = PAGE_SIZE; |
| 272 | loff_t offset = mddev->bitmap_info.offset; |
Jonathan Brassow | a6ff7e0 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 273 | |
| 274 | bdev = (rdev->meta_bdev) ? rdev->meta_bdev : rdev->bdev; |
| 275 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 276 | if (page->index == bitmap->file_pages-1) |
| 277 | size = roundup(bitmap->last_page_size, |
Jonathan Brassow | a6ff7e0 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 278 | bdev_logical_block_size(bdev)); |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 279 | /* Just make sure we aren't corrupting data or |
| 280 | * metadata |
| 281 | */ |
| 282 | if (mddev->external) { |
| 283 | /* Bitmap could be anywhere. */ |
| 284 | if (rdev->sb_start + offset + (page->index |
| 285 | * (PAGE_SIZE/512)) |
| 286 | > rdev->data_offset |
| 287 | && |
| 288 | rdev->sb_start + offset |
| 289 | < (rdev->data_offset + mddev->dev_sectors |
| 290 | + (PAGE_SIZE/512))) |
| 291 | goto bad_alignment; |
| 292 | } else if (offset < 0) { |
| 293 | /* DATA BITMAP METADATA */ |
| 294 | if (offset |
| 295 | + (long)(page->index * (PAGE_SIZE/512)) |
| 296 | + size/512 > 0) |
| 297 | /* bitmap runs in to metadata */ |
| 298 | goto bad_alignment; |
| 299 | if (rdev->data_offset + mddev->dev_sectors |
| 300 | > rdev->sb_start + offset) |
| 301 | /* data runs in to bitmap */ |
| 302 | goto bad_alignment; |
| 303 | } else if (rdev->sb_start < rdev->data_offset) { |
| 304 | /* METADATA BITMAP DATA */ |
| 305 | if (rdev->sb_start |
| 306 | + offset |
| 307 | + page->index*(PAGE_SIZE/512) + size/512 |
| 308 | > rdev->data_offset) |
| 309 | /* bitmap runs in to data */ |
| 310 | goto bad_alignment; |
| 311 | } else { |
| 312 | /* DATA METADATA BITMAP - no problems */ |
| 313 | } |
| 314 | md_super_write(mddev, rdev, |
| 315 | rdev->sb_start + offset |
| 316 | + page->index * (PAGE_SIZE/512), |
| 317 | size, |
| 318 | page); |
NeilBrown | b2d2c4c | 2008-09-01 12:48:13 +1000 | [diff] [blame] | 319 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 320 | |
| 321 | if (wait) |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 322 | md_super_wait(mddev); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 323 | return 0; |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 324 | |
| 325 | bad_alignment: |
NeilBrown | 4b80991 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 326 | return -EINVAL; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 327 | } |
| 328 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 329 | static void bitmap_file_kick(struct bitmap *bitmap); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 330 | /* |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 331 | * write out a page to a file |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 332 | */ |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 333 | static void write_page(struct bitmap *bitmap, struct page *page, int wait) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 334 | { |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 335 | struct buffer_head *bh; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 336 | |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 337 | if (bitmap->file == NULL) { |
| 338 | switch (write_sb_page(bitmap, page, wait)) { |
| 339 | case -EINVAL: |
| 340 | bitmap->flags |= BITMAP_WRITE_ERROR; |
NeilBrown | f0d76d7 | 2007-07-17 04:06:12 -0700 | [diff] [blame] | 341 | } |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 342 | } else { |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 343 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 344 | bh = page_buffers(page); |
NeilBrown | c708443 | 2006-01-06 00:20:45 -0800 | [diff] [blame] | 345 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 346 | while (bh && bh->b_blocknr) { |
| 347 | atomic_inc(&bitmap->pending_writes); |
| 348 | set_buffer_locked(bh); |
| 349 | set_buffer_mapped(bh); |
NeilBrown | be2a265 | 2010-10-27 15:37:41 +1100 | [diff] [blame] | 350 | submit_bh(WRITE | REQ_UNPLUG | REQ_SYNC, bh); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 351 | bh = bh->b_this_page; |
| 352 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 353 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 354 | if (wait) |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 355 | wait_event(bitmap->write_wait, |
| 356 | atomic_read(&bitmap->pending_writes)==0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 357 | } |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 358 | if (bitmap->flags & BITMAP_WRITE_ERROR) |
| 359 | bitmap_file_kick(bitmap); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 360 | } |
| 361 | |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 362 | static void end_bitmap_write(struct buffer_head *bh, int uptodate) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 363 | { |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 364 | struct bitmap *bitmap = bh->b_private; |
| 365 | unsigned long flags; |
| 366 | |
| 367 | if (!uptodate) { |
| 368 | spin_lock_irqsave(&bitmap->lock, flags); |
| 369 | bitmap->flags |= BITMAP_WRITE_ERROR; |
| 370 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 371 | } |
| 372 | if (atomic_dec_and_test(&bitmap->pending_writes)) |
| 373 | wake_up(&bitmap->write_wait); |
| 374 | } |
| 375 | |
| 376 | /* copied from buffer.c */ |
| 377 | static void |
| 378 | __clear_page_buffers(struct page *page) |
| 379 | { |
| 380 | ClearPagePrivate(page); |
| 381 | set_page_private(page, 0); |
| 382 | page_cache_release(page); |
| 383 | } |
| 384 | static void free_buffers(struct page *page) |
| 385 | { |
| 386 | struct buffer_head *bh = page_buffers(page); |
| 387 | |
| 388 | while (bh) { |
| 389 | struct buffer_head *next = bh->b_this_page; |
| 390 | free_buffer_head(bh); |
| 391 | bh = next; |
| 392 | } |
| 393 | __clear_page_buffers(page); |
| 394 | put_page(page); |
| 395 | } |
| 396 | |
| 397 | /* read a page from a file. |
| 398 | * We both read the page, and attach buffers to the page to record the |
| 399 | * address of each block (using bmap). These addresses will be used |
| 400 | * to write the block later, completely bypassing the filesystem. |
| 401 | * This usage is similar to how swap files are handled, and allows us |
| 402 | * to write to a file with no concerns of memory allocation failing. |
| 403 | */ |
| 404 | static struct page *read_page(struct file *file, unsigned long index, |
| 405 | struct bitmap *bitmap, |
| 406 | unsigned long count) |
| 407 | { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 408 | struct page *page = NULL; |
Josef Sipek | c649bb9 | 2006-12-08 02:37:19 -0800 | [diff] [blame] | 409 | struct inode *inode = file->f_path.dentry->d_inode; |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 410 | struct buffer_head *bh; |
| 411 | sector_t block; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 412 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 413 | PRINTK("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE, |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 414 | (unsigned long long)index << PAGE_SHIFT); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 415 | |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 416 | page = alloc_page(GFP_KERNEL); |
| 417 | if (!page) |
| 418 | page = ERR_PTR(-ENOMEM); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 419 | if (IS_ERR(page)) |
| 420 | goto out; |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 421 | |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 422 | bh = alloc_page_buffers(page, 1<<inode->i_blkbits, 0); |
| 423 | if (!bh) { |
| 424 | put_page(page); |
| 425 | page = ERR_PTR(-ENOMEM); |
| 426 | goto out; |
| 427 | } |
| 428 | attach_page_buffers(page, bh); |
| 429 | block = index << (PAGE_SHIFT - inode->i_blkbits); |
| 430 | while (bh) { |
| 431 | if (count == 0) |
| 432 | bh->b_blocknr = 0; |
| 433 | else { |
| 434 | bh->b_blocknr = bmap(inode, block); |
| 435 | if (bh->b_blocknr == 0) { |
| 436 | /* Cannot use this file! */ |
| 437 | free_buffers(page); |
| 438 | page = ERR_PTR(-EINVAL); |
| 439 | goto out; |
| 440 | } |
| 441 | bh->b_bdev = inode->i_sb->s_bdev; |
| 442 | if (count < (1<<inode->i_blkbits)) |
| 443 | count = 0; |
| 444 | else |
| 445 | count -= (1<<inode->i_blkbits); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 446 | |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 447 | bh->b_end_io = end_bitmap_write; |
| 448 | bh->b_private = bitmap; |
NeilBrown | ce25c31 | 2006-06-26 00:27:49 -0700 | [diff] [blame] | 449 | atomic_inc(&bitmap->pending_writes); |
| 450 | set_buffer_locked(bh); |
| 451 | set_buffer_mapped(bh); |
| 452 | submit_bh(READ, bh); |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 453 | } |
| 454 | block++; |
| 455 | bh = bh->b_this_page; |
| 456 | } |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 457 | page->index = index; |
NeilBrown | ce25c31 | 2006-06-26 00:27:49 -0700 | [diff] [blame] | 458 | |
| 459 | wait_event(bitmap->write_wait, |
| 460 | atomic_read(&bitmap->pending_writes)==0); |
| 461 | if (bitmap->flags & BITMAP_WRITE_ERROR) { |
| 462 | free_buffers(page); |
| 463 | page = ERR_PTR(-EIO); |
| 464 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 465 | out: |
| 466 | if (IS_ERR(page)) |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 467 | printk(KERN_ALERT "md: bitmap read error: (%dB @ %llu): %ld\n", |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 468 | (int)PAGE_SIZE, |
| 469 | (unsigned long long)index << PAGE_SHIFT, |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 470 | PTR_ERR(page)); |
| 471 | return page; |
| 472 | } |
| 473 | |
| 474 | /* |
| 475 | * bitmap file superblock operations |
| 476 | */ |
| 477 | |
| 478 | /* update the event counter and sync the superblock to disk */ |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 479 | void bitmap_update_sb(struct bitmap *bitmap) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 480 | { |
| 481 | bitmap_super_t *sb; |
| 482 | unsigned long flags; |
| 483 | |
| 484 | if (!bitmap || !bitmap->mddev) /* no bitmap for this array */ |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 485 | return; |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 486 | if (bitmap->mddev->bitmap_info.external) |
| 487 | return; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 488 | spin_lock_irqsave(&bitmap->lock, flags); |
| 489 | if (!bitmap->sb_page) { /* no superblock */ |
| 490 | spin_unlock_irqrestore(&bitmap->lock, flags); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 491 | return; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 492 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 493 | spin_unlock_irqrestore(&bitmap->lock, flags); |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 494 | sb = kmap_atomic(bitmap->sb_page, KM_USER0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 495 | sb->events = cpu_to_le64(bitmap->mddev->events); |
Neil Brown | a0da84f | 2008-06-28 08:31:22 +1000 | [diff] [blame] | 496 | if (bitmap->mddev->events < bitmap->events_cleared) { |
| 497 | /* rocking back to read-only */ |
| 498 | bitmap->events_cleared = bitmap->mddev->events; |
| 499 | sb->events_cleared = cpu_to_le64(bitmap->events_cleared); |
| 500 | } |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 501 | /* Just in case these have been changed via sysfs: */ |
| 502 | sb->daemon_sleep = cpu_to_le32(bitmap->mddev->bitmap_info.daemon_sleep/HZ); |
| 503 | sb->write_behind = cpu_to_le32(bitmap->mddev->bitmap_info.max_write_behind); |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 504 | kunmap_atomic(sb, KM_USER0); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 505 | write_page(bitmap, bitmap->sb_page, 1); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | /* print out the bitmap file superblock */ |
| 509 | void bitmap_print_sb(struct bitmap *bitmap) |
| 510 | { |
| 511 | bitmap_super_t *sb; |
| 512 | |
| 513 | if (!bitmap || !bitmap->sb_page) |
| 514 | return; |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 515 | sb = kmap_atomic(bitmap->sb_page, KM_USER0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 516 | printk(KERN_DEBUG "%s: bitmap file superblock:\n", bmname(bitmap)); |
NeilBrown | a2cff26 | 2005-06-21 17:17:20 -0700 | [diff] [blame] | 517 | printk(KERN_DEBUG " magic: %08x\n", le32_to_cpu(sb->magic)); |
| 518 | printk(KERN_DEBUG " version: %d\n", le32_to_cpu(sb->version)); |
| 519 | printk(KERN_DEBUG " uuid: %08x.%08x.%08x.%08x\n", |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 520 | *(__u32 *)(sb->uuid+0), |
| 521 | *(__u32 *)(sb->uuid+4), |
| 522 | *(__u32 *)(sb->uuid+8), |
| 523 | *(__u32 *)(sb->uuid+12)); |
NeilBrown | a2cff26 | 2005-06-21 17:17:20 -0700 | [diff] [blame] | 524 | printk(KERN_DEBUG " events: %llu\n", |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 525 | (unsigned long long) le64_to_cpu(sb->events)); |
NeilBrown | a2cff26 | 2005-06-21 17:17:20 -0700 | [diff] [blame] | 526 | printk(KERN_DEBUG "events cleared: %llu\n", |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 527 | (unsigned long long) le64_to_cpu(sb->events_cleared)); |
NeilBrown | a2cff26 | 2005-06-21 17:17:20 -0700 | [diff] [blame] | 528 | printk(KERN_DEBUG " state: %08x\n", le32_to_cpu(sb->state)); |
| 529 | printk(KERN_DEBUG " chunksize: %d B\n", le32_to_cpu(sb->chunksize)); |
| 530 | printk(KERN_DEBUG " daemon sleep: %ds\n", le32_to_cpu(sb->daemon_sleep)); |
| 531 | printk(KERN_DEBUG " sync size: %llu KB\n", |
| 532 | (unsigned long long)le64_to_cpu(sb->sync_size)/2); |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 533 | printk(KERN_DEBUG "max write behind: %d\n", le32_to_cpu(sb->write_behind)); |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 534 | kunmap_atomic(sb, KM_USER0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /* read the superblock from the bitmap file and initialize some bitmap fields */ |
| 538 | static int bitmap_read_sb(struct bitmap *bitmap) |
| 539 | { |
| 540 | char *reason = NULL; |
| 541 | bitmap_super_t *sb; |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 542 | unsigned long chunksize, daemon_sleep, write_behind; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 543 | unsigned long long events; |
| 544 | int err = -EINVAL; |
| 545 | |
| 546 | /* page 0 is the superblock, read it... */ |
NeilBrown | f49d5e6 | 2007-01-26 00:57:03 -0800 | [diff] [blame] | 547 | if (bitmap->file) { |
| 548 | loff_t isize = i_size_read(bitmap->file->f_mapping->host); |
| 549 | int bytes = isize > PAGE_SIZE ? PAGE_SIZE : isize; |
| 550 | |
| 551 | bitmap->sb_page = read_page(bitmap->file, 0, bitmap, bytes); |
| 552 | } else { |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 553 | bitmap->sb_page = read_sb_page(bitmap->mddev, |
| 554 | bitmap->mddev->bitmap_info.offset, |
NeilBrown | a2ed961 | 2008-12-19 16:25:01 +1100 | [diff] [blame] | 555 | NULL, |
| 556 | 0, sizeof(bitmap_super_t)); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 557 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 558 | if (IS_ERR(bitmap->sb_page)) { |
| 559 | err = PTR_ERR(bitmap->sb_page); |
| 560 | bitmap->sb_page = NULL; |
| 561 | return err; |
| 562 | } |
| 563 | |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 564 | sb = kmap_atomic(bitmap->sb_page, KM_USER0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 565 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 566 | chunksize = le32_to_cpu(sb->chunksize); |
NeilBrown | 1b04be9 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 567 | daemon_sleep = le32_to_cpu(sb->daemon_sleep) * HZ; |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 568 | write_behind = le32_to_cpu(sb->write_behind); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 569 | |
| 570 | /* verify that the bitmap-specific fields are valid */ |
| 571 | if (sb->magic != cpu_to_le32(BITMAP_MAGIC)) |
| 572 | reason = "bad magic"; |
NeilBrown | bd926c6 | 2005-11-08 21:39:32 -0800 | [diff] [blame] | 573 | else if (le32_to_cpu(sb->version) < BITMAP_MAJOR_LO || |
| 574 | le32_to_cpu(sb->version) > BITMAP_MAJOR_HI) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 575 | reason = "unrecognized superblock version"; |
NeilBrown | 1187cf0 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 576 | else if (chunksize < 512) |
NeilBrown | 7dd5d34 | 2006-01-06 00:20:39 -0800 | [diff] [blame] | 577 | reason = "bitmap chunksize too small"; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 578 | else if ((1 << ffz(~chunksize)) != chunksize) |
| 579 | reason = "bitmap chunksize not a power of 2"; |
NeilBrown | 1b04be9 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 580 | else if (daemon_sleep < 1 || daemon_sleep > MAX_SCHEDULE_TIMEOUT) |
NeilBrown | 7dd5d34 | 2006-01-06 00:20:39 -0800 | [diff] [blame] | 581 | reason = "daemon sleep period out of range"; |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 582 | else if (write_behind > COUNTER_MAX) |
| 583 | reason = "write-behind limit out of range (0 - 16383)"; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 584 | if (reason) { |
| 585 | printk(KERN_INFO "%s: invalid bitmap file superblock: %s\n", |
| 586 | bmname(bitmap), reason); |
| 587 | goto out; |
| 588 | } |
| 589 | |
| 590 | /* keep the array size field of the bitmap superblock up to date */ |
| 591 | sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); |
| 592 | |
| 593 | if (!bitmap->mddev->persistent) |
| 594 | goto success; |
| 595 | |
| 596 | /* |
| 597 | * if we have a persistent array superblock, compare the |
| 598 | * bitmap's UUID and event counter to the mddev's |
| 599 | */ |
| 600 | if (memcmp(sb->uuid, bitmap->mddev->uuid, 16)) { |
| 601 | printk(KERN_INFO "%s: bitmap superblock UUID mismatch\n", |
| 602 | bmname(bitmap)); |
| 603 | goto out; |
| 604 | } |
| 605 | events = le64_to_cpu(sb->events); |
| 606 | if (events < bitmap->mddev->events) { |
| 607 | printk(KERN_INFO "%s: bitmap file is out of date (%llu < %llu) " |
| 608 | "-- forcing full recovery\n", bmname(bitmap), events, |
| 609 | (unsigned long long) bitmap->mddev->events); |
NeilBrown | 4f2e639 | 2006-10-21 10:24:09 -0700 | [diff] [blame] | 610 | sb->state |= cpu_to_le32(BITMAP_STALE); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 611 | } |
| 612 | success: |
| 613 | /* assign fields using values from superblock */ |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 614 | bitmap->mddev->bitmap_info.chunksize = chunksize; |
| 615 | bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 616 | bitmap->mddev->bitmap_info.max_write_behind = write_behind; |
NeilBrown | 4f2e639 | 2006-10-21 10:24:09 -0700 | [diff] [blame] | 617 | bitmap->flags |= le32_to_cpu(sb->state); |
NeilBrown | bd926c6 | 2005-11-08 21:39:32 -0800 | [diff] [blame] | 618 | if (le32_to_cpu(sb->version) == BITMAP_MAJOR_HOSTENDIAN) |
| 619 | bitmap->flags |= BITMAP_HOSTENDIAN; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 620 | bitmap->events_cleared = le64_to_cpu(sb->events_cleared); |
NeilBrown | 4f2e639 | 2006-10-21 10:24:09 -0700 | [diff] [blame] | 621 | if (sb->state & cpu_to_le32(BITMAP_STALE)) |
NeilBrown | 6a07997 | 2005-09-09 16:23:44 -0700 | [diff] [blame] | 622 | bitmap->events_cleared = bitmap->mddev->events; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 623 | err = 0; |
| 624 | out: |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 625 | kunmap_atomic(sb, KM_USER0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 626 | if (err) |
| 627 | bitmap_print_sb(bitmap); |
| 628 | return err; |
| 629 | } |
| 630 | |
| 631 | enum bitmap_mask_op { |
| 632 | MASK_SET, |
| 633 | MASK_UNSET |
| 634 | }; |
| 635 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 636 | /* record the state of the bitmap in the superblock. Return the old value */ |
| 637 | static int bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits, |
| 638 | enum bitmap_mask_op op) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 639 | { |
| 640 | bitmap_super_t *sb; |
| 641 | unsigned long flags; |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 642 | int old; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 643 | |
| 644 | spin_lock_irqsave(&bitmap->lock, flags); |
Adrian Bunk | 7e31765 | 2006-03-25 03:07:51 -0800 | [diff] [blame] | 645 | if (!bitmap->sb_page) { /* can't set the state */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 646 | spin_unlock_irqrestore(&bitmap->lock, flags); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 647 | return 0; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 648 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 649 | spin_unlock_irqrestore(&bitmap->lock, flags); |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 650 | sb = kmap_atomic(bitmap->sb_page, KM_USER0); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 651 | old = le32_to_cpu(sb->state) & bits; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 652 | switch (op) { |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 653 | case MASK_SET: |
| 654 | sb->state |= cpu_to_le32(bits); |
| 655 | break; |
| 656 | case MASK_UNSET: |
| 657 | sb->state &= cpu_to_le32(~bits); |
| 658 | break; |
| 659 | default: |
| 660 | BUG(); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 661 | } |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 662 | kunmap_atomic(sb, KM_USER0); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 663 | return old; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /* |
| 667 | * general bitmap file operations |
| 668 | */ |
| 669 | |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 670 | /* |
| 671 | * on-disk bitmap: |
| 672 | * |
| 673 | * Use one bit per "chunk" (block set). We do the disk I/O on the bitmap |
| 674 | * file a page at a time. There's a superblock at the start of the file. |
| 675 | */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 676 | /* calculate the index of the page that contains this bit */ |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 677 | static inline unsigned long file_page_index(struct bitmap *bitmap, unsigned long chunk) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 678 | { |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 679 | if (!bitmap->mddev->bitmap_info.external) |
| 680 | chunk += sizeof(bitmap_super_t) << 3; |
| 681 | return chunk >> PAGE_BIT_SHIFT; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | /* calculate the (bit) offset of this bit within a page */ |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 685 | static inline unsigned long file_page_offset(struct bitmap *bitmap, unsigned long chunk) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 686 | { |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 687 | if (!bitmap->mddev->bitmap_info.external) |
| 688 | chunk += sizeof(bitmap_super_t) << 3; |
| 689 | return chunk & (PAGE_BITS - 1); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /* |
| 693 | * return a pointer to the page in the filemap that contains the given bit |
| 694 | * |
| 695 | * this lookup is complicated by the fact that the bitmap sb might be exactly |
| 696 | * 1 page (e.g., x86) or less than 1 page -- so the bitmap might start on page |
| 697 | * 0 or page 1 |
| 698 | */ |
| 699 | static inline struct page *filemap_get_page(struct bitmap *bitmap, |
| 700 | unsigned long chunk) |
| 701 | { |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 702 | if (bitmap->filemap == NULL) |
| 703 | return NULL; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 704 | if (file_page_index(bitmap, chunk) >= bitmap->file_pages) |
| 705 | return NULL; |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 706 | return bitmap->filemap[file_page_index(bitmap, chunk) |
| 707 | - file_page_index(bitmap, 0)]; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 708 | } |
| 709 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 710 | static void bitmap_file_unmap(struct bitmap *bitmap) |
| 711 | { |
| 712 | struct page **map, *sb_page; |
| 713 | unsigned long *attr; |
| 714 | int pages; |
| 715 | unsigned long flags; |
| 716 | |
| 717 | spin_lock_irqsave(&bitmap->lock, flags); |
| 718 | map = bitmap->filemap; |
| 719 | bitmap->filemap = NULL; |
| 720 | attr = bitmap->filemap_attr; |
| 721 | bitmap->filemap_attr = NULL; |
| 722 | pages = bitmap->file_pages; |
| 723 | bitmap->file_pages = 0; |
| 724 | sb_page = bitmap->sb_page; |
| 725 | bitmap->sb_page = NULL; |
| 726 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 727 | |
| 728 | while (pages--) |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 729 | if (map[pages] != sb_page) /* 0 is sb_page, release it below */ |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 730 | free_buffers(map[pages]); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 731 | kfree(map); |
| 732 | kfree(attr); |
| 733 | |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 734 | if (sb_page) |
| 735 | free_buffers(sb_page); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | static void bitmap_file_put(struct bitmap *bitmap) |
| 739 | { |
| 740 | struct file *file; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 741 | unsigned long flags; |
| 742 | |
| 743 | spin_lock_irqsave(&bitmap->lock, flags); |
| 744 | file = bitmap->file; |
| 745 | bitmap->file = NULL; |
| 746 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 747 | |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 748 | if (file) |
| 749 | wait_event(bitmap->write_wait, |
| 750 | atomic_read(&bitmap->pending_writes)==0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 751 | bitmap_file_unmap(bitmap); |
| 752 | |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 753 | if (file) { |
Josef Sipek | c649bb9 | 2006-12-08 02:37:19 -0800 | [diff] [blame] | 754 | struct inode *inode = file->f_path.dentry->d_inode; |
Andrew Morton | fc0ecff | 2007-02-10 01:45:39 -0800 | [diff] [blame] | 755 | invalidate_mapping_pages(inode->i_mapping, 0, -1); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 756 | fput(file); |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 757 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 758 | } |
| 759 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 760 | /* |
| 761 | * bitmap_file_kick - if an error occurs while manipulating the bitmap file |
| 762 | * then it is no longer reliable, so we stop using it and we mark the file |
| 763 | * as failed in the superblock |
| 764 | */ |
| 765 | static void bitmap_file_kick(struct bitmap *bitmap) |
| 766 | { |
| 767 | char *path, *ptr = NULL; |
| 768 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 769 | if (bitmap_mask_state(bitmap, BITMAP_STALE, MASK_SET) == 0) { |
| 770 | bitmap_update_sb(bitmap); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 771 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 772 | if (bitmap->file) { |
| 773 | path = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 774 | if (path) |
Christoph Hellwig | 6bcfd60 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 775 | ptr = d_path(&bitmap->file->f_path, path, |
| 776 | PAGE_SIZE); |
| 777 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 778 | printk(KERN_ALERT |
| 779 | "%s: kicking failed bitmap file %s from array!\n", |
Christoph Hellwig | 6bcfd60 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 780 | bmname(bitmap), IS_ERR(ptr) ? "" : ptr); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 781 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 782 | kfree(path); |
| 783 | } else |
| 784 | printk(KERN_ALERT |
| 785 | "%s: disabling internal bitmap due to errors\n", |
| 786 | bmname(bitmap)); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 787 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 788 | |
| 789 | bitmap_file_put(bitmap); |
| 790 | |
| 791 | return; |
| 792 | } |
| 793 | |
| 794 | enum bitmap_page_attr { |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 795 | BITMAP_PAGE_DIRTY = 0, /* there are set bits that need to be synced */ |
| 796 | BITMAP_PAGE_CLEAN = 1, /* there are bits that might need to be cleared */ |
| 797 | BITMAP_PAGE_NEEDWRITE = 2, /* there are cleared bits that need to be synced */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 798 | }; |
| 799 | |
| 800 | static inline void set_page_attr(struct bitmap *bitmap, struct page *page, |
| 801 | enum bitmap_page_attr attr) |
| 802 | { |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 803 | if (page) |
| 804 | __set_bit((page->index<<2) + attr, bitmap->filemap_attr); |
| 805 | else |
| 806 | __set_bit(attr, &bitmap->logattrs); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | static inline void clear_page_attr(struct bitmap *bitmap, struct page *page, |
| 810 | enum bitmap_page_attr attr) |
| 811 | { |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 812 | if (page) |
| 813 | __clear_bit((page->index<<2) + attr, bitmap->filemap_attr); |
| 814 | else |
| 815 | __clear_bit(attr, &bitmap->logattrs); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 816 | } |
| 817 | |
NeilBrown | ec7a319 | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 818 | static inline unsigned long test_page_attr(struct bitmap *bitmap, struct page *page, |
| 819 | enum bitmap_page_attr attr) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 820 | { |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 821 | if (page) |
| 822 | return test_bit((page->index<<2) + attr, bitmap->filemap_attr); |
| 823 | else |
| 824 | return test_bit(attr, &bitmap->logattrs); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | /* |
| 828 | * bitmap_file_set_bit -- called before performing a write to the md device |
| 829 | * to set (and eventually sync) a particular bit in the bitmap file |
| 830 | * |
| 831 | * we set the bit immediately, then we record the page number so that |
| 832 | * when an unplug occurs, we can flush the dirty pages out to disk |
| 833 | */ |
| 834 | static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) |
| 835 | { |
| 836 | unsigned long bit; |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 837 | struct page *page = NULL; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 838 | void *kaddr; |
| 839 | unsigned long chunk = block >> CHUNK_BLOCK_SHIFT(bitmap); |
| 840 | |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 841 | if (!bitmap->filemap) { |
| 842 | struct dm_dirty_log *log = bitmap->mddev->bitmap_info.log; |
| 843 | if (log) |
| 844 | log->type->mark_region(log, chunk); |
| 845 | } else { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 846 | |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 847 | page = filemap_get_page(bitmap, chunk); |
| 848 | if (!page) |
| 849 | return; |
| 850 | bit = file_page_offset(bitmap, chunk); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 851 | |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 852 | /* set the bit */ |
| 853 | kaddr = kmap_atomic(page, KM_USER0); |
| 854 | if (bitmap->flags & BITMAP_HOSTENDIAN) |
| 855 | set_bit(bit, kaddr); |
| 856 | else |
| 857 | ext2_set_bit(bit, kaddr); |
| 858 | kunmap_atomic(kaddr, KM_USER0); |
| 859 | PRINTK("set file bit %lu page %lu\n", bit, page->index); |
| 860 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 861 | /* record page number so it gets flushed to disk when unplug occurs */ |
| 862 | set_page_attr(bitmap, page, BITMAP_PAGE_DIRTY); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | /* this gets called when the md device is ready to unplug its underlying |
| 866 | * (slave) device queues -- before we let any writes go down, we need to |
| 867 | * sync the dirty pages of the bitmap file to disk */ |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 868 | void bitmap_unplug(struct bitmap *bitmap) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 869 | { |
NeilBrown | ec7a319 | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 870 | unsigned long i, flags; |
| 871 | int dirty, need_write; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 872 | struct page *page; |
| 873 | int wait = 0; |
| 874 | |
| 875 | if (!bitmap) |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 876 | return; |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 877 | if (!bitmap->filemap) { |
| 878 | /* Must be using a dirty_log */ |
| 879 | struct dm_dirty_log *log = bitmap->mddev->bitmap_info.log; |
| 880 | dirty = test_and_clear_bit(BITMAP_PAGE_DIRTY, &bitmap->logattrs); |
| 881 | need_write = test_and_clear_bit(BITMAP_PAGE_NEEDWRITE, &bitmap->logattrs); |
| 882 | if (dirty || need_write) |
| 883 | if (log->type->flush(log)) |
| 884 | bitmap->flags |= BITMAP_WRITE_ERROR; |
| 885 | goto out; |
| 886 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 887 | |
| 888 | /* look at each page to see if there are any set bits that need to be |
| 889 | * flushed out to disk */ |
| 890 | for (i = 0; i < bitmap->file_pages; i++) { |
| 891 | spin_lock_irqsave(&bitmap->lock, flags); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 892 | if (!bitmap->filemap) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 893 | spin_unlock_irqrestore(&bitmap->lock, flags); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 894 | return; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 895 | } |
| 896 | page = bitmap->filemap[i]; |
NeilBrown | ec7a319 | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 897 | dirty = test_page_attr(bitmap, page, BITMAP_PAGE_DIRTY); |
| 898 | need_write = test_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 899 | clear_page_attr(bitmap, page, BITMAP_PAGE_DIRTY); |
| 900 | clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE); |
NeilBrown | ec7a319 | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 901 | if (dirty) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 902 | wait = 1; |
| 903 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 904 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 905 | if (dirty || need_write) |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 906 | write_page(bitmap, page, 0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 907 | } |
| 908 | if (wait) { /* if any writes were performed, we need to wait on them */ |
NeilBrown | 0b79ccf | 2006-06-26 00:27:44 -0700 | [diff] [blame] | 909 | if (bitmap->file) |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 910 | wait_event(bitmap->write_wait, |
| 911 | atomic_read(&bitmap->pending_writes)==0); |
NeilBrown | 0b79ccf | 2006-06-26 00:27:44 -0700 | [diff] [blame] | 912 | else |
NeilBrown | a9701a3 | 2005-11-08 21:39:34 -0800 | [diff] [blame] | 913 | md_super_wait(bitmap->mddev); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 914 | } |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 915 | out: |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 916 | if (bitmap->flags & BITMAP_WRITE_ERROR) |
| 917 | bitmap_file_kick(bitmap); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 918 | } |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 919 | EXPORT_SYMBOL(bitmap_unplug); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 920 | |
NeilBrown | 6a07997 | 2005-09-09 16:23:44 -0700 | [diff] [blame] | 921 | static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 922 | /* * bitmap_init_from_disk -- called at bitmap_create time to initialize |
| 923 | * the in-memory bitmap from the on-disk bitmap -- also, sets up the |
| 924 | * memory mapping of the bitmap file |
| 925 | * Special cases: |
| 926 | * if there's no bitmap file, or if the bitmap file had been |
| 927 | * previously kicked from the array, we mark all the bits as |
| 928 | * 1's in order to cause a full resync. |
NeilBrown | 6a07997 | 2005-09-09 16:23:44 -0700 | [diff] [blame] | 929 | * |
| 930 | * We ignore all bits for sectors that end earlier than 'start'. |
| 931 | * This is used when reading an out-of-date bitmap... |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 932 | */ |
NeilBrown | 6a07997 | 2005-09-09 16:23:44 -0700 | [diff] [blame] | 933 | static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 934 | { |
| 935 | unsigned long i, chunks, index, oldindex, bit; |
| 936 | struct page *page = NULL, *oldpage = NULL; |
| 937 | unsigned long num_pages, bit_cnt = 0; |
| 938 | struct file *file; |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 939 | unsigned long bytes, offset; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 940 | int outofdate; |
| 941 | int ret = -ENOSPC; |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 942 | void *paddr; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 943 | |
| 944 | chunks = bitmap->chunks; |
| 945 | file = bitmap->file; |
| 946 | |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 947 | BUG_ON(!file && !bitmap->mddev->bitmap_info.offset); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 948 | |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 949 | #ifdef INJECT_FAULTS_3 |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 950 | outofdate = 1; |
| 951 | #else |
| 952 | outofdate = bitmap->flags & BITMAP_STALE; |
| 953 | #endif |
| 954 | if (outofdate) |
| 955 | printk(KERN_INFO "%s: bitmap file is out of date, doing full " |
| 956 | "recovery\n", bmname(bitmap)); |
| 957 | |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 958 | bytes = DIV_ROUND_UP(bitmap->chunks, 8); |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 959 | if (!bitmap->mddev->bitmap_info.external) |
| 960 | bytes += sizeof(bitmap_super_t); |
NeilBrown | bc7f77d | 2005-06-21 17:17:17 -0700 | [diff] [blame] | 961 | |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 962 | num_pages = DIV_ROUND_UP(bytes, PAGE_SIZE); |
NeilBrown | bc7f77d | 2005-06-21 17:17:17 -0700 | [diff] [blame] | 963 | |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 964 | if (file && i_size_read(file->f_mapping->host) < bytes) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 965 | printk(KERN_INFO "%s: bitmap file too short %lu < %lu\n", |
| 966 | bmname(bitmap), |
| 967 | (unsigned long) i_size_read(file->f_mapping->host), |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 968 | bytes); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 969 | goto err; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 970 | } |
NeilBrown | bc7f77d | 2005-06-21 17:17:17 -0700 | [diff] [blame] | 971 | |
| 972 | ret = -ENOMEM; |
| 973 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 974 | bitmap->filemap = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL); |
NeilBrown | bc7f77d | 2005-06-21 17:17:17 -0700 | [diff] [blame] | 975 | if (!bitmap->filemap) |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 976 | goto err; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 977 | |
NeilBrown | e16b68b | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 978 | /* We need 4 bits per page, rounded up to a multiple of sizeof(unsigned long) */ |
| 979 | bitmap->filemap_attr = kzalloc( |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 980 | roundup(DIV_ROUND_UP(num_pages*4, 8), sizeof(unsigned long)), |
NeilBrown | e16b68b | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 981 | GFP_KERNEL); |
NeilBrown | bc7f77d | 2005-06-21 17:17:17 -0700 | [diff] [blame] | 982 | if (!bitmap->filemap_attr) |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 983 | goto err; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 984 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 985 | oldindex = ~0L; |
| 986 | |
| 987 | for (i = 0; i < chunks; i++) { |
NeilBrown | bd926c6 | 2005-11-08 21:39:32 -0800 | [diff] [blame] | 988 | int b; |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 989 | index = file_page_index(bitmap, i); |
| 990 | bit = file_page_offset(bitmap, i); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 991 | if (index != oldindex) { /* this is a new page, read it in */ |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 992 | int count; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 993 | /* unmap the old page, we're done with it */ |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 994 | if (index == num_pages-1) |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 995 | count = bytes - index * PAGE_SIZE; |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 996 | else |
| 997 | count = PAGE_SIZE; |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 998 | if (index == 0 && bitmap->sb_page) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 999 | /* |
| 1000 | * if we're here then the superblock page |
| 1001 | * contains some bits (PAGE_SIZE != sizeof sb) |
| 1002 | * we've already read it in, so just use it |
| 1003 | */ |
| 1004 | page = bitmap->sb_page; |
| 1005 | offset = sizeof(bitmap_super_t); |
NeilBrown | 5384527 | 2009-01-09 08:31:05 +1100 | [diff] [blame] | 1006 | if (!file) |
Vasiliy Kulikov | 5c04f55 | 2010-10-01 14:18:12 -0700 | [diff] [blame] | 1007 | page = read_sb_page( |
| 1008 | bitmap->mddev, |
| 1009 | bitmap->mddev->bitmap_info.offset, |
| 1010 | page, |
| 1011 | index, count); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1012 | } else if (file) { |
NeilBrown | d785a06 | 2006-06-26 00:27:48 -0700 | [diff] [blame] | 1013 | page = read_page(file, index, bitmap, count); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1014 | offset = 0; |
| 1015 | } else { |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1016 | page = read_sb_page(bitmap->mddev, |
| 1017 | bitmap->mddev->bitmap_info.offset, |
NeilBrown | a2ed961 | 2008-12-19 16:25:01 +1100 | [diff] [blame] | 1018 | NULL, |
| 1019 | index, count); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1020 | offset = 0; |
| 1021 | } |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1022 | if (IS_ERR(page)) { /* read error */ |
| 1023 | ret = PTR_ERR(page); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1024 | goto err; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1027 | oldindex = index; |
| 1028 | oldpage = page; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1029 | |
NeilBrown | b74fd28 | 2009-05-07 12:47:19 +1000 | [diff] [blame] | 1030 | bitmap->filemap[bitmap->file_pages++] = page; |
| 1031 | bitmap->last_page_size = count; |
| 1032 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1033 | if (outofdate) { |
| 1034 | /* |
| 1035 | * if bitmap is out of date, dirty the |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1036 | * whole page and write it out |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1037 | */ |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 1038 | paddr = kmap_atomic(page, KM_USER0); |
| 1039 | memset(paddr + offset, 0xff, |
NeilBrown | 6a07997 | 2005-09-09 16:23:44 -0700 | [diff] [blame] | 1040 | PAGE_SIZE - offset); |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 1041 | kunmap_atomic(paddr, KM_USER0); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1042 | write_page(bitmap, page, 1); |
| 1043 | |
| 1044 | ret = -EIO; |
NeilBrown | b74fd28 | 2009-05-07 12:47:19 +1000 | [diff] [blame] | 1045 | if (bitmap->flags & BITMAP_WRITE_ERROR) |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1046 | goto err; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1047 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1048 | } |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 1049 | paddr = kmap_atomic(page, KM_USER0); |
NeilBrown | bd926c6 | 2005-11-08 21:39:32 -0800 | [diff] [blame] | 1050 | if (bitmap->flags & BITMAP_HOSTENDIAN) |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 1051 | b = test_bit(bit, paddr); |
NeilBrown | bd926c6 | 2005-11-08 21:39:32 -0800 | [diff] [blame] | 1052 | else |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 1053 | b = ext2_test_bit(bit, paddr); |
| 1054 | kunmap_atomic(paddr, KM_USER0); |
NeilBrown | bd926c6 | 2005-11-08 21:39:32 -0800 | [diff] [blame] | 1055 | if (b) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1056 | /* if the disk bit is set, set the memory bit */ |
NeilBrown | db305e5 | 2009-05-07 12:49:06 +1000 | [diff] [blame] | 1057 | int needed = ((sector_t)(i+1) << (CHUNK_BLOCK_SHIFT(bitmap)) |
| 1058 | >= start); |
| 1059 | bitmap_set_memory_bits(bitmap, |
| 1060 | (sector_t)i << CHUNK_BLOCK_SHIFT(bitmap), |
| 1061 | needed); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1062 | bit_cnt++; |
NeilBrown | 6a07997 | 2005-09-09 16:23:44 -0700 | [diff] [blame] | 1063 | set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1064 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1067 | /* everything went OK */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1068 | ret = 0; |
| 1069 | bitmap_mask_state(bitmap, BITMAP_STALE, MASK_UNSET); |
| 1070 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1071 | if (bit_cnt) { /* Kick recovery if any bits were set */ |
| 1072 | set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery); |
| 1073 | md_wakeup_thread(bitmap->mddev->thread); |
| 1074 | } |
| 1075 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1076 | printk(KERN_INFO "%s: bitmap initialized from disk: " |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1077 | "read %lu/%lu pages, set %lu bits\n", |
| 1078 | bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1079 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1080 | return 0; |
| 1081 | |
| 1082 | err: |
| 1083 | printk(KERN_INFO "%s: bitmap initialisation failed: %d\n", |
| 1084 | bmname(bitmap), ret); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1085 | return ret; |
| 1086 | } |
| 1087 | |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1088 | void bitmap_write_all(struct bitmap *bitmap) |
| 1089 | { |
| 1090 | /* We don't actually write all bitmap blocks here, |
| 1091 | * just flag them as needing to be written |
| 1092 | */ |
NeilBrown | ec7a319 | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 1093 | int i; |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1094 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1095 | for (i = 0; i < bitmap->file_pages; i++) |
NeilBrown | ec7a319 | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 1096 | set_page_attr(bitmap, bitmap->filemap[i], |
| 1097 | BITMAP_PAGE_NEEDWRITE); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1100 | static void bitmap_count_page(struct bitmap *bitmap, sector_t offset, int inc) |
| 1101 | { |
| 1102 | sector_t chunk = offset >> CHUNK_BLOCK_SHIFT(bitmap); |
| 1103 | unsigned long page = chunk >> PAGE_COUNTER_SHIFT; |
| 1104 | bitmap->bp[page].count += inc; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1105 | bitmap_checkfree(bitmap, page); |
| 1106 | } |
| 1107 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1108 | sector_t offset, sector_t *blocks, |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1109 | int create); |
| 1110 | |
| 1111 | /* |
| 1112 | * bitmap daemon -- periodically wakes up to clean bits and flush pages |
| 1113 | * out to disk |
| 1114 | */ |
| 1115 | |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1116 | void bitmap_daemon_work(mddev_t *mddev) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1117 | { |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1118 | struct bitmap *bitmap; |
NeilBrown | aa3163f | 2005-06-21 17:17:22 -0700 | [diff] [blame] | 1119 | unsigned long j; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1120 | unsigned long flags; |
| 1121 | struct page *page = NULL, *lastpage = NULL; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1122 | sector_t blocks; |
NeilBrown | ea03aff | 2006-01-06 00:20:34 -0800 | [diff] [blame] | 1123 | void *paddr; |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1124 | struct dm_dirty_log *log = mddev->bitmap_info.log; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1125 | |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1126 | /* Use a mutex to guard daemon_work against |
| 1127 | * bitmap_destroy. |
| 1128 | */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1129 | mutex_lock(&mddev->bitmap_info.mutex); |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1130 | bitmap = mddev->bitmap; |
| 1131 | if (bitmap == NULL) { |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1132 | mutex_unlock(&mddev->bitmap_info.mutex); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1133 | return; |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1134 | } |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1135 | if (time_before(jiffies, bitmap->daemon_lastrun |
NeilBrown | 1b04be9 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1136 | + bitmap->mddev->bitmap_info.daemon_sleep)) |
NeilBrown | 7be3dfe | 2008-03-10 11:43:48 -0700 | [diff] [blame] | 1137 | goto done; |
| 1138 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1139 | bitmap->daemon_lastrun = jiffies; |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1140 | if (bitmap->allclean) { |
| 1141 | bitmap->mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT; |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1142 | goto done; |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1143 | } |
| 1144 | bitmap->allclean = 1; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1145 | |
NeilBrown | be51269 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 1146 | spin_lock_irqsave(&bitmap->lock, flags); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1147 | for (j = 0; j < bitmap->chunks; j++) { |
| 1148 | bitmap_counter_t *bmc; |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1149 | if (!bitmap->filemap) { |
| 1150 | if (!log) |
| 1151 | /* error or shutdown */ |
| 1152 | break; |
| 1153 | } else |
| 1154 | page = filemap_get_page(bitmap, j); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1155 | |
| 1156 | if (page != lastpage) { |
NeilBrown | aa3163f | 2005-06-21 17:17:22 -0700 | [diff] [blame] | 1157 | /* skip this page unless it's marked as needing cleaning */ |
NeilBrown | ec7a319 | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 1158 | if (!test_page_attr(bitmap, page, BITMAP_PAGE_CLEAN)) { |
| 1159 | int need_write = test_page_attr(bitmap, page, |
| 1160 | BITMAP_PAGE_NEEDWRITE); |
NeilBrown | a647e4b | 2006-06-26 00:27:46 -0700 | [diff] [blame] | 1161 | if (need_write) |
NeilBrown | aa3163f | 2005-06-21 17:17:22 -0700 | [diff] [blame] | 1162 | clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE); |
NeilBrown | a647e4b | 2006-06-26 00:27:46 -0700 | [diff] [blame] | 1163 | |
NeilBrown | aa3163f | 2005-06-21 17:17:22 -0700 | [diff] [blame] | 1164 | spin_unlock_irqrestore(&bitmap->lock, flags); |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1165 | if (need_write) { |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1166 | write_page(bitmap, page, 0); |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1167 | bitmap->allclean = 0; |
| 1168 | } |
NeilBrown | be51269 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 1169 | spin_lock_irqsave(&bitmap->lock, flags); |
| 1170 | j |= (PAGE_BITS - 1); |
NeilBrown | aa3163f | 2005-06-21 17:17:22 -0700 | [diff] [blame] | 1171 | continue; |
| 1172 | } |
| 1173 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1174 | /* grab the new page, sync and release the old */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1175 | if (lastpage != NULL) { |
NeilBrown | ec7a319 | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 1176 | if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1177 | clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); |
| 1178 | spin_unlock_irqrestore(&bitmap->lock, flags); |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1179 | write_page(bitmap, lastpage, 0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1180 | } else { |
| 1181 | set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); |
| 1182 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 1183 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1184 | } else |
| 1185 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 1186 | lastpage = page; |
Neil Brown | a0da84f | 2008-06-28 08:31:22 +1000 | [diff] [blame] | 1187 | |
| 1188 | /* We are possibly going to clear some bits, so make |
| 1189 | * sure that events_cleared is up-to-date. |
| 1190 | */ |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1191 | if (bitmap->need_sync && |
| 1192 | bitmap->mddev->bitmap_info.external == 0) { |
Neil Brown | a0da84f | 2008-06-28 08:31:22 +1000 | [diff] [blame] | 1193 | bitmap_super_t *sb; |
| 1194 | bitmap->need_sync = 0; |
| 1195 | sb = kmap_atomic(bitmap->sb_page, KM_USER0); |
| 1196 | sb->events_cleared = |
| 1197 | cpu_to_le64(bitmap->events_cleared); |
| 1198 | kunmap_atomic(sb, KM_USER0); |
| 1199 | write_page(bitmap, bitmap->sb_page, 1); |
| 1200 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1201 | spin_lock_irqsave(&bitmap->lock, flags); |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1202 | if (!bitmap->need_sync) |
| 1203 | clear_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1204 | } |
NeilBrown | db305e5 | 2009-05-07 12:49:06 +1000 | [diff] [blame] | 1205 | bmc = bitmap_get_counter(bitmap, |
| 1206 | (sector_t)j << CHUNK_BLOCK_SHIFT(bitmap), |
| 1207 | &blocks, 0); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1208 | if (bmc) { |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1209 | if (*bmc) |
| 1210 | bitmap->allclean = 0; |
| 1211 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1212 | if (*bmc == 2) { |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1213 | *bmc = 1; /* maybe clear the bit next time */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1214 | set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1215 | } else if (*bmc == 1 && !bitmap->need_sync) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1216 | /* we can clear the bit */ |
| 1217 | *bmc = 0; |
NeilBrown | db305e5 | 2009-05-07 12:49:06 +1000 | [diff] [blame] | 1218 | bitmap_count_page(bitmap, |
| 1219 | (sector_t)j << CHUNK_BLOCK_SHIFT(bitmap), |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1220 | -1); |
| 1221 | |
| 1222 | /* clear the bit */ |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1223 | if (page) { |
| 1224 | paddr = kmap_atomic(page, KM_USER0); |
| 1225 | if (bitmap->flags & BITMAP_HOSTENDIAN) |
| 1226 | clear_bit(file_page_offset(bitmap, j), |
| 1227 | paddr); |
| 1228 | else |
| 1229 | ext2_clear_bit(file_page_offset(bitmap, j), |
| 1230 | paddr); |
| 1231 | kunmap_atomic(paddr, KM_USER0); |
| 1232 | } else |
| 1233 | log->type->clear_region(log, j); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1234 | } |
NeilBrown | be51269 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 1235 | } else |
| 1236 | j |= PAGE_COUNTER_MASK; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1237 | } |
NeilBrown | be51269 | 2009-05-26 09:41:17 +1000 | [diff] [blame] | 1238 | spin_unlock_irqrestore(&bitmap->lock, flags); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1239 | |
| 1240 | /* now sync the final page */ |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1241 | if (lastpage != NULL || log != NULL) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1242 | spin_lock_irqsave(&bitmap->lock, flags); |
NeilBrown | ec7a319 | 2006-06-26 00:27:45 -0700 | [diff] [blame] | 1243 | if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1244 | clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); |
| 1245 | spin_unlock_irqrestore(&bitmap->lock, flags); |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1246 | if (lastpage) |
| 1247 | write_page(bitmap, lastpage, 0); |
| 1248 | else |
| 1249 | if (log->type->flush(log)) |
| 1250 | bitmap->flags |= BITMAP_WRITE_ERROR; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1251 | } else { |
| 1252 | set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); |
| 1253 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 1254 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
NeilBrown | 7be3dfe | 2008-03-10 11:43:48 -0700 | [diff] [blame] | 1257 | done: |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1258 | if (bitmap->allclean == 0) |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1259 | bitmap->mddev->thread->timeout = |
NeilBrown | 1b04be9 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1260 | bitmap->mddev->bitmap_info.daemon_sleep; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1261 | mutex_unlock(&mddev->bitmap_info.mutex); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1264 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1265 | sector_t offset, sector_t *blocks, |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1266 | int create) |
NeilBrown | ee305ac | 2009-09-23 18:06:44 +1000 | [diff] [blame] | 1267 | __releases(bitmap->lock) |
| 1268 | __acquires(bitmap->lock) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1269 | { |
| 1270 | /* If 'create', we might release the lock and reclaim it. |
| 1271 | * The lock must have been taken with interrupts enabled. |
| 1272 | * If !create, we don't release the lock. |
| 1273 | */ |
| 1274 | sector_t chunk = offset >> CHUNK_BLOCK_SHIFT(bitmap); |
| 1275 | unsigned long page = chunk >> PAGE_COUNTER_SHIFT; |
| 1276 | unsigned long pageoff = (chunk & PAGE_COUNTER_MASK) << COUNTER_BYTE_SHIFT; |
| 1277 | sector_t csize; |
NeilBrown | ef42567 | 2010-06-01 19:37:33 +1000 | [diff] [blame] | 1278 | int err; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1279 | |
NeilBrown | ef42567 | 2010-06-01 19:37:33 +1000 | [diff] [blame] | 1280 | err = bitmap_checkpage(bitmap, page, create); |
| 1281 | |
| 1282 | if (bitmap->bp[page].hijacked || |
| 1283 | bitmap->bp[page].map == NULL) |
| 1284 | csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap) + |
| 1285 | PAGE_COUNTER_SHIFT - 1); |
| 1286 | else |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1287 | csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap)); |
NeilBrown | ef42567 | 2010-06-01 19:37:33 +1000 | [diff] [blame] | 1288 | *blocks = csize - (offset & (csize - 1)); |
| 1289 | |
| 1290 | if (err < 0) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1291 | return NULL; |
NeilBrown | ef42567 | 2010-06-01 19:37:33 +1000 | [diff] [blame] | 1292 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1293 | /* now locked ... */ |
| 1294 | |
| 1295 | if (bitmap->bp[page].hijacked) { /* hijacked pointer */ |
| 1296 | /* should we use the first or second counter field |
| 1297 | * of the hijacked pointer? */ |
| 1298 | int hi = (pageoff > PAGE_COUNTER_MASK); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1299 | return &((bitmap_counter_t *) |
| 1300 | &bitmap->bp[page].map)[hi]; |
NeilBrown | ef42567 | 2010-06-01 19:37:33 +1000 | [diff] [blame] | 1301 | } else /* page is allocated */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1302 | return (bitmap_counter_t *) |
| 1303 | &(bitmap->bp[page].map[pageoff]); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 1306 | int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1307 | { |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1308 | if (!bitmap) |
| 1309 | return 0; |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 1310 | |
| 1311 | if (behind) { |
Paul Clements | 696fcd5 | 2010-03-08 16:02:37 +1100 | [diff] [blame] | 1312 | int bw; |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 1313 | atomic_inc(&bitmap->behind_writes); |
Paul Clements | 696fcd5 | 2010-03-08 16:02:37 +1100 | [diff] [blame] | 1314 | bw = atomic_read(&bitmap->behind_writes); |
| 1315 | if (bw > bitmap->behind_writes_used) |
| 1316 | bitmap->behind_writes_used = bw; |
| 1317 | |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 1318 | PRINTK(KERN_DEBUG "inc write-behind count %d/%d\n", |
Paul Clements | 696fcd5 | 2010-03-08 16:02:37 +1100 | [diff] [blame] | 1319 | bw, bitmap->max_write_behind); |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1322 | while (sectors) { |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1323 | sector_t blocks; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1324 | bitmap_counter_t *bmc; |
| 1325 | |
| 1326 | spin_lock_irq(&bitmap->lock); |
| 1327 | bmc = bitmap_get_counter(bitmap, offset, &blocks, 1); |
| 1328 | if (!bmc) { |
| 1329 | spin_unlock_irq(&bitmap->lock); |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
Neil Brown | da6e1a3 | 2007-02-08 14:20:37 -0800 | [diff] [blame] | 1333 | if (unlikely((*bmc & COUNTER_MAX) == COUNTER_MAX)) { |
| 1334 | DEFINE_WAIT(__wait); |
| 1335 | /* note that it is safe to do the prepare_to_wait |
| 1336 | * after the test as long as we do it before dropping |
| 1337 | * the spinlock. |
| 1338 | */ |
| 1339 | prepare_to_wait(&bitmap->overflow_wait, &__wait, |
| 1340 | TASK_UNINTERRUPTIBLE); |
| 1341 | spin_unlock_irq(&bitmap->lock); |
NeilBrown | b63d7c2 | 2010-06-01 19:37:33 +1000 | [diff] [blame] | 1342 | md_unplug(bitmap->mddev); |
Neil Brown | da6e1a3 | 2007-02-08 14:20:37 -0800 | [diff] [blame] | 1343 | schedule(); |
| 1344 | finish_wait(&bitmap->overflow_wait, &__wait); |
| 1345 | continue; |
| 1346 | } |
| 1347 | |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1348 | switch (*bmc) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1349 | case 0: |
| 1350 | bitmap_file_set_bit(bitmap, offset); |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1351 | bitmap_count_page(bitmap, offset, 1); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1352 | /* fall through */ |
| 1353 | case 1: |
| 1354 | *bmc = 2; |
| 1355 | } |
Neil Brown | da6e1a3 | 2007-02-08 14:20:37 -0800 | [diff] [blame] | 1356 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1357 | (*bmc)++; |
| 1358 | |
| 1359 | spin_unlock_irq(&bitmap->lock); |
| 1360 | |
| 1361 | offset += blocks; |
| 1362 | if (sectors > blocks) |
| 1363 | sectors -= blocks; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1364 | else |
| 1365 | sectors = 0; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1366 | } |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1367 | bitmap->allclean = 0; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1368 | return 0; |
| 1369 | } |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1370 | EXPORT_SYMBOL(bitmap_startwrite); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1371 | |
| 1372 | void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 1373 | int success, int behind) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1374 | { |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1375 | if (!bitmap) |
| 1376 | return; |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 1377 | if (behind) { |
NeilBrown | e555190 | 2010-03-31 11:21:44 +1100 | [diff] [blame] | 1378 | if (atomic_dec_and_test(&bitmap->behind_writes)) |
| 1379 | wake_up(&bitmap->behind_wait); |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 1380 | PRINTK(KERN_DEBUG "dec write-behind count %d/%d\n", |
| 1381 | atomic_read(&bitmap->behind_writes), bitmap->max_write_behind); |
| 1382 | } |
NeilBrown | d0a4bb4 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1383 | if (bitmap->mddev->degraded) |
| 1384 | /* Never clear bits or update events_cleared when degraded */ |
| 1385 | success = 0; |
NeilBrown | 4b6d287 | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 1386 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1387 | while (sectors) { |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1388 | sector_t blocks; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1389 | unsigned long flags; |
| 1390 | bitmap_counter_t *bmc; |
| 1391 | |
| 1392 | spin_lock_irqsave(&bitmap->lock, flags); |
| 1393 | bmc = bitmap_get_counter(bitmap, offset, &blocks, 0); |
| 1394 | if (!bmc) { |
| 1395 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 1396 | return; |
| 1397 | } |
| 1398 | |
Neil Brown | a0da84f | 2008-06-28 08:31:22 +1000 | [diff] [blame] | 1399 | if (success && |
| 1400 | bitmap->events_cleared < bitmap->mddev->events) { |
| 1401 | bitmap->events_cleared = bitmap->mddev->events; |
| 1402 | bitmap->need_sync = 1; |
NeilBrown | 5ff5aff | 2010-06-01 19:37:32 +1000 | [diff] [blame] | 1403 | sysfs_notify_dirent_safe(bitmap->sysfs_can_clear); |
Neil Brown | a0da84f | 2008-06-28 08:31:22 +1000 | [diff] [blame] | 1404 | } |
| 1405 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1406 | if (!success && ! (*bmc & NEEDED_MASK)) |
| 1407 | *bmc |= NEEDED_MASK; |
| 1408 | |
Neil Brown | da6e1a3 | 2007-02-08 14:20:37 -0800 | [diff] [blame] | 1409 | if ((*bmc & COUNTER_MAX) == COUNTER_MAX) |
| 1410 | wake_up(&bitmap->overflow_wait); |
| 1411 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1412 | (*bmc)--; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1413 | if (*bmc <= 2) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1414 | set_page_attr(bitmap, |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1415 | filemap_get_page( |
| 1416 | bitmap, |
| 1417 | offset >> CHUNK_BLOCK_SHIFT(bitmap)), |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1418 | BITMAP_PAGE_CLEAN); |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1419 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1420 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 1421 | offset += blocks; |
| 1422 | if (sectors > blocks) |
| 1423 | sectors -= blocks; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1424 | else |
| 1425 | sectors = 0; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1426 | } |
| 1427 | } |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1428 | EXPORT_SYMBOL(bitmap_endwrite); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1429 | |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1430 | static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, |
NeilBrown | 1187cf0 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1431 | int degraded) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1432 | { |
| 1433 | bitmap_counter_t *bmc; |
| 1434 | int rv; |
| 1435 | if (bitmap == NULL) {/* FIXME or bitmap set as 'failed' */ |
| 1436 | *blocks = 1024; |
| 1437 | return 1; /* always resync if no bitmap */ |
| 1438 | } |
| 1439 | spin_lock_irq(&bitmap->lock); |
| 1440 | bmc = bitmap_get_counter(bitmap, offset, blocks, 0); |
| 1441 | rv = 0; |
| 1442 | if (bmc) { |
| 1443 | /* locked */ |
| 1444 | if (RESYNC(*bmc)) |
| 1445 | rv = 1; |
| 1446 | else if (NEEDED(*bmc)) { |
| 1447 | rv = 1; |
NeilBrown | 6a806c5 | 2005-07-15 03:56:35 -0700 | [diff] [blame] | 1448 | if (!degraded) { /* don't set/clear bits if degraded */ |
| 1449 | *bmc |= RESYNC_MASK; |
| 1450 | *bmc &= ~NEEDED_MASK; |
| 1451 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | spin_unlock_irq(&bitmap->lock); |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1455 | bitmap->allclean = 0; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1456 | return rv; |
| 1457 | } |
| 1458 | |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1459 | int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, |
NeilBrown | 1187cf0 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1460 | int degraded) |
| 1461 | { |
| 1462 | /* bitmap_start_sync must always report on multiples of whole |
| 1463 | * pages, otherwise resync (which is very PAGE_SIZE based) will |
| 1464 | * get confused. |
| 1465 | * So call __bitmap_start_sync repeatedly (if needed) until |
| 1466 | * At least PAGE_SIZE>>9 blocks are covered. |
| 1467 | * Return the 'or' of the result. |
| 1468 | */ |
| 1469 | int rv = 0; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1470 | sector_t blocks1; |
NeilBrown | 1187cf0 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1471 | |
| 1472 | *blocks = 0; |
| 1473 | while (*blocks < (PAGE_SIZE>>9)) { |
| 1474 | rv |= __bitmap_start_sync(bitmap, offset, |
| 1475 | &blocks1, degraded); |
| 1476 | offset += blocks1; |
| 1477 | *blocks += blocks1; |
| 1478 | } |
| 1479 | return rv; |
| 1480 | } |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1481 | EXPORT_SYMBOL(bitmap_start_sync); |
NeilBrown | 1187cf0 | 2009-03-31 14:27:02 +1100 | [diff] [blame] | 1482 | |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1483 | void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1484 | { |
| 1485 | bitmap_counter_t *bmc; |
| 1486 | unsigned long flags; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1487 | |
| 1488 | if (bitmap == NULL) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1489 | *blocks = 1024; |
| 1490 | return; |
| 1491 | } |
| 1492 | spin_lock_irqsave(&bitmap->lock, flags); |
| 1493 | bmc = bitmap_get_counter(bitmap, offset, blocks, 0); |
| 1494 | if (bmc == NULL) |
| 1495 | goto unlock; |
| 1496 | /* locked */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1497 | if (RESYNC(*bmc)) { |
| 1498 | *bmc &= ~RESYNC_MASK; |
| 1499 | |
| 1500 | if (!NEEDED(*bmc) && aborted) |
| 1501 | *bmc |= NEEDED_MASK; |
| 1502 | else { |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1503 | if (*bmc <= 2) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1504 | set_page_attr(bitmap, |
| 1505 | filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)), |
| 1506 | BITMAP_PAGE_CLEAN); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | unlock: |
| 1510 | spin_unlock_irqrestore(&bitmap->lock, flags); |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1511 | bitmap->allclean = 0; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1512 | } |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1513 | EXPORT_SYMBOL(bitmap_end_sync); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1514 | |
| 1515 | void bitmap_close_sync(struct bitmap *bitmap) |
| 1516 | { |
| 1517 | /* Sync has finished, and any bitmap chunks that weren't synced |
| 1518 | * properly have been aborted. It remains to us to clear the |
| 1519 | * RESYNC bit wherever it is still on |
| 1520 | */ |
| 1521 | sector_t sector = 0; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1522 | sector_t blocks; |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 1523 | if (!bitmap) |
| 1524 | return; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1525 | while (sector < bitmap->mddev->resync_max_sectors) { |
| 1526 | bitmap_end_sync(bitmap, sector, &blocks, 0); |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 1527 | sector += blocks; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1528 | } |
| 1529 | } |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1530 | EXPORT_SYMBOL(bitmap_close_sync); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1531 | |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 1532 | void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector) |
| 1533 | { |
| 1534 | sector_t s = 0; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1535 | sector_t blocks; |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 1536 | |
| 1537 | if (!bitmap) |
| 1538 | return; |
| 1539 | if (sector == 0) { |
| 1540 | bitmap->last_end_sync = jiffies; |
| 1541 | return; |
| 1542 | } |
| 1543 | if (time_before(jiffies, (bitmap->last_end_sync |
NeilBrown | 1b04be9 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1544 | + bitmap->mddev->bitmap_info.daemon_sleep))) |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 1545 | return; |
| 1546 | wait_event(bitmap->mddev->recovery_wait, |
| 1547 | atomic_read(&bitmap->mddev->recovery_active) == 0); |
| 1548 | |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 1549 | bitmap->mddev->curr_resync_completed = sector; |
NeilBrown | 070dc6d | 2010-08-30 17:33:34 +1000 | [diff] [blame] | 1550 | set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags); |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 1551 | sector &= ~((1ULL << CHUNK_BLOCK_SHIFT(bitmap)) - 1); |
| 1552 | s = 0; |
| 1553 | while (s < sector && s < bitmap->mddev->resync_max_sectors) { |
| 1554 | bitmap_end_sync(bitmap, s, &blocks, 0); |
| 1555 | s += blocks; |
| 1556 | } |
| 1557 | bitmap->last_end_sync = jiffies; |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 1558 | sysfs_notify(&bitmap->mddev->kobj, NULL, "sync_completed"); |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 1559 | } |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1560 | EXPORT_SYMBOL(bitmap_cond_end_sync); |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 1561 | |
NeilBrown | 6a07997 | 2005-09-09 16:23:44 -0700 | [diff] [blame] | 1562 | static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1563 | { |
| 1564 | /* For each chunk covered by any of these sectors, set the |
NeilBrown | 193f1c9 | 2005-08-04 12:53:33 -0700 | [diff] [blame] | 1565 | * counter to 1 and set resync_needed. They should all |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1566 | * be 0 at this point |
| 1567 | */ |
NeilBrown | 193f1c9 | 2005-08-04 12:53:33 -0700 | [diff] [blame] | 1568 | |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1569 | sector_t secs; |
NeilBrown | 193f1c9 | 2005-08-04 12:53:33 -0700 | [diff] [blame] | 1570 | bitmap_counter_t *bmc; |
| 1571 | spin_lock_irq(&bitmap->lock); |
| 1572 | bmc = bitmap_get_counter(bitmap, offset, &secs, 1); |
| 1573 | if (!bmc) { |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1574 | spin_unlock_irq(&bitmap->lock); |
NeilBrown | 193f1c9 | 2005-08-04 12:53:33 -0700 | [diff] [blame] | 1575 | return; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1576 | } |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1577 | if (!*bmc) { |
NeilBrown | 193f1c9 | 2005-08-04 12:53:33 -0700 | [diff] [blame] | 1578 | struct page *page; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1579 | *bmc = 1 | (needed ? NEEDED_MASK : 0); |
NeilBrown | 193f1c9 | 2005-08-04 12:53:33 -0700 | [diff] [blame] | 1580 | bitmap_count_page(bitmap, offset, 1); |
| 1581 | page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)); |
| 1582 | set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); |
| 1583 | } |
| 1584 | spin_unlock_irq(&bitmap->lock); |
NeilBrown | 8311c29 | 2008-03-04 14:29:30 -0800 | [diff] [blame] | 1585 | bitmap->allclean = 0; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 1588 | /* dirty the memory and file bits for bitmap chunks "s" to "e" */ |
| 1589 | void bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e) |
| 1590 | { |
| 1591 | unsigned long chunk; |
| 1592 | |
| 1593 | for (chunk = s; chunk <= e; chunk++) { |
NeilBrown | db305e5 | 2009-05-07 12:49:06 +1000 | [diff] [blame] | 1594 | sector_t sec = (sector_t)chunk << CHUNK_BLOCK_SHIFT(bitmap); |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 1595 | bitmap_set_memory_bits(bitmap, sec, 1); |
| 1596 | bitmap_file_set_bit(bitmap, sec); |
NeilBrown | ffa2332 | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1597 | if (sec < bitmap->mddev->recovery_cp) |
| 1598 | /* We are asserting that the array is dirty, |
| 1599 | * so move the recovery_cp address back so |
| 1600 | * that it is obvious that it is dirty |
| 1601 | */ |
| 1602 | bitmap->mddev->recovery_cp = sec; |
Paul Clements | 9b1d1da | 2006-10-03 01:15:49 -0700 | [diff] [blame] | 1603 | } |
| 1604 | } |
| 1605 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1606 | /* |
NeilBrown | 6b8b3e8 | 2005-08-04 12:53:35 -0700 | [diff] [blame] | 1607 | * flush out any pending updates |
| 1608 | */ |
| 1609 | void bitmap_flush(mddev_t *mddev) |
| 1610 | { |
| 1611 | struct bitmap *bitmap = mddev->bitmap; |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1612 | long sleep; |
NeilBrown | 6b8b3e8 | 2005-08-04 12:53:35 -0700 | [diff] [blame] | 1613 | |
| 1614 | if (!bitmap) /* there was no bitmap */ |
| 1615 | return; |
| 1616 | |
| 1617 | /* run the daemon_work three time to ensure everything is flushed |
| 1618 | * that can be |
| 1619 | */ |
NeilBrown | 1b04be9 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1620 | sleep = mddev->bitmap_info.daemon_sleep * 2; |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1621 | bitmap->daemon_lastrun -= sleep; |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1622 | bitmap_daemon_work(mddev); |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1623 | bitmap->daemon_lastrun -= sleep; |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1624 | bitmap_daemon_work(mddev); |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1625 | bitmap->daemon_lastrun -= sleep; |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1626 | bitmap_daemon_work(mddev); |
NeilBrown | 6b8b3e8 | 2005-08-04 12:53:35 -0700 | [diff] [blame] | 1627 | bitmap_update_sb(bitmap); |
| 1628 | } |
| 1629 | |
| 1630 | /* |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1631 | * free memory that was allocated |
| 1632 | */ |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1633 | static void bitmap_free(struct bitmap *bitmap) |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1634 | { |
| 1635 | unsigned long k, pages; |
| 1636 | struct bitmap_page *bp; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1637 | |
| 1638 | if (!bitmap) /* there was no bitmap */ |
| 1639 | return; |
| 1640 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1641 | /* release the bitmap file and kill the daemon */ |
| 1642 | bitmap_file_put(bitmap); |
| 1643 | |
| 1644 | bp = bitmap->bp; |
| 1645 | pages = bitmap->pages; |
| 1646 | |
| 1647 | /* free all allocated memory */ |
| 1648 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1649 | if (bp) /* deallocate the page memory */ |
| 1650 | for (k = 0; k < pages; k++) |
| 1651 | if (bp[k].map && !bp[k].hijacked) |
| 1652 | kfree(bp[k].map); |
| 1653 | kfree(bp); |
| 1654 | kfree(bitmap); |
| 1655 | } |
NeilBrown | aa5cbd1 | 2009-12-14 12:49:46 +1100 | [diff] [blame] | 1656 | |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1657 | void bitmap_destroy(mddev_t *mddev) |
| 1658 | { |
| 1659 | struct bitmap *bitmap = mddev->bitmap; |
| 1660 | |
| 1661 | if (!bitmap) /* there was no bitmap */ |
| 1662 | return; |
| 1663 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1664 | mutex_lock(&mddev->bitmap_info.mutex); |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1665 | mddev->bitmap = NULL; /* disconnect from the md device */ |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1666 | mutex_unlock(&mddev->bitmap_info.mutex); |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1667 | if (mddev->thread) |
| 1668 | mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT; |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1669 | |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1670 | if (bitmap->sysfs_can_clear) |
| 1671 | sysfs_put(bitmap->sysfs_can_clear); |
| 1672 | |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1673 | bitmap_free(bitmap); |
| 1674 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1675 | |
| 1676 | /* |
| 1677 | * initialize the bitmap structure |
| 1678 | * if this returns an error, bitmap_destroy must be called to do clean up |
| 1679 | */ |
| 1680 | int bitmap_create(mddev_t *mddev) |
| 1681 | { |
| 1682 | struct bitmap *bitmap; |
NeilBrown | 1f59390 | 2009-04-20 11:50:24 +1000 | [diff] [blame] | 1683 | sector_t blocks = mddev->resync_max_sectors; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1684 | unsigned long chunks; |
| 1685 | unsigned long pages; |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1686 | struct file *file = mddev->bitmap_info.file; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1687 | int err; |
NeilBrown | 5ff5aff | 2010-06-01 19:37:32 +1000 | [diff] [blame] | 1688 | struct sysfs_dirent *bm = NULL; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1689 | |
Alexey Dobriyan | 5f6e3c83 | 2006-10-11 01:22:26 -0700 | [diff] [blame] | 1690 | BUILD_BUG_ON(sizeof(bitmap_super_t) != 256); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1691 | |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1692 | if (!file |
| 1693 | && !mddev->bitmap_info.offset |
| 1694 | && !mddev->bitmap_info.log) /* bitmap disabled, nothing to do */ |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1695 | return 0; |
| 1696 | |
NeilBrown | c3d9714 | 2009-12-14 12:49:52 +1100 | [diff] [blame] | 1697 | BUG_ON(file && mddev->bitmap_info.offset); |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1698 | BUG_ON(mddev->bitmap_info.offset && mddev->bitmap_info.log); |
NeilBrown | a654b9d8 | 2005-06-21 17:17:27 -0700 | [diff] [blame] | 1699 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 1700 | bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1701 | if (!bitmap) |
| 1702 | return -ENOMEM; |
| 1703 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1704 | spin_lock_init(&bitmap->lock); |
NeilBrown | ce25c31 | 2006-06-26 00:27:49 -0700 | [diff] [blame] | 1705 | atomic_set(&bitmap->pending_writes, 0); |
| 1706 | init_waitqueue_head(&bitmap->write_wait); |
Neil Brown | da6e1a3 | 2007-02-08 14:20:37 -0800 | [diff] [blame] | 1707 | init_waitqueue_head(&bitmap->overflow_wait); |
NeilBrown | e555190 | 2010-03-31 11:21:44 +1100 | [diff] [blame] | 1708 | init_waitqueue_head(&bitmap->behind_wait); |
NeilBrown | ce25c31 | 2006-06-26 00:27:49 -0700 | [diff] [blame] | 1709 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1710 | bitmap->mddev = mddev; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1711 | |
NeilBrown | 5ff5aff | 2010-06-01 19:37:32 +1000 | [diff] [blame] | 1712 | if (mddev->kobj.sd) |
| 1713 | bm = sysfs_get_dirent(mddev->kobj.sd, NULL, "bitmap"); |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1714 | if (bm) { |
Eric W. Biederman | 3ff195b | 2010-03-30 11:31:26 -0700 | [diff] [blame] | 1715 | bitmap->sysfs_can_clear = sysfs_get_dirent(bm, NULL, "can_clear"); |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1716 | sysfs_put(bm); |
| 1717 | } else |
| 1718 | bitmap->sysfs_can_clear = NULL; |
| 1719 | |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1720 | bitmap->file = file; |
NeilBrown | ce25c31 | 2006-06-26 00:27:49 -0700 | [diff] [blame] | 1721 | if (file) { |
| 1722 | get_file(file); |
NeilBrown | ae8fa28 | 2009-10-16 15:56:01 +1100 | [diff] [blame] | 1723 | /* As future accesses to this file will use bmap, |
| 1724 | * and bypass the page cache, we must sync the file |
| 1725 | * first. |
| 1726 | */ |
Christoph Hellwig | 8018ab0 | 2010-03-22 17:32:25 +0100 | [diff] [blame] | 1727 | vfs_fsync(file, 1); |
NeilBrown | ce25c31 | 2006-06-26 00:27:49 -0700 | [diff] [blame] | 1728 | } |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1729 | /* read superblock from bitmap file (this sets mddev->bitmap_info.chunksize) */ |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1730 | if (!mddev->bitmap_info.external) |
| 1731 | err = bitmap_read_sb(bitmap); |
| 1732 | else { |
| 1733 | err = 0; |
| 1734 | if (mddev->bitmap_info.chunksize == 0 || |
| 1735 | mddev->bitmap_info.daemon_sleep == 0) |
| 1736 | /* chunksize and time_base need to be |
| 1737 | * set first. */ |
| 1738 | err = -EINVAL; |
| 1739 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1740 | if (err) |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1741 | goto error; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1742 | |
NeilBrown | 624ce4f | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1743 | bitmap->daemon_lastrun = jiffies; |
NeilBrown | 42a04b5 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1744 | bitmap->chunkshift = ffz(~mddev->bitmap_info.chunksize); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1745 | |
| 1746 | /* now that chunksize and chunkshift are set, we can use these macros */ |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1747 | chunks = (blocks + CHUNK_BLOCK_RATIO(bitmap) - 1) >> |
NeilBrown | 1f59390 | 2009-04-20 11:50:24 +1000 | [diff] [blame] | 1748 | CHUNK_BLOCK_SHIFT(bitmap); |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1749 | pages = (chunks + PAGE_COUNTER_RATIO - 1) / PAGE_COUNTER_RATIO; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1750 | |
| 1751 | BUG_ON(!pages); |
| 1752 | |
| 1753 | bitmap->chunks = chunks; |
| 1754 | bitmap->pages = pages; |
| 1755 | bitmap->missing_pages = pages; |
| 1756 | bitmap->counter_bits = COUNTER_BITS; |
| 1757 | |
| 1758 | bitmap->syncchunk = ~0UL; |
| 1759 | |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 1760 | #ifdef INJECT_FATAL_FAULT_1 |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1761 | bitmap->bp = NULL; |
| 1762 | #else |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 1763 | bitmap->bp = kzalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1764 | #endif |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1765 | err = -ENOMEM; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1766 | if (!bitmap->bp) |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1767 | goto error; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1768 | |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 1769 | printk(KERN_INFO "created bitmap (%lu pages) for device %s\n", |
| 1770 | pages, bmname(bitmap)); |
| 1771 | |
| 1772 | mddev->bitmap = bitmap; |
| 1773 | |
| 1774 | |
| 1775 | return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0; |
| 1776 | |
| 1777 | error: |
| 1778 | bitmap_free(bitmap); |
| 1779 | return err; |
| 1780 | } |
| 1781 | |
| 1782 | int bitmap_load(mddev_t *mddev) |
| 1783 | { |
| 1784 | int err = 0; |
| 1785 | sector_t sector = 0; |
| 1786 | struct bitmap *bitmap = mddev->bitmap; |
| 1787 | |
| 1788 | if (!bitmap) |
| 1789 | goto out; |
| 1790 | |
| 1791 | /* Clear out old bitmap info first: Either there is none, or we |
| 1792 | * are resuming after someone else has possibly changed things, |
| 1793 | * so we should forget old cached info. |
| 1794 | * All chunks should be clean, but some might need_sync. |
| 1795 | */ |
| 1796 | while (sector < mddev->resync_max_sectors) { |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 1797 | sector_t blocks; |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 1798 | bitmap_start_sync(bitmap, sector, &blocks, 0); |
| 1799 | sector += blocks; |
| 1800 | } |
| 1801 | bitmap_close_sync(bitmap); |
| 1802 | |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1803 | if (mddev->bitmap_info.log) { |
| 1804 | unsigned long i; |
| 1805 | struct dm_dirty_log *log = mddev->bitmap_info.log; |
| 1806 | for (i = 0; i < bitmap->chunks; i++) |
| 1807 | if (!log->type->in_sync(log, i, 1)) |
| 1808 | bitmap_set_memory_bits(bitmap, |
| 1809 | (sector_t)i << CHUNK_BLOCK_SHIFT(bitmap), |
| 1810 | 1); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 1811 | } else { |
| 1812 | sector_t start = 0; |
| 1813 | if (mddev->degraded == 0 |
| 1814 | || bitmap->events_cleared == mddev->events) |
| 1815 | /* no need to keep dirty bits to optimise a |
| 1816 | * re-add of a missing device */ |
| 1817 | start = mddev->recovery_cp; |
| 1818 | |
NeilBrown | e384e58 | 2010-06-01 19:37:34 +1000 | [diff] [blame] | 1819 | err = bitmap_init_from_disk(bitmap, start); |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 1820 | } |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1821 | if (err) |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 1822 | goto out; |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1823 | |
NeilBrown | 1b04be9 | 2009-12-14 12:49:53 +1100 | [diff] [blame] | 1824 | mddev->thread->timeout = mddev->bitmap_info.daemon_sleep; |
NeilBrown | 9cd30fd | 2009-12-14 12:49:54 +1100 | [diff] [blame] | 1825 | md_wakeup_thread(mddev->thread); |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1826 | |
NeilBrown | 4ad1366 | 2007-07-17 04:06:13 -0700 | [diff] [blame] | 1827 | bitmap_update_sb(bitmap); |
| 1828 | |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 1829 | if (bitmap->flags & BITMAP_WRITE_ERROR) |
| 1830 | err = -EIO; |
| 1831 | out: |
NeilBrown | 3178b0d | 2005-09-09 16:23:50 -0700 | [diff] [blame] | 1832 | return err; |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1833 | } |
NeilBrown | 69e51b4 | 2010-06-01 19:37:35 +1000 | [diff] [blame] | 1834 | EXPORT_SYMBOL_GPL(bitmap_load); |
NeilBrown | 32a7627 | 2005-06-21 17:17:14 -0700 | [diff] [blame] | 1835 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 1836 | static ssize_t |
| 1837 | location_show(mddev_t *mddev, char *page) |
| 1838 | { |
| 1839 | ssize_t len; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1840 | if (mddev->bitmap_info.file) |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 1841 | len = sprintf(page, "file"); |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1842 | else if (mddev->bitmap_info.offset) |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 1843 | len = sprintf(page, "%+lld", (long long)mddev->bitmap_info.offset); |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1844 | else |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 1845 | len = sprintf(page, "none"); |
| 1846 | len += sprintf(page+len, "\n"); |
| 1847 | return len; |
| 1848 | } |
| 1849 | |
| 1850 | static ssize_t |
| 1851 | location_store(mddev_t *mddev, const char *buf, size_t len) |
| 1852 | { |
| 1853 | |
| 1854 | if (mddev->pers) { |
| 1855 | if (!mddev->pers->quiesce) |
| 1856 | return -EBUSY; |
| 1857 | if (mddev->recovery || mddev->sync_thread) |
| 1858 | return -EBUSY; |
| 1859 | } |
| 1860 | |
| 1861 | if (mddev->bitmap || mddev->bitmap_info.file || |
| 1862 | mddev->bitmap_info.offset) { |
| 1863 | /* bitmap already configured. Only option is to clear it */ |
| 1864 | if (strncmp(buf, "none", 4) != 0) |
| 1865 | return -EBUSY; |
| 1866 | if (mddev->pers) { |
| 1867 | mddev->pers->quiesce(mddev, 1); |
| 1868 | bitmap_destroy(mddev); |
| 1869 | mddev->pers->quiesce(mddev, 0); |
| 1870 | } |
| 1871 | mddev->bitmap_info.offset = 0; |
| 1872 | if (mddev->bitmap_info.file) { |
| 1873 | struct file *f = mddev->bitmap_info.file; |
| 1874 | mddev->bitmap_info.file = NULL; |
| 1875 | restore_bitmap_write_access(f); |
| 1876 | fput(f); |
| 1877 | } |
| 1878 | } else { |
| 1879 | /* No bitmap, OK to set a location */ |
| 1880 | long long offset; |
| 1881 | if (strncmp(buf, "none", 4) == 0) |
| 1882 | /* nothing to be done */; |
| 1883 | else if (strncmp(buf, "file:", 5) == 0) { |
| 1884 | /* Not supported yet */ |
| 1885 | return -EINVAL; |
| 1886 | } else { |
| 1887 | int rv; |
| 1888 | if (buf[0] == '+') |
| 1889 | rv = strict_strtoll(buf+1, 10, &offset); |
| 1890 | else |
| 1891 | rv = strict_strtoll(buf, 10, &offset); |
| 1892 | if (rv) |
| 1893 | return rv; |
| 1894 | if (offset == 0) |
| 1895 | return -EINVAL; |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 1896 | if (mddev->bitmap_info.external == 0 && |
| 1897 | mddev->major_version == 0 && |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 1898 | offset != mddev->bitmap_info.default_offset) |
| 1899 | return -EINVAL; |
| 1900 | mddev->bitmap_info.offset = offset; |
| 1901 | if (mddev->pers) { |
| 1902 | mddev->pers->quiesce(mddev, 1); |
| 1903 | rv = bitmap_create(mddev); |
| 1904 | if (rv) { |
| 1905 | bitmap_destroy(mddev); |
| 1906 | mddev->bitmap_info.offset = 0; |
| 1907 | } |
| 1908 | mddev->pers->quiesce(mddev, 0); |
| 1909 | if (rv) |
| 1910 | return rv; |
| 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | if (!mddev->external) { |
| 1915 | /* Ensure new bitmap info is stored in |
| 1916 | * metadata promptly. |
| 1917 | */ |
| 1918 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 1919 | md_wakeup_thread(mddev->thread); |
| 1920 | } |
| 1921 | return len; |
| 1922 | } |
| 1923 | |
| 1924 | static struct md_sysfs_entry bitmap_location = |
| 1925 | __ATTR(location, S_IRUGO|S_IWUSR, location_show, location_store); |
| 1926 | |
| 1927 | static ssize_t |
| 1928 | timeout_show(mddev_t *mddev, char *page) |
| 1929 | { |
| 1930 | ssize_t len; |
| 1931 | unsigned long secs = mddev->bitmap_info.daemon_sleep / HZ; |
| 1932 | unsigned long jifs = mddev->bitmap_info.daemon_sleep % HZ; |
NeilBrown | ac2f40b | 2010-06-01 19:37:31 +1000 | [diff] [blame] | 1933 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 1934 | len = sprintf(page, "%lu", secs); |
| 1935 | if (jifs) |
| 1936 | len += sprintf(page+len, ".%03u", jiffies_to_msecs(jifs)); |
| 1937 | len += sprintf(page+len, "\n"); |
| 1938 | return len; |
| 1939 | } |
| 1940 | |
| 1941 | static ssize_t |
| 1942 | timeout_store(mddev_t *mddev, const char *buf, size_t len) |
| 1943 | { |
| 1944 | /* timeout can be set at any time */ |
| 1945 | unsigned long timeout; |
| 1946 | int rv = strict_strtoul_scaled(buf, &timeout, 4); |
| 1947 | if (rv) |
| 1948 | return rv; |
| 1949 | |
| 1950 | /* just to make sure we don't overflow... */ |
| 1951 | if (timeout >= LONG_MAX / HZ) |
| 1952 | return -EINVAL; |
| 1953 | |
| 1954 | timeout = timeout * HZ / 10000; |
| 1955 | |
| 1956 | if (timeout >= MAX_SCHEDULE_TIMEOUT) |
| 1957 | timeout = MAX_SCHEDULE_TIMEOUT-1; |
| 1958 | if (timeout < 1) |
| 1959 | timeout = 1; |
| 1960 | mddev->bitmap_info.daemon_sleep = timeout; |
| 1961 | if (mddev->thread) { |
| 1962 | /* if thread->timeout is MAX_SCHEDULE_TIMEOUT, then |
| 1963 | * the bitmap is all clean and we don't need to |
| 1964 | * adjust the timeout right now |
| 1965 | */ |
| 1966 | if (mddev->thread->timeout < MAX_SCHEDULE_TIMEOUT) { |
| 1967 | mddev->thread->timeout = timeout; |
| 1968 | md_wakeup_thread(mddev->thread); |
| 1969 | } |
| 1970 | } |
| 1971 | return len; |
| 1972 | } |
| 1973 | |
| 1974 | static struct md_sysfs_entry bitmap_timeout = |
| 1975 | __ATTR(time_base, S_IRUGO|S_IWUSR, timeout_show, timeout_store); |
| 1976 | |
| 1977 | static ssize_t |
| 1978 | backlog_show(mddev_t *mddev, char *page) |
| 1979 | { |
| 1980 | return sprintf(page, "%lu\n", mddev->bitmap_info.max_write_behind); |
| 1981 | } |
| 1982 | |
| 1983 | static ssize_t |
| 1984 | backlog_store(mddev_t *mddev, const char *buf, size_t len) |
| 1985 | { |
| 1986 | unsigned long backlog; |
| 1987 | int rv = strict_strtoul(buf, 10, &backlog); |
| 1988 | if (rv) |
| 1989 | return rv; |
| 1990 | if (backlog > COUNTER_MAX) |
| 1991 | return -EINVAL; |
| 1992 | mddev->bitmap_info.max_write_behind = backlog; |
| 1993 | return len; |
| 1994 | } |
| 1995 | |
| 1996 | static struct md_sysfs_entry bitmap_backlog = |
| 1997 | __ATTR(backlog, S_IRUGO|S_IWUSR, backlog_show, backlog_store); |
| 1998 | |
| 1999 | static ssize_t |
| 2000 | chunksize_show(mddev_t *mddev, char *page) |
| 2001 | { |
| 2002 | return sprintf(page, "%lu\n", mddev->bitmap_info.chunksize); |
| 2003 | } |
| 2004 | |
| 2005 | static ssize_t |
| 2006 | chunksize_store(mddev_t *mddev, const char *buf, size_t len) |
| 2007 | { |
| 2008 | /* Can only be changed when no bitmap is active */ |
| 2009 | int rv; |
| 2010 | unsigned long csize; |
| 2011 | if (mddev->bitmap) |
| 2012 | return -EBUSY; |
| 2013 | rv = strict_strtoul(buf, 10, &csize); |
| 2014 | if (rv) |
| 2015 | return rv; |
| 2016 | if (csize < 512 || |
| 2017 | !is_power_of_2(csize)) |
| 2018 | return -EINVAL; |
| 2019 | mddev->bitmap_info.chunksize = csize; |
| 2020 | return len; |
| 2021 | } |
| 2022 | |
| 2023 | static struct md_sysfs_entry bitmap_chunksize = |
| 2024 | __ATTR(chunksize, S_IRUGO|S_IWUSR, chunksize_show, chunksize_store); |
| 2025 | |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 2026 | static ssize_t metadata_show(mddev_t *mddev, char *page) |
| 2027 | { |
| 2028 | return sprintf(page, "%s\n", (mddev->bitmap_info.external |
| 2029 | ? "external" : "internal")); |
| 2030 | } |
| 2031 | |
| 2032 | static ssize_t metadata_store(mddev_t *mddev, const char *buf, size_t len) |
| 2033 | { |
| 2034 | if (mddev->bitmap || |
| 2035 | mddev->bitmap_info.file || |
| 2036 | mddev->bitmap_info.offset) |
| 2037 | return -EBUSY; |
| 2038 | if (strncmp(buf, "external", 8) == 0) |
| 2039 | mddev->bitmap_info.external = 1; |
| 2040 | else if (strncmp(buf, "internal", 8) == 0) |
| 2041 | mddev->bitmap_info.external = 0; |
| 2042 | else |
| 2043 | return -EINVAL; |
| 2044 | return len; |
| 2045 | } |
| 2046 | |
| 2047 | static struct md_sysfs_entry bitmap_metadata = |
| 2048 | __ATTR(metadata, S_IRUGO|S_IWUSR, metadata_show, metadata_store); |
| 2049 | |
| 2050 | static ssize_t can_clear_show(mddev_t *mddev, char *page) |
| 2051 | { |
| 2052 | int len; |
| 2053 | if (mddev->bitmap) |
| 2054 | len = sprintf(page, "%s\n", (mddev->bitmap->need_sync ? |
| 2055 | "false" : "true")); |
| 2056 | else |
| 2057 | len = sprintf(page, "\n"); |
| 2058 | return len; |
| 2059 | } |
| 2060 | |
| 2061 | static ssize_t can_clear_store(mddev_t *mddev, const char *buf, size_t len) |
| 2062 | { |
| 2063 | if (mddev->bitmap == NULL) |
| 2064 | return -ENOENT; |
| 2065 | if (strncmp(buf, "false", 5) == 0) |
| 2066 | mddev->bitmap->need_sync = 1; |
| 2067 | else if (strncmp(buf, "true", 4) == 0) { |
| 2068 | if (mddev->degraded) |
| 2069 | return -EBUSY; |
| 2070 | mddev->bitmap->need_sync = 0; |
| 2071 | } else |
| 2072 | return -EINVAL; |
| 2073 | return len; |
| 2074 | } |
| 2075 | |
| 2076 | static struct md_sysfs_entry bitmap_can_clear = |
| 2077 | __ATTR(can_clear, S_IRUGO|S_IWUSR, can_clear_show, can_clear_store); |
| 2078 | |
Paul Clements | 696fcd5 | 2010-03-08 16:02:37 +1100 | [diff] [blame] | 2079 | static ssize_t |
| 2080 | behind_writes_used_show(mddev_t *mddev, char *page) |
| 2081 | { |
| 2082 | if (mddev->bitmap == NULL) |
| 2083 | return sprintf(page, "0\n"); |
| 2084 | return sprintf(page, "%lu\n", |
| 2085 | mddev->bitmap->behind_writes_used); |
| 2086 | } |
| 2087 | |
| 2088 | static ssize_t |
| 2089 | behind_writes_used_reset(mddev_t *mddev, const char *buf, size_t len) |
| 2090 | { |
| 2091 | if (mddev->bitmap) |
| 2092 | mddev->bitmap->behind_writes_used = 0; |
| 2093 | return len; |
| 2094 | } |
| 2095 | |
| 2096 | static struct md_sysfs_entry max_backlog_used = |
| 2097 | __ATTR(max_backlog_used, S_IRUGO | S_IWUSR, |
| 2098 | behind_writes_used_show, behind_writes_used_reset); |
| 2099 | |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2100 | static struct attribute *md_bitmap_attrs[] = { |
| 2101 | &bitmap_location.attr, |
| 2102 | &bitmap_timeout.attr, |
| 2103 | &bitmap_backlog.attr, |
| 2104 | &bitmap_chunksize.attr, |
NeilBrown | ece5cff | 2009-12-14 12:49:56 +1100 | [diff] [blame] | 2105 | &bitmap_metadata.attr, |
| 2106 | &bitmap_can_clear.attr, |
Paul Clements | 696fcd5 | 2010-03-08 16:02:37 +1100 | [diff] [blame] | 2107 | &max_backlog_used.attr, |
NeilBrown | 43a7050 | 2009-12-14 12:49:55 +1100 | [diff] [blame] | 2108 | NULL |
| 2109 | }; |
| 2110 | struct attribute_group md_bitmap_group = { |
| 2111 | .name = "bitmap", |
| 2112 | .attrs = md_bitmap_attrs, |
| 2113 | }; |
| 2114 | |