CIFS: Add launder_page operation (try #3)
authorPavel Shilovsky <piastry@etersoft.ru>
Fri, 8 Apr 2011 01:29:10 +0000 (05:29 +0400)
committerSteve French <sfrench@us.ibm.com>
Thu, 19 May 2011 14:10:50 +0000 (14:10 +0000)
Add this let us drop filemap_write_and_wait from cifs_invalidate_mapping
and simplify the code to properly process invalidate logic.

Reviewed-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru>
Signed-off-by: Steve French <sfrench@us.ibm.com>
fs/cifs/file.c

index faf59529e847a2adceb9728d10e739adc822f1f5..00b466e667ab9735c60322b082a71d8ef3fd427c 100644 (file)
@@ -1420,9 +1420,10 @@ retry_write:
        return rc;
 }
 
-static int cifs_writepage(struct page *page, struct writeback_control *wbc)
+static int
+cifs_writepage_locked(struct page *page, struct writeback_control *wbc)
 {
-       int rc = -EFAULT;
+       int rc;
        int xid;
 
        xid = GetXid();
@@ -1442,15 +1443,29 @@ static int cifs_writepage(struct page *page, struct writeback_control *wbc)
         * to fail to update with the state of the page correctly.
         */
        set_page_writeback(page);
+retry_write:
        rc = cifs_partialpagewrite(page, 0, PAGE_CACHE_SIZE);
-       SetPageUptodate(page); /* BB add check for error and Clearuptodate? */
-       unlock_page(page);
+       if (rc == -EAGAIN && wbc->sync_mode == WB_SYNC_ALL)
+               goto retry_write;
+       else if (rc == -EAGAIN)
+               redirty_page_for_writepage(wbc, page);
+       else if (rc != 0)
+               SetPageError(page);
+       else
+               SetPageUptodate(page);
        end_page_writeback(page);
        page_cache_release(page);
        FreeXid(xid);
        return rc;
 }
 
+static int cifs_writepage(struct page *page, struct writeback_control *wbc)
+{
+       int rc = cifs_writepage_locked(page, wbc);
+       unlock_page(page);
+       return rc;
+}
+
 static int cifs_write_end(struct file *file, struct address_space *mapping,
                        loff_t pos, unsigned len, unsigned copied,
                        struct page *page, void *fsdata)
@@ -2415,6 +2430,27 @@ static void cifs_invalidate_page(struct page *page, unsigned long offset)
                cifs_fscache_invalidate_page(page, &cifsi->vfs_inode);
 }
 
+static int cifs_launder_page(struct page *page)
+{
+       int rc = 0;
+       loff_t range_start = page_offset(page);
+       loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
+       struct writeback_control wbc = {
+               .sync_mode = WB_SYNC_ALL,
+               .nr_to_write = 0,
+               .range_start = range_start,
+               .range_end = range_end,
+       };
+
+       cFYI(1, "Launder page: %p", page);
+
+       if (clear_page_dirty_for_io(page))
+               rc = cifs_writepage_locked(page, &wbc);
+
+       cifs_fscache_invalidate_page(page, page->mapping->host);
+       return rc;
+}
+
 void cifs_oplock_break(struct work_struct *work)
 {
        struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
@@ -2486,7 +2522,7 @@ const struct address_space_operations cifs_addr_ops = {
        .set_page_dirty = __set_page_dirty_nobuffers,
        .releasepage = cifs_release_page,
        .invalidatepage = cifs_invalidate_page,
-       /* .direct_IO = */
+       .launder_page = cifs_launder_page,
 };
 
 /*
@@ -2503,5 +2539,5 @@ const struct address_space_operations cifs_addr_ops_smallbuf = {
        .set_page_dirty = __set_page_dirty_nobuffers,
        .releasepage = cifs_release_page,
        .invalidatepage = cifs_invalidate_page,
-       /* .direct_IO = */
+       .launder_page = cifs_launder_page,
 };