writeback: fix possible race when creating bdi threads
[deliverable/linux.git] / mm / backing-dev.c
index 4e9ed2a8521fe15b99cfa7fd3387cec33be8791b..327e36d1d623ab14aafe2f6716b296c88c4a9823 100644 (file)
@@ -331,8 +331,8 @@ static int bdi_forker_thread(void *ptr)
        set_user_nice(current, 0);
 
        for (;;) {
+               struct task_struct *task;
                struct backing_dev_info *bdi, *tmp;
-               struct bdi_writeback *wb;
 
                /*
                 * Temporary measure, we want to make sure we don't see
@@ -383,29 +383,23 @@ static int bdi_forker_thread(void *ptr)
                list_del_init(&bdi->bdi_list);
                spin_unlock_bh(&bdi_lock);
 
-               wb = &bdi->wb;
-               wb->task = kthread_run(bdi_writeback_thread, wb, "flush-%s",
-                                       dev_name(bdi->dev));
-               /*
-                * If thread creation fails, then readd the bdi to
-                * the pending list and force writeout of the bdi
-                * from this forker thread. That will free some memory
-                * and we can try again.
-                */
-               if (IS_ERR(wb->task)) {
-                       wb->task = NULL;
-
+               task = kthread_run(bdi_writeback_thread, &bdi->wb, "flush-%s",
+                                  dev_name(bdi->dev));
+               if (IS_ERR(task)) {
                        /*
-                        * Add this 'bdi' to the back, so we get
-                        * a chance to flush other bdi's to free
-                        * memory.
+                        * If thread creation fails, then readd the bdi back to
+                        * the list and force writeout of the bdi from this
+                        * forker thread. That will free some memory and we can
+                        * try again. Add it to the tail so we get a chance to
+                        * flush other bdi's to free memory.
                         */
                        spin_lock_bh(&bdi_lock);
                        list_add_tail(&bdi->bdi_list, &bdi_pending_list);
                        spin_unlock_bh(&bdi_lock);
 
                        bdi_flush_io(bdi);
-               }
+               } else
+                       bdi->wb.task = task;
        }
 
        return 0;
This page took 0.038341 seconds and 5 git commands to generate.