xfs_fs_subr.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2000-2002,2005-2006 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * 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.
  13. *
  14. * 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
  17. */
  18. #include "xfs.h"
  19. #include "xfs_vnodeops.h"
  20. #include "xfs_bmap_btree.h"
  21. #include "xfs_inode.h"
  22. int fs_noerr(void) { return 0; }
  23. int fs_nosys(void) { return ENOSYS; }
  24. void fs_noval(void) { return; }
  25. /*
  26. * note: all filemap functions return negative error codes. These
  27. * need to be inverted before returning to the xfs core functions.
  28. */
  29. void
  30. xfs_tosspages(
  31. xfs_inode_t *ip,
  32. xfs_off_t first,
  33. xfs_off_t last,
  34. int fiopt)
  35. {
  36. struct address_space *mapping = VFS_I(ip)->i_mapping;
  37. if (mapping->nrpages)
  38. truncate_inode_pages(mapping, first);
  39. }
  40. int
  41. xfs_flushinval_pages(
  42. xfs_inode_t *ip,
  43. xfs_off_t first,
  44. xfs_off_t last,
  45. int fiopt)
  46. {
  47. struct address_space *mapping = VFS_I(ip)->i_mapping;
  48. int ret = 0;
  49. if (mapping->nrpages) {
  50. xfs_iflags_clear(ip, XFS_ITRUNCATED);
  51. ret = filemap_write_and_wait(mapping);
  52. if (!ret)
  53. truncate_inode_pages(mapping, first);
  54. }
  55. return -ret;
  56. }
  57. int
  58. xfs_flush_pages(
  59. xfs_inode_t *ip,
  60. xfs_off_t first,
  61. xfs_off_t last,
  62. uint64_t flags,
  63. int fiopt)
  64. {
  65. struct address_space *mapping = VFS_I(ip)->i_mapping;
  66. int ret = 0;
  67. int ret2;
  68. if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
  69. xfs_iflags_clear(ip, XFS_ITRUNCATED);
  70. ret = -filemap_fdatawrite(mapping);
  71. }
  72. if (flags & XFS_B_ASYNC)
  73. return ret;
  74. ret2 = xfs_wait_on_pages(ip, first, last);
  75. if (!ret)
  76. ret = ret2;
  77. return ret;
  78. }
  79. int
  80. xfs_wait_on_pages(
  81. xfs_inode_t *ip,
  82. xfs_off_t first,
  83. xfs_off_t last)
  84. {
  85. struct address_space *mapping = VFS_I(ip)->i_mapping;
  86. if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK))
  87. return -filemap_fdatawait(mapping);
  88. return 0;
  89. }