diff options
| author | Geliang Tang <geliangtang@gmail.com> | 2016-09-15 12:02:32 -0400 |
|---|---|---|
| committer | Theodore Ts'o <tytso@mit.edu> | 2016-09-15 12:02:32 -0400 |
| commit | f0c9fd5458bacf7b12a9a579a727dc740cbe047e (patch) | |
| tree | f8fa3663bbb0b44944185ccf0fc09b2799d8ea67 /fs/jbd2 | |
| parent | be32197cd6b8c37425ca954e719d236e6117a8ee (diff) | |
jbd2: move more common code into journal_init_common()
There are some repetitive code in jbd2_journal_init_dev() and
jbd2_journal_init_inode(). So this patch moves the common code into
journal_init_common() helper to simplify the code. And fix the coding
style warnings reported by checkpatch.pl by the way.
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/jbd2')
| -rw-r--r-- | fs/jbd2/journal.c | 131 |
1 files changed, 50 insertions, 81 deletions
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 46261a6f902d..927da4956a89 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c | |||
| @@ -1090,11 +1090,15 @@ static void jbd2_stats_proc_exit(journal_t *journal) | |||
| 1090 | * very few fields yet: that has to wait until we have created the | 1090 | * very few fields yet: that has to wait until we have created the |
| 1091 | * journal structures from from scratch, or loaded them from disk. */ | 1091 | * journal structures from from scratch, or loaded them from disk. */ |
| 1092 | 1092 | ||
| 1093 | static journal_t * journal_init_common (void) | 1093 | static journal_t *journal_init_common(struct block_device *bdev, |
| 1094 | struct block_device *fs_dev, | ||
| 1095 | unsigned long long start, int len, int blocksize) | ||
| 1094 | { | 1096 | { |
| 1095 | static struct lock_class_key jbd2_trans_commit_key; | 1097 | static struct lock_class_key jbd2_trans_commit_key; |
| 1096 | journal_t *journal; | 1098 | journal_t *journal; |
| 1097 | int err; | 1099 | int err; |
| 1100 | struct buffer_head *bh; | ||
| 1101 | int n; | ||
| 1098 | 1102 | ||
| 1099 | journal = kzalloc(sizeof(*journal), GFP_KERNEL); | 1103 | journal = kzalloc(sizeof(*journal), GFP_KERNEL); |
| 1100 | if (!journal) | 1104 | if (!journal) |
| @@ -1131,6 +1135,32 @@ static journal_t * journal_init_common (void) | |||
| 1131 | lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle", | 1135 | lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle", |
| 1132 | &jbd2_trans_commit_key, 0); | 1136 | &jbd2_trans_commit_key, 0); |
| 1133 | 1137 | ||
| 1138 | /* journal descriptor can store up to n blocks -bzzz */ | ||
| 1139 | journal->j_blocksize = blocksize; | ||
| 1140 | journal->j_dev = bdev; | ||
| 1141 | journal->j_fs_dev = fs_dev; | ||
| 1142 | journal->j_blk_offset = start; | ||
| 1143 | journal->j_maxlen = len; | ||
| 1144 | n = journal->j_blocksize / sizeof(journal_block_tag_t); | ||
| 1145 | journal->j_wbufsize = n; | ||
| 1146 | journal->j_wbuf = kmalloc_array(n, sizeof(struct buffer_head *), | ||
| 1147 | GFP_KERNEL); | ||
| 1148 | if (!journal->j_wbuf) { | ||
| 1149 | kfree(journal); | ||
| 1150 | return NULL; | ||
| 1151 | } | ||
| 1152 | |||
| 1153 | bh = getblk_unmovable(journal->j_dev, start, journal->j_blocksize); | ||
| 1154 | if (!bh) { | ||
| 1155 | pr_err("%s: Cannot get buffer for journal superblock\n", | ||
| 1156 | __func__); | ||
| 1157 | kfree(journal->j_wbuf); | ||
| 1158 | kfree(journal); | ||
| 1159 | return NULL; | ||
| 1160 | } | ||
| 1161 | journal->j_sb_buffer = bh; | ||
| 1162 | journal->j_superblock = (journal_superblock_t *)bh->b_data; | ||
| 1163 | |||
| 1134 | return journal; | 1164 | return journal; |
| 1135 | } | 1165 | } |
| 1136 | 1166 | ||
| @@ -1157,51 +1187,21 @@ static journal_t * journal_init_common (void) | |||
| 1157 | * range of blocks on an arbitrary block device. | 1187 | * range of blocks on an arbitrary block device. |
| 1158 | * | 1188 | * |
| 1159 | */ | 1189 | */ |
| 1160 | journal_t * jbd2_journal_init_dev(struct block_device *bdev, | 1190 | journal_t *jbd2_journal_init_dev(struct block_device *bdev, |
| 1161 | struct block_device *fs_dev, | 1191 | struct block_device *fs_dev, |
| 1162 | unsigned long long start, int len, int blocksize) | 1192 | unsigned long long start, int len, int blocksize) |
| 1163 | { | 1193 | { |
| 1164 | journal_t *journal = journal_init_common(); | 1194 | journal_t *journal; |
| 1165 | struct buffer_head *bh; | ||
| 1166 | int n; | ||
| 1167 | 1195 | ||
| 1196 | journal = journal_init_common(bdev, fs_dev, start, len, blocksize); | ||
| 1168 | if (!journal) | 1197 | if (!journal) |
| 1169 | return NULL; | 1198 | return NULL; |
| 1170 | 1199 | ||
| 1171 | /* journal descriptor can store up to n blocks -bzzz */ | ||
| 1172 | journal->j_blocksize = blocksize; | ||
| 1173 | journal->j_dev = bdev; | ||
| 1174 | journal->j_fs_dev = fs_dev; | ||
| 1175 | journal->j_blk_offset = start; | ||
| 1176 | journal->j_maxlen = len; | ||
| 1177 | bdevname(journal->j_dev, journal->j_devname); | 1200 | bdevname(journal->j_dev, journal->j_devname); |
| 1178 | strreplace(journal->j_devname, '/', '!'); | 1201 | strreplace(journal->j_devname, '/', '!'); |
| 1179 | jbd2_stats_proc_init(journal); | 1202 | jbd2_stats_proc_init(journal); |
| 1180 | n = journal->j_blocksize / sizeof(journal_block_tag_t); | ||
| 1181 | journal->j_wbufsize = n; | ||
| 1182 | journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); | ||
| 1183 | if (!journal->j_wbuf) { | ||
| 1184 | printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n", | ||
| 1185 | __func__); | ||
| 1186 | goto out_err; | ||
| 1187 | } | ||
| 1188 | |||
| 1189 | bh = __getblk(journal->j_dev, start, journal->j_blocksize); | ||
| 1190 | if (!bh) { | ||
| 1191 | printk(KERN_ERR | ||
| 1192 | "%s: Cannot get buffer for journal superblock\n", | ||
| 1193 | __func__); | ||
| 1194 | goto out_err; | ||
| 1195 | } | ||
| 1196 | journal->j_sb_buffer = bh; | ||
| 1197 | journal->j_superblock = (journal_superblock_t *)bh->b_data; | ||
| 1198 | 1203 | ||
| 1199 | return journal; | 1204 | return journal; |
| 1200 | out_err: | ||
| 1201 | kfree(journal->j_wbuf); | ||
| 1202 | jbd2_stats_proc_exit(journal); | ||
| 1203 | kfree(journal); | ||
| 1204 | return NULL; | ||
| 1205 | } | 1205 | } |
| 1206 | 1206 | ||
| 1207 | /** | 1207 | /** |
| @@ -1212,67 +1212,36 @@ out_err: | |||
| 1212 | * the journal. The inode must exist already, must support bmap() and | 1212 | * the journal. The inode must exist already, must support bmap() and |
| 1213 | * must have all data blocks preallocated. | 1213 | * must have all data blocks preallocated. |
| 1214 | */ | 1214 | */ |
| 1215 | journal_t * jbd2_journal_init_inode (struct inode *inode) | 1215 | journal_t *jbd2_journal_init_inode(struct inode *inode) |
| 1216 | { | 1216 | { |
| 1217 | struct buffer_head *bh; | 1217 | journal_t *journal; |
| 1218 | journal_t *journal = journal_init_common(); | ||
| 1219 | char *p; | 1218 | char *p; |
| 1220 | int err; | ||
| 1221 | int n; | ||
| 1222 | unsigned long long blocknr; | 1219 | unsigned long long blocknr; |
| 1223 | 1220 | ||
| 1221 | blocknr = bmap(inode, 0); | ||
| 1222 | if (!blocknr) { | ||
| 1223 | pr_err("%s: Cannot locate journal superblock\n", | ||
| 1224 | __func__); | ||
| 1225 | return NULL; | ||
| 1226 | } | ||
| 1227 | |||
| 1228 | jbd_debug(1, "JBD2: inode %s/%ld, size %lld, bits %d, blksize %ld\n", | ||
| 1229 | inode->i_sb->s_id, inode->i_ino, (long long) inode->i_size, | ||
| 1230 | inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize); | ||
| 1231 | |||
| 1232 | journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev, | ||
| 1233 | blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits, | ||
| 1234 | inode->i_sb->s_blocksize); | ||
| 1224 | if (!journal) | 1235 | if (!journal) |
| 1225 | return NULL; | 1236 | return NULL; |
| 1226 | 1237 | ||
| 1227 | journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev; | ||
| 1228 | journal->j_inode = inode; | 1238 | journal->j_inode = inode; |
| 1229 | bdevname(journal->j_dev, journal->j_devname); | 1239 | bdevname(journal->j_dev, journal->j_devname); |
| 1230 | p = strreplace(journal->j_devname, '/', '!'); | 1240 | p = strreplace(journal->j_devname, '/', '!'); |
| 1231 | sprintf(p, "-%lu", journal->j_inode->i_ino); | 1241 | sprintf(p, "-%lu", journal->j_inode->i_ino); |
| 1232 | jbd_debug(1, | ||
| 1233 | "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n", | ||
| 1234 | journal, inode->i_sb->s_id, inode->i_ino, | ||
| 1235 | (long long) inode->i_size, | ||
| 1236 | inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize); | ||
| 1237 | |||
| 1238 | journal->j_maxlen = inode->i_size >> inode->i_sb->s_blocksize_bits; | ||
| 1239 | journal->j_blocksize = inode->i_sb->s_blocksize; | ||
| 1240 | jbd2_stats_proc_init(journal); | 1242 | jbd2_stats_proc_init(journal); |
| 1241 | 1243 | ||
| 1242 | /* journal descriptor can store up to n blocks -bzzz */ | ||
| 1243 | n = journal->j_blocksize / sizeof(journal_block_tag_t); | ||
| 1244 | journal->j_wbufsize = n; | ||
| 1245 | journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); | ||
| 1246 | if (!journal->j_wbuf) { | ||
| 1247 | printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n", | ||
| 1248 | __func__); | ||
| 1249 | goto out_err; | ||
| 1250 | } | ||
| 1251 | |||
| 1252 | err = jbd2_journal_bmap(journal, 0, &blocknr); | ||
| 1253 | /* If that failed, give up */ | ||
| 1254 | if (err) { | ||
| 1255 | printk(KERN_ERR "%s: Cannot locate journal superblock\n", | ||
| 1256 | __func__); | ||
| 1257 | goto out_err; | ||
| 1258 | } | ||
| 1259 | |||
| 1260 | bh = getblk_unmovable(journal->j_dev, blocknr, journal->j_blocksize); | ||
| 1261 | if (!bh) { | ||
| 1262 | printk(KERN_ERR | ||
| 1263 | "%s: Cannot get buffer for journal superblock\n", | ||
| 1264 | __func__); | ||
| 1265 | goto out_err; | ||
| 1266 | } | ||
| 1267 | journal->j_sb_buffer = bh; | ||
| 1268 | journal->j_superblock = (journal_superblock_t *)bh->b_data; | ||
| 1269 | |||
| 1270 | return journal; | 1244 | return journal; |
| 1271 | out_err: | ||
| 1272 | kfree(journal->j_wbuf); | ||
| 1273 | jbd2_stats_proc_exit(journal); | ||
| 1274 | kfree(journal); | ||
| 1275 | return NULL; | ||
| 1276 | } | 1245 | } |
| 1277 | 1246 | ||
| 1278 | /* | 1247 | /* |
