/kern_2.6.32/fs/xfs/xfs_filestream.h

http://omnia2droid.googlecode.com/ · C++ Header · 136 lines · 65 code · 14 blank · 57 comment · 0 complexity · c480dc9a36f738acd9f7dd2be9ba0913 MD5 · raw file

  1. /*
  2. * Copyright (c) 2006-2007 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. #ifndef __XFS_FILESTREAM_H__
  19. #define __XFS_FILESTREAM_H__
  20. #ifdef __KERNEL__
  21. struct xfs_mount;
  22. struct xfs_inode;
  23. struct xfs_perag;
  24. struct xfs_bmalloca;
  25. #ifdef XFS_FILESTREAMS_TRACE
  26. #define XFS_FSTRM_KTRACE_INFO 1
  27. #define XFS_FSTRM_KTRACE_AGSCAN 2
  28. #define XFS_FSTRM_KTRACE_AGPICK1 3
  29. #define XFS_FSTRM_KTRACE_AGPICK2 4
  30. #define XFS_FSTRM_KTRACE_UPDATE 5
  31. #define XFS_FSTRM_KTRACE_FREE 6
  32. #define XFS_FSTRM_KTRACE_ITEM_LOOKUP 7
  33. #define XFS_FSTRM_KTRACE_ASSOCIATE 8
  34. #define XFS_FSTRM_KTRACE_MOVEAG 9
  35. #define XFS_FSTRM_KTRACE_ORPHAN 10
  36. #define XFS_FSTRM_KTRACE_SIZE 16384
  37. extern ktrace_t *xfs_filestreams_trace_buf;
  38. #endif
  39. /*
  40. * Allocation group filestream associations are tracked with per-ag atomic
  41. * counters. These counters allow _xfs_filestream_pick_ag() to tell whether a
  42. * particular AG already has active filestreams associated with it. The mount
  43. * point's m_peraglock is used to protect these counters from per-ag array
  44. * re-allocation during a growfs operation. When xfs_growfs_data_private() is
  45. * about to reallocate the array, it calls xfs_filestream_flush() with the
  46. * m_peraglock held in write mode.
  47. *
  48. * Since xfs_mru_cache_flush() guarantees that all the free functions for all
  49. * the cache elements have finished executing before it returns, it's safe for
  50. * the free functions to use the atomic counters without m_peraglock protection.
  51. * This allows the implementation of xfs_fstrm_free_func() to be agnostic about
  52. * whether it was called with the m_peraglock held in read mode, write mode or
  53. * not held at all. The race condition this addresses is the following:
  54. *
  55. * - The work queue scheduler fires and pulls a filestream directory cache
  56. * element off the LRU end of the cache for deletion, then gets pre-empted.
  57. * - A growfs operation grabs the m_peraglock in write mode, flushes all the
  58. * remaining items from the cache and reallocates the mount point's per-ag
  59. * array, resetting all the counters to zero.
  60. * - The work queue thread resumes and calls the free function for the element
  61. * it started cleaning up earlier. In the process it decrements the
  62. * filestreams counter for an AG that now has no references.
  63. *
  64. * With a shrinkfs feature, the above scenario could panic the system.
  65. *
  66. * All other uses of the following macros should be protected by either the
  67. * m_peraglock held in read mode, or the cache's internal locking exposed by the
  68. * interval between a call to xfs_mru_cache_lookup() and a call to
  69. * xfs_mru_cache_done(). In addition, the m_peraglock must be held in read mode
  70. * when new elements are added to the cache.
  71. *
  72. * Combined, these locking rules ensure that no associations will ever exist in
  73. * the cache that reference per-ag array elements that have since been
  74. * reallocated.
  75. */
  76. STATIC_INLINE int
  77. xfs_filestream_peek_ag(
  78. xfs_mount_t *mp,
  79. xfs_agnumber_t agno)
  80. {
  81. return atomic_read(&mp->m_perag[agno].pagf_fstrms);
  82. }
  83. STATIC_INLINE int
  84. xfs_filestream_get_ag(
  85. xfs_mount_t *mp,
  86. xfs_agnumber_t agno)
  87. {
  88. return atomic_inc_return(&mp->m_perag[agno].pagf_fstrms);
  89. }
  90. STATIC_INLINE int
  91. xfs_filestream_put_ag(
  92. xfs_mount_t *mp,
  93. xfs_agnumber_t agno)
  94. {
  95. return atomic_dec_return(&mp->m_perag[agno].pagf_fstrms);
  96. }
  97. /* allocation selection flags */
  98. typedef enum xfs_fstrm_alloc {
  99. XFS_PICK_USERDATA = 1,
  100. XFS_PICK_LOWSPACE = 2,
  101. } xfs_fstrm_alloc_t;
  102. /* prototypes for filestream.c */
  103. int xfs_filestream_init(void);
  104. void xfs_filestream_uninit(void);
  105. int xfs_filestream_mount(struct xfs_mount *mp);
  106. void xfs_filestream_unmount(struct xfs_mount *mp);
  107. void xfs_filestream_flush(struct xfs_mount *mp);
  108. xfs_agnumber_t xfs_filestream_lookup_ag(struct xfs_inode *ip);
  109. int xfs_filestream_associate(struct xfs_inode *dip, struct xfs_inode *ip);
  110. void xfs_filestream_deassociate(struct xfs_inode *ip);
  111. int xfs_filestream_new_ag(struct xfs_bmalloca *ap, xfs_agnumber_t *agp);
  112. /* filestreams for the inode? */
  113. STATIC_INLINE int
  114. xfs_inode_is_filestream(
  115. struct xfs_inode *ip)
  116. {
  117. return (ip->i_mount->m_flags & XFS_MOUNT_FILESTREAMS) ||
  118. xfs_iflags_test(ip, XFS_IFILESTREAM) ||
  119. (ip->i_d.di_flags & XFS_DIFLAG_FILESTREAM);
  120. }
  121. #endif /* __KERNEL__ */
  122. #endif /* __XFS_FILESTREAM_H__ */