aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/block_dev.c1
-rw-r--r--fs/compat.c49
-rw-r--r--fs/dcache.c5
-rw-r--r--fs/dquot.c15
-rw-r--r--fs/ecryptfs/crypto.c191
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h17
-rw-r--r--fs/ecryptfs/file.c5
-rw-r--r--fs/ecryptfs/inode.c16
-rw-r--r--fs/ecryptfs/keystore.c8
-rw-r--r--fs/ecryptfs/main.c40
-rw-r--r--fs/ecryptfs/mmap.c23
-rw-r--r--fs/ecryptfs/read_write.c2
-rw-r--r--fs/ecryptfs/super.c48
-rw-r--r--fs/eventfd.c1
-rw-r--r--fs/ext2/balloc.c98
-rw-r--r--fs/ext2/dir.c2
-rw-r--r--fs/ext2/ext2.h3
-rw-r--r--fs/ext2/file.c4
-rw-r--r--fs/ext2/inode.c8
-rw-r--r--fs/ext2/ioctl.c12
-rw-r--r--fs/ext2/super.c31
-rw-r--r--fs/ext3/balloc.c94
-rw-r--r--fs/ext3/inode.c114
-rw-r--r--fs/ext3/namei.c4
-rw-r--r--fs/ext3/super.c29
-rw-r--r--fs/ext4/balloc.c8
-rw-r--r--fs/ext4/inode.c9
-rw-r--r--fs/ext4/super.c14
-rw-r--r--fs/fat/file.c47
-rw-r--r--fs/fat/inode.c6
-rw-r--r--fs/fat/misc.c5
-rw-r--r--fs/file.c8
-rw-r--r--fs/fs-writeback.c7
-rw-r--r--fs/fuse/dev.c113
-rw-r--r--fs/fuse/dir.c1
-rw-r--r--fs/fuse/file.c14
-rw-r--r--fs/fuse/fuse_i.h18
-rw-r--r--fs/fuse/inode.c1
-rw-r--r--fs/hfs/bfind.c11
-rw-r--r--fs/hfs/brec.c4
-rw-r--r--fs/hfs/btree.c26
-rw-r--r--fs/hfs/hfs.h2
-rw-r--r--fs/hfs/super.c2
-rw-r--r--fs/inotify.c30
-rw-r--r--fs/inotify_user.c29
-rw-r--r--fs/jbd/journal.c2
-rw-r--r--fs/jbd/recovery.c2
-rw-r--r--fs/jbd2/recovery.c2
-rw-r--r--fs/namei.c3
-rw-r--r--fs/namespace.c45
-rw-r--r--fs/ncpfs/inode.c4
-rw-r--r--fs/partitions/Kconfig2
-rw-r--r--fs/pnode.c2
-rw-r--r--fs/proc/proc_misc.c14
-rw-r--r--fs/reiserfs/prints.c2
-rw-r--r--fs/reiserfs/xattr.c2
-rw-r--r--fs/select.c2
-rw-r--r--fs/signalfd.c1
-rw-r--r--fs/smbfs/sock.c5
-rw-r--r--fs/utimes.c1
60 files changed, 697 insertions, 567 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index e48a630ae266..e63067d25cdb 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -534,7 +534,6 @@ void __init bdev_cache_init(void)
534 if (err) 534 if (err)
535 panic("Cannot register bdev pseudo-fs"); 535 panic("Cannot register bdev pseudo-fs");
536 bd_mnt = kern_mount(&bd_type); 536 bd_mnt = kern_mount(&bd_type);
537 err = PTR_ERR(bd_mnt);
538 if (IS_ERR(bd_mnt)) 537 if (IS_ERR(bd_mnt))
539 panic("Cannot create bdev pseudo-fs"); 538 panic("Cannot create bdev pseudo-fs");
540 blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */ 539 blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */
diff --git a/fs/compat.c b/fs/compat.c
index 69baca5ad608..ee80ff341d37 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -2083,51 +2083,6 @@ long asmlinkage compat_sys_nfsservctl(int cmd, void *notused, void *notused2)
2083 2083
2084#ifdef CONFIG_EPOLL 2084#ifdef CONFIG_EPOLL
2085 2085
2086#ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
2087asmlinkage long compat_sys_epoll_ctl(int epfd, int op, int fd,
2088 struct compat_epoll_event __user *event)
2089{
2090 long err = 0;
2091 struct compat_epoll_event user;
2092 struct epoll_event __user *kernel = NULL;
2093
2094 if (event) {
2095 if (copy_from_user(&user, event, sizeof(user)))
2096 return -EFAULT;
2097 kernel = compat_alloc_user_space(sizeof(struct epoll_event));
2098 err |= __put_user(user.events, &kernel->events);
2099 err |= __put_user(user.data, &kernel->data);
2100 }
2101
2102 return err ? err : sys_epoll_ctl(epfd, op, fd, kernel);
2103}
2104
2105
2106asmlinkage long compat_sys_epoll_wait(int epfd,
2107 struct compat_epoll_event __user *events,
2108 int maxevents, int timeout)
2109{
2110 long i, ret, err = 0;
2111 struct epoll_event __user *kbuf;
2112 struct epoll_event ev;
2113
2114 if ((maxevents <= 0) ||
2115 (maxevents > (INT_MAX / sizeof(struct epoll_event))))
2116 return -EINVAL;
2117 kbuf = compat_alloc_user_space(sizeof(struct epoll_event) * maxevents);
2118 ret = sys_epoll_wait(epfd, kbuf, maxevents, timeout);
2119 for (i = 0; i < ret; i++) {
2120 err |= __get_user(ev.events, &kbuf[i].events);
2121 err |= __get_user(ev.data, &kbuf[i].data);
2122 err |= __put_user(ev.events, &events->events);
2123 err |= __put_user_unaligned(ev.data, &events->data);
2124 events++;
2125 }
2126
2127 return err ? -EFAULT: ret;
2128}
2129#endif /* CONFIG_HAS_COMPAT_EPOLL_EVENT */
2130
2131#ifdef TIF_RESTORE_SIGMASK 2086#ifdef TIF_RESTORE_SIGMASK
2132asmlinkage long compat_sys_epoll_pwait(int epfd, 2087asmlinkage long compat_sys_epoll_pwait(int epfd,
2133 struct compat_epoll_event __user *events, 2088 struct compat_epoll_event __user *events,
@@ -2153,11 +2108,7 @@ asmlinkage long compat_sys_epoll_pwait(int epfd,
2153 sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved); 2108 sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
2154 } 2109 }
2155 2110
2156#ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
2157 err = compat_sys_epoll_wait(epfd, events, maxevents, timeout);
2158#else
2159 err = sys_epoll_wait(epfd, events, maxevents, timeout); 2111 err = sys_epoll_wait(epfd, events, maxevents, timeout);
2160#endif
2161 2112
2162 /* 2113 /*
2163 * If we changed the signal mask, we need to restore the original one. 2114 * If we changed the signal mask, we need to restore the original one.
diff --git a/fs/dcache.c b/fs/dcache.c
index d9ca1e5ceb92..44f6cf23b70e 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -89,7 +89,7 @@ static void d_free(struct dentry *dentry)
89 if (dentry->d_op && dentry->d_op->d_release) 89 if (dentry->d_op && dentry->d_op->d_release)
90 dentry->d_op->d_release(dentry); 90 dentry->d_op->d_release(dentry);
91 /* if dentry was never inserted into hash, immediate free is OK */ 91 /* if dentry was never inserted into hash, immediate free is OK */
92 if (dentry->d_hash.pprev == NULL) 92 if (hlist_unhashed(&dentry->d_hash))
93 __d_free(dentry); 93 __d_free(dentry);
94 else 94 else
95 call_rcu(&dentry->d_u.d_rcu, d_callback); 95 call_rcu(&dentry->d_u.d_rcu, d_callback);
@@ -1408,9 +1408,6 @@ void d_delete(struct dentry * dentry)
1408 if (atomic_read(&dentry->d_count) == 1) { 1408 if (atomic_read(&dentry->d_count) == 1) {
1409 dentry_iput(dentry); 1409 dentry_iput(dentry);
1410 fsnotify_nameremove(dentry, isdir); 1410 fsnotify_nameremove(dentry, isdir);
1411
1412 /* remove this and other inotify debug checks after 2.6.18 */
1413 dentry->d_flags &= ~DCACHE_INOTIFY_PARENT_WATCHED;
1414 return; 1411 return;
1415 } 1412 }
1416 1413
diff --git a/fs/dquot.c b/fs/dquot.c
index cee7c6f428f0..def4e969df77 100644
--- a/fs/dquot.c
+++ b/fs/dquot.c
@@ -696,9 +696,8 @@ static int dqinit_needed(struct inode *inode, int type)
696/* This routine is guarded by dqonoff_mutex mutex */ 696/* This routine is guarded by dqonoff_mutex mutex */
697static void add_dquot_ref(struct super_block *sb, int type) 697static void add_dquot_ref(struct super_block *sb, int type)
698{ 698{
699 struct inode *inode; 699 struct inode *inode, *old_inode = NULL;
700 700
701restart:
702 spin_lock(&inode_lock); 701 spin_lock(&inode_lock);
703 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { 702 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
704 if (!atomic_read(&inode->i_writecount)) 703 if (!atomic_read(&inode->i_writecount))
@@ -711,12 +710,18 @@ restart:
711 __iget(inode); 710 __iget(inode);
712 spin_unlock(&inode_lock); 711 spin_unlock(&inode_lock);
713 712
713 iput(old_inode);
714 sb->dq_op->initialize(inode, type); 714 sb->dq_op->initialize(inode, type);
715 iput(inode); 715 /* We hold a reference to 'inode' so it couldn't have been
716 /* As we may have blocked we had better restart... */ 716 * removed from s_inodes list while we dropped the inode_lock.
717 goto restart; 717 * We cannot iput the inode now as we can be holding the last
718 * reference and we cannot iput it under inode_lock. So we
719 * keep the reference and iput it later. */
720 old_inode = inode;
721 spin_lock(&inode_lock);
718 } 722 }
719 spin_unlock(&inode_lock); 723 spin_unlock(&inode_lock);
724 iput(old_inode);
720} 725}
721 726
722/* Return 0 if dqput() won't block (note that 1 doesn't necessarily mean blocking) */ 727/* Return 0 if dqput() won't block (note that 1 doesn't necessarily mean blocking) */
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index f8ef0af919e7..a066e109ad9c 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -355,8 +355,11 @@ static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat,
355 } 355 }
356 /* Consider doing this once, when the file is opened */ 356 /* Consider doing this once, when the file is opened */
357 mutex_lock(&crypt_stat->cs_tfm_mutex); 357 mutex_lock(&crypt_stat->cs_tfm_mutex);
358 rc = crypto_blkcipher_setkey(crypt_stat->tfm, crypt_stat->key, 358 if (!(crypt_stat->flags & ECRYPTFS_KEY_SET)) {
359 crypt_stat->key_size); 359 rc = crypto_blkcipher_setkey(crypt_stat->tfm, crypt_stat->key,
360 crypt_stat->key_size);
361 crypt_stat->flags |= ECRYPTFS_KEY_SET;
362 }
360 if (rc) { 363 if (rc) {
361 ecryptfs_printk(KERN_ERR, "Error setting key; rc = [%d]\n", 364 ecryptfs_printk(KERN_ERR, "Error setting key; rc = [%d]\n",
362 rc); 365 rc);
@@ -376,11 +379,10 @@ out:
376 * 379 *
377 * Convert an eCryptfs page index into a lower byte offset 380 * Convert an eCryptfs page index into a lower byte offset
378 */ 381 */
379void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num, 382static void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num,
380 struct ecryptfs_crypt_stat *crypt_stat) 383 struct ecryptfs_crypt_stat *crypt_stat)
381{ 384{
382 (*offset) = ((crypt_stat->extent_size 385 (*offset) = (crypt_stat->num_header_bytes_at_front
383 * crypt_stat->num_header_extents_at_front)
384 + (crypt_stat->extent_size * extent_num)); 386 + (crypt_stat->extent_size * extent_num));
385} 387}
386 388
@@ -842,15 +844,13 @@ void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat)
842 set_extent_mask_and_shift(crypt_stat); 844 set_extent_mask_and_shift(crypt_stat);
843 crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES; 845 crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES;
844 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) 846 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
845 crypt_stat->num_header_extents_at_front = 0; 847 crypt_stat->num_header_bytes_at_front = 0;
846 else { 848 else {
847 if (PAGE_CACHE_SIZE <= ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE) 849 if (PAGE_CACHE_SIZE <= ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)
848 crypt_stat->num_header_extents_at_front = 850 crypt_stat->num_header_bytes_at_front =
849 (ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE 851 ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE;
850 / crypt_stat->extent_size);
851 else 852 else
852 crypt_stat->num_header_extents_at_front = 853 crypt_stat->num_header_bytes_at_front = PAGE_CACHE_SIZE;
853 (PAGE_CACHE_SIZE / crypt_stat->extent_size);
854 } 854 }
855} 855}
856 856
@@ -1128,7 +1128,7 @@ write_ecryptfs_flags(char *page_virt, struct ecryptfs_crypt_stat *crypt_stat,
1128 1128
1129struct ecryptfs_cipher_code_str_map_elem { 1129struct ecryptfs_cipher_code_str_map_elem {
1130 char cipher_str[16]; 1130 char cipher_str[16];
1131 u16 cipher_code; 1131 u8 cipher_code;
1132}; 1132};
1133 1133
1134/* Add support for additional ciphers by adding elements here. The 1134/* Add support for additional ciphers by adding elements here. The
@@ -1152,10 +1152,10 @@ ecryptfs_cipher_code_str_map[] = {
1152 * 1152 *
1153 * Returns zero on no match, or the cipher code on match 1153 * Returns zero on no match, or the cipher code on match
1154 */ 1154 */
1155u16 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat) 1155u8 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat)
1156{ 1156{
1157 int i; 1157 int i;
1158 u16 code = 0; 1158 u8 code = 0;
1159 struct ecryptfs_cipher_code_str_map_elem *map = 1159 struct ecryptfs_cipher_code_str_map_elem *map =
1160 ecryptfs_cipher_code_str_map; 1160 ecryptfs_cipher_code_str_map;
1161 1161
@@ -1187,7 +1187,7 @@ u16 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat)
1187 * 1187 *
1188 * Returns zero on success 1188 * Returns zero on success
1189 */ 1189 */
1190int ecryptfs_cipher_code_to_string(char *str, u16 cipher_code) 1190int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code)
1191{ 1191{
1192 int rc = 0; 1192 int rc = 0;
1193 int i; 1193 int i;
@@ -1236,7 +1236,8 @@ ecryptfs_write_header_metadata(char *virt,
1236 1236
1237 header_extent_size = (u32)crypt_stat->extent_size; 1237 header_extent_size = (u32)crypt_stat->extent_size;
1238 num_header_extents_at_front = 1238 num_header_extents_at_front =
1239 (u16)crypt_stat->num_header_extents_at_front; 1239 (u16)(crypt_stat->num_header_bytes_at_front
1240 / crypt_stat->extent_size);
1240 header_extent_size = cpu_to_be32(header_extent_size); 1241 header_extent_size = cpu_to_be32(header_extent_size);
1241 memcpy(virt, &header_extent_size, 4); 1242 memcpy(virt, &header_extent_size, 4);
1242 virt += 4; 1243 virt += 4;
@@ -1311,40 +1312,16 @@ static int ecryptfs_write_headers_virt(char *page_virt, size_t *size,
1311static int 1312static int
1312ecryptfs_write_metadata_to_contents(struct ecryptfs_crypt_stat *crypt_stat, 1313ecryptfs_write_metadata_to_contents(struct ecryptfs_crypt_stat *crypt_stat,
1313 struct dentry *ecryptfs_dentry, 1314 struct dentry *ecryptfs_dentry,
1314 char *page_virt) 1315 char *virt)
1315{ 1316{
1316 int current_header_page;
1317 int header_pages;
1318 int rc; 1317 int rc;
1319 1318
1320 rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, page_virt, 1319 rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, virt,
1321 0, PAGE_CACHE_SIZE); 1320 0, crypt_stat->num_header_bytes_at_front);
1322 if (rc) { 1321 if (rc)
1323 printk(KERN_ERR "%s: Error attempting to write header " 1322 printk(KERN_ERR "%s: Error attempting to write header "
1324 "information to lower file; rc = [%d]\n", __FUNCTION__, 1323 "information to lower file; rc = [%d]\n", __FUNCTION__,
1325 rc); 1324 rc);
1326 goto out;
1327 }
1328 header_pages = ((crypt_stat->extent_size
1329 * crypt_stat->num_header_extents_at_front)
1330 / PAGE_CACHE_SIZE);
1331 memset(page_virt, 0, PAGE_CACHE_SIZE);
1332 current_header_page = 1;
1333 while (current_header_page < header_pages) {
1334 loff_t offset;
1335
1336 offset = (((loff_t)current_header_page) << PAGE_CACHE_SHIFT);
1337 if ((rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode,
1338 page_virt, offset,
1339 PAGE_CACHE_SIZE))) {
1340 printk(KERN_ERR "%s: Error attempting to write header "
1341 "information to lower file; rc = [%d]\n",
1342 __FUNCTION__, rc);
1343 goto out;
1344 }
1345 current_header_page++;
1346 }
1347out:
1348 return rc; 1325 return rc;
1349} 1326}
1350 1327
@@ -1370,15 +1347,13 @@ ecryptfs_write_metadata_to_xattr(struct dentry *ecryptfs_dentry,
1370 * retrieved via a prompt. Exactly what happens at this point should 1347 * retrieved via a prompt. Exactly what happens at this point should
1371 * be policy-dependent. 1348 * be policy-dependent.
1372 * 1349 *
1373 * TODO: Support header information spanning multiple pages
1374 *
1375 * Returns zero on success; non-zero on error 1350 * Returns zero on success; non-zero on error
1376 */ 1351 */
1377int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry) 1352int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry)
1378{ 1353{
1379 struct ecryptfs_crypt_stat *crypt_stat = 1354 struct ecryptfs_crypt_stat *crypt_stat =
1380 &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat; 1355 &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat;
1381 char *page_virt; 1356 char *virt;
1382 size_t size = 0; 1357 size_t size = 0;
1383 int rc = 0; 1358 int rc = 0;
1384 1359
@@ -1389,40 +1364,39 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry)
1389 goto out; 1364 goto out;
1390 } 1365 }
1391 } else { 1366 } else {
1367 printk(KERN_WARNING "%s: Encrypted flag not set\n",
1368 __FUNCTION__);
1392 rc = -EINVAL; 1369 rc = -EINVAL;
1393 ecryptfs_printk(KERN_WARNING,
1394 "Called with crypt_stat->encrypted == 0\n");
1395 goto out; 1370 goto out;
1396 } 1371 }
1397 /* Released in this function */ 1372 /* Released in this function */
1398 page_virt = kmem_cache_zalloc(ecryptfs_header_cache_0, GFP_USER); 1373 virt = kzalloc(crypt_stat->num_header_bytes_at_front, GFP_KERNEL);
1399 if (!page_virt) { 1374 if (!virt) {
1400 ecryptfs_printk(KERN_ERR, "Out of memory\n"); 1375 printk(KERN_ERR "%s: Out of memory\n", __FUNCTION__);
1401 rc = -ENOMEM; 1376 rc = -ENOMEM;
1402 goto out; 1377 goto out;
1403 } 1378 }
1404 rc = ecryptfs_write_headers_virt(page_virt, &size, crypt_stat, 1379 rc = ecryptfs_write_headers_virt(virt, &size, crypt_stat,
1405 ecryptfs_dentry); 1380 ecryptfs_dentry);
1406 if (unlikely(rc)) { 1381 if (unlikely(rc)) {
1407 ecryptfs_printk(KERN_ERR, "Error whilst writing headers\n"); 1382 printk(KERN_ERR "%s: Error whilst writing headers; rc = [%d]\n",
1408 memset(page_virt, 0, PAGE_CACHE_SIZE); 1383 __FUNCTION__, rc);
1409 goto out_free; 1384 goto out_free;
1410 } 1385 }
1411 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) 1386 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
1412 rc = ecryptfs_write_metadata_to_xattr(ecryptfs_dentry, 1387 rc = ecryptfs_write_metadata_to_xattr(ecryptfs_dentry,
1413 crypt_stat, page_virt, 1388 crypt_stat, virt, size);
1414 size);
1415 else 1389 else
1416 rc = ecryptfs_write_metadata_to_contents(crypt_stat, 1390 rc = ecryptfs_write_metadata_to_contents(crypt_stat,
1417 ecryptfs_dentry, 1391 ecryptfs_dentry, virt);
1418 page_virt);
1419 if (rc) { 1392 if (rc) {
1420 printk(KERN_ERR "Error writing metadata out to lower file; " 1393 printk(KERN_ERR "%s: Error writing metadata out to lower file; "
1421 "rc = [%d]\n", rc); 1394 "rc = [%d]\n", __FUNCTION__, rc);
1422 goto out_free; 1395 goto out_free;
1423 } 1396 }
1424out_free: 1397out_free:
1425 kmem_cache_free(ecryptfs_header_cache_0, page_virt); 1398 memset(virt, 0, crypt_stat->num_header_bytes_at_front);
1399 kfree(virt);
1426out: 1400out:
1427 return rc; 1401 return rc;
1428} 1402}
@@ -1442,16 +1416,16 @@ static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat,
1442 virt += sizeof(u32); 1416 virt += sizeof(u32);
1443 memcpy(&num_header_extents_at_front, virt, sizeof(u16)); 1417 memcpy(&num_header_extents_at_front, virt, sizeof(u16));
1444 num_header_extents_at_front = be16_to_cpu(num_header_extents_at_front); 1418 num_header_extents_at_front = be16_to_cpu(num_header_extents_at_front);
1445 crypt_stat->num_header_extents_at_front = 1419 crypt_stat->num_header_bytes_at_front =
1446 (int)num_header_extents_at_front; 1420 (((size_t)num_header_extents_at_front
1421 * (size_t)header_extent_size));
1447 (*bytes_read) = (sizeof(u32) + sizeof(u16)); 1422 (*bytes_read) = (sizeof(u32) + sizeof(u16));
1448 if ((validate_header_size == ECRYPTFS_VALIDATE_HEADER_SIZE) 1423 if ((validate_header_size == ECRYPTFS_VALIDATE_HEADER_SIZE)
1449 && ((crypt_stat->extent_size 1424 && (crypt_stat->num_header_bytes_at_front
1450 * crypt_stat->num_header_extents_at_front)
1451 < ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)) { 1425 < ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)) {
1452 rc = -EINVAL; 1426 rc = -EINVAL;
1453 printk(KERN_WARNING "Invalid number of header extents: [%zd]\n", 1427 printk(KERN_WARNING "Invalid header size: [%zd]\n",
1454 crypt_stat->num_header_extents_at_front); 1428 crypt_stat->num_header_bytes_at_front);
1455 } 1429 }
1456 return rc; 1430 return rc;
1457} 1431}
@@ -1466,7 +1440,8 @@ static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat,
1466 */ 1440 */
1467static void set_default_header_data(struct ecryptfs_crypt_stat *crypt_stat) 1441static void set_default_header_data(struct ecryptfs_crypt_stat *crypt_stat)
1468{ 1442{
1469 crypt_stat->num_header_extents_at_front = 2; 1443 crypt_stat->num_header_bytes_at_front =
1444 ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE;
1470} 1445}
1471 1446
1472/** 1447/**
@@ -1552,9 +1527,10 @@ int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode)
1552 size = ecryptfs_getxattr_lower(lower_dentry, ECRYPTFS_XATTR_NAME, 1527 size = ecryptfs_getxattr_lower(lower_dentry, ECRYPTFS_XATTR_NAME,
1553 page_virt, ECRYPTFS_DEFAULT_EXTENT_SIZE); 1528 page_virt, ECRYPTFS_DEFAULT_EXTENT_SIZE);
1554 if (size < 0) { 1529 if (size < 0) {
1555 printk(KERN_ERR "Error attempting to read the [%s] " 1530 if (unlikely(ecryptfs_verbosity > 0))
1556 "xattr from the lower file; return value = [%zd]\n", 1531 printk(KERN_INFO "Error attempting to read the [%s] "
1557 ECRYPTFS_XATTR_NAME, size); 1532 "xattr from the lower file; return value = "
1533 "[%zd]\n", ECRYPTFS_XATTR_NAME, size);
1558 rc = -EINVAL; 1534 rc = -EINVAL;
1559 goto out; 1535 goto out;
1560 } 1536 }
@@ -1802,7 +1778,7 @@ out:
1802} 1778}
1803 1779
1804struct kmem_cache *ecryptfs_key_tfm_cache; 1780struct kmem_cache *ecryptfs_key_tfm_cache;
1805struct list_head key_tfm_list; 1781static struct list_head key_tfm_list;
1806struct mutex key_tfm_list_mutex; 1782struct mutex key_tfm_list_mutex;
1807 1783
1808int ecryptfs_init_crypto(void) 1784int ecryptfs_init_crypto(void)
@@ -1812,6 +1788,11 @@ int ecryptfs_init_crypto(void)
1812 return 0; 1788 return 0;
1813} 1789}
1814 1790
1791/**
1792 * ecryptfs_destroy_crypto - free all cached key_tfms on key_tfm_list
1793 *
1794 * Called only at module unload time
1795 */
1815int ecryptfs_destroy_crypto(void) 1796int ecryptfs_destroy_crypto(void)
1816{ 1797{
1817 struct ecryptfs_key_tfm *key_tfm, *key_tfm_tmp; 1798 struct ecryptfs_key_tfm *key_tfm, *key_tfm_tmp;
@@ -1835,6 +1816,8 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
1835 struct ecryptfs_key_tfm *tmp_tfm; 1816 struct ecryptfs_key_tfm *tmp_tfm;
1836 int rc = 0; 1817 int rc = 0;
1837 1818
1819 BUG_ON(!mutex_is_locked(&key_tfm_list_mutex));
1820
1838 tmp_tfm = kmem_cache_alloc(ecryptfs_key_tfm_cache, GFP_KERNEL); 1821 tmp_tfm = kmem_cache_alloc(ecryptfs_key_tfm_cache, GFP_KERNEL);
1839 if (key_tfm != NULL) 1822 if (key_tfm != NULL)
1840 (*key_tfm) = tmp_tfm; 1823 (*key_tfm) = tmp_tfm;
@@ -1861,13 +1844,50 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
1861 (*key_tfm) = NULL; 1844 (*key_tfm) = NULL;
1862 goto out; 1845 goto out;
1863 } 1846 }
1864 mutex_lock(&key_tfm_list_mutex);
1865 list_add(&tmp_tfm->key_tfm_list, &key_tfm_list); 1847 list_add(&tmp_tfm->key_tfm_list, &key_tfm_list);
1866 mutex_unlock(&key_tfm_list_mutex);
1867out: 1848out:
1868 return rc; 1849 return rc;
1869} 1850}
1870 1851
1852/**
1853 * ecryptfs_tfm_exists - Search for existing tfm for cipher_name.
1854 * @cipher_name: the name of the cipher to search for
1855 * @key_tfm: set to corresponding tfm if found
1856 *
1857 * Searches for cached key_tfm matching @cipher_name
1858 * Must be called with &key_tfm_list_mutex held
1859 * Returns 1 if found, with @key_tfm set
1860 * Returns 0 if not found, with @key_tfm set to NULL
1861 */
1862int ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm)
1863{
1864 struct ecryptfs_key_tfm *tmp_key_tfm;
1865
1866 BUG_ON(!mutex_is_locked(&key_tfm_list_mutex));
1867
1868 list_for_each_entry(tmp_key_tfm, &key_tfm_list, key_tfm_list) {
1869 if (strcmp(tmp_key_tfm->cipher_name, cipher_name) == 0) {
1870 if (key_tfm)
1871 (*key_tfm) = tmp_key_tfm;
1872 return 1;
1873 }
1874 }
1875 if (key_tfm)
1876 (*key_tfm) = NULL;
1877 return 0;
1878}
1879
1880/**
1881 * ecryptfs_get_tfm_and_mutex_for_cipher_name
1882 *
1883 * @tfm: set to cached tfm found, or new tfm created
1884 * @tfm_mutex: set to mutex for cached tfm found, or new tfm created
1885 * @cipher_name: the name of the cipher to search for and/or add
1886 *
1887 * Sets pointers to @tfm & @tfm_mutex matching @cipher_name.
1888 * Searches for cached item first, and creates new if not found.
1889 * Returns 0 on success, non-zero if adding new cipher failed
1890 */
1871int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm, 1891int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm,
1872 struct mutex **tfm_mutex, 1892 struct mutex **tfm_mutex,
1873 char *cipher_name) 1893 char *cipher_name)
@@ -1877,22 +1897,17 @@ int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm,
1877 1897
1878 (*tfm) = NULL; 1898 (*tfm) = NULL;
1879 (*tfm_mutex) = NULL; 1899 (*tfm_mutex) = NULL;
1900
1880 mutex_lock(&key_tfm_list_mutex); 1901 mutex_lock(&key_tfm_list_mutex);
1881 list_for_each_entry(key_tfm, &key_tfm_list, key_tfm_list) { 1902 if (!ecryptfs_tfm_exists(cipher_name, &key_tfm)) {
1882 if (strcmp(key_tfm->cipher_name, cipher_name) == 0) { 1903 rc = ecryptfs_add_new_key_tfm(&key_tfm, cipher_name, 0);
1883 (*tfm) = key_tfm->key_tfm; 1904 if (rc) {
1884 (*tfm_mutex) = &key_tfm->key_tfm_mutex; 1905 printk(KERN_ERR "Error adding new key_tfm to list; "
1885 mutex_unlock(&key_tfm_list_mutex); 1906 "rc = [%d]\n", rc);
1886 goto out; 1907 goto out;
1887 } 1908 }
1888 } 1909 }
1889 mutex_unlock(&key_tfm_list_mutex); 1910 mutex_unlock(&key_tfm_list_mutex);
1890 rc = ecryptfs_add_new_key_tfm(&key_tfm, cipher_name, 0);
1891 if (rc) {
1892 printk(KERN_ERR "Error adding new key_tfm to list; rc = [%d]\n",
1893 rc);
1894 goto out;
1895 }
1896 (*tfm) = key_tfm->key_tfm; 1911 (*tfm) = key_tfm->key_tfm;
1897 (*tfm_mutex) = &key_tfm->key_tfm_mutex; 1912 (*tfm_mutex) = &key_tfm->key_tfm_mutex;
1898out: 1913out:
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index ce7a5d4aec36..5007f788da01 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -234,10 +234,11 @@ struct ecryptfs_crypt_stat {
234#define ECRYPTFS_KEY_VALID 0x00000080 234#define ECRYPTFS_KEY_VALID 0x00000080
235#define ECRYPTFS_METADATA_IN_XATTR 0x00000100 235#define ECRYPTFS_METADATA_IN_XATTR 0x00000100
236#define ECRYPTFS_VIEW_AS_ENCRYPTED 0x00000200 236#define ECRYPTFS_VIEW_AS_ENCRYPTED 0x00000200
237#define ECRYPTFS_KEY_SET 0x00000400
237 u32 flags; 238 u32 flags;
238 unsigned int file_version; 239 unsigned int file_version;
239 size_t iv_bytes; 240 size_t iv_bytes;
240 size_t num_header_extents_at_front; 241 size_t num_header_bytes_at_front;
241 size_t extent_size; /* Data extent size; default is 4096 */ 242 size_t extent_size; /* Data extent size; default is 4096 */
242 size_t key_size; 243 size_t key_size;
243 size_t extent_shift; 244 size_t extent_shift;
@@ -322,7 +323,6 @@ struct ecryptfs_key_tfm {
322 unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1]; 323 unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
323}; 324};
324 325
325extern struct list_head key_tfm_list;
326extern struct mutex key_tfm_list_mutex; 326extern struct mutex key_tfm_list_mutex;
327 327
328/** 328/**
@@ -521,11 +521,9 @@ extern struct kmem_cache *ecryptfs_file_info_cache;
521extern struct kmem_cache *ecryptfs_dentry_info_cache; 521extern struct kmem_cache *ecryptfs_dentry_info_cache;
522extern struct kmem_cache *ecryptfs_inode_info_cache; 522extern struct kmem_cache *ecryptfs_inode_info_cache;
523extern struct kmem_cache *ecryptfs_sb_info_cache; 523extern struct kmem_cache *ecryptfs_sb_info_cache;
524extern struct kmem_cache *ecryptfs_header_cache_0;
525extern struct kmem_cache *ecryptfs_header_cache_1; 524extern struct kmem_cache *ecryptfs_header_cache_1;
526extern struct kmem_cache *ecryptfs_header_cache_2; 525extern struct kmem_cache *ecryptfs_header_cache_2;
527extern struct kmem_cache *ecryptfs_xattr_cache; 526extern struct kmem_cache *ecryptfs_xattr_cache;
528extern struct kmem_cache *ecryptfs_lower_page_cache;
529extern struct kmem_cache *ecryptfs_key_record_cache; 527extern struct kmem_cache *ecryptfs_key_record_cache;
530extern struct kmem_cache *ecryptfs_key_sig_cache; 528extern struct kmem_cache *ecryptfs_key_sig_cache;
531extern struct kmem_cache *ecryptfs_global_auth_tok_cache; 529extern struct kmem_cache *ecryptfs_global_auth_tok_cache;
@@ -562,8 +560,8 @@ int ecryptfs_read_and_validate_header_region(char *data,
562 struct inode *ecryptfs_inode); 560 struct inode *ecryptfs_inode);
563int ecryptfs_read_and_validate_xattr_region(char *page_virt, 561int ecryptfs_read_and_validate_xattr_region(char *page_virt,
564 struct dentry *ecryptfs_dentry); 562 struct dentry *ecryptfs_dentry);
565u16 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat); 563u8 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat);
566int ecryptfs_cipher_code_to_string(char *str, u16 cipher_code); 564int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code);
567void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat); 565void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat);
568int ecryptfs_generate_key_packet_set(char *dest_base, 566int ecryptfs_generate_key_packet_set(char *dest_base,
569 struct ecryptfs_crypt_stat *crypt_stat, 567 struct ecryptfs_crypt_stat *crypt_stat,
@@ -576,8 +574,6 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length);
576int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode); 574int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode);
577int ecryptfs_inode_set(struct inode *inode, void *lower_inode); 575int ecryptfs_inode_set(struct inode *inode, void *lower_inode);
578void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode); 576void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode);
579ssize_t ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value,
580 size_t size);
581ssize_t 577ssize_t
582ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name, 578ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
583 void *value, size_t size); 579 void *value, size_t size);
@@ -623,6 +619,7 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
623 size_t key_size); 619 size_t key_size);
624int ecryptfs_init_crypto(void); 620int ecryptfs_init_crypto(void);
625int ecryptfs_destroy_crypto(void); 621int ecryptfs_destroy_crypto(void);
622int ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm);
626int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm, 623int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm,
627 struct mutex **tfm_mutex, 624 struct mutex **tfm_mutex,
628 char *cipher_name); 625 char *cipher_name);
@@ -631,8 +628,6 @@ int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key,
631 char *sig); 628 char *sig);
632int ecryptfs_write_zeros(struct file *file, pgoff_t index, int start, 629int ecryptfs_write_zeros(struct file *file, pgoff_t index, int start,
633 int num_zeros); 630 int num_zeros);
634void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num,
635 struct ecryptfs_crypt_stat *crypt_stat);
636int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data, 631int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
637 loff_t offset, size_t size); 632 loff_t offset, size_t size);
638int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode, 633int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
@@ -646,8 +641,6 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
646 pgoff_t page_index, 641 pgoff_t page_index,
647 size_t offset_in_page, size_t size, 642 size_t offset_in_page, size_t size,
648 struct inode *ecryptfs_inode); 643 struct inode *ecryptfs_inode);
649int ecryptfs_read(char *data, loff_t offset, size_t size,
650 struct file *ecryptfs_file);
651struct page *ecryptfs_get_locked_page(struct file *file, loff_t index); 644struct page *ecryptfs_get_locked_page(struct file *file, loff_t index);
652 645
653#endif /* #ifndef ECRYPTFS_KERNEL_H */ 646#endif /* #ifndef ECRYPTFS_KERNEL_H */
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index c98c4690a771..2b8f5ed4adea 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -209,9 +209,10 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
209 if (!(mount_crypt_stat->flags 209 if (!(mount_crypt_stat->flags
210 & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { 210 & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
211 rc = -EIO; 211 rc = -EIO;
212 printk(KERN_WARNING "Attempt to read file that " 212 printk(KERN_WARNING "Either the lower file "
213 "is not in a valid eCryptfs format, " 213 "is not in a valid eCryptfs format, "
214 "and plaintext passthrough mode is not " 214 "or the key could not be retrieved. "
215 "Plaintext passthrough mode is not "
215 "enabled; returning -EIO\n"); 216 "enabled; returning -EIO\n");
216 mutex_unlock(&crypt_stat->cs_mutex); 217 mutex_unlock(&crypt_stat->cs_mutex);
217 goto out_free; 218 goto out_free;
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 5a719180983c..edd1e44e9d47 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -365,8 +365,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
365 dentry->d_sb)->mount_crypt_stat; 365 dentry->d_sb)->mount_crypt_stat;
366 if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) { 366 if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) {
367 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) 367 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
368 file_size = ((crypt_stat->extent_size 368 file_size = (crypt_stat->num_header_bytes_at_front
369 * crypt_stat->num_header_extents_at_front)
370 + i_size_read(lower_dentry->d_inode)); 369 + i_size_read(lower_dentry->d_inode));
371 else 370 else
372 file_size = i_size_read(lower_dentry->d_inode); 371 file_size = i_size_read(lower_dentry->d_inode);
@@ -685,7 +684,7 @@ ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
685 * @crypt_stat: Crypt_stat associated with file 684 * @crypt_stat: Crypt_stat associated with file
686 * @upper_size: Size of the upper file 685 * @upper_size: Size of the upper file
687 * 686 *
688 * Calculate the requried size of the lower file based on the 687 * Calculate the required size of the lower file based on the
689 * specified size of the upper file. This calculation is based on the 688 * specified size of the upper file. This calculation is based on the
690 * number of headers in the underlying file and the extent size. 689 * number of headers in the underlying file and the extent size.
691 * 690 *
@@ -697,8 +696,7 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
697{ 696{
698 loff_t lower_size; 697 loff_t lower_size;
699 698
700 lower_size = (crypt_stat->extent_size 699 lower_size = crypt_stat->num_header_bytes_at_front;
701 * crypt_stat->num_header_extents_at_front);
702 if (upper_size != 0) { 700 if (upper_size != 0) {
703 loff_t num_extents; 701 loff_t num_extents;
704 702
@@ -875,11 +873,11 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
875 if (!(mount_crypt_stat->flags 873 if (!(mount_crypt_stat->flags
876 & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { 874 & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
877 rc = -EIO; 875 rc = -EIO;
878 printk(KERN_WARNING "Attempt to read file that " 876 printk(KERN_WARNING "Either the lower file "
879 "is not in a valid eCryptfs format, " 877 "is not in a valid eCryptfs format, "
880 "and plaintext passthrough mode is not " 878 "or the key could not be retrieved. "
879 "Plaintext passthrough mode is not "
881 "enabled; returning -EIO\n"); 880 "enabled; returning -EIO\n");
882
883 mutex_unlock(&crypt_stat->cs_mutex); 881 mutex_unlock(&crypt_stat->cs_mutex);
884 goto out; 882 goto out;
885 } 883 }
@@ -954,7 +952,7 @@ out:
954 return rc; 952 return rc;
955} 953}
956 954
957ssize_t 955static ssize_t
958ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value, 956ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value,
959 size_t size) 957 size_t size)
960{ 958{
diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
index f458c1f35565..682b1b2482c2 100644
--- a/fs/ecryptfs/keystore.c
+++ b/fs/ecryptfs/keystore.c
@@ -189,7 +189,7 @@ out:
189} 189}
190 190
191static int 191static int
192parse_tag_65_packet(struct ecryptfs_session_key *session_key, u16 *cipher_code, 192parse_tag_65_packet(struct ecryptfs_session_key *session_key, u8 *cipher_code,
193 struct ecryptfs_message *msg) 193 struct ecryptfs_message *msg)
194{ 194{
195 size_t i = 0; 195 size_t i = 0;
@@ -275,7 +275,7 @@ out:
275 275
276 276
277static int 277static int
278write_tag_66_packet(char *signature, size_t cipher_code, 278write_tag_66_packet(char *signature, u8 cipher_code,
279 struct ecryptfs_crypt_stat *crypt_stat, char **packet, 279 struct ecryptfs_crypt_stat *crypt_stat, char **packet,
280 size_t *packet_len) 280 size_t *packet_len)
281{ 281{
@@ -428,7 +428,7 @@ static int
428decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok, 428decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
429 struct ecryptfs_crypt_stat *crypt_stat) 429 struct ecryptfs_crypt_stat *crypt_stat)
430{ 430{
431 u16 cipher_code = 0; 431 u8 cipher_code = 0;
432 struct ecryptfs_msg_ctx *msg_ctx; 432 struct ecryptfs_msg_ctx *msg_ctx;
433 struct ecryptfs_message *msg = NULL; 433 struct ecryptfs_message *msg = NULL;
434 char *auth_tok_sig; 434 char *auth_tok_sig;
@@ -1537,7 +1537,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
1537 struct scatterlist dst_sg; 1537 struct scatterlist dst_sg;
1538 struct scatterlist src_sg; 1538 struct scatterlist src_sg;
1539 struct mutex *tfm_mutex = NULL; 1539 struct mutex *tfm_mutex = NULL;
1540 size_t cipher_code; 1540 u8 cipher_code;
1541 size_t packet_size_length; 1541 size_t packet_size_length;
1542 size_t max_packet_size; 1542 size_t max_packet_size;
1543 struct ecryptfs_mount_crypt_stat *mount_crypt_stat = 1543 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 0249aa4ae181..778c420e4cac 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -117,7 +117,7 @@ void __ecryptfs_printk(const char *fmt, ...)
117 * 117 *
118 * Returns zero on success; non-zero otherwise 118 * Returns zero on success; non-zero otherwise
119 */ 119 */
120int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry) 120static int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
121{ 121{
122 struct ecryptfs_inode_info *inode_info = 122 struct ecryptfs_inode_info *inode_info =
123 ecryptfs_inode_to_private(ecryptfs_dentry->d_inode); 123 ecryptfs_inode_to_private(ecryptfs_dentry->d_inode);
@@ -226,17 +226,15 @@ out:
226 return rc; 226 return rc;
227} 227}
228 228
229enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, ecryptfs_opt_debug, 229enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
230 ecryptfs_opt_ecryptfs_debug, ecryptfs_opt_cipher, 230 ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher,
231 ecryptfs_opt_ecryptfs_cipher, ecryptfs_opt_ecryptfs_key_bytes, 231 ecryptfs_opt_ecryptfs_key_bytes,
232 ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata, 232 ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata,
233 ecryptfs_opt_encrypted_view, ecryptfs_opt_err }; 233 ecryptfs_opt_encrypted_view, ecryptfs_opt_err };
234 234
235static match_table_t tokens = { 235static match_table_t tokens = {
236 {ecryptfs_opt_sig, "sig=%s"}, 236 {ecryptfs_opt_sig, "sig=%s"},
237 {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"}, 237 {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"},
238 {ecryptfs_opt_debug, "debug=%u"},
239 {ecryptfs_opt_ecryptfs_debug, "ecryptfs_debug=%u"},
240 {ecryptfs_opt_cipher, "cipher=%s"}, 238 {ecryptfs_opt_cipher, "cipher=%s"},
241 {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"}, 239 {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"},
242 {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"}, 240 {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"},
@@ -313,7 +311,6 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options)
313 substring_t args[MAX_OPT_ARGS]; 311 substring_t args[MAX_OPT_ARGS];
314 int token; 312 int token;
315 char *sig_src; 313 char *sig_src;
316 char *debug_src;
317 char *cipher_name_dst; 314 char *cipher_name_dst;
318 char *cipher_name_src; 315 char *cipher_name_src;
319 char *cipher_key_bytes_src; 316 char *cipher_key_bytes_src;
@@ -341,16 +338,6 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options)
341 } 338 }
342 sig_set = 1; 339 sig_set = 1;
343 break; 340 break;
344 case ecryptfs_opt_debug:
345 case ecryptfs_opt_ecryptfs_debug:
346 debug_src = args[0].from;
347 ecryptfs_verbosity =
348 (int)simple_strtol(debug_src, &debug_src,
349 0);
350 ecryptfs_printk(KERN_DEBUG,
351 "Verbosity set to [%d]" "\n",
352 ecryptfs_verbosity);
353 break;
354 case ecryptfs_opt_cipher: 341 case ecryptfs_opt_cipher:
355 case ecryptfs_opt_ecryptfs_cipher: 342 case ecryptfs_opt_ecryptfs_cipher:
356 cipher_name_src = args[0].from; 343 cipher_name_src = args[0].from;
@@ -423,9 +410,13 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options)
423 if (!cipher_key_bytes_set) { 410 if (!cipher_key_bytes_set) {
424 mount_crypt_stat->global_default_cipher_key_size = 0; 411 mount_crypt_stat->global_default_cipher_key_size = 0;
425 } 412 }
426 rc = ecryptfs_add_new_key_tfm( 413 mutex_lock(&key_tfm_list_mutex);
427 NULL, mount_crypt_stat->global_default_cipher_name, 414 if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
428 mount_crypt_stat->global_default_cipher_key_size); 415 NULL))
416 rc = ecryptfs_add_new_key_tfm(
417 NULL, mount_crypt_stat->global_default_cipher_name,
418 mount_crypt_stat->global_default_cipher_key_size);
419 mutex_unlock(&key_tfm_list_mutex);
429 if (rc) { 420 if (rc) {
430 printk(KERN_ERR "Error attempting to initialize cipher with " 421 printk(KERN_ERR "Error attempting to initialize cipher with "
431 "name = [%s] and key size = [%td]; rc = [%d]\n", 422 "name = [%s] and key size = [%td]; rc = [%d]\n",
@@ -654,11 +645,6 @@ static struct ecryptfs_cache_info {
654 .size = sizeof(struct ecryptfs_sb_info), 645 .size = sizeof(struct ecryptfs_sb_info),
655 }, 646 },
656 { 647 {
657 .cache = &ecryptfs_header_cache_0,
658 .name = "ecryptfs_headers_0",
659 .size = PAGE_CACHE_SIZE,
660 },
661 {
662 .cache = &ecryptfs_header_cache_1, 648 .cache = &ecryptfs_header_cache_1,
663 .name = "ecryptfs_headers_1", 649 .name = "ecryptfs_headers_1",
664 .size = PAGE_CACHE_SIZE, 650 .size = PAGE_CACHE_SIZE,
@@ -821,6 +807,10 @@ static int __init ecryptfs_init(void)
821 "rc = [%d]\n", rc); 807 "rc = [%d]\n", rc);
822 goto out_release_messaging; 808 goto out_release_messaging;
823 } 809 }
810 if (ecryptfs_verbosity > 0)
811 printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values "
812 "will be written to the syslog!\n", ecryptfs_verbosity);
813
824 goto out; 814 goto out;
825out_release_messaging: 815out_release_messaging:
826 ecryptfs_release_messaging(ecryptfs_transport); 816 ecryptfs_release_messaging(ecryptfs_transport);
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 0535412d8c64..dc74b186145d 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -34,8 +34,6 @@
34#include <linux/scatterlist.h> 34#include <linux/scatterlist.h>
35#include "ecryptfs_kernel.h" 35#include "ecryptfs_kernel.h"
36 36
37struct kmem_cache *ecryptfs_lower_page_cache;
38
39/** 37/**
40 * ecryptfs_get_locked_page 38 * ecryptfs_get_locked_page
41 * 39 *
@@ -102,13 +100,14 @@ static void set_header_info(char *page_virt,
102 struct ecryptfs_crypt_stat *crypt_stat) 100 struct ecryptfs_crypt_stat *crypt_stat)
103{ 101{
104 size_t written; 102 size_t written;
105 int save_num_header_extents_at_front = 103 size_t save_num_header_bytes_at_front =
106 crypt_stat->num_header_extents_at_front; 104 crypt_stat->num_header_bytes_at_front;
107 105
108 crypt_stat->num_header_extents_at_front = 1; 106 crypt_stat->num_header_bytes_at_front =
107 ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE;
109 ecryptfs_write_header_metadata(page_virt + 20, crypt_stat, &written); 108 ecryptfs_write_header_metadata(page_virt + 20, crypt_stat, &written);
110 crypt_stat->num_header_extents_at_front = 109 crypt_stat->num_header_bytes_at_front =
111 save_num_header_extents_at_front; 110 save_num_header_bytes_at_front;
112} 111}
113 112
114/** 113/**
@@ -134,8 +133,11 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
134 loff_t view_extent_num = ((((loff_t)page->index) 133 loff_t view_extent_num = ((((loff_t)page->index)
135 * num_extents_per_page) 134 * num_extents_per_page)
136 + extent_num_in_page); 135 + extent_num_in_page);
136 size_t num_header_extents_at_front =
137 (crypt_stat->num_header_bytes_at_front
138 / crypt_stat->extent_size);
137 139
138 if (view_extent_num < crypt_stat->num_header_extents_at_front) { 140 if (view_extent_num < num_header_extents_at_front) {
139 /* This is a header extent */ 141 /* This is a header extent */
140 char *page_virt; 142 char *page_virt;
141 143
@@ -157,9 +159,8 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
157 } else { 159 } else {
158 /* This is an encrypted data extent */ 160 /* This is an encrypted data extent */
159 loff_t lower_offset = 161 loff_t lower_offset =
160 ((view_extent_num - 162 ((view_extent_num * crypt_stat->extent_size)
161 crypt_stat->num_header_extents_at_front) 163 - crypt_stat->num_header_bytes_at_front);
162 * crypt_stat->extent_size);
163 164
164 rc = ecryptfs_read_lower_page_segment( 165 rc = ecryptfs_read_lower_page_segment(
165 page, (lower_offset >> PAGE_CACHE_SHIFT), 166 page, (lower_offset >> PAGE_CACHE_SHIFT),
diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
index 948f57624c05..0c4928623bbc 100644
--- a/fs/ecryptfs/read_write.c
+++ b/fs/ecryptfs/read_write.c
@@ -293,6 +293,7 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
293 return rc; 293 return rc;
294} 294}
295 295
296#if 0
296/** 297/**
297 * ecryptfs_read 298 * ecryptfs_read
298 * @data: The virtual address into which to write the data read (and 299 * @data: The virtual address into which to write the data read (and
@@ -371,3 +372,4 @@ int ecryptfs_read(char *data, loff_t offset, size_t size,
371out: 372out:
372 return rc; 373 return rc;
373} 374}
375#endif /* 0 */
diff --git a/fs/ecryptfs/super.c b/fs/ecryptfs/super.c
index 4859c4eecd65..c27ac2b358a1 100644
--- a/fs/ecryptfs/super.c
+++ b/fs/ecryptfs/super.c
@@ -156,32 +156,38 @@ static void ecryptfs_clear_inode(struct inode *inode)
156/** 156/**
157 * ecryptfs_show_options 157 * ecryptfs_show_options
158 * 158 *
159 * Prints the directory we are currently mounted over. 159 * Prints the mount options for a given superblock.
160 * Returns zero on success; non-zero otherwise 160 * Returns zero; does not fail.
161 */ 161 */
162static int ecryptfs_show_options(struct seq_file *m, struct vfsmount *mnt) 162static int ecryptfs_show_options(struct seq_file *m, struct vfsmount *mnt)
163{ 163{
164 struct super_block *sb = mnt->mnt_sb; 164 struct super_block *sb = mnt->mnt_sb;
165 struct dentry *lower_root_dentry = ecryptfs_dentry_to_lower(sb->s_root); 165 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
166 struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(sb->s_root); 166 &ecryptfs_superblock_to_private(sb)->mount_crypt_stat;
167 char *tmp_page; 167 struct ecryptfs_global_auth_tok *walker;
168 char *path; 168
169 int rc = 0; 169 mutex_lock(&mount_crypt_stat->global_auth_tok_list_mutex);
170 170 list_for_each_entry(walker,
171 tmp_page = (char *)__get_free_page(GFP_KERNEL); 171 &mount_crypt_stat->global_auth_tok_list,
172 if (!tmp_page) { 172 mount_crypt_stat_list) {
173 rc = -ENOMEM; 173 seq_printf(m, ",ecryptfs_sig=%s", walker->sig);
174 goto out;
175 }
176 path = d_path(lower_root_dentry, lower_mnt, tmp_page, PAGE_SIZE);
177 if (IS_ERR(path)) {
178 rc = PTR_ERR(path);
179 goto out;
180 } 174 }
181 seq_printf(m, ",dir=%s", path); 175 mutex_unlock(&mount_crypt_stat->global_auth_tok_list_mutex);
182 free_page((unsigned long)tmp_page); 176
183out: 177 seq_printf(m, ",ecryptfs_cipher=%s",
184 return rc; 178 mount_crypt_stat->global_default_cipher_name);
179
180 if (mount_crypt_stat->global_default_cipher_key_size)
181 seq_printf(m, ",ecryptfs_key_bytes=%zd",
182 mount_crypt_stat->global_default_cipher_key_size);
183 if (mount_crypt_stat->flags & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)
184 seq_printf(m, ",ecryptfs_passthrough");
185 if (mount_crypt_stat->flags & ECRYPTFS_XATTR_METADATA_ENABLED)
186 seq_printf(m, ",ecryptfs_xattr_metadata");
187 if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
188 seq_printf(m, ",ecryptfs_encrypted_view");
189
190 return 0;
185} 191}
186 192
187const struct super_operations ecryptfs_sops = { 193const struct super_operations ecryptfs_sops = {
diff --git a/fs/eventfd.c b/fs/eventfd.c
index 2ce19c000d2a..a9f130cd50ac 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -15,6 +15,7 @@
15#include <linux/spinlock.h> 15#include <linux/spinlock.h>
16#include <linux/anon_inodes.h> 16#include <linux/anon_inodes.h>
17#include <linux/eventfd.h> 17#include <linux/eventfd.h>
18#include <linux/syscalls.h>
18 19
19struct eventfd_ctx { 20struct eventfd_ctx {
20 wait_queue_head_t wqh; 21 wait_queue_head_t wqh;
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 377ad172d74b..e7b2bafa1dd9 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -69,9 +69,53 @@ struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
69 return desc + offset; 69 return desc + offset;
70} 70}
71 71
72static int ext2_valid_block_bitmap(struct super_block *sb,
73 struct ext2_group_desc *desc,
74 unsigned int block_group,
75 struct buffer_head *bh)
76{
77 ext2_grpblk_t offset;
78 ext2_grpblk_t next_zero_bit;
79 ext2_fsblk_t bitmap_blk;
80 ext2_fsblk_t group_first_block;
81
82 group_first_block = ext2_group_first_block_no(sb, block_group);
83
84 /* check whether block bitmap block number is set */
85 bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
86 offset = bitmap_blk - group_first_block;
87 if (!ext2_test_bit(offset, bh->b_data))
88 /* bad block bitmap */
89 goto err_out;
90
91 /* check whether the inode bitmap block number is set */
92 bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
93 offset = bitmap_blk - group_first_block;
94 if (!ext2_test_bit(offset, bh->b_data))
95 /* bad block bitmap */
96 goto err_out;
97
98 /* check whether the inode table block number is set */
99 bitmap_blk = le32_to_cpu(desc->bg_inode_table);
100 offset = bitmap_blk - group_first_block;
101 next_zero_bit = ext2_find_next_zero_bit(bh->b_data,
102 offset + EXT2_SB(sb)->s_itb_per_group,
103 offset);
104 if (next_zero_bit >= offset + EXT2_SB(sb)->s_itb_per_group)
105 /* good bitmap for inode tables */
106 return 1;
107
108err_out:
109 ext2_error(sb, __FUNCTION__,
110 "Invalid block bitmap - "
111 "block_group = %d, block = %lu",
112 block_group, bitmap_blk);
113 return 0;
114}
115
72/* 116/*
73 * Read the bitmap for a given block_group, reading into the specified 117 * Read the bitmap for a given block_group,and validate the
74 * slot in the superblock's bitmap cache. 118 * bits for block/inode/inode tables are set in the bitmaps
75 * 119 *
76 * Return buffer_head on success or NULL in case of failure. 120 * Return buffer_head on success or NULL in case of failure.
77 */ 121 */
@@ -80,17 +124,36 @@ read_block_bitmap(struct super_block *sb, unsigned int block_group)
80{ 124{
81 struct ext2_group_desc * desc; 125 struct ext2_group_desc * desc;
82 struct buffer_head * bh = NULL; 126 struct buffer_head * bh = NULL;
83 127 ext2_fsblk_t bitmap_blk;
84 desc = ext2_get_group_desc (sb, block_group, NULL); 128
129 desc = ext2_get_group_desc(sb, block_group, NULL);
85 if (!desc) 130 if (!desc)
86 goto error_out; 131 return NULL;
87 bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap)); 132 bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
88 if (!bh) 133 bh = sb_getblk(sb, bitmap_blk);
89 ext2_error (sb, "read_block_bitmap", 134 if (unlikely(!bh)) {
135 ext2_error(sb, __FUNCTION__,
136 "Cannot read block bitmap - "
137 "block_group = %d, block_bitmap = %u",
138 block_group, le32_to_cpu(desc->bg_block_bitmap));
139 return NULL;
140 }
141 if (likely(bh_uptodate_or_lock(bh)))
142 return bh;
143
144 if (bh_submit_read(bh) < 0) {
145 brelse(bh);
146 ext2_error(sb, __FUNCTION__,
90 "Cannot read block bitmap - " 147 "Cannot read block bitmap - "
91 "block_group = %d, block_bitmap = %u", 148 "block_group = %d, block_bitmap = %u",
92 block_group, le32_to_cpu(desc->bg_block_bitmap)); 149 block_group, le32_to_cpu(desc->bg_block_bitmap));
93error_out: 150 return NULL;
151 }
152 if (!ext2_valid_block_bitmap(sb, desc, block_group, bh)) {
153 brelse(bh);
154 return NULL;
155 }
156
94 return bh; 157 return bh;
95} 158}
96 159
@@ -474,11 +537,13 @@ do_more:
474 in_range (block, le32_to_cpu(desc->bg_inode_table), 537 in_range (block, le32_to_cpu(desc->bg_inode_table),
475 sbi->s_itb_per_group) || 538 sbi->s_itb_per_group) ||
476 in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table), 539 in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table),
477 sbi->s_itb_per_group)) 540 sbi->s_itb_per_group)) {
478 ext2_error (sb, "ext2_free_blocks", 541 ext2_error (sb, "ext2_free_blocks",
479 "Freeing blocks in system zones - " 542 "Freeing blocks in system zones - "
480 "Block = %lu, count = %lu", 543 "Block = %lu, count = %lu",
481 block, count); 544 block, count);
545 goto error_return;
546 }
482 547
483 for (i = 0, group_freed = 0; i < count; i++) { 548 for (i = 0, group_freed = 0; i < count; i++) {
484 if (!ext2_clear_bit_atomic(sb_bgl_lock(sbi, block_group), 549 if (!ext2_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
@@ -1250,8 +1315,8 @@ retry_alloc:
1250 smp_rmb(); 1315 smp_rmb();
1251 1316
1252 /* 1317 /*
1253 * Now search the rest of the groups. We assume that 1318 * Now search the rest of the groups. We assume that
1254 * i and gdp correctly point to the last group visited. 1319 * group_no and gdp correctly point to the last group visited.
1255 */ 1320 */
1256 for (bgi = 0; bgi < ngroups; bgi++) { 1321 for (bgi = 0; bgi < ngroups; bgi++) {
1257 group_no++; 1322 group_no++;
@@ -1311,11 +1376,13 @@ allocated:
1311 in_range(ret_block, le32_to_cpu(gdp->bg_inode_table), 1376 in_range(ret_block, le32_to_cpu(gdp->bg_inode_table),
1312 EXT2_SB(sb)->s_itb_per_group) || 1377 EXT2_SB(sb)->s_itb_per_group) ||
1313 in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table), 1378 in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table),
1314 EXT2_SB(sb)->s_itb_per_group)) 1379 EXT2_SB(sb)->s_itb_per_group)) {
1315 ext2_error(sb, "ext2_new_blocks", 1380 ext2_error(sb, "ext2_new_blocks",
1316 "Allocating block in system zone - " 1381 "Allocating block in system zone - "
1317 "blocks from "E2FSBLK", length %lu", 1382 "blocks from "E2FSBLK", length %lu",
1318 ret_block, num); 1383 ret_block, num);
1384 goto out;
1385 }
1319 1386
1320 performed_allocation = 1; 1387 performed_allocation = 1;
1321 1388
@@ -1466,9 +1533,6 @@ int ext2_bg_has_super(struct super_block *sb, int group)
1466 */ 1533 */
1467unsigned long ext2_bg_num_gdb(struct super_block *sb, int group) 1534unsigned long ext2_bg_num_gdb(struct super_block *sb, int group)
1468{ 1535{
1469 if (EXT2_HAS_RO_COMPAT_FEATURE(sb,EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)&& 1536 return ext2_bg_has_super(sb, group) ? EXT2_SB(sb)->s_gdb_count : 0;
1470 !ext2_group_sparse(group))
1471 return 0;
1472 return EXT2_SB(sb)->s_gdb_count;
1473} 1537}
1474 1538
diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index d868e26c15eb..8dededd80fe2 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -703,7 +703,7 @@ const struct file_operations ext2_dir_operations = {
703 .llseek = generic_file_llseek, 703 .llseek = generic_file_llseek,
704 .read = generic_read_dir, 704 .read = generic_read_dir,
705 .readdir = ext2_readdir, 705 .readdir = ext2_readdir,
706 .ioctl = ext2_ioctl, 706 .unlocked_ioctl = ext2_ioctl,
707#ifdef CONFIG_COMPAT 707#ifdef CONFIG_COMPAT
708 .compat_ioctl = ext2_compat_ioctl, 708 .compat_ioctl = ext2_compat_ioctl,
709#endif 709#endif
diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h
index c87ae29c19cb..bb9948cdd50f 100644
--- a/fs/ext2/ext2.h
+++ b/fs/ext2/ext2.h
@@ -139,8 +139,7 @@ int __ext2_write_begin(struct file *file, struct address_space *mapping,
139 struct page **pagep, void **fsdata); 139 struct page **pagep, void **fsdata);
140 140
141/* ioctl.c */ 141/* ioctl.c */
142extern int ext2_ioctl (struct inode *, struct file *, unsigned int, 142extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
143 unsigned long);
144extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long); 143extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
145 144
146/* namei.c */ 145/* namei.c */
diff --git a/fs/ext2/file.c b/fs/ext2/file.c
index c051798459a1..5f2fa9c36293 100644
--- a/fs/ext2/file.c
+++ b/fs/ext2/file.c
@@ -48,7 +48,7 @@ const struct file_operations ext2_file_operations = {
48 .write = do_sync_write, 48 .write = do_sync_write,
49 .aio_read = generic_file_aio_read, 49 .aio_read = generic_file_aio_read,
50 .aio_write = generic_file_aio_write, 50 .aio_write = generic_file_aio_write,
51 .ioctl = ext2_ioctl, 51 .unlocked_ioctl = ext2_ioctl,
52#ifdef CONFIG_COMPAT 52#ifdef CONFIG_COMPAT
53 .compat_ioctl = ext2_compat_ioctl, 53 .compat_ioctl = ext2_compat_ioctl,
54#endif 54#endif
@@ -65,7 +65,7 @@ const struct file_operations ext2_xip_file_operations = {
65 .llseek = generic_file_llseek, 65 .llseek = generic_file_llseek,
66 .read = xip_file_read, 66 .read = xip_file_read,
67 .write = xip_file_write, 67 .write = xip_file_write,
68 .ioctl = ext2_ioctl, 68 .unlocked_ioctl = ext2_ioctl,
69#ifdef CONFIG_COMPAT 69#ifdef CONFIG_COMPAT
70 .compat_ioctl = ext2_compat_ioctl, 70 .compat_ioctl = ext2_compat_ioctl,
71#endif 71#endif
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index b1ab32ab5a77..03978ec2a91c 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -286,15 +286,12 @@ static unsigned long ext2_find_near(struct inode *inode, Indirect *ind)
286 * ext2_find_goal - find a prefered place for allocation. 286 * ext2_find_goal - find a prefered place for allocation.
287 * @inode: owner 287 * @inode: owner
288 * @block: block we want 288 * @block: block we want
289 * @chain: chain of indirect blocks
290 * @partial: pointer to the last triple within a chain 289 * @partial: pointer to the last triple within a chain
291 * 290 *
292 * Returns preferred place for a block (the goal). 291 * Returns preferred place for a block (the goal).
293 */ 292 */
294 293
295static inline int ext2_find_goal(struct inode *inode, 294static inline int ext2_find_goal(struct inode *inode, long block,
296 long block,
297 Indirect chain[4],
298 Indirect *partial) 295 Indirect *partial)
299{ 296{
300 struct ext2_block_alloc_info *block_i; 297 struct ext2_block_alloc_info *block_i;
@@ -569,7 +566,6 @@ static void ext2_splice_branch(struct inode *inode,
569 * 566 *
570 * `handle' can be NULL if create == 0. 567 * `handle' can be NULL if create == 0.
571 * 568 *
572 * The BKL may not be held on entry here. Be sure to take it early.
573 * return > 0, # of blocks mapped or allocated. 569 * return > 0, # of blocks mapped or allocated.
574 * return = 0, if plain lookup failed. 570 * return = 0, if plain lookup failed.
575 * return < 0, error case. 571 * return < 0, error case.
@@ -639,7 +635,7 @@ reread:
639 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info)) 635 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
640 ext2_init_block_alloc_info(inode); 636 ext2_init_block_alloc_info(inode);
641 637
642 goal = ext2_find_goal(inode, iblock, chain, partial); 638 goal = ext2_find_goal(inode, iblock, partial);
643 639
644 /* the number of blocks need to allocate for [d,t]indirect blocks */ 640 /* the number of blocks need to allocate for [d,t]indirect blocks */
645 indirect_blks = (chain + depth) - partial - 1; 641 indirect_blks = (chain + depth) - partial - 1;
diff --git a/fs/ext2/ioctl.c b/fs/ext2/ioctl.c
index 320b2cb3d4d2..b8ea11fee5c6 100644
--- a/fs/ext2/ioctl.c
+++ b/fs/ext2/ioctl.c
@@ -17,9 +17,9 @@
17#include <asm/uaccess.h> 17#include <asm/uaccess.h>
18 18
19 19
20int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, 20long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
21 unsigned long arg)
22{ 21{
22 struct inode *inode = filp->f_dentry->d_inode;
23 struct ext2_inode_info *ei = EXT2_I(inode); 23 struct ext2_inode_info *ei = EXT2_I(inode);
24 unsigned int flags; 24 unsigned int flags;
25 unsigned short rsv_window_size; 25 unsigned short rsv_window_size;
@@ -141,9 +141,6 @@ int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
141#ifdef CONFIG_COMPAT 141#ifdef CONFIG_COMPAT
142long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 142long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
143{ 143{
144 struct inode *inode = file->f_path.dentry->d_inode;
145 int ret;
146
147 /* These are just misnamed, they actually get/put from/to user an int */ 144 /* These are just misnamed, they actually get/put from/to user an int */
148 switch (cmd) { 145 switch (cmd) {
149 case EXT2_IOC32_GETFLAGS: 146 case EXT2_IOC32_GETFLAGS:
@@ -161,9 +158,6 @@ long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
161 default: 158 default:
162 return -ENOIOCTLCMD; 159 return -ENOIOCTLCMD;
163 } 160 }
164 lock_kernel(); 161 return ext2_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
165 ret = ext2_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
166 unlock_kernel();
167 return ret;
168} 162}
169#endif 163#endif
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 6abaf75163f0..1ba18b72d43a 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -234,16 +234,16 @@ static int ext2_show_options(struct seq_file *seq, struct vfsmount *vfs)
234 le16_to_cpu(es->s_def_resgid) != EXT2_DEF_RESGID) { 234 le16_to_cpu(es->s_def_resgid) != EXT2_DEF_RESGID) {
235 seq_printf(seq, ",resgid=%u", sbi->s_resgid); 235 seq_printf(seq, ",resgid=%u", sbi->s_resgid);
236 } 236 }
237 if (test_opt(sb, ERRORS_CONT)) { 237 if (test_opt(sb, ERRORS_RO)) {
238 int def_errors = le16_to_cpu(es->s_errors); 238 int def_errors = le16_to_cpu(es->s_errors);
239 239
240 if (def_errors == EXT2_ERRORS_PANIC || 240 if (def_errors == EXT2_ERRORS_PANIC ||
241 def_errors == EXT2_ERRORS_RO) { 241 def_errors == EXT2_ERRORS_CONTINUE) {
242 seq_puts(seq, ",errors=continue"); 242 seq_puts(seq, ",errors=remount-ro");
243 } 243 }
244 } 244 }
245 if (test_opt(sb, ERRORS_RO)) 245 if (test_opt(sb, ERRORS_CONT))
246 seq_puts(seq, ",errors=remount-ro"); 246 seq_puts(seq, ",errors=continue");
247 if (test_opt(sb, ERRORS_PANIC)) 247 if (test_opt(sb, ERRORS_PANIC))
248 seq_puts(seq, ",errors=panic"); 248 seq_puts(seq, ",errors=panic");
249 if (test_opt(sb, NO_UID32)) 249 if (test_opt(sb, NO_UID32))
@@ -617,27 +617,24 @@ static int ext2_setup_super (struct super_block * sb,
617 return res; 617 return res;
618} 618}
619 619
620static int ext2_check_descriptors (struct super_block * sb) 620static int ext2_check_descriptors(struct super_block *sb)
621{ 621{
622 int i; 622 int i;
623 int desc_block = 0;
624 struct ext2_sb_info *sbi = EXT2_SB(sb); 623 struct ext2_sb_info *sbi = EXT2_SB(sb);
625 unsigned long first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 624 unsigned long first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
626 unsigned long last_block; 625 unsigned long last_block;
627 struct ext2_group_desc * gdp = NULL;
628 626
629 ext2_debug ("Checking group descriptors"); 627 ext2_debug ("Checking group descriptors");
630 628
631 for (i = 0; i < sbi->s_groups_count; i++) 629 for (i = 0; i < sbi->s_groups_count; i++) {
632 { 630 struct ext2_group_desc *gdp = ext2_get_group_desc(sb, i, NULL);
631
633 if (i == sbi->s_groups_count - 1) 632 if (i == sbi->s_groups_count - 1)
634 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1; 633 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
635 else 634 else
636 last_block = first_block + 635 last_block = first_block +
637 (EXT2_BLOCKS_PER_GROUP(sb) - 1); 636 (EXT2_BLOCKS_PER_GROUP(sb) - 1);
638 637
639 if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
640 gdp = (struct ext2_group_desc *) sbi->s_group_desc[desc_block++]->b_data;
641 if (le32_to_cpu(gdp->bg_block_bitmap) < first_block || 638 if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
642 le32_to_cpu(gdp->bg_block_bitmap) > last_block) 639 le32_to_cpu(gdp->bg_block_bitmap) > last_block)
643 { 640 {
@@ -667,7 +664,6 @@ static int ext2_check_descriptors (struct super_block * sb)
667 return 0; 664 return 0;
668 } 665 }
669 first_block += EXT2_BLOCKS_PER_GROUP(sb); 666 first_block += EXT2_BLOCKS_PER_GROUP(sb);
670 gdp++;
671 } 667 }
672 return 1; 668 return 1;
673} 669}
@@ -820,10 +816,10 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
820 816
821 if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC) 817 if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC)
822 set_opt(sbi->s_mount_opt, ERRORS_PANIC); 818 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
823 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_RO) 819 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_CONTINUE)
824 set_opt(sbi->s_mount_opt, ERRORS_RO);
825 else
826 set_opt(sbi->s_mount_opt, ERRORS_CONT); 820 set_opt(sbi->s_mount_opt, ERRORS_CONT);
821 else
822 set_opt(sbi->s_mount_opt, ERRORS_RO);
827 823
828 sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 824 sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
829 sbi->s_resgid = le16_to_cpu(es->s_def_resgid); 825 sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
@@ -868,8 +864,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
868 864
869 blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size); 865 blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
870 866
871 if ((ext2_use_xip(sb)) && ((blocksize != PAGE_SIZE) || 867 if (ext2_use_xip(sb) && blocksize != PAGE_SIZE) {
872 (sb->s_blocksize != blocksize))) {
873 if (!silent) 868 if (!silent)
874 printk("XIP: Unsupported blocksize\n"); 869 printk("XIP: Unsupported blocksize\n");
875 goto failed_mount; 870 goto failed_mount;
diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
index a8ba7e831278..a75713031105 100644
--- a/fs/ext3/balloc.c
+++ b/fs/ext3/balloc.c
@@ -80,13 +80,57 @@ struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
80 return desc + offset; 80 return desc + offset;
81} 81}
82 82
83static int ext3_valid_block_bitmap(struct super_block *sb,
84 struct ext3_group_desc *desc,
85 unsigned int block_group,
86 struct buffer_head *bh)
87{
88 ext3_grpblk_t offset;
89 ext3_grpblk_t next_zero_bit;
90 ext3_fsblk_t bitmap_blk;
91 ext3_fsblk_t group_first_block;
92
93 group_first_block = ext3_group_first_block_no(sb, block_group);
94
95 /* check whether block bitmap block number is set */
96 bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
97 offset = bitmap_blk - group_first_block;
98 if (!ext3_test_bit(offset, bh->b_data))
99 /* bad block bitmap */
100 goto err_out;
101
102 /* check whether the inode bitmap block number is set */
103 bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
104 offset = bitmap_blk - group_first_block;
105 if (!ext3_test_bit(offset, bh->b_data))
106 /* bad block bitmap */
107 goto err_out;
108
109 /* check whether the inode table block number is set */
110 bitmap_blk = le32_to_cpu(desc->bg_inode_table);
111 offset = bitmap_blk - group_first_block;
112 next_zero_bit = ext3_find_next_zero_bit(bh->b_data,
113 offset + EXT3_SB(sb)->s_itb_per_group,
114 offset);
115 if (next_zero_bit >= offset + EXT3_SB(sb)->s_itb_per_group)
116 /* good bitmap for inode tables */
117 return 1;
118
119err_out:
120 ext3_error(sb, __FUNCTION__,
121 "Invalid block bitmap - "
122 "block_group = %d, block = %lu",
123 block_group, bitmap_blk);
124 return 0;
125}
126
83/** 127/**
84 * read_block_bitmap() 128 * read_block_bitmap()
85 * @sb: super block 129 * @sb: super block
86 * @block_group: given block group 130 * @block_group: given block group
87 * 131 *
88 * Read the bitmap for a given block_group, reading into the specified 132 * Read the bitmap for a given block_group,and validate the
89 * slot in the superblock's bitmap cache. 133 * bits for block/inode/inode tables are set in the bitmaps
90 * 134 *
91 * Return buffer_head on success or NULL in case of failure. 135 * Return buffer_head on success or NULL in case of failure.
92 */ 136 */
@@ -95,17 +139,35 @@ read_block_bitmap(struct super_block *sb, unsigned int block_group)
95{ 139{
96 struct ext3_group_desc * desc; 140 struct ext3_group_desc * desc;
97 struct buffer_head * bh = NULL; 141 struct buffer_head * bh = NULL;
142 ext3_fsblk_t bitmap_blk;
98 143
99 desc = ext3_get_group_desc (sb, block_group, NULL); 144 desc = ext3_get_group_desc(sb, block_group, NULL);
100 if (!desc) 145 if (!desc)
101 goto error_out; 146 return NULL;
102 bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap)); 147 bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
103 if (!bh) 148 bh = sb_getblk(sb, bitmap_blk);
104 ext3_error (sb, "read_block_bitmap", 149 if (unlikely(!bh)) {
150 ext3_error(sb, __FUNCTION__,
105 "Cannot read block bitmap - " 151 "Cannot read block bitmap - "
106 "block_group = %d, block_bitmap = %u", 152 "block_group = %d, block_bitmap = %u",
107 block_group, le32_to_cpu(desc->bg_block_bitmap)); 153 block_group, le32_to_cpu(desc->bg_block_bitmap));
108error_out: 154 return NULL;
155 }
156 if (likely(bh_uptodate_or_lock(bh)))
157 return bh;
158
159 if (bh_submit_read(bh) < 0) {
160 brelse(bh);
161 ext3_error(sb, __FUNCTION__,
162 "Cannot read block bitmap - "
163 "block_group = %d, block_bitmap = %u",
164 block_group, le32_to_cpu(desc->bg_block_bitmap));
165 return NULL;
166 }
167 if (!ext3_valid_block_bitmap(sb, desc, block_group, bh)) {
168 brelse(bh);
169 return NULL;
170 }
109 return bh; 171 return bh;
110} 172}
111/* 173/*
@@ -468,11 +530,13 @@ do_more:
468 in_range (block, le32_to_cpu(desc->bg_inode_table), 530 in_range (block, le32_to_cpu(desc->bg_inode_table),
469 sbi->s_itb_per_group) || 531 sbi->s_itb_per_group) ||
470 in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table), 532 in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table),
471 sbi->s_itb_per_group)) 533 sbi->s_itb_per_group)) {
472 ext3_error (sb, "ext3_free_blocks", 534 ext3_error (sb, "ext3_free_blocks",
473 "Freeing blocks in system zones - " 535 "Freeing blocks in system zones - "
474 "Block = "E3FSBLK", count = %lu", 536 "Block = "E3FSBLK", count = %lu",
475 block, count); 537 block, count);
538 goto error_return;
539 }
476 540
477 /* 541 /*
478 * We are about to start releasing blocks in the bitmap, 542 * We are about to start releasing blocks in the bitmap,
@@ -1508,7 +1572,7 @@ retry_alloc:
1508 1572
1509 /* 1573 /*
1510 * Now search the rest of the groups. We assume that 1574 * Now search the rest of the groups. We assume that
1511 * i and gdp correctly point to the last group visited. 1575 * group_no and gdp correctly point to the last group visited.
1512 */ 1576 */
1513 for (bgi = 0; bgi < ngroups; bgi++) { 1577 for (bgi = 0; bgi < ngroups; bgi++) {
1514 group_no++; 1578 group_no++;
@@ -1575,11 +1639,13 @@ allocated:
1575 in_range(ret_block, le32_to_cpu(gdp->bg_inode_table), 1639 in_range(ret_block, le32_to_cpu(gdp->bg_inode_table),
1576 EXT3_SB(sb)->s_itb_per_group) || 1640 EXT3_SB(sb)->s_itb_per_group) ||
1577 in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table), 1641 in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table),
1578 EXT3_SB(sb)->s_itb_per_group)) 1642 EXT3_SB(sb)->s_itb_per_group)) {
1579 ext3_error(sb, "ext3_new_block", 1643 ext3_error(sb, "ext3_new_block",
1580 "Allocating block in system zone - " 1644 "Allocating block in system zone - "
1581 "blocks from "E3FSBLK", length %lu", 1645 "blocks from "E3FSBLK", length %lu",
1582 ret_block, num); 1646 ret_block, num);
1647 goto out;
1648 }
1583 1649
1584 performed_allocation = 1; 1650 performed_allocation = 1;
1585 1651
@@ -1782,11 +1848,7 @@ static unsigned long ext3_bg_num_gdb_meta(struct super_block *sb, int group)
1782 1848
1783static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group) 1849static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group)
1784{ 1850{
1785 if (EXT3_HAS_RO_COMPAT_FEATURE(sb, 1851 return ext3_bg_has_super(sb, group) ? EXT3_SB(sb)->s_gdb_count : 0;
1786 EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
1787 !ext3_group_sparse(group))
1788 return 0;
1789 return EXT3_SB(sb)->s_gdb_count;
1790} 1852}
1791 1853
1792/** 1854/**
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 077535439288..8a9ce2d09bde 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -439,16 +439,14 @@ static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind)
439 * ext3_find_goal - find a prefered place for allocation. 439 * ext3_find_goal - find a prefered place for allocation.
440 * @inode: owner 440 * @inode: owner
441 * @block: block we want 441 * @block: block we want
442 * @chain: chain of indirect blocks
443 * @partial: pointer to the last triple within a chain 442 * @partial: pointer to the last triple within a chain
444 * @goal: place to store the result.
445 * 443 *
446 * Normally this function find the prefered place for block allocation, 444 * Normally this function find the prefered place for block allocation,
447 * stores it in *@goal and returns zero. 445 * returns it.
448 */ 446 */
449 447
450static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block, 448static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block,
451 Indirect chain[4], Indirect *partial) 449 Indirect *partial)
452{ 450{
453 struct ext3_block_alloc_info *block_i; 451 struct ext3_block_alloc_info *block_i;
454 452
@@ -884,7 +882,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
884 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info)) 882 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
885 ext3_init_block_alloc_info(inode); 883 ext3_init_block_alloc_info(inode);
886 884
887 goal = ext3_find_goal(inode, iblock, chain, partial); 885 goal = ext3_find_goal(inode, iblock, partial);
888 886
889 /* the number of blocks need to allocate for [d,t]indirect blocks */ 887 /* the number of blocks need to allocate for [d,t]indirect blocks */
890 indirect_blks = (chain + depth) - partial - 1; 888 indirect_blks = (chain + depth) - partial - 1;
@@ -941,55 +939,45 @@ out:
941 return err; 939 return err;
942} 940}
943 941
944#define DIO_CREDITS (EXT3_RESERVE_TRANS_BLOCKS + 32) 942/* Maximum number of blocks we map for direct IO at once. */
943#define DIO_MAX_BLOCKS 4096
944/*
945 * Number of credits we need for writing DIO_MAX_BLOCKS:
946 * We need sb + group descriptor + bitmap + inode -> 4
947 * For B blocks with A block pointers per block we need:
948 * 1 (triple ind.) + (B/A/A + 2) (doubly ind.) + (B/A + 2) (indirect).
949 * If we plug in 4096 for B and 256 for A (for 1KB block size), we get 25.
950 */
951#define DIO_CREDITS 25
945 952
946static int ext3_get_block(struct inode *inode, sector_t iblock, 953static int ext3_get_block(struct inode *inode, sector_t iblock,
947 struct buffer_head *bh_result, int create) 954 struct buffer_head *bh_result, int create)
948{ 955{
949 handle_t *handle = ext3_journal_current_handle(); 956 handle_t *handle = ext3_journal_current_handle();
950 int ret = 0; 957 int ret = 0, started = 0;
951 unsigned max_blocks = bh_result->b_size >> inode->i_blkbits; 958 unsigned max_blocks = bh_result->b_size >> inode->i_blkbits;
952 959
953 if (!create) 960 if (create && !handle) { /* Direct IO write... */
954 goto get_block; /* A read */ 961 if (max_blocks > DIO_MAX_BLOCKS)
955 962 max_blocks = DIO_MAX_BLOCKS;
956 if (max_blocks == 1) 963 handle = ext3_journal_start(inode, DIO_CREDITS +
957 goto get_block; /* A single block get */ 964 2 * EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb));
958 965 if (IS_ERR(handle)) {
959 if (handle->h_transaction->t_state == T_LOCKED) {
960 /*
961 * Huge direct-io writes can hold off commits for long
962 * periods of time. Let this commit run.
963 */
964 ext3_journal_stop(handle);
965 handle = ext3_journal_start(inode, DIO_CREDITS);
966 if (IS_ERR(handle))
967 ret = PTR_ERR(handle); 966 ret = PTR_ERR(handle);
968 goto get_block; 967 goto out;
969 }
970
971 if (handle->h_buffer_credits <= EXT3_RESERVE_TRANS_BLOCKS) {
972 /*
973 * Getting low on buffer credits...
974 */
975 ret = ext3_journal_extend(handle, DIO_CREDITS);
976 if (ret > 0) {
977 /*
978 * Couldn't extend the transaction. Start a new one.
979 */
980 ret = ext3_journal_restart(handle, DIO_CREDITS);
981 } 968 }
969 started = 1;
982 } 970 }
983 971
984get_block: 972 ret = ext3_get_blocks_handle(handle, inode, iblock,
985 if (ret == 0) {
986 ret = ext3_get_blocks_handle(handle, inode, iblock,
987 max_blocks, bh_result, create, 0); 973 max_blocks, bh_result, create, 0);
988 if (ret > 0) { 974 if (ret > 0) {
989 bh_result->b_size = (ret << inode->i_blkbits); 975 bh_result->b_size = (ret << inode->i_blkbits);
990 ret = 0; 976 ret = 0;
991 }
992 } 977 }
978 if (started)
979 ext3_journal_stop(handle);
980out:
993 return ret; 981 return ret;
994} 982}
995 983
@@ -1680,7 +1668,8 @@ static int ext3_releasepage(struct page *page, gfp_t wait)
1680 * if the machine crashes during the write. 1668 * if the machine crashes during the write.
1681 * 1669 *
1682 * If the O_DIRECT write is intantiating holes inside i_size and the machine 1670 * If the O_DIRECT write is intantiating holes inside i_size and the machine
1683 * crashes then stale disk data _may_ be exposed inside the file. 1671 * crashes then stale disk data _may_ be exposed inside the file. But current
1672 * VFS code falls back into buffered path in that case so we are safe.
1684 */ 1673 */
1685static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, 1674static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
1686 const struct iovec *iov, loff_t offset, 1675 const struct iovec *iov, loff_t offset,
@@ -1689,7 +1678,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
1689 struct file *file = iocb->ki_filp; 1678 struct file *file = iocb->ki_filp;
1690 struct inode *inode = file->f_mapping->host; 1679 struct inode *inode = file->f_mapping->host;
1691 struct ext3_inode_info *ei = EXT3_I(inode); 1680 struct ext3_inode_info *ei = EXT3_I(inode);
1692 handle_t *handle = NULL; 1681 handle_t *handle;
1693 ssize_t ret; 1682 ssize_t ret;
1694 int orphan = 0; 1683 int orphan = 0;
1695 size_t count = iov_length(iov, nr_segs); 1684 size_t count = iov_length(iov, nr_segs);
@@ -1697,17 +1686,21 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
1697 if (rw == WRITE) { 1686 if (rw == WRITE) {
1698 loff_t final_size = offset + count; 1687 loff_t final_size = offset + count;
1699 1688
1700 handle = ext3_journal_start(inode, DIO_CREDITS);
1701 if (IS_ERR(handle)) {
1702 ret = PTR_ERR(handle);
1703 goto out;
1704 }
1705 if (final_size > inode->i_size) { 1689 if (final_size > inode->i_size) {
1690 /* Credits for sb + inode write */
1691 handle = ext3_journal_start(inode, 2);
1692 if (IS_ERR(handle)) {
1693 ret = PTR_ERR(handle);
1694 goto out;
1695 }
1706 ret = ext3_orphan_add(handle, inode); 1696 ret = ext3_orphan_add(handle, inode);
1707 if (ret) 1697 if (ret) {
1708 goto out_stop; 1698 ext3_journal_stop(handle);
1699 goto out;
1700 }
1709 orphan = 1; 1701 orphan = 1;
1710 ei->i_disksize = inode->i_size; 1702 ei->i_disksize = inode->i_size;
1703 ext3_journal_stop(handle);
1711 } 1704 }
1712 } 1705 }
1713 1706
@@ -1715,18 +1708,21 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
1715 offset, nr_segs, 1708 offset, nr_segs,
1716 ext3_get_block, NULL); 1709 ext3_get_block, NULL);
1717 1710
1718 /* 1711 if (orphan) {
1719 * Reacquire the handle: ext3_get_block() can restart the transaction
1720 */
1721 handle = ext3_journal_current_handle();
1722
1723out_stop:
1724 if (handle) {
1725 int err; 1712 int err;
1726 1713
1727 if (orphan && inode->i_nlink) 1714 /* Credits for sb + inode write */
1715 handle = ext3_journal_start(inode, 2);
1716 if (IS_ERR(handle)) {
1717 /* This is really bad luck. We've written the data
1718 * but cannot extend i_size. Bail out and pretend
1719 * the write failed... */
1720 ret = PTR_ERR(handle);
1721 goto out;
1722 }
1723 if (inode->i_nlink)
1728 ext3_orphan_del(handle, inode); 1724 ext3_orphan_del(handle, inode);
1729 if (orphan && ret > 0) { 1725 if (ret > 0) {
1730 loff_t end = offset + ret; 1726 loff_t end = offset + ret;
1731 if (end > inode->i_size) { 1727 if (end > inode->i_size) {
1732 ei->i_disksize = end; 1728 ei->i_disksize = end;
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 4ab6f76e63d0..92b83b004dd8 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -860,14 +860,10 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
860 int nblocks, i, err; 860 int nblocks, i, err;
861 struct inode *dir = dentry->d_parent->d_inode; 861 struct inode *dir = dentry->d_parent->d_inode;
862 int namelen; 862 int namelen;
863 const u8 *name;
864 unsigned blocksize;
865 863
866 *res_dir = NULL; 864 *res_dir = NULL;
867 sb = dir->i_sb; 865 sb = dir->i_sb;
868 blocksize = sb->s_blocksize;
869 namelen = dentry->d_name.len; 866 namelen = dentry->d_name.len;
870 name = dentry->d_name.name;
871 if (namelen > EXT3_NAME_LEN) 867 if (namelen > EXT3_NAME_LEN)
872 return NULL; 868 return NULL;
873 if (is_dx(dir)) { 869 if (is_dx(dir)) {
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index f3675cc630e9..343677e8c350 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -575,16 +575,16 @@ static int ext3_show_options(struct seq_file *seq, struct vfsmount *vfs)
575 le16_to_cpu(es->s_def_resgid) != EXT3_DEF_RESGID) { 575 le16_to_cpu(es->s_def_resgid) != EXT3_DEF_RESGID) {
576 seq_printf(seq, ",resgid=%u", sbi->s_resgid); 576 seq_printf(seq, ",resgid=%u", sbi->s_resgid);
577 } 577 }
578 if (test_opt(sb, ERRORS_CONT)) { 578 if (test_opt(sb, ERRORS_RO)) {
579 int def_errors = le16_to_cpu(es->s_errors); 579 int def_errors = le16_to_cpu(es->s_errors);
580 580
581 if (def_errors == EXT3_ERRORS_PANIC || 581 if (def_errors == EXT3_ERRORS_PANIC ||
582 def_errors == EXT3_ERRORS_RO) { 582 def_errors == EXT3_ERRORS_CONTINUE) {
583 seq_puts(seq, ",errors=continue"); 583 seq_puts(seq, ",errors=remount-ro");
584 } 584 }
585 } 585 }
586 if (test_opt(sb, ERRORS_RO)) 586 if (test_opt(sb, ERRORS_CONT))
587 seq_puts(seq, ",errors=remount-ro"); 587 seq_puts(seq, ",errors=continue");
588 if (test_opt(sb, ERRORS_PANIC)) 588 if (test_opt(sb, ERRORS_PANIC))
589 seq_puts(seq, ",errors=panic"); 589 seq_puts(seq, ",errors=panic");
590 if (test_opt(sb, NO_UID32)) 590 if (test_opt(sb, NO_UID32))
@@ -1252,28 +1252,24 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es,
1252} 1252}
1253 1253
1254/* Called at mount-time, super-block is locked */ 1254/* Called at mount-time, super-block is locked */
1255static int ext3_check_descriptors (struct super_block * sb) 1255static int ext3_check_descriptors(struct super_block *sb)
1256{ 1256{
1257 struct ext3_sb_info *sbi = EXT3_SB(sb); 1257 struct ext3_sb_info *sbi = EXT3_SB(sb);
1258 ext3_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 1258 ext3_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
1259 ext3_fsblk_t last_block; 1259 ext3_fsblk_t last_block;
1260 struct ext3_group_desc * gdp = NULL;
1261 int desc_block = 0;
1262 int i; 1260 int i;
1263 1261
1264 ext3_debug ("Checking group descriptors"); 1262 ext3_debug ("Checking group descriptors");
1265 1263
1266 for (i = 0; i < sbi->s_groups_count; i++) 1264 for (i = 0; i < sbi->s_groups_count; i++) {
1267 { 1265 struct ext3_group_desc *gdp = ext3_get_group_desc(sb, i, NULL);
1266
1268 if (i == sbi->s_groups_count - 1) 1267 if (i == sbi->s_groups_count - 1)
1269 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1; 1268 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
1270 else 1269 else
1271 last_block = first_block + 1270 last_block = first_block +
1272 (EXT3_BLOCKS_PER_GROUP(sb) - 1); 1271 (EXT3_BLOCKS_PER_GROUP(sb) - 1);
1273 1272
1274 if ((i % EXT3_DESC_PER_BLOCK(sb)) == 0)
1275 gdp = (struct ext3_group_desc *)
1276 sbi->s_group_desc[desc_block++]->b_data;
1277 if (le32_to_cpu(gdp->bg_block_bitmap) < first_block || 1273 if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
1278 le32_to_cpu(gdp->bg_block_bitmap) > last_block) 1274 le32_to_cpu(gdp->bg_block_bitmap) > last_block)
1279 { 1275 {
@@ -1306,7 +1302,6 @@ static int ext3_check_descriptors (struct super_block * sb)
1306 return 0; 1302 return 0;
1307 } 1303 }
1308 first_block += EXT3_BLOCKS_PER_GROUP(sb); 1304 first_block += EXT3_BLOCKS_PER_GROUP(sb);
1309 gdp++;
1310 } 1305 }
1311 1306
1312 sbi->s_es->s_free_blocks_count=cpu_to_le32(ext3_count_free_blocks(sb)); 1307 sbi->s_es->s_free_blocks_count=cpu_to_le32(ext3_count_free_blocks(sb));
@@ -1583,10 +1578,10 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1583 1578
1584 if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC) 1579 if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC)
1585 set_opt(sbi->s_mount_opt, ERRORS_PANIC); 1580 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
1586 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_RO) 1581 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_CONTINUE)
1587 set_opt(sbi->s_mount_opt, ERRORS_RO);
1588 else
1589 set_opt(sbi->s_mount_opt, ERRORS_CONT); 1582 set_opt(sbi->s_mount_opt, ERRORS_CONT);
1583 else
1584 set_opt(sbi->s_mount_opt, ERRORS_RO);
1590 1585
1591 sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 1586 sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
1592 sbi->s_resgid = le16_to_cpu(es->s_def_resgid); 1587 sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index ac75ea953d83..0737e05ba3dd 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -1700,7 +1700,7 @@ retry_alloc:
1700 1700
1701 /* 1701 /*
1702 * Now search the rest of the groups. We assume that 1702 * Now search the rest of the groups. We assume that
1703 * i and gdp correctly point to the last group visited. 1703 * group_no and gdp correctly point to the last group visited.
1704 */ 1704 */
1705 for (bgi = 0; bgi < ngroups; bgi++) { 1705 for (bgi = 0; bgi < ngroups; bgi++) {
1706 group_no++; 1706 group_no++;
@@ -2011,11 +2011,7 @@ static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb,
2011static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb, 2011static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb,
2012 ext4_group_t group) 2012 ext4_group_t group)
2013{ 2013{
2014 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 2014 return ext4_bg_has_super(sb, group) ? EXT4_SB(sb)->s_gdb_count : 0;
2015 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
2016 !ext4_group_sparse(group))
2017 return 0;
2018 return EXT4_SB(sb)->s_gdb_count;
2019} 2015}
2020 2016
2021/** 2017/**
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 05c4145dd27d..0e9055cf700e 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -429,16 +429,13 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
429 * ext4_find_goal - find a prefered place for allocation. 429 * ext4_find_goal - find a prefered place for allocation.
430 * @inode: owner 430 * @inode: owner
431 * @block: block we want 431 * @block: block we want
432 * @chain: chain of indirect blocks
433 * @partial: pointer to the last triple within a chain 432 * @partial: pointer to the last triple within a chain
434 * @goal: place to store the result.
435 * 433 *
436 * Normally this function find the prefered place for block allocation, 434 * Normally this function find the prefered place for block allocation,
437 * stores it in *@goal and returns zero. 435 * returns it.
438 */ 436 */
439
440static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block, 437static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block,
441 Indirect chain[4], Indirect *partial) 438 Indirect *partial)
442{ 439{
443 struct ext4_block_alloc_info *block_i; 440 struct ext4_block_alloc_info *block_i;
444 441
@@ -839,7 +836,7 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
839 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info)) 836 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
840 ext4_init_block_alloc_info(inode); 837 ext4_init_block_alloc_info(inode);
841 838
842 goal = ext4_find_goal(inode, iblock, chain, partial); 839 goal = ext4_find_goal(inode, iblock, partial);
843 840
844 /* the number of blocks need to allocate for [d,t]indirect blocks */ 841 /* the number of blocks need to allocate for [d,t]indirect blocks */
845 indirect_blks = (chain + depth) - partial - 1; 842 indirect_blks = (chain + depth) - partial - 1;
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 055a0cd0168e..c89bb8797765 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1458,7 +1458,7 @@ int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group,
1458} 1458}
1459 1459
1460/* Called at mount-time, super-block is locked */ 1460/* Called at mount-time, super-block is locked */
1461static int ext4_check_descriptors (struct super_block * sb) 1461static int ext4_check_descriptors(struct super_block *sb)
1462{ 1462{
1463 struct ext4_sb_info *sbi = EXT4_SB(sb); 1463 struct ext4_sb_info *sbi = EXT4_SB(sb);
1464 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 1464 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
@@ -1466,8 +1466,6 @@ static int ext4_check_descriptors (struct super_block * sb)
1466 ext4_fsblk_t block_bitmap; 1466 ext4_fsblk_t block_bitmap;
1467 ext4_fsblk_t inode_bitmap; 1467 ext4_fsblk_t inode_bitmap;
1468 ext4_fsblk_t inode_table; 1468 ext4_fsblk_t inode_table;
1469 struct ext4_group_desc * gdp = NULL;
1470 int desc_block = 0;
1471 int flexbg_flag = 0; 1469 int flexbg_flag = 0;
1472 ext4_group_t i; 1470 ext4_group_t i;
1473 1471
@@ -1476,17 +1474,15 @@ static int ext4_check_descriptors (struct super_block * sb)
1476 1474
1477 ext4_debug ("Checking group descriptors"); 1475 ext4_debug ("Checking group descriptors");
1478 1476
1479 for (i = 0; i < sbi->s_groups_count; i++) 1477 for (i = 0; i < sbi->s_groups_count; i++) {
1480 { 1478 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
1479
1481 if (i == sbi->s_groups_count - 1 || flexbg_flag) 1480 if (i == sbi->s_groups_count - 1 || flexbg_flag)
1482 last_block = ext4_blocks_count(sbi->s_es) - 1; 1481 last_block = ext4_blocks_count(sbi->s_es) - 1;
1483 else 1482 else
1484 last_block = first_block + 1483 last_block = first_block +
1485 (EXT4_BLOCKS_PER_GROUP(sb) - 1); 1484 (EXT4_BLOCKS_PER_GROUP(sb) - 1);
1486 1485
1487 if ((i % EXT4_DESC_PER_BLOCK(sb)) == 0)
1488 gdp = (struct ext4_group_desc *)
1489 sbi->s_group_desc[desc_block++]->b_data;
1490 block_bitmap = ext4_block_bitmap(sb, gdp); 1486 block_bitmap = ext4_block_bitmap(sb, gdp);
1491 if (block_bitmap < first_block || block_bitmap > last_block) 1487 if (block_bitmap < first_block || block_bitmap > last_block)
1492 { 1488 {
@@ -1524,8 +1520,6 @@ static int ext4_check_descriptors (struct super_block * sb)
1524 } 1520 }
1525 if (!flexbg_flag) 1521 if (!flexbg_flag)
1526 first_block += EXT4_BLOCKS_PER_GROUP(sb); 1522 first_block += EXT4_BLOCKS_PER_GROUP(sb);
1527 gdp = (struct ext4_group_desc *)
1528 ((__u8 *)gdp + EXT4_DESC_SIZE(sb));
1529 } 1523 }
1530 1524
1531 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb)); 1525 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb));
diff --git a/fs/fat/file.c b/fs/fat/file.c
index 69a83b59dce8..c614175876e0 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -155,6 +155,42 @@ out:
155 return err; 155 return err;
156} 156}
157 157
158static int check_mode(const struct msdos_sb_info *sbi, mode_t mode)
159{
160 mode_t req = mode & ~S_IFMT;
161
162 /*
163 * Of the r and x bits, all (subject to umask) must be present. Of the
164 * w bits, either all (subject to umask) or none must be present.
165 */
166
167 if (S_ISREG(mode)) {
168 req &= ~sbi->options.fs_fmask;
169
170 if ((req & (S_IRUGO | S_IXUGO)) !=
171 ((S_IRUGO | S_IXUGO) & ~sbi->options.fs_fmask))
172 return -EPERM;
173
174 if ((req & S_IWUGO) != 0 &&
175 (req & S_IWUGO) != (S_IWUGO & ~sbi->options.fs_fmask))
176 return -EPERM;
177 } else if (S_ISDIR(mode)) {
178 req &= ~sbi->options.fs_dmask;
179
180 if ((req & (S_IRUGO | S_IXUGO)) !=
181 ((S_IRUGO | S_IXUGO) & ~sbi->options.fs_dmask))
182 return -EPERM;
183
184 if ((req & S_IWUGO) != 0 &&
185 (req & S_IWUGO) != (S_IWUGO & ~sbi->options.fs_dmask))
186 return -EPERM;
187 } else {
188 return -EPERM;
189 }
190
191 return 0;
192}
193
158int fat_notify_change(struct dentry *dentry, struct iattr *attr) 194int fat_notify_change(struct dentry *dentry, struct iattr *attr)
159{ 195{
160 struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb); 196 struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb);
@@ -186,9 +222,7 @@ int fat_notify_change(struct dentry *dentry, struct iattr *attr)
186 if (((attr->ia_valid & ATTR_UID) && 222 if (((attr->ia_valid & ATTR_UID) &&
187 (attr->ia_uid != sbi->options.fs_uid)) || 223 (attr->ia_uid != sbi->options.fs_uid)) ||
188 ((attr->ia_valid & ATTR_GID) && 224 ((attr->ia_valid & ATTR_GID) &&
189 (attr->ia_gid != sbi->options.fs_gid)) || 225 (attr->ia_gid != sbi->options.fs_gid)))
190 ((attr->ia_valid & ATTR_MODE) &&
191 (attr->ia_mode & ~MSDOS_VALID_MODE)))
192 error = -EPERM; 226 error = -EPERM;
193 227
194 if (error) { 228 if (error) {
@@ -196,6 +230,13 @@ int fat_notify_change(struct dentry *dentry, struct iattr *attr)
196 error = 0; 230 error = 0;
197 goto out; 231 goto out;
198 } 232 }
233
234 if (attr->ia_valid & ATTR_MODE) {
235 error = check_mode(sbi, attr->ia_mode);
236 if (error != 0 && !sbi->options.quiet)
237 goto out;
238 }
239
199 error = inode_setattr(inode, attr); 240 error = inode_setattr(inode, attr);
200 if (error) 241 if (error)
201 goto out; 242 goto out;
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 920a576e1c25..24c0aaa5ae80 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -1295,10 +1295,8 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
1295 1295
1296 fsinfo = (struct fat_boot_fsinfo *)fsinfo_bh->b_data; 1296 fsinfo = (struct fat_boot_fsinfo *)fsinfo_bh->b_data;
1297 if (!IS_FSINFO(fsinfo)) { 1297 if (!IS_FSINFO(fsinfo)) {
1298 printk(KERN_WARNING 1298 printk(KERN_WARNING "FAT: Invalid FSINFO signature: "
1299 "FAT: Did not find valid FSINFO signature.\n" 1299 "0x%08x, 0x%08x (sector = %lu)\n",
1300 " Found signature1 0x%08x signature2 0x%08x"
1301 " (sector = %lu)\n",
1302 le32_to_cpu(fsinfo->signature1), 1300 le32_to_cpu(fsinfo->signature1),
1303 le32_to_cpu(fsinfo->signature2), 1301 le32_to_cpu(fsinfo->signature2),
1304 sbi->fsinfo_sector); 1302 sbi->fsinfo_sector);
diff --git a/fs/fat/misc.c b/fs/fat/misc.c
index 308f2b6b5026..61f23511eacf 100644
--- a/fs/fat/misc.c
+++ b/fs/fat/misc.c
@@ -55,9 +55,8 @@ void fat_clusters_flush(struct super_block *sb)
55 fsinfo = (struct fat_boot_fsinfo *)bh->b_data; 55 fsinfo = (struct fat_boot_fsinfo *)bh->b_data;
56 /* Sanity check */ 56 /* Sanity check */
57 if (!IS_FSINFO(fsinfo)) { 57 if (!IS_FSINFO(fsinfo)) {
58 printk(KERN_ERR "FAT: Did not find valid FSINFO signature.\n" 58 printk(KERN_ERR "FAT: Invalid FSINFO signature: "
59 " Found signature1 0x%08x signature2 0x%08x" 59 "0x%08x, 0x%08x (sector = %lu)\n",
60 " (sector = %lu)\n",
61 le32_to_cpu(fsinfo->signature1), 60 le32_to_cpu(fsinfo->signature1),
62 le32_to_cpu(fsinfo->signature2), 61 le32_to_cpu(fsinfo->signature2),
63 sbi->fsinfo_sector); 62 sbi->fsinfo_sector);
diff --git a/fs/file.c b/fs/file.c
index c5575de01113..5110acb1c9ef 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -24,6 +24,8 @@ struct fdtable_defer {
24 struct fdtable *next; 24 struct fdtable *next;
25}; 25};
26 26
27int sysctl_nr_open __read_mostly = 1024*1024;
28
27/* 29/*
28 * We use this list to defer free fdtables that have vmalloced 30 * We use this list to defer free fdtables that have vmalloced
29 * sets/arrays. By keeping a per-cpu list, we avoid having to embed 31 * sets/arrays. By keeping a per-cpu list, we avoid having to embed
@@ -147,8 +149,8 @@ static struct fdtable * alloc_fdtable(unsigned int nr)
147 nr /= (1024 / sizeof(struct file *)); 149 nr /= (1024 / sizeof(struct file *));
148 nr = roundup_pow_of_two(nr + 1); 150 nr = roundup_pow_of_two(nr + 1);
149 nr *= (1024 / sizeof(struct file *)); 151 nr *= (1024 / sizeof(struct file *));
150 if (nr > NR_OPEN) 152 if (nr > sysctl_nr_open)
151 nr = NR_OPEN; 153 nr = sysctl_nr_open;
152 154
153 fdt = kmalloc(sizeof(struct fdtable), GFP_KERNEL); 155 fdt = kmalloc(sizeof(struct fdtable), GFP_KERNEL);
154 if (!fdt) 156 if (!fdt)
@@ -233,7 +235,7 @@ int expand_files(struct files_struct *files, int nr)
233 if (nr < fdt->max_fds) 235 if (nr < fdt->max_fds)
234 return 0; 236 return 0;
235 /* Can we expand? */ 237 /* Can we expand? */
236 if (nr >= NR_OPEN) 238 if (nr >= sysctl_nr_open)
237 return -EMFILE; 239 return -EMFILE;
238 240
239 /* All good, so we try */ 241 /* All good, so we try */
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 0b3064079fa5..db80ce9eb1d0 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -515,8 +515,7 @@ writeback_inodes(struct writeback_control *wbc)
515 might_sleep(); 515 might_sleep();
516 spin_lock(&sb_lock); 516 spin_lock(&sb_lock);
517restart: 517restart:
518 sb = sb_entry(super_blocks.prev); 518 list_for_each_entry_reverse(sb, &super_blocks, s_list) {
519 for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) {
520 if (sb_has_dirty_inodes(sb)) { 519 if (sb_has_dirty_inodes(sb)) {
521 /* we're making our own get_super here */ 520 /* we're making our own get_super here */
522 sb->s_count++; 521 sb->s_count++;
@@ -581,10 +580,8 @@ static void set_sb_syncing(int val)
581{ 580{
582 struct super_block *sb; 581 struct super_block *sb;
583 spin_lock(&sb_lock); 582 spin_lock(&sb_lock);
584 sb = sb_entry(super_blocks.prev); 583 list_for_each_entry_reverse(sb, &super_blocks, s_list)
585 for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) {
586 sb->s_syncing = val; 584 sb->s_syncing = val;
587 }
588 spin_unlock(&sb_lock); 585 spin_unlock(&sb_lock);
589} 586}
590 587
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index db534bcde45f..af639807524e 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -201,6 +201,55 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
201 } 201 }
202} 202}
203 203
204static unsigned len_args(unsigned numargs, struct fuse_arg *args)
205{
206 unsigned nbytes = 0;
207 unsigned i;
208
209 for (i = 0; i < numargs; i++)
210 nbytes += args[i].size;
211
212 return nbytes;
213}
214
215static u64 fuse_get_unique(struct fuse_conn *fc)
216{
217 fc->reqctr++;
218 /* zero is special */
219 if (fc->reqctr == 0)
220 fc->reqctr = 1;
221
222 return fc->reqctr;
223}
224
225static void queue_request(struct fuse_conn *fc, struct fuse_req *req)
226{
227 req->in.h.unique = fuse_get_unique(fc);
228 req->in.h.len = sizeof(struct fuse_in_header) +
229 len_args(req->in.numargs, (struct fuse_arg *) req->in.args);
230 list_add_tail(&req->list, &fc->pending);
231 req->state = FUSE_REQ_PENDING;
232 if (!req->waiting) {
233 req->waiting = 1;
234 atomic_inc(&fc->num_waiting);
235 }
236 wake_up(&fc->waitq);
237 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
238}
239
240static void flush_bg_queue(struct fuse_conn *fc)
241{
242 while (fc->active_background < FUSE_MAX_BACKGROUND &&
243 !list_empty(&fc->bg_queue)) {
244 struct fuse_req *req;
245
246 req = list_entry(fc->bg_queue.next, struct fuse_req, list);
247 list_del(&req->list);
248 fc->active_background++;
249 queue_request(fc, req);
250 }
251}
252
204/* 253/*
205 * This function is called when a request is finished. Either a reply 254 * This function is called when a request is finished. Either a reply
206 * has arrived or it was aborted (and not yet sent) or some error 255 * has arrived or it was aborted (and not yet sent) or some error
@@ -229,6 +278,8 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
229 clear_bdi_congested(&fc->bdi, WRITE); 278 clear_bdi_congested(&fc->bdi, WRITE);
230 } 279 }
231 fc->num_background--; 280 fc->num_background--;
281 fc->active_background--;
282 flush_bg_queue(fc);
232 } 283 }
233 spin_unlock(&fc->lock); 284 spin_unlock(&fc->lock);
234 wake_up(&req->waitq); 285 wake_up(&req->waitq);
@@ -320,42 +371,6 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
320 } 371 }
321} 372}
322 373
323static unsigned len_args(unsigned numargs, struct fuse_arg *args)
324{
325 unsigned nbytes = 0;
326 unsigned i;
327
328 for (i = 0; i < numargs; i++)
329 nbytes += args[i].size;
330
331 return nbytes;
332}
333
334static u64 fuse_get_unique(struct fuse_conn *fc)
335 {
336 fc->reqctr++;
337 /* zero is special */
338 if (fc->reqctr == 0)
339 fc->reqctr = 1;
340
341 return fc->reqctr;
342}
343
344static void queue_request(struct fuse_conn *fc, struct fuse_req *req)
345{
346 req->in.h.unique = fuse_get_unique(fc);
347 req->in.h.len = sizeof(struct fuse_in_header) +
348 len_args(req->in.numargs, (struct fuse_arg *) req->in.args);
349 list_add_tail(&req->list, &fc->pending);
350 req->state = FUSE_REQ_PENDING;
351 if (!req->waiting) {
352 req->waiting = 1;
353 atomic_inc(&fc->num_waiting);
354 }
355 wake_up(&fc->waitq);
356 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
357}
358
359void request_send(struct fuse_conn *fc, struct fuse_req *req) 374void request_send(struct fuse_conn *fc, struct fuse_req *req)
360{ 375{
361 req->isreply = 1; 376 req->isreply = 1;
@@ -375,20 +390,26 @@ void request_send(struct fuse_conn *fc, struct fuse_req *req)
375 spin_unlock(&fc->lock); 390 spin_unlock(&fc->lock);
376} 391}
377 392
393static void request_send_nowait_locked(struct fuse_conn *fc,
394 struct fuse_req *req)
395{
396 req->background = 1;
397 fc->num_background++;
398 if (fc->num_background == FUSE_MAX_BACKGROUND)
399 fc->blocked = 1;
400 if (fc->num_background == FUSE_CONGESTION_THRESHOLD) {
401 set_bdi_congested(&fc->bdi, READ);
402 set_bdi_congested(&fc->bdi, WRITE);
403 }
404 list_add_tail(&req->list, &fc->bg_queue);
405 flush_bg_queue(fc);
406}
407
378static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req) 408static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
379{ 409{
380 spin_lock(&fc->lock); 410 spin_lock(&fc->lock);
381 if (fc->connected) { 411 if (fc->connected) {
382 req->background = 1; 412 request_send_nowait_locked(fc, req);
383 fc->num_background++;
384 if (fc->num_background == FUSE_MAX_BACKGROUND)
385 fc->blocked = 1;
386 if (fc->num_background == FUSE_CONGESTION_THRESHOLD) {
387 set_bdi_congested(&fc->bdi, READ);
388 set_bdi_congested(&fc->bdi, WRITE);
389 }
390
391 queue_request(fc, req);
392 spin_unlock(&fc->lock); 413 spin_unlock(&fc->lock);
393 } else { 414 } else {
394 req->out.h.error = -ENOTCONN; 415 req->out.h.error = -ENOTCONN;
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 80d2f5292cf9..f56f91bd38be 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -416,6 +416,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
416 fuse_put_request(fc, forget_req); 416 fuse_put_request(fc, forget_req);
417 d_instantiate(entry, inode); 417 d_instantiate(entry, inode);
418 fuse_change_entry_timeout(entry, &outentry); 418 fuse_change_entry_timeout(entry, &outentry);
419 fuse_invalidate_attr(dir);
419 file = lookup_instantiate_filp(nd, entry, generic_file_open); 420 file = lookup_instantiate_filp(nd, entry, generic_file_open);
420 if (IS_ERR(file)) { 421 if (IS_ERR(file)) {
421 ff->fh = outopen.fh; 422 ff->fh = outopen.fh;
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index bb05d227cf30..676b0bc8a86d 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -77,8 +77,8 @@ static struct fuse_file *fuse_file_get(struct fuse_file *ff)
77 77
78static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req) 78static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req)
79{ 79{
80 dput(req->dentry); 80 dput(req->misc.release.dentry);
81 mntput(req->vfsmount); 81 mntput(req->misc.release.vfsmount);
82 fuse_put_request(fc, req); 82 fuse_put_request(fc, req);
83} 83}
84 84
@@ -86,7 +86,8 @@ static void fuse_file_put(struct fuse_file *ff)
86{ 86{
87 if (atomic_dec_and_test(&ff->count)) { 87 if (atomic_dec_and_test(&ff->count)) {
88 struct fuse_req *req = ff->reserved_req; 88 struct fuse_req *req = ff->reserved_req;
89 struct fuse_conn *fc = get_fuse_conn(req->dentry->d_inode); 89 struct inode *inode = req->misc.release.dentry->d_inode;
90 struct fuse_conn *fc = get_fuse_conn(inode);
90 req->end = fuse_release_end; 91 req->end = fuse_release_end;
91 request_send_background(fc, req); 92 request_send_background(fc, req);
92 kfree(ff); 93 kfree(ff);
@@ -137,7 +138,7 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir)
137void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode) 138void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode)
138{ 139{
139 struct fuse_req *req = ff->reserved_req; 140 struct fuse_req *req = ff->reserved_req;
140 struct fuse_release_in *inarg = &req->misc.release_in; 141 struct fuse_release_in *inarg = &req->misc.release.in;
141 142
142 inarg->fh = ff->fh; 143 inarg->fh = ff->fh;
143 inarg->flags = flags; 144 inarg->flags = flags;
@@ -153,13 +154,14 @@ int fuse_release_common(struct inode *inode, struct file *file, int isdir)
153 struct fuse_file *ff = file->private_data; 154 struct fuse_file *ff = file->private_data;
154 if (ff) { 155 if (ff) {
155 struct fuse_conn *fc = get_fuse_conn(inode); 156 struct fuse_conn *fc = get_fuse_conn(inode);
157 struct fuse_req *req = ff->reserved_req;
156 158
157 fuse_release_fill(ff, get_node_id(inode), file->f_flags, 159 fuse_release_fill(ff, get_node_id(inode), file->f_flags,
158 isdir ? FUSE_RELEASEDIR : FUSE_RELEASE); 160 isdir ? FUSE_RELEASEDIR : FUSE_RELEASE);
159 161
160 /* Hold vfsmount and dentry until release is finished */ 162 /* Hold vfsmount and dentry until release is finished */
161 ff->reserved_req->vfsmount = mntget(file->f_path.mnt); 163 req->misc.release.vfsmount = mntget(file->f_path.mnt);
162 ff->reserved_req->dentry = dget(file->f_path.dentry); 164 req->misc.release.dentry = dget(file->f_path.dentry);
163 165
164 spin_lock(&fc->lock); 166 spin_lock(&fc->lock);
165 list_del(&ff->write_entry); 167 list_del(&ff->write_entry);
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 3ab8a3048e8b..67aaf6ee38ea 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -215,7 +215,11 @@ struct fuse_req {
215 /** Data for asynchronous requests */ 215 /** Data for asynchronous requests */
216 union { 216 union {
217 struct fuse_forget_in forget_in; 217 struct fuse_forget_in forget_in;
218 struct fuse_release_in release_in; 218 struct {
219 struct fuse_release_in in;
220 struct vfsmount *vfsmount;
221 struct dentry *dentry;
222 } release;
219 struct fuse_init_in init_in; 223 struct fuse_init_in init_in;
220 struct fuse_init_out init_out; 224 struct fuse_init_out init_out;
221 struct fuse_read_in read_in; 225 struct fuse_read_in read_in;
@@ -238,12 +242,6 @@ struct fuse_req {
238 /** File used in the request (or NULL) */ 242 /** File used in the request (or NULL) */
239 struct fuse_file *ff; 243 struct fuse_file *ff;
240 244
241 /** vfsmount used in release */
242 struct vfsmount *vfsmount;
243
244 /** dentry used in release */
245 struct dentry *dentry;
246
247 /** Request completion callback */ 245 /** Request completion callback */
248 void (*end)(struct fuse_conn *, struct fuse_req *); 246 void (*end)(struct fuse_conn *, struct fuse_req *);
249 247
@@ -298,6 +296,12 @@ struct fuse_conn {
298 /** Number of requests currently in the background */ 296 /** Number of requests currently in the background */
299 unsigned num_background; 297 unsigned num_background;
300 298
299 /** Number of background requests currently queued for userspace */
300 unsigned active_background;
301
302 /** The list of background requests set aside for later queuing */
303 struct list_head bg_queue;
304
301 /** Pending interrupts */ 305 /** Pending interrupts */
302 struct list_head interrupts; 306 struct list_head interrupts;
303 307
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index e5e80d1a4687..c90f633d0b57 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -465,6 +465,7 @@ static struct fuse_conn *new_conn(void)
465 INIT_LIST_HEAD(&fc->processing); 465 INIT_LIST_HEAD(&fc->processing);
466 INIT_LIST_HEAD(&fc->io); 466 INIT_LIST_HEAD(&fc->io);
467 INIT_LIST_HEAD(&fc->interrupts); 467 INIT_LIST_HEAD(&fc->interrupts);
468 INIT_LIST_HEAD(&fc->bg_queue);
468 atomic_set(&fc->num_waiting, 0); 469 atomic_set(&fc->num_waiting, 0);
469 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; 470 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
470 fc->bdi.unplug_io_fn = default_unplug_io_fn; 471 fc->bdi.unplug_io_fn = default_unplug_io_fn;
diff --git a/fs/hfs/bfind.c b/fs/hfs/bfind.c
index f8452a0eab56..4129cdb3f0d8 100644
--- a/fs/hfs/bfind.c
+++ b/fs/hfs/bfind.c
@@ -52,9 +52,9 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
52 rec = (e + b) / 2; 52 rec = (e + b) / 2;
53 len = hfs_brec_lenoff(bnode, rec, &off); 53 len = hfs_brec_lenoff(bnode, rec, &off);
54 keylen = hfs_brec_keylen(bnode, rec); 54 keylen = hfs_brec_keylen(bnode, rec);
55 if (keylen == HFS_BAD_KEYLEN) { 55 if (keylen == 0) {
56 res = -EINVAL; 56 res = -EINVAL;
57 goto done; 57 goto fail;
58 } 58 }
59 hfs_bnode_read(bnode, fd->key, off, keylen); 59 hfs_bnode_read(bnode, fd->key, off, keylen);
60 cmpval = bnode->tree->keycmp(fd->key, fd->search_key); 60 cmpval = bnode->tree->keycmp(fd->key, fd->search_key);
@@ -71,9 +71,9 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
71 if (rec != e && e >= 0) { 71 if (rec != e && e >= 0) {
72 len = hfs_brec_lenoff(bnode, e, &off); 72 len = hfs_brec_lenoff(bnode, e, &off);
73 keylen = hfs_brec_keylen(bnode, e); 73 keylen = hfs_brec_keylen(bnode, e);
74 if (keylen == HFS_BAD_KEYLEN) { 74 if (keylen == 0) {
75 res = -EINVAL; 75 res = -EINVAL;
76 goto done; 76 goto fail;
77 } 77 }
78 hfs_bnode_read(bnode, fd->key, off, keylen); 78 hfs_bnode_read(bnode, fd->key, off, keylen);
79 } 79 }
@@ -83,6 +83,7 @@ done:
83 fd->keylength = keylen; 83 fd->keylength = keylen;
84 fd->entryoffset = off + keylen; 84 fd->entryoffset = off + keylen;
85 fd->entrylength = len - keylen; 85 fd->entrylength = len - keylen;
86fail:
86 return res; 87 return res;
87} 88}
88 89
@@ -206,7 +207,7 @@ int hfs_brec_goto(struct hfs_find_data *fd, int cnt)
206 207
207 len = hfs_brec_lenoff(bnode, fd->record, &off); 208 len = hfs_brec_lenoff(bnode, fd->record, &off);
208 keylen = hfs_brec_keylen(bnode, fd->record); 209 keylen = hfs_brec_keylen(bnode, fd->record);
209 if (keylen == HFS_BAD_KEYLEN) { 210 if (keylen == 0) {
210 res = -EINVAL; 211 res = -EINVAL;
211 goto out; 212 goto out;
212 } 213 }
diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c
index 8626ee375ea8..878bf25dbc6a 100644
--- a/fs/hfs/brec.c
+++ b/fs/hfs/brec.c
@@ -49,14 +49,14 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec)
49 if (retval > node->tree->max_key_len + 2) { 49 if (retval > node->tree->max_key_len + 2) {
50 printk(KERN_ERR "hfs: keylen %d too large\n", 50 printk(KERN_ERR "hfs: keylen %d too large\n",
51 retval); 51 retval);
52 retval = HFS_BAD_KEYLEN; 52 retval = 0;
53 } 53 }
54 } else { 54 } else {
55 retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1; 55 retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1;
56 if (retval > node->tree->max_key_len + 1) { 56 if (retval > node->tree->max_key_len + 1) {
57 printk(KERN_ERR "hfs: keylen %d too large\n", 57 printk(KERN_ERR "hfs: keylen %d too large\n",
58 retval); 58 retval);
59 retval = HFS_BAD_KEYLEN; 59 retval = 0;
60 } 60 }
61 } 61 }
62 } 62 }
diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c
index 110dd3515dc8..24cf6fc43021 100644
--- a/fs/hfs/btree.c
+++ b/fs/hfs/btree.c
@@ -81,15 +81,23 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
81 goto fail_page; 81 goto fail_page;
82 if (!tree->node_count) 82 if (!tree->node_count)
83 goto fail_page; 83 goto fail_page;
84 if ((id == HFS_EXT_CNID) && (tree->max_key_len != HFS_MAX_EXT_KEYLEN)) { 84 switch (id) {
85 printk(KERN_ERR "hfs: invalid extent max_key_len %d\n", 85 case HFS_EXT_CNID:
86 tree->max_key_len); 86 if (tree->max_key_len != HFS_MAX_EXT_KEYLEN) {
87 goto fail_page; 87 printk(KERN_ERR "hfs: invalid extent max_key_len %d\n",
88 } 88 tree->max_key_len);
89 if ((id == HFS_CAT_CNID) && (tree->max_key_len != HFS_MAX_CAT_KEYLEN)) { 89 goto fail_page;
90 printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n", 90 }
91 tree->max_key_len); 91 break;
92 goto fail_page; 92 case HFS_CAT_CNID:
93 if (tree->max_key_len != HFS_MAX_CAT_KEYLEN) {
94 printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n",
95 tree->max_key_len);
96 goto fail_page;
97 }
98 break;
99 default:
100 BUG();
93 } 101 }
94 102
95 tree->node_size_shift = ffs(size) - 1; 103 tree->node_size_shift = ffs(size) - 1;
diff --git a/fs/hfs/hfs.h b/fs/hfs/hfs.h
index c6aae61adfe6..6f194d0768b6 100644
--- a/fs/hfs/hfs.h
+++ b/fs/hfs/hfs.h
@@ -28,8 +28,6 @@
28#define HFS_MAX_NAMELEN 128 28#define HFS_MAX_NAMELEN 128
29#define HFS_MAX_VALENCE 32767U 29#define HFS_MAX_VALENCE 32767U
30 30
31#define HFS_BAD_KEYLEN 0xFF
32
33/* Meanings of the drAtrb field of the MDB, 31/* Meanings of the drAtrb field of the MDB,
34 * Reference: _Inside Macintosh: Files_ p. 2-61 32 * Reference: _Inside Macintosh: Files_ p. 2-61
35 */ 33 */
diff --git a/fs/hfs/super.c b/fs/hfs/super.c
index 16cbd902f8b9..32de44ed0021 100644
--- a/fs/hfs/super.c
+++ b/fs/hfs/super.c
@@ -6,7 +6,7 @@
6 * This file may be distributed under the terms of the GNU General Public License. 6 * This file may be distributed under the terms of the GNU General Public License.
7 * 7 *
8 * This file contains hfs_read_super(), some of the super_ops and 8 * This file contains hfs_read_super(), some of the super_ops and
9 * init_module() and cleanup_module(). The remaining super_ops are in 9 * init_hfs_fs() and exit_hfs_fs(). The remaining super_ops are in
10 * inode.c since they deal with inodes. 10 * inode.c since they deal with inodes.
11 * 11 *
12 * Based on the minix file system code, (C) 1991, 1992 by Linus Torvalds 12 * Based on the minix file system code, (C) 1991, 1992 by Linus Torvalds
diff --git a/fs/inotify.c b/fs/inotify.c
index 2c5b92152876..690e72595e6e 100644
--- a/fs/inotify.c
+++ b/fs/inotify.c
@@ -168,20 +168,14 @@ static void set_dentry_child_flags(struct inode *inode, int watched)
168 struct dentry *child; 168 struct dentry *child;
169 169
170 list_for_each_entry(child, &alias->d_subdirs, d_u.d_child) { 170 list_for_each_entry(child, &alias->d_subdirs, d_u.d_child) {
171 if (!child->d_inode) { 171 if (!child->d_inode)
172 WARN_ON(child->d_flags & DCACHE_INOTIFY_PARENT_WATCHED);
173 continue; 172 continue;
174 } 173
175 spin_lock(&child->d_lock); 174 spin_lock(&child->d_lock);
176 if (watched) { 175 if (watched)
177 WARN_ON(child->d_flags &
178 DCACHE_INOTIFY_PARENT_WATCHED);
179 child->d_flags |= DCACHE_INOTIFY_PARENT_WATCHED; 176 child->d_flags |= DCACHE_INOTIFY_PARENT_WATCHED;
180 } else { 177 else
181 WARN_ON(!(child->d_flags & 178 child->d_flags &=~DCACHE_INOTIFY_PARENT_WATCHED;
182 DCACHE_INOTIFY_PARENT_WATCHED));
183 child->d_flags&=~DCACHE_INOTIFY_PARENT_WATCHED;
184 }
185 spin_unlock(&child->d_lock); 179 spin_unlock(&child->d_lock);
186 } 180 }
187 } 181 }
@@ -253,7 +247,6 @@ void inotify_d_instantiate(struct dentry *entry, struct inode *inode)
253 if (!inode) 247 if (!inode)
254 return; 248 return;
255 249
256 WARN_ON(entry->d_flags & DCACHE_INOTIFY_PARENT_WATCHED);
257 spin_lock(&entry->d_lock); 250 spin_lock(&entry->d_lock);
258 parent = entry->d_parent; 251 parent = entry->d_parent;
259 if (parent->d_inode && inotify_inode_watched(parent->d_inode)) 252 if (parent->d_inode && inotify_inode_watched(parent->d_inode))
@@ -627,6 +620,7 @@ s32 inotify_add_watch(struct inotify_handle *ih, struct inotify_watch *watch,
627 struct inode *inode, u32 mask) 620 struct inode *inode, u32 mask)
628{ 621{
629 int ret = 0; 622 int ret = 0;
623 int newly_watched;
630 624
631 /* don't allow invalid bits: we don't want flags set */ 625 /* don't allow invalid bits: we don't want flags set */
632 mask &= IN_ALL_EVENTS | IN_ONESHOT; 626 mask &= IN_ALL_EVENTS | IN_ONESHOT;
@@ -653,12 +647,18 @@ s32 inotify_add_watch(struct inotify_handle *ih, struct inotify_watch *watch,
653 */ 647 */
654 watch->inode = igrab(inode); 648 watch->inode = igrab(inode);
655 649
656 if (!inotify_inode_watched(inode))
657 set_dentry_child_flags(inode, 1);
658
659 /* Add the watch to the handle's and the inode's list */ 650 /* Add the watch to the handle's and the inode's list */
651 newly_watched = !inotify_inode_watched(inode);
660 list_add(&watch->h_list, &ih->watches); 652 list_add(&watch->h_list, &ih->watches);
661 list_add(&watch->i_list, &inode->inotify_watches); 653 list_add(&watch->i_list, &inode->inotify_watches);
654 /*
655 * Set child flags _after_ adding the watch, so there is no race
656 * windows where newly instantiated children could miss their parent's
657 * watched flag.
658 */
659 if (newly_watched)
660 set_dentry_child_flags(inode, 1);
661
662out: 662out:
663 mutex_unlock(&ih->mutex); 663 mutex_unlock(&ih->mutex);
664 mutex_unlock(&inode->inotify_mutex); 664 mutex_unlock(&inode->inotify_mutex);
diff --git a/fs/inotify_user.c b/fs/inotify_user.c
index 5e009331c01f..a336c9709f3c 100644
--- a/fs/inotify_user.c
+++ b/fs/inotify_user.c
@@ -79,6 +79,7 @@ struct inotify_device {
79 atomic_t count; /* reference count */ 79 atomic_t count; /* reference count */
80 struct user_struct *user; /* user who opened this dev */ 80 struct user_struct *user; /* user who opened this dev */
81 struct inotify_handle *ih; /* inotify handle */ 81 struct inotify_handle *ih; /* inotify handle */
82 struct fasync_struct *fa; /* async notification */
82 unsigned int queue_size; /* size of the queue (bytes) */ 83 unsigned int queue_size; /* size of the queue (bytes) */
83 unsigned int event_count; /* number of pending events */ 84 unsigned int event_count; /* number of pending events */
84 unsigned int max_events; /* maximum number of events */ 85 unsigned int max_events; /* maximum number of events */
@@ -248,6 +249,19 @@ inotify_dev_get_event(struct inotify_device *dev)
248} 249}
249 250
250/* 251/*
252 * inotify_dev_get_last_event - return the last event in the given dev's queue
253 *
254 * Caller must hold dev->ev_mutex.
255 */
256static inline struct inotify_kernel_event *
257inotify_dev_get_last_event(struct inotify_device *dev)
258{
259 if (list_empty(&dev->events))
260 return NULL;
261 return list_entry(dev->events.prev, struct inotify_kernel_event, list);
262}
263
264/*
251 * inotify_dev_queue_event - event handler registered with core inotify, adds 265 * inotify_dev_queue_event - event handler registered with core inotify, adds
252 * a new event to the given device 266 * a new event to the given device
253 * 267 *
@@ -273,7 +287,7 @@ static void inotify_dev_queue_event(struct inotify_watch *w, u32 wd, u32 mask,
273 put_inotify_watch(w); /* final put */ 287 put_inotify_watch(w); /* final put */
274 288
275 /* coalescing: drop this event if it is a dupe of the previous */ 289 /* coalescing: drop this event if it is a dupe of the previous */
276 last = inotify_dev_get_event(dev); 290 last = inotify_dev_get_last_event(dev);
277 if (last && last->event.mask == mask && last->event.wd == wd && 291 if (last && last->event.mask == mask && last->event.wd == wd &&
278 last->event.cookie == cookie) { 292 last->event.cookie == cookie) {
279 const char *lastname = last->name; 293 const char *lastname = last->name;
@@ -302,6 +316,7 @@ static void inotify_dev_queue_event(struct inotify_watch *w, u32 wd, u32 mask,
302 dev->queue_size += sizeof(struct inotify_event) + kevent->event.len; 316 dev->queue_size += sizeof(struct inotify_event) + kevent->event.len;
303 list_add_tail(&kevent->list, &dev->events); 317 list_add_tail(&kevent->list, &dev->events);
304 wake_up_interruptible(&dev->wq); 318 wake_up_interruptible(&dev->wq);
319 kill_fasync(&dev->fa, SIGIO, POLL_IN);
305 320
306out: 321out:
307 mutex_unlock(&dev->ev_mutex); 322 mutex_unlock(&dev->ev_mutex);
@@ -490,6 +505,13 @@ static ssize_t inotify_read(struct file *file, char __user *buf,
490 return ret; 505 return ret;
491} 506}
492 507
508static int inotify_fasync(int fd, struct file *file, int on)
509{
510 struct inotify_device *dev = file->private_data;
511
512 return fasync_helper(fd, file, on, &dev->fa) >= 0 ? 0 : -EIO;
513}
514
493static int inotify_release(struct inode *ignored, struct file *file) 515static int inotify_release(struct inode *ignored, struct file *file)
494{ 516{
495 struct inotify_device *dev = file->private_data; 517 struct inotify_device *dev = file->private_data;
@@ -502,6 +524,9 @@ static int inotify_release(struct inode *ignored, struct file *file)
502 inotify_dev_event_dequeue(dev); 524 inotify_dev_event_dequeue(dev);
503 mutex_unlock(&dev->ev_mutex); 525 mutex_unlock(&dev->ev_mutex);
504 526
527 if (file->f_flags & FASYNC)
528 inotify_fasync(-1, file, 0);
529
505 /* free this device: the put matching the get in inotify_init() */ 530 /* free this device: the put matching the get in inotify_init() */
506 put_inotify_dev(dev); 531 put_inotify_dev(dev);
507 532
@@ -530,6 +555,7 @@ static long inotify_ioctl(struct file *file, unsigned int cmd,
530static const struct file_operations inotify_fops = { 555static const struct file_operations inotify_fops = {
531 .poll = inotify_poll, 556 .poll = inotify_poll,
532 .read = inotify_read, 557 .read = inotify_read,
558 .fasync = inotify_fasync,
533 .release = inotify_release, 559 .release = inotify_release,
534 .unlocked_ioctl = inotify_ioctl, 560 .unlocked_ioctl = inotify_ioctl,
535 .compat_ioctl = inotify_ioctl, 561 .compat_ioctl = inotify_ioctl,
@@ -577,6 +603,7 @@ asmlinkage long sys_inotify_init(void)
577 goto out_free_dev; 603 goto out_free_dev;
578 } 604 }
579 dev->ih = ih; 605 dev->ih = ih;
606 dev->fa = NULL;
580 607
581 filp->f_op = &inotify_fops; 608 filp->f_op = &inotify_fops;
582 filp->f_path.mnt = mntget(inotify_mnt); 609 filp->f_path.mnt = mntget(inotify_mnt);
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
index 5d14243499d4..3943a8905eb2 100644
--- a/fs/jbd/journal.c
+++ b/fs/jbd/journal.c
@@ -1457,7 +1457,7 @@ static const char *journal_dev_name(journal_t *journal, char *buffer)
1457 * Aborts hard --- we mark the abort as occurred, but do _nothing_ else, 1457 * Aborts hard --- we mark the abort as occurred, but do _nothing_ else,
1458 * and don't attempt to make any other journal updates. 1458 * and don't attempt to make any other journal updates.
1459 */ 1459 */
1460void __journal_abort_hard(journal_t *journal) 1460static void __journal_abort_hard(journal_t *journal)
1461{ 1461{
1462 transaction_t *transaction; 1462 transaction_t *transaction;
1463 char b[BDEVNAME_SIZE]; 1463 char b[BDEVNAME_SIZE];
diff --git a/fs/jbd/recovery.c b/fs/jbd/recovery.c
index c5d9694b6a2f..2b8edf4d6eaa 100644
--- a/fs/jbd/recovery.c
+++ b/fs/jbd/recovery.c
@@ -354,7 +354,7 @@ static int do_one_pass(journal_t *journal,
354 struct buffer_head * obh; 354 struct buffer_head * obh;
355 struct buffer_head * nbh; 355 struct buffer_head * nbh;
356 356
357 cond_resched(); /* We're under lock_kernel() */ 357 cond_resched();
358 358
359 /* If we already know where to stop the log traversal, 359 /* If we already know where to stop the log traversal,
360 * check right now that we haven't gone past the end of 360 * check right now that we haven't gone past the end of
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index 921680663fa2..d36356f7d222 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -397,7 +397,7 @@ static int do_one_pass(journal_t *journal,
397 struct buffer_head * obh; 397 struct buffer_head * obh;
398 struct buffer_head * nbh; 398 struct buffer_head * nbh;
399 399
400 cond_resched(); /* We're under lock_kernel() */ 400 cond_resched();
401 401
402 /* If we already know where to stop the log traversal, 402 /* If we already know where to stop the log traversal,
403 * check right now that we haven't gone past the end of 403 * check right now that we haven't gone past the end of
diff --git a/fs/namei.c b/fs/namei.c
index 73e2e665817a..241cff423653 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2188,6 +2188,7 @@ int vfs_unlink(struct inode *dir, struct dentry *dentry)
2188 2188
2189 /* We don't d_delete() NFS sillyrenamed files--they still exist. */ 2189 /* We don't d_delete() NFS sillyrenamed files--they still exist. */
2190 if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) { 2190 if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) {
2191 fsnotify_link_count(dentry->d_inode);
2191 d_delete(dentry); 2192 d_delete(dentry);
2192 } 2193 }
2193 2194
@@ -2360,7 +2361,7 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
2360 error = dir->i_op->link(old_dentry, dir, new_dentry); 2361 error = dir->i_op->link(old_dentry, dir, new_dentry);
2361 mutex_unlock(&old_dentry->d_inode->i_mutex); 2362 mutex_unlock(&old_dentry->d_inode->i_mutex);
2362 if (!error) 2363 if (!error)
2363 fsnotify_create(dir, new_dentry); 2364 fsnotify_link(dir, old_dentry->d_inode, new_dentry);
2364 return error; 2365 return error;
2365} 2366}
2366 2367
diff --git a/fs/namespace.c b/fs/namespace.c
index 61bf376e29e8..e9c10cd01e13 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -25,18 +25,21 @@
25#include <linux/security.h> 25#include <linux/security.h>
26#include <linux/mount.h> 26#include <linux/mount.h>
27#include <linux/ramfs.h> 27#include <linux/ramfs.h>
28#include <linux/log2.h>
28#include <asm/uaccess.h> 29#include <asm/uaccess.h>
29#include <asm/unistd.h> 30#include <asm/unistd.h>
30#include "pnode.h" 31#include "pnode.h"
31#include "internal.h" 32#include "internal.h"
32 33
34#define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head))
35#define HASH_SIZE (1UL << HASH_SHIFT)
36
33/* spinlock for vfsmount related operations, inplace of dcache_lock */ 37/* spinlock for vfsmount related operations, inplace of dcache_lock */
34__cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock); 38__cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
35 39
36static int event; 40static int event;
37 41
38static struct list_head *mount_hashtable __read_mostly; 42static struct list_head *mount_hashtable __read_mostly;
39static int hash_mask __read_mostly, hash_bits __read_mostly;
40static struct kmem_cache *mnt_cache __read_mostly; 43static struct kmem_cache *mnt_cache __read_mostly;
41static struct rw_semaphore namespace_sem; 44static struct rw_semaphore namespace_sem;
42 45
@@ -48,8 +51,8 @@ static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
48{ 51{
49 unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES); 52 unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES);
50 tmp += ((unsigned long)dentry / L1_CACHE_BYTES); 53 tmp += ((unsigned long)dentry / L1_CACHE_BYTES);
51 tmp = tmp + (tmp >> hash_bits); 54 tmp = tmp + (tmp >> HASH_SHIFT);
52 return tmp & hash_mask; 55 return tmp & (HASH_SIZE - 1);
53} 56}
54 57
55struct vfsmount *alloc_vfsmnt(const char *name) 58struct vfsmount *alloc_vfsmnt(const char *name)
@@ -1813,9 +1816,7 @@ static void __init init_mount_tree(void)
1813 1816
1814void __init mnt_init(void) 1817void __init mnt_init(void)
1815{ 1818{
1816 struct list_head *d; 1819 unsigned u;
1817 unsigned int nr_hash;
1818 int i;
1819 int err; 1820 int err;
1820 1821
1821 init_rwsem(&namespace_sem); 1822 init_rwsem(&namespace_sem);
@@ -1828,35 +1829,11 @@ void __init mnt_init(void)
1828 if (!mount_hashtable) 1829 if (!mount_hashtable)
1829 panic("Failed to allocate mount hash table\n"); 1830 panic("Failed to allocate mount hash table\n");
1830 1831
1831 /* 1832 printk("Mount-cache hash table entries: %lu\n", HASH_SIZE);
1832 * Find the power-of-two list-heads that can fit into the allocation.. 1833
1833 * We don't guarantee that "sizeof(struct list_head)" is necessarily 1834 for (u = 0; u < HASH_SIZE; u++)
1834 * a power-of-two. 1835 INIT_LIST_HEAD(&mount_hashtable[u]);
1835 */
1836 nr_hash = PAGE_SIZE / sizeof(struct list_head);
1837 hash_bits = 0;
1838 do {
1839 hash_bits++;
1840 } while ((nr_hash >> hash_bits) != 0);
1841 hash_bits--;
1842 1836
1843 /*
1844 * Re-calculate the actual number of entries and the mask
1845 * from the number of bits we can fit.
1846 */
1847 nr_hash = 1UL << hash_bits;
1848 hash_mask = nr_hash - 1;
1849
1850 printk("Mount-cache hash table entries: %d\n", nr_hash);
1851
1852 /* And initialize the newly allocated array */
1853 d = mount_hashtable;
1854 i = nr_hash;
1855 do {
1856 INIT_LIST_HEAD(d);
1857 d++;
1858 i--;
1859 } while (i);
1860 err = sysfs_init(); 1837 err = sysfs_init();
1861 if (err) 1838 if (err)
1862 printk(KERN_WARNING "%s: sysfs_init error: %d\n", 1839 printk(KERN_WARNING "%s: sysfs_init error: %d\n",
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
index e1cb70c643f8..eff1f18d034f 100644
--- a/fs/ncpfs/inode.c
+++ b/fs/ncpfs/inode.c
@@ -987,7 +987,7 @@ static struct file_system_type ncp_fs_type = {
987static int __init init_ncp_fs(void) 987static int __init init_ncp_fs(void)
988{ 988{
989 int err; 989 int err;
990 DPRINTK("ncpfs: init_module called\n"); 990 DPRINTK("ncpfs: init_ncp_fs called\n");
991 991
992 err = init_inodecache(); 992 err = init_inodecache();
993 if (err) 993 if (err)
@@ -1004,7 +1004,7 @@ out1:
1004 1004
1005static void __exit exit_ncp_fs(void) 1005static void __exit exit_ncp_fs(void)
1006{ 1006{
1007 DPRINTK("ncpfs: cleanup_module called\n"); 1007 DPRINTK("ncpfs: exit_ncp_fs called\n");
1008 unregister_filesystem(&ncp_fs_type); 1008 unregister_filesystem(&ncp_fs_type);
1009 destroy_inodecache(); 1009 destroy_inodecache();
1010} 1010}
diff --git a/fs/partitions/Kconfig b/fs/partitions/Kconfig
index a99acd8de353..cb5f0a3f1b03 100644
--- a/fs/partitions/Kconfig
+++ b/fs/partitions/Kconfig
@@ -198,7 +198,7 @@ config LDM_DEBUG
198 198
199config SGI_PARTITION 199config SGI_PARTITION
200 bool "SGI partition support" if PARTITION_ADVANCED 200 bool "SGI partition support" if PARTITION_ADVANCED
201 default y if (SGI_IP22 || SGI_IP27 || ((MACH_JAZZ || SNI_RM) && !CPU_LITTLE_ENDIAN)) 201 default y if DEFAULT_SGI_PARTITION
202 help 202 help
203 Say Y here if you would like to be able to read the hard disk 203 Say Y here if you would like to be able to read the hard disk
204 partition table format used by SGI machines. 204 partition table format used by SGI machines.
diff --git a/fs/pnode.c b/fs/pnode.c
index 89940f243fc2..05ba692bc540 100644
--- a/fs/pnode.c
+++ b/fs/pnode.c
@@ -83,6 +83,8 @@ void change_mnt_propagation(struct vfsmount *mnt, int type)
83 mnt->mnt_master = NULL; 83 mnt->mnt_master = NULL;
84 if (type == MS_UNBINDABLE) 84 if (type == MS_UNBINDABLE)
85 mnt->mnt_flags |= MNT_UNBINDABLE; 85 mnt->mnt_flags |= MNT_UNBINDABLE;
86 else
87 mnt->mnt_flags &= ~MNT_UNBINDABLE;
86 } 88 }
87} 89}
88 90
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c
index 51288db37a0c..2686592dbcb2 100644
--- a/fs/proc/proc_misc.c
+++ b/fs/proc/proc_misc.c
@@ -29,6 +29,7 @@
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <linux/mmzone.h> 30#include <linux/mmzone.h>
31#include <linux/pagemap.h> 31#include <linux/pagemap.h>
32#include <linux/interrupt.h>
32#include <linux/swap.h> 33#include <linux/swap.h>
33#include <linux/slab.h> 34#include <linux/slab.h>
34#include <linux/smp.h> 35#include <linux/smp.h>
@@ -64,7 +65,6 @@
64 */ 65 */
65extern int get_hardware_list(char *); 66extern int get_hardware_list(char *);
66extern int get_stram_list(char *); 67extern int get_stram_list(char *);
67extern int get_filesystem_list(char *);
68extern int get_exec_domain_list(char *); 68extern int get_exec_domain_list(char *);
69extern int get_dma_list(char *); 69extern int get_dma_list(char *);
70 70
@@ -84,10 +84,15 @@ static int loadavg_read_proc(char *page, char **start, off_t off,
84{ 84{
85 int a, b, c; 85 int a, b, c;
86 int len; 86 int len;
87 unsigned long seq;
88
89 do {
90 seq = read_seqbegin(&xtime_lock);
91 a = avenrun[0] + (FIXED_1/200);
92 b = avenrun[1] + (FIXED_1/200);
93 c = avenrun[2] + (FIXED_1/200);
94 } while (read_seqretry(&xtime_lock, seq));
87 95
88 a = avenrun[0] + (FIXED_1/200);
89 b = avenrun[1] + (FIXED_1/200);
90 c = avenrun[2] + (FIXED_1/200);
91 len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n", 96 len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
92 LOAD_INT(a), LOAD_FRAC(a), 97 LOAD_INT(a), LOAD_FRAC(a),
93 LOAD_INT(b), LOAD_FRAC(b), 98 LOAD_INT(b), LOAD_FRAC(b),
@@ -599,7 +604,6 @@ static void int_seq_stop(struct seq_file *f, void *v)
599} 604}
600 605
601 606
602extern int show_interrupts(struct seq_file *f, void *v); /* In arch code */
603static struct seq_operations int_seq_ops = { 607static struct seq_operations int_seq_ops = {
604 .start = int_seq_start, 608 .start = int_seq_start,
605 .next = int_seq_next, 609 .next = int_seq_next,
diff --git a/fs/reiserfs/prints.c b/fs/reiserfs/prints.c
index 5e7388b32d02..740bb8c0c1ae 100644
--- a/fs/reiserfs/prints.c
+++ b/fs/reiserfs/prints.c
@@ -575,6 +575,8 @@ void print_block(struct buffer_head *bh, ...) //int print_mode, int first, int l
575 printk 575 printk
576 ("Block %llu contains unformatted data\n", 576 ("Block %llu contains unformatted data\n",
577 (unsigned long long)bh->b_blocknr); 577 (unsigned long long)bh->b_blocknr);
578
579 va_end(args);
578} 580}
579 581
580static char print_tb_buf[2048]; 582static char print_tb_buf[2048];
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index 1597f6b649e0..a5bd23ce0e46 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -1084,7 +1084,7 @@ ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
1084} 1084}
1085 1085
1086/* This is the implementation for the xattr plugin infrastructure */ 1086/* This is the implementation for the xattr plugin infrastructure */
1087static struct list_head xattr_handlers = LIST_HEAD_INIT(xattr_handlers); 1087static LIST_HEAD(xattr_handlers);
1088static DEFINE_RWLOCK(handler_lock); 1088static DEFINE_RWLOCK(handler_lock);
1089 1089
1090static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char 1090static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
diff --git a/fs/select.c b/fs/select.c
index 47f47925aea2..5633fe980781 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -739,7 +739,7 @@ asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
739 timeout_jiffies = -1; 739 timeout_jiffies = -1;
740 else 740 else
741#endif 741#endif
742 timeout_jiffies = msecs_to_jiffies(timeout_msecs); 742 timeout_jiffies = msecs_to_jiffies(timeout_msecs) + 1;
743 } else { 743 } else {
744 /* Infinite (< 0) or no (0) timeout */ 744 /* Infinite (< 0) or no (0) timeout */
745 timeout_jiffies = timeout_msecs; 745 timeout_jiffies = timeout_msecs;
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 2d3e107da2d3..cb2b63ae0bf4 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -27,6 +27,7 @@
27#include <linux/list.h> 27#include <linux/list.h>
28#include <linux/anon_inodes.h> 28#include <linux/anon_inodes.h>
29#include <linux/signalfd.h> 29#include <linux/signalfd.h>
30#include <linux/syscalls.h>
30 31
31struct signalfd_ctx { 32struct signalfd_ctx {
32 sigset_t sigmask; 33 sigset_t sigmask;
diff --git a/fs/smbfs/sock.c b/fs/smbfs/sock.c
index e48bd8235a8e..e37fe4deebd0 100644
--- a/fs/smbfs/sock.c
+++ b/fs/smbfs/sock.c
@@ -329,9 +329,8 @@ smb_receive(struct smb_sb_info *server, struct smb_request *req)
329 msg.msg_control = NULL; 329 msg.msg_control = NULL;
330 330
331 /* Dont repeat bytes and count available bufferspace */ 331 /* Dont repeat bytes and count available bufferspace */
332 rlen = smb_move_iov(&p, &num, iov, req->rq_bytes_recvd); 332 rlen = min_t(int, smb_move_iov(&p, &num, iov, req->rq_bytes_recvd),
333 if (req->rq_rlen < rlen) 333 (req->rq_rlen - req->rq_bytes_recvd));
334 rlen = req->rq_rlen;
335 334
336 result = kernel_recvmsg(sock, &msg, p, num, rlen, flags); 335 result = kernel_recvmsg(sock, &msg, p, num, rlen, flags);
337 336
diff --git a/fs/utimes.c b/fs/utimes.c
index b9912ecbee24..e5588cd8530e 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -6,6 +6,7 @@
6#include <linux/sched.h> 6#include <linux/sched.h>
7#include <linux/stat.h> 7#include <linux/stat.h>
8#include <linux/utime.h> 8#include <linux/utime.h>
9#include <linux/syscalls.h>
9#include <asm/uaccess.h> 10#include <asm/uaccess.h>
10#include <asm/unistd.h> 11#include <asm/unistd.h>
11 12