]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
dm kcopyd: fix callback race
authorMikulas Patocka <mpatocka@redhat.com>
Thu, 9 Apr 2009 18:20:04 +0000 (18:20 +0000)
committerChris Wright <chrisw@sous-sol.org>
Mon, 27 Apr 2009 17:36:59 +0000 (10:36 -0700)
commit94835d2bc7374d26ae8602a96c866c9ddf2e2c45
tree178fe0242c60913479c2b4aa93bf47b629811e41
parentf2fcdb15ebd2425d165c97c4d07fe10c8730ae23
dm kcopyd: fix callback race

upstream commit: 340cd44451fb0bfa542365e6b4b565bbd44836e2

If the thread calling dm_kcopyd_copy is delayed due to scheduling inside
split_job/segment_complete and the subjobs complete before the loop in
split_job completes, the kcopyd callback could be invoked from the
thread that called dm_kcopyd_copy instead of the kcopyd workqueue.

dm_kcopyd_copy -> split_job -> segment_complete -> job->fn()

Snapshots depend on the fact that callbacks are called from the singlethreaded
kcopyd workqueue and expect that there is no racing between individual
callbacks. The racing between callbacks can lead to corruption of exception
store and it can also mean that exception store callbacks are called twice
for the same exception - a likely reason for crashes reported inside
pending_complete() / remove_exception().

This patch fixes two problems:

1. job->fn being called from the thread that submitted the job (see above).

- Fix: hand over the completion callback to the kcopyd thread.

2. job->fn(read_err, write_err, job->context); in segment_complete
reports the error of the last subjob, not the union of all errors.

- Fix: pass job->write_err to the callback to report all error bits
  (it is done already in run_complete_job)

Cc: stable@kernel.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
drivers/md/dm-kcopyd.c