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);
66 * Base amount of descriptor blocks we reserve for each transaction.
81 * space for commit block and normal transaction descriptor blocks.
90 * Simply initialise a new transaction. Initialize it in
92 * have an existing running transaction: we only make a new transaction
97 * new transaction and we can't block without protecting against other
103 transaction_t *transaction)
105 transaction->t_journal = journal;
106 transaction->t_state = T_RUNNING;
107 transaction->t_start_time = ktime_get();
108 transaction->t_tid = journal->j_transaction_sequence++;
109 transaction->t_expires = jiffies + journal->j_commit_interval;
110 atomic_set(&transaction->t_updates, 0);
111 atomic_set(&transaction->t_outstanding_credits,
114 atomic_set(&transaction->t_outstanding_revokes, 0);
115 atomic_set(&transaction->t_handle_count, 0);
116 INIT_LIST_HEAD(&transaction->t_inode_list);
117 INIT_LIST_HEAD(&transaction->t_private_list);
119 /* Set up the commit timer for the new transaction. */
120 journal->j_commit_timer.expires = round_jiffies_up(transaction->t_expires);
124 journal->j_running_transaction = transaction;
125 transaction->t_max_wait = 0;
126 transaction->t_start = jiffies;
127 transaction->t_requested = 0;
139 * Update transaction's maximum wait time, if debugging is enabled.
146 static inline void update_t_max_wait(transaction_t *transaction,
151 if (time_after(transaction->t_start, ts)) {
152 newts = jbd2_time_diff(ts, transaction->t_start);
153 oldts = READ_ONCE(transaction->t_max_wait);
155 oldts = cmpxchg(&transaction->t_max_wait, oldts, newts);
160 * Wait until running transaction passes to T_FLUSH state and new transaction
162 * running transaction to exist and releases j_state_lock.
183 * Wait until running transaction transitions from T_SWITCH to T_FLUSH
184 * state and new transaction can thus be started. The function releases
217 * Wait until we can add credits for handle to the running transaction. Called
219 * transaction. Returns 1 if we had to wait, j_state_lock is dropped, and
236 * If the current transaction is locked down for commit, wait
254 * If the current transaction is already too large,
256 * attach this handle to a new transaction.
261 * Is the number of reserved credits in the current transaction too
284 * associated with a committing transaction creates a deadlock,
289 * in the new transaction.
309 /* We allow at most half of a transaction to be reserved */
327 * to begin. Attach the handle to a transaction and set up the
328 * transaction's buffer credits.
334 transaction_t *transaction, *new_transaction = NULL;
343 * Limit the number of reserved credits to 1/2 of maximum transaction
345 * transaction size per operation.
360 * transaction early if there are high chances we'll need it. If we
361 * guess wrong, we'll retry or free unused transaction.
393 * Wait on the journal's transaction barrier if necessary. Specifically
418 transaction = journal->j_running_transaction;
433 * transaction and we don't have to check for transaction size
435 * transaction is being switched to a committing one as it
438 if (transaction->t_state == T_SWITCH) {
447 * use and add the handle to the running transaction.
449 update_t_max_wait(transaction, ts);
450 handle->h_transaction = transaction;
454 atomic_inc(&transaction->t_updates);
455 atomic_inc(&transaction->t_handle_count);
458 atomic_read(&transaction->t_outstanding_credits),
466 * Ensure that no allocations done while the transaction is open are
540 * @journal: Journal to start transaction on.
543 * We make sure that the transaction can guarantee at least nblocks of
547 * stored in h_rsv_handle. It is not attached to any particular transaction
548 * and thus doesn't block transaction commit. If the caller uses this reserved
577 /* Get j_state_lock to pin running transaction if it exists */
592 * This attaches @handle to the running transaction (or creates one if there's
593 * not transaction running). Unlike jbd2_journal_start() this function cannot
658 * return code > 0 implies normal transaction-full status.
662 transaction_t *transaction = handle->h_transaction;
669 journal = transaction->t_journal;
675 /* Don't extend a locked-down transaction! */
676 if (transaction->t_state != T_RUNNING) {
678 "transaction not running\n", handle, nblocks);
689 &transaction->t_outstanding_credits);
693 "transaction too large\n", handle, nblocks);
694 atomic_sub(nblocks, &transaction->t_outstanding_credits);
699 transaction->t_tid,
718 transaction_t *transaction = handle->h_transaction;
719 journal_t *journal = transaction->t_journal;
723 J_ASSERT(atomic_read(&transaction->t_updates) > 0);
728 * transaction will really need as large sequences of transactions with
739 &transaction->t_outstanding_revokes);
746 &transaction->t_outstanding_credits);
749 transaction);
750 if (atomic_dec_and_test(&transaction->t_updates))
768 * Restart a handle for a multi-transaction filesystem
773 * handle's transaction so far and reattach the handle to a new
774 * transaction capable of guaranteeing the requested number of
781 transaction_t *transaction = handle->h_transaction;
791 journal = transaction->t_journal;
792 tid = transaction->t_tid;
795 * First unlink the handle from its current transaction, and start the
841 * Note that the running transaction can get freed under us if
842 * this transaction is getting committed in
848 * lead to use-after-free of old freed transaction.
850 transaction_t *transaction = journal->j_running_transaction;
852 if (!transaction)
857 if (!atomic_read(&transaction->t_updates)) {
869 * jbd2_journal_lock_updates () - establish a transaction barrier.
911 * Release a transaction barrier obtained with jbd2_journal_lock_updates().
956 * If the buffer is already part of the current transaction, then there
958 * transaction which we are still committing to disk, then we need to
962 * part of the transaction, that is).
970 transaction_t *transaction = handle->h_transaction;
976 journal = transaction->t_journal;
1036 * The buffer is already part of this transaction if b_transaction or
1039 if (jh->b_transaction == transaction ||
1040 jh->b_next_transaction == transaction) {
1046 * this is the first time this transaction is touching this buffer,
1057 JBUFFER_TRACE(jh, "no transaction");
1062 * visible before attaching it to the running transaction.
1078 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
1095 JBUFFER_TRACE(jh, "owned by older transaction");
1101 * committing transaction is currently writing this buffer out to disk
1116 * Only do the copy if the currently-owning transaction still needs it.
1117 * If buffer isn't on BJ_Metadata list, the committing transaction is
1124 * committed_data record after the transaction, so we HAVE to force the
1143 * before attaching it to the running transaction. Paired with barrier
1147 jh->b_next_transaction = transaction;
1166 /* Fast check whether buffer is already attached to the required transaction */
1181 * we see jh attached to the running transaction, we know it must stay
1182 * so until the transaction is committed. Thus jh won't be freed and
1184 * happen jh gets freed, reallocated, and attached to the transaction
1204 * detect when jh went through free, realloc, attach to transaction
1222 * @handle: transaction to add buffer modifications to
1258 * the bh is not already part of an existing transaction.
1266 * @handle: transaction to new buffer to
1273 transaction_t *transaction = handle->h_transaction;
1282 journal = transaction->t_journal;
1287 * The buffer may already belong to this transaction due to pre-zeroing
1289 * committing transaction's lists, but it HAS to be in Forget state in
1290 * that case: the transaction must have deleted the buffer for it to be
1294 J_ASSERT_JH(jh, (jh->b_transaction == transaction ||
1308 * the buffer so the transaction freeing it must have
1312 /* first access by this transaction */
1317 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
1320 /* first access by this transaction */
1323 JBUFFER_TRACE(jh, "set next transaction");
1325 jh->b_next_transaction = transaction;
1347 * @handle: transaction
1363 * We never need to know which transaction the committed data is part
1365 * will be committed to a new transaction in due course, at which point
1428 * a running transaction will match the buffer in that transaction.
1465 * @handle: transaction to add buffer to.
1469 * transaction.
1475 * The buffer is placed on the transaction's metadata list and is marked
1476 * as belonging to the transaction.
1481 * current committing transaction (in which case we should have frozen
1483 * buffer: that only gets done when the old transaction finally
1488 transaction_t *transaction = handle->h_transaction;
1498 * of the running transaction.
1510 if (data_race(jh->b_transaction != transaction &&
1511 jh->b_next_transaction != transaction)) {
1513 J_ASSERT_JH(jh, jh->b_transaction == transaction ||
1514 jh->b_next_transaction == transaction);
1518 /* If it's in our transaction it must be in BJ_Metadata list. */
1519 if (data_race(jh->b_transaction == transaction &&
1522 if (jh->b_transaction == transaction &&
1529 J_ASSERT_JH(jh, jh->b_transaction != transaction ||
1536 journal = transaction->t_journal;
1543 * 'jh->b_next_transaction' during old transaction
1554 * of the transaction. This needs to be done
1555 * once a transaction -bzzz
1567 * on the running transaction's metadata list there is nothing to do.
1572 if (jh->b_transaction == transaction && jh->b_jlist == BJ_Metadata) {
1594 * Metadata already on the current transaction list doesn't
1595 * need to be filed. Metadata on another transaction's list must
1599 if (jh->b_transaction != transaction) {
1600 JBUFFER_TRACE(jh, "already on other transaction");
1603 (jh->b_next_transaction != transaction))) {
1606 "transaction (%p, %u), "
1611 transaction, transaction->t_tid,
1623 * transaction's data buffer, ever. */
1632 __jbd2_journal_file_buffer(jh, transaction, BJ_Metadata);
1643 * @handle: transaction handle
1647 * buffer. If the buffer is dirty in the current running transaction we
1660 transaction_t *transaction = handle->h_transaction;
1669 journal = transaction->t_journal;
1689 /* keep track of whether or not this transaction modified us */
1693 * The buffer's going from the transaction, we must drop
1698 if (jh->b_transaction == transaction) {
1702 * of this transaction, then we can just drop it from
1703 * the transaction immediately. */
1707 JBUFFER_TRACE(jh, "belongs to current transaction: unfile");
1710 * we only want to drop a reference if this transaction
1718 * However, the commit of this transaction is still
1731 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1741 * (committing) transaction, we can't drop it yet... */
1742 JBUFFER_TRACE(jh, "belongs to older transaction");
1743 /* ... but we CAN drop it from the new transaction through
1745 * the new transaction, so that not only the commit code
1748 * after the new transaction commits. */
1754 jh->b_next_transaction = transaction;
1757 J_ASSERT(jh->b_next_transaction == transaction);
1760 * only drop a reference if this transaction modified
1769 * transaction, we can just drop it now if it has no
1774 JBUFFER_TRACE(jh, "belongs to none transaction");
1790 * attach this buffer to current transaction so that the
1792 * transaction commits.
1795 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1810 * jbd2_journal_stop() - complete a transaction
1811 * @handle: transaction to complete.
1816 * buffer credits to the transaction and remove the handle. The only
1823 * transaction began.
1827 transaction_t *transaction = handle->h_transaction;
1840 if (!transaction) {
1842 * Handle is already detached from the transaction so there is
1848 journal = transaction->t_journal;
1849 tid = transaction->t_tid;
1863 * Implement synchronous transaction batching. If the handle
1866 * transaction. Keep doing that while new threads continue to
1875 * and wait for the transaction to be committed than it is to
1877 * join the transaction. We achieve this by measuring how
1878 * long it takes to commit a transaction, and compare it with
1879 * how long this transaction has been running, and if run time
1903 transaction->t_start_time));
1919 transaction->t_synchronous_commit = 1;
1923 * going! We also want to force a commit if the transaction is too
1927 time_after_eq(jiffies, transaction->t_expires)) {
1932 jbd2_debug(2, "transaction too old, requesting commit for "
1946 * Once stop_this_handle() drops t_updates, the transaction could start
1948 * dereference transaction pointer again after calling
1966 * transaction buffer lists.
1971 * Append a buffer to a transaction list, given the transaction's list head
1995 * Remove a buffer from a transaction list, given the transaction's list
2016 * Remove a buffer from the appropriate transaction list.
2029 transaction_t *transaction;
2033 transaction = jh->b_transaction;
2034 if (transaction)
2035 assert_spin_locked(&transaction->t_journal->j_list_lock);
2039 J_ASSERT_JH(jh, transaction != NULL);
2045 transaction->t_nr_buffers--;
2046 J_ASSERT_JH(jh, transaction->t_nr_buffers >= 0);
2047 list = &transaction->t_buffers;
2050 list = &transaction->t_forget;
2053 list = &transaction->t_shadow_list;
2056 list = &transaction->t_reserved_list;
2062 if (transaction && is_journal_aborted(transaction->t_journal))
2070 * the jh reference that belonged to the transaction.
2114 * running transaction's ->t_datalist via __jbd2_journal_unfile_buffer.
2128 * while the data is part of a transaction. Yes?
2174 * This buffer is no longer needed. If it is on an older transaction's
2175 * checkpoint list we need to record it on this transaction's forget list
2176 * to pin this buffer (and hence its checkpointing transaction) down until
2177 * this transaction commits. If the buffer isn't on a checkpoint list, we
2185 static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
2191 JBUFFER_TRACE(jh, "on running+cp transaction");
2199 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
2202 JBUFFER_TRACE(jh, "on running transaction");
2222 * attached to the current transaction: once the transaction commits,
2226 * previous, committing transaction!
2229 * transaction (and which therefore cannot be discarded immediately) are
2230 * not going to be reused in the new running transaction
2233 * allocated in one transaction and removed in the next will be marked
2235 * the next transaction to delete the block commits. This means that
2244 * transaction commit --- so it is always safe just to discard data
2251 * transaction.
2253 * We're outside-transaction here. Either or both of j_running_transaction
2259 transaction_t *transaction;
2282 * transaction adding inode to orphan list (let's call it T)
2283 * is committed. Otherwise if the transaction changing the
2288 * transaction marking the buffer as freed in the filesystem
2293 * the buffer to BJ_Forget list of the newest transaction.
2301 * the transaction this buffer was modified in.
2303 transaction = jh->b_transaction;
2304 if (transaction == NULL) {
2305 /* First case: not on any transaction. If it
2310 JBUFFER_TRACE(jh, "not on any transaction: zap");
2325 /* ... and once the current transaction has
2333 /* There is no currently-running transaction. So the
2336 * the committing transaction, if it exists. */
2343 /* The orphan record's transaction has
2350 } else if (transaction == journal->j_committing_transaction) {
2351 JBUFFER_TRACE(jh, "on committing transaction");
2369 * b_modified to not confuse transaction credit accounting, and
2370 * set j_next_transaction to the running transaction (if there
2384 /* Good, the buffer belongs to the running transaction.
2385 * We are writing our own transaction's data, not any
2390 J_ASSERT_JH(jh, transaction == journal->j_running_transaction);
2391 JBUFFER_TRACE(jh, "on running transaction");
2392 may_free = __dispose_buffer(jh, transaction);
2400 * running transaction, journal_get_write_access() won't clear
2429 * Can return -EBUSY if buffers are part of the committing transaction and
2485 * File a buffer on the given transaction list.
2488 transaction_t *transaction, int jlist)
2495 assert_spin_locked(&transaction->t_journal->j_list_lock);
2498 J_ASSERT_JH(jh, jh->b_transaction == transaction ||
2524 jh->b_transaction = transaction;
2532 transaction->t_nr_buffers++;
2533 list = &transaction->t_buffers;
2536 list = &transaction->t_forget;
2539 list = &transaction->t_shadow_list;
2542 list = &transaction->t_reserved_list;
2554 transaction_t *transaction, int jlist)
2557 spin_lock(&transaction->t_journal->j_list_lock);
2558 __jbd2_journal_file_buffer(jh, transaction, jlist);
2559 spin_unlock(&transaction->t_journal->j_list_lock);
2565 * dropping it from its current transaction entirely. If the buffer has
2566 * already started to be used by a subsequent transaction, refile the
2567 * buffer on that transaction's metadata list.
2572 * When this function returns true, there's no next transaction to refile to
2592 * It has been modified by a later transaction: add it to the new
2593 * transaction's metadata list.
2646 * File inode in the inode list of the handle's transaction
2651 transaction_t *transaction = handle->h_transaction;
2656 journal = transaction->t_journal;
2659 transaction->t_tid);
2673 if (jinode->i_transaction == transaction ||
2674 jinode->i_next_transaction == transaction)
2682 if (!transaction->t_need_data_flush)
2683 transaction->t_need_data_flush = 1;
2684 /* On some different transaction's list - should be
2690 jinode->i_next_transaction = transaction;
2693 /* Not on any transaction list... */
2695 jinode->i_transaction = transaction;
2696 list_add(&jinode->i_list, &transaction->t_inode_list);
2719 * File truncate and transaction commit interact with each other in a
2720 * non-trivial way. If a transaction writing data block A is
2722 * written them. Otherwise if we crashed after the transaction with
2723 * write has committed but before the transaction with truncate has
2726 * part in case it is in the committing transaction.
2732 * committing the transaction after this function has been called but
2733 * before a transaction for truncate is started (and furthermore it
2735 * happens in the same transaction as write --- we don't have to write
2749 * enough that the transaction was not committing before we started
2750 * a transaction adding the inode to orphan list */