Linux: Don't read pages beyond the cache eof
authorSimon Wilkinson <sxw@your-file-system.com>
Mon, 25 Apr 2011 18:18:39 +0000 (14:18 -0400)
committerDerrick Brashear <shadow@dementia.org>
Tue, 3 May 2011 02:20:03 +0000 (19:20 -0700)
If we attempt to read past the end of the current cache file (for
example, when we're extending the file with ftruncate), don't force
the backend filesystem to populate that page with non-existent data.

This will hopefully fix a bus error when using tmpfs as a backing
cache.

FIXES 128452

Reviewed-on: http://gerrit.openafs.org/4562
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
(cherry picked from commit 79d5b5cce65b10134004c4cb2b7b34ac509cba6a)

Change-Id: Id9956be824a4c4d8db7deb65403f4d9740758e42
Reviewed-on: http://gerrit.openafs.org/4600
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/afs/LINUX/osi_vnodeops.c

index d8d23b5..45e0a35 100644 (file)
@@ -1415,15 +1415,26 @@ afs_linux_read_cache(struct file *cachefp, struct page *page,
                     int chunk, struct pagevec *lrupv,
                     struct afs_pagecopy_task *task) {
     loff_t offset = page_offset(page);
+    struct inode *cacheinode = cachefp->f_dentry->d_inode;
     struct page *newpage, *cachepage;
     struct address_space *cachemapping;
-    int pageindex;
+    int pageindex, endindex;
     int code = 0;
 
-    cachemapping = cachefp->f_dentry->d_inode->i_mapping;
+    cachemapping = cacheinode->i_mapping;
     newpage = NULL;
     cachepage = NULL;
 
+    /* If we're trying to read a page that's past the end of the disk
+     * cache file, then just return a zeroed page */
+    if (offset >= i_size_read(cacheinode)) {
+       zero_user_segment(page, 0, PAGE_CACHE_SIZE);
+       SetPageUptodate(page);
+       if (task)
+           unlock_page(page);
+       return 0;
+    }
+
     /* From our offset, we now need to work out which page in the disk
      * file it corresponds to. This will be fun ... */
     pageindex = (offset - AFS_CHUNKTOBASE(chunk)) >> PAGE_CACHE_SHIFT;