diff options
Diffstat (limited to 'fs/reiserfs/file.c')
-rw-r--r-- | fs/reiserfs/file.c | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c index b82cdd8a45dd..6846371498b6 100644 --- a/fs/reiserfs/file.c +++ b/fs/reiserfs/file.c | |||
@@ -38,20 +38,24 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp) | |||
38 | 38 | ||
39 | BUG_ON(!S_ISREG(inode->i_mode)); | 39 | BUG_ON(!S_ISREG(inode->i_mode)); |
40 | 40 | ||
41 | if (atomic_add_unless(&REISERFS_I(inode)->openers, -1, 1)) | ||
42 | return 0; | ||
43 | |||
44 | mutex_lock(&(REISERFS_I(inode)->tailpack)); | ||
45 | |||
46 | if (!atomic_dec_and_test(&REISERFS_I(inode)->openers)) { | ||
47 | mutex_unlock(&(REISERFS_I(inode)->tailpack)); | ||
48 | return 0; | ||
49 | } | ||
50 | |||
41 | /* fast out for when nothing needs to be done */ | 51 | /* fast out for when nothing needs to be done */ |
42 | if ((atomic_read(&inode->i_count) > 1 || | 52 | if ((!(REISERFS_I(inode)->i_flags & i_pack_on_close_mask) || |
43 | !(REISERFS_I(inode)->i_flags & i_pack_on_close_mask) || | ||
44 | !tail_has_to_be_packed(inode)) && | 53 | !tail_has_to_be_packed(inode)) && |
45 | REISERFS_I(inode)->i_prealloc_count <= 0) { | 54 | REISERFS_I(inode)->i_prealloc_count <= 0) { |
55 | mutex_unlock(&(REISERFS_I(inode)->tailpack)); | ||
46 | return 0; | 56 | return 0; |
47 | } | 57 | } |
48 | 58 | ||
49 | mutex_lock(&inode->i_mutex); | ||
50 | |||
51 | mutex_lock(&(REISERFS_I(inode)->i_mmap)); | ||
52 | if (REISERFS_I(inode)->i_flags & i_ever_mapped) | ||
53 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; | ||
54 | |||
55 | reiserfs_write_lock(inode->i_sb); | 59 | reiserfs_write_lock(inode->i_sb); |
56 | /* freeing preallocation only involves relogging blocks that | 60 | /* freeing preallocation only involves relogging blocks that |
57 | * are already in the current transaction. preallocation gets | 61 | * are already in the current transaction. preallocation gets |
@@ -94,9 +98,10 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp) | |||
94 | if (!err) | 98 | if (!err) |
95 | err = jbegin_failure; | 99 | err = jbegin_failure; |
96 | 100 | ||
97 | if (!err && atomic_read(&inode->i_count) <= 1 && | 101 | if (!err && |
98 | (REISERFS_I(inode)->i_flags & i_pack_on_close_mask) && | 102 | (REISERFS_I(inode)->i_flags & i_pack_on_close_mask) && |
99 | tail_has_to_be_packed(inode)) { | 103 | tail_has_to_be_packed(inode)) { |
104 | |||
100 | /* if regular file is released by last holder and it has been | 105 | /* if regular file is released by last holder and it has been |
101 | appended (we append by unformatted node only) or its direct | 106 | appended (we append by unformatted node only) or its direct |
102 | item(s) had to be converted, then it may have to be | 107 | item(s) had to be converted, then it may have to be |
@@ -104,27 +109,28 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp) | |||
104 | err = reiserfs_truncate_file(inode, 0); | 109 | err = reiserfs_truncate_file(inode, 0); |
105 | } | 110 | } |
106 | out: | 111 | out: |
107 | mutex_unlock(&(REISERFS_I(inode)->i_mmap)); | ||
108 | mutex_unlock(&inode->i_mutex); | ||
109 | reiserfs_write_unlock(inode->i_sb); | 112 | reiserfs_write_unlock(inode->i_sb); |
113 | mutex_unlock(&(REISERFS_I(inode)->tailpack)); | ||
110 | return err; | 114 | return err; |
111 | } | 115 | } |
112 | 116 | ||
113 | static int reiserfs_file_mmap(struct file *file, struct vm_area_struct *vma) | 117 | static int reiserfs_file_open(struct inode *inode, struct file *file) |
114 | { | 118 | { |
115 | struct inode *inode; | 119 | int err = dquot_file_open(inode, file); |
116 | 120 | if (!atomic_inc_not_zero(&REISERFS_I(inode)->openers)) { | |
117 | inode = file->f_path.dentry->d_inode; | 121 | /* somebody might be tailpacking on final close; wait for it */ |
118 | mutex_lock(&(REISERFS_I(inode)->i_mmap)); | 122 | mutex_lock(&(REISERFS_I(inode)->tailpack)); |
119 | REISERFS_I(inode)->i_flags |= i_ever_mapped; | 123 | atomic_inc(&REISERFS_I(inode)->openers); |
120 | mutex_unlock(&(REISERFS_I(inode)->i_mmap)); | 124 | mutex_unlock(&(REISERFS_I(inode)->tailpack)); |
121 | 125 | } | |
122 | return generic_file_mmap(file, vma); | 126 | return err; |
123 | } | 127 | } |
124 | 128 | ||
125 | static void reiserfs_vfs_truncate_file(struct inode *inode) | 129 | static void reiserfs_vfs_truncate_file(struct inode *inode) |
126 | { | 130 | { |
131 | mutex_lock(&(REISERFS_I(inode)->tailpack)); | ||
127 | reiserfs_truncate_file(inode, 1); | 132 | reiserfs_truncate_file(inode, 1); |
133 | mutex_unlock(&(REISERFS_I(inode)->tailpack)); | ||
128 | } | 134 | } |
129 | 135 | ||
130 | /* Sync a reiserfs file. */ | 136 | /* Sync a reiserfs file. */ |
@@ -288,8 +294,8 @@ const struct file_operations reiserfs_file_operations = { | |||
288 | #ifdef CONFIG_COMPAT | 294 | #ifdef CONFIG_COMPAT |
289 | .compat_ioctl = reiserfs_compat_ioctl, | 295 | .compat_ioctl = reiserfs_compat_ioctl, |
290 | #endif | 296 | #endif |
291 | .mmap = reiserfs_file_mmap, | 297 | .mmap = generic_file_mmap, |
292 | .open = dquot_file_open, | 298 | .open = reiserfs_file_open, |
293 | .release = reiserfs_file_release, | 299 | .release = reiserfs_file_release, |
294 | .fsync = reiserfs_sync_file, | 300 | .fsync = reiserfs_sync_file, |
295 | .aio_read = generic_file_aio_read, | 301 | .aio_read = generic_file_aio_read, |