空闲 inode 号查找:要分配新的 inode 盘区,先要找到 32 个相邻的、未分配给相应 inode 盘区的 inode
。当所有已分配的 inode 都在使用,或当 JFS 需要给分配组分配 inode 但以前从未分配过 inode 时,或当一个分配组中没有空闲
inode 时,需要分配新的 inode 盘区。
注意动态 inode 分配的一种微妙效应:相邻 inode
号在磁盘上未必相邻:inode N+32 可以和 inode N 相隔任意远。然而,相隔很远的 inode
号在磁盘上可以是紧邻的;所以,inode N+K 和 inode N 紧邻在理论上是可能的(即使 K>1)
inode 分配映射表
inode 分配映射表解决正向查找问题。聚集和每个文件集都有一个 inode
分配映射表,该表是一个 IAG(inode 分配组)的数组。IAG 是 inode 分配映射表的数据。对于聚集,inode 分配映射表映射的
inode 也称为聚集 inode 表。对于文件集,inode 分配映射表映射的 inode 也称为文件 inode 表。
每个 IAG 大小为 4K,描述磁盘上 128 个物理 inode 盘区。由于每个 inode 盘区包含 32 个 inode
,所以每个 IAG 描述 4096 个 inode 。IAG 可以位于聚集的任意位置。IAG 的所有 inode 盘区位于一个分配组,由此
IAG 和 AG 绑定在一起直至释放所有的 inode 盘区。任意 AG 可以分配空间给一个 inode 盘区,然后该 IAG 就与那个 AG
绑定。IAG 由 struct iag_t 定义(见 jfs_imap.h)。
/*
* inode allocation group page (per 4096 inodes of an AG)
*/
typedef struct {
int64 agstart; /* 8: starting block of ag */
int32 iagnum; /* 4: inode allocation group number */
int32 inofreefwd; /* 4: ag inode free list forward */
int32 inofreeback; /* 4: ag inode free list back */
int32 extfreefwd; /* 4: ag inode extent free list forward */
int32 extfreeback; /* 4: ag inode extent free list back */
int32 iagfree; /* 4: iag free list */
/* summary map: 1 bit per inode extent */
int32 inosmap[SMAPSZ];/* 16: sum map of mapwords w/ free inodes;
* note: this indicates free and backed
* inodes, if the extent is not backed the
* value will be 1. if the extent is
* backed but all inodes are being used the
* value will be 1. if the extent is
* backed but at least one of the inodes is
* free the value will be 0.
*/
int32 extsmap[SMAPSZ];/* 16: sum map of mapwords w/ free extents */
int32 nfreeinos; /* 4: number of free inodes */
int32 nfreeexts; /* 4: number of free extents */
/* (72) */
uint8 pad[1976]; /* 1976: pad to 2048 bytes */
/* allocation bit map: 1 bit per inode (0 - free, 1 - allocated) */
uint32 wmap[EXTSPERIAG]; /* 512: working allocation map */
uint32 pmap[EXTSPERIAG]; /* 512: persistent allocation map */
pxd_t inoext[EXTSPERIAG]; /* 1024: inode extent addresses */
} iag_t; /* (4096) */
inode 分配映射表最前面 4k 大小的页是控制页。该页包含 inode 分配映射表的摘要信息。 dinomap_t 结构的定义见 jfs_imap.h。
逻辑上,inode 分配映射表是动态可扩展的 IAG 结构的数组:
struct iag inode_allocation_map [ 1.. N ];