btrfs: fix a livelock in wait_for_commit() on PREEMPT_RT
Peter reported [1] that running multiple RR tasks doing sync()
on fully preemptible kernel may starve other/normal sync() tasks
due to fs_info::trans_lock turned into rt_mutex.
This is caused by RR tasks contending over the mutex with priority over
other tasks, which in turn lack progress and they are no longer able to
remove TRANS_STATE_COMPLETED transactions from the fs_info::trans_list.
The offenders start looping in wait_for_commit() expecting the completed
transactions to get off the trans_list but since they're bouncing the
trans_lock the tasks with other/normal priority which are about to delist
such transactions never get a chance to do so due to lower priority.
A simple reproducer can be found in the mentioned email thread [1].
The situation can be resolved by boosting the priority of the starved
tasks or dropping priority of the offenders. Thought this fix prevents
the situation from happening in the first place. We simply delist the
transactions before changing them to completed state. That breaks the
loop condition.