blob: 1f279b012f94be7fd4ef2f5fbf084b89921804c1 [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
Dave Chinner2e656092008-11-28 14:23:33 +110024/*
25 * note: all filemap functions return negative error codes. These
26 * need to be inverted before returning to the xfs core functions.
27 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028void
Christoph Hellwig993386c2007-08-28 16:12:30 +100029xfs_tosspages(
30 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 xfs_off_t first,
32 xfs_off_t last,
33 int fiopt)
34{
David Chinner01651642008-08-13 15:45:15 +100035 struct address_space *mapping = VFS_I(ip)->i_mapping;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110037 if (mapping->nrpages)
38 truncate_inode_pages(mapping, first);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100041int
Christoph Hellwig993386c2007-08-28 16:12:30 +100042xfs_flushinval_pages(
43 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 xfs_off_t first,
45 xfs_off_t last,
46 int fiopt)
47{
David Chinner01651642008-08-13 15:45:15 +100048 struct address_space *mapping = VFS_I(ip)->i_mapping;
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100049 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000051 trace_xfs_pagecache_inval(ip, first, last);
52
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110053 if (mapping->nrpages) {
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +100054 xfs_iflags_clear(ip, XFS_ITRUNCATED);
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110055 ret = filemap_write_and_wait(mapping);
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100056 if (!ret)
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110057 truncate_inode_pages(mapping, first);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 }
Dave Chinner2e656092008-11-28 14:23:33 +110059 return -ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062int
Christoph Hellwig993386c2007-08-28 16:12:30 +100063xfs_flush_pages(
64 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 xfs_off_t first,
66 xfs_off_t last,
67 uint64_t flags,
68 int fiopt)
69{
David Chinner01651642008-08-13 15:45:15 +100070 struct address_space *mapping = VFS_I(ip)->i_mapping;
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100071 int ret = 0;
72 int ret2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110074 if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +100075 xfs_iflags_clear(ip, XFS_ITRUNCATED);
Dave Chinnera8d770d2009-04-06 18:44:54 +020076 ret = -filemap_fdatawrite(mapping);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
Christoph Hellwig0cadda12010-01-19 09:56:44 +000078 if (flags & XBF_ASYNC)
Dave Chinnera8d770d2009-04-06 18:44:54 +020079 return ret;
80 ret2 = xfs_wait_on_pages(ip, first, last);
81 if (!ret)
82 ret = ret2;
83 return ret;
Dave Chinner2e656092008-11-28 14:23:33 +110084}
85
86int
87xfs_wait_on_pages(
88 xfs_inode_t *ip,
89 xfs_off_t first,
90 xfs_off_t last)
91{
92 struct address_space *mapping = VFS_I(ip)->i_mapping;
93
94 if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK))
95 return -filemap_fdatawait(mapping);
96 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}