diff options
author | Amir Goldstein <amir73il@users.sf.net> | 2011-05-09 10:46:41 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2011-05-09 10:46:41 -0400 |
commit | 2846e82004a8d5ef0a63cd3209c84ea5cd796f11 (patch) | |
tree | 3b20c08ce64e918d4217bb95228fc597c63bf0e0 /fs/ext4/balloc.c | |
parent | 66bb82798d9ff896271d13f5020f7fb9b7d88e1a (diff) |
ext4: move ext4_add_groupblocks() to mballoc.c
In preparation for the next patch, the function ext4_add_groupblocks()
is moved to mballoc.c, where it could use some static functions.
Signed-off-by: Amir Goldstein <amir73il@users.sf.net>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/balloc.c')
-rw-r--r-- | fs/ext4/balloc.c | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index 9c6cd51c09e3..b2d10da505ef 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c | |||
@@ -362,130 +362,6 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group) | |||
362 | } | 362 | } |
363 | 363 | ||
364 | /** | 364 | /** |
365 | * ext4_add_groupblocks() -- Add given blocks to an existing group | ||
366 | * @handle: handle to this transaction | ||
367 | * @sb: super block | ||
368 | * @block: start physcial block to add to the block group | ||
369 | * @count: number of blocks to free | ||
370 | * | ||
371 | * This marks the blocks as free in the bitmap. We ask the | ||
372 | * mballoc to reload the buddy after this by setting group | ||
373 | * EXT4_GROUP_INFO_NEED_INIT_BIT flag | ||
374 | */ | ||
375 | void ext4_add_groupblocks(handle_t *handle, struct super_block *sb, | ||
376 | ext4_fsblk_t block, unsigned long count) | ||
377 | { | ||
378 | struct buffer_head *bitmap_bh = NULL; | ||
379 | struct buffer_head *gd_bh; | ||
380 | ext4_group_t block_group; | ||
381 | ext4_grpblk_t bit; | ||
382 | unsigned int i; | ||
383 | struct ext4_group_desc *desc; | ||
384 | struct ext4_sb_info *sbi = EXT4_SB(sb); | ||
385 | int err = 0, ret, blk_free_count; | ||
386 | ext4_grpblk_t blocks_freed; | ||
387 | struct ext4_group_info *grp; | ||
388 | |||
389 | ext4_debug("Adding block(s) %llu-%llu\n", block, block + count - 1); | ||
390 | |||
391 | ext4_get_group_no_and_offset(sb, block, &block_group, &bit); | ||
392 | grp = ext4_get_group_info(sb, block_group); | ||
393 | /* | ||
394 | * Check to see if we are freeing blocks across a group | ||
395 | * boundary. | ||
396 | */ | ||
397 | if (bit + count > EXT4_BLOCKS_PER_GROUP(sb)) { | ||
398 | goto error_return; | ||
399 | } | ||
400 | bitmap_bh = ext4_read_block_bitmap(sb, block_group); | ||
401 | if (!bitmap_bh) | ||
402 | goto error_return; | ||
403 | desc = ext4_get_group_desc(sb, block_group, &gd_bh); | ||
404 | if (!desc) | ||
405 | goto error_return; | ||
406 | |||
407 | if (in_range(ext4_block_bitmap(sb, desc), block, count) || | ||
408 | in_range(ext4_inode_bitmap(sb, desc), block, count) || | ||
409 | in_range(block, ext4_inode_table(sb, desc), sbi->s_itb_per_group) || | ||
410 | in_range(block + count - 1, ext4_inode_table(sb, desc), | ||
411 | sbi->s_itb_per_group)) { | ||
412 | ext4_error(sb, "Adding blocks in system zones - " | ||
413 | "Block = %llu, count = %lu", | ||
414 | block, count); | ||
415 | goto error_return; | ||
416 | } | ||
417 | |||
418 | /* | ||
419 | * We are about to add blocks to the bitmap, | ||
420 | * so we need undo access. | ||
421 | */ | ||
422 | BUFFER_TRACE(bitmap_bh, "getting undo access"); | ||
423 | err = ext4_journal_get_undo_access(handle, bitmap_bh); | ||
424 | if (err) | ||
425 | goto error_return; | ||
426 | |||
427 | /* | ||
428 | * We are about to modify some metadata. Call the journal APIs | ||
429 | * to unshare ->b_data if a currently-committing transaction is | ||
430 | * using it | ||
431 | */ | ||
432 | BUFFER_TRACE(gd_bh, "get_write_access"); | ||
433 | err = ext4_journal_get_write_access(handle, gd_bh); | ||
434 | if (err) | ||
435 | goto error_return; | ||
436 | /* | ||
437 | * make sure we don't allow a parallel init on other groups in the | ||
438 | * same buddy cache | ||
439 | */ | ||
440 | down_write(&grp->alloc_sem); | ||
441 | for (i = 0, blocks_freed = 0; i < count; i++) { | ||
442 | BUFFER_TRACE(bitmap_bh, "clear bit"); | ||
443 | if (!ext4_clear_bit_atomic(ext4_group_lock_ptr(sb, block_group), | ||
444 | bit + i, bitmap_bh->b_data)) { | ||
445 | ext4_error(sb, "bit already cleared for block %llu", | ||
446 | (ext4_fsblk_t)(block + i)); | ||
447 | BUFFER_TRACE(bitmap_bh, "bit already cleared"); | ||
448 | } else { | ||
449 | blocks_freed++; | ||
450 | } | ||
451 | } | ||
452 | ext4_lock_group(sb, block_group); | ||
453 | blk_free_count = blocks_freed + ext4_free_blks_count(sb, desc); | ||
454 | ext4_free_blks_set(sb, desc, blk_free_count); | ||
455 | desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc); | ||
456 | ext4_unlock_group(sb, block_group); | ||
457 | percpu_counter_add(&sbi->s_freeblocks_counter, blocks_freed); | ||
458 | |||
459 | if (sbi->s_log_groups_per_flex) { | ||
460 | ext4_group_t flex_group = ext4_flex_group(sbi, block_group); | ||
461 | atomic_add(blocks_freed, | ||
462 | &sbi->s_flex_groups[flex_group].free_blocks); | ||
463 | } | ||
464 | /* | ||
465 | * request to reload the buddy with the | ||
466 | * new bitmap information | ||
467 | */ | ||
468 | set_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &(grp->bb_state)); | ||
469 | grp->bb_free += blocks_freed; | ||
470 | up_write(&grp->alloc_sem); | ||
471 | |||
472 | /* We dirtied the bitmap block */ | ||
473 | BUFFER_TRACE(bitmap_bh, "dirtied bitmap block"); | ||
474 | err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh); | ||
475 | |||
476 | /* And the group descriptor block */ | ||
477 | BUFFER_TRACE(gd_bh, "dirtied group descriptor block"); | ||
478 | ret = ext4_handle_dirty_metadata(handle, NULL, gd_bh); | ||
479 | if (!err) | ||
480 | err = ret; | ||
481 | |||
482 | error_return: | ||
483 | brelse(bitmap_bh); | ||
484 | ext4_std_error(sb, err); | ||
485 | return; | ||
486 | } | ||
487 | |||
488 | /** | ||
489 | * ext4_has_free_blocks() | 365 | * ext4_has_free_blocks() |
490 | * @sbi: in-core super block structure. | 366 | * @sbi: in-core super block structure. |
491 | * @nblocks: number of needed blocks | 367 | * @nblocks: number of needed blocks |