diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/jbd2/checkpoint.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c index 9203c3332f17..9497718fe920 100644 --- a/fs/jbd2/checkpoint.c +++ b/fs/jbd2/checkpoint.c | |||
@@ -116,7 +116,7 @@ static int __try_to_free_cp_buf(struct journal_head *jh) | |||
116 | */ | 116 | */ |
117 | void __jbd2_log_wait_for_space(journal_t *journal) | 117 | void __jbd2_log_wait_for_space(journal_t *journal) |
118 | { | 118 | { |
119 | int nblocks; | 119 | int nblocks, space_left; |
120 | assert_spin_locked(&journal->j_state_lock); | 120 | assert_spin_locked(&journal->j_state_lock); |
121 | 121 | ||
122 | nblocks = jbd_space_needed(journal); | 122 | nblocks = jbd_space_needed(journal); |
@@ -129,25 +129,43 @@ void __jbd2_log_wait_for_space(journal_t *journal) | |||
129 | /* | 129 | /* |
130 | * Test again, another process may have checkpointed while we | 130 | * Test again, another process may have checkpointed while we |
131 | * were waiting for the checkpoint lock. If there are no | 131 | * were waiting for the checkpoint lock. If there are no |
132 | * outstanding transactions there is nothing to checkpoint and | 132 | * transactions ready to be checkpointed, try to recover |
133 | * we can't make progress. Abort the journal in this case. | 133 | * journal space by calling cleanup_journal_tail(), and if |
134 | * that doesn't work, by waiting for the currently committing | ||
135 | * transaction to complete. If there is absolutely no way | ||
136 | * to make progress, this is either a BUG or corrupted | ||
137 | * filesystem, so abort the journal and leave a stack | ||
138 | * trace for forensic evidence. | ||
134 | */ | 139 | */ |
135 | spin_lock(&journal->j_state_lock); | 140 | spin_lock(&journal->j_state_lock); |
136 | spin_lock(&journal->j_list_lock); | 141 | spin_lock(&journal->j_list_lock); |
137 | nblocks = jbd_space_needed(journal); | 142 | nblocks = jbd_space_needed(journal); |
138 | if (__jbd2_log_space_left(journal) < nblocks) { | 143 | space_left = __jbd2_log_space_left(journal); |
144 | if (space_left < nblocks) { | ||
139 | int chkpt = journal->j_checkpoint_transactions != NULL; | 145 | int chkpt = journal->j_checkpoint_transactions != NULL; |
146 | tid_t tid = 0; | ||
140 | 147 | ||
148 | if (journal->j_committing_transaction) | ||
149 | tid = journal->j_committing_transaction->t_tid; | ||
141 | spin_unlock(&journal->j_list_lock); | 150 | spin_unlock(&journal->j_list_lock); |
142 | spin_unlock(&journal->j_state_lock); | 151 | spin_unlock(&journal->j_state_lock); |
143 | if (chkpt) { | 152 | if (chkpt) { |
144 | jbd2_log_do_checkpoint(journal); | 153 | jbd2_log_do_checkpoint(journal); |
154 | } else if (jbd2_cleanup_journal_tail(journal) == 0) { | ||
155 | /* We were able to recover space; yay! */ | ||
156 | ; | ||
157 | } else if (tid) { | ||
158 | jbd2_log_wait_commit(journal, tid); | ||
145 | } else { | 159 | } else { |
146 | printk(KERN_ERR "%s: no transactions\n", | 160 | printk(KERN_ERR "%s: needed %d blocks and " |
147 | __func__); | 161 | "only had %d space available\n", |
162 | __func__, nblocks, space_left); | ||
163 | printk(KERN_ERR "%s: no way to get more " | ||
164 | "journal space in %s\n", __func__, | ||
165 | journal->j_devname); | ||
166 | WARN_ON(1); | ||
148 | jbd2_journal_abort(journal, 0); | 167 | jbd2_journal_abort(journal, 0); |
149 | } | 168 | } |
150 | |||
151 | spin_lock(&journal->j_state_lock); | 169 | spin_lock(&journal->j_state_lock); |
152 | } else { | 170 | } else { |
153 | spin_unlock(&journal->j_list_lock); | 171 | spin_unlock(&journal->j_list_lock); |