162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) International Business Machines Corp., 2000-2002 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci#ifndef _H_JFS_IMAP 662306a36Sopenharmony_ci#define _H_JFS_IMAP 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include "jfs_txnmgr.h" 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci/* 1162306a36Sopenharmony_ci * jfs_imap.h: disk inode manager 1262306a36Sopenharmony_ci */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define EXTSPERIAG 128 /* number of disk inode extent per iag */ 1562306a36Sopenharmony_ci#define IMAPBLKNO 0 /* lblkno of dinomap within inode map */ 1662306a36Sopenharmony_ci#define SMAPSZ 4 /* number of words per summary map */ 1762306a36Sopenharmony_ci#define EXTSPERSUM 32 /* number of extents per summary map entry */ 1862306a36Sopenharmony_ci#define L2EXTSPERSUM 5 /* l2 number of extents per summary map */ 1962306a36Sopenharmony_ci#define PGSPERIEXT 4 /* number of 4K pages per dinode extent */ 2062306a36Sopenharmony_ci#define MAXIAGS ((1<<20)-1) /* maximum number of iags */ 2162306a36Sopenharmony_ci#define MAXAG 128 /* maximum number of allocation groups */ 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#define AMAPSIZE 512 /* bytes in the IAG allocation maps */ 2462306a36Sopenharmony_ci#define SMAPSIZE 16 /* bytes in the IAG summary maps */ 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* convert inode number to iag number */ 2762306a36Sopenharmony_ci#define INOTOIAG(ino) ((ino) >> L2INOSPERIAG) 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* convert iag number to logical block number of the iag page */ 3062306a36Sopenharmony_ci#define IAGTOLBLK(iagno,l2nbperpg) (((iagno) + 1) << (l2nbperpg)) 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* get the starting block number of the 4K page of an inode extent 3362306a36Sopenharmony_ci * that contains ino. 3462306a36Sopenharmony_ci */ 3562306a36Sopenharmony_ci#define INOPBLK(pxd,ino,l2nbperpg) (addressPXD((pxd)) + \ 3662306a36Sopenharmony_ci ((((ino) & (INOSPEREXT-1)) >> L2INOSPERPAGE) << (l2nbperpg))) 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* 3962306a36Sopenharmony_ci * inode allocation map: 4062306a36Sopenharmony_ci * 4162306a36Sopenharmony_ci * inode allocation map consists of 4262306a36Sopenharmony_ci * . the inode map control page and 4362306a36Sopenharmony_ci * . inode allocation group pages (per 4096 inodes) 4462306a36Sopenharmony_ci * which are addressed by standard JFS xtree. 4562306a36Sopenharmony_ci */ 4662306a36Sopenharmony_ci/* 4762306a36Sopenharmony_ci * inode allocation group page (per 4096 inodes of an AG) 4862306a36Sopenharmony_ci */ 4962306a36Sopenharmony_cistruct iag { 5062306a36Sopenharmony_ci __le64 agstart; /* 8: starting block of ag */ 5162306a36Sopenharmony_ci __le32 iagnum; /* 4: inode allocation group number */ 5262306a36Sopenharmony_ci __le32 inofreefwd; /* 4: ag inode free list forward */ 5362306a36Sopenharmony_ci __le32 inofreeback; /* 4: ag inode free list back */ 5462306a36Sopenharmony_ci __le32 extfreefwd; /* 4: ag inode extent free list forward */ 5562306a36Sopenharmony_ci __le32 extfreeback; /* 4: ag inode extent free list back */ 5662306a36Sopenharmony_ci __le32 iagfree; /* 4: iag free list */ 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci /* summary map: 1 bit per inode extent */ 5962306a36Sopenharmony_ci __le32 inosmap[SMAPSZ]; /* 16: sum map of mapwords w/ free inodes; 6062306a36Sopenharmony_ci * note: this indicates free and backed 6162306a36Sopenharmony_ci * inodes, if the extent is not backed the 6262306a36Sopenharmony_ci * value will be 1. if the extent is 6362306a36Sopenharmony_ci * backed but all inodes are being used the 6462306a36Sopenharmony_ci * value will be 1. if the extent is 6562306a36Sopenharmony_ci * backed but at least one of the inodes is 6662306a36Sopenharmony_ci * free the value will be 0. 6762306a36Sopenharmony_ci */ 6862306a36Sopenharmony_ci __le32 extsmap[SMAPSZ]; /* 16: sum map of mapwords w/ free extents */ 6962306a36Sopenharmony_ci __le32 nfreeinos; /* 4: number of free inodes */ 7062306a36Sopenharmony_ci __le32 nfreeexts; /* 4: number of free extents */ 7162306a36Sopenharmony_ci /* (72) */ 7262306a36Sopenharmony_ci u8 pad[1976]; /* 1976: pad to 2048 bytes */ 7362306a36Sopenharmony_ci /* allocation bit map: 1 bit per inode (0 - free, 1 - allocated) */ 7462306a36Sopenharmony_ci __le32 wmap[EXTSPERIAG]; /* 512: working allocation map */ 7562306a36Sopenharmony_ci __le32 pmap[EXTSPERIAG]; /* 512: persistent allocation map */ 7662306a36Sopenharmony_ci pxd_t inoext[EXTSPERIAG]; /* 1024: inode extent addresses */ 7762306a36Sopenharmony_ci}; /* (4096) */ 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci/* 8062306a36Sopenharmony_ci * per AG control information (in inode map control page) 8162306a36Sopenharmony_ci */ 8262306a36Sopenharmony_cistruct iagctl_disk { 8362306a36Sopenharmony_ci __le32 inofree; /* 4: free inode list anchor */ 8462306a36Sopenharmony_ci __le32 extfree; /* 4: free extent list anchor */ 8562306a36Sopenharmony_ci __le32 numinos; /* 4: number of backed inodes */ 8662306a36Sopenharmony_ci __le32 numfree; /* 4: number of free inodes */ 8762306a36Sopenharmony_ci}; /* (16) */ 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_cistruct iagctl { 9062306a36Sopenharmony_ci int inofree; /* free inode list anchor */ 9162306a36Sopenharmony_ci int extfree; /* free extent list anchor */ 9262306a36Sopenharmony_ci int numinos; /* number of backed inodes */ 9362306a36Sopenharmony_ci int numfree; /* number of free inodes */ 9462306a36Sopenharmony_ci}; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci/* 9762306a36Sopenharmony_ci * per fileset/aggregate inode map control page 9862306a36Sopenharmony_ci */ 9962306a36Sopenharmony_cistruct dinomap_disk { 10062306a36Sopenharmony_ci __le32 in_freeiag; /* 4: free iag list anchor */ 10162306a36Sopenharmony_ci __le32 in_nextiag; /* 4: next free iag number */ 10262306a36Sopenharmony_ci __le32 in_numinos; /* 4: num of backed inodes */ 10362306a36Sopenharmony_ci __le32 in_numfree; /* 4: num of free backed inodes */ 10462306a36Sopenharmony_ci __le32 in_nbperiext; /* 4: num of blocks per inode extent */ 10562306a36Sopenharmony_ci __le32 in_l2nbperiext; /* 4: l2 of in_nbperiext */ 10662306a36Sopenharmony_ci __le32 in_diskblock; /* 4: for standalone test driver */ 10762306a36Sopenharmony_ci __le32 in_maxag; /* 4: for standalone test driver */ 10862306a36Sopenharmony_ci u8 pad[2016]; /* 2016: pad to 2048 */ 10962306a36Sopenharmony_ci struct iagctl_disk in_agctl[MAXAG]; /* 2048: AG control information */ 11062306a36Sopenharmony_ci}; /* (4096) */ 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_cistruct dinomap { 11362306a36Sopenharmony_ci int in_freeiag; /* free iag list anchor */ 11462306a36Sopenharmony_ci int in_nextiag; /* next free iag number */ 11562306a36Sopenharmony_ci int in_numinos; /* num of backed inodes */ 11662306a36Sopenharmony_ci int in_numfree; /* num of free backed inodes */ 11762306a36Sopenharmony_ci int in_nbperiext; /* num of blocks per inode extent */ 11862306a36Sopenharmony_ci int in_l2nbperiext; /* l2 of in_nbperiext */ 11962306a36Sopenharmony_ci int in_diskblock; /* for standalone test driver */ 12062306a36Sopenharmony_ci int in_maxag; /* for standalone test driver */ 12162306a36Sopenharmony_ci struct iagctl in_agctl[MAXAG]; /* AG control information */ 12262306a36Sopenharmony_ci}; 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci/* 12562306a36Sopenharmony_ci * In-core inode map control page 12662306a36Sopenharmony_ci */ 12762306a36Sopenharmony_cistruct inomap { 12862306a36Sopenharmony_ci struct dinomap im_imap; /* 4096: inode allocation control */ 12962306a36Sopenharmony_ci struct inode *im_ipimap; /* 4: ptr to inode for imap */ 13062306a36Sopenharmony_ci struct mutex im_freelock; /* 4: iag free list lock */ 13162306a36Sopenharmony_ci struct mutex im_aglock[MAXAG]; /* 512: per AG locks */ 13262306a36Sopenharmony_ci u32 *im_DBGdimap; 13362306a36Sopenharmony_ci atomic_t im_numinos; /* num of backed inodes */ 13462306a36Sopenharmony_ci atomic_t im_numfree; /* num of free backed inodes */ 13562306a36Sopenharmony_ci}; 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci#define im_freeiag im_imap.in_freeiag 13862306a36Sopenharmony_ci#define im_nextiag im_imap.in_nextiag 13962306a36Sopenharmony_ci#define im_agctl im_imap.in_agctl 14062306a36Sopenharmony_ci#define im_nbperiext im_imap.in_nbperiext 14162306a36Sopenharmony_ci#define im_l2nbperiext im_imap.in_l2nbperiext 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci/* for standalone testdriver 14462306a36Sopenharmony_ci */ 14562306a36Sopenharmony_ci#define im_diskblock im_imap.in_diskblock 14662306a36Sopenharmony_ci#define im_maxag im_imap.in_maxag 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ciextern int diFree(struct inode *); 14962306a36Sopenharmony_ciextern int diAlloc(struct inode *, bool, struct inode *); 15062306a36Sopenharmony_ciextern int diSync(struct inode *); 15162306a36Sopenharmony_ci/* external references */ 15262306a36Sopenharmony_ciextern int diUpdatePMap(struct inode *ipimap, unsigned long inum, 15362306a36Sopenharmony_ci bool is_free, struct tblock * tblk); 15462306a36Sopenharmony_ciextern int diExtendFS(struct inode *ipimap, struct inode *ipbmap); 15562306a36Sopenharmony_ciextern int diMount(struct inode *); 15662306a36Sopenharmony_ciextern int diUnmount(struct inode *, int); 15762306a36Sopenharmony_ciextern int diRead(struct inode *); 15862306a36Sopenharmony_ciextern struct inode *diReadSpecial(struct super_block *, ino_t, int); 15962306a36Sopenharmony_ciextern void diWriteSpecial(struct inode *, int); 16062306a36Sopenharmony_ciextern void diFreeSpecial(struct inode *); 16162306a36Sopenharmony_ciextern int diWrite(tid_t tid, struct inode *); 16262306a36Sopenharmony_ci#endif /* _H_JFS_IMAP */ 163