From cfd3d87a31ae855f3156ad8461ba12bc9ea163d3 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 14 Aug 2009 14:37:36 -0700 Subject: [PATCH] kclient: zero pages we did readahead on If we get -ENOENT or a short read on readahead, we should still zero the pages and add them to the page cache, to avoid a future readpage on each one. --- src/kernel/addr.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/kernel/addr.c b/src/kernel/addr.c index e0fe3f445e47b..56cfc95cd85fb 100644 --- a/src/kernel/addr.c +++ b/src/kernel/addr.c @@ -295,24 +295,27 @@ static int ceph_readpages(struct file *file, struct address_space *mapping, offset, &len, ci->i_truncate_seq, ci->i_truncate_size, pages, nr_pages); + if (rc == -ENOENT) + rc = 0; if (rc < 0) goto out; /* set uptodate and add to lru in pagevec-sized chunks */ pagevec_init(&pvec, 0); - for (; rc > 0; rc -= PAGE_CACHE_SIZE) { - struct page *page; + for (; !list_empty(page_list) && len > 0; + rc -= PAGE_CACHE_SIZE, len -= PAGE_CACHE_SIZE) { + struct page *page = + list_entry(page_list->prev, struct page, lru); - BUG_ON(list_empty(page_list)); - page = list_entry(page_list->prev, struct page, lru); list_del(&page->lru); if (rc < PAGE_CACHE_SIZE) { - /* zero remainder of page */ + /* zero (remainder of) page */ + int s = rc < 0 ? 0 : rc; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25) - zero_user_segment(page, rc, PAGE_CACHE_SIZE); + zero_user_segment(page, s, PAGE_CACHE_SIZE); #else - zero_user_page(page, rc, PAGE_CACHE_SIZE-rc, KM_USER0); + zero_user_page(page, s, PAGE_CACHE_SIZE-s, KM_USER0); #endif } -- 2.39.5