xfs_fs_subr.c 2.3 KB

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