diff options
author | Theodore Ts'o <tytso@mit.edu> | 2011-09-09 19:16:51 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2011-09-09 19:16:51 -0400 |
commit | df55c99dc8ee4c3c886a5edc8a4aa6b131c95afc (patch) | |
tree | 6e5ea5a435659fa2dee7410f0b0196bdaf3a2054 | |
parent | e7d5f3156e6827970f75ab27ad7eb0155826eb0b (diff) |
ext4: rename ext4_has_free_blocks() to ext4_has_free_clusters()
Rename the function so it is more clear what is going on. Also rename
the various variables so it's clearer what's happening.
Also fix a missing blocks to cluster conversion when reading the
number of reserved blocks for root.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r-- | fs/ext4/balloc.c | 43 | ||||
-rw-r--r-- | fs/ext4/ext4.h | 8 | ||||
-rw-r--r-- | fs/ext4/inode.c | 2 |
3 files changed, 27 insertions, 26 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index af0c5357e35a..f6dba4505f1c 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c | |||
@@ -403,42 +403,43 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group) | |||
403 | } | 403 | } |
404 | 404 | ||
405 | /** | 405 | /** |
406 | * ext4_has_free_blocks() | 406 | * ext4_has_free_clusters() |
407 | * @sbi: in-core super block structure. | 407 | * @sbi: in-core super block structure. |
408 | * @nblocks: number of needed blocks | 408 | * @nclusters: number of needed blocks |
409 | * @flags: flags from ext4_mb_new_blocks() | ||
409 | * | 410 | * |
410 | * Check if filesystem has nblocks free & available for allocation. | 411 | * Check if filesystem has nclusters free & available for allocation. |
411 | * On success return 1, return 0 on failure. | 412 | * On success return 1, return 0 on failure. |
412 | */ | 413 | */ |
413 | static int ext4_has_free_blocks(struct ext4_sb_info *sbi, | 414 | static int ext4_has_free_clusters(struct ext4_sb_info *sbi, |
414 | s64 nblocks, unsigned int flags) | 415 | s64 nclusters, unsigned int flags) |
415 | { | 416 | { |
416 | s64 free_blocks, dirty_blocks, root_blocks; | 417 | s64 free_clusters, dirty_clusters, root_clusters; |
417 | struct percpu_counter *fcc = &sbi->s_freeclusters_counter; | 418 | struct percpu_counter *fcc = &sbi->s_freeclusters_counter; |
418 | struct percpu_counter *dbc = &sbi->s_dirtyclusters_counter; | 419 | struct percpu_counter *dcc = &sbi->s_dirtyclusters_counter; |
419 | 420 | ||
420 | free_blocks = percpu_counter_read_positive(fcc); | 421 | free_clusters = percpu_counter_read_positive(fcc); |
421 | dirty_blocks = percpu_counter_read_positive(dbc); | 422 | dirty_clusters = percpu_counter_read_positive(dcc); |
422 | root_blocks = ext4_r_blocks_count(sbi->s_es); | 423 | root_clusters = EXT4_B2C(sbi, ext4_r_blocks_count(sbi->s_es)); |
423 | 424 | ||
424 | if (free_blocks - (nblocks + root_blocks + dirty_blocks) < | 425 | if (free_clusters - (nclusters + root_clusters + dirty_clusters) < |
425 | EXT4_FREEBLOCKS_WATERMARK) { | 426 | EXT4_FREECLUSTERS_WATERMARK) { |
426 | free_blocks = EXT4_C2B(sbi, percpu_counter_sum_positive(fcc)); | 427 | free_clusters = EXT4_C2B(sbi, percpu_counter_sum_positive(fcc)); |
427 | dirty_blocks = percpu_counter_sum_positive(dbc); | 428 | dirty_clusters = percpu_counter_sum_positive(dcc); |
428 | } | 429 | } |
429 | /* Check whether we have space after | 430 | /* Check whether we have space after accounting for current |
430 | * accounting for current dirty blocks & root reserved blocks. | 431 | * dirty clusters & root reserved clusters. |
431 | */ | 432 | */ |
432 | if (free_blocks >= ((root_blocks + nblocks) + dirty_blocks)) | 433 | if (free_clusters >= ((root_clusters + nclusters) + dirty_clusters)) |
433 | return 1; | 434 | return 1; |
434 | 435 | ||
435 | /* Hm, nope. Are (enough) root reserved blocks available? */ | 436 | /* Hm, nope. Are (enough) root reserved clusters available? */ |
436 | if (sbi->s_resuid == current_fsuid() || | 437 | if (sbi->s_resuid == current_fsuid() || |
437 | ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) || | 438 | ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) || |
438 | capable(CAP_SYS_RESOURCE) || | 439 | capable(CAP_SYS_RESOURCE) || |
439 | (flags & EXT4_MB_USE_ROOT_BLOCKS)) { | 440 | (flags & EXT4_MB_USE_ROOT_BLOCKS)) { |
440 | 441 | ||
441 | if (free_blocks >= (nblocks + dirty_blocks)) | 442 | if (free_clusters >= (nclusters + dirty_clusters)) |
442 | return 1; | 443 | return 1; |
443 | } | 444 | } |
444 | 445 | ||
@@ -448,7 +449,7 @@ static int ext4_has_free_blocks(struct ext4_sb_info *sbi, | |||
448 | int ext4_claim_free_clusters(struct ext4_sb_info *sbi, | 449 | int ext4_claim_free_clusters(struct ext4_sb_info *sbi, |
449 | s64 nclusters, unsigned int flags) | 450 | s64 nclusters, unsigned int flags) |
450 | { | 451 | { |
451 | if (ext4_has_free_blocks(sbi, nclusters, flags)) { | 452 | if (ext4_has_free_clusters(sbi, nclusters, flags)) { |
452 | percpu_counter_add(&sbi->s_dirtyclusters_counter, nclusters); | 453 | percpu_counter_add(&sbi->s_dirtyclusters_counter, nclusters); |
453 | return 0; | 454 | return 0; |
454 | } else | 455 | } else |
@@ -469,7 +470,7 @@ int ext4_claim_free_clusters(struct ext4_sb_info *sbi, | |||
469 | */ | 470 | */ |
470 | int ext4_should_retry_alloc(struct super_block *sb, int *retries) | 471 | int ext4_should_retry_alloc(struct super_block *sb, int *retries) |
471 | { | 472 | { |
472 | if (!ext4_has_free_blocks(EXT4_SB(sb), 1, 0) || | 473 | if (!ext4_has_free_clusters(EXT4_SB(sb), 1, 0) || |
473 | (*retries)++ > 3 || | 474 | (*retries)++ > 3 || |
474 | !EXT4_SB(sb)->s_journal) | 475 | !EXT4_SB(sb)->s_journal) |
475 | return 0; | 476 | return 0; |
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index f97638634e34..21ea65d8bd46 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -2103,13 +2103,13 @@ do { \ | |||
2103 | } while (0) | 2103 | } while (0) |
2104 | 2104 | ||
2105 | #ifdef CONFIG_SMP | 2105 | #ifdef CONFIG_SMP |
2106 | /* Each CPU can accumulate percpu_counter_batch blocks in their local | 2106 | /* Each CPU can accumulate percpu_counter_batch clusters in their local |
2107 | * counters. So we need to make sure we have free blocks more | 2107 | * counters. So we need to make sure we have free clusters more |
2108 | * than percpu_counter_batch * nr_cpu_ids. Also add a window of 4 times. | 2108 | * than percpu_counter_batch * nr_cpu_ids. Also add a window of 4 times. |
2109 | */ | 2109 | */ |
2110 | #define EXT4_FREEBLOCKS_WATERMARK (4 * (percpu_counter_batch * nr_cpu_ids)) | 2110 | #define EXT4_FREECLUSTERS_WATERMARK (4 * (percpu_counter_batch * nr_cpu_ids)) |
2111 | #else | 2111 | #else |
2112 | #define EXT4_FREEBLOCKS_WATERMARK 0 | 2112 | #define EXT4_FREECLUSTERS_WATERMARK 0 |
2113 | #endif | 2113 | #endif |
2114 | 2114 | ||
2115 | static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize) | 2115 | static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize) |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 557c34ffa05b..88dc63a01756 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -2255,7 +2255,7 @@ static int ext4_nonda_switch(struct super_block *sb) | |||
2255 | percpu_counter_read_positive(&sbi->s_freeclusters_counter)); | 2255 | percpu_counter_read_positive(&sbi->s_freeclusters_counter)); |
2256 | dirty_blocks = percpu_counter_read_positive(&sbi->s_dirtyclusters_counter); | 2256 | dirty_blocks = percpu_counter_read_positive(&sbi->s_dirtyclusters_counter); |
2257 | if (2 * free_blocks < 3 * dirty_blocks || | 2257 | if (2 * free_blocks < 3 * dirty_blocks || |
2258 | free_blocks < (dirty_blocks + EXT4_FREEBLOCKS_WATERMARK)) { | 2258 | free_blocks < (dirty_blocks + EXT4_FREECLUSTERS_WATERMARK)) { |
2259 | /* | 2259 | /* |
2260 | * free block count is less than 150% of dirty blocks | 2260 | * free block count is less than 150% of dirty blocks |
2261 | * or free blocks is less than watermark | 2261 | * or free blocks is less than watermark |