Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 8 Apr 2014 00:59:17 +0000 (17:59 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 8 Apr 2014 00:59:17 +0000 (17:59 -0700)
Pull ext3 improvements, cleanups, reiserfs fix from Jan Kara:
 "various cleanups for ext2, ext3, udf, isofs, a documentation update
  for quota, and a fix of a race in reiserfs readdir implementation"

* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs:
  reiserfs: fix race in readdir
  ext2: acl: remove unneeded include of linux/capability.h
  ext3: explicitly remove inode from orphan list after failed direct io
  fs/isofs/inode.c add __init to init_inodecache()
  ext3: Speedup WB_SYNC_ALL pass
  fs/quota/Kconfig: Update filesystems
  ext3: Update outdated comment before ext3_ordered_writepage()
  ext3: Update PF_MEMALLOC handling in ext3_write_inode()
  ext2/3: use prandom_u32() instead of get_random_bytes()
  ext3: remove an unneeded check in ext3_new_blocks()
  ext3: remove unneeded check in ext3_ordered_writepage()
  fs: Mark function as static in ext3/xattr_security.c
  fs: Mark function as static in ext3/dir.c
  fs: Mark function as static in ext2/xattr_security.c
  ext3: Add __init macro to init_inodecache
  ext2: Add __init macro to init_inodecache
  udf: Add __init macro to init_inodecache
  fs: udf: parse_options: blocksize check

1  2 
fs/ext2/super.c
fs/ext3/inode.c
fs/ext3/super.c
fs/isofs/inode.c
fs/udf/super.c

diff --combined fs/ext2/super.c
index d260115c0350e91be14eca760b813032e5325fca,73d80da25acd32f0a0c6a95dc156e1417278c071..3750031cfa2f796af344e19f4cc234df5f0c1eba
@@@ -192,7 -192,7 +192,7 @@@ static void init_once(void *foo
        inode_init_once(&ei->vfs_inode);
  }
  
- static int init_inodecache(void)
+ static int __init init_inodecache(void)
  {
        ext2_inode_cachep = kmem_cache_create("ext2_inode_cache",
                                             sizeof(struct ext2_inode_info),
@@@ -1254,7 -1254,6 +1254,7 @@@ static int ext2_remount (struct super_b
        unsigned long old_sb_flags;
        int err;
  
 +      sync_filesystem(sb);
        spin_lock(&sbi->s_lock);
  
        /* Store the old options */
diff --combined fs/ext3/inode.c
index efce2bbfb5e580976e76d95791dd676a29d71dd0,77042a2e017c94631f6de3d3a270f6e5145dd105..f5157d0d1b43772e95aace234b4ee50fca9ade3b
@@@ -228,7 -228,7 +228,7 @@@ void ext3_evict_inode (struct inode *in
                log_wait_commit(journal, commit_tid);
                filemap_write_and_wait(&inode->i_data);
        }
 -      truncate_inode_pages(&inode->i_data, 0);
 +      truncate_inode_pages_final(&inode->i_data);
  
        ext3_discard_reservation(inode);
        rsv = ei->i_block_alloc_info;
@@@ -1559,56 -1559,17 +1559,17 @@@ static int buffer_unmapped(handle_t *ha
  }
  
  /*
-  * Note that we always start a transaction even if we're not journalling
-  * data.  This is to preserve ordering: any hole instantiation within
-  * __block_write_full_page -> ext3_get_block() should be journalled
-  * along with the data so we don't crash and then get metadata which
+  * Note that whenever we need to map blocks we start a transaction even if
+  * we're not journalling data.  This is to preserve ordering: any hole
+  * instantiation within __block_write_full_page -> ext3_get_block() should be
+  * journalled along with the data so we don't crash and then get metadata which
   * refers to old data.
   *
   * In all journalling modes block_write_full_page() will start the I/O.
   *
-  * Problem:
-  *
-  *    ext3_writepage() -> kmalloc() -> __alloc_pages() -> page_launder() ->
-  *            ext3_writepage()
-  *
-  * Similar for:
-  *
-  *    ext3_file_write() -> generic_file_write() -> __alloc_pages() -> ...
-  *
-  * Same applies to ext3_get_block().  We will deadlock on various things like
-  * lock_journal and i_truncate_mutex.
-  *
-  * Setting PF_MEMALLOC here doesn't work - too many internal memory
-  * allocations fail.
-  *
-  * 16May01: If we're reentered then journal_current_handle() will be
-  *        non-zero. We simply *return*.
-  *
-  * 1 July 2001: @@@ FIXME:
-  *   In journalled data mode, a data buffer may be metadata against the
-  *   current transaction.  But the same file is part of a shared mapping
-  *   and someone does a writepage() on it.
-  *
-  *   We will move the buffer onto the async_data list, but *after* it has
-  *   been dirtied. So there's a small window where we have dirty data on
-  *   BJ_Metadata.
-  *
-  *   Note that this only applies to the last partial page in the file.  The
-  *   bit which block_write_full_page() uses prepare/commit for.  (That's
-  *   broken code anyway: it's wrong for msync()).
-  *
-  *   It's a rare case: affects the final partial page, for journalled data
-  *   where the file is subject to bith write() and writepage() in the same
-  *   transction.  To fix it we'll need a custom block_write_full_page().
-  *   We'll probably need that anyway for journalling writepage() output.
-  *
   * We don't honour synchronous mounts for writepage().  That would be
   * disastrous.  Any write() or metadata operation will sync the fs for
   * us.
-  *
-  * AKPM2: if all the page's buffers are mapped to disk and !data=journal,
-  * we don't need to open a transaction here.
   */
  static int ext3_ordered_writepage(struct page *page,
                                struct writeback_control *wbc)
         * block_write_full_page() succeeded.  Otherwise they are unmapped,
         * and generally junk.
         */
-       if (ret == 0) {
-               err = walk_page_buffers(handle, page_bufs, 0, PAGE_CACHE_SIZE,
+       if (ret == 0)
+               ret = walk_page_buffers(handle, page_bufs, 0, PAGE_CACHE_SIZE,
                                        NULL, journal_dirty_data_fn);
-               if (!ret)
-                       ret = err;
-       }
        walk_page_buffers(handle, page_bufs, 0,
                        PAGE_CACHE_SIZE, NULL, bput_one);
        err = ext3_journal_stop(handle);
@@@ -1925,6 -1883,8 +1883,8 @@@ retry
                         * and pretend the write failed... */
                        ext3_truncate_failed_direct_write(inode);
                        ret = PTR_ERR(handle);
+                       if (inode->i_nlink)
+                               ext3_orphan_del(NULL, inode);
                        goto out;
                }
                if (inode->i_nlink)
@@@ -3212,21 -3172,20 +3172,20 @@@ out_brelse
   *
   * We are called from a few places:
   *
-  * - Within generic_file_write() for O_SYNC files.
+  * - Within generic_file_aio_write() -> generic_write_sync() for O_SYNC files.
   *   Here, there will be no transaction running. We wait for any running
   *   transaction to commit.
   *
-  * - Within sys_sync(), kupdate and such.
-  *   We wait on commit, if tol to.
+  * - Within flush work (for sys_sync(), kupdate and such).
+  *   We wait on commit, if told to.
   *
-  * - Within prune_icache() (PF_MEMALLOC == true)
-  *   Here we simply return.  We can't afford to block kswapd on the
-  *   journal commit.
+  * - Within iput_final() -> write_inode_now()
+  *   We wait on commit, if told to.
   *
   * In all cases it is actually safe for us to return without doing anything,
   * because the inode has been copied into a raw inode buffer in
-  * ext3_mark_inode_dirty().  This is a correctness thing for O_SYNC and for
-  * knfsd.
+  * ext3_mark_inode_dirty().  This is a correctness thing for WB_SYNC_ALL
+  * writeback.
   *
   * Note that we are absolutely dependent upon all inode dirtiers doing the
   * right thing: they *must* call mark_inode_dirty() after dirtying info in
   *    stuff();
   *    inode->i_size = expr;
   *
-  * is in error because a kswapd-driven write_inode() could occur while
-  * `stuff()' is running, and the new i_size will be lost.  Plus the inode
-  * will no longer be on the superblock's dirty inode list.
+  * is in error because write_inode() could occur while `stuff()' is running,
+  * and the new i_size will be lost.  Plus the inode will no longer be on the
+  * superblock's dirty inode list.
   */
  int ext3_write_inode(struct inode *inode, struct writeback_control *wbc)
  {
-       if (current->flags & PF_MEMALLOC)
+       if (WARN_ON_ONCE(current->flags & PF_MEMALLOC))
                return 0;
  
        if (ext3_journal_current_handle()) {
                return -EIO;
        }
  
-       if (wbc->sync_mode != WB_SYNC_ALL)
+       /*
+        * No need to force transaction in WB_SYNC_NONE mode. Also
+        * ext3_sync_fs() will force the commit after everything is
+        * written.
+        */
+       if (wbc->sync_mode != WB_SYNC_ALL || wbc->for_sync)
                return 0;
  
        return ext3_force_commit(inode->i_sb);
diff --combined fs/ext3/super.c
index 95c6c5a6d0c56e20fe6bc2374dc8a3bed5da2b72,94608d4958fe11b154957969abce35b1e1cce192..08cdfe5461e3f726650c1216f801d6620694ea5f
@@@ -527,7 -527,7 +527,7 @@@ static void init_once(void *foo
        inode_init_once(&ei->vfs_inode);
  }
  
- static int init_inodecache(void)
+ static int __init init_inodecache(void)
  {
        ext3_inode_cachep = kmem_cache_create("ext3_inode_cache",
                                             sizeof(struct ext3_inode_info),
@@@ -2649,8 -2649,6 +2649,8 @@@ static int ext3_remount (struct super_b
        int i;
  #endif
  
 +      sync_filesystem(sb);
 +
        /* Store the original options */
        old_sb_flags = sb->s_flags;
        old_opts.s_mount_opt = sbi->s_mount_opt;
diff --combined fs/isofs/inode.c
index 6af66ee56390793ed3b1f718f2cb07cba8b92a50,7df1914e97f55ffede83a81869b6d0c0ba111df0..4556ce1af5b04f5a4f0cd0b4e1ae0515435a1857
@@@ -93,7 -93,7 +93,7 @@@ static void init_once(void *foo
        inode_init_once(&ei->vfs_inode);
  }
  
- static int init_inodecache(void)
+ static int __init init_inodecache(void)
  {
        isofs_inode_cachep = kmem_cache_create("isofs_inode_cache",
                                        sizeof(struct iso_inode_info),
@@@ -117,7 -117,6 +117,7 @@@ static void destroy_inodecache(void
  
  static int isofs_remount(struct super_block *sb, int *flags, char *data)
  {
 +      sync_filesystem(sb);
        if (!(*flags & MS_RDONLY))
                return -EROFS;
        return 0;
diff --combined fs/udf/super.c
index 64f2b7334d08bf41f6ec9ed0910393eb680d9fbc,f15d2dcb831549a0f4597420ff80dc4c02ddc436..3286db047a40230f50cb5e18a177b744f150342b
@@@ -175,7 -175,7 +175,7 @@@ static void init_once(void *foo
        inode_init_once(&ei->vfs_inode);
  }
  
- static int init_inodecache(void)
+ static int __init init_inodecache(void)
  {
        udf_inode_cachep = kmem_cache_create("udf_inode_cache",
                                             sizeof(struct udf_inode_info),
@@@ -505,6 -505,7 +505,7 @@@ static int udf_parse_options(char *opti
        while ((p = strsep(&options, ",")) != NULL) {
                substring_t args[MAX_OPT_ARGS];
                int token;
+               unsigned n;
                if (!*p)
                        continue;
  
                case Opt_bs:
                        if (match_int(&args[0], &option))
                                return 0;
-                       uopt->blocksize = option;
+                       n = option;
+                       if (n != 512 && n != 1024 && n != 2048 && n != 4096)
+                               return 0;
+                       uopt->blocksize = n;
                        uopt->flags |= (1 << UDF_FLAG_BLOCKSIZE_SET);
                        break;
                case Opt_unhide:
@@@ -646,7 -650,6 +650,7 @@@ static int udf_remount_fs(struct super_
        int error = 0;
        struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sb);
  
 +      sync_filesystem(sb);
        if (lvidiu) {
                int write_rev = le16_to_cpu(lvidiu->minUDFWriteRev);
                if (write_rev > UDF_MAX_WRITE_VERSION && !(*flags & MS_RDONLY))