xfs_fs_subr.c 2.3 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. /* can't toss partial tail pages, so mask them out */
  35. last &= ~(PAGE_SIZE - 1);
  36. truncate_inode_pages_range(VFS_I(ip)->i_mapping, first, last - 1);
  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. xfs_iflags_clear(ip, XFS_ITRUNCATED);
  49. ret = filemap_write_and_wait_range(mapping, first,
  50. last == -1 ? LLONG_MAX : last);
  51. if (!ret)
  52. truncate_inode_pages_range(mapping, first, last);
  53. return -ret;
  54. }
  55. int
  56. xfs_flush_pages(
  57. xfs_inode_t *ip,
  58. xfs_off_t first,
  59. xfs_off_t last,
  60. uint64_t flags,
  61. int fiopt)
  62. {
  63. struct address_space *mapping = VFS_I(ip)->i_mapping;
  64. int ret = 0;
  65. int ret2;
  66. xfs_iflags_clear(ip, XFS_ITRUNCATED);
  67. ret = -filemap_fdatawrite_range(mapping, first,
  68. last == -1 ? LLONG_MAX : last);
  69. if (flags & XBF_ASYNC)
  70. return ret;
  71. ret2 = xfs_wait_on_pages(ip, first, last);
  72. if (!ret)
  73. ret = ret2;
  74. return ret;
  75. }
  76. int
  77. xfs_wait_on_pages(
  78. xfs_inode_t *ip,
  79. xfs_off_t first,
  80. xfs_off_t last)
  81. {
  82. struct address_space *mapping = VFS_I(ip)->i_mapping;
  83. if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) {
  84. return -filemap_fdatawait_range(mapping, first,
  85. last == -1 ? ip->i_size - 1 : last);
  86. }
  87. return 0;
  88. }