diff options
Diffstat (limited to 'kernel/res_counter.c')
-rw-r--r-- | kernel/res_counter.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/kernel/res_counter.c b/kernel/res_counter.c index 6d269cce7aa1..d508363858b3 100644 --- a/kernel/res_counter.c +++ b/kernel/res_counter.c | |||
@@ -66,6 +66,31 @@ done: | |||
66 | return ret; | 66 | return ret; |
67 | } | 67 | } |
68 | 68 | ||
69 | int res_counter_charge_nofail(struct res_counter *counter, unsigned long val, | ||
70 | struct res_counter **limit_fail_at) | ||
71 | { | ||
72 | int ret, r; | ||
73 | unsigned long flags; | ||
74 | struct res_counter *c; | ||
75 | |||
76 | r = ret = 0; | ||
77 | *limit_fail_at = NULL; | ||
78 | local_irq_save(flags); | ||
79 | for (c = counter; c != NULL; c = c->parent) { | ||
80 | spin_lock(&c->lock); | ||
81 | r = res_counter_charge_locked(c, val); | ||
82 | if (r) | ||
83 | c->usage += val; | ||
84 | spin_unlock(&c->lock); | ||
85 | if (r < 0 && ret == 0) { | ||
86 | *limit_fail_at = c; | ||
87 | ret = r; | ||
88 | } | ||
89 | } | ||
90 | local_irq_restore(flags); | ||
91 | |||
92 | return ret; | ||
93 | } | ||
69 | void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val) | 94 | void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val) |
70 | { | 95 | { |
71 | if (WARN_ON(counter->usage < val)) | 96 | if (WARN_ON(counter->usage < val)) |