cleanup __writeback_single_inode
[pandora-kernel.git] / fs / fs-writeback.c
index 91013ff..c54226b 100644 (file)
@@ -64,6 +64,28 @@ static void writeback_release(struct backing_dev_info *bdi)
        clear_bit(BDI_pdflush, &bdi->state);
 }
 
+static noinline void block_dump___mark_inode_dirty(struct inode *inode)
+{
+       if (inode->i_ino || strcmp(inode->i_sb->s_id, "bdev")) {
+               struct dentry *dentry;
+               const char *name = "?";
+
+               dentry = d_find_alias(inode);
+               if (dentry) {
+                       spin_lock(&dentry->d_lock);
+                       name = (const char *) dentry->d_name.name;
+               }
+               printk(KERN_DEBUG
+                      "%s(%d): dirtied inode %lu (%s) on %s\n",
+                      current->comm, task_pid_nr(current), inode->i_ino,
+                      name, inode->i_sb->s_id);
+               if (dentry) {
+                       spin_unlock(&dentry->d_lock);
+                       dput(dentry);
+               }
+       }
+}
+
 /**
  *     __mark_inode_dirty -    internal function
  *     @inode: inode to mark
@@ -114,23 +136,8 @@ void __mark_inode_dirty(struct inode *inode, int flags)
        if ((inode->i_state & flags) == flags)
                return;
 
-       if (unlikely(block_dump)) {
-               struct dentry *dentry = NULL;
-               const char *name = "?";
-
-               if (!list_empty(&inode->i_dentry)) {
-                       dentry = list_entry(inode->i_dentry.next,
-                                           struct dentry, d_alias);
-                       if (dentry && dentry->d_name.name)
-                               name = (const char *) dentry->d_name.name;
-               }
-
-               if (inode->i_ino || strcmp(inode->i_sb->s_id, "bdev"))
-                       printk(KERN_DEBUG
-                              "%s(%d): dirtied inode %lu (%s) on %s\n",
-                              current->comm, task_pid_nr(current), inode->i_ino,
-                              name, inode->i_sb->s_id);
-       }
+       if (unlikely(block_dump))
+               block_dump___mark_inode_dirty(inode);
 
        spin_lock(&inode_lock);
        if ((inode->i_state & flags) != flags) {
@@ -271,7 +278,26 @@ int sb_has_dirty_inodes(struct super_block *sb)
 EXPORT_SYMBOL(sb_has_dirty_inodes);
 
 /*
- * Write a single inode's dirty pages and inode data out to disk.
+ * Wait for writeback on an inode to complete.
+ */
+static void inode_wait_for_writeback(struct inode *inode)
+{
+       DEFINE_WAIT_BIT(wq, &inode->i_state, __I_SYNC);
+       wait_queue_head_t *wqh;
+
+       wqh = bit_waitqueue(&inode->i_state, __I_SYNC);
+       do {
+               spin_unlock(&inode_lock);
+               __wait_on_bit(wqh, &wq, inode_wait, TASK_UNINTERRUPTIBLE);
+               spin_lock(&inode_lock);
+       } while (inode->i_state & I_SYNC);
+}
+
+/*
+ * Write out an inode's dirty pages.  Called under inode_lock.  Either the
+ * caller has ref on the inode (either via __iget or via syscall against an fd)
+ * or the inode has I_WILL_FREE set (via generic_forget_inode)
+ *
  * If `wait' is set, wait on the writeout.
  *
  * The whole writeout design is quite complex and fragile.  We want to avoid
@@ -281,15 +307,39 @@ EXPORT_SYMBOL(sb_has_dirty_inodes);
  * Called under inode_lock.
  */
 static int
-__sync_single_inode(struct inode *inode, struct writeback_control *wbc)
+writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
 {
-       unsigned dirty;
        struct address_space *mapping = inode->i_mapping;
        int wait = wbc->sync_mode == WB_SYNC_ALL;
+       unsigned dirty;
        int ret;
 
+       if (!atomic_read(&inode->i_count))
+               WARN_ON(!(inode->i_state & (I_WILL_FREE|I_FREEING)));
+       else
+               WARN_ON(inode->i_state & I_WILL_FREE);
+
+       if (inode->i_state & I_SYNC) {
+               /*
+                * If this inode is locked for writeback and we are not doing
+                * writeback-for-data-integrity, move it to s_more_io so that
+                * writeback can proceed with the other inodes on s_io.
+                *
+                * We'll have another go at writing back this inode when we
+                * completed a full scan of s_io.
+                */
+               if (!wait) {
+                       requeue_io(inode);
+                       return 0;
+               }
+
+               /*
+                * It's a data-integrity sync.  We must wait.
+                */
+               inode_wait_for_writeback(inode);
+       }
+
        BUG_ON(inode->i_state & I_SYNC);
-       WARN_ON(inode->i_state & I_NEW);
 
        /* Set I_SYNC, reset I_DIRTY */
        dirty = inode->i_state & I_DIRTY;
@@ -314,9 +364,8 @@ __sync_single_inode(struct inode *inode, struct writeback_control *wbc)
        }
 
        spin_lock(&inode_lock);
-       WARN_ON(inode->i_state & I_NEW);
        inode->i_state &= ~I_SYNC;
-       if (!(inode->i_state & I_FREEING)) {
+       if (!(inode->i_state & (I_FREEING | I_CLEAR))) {
                if (!(inode->i_state & I_DIRTY) &&
                    mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
                        /*
@@ -384,50 +433,6 @@ __sync_single_inode(struct inode *inode, struct writeback_control *wbc)
        return ret;
 }
 
-/*
- * Write out an inode's dirty pages.  Called under inode_lock.  Either the
- * caller has ref on the inode (either via __iget or via syscall against an fd)
- * or the inode has I_WILL_FREE set (via generic_forget_inode)
- */
-static int
-__writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
-{
-       wait_queue_head_t *wqh;
-
-       if (!atomic_read(&inode->i_count))
-               WARN_ON(!(inode->i_state & (I_WILL_FREE|I_FREEING)));
-       else
-               WARN_ON(inode->i_state & I_WILL_FREE);
-
-       if ((wbc->sync_mode != WB_SYNC_ALL) && (inode->i_state & I_SYNC)) {
-               /*
-                * We're skipping this inode because it's locked, and we're not
-                * doing writeback-for-data-integrity.  Move it to s_more_io so
-                * that writeback can proceed with the other inodes on s_io.
-                * We'll have another go at writing back this inode when we
-                * completed a full scan of s_io.
-                */
-               requeue_io(inode);
-               return 0;
-       }
-
-       /*
-        * It's a data-integrity sync.  We must wait.
-        */
-       if (inode->i_state & I_SYNC) {
-               DEFINE_WAIT_BIT(wq, &inode->i_state, __I_SYNC);
-
-               wqh = bit_waitqueue(&inode->i_state, __I_SYNC);
-               do {
-                       spin_unlock(&inode_lock);
-                       __wait_on_bit(wqh, &wq, inode_wait,
-                                                       TASK_UNINTERRUPTIBLE);
-                       spin_lock(&inode_lock);
-               } while (inode->i_state & I_SYNC);
-       }
-       return __sync_single_inode(inode, wbc);
-}
-
 /*
  * Write out a superblock's list of dirty inodes.  A wait will be performed
  * upon no inodes, all inodes or the final one, depending upon sync_mode.
@@ -487,7 +492,7 @@ void generic_sync_sb_inodes(struct super_block *sb,
                        break;
                }
 
-               if (inode->i_state & I_NEW) {
+               if (inode->i_state & (I_NEW | I_WILL_FREE)) {
                        requeue_io(inode);
                        continue;
                }
@@ -518,10 +523,10 @@ void generic_sync_sb_inodes(struct super_block *sb,
                if (current_is_pdflush() && !writeback_acquire(bdi))
                        break;
 
-               BUG_ON(inode->i_state & I_FREEING);
+               BUG_ON(inode->i_state & (I_FREEING | I_CLEAR));
                __iget(inode);
                pages_skipped = wbc->pages_skipped;
-               __writeback_single_inode(inode, wbc);
+               writeback_single_inode(inode, wbc);
                if (current_is_pdflush())
                        writeback_release(bdi);
                if (wbc->pages_skipped != pages_skipped) {
@@ -678,55 +683,6 @@ void sync_inodes_sb(struct super_block *sb, int wait)
        sync_sb_inodes(sb, &wbc);
 }
 
-/**
- * sync_inodes - writes all inodes to disk
- * @wait: wait for completion
- *
- * sync_inodes() goes through each super block's dirty inode list, writes the
- * inodes out, waits on the writeout and puts the inodes back on the normal
- * list.
- *
- * This is for sys_sync().  fsync_dev() uses the same algorithm.  The subtle
- * part of the sync functions is that the blockdev "superblock" is processed
- * last.  This is because the write_inode() function of a typical fs will
- * perform no I/O, but will mark buffers in the blockdev mapping as dirty.
- * What we want to do is to perform all that dirtying first, and then write
- * back all those inode blocks via the blockdev mapping in one sweep.  So the
- * additional (somewhat redundant) sync_blockdev() calls here are to make
- * sure that really happens.  Because if we call sync_inodes_sb(wait=1) with
- * outstanding dirty inodes, the writeback goes block-at-a-time within the
- * filesystem's write_inode().  This is extremely slow.
- */
-static void __sync_inodes(int wait)
-{
-       struct super_block *sb;
-
-       spin_lock(&sb_lock);
-restart:
-       list_for_each_entry(sb, &super_blocks, s_list) {
-               sb->s_count++;
-               spin_unlock(&sb_lock);
-               down_read(&sb->s_umount);
-               if (sb->s_root) {
-                       sync_inodes_sb(sb, wait);
-                       sync_blockdev(sb->s_bdev);
-               }
-               up_read(&sb->s_umount);
-               spin_lock(&sb_lock);
-               if (__put_super_and_need_restart(sb))
-                       goto restart;
-       }
-       spin_unlock(&sb_lock);
-}
-
-void sync_inodes(int wait)
-{
-       __sync_inodes(0);
-
-       if (wait)
-               __sync_inodes(1);
-}
-
 /**
  * write_inode_now     -       write an inode to disk
  * @inode: inode to write to disk
@@ -752,7 +708,7 @@ int write_inode_now(struct inode *inode, int sync)
 
        might_sleep();
        spin_lock(&inode_lock);
-       ret = __writeback_single_inode(inode, &wbc);
+       ret = writeback_single_inode(inode, &wbc);
        spin_unlock(&inode_lock);
        if (sync)
                inode_sync_wait(inode);
@@ -776,7 +732,7 @@ int sync_inode(struct inode *inode, struct writeback_control *wbc)
        int ret;
 
        spin_lock(&inode_lock);
-       ret = __writeback_single_inode(inode, wbc);
+       ret = writeback_single_inode(inode, wbc);
        spin_unlock(&inode_lock);
        return ret;
 }