11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   Copyright (C) International Business Machines Corp., 2000-2004
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   Portions Copyright (C) Christoph Hellwig, 2001-2002
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   This program is free software;  you can redistribute it and/or modify
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   it under the terms of the GNU General Public License as published by
763f83c9fcf40ab61b75edf5d2f2c1ae6bf876482Dave Kleikamp *   the Free Software Foundation; either version 2 of the License, or
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   (at your option) any later version.
963f83c9fcf40ab61b75edf5d2f2c1ae6bf876482Dave Kleikamp *
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   This program is distributed in the hope that it will be useful,
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   the GNU General Public License for more details.
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   You should have received a copy of the GNU General Public License
1663f83c9fcf40ab61b75edf5d2f2c1ae6bf876482Dave Kleikamp *   along with this program;  if not, write to the Free Software
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/fs.h>
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/mpage.h>
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/buffer_head.h>
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/pagemap.h>
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/quotaops.h>
25a9185b41a4f84971b930c519f0c63bd450c4810dChristoph Hellwig#include <linux/writeback.h>
26a27bb332c04cec8c4afd7912df0dc7890db27560Kent Overstreet#include <linux/aio.h>
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "jfs_incore.h"
281868f4aa5a4a72bbe0b7db6c1d4ee666824c3895Dave Kleikamp#include "jfs_inode.h"
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "jfs_filsys.h"
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "jfs_imap.h"
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "jfs_extent.h"
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "jfs_unicode.h"
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "jfs_debug.h"
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
36eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howellsstruct inode *jfs_iget(struct super_block *sb, unsigned long ino)
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
38eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells	struct inode *inode;
39eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells	int ret;
40eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells
41eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells	inode = iget_locked(sb, ino);
42eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells	if (!inode)
43eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells		return ERR_PTR(-ENOMEM);
44eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells	if (!(inode->i_state & I_NEW))
45eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells		return inode;
46eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells
47eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells	ret = diRead(inode);
48eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells	if (ret < 0) {
49eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells		iget_failed(inode);
50eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells		return ERR_PTR(ret);
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (S_ISREG(inode->i_mode)) {
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		inode->i_op = &jfs_file_inode_operations;
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		inode->i_fop = &jfs_file_operations;
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		inode->i_mapping->a_ops = &jfs_aops;
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} else if (S_ISDIR(inode->i_mode)) {
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		inode->i_op = &jfs_dir_inode_operations;
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		inode->i_fop = &jfs_dir_operations;
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} else if (S_ISLNK(inode->i_mode)) {
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (inode->i_size >= IDATASIZE) {
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			inode->i_op = &page_symlink_inode_operations;
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			inode->i_mapping->a_ops = &jfs_aops;
64d69e83d99cf87e3328c47bb54684360e32aef17dDave Kleikamp		} else {
65c7f2e1f0ac142a657a1de00d404e1c8345b20598Dmitry Monakhov			inode->i_op = &jfs_fast_symlink_inode_operations;
66d69e83d99cf87e3328c47bb54684360e32aef17dDave Kleikamp			/*
67d69e83d99cf87e3328c47bb54684360e32aef17dDave Kleikamp			 * The inline data should be null-terminated, but
68d69e83d99cf87e3328c47bb54684360e32aef17dDave Kleikamp			 * don't let on-disk corruption crash the kernel
69d69e83d99cf87e3328c47bb54684360e32aef17dDave Kleikamp			 */
70d69e83d99cf87e3328c47bb54684360e32aef17dDave Kleikamp			JFS_IP(inode)->i_inline[inode->i_size] = '\0';
71d69e83d99cf87e3328c47bb54684360e32aef17dDave Kleikamp		}
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} else {
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		inode->i_op = &jfs_file_inode_operations;
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		init_special_inode(inode, inode->i_mode, inode->i_rdev);
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
76eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells	unlock_new_inode(inode);
77eab1df71a0ef6d333b9b826deaa0d0eb4b4f69dcDavid Howells	return inode;
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Workhorse of both fsync & write_inode
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint jfs_commit_inode(struct inode *inode, int wait)
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int rc = 0;
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	tid_t tid;
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	static int noisy = 5;
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	jfs_info("In jfs_commit_inode, inode = 0x%p", inode);
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Don't commit if inode has been committed since last being
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * marked dirty, or if it has been deleted.
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (inode->i_nlink == 0 || !test_cflag(COMMIT_Dirty, inode))
961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return 0;
971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (isReadOnly(inode)) {
991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* kernel allows writes to devices on read-only
1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * partitions and may think inode is dirty
1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (!special_file(inode->i_mode) && noisy) {
1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			jfs_err("jfs_commit_inode(0x%p) called on "
1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				   "read-only volume", inode);
1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			jfs_err("Is remount racy?");
1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			noisy--;
1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return 0;
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	tid = txBegin(inode->i_sb, COMMIT_INODE);
1121de87444f8f91009b726108c9a56600645ee8751Ingo Molnar	mutex_lock(&JFS_IP(inode)->commit_mutex);
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
1151de87444f8f91009b726108c9a56600645ee8751Ingo Molnar	 * Retest inode state after taking commit_mutex
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (inode->i_nlink && test_cflag(COMMIT_Dirty, inode))
1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		rc = txCommit(tid, 1, &inode, wait ? COMMIT_SYNC : 0);
1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	txEnd(tid);
1211de87444f8f91009b726108c9a56600645ee8751Ingo Molnar	mutex_unlock(&JFS_IP(inode)->commit_mutex);
1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return rc;
1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
125a9185b41a4f84971b930c519f0c63bd450c4810dChristoph Hellwigint jfs_write_inode(struct inode *inode, struct writeback_control *wbc)
1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
127a9185b41a4f84971b930c519f0c63bd450c4810dChristoph Hellwig	int wait = wbc->sync_mode == WB_SYNC_ALL;
128a9185b41a4f84971b930c519f0c63bd450c4810dChristoph Hellwig
12973aaa22d5ffb2630456bac2f9a4ed9b81d0d7271Dave Kleikamp	if (inode->i_nlink == 0)
1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return 0;
1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * If COMMIT_DIRTY is not set, the inode isn't really dirty.
1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * It has been committed since the last change, but was still
1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * on the dirty inode list.
1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 if (!test_cflag(COMMIT_Dirty, inode)) {
1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* Make sure committed changes hit the disk */
1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		jfs_flush_journal(JFS_SBI(inode->i_sb)->log, wait);
1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return 0;
1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 }
1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (jfs_commit_inode(inode, wait)) {
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		jfs_err("jfs_write_inode: jfs_commit_inode failed!");
1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return -EIO;
1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} else
1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return 0;
1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
14962aff86fdf18657d9eca7878654415f94f16d027Al Virovoid jfs_evict_inode(struct inode *inode)
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
15162aff86fdf18657d9eca7878654415f94f16d027Al Viro	jfs_info("In jfs_evict_inode, inode = 0x%p", inode);
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
15362aff86fdf18657d9eca7878654415f94f16d027Al Viro	if (!inode->i_nlink && !is_bad_inode(inode)) {
154871a293155a24554e153538d36e3a80fa169aefbChristoph Hellwig		dquot_initialize(inode);
155907f4554e2521cb28b0009d17167760650a9561cChristoph Hellwig
15662aff86fdf18657d9eca7878654415f94f16d027Al Viro		if (JFS_IP(inode)->fileset == FILESYSTEM_I) {
15791b0abe36a7b2b3b02d7500925a5f8455334f0e5Johannes Weiner			truncate_inode_pages_final(&inode->i_data);
158fef266580e5cf897a1b63528fc6b1185e2d6bb87Mark Fasheh
15962aff86fdf18657d9eca7878654415f94f16d027Al Viro			if (test_cflag(COMMIT_Freewmap, inode))
16062aff86fdf18657d9eca7878654415f94f16d027Al Viro				jfs_free_zero_link(inode);
1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
16262aff86fdf18657d9eca7878654415f94f16d027Al Viro			diFree(inode);
1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
16462aff86fdf18657d9eca7878654415f94f16d027Al Viro			/*
16562aff86fdf18657d9eca7878654415f94f16d027Al Viro			 * Free the inode from the quota allocation.
16662aff86fdf18657d9eca7878654415f94f16d027Al Viro			 */
16762aff86fdf18657d9eca7878654415f94f16d027Al Viro			dquot_initialize(inode);
16862aff86fdf18657d9eca7878654415f94f16d027Al Viro			dquot_free_inode(inode);
16962aff86fdf18657d9eca7878654415f94f16d027Al Viro		}
17062aff86fdf18657d9eca7878654415f94f16d027Al Viro	} else {
17191b0abe36a7b2b3b02d7500925a5f8455334f0e5Johannes Weiner		truncate_inode_pages_final(&inode->i_data);
172b1b5d7f9b7ac6a8e3452ac43a53eebf69fdf5a77Dave Kleikamp	}
173dbd5768f87ff6fb0a4fe09c4d7b6c4a24de99430Jan Kara	clear_inode(inode);
17462aff86fdf18657d9eca7878654415f94f16d027Al Viro	dquot_drop(inode);
1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
177aa38572954ade525817fe88c54faebf85e5a61c0Christoph Hellwigvoid jfs_dirty_inode(struct inode *inode, int flags)
1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	static int noisy = 5;
1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (isReadOnly(inode)) {
1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (!special_file(inode->i_mode) && noisy) {
1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			/* kernel allows writes to devices on read-only
1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 * partitions and may try to mark inode dirty
1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 */
1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			jfs_err("jfs_dirty_inode called on read-only volume");
1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			jfs_err("Is remount racy?");
1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			noisy--;
1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return;
1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	set_cflag(COMMIT_Dirty, inode);
1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
196115ff50bade0f93a288677745a5884def6cbf9b1Dave Kleikampint jfs_get_block(struct inode *ip, sector_t lblock,
197115ff50bade0f93a288677745a5884def6cbf9b1Dave Kleikamp		  struct buffer_head *bh_result, int create)
1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	s64 lblock64 = lblock;
2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int rc = 0;
2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	xad_t xad;
2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	s64 xaddr;
2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int xflag;
204115ff50bade0f93a288677745a5884def6cbf9b1Dave Kleikamp	s32 xlen = bh_result->b_size >> ip->i_blkbits;
2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Take appropriate lock on inode
2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
2097fab479bebb96b1b4888bdae9b42e1fa9c5d3f38Dave Kleikamp	if (create)
21082d5b9a7c63054a9a2cd838ffd177697f86e7e34Dave Kleikamp		IWRITE_LOCK(ip, RDWRLOCK_NORMAL);
2117fab479bebb96b1b4888bdae9b42e1fa9c5d3f38Dave Kleikamp	else
21282d5b9a7c63054a9a2cd838ffd177697f86e7e34Dave Kleikamp		IREAD_LOCK(ip, RDWRLOCK_NORMAL);
2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (((lblock64 << ip->i_sb->s_blocksize_bits) < ip->i_size) &&
215115ff50bade0f93a288677745a5884def6cbf9b1Dave Kleikamp	    (!xtLookup(ip, lblock64, xlen, &xflag, &xaddr, &xlen, 0)) &&
2166628465e33ca694bd8fd5c3cf4eb7ff9177bc694Dave Kleikamp	    xaddr) {
2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (xflag & XAD_NOTRECORDED) {
2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			if (!create)
2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				/*
2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				 * Allocated but not recorded, read treats
2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				 * this as a hole
2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				 */
2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				goto unlock;
2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef _JFS_4K
2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			XADoffset(&xad, lblock64);
2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			XADlength(&xad, xlen);
2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			XADaddress(&xad, xaddr);
2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else				/* _JFS_4K */
2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			/*
2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 * As long as block size = 4K, this isn't a problem.
2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 * We should mark the whole page not ABNR, but how
2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 * will we know to mark the other blocks BH_New?
2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 */
2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			BUG();
2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif				/* _JFS_4K */
2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			rc = extRecord(ip, &xad);
2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			if (rc)
2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				goto unlock;
2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			set_buffer_new(bh_result);
2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		map_bh(bh_result, ip->i_sb, xaddr);
2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		bh_result->b_size = xlen << ip->i_blkbits;
2441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto unlock;
2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (!create)
2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto unlock;
2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Allocate a new block
2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef _JFS_4K
2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if ((rc = extHint(ip, lblock64 << ip->i_sb->s_blocksize_bits, &xad)))
2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto unlock;
2554d81715fc5dfa1680ad47d7edf3ac4a74c5bf104Richard Knutsson	rc = extAlloc(ip, xlen, lblock64, &xad, false);
2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (rc)
2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto unlock;
2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	set_buffer_new(bh_result);
2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	map_bh(bh_result, ip->i_sb, addressXAD(&xad));
2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	bh_result->b_size = lengthXAD(&xad) << ip->i_blkbits;
2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else				/* _JFS_4K */
2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * We need to do whatever it takes to keep all but the last buffers
2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * in 4K pages - see jfs_write.c
2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	BUG();
2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif				/* _JFS_4K */
2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds      unlock:
2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Release lock on inode
2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
2757fab479bebb96b1b4888bdae9b42e1fa9c5d3f38Dave Kleikamp	if (create)
2767fab479bebb96b1b4888bdae9b42e1fa9c5d3f38Dave Kleikamp		IWRITE_UNLOCK(ip);
2777fab479bebb96b1b4888bdae9b42e1fa9c5d3f38Dave Kleikamp	else
2787fab479bebb96b1b4888bdae9b42e1fa9c5d3f38Dave Kleikamp		IREAD_UNLOCK(ip);
2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return rc;
2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int jfs_writepage(struct page *page, struct writeback_control *wbc)
2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
284d5c5f84ba9b9138b03ba90f1b7f83a379cfaea6aNick Piggin	return block_write_full_page(page, jfs_get_block, wbc);
2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int jfs_writepages(struct address_space *mapping,
2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			struct writeback_control *wbc)
2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return mpage_writepages(mapping, wbc, jfs_get_block);
2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int jfs_readpage(struct file *file, struct page *page)
2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return mpage_readpage(page, jfs_get_block);
2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int jfs_readpages(struct file *file, struct address_space *mapping,
2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		struct list_head *pages, unsigned nr_pages)
3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return mpage_readpages(mapping, pages, nr_pages, jfs_get_block);
3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
30486dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornellistatic void jfs_write_failed(struct address_space *mapping, loff_t to)
30586dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli{
30686dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli	struct inode *inode = mapping->host;
30786dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli
30886dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli	if (to > inode->i_size) {
3097caef26767c1727d7abfbbbfbe8b2bb473430d48Kirill A. Shutemov		truncate_pagecache(inode, inode->i_size);
31086dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli		jfs_truncate(inode);
31186dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli	}
31286dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli}
31386dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli
314d5c5f84ba9b9138b03ba90f1b7f83a379cfaea6aNick Pigginstatic int jfs_write_begin(struct file *file, struct address_space *mapping,
315d5c5f84ba9b9138b03ba90f1b7f83a379cfaea6aNick Piggin				loff_t pos, unsigned len, unsigned flags,
316d5c5f84ba9b9138b03ba90f1b7f83a379cfaea6aNick Piggin				struct page **pagep, void **fsdata)
3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
318ea0f04e59543bafb3d2cbe37a0d375acb0bb2c34Christoph Hellwig	int ret;
319ea0f04e59543bafb3d2cbe37a0d375acb0bb2c34Christoph Hellwig
320ea0f04e59543bafb3d2cbe37a0d375acb0bb2c34Christoph Hellwig	ret = nobh_write_begin(mapping, pos, len, flags, pagep, fsdata,
321d5c5f84ba9b9138b03ba90f1b7f83a379cfaea6aNick Piggin				jfs_get_block);
32286dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli	if (unlikely(ret))
32386dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli		jfs_write_failed(mapping, pos + len);
324ea0f04e59543bafb3d2cbe37a0d375acb0bb2c34Christoph Hellwig
325ea0f04e59543bafb3d2cbe37a0d375acb0bb2c34Christoph Hellwig	return ret;
3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic sector_t jfs_bmap(struct address_space *mapping, sector_t block)
3291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return generic_block_bmap(mapping, block, jfs_get_block);
3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t jfs_direct_IO(int rw, struct kiocb *iocb,
334d8d3d94b80aa1a1c0ca75c58b8abdc7356f38418Al Viro	struct iov_iter *iter, loff_t offset)
3351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
3361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct file *file = iocb->ki_filp;
33786dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli	struct address_space *mapping = file->f_mapping;
3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct inode *inode = file->f_mapping->host;
339a6cbcd4a4a85e2fdb0b3344b88df2e8b3d526b9eAl Viro	size_t count = iov_iter_count(iter);
340eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig	ssize_t ret;
3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
34231b140398ce56ab41646eda7f02bcb78d6a4c916Al Viro	ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, jfs_get_block);
343eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig
344eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig	/*
345eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig	 * In case of error extending write may have instantiated a few
346eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig	 * blocks outside i_size. Trim these off again.
347eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig	 */
348eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig	if (unlikely((rw & WRITE) && ret < 0)) {
349eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig		loff_t isize = i_size_read(inode);
350a6cbcd4a4a85e2fdb0b3344b88df2e8b3d526b9eAl Viro		loff_t end = offset + count;
351eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig
352eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig		if (end > isize)
35386dd07d66a2f7284cfe2b771d062dd6c0e331766Marco Stornelli			jfs_write_failed(mapping, end);
354eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig	}
355eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig
356eafdc7d190a944c755a9fe68573c193e6e0217e7Christoph Hellwig	return ret;
3571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
359f5e54d6e53a20cef45af7499e86164f0e0d16bb2Christoph Hellwigconst struct address_space_operations jfs_aops = {
3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.readpage	= jfs_readpage,
3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.readpages	= jfs_readpages,
3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.writepage	= jfs_writepage,
3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.writepages	= jfs_writepages,
364d5c5f84ba9b9138b03ba90f1b7f83a379cfaea6aNick Piggin	.write_begin	= jfs_write_begin,
36503158cd7eb3374843de68421142ca5900df845d9Nick Piggin	.write_end	= nobh_write_end,
3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.bmap		= jfs_bmap,
3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.direct_IO	= jfs_direct_IO,
3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Guts of jfs_truncate.  Called with locks already held.  Can be called
3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * with directory for truncating directory index table.
3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid jfs_truncate_nolock(struct inode *ip, loff_t length)
3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
3761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	loff_t newsize;
3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	tid_t tid;
3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ASSERT(length >= 0);
3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (test_cflag(COMMIT_Nolink, ip)) {
3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		xtTruncate(0, ip, length, COMMIT_WMAP);
3831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return;
3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	do {
3871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		tid = txBegin(ip->i_sb, 0);
3881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
3901de87444f8f91009b726108c9a56600645ee8751Ingo Molnar		 * The commit_mutex cannot be taken before txBegin.
3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * txBegin may block and there is a chance the inode
3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * could be marked dirty and need to be committed
3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * before txBegin unblocks
3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
3951de87444f8f91009b726108c9a56600645ee8751Ingo Molnar		mutex_lock(&JFS_IP(ip)->commit_mutex);
3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		newsize = xtTruncate(tid, ip, length,
3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				     COMMIT_TRUNCATE | COMMIT_PWMAP);
3991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (newsize < 0) {
4001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			txEnd(tid);
4011de87444f8f91009b726108c9a56600645ee8751Ingo Molnar			mutex_unlock(&JFS_IP(ip)->commit_mutex);
4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			break;
4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ip->i_mtime = ip->i_ctime = CURRENT_TIME;
4061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		mark_inode_dirty(ip);
4071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		txCommit(tid, 1, &ip, 0);
4091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		txEnd(tid);
4101de87444f8f91009b726108c9a56600645ee8751Ingo Molnar		mutex_unlock(&JFS_IP(ip)->commit_mutex);
4111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} while (newsize > length);	/* Truncate isn't always atomic */
4121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
4131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid jfs_truncate(struct inode *ip)
4151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
4161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	jfs_info("jfs_truncate: size = 0x%lx", (ulong) ip->i_size);
4171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
41803158cd7eb3374843de68421142ca5900df845d9Nick Piggin	nobh_truncate_page(ip->i_mapping, ip->i_size, jfs_get_block);
4191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
42082d5b9a7c63054a9a2cd838ffd177697f86e7e34Dave Kleikamp	IWRITE_LOCK(ip, RDWRLOCK_NORMAL);
4211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	jfs_truncate_nolock(ip, ip->i_size);
4221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	IWRITE_UNLOCK(ip);
4231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
424