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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Nathan Scott | 7d4fb40 | 2006-06-09 15:27:16 +1000 | [diff] [blame] | 23 | int fs_noerr(void) { return 0; } |
| 24 | int fs_nosys(void) { return ENOSYS; } |
| 25 | void fs_noval(void) { return; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Dave Chinner | 2e65609 | 2008-11-28 14:23:33 +1100 | [diff] [blame] | 27 | /* |
| 28 | * note: all filemap functions return negative error codes. These |
| 29 | * need to be inverted before returning to the xfs core functions. |
| 30 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | void |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 32 | xfs_tosspages( |
| 33 | xfs_inode_t *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | xfs_off_t first, |
| 35 | xfs_off_t last, |
| 36 | int fiopt) |
| 37 | { |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 38 | struct address_space *mapping = VFS_I(ip)->i_mapping; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Christoph Hellwig | a8b3acd | 2008-03-06 13:44:41 +1100 | [diff] [blame] | 40 | if (mapping->nrpages) |
| 41 | truncate_inode_pages(mapping, first); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Lachlan McIlroy | d3cf209 | 2007-05-08 13:49:27 +1000 | [diff] [blame] | 44 | int |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 45 | xfs_flushinval_pages( |
| 46 | xfs_inode_t *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | xfs_off_t first, |
| 48 | xfs_off_t last, |
| 49 | int fiopt) |
| 50 | { |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 51 | struct address_space *mapping = VFS_I(ip)->i_mapping; |
Lachlan McIlroy | d3cf209 | 2007-05-08 13:49:27 +1000 | [diff] [blame] | 52 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Christoph Hellwig | a8b3acd | 2008-03-06 13:44:41 +1100 | [diff] [blame] | 54 | if (mapping->nrpages) { |
Christoph Hellwig | b3aea4e | 2007-08-29 11:44:37 +1000 | [diff] [blame] | 55 | xfs_iflags_clear(ip, XFS_ITRUNCATED); |
Christoph Hellwig | a8b3acd | 2008-03-06 13:44:41 +1100 | [diff] [blame] | 56 | ret = filemap_write_and_wait(mapping); |
Lachlan McIlroy | d3cf209 | 2007-05-08 13:49:27 +1000 | [diff] [blame] | 57 | if (!ret) |
Christoph Hellwig | a8b3acd | 2008-03-06 13:44:41 +1100 | [diff] [blame] | 58 | truncate_inode_pages(mapping, first); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
Dave Chinner | 2e65609 | 2008-11-28 14:23:33 +1100 | [diff] [blame] | 60 | return -ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | int |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 64 | xfs_flush_pages( |
| 65 | xfs_inode_t *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | xfs_off_t first, |
| 67 | xfs_off_t last, |
| 68 | uint64_t flags, |
| 69 | int fiopt) |
| 70 | { |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 71 | struct address_space *mapping = VFS_I(ip)->i_mapping; |
Lachlan McIlroy | d3cf209 | 2007-05-08 13:49:27 +1000 | [diff] [blame] | 72 | int ret = 0; |
| 73 | int ret2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Christoph Hellwig | a8b3acd | 2008-03-06 13:44:41 +1100 | [diff] [blame] | 75 | if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) { |
Christoph Hellwig | b3aea4e | 2007-08-29 11:44:37 +1000 | [diff] [blame] | 76 | xfs_iflags_clear(ip, XFS_ITRUNCATED); |
Christoph Hellwig | a8b3acd | 2008-03-06 13:44:41 +1100 | [diff] [blame] | 77 | ret = filemap_fdatawrite(mapping); |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 78 | if (flags & XFS_B_ASYNC) |
Dave Chinner | 2e65609 | 2008-11-28 14:23:33 +1100 | [diff] [blame] | 79 | return -ret; |
Christoph Hellwig | a8b3acd | 2008-03-06 13:44:41 +1100 | [diff] [blame] | 80 | ret2 = filemap_fdatawait(mapping); |
Lachlan McIlroy | d3cf209 | 2007-05-08 13:49:27 +1000 | [diff] [blame] | 81 | if (!ret) |
| 82 | ret = ret2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
Dave Chinner | 2e65609 | 2008-11-28 14:23:33 +1100 | [diff] [blame] | 84 | return -ret; |
| 85 | } |
| 86 | |
| 87 | int |
| 88 | xfs_wait_on_pages( |
| 89 | xfs_inode_t *ip, |
| 90 | xfs_off_t first, |
| 91 | xfs_off_t last) |
| 92 | { |
| 93 | struct address_space *mapping = VFS_I(ip)->i_mapping; |
| 94 | |
| 95 | if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) |
| 96 | return -filemap_fdatawait(mapping); |
| 97 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |