diff options
Diffstat (limited to 'fs/reiserfs/bitmap.c')
-rw-r--r-- | fs/reiserfs/bitmap.c | 259 |
1 files changed, 167 insertions, 92 deletions
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c index 1bcffeab713c..dc198bc64c61 100644 --- a/fs/reiserfs/bitmap.c +++ b/fs/reiserfs/bitmap.c | |||
@@ -50,8 +50,10 @@ static inline void get_bit_address(struct super_block *s, | |||
50 | unsigned int *bmap_nr, | 50 | unsigned int *bmap_nr, |
51 | unsigned int *offset) | 51 | unsigned int *offset) |
52 | { | 52 | { |
53 | /* It is in the bitmap block number equal to the block | 53 | /* |
54 | * number divided by the number of bits in a block. */ | 54 | * It is in the bitmap block number equal to the block |
55 | * number divided by the number of bits in a block. | ||
56 | */ | ||
55 | *bmap_nr = block >> (s->s_blocksize_bits + 3); | 57 | *bmap_nr = block >> (s->s_blocksize_bits + 3); |
56 | /* Within that bitmap block it is located at bit offset *offset. */ | 58 | /* Within that bitmap block it is located at bit offset *offset. */ |
57 | *offset = block & ((s->s_blocksize << 3) - 1); | 59 | *offset = block & ((s->s_blocksize << 3) - 1); |
@@ -71,10 +73,12 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) | |||
71 | 73 | ||
72 | get_bit_address(s, block, &bmap, &offset); | 74 | get_bit_address(s, block, &bmap, &offset); |
73 | 75 | ||
74 | /* Old format filesystem? Unlikely, but the bitmaps are all up front so | 76 | /* |
75 | * we need to account for it. */ | 77 | * Old format filesystem? Unlikely, but the bitmaps are all |
78 | * up front so we need to account for it. | ||
79 | */ | ||
76 | if (unlikely(test_bit(REISERFS_OLD_FORMAT, | 80 | if (unlikely(test_bit(REISERFS_OLD_FORMAT, |
77 | &(REISERFS_SB(s)->s_properties)))) { | 81 | &REISERFS_SB(s)->s_properties))) { |
78 | b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1; | 82 | b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1; |
79 | if (block >= bmap1 && | 83 | if (block >= bmap1 && |
80 | block <= bmap1 + bmap_count) { | 84 | block <= bmap1 + bmap_count) { |
@@ -108,8 +112,11 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) | |||
108 | return 1; | 112 | return 1; |
109 | } | 113 | } |
110 | 114 | ||
111 | /* searches in journal structures for a given block number (bmap, off). If block | 115 | /* |
112 | is found in reiserfs journal it suggests next free block candidate to test. */ | 116 | * Searches in journal structures for a given block number (bmap, off). |
117 | * If block is found in reiserfs journal it suggests next free block | ||
118 | * candidate to test. | ||
119 | */ | ||
113 | static inline int is_block_in_journal(struct super_block *s, unsigned int bmap, | 120 | static inline int is_block_in_journal(struct super_block *s, unsigned int bmap, |
114 | int off, int *next) | 121 | int off, int *next) |
115 | { | 122 | { |
@@ -120,7 +127,7 @@ static inline int is_block_in_journal(struct super_block *s, unsigned int bmap, | |||
120 | *next = tmp; | 127 | *next = tmp; |
121 | PROC_INFO_INC(s, scan_bitmap.in_journal_hint); | 128 | PROC_INFO_INC(s, scan_bitmap.in_journal_hint); |
122 | } else { | 129 | } else { |
123 | (*next) = off + 1; /* inc offset to avoid looping. */ | 130 | (*next) = off + 1; /* inc offset to avoid looping. */ |
124 | PROC_INFO_INC(s, scan_bitmap.in_journal_nohint); | 131 | PROC_INFO_INC(s, scan_bitmap.in_journal_nohint); |
125 | } | 132 | } |
126 | PROC_INFO_INC(s, scan_bitmap.retry); | 133 | PROC_INFO_INC(s, scan_bitmap.retry); |
@@ -129,8 +136,10 @@ static inline int is_block_in_journal(struct super_block *s, unsigned int bmap, | |||
129 | return 0; | 136 | return 0; |
130 | } | 137 | } |
131 | 138 | ||
132 | /* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap | 139 | /* |
133 | * block; */ | 140 | * Searches for a window of zero bits with given minimum and maximum |
141 | * lengths in one bitmap block | ||
142 | */ | ||
134 | static int scan_bitmap_block(struct reiserfs_transaction_handle *th, | 143 | static int scan_bitmap_block(struct reiserfs_transaction_handle *th, |
135 | unsigned int bmap_n, int *beg, int boundary, | 144 | unsigned int bmap_n, int *beg, int boundary, |
136 | int min, int max, int unfm) | 145 | int min, int max, int unfm) |
@@ -145,10 +154,6 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th, | |||
145 | RFALSE(bmap_n >= reiserfs_bmap_count(s), "Bitmap %u is out of " | 154 | RFALSE(bmap_n >= reiserfs_bmap_count(s), "Bitmap %u is out of " |
146 | "range (0..%u)", bmap_n, reiserfs_bmap_count(s) - 1); | 155 | "range (0..%u)", bmap_n, reiserfs_bmap_count(s) - 1); |
147 | PROC_INFO_INC(s, scan_bitmap.bmap); | 156 | PROC_INFO_INC(s, scan_bitmap.bmap); |
148 | /* this is unclear and lacks comments, explain how journal bitmaps | ||
149 | work here for the reader. Convey a sense of the design here. What | ||
150 | is a window? */ | ||
151 | /* - I mean `a window of zero bits' as in description of this function - Zam. */ | ||
152 | 157 | ||
153 | if (!bi) { | 158 | if (!bi) { |
154 | reiserfs_error(s, "jdm-4055", "NULL bitmap info pointer " | 159 | reiserfs_error(s, "jdm-4055", "NULL bitmap info pointer " |
@@ -161,18 +166,21 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th, | |||
161 | return 0; | 166 | return 0; |
162 | 167 | ||
163 | while (1) { | 168 | while (1) { |
164 | cont: | 169 | cont: |
165 | if (bi->free_count < min) { | 170 | if (bi->free_count < min) { |
166 | brelse(bh); | 171 | brelse(bh); |
167 | return 0; // No free blocks in this bitmap | 172 | return 0; /* No free blocks in this bitmap */ |
168 | } | 173 | } |
169 | 174 | ||
170 | /* search for a first zero bit -- beginning of a window */ | 175 | /* search for a first zero bit -- beginning of a window */ |
171 | *beg = reiserfs_find_next_zero_le_bit | 176 | *beg = reiserfs_find_next_zero_le_bit |
172 | ((unsigned long *)(bh->b_data), boundary, *beg); | 177 | ((unsigned long *)(bh->b_data), boundary, *beg); |
173 | 178 | ||
174 | if (*beg + min > boundary) { /* search for a zero bit fails or the rest of bitmap block | 179 | /* |
175 | * cannot contain a zero window of minimum size */ | 180 | * search for a zero bit fails or the rest of bitmap block |
181 | * cannot contain a zero window of minimum size | ||
182 | */ | ||
183 | if (*beg + min > boundary) { | ||
176 | brelse(bh); | 184 | brelse(bh); |
177 | return 0; | 185 | return 0; |
178 | } | 186 | } |
@@ -186,49 +194,75 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th, | |||
186 | next = end; | 194 | next = end; |
187 | break; | 195 | break; |
188 | } | 196 | } |
189 | /* finding the other end of zero bit window requires looking into journal structures (in | 197 | |
190 | * case of searching for free blocks for unformatted nodes) */ | 198 | /* |
199 | * finding the other end of zero bit window requires | ||
200 | * looking into journal structures (in case of | ||
201 | * searching for free blocks for unformatted nodes) | ||
202 | */ | ||
191 | if (unfm && is_block_in_journal(s, bmap_n, end, &next)) | 203 | if (unfm && is_block_in_journal(s, bmap_n, end, &next)) |
192 | break; | 204 | break; |
193 | } | 205 | } |
194 | 206 | ||
195 | /* now (*beg) points to beginning of zero bits window, | 207 | /* |
196 | * (end) points to one bit after the window end */ | 208 | * now (*beg) points to beginning of zero bits window, |
197 | if (end - *beg >= min) { /* it seems we have found window of proper size */ | 209 | * (end) points to one bit after the window end |
210 | */ | ||
211 | |||
212 | /* found window of proper size */ | ||
213 | if (end - *beg >= min) { | ||
198 | int i; | 214 | int i; |
199 | reiserfs_prepare_for_journal(s, bh, 1); | 215 | reiserfs_prepare_for_journal(s, bh, 1); |
200 | /* try to set all blocks used checking are they still free */ | 216 | /* |
217 | * try to set all blocks used checking are | ||
218 | * they still free | ||
219 | */ | ||
201 | for (i = *beg; i < end; i++) { | 220 | for (i = *beg; i < end; i++) { |
202 | /* It seems that we should not check in journal again. */ | 221 | /* Don't check in journal again. */ |
203 | if (reiserfs_test_and_set_le_bit | 222 | if (reiserfs_test_and_set_le_bit |
204 | (i, bh->b_data)) { | 223 | (i, bh->b_data)) { |
205 | /* bit was set by another process | 224 | /* |
206 | * while we slept in prepare_for_journal() */ | 225 | * bit was set by another process while |
226 | * we slept in prepare_for_journal() | ||
227 | */ | ||
207 | PROC_INFO_INC(s, scan_bitmap.stolen); | 228 | PROC_INFO_INC(s, scan_bitmap.stolen); |
208 | if (i >= *beg + min) { /* we can continue with smaller set of allocated blocks, | 229 | |
209 | * if length of this set is more or equal to `min' */ | 230 | /* |
231 | * we can continue with smaller set | ||
232 | * of allocated blocks, if length of | ||
233 | * this set is more or equal to `min' | ||
234 | */ | ||
235 | if (i >= *beg + min) { | ||
210 | end = i; | 236 | end = i; |
211 | break; | 237 | break; |
212 | } | 238 | } |
213 | /* otherwise we clear all bit were set ... */ | 239 | |
240 | /* | ||
241 | * otherwise we clear all bit | ||
242 | * were set ... | ||
243 | */ | ||
214 | while (--i >= *beg) | 244 | while (--i >= *beg) |
215 | reiserfs_clear_le_bit | 245 | reiserfs_clear_le_bit |
216 | (i, bh->b_data); | 246 | (i, bh->b_data); |
217 | reiserfs_restore_prepared_buffer(s, bh); | 247 | reiserfs_restore_prepared_buffer(s, bh); |
218 | *beg = org; | 248 | *beg = org; |
219 | /* ... and search again in current block from beginning */ | 249 | |
250 | /* | ||
251 | * Search again in current block | ||
252 | * from beginning | ||
253 | */ | ||
220 | goto cont; | 254 | goto cont; |
221 | } | 255 | } |
222 | } | 256 | } |
223 | bi->free_count -= (end - *beg); | 257 | bi->free_count -= (end - *beg); |
224 | journal_mark_dirty(th, s, bh); | 258 | journal_mark_dirty(th, bh); |
225 | brelse(bh); | 259 | brelse(bh); |
226 | 260 | ||
227 | /* free block count calculation */ | 261 | /* free block count calculation */ |
228 | reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), | 262 | reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), |
229 | 1); | 263 | 1); |
230 | PUT_SB_FREE_BLOCKS(s, SB_FREE_BLOCKS(s) - (end - *beg)); | 264 | PUT_SB_FREE_BLOCKS(s, SB_FREE_BLOCKS(s) - (end - *beg)); |
231 | journal_mark_dirty(th, s, SB_BUFFER_WITH_SB(s)); | 265 | journal_mark_dirty(th, SB_BUFFER_WITH_SB(s)); |
232 | 266 | ||
233 | return end - (*beg); | 267 | return end - (*beg); |
234 | } else { | 268 | } else { |
@@ -267,11 +301,13 @@ static inline int block_group_used(struct super_block *s, u32 id) | |||
267 | int bm = bmap_hash_id(s, id); | 301 | int bm = bmap_hash_id(s, id); |
268 | struct reiserfs_bitmap_info *info = &SB_AP_BITMAP(s)[bm]; | 302 | struct reiserfs_bitmap_info *info = &SB_AP_BITMAP(s)[bm]; |
269 | 303 | ||
270 | /* If we don't have cached information on this bitmap block, we're | 304 | /* |
305 | * If we don't have cached information on this bitmap block, we're | ||
271 | * going to have to load it later anyway. Loading it here allows us | 306 | * going to have to load it later anyway. Loading it here allows us |
272 | * to make a better decision. This favors long-term performance gain | 307 | * to make a better decision. This favors long-term performance gain |
273 | * with a better on-disk layout vs. a short term gain of skipping the | 308 | * with a better on-disk layout vs. a short term gain of skipping the |
274 | * read and potentially having a bad placement. */ | 309 | * read and potentially having a bad placement. |
310 | */ | ||
275 | if (info->free_count == UINT_MAX) { | 311 | if (info->free_count == UINT_MAX) { |
276 | struct buffer_head *bh = reiserfs_read_bitmap_block(s, bm); | 312 | struct buffer_head *bh = reiserfs_read_bitmap_block(s, bm); |
277 | brelse(bh); | 313 | brelse(bh); |
@@ -304,25 +340,26 @@ __le32 reiserfs_choose_packing(struct inode * dir) | |||
304 | return packing; | 340 | return packing; |
305 | } | 341 | } |
306 | 342 | ||
307 | /* Tries to find contiguous zero bit window (given size) in given region of | 343 | /* |
308 | * bitmap and place new blocks there. Returns number of allocated blocks. */ | 344 | * Tries to find contiguous zero bit window (given size) in given region of |
345 | * bitmap and place new blocks there. Returns number of allocated blocks. | ||
346 | */ | ||
309 | static int scan_bitmap(struct reiserfs_transaction_handle *th, | 347 | static int scan_bitmap(struct reiserfs_transaction_handle *th, |
310 | b_blocknr_t * start, b_blocknr_t finish, | 348 | b_blocknr_t * start, b_blocknr_t finish, |
311 | int min, int max, int unfm, sector_t file_block) | 349 | int min, int max, int unfm, sector_t file_block) |
312 | { | 350 | { |
313 | int nr_allocated = 0; | 351 | int nr_allocated = 0; |
314 | struct super_block *s = th->t_super; | 352 | struct super_block *s = th->t_super; |
315 | /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr | ||
316 | * - Hans, it is not a block number - Zam. */ | ||
317 | |||
318 | unsigned int bm, off; | 353 | unsigned int bm, off; |
319 | unsigned int end_bm, end_off; | 354 | unsigned int end_bm, end_off; |
320 | unsigned int off_max = s->s_blocksize << 3; | 355 | unsigned int off_max = s->s_blocksize << 3; |
321 | 356 | ||
322 | BUG_ON(!th->t_trans_id); | 357 | BUG_ON(!th->t_trans_id); |
323 | PROC_INFO_INC(s, scan_bitmap.call); | 358 | PROC_INFO_INC(s, scan_bitmap.call); |
359 | |||
360 | /* No point in looking for more free blocks */ | ||
324 | if (SB_FREE_BLOCKS(s) <= 0) | 361 | if (SB_FREE_BLOCKS(s) <= 0) |
325 | return 0; // No point in looking for more free blocks | 362 | return 0; |
326 | 363 | ||
327 | get_bit_address(s, *start, &bm, &off); | 364 | get_bit_address(s, *start, &bm, &off); |
328 | get_bit_address(s, finish, &end_bm, &end_off); | 365 | get_bit_address(s, finish, &end_bm, &end_off); |
@@ -331,7 +368,8 @@ static int scan_bitmap(struct reiserfs_transaction_handle *th, | |||
331 | if (end_bm > reiserfs_bmap_count(s)) | 368 | if (end_bm > reiserfs_bmap_count(s)) |
332 | end_bm = reiserfs_bmap_count(s); | 369 | end_bm = reiserfs_bmap_count(s); |
333 | 370 | ||
334 | /* When the bitmap is more than 10% free, anyone can allocate. | 371 | /* |
372 | * When the bitmap is more than 10% free, anyone can allocate. | ||
335 | * When it's less than 10% free, only files that already use the | 373 | * When it's less than 10% free, only files that already use the |
336 | * bitmap are allowed. Once we pass 80% full, this restriction | 374 | * bitmap are allowed. Once we pass 80% full, this restriction |
337 | * is lifted. | 375 | * is lifted. |
@@ -369,7 +407,7 @@ static int scan_bitmap(struct reiserfs_transaction_handle *th, | |||
369 | nr_allocated = | 407 | nr_allocated = |
370 | scan_bitmap_block(th, bm, &off, end_off + 1, min, max, unfm); | 408 | scan_bitmap_block(th, bm, &off, end_off + 1, min, max, unfm); |
371 | 409 | ||
372 | ret: | 410 | ret: |
373 | *start = bm * off_max + off; | 411 | *start = bm * off_max + off; |
374 | return nr_allocated; | 412 | return nr_allocated; |
375 | 413 | ||
@@ -411,14 +449,14 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th, | |||
411 | "block %lu: bit already cleared", block); | 449 | "block %lu: bit already cleared", block); |
412 | } | 450 | } |
413 | apbi[nr].free_count++; | 451 | apbi[nr].free_count++; |
414 | journal_mark_dirty(th, s, bmbh); | 452 | journal_mark_dirty(th, bmbh); |
415 | brelse(bmbh); | 453 | brelse(bmbh); |
416 | 454 | ||
417 | reiserfs_prepare_for_journal(s, sbh, 1); | 455 | reiserfs_prepare_for_journal(s, sbh, 1); |
418 | /* update super block */ | 456 | /* update super block */ |
419 | set_sb_free_blocks(rs, sb_free_blocks(rs) + 1); | 457 | set_sb_free_blocks(rs, sb_free_blocks(rs) + 1); |
420 | 458 | ||
421 | journal_mark_dirty(th, s, sbh); | 459 | journal_mark_dirty(th, sbh); |
422 | if (for_unformatted) { | 460 | if (for_unformatted) { |
423 | int depth = reiserfs_write_unlock_nested(s); | 461 | int depth = reiserfs_write_unlock_nested(s); |
424 | dquot_free_block_nodirty(inode, 1); | 462 | dquot_free_block_nodirty(inode, 1); |
@@ -483,7 +521,7 @@ static void __discard_prealloc(struct reiserfs_transaction_handle *th, | |||
483 | if (dirty) | 521 | if (dirty) |
484 | reiserfs_update_sd(th, inode); | 522 | reiserfs_update_sd(th, inode); |
485 | ei->i_prealloc_block = save; | 523 | ei->i_prealloc_block = save; |
486 | list_del_init(&(ei->i_prealloc_list)); | 524 | list_del_init(&ei->i_prealloc_list); |
487 | } | 525 | } |
488 | 526 | ||
489 | /* FIXME: It should be inline function */ | 527 | /* FIXME: It should be inline function */ |
@@ -529,7 +567,8 @@ int reiserfs_parse_alloc_options(struct super_block *s, char *options) | |||
529 | { | 567 | { |
530 | char *this_char, *value; | 568 | char *this_char, *value; |
531 | 569 | ||
532 | REISERFS_SB(s)->s_alloc_options.bits = 0; /* clear default settings */ | 570 | /* clear default settings */ |
571 | REISERFS_SB(s)->s_alloc_options.bits = 0; | ||
533 | 572 | ||
534 | while ((this_char = strsep(&options, ":")) != NULL) { | 573 | while ((this_char = strsep(&options, ":")) != NULL) { |
535 | if ((value = strchr(this_char, '=')) != NULL) | 574 | if ((value = strchr(this_char, '=')) != NULL) |
@@ -731,7 +770,7 @@ static inline void new_hashed_relocation(reiserfs_blocknr_hint_t * hint) | |||
731 | hash_in = (char *)&hint->key.k_dir_id; | 770 | hash_in = (char *)&hint->key.k_dir_id; |
732 | } else { | 771 | } else { |
733 | if (!hint->inode) { | 772 | if (!hint->inode) { |
734 | //hint->search_start = hint->beg; | 773 | /*hint->search_start = hint->beg;*/ |
735 | hash_in = (char *)&hint->key.k_dir_id; | 774 | hash_in = (char *)&hint->key.k_dir_id; |
736 | } else | 775 | } else |
737 | if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) | 776 | if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) |
@@ -785,7 +824,8 @@ static void oid_groups(reiserfs_blocknr_hint_t * hint) | |||
785 | 824 | ||
786 | dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id); | 825 | dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id); |
787 | 826 | ||
788 | /* keep the root dir and it's first set of subdirs close to | 827 | /* |
828 | * keep the root dir and it's first set of subdirs close to | ||
789 | * the start of the disk | 829 | * the start of the disk |
790 | */ | 830 | */ |
791 | if (dirid <= 2) | 831 | if (dirid <= 2) |
@@ -799,7 +839,8 @@ static void oid_groups(reiserfs_blocknr_hint_t * hint) | |||
799 | } | 839 | } |
800 | } | 840 | } |
801 | 841 | ||
802 | /* returns 1 if it finds an indirect item and gets valid hint info | 842 | /* |
843 | * returns 1 if it finds an indirect item and gets valid hint info | ||
803 | * from it, otherwise 0 | 844 | * from it, otherwise 0 |
804 | */ | 845 | */ |
805 | static int get_left_neighbor(reiserfs_blocknr_hint_t * hint) | 846 | static int get_left_neighbor(reiserfs_blocknr_hint_t * hint) |
@@ -811,25 +852,29 @@ static int get_left_neighbor(reiserfs_blocknr_hint_t * hint) | |||
811 | __le32 *item; | 852 | __le32 *item; |
812 | int ret = 0; | 853 | int ret = 0; |
813 | 854 | ||
814 | if (!hint->path) /* reiserfs code can call this function w/o pointer to path | 855 | /* |
815 | * structure supplied; then we rely on supplied search_start */ | 856 | * reiserfs code can call this function w/o pointer to path |
857 | * structure supplied; then we rely on supplied search_start | ||
858 | */ | ||
859 | if (!hint->path) | ||
816 | return 0; | 860 | return 0; |
817 | 861 | ||
818 | path = hint->path; | 862 | path = hint->path; |
819 | bh = get_last_bh(path); | 863 | bh = get_last_bh(path); |
820 | RFALSE(!bh, "green-4002: Illegal path specified to get_left_neighbor"); | 864 | RFALSE(!bh, "green-4002: Illegal path specified to get_left_neighbor"); |
821 | ih = get_ih(path); | 865 | ih = tp_item_head(path); |
822 | pos_in_item = path->pos_in_item; | 866 | pos_in_item = path->pos_in_item; |
823 | item = get_item(path); | 867 | item = tp_item_body(path); |
824 | 868 | ||
825 | hint->search_start = bh->b_blocknr; | 869 | hint->search_start = bh->b_blocknr; |
826 | 870 | ||
871 | /* | ||
872 | * for indirect item: go to left and look for the first non-hole entry | ||
873 | * in the indirect item | ||
874 | */ | ||
827 | if (!hint->formatted_node && is_indirect_le_ih(ih)) { | 875 | if (!hint->formatted_node && is_indirect_le_ih(ih)) { |
828 | /* for indirect item: go to left and look for the first non-hole entry | ||
829 | in the indirect item */ | ||
830 | if (pos_in_item == I_UNFM_NUM(ih)) | 876 | if (pos_in_item == I_UNFM_NUM(ih)) |
831 | pos_in_item--; | 877 | pos_in_item--; |
832 | // pos_in_item = I_UNFM_NUM (ih) - 1; | ||
833 | while (pos_in_item >= 0) { | 878 | while (pos_in_item >= 0) { |
834 | int t = get_block_num(item, pos_in_item); | 879 | int t = get_block_num(item, pos_in_item); |
835 | if (t) { | 880 | if (t) { |
@@ -845,10 +890,12 @@ static int get_left_neighbor(reiserfs_blocknr_hint_t * hint) | |||
845 | return ret; | 890 | return ret; |
846 | } | 891 | } |
847 | 892 | ||
848 | /* should be, if formatted node, then try to put on first part of the device | 893 | /* |
849 | specified as number of percent with mount option device, else try to put | 894 | * should be, if formatted node, then try to put on first part of the device |
850 | on last of device. This is not to say it is good code to do so, | 895 | * specified as number of percent with mount option device, else try to put |
851 | but the effect should be measured. */ | 896 | * on last of device. This is not to say it is good code to do so, |
897 | * but the effect should be measured. | ||
898 | */ | ||
852 | static inline void set_border_in_hint(struct super_block *s, | 899 | static inline void set_border_in_hint(struct super_block *s, |
853 | reiserfs_blocknr_hint_t * hint) | 900 | reiserfs_blocknr_hint_t * hint) |
854 | { | 901 | { |
@@ -974,21 +1021,27 @@ static void determine_search_start(reiserfs_blocknr_hint_t * hint, | |||
974 | set_border_in_hint(s, hint); | 1021 | set_border_in_hint(s, hint); |
975 | 1022 | ||
976 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES | 1023 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES |
977 | /* whenever we create a new directory, we displace it. At first we will | 1024 | /* |
978 | hash for location, later we might look for a moderately empty place for | 1025 | * whenever we create a new directory, we displace it. At first |
979 | it */ | 1026 | * we will hash for location, later we might look for a moderately |
1027 | * empty place for it | ||
1028 | */ | ||
980 | if (displacing_new_packing_localities(s) | 1029 | if (displacing_new_packing_localities(s) |
981 | && hint->th->displace_new_blocks) { | 1030 | && hint->th->displace_new_blocks) { |
982 | displace_new_packing_locality(hint); | 1031 | displace_new_packing_locality(hint); |
983 | 1032 | ||
984 | /* we do not continue determine_search_start, | 1033 | /* |
985 | * if new packing locality is being displaced */ | 1034 | * we do not continue determine_search_start, |
1035 | * if new packing locality is being displaced | ||
1036 | */ | ||
986 | return; | 1037 | return; |
987 | } | 1038 | } |
988 | #endif | 1039 | #endif |
989 | 1040 | ||
990 | /* all persons should feel encouraged to add more special cases here and | 1041 | /* |
991 | * test them */ | 1042 | * all persons should feel encouraged to add more special cases |
1043 | * here and test them | ||
1044 | */ | ||
992 | 1045 | ||
993 | if (displacing_large_files(s) && !hint->formatted_node | 1046 | if (displacing_large_files(s) && !hint->formatted_node |
994 | && this_blocknr_allocation_would_make_it_a_large_file(hint)) { | 1047 | && this_blocknr_allocation_would_make_it_a_large_file(hint)) { |
@@ -996,8 +1049,10 @@ static void determine_search_start(reiserfs_blocknr_hint_t * hint, | |||
996 | return; | 1049 | return; |
997 | } | 1050 | } |
998 | 1051 | ||
999 | /* if none of our special cases is relevant, use the left neighbor in the | 1052 | /* |
1000 | tree order of the new node we are allocating for */ | 1053 | * if none of our special cases is relevant, use the left |
1054 | * neighbor in the tree order of the new node we are allocating for | ||
1055 | */ | ||
1001 | if (hint->formatted_node && TEST_OPTION(hashed_formatted_nodes, s)) { | 1056 | if (hint->formatted_node && TEST_OPTION(hashed_formatted_nodes, s)) { |
1002 | hash_formatted_node(hint); | 1057 | hash_formatted_node(hint); |
1003 | return; | 1058 | return; |
@@ -1005,10 +1060,13 @@ static void determine_search_start(reiserfs_blocknr_hint_t * hint, | |||
1005 | 1060 | ||
1006 | unfm_hint = get_left_neighbor(hint); | 1061 | unfm_hint = get_left_neighbor(hint); |
1007 | 1062 | ||
1008 | /* Mimic old block allocator behaviour, that is if VFS allowed for preallocation, | 1063 | /* |
1009 | new blocks are displaced based on directory ID. Also, if suggested search_start | 1064 | * Mimic old block allocator behaviour, that is if VFS allowed for |
1010 | is less than last preallocated block, we start searching from it, assuming that | 1065 | * preallocation, new blocks are displaced based on directory ID. |
1011 | HDD dataflow is faster in forward direction */ | 1066 | * Also, if suggested search_start is less than last preallocated |
1067 | * block, we start searching from it, assuming that HDD dataflow | ||
1068 | * is faster in forward direction | ||
1069 | */ | ||
1012 | if (TEST_OPTION(old_way, s)) { | 1070 | if (TEST_OPTION(old_way, s)) { |
1013 | if (!hint->formatted_node) { | 1071 | if (!hint->formatted_node) { |
1014 | if (!reiserfs_hashed_relocation(s)) | 1072 | if (!reiserfs_hashed_relocation(s)) |
@@ -1037,11 +1095,13 @@ static void determine_search_start(reiserfs_blocknr_hint_t * hint, | |||
1037 | TEST_OPTION(old_hashed_relocation, s)) { | 1095 | TEST_OPTION(old_hashed_relocation, s)) { |
1038 | old_hashed_relocation(hint); | 1096 | old_hashed_relocation(hint); |
1039 | } | 1097 | } |
1098 | |||
1040 | /* new_hashed_relocation works with both formatted/unformatted nodes */ | 1099 | /* new_hashed_relocation works with both formatted/unformatted nodes */ |
1041 | if ((!unfm_hint || hint->formatted_node) && | 1100 | if ((!unfm_hint || hint->formatted_node) && |
1042 | TEST_OPTION(new_hashed_relocation, s)) { | 1101 | TEST_OPTION(new_hashed_relocation, s)) { |
1043 | new_hashed_relocation(hint); | 1102 | new_hashed_relocation(hint); |
1044 | } | 1103 | } |
1104 | |||
1045 | /* dirid grouping works only on unformatted nodes */ | 1105 | /* dirid grouping works only on unformatted nodes */ |
1046 | if (!unfm_hint && !hint->formatted_node && TEST_OPTION(dirid_groups, s)) { | 1106 | if (!unfm_hint && !hint->formatted_node && TEST_OPTION(dirid_groups, s)) { |
1047 | dirid_groups(hint); | 1107 | dirid_groups(hint); |
@@ -1079,8 +1139,6 @@ static int determine_prealloc_size(reiserfs_blocknr_hint_t * hint) | |||
1079 | return CARRY_ON; | 1139 | return CARRY_ON; |
1080 | } | 1140 | } |
1081 | 1141 | ||
1082 | /* XXX I know it could be merged with upper-level function; | ||
1083 | but may be result function would be too complex. */ | ||
1084 | static inline int allocate_without_wrapping_disk(reiserfs_blocknr_hint_t * hint, | 1142 | static inline int allocate_without_wrapping_disk(reiserfs_blocknr_hint_t * hint, |
1085 | b_blocknr_t * new_blocknrs, | 1143 | b_blocknr_t * new_blocknrs, |
1086 | b_blocknr_t start, | 1144 | b_blocknr_t start, |
@@ -1108,7 +1166,10 @@ static inline int allocate_without_wrapping_disk(reiserfs_blocknr_hint_t * hint, | |||
1108 | 1166 | ||
1109 | /* do we have something to fill prealloc. array also ? */ | 1167 | /* do we have something to fill prealloc. array also ? */ |
1110 | if (nr_allocated > 0) { | 1168 | if (nr_allocated > 0) { |
1111 | /* it means prealloc_size was greater that 0 and we do preallocation */ | 1169 | /* |
1170 | * it means prealloc_size was greater that 0 and | ||
1171 | * we do preallocation | ||
1172 | */ | ||
1112 | list_add(&REISERFS_I(hint->inode)->i_prealloc_list, | 1173 | list_add(&REISERFS_I(hint->inode)->i_prealloc_list, |
1113 | &SB_JOURNAL(hint->th->t_super)-> | 1174 | &SB_JOURNAL(hint->th->t_super)-> |
1114 | j_prealloc_list); | 1175 | j_prealloc_list); |
@@ -1176,7 +1237,8 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start | |||
1176 | start = 0; | 1237 | start = 0; |
1177 | finish = hint->beg; | 1238 | finish = hint->beg; |
1178 | break; | 1239 | break; |
1179 | default: /* We've tried searching everywhere, not enough space */ | 1240 | default: |
1241 | /* We've tried searching everywhere, not enough space */ | ||
1180 | /* Free the blocks */ | 1242 | /* Free the blocks */ |
1181 | if (!hint->formatted_node) { | 1243 | if (!hint->formatted_node) { |
1182 | #ifdef REISERQUOTA_DEBUG | 1244 | #ifdef REISERQUOTA_DEBUG |
@@ -1261,8 +1323,11 @@ static int use_preallocated_list_if_available(reiserfs_blocknr_hint_t * hint, | |||
1261 | return amount_needed; | 1323 | return amount_needed; |
1262 | } | 1324 | } |
1263 | 1325 | ||
1264 | int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t * hint, b_blocknr_t * new_blocknrs, int amount_needed, int reserved_by_us /* Amount of blocks we have | 1326 | int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *hint, |
1265 | already reserved */ ) | 1327 | b_blocknr_t *new_blocknrs, |
1328 | int amount_needed, | ||
1329 | /* Amount of blocks we have already reserved */ | ||
1330 | int reserved_by_us) | ||
1266 | { | 1331 | { |
1267 | int initial_amount_needed = amount_needed; | 1332 | int initial_amount_needed = amount_needed; |
1268 | int ret; | 1333 | int ret; |
@@ -1274,15 +1339,21 @@ int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t * hint, b_blocknr_t * new | |||
1274 | return NO_DISK_SPACE; | 1339 | return NO_DISK_SPACE; |
1275 | /* should this be if !hint->inode && hint->preallocate? */ | 1340 | /* should this be if !hint->inode && hint->preallocate? */ |
1276 | /* do you mean hint->formatted_node can be removed ? - Zam */ | 1341 | /* do you mean hint->formatted_node can be removed ? - Zam */ |
1277 | /* hint->formatted_node cannot be removed because we try to access | 1342 | /* |
1278 | inode information here, and there is often no inode assotiated with | 1343 | * hint->formatted_node cannot be removed because we try to access |
1279 | metadata allocations - green */ | 1344 | * inode information here, and there is often no inode associated with |
1345 | * metadata allocations - green | ||
1346 | */ | ||
1280 | 1347 | ||
1281 | if (!hint->formatted_node && hint->preallocate) { | 1348 | if (!hint->formatted_node && hint->preallocate) { |
1282 | amount_needed = use_preallocated_list_if_available | 1349 | amount_needed = use_preallocated_list_if_available |
1283 | (hint, new_blocknrs, amount_needed); | 1350 | (hint, new_blocknrs, amount_needed); |
1284 | if (amount_needed == 0) /* all blocknrs we need we got from | 1351 | |
1285 | prealloc. list */ | 1352 | /* |
1353 | * We have all the block numbers we need from the | ||
1354 | * prealloc list | ||
1355 | */ | ||
1356 | if (amount_needed == 0) | ||
1286 | return CARRY_ON; | 1357 | return CARRY_ON; |
1287 | new_blocknrs += (initial_amount_needed - amount_needed); | 1358 | new_blocknrs += (initial_amount_needed - amount_needed); |
1288 | } | 1359 | } |
@@ -1296,10 +1367,12 @@ int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t * hint, b_blocknr_t * new | |||
1296 | ret = blocknrs_and_prealloc_arrays_from_search_start | 1367 | ret = blocknrs_and_prealloc_arrays_from_search_start |
1297 | (hint, new_blocknrs, amount_needed); | 1368 | (hint, new_blocknrs, amount_needed); |
1298 | 1369 | ||
1299 | /* we used prealloc. list to fill (partially) new_blocknrs array. If final allocation fails we | 1370 | /* |
1300 | * need to return blocks back to prealloc. list or just free them. -- Zam (I chose second | 1371 | * We used prealloc. list to fill (partially) new_blocknrs array. |
1301 | * variant) */ | 1372 | * If final allocation fails we need to return blocks back to |
1302 | 1373 | * prealloc. list or just free them. -- Zam (I chose second | |
1374 | * variant) | ||
1375 | */ | ||
1303 | if (ret != CARRY_ON) { | 1376 | if (ret != CARRY_ON) { |
1304 | while (amount_needed++ < initial_amount_needed) { | 1377 | while (amount_needed++ < initial_amount_needed) { |
1305 | reiserfs_free_block(hint->th, hint->inode, | 1378 | reiserfs_free_block(hint->th, hint->inode, |
@@ -1338,10 +1411,12 @@ struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, | |||
1338 | struct reiserfs_bitmap_info *info = SB_AP_BITMAP(sb) + bitmap; | 1411 | struct reiserfs_bitmap_info *info = SB_AP_BITMAP(sb) + bitmap; |
1339 | struct buffer_head *bh; | 1412 | struct buffer_head *bh; |
1340 | 1413 | ||
1341 | /* Way old format filesystems had the bitmaps packed up front. | 1414 | /* |
1342 | * I doubt there are any of these left, but just in case... */ | 1415 | * Way old format filesystems had the bitmaps packed up front. |
1416 | * I doubt there are any of these left, but just in case... | ||
1417 | */ | ||
1343 | if (unlikely(test_bit(REISERFS_OLD_FORMAT, | 1418 | if (unlikely(test_bit(REISERFS_OLD_FORMAT, |
1344 | &(REISERFS_SB(sb)->s_properties)))) | 1419 | &REISERFS_SB(sb)->s_properties))) |
1345 | block = REISERFS_SB(sb)->s_sbh->b_blocknr + 1 + bitmap; | 1420 | block = REISERFS_SB(sb)->s_sbh->b_blocknr + 1 + bitmap; |
1346 | else if (bitmap == 0) | 1421 | else if (bitmap == 0) |
1347 | block = (REISERFS_DISK_OFFSET_IN_BYTES >> sb->s_blocksize_bits) + 1; | 1422 | block = (REISERFS_DISK_OFFSET_IN_BYTES >> sb->s_blocksize_bits) + 1; |