Merge branch 'paul' (Fixups from Paul Gortmaker)
[linux-flexiantxendom0-3.2.10.git] / kernel / res_counter.c
index 88faec2..d508363 100644 (file)
@@ -10,7 +10,6 @@
 #include <linux/types.h>
 #include <linux/parser.h>
 #include <linux/fs.h>
-#include <linux/slab.h>
 #include <linux/res_counter.h>
 #include <linux/uaccess.h>
 #include <linux/mm.h>
@@ -37,27 +36,17 @@ int res_counter_charge_locked(struct res_counter *counter, unsigned long val)
 }
 
 int res_counter_charge(struct res_counter *counter, unsigned long val,
-                       struct res_counter **limit_fail_at,
-                       struct res_counter **soft_limit_fail_at)
+                       struct res_counter **limit_fail_at)
 {
        int ret;
        unsigned long flags;
        struct res_counter *c, *u;
 
        *limit_fail_at = NULL;
-       if (soft_limit_fail_at)
-               *soft_limit_fail_at = NULL;
        local_irq_save(flags);
        for (c = counter; c != NULL; c = c->parent) {
                spin_lock(&c->lock);
                ret = res_counter_charge_locked(c, val);
-               /*
-                * With soft limits, we return the highest ancestor
-                * that exceeds its soft limit
-                */
-               if (soft_limit_fail_at &&
-                       !res_counter_soft_limit_check_locked(c))
-                       *soft_limit_fail_at = c;
                spin_unlock(&c->lock);
                if (ret < 0) {
                        *limit_fail_at = c;
@@ -77,6 +66,31 @@ done:
        return ret;
 }
 
+int res_counter_charge_nofail(struct res_counter *counter, unsigned long val,
+                             struct res_counter **limit_fail_at)
+{
+       int ret, r;
+       unsigned long flags;
+       struct res_counter *c;
+
+       r = ret = 0;
+       *limit_fail_at = NULL;
+       local_irq_save(flags);
+       for (c = counter; c != NULL; c = c->parent) {
+               spin_lock(&c->lock);
+               r = res_counter_charge_locked(c, val);
+               if (r)
+                       c->usage += val;
+               spin_unlock(&c->lock);
+               if (r < 0 && ret == 0) {
+                       *limit_fail_at = c;
+                       ret = r;
+               }
+       }
+       local_irq_restore(flags);
+
+       return ret;
+}
 void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val)
 {
        if (WARN_ON(counter->usage < val))
@@ -85,8 +99,7 @@ void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val)
        counter->usage -= val;
 }
 
-void res_counter_uncharge(struct res_counter *counter, unsigned long val,
-                               bool *was_soft_limit_excess)
+void res_counter_uncharge(struct res_counter *counter, unsigned long val)
 {
        unsigned long flags;
        struct res_counter *c;
@@ -94,9 +107,6 @@ void res_counter_uncharge(struct res_counter *counter, unsigned long val,
        local_irq_save(flags);
        for (c = counter; c != NULL; c = c->parent) {
                spin_lock(&c->lock);
-               if (was_soft_limit_excess)
-                       *was_soft_limit_excess =
-                               !res_counter_soft_limit_check_locked(c);
                res_counter_uncharge_locked(c, val);
                spin_unlock(&c->lock);
        }
@@ -141,10 +151,24 @@ ssize_t res_counter_read(struct res_counter *counter, int member,
                        pos, buf, s - buf);
 }
 
+#if BITS_PER_LONG == 32
+u64 res_counter_read_u64(struct res_counter *counter, int member)
+{
+       unsigned long flags;
+       u64 ret;
+
+       spin_lock_irqsave(&counter->lock, flags);
+       ret = *res_counter_member(counter, member);
+       spin_unlock_irqrestore(&counter->lock, flags);
+
+       return ret;
+}
+#else
 u64 res_counter_read_u64(struct res_counter *counter, int member)
 {
        return *res_counter_member(counter, member);
 }
+#endif
 
 int res_counter_memparse_write_strategy(const char *buf,
                                        unsigned long long *res)
@@ -160,8 +184,7 @@ int res_counter_memparse_write_strategy(const char *buf,
                return 0;
        }
 
-       /* FIXME - make memparse() take const char* args */
-       *res = memparse((char *)buf, &end);
+       *res = memparse(buf, &end);
        if (*end != '\0')
                return -EINVAL;