diff options
Diffstat (limited to 'include/linux/res_counter.h')
-rw-r--r-- | include/linux/res_counter.h | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index 6d9e1fca098c..fdeadd9740dc 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h | |||
@@ -63,9 +63,14 @@ u64 res_counter_read_u64(struct res_counter *counter, int member); | |||
63 | ssize_t res_counter_read(struct res_counter *counter, int member, | 63 | ssize_t res_counter_read(struct res_counter *counter, int member, |
64 | const char __user *buf, size_t nbytes, loff_t *pos, | 64 | const char __user *buf, size_t nbytes, loff_t *pos, |
65 | int (*read_strategy)(unsigned long long val, char *s)); | 65 | int (*read_strategy)(unsigned long long val, char *s)); |
66 | ssize_t res_counter_write(struct res_counter *counter, int member, | 66 | |
67 | const char __user *buf, size_t nbytes, loff_t *pos, | 67 | typedef int (*write_strategy_fn)(const char *buf, unsigned long long *val); |
68 | int (*write_strategy)(char *buf, unsigned long long *val)); | 68 | |
69 | int res_counter_memparse_write_strategy(const char *buf, | ||
70 | unsigned long long *res); | ||
71 | |||
72 | int res_counter_write(struct res_counter *counter, int member, | ||
73 | const char *buffer, write_strategy_fn write_strategy); | ||
69 | 74 | ||
70 | /* | 75 | /* |
71 | * the field descriptors. one for each member of res_counter | 76 | * the field descriptors. one for each member of res_counter |
@@ -95,8 +100,10 @@ void res_counter_init(struct res_counter *counter); | |||
95 | * counter->limit _locked call expects the counter->lock to be taken | 100 | * counter->limit _locked call expects the counter->lock to be taken |
96 | */ | 101 | */ |
97 | 102 | ||
98 | int res_counter_charge_locked(struct res_counter *counter, unsigned long val); | 103 | int __must_check res_counter_charge_locked(struct res_counter *counter, |
99 | int res_counter_charge(struct res_counter *counter, unsigned long val); | 104 | unsigned long val); |
105 | int __must_check res_counter_charge(struct res_counter *counter, | ||
106 | unsigned long val); | ||
100 | 107 | ||
101 | /* | 108 | /* |
102 | * uncharge - tell that some portion of the resource is released | 109 | * uncharge - tell that some portion of the resource is released |
@@ -151,4 +158,20 @@ static inline void res_counter_reset_failcnt(struct res_counter *cnt) | |||
151 | cnt->failcnt = 0; | 158 | cnt->failcnt = 0; |
152 | spin_unlock_irqrestore(&cnt->lock, flags); | 159 | spin_unlock_irqrestore(&cnt->lock, flags); |
153 | } | 160 | } |
161 | |||
162 | static inline int res_counter_set_limit(struct res_counter *cnt, | ||
163 | unsigned long long limit) | ||
164 | { | ||
165 | unsigned long flags; | ||
166 | int ret = -EBUSY; | ||
167 | |||
168 | spin_lock_irqsave(&cnt->lock, flags); | ||
169 | if (cnt->usage < limit) { | ||
170 | cnt->limit = limit; | ||
171 | ret = 0; | ||
172 | } | ||
173 | spin_unlock_irqrestore(&cnt->lock, flags); | ||
174 | return ret; | ||
175 | } | ||
176 | |||
154 | #endif | 177 | #endif |