blob: 7501b85fd8606bb94d8983f3175505bf580ec456 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7d4fb402006-06-09 15:27:16 +10002 * Copyright (c) 2000-2002,2005-2006 Silicon Graphics, Inc.
Nathan Scott7b718762005-11-02 14:58:39 +11003 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Christoph Hellwig993386c2007-08-28 16:12:30 +100019#include "xfs_vnodeops.h"
Christoph Hellwig993386c2007-08-28 16:12:30 +100020#include "xfs_bmap_btree.h"
Christoph Hellwig993386c2007-08-28 16:12:30 +100021#include "xfs_inode.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000022#include "xfs_trace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Nathan Scott7d4fb402006-06-09 15:27:16 +100024int fs_noerr(void) { return 0; }
25int fs_nosys(void) { return ENOSYS; }
26void fs_noval(void) { return; }
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Dave Chinner2e656092008-11-28 14:23:33 +110028/*
29 * note: all filemap functions return negative error codes. These
30 * need to be inverted before returning to the xfs core functions.
31 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032void
Christoph Hellwig993386c2007-08-28 16:12:30 +100033xfs_tosspages(
34 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 xfs_off_t first,
36 xfs_off_t last,
37 int fiopt)
38{
David Chinner01651642008-08-13 15:45:15 +100039 struct address_space *mapping = VFS_I(ip)->i_mapping;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110041 if (mapping->nrpages)
42 truncate_inode_pages(mapping, first);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100045int
Christoph Hellwig993386c2007-08-28 16:12:30 +100046xfs_flushinval_pages(
47 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 xfs_off_t first,
49 xfs_off_t last,
50 int fiopt)
51{
David Chinner01651642008-08-13 15:45:15 +100052 struct address_space *mapping = VFS_I(ip)->i_mapping;
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100053 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000055 trace_xfs_pagecache_inval(ip, first, last);
56
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110057 if (mapping->nrpages) {
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +100058 xfs_iflags_clear(ip, XFS_ITRUNCATED);
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110059 ret = filemap_write_and_wait(mapping);
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100060 if (!ret)
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110061 truncate_inode_pages(mapping, first);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 }
Dave Chinner2e656092008-11-28 14:23:33 +110063 return -ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066int
Christoph Hellwig993386c2007-08-28 16:12:30 +100067xfs_flush_pages(
68 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 xfs_off_t first,
70 xfs_off_t last,
71 uint64_t flags,
72 int fiopt)
73{
David Chinner01651642008-08-13 15:45:15 +100074 struct address_space *mapping = VFS_I(ip)->i_mapping;
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100075 int ret = 0;
76 int ret2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110078 if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +100079 xfs_iflags_clear(ip, XFS_ITRUNCATED);
Dave Chinnera8d770d2009-04-06 18:44:54 +020080 ret = -filemap_fdatawrite(mapping);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
Dave Chinnera8d770d2009-04-06 18:44:54 +020082 if (flags & XFS_B_ASYNC)
83 return ret;
84 ret2 = xfs_wait_on_pages(ip, first, last);
85 if (!ret)
86 ret = ret2;
87 return ret;
Dave Chinner2e656092008-11-28 14:23:33 +110088}
89
90int
91xfs_wait_on_pages(
92 xfs_inode_t *ip,
93 xfs_off_t first,
94 xfs_off_t last)
95{
96 struct address_space *mapping = VFS_I(ip)->i_mapping;
97
98 if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK))
99 return -filemap_fdatawait(mapping);
100 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}