19 #include <linux/module.h>
20 #include <linux/errno.h>
21 #include <linux/slab.h>
24 #include <linux/sched.h>
25 #include <linux/list.h>
35 return bitmap->mddev ? mdname(bitmap->mddev) :
"mdX";
48 static int bitmap_checkpage(
struct bitmap_counts *bitmap,
53 unsigned char *mappage;
63 if (bitmap->bp[
page].hijacked)
66 if (bitmap->bp[
page].map)
74 spin_unlock_irq(&bitmap->lock);
76 spin_lock_irq(&bitmap->lock);
78 if (mappage ==
NULL) {
79 pr_debug(
"md/bitmap: map page allocation failed, hijacking\n");
82 if (!bitmap->bp[
page].map)
83 bitmap->bp[
page].hijacked = 1;
84 }
else if (bitmap->bp[
page].map ||
85 bitmap->bp[
page].hijacked) {
93 bitmap->bp[
page].map = mappage;
94 bitmap->missing_pages--;
102 static void bitmap_checkfree(
struct bitmap_counts *bitmap,
unsigned long page)
106 if (bitmap->bp[page].count)
111 if (bitmap->bp[page].hijacked) {
112 bitmap->bp[
page].hijacked = 0;
116 ptr = bitmap->bp[
page].map;
118 bitmap->missing_pages++;
146 target = offset + index * (
PAGE_SIZE/512);
149 roundup(size, bdev_logical_block_size(rdev->
bdev)),
158 static struct md_rdev *next_active_rdev(
struct md_rdev *rdev,
struct mddev *mddev)
174 rdev_dec_pending(rdev, mddev);
176 list_for_each_entry_continue_rcu(rdev, &mddev->
disks,
same_set) {
189 static int write_sb_page(
struct bitmap *bitmap,
struct page *page,
int wait)
193 struct mddev *mddev = bitmap->mddev;
194 struct bitmap_storage *
store = &bitmap->storage;
196 while ((rdev = next_active_rdev(rdev, mddev)) !=
NULL) {
202 if (page->
index == store->file_pages-1) {
203 int last_page_size = store->bytes & (
PAGE_SIZE-1);
204 if (last_page_size == 0)
207 bdev_logical_block_size(bdev));
222 }
else if (offset < 0) {
259 static void bitmap_file_kick(
struct bitmap *bitmap);
263 static void write_page(
struct bitmap *bitmap,
struct page *page,
int wait)
265 struct buffer_head *bh;
267 if (bitmap->storage.file ==
NULL) {
268 switch (write_sb_page(bitmap, page, wait)) {
274 bh = page_buffers(page);
276 while (bh && bh->b_blocknr) {
278 set_buffer_locked(bh);
279 set_buffer_mapped(bh);
281 bh = bh->b_this_page;
289 bitmap_file_kick(bitmap);
292 static void end_bitmap_write(
struct buffer_head *bh,
int uptodate)
294 struct bitmap *bitmap = bh->b_private;
304 __clear_page_buffers(
struct page *page)
306 ClearPagePrivate(page);
307 set_page_private(page, 0);
310 static void free_buffers(
struct page *page)
312 struct buffer_head *bh;
314 if (!PagePrivate(page))
317 bh = page_buffers(page);
319 struct buffer_head *
next = bh->b_this_page;
323 __clear_page_buffers(page);
334 static int read_page(
struct file *
file,
unsigned long index,
335 struct bitmap *bitmap,
341 struct buffer_head *bh;
352 attach_page_buffers(page, bh);
358 bh->b_blocknr =
bmap(inode, block);
359 if (bh->b_blocknr == 0) {
364 bh->b_bdev = inode->
i_sb->s_bdev;
370 bh->b_end_io = end_bitmap_write;
373 set_buffer_locked(bh);
374 set_buffer_mapped(bh);
378 bh = bh->b_this_page;
404 if (!bitmap || !bitmap->mddev)
406 if (bitmap->mddev->bitmap_info.external)
408 if (!bitmap->storage.sb_page)
412 if (bitmap->mddev->events < bitmap->events_cleared)
414 bitmap->events_cleared = bitmap->mddev->events;
426 write_page(bitmap, bitmap->storage.sb_page, 1);
434 if (!bitmap || !bitmap->storage.sb_page)
469 static int bitmap_new_disk_sb(
struct bitmap *bitmap)
472 unsigned long chunksize, daemon_sleep, write_behind;
475 if (bitmap->storage.sb_page ==
NULL)
477 bitmap->storage.sb_page->index = 0;
484 chunksize = bitmap->mddev->bitmap_info.chunksize;
493 daemon_sleep = bitmap->mddev->bitmap_info.daemon_sleep;
497 daemon_sleep = 5 *
HZ;
500 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep;
506 write_behind = bitmap->mddev->bitmap_info.max_write_behind;
507 if (write_behind > COUNTER_MAX)
508 write_behind = COUNTER_MAX / 2;
510 bitmap->mddev->bitmap_info.max_write_behind = write_behind;
519 bitmap->events_cleared = bitmap->mddev->events;
528 static int bitmap_read_sb(
struct bitmap *bitmap)
532 unsigned long chunksize, daemon_sleep, write_behind;
533 unsigned long long events;
534 unsigned long sectors_reserved = 0;
536 struct page *sb_page;
538 if (!bitmap->storage.file && !bitmap->mddev->bitmap_info.offset) {
539 chunksize = 128 * 1024 * 1024;
540 daemon_sleep = 5 *
HZ;
550 bitmap->storage.sb_page = sb_page;
552 if (bitmap->storage.file) {
553 loff_t isize = i_size_read(bitmap->storage.file->f_mapping->host);
554 int bytes = isize > PAGE_SIZE ? PAGE_SIZE : isize;
556 err = read_page(bitmap->storage.file, 0,
557 bitmap, bytes, sb_page);
559 err = read_sb_page(bitmap->mddev,
560 bitmap->mddev->bitmap_info.offset,
576 reason =
"bad magic";
579 reason =
"unrecognized superblock version";
580 else if (chunksize < 512)
581 reason =
"bitmap chunksize too small";
583 reason =
"bitmap chunksize not a power of 2";
585 reason =
"daemon sleep period out of range";
586 else if (write_behind > COUNTER_MAX)
587 reason =
"write-behind limit out of range (0 - 16383)";
590 bmname(bitmap), reason);
597 if (bitmap->mddev->persistent) {
602 if (
memcmp(sb->
uuid, bitmap->mddev->uuid, 16)) {
604 "%s: bitmap superblock UUID mismatch\n",
611 "%s: bitmap file is out of date (%llu < %llu) "
612 "-- forcing full recovery\n",
613 bmname(bitmap), events,
614 (
unsigned long long) bitmap->mddev->events);
629 bitmap->events_cleared = bitmap->mddev->events;
630 bitmap->mddev->bitmap_info.chunksize = chunksize;
631 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep;
632 bitmap->mddev->bitmap_info.max_write_behind = write_behind;
633 if (bitmap->mddev->bitmap_info.space == 0 ||
634 bitmap->mddev->bitmap_info.space > sectors_reserved)
635 bitmap->mddev->bitmap_info.space = sectors_reserved;
652 static inline unsigned long file_page_index(
struct bitmap_storage *store,
657 return chunk >> PAGE_BIT_SHIFT;
661 static inline unsigned long file_page_offset(
struct bitmap_storage *store,
666 return chunk & (PAGE_BITS - 1);
676 static inline struct page *filemap_get_page(
struct bitmap_storage *store,
679 if (file_page_index(store, chunk) >= store->file_pages)
681 return store->filemap[file_page_index(store, chunk)
682 - file_page_index(store, 0)];
685 static int bitmap_storage_alloc(
struct bitmap_storage *store,
686 unsigned long chunks,
int with_super)
698 store->filemap =
kmalloc(
sizeof(
struct page *)
703 if (with_super && !store->sb_page) {
705 if (store->sb_page ==
NULL)
707 store->sb_page->index = 0;
710 if (store->sb_page) {
711 store->filemap[0] = store->sb_page;
716 if (!store->filemap[pnum]) {
717 store->file_pages = pnum;
720 store->filemap[pnum]->index = pnum;
722 store->file_pages = pnum;
726 store->filemap_attr = kzalloc(
729 if (!store->filemap_attr)
732 store->bytes =
bytes;
737 static void bitmap_file_unmap(
struct bitmap_storage *store)
739 struct page **
map, *sb_page;
744 map = store->filemap;
745 pages = store->file_pages;
746 sb_page = store->sb_page;
749 if (map[pages] != sb_page)
750 free_buffers(map[pages]);
752 kfree(store->filemap_attr);
755 free_buffers(sb_page);
758 struct inode *inode = file->
f_path.dentry->d_inode;
769 static void bitmap_file_kick(
struct bitmap *bitmap)
776 if (bitmap->storage.file) {
779 ptr =
d_path(&bitmap->storage.file->f_path,
783 "%s: kicking failed bitmap file %s from array!\n",
784 bmname(bitmap), IS_ERR(ptr) ?
"" : ptr);
789 "%s: disabling internal bitmap due to errors\n",
801 static inline void set_page_attr(
struct bitmap *bitmap,
int pnum,
804 set_bit((pnum<<2) + attr, bitmap->storage.filemap_attr);
807 static inline void clear_page_attr(
struct bitmap *bitmap,
int pnum,
810 clear_bit((pnum<<2) + attr, bitmap->storage.filemap_attr);
813 static inline int test_page_attr(
struct bitmap *bitmap,
int pnum,
816 return test_bit((pnum<<2) + attr, bitmap->storage.filemap_attr);
819 static inline int test_and_clear_page_attr(
struct bitmap *bitmap,
int pnum,
823 bitmap->storage.filemap_attr);
832 static void bitmap_file_set_bit(
struct bitmap *bitmap,
sector_t block)
837 unsigned long chunk = block >> bitmap->counts.chunkshift;
839 page = filemap_get_page(&bitmap->storage, chunk);
842 bit = file_page_offset(&bitmap->storage, chunk);
849 test_and_set_bit_le(bit, kaddr);
856 static void bitmap_file_clear_bit(
struct bitmap *bitmap,
sector_t block)
861 unsigned long chunk = block >> bitmap->counts.chunkshift;
863 page = filemap_get_page(&bitmap->storage, chunk);
866 bit = file_page_offset(&bitmap->storage, chunk);
871 test_and_clear_bit_le(bit, paddr);
875 bitmap->allclean = 0;
885 int dirty, need_write;
888 if (!bitmap || !bitmap->storage.filemap ||
894 for (i = 0; i < bitmap->storage.file_pages; i++) {
895 if (!bitmap->storage.filemap)
898 need_write = test_and_clear_page_attr(bitmap, i,
900 if (dirty || need_write) {
902 write_page(bitmap, bitmap->storage.filemap[i], 0);
908 if (bitmap->storage.file)
915 bitmap_file_kick(bitmap);
919 static void bitmap_set_memory_bits(
struct bitmap *bitmap,
sector_t offset,
int needed);
931 static int bitmap_init_from_disk(
struct bitmap *bitmap,
sector_t start)
933 unsigned long i, chunks,
index, oldindex,
bit;
934 struct page *page =
NULL;
935 unsigned long bit_cnt = 0;
941 struct bitmap_storage *store = &bitmap->storage;
943 chunks = bitmap->counts.chunks;
946 if (!file && !bitmap->mddev->bitmap_info.offset) {
948 store->filemap =
NULL;
949 store->file_pages = 0;
950 for (i = 0; i < chunks ; i++) {
952 int needed = ((
sector_t)(i+1) << (bitmap->counts.chunkshift)
954 bitmap_set_memory_bits(bitmap,
955 (
sector_t)i << bitmap->counts.chunkshift,
964 "recovery\n", bmname(bitmap));
966 if (file && i_size_read(file->
f_mapping->host) < store->bytes) {
969 (
unsigned long) i_size_read(file->
f_mapping->host),
976 if (!bitmap->mddev->bitmap_info.external)
979 for (i = 0; i < chunks; i++) {
981 index = file_page_index(&bitmap->storage, i);
982 bit = file_page_offset(&bitmap->storage, i);
983 if (index != oldindex) {
986 if (index == store->file_pages-1)
987 count = store->bytes - index *
PAGE_SIZE;
990 page = store->filemap[
index];
992 ret = read_page(file, index, bitmap,
997 bitmap->mddev->bitmap_info.offset,
1012 memset(paddr + offset, 0xff,
1013 PAGE_SIZE - offset);
1015 write_page(bitmap, page, 1);
1027 b = test_bit_le(bit, paddr);
1031 int needed = ((
sector_t)(i+1) << bitmap->counts.chunkshift
1033 bitmap_set_memory_bits(bitmap,
1034 (
sector_t)i << bitmap->counts.chunkshift,
1042 "read %lu pages, set %lu of %lu bits\n",
1043 bmname(bitmap), store->file_pages,
1050 bmname(bitmap), ret);
1061 if (!bitmap || !bitmap->storage.filemap)
1063 if (bitmap->storage.file)
1067 for (i = 0; i < bitmap->storage.file_pages; i++)
1068 set_page_attr(bitmap, i,
1070 bitmap->allclean = 0;
1073 static void bitmap_count_page(
struct bitmap_counts *bitmap,
1076 sector_t chunk = offset >> bitmap->chunkshift;
1077 unsigned long page = chunk >> PAGE_COUNTER_SHIFT;
1078 bitmap->bp[
page].count +=
inc;
1079 bitmap_checkfree(bitmap, page);
1082 static void bitmap_set_pending(
struct bitmap_counts *bitmap,
sector_t offset)
1084 sector_t chunk = offset >> bitmap->chunkshift;
1085 unsigned long page = chunk >> PAGE_COUNTER_SHIFT;
1086 struct bitmap_page *bp = &bitmap->bp[
page];
1092 static bitmap_counter_t *bitmap_get_counter(
struct bitmap_counts *bitmap,
1105 unsigned long nextpage;
1107 struct bitmap_counts *counts;
1114 if (bitmap ==
NULL) {
1122 bitmap->daemon_lastrun =
jiffies;
1123 if (bitmap->allclean) {
1127 bitmap->allclean = 1;
1133 for (j = 0; j < bitmap->storage.file_pages; j++)
1134 if (test_and_clear_page_attr(bitmap, j,
1136 set_page_attr(bitmap, j,
1139 if (bitmap->need_sync &&
1144 bitmap->need_sync = 0;
1145 if (bitmap->storage.filemap) {
1150 set_page_attr(bitmap, 0,
1157 counts = &bitmap->counts;
1158 spin_lock_irq(&counts->lock);
1160 for (j = 0; j < counts->chunks; j++) {
1161 bitmap_counter_t *bmc;
1164 if (j == nextpage) {
1165 nextpage += PAGE_COUNTER_RATIO;
1166 if (!counts->bp[j >> PAGE_COUNTER_SHIFT].pending) {
1167 j |= PAGE_COUNTER_MASK;
1170 counts->bp[j >> PAGE_COUNTER_SHIFT].pending = 0;
1172 bmc = bitmap_get_counter(counts,
1177 j |= PAGE_COUNTER_MASK;
1180 if (*bmc == 1 && !bitmap->need_sync) {
1183 bitmap_count_page(counts, block, -1);
1184 bitmap_file_clear_bit(bitmap, block);
1185 }
else if (*bmc && *bmc <= 2) {
1187 bitmap_set_pending(counts, block);
1188 bitmap->allclean = 0;
1191 spin_unlock_irq(&counts->lock);
1202 j < bitmap->storage.file_pages
1206 if (test_page_attr(bitmap, j,
1210 if (test_and_clear_page_attr(bitmap, j,
1212 write_page(bitmap, bitmap->storage.filemap[j], 0);
1217 if (bitmap->allclean == 0)
1223 static bitmap_counter_t *bitmap_get_counter(
struct bitmap_counts *bitmap,
1233 sector_t chunk = offset >> bitmap->chunkshift;
1234 unsigned long page = chunk >> PAGE_COUNTER_SHIFT;
1235 unsigned long pageoff = (chunk & PAGE_COUNTER_MASK) << COUNTER_BYTE_SHIFT;
1239 err = bitmap_checkpage(bitmap, page,
create);
1241 if (bitmap->bp[page].hijacked ||
1242 bitmap->bp[page].map ==
NULL)
1243 csize = ((
sector_t)1) << (bitmap->chunkshift +
1244 PAGE_COUNTER_SHIFT - 1);
1246 csize = ((
sector_t)1) << bitmap->chunkshift;
1247 *blocks = csize - (offset & (csize - 1));
1254 if (bitmap->bp[page].hijacked) {
1257 int hi = (pageoff > PAGE_COUNTER_MASK);
1258 return &((bitmap_counter_t *)
1259 &bitmap->bp[page].map)[hi];
1261 return (bitmap_counter_t *)
1262 &(bitmap->bp[
page].map[pageoff]);
1274 if (bw > bitmap->behind_writes_used)
1275 bitmap->behind_writes_used = bw;
1277 pr_debug(
"inc write-behind count %d/%lu\n",
1278 bw, bitmap->mddev->bitmap_info.max_write_behind);
1283 bitmap_counter_t *bmc;
1285 spin_lock_irq(&bitmap->counts.lock);
1286 bmc = bitmap_get_counter(&bitmap->counts, offset, &blocks, 1);
1288 spin_unlock_irq(&bitmap->counts.lock);
1300 spin_unlock_irq(&bitmap->counts.lock);
1308 bitmap_file_set_bit(bitmap, offset);
1309 bitmap_count_page(&bitmap->counts, offset, 1);
1317 spin_unlock_irq(&bitmap->counts.lock);
1320 if (sectors > blocks)
1330 int success,
int behind)
1336 wake_up(&bitmap->behind_wait);
1337 pr_debug(
"dec write-behind count %d/%lu\n",
1339 bitmap->mddev->bitmap_info.max_write_behind);
1344 unsigned long flags;
1345 bitmap_counter_t *bmc;
1348 bmc = bitmap_get_counter(&bitmap->counts, offset, &blocks, 0);
1350 spin_unlock_irqrestore(&bitmap->counts.lock, flags);
1354 if (success && !bitmap->mddev->degraded &&
1355 bitmap->events_cleared < bitmap->mddev->events) {
1356 bitmap->events_cleared = bitmap->mddev->events;
1357 bitmap->need_sync = 1;
1358 sysfs_notify_dirent_safe(bitmap->sysfs_can_clear);
1361 if (!success && !NEEDED(*bmc))
1362 *bmc |= NEEDED_MASK;
1364 if (
COUNTER(*bmc) == COUNTER_MAX)
1365 wake_up(&bitmap->overflow_wait);
1369 bitmap_set_pending(&bitmap->counts, offset);
1370 bitmap->allclean = 0;
1372 spin_unlock_irqrestore(&bitmap->counts.lock, flags);
1374 if (sectors > blocks)
1382 static int __bitmap_start_sync(
struct bitmap *bitmap,
sector_t offset,
sector_t *blocks,
1385 bitmap_counter_t *bmc;
1387 if (bitmap ==
NULL) {
1391 spin_lock_irq(&bitmap->counts.lock);
1392 bmc = bitmap_get_counter(&bitmap->counts, offset, blocks, 0);
1398 else if (NEEDED(*bmc)) {
1401 *bmc |= RESYNC_MASK;
1402 *bmc &= ~NEEDED_MASK;
1406 spin_unlock_irq(&bitmap->counts.lock);
1424 while (*blocks < (PAGE_SIZE>>9)) {
1425 rv |= __bitmap_start_sync(bitmap, offset,
1426 &blocks1, degraded);
1436 bitmap_counter_t *bmc;
1437 unsigned long flags;
1439 if (bitmap ==
NULL) {
1444 bmc = bitmap_get_counter(&bitmap->counts, offset, blocks, 0);
1449 *bmc &= ~RESYNC_MASK;
1451 if (!NEEDED(*bmc) && aborted)
1452 *bmc |= NEEDED_MASK;
1455 bitmap_set_pending(&bitmap->counts, offset);
1456 bitmap->allclean = 0;
1461 spin_unlock_irqrestore(&bitmap->counts.lock, flags);
1490 bitmap->last_end_sync =
jiffies;
1494 + bitmap->mddev->bitmap_info.daemon_sleep)))
1497 atomic_read(&bitmap->mddev->recovery_active) == 0);
1499 bitmap->mddev->curr_resync_completed =
sector;
1501 sector &= ~((1ULL << bitmap->counts.chunkshift) - 1);
1507 bitmap->last_end_sync =
jiffies;
1512 static void bitmap_set_memory_bits(
struct bitmap *bitmap,
sector_t offset,
int needed)
1520 bitmap_counter_t *bmc;
1521 spin_lock_irq(&bitmap->counts.lock);
1522 bmc = bitmap_get_counter(&bitmap->counts, offset, &secs, 1);
1524 spin_unlock_irq(&bitmap->counts.lock);
1528 *bmc = 2 | (needed ? NEEDED_MASK : 0);
1529 bitmap_count_page(&bitmap->counts, offset, 1);
1530 bitmap_set_pending(&bitmap->counts, offset);
1531 bitmap->allclean = 0;
1533 spin_unlock_irq(&bitmap->counts.lock);
1539 unsigned long chunk;
1541 for (chunk = s; chunk <=
e; chunk++) {
1543 bitmap_set_memory_bits(bitmap, sec, 1);
1544 bitmap_file_set_bit(bitmap, sec);
1550 bitmap->mddev->recovery_cp =
sec;
1559 struct bitmap *bitmap = mddev->
bitmap;
1569 bitmap->daemon_lastrun -= sleep;
1571 bitmap->daemon_lastrun -= sleep;
1573 bitmap->daemon_lastrun -= sleep;
1581 static void bitmap_free(
struct bitmap *bitmap)
1584 struct bitmap_page *bp;
1594 bitmap_file_unmap(&bitmap->storage);
1596 bp = bitmap->counts.bp;
1597 pages = bitmap->counts.pages;
1602 for (k = 0; k <
pages; k++)
1603 if (bp[k].map && !bp[k].hijacked)
1611 struct bitmap *bitmap = mddev->
bitmap;
1622 if (bitmap->sysfs_can_clear)
1625 bitmap_free(bitmap);
1644 bitmap = kzalloc(
sizeof(*bitmap),
GFP_KERNEL);
1654 bitmap->mddev = mddev;
1662 bitmap->sysfs_can_clear =
NULL;
1664 bitmap->storage.file =
file;
1680 err = bitmap_new_disk_sb(bitmap);
1682 err = bitmap_read_sb(bitmap);
1694 bitmap->daemon_lastrun =
jiffies;
1700 bitmap->counts.pages, bmname(bitmap));
1706 bitmap_free(bitmap);
1715 struct bitmap *bitmap = mddev->
bitmap;
1725 while (sector < mddev->resync_max_sectors) {
1733 || bitmap->events_cleared == mddev->
events)
1739 err = bitmap_init_from_disk(bitmap, start);
1763 unsigned long chunk_kb;
1764 struct bitmap_counts *counts;
1769 counts = &bitmap->counts;
1771 chunk_kb = bitmap->mddev->bitmap_info.chunksize >> 10;
1772 seq_printf(seq,
"bitmap: %lu/%lu pages [%luKB], "
1774 counts->pages - counts->missing_pages,
1776 (counts->pages - counts->missing_pages)
1778 chunk_kb ? chunk_kb : bitmap->mddev->bitmap_info.chunksize,
1779 chunk_kb ?
"KB" :
"B");
1780 if (bitmap->storage.file) {
1782 seq_path(seq, &bitmap->storage.file->f_path,
" \t\n");
1789 int chunksize,
int init)
1801 struct bitmap_storage store;
1802 struct bitmap_counts old_counts;
1803 unsigned long chunks;
1809 struct bitmap_page *new_bp;
1811 if (chunksize == 0) {
1816 long space = bitmap->mddev->bitmap_info.space;
1823 if (!bitmap->mddev->bitmap_info.external)
1826 bitmap->mddev->bitmap_info.space = space;
1828 chunkshift = bitmap->counts.chunkshift;
1835 if (!bitmap->mddev->bitmap_info.external)
1837 }
while (bytes > (space << 9));
1839 chunkshift =
ffz(~chunksize) - BITMAP_BLOCK_SHIFT;
1842 memset(&store, 0,
sizeof(store));
1843 if (bitmap->mddev->bitmap_info.offset || bitmap->mddev->bitmap_info.file)
1844 ret = bitmap_storage_alloc(&store, chunks,
1845 !bitmap->mddev->bitmap_info.external);
1851 new_bp = kzalloc(pages *
sizeof(*new_bp),
GFP_KERNEL);
1854 bitmap_file_unmap(&store);
1859 bitmap->mddev->pers->quiesce(bitmap->mddev, 1);
1861 store.file = bitmap->storage.file;
1862 bitmap->storage.file =
NULL;
1864 if (store.sb_page && bitmap->storage.sb_page)
1868 bitmap_file_unmap(&bitmap->storage);
1869 bitmap->storage = store;
1871 old_counts = bitmap->counts;
1872 bitmap->counts.bp = new_bp;
1873 bitmap->counts.pages =
pages;
1874 bitmap->counts.missing_pages =
pages;
1875 bitmap->counts.chunkshift = chunkshift;
1876 bitmap->counts.chunks = chunks;
1877 bitmap->mddev->bitmap_info.chunksize = 1 << (chunkshift +
1878 BITMAP_BLOCK_SHIFT);
1880 blocks =
min(old_counts.chunks << old_counts.chunkshift,
1881 chunks << chunkshift);
1883 spin_lock_irq(&bitmap->counts.lock);
1884 for (block = 0; block < blocks; ) {
1885 bitmap_counter_t *bmc_old, *bmc_new;
1888 bmc_old = bitmap_get_counter(&old_counts, block,
1890 set = bmc_old && NEEDED(*bmc_old);
1893 bmc_new = bitmap_get_counter(&bitmap->counts, block,
1895 if (*bmc_new == 0) {
1898 sector_t start = block >> chunkshift;
1899 start <<= chunkshift;
1900 while (start < end) {
1901 bitmap_file_set_bit(bitmap, block);
1902 start += 1 << chunkshift;
1905 bitmap_count_page(&bitmap->counts,
1907 bitmap_set_pending(&bitmap->counts,
1910 *bmc_new |= NEEDED_MASK;
1911 if (new_blocks < old_blocks)
1912 old_blocks = new_blocks;
1914 block += old_blocks;
1919 while (block < (chunks << chunkshift)) {
1920 bitmap_counter_t *bmc;
1921 bmc = bitmap_get_counter(&bitmap->counts, block,
1928 *bmc = NEEDED_MASK | 2;
1929 bitmap_count_page(&bitmap->counts,
1931 bitmap_set_pending(&bitmap->counts,
1935 block += new_blocks;
1937 for (i = 0; i < bitmap->storage.file_pages; i++)
1940 spin_unlock_irq(&bitmap->counts.lock);
1944 bitmap->mddev->pers->quiesce(bitmap->mddev, 0);
1953 location_show(
struct mddev *mddev,
char *page)
1962 len +=
sprintf(page+len,
"\n");
1967 location_store(
struct mddev *mddev,
const char *
buf,
size_t len)
1971 if (!mddev->
pers->quiesce)
1980 if (
strncmp(buf,
"none", 4) != 0)
1983 mddev->
pers->quiesce(mddev, 1);
1985 mddev->
pers->quiesce(mddev, 0);
1997 if (
strncmp(buf,
"none", 4) == 0)
1999 else if (
strncmp(buf,
"file:", 5) == 0) {
2018 mddev->
pers->quiesce(mddev, 1);
2026 mddev->
pers->quiesce(mddev, 0);
2050 space_show(
struct mddev *mddev,
char *page)
2056 space_store(
struct mddev *mddev,
const char *buf,
size_t len)
2061 rv = kstrtoul(buf, 10, §ors);
2069 sectors < (mddev->
bitmap->storage.bytes + 511) >> 9)
2083 timeout_show(
struct mddev *mddev,
char *page)
2089 len =
sprintf(page,
"%lu", secs);
2092 len +=
sprintf(page+len,
"\n");
2097 timeout_store(
struct mddev *mddev,
const char *buf,
size_t len)
2109 timeout = timeout *
HZ / 10000;
2111 if (timeout >= MAX_SCHEDULE_TIMEOUT)
2112 timeout = MAX_SCHEDULE_TIMEOUT-1;
2121 if (mddev->
thread->timeout < MAX_SCHEDULE_TIMEOUT) {
2122 mddev->
thread->timeout = timeout;
2133 backlog_show(
struct mddev *mddev,
char *page)
2139 backlog_store(
struct mddev *mddev,
const char *buf,
size_t len)
2145 if (backlog > COUNTER_MAX)
2155 chunksize_show(
struct mddev *mddev,
char *page)
2161 chunksize_store(
struct mddev *mddev,
const char *buf,
size_t len)
2165 unsigned long csize;
2181 static ssize_t metadata_show(
struct mddev *mddev,
char *page)
2184 ?
"external" :
"internal"));
2187 static ssize_t metadata_store(
struct mddev *mddev,
const char *buf,
size_t len)
2193 if (
strncmp(buf,
"external", 8) == 0)
2195 else if (
strncmp(buf,
"internal", 8) == 0)
2205 static ssize_t can_clear_show(
struct mddev *mddev,
char *page)
2216 static ssize_t can_clear_store(
struct mddev *mddev,
const char *buf,
size_t len)
2220 if (
strncmp(buf,
"false", 5) == 0)
2221 mddev->
bitmap->need_sync = 1;
2222 else if (
strncmp(buf,
"true", 4) == 0) {
2225 mddev->
bitmap->need_sync = 0;
2235 behind_writes_used_show(
struct mddev *mddev,
char *page)
2240 mddev->
bitmap->behind_writes_used);
2244 behind_writes_used_reset(
struct mddev *mddev,
const char *buf,
size_t len)
2247 mddev->
bitmap->behind_writes_used = 0;
2253 behind_writes_used_show, behind_writes_used_reset);
2255 static struct attribute *md_bitmap_attrs[] = {
2256 &bitmap_location.
attr,
2258 &bitmap_timeout.
attr,
2259 &bitmap_backlog.
attr,
2260 &bitmap_chunksize.
attr,
2261 &bitmap_metadata.
attr,
2262 &bitmap_can_clear.
attr,
2263 &max_backlog_used.
attr,
2268 .attrs = md_bitmap_attrs,