add patch create-function-to-read-journal-inode
[ext4-patch-queue.git] / create-function-to-read-journal-inode
blobe4966678a4a2dd970d6d977b2d503fff45cd0af8
1 ext4: create function to read journal inode
3 From: Eric Whitney <enwlinux@gmail.com>
5 Factor out the code used in ext4_get_journal() to read a valid journal
6 inode from storage, enabling its reuse in other functions.
8 Signed-off-by: Eric Whitney <enwlinux@gmail.com>
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 ---
11  fs/ext4/super.c | 32 +++++++++++++++++++++++---------
12  1 file changed, 23 insertions(+), 9 deletions(-)
14 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
15 index 50912cc..4b0ca25 100644
16 --- a/fs/ext4/super.c
17 +++ b/fs/ext4/super.c
18 @@ -78,6 +78,8 @@ static int ext4_feature_set_ok(struct super_block *sb, int readonly);
19  static void ext4_destroy_lazyinit_thread(void);
20  static void ext4_unregister_li_request(struct super_block *sb);
21  static void ext4_clear_request_list(void);
22 +static struct inode *ext4_get_journal_inode(struct super_block *sb,
23 +                                           unsigned int journal_inum);
25  /*
26   * Lock ordering
27 @@ -4237,18 +4239,16 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
28         write_unlock(&journal->j_state_lock);
29  }
31 -static journal_t *ext4_get_journal(struct super_block *sb,
32 -                                  unsigned int journal_inum)
33 +static struct inode *ext4_get_journal_inode(struct super_block *sb,
34 +                                            unsigned int journal_inum)
35  {
36         struct inode *journal_inode;
37 -       journal_t *journal;
39 -       BUG_ON(!ext4_has_feature_journal(sb));
41 -       /* First, test for the existence of a valid inode on disk.  Bad
42 -        * things happen if we iget() an unused inode, as the subsequent
43 -        * iput() will try to delete it. */
45 +       /*
46 +        * Test for the existence of a valid inode on disk.  Bad things
47 +        * happen if we iget() an unused inode, as the subsequent iput()
48 +        * will try to delete it.
49 +        */
50         journal_inode = ext4_iget(sb, journal_inum);
51         if (IS_ERR(journal_inode)) {
52                 ext4_msg(sb, KERN_ERR, "no journal found");
53 @@ -4268,6 +4268,20 @@ static journal_t *ext4_get_journal(struct super_block *sb,
54                 iput(journal_inode);
55                 return NULL;
56         }
57 +       return journal_inode;
60 +static journal_t *ext4_get_journal(struct super_block *sb,
61 +                                  unsigned int journal_inum)
63 +       struct inode *journal_inode;
64 +       journal_t *journal;
66 +       BUG_ON(!ext4_has_feature_journal(sb));
68 +       journal_inode = ext4_get_journal_inode(sb, journal_inum);
69 +       if (!journal_inode)
70 +               return NULL;
72         journal = jbd2_journal_init_inode(journal_inode);
73         if (!journal) {
74 -- 
75 2.1.4