blob: 652b875a9d4c441bd3c759df185c153dfee0e8f5 [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{
Dave Chinner3ae4c9d2010-08-24 12:01:50 +100035 /* 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 Torvalds1da177e2005-04-16 15:20:36 -070038}
39
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100040int
Christoph Hellwig993386c2007-08-28 16:12:30 +100041xfs_flushinval_pages(
42 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 xfs_off_t first,
44 xfs_off_t last,
45 int fiopt)
46{
David Chinner01651642008-08-13 15:45:15 +100047 struct address_space *mapping = VFS_I(ip)->i_mapping;
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100048 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000050 trace_xfs_pagecache_inval(ip, first, last);
51
Dave Chinner3ae4c9d2010-08-24 12:01:50 +100052 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 Chinner2e656092008-11-28 14:23:33 +110057 return -ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060int
Christoph Hellwig993386c2007-08-28 16:12:30 +100061xfs_flush_pages(
62 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 xfs_off_t first,
64 xfs_off_t last,
65 uint64_t flags,
66 int fiopt)
67{
David Chinner01651642008-08-13 15:45:15 +100068 struct address_space *mapping = VFS_I(ip)->i_mapping;
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100069 int ret = 0;
70 int ret2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Dave Chinner3ae4c9d2010-08-24 12:01:50 +100072 xfs_iflags_clear(ip, XFS_ITRUNCATED);
73 ret = -filemap_fdatawrite_range(mapping, first,
74 last == -1 ? LLONG_MAX : last);
Christoph Hellwig0cadda12010-01-19 09:56:44 +000075 if (flags & XBF_ASYNC)
Dave Chinnera8d770d2009-04-06 18:44:54 +020076 return ret;
77 ret2 = xfs_wait_on_pages(ip, first, last);
78 if (!ret)
79 ret = ret2;
80 return ret;
Dave Chinner2e656092008-11-28 14:23:33 +110081}
82
83int
84xfs_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 Chinner3ae4c9d2010-08-24 12:01:50 +100091 if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) {
92 return -filemap_fdatawait_range(mapping, first,
Christoph Hellwigce7ae1512011-12-18 20:00:11 +000093 last == -1 ? XFS_ISIZE(ip) - 1 : last);
Dave Chinner3ae4c9d2010-08-24 12:01:50 +100094 }
Dave Chinner2e656092008-11-28 14:23:33 +110095 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}