diff options
Diffstat (limited to 'fs/ext4/balloc.c')
-rw-r--r-- | fs/ext4/balloc.c | 66 |
1 files changed, 51 insertions, 15 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index cf1821784a16..d0f13eada0ed 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c | |||
@@ -30,6 +30,23 @@ static unsigned ext4_num_base_meta_clusters(struct super_block *sb, | |||
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * Calculate block group number for a given block number | ||
34 | */ | ||
35 | ext4_group_t ext4_get_group_number(struct super_block *sb, | ||
36 | ext4_fsblk_t block) | ||
37 | { | ||
38 | ext4_group_t group; | ||
39 | |||
40 | if (test_opt2(sb, STD_GROUP_SIZE)) | ||
41 | group = (le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) + | ||
42 | block) >> | ||
43 | (EXT4_BLOCK_SIZE_BITS(sb) + EXT4_CLUSTER_BITS(sb) + 3); | ||
44 | else | ||
45 | ext4_get_group_no_and_offset(sb, block, &group, NULL); | ||
46 | return group; | ||
47 | } | ||
48 | |||
49 | /* | ||
33 | * Calculate the block group number and offset into the block/cluster | 50 | * Calculate the block group number and offset into the block/cluster |
34 | * allocation bitmap, given a block number | 51 | * allocation bitmap, given a block number |
35 | */ | 52 | */ |
@@ -49,14 +66,18 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr, | |||
49 | 66 | ||
50 | } | 67 | } |
51 | 68 | ||
52 | static int ext4_block_in_group(struct super_block *sb, ext4_fsblk_t block, | 69 | /* |
53 | ext4_group_t block_group) | 70 | * Check whether the 'block' lives within the 'block_group'. Returns 1 if so |
71 | * and 0 otherwise. | ||
72 | */ | ||
73 | static inline int ext4_block_in_group(struct super_block *sb, | ||
74 | ext4_fsblk_t block, | ||
75 | ext4_group_t block_group) | ||
54 | { | 76 | { |
55 | ext4_group_t actual_group; | 77 | ext4_group_t actual_group; |
56 | ext4_get_group_no_and_offset(sb, block, &actual_group, NULL); | 78 | |
57 | if (actual_group == block_group) | 79 | actual_group = ext4_get_group_number(sb, block); |
58 | return 1; | 80 | return (actual_group == block_group) ? 1 : 0; |
59 | return 0; | ||
60 | } | 81 | } |
61 | 82 | ||
62 | /* Return the number of clusters used for file system metadata; this | 83 | /* Return the number of clusters used for file system metadata; this |
@@ -358,7 +379,7 @@ void ext4_validate_block_bitmap(struct super_block *sb, | |||
358 | } | 379 | } |
359 | 380 | ||
360 | /** | 381 | /** |
361 | * ext4_read_block_bitmap() | 382 | * ext4_read_block_bitmap_nowait() |
362 | * @sb: super block | 383 | * @sb: super block |
363 | * @block_group: given block group | 384 | * @block_group: given block group |
364 | * | 385 | * |
@@ -420,7 +441,7 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group) | |||
420 | trace_ext4_read_block_bitmap_load(sb, block_group); | 441 | trace_ext4_read_block_bitmap_load(sb, block_group); |
421 | bh->b_end_io = ext4_end_bitmap_read; | 442 | bh->b_end_io = ext4_end_bitmap_read; |
422 | get_bh(bh); | 443 | get_bh(bh); |
423 | submit_bh(READ, bh); | 444 | submit_bh(READ | REQ_META | REQ_PRIO, bh); |
424 | return bh; | 445 | return bh; |
425 | verify: | 446 | verify: |
426 | ext4_validate_block_bitmap(sb, desc, block_group, bh); | 447 | ext4_validate_block_bitmap(sb, desc, block_group, bh); |
@@ -457,6 +478,8 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group) | |||
457 | struct buffer_head *bh; | 478 | struct buffer_head *bh; |
458 | 479 | ||
459 | bh = ext4_read_block_bitmap_nowait(sb, block_group); | 480 | bh = ext4_read_block_bitmap_nowait(sb, block_group); |
481 | if (!bh) | ||
482 | return NULL; | ||
460 | if (ext4_wait_block_bitmap(sb, block_group, bh)) { | 483 | if (ext4_wait_block_bitmap(sb, block_group, bh)) { |
461 | put_bh(bh); | 484 | put_bh(bh); |
462 | return NULL; | 485 | return NULL; |
@@ -476,31 +499,44 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group) | |||
476 | static int ext4_has_free_clusters(struct ext4_sb_info *sbi, | 499 | static int ext4_has_free_clusters(struct ext4_sb_info *sbi, |
477 | s64 nclusters, unsigned int flags) | 500 | s64 nclusters, unsigned int flags) |
478 | { | 501 | { |
479 | s64 free_clusters, dirty_clusters, root_clusters; | 502 | s64 free_clusters, dirty_clusters, rsv, resv_clusters; |
480 | struct percpu_counter *fcc = &sbi->s_freeclusters_counter; | 503 | struct percpu_counter *fcc = &sbi->s_freeclusters_counter; |
481 | struct percpu_counter *dcc = &sbi->s_dirtyclusters_counter; | 504 | struct percpu_counter *dcc = &sbi->s_dirtyclusters_counter; |
482 | 505 | ||
483 | free_clusters = percpu_counter_read_positive(fcc); | 506 | free_clusters = percpu_counter_read_positive(fcc); |
484 | dirty_clusters = percpu_counter_read_positive(dcc); | 507 | dirty_clusters = percpu_counter_read_positive(dcc); |
485 | root_clusters = EXT4_B2C(sbi, ext4_r_blocks_count(sbi->s_es)); | 508 | resv_clusters = atomic64_read(&sbi->s_resv_clusters); |
486 | 509 | ||
487 | if (free_clusters - (nclusters + root_clusters + dirty_clusters) < | 510 | /* |
511 | * r_blocks_count should always be multiple of the cluster ratio so | ||
512 | * we are safe to do a plane bit shift only. | ||
513 | */ | ||
514 | rsv = (ext4_r_blocks_count(sbi->s_es) >> sbi->s_cluster_bits) + | ||
515 | resv_clusters; | ||
516 | |||
517 | if (free_clusters - (nclusters + rsv + dirty_clusters) < | ||
488 | EXT4_FREECLUSTERS_WATERMARK) { | 518 | EXT4_FREECLUSTERS_WATERMARK) { |
489 | free_clusters = EXT4_C2B(sbi, percpu_counter_sum_positive(fcc)); | 519 | free_clusters = percpu_counter_sum_positive(fcc); |
490 | dirty_clusters = percpu_counter_sum_positive(dcc); | 520 | dirty_clusters = percpu_counter_sum_positive(dcc); |
491 | } | 521 | } |
492 | /* Check whether we have space after accounting for current | 522 | /* Check whether we have space after accounting for current |
493 | * dirty clusters & root reserved clusters. | 523 | * dirty clusters & root reserved clusters. |
494 | */ | 524 | */ |
495 | if (free_clusters >= ((root_clusters + nclusters) + dirty_clusters)) | 525 | if (free_clusters >= (rsv + nclusters + dirty_clusters)) |
496 | return 1; | 526 | return 1; |
497 | 527 | ||
498 | /* Hm, nope. Are (enough) root reserved clusters available? */ | 528 | /* Hm, nope. Are (enough) root reserved clusters available? */ |
499 | if (uid_eq(sbi->s_resuid, current_fsuid()) || | 529 | if (uid_eq(sbi->s_resuid, current_fsuid()) || |
500 | (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) || | 530 | (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) || |
501 | capable(CAP_SYS_RESOURCE) || | 531 | capable(CAP_SYS_RESOURCE) || |
502 | (flags & EXT4_MB_USE_ROOT_BLOCKS)) { | 532 | (flags & EXT4_MB_USE_ROOT_BLOCKS)) { |
503 | 533 | ||
534 | if (free_clusters >= (nclusters + dirty_clusters + | ||
535 | resv_clusters)) | ||
536 | return 1; | ||
537 | } | ||
538 | /* No free blocks. Let's see if we can dip into reserved pool */ | ||
539 | if (flags & EXT4_MB_USE_RESERVED) { | ||
504 | if (free_clusters >= (nclusters + dirty_clusters)) | 540 | if (free_clusters >= (nclusters + dirty_clusters)) |
505 | return 1; | 541 | return 1; |
506 | } | 542 | } |
@@ -628,7 +664,7 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb) | |||
628 | brelse(bitmap_bh); | 664 | brelse(bitmap_bh); |
629 | printk(KERN_DEBUG "ext4_count_free_clusters: stored = %llu" | 665 | printk(KERN_DEBUG "ext4_count_free_clusters: stored = %llu" |
630 | ", computed = %llu, %llu\n", | 666 | ", computed = %llu, %llu\n", |
631 | EXT4_B2C(EXT4_SB(sb), ext4_free_blocks_count(es)), | 667 | EXT4_NUM_B2C(EXT4_SB(sb), ext4_free_blocks_count(es)), |
632 | desc_count, bitmap_count); | 668 | desc_count, bitmap_count); |
633 | return bitmap_count; | 669 | return bitmap_count; |
634 | #else | 670 | #else |