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)  *   Portions Copyright (C) Christoph Hellwig, 2001-2002
^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) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/mpage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "jfs_incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "jfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "jfs_filsys.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "jfs_imap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "jfs_extent.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "jfs_unicode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "jfs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "jfs_dmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct inode *jfs_iget(struct super_block *sb, unsigned long ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	inode = iget_locked(sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (!(inode->i_state & I_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	ret = diRead(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		inode->i_op = &jfs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		inode->i_fop = &jfs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		inode->i_mapping->a_ops = &jfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	} else if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		inode->i_op = &jfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		inode->i_fop = &jfs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	} else if (S_ISLNK(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		if (inode->i_size >= IDATASIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			inode->i_op = &page_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			inode_nohighmem(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			inode->i_mapping->a_ops = &jfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			inode->i_op = &jfs_fast_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			inode->i_link = JFS_IP(inode)->i_inline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			 * The inline data should be null-terminated, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			 * don't let on-disk corruption crash the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			inode->i_link[inode->i_size] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		inode->i_op = &jfs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		init_special_inode(inode, inode->i_mode, inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * Workhorse of both fsync & write_inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) int jfs_commit_inode(struct inode *inode, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	tid_t tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	static int noisy = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	jfs_info("In jfs_commit_inode, inode = 0x%p", inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * Don't commit if inode has been committed since last being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 * marked dirty, or if it has been deleted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (inode->i_nlink == 0 || !test_cflag(COMMIT_Dirty, inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (isReadOnly(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		/* kernel allows writes to devices on read-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		 * partitions and may think inode is dirty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if (!special_file(inode->i_mode) && noisy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			jfs_err("jfs_commit_inode(0x%p) called on read-only volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 				inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			jfs_err("Is remount racy?");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			noisy--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	tid = txBegin(inode->i_sb, COMMIT_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	mutex_lock(&JFS_IP(inode)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 * Retest inode state after taking commit_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (inode->i_nlink && test_cflag(COMMIT_Dirty, inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		rc = txCommit(tid, 1, &inode, wait ? COMMIT_SYNC : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	mutex_unlock(&JFS_IP(inode)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int jfs_write_inode(struct inode *inode, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	int wait = wbc->sync_mode == WB_SYNC_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (inode->i_nlink == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 * If COMMIT_DIRTY is not set, the inode isn't really dirty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 * It has been committed since the last change, but was still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * on the dirty inode list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (!test_cflag(COMMIT_Dirty, inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		/* Make sure committed changes hit the disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		jfs_flush_journal(JFS_SBI(inode->i_sb)->log, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (jfs_commit_inode(inode, wait)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		jfs_err("jfs_write_inode: jfs_commit_inode failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) void jfs_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct jfs_inode_info *ji = JFS_IP(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	jfs_info("In jfs_evict_inode, inode = 0x%p", inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (!inode->i_nlink && !is_bad_inode(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		dquot_initialize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		if (JFS_IP(inode)->fileset == FILESYSTEM_I) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			if (test_cflag(COMMIT_Freewmap, inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				jfs_free_zero_link(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			if (JFS_SBI(inode->i_sb)->ipimap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				diFree(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			 * Free the inode from the quota allocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			dquot_free_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	dquot_drop(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	BUG_ON(!list_empty(&ji->anon_inode_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	spin_lock_irq(&ji->ag_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (ji->active_ag != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		atomic_dec(&bmap->db_active[ji->active_ag]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		ji->active_ag = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	spin_unlock_irq(&ji->ag_lock);
^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) void jfs_dirty_inode(struct inode *inode, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	static int noisy = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (isReadOnly(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		if (!special_file(inode->i_mode) && noisy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			/* kernel allows writes to devices on read-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			 * partitions and may try to mark inode dirty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			jfs_err("jfs_dirty_inode called on read-only volume");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			jfs_err("Is remount racy?");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			noisy--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return;
^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) 	set_cflag(COMMIT_Dirty, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int jfs_get_block(struct inode *ip, sector_t lblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		  struct buffer_head *bh_result, int create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	s64 lblock64 = lblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	xad_t xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	s64 xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	int xflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	s32 xlen = bh_result->b_size >> ip->i_blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	 * Take appropriate lock on inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		IWRITE_LOCK(ip, RDWRLOCK_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		IREAD_LOCK(ip, RDWRLOCK_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (((lblock64 << ip->i_sb->s_blocksize_bits) < ip->i_size) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	    (!xtLookup(ip, lblock64, xlen, &xflag, &xaddr, &xlen, 0)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	    xaddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		if (xflag & XAD_NOTRECORDED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			if (!create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				 * Allocated but not recorded, read treats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				 * this as a hole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #ifdef _JFS_4K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			XADoffset(&xad, lblock64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			XADlength(&xad, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			XADaddress(&xad, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #else				/* _JFS_4K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			 * As long as block size = 4K, this isn't a problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			 * We should mark the whole page not ABNR, but how
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			 * will we know to mark the other blocks BH_New?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #endif				/* _JFS_4K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			rc = extRecord(ip, &xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 				goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			set_buffer_new(bh_result);
^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) 		map_bh(bh_result, ip->i_sb, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		bh_result->b_size = xlen << ip->i_blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (!create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	 * Allocate a new block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #ifdef _JFS_4K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if ((rc = extHint(ip, lblock64 << ip->i_sb->s_blocksize_bits, &xad)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	rc = extAlloc(ip, xlen, lblock64, &xad, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	set_buffer_new(bh_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	map_bh(bh_result, ip->i_sb, addressXAD(&xad));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	bh_result->b_size = lengthXAD(&xad) << ip->i_blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #else				/* _JFS_4K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	 * We need to do whatever it takes to keep all but the last buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	 * in 4K pages - see jfs_write.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #endif				/* _JFS_4K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)       unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 * Release lock on inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		IWRITE_UNLOCK(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		IREAD_UNLOCK(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static int jfs_writepage(struct page *page, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	return block_write_full_page(page, jfs_get_block, wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int jfs_writepages(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return mpage_writepages(mapping, wbc, jfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static int jfs_readpage(struct file *file, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return mpage_readpage(page, jfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static void jfs_readahead(struct readahead_control *rac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	mpage_readahead(rac, jfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static void jfs_write_failed(struct address_space *mapping, loff_t to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (to > inode->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		truncate_pagecache(inode, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		jfs_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static int jfs_write_begin(struct file *file, struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 				loff_t pos, unsigned len, unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 				struct page **pagep, void **fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	ret = nobh_write_begin(mapping, pos, len, flags, pagep, fsdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 				jfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		jfs_write_failed(mapping, pos + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	return ret;
^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) static sector_t jfs_bmap(struct address_space *mapping, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	return generic_block_bmap(mapping, block, jfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static ssize_t jfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct file *file = iocb->ki_filp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct address_space *mapping = file->f_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	struct inode *inode = file->f_mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	size_t count = iov_iter_count(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	ret = blockdev_direct_IO(iocb, inode, iter, jfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 * In case of error extending write may have instantiated a few
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 * blocks outside i_size. Trim these off again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		loff_t isize = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		loff_t end = iocb->ki_pos + count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		if (end > isize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			jfs_write_failed(mapping, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	return ret;
^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) const struct address_space_operations jfs_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	.readpage	= jfs_readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	.readahead	= jfs_readahead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	.writepage	= jfs_writepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	.writepages	= jfs_writepages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	.write_begin	= jfs_write_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	.write_end	= nobh_write_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	.bmap		= jfs_bmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	.direct_IO	= jfs_direct_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) };
^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)  * Guts of jfs_truncate.  Called with locks already held.  Can be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * with directory for truncating directory index table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) void jfs_truncate_nolock(struct inode *ip, loff_t length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	loff_t newsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	tid_t tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	ASSERT(length >= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	if (test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		xtTruncate(0, ip, length, COMMIT_WMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		tid = txBegin(ip->i_sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		 * The commit_mutex cannot be taken before txBegin.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		 * txBegin may block and there is a chance the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		 * could be marked dirty and need to be committed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		 * before txBegin unblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		mutex_lock(&JFS_IP(ip)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		newsize = xtTruncate(tid, ip, length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 				     COMMIT_TRUNCATE | COMMIT_PWMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		if (newsize < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 			mutex_unlock(&JFS_IP(ip)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			break;
^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) 		ip->i_mtime = ip->i_ctime = current_time(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		mark_inode_dirty(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		txCommit(tid, 1, &ip, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		mutex_unlock(&JFS_IP(ip)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	} while (newsize > length);	/* Truncate isn't always atomic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) void jfs_truncate(struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	jfs_info("jfs_truncate: size = 0x%lx", (ulong) ip->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	nobh_truncate_page(ip->i_mapping, ip->i_size, jfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	IWRITE_LOCK(ip, RDWRLOCK_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	jfs_truncate_nolock(ip, ip->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	IWRITE_UNLOCK(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }