Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 13 Aug 2014 23:45:40 +0000 (17:45 -0600)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 13 Aug 2014 23:45:40 +0000 (17:45 -0600)
Pull quota, reiserfs, UDF updates from Jan Kara:
 "Scalability improvements for quota, a few reiserfs fixes, and couple
  of misc cleanups (udf, ext2)"

* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs:
  reiserfs: Fix use after free in journal teardown
  reiserfs: fix corruption introduced by balance_leaf refactor
  udf: avoid redundant memcpy when writing data in ICB
  fs/udf: re-use hex_asc_upper_{hi,lo} macros
  fs/quota: kernel-doc warning fixes
  udf: use linux/uaccess.h
  fs/ext2/super.c: Drop memory allocation cast
  quota: remove dqptr_sem
  quota: simplify remove_inode_dquot_ref()
  quota: avoid unnecessary dqget()/dqput() calls
  quota: protect Q_GETFMT by dqonoff_mutex

1  2 
fs/reiserfs/do_balan.c
fs/reiserfs/lbalance.c
fs/reiserfs/super.c
fs/super.c

diff --combined fs/reiserfs/do_balan.c
@@@ -10,7 -10,7 +10,7 @@@
   * and using buffers obtained after all above.
   */
  
 -#include <asm/uaccess.h>
 +#include <linux/uaccess.h>
  #include <linux/time.h>
  #include "reiserfs.h"
  #include <linux/buffer_head.h>
@@@ -286,12 -286,14 +286,14 @@@ static int balance_leaf_when_delete(str
        return 0;
  }
  
- static void balance_leaf_insert_left(struct tree_balance *tb,
-                                    struct item_head *ih, const char *body)
+ static unsigned int balance_leaf_insert_left(struct tree_balance *tb,
+                                            struct item_head *const ih,
+                                            const char * const body)
  {
        int ret;
        struct buffer_info bi;
        int n = B_NR_ITEMS(tb->L[0]);
+       unsigned body_shift_bytes = 0;
  
        if (tb->item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) {
                /* part of new item falls into L[0] */
  
                put_ih_item_len(ih, new_item_len);
                if (tb->lbytes > tb->zeroes_num) {
-                       body += (tb->lbytes - tb->zeroes_num);
+                       body_shift_bytes = tb->lbytes - tb->zeroes_num;
                        tb->zeroes_num = 0;
                } else
                        tb->zeroes_num -= tb->lbytes;
                tb->insert_size[0] = 0;
                tb->zeroes_num = 0;
        }
+       return body_shift_bytes;
  }
  
  static void balance_leaf_paste_left_shift_dirent(struct tree_balance *tb,
-                                                struct item_head *ih,
-                                                const char *body)
+                                                struct item_head * const ih,
+                                                const char * const body)
  {
        int n = B_NR_ITEMS(tb->L[0]);
        struct buffer_info bi;
        tb->pos_in_item -= tb->lbytes;
  }
  
- static void balance_leaf_paste_left_shift(struct tree_balance *tb,
-                                         struct item_head *ih,
-                                         const char *body)
+ static unsigned int balance_leaf_paste_left_shift(struct tree_balance *tb,
+                                                 struct item_head * const ih,
+                                                 const char * const body)
  {
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
        int n = B_NR_ITEMS(tb->L[0]);
        struct buffer_info bi;
+       int body_shift_bytes = 0;
  
        if (is_direntry_le_ih(item_head(tbS0, tb->item_pos))) {
                balance_leaf_paste_left_shift_dirent(tb, ih, body);
-               return;
+               return 0;
        }
  
        RFALSE(tb->lbytes <= 0,
                 * insert_size[0]
                 */
                if (l_n > tb->zeroes_num) {
-                       body += (l_n - tb->zeroes_num);
+                       body_shift_bytes = l_n - tb->zeroes_num;
                        tb->zeroes_num = 0;
                } else
                        tb->zeroes_num -= l_n;
                 */
                leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
        }
+       return body_shift_bytes;
  }
  
  
  /* appended item will be in L[0] in whole */
  static void balance_leaf_paste_left_whole(struct tree_balance *tb,
-                                         struct item_head *ih,
-                                         const char *body)
+                                         struct item_head * const ih,
+                                         const char * const body)
  {
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
        int n = B_NR_ITEMS(tb->L[0]);
        tb->zeroes_num = 0;
  }
  
- static void balance_leaf_paste_left(struct tree_balance *tb,
-                                   struct item_head *ih, const char *body)
+ static unsigned int balance_leaf_paste_left(struct tree_balance *tb,
+                                           struct item_head * const ih,
+                                           const char * const body)
  {
        /* we must shift the part of the appended item */
        if (tb->item_pos == tb->lnum[0] - 1 && tb->lbytes != -1)
-               balance_leaf_paste_left_shift(tb, ih, body);
+               return balance_leaf_paste_left_shift(tb, ih, body);
        else
                balance_leaf_paste_left_whole(tb, ih, body);
+       return 0;
  }
  
  /* Shift lnum[0] items from S[0] to the left neighbor L[0] */
- static void balance_leaf_left(struct tree_balance *tb, struct item_head *ih,
-                             const char *body, int flag)
+ static unsigned int balance_leaf_left(struct tree_balance *tb,
+                                     struct item_head * const ih,
+                                     const char * const body, int flag)
  {
        if (tb->lnum[0] <= 0)
-               return;
+               return 0;
  
        /* new item or it part falls to L[0], shift it too */
        if (tb->item_pos < tb->lnum[0]) {
                BUG_ON(flag != M_INSERT && flag != M_PASTE);
  
                if (flag == M_INSERT)
-                       balance_leaf_insert_left(tb, ih, body);
+                       return balance_leaf_insert_left(tb, ih, body);
                else /* M_PASTE */
-                       balance_leaf_paste_left(tb, ih, body);
+                       return balance_leaf_paste_left(tb, ih, body);
        } else
                /* new item doesn't fall into L[0] */
                leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
+       return 0;
  }
  
  
  static void balance_leaf_insert_right(struct tree_balance *tb,
-                                     struct item_head *ih, const char *body)
+                                     struct item_head * const ih,
+                                     const char * const body)
  {
  
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
  
  
  static void balance_leaf_paste_right_shift_dirent(struct tree_balance *tb,
-                                    struct item_head *ih, const char *body)
+                                    struct item_head * const ih,
+                                    const char * const body)
  {
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
        struct buffer_info bi;
  }
  
  static void balance_leaf_paste_right_shift(struct tree_balance *tb,
-                                    struct item_head *ih, const char *body)
+                                    struct item_head * const ih,
+                                    const char * const body)
  {
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
        int n_shift, n_rem, r_zeroes_number, version;
  }
  
  static void balance_leaf_paste_right_whole(struct tree_balance *tb,
-                                    struct item_head *ih, const char *body)
+                                    struct item_head * const ih,
+                                    const char * const body)
  {
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
        int n = B_NR_ITEMS(tbS0);
  }
  
  static void balance_leaf_paste_right(struct tree_balance *tb,
-                                    struct item_head *ih, const char *body)
+                                    struct item_head * const ih,
+                                    const char * const body)
  {
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
        int n = B_NR_ITEMS(tbS0);
  }
  
  /* shift rnum[0] items from S[0] to the right neighbor R[0] */
- static void balance_leaf_right(struct tree_balance *tb, struct item_head *ih,
-                              const char *body, int flag)
+ static void balance_leaf_right(struct tree_balance *tb,
+                              struct item_head * const ih,
+                              const char * const body, int flag)
  {
        if (tb->rnum[0] <= 0)
                return;
  }
  
  static void balance_leaf_new_nodes_insert(struct tree_balance *tb,
-                                         struct item_head *ih,
-                                         const char *body,
+                                         struct item_head * const ih,
+                                         const char * const body,
                                          struct item_head *insert_key,
                                          struct buffer_head **insert_ptr,
                                          int i)
  
  /* we append to directory item */
  static void balance_leaf_new_nodes_paste_dirent(struct tree_balance *tb,
-                                        struct item_head *ih,
-                                        const char *body,
+                                        struct item_head * const ih,
+                                        const char * const body,
                                         struct item_head *insert_key,
                                         struct buffer_head **insert_ptr,
                                         int i)
  }
  
  static void balance_leaf_new_nodes_paste_shift(struct tree_balance *tb,
-                                        struct item_head *ih,
-                                        const char *body,
+                                        struct item_head * const ih,
+                                        const char * const body,
                                         struct item_head *insert_key,
                                         struct buffer_head **insert_ptr,
                                         int i)
  }
  
  static void balance_leaf_new_nodes_paste_whole(struct tree_balance *tb,
-                                              struct item_head *ih,
-                                              const char *body,
+                                              struct item_head * const ih,
+                                              const char * const body,
                                               struct item_head *insert_key,
                                               struct buffer_head **insert_ptr,
                                               int i)
  
  }
  static void balance_leaf_new_nodes_paste(struct tree_balance *tb,
-                                        struct item_head *ih,
-                                        const char *body,
+                                        struct item_head * const ih,
+                                        const char * const body,
                                         struct item_head *insert_key,
                                         struct buffer_head **insert_ptr,
                                         int i)
  
  /* Fill new nodes that appear in place of S[0] */
  static void balance_leaf_new_nodes(struct tree_balance *tb,
-                                  struct item_head *ih,
-                                  const char *body,
+                                  struct item_head * const ih,
+                                  const char * const body,
                                   struct item_head *insert_key,
                                   struct buffer_head **insert_ptr,
                                   int flag)
  }
  
  static void balance_leaf_finish_node_insert(struct tree_balance *tb,
-                                           struct item_head *ih,
-                                           const char *body)
+                                           struct item_head * const ih,
+                                           const char * const body)
  {
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
        struct buffer_info bi;
  }
  
  static void balance_leaf_finish_node_paste_dirent(struct tree_balance *tb,
-                                                 struct item_head *ih,
-                                                 const char *body)
+                                                 struct item_head * const ih,
+                                                 const char * const body)
  {
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
        struct item_head *pasted = item_head(tbS0, tb->item_pos);
  }
  
  static void balance_leaf_finish_node_paste(struct tree_balance *tb,
-                                          struct item_head *ih,
-                                          const char *body)
+                                          struct item_head * const ih,
+                                          const char * const body)
  {
        struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
        struct buffer_info bi;
   * of the affected item which remains in S
   */
  static void balance_leaf_finish_node(struct tree_balance *tb,
-                                     struct item_head *ih,
-                                     const char *body, int flag)
+                                     struct item_head * const ih,
+                                     const char * const body, int flag)
  {
        /* if we must insert or append into buffer S[0] */
        if (0 <= tb->item_pos && tb->item_pos < tb->s0num) {
@@@ -1402,7 -1417,7 +1417,7 @@@ static int balance_leaf(struct tree_bal
            && is_indirect_le_ih(item_head(tbS0, tb->item_pos)))
                tb->pos_in_item *= UNFM_P_SIZE;
  
-       balance_leaf_left(tb, ih, body, flag);
+       body += balance_leaf_left(tb, ih, body, flag);
  
        /* tb->lnum[0] > 0 */
        /* Calculate new item position */
diff --combined fs/reiserfs/lbalance.c
@@@ -2,7 -2,7 +2,7 @@@
   * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
   */
  
 -#include <asm/uaccess.h>
 +#include <linux/uaccess.h>
  #include <linux/string.h>
  #include <linux/time.h>
  #include "reiserfs.h"
@@@ -899,8 -899,9 +899,9 @@@ void leaf_delete_items(struct buffer_in
  
  /* insert item into the leaf node in position before */
  void leaf_insert_into_buf(struct buffer_info *bi, int before,
-                         struct item_head *inserted_item_ih,
-                         const char *inserted_item_body, int zeros_number)
+                         struct item_head * const inserted_item_ih,
+                         const char * const inserted_item_body,
+                         int zeros_number)
  {
        struct buffer_head *bh = bi->bi_bh;
        int nr, free_space;
diff --combined fs/reiserfs/super.c
@@@ -15,7 -15,7 +15,7 @@@
  #include <linux/slab.h>
  #include <linux/vmalloc.h>
  #include <linux/time.h>
 -#include <asm/uaccess.h>
 +#include <linux/uaccess.h>
  #include "reiserfs.h"
  #include "acl.h"
  #include "xattr.h"
@@@ -100,7 -100,11 +100,11 @@@ void reiserfs_schedule_old_flush(struc
        struct reiserfs_sb_info *sbi = REISERFS_SB(s);
        unsigned long delay;
  
-       if (s->s_flags & MS_RDONLY)
+       /*
+        * Avoid scheduling flush when sb is being shut down. It can race
+        * with journal shutdown and free still queued delayed work.
+        */
+       if (s->s_flags & MS_RDONLY || !(s->s_flags & MS_ACTIVE))
                return;
  
        spin_lock(&sbi->old_work_lock);
@@@ -331,7 -335,7 +335,7 @@@ static int finish_unfinished(struct sup
                         * not completed truncate found. New size was
                         * committed together with "save" link
                         */
 -                      reiserfs_info(s, "Truncating %k to %Ld ..",
 +                      reiserfs_info(s, "Truncating %k to %lld ..",
                                      INODE_PKEY(inode), inode->i_size);
  
                        /* don't update modification time */
@@@ -1577,7 -1581,7 +1581,7 @@@ static int read_super_block(struct supe
        rs = (struct reiserfs_super_block *)bh->b_data;
        if (sb_blocksize(rs) != s->s_blocksize) {
                reiserfs_warning(s, "sh-2011", "can't find a reiserfs "
 -                               "filesystem on (dev %s, block %Lu, size %lu)",
 +                               "filesystem on (dev %s, block %llu, size %lu)",
                                 s->s_id,
                                 (unsigned long long)bh->b_blocknr,
                                 s->s_blocksize);
@@@ -2441,7 -2445,8 +2445,7 @@@ static ssize_t reiserfs_quota_write(str
        struct buffer_head tmp_bh, *bh;
  
        if (!current->journal_info) {
 -              printk(KERN_WARNING "reiserfs: Quota write (off=%Lu, len=%Lu)"
 -                      " cancelled because transaction is not started.\n",
 +              printk(KERN_WARNING "reiserfs: Quota write (off=%llu, len=%llu) cancelled because transaction is not started.\n",
                        (unsigned long long)off, (unsigned long long)len);
                return -EIO;
        }
diff --combined fs/super.c
@@@ -22,6 -22,7 +22,6 @@@
  
  #include <linux/export.h>
  #include <linux/slab.h>
 -#include <linux/acct.h>
  #include <linux/blkdev.h>
  #include <linux/mount.h>
  #include <linux/security.h>
@@@ -217,7 -218,6 +217,6 @@@ static struct super_block *alloc_super(
        lockdep_set_class(&s->s_vfs_rename_mutex, &type->s_vfs_rename_key);
        mutex_init(&s->s_dquot.dqio_mutex);
        mutex_init(&s->s_dquot.dqonoff_mutex);
-       init_rwsem(&s->s_dquot.dqptr_sem);
        s->s_maxbytes = MAX_NON_LFS;
        s->s_op = &default_op;
        s->s_time_gran = 1000000000;
@@@ -701,22 -701,12 +700,22 @@@ int do_remount_sb(struct super_block *s
                return -EACCES;
  #endif
  
 -      if (flags & MS_RDONLY)
 -              acct_auto_close(sb);
 -      shrink_dcache_sb(sb);
 -
        remount_ro = (flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY);
  
 +      if (remount_ro) {
 +              if (sb->s_pins.first) {
 +                      up_write(&sb->s_umount);
 +                      sb_pin_kill(sb);
 +                      down_write(&sb->s_umount);
 +                      if (!sb->s_root)
 +                              return 0;
 +                      if (sb->s_writers.frozen != SB_UNFROZEN)
 +                              return -EBUSY;
 +                      remount_ro = (flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY);
 +              }
 +      }
 +      shrink_dcache_sb(sb);
 +
        /* If we are remounting RDONLY and current sb is read/write,
           make sure there are no rw files opened */
        if (remount_ro) {