Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7d4fb40 | 2006-06-09 15:27:16 +1000 | [diff] [blame] | 2 | * Copyright (c) 2000-2002,2005-2006 Silicon Graphics, Inc. |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 19 | #include "xfs_vnodeops.h" |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 20 | #include "xfs_bmap_btree.h" |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 21 | #include "xfs_inode.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 22 | #include "xfs_trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Dave Chinner | 2e65609 | 2008-11-28 14:23:33 +1100 | [diff] [blame] | 24 | /* |
| 25 | * note: all filemap functions return negative error codes. These |
| 26 | * need to be inverted before returning to the xfs core functions. |
| 27 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | void |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 29 | xfs_tosspages( |
| 30 | xfs_inode_t *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | xfs_off_t first, |
| 32 | xfs_off_t last, |
| 33 | int fiopt) |
| 34 | { |
Dave Chinner | 3ae4c9d | 2010-08-24 12:01:50 +1000 | [diff] [blame] | 35 | /* can't toss partial tail pages, so mask them out */ |
| 36 | last &= ~(PAGE_SIZE - 1); |
| 37 | truncate_inode_pages_range(VFS_I(ip)->i_mapping, first, last - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Lachlan McIlroy | d3cf209 | 2007-05-08 13:49:27 +1000 | [diff] [blame] | 40 | int |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 41 | xfs_flushinval_pages( |
| 42 | xfs_inode_t *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | xfs_off_t first, |
| 44 | xfs_off_t last, |
| 45 | int fiopt) |
| 46 | { |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 47 | struct address_space *mapping = VFS_I(ip)->i_mapping; |
Lachlan McIlroy | d3cf209 | 2007-05-08 13:49:27 +1000 | [diff] [blame] | 48 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 50 | trace_xfs_pagecache_inval(ip, first, last); |
| 51 | |
Dave Chinner | 3ae4c9d | 2010-08-24 12:01:50 +1000 | [diff] [blame] | 52 | xfs_iflags_clear(ip, XFS_ITRUNCATED); |
| 53 | ret = filemap_write_and_wait_range(mapping, first, |
| 54 | last == -1 ? LLONG_MAX : last); |
| 55 | if (!ret) |
| 56 | truncate_inode_pages_range(mapping, first, last); |
Dave Chinner | 2e65609 | 2008-11-28 14:23:33 +1100 | [diff] [blame] | 57 | return -ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | int |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 61 | xfs_flush_pages( |
| 62 | xfs_inode_t *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | xfs_off_t first, |
| 64 | xfs_off_t last, |
| 65 | uint64_t flags, |
| 66 | int fiopt) |
| 67 | { |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 68 | struct address_space *mapping = VFS_I(ip)->i_mapping; |
Lachlan McIlroy | d3cf209 | 2007-05-08 13:49:27 +1000 | [diff] [blame] | 69 | int ret = 0; |
| 70 | int ret2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Dave Chinner | 3ae4c9d | 2010-08-24 12:01:50 +1000 | [diff] [blame] | 72 | xfs_iflags_clear(ip, XFS_ITRUNCATED); |
| 73 | ret = -filemap_fdatawrite_range(mapping, first, |
| 74 | last == -1 ? LLONG_MAX : last); |
Christoph Hellwig | 0cadda1 | 2010-01-19 09:56:44 +0000 | [diff] [blame] | 75 | if (flags & XBF_ASYNC) |
Dave Chinner | a8d770d | 2009-04-06 18:44:54 +0200 | [diff] [blame] | 76 | return ret; |
| 77 | ret2 = xfs_wait_on_pages(ip, first, last); |
| 78 | if (!ret) |
| 79 | ret = ret2; |
| 80 | return ret; |
Dave Chinner | 2e65609 | 2008-11-28 14:23:33 +1100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | int |
| 84 | xfs_wait_on_pages( |
| 85 | xfs_inode_t *ip, |
| 86 | xfs_off_t first, |
| 87 | xfs_off_t last) |
| 88 | { |
| 89 | struct address_space *mapping = VFS_I(ip)->i_mapping; |
| 90 | |
Dave Chinner | 3ae4c9d | 2010-08-24 12:01:50 +1000 | [diff] [blame] | 91 | if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) { |
| 92 | return -filemap_fdatawait_range(mapping, first, |
Christoph Hellwig | ce7ae15 | 2011-12-18 20:00:11 +0000 | [diff] [blame] | 93 | last == -1 ? XFS_ISIZE(ip) - 1 : last); |
Dave Chinner | 3ae4c9d | 2010-08-24 12:01:50 +1000 | [diff] [blame] | 94 | } |
Dave Chinner | 2e65609 | 2008-11-28 14:23:33 +1100 | [diff] [blame] | 95 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |