xref: /linux/fs/xfs/libxfs/xfs_ialloc.h (revision b7019ac550eb3916f34d79db583e9b7ea2524afa)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef __XFS_IALLOC_H__
7 #define	__XFS_IALLOC_H__
8 
9 struct xfs_buf;
10 struct xfs_dinode;
11 struct xfs_imap;
12 struct xfs_mount;
13 struct xfs_trans;
14 struct xfs_btree_cur;
15 
16 /* Move inodes in clusters of this size */
17 #define	XFS_INODE_BIG_CLUSTER_SIZE	8192
18 
19 struct xfs_icluster {
20 	bool		deleted;	/* record is deleted */
21 	xfs_ino_t	first_ino;	/* first inode number */
22 	uint64_t	alloc;		/* inode phys. allocation bitmap for
23 					 * sparse chunks */
24 };
25 
26 /* Calculate and return the number of filesystem blocks per inode cluster */
27 static inline int
28 xfs_icluster_size_fsb(
29 	struct xfs_mount	*mp)
30 {
31 	if (mp->m_sb.sb_blocksize >= mp->m_inode_cluster_size)
32 		return 1;
33 	return mp->m_inode_cluster_size >> mp->m_sb.sb_blocklog;
34 }
35 
36 /*
37  * Make an inode pointer out of the buffer/offset.
38  */
39 static inline struct xfs_dinode *
40 xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
41 {
42 	return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog);
43 }
44 
45 /*
46  * Allocate an inode on disk.
47  * Mode is used to tell whether the new inode will need space, and whether
48  * it is a directory.
49  *
50  * To work within the constraint of one allocation per transaction,
51  * xfs_dialloc() is designed to be called twice if it has to do an
52  * allocation to make more free inodes.  If an inode is
53  * available without an allocation, agbp would be set to the current
54  * agbp and alloc_done set to false.
55  * If an allocation needed to be done, agbp would be set to the
56  * inode header of the allocation group and alloc_done set to true.
57  * The caller should then commit the current transaction and allocate a new
58  * transaction.  xfs_dialloc() should then be called again with
59  * the agbp value returned from the previous call.
60  *
61  * Once we successfully pick an inode its number is returned and the
62  * on-disk data structures are updated.  The inode itself is not read
63  * in, since doing so would break ordering constraints with xfs_reclaim.
64  *
65  * *agbp should be set to NULL on the first call, *alloc_done set to FALSE.
66  */
67 int					/* error */
68 xfs_dialloc(
69 	struct xfs_trans *tp,		/* transaction pointer */
70 	xfs_ino_t	parent,		/* parent inode (directory) */
71 	umode_t		mode,		/* mode bits for new inode */
72 	struct xfs_buf	**agbp,		/* buf for a.g. inode header */
73 	xfs_ino_t	*inop);		/* inode number allocated */
74 
75 /*
76  * Free disk inode.  Carefully avoids touching the incore inode, all
77  * manipulations incore are the caller's responsibility.
78  * The on-disk inode is not changed by this operation, only the
79  * btree (free inode mask) is changed.
80  */
81 int					/* error */
82 xfs_difree(
83 	struct xfs_trans *tp,		/* transaction pointer */
84 	xfs_ino_t	inode,		/* inode to be freed */
85 	struct xfs_icluster *ifree);	/* cluster info if deleted */
86 
87 /*
88  * Return the location of the inode in imap, for mapping it into a buffer.
89  */
90 int
91 xfs_imap(
92 	struct xfs_mount *mp,		/* file system mount structure */
93 	struct xfs_trans *tp,		/* transaction pointer */
94 	xfs_ino_t	ino,		/* inode to locate */
95 	struct xfs_imap	*imap,		/* location map structure */
96 	uint		flags);		/* flags for inode btree lookup */
97 
98 /*
99  * Compute and fill in value of m_in_maxlevels.
100  */
101 void
102 xfs_ialloc_compute_maxlevels(
103 	struct xfs_mount *mp);		/* file system mount structure */
104 
105 /*
106  * Log specified fields for the ag hdr (inode section)
107  */
108 void
109 xfs_ialloc_log_agi(
110 	struct xfs_trans *tp,		/* transaction pointer */
111 	struct xfs_buf	*bp,		/* allocation group header buffer */
112 	int		fields);	/* bitmask of fields to log */
113 
114 /*
115  * Read in the allocation group header (inode allocation section)
116  */
117 int					/* error */
118 xfs_ialloc_read_agi(
119 	struct xfs_mount *mp,		/* file system mount structure */
120 	struct xfs_trans *tp,		/* transaction pointer */
121 	xfs_agnumber_t	agno,		/* allocation group number */
122 	struct xfs_buf	**bpp);		/* allocation group hdr buf */
123 
124 /*
125  * Read in the allocation group header to initialise the per-ag data
126  * in the mount structure
127  */
128 int
129 xfs_ialloc_pagi_init(
130 	struct xfs_mount *mp,		/* file system mount structure */
131 	struct xfs_trans *tp,		/* transaction pointer */
132         xfs_agnumber_t  agno);		/* allocation group number */
133 
134 /*
135  * Lookup a record by ino in the btree given by cur.
136  */
137 int xfs_inobt_lookup(struct xfs_btree_cur *cur, xfs_agino_t ino,
138 		xfs_lookup_t dir, int *stat);
139 
140 /*
141  * Get the data from the pointed-to record.
142  */
143 int xfs_inobt_get_rec(struct xfs_btree_cur *cur,
144 		xfs_inobt_rec_incore_t *rec, int *stat);
145 
146 /*
147  * Inode chunk initialisation routine
148  */
149 int xfs_ialloc_inode_init(struct xfs_mount *mp, struct xfs_trans *tp,
150 			  struct list_head *buffer_list, int icount,
151 			  xfs_agnumber_t agno, xfs_agblock_t agbno,
152 			  xfs_agblock_t length, unsigned int gen);
153 
154 int xfs_read_agi(struct xfs_mount *mp, struct xfs_trans *tp,
155 		xfs_agnumber_t agno, struct xfs_buf **bpp);
156 
157 union xfs_btree_rec;
158 void xfs_inobt_btrec_to_irec(struct xfs_mount *mp, union xfs_btree_rec *rec,
159 		struct xfs_inobt_rec_incore *irec);
160 int xfs_ialloc_has_inodes_at_extent(struct xfs_btree_cur *cur,
161 		xfs_agblock_t bno, xfs_extlen_t len, bool *exists);
162 int xfs_ialloc_has_inode_record(struct xfs_btree_cur *cur, xfs_agino_t low,
163 		xfs_agino_t high, bool *exists);
164 int xfs_ialloc_count_inodes(struct xfs_btree_cur *cur, xfs_agino_t *count,
165 		xfs_agino_t *freecount);
166 int xfs_inobt_insert_rec(struct xfs_btree_cur *cur, uint16_t holemask,
167 		uint8_t count, int32_t freecount, xfs_inofree_t free,
168 		int *stat);
169 
170 int xfs_ialloc_cluster_alignment(struct xfs_mount *mp);
171 
172 #endif	/* __XFS_IALLOC_H__ */
173