Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *   Copyright (C) International Business Machines Corp., 2000-2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *	jfs_imap.c: inode allocation map manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Serialization:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *   Each AG has a simple lock which is used to control the serialization of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *	the AG level lists.  This lock should be taken first whenever an AG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *	level list will be modified or accessed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *   Each IAG is locked by obtaining the buffer for the IAG page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *   There is also a inode lock for the inode map inode.  A read lock needs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *	be taken whenever an IAG is read from the map or the global level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *	information is read.  A write lock needs to be taken whenever the global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *	level information is modified or an atomic operation needs to be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *	If more than one IAG is read at one time, the read lock may not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *	be given up until all of the IAG's are read.  Otherwise, a deadlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *	may occur when trying to obtain the read lock while another thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *	holding the read lock is waiting on the IAG already being held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *   The control page of the inode map is read into memory by diMount().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *	Thereafter it should only be modified in memory and then it will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *	written out when the filesystem is unmounted by diUnmount().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include "jfs_incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include "jfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include "jfs_filsys.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include "jfs_dinode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include "jfs_dmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include "jfs_imap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include "jfs_metapage.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include "jfs_superblock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include "jfs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  * imap locks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) /* iag free list lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #define IAGFREE_LOCK_INIT(imap)		mutex_init(&imap->im_freelock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define IAGFREE_LOCK(imap)		mutex_lock(&imap->im_freelock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define IAGFREE_UNLOCK(imap)		mutex_unlock(&imap->im_freelock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) /* per ag iag list locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define AG_LOCK_INIT(imap,index)	mutex_init(&(imap->im_aglock[index]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #define AG_LOCK(imap,agno)		mutex_lock(&imap->im_aglock[agno])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define AG_UNLOCK(imap,agno)		mutex_unlock(&imap->im_aglock[agno])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)  * forward references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) static int diAllocAG(struct inomap *, int, bool, struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static int diAllocAny(struct inomap *, int, bool, struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) static int diAllocBit(struct inomap *, struct iag *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) static int diAllocExt(struct inomap *, int, struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static int diAllocIno(struct inomap *, int, struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) static int diFindFree(u32, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) static int diNewExt(struct inomap *, struct iag *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) static int diNewIAG(struct inomap *, int *, int, struct metapage **);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) static void duplicateIXtree(struct super_block *, s64, int, s64 *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) static int diIAGRead(struct inomap * imap, int, struct metapage **);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static int copy_from_dinode(struct dinode *, struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) static void copy_to_dinode(struct dinode *, struct inode *);
^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)  * NAME:	diMount()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  * FUNCTION:	initialize the incore inode map control structures for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  *		a fileset or aggregate init time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  *		the inode map's control structure (dinomap) is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  *		brought in from disk and placed in virtual memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87)  *	ipimap	- pointer to inode map inode for the aggregate or fileset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  *	0	- success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  *	-ENOMEM	- insufficient free virtual memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) int diMount(struct inode *ipimap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	struct inomap *imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	struct dinomap_disk *dinom_le;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	 * allocate/initialize the in-memory inode map control structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	/* allocate the in-memory inode map control structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	imap = kmalloc(sizeof(struct inomap), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	if (imap == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		jfs_err("diMount: kmalloc returned NULL!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	/* read the on-disk inode map control structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	mp = read_metapage(ipimap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 			   IMAPBLKNO << JFS_SBI(ipimap->i_sb)->l2nbperpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 			   PSIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	if (mp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 		kfree(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	/* copy the on-disk version to the in-memory version. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	dinom_le = (struct dinomap_disk *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	imap->im_freeiag = le32_to_cpu(dinom_le->in_freeiag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	imap->im_nextiag = le32_to_cpu(dinom_le->in_nextiag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	atomic_set(&imap->im_numinos, le32_to_cpu(dinom_le->in_numinos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	atomic_set(&imap->im_numfree, le32_to_cpu(dinom_le->in_numfree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	imap->im_nbperiext = le32_to_cpu(dinom_le->in_nbperiext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	imap->im_l2nbperiext = le32_to_cpu(dinom_le->in_l2nbperiext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	for (index = 0; index < MAXAG; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 		imap->im_agctl[index].inofree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		    le32_to_cpu(dinom_le->in_agctl[index].inofree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 		imap->im_agctl[index].extfree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 		    le32_to_cpu(dinom_le->in_agctl[index].extfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 		imap->im_agctl[index].numinos =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		    le32_to_cpu(dinom_le->in_agctl[index].numinos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		imap->im_agctl[index].numfree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 		    le32_to_cpu(dinom_le->in_agctl[index].numfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	/* release the buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	 * allocate/initialize inode allocation map locks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	/* allocate and init iag free list lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	IAGFREE_LOCK_INIT(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	/* allocate and init ag list locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	for (index = 0; index < MAXAG; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		AG_LOCK_INIT(imap, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	/* bind the inode map inode and inode map control structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	 * to each other.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	imap->im_ipimap = ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	JFS_IP(ipimap)->i_imap = imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165)  * NAME:	diUnmount()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)  * FUNCTION:	write to disk the incore inode map control structures for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)  *		a fileset or aggregate at unmount time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  *	ipimap	- pointer to inode map inode for the aggregate or fileset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174)  *	0	- success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175)  *	-ENOMEM	- insufficient free virtual memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) int diUnmount(struct inode *ipimap, int mounterror)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	struct inomap *imap = JFS_IP(ipimap)->i_imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	 * update the on-disk inode map control structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	if (!(mounterror || isReadOnly(ipimap)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		diSync(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	 * Invalidate the page cache buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	truncate_inode_pages(ipimap->i_mapping, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	 * free in-memory control structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	kfree(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204)  *	diSync()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) int diSync(struct inode *ipimap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	struct dinomap_disk *dinom_le;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	struct inomap *imp = JFS_IP(ipimap)->i_imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	 * write imap global conrol page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	/* read the on-disk inode map control structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	mp = get_metapage(ipimap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 			  IMAPBLKNO << JFS_SBI(ipimap->i_sb)->l2nbperpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 			  PSIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	if (mp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		jfs_err("diSync: get_metapage failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	/* copy the in-memory version to the on-disk version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	dinom_le = (struct dinomap_disk *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	dinom_le->in_freeiag = cpu_to_le32(imp->im_freeiag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	dinom_le->in_nextiag = cpu_to_le32(imp->im_nextiag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	dinom_le->in_numinos = cpu_to_le32(atomic_read(&imp->im_numinos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	dinom_le->in_numfree = cpu_to_le32(atomic_read(&imp->im_numfree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	dinom_le->in_nbperiext = cpu_to_le32(imp->im_nbperiext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	dinom_le->in_l2nbperiext = cpu_to_le32(imp->im_l2nbperiext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	for (index = 0; index < MAXAG; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		dinom_le->in_agctl[index].inofree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		    cpu_to_le32(imp->im_agctl[index].inofree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		dinom_le->in_agctl[index].extfree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		    cpu_to_le32(imp->im_agctl[index].extfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		dinom_le->in_agctl[index].numinos =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		    cpu_to_le32(imp->im_agctl[index].numinos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		dinom_le->in_agctl[index].numfree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		    cpu_to_le32(imp->im_agctl[index].numfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	/* write out the control structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	write_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	 * write out dirty pages of imap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	filemap_write_and_wait(ipimap->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	diWriteSpecial(ipimap, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259)  * NAME:	diRead()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261)  * FUNCTION:	initialize an incore inode from disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263)  *		on entry, the specifed incore inode should itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264)  *		specify the disk inode number corresponding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265)  *		incore inode (i.e. i_number should be initialized).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267)  *		this routine handles incore inode initialization for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268)  *		both "special" and "regular" inodes.  special inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269)  *		are those required early in the mount process and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270)  *		require special handling since much of the file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271)  *		is not yet initialized.  these "special" inodes are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272)  *		identified by a NULL inode map inode pointer and are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273)  *		actually initialized by a call to diReadSpecial().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275)  *		for regular inodes, the iag describing the disk inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276)  *		is read from disk to determine the inode extent address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277)  *		for the disk inode.  with the inode extent address in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278)  *		hand, the page of the extent that contains the disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279)  *		inode is read and the disk inode is copied to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280)  *		incore inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283)  *	ip	-  pointer to incore inode to be initialized from disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286)  *	0	- success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)  *	-ENOMEM	- insufficient memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) int diRead(struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	int iagno, ino, extno, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	struct inode *ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	struct dinode *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	struct iag *iagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	s64 blkno, agstart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	struct inomap *imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	int block_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	int inodes_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	unsigned long pageno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	int rel_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	jfs_info("diRead: ino = %ld", ip->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	ipimap = sbi->ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	JFS_IP(ip)->ipimap = ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	/* determine the iag number for this inode (number) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	iagno = INOTOIAG(ip->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	/* read the iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	imap = JFS_IP(ipimap)->i_imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	IREAD_LOCK(ipimap, RDWRLOCK_IMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	rc = diIAGRead(imap, iagno, &mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		jfs_err("diRead: diIAGRead returned %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	iagp = (struct iag *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	/* determine inode extent that holds the disk inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	ino = ip->i_ino & (INOSPERIAG - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	extno = ino >> L2INOSPEREXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	if ((lengthPXD(&iagp->inoext[extno]) != imap->im_nbperiext) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	    (addressPXD(&iagp->inoext[extno]) == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		return -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	/* get disk block number of the page within the inode extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	 * that holds the disk inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	blkno = INOPBLK(&iagp->inoext[extno], ino, sbi->l2nbperpage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	/* get the ag for the iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	agstart = le64_to_cpu(iagp->agstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	rel_inode = (ino & (INOSPERPAGE - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	pageno = blkno >> sbi->l2nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	if ((block_offset = ((u32) blkno & (sbi->nbperpage - 1)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		 * OS/2 didn't always align inode extents on page boundaries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		inodes_left =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		     (sbi->nbperpage - block_offset) << sbi->l2niperblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		if (rel_inode < inodes_left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 			rel_inode += block_offset << sbi->l2niperblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			pageno += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 			rel_inode -= inodes_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	/* read the page of disk inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	if (!mp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 		jfs_err("diRead: read_metapage failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	/* locate the disk inode requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	dp = (struct dinode *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	dp += rel_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	if (ip->i_ino != le32_to_cpu(dp->di_number)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		jfs_error(ip->i_sb, "i_ino != di_number\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	} else if (le32_to_cpu(dp->di_nlink) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		rc = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		/* copy the disk inode to the in-memory inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		rc = copy_from_dinode(dp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	/* set the ag for the inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	JFS_IP(ip)->agstart = agstart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	JFS_IP(ip)->active_ag = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395)  * NAME:	diReadSpecial()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397)  * FUNCTION:	initialize a 'special' inode from disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399)  *		this routines handles aggregate level inodes.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400)  *		inode cache cannot differentiate between the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401)  *		aggregate inodes and the filesystem inodes, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402)  *		handle these here.  We don't actually use the aggregate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403)  *		inode map, since these inodes are at a fixed location
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404)  *		and in some cases the aggregate inode map isn't initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)  *		yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)  *	sb - filesystem superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  *	inum - aggregate inode number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  *	secondary - 1 if secondary aggregate inode table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)  *	new inode	- success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)  *	NULL		- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) struct inode *diReadSpecial(struct super_block *sb, ino_t inum, int secondary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	struct jfs_sb_info *sbi = JFS_SBI(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	uint address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	struct dinode *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	struct inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	ip = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	if (ip == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		jfs_err("diReadSpecial: new_inode returned NULL!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		return ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	if (secondary) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		address = addressPXD(&sbi->ait2) >> sbi->l2nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		JFS_IP(ip)->ipimap = sbi->ipaimap2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		address = AITBL_OFF >> L2PSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		JFS_IP(ip)->ipimap = sbi->ipaimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	ASSERT(inum < INOSPEREXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	ip->i_ino = inum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	address += inum >> 3;	/* 8 inodes per 4K page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	/* read the page of fixed disk inode (AIT) in raw mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	mp = read_metapage(ip, address << sbi->l2nbperpage, PSIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	if (mp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		set_nlink(ip, 1);	/* Don't want iput() deleting it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		iput(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		return (NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	/* get the pointer to the disk inode of interest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	dp = (struct dinode *) (mp->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	dp += inum % 8;		/* 8 inodes per 4K page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	/* copy on-disk inode to in-memory inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	if ((copy_from_dinode(dp, ip)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		/* handle bad return by returning NULL for ip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		set_nlink(ip, 1);	/* Don't want iput() deleting it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		iput(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		/* release the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		return (NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	ip->i_mapping->a_ops = &jfs_metapage_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	mapping_set_gfp_mask(ip->i_mapping, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	/* Allocations to metadata inodes should not affect quotas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	ip->i_flags |= S_NOQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	if ((inum == FILESYSTEM_I) && (JFS_IP(ip)->ipimap == sbi->ipaimap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		sbi->gengen = le32_to_cpu(dp->di_gengen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		sbi->inostamp = le32_to_cpu(dp->di_inostamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	/* release the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	inode_fake_hash(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	return (ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487)  * NAME:	diWriteSpecial()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489)  * FUNCTION:	Write the special inode to disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492)  *	ip - special inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493)  *	secondary - 1 if secondary aggregate inode table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495)  * RETURN VALUES: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) void diWriteSpecial(struct inode *ip, int secondary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	uint address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	struct dinode *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	ino_t inum = ip->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	if (secondary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		address = addressPXD(&sbi->ait2) >> sbi->l2nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		address = AITBL_OFF >> L2PSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	ASSERT(inum < INOSPEREXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	address += inum >> 3;	/* 8 inodes per 4K page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	/* read the page of fixed disk inode (AIT) in raw mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	mp = read_metapage(ip, address << sbi->l2nbperpage, PSIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	if (mp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		jfs_err("diWriteSpecial: failed to read aggregate inode extent!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	/* get the pointer to the disk inode of interest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	dp = (struct dinode *) (mp->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	dp += inum % 8;		/* 8 inodes per 4K page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	/* copy on-disk inode to in-memory inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	copy_to_dinode(dp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	memcpy(&dp->di_xtroot, &JFS_IP(ip)->i_xtroot, 288);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	if (inum == FILESYSTEM_I)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		dp->di_gengen = cpu_to_le32(sbi->gengen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	/* write the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	write_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538)  * NAME:	diFreeSpecial()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540)  * FUNCTION:	Free allocated space for special inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) void diFreeSpecial(struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	if (ip == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		jfs_err("diFreeSpecial called with NULL ip!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	filemap_write_and_wait(ip->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	truncate_inode_pages(ip->i_mapping, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	iput(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556)  * NAME:	diWrite()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558)  * FUNCTION:	write the on-disk inode portion of the in-memory inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559)  *		to its corresponding on-disk inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561)  *		on entry, the specifed incore inode should itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  *		specify the disk inode number corresponding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)  *		incore inode (i.e. i_number should be initialized).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565)  *		the inode contains the inode extent address for the disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566)  *		inode.  with the inode extent address in hand, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567)  *		page of the extent that contains the disk inode is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568)  *		read and the disk inode portion of the incore inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569)  *		is copied to the disk inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572)  *	tid -  transacation id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573)  *	ip  -  pointer to incore inode to be written to the inode extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576)  *	0	- success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) int diWrite(tid_t tid, struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	struct jfs_inode_info *jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	s32 ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	struct dinode *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	s64 blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	int block_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	int inodes_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	unsigned long pageno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	int rel_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	int dioffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	struct inode *ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	uint type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	lid_t lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	struct tlock *ditlck, *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	struct linelock *dilinelock, *ilinelock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	struct lv *lv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	ipimap = jfs_ip->ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	ino = ip->i_ino & (INOSPERIAG - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	if (!addressPXD(&(jfs_ip->ixpxd)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	    (lengthPXD(&(jfs_ip->ixpxd)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	     JFS_IP(ipimap)->i_imap->im_nbperiext)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		jfs_error(ip->i_sb, "ixpxd invalid\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	 * read the page of disk inode containing the specified inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	/* compute the block address of the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	blkno = INOPBLK(&(jfs_ip->ixpxd), ino, sbi->l2nbperpage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	rel_inode = (ino & (INOSPERPAGE - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	pageno = blkno >> sbi->l2nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	if ((block_offset = ((u32) blkno & (sbi->nbperpage - 1)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		 * OS/2 didn't always align inode extents on page boundaries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		inodes_left =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		    (sbi->nbperpage - block_offset) << sbi->l2niperblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		if (rel_inode < inodes_left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 			rel_inode += block_offset << sbi->l2niperblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 			pageno += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			rel_inode -= inodes_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	/* read the page of disk inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636)       retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	if (!mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	/* get the pointer to the disk inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	dp = (struct dinode *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	dp += rel_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	dioffset = (ino & (INOSPERPAGE - 1)) << L2DISIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	 * acquire transaction lock on the on-disk inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	 * N.B. tlock is acquired on ipimap not ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	if ((ditlck =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	     txLock(tid, ipimap, mp, tlckINODE | tlckENTRY)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	dilinelock = (struct linelock *) & ditlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	 * copy btree root from in-memory inode to on-disk inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	 * (tlock is taken from inline B+-tree root in in-memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	 * inode when the B+-tree root is updated, which is pointed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	 * by jfs_ip->blid as well as being on tx tlock list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	 * further processing of btree root is based on the copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	 * in in-memory inode, where txLog() will log from, and,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	 * for xtree root, txUpdateMap() will update map and reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	 * XAD_NEW bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	if (S_ISDIR(ip->i_mode) && (lid = jfs_ip->xtlid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		 * This is the special xtree inside the directory for storing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		 * the directory table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		xtpage_t *p, *xp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		jfs_ip->xtlid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		assert(tlck->type & tlckXTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		tlck->type |= tlckBTROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		tlck->mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		ilinelock = (struct linelock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		 * copy xtree root from inode to dinode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		p = &jfs_ip->i_xtroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		xp = (xtpage_t *) &dp->di_dirtable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		lv = ilinelock->lv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		for (n = 0; n < ilinelock->index; n++, lv++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 			memcpy(&xp->xad[lv->offset], &p->xad[lv->offset],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			       lv->length << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		/* reset on-disk (metadata page) xtree XAD_NEW bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		xad = &xp->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		for (n = XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		     n < le16_to_cpu(xp->header.nextindex); n++, xad++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 			if (xad->flag & (XAD_NEW | XAD_EXTENDED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 				xad->flag &= ~(XAD_NEW | XAD_EXTENDED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	if ((lid = jfs_ip->blid) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		goto inlineData;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	jfs_ip->blid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	type = tlck->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	tlck->type |= tlckBTROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	tlck->mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	ilinelock = (struct linelock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	 *	regular file: 16 byte (XAD slot) granularity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	if (type & tlckXTREE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		xtpage_t *p, *xp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		 * copy xtree root from inode to dinode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		p = &jfs_ip->i_xtroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		xp = &dp->di_xtroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		lv = ilinelock->lv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		for (n = 0; n < ilinelock->index; n++, lv++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 			memcpy(&xp->xad[lv->offset], &p->xad[lv->offset],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 			       lv->length << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		/* reset on-disk (metadata page) xtree XAD_NEW bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		xad = &xp->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		for (n = XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		     n < le16_to_cpu(xp->header.nextindex); n++, xad++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			if (xad->flag & (XAD_NEW | XAD_EXTENDED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 				xad->flag &= ~(XAD_NEW | XAD_EXTENDED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	 *	directory: 32 byte (directory entry slot) granularity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	else if (type & tlckDTREE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		dtpage_t *p, *xp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		 * copy dtree root from inode to dinode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		p = (dtpage_t *) &jfs_ip->i_dtroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		xp = (dtpage_t *) & dp->di_dtroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		lv = ilinelock->lv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		for (n = 0; n < ilinelock->index; n++, lv++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 			memcpy(&xp->slot[lv->offset], &p->slot[lv->offset],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 			       lv->length << L2DTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		jfs_err("diWrite: UFO tlock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758)       inlineData:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	 * copy inline symlink from in-memory inode to on-disk inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	if (S_ISLNK(ip->i_mode) && ip->i_size < IDATASIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		lv = & dilinelock->lv[dilinelock->index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		lv->offset = (dioffset + 2 * 128) >> L2INODESLOTSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		lv->length = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		memcpy(&dp->di_fastsymlink, jfs_ip->i_inline, IDATASIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		dilinelock->index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	 * copy inline data from in-memory inode to on-disk inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	 * 128 byte slot granularity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	if (test_cflag(COMMIT_Inlineea, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		lv = & dilinelock->lv[dilinelock->index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		lv->offset = (dioffset + 3 * 128) >> L2INODESLOTSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		lv->length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		memcpy(&dp->di_inlineea, jfs_ip->i_inline_ea, INODESLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		dilinelock->index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		clear_cflag(COMMIT_Inlineea, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	 *	lock/copy inode base: 128 byte slot granularity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	lv = & dilinelock->lv[dilinelock->index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	lv->offset = dioffset >> L2INODESLOTSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	copy_to_dinode(dp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	if (test_and_clear_cflag(COMMIT_Dirtable, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		lv->length = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		memcpy(&dp->di_dirtable, &jfs_ip->i_dirtable, 96);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		lv->length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	dilinelock->index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	/* release the buffer holding the updated on-disk inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	 * the buffer will be later written by commit processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	write_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806)  * NAME:	diFree(ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808)  * FUNCTION:	free a specified inode from the inode working map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809)  *		for a fileset or aggregate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811)  *		if the inode to be freed represents the first (only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812)  *		free inode within the iag, the iag will be placed on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813)  *		the ag free inode list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815)  *		freeing the inode will cause the inode extent to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816)  *		freed if the inode is the only allocated inode within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817)  *		the extent.  in this case all the disk resource backing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818)  *		up the inode extent will be freed. in addition, the iag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819)  *		will be placed on the ag extent free list if the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820)  *		is the first free extent in the iag.  if freeing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821)  *		extent also means that no free inodes will exist for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822)  *		the iag, the iag will also be removed from the ag free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823)  *		inode list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825)  *		the iag describing the inode will be freed if the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  *		is to be freed and it is the only backed extent within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)  *		the iag.  in this case, the iag will be removed from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828)  *		ag free extent list and ag free inode list and placed on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829)  *		the inode map's free iag list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831)  *		a careful update approach is used to provide consistency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832)  *		in the face of updates to multiple buffers.  under this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833)  *		approach, all required buffers are obtained before making
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834)  *		any updates and are held until all updates are complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837)  *	ip	- inode to be freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840)  *	0	- success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) int diFree(struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	ino_t inum = ip->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	struct iag *iagp, *aiagp, *biagp, *ciagp, *diagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	struct metapage *mp, *amp, *bmp, *cmp, *dmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	int iagno, ino, extno, bitno, sword, agno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	int back, fwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	u32 bitmap, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	struct inode *ipimap = JFS_SBI(ip->i_sb)->ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	struct inomap *imap = JFS_IP(ipimap)->i_imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	pxd_t freepxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	tid_t tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	struct inode *iplist[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	struct pxd_lock *pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	 * This is just to suppress compiler warnings.  The same logic that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	 * references these variables is used to initialize them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	aiagp = biagp = ciagp = diagp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	/* get the iag number containing the inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	iagno = INOTOIAG(inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	/* make sure that the iag is contained within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	 * the map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	if (iagno >= imap->im_nextiag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		print_hex_dump(KERN_ERR, "imap: ", DUMP_PREFIX_ADDRESS, 16, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 			       imap, 32, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		jfs_error(ip->i_sb, "inum = %d, iagno = %d, nextiag = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 			  (uint) inum, iagno, imap->im_nextiag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	/* get the allocation group for this ino.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	agno = BLKTOAG(JFS_IP(ip)->agstart, JFS_SBI(ip->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	/* Lock the AG specific inode map information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	AG_LOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	/* Obtain read lock in imap inode.  Don't release it until we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	 * read all of the IAG's that we are going to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	IREAD_LOCK(ipimap, RDWRLOCK_IMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	/* read the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	if ((rc = diIAGRead(imap, iagno, &mp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	iagp = (struct iag *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	/* get the inode number and extent number of the inode within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	 * the iag and the inode number within the extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	ino = inum & (INOSPERIAG - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	extno = ino >> L2INOSPEREXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	bitno = ino & (INOSPEREXT - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	mask = HIGHORDER >> bitno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		jfs_error(ip->i_sb, "wmap shows inode already free\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	if (!addressPXD(&iagp->inoext[extno])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		jfs_error(ip->i_sb, "invalid inoext\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	/* compute the bitmap for the extent reflecting the freed inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	bitmap = le32_to_cpu(iagp->wmap[extno]) & ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	if (imap->im_agctl[agno].numfree > imap->im_agctl[agno].numinos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		jfs_error(ip->i_sb, "numfree > numinos\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	 *	inode extent still has some inodes or below low water mark:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	 *	keep the inode extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	if (bitmap ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	    imap->im_agctl[agno].numfree < 96 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	    (imap->im_agctl[agno].numfree < 288 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	     (((imap->im_agctl[agno].numfree * 100) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	       imap->im_agctl[agno].numinos) <= 25))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		/* if the iag currently has no free inodes (i.e.,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		 * the inode being freed is the first free inode of iag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		 * insert the iag at head of the inode free list for the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		if (iagp->nfreeinos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 			/* check if there are any iags on the ag inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			 * free list.  if so, read the first one so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 			 * we can link the current iag onto the list at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 			 * the head.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 			if ((fwd = imap->im_agctl[agno].inofree) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 				/* read the iag that currently is the head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 				 * of the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 				if ((rc = diIAGRead(imap, fwd, &amp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 					IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 					AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 					release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 					return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 				aiagp = (struct iag *) amp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 				/* make current head point back to the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 				aiagp->inofreeback = cpu_to_le32(iagno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 				write_metapage(amp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 			/* iag points forward to current head and iag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			 * becomes the new head of the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 			iagp->inofreefwd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 			    cpu_to_le32(imap->im_agctl[agno].inofree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			iagp->inofreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 			imap->im_agctl[agno].inofree = iagno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		/* update the free inode summary map for the extent if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		 * freeing the inode means the extent will now have free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		 * inodes (i.e., the inode being freed is the first free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		 * inode of extent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		if (iagp->wmap[extno] == cpu_to_le32(ONES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			sword = extno >> L2EXTSPERSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 			bitno = extno & (EXTSPERSUM - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 			iagp->inosmap[sword] &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 			    cpu_to_le32(~(HIGHORDER >> bitno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		/* update the bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		iagp->wmap[extno] = cpu_to_le32(bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		/* update the free inode counts at the iag, ag and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		 * map level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		le32_add_cpu(&iagp->nfreeinos, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		imap->im_agctl[agno].numfree += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		atomic_inc(&imap->im_numfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		/* release the AG inode map lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		/* write the iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		write_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	 *	inode extent has become free and above low water mark:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	 *	free the inode extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	 *	prepare to update iag list(s) (careful update step 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	amp = bmp = cmp = dmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	fwd = back = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	/* check if the iag currently has no free extents.  if so,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	 * it will be placed on the head of the ag extent free list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	if (iagp->nfreeexts == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		/* check if the ag extent free list has any iags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		 * if so, read the iag at the head of the list now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		 * this (head) iag will be updated later to reflect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		 * the addition of the current iag at the head of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		 * the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		if ((fwd = imap->im_agctl[agno].extfree) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 			if ((rc = diIAGRead(imap, fwd, &amp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 				goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			aiagp = (struct iag *) amp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		/* iag has free extents. check if the addition of a free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		 * extent will cause all extents to be free within this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		 * iag.  if so, the iag will be removed from the ag extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		 * free list and placed on the inode map's free iag list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 			/* in preparation for removing the iag from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			 * ag extent free list, read the iags preceding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 			 * and following the iag on the ag extent free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 			 * list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 			if ((fwd = le32_to_cpu(iagp->extfreefwd)) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 				if ((rc = diIAGRead(imap, fwd, &amp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 					goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 				aiagp = (struct iag *) amp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 			if ((back = le32_to_cpu(iagp->extfreeback)) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 				if ((rc = diIAGRead(imap, back, &bmp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 					goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 				biagp = (struct iag *) bmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	/* remove the iag from the ag inode free list if freeing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	 * this extent cause the iag to have no free inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	if (iagp->nfreeinos == cpu_to_le32(INOSPEREXT - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		int inofreeback = le32_to_cpu(iagp->inofreeback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		int inofreefwd = le32_to_cpu(iagp->inofreefwd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		/* in preparation for removing the iag from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		 * ag inode free list, read the iags preceding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		 * and following the iag on the ag inode free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		 * list.  before reading these iags, we must make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		 * sure that we already don't have them in hand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		 * from up above, since re-reading an iag (buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		 * we are currently holding would cause a deadlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		if (inofreefwd >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 			if (inofreefwd == fwd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 				ciagp = (struct iag *) amp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 			else if (inofreefwd == back)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 				ciagp = (struct iag *) bmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 				if ((rc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 				     diIAGRead(imap, inofreefwd, &cmp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 					goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 				ciagp = (struct iag *) cmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 			assert(ciagp != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		if (inofreeback >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 			if (inofreeback == fwd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 				diagp = (struct iag *) amp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 			else if (inofreeback == back)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 				diagp = (struct iag *) bmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 				if ((rc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 				     diIAGRead(imap, inofreeback, &dmp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 					goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 				diagp = (struct iag *) dmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 			assert(diagp != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	 * invalidate any page of the inode extent freed from buffer cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	freepxd = iagp->inoext[extno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	invalidate_pxd_metapages(ip, freepxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	 *	update iag list(s) (careful update step 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	/* add the iag to the ag extent free list if this is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	 * first free extent for the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	if (iagp->nfreeexts == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		if (fwd >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 			aiagp->extfreeback = cpu_to_le32(iagno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		iagp->extfreefwd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		    cpu_to_le32(imap->im_agctl[agno].extfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		iagp->extfreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		imap->im_agctl[agno].extfree = iagno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		/* remove the iag from the ag extent list if all extents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		 * are now free and place it on the inode map iag free list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 			if (fwd >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 				aiagp->extfreeback = iagp->extfreeback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 			if (back >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 				biagp->extfreefwd = iagp->extfreefwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 				imap->im_agctl[agno].extfree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 				    le32_to_cpu(iagp->extfreefwd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 			iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 			IAGFREE_LOCK(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 			iagp->iagfree = cpu_to_le32(imap->im_freeiag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 			imap->im_freeiag = iagno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 			IAGFREE_UNLOCK(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	/* remove the iag from the ag inode free list if freeing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	 * this extent causes the iag to have no free inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	if (iagp->nfreeinos == cpu_to_le32(INOSPEREXT - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		if ((int) le32_to_cpu(iagp->inofreefwd) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			ciagp->inofreeback = iagp->inofreeback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		if ((int) le32_to_cpu(iagp->inofreeback) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 			diagp->inofreefwd = iagp->inofreefwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 			imap->im_agctl[agno].inofree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 			    le32_to_cpu(iagp->inofreefwd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	/* update the inode extent address and working map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	 * to reflect the free extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	 * the permanent map should have been updated already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	 * for the inode being freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	if (iagp->pmap[extno] != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 		jfs_error(ip->i_sb, "the pmap does not show inode free\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	iagp->wmap[extno] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	PXDlength(&iagp->inoext[extno], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	PXDaddress(&iagp->inoext[extno], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	/* update the free extent and free inode summary maps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	 * to reflect the freed extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	 * the inode summary map is marked to indicate no inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	 * available for the freed extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	sword = extno >> L2EXTSPERSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	bitno = extno & (EXTSPERSUM - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	mask = HIGHORDER >> bitno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	iagp->inosmap[sword] |= cpu_to_le32(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	iagp->extsmap[sword] &= cpu_to_le32(~mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	/* update the number of free inodes and number of free extents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	 * for the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	le32_add_cpu(&iagp->nfreeinos, -(INOSPEREXT - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	le32_add_cpu(&iagp->nfreeexts, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	/* update the number of free inodes and backed inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	 * at the ag and inode map level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	imap->im_agctl[agno].numfree -= (INOSPEREXT - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	imap->im_agctl[agno].numinos -= INOSPEREXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	atomic_sub(INOSPEREXT - 1, &imap->im_numfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	atomic_sub(INOSPEREXT, &imap->im_numinos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	if (amp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		write_metapage(amp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	if (bmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		write_metapage(bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	if (cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		write_metapage(cmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	if (dmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		write_metapage(dmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	 * start transaction to update block allocation map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	 * for the inode extent freed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	 * N.B. AG_LOCK is released and iag will be released below, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	 * other thread may allocate inode from/reusing the ixad freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	 * BUT with new/different backing inode extent from the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	 * to be freed by the transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	tid = txBegin(ipimap->i_sb, COMMIT_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	mutex_lock(&JFS_IP(ipimap)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	/* acquire tlock of the iag page of the freed ixad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	 * to force the page NOHOMEOK (even though no data is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	 * logged from the iag page) until NOREDOPAGE|FREEXTENT log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	 * for the free of the extent is committed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	 * write FREEXTENT|NOREDOPAGE log record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	 * N.B. linelock is overlaid as freed extent descriptor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	tlck = txLock(tid, ipimap, mp, tlckINODE | tlckFREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	pxdlock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	pxdlock->flag = mlckFREEPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	pxdlock->pxd = freepxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	pxdlock->index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	write_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	iplist[0] = ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	 * logredo needs the IAG number and IAG extent index in order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	 * to ensure that the IMap is consistent.  The least disruptive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	 * way to pass these values through  to the transaction manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	 * is in the iplist array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	 * It's not pretty, but it works.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	iplist[1] = (struct inode *) (size_t)iagno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	iplist[2] = (struct inode *) (size_t)extno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	rc = txCommit(tid, 1, &iplist[0], COMMIT_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	mutex_unlock(&JFS_IP(ipimap)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	/* unlock the AG inode map information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)       error_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	if (amp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		release_metapage(amp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	if (bmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		release_metapage(bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	if (cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		release_metapage(cmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	if (dmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		release_metapage(dmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)  * There are several places in the diAlloc* routines where we initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)  * the inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) diInitInode(struct inode *ip, int iagno, int ino, int extno, struct iag * iagp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	struct jfs_inode_info *jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	ip->i_ino = (iagno << L2INOSPERIAG) + ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	jfs_ip->ixpxd = iagp->inoext[extno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	jfs_ip->agstart = le64_to_cpu(iagp->agstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	jfs_ip->active_ag = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)  * NAME:	diAlloc(pip,dir,ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)  * FUNCTION:	allocate a disk inode from the inode working map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)  *		for a fileset or aggregate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)  *	pip	- pointer to incore inode for the parent inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)  *	dir	- 'true' if the new disk inode is for a directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)  *	ip	- pointer to a new inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317)  *	0	- success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)  *	-ENOSPC	- insufficient disk resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) int diAlloc(struct inode *pip, bool dir, struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	int rc, ino, iagno, addext, extno, bitno, sword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	int nwords, rem, i, agno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	u32 mask, inosmap, extsmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	struct inode *ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	ino_t inum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	struct iag *iagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	struct inomap *imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	/* get the pointers to the inode map inode and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	 * corresponding imap control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	ipimap = JFS_SBI(pip->i_sb)->ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	imap = JFS_IP(ipimap)->i_imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	JFS_IP(ip)->ipimap = ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	JFS_IP(ip)->fileset = FILESYSTEM_I;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	/* for a directory, the allocation policy is to start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	 * at the ag level using the preferred ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	if (dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		agno = dbNextAG(JFS_SBI(pip->i_sb)->ipbmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		AG_LOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		goto tryag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	/* for files, the policy starts off by trying to allocate from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	 * the same iag containing the parent disk inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	 * try to allocate the new disk inode close to the parent disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	 * inode, using parent disk inode number + 1 as the allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	 * hint.  (we use a left-to-right policy to attempt to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	 * moving backward on the disk.)  compute the hint within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	 * file system and the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	/* get the ag number of this iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		 * There is an open file actively growing.  We want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		 * allocate new inodes from a different ag to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		 * fragmentation problems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		agno = dbNextAG(JFS_SBI(pip->i_sb)->ipbmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		AG_LOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		goto tryag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	inum = pip->i_ino + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	ino = inum & (INOSPERIAG - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	/* back off the hint if it is outside of the iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	if (ino == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		inum = pip->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	/* lock the AG inode map information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	AG_LOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	/* Get read lock on imap inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	IREAD_LOCK(ipimap, RDWRLOCK_IMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	/* get the iag number and read the iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	iagno = INOTOIAG(inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	if ((rc = diIAGRead(imap, iagno, &mp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	iagp = (struct iag *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	/* determine if new inode extent is allowed to be added to the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	 * new inode extent can be added to the iag if the ag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	 * has less than 32 free disk inodes and the iag has free extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	addext = (imap->im_agctl[agno].numfree < 32 && iagp->nfreeexts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	 *	try to allocate from the IAG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	/* check if the inode may be allocated from the iag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	 * (i.e. the inode has free inodes or new extent can be added).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	if (iagp->nfreeinos || addext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		/* determine the extent number of the hint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		extno = ino >> L2INOSPEREXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		/* check if the extent containing the hint has backed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		 * inodes.  if so, try to allocate within this extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		if (addressPXD(&iagp->inoext[extno])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 			bitno = ino & (INOSPEREXT - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 			if ((bitno =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 			     diFindFree(le32_to_cpu(iagp->wmap[extno]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 					bitno))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 			    < INOSPEREXT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 				ino = (extno << L2INOSPEREXT) + bitno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 				/* a free inode (bit) was found within this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 				 * extent, so allocate it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 				rc = diAllocBit(imap, iagp, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 				IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 				if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 					assert(rc == -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 					/* set the results of the allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 					 * and write the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 					diInitInode(ip, iagno, ino, extno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 						    iagp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 					mark_metapage_dirty(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 				release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 				/* free the AG lock and return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 				AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 				return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 			if (!addext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 				extno =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 				    (extno ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 				     EXTSPERIAG - 1) ? 0 : extno + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		 * no free inodes within the extent containing the hint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 		 * try to allocate from the backed extents following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		 * hint or, if appropriate (i.e. addext is true), allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 		 * an extent of free inodes at or following the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 		 * containing the hint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 		 * the free inode and free extent summary maps are used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 		 * here, so determine the starting summary map position
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 		 * and the number of words we'll have to examine.  again,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 		 * the approach is to allocate following the hint, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 		 * might have to initially ignore prior bits of the summary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 		 * map that represent extents prior to the extent containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 		 * the hint and later revisit these bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		bitno = extno & (EXTSPERSUM - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 		nwords = (bitno == 0) ? SMAPSZ : SMAPSZ + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		sword = extno >> L2EXTSPERSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		/* mask any prior bits for the starting words of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		 * summary map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		mask = (bitno == 0) ? 0 : (ONES << (EXTSPERSUM - bitno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		inosmap = le32_to_cpu(iagp->inosmap[sword]) | mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 		extsmap = le32_to_cpu(iagp->extsmap[sword]) | mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		/* scan the free inode and free extent summary maps for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		 * free resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 		for (i = 0; i < nwords; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 			/* check if this word of the free inode summary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 			 * map describes an extent with free inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 			if (~inosmap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 				/* an extent with free inodes has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 				 * found. determine the extent number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 				 * and the inode number within the extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 				rem = diFindFree(inosmap, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 				extno = (sword << L2EXTSPERSUM) + rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 				rem = diFindFree(le32_to_cpu(iagp->wmap[extno]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 						 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 				if (rem >= INOSPEREXT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 					IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 					release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 					AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 					jfs_error(ip->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 						  "can't find free bit in wmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 					return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 				/* determine the inode number within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 				 * iag and allocate the inode from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 				 * map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 				ino = (extno << L2INOSPEREXT) + rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 				rc = diAllocBit(imap, iagp, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 				IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 				if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 					assert(rc == -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 				else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 					/* set the results of the allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 					 * and write the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 					diInitInode(ip, iagno, ino, extno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 						    iagp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 					mark_metapage_dirty(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 				release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 				/* free the AG lock and return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 				AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 				return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 			/* check if we may allocate an extent of free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 			 * inodes and whether this word of the free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 			 * extents summary map describes a free extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 			if (addext && ~extsmap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 				/* a free extent has been found.  determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 				 * the extent number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 				rem = diFindFree(extsmap, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 				extno = (sword << L2EXTSPERSUM) + rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 				/* allocate an extent of free inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 				if ((rc = diNewExt(imap, iagp, extno))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 					/* if there is no disk space for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 					 * new extent, try to allocate the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 					 * disk inode from somewhere else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 					if (rc == -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 						break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 					assert(rc == -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 					/* set the results of the allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 					 * and write the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 					diInitInode(ip, iagno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 						    extno << L2INOSPEREXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 						    extno, iagp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 					mark_metapage_dirty(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 				release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 				/* free the imap inode & the AG lock & return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 				IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 				AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 				return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 			/* move on to the next set of summary map words.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 			sword = (sword == SMAPSZ - 1) ? 0 : sword + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 			inosmap = le32_to_cpu(iagp->inosmap[sword]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 			extsmap = le32_to_cpu(iagp->extsmap[sword]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	/* unlock imap inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	/* nothing doing in this iag, so release it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581)       tryag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	 * try to allocate anywhere within the same AG as the parent inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	rc = diAllocAG(imap, agno, dir, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	AG_UNLOCK(imap, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	if (rc != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	 * try to allocate in any AG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	return (diAllocAny(imap, agno, dir, ip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)  * NAME:	diAllocAG(imap,agno,dir,ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)  * FUNCTION:	allocate a disk inode from the allocation group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)  *		this routine first determines if a new extent of free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)  *		inodes should be added for the allocation group, with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)  *		the current request satisfied from this extent. if this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)  *		is the case, an attempt will be made to do just that.  if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608)  *		this attempt fails or it has been determined that a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)  *		extent should not be added, an attempt is made to satisfy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)  *		the request by allocating an existing (backed) free inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)  *		from the allocation group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)  * PRE CONDITION: Already have the AG lock for this AG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)  *	imap	- pointer to inode map control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)  *	agno	- allocation group to allocate from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)  *	dir	- 'true' if the new disk inode is for a directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619)  *	ip	- pointer to the new inode to be filled in on successful return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)  *		  with the disk inode number allocated, its extent address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)  *		  and the start of the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624)  *	0	- success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)  *	-ENOSPC	- insufficient disk resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) diAllocAG(struct inomap * imap, int agno, bool dir, struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	int rc, addext, numfree, numinos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	/* get the number of free and the number of backed disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	 * inodes currently within the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	numfree = imap->im_agctl[agno].numfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	numinos = imap->im_agctl[agno].numinos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	if (numfree > numinos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 		jfs_error(ip->i_sb, "numfree > numinos\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	/* determine if we should allocate a new extent of free inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	 * within the ag: for directory inodes, add a new extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	 * if there are a small number of free inodes or number of free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	 * inodes is a small percentage of the number of backed inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	if (dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 		addext = (numfree < 64 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 			  (numfree < 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 			   && ((numfree * 100) / numinos) <= 20));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		addext = (numfree == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	 * try to allocate a new extent of free inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	if (addext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		/* if free space is not available for this new extent, try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 		 * below to allocate a free and existing (already backed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 		 * inode from the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		if ((rc = diAllocExt(imap, agno, ip)) != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 			return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	 * try to allocate an existing free inode from the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	return (diAllocIno(imap, agno, ip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676)  * NAME:	diAllocAny(imap,agno,dir,iap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)  * FUNCTION:	allocate a disk inode from any other allocation group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)  *		this routine is called when an allocation attempt within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)  *		the primary allocation group has failed. if attempts to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)  *		allocate an inode from any allocation group other than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683)  *		specified primary group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)  *	imap	- pointer to inode map control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)  *	agno	- primary allocation group (to avoid).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)  *	dir	- 'true' if the new disk inode is for a directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)  *	ip	- pointer to a new inode to be filled in on successful return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690)  *		  with the disk inode number allocated, its extent address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)  *		  and the start of the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)  *	0	- success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)  *	-ENOSPC	- insufficient disk resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) diAllocAny(struct inomap * imap, int agno, bool dir, struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	int ag, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	int maxag = JFS_SBI(imap->im_ipimap->i_sb)->bmap->db_maxag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	/* try to allocate from the ags following agno up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	 * the maximum ag number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	for (ag = agno + 1; ag <= maxag; ag++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 		AG_LOCK(imap, ag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 		rc = diAllocAG(imap, ag, dir, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 		AG_UNLOCK(imap, ag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 		if (rc != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 			return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	/* try to allocate from the ags in front of agno.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	for (ag = 0; ag < agno; ag++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 		AG_LOCK(imap, ag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 		rc = diAllocAG(imap, ag, dir, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 		AG_UNLOCK(imap, ag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 		if (rc != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 			return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	/* no free disk inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)  * NAME:	diAllocIno(imap,agno,ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)  * FUNCTION:	allocate a disk inode from the allocation group's free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)  *		inode list, returning an error if this free list is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743)  *		empty (i.e. no iags on the list).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)  *		allocation occurs from the first iag on the list using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)  *		the iag's free inode summary map to find the leftmost
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)  *		free inode in the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)  * PRE CONDITION: Already have AG lock for this AG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)  *	imap	- pointer to inode map control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)  *	agno	- allocation group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)  *	ip	- pointer to new inode to be filled in on successful return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755)  *		  with the disk inode number allocated, its extent address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)  *		  and the start of the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)  *	0	- success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)  *	-ENOSPC	- insufficient disk resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) static int diAllocIno(struct inomap * imap, int agno, struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	int iagno, ino, rc, rem, extno, sword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	struct iag *iagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	/* check if there are iags on the ag's free inode list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	if ((iagno = imap->im_agctl[agno].inofree) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	/* obtain read lock on imap inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	IREAD_LOCK(imap->im_ipimap, RDWRLOCK_IMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	/* read the iag at the head of the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	if ((rc = diIAGRead(imap, iagno, &mp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 		IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 		return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	iagp = (struct iag *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	/* better be free inodes in this iag if it is on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	 * list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	if (!iagp->nfreeinos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 		IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 		release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 		jfs_error(ip->i_sb, "nfreeinos = 0, but iag on freelist\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	/* scan the free inode summary map to find an extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	 * with free inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	for (sword = 0;; sword++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 		if (sword >= SMAPSZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 			IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 			release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 			jfs_error(ip->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 				  "free inode not found in summary map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 		if (~iagp->inosmap[sword])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	/* found a extent with free inodes. determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	 * the extent number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	rem = diFindFree(le32_to_cpu(iagp->inosmap[sword]), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	if (rem >= EXTSPERSUM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 		IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 		release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 		jfs_error(ip->i_sb, "no free extent found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	extno = (sword << L2EXTSPERSUM) + rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	/* find the first free inode in the extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	rem = diFindFree(le32_to_cpu(iagp->wmap[extno]), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	if (rem >= INOSPEREXT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 		IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 		jfs_error(ip->i_sb, "free inode not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	/* compute the inode number within the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	ino = (extno << L2INOSPEREXT) + rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	/* allocate the inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	rc = diAllocBit(imap, iagp, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 		release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 		return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	/* set the results of the allocation and write the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	diInitInode(ip, iagno, ino, extno, iagp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	write_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)  * NAME:	diAllocExt(imap,agno,ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)  * FUNCTION:	add a new extent of free inodes to an iag, allocating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859)  *		an inode from this extent to satisfy the current allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)  *		request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)  *		this routine first tries to find an existing iag with free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863)  *		extents through the ag free extent list.  if list is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)  *		empty, the head of the list will be selected as the home
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865)  *		of the new extent of free inodes.  otherwise (the list is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866)  *		empty), a new iag will be allocated for the ag to contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)  *		the extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869)  *		once an iag has been selected, the free extent summary map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)  *		is used to locate a free extent within the iag and diNewExt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871)  *		is called to initialize the extent, with initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872)  *		including the allocation of the first inode of the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873)  *		for the purpose of satisfying this request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)  *	imap	- pointer to inode map control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877)  *	agno	- allocation group number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878)  *	ip	- pointer to new inode to be filled in on successful return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)  *		  with the disk inode number allocated, its extent address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)  *		  and the start of the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)  *	0	- success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884)  *	-ENOSPC	- insufficient disk resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) static int diAllocExt(struct inomap * imap, int agno, struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	int rem, iagno, sword, extno, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	struct iag *iagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	/* check if the ag has any iags with free extents.  if not,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	 * allocate a new iag for the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	if ((iagno = imap->im_agctl[agno].extfree) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 		/* If successful, diNewIAG will obtain the read lock on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 		 * imap inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 		if ((rc = diNewIAG(imap, &iagno, agno, &mp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 			return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 		iagp = (struct iag *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 		/* set the ag number if this a brand new iag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 		iagp->agstart =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 		    cpu_to_le64(AGTOBLK(agno, imap->im_ipimap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 		/* read the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 		IREAD_LOCK(imap->im_ipimap, RDWRLOCK_IMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 		if ((rc = diIAGRead(imap, iagno, &mp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 			IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 			jfs_error(ip->i_sb, "error reading iag\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 		iagp = (struct iag *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 	/* using the free extent summary map, find a free extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	for (sword = 0;; sword++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		if (sword >= SMAPSZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 			release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 			IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 			jfs_error(ip->i_sb, "free ext summary map not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 		if (~iagp->extsmap[sword])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	/* determine the extent number of the free extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 	rem = diFindFree(le32_to_cpu(iagp->extsmap[sword]), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	if (rem >= EXTSPERSUM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 		release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 		IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 		jfs_error(ip->i_sb, "free extent not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	extno = (sword << L2EXTSPERSUM) + rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	/* initialize the new extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	rc = diNewExt(imap, iagp, extno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 	IREAD_UNLOCK(imap->im_ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 		/* something bad happened.  if a new iag was allocated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 		 * place it back on the inode map's iag free list, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 		 * clear the ag number information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 			IAGFREE_LOCK(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 			iagp->iagfree = cpu_to_le32(imap->im_freeiag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 			imap->im_freeiag = iagno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 			IAGFREE_UNLOCK(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		write_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 		return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	/* set the results of the allocation and write the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 	diInitInode(ip, iagno, extno << L2INOSPEREXT, extno, iagp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	write_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975)  * NAME:	diAllocBit(imap,iagp,ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)  * FUNCTION:	allocate a backed inode from an iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979)  *		this routine performs the mechanics of allocating a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)  *		specified inode from a backed extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)  *		if the inode to be allocated represents the last free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983)  *		inode within the iag, the iag will be removed from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984)  *		ag free inode list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986)  *		a careful update approach is used to provide consistency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987)  *		in the face of updates to multiple buffers.  under this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988)  *		approach, all required buffers are obtained before making
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989)  *		any updates and are held all are updates are complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991)  * PRE CONDITION: Already have buffer lock on iagp.  Already have AG lock on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)  *	this AG.  Must have read lock on imap inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995)  *	imap	- pointer to inode map control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996)  *	iagp	- pointer to iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997)  *	ino	- inode number to be allocated within the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000)  *	0	- success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001)  *	-ENOSPC	- insufficient disk resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) static int diAllocBit(struct inomap * imap, struct iag * iagp, int ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 	int extno, bitno, agno, sword, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	struct metapage *amp = NULL, *bmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	struct iag *aiagp = NULL, *biagp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 	u32 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	/* check if this is the last free inode within the iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 	 * if so, it will have to be removed from the ag free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 	 * inode list, so get the iags preceding and following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 	 * it on the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 	if (iagp->nfreeinos == cpu_to_le32(1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 		if ((int) le32_to_cpu(iagp->inofreefwd) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 			if ((rc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 			     diIAGRead(imap, le32_to_cpu(iagp->inofreefwd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 				       &amp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 				return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 			aiagp = (struct iag *) amp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 		if ((int) le32_to_cpu(iagp->inofreeback) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 			if ((rc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 			     diIAGRead(imap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 				       le32_to_cpu(iagp->inofreeback),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 				       &bmp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 				if (amp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 					release_metapage(amp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 				return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 			biagp = (struct iag *) bmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 	/* get the ag number, extent number, inode number within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	 * the extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	agno = BLKTOAG(le64_to_cpu(iagp->agstart), JFS_SBI(imap->im_ipimap->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 	extno = ino >> L2INOSPEREXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 	bitno = ino & (INOSPEREXT - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 	/* compute the mask for setting the map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 	mask = HIGHORDER >> bitno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 	/* the inode should be free and backed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 	if (((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 	    ((le32_to_cpu(iagp->wmap[extno]) & mask) != 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	    (addressPXD(&iagp->inoext[extno]) == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 		if (amp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 			release_metapage(amp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 		if (bmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 			release_metapage(bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 		jfs_error(imap->im_ipimap->i_sb, "iag inconsistent\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	/* mark the inode as allocated in the working map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 	iagp->wmap[extno] |= cpu_to_le32(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 	/* check if all inodes within the extent are now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	 * allocated.  if so, update the free inode summary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	 * map to reflect this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	if (iagp->wmap[extno] == cpu_to_le32(ONES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 		sword = extno >> L2EXTSPERSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 		bitno = extno & (EXTSPERSUM - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 		iagp->inosmap[sword] |= cpu_to_le32(HIGHORDER >> bitno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	/* if this was the last free inode in the iag, remove the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	 * iag from the ag free inode list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 	if (iagp->nfreeinos == cpu_to_le32(1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 		if (amp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 			aiagp->inofreeback = iagp->inofreeback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 			write_metapage(amp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 		if (bmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 			biagp->inofreefwd = iagp->inofreefwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 			write_metapage(bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 			imap->im_agctl[agno].inofree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 			    le32_to_cpu(iagp->inofreefwd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 		iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	/* update the free inode count at the iag, ag, inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 	 * map levels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 	le32_add_cpu(&iagp->nfreeinos, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 	imap->im_agctl[agno].numfree -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	atomic_dec(&imap->im_numfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)  * NAME:	diNewExt(imap,iagp,extno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110)  * FUNCTION:	initialize a new extent of inodes for an iag, allocating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111)  *		the first inode of the extent for use for the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)  *		allocation request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)  *		disk resources are allocated for the new extent of inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115)  *		and the inodes themselves are initialized to reflect their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116)  *		existence within the extent (i.e. their inode numbers and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)  *		inode extent addresses are set) and their initial state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)  *		(mode and link count are set to zero).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120)  *		if the iag is new, it is not yet on an ag extent free list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)  *		but will now be placed on this list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123)  *		if the allocation of the new extent causes the iag to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)  *		have no free extent, the iag will be removed from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)  *		ag extent free list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)  *		if the iag has no free backed inodes, it will be placed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128)  *		on the ag free inode list, since the addition of the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129)  *		extent will now cause it to have free inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131)  *		a careful update approach is used to provide consistency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132)  *		(i.e. list consistency) in the face of updates to multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133)  *		buffers.  under this approach, all required buffers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134)  *		obtained before making any updates and are held until all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135)  *		updates are complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137)  * PRE CONDITION: Already have buffer lock on iagp.  Already have AG lock on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)  *	this AG.  Must have read lock on imap inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141)  *	imap	- pointer to inode map control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142)  *	iagp	- pointer to iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)  *	extno	- extent number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146)  *	0	- success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147)  *	-ENOSPC	- insufficient disk resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) static int diNewExt(struct inomap * imap, struct iag * iagp, int extno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 	int agno, iagno, fwd, back, freei = 0, sword, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	struct iag *aiagp = NULL, *biagp = NULL, *ciagp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	struct metapage *amp, *bmp, *cmp, *dmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	struct inode *ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	s64 blkno, hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 	u32 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 	ino_t ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 	struct dinode *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 	struct jfs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 	/* better have free extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	if (!iagp->nfreeexts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 		jfs_error(imap->im_ipimap->i_sb, "no free extents\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	/* get the inode map inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	ipimap = imap->im_ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 	sbi = JFS_SBI(ipimap->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 	amp = bmp = cmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 	/* get the ag and iag numbers for this iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 	agno = BLKTOAG(le64_to_cpu(iagp->agstart), sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	iagno = le32_to_cpu(iagp->iagnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 	/* check if this is the last free extent within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 	 * iag.  if so, the iag must be removed from the ag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 	 * free extent list, so get the iags preceding and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 	 * following the iag on this list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 	if (iagp->nfreeexts == cpu_to_le32(1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 		if ((fwd = le32_to_cpu(iagp->extfreefwd)) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 			if ((rc = diIAGRead(imap, fwd, &amp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 				return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 			aiagp = (struct iag *) amp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		if ((back = le32_to_cpu(iagp->extfreeback)) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 			if ((rc = diIAGRead(imap, back, &bmp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 				goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 			biagp = (struct iag *) bmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 		/* the iag has free extents.  if all extents are free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 		 * (as is the case for a newly allocated iag), the iag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 		 * must be added to the ag free extent list, so get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 		 * the iag at the head of the list in preparation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		 * adding this iag to this list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 		fwd = back = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 		if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 			if ((fwd = imap->im_agctl[agno].extfree) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 				if ((rc = diIAGRead(imap, fwd, &amp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 					goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 				aiagp = (struct iag *) amp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 	/* check if the iag has no free inodes.  if so, the iag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 	 * will have to be added to the ag free inode list, so get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 	 * the iag at the head of the list in preparation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 	 * adding this iag to this list.  in doing this, we must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 	 * check if we already have the iag at the head of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 	 * the list in hand.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	if (iagp->nfreeinos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 		freei = imap->im_agctl[agno].inofree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		if (freei >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 			if (freei == fwd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 				ciagp = aiagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 			} else if (freei == back) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 				ciagp = biagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 				if ((rc = diIAGRead(imap, freei, &cmp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 					goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 				ciagp = (struct iag *) cmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 			if (ciagp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 				jfs_error(imap->im_ipimap->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 					  "ciagp == NULL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 				rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 				goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 	/* allocate disk space for the inode extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	if ((extno == 0) || (addressPXD(&iagp->inoext[extno - 1]) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 		hint = ((s64) agno << sbi->bmap->db_agl2size) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 		hint = addressPXD(&iagp->inoext[extno - 1]) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 		    lengthPXD(&iagp->inoext[extno - 1]) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	if ((rc = dbAlloc(ipimap, hint, (s64) imap->im_nbperiext, &blkno)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 	/* compute the inode number of the first inode within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 	 * extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	ino = (iagno << L2INOSPERIAG) + (extno << L2INOSPEREXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	/* initialize the inodes within the newly allocated extent a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 	 * page at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 	for (i = 0; i < imap->im_nbperiext; i += sbi->nbperpage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 		/* get a buffer for this page of disk inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 		dmp = get_metapage(ipimap, blkno + i, PSIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 		if (dmp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 			goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 		dp = (struct dinode *) dmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 		/* initialize the inode number, mode, link count and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 		 * inode extent address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 		for (j = 0; j < INOSPERPAGE; j++, dp++, ino++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 			dp->di_inostamp = cpu_to_le32(sbi->inostamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 			dp->di_number = cpu_to_le32(ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 			dp->di_fileset = cpu_to_le32(FILESYSTEM_I);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 			dp->di_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 			dp->di_nlink = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 			PXDaddress(&(dp->di_ixpxd), blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 			PXDlength(&(dp->di_ixpxd), imap->im_nbperiext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 		write_metapage(dmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 	/* if this is the last free extent within the iag, remove the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 	 * iag from the ag free extent list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 	if (iagp->nfreeexts == cpu_to_le32(1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 		if (fwd >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 			aiagp->extfreeback = iagp->extfreeback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 		if (back >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 			biagp->extfreefwd = iagp->extfreefwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 			imap->im_agctl[agno].extfree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 			    le32_to_cpu(iagp->extfreefwd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 		iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 		/* if the iag has all free extents (newly allocated iag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 		 * add the iag to the ag free extent list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 		if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 			if (fwd >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 				aiagp->extfreeback = cpu_to_le32(iagno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 			iagp->extfreefwd = cpu_to_le32(fwd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 			iagp->extfreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 			imap->im_agctl[agno].extfree = iagno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 	/* if the iag has no free inodes, add the iag to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 	 * ag free inode list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 	if (iagp->nfreeinos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 		if (freei >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 			ciagp->inofreeback = cpu_to_le32(iagno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 		iagp->inofreefwd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 		    cpu_to_le32(imap->im_agctl[agno].inofree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 		iagp->inofreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 		imap->im_agctl[agno].inofree = iagno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 	/* initialize the extent descriptor of the extent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	PXDlength(&iagp->inoext[extno], imap->im_nbperiext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 	PXDaddress(&iagp->inoext[extno], blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 	/* initialize the working and persistent map of the extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 	 * the working map will be initialized such that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 	 * it indicates the first inode of the extent is allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 	iagp->wmap[extno] = cpu_to_le32(HIGHORDER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 	iagp->pmap[extno] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 	/* update the free inode and free extent summary maps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	 * for the extent to indicate the extent has free inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 	 * and no longer represents a free extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 	sword = extno >> L2EXTSPERSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 	mask = HIGHORDER >> (extno & (EXTSPERSUM - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 	iagp->extsmap[sword] |= cpu_to_le32(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 	iagp->inosmap[sword] &= cpu_to_le32(~mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 	/* update the free inode and free extent counts for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 	 * iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 	le32_add_cpu(&iagp->nfreeinos, (INOSPEREXT - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 	le32_add_cpu(&iagp->nfreeexts, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	/* update the free and backed inode counts for the ag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	imap->im_agctl[agno].numfree += (INOSPEREXT - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 	imap->im_agctl[agno].numinos += INOSPEREXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 	/* update the free and backed inode counts for the inode map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 	atomic_add(INOSPEREXT - 1, &imap->im_numfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 	atomic_add(INOSPEREXT, &imap->im_numinos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 	/* write the iags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	if (amp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 		write_metapage(amp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 	if (bmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 		write_metapage(bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 	if (cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 		write_metapage(cmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377)       error_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 	/* release the iags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 	if (amp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 		release_metapage(amp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 	if (bmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 		release_metapage(bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 	if (cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 		release_metapage(cmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393)  * NAME:	diNewIAG(imap,iagnop,agno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395)  * FUNCTION:	allocate a new iag for an allocation group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397)  *		first tries to allocate the iag from the inode map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398)  *		iagfree list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399)  *		if the list has free iags, the head of the list is removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400)  *		and returned to satisfy the request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401)  *		if the inode map's iag free list is empty, the inode map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402)  *		is extended to hold a new iag. this new iag is initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403)  *		and returned to satisfy the request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406)  *	imap	- pointer to inode map control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407)  *	iagnop	- pointer to an iag number set with the number of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408)  *		  newly allocated iag upon successful return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409)  *	agno	- allocation group number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410)  *	bpp	- Buffer pointer to be filled in with new IAG's buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413)  *	0	- success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414)  *	-ENOSPC	- insufficient disk resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417)  * serialization:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)  *	AG lock held on entry/exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)  *	write lock on the map is held inside;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)  *	read lock on the map is held on successful completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422)  * note: new iag transaction:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423)  * . synchronously write iag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424)  * . write log of xtree and inode of imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425)  * . commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426)  * . synchronous write of xtree (right to left, bottom to top);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427)  * . at start of logredo(): init in-memory imap with one additional iag page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428)  * . at end of logredo(): re-read imap inode to determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429)  *   new imap size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) diNewIAG(struct inomap * imap, int *iagnop, int agno, struct metapage ** mpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 	int iagno, i, xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 	struct inode *ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 	struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 	struct jfs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 	struct iag *iagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 	s64 xaddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 	s64 blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 	tid_t tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 	struct inode *iplist[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 	/* pick up pointers to the inode map and mount inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 	ipimap = imap->im_ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 	sb = ipimap->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 	sbi = JFS_SBI(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 	/* acquire the free iag lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 	IAGFREE_LOCK(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 	/* if there are any iags on the inode map free iag list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 	 * allocate the iag from the head of the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 	if (imap->im_freeiag >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 		/* pick up the iag number at the head of the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 		iagno = imap->im_freeiag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 		/* determine the logical block number of the iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 		blkno = IAGTOLBLK(iagno, sbi->l2nbperpage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 		/* no free iags. the inode map will have to be extented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 		 * to include a new iag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 		/* acquire inode map lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 		IWRITE_LOCK(ipimap, RDWRLOCK_IMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 		if (ipimap->i_size >> L2PSIZE != imap->im_nextiag + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 			IWRITE_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 			IAGFREE_UNLOCK(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 			jfs_error(imap->im_ipimap->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 				  "ipimap->i_size is wrong\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 		/* get the next available iag number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 		iagno = imap->im_nextiag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 		/* make sure that we have not exceeded the maximum inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 		 * number limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 		if (iagno > (MAXIAGS - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 			/* release the inode map lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 			IWRITE_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 			rc = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 		 * synchronously append new iag page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 		/* determine the logical address of iag page to append */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 		blkno = IAGTOLBLK(iagno, sbi->l2nbperpage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 		/* Allocate extent for new iag page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 		xlen = sbi->nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 		if ((rc = dbAlloc(ipimap, 0, (s64) xlen, &xaddr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 			/* release the inode map lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 			IWRITE_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 		 * start transaction of update of the inode map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 		 * addressing structure pointing to the new iag page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 		tid = txBegin(sb, COMMIT_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 		mutex_lock(&JFS_IP(ipimap)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 		/* update the inode map addressing structure to point to it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 		if ((rc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 		     xtInsert(tid, ipimap, 0, blkno, xlen, &xaddr, 0))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 			txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 			mutex_unlock(&JFS_IP(ipimap)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 			/* Free the blocks allocated for the iag since it was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 			 * not successfully added to the inode map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 			dbFree(ipimap, xaddr, (s64) xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 			/* release the inode map lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 			IWRITE_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 		/* update the inode map's inode to reflect the extension */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 		ipimap->i_size += PSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 		inode_add_bytes(ipimap, PSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 		/* assign a buffer for the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 		mp = get_metapage(ipimap, blkno, PSIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 		if (!mp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 			 * This is very unlikely since we just created the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 			 * extent, but let's try to handle it correctly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 			xtTruncate(tid, ipimap, ipimap->i_size - PSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 				   COMMIT_PWMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 			txAbort(tid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 			txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 			mutex_unlock(&JFS_IP(ipimap)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 			/* release the inode map lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 			IWRITE_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 		iagp = (struct iag *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 		/* init the iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 		memset(iagp, 0, sizeof(struct iag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 		iagp->iagnum = cpu_to_le32(iagno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 		iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 		iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 		iagp->iagfree = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 		iagp->nfreeinos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 		iagp->nfreeexts = cpu_to_le32(EXTSPERIAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 		/* initialize the free inode summary map (free extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 		 * summary map initialization handled by bzero).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 		for (i = 0; i < SMAPSZ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 			iagp->inosmap[i] = cpu_to_le32(ONES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 		 * Write and sync the metapage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 		flush_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 		 * txCommit(COMMIT_FORCE) will synchronously write address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 		 * index pages and inode after commit in careful update order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 		 * of address index pages (right to left, bottom up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 		iplist[0] = ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 		rc = txCommit(tid, 1, &iplist[0], COMMIT_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 		txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 		mutex_unlock(&JFS_IP(ipimap)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 		duplicateIXtree(sb, blkno, xlen, &xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 		/* update the next available iag number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 		imap->im_nextiag += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 		/* Add the iag to the iag free list so we don't lose the iag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 		 * if a failure happens now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 		imap->im_freeiag = iagno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 		/* Until we have logredo working, we want the imap inode &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 		 * control page to be up to date.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 		diSync(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 		/* release the inode map lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 		IWRITE_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 	/* obtain read lock on map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 	IREAD_LOCK(ipimap, RDWRLOCK_IMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 	/* read the iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 	if ((rc = diIAGRead(imap, iagno, &mp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 		IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 	iagp = (struct iag *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 	/* remove the iag from the iag free list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 	imap->im_freeiag = le32_to_cpu(iagp->iagfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 	iagp->iagfree = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 	/* set the return iag number and buffer pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 	*iagnop = iagno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 	*mpp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627)       out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	/* release the iag free lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 	IAGFREE_UNLOCK(imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 	return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)  * NAME:	diIAGRead()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637)  * FUNCTION:	get the buffer for the specified iag within a fileset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638)  *		or aggregate inode map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641)  *	imap	- pointer to inode map control structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642)  *	iagno	- iag number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643)  *	bpp	- point to buffer pointer to be filled in on successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644)  *		  exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)  * SERIALIZATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647)  *	must have read lock on imap inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648)  *	(When called by diExtendFS, the filesystem is quiesced, therefore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649)  *	 the read lock is unnecessary.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652)  *	0	- success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653)  *	-EIO	- i/o error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) static int diIAGRead(struct inomap * imap, int iagno, struct metapage ** mpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 	struct inode *ipimap = imap->im_ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 	s64 blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 	/* compute the logical block number of the iag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 	blkno = IAGTOLBLK(iagno, JFS_SBI(ipimap->i_sb)->l2nbperpage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 	/* read the iag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 	*mpp = read_metapage(ipimap, blkno, PSIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 	if (*mpp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)  * NAME:	diFindFree()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675)  * FUNCTION:	find the first free bit in a word starting at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676)  *		the specified bit position.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679)  *	word	- word to be examined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680)  *	start	- starting bit position.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683)  *	bit position of first free bit in the word or 32 if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684)  *	no free bits were found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) static int diFindFree(u32 word, int start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 	int bitno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 	assert(start < 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 	/* scan the word for the first free bit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 	for (word <<= start, bitno = start; bitno < 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 	     bitno++, word <<= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 		if ((word & HIGHORDER) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 	return (bitno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700)  * NAME:	diUpdatePMap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702)  * FUNCTION: Update the persistent map in an IAG for the allocation or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703)  *	freeing of the specified inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705)  * PRE CONDITIONS: Working map has already been updated for allocate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707)  * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708)  *	ipimap	- Incore inode map inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709)  *	inum	- Number of inode to mark in permanent map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710)  *	is_free	- If 'true' indicates inode should be marked freed, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711)  *		  indicates inode should be marked allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714)  *		0 for success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) diUpdatePMap(struct inode *ipimap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 	     unsigned long inum, bool is_free, struct tblock * tblk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 	struct iag *iagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 	struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 	int iagno, ino, extno, bitno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 	struct inomap *imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 	u32 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 	struct jfs_log *log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 	int lsn, difft, diffp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 	imap = JFS_IP(ipimap)->i_imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 	/* get the iag number containing the inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 	iagno = INOTOIAG(inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	/* make sure that the iag is contained within the map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 	if (iagno >= imap->im_nextiag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 		jfs_error(ipimap->i_sb, "the iag is outside the map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 	/* read the iag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 	IREAD_LOCK(ipimap, RDWRLOCK_IMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 	rc = diIAGRead(imap, iagno, &mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 	IREAD_UNLOCK(ipimap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 		return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 	metapage_wait_for_io(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 	iagp = (struct iag *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 	/* get the inode number and extent number of the inode within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 	 * the iag and the inode number within the extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 	ino = inum & (INOSPERIAG - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 	extno = ino >> L2INOSPEREXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 	bitno = ino & (INOSPEREXT - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 	mask = HIGHORDER >> bitno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 	 * mark the inode free in persistent map:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 	if (is_free) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 		/* The inode should have been allocated both in working
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 		 * map and in persistent map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 		 * the inode will be freed from working map at the release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 		 * of last reference release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 		if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 			jfs_error(ipimap->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 				  "inode %ld not marked as allocated in wmap!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 				  inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 		if (!(le32_to_cpu(iagp->pmap[extno]) & mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 			jfs_error(ipimap->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 				  "inode %ld not marked as allocated in pmap!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 				  inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 		/* update the bitmap for the extent of the freed inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 		iagp->pmap[extno] &= cpu_to_le32(~mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 	 * mark the inode allocated in persistent map:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 		/* The inode should be already allocated in the working map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 		 * and should be free in persistent map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 		if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 			release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 			jfs_error(ipimap->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 				  "the inode is not allocated in the working map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 		if ((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 			release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 			jfs_error(ipimap->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 				  "the inode is not free in the persistent map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 		/* update the bitmap for the extent of the allocated inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 		iagp->pmap[extno] |= cpu_to_le32(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 	 * update iag lsn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 	lsn = tblk->lsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 	log = JFS_SBI(tblk->sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 	LOGSYNC_LOCK(log, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 	if (mp->lsn != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 		/* inherit older/smaller lsn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 		logdiff(difft, lsn, log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 		logdiff(diffp, mp->lsn, log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 		if (difft < diffp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 			mp->lsn = lsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 			/* move mp after tblock in logsync list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 			list_move(&mp->synclist, &tblk->synclist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 		/* inherit younger/larger clsn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 		assert(mp->clsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 		logdiff(difft, tblk->clsn, log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 		logdiff(diffp, mp->clsn, log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 		if (difft > diffp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 			mp->clsn = tblk->clsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 		mp->log = log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 		mp->lsn = lsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 		/* insert mp after tblock in logsync list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 		log->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 		list_add(&mp->synclist, &tblk->synclist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 		mp->clsn = tblk->clsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	LOGSYNC_UNLOCK(log, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 	write_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832)  *	diExtendFS()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834)  * function: update imap for extendfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836)  * note: AG size has been increased s.t. each k old contiguous AGs are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837)  * coalesced into a new AG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) int diExtendFS(struct inode *ipimap, struct inode *ipbmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 	int rc, rcx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 	struct inomap *imap = JFS_IP(ipimap)->i_imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 	struct iag *iagp = NULL, *hiagp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 	struct bmap *mp = JFS_SBI(ipbmap->i_sb)->bmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 	struct metapage *bp, *hbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 	int i, n, head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 	int numinos, xnuminos = 0, xnumfree = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 	s64 agstart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 	jfs_info("diExtendFS: nextiag:%d numinos:%d numfree:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 		   imap->im_nextiag, atomic_read(&imap->im_numinos),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 		   atomic_read(&imap->im_numfree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 	 *	reconstruct imap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 	 * coalesce contiguous k (newAGSize/oldAGSize) AGs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 	 * i.e., (AGi, ..., AGj) where i = k*n and j = k*(n+1) - 1 to AGn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 	 * note: new AG size = old AG size * (2**x).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 	/* init per AG control information im_agctl[] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 	for (i = 0; i < MAXAG; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 		imap->im_agctl[i].inofree = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 		imap->im_agctl[i].extfree = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) 		imap->im_agctl[i].numinos = 0;	/* number of backed inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 		imap->im_agctl[i].numfree = 0;	/* number of free backed inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 	 *	process each iag page of the map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 	 * rebuild AG Free Inode List, AG Free Inode Extent List;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 	for (i = 0; i < imap->im_nextiag; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 		if ((rc = diIAGRead(imap, i, &bp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 			rcx = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 		iagp = (struct iag *) bp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 		if (le32_to_cpu(iagp->iagnum) != i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 			release_metapage(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 			jfs_error(ipimap->i_sb, "unexpected value of iagnum\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 		/* leave free iag in the free iag list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 		if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 			release_metapage(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 		agstart = le64_to_cpu(iagp->agstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 		n = agstart >> mp->db_agl2size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 		iagp->agstart = cpu_to_le64((s64)n << mp->db_agl2size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 		/* compute backed inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 		numinos = (EXTSPERIAG - le32_to_cpu(iagp->nfreeexts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 		    << L2INOSPEREXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 		if (numinos > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 			/* merge AG backed inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 			imap->im_agctl[n].numinos += numinos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 			xnuminos += numinos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 		/* if any backed free inodes, insert at AG free inode list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 		if ((int) le32_to_cpu(iagp->nfreeinos) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 			if ((head = imap->im_agctl[n].inofree) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 				iagp->inofreefwd = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 				iagp->inofreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 				if ((rc = diIAGRead(imap, head, &hbp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 					rcx = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 					goto nextiag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 				hiagp = (struct iag *) hbp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 				hiagp->inofreeback = iagp->iagnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) 				iagp->inofreefwd = cpu_to_le32(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 				iagp->inofreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 				write_metapage(hbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 			imap->im_agctl[n].inofree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 			    le32_to_cpu(iagp->iagnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 			/* merge AG backed free inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 			imap->im_agctl[n].numfree +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 			    le32_to_cpu(iagp->nfreeinos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 			xnumfree += le32_to_cpu(iagp->nfreeinos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 		/* if any free extents, insert at AG free extent list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 		if (le32_to_cpu(iagp->nfreeexts) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 			if ((head = imap->im_agctl[n].extfree) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 				iagp->extfreefwd = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 				iagp->extfreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 				if ((rc = diIAGRead(imap, head, &hbp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 					rcx = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 					goto nextiag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 				hiagp = (struct iag *) hbp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 				hiagp->extfreeback = iagp->iagnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 				iagp->extfreefwd = cpu_to_le32(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 				iagp->extfreeback = cpu_to_le32(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 				write_metapage(hbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 			imap->im_agctl[n].extfree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 			    le32_to_cpu(iagp->iagnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 	      nextiag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 		write_metapage(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 	if (xnuminos != atomic_read(&imap->im_numinos) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 	    xnumfree != atomic_read(&imap->im_numfree)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 		jfs_error(ipimap->i_sb, "numinos or numfree incorrect\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 	return rcx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968)  *	duplicateIXtree()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970)  * serialization: IWRITE_LOCK held on entry/exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972)  * note: shadow page with regular inode (rel.2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) static void duplicateIXtree(struct super_block *sb, s64 blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 			    int xlen, s64 *xaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 	struct jfs_superblock *j_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 	struct inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 	tid_t tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 	/* if AIT2 ipmap2 is bad, do not try to update it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 	if (JFS_SBI(sb)->mntflag & JFS_BAD_SAIT)	/* s_flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 	ip = diReadSpecial(sb, FILESYSTEM_I, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 	if (ip == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 		JFS_SBI(sb)->mntflag |= JFS_BAD_SAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 		if (readSuper(sb, &bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 		j_sb = (struct jfs_superblock *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 		j_sb->s_flag |= cpu_to_le32(JFS_BAD_SAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 		mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) 		sync_dirty_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 	/* start transaction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 	tid = txBegin(sb, COMMIT_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 	/* update the inode map addressing structure to point to it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 	if (xtInsert(tid, ip, 0, blkno, xlen, xaddr, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 		JFS_SBI(sb)->mntflag |= JFS_BAD_SAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 		txAbort(tid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 	/* update the inode map's inode to reflect the extension */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 	ip->i_size += PSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 	inode_add_bytes(ip, PSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 	txCommit(tid, 1, &ip, COMMIT_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012)       cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 	txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 	diFreeSpecial(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018)  * NAME:	copy_from_dinode()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020)  * FUNCTION:	Copies inode info from disk inode to in-memory inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022)  * RETURN VALUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023)  *	0	- success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024)  *	-ENOMEM	- insufficient memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) static int copy_from_dinode(struct dinode * dip, struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 	struct jfs_inode_info *jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 	struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 	jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 	jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 	jfs_set_inode_flags(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 	ip->i_mode = le32_to_cpu(dip->di_mode) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 	if (sbi->umask != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 		ip->i_mode = (ip->i_mode & ~0777) | (0777 & ~sbi->umask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 		/* For directories, add x permission if r is allowed by umask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 		if (S_ISDIR(ip->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 			if (ip->i_mode & 0400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 				ip->i_mode |= 0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 			if (ip->i_mode & 0040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 				ip->i_mode |= 0010;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 			if (ip->i_mode & 0004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 				ip->i_mode |= 0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 	set_nlink(ip, le32_to_cpu(dip->di_nlink));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 	jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 	if (!uid_valid(sbi->uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 		ip->i_uid = jfs_ip->saved_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 		ip->i_uid = sbi->uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 	jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 	if (!gid_valid(sbi->gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 		ip->i_gid = jfs_ip->saved_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 		ip->i_gid = sbi->gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 	ip->i_size = le64_to_cpu(dip->di_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 	ip->i_atime.tv_sec = le32_to_cpu(dip->di_atime.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 	ip->i_atime.tv_nsec = le32_to_cpu(dip->di_atime.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 	ip->i_mtime.tv_sec = le32_to_cpu(dip->di_mtime.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 	ip->i_mtime.tv_nsec = le32_to_cpu(dip->di_mtime.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 	ip->i_ctime.tv_sec = le32_to_cpu(dip->di_ctime.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 	ip->i_ctime.tv_nsec = le32_to_cpu(dip->di_ctime.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 	ip->i_blocks = LBLK2PBLK(ip->i_sb, le64_to_cpu(dip->di_nblocks));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 	ip->i_generation = le32_to_cpu(dip->di_gen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 	jfs_ip->ixpxd = dip->di_ixpxd;	/* in-memory pxd's are little-endian */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 	jfs_ip->acl = dip->di_acl;	/* as are dxd's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 	jfs_ip->ea = dip->di_ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 	jfs_ip->next_index = le32_to_cpu(dip->di_next_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 	jfs_ip->otime = le32_to_cpu(dip->di_otime.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 	jfs_ip->acltype = le32_to_cpu(dip->di_acltype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 	if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 		jfs_ip->dev = le32_to_cpu(dip->di_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 		ip->i_rdev = new_decode_dev(jfs_ip->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 	if (S_ISDIR(ip->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 		memcpy(&jfs_ip->i_dirtable, &dip->di_dirtable, 384);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 	} else if (S_ISREG(ip->i_mode) || S_ISLNK(ip->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 		memcpy(&jfs_ip->i_xtroot, &dip->di_xtroot, 288);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 		memcpy(&jfs_ip->i_inline_ea, &dip->di_inlineea, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 	/* Zero the in-memory-only stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 	jfs_ip->cflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 	jfs_ip->btindex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 	jfs_ip->btorder = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 	jfs_ip->bxflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 	jfs_ip->blid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 	jfs_ip->atlhead = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 	jfs_ip->atltail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 	jfs_ip->xtlid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106)  * NAME:	copy_to_dinode()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108)  * FUNCTION:	Copies inode info from in-memory inode to disk inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) static void copy_to_dinode(struct dinode * dip, struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 	struct jfs_inode_info *jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 	struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 	dip->di_fileset = cpu_to_le32(jfs_ip->fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 	dip->di_inostamp = cpu_to_le32(sbi->inostamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 	dip->di_number = cpu_to_le32(ip->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 	dip->di_gen = cpu_to_le32(ip->i_generation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 	dip->di_size = cpu_to_le64(ip->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 	dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 	dip->di_nlink = cpu_to_le32(ip->i_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 	if (!uid_valid(sbi->uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 		dip->di_uid = cpu_to_le32(i_uid_read(ip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 		dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 						   jfs_ip->saved_uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 	if (!gid_valid(sbi->gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 		dip->di_gid = cpu_to_le32(i_gid_read(ip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 		dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 						    jfs_ip->saved_gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 	 * mode2 is only needed for storing the higher order bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 	 * Trust i_mode for the lower order ones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 	if (sbi->umask == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 		dip->di_mode = cpu_to_le32((jfs_ip->mode2 & 0xffff0000) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 					   ip->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 	else /* Leave the original permissions alone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 		dip->di_mode = cpu_to_le32(jfs_ip->mode2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 	dip->di_atime.tv_sec = cpu_to_le32(ip->i_atime.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 	dip->di_atime.tv_nsec = cpu_to_le32(ip->i_atime.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 	dip->di_ctime.tv_sec = cpu_to_le32(ip->i_ctime.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 	dip->di_ctime.tv_nsec = cpu_to_le32(ip->i_ctime.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 	dip->di_mtime.tv_sec = cpu_to_le32(ip->i_mtime.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 	dip->di_mtime.tv_nsec = cpu_to_le32(ip->i_mtime.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 	dip->di_ixpxd = jfs_ip->ixpxd;	/* in-memory pxd's are little-endian */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 	dip->di_acl = jfs_ip->acl;	/* as are dxd's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 	dip->di_ea = jfs_ip->ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 	dip->di_next_index = cpu_to_le32(jfs_ip->next_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 	dip->di_otime.tv_sec = cpu_to_le32(jfs_ip->otime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 	dip->di_otime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 	dip->di_acltype = cpu_to_le32(jfs_ip->acltype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 	if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 		dip->di_rdev = cpu_to_le32(jfs_ip->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) }