Skip to contentSkip to conversation

percpu_counter: use correct API

PATCH In review Shaohua Li 2 participants 2 messages Apr 12, 2011 ext4 file system

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 2/4 percpu_counter: use correct API

percpu_counter_sum_positive never returns negative, since there is a negative check, I changed it to percpu_counter_sum.

---
 fs/ext4/balloc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/balloc.c +1 -1
Index: linux/fs/ext4/balloc.c
===================================================================
@@ -506,7 +506,7 @@ static int ext4_has_free_blocks(struct e
 	if (free_blocks - (nblocks + root_blocks + dirty_blocks) <
 						EXT4_FREEBLOCKS_WATERMARK) {
 		free_blocks  = percpu_counter_sum_positive(fbc);
-		dirty_blocks = percpu_counter_sum_positive(dbc);
+		dirty_blocks = percpu_counter_sum(dbc);
 		if (dirty_blocks < 0) {
 			printk(KERN_CRIT "Dirty block accounting "
 					"went wrong %lld\n",
#1 lore raw
Quoted 14 lines · Shaohua Li

percpu_counter_sum_positive never returns negative, since there is a negative check, I changed it to percpu_counter_sum.

---
 fs/ext4/balloc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/fs/ext4/balloc.c
===================================================================

fs/ext4/balloc.c static int ext4_has_free_blocks(struct e · line 512

Quoted 8 lines
fs/ext4/balloc.c +1 -1
@@ -506,7 +506,7 @@ static int ext4_has_free_blocks(struct e
 	if (free_blocks - (nblocks + root_blocks + dirty_blocks) <
 						EXT4_FREEBLOCKS_WATERMARK) {
 		free_blocks  = percpu_counter_sum_positive(fbc);
-		dirty_blocks = percpu_counter_sum_positive(dbc);
+		dirty_blocks = percpu_counter_sum(dbc);
 		if (dirty_blocks < 0) {
 			printk(KERN_CRIT "Dirty block accounting "
 					"went wrong %lld\n",

The right thing to do would be removing if (dirty_blocks < 0) and keep using _positive. perpcu_counter_sum() may return a negative number spuriously (that's the whole point of _positive functions) and may trigger the critial error path when nothing is really wrong.

Thanks.

Signature · 1 line
tejun