[Linux-cachefs] [PATCH v2] ceph: fix write_begin optimization when write is beyond EOF

Jeff Layton jlayton at kernel.org
Sat Jun 12 00:11:41 UTC 2021


It's not sufficient to skip reading when the pos is beyond the EOF.
There may be data at the head of the page that we need to fill in
before the write. Only elide the read if the pos is beyond the last page
in the file.

Cc: <stable at vger.kernel.org> # v5.10+
Fixes: 1cc1699070bd ("ceph: fold ceph_update_writeable_page into ceph_write_begin")
Reported-by: Andrew W Elble <aweits at rit.edu>
Signed-off-by: Jeff Layton <jlayton at kernel.org>
---
 fs/ceph/addr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

This version fixes the one-off bug that Willy pointed out in v1.

Note that v5.13 has been converted to use the new netfs read helper lib,xi
so this fix is for v5.10.z through v5.12.z.

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 26e66436f005..813ab4256dbb 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1353,11 +1353,11 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping,
 		/*
 		 * In some cases we don't need to read at all:
 		 * - full page write
-		 * - write that lies completely beyond EOF
+		 * - write that lies in a page that is completely beyond EOF
 		 * - write that covers the the page from start to EOF or beyond it
 		 */
 		if ((pos_in_page == 0 && len == PAGE_SIZE) ||
-		    (pos >= i_size_read(inode)) ||
+		    (index > (i_size_read(inode) - 1) / PAGE_SIZE) ||
 		    (pos_in_page == 0 && (pos + len) >= i_size_read(inode))) {
 			zero_user_segments(page, 0, pos_in_page,
 					   pos_in_page + len, PAGE_SIZE);
-- 
2.31.1





More information about the Linux-cachefs mailing list