Skip to content

Commit c8fd0d3

Browse files
ukernelidryomov
authored andcommitted
ceph: handle race between vmtruncate and queuing cap snap
It's possible that we create a cap snap while there is pending vmtruncate (truncate hasn't been processed by worker thread). We should truncate dirty pages beyond capsnap->size in that case. Signed-off-by: "Yan, Zheng" <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent fa0aa3b commit c8fd0d3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

fs/ceph/inode.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,9 +1833,20 @@ void __ceph_do_pending_vmtruncate(struct inode *inode)
18331833
* possibly truncate them.. so write AND block!
18341834
*/
18351835
if (ci->i_wrbuffer_ref_head < ci->i_wrbuffer_ref) {
1836+
struct ceph_cap_snap *capsnap;
1837+
to = ci->i_truncate_size;
1838+
list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) {
1839+
// MDS should have revoked Frw caps
1840+
WARN_ON_ONCE(capsnap->writing);
1841+
if (capsnap->dirty_pages && capsnap->size > to)
1842+
to = capsnap->size;
1843+
}
1844+
spin_unlock(&ci->i_ceph_lock);
18361845
dout("__do_pending_vmtruncate %p flushing snaps first\n",
18371846
inode);
1838-
spin_unlock(&ci->i_ceph_lock);
1847+
1848+
truncate_pagecache(inode, to);
1849+
18391850
filemap_write_and_wait_range(&inode->i_data, 0,
18401851
inode->i_sb->s_maxbytes);
18411852
goto retry;

0 commit comments

Comments
 (0)