*/
 #define MIN_WRITEBACK_PAGES    (4096UL >> (PAGE_CACHE_SHIFT - 10))
 
+struct wb_completion {
+       atomic_t                cnt;
+};
+
 /*
  * Passed into wb_writeback(), essentially a subset of writeback_control
  */
        enum wb_reason reason;          /* why was writeback initiated? */
 
        struct list_head list;          /* pending work list */
-       struct completion *done;        /* set if the caller waits */
+       struct wb_completion *done;     /* set if the caller waits */
 };
 
+/*
+ * If one wants to wait for one or more wb_writeback_works, each work's
+ * ->done should be set to a wb_completion defined using the following
+ * macro.  Once all work items are issued with wb_queue_work(), the caller
+ * can wait for the completion of all using wb_wait_for_completion().  Work
+ * items which are waited upon aren't freed automatically on completion.
+ */
+#define DEFINE_WB_COMPLETION_ONSTACK(cmpl)                             \
+       struct wb_completion cmpl = {                                   \
+               .cnt            = ATOMIC_INIT(1),                       \
+       }
+
+
 /*
  * If an inode is constantly having its pages dirtied, but then the
  * updates stop dirtytime_expire_interval seconds in the past, it's
        trace_writeback_queue(wb->bdi, work);
 
        spin_lock_bh(&wb->work_lock);
-       if (!test_bit(WB_registered, &wb->state)) {
-               if (work->done)
-                       complete(work->done);
+       if (!test_bit(WB_registered, &wb->state))
                goto out_unlock;
-       }
+       if (work->done)
+               atomic_inc(&work->done->cnt);
        list_add_tail(&work->list, &wb->work_list);
        mod_delayed_work(bdi_wq, &wb->dwork, 0);
 out_unlock:
        spin_unlock_bh(&wb->work_lock);
 }
 
+/**
+ * wb_wait_for_completion - wait for completion of bdi_writeback_works
+ * @bdi: bdi work items were issued to
+ * @done: target wb_completion
+ *
+ * Wait for one or more work items issued to @bdi with their ->done field
+ * set to @done, which should have been defined with
+ * DEFINE_WB_COMPLETION_ONSTACK().  This function returns after all such
+ * work items are completed.  Work items which are waited upon aren't freed
+ * automatically on completion.
+ */
+static void wb_wait_for_completion(struct backing_dev_info *bdi,
+                                  struct wb_completion *done)
+{
+       atomic_dec(&done->cnt);         /* put down the initial count */
+       wait_event(bdi->wb_waitq, !atomic_read(&done->cnt));
+}
+
 #ifdef CONFIG_CGROUP_WRITEBACK
 
 /**
 
        set_bit(WB_writeback_running, &wb->state);
        while ((work = get_next_work_item(wb)) != NULL) {
-               struct completion *done = work->done;
+               struct wb_completion *done = work->done;
 
                trace_writeback_exec(wb->bdi, work);
 
 
                if (work->auto_free)
                        kfree(work);
-               if (done)
-                       complete(done);
+               if (done && atomic_dec_and_test(&done->cnt))
+                       wake_up_all(&wb->bdi->wb_waitq);
        }
 
        /*
                            unsigned long nr,
                            enum wb_reason reason)
 {
-       DECLARE_COMPLETION_ONSTACK(done);
+       DEFINE_WB_COMPLETION_ONSTACK(done);
        struct wb_writeback_work work = {
                .sb                     = sb,
                .sync_mode              = WB_SYNC_NONE,
                return;
        WARN_ON(!rwsem_is_locked(&sb->s_umount));
        wb_queue_work(&bdi->wb, &work);
-       wait_for_completion(&done);
+       wb_wait_for_completion(bdi, &done);
 }
 EXPORT_SYMBOL(writeback_inodes_sb_nr);
 
  */
 void sync_inodes_sb(struct super_block *sb)
 {
-       DECLARE_COMPLETION_ONSTACK(done);
+       DEFINE_WB_COMPLETION_ONSTACK(done);
        struct wb_writeback_work work = {
                .sb             = sb,
                .sync_mode      = WB_SYNC_ALL,
        WARN_ON(!rwsem_is_locked(&sb->s_umount));
 
        wb_queue_work(&bdi->wb, &work);
-       wait_for_completion(&done);
+       wb_wait_for_completion(bdi, &done);
 
        wait_sb_inodes(sb);
 }