diff options
author | NeilBrown <neilb@suse.de> | 2012-05-21 23:55:24 -0400 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2012-05-21 23:55:24 -0400 |
commit | 40cffcc0e8f9f6e295630cb8b8d58a13baa6c7f9 (patch) | |
tree | eb23aa8ac3866c93708a1aee36fd6ae15a6a863f /drivers/md | |
parent | 63c68268b2fc63f7f612dfebecb5c9cbbd3ebeaf (diff) |
md/bitmap: create a 'struct bitmap_counts' substructure of 'struct bitmap'
The new "struct bitmap_counts" contains all the fields that are
related to counting the number of active writes in each bitmap chunk.
Having this separate will make it easier to change the chunksize
or overall size of a bitmap atomically.
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/bitmap.c | 138 | ||||
-rw-r--r-- | drivers/md/bitmap.h | 23 |
2 files changed, 84 insertions, 77 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c index 7c3c1c58ff1b..c100a47bc157 100644 --- a/drivers/md/bitmap.c +++ b/drivers/md/bitmap.c | |||
@@ -45,7 +45,7 @@ static inline char *bmname(struct bitmap *bitmap) | |||
45 | * if we find our page, we increment the page's refcount so that it stays | 45 | * if we find our page, we increment the page's refcount so that it stays |
46 | * allocated while we're using it | 46 | * allocated while we're using it |
47 | */ | 47 | */ |
48 | static int bitmap_checkpage(struct bitmap *bitmap, | 48 | static int bitmap_checkpage(struct bitmap_counts *bitmap, |
49 | unsigned long page, int create) | 49 | unsigned long page, int create) |
50 | __releases(bitmap->lock) | 50 | __releases(bitmap->lock) |
51 | __acquires(bitmap->lock) | 51 | __acquires(bitmap->lock) |
@@ -76,8 +76,7 @@ __acquires(bitmap->lock) | |||
76 | spin_lock_irq(&bitmap->lock); | 76 | spin_lock_irq(&bitmap->lock); |
77 | 77 | ||
78 | if (mappage == NULL) { | 78 | if (mappage == NULL) { |
79 | pr_debug("%s: bitmap map page allocation failed, hijacking\n", | 79 | pr_debug("md/bitmap: map page allocation failed, hijacking\n"); |
80 | bmname(bitmap)); | ||
81 | /* failed - set the hijacked flag so that we can use the | 80 | /* failed - set the hijacked flag so that we can use the |
82 | * pointer as a counter */ | 81 | * pointer as a counter */ |
83 | if (!bitmap->bp[page].map) | 82 | if (!bitmap->bp[page].map) |
@@ -100,7 +99,7 @@ __acquires(bitmap->lock) | |||
100 | /* if page is completely empty, put it back on the free list, or dealloc it */ | 99 | /* if page is completely empty, put it back on the free list, or dealloc it */ |
101 | /* if page was hijacked, unmark the flag so it might get alloced next time */ | 100 | /* if page was hijacked, unmark the flag so it might get alloced next time */ |
102 | /* Note: lock should be held when calling this */ | 101 | /* Note: lock should be held when calling this */ |
103 | static void bitmap_checkfree(struct bitmap *bitmap, unsigned long page) | 102 | static void bitmap_checkfree(struct bitmap_counts *bitmap, unsigned long page) |
104 | { | 103 | { |
105 | char *ptr; | 104 | char *ptr; |
106 | 105 | ||
@@ -832,7 +831,7 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) | |||
832 | unsigned long bit; | 831 | unsigned long bit; |
833 | struct page *page; | 832 | struct page *page; |
834 | void *kaddr; | 833 | void *kaddr; |
835 | unsigned long chunk = block >> bitmap->chunkshift; | 834 | unsigned long chunk = block >> bitmap->counts.chunkshift; |
836 | 835 | ||
837 | page = filemap_get_page(&bitmap->storage, chunk); | 836 | page = filemap_get_page(&bitmap->storage, chunk); |
838 | if (!page) | 837 | if (!page) |
@@ -856,7 +855,7 @@ static void bitmap_file_clear_bit(struct bitmap *bitmap, sector_t block) | |||
856 | unsigned long bit; | 855 | unsigned long bit; |
857 | struct page *page; | 856 | struct page *page; |
858 | void *paddr; | 857 | void *paddr; |
859 | unsigned long chunk = block >> bitmap->chunkshift; | 858 | unsigned long chunk = block >> bitmap->counts.chunkshift; |
860 | 859 | ||
861 | page = filemap_get_page(&bitmap->storage, chunk); | 860 | page = filemap_get_page(&bitmap->storage, chunk); |
862 | if (!page) | 861 | if (!page) |
@@ -938,7 +937,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) | |||
938 | void *paddr; | 937 | void *paddr; |
939 | struct bitmap_storage *store = &bitmap->storage; | 938 | struct bitmap_storage *store = &bitmap->storage; |
940 | 939 | ||
941 | chunks = bitmap->chunks; | 940 | chunks = bitmap->counts.chunks; |
942 | file = store->file; | 941 | file = store->file; |
943 | 942 | ||
944 | if (!file && !bitmap->mddev->bitmap_info.offset) { | 943 | if (!file && !bitmap->mddev->bitmap_info.offset) { |
@@ -947,10 +946,10 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) | |||
947 | store->file_pages = 0; | 946 | store->file_pages = 0; |
948 | for (i = 0; i < chunks ; i++) { | 947 | for (i = 0; i < chunks ; i++) { |
949 | /* if the disk bit is set, set the memory bit */ | 948 | /* if the disk bit is set, set the memory bit */ |
950 | int needed = ((sector_t)(i+1) << (bitmap->chunkshift) | 949 | int needed = ((sector_t)(i+1) << (bitmap->counts.chunkshift) |
951 | >= start); | 950 | >= start); |
952 | bitmap_set_memory_bits(bitmap, | 951 | bitmap_set_memory_bits(bitmap, |
953 | (sector_t)i << bitmap->chunkshift, | 952 | (sector_t)i << bitmap->counts.chunkshift, |
954 | needed); | 953 | needed); |
955 | } | 954 | } |
956 | return 0; | 955 | return 0; |
@@ -1026,10 +1025,10 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) | |||
1026 | kunmap_atomic(paddr); | 1025 | kunmap_atomic(paddr); |
1027 | if (b) { | 1026 | if (b) { |
1028 | /* if the disk bit is set, set the memory bit */ | 1027 | /* if the disk bit is set, set the memory bit */ |
1029 | int needed = ((sector_t)(i+1) << bitmap->chunkshift | 1028 | int needed = ((sector_t)(i+1) << bitmap->counts.chunkshift |
1030 | >= start); | 1029 | >= start); |
1031 | bitmap_set_memory_bits(bitmap, | 1030 | bitmap_set_memory_bits(bitmap, |
1032 | (sector_t)i << bitmap->chunkshift, | 1031 | (sector_t)i << bitmap->counts.chunkshift, |
1033 | needed); | 1032 | needed); |
1034 | bit_cnt++; | 1033 | bit_cnt++; |
1035 | } | 1034 | } |
@@ -1068,7 +1067,8 @@ void bitmap_write_all(struct bitmap *bitmap) | |||
1068 | bitmap->allclean = 0; | 1067 | bitmap->allclean = 0; |
1069 | } | 1068 | } |
1070 | 1069 | ||
1071 | static void bitmap_count_page(struct bitmap *bitmap, sector_t offset, int inc) | 1070 | static void bitmap_count_page(struct bitmap_counts *bitmap, |
1071 | sector_t offset, int inc) | ||
1072 | { | 1072 | { |
1073 | sector_t chunk = offset >> bitmap->chunkshift; | 1073 | sector_t chunk = offset >> bitmap->chunkshift; |
1074 | unsigned long page = chunk >> PAGE_COUNTER_SHIFT; | 1074 | unsigned long page = chunk >> PAGE_COUNTER_SHIFT; |
@@ -1076,7 +1076,7 @@ static void bitmap_count_page(struct bitmap *bitmap, sector_t offset, int inc) | |||
1076 | bitmap_checkfree(bitmap, page); | 1076 | bitmap_checkfree(bitmap, page); |
1077 | } | 1077 | } |
1078 | 1078 | ||
1079 | static void bitmap_set_pending(struct bitmap *bitmap, sector_t offset) | 1079 | static void bitmap_set_pending(struct bitmap_counts *bitmap, sector_t offset) |
1080 | { | 1080 | { |
1081 | sector_t chunk = offset >> bitmap->chunkshift; | 1081 | sector_t chunk = offset >> bitmap->chunkshift; |
1082 | unsigned long page = chunk >> PAGE_COUNTER_SHIFT; | 1082 | unsigned long page = chunk >> PAGE_COUNTER_SHIFT; |
@@ -1086,7 +1086,7 @@ static void bitmap_set_pending(struct bitmap *bitmap, sector_t offset) | |||
1086 | bp->pending = 1; | 1086 | bp->pending = 1; |
1087 | } | 1087 | } |
1088 | 1088 | ||
1089 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, | 1089 | static bitmap_counter_t *bitmap_get_counter(struct bitmap_counts *bitmap, |
1090 | sector_t offset, sector_t *blocks, | 1090 | sector_t offset, sector_t *blocks, |
1091 | int create); | 1091 | int create); |
1092 | 1092 | ||
@@ -1101,6 +1101,7 @@ void bitmap_daemon_work(struct mddev *mddev) | |||
1101 | unsigned long j; | 1101 | unsigned long j; |
1102 | unsigned long nextpage; | 1102 | unsigned long nextpage; |
1103 | sector_t blocks; | 1103 | sector_t blocks; |
1104 | struct bitmap_counts *counts; | ||
1104 | 1105 | ||
1105 | /* Use a mutex to guard daemon_work against | 1106 | /* Use a mutex to guard daemon_work against |
1106 | * bitmap_destroy. | 1107 | * bitmap_destroy. |
@@ -1150,21 +1151,22 @@ void bitmap_daemon_work(struct mddev *mddev) | |||
1150 | /* Now look at the bitmap counters and if any are '2' or '1', | 1151 | /* Now look at the bitmap counters and if any are '2' or '1', |
1151 | * decrement and handle accordingly. | 1152 | * decrement and handle accordingly. |
1152 | */ | 1153 | */ |
1153 | spin_lock_irq(&bitmap->lock); | 1154 | counts = &bitmap->counts; |
1155 | spin_lock_irq(&counts->lock); | ||
1154 | nextpage = 0; | 1156 | nextpage = 0; |
1155 | for (j = 0; j < bitmap->chunks; j++) { | 1157 | for (j = 0; j < counts->chunks; j++) { |
1156 | bitmap_counter_t *bmc; | 1158 | bitmap_counter_t *bmc; |
1157 | sector_t block = (sector_t)j << bitmap->chunkshift; | 1159 | sector_t block = (sector_t)j << counts->chunkshift; |
1158 | 1160 | ||
1159 | if (j == nextpage) { | 1161 | if (j == nextpage) { |
1160 | nextpage += PAGE_COUNTER_RATIO; | 1162 | nextpage += PAGE_COUNTER_RATIO; |
1161 | if (!bitmap->bp[j >> PAGE_COUNTER_SHIFT].pending) { | 1163 | if (!counts->bp[j >> PAGE_COUNTER_SHIFT].pending) { |
1162 | j |= PAGE_COUNTER_MASK; | 1164 | j |= PAGE_COUNTER_MASK; |
1163 | continue; | 1165 | continue; |
1164 | } | 1166 | } |
1165 | bitmap->bp[j >> PAGE_COUNTER_SHIFT].pending = 0; | 1167 | counts->bp[j >> PAGE_COUNTER_SHIFT].pending = 0; |
1166 | } | 1168 | } |
1167 | bmc = bitmap_get_counter(bitmap, | 1169 | bmc = bitmap_get_counter(counts, |
1168 | block, | 1170 | block, |
1169 | &blocks, 0); | 1171 | &blocks, 0); |
1170 | 1172 | ||
@@ -1175,15 +1177,15 @@ void bitmap_daemon_work(struct mddev *mddev) | |||
1175 | if (*bmc == 1 && !bitmap->need_sync) { | 1177 | if (*bmc == 1 && !bitmap->need_sync) { |
1176 | /* We can clear the bit */ | 1178 | /* We can clear the bit */ |
1177 | *bmc = 0; | 1179 | *bmc = 0; |
1178 | bitmap_count_page(bitmap, block, -1); | 1180 | bitmap_count_page(counts, block, -1); |
1179 | bitmap_file_clear_bit(bitmap, block); | 1181 | bitmap_file_clear_bit(bitmap, block); |
1180 | } else if (*bmc && *bmc <= 2) { | 1182 | } else if (*bmc && *bmc <= 2) { |
1181 | *bmc = 1; | 1183 | *bmc = 1; |
1182 | bitmap_set_pending(bitmap, block); | 1184 | bitmap_set_pending(counts, block); |
1183 | bitmap->allclean = 0; | 1185 | bitmap->allclean = 0; |
1184 | } | 1186 | } |
1185 | } | 1187 | } |
1186 | spin_unlock_irq(&bitmap->lock); | 1188 | spin_unlock_irq(&counts->lock); |
1187 | 1189 | ||
1188 | /* Now start writeout on any page in NEEDWRITE that isn't DIRTY. | 1190 | /* Now start writeout on any page in NEEDWRITE that isn't DIRTY. |
1189 | * DIRTY pages need to be written by bitmap_unplug so it can wait | 1191 | * DIRTY pages need to be written by bitmap_unplug so it can wait |
@@ -1215,7 +1217,7 @@ void bitmap_daemon_work(struct mddev *mddev) | |||
1215 | mutex_unlock(&mddev->bitmap_info.mutex); | 1217 | mutex_unlock(&mddev->bitmap_info.mutex); |
1216 | } | 1218 | } |
1217 | 1219 | ||
1218 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, | 1220 | static bitmap_counter_t *bitmap_get_counter(struct bitmap_counts *bitmap, |
1219 | sector_t offset, sector_t *blocks, | 1221 | sector_t offset, sector_t *blocks, |
1220 | int create) | 1222 | int create) |
1221 | __releases(bitmap->lock) | 1223 | __releases(bitmap->lock) |
@@ -1277,10 +1279,10 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect | |||
1277 | sector_t blocks; | 1279 | sector_t blocks; |
1278 | bitmap_counter_t *bmc; | 1280 | bitmap_counter_t *bmc; |
1279 | 1281 | ||
1280 | spin_lock_irq(&bitmap->lock); | 1282 | spin_lock_irq(&bitmap->counts.lock); |
1281 | bmc = bitmap_get_counter(bitmap, offset, &blocks, 1); | 1283 | bmc = bitmap_get_counter(&bitmap->counts, offset, &blocks, 1); |
1282 | if (!bmc) { | 1284 | if (!bmc) { |
1283 | spin_unlock_irq(&bitmap->lock); | 1285 | spin_unlock_irq(&bitmap->counts.lock); |
1284 | return 0; | 1286 | return 0; |
1285 | } | 1287 | } |
1286 | 1288 | ||
@@ -1292,7 +1294,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect | |||
1292 | */ | 1294 | */ |
1293 | prepare_to_wait(&bitmap->overflow_wait, &__wait, | 1295 | prepare_to_wait(&bitmap->overflow_wait, &__wait, |
1294 | TASK_UNINTERRUPTIBLE); | 1296 | TASK_UNINTERRUPTIBLE); |
1295 | spin_unlock_irq(&bitmap->lock); | 1297 | spin_unlock_irq(&bitmap->counts.lock); |
1296 | io_schedule(); | 1298 | io_schedule(); |
1297 | finish_wait(&bitmap->overflow_wait, &__wait); | 1299 | finish_wait(&bitmap->overflow_wait, &__wait); |
1298 | continue; | 1300 | continue; |
@@ -1301,7 +1303,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect | |||
1301 | switch (*bmc) { | 1303 | switch (*bmc) { |
1302 | case 0: | 1304 | case 0: |
1303 | bitmap_file_set_bit(bitmap, offset); | 1305 | bitmap_file_set_bit(bitmap, offset); |
1304 | bitmap_count_page(bitmap, offset, 1); | 1306 | bitmap_count_page(&bitmap->counts, offset, 1); |
1305 | /* fall through */ | 1307 | /* fall through */ |
1306 | case 1: | 1308 | case 1: |
1307 | *bmc = 2; | 1309 | *bmc = 2; |
@@ -1309,7 +1311,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect | |||
1309 | 1311 | ||
1310 | (*bmc)++; | 1312 | (*bmc)++; |
1311 | 1313 | ||
1312 | spin_unlock_irq(&bitmap->lock); | 1314 | spin_unlock_irq(&bitmap->counts.lock); |
1313 | 1315 | ||
1314 | offset += blocks; | 1316 | offset += blocks; |
1315 | if (sectors > blocks) | 1317 | if (sectors > blocks) |
@@ -1339,10 +1341,10 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto | |||
1339 | unsigned long flags; | 1341 | unsigned long flags; |
1340 | bitmap_counter_t *bmc; | 1342 | bitmap_counter_t *bmc; |
1341 | 1343 | ||
1342 | spin_lock_irqsave(&bitmap->lock, flags); | 1344 | spin_lock_irqsave(&bitmap->counts.lock, flags); |
1343 | bmc = bitmap_get_counter(bitmap, offset, &blocks, 0); | 1345 | bmc = bitmap_get_counter(&bitmap->counts, offset, &blocks, 0); |
1344 | if (!bmc) { | 1346 | if (!bmc) { |
1345 | spin_unlock_irqrestore(&bitmap->lock, flags); | 1347 | spin_unlock_irqrestore(&bitmap->counts.lock, flags); |
1346 | return; | 1348 | return; |
1347 | } | 1349 | } |
1348 | 1350 | ||
@@ -1361,10 +1363,10 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto | |||
1361 | 1363 | ||
1362 | (*bmc)--; | 1364 | (*bmc)--; |
1363 | if (*bmc <= 2) { | 1365 | if (*bmc <= 2) { |
1364 | bitmap_set_pending(bitmap, offset); | 1366 | bitmap_set_pending(&bitmap->counts, offset); |
1365 | bitmap->allclean = 0; | 1367 | bitmap->allclean = 0; |
1366 | } | 1368 | } |
1367 | spin_unlock_irqrestore(&bitmap->lock, flags); | 1369 | spin_unlock_irqrestore(&bitmap->counts.lock, flags); |
1368 | offset += blocks; | 1370 | offset += blocks; |
1369 | if (sectors > blocks) | 1371 | if (sectors > blocks) |
1370 | sectors -= blocks; | 1372 | sectors -= blocks; |
@@ -1383,8 +1385,8 @@ static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t | |||
1383 | *blocks = 1024; | 1385 | *blocks = 1024; |
1384 | return 1; /* always resync if no bitmap */ | 1386 | return 1; /* always resync if no bitmap */ |
1385 | } | 1387 | } |
1386 | spin_lock_irq(&bitmap->lock); | 1388 | spin_lock_irq(&bitmap->counts.lock); |
1387 | bmc = bitmap_get_counter(bitmap, offset, blocks, 0); | 1389 | bmc = bitmap_get_counter(&bitmap->counts, offset, blocks, 0); |
1388 | rv = 0; | 1390 | rv = 0; |
1389 | if (bmc) { | 1391 | if (bmc) { |
1390 | /* locked */ | 1392 | /* locked */ |
@@ -1398,7 +1400,7 @@ static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t | |||
1398 | } | 1400 | } |
1399 | } | 1401 | } |
1400 | } | 1402 | } |
1401 | spin_unlock_irq(&bitmap->lock); | 1403 | spin_unlock_irq(&bitmap->counts.lock); |
1402 | return rv; | 1404 | return rv; |
1403 | } | 1405 | } |
1404 | 1406 | ||
@@ -1435,8 +1437,8 @@ void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, i | |||
1435 | *blocks = 1024; | 1437 | *blocks = 1024; |
1436 | return; | 1438 | return; |
1437 | } | 1439 | } |
1438 | spin_lock_irqsave(&bitmap->lock, flags); | 1440 | spin_lock_irqsave(&bitmap->counts.lock, flags); |
1439 | bmc = bitmap_get_counter(bitmap, offset, blocks, 0); | 1441 | bmc = bitmap_get_counter(&bitmap->counts, offset, blocks, 0); |
1440 | if (bmc == NULL) | 1442 | if (bmc == NULL) |
1441 | goto unlock; | 1443 | goto unlock; |
1442 | /* locked */ | 1444 | /* locked */ |
@@ -1447,13 +1449,13 @@ void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, i | |||
1447 | *bmc |= NEEDED_MASK; | 1449 | *bmc |= NEEDED_MASK; |
1448 | else { | 1450 | else { |
1449 | if (*bmc <= 2) { | 1451 | if (*bmc <= 2) { |
1450 | bitmap_set_pending(bitmap, offset); | 1452 | bitmap_set_pending(&bitmap->counts, offset); |
1451 | bitmap->allclean = 0; | 1453 | bitmap->allclean = 0; |
1452 | } | 1454 | } |
1453 | } | 1455 | } |
1454 | } | 1456 | } |
1455 | unlock: | 1457 | unlock: |
1456 | spin_unlock_irqrestore(&bitmap->lock, flags); | 1458 | spin_unlock_irqrestore(&bitmap->counts.lock, flags); |
1457 | } | 1459 | } |
1458 | EXPORT_SYMBOL(bitmap_end_sync); | 1460 | EXPORT_SYMBOL(bitmap_end_sync); |
1459 | 1461 | ||
@@ -1493,7 +1495,7 @@ void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector) | |||
1493 | 1495 | ||
1494 | bitmap->mddev->curr_resync_completed = sector; | 1496 | bitmap->mddev->curr_resync_completed = sector; |
1495 | set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags); | 1497 | set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags); |
1496 | sector &= ~((1ULL << bitmap->chunkshift) - 1); | 1498 | sector &= ~((1ULL << bitmap->counts.chunkshift) - 1); |
1497 | s = 0; | 1499 | s = 0; |
1498 | while (s < sector && s < bitmap->mddev->resync_max_sectors) { | 1500 | while (s < sector && s < bitmap->mddev->resync_max_sectors) { |
1499 | bitmap_end_sync(bitmap, s, &blocks, 0); | 1501 | bitmap_end_sync(bitmap, s, &blocks, 0); |
@@ -1513,19 +1515,19 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int n | |||
1513 | 1515 | ||
1514 | sector_t secs; | 1516 | sector_t secs; |
1515 | bitmap_counter_t *bmc; | 1517 | bitmap_counter_t *bmc; |
1516 | spin_lock_irq(&bitmap->lock); | 1518 | spin_lock_irq(&bitmap->counts.lock); |
1517 | bmc = bitmap_get_counter(bitmap, offset, &secs, 1); | 1519 | bmc = bitmap_get_counter(&bitmap->counts, offset, &secs, 1); |
1518 | if (!bmc) { | 1520 | if (!bmc) { |
1519 | spin_unlock_irq(&bitmap->lock); | 1521 | spin_unlock_irq(&bitmap->counts.lock); |
1520 | return; | 1522 | return; |
1521 | } | 1523 | } |
1522 | if (!*bmc) { | 1524 | if (!*bmc) { |
1523 | *bmc = 2 | (needed ? NEEDED_MASK : 0); | 1525 | *bmc = 2 | (needed ? NEEDED_MASK : 0); |
1524 | bitmap_count_page(bitmap, offset, 1); | 1526 | bitmap_count_page(&bitmap->counts, offset, 1); |
1525 | bitmap_set_pending(bitmap, offset); | 1527 | bitmap_set_pending(&bitmap->counts, offset); |
1526 | bitmap->allclean = 0; | 1528 | bitmap->allclean = 0; |
1527 | } | 1529 | } |
1528 | spin_unlock_irq(&bitmap->lock); | 1530 | spin_unlock_irq(&bitmap->counts.lock); |
1529 | } | 1531 | } |
1530 | 1532 | ||
1531 | /* dirty the memory and file bits for bitmap chunks "s" to "e" */ | 1533 | /* dirty the memory and file bits for bitmap chunks "s" to "e" */ |
@@ -1534,7 +1536,7 @@ void bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e) | |||
1534 | unsigned long chunk; | 1536 | unsigned long chunk; |
1535 | 1537 | ||
1536 | for (chunk = s; chunk <= e; chunk++) { | 1538 | for (chunk = s; chunk <= e; chunk++) { |
1537 | sector_t sec = (sector_t)chunk << bitmap->chunkshift; | 1539 | sector_t sec = (sector_t)chunk << bitmap->counts.chunkshift; |
1538 | bitmap_set_memory_bits(bitmap, sec, 1); | 1540 | bitmap_set_memory_bits(bitmap, sec, 1); |
1539 | bitmap_file_set_bit(bitmap, sec); | 1541 | bitmap_file_set_bit(bitmap, sec); |
1540 | if (sec < bitmap->mddev->recovery_cp) | 1542 | if (sec < bitmap->mddev->recovery_cp) |
@@ -1588,8 +1590,8 @@ static void bitmap_free(struct bitmap *bitmap) | |||
1588 | /* release the bitmap file */ | 1590 | /* release the bitmap file */ |
1589 | bitmap_file_unmap(&bitmap->storage); | 1591 | bitmap_file_unmap(&bitmap->storage); |
1590 | 1592 | ||
1591 | bp = bitmap->bp; | 1593 | bp = bitmap->counts.bp; |
1592 | pages = bitmap->pages; | 1594 | pages = bitmap->counts.pages; |
1593 | 1595 | ||
1594 | /* free all allocated memory */ | 1596 | /* free all allocated memory */ |
1595 | 1597 | ||
@@ -1642,7 +1644,7 @@ int bitmap_create(struct mddev *mddev) | |||
1642 | if (!bitmap) | 1644 | if (!bitmap) |
1643 | return -ENOMEM; | 1645 | return -ENOMEM; |
1644 | 1646 | ||
1645 | spin_lock_init(&bitmap->lock); | 1647 | spin_lock_init(&bitmap->counts.lock); |
1646 | atomic_set(&bitmap->pending_writes, 0); | 1648 | atomic_set(&bitmap->pending_writes, 0); |
1647 | init_waitqueue_head(&bitmap->write_wait); | 1649 | init_waitqueue_head(&bitmap->write_wait); |
1648 | init_waitqueue_head(&bitmap->overflow_wait); | 1650 | init_waitqueue_head(&bitmap->overflow_wait); |
@@ -1689,27 +1691,28 @@ int bitmap_create(struct mddev *mddev) | |||
1689 | goto error; | 1691 | goto error; |
1690 | 1692 | ||
1691 | bitmap->daemon_lastrun = jiffies; | 1693 | bitmap->daemon_lastrun = jiffies; |
1692 | bitmap->chunkshift = (ffz(~mddev->bitmap_info.chunksize) | 1694 | bitmap->counts.chunkshift = (ffz(~mddev->bitmap_info.chunksize) |
1693 | - BITMAP_BLOCK_SHIFT); | 1695 | - BITMAP_BLOCK_SHIFT); |
1694 | 1696 | ||
1695 | chunks = (blocks + (1 << bitmap->chunkshift) - 1) >> | 1697 | chunks = (blocks + (1 << bitmap->counts.chunkshift) - 1) >> |
1696 | bitmap->chunkshift; | 1698 | bitmap->counts.chunkshift; |
1697 | pages = (chunks + PAGE_COUNTER_RATIO - 1) / PAGE_COUNTER_RATIO; | 1699 | pages = (chunks + PAGE_COUNTER_RATIO - 1) / PAGE_COUNTER_RATIO; |
1698 | 1700 | ||
1699 | BUG_ON(!pages); | 1701 | BUG_ON(!pages); |
1700 | 1702 | ||
1701 | bitmap->chunks = chunks; | 1703 | bitmap->counts.chunks = chunks; |
1702 | bitmap->pages = pages; | 1704 | bitmap->counts.pages = pages; |
1703 | bitmap->missing_pages = pages; | 1705 | bitmap->counts.missing_pages = pages; |
1704 | 1706 | ||
1705 | bitmap->bp = kzalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL); | 1707 | bitmap->counts.bp = kzalloc(pages * sizeof(*bitmap->counts.bp), |
1708 | GFP_KERNEL); | ||
1706 | 1709 | ||
1707 | err = -ENOMEM; | 1710 | err = -ENOMEM; |
1708 | if (!bitmap->bp) | 1711 | if (!bitmap->counts.bp) |
1709 | goto error; | 1712 | goto error; |
1710 | 1713 | ||
1711 | if (file || mddev->bitmap_info.offset) { | 1714 | if (file || mddev->bitmap_info.offset) { |
1712 | err = bitmap_storage_alloc(&bitmap->storage, bitmap->chunks, | 1715 | err = bitmap_storage_alloc(&bitmap->storage, bitmap->counts.chunks, |
1713 | !mddev->bitmap_info.external); | 1716 | !mddev->bitmap_info.external); |
1714 | if (err) | 1717 | if (err) |
1715 | goto error; | 1718 | goto error; |
@@ -1781,17 +1784,19 @@ EXPORT_SYMBOL_GPL(bitmap_load); | |||
1781 | void bitmap_status(struct seq_file *seq, struct bitmap *bitmap) | 1784 | void bitmap_status(struct seq_file *seq, struct bitmap *bitmap) |
1782 | { | 1785 | { |
1783 | unsigned long chunk_kb; | 1786 | unsigned long chunk_kb; |
1787 | struct bitmap_counts *counts; | ||
1784 | 1788 | ||
1785 | if (!bitmap) | 1789 | if (!bitmap) |
1786 | return; | 1790 | return; |
1787 | 1791 | ||
1788 | spin_lock_irq(&bitmap->lock); | 1792 | counts = &bitmap->counts; |
1793 | |||
1789 | chunk_kb = bitmap->mddev->bitmap_info.chunksize >> 10; | 1794 | chunk_kb = bitmap->mddev->bitmap_info.chunksize >> 10; |
1790 | seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], " | 1795 | seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], " |
1791 | "%lu%s chunk", | 1796 | "%lu%s chunk", |
1792 | bitmap->pages - bitmap->missing_pages, | 1797 | counts->pages - counts->missing_pages, |
1793 | bitmap->pages, | 1798 | counts->pages, |
1794 | (bitmap->pages - bitmap->missing_pages) | 1799 | (counts->pages - counts->missing_pages) |
1795 | << (PAGE_SHIFT - 10), | 1800 | << (PAGE_SHIFT - 10), |
1796 | chunk_kb ? chunk_kb : bitmap->mddev->bitmap_info.chunksize, | 1801 | chunk_kb ? chunk_kb : bitmap->mddev->bitmap_info.chunksize, |
1797 | chunk_kb ? "KB" : "B"); | 1802 | chunk_kb ? "KB" : "B"); |
@@ -1801,7 +1806,6 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap) | |||
1801 | } | 1806 | } |
1802 | 1807 | ||
1803 | seq_printf(seq, "\n"); | 1808 | seq_printf(seq, "\n"); |
1804 | spin_unlock_irq(&bitmap->lock); | ||
1805 | } | 1809 | } |
1806 | 1810 | ||
1807 | static ssize_t | 1811 | static ssize_t |
diff --git a/drivers/md/bitmap.h b/drivers/md/bitmap.h index e2d999a62ba9..6bde180e987b 100644 --- a/drivers/md/bitmap.h +++ b/drivers/md/bitmap.h | |||
@@ -172,22 +172,25 @@ struct bitmap_page { | |||
172 | 172 | ||
173 | /* the main bitmap structure - one per mddev */ | 173 | /* the main bitmap structure - one per mddev */ |
174 | struct bitmap { | 174 | struct bitmap { |
175 | struct bitmap_page *bp; | ||
176 | unsigned long pages; /* total number of pages in the bitmap */ | ||
177 | unsigned long missing_pages; /* number of pages not yet allocated */ | ||
178 | 175 | ||
179 | struct mddev *mddev; /* the md device that the bitmap is for */ | 176 | struct bitmap_counts { |
177 | spinlock_t lock; | ||
178 | struct bitmap_page *bp; | ||
179 | unsigned long pages; /* total number of pages | ||
180 | * in the bitmap */ | ||
181 | unsigned long missing_pages; /* number of pages | ||
182 | * not yet allocated */ | ||
183 | unsigned long chunkshift; /* chunksize = 2^chunkshift | ||
184 | * (for bitops) */ | ||
185 | unsigned long chunks; /* Total number of data | ||
186 | * chunks for the array */ | ||
187 | } counts; | ||
180 | 188 | ||
181 | /* bitmap chunksize -- how much data does each bit represent? */ | 189 | struct mddev *mddev; /* the md device that the bitmap is for */ |
182 | unsigned long chunkshift; /* chunksize = 2^(chunkshift+9) (for bitops) */ | ||
183 | unsigned long chunks; /* total number of data chunks for the array */ | ||
184 | 190 | ||
185 | __u64 events_cleared; | 191 | __u64 events_cleared; |
186 | int need_sync; | 192 | int need_sync; |
187 | 193 | ||
188 | /* bitmap spinlock */ | ||
189 | spinlock_t lock; | ||
190 | |||
191 | struct bitmap_storage { | 194 | struct bitmap_storage { |
192 | struct file *file; /* backing disk file */ | 195 | struct file *file; /* backing disk file */ |
193 | struct page *sb_page; /* cached copy of the bitmap | 196 | struct page *sb_page; /* cached copy of the bitmap |