From: Simon Wilkinson Date: Mon, 25 Apr 2011 18:18:39 +0000 (-0400) Subject: Linux: Don't read pages beyond the cache eof X-Git-Tag: openafs-devel-1_7_1~543 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=79d5b5cce65b10134004c4cb2b7b34ac509cba6a;hp=64c92b24447aa1a86a4557d6bab3a72b38640fce Linux: Don't read pages beyond the cache eof 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 Tested-by: Derrick Brashear --- diff --git a/src/afs/LINUX/osi_vnodeops.c b/src/afs/LINUX/osi_vnodeops.c index 2b02f55..79a61e4 100644 --- a/src/afs/LINUX/osi_vnodeops.c +++ b/src/afs/LINUX/osi_vnodeops.c @@ -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;