diff options
author | NeilBrown <neilb@suse.de> | 2005-11-09 00:39:32 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-11-09 10:56:38 -0500 |
commit | bd926c63b7a6843d3ce2728396c0891e54fce5c4 (patch) | |
tree | 38f7083a733e9b31efe69616c5fa3448c74c1320 /drivers | |
parent | b2d444d7ad975d555bb919601bcdc0e58975a40e (diff) |
[PATCH] md: make md on-disk bitmaps not host-endian
Current bitmaps use set_bit et.al and so are host-endian, which means
not-portable. Oops.
Define a new version number (4) for which bitmaps are little-endian.
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/md/bitmap.c | 22 | ||||
-rw-r--r-- | drivers/md/md.c | 2 |
2 files changed, 19 insertions, 5 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c index c5fa4c2a5af1..220273e81ed6 100644 --- a/drivers/md/bitmap.c +++ b/drivers/md/bitmap.c | |||
@@ -482,7 +482,8 @@ static int bitmap_read_sb(struct bitmap *bitmap) | |||
482 | /* verify that the bitmap-specific fields are valid */ | 482 | /* verify that the bitmap-specific fields are valid */ |
483 | if (sb->magic != cpu_to_le32(BITMAP_MAGIC)) | 483 | if (sb->magic != cpu_to_le32(BITMAP_MAGIC)) |
484 | reason = "bad magic"; | 484 | reason = "bad magic"; |
485 | else if (sb->version != cpu_to_le32(BITMAP_MAJOR)) | 485 | else if (le32_to_cpu(sb->version) < BITMAP_MAJOR_LO || |
486 | le32_to_cpu(sb->version) > BITMAP_MAJOR_HI) | ||
486 | reason = "unrecognized superblock version"; | 487 | reason = "unrecognized superblock version"; |
487 | else if (chunksize < 512 || chunksize > (1024 * 1024 * 4)) | 488 | else if (chunksize < 512 || chunksize > (1024 * 1024 * 4)) |
488 | reason = "bitmap chunksize out of range (512B - 4MB)"; | 489 | reason = "bitmap chunksize out of range (512B - 4MB)"; |
@@ -527,6 +528,8 @@ success: | |||
527 | bitmap->daemon_lastrun = jiffies; | 528 | bitmap->daemon_lastrun = jiffies; |
528 | bitmap->max_write_behind = write_behind; | 529 | bitmap->max_write_behind = write_behind; |
529 | bitmap->flags |= sb->state; | 530 | bitmap->flags |= sb->state; |
531 | if (le32_to_cpu(sb->version) == BITMAP_MAJOR_HOSTENDIAN) | ||
532 | bitmap->flags |= BITMAP_HOSTENDIAN; | ||
530 | bitmap->events_cleared = le64_to_cpu(sb->events_cleared); | 533 | bitmap->events_cleared = le64_to_cpu(sb->events_cleared); |
531 | if (sb->state & BITMAP_STALE) | 534 | if (sb->state & BITMAP_STALE) |
532 | bitmap->events_cleared = bitmap->mddev->events; | 535 | bitmap->events_cleared = bitmap->mddev->events; |
@@ -764,7 +767,10 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) | |||
764 | 767 | ||
765 | /* set the bit */ | 768 | /* set the bit */ |
766 | kaddr = kmap_atomic(page, KM_USER0); | 769 | kaddr = kmap_atomic(page, KM_USER0); |
767 | set_bit(bit, kaddr); | 770 | if (bitmap->flags & BITMAP_HOSTENDIAN) |
771 | set_bit(bit, kaddr); | ||
772 | else | ||
773 | ext2_set_bit(bit, kaddr); | ||
768 | kunmap_atomic(kaddr, KM_USER0); | 774 | kunmap_atomic(kaddr, KM_USER0); |
769 | PRINTK("set file bit %lu page %lu\n", bit, page->index); | 775 | PRINTK("set file bit %lu page %lu\n", bit, page->index); |
770 | 776 | ||
@@ -891,6 +897,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) | |||
891 | oldindex = ~0L; | 897 | oldindex = ~0L; |
892 | 898 | ||
893 | for (i = 0; i < chunks; i++) { | 899 | for (i = 0; i < chunks; i++) { |
900 | int b; | ||
894 | index = file_page_index(i); | 901 | index = file_page_index(i); |
895 | bit = file_page_offset(i); | 902 | bit = file_page_offset(i); |
896 | if (index != oldindex) { /* this is a new page, read it in */ | 903 | if (index != oldindex) { /* this is a new page, read it in */ |
@@ -939,7 +946,11 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) | |||
939 | 946 | ||
940 | bitmap->filemap[bitmap->file_pages++] = page; | 947 | bitmap->filemap[bitmap->file_pages++] = page; |
941 | } | 948 | } |
942 | if (test_bit(bit, page_address(page))) { | 949 | if (bitmap->flags & BITMAP_HOSTENDIAN) |
950 | b = test_bit(bit, page_address(page)); | ||
951 | else | ||
952 | b = ext2_test_bit(bit, page_address(page)); | ||
953 | if (b) { | ||
943 | /* if the disk bit is set, set the memory bit */ | 954 | /* if the disk bit is set, set the memory bit */ |
944 | bitmap_set_memory_bits(bitmap, i << CHUNK_BLOCK_SHIFT(bitmap), | 955 | bitmap_set_memory_bits(bitmap, i << CHUNK_BLOCK_SHIFT(bitmap), |
945 | ((i+1) << (CHUNK_BLOCK_SHIFT(bitmap)) >= start) | 956 | ((i+1) << (CHUNK_BLOCK_SHIFT(bitmap)) >= start) |
@@ -1097,7 +1108,10 @@ int bitmap_daemon_work(struct bitmap *bitmap) | |||
1097 | -1); | 1108 | -1); |
1098 | 1109 | ||
1099 | /* clear the bit */ | 1110 | /* clear the bit */ |
1100 | clear_bit(file_page_offset(j), page_address(page)); | 1111 | if (bitmap->flags & BITMAP_HOSTENDIAN) |
1112 | clear_bit(file_page_offset(j), page_address(page)); | ||
1113 | else | ||
1114 | ext2_clear_bit(file_page_offset(j), page_address(page)); | ||
1101 | } | 1115 | } |
1102 | } | 1116 | } |
1103 | spin_unlock_irqrestore(&bitmap->lock, flags); | 1117 | spin_unlock_irqrestore(&bitmap->lock, flags); |
diff --git a/drivers/md/md.c b/drivers/md/md.c index 9dfa063d1c6a..caa4add00c1b 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
@@ -4281,7 +4281,7 @@ static int __init md_init(void) | |||
4281 | " MD_SB_DISKS=%d\n", | 4281 | " MD_SB_DISKS=%d\n", |
4282 | MD_MAJOR_VERSION, MD_MINOR_VERSION, | 4282 | MD_MAJOR_VERSION, MD_MINOR_VERSION, |
4283 | MD_PATCHLEVEL_VERSION, MAX_MD_DEVS, MD_SB_DISKS); | 4283 | MD_PATCHLEVEL_VERSION, MAX_MD_DEVS, MD_SB_DISKS); |
4284 | printk(KERN_INFO "md: bitmap version %d.%d\n", BITMAP_MAJOR, | 4284 | printk(KERN_INFO "md: bitmap version %d.%d\n", BITMAP_MAJOR_HI, |
4285 | BITMAP_MINOR); | 4285 | BITMAP_MINOR); |
4286 | 4286 | ||
4287 | if (register_blkdev(MAJOR_NR, "md")) | 4287 | if (register_blkdev(MAJOR_NR, "md")) |