• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/fs/jbd2/

Lines Matching refs:transaction

2  * linux/fs/jbd2/transaction.c
12 * Generic filesystem transaction handling code; part of the ext2fs
37 * Simply allocate and initialise a new transaction. Create it in
39 * have an existing running transaction: we only make a new transaction
44 * new transaction and we can't block without protecting against other
50 jbd2_get_transaction(journal_t *journal, transaction_t *transaction)
52 transaction->t_journal = journal;
53 transaction->t_state = T_RUNNING;
54 transaction->t_start_time = ktime_get();
55 transaction->t_tid = journal->j_transaction_sequence++;
56 transaction->t_expires = jiffies + journal->j_commit_interval;
57 spin_lock_init(&transaction->t_handle_lock);
58 atomic_set(&transaction->t_updates, 0);
59 atomic_set(&transaction->t_outstanding_credits, 0);
60 atomic_set(&transaction->t_handle_count, 0);
61 INIT_LIST_HEAD(&transaction->t_inode_list);
62 INIT_LIST_HEAD(&transaction->t_private_list);
64 /* Set up the commit timer for the new transaction. */
65 journal->j_commit_timer.expires = round_jiffies_up(transaction->t_expires);
69 journal->j_running_transaction = transaction;
70 transaction->t_max_wait = 0;
71 transaction->t_start = jiffies;
73 return transaction;
94 static inline void update_t_max_wait(transaction_t *transaction)
100 time_after(transaction->t_start, ts)) {
101 ts = jbd2_time_diff(ts, transaction->t_start);
102 spin_lock(&transaction->t_handle_lock);
103 if (ts > transaction->t_max_wait)
104 transaction->t_max_wait = ts;
105 spin_unlock(&transaction->t_handle_lock);
113 * to begin. Attach the handle to a transaction and set up the
114 * transaction's buffer credits.
120 transaction_t *transaction;
166 /* Wait on the journal's transaction barrier if necessary */
187 transaction = journal->j_running_transaction;
190 * If the current transaction is locked down for commit, wait for the
193 if (transaction->t_state == T_LOCKED) {
210 &transaction->t_outstanding_credits);
214 * If the current transaction is already too large, then start
216 * a new transaction.
221 atomic_sub(nblocks, &transaction->t_outstanding_credits);
224 __jbd2_log_start_commit(journal, transaction->t_tid);
235 * associated with a committing transaction creates a deadlock,
240 * in the new transaction.
242 * The worst part is, any transaction currently committing can
250 * the committing transaction. Really, we only need to give it
258 atomic_sub(nblocks, &transaction->t_outstanding_credits);
268 * use and add the handle to the running transaction.
270 update_t_max_wait(transaction);
271 handle->h_transaction = transaction;
272 atomic_inc(&transaction->t_updates);
273 atomic_inc(&transaction->t_handle_count);
276 atomic_read(&transaction->t_outstanding_credits),
305 * @journal: Journal to start transaction on.
308 * We make sure that the transaction can guarantee at least nblocks of
375 * return code > 0 implies normal transaction-full status.
379 transaction_t *transaction = handle->h_transaction;
380 journal_t *journal = transaction->t_journal;
392 /* Don't extend a locked-down transaction! */
395 "transaction not running\n", handle, nblocks);
399 spin_lock(&transaction->t_handle_lock);
400 wanted = atomic_read(&transaction->t_outstanding_credits) + nblocks;
404 "transaction too large\n", handle, nblocks);
415 atomic_add(nblocks, &transaction->t_outstanding_credits);
420 spin_unlock(&transaction->t_handle_lock);
433 * Restart a handle for a multi-transaction filesystem
438 * handle's transaction so far and reattach the handle to a new
439 * transaction capabable of guaranteeing the requested number of
444 transaction_t *transaction = handle->h_transaction;
445 journal_t *journal = transaction->t_journal;
454 * First unlink the handle from its current transaction, and start the
457 J_ASSERT(atomic_read(&transaction->t_updates) > 0);
461 spin_lock(&transaction->t_handle_lock);
463 &transaction->t_outstanding_credits);
464 if (atomic_dec_and_test(&transaction->t_updates))
466 spin_unlock(&transaction->t_handle_lock);
469 __jbd2_log_start_commit(journal, transaction->t_tid);
487 * void jbd2_journal_lock_updates () - establish a transaction barrier.
505 transaction_t *transaction = journal->j_running_transaction;
507 if (!transaction)
510 spin_lock(&transaction->t_handle_lock);
511 if (!atomic_read(&transaction->t_updates)) {
512 spin_unlock(&transaction->t_handle_lock);
517 spin_unlock(&transaction->t_handle_lock);
538 * Release a transaction barrier obtained with jbd2_journal_lock_updates().
565 * If the buffer is already part of the current transaction, then there
567 * transaction which we are still committing to disk, then we need to
571 * part of the transaction, that is).
579 transaction_t *transaction;
588 transaction = handle->h_transaction;
589 journal = transaction->t_journal;
618 * transaction or the existing committing transaction?
622 jh->b_transaction == transaction ||
627 transaction);
650 * The buffer is already part of this transaction if b_transaction or
653 if (jh->b_transaction == transaction ||
654 jh->b_next_transaction == transaction)
658 * this is the first time this transaction is touching this buffer,
670 jh->b_next_transaction = transaction;
676 if (jh->b_transaction && jh->b_transaction != transaction) {
677 JBUFFER_TRACE(jh, "owned by older transaction");
683 * If the committing transaction is currently writing
711 /* Only do the copy if the currently-owning transaction
713 * committing transaction is past that stage. The
722 * transaction, so we HAVE to force the frozen_data copy
748 jh->b_next_transaction = transaction;
758 JBUFFER_TRACE(jh, "no transaction");
760 jh->b_transaction = transaction;
763 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
808 * @handle: transaction to add buffer modifications to
838 * the bh is not already part of an existing transaction.
846 * @handle: transaction to new buffer to
853 transaction_t *transaction = handle->h_transaction;
854 journal_t *journal = transaction->t_journal;
866 * The buffer may already belong to this transaction due to pre-zeroing
868 * committing transaction's lists, but it HAS to be in Forget state in
869 * that case: the transaction must have deleted the buffer for it to be
874 J_ASSERT_JH(jh, (jh->b_transaction == transaction ||
888 * the buffer so the transaction freeing it must have
892 jh->b_transaction = transaction;
894 /* first access by this transaction */
898 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
900 /* first access by this transaction */
903 JBUFFER_TRACE(jh, "set next transaction");
904 jh->b_next_transaction = transaction;
926 * @handle: transaction
943 * We never need to know which transaction the committed data is part
945 * will be committed to a new transaction in due course, at which point
1007 * a running transaction will match the buffer in that transaction.
1043 * @handle: transaction to add buffer to.
1047 * transaction.
1049 * The buffer is placed on the transaction's metadata list and is marked
1050 * as belonging to the transaction.
1055 * current committing transaction (in which case we should have frozen
1057 * buffer: that only gets done when the old transaction finally
1062 transaction_t *transaction = handle->h_transaction;
1063 journal_t *journal = transaction->t_journal;
1076 * of the transaction. This needs to be done
1077 * once a transaction -bzzz
1086 * on the running transaction's metadata list there is nothing to do.
1091 if (jh->b_transaction == transaction && jh->b_jlist == BJ_Metadata) {
1101 * Metadata already on the current transaction list doesn't
1102 * need to be filed. Metadata on another transaction's list must
1106 if (jh->b_transaction != transaction) {
1107 JBUFFER_TRACE(jh, "already on other transaction");
1110 J_ASSERT_JH(jh, jh->b_next_transaction == transaction);
1112 * transaction's data buffer, ever. */
1143 * @handle: transaction handle
1147 * buffer. If the buffer is dirty in the current running transaction we
1160 transaction_t *transaction = handle->h_transaction;
1161 journal_t *journal = transaction->t_journal;
1184 /* keep track of wether or not this transaction modified us */
1188 * The buffer's going from the transaction, we must drop
1197 * of this transaction, then we can just drop it from
1198 * the transaction immediately. */
1202 JBUFFER_TRACE(jh, "belongs to current transaction: unfile");
1205 * we only want to drop a reference if this transaction
1213 * However, the commit of this transaction is still
1225 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1241 * (committing) transaction, we can't drop it yet... */
1242 JBUFFER_TRACE(jh, "belongs to older transaction");
1243 /* ... but we CAN drop it from the new transaction if we
1247 J_ASSERT(jh->b_next_transaction == transaction);
1251 * only drop a reference if this transaction modified
1272 * int jbd2_journal_stop() - complete a transaction
1278 * buffer credits to the transaction and remove the handle. The only
1285 * transaction began.
1289 transaction_t *transaction = handle->h_transaction;
1290 journal_t *journal = transaction->t_journal;
1300 J_ASSERT(atomic_read(&transaction->t_updates) > 0);
1313 * Implement synchronous transaction batching. If the handle
1316 * transaction. Keep doing that while new threads continue to
1325 * and wait for the transaction to be committed than it is to
1327 * join the transaction. We achieve this by measuring how
1328 * long it takes to commit a transaction, and compare it with
1329 * how long this transaction has been running, and if run time
1350 transaction->t_start_time));
1366 transaction->t_synchronous_commit = 1;
1369 &transaction->t_outstanding_credits);
1374 * transaction is occupying too much of the log, or if the
1375 * transaction is too old now.
1378 (atomic_read(&transaction->t_outstanding_credits) >
1380 time_after_eq(jiffies, transaction->t_expires)) {
1385 jbd_debug(2, "transaction too old, requesting commit for "
1388 jbd2_log_start_commit(journal, transaction->t_tid);
1399 * Once we drop t_updates, if it goes to zero the transaction
1401 * once we do this, we must not dereference transaction
1404 tid = transaction->t_tid;
1405 if (atomic_dec_and_test(&transaction->t_updates)) {
1446 * transaction buffer lists.
1451 * Append a buffer to a transaction list, given the transaction's list head
1475 * Remove a buffer from a transaction list, given the transaction's list
1496 * Remove a buffer from the appropriate transaction list.
1509 transaction_t *transaction;
1513 transaction = jh->b_transaction;
1514 if (transaction)
1515 assert_spin_locked(&transaction->t_journal->j_list_lock);
1519 J_ASSERT_JH(jh, transaction != NULL);
1525 transaction->t_nr_buffers--;
1526 J_ASSERT_JH(jh, transaction->t_nr_buffers >= 0);
1527 list = &transaction->t_buffers;
1530 list = &transaction->t_forget;
1533 list = &transaction->t_iobuf_list;
1536 list = &transaction->t_shadow_list;
1539 list = &transaction->t_log_list;
1542 list = &transaction->t_reserved_list;
1620 * running transaction's ->t_datalist via __jbd2_journal_unfile_buffer.
1634 * while the data is part of a transaction. Yes?
1677 * This buffer is no longer needed. If it is on an older transaction's
1678 * checkpoint list we need to record it on this transaction's forget list
1679 * to pin this buffer (and hence its checkpointing transaction) down until
1680 * this transaction commits. If the buffer isn't on a checkpoint list, we
1688 static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
1696 JBUFFER_TRACE(jh, "on running+cp transaction");
1703 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1706 JBUFFER_TRACE(jh, "on running transaction");
1726 * attached to the current transaction: once the transaction commits,
1730 * previous, committing transaction!
1733 * transaction (and which therefore cannot be discarded immediately) are
1734 * not going to be reused in the new running transaction
1737 * allocated in one transaction and removed in the next will be marked
1739 * the next transaction to delete the block commits. This means that
1748 * transaction commit --- so it is always safe just to discard data
1755 * transaction.
1757 * We're outside-transaction here. Either or both of j_running_transaction
1762 transaction_t *transaction;
1789 * transaction adding inode to orphan list (let's call it T)
1790 * is committed. Otherwise if the transaction changing the
1795 * transaction marking the buffer as freed in the filesystem
1800 * the buffer to BJ_Forget list of the newest transaction.
1802 transaction = jh->b_transaction;
1803 if (transaction == NULL) {
1804 /* First case: not on any transaction. If it
1809 JBUFFER_TRACE(jh, "not on any transaction: zap");
1823 /* ... and once the current transaction has
1835 /* There is no currently-running transaction. So the
1838 * the committing transaction, if it exists. */
1849 /* The orphan record's transaction has
1855 } else if (transaction == journal->j_committing_transaction) {
1856 JBUFFER_TRACE(jh, "on committing transaction");
1860 * running transaction (if there is one) and mark
1873 /* Good, the buffer belongs to the running transaction.
1874 * We are writing our own transaction's data, not any
1879 J_ASSERT_JH(jh, transaction == journal->j_running_transaction);
1880 JBUFFER_TRACE(jh, "on running transaction");
1881 may_free = __dispose_buffer(jh, transaction);
1949 * File a buffer on the given transaction list.
1952 transaction_t *transaction, int jlist)
1959 assert_spin_locked(&transaction->t_journal->j_list_lock);
1962 J_ASSERT_JH(jh, jh->b_transaction == transaction ||
1986 jh->b_transaction = transaction;
1994 transaction->t_nr_buffers++;
1995 list = &transaction->t_buffers;
1998 list = &transaction->t_forget;
2001 list = &transaction->t_iobuf_list;
2004 list = &transaction->t_shadow_list;
2007 list = &transaction->t_log_list;
2010 list = &transaction->t_reserved_list;
2022 transaction_t *transaction, int jlist)
2025 spin_lock(&transaction->t_journal->j_list_lock);
2026 __jbd2_journal_file_buffer(jh, transaction, jlist);
2027 spin_unlock(&transaction->t_journal->j_list_lock);
2033 * dropping it from its current transaction entirely. If the buffer has
2034 * already started to be used by a subsequent transaction, refile the
2035 * buffer on that transaction's metadata list.
2057 * It has been modified by a later transaction: add it to the new
2058 * transaction's metadata list.
2108 * File inode in the inode list of the handle's transaction
2112 transaction_t *transaction = handle->h_transaction;
2113 journal_t *journal = transaction->t_journal;
2119 transaction->t_tid);
2122 * First check whether inode isn't already on the transaction's
2125 * from the transaction. The reason is that we remove inode from the
2126 * transaction only in journal_release_jbd_inode() and when we commit
2127 * the transaction. We are guarded from the first case by holding
2129 * because if jinode->i_transaction == transaction, commit code
2130 * cannot touch the transaction because we hold reference to it,
2131 * and if jinode->i_next_transaction == transaction, commit code
2134 if (jinode->i_transaction == transaction ||
2135 jinode->i_next_transaction == transaction)
2140 if (jinode->i_transaction == transaction ||
2141 jinode->i_next_transaction == transaction)
2144 /* On some different transaction's list - should be
2150 jinode->i_next_transaction = transaction;
2153 /* Not on any transaction list... */
2155 jinode->i_transaction = transaction;
2156 list_add(&jinode->i_list, &transaction->t_inode_list);
2164 * File truncate and transaction commit interact with each other in a
2165 * non-trivial way. If a transaction writing data block A is
2167 * written them. Otherwise if we crashed after the transaction with
2168 * write has committed but before the transaction with truncate has
2171 * part in case it is in the committing transaction.
2177 * committing the transaction after this function has been called but
2178 * before a transaction for truncate is started (and furthermore it
2180 * happens in the same transaction as write --- we don't have to write
2194 * enough that the transaction was not committing before we started
2195 * a transaction adding the inode to orphan list */