Merge tag 'armsoc-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[linux-2.6-block.git] / mm / backing-dev.c
index 2e5d3df0853d928021cba0e30c70ff682afeaf68..8a8bb8796c6c43cb711c0f618c488df188853623 100644 (file)
@@ -438,10 +438,10 @@ retry:
        if (new_congested) {
                /* !found and storage for new one already allocated, insert */
                congested = new_congested;
-               new_congested = NULL;
                rb_link_node(&congested->rb_node, parent, node);
                rb_insert_color(&congested->rb_node, &bdi->cgwb_congested_tree);
-               goto found;
+               spin_unlock_irqrestore(&cgwb_lock, flags);
+               return congested;
        }
 
        spin_unlock_irqrestore(&cgwb_lock, flags);
@@ -451,13 +451,13 @@ retry:
        if (!new_congested)
                return NULL;
 
-       atomic_set(&new_congested->refcnt, 0);
+       refcount_set(&new_congested->refcnt, 1);
        new_congested->__bdi = bdi;
        new_congested->blkcg_id = blkcg_id;
        goto retry;
 
 found:
-       atomic_inc(&congested->refcnt);
+       refcount_inc(&congested->refcnt);
        spin_unlock_irqrestore(&cgwb_lock, flags);
        kfree(new_congested);
        return congested;
@@ -473,11 +473,8 @@ void wb_congested_put(struct bdi_writeback_congested *congested)
 {
        unsigned long flags;
 
-       local_irq_save(flags);
-       if (!atomic_dec_and_lock(&congested->refcnt, &cgwb_lock)) {
-               local_irq_restore(flags);
+       if (!refcount_dec_and_lock_irqsave(&congested->refcnt, &cgwb_lock, &flags))
                return;
-       }
 
        /* bdi might already have been destroyed leaving @congested unlinked */
        if (congested->__bdi) {
@@ -494,6 +491,7 @@ static void cgwb_release_workfn(struct work_struct *work)
 {
        struct bdi_writeback *wb = container_of(work, struct bdi_writeback,
                                                release_work);
+       struct blkcg *blkcg = css_to_blkcg(wb->blkcg_css);
 
        mutex_lock(&wb->bdi->cgwb_release_mutex);
        wb_shutdown(wb);
@@ -502,6 +500,9 @@ static void cgwb_release_workfn(struct work_struct *work)
        css_put(wb->blkcg_css);
        mutex_unlock(&wb->bdi->cgwb_release_mutex);
 
+       /* triggers blkg destruction if cgwb_refcnt becomes zero */
+       blkcg_cgwb_put(blkcg);
+
        fprop_local_destroy_percpu(&wb->memcg_completions);
        percpu_ref_exit(&wb->refcnt);
        wb_exit(wb);
@@ -600,6 +601,7 @@ static int cgwb_create(struct backing_dev_info *bdi,
                        list_add_tail_rcu(&wb->bdi_node, &bdi->wb_list);
                        list_add(&wb->memcg_node, memcg_cgwb_list);
                        list_add(&wb->blkcg_node, blkcg_cgwb_list);
+                       blkcg_cgwb_get(blkcg);
                        css_get(memcg_css);
                        css_get(blkcg_css);
                }
@@ -804,7 +806,7 @@ static int cgwb_bdi_init(struct backing_dev_info *bdi)
        if (!bdi->wb_congested)
                return -ENOMEM;
 
-       atomic_set(&bdi->wb_congested->refcnt, 1);
+       refcount_set(&bdi->wb_congested->refcnt, 1);
 
        err = wb_init(&bdi->wb, bdi, 1, GFP_KERNEL);
        if (err) {