diff options
Diffstat (limited to 'fs/jbd/journal.c')
-rw-r--r-- | fs/jbd/journal.c | 206 |
1 files changed, 135 insertions, 71 deletions
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c index 0971e9217808..425c2f2cf170 100644 --- a/fs/jbd/journal.c +++ b/fs/jbd/journal.c | |||
@@ -563,6 +563,8 @@ int log_wait_commit(journal_t *journal, tid_t tid) | |||
563 | spin_unlock(&journal->j_state_lock); | 563 | spin_unlock(&journal->j_state_lock); |
564 | #endif | 564 | #endif |
565 | spin_lock(&journal->j_state_lock); | 565 | spin_lock(&journal->j_state_lock); |
566 | if (!tid_geq(journal->j_commit_waited, tid)) | ||
567 | journal->j_commit_waited = tid; | ||
566 | while (tid_gt(tid, journal->j_commit_sequence)) { | 568 | while (tid_gt(tid, journal->j_commit_sequence)) { |
567 | jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n", | 569 | jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n", |
568 | tid, journal->j_commit_sequence); | 570 | tid, journal->j_commit_sequence); |
@@ -921,8 +923,33 @@ static int journal_reset(journal_t *journal) | |||
921 | 923 | ||
922 | journal->j_max_transaction_buffers = journal->j_maxlen / 4; | 924 | journal->j_max_transaction_buffers = journal->j_maxlen / 4; |
923 | 925 | ||
924 | /* Add the dynamic fields and write it to disk. */ | 926 | /* |
925 | journal_update_superblock(journal, 1); | 927 | * As a special case, if the on-disk copy is already marked as needing |
928 | * no recovery (s_start == 0), then we can safely defer the superblock | ||
929 | * update until the next commit by setting JFS_FLUSHED. This avoids | ||
930 | * attempting a write to a potential-readonly device. | ||
931 | */ | ||
932 | if (sb->s_start == 0) { | ||
933 | jbd_debug(1,"JBD: Skipping superblock update on recovered sb " | ||
934 | "(start %u, seq %d, errno %d)\n", | ||
935 | journal->j_tail, journal->j_tail_sequence, | ||
936 | journal->j_errno); | ||
937 | journal->j_flags |= JFS_FLUSHED; | ||
938 | } else { | ||
939 | /* Lock here to make assertions happy... */ | ||
940 | mutex_lock(&journal->j_checkpoint_mutex); | ||
941 | /* | ||
942 | * Update log tail information. We use WRITE_FUA since new | ||
943 | * transaction will start reusing journal space and so we | ||
944 | * must make sure information about current log tail is on | ||
945 | * disk before that. | ||
946 | */ | ||
947 | journal_update_sb_log_tail(journal, | ||
948 | journal->j_tail_sequence, | ||
949 | journal->j_tail, | ||
950 | WRITE_FUA); | ||
951 | mutex_unlock(&journal->j_checkpoint_mutex); | ||
952 | } | ||
926 | return journal_start_thread(journal); | 953 | return journal_start_thread(journal); |
927 | } | 954 | } |
928 | 955 | ||
@@ -999,35 +1026,15 @@ int journal_create(journal_t *journal) | |||
999 | return journal_reset(journal); | 1026 | return journal_reset(journal); |
1000 | } | 1027 | } |
1001 | 1028 | ||
1002 | /** | 1029 | static void journal_write_superblock(journal_t *journal, int write_op) |
1003 | * void journal_update_superblock() - Update journal sb on disk. | ||
1004 | * @journal: The journal to update. | ||
1005 | * @wait: Set to '0' if you don't want to wait for IO completion. | ||
1006 | * | ||
1007 | * Update a journal's dynamic superblock fields and write it to disk, | ||
1008 | * optionally waiting for the IO to complete. | ||
1009 | */ | ||
1010 | void journal_update_superblock(journal_t *journal, int wait) | ||
1011 | { | 1030 | { |
1012 | journal_superblock_t *sb = journal->j_superblock; | ||
1013 | struct buffer_head *bh = journal->j_sb_buffer; | 1031 | struct buffer_head *bh = journal->j_sb_buffer; |
1032 | int ret; | ||
1014 | 1033 | ||
1015 | /* | 1034 | trace_journal_write_superblock(journal, write_op); |
1016 | * As a special case, if the on-disk copy is already marked as needing | 1035 | if (!(journal->j_flags & JFS_BARRIER)) |
1017 | * no recovery (s_start == 0) and there are no outstanding transactions | 1036 | write_op &= ~(REQ_FUA | REQ_FLUSH); |
1018 | * in the filesystem, then we can safely defer the superblock update | 1037 | lock_buffer(bh); |
1019 | * until the next commit by setting JFS_FLUSHED. This avoids | ||
1020 | * attempting a write to a potential-readonly device. | ||
1021 | */ | ||
1022 | if (sb->s_start == 0 && journal->j_tail_sequence == | ||
1023 | journal->j_transaction_sequence) { | ||
1024 | jbd_debug(1,"JBD: Skipping superblock update on recovered sb " | ||
1025 | "(start %u, seq %d, errno %d)\n", | ||
1026 | journal->j_tail, journal->j_tail_sequence, | ||
1027 | journal->j_errno); | ||
1028 | goto out; | ||
1029 | } | ||
1030 | |||
1031 | if (buffer_write_io_error(bh)) { | 1038 | if (buffer_write_io_error(bh)) { |
1032 | char b[BDEVNAME_SIZE]; | 1039 | char b[BDEVNAME_SIZE]; |
1033 | /* | 1040 | /* |
@@ -1045,42 +1052,100 @@ void journal_update_superblock(journal_t *journal, int wait) | |||
1045 | set_buffer_uptodate(bh); | 1052 | set_buffer_uptodate(bh); |
1046 | } | 1053 | } |
1047 | 1054 | ||
1055 | get_bh(bh); | ||
1056 | bh->b_end_io = end_buffer_write_sync; | ||
1057 | ret = submit_bh(write_op, bh); | ||
1058 | wait_on_buffer(bh); | ||
1059 | if (buffer_write_io_error(bh)) { | ||
1060 | clear_buffer_write_io_error(bh); | ||
1061 | set_buffer_uptodate(bh); | ||
1062 | ret = -EIO; | ||
1063 | } | ||
1064 | if (ret) { | ||
1065 | char b[BDEVNAME_SIZE]; | ||
1066 | printk(KERN_ERR "JBD: Error %d detected " | ||
1067 | "when updating journal superblock for %s.\n", | ||
1068 | ret, journal_dev_name(journal, b)); | ||
1069 | } | ||
1070 | } | ||
1071 | |||
1072 | /** | ||
1073 | * journal_update_sb_log_tail() - Update log tail in journal sb on disk. | ||
1074 | * @journal: The journal to update. | ||
1075 | * @tail_tid: TID of the new transaction at the tail of the log | ||
1076 | * @tail_block: The first block of the transaction at the tail of the log | ||
1077 | * @write_op: With which operation should we write the journal sb | ||
1078 | * | ||
1079 | * Update a journal's superblock information about log tail and write it to | ||
1080 | * disk, waiting for the IO to complete. | ||
1081 | */ | ||
1082 | void journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid, | ||
1083 | unsigned int tail_block, int write_op) | ||
1084 | { | ||
1085 | journal_superblock_t *sb = journal->j_superblock; | ||
1086 | |||
1087 | BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); | ||
1088 | jbd_debug(1,"JBD: updating superblock (start %u, seq %u)\n", | ||
1089 | tail_block, tail_tid); | ||
1090 | |||
1091 | sb->s_sequence = cpu_to_be32(tail_tid); | ||
1092 | sb->s_start = cpu_to_be32(tail_block); | ||
1093 | |||
1094 | journal_write_superblock(journal, write_op); | ||
1095 | |||
1096 | /* Log is no longer empty */ | ||
1097 | spin_lock(&journal->j_state_lock); | ||
1098 | WARN_ON(!sb->s_sequence); | ||
1099 | journal->j_flags &= ~JFS_FLUSHED; | ||
1100 | spin_unlock(&journal->j_state_lock); | ||
1101 | } | ||
1102 | |||
1103 | /** | ||
1104 | * mark_journal_empty() - Mark on disk journal as empty. | ||
1105 | * @journal: The journal to update. | ||
1106 | * | ||
1107 | * Update a journal's dynamic superblock fields to show that journal is empty. | ||
1108 | * Write updated superblock to disk waiting for IO to complete. | ||
1109 | */ | ||
1110 | static void mark_journal_empty(journal_t *journal) | ||
1111 | { | ||
1112 | journal_superblock_t *sb = journal->j_superblock; | ||
1113 | |||
1114 | BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); | ||
1048 | spin_lock(&journal->j_state_lock); | 1115 | spin_lock(&journal->j_state_lock); |
1049 | jbd_debug(1,"JBD: updating superblock (start %u, seq %d, errno %d)\n", | 1116 | jbd_debug(1, "JBD: Marking journal as empty (seq %d)\n", |
1050 | journal->j_tail, journal->j_tail_sequence, journal->j_errno); | 1117 | journal->j_tail_sequence); |
1051 | 1118 | ||
1052 | sb->s_sequence = cpu_to_be32(journal->j_tail_sequence); | 1119 | sb->s_sequence = cpu_to_be32(journal->j_tail_sequence); |
1053 | sb->s_start = cpu_to_be32(journal->j_tail); | 1120 | sb->s_start = cpu_to_be32(0); |
1054 | sb->s_errno = cpu_to_be32(journal->j_errno); | ||
1055 | spin_unlock(&journal->j_state_lock); | 1121 | spin_unlock(&journal->j_state_lock); |
1056 | 1122 | ||
1057 | BUFFER_TRACE(bh, "marking dirty"); | 1123 | journal_write_superblock(journal, WRITE_FUA); |
1058 | mark_buffer_dirty(bh); | ||
1059 | if (wait) { | ||
1060 | sync_dirty_buffer(bh); | ||
1061 | if (buffer_write_io_error(bh)) { | ||
1062 | char b[BDEVNAME_SIZE]; | ||
1063 | printk(KERN_ERR "JBD: I/O error detected " | ||
1064 | "when updating journal superblock for %s.\n", | ||
1065 | journal_dev_name(journal, b)); | ||
1066 | clear_buffer_write_io_error(bh); | ||
1067 | set_buffer_uptodate(bh); | ||
1068 | } | ||
1069 | } else | ||
1070 | write_dirty_buffer(bh, WRITE); | ||
1071 | 1124 | ||
1072 | trace_jbd_update_superblock_end(journal, wait); | 1125 | spin_lock(&journal->j_state_lock); |
1073 | out: | 1126 | /* Log is empty */ |
1074 | /* If we have just flushed the log (by marking s_start==0), then | 1127 | journal->j_flags |= JFS_FLUSHED; |
1075 | * any future commit will have to be careful to update the | 1128 | spin_unlock(&journal->j_state_lock); |
1076 | * superblock again to re-record the true start of the log. */ | 1129 | } |
1130 | |||
1131 | /** | ||
1132 | * journal_update_sb_errno() - Update error in the journal. | ||
1133 | * @journal: The journal to update. | ||
1134 | * | ||
1135 | * Update a journal's errno. Write updated superblock to disk waiting for IO | ||
1136 | * to complete. | ||
1137 | */ | ||
1138 | static void journal_update_sb_errno(journal_t *journal) | ||
1139 | { | ||
1140 | journal_superblock_t *sb = journal->j_superblock; | ||
1077 | 1141 | ||
1078 | spin_lock(&journal->j_state_lock); | 1142 | spin_lock(&journal->j_state_lock); |
1079 | if (sb->s_start) | 1143 | jbd_debug(1, "JBD: updating superblock error (errno %d)\n", |
1080 | journal->j_flags &= ~JFS_FLUSHED; | 1144 | journal->j_errno); |
1081 | else | 1145 | sb->s_errno = cpu_to_be32(journal->j_errno); |
1082 | journal->j_flags |= JFS_FLUSHED; | ||
1083 | spin_unlock(&journal->j_state_lock); | 1146 | spin_unlock(&journal->j_state_lock); |
1147 | |||
1148 | journal_write_superblock(journal, WRITE_SYNC); | ||
1084 | } | 1149 | } |
1085 | 1150 | ||
1086 | /* | 1151 | /* |
@@ -1251,6 +1316,8 @@ int journal_destroy(journal_t *journal) | |||
1251 | 1316 | ||
1252 | /* Force any old transactions to disk */ | 1317 | /* Force any old transactions to disk */ |
1253 | 1318 | ||
1319 | /* We cannot race with anybody but must keep assertions happy */ | ||
1320 | mutex_lock(&journal->j_checkpoint_mutex); | ||
1254 | /* Totally anal locking here... */ | 1321 | /* Totally anal locking here... */ |
1255 | spin_lock(&journal->j_list_lock); | 1322 | spin_lock(&journal->j_list_lock); |
1256 | while (journal->j_checkpoint_transactions != NULL) { | 1323 | while (journal->j_checkpoint_transactions != NULL) { |
@@ -1266,16 +1333,14 @@ int journal_destroy(journal_t *journal) | |||
1266 | 1333 | ||
1267 | if (journal->j_sb_buffer) { | 1334 | if (journal->j_sb_buffer) { |
1268 | if (!is_journal_aborted(journal)) { | 1335 | if (!is_journal_aborted(journal)) { |
1269 | /* We can now mark the journal as empty. */ | ||
1270 | journal->j_tail = 0; | ||
1271 | journal->j_tail_sequence = | 1336 | journal->j_tail_sequence = |
1272 | ++journal->j_transaction_sequence; | 1337 | ++journal->j_transaction_sequence; |
1273 | journal_update_superblock(journal, 1); | 1338 | mark_journal_empty(journal); |
1274 | } else { | 1339 | } else |
1275 | err = -EIO; | 1340 | err = -EIO; |
1276 | } | ||
1277 | brelse(journal->j_sb_buffer); | 1341 | brelse(journal->j_sb_buffer); |
1278 | } | 1342 | } |
1343 | mutex_unlock(&journal->j_checkpoint_mutex); | ||
1279 | 1344 | ||
1280 | if (journal->j_inode) | 1345 | if (journal->j_inode) |
1281 | iput(journal->j_inode); | 1346 | iput(journal->j_inode); |
@@ -1455,7 +1520,6 @@ int journal_flush(journal_t *journal) | |||
1455 | { | 1520 | { |
1456 | int err = 0; | 1521 | int err = 0; |
1457 | transaction_t *transaction = NULL; | 1522 | transaction_t *transaction = NULL; |
1458 | unsigned int old_tail; | ||
1459 | 1523 | ||
1460 | spin_lock(&journal->j_state_lock); | 1524 | spin_lock(&journal->j_state_lock); |
1461 | 1525 | ||
@@ -1490,6 +1554,7 @@ int journal_flush(journal_t *journal) | |||
1490 | if (is_journal_aborted(journal)) | 1554 | if (is_journal_aborted(journal)) |
1491 | return -EIO; | 1555 | return -EIO; |
1492 | 1556 | ||
1557 | mutex_lock(&journal->j_checkpoint_mutex); | ||
1493 | cleanup_journal_tail(journal); | 1558 | cleanup_journal_tail(journal); |
1494 | 1559 | ||
1495 | /* Finally, mark the journal as really needing no recovery. | 1560 | /* Finally, mark the journal as really needing no recovery. |
@@ -1497,14 +1562,9 @@ int journal_flush(journal_t *journal) | |||
1497 | * the magic code for a fully-recovered superblock. Any future | 1562 | * the magic code for a fully-recovered superblock. Any future |
1498 | * commits of data to the journal will restore the current | 1563 | * commits of data to the journal will restore the current |
1499 | * s_start value. */ | 1564 | * s_start value. */ |
1565 | mark_journal_empty(journal); | ||
1566 | mutex_unlock(&journal->j_checkpoint_mutex); | ||
1500 | spin_lock(&journal->j_state_lock); | 1567 | spin_lock(&journal->j_state_lock); |
1501 | old_tail = journal->j_tail; | ||
1502 | journal->j_tail = 0; | ||
1503 | spin_unlock(&journal->j_state_lock); | ||
1504 | journal_update_superblock(journal, 1); | ||
1505 | spin_lock(&journal->j_state_lock); | ||
1506 | journal->j_tail = old_tail; | ||
1507 | |||
1508 | J_ASSERT(!journal->j_running_transaction); | 1568 | J_ASSERT(!journal->j_running_transaction); |
1509 | J_ASSERT(!journal->j_committing_transaction); | 1569 | J_ASSERT(!journal->j_committing_transaction); |
1510 | J_ASSERT(!journal->j_checkpoint_transactions); | 1570 | J_ASSERT(!journal->j_checkpoint_transactions); |
@@ -1544,8 +1604,12 @@ int journal_wipe(journal_t *journal, int write) | |||
1544 | write ? "Clearing" : "Ignoring"); | 1604 | write ? "Clearing" : "Ignoring"); |
1545 | 1605 | ||
1546 | err = journal_skip_recovery(journal); | 1606 | err = journal_skip_recovery(journal); |
1547 | if (write) | 1607 | if (write) { |
1548 | journal_update_superblock(journal, 1); | 1608 | /* Lock to make assertions happy... */ |
1609 | mutex_lock(&journal->j_checkpoint_mutex); | ||
1610 | mark_journal_empty(journal); | ||
1611 | mutex_unlock(&journal->j_checkpoint_mutex); | ||
1612 | } | ||
1549 | 1613 | ||
1550 | no_recovery: | 1614 | no_recovery: |
1551 | return err; | 1615 | return err; |
@@ -1613,7 +1677,7 @@ static void __journal_abort_soft (journal_t *journal, int errno) | |||
1613 | __journal_abort_hard(journal); | 1677 | __journal_abort_hard(journal); |
1614 | 1678 | ||
1615 | if (errno) | 1679 | if (errno) |
1616 | journal_update_superblock(journal, 1); | 1680 | journal_update_sb_errno(journal); |
1617 | } | 1681 | } |
1618 | 1682 | ||
1619 | /** | 1683 | /** |