Lines Matching refs:transaction
3 * linux/fs/jbd2/transaction.c
9 * Generic filesystem transaction handling code; part of the ext2fs
46 pr_emerg("JBD2: failed to create transaction cache\n");
58 void jbd2_journal_free_transaction(transaction_t *transaction)
60 if (unlikely(ZERO_OR_NULL_PTR(transaction)))
62 kmem_cache_free(transaction_cache, transaction);
68 * Simply initialise a new transaction. Initialize it in
70 * have an existing running transaction: we only make a new transaction
75 * new transaction and we can't block without protecting against other
81 transaction_t *transaction)
83 transaction->t_journal = journal;
84 transaction->t_state = T_RUNNING;
85 transaction->t_start_time = ktime_get();
86 transaction->t_tid = journal->j_transaction_sequence++;
87 transaction->t_expires = jiffies + journal->j_commit_interval;
88 atomic_set(&transaction->t_updates, 0);
89 atomic_set(&transaction->t_outstanding_credits,
92 atomic_set(&transaction->t_outstanding_revokes, 0);
93 atomic_set(&transaction->t_handle_count, 0);
94 INIT_LIST_HEAD(&transaction->t_inode_list);
96 /* Set up the commit timer for the new transaction. */
97 journal->j_commit_timer.expires = round_jiffies_up(transaction->t_expires);
101 journal->j_running_transaction = transaction;
102 transaction->t_max_wait = 0;
103 transaction->t_start = jiffies;
104 transaction->t_requested = 0;
120 static inline void update_t_max_wait(transaction_t *transaction,
125 if (time_after(transaction->t_start, ts)) {
126 newts = jbd2_time_diff(ts, transaction->t_start);
127 oldts = READ_ONCE(transaction->t_max_wait);
129 oldts = cmpxchg(&transaction->t_max_wait, oldts, newts);
134 * Wait until running transaction passes to T_FLUSH state and new transaction
136 * running transaction to exist and releases j_state_lock.
157 * Wait until running transaction transitions from T_SWITCH to T_FLUSH
158 * state and new transaction can thus be started. The function releases
190 /* Maximum number of blocks for user transaction payload */
198 * Wait until we can add credits for handle to the running transaction. Called
200 * transaction. Returns 1 if we had to wait, j_state_lock is dropped, and
217 * If the current transaction is locked down for commit, wait
235 * If the current transaction is already too large,
237 * attach this handle to a new transaction.
242 * Is the number of reserved credits in the current transaction too
265 * associated with a committing transaction creates a deadlock,
270 * in the new transaction.
290 /* We allow at most half of a transaction to be reserved */
308 * to begin. Attach the handle to a transaction and set up the
309 * transaction's buffer credits.
315 transaction_t *transaction, *new_transaction = NULL;
324 * Limit the number of reserved credits to 1/2 of maximum transaction
326 * transaction size per operation.
341 * transaction early if there are high chances we'll need it. If we
342 * guess wrong, we'll retry or free unused transaction.
374 * Wait on the journal's transaction barrier if necessary. Specifically
399 transaction = journal->j_running_transaction;
414 * transaction and we don't have to check for transaction size
416 * transaction is being switched to a committing one as it
419 if (transaction->t_state == T_SWITCH) {
428 * use and add the handle to the running transaction.
430 update_t_max_wait(transaction, ts);
431 handle->h_transaction = transaction;
435 atomic_inc(&transaction->t_updates);
436 atomic_inc(&transaction->t_handle_count);
439 atomic_read(&transaction->t_outstanding_credits),
447 * Ensure that no allocations done while the transaction is open are
521 * @journal: Journal to start transaction on.
524 * We make sure that the transaction can guarantee at least nblocks of
528 * stored in h_rsv_handle. It is not attached to any particular transaction
529 * and thus doesn't block transaction commit. If the caller uses this reserved
558 /* Get j_state_lock to pin running transaction if it exists */
573 * This attaches @handle to the running transaction (or creates one if there's
574 * not transaction running). Unlike jbd2_journal_start() this function cannot
639 * return code > 0 implies normal transaction-full status.
643 transaction_t *transaction = handle->h_transaction;
650 journal = transaction->t_journal;
656 /* Don't extend a locked-down transaction! */
657 if (transaction->t_state != T_RUNNING) {
659 "transaction not running\n", handle, nblocks);
670 &transaction->t_outstanding_credits);
674 "transaction too large\n", handle, nblocks);
675 atomic_sub(nblocks, &transaction->t_outstanding_credits);
680 transaction->t_tid,
699 transaction_t *transaction = handle->h_transaction;
700 journal_t *journal = transaction->t_journal;
704 J_ASSERT(atomic_read(&transaction->t_updates) > 0);
709 * transaction will really need as large sequences of transactions with
720 &transaction->t_outstanding_revokes);
727 &transaction->t_outstanding_credits);
730 transaction);
731 if (atomic_dec_and_test(&transaction->t_updates))
749 * Restart a handle for a multi-transaction filesystem
754 * handle's transaction so far and reattach the handle to a new
755 * transaction capable of guaranteeing the requested number of
762 transaction_t *transaction = handle->h_transaction;
772 journal = transaction->t_journal;
773 tid = transaction->t_tid;
776 * First unlink the handle from its current transaction, and start the
822 * Note that the running transaction can get freed under us if
823 * this transaction is getting committed in
829 * lead to use-after-free of old freed transaction.
831 transaction_t *transaction = journal->j_running_transaction;
833 if (!transaction)
838 if (!atomic_read(&transaction->t_updates)) {
850 * jbd2_journal_lock_updates () - establish a transaction barrier.
892 * Release a transaction barrier obtained with jbd2_journal_lock_updates().
937 * If the buffer is already part of the current transaction, then there
939 * transaction which we are still committing to disk, then we need to
943 * part of the transaction, that is).
951 transaction_t *transaction = handle->h_transaction;
957 journal = transaction->t_journal;
1017 * The buffer is already part of this transaction if b_transaction or
1020 if (jh->b_transaction == transaction ||
1021 jh->b_next_transaction == transaction) {
1027 * this is the first time this transaction is touching this buffer,
1038 JBUFFER_TRACE(jh, "no transaction");
1043 * visible before attaching it to the running transaction.
1059 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
1076 JBUFFER_TRACE(jh, "owned by older transaction");
1082 * committing transaction is currently writing this buffer out to disk
1097 * Only do the copy if the currently-owning transaction still needs it.
1098 * If buffer isn't on BJ_Metadata list, the committing transaction is
1105 * committed_data record after the transaction, so we HAVE to force the
1124 * before attaching it to the running transaction. Paired with barrier
1128 jh->b_next_transaction = transaction;
1147 /* Fast check whether buffer is already attached to the required transaction */
1162 * we see jh attached to the running transaction, we know it must stay
1163 * so until the transaction is committed. Thus jh won't be freed and
1165 * happen jh gets freed, reallocated, and attached to the transaction
1185 * detect when jh went through free, realloc, attach to transaction
1203 * @handle: transaction to add buffer modifications to
1253 * the bh is not already part of an existing transaction.
1261 * @handle: transaction to new buffer to
1268 transaction_t *transaction = handle->h_transaction;
1277 journal = transaction->t_journal;
1282 * The buffer may already belong to this transaction due to pre-zeroing
1284 * committing transaction's lists, but it HAS to be in Forget state in
1285 * that case: the transaction must have deleted the buffer for it to be
1289 J_ASSERT_JH(jh, (jh->b_transaction == transaction ||
1303 * the buffer so the transaction freeing it must have
1307 /* first access by this transaction */
1312 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
1315 /* first access by this transaction */
1318 JBUFFER_TRACE(jh, "set next transaction");
1320 jh->b_next_transaction = transaction;
1342 * @handle: transaction
1358 * We never need to know which transaction the committed data is part
1360 * will be committed to a new transaction in due course, at which point
1423 * a running transaction will match the buffer in that transaction.
1460 * @handle: transaction to add buffer to.
1464 * transaction.
1470 * The buffer is placed on the transaction's metadata list and is marked
1471 * as belonging to the transaction.
1476 * current committing transaction (in which case we should have frozen
1478 * buffer: that only gets done when the old transaction finally
1483 transaction_t *transaction = handle->h_transaction;
1493 * of the running transaction.
1505 if (data_race(jh->b_transaction != transaction &&
1506 jh->b_next_transaction != transaction)) {
1508 J_ASSERT_JH(jh, jh->b_transaction == transaction ||
1509 jh->b_next_transaction == transaction);
1513 /* If it's in our transaction it must be in BJ_Metadata list. */
1514 if (data_race(jh->b_transaction == transaction &&
1517 if (jh->b_transaction == transaction &&
1524 J_ASSERT_JH(jh, jh->b_transaction != transaction ||
1537 * 'jh->b_next_transaction' during old transaction
1545 journal = transaction->t_journal;
1550 * of the transaction. This needs to be done
1551 * once a transaction -bzzz
1563 * on the running transaction's metadata list there is nothing to do.
1568 if (jh->b_transaction == transaction && jh->b_jlist == BJ_Metadata) {
1590 * Metadata already on the current transaction list doesn't
1591 * need to be filed. Metadata on another transaction's list must
1595 if (jh->b_transaction != transaction) {
1596 JBUFFER_TRACE(jh, "already on other transaction");
1599 (jh->b_next_transaction != transaction))) {
1602 "transaction (%p, %u), "
1607 transaction, transaction->t_tid,
1619 * transaction's data buffer, ever. */
1628 __jbd2_journal_file_buffer(jh, transaction, BJ_Metadata);
1639 * @handle: transaction handle
1643 * buffer. If the buffer is dirty in the current running transaction we
1656 transaction_t *transaction = handle->h_transaction;
1665 journal = transaction->t_journal;
1685 /* keep track of whether or not this transaction modified us */
1689 * The buffer's going from the transaction, we must drop
1694 if (jh->b_transaction == transaction) {
1698 * of this transaction, then we can just drop it from
1699 * the transaction immediately. */
1703 JBUFFER_TRACE(jh, "belongs to current transaction: unfile");
1706 * we only want to drop a reference if this transaction
1714 * However, the commit of this transaction is still
1727 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1737 * (committing) transaction, we can't drop it yet... */
1738 JBUFFER_TRACE(jh, "belongs to older transaction");
1739 /* ... but we CAN drop it from the new transaction through
1741 * the new transaction, so that not only the commit code
1744 * after the new transaction commits. */
1750 jh->b_next_transaction = transaction;
1753 J_ASSERT(jh->b_next_transaction == transaction);
1756 * only drop a reference if this transaction modified
1765 * transaction, we can just drop it now if it has no
1770 JBUFFER_TRACE(jh, "belongs to none transaction");
1786 * attach this buffer to current transaction so that the
1788 * transaction commits.
1791 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1806 * jbd2_journal_stop() - complete a transaction
1807 * @handle: transaction to complete.
1812 * buffer credits to the transaction and remove the handle. The only
1819 * transaction began.
1823 transaction_t *transaction = handle->h_transaction;
1836 if (!transaction) {
1838 * Handle is already detached from the transaction so there is
1844 journal = transaction->t_journal;
1845 tid = transaction->t_tid;
1859 * Implement synchronous transaction batching. If the handle
1862 * transaction. Keep doing that while new threads continue to
1871 * and wait for the transaction to be committed than it is to
1873 * join the transaction. We achieve this by measuring how
1874 * long it takes to commit a transaction, and compare it with
1875 * how long this transaction has been running, and if run time
1899 transaction->t_start_time));
1915 transaction->t_synchronous_commit = 1;
1919 * going! We also want to force a commit if the transaction is too
1923 time_after_eq(jiffies, transaction->t_expires)) {
1928 jbd2_debug(2, "transaction too old, requesting commit for "
1942 * Once stop_this_handle() drops t_updates, the transaction could start
1944 * dereference transaction pointer again after calling
1962 * transaction buffer lists.
1967 * Append a buffer to a transaction list, given the transaction's list head
1991 * Remove a buffer from a transaction list, given the transaction's list
2012 * Remove a buffer from the appropriate transaction list.
2025 transaction_t *transaction;
2029 transaction = jh->b_transaction;
2030 if (transaction)
2031 assert_spin_locked(&transaction->t_journal->j_list_lock);
2035 J_ASSERT_JH(jh, transaction != NULL);
2041 transaction->t_nr_buffers--;
2042 J_ASSERT_JH(jh, transaction->t_nr_buffers >= 0);
2043 list = &transaction->t_buffers;
2046 list = &transaction->t_forget;
2049 list = &transaction->t_shadow_list;
2052 list = &transaction->t_reserved_list;
2058 if (transaction && is_journal_aborted(transaction->t_journal))
2066 * the jh reference that belonged to the transaction.
2095 * running transaction's ->t_datalist via __jbd2_journal_unfile_buffer.
2109 * while the data is part of a transaction. Yes?
2155 * This buffer is no longer needed. If it is on an older transaction's
2156 * checkpoint list we need to record it on this transaction's forget list
2157 * to pin this buffer (and hence its checkpointing transaction) down until
2158 * this transaction commits. If the buffer isn't on a checkpoint list, we
2166 static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
2172 JBUFFER_TRACE(jh, "on running+cp transaction");
2180 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
2183 JBUFFER_TRACE(jh, "on running transaction");
2203 * attached to the current transaction: once the transaction commits,
2207 * previous, committing transaction!
2210 * transaction (and which therefore cannot be discarded immediately) are
2211 * not going to be reused in the new running transaction
2214 * allocated in one transaction and removed in the next will be marked
2216 * the next transaction to delete the block commits. This means that
2225 * transaction commit --- so it is always safe just to discard data
2232 * transaction.
2234 * We're outside-transaction here. Either or both of j_running_transaction
2240 transaction_t *transaction;
2263 * transaction adding inode to orphan list (let's call it T)
2264 * is committed. Otherwise if the transaction changing the
2269 * transaction marking the buffer as freed in the filesystem
2274 * the buffer to BJ_Forget list of the newest transaction.
2282 * the transaction this buffer was modified in.
2284 transaction = jh->b_transaction;
2285 if (transaction == NULL) {
2286 /* First case: not on any transaction. If it
2291 JBUFFER_TRACE(jh, "not on any transaction: zap");
2306 /* ... and once the current transaction has
2314 /* There is no currently-running transaction. So the
2317 * the committing transaction, if it exists. */
2324 /* The orphan record's transaction has
2331 } else if (transaction == journal->j_committing_transaction) {
2332 JBUFFER_TRACE(jh, "on committing transaction");
2350 * b_modified to not confuse transaction credit accounting, and
2351 * set j_next_transaction to the running transaction (if there
2365 /* Good, the buffer belongs to the running transaction.
2366 * We are writing our own transaction's data, not any
2371 J_ASSERT_JH(jh, transaction == journal->j_running_transaction);
2372 JBUFFER_TRACE(jh, "on running transaction");
2373 may_free = __dispose_buffer(jh, transaction);
2381 * running transaction, journal_get_write_access() won't clear
2410 * Can return -EBUSY if buffers are part of the committing transaction and
2466 * File a buffer on the given transaction list.
2469 transaction_t *transaction, int jlist)
2476 assert_spin_locked(&transaction->t_journal->j_list_lock);
2479 J_ASSERT_JH(jh, jh->b_transaction == transaction ||
2505 jh->b_transaction = transaction;
2513 transaction->t_nr_buffers++;
2514 list = &transaction->t_buffers;
2517 list = &transaction->t_forget;
2520 list = &transaction->t_shadow_list;
2523 list = &transaction->t_reserved_list;
2535 transaction_t *transaction, int jlist)
2538 spin_lock(&transaction->t_journal->j_list_lock);
2539 __jbd2_journal_file_buffer(jh, transaction, jlist);
2540 spin_unlock(&transaction->t_journal->j_list_lock);
2546 * dropping it from its current transaction entirely. If the buffer has
2547 * already started to be used by a subsequent transaction, refile the
2548 * buffer on that transaction's metadata list.
2553 * When this function returns true, there's no next transaction to refile to
2573 * It has been modified by a later transaction: add it to the new
2574 * transaction's metadata list.
2627 * File inode in the inode list of the handle's transaction
2632 transaction_t *transaction = handle->h_transaction;
2637 journal = transaction->t_journal;
2640 transaction->t_tid);
2654 if (jinode->i_transaction == transaction ||
2655 jinode->i_next_transaction == transaction)
2663 if (!transaction->t_need_data_flush)
2664 transaction->t_need_data_flush = 1;
2665 /* On some different transaction's list - should be
2671 jinode->i_next_transaction = transaction;
2674 /* Not on any transaction list... */
2676 jinode->i_transaction = transaction;
2677 list_add(&jinode->i_list, &transaction->t_inode_list);
2700 * File truncate and transaction commit interact with each other in a
2701 * non-trivial way. If a transaction writing data block A is
2703 * written them. Otherwise if we crashed after the transaction with
2704 * write has committed but before the transaction with truncate has
2707 * part in case it is in the committing transaction.
2713 * committing the transaction after this function has been called but
2714 * before a transaction for truncate is started (and furthermore it
2716 * happens in the same transaction as write --- we don't have to write
2730 * enough that the transaction was not committing before we started
2731 * a transaction adding the inode to orphan list */