Commit 8875527c authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] BKL shifted into ->truncate()

	BKL shifted into all instances of ->truncate().  Callers updated.
parent 22d2d0d2
......@@ -19,7 +19,7 @@ Declare
/* fs-private stuff */
struct inode vfs_inode;
};
static inline FOO_I(struct inode *inode)
static inline struct foo_inode_info *FOO_I(struct inode *inode)
{
return list_entry(inode, struct foo_inode_info, vfs_inode);
}
......@@ -84,3 +84,8 @@ can relax your locking.
- that will guarantee the same locking you used to have. If your ->lookup()
or its parts do not need BKL - better yet, now you can shift lock_kernel()/
unlock_kernel() so that they would protect exactly what needs to be protected.
---
[mandatory]
->truncate() is called without BKL now (same as above).
......@@ -807,6 +807,7 @@ affs_truncate(struct inode *inode)
pr_debug("AFFS: truncate(inode=%d, size=%u)\n", (u32)inode->i_ino, (u32)inode->i_size);
lock_kernel();
last_blk = 0;
ext = 0;
if (inode->i_size) {
......@@ -821,8 +822,10 @@ affs_truncate(struct inode *inode)
int res;
page = grab_cache_page(mapping, size >> PAGE_CACHE_SHIFT);
if (!page)
if (!page) {
unlock_kernel();
return;
}
size = (size & (PAGE_CACHE_SIZE - 1)) + 1;
res = mapping->a_ops->prepare_write(NULL, page, size, size);
if (!res)
......@@ -830,9 +833,12 @@ affs_truncate(struct inode *inode)
UnlockPage(page);
page_cache_release(page);
mark_inode_dirty(inode);
unlock_kernel();
return;
} else if (inode->i_size == AFFS_I(inode)->mmu_private)
} else if (inode->i_size == AFFS_I(inode)->mmu_private) {
unlock_kernel();
return;
}
// lock cache
ext_bh = affs_get_extblock(inode, ext);
......@@ -888,4 +894,5 @@ affs_truncate(struct inode *inode)
ext_key = be32_to_cpu(AFFS_TAIL(sb, ext_bh)->extension);
affs_brelse(ext_bh);
}
unlock_kernel();
}
......@@ -275,11 +275,11 @@ void
affs_delete_inode(struct inode *inode)
{
pr_debug("AFFS: delete_inode(ino=%lu, nlink=%u)\n", inode->i_ino, inode->i_nlink);
lock_kernel();
inode->i_size = 0;
if (S_ISREG(inode->i_mode))
affs_truncate(inode);
clear_inode(inode);
lock_kernel();
affs_free_block(inode->i_sb, inode->i_ino);
unlock_kernel();
}
......
......@@ -57,10 +57,10 @@ void ext2_delete_inode (struct inode * inode)
mark_inode_dirty(inode);
ext2_update_inode(inode, IS_SYNC(inode));
lock_kernel();
inode->i_size = 0;
if (inode->i_blocks)
ext2_truncate (inode);
lock_kernel();
ext2_free_inode (inode);
unlock_kernel();
......@@ -801,7 +801,6 @@ void ext2_truncate (struct inode * inode)
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
return;
unlock_kernel();
ext2_discard_prealloc(inode);
blocksize = inode->i_sb->s_blocksize;
......@@ -875,7 +874,6 @@ void ext2_truncate (struct inode * inode)
ext2_sync_inode (inode);
else
mark_inode_dirty(inode);
lock_kernel();
}
void ext2_read_inode (struct inode * inode)
......
......@@ -1848,11 +1848,14 @@ void ext3_truncate(struct inode * inode)
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
return;
lock_kernel();
ext3_discard_prealloc(inode);
handle = start_transaction(inode);
if (IS_ERR(handle))
if (IS_ERR(handle)) {
unlock_kernel();
return; /* AKPM: return what? */
}
blocksize = inode->i_sb->s_blocksize;
last_block = (inode->i_size + blocksize-1)
......@@ -1974,6 +1977,7 @@ void ext3_truncate(struct inode * inode)
ext3_orphan_del(handle, inode);
ext3_journal_stop(handle, inode);
unlock_kernel();
}
/*
......
......@@ -10,6 +10,7 @@
#include <linux/locks.h>
#include <linux/msdos_fs.h>
#include <linux/fat_cvf.h>
#include <linux/smp_lock.h>
#define PRINTK(x)
#define Printk(x) printk x
......@@ -119,8 +120,10 @@ void fat_truncate(struct inode *inode)
if (MSDOS_I(inode)->mmu_private > inode->i_size)
MSDOS_I(inode)->mmu_private = inode->i_size;
lock_kernel();
fat_free(inode, (inode->i_size + (cluster - 1)) >> sbi->cluster_bits);
MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
unlock_kernel();
inode->i_ctime = inode->i_mtime = CURRENT_TIME;
mark_inode_dirty(inode);
}
......@@ -147,10 +147,8 @@ struct inode *fat_build_inode(struct super_block *sb,
void fat_delete_inode(struct inode *inode)
{
if (!is_bad_inode(inode)) {
lock_kernel();
inode->i_size = 0;
fat_truncate(inode);
unlock_kernel();
}
clear_inode(inode);
}
......
......@@ -20,6 +20,7 @@
#include <linux/hfs_fs_sb.h>
#include <linux/hfs_fs_i.h>
#include <linux/hfs_fs.h>
#include <linux/smp_lock.h>
/*================ Forward declarations ================*/
......@@ -223,8 +224,10 @@ static hfs_rwret_t hfs_file_write(struct file * filp, const char * buf,
*/
static void hfs_file_truncate(struct inode * inode)
{
struct hfs_fork *fork = HFS_I(inode)->fork;
struct hfs_fork *fork;
lock_kernel();
fork = HFS_I(inode)->fork;
fork->lsize = inode->i_size;
hfs_extent_adj(fork);
hfs_cat_mark_dirty(HFS_I(inode)->entry);
......@@ -232,6 +235,7 @@ static void hfs_file_truncate(struct inode * inode)
inode->i_size = fork->lsize;
inode->i_blocks = fork->psize;
mark_inode_dirty(inode);
unlock_kernel();
}
/*
......
......@@ -62,11 +62,14 @@ secno hpfs_bmap(struct inode *inode, unsigned file_secno)
void hpfs_truncate(struct inode *i)
{
if (IS_IMMUTABLE(i)) return /*-EPERM*/;
lock_kernel();
hpfs_i(i)->i_n_secs = 0;
i->i_blocks = 1 + ((i->i_size + 511) >> 9);
hpfs_i(i)->mmu_private = i->i_size;
hpfs_truncate_btree(i->i_sb, i->i_ino, 1, ((i->i_size + 511) >> 9));
hpfs_write_inode(i);
hpfs_i(i)->i_n_secs = 0;
unlock_kernel();
}
int hpfs_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create)
......
......@@ -27,12 +27,10 @@ static int minix_remount (struct super_block * sb, int * flags, char * data);
static void minix_delete_inode(struct inode *inode)
{
lock_kernel();
inode->i_size = 0;
minix_truncate(inode);
lock_kernel();
minix_free_inode(inode);
unlock_kernel();
}
......@@ -551,10 +549,12 @@ int minix_sync_inode(struct inode * inode)
*/
void minix_truncate(struct inode * inode)
{
lock_kernel();
if (INODE_VERSION(inode) == MINIX_V1)
V1_minix_truncate(inode);
else
V2_minix_truncate(inode);
unlock_kernel();
}
static struct super_block *minix_get_sb(struct file_system_type *fs_type,
......
......@@ -63,9 +63,9 @@ int qnx4_sync_inode(struct inode *inode)
static void qnx4_delete_inode(struct inode *inode)
{
QNX4DEBUG(("qnx4: deleting inode [%lu]\n", (unsigned long) inode->i_ino));
lock_kernel();
inode->i_size = 0;
qnx4_truncate(inode);
lock_kernel();
qnx4_free_inode(inode);
unlock_kernel();
}
......
......@@ -16,6 +16,7 @@
#include <linux/fs.h>
#include <linux/qnx4_fs.h>
#include <linux/locks.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#ifdef CONFIG_QNX4FS_RW
......@@ -26,12 +27,14 @@ void qnx4_truncate(struct inode *inode)
S_ISLNK(inode->i_mode))) {
return;
}
lock_kernel();
if (!(S_ISDIR(inode->i_mode))) {
/* TODO */
}
QNX4DEBUG(("qnx4: qnx4_truncate called\n"));
inode->i_mtime = inode->i_ctime = CURRENT_TIME;
mark_inode_dirty(inode);
unlock_kernel();
}
#endif
......@@ -66,7 +66,9 @@ static int reiserfs_file_release (struct inode * inode, struct file * filp)
}
static void reiserfs_vfs_truncate_file(struct inode *inode) {
lock_kernel();
reiserfs_truncate_file(inode, 1) ;
unlock_kernel();
}
/* Sync a reiserfs file. */
......
......@@ -260,9 +260,9 @@ int sysv_sync_inode(struct inode * inode)
static void sysv_delete_inode(struct inode *inode)
{
lock_kernel();
inode->i_size = 0;
sysv_truncate(inode);
lock_kernel();
sysv_free_inode(inode);
unlock_kernel();
}
......
......@@ -371,6 +371,8 @@ void sysv_truncate (struct inode * inode)
if (n == 0)
return;
lock_kernel();
if (n == 1) {
free_data(inode, i_data+offsets[0], i_data + DIRECT);
goto do_indirects;
......@@ -409,6 +411,7 @@ void sysv_truncate (struct inode * inode)
sysv_sync_inode (inode);
else
mark_inode_dirty(inode);
unlock_kernel();
}
static int sysv_writepage(struct page *page)
......
......@@ -108,20 +108,19 @@ void udf_put_inode(struct inode * inode)
*/
void udf_delete_inode(struct inode * inode)
{
lock_kernel();
if (is_bad_inode(inode))
goto no_delete;
inode->i_size = 0;
udf_truncate(inode);
lock_kernel();
udf_update_inode(inode, IS_SYNC(inode));
udf_free_inode(inode);
unlock_kernel();
return;
no_delete:
unlock_kernel();
clear_inode(inode);
}
......@@ -858,6 +857,7 @@ void udf_truncate(struct inode * inode)
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
return;
lock_kernel();
if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_IN_ICB)
{
if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
......@@ -867,6 +867,7 @@ void udf_truncate(struct inode * inode)
if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_IN_ICB)
{
inode->i_size = UDF_I_LENALLOC(inode);
unlock_kernel();
return;
}
else
......@@ -899,6 +900,7 @@ void udf_truncate(struct inode * inode)
udf_sync_inode (inode);
else
mark_inode_dirty(inode);
unlock_kernel();
}
/*
......
......@@ -37,6 +37,7 @@
#include <linux/stat.h>
#include <linux/locks.h>
#include <linux/string.h>
#include <linux/smp_lock.h>
#include "swab.h"
#include "util.h"
......@@ -439,6 +440,7 @@ void ufs_truncate (struct inode * inode)
return;
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
return;
lock_kernel();
while (1) {
retry = ufs_trunc_direct(inode);
retry |= ufs_trunc_indirect (inode, UFS_IND_BLOCK,
......@@ -464,6 +466,7 @@ void ufs_truncate (struct inode * inode)
}
inode->i_mtime = inode->i_ctime = CURRENT_TIME;
ufsi->i_lastfrag = DIRECT_FRAGMENT;
unlock_kernel();
mark_inode_dirty(inode);
UFSD(("EXIT\n"))
}
......@@ -1048,11 +1048,8 @@ int vmtruncate(struct inode * inode, loff_t offset)
inode->i_size = offset;
out_truncate:
if (inode->i_op && inode->i_op->truncate) {
lock_kernel();
if (inode->i_op && inode->i_op->truncate)
inode->i_op->truncate(inode);
unlock_kernel();
}
out:
return 0;
}
......
......@@ -311,6 +311,7 @@ shmem_truncate_indirect(struct shmem_inode_info *info, unsigned long index)
return shmem_truncate_direct(base, start, len);
}
/* SMP-safe */
static void shmem_truncate (struct inode * inode)
{
unsigned long index;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment