Skip to content

Commit b422f11

Browse files
Luís Henriquesidryomov
authored andcommitted
ceph: invalidate pages when doing direct/sync writes
When doing a direct/sync write, we need to invalidate the page cache in the range being written to. If we don't do this, the cache will include invalid data as we just did a write that avoided the page cache. In the event that invalidation fails, just ignore the error. That likely just means that we raced with another task doing a buffered write, in which case we want to leave the page intact anyway. [ jlayton: minor comment update ] Signed-off-by: Luís Henriques <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Reviewed-by: Xiubo Li <[email protected]> Reviewed-by: Milind Changire <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent f0fe1e5 commit b422f11

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

fs/ceph/file.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,11 +1636,6 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
16361636
return ret;
16371637

16381638
ceph_fscache_invalidate(inode, false);
1639-
ret = invalidate_inode_pages2_range(inode->i_mapping,
1640-
pos >> PAGE_SHIFT,
1641-
(pos + count - 1) >> PAGE_SHIFT);
1642-
if (ret < 0)
1643-
dout("invalidate_inode_pages2_range returned %d\n", ret);
16441639

16451640
while ((len = iov_iter_count(from)) > 0) {
16461641
size_t left;
@@ -1968,6 +1963,20 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
19681963
}
19691964

19701965
ceph_clear_error_write(ci);
1966+
1967+
/*
1968+
* We successfully wrote to a range of the file. Declare
1969+
* that region of the pagecache invalid.
1970+
*/
1971+
ret = invalidate_inode_pages2_range(
1972+
inode->i_mapping,
1973+
pos >> PAGE_SHIFT,
1974+
(pos + len - 1) >> PAGE_SHIFT);
1975+
if (ret < 0) {
1976+
dout("invalidate_inode_pages2_range returned %d\n",
1977+
ret);
1978+
ret = 0;
1979+
}
19711980
pos += len;
19721981
written += len;
19731982
dout("sync_write written %d\n", written);

0 commit comments

Comments
 (0)