holepunch: fix shmem_truncate_range punching too far
commitac66c863ed2a729015b32dc0b72dc07f4abdfd81
authorHugh Dickins <hugh@veritas.com>
Fri, 13 Apr 2007 17:25:00 +0000 (13 18:25 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 2 May 2007 00:05:55 +0000 (1 17:05 -0700)
treea16df4703f9170f50e180ae9fddda9f14fa11911
parent036bb8535c517d6ea5669337ed709cd975369a2b
holepunch: fix shmem_truncate_range punching too far

Miklos Szeredi observes BUG_ON(!entry) in shmem_writepage() triggered
in rare circumstances, because shmem_truncate_range() erroneously
removes partially truncated directory pages at the end of the range:
later reclaim on pages pointing to these removed directories triggers
the BUG.  Indeed, and it can also cause data loss beyond the hole.

Fix this as in the patch proposed by Miklos, but distinguish between
"limit" (how far we need to search: ignore truncation's next_index
optimization in the holepunch case - if there are races it's more
consistent to act on the whole range specified) and "upper_limit"
(how far we can free directory pages: generally we must be careful
to keep partially punched pages, but can relax at end of file -
i_size being held stable by i_mutex).

Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
mm/shmem.c