add patch handle-symlink-properly-with-inline_data
[ext4-patch-queue.git] / use-sbi-in-ext4_orphan_add_del
blob081cb9a115bbdca5c63a94374316aa8d7f3018f3
1 ext4: use sbi in ext4_orphan_{add|del}()
3 From: Jan Kara <jack@suse.cz>
5 Use sbi pointer consistently in ext4_orphan_del() instead of opencoding
6 it sometimes. Also ext4_orphan_add() uses EXT4_SB(sb) often so create
7 sbi variable for it as well and use it.
9 Signed-off-by: Jan Kara <jack@suse.cz>
10 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
11 ---
12  fs/ext4/namei.c | 31 +++++++++++++++----------------
13  1 file changed, 15 insertions(+), 16 deletions(-)
15 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
16 index 7ac6167..eb61584 100644
17 --- a/fs/ext4/namei.c
18 +++ b/fs/ext4/namei.c
19 @@ -2551,13 +2551,14 @@ static int empty_dir(struct inode *inode)
20  int ext4_orphan_add(handle_t *handle, struct inode *inode)
21  {
22         struct super_block *sb = inode->i_sb;
23 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
24         struct ext4_iloc iloc;
25         int err = 0, rc;
27 -       if (!EXT4_SB(sb)->s_journal)
28 +       if (!sbi->s_journal)
29                 return 0;
31 -       mutex_lock(&EXT4_SB(sb)->s_orphan_lock);
32 +       mutex_lock(&sbi->s_orphan_lock);
33         if (!list_empty(&EXT4_I(inode)->i_orphan))
34                 goto out_unlock;
36 @@ -2570,8 +2571,8 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
37         J_ASSERT((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
38                   S_ISLNK(inode->i_mode)) || inode->i_nlink == 0);
40 -       BUFFER_TRACE(EXT4_SB(sb)->s_sbh, "get_write_access");
41 -       err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh);
42 +       BUFFER_TRACE(sbi->s_sbh, "get_write_access");
43 +       err = ext4_journal_get_write_access(handle, sbi->s_sbh);
44         if (err)
45                 goto out_unlock;
47 @@ -2583,12 +2584,12 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
48          * orphan list. If so skip on-disk list modification.
49          */
50         if (NEXT_ORPHAN(inode) && NEXT_ORPHAN(inode) <=
51 -               (le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)))
52 +               (le32_to_cpu(sbi->s_es->s_inodes_count)))
53                         goto mem_insert;
55         /* Insert this inode at the head of the on-disk orphan list... */
56 -       NEXT_ORPHAN(inode) = le32_to_cpu(EXT4_SB(sb)->s_es->s_last_orphan);
57 -       EXT4_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino);
58 +       NEXT_ORPHAN(inode) = le32_to_cpu(sbi->s_es->s_last_orphan);
59 +       sbi->s_es->s_last_orphan = cpu_to_le32(inode->i_ino);
60         err = ext4_handle_dirty_super(handle, sb);
61         rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
62         if (!err)
63 @@ -2604,14 +2605,14 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
64          * anyway on the next recovery. */
65  mem_insert:
66         if (!err)
67 -               list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
68 +               list_add(&EXT4_I(inode)->i_orphan, &sbi->s_orphan);
70         jbd_debug(4, "superblock will point to %lu\n", inode->i_ino);
71         jbd_debug(4, "orphan inode %lu will point to %d\n",
72                         inode->i_ino, NEXT_ORPHAN(inode));
73  out_unlock:
74 -       mutex_unlock(&EXT4_SB(sb)->s_orphan_lock);
75 -       ext4_std_error(inode->i_sb, err);
76 +       mutex_unlock(&sbi->s_orphan_lock);
77 +       ext4_std_error(sb, err);
78         return err;
79  }
81 @@ -2623,22 +2624,20 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
82  {
83         struct list_head *prev;
84         struct ext4_inode_info *ei = EXT4_I(inode);
85 -       struct ext4_sb_info *sbi;
86 +       struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
87         __u32 ino_next;
88         struct ext4_iloc iloc;
89         int err = 0;
91 -       if ((!EXT4_SB(inode->i_sb)->s_journal) &&
92 -           !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS))
93 +       if (!sbi->s_journal && !(sbi->s_mount_state & EXT4_ORPHAN_FS))
94                 return 0;
96 -       mutex_lock(&EXT4_SB(inode->i_sb)->s_orphan_lock);
97 +       mutex_lock(&sbi->s_orphan_lock);
98         if (list_empty(&ei->i_orphan))
99                 goto out;
101         ino_next = NEXT_ORPHAN(inode);
102         prev = ei->i_orphan.prev;
103 -       sbi = EXT4_SB(inode->i_sb);
105         jbd_debug(4, "remove inode %lu from orphan list\n", inode->i_ino);
107 @@ -2684,7 +2683,7 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
108  out_err:
109         ext4_std_error(inode->i_sb, err);
110  out:
111 -       mutex_unlock(&EXT4_SB(inode->i_sb)->s_orphan_lock);
112 +       mutex_unlock(&sbi->s_orphan_lock);
113         return err;
115  out_brelse: