blob: 7f5debe1acb6b4d956d5b6dc3006fe8cb6e2a870 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_IALLOC_H__
19#define __XFS_IALLOC_H__
20
21struct xfs_buf;
22struct xfs_dinode;
23struct xfs_mount;
24struct xfs_trans;
25
26/*
27 * Allocation parameters for inode allocation.
28 */
Nathan Scotta844f452005-11-02 14:38:42 +110029#define XFS_IALLOC_INODES(mp) (mp)->m_ialloc_inos
30#define XFS_IALLOC_BLOCKS(mp) (mp)->m_ialloc_blks
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/*
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().
38 */
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
42
43/*
44 * Make an inode pointer out of the buffer/offset.
45 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define XFS_MAKE_IPTR(mp,b,o) xfs_make_iptr(mp,b,o)
Nathan Scotta844f452005-11-02 14:38:42 +110047static inline struct xfs_dinode *
48xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
49{
50 return (xfs_dinode_t *)
51 (xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog));
52}
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/*
55 * Find a free (set) bit in the inode bitmask.
56 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define XFS_IALLOC_FIND_FREE(fp) xfs_ialloc_find_free(fp)
Nathan Scotta844f452005-11-02 14:38:42 +110058static inline int xfs_ialloc_find_free(xfs_inofree_t *fp)
59{
60 return xfs_lowbit64(*fp);
61}
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63
64#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/*
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.
69 *
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.
80 *
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.
84 *
85 * *agbp should be set to NULL on the first call, *alloc_done set to FALSE.
86 */
87int /* error */
88xfs_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 */
97
98/*
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.
103 */
104int /* error */
105xfs_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 */
111
112/*
113 * Return the location of the inode in bno/len/off,
114 * for mapping it into a buffer.
115 */
116int
117xfs_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 */
125
126/*
127 * Compute and fill in value of m_in_maxlevels.
128 */
129void
130xfs_ialloc_compute_maxlevels(
131 struct xfs_mount *mp); /* file system mount structure */
132
133/*
134 * Log specified fields for the ag hdr (inode section)
135 */
136void
137xfs_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 */
141
142/*
143 * Read in the allocation group header (inode allocation section)
144 */
145int /* error */
146xfs_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 */
151
152#endif /* __KERNEL__ */
153
154#endif /* __XFS_IALLOC_H__ */