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) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "jfs_incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "jfs_filsys.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "jfs_metapage.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "jfs_dinode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "jfs_imap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "jfs_dmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "jfs_superblock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "jfs_txnmgr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "jfs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define BITSPERPAGE	(PSIZE << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define L2MEGABYTE	20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define MEGABYTE	(1 << L2MEGABYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define MEGABYTE32	(MEGABYTE << 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* convert block number to bmap file page number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define BLKTODMAPN(b)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	(((b) >> 13) + ((b) >> 23) + ((b) >> 33) + 3 + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *	jfs_extendfs()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * function: extend file system;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *   |-------------------------------|----------|----------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *   file system space               fsck       inline log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *                                   workspace  space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *	new LVSize: in LV blocks (required)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *	new LogSize: in LV blocks (optional)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *	new FSSize: in LV blocks (optional)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * new configuration:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * 1. set new LogSize as specified or default from new LVSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * 2. compute new FSCKSize from new LVSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * 3. set new FSSize as MIN(FSSize, LVSize-(LogSize+FSCKSize)) where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *    assert(new FSSize >= old FSSize),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *    i.e., file system must not be shrunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) int jfs_extendfs(struct super_block *sb, s64 newLVSize, int newLogSize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct jfs_sb_info *sbi = JFS_SBI(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct inode *ipbmap = sbi->ipbmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct inode *ipbmap2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct inode *ipimap = sbi->ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct jfs_log *log = sbi->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct bmap *bmp = sbi->bmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	s64 newLogAddress, newFSCKAddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int newFSCKSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	s64 newMapSize = 0, mapSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	s64 XAddress, XSize, nblocks, xoff, xaddr, t64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	s64 oldLVSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	s64 newFSSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	s64 VolumeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	int newNpages = 0, nPages, newPage, xlen, t32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int log_formatted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct inode *iplist[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct jfs_superblock *j_sb, *j_sb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	s64 old_agsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int agsizechanged = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct buffer_head *bh, *bh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* If the volume hasn't grown, get out now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (sbi->mntflag & JFS_INLINELOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		oldLVSize = addressPXD(&sbi->logpxd) + lengthPXD(&sbi->logpxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		oldLVSize = addressPXD(&sbi->fsckpxd) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		    lengthPXD(&sbi->fsckpxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (oldLVSize >= newLVSize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		       "jfs_extendfs: volume hasn't grown, returning\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	VolumeSize = i_size_read(sb->s_bdev->bd_inode) >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (VolumeSize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if (newLVSize > VolumeSize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			printk(KERN_WARNING "jfs_extendfs: invalid size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		/* check the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		bh = sb_bread(sb, newLVSize - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			printk(KERN_WARNING "jfs_extendfs: invalid size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		bforget(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* Can't extend write-protected drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (isReadOnly(ipbmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		printk(KERN_WARNING "jfs_extendfs: read-only file system\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		rc = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 *	reconfigure LV spaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 *	---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * validate new size, or, if not specified, determine new size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * reconfigure inline log space:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if ((sbi->mntflag & JFS_INLINELOG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		if (newLogSize == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			 * no size specified: default to 1/256 of aggregate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			 * size; rounded up to a megabyte boundary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			newLogSize = newLVSize >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			t32 = (1 << (20 - sbi->l2bsize)) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			newLogSize = (newLogSize + t32) & ~t32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			newLogSize =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			    min(newLogSize, MEGABYTE32 >> sbi->l2bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			 * convert the newLogSize to fs blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			 * Since this is given in megabytes, it will always be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			 * an even number of pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			newLogSize = (newLogSize * MEGABYTE) >> sbi->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		newLogSize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	newLogAddress = newLVSize - newLogSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 * reconfigure fsck work space:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 * configure it to the end of the logical volume regardless of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	 * whether file system extends to the end of the aggregate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 * Need enough 4k pages to cover:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 *  - 1 bit per block in aggregate rounded up to BPERDMAP boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 *  - 1 extra page to handle control page and intermediate level pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 *  - 50 extra pages for the chkdsk service log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	t64 = ((newLVSize - newLogSize + BPERDMAP - 1) >> L2BPERDMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	    << L2BPERDMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	t32 = DIV_ROUND_UP(t64, BITSPERPAGE) + 1 + 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	newFSCKSize = t32 << sbi->l2nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	newFSCKAddress = newLogAddress - newFSCKSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	 * compute new file system space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	newFSSize = newLVSize - newLogSize - newFSCKSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	/* file system cannot be shrunk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (newFSSize < bmp->db_mapsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 * If we're expanding enough that the inline log does not overlap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 * the old one, we can format the new log before we quiesce the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 * filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if ((sbi->mntflag & JFS_INLINELOG) && (newLogAddress > oldLVSize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		if ((rc = lmLogFormat(log, newLogAddress, newLogSize)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		log_formatted = 1;
^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) 	 *	quiesce file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	 * (prepare to move the inline log and to prevent map update)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 * block any new transactions and wait for completion of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	 * all wip transactions and flush modified pages s.t.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	 * on-disk file system is in consistent state and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 * log is not required for recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	txQuiesce(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	/* Reset size of direct inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	sbi->direct_inode->i_size =  i_size_read(sb->s_bdev->bd_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (sbi->mntflag & JFS_INLINELOG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		 * deactivate old inline log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		lmLogShutdown(log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		 * mark on-disk super block for fs in transition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		 * update on-disk superblock for the new space configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		 * of inline log space and fsck work space descriptors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		 * N.B. FS descriptor is NOT updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		 * crash recovery:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		 * logredo(): if FM_EXTENDFS, return to fsck() for cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		 * fsck(): if FM_EXTENDFS, reformat inline log and fsck
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		 * workspace from superblock inline log descriptor and fsck
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		 * workspace descriptor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		/* read in superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		if ((rc = readSuper(sb, &bh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		j_sb = (struct jfs_superblock *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		/* mark extendfs() in progress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		j_sb->s_state |= cpu_to_le32(FM_EXTENDFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		j_sb->s_xsize = cpu_to_le64(newFSSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		PXDaddress(&j_sb->s_xfsckpxd, newFSCKAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		PXDlength(&j_sb->s_xfsckpxd, newFSCKSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		PXDaddress(&j_sb->s_xlogpxd, newLogAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		PXDlength(&j_sb->s_xlogpxd, newLogSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		/* synchronously update superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		sync_dirty_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		 * format new inline log synchronously;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		 * crash recovery: if log move in progress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		 * reformat log and exit success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		if (!log_formatted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			if ((rc = lmLogFormat(log, newLogAddress, newLogSize)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		 * activate new log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		log->base = newLogAddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		log->size = newLogSize >> (L2LOGPSIZE - sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		if ((rc = lmLogInit(log)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	 *	extend block allocation map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	 *	---------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	 * extendfs() for new extension, retry after crash recovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	 * note: both logredo() and fsck() rebuild map from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	 * the bitmap and configuration parameter from superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	 * (disregarding all other control information in the map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	 * superblock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	 *  s_size: aggregate size in physical blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 *	compute the new block allocation map configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 * map dinode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 *  di_size: map file size in byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	 *  di_nblocks: number of blocks allocated for map file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	 *  di_mapsize: number of blocks in aggregate (covered by map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	 * map control page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	 *  db_mapsize: number of blocks in aggregate (covered by map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	newMapSize = newFSSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	/* number of data pages of new bmap file:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	 * roundup new size to full dmap page boundary and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	 * add 1 extra dmap page for next extendfs()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	t64 = (newMapSize - 1) + BPERDMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	newNpages = BLKTODMAPN(t64) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	 *	extend map from current map (WITHOUT growing mapfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 * map new extension with unmapped part of the last partial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 * dmap page, if applicable, and extra page(s) allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	 * at end of bmap by mkfs() or previous extendfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)       extendBmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	/* compute number of blocks requested to extend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	mapSize = bmp->db_mapsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	XAddress = mapSize;	/* eXtension Address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	XSize = newMapSize - mapSize;	/* eXtension Size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	old_agsize = bmp->db_agsize;	/* We need to know if this changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	/* compute number of blocks that can be extended by current mapfile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	t64 = dbMapFileSizeToMapSize(ipbmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (mapSize > t64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		printk(KERN_ERR "jfs_extendfs: mapSize (0x%Lx) > t64 (0x%Lx)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		       (long long) mapSize, (long long) t64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	nblocks = min(t64 - mapSize, XSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	 * update map pages for new extension:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 * update/init dmap and bubble up the control hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	 * incrementally fold up dmaps into upper levels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	 * update bmap control page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if ((rc = dbExtendFS(ipbmap, XAddress, nblocks)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	agsizechanged |= (bmp->db_agsize != old_agsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	 * the map now has extended to cover additional nblocks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	 * dn_mapsize = oldMapsize + nblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	/* ipbmap->i_mapsize += nblocks; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	XSize -= nblocks;
^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) 	 *	grow map file to cover remaining extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	 *	and/or one extra dmap page for next extendfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	 * allocate new map pages and its backing blocks, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	 * update map file xtree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	/* compute number of data pages of current bmap file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	nPages = ipbmap->i_size >> L2PSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	/* need to grow map file ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (nPages == newNpages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		goto finalizeBmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	 * grow bmap file for the new map pages required:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	 * allocate growth at the start of newly extended region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	 * bmap file only grows sequentially, i.e., both data pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	 * and possibly xtree index pages may grow in append mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	 * s.t. logredo() can reconstruct pre-extension state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	 * by washing away bmap file of pages outside s_size boundary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	 * journal map file growth as if a regular file growth:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	 * (note: bmap is created with di_mode = IFJOURNAL|IFREG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	 * journaling of bmap file growth is not required since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	 * logredo() do/can not use log records of bmap file growth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	 * but it provides careful write semantics, pmap update, etc.;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	/* synchronous write of data pages: bmap data pages are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	 * cached in meta-data cache, and not written out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	 * by txCommit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	rc = filemap_fdatawait(ipbmap->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	rc = filemap_write_and_wait(ipbmap->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	diWriteSpecial(ipbmap, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	newPage = nPages;	/* first new page number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	xoff = newPage << sbi->l2nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	xlen = (newNpages - nPages) << sbi->l2nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	xlen = min(xlen, (int) nblocks) & ~(sbi->nbperpage - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	xaddr = XAddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	tid = txBegin(sb, COMMIT_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if ((rc = xtAppend(tid, ipbmap, 0, xoff, nblocks, &xlen, &xaddr, 0))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* update bmap file size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	ipbmap->i_size += xlen << sbi->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	inode_add_bytes(ipbmap, xlen << sbi->l2bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	iplist[0] = ipbmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	rc = txCommit(tid, 1, &iplist[0], COMMIT_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	 * map file has been grown now to cover extension to further out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	 * di_size = new map file size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	 * if huge extension, the previous extension based on previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	 * map file size may not have been sufficient to cover whole extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	 * (it could have been used up for new map pages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	 * but the newly grown map file now covers lot bigger new free space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	 * available for further extension of map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	/* any more blocks to extend ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (XSize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		goto extendBmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)       finalizeBmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	/* finalize bmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	dbFinalizeBmap(ipbmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	 *	update inode allocation map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	 *	---------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	 * move iag lists from old to new iag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	 * agstart field is not updated for logredo() to reconstruct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	 * iag lists if system crash occurs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	 * (computation of ag number from agstart based on agsize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	 * will correctly identify the new ag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	/* if new AG size the same as old AG size, done! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	if (agsizechanged) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		if ((rc = diExtendFS(ipimap, ipbmap)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		/* finalize imap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		if ((rc = diSync(ipimap)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	 *	finalize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	 *	--------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	 * extension is committed when on-disk super block is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	 * updated with new descriptors: logredo will recover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	 * crash before it to pre-extension state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	/* sync log to skip log replay of bmap file growth transaction; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	/* lmLogSync(log, 1); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	 * synchronous write bmap global control page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	 * for crash before completion of write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	 * logredo() will recover to pre-extendfs state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	 * for crash after completion of write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	 * logredo() will recover post-extendfs state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	if ((rc = dbSync(ipbmap)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	 * copy primary bmap inode to secondary bmap inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	ipbmap2 = diReadSpecial(sb, BMAP_I, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	if (ipbmap2 == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		printk(KERN_ERR "jfs_extendfs: diReadSpecial(bmap) failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	memcpy(&JFS_IP(ipbmap2)->i_xtroot, &JFS_IP(ipbmap)->i_xtroot, 288);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	ipbmap2->i_size = ipbmap->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	ipbmap2->i_blocks = ipbmap->i_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	diWriteSpecial(ipbmap2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	diFreeSpecial(ipbmap2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	 *	update superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	if ((rc = readSuper(sb, &bh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	j_sb = (struct jfs_superblock *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	/* mark extendfs() completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	j_sb->s_state &= cpu_to_le32(~FM_EXTENDFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	j_sb->s_size = cpu_to_le64(bmp->db_mapsize <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 				   le16_to_cpu(j_sb->s_l2bfactor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	j_sb->s_agsize = cpu_to_le32(bmp->db_agsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	/* update inline log space descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	if (sbi->mntflag & JFS_INLINELOG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		PXDaddress(&(j_sb->s_logpxd), newLogAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		PXDlength(&(j_sb->s_logpxd), newLogSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	/* record log's mount serial number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	j_sb->s_logserial = cpu_to_le32(log->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	/* update fsck work space descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	PXDaddress(&(j_sb->s_fsckpxd), newFSCKAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	PXDlength(&(j_sb->s_fsckpxd), newFSCKSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	j_sb->s_fscklog = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	/* sb->s_fsckloglen remains the same */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	/* Update secondary superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	bh2 = sb_bread(sb, SUPER2_OFF >> sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	if (bh2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		j_sb2 = (struct jfs_superblock *)bh2->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		memcpy(j_sb2, j_sb, sizeof (struct jfs_superblock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		sync_dirty_buffer(bh2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		brelse(bh2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	/* write primary superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	sync_dirty_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	goto resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)       error_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	jfs_error(sb, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)       resume:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	 *	resume file system transactions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	txResume(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)       out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }