diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-02-22 14:05:19 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-02-22 14:05:19 -0500 |
commit | fc6fc7f1b1095b92d4834e69b385b91e412a7ce5 (patch) | |
tree | 2ad451d5dac4d460830536944cef1de93be36b2a /fs/jbd2/transaction.c | |
parent | ef1f87aa7ba6224bef1b750b3272ba281d8f43ed (diff) | |
parent | 770824bdc421ff58a64db608294323571c949f4c (diff) |
Merge branch 'linus' into x86/apic
Conflicts:
arch/x86/mach-default/setup.c
Semantic conflict resolution:
arch/x86/kernel/setup.c
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'fs/jbd2/transaction.c')
-rw-r--r-- | fs/jbd2/transaction.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index 46b4e347ed7d..28ce21d8598e 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c | |||
@@ -2129,26 +2129,46 @@ done: | |||
2129 | } | 2129 | } |
2130 | 2130 | ||
2131 | /* | 2131 | /* |
2132 | * This function must be called when inode is journaled in ordered mode | 2132 | * File truncate and transaction commit interact with each other in a |
2133 | * before truncation happens. It starts writeout of truncated part in | 2133 | * non-trivial way. If a transaction writing data block A is |
2134 | * case it is in the committing transaction so that we stand to ordered | 2134 | * committing, we cannot discard the data by truncate until we have |
2135 | * mode consistency guarantees. | 2135 | * written them. Otherwise if we crashed after the transaction with |
2136 | * write has committed but before the transaction with truncate has | ||
2137 | * committed, we could see stale data in block A. This function is a | ||
2138 | * helper to solve this problem. It starts writeout of the truncated | ||
2139 | * part in case it is in the committing transaction. | ||
2140 | * | ||
2141 | * Filesystem code must call this function when inode is journaled in | ||
2142 | * ordered mode before truncation happens and after the inode has been | ||
2143 | * placed on orphan list with the new inode size. The second condition | ||
2144 | * avoids the race that someone writes new data and we start | ||
2145 | * committing the transaction after this function has been called but | ||
2146 | * before a transaction for truncate is started (and furthermore it | ||
2147 | * allows us to optimize the case where the addition to orphan list | ||
2148 | * happens in the same transaction as write --- we don't have to write | ||
2149 | * any data in such case). | ||
2136 | */ | 2150 | */ |
2137 | int jbd2_journal_begin_ordered_truncate(struct jbd2_inode *inode, | 2151 | int jbd2_journal_begin_ordered_truncate(journal_t *journal, |
2152 | struct jbd2_inode *jinode, | ||
2138 | loff_t new_size) | 2153 | loff_t new_size) |
2139 | { | 2154 | { |
2140 | journal_t *journal; | 2155 | transaction_t *inode_trans, *commit_trans; |
2141 | transaction_t *commit_trans; | ||
2142 | int ret = 0; | 2156 | int ret = 0; |
2143 | 2157 | ||
2144 | if (!inode->i_transaction && !inode->i_next_transaction) | 2158 | /* This is a quick check to avoid locking if not necessary */ |
2159 | if (!jinode->i_transaction) | ||
2145 | goto out; | 2160 | goto out; |
2146 | journal = inode->i_transaction->t_journal; | 2161 | /* Locks are here just to force reading of recent values, it is |
2162 | * enough that the transaction was not committing before we started | ||
2163 | * a transaction adding the inode to orphan list */ | ||
2147 | spin_lock(&journal->j_state_lock); | 2164 | spin_lock(&journal->j_state_lock); |
2148 | commit_trans = journal->j_committing_transaction; | 2165 | commit_trans = journal->j_committing_transaction; |
2149 | spin_unlock(&journal->j_state_lock); | 2166 | spin_unlock(&journal->j_state_lock); |
2150 | if (inode->i_transaction == commit_trans) { | 2167 | spin_lock(&journal->j_list_lock); |
2151 | ret = filemap_fdatawrite_range(inode->i_vfs_inode->i_mapping, | 2168 | inode_trans = jinode->i_transaction; |
2169 | spin_unlock(&journal->j_list_lock); | ||
2170 | if (inode_trans == commit_trans) { | ||
2171 | ret = filemap_fdatawrite_range(jinode->i_vfs_inode->i_mapping, | ||
2152 | new_size, LLONG_MAX); | 2172 | new_size, LLONG_MAX); |
2153 | if (ret) | 2173 | if (ret) |
2154 | jbd2_journal_abort(journal, ret); | 2174 | jbd2_journal_abort(journal, ret); |