Merge git://git.kernel.org/pub/scm/linux/kernel/git/aia21/ntfs-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/aia21/ntfs-2.6:
NTFS: Forgot to bump version number in makefile to 2.1.28...
NTFS: 2.1.28 - Fix deadlock reported by Sergey Vlasov due to ntfs_put_inode().

+53 -85
+2
Documentation/filesystems/ntfs.txt
··· 457 457 458 458 Note, a technical ChangeLog aimed at kernel hackers is in fs/ntfs/ChangeLog. 459 459 460 + 2.1.28: 461 + - Fix a deadlock. 460 462 2.1.27: 461 463 - Implement page migration support so the kernel can move memory used 462 464 by NTFS files and directories around for management purposes.
+7
fs/ntfs/ChangeLog
··· 17 17 happen is unclear however so it is worth waiting until someone hits 18 18 the problem. 19 19 20 + 2.1.28 - Fix a deadlock. 21 + 22 + - Fix deadlock in fs/ntfs/inode.c::ntfs_put_inode(). Thanks to Sergey 23 + Vlasov for the report and detailed analysis of the deadlock. The fix 24 + involved getting rid of ntfs_put_inode() altogether and hence NTFS no 25 + longer has a ->put_inode super operation. 26 + 20 27 2.1.27 - Various bug fixes and cleanups. 21 28 22 29 - Fix two compiler warnings on Alpha. Thanks to Andrew Morton for
+1 -1
fs/ntfs/Makefile
··· 6 6 index.o inode.o mft.o mst.o namei.o runlist.o super.o sysctl.o \ 7 7 unistr.o upcase.o 8 8 9 - EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.27\" 9 + EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.28\" 10 10 11 11 ifeq ($(CONFIG_NTFS_DEBUG),y) 12 12 EXTRA_CFLAGS += -DDEBUG
+27 -18
fs/ntfs/dir.c
··· 1 1 /** 2 2 * dir.c - NTFS kernel directory operations. Part of the Linux-NTFS project. 3 3 * 4 - * Copyright (c) 2001-2005 Anton Altaparmakov 4 + * Copyright (c) 2001-2007 Anton Altaparmakov 5 5 * Copyright (c) 2002 Richard Russon 6 6 * 7 7 * This program/include file is free software; you can redistribute it and/or ··· 1249 1249 /* Get the offset into the index allocation attribute. */ 1250 1250 ia_pos = (s64)fpos - vol->mft_record_size; 1251 1251 ia_mapping = vdir->i_mapping; 1252 - bmp_vi = ndir->itype.index.bmp_ino; 1253 - if (unlikely(!bmp_vi)) { 1254 - ntfs_debug("Inode 0x%lx, regetting index bitmap.", vdir->i_ino); 1255 - bmp_vi = ntfs_attr_iget(vdir, AT_BITMAP, I30, 4); 1256 - if (IS_ERR(bmp_vi)) { 1257 - ntfs_error(sb, "Failed to get bitmap attribute."); 1258 - err = PTR_ERR(bmp_vi); 1259 - goto err_out; 1260 - } 1261 - ndir->itype.index.bmp_ino = bmp_vi; 1252 + ntfs_debug("Inode 0x%lx, getting index bitmap.", vdir->i_ino); 1253 + bmp_vi = ntfs_attr_iget(vdir, AT_BITMAP, I30, 4); 1254 + if (IS_ERR(bmp_vi)) { 1255 + ntfs_error(sb, "Failed to get bitmap attribute."); 1256 + err = PTR_ERR(bmp_vi); 1257 + goto err_out; 1262 1258 } 1263 1259 bmp_mapping = bmp_vi->i_mapping; 1264 1260 /* Get the starting bitmap bit position and sanity check it. */ ··· 1262 1266 if (unlikely(bmp_pos >> 3 >= i_size_read(bmp_vi))) { 1263 1267 ntfs_error(sb, "Current index allocation position exceeds " 1264 1268 "index bitmap size."); 1265 - goto err_out; 1269 + goto iput_err_out; 1266 1270 } 1267 1271 /* Get the starting bit position in the current bitmap page. */ 1268 1272 cur_bmp_pos = bmp_pos & ((PAGE_CACHE_SIZE * 8) - 1); ··· 1278 1282 ntfs_error(sb, "Reading index bitmap failed."); 1279 1283 err = PTR_ERR(bmp_page); 1280 1284 bmp_page = NULL; 1281 - goto err_out; 1285 + goto iput_err_out; 1282 1286 } 1283 1287 bmp = (u8*)page_address(bmp_page); 1284 1288 /* Find next index block in use. */ ··· 1425 1429 /* @ia_page is already unlocked in this case. */ 1426 1430 ntfs_unmap_page(ia_page); 1427 1431 ntfs_unmap_page(bmp_page); 1432 + iput(bmp_vi); 1428 1433 goto abort; 1429 1434 } 1430 1435 } ··· 1436 1439 ntfs_unmap_page(ia_page); 1437 1440 } 1438 1441 ntfs_unmap_page(bmp_page); 1442 + iput(bmp_vi); 1439 1443 EOD: 1440 1444 /* We are finished, set fpos to EOD. */ 1441 1445 fpos = i_size + vol->mft_record_size; ··· 1453 1455 filp->f_pos = fpos; 1454 1456 return 0; 1455 1457 err_out: 1456 - if (bmp_page) 1458 + if (bmp_page) { 1457 1459 ntfs_unmap_page(bmp_page); 1460 + iput_err_out: 1461 + iput(bmp_vi); 1462 + } 1458 1463 if (ia_page) { 1459 1464 unlock_page(ia_page); 1460 1465 ntfs_unmap_page(ia_page); ··· 1530 1529 static int ntfs_dir_fsync(struct file *filp, struct dentry *dentry, 1531 1530 int datasync) 1532 1531 { 1533 - struct inode *vi = dentry->d_inode; 1534 - ntfs_inode *ni = NTFS_I(vi); 1532 + struct inode *bmp_vi, *vi = dentry->d_inode; 1535 1533 int err, ret; 1534 + ntfs_attr na; 1536 1535 1537 1536 ntfs_debug("Entering for inode 0x%lx.", vi->i_ino); 1538 1537 BUG_ON(!S_ISDIR(vi->i_mode)); 1539 - if (NInoIndexAllocPresent(ni) && ni->itype.index.bmp_ino) 1540 - write_inode_now(ni->itype.index.bmp_ino, !datasync); 1538 + /* If the bitmap attribute inode is in memory sync it, too. */ 1539 + na.mft_no = vi->i_ino; 1540 + na.type = AT_BITMAP; 1541 + na.name = I30; 1542 + na.name_len = 4; 1543 + bmp_vi = ilookup5(vi->i_sb, vi->i_ino, (test_t)ntfs_test_inode, &na); 1544 + if (bmp_vi) { 1545 + write_inode_now(bmp_vi, !datasync); 1546 + iput(bmp_vi); 1547 + } 1541 1548 ret = ntfs_write_inode(vi, 1); 1542 1549 write_inode_now(vi, !datasync); 1543 1550 err = sync_blockdev(vi->i_sb->s_bdev);
+13 -56
fs/ntfs/inode.c
··· 1 1 /** 2 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 6 * This program/include file is free software; you can redistribute it and/or 7 7 * modify it under the terms of the GNU General Public License as published ··· 95 95 * If initializing the normal file/directory inode, set @na->type to AT_UNUSED. 96 96 * In that case, @na->name and @na->name_len should be set to NULL and 0, 97 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 100 * Return 0 on success and -errno on error. 101 101 * ··· 171 171 struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no) 172 172 { 173 173 struct inode *vi; 174 - ntfs_attr na; 175 174 int err; 175 + ntfs_attr na; 176 176 177 177 na.mft_no = mft_no; 178 178 na.type = AT_UNUSED; ··· 229 229 ntfschar *name, u32 name_len) 230 230 { 231 231 struct inode *vi; 232 - ntfs_attr na; 233 232 int err; 233 + ntfs_attr na; 234 234 235 235 /* Make sure no one calls ntfs_attr_iget() for indices. */ 236 236 BUG_ON(type == AT_INDEX_ALLOCATION); ··· 287 287 u32 name_len) 288 288 { 289 289 struct inode *vi; 290 - ntfs_attr na; 291 290 int err; 291 + ntfs_attr na; 292 292 293 293 na.mft_no = base_vi->i_ino; 294 294 na.type = AT_INDEX_ALLOCATION; ··· 402 402 ntfs_init_runlist(&ni->attr_list_rl); 403 403 lockdep_set_class(&ni->attr_list_rl.lock, 404 404 &attr_list_rl_lock_class); 405 - ni->itype.index.bmp_ino = NULL; 406 405 ni->itype.index.block_size = 0; 407 406 ni->itype.index.vcn_size = 0; 408 407 ni->itype.index.collation_rule = 0; ··· 545 546 { 546 547 ntfs_volume *vol = NTFS_SB(vi->i_sb); 547 548 ntfs_inode *ni; 549 + struct inode *bvi; 548 550 MFT_RECORD *m; 549 551 ATTR_RECORD *a; 550 552 STANDARD_INFORMATION *si; ··· 780 780 */ 781 781 if (S_ISDIR(vi->i_mode)) { 782 782 loff_t bvi_size; 783 - struct inode *bvi; 784 783 ntfs_inode *bni; 785 784 INDEX_ROOT *ir; 786 785 u8 *ir_end, *index_end; ··· 984 985 err = PTR_ERR(bvi); 985 986 goto unm_err_out; 986 987 } 987 - ni->itype.index.bmp_ino = bvi; 988 988 bni = NTFS_I(bvi); 989 989 if (NInoCompressed(bni) || NInoEncrypted(bni) || 990 990 NInoSparse(bni)) { 991 991 ntfs_error(vi->i_sb, "$BITMAP attribute is compressed " 992 992 "and/or encrypted and/or sparse."); 993 - goto unm_err_out; 993 + goto iput_unm_err_out; 994 994 } 995 995 /* Consistency check bitmap size vs. index allocation size. */ 996 996 bvi_size = i_size_read(bvi); ··· 998 1000 ntfs_error(vi->i_sb, "Index bitmap too small (0x%llx) " 999 1001 "for index allocation (0x%llx).", 1000 1002 bvi_size << 3, vi->i_size); 1001 - goto unm_err_out; 1003 + goto iput_unm_err_out; 1002 1004 } 1005 + /* No longer need the bitmap attribute inode. */ 1006 + iput(bvi); 1003 1007 skip_large_dir_stuff: 1004 1008 /* Setup the operations for this inode. */ 1005 1009 vi->i_op = &ntfs_dir_inode_ops; ··· 1176 1176 vi->i_blocks = ni->allocated_size >> 9; 1177 1177 ntfs_debug("Done."); 1178 1178 return 0; 1179 - 1179 + iput_unm_err_out: 1180 + iput(bvi); 1180 1181 unm_err_out: 1181 1182 if (!err) 1182 1183 err = -EIO; ··· 1698 1697 vi->i_size); 1699 1698 goto iput_unm_err_out; 1700 1699 } 1701 - ni->itype.index.bmp_ino = bvi; 1700 + iput(bvi); 1702 1701 skip_large_index_stuff: 1703 1702 /* Setup the operations for this index inode. */ 1704 1703 vi->i_op = NULL; ··· 1715 1714 1716 1715 ntfs_debug("Done."); 1717 1716 return 0; 1718 - 1719 1717 iput_unm_err_out: 1720 1718 iput(bvi); 1721 1719 unm_err_out: ··· 2191 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 - */ 2206 - void 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 - 2225 2194 static void __ntfs_clear_inode(ntfs_inode *ni) 2226 2195 { 2227 2196 /* Free all alocated memory. */ ··· 2256 2287 { 2257 2288 ntfs_inode *ni = NTFS_I(vi); 2258 2289 2259 - /* 2260 - * If the inode @vi is an index inode we need to put the attribute 2261 - * inode for the index bitmap, if it is present, otherwise the index 2262 - * inode would disappear and the attribute inode for the index bitmap 2263 - * would no longer be referenced from anywhere and thus it would remain 2264 - * pinned for ever. 2265 - */ 2266 - if (NInoAttr(ni) && (ni->type == AT_INDEX_ALLOCATION) && 2267 - NInoIndexAllocPresent(ni) && ni->itype.index.bmp_ino) { 2268 - iput(ni->itype.index.bmp_ino); 2269 - ni->itype.index.bmp_ino = NULL; 2270 - } 2271 2290 #ifdef NTFS_RW 2272 2291 if (NInoDirty(ni)) { 2273 2292 bool was_bad = (is_bad_inode(vi));
+1 -5
fs/ntfs/inode.h
··· 2 2 * inode.h - Defines for inode structures NTFS Linux kernel driver. Part of 3 3 * the Linux-NTFS project. 4 4 * 5 - * Copyright (c) 2001-2005 Anton Altaparmakov 5 + * Copyright (c) 2001-2007 Anton Altaparmakov 6 6 * Copyright (c) 2002 Richard Russon 7 7 * 8 8 * This program/include file is free software; you can redistribute it and/or ··· 101 101 runlist attr_list_rl; /* Run list for the attribute list value. */ 102 102 union { 103 103 struct { /* It is a directory, $MFT, or an index inode. */ 104 - struct inode *bmp_ino; /* Attribute inode for the 105 - index $BITMAP. */ 106 104 u32 block_size; /* Size of an index block. */ 107 105 u32 vcn_size; /* Size of a vcn in this 108 106 index. */ ··· 297 299 extern void ntfs_clear_extent_inode(ntfs_inode *ni); 298 300 299 301 extern int ntfs_read_inode_mount(struct inode *vi); 300 - 301 - extern void ntfs_put_inode(struct inode *vi); 302 302 303 303 extern int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt); 304 304
+2 -5
fs/ntfs/super.c
··· 1 1 /* 2 2 * super.c - NTFS kernel super block 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 * Copyright (c) 2001,2002 Richard Russon 6 6 * 7 7 * This program/include file is free software; you can redistribute it and/or ··· 2702 2702 static struct super_operations ntfs_sops = { 2703 2703 .alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */ 2704 2704 .destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */ 2705 - .put_inode = ntfs_put_inode, /* VFS: Called just before 2706 - the inode reference count 2707 - is decreased. */ 2708 2705 #ifdef NTFS_RW 2709 2706 //.dirty_inode = NULL, /* VFS: Called from 2710 2707 // __mark_inode_dirty(). */ ··· 3258 3261 } 3259 3262 3260 3263 MODULE_AUTHOR("Anton Altaparmakov <aia21@cantab.net>"); 3261 - MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2006 Anton Altaparmakov"); 3264 + MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2007 Anton Altaparmakov"); 3262 3265 MODULE_VERSION(NTFS_VERSION); 3263 3266 MODULE_LICENSE("GPL"); 3264 3267 #ifdef DEBUG