xfs_ialloc.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #ifndef __XFS_IALLOC_H__
  33. #define __XFS_IALLOC_H__
  34. struct xfs_buf;
  35. struct xfs_dinode;
  36. struct xfs_mount;
  37. struct xfs_trans;
  38. /*
  39. * Allocation parameters for inode allocation.
  40. */
  41. #define XFS_IALLOC_INODES(mp) (mp)->m_ialloc_inos
  42. #define XFS_IALLOC_BLOCKS(mp) (mp)->m_ialloc_blks
  43. /*
  44. * For small block file systems, move inodes in clusters of this size.
  45. * When we don't have a lot of memory, however, we go a bit smaller
  46. * to reduce the number of AGI and ialloc btree blocks we need to keep
  47. * around for xfs_dilocate(). We choose which one to use in
  48. * xfs_mount_int().
  49. */
  50. #define XFS_INODE_BIG_CLUSTER_SIZE 8192
  51. #define XFS_INODE_SMALL_CLUSTER_SIZE 4096
  52. #define XFS_INODE_CLUSTER_SIZE(mp) (mp)->m_inode_cluster_size
  53. /*
  54. * Make an inode pointer out of the buffer/offset.
  55. */
  56. #define XFS_MAKE_IPTR(mp,b,o) xfs_make_iptr(mp,b,o)
  57. static inline struct xfs_dinode *
  58. xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
  59. {
  60. return (xfs_dinode_t *)
  61. (xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog));
  62. }
  63. /*
  64. * Find a free (set) bit in the inode bitmask.
  65. */
  66. #define XFS_IALLOC_FIND_FREE(fp) xfs_ialloc_find_free(fp)
  67. static inline int xfs_ialloc_find_free(xfs_inofree_t *fp)
  68. {
  69. return xfs_lowbit64(*fp);
  70. }
  71. #ifdef __KERNEL__
  72. /*
  73. * Allocate an inode on disk.
  74. * Mode is used to tell whether the new inode will need space, and whether
  75. * it is a directory.
  76. *
  77. * To work within the constraint of one allocation per transaction,
  78. * xfs_dialloc() is designed to be called twice if it has to do an
  79. * allocation to make more free inodes. If an inode is
  80. * available without an allocation, agbp would be set to the current
  81. * agbp and alloc_done set to false.
  82. * If an allocation needed to be done, agbp would be set to the
  83. * inode header of the allocation group and alloc_done set to true.
  84. * The caller should then commit the current transaction and allocate a new
  85. * transaction. xfs_dialloc() should then be called again with
  86. * the agbp value returned from the previous call.
  87. *
  88. * Once we successfully pick an inode its number is returned and the
  89. * on-disk data structures are updated. The inode itself is not read
  90. * in, since doing so would break ordering constraints with xfs_reclaim.
  91. *
  92. * *agbp should be set to NULL on the first call, *alloc_done set to FALSE.
  93. */
  94. int /* error */
  95. xfs_dialloc(
  96. struct xfs_trans *tp, /* transaction pointer */
  97. xfs_ino_t parent, /* parent inode (directory) */
  98. mode_t mode, /* mode bits for new inode */
  99. int okalloc, /* ok to allocate more space */
  100. struct xfs_buf **agbp, /* buf for a.g. inode header */
  101. boolean_t *alloc_done, /* an allocation was done to replenish
  102. the free inodes */
  103. xfs_ino_t *inop); /* inode number allocated */
  104. /*
  105. * Free disk inode. Carefully avoids touching the incore inode, all
  106. * manipulations incore are the caller's responsibility.
  107. * The on-disk inode is not changed by this operation, only the
  108. * btree (free inode mask) is changed.
  109. */
  110. int /* error */
  111. xfs_difree(
  112. struct xfs_trans *tp, /* transaction pointer */
  113. xfs_ino_t inode, /* inode to be freed */
  114. struct xfs_bmap_free *flist, /* extents to free */
  115. int *delete, /* set if inode cluster was deleted */
  116. xfs_ino_t *first_ino); /* first inode in deleted cluster */
  117. /*
  118. * Return the location of the inode in bno/len/off,
  119. * for mapping it into a buffer.
  120. */
  121. int
  122. xfs_dilocate(
  123. struct xfs_mount *mp, /* file system mount structure */
  124. struct xfs_trans *tp, /* transaction pointer */
  125. xfs_ino_t ino, /* inode to locate */
  126. xfs_fsblock_t *bno, /* output: block containing inode */
  127. int *len, /* output: num blocks in cluster*/
  128. int *off, /* output: index in block of inode */
  129. uint flags); /* flags for inode btree lookup */
  130. /*
  131. * Compute and fill in value of m_in_maxlevels.
  132. */
  133. void
  134. xfs_ialloc_compute_maxlevels(
  135. struct xfs_mount *mp); /* file system mount structure */
  136. /*
  137. * Log specified fields for the ag hdr (inode section)
  138. */
  139. void
  140. xfs_ialloc_log_agi(
  141. struct xfs_trans *tp, /* transaction pointer */
  142. struct xfs_buf *bp, /* allocation group header buffer */
  143. int fields); /* bitmask of fields to log */
  144. /*
  145. * Read in the allocation group header (inode allocation section)
  146. */
  147. int /* error */
  148. xfs_ialloc_read_agi(
  149. struct xfs_mount *mp, /* file system mount structure */
  150. struct xfs_trans *tp, /* transaction pointer */
  151. xfs_agnumber_t agno, /* allocation group number */
  152. struct xfs_buf **bpp); /* allocation group hdr buf */
  153. #endif /* __KERNEL__ */
  154. #endif /* __XFS_IALLOC_H__ */