1 jbd2: move more common code into journal_init_common()
3 From: Geliang Tang <geliangtang@gmail.com>
5 There are some repetitive code in jbd2_journal_init_dev() and
6 jbd2_journal_init_inode(). So this patch moves the common code into
7 journal_init_common() helper to simplify the code. And fix the coding
8 style warnings reported by checkpatch.pl by the way.
10 Signed-off-by: Geliang Tang <geliangtang@gmail.com>
11 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12 Reviewed-by: Jan Kara <jack@suse.cz>
14 fs/jbd2/journal.c | 131 +++++++++++++++++++++++++++++++++-----------------------------------------------------
15 1 file changed, 50 insertions(+), 81 deletions(-)
17 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
18 index 46261a6..927da49 100644
19 --- a/fs/jbd2/journal.c
20 +++ b/fs/jbd2/journal.c
21 @@ -1090,11 +1090,15 @@ static void jbd2_stats_proc_exit(journal_t *journal)
22 * very few fields yet: that has to wait until we have created the
23 * journal structures from from scratch, or loaded them from disk. */
25 -static journal_t * journal_init_common (void)
26 +static journal_t *journal_init_common(struct block_device *bdev,
27 + struct block_device *fs_dev,
28 + unsigned long long start, int len, int blocksize)
30 static struct lock_class_key jbd2_trans_commit_key;
33 + struct buffer_head *bh;
36 journal = kzalloc(sizeof(*journal), GFP_KERNEL);
38 @@ -1131,6 +1135,32 @@ static journal_t * journal_init_common (void)
39 lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle",
40 &jbd2_trans_commit_key, 0);
42 + /* journal descriptor can store up to n blocks -bzzz */
43 + journal->j_blocksize = blocksize;
44 + journal->j_dev = bdev;
45 + journal->j_fs_dev = fs_dev;
46 + journal->j_blk_offset = start;
47 + journal->j_maxlen = len;
48 + n = journal->j_blocksize / sizeof(journal_block_tag_t);
49 + journal->j_wbufsize = n;
50 + journal->j_wbuf = kmalloc_array(n, sizeof(struct buffer_head *),
52 + if (!journal->j_wbuf) {
57 + bh = getblk_unmovable(journal->j_dev, start, journal->j_blocksize);
59 + pr_err("%s: Cannot get buffer for journal superblock\n",
61 + kfree(journal->j_wbuf);
65 + journal->j_sb_buffer = bh;
66 + journal->j_superblock = (journal_superblock_t *)bh->b_data;
71 @@ -1157,51 +1187,21 @@ static journal_t * journal_init_common (void)
72 * range of blocks on an arbitrary block device.
75 -journal_t * jbd2_journal_init_dev(struct block_device *bdev,
76 +journal_t *jbd2_journal_init_dev(struct block_device *bdev,
77 struct block_device *fs_dev,
78 unsigned long long start, int len, int blocksize)
80 - journal_t *journal = journal_init_common();
81 - struct buffer_head *bh;
85 + journal = journal_init_common(bdev, fs_dev, start, len, blocksize);
89 - /* journal descriptor can store up to n blocks -bzzz */
90 - journal->j_blocksize = blocksize;
91 - journal->j_dev = bdev;
92 - journal->j_fs_dev = fs_dev;
93 - journal->j_blk_offset = start;
94 - journal->j_maxlen = len;
95 bdevname(journal->j_dev, journal->j_devname);
96 strreplace(journal->j_devname, '/', '!');
97 jbd2_stats_proc_init(journal);
98 - n = journal->j_blocksize / sizeof(journal_block_tag_t);
99 - journal->j_wbufsize = n;
100 - journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
101 - if (!journal->j_wbuf) {
102 - printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n",
107 - bh = __getblk(journal->j_dev, start, journal->j_blocksize);
110 - "%s: Cannot get buffer for journal superblock\n",
114 - journal->j_sb_buffer = bh;
115 - journal->j_superblock = (journal_superblock_t *)bh->b_data;
119 - kfree(journal->j_wbuf);
120 - jbd2_stats_proc_exit(journal);
126 @@ -1212,67 +1212,36 @@ out_err:
127 * the journal. The inode must exist already, must support bmap() and
128 * must have all data blocks preallocated.
130 -journal_t * jbd2_journal_init_inode (struct inode *inode)
131 +journal_t *jbd2_journal_init_inode(struct inode *inode)
133 - struct buffer_head *bh;
134 - journal_t *journal = journal_init_common();
135 + journal_t *journal;
139 unsigned long long blocknr;
141 + blocknr = bmap(inode, 0);
143 + pr_err("%s: Cannot locate journal superblock\n",
148 + jbd_debug(1, "JBD2: inode %s/%ld, size %lld, bits %d, blksize %ld\n",
149 + inode->i_sb->s_id, inode->i_ino, (long long) inode->i_size,
150 + inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);
152 + journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev,
153 + blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits,
154 + inode->i_sb->s_blocksize);
158 - journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev;
159 journal->j_inode = inode;
160 bdevname(journal->j_dev, journal->j_devname);
161 p = strreplace(journal->j_devname, '/', '!');
162 sprintf(p, "-%lu", journal->j_inode->i_ino);
164 - "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n",
165 - journal, inode->i_sb->s_id, inode->i_ino,
166 - (long long) inode->i_size,
167 - inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);
169 - journal->j_maxlen = inode->i_size >> inode->i_sb->s_blocksize_bits;
170 - journal->j_blocksize = inode->i_sb->s_blocksize;
171 jbd2_stats_proc_init(journal);
173 - /* journal descriptor can store up to n blocks -bzzz */
174 - n = journal->j_blocksize / sizeof(journal_block_tag_t);
175 - journal->j_wbufsize = n;
176 - journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
177 - if (!journal->j_wbuf) {
178 - printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n",
183 - err = jbd2_journal_bmap(journal, 0, &blocknr);
184 - /* If that failed, give up */
186 - printk(KERN_ERR "%s: Cannot locate journal superblock\n",
191 - bh = getblk_unmovable(journal->j_dev, blocknr, journal->j_blocksize);
194 - "%s: Cannot get buffer for journal superblock\n",
198 - journal->j_sb_buffer = bh;
199 - journal->j_superblock = (journal_superblock_t *)bh->b_data;
203 - kfree(journal->j_wbuf);
204 - jbd2_stats_proc_exit(journal);