Fix patch formatting.
[ext4-patch-queue.git] / ext4-ext4_find_next_zero_bit_needs_aligned_address-fix.patch
blobadb730db06e0d614cd1d167f5ea4fd756bcfeb9d
1 ext4: ext4_find_next_zero_bit needs an aligned address on some arch
3 From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
5 ext4_find_next_zero_bit and ext4_find_next_bit needs a long aligned
6 address on x8_64. Add mb_find_next_zero_bit and mb_find_next_bit
7 and use them in the mballoc.
9 Fix: https://bugzilla.redhat.com/show_bug.cgi?id=433286
11 Eric Sandeen debugged the problem and suggested the fix.
13 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
14 Acked-by: Eric Sandeen <sandeen@redhat.com>
15 Signed-off-by: Mingming Cao <cmm@us.ibm.com>
16 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
17 ---
18 fs/ext4/mballoc.c | 62 ++++++++++++++++++++++++++++++++++--------------------
19 1 file changed, 40 insertions(+), 22 deletions(-)
21 Index: linux-2.6.25-rc2/fs/ext4/mballoc.c
22 ===================================================================
23 --- linux-2.6.25-rc2.orig/fs/ext4/mballoc.c 2008-02-20 08:18:30.000000000 -0800
24 +++ linux-2.6.25-rc2/fs/ext4/mballoc.c 2008-02-20 08:20:30.000000000 -0800
25 @@ -627,21 +627,19 @@ static ext4_fsblk_t ext4_grp_offs_to_blo
26 return block;
29 +static inline void *mb_correct_addr_and_bit(int *bit, void *addr)
31 #if BITS_PER_LONG == 64
32 -#define mb_correct_addr_and_bit(bit, addr) \
33 -{ \
34 - bit += ((unsigned long) addr & 7UL) << 3; \
35 - addr = (void *) ((unsigned long) addr & ~7UL); \
37 + *bit += ((unsigned long) addr & 7UL) << 3;
38 + addr = (void *) ((unsigned long) addr & ~7UL);
39 #elif BITS_PER_LONG == 32
40 -#define mb_correct_addr_and_bit(bit, addr) \
41 -{ \
42 - bit += ((unsigned long) addr & 3UL) << 3; \
43 - addr = (void *) ((unsigned long) addr & ~3UL); \
45 + *bit += ((unsigned long) addr & 3UL) << 3;
46 + addr = (void *) ((unsigned long) addr & ~3UL);
47 #else
48 #error "how many bits you are?!"
49 #endif
50 + return addr;
53 static inline int mb_test_bit(int bit, void *addr)
55 @@ -649,34 +647,54 @@ static inline int mb_test_bit(int bit, v
56 * ext4_test_bit on architecture like powerpc
57 * needs unsigned long aligned address
59 - mb_correct_addr_and_bit(bit, addr);
60 + addr = mb_correct_addr_and_bit(&bit, addr);
61 return ext4_test_bit(bit, addr);
64 static inline void mb_set_bit(int bit, void *addr)
66 - mb_correct_addr_and_bit(bit, addr);
67 + addr = mb_correct_addr_and_bit(&bit, addr);
68 ext4_set_bit(bit, addr);
71 static inline void mb_set_bit_atomic(spinlock_t *lock, int bit, void *addr)
73 - mb_correct_addr_and_bit(bit, addr);
74 + addr = mb_correct_addr_and_bit(&bit, addr);
75 ext4_set_bit_atomic(lock, bit, addr);
78 static inline void mb_clear_bit(int bit, void *addr)
80 - mb_correct_addr_and_bit(bit, addr);
81 + addr = mb_correct_addr_and_bit(&bit, addr);
82 ext4_clear_bit(bit, addr);
85 static inline void mb_clear_bit_atomic(spinlock_t *lock, int bit, void *addr)
87 - mb_correct_addr_and_bit(bit, addr);
88 + addr = mb_correct_addr_and_bit(&bit, addr);
89 ext4_clear_bit_atomic(lock, bit, addr);
92 +static inline int mb_find_next_zero_bit(void *addr, int max, int start)
94 + int fix = 0;
95 + addr = mb_correct_addr_and_bit(&fix, addr);
96 + max += fix;
97 + start += fix;
99 + return ext4_find_next_zero_bit(addr, max, start) - fix;
102 +static inline int mb_find_next_bit(void *addr, int max, int start)
104 + int fix = 0;
105 + addr = mb_correct_addr_and_bit(&fix, addr);
106 + max += fix;
107 + start += fix;
109 + return ext4_find_next_bit(addr, max, start) - fix;
112 static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max)
114 char *bb;
115 @@ -946,12 +964,12 @@ static void ext4_mb_generate_buddy(struc
117 /* initialize buddy from bitmap which is aggregation
118 * of on-disk bitmap and preallocations */
119 - i = ext4_find_next_zero_bit(bitmap, max, 0);
120 + i = mb_find_next_zero_bit(bitmap, max, 0);
121 grp->bb_first_free = i;
122 while (i < max) {
123 fragments++;
124 first = i;
125 - i = ext4_find_next_bit(bitmap, max, i);
126 + i = mb_find_next_bit(bitmap, max, i);
127 len = i - first;
128 free += len;
129 if (len > 1)
130 @@ -959,7 +977,7 @@ static void ext4_mb_generate_buddy(struc
131 else
132 grp->bb_counters[0]++;
133 if (i < max)
134 - i = ext4_find_next_zero_bit(bitmap, max, i);
135 + i = mb_find_next_zero_bit(bitmap, max, i);
137 grp->bb_fragments = fragments;
139 @@ -1782,7 +1800,7 @@ static void ext4_mb_simple_scan_group(st
140 buddy = mb_find_buddy(e4b, i, &max);
141 BUG_ON(buddy == NULL);
143 - k = ext4_find_next_zero_bit(buddy, max, 0);
144 + k = mb_find_next_zero_bit(buddy, max, 0);
145 BUG_ON(k >= max);
147 ac->ac_found++;
148 @@ -1822,7 +1840,7 @@ static void ext4_mb_complex_scan_group(s
149 i = e4b->bd_info->bb_first_free;
151 while (free && ac->ac_status == AC_STATUS_CONTINUE) {
152 - i = ext4_find_next_zero_bit(bitmap,
153 + i = mb_find_next_zero_bit(bitmap,
154 EXT4_BLOCKS_PER_GROUP(sb), i);
155 if (i >= EXT4_BLOCKS_PER_GROUP(sb)) {
157 @@ -3750,10 +3768,10 @@ static int ext4_mb_release_inode_pa(stru
160 while (bit < end) {
161 - bit = ext4_find_next_zero_bit(bitmap_bh->b_data, end, bit);
162 + bit = mb_find_next_zero_bit(bitmap_bh->b_data, end, bit);
163 if (bit >= end)
164 break;
165 - next = ext4_find_next_bit(bitmap_bh->b_data, end, bit);
166 + next = mb_find_next_bit(bitmap_bh->b_data, end, bit);
167 if (next > end)
168 next = end;
169 start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit +