From: Alexander Zarochentsev Have get_exclusive_access() restart transaction before taking r/w semaphore. There are several places in write_unix_file and extent_balance_dirty_pages where transaction may be open before calling get_exclusive_access. It triggers the "deadlock detection" BUG_ON inside get_exclusive_access(). This patch fixes the bug by embedding txn_restart into the get_exclusive_access() code and cleanes up other places where txn_restart() was called right before get_exclusive_access(). Signed-off-by: Alexander Zarochentsev Signed-off-by: Hans Reiser Signed-off-by: Andrew Morton --- fs/reiser4/plugin/file/file.c | 13 ------------- fs/reiser4/plugin/file/tail_conversion.c | 5 ++--- 2 files changed, 2 insertions(+), 16 deletions(-) diff -puN fs/reiser4/plugin/file/file.c~reiser4-have-get_exclusive_access-restart-transaction fs/reiser4/plugin/file/file.c --- devel/fs/reiser4/plugin/file/file.c~reiser4-have-get_exclusive_access-restart-transaction 2006-05-17 13:10:17.000000000 -0700 +++ devel-akpm/fs/reiser4/plugin/file/file.c 2006-05-17 13:10:17.000000000 -0700 @@ -1451,9 +1451,6 @@ static int commit_file_atoms(struct inod int result; unix_file_info_t *uf_info; - /* close current transaction */ - txn_restart_current(); - uf_info = unix_file_inode_data(inode); /* @@ -2174,7 +2171,6 @@ append_and_or_overwrite(hint_t * hint, s done_lh(&hint->lh); if (!exclusive) { drop_nonexclusive_access(uf_info); - txn_restart_current(); get_exclusive_access(uf_info); } result = tail2extent(uf_info); @@ -2963,15 +2959,6 @@ int delete_object_unix_file(struct inode unix_file_info_t *uf_info; int result; - /* - * transaction can be open already. For example: - * writeback_inodes->sync_sb_inodes->reiser4_sync_inodes-> - * generic_sync_sb_inodes->iput->generic_drop_inode-> - * generic_delete_inode->reiser4_delete_inode->delete_object_unix_file. - * So, restart transaction to avoid deadlock with file rw semaphore. - */ - txn_restart_current(); - if (inode_get_flag(inode, REISER4_NO_SD)) return 0; diff -puN fs/reiser4/plugin/file/tail_conversion.c~reiser4-have-get_exclusive_access-restart-transaction fs/reiser4/plugin/file/tail_conversion.c --- devel/fs/reiser4/plugin/file/tail_conversion.c~reiser4-have-get_exclusive_access-restart-transaction 2006-05-17 13:10:17.000000000 -0700 +++ devel-akpm/fs/reiser4/plugin/file/tail_conversion.c 2006-05-17 13:10:17.000000000 -0700 @@ -20,13 +20,12 @@ void get_exclusive_access(unix_file_info assert("nikita-3047", LOCK_CNT_NIL(inode_sem_w)); assert("nikita-3048", LOCK_CNT_NIL(inode_sem_r)); /* - * "deadlock detection": sometimes we commit a transaction under + * "deadlock avoidance": sometimes we commit a transaction under * rw-semaphore on a file. Such commit can deadlock with another * thread that captured some block (hence preventing atom from being * committed) and waits on rw-semaphore. */ - assert("nikita-3361", get_current_context()->trans->atom == NULL); - BUG_ON(get_current_context()->trans->atom != NULL); + txn_restart_current(); LOCK_CNT_INC(inode_sem_w); down_write(&uf_info->latch); uf_info->exclusive_use = 1; _