10 #include <linux/kernel.h>
15 #include <linux/export.h>
42 void (*invalidatepage)(
struct page *,
unsigned long);
43 invalidatepage = page->
mapping->a_ops->invalidatepage;
52 static inline void truncate_partial_page(
struct page *
page,
unsigned partial)
55 cleancache_invalidate_page(page->
mapping, page);
56 if (page_has_private(page))
76 if (TestClearPageDirty(page)) {
78 if (mapping && mapping_cap_account_dirty(mapping)) {
83 task_io_account_cancelled_write(account_size);
105 if (page_has_private(page))
110 ClearPageMappedToDisk(page);
124 invalidate_complete_page(
struct address_space *mapping,
struct page *page)
141 if (page_mapped(page)) {
146 return truncate_complete_page(mapping, page);
177 if (PageDirty(page) || PageWriteback(page))
179 if (page_mapped(page))
181 return invalidate_complete_page(mapping, page);
205 loff_t lstart, loff_t lend)
214 cleancache_invalidate_inode(mapping);
221 pagevec_init(&pvec, 0);
226 for (i = 0; i < pagevec_count(&pvec); i++) {
227 struct page *page = pvec.
pages[
i];
234 if (!trylock_page(page))
237 if (PageWriteback(page)) {
244 pagevec_release(&pvec);
253 wait_on_page_writeback(page);
254 truncate_partial_page(page, partial);
270 if (index == start && pvec.
pages[0]->index > end) {
271 pagevec_release(&pvec);
275 for (i = 0; i < pagevec_count(&pvec); i++) {
276 struct page *page = pvec.
pages[
i];
285 wait_on_page_writeback(page);
289 pagevec_release(&pvec);
293 cleancache_invalidate_inode(mapping);
334 unsigned long count = 0;
345 pagevec_init(&pvec, 0);
349 for (i = 0; i < pagevec_count(&pvec); i++) {
350 struct page *page = pvec.
pages[
i];
357 if (!trylock_page(page))
370 pagevec_release(&pvec);
387 invalidate_complete_page2(
struct address_space *mapping,
struct page *page)
399 BUG_ON(page_has_private(page));
404 if (mapping->
a_ops->freepage)
405 mapping->
a_ops->freepage(page);
414 static int do_launder_page(
struct address_space *mapping,
struct page *page)
416 if (!PageDirty(page))
420 return mapping->
a_ops->launder_page(page);
442 int did_range_unmap = 0;
444 cleancache_invalidate_inode(mapping);
445 pagevec_init(&pvec, 0);
450 for (i = 0; i < pagevec_count(&pvec); i++) {
451 struct page *page = pvec.
pages[
i];
460 if (page->
mapping != mapping) {
464 wait_on_page_writeback(page);
465 if (page_mapped(page)) {
466 if (!did_range_unmap) {
472 (loff_t)(1 + end - index)
485 BUG_ON(page_mapped(page));
486 ret2 = do_launder_page(mapping, page);
488 if (!invalidate_complete_page2(mapping, page))
495 pagevec_release(&pvec);
500 cleancache_invalidate_inode(mapping);
573 i_size_write(inode, newsize);
596 if (inode->
i_op->truncate)
597 inode->
i_op->truncate(inode);
635 if ((
u64)unmap_end > (
u64)unmap_start)
637 1 + unmap_end - unmap_start, 0);