xfs_fs_subr.c 2.3 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2
 * Copyright (c) 2000-2002,2005-2006 Silicon Graphics, Inc.
3
 * All Rights Reserved.
L
Linus Torvalds 已提交
4
 *
5 6
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
L
Linus Torvalds 已提交
7 8
 * published by the Free Software Foundation.
 *
9 10 11 12
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
L
Linus Torvalds 已提交
13
 *
14 15 16
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
L
Linus Torvalds 已提交
17 18
 */
#include "xfs.h"
19 20 21
#include "xfs_vnodeops.h"
#include "xfs_bmap_btree.h"
#include "xfs_inode.h"
C
Christoph Hellwig 已提交
22
#include "xfs_trace.h"
L
Linus Torvalds 已提交
23

24 25 26 27
/*
 * note: all filemap functions return negative error codes. These
 * need to be inverted before returning to the xfs core functions.
 */
L
Linus Torvalds 已提交
28
void
29 30
xfs_tosspages(
	xfs_inode_t	*ip,
L
Linus Torvalds 已提交
31 32 33 34
	xfs_off_t	first,
	xfs_off_t	last,
	int		fiopt)
{
35 36 37
	/* can't toss partial tail pages, so mask them out */
	last &= ~(PAGE_SIZE - 1);
	truncate_inode_pages_range(VFS_I(ip)->i_mapping, first, last - 1);
L
Linus Torvalds 已提交
38 39
}

40
int
41 42
xfs_flushinval_pages(
	xfs_inode_t	*ip,
L
Linus Torvalds 已提交
43 44 45 46
	xfs_off_t	first,
	xfs_off_t	last,
	int		fiopt)
{
47
	struct address_space *mapping = VFS_I(ip)->i_mapping;
48
	int		ret = 0;
L
Linus Torvalds 已提交
49

C
Christoph Hellwig 已提交
50 51
	trace_xfs_pagecache_inval(ip, first, last);

52 53 54 55 56
	xfs_iflags_clear(ip, XFS_ITRUNCATED);
	ret = filemap_write_and_wait_range(mapping, first,
				last == -1 ? LLONG_MAX : last);
	if (!ret)
		truncate_inode_pages_range(mapping, first, last);
57
	return -ret;
L
Linus Torvalds 已提交
58 59 60
}

int
61 62
xfs_flush_pages(
	xfs_inode_t	*ip,
L
Linus Torvalds 已提交
63 64 65 66 67
	xfs_off_t	first,
	xfs_off_t	last,
	uint64_t	flags,
	int		fiopt)
{
68
	struct address_space *mapping = VFS_I(ip)->i_mapping;
69 70
	int		ret = 0;
	int		ret2;
L
Linus Torvalds 已提交
71

72 73 74
	xfs_iflags_clear(ip, XFS_ITRUNCATED);
	ret = -filemap_fdatawrite_range(mapping, first,
				last == -1 ? LLONG_MAX : last);
75
	if (flags & XBF_ASYNC)
76 77 78 79 80
		return ret;
	ret2 = xfs_wait_on_pages(ip, first, last);
	if (!ret)
		ret = ret2;
	return ret;
81 82 83 84 85 86 87 88 89 90
}

int
xfs_wait_on_pages(
	xfs_inode_t	*ip,
	xfs_off_t	first,
	xfs_off_t	last)
{
	struct address_space *mapping = VFS_I(ip)->i_mapping;

91 92
	if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) {
		return -filemap_fdatawait_range(mapping, first,
93
					last == -1 ? XFS_ISIZE(ip) - 1 : last);
94
	}
95
	return 0;
L
Linus Torvalds 已提交
96
}