xfs_rw.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2000-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_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_bit.h"
  22. #include "xfs_log.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_bmap_btree.h"
  28. #include "xfs_dinode.h"
  29. #include "xfs_inode.h"
  30. #include "xfs_error.h"
  31. #include "xfs_rw.h"
  32. /*
  33. * Force a shutdown of the filesystem instantly while keeping
  34. * the filesystem consistent. We don't do an unmount here; just shutdown
  35. * the shop, make sure that absolutely nothing persistent happens to
  36. * this filesystem after this point.
  37. */
  38. void
  39. xfs_do_force_shutdown(
  40. xfs_mount_t *mp,
  41. int flags,
  42. char *fname,
  43. int lnnum)
  44. {
  45. int logerror;
  46. logerror = flags & SHUTDOWN_LOG_IO_ERROR;
  47. if (!(flags & SHUTDOWN_FORCE_UMOUNT)) {
  48. xfs_notice(mp,
  49. "%s(0x%x) called from line %d of file %s. Return address = 0x%p",
  50. __func__, flags, lnnum, fname, __return_address);
  51. }
  52. /*
  53. * No need to duplicate efforts.
  54. */
  55. if (XFS_FORCED_SHUTDOWN(mp) && !logerror)
  56. return;
  57. /*
  58. * This flags XFS_MOUNT_FS_SHUTDOWN, makes sure that we don't
  59. * queue up anybody new on the log reservations, and wakes up
  60. * everybody who's sleeping on log reservations to tell them
  61. * the bad news.
  62. */
  63. if (xfs_log_force_umount(mp, logerror))
  64. return;
  65. if (flags & SHUTDOWN_CORRUPT_INCORE) {
  66. xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_CORRUPT,
  67. "Corruption of in-memory data detected. Shutting down filesystem");
  68. if (XFS_ERRLEVEL_HIGH <= xfs_error_level)
  69. xfs_stack_trace();
  70. } else if (!(flags & SHUTDOWN_FORCE_UMOUNT)) {
  71. if (logerror) {
  72. xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_LOGERROR,
  73. "Log I/O Error Detected. Shutting down filesystem");
  74. } else if (flags & SHUTDOWN_DEVICE_REQ) {
  75. xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_IOERROR,
  76. "All device paths lost. Shutting down filesystem");
  77. } else if (!(flags & SHUTDOWN_REMOTE_REQ)) {
  78. xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_IOERROR,
  79. "I/O Error Detected. Shutting down filesystem");
  80. }
  81. }
  82. if (!(flags & SHUTDOWN_FORCE_UMOUNT)) {
  83. xfs_alert(mp,
  84. "Please umount the filesystem and rectify the problem(s)");
  85. }
  86. }
  87. /*
  88. * helper function to extract extent size hint from inode
  89. */
  90. xfs_extlen_t
  91. xfs_get_extsz_hint(
  92. struct xfs_inode *ip)
  93. {
  94. if ((ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE) && ip->i_d.di_extsize)
  95. return ip->i_d.di_extsize;
  96. if (XFS_IS_REALTIME_INODE(ip))
  97. return ip->i_mount->m_sb.sb_rextsize;
  98. return 0;
  99. }