blob: d49de3d70456f1b2ea31774f559657d29ca8e812 [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 Hellwig993386c12007-08-28 16:12:30 +100019#include "xfs_vnodeops.h"
Christoph Hellwig993386c12007-08-28 16:12:30 +100020#include "xfs_bmap_btree.h"
Christoph Hellwig993386c12007-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 */
Lachlan McIlroyd3cf20942007-05-08 13:49:27 +100028int
Christoph Hellwig993386c12007-08-28 16:12:30 +100029xfs_flushinval_pages(
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;
Lachlan McIlroyd3cf20942007-05-08 13:49:27 +100036 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000038 trace_xfs_pagecache_inval(ip, first, last);
39
Dave Chinner3ae4c9d2010-08-24 12:01:50 +100040 xfs_iflags_clear(ip, XFS_ITRUNCATED);
41 ret = filemap_write_and_wait_range(mapping, first,
42 last == -1 ? LLONG_MAX : last);
43 if (!ret)
44 truncate_inode_pages_range(mapping, first, last);
Dave Chinner2e656092008-11-28 14:23:33 +110045 return -ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048int
Christoph Hellwig993386c12007-08-28 16:12:30 +100049xfs_flush_pages(
50 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 xfs_off_t first,
52 xfs_off_t last,
53 uint64_t flags,
54 int fiopt)
55{
David Chinner01651642008-08-13 15:45:15 +100056 struct address_space *mapping = VFS_I(ip)->i_mapping;
Lachlan McIlroyd3cf20942007-05-08 13:49:27 +100057 int ret = 0;
58 int ret2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Dave Chinner3ae4c9d2010-08-24 12:01:50 +100060 xfs_iflags_clear(ip, XFS_ITRUNCATED);
61 ret = -filemap_fdatawrite_range(mapping, first,
62 last == -1 ? LLONG_MAX : last);
Christoph Hellwig0cadda12010-01-19 09:56:44 +000063 if (flags & XBF_ASYNC)
Dave Chinnera8d770d2009-04-06 18:44:54 +020064 return ret;
65 ret2 = xfs_wait_on_pages(ip, first, last);
66 if (!ret)
67 ret = ret2;
68 return ret;
Dave Chinner2e656092008-11-28 14:23:33 +110069}
70
71int
72xfs_wait_on_pages(
73 xfs_inode_t *ip,
74 xfs_off_t first,
75 xfs_off_t last)
76{
77 struct address_space *mapping = VFS_I(ip)->i_mapping;
78
Dave Chinner3ae4c9d2010-08-24 12:01:50 +100079 if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) {
80 return -filemap_fdatawait_range(mapping, first,
Christoph Hellwigce7ae1512011-12-18 20:00:11 +000081 last == -1 ? XFS_ISIZE(ip) - 1 : last);
Dave Chinner3ae4c9d2010-08-24 12:01:50 +100082 }
Dave Chinner2e656092008-11-28 14:23:33 +110083 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}