Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / xfs / xfs_ialloc.h
blob7f5debe1acb6b4d956d5b6dc3006fe8cb6e2a870
1 /*
2 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
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.
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.
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
18 #ifndef __XFS_IALLOC_H__
19 #define __XFS_IALLOC_H__
21 struct xfs_buf;
22 struct xfs_dinode;
23 struct xfs_mount;
24 struct xfs_trans;
27 * Allocation parameters for inode allocation.
29 #define XFS_IALLOC_INODES(mp) (mp)->m_ialloc_inos
30 #define XFS_IALLOC_BLOCKS(mp) (mp)->m_ialloc_blks
33 * For small block file systems, move inodes in clusters of this size.
34 * When we don't have a lot of memory, however, we go a bit smaller
35 * to reduce the number of AGI and ialloc btree blocks we need to keep
36 * around for xfs_dilocate(). We choose which one to use in
37 * xfs_mount_int().
39 #define XFS_INODE_BIG_CLUSTER_SIZE 8192
40 #define XFS_INODE_SMALL_CLUSTER_SIZE 4096
41 #define XFS_INODE_CLUSTER_SIZE(mp) (mp)->m_inode_cluster_size
44 * Make an inode pointer out of the buffer/offset.
46 #define XFS_MAKE_IPTR(mp,b,o) xfs_make_iptr(mp,b,o)
47 static inline struct xfs_dinode *
48 xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
50 return (xfs_dinode_t *)
51 (xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog));
55 * Find a free (set) bit in the inode bitmask.
57 #define XFS_IALLOC_FIND_FREE(fp) xfs_ialloc_find_free(fp)
58 static inline int xfs_ialloc_find_free(xfs_inofree_t *fp)
60 return xfs_lowbit64(*fp);
64 #ifdef __KERNEL__
66 * Allocate an inode on disk.
67 * Mode is used to tell whether the new inode will need space, and whether
68 * it is a directory.
70 * To work within the constraint of one allocation per transaction,
71 * xfs_dialloc() is designed to be called twice if it has to do an
72 * allocation to make more free inodes. If an inode is
73 * available without an allocation, agbp would be set to the current
74 * agbp and alloc_done set to false.
75 * If an allocation needed to be done, agbp would be set to the
76 * inode header of the allocation group and alloc_done set to true.
77 * The caller should then commit the current transaction and allocate a new
78 * transaction. xfs_dialloc() should then be called again with
79 * the agbp value returned from the previous call.
81 * Once we successfully pick an inode its number is returned and the
82 * on-disk data structures are updated. The inode itself is not read
83 * in, since doing so would break ordering constraints with xfs_reclaim.
85 * *agbp should be set to NULL on the first call, *alloc_done set to FALSE.
87 int /* error */
88 xfs_dialloc(
89 struct xfs_trans *tp, /* transaction pointer */
90 xfs_ino_t parent, /* parent inode (directory) */
91 mode_t mode, /* mode bits for new inode */
92 int okalloc, /* ok to allocate more space */
93 struct xfs_buf **agbp, /* buf for a.g. inode header */
94 boolean_t *alloc_done, /* an allocation was done to replenish
95 the free inodes */
96 xfs_ino_t *inop); /* inode number allocated */
99 * Free disk inode. Carefully avoids touching the incore inode, all
100 * manipulations incore are the caller's responsibility.
101 * The on-disk inode is not changed by this operation, only the
102 * btree (free inode mask) is changed.
104 int /* error */
105 xfs_difree(
106 struct xfs_trans *tp, /* transaction pointer */
107 xfs_ino_t inode, /* inode to be freed */
108 struct xfs_bmap_free *flist, /* extents to free */
109 int *delete, /* set if inode cluster was deleted */
110 xfs_ino_t *first_ino); /* first inode in deleted cluster */
113 * Return the location of the inode in bno/len/off,
114 * for mapping it into a buffer.
117 xfs_dilocate(
118 struct xfs_mount *mp, /* file system mount structure */
119 struct xfs_trans *tp, /* transaction pointer */
120 xfs_ino_t ino, /* inode to locate */
121 xfs_fsblock_t *bno, /* output: block containing inode */
122 int *len, /* output: num blocks in cluster*/
123 int *off, /* output: index in block of inode */
124 uint flags); /* flags for inode btree lookup */
127 * Compute and fill in value of m_in_maxlevels.
129 void
130 xfs_ialloc_compute_maxlevels(
131 struct xfs_mount *mp); /* file system mount structure */
134 * Log specified fields for the ag hdr (inode section)
136 void
137 xfs_ialloc_log_agi(
138 struct xfs_trans *tp, /* transaction pointer */
139 struct xfs_buf *bp, /* allocation group header buffer */
140 int fields); /* bitmask of fields to log */
143 * Read in the allocation group header (inode allocation section)
145 int /* error */
146 xfs_ialloc_read_agi(
147 struct xfs_mount *mp, /* file system mount structure */
148 struct xfs_trans *tp, /* transaction pointer */
149 xfs_agnumber_t agno, /* allocation group number */
150 struct xfs_buf **bpp); /* allocation group hdr buf */
152 #endif /* __KERNEL__ */
154 #endif /* __XFS_IALLOC_H__ */