diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-28 13:02:55 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-28 13:02:55 -0400 |
commit | 69e1aaddd63104f37021d0b0f6abfd9623c9134c (patch) | |
tree | 14ad49741b428d270b681694bb2df349465455b9 /fs/jbd2/journal.c | |
parent | 56b59b429b4c26e5e730bc8c3d837de9f7d0a966 (diff) | |
parent | 9d547c35799a4ddd235f1565cec2fff6c9263504 (diff) |
Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 updates for 3.4 from Ted Ts'o:
"Ext4 commits for 3.3 merge window; mostly cleanups and bug fixes
The changes to export dirty_writeback_interval are from Artem's s_dirt
cleanup patch series. The same is true of the change to remove the
s_dirt helper functions which never got used by anyone in-tree. I've
run these changes by Al Viro, and am carrying them so that Artem can
more easily fix up the rest of the file systems during the next merge
window. (Originally we had hopped to remove the use of s_dirt from
ext4 during this merge window, but his patches had some bugs, so I
ultimately ended dropping them from the ext4 tree.)"
* tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (66 commits)
vfs: remove unused superblock helpers
mm: export dirty_writeback_interval
ext4: remove useless s_dirt assignment
ext4: write superblock only once on unmount
ext4: do not mark superblock as dirty unnecessarily
ext4: correct ext4_punch_hole return codes
ext4: remove restrictive checks for EOFBLOCKS_FL
ext4: always set then trimmed blocks count into len
ext4: fix trimmed block count accunting
ext4: fix start and len arguments handling in ext4_trim_fs()
ext4: update s_free_{inodes,blocks}_count during online resize
ext4: change some printk() calls to use ext4_msg() instead
ext4: avoid output message interleaving in ext4_error_<foo>()
ext4: remove trailing newlines from ext4_msg() and ext4_error() messages
ext4: add no_printk argument validation, fix fallout
ext4: remove redundant "EXT4-fs: " from uses of ext4_msg
ext4: give more helpful error message in ext4_ext_rm_leaf()
ext4: remove unused code from ext4_ext_map_blocks()
ext4: rewrite punch hole to use ext4_ext_remove_space()
jbd2: cleanup journal tail after transaction commit
...
Diffstat (limited to 'fs/jbd2/journal.c')
-rw-r--r-- | fs/jbd2/journal.c | 361 |
1 files changed, 229 insertions, 132 deletions
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 839377e3d624..98ed6dbfe381 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c | |||
@@ -71,7 +71,6 @@ EXPORT_SYMBOL(jbd2_journal_revoke); | |||
71 | 71 | ||
72 | EXPORT_SYMBOL(jbd2_journal_init_dev); | 72 | EXPORT_SYMBOL(jbd2_journal_init_dev); |
73 | EXPORT_SYMBOL(jbd2_journal_init_inode); | 73 | EXPORT_SYMBOL(jbd2_journal_init_inode); |
74 | EXPORT_SYMBOL(jbd2_journal_update_format); | ||
75 | EXPORT_SYMBOL(jbd2_journal_check_used_features); | 74 | EXPORT_SYMBOL(jbd2_journal_check_used_features); |
76 | EXPORT_SYMBOL(jbd2_journal_check_available_features); | 75 | EXPORT_SYMBOL(jbd2_journal_check_available_features); |
77 | EXPORT_SYMBOL(jbd2_journal_set_features); | 76 | EXPORT_SYMBOL(jbd2_journal_set_features); |
@@ -96,7 +95,6 @@ EXPORT_SYMBOL(jbd2_journal_release_jbd_inode); | |||
96 | EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate); | 95 | EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate); |
97 | EXPORT_SYMBOL(jbd2_inode_cache); | 96 | EXPORT_SYMBOL(jbd2_inode_cache); |
98 | 97 | ||
99 | static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *); | ||
100 | static void __journal_abort_soft (journal_t *journal, int errno); | 98 | static void __journal_abort_soft (journal_t *journal, int errno); |
101 | static int jbd2_journal_create_slab(size_t slab_size); | 99 | static int jbd2_journal_create_slab(size_t slab_size); |
102 | 100 | ||
@@ -746,6 +744,98 @@ struct journal_head *jbd2_journal_get_descriptor_buffer(journal_t *journal) | |||
746 | return jbd2_journal_add_journal_head(bh); | 744 | return jbd2_journal_add_journal_head(bh); |
747 | } | 745 | } |
748 | 746 | ||
747 | /* | ||
748 | * Return tid of the oldest transaction in the journal and block in the journal | ||
749 | * where the transaction starts. | ||
750 | * | ||
751 | * If the journal is now empty, return which will be the next transaction ID | ||
752 | * we will write and where will that transaction start. | ||
753 | * | ||
754 | * The return value is 0 if journal tail cannot be pushed any further, 1 if | ||
755 | * it can. | ||
756 | */ | ||
757 | int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid, | ||
758 | unsigned long *block) | ||
759 | { | ||
760 | transaction_t *transaction; | ||
761 | int ret; | ||
762 | |||
763 | read_lock(&journal->j_state_lock); | ||
764 | spin_lock(&journal->j_list_lock); | ||
765 | transaction = journal->j_checkpoint_transactions; | ||
766 | if (transaction) { | ||
767 | *tid = transaction->t_tid; | ||
768 | *block = transaction->t_log_start; | ||
769 | } else if ((transaction = journal->j_committing_transaction) != NULL) { | ||
770 | *tid = transaction->t_tid; | ||
771 | *block = transaction->t_log_start; | ||
772 | } else if ((transaction = journal->j_running_transaction) != NULL) { | ||
773 | *tid = transaction->t_tid; | ||
774 | *block = journal->j_head; | ||
775 | } else { | ||
776 | *tid = journal->j_transaction_sequence; | ||
777 | *block = journal->j_head; | ||
778 | } | ||
779 | ret = tid_gt(*tid, journal->j_tail_sequence); | ||
780 | spin_unlock(&journal->j_list_lock); | ||
781 | read_unlock(&journal->j_state_lock); | ||
782 | |||
783 | return ret; | ||
784 | } | ||
785 | |||
786 | /* | ||
787 | * Update information in journal structure and in on disk journal superblock | ||
788 | * about log tail. This function does not check whether information passed in | ||
789 | * really pushes log tail further. It's responsibility of the caller to make | ||
790 | * sure provided log tail information is valid (e.g. by holding | ||
791 | * j_checkpoint_mutex all the time between computing log tail and calling this | ||
792 | * function as is the case with jbd2_cleanup_journal_tail()). | ||
793 | * | ||
794 | * Requires j_checkpoint_mutex | ||
795 | */ | ||
796 | void __jbd2_update_log_tail(journal_t *journal, tid_t tid, unsigned long block) | ||
797 | { | ||
798 | unsigned long freed; | ||
799 | |||
800 | BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); | ||
801 | |||
802 | /* | ||
803 | * We cannot afford for write to remain in drive's caches since as | ||
804 | * soon as we update j_tail, next transaction can start reusing journal | ||
805 | * space and if we lose sb update during power failure we'd replay | ||
806 | * old transaction with possibly newly overwritten data. | ||
807 | */ | ||
808 | jbd2_journal_update_sb_log_tail(journal, tid, block, WRITE_FUA); | ||
809 | write_lock(&journal->j_state_lock); | ||
810 | freed = block - journal->j_tail; | ||
811 | if (block < journal->j_tail) | ||
812 | freed += journal->j_last - journal->j_first; | ||
813 | |||
814 | trace_jbd2_update_log_tail(journal, tid, block, freed); | ||
815 | jbd_debug(1, | ||
816 | "Cleaning journal tail from %d to %d (offset %lu), " | ||
817 | "freeing %lu\n", | ||
818 | journal->j_tail_sequence, tid, block, freed); | ||
819 | |||
820 | journal->j_free += freed; | ||
821 | journal->j_tail_sequence = tid; | ||
822 | journal->j_tail = block; | ||
823 | write_unlock(&journal->j_state_lock); | ||
824 | } | ||
825 | |||
826 | /* | ||
827 | * This is a variaon of __jbd2_update_log_tail which checks for validity of | ||
828 | * provided log tail and locks j_checkpoint_mutex. So it is safe against races | ||
829 | * with other threads updating log tail. | ||
830 | */ | ||
831 | void jbd2_update_log_tail(journal_t *journal, tid_t tid, unsigned long block) | ||
832 | { | ||
833 | mutex_lock(&journal->j_checkpoint_mutex); | ||
834 | if (tid_gt(tid, journal->j_tail_sequence)) | ||
835 | __jbd2_update_log_tail(journal, tid, block); | ||
836 | mutex_unlock(&journal->j_checkpoint_mutex); | ||
837 | } | ||
838 | |||
749 | struct jbd2_stats_proc_session { | 839 | struct jbd2_stats_proc_session { |
750 | journal_t *journal; | 840 | journal_t *journal; |
751 | struct transaction_stats_s *stats; | 841 | struct transaction_stats_s *stats; |
@@ -1114,40 +1204,45 @@ static int journal_reset(journal_t *journal) | |||
1114 | 1204 | ||
1115 | journal->j_max_transaction_buffers = journal->j_maxlen / 4; | 1205 | journal->j_max_transaction_buffers = journal->j_maxlen / 4; |
1116 | 1206 | ||
1117 | /* Add the dynamic fields and write it to disk. */ | ||
1118 | jbd2_journal_update_superblock(journal, 1); | ||
1119 | return jbd2_journal_start_thread(journal); | ||
1120 | } | ||
1121 | |||
1122 | /** | ||
1123 | * void jbd2_journal_update_superblock() - Update journal sb on disk. | ||
1124 | * @journal: The journal to update. | ||
1125 | * @wait: Set to '0' if you don't want to wait for IO completion. | ||
1126 | * | ||
1127 | * Update a journal's dynamic superblock fields and write it to disk, | ||
1128 | * optionally waiting for the IO to complete. | ||
1129 | */ | ||
1130 | void jbd2_journal_update_superblock(journal_t *journal, int wait) | ||
1131 | { | ||
1132 | journal_superblock_t *sb = journal->j_superblock; | ||
1133 | struct buffer_head *bh = journal->j_sb_buffer; | ||
1134 | |||
1135 | /* | 1207 | /* |
1136 | * As a special case, if the on-disk copy is already marked as needing | 1208 | * As a special case, if the on-disk copy is already marked as needing |
1137 | * no recovery (s_start == 0) and there are no outstanding transactions | 1209 | * no recovery (s_start == 0), then we can safely defer the superblock |
1138 | * in the filesystem, then we can safely defer the superblock update | 1210 | * update until the next commit by setting JBD2_FLUSHED. This avoids |
1139 | * until the next commit by setting JBD2_FLUSHED. This avoids | ||
1140 | * attempting a write to a potential-readonly device. | 1211 | * attempting a write to a potential-readonly device. |
1141 | */ | 1212 | */ |
1142 | if (sb->s_start == 0 && journal->j_tail_sequence == | 1213 | if (sb->s_start == 0) { |
1143 | journal->j_transaction_sequence) { | ||
1144 | jbd_debug(1, "JBD2: Skipping superblock update on recovered sb " | 1214 | jbd_debug(1, "JBD2: Skipping superblock update on recovered sb " |
1145 | "(start %ld, seq %d, errno %d)\n", | 1215 | "(start %ld, seq %d, errno %d)\n", |
1146 | journal->j_tail, journal->j_tail_sequence, | 1216 | journal->j_tail, journal->j_tail_sequence, |
1147 | journal->j_errno); | 1217 | journal->j_errno); |
1148 | goto out; | 1218 | journal->j_flags |= JBD2_FLUSHED; |
1219 | } else { | ||
1220 | /* Lock here to make assertions happy... */ | ||
1221 | mutex_lock(&journal->j_checkpoint_mutex); | ||
1222 | /* | ||
1223 | * Update log tail information. We use WRITE_FUA since new | ||
1224 | * transaction will start reusing journal space and so we | ||
1225 | * must make sure information about current log tail is on | ||
1226 | * disk before that. | ||
1227 | */ | ||
1228 | jbd2_journal_update_sb_log_tail(journal, | ||
1229 | journal->j_tail_sequence, | ||
1230 | journal->j_tail, | ||
1231 | WRITE_FUA); | ||
1232 | mutex_unlock(&journal->j_checkpoint_mutex); | ||
1149 | } | 1233 | } |
1234 | return jbd2_journal_start_thread(journal); | ||
1235 | } | ||
1150 | 1236 | ||
1237 | static void jbd2_write_superblock(journal_t *journal, int write_op) | ||
1238 | { | ||
1239 | struct buffer_head *bh = journal->j_sb_buffer; | ||
1240 | int ret; | ||
1241 | |||
1242 | trace_jbd2_write_superblock(journal, write_op); | ||
1243 | if (!(journal->j_flags & JBD2_BARRIER)) | ||
1244 | write_op &= ~(REQ_FUA | REQ_FLUSH); | ||
1245 | lock_buffer(bh); | ||
1151 | if (buffer_write_io_error(bh)) { | 1246 | if (buffer_write_io_error(bh)) { |
1152 | /* | 1247 | /* |
1153 | * Oh, dear. A previous attempt to write the journal | 1248 | * Oh, dear. A previous attempt to write the journal |
@@ -1163,48 +1258,106 @@ void jbd2_journal_update_superblock(journal_t *journal, int wait) | |||
1163 | clear_buffer_write_io_error(bh); | 1258 | clear_buffer_write_io_error(bh); |
1164 | set_buffer_uptodate(bh); | 1259 | set_buffer_uptodate(bh); |
1165 | } | 1260 | } |
1261 | get_bh(bh); | ||
1262 | bh->b_end_io = end_buffer_write_sync; | ||
1263 | ret = submit_bh(write_op, bh); | ||
1264 | wait_on_buffer(bh); | ||
1265 | if (buffer_write_io_error(bh)) { | ||
1266 | clear_buffer_write_io_error(bh); | ||
1267 | set_buffer_uptodate(bh); | ||
1268 | ret = -EIO; | ||
1269 | } | ||
1270 | if (ret) { | ||
1271 | printk(KERN_ERR "JBD2: Error %d detected when updating " | ||
1272 | "journal superblock for %s.\n", ret, | ||
1273 | journal->j_devname); | ||
1274 | } | ||
1275 | } | ||
1276 | |||
1277 | /** | ||
1278 | * jbd2_journal_update_sb_log_tail() - Update log tail in journal sb on disk. | ||
1279 | * @journal: The journal to update. | ||
1280 | * @tail_tid: TID of the new transaction at the tail of the log | ||
1281 | * @tail_block: The first block of the transaction at the tail of the log | ||
1282 | * @write_op: With which operation should we write the journal sb | ||
1283 | * | ||
1284 | * Update a journal's superblock information about log tail and write it to | ||
1285 | * disk, waiting for the IO to complete. | ||
1286 | */ | ||
1287 | void jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid, | ||
1288 | unsigned long tail_block, int write_op) | ||
1289 | { | ||
1290 | journal_superblock_t *sb = journal->j_superblock; | ||
1291 | |||
1292 | BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); | ||
1293 | jbd_debug(1, "JBD2: updating superblock (start %lu, seq %u)\n", | ||
1294 | tail_block, tail_tid); | ||
1295 | |||
1296 | sb->s_sequence = cpu_to_be32(tail_tid); | ||
1297 | sb->s_start = cpu_to_be32(tail_block); | ||
1298 | |||
1299 | jbd2_write_superblock(journal, write_op); | ||
1300 | |||
1301 | /* Log is no longer empty */ | ||
1302 | write_lock(&journal->j_state_lock); | ||
1303 | WARN_ON(!sb->s_sequence); | ||
1304 | journal->j_flags &= ~JBD2_FLUSHED; | ||
1305 | write_unlock(&journal->j_state_lock); | ||
1306 | } | ||
1307 | |||
1308 | /** | ||
1309 | * jbd2_mark_journal_empty() - Mark on disk journal as empty. | ||
1310 | * @journal: The journal to update. | ||
1311 | * | ||
1312 | * Update a journal's dynamic superblock fields to show that journal is empty. | ||
1313 | * Write updated superblock to disk waiting for IO to complete. | ||
1314 | */ | ||
1315 | static void jbd2_mark_journal_empty(journal_t *journal) | ||
1316 | { | ||
1317 | journal_superblock_t *sb = journal->j_superblock; | ||
1166 | 1318 | ||
1319 | BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); | ||
1167 | read_lock(&journal->j_state_lock); | 1320 | read_lock(&journal->j_state_lock); |
1168 | jbd_debug(1, "JBD2: updating superblock (start %ld, seq %d, errno %d)\n", | 1321 | jbd_debug(1, "JBD2: Marking journal as empty (seq %d)\n", |
1169 | journal->j_tail, journal->j_tail_sequence, journal->j_errno); | 1322 | journal->j_tail_sequence); |
1170 | 1323 | ||
1171 | sb->s_sequence = cpu_to_be32(journal->j_tail_sequence); | 1324 | sb->s_sequence = cpu_to_be32(journal->j_tail_sequence); |
1172 | sb->s_start = cpu_to_be32(journal->j_tail); | 1325 | sb->s_start = cpu_to_be32(0); |
1173 | sb->s_errno = cpu_to_be32(journal->j_errno); | ||
1174 | read_unlock(&journal->j_state_lock); | 1326 | read_unlock(&journal->j_state_lock); |
1175 | 1327 | ||
1176 | BUFFER_TRACE(bh, "marking dirty"); | 1328 | jbd2_write_superblock(journal, WRITE_FUA); |
1177 | mark_buffer_dirty(bh); | ||
1178 | if (wait) { | ||
1179 | sync_dirty_buffer(bh); | ||
1180 | if (buffer_write_io_error(bh)) { | ||
1181 | printk(KERN_ERR "JBD2: I/O error detected " | ||
1182 | "when updating journal superblock for %s.\n", | ||
1183 | journal->j_devname); | ||
1184 | clear_buffer_write_io_error(bh); | ||
1185 | set_buffer_uptodate(bh); | ||
1186 | } | ||
1187 | } else | ||
1188 | write_dirty_buffer(bh, WRITE); | ||
1189 | |||
1190 | out: | ||
1191 | /* If we have just flushed the log (by marking s_start==0), then | ||
1192 | * any future commit will have to be careful to update the | ||
1193 | * superblock again to re-record the true start of the log. */ | ||
1194 | 1329 | ||
1330 | /* Log is no longer empty */ | ||
1195 | write_lock(&journal->j_state_lock); | 1331 | write_lock(&journal->j_state_lock); |
1196 | if (sb->s_start) | 1332 | journal->j_flags |= JBD2_FLUSHED; |
1197 | journal->j_flags &= ~JBD2_FLUSHED; | ||
1198 | else | ||
1199 | journal->j_flags |= JBD2_FLUSHED; | ||
1200 | write_unlock(&journal->j_state_lock); | 1333 | write_unlock(&journal->j_state_lock); |
1201 | } | 1334 | } |
1202 | 1335 | ||
1336 | |||
1337 | /** | ||
1338 | * jbd2_journal_update_sb_errno() - Update error in the journal. | ||
1339 | * @journal: The journal to update. | ||
1340 | * | ||
1341 | * Update a journal's errno. Write updated superblock to disk waiting for IO | ||
1342 | * to complete. | ||
1343 | */ | ||
1344 | static void jbd2_journal_update_sb_errno(journal_t *journal) | ||
1345 | { | ||
1346 | journal_superblock_t *sb = journal->j_superblock; | ||
1347 | |||
1348 | read_lock(&journal->j_state_lock); | ||
1349 | jbd_debug(1, "JBD2: updating superblock error (errno %d)\n", | ||
1350 | journal->j_errno); | ||
1351 | sb->s_errno = cpu_to_be32(journal->j_errno); | ||
1352 | read_unlock(&journal->j_state_lock); | ||
1353 | |||
1354 | jbd2_write_superblock(journal, WRITE_SYNC); | ||
1355 | } | ||
1356 | |||
1203 | /* | 1357 | /* |
1204 | * Read the superblock for a given journal, performing initial | 1358 | * Read the superblock for a given journal, performing initial |
1205 | * validation of the format. | 1359 | * validation of the format. |
1206 | */ | 1360 | */ |
1207 | |||
1208 | static int journal_get_superblock(journal_t *journal) | 1361 | static int journal_get_superblock(journal_t *journal) |
1209 | { | 1362 | { |
1210 | struct buffer_head *bh; | 1363 | struct buffer_head *bh; |
@@ -1398,14 +1551,11 @@ int jbd2_journal_destroy(journal_t *journal) | |||
1398 | 1551 | ||
1399 | if (journal->j_sb_buffer) { | 1552 | if (journal->j_sb_buffer) { |
1400 | if (!is_journal_aborted(journal)) { | 1553 | if (!is_journal_aborted(journal)) { |
1401 | /* We can now mark the journal as empty. */ | 1554 | mutex_lock(&journal->j_checkpoint_mutex); |
1402 | journal->j_tail = 0; | 1555 | jbd2_mark_journal_empty(journal); |
1403 | journal->j_tail_sequence = | 1556 | mutex_unlock(&journal->j_checkpoint_mutex); |
1404 | ++journal->j_transaction_sequence; | 1557 | } else |
1405 | jbd2_journal_update_superblock(journal, 1); | ||
1406 | } else { | ||
1407 | err = -EIO; | 1558 | err = -EIO; |
1408 | } | ||
1409 | brelse(journal->j_sb_buffer); | 1559 | brelse(journal->j_sb_buffer); |
1410 | } | 1560 | } |
1411 | 1561 | ||
@@ -1552,61 +1702,6 @@ void jbd2_journal_clear_features(journal_t *journal, unsigned long compat, | |||
1552 | EXPORT_SYMBOL(jbd2_journal_clear_features); | 1702 | EXPORT_SYMBOL(jbd2_journal_clear_features); |
1553 | 1703 | ||
1554 | /** | 1704 | /** |
1555 | * int jbd2_journal_update_format () - Update on-disk journal structure. | ||
1556 | * @journal: Journal to act on. | ||
1557 | * | ||
1558 | * Given an initialised but unloaded journal struct, poke about in the | ||
1559 | * on-disk structure to update it to the most recent supported version. | ||
1560 | */ | ||
1561 | int jbd2_journal_update_format (journal_t *journal) | ||
1562 | { | ||
1563 | journal_superblock_t *sb; | ||
1564 | int err; | ||
1565 | |||
1566 | err = journal_get_superblock(journal); | ||
1567 | if (err) | ||
1568 | return err; | ||
1569 | |||
1570 | sb = journal->j_superblock; | ||
1571 | |||
1572 | switch (be32_to_cpu(sb->s_header.h_blocktype)) { | ||
1573 | case JBD2_SUPERBLOCK_V2: | ||
1574 | return 0; | ||
1575 | case JBD2_SUPERBLOCK_V1: | ||
1576 | return journal_convert_superblock_v1(journal, sb); | ||
1577 | default: | ||
1578 | break; | ||
1579 | } | ||
1580 | return -EINVAL; | ||
1581 | } | ||
1582 | |||
1583 | static int journal_convert_superblock_v1(journal_t *journal, | ||
1584 | journal_superblock_t *sb) | ||
1585 | { | ||
1586 | int offset, blocksize; | ||
1587 | struct buffer_head *bh; | ||
1588 | |||
1589 | printk(KERN_WARNING | ||
1590 | "JBD2: Converting superblock from version 1 to 2.\n"); | ||
1591 | |||
1592 | /* Pre-initialise new fields to zero */ | ||
1593 | offset = ((char *) &(sb->s_feature_compat)) - ((char *) sb); | ||
1594 | blocksize = be32_to_cpu(sb->s_blocksize); | ||
1595 | memset(&sb->s_feature_compat, 0, blocksize-offset); | ||
1596 | |||
1597 | sb->s_nr_users = cpu_to_be32(1); | ||
1598 | sb->s_header.h_blocktype = cpu_to_be32(JBD2_SUPERBLOCK_V2); | ||
1599 | journal->j_format_version = 2; | ||
1600 | |||
1601 | bh = journal->j_sb_buffer; | ||
1602 | BUFFER_TRACE(bh, "marking dirty"); | ||
1603 | mark_buffer_dirty(bh); | ||
1604 | sync_dirty_buffer(bh); | ||
1605 | return 0; | ||
1606 | } | ||
1607 | |||
1608 | |||
1609 | /** | ||
1610 | * int jbd2_journal_flush () - Flush journal | 1705 | * int jbd2_journal_flush () - Flush journal |
1611 | * @journal: Journal to act on. | 1706 | * @journal: Journal to act on. |
1612 | * | 1707 | * |
@@ -1619,7 +1714,6 @@ int jbd2_journal_flush(journal_t *journal) | |||
1619 | { | 1714 | { |
1620 | int err = 0; | 1715 | int err = 0; |
1621 | transaction_t *transaction = NULL; | 1716 | transaction_t *transaction = NULL; |
1622 | unsigned long old_tail; | ||
1623 | 1717 | ||
1624 | write_lock(&journal->j_state_lock); | 1718 | write_lock(&journal->j_state_lock); |
1625 | 1719 | ||
@@ -1654,6 +1748,7 @@ int jbd2_journal_flush(journal_t *journal) | |||
1654 | if (is_journal_aborted(journal)) | 1748 | if (is_journal_aborted(journal)) |
1655 | return -EIO; | 1749 | return -EIO; |
1656 | 1750 | ||
1751 | mutex_lock(&journal->j_checkpoint_mutex); | ||
1657 | jbd2_cleanup_journal_tail(journal); | 1752 | jbd2_cleanup_journal_tail(journal); |
1658 | 1753 | ||
1659 | /* Finally, mark the journal as really needing no recovery. | 1754 | /* Finally, mark the journal as really needing no recovery. |
@@ -1661,14 +1756,9 @@ int jbd2_journal_flush(journal_t *journal) | |||
1661 | * the magic code for a fully-recovered superblock. Any future | 1756 | * the magic code for a fully-recovered superblock. Any future |
1662 | * commits of data to the journal will restore the current | 1757 | * commits of data to the journal will restore the current |
1663 | * s_start value. */ | 1758 | * s_start value. */ |
1759 | jbd2_mark_journal_empty(journal); | ||
1760 | mutex_unlock(&journal->j_checkpoint_mutex); | ||
1664 | write_lock(&journal->j_state_lock); | 1761 | write_lock(&journal->j_state_lock); |
1665 | old_tail = journal->j_tail; | ||
1666 | journal->j_tail = 0; | ||
1667 | write_unlock(&journal->j_state_lock); | ||
1668 | jbd2_journal_update_superblock(journal, 1); | ||
1669 | write_lock(&journal->j_state_lock); | ||
1670 | journal->j_tail = old_tail; | ||
1671 | |||
1672 | J_ASSERT(!journal->j_running_transaction); | 1762 | J_ASSERT(!journal->j_running_transaction); |
1673 | J_ASSERT(!journal->j_committing_transaction); | 1763 | J_ASSERT(!journal->j_committing_transaction); |
1674 | J_ASSERT(!journal->j_checkpoint_transactions); | 1764 | J_ASSERT(!journal->j_checkpoint_transactions); |
@@ -1708,8 +1798,12 @@ int jbd2_journal_wipe(journal_t *journal, int write) | |||
1708 | write ? "Clearing" : "Ignoring"); | 1798 | write ? "Clearing" : "Ignoring"); |
1709 | 1799 | ||
1710 | err = jbd2_journal_skip_recovery(journal); | 1800 | err = jbd2_journal_skip_recovery(journal); |
1711 | if (write) | 1801 | if (write) { |
1712 | jbd2_journal_update_superblock(journal, 1); | 1802 | /* Lock to make assertions happy... */ |
1803 | mutex_lock(&journal->j_checkpoint_mutex); | ||
1804 | jbd2_mark_journal_empty(journal); | ||
1805 | mutex_unlock(&journal->j_checkpoint_mutex); | ||
1806 | } | ||
1713 | 1807 | ||
1714 | no_recovery: | 1808 | no_recovery: |
1715 | return err; | 1809 | return err; |
@@ -1759,7 +1853,7 @@ static void __journal_abort_soft (journal_t *journal, int errno) | |||
1759 | __jbd2_journal_abort_hard(journal); | 1853 | __jbd2_journal_abort_hard(journal); |
1760 | 1854 | ||
1761 | if (errno) | 1855 | if (errno) |
1762 | jbd2_journal_update_superblock(journal, 1); | 1856 | jbd2_journal_update_sb_errno(journal); |
1763 | } | 1857 | } |
1764 | 1858 | ||
1765 | /** | 1859 | /** |
@@ -2017,7 +2111,7 @@ static struct kmem_cache *jbd2_journal_head_cache; | |||
2017 | static atomic_t nr_journal_heads = ATOMIC_INIT(0); | 2111 | static atomic_t nr_journal_heads = ATOMIC_INIT(0); |
2018 | #endif | 2112 | #endif |
2019 | 2113 | ||
2020 | static int journal_init_jbd2_journal_head_cache(void) | 2114 | static int jbd2_journal_init_journal_head_cache(void) |
2021 | { | 2115 | { |
2022 | int retval; | 2116 | int retval; |
2023 | 2117 | ||
@@ -2035,7 +2129,7 @@ static int journal_init_jbd2_journal_head_cache(void) | |||
2035 | return retval; | 2129 | return retval; |
2036 | } | 2130 | } |
2037 | 2131 | ||
2038 | static void jbd2_journal_destroy_jbd2_journal_head_cache(void) | 2132 | static void jbd2_journal_destroy_journal_head_cache(void) |
2039 | { | 2133 | { |
2040 | if (jbd2_journal_head_cache) { | 2134 | if (jbd2_journal_head_cache) { |
2041 | kmem_cache_destroy(jbd2_journal_head_cache); | 2135 | kmem_cache_destroy(jbd2_journal_head_cache); |
@@ -2323,7 +2417,7 @@ static void __exit jbd2_remove_jbd_stats_proc_entry(void) | |||
2323 | 2417 | ||
2324 | struct kmem_cache *jbd2_handle_cache, *jbd2_inode_cache; | 2418 | struct kmem_cache *jbd2_handle_cache, *jbd2_inode_cache; |
2325 | 2419 | ||
2326 | static int __init journal_init_handle_cache(void) | 2420 | static int __init jbd2_journal_init_handle_cache(void) |
2327 | { | 2421 | { |
2328 | jbd2_handle_cache = KMEM_CACHE(jbd2_journal_handle, SLAB_TEMPORARY); | 2422 | jbd2_handle_cache = KMEM_CACHE(jbd2_journal_handle, SLAB_TEMPORARY); |
2329 | if (jbd2_handle_cache == NULL) { | 2423 | if (jbd2_handle_cache == NULL) { |
@@ -2358,17 +2452,20 @@ static int __init journal_init_caches(void) | |||
2358 | 2452 | ||
2359 | ret = jbd2_journal_init_revoke_caches(); | 2453 | ret = jbd2_journal_init_revoke_caches(); |
2360 | if (ret == 0) | 2454 | if (ret == 0) |
2361 | ret = journal_init_jbd2_journal_head_cache(); | 2455 | ret = jbd2_journal_init_journal_head_cache(); |
2456 | if (ret == 0) | ||
2457 | ret = jbd2_journal_init_handle_cache(); | ||
2362 | if (ret == 0) | 2458 | if (ret == 0) |
2363 | ret = journal_init_handle_cache(); | 2459 | ret = jbd2_journal_init_transaction_cache(); |
2364 | return ret; | 2460 | return ret; |
2365 | } | 2461 | } |
2366 | 2462 | ||
2367 | static void jbd2_journal_destroy_caches(void) | 2463 | static void jbd2_journal_destroy_caches(void) |
2368 | { | 2464 | { |
2369 | jbd2_journal_destroy_revoke_caches(); | 2465 | jbd2_journal_destroy_revoke_caches(); |
2370 | jbd2_journal_destroy_jbd2_journal_head_cache(); | 2466 | jbd2_journal_destroy_journal_head_cache(); |
2371 | jbd2_journal_destroy_handle_cache(); | 2467 | jbd2_journal_destroy_handle_cache(); |
2468 | jbd2_journal_destroy_transaction_cache(); | ||
2372 | jbd2_journal_destroy_slabs(); | 2469 | jbd2_journal_destroy_slabs(); |
2373 | } | 2470 | } |
2374 | 2471 | ||