xfs_fs_subr.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "xfs_trace.h"
  23. /*
  24. * note: all filemap functions return negative error codes. These
  25. * need to be inverted before returning to the xfs core functions.
  26. */
  27. void
  28. xfs_tosspages(
  29. xfs_inode_t *ip,
  30. xfs_off_t first,
  31. xfs_off_t last,
  32. int fiopt)
  33. {
  34. struct address_space *mapping = VFS_I(ip)->i_mapping;
  35. if (mapping->nrpages)
  36. truncate_inode_pages(mapping, first);
  37. }
  38. int
  39. xfs_flushinval_pages(
  40. xfs_inode_t *ip,
  41. xfs_off_t first,
  42. xfs_off_t last,
  43. int fiopt)
  44. {
  45. struct address_space *mapping = VFS_I(ip)->i_mapping;
  46. int ret = 0;
  47. trace_xfs_pagecache_inval(ip, first, last);
  48. if (mapping->nrpages) {
  49. xfs_iflags_clear(ip, XFS_ITRUNCATED);
  50. ret = filemap_write_and_wait(mapping);
  51. if (!ret)
  52. truncate_inode_pages(mapping, first);
  53. }
  54. return -ret;
  55. }
  56. int
  57. xfs_flush_pages(
  58. xfs_inode_t *ip,
  59. xfs_off_t first,
  60. xfs_off_t last,
  61. uint64_t flags,
  62. int fiopt)
  63. {
  64. struct address_space *mapping = VFS_I(ip)->i_mapping;
  65. int ret = 0;
  66. int ret2;
  67. if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
  68. xfs_iflags_clear(ip, XFS_ITRUNCATED);
  69. ret = -filemap_fdatawrite(mapping);
  70. }
  71. if (flags & XBF_ASYNC)
  72. return ret;
  73. ret2 = xfs_wait_on_pages(ip, first, last);
  74. if (!ret)
  75. ret = ret2;
  76. return ret;
  77. }
  78. int
  79. xfs_wait_on_pages(
  80. xfs_inode_t *ip,
  81. xfs_off_t first,
  82. xfs_off_t last)
  83. {
  84. struct address_space *mapping = VFS_I(ip)->i_mapping;
  85. if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK))
  86. return -filemap_fdatawait(mapping);
  87. return 0;
  88. }