Skip to content

Commit 9746151

Browse files
Arjan van de VenLinus Torvalds
authored andcommitted
[PATCH] convert ext3's truncate_sem to a mutex
ext3's truncate_sem is always released in the same function it's taken and it otherwise is a mutex as well.. Signed-off-by: Arjan van de Ven <arjan@infradead.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 7bf6d78 commit 9746151

5 files changed

Lines changed: 16 additions & 15 deletions

File tree

‎fs/ext3/file.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ static int ext3_release_file (struct inode * inode, struct file * filp)
3737
if ((filp->f_mode & FMODE_WRITE) &&
3838
(atomic_read(&inode->i_writecount) == 1))
3939
{
40-
down(&EXT3_I(inode)->truncate_sem);
40+
mutex_lock(&EXT3_I(inode)->truncate_mutex);
4141
ext3_discard_reservation(inode);
42-
up(&EXT3_I(inode)->truncate_sem);
42+
mutex_unlock(&EXT3_I(inode)->truncate_mutex);
4343
}
4444
if (is_dx(inode) && filp->private_data)
4545
ext3_htree_free_dir_info(filp->private_data);

‎fs/ext3/inode.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ ext3_get_block_handle(handle_t *handle, struct inode *inode, sector_t iblock,
702702
if (!create || err == -EIO)
703703
goto cleanup;
704704

705-
down(&ei->truncate_sem);
705+
mutex_lock(&ei->truncate_mutex);
706706

707707
/*
708708
* If the indirect block is missing while we are reading
@@ -723,7 +723,7 @@ ext3_get_block_handle(handle_t *handle, struct inode *inode, sector_t iblock,
723723
}
724724
partial = ext3_get_branch(inode, depth, offsets, chain, &err);
725725
if (!partial) {
726-
up(&ei->truncate_sem);
726+
mutex_unlock(&ei->truncate_mutex);
727727
if (err)
728728
goto cleanup;
729729
clear_buffer_new(bh_result);
@@ -759,13 +759,13 @@ ext3_get_block_handle(handle_t *handle, struct inode *inode, sector_t iblock,
759759
err = ext3_splice_branch(handle, inode, iblock, chain,
760760
partial, left);
761761
/*
762-
* i_disksize growing is protected by truncate_sem. Don't forget to
762+
* i_disksize growing is protected by truncate_mutex. Don't forget to
763763
* protect it if you're about to implement concurrent
764764
* ext3_get_block() -bzzz
765765
*/
766766
if (!err && extend_disksize && inode->i_size > ei->i_disksize)
767767
ei->i_disksize = inode->i_size;
768-
up(&ei->truncate_sem);
768+
mutex_unlock(&ei->truncate_mutex);
769769
if (err)
770770
goto cleanup;
771771

@@ -1227,7 +1227,7 @@ static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)
12271227
* ext3_file_write() -> generic_file_write() -> __alloc_pages() -> ...
12281228
*
12291229
* Same applies to ext3_get_block(). We will deadlock on various things like
1230-
* lock_journal and i_truncate_sem.
1230+
* lock_journal and i_truncate_mutex.
12311231
*
12321232
* Setting PF_MEMALLOC here doesn't work - too many internal memory
12331233
* allocations fail.
@@ -2161,7 +2161,7 @@ void ext3_truncate(struct inode * inode)
21612161
* From here we block out all ext3_get_block() callers who want to
21622162
* modify the block allocation tree.
21632163
*/
2164-
down(&ei->truncate_sem);
2164+
mutex_lock(&ei->truncate_mutex);
21652165

21662166
if (n == 1) { /* direct blocks */
21672167
ext3_free_data(handle, inode, NULL, i_data+offsets[0],
@@ -2228,7 +2228,7 @@ void ext3_truncate(struct inode * inode)
22282228

22292229
ext3_discard_reservation(inode);
22302230

2231-
up(&ei->truncate_sem);
2231+
mutex_unlock(&ei->truncate_mutex);
22322232
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
22332233
ext3_mark_inode_dirty(handle, inode);
22342234

‎fs/ext3/ioctl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
182182
* need to allocate reservation structure for this inode
183183
* before set the window size
184184
*/
185-
down(&ei->truncate_sem);
185+
mutex_lock(&ei->truncate_mutex);
186186
if (!ei->i_block_alloc_info)
187187
ext3_init_block_alloc_info(inode);
188188

189189
if (ei->i_block_alloc_info){
190190
struct ext3_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node;
191191
rsv->rsv_goal_size = rsv_window_size;
192192
}
193-
up(&ei->truncate_sem);
193+
mutex_unlock(&ei->truncate_mutex);
194194
return 0;
195195
}
196196
case EXT3_IOC_GROUP_EXTEND: {

‎fs/ext3/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
472472
#ifdef CONFIG_EXT3_FS_XATTR
473473
init_rwsem(&ei->xattr_sem);
474474
#endif
475-
init_MUTEX(&ei->truncate_sem);
475+
mutex_init(&ei->truncate_mutex);
476476
inode_init_once(&ei->vfs_inode);
477477
}
478478
}

‎include/linux/ext3_fs_i.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/rwsem.h>
2020
#include <linux/rbtree.h>
2121
#include <linux/seqlock.h>
22+
#include <linux/mutex.h>
2223

2324
struct ext3_reserve_window {
2425
__u32 _rsv_start; /* First byte reserved */
@@ -122,16 +123,16 @@ struct ext3_inode_info {
122123
__u16 i_extra_isize;
123124

124125
/*
125-
* truncate_sem is for serialising ext3_truncate() against
126+
* truncate_mutex is for serialising ext3_truncate() against
126127
* ext3_getblock(). In the 2.4 ext2 design, great chunks of inode's
127128
* data tree are chopped off during truncate. We can't do that in
128129
* ext3 because whenever we perform intermediate commits during
129130
* truncate, the inode and all the metadata blocks *must* be in a
130131
* consistent state which allows truncation of the orphans to restart
131132
* during recovery. Hence we must fix the get_block-vs-truncate race
132-
* by other means, so we have truncate_sem.
133+
* by other means, so we have truncate_mutex.
133134
*/
134-
struct semaphore truncate_sem;
135+
struct mutex truncate_mutex;
135136
struct inode vfs_inode;
136137
};
137138

0 commit comments

Comments
 (0)