set h_transaction to NULL when restart handle
PATCH 1/1 set h_transaction to NULL when restart handle
We may restart journal handle when do truncate or resize work, but current journal restart doesn't set handle->h_transaction to NULL when remove the handle from old transaction. This may results bugs if restart handle failed, since this handle doesn't belongs to the old transaction any more, and the transaction may have been committed, checkpointed and dropped while this handle still refer to it.
So an active handle has a state that doesn't belongs to any transaction now, but current journal codes suppose that handle must belongs to an transaction, I add h_journal to handle_s, which points to journal.
ext4/jbd2 also has this problem. I will make & send it out if this patch working.
--- fs/ext3/ext3_jbd.c | 8 +++++ fs/ext3/super.c | 6 +++- fs/jbd/revoke.c | 12 ++++++-- fs/jbd/transaction.c | 68 +++++++++++++++++++++++++++++++++------------- include/linux/ext3_jbd.h | 9 +++--- include/linux/jbd.h | 1 + 6 files changed, 75 insertions(+), 29 deletions(-)
fs/ext3/ext3_jbd.c +8 -0
@@ -57,3 +57,11 @@ int __ext3_journal_dirty_metadata(const char *where,ext3_journal_abort_handle (where, __func__, bh, handle,err);return err; } + +int __ext3_journal_restart (const char *where,handle_t *handle,int nblocks) +{ +int err =journal_restart (handle, nblocks); +if (err) +ext3_journal_abort_handle (where, __func__,NULL , handle, err); +return err; +}
fs/ext3/super.c +4 -2
@@ -105,11 +105,13 @@ handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks)*/ int __ext3_journal_stop (const char *where,handle_t *handle) { -struct super_block *sb; +struct super_block *sb = handle->h_journal->j_private;int err;int rc; - sb = handle->h_transaction->t_journal->j_private; +if (unlikely (handle->h_transaction ==NULL )) +BUG_ON (!is_handle_aborted (handle)); + err = handle->h_err; rc =journal_stop (handle);
fs/jbd/revoke.c +9 -3
@@ -336,7 +336,7 @@ int journal_revoke(handle_t *handle, unsigned long blocknr, struct buffer_head *bh_in) {struct buffer_head *bh =NULL ; -journal_t *journal; +journal_t *journal = handle->h_journal;struct block_device *bdev;int err;
@@ -344,7 +344,11 @@ int journal_revoke(handle_t *handle, unsigned long blocknr,if (bh_in)BUFFER_TRACE (bh_in,"enter" ); - journal = handle->h_transaction->t_journal; +if (unlikely (handle->h_transaction ==NULL )) { +J_ASSERT (is_handle_aborted (handle)); +return -EROFS ; + } +if (!journal_set_features (journal,0 ,0 ,JFS_FEATURE_INCOMPAT_REVOKE )){J_ASSERT (!"Cannot set revoke feature!" );return -EINVAL ;
@@ -426,13 +430,15 @@ int journal_revoke(handle_t *handle, unsigned long blocknr,int journal_cancel_revoke (handle_t *handle,struct journal_head *jh) {struct jbd_revoke_record_s *record; -journal_t *journal = handle->h_transaction->t_journal; +journal_t *journal = handle->h_journal;int need_cancel;int did_revoke =0 ;/* akpm: debug */ struct buffer_head *bh =jh2bh (jh);jbd_debug (4 ,"journal_head %p, cancelling revoke\n" , jh); +J_ASSERT (handle->h_transaction !=NULL ); +/* Is the existing Revoke bit valid? If so, we trust it, and * only perform the full cancel if the revoke bit is set. If * not, we can't trust the revoke bit, and we need to do the
fs/jbd/transaction.c +49 -19
181 lines not on this page · raw message
include/linux/ext3_jbd.h +4 -4
@@ -136,6 +136,8 @@ int __ext3_journal_get_create_access(const char *where,int __ext3_journal_dirty_metadata (const char *where,handle_t *handle,struct buffer_head *bh); +int __ext3_journal_restart (const char *where,handle_t *handle,int nblocks); +#define ext3_journal_get_undo_access (handle, bh) \ __ext3_journal_get_undo_access(__func__, (handle), (bh))#define ext3_journal_get_write_access (handle, bh) \
@@ -148,6 +150,8 @@ int __ext3_journal_dirty_metadata(const char *where, __ext3_journal_dirty_metadata(__func__, (handle), (bh))#define ext3_journal_forget (handle, bh) \ __ext3_journal_forget(__func__, (handle), (bh)) +#define ext3_journal_restart (handle, nblocks) \ + __ext3_journal_restart(__func__, (handle), (nblocks))int ext3_journal_dirty_data (handle_t *handle,struct buffer_head *bh);
@@ -172,11 +176,6 @@ static inline int ext3_journal_extend(handle_t *handle, int nblocks)return journal_extend (handle, nblocks); } -static inline int ext3_journal_restart (handle_t *handle,int nblocks) -{ -return journal_restart (handle, nblocks); -}