From 79d5b5cce65b10134004c4cb2b7b34ac509cba6a Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Mon, 25 Apr 2011 14:18:39 -0400 Subject: [PATCH 1/1] 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 --- src/afs/LINUX/osi_vnodeops.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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; -- 1.9.4