Skip to contentSkip to conversation

Fix page unlocking in cifs_readpage()

PATCH In review Sachin Prabhu 2 participants 4 messages Sep 13, 2013 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Fix page unlocking in cifs_readpage()

A set of 2 patches to fix a warning message generated when using fscache with cifs. The problem was first discovered when testing new fscache patches for cifs.

This is a repost of the original patch after taking into account suggestions from Jeff Layton and Steve French.

Sachin Prabhu (2):
cifs: Do not take a reference to the page in cifs_readpage_worker()
cifs: Avoid calling unlock_page() twice in cifs_readpage() when using
fscache

 fs/cifs/file.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.3.1

A message that is not in the archive (sent off-list or not yet received): 1379077917-31017-1-git-send-email-sprabhu-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH 1/2 cifs: Do not take a reference to the page in cifs_readpage_worker()

We do not need to take a reference to the pagecache in cifs_readpage_worker() since the calling function will have already taken one before passing the pointer to the page as an argument to the function.

---
 fs/cifs/file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/cifs/file.c +3 -2
index 69e8431..e47c379 100644
@@ -3384,6 +3384,9 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
 	return rc;
 }
 
+/*
+ * cifs_readpage_worker must be called with the page pinned
+ */
 static int cifs_readpage_worker(struct file *file, struct page *page,
 	loff_t *poffset)
 {
@@ -3395,7 +3398,6 @@ static int cifs_readpage_worker(struct file *file, struct page *page,
 	if (rc == 0)
 		goto read_complete;
 
-	page_cache_get(page);
 	read_data = kmap(page);
 	/* for reads over a certain size could initiate async read ahead */
 
@@ -3422,7 +3424,6 @@ static int cifs_readpage_worker(struct file *file, struct page *page,
 
 io_error:
 	kunmap(page);
-	page_cache_release(page);
 
 read_complete:
 	return rc;
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 2/2 cifs: Avoid calling unlock_page() twice in cifs_readpage() when using fscache

In reply to a message not in the archive

When reading a single page with cifs_readpage(), we make a call to fscache_read_or_alloc_page() which once done, asynchronously calls the completion function cifs_readpage_from_fscache_complete(). This completion function unlocks the page once it has been populated from cache. The module then attempts to unlock the page a second time in cifs_readpage() which leads to warning messages.

In case of a successful call to fscache_read_or_alloc_page() we should skip the second unlock_page() since this will be called by the cifs_readpage_from_fscache_complete() once the page has been populated by fscache.

With the modifications to cifs_readpage_worker(), we will need to re-grab the page lock in cifs_write_begin().

The problem was first noticed when testing new fscache patches for cifs.
https://bugzilla.redhat.com/show_bug.cgi?id=1005737

---
 fs/cifs/file.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/cifs/file.c +7 -3
index e47c379..7b5d0cb 100644
@@ -3424,6 +3424,7 @@ static int cifs_readpage_worker(struct file *file, struct page *page,
 
 io_error:
 	kunmap(page);
+	unlock_page(page);
 
 read_complete:
 	return rc;
@@ -3448,8 +3449,6 @@ static int cifs_readpage(struct file *file, struct page *page)
 
 	rc = cifs_readpage_worker(file, page, &offset);
 
-	unlock_page(page);
-
 	free_xid(xid);
 	return rc;
 }
@@ -3503,6 +3502,7 @@ static int cifs_write_begin(struct file *file, struct address_space *mapping,
 			loff_t pos, unsigned len, unsigned flags,
 			struct page **pagep, void **fsdata)
 {
+	int oncethru = 0;
 	pgoff_t index = pos >> PAGE_CACHE_SHIFT;
 	loff_t offset = pos & (PAGE_CACHE_SIZE - 1);
 	loff_t page_start = pos & PAGE_MASK;
@@ -3512,6 +3512,7 @@ static int cifs_write_begin(struct file *file, struct address_space *mapping,
 
 	cifs_dbg(FYI, "write_begin from %lld len %d\n", (long long)pos, len);
 
+start:
 	page = grab_cache_page_write_begin(mapping, index, flags);
 	if (!page) {
 		rc = -ENOMEM;
@@ -3553,13 +3554,16 @@ static int cifs_write_begin(struct file *file, struct address_space *mapping,
 		}
 	}
 
-	if ((file->f_flags & O_ACCMODE) != O_WRONLY) {
+	if ((file->f_flags & O_ACCMODE) != O_WRONLY && !oncethru) {
 		/*
 		 * might as well read a page, it is fast enough. If we get
 		 * an error, we don't need to return it. cifs_write_end will
 		 * do a sync write instead since PG_uptodate isn't set.
 		 */
 		cifs_readpage_worker(file, page, &page_start);
+		page_cache_release(page);
+		oncethru = 1;
+		goto start;
 	} else {
 		/* we could try using another file handle if there is one -
 		   but how would we lock it to prevent close of that handle
Signature · 1 line
1.8.3.1
Reviewed-by
#4 lore raw
In reply to a message not in the archive
Quoted 7 lines · On Fri, 13 Sep 2013 14:11:55 +0100 Sachin Prabhu…

A set of 2 patches to fix a warning message generated when using fscache with cifs. The problem was first discovered when testing new fscache patches for cifs.

This is a repost of the original patch after taking into account suggestions from Jeff Layton and Steve French.

Quoted 8 lines

Sachin Prabhu (2):
cifs: Do not take a reference to the page in cifs_readpage_worker()
cifs: Avoid calling unlock_page() twice in cifs_readpage() when using
fscache

 fs/cifs/file.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Looks good. You can add this to the set if you like: