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>
Wed, 27 Apr 2011 17:39:25 +0000 (10:39 -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

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

src/afs/LINUX/osi_vnodeops.c

index 2b02f55..79a61e4 100644 (file)
@@ -1510,15 +1510,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;