Merge branch 'core/iommu' into core/urgent
[linux-2.6] / fs / xfs / linux-2.6 / xfs_fs_subr.c
1 /*
2  * Copyright (c) 2000-2002,2005-2006 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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
7  * published by the Free Software Foundation.
8  *
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.
13  *
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
17  */
18 #include "xfs.h"
19 #include "xfs_vnodeops.h"
20 #include "xfs_bmap_btree.h"
21 #include "xfs_inode.h"
22
23 int  fs_noerr(void) { return 0; }
24 int  fs_nosys(void) { return ENOSYS; }
25 void fs_noval(void) { return; }
26
27 /*
28  * note: all filemap functions return negative error codes. These
29  * need to be inverted before returning to the xfs core functions.
30  */
31 void
32 xfs_tosspages(
33         xfs_inode_t     *ip,
34         xfs_off_t       first,
35         xfs_off_t       last,
36         int             fiopt)
37 {
38         struct address_space *mapping = VFS_I(ip)->i_mapping;
39
40         if (mapping->nrpages)
41                 truncate_inode_pages(mapping, first);
42 }
43
44 int
45 xfs_flushinval_pages(
46         xfs_inode_t     *ip,
47         xfs_off_t       first,
48         xfs_off_t       last,
49         int             fiopt)
50 {
51         struct address_space *mapping = VFS_I(ip)->i_mapping;
52         int             ret = 0;
53
54         if (mapping->nrpages) {
55                 xfs_iflags_clear(ip, XFS_ITRUNCATED);
56                 ret = filemap_write_and_wait(mapping);
57                 if (!ret)
58                         truncate_inode_pages(mapping, first);
59         }
60         return -ret;
61 }
62
63 int
64 xfs_flush_pages(
65         xfs_inode_t     *ip,
66         xfs_off_t       first,
67         xfs_off_t       last,
68         uint64_t        flags,
69         int             fiopt)
70 {
71         struct address_space *mapping = VFS_I(ip)->i_mapping;
72         int             ret = 0;
73         int             ret2;
74
75         if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
76                 xfs_iflags_clear(ip, XFS_ITRUNCATED);
77                 ret = filemap_fdatawrite(mapping);
78                 if (flags & XFS_B_ASYNC)
79                         return -ret;
80                 ret2 = filemap_fdatawait(mapping);
81                 if (!ret)
82                         ret = ret2;
83         }
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;
98 }