^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/jbd2/commit.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by Stephen C. Tweedie <sct@redhat.com>, 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright 1998 Red Hat corp --- All Rights Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Journal commit routines for the generic filesystem journaling code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * part of the ext2fs journaling system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/jbd2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <trace/events/jbd2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * IO end handler for temporary buffer_heads handling writes to the journal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static void journal_end_buffer_io_sync(struct buffer_head *bh, int uptodate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct buffer_head *orig_bh = bh->b_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) BUFFER_TRACE(bh, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (uptodate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) set_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) clear_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (orig_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) clear_bit_unlock(BH_Shadow, &orig_bh->b_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) wake_up_bit(&orig_bh->b_state, BH_Shadow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * When an ext4 file is truncated, it is possible that some pages are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * successfully freed, because they are attached to a committing transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * After the transaction commits, these pages are left on the LRU, with no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * ->mapping, and with attached buffers. These pages are trivially reclaimable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * by the VM, but their apparent absence upsets the VM accounting, and it makes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * the numbers in /proc/meminfo look odd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * So here, we have a buffer which has just come off the forget list. Look to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * see if we can strip all buffers from the backing page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * Called under lock_journal(), and possibly under journal_datalist_lock. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * caller provided us with a ref against the buffer, and we drop that here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static void release_buffer_page(struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (buffer_dirty(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) goto nope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (atomic_read(&bh->b_count) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) goto nope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) page = bh->b_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) goto nope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (page->mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) goto nope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* OK, it's a truncated page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (!trylock_page(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) goto nope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) get_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) __brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) try_to_free_buffers(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) nope:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) __brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void jbd2_commit_block_csum_set(journal_t *j, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct commit_header *h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) __u32 csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (!jbd2_journal_has_csum_v2or3(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) h = (struct commit_header *)(bh->b_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) h->h_chksum_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) h->h_chksum_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) h->h_chksum[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) h->h_chksum[0] = cpu_to_be32(csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * Done it all: now submit the commit record. We should have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * cleaned up our previous buffers by now, so if we are in abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * mode we can now just skip the rest of the journal write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * entirely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * Returns 1 if the journal needs to be aborted or 0 on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int journal_submit_commit_record(journal_t *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) transaction_t *commit_transaction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct buffer_head **cbh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) __u32 crc32_sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct commit_header *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct timespec64 now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) *cbh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (is_journal_aborted(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) bh = jbd2_journal_get_descriptor_buffer(commit_transaction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) JBD2_COMMIT_BLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) tmp = (struct commit_header *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ktime_get_coarse_real_ts64(&now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) tmp->h_commit_sec = cpu_to_be64(now.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (jbd2_has_feature_checksum(journal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) tmp->h_chksum_type = JBD2_CRC32_CHKSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) tmp->h_chksum[0] = cpu_to_be32(crc32_sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) jbd2_commit_block_csum_set(journal, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) BUFFER_TRACE(bh, "submit commit block");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) clear_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) set_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) bh->b_end_io = journal_end_buffer_io_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (journal->j_flags & JBD2_BARRIER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) !jbd2_has_feature_async_commit(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ret = submit_bh(REQ_OP_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) REQ_SYNC | REQ_PREFLUSH | REQ_FUA, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ret = submit_bh(REQ_OP_WRITE, REQ_SYNC, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) *cbh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * This function along with journal_submit_commit_record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * allows to write the commit record asynchronously.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int journal_wait_on_commit_record(journal_t *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) clear_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) wait_on_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (unlikely(!buffer_uptodate(bh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) put_bh(bh); /* One for getblk() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * write the filemap data using writepage() address_space_operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * We don't do block allocation here even for delalloc. We don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * use writepages() because with delayed allocation we may be doing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * block allocation in writepages().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) int jbd2_journal_submit_inode_data_buffers(struct jbd2_inode *jinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct address_space *mapping = jinode->i_vfs_inode->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct writeback_control wbc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) .sync_mode = WB_SYNC_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) .nr_to_write = mapping->nrpages * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) .range_start = jinode->i_dirty_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .range_end = jinode->i_dirty_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * submit the inode data buffers. We use writepage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * instead of writepages. Because writepages can do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * block allocation with delalloc. We need to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * only allocated blocks here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return generic_writepages(mapping, &wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* Send all the data buffers related to an inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int jbd2_submit_inode_data(struct jbd2_inode *jinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!jinode || !(jinode->i_flags & JI_WRITE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) trace_jbd2_submit_inode_data(jinode->i_vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return jbd2_journal_submit_inode_data_buffers(jinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) EXPORT_SYMBOL(jbd2_submit_inode_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (!jinode || !(jinode->i_flags & JI_WAIT_DATA) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) !jinode->i_vfs_inode || !jinode->i_vfs_inode->i_mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return filemap_fdatawait_range_keep_errors(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) jinode->i_vfs_inode->i_mapping, jinode->i_dirty_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) jinode->i_dirty_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) EXPORT_SYMBOL(jbd2_wait_inode_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Submit all the data buffers of inode associated with the transaction to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * We are in a committing transaction. Therefore no new inode can be added to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * our inode list. We use JI_COMMIT_RUNNING flag to protect inode we currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * operate on from being released while we write out pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static int journal_submit_data_buffers(journal_t *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) transaction_t *commit_transaction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct jbd2_inode *jinode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int err, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) spin_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!(jinode->i_flags & JI_WRITE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) jinode->i_flags |= JI_COMMIT_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* submit the inode data buffers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) trace_jbd2_submit_inode_data(jinode->i_vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (journal->j_submit_inode_data_buffers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) err = journal->j_submit_inode_data_buffers(jinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) spin_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) J_ASSERT(jinode->i_transaction == commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) jinode->i_flags &= ~JI_COMMIT_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) int jbd2_journal_finish_inode_data_buffers(struct jbd2_inode *jinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct address_space *mapping = jinode->i_vfs_inode->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return filemap_fdatawait_range_keep_errors(mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) jinode->i_dirty_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) jinode->i_dirty_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * Wait for data submitted for writeout, refile inodes to proper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * transaction if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static int journal_finish_inode_data_buffers(journal_t *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) transaction_t *commit_transaction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct jbd2_inode *jinode, *next_i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int err, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* For locking, see the comment in journal_submit_data_buffers() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) spin_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (!(jinode->i_flags & JI_WAIT_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) jinode->i_flags |= JI_COMMIT_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /* wait for the inode data buffers writeout. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (journal->j_finish_inode_data_buffers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) err = journal->j_finish_inode_data_buffers(jinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) spin_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) jinode->i_flags &= ~JI_COMMIT_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* Now refile inode to proper lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) list_for_each_entry_safe(jinode, next_i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) &commit_transaction->t_inode_list, i_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) list_del(&jinode->i_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (jinode->i_next_transaction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) jinode->i_transaction = jinode->i_next_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) jinode->i_next_transaction = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) list_add(&jinode->i_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) &jinode->i_transaction->t_inode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) jinode->i_transaction = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) jinode->i_dirty_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) jinode->i_dirty_end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static __u32 jbd2_checksum_data(__u32 crc32_sum, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct page *page = bh->b_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) char *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) __u32 checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) addr = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) checksum = crc32_be(crc32_sum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) (void *)(addr + offset_in_page(bh->b_data)), bh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) kunmap_atomic(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static void write_tag_block(journal_t *j, journal_block_tag_t *tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) unsigned long long block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) tag->t_blocknr = cpu_to_be32(block & (u32)~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (jbd2_has_feature_64bit(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct buffer_head *bh, __u32 sequence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) journal_block_tag3_t *tag3 = (journal_block_tag3_t *)tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct page *page = bh->b_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) __u8 *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) __u32 csum32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) __be32 seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (!jbd2_journal_has_csum_v2or3(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) seq = cpu_to_be32(sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) addr = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&seq, sizeof(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) csum32 = jbd2_chksum(j, csum32, addr + offset_in_page(bh->b_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) bh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) kunmap_atomic(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (jbd2_has_feature_csum3(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) tag3->t_checksum = cpu_to_be32(csum32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) tag->t_checksum = cpu_to_be16(csum32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * jbd2_journal_commit_transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * The primary function for committing a transaction to the log. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * function is called by the journal thread to begin a complete commit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) void jbd2_journal_commit_transaction(journal_t *journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) struct transaction_stats_s stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) transaction_t *commit_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct journal_head *jh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct buffer_head *descriptor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct buffer_head **wbuf = journal->j_wbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) int bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) unsigned long long blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) ktime_t start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) u64 commit_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) char *tagp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) journal_block_tag_t *tag = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) int space_left = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) int first_tag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) int tag_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) int tag_bytes = journal_tag_bytes(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct buffer_head *cbh = NULL; /* For transactional checksums */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) __u32 crc32_sum = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct blk_plug plug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* Tail of the journal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) unsigned long first_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) tid_t first_tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) int update_tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) int csum_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) LIST_HEAD(io_bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) LIST_HEAD(log_bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (jbd2_journal_has_csum_v2or3(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) csum_size = sizeof(struct jbd2_journal_block_tail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * First job: lock down the current transaction and wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * all outstanding updates to complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /* Do we need to erase the effects of a prior jbd2_journal_flush? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (journal->j_flags & JBD2_FLUSHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) jbd_debug(3, "super block updated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) mutex_lock_io(&journal->j_checkpoint_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * We hold j_checkpoint_mutex so tail cannot change under us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * We don't need any special data guarantees for writing sb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * since journal is empty and it is ok for write to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * flushed only with transaction commit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) jbd2_journal_update_sb_log_tail(journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) journal->j_tail_sequence,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) journal->j_tail,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) REQ_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) mutex_unlock(&journal->j_checkpoint_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) jbd_debug(3, "superblock not updated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) J_ASSERT(journal->j_running_transaction != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) J_ASSERT(journal->j_committing_transaction == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) journal->j_flags |= JBD2_FULL_COMMIT_ONGOING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) while (journal->j_flags & JBD2_FAST_COMMIT_ONGOING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) prepare_to_wait(&journal->j_fc_wait, &wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) finish_wait(&journal->j_fc_wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * TODO: by blocking fast commits here, we are increasing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * fsync() latency slightly. Strictly speaking, we don't need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * to block fast commits until the transaction enters T_FLUSH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * state. So an optimization is possible where we block new fast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * commits here and wait for existing ones to complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * just before we enter T_FLUSH. That way, the existing fast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * commits and this full commit can proceed parallely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) commit_transaction = journal->j_running_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) trace_jbd2_start_commit(journal, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) jbd_debug(1, "JBD2: starting commit of transaction %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) commit_transaction->t_tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) journal->j_fc_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) J_ASSERT(commit_transaction->t_state == T_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) commit_transaction->t_state = T_LOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) trace_jbd2_commit_locking(journal, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) stats.run.rs_wait = commit_transaction->t_max_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) stats.run.rs_request_delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) stats.run.rs_locked = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (commit_transaction->t_requested)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) stats.run.rs_request_delay =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) jbd2_time_diff(commit_transaction->t_requested,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) stats.run.rs_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) stats.run.rs_running = jbd2_time_diff(commit_transaction->t_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) stats.run.rs_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) spin_lock(&commit_transaction->t_handle_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) while (atomic_read(&commit_transaction->t_updates)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) prepare_to_wait(&journal->j_wait_updates, &wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (atomic_read(&commit_transaction->t_updates)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) spin_unlock(&commit_transaction->t_handle_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) spin_lock(&commit_transaction->t_handle_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) finish_wait(&journal->j_wait_updates, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) spin_unlock(&commit_transaction->t_handle_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) commit_transaction->t_state = T_SWITCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) J_ASSERT (atomic_read(&commit_transaction->t_outstanding_credits) <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) journal->j_max_transaction_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * First thing we are allowed to do is to discard any remaining
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * BJ_Reserved buffers. Note, it is _not_ permissible to assume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) * that there are no such buffers: if a large filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * operation like a truncate needs to split itself over multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * transactions, then it may try to do a jbd2_journal_restart() while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * there are still BJ_Reserved buffers outstanding. These must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * be released cleanly from the current transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * In this case, the filesystem must still reserve write access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * again before modifying the buffer in the new transaction, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * we do not require it to remember exactly which old buffers it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * has reserved. This is consistent with the existing behaviour
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * that multiple jbd2_journal_get_write_access() calls to the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * buffer are perfectly permissible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) while (commit_transaction->t_reserved_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) jh = commit_transaction->t_reserved_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) JBUFFER_TRACE(jh, "reserved, unused: refile");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * A jbd2_journal_get_undo_access()+jbd2_journal_release_buffer() may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * leave undo-committed data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (jh->b_committed_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct buffer_head *bh = jh2bh(jh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) spin_lock(&jh->b_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) jbd2_free(jh->b_committed_data, bh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) jh->b_committed_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) spin_unlock(&jh->b_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) jbd2_journal_refile_buffer(journal, jh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * Now try to drop any written-back buffers from the journal's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * checkpoint lists. We do this *before* commit because it potentially
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * frees some memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) spin_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) __jbd2_journal_clean_checkpoint_list(journal, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) jbd_debug(3, "JBD2: commit phase 1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * Clear revoked flag to reflect there is no revoked buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * in the next transaction which is going to be started.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) jbd2_clear_buffer_revoked_flags(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * Switch to a new revoke table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) jbd2_journal_switch_revoke_table(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * Reserved credits cannot be claimed anymore, free them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) atomic_sub(atomic_read(&journal->j_reserved_credits),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) &commit_transaction->t_outstanding_credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) trace_jbd2_commit_flushing(journal, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) stats.run.rs_flushing = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) stats.run.rs_locked = jbd2_time_diff(stats.run.rs_locked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) stats.run.rs_flushing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) commit_transaction->t_state = T_FLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) journal->j_committing_transaction = commit_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) journal->j_running_transaction = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) start_time = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) commit_transaction->t_log_start = journal->j_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) wake_up(&journal->j_wait_transaction_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) jbd_debug(3, "JBD2: commit phase 2a\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * Now start flushing things to disk, in the order they appear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * on the transaction lists. Data blocks go first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) err = journal_submit_data_buffers(journal, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) jbd2_journal_abort(journal, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) blk_start_plug(&plug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) jbd2_journal_write_revoke_records(commit_transaction, &log_bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) jbd_debug(3, "JBD2: commit phase 2b\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) * Way to go: we have now written out all of the data for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) * transaction! Now comes the tricky part: we need to write out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) * metadata. Loop over the transaction's entire buffer list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) commit_transaction->t_state = T_COMMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) trace_jbd2_commit_logging(journal, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) stats.run.rs_logging = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) stats.run.rs_flushing = jbd2_time_diff(stats.run.rs_flushing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) stats.run.rs_logging);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) stats.run.rs_blocks = commit_transaction->t_nr_buffers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) stats.run.rs_blocks_logged = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) J_ASSERT(commit_transaction->t_nr_buffers <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) atomic_read(&commit_transaction->t_outstanding_credits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) bufs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) descriptor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) while (commit_transaction->t_buffers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) /* Find the next buffer to be journaled... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) jh = commit_transaction->t_buffers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) /* If we're in abort mode, we just un-journal the buffer and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) release it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) if (is_journal_aborted(journal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) clear_buffer_jbddirty(jh2bh(jh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) JBUFFER_TRACE(jh, "journal is aborting: refile");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) jbd2_buffer_abort_trigger(jh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) jh->b_frozen_data ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) jh->b_frozen_triggers :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) jh->b_triggers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) jbd2_journal_refile_buffer(journal, jh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) /* If that was the last one, we need to clean up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) * any descriptor buffers which may have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * already allocated, even if we are now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) * aborting. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (!commit_transaction->t_buffers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) goto start_journal_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) /* Make sure we have a descriptor block in which to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) record the metadata buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (!descriptor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) J_ASSERT (bufs == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) jbd_debug(4, "JBD2: get descriptor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) descriptor = jbd2_journal_get_descriptor_buffer(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) commit_transaction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) JBD2_DESCRIPTOR_BLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (!descriptor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) jbd2_journal_abort(journal, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) jbd_debug(4, "JBD2: got buffer %llu (%p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) (unsigned long long)descriptor->b_blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) descriptor->b_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) tagp = &descriptor->b_data[sizeof(journal_header_t)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) space_left = descriptor->b_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) sizeof(journal_header_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) first_tag = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) set_buffer_jwrite(descriptor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) set_buffer_dirty(descriptor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) wbuf[bufs++] = descriptor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) /* Record it so that we can wait for IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) completion later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) BUFFER_TRACE(descriptor, "ph3: file as descriptor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) jbd2_file_log_bh(&log_bufs, descriptor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /* Where is the buffer to be written? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) err = jbd2_journal_next_log_block(journal, &blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /* If the block mapping failed, just abandon the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) and repeat this loop: we'll fall into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) refile-on-abort condition above. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) jbd2_journal_abort(journal, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * start_this_handle() uses t_outstanding_credits to determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * the free space in the log.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) atomic_dec(&commit_transaction->t_outstanding_credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* Bump b_count to prevent truncate from stumbling over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) the shadowed buffer! @@@ This can go if we ever get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) rid of the shadow pairing of buffers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) atomic_inc(&jh2bh(jh)->b_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * Make a temporary IO buffer with which to write it out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * (this will requeue the metadata buffer to BJ_Shadow).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) set_bit(BH_JWrite, &jh2bh(jh)->b_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) JBUFFER_TRACE(jh, "ph3: write metadata");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) flags = jbd2_journal_write_metadata_buffer(commit_transaction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) jh, &wbuf[bufs], blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) if (flags < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) jbd2_journal_abort(journal, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) jbd2_file_log_bh(&io_bufs, wbuf[bufs]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) /* Record the new block's tag in the current descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) tag_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) if (flags & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) tag_flag |= JBD2_FLAG_ESCAPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (!first_tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) tag_flag |= JBD2_FLAG_SAME_UUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) tag = (journal_block_tag_t *) tagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) write_tag_block(journal, tag, jh2bh(jh)->b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) tag->t_flags = cpu_to_be16(tag_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) jbd2_block_tag_csum_set(journal, tag, wbuf[bufs],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) commit_transaction->t_tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) tagp += tag_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) space_left -= tag_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) bufs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (first_tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) memcpy (tagp, journal->j_uuid, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) tagp += 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) space_left -= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) first_tag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) /* If there's no more to do, or if the descriptor is full,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) let the IO rip! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (bufs == journal->j_wbufsize ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) commit_transaction->t_buffers == NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) space_left < tag_bytes + 16 + csum_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) jbd_debug(4, "JBD2: Submit %d IOs\n", bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) /* Write an end-of-descriptor marker before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) submitting the IOs. "tag" still points to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) the last tag we set up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) tag->t_flags |= cpu_to_be16(JBD2_FLAG_LAST_TAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) start_journal_io:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if (descriptor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) jbd2_descriptor_block_csum_set(journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) descriptor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) for (i = 0; i < bufs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) struct buffer_head *bh = wbuf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) * Compute checksum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if (jbd2_has_feature_checksum(journal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) crc32_sum =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) jbd2_checksum_data(crc32_sum, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) clear_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) set_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) bh->b_end_io = journal_end_buffer_io_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) submit_bh(REQ_OP_WRITE, REQ_SYNC, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) /* Force a new descriptor to be generated next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) time round the loop. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) descriptor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) bufs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) err = journal_finish_inode_data_buffers(journal, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) "JBD2: Detected IO errors while flushing file data "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) "on %s\n", journal->j_devname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (journal->j_flags & JBD2_ABORT_ON_SYNCDATA_ERR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) jbd2_journal_abort(journal, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * Get current oldest transaction in the log before we issue flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) * to the filesystem device. After the flush we can be sure that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * blocks of all older transactions are checkpointed to persistent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * storage and we will be safe to update journal start in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * superblock with the numbers we get here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) update_tail =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) jbd2_journal_get_log_tail(journal, &first_tid, &first_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (update_tail) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) long freed = first_block - journal->j_tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) if (first_block < journal->j_tail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) freed += journal->j_last - journal->j_first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) /* Update tail only if we free significant amount of space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (freed < jbd2_journal_get_max_txn_bufs(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) update_tail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) J_ASSERT(commit_transaction->t_state == T_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) commit_transaction->t_state = T_COMMIT_DFLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) * If the journal is not located on the file system device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * then we must flush the file system device before we issue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) * the commit record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) if (commit_transaction->t_need_data_flush &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) (journal->j_fs_dev != journal->j_dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) (journal->j_flags & JBD2_BARRIER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) /* Done it all: now write the commit record asynchronously. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (jbd2_has_feature_async_commit(journal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) err = journal_submit_commit_record(journal, commit_transaction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) &cbh, crc32_sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) jbd2_journal_abort(journal, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) blk_finish_plug(&plug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) /* Lo and behold: we have just managed to send a transaction to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) the log. Before we can commit it, wait for the IO so far to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) complete. Control buffers being written are on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) transaction's t_log_list queue, and metadata buffers are on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) the io_bufs list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) Wait for the buffers in reverse order. That way we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) less likely to be woken up until all IOs have completed, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) so we incur less scheduling load.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) jbd_debug(3, "JBD2: commit phase 3\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) while (!list_empty(&io_bufs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct buffer_head *bh = list_entry(io_bufs.prev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) struct buffer_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) b_assoc_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) wait_on_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) if (unlikely(!buffer_uptodate(bh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) jbd2_unfile_log_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) stats.run.rs_blocks_logged++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) * The list contains temporary buffer heads created by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) * jbd2_journal_write_metadata_buffer().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) BUFFER_TRACE(bh, "dumping temporary bh");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) __brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) J_ASSERT_BH(bh, atomic_read(&bh->b_count) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) free_buffer_head(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) /* We also have to refile the corresponding shadowed buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) jh = commit_transaction->t_shadow_list->b_tprev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) bh = jh2bh(jh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) clear_buffer_jwrite(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) J_ASSERT_BH(bh, buffer_jbddirty(bh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) J_ASSERT_BH(bh, !buffer_shadow(bh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) /* The metadata is now released for reuse, but we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) to remember it against this transaction so that when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) we finally commit, we can do any checkpointing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) required. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) JBUFFER_TRACE(jh, "file as BJ_Forget");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) JBUFFER_TRACE(jh, "brelse shadowed buffer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) __brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) J_ASSERT (commit_transaction->t_shadow_list == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) jbd_debug(3, "JBD2: commit phase 4\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) /* Here we wait for the revoke record and descriptor record buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) while (!list_empty(&log_bufs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) bh = list_entry(log_bufs.prev, struct buffer_head, b_assoc_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) wait_on_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if (unlikely(!buffer_uptodate(bh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) BUFFER_TRACE(bh, "ph5: control buffer writeout done: unfile");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) clear_buffer_jwrite(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) jbd2_unfile_log_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) stats.run.rs_blocks_logged++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) __brelse(bh); /* One for getblk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) /* AKPM: bforget here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) jbd2_journal_abort(journal, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) jbd_debug(3, "JBD2: commit phase 5\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) J_ASSERT(commit_transaction->t_state == T_COMMIT_DFLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) commit_transaction->t_state = T_COMMIT_JFLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) if (!jbd2_has_feature_async_commit(journal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) err = journal_submit_commit_record(journal, commit_transaction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) &cbh, crc32_sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) jbd2_journal_abort(journal, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) if (cbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) err = journal_wait_on_commit_record(journal, cbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) stats.run.rs_blocks_logged++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (jbd2_has_feature_async_commit(journal) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) journal->j_flags & JBD2_BARRIER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) blkdev_issue_flush(journal->j_dev, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) jbd2_journal_abort(journal, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) WARN_ON_ONCE(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) atomic_read(&commit_transaction->t_outstanding_credits) < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) * Now disk caches for filesystem device are flushed so we are safe to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) * erase checkpointed transactions from the log by updating journal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) * superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (update_tail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) jbd2_update_log_tail(journal, first_tid, first_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) /* End of a transaction! Finally, we can do checkpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) processing: any buffers committed as a result of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) transaction can be removed from any checkpoint list it was on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) before. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) jbd_debug(3, "JBD2: commit phase 6\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) J_ASSERT(list_empty(&commit_transaction->t_inode_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) J_ASSERT(commit_transaction->t_buffers == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) J_ASSERT(commit_transaction->t_checkpoint_list == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) J_ASSERT(commit_transaction->t_shadow_list == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) restart_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) * As there are other places (journal_unmap_buffer()) adding buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) * to this list we have to be careful and hold the j_list_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) spin_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) while (commit_transaction->t_forget) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) transaction_t *cp_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) int try_to_free = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) bool drop_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) jh = commit_transaction->t_forget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) bh = jh2bh(jh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) * Get a reference so that bh cannot be freed before we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) * done with it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) get_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) spin_lock(&jh->b_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) J_ASSERT_JH(jh, jh->b_transaction == commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) * If there is undo-protected committed data against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) * this buffer, then we can remove it now. If it is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) * buffer needing such protection, the old frozen_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) * field now points to a committed version of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) * buffer, so rotate that field to the new committed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) * data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) * Otherwise, we can just throw away the frozen data now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) * We also know that the frozen data has already fired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) * its triggers if they exist, so we can clear that too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) if (jh->b_committed_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) jbd2_free(jh->b_committed_data, bh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) jh->b_committed_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) if (jh->b_frozen_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) jh->b_committed_data = jh->b_frozen_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) jh->b_frozen_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) jh->b_frozen_triggers = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) } else if (jh->b_frozen_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) jbd2_free(jh->b_frozen_data, bh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) jh->b_frozen_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) jh->b_frozen_triggers = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) spin_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) cp_transaction = jh->b_cp_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) if (cp_transaction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) JBUFFER_TRACE(jh, "remove from old cp transaction");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) cp_transaction->t_chp_stats.cs_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) __jbd2_journal_remove_checkpoint(jh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) /* Only re-checkpoint the buffer_head if it is marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) * dirty. If the buffer was added to the BJ_Forget list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) * by jbd2_journal_forget, it may no longer be dirty and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) * there's no point in keeping a checkpoint record for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) * it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) * A buffer which has been freed while still being journaled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) * by a previous transaction, refile the buffer to BJ_Forget of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) * the running transaction. If the just committed transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) * contains "add to orphan" operation, we can completely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) * invalidate the buffer now. We are rather through in that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) * since the buffer may be still accessible when blocksize <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) * pagesize and it is attached to the last partial page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (buffer_freed(bh) && !jh->b_next_transaction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) struct address_space *mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) clear_buffer_freed(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) clear_buffer_jbddirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) * Block device buffers need to stay mapped all the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * time, so it is enough to clear buffer_jbddirty and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) * buffer_freed bits. For the file mapping buffers (i.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) * journalled data) we need to unmap buffer and clear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) * more bits. We also need to be careful about the check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) * because the data page mapping can get cleared under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) * our hands. Note that if mapping == NULL, we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) * need to make buffer unmapped because the page is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) * already detached from the mapping and buffers cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) * get reused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) mapping = READ_ONCE(bh->b_page->mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (mapping && !sb_is_blkdev_sb(mapping->host->i_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) clear_buffer_mapped(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) clear_buffer_new(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) clear_buffer_req(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) bh->b_bdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (buffer_jbddirty(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) JBUFFER_TRACE(jh, "add to new checkpointing trans");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) __jbd2_journal_insert_checkpoint(jh, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (is_journal_aborted(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) clear_buffer_jbddirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) J_ASSERT_BH(bh, !buffer_dirty(bh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) * The buffer on BJ_Forget list and not jbddirty means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) * it has been freed by this transaction and hence it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) * could not have been reallocated until this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) * transaction has committed. *BUT* it could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) * reallocated once we have written all the data to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) * disk and before we process the buffer on BJ_Forget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) * list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) if (!jh->b_next_transaction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) try_to_free = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) JBUFFER_TRACE(jh, "refile or unfile buffer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) drop_ref = __jbd2_journal_refile_buffer(jh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) spin_unlock(&jh->b_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) if (drop_ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) jbd2_journal_put_journal_head(jh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (try_to_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) release_buffer_page(bh); /* Drops bh reference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) __brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) cond_resched_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) * This is a bit sleazy. We use j_list_lock to protect transition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) * of a transaction into T_FINISHED state and calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) * __jbd2_journal_drop_transaction(). Otherwise we could race with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) * other checkpointing code processing the transaction...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) spin_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) * Now recheck if some buffers did not get attached to the transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) * while the lock was dropped...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (commit_transaction->t_forget) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) goto restart_loop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) /* Add the transaction to the checkpoint list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) * __journal_remove_checkpoint() can not destroy transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) * under us because it is not marked as T_FINISHED yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) if (journal->j_checkpoint_transactions == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) journal->j_checkpoint_transactions = commit_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) commit_transaction->t_cpnext = commit_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) commit_transaction->t_cpprev = commit_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) commit_transaction->t_cpnext =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) journal->j_checkpoint_transactions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) commit_transaction->t_cpprev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) commit_transaction->t_cpnext->t_cpprev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) commit_transaction->t_cpnext->t_cpprev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) commit_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) commit_transaction->t_cpprev->t_cpnext =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) commit_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) /* Done with this transaction! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) jbd_debug(3, "JBD2: commit phase 7\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) J_ASSERT(commit_transaction->t_state == T_COMMIT_JFLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) commit_transaction->t_start = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) stats.run.rs_logging = jbd2_time_diff(stats.run.rs_logging,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) commit_transaction->t_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) * File the transaction statistics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) stats.ts_tid = commit_transaction->t_tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) stats.run.rs_handle_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) atomic_read(&commit_transaction->t_handle_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) trace_jbd2_run_stats(journal->j_fs_dev->bd_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) commit_transaction->t_tid, &stats.run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) stats.ts_requested = (commit_transaction->t_requested) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) commit_transaction->t_state = T_COMMIT_CALLBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) J_ASSERT(commit_transaction == journal->j_committing_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) journal->j_commit_sequence = commit_transaction->t_tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) journal->j_committing_transaction = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) commit_time = ktime_to_ns(ktime_sub(ktime_get(), start_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) * weight the commit time higher than the average time so we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) * react too strongly to vast changes in the commit time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) if (likely(journal->j_average_commit_time))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) journal->j_average_commit_time = (commit_time +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) journal->j_average_commit_time*3) / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) journal->j_average_commit_time = commit_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if (journal->j_commit_callback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) journal->j_commit_callback(journal, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) if (journal->j_fc_cleanup_callback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) journal->j_fc_cleanup_callback(journal, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) trace_jbd2_end_commit(journal, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) jbd_debug(1, "JBD2: commit %d complete, head %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) journal->j_commit_sequence, journal->j_tail_sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) write_lock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) journal->j_flags &= ~JBD2_FULL_COMMIT_ONGOING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) journal->j_flags &= ~JBD2_FAST_COMMIT_ONGOING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) spin_lock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) commit_transaction->t_state = T_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) /* Check if the transaction can be dropped now that we are finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) if (commit_transaction->t_checkpoint_list == NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) commit_transaction->t_checkpoint_io_list == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) __jbd2_journal_drop_transaction(journal, commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) jbd2_journal_free_transaction(commit_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) spin_unlock(&journal->j_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) write_unlock(&journal->j_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) wake_up(&journal->j_wait_done_commit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) wake_up(&journal->j_fc_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) * Calculate overall stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) spin_lock(&journal->j_history_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) journal->j_stats.ts_tid++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) journal->j_stats.ts_requested += stats.ts_requested;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) journal->j_stats.run.rs_wait += stats.run.rs_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) journal->j_stats.run.rs_request_delay += stats.run.rs_request_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) journal->j_stats.run.rs_running += stats.run.rs_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) journal->j_stats.run.rs_locked += stats.run.rs_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) journal->j_stats.run.rs_flushing += stats.run.rs_flushing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) journal->j_stats.run.rs_logging += stats.run.rs_logging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) journal->j_stats.run.rs_handle_count += stats.run.rs_handle_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) journal->j_stats.run.rs_blocks += stats.run.rs_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) journal->j_stats.run.rs_blocks_logged += stats.run.rs_blocks_logged;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) spin_unlock(&journal->j_history_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }