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 spin_lock_init(&transaction->t_handle_lock);
111 atomic_set(&transaction->t_updates, 0);
112 atomic_set(&transaction->t_outstanding_credits,
115 atomic_set(&transaction->t_outstanding_revokes, 0);
116 atomic_set(&transaction->t_handle_count, 0);
117 INIT_LIST_HEAD(&transaction->t_inode_list);
118 INIT_LIST_HEAD(&transaction->t_private_list);
120 /* Set up the commit timer for the new transaction. */
121 journal->j_commit_timer.expires = round_jiffies_up(transaction->t_expires);
125 journal->j_running_transaction = transaction;
126 transaction->t_max_wait = 0;
127 transaction->t_start = jiffies;
128 transaction->t_requested = 0;
140 * Update transaction's maximum wait time, if debugging is enabled.
149 static inline void update_t_max_wait(transaction_t *transaction,
154 time_after(transaction->t_start, ts)) {
155 ts = jbd2_time_diff(ts, transaction->t_start);
156 spin_lock(&transaction->t_handle_lock);
157 if (ts > transaction->t_max_wait)
158 transaction->t_max_wait = ts;
159 spin_unlock(&transaction->t_handle_lock);
165 * Wait until running transaction passes to T_FLUSH state and new transaction
167 * running transaction to exist and releases j_state_lock.
188 * Wait until running transaction transitions from T_SWITCH to T_FLUSH
189 * state and new transaction can thus be started. The function releases
222 * Wait until we can add credits for handle to the running transaction. Called
224 * transaction. Returns 1 if we had to wait, j_state_lock is dropped, and
235 * If the current transaction is locked down for commit, wait
252 * If the current transaction is already too large,
254 * attach this handle to a new transaction.
259 * Is the number of reserved credits in the current transaction too
280 * associated with a committing transaction creates a deadlock,
285 * in the new transaction.
304 /* We allow at most half of a transaction to be reserved */
321 * to begin. Attach the handle to a transaction and set up the
322 * transaction's buffer credits.
328 transaction_t *transaction, *new_transaction = NULL;
337 * Limit the number of reserved credits to 1/2 of maximum transaction
339 * transaction size per operation.
354 * transaction early if there are high chances we'll need it. If we
355 * guess wrong, we'll retry or free unused transaction.
387 * Wait on the journal's transaction barrier if necessary. Specifically
412 transaction = journal->j_running_transaction;
421 * transaction and we don't have to check for transaction size
423 * transaction is being switched to a committing one as it
426 if (transaction->t_state == T_SWITCH) {
435 * use and add the handle to the running transaction.
437 update_t_max_wait(transaction, ts);
438 handle->h_transaction = transaction;
442 atomic_inc(&transaction->t_updates);
443 atomic_inc(&transaction->t_handle_count);
446 atomic_read(&transaction->t_outstanding_credits),
454 * Ensure that no allocations done while the transaction is open are
528 * @journal: Journal to start transaction on.
531 * We make sure that the transaction can guarantee at least nblocks of
535 * stored in h_rsv_handle. It is not attached to any particular transaction
536 * and thus doesn't block transaction commit. If the caller uses this reserved
565 /* Get j_state_lock to pin running transaction if it exists */
580 * This attaches @handle to the running transaction (or creates one if there's
581 * not transaction running). Unlike jbd2_journal_start() this function cannot
646 * return code > 0 implies normal transaction-full status.
650 transaction_t *transaction = handle->h_transaction;
657 journal = transaction->t_journal;
663 /* Don't extend a locked-down transaction! */
664 if (transaction->t_state != T_RUNNING) {
666 "transaction not running\n", handle, nblocks);
676 spin_lock(&transaction->t_handle_lock);
678 &transaction->t_outstanding_credits);
682 "transaction too large\n", handle, nblocks);
683 atomic_sub(nblocks, &transaction->t_outstanding_credits);
688 transaction->t_tid,
701 spin_unlock(&transaction->t_handle_lock);
709 transaction_t *transaction = handle->h_transaction;
710 journal_t *journal = transaction->t_journal;
714 J_ASSERT(atomic_read(&transaction->t_updates) > 0);
719 * transaction will really need as large sequences of transactions with
730 &transaction->t_outstanding_revokes);
737 &transaction->t_outstanding_credits);
740 transaction);
741 if (atomic_dec_and_test(&transaction->t_updates))
759 * Restart a handle for a multi-transaction filesystem
764 * handle's transaction so far and reattach the handle to a new
765 * transaction capable of guaranteeing the requested number of
772 transaction_t *transaction = handle->h_transaction;
782 journal = transaction->t_journal;
783 tid = transaction->t_tid;
786 * First unlink the handle from its current transaction, and start the
823 * jbd2_journal_lock_updates () - establish a transaction barrier.
851 transaction_t *transaction = journal->j_running_transaction;
853 if (!transaction)
856 spin_lock(&transaction->t_handle_lock);
859 if (!atomic_read(&transaction->t_updates)) {
860 spin_unlock(&transaction->t_handle_lock);
864 spin_unlock(&transaction->t_handle_lock);
885 * Release a transaction barrier obtained with jbd2_journal_lock_updates().
934 * If the buffer is already part of the current transaction, then there
936 * transaction which we are still committing to disk, then we need to
940 * part of the transaction, that is).
948 transaction_t *transaction = handle->h_transaction;
954 journal = transaction->t_journal;
1014 * The buffer is already part of this transaction if b_transaction or
1017 if (jh->b_transaction == transaction ||
1018 jh->b_next_transaction == transaction) {
1024 * this is the first time this transaction is touching this buffer,
1035 JBUFFER_TRACE(jh, "no transaction");
1040 * visible before attaching it to the running transaction.
1056 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
1073 JBUFFER_TRACE(jh, "owned by older transaction");
1079 * committing transaction is currently writing this buffer out to disk
1094 * Only do the copy if the currently-owning transaction still needs it.
1095 * If buffer isn't on BJ_Metadata list, the committing transaction is
1102 * committed_data record after the transaction, so we HAVE to force the
1121 * before attaching it to the running transaction. Paired with barrier
1125 jh->b_next_transaction = transaction;
1144 /* Fast check whether buffer is already attached to the required transaction */
1159 * we see jh attached to the running transaction, we know it must stay
1160 * so until the transaction is committed. Thus jh won't be freed and
1162 * happen jh gets freed, reallocated, and attached to the transaction
1182 * detect when jh went through free, realloc, attach to transaction
1200 * @handle: transaction to add buffer modifications to
1236 * the bh is not already part of an existing transaction.
1244 * @handle: transaction to new buffer to
1251 transaction_t *transaction = handle->h_transaction;
1260 journal = transaction->t_journal;
1265 * The buffer may already belong to this transaction due to pre-zeroing
1267 * committing transaction's lists, but it HAS to be in Forget state in
1268 * that case: the transaction must have deleted the buffer for it to be
1272 J_ASSERT_JH(jh, (jh->b_transaction == transaction ||
1286 * the buffer so the transaction freeing it must have
1290 /* first access by this transaction */
1295 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
1298 /* first access by this transaction */
1301 JBUFFER_TRACE(jh, "set next transaction");
1303 jh->b_next_transaction = transaction;
1325 * @handle: transaction
1341 * We never need to know which transaction the committed data is part
1343 * will be committed to a new transaction in due course, at which point
1406 * a running transaction will match the buffer in that transaction.
1443 * @handle: transaction to add buffer to.
1447 * transaction.
1453 * The buffer is placed on the transaction's metadata list and is marked
1454 * as belonging to the transaction.
1459 * current committing transaction (in which case we should have frozen
1461 * buffer: that only gets done when the old transaction finally
1466 transaction_t *transaction = handle->h_transaction;
1476 * of the running transaction.
1488 if (data_race(jh->b_transaction != transaction &&
1489 jh->b_next_transaction != transaction)) {
1491 J_ASSERT_JH(jh, jh->b_transaction == transaction ||
1492 jh->b_next_transaction == transaction);
1496 /* If it's in our transaction it must be in BJ_Metadata list. */
1497 if (data_race(jh->b_transaction == transaction &&
1500 if (jh->b_transaction == transaction &&
1507 J_ASSERT_JH(jh, jh->b_transaction != transaction ||
1514 journal = transaction->t_journal;
1521 * 'jh->b_next_transaction' during old transaction
1532 * of the transaction. This needs to be done
1533 * once a transaction -bzzz
1545 * on the running transaction's metadata list there is nothing to do.
1550 if (jh->b_transaction == transaction && jh->b_jlist == BJ_Metadata) {
1572 * Metadata already on the current transaction list doesn't
1573 * need to be filed. Metadata on another transaction's list must
1577 if (jh->b_transaction != transaction) {
1578 JBUFFER_TRACE(jh, "already on other transaction");
1581 (jh->b_next_transaction != transaction))) {
1584 "transaction (%p, %u), "
1589 transaction, transaction->t_tid,
1601 * transaction's data buffer, ever. */
1610 __jbd2_journal_file_buffer(jh, transaction, BJ_Metadata);
1621 * @handle: transaction handle
1625 * buffer. If the buffer is dirty in the current running transaction we
1638 transaction_t *transaction = handle->h_transaction;
1647 journal = transaction->t_journal;
1667 /* keep track of whether or not this transaction modified us */
1671 * The buffer's going from the transaction, we must drop
1676 if (jh->b_transaction == transaction) {
1680 * of this transaction, then we can just drop it from
1681 * the transaction immediately. */
1685 JBUFFER_TRACE(jh, "belongs to current transaction: unfile");
1688 * we only want to drop a reference if this transaction
1696 * However, the commit of this transaction is still
1709 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1719 * (committing) transaction, we can't drop it yet... */
1720 JBUFFER_TRACE(jh, "belongs to older transaction");
1721 /* ... but we CAN drop it from the new transaction through
1723 * the new transaction, so that not only the commit code
1726 * after the new transaction commits. */
1732 jh->b_next_transaction = transaction;
1735 J_ASSERT(jh->b_next_transaction == transaction);
1738 * only drop a reference if this transaction modified
1747 * transaction, we can just drop it now if it has no
1752 JBUFFER_TRACE(jh, "belongs to none transaction");
1769 * attach this buffer to current transaction so that the
1771 * transaction commits.
1774 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1789 * jbd2_journal_stop() - complete a transaction
1790 * @handle: transaction to complete.
1795 * buffer credits to the transaction and remove the handle. The only
1802 * transaction began.
1806 transaction_t *transaction = handle->h_transaction;
1819 if (!transaction) {
1821 * Handle is already detached from the transaction so there is
1827 journal = transaction->t_journal;
1828 tid = transaction->t_tid;
1842 * Implement synchronous transaction batching. If the handle
1845 * transaction. Keep doing that while new threads continue to
1854 * and wait for the transaction to be committed than it is to
1856 * join the transaction. We achieve this by measuring how
1857 * long it takes to commit a transaction, and compare it with
1858 * how long this transaction has been running, and if run time
1882 transaction->t_start_time));
1898 transaction->t_synchronous_commit = 1;
1902 * going! We also want to force a commit if the transaction is too
1906 time_after_eq(jiffies, transaction->t_expires)) {
1911 jbd_debug(2, "transaction too old, requesting commit for "
1925 * Once stop_this_handle() drops t_updates, the transaction could start
1927 * dereference transaction pointer again after calling
1945 * transaction buffer lists.
1950 * Append a buffer to a transaction list, given the transaction's list head
1974 * Remove a buffer from a transaction list, given the transaction's list
1995 * Remove a buffer from the appropriate transaction list.
2008 transaction_t *transaction;
2012 transaction = jh->b_transaction;
2013 if (transaction)
2014 assert_spin_locked(&transaction->t_journal->j_list_lock);
2018 J_ASSERT_JH(jh, transaction != NULL);
2024 transaction->t_nr_buffers--;
2025 J_ASSERT_JH(jh, transaction->t_nr_buffers >= 0);
2026 list = &transaction->t_buffers;
2029 list = &transaction->t_forget;
2032 list = &transaction->t_shadow_list;
2035 list = &transaction->t_reserved_list;
2041 if (transaction && is_journal_aborted(transaction->t_journal))
2049 * the jh reference that belonged to the transaction.
2122 * running transaction's ->t_datalist via __jbd2_journal_unfile_buffer.
2136 * while the data is part of a transaction. Yes?
2176 * This buffer is no longer needed. If it is on an older transaction's
2177 * checkpoint list we need to record it on this transaction's forget list
2178 * to pin this buffer (and hence its checkpointing transaction) down until
2179 * this transaction commits. If the buffer isn't on a checkpoint list, we
2187 static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
2193 JBUFFER_TRACE(jh, "on running+cp transaction");
2201 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
2204 JBUFFER_TRACE(jh, "on running transaction");
2224 * attached to the current transaction: once the transaction commits,
2228 * previous, committing transaction!
2231 * transaction (and which therefore cannot be discarded immediately) are
2232 * not going to be reused in the new running transaction
2235 * allocated in one transaction and removed in the next will be marked
2237 * the next transaction to delete the block commits. This means that
2246 * transaction commit --- so it is always safe just to discard data
2253 * transaction.
2255 * We're outside-transaction here. Either or both of j_running_transaction
2261 transaction_t *transaction;
2284 * transaction adding inode to orphan list (let's call it T)
2285 * is committed. Otherwise if the transaction changing the
2290 * transaction marking the buffer as freed in the filesystem
2295 * the buffer to BJ_Forget list of the newest transaction.
2303 * the transaction this buffer was modified in.
2305 transaction = jh->b_transaction;
2306 if (transaction == NULL) {
2307 /* First case: not on any transaction. If it
2312 JBUFFER_TRACE(jh, "not on any transaction: zap");
2327 /* ... and once the current transaction has
2335 /* There is no currently-running transaction. So the
2338 * the committing transaction, if it exists. */
2345 /* The orphan record's transaction has
2352 } else if (transaction == journal->j_committing_transaction) {
2353 JBUFFER_TRACE(jh, "on committing transaction");
2371 * b_modified to not confuse transaction credit accounting, and
2372 * set j_next_transaction to the running transaction (if there
2386 /* Good, the buffer belongs to the running transaction.
2387 * We are writing our own transaction's data, not any
2392 J_ASSERT_JH(jh, transaction == journal->j_running_transaction);
2393 JBUFFER_TRACE(jh, "on running transaction");
2394 may_free = __dispose_buffer(jh, transaction);
2402 * running transaction, journal_get_write_access() won't clear
2431 * Can return -EBUSY if buffers are part of the committing transaction and
2488 * File a buffer on the given transaction list.
2491 transaction_t *transaction, int jlist)
2498 assert_spin_locked(&transaction->t_journal->j_list_lock);
2501 J_ASSERT_JH(jh, jh->b_transaction == transaction ||
2527 jh->b_transaction = transaction;
2535 transaction->t_nr_buffers++;
2536 list = &transaction->t_buffers;
2539 list = &transaction->t_forget;
2542 list = &transaction->t_shadow_list;
2545 list = &transaction->t_reserved_list;
2557 transaction_t *transaction, int jlist)
2560 spin_lock(&transaction->t_journal->j_list_lock);
2561 __jbd2_journal_file_buffer(jh, transaction, jlist);
2562 spin_unlock(&transaction->t_journal->j_list_lock);
2568 * dropping it from its current transaction entirely. If the buffer has
2569 * already started to be used by a subsequent transaction, refile the
2570 * buffer on that transaction's metadata list.
2575 * When this function returns true, there's no next transaction to refile to
2595 * It has been modified by a later transaction: add it to the new
2596 * transaction's metadata list.
2649 * File inode in the inode list of the handle's transaction
2654 transaction_t *transaction = handle->h_transaction;
2659 journal = transaction->t_journal;
2662 transaction->t_tid);
2676 if (jinode->i_transaction == transaction ||
2677 jinode->i_next_transaction == transaction)
2685 if (!transaction->t_need_data_flush)
2686 transaction->t_need_data_flush = 1;
2687 /* On some different transaction's list - should be
2693 jinode->i_next_transaction = transaction;
2696 /* Not on any transaction list... */
2698 jinode->i_transaction = transaction;
2699 list_add(&jinode->i_list, &transaction->t_inode_list);
2722 * File truncate and transaction commit interact with each other in a
2723 * non-trivial way. If a transaction writing data block A is
2725 * written them. Otherwise if we crashed after the transaction with
2726 * write has committed but before the transaction with truncate has
2729 * part in case it is in the committing transaction.
2735 * committing the transaction after this function has been called but
2736 * before a transaction for truncate is started (and furthermore it
2738 * happens in the same transaction as write --- we don't have to write
2752 * enough that the transaction was not committing before we started
2753 * a transaction adding the inode to orphan list */