aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ntfs/inode.c
diff options
context:
space:
mode:
authorAnton Altaparmakov <aia21@cantab.net>2007-01-18 04:42:48 -0500
committerAnton Altaparmakov <aia21@cantab.net>2007-01-18 04:42:48 -0500
commit8331191e56802f0155772a3d56bc2a750acc38e1 (patch)
tree556f3b8f395d7c66b9eca9d35309644b9f1c027d /fs/ntfs/inode.c
parenta8b3485287731978899ced11f24628c927890e78 (diff)
NTFS: 2.1.28 - Fix deadlock reported by Sergey Vlasov due to ntfs_put_inode().
- Fix deadlock in fs/ntfs/inode.c::ntfs_put_inode(). Thanks to Sergey Vlasov for the report and detailed analysis of the deadlock. The fix involved getting rid of ntfs_put_inode() altogether and hence NTFS no longer has a ->put_inode super operation. Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
Diffstat (limited to 'fs/ntfs/inode.c')
-rw-r--r--fs/ntfs/inode.c69
1 files changed, 13 insertions, 56 deletions
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index 247989891b4b..f8bf8da67ee8 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -1,7 +1,7 @@
1/** 1/**
2 * inode.c - NTFS kernel inode handling. Part of the Linux-NTFS project. 2 * inode.c - NTFS kernel inode handling. Part of the Linux-NTFS project.
3 * 3 *
4 * Copyright (c) 2001-2006 Anton Altaparmakov 4 * Copyright (c) 2001-2007 Anton Altaparmakov
5 * 5 *
6 * This program/include file is free software; you can redistribute it and/or 6 * This program/include file is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as published 7 * modify it under the terms of the GNU General Public License as published
@@ -95,7 +95,7 @@ int ntfs_test_inode(struct inode *vi, ntfs_attr *na)
95 * If initializing the normal file/directory inode, set @na->type to AT_UNUSED. 95 * If initializing the normal file/directory inode, set @na->type to AT_UNUSED.
96 * In that case, @na->name and @na->name_len should be set to NULL and 0, 96 * In that case, @na->name and @na->name_len should be set to NULL and 0,
97 * respectively. Although that is not strictly necessary as 97 * respectively. Although that is not strictly necessary as
98 * ntfs_read_inode_locked() will fill them in later. 98 * ntfs_read_locked_inode() will fill them in later.
99 * 99 *
100 * Return 0 on success and -errno on error. 100 * Return 0 on success and -errno on error.
101 * 101 *
@@ -171,8 +171,8 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi,
171struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no) 171struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no)
172{ 172{
173 struct inode *vi; 173 struct inode *vi;
174 ntfs_attr na;
175 int err; 174 int err;
175 ntfs_attr na;
176 176
177 na.mft_no = mft_no; 177 na.mft_no = mft_no;
178 na.type = AT_UNUSED; 178 na.type = AT_UNUSED;
@@ -229,8 +229,8 @@ struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPE type,
229 ntfschar *name, u32 name_len) 229 ntfschar *name, u32 name_len)
230{ 230{
231 struct inode *vi; 231 struct inode *vi;
232 ntfs_attr na;
233 int err; 232 int err;
233 ntfs_attr na;
234 234
235 /* Make sure no one calls ntfs_attr_iget() for indices. */ 235 /* Make sure no one calls ntfs_attr_iget() for indices. */
236 BUG_ON(type == AT_INDEX_ALLOCATION); 236 BUG_ON(type == AT_INDEX_ALLOCATION);
@@ -287,8 +287,8 @@ struct inode *ntfs_index_iget(struct inode *base_vi, ntfschar *name,
287 u32 name_len) 287 u32 name_len)
288{ 288{
289 struct inode *vi; 289 struct inode *vi;
290 ntfs_attr na;
291 int err; 290 int err;
291 ntfs_attr na;
292 292
293 na.mft_no = base_vi->i_ino; 293 na.mft_no = base_vi->i_ino;
294 na.type = AT_INDEX_ALLOCATION; 294 na.type = AT_INDEX_ALLOCATION;
@@ -402,7 +402,6 @@ void __ntfs_init_inode(struct super_block *sb, ntfs_inode *ni)
402 ntfs_init_runlist(&ni->attr_list_rl); 402 ntfs_init_runlist(&ni->attr_list_rl);
403 lockdep_set_class(&ni->attr_list_rl.lock, 403 lockdep_set_class(&ni->attr_list_rl.lock,
404 &attr_list_rl_lock_class); 404 &attr_list_rl_lock_class);
405 ni->itype.index.bmp_ino = NULL;
406 ni->itype.index.block_size = 0; 405 ni->itype.index.block_size = 0;
407 ni->itype.index.vcn_size = 0; 406 ni->itype.index.vcn_size = 0;
408 ni->itype.index.collation_rule = 0; 407 ni->itype.index.collation_rule = 0;
@@ -546,6 +545,7 @@ static int ntfs_read_locked_inode(struct inode *vi)
546{ 545{
547 ntfs_volume *vol = NTFS_SB(vi->i_sb); 546 ntfs_volume *vol = NTFS_SB(vi->i_sb);
548 ntfs_inode *ni; 547 ntfs_inode *ni;
548 struct inode *bvi;
549 MFT_RECORD *m; 549 MFT_RECORD *m;
550 ATTR_RECORD *a; 550 ATTR_RECORD *a;
551 STANDARD_INFORMATION *si; 551 STANDARD_INFORMATION *si;
@@ -780,7 +780,6 @@ skip_attr_list_load:
780 */ 780 */
781 if (S_ISDIR(vi->i_mode)) { 781 if (S_ISDIR(vi->i_mode)) {
782 loff_t bvi_size; 782 loff_t bvi_size;
783 struct inode *bvi;
784 ntfs_inode *bni; 783 ntfs_inode *bni;
785 INDEX_ROOT *ir; 784 INDEX_ROOT *ir;
786 u8 *ir_end, *index_end; 785 u8 *ir_end, *index_end;
@@ -985,13 +984,12 @@ skip_attr_list_load:
985 err = PTR_ERR(bvi); 984 err = PTR_ERR(bvi);
986 goto unm_err_out; 985 goto unm_err_out;
987 } 986 }
988 ni->itype.index.bmp_ino = bvi;
989 bni = NTFS_I(bvi); 987 bni = NTFS_I(bvi);
990 if (NInoCompressed(bni) || NInoEncrypted(bni) || 988 if (NInoCompressed(bni) || NInoEncrypted(bni) ||
991 NInoSparse(bni)) { 989 NInoSparse(bni)) {
992 ntfs_error(vi->i_sb, "$BITMAP attribute is compressed " 990 ntfs_error(vi->i_sb, "$BITMAP attribute is compressed "
993 "and/or encrypted and/or sparse."); 991 "and/or encrypted and/or sparse.");
994 goto unm_err_out; 992 goto iput_unm_err_out;
995 } 993 }
996 /* Consistency check bitmap size vs. index allocation size. */ 994 /* Consistency check bitmap size vs. index allocation size. */
997 bvi_size = i_size_read(bvi); 995 bvi_size = i_size_read(bvi);
@@ -1000,8 +998,10 @@ skip_attr_list_load:
1000 ntfs_error(vi->i_sb, "Index bitmap too small (0x%llx) " 998 ntfs_error(vi->i_sb, "Index bitmap too small (0x%llx) "
1001 "for index allocation (0x%llx).", 999 "for index allocation (0x%llx).",
1002 bvi_size << 3, vi->i_size); 1000 bvi_size << 3, vi->i_size);
1003 goto unm_err_out; 1001 goto iput_unm_err_out;
1004 } 1002 }
1003 /* No longer need the bitmap attribute inode. */
1004 iput(bvi);
1005skip_large_dir_stuff: 1005skip_large_dir_stuff:
1006 /* Setup the operations for this inode. */ 1006 /* Setup the operations for this inode. */
1007 vi->i_op = &ntfs_dir_inode_ops; 1007 vi->i_op = &ntfs_dir_inode_ops;
@@ -1176,7 +1176,8 @@ no_data_attr_special_case:
1176 vi->i_blocks = ni->allocated_size >> 9; 1176 vi->i_blocks = ni->allocated_size >> 9;
1177 ntfs_debug("Done."); 1177 ntfs_debug("Done.");
1178 return 0; 1178 return 0;
1179 1179iput_unm_err_out:
1180 iput(bvi);
1180unm_err_out: 1181unm_err_out:
1181 if (!err) 1182 if (!err)
1182 err = -EIO; 1183 err = -EIO;
@@ -1697,7 +1698,7 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi)
1697 vi->i_size); 1698 vi->i_size);
1698 goto iput_unm_err_out; 1699 goto iput_unm_err_out;
1699 } 1700 }
1700 ni->itype.index.bmp_ino = bvi; 1701 iput(bvi);
1701skip_large_index_stuff: 1702skip_large_index_stuff:
1702 /* Setup the operations for this index inode. */ 1703 /* Setup the operations for this index inode. */
1703 vi->i_op = NULL; 1704 vi->i_op = NULL;
@@ -1714,7 +1715,6 @@ skip_large_index_stuff:
1714 1715
1715 ntfs_debug("Done."); 1716 ntfs_debug("Done.");
1716 return 0; 1717 return 0;
1717
1718iput_unm_err_out: 1718iput_unm_err_out:
1719 iput(bvi); 1719 iput(bvi);
1720unm_err_out: 1720unm_err_out:
@@ -2191,37 +2191,6 @@ err_out:
2191 return -1; 2191 return -1;
2192} 2192}
2193 2193
2194/**
2195 * ntfs_put_inode - handler for when the inode reference count is decremented
2196 * @vi: vfs inode
2197 *
2198 * The VFS calls ntfs_put_inode() every time the inode reference count (i_count)
2199 * is about to be decremented (but before the decrement itself.
2200 *
2201 * If the inode @vi is a directory with two references, one of which is being
2202 * dropped, we need to put the attribute inode for the directory index bitmap,
2203 * if it is present, otherwise the directory inode would remain pinned for
2204 * ever.
2205 */
2206void ntfs_put_inode(struct inode *vi)
2207{
2208 if (S_ISDIR(vi->i_mode) && atomic_read(&vi->i_count) == 2) {
2209 ntfs_inode *ni = NTFS_I(vi);
2210 if (NInoIndexAllocPresent(ni)) {
2211 struct inode *bvi = NULL;
2212 mutex_lock(&vi->i_mutex);
2213 if (atomic_read(&vi->i_count) == 2) {
2214 bvi = ni->itype.index.bmp_ino;
2215 if (bvi)
2216 ni->itype.index.bmp_ino = NULL;
2217 }
2218 mutex_unlock(&vi->i_mutex);
2219 if (bvi)
2220 iput(bvi);
2221 }
2222 }
2223}
2224
2225static void __ntfs_clear_inode(ntfs_inode *ni) 2194static void __ntfs_clear_inode(ntfs_inode *ni)
2226{ 2195{
2227 /* Free all alocated memory. */ 2196 /* Free all alocated memory. */
@@ -2287,18 +2256,6 @@ void ntfs_clear_big_inode(struct inode *vi)
2287{ 2256{
2288 ntfs_inode *ni = NTFS_I(vi); 2257 ntfs_inode *ni = NTFS_I(vi);
2289 2258
2290 /*
2291 * If the inode @vi is an index inode we need to put the attribute
2292 * inode for the index bitmap, if it is present, otherwise the index
2293 * inode would disappear and the attribute inode for the index bitmap
2294 * would no longer be referenced from anywhere and thus it would remain
2295 * pinned for ever.
2296 */
2297 if (NInoAttr(ni) && (ni->type == AT_INDEX_ALLOCATION) &&
2298 NInoIndexAllocPresent(ni) && ni->itype.index.bmp_ino) {
2299 iput(ni->itype.index.bmp_ino);
2300 ni->itype.index.bmp_ino = NULL;
2301 }
2302#ifdef NTFS_RW 2259#ifdef NTFS_RW
2303 if (NInoDirty(ni)) { 2260 if (NInoDirty(ni)) {
2304 bool was_bad = (is_bad_inode(vi)); 2261 bool was_bad = (is_bad_inode(vi));