]> git.hungrycats.org Git - linux/commit
btrfs: fix deadlock with extent-same and readpage
authorMark Fasheh <mfasheh@suse.de>
Thu, 18 Jun 2015 21:10:03 +0000 (14:10 -0700)
committerZygo Blaxell <zblaxell@thirteen.furryterror.org>
Tue, 23 Jun 2015 16:43:23 +0000 (12:43 -0400)
commitfa5d1559aab1330914e2e187a63679b9a826bed0
treea98693300f69bc7734c94d1f6d31a98d49bf8832
parent7c3abddc9f33762a15f6189e652a96361e7a6372
btrfs: fix deadlock with extent-same and readpage

->readpage() does page_lock() before extent_lock(), we do the opposite in
extent-same. We want to reverse the order in btrfs_extent_same() but it's
not quite straightforward since the page locks are taken inside btrfs_cmp_data().

So I split btrfs_cmp_data() into 3 parts with a small context structure that
is passed between them. The first, btrfs_cmp_data_prepare() gathers up the
pages needed (taking page lock as required) and puts them on our context
structure. At this point, we are safe to lock the extent range. Afterwards,
we use btrfs_cmp_data() to do the data compare as usual and btrfs_cmp_data_free()
to clean up our context.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
(cherry picked from commit 405ef2a6134205a3d3cdda6a0751a70ea3fb40f4)
fs/btrfs/ioctl.c