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