blob: f8b3be8732262f1642c0a1b4e19399bd048b964f [file] [log] [blame]
Dave Kleikamp470decc2006-10-11 01:20:57 -07001/*
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002 * linux/fs/jbd2/commit.c
Dave Kleikamp470decc2006-10-11 01:20:57 -07003 *
4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1998
5 *
6 * Copyright 1998 Red Hat corp --- All Rights Reserved
7 *
8 * This file is part of the Linux kernel and is made available under
9 * the terms of the GNU General Public License, version 2, or at your
10 * option, any later version, incorporated herein by reference.
11 *
12 * Journal commit routines for the generic filesystem journaling code;
13 * part of the ext2fs journaling system.
14 */
15
16#include <linux/time.h>
17#include <linux/fs.h>
Mingming Caof7f4bcc2006-10-11 01:20:59 -070018#include <linux/jbd2.h>
Dave Kleikamp470decc2006-10-11 01:20:57 -070019#include <linux/errno.h>
20#include <linux/slab.h>
21#include <linux/mm.h>
22#include <linux/pagemap.h>
Johann Lombardi8e85fb32008-01-28 23:58:27 -050023#include <linux/jiffies.h>
Girish Shilamkar818d2762008-01-28 23:58:27 -050024#include <linux/crc32.h>
Aneesh Kumar K.Vcd1aac32008-07-11 19:27:31 -040025#include <linux/writeback.h>
26#include <linux/backing-dev.h>
Dave Kleikamp470decc2006-10-11 01:20:57 -070027
28/*
29 * Default IO end handler for temporary BJ_IO buffer_heads.
30 */
31static void journal_end_buffer_io_sync(struct buffer_head *bh, int uptodate)
32{
33 BUFFER_TRACE(bh, "");
34 if (uptodate)
35 set_buffer_uptodate(bh);
36 else
37 clear_buffer_uptodate(bh);
38 unlock_buffer(bh);
39}
40
41/*
Jan Kara87c89c22008-07-11 19:27:31 -040042 * When an ext4 file is truncated, it is possible that some pages are not
43 * successfully freed, because they are attached to a committing transaction.
Dave Kleikamp470decc2006-10-11 01:20:57 -070044 * After the transaction commits, these pages are left on the LRU, with no
45 * ->mapping, and with attached buffers. These pages are trivially reclaimable
46 * by the VM, but their apparent absence upsets the VM accounting, and it makes
47 * the numbers in /proc/meminfo look odd.
48 *
49 * So here, we have a buffer which has just come off the forget list. Look to
50 * see if we can strip all buffers from the backing page.
51 *
52 * Called under lock_journal(), and possibly under journal_datalist_lock. The
53 * caller provided us with a ref against the buffer, and we drop that here.
54 */
55static void release_buffer_page(struct buffer_head *bh)
56{
57 struct page *page;
58
59 if (buffer_dirty(bh))
60 goto nope;
61 if (atomic_read(&bh->b_count) != 1)
62 goto nope;
63 page = bh->b_page;
64 if (!page)
65 goto nope;
66 if (page->mapping)
67 goto nope;
68
69 /* OK, it's a truncated page */
70 if (TestSetPageLocked(page))
71 goto nope;
72
73 page_cache_get(page);
74 __brelse(bh);
75 try_to_free_buffers(page);
76 unlock_page(page);
77 page_cache_release(page);
78 return;
79
80nope:
81 __brelse(bh);
82}
83
84/*
Girish Shilamkar818d2762008-01-28 23:58:27 -050085 * Done it all: now submit the commit record. We should have
Dave Kleikamp470decc2006-10-11 01:20:57 -070086 * cleaned up our previous buffers by now, so if we are in abort
87 * mode we can now just skip the rest of the journal write
88 * entirely.
89 *
90 * Returns 1 if the journal needs to be aborted or 0 on success
91 */
Girish Shilamkar818d2762008-01-28 23:58:27 -050092static int journal_submit_commit_record(journal_t *journal,
93 transaction_t *commit_transaction,
94 struct buffer_head **cbh,
95 __u32 crc32_sum)
Dave Kleikamp470decc2006-10-11 01:20:57 -070096{
97 struct journal_head *descriptor;
Girish Shilamkar818d2762008-01-28 23:58:27 -050098 struct commit_header *tmp;
Dave Kleikamp470decc2006-10-11 01:20:57 -070099 struct buffer_head *bh;
Girish Shilamkar818d2762008-01-28 23:58:27 -0500100 int ret;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700101 int barrier_done = 0;
Theodore Ts'o736603a2008-07-11 19:27:31 -0400102 struct timespec now = current_kernel_time();
Dave Kleikamp470decc2006-10-11 01:20:57 -0700103
104 if (is_journal_aborted(journal))
105 return 0;
106
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700107 descriptor = jbd2_journal_get_descriptor_buffer(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700108 if (!descriptor)
109 return 1;
110
111 bh = jh2bh(descriptor);
112
Girish Shilamkar818d2762008-01-28 23:58:27 -0500113 tmp = (struct commit_header *)bh->b_data;
114 tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
115 tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK);
116 tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid);
Theodore Ts'o736603a2008-07-11 19:27:31 -0400117 tmp->h_commit_sec = cpu_to_be64(now.tv_sec);
118 tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec);
Girish Shilamkar818d2762008-01-28 23:58:27 -0500119
120 if (JBD2_HAS_COMPAT_FEATURE(journal,
121 JBD2_FEATURE_COMPAT_CHECKSUM)) {
122 tmp->h_chksum_type = JBD2_CRC32_CHKSUM;
123 tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE;
124 tmp->h_chksum[0] = cpu_to_be32(crc32_sum);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700125 }
126
Girish Shilamkar818d2762008-01-28 23:58:27 -0500127 JBUFFER_TRACE(descriptor, "submit commit block");
128 lock_buffer(bh);
Aneesh Kumar K.Vc4b8e632008-02-05 10:55:26 -0500129 get_bh(bh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700130 set_buffer_dirty(bh);
Girish Shilamkar818d2762008-01-28 23:58:27 -0500131 set_buffer_uptodate(bh);
132 bh->b_end_io = journal_end_buffer_io_sync;
133
134 if (journal->j_flags & JBD2_BARRIER &&
Aneesh Kumar K.V4d605172008-02-05 10:56:15 -0500135 !JBD2_HAS_INCOMPAT_FEATURE(journal,
Girish Shilamkar818d2762008-01-28 23:58:27 -0500136 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
Dave Kleikamp470decc2006-10-11 01:20:57 -0700137 set_buffer_ordered(bh);
138 barrier_done = 1;
139 }
Girish Shilamkar818d2762008-01-28 23:58:27 -0500140 ret = submit_bh(WRITE, bh);
Dave Kleikampc4e35e072008-02-10 01:09:32 -0500141 if (barrier_done)
142 clear_buffer_ordered(bh);
Girish Shilamkar818d2762008-01-28 23:58:27 -0500143
Dave Kleikamp470decc2006-10-11 01:20:57 -0700144 /* is it possible for another commit to fail at roughly
145 * the same time as this one? If so, we don't want to
146 * trust the barrier flag in the super, but instead want
147 * to remember if we sent a barrier request
148 */
149 if (ret == -EOPNOTSUPP && barrier_done) {
150 char b[BDEVNAME_SIZE];
151
152 printk(KERN_WARNING
153 "JBD: barrier-based sync failed on %s - "
154 "disabling barriers\n",
155 bdevname(journal->j_dev, b));
156 spin_lock(&journal->j_state_lock);
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700157 journal->j_flags &= ~JBD2_BARRIER;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700158 spin_unlock(&journal->j_state_lock);
159
160 /* And try again, without the barrier */
Theodore Ts'o034772b2008-06-03 22:31:11 -0400161 lock_buffer(bh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700162 set_buffer_uptodate(bh);
163 set_buffer_dirty(bh);
Girish Shilamkar818d2762008-01-28 23:58:27 -0500164 ret = submit_bh(WRITE, bh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700165 }
Girish Shilamkar818d2762008-01-28 23:58:27 -0500166 *cbh = bh;
167 return ret;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700168}
169
Girish Shilamkar818d2762008-01-28 23:58:27 -0500170/*
171 * This function along with journal_submit_commit_record
172 * allows to write the commit record asynchronously.
173 */
174static int journal_wait_on_commit_record(struct buffer_head *bh)
175{
176 int ret = 0;
177
178 clear_buffer_dirty(bh);
179 wait_on_buffer(bh);
180
181 if (unlikely(!buffer_uptodate(bh)))
182 ret = -EIO;
183 put_bh(bh); /* One for getblk() */
184 jbd2_journal_put_journal_head(bh2jh(bh));
185
186 return ret;
187}
188
189/*
Aneesh Kumar K.Vcd1aac32008-07-11 19:27:31 -0400190 * write the filemap data using writepage() address_space_operations.
191 * We don't do block allocation here even for delalloc. We don't
192 * use writepages() because with dealyed allocation we may be doing
193 * block allocation in writepages().
194 */
195static int journal_submit_inode_data_buffers(struct address_space *mapping)
196{
197 int ret;
198 struct writeback_control wbc = {
199 .sync_mode = WB_SYNC_ALL,
200 .nr_to_write = mapping->nrpages * 2,
201 .range_start = 0,
202 .range_end = i_size_read(mapping->host),
203 .for_writepages = 1,
204 };
205
206 ret = generic_writepages(mapping, &wbc);
207 return ret;
208}
209
210/*
Jan Karac851ed52008-07-11 19:27:31 -0400211 * Submit all the data buffers of inode associated with the transaction to
212 * disk.
213 *
214 * We are in a committing transaction. Therefore no new inode can be added to
215 * our inode list. We use JI_COMMIT_RUNNING flag to protect inode we currently
216 * operate on from being released while we write out pages.
217 */
Aneesh Kumar K.Vcd1aac32008-07-11 19:27:31 -0400218static int journal_submit_data_buffers(journal_t *journal,
Jan Karac851ed52008-07-11 19:27:31 -0400219 transaction_t *commit_transaction)
220{
221 struct jbd2_inode *jinode;
222 int err, ret = 0;
223 struct address_space *mapping;
224
225 spin_lock(&journal->j_list_lock);
226 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
227 mapping = jinode->i_vfs_inode->i_mapping;
228 jinode->i_flags |= JI_COMMIT_RUNNING;
229 spin_unlock(&journal->j_list_lock);
Aneesh Kumar K.Vcd1aac32008-07-11 19:27:31 -0400230 /*
231 * submit the inode data buffers. We use writepage
232 * instead of writepages. Because writepages can do
233 * block allocation with delalloc. We need to write
234 * only allocated blocks here.
235 */
236 err = journal_submit_inode_data_buffers(mapping);
Jan Karac851ed52008-07-11 19:27:31 -0400237 if (!ret)
238 ret = err;
239 spin_lock(&journal->j_list_lock);
240 J_ASSERT(jinode->i_transaction == commit_transaction);
241 jinode->i_flags &= ~JI_COMMIT_RUNNING;
242 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
243 }
244 spin_unlock(&journal->j_list_lock);
245 return ret;
246}
247
248/*
249 * Wait for data submitted for writeout, refile inodes to proper
250 * transaction if needed.
251 *
252 */
253static int journal_finish_inode_data_buffers(journal_t *journal,
254 transaction_t *commit_transaction)
255{
256 struct jbd2_inode *jinode, *next_i;
257 int err, ret = 0;
258
Aneesh Kumar K.Vcd1aac32008-07-11 19:27:31 -0400259 /* For locking, see the comment in journal_submit_data_buffers() */
Jan Karac851ed52008-07-11 19:27:31 -0400260 spin_lock(&journal->j_list_lock);
261 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
262 jinode->i_flags |= JI_COMMIT_RUNNING;
263 spin_unlock(&journal->j_list_lock);
264 err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping);
265 if (!ret)
266 ret = err;
267 spin_lock(&journal->j_list_lock);
268 jinode->i_flags &= ~JI_COMMIT_RUNNING;
269 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
270 }
271
272 /* Now refile inode to proper lists */
273 list_for_each_entry_safe(jinode, next_i,
274 &commit_transaction->t_inode_list, i_list) {
275 list_del(&jinode->i_list);
276 if (jinode->i_next_transaction) {
277 jinode->i_transaction = jinode->i_next_transaction;
278 jinode->i_next_transaction = NULL;
279 list_add(&jinode->i_list,
280 &jinode->i_transaction->t_inode_list);
281 } else {
282 jinode->i_transaction = NULL;
283 }
284 }
285 spin_unlock(&journal->j_list_lock);
286
287 return ret;
288}
289
Girish Shilamkar818d2762008-01-28 23:58:27 -0500290static __u32 jbd2_checksum_data(__u32 crc32_sum, struct buffer_head *bh)
291{
292 struct page *page = bh->b_page;
293 char *addr;
294 __u32 checksum;
295
296 addr = kmap_atomic(page, KM_USER0);
297 checksum = crc32_be(crc32_sum,
298 (void *)(addr + offset_in_page(bh->b_data)), bh->b_size);
299 kunmap_atomic(addr, KM_USER0);
300
301 return checksum;
302}
303
304static void write_tag_block(int tag_bytes, journal_block_tag_t *tag,
Mingming Cao18eba7a2006-10-11 01:21:13 -0700305 unsigned long long block)
Zach Brownb517bea2006-10-11 01:21:08 -0700306{
307 tag->t_blocknr = cpu_to_be32(block & (u32)~0);
Mingming Caocd02ff02007-10-16 18:38:25 -0400308 if (tag_bytes > JBD2_TAG_SIZE32)
Zach Brownb517bea2006-10-11 01:21:08 -0700309 tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1);
310}
311
Dave Kleikamp470decc2006-10-11 01:20:57 -0700312/*
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700313 * jbd2_journal_commit_transaction
Dave Kleikamp470decc2006-10-11 01:20:57 -0700314 *
315 * The primary function for committing a transaction to the log. This
316 * function is called by the journal thread to begin a complete commit.
317 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700318void jbd2_journal_commit_transaction(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700319{
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500320 struct transaction_stats_s stats;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700321 transaction_t *commit_transaction;
322 struct journal_head *jh, *new_jh, *descriptor;
323 struct buffer_head **wbuf = journal->j_wbuf;
324 int bufs;
325 int flags;
326 int err;
Mingming Cao18eba7a2006-10-11 01:21:13 -0700327 unsigned long long blocknr;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700328 char *tagp = NULL;
329 journal_header_t *header;
330 journal_block_tag_t *tag = NULL;
331 int space_left = 0;
332 int first_tag = 0;
333 int tag_flag;
334 int i;
Zach Brownb517bea2006-10-11 01:21:08 -0700335 int tag_bytes = journal_tag_bytes(journal);
Girish Shilamkar818d2762008-01-28 23:58:27 -0500336 struct buffer_head *cbh = NULL; /* For transactional checksums */
337 __u32 crc32_sum = ~0;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700338
339 /*
340 * First job: lock down the current transaction and wait for
341 * all outstanding updates to complete.
342 */
343
344#ifdef COMMIT_STATS
345 spin_lock(&journal->j_list_lock);
346 summarise_journal_usage(journal);
347 spin_unlock(&journal->j_list_lock);
348#endif
349
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700350 /* Do we need to erase the effects of a prior jbd2_journal_flush? */
351 if (journal->j_flags & JBD2_FLUSHED) {
Dave Kleikamp470decc2006-10-11 01:20:57 -0700352 jbd_debug(3, "super block updated\n");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700353 jbd2_journal_update_superblock(journal, 1);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700354 } else {
355 jbd_debug(3, "superblock not updated\n");
356 }
357
358 J_ASSERT(journal->j_running_transaction != NULL);
359 J_ASSERT(journal->j_committing_transaction == NULL);
360
361 commit_transaction = journal->j_running_transaction;
362 J_ASSERT(commit_transaction->t_state == T_RUNNING);
363
364 jbd_debug(1, "JBD: starting commit of transaction %d\n",
365 commit_transaction->t_tid);
366
367 spin_lock(&journal->j_state_lock);
368 commit_transaction->t_state = T_LOCKED;
369
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500370 stats.u.run.rs_wait = commit_transaction->t_max_wait;
371 stats.u.run.rs_locked = jiffies;
372 stats.u.run.rs_running = jbd2_time_diff(commit_transaction->t_start,
373 stats.u.run.rs_locked);
374
Dave Kleikamp470decc2006-10-11 01:20:57 -0700375 spin_lock(&commit_transaction->t_handle_lock);
376 while (commit_transaction->t_updates) {
377 DEFINE_WAIT(wait);
378
379 prepare_to_wait(&journal->j_wait_updates, &wait,
380 TASK_UNINTERRUPTIBLE);
381 if (commit_transaction->t_updates) {
382 spin_unlock(&commit_transaction->t_handle_lock);
383 spin_unlock(&journal->j_state_lock);
384 schedule();
385 spin_lock(&journal->j_state_lock);
386 spin_lock(&commit_transaction->t_handle_lock);
387 }
388 finish_wait(&journal->j_wait_updates, &wait);
389 }
390 spin_unlock(&commit_transaction->t_handle_lock);
391
392 J_ASSERT (commit_transaction->t_outstanding_credits <=
393 journal->j_max_transaction_buffers);
394
395 /*
396 * First thing we are allowed to do is to discard any remaining
397 * BJ_Reserved buffers. Note, it is _not_ permissible to assume
398 * that there are no such buffers: if a large filesystem
399 * operation like a truncate needs to split itself over multiple
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700400 * transactions, then it may try to do a jbd2_journal_restart() while
Dave Kleikamp470decc2006-10-11 01:20:57 -0700401 * there are still BJ_Reserved buffers outstanding. These must
402 * be released cleanly from the current transaction.
403 *
404 * In this case, the filesystem must still reserve write access
405 * again before modifying the buffer in the new transaction, but
406 * we do not require it to remember exactly which old buffers it
407 * has reserved. This is consistent with the existing behaviour
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700408 * that multiple jbd2_journal_get_write_access() calls to the same
Dave Kleikamp470decc2006-10-11 01:20:57 -0700409 * buffer are perfectly permissable.
410 */
411 while (commit_transaction->t_reserved_list) {
412 jh = commit_transaction->t_reserved_list;
413 JBUFFER_TRACE(jh, "reserved, unused: refile");
414 /*
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700415 * A jbd2_journal_get_undo_access()+jbd2_journal_release_buffer() may
Dave Kleikamp470decc2006-10-11 01:20:57 -0700416 * leave undo-committed data.
417 */
418 if (jh->b_committed_data) {
419 struct buffer_head *bh = jh2bh(jh);
420
421 jbd_lock_bh_state(bh);
Mingming Caoaf1e76d2007-10-16 18:38:25 -0400422 jbd2_free(jh->b_committed_data, bh->b_size);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700423 jh->b_committed_data = NULL;
424 jbd_unlock_bh_state(bh);
425 }
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700426 jbd2_journal_refile_buffer(journal, jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700427 }
428
429 /*
430 * Now try to drop any written-back buffers from the journal's
431 * checkpoint lists. We do this *before* commit because it potentially
432 * frees some memory
433 */
434 spin_lock(&journal->j_list_lock);
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700435 __jbd2_journal_clean_checkpoint_list(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700436 spin_unlock(&journal->j_list_lock);
437
438 jbd_debug (3, "JBD: commit phase 1\n");
439
440 /*
441 * Switch to a new revoke table.
442 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700443 jbd2_journal_switch_revoke_table(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700444
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500445 stats.u.run.rs_flushing = jiffies;
446 stats.u.run.rs_locked = jbd2_time_diff(stats.u.run.rs_locked,
447 stats.u.run.rs_flushing);
448
Dave Kleikamp470decc2006-10-11 01:20:57 -0700449 commit_transaction->t_state = T_FLUSH;
450 journal->j_committing_transaction = commit_transaction;
451 journal->j_running_transaction = NULL;
452 commit_transaction->t_log_start = journal->j_head;
453 wake_up(&journal->j_wait_transaction_locked);
454 spin_unlock(&journal->j_state_lock);
455
456 jbd_debug (3, "JBD: commit phase 2\n");
457
458 /*
Dave Kleikamp470decc2006-10-11 01:20:57 -0700459 * Now start flushing things to disk, in the order they appear
460 * on the transaction lists. Data blocks go first.
461 */
Aneesh Kumar K.Vcd1aac32008-07-11 19:27:31 -0400462 err = journal_submit_data_buffers(journal, commit_transaction);
Jan Karac851ed52008-07-11 19:27:31 -0400463 if (err)
464 jbd2_journal_abort(journal, err);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700465
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700466 jbd2_journal_write_revoke_records(journal, commit_transaction);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700467
468 jbd_debug(3, "JBD: commit phase 2\n");
469
470 /*
Dave Kleikamp470decc2006-10-11 01:20:57 -0700471 * Way to go: we have now written out all of the data for a
472 * transaction! Now comes the tricky part: we need to write out
473 * metadata. Loop over the transaction's entire buffer list:
474 */
Mingming Cao02c471c2008-05-15 14:46:17 -0400475 spin_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700476 commit_transaction->t_state = T_COMMIT;
Mingming Cao02c471c2008-05-15 14:46:17 -0400477 spin_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700478
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500479 stats.u.run.rs_logging = jiffies;
480 stats.u.run.rs_flushing = jbd2_time_diff(stats.u.run.rs_flushing,
481 stats.u.run.rs_logging);
482 stats.u.run.rs_blocks = commit_transaction->t_outstanding_credits;
483 stats.u.run.rs_blocks_logged = 0;
484
Josef Bacik1dfc3222008-04-17 10:38:59 -0400485 J_ASSERT(commit_transaction->t_nr_buffers <=
486 commit_transaction->t_outstanding_credits);
487
Jan Kara87c89c22008-07-11 19:27:31 -0400488 err = 0;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700489 descriptor = NULL;
490 bufs = 0;
491 while (commit_transaction->t_buffers) {
492
493 /* Find the next buffer to be journaled... */
494
495 jh = commit_transaction->t_buffers;
496
497 /* If we're in abort mode, we just un-journal the buffer and
498 release it for background writing. */
499
500 if (is_journal_aborted(journal)) {
501 JBUFFER_TRACE(jh, "journal is aborting: refile");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700502 jbd2_journal_refile_buffer(journal, jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700503 /* If that was the last one, we need to clean up
504 * any descriptor buffers which may have been
505 * already allocated, even if we are now
506 * aborting. */
507 if (!commit_transaction->t_buffers)
508 goto start_journal_io;
509 continue;
510 }
511
512 /* Make sure we have a descriptor block in which to
513 record the metadata buffer. */
514
515 if (!descriptor) {
516 struct buffer_head *bh;
517
518 J_ASSERT (bufs == 0);
519
520 jbd_debug(4, "JBD: get descriptor\n");
521
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700522 descriptor = jbd2_journal_get_descriptor_buffer(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700523 if (!descriptor) {
Jan Karaa7fa2ba2007-10-16 18:38:25 -0400524 jbd2_journal_abort(journal, -EIO);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700525 continue;
526 }
527
528 bh = jh2bh(descriptor);
529 jbd_debug(4, "JBD: got buffer %llu (%p)\n",
530 (unsigned long long)bh->b_blocknr, bh->b_data);
531 header = (journal_header_t *)&bh->b_data[0];
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700532 header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
533 header->h_blocktype = cpu_to_be32(JBD2_DESCRIPTOR_BLOCK);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700534 header->h_sequence = cpu_to_be32(commit_transaction->t_tid);
535
536 tagp = &bh->b_data[sizeof(journal_header_t)];
537 space_left = bh->b_size - sizeof(journal_header_t);
538 first_tag = 1;
539 set_buffer_jwrite(bh);
540 set_buffer_dirty(bh);
541 wbuf[bufs++] = bh;
542
543 /* Record it so that we can wait for IO
544 completion later */
545 BUFFER_TRACE(bh, "ph3: file as descriptor");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700546 jbd2_journal_file_buffer(descriptor, commit_transaction,
Dave Kleikamp470decc2006-10-11 01:20:57 -0700547 BJ_LogCtl);
548 }
549
550 /* Where is the buffer to be written? */
551
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700552 err = jbd2_journal_next_log_block(journal, &blocknr);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700553 /* If the block mapping failed, just abandon the buffer
554 and repeat this loop: we'll fall into the
555 refile-on-abort condition above. */
556 if (err) {
Jan Karaa7fa2ba2007-10-16 18:38:25 -0400557 jbd2_journal_abort(journal, err);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700558 continue;
559 }
560
561 /*
562 * start_this_handle() uses t_outstanding_credits to determine
563 * the free space in the log, but this counter is changed
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700564 * by jbd2_journal_next_log_block() also.
Dave Kleikamp470decc2006-10-11 01:20:57 -0700565 */
566 commit_transaction->t_outstanding_credits--;
567
568 /* Bump b_count to prevent truncate from stumbling over
569 the shadowed buffer! @@@ This can go if we ever get
570 rid of the BJ_IO/BJ_Shadow pairing of buffers. */
571 atomic_inc(&jh2bh(jh)->b_count);
572
573 /* Make a temporary IO buffer with which to write it out
574 (this will requeue both the metadata buffer and the
575 temporary IO buffer). new_bh goes on BJ_IO*/
576
577 set_bit(BH_JWrite, &jh2bh(jh)->b_state);
578 /*
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700579 * akpm: jbd2_journal_write_metadata_buffer() sets
Dave Kleikamp470decc2006-10-11 01:20:57 -0700580 * new_bh->b_transaction to commit_transaction.
581 * We need to clean this up before we release new_bh
582 * (which is of type BJ_IO)
583 */
584 JBUFFER_TRACE(jh, "ph3: write metadata");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700585 flags = jbd2_journal_write_metadata_buffer(commit_transaction,
Dave Kleikamp470decc2006-10-11 01:20:57 -0700586 jh, &new_jh, blocknr);
587 set_bit(BH_JWrite, &jh2bh(new_jh)->b_state);
588 wbuf[bufs++] = jh2bh(new_jh);
589
590 /* Record the new block's tag in the current descriptor
591 buffer */
592
593 tag_flag = 0;
594 if (flags & 1)
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700595 tag_flag |= JBD2_FLAG_ESCAPE;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700596 if (!first_tag)
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700597 tag_flag |= JBD2_FLAG_SAME_UUID;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700598
599 tag = (journal_block_tag_t *) tagp;
Zach Brownb517bea2006-10-11 01:21:08 -0700600 write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700601 tag->t_flags = cpu_to_be32(tag_flag);
Zach Brownb517bea2006-10-11 01:21:08 -0700602 tagp += tag_bytes;
603 space_left -= tag_bytes;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700604
605 if (first_tag) {
606 memcpy (tagp, journal->j_uuid, 16);
607 tagp += 16;
608 space_left -= 16;
609 first_tag = 0;
610 }
611
612 /* If there's no more to do, or if the descriptor is full,
613 let the IO rip! */
614
615 if (bufs == journal->j_wbufsize ||
616 commit_transaction->t_buffers == NULL ||
Zach Brownb517bea2006-10-11 01:21:08 -0700617 space_left < tag_bytes + 16) {
Dave Kleikamp470decc2006-10-11 01:20:57 -0700618
619 jbd_debug(4, "JBD: Submit %d IOs\n", bufs);
620
621 /* Write an end-of-descriptor marker before
622 submitting the IOs. "tag" still points to
623 the last tag we set up. */
624
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700625 tag->t_flags |= cpu_to_be32(JBD2_FLAG_LAST_TAG);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700626
627start_journal_io:
628 for (i = 0; i < bufs; i++) {
629 struct buffer_head *bh = wbuf[i];
Girish Shilamkar818d2762008-01-28 23:58:27 -0500630 /*
631 * Compute checksum.
632 */
633 if (JBD2_HAS_COMPAT_FEATURE(journal,
634 JBD2_FEATURE_COMPAT_CHECKSUM)) {
635 crc32_sum =
636 jbd2_checksum_data(crc32_sum, bh);
637 }
638
Dave Kleikamp470decc2006-10-11 01:20:57 -0700639 lock_buffer(bh);
640 clear_buffer_dirty(bh);
641 set_buffer_uptodate(bh);
642 bh->b_end_io = journal_end_buffer_io_sync;
643 submit_bh(WRITE, bh);
644 }
645 cond_resched();
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500646 stats.u.run.rs_blocks_logged += bufs;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700647
648 /* Force a new descriptor to be generated next
649 time round the loop. */
650 descriptor = NULL;
651 bufs = 0;
652 }
653 }
654
Girish Shilamkar818d2762008-01-28 23:58:27 -0500655 /* Done it all: now write the commit record asynchronously. */
656
657 if (JBD2_HAS_INCOMPAT_FEATURE(journal,
658 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
659 err = journal_submit_commit_record(journal, commit_transaction,
660 &cbh, crc32_sum);
661 if (err)
662 __jbd2_journal_abort_hard(journal);
Girish Shilamkar818d2762008-01-28 23:58:27 -0500663 }
664
Jan Karac851ed52008-07-11 19:27:31 -0400665 /*
666 * This is the right place to wait for data buffers both for ASYNC
667 * and !ASYNC commit. If commit is ASYNC, we need to wait only after
668 * the commit block went to disk (which happens above). If commit is
669 * SYNC, we need to wait for data buffers before we start writing
670 * commit block, which happens below in such setting.
671 */
672 err = journal_finish_inode_data_buffers(journal, commit_transaction);
673 if (err)
674 jbd2_journal_abort(journal, err);
675
Dave Kleikamp470decc2006-10-11 01:20:57 -0700676 /* Lo and behold: we have just managed to send a transaction to
677 the log. Before we can commit it, wait for the IO so far to
678 complete. Control buffers being written are on the
679 transaction's t_log_list queue, and metadata buffers are on
680 the t_iobuf_list queue.
681
682 Wait for the buffers in reverse order. That way we are
683 less likely to be woken up until all IOs have completed, and
684 so we incur less scheduling load.
685 */
686
Jan Kara87c89c22008-07-11 19:27:31 -0400687 jbd_debug(3, "JBD: commit phase 3\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -0700688
689 /*
690 * akpm: these are BJ_IO, and j_list_lock is not needed.
691 * See __journal_try_to_free_buffer.
692 */
693wait_for_iobuf:
694 while (commit_transaction->t_iobuf_list != NULL) {
695 struct buffer_head *bh;
696
697 jh = commit_transaction->t_iobuf_list->b_tprev;
698 bh = jh2bh(jh);
699 if (buffer_locked(bh)) {
700 wait_on_buffer(bh);
701 goto wait_for_iobuf;
702 }
703 if (cond_resched())
704 goto wait_for_iobuf;
705
706 if (unlikely(!buffer_uptodate(bh)))
707 err = -EIO;
708
709 clear_buffer_jwrite(bh);
710
711 JBUFFER_TRACE(jh, "ph4: unfile after journal write");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700712 jbd2_journal_unfile_buffer(journal, jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700713
714 /*
715 * ->t_iobuf_list should contain only dummy buffer_heads
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700716 * which were created by jbd2_journal_write_metadata_buffer().
Dave Kleikamp470decc2006-10-11 01:20:57 -0700717 */
718 BUFFER_TRACE(bh, "dumping temporary bh");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700719 jbd2_journal_put_journal_head(jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700720 __brelse(bh);
721 J_ASSERT_BH(bh, atomic_read(&bh->b_count) == 0);
722 free_buffer_head(bh);
723
724 /* We also have to unlock and free the corresponding
725 shadowed buffer */
726 jh = commit_transaction->t_shadow_list->b_tprev;
727 bh = jh2bh(jh);
728 clear_bit(BH_JWrite, &bh->b_state);
729 J_ASSERT_BH(bh, buffer_jbddirty(bh));
730
731 /* The metadata is now released for reuse, but we need
732 to remember it against this transaction so that when
733 we finally commit, we can do any checkpointing
734 required. */
735 JBUFFER_TRACE(jh, "file as BJ_Forget");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700736 jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700737 /* Wake up any transactions which were waiting for this
738 IO to complete */
739 wake_up_bit(&bh->b_state, BH_Unshadow);
740 JBUFFER_TRACE(jh, "brelse shadowed buffer");
741 __brelse(bh);
742 }
743
744 J_ASSERT (commit_transaction->t_shadow_list == NULL);
745
Jan Kara87c89c22008-07-11 19:27:31 -0400746 jbd_debug(3, "JBD: commit phase 4\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -0700747
748 /* Here we wait for the revoke record and descriptor record buffers */
749 wait_for_ctlbuf:
750 while (commit_transaction->t_log_list != NULL) {
751 struct buffer_head *bh;
752
753 jh = commit_transaction->t_log_list->b_tprev;
754 bh = jh2bh(jh);
755 if (buffer_locked(bh)) {
756 wait_on_buffer(bh);
757 goto wait_for_ctlbuf;
758 }
759 if (cond_resched())
760 goto wait_for_ctlbuf;
761
762 if (unlikely(!buffer_uptodate(bh)))
763 err = -EIO;
764
765 BUFFER_TRACE(bh, "ph5: control buffer writeout done: unfile");
766 clear_buffer_jwrite(bh);
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700767 jbd2_journal_unfile_buffer(journal, jh);
768 jbd2_journal_put_journal_head(jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700769 __brelse(bh); /* One for getblk */
770 /* AKPM: bforget here */
771 }
772
Jan Kara87c89c22008-07-11 19:27:31 -0400773 jbd_debug(3, "JBD: commit phase 5\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -0700774
Girish Shilamkar818d2762008-01-28 23:58:27 -0500775 if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
776 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
777 err = journal_submit_commit_record(journal, commit_transaction,
778 &cbh, crc32_sum);
779 if (err)
780 __jbd2_journal_abort_hard(journal);
781 }
Mingming Caob048d842008-02-05 08:52:45 -0500782 if (!err && !is_journal_aborted(journal))
783 err = journal_wait_on_commit_record(cbh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700784
785 if (err)
Jan Karaa7fa2ba2007-10-16 18:38:25 -0400786 jbd2_journal_abort(journal, err);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700787
788 /* End of a transaction! Finally, we can do checkpoint
789 processing: any buffers committed as a result of this
790 transaction can be removed from any checkpoint list it was on
791 before. */
792
Jan Kara87c89c22008-07-11 19:27:31 -0400793 jbd_debug(3, "JBD: commit phase 6\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -0700794
Jan Karac851ed52008-07-11 19:27:31 -0400795 J_ASSERT(list_empty(&commit_transaction->t_inode_list));
Dave Kleikamp470decc2006-10-11 01:20:57 -0700796 J_ASSERT(commit_transaction->t_buffers == NULL);
797 J_ASSERT(commit_transaction->t_checkpoint_list == NULL);
798 J_ASSERT(commit_transaction->t_iobuf_list == NULL);
799 J_ASSERT(commit_transaction->t_shadow_list == NULL);
800 J_ASSERT(commit_transaction->t_log_list == NULL);
801
802restart_loop:
803 /*
804 * As there are other places (journal_unmap_buffer()) adding buffers
805 * to this list we have to be careful and hold the j_list_lock.
806 */
807 spin_lock(&journal->j_list_lock);
808 while (commit_transaction->t_forget) {
809 transaction_t *cp_transaction;
810 struct buffer_head *bh;
811
812 jh = commit_transaction->t_forget;
813 spin_unlock(&journal->j_list_lock);
814 bh = jh2bh(jh);
815 jbd_lock_bh_state(bh);
816 J_ASSERT_JH(jh, jh->b_transaction == commit_transaction ||
817 jh->b_transaction == journal->j_running_transaction);
818
819 /*
820 * If there is undo-protected committed data against
821 * this buffer, then we can remove it now. If it is a
822 * buffer needing such protection, the old frozen_data
823 * field now points to a committed version of the
824 * buffer, so rotate that field to the new committed
825 * data.
826 *
827 * Otherwise, we can just throw away the frozen data now.
828 */
829 if (jh->b_committed_data) {
Mingming Caoaf1e76d2007-10-16 18:38:25 -0400830 jbd2_free(jh->b_committed_data, bh->b_size);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700831 jh->b_committed_data = NULL;
832 if (jh->b_frozen_data) {
833 jh->b_committed_data = jh->b_frozen_data;
834 jh->b_frozen_data = NULL;
835 }
836 } else if (jh->b_frozen_data) {
Mingming Caoaf1e76d2007-10-16 18:38:25 -0400837 jbd2_free(jh->b_frozen_data, bh->b_size);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700838 jh->b_frozen_data = NULL;
839 }
840
841 spin_lock(&journal->j_list_lock);
842 cp_transaction = jh->b_cp_transaction;
843 if (cp_transaction) {
844 JBUFFER_TRACE(jh, "remove from old cp transaction");
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500845 cp_transaction->t_chp_stats.cs_dropped++;
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700846 __jbd2_journal_remove_checkpoint(jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700847 }
848
849 /* Only re-checkpoint the buffer_head if it is marked
850 * dirty. If the buffer was added to the BJ_Forget list
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700851 * by jbd2_journal_forget, it may no longer be dirty and
Dave Kleikamp470decc2006-10-11 01:20:57 -0700852 * there's no point in keeping a checkpoint record for
853 * it. */
854
855 /* A buffer which has been freed while still being
856 * journaled by a previous transaction may end up still
857 * being dirty here, but we want to avoid writing back
858 * that buffer in the future now that the last use has
859 * been committed. That's not only a performance gain,
860 * it also stops aliasing problems if the buffer is left
861 * behind for writeback and gets reallocated for another
862 * use in a different page. */
863 if (buffer_freed(bh)) {
864 clear_buffer_freed(bh);
865 clear_buffer_jbddirty(bh);
866 }
867
868 if (buffer_jbddirty(bh)) {
869 JBUFFER_TRACE(jh, "add to new checkpointing trans");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700870 __jbd2_journal_insert_checkpoint(jh, commit_transaction);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700871 JBUFFER_TRACE(jh, "refile for checkpoint writeback");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700872 __jbd2_journal_refile_buffer(jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700873 jbd_unlock_bh_state(bh);
874 } else {
875 J_ASSERT_BH(bh, !buffer_dirty(bh));
876 /* The buffer on BJ_Forget list and not jbddirty means
877 * it has been freed by this transaction and hence it
878 * could not have been reallocated until this
879 * transaction has committed. *BUT* it could be
880 * reallocated once we have written all the data to
881 * disk and before we process the buffer on BJ_Forget
882 * list. */
883 JBUFFER_TRACE(jh, "refile or unfile freed buffer");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700884 __jbd2_journal_refile_buffer(jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700885 if (!jh->b_transaction) {
886 jbd_unlock_bh_state(bh);
887 /* needs a brelse */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700888 jbd2_journal_remove_journal_head(bh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700889 release_buffer_page(bh);
890 } else
891 jbd_unlock_bh_state(bh);
892 }
893 cond_resched_lock(&journal->j_list_lock);
894 }
895 spin_unlock(&journal->j_list_lock);
896 /*
Jan Karaf5a7a6b2008-01-28 23:58:27 -0500897 * This is a bit sleazy. We use j_list_lock to protect transition
898 * of a transaction into T_FINISHED state and calling
899 * __jbd2_journal_drop_transaction(). Otherwise we could race with
900 * other checkpointing code processing the transaction...
Dave Kleikamp470decc2006-10-11 01:20:57 -0700901 */
902 spin_lock(&journal->j_state_lock);
903 spin_lock(&journal->j_list_lock);
904 /*
905 * Now recheck if some buffers did not get attached to the transaction
906 * while the lock was dropped...
907 */
908 if (commit_transaction->t_forget) {
909 spin_unlock(&journal->j_list_lock);
910 spin_unlock(&journal->j_state_lock);
911 goto restart_loop;
912 }
913
914 /* Done with this transaction! */
915
Jan Kara87c89c22008-07-11 19:27:31 -0400916 jbd_debug(3, "JBD: commit phase 7\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -0700917
918 J_ASSERT(commit_transaction->t_state == T_COMMIT);
919
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500920 commit_transaction->t_start = jiffies;
921 stats.u.run.rs_logging = jbd2_time_diff(stats.u.run.rs_logging,
922 commit_transaction->t_start);
923
924 /*
925 * File the transaction for history
926 */
927 stats.ts_type = JBD2_STATS_RUN;
928 stats.ts_tid = commit_transaction->t_tid;
929 stats.u.run.rs_handle_count = commit_transaction->t_handle_count;
930 spin_lock(&journal->j_history_lock);
931 memcpy(journal->j_history + journal->j_history_cur, &stats,
932 sizeof(stats));
933 if (++journal->j_history_cur == journal->j_history_max)
934 journal->j_history_cur = 0;
935
936 /*
937 * Calculate overall stats
938 */
939 journal->j_stats.ts_tid++;
940 journal->j_stats.u.run.rs_wait += stats.u.run.rs_wait;
941 journal->j_stats.u.run.rs_running += stats.u.run.rs_running;
942 journal->j_stats.u.run.rs_locked += stats.u.run.rs_locked;
943 journal->j_stats.u.run.rs_flushing += stats.u.run.rs_flushing;
944 journal->j_stats.u.run.rs_logging += stats.u.run.rs_logging;
945 journal->j_stats.u.run.rs_handle_count += stats.u.run.rs_handle_count;
946 journal->j_stats.u.run.rs_blocks += stats.u.run.rs_blocks;
947 journal->j_stats.u.run.rs_blocks_logged += stats.u.run.rs_blocks_logged;
948 spin_unlock(&journal->j_history_lock);
949
Dave Kleikamp470decc2006-10-11 01:20:57 -0700950 commit_transaction->t_state = T_FINISHED;
951 J_ASSERT(commit_transaction == journal->j_committing_transaction);
952 journal->j_commit_sequence = commit_transaction->t_tid;
953 journal->j_committing_transaction = NULL;
954 spin_unlock(&journal->j_state_lock);
955
Jan Karaf89b7792007-07-15 23:37:20 -0700956 if (commit_transaction->t_checkpoint_list == NULL &&
957 commit_transaction->t_checkpoint_io_list == NULL) {
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700958 __jbd2_journal_drop_transaction(journal, commit_transaction);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700959 } else {
960 if (journal->j_checkpoint_transactions == NULL) {
961 journal->j_checkpoint_transactions = commit_transaction;
962 commit_transaction->t_cpnext = commit_transaction;
963 commit_transaction->t_cpprev = commit_transaction;
964 } else {
965 commit_transaction->t_cpnext =
966 journal->j_checkpoint_transactions;
967 commit_transaction->t_cpprev =
968 commit_transaction->t_cpnext->t_cpprev;
969 commit_transaction->t_cpnext->t_cpprev =
970 commit_transaction;
971 commit_transaction->t_cpprev->t_cpnext =
972 commit_transaction;
973 }
974 }
975 spin_unlock(&journal->j_list_lock);
976
977 jbd_debug(1, "JBD: commit %d complete, head %d\n",
978 journal->j_commit_sequence, journal->j_tail_sequence);
979
980 wake_up(&journal->j_wait_done_commit);
981}