|
@@ -1,6 +1,6 @@
|
|
|
/*
|
|
|
* linux/fs/transaction.c
|
|
|
- *
|
|
|
+ *
|
|
|
* Written by Stephen C. Tweedie <sct@redhat.com>, 1998
|
|
|
*
|
|
|
* Copyright 1998 Red Hat corp --- All Rights Reserved
|
|
@@ -10,7 +10,7 @@
|
|
|
* option, any later version, incorporated herein by reference.
|
|
|
*
|
|
|
* Generic filesystem transaction handling code; part of the ext2fs
|
|
|
- * journaling system.
|
|
|
+ * journaling system.
|
|
|
*
|
|
|
* This file manages transactions (compound commits managed by the
|
|
|
* journaling code) and handles (individual atomic operations by the
|
|
@@ -74,7 +74,7 @@ get_transaction(journal_t *journal, transaction_t *transaction)
|
|
|
* start_this_handle: Given a handle, deal with any locking or stalling
|
|
|
* needed to make sure that there is enough journal space for the handle
|
|
|
* to begin. Attach the handle to a transaction and set up the
|
|
|
- * transaction's buffer credits.
|
|
|
+ * transaction's buffer credits.
|
|
|
*/
|
|
|
|
|
|
static int start_this_handle(journal_t *journal, handle_t *handle)
|
|
@@ -117,7 +117,7 @@ repeat_locked:
|
|
|
if (is_journal_aborted(journal) ||
|
|
|
(journal->j_errno != 0 && !(journal->j_flags & JFS_ACK_ERR))) {
|
|
|
spin_unlock(&journal->j_state_lock);
|
|
|
- ret = -EROFS;
|
|
|
+ ret = -EROFS;
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
@@ -182,7 +182,7 @@ repeat_locked:
|
|
|
goto repeat;
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /*
|
|
|
* The commit code assumes that it can get enough log space
|
|
|
* without forcing a checkpoint. This is *critical* for
|
|
|
* correctness: a checkpoint of a buffer which is also
|
|
@@ -191,7 +191,7 @@ repeat_locked:
|
|
|
*
|
|
|
* We must therefore ensure the necessary space in the journal
|
|
|
* *before* starting to dirty potentially checkpointed buffers
|
|
|
- * in the new transaction.
|
|
|
+ * in the new transaction.
|
|
|
*
|
|
|
* The worst part is, any transaction currently committing can
|
|
|
* reduce the free space arbitrarily. Be careful to account for
|
|
@@ -246,13 +246,13 @@ static handle_t *new_handle(int nblocks)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * handle_t *journal_start() - Obtain a new handle.
|
|
|
+ * handle_t *journal_start() - Obtain a new handle.
|
|
|
* @journal: Journal to start transaction on.
|
|
|
* @nblocks: number of block buffer we might modify
|
|
|
*
|
|
|
* We make sure that the transaction can guarantee at least nblocks of
|
|
|
* modified buffers in the log. We block until the log can guarantee
|
|
|
- * that much space.
|
|
|
+ * that much space.
|
|
|
*
|
|
|
* This function is visible to journal users (like ext3fs), so is not
|
|
|
* called with the journal already locked.
|
|
@@ -292,11 +292,11 @@ handle_t *journal_start(journal_t *journal, int nblocks)
|
|
|
* int journal_extend() - extend buffer credits.
|
|
|
* @handle: handle to 'extend'
|
|
|
* @nblocks: nr blocks to try to extend by.
|
|
|
- *
|
|
|
+ *
|
|
|
* Some transactions, such as large extends and truncates, can be done
|
|
|
* atomically all at once or in several stages. The operation requests
|
|
|
* a credit for a number of buffer modications in advance, but can
|
|
|
- * extend its credit if it needs more.
|
|
|
+ * extend its credit if it needs more.
|
|
|
*
|
|
|
* journal_extend tries to give the running handle more buffer credits.
|
|
|
* It does not guarantee that allocation - this is a best-effort only.
|
|
@@ -363,7 +363,7 @@ out:
|
|
|
* int journal_restart() - restart a handle .
|
|
|
* @handle: handle to restart
|
|
|
* @nblocks: nr credits requested
|
|
|
- *
|
|
|
+ *
|
|
|
* Restart a handle for a multi-transaction filesystem
|
|
|
* operation.
|
|
|
*
|
|
@@ -462,7 +462,7 @@ void journal_lock_updates(journal_t *journal)
|
|
|
/**
|
|
|
* void journal_unlock_updates (journal_t* journal) - release barrier
|
|
|
* @journal: Journal to release the barrier on.
|
|
|
- *
|
|
|
+ *
|
|
|
* Release a transaction barrier obtained with journal_lock_updates().
|
|
|
*
|
|
|
* Should be called without the journal lock held.
|
|
@@ -547,8 +547,8 @@ repeat:
|
|
|
jbd_lock_bh_state(bh);
|
|
|
|
|
|
/* We now hold the buffer lock so it is safe to query the buffer
|
|
|
- * state. Is the buffer dirty?
|
|
|
- *
|
|
|
+ * state. Is the buffer dirty?
|
|
|
+ *
|
|
|
* If so, there are two possibilities. The buffer may be
|
|
|
* non-journaled, and undergoing a quite legitimate writeback.
|
|
|
* Otherwise, it is journaled, and we don't expect dirty buffers
|
|
@@ -566,7 +566,7 @@ repeat:
|
|
|
*/
|
|
|
if (jh->b_transaction) {
|
|
|
J_ASSERT_JH(jh,
|
|
|
- jh->b_transaction == transaction ||
|
|
|
+ jh->b_transaction == transaction ||
|
|
|
jh->b_transaction ==
|
|
|
journal->j_committing_transaction);
|
|
|
if (jh->b_next_transaction)
|
|
@@ -653,7 +653,7 @@ repeat:
|
|
|
* buffer had better remain locked during the kmalloc,
|
|
|
* but that should be true --- we hold the journal lock
|
|
|
* still and the buffer is already on the BUF_JOURNAL
|
|
|
- * list so won't be flushed.
|
|
|
+ * list so won't be flushed.
|
|
|
*
|
|
|
* Subtle point, though: if this is a get_undo_access,
|
|
|
* then we will be relying on the frozen_data to contain
|
|
@@ -765,8 +765,8 @@ int journal_get_write_access(handle_t *handle, struct buffer_head *bh)
|
|
|
* manually rather than reading off disk), then we need to keep the
|
|
|
* buffer_head locked until it has been completely filled with new
|
|
|
* data. In this case, we should be able to make the assertion that
|
|
|
- * the bh is not already part of an existing transaction.
|
|
|
- *
|
|
|
+ * the bh is not already part of an existing transaction.
|
|
|
+ *
|
|
|
* The buffer should already be locked by the caller by this point.
|
|
|
* There is no lock ranking violation: it was a newly created,
|
|
|
* unlocked buffer beforehand. */
|
|
@@ -778,7 +778,7 @@ int journal_get_write_access(handle_t *handle, struct buffer_head *bh)
|
|
|
*
|
|
|
* Call this if you create a new bh.
|
|
|
*/
|
|
|
-int journal_get_create_access(handle_t *handle, struct buffer_head *bh)
|
|
|
+int journal_get_create_access(handle_t *handle, struct buffer_head *bh)
|
|
|
{
|
|
|
transaction_t *transaction = handle->h_transaction;
|
|
|
journal_t *journal = transaction->t_journal;
|
|
@@ -847,13 +847,13 @@ out:
|
|
|
* do not reuse freed space until the deallocation has been committed,
|
|
|
* since if we overwrote that space we would make the delete
|
|
|
* un-rewindable in case of a crash.
|
|
|
- *
|
|
|
+ *
|
|
|
* To deal with that, journal_get_undo_access requests write access to a
|
|
|
* buffer for parts of non-rewindable operations such as delete
|
|
|
* operations on the bitmaps. The journaling code must keep a copy of
|
|
|
* the buffer's contents prior to the undo_access call until such time
|
|
|
* as we know that the buffer has definitely been committed to disk.
|
|
|
- *
|
|
|
+ *
|
|
|
* We never need to know which transaction the committed data is part
|
|
|
* of, buffers touched here are guaranteed to be dirtied later and so
|
|
|
* will be committed to a new transaction in due course, at which point
|
|
@@ -911,13 +911,13 @@ out:
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
+/**
|
|
|
* int journal_dirty_data() - mark a buffer as containing dirty data which
|
|
|
* needs to be flushed before we can commit the
|
|
|
- * current transaction.
|
|
|
+ * current transaction.
|
|
|
* @handle: transaction
|
|
|
* @bh: bufferhead to mark
|
|
|
- *
|
|
|
+ *
|
|
|
* The buffer is placed on the transaction's data list and is marked as
|
|
|
* belonging to the transaction.
|
|
|
*
|
|
@@ -946,15 +946,15 @@ int journal_dirty_data(handle_t *handle, struct buffer_head *bh)
|
|
|
|
|
|
/*
|
|
|
* What if the buffer is already part of a running transaction?
|
|
|
- *
|
|
|
+ *
|
|
|
* There are two cases:
|
|
|
* 1) It is part of the current running transaction. Refile it,
|
|
|
* just in case we have allocated it as metadata, deallocated
|
|
|
- * it, then reallocated it as data.
|
|
|
+ * it, then reallocated it as data.
|
|
|
* 2) It is part of the previous, still-committing transaction.
|
|
|
* If all we want to do is to guarantee that the buffer will be
|
|
|
* written to disk before this new transaction commits, then
|
|
|
- * being sure that the *previous* transaction has this same
|
|
|
+ * being sure that the *previous* transaction has this same
|
|
|
* property is sufficient for us! Just leave it on its old
|
|
|
* transaction.
|
|
|
*
|
|
@@ -1076,18 +1076,18 @@ no_journal:
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
+/**
|
|
|
* int journal_dirty_metadata() - mark a buffer as containing dirty metadata
|
|
|
* @handle: transaction to add buffer to.
|
|
|
- * @bh: buffer to mark
|
|
|
- *
|
|
|
+ * @bh: buffer to mark
|
|
|
+ *
|
|
|
* mark dirty metadata which needs to be journaled as part of the current
|
|
|
* transaction.
|
|
|
*
|
|
|
* The buffer is placed on the transaction's metadata list and is marked
|
|
|
- * as belonging to the transaction.
|
|
|
+ * as belonging to the transaction.
|
|
|
*
|
|
|
- * Returns error number or 0 on success.
|
|
|
+ * Returns error number or 0 on success.
|
|
|
*
|
|
|
* Special care needs to be taken if the buffer already belongs to the
|
|
|
* current committing transaction (in which case we should have frozen
|
|
@@ -1135,11 +1135,11 @@ int journal_dirty_metadata(handle_t *handle, struct buffer_head *bh)
|
|
|
|
|
|
set_buffer_jbddirty(bh);
|
|
|
|
|
|
- /*
|
|
|
+ /*
|
|
|
* Metadata already on the current transaction list doesn't
|
|
|
* need to be filed. Metadata on another transaction's list must
|
|
|
* be committing, and will be refiled once the commit completes:
|
|
|
- * leave it alone for now.
|
|
|
+ * leave it alone for now.
|
|
|
*/
|
|
|
if (jh->b_transaction != transaction) {
|
|
|
JBUFFER_TRACE(jh, "already on other transaction");
|
|
@@ -1165,7 +1165,7 @@ out:
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
+/*
|
|
|
* journal_release_buffer: undo a get_write_access without any buffer
|
|
|
* updates, if the update decided in the end that it didn't need access.
|
|
|
*
|
|
@@ -1176,20 +1176,20 @@ journal_release_buffer(handle_t *handle, struct buffer_head *bh)
|
|
|
BUFFER_TRACE(bh, "entry");
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
+/**
|
|
|
* void journal_forget() - bforget() for potentially-journaled buffers.
|
|
|
* @handle: transaction handle
|
|
|
* @bh: bh to 'forget'
|
|
|
*
|
|
|
* We can only do the bforget if there are no commits pending against the
|
|
|
* buffer. If the buffer is dirty in the current running transaction we
|
|
|
- * can safely unlink it.
|
|
|
+ * can safely unlink it.
|
|
|
*
|
|
|
* bh may not be a journalled buffer at all - it may be a non-JBD
|
|
|
* buffer which came off the hashtable. Check for this.
|
|
|
*
|
|
|
* Decrements bh->b_count by one.
|
|
|
- *
|
|
|
+ *
|
|
|
* Allow this call even if the handle has aborted --- it may be part of
|
|
|
* the caller's cleanup after an abort.
|
|
|
*/
|
|
@@ -1237,7 +1237,7 @@ int journal_forget (handle_t *handle, struct buffer_head *bh)
|
|
|
|
|
|
drop_reserve = 1;
|
|
|
|
|
|
- /*
|
|
|
+ /*
|
|
|
* We are no longer going to journal this buffer.
|
|
|
* However, the commit of this transaction is still
|
|
|
* important to the buffer: the delete that we are now
|
|
@@ -1246,7 +1246,7 @@ int journal_forget (handle_t *handle, struct buffer_head *bh)
|
|
|
*
|
|
|
* So, if we have a checkpoint on the buffer, we should
|
|
|
* now refile the buffer on our BJ_Forget list so that
|
|
|
- * we know to remove the checkpoint after we commit.
|
|
|
+ * we know to remove the checkpoint after we commit.
|
|
|
*/
|
|
|
|
|
|
if (jh->b_cp_transaction) {
|
|
@@ -1264,7 +1264,7 @@ int journal_forget (handle_t *handle, struct buffer_head *bh)
|
|
|
}
|
|
|
}
|
|
|
} else if (jh->b_transaction) {
|
|
|
- J_ASSERT_JH(jh, (jh->b_transaction ==
|
|
|
+ J_ASSERT_JH(jh, (jh->b_transaction ==
|
|
|
journal->j_committing_transaction));
|
|
|
/* However, if the buffer is still owned by a prior
|
|
|
* (committing) transaction, we can't drop it yet... */
|
|
@@ -1294,7 +1294,7 @@ drop:
|
|
|
/**
|
|
|
* int journal_stop() - complete a transaction
|
|
|
* @handle: tranaction to complete.
|
|
|
- *
|
|
|
+ *
|
|
|
* All done for a particular handle.
|
|
|
*
|
|
|
* There is not much action needed here. We just return any remaining
|
|
@@ -1303,7 +1303,7 @@ drop:
|
|
|
* filesystem is marked for synchronous update.
|
|
|
*
|
|
|
* journal_stop itself will not usually return an error, but it may
|
|
|
- * do so in unusual circumstances. In particular, expect it to
|
|
|
+ * do so in unusual circumstances. In particular, expect it to
|
|
|
* return -EIO if a journal_abort has been executed since the
|
|
|
* transaction began.
|
|
|
*/
|
|
@@ -1388,7 +1388,7 @@ int journal_stop(handle_t *handle)
|
|
|
|
|
|
/*
|
|
|
* Special case: JFS_SYNC synchronous updates require us
|
|
|
- * to wait for the commit to complete.
|
|
|
+ * to wait for the commit to complete.
|
|
|
*/
|
|
|
if (handle->h_sync && !(current->flags & PF_MEMALLOC))
|
|
|
err = log_wait_commit(journal, tid);
|
|
@@ -1439,7 +1439,7 @@ int journal_force_commit(journal_t *journal)
|
|
|
* jbd_lock_bh_state(jh2bh(jh)) is held.
|
|
|
*/
|
|
|
|
|
|
-static inline void
|
|
|
+static inline void
|
|
|
__blist_add_buffer(struct journal_head **list, struct journal_head *jh)
|
|
|
{
|
|
|
if (!*list) {
|
|
@@ -1454,7 +1454,7 @@ __blist_add_buffer(struct journal_head **list, struct journal_head *jh)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
+/*
|
|
|
* Remove a buffer from a transaction list, given the transaction's list
|
|
|
* head pointer.
|
|
|
*
|
|
@@ -1475,7 +1475,7 @@ __blist_del_buffer(struct journal_head **list, struct journal_head *jh)
|
|
|
jh->b_tnext->b_tprev = jh->b_tprev;
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
+/*
|
|
|
* Remove a buffer from the appropriate transaction list.
|
|
|
*
|
|
|
* Note that this function can *change* the value of
|
|
@@ -1595,17 +1595,17 @@ out:
|
|
|
}
|
|
|
|
|
|
|
|
|
-/**
|
|
|
+/**
|
|
|
* int journal_try_to_free_buffers() - try to free page buffers.
|
|
|
* @journal: journal for operation
|
|
|
* @page: to try and free
|
|
|
* @unused_gfp_mask: unused
|
|
|
*
|
|
|
- *
|
|
|
+ *
|
|
|
* For all the buffers on this page,
|
|
|
* if they are fully written out ordered data, move them onto BUF_CLEAN
|
|
|
* so try_to_free_buffers() can reap them.
|
|
|
- *
|
|
|
+ *
|
|
|
* This function returns non-zero if we wish try_to_free_buffers()
|
|
|
* to be called. We do this if the page is releasable by try_to_free_buffers().
|
|
|
* We also do it if the page has locked or dirty buffers and the caller wants
|
|
@@ -1629,7 +1629,7 @@ out:
|
|
|
* cannot happen because we never reallocate freed data as metadata
|
|
|
* while the data is part of a transaction. Yes?
|
|
|
*/
|
|
|
-int journal_try_to_free_buffers(journal_t *journal,
|
|
|
+int journal_try_to_free_buffers(journal_t *journal,
|
|
|
struct page *page, gfp_t unused_gfp_mask)
|
|
|
{
|
|
|
struct buffer_head *head;
|
|
@@ -1697,7 +1697,7 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * journal_invalidatepage
|
|
|
+ * journal_invalidatepage
|
|
|
*
|
|
|
* This code is tricky. It has a number of cases to deal with.
|
|
|
*
|
|
@@ -1705,15 +1705,15 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
|
|
|
*
|
|
|
* i_size must be updated on disk before we start calling invalidatepage on the
|
|
|
* data.
|
|
|
- *
|
|
|
+ *
|
|
|
* This is done in ext3 by defining an ext3_setattr method which
|
|
|
* updates i_size before truncate gets going. By maintaining this
|
|
|
* invariant, we can be sure that it is safe to throw away any buffers
|
|
|
* attached to the current transaction: once the transaction commits,
|
|
|
* we know that the data will not be needed.
|
|
|
- *
|
|
|
+ *
|
|
|
* Note however that we can *not* throw away data belonging to the
|
|
|
- * previous, committing transaction!
|
|
|
+ * previous, committing transaction!
|
|
|
*
|
|
|
* Any disk blocks which *are* part of the previous, committing
|
|
|
* transaction (and which therefore cannot be discarded immediately) are
|
|
@@ -1732,7 +1732,7 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
|
|
|
* don't make guarantees about the order in which data hits disk --- in
|
|
|
* particular we don't guarantee that new dirty data is flushed before
|
|
|
* transaction commit --- so it is always safe just to discard data
|
|
|
- * immediately in that mode. --sct
|
|
|
+ * immediately in that mode. --sct
|
|
|
*/
|
|
|
|
|
|
/*
|
|
@@ -1876,9 +1876,9 @@ zap_buffer_unlocked:
|
|
|
return may_free;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
+/**
|
|
|
* void journal_invalidatepage()
|
|
|
- * @journal: journal to use for flush...
|
|
|
+ * @journal: journal to use for flush...
|
|
|
* @page: page to flush
|
|
|
* @offset: length of page to invalidate.
|
|
|
*
|
|
@@ -1886,7 +1886,7 @@ zap_buffer_unlocked:
|
|
|
*
|
|
|
*/
|
|
|
void journal_invalidatepage(journal_t *journal,
|
|
|
- struct page *page,
|
|
|
+ struct page *page,
|
|
|
unsigned long offset)
|
|
|
{
|
|
|
struct buffer_head *head, *bh, *next;
|
|
@@ -1924,8 +1924,8 @@ void journal_invalidatepage(journal_t *journal,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
- * File a buffer on the given transaction list.
|
|
|
+/*
|
|
|
+ * File a buffer on the given transaction list.
|
|
|
*/
|
|
|
void __journal_file_buffer(struct journal_head *jh,
|
|
|
transaction_t *transaction, int jlist)
|
|
@@ -1948,7 +1948,7 @@ void __journal_file_buffer(struct journal_head *jh,
|
|
|
* with __jbd_unexpected_dirty_buffer()'s handling of dirty
|
|
|
* state. */
|
|
|
|
|
|
- if (jlist == BJ_Metadata || jlist == BJ_Reserved ||
|
|
|
+ if (jlist == BJ_Metadata || jlist == BJ_Reserved ||
|
|
|
jlist == BJ_Shadow || jlist == BJ_Forget) {
|
|
|
if (test_clear_buffer_dirty(bh) ||
|
|
|
test_clear_buffer_jbddirty(bh))
|
|
@@ -2008,7 +2008,7 @@ void journal_file_buffer(struct journal_head *jh,
|
|
|
jbd_unlock_bh_state(jh2bh(jh));
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
+/*
|
|
|
* Remove a buffer from its current buffer list in preparation for
|
|
|
* dropping it from its current transaction entirely. If the buffer has
|
|
|
* already started to be used by a subsequent transaction, refile the
|
|
@@ -2060,7 +2060,7 @@ void __journal_refile_buffer(struct journal_head *jh)
|
|
|
* to the caller to remove the journal_head if necessary. For the
|
|
|
* unlocked journal_refile_buffer call, the caller isn't going to be
|
|
|
* doing anything else to the buffer so we need to do the cleanup
|
|
|
- * ourselves to avoid a jh leak.
|
|
|
+ * ourselves to avoid a jh leak.
|
|
|
*
|
|
|
* *** The journal_head may be freed by this call! ***
|
|
|
*/
|