[v2,4/5] ceph: lock page before checking Uptodate flag
diff mbox series

Message ID 20190711184136.19779-5-jlayton@kernel.org
State New
Headers show
Series
  • ceph: fix races when uninlining data
Related show

Commit Message

Jeff Layton July 11, 2019, 6:41 p.m. UTC
We could end up racing with a call to set or clear the Uptodate flag
prior to taking the page lock. Use find_lock_page instead to have
it return a locked page and unlock it before releasing it if it's not
Uptodate.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/ceph/addr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 4606da82da6f..83b1f6dccab8 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1715,12 +1715,12 @@  int ceph_uninline_data(struct inode *inode, struct page *provided_page)
 		WARN_ON(!PageUptodate(page));
 	} else if (ceph_caps_issued(ci) &
 		   (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) {
-		page = find_get_page(inode->i_mapping, 0);
+		page = find_lock_page(inode->i_mapping, 0);
 		if (page) {
 			if (PageUptodate(page)) {
 				from_pagecache = true;
-				lock_page(page);
 			} else {
+				unlock_page(page);
 				put_page(page);
 				page = NULL;
 			}