Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | #ifndef __XFS_IALLOC_H__ |
| 19 | #define __XFS_IALLOC_H__ |
| 20 | |
| 21 | struct xfs_buf; |
| 22 | struct xfs_dinode; |
| 23 | struct xfs_mount; |
| 24 | struct xfs_trans; |
| 25 | |
| 26 | /* |
| 27 | * Allocation parameters for inode allocation. |
| 28 | */ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 29 | #define XFS_IALLOC_INODES(mp) (mp)->m_ialloc_inos |
| 30 | #define XFS_IALLOC_BLOCKS(mp) (mp)->m_ialloc_blks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #define XFS_MAKE_IPTR(mp,b,o) xfs_make_iptr(mp,b,o) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 47 | static inline struct xfs_dinode * |
| 48 | xfs_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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Find a free (set) bit in the inode bitmask. |
| 56 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #define XFS_IALLOC_FIND_FREE(fp) xfs_ialloc_find_free(fp) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 58 | static inline int xfs_ialloc_find_free(xfs_inofree_t *fp) |
| 59 | { |
| 60 | return xfs_lowbit64(*fp); |
| 61 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | |
| 64 | #ifdef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* |
| 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 | */ |
| 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 */ |
| 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 | */ |
| 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 */ |
| 111 | |
| 112 | /* |
| 113 | * Return the location of the inode in bno/len/off, |
| 114 | * for mapping it into a buffer. |
| 115 | */ |
| 116 | int |
| 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 */ |
| 125 | |
| 126 | /* |
| 127 | * Compute and fill in value of m_in_maxlevels. |
| 128 | */ |
| 129 | void |
| 130 | xfs_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 | */ |
| 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 */ |
| 141 | |
| 142 | /* |
| 143 | * Read in the allocation group header (inode allocation section) |
| 144 | */ |
| 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 */ |
| 151 | |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 152 | /* |
| 153 | * Read in the allocation group header to initialise the per-ag data |
| 154 | * in the mount structure |
| 155 | */ |
| 156 | int |
| 157 | xfs_ialloc_pagi_init( |
| 158 | struct xfs_mount *mp, /* file system mount structure */ |
| 159 | struct xfs_trans *tp, /* transaction pointer */ |
| 160 | xfs_agnumber_t agno); /* allocation group number */ |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | #endif /* __KERNEL__ */ |
| 163 | |
| 164 | #endif /* __XFS_IALLOC_H__ */ |