ALSA: ice1724 - Fix ESI Maya44 capture source control
[safe/jmp/linux-2.6] / block / blk-cgroup.c
index 4ef78d3..2cc682b 100644 (file)
 #include <linux/ioprio.h>
 #include <linux/seq_file.h>
 #include <linux/kdev_t.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/slab.h>
 #include "blk-cgroup.h"
 
-extern void cfq_unlink_blkio_group(void *, struct blkio_group *);
+static DEFINE_SPINLOCK(blkio_list_lock);
+static LIST_HEAD(blkio_list);
 
 struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
+EXPORT_SYMBOL_GPL(blkio_root_cgroup);
+
+static struct cgroup_subsys_state *blkiocg_create(struct cgroup_subsys *,
+                                                 struct cgroup *);
+static int blkiocg_can_attach(struct cgroup_subsys *, struct cgroup *,
+                             struct task_struct *, bool);
+static void blkiocg_attach(struct cgroup_subsys *, struct cgroup *,
+                          struct cgroup *, struct task_struct *, bool);
+static void blkiocg_destroy(struct cgroup_subsys *, struct cgroup *);
+static int blkiocg_populate(struct cgroup_subsys *, struct cgroup *);
+
+struct cgroup_subsys blkio_subsys = {
+       .name = "blkio",
+       .create = blkiocg_create,
+       .can_attach = blkiocg_can_attach,
+       .attach = blkiocg_attach,
+       .destroy = blkiocg_destroy,
+       .populate = blkiocg_populate,
+#ifdef CONFIG_BLK_CGROUP
+       /* note: blkio_subsys_id is otherwise defined in blk-cgroup.h */
+       .subsys_id = blkio_subsys_id,
+#endif
+       .use_id = 1,
+       .module = THIS_MODULE,
+};
+EXPORT_SYMBOL_GPL(blkio_subsys);
 
 struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)
 {
        return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id),
                            struct blkio_cgroup, css);
 }
+EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup);
 
 void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
                        unsigned long time, unsigned long sectors)
@@ -31,6 +62,7 @@ void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
        blkg->time += time;
        blkg->sectors += sectors;
 }
+EXPORT_SYMBOL_GPL(blkiocg_update_blkio_group_stats);
 
 void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
                        struct blkio_group *blkg, void *key, dev_t dev)
@@ -48,6 +80,7 @@ void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
 #endif
        blkg->dev = dev;
 }
+EXPORT_SYMBOL_GPL(blkiocg_add_blkio_group);
 
 static void __blkiocg_del_blkio_group(struct blkio_group *blkg)
 {
@@ -82,6 +115,7 @@ out:
        rcu_read_unlock();
        return ret;
 }
+EXPORT_SYMBOL_GPL(blkiocg_del_blkio_group);
 
 /* called under rcu_read_lock(). */
 struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key)
@@ -98,6 +132,7 @@ struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key)
 
        return NULL;
 }
+EXPORT_SYMBOL_GPL(blkiocg_lookup_group);
 
 #define SHOW_FUNCTION(__VAR)                                           \
 static u64 blkiocg_##__VAR##_read(struct cgroup *cgroup,               \
@@ -116,12 +151,24 @@ static int
 blkiocg_weight_write(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 {
        struct blkio_cgroup *blkcg;
+       struct blkio_group *blkg;
+       struct hlist_node *n;
+       struct blkio_policy_type *blkiop;
 
        if (val < BLKIO_WEIGHT_MIN || val > BLKIO_WEIGHT_MAX)
                return -EINVAL;
 
        blkcg = cgroup_to_blkio_cgroup(cgroup);
+       spin_lock(&blkio_list_lock);
+       spin_lock_irq(&blkcg->lock);
        blkcg->weight = (unsigned int)val;
+       hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
+               list_for_each_entry(blkiop, &blkio_list, list)
+                       blkiop->ops.blkio_update_group_weight_fn(blkg,
+                                       blkcg->weight);
+       }
+       spin_unlock_irq(&blkcg->lock);
+       spin_unlock(&blkio_list_lock);
        return 0;
 }
 
@@ -161,6 +208,7 @@ void blkiocg_update_blkio_group_dequeue_stats(struct blkio_group *blkg,
 {
        blkg->dequeue += dequeue;
 }
+EXPORT_SYMBOL_GPL(blkiocg_update_blkio_group_dequeue_stats);
 #endif
 
 struct cftype blkio_files[] = {
@@ -197,6 +245,7 @@ static void blkiocg_destroy(struct cgroup_subsys *subsys, struct cgroup *cgroup)
        unsigned long flags;
        struct blkio_group *blkg;
        void *key;
+       struct blkio_policy_type *blkiop;
 
        rcu_read_lock();
 remove_entry:
@@ -222,27 +271,31 @@ remove_entry:
         * we have more policies in place, we need some dynamic registration
         * of callback function.
         */
-       cfq_unlink_blkio_group(key, blkg);
+       spin_lock(&blkio_list_lock);
+       list_for_each_entry(blkiop, &blkio_list, list)
+               blkiop->ops.blkio_unlink_group_fn(key, blkg);
+       spin_unlock(&blkio_list_lock);
        goto remove_entry;
 done:
        free_css_id(&blkio_subsys, &blkcg->css);
        rcu_read_unlock();
-       kfree(blkcg);
+       if (blkcg != &blkio_root_cgroup)
+               kfree(blkcg);
 }
 
 static struct cgroup_subsys_state *
 blkiocg_create(struct cgroup_subsys *subsys, struct cgroup *cgroup)
 {
-       struct blkio_cgroup *blkcg, *parent_blkcg;
+       struct blkio_cgroup *blkcg;
+       struct cgroup *parent = cgroup->parent;
 
-       if (!cgroup->parent) {
+       if (!parent) {
                blkcg = &blkio_root_cgroup;
                goto done;
        }
 
        /* Currently we do not support hierarchy deeper than two level (0,1) */
-       parent_blkcg = cgroup_to_blkio_cgroup(cgroup->parent);
-       if (css_depth(&parent_blkcg->css) > 0)
+       if (parent != cgroup->top_cgroup)
                return ERR_PTR(-EINVAL);
 
        blkcg = kzalloc(sizeof(*blkcg), GFP_KERNEL);
@@ -293,13 +346,32 @@ static void blkiocg_attach(struct cgroup_subsys *subsys, struct cgroup *cgroup,
        task_unlock(tsk);
 }
 
-struct cgroup_subsys blkio_subsys = {
-       .name = "blkio",
-       .create = blkiocg_create,
-       .can_attach = blkiocg_can_attach,
-       .attach = blkiocg_attach,
-       .destroy = blkiocg_destroy,
-       .populate = blkiocg_populate,
-       .subsys_id = blkio_subsys_id,
-       .use_id = 1,
-};
+void blkio_policy_register(struct blkio_policy_type *blkiop)
+{
+       spin_lock(&blkio_list_lock);
+       list_add_tail(&blkiop->list, &blkio_list);
+       spin_unlock(&blkio_list_lock);
+}
+EXPORT_SYMBOL_GPL(blkio_policy_register);
+
+void blkio_policy_unregister(struct blkio_policy_type *blkiop)
+{
+       spin_lock(&blkio_list_lock);
+       list_del_init(&blkiop->list);
+       spin_unlock(&blkio_list_lock);
+}
+EXPORT_SYMBOL_GPL(blkio_policy_unregister);
+
+static int __init init_cgroup_blkio(void)
+{
+       return cgroup_load_subsys(&blkio_subsys);
+}
+
+static void __exit exit_cgroup_blkio(void)
+{
+       cgroup_unload_subsys(&blkio_subsys);
+}
+
+module_init(init_cgroup_blkio);
+module_exit(exit_cgroup_blkio);
+MODULE_LICENSE("GPL");