diff options
Diffstat (limited to 'fs/reiserfs/bitmap.c')
| -rw-r--r-- | fs/reiserfs/bitmap.c | 1842 |
1 files changed, 969 insertions, 873 deletions
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c index 49c479c9454a..909f71e9a30f 100644 --- a/fs/reiserfs/bitmap.c +++ b/fs/reiserfs/bitmap.c | |||
| @@ -46,1125 +46,1221 @@ | |||
| 46 | #define TEST_OPTION(optname, s) \ | 46 | #define TEST_OPTION(optname, s) \ |
| 47 | test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)) | 47 | test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)) |
| 48 | 48 | ||
| 49 | static inline void get_bit_address (struct super_block * s, | 49 | static inline void get_bit_address(struct super_block *s, |
| 50 | b_blocknr_t block, int * bmap_nr, int * offset) | 50 | b_blocknr_t block, int *bmap_nr, int *offset) |
| 51 | { | 51 | { |
| 52 | /* It is in the bitmap block number equal to the block | 52 | /* It is in the bitmap block number equal to the block |
| 53 | * number divided by the number of bits in a block. */ | 53 | * number divided by the number of bits in a block. */ |
| 54 | *bmap_nr = block / (s->s_blocksize << 3); | 54 | *bmap_nr = block / (s->s_blocksize << 3); |
| 55 | /* Within that bitmap block it is located at bit offset *offset. */ | 55 | /* Within that bitmap block it is located at bit offset *offset. */ |
| 56 | *offset = block & ((s->s_blocksize << 3) - 1 ); | 56 | *offset = block & ((s->s_blocksize << 3) - 1); |
| 57 | return; | 57 | return; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | #ifdef CONFIG_REISERFS_CHECK | 60 | #ifdef CONFIG_REISERFS_CHECK |
| 61 | int is_reusable (struct super_block * s, b_blocknr_t block, int bit_value) | 61 | int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) |
| 62 | { | 62 | { |
| 63 | int i, j; | 63 | int i, j; |
| 64 | 64 | ||
| 65 | if (block == 0 || block >= SB_BLOCK_COUNT (s)) { | 65 | if (block == 0 || block >= SB_BLOCK_COUNT(s)) { |
| 66 | reiserfs_warning (s, "vs-4010: is_reusable: block number is out of range %lu (%u)", | 66 | reiserfs_warning(s, |
| 67 | block, SB_BLOCK_COUNT (s)); | 67 | "vs-4010: is_reusable: block number is out of range %lu (%u)", |
| 68 | return 0; | 68 | block, SB_BLOCK_COUNT(s)); |
| 69 | } | 69 | return 0; |
| 70 | |||
| 71 | /* it can't be one of the bitmap blocks */ | ||
| 72 | for (i = 0; i < SB_BMAP_NR (s); i ++) | ||
| 73 | if (block == SB_AP_BITMAP (s)[i].bh->b_blocknr) { | ||
| 74 | reiserfs_warning (s, "vs: 4020: is_reusable: " | ||
| 75 | "bitmap block %lu(%u) can't be freed or reused", | ||
| 76 | block, SB_BMAP_NR (s)); | ||
| 77 | return 0; | ||
| 78 | } | 70 | } |
| 79 | |||
| 80 | get_bit_address (s, block, &i, &j); | ||
| 81 | 71 | ||
| 82 | if (i >= SB_BMAP_NR (s)) { | 72 | /* it can't be one of the bitmap blocks */ |
| 83 | reiserfs_warning (s, "vs-4030: is_reusable: there is no so many bitmap blocks: " | 73 | for (i = 0; i < SB_BMAP_NR(s); i++) |
| 84 | "block=%lu, bitmap_nr=%d", block, i); | 74 | if (block == SB_AP_BITMAP(s)[i].bh->b_blocknr) { |
| 85 | return 0; | 75 | reiserfs_warning(s, "vs: 4020: is_reusable: " |
| 86 | } | 76 | "bitmap block %lu(%u) can't be freed or reused", |
| 77 | block, SB_BMAP_NR(s)); | ||
| 78 | return 0; | ||
| 79 | } | ||
| 87 | 80 | ||
| 88 | if ((bit_value == 0 && | 81 | get_bit_address(s, block, &i, &j); |
| 89 | reiserfs_test_le_bit(j, SB_AP_BITMAP(s)[i].bh->b_data)) || | ||
| 90 | (bit_value == 1 && | ||
| 91 | reiserfs_test_le_bit(j, SB_AP_BITMAP (s)[i].bh->b_data) == 0)) { | ||
| 92 | reiserfs_warning (s, "vs-4040: is_reusable: corresponding bit of block %lu does not " | ||
| 93 | "match required value (i==%d, j==%d) test_bit==%d", | ||
| 94 | block, i, j, reiserfs_test_le_bit (j, SB_AP_BITMAP (s)[i].bh->b_data)); | ||
| 95 | 82 | ||
| 96 | return 0; | 83 | if (i >= SB_BMAP_NR(s)) { |
| 97 | } | 84 | reiserfs_warning(s, |
| 85 | "vs-4030: is_reusable: there is no so many bitmap blocks: " | ||
| 86 | "block=%lu, bitmap_nr=%d", block, i); | ||
| 87 | return 0; | ||
| 88 | } | ||
| 98 | 89 | ||
| 99 | if (bit_value == 0 && block == SB_ROOT_BLOCK (s)) { | 90 | if ((bit_value == 0 && |
| 100 | reiserfs_warning (s, "vs-4050: is_reusable: this is root block (%u), " | 91 | reiserfs_test_le_bit(j, SB_AP_BITMAP(s)[i].bh->b_data)) || |
| 101 | "it must be busy", SB_ROOT_BLOCK (s)); | 92 | (bit_value == 1 && |
| 102 | return 0; | 93 | reiserfs_test_le_bit(j, SB_AP_BITMAP(s)[i].bh->b_data) == 0)) { |
| 103 | } | 94 | reiserfs_warning(s, |
| 95 | "vs-4040: is_reusable: corresponding bit of block %lu does not " | ||
| 96 | "match required value (i==%d, j==%d) test_bit==%d", | ||
| 97 | block, i, j, reiserfs_test_le_bit(j, | ||
| 98 | SB_AP_BITMAP | ||
| 99 | (s)[i].bh-> | ||
| 100 | b_data)); | ||
| 101 | |||
| 102 | return 0; | ||
| 103 | } | ||
| 104 | 104 | ||
| 105 | return 1; | 105 | if (bit_value == 0 && block == SB_ROOT_BLOCK(s)) { |
| 106 | reiserfs_warning(s, | ||
| 107 | "vs-4050: is_reusable: this is root block (%u), " | ||
| 108 | "it must be busy", SB_ROOT_BLOCK(s)); | ||
| 109 | return 0; | ||
| 110 | } | ||
| 111 | |||
| 112 | return 1; | ||
| 106 | } | 113 | } |
| 107 | #endif /* CONFIG_REISERFS_CHECK */ | 114 | #endif /* CONFIG_REISERFS_CHECK */ |
| 108 | 115 | ||
| 109 | /* searches in journal structures for a given block number (bmap, off). If block | 116 | /* searches in journal structures for a given block number (bmap, off). If block |
| 110 | is found in reiserfs journal it suggests next free block candidate to test. */ | 117 | is found in reiserfs journal it suggests next free block candidate to test. */ |
| 111 | static inline int is_block_in_journal (struct super_block * s, int bmap, int | 118 | static inline int is_block_in_journal(struct super_block *s, int bmap, int |
| 112 | off, int *next) | 119 | off, int *next) |
| 113 | { | 120 | { |
| 114 | b_blocknr_t tmp; | 121 | b_blocknr_t tmp; |
| 115 | 122 | ||
| 116 | if (reiserfs_in_journal (s, bmap, off, 1, &tmp)) { | 123 | if (reiserfs_in_journal(s, bmap, off, 1, &tmp)) { |
| 117 | if (tmp) { /* hint supplied */ | 124 | if (tmp) { /* hint supplied */ |
| 118 | *next = tmp; | 125 | *next = tmp; |
| 119 | PROC_INFO_INC( s, scan_bitmap.in_journal_hint ); | 126 | PROC_INFO_INC(s, scan_bitmap.in_journal_hint); |
| 120 | } else { | 127 | } else { |
| 121 | (*next) = off + 1; /* inc offset to avoid looping. */ | 128 | (*next) = off + 1; /* inc offset to avoid looping. */ |
| 122 | PROC_INFO_INC( s, scan_bitmap.in_journal_nohint ); | 129 | PROC_INFO_INC(s, scan_bitmap.in_journal_nohint); |
| 130 | } | ||
| 131 | PROC_INFO_INC(s, scan_bitmap.retry); | ||
| 132 | return 1; | ||
| 123 | } | 133 | } |
| 124 | PROC_INFO_INC( s, scan_bitmap.retry ); | 134 | return 0; |
| 125 | return 1; | ||
| 126 | } | ||
| 127 | return 0; | ||
| 128 | } | 135 | } |
| 129 | 136 | ||
| 130 | /* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap | 137 | /* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap |
| 131 | * block; */ | 138 | * block; */ |
| 132 | static int scan_bitmap_block (struct reiserfs_transaction_handle *th, | 139 | static int scan_bitmap_block(struct reiserfs_transaction_handle *th, |
| 133 | int bmap_n, int *beg, int boundary, int min, int max, int unfm) | 140 | int bmap_n, int *beg, int boundary, int min, |
| 141 | int max, int unfm) | ||
| 134 | { | 142 | { |
| 135 | struct super_block *s = th->t_super; | 143 | struct super_block *s = th->t_super; |
| 136 | struct reiserfs_bitmap_info *bi=&SB_AP_BITMAP(s)[bmap_n]; | 144 | struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n]; |
| 137 | int end, next; | 145 | int end, next; |
| 138 | int org = *beg; | 146 | int org = *beg; |
| 139 | 147 | ||
| 140 | BUG_ON (!th->t_trans_id); | 148 | BUG_ON(!th->t_trans_id); |
| 141 | 149 | ||
| 142 | RFALSE(bmap_n >= SB_BMAP_NR (s), "Bitmap %d is out of range (0..%d)",bmap_n, SB_BMAP_NR (s) - 1); | 150 | RFALSE(bmap_n >= SB_BMAP_NR(s), "Bitmap %d is out of range (0..%d)", |
| 143 | PROC_INFO_INC( s, scan_bitmap.bmap ); | 151 | bmap_n, SB_BMAP_NR(s) - 1); |
| 152 | PROC_INFO_INC(s, scan_bitmap.bmap); | ||
| 144 | /* this is unclear and lacks comments, explain how journal bitmaps | 153 | /* this is unclear and lacks comments, explain how journal bitmaps |
| 145 | work here for the reader. Convey a sense of the design here. What | 154 | work here for the reader. Convey a sense of the design here. What |
| 146 | is a window? */ | 155 | is a window? */ |
| 147 | /* - I mean `a window of zero bits' as in description of this function - Zam. */ | 156 | /* - I mean `a window of zero bits' as in description of this function - Zam. */ |
| 148 | |||
| 149 | if ( !bi ) { | ||
| 150 | reiserfs_warning (s, "NULL bitmap info pointer for bitmap %d", bmap_n); | ||
| 151 | return 0; | ||
| 152 | } | ||
| 153 | if (buffer_locked (bi->bh)) { | ||
| 154 | PROC_INFO_INC( s, scan_bitmap.wait ); | ||
| 155 | __wait_on_buffer (bi->bh); | ||
| 156 | } | ||
| 157 | |||
| 158 | while (1) { | ||
| 159 | cont: | ||
| 160 | if (bi->free_count < min) | ||
| 161 | return 0; // No free blocks in this bitmap | ||
| 162 | |||
| 163 | /* search for a first zero bit -- beggining of a window */ | ||
| 164 | *beg = reiserfs_find_next_zero_le_bit | ||
| 165 | ((unsigned long*)(bi->bh->b_data), boundary, *beg); | ||
| 166 | |||
| 167 | if (*beg + min > boundary) { /* search for a zero bit fails or the rest of bitmap block | ||
| 168 | * cannot contain a zero window of minimum size */ | ||
| 169 | return 0; | ||
| 170 | } | ||
| 171 | 157 | ||
| 172 | if (unfm && is_block_in_journal(s,bmap_n, *beg, beg)) | 158 | if (!bi) { |
| 173 | continue; | 159 | reiserfs_warning(s, "NULL bitmap info pointer for bitmap %d", |
| 174 | /* first zero bit found; we check next bits */ | 160 | bmap_n); |
| 175 | for (end = *beg + 1;; end ++) { | 161 | return 0; |
| 176 | if (end >= *beg + max || end >= boundary || reiserfs_test_le_bit (end, bi->bh->b_data)) { | 162 | } |
| 177 | next = end; | 163 | if (buffer_locked(bi->bh)) { |
| 178 | break; | 164 | PROC_INFO_INC(s, scan_bitmap.wait); |
| 179 | } | 165 | __wait_on_buffer(bi->bh); |
| 180 | /* finding the other end of zero bit window requires looking into journal structures (in | ||
| 181 | * case of searching for free blocks for unformatted nodes) */ | ||
| 182 | if (unfm && is_block_in_journal(s, bmap_n, end, &next)) | ||
| 183 | break; | ||
| 184 | } | 166 | } |
| 185 | 167 | ||
| 186 | /* now (*beg) points to beginning of zero bits window, | 168 | while (1) { |
| 187 | * (end) points to one bit after the window end */ | 169 | cont: |
| 188 | if (end - *beg >= min) { /* it seems we have found window of proper size */ | 170 | if (bi->free_count < min) |
| 189 | int i; | 171 | return 0; // No free blocks in this bitmap |
| 190 | reiserfs_prepare_for_journal (s, bi->bh, 1); | 172 | |
| 191 | /* try to set all blocks used checking are they still free */ | 173 | /* search for a first zero bit -- beggining of a window */ |
| 192 | for (i = *beg; i < end; i++) { | 174 | *beg = reiserfs_find_next_zero_le_bit |
| 193 | /* It seems that we should not check in journal again. */ | 175 | ((unsigned long *)(bi->bh->b_data), boundary, *beg); |
| 194 | if (reiserfs_test_and_set_le_bit (i, bi->bh->b_data)) { | 176 | |
| 195 | /* bit was set by another process | 177 | if (*beg + min > boundary) { /* search for a zero bit fails or the rest of bitmap block |
| 196 | * while we slept in prepare_for_journal() */ | 178 | * cannot contain a zero window of minimum size */ |
| 197 | PROC_INFO_INC( s, scan_bitmap.stolen ); | 179 | return 0; |
| 198 | if (i >= *beg + min) { /* we can continue with smaller set of allocated blocks, | ||
| 199 | * if length of this set is more or equal to `min' */ | ||
| 200 | end = i; | ||
| 201 | break; | ||
| 202 | } | ||
| 203 | /* otherwise we clear all bit were set ... */ | ||
| 204 | while (--i >= *beg) | ||
| 205 | reiserfs_test_and_clear_le_bit (i, bi->bh->b_data); | ||
| 206 | reiserfs_restore_prepared_buffer (s, bi->bh); | ||
| 207 | *beg = org; | ||
| 208 | /* ... and search again in current block from beginning */ | ||
| 209 | goto cont; | ||
| 210 | } | 180 | } |
| 211 | } | ||
| 212 | bi->free_count -= (end - *beg); | ||
| 213 | journal_mark_dirty (th, s, bi->bh); | ||
| 214 | 181 | ||
| 215 | /* free block count calculation */ | 182 | if (unfm && is_block_in_journal(s, bmap_n, *beg, beg)) |
| 216 | reiserfs_prepare_for_journal (s, SB_BUFFER_WITH_SB(s), 1); | 183 | continue; |
| 217 | PUT_SB_FREE_BLOCKS(s, SB_FREE_BLOCKS(s) - (end - *beg)); | 184 | /* first zero bit found; we check next bits */ |
| 218 | journal_mark_dirty (th, s, SB_BUFFER_WITH_SB(s)); | 185 | for (end = *beg + 1;; end++) { |
| 186 | if (end >= *beg + max || end >= boundary | ||
| 187 | || reiserfs_test_le_bit(end, bi->bh->b_data)) { | ||
| 188 | next = end; | ||
| 189 | break; | ||
| 190 | } | ||
| 191 | /* finding the other end of zero bit window requires looking into journal structures (in | ||
| 192 | * case of searching for free blocks for unformatted nodes) */ | ||
| 193 | if (unfm && is_block_in_journal(s, bmap_n, end, &next)) | ||
| 194 | break; | ||
| 195 | } | ||
| 219 | 196 | ||
| 220 | return end - (*beg); | 197 | /* now (*beg) points to beginning of zero bits window, |
| 221 | } else { | 198 | * (end) points to one bit after the window end */ |
| 222 | *beg = next; | 199 | if (end - *beg >= min) { /* it seems we have found window of proper size */ |
| 200 | int i; | ||
| 201 | reiserfs_prepare_for_journal(s, bi->bh, 1); | ||
| 202 | /* try to set all blocks used checking are they still free */ | ||
| 203 | for (i = *beg; i < end; i++) { | ||
| 204 | /* It seems that we should not check in journal again. */ | ||
| 205 | if (reiserfs_test_and_set_le_bit | ||
| 206 | (i, bi->bh->b_data)) { | ||
| 207 | /* bit was set by another process | ||
| 208 | * while we slept in prepare_for_journal() */ | ||
| 209 | PROC_INFO_INC(s, scan_bitmap.stolen); | ||
| 210 | if (i >= *beg + min) { /* we can continue with smaller set of allocated blocks, | ||
| 211 | * if length of this set is more or equal to `min' */ | ||
| 212 | end = i; | ||
| 213 | break; | ||
| 214 | } | ||
| 215 | /* otherwise we clear all bit were set ... */ | ||
| 216 | while (--i >= *beg) | ||
| 217 | reiserfs_test_and_clear_le_bit | ||
| 218 | (i, bi->bh->b_data); | ||
| 219 | reiserfs_restore_prepared_buffer(s, | ||
| 220 | bi-> | ||
| 221 | bh); | ||
| 222 | *beg = org; | ||
| 223 | /* ... and search again in current block from beginning */ | ||
| 224 | goto cont; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | bi->free_count -= (end - *beg); | ||
| 228 | journal_mark_dirty(th, s, bi->bh); | ||
| 229 | |||
| 230 | /* free block count calculation */ | ||
| 231 | reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), | ||
| 232 | 1); | ||
| 233 | PUT_SB_FREE_BLOCKS(s, SB_FREE_BLOCKS(s) - (end - *beg)); | ||
| 234 | journal_mark_dirty(th, s, SB_BUFFER_WITH_SB(s)); | ||
| 235 | |||
| 236 | return end - (*beg); | ||
| 237 | } else { | ||
| 238 | *beg = next; | ||
| 239 | } | ||
| 223 | } | 240 | } |
| 224 | } | ||
| 225 | } | 241 | } |
| 226 | 242 | ||
| 227 | static int bmap_hash_id(struct super_block *s, u32 id) { | 243 | static int bmap_hash_id(struct super_block *s, u32 id) |
| 228 | char * hash_in = NULL; | 244 | { |
| 229 | unsigned long hash; | 245 | char *hash_in = NULL; |
| 230 | unsigned bm; | 246 | unsigned long hash; |
| 231 | 247 | unsigned bm; | |
| 232 | if (id <= 2) { | 248 | |
| 233 | bm = 1; | 249 | if (id <= 2) { |
| 234 | } else { | 250 | bm = 1; |
| 235 | hash_in = (char *)(&id); | 251 | } else { |
| 236 | hash = keyed_hash(hash_in, 4); | 252 | hash_in = (char *)(&id); |
| 237 | bm = hash % SB_BMAP_NR(s); | 253 | hash = keyed_hash(hash_in, 4); |
| 238 | if (!bm) | 254 | bm = hash % SB_BMAP_NR(s); |
| 239 | bm = 1; | 255 | if (!bm) |
| 240 | } | 256 | bm = 1; |
| 241 | /* this can only be true when SB_BMAP_NR = 1 */ | 257 | } |
| 242 | if (bm >= SB_BMAP_NR(s)) | 258 | /* this can only be true when SB_BMAP_NR = 1 */ |
| 243 | bm = 0; | 259 | if (bm >= SB_BMAP_NR(s)) |
| 244 | return bm; | 260 | bm = 0; |
| 261 | return bm; | ||
| 245 | } | 262 | } |
| 246 | 263 | ||
| 247 | /* | 264 | /* |
| 248 | * hashes the id and then returns > 0 if the block group for the | 265 | * hashes the id and then returns > 0 if the block group for the |
| 249 | * corresponding hash is full | 266 | * corresponding hash is full |
| 250 | */ | 267 | */ |
| 251 | static inline int block_group_used(struct super_block *s, u32 id) { | 268 | static inline int block_group_used(struct super_block *s, u32 id) |
| 252 | int bm; | 269 | { |
| 253 | bm = bmap_hash_id(s, id); | 270 | int bm; |
| 254 | if (SB_AP_BITMAP(s)[bm].free_count > ((s->s_blocksize << 3) * 60 / 100) ) { | 271 | bm = bmap_hash_id(s, id); |
| 255 | return 0; | 272 | if (SB_AP_BITMAP(s)[bm].free_count > ((s->s_blocksize << 3) * 60 / 100)) { |
| 256 | } | 273 | return 0; |
| 257 | return 1; | 274 | } |
| 275 | return 1; | ||
| 258 | } | 276 | } |
| 259 | 277 | ||
| 260 | /* | 278 | /* |
| 261 | * the packing is returned in disk byte order | 279 | * the packing is returned in disk byte order |
| 262 | */ | 280 | */ |
| 263 | __le32 reiserfs_choose_packing(struct inode *dir) | 281 | __le32 reiserfs_choose_packing(struct inode * dir) |
| 264 | { | 282 | { |
| 265 | __le32 packing; | 283 | __le32 packing; |
| 266 | if (TEST_OPTION(packing_groups, dir->i_sb)) { | 284 | if (TEST_OPTION(packing_groups, dir->i_sb)) { |
| 267 | u32 parent_dir = le32_to_cpu(INODE_PKEY(dir)->k_dir_id); | 285 | u32 parent_dir = le32_to_cpu(INODE_PKEY(dir)->k_dir_id); |
| 268 | /* | 286 | /* |
| 269 | * some versions of reiserfsck expect packing locality 1 to be | 287 | * some versions of reiserfsck expect packing locality 1 to be |
| 270 | * special | 288 | * special |
| 271 | */ | 289 | */ |
| 272 | if (parent_dir == 1 || block_group_used(dir->i_sb,parent_dir)) | 290 | if (parent_dir == 1 || block_group_used(dir->i_sb, parent_dir)) |
| 273 | packing = INODE_PKEY(dir)->k_objectid; | 291 | packing = INODE_PKEY(dir)->k_objectid; |
| 274 | else | 292 | else |
| 275 | packing = INODE_PKEY(dir)->k_dir_id; | 293 | packing = INODE_PKEY(dir)->k_dir_id; |
| 276 | } else | 294 | } else |
| 277 | packing = INODE_PKEY(dir)->k_objectid; | 295 | packing = INODE_PKEY(dir)->k_objectid; |
| 278 | return packing; | 296 | return packing; |
| 279 | } | 297 | } |
| 280 | 298 | ||
| 281 | /* Tries to find contiguous zero bit window (given size) in given region of | 299 | /* Tries to find contiguous zero bit window (given size) in given region of |
| 282 | * bitmap and place new blocks there. Returns number of allocated blocks. */ | 300 | * bitmap and place new blocks there. Returns number of allocated blocks. */ |
| 283 | static int scan_bitmap (struct reiserfs_transaction_handle *th, | 301 | static int scan_bitmap(struct reiserfs_transaction_handle *th, |
| 284 | b_blocknr_t *start, b_blocknr_t finish, | 302 | b_blocknr_t * start, b_blocknr_t finish, |
| 285 | int min, int max, int unfm, unsigned long file_block) | 303 | int min, int max, int unfm, unsigned long file_block) |
| 286 | { | 304 | { |
| 287 | int nr_allocated=0; | 305 | int nr_allocated = 0; |
| 288 | struct super_block * s = th->t_super; | 306 | struct super_block *s = th->t_super; |
| 289 | /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr | 307 | /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr |
| 290 | * - Hans, it is not a block number - Zam. */ | 308 | * - Hans, it is not a block number - Zam. */ |
| 291 | 309 | ||
| 292 | int bm, off; | 310 | int bm, off; |
| 293 | int end_bm, end_off; | 311 | int end_bm, end_off; |
| 294 | int off_max = s->s_blocksize << 3; | 312 | int off_max = s->s_blocksize << 3; |
| 295 | 313 | ||
| 296 | BUG_ON (!th->t_trans_id); | 314 | BUG_ON(!th->t_trans_id); |
| 297 | 315 | ||
| 298 | PROC_INFO_INC( s, scan_bitmap.call ); | 316 | PROC_INFO_INC(s, scan_bitmap.call); |
| 299 | if ( SB_FREE_BLOCKS(s) <= 0) | 317 | if (SB_FREE_BLOCKS(s) <= 0) |
| 300 | return 0; // No point in looking for more free blocks | 318 | return 0; // No point in looking for more free blocks |
| 301 | 319 | ||
| 302 | get_bit_address (s, *start, &bm, &off); | 320 | get_bit_address(s, *start, &bm, &off); |
| 303 | get_bit_address (s, finish, &end_bm, &end_off); | 321 | get_bit_address(s, finish, &end_bm, &end_off); |
| 304 | if (bm > SB_BMAP_NR(s)) | 322 | if (bm > SB_BMAP_NR(s)) |
| 305 | return 0; | 323 | return 0; |
| 306 | if (end_bm > SB_BMAP_NR(s)) | 324 | if (end_bm > SB_BMAP_NR(s)) |
| 307 | end_bm = SB_BMAP_NR(s); | 325 | end_bm = SB_BMAP_NR(s); |
| 308 | 326 | ||
| 309 | /* When the bitmap is more than 10% free, anyone can allocate. | 327 | /* When the bitmap is more than 10% free, anyone can allocate. |
| 310 | * When it's less than 10% free, only files that already use the | 328 | * When it's less than 10% free, only files that already use the |
| 311 | * bitmap are allowed. Once we pass 80% full, this restriction | 329 | * bitmap are allowed. Once we pass 80% full, this restriction |
| 312 | * is lifted. | 330 | * is lifted. |
| 313 | * | 331 | * |
| 314 | * We do this so that files that grow later still have space close to | 332 | * We do this so that files that grow later still have space close to |
| 315 | * their original allocation. This improves locality, and presumably | 333 | * their original allocation. This improves locality, and presumably |
| 316 | * performance as a result. | 334 | * performance as a result. |
| 317 | * | 335 | * |
| 318 | * This is only an allocation policy and does not make up for getting a | 336 | * This is only an allocation policy and does not make up for getting a |
| 319 | * bad hint. Decent hinting must be implemented for this to work well. | 337 | * bad hint. Decent hinting must be implemented for this to work well. |
| 320 | */ | 338 | */ |
| 321 | if ( TEST_OPTION(skip_busy, s) && SB_FREE_BLOCKS(s) > SB_BLOCK_COUNT(s)/20 ) { | 339 | if (TEST_OPTION(skip_busy, s) |
| 322 | for (;bm < end_bm; bm++, off = 0) { | 340 | && SB_FREE_BLOCKS(s) > SB_BLOCK_COUNT(s) / 20) { |
| 323 | if ( ( off && (!unfm || (file_block != 0))) || SB_AP_BITMAP(s)[bm].free_count > (s->s_blocksize << 3) / 10 ) | 341 | for (; bm < end_bm; bm++, off = 0) { |
| 324 | nr_allocated = scan_bitmap_block(th, bm, &off, off_max, min, max, unfm); | 342 | if ((off && (!unfm || (file_block != 0))) |
| 325 | if (nr_allocated) | 343 | || SB_AP_BITMAP(s)[bm].free_count > |
| 326 | goto ret; | 344 | (s->s_blocksize << 3) / 10) |
| 327 | } | 345 | nr_allocated = |
| 328 | /* we know from above that start is a reasonable number */ | 346 | scan_bitmap_block(th, bm, &off, off_max, |
| 329 | get_bit_address (s, *start, &bm, &off); | 347 | min, max, unfm); |
| 330 | } | 348 | if (nr_allocated) |
| 331 | 349 | goto ret; | |
| 332 | for (;bm < end_bm; bm++, off = 0) { | 350 | } |
| 333 | nr_allocated = scan_bitmap_block(th, bm, &off, off_max, min, max, unfm); | 351 | /* we know from above that start is a reasonable number */ |
| 334 | if (nr_allocated) | 352 | get_bit_address(s, *start, &bm, &off); |
| 335 | goto ret; | 353 | } |
| 336 | } | 354 | |
| 337 | 355 | for (; bm < end_bm; bm++, off = 0) { | |
| 338 | nr_allocated = scan_bitmap_block(th, bm, &off, end_off + 1, min, max, unfm); | 356 | nr_allocated = |
| 339 | 357 | scan_bitmap_block(th, bm, &off, off_max, min, max, unfm); | |
| 340 | ret: | 358 | if (nr_allocated) |
| 341 | *start = bm * off_max + off; | 359 | goto ret; |
| 342 | return nr_allocated; | 360 | } |
| 361 | |||
| 362 | nr_allocated = | ||
| 363 | scan_bitmap_block(th, bm, &off, end_off + 1, min, max, unfm); | ||
| 364 | |||
| 365 | ret: | ||
| 366 | *start = bm * off_max + off; | ||
| 367 | return nr_allocated; | ||
| 343 | 368 | ||
| 344 | } | 369 | } |
| 345 | 370 | ||
| 346 | static void _reiserfs_free_block (struct reiserfs_transaction_handle *th, | 371 | static void _reiserfs_free_block(struct reiserfs_transaction_handle *th, |
| 347 | struct inode *inode, b_blocknr_t block, | 372 | struct inode *inode, b_blocknr_t block, |
| 348 | int for_unformatted) | 373 | int for_unformatted) |
| 349 | { | 374 | { |
| 350 | struct super_block * s = th->t_super; | 375 | struct super_block *s = th->t_super; |
| 351 | struct reiserfs_super_block * rs; | 376 | struct reiserfs_super_block *rs; |
| 352 | struct buffer_head * sbh; | 377 | struct buffer_head *sbh; |
| 353 | struct reiserfs_bitmap_info *apbi; | 378 | struct reiserfs_bitmap_info *apbi; |
| 354 | int nr, offset; | 379 | int nr, offset; |
| 355 | 380 | ||
| 356 | BUG_ON (!th->t_trans_id); | 381 | BUG_ON(!th->t_trans_id); |
| 357 | 382 | ||
| 358 | PROC_INFO_INC( s, free_block ); | 383 | PROC_INFO_INC(s, free_block); |
| 359 | 384 | ||
| 360 | rs = SB_DISK_SUPER_BLOCK (s); | 385 | rs = SB_DISK_SUPER_BLOCK(s); |
| 361 | sbh = SB_BUFFER_WITH_SB (s); | 386 | sbh = SB_BUFFER_WITH_SB(s); |
| 362 | apbi = SB_AP_BITMAP(s); | 387 | apbi = SB_AP_BITMAP(s); |
| 363 | 388 | ||
| 364 | get_bit_address (s, block, &nr, &offset); | 389 | get_bit_address(s, block, &nr, &offset); |
| 365 | 390 | ||
| 366 | if (nr >= sb_bmap_nr (rs)) { | 391 | if (nr >= sb_bmap_nr(rs)) { |
| 367 | reiserfs_warning (s, "vs-4075: reiserfs_free_block: " | 392 | reiserfs_warning(s, "vs-4075: reiserfs_free_block: " |
| 368 | "block %lu is out of range on %s", | 393 | "block %lu is out of range on %s", |
| 369 | block, reiserfs_bdevname (s)); | 394 | block, reiserfs_bdevname(s)); |
| 370 | return; | 395 | return; |
| 371 | } | 396 | } |
| 372 | 397 | ||
| 373 | reiserfs_prepare_for_journal(s, apbi[nr].bh, 1 ) ; | 398 | reiserfs_prepare_for_journal(s, apbi[nr].bh, 1); |
| 374 | 399 | ||
| 375 | /* clear bit for the given block in bit map */ | 400 | /* clear bit for the given block in bit map */ |
| 376 | if (!reiserfs_test_and_clear_le_bit (offset, apbi[nr].bh->b_data)) { | 401 | if (!reiserfs_test_and_clear_le_bit(offset, apbi[nr].bh->b_data)) { |
| 377 | reiserfs_warning (s, "vs-4080: reiserfs_free_block: " | 402 | reiserfs_warning(s, "vs-4080: reiserfs_free_block: " |
| 378 | "free_block (%s:%lu)[dev:blocknr]: bit already cleared", | 403 | "free_block (%s:%lu)[dev:blocknr]: bit already cleared", |
| 379 | reiserfs_bdevname (s), block); | 404 | reiserfs_bdevname(s), block); |
| 380 | } | 405 | } |
| 381 | apbi[nr].free_count ++; | 406 | apbi[nr].free_count++; |
| 382 | journal_mark_dirty (th, s, apbi[nr].bh); | 407 | journal_mark_dirty(th, s, apbi[nr].bh); |
| 383 | 408 | ||
| 384 | reiserfs_prepare_for_journal(s, sbh, 1) ; | 409 | reiserfs_prepare_for_journal(s, sbh, 1); |
| 385 | /* update super block */ | 410 | /* update super block */ |
| 386 | set_sb_free_blocks( rs, sb_free_blocks(rs) + 1 ); | 411 | set_sb_free_blocks(rs, sb_free_blocks(rs) + 1); |
| 387 | 412 | ||
| 388 | journal_mark_dirty (th, s, sbh); | 413 | journal_mark_dirty(th, s, sbh); |
| 389 | if (for_unformatted) | 414 | if (for_unformatted) |
| 390 | DQUOT_FREE_BLOCK_NODIRTY(inode, 1); | 415 | DQUOT_FREE_BLOCK_NODIRTY(inode, 1); |
| 391 | } | 416 | } |
| 392 | 417 | ||
| 393 | void reiserfs_free_block (struct reiserfs_transaction_handle *th, | 418 | void reiserfs_free_block(struct reiserfs_transaction_handle *th, |
| 394 | struct inode *inode, b_blocknr_t block, | 419 | struct inode *inode, b_blocknr_t block, |
| 395 | int for_unformatted) | 420 | int for_unformatted) |
| 396 | { | 421 | { |
| 397 | struct super_block * s = th->t_super; | 422 | struct super_block *s = th->t_super; |
| 398 | 423 | ||
| 399 | BUG_ON (!th->t_trans_id); | 424 | BUG_ON(!th->t_trans_id); |
| 400 | 425 | ||
| 401 | RFALSE(!s, "vs-4061: trying to free block on nonexistent device"); | 426 | RFALSE(!s, "vs-4061: trying to free block on nonexistent device"); |
| 402 | RFALSE(is_reusable (s, block, 1) == 0, "vs-4071: can not free such block"); | 427 | RFALSE(is_reusable(s, block, 1) == 0, |
| 403 | /* mark it before we clear it, just in case */ | 428 | "vs-4071: can not free such block"); |
| 404 | journal_mark_freed(th, s, block) ; | 429 | /* mark it before we clear it, just in case */ |
| 405 | _reiserfs_free_block(th, inode, block, for_unformatted) ; | 430 | journal_mark_freed(th, s, block); |
| 431 | _reiserfs_free_block(th, inode, block, for_unformatted); | ||
| 406 | } | 432 | } |
| 407 | 433 | ||
| 408 | /* preallocated blocks don't need to be run through journal_mark_freed */ | 434 | /* preallocated blocks don't need to be run through journal_mark_freed */ |
| 409 | static void reiserfs_free_prealloc_block (struct reiserfs_transaction_handle *th, | 435 | static void reiserfs_free_prealloc_block(struct reiserfs_transaction_handle *th, |
| 410 | struct inode *inode, b_blocknr_t block) { | 436 | struct inode *inode, b_blocknr_t block) |
| 411 | RFALSE(!th->t_super, "vs-4060: trying to free block on nonexistent device"); | 437 | { |
| 412 | RFALSE(is_reusable (th->t_super, block, 1) == 0, "vs-4070: can not free such block"); | 438 | RFALSE(!th->t_super, |
| 413 | BUG_ON (!th->t_trans_id); | 439 | "vs-4060: trying to free block on nonexistent device"); |
| 414 | _reiserfs_free_block(th, inode, block, 1) ; | 440 | RFALSE(is_reusable(th->t_super, block, 1) == 0, |
| 441 | "vs-4070: can not free such block"); | ||
| 442 | BUG_ON(!th->t_trans_id); | ||
| 443 | _reiserfs_free_block(th, inode, block, 1); | ||
| 415 | } | 444 | } |
| 416 | 445 | ||
| 417 | static void __discard_prealloc (struct reiserfs_transaction_handle * th, | 446 | static void __discard_prealloc(struct reiserfs_transaction_handle *th, |
| 418 | struct reiserfs_inode_info *ei) | 447 | struct reiserfs_inode_info *ei) |
| 419 | { | 448 | { |
| 420 | unsigned long save = ei->i_prealloc_block ; | 449 | unsigned long save = ei->i_prealloc_block; |
| 421 | int dirty = 0; | 450 | int dirty = 0; |
| 422 | struct inode *inode = &ei->vfs_inode; | 451 | struct inode *inode = &ei->vfs_inode; |
| 423 | BUG_ON (!th->t_trans_id); | 452 | BUG_ON(!th->t_trans_id); |
| 424 | #ifdef CONFIG_REISERFS_CHECK | 453 | #ifdef CONFIG_REISERFS_CHECK |
| 425 | if (ei->i_prealloc_count < 0) | 454 | if (ei->i_prealloc_count < 0) |
| 426 | reiserfs_warning (th->t_super, "zam-4001:%s: inode has negative prealloc blocks count.", __FUNCTION__ ); | 455 | reiserfs_warning(th->t_super, |
| 456 | "zam-4001:%s: inode has negative prealloc blocks count.", | ||
| 457 | __FUNCTION__); | ||
| 427 | #endif | 458 | #endif |
| 428 | while (ei->i_prealloc_count > 0) { | 459 | while (ei->i_prealloc_count > 0) { |
| 429 | reiserfs_free_prealloc_block(th, inode, ei->i_prealloc_block); | 460 | reiserfs_free_prealloc_block(th, inode, ei->i_prealloc_block); |
| 430 | ei->i_prealloc_block++; | 461 | ei->i_prealloc_block++; |
| 431 | ei->i_prealloc_count --; | 462 | ei->i_prealloc_count--; |
| 432 | dirty = 1; | 463 | dirty = 1; |
| 433 | } | 464 | } |
| 434 | if (dirty) | 465 | if (dirty) |
| 435 | reiserfs_update_sd(th, inode); | 466 | reiserfs_update_sd(th, inode); |
| 436 | ei->i_prealloc_block = save; | 467 | ei->i_prealloc_block = save; |
| 437 | list_del_init(&(ei->i_prealloc_list)); | 468 | list_del_init(&(ei->i_prealloc_list)); |
| 438 | } | 469 | } |
| 439 | 470 | ||
| 440 | /* FIXME: It should be inline function */ | 471 | /* FIXME: It should be inline function */ |
| 441 | void reiserfs_discard_prealloc (struct reiserfs_transaction_handle *th, | 472 | void reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th, |
| 442 | struct inode *inode) | 473 | struct inode *inode) |
| 443 | { | 474 | { |
| 444 | struct reiserfs_inode_info *ei = REISERFS_I(inode); | 475 | struct reiserfs_inode_info *ei = REISERFS_I(inode); |
| 445 | BUG_ON (!th->t_trans_id); | 476 | BUG_ON(!th->t_trans_id); |
| 446 | if (ei->i_prealloc_count) | 477 | if (ei->i_prealloc_count) |
| 447 | __discard_prealloc(th, ei); | 478 | __discard_prealloc(th, ei); |
| 448 | } | 479 | } |
| 449 | 480 | ||
| 450 | void reiserfs_discard_all_prealloc (struct reiserfs_transaction_handle *th) | 481 | void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th) |
| 451 | { | 482 | { |
| 452 | struct list_head * plist = &SB_JOURNAL(th->t_super)->j_prealloc_list; | 483 | struct list_head *plist = &SB_JOURNAL(th->t_super)->j_prealloc_list; |
| 453 | 484 | ||
| 454 | BUG_ON (!th->t_trans_id); | 485 | BUG_ON(!th->t_trans_id); |
| 455 | 486 | ||
| 456 | while (!list_empty(plist)) { | 487 | while (!list_empty(plist)) { |
| 457 | struct reiserfs_inode_info *ei; | 488 | struct reiserfs_inode_info *ei; |
| 458 | ei = list_entry(plist->next, struct reiserfs_inode_info, i_prealloc_list); | 489 | ei = list_entry(plist->next, struct reiserfs_inode_info, |
| 490 | i_prealloc_list); | ||
| 459 | #ifdef CONFIG_REISERFS_CHECK | 491 | #ifdef CONFIG_REISERFS_CHECK |
| 460 | if (!ei->i_prealloc_count) { | 492 | if (!ei->i_prealloc_count) { |
| 461 | reiserfs_warning (th->t_super, "zam-4001:%s: inode is in prealloc list but has no preallocated blocks.", __FUNCTION__); | 493 | reiserfs_warning(th->t_super, |
| 462 | } | 494 | "zam-4001:%s: inode is in prealloc list but has no preallocated blocks.", |
| 495 | __FUNCTION__); | ||
| 496 | } | ||
| 463 | #endif | 497 | #endif |
| 464 | __discard_prealloc(th, ei); | 498 | __discard_prealloc(th, ei); |
| 465 | } | 499 | } |
| 466 | } | 500 | } |
| 467 | 501 | ||
| 468 | void reiserfs_init_alloc_options (struct super_block *s) | 502 | void reiserfs_init_alloc_options(struct super_block *s) |
| 469 | { | 503 | { |
| 470 | set_bit (_ALLOC_skip_busy, &SB_ALLOC_OPTS(s)); | 504 | set_bit(_ALLOC_skip_busy, &SB_ALLOC_OPTS(s)); |
| 471 | set_bit (_ALLOC_dirid_groups, &SB_ALLOC_OPTS(s)); | 505 | set_bit(_ALLOC_dirid_groups, &SB_ALLOC_OPTS(s)); |
| 472 | set_bit (_ALLOC_packing_groups, &SB_ALLOC_OPTS(s)); | 506 | set_bit(_ALLOC_packing_groups, &SB_ALLOC_OPTS(s)); |
| 473 | } | 507 | } |
| 474 | 508 | ||
| 475 | /* block allocator related options are parsed here */ | 509 | /* block allocator related options are parsed here */ |
| 476 | int reiserfs_parse_alloc_options(struct super_block * s, char * options) | 510 | int reiserfs_parse_alloc_options(struct super_block *s, char *options) |
| 477 | { | 511 | { |
| 478 | char * this_char, * value; | 512 | char *this_char, *value; |
| 479 | 513 | ||
| 480 | REISERFS_SB(s)->s_alloc_options.bits = 0; /* clear default settings */ | 514 | REISERFS_SB(s)->s_alloc_options.bits = 0; /* clear default settings */ |
| 481 | 515 | ||
| 482 | while ( (this_char = strsep (&options, ":")) != NULL ) { | 516 | while ((this_char = strsep(&options, ":")) != NULL) { |
| 483 | if ((value = strchr (this_char, '=')) != NULL) | 517 | if ((value = strchr(this_char, '=')) != NULL) |
| 484 | *value++ = 0; | 518 | *value++ = 0; |
| 485 | 519 | ||
| 486 | if (!strcmp(this_char, "concentrating_formatted_nodes")) { | 520 | if (!strcmp(this_char, "concentrating_formatted_nodes")) { |
| 487 | int temp; | 521 | int temp; |
| 488 | SET_OPTION(concentrating_formatted_nodes); | 522 | SET_OPTION(concentrating_formatted_nodes); |
| 489 | temp = (value && *value) ? simple_strtoul (value, &value, 0) : 10; | 523 | temp = (value |
| 490 | if (temp <= 0 || temp > 100) { | 524 | && *value) ? simple_strtoul(value, &value, |
| 491 | REISERFS_SB(s)->s_alloc_options.border = 10; | 525 | 0) : 10; |
| 492 | } else { | 526 | if (temp <= 0 || temp > 100) { |
| 493 | REISERFS_SB(s)->s_alloc_options.border = 100 / temp; | 527 | REISERFS_SB(s)->s_alloc_options.border = 10; |
| 494 | } | 528 | } else { |
| 495 | continue; | 529 | REISERFS_SB(s)->s_alloc_options.border = |
| 496 | } | 530 | 100 / temp; |
| 497 | if (!strcmp(this_char, "displacing_large_files")) { | 531 | } |
| 498 | SET_OPTION(displacing_large_files); | 532 | continue; |
| 499 | REISERFS_SB(s)->s_alloc_options.large_file_size = | 533 | } |
| 500 | (value && *value) ? simple_strtoul (value, &value, 0) : 16; | 534 | if (!strcmp(this_char, "displacing_large_files")) { |
| 501 | continue; | 535 | SET_OPTION(displacing_large_files); |
| 502 | } | 536 | REISERFS_SB(s)->s_alloc_options.large_file_size = |
| 503 | if (!strcmp(this_char, "displacing_new_packing_localities")) { | 537 | (value |
| 504 | SET_OPTION(displacing_new_packing_localities); | 538 | && *value) ? simple_strtoul(value, &value, 0) : 16; |
| 505 | continue; | 539 | continue; |
| 506 | }; | 540 | } |
| 507 | 541 | if (!strcmp(this_char, "displacing_new_packing_localities")) { | |
| 508 | if (!strcmp(this_char, "old_hashed_relocation")) { | 542 | SET_OPTION(displacing_new_packing_localities); |
| 509 | SET_OPTION(old_hashed_relocation); | 543 | continue; |
| 510 | continue; | 544 | }; |
| 511 | } | 545 | |
| 546 | if (!strcmp(this_char, "old_hashed_relocation")) { | ||
| 547 | SET_OPTION(old_hashed_relocation); | ||
| 548 | continue; | ||
| 549 | } | ||
| 512 | 550 | ||
| 513 | if (!strcmp(this_char, "new_hashed_relocation")) { | 551 | if (!strcmp(this_char, "new_hashed_relocation")) { |
| 514 | SET_OPTION(new_hashed_relocation); | 552 | SET_OPTION(new_hashed_relocation); |
| 515 | continue; | 553 | continue; |
| 516 | } | 554 | } |
| 517 | 555 | ||
| 518 | if (!strcmp(this_char, "dirid_groups")) { | 556 | if (!strcmp(this_char, "dirid_groups")) { |
| 519 | SET_OPTION(dirid_groups); | 557 | SET_OPTION(dirid_groups); |
| 520 | continue; | 558 | continue; |
| 521 | } | 559 | } |
| 522 | if (!strcmp(this_char, "oid_groups")) { | 560 | if (!strcmp(this_char, "oid_groups")) { |
| 523 | SET_OPTION(oid_groups); | 561 | SET_OPTION(oid_groups); |
| 524 | continue; | 562 | continue; |
| 525 | } | 563 | } |
| 526 | if (!strcmp(this_char, "packing_groups")) { | 564 | if (!strcmp(this_char, "packing_groups")) { |
| 527 | SET_OPTION(packing_groups); | 565 | SET_OPTION(packing_groups); |
| 528 | continue; | 566 | continue; |
| 529 | } | 567 | } |
| 530 | if (!strcmp(this_char, "hashed_formatted_nodes")) { | 568 | if (!strcmp(this_char, "hashed_formatted_nodes")) { |
| 531 | SET_OPTION(hashed_formatted_nodes); | 569 | SET_OPTION(hashed_formatted_nodes); |
| 532 | continue; | 570 | continue; |
| 533 | } | 571 | } |
| 534 | 572 | ||
| 535 | if (!strcmp(this_char, "skip_busy")) { | 573 | if (!strcmp(this_char, "skip_busy")) { |
| 536 | SET_OPTION(skip_busy); | 574 | SET_OPTION(skip_busy); |
| 537 | continue; | 575 | continue; |
| 538 | } | 576 | } |
| 539 | 577 | ||
| 540 | if (!strcmp(this_char, "hundredth_slices")) { | 578 | if (!strcmp(this_char, "hundredth_slices")) { |
| 541 | SET_OPTION(hundredth_slices); | 579 | SET_OPTION(hundredth_slices); |
| 542 | continue; | 580 | continue; |
| 543 | } | 581 | } |
| 544 | 582 | ||
| 545 | if (!strcmp(this_char, "old_way")) { | 583 | if (!strcmp(this_char, "old_way")) { |
| 546 | SET_OPTION(old_way); | 584 | SET_OPTION(old_way); |
| 547 | continue; | 585 | continue; |
| 548 | } | 586 | } |
| 549 | 587 | ||
| 550 | if (!strcmp(this_char, "displace_based_on_dirid")) { | 588 | if (!strcmp(this_char, "displace_based_on_dirid")) { |
| 551 | SET_OPTION(displace_based_on_dirid); | 589 | SET_OPTION(displace_based_on_dirid); |
| 552 | continue; | 590 | continue; |
| 553 | } | 591 | } |
| 554 | 592 | ||
| 555 | if (!strcmp(this_char, "preallocmin")) { | 593 | if (!strcmp(this_char, "preallocmin")) { |
| 556 | REISERFS_SB(s)->s_alloc_options.preallocmin = | 594 | REISERFS_SB(s)->s_alloc_options.preallocmin = |
| 557 | (value && *value) ? simple_strtoul (value, &value, 0) : 4; | 595 | (value |
| 558 | continue; | 596 | && *value) ? simple_strtoul(value, &value, 0) : 4; |
| 559 | } | 597 | continue; |
| 598 | } | ||
| 599 | |||
| 600 | if (!strcmp(this_char, "preallocsize")) { | ||
| 601 | REISERFS_SB(s)->s_alloc_options.preallocsize = | ||
| 602 | (value | ||
| 603 | && *value) ? simple_strtoul(value, &value, | ||
| 604 | 0) : | ||
| 605 | PREALLOCATION_SIZE; | ||
| 606 | continue; | ||
| 607 | } | ||
| 560 | 608 | ||
| 561 | if (!strcmp(this_char, "preallocsize")) { | 609 | reiserfs_warning(s, "zam-4001: %s : unknown option - %s", |
| 562 | REISERFS_SB(s)->s_alloc_options.preallocsize = | 610 | __FUNCTION__, this_char); |
| 563 | (value && *value) ? simple_strtoul (value, &value, 0) : PREALLOCATION_SIZE; | 611 | return 1; |
| 564 | continue; | ||
| 565 | } | 612 | } |
| 566 | 613 | ||
| 567 | reiserfs_warning (s, "zam-4001: %s : unknown option - %s", | 614 | reiserfs_warning(s, "allocator options = [%08x]\n", SB_ALLOC_OPTS(s)); |
| 568 | __FUNCTION__ , this_char); | 615 | return 0; |
| 569 | return 1; | ||
| 570 | } | ||
| 571 | |||
| 572 | reiserfs_warning (s, "allocator options = [%08x]\n", SB_ALLOC_OPTS(s)); | ||
| 573 | return 0; | ||
| 574 | } | 616 | } |
| 575 | 617 | ||
| 576 | static inline void new_hashed_relocation (reiserfs_blocknr_hint_t * hint) | 618 | static inline void new_hashed_relocation(reiserfs_blocknr_hint_t * hint) |
| 577 | { | 619 | { |
| 578 | char * hash_in; | 620 | char *hash_in; |
| 579 | if (hint->formatted_node) { | 621 | if (hint->formatted_node) { |
| 580 | hash_in = (char*)&hint->key.k_dir_id; | 622 | hash_in = (char *)&hint->key.k_dir_id; |
| 581 | } else { | 623 | } else { |
| 582 | if (!hint->inode) { | 624 | if (!hint->inode) { |
| 583 | //hint->search_start = hint->beg; | 625 | //hint->search_start = hint->beg; |
| 584 | hash_in = (char*)&hint->key.k_dir_id; | 626 | hash_in = (char *)&hint->key.k_dir_id; |
| 585 | } else | 627 | } else |
| 586 | if ( TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) | 628 | if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) |
| 587 | hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id); | 629 | hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id); |
| 588 | else | 630 | else |
| 589 | hash_in = (char *)(&INODE_PKEY(hint->inode)->k_objectid); | 631 | hash_in = |
| 590 | } | 632 | (char *)(&INODE_PKEY(hint->inode)->k_objectid); |
| 633 | } | ||
| 591 | 634 | ||
| 592 | hint->search_start = hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg); | 635 | hint->search_start = |
| 636 | hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg); | ||
| 593 | } | 637 | } |
| 594 | 638 | ||
| 595 | /* | 639 | /* |
| 596 | * Relocation based on dirid, hashing them into a given bitmap block | 640 | * Relocation based on dirid, hashing them into a given bitmap block |
| 597 | * files. Formatted nodes are unaffected, a seperate policy covers them | 641 | * files. Formatted nodes are unaffected, a seperate policy covers them |
| 598 | */ | 642 | */ |
| 599 | static void | 643 | static void dirid_groups(reiserfs_blocknr_hint_t * hint) |
| 600 | dirid_groups (reiserfs_blocknr_hint_t *hint) | ||
| 601 | { | 644 | { |
| 602 | unsigned long hash; | 645 | unsigned long hash; |
| 603 | __u32 dirid = 0; | 646 | __u32 dirid = 0; |
| 604 | int bm = 0; | 647 | int bm = 0; |
| 605 | struct super_block *sb = hint->th->t_super; | 648 | struct super_block *sb = hint->th->t_super; |
| 606 | if (hint->inode) | ||
| 607 | dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id); | ||
| 608 | else if (hint->formatted_node) | ||
| 609 | dirid = hint->key.k_dir_id; | ||
| 610 | |||
| 611 | if (dirid) { | ||
| 612 | bm = bmap_hash_id(sb, dirid); | ||
| 613 | hash = bm * (sb->s_blocksize << 3); | ||
| 614 | /* give a portion of the block group to metadata */ | ||
| 615 | if (hint->inode) | 649 | if (hint->inode) |
| 616 | hash += sb->s_blocksize/2; | 650 | dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id); |
| 617 | hint->search_start = hash; | 651 | else if (hint->formatted_node) |
| 618 | } | 652 | dirid = hint->key.k_dir_id; |
| 653 | |||
| 654 | if (dirid) { | ||
| 655 | bm = bmap_hash_id(sb, dirid); | ||
| 656 | hash = bm * (sb->s_blocksize << 3); | ||
| 657 | /* give a portion of the block group to metadata */ | ||
| 658 | if (hint->inode) | ||
| 659 | hash += sb->s_blocksize / 2; | ||
| 660 | hint->search_start = hash; | ||
| 661 | } | ||
| 619 | } | 662 | } |
| 620 | 663 | ||
| 621 | /* | 664 | /* |
| 622 | * Relocation based on oid, hashing them into a given bitmap block | 665 | * Relocation based on oid, hashing them into a given bitmap block |
| 623 | * files. Formatted nodes are unaffected, a seperate policy covers them | 666 | * files. Formatted nodes are unaffected, a seperate policy covers them |
| 624 | */ | 667 | */ |
| 625 | static void | 668 | static void oid_groups(reiserfs_blocknr_hint_t * hint) |
| 626 | oid_groups (reiserfs_blocknr_hint_t *hint) | ||
| 627 | { | 669 | { |
| 628 | if (hint->inode) { | 670 | if (hint->inode) { |
| 629 | unsigned long hash; | 671 | unsigned long hash; |
| 630 | __u32 oid; | 672 | __u32 oid; |
| 631 | __u32 dirid; | 673 | __u32 dirid; |
| 632 | int bm; | 674 | int bm; |
| 633 | 675 | ||
| 634 | dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id); | 676 | dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id); |
| 635 | 677 | ||
| 636 | /* keep the root dir and it's first set of subdirs close to | 678 | /* keep the root dir and it's first set of subdirs close to |
| 637 | * the start of the disk | 679 | * the start of the disk |
| 638 | */ | 680 | */ |
| 639 | if (dirid <= 2) | 681 | if (dirid <= 2) |
| 640 | hash = (hint->inode->i_sb->s_blocksize << 3); | 682 | hash = (hint->inode->i_sb->s_blocksize << 3); |
| 641 | else { | 683 | else { |
| 642 | oid = le32_to_cpu(INODE_PKEY(hint->inode)->k_objectid); | 684 | oid = le32_to_cpu(INODE_PKEY(hint->inode)->k_objectid); |
| 643 | bm = bmap_hash_id(hint->inode->i_sb, oid); | 685 | bm = bmap_hash_id(hint->inode->i_sb, oid); |
| 644 | hash = bm * (hint->inode->i_sb->s_blocksize << 3); | 686 | hash = bm * (hint->inode->i_sb->s_blocksize << 3); |
| 687 | } | ||
| 688 | hint->search_start = hash; | ||
| 645 | } | 689 | } |
| 646 | hint->search_start = hash; | ||
| 647 | } | ||
| 648 | } | 690 | } |
| 649 | 691 | ||
| 650 | /* returns 1 if it finds an indirect item and gets valid hint info | 692 | /* returns 1 if it finds an indirect item and gets valid hint info |
| 651 | * from it, otherwise 0 | 693 | * from it, otherwise 0 |
| 652 | */ | 694 | */ |
| 653 | static int get_left_neighbor(reiserfs_blocknr_hint_t *hint) | 695 | static int get_left_neighbor(reiserfs_blocknr_hint_t * hint) |
| 654 | { | 696 | { |
| 655 | struct path * path; | 697 | struct path *path; |
| 656 | struct buffer_head * bh; | 698 | struct buffer_head *bh; |
| 657 | struct item_head * ih; | 699 | struct item_head *ih; |
| 658 | int pos_in_item; | 700 | int pos_in_item; |
| 659 | __le32 * item; | 701 | __le32 *item; |
| 660 | int ret = 0; | 702 | int ret = 0; |
| 661 | 703 | ||
| 662 | if (!hint->path) /* reiserfs code can call this function w/o pointer to path | 704 | if (!hint->path) /* reiserfs code can call this function w/o pointer to path |
| 663 | * structure supplied; then we rely on supplied search_start */ | 705 | * structure supplied; then we rely on supplied search_start */ |
| 664 | return 0; | 706 | return 0; |
| 665 | 707 | ||
| 666 | path = hint->path; | 708 | path = hint->path; |
| 667 | bh = get_last_bh(path); | 709 | bh = get_last_bh(path); |
| 668 | RFALSE( !bh, "green-4002: Illegal path specified to get_left_neighbor"); | 710 | RFALSE(!bh, "green-4002: Illegal path specified to get_left_neighbor"); |
| 669 | ih = get_ih(path); | 711 | ih = get_ih(path); |
| 670 | pos_in_item = path->pos_in_item; | 712 | pos_in_item = path->pos_in_item; |
| 671 | item = get_item (path); | 713 | item = get_item(path); |
| 672 | 714 | ||
| 673 | hint->search_start = bh->b_blocknr; | 715 | hint->search_start = bh->b_blocknr; |
| 674 | 716 | ||
| 675 | if (!hint->formatted_node && is_indirect_le_ih (ih)) { | 717 | if (!hint->formatted_node && is_indirect_le_ih(ih)) { |
| 676 | /* for indirect item: go to left and look for the first non-hole entry | 718 | /* for indirect item: go to left and look for the first non-hole entry |
| 677 | in the indirect item */ | 719 | in the indirect item */ |
| 678 | if (pos_in_item == I_UNFM_NUM (ih)) | 720 | if (pos_in_item == I_UNFM_NUM(ih)) |
| 679 | pos_in_item--; | 721 | pos_in_item--; |
| 680 | // pos_in_item = I_UNFM_NUM (ih) - 1; | 722 | // pos_in_item = I_UNFM_NUM (ih) - 1; |
| 681 | while (pos_in_item >= 0) { | 723 | while (pos_in_item >= 0) { |
| 682 | int t=get_block_num(item,pos_in_item); | 724 | int t = get_block_num(item, pos_in_item); |
| 683 | if (t) { | 725 | if (t) { |
| 684 | hint->search_start = t; | 726 | hint->search_start = t; |
| 685 | ret = 1; | 727 | ret = 1; |
| 686 | break; | 728 | break; |
| 687 | } | 729 | } |
| 688 | pos_in_item --; | 730 | pos_in_item--; |
| 731 | } | ||
| 689 | } | 732 | } |
| 690 | } | ||
| 691 | 733 | ||
| 692 | /* does result value fit into specified region? */ | 734 | /* does result value fit into specified region? */ |
| 693 | return ret; | 735 | return ret; |
| 694 | } | 736 | } |
| 695 | 737 | ||
| 696 | /* should be, if formatted node, then try to put on first part of the device | 738 | /* should be, if formatted node, then try to put on first part of the device |
| 697 | specified as number of percent with mount option device, else try to put | 739 | specified as number of percent with mount option device, else try to put |
| 698 | on last of device. This is not to say it is good code to do so, | 740 | on last of device. This is not to say it is good code to do so, |
| 699 | but the effect should be measured. */ | 741 | but the effect should be measured. */ |
| 700 | static inline void set_border_in_hint(struct super_block *s, reiserfs_blocknr_hint_t *hint) | 742 | static inline void set_border_in_hint(struct super_block *s, |
| 743 | reiserfs_blocknr_hint_t * hint) | ||
| 701 | { | 744 | { |
| 702 | b_blocknr_t border = SB_BLOCK_COUNT(s) / REISERFS_SB(s)->s_alloc_options.border; | 745 | b_blocknr_t border = |
| 746 | SB_BLOCK_COUNT(s) / REISERFS_SB(s)->s_alloc_options.border; | ||
| 703 | 747 | ||
| 704 | if (hint->formatted_node) | 748 | if (hint->formatted_node) |
| 705 | hint->end = border - 1; | 749 | hint->end = border - 1; |
| 706 | else | 750 | else |
| 707 | hint->beg = border; | 751 | hint->beg = border; |
| 708 | } | 752 | } |
| 709 | 753 | ||
| 710 | static inline void displace_large_file(reiserfs_blocknr_hint_t *hint) | 754 | static inline void displace_large_file(reiserfs_blocknr_hint_t * hint) |
| 711 | { | 755 | { |
| 712 | if ( TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) | 756 | if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) |
| 713 | hint->search_start = hint->beg + keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_dir_id), 4) % (hint->end - hint->beg); | 757 | hint->search_start = |
| 714 | else | 758 | hint->beg + |
| 715 | hint->search_start = hint->beg + keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_objectid), 4) % (hint->end - hint->beg); | 759 | keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_dir_id), |
| 760 | 4) % (hint->end - hint->beg); | ||
| 761 | else | ||
| 762 | hint->search_start = | ||
| 763 | hint->beg + | ||
| 764 | keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_objectid), | ||
| 765 | 4) % (hint->end - hint->beg); | ||
| 716 | } | 766 | } |
| 717 | 767 | ||
| 718 | static inline void hash_formatted_node(reiserfs_blocknr_hint_t *hint) | 768 | static inline void hash_formatted_node(reiserfs_blocknr_hint_t * hint) |
| 719 | { | 769 | { |
| 720 | char * hash_in; | 770 | char *hash_in; |
| 721 | 771 | ||
| 722 | if (!hint->inode) | 772 | if (!hint->inode) |
| 723 | hash_in = (char*)&hint->key.k_dir_id; | 773 | hash_in = (char *)&hint->key.k_dir_id; |
| 724 | else if ( TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) | 774 | else if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) |
| 725 | hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id); | 775 | hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id); |
| 726 | else | 776 | else |
| 727 | hash_in = (char *)(&INODE_PKEY(hint->inode)->k_objectid); | 777 | hash_in = (char *)(&INODE_PKEY(hint->inode)->k_objectid); |
| 728 | 778 | ||
| 729 | hint->search_start = hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg); | 779 | hint->search_start = |
| 780 | hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg); | ||
| 730 | } | 781 | } |
| 731 | 782 | ||
| 732 | static inline int this_blocknr_allocation_would_make_it_a_large_file(reiserfs_blocknr_hint_t *hint) | 783 | static inline int |
| 784 | this_blocknr_allocation_would_make_it_a_large_file(reiserfs_blocknr_hint_t * | ||
| 785 | hint) | ||
| 733 | { | 786 | { |
| 734 | return hint->block == REISERFS_SB(hint->th->t_super)->s_alloc_options.large_file_size; | 787 | return hint->block == |
| 788 | REISERFS_SB(hint->th->t_super)->s_alloc_options.large_file_size; | ||
| 735 | } | 789 | } |
| 736 | 790 | ||
| 737 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES | 791 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES |
| 738 | static inline void displace_new_packing_locality (reiserfs_blocknr_hint_t *hint) | 792 | static inline void displace_new_packing_locality(reiserfs_blocknr_hint_t * hint) |
| 739 | { | 793 | { |
| 740 | struct in_core_key * key = &hint->key; | 794 | struct in_core_key *key = &hint->key; |
| 741 | 795 | ||
| 742 | hint->th->displace_new_blocks = 0; | 796 | hint->th->displace_new_blocks = 0; |
| 743 | hint->search_start = hint->beg + keyed_hash((char*)(&key->k_objectid),4) % (hint->end - hint->beg); | 797 | hint->search_start = |
| 798 | hint->beg + keyed_hash((char *)(&key->k_objectid), | ||
| 799 | 4) % (hint->end - hint->beg); | ||
| 744 | } | 800 | } |
| 745 | #endif | 801 | #endif |
| 746 | 802 | ||
| 747 | static inline int old_hashed_relocation (reiserfs_blocknr_hint_t * hint) | 803 | static inline int old_hashed_relocation(reiserfs_blocknr_hint_t * hint) |
| 748 | { | 804 | { |
| 749 | b_blocknr_t border; | 805 | b_blocknr_t border; |
| 750 | u32 hash_in; | 806 | u32 hash_in; |
| 751 | |||
| 752 | if (hint->formatted_node || hint->inode == NULL) { | ||
| 753 | return 0; | ||
| 754 | } | ||
| 755 | 807 | ||
| 756 | hash_in = le32_to_cpu((INODE_PKEY(hint->inode))->k_dir_id); | 808 | if (hint->formatted_node || hint->inode == NULL) { |
| 757 | border = hint->beg + (u32) keyed_hash(((char *) (&hash_in)), 4) % (hint->end - hint->beg - 1); | 809 | return 0; |
| 758 | if (border > hint->search_start) | 810 | } |
| 759 | hint->search_start = border; | ||
| 760 | 811 | ||
| 761 | return 1; | 812 | hash_in = le32_to_cpu((INODE_PKEY(hint->inode))->k_dir_id); |
| 762 | } | 813 | border = |
| 763 | 814 | hint->beg + (u32) keyed_hash(((char *)(&hash_in)), | |
| 764 | static inline int old_way (reiserfs_blocknr_hint_t * hint) | 815 | 4) % (hint->end - hint->beg - 1); |
| 765 | { | 816 | if (border > hint->search_start) |
| 766 | b_blocknr_t border; | 817 | hint->search_start = border; |
| 767 | |||
| 768 | if (hint->formatted_node || hint->inode == NULL) { | ||
| 769 | return 0; | ||
| 770 | } | ||
| 771 | |||
| 772 | border = hint->beg + le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id) % (hint->end - hint->beg); | ||
| 773 | if (border > hint->search_start) | ||
| 774 | hint->search_start = border; | ||
| 775 | 818 | ||
| 776 | return 1; | 819 | return 1; |
| 777 | } | 820 | } |
| 778 | 821 | ||
| 779 | static inline void hundredth_slices (reiserfs_blocknr_hint_t * hint) | 822 | static inline int old_way(reiserfs_blocknr_hint_t * hint) |
| 780 | { | 823 | { |
| 781 | struct in_core_key * key = &hint->key; | 824 | b_blocknr_t border; |
| 782 | b_blocknr_t slice_start; | 825 | |
| 826 | if (hint->formatted_node || hint->inode == NULL) { | ||
| 827 | return 0; | ||
| 828 | } | ||
| 829 | |||
| 830 | border = | ||
| 831 | hint->beg + | ||
| 832 | le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id) % (hint->end - | ||
| 833 | hint->beg); | ||
| 834 | if (border > hint->search_start) | ||
| 835 | hint->search_start = border; | ||
| 783 | 836 | ||
| 784 | slice_start = (keyed_hash((char*)(&key->k_dir_id),4) % 100) * (hint->end / 100); | 837 | return 1; |
| 785 | if ( slice_start > hint->search_start || slice_start + (hint->end / 100) <= hint->search_start) { | 838 | } |
| 786 | hint->search_start = slice_start; | 839 | |
| 787 | } | 840 | static inline void hundredth_slices(reiserfs_blocknr_hint_t * hint) |
| 841 | { | ||
| 842 | struct in_core_key *key = &hint->key; | ||
| 843 | b_blocknr_t slice_start; | ||
| 844 | |||
| 845 | slice_start = | ||
| 846 | (keyed_hash((char *)(&key->k_dir_id), 4) % 100) * (hint->end / 100); | ||
| 847 | if (slice_start > hint->search_start | ||
| 848 | || slice_start + (hint->end / 100) <= hint->search_start) { | ||
| 849 | hint->search_start = slice_start; | ||
| 850 | } | ||
| 788 | } | 851 | } |
| 789 | 852 | ||
| 790 | static void determine_search_start(reiserfs_blocknr_hint_t *hint, | 853 | static void determine_search_start(reiserfs_blocknr_hint_t * hint, |
| 791 | int amount_needed) | 854 | int amount_needed) |
| 792 | { | 855 | { |
| 793 | struct super_block *s = hint->th->t_super; | 856 | struct super_block *s = hint->th->t_super; |
| 794 | int unfm_hint; | 857 | int unfm_hint; |
| 795 | 858 | ||
| 796 | hint->beg = 0; | 859 | hint->beg = 0; |
| 797 | hint->end = SB_BLOCK_COUNT(s) - 1; | 860 | hint->end = SB_BLOCK_COUNT(s) - 1; |
| 798 | 861 | ||
| 799 | /* This is former border algorithm. Now with tunable border offset */ | 862 | /* This is former border algorithm. Now with tunable border offset */ |
| 800 | if (concentrating_formatted_nodes(s)) | 863 | if (concentrating_formatted_nodes(s)) |
| 801 | set_border_in_hint(s, hint); | 864 | set_border_in_hint(s, hint); |
| 802 | 865 | ||
| 803 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES | 866 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES |
| 804 | /* whenever we create a new directory, we displace it. At first we will | 867 | /* whenever we create a new directory, we displace it. At first we will |
| 805 | hash for location, later we might look for a moderately empty place for | 868 | hash for location, later we might look for a moderately empty place for |
| 806 | it */ | 869 | it */ |
| 807 | if (displacing_new_packing_localities(s) | 870 | if (displacing_new_packing_localities(s) |
| 808 | && hint->th->displace_new_blocks) { | 871 | && hint->th->displace_new_blocks) { |
| 809 | displace_new_packing_locality(hint); | 872 | displace_new_packing_locality(hint); |
| 810 | 873 | ||
| 811 | /* we do not continue determine_search_start, | 874 | /* we do not continue determine_search_start, |
| 812 | * if new packing locality is being displaced */ | 875 | * if new packing locality is being displaced */ |
| 813 | return; | 876 | return; |
| 814 | } | 877 | } |
| 815 | #endif | 878 | #endif |
| 816 | |||
| 817 | /* all persons should feel encouraged to add more special cases here and | ||
| 818 | * test them */ | ||
| 819 | 879 | ||
| 820 | if (displacing_large_files(s) && !hint->formatted_node | 880 | /* all persons should feel encouraged to add more special cases here and |
| 821 | && this_blocknr_allocation_would_make_it_a_large_file(hint)) { | 881 | * test them */ |
| 822 | displace_large_file(hint); | ||
| 823 | return; | ||
| 824 | } | ||
| 825 | |||
| 826 | /* if none of our special cases is relevant, use the left neighbor in the | ||
| 827 | tree order of the new node we are allocating for */ | ||
| 828 | if (hint->formatted_node && TEST_OPTION(hashed_formatted_nodes,s)) { | ||
| 829 | hash_formatted_node(hint); | ||
| 830 | return; | ||
| 831 | } | ||
| 832 | 882 | ||
| 833 | unfm_hint = get_left_neighbor(hint); | 883 | if (displacing_large_files(s) && !hint->formatted_node |
| 884 | && this_blocknr_allocation_would_make_it_a_large_file(hint)) { | ||
| 885 | displace_large_file(hint); | ||
| 886 | return; | ||
| 887 | } | ||
| 834 | 888 | ||
| 835 | /* Mimic old block allocator behaviour, that is if VFS allowed for preallocation, | 889 | /* if none of our special cases is relevant, use the left neighbor in the |
| 836 | new blocks are displaced based on directory ID. Also, if suggested search_start | 890 | tree order of the new node we are allocating for */ |
| 837 | is less than last preallocated block, we start searching from it, assuming that | 891 | if (hint->formatted_node && TEST_OPTION(hashed_formatted_nodes, s)) { |
| 838 | HDD dataflow is faster in forward direction */ | 892 | hash_formatted_node(hint); |
| 839 | if ( TEST_OPTION(old_way, s)) { | 893 | return; |
| 840 | if (!hint->formatted_node) { | 894 | } |
| 841 | if ( !reiserfs_hashed_relocation(s)) | ||
| 842 | old_way(hint); | ||
| 843 | else if (!reiserfs_no_unhashed_relocation(s)) | ||
| 844 | old_hashed_relocation(hint); | ||
| 845 | 895 | ||
| 846 | if ( hint->inode && hint->search_start < REISERFS_I(hint->inode)->i_prealloc_block) | 896 | unfm_hint = get_left_neighbor(hint); |
| 847 | hint->search_start = REISERFS_I(hint->inode)->i_prealloc_block; | 897 | |
| 898 | /* Mimic old block allocator behaviour, that is if VFS allowed for preallocation, | ||
| 899 | new blocks are displaced based on directory ID. Also, if suggested search_start | ||
| 900 | is less than last preallocated block, we start searching from it, assuming that | ||
| 901 | HDD dataflow is faster in forward direction */ | ||
| 902 | if (TEST_OPTION(old_way, s)) { | ||
| 903 | if (!hint->formatted_node) { | ||
| 904 | if (!reiserfs_hashed_relocation(s)) | ||
| 905 | old_way(hint); | ||
| 906 | else if (!reiserfs_no_unhashed_relocation(s)) | ||
| 907 | old_hashed_relocation(hint); | ||
| 908 | |||
| 909 | if (hint->inode | ||
| 910 | && hint->search_start < | ||
| 911 | REISERFS_I(hint->inode)->i_prealloc_block) | ||
| 912 | hint->search_start = | ||
| 913 | REISERFS_I(hint->inode)->i_prealloc_block; | ||
| 914 | } | ||
| 915 | return; | ||
| 848 | } | 916 | } |
| 849 | return; | ||
| 850 | } | ||
| 851 | 917 | ||
| 852 | /* This is an approach proposed by Hans */ | 918 | /* This is an approach proposed by Hans */ |
| 853 | if ( TEST_OPTION(hundredth_slices, s) && ! (displacing_large_files(s) && !hint->formatted_node)) { | 919 | if (TEST_OPTION(hundredth_slices, s) |
| 854 | hundredth_slices(hint); | 920 | && !(displacing_large_files(s) && !hint->formatted_node)) { |
| 855 | return; | 921 | hundredth_slices(hint); |
| 856 | } | 922 | return; |
| 857 | 923 | } | |
| 858 | /* old_hashed_relocation only works on unformatted */ | ||
| 859 | if (!unfm_hint && !hint->formatted_node && | ||
| 860 | TEST_OPTION(old_hashed_relocation, s)) | ||
| 861 | { | ||
| 862 | old_hashed_relocation(hint); | ||
| 863 | } | ||
| 864 | /* new_hashed_relocation works with both formatted/unformatted nodes */ | ||
| 865 | if ((!unfm_hint || hint->formatted_node) && | ||
| 866 | TEST_OPTION(new_hashed_relocation, s)) | ||
| 867 | { | ||
| 868 | new_hashed_relocation(hint); | ||
| 869 | } | ||
| 870 | /* dirid grouping works only on unformatted nodes */ | ||
| 871 | if (!unfm_hint && !hint->formatted_node && TEST_OPTION(dirid_groups,s)) | ||
| 872 | { | ||
| 873 | dirid_groups(hint); | ||
| 874 | } | ||
| 875 | 924 | ||
| 925 | /* old_hashed_relocation only works on unformatted */ | ||
| 926 | if (!unfm_hint && !hint->formatted_node && | ||
| 927 | TEST_OPTION(old_hashed_relocation, s)) { | ||
| 928 | old_hashed_relocation(hint); | ||
| 929 | } | ||
| 930 | /* new_hashed_relocation works with both formatted/unformatted nodes */ | ||
| 931 | if ((!unfm_hint || hint->formatted_node) && | ||
| 932 | TEST_OPTION(new_hashed_relocation, s)) { | ||
| 933 | new_hashed_relocation(hint); | ||
| 934 | } | ||
| 935 | /* dirid grouping works only on unformatted nodes */ | ||
| 936 | if (!unfm_hint && !hint->formatted_node && TEST_OPTION(dirid_groups, s)) { | ||
| 937 | dirid_groups(hint); | ||
| 938 | } | ||
| 876 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES | 939 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES |
| 877 | if (hint->formatted_node && TEST_OPTION(dirid_groups,s)) | 940 | if (hint->formatted_node && TEST_OPTION(dirid_groups, s)) { |
| 878 | { | 941 | dirid_groups(hint); |
| 879 | dirid_groups(hint); | 942 | } |
| 880 | } | ||
| 881 | #endif | 943 | #endif |
| 882 | 944 | ||
| 883 | /* oid grouping works only on unformatted nodes */ | 945 | /* oid grouping works only on unformatted nodes */ |
| 884 | if (!unfm_hint && !hint->formatted_node && TEST_OPTION(oid_groups,s)) | 946 | if (!unfm_hint && !hint->formatted_node && TEST_OPTION(oid_groups, s)) { |
| 885 | { | 947 | oid_groups(hint); |
| 886 | oid_groups(hint); | 948 | } |
| 887 | } | 949 | return; |
| 888 | return; | ||
| 889 | } | 950 | } |
| 890 | 951 | ||
| 891 | static int determine_prealloc_size(reiserfs_blocknr_hint_t * hint) | 952 | static int determine_prealloc_size(reiserfs_blocknr_hint_t * hint) |
| 892 | { | 953 | { |
| 893 | /* make minimum size a mount option and benchmark both ways */ | 954 | /* make minimum size a mount option and benchmark both ways */ |
| 894 | /* we preallocate blocks only for regular files, specific size */ | 955 | /* we preallocate blocks only for regular files, specific size */ |
| 895 | /* benchmark preallocating always and see what happens */ | 956 | /* benchmark preallocating always and see what happens */ |
| 896 | 957 | ||
| 897 | hint->prealloc_size = 0; | 958 | hint->prealloc_size = 0; |
| 898 | 959 | ||
| 899 | if (!hint->formatted_node && hint->preallocate) { | 960 | if (!hint->formatted_node && hint->preallocate) { |
| 900 | if (S_ISREG(hint->inode->i_mode) | 961 | if (S_ISREG(hint->inode->i_mode) |
| 901 | && hint->inode->i_size >= REISERFS_SB(hint->th->t_super)->s_alloc_options.preallocmin * hint->inode->i_sb->s_blocksize) | 962 | && hint->inode->i_size >= |
| 902 | hint->prealloc_size = REISERFS_SB(hint->th->t_super)->s_alloc_options.preallocsize - 1; | 963 | REISERFS_SB(hint->th->t_super)->s_alloc_options. |
| 903 | } | 964 | preallocmin * hint->inode->i_sb->s_blocksize) |
| 904 | return CARRY_ON; | 965 | hint->prealloc_size = |
| 966 | REISERFS_SB(hint->th->t_super)->s_alloc_options. | ||
| 967 | preallocsize - 1; | ||
| 968 | } | ||
| 969 | return CARRY_ON; | ||
| 905 | } | 970 | } |
| 906 | 971 | ||
| 907 | /* XXX I know it could be merged with upper-level function; | 972 | /* XXX I know it could be merged with upper-level function; |
| 908 | but may be result function would be too complex. */ | 973 | but may be result function would be too complex. */ |
| 909 | static inline int allocate_without_wrapping_disk (reiserfs_blocknr_hint_t * hint, | 974 | static inline int allocate_without_wrapping_disk(reiserfs_blocknr_hint_t * hint, |
| 910 | b_blocknr_t * new_blocknrs, | 975 | b_blocknr_t * new_blocknrs, |
| 911 | b_blocknr_t start, b_blocknr_t finish, | 976 | b_blocknr_t start, |
| 912 | int min, | 977 | b_blocknr_t finish, int min, |
| 913 | int amount_needed, int prealloc_size) | 978 | int amount_needed, |
| 979 | int prealloc_size) | ||
| 914 | { | 980 | { |
| 915 | int rest = amount_needed; | 981 | int rest = amount_needed; |
| 916 | int nr_allocated; | 982 | int nr_allocated; |
| 917 | 983 | ||
| 918 | while (rest > 0 && start <= finish) { | 984 | while (rest > 0 && start <= finish) { |
| 919 | nr_allocated = scan_bitmap (hint->th, &start, finish, min, | 985 | nr_allocated = scan_bitmap(hint->th, &start, finish, min, |
| 920 | rest + prealloc_size, !hint->formatted_node, | 986 | rest + prealloc_size, |
| 921 | hint->block); | 987 | !hint->formatted_node, hint->block); |
| 922 | 988 | ||
| 923 | if (nr_allocated == 0) /* no new blocks allocated, return */ | 989 | if (nr_allocated == 0) /* no new blocks allocated, return */ |
| 924 | break; | 990 | break; |
| 925 | 991 | ||
| 926 | /* fill free_blocknrs array first */ | 992 | /* fill free_blocknrs array first */ |
| 927 | while (rest > 0 && nr_allocated > 0) { | 993 | while (rest > 0 && nr_allocated > 0) { |
| 928 | * new_blocknrs ++ = start ++; | 994 | *new_blocknrs++ = start++; |
| 929 | rest --; nr_allocated --; | 995 | rest--; |
| 930 | } | 996 | nr_allocated--; |
| 997 | } | ||
| 931 | 998 | ||
| 932 | /* do we have something to fill prealloc. array also ? */ | 999 | /* do we have something to fill prealloc. array also ? */ |
| 933 | if (nr_allocated > 0) { | 1000 | if (nr_allocated > 0) { |
| 934 | /* it means prealloc_size was greater that 0 and we do preallocation */ | 1001 | /* it means prealloc_size was greater that 0 and we do preallocation */ |
| 935 | list_add(&REISERFS_I(hint->inode)->i_prealloc_list, | 1002 | list_add(&REISERFS_I(hint->inode)->i_prealloc_list, |
| 936 | &SB_JOURNAL(hint->th->t_super)->j_prealloc_list); | 1003 | &SB_JOURNAL(hint->th->t_super)-> |
| 937 | REISERFS_I(hint->inode)->i_prealloc_block = start; | 1004 | j_prealloc_list); |
| 938 | REISERFS_I(hint->inode)->i_prealloc_count = nr_allocated; | 1005 | REISERFS_I(hint->inode)->i_prealloc_block = start; |
| 939 | break; | 1006 | REISERFS_I(hint->inode)->i_prealloc_count = |
| 1007 | nr_allocated; | ||
| 1008 | break; | ||
| 1009 | } | ||
| 940 | } | 1010 | } |
| 941 | } | ||
| 942 | 1011 | ||
| 943 | return (amount_needed - rest); | 1012 | return (amount_needed - rest); |
| 944 | } | 1013 | } |
| 945 | 1014 | ||
| 946 | static inline int blocknrs_and_prealloc_arrays_from_search_start | 1015 | static inline int blocknrs_and_prealloc_arrays_from_search_start |
| 947 | (reiserfs_blocknr_hint_t *hint, b_blocknr_t *new_blocknrs, int amount_needed) | 1016 | (reiserfs_blocknr_hint_t * hint, b_blocknr_t * new_blocknrs, |
| 948 | { | 1017 | int amount_needed) { |
| 949 | struct super_block *s = hint->th->t_super; | 1018 | struct super_block *s = hint->th->t_super; |
| 950 | b_blocknr_t start = hint->search_start; | 1019 | b_blocknr_t start = hint->search_start; |
| 951 | b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1; | 1020 | b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1; |
| 952 | int passno = 0; | 1021 | int passno = 0; |
| 953 | int nr_allocated = 0; | 1022 | int nr_allocated = 0; |
| 954 | int bigalloc = 0; | 1023 | int bigalloc = 0; |
| 955 | 1024 | ||
| 956 | determine_prealloc_size(hint); | 1025 | determine_prealloc_size(hint); |
| 957 | if (!hint->formatted_node) { | 1026 | if (!hint->formatted_node) { |
| 958 | int quota_ret; | 1027 | int quota_ret; |
| 959 | #ifdef REISERQUOTA_DEBUG | 1028 | #ifdef REISERQUOTA_DEBUG |
| 960 | reiserfs_debug (s, REISERFS_DEBUG_CODE, "reiserquota: allocating %d blocks id=%u", amount_needed, hint->inode->i_uid); | 1029 | reiserfs_debug(s, REISERFS_DEBUG_CODE, |
| 1030 | "reiserquota: allocating %d blocks id=%u", | ||
| 1031 | amount_needed, hint->inode->i_uid); | ||
| 961 | #endif | 1032 | #endif |
| 962 | quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed); | 1033 | quota_ret = |
| 963 | if (quota_ret) /* Quota exceeded? */ | 1034 | DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed); |
| 964 | return QUOTA_EXCEEDED; | 1035 | if (quota_ret) /* Quota exceeded? */ |
| 965 | if (hint->preallocate && hint->prealloc_size ) { | 1036 | return QUOTA_EXCEEDED; |
| 1037 | if (hint->preallocate && hint->prealloc_size) { | ||
| 966 | #ifdef REISERQUOTA_DEBUG | 1038 | #ifdef REISERQUOTA_DEBUG |
| 967 | reiserfs_debug (s, REISERFS_DEBUG_CODE, "reiserquota: allocating (prealloc) %d blocks id=%u", hint->prealloc_size, hint->inode->i_uid); | 1039 | reiserfs_debug(s, REISERFS_DEBUG_CODE, |
| 1040 | "reiserquota: allocating (prealloc) %d blocks id=%u", | ||
| 1041 | hint->prealloc_size, hint->inode->i_uid); | ||
| 968 | #endif | 1042 | #endif |
| 969 | quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode, hint->prealloc_size); | 1043 | quota_ret = |
| 970 | if (quota_ret) | 1044 | DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode, |
| 971 | hint->preallocate=hint->prealloc_size=0; | 1045 | hint->prealloc_size); |
| 1046 | if (quota_ret) | ||
| 1047 | hint->preallocate = hint->prealloc_size = 0; | ||
| 1048 | } | ||
| 1049 | /* for unformatted nodes, force large allocations */ | ||
| 1050 | bigalloc = amount_needed; | ||
| 972 | } | 1051 | } |
| 973 | /* for unformatted nodes, force large allocations */ | ||
| 974 | bigalloc = amount_needed; | ||
| 975 | } | ||
| 976 | 1052 | ||
| 977 | do { | 1053 | do { |
| 978 | /* in bigalloc mode, nr_allocated should stay zero until | 1054 | /* in bigalloc mode, nr_allocated should stay zero until |
| 979 | * the entire allocation is filled | 1055 | * the entire allocation is filled |
| 980 | */ | 1056 | */ |
| 981 | if (unlikely(bigalloc && nr_allocated)) { | 1057 | if (unlikely(bigalloc && nr_allocated)) { |
| 982 | reiserfs_warning(s, "bigalloc is %d, nr_allocated %d\n", | 1058 | reiserfs_warning(s, "bigalloc is %d, nr_allocated %d\n", |
| 983 | bigalloc, nr_allocated); | 1059 | bigalloc, nr_allocated); |
| 984 | /* reset things to a sane value */ | 1060 | /* reset things to a sane value */ |
| 985 | bigalloc = amount_needed - nr_allocated; | 1061 | bigalloc = amount_needed - nr_allocated; |
| 986 | } | 1062 | } |
| 987 | /* | 1063 | /* |
| 988 | * try pass 0 and pass 1 looking for a nice big | 1064 | * try pass 0 and pass 1 looking for a nice big |
| 989 | * contiguous allocation. Then reset and look | 1065 | * contiguous allocation. Then reset and look |
| 990 | * for anything you can find. | 1066 | * for anything you can find. |
| 991 | */ | 1067 | */ |
| 992 | if (passno == 2 && bigalloc) { | 1068 | if (passno == 2 && bigalloc) { |
| 993 | passno = 0; | 1069 | passno = 0; |
| 994 | bigalloc = 0; | 1070 | bigalloc = 0; |
| 995 | } | 1071 | } |
| 996 | switch (passno++) { | 1072 | switch (passno++) { |
| 997 | case 0: /* Search from hint->search_start to end of disk */ | 1073 | case 0: /* Search from hint->search_start to end of disk */ |
| 998 | start = hint->search_start; | 1074 | start = hint->search_start; |
| 999 | finish = SB_BLOCK_COUNT(s) - 1; | 1075 | finish = SB_BLOCK_COUNT(s) - 1; |
| 1000 | break; | 1076 | break; |
| 1001 | case 1: /* Search from hint->beg to hint->search_start */ | 1077 | case 1: /* Search from hint->beg to hint->search_start */ |
| 1002 | start = hint->beg; | 1078 | start = hint->beg; |
| 1003 | finish = hint->search_start; | 1079 | finish = hint->search_start; |
| 1004 | break; | 1080 | break; |
| 1005 | case 2: /* Last chance: Search from 0 to hint->beg */ | 1081 | case 2: /* Last chance: Search from 0 to hint->beg */ |
| 1006 | start = 0; | 1082 | start = 0; |
| 1007 | finish = hint->beg; | 1083 | finish = hint->beg; |
| 1008 | break; | 1084 | break; |
| 1009 | default: /* We've tried searching everywhere, not enough space */ | 1085 | default: /* We've tried searching everywhere, not enough space */ |
| 1010 | /* Free the blocks */ | 1086 | /* Free the blocks */ |
| 1011 | if (!hint->formatted_node) { | 1087 | if (!hint->formatted_node) { |
| 1012 | #ifdef REISERQUOTA_DEBUG | 1088 | #ifdef REISERQUOTA_DEBUG |
| 1013 | reiserfs_debug (s, REISERFS_DEBUG_CODE, "reiserquota: freeing (nospace) %d blocks id=%u", amount_needed + hint->prealloc_size - nr_allocated, hint->inode->i_uid); | 1089 | reiserfs_debug(s, REISERFS_DEBUG_CODE, |
| 1090 | "reiserquota: freeing (nospace) %d blocks id=%u", | ||
| 1091 | amount_needed + | ||
| 1092 | hint->prealloc_size - | ||
| 1093 | nr_allocated, | ||
| 1094 | hint->inode->i_uid); | ||
| 1014 | #endif | 1095 | #endif |
| 1015 | DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated); /* Free not allocated blocks */ | 1096 | DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated); /* Free not allocated blocks */ |
| 1016 | } | 1097 | } |
| 1017 | while (nr_allocated --) | 1098 | while (nr_allocated--) |
| 1018 | reiserfs_free_block(hint->th, hint->inode, new_blocknrs[nr_allocated], !hint->formatted_node); | 1099 | reiserfs_free_block(hint->th, hint->inode, |
| 1019 | 1100 | new_blocknrs[nr_allocated], | |
| 1020 | return NO_DISK_SPACE; | 1101 | !hint->formatted_node); |
| 1021 | } | 1102 | |
| 1022 | } while ((nr_allocated += allocate_without_wrapping_disk (hint, | 1103 | return NO_DISK_SPACE; |
| 1023 | new_blocknrs + nr_allocated, start, finish, | 1104 | } |
| 1024 | bigalloc ? bigalloc : 1, | 1105 | } while ((nr_allocated += allocate_without_wrapping_disk(hint, |
| 1025 | amount_needed - nr_allocated, | 1106 | new_blocknrs + |
| 1026 | hint->prealloc_size)) | 1107 | nr_allocated, |
| 1027 | < amount_needed); | 1108 | start, finish, |
| 1028 | if ( !hint->formatted_node && | 1109 | bigalloc ? |
| 1029 | amount_needed + hint->prealloc_size > | 1110 | bigalloc : 1, |
| 1030 | nr_allocated + REISERFS_I(hint->inode)->i_prealloc_count) { | 1111 | amount_needed - |
| 1031 | /* Some of preallocation blocks were not allocated */ | 1112 | nr_allocated, |
| 1113 | hint-> | ||
| 1114 | prealloc_size)) | ||
| 1115 | < amount_needed); | ||
| 1116 | if (!hint->formatted_node && | ||
| 1117 | amount_needed + hint->prealloc_size > | ||
| 1118 | nr_allocated + REISERFS_I(hint->inode)->i_prealloc_count) { | ||
| 1119 | /* Some of preallocation blocks were not allocated */ | ||
| 1032 | #ifdef REISERQUOTA_DEBUG | 1120 | #ifdef REISERQUOTA_DEBUG |
| 1033 | reiserfs_debug (s, REISERFS_DEBUG_CODE, "reiserquota: freeing (failed prealloc) %d blocks id=%u", amount_needed + hint->prealloc_size - nr_allocated - REISERFS_I(hint->inode)->i_prealloc_count, hint->inode->i_uid); | 1121 | reiserfs_debug(s, REISERFS_DEBUG_CODE, |
| 1122 | "reiserquota: freeing (failed prealloc) %d blocks id=%u", | ||
| 1123 | amount_needed + hint->prealloc_size - | ||
| 1124 | nr_allocated - | ||
| 1125 | REISERFS_I(hint->inode)->i_prealloc_count, | ||
| 1126 | hint->inode->i_uid); | ||
| 1034 | #endif | 1127 | #endif |
| 1035 | DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + | 1128 | DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + |
| 1036 | hint->prealloc_size - nr_allocated - | 1129 | hint->prealloc_size - nr_allocated - |
| 1037 | REISERFS_I(hint->inode)->i_prealloc_count); | 1130 | REISERFS_I(hint->inode)-> |
| 1038 | } | 1131 | i_prealloc_count); |
| 1132 | } | ||
| 1039 | 1133 | ||
| 1040 | return CARRY_ON; | 1134 | return CARRY_ON; |
| 1041 | } | 1135 | } |
| 1042 | 1136 | ||
| 1043 | /* grab new blocknrs from preallocated list */ | 1137 | /* grab new blocknrs from preallocated list */ |
| 1044 | /* return amount still needed after using them */ | 1138 | /* return amount still needed after using them */ |
| 1045 | static int use_preallocated_list_if_available (reiserfs_blocknr_hint_t *hint, | 1139 | static int use_preallocated_list_if_available(reiserfs_blocknr_hint_t * hint, |
| 1046 | b_blocknr_t *new_blocknrs, int amount_needed) | 1140 | b_blocknr_t * new_blocknrs, |
| 1141 | int amount_needed) | ||
| 1047 | { | 1142 | { |
| 1048 | struct inode * inode = hint->inode; | 1143 | struct inode *inode = hint->inode; |
| 1049 | 1144 | ||
| 1050 | if (REISERFS_I(inode)->i_prealloc_count > 0) { | 1145 | if (REISERFS_I(inode)->i_prealloc_count > 0) { |
| 1051 | while (amount_needed) { | 1146 | while (amount_needed) { |
| 1052 | 1147 | ||
| 1053 | *new_blocknrs ++ = REISERFS_I(inode)->i_prealloc_block ++; | 1148 | *new_blocknrs++ = REISERFS_I(inode)->i_prealloc_block++; |
| 1054 | REISERFS_I(inode)->i_prealloc_count --; | 1149 | REISERFS_I(inode)->i_prealloc_count--; |
| 1055 | 1150 | ||
| 1056 | amount_needed --; | 1151 | amount_needed--; |
| 1057 | 1152 | ||
| 1058 | if (REISERFS_I(inode)->i_prealloc_count <= 0) { | 1153 | if (REISERFS_I(inode)->i_prealloc_count <= 0) { |
| 1059 | list_del(&REISERFS_I(inode)->i_prealloc_list); | 1154 | list_del(&REISERFS_I(inode)->i_prealloc_list); |
| 1060 | break; | 1155 | break; |
| 1061 | } | 1156 | } |
| 1157 | } | ||
| 1062 | } | 1158 | } |
| 1063 | } | 1159 | /* return amount still needed after using preallocated blocks */ |
| 1064 | /* return amount still needed after using preallocated blocks */ | 1160 | return amount_needed; |
| 1065 | return amount_needed; | ||
| 1066 | } | 1161 | } |
| 1067 | 1162 | ||
| 1068 | int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *hint, | 1163 | 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 |
| 1069 | b_blocknr_t * new_blocknrs, int amount_needed, | 1164 | already reserved */ ) |
| 1070 | int reserved_by_us /* Amount of blocks we have | ||
| 1071 | already reserved */) | ||
| 1072 | { | 1165 | { |
| 1073 | int initial_amount_needed = amount_needed; | 1166 | int initial_amount_needed = amount_needed; |
| 1074 | int ret; | 1167 | int ret; |
| 1075 | struct super_block *s = hint->th->t_super; | 1168 | struct super_block *s = hint->th->t_super; |
| 1076 | 1169 | ||
| 1077 | /* Check if there is enough space, taking into account reserved space */ | 1170 | /* Check if there is enough space, taking into account reserved space */ |
| 1078 | if ( SB_FREE_BLOCKS(s) - REISERFS_SB(s)->reserved_blocks < | 1171 | if (SB_FREE_BLOCKS(s) - REISERFS_SB(s)->reserved_blocks < |
| 1079 | amount_needed - reserved_by_us) | 1172 | amount_needed - reserved_by_us) |
| 1080 | return NO_DISK_SPACE; | 1173 | return NO_DISK_SPACE; |
| 1081 | /* should this be if !hint->inode && hint->preallocate? */ | 1174 | /* should this be if !hint->inode && hint->preallocate? */ |
| 1082 | /* do you mean hint->formatted_node can be removed ? - Zam */ | 1175 | /* do you mean hint->formatted_node can be removed ? - Zam */ |
| 1083 | /* hint->formatted_node cannot be removed because we try to access | 1176 | /* hint->formatted_node cannot be removed because we try to access |
| 1084 | inode information here, and there is often no inode assotiated with | 1177 | inode information here, and there is often no inode assotiated with |
| 1085 | metadata allocations - green */ | 1178 | metadata allocations - green */ |
| 1086 | 1179 | ||
| 1087 | if (!hint->formatted_node && hint->preallocate) { | 1180 | if (!hint->formatted_node && hint->preallocate) { |
| 1088 | amount_needed = use_preallocated_list_if_available | 1181 | amount_needed = use_preallocated_list_if_available |
| 1182 | (hint, new_blocknrs, amount_needed); | ||
| 1183 | if (amount_needed == 0) /* all blocknrs we need we got from | ||
| 1184 | prealloc. list */ | ||
| 1185 | return CARRY_ON; | ||
| 1186 | new_blocknrs += (initial_amount_needed - amount_needed); | ||
| 1187 | } | ||
| 1188 | |||
| 1189 | /* find search start and save it in hint structure */ | ||
| 1190 | determine_search_start(hint, amount_needed); | ||
| 1191 | if (hint->search_start >= SB_BLOCK_COUNT(s)) | ||
| 1192 | hint->search_start = SB_BLOCK_COUNT(s) - 1; | ||
| 1193 | |||
| 1194 | /* allocation itself; fill new_blocknrs and preallocation arrays */ | ||
| 1195 | ret = blocknrs_and_prealloc_arrays_from_search_start | ||
| 1089 | (hint, new_blocknrs, amount_needed); | 1196 | (hint, new_blocknrs, amount_needed); |
| 1090 | if (amount_needed == 0) /* all blocknrs we need we got from | 1197 | |
| 1091 | prealloc. list */ | 1198 | /* we used prealloc. list to fill (partially) new_blocknrs array. If final allocation fails we |
| 1092 | return CARRY_ON; | 1199 | * need to return blocks back to prealloc. list or just free them. -- Zam (I chose second |
| 1093 | new_blocknrs += (initial_amount_needed - amount_needed); | 1200 | * variant) */ |
| 1094 | } | 1201 | |
| 1095 | 1202 | if (ret != CARRY_ON) { | |
| 1096 | /* find search start and save it in hint structure */ | 1203 | while (amount_needed++ < initial_amount_needed) { |
| 1097 | determine_search_start(hint, amount_needed); | 1204 | reiserfs_free_block(hint->th, hint->inode, |
| 1098 | if (hint->search_start >= SB_BLOCK_COUNT(s)) | 1205 | *(--new_blocknrs), 1); |
| 1099 | hint->search_start = SB_BLOCK_COUNT(s) - 1; | 1206 | } |
| 1100 | |||
| 1101 | /* allocation itself; fill new_blocknrs and preallocation arrays */ | ||
| 1102 | ret = blocknrs_and_prealloc_arrays_from_search_start | ||
| 1103 | (hint, new_blocknrs, amount_needed); | ||
| 1104 | |||
| 1105 | /* we used prealloc. list to fill (partially) new_blocknrs array. If final allocation fails we | ||
| 1106 | * need to return blocks back to prealloc. list or just free them. -- Zam (I chose second | ||
| 1107 | * variant) */ | ||
| 1108 | |||
| 1109 | if (ret != CARRY_ON) { | ||
| 1110 | while (amount_needed ++ < initial_amount_needed) { | ||
| 1111 | reiserfs_free_block(hint->th, hint->inode, *(--new_blocknrs), 1); | ||
| 1112 | } | 1207 | } |
| 1113 | } | 1208 | return ret; |
| 1114 | return ret; | ||
| 1115 | } | 1209 | } |
| 1116 | 1210 | ||
| 1117 | /* These 2 functions are here to provide blocks reservation to the rest of kernel */ | 1211 | /* These 2 functions are here to provide blocks reservation to the rest of kernel */ |
| 1118 | /* Reserve @blocks amount of blocks in fs pointed by @sb. Caller must make sure | 1212 | /* Reserve @blocks amount of blocks in fs pointed by @sb. Caller must make sure |
| 1119 | there are actually this much blocks on the FS available */ | 1213 | there are actually this much blocks on the FS available */ |
| 1120 | void reiserfs_claim_blocks_to_be_allocated( | 1214 | void reiserfs_claim_blocks_to_be_allocated(struct super_block *sb, /* super block of |
| 1121 | struct super_block *sb, /* super block of | 1215 | filesystem where |
| 1122 | filesystem where | 1216 | blocks should be |
| 1123 | blocks should be | 1217 | reserved */ |
| 1124 | reserved */ | 1218 | int blocks /* How much to reserve */ |
| 1125 | int blocks /* How much to reserve */ | 1219 | ) |
| 1126 | ) | ||
| 1127 | { | 1220 | { |
| 1128 | 1221 | ||
| 1129 | /* Fast case, if reservation is zero - exit immediately. */ | 1222 | /* Fast case, if reservation is zero - exit immediately. */ |
| 1130 | if ( !blocks ) | 1223 | if (!blocks) |
| 1131 | return; | 1224 | return; |
| 1132 | 1225 | ||
| 1133 | spin_lock(&REISERFS_SB(sb)->bitmap_lock); | 1226 | spin_lock(&REISERFS_SB(sb)->bitmap_lock); |
| 1134 | REISERFS_SB(sb)->reserved_blocks += blocks; | 1227 | REISERFS_SB(sb)->reserved_blocks += blocks; |
| 1135 | spin_unlock(&REISERFS_SB(sb)->bitmap_lock); | 1228 | spin_unlock(&REISERFS_SB(sb)->bitmap_lock); |
| 1136 | } | 1229 | } |
| 1137 | 1230 | ||
| 1138 | /* Unreserve @blocks amount of blocks in fs pointed by @sb */ | 1231 | /* Unreserve @blocks amount of blocks in fs pointed by @sb */ |
| 1139 | void reiserfs_release_claimed_blocks( | 1232 | void reiserfs_release_claimed_blocks(struct super_block *sb, /* super block of |
| 1140 | struct super_block *sb, /* super block of | 1233 | filesystem where |
| 1141 | filesystem where | 1234 | blocks should be |
| 1142 | blocks should be | 1235 | reserved */ |
| 1143 | reserved */ | 1236 | int blocks /* How much to unreserve */ |
| 1144 | int blocks /* How much to unreserve */ | 1237 | ) |
| 1145 | ) | ||
| 1146 | { | 1238 | { |
| 1147 | 1239 | ||
| 1148 | /* Fast case, if unreservation is zero - exit immediately. */ | 1240 | /* Fast case, if unreservation is zero - exit immediately. */ |
| 1149 | if ( !blocks ) | 1241 | if (!blocks) |
| 1150 | return; | 1242 | return; |
| 1151 | 1243 | ||
| 1152 | spin_lock(&REISERFS_SB(sb)->bitmap_lock); | 1244 | spin_lock(&REISERFS_SB(sb)->bitmap_lock); |
| 1153 | REISERFS_SB(sb)->reserved_blocks -= blocks; | 1245 | REISERFS_SB(sb)->reserved_blocks -= blocks; |
| 1154 | spin_unlock(&REISERFS_SB(sb)->bitmap_lock); | 1246 | spin_unlock(&REISERFS_SB(sb)->bitmap_lock); |
| 1155 | RFALSE( REISERFS_SB(sb)->reserved_blocks < 0, "amount of blocks reserved became zero?"); | 1247 | RFALSE(REISERFS_SB(sb)->reserved_blocks < 0, |
| 1248 | "amount of blocks reserved became zero?"); | ||
| 1156 | } | 1249 | } |
| 1157 | 1250 | ||
| 1158 | /* This function estimates how much pages we will be able to write to FS | 1251 | /* This function estimates how much pages we will be able to write to FS |
| 1159 | used for reiserfs_file_write() purposes for now. */ | 1252 | used for reiserfs_file_write() purposes for now. */ |
| 1160 | int reiserfs_can_fit_pages ( struct super_block *sb /* superblock of filesystem | 1253 | int reiserfs_can_fit_pages(struct super_block *sb /* superblock of filesystem |
| 1161 | to estimate space */ ) | 1254 | to estimate space */ ) |
| 1162 | { | 1255 | { |
| 1163 | int space; | 1256 | int space; |
| 1164 | 1257 | ||
| 1165 | spin_lock(&REISERFS_SB(sb)->bitmap_lock); | 1258 | spin_lock(&REISERFS_SB(sb)->bitmap_lock); |
| 1166 | space = (SB_FREE_BLOCKS(sb) - REISERFS_SB(sb)->reserved_blocks) >> ( PAGE_CACHE_SHIFT - sb->s_blocksize_bits); | 1259 | space = |
| 1260 | (SB_FREE_BLOCKS(sb) - | ||
| 1261 | REISERFS_SB(sb)->reserved_blocks) >> (PAGE_CACHE_SHIFT - | ||
| 1262 | sb->s_blocksize_bits); | ||
| 1167 | spin_unlock(&REISERFS_SB(sb)->bitmap_lock); | 1263 | spin_unlock(&REISERFS_SB(sb)->bitmap_lock); |
| 1168 | 1264 | ||
| 1169 | return space>0?space:0; | 1265 | return space > 0 ? space : 0; |
| 1170 | } | 1266 | } |
