diff options
Diffstat (limited to 'include/linux/res_counter.h')
-rw-r--r-- | include/linux/res_counter.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index c9d625ca659e..da81af086eaf 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h | |||
@@ -109,12 +109,18 @@ void res_counter_init(struct res_counter *counter, struct res_counter *parent); | |||
109 | * | 109 | * |
110 | * returns 0 on success and <0 if the counter->usage will exceed the | 110 | * returns 0 on success and <0 if the counter->usage will exceed the |
111 | * counter->limit _locked call expects the counter->lock to be taken | 111 | * counter->limit _locked call expects the counter->lock to be taken |
112 | * | ||
113 | * charge_nofail works the same, except that it charges the resource | ||
114 | * counter unconditionally, and returns < 0 if the after the current | ||
115 | * charge we are over limit. | ||
112 | */ | 116 | */ |
113 | 117 | ||
114 | int __must_check res_counter_charge_locked(struct res_counter *counter, | 118 | int __must_check res_counter_charge_locked(struct res_counter *counter, |
115 | unsigned long val); | 119 | unsigned long val); |
116 | int __must_check res_counter_charge(struct res_counter *counter, | 120 | int __must_check res_counter_charge(struct res_counter *counter, |
117 | unsigned long val, struct res_counter **limit_fail_at); | 121 | unsigned long val, struct res_counter **limit_fail_at); |
122 | int __must_check res_counter_charge_nofail(struct res_counter *counter, | ||
123 | unsigned long val, struct res_counter **limit_fail_at); | ||
118 | 124 | ||
119 | /* | 125 | /* |
120 | * uncharge - tell that some portion of the resource is released | 126 | * uncharge - tell that some portion of the resource is released |
@@ -142,7 +148,10 @@ static inline unsigned long long res_counter_margin(struct res_counter *cnt) | |||
142 | unsigned long flags; | 148 | unsigned long flags; |
143 | 149 | ||
144 | spin_lock_irqsave(&cnt->lock, flags); | 150 | spin_lock_irqsave(&cnt->lock, flags); |
145 | margin = cnt->limit - cnt->usage; | 151 | if (cnt->limit > cnt->usage) |
152 | margin = cnt->limit - cnt->usage; | ||
153 | else | ||
154 | margin = 0; | ||
146 | spin_unlock_irqrestore(&cnt->lock, flags); | 155 | spin_unlock_irqrestore(&cnt->lock, flags); |
147 | return margin; | 156 | return margin; |
148 | } | 157 | } |