blob: 5aeb777769613152297ebacb0d5a9ade99f7f26c [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Nathan Scott7d4fb402006-06-09 15:27:16 +100023int fs_noerr(void) { return 0; }
24int fs_nosys(void) { return ENOSYS; }
25void fs_noval(void) { return; }
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Dave Chinner2e656092008-11-28 14:23:33 +110027/*
28 * note: all filemap functions return negative error codes. These
29 * need to be inverted before returning to the xfs core functions.
30 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031void
Christoph Hellwig993386c2007-08-28 16:12:30 +100032xfs_tosspages(
33 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 xfs_off_t first,
35 xfs_off_t last,
36 int fiopt)
37{
David Chinner01651642008-08-13 15:45:15 +100038 struct address_space *mapping = VFS_I(ip)->i_mapping;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110040 if (mapping->nrpages)
41 truncate_inode_pages(mapping, first);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100044int
Christoph Hellwig993386c2007-08-28 16:12:30 +100045xfs_flushinval_pages(
46 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 xfs_off_t first,
48 xfs_off_t last,
49 int fiopt)
50{
David Chinner01651642008-08-13 15:45:15 +100051 struct address_space *mapping = VFS_I(ip)->i_mapping;
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100052 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110054 if (mapping->nrpages) {
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +100055 xfs_iflags_clear(ip, XFS_ITRUNCATED);
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110056 ret = filemap_write_and_wait(mapping);
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100057 if (!ret)
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110058 truncate_inode_pages(mapping, first);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 }
Dave Chinner2e656092008-11-28 14:23:33 +110060 return -ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063int
Christoph Hellwig993386c2007-08-28 16:12:30 +100064xfs_flush_pages(
65 xfs_inode_t *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 xfs_off_t first,
67 xfs_off_t last,
68 uint64_t flags,
69 int fiopt)
70{
David Chinner01651642008-08-13 15:45:15 +100071 struct address_space *mapping = VFS_I(ip)->i_mapping;
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100072 int ret = 0;
73 int ret2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110075 if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +100076 xfs_iflags_clear(ip, XFS_ITRUNCATED);
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110077 ret = filemap_fdatawrite(mapping);
Nathan Scottee348072005-11-02 10:32:38 +110078 if (flags & XFS_B_ASYNC)
Dave Chinner2e656092008-11-28 14:23:33 +110079 return -ret;
Christoph Hellwiga8b3acd2008-03-06 13:44:41 +110080 ret2 = filemap_fdatawait(mapping);
Lachlan McIlroyd3cf2092007-05-08 13:49:27 +100081 if (!ret)
82 ret = ret2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
Dave Chinner2e656092008-11-28 14:23:33 +110084 return -ret;
85}
86
87int
88xfs_wait_on_pages(
89 xfs_inode_t *ip,
90 xfs_off_t first,
91 xfs_off_t last)
92{
93 struct address_space *mapping = VFS_I(ip)->i_mapping;
94
95 if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK))
96 return -filemap_fdatawait(mapping);
97 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}