aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/9p/fid.c4
-rw-r--r--fs/9p/v9fs.c51
-rw-r--r--fs/9p/v9fs.h5
-rw-r--r--fs/9p/vfs_file.c4
-rw-r--r--fs/9p/vfs_inode.c7
-rw-r--r--fs/Kconfig121
-rw-r--r--fs/affs/affs.h3
-rw-r--r--fs/affs/amigaffs.c6
-rw-r--r--fs/affs/inode.c20
-rw-r--r--fs/affs/namei.c12
-rw-r--r--fs/affs/super.c12
-rw-r--r--fs/afs/dir.c4
-rw-r--r--fs/afs/inode.c5
-rw-r--r--fs/afs/security.c2
-rw-r--r--fs/autofs/autofs_i.h1
-rw-r--r--fs/autofs/inode.c27
-rw-r--r--fs/autofs/root.c22
-rw-r--r--fs/bad_inode.c14
-rw-r--r--fs/befs/btree.c2
-rw-r--r--fs/befs/datastream.c2
-rw-r--r--fs/befs/linuxvfs.c39
-rw-r--r--fs/bfs/bfs.h2
-rw-r--r--fs/bfs/dir.c6
-rw-r--r--fs/bfs/inode.c32
-rw-r--r--fs/binfmt_aout.c2
-rw-r--r--fs/binfmt_elf.c4
-rw-r--r--fs/block_dev.c1
-rw-r--r--fs/buffer.c62
-rw-r--r--fs/cifs/cifsfs.c8
-rw-r--r--fs/cifs/cifsfs.h1
-rw-r--r--fs/cifs/inode.c24
-rw-r--r--fs/compat.c81
-rw-r--r--fs/compat_ioctl.c2
-rw-r--r--fs/dcache.c5
-rw-r--r--fs/direct-io.c4
-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.c28
-rw-r--r--fs/ecryptfs/read_write.c2
-rw-r--r--fs/ecryptfs/super.c48
-rw-r--r--fs/efs/inode.c25
-rw-r--r--fs/efs/namei.c23
-rw-r--r--fs/efs/super.c16
-rw-r--r--fs/eventfd.c1
-rw-r--r--fs/eventpoll.c2
-rw-r--r--fs/exec.c16
-rw-r--r--fs/ext2/balloc.c98
-rw-r--r--fs/ext2/dir.c2
-rw-r--r--fs/ext2/ext2.h5
-rw-r--r--fs/ext2/file.c4
-rw-r--r--fs/ext2/inode.c37
-rw-r--r--fs/ext2/ioctl.c12
-rw-r--r--fs/ext2/namei.c12
-rw-r--r--fs/ext2/super.c63
-rw-r--r--fs/ext3/balloc.c94
-rw-r--r--fs/ext3/ialloc.c58
-rw-r--r--fs/ext3/inode.c143
-rw-r--r--fs/ext3/namei.c33
-rw-r--r--fs/ext3/resize.c7
-rw-r--r--fs/ext3/super.c69
-rw-r--r--fs/ext4/balloc.c8
-rw-r--r--fs/ext4/ialloc.c58
-rw-r--r--fs/ext4/inode.c38
-rw-r--r--fs/ext4/namei.c29
-rw-r--r--fs/ext4/resize.c7
-rw-r--r--fs/ext4/super.c50
-rw-r--r--fs/fat/file.c47
-rw-r--r--fs/fat/inode.c14
-rw-r--r--fs/fat/misc.c5
-rw-r--r--fs/file.c8
-rw-r--r--fs/freevxfs/vxfs_dir.h2
-rw-r--r--fs/freevxfs/vxfs_extern.h2
-rw-r--r--fs/freevxfs/vxfs_immed.c2
-rw-r--r--fs/freevxfs/vxfs_inode.c45
-rw-r--r--fs/freevxfs/vxfs_lookup.c6
-rw-r--r--fs/freevxfs/vxfs_super.c10
-rw-r--r--fs/fs-writeback.c38
-rw-r--r--fs/fuse/dev.c113
-rw-r--r--fs/fuse/dir.c7
-rw-r--r--fs/fuse/file.c14
-rw-r--r--fs/fuse/fuse_i.h18
-rw-r--r--fs/fuse/inode.c7
-rw-r--r--fs/gfs2/bmap.c2
-rw-r--r--fs/gfs2/dir.c2
-rw-r--r--fs/gfs2/glock.c37
-rw-r--r--fs/gfs2/glock.h4
-rw-r--r--fs/gfs2/incore.h4
-rw-r--r--fs/gfs2/inode.c2
-rw-r--r--fs/gfs2/ops_address.c2
-rw-r--r--fs/gfs2/ops_export.c2
-rw-r--r--fs/gfs2/ops_inode.c2
-rw-r--r--fs/gfs2/recovery.c2
-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/hfsplus/btree.c6
-rw-r--r--fs/hfsplus/dir.c6
-rw-r--r--fs/hfsplus/hfsplus_fs.h3
-rw-r--r--fs/hfsplus/super.c47
-rw-r--r--fs/hostfs/hostfs_kern.c57
-rw-r--r--fs/hostfs/hostfs_user.c8
-rw-r--r--fs/hppfs/hppfs_kern.c27
-rw-r--r--fs/hugetlbfs/inode.c2
-rw-r--r--fs/inode.c4
-rw-r--r--fs/inotify.c30
-rw-r--r--fs/inotify_user.c29
-rw-r--r--fs/ioctl.c223
-rw-r--r--fs/isofs/export.c14
-rw-r--r--fs/isofs/inode.c68
-rw-r--r--fs/isofs/namei.c4
-rw-r--r--fs/isofs/rock.c4
-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/jffs2/dir.c6
-rw-r--r--fs/jffs2/fs.c56
-rw-r--r--fs/jffs2/os-linux.h2
-rw-r--r--fs/jffs2/readinode.c2
-rw-r--r--fs/jffs2/super.c1
-rw-r--r--fs/jffs2/write.c4
-rw-r--r--fs/jfs/inode.c20
-rw-r--r--fs/jfs/jfs_inode.h2
-rw-r--r--fs/jfs/jfs_xtree.c2
-rw-r--r--fs/jfs/namei.c34
-rw-r--r--fs/jfs/super.c15
-rw-r--r--fs/libfs.c11
-rw-r--r--fs/locks.c125
-rw-r--r--fs/minix/inode.c43
-rw-r--r--fs/minix/minix.h1
-rw-r--r--fs/minix/namei.c7
-rw-r--r--fs/mpage.c7
-rw-r--r--fs/namei.c3
-rw-r--r--fs/namespace.c45
-rw-r--r--fs/ncpfs/inode.c4
-rw-r--r--fs/ncpfs/mmap.c4
-rw-r--r--fs/nfs/getroot.c4
-rw-r--r--fs/nfs/read.c10
-rw-r--r--fs/nfs/write.c4
-rw-r--r--fs/nfsd/auth.c10
-rw-r--r--fs/nfsd/export.c4
-rw-r--r--fs/ntfs/aops.c20
-rw-r--r--fs/ntfs/compress.c2
-rw-r--r--fs/ntfs/file.c32
-rw-r--r--fs/ntfs/malloc.h3
-rw-r--r--fs/ocfs2/alloc.c4
-rw-r--r--fs/ocfs2/aops.c6
-rw-r--r--fs/ocfs2/dir.c2
-rw-r--r--fs/ocfs2/ocfs1_fs_compat.h2
-rw-r--r--fs/ocfs2/suballoc.c2
-rw-r--r--fs/openpromfs/inode.c45
-rw-r--r--fs/partitions/Kconfig2
-rw-r--r--fs/pnode.c2
-rw-r--r--fs/proc/array.c21
-rw-r--r--fs/proc/base.c51
-rw-r--r--fs/proc/inode.c60
-rw-r--r--fs/proc/internal.h8
-rw-r--r--fs/proc/kcore.c2
-rw-r--r--fs/proc/proc_misc.c150
-rw-r--r--fs/proc/task_mmu.c676
-rw-r--r--fs/qnx4/inode.c47
-rw-r--r--fs/qnx4/namei.c8
-rw-r--r--fs/quota.c4
-rw-r--r--fs/reiserfs/bitmap.c6
-rw-r--r--fs/reiserfs/inode.c6
-rw-r--r--fs/reiserfs/prints.c2
-rw-r--r--fs/reiserfs/xattr.c6
-rw-r--r--fs/romfs/inode.c46
-rw-r--r--fs/select.c2
-rw-r--r--fs/signalfd.c3
-rw-r--r--fs/smbfs/inode.c7
-rw-r--r--fs/smbfs/sock.c5
-rw-r--r--fs/sysv/inode.c25
-rw-r--r--fs/sysv/namei.c6
-rw-r--r--fs/sysv/super.c4
-rw-r--r--fs/sysv/sysv.h1
-rw-r--r--fs/timerfd.c207
-rw-r--r--fs/ufs/inode.c34
-rw-r--r--fs/ufs/namei.c6
-rw-r--r--fs/ufs/super.c14
-rw-r--r--fs/ufs/ufs.h2
-rw-r--r--fs/utimes.c1
-rw-r--r--fs/vfat/namei.c2
-rw-r--r--fs/xattr.c45
-rw-r--r--fs/xfs/linux-2.6/kmem.c3
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.c3
-rw-r--r--fs/xfs/linux-2.6/xfs_lrw.c2
193 files changed, 2891 insertions, 1979 deletions
diff --git a/fs/9p/fid.c b/fs/9p/fid.c
index b364da70ff28..dfebdbe7440e 100644
--- a/fs/9p/fid.c
+++ b/fs/9p/fid.c
@@ -175,7 +175,7 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
175 if (!wnames) 175 if (!wnames)
176 return ERR_PTR(-ENOMEM); 176 return ERR_PTR(-ENOMEM);
177 177
178 for (d = dentry, i = n; i >= 0; i--, d = d->d_parent) 178 for (d = dentry, i = (n-1); i >= 0; i--, d = d->d_parent)
179 wnames[i] = (char *) d->d_name.name; 179 wnames[i] = (char *) d->d_name.name;
180 180
181 clone = 1; 181 clone = 1;
@@ -183,7 +183,7 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
183 while (i < n) { 183 while (i < n) {
184 l = min(n - i, P9_MAXWELEM); 184 l = min(n - i, P9_MAXWELEM);
185 fid = p9_client_walk(fid, l, &wnames[i], clone); 185 fid = p9_client_walk(fid, l, &wnames[i], clone);
186 if (!fid) { 186 if (IS_ERR(fid)) {
187 kfree(wnames); 187 kfree(wnames);
188 return fid; 188 return fid;
189 } 189 }
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index fbb12dadba83..9b0f0222e8bb 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * This file contains functions assisting in mapping VFS to 9P2000 4 * This file contains functions assisting in mapping VFS to 9P2000
5 * 5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> 6 * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> 7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
@@ -31,7 +31,6 @@
31#include <linux/idr.h> 31#include <linux/idr.h>
32#include <net/9p/9p.h> 32#include <net/9p/9p.h>
33#include <net/9p/transport.h> 33#include <net/9p/transport.h>
34#include <net/9p/conn.h>
35#include <net/9p/client.h> 34#include <net/9p/client.h>
36#include "v9fs.h" 35#include "v9fs.h"
37#include "v9fs_vfs.h" 36#include "v9fs_vfs.h"
@@ -43,11 +42,11 @@
43 42
44enum { 43enum {
45 /* Options that take integer arguments */ 44 /* Options that take integer arguments */
46 Opt_debug, Opt_msize, Opt_dfltuid, Opt_dfltgid, Opt_afid, 45 Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid,
47 /* String options */ 46 /* String options */
48 Opt_uname, Opt_remotename, Opt_trans, 47 Opt_uname, Opt_remotename, Opt_trans,
49 /* Options that take no arguments */ 48 /* Options that take no arguments */
50 Opt_legacy, Opt_nodevmap, 49 Opt_nodevmap,
51 /* Cache options */ 50 /* Cache options */
52 Opt_cache_loose, 51 Opt_cache_loose,
53 /* Access options */ 52 /* Access options */
@@ -58,14 +57,11 @@ enum {
58 57
59static match_table_t tokens = { 58static match_table_t tokens = {
60 {Opt_debug, "debug=%x"}, 59 {Opt_debug, "debug=%x"},
61 {Opt_msize, "msize=%u"},
62 {Opt_dfltuid, "dfltuid=%u"}, 60 {Opt_dfltuid, "dfltuid=%u"},
63 {Opt_dfltgid, "dfltgid=%u"}, 61 {Opt_dfltgid, "dfltgid=%u"},
64 {Opt_afid, "afid=%u"}, 62 {Opt_afid, "afid=%u"},
65 {Opt_uname, "uname=%s"}, 63 {Opt_uname, "uname=%s"},
66 {Opt_remotename, "aname=%s"}, 64 {Opt_remotename, "aname=%s"},
67 {Opt_trans, "trans=%s"},
68 {Opt_legacy, "noextend"},
69 {Opt_nodevmap, "nodevmap"}, 65 {Opt_nodevmap, "nodevmap"},
70 {Opt_cache_loose, "cache=loose"}, 66 {Opt_cache_loose, "cache=loose"},
71 {Opt_cache_loose, "loose"}, 67 {Opt_cache_loose, "loose"},
@@ -85,16 +81,14 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
85 char *options; 81 char *options;
86 substring_t args[MAX_OPT_ARGS]; 82 substring_t args[MAX_OPT_ARGS];
87 char *p; 83 char *p;
88 int option; 84 int option = 0;
89 int ret;
90 char *s, *e; 85 char *s, *e;
86 int ret;
91 87
92 /* setup defaults */ 88 /* setup defaults */
93 v9ses->maxdata = 8192;
94 v9ses->afid = ~0; 89 v9ses->afid = ~0;
95 v9ses->debug = 0; 90 v9ses->debug = 0;
96 v9ses->cache = 0; 91 v9ses->cache = 0;
97 v9ses->trans = v9fs_default_trans();
98 92
99 if (!v9ses->options) 93 if (!v9ses->options)
100 return; 94 return;
@@ -106,7 +100,8 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
106 continue; 100 continue;
107 token = match_token(p, tokens, args); 101 token = match_token(p, tokens, args);
108 if (token < Opt_uname) { 102 if (token < Opt_uname) {
109 if ((ret = match_int(&args[0], &option)) < 0) { 103 ret = match_int(&args[0], &option);
104 if (ret < 0) {
110 P9_DPRINTK(P9_DEBUG_ERROR, 105 P9_DPRINTK(P9_DEBUG_ERROR,
111 "integer field, but no integer?\n"); 106 "integer field, but no integer?\n");
112 continue; 107 continue;
@@ -119,9 +114,7 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
119 p9_debug_level = option; 114 p9_debug_level = option;
120#endif 115#endif
121 break; 116 break;
122 case Opt_msize: 117
123 v9ses->maxdata = option;
124 break;
125 case Opt_dfltuid: 118 case Opt_dfltuid:
126 v9ses->dfltuid = option; 119 v9ses->dfltuid = option;
127 break; 120 break;
@@ -131,18 +124,12 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
131 case Opt_afid: 124 case Opt_afid:
132 v9ses->afid = option; 125 v9ses->afid = option;
133 break; 126 break;
134 case Opt_trans:
135 v9ses->trans = v9fs_match_trans(&args[0]);
136 break;
137 case Opt_uname: 127 case Opt_uname:
138 match_strcpy(v9ses->uname, &args[0]); 128 match_strcpy(v9ses->uname, &args[0]);
139 break; 129 break;
140 case Opt_remotename: 130 case Opt_remotename:
141 match_strcpy(v9ses->aname, &args[0]); 131 match_strcpy(v9ses->aname, &args[0]);
142 break; 132 break;
143 case Opt_legacy:
144 v9ses->flags &= ~V9FS_EXTENDED;
145 break;
146 case Opt_nodevmap: 133 case Opt_nodevmap:
147 v9ses->nodev = 1; 134 v9ses->nodev = 1;
148 break; 135 break;
@@ -185,7 +172,6 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
185 const char *dev_name, char *data) 172 const char *dev_name, char *data)
186{ 173{
187 int retval = -EINVAL; 174 int retval = -EINVAL;
188 struct p9_trans *trans = NULL;
189 struct p9_fid *fid; 175 struct p9_fid *fid;
190 176
191 v9ses->uname = __getname(); 177 v9ses->uname = __getname();
@@ -207,24 +193,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
207 v9ses->options = kstrdup(data, GFP_KERNEL); 193 v9ses->options = kstrdup(data, GFP_KERNEL);
208 v9fs_parse_options(v9ses); 194 v9fs_parse_options(v9ses);
209 195
210 if (v9ses->trans == NULL) { 196 v9ses->clnt = p9_client_create(dev_name, v9ses->options);
211 retval = -EPROTONOSUPPORT;
212 P9_DPRINTK(P9_DEBUG_ERROR,
213 "No transport defined or default transport\n");
214 goto error;
215 }
216
217 trans = v9ses->trans->create(dev_name, v9ses->options);
218 if (IS_ERR(trans)) {
219 retval = PTR_ERR(trans);
220 trans = NULL;
221 goto error;
222 }
223 if ((v9ses->maxdata+P9_IOHDRSZ) > v9ses->trans->maxsize)
224 v9ses->maxdata = v9ses->trans->maxsize-P9_IOHDRSZ;
225
226 v9ses->clnt = p9_client_create(trans, v9ses->maxdata+P9_IOHDRSZ,
227 v9fs_extended(v9ses));
228 197
229 if (IS_ERR(v9ses->clnt)) { 198 if (IS_ERR(v9ses->clnt)) {
230 retval = PTR_ERR(v9ses->clnt); 199 retval = PTR_ERR(v9ses->clnt);
@@ -236,6 +205,8 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
236 if (!v9ses->clnt->dotu) 205 if (!v9ses->clnt->dotu)
237 v9ses->flags &= ~V9FS_EXTENDED; 206 v9ses->flags &= ~V9FS_EXTENDED;
238 207
208 v9ses->maxdata = v9ses->clnt->msize;
209
239 /* for legacy mode, fall back to V9FS_ACCESS_ANY */ 210 /* for legacy mode, fall back to V9FS_ACCESS_ANY */
240 if (!v9fs_extended(v9ses) && 211 if (!v9fs_extended(v9ses) &&
241 ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) { 212 ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h
index db4b4193f2e2..7d3a1018db52 100644
--- a/fs/9p/v9fs.h
+++ b/fs/9p/v9fs.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * V9FS definitions. 2 * V9FS definitions.
3 * 3 *
4 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> 4 * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
5 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> 5 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -28,7 +28,6 @@
28 28
29struct v9fs_session_info { 29struct v9fs_session_info {
30 /* options */ 30 /* options */
31 unsigned int maxdata;
32 unsigned char flags; /* session flags */ 31 unsigned char flags; /* session flags */
33 unsigned char nodev; /* set to 1 if no disable device mapping */ 32 unsigned char nodev; /* set to 1 if no disable device mapping */
34 unsigned short debug; /* debug level */ 33 unsigned short debug; /* debug level */
@@ -38,10 +37,10 @@ struct v9fs_session_info {
38 char *options; /* copy of mount options */ 37 char *options; /* copy of mount options */
39 char *uname; /* user name to mount as */ 38 char *uname; /* user name to mount as */
40 char *aname; /* name of remote hierarchy being mounted */ 39 char *aname; /* name of remote hierarchy being mounted */
40 unsigned int maxdata; /* max data for client interface */
41 unsigned int dfltuid; /* default uid/muid for legacy support */ 41 unsigned int dfltuid; /* default uid/muid for legacy support */
42 unsigned int dfltgid; /* default gid for legacy support */ 42 unsigned int dfltgid; /* default gid for legacy support */
43 u32 uid; /* if ACCESS_SINGLE, the uid that has access */ 43 u32 uid; /* if ACCESS_SINGLE, the uid that has access */
44 struct p9_trans_module *trans; /* 9p transport */
45 struct p9_client *clnt; /* 9p client */ 44 struct p9_client *clnt; /* 9p client */
46 struct dentry *debugfs_dir; 45 struct dentry *debugfs_dir;
47}; 46};
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index ba4b1caa9c43..a616fff8906d 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -184,7 +184,7 @@ static const struct file_operations v9fs_cached_file_operations = {
184 .open = v9fs_file_open, 184 .open = v9fs_file_open,
185 .release = v9fs_dir_release, 185 .release = v9fs_dir_release,
186 .lock = v9fs_file_lock, 186 .lock = v9fs_file_lock,
187 .mmap = generic_file_mmap, 187 .mmap = generic_file_readonly_mmap,
188}; 188};
189 189
190const struct file_operations v9fs_file_operations = { 190const struct file_operations v9fs_file_operations = {
@@ -194,5 +194,5 @@ const struct file_operations v9fs_file_operations = {
194 .open = v9fs_file_open, 194 .open = v9fs_file_open,
195 .release = v9fs_dir_release, 195 .release = v9fs_dir_release,
196 .lock = v9fs_file_lock, 196 .lock = v9fs_file_lock,
197 .mmap = generic_file_mmap, 197 .mmap = generic_file_readonly_mmap,
198}; 198};
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 23581bcb599b..6a28842052ea 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -77,6 +77,8 @@ static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
77 res |= P9_DMSETUID; 77 res |= P9_DMSETUID;
78 if ((mode & S_ISGID) == S_ISGID) 78 if ((mode & S_ISGID) == S_ISGID)
79 res |= P9_DMSETGID; 79 res |= P9_DMSETGID;
80 if ((mode & S_ISVTX) == S_ISVTX)
81 res |= P9_DMSETVTX;
80 if ((mode & P9_DMLINK)) 82 if ((mode & P9_DMLINK))
81 res |= P9_DMLINK; 83 res |= P9_DMLINK;
82 } 84 }
@@ -119,6 +121,9 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
119 121
120 if ((mode & P9_DMSETGID) == P9_DMSETGID) 122 if ((mode & P9_DMSETGID) == P9_DMSETGID)
121 res |= S_ISGID; 123 res |= S_ISGID;
124
125 if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
126 res |= S_ISVTX;
122 } 127 }
123 128
124 return res; 129 return res;
@@ -568,7 +573,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
568 v9ses = v9fs_inode2v9ses(dir); 573 v9ses = v9fs_inode2v9ses(dir);
569 dfid = v9fs_fid_lookup(dentry->d_parent); 574 dfid = v9fs_fid_lookup(dentry->d_parent);
570 if (IS_ERR(dfid)) 575 if (IS_ERR(dfid))
571 return ERR_PTR(PTR_ERR(dfid)); 576 return ERR_CAST(dfid);
572 577
573 name = (char *) dentry->d_name.name; 578 name = (char *) dentry->d_name.name;
574 fid = p9_client_walk(dfid, 1, &name, 1); 579 fid = p9_client_walk(dfid, 1, &name, 1);
diff --git a/fs/Kconfig b/fs/Kconfig
index 987b5d7cb21a..3bf6ace1720c 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -463,40 +463,18 @@ config OCFS2_DEBUG_FS
463 this option for debugging only as it is likely to decrease 463 this option for debugging only as it is likely to decrease
464 performance of the filesystem. 464 performance of the filesystem.
465 465
466config MINIX_FS 466endif # BLOCK
467 tristate "Minix fs support"
468 help
469 Minix is a simple operating system used in many classes about OS's.
470 The minix file system (method to organize files on a hard disk
471 partition or a floppy disk) was the original file system for Linux,
472 but has been superseded by the second extended file system ext2fs.
473 You don't want to use the minix file system on your hard disk
474 because of certain built-in restrictions, but it is sometimes found
475 on older Linux floppy disks. This option will enlarge your kernel
476 by about 28 KB. If unsure, say N.
477
478 To compile this file system support as a module, choose M here: the
479 module will be called minix. Note that the file system of your root
480 partition (the one containing the directory /) cannot be compiled as
481 a module.
482
483config ROMFS_FS
484 tristate "ROM file system support"
485 ---help---
486 This is a very small read-only file system mainly intended for
487 initial ram disks of installation disks, but it could be used for
488 other read-only media as well. Read
489 <file:Documentation/filesystems/romfs.txt> for details.
490
491 To compile this file system support as a module, choose M here: the
492 module will be called romfs. Note that the file system of your
493 root partition (the one containing the directory /) cannot be a
494 module.
495 467
496 If you don't know whether you need it, then you don't need it: 468config DNOTIFY
497 answer N. 469 bool "Dnotify support"
470 default y
471 help
472 Dnotify is a directory-based per-fd file change notification system
473 that uses signals to communicate events to user-space. There exist
474 superior alternatives, but some applications may still rely on
475 dnotify.
498 476
499endif 477 If unsure, say Y.
500 478
501config INOTIFY 479config INOTIFY
502 bool "Inotify file change notification support" 480 bool "Inotify file change notification support"
@@ -577,17 +555,6 @@ config QUOTACTL
577 depends on XFS_QUOTA || QUOTA 555 depends on XFS_QUOTA || QUOTA
578 default y 556 default y
579 557
580config DNOTIFY
581 bool "Dnotify support"
582 default y
583 help
584 Dnotify is a directory-based per-fd file change notification system
585 that uses signals to communicate events to user-space. There exist
586 superior alternatives, but some applications may still rely on
587 dnotify.
588
589 If unsure, say Y.
590
591config AUTOFS_FS 558config AUTOFS_FS
592 tristate "Kernel automounter support" 559 tristate "Kernel automounter support"
593 help 560 help
@@ -713,7 +680,7 @@ config UDF_NLS
713 depends on (UDF_FS=m && NLS) || (UDF_FS=y && NLS=y) 680 depends on (UDF_FS=m && NLS) || (UDF_FS=y && NLS=y)
714 681
715endmenu 682endmenu
716endif 683endif # BLOCK
717 684
718if BLOCK 685if BLOCK
719menu "DOS/FAT/NT Filesystems" 686menu "DOS/FAT/NT Filesystems"
@@ -896,7 +863,7 @@ config NTFS_RW
896 It is perfectly safe to say N here. 863 It is perfectly safe to say N here.
897 864
898endmenu 865endmenu
899endif 866endif # BLOCK
900 867
901menu "Pseudo filesystems" 868menu "Pseudo filesystems"
902 869
@@ -1152,7 +1119,7 @@ config BEFS_DEBUG
1152 depends on BEFS_FS 1119 depends on BEFS_FS
1153 help 1120 help
1154 If you say Y here, you can use the 'debug' mount option to enable 1121 If you say Y here, you can use the 'debug' mount option to enable
1155 debugging output from the driver. 1122 debugging output from the driver.
1156 1123
1157config BFS_FS 1124config BFS_FS
1158 tristate "BFS file system support (EXPERIMENTAL)" 1125 tristate "BFS file system support (EXPERIMENTAL)"
@@ -1263,7 +1230,7 @@ config JFFS2_FS_XATTR
1263 Extended attributes are name:value pairs associated with inodes by 1230 Extended attributes are name:value pairs associated with inodes by
1264 the kernel or by users (see the attr(5) manual page, or visit 1231 the kernel or by users (see the attr(5) manual page, or visit
1265 <http://acl.bestbits.at/> for details). 1232 <http://acl.bestbits.at/> for details).
1266 1233
1267 If unsure, say N. 1234 If unsure, say N.
1268 1235
1269config JFFS2_FS_POSIX_ACL 1236config JFFS2_FS_POSIX_ACL
@@ -1274,10 +1241,10 @@ config JFFS2_FS_POSIX_ACL
1274 help 1241 help
1275 Posix Access Control Lists (ACLs) support permissions for users and 1242 Posix Access Control Lists (ACLs) support permissions for users and
1276 groups beyond the owner/group/world scheme. 1243 groups beyond the owner/group/world scheme.
1277 1244
1278 To learn more about Access Control Lists, visit the Posix ACLs for 1245 To learn more about Access Control Lists, visit the Posix ACLs for
1279 Linux website <http://acl.bestbits.at/>. 1246 Linux website <http://acl.bestbits.at/>.
1280 1247
1281 If you don't know what Access Control Lists are, say N 1248 If you don't know what Access Control Lists are, say N
1282 1249
1283config JFFS2_FS_SECURITY 1250config JFFS2_FS_SECURITY
@@ -1289,7 +1256,7 @@ config JFFS2_FS_SECURITY
1289 implemented by security modules like SELinux. This option 1256 implemented by security modules like SELinux. This option
1290 enables an extended attribute handler for file security 1257 enables an extended attribute handler for file security
1291 labels in the jffs2 filesystem. 1258 labels in the jffs2 filesystem.
1292 1259
1293 If you are not using a security module that requires using 1260 If you are not using a security module that requires using
1294 extended attributes for file security labels, say N. 1261 extended attributes for file security labels, say N.
1295 1262
@@ -1417,6 +1384,24 @@ config VXFS_FS
1417 To compile this as a module, choose M here: the module will be 1384 To compile this as a module, choose M here: the module will be
1418 called freevxfs. If unsure, say N. 1385 called freevxfs. If unsure, say N.
1419 1386
1387config MINIX_FS
1388 tristate "Minix file system support"
1389 depends on BLOCK
1390 help
1391 Minix is a simple operating system used in many classes about OS's.
1392 The minix file system (method to organize files on a hard disk
1393 partition or a floppy disk) was the original file system for Linux,
1394 but has been superseded by the second extended file system ext2fs.
1395 You don't want to use the minix file system on your hard disk
1396 because of certain built-in restrictions, but it is sometimes found
1397 on older Linux floppy disks. This option will enlarge your kernel
1398 by about 28 KB. If unsure, say N.
1399
1400 To compile this file system support as a module, choose M here: the
1401 module will be called minix. Note that the file system of your root
1402 partition (the one containing the directory /) cannot be compiled as
1403 a module.
1404
1420 1405
1421config HPFS_FS 1406config HPFS_FS
1422 tristate "OS/2 HPFS file system support" 1407 tristate "OS/2 HPFS file system support"
@@ -1434,7 +1419,6 @@ config HPFS_FS
1434 module will be called hpfs. If unsure, say N. 1419 module will be called hpfs. If unsure, say N.
1435 1420
1436 1421
1437
1438config QNX4FS_FS 1422config QNX4FS_FS
1439 tristate "QNX4 file system support (read only)" 1423 tristate "QNX4 file system support (read only)"
1440 depends on BLOCK 1424 depends on BLOCK
@@ -1461,6 +1445,22 @@ config QNX4FS_RW
1461 It's currently broken, so for now: 1445 It's currently broken, so for now:
1462 answer N. 1446 answer N.
1463 1447
1448config ROMFS_FS
1449 tristate "ROM file system support"
1450 depends on BLOCK
1451 ---help---
1452 This is a very small read-only file system mainly intended for
1453 initial ram disks of installation disks, but it could be used for
1454 other read-only media as well. Read
1455 <file:Documentation/filesystems/romfs.txt> for details.
1456
1457 To compile this file system support as a module, choose M here: the
1458 module will be called romfs. Note that the file system of your
1459 root partition (the one containing the directory /) cannot be a
1460 module.
1461
1462 If you don't know whether you need it, then you don't need it:
1463 answer N.
1464 1464
1465 1465
1466config SYSV_FS 1466config SYSV_FS
@@ -1501,7 +1501,6 @@ config SYSV_FS
1501 If you haven't heard about all of this before, it's safe to say N. 1501 If you haven't heard about all of this before, it's safe to say N.
1502 1502
1503 1503
1504
1505config UFS_FS 1504config UFS_FS
1506 tristate "UFS file system support (read only)" 1505 tristate "UFS file system support (read only)"
1507 depends on BLOCK 1506 depends on BLOCK
@@ -1835,7 +1834,7 @@ config RPCSEC_GSS_SPKM3
1835 If unsure, say N. 1834 If unsure, say N.
1836 1835
1837config SMB_FS 1836config SMB_FS
1838 tristate "SMB file system support (to mount Windows shares etc.)" 1837 tristate "SMB file system support (OBSOLETE, please use CIFS)"
1839 depends on INET 1838 depends on INET
1840 select NLS 1839 select NLS
1841 help 1840 help
@@ -1858,8 +1857,8 @@ config SMB_FS
1858 General information about how to connect Linux, Windows machines and 1857 General information about how to connect Linux, Windows machines and
1859 Macs is on the WWW at <http://www.eats.com/linux_mac_win.html>. 1858 Macs is on the WWW at <http://www.eats.com/linux_mac_win.html>.
1860 1859
1861 To compile the SMB support as a module, choose M here: the module will 1860 To compile the SMB support as a module, choose M here:
1862 be called smbfs. Most people say N, however. 1861 the module will be called smbfs. Most people say N, however.
1863 1862
1864config SMB_NLS_DEFAULT 1863config SMB_NLS_DEFAULT
1865 bool "Use a default NLS" 1864 bool "Use a default NLS"
@@ -1891,7 +1890,7 @@ config SMB_NLS_REMOTE
1891 smbmount from samba 2.2.0 or later supports this. 1890 smbmount from samba 2.2.0 or later supports this.
1892 1891
1893config CIFS 1892config CIFS
1894 tristate "CIFS support (advanced network filesystem for Samba, Window and other CIFS compliant servers)" 1893 tristate "CIFS support (advanced network filesystem, SMBFS successor)"
1895 depends on INET 1894 depends on INET
1896 select NLS 1895 select NLS
1897 help 1896 help
@@ -1949,16 +1948,16 @@ config CIFS_WEAK_PW_HASH
1949 LANMAN based servers such as OS/2 and Windows 95, but such 1948 LANMAN based servers such as OS/2 and Windows 95, but such
1950 mounts may be less secure than mounts using NTLM or more recent 1949 mounts may be less secure than mounts using NTLM or more recent
1951 security mechanisms if you are on a public network. Unless you 1950 security mechanisms if you are on a public network. Unless you
1952 have a need to access old SMB servers (and are on a private 1951 have a need to access old SMB servers (and are on a private
1953 network) you probably want to say N. Even if this support 1952 network) you probably want to say N. Even if this support
1954 is enabled in the kernel build, LANMAN authentication will not be 1953 is enabled in the kernel build, LANMAN authentication will not be
1955 used automatically. At runtime LANMAN mounts are disabled but 1954 used automatically. At runtime LANMAN mounts are disabled but
1956 can be set to required (or optional) either in 1955 can be set to required (or optional) either in
1957 /proc/fs/cifs (see fs/cifs/README for more detail) or via an 1956 /proc/fs/cifs (see fs/cifs/README for more detail) or via an
1958 option on the mount command. This support is disabled by 1957 option on the mount command. This support is disabled by
1959 default in order to reduce the possibility of a downgrade 1958 default in order to reduce the possibility of a downgrade
1960 attack. 1959 attack.
1961 1960
1962 If unsure, say N. 1961 If unsure, say N.
1963 1962
1964config CIFS_XATTR 1963config CIFS_XATTR
@@ -1999,7 +1998,7 @@ config CIFS_DEBUG2
1999 messages in some error paths, slowing performance. This 1998 messages in some error paths, slowing performance. This
2000 option can be turned off unless you are debugging 1999 option can be turned off unless you are debugging
2001 cifs problems. If unsure, say N. 2000 cifs problems. If unsure, say N.
2002 2001
2003config CIFS_EXPERIMENTAL 2002config CIFS_EXPERIMENTAL
2004 bool "CIFS Experimental Features (EXPERIMENTAL)" 2003 bool "CIFS Experimental Features (EXPERIMENTAL)"
2005 depends on CIFS && EXPERIMENTAL 2004 depends on CIFS && EXPERIMENTAL
@@ -2090,7 +2089,7 @@ config CODA_FS_OLD_API
2090 However this new API is not backward compatible with older 2089 However this new API is not backward compatible with older
2091 clients. If you really need to run the old Coda userspace 2090 clients. If you really need to run the old Coda userspace
2092 cache manager then say Y. 2091 cache manager then say Y.
2093 2092
2094 For most cases you probably want to say N. 2093 For most cases you probably want to say N.
2095 2094
2096config AFS_FS 2095config AFS_FS
diff --git a/fs/affs/affs.h b/fs/affs/affs.h
index 232c69493683..d5bd497ab9cb 100644
--- a/fs/affs/affs.h
+++ b/fs/affs/affs.h
@@ -174,7 +174,8 @@ extern void affs_put_inode(struct inode *inode);
174extern void affs_drop_inode(struct inode *inode); 174extern void affs_drop_inode(struct inode *inode);
175extern void affs_delete_inode(struct inode *inode); 175extern void affs_delete_inode(struct inode *inode);
176extern void affs_clear_inode(struct inode *inode); 176extern void affs_clear_inode(struct inode *inode);
177extern void affs_read_inode(struct inode *inode); 177extern struct inode *affs_iget(struct super_block *sb,
178 unsigned long ino);
178extern int affs_write_inode(struct inode *inode, int); 179extern int affs_write_inode(struct inode *inode, int);
179extern int affs_add_entry(struct inode *dir, struct inode *inode, struct dentry *dentry, s32 type); 180extern int affs_add_entry(struct inode *dir, struct inode *inode, struct dentry *dentry, s32 type);
180 181
diff --git a/fs/affs/amigaffs.c b/fs/affs/amigaffs.c
index f4de4b98004f..805573005de6 100644
--- a/fs/affs/amigaffs.c
+++ b/fs/affs/amigaffs.c
@@ -170,9 +170,11 @@ affs_remove_link(struct dentry *dentry)
170 if (!link_bh) 170 if (!link_bh)
171 goto done; 171 goto done;
172 172
173 dir = iget(sb, be32_to_cpu(AFFS_TAIL(sb, link_bh)->parent)); 173 dir = affs_iget(sb, be32_to_cpu(AFFS_TAIL(sb, link_bh)->parent));
174 if (!dir) 174 if (IS_ERR(dir)) {
175 retval = PTR_ERR(dir);
175 goto done; 176 goto done;
177 }
176 178
177 affs_lock_dir(dir); 179 affs_lock_dir(dir);
178 affs_fix_dcache(dentry, link_ino); 180 affs_fix_dcache(dentry, link_ino);
diff --git a/fs/affs/inode.c b/fs/affs/inode.c
index 4609a6c13fe9..27fe6cbe43ae 100644
--- a/fs/affs/inode.c
+++ b/fs/affs/inode.c
@@ -15,20 +15,25 @@
15extern const struct inode_operations affs_symlink_inode_operations; 15extern const struct inode_operations affs_symlink_inode_operations;
16extern struct timezone sys_tz; 16extern struct timezone sys_tz;
17 17
18void 18struct inode *affs_iget(struct super_block *sb, unsigned long ino)
19affs_read_inode(struct inode *inode)
20{ 19{
21 struct super_block *sb = inode->i_sb;
22 struct affs_sb_info *sbi = AFFS_SB(sb); 20 struct affs_sb_info *sbi = AFFS_SB(sb);
23 struct buffer_head *bh; 21 struct buffer_head *bh;
24 struct affs_head *head; 22 struct affs_head *head;
25 struct affs_tail *tail; 23 struct affs_tail *tail;
24 struct inode *inode;
26 u32 block; 25 u32 block;
27 u32 size; 26 u32 size;
28 u32 prot; 27 u32 prot;
29 u16 id; 28 u16 id;
30 29
31 pr_debug("AFFS: read_inode(%lu)\n",inode->i_ino); 30 inode = iget_locked(sb, ino);
31 if (!inode)
32 return ERR_PTR(-ENOMEM);
33 if (!(inode->i_state & I_NEW))
34 return inode;
35
36 pr_debug("AFFS: affs_iget(%lu)\n", inode->i_ino);
32 37
33 block = inode->i_ino; 38 block = inode->i_ino;
34 bh = affs_bread(sb, block); 39 bh = affs_bread(sb, block);
@@ -154,12 +159,13 @@ affs_read_inode(struct inode *inode)
154 sys_tz.tz_minuteswest * 60; 159 sys_tz.tz_minuteswest * 60;
155 inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = inode->i_atime.tv_nsec = 0; 160 inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = inode->i_atime.tv_nsec = 0;
156 affs_brelse(bh); 161 affs_brelse(bh);
157 return; 162 unlock_new_inode(inode);
163 return inode;
158 164
159bad_inode: 165bad_inode:
160 make_bad_inode(inode);
161 affs_brelse(bh); 166 affs_brelse(bh);
162 return; 167 iget_failed(inode);
168 return ERR_PTR(-EIO);
163} 169}
164 170
165int 171int
diff --git a/fs/affs/namei.c b/fs/affs/namei.c
index a42143ca0169..2218f1ee71ce 100644
--- a/fs/affs/namei.c
+++ b/fs/affs/namei.c
@@ -208,9 +208,8 @@ affs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
208 affs_lock_dir(dir); 208 affs_lock_dir(dir);
209 bh = affs_find_entry(dir, dentry); 209 bh = affs_find_entry(dir, dentry);
210 affs_unlock_dir(dir); 210 affs_unlock_dir(dir);
211 if (IS_ERR(bh)) { 211 if (IS_ERR(bh))
212 return ERR_PTR(PTR_ERR(bh)); 212 return ERR_CAST(bh);
213 }
214 if (bh) { 213 if (bh) {
215 u32 ino = bh->b_blocknr; 214 u32 ino = bh->b_blocknr;
216 215
@@ -223,10 +222,9 @@ affs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
223 ino = be32_to_cpu(AFFS_TAIL(sb, bh)->original); 222 ino = be32_to_cpu(AFFS_TAIL(sb, bh)->original);
224 } 223 }
225 affs_brelse(bh); 224 affs_brelse(bh);
226 inode = iget(sb, ino); 225 inode = affs_iget(sb, ino);
227 if (!inode) { 226 if (IS_ERR(inode))
228 return ERR_PTR(-EACCES); 227 return ERR_PTR(PTR_ERR(inode));
229 }
230 } 228 }
231 dentry->d_op = AFFS_SB(sb)->s_flags & SF_INTL ? &affs_intl_dentry_operations : &affs_dentry_operations; 229 dentry->d_op = AFFS_SB(sb)->s_flags & SF_INTL ? &affs_intl_dentry_operations : &affs_dentry_operations;
232 d_add(dentry, inode); 230 d_add(dentry, inode);
diff --git a/fs/affs/super.c b/fs/affs/super.c
index b53e5d0ec65c..3c45d49c0d26 100644
--- a/fs/affs/super.c
+++ b/fs/affs/super.c
@@ -113,7 +113,6 @@ static void destroy_inodecache(void)
113static const struct super_operations affs_sops = { 113static const struct super_operations affs_sops = {
114 .alloc_inode = affs_alloc_inode, 114 .alloc_inode = affs_alloc_inode,
115 .destroy_inode = affs_destroy_inode, 115 .destroy_inode = affs_destroy_inode,
116 .read_inode = affs_read_inode,
117 .write_inode = affs_write_inode, 116 .write_inode = affs_write_inode,
118 .put_inode = affs_put_inode, 117 .put_inode = affs_put_inode,
119 .drop_inode = affs_drop_inode, 118 .drop_inode = affs_drop_inode,
@@ -271,6 +270,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
271 unsigned long mount_flags; 270 unsigned long mount_flags;
272 int tmp_flags; /* fix remount prototype... */ 271 int tmp_flags; /* fix remount prototype... */
273 u8 sig[4]; 272 u8 sig[4];
273 int ret = -EINVAL;
274 274
275 pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options"); 275 pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options");
276 276
@@ -444,7 +444,12 @@ got_root:
444 444
445 /* set up enough so that it can read an inode */ 445 /* set up enough so that it can read an inode */
446 446
447 root_inode = iget(sb, root_block); 447 root_inode = affs_iget(sb, root_block);
448 if (IS_ERR(root_inode)) {
449 ret = PTR_ERR(root_inode);
450 goto out_error_noinode;
451 }
452
448 sb->s_root = d_alloc_root(root_inode); 453 sb->s_root = d_alloc_root(root_inode);
449 if (!sb->s_root) { 454 if (!sb->s_root) {
450 printk(KERN_ERR "AFFS: Get root inode failed\n"); 455 printk(KERN_ERR "AFFS: Get root inode failed\n");
@@ -461,12 +466,13 @@ got_root:
461out_error: 466out_error:
462 if (root_inode) 467 if (root_inode)
463 iput(root_inode); 468 iput(root_inode);
469out_error_noinode:
464 kfree(sbi->s_bitmap); 470 kfree(sbi->s_bitmap);
465 affs_brelse(root_bh); 471 affs_brelse(root_bh);
466 kfree(sbi->s_prefix); 472 kfree(sbi->s_prefix);
467 kfree(sbi); 473 kfree(sbi);
468 sb->s_fs_info = NULL; 474 sb->s_fs_info = NULL;
469 return -EINVAL; 475 return ret;
470} 476}
471 477
472static int 478static int
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 0cc3597c1197..b58af8f18bc4 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -512,7 +512,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
512 key = afs_request_key(vnode->volume->cell); 512 key = afs_request_key(vnode->volume->cell);
513 if (IS_ERR(key)) { 513 if (IS_ERR(key)) {
514 _leave(" = %ld [key]", PTR_ERR(key)); 514 _leave(" = %ld [key]", PTR_ERR(key));
515 return ERR_PTR(PTR_ERR(key)); 515 return ERR_CAST(key);
516 } 516 }
517 517
518 ret = afs_validate(vnode, key); 518 ret = afs_validate(vnode, key);
@@ -540,7 +540,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
540 key_put(key); 540 key_put(key);
541 if (IS_ERR(inode)) { 541 if (IS_ERR(inode)) {
542 _leave(" = %ld", PTR_ERR(inode)); 542 _leave(" = %ld", PTR_ERR(inode));
543 return ERR_PTR(PTR_ERR(inode)); 543 return ERR_CAST(inode);
544 } 544 }
545 545
546 dentry->d_op = &afs_fs_dentry_operations; 546 dentry->d_op = &afs_fs_dentry_operations;
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index 84750c8e9f95..08db82e1343a 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -196,10 +196,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,
196 196
197 /* failure */ 197 /* failure */
198bad_inode: 198bad_inode:
199 make_bad_inode(inode); 199 iget_failed(inode);
200 unlock_new_inode(inode);
201 iput(inode);
202
203 _leave(" = %d [bad]", ret); 200 _leave(" = %d [bad]", ret);
204 return ERR_PTR(ret); 201 return ERR_PTR(ret);
205} 202}
diff --git a/fs/afs/security.c b/fs/afs/security.c
index 566fe712c682..9446a1fd108a 100644
--- a/fs/afs/security.c
+++ b/fs/afs/security.c
@@ -95,7 +95,7 @@ static struct afs_vnode *afs_get_auth_inode(struct afs_vnode *vnode,
95 auth_inode = afs_iget(vnode->vfs_inode.i_sb, key, 95 auth_inode = afs_iget(vnode->vfs_inode.i_sb, key,
96 &vnode->status.parent, NULL, NULL); 96 &vnode->status.parent, NULL, NULL);
97 if (IS_ERR(auth_inode)) 97 if (IS_ERR(auth_inode))
98 return ERR_PTR(PTR_ERR(auth_inode)); 98 return ERR_CAST(auth_inode);
99 } 99 }
100 100
101 auth_vnode = AFS_FS_I(auth_inode); 101 auth_vnode = AFS_FS_I(auth_inode);
diff --git a/fs/autofs/autofs_i.h b/fs/autofs/autofs_i.h
index 8b4cca3c4705..901a3e67ec45 100644
--- a/fs/autofs/autofs_i.h
+++ b/fs/autofs/autofs_i.h
@@ -150,6 +150,7 @@ extern const struct file_operations autofs_root_operations;
150 150
151int autofs_fill_super(struct super_block *, void *, int); 151int autofs_fill_super(struct super_block *, void *, int);
152void autofs_kill_sb(struct super_block *sb); 152void autofs_kill_sb(struct super_block *sb);
153struct inode *autofs_iget(struct super_block *, unsigned long);
153 154
154/* Queue management functions */ 155/* Queue management functions */
155 156
diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c
index 45f5992a0957..708bdb89fea1 100644
--- a/fs/autofs/inode.c
+++ b/fs/autofs/inode.c
@@ -52,10 +52,7 @@ out_kill_sb:
52 kill_anon_super(sb); 52 kill_anon_super(sb);
53} 53}
54 54
55static void autofs_read_inode(struct inode *inode);
56
57static const struct super_operations autofs_sops = { 55static const struct super_operations autofs_sops = {
58 .read_inode = autofs_read_inode,
59 .statfs = simple_statfs, 56 .statfs = simple_statfs,
60}; 57};
61 58
@@ -164,7 +161,9 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
164 s->s_time_gran = 1; 161 s->s_time_gran = 1;
165 sbi->sb = s; 162 sbi->sb = s;
166 163
167 root_inode = iget(s, AUTOFS_ROOT_INO); 164 root_inode = autofs_iget(s, AUTOFS_ROOT_INO);
165 if (IS_ERR(root_inode))
166 goto fail_free;
168 root = d_alloc_root(root_inode); 167 root = d_alloc_root(root_inode);
169 pipe = NULL; 168 pipe = NULL;
170 169
@@ -230,11 +229,17 @@ fail_unlock:
230 return -EINVAL; 229 return -EINVAL;
231} 230}
232 231
233static void autofs_read_inode(struct inode *inode) 232struct inode *autofs_iget(struct super_block *sb, unsigned long ino)
234{ 233{
235 ino_t ino = inode->i_ino;
236 unsigned int n; 234 unsigned int n;
237 struct autofs_sb_info *sbi = autofs_sbi(inode->i_sb); 235 struct autofs_sb_info *sbi = autofs_sbi(sb);
236 struct inode *inode;
237
238 inode = iget_locked(sb, ino);
239 if (!inode)
240 return ERR_PTR(-ENOMEM);
241 if (!(inode->i_state & I_NEW))
242 return inode;
238 243
239 /* Initialize to the default case (stub directory) */ 244 /* Initialize to the default case (stub directory) */
240 245
@@ -250,7 +255,7 @@ static void autofs_read_inode(struct inode *inode)
250 inode->i_op = &autofs_root_inode_operations; 255 inode->i_op = &autofs_root_inode_operations;
251 inode->i_fop = &autofs_root_operations; 256 inode->i_fop = &autofs_root_operations;
252 inode->i_uid = inode->i_gid = 0; /* Changed in read_super */ 257 inode->i_uid = inode->i_gid = 0; /* Changed in read_super */
253 return; 258 goto done;
254 } 259 }
255 260
256 inode->i_uid = inode->i_sb->s_root->d_inode->i_uid; 261 inode->i_uid = inode->i_sb->s_root->d_inode->i_uid;
@@ -263,7 +268,7 @@ static void autofs_read_inode(struct inode *inode)
263 n = ino - AUTOFS_FIRST_SYMLINK; 268 n = ino - AUTOFS_FIRST_SYMLINK;
264 if (n >= AUTOFS_MAX_SYMLINKS || !test_bit(n,sbi->symlink_bitmap)) { 269 if (n >= AUTOFS_MAX_SYMLINKS || !test_bit(n,sbi->symlink_bitmap)) {
265 printk("autofs: Looking for bad symlink inode %u\n", (unsigned int) ino); 270 printk("autofs: Looking for bad symlink inode %u\n", (unsigned int) ino);
266 return; 271 goto done;
267 } 272 }
268 273
269 inode->i_op = &autofs_symlink_inode_operations; 274 inode->i_op = &autofs_symlink_inode_operations;
@@ -275,4 +280,8 @@ static void autofs_read_inode(struct inode *inode)
275 inode->i_size = sl->len; 280 inode->i_size = sl->len;
276 inode->i_nlink = 1; 281 inode->i_nlink = 1;
277 } 282 }
283
284done:
285 unlock_new_inode(inode);
286 return inode;
278} 287}
diff --git a/fs/autofs/root.c b/fs/autofs/root.c
index 5efff3c0d886..8aacade56956 100644
--- a/fs/autofs/root.c
+++ b/fs/autofs/root.c
@@ -114,8 +114,8 @@ static int try_to_fill_dentry(struct dentry *dentry, struct super_block *sb, str
114 dentry->d_time = (unsigned long) ent; 114 dentry->d_time = (unsigned long) ent;
115 115
116 if (!dentry->d_inode) { 116 if (!dentry->d_inode) {
117 inode = iget(sb, ent->ino); 117 inode = autofs_iget(sb, ent->ino);
118 if (!inode) { 118 if (IS_ERR(inode)) {
119 /* Failed, but leave pending for next time */ 119 /* Failed, but leave pending for next time */
120 return 1; 120 return 1;
121 } 121 }
@@ -274,6 +274,7 @@ static int autofs_root_symlink(struct inode *dir, struct dentry *dentry, const c
274 unsigned int n; 274 unsigned int n;
275 int slsize; 275 int slsize;
276 struct autofs_symlink *sl; 276 struct autofs_symlink *sl;
277 struct inode *inode;
277 278
278 DPRINTK(("autofs_root_symlink: %s <- ", symname)); 279 DPRINTK(("autofs_root_symlink: %s <- ", symname));
279 autofs_say(dentry->d_name.name,dentry->d_name.len); 280 autofs_say(dentry->d_name.name,dentry->d_name.len);
@@ -331,7 +332,12 @@ static int autofs_root_symlink(struct inode *dir, struct dentry *dentry, const c
331 ent->dentry = NULL; /* We don't keep the dentry for symlinks */ 332 ent->dentry = NULL; /* We don't keep the dentry for symlinks */
332 333
333 autofs_hash_insert(dh,ent); 334 autofs_hash_insert(dh,ent);
334 d_instantiate(dentry, iget(dir->i_sb,ent->ino)); 335
336 inode = autofs_iget(dir->i_sb, ent->ino);
337 if (IS_ERR(inode))
338 return PTR_ERR(inode);
339
340 d_instantiate(dentry, inode);
335 unlock_kernel(); 341 unlock_kernel();
336 return 0; 342 return 0;
337} 343}
@@ -428,6 +434,7 @@ static int autofs_root_mkdir(struct inode *dir, struct dentry *dentry, int mode)
428 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb); 434 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
429 struct autofs_dirhash *dh = &sbi->dirhash; 435 struct autofs_dirhash *dh = &sbi->dirhash;
430 struct autofs_dir_ent *ent; 436 struct autofs_dir_ent *ent;
437 struct inode *inode;
431 ino_t ino; 438 ino_t ino;
432 439
433 lock_kernel(); 440 lock_kernel();
@@ -469,7 +476,14 @@ static int autofs_root_mkdir(struct inode *dir, struct dentry *dentry, int mode)
469 autofs_hash_insert(dh,ent); 476 autofs_hash_insert(dh,ent);
470 477
471 inc_nlink(dir); 478 inc_nlink(dir);
472 d_instantiate(dentry, iget(dir->i_sb,ino)); 479
480 inode = autofs_iget(dir->i_sb, ino);
481 if (IS_ERR(inode)) {
482 drop_nlink(dir);
483 return PTR_ERR(inode);
484 }
485
486 d_instantiate(dentry, inode);
473 unlock_kernel(); 487 unlock_kernel();
474 488
475 return 0; 489 return 0;
diff --git a/fs/bad_inode.c b/fs/bad_inode.c
index 521ff7caadbd..f1c2ea8342f5 100644
--- a/fs/bad_inode.c
+++ b/fs/bad_inode.c
@@ -359,3 +359,17 @@ int is_bad_inode(struct inode *inode)
359} 359}
360 360
361EXPORT_SYMBOL(is_bad_inode); 361EXPORT_SYMBOL(is_bad_inode);
362
363/**
364 * iget_failed - Mark an under-construction inode as dead and release it
365 * @inode: The inode to discard
366 *
367 * Mark an under-construction inode as dead and release it.
368 */
369void iget_failed(struct inode *inode)
370{
371 make_bad_inode(inode);
372 unlock_new_inode(inode);
373 iput(inode);
374}
375EXPORT_SYMBOL(iget_failed);
diff --git a/fs/befs/btree.c b/fs/befs/btree.c
index af5bb93276f8..4202db7496cb 100644
--- a/fs/befs/btree.c
+++ b/fs/befs/btree.c
@@ -232,7 +232,7 @@ befs_bt_read_node(struct super_block *sb, befs_data_stream * ds,
232 * @key: Key string to lookup in btree 232 * @key: Key string to lookup in btree
233 * @value: Value stored with @key 233 * @value: Value stored with @key
234 * 234 *
235 * On sucess, returns BEFS_OK and sets *@value to the value stored 235 * On success, returns BEFS_OK and sets *@value to the value stored
236 * with @key (usually the disk block number of an inode). 236 * with @key (usually the disk block number of an inode).
237 * 237 *
238 * On failure, returns BEFS_ERR or BEFS_BT_NOT_FOUND. 238 * On failure, returns BEFS_ERR or BEFS_BT_NOT_FOUND.
diff --git a/fs/befs/datastream.c b/fs/befs/datastream.c
index aacb4da6298a..e3287d0d1a58 100644
--- a/fs/befs/datastream.c
+++ b/fs/befs/datastream.c
@@ -236,7 +236,7 @@ befs_count_blocks(struct super_block * sb, befs_data_stream * ds)
236 as in the indirect region code). 236 as in the indirect region code).
237 237
238 When/if blockno is found, if blockno is inside of a block 238 When/if blockno is found, if blockno is inside of a block
239 run as stored on disk, we offset the start and lenght members 239 run as stored on disk, we offset the start and length members
240 of the block run, so that blockno is the start and len is 240 of the block run, so that blockno is the start and len is
241 still valid (the run ends in the same place). 241 still valid (the run ends in the same place).
242 242
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index b28a20e61b80..403fe661c144 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -35,7 +35,7 @@ static int befs_get_block(struct inode *, sector_t, struct buffer_head *, int);
35static int befs_readpage(struct file *file, struct page *page); 35static int befs_readpage(struct file *file, struct page *page);
36static sector_t befs_bmap(struct address_space *mapping, sector_t block); 36static sector_t befs_bmap(struct address_space *mapping, sector_t block);
37static struct dentry *befs_lookup(struct inode *, struct dentry *, struct nameidata *); 37static struct dentry *befs_lookup(struct inode *, struct dentry *, struct nameidata *);
38static void befs_read_inode(struct inode *ino); 38static struct inode *befs_iget(struct super_block *, unsigned long);
39static struct inode *befs_alloc_inode(struct super_block *sb); 39static struct inode *befs_alloc_inode(struct super_block *sb);
40static void befs_destroy_inode(struct inode *inode); 40static void befs_destroy_inode(struct inode *inode);
41static int befs_init_inodecache(void); 41static int befs_init_inodecache(void);
@@ -52,7 +52,6 @@ static int befs_statfs(struct dentry *, struct kstatfs *);
52static int parse_options(char *, befs_mount_options *); 52static int parse_options(char *, befs_mount_options *);
53 53
54static const struct super_operations befs_sops = { 54static const struct super_operations befs_sops = {
55 .read_inode = befs_read_inode, /* initialize & read inode */
56 .alloc_inode = befs_alloc_inode, /* allocate a new inode */ 55 .alloc_inode = befs_alloc_inode, /* allocate a new inode */
57 .destroy_inode = befs_destroy_inode, /* deallocate an inode */ 56 .destroy_inode = befs_destroy_inode, /* deallocate an inode */
58 .put_super = befs_put_super, /* uninit super */ 57 .put_super = befs_put_super, /* uninit super */
@@ -198,9 +197,9 @@ befs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
198 return ERR_PTR(-ENODATA); 197 return ERR_PTR(-ENODATA);
199 } 198 }
200 199
201 inode = iget(dir->i_sb, (ino_t) offset); 200 inode = befs_iget(dir->i_sb, (ino_t) offset);
202 if (!inode) 201 if (IS_ERR(inode))
203 return ERR_PTR(-EACCES); 202 return ERR_CAST(inode);
204 203
205 d_add(dentry, inode); 204 d_add(dentry, inode);
206 205
@@ -296,17 +295,23 @@ static void init_once(struct kmem_cache *cachep, void *foo)
296 inode_init_once(&bi->vfs_inode); 295 inode_init_once(&bi->vfs_inode);
297} 296}
298 297
299static void 298static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
300befs_read_inode(struct inode *inode)
301{ 299{
302 struct buffer_head *bh = NULL; 300 struct buffer_head *bh = NULL;
303 befs_inode *raw_inode = NULL; 301 befs_inode *raw_inode = NULL;
304 302
305 struct super_block *sb = inode->i_sb;
306 befs_sb_info *befs_sb = BEFS_SB(sb); 303 befs_sb_info *befs_sb = BEFS_SB(sb);
307 befs_inode_info *befs_ino = NULL; 304 befs_inode_info *befs_ino = NULL;
305 struct inode *inode;
306 long ret = -EIO;
308 307
309 befs_debug(sb, "---> befs_read_inode() " "inode = %lu", inode->i_ino); 308 befs_debug(sb, "---> befs_read_inode() " "inode = %lu", ino);
309
310 inode = iget_locked(sb, ino);
311 if (IS_ERR(inode))
312 return inode;
313 if (!(inode->i_state & I_NEW))
314 return inode;
310 315
311 befs_ino = BEFS_I(inode); 316 befs_ino = BEFS_I(inode);
312 317
@@ -402,15 +407,16 @@ befs_read_inode(struct inode *inode)
402 407
403 brelse(bh); 408 brelse(bh);
404 befs_debug(sb, "<--- befs_read_inode()"); 409 befs_debug(sb, "<--- befs_read_inode()");
405 return; 410 unlock_new_inode(inode);
411 return inode;
406 412
407 unacquire_bh: 413 unacquire_bh:
408 brelse(bh); 414 brelse(bh);
409 415
410 unacquire_none: 416 unacquire_none:
411 make_bad_inode(inode); 417 iget_failed(inode);
412 befs_debug(sb, "<--- befs_read_inode() - Bad inode"); 418 befs_debug(sb, "<--- befs_read_inode() - Bad inode");
413 return; 419 return ERR_PTR(ret);
414} 420}
415 421
416/* Initialize the inode cache. Called at fs setup. 422/* Initialize the inode cache. Called at fs setup.
@@ -752,6 +758,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
752 befs_sb_info *befs_sb; 758 befs_sb_info *befs_sb;
753 befs_super_block *disk_sb; 759 befs_super_block *disk_sb;
754 struct inode *root; 760 struct inode *root;
761 long ret = -EINVAL;
755 762
756 const unsigned long sb_block = 0; 763 const unsigned long sb_block = 0;
757 const off_t x86_sb_off = 512; 764 const off_t x86_sb_off = 512;
@@ -833,7 +840,11 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
833 /* Set real blocksize of fs */ 840 /* Set real blocksize of fs */
834 sb_set_blocksize(sb, (ulong) befs_sb->block_size); 841 sb_set_blocksize(sb, (ulong) befs_sb->block_size);
835 sb->s_op = (struct super_operations *) &befs_sops; 842 sb->s_op = (struct super_operations *) &befs_sops;
836 root = iget(sb, iaddr2blockno(sb, &(befs_sb->root_dir))); 843 root = befs_iget(sb, iaddr2blockno(sb, &(befs_sb->root_dir)));
844 if (IS_ERR(root)) {
845 ret = PTR_ERR(root);
846 goto unacquire_priv_sbp;
847 }
837 sb->s_root = d_alloc_root(root); 848 sb->s_root = d_alloc_root(root);
838 if (!sb->s_root) { 849 if (!sb->s_root) {
839 iput(root); 850 iput(root);
@@ -868,7 +879,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
868 879
869 unacquire_none: 880 unacquire_none:
870 sb->s_fs_info = NULL; 881 sb->s_fs_info = NULL;
871 return -EINVAL; 882 return ret;
872} 883}
873 884
874static int 885static int
diff --git a/fs/bfs/bfs.h b/fs/bfs/bfs.h
index ac7a8b1d6c3a..71faf4d23908 100644
--- a/fs/bfs/bfs.h
+++ b/fs/bfs/bfs.h
@@ -44,6 +44,8 @@ static inline struct bfs_inode_info *BFS_I(struct inode *inode)
44#define printf(format, args...) \ 44#define printf(format, args...) \
45 printk(KERN_ERR "BFS-fs: %s(): " format, __FUNCTION__, ## args) 45 printk(KERN_ERR "BFS-fs: %s(): " format, __FUNCTION__, ## args)
46 46
47/* inode.c */
48extern struct inode *bfs_iget(struct super_block *sb, unsigned long ino);
47 49
48/* file.c */ 50/* file.c */
49extern const struct inode_operations bfs_file_inops; 51extern const struct inode_operations bfs_file_inops;
diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c
index 1fd056d0fc3d..034950cb3cbe 100644
--- a/fs/bfs/dir.c
+++ b/fs/bfs/dir.c
@@ -148,10 +148,10 @@ static struct dentry *bfs_lookup(struct inode *dir, struct dentry *dentry,
148 if (bh) { 148 if (bh) {
149 unsigned long ino = (unsigned long)le16_to_cpu(de->ino); 149 unsigned long ino = (unsigned long)le16_to_cpu(de->ino);
150 brelse(bh); 150 brelse(bh);
151 inode = iget(dir->i_sb, ino); 151 inode = bfs_iget(dir->i_sb, ino);
152 if (!inode) { 152 if (IS_ERR(inode)) {
153 unlock_kernel(); 153 unlock_kernel();
154 return ERR_PTR(-EACCES); 154 return ERR_CAST(inode);
155 } 155 }
156 } 156 }
157 unlock_kernel(); 157 unlock_kernel();
diff --git a/fs/bfs/inode.c b/fs/bfs/inode.c
index a64a71d444f5..8db623838b50 100644
--- a/fs/bfs/inode.c
+++ b/fs/bfs/inode.c
@@ -32,17 +32,22 @@ MODULE_LICENSE("GPL");
32 32
33void dump_imap(const char *prefix, struct super_block *s); 33void dump_imap(const char *prefix, struct super_block *s);
34 34
35static void bfs_read_inode(struct inode *inode) 35struct inode *bfs_iget(struct super_block *sb, unsigned long ino)
36{ 36{
37 unsigned long ino = inode->i_ino;
38 struct bfs_inode *di; 37 struct bfs_inode *di;
38 struct inode *inode;
39 struct buffer_head *bh; 39 struct buffer_head *bh;
40 int block, off; 40 int block, off;
41 41
42 inode = iget_locked(sb, ino);
43 if (IS_ERR(inode))
44 return ERR_PTR(-ENOMEM);
45 if (!(inode->i_state & I_NEW))
46 return inode;
47
42 if ((ino < BFS_ROOT_INO) || (ino > BFS_SB(inode->i_sb)->si_lasti)) { 48 if ((ino < BFS_ROOT_INO) || (ino > BFS_SB(inode->i_sb)->si_lasti)) {
43 printf("Bad inode number %s:%08lx\n", inode->i_sb->s_id, ino); 49 printf("Bad inode number %s:%08lx\n", inode->i_sb->s_id, ino);
44 make_bad_inode(inode); 50 goto error;
45 return;
46 } 51 }
47 52
48 block = (ino - BFS_ROOT_INO) / BFS_INODES_PER_BLOCK + 1; 53 block = (ino - BFS_ROOT_INO) / BFS_INODES_PER_BLOCK + 1;
@@ -50,8 +55,7 @@ static void bfs_read_inode(struct inode *inode)
50 if (!bh) { 55 if (!bh) {
51 printf("Unable to read inode %s:%08lx\n", inode->i_sb->s_id, 56 printf("Unable to read inode %s:%08lx\n", inode->i_sb->s_id,
52 ino); 57 ino);
53 make_bad_inode(inode); 58 goto error;
54 return;
55 } 59 }
56 60
57 off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK; 61 off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK;
@@ -85,6 +89,12 @@ static void bfs_read_inode(struct inode *inode)
85 inode->i_ctime.tv_nsec = 0; 89 inode->i_ctime.tv_nsec = 0;
86 90
87 brelse(bh); 91 brelse(bh);
92 unlock_new_inode(inode);
93 return inode;
94
95error:
96 iget_failed(inode);
97 return ERR_PTR(-EIO);
88} 98}
89 99
90static int bfs_write_inode(struct inode *inode, int unused) 100static int bfs_write_inode(struct inode *inode, int unused)
@@ -276,7 +286,6 @@ static void destroy_inodecache(void)
276static const struct super_operations bfs_sops = { 286static const struct super_operations bfs_sops = {
277 .alloc_inode = bfs_alloc_inode, 287 .alloc_inode = bfs_alloc_inode,
278 .destroy_inode = bfs_destroy_inode, 288 .destroy_inode = bfs_destroy_inode,
279 .read_inode = bfs_read_inode,
280 .write_inode = bfs_write_inode, 289 .write_inode = bfs_write_inode,
281 .delete_inode = bfs_delete_inode, 290 .delete_inode = bfs_delete_inode,
282 .put_super = bfs_put_super, 291 .put_super = bfs_put_super,
@@ -312,6 +321,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
312 struct inode *inode; 321 struct inode *inode;
313 unsigned i, imap_len; 322 unsigned i, imap_len;
314 struct bfs_sb_info *info; 323 struct bfs_sb_info *info;
324 long ret = -EINVAL;
315 325
316 info = kzalloc(sizeof(*info), GFP_KERNEL); 326 info = kzalloc(sizeof(*info), GFP_KERNEL);
317 if (!info) 327 if (!info)
@@ -346,14 +356,16 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
346 set_bit(i, info->si_imap); 356 set_bit(i, info->si_imap);
347 357
348 s->s_op = &bfs_sops; 358 s->s_op = &bfs_sops;
349 inode = iget(s, BFS_ROOT_INO); 359 inode = bfs_iget(s, BFS_ROOT_INO);
350 if (!inode) { 360 if (IS_ERR(inode)) {
361 ret = PTR_ERR(inode);
351 kfree(info->si_imap); 362 kfree(info->si_imap);
352 goto out; 363 goto out;
353 } 364 }
354 s->s_root = d_alloc_root(inode); 365 s->s_root = d_alloc_root(inode);
355 if (!s->s_root) { 366 if (!s->s_root) {
356 iput(inode); 367 iput(inode);
368 ret = -ENOMEM;
357 kfree(info->si_imap); 369 kfree(info->si_imap);
358 goto out; 370 goto out;
359 } 371 }
@@ -404,7 +416,7 @@ out:
404 brelse(bh); 416 brelse(bh);
405 kfree(info); 417 kfree(info);
406 s->s_fs_info = NULL; 418 s->s_fs_info = NULL;
407 return -EINVAL; 419 return ret;
408} 420}
409 421
410static int bfs_get_sb(struct file_system_type *fs_type, 422static int bfs_get_sb(struct file_system_type *fs_type,
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 7596e1e94cde..7f65e71bf859 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -115,7 +115,7 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
115 current->flags |= PF_DUMPCORE; 115 current->flags |= PF_DUMPCORE;
116 strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm)); 116 strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm));
117#ifndef __sparc__ 117#ifndef __sparc__
118 dump.u_ar0 = (void *)(((unsigned long)(&dump.regs)) - ((unsigned long)(&dump))); 118 dump.u_ar0 = offsetof(struct user, regs);
119#endif 119#endif
120 dump.signal = signr; 120 dump.signal = signr;
121 dump_thread(regs, &dump); 121 dump_thread(regs, &dump);
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 18ed6dd906c1..111771d38e6e 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -117,7 +117,7 @@ static int padzero(unsigned long elf_bss)
117 return 0; 117 return 0;
118} 118}
119 119
120/* Let's use some macros to make this stack manipulation a litle clearer */ 120/* Let's use some macros to make this stack manipulation a little clearer */
121#ifdef CONFIG_STACK_GROWSUP 121#ifdef CONFIG_STACK_GROWSUP
122#define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) + (items)) 122#define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) + (items))
123#define STACK_ROUND(sp, items) \ 123#define STACK_ROUND(sp, items) \
@@ -1077,7 +1077,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
1077 current->mm->start_stack = bprm->p; 1077 current->mm->start_stack = bprm->p;
1078 1078
1079#ifdef arch_randomize_brk 1079#ifdef arch_randomize_brk
1080 if (current->flags & PF_RANDOMIZE) 1080 if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1))
1081 current->mm->brk = current->mm->start_brk = 1081 current->mm->brk = current->mm->start_brk =
1082 arch_randomize_brk(current->mm); 1082 arch_randomize_brk(current->mm);
1083#endif 1083#endif
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/buffer.c b/fs/buffer.c
index 456c9ab7705b..826baf4f04bc 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1798,7 +1798,7 @@ void page_zero_new_buffers(struct page *page, unsigned from, unsigned to)
1798 start = max(from, block_start); 1798 start = max(from, block_start);
1799 size = min(to, block_end) - start; 1799 size = min(to, block_end) - start;
1800 1800
1801 zero_user_page(page, start, size, KM_USER0); 1801 zero_user(page, start, size);
1802 set_buffer_uptodate(bh); 1802 set_buffer_uptodate(bh);
1803 } 1803 }
1804 1804
@@ -1861,19 +1861,10 @@ static int __block_prepare_write(struct inode *inode, struct page *page,
1861 mark_buffer_dirty(bh); 1861 mark_buffer_dirty(bh);
1862 continue; 1862 continue;
1863 } 1863 }
1864 if (block_end > to || block_start < from) { 1864 if (block_end > to || block_start < from)
1865 void *kaddr; 1865 zero_user_segments(page,
1866 1866 to, block_end,
1867 kaddr = kmap_atomic(page, KM_USER0); 1867 block_start, from);
1868 if (block_end > to)
1869 memset(kaddr+to, 0,
1870 block_end-to);
1871 if (block_start < from)
1872 memset(kaddr+block_start,
1873 0, from-block_start);
1874 flush_dcache_page(page);
1875 kunmap_atomic(kaddr, KM_USER0);
1876 }
1877 continue; 1868 continue;
1878 } 1869 }
1879 } 1870 }
@@ -2104,8 +2095,7 @@ int block_read_full_page(struct page *page, get_block_t *get_block)
2104 SetPageError(page); 2095 SetPageError(page);
2105 } 2096 }
2106 if (!buffer_mapped(bh)) { 2097 if (!buffer_mapped(bh)) {
2107 zero_user_page(page, i * blocksize, blocksize, 2098 zero_user(page, i * blocksize, blocksize);
2108 KM_USER0);
2109 if (!err) 2099 if (!err)
2110 set_buffer_uptodate(bh); 2100 set_buffer_uptodate(bh);
2111 continue; 2101 continue;
@@ -2218,7 +2208,7 @@ int cont_expand_zero(struct file *file, struct address_space *mapping,
2218 &page, &fsdata); 2208 &page, &fsdata);
2219 if (err) 2209 if (err)
2220 goto out; 2210 goto out;
2221 zero_user_page(page, zerofrom, len, KM_USER0); 2211 zero_user(page, zerofrom, len);
2222 err = pagecache_write_end(file, mapping, curpos, len, len, 2212 err = pagecache_write_end(file, mapping, curpos, len, len,
2223 page, fsdata); 2213 page, fsdata);
2224 if (err < 0) 2214 if (err < 0)
@@ -2245,7 +2235,7 @@ int cont_expand_zero(struct file *file, struct address_space *mapping,
2245 &page, &fsdata); 2235 &page, &fsdata);
2246 if (err) 2236 if (err)
2247 goto out; 2237 goto out;
2248 zero_user_page(page, zerofrom, len, KM_USER0); 2238 zero_user(page, zerofrom, len);
2249 err = pagecache_write_end(file, mapping, curpos, len, len, 2239 err = pagecache_write_end(file, mapping, curpos, len, len,
2250 page, fsdata); 2240 page, fsdata);
2251 if (err < 0) 2241 if (err < 0)
@@ -2422,7 +2412,6 @@ int nobh_write_begin(struct file *file, struct address_space *mapping,
2422 unsigned block_in_page; 2412 unsigned block_in_page;
2423 unsigned block_start, block_end; 2413 unsigned block_start, block_end;
2424 sector_t block_in_file; 2414 sector_t block_in_file;
2425 char *kaddr;
2426 int nr_reads = 0; 2415 int nr_reads = 0;
2427 int ret = 0; 2416 int ret = 0;
2428 int is_mapped_to_disk = 1; 2417 int is_mapped_to_disk = 1;
@@ -2493,13 +2482,8 @@ int nobh_write_begin(struct file *file, struct address_space *mapping,
2493 continue; 2482 continue;
2494 } 2483 }
2495 if (buffer_new(bh) || !buffer_mapped(bh)) { 2484 if (buffer_new(bh) || !buffer_mapped(bh)) {
2496 kaddr = kmap_atomic(page, KM_USER0); 2485 zero_user_segments(page, block_start, from,
2497 if (block_start < from) 2486 to, block_end);
2498 memset(kaddr+block_start, 0, from-block_start);
2499 if (block_end > to)
2500 memset(kaddr + to, 0, block_end - to);
2501 flush_dcache_page(page);
2502 kunmap_atomic(kaddr, KM_USER0);
2503 continue; 2487 continue;
2504 } 2488 }
2505 if (buffer_uptodate(bh)) 2489 if (buffer_uptodate(bh))
@@ -2636,7 +2620,7 @@ int nobh_writepage(struct page *page, get_block_t *get_block,
2636 * the page size, the remaining memory is zeroed when mapped, and 2620 * the page size, the remaining memory is zeroed when mapped, and
2637 * writes to that region are not written out to the file." 2621 * writes to that region are not written out to the file."
2638 */ 2622 */
2639 zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0); 2623 zero_user_segment(page, offset, PAGE_CACHE_SIZE);
2640out: 2624out:
2641 ret = mpage_writepage(page, get_block, wbc); 2625 ret = mpage_writepage(page, get_block, wbc);
2642 if (ret == -EAGAIN) 2626 if (ret == -EAGAIN)
@@ -2709,7 +2693,7 @@ has_buffers:
2709 if (page_has_buffers(page)) 2693 if (page_has_buffers(page))
2710 goto has_buffers; 2694 goto has_buffers;
2711 } 2695 }
2712 zero_user_page(page, offset, length, KM_USER0); 2696 zero_user(page, offset, length);
2713 set_page_dirty(page); 2697 set_page_dirty(page);
2714 err = 0; 2698 err = 0;
2715 2699
@@ -2785,7 +2769,7 @@ int block_truncate_page(struct address_space *mapping,
2785 goto unlock; 2769 goto unlock;
2786 } 2770 }
2787 2771
2788 zero_user_page(page, offset, length, KM_USER0); 2772 zero_user(page, offset, length);
2789 mark_buffer_dirty(bh); 2773 mark_buffer_dirty(bh);
2790 err = 0; 2774 err = 0;
2791 2775
@@ -2831,7 +2815,7 @@ int block_write_full_page(struct page *page, get_block_t *get_block,
2831 * the page size, the remaining memory is zeroed when mapped, and 2815 * the page size, the remaining memory is zeroed when mapped, and
2832 * writes to that region are not written out to the file." 2816 * writes to that region are not written out to the file."
2833 */ 2817 */
2834 zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0); 2818 zero_user_segment(page, offset, PAGE_CACHE_SIZE);
2835 return __block_write_full_page(inode, page, get_block, wbc); 2819 return __block_write_full_page(inode, page, get_block, wbc);
2836} 2820}
2837 2821
@@ -3169,7 +3153,7 @@ static void recalc_bh_state(void)
3169 3153
3170struct buffer_head *alloc_buffer_head(gfp_t gfp_flags) 3154struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
3171{ 3155{
3172 struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, 3156 struct buffer_head *ret = kmem_cache_alloc(bh_cachep,
3173 set_migrateflags(gfp_flags, __GFP_RECLAIMABLE)); 3157 set_migrateflags(gfp_flags, __GFP_RECLAIMABLE));
3174 if (ret) { 3158 if (ret) {
3175 INIT_LIST_HEAD(&ret->b_assoc_buffers); 3159 INIT_LIST_HEAD(&ret->b_assoc_buffers);
@@ -3257,12 +3241,24 @@ int bh_submit_read(struct buffer_head *bh)
3257} 3241}
3258EXPORT_SYMBOL(bh_submit_read); 3242EXPORT_SYMBOL(bh_submit_read);
3259 3243
3244static void
3245init_buffer_head(struct kmem_cache *cachep, void *data)
3246{
3247 struct buffer_head *bh = data;
3248
3249 memset(bh, 0, sizeof(*bh));
3250 INIT_LIST_HEAD(&bh->b_assoc_buffers);
3251}
3252
3260void __init buffer_init(void) 3253void __init buffer_init(void)
3261{ 3254{
3262 int nrpages; 3255 int nrpages;
3263 3256
3264 bh_cachep = KMEM_CACHE(buffer_head, 3257 bh_cachep = kmem_cache_create("buffer_head",
3265 SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD); 3258 sizeof(struct buffer_head), 0,
3259 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
3260 SLAB_MEM_SPREAD),
3261 init_buffer_head);
3266 3262
3267 /* 3263 /*
3268 * Limit the bh occupancy to 10% of ZONE_NORMAL 3264 * Limit the bh occupancy to 10% of ZONE_NORMAL
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index e9f4ec701092..fcc434227691 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -147,10 +147,11 @@ cifs_read_super(struct super_block *sb, void *data,
147#endif 147#endif
148 sb->s_blocksize = CIFS_MAX_MSGSIZE; 148 sb->s_blocksize = CIFS_MAX_MSGSIZE;
149 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */ 149 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
150 inode = iget(sb, ROOT_I); 150 inode = cifs_iget(sb, ROOT_I);
151 151
152 if (!inode) { 152 if (IS_ERR(inode)) {
153 rc = -ENOMEM; 153 rc = PTR_ERR(inode);
154 inode = NULL;
154 goto out_no_root; 155 goto out_no_root;
155 } 156 }
156 157
@@ -520,7 +521,6 @@ static int cifs_remount(struct super_block *sb, int *flags, char *data)
520} 521}
521 522
522static const struct super_operations cifs_super_ops = { 523static const struct super_operations cifs_super_ops = {
523 .read_inode = cifs_read_inode,
524 .put_super = cifs_put_super, 524 .put_super = cifs_put_super,
525 .statfs = cifs_statfs, 525 .statfs = cifs_statfs,
526 .alloc_inode = cifs_alloc_inode, 526 .alloc_inode = cifs_alloc_inode,
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index 195b14de5567..68978306c3ca 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -44,6 +44,7 @@ extern void cifs_read_inode(struct inode *);
44 44
45/* Functions related to inodes */ 45/* Functions related to inodes */
46extern const struct inode_operations cifs_dir_inode_ops; 46extern const struct inode_operations cifs_dir_inode_ops;
47extern struct inode *cifs_iget(struct super_block *, unsigned long);
47extern int cifs_create(struct inode *, struct dentry *, int, 48extern int cifs_create(struct inode *, struct dentry *, int,
48 struct nameidata *); 49 struct nameidata *);
49extern struct dentry *cifs_lookup(struct inode *, struct dentry *, 50extern struct dentry *cifs_lookup(struct inode *, struct dentry *,
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index d9567ba2960b..b1a4a65eaa08 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -586,10 +586,18 @@ static const struct inode_operations cifs_ipc_inode_ops = {
586}; 586};
587 587
588/* gets root inode */ 588/* gets root inode */
589void cifs_read_inode(struct inode *inode) 589struct inode *cifs_iget(struct super_block *sb, unsigned long ino)
590{ 590{
591 int xid, rc; 591 int xid;
592 struct cifs_sb_info *cifs_sb; 592 struct cifs_sb_info *cifs_sb;
593 struct inode *inode;
594 long rc;
595
596 inode = iget_locked(sb, ino);
597 if (!inode)
598 return ERR_PTR(-ENOMEM);
599 if (!(inode->i_state & I_NEW))
600 return inode;
593 601
594 cifs_sb = CIFS_SB(inode->i_sb); 602 cifs_sb = CIFS_SB(inode->i_sb);
595 xid = GetXid(); 603 xid = GetXid();
@@ -606,10 +614,18 @@ void cifs_read_inode(struct inode *inode)
606 inode->i_fop = &simple_dir_operations; 614 inode->i_fop = &simple_dir_operations;
607 inode->i_uid = cifs_sb->mnt_uid; 615 inode->i_uid = cifs_sb->mnt_uid;
608 inode->i_gid = cifs_sb->mnt_gid; 616 inode->i_gid = cifs_sb->mnt_gid;
617 _FreeXid(xid);
618 iget_failed(inode);
619 return ERR_PTR(rc);
609 } 620 }
610 621
611 /* can not call macro FreeXid here since in a void func */ 622 unlock_new_inode(inode);
623
624 /* can not call macro FreeXid here since in a void func
625 * TODO: This is no longer true
626 */
612 _FreeXid(xid); 627 _FreeXid(xid);
628 return inode;
613} 629}
614 630
615int cifs_unlink(struct inode *inode, struct dentry *direntry) 631int cifs_unlink(struct inode *inode, struct dentry *direntry)
@@ -1386,7 +1402,7 @@ static int cifs_truncate_page(struct address_space *mapping, loff_t from)
1386 if (!page) 1402 if (!page)
1387 return -ENOMEM; 1403 return -ENOMEM;
1388 1404
1389 zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0); 1405 zero_user_segment(page, offset, PAGE_CACHE_SIZE);
1390 unlock_page(page); 1406 unlock_page(page);
1391 page_cache_release(page); 1407 page_cache_release(page);
1392 return rc; 1408 return rc;
diff --git a/fs/compat.c b/fs/compat.c
index 5216c3fd7517..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.
@@ -2206,19 +2157,41 @@ asmlinkage long compat_sys_signalfd(int ufd,
2206 2157
2207#ifdef CONFIG_TIMERFD 2158#ifdef CONFIG_TIMERFD
2208 2159
2209asmlinkage long compat_sys_timerfd(int ufd, int clockid, int flags, 2160asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
2210 const struct compat_itimerspec __user *utmr) 2161 const struct compat_itimerspec __user *utmr,
2162 struct compat_itimerspec __user *otmr)
2211{ 2163{
2164 int error;
2212 struct itimerspec t; 2165 struct itimerspec t;
2213 struct itimerspec __user *ut; 2166 struct itimerspec __user *ut;
2214 2167
2215 if (get_compat_itimerspec(&t, utmr)) 2168 if (get_compat_itimerspec(&t, utmr))
2216 return -EFAULT; 2169 return -EFAULT;
2217 ut = compat_alloc_user_space(sizeof(*ut)); 2170 ut = compat_alloc_user_space(2 * sizeof(struct itimerspec));
2218 if (copy_to_user(ut, &t, sizeof(t))) 2171 if (copy_to_user(&ut[0], &t, sizeof(t)))
2219 return -EFAULT; 2172 return -EFAULT;
2173 error = sys_timerfd_settime(ufd, flags, &ut[0], &ut[1]);
2174 if (!error && otmr)
2175 error = (copy_from_user(&t, &ut[1], sizeof(struct itimerspec)) ||
2176 put_compat_itimerspec(otmr, &t)) ? -EFAULT: 0;
2177
2178 return error;
2179}
2180
2181asmlinkage long compat_sys_timerfd_gettime(int ufd,
2182 struct compat_itimerspec __user *otmr)
2183{
2184 int error;
2185 struct itimerspec t;
2186 struct itimerspec __user *ut;
2220 2187
2221 return sys_timerfd(ufd, clockid, flags, ut); 2188 ut = compat_alloc_user_space(sizeof(struct itimerspec));
2189 error = sys_timerfd_gettime(ufd, ut);
2190 if (!error)
2191 error = (copy_from_user(&t, ut, sizeof(struct itimerspec)) ||
2192 put_compat_itimerspec(otmr, &t)) ? -EFAULT: 0;
2193
2194 return error;
2222} 2195}
2223 2196
2224#endif /* CONFIG_TIMERFD */ 2197#endif /* CONFIG_TIMERFD */
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index ffdc022cae64..614bd75b5a4a 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -2986,7 +2986,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
2986 } 2986 }
2987 2987
2988 do_ioctl: 2988 do_ioctl:
2989 error = vfs_ioctl(filp, fd, cmd, arg); 2989 error = do_vfs_ioctl(filp, fd, cmd, arg);
2990 out_fput: 2990 out_fput:
2991 fput_light(filp, fput_needed); 2991 fput_light(filp, fput_needed);
2992 out: 2992 out:
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/direct-io.c b/fs/direct-io.c
index acf0da1bd257..9e81addbd6ea 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -878,8 +878,8 @@ do_holes:
878 page_cache_release(page); 878 page_cache_release(page);
879 goto out; 879 goto out;
880 } 880 }
881 zero_user_page(page, block_in_page << blkbits, 881 zero_user(page, block_in_page << blkbits,
882 1 << blkbits, KM_USER0); 882 1 << blkbits);
883 dio->block_in_file++; 883 dio->block_in_file++;
884 block_in_page++; 884 block_in_page++;
885 goto next_block; 885 goto next_block;
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 32c5711d79a3..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),
@@ -257,8 +258,7 @@ static int fill_zeros_to_end_of_page(struct page *page, unsigned int to)
257 end_byte_in_page = i_size_read(inode) % PAGE_CACHE_SIZE; 258 end_byte_in_page = i_size_read(inode) % PAGE_CACHE_SIZE;
258 if (to > end_byte_in_page) 259 if (to > end_byte_in_page)
259 end_byte_in_page = to; 260 end_byte_in_page = to;
260 zero_user_page(page, end_byte_in_page, 261 zero_user_segment(page, end_byte_in_page, PAGE_CACHE_SIZE);
261 PAGE_CACHE_SIZE - end_byte_in_page, KM_USER0);
262out: 262out:
263 return 0; 263 return 0;
264} 264}
@@ -307,7 +307,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
307 */ 307 */
308 if ((i_size_read(page->mapping->host) == prev_page_end_size) && 308 if ((i_size_read(page->mapping->host) == prev_page_end_size) &&
309 (from != 0)) { 309 (from != 0)) {
310 zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0); 310 zero_user(page, 0, PAGE_CACHE_SIZE);
311 } 311 }
312out: 312out:
313 return rc; 313 return rc;
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/efs/inode.c b/fs/efs/inode.c
index 174696f9bf14..627c3026946d 100644
--- a/fs/efs/inode.c
+++ b/fs/efs/inode.c
@@ -45,17 +45,26 @@ static inline void extent_copy(efs_extent *src, efs_extent *dst) {
45 return; 45 return;
46} 46}
47 47
48void efs_read_inode(struct inode *inode) 48struct inode *efs_iget(struct super_block *super, unsigned long ino)
49{ 49{
50 int i, inode_index; 50 int i, inode_index;
51 dev_t device; 51 dev_t device;
52 u32 rdev; 52 u32 rdev;
53 struct buffer_head *bh; 53 struct buffer_head *bh;
54 struct efs_sb_info *sb = SUPER_INFO(inode->i_sb); 54 struct efs_sb_info *sb = SUPER_INFO(super);
55 struct efs_inode_info *in = INODE_INFO(inode); 55 struct efs_inode_info *in;
56 efs_block_t block, offset; 56 efs_block_t block, offset;
57 struct efs_dinode *efs_inode; 57 struct efs_dinode *efs_inode;
58 58 struct inode *inode;
59
60 inode = iget_locked(super, ino);
61 if (IS_ERR(inode))
62 return ERR_PTR(-ENOMEM);
63 if (!(inode->i_state & I_NEW))
64 return inode;
65
66 in = INODE_INFO(inode);
67
59 /* 68 /*
60 ** EFS layout: 69 ** EFS layout:
61 ** 70 **
@@ -159,13 +168,13 @@ void efs_read_inode(struct inode *inode)
159 break; 168 break;
160 } 169 }
161 170
162 return; 171 unlock_new_inode(inode);
172 return inode;
163 173
164read_inode_error: 174read_inode_error:
165 printk(KERN_WARNING "EFS: failed to read inode %lu\n", inode->i_ino); 175 printk(KERN_WARNING "EFS: failed to read inode %lu\n", inode->i_ino);
166 make_bad_inode(inode); 176 iget_failed(inode);
167 177 return ERR_PTR(-EIO);
168 return;
169} 178}
170 179
171static inline efs_block_t 180static inline efs_block_t
diff --git a/fs/efs/namei.c b/fs/efs/namei.c
index f7f407075be1..e26704742d41 100644
--- a/fs/efs/namei.c
+++ b/fs/efs/namei.c
@@ -66,9 +66,10 @@ struct dentry *efs_lookup(struct inode *dir, struct dentry *dentry, struct namei
66 lock_kernel(); 66 lock_kernel();
67 inodenum = efs_find_entry(dir, dentry->d_name.name, dentry->d_name.len); 67 inodenum = efs_find_entry(dir, dentry->d_name.name, dentry->d_name.len);
68 if (inodenum) { 68 if (inodenum) {
69 if (!(inode = iget(dir->i_sb, inodenum))) { 69 inode = efs_iget(dir->i_sb, inodenum);
70 if (IS_ERR(inode)) {
70 unlock_kernel(); 71 unlock_kernel();
71 return ERR_PTR(-EACCES); 72 return ERR_CAST(inode);
72 } 73 }
73 } 74 }
74 unlock_kernel(); 75 unlock_kernel();
@@ -84,12 +85,11 @@ static struct inode *efs_nfs_get_inode(struct super_block *sb, u64 ino,
84 85
85 if (ino == 0) 86 if (ino == 0)
86 return ERR_PTR(-ESTALE); 87 return ERR_PTR(-ESTALE);
87 inode = iget(sb, ino); 88 inode = efs_iget(sb, ino);
88 if (inode == NULL) 89 if (IS_ERR(inode))
89 return ERR_PTR(-ENOMEM); 90 return ERR_CAST(inode);
90 91
91 if (is_bad_inode(inode) || 92 if (generation && inode->i_generation != generation) {
92 (generation && inode->i_generation != generation)) {
93 iput(inode); 93 iput(inode);
94 return ERR_PTR(-ESTALE); 94 return ERR_PTR(-ESTALE);
95 } 95 }
@@ -116,7 +116,7 @@ struct dentry *efs_get_parent(struct dentry *child)
116 struct dentry *parent; 116 struct dentry *parent;
117 struct inode *inode; 117 struct inode *inode;
118 efs_ino_t ino; 118 efs_ino_t ino;
119 int error; 119 long error;
120 120
121 lock_kernel(); 121 lock_kernel();
122 122
@@ -125,10 +125,11 @@ struct dentry *efs_get_parent(struct dentry *child)
125 if (!ino) 125 if (!ino)
126 goto fail; 126 goto fail;
127 127
128 error = -EACCES; 128 inode = efs_iget(child->d_inode->i_sb, ino);
129 inode = iget(child->d_inode->i_sb, ino); 129 if (IS_ERR(inode)) {
130 if (!inode) 130 error = PTR_ERR(inode);
131 goto fail; 131 goto fail;
132 }
132 133
133 error = -ENOMEM; 134 error = -ENOMEM;
134 parent = d_alloc_anon(inode); 135 parent = d_alloc_anon(inode);
diff --git a/fs/efs/super.c b/fs/efs/super.c
index c79bc627f107..14082405cdd1 100644
--- a/fs/efs/super.c
+++ b/fs/efs/super.c
@@ -107,7 +107,6 @@ static int efs_remount(struct super_block *sb, int *flags, char *data)
107static const struct super_operations efs_superblock_operations = { 107static const struct super_operations efs_superblock_operations = {
108 .alloc_inode = efs_alloc_inode, 108 .alloc_inode = efs_alloc_inode,
109 .destroy_inode = efs_destroy_inode, 109 .destroy_inode = efs_destroy_inode,
110 .read_inode = efs_read_inode,
111 .put_super = efs_put_super, 110 .put_super = efs_put_super,
112 .statfs = efs_statfs, 111 .statfs = efs_statfs,
113 .remount_fs = efs_remount, 112 .remount_fs = efs_remount,
@@ -247,6 +246,7 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
247 struct efs_sb_info *sb; 246 struct efs_sb_info *sb;
248 struct buffer_head *bh; 247 struct buffer_head *bh;
249 struct inode *root; 248 struct inode *root;
249 int ret = -EINVAL;
250 250
251 sb = kzalloc(sizeof(struct efs_sb_info), GFP_KERNEL); 251 sb = kzalloc(sizeof(struct efs_sb_info), GFP_KERNEL);
252 if (!sb) 252 if (!sb)
@@ -303,12 +303,18 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
303 } 303 }
304 s->s_op = &efs_superblock_operations; 304 s->s_op = &efs_superblock_operations;
305 s->s_export_op = &efs_export_ops; 305 s->s_export_op = &efs_export_ops;
306 root = iget(s, EFS_ROOTINODE); 306 root = efs_iget(s, EFS_ROOTINODE);
307 if (IS_ERR(root)) {
308 printk(KERN_ERR "EFS: get root inode failed\n");
309 ret = PTR_ERR(root);
310 goto out_no_fs;
311 }
312
307 s->s_root = d_alloc_root(root); 313 s->s_root = d_alloc_root(root);
308
309 if (!(s->s_root)) { 314 if (!(s->s_root)) {
310 printk(KERN_ERR "EFS: get root inode failed\n"); 315 printk(KERN_ERR "EFS: get root dentry failed\n");
311 iput(root); 316 iput(root);
317 ret = -ENOMEM;
312 goto out_no_fs; 318 goto out_no_fs;
313 } 319 }
314 320
@@ -318,7 +324,7 @@ out_no_fs_ul:
318out_no_fs: 324out_no_fs:
319 s->s_fs_info = NULL; 325 s->s_fs_info = NULL;
320 kfree(sb); 326 kfree(sb);
321 return -EINVAL; 327 return ret;
322} 328}
323 329
324static int efs_statfs(struct dentry *dentry, struct kstatfs *buf) { 330static int efs_statfs(struct dentry *dentry, struct kstatfs *buf) {
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/eventpoll.c b/fs/eventpoll.c
index 81c04abfb1aa..a415f42d32cf 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -353,7 +353,7 @@ static void ep_poll_safewake(struct poll_safewake *psw, wait_queue_head_t *wq)
353 spin_unlock_irqrestore(&psw->lock, flags); 353 spin_unlock_irqrestore(&psw->lock, flags);
354 354
355 /* Do really wake up now */ 355 /* Do really wake up now */
356 wake_up(wq); 356 wake_up_nested(wq, 1 + wake_nests);
357 357
358 /* Remove the current task from the list */ 358 /* Remove the current task from the list */
359 spin_lock_irqsave(&psw->lock, flags); 359 spin_lock_irqsave(&psw->lock, flags);
diff --git a/fs/exec.c b/fs/exec.c
index 282240afe99e..be923e4bc389 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -760,7 +760,7 @@ static int de_thread(struct task_struct *tsk)
760 */ 760 */
761 read_lock(&tasklist_lock); 761 read_lock(&tasklist_lock);
762 spin_lock_irq(lock); 762 spin_lock_irq(lock);
763 if (sig->flags & SIGNAL_GROUP_EXIT) { 763 if (signal_group_exit(sig)) {
764 /* 764 /*
765 * Another group action in progress, just 765 * Another group action in progress, just
766 * return so that the signal is processed. 766 * return so that the signal is processed.
@@ -778,6 +778,7 @@ static int de_thread(struct task_struct *tsk)
778 if (unlikely(tsk->group_leader == task_child_reaper(tsk))) 778 if (unlikely(tsk->group_leader == task_child_reaper(tsk)))
779 task_active_pid_ns(tsk)->child_reaper = tsk; 779 task_active_pid_ns(tsk)->child_reaper = tsk;
780 780
781 sig->group_exit_task = tsk;
781 zap_other_threads(tsk); 782 zap_other_threads(tsk);
782 read_unlock(&tasklist_lock); 783 read_unlock(&tasklist_lock);
783 784
@@ -802,7 +803,6 @@ static int de_thread(struct task_struct *tsk)
802 } 803 }
803 804
804 sig->notify_count = count; 805 sig->notify_count = count;
805 sig->group_exit_task = tsk;
806 while (atomic_read(&sig->count) > count) { 806 while (atomic_read(&sig->count) > count) {
807 __set_current_state(TASK_UNINTERRUPTIBLE); 807 __set_current_state(TASK_UNINTERRUPTIBLE);
808 spin_unlock_irq(lock); 808 spin_unlock_irq(lock);
@@ -871,15 +871,10 @@ static int de_thread(struct task_struct *tsk)
871 leader->exit_state = EXIT_DEAD; 871 leader->exit_state = EXIT_DEAD;
872 872
873 write_unlock_irq(&tasklist_lock); 873 write_unlock_irq(&tasklist_lock);
874 } 874 }
875 875
876 sig->group_exit_task = NULL; 876 sig->group_exit_task = NULL;
877 sig->notify_count = 0; 877 sig->notify_count = 0;
878 /*
879 * There may be one thread left which is just exiting,
880 * but it's safe to stop telling the group to kill themselves.
881 */
882 sig->flags = 0;
883 878
884no_thread_group: 879no_thread_group:
885 exit_itimers(sig); 880 exit_itimers(sig);
@@ -947,12 +942,13 @@ static void flush_old_files(struct files_struct * files)
947 spin_unlock(&files->file_lock); 942 spin_unlock(&files->file_lock);
948} 943}
949 944
950void get_task_comm(char *buf, struct task_struct *tsk) 945char *get_task_comm(char *buf, struct task_struct *tsk)
951{ 946{
952 /* buf must be at least sizeof(tsk->comm) in size */ 947 /* buf must be at least sizeof(tsk->comm) in size */
953 task_lock(tsk); 948 task_lock(tsk);
954 strncpy(buf, tsk->comm, sizeof(tsk->comm)); 949 strncpy(buf, tsk->comm, sizeof(tsk->comm));
955 task_unlock(tsk); 950 task_unlock(tsk);
951 return buf;
956} 952}
957 953
958void set_task_comm(struct task_struct *tsk, char *buf) 954void set_task_comm(struct task_struct *tsk, char *buf)
@@ -1548,7 +1544,7 @@ static inline int zap_threads(struct task_struct *tsk, struct mm_struct *mm,
1548 int err = -EAGAIN; 1544 int err = -EAGAIN;
1549 1545
1550 spin_lock_irq(&tsk->sighand->siglock); 1546 spin_lock_irq(&tsk->sighand->siglock);
1551 if (!(tsk->signal->flags & SIGNAL_GROUP_EXIT)) { 1547 if (!signal_group_exit(tsk->signal)) {
1552 tsk->signal->group_exit_code = exit_code; 1548 tsk->signal->group_exit_code = exit_code;
1553 zap_process(tsk); 1549 zap_process(tsk);
1554 err = 0; 1550 err = 0;
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..f1e5705e75f1 100644
--- a/fs/ext2/ext2.h
+++ b/fs/ext2/ext2.h
@@ -124,7 +124,7 @@ extern void ext2_check_inodes_bitmap (struct super_block *);
124extern unsigned long ext2_count_free (struct buffer_head *, unsigned); 124extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
125 125
126/* inode.c */ 126/* inode.c */
127extern void ext2_read_inode (struct inode *); 127extern struct inode *ext2_iget (struct super_block *, unsigned long);
128extern int ext2_write_inode (struct inode *, int); 128extern int ext2_write_inode (struct inode *, int);
129extern void ext2_put_inode (struct inode *); 129extern void ext2_put_inode (struct inode *);
130extern void ext2_delete_inode (struct inode *); 130extern void ext2_delete_inode (struct inode *);
@@ -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..c62006805427 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;
@@ -1185,22 +1181,33 @@ void ext2_get_inode_flags(struct ext2_inode_info *ei)
1185 ei->i_flags |= EXT2_DIRSYNC_FL; 1181 ei->i_flags |= EXT2_DIRSYNC_FL;
1186} 1182}
1187 1183
1188void ext2_read_inode (struct inode * inode) 1184struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
1189{ 1185{
1190 struct ext2_inode_info *ei = EXT2_I(inode); 1186 struct ext2_inode_info *ei;
1191 ino_t ino = inode->i_ino;
1192 struct buffer_head * bh; 1187 struct buffer_head * bh;
1193 struct ext2_inode * raw_inode = ext2_get_inode(inode->i_sb, ino, &bh); 1188 struct ext2_inode *raw_inode;
1189 struct inode *inode;
1190 long ret = -EIO;
1194 int n; 1191 int n;
1195 1192
1193 inode = iget_locked(sb, ino);
1194 if (!inode)
1195 return ERR_PTR(-ENOMEM);
1196 if (!(inode->i_state & I_NEW))
1197 return inode;
1198
1199 ei = EXT2_I(inode);
1196#ifdef CONFIG_EXT2_FS_POSIX_ACL 1200#ifdef CONFIG_EXT2_FS_POSIX_ACL
1197 ei->i_acl = EXT2_ACL_NOT_CACHED; 1201 ei->i_acl = EXT2_ACL_NOT_CACHED;
1198 ei->i_default_acl = EXT2_ACL_NOT_CACHED; 1202 ei->i_default_acl = EXT2_ACL_NOT_CACHED;
1199#endif 1203#endif
1200 ei->i_block_alloc_info = NULL; 1204 ei->i_block_alloc_info = NULL;
1201 1205
1202 if (IS_ERR(raw_inode)) 1206 raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);
1207 if (IS_ERR(raw_inode)) {
1208 ret = PTR_ERR(raw_inode);
1203 goto bad_inode; 1209 goto bad_inode;
1210 }
1204 1211
1205 inode->i_mode = le16_to_cpu(raw_inode->i_mode); 1212 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
1206 inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low); 1213 inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
@@ -1224,6 +1231,7 @@ void ext2_read_inode (struct inode * inode)
1224 if (inode->i_nlink == 0 && (inode->i_mode == 0 || ei->i_dtime)) { 1231 if (inode->i_nlink == 0 && (inode->i_mode == 0 || ei->i_dtime)) {
1225 /* this inode is deleted */ 1232 /* this inode is deleted */
1226 brelse (bh); 1233 brelse (bh);
1234 ret = -ESTALE;
1227 goto bad_inode; 1235 goto bad_inode;
1228 } 1236 }
1229 inode->i_blocks = le32_to_cpu(raw_inode->i_blocks); 1237 inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
@@ -1290,11 +1298,12 @@ void ext2_read_inode (struct inode * inode)
1290 } 1298 }
1291 brelse (bh); 1299 brelse (bh);
1292 ext2_set_inode_flags(inode); 1300 ext2_set_inode_flags(inode);
1293 return; 1301 unlock_new_inode(inode);
1302 return inode;
1294 1303
1295bad_inode: 1304bad_inode:
1296 make_bad_inode(inode); 1305 iget_failed(inode);
1297 return; 1306 return ERR_PTR(ret);
1298} 1307}
1299 1308
1300static int ext2_update_inode(struct inode * inode, int do_sync) 1309static int ext2_update_inode(struct inode * inode, int do_sync)
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/namei.c b/fs/ext2/namei.c
index e69beed839ac..80c97fd8c571 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -63,9 +63,9 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, str
63 ino = ext2_inode_by_name(dir, dentry); 63 ino = ext2_inode_by_name(dir, dentry);
64 inode = NULL; 64 inode = NULL;
65 if (ino) { 65 if (ino) {
66 inode = iget(dir->i_sb, ino); 66 inode = ext2_iget(dir->i_sb, ino);
67 if (!inode) 67 if (IS_ERR(inode))
68 return ERR_PTR(-EACCES); 68 return ERR_CAST(inode);
69 } 69 }
70 return d_splice_alias(inode, dentry); 70 return d_splice_alias(inode, dentry);
71} 71}
@@ -83,10 +83,10 @@ struct dentry *ext2_get_parent(struct dentry *child)
83 ino = ext2_inode_by_name(child->d_inode, &dotdot); 83 ino = ext2_inode_by_name(child->d_inode, &dotdot);
84 if (!ino) 84 if (!ino)
85 return ERR_PTR(-ENOENT); 85 return ERR_PTR(-ENOENT);
86 inode = iget(child->d_inode->i_sb, ino); 86 inode = ext2_iget(child->d_inode->i_sb, ino);
87 87
88 if (!inode) 88 if (IS_ERR(inode))
89 return ERR_PTR(-EACCES); 89 return ERR_CAST(inode);
90 parent = d_alloc_anon(inode); 90 parent = d_alloc_anon(inode);
91 if (!parent) { 91 if (!parent) {
92 iput(inode); 92 iput(inode);
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 6abaf75163f0..22f1010bf79f 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))
@@ -296,7 +296,6 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type, const char *da
296static const struct super_operations ext2_sops = { 296static const struct super_operations ext2_sops = {
297 .alloc_inode = ext2_alloc_inode, 297 .alloc_inode = ext2_alloc_inode,
298 .destroy_inode = ext2_destroy_inode, 298 .destroy_inode = ext2_destroy_inode,
299 .read_inode = ext2_read_inode,
300 .write_inode = ext2_write_inode, 299 .write_inode = ext2_write_inode,
301 .delete_inode = ext2_delete_inode, 300 .delete_inode = ext2_delete_inode,
302 .put_super = ext2_put_super, 301 .put_super = ext2_put_super,
@@ -326,11 +325,10 @@ static struct inode *ext2_nfs_get_inode(struct super_block *sb,
326 * it might be "neater" to call ext2_get_inode first and check 325 * it might be "neater" to call ext2_get_inode first and check
327 * if the inode is valid..... 326 * if the inode is valid.....
328 */ 327 */
329 inode = iget(sb, ino); 328 inode = ext2_iget(sb, ino);
330 if (inode == NULL) 329 if (IS_ERR(inode))
331 return ERR_PTR(-ENOMEM); 330 return ERR_CAST(inode);
332 if (is_bad_inode(inode) || 331 if (generation && inode->i_generation != generation) {
333 (generation && inode->i_generation != generation)) {
334 /* we didn't find the right inode.. */ 332 /* we didn't find the right inode.. */
335 iput(inode); 333 iput(inode);
336 return ERR_PTR(-ESTALE); 334 return ERR_PTR(-ESTALE);
@@ -617,27 +615,24 @@ static int ext2_setup_super (struct super_block * sb,
617 return res; 615 return res;
618} 616}
619 617
620static int ext2_check_descriptors (struct super_block * sb) 618static int ext2_check_descriptors(struct super_block *sb)
621{ 619{
622 int i; 620 int i;
623 int desc_block = 0;
624 struct ext2_sb_info *sbi = EXT2_SB(sb); 621 struct ext2_sb_info *sbi = EXT2_SB(sb);
625 unsigned long first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 622 unsigned long first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
626 unsigned long last_block; 623 unsigned long last_block;
627 struct ext2_group_desc * gdp = NULL;
628 624
629 ext2_debug ("Checking group descriptors"); 625 ext2_debug ("Checking group descriptors");
630 626
631 for (i = 0; i < sbi->s_groups_count; i++) 627 for (i = 0; i < sbi->s_groups_count; i++) {
632 { 628 struct ext2_group_desc *gdp = ext2_get_group_desc(sb, i, NULL);
629
633 if (i == sbi->s_groups_count - 1) 630 if (i == sbi->s_groups_count - 1)
634 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1; 631 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
635 else 632 else
636 last_block = first_block + 633 last_block = first_block +
637 (EXT2_BLOCKS_PER_GROUP(sb) - 1); 634 (EXT2_BLOCKS_PER_GROUP(sb) - 1);
638 635
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 || 636 if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
642 le32_to_cpu(gdp->bg_block_bitmap) > last_block) 637 le32_to_cpu(gdp->bg_block_bitmap) > last_block)
643 { 638 {
@@ -667,7 +662,6 @@ static int ext2_check_descriptors (struct super_block * sb)
667 return 0; 662 return 0;
668 } 663 }
669 first_block += EXT2_BLOCKS_PER_GROUP(sb); 664 first_block += EXT2_BLOCKS_PER_GROUP(sb);
670 gdp++;
671 } 665 }
672 return 1; 666 return 1;
673} 667}
@@ -750,6 +744,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
750 unsigned long logic_sb_block; 744 unsigned long logic_sb_block;
751 unsigned long offset = 0; 745 unsigned long offset = 0;
752 unsigned long def_mount_opts; 746 unsigned long def_mount_opts;
747 long ret = -EINVAL;
753 int blocksize = BLOCK_SIZE; 748 int blocksize = BLOCK_SIZE;
754 int db_count; 749 int db_count;
755 int i, j; 750 int i, j;
@@ -820,10 +815,10 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
820 815
821 if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC) 816 if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC)
822 set_opt(sbi->s_mount_opt, ERRORS_PANIC); 817 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
823 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_RO) 818 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); 819 set_opt(sbi->s_mount_opt, ERRORS_CONT);
820 else
821 set_opt(sbi->s_mount_opt, ERRORS_RO);
827 822
828 sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 823 sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
829 sbi->s_resgid = le16_to_cpu(es->s_def_resgid); 824 sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
@@ -868,8 +863,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
868 863
869 blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size); 864 blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
870 865
871 if ((ext2_use_xip(sb)) && ((blocksize != PAGE_SIZE) || 866 if (ext2_use_xip(sb) && blocksize != PAGE_SIZE) {
872 (sb->s_blocksize != blocksize))) {
873 if (!silent) 867 if (!silent)
874 printk("XIP: Unsupported blocksize\n"); 868 printk("XIP: Unsupported blocksize\n");
875 goto failed_mount; 869 goto failed_mount;
@@ -1046,19 +1040,24 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
1046 sb->s_op = &ext2_sops; 1040 sb->s_op = &ext2_sops;
1047 sb->s_export_op = &ext2_export_ops; 1041 sb->s_export_op = &ext2_export_ops;
1048 sb->s_xattr = ext2_xattr_handlers; 1042 sb->s_xattr = ext2_xattr_handlers;
1049 root = iget(sb, EXT2_ROOT_INO); 1043 root = ext2_iget(sb, EXT2_ROOT_INO);
1050 sb->s_root = d_alloc_root(root); 1044 if (IS_ERR(root)) {
1051 if (!sb->s_root) { 1045 ret = PTR_ERR(root);
1052 iput(root);
1053 printk(KERN_ERR "EXT2-fs: get root inode failed\n");
1054 goto failed_mount3; 1046 goto failed_mount3;
1055 } 1047 }
1056 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { 1048 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
1057 dput(sb->s_root); 1049 iput(root);
1058 sb->s_root = NULL;
1059 printk(KERN_ERR "EXT2-fs: corrupt root inode, run e2fsck\n"); 1050 printk(KERN_ERR "EXT2-fs: corrupt root inode, run e2fsck\n");
1060 goto failed_mount3; 1051 goto failed_mount3;
1061 } 1052 }
1053
1054 sb->s_root = d_alloc_root(root);
1055 if (!sb->s_root) {
1056 iput(root);
1057 printk(KERN_ERR "EXT2-fs: get root inode failed\n");
1058 ret = -ENOMEM;
1059 goto failed_mount3;
1060 }
1062 if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) 1061 if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL))
1063 ext2_warning(sb, __FUNCTION__, 1062 ext2_warning(sb, __FUNCTION__,
1064 "mounting ext3 filesystem as ext2"); 1063 "mounting ext3 filesystem as ext2");
@@ -1085,7 +1084,7 @@ failed_mount:
1085failed_sbi: 1084failed_sbi:
1086 sb->s_fs_info = NULL; 1085 sb->s_fs_info = NULL;
1087 kfree(sbi); 1086 kfree(sbi);
1088 return -EINVAL; 1087 return ret;
1089} 1088}
1090 1089
1091static void ext2_commit_super (struct super_block * sb, 1090static void ext2_commit_super (struct super_block * sb,
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/ialloc.c b/fs/ext3/ialloc.c
index 1bc8cd89c51d..58ae2f943f12 100644
--- a/fs/ext3/ialloc.c
+++ b/fs/ext3/ialloc.c
@@ -642,14 +642,15 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
642 unsigned long max_ino = le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count); 642 unsigned long max_ino = le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count);
643 unsigned long block_group; 643 unsigned long block_group;
644 int bit; 644 int bit;
645 struct buffer_head *bitmap_bh = NULL; 645 struct buffer_head *bitmap_bh;
646 struct inode *inode = NULL; 646 struct inode *inode = NULL;
647 long err = -EIO;
647 648
648 /* Error cases - e2fsck has already cleaned up for us */ 649 /* Error cases - e2fsck has already cleaned up for us */
649 if (ino > max_ino) { 650 if (ino > max_ino) {
650 ext3_warning(sb, __FUNCTION__, 651 ext3_warning(sb, __FUNCTION__,
651 "bad orphan ino %lu! e2fsck was run?", ino); 652 "bad orphan ino %lu! e2fsck was run?", ino);
652 goto out; 653 goto error;
653 } 654 }
654 655
655 block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); 656 block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb);
@@ -658,38 +659,49 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
658 if (!bitmap_bh) { 659 if (!bitmap_bh) {
659 ext3_warning(sb, __FUNCTION__, 660 ext3_warning(sb, __FUNCTION__,
660 "inode bitmap error for orphan %lu", ino); 661 "inode bitmap error for orphan %lu", ino);
661 goto out; 662 goto error;
662 } 663 }
663 664
664 /* Having the inode bit set should be a 100% indicator that this 665 /* Having the inode bit set should be a 100% indicator that this
665 * is a valid orphan (no e2fsck run on fs). Orphans also include 666 * is a valid orphan (no e2fsck run on fs). Orphans also include
666 * inodes that were being truncated, so we can't check i_nlink==0. 667 * inodes that were being truncated, so we can't check i_nlink==0.
667 */ 668 */
668 if (!ext3_test_bit(bit, bitmap_bh->b_data) || 669 if (!ext3_test_bit(bit, bitmap_bh->b_data))
669 !(inode = iget(sb, ino)) || is_bad_inode(inode) || 670 goto bad_orphan;
670 NEXT_ORPHAN(inode) > max_ino) { 671
671 ext3_warning(sb, __FUNCTION__, 672 inode = ext3_iget(sb, ino);
672 "bad orphan inode %lu! e2fsck was run?", ino); 673 if (IS_ERR(inode))
673 printk(KERN_NOTICE "ext3_test_bit(bit=%d, block=%llu) = %d\n", 674 goto iget_failed;
674 bit, (unsigned long long)bitmap_bh->b_blocknr, 675
675 ext3_test_bit(bit, bitmap_bh->b_data)); 676 if (NEXT_ORPHAN(inode) > max_ino)
676 printk(KERN_NOTICE "inode=%p\n", inode); 677 goto bad_orphan;
677 if (inode) { 678 brelse(bitmap_bh);
678 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n", 679 return inode;
679 is_bad_inode(inode)); 680
680 printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n", 681iget_failed:
681 NEXT_ORPHAN(inode)); 682 err = PTR_ERR(inode);
682 printk(KERN_NOTICE "max_ino=%lu\n", max_ino); 683 inode = NULL;
683 } 684bad_orphan:
685 ext3_warning(sb, __FUNCTION__,
686 "bad orphan inode %lu! e2fsck was run?", ino);
687 printk(KERN_NOTICE "ext3_test_bit(bit=%d, block=%llu) = %d\n",
688 bit, (unsigned long long)bitmap_bh->b_blocknr,
689 ext3_test_bit(bit, bitmap_bh->b_data));
690 printk(KERN_NOTICE "inode=%p\n", inode);
691 if (inode) {
692 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n",
693 is_bad_inode(inode));
694 printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n",
695 NEXT_ORPHAN(inode));
696 printk(KERN_NOTICE "max_ino=%lu\n", max_ino);
684 /* Avoid freeing blocks if we got a bad deleted inode */ 697 /* Avoid freeing blocks if we got a bad deleted inode */
685 if (inode && inode->i_nlink == 0) 698 if (inode->i_nlink == 0)
686 inode->i_blocks = 0; 699 inode->i_blocks = 0;
687 iput(inode); 700 iput(inode);
688 inode = NULL;
689 } 701 }
690out:
691 brelse(bitmap_bh); 702 brelse(bitmap_bh);
692 return inode; 703error:
704 return ERR_PTR(err);
693} 705}
694 706
695unsigned long ext3_count_free_inodes (struct super_block * sb) 707unsigned long ext3_count_free_inodes (struct super_block * sb)
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 9b162cd6c16c..eb95670a27eb 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;
@@ -1845,7 +1841,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
1845 */ 1841 */
1846 if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) && 1842 if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) &&
1847 ext3_should_writeback_data(inode) && PageUptodate(page)) { 1843 ext3_should_writeback_data(inode) && PageUptodate(page)) {
1848 zero_user_page(page, offset, length, KM_USER0); 1844 zero_user(page, offset, length);
1849 set_page_dirty(page); 1845 set_page_dirty(page);
1850 goto unlock; 1846 goto unlock;
1851 } 1847 }
@@ -1898,7 +1894,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
1898 goto unlock; 1894 goto unlock;
1899 } 1895 }
1900 1896
1901 zero_user_page(page, offset, length, KM_USER0); 1897 zero_user(page, offset, length);
1902 BUFFER_TRACE(bh, "zeroed end of block"); 1898 BUFFER_TRACE(bh, "zeroed end of block");
1903 1899
1904 err = 0; 1900 err = 0;
@@ -2658,21 +2654,31 @@ void ext3_get_inode_flags(struct ext3_inode_info *ei)
2658 ei->i_flags |= EXT3_DIRSYNC_FL; 2654 ei->i_flags |= EXT3_DIRSYNC_FL;
2659} 2655}
2660 2656
2661void ext3_read_inode(struct inode * inode) 2657struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2662{ 2658{
2663 struct ext3_iloc iloc; 2659 struct ext3_iloc iloc;
2664 struct ext3_inode *raw_inode; 2660 struct ext3_inode *raw_inode;
2665 struct ext3_inode_info *ei = EXT3_I(inode); 2661 struct ext3_inode_info *ei;
2666 struct buffer_head *bh; 2662 struct buffer_head *bh;
2663 struct inode *inode;
2664 long ret;
2667 int block; 2665 int block;
2668 2666
2667 inode = iget_locked(sb, ino);
2668 if (!inode)
2669 return ERR_PTR(-ENOMEM);
2670 if (!(inode->i_state & I_NEW))
2671 return inode;
2672
2673 ei = EXT3_I(inode);
2669#ifdef CONFIG_EXT3_FS_POSIX_ACL 2674#ifdef CONFIG_EXT3_FS_POSIX_ACL
2670 ei->i_acl = EXT3_ACL_NOT_CACHED; 2675 ei->i_acl = EXT3_ACL_NOT_CACHED;
2671 ei->i_default_acl = EXT3_ACL_NOT_CACHED; 2676 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
2672#endif 2677#endif
2673 ei->i_block_alloc_info = NULL; 2678 ei->i_block_alloc_info = NULL;
2674 2679
2675 if (__ext3_get_inode_loc(inode, &iloc, 0)) 2680 ret = __ext3_get_inode_loc(inode, &iloc, 0);
2681 if (ret < 0)
2676 goto bad_inode; 2682 goto bad_inode;
2677 bh = iloc.bh; 2683 bh = iloc.bh;
2678 raw_inode = ext3_raw_inode(&iloc); 2684 raw_inode = ext3_raw_inode(&iloc);
@@ -2703,6 +2709,7 @@ void ext3_read_inode(struct inode * inode)
2703 !(EXT3_SB(inode->i_sb)->s_mount_state & EXT3_ORPHAN_FS)) { 2709 !(EXT3_SB(inode->i_sb)->s_mount_state & EXT3_ORPHAN_FS)) {
2704 /* this inode is deleted */ 2710 /* this inode is deleted */
2705 brelse (bh); 2711 brelse (bh);
2712 ret = -ESTALE;
2706 goto bad_inode; 2713 goto bad_inode;
2707 } 2714 }
2708 /* The only unlinked inodes we let through here have 2715 /* The only unlinked inodes we let through here have
@@ -2746,6 +2753,7 @@ void ext3_read_inode(struct inode * inode)
2746 if (EXT3_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > 2753 if (EXT3_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
2747 EXT3_INODE_SIZE(inode->i_sb)) { 2754 EXT3_INODE_SIZE(inode->i_sb)) {
2748 brelse (bh); 2755 brelse (bh);
2756 ret = -EIO;
2749 goto bad_inode; 2757 goto bad_inode;
2750 } 2758 }
2751 if (ei->i_extra_isize == 0) { 2759 if (ei->i_extra_isize == 0) {
@@ -2787,11 +2795,12 @@ void ext3_read_inode(struct inode * inode)
2787 } 2795 }
2788 brelse (iloc.bh); 2796 brelse (iloc.bh);
2789 ext3_set_inode_flags(inode); 2797 ext3_set_inode_flags(inode);
2790 return; 2798 unlock_new_inode(inode);
2799 return inode;
2791 2800
2792bad_inode: 2801bad_inode:
2793 make_bad_inode(inode); 2802 iget_failed(inode);
2794 return; 2803 return ERR_PTR(ret);
2795} 2804}
2796 2805
2797/* 2806/*
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 4ab6f76e63d0..dec3e0d88ab1 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)) {
@@ -1041,17 +1037,11 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str
1041 if (!ext3_valid_inum(dir->i_sb, ino)) { 1037 if (!ext3_valid_inum(dir->i_sb, ino)) {
1042 ext3_error(dir->i_sb, "ext3_lookup", 1038 ext3_error(dir->i_sb, "ext3_lookup",
1043 "bad inode number: %lu", ino); 1039 "bad inode number: %lu", ino);
1044 inode = NULL; 1040 return ERR_PTR(-EIO);
1045 } else
1046 inode = iget(dir->i_sb, ino);
1047
1048 if (!inode)
1049 return ERR_PTR(-EACCES);
1050
1051 if (is_bad_inode(inode)) {
1052 iput(inode);
1053 return ERR_PTR(-ENOENT);
1054 } 1041 }
1042 inode = ext3_iget(dir->i_sb, ino);
1043 if (IS_ERR(inode))
1044 return ERR_CAST(inode);
1055 } 1045 }
1056 return d_splice_alias(inode, dentry); 1046 return d_splice_alias(inode, dentry);
1057} 1047}
@@ -1080,18 +1070,13 @@ struct dentry *ext3_get_parent(struct dentry *child)
1080 if (!ext3_valid_inum(child->d_inode->i_sb, ino)) { 1070 if (!ext3_valid_inum(child->d_inode->i_sb, ino)) {
1081 ext3_error(child->d_inode->i_sb, "ext3_get_parent", 1071 ext3_error(child->d_inode->i_sb, "ext3_get_parent",
1082 "bad inode number: %lu", ino); 1072 "bad inode number: %lu", ino);
1083 inode = NULL; 1073 return ERR_PTR(-EIO);
1084 } else
1085 inode = iget(child->d_inode->i_sb, ino);
1086
1087 if (!inode)
1088 return ERR_PTR(-EACCES);
1089
1090 if (is_bad_inode(inode)) {
1091 iput(inode);
1092 return ERR_PTR(-ENOENT);
1093 } 1074 }
1094 1075
1076 inode = ext3_iget(child->d_inode->i_sb, ino);
1077 if (IS_ERR(inode))
1078 return ERR_CAST(inode);
1079
1095 parent = d_alloc_anon(inode); 1080 parent = d_alloc_anon(inode);
1096 if (!parent) { 1081 if (!parent) {
1097 iput(inode); 1082 iput(inode);
diff --git a/fs/ext3/resize.c b/fs/ext3/resize.c
index 44de1453c301..ebc05af7343a 100644
--- a/fs/ext3/resize.c
+++ b/fs/ext3/resize.c
@@ -795,12 +795,11 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
795 "No reserved GDT blocks, can't resize"); 795 "No reserved GDT blocks, can't resize");
796 return -EPERM; 796 return -EPERM;
797 } 797 }
798 inode = iget(sb, EXT3_RESIZE_INO); 798 inode = ext3_iget(sb, EXT3_RESIZE_INO);
799 if (!inode || is_bad_inode(inode)) { 799 if (IS_ERR(inode)) {
800 ext3_warning(sb, __FUNCTION__, 800 ext3_warning(sb, __FUNCTION__,
801 "Error opening resize inode"); 801 "Error opening resize inode");
802 iput(inode); 802 return PTR_ERR(inode);
803 return -ENOENT;
804 } 803 }
805 } 804 }
806 805
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index f3675cc630e9..cf2a2c3660ec 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))
@@ -649,11 +649,10 @@ static struct inode *ext3_nfs_get_inode(struct super_block *sb,
649 * Currently we don't know the generation for parent directory, so 649 * Currently we don't know the generation for parent directory, so
650 * a generation of 0 means "accept any" 650 * a generation of 0 means "accept any"
651 */ 651 */
652 inode = iget(sb, ino); 652 inode = ext3_iget(sb, ino);
653 if (inode == NULL) 653 if (IS_ERR(inode))
654 return ERR_PTR(-ENOMEM); 654 return ERR_CAST(inode);
655 if (is_bad_inode(inode) || 655 if (generation && inode->i_generation != generation) {
656 (generation && inode->i_generation != generation)) {
657 iput(inode); 656 iput(inode);
658 return ERR_PTR(-ESTALE); 657 return ERR_PTR(-ESTALE);
659 } 658 }
@@ -722,7 +721,6 @@ static struct quotactl_ops ext3_qctl_operations = {
722static const struct super_operations ext3_sops = { 721static const struct super_operations ext3_sops = {
723 .alloc_inode = ext3_alloc_inode, 722 .alloc_inode = ext3_alloc_inode,
724 .destroy_inode = ext3_destroy_inode, 723 .destroy_inode = ext3_destroy_inode,
725 .read_inode = ext3_read_inode,
726 .write_inode = ext3_write_inode, 724 .write_inode = ext3_write_inode,
727 .dirty_inode = ext3_dirty_inode, 725 .dirty_inode = ext3_dirty_inode,
728 .delete_inode = ext3_delete_inode, 726 .delete_inode = ext3_delete_inode,
@@ -1252,28 +1250,24 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es,
1252} 1250}
1253 1251
1254/* Called at mount-time, super-block is locked */ 1252/* Called at mount-time, super-block is locked */
1255static int ext3_check_descriptors (struct super_block * sb) 1253static int ext3_check_descriptors(struct super_block *sb)
1256{ 1254{
1257 struct ext3_sb_info *sbi = EXT3_SB(sb); 1255 struct ext3_sb_info *sbi = EXT3_SB(sb);
1258 ext3_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 1256 ext3_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
1259 ext3_fsblk_t last_block; 1257 ext3_fsblk_t last_block;
1260 struct ext3_group_desc * gdp = NULL;
1261 int desc_block = 0;
1262 int i; 1258 int i;
1263 1259
1264 ext3_debug ("Checking group descriptors"); 1260 ext3_debug ("Checking group descriptors");
1265 1261
1266 for (i = 0; i < sbi->s_groups_count; i++) 1262 for (i = 0; i < sbi->s_groups_count; i++) {
1267 { 1263 struct ext3_group_desc *gdp = ext3_get_group_desc(sb, i, NULL);
1264
1268 if (i == sbi->s_groups_count - 1) 1265 if (i == sbi->s_groups_count - 1)
1269 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1; 1266 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
1270 else 1267 else
1271 last_block = first_block + 1268 last_block = first_block +
1272 (EXT3_BLOCKS_PER_GROUP(sb) - 1); 1269 (EXT3_BLOCKS_PER_GROUP(sb) - 1);
1273 1270
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 || 1271 if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
1278 le32_to_cpu(gdp->bg_block_bitmap) > last_block) 1272 le32_to_cpu(gdp->bg_block_bitmap) > last_block)
1279 { 1273 {
@@ -1306,7 +1300,6 @@ static int ext3_check_descriptors (struct super_block * sb)
1306 return 0; 1300 return 0;
1307 } 1301 }
1308 first_block += EXT3_BLOCKS_PER_GROUP(sb); 1302 first_block += EXT3_BLOCKS_PER_GROUP(sb);
1309 gdp++;
1310 } 1303 }
1311 1304
1312 sbi->s_es->s_free_blocks_count=cpu_to_le32(ext3_count_free_blocks(sb)); 1305 sbi->s_es->s_free_blocks_count=cpu_to_le32(ext3_count_free_blocks(sb));
@@ -1383,8 +1376,8 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1383 while (es->s_last_orphan) { 1376 while (es->s_last_orphan) {
1384 struct inode *inode; 1377 struct inode *inode;
1385 1378
1386 if (!(inode = 1379 inode = ext3_orphan_get(sb, le32_to_cpu(es->s_last_orphan));
1387 ext3_orphan_get(sb, le32_to_cpu(es->s_last_orphan)))) { 1380 if (IS_ERR(inode)) {
1388 es->s_last_orphan = 0; 1381 es->s_last_orphan = 0;
1389 break; 1382 break;
1390 } 1383 }
@@ -1513,6 +1506,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1513 int db_count; 1506 int db_count;
1514 int i; 1507 int i;
1515 int needs_recovery; 1508 int needs_recovery;
1509 int ret = -EINVAL;
1516 __le32 features; 1510 __le32 features;
1517 int err; 1511 int err;
1518 1512
@@ -1583,10 +1577,10 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1583 1577
1584 if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC) 1578 if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC)
1585 set_opt(sbi->s_mount_opt, ERRORS_PANIC); 1579 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
1586 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_RO) 1580 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); 1581 set_opt(sbi->s_mount_opt, ERRORS_CONT);
1582 else
1583 set_opt(sbi->s_mount_opt, ERRORS_RO);
1590 1584
1591 sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 1585 sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
1592 sbi->s_resgid = le16_to_cpu(es->s_def_resgid); 1586 sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
@@ -1882,19 +1876,24 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1882 * so we can safely mount the rest of the filesystem now. 1876 * so we can safely mount the rest of the filesystem now.
1883 */ 1877 */
1884 1878
1885 root = iget(sb, EXT3_ROOT_INO); 1879 root = ext3_iget(sb, EXT3_ROOT_INO);
1886 sb->s_root = d_alloc_root(root); 1880 if (IS_ERR(root)) {
1887 if (!sb->s_root) {
1888 printk(KERN_ERR "EXT3-fs: get root inode failed\n"); 1881 printk(KERN_ERR "EXT3-fs: get root inode failed\n");
1889 iput(root); 1882 ret = PTR_ERR(root);
1890 goto failed_mount4; 1883 goto failed_mount4;
1891 } 1884 }
1892 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { 1885 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
1893 dput(sb->s_root); 1886 iput(root);
1894 sb->s_root = NULL;
1895 printk(KERN_ERR "EXT3-fs: corrupt root inode, run e2fsck\n"); 1887 printk(KERN_ERR "EXT3-fs: corrupt root inode, run e2fsck\n");
1896 goto failed_mount4; 1888 goto failed_mount4;
1897 } 1889 }
1890 sb->s_root = d_alloc_root(root);
1891 if (!sb->s_root) {
1892 printk(KERN_ERR "EXT3-fs: get root dentry failed\n");
1893 iput(root);
1894 ret = -ENOMEM;
1895 goto failed_mount4;
1896 }
1898 1897
1899 ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY); 1898 ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY);
1900 /* 1899 /*
@@ -1946,7 +1945,7 @@ out_fail:
1946 sb->s_fs_info = NULL; 1945 sb->s_fs_info = NULL;
1947 kfree(sbi); 1946 kfree(sbi);
1948 lock_kernel(); 1947 lock_kernel();
1949 return -EINVAL; 1948 return ret;
1950} 1949}
1951 1950
1952/* 1951/*
@@ -1982,8 +1981,8 @@ static journal_t *ext3_get_journal(struct super_block *sb,
1982 * things happen if we iget() an unused inode, as the subsequent 1981 * things happen if we iget() an unused inode, as the subsequent
1983 * iput() will try to delete it. */ 1982 * iput() will try to delete it. */
1984 1983
1985 journal_inode = iget(sb, journal_inum); 1984 journal_inode = ext3_iget(sb, journal_inum);
1986 if (!journal_inode) { 1985 if (IS_ERR(journal_inode)) {
1987 printk(KERN_ERR "EXT3-fs: no journal found.\n"); 1986 printk(KERN_ERR "EXT3-fs: no journal found.\n");
1988 return NULL; 1987 return NULL;
1989 } 1988 }
@@ -1996,7 +1995,7 @@ static journal_t *ext3_get_journal(struct super_block *sb,
1996 1995
1997 jbd_debug(2, "Journal inode found at %p: %Ld bytes\n", 1996 jbd_debug(2, "Journal inode found at %p: %Ld bytes\n",
1998 journal_inode, journal_inode->i_size); 1997 journal_inode, journal_inode->i_size);
1999 if (is_bad_inode(journal_inode) || !S_ISREG(journal_inode->i_mode)) { 1998 if (!S_ISREG(journal_inode->i_mode)) {
2000 printk(KERN_ERR "EXT3-fs: invalid journal inode.\n"); 1999 printk(KERN_ERR "EXT3-fs: invalid journal inode.\n");
2001 iput(journal_inode); 2000 iput(journal_inode);
2002 return NULL; 2001 return NULL;
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/ialloc.c b/fs/ext4/ialloc.c
index 575b5215c808..da18a74b966a 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -782,14 +782,15 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
782 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count); 782 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
783 ext4_group_t block_group; 783 ext4_group_t block_group;
784 int bit; 784 int bit;
785 struct buffer_head *bitmap_bh = NULL; 785 struct buffer_head *bitmap_bh;
786 struct inode *inode = NULL; 786 struct inode *inode = NULL;
787 long err = -EIO;
787 788
788 /* Error cases - e2fsck has already cleaned up for us */ 789 /* Error cases - e2fsck has already cleaned up for us */
789 if (ino > max_ino) { 790 if (ino > max_ino) {
790 ext4_warning(sb, __FUNCTION__, 791 ext4_warning(sb, __FUNCTION__,
791 "bad orphan ino %lu! e2fsck was run?", ino); 792 "bad orphan ino %lu! e2fsck was run?", ino);
792 goto out; 793 goto error;
793 } 794 }
794 795
795 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); 796 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
@@ -798,38 +799,49 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
798 if (!bitmap_bh) { 799 if (!bitmap_bh) {
799 ext4_warning(sb, __FUNCTION__, 800 ext4_warning(sb, __FUNCTION__,
800 "inode bitmap error for orphan %lu", ino); 801 "inode bitmap error for orphan %lu", ino);
801 goto out; 802 goto error;
802 } 803 }
803 804
804 /* Having the inode bit set should be a 100% indicator that this 805 /* Having the inode bit set should be a 100% indicator that this
805 * is a valid orphan (no e2fsck run on fs). Orphans also include 806 * is a valid orphan (no e2fsck run on fs). Orphans also include
806 * inodes that were being truncated, so we can't check i_nlink==0. 807 * inodes that were being truncated, so we can't check i_nlink==0.
807 */ 808 */
808 if (!ext4_test_bit(bit, bitmap_bh->b_data) || 809 if (!ext4_test_bit(bit, bitmap_bh->b_data))
809 !(inode = iget(sb, ino)) || is_bad_inode(inode) || 810 goto bad_orphan;
810 NEXT_ORPHAN(inode) > max_ino) { 811
811 ext4_warning(sb, __FUNCTION__, 812 inode = ext4_iget(sb, ino);
812 "bad orphan inode %lu! e2fsck was run?", ino); 813 if (IS_ERR(inode))
813 printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n", 814 goto iget_failed;
814 bit, (unsigned long long)bitmap_bh->b_blocknr, 815
815 ext4_test_bit(bit, bitmap_bh->b_data)); 816 if (NEXT_ORPHAN(inode) > max_ino)
816 printk(KERN_NOTICE "inode=%p\n", inode); 817 goto bad_orphan;
817 if (inode) { 818 brelse(bitmap_bh);
818 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n", 819 return inode;
819 is_bad_inode(inode)); 820
820 printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n", 821iget_failed:
821 NEXT_ORPHAN(inode)); 822 err = PTR_ERR(inode);
822 printk(KERN_NOTICE "max_ino=%lu\n", max_ino); 823 inode = NULL;
823 } 824bad_orphan:
825 ext4_warning(sb, __FUNCTION__,
826 "bad orphan inode %lu! e2fsck was run?", ino);
827 printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
828 bit, (unsigned long long)bitmap_bh->b_blocknr,
829 ext4_test_bit(bit, bitmap_bh->b_data));
830 printk(KERN_NOTICE "inode=%p\n", inode);
831 if (inode) {
832 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n",
833 is_bad_inode(inode));
834 printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n",
835 NEXT_ORPHAN(inode));
836 printk(KERN_NOTICE "max_ino=%lu\n", max_ino);
824 /* Avoid freeing blocks if we got a bad deleted inode */ 837 /* Avoid freeing blocks if we got a bad deleted inode */
825 if (inode && inode->i_nlink == 0) 838 if (inode->i_nlink == 0)
826 inode->i_blocks = 0; 839 inode->i_blocks = 0;
827 iput(inode); 840 iput(inode);
828 inode = NULL;
829 } 841 }
830out:
831 brelse(bitmap_bh); 842 brelse(bitmap_bh);
832 return inode; 843error:
844 return ERR_PTR(err);
833} 845}
834 846
835unsigned long ext4_count_free_inodes (struct super_block * sb) 847unsigned long ext4_count_free_inodes (struct super_block * sb)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index bb717cbb749c..f4e387452246 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;
@@ -1840,7 +1837,7 @@ int ext4_block_truncate_page(handle_t *handle, struct page *page,
1840 */ 1837 */
1841 if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) && 1838 if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) &&
1842 ext4_should_writeback_data(inode) && PageUptodate(page)) { 1839 ext4_should_writeback_data(inode) && PageUptodate(page)) {
1843 zero_user_page(page, offset, length, KM_USER0); 1840 zero_user(page, offset, length);
1844 set_page_dirty(page); 1841 set_page_dirty(page);
1845 goto unlock; 1842 goto unlock;
1846 } 1843 }
@@ -1893,7 +1890,7 @@ int ext4_block_truncate_page(handle_t *handle, struct page *page,
1893 goto unlock; 1890 goto unlock;
1894 } 1891 }
1895 1892
1896 zero_user_page(page, offset, length, KM_USER0); 1893 zero_user(page, offset, length);
1897 1894
1898 BUFFER_TRACE(bh, "zeroed end of block"); 1895 BUFFER_TRACE(bh, "zeroed end of block");
1899 1896
@@ -2683,21 +2680,31 @@ static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
2683 } 2680 }
2684} 2681}
2685 2682
2686void ext4_read_inode(struct inode * inode) 2683struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
2687{ 2684{
2688 struct ext4_iloc iloc; 2685 struct ext4_iloc iloc;
2689 struct ext4_inode *raw_inode; 2686 struct ext4_inode *raw_inode;
2690 struct ext4_inode_info *ei = EXT4_I(inode); 2687 struct ext4_inode_info *ei;
2691 struct buffer_head *bh; 2688 struct buffer_head *bh;
2689 struct inode *inode;
2690 long ret;
2692 int block; 2691 int block;
2693 2692
2693 inode = iget_locked(sb, ino);
2694 if (!inode)
2695 return ERR_PTR(-ENOMEM);
2696 if (!(inode->i_state & I_NEW))
2697 return inode;
2698
2699 ei = EXT4_I(inode);
2694#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL 2700#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
2695 ei->i_acl = EXT4_ACL_NOT_CACHED; 2701 ei->i_acl = EXT4_ACL_NOT_CACHED;
2696 ei->i_default_acl = EXT4_ACL_NOT_CACHED; 2702 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
2697#endif 2703#endif
2698 ei->i_block_alloc_info = NULL; 2704 ei->i_block_alloc_info = NULL;
2699 2705
2700 if (__ext4_get_inode_loc(inode, &iloc, 0)) 2706 ret = __ext4_get_inode_loc(inode, &iloc, 0);
2707 if (ret < 0)
2701 goto bad_inode; 2708 goto bad_inode;
2702 bh = iloc.bh; 2709 bh = iloc.bh;
2703 raw_inode = ext4_raw_inode(&iloc); 2710 raw_inode = ext4_raw_inode(&iloc);
@@ -2723,6 +2730,7 @@ void ext4_read_inode(struct inode * inode)
2723 !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) { 2730 !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) {
2724 /* this inode is deleted */ 2731 /* this inode is deleted */
2725 brelse (bh); 2732 brelse (bh);
2733 ret = -ESTALE;
2726 goto bad_inode; 2734 goto bad_inode;
2727 } 2735 }
2728 /* The only unlinked inodes we let through here have 2736 /* The only unlinked inodes we let through here have
@@ -2761,6 +2769,7 @@ void ext4_read_inode(struct inode * inode)
2761 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > 2769 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
2762 EXT4_INODE_SIZE(inode->i_sb)) { 2770 EXT4_INODE_SIZE(inode->i_sb)) {
2763 brelse (bh); 2771 brelse (bh);
2772 ret = -EIO;
2764 goto bad_inode; 2773 goto bad_inode;
2765 } 2774 }
2766 if (ei->i_extra_isize == 0) { 2775 if (ei->i_extra_isize == 0) {
@@ -2814,11 +2823,12 @@ void ext4_read_inode(struct inode * inode)
2814 } 2823 }
2815 brelse (iloc.bh); 2824 brelse (iloc.bh);
2816 ext4_set_inode_flags(inode); 2825 ext4_set_inode_flags(inode);
2817 return; 2826 unlock_new_inode(inode);
2827 return inode;
2818 2828
2819bad_inode: 2829bad_inode:
2820 make_bad_inode(inode); 2830 iget_failed(inode);
2821 return; 2831 return ERR_PTR(ret);
2822} 2832}
2823 2833
2824static int ext4_inode_blocks_set(handle_t *handle, 2834static int ext4_inode_blocks_set(handle_t *handle,
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 67b6d8a1ceff..d153bb5922fc 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1039,17 +1039,11 @@ static struct dentry *ext4_lookup(struct inode * dir, struct dentry *dentry, str
1039 if (!ext4_valid_inum(dir->i_sb, ino)) { 1039 if (!ext4_valid_inum(dir->i_sb, ino)) {
1040 ext4_error(dir->i_sb, "ext4_lookup", 1040 ext4_error(dir->i_sb, "ext4_lookup",
1041 "bad inode number: %lu", ino); 1041 "bad inode number: %lu", ino);
1042 inode = NULL; 1042 return ERR_PTR(-EIO);
1043 } else
1044 inode = iget(dir->i_sb, ino);
1045
1046 if (!inode)
1047 return ERR_PTR(-EACCES);
1048
1049 if (is_bad_inode(inode)) {
1050 iput(inode);
1051 return ERR_PTR(-ENOENT);
1052 } 1043 }
1044 inode = ext4_iget(dir->i_sb, ino);
1045 if (IS_ERR(inode))
1046 return ERR_CAST(inode);
1053 } 1047 }
1054 return d_splice_alias(inode, dentry); 1048 return d_splice_alias(inode, dentry);
1055} 1049}
@@ -1078,18 +1072,13 @@ struct dentry *ext4_get_parent(struct dentry *child)
1078 if (!ext4_valid_inum(child->d_inode->i_sb, ino)) { 1072 if (!ext4_valid_inum(child->d_inode->i_sb, ino)) {
1079 ext4_error(child->d_inode->i_sb, "ext4_get_parent", 1073 ext4_error(child->d_inode->i_sb, "ext4_get_parent",
1080 "bad inode number: %lu", ino); 1074 "bad inode number: %lu", ino);
1081 inode = NULL; 1075 return ERR_PTR(-EIO);
1082 } else
1083 inode = iget(child->d_inode->i_sb, ino);
1084
1085 if (!inode)
1086 return ERR_PTR(-EACCES);
1087
1088 if (is_bad_inode(inode)) {
1089 iput(inode);
1090 return ERR_PTR(-ENOENT);
1091 } 1076 }
1092 1077
1078 inode = ext4_iget(child->d_inode->i_sb, ino);
1079 if (IS_ERR(inode))
1080 return ERR_CAST(inode);
1081
1093 parent = d_alloc_anon(inode); 1082 parent = d_alloc_anon(inode);
1094 if (!parent) { 1083 if (!parent) {
1095 iput(inode); 1084 iput(inode);
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 4fbba60816f4..9477a2bd6ff2 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -779,12 +779,11 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
779 "No reserved GDT blocks, can't resize"); 779 "No reserved GDT blocks, can't resize");
780 return -EPERM; 780 return -EPERM;
781 } 781 }
782 inode = iget(sb, EXT4_RESIZE_INO); 782 inode = ext4_iget(sb, EXT4_RESIZE_INO);
783 if (!inode || is_bad_inode(inode)) { 783 if (IS_ERR(inode)) {
784 ext4_warning(sb, __FUNCTION__, 784 ext4_warning(sb, __FUNCTION__,
785 "Error opening resize inode"); 785 "Error opening resize inode");
786 iput(inode); 786 return PTR_ERR(inode);
787 return -ENOENT;
788 } 787 }
789 } 788 }
790 789
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 055a0cd0168e..93beb865c20d 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -777,11 +777,10 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb,
777 * Currently we don't know the generation for parent directory, so 777 * Currently we don't know the generation for parent directory, so
778 * a generation of 0 means "accept any" 778 * a generation of 0 means "accept any"
779 */ 779 */
780 inode = iget(sb, ino); 780 inode = ext4_iget(sb, ino);
781 if (inode == NULL) 781 if (IS_ERR(inode))
782 return ERR_PTR(-ENOMEM); 782 return ERR_CAST(inode);
783 if (is_bad_inode(inode) || 783 if (generation && inode->i_generation != generation) {
784 (generation && inode->i_generation != generation)) {
785 iput(inode); 784 iput(inode);
786 return ERR_PTR(-ESTALE); 785 return ERR_PTR(-ESTALE);
787 } 786 }
@@ -850,7 +849,6 @@ static struct quotactl_ops ext4_qctl_operations = {
850static const struct super_operations ext4_sops = { 849static const struct super_operations ext4_sops = {
851 .alloc_inode = ext4_alloc_inode, 850 .alloc_inode = ext4_alloc_inode,
852 .destroy_inode = ext4_destroy_inode, 851 .destroy_inode = ext4_destroy_inode,
853 .read_inode = ext4_read_inode,
854 .write_inode = ext4_write_inode, 852 .write_inode = ext4_write_inode,
855 .dirty_inode = ext4_dirty_inode, 853 .dirty_inode = ext4_dirty_inode,
856 .delete_inode = ext4_delete_inode, 854 .delete_inode = ext4_delete_inode,
@@ -1458,7 +1456,7 @@ int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group,
1458} 1456}
1459 1457
1460/* Called at mount-time, super-block is locked */ 1458/* Called at mount-time, super-block is locked */
1461static int ext4_check_descriptors (struct super_block * sb) 1459static int ext4_check_descriptors(struct super_block *sb)
1462{ 1460{
1463 struct ext4_sb_info *sbi = EXT4_SB(sb); 1461 struct ext4_sb_info *sbi = EXT4_SB(sb);
1464 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 1462 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
@@ -1466,8 +1464,6 @@ static int ext4_check_descriptors (struct super_block * sb)
1466 ext4_fsblk_t block_bitmap; 1464 ext4_fsblk_t block_bitmap;
1467 ext4_fsblk_t inode_bitmap; 1465 ext4_fsblk_t inode_bitmap;
1468 ext4_fsblk_t inode_table; 1466 ext4_fsblk_t inode_table;
1469 struct ext4_group_desc * gdp = NULL;
1470 int desc_block = 0;
1471 int flexbg_flag = 0; 1467 int flexbg_flag = 0;
1472 ext4_group_t i; 1468 ext4_group_t i;
1473 1469
@@ -1476,17 +1472,15 @@ static int ext4_check_descriptors (struct super_block * sb)
1476 1472
1477 ext4_debug ("Checking group descriptors"); 1473 ext4_debug ("Checking group descriptors");
1478 1474
1479 for (i = 0; i < sbi->s_groups_count; i++) 1475 for (i = 0; i < sbi->s_groups_count; i++) {
1480 { 1476 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
1477
1481 if (i == sbi->s_groups_count - 1 || flexbg_flag) 1478 if (i == sbi->s_groups_count - 1 || flexbg_flag)
1482 last_block = ext4_blocks_count(sbi->s_es) - 1; 1479 last_block = ext4_blocks_count(sbi->s_es) - 1;
1483 else 1480 else
1484 last_block = first_block + 1481 last_block = first_block +
1485 (EXT4_BLOCKS_PER_GROUP(sb) - 1); 1482 (EXT4_BLOCKS_PER_GROUP(sb) - 1);
1486 1483
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); 1484 block_bitmap = ext4_block_bitmap(sb, gdp);
1491 if (block_bitmap < first_block || block_bitmap > last_block) 1485 if (block_bitmap < first_block || block_bitmap > last_block)
1492 { 1486 {
@@ -1524,8 +1518,6 @@ static int ext4_check_descriptors (struct super_block * sb)
1524 } 1518 }
1525 if (!flexbg_flag) 1519 if (!flexbg_flag)
1526 first_block += EXT4_BLOCKS_PER_GROUP(sb); 1520 first_block += EXT4_BLOCKS_PER_GROUP(sb);
1527 gdp = (struct ext4_group_desc *)
1528 ((__u8 *)gdp + EXT4_DESC_SIZE(sb));
1529 } 1521 }
1530 1522
1531 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb)); 1523 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb));
@@ -1811,6 +1803,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)
1811 unsigned long journal_devnum = 0; 1803 unsigned long journal_devnum = 0;
1812 unsigned long def_mount_opts; 1804 unsigned long def_mount_opts;
1813 struct inode *root; 1805 struct inode *root;
1806 int ret = -EINVAL;
1814 int blocksize; 1807 int blocksize;
1815 int db_count; 1808 int db_count;
1816 int i; 1809 int i;
@@ -2243,19 +2236,24 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)
2243 * so we can safely mount the rest of the filesystem now. 2236 * so we can safely mount the rest of the filesystem now.
2244 */ 2237 */
2245 2238
2246 root = iget(sb, EXT4_ROOT_INO); 2239 root = ext4_iget(sb, EXT4_ROOT_INO);
2247 sb->s_root = d_alloc_root(root); 2240 if (IS_ERR(root)) {
2248 if (!sb->s_root) {
2249 printk(KERN_ERR "EXT4-fs: get root inode failed\n"); 2241 printk(KERN_ERR "EXT4-fs: get root inode failed\n");
2250 iput(root); 2242 ret = PTR_ERR(root);
2251 goto failed_mount4; 2243 goto failed_mount4;
2252 } 2244 }
2253 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { 2245 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
2254 dput(sb->s_root); 2246 iput(root);
2255 sb->s_root = NULL;
2256 printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n"); 2247 printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n");
2257 goto failed_mount4; 2248 goto failed_mount4;
2258 } 2249 }
2250 sb->s_root = d_alloc_root(root);
2251 if (!sb->s_root) {
2252 printk(KERN_ERR "EXT4-fs: get root dentry failed\n");
2253 iput(root);
2254 ret = -ENOMEM;
2255 goto failed_mount4;
2256 }
2259 2257
2260 ext4_setup_super (sb, es, sb->s_flags & MS_RDONLY); 2258 ext4_setup_super (sb, es, sb->s_flags & MS_RDONLY);
2261 2259
@@ -2336,7 +2334,7 @@ out_fail:
2336 sb->s_fs_info = NULL; 2334 sb->s_fs_info = NULL;
2337 kfree(sbi); 2335 kfree(sbi);
2338 lock_kernel(); 2336 lock_kernel();
2339 return -EINVAL; 2337 return ret;
2340} 2338}
2341 2339
2342/* 2340/*
@@ -2372,8 +2370,8 @@ static journal_t *ext4_get_journal(struct super_block *sb,
2372 * things happen if we iget() an unused inode, as the subsequent 2370 * things happen if we iget() an unused inode, as the subsequent
2373 * iput() will try to delete it. */ 2371 * iput() will try to delete it. */
2374 2372
2375 journal_inode = iget(sb, journal_inum); 2373 journal_inode = ext4_iget(sb, journal_inum);
2376 if (!journal_inode) { 2374 if (IS_ERR(journal_inode)) {
2377 printk(KERN_ERR "EXT4-fs: no journal found.\n"); 2375 printk(KERN_ERR "EXT4-fs: no journal found.\n");
2378 return NULL; 2376 return NULL;
2379 } 2377 }
@@ -2386,7 +2384,7 @@ static journal_t *ext4_get_journal(struct super_block *sb,
2386 2384
2387 jbd_debug(2, "Journal inode found at %p: %Ld bytes\n", 2385 jbd_debug(2, "Journal inode found at %p: %Ld bytes\n",
2388 journal_inode, journal_inode->i_size); 2386 journal_inode, journal_inode->i_size);
2389 if (is_bad_inode(journal_inode) || !S_ISREG(journal_inode->i_mode)) { 2387 if (!S_ISREG(journal_inode->i_mode)) {
2390 printk(KERN_ERR "EXT4-fs: invalid journal inode.\n"); 2388 printk(KERN_ERR "EXT4-fs: invalid journal inode.\n");
2391 iput(journal_inode); 2389 iput(journal_inode);
2392 return NULL; 2390 return NULL;
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..085269e07fb3 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -634,8 +634,6 @@ static const struct super_operations fat_sops = {
634 .clear_inode = fat_clear_inode, 634 .clear_inode = fat_clear_inode,
635 .remount_fs = fat_remount, 635 .remount_fs = fat_remount,
636 636
637 .read_inode = make_bad_inode,
638
639 .show_options = fat_show_options, 637 .show_options = fat_show_options,
640}; 638};
641 639
@@ -663,8 +661,8 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
663 if (fh_len < 5 || fh_type != 3) 661 if (fh_len < 5 || fh_type != 3)
664 return NULL; 662 return NULL;
665 663
666 inode = iget(sb, fh[0]); 664 inode = ilookup(sb, fh[0]);
667 if (!inode || is_bad_inode(inode) || inode->i_generation != fh[1]) { 665 if (!inode || inode->i_generation != fh[1]) {
668 if (inode) 666 if (inode)
669 iput(inode); 667 iput(inode);
670 inode = NULL; 668 inode = NULL;
@@ -760,7 +758,7 @@ static struct dentry *fat_get_parent(struct dentry *child)
760 inode = fat_build_inode(child->d_sb, de, i_pos); 758 inode = fat_build_inode(child->d_sb, de, i_pos);
761 brelse(bh); 759 brelse(bh);
762 if (IS_ERR(inode)) { 760 if (IS_ERR(inode)) {
763 parent = ERR_PTR(PTR_ERR(inode)); 761 parent = ERR_CAST(inode);
764 goto out; 762 goto out;
765 } 763 }
766 parent = d_alloc_anon(inode); 764 parent = d_alloc_anon(inode);
@@ -1295,10 +1293,8 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
1295 1293
1296 fsinfo = (struct fat_boot_fsinfo *)fsinfo_bh->b_data; 1294 fsinfo = (struct fat_boot_fsinfo *)fsinfo_bh->b_data;
1297 if (!IS_FSINFO(fsinfo)) { 1295 if (!IS_FSINFO(fsinfo)) {
1298 printk(KERN_WARNING 1296 printk(KERN_WARNING "FAT: Invalid FSINFO signature: "
1299 "FAT: Did not find valid FSINFO signature.\n" 1297 "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), 1298 le32_to_cpu(fsinfo->signature1),
1303 le32_to_cpu(fsinfo->signature2), 1299 le32_to_cpu(fsinfo->signature2),
1304 sbi->fsinfo_sector); 1300 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/freevxfs/vxfs_dir.h b/fs/freevxfs/vxfs_dir.h
index 3c96d6e63978..aaf1fb098639 100644
--- a/fs/freevxfs/vxfs_dir.h
+++ b/fs/freevxfs/vxfs_dir.h
@@ -41,7 +41,7 @@
41 * VxFS directory block header. 41 * VxFS directory block header.
42 * 42 *
43 * This entry is the head of every filesystem block in a directory. 43 * This entry is the head of every filesystem block in a directory.
44 * It is used for free space managment and additionally includes 44 * It is used for free space management and additionally includes
45 * a hash for speeding up directory search (lookup). 45 * a hash for speeding up directory search (lookup).
46 * 46 *
47 * The hash may be empty and in fact we do not use it all in the 47 * The hash may be empty and in fact we do not use it all in the
diff --git a/fs/freevxfs/vxfs_extern.h b/fs/freevxfs/vxfs_extern.h
index 91ccee8723f7..2b46064f66b2 100644
--- a/fs/freevxfs/vxfs_extern.h
+++ b/fs/freevxfs/vxfs_extern.h
@@ -58,7 +58,7 @@ extern struct inode * vxfs_get_fake_inode(struct super_block *,
58extern void vxfs_put_fake_inode(struct inode *); 58extern void vxfs_put_fake_inode(struct inode *);
59extern struct vxfs_inode_info * vxfs_blkiget(struct super_block *, u_long, ino_t); 59extern struct vxfs_inode_info * vxfs_blkiget(struct super_block *, u_long, ino_t);
60extern struct vxfs_inode_info * vxfs_stiget(struct super_block *, ino_t); 60extern struct vxfs_inode_info * vxfs_stiget(struct super_block *, ino_t);
61extern void vxfs_read_inode(struct inode *); 61extern struct inode * vxfs_iget(struct super_block *, ino_t);
62extern void vxfs_clear_inode(struct inode *); 62extern void vxfs_clear_inode(struct inode *);
63 63
64/* vxfs_lookup.c */ 64/* vxfs_lookup.c */
diff --git a/fs/freevxfs/vxfs_immed.c b/fs/freevxfs/vxfs_immed.c
index 24b5a775ff96..8a5959a61ba9 100644
--- a/fs/freevxfs/vxfs_immed.c
+++ b/fs/freevxfs/vxfs_immed.c
@@ -54,7 +54,7 @@ const struct inode_operations vxfs_immed_symlink_iops = {
54}; 54};
55 55
56/* 56/*
57 * Adress space operations for immed files and directories. 57 * Address space operations for immed files and directories.
58 */ 58 */
59const struct address_space_operations vxfs_immed_aops = { 59const struct address_space_operations vxfs_immed_aops = {
60 .readpage = vxfs_immed_readpage, 60 .readpage = vxfs_immed_readpage,
diff --git a/fs/freevxfs/vxfs_inode.c b/fs/freevxfs/vxfs_inode.c
index d1f7c5b5b3c3..ad88d2364bc2 100644
--- a/fs/freevxfs/vxfs_inode.c
+++ b/fs/freevxfs/vxfs_inode.c
@@ -129,7 +129,7 @@ fail:
129 * Description: 129 * Description:
130 * Search the for inode number @ino in the filesystem 130 * Search the for inode number @ino in the filesystem
131 * described by @sbp. Use the specified inode table (@ilistp). 131 * described by @sbp. Use the specified inode table (@ilistp).
132 * Returns the matching VxFS inode on success, else a NULL pointer. 132 * Returns the matching VxFS inode on success, else an error code.
133 */ 133 */
134static struct vxfs_inode_info * 134static struct vxfs_inode_info *
135__vxfs_iget(ino_t ino, struct inode *ilistp) 135__vxfs_iget(ino_t ino, struct inode *ilistp)
@@ -157,12 +157,12 @@ __vxfs_iget(ino_t ino, struct inode *ilistp)
157 } 157 }
158 158
159 printk(KERN_WARNING "vxfs: error on page %p\n", pp); 159 printk(KERN_WARNING "vxfs: error on page %p\n", pp);
160 return NULL; 160 return ERR_CAST(pp);
161 161
162fail: 162fail:
163 printk(KERN_WARNING "vxfs: unable to read inode %ld\n", (unsigned long)ino); 163 printk(KERN_WARNING "vxfs: unable to read inode %ld\n", (unsigned long)ino);
164 vxfs_put_page(pp); 164 vxfs_put_page(pp);
165 return NULL; 165 return ERR_PTR(-ENOMEM);
166} 166}
167 167
168/** 168/**
@@ -178,7 +178,10 @@ fail:
178struct vxfs_inode_info * 178struct vxfs_inode_info *
179vxfs_stiget(struct super_block *sbp, ino_t ino) 179vxfs_stiget(struct super_block *sbp, ino_t ino)
180{ 180{
181 return __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_stilist); 181 struct vxfs_inode_info *vip;
182
183 vip = __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_stilist);
184 return IS_ERR(vip) ? NULL : vip;
182} 185}
183 186
184/** 187/**
@@ -282,23 +285,32 @@ vxfs_put_fake_inode(struct inode *ip)
282} 285}
283 286
284/** 287/**
285 * vxfs_read_inode - fill in inode information 288 * vxfs_iget - get an inode
286 * @ip: inode pointer to fill 289 * @sbp: the superblock to get the inode for
290 * @ino: the number of the inode to get
287 * 291 *
288 * Description: 292 * Description:
289 * vxfs_read_inode reads the disk inode for @ip and fills 293 * vxfs_read_inode creates an inode, reads the disk inode for @ino and fills
290 * in all relevant fields in @ip. 294 * in all relevant fields in the new inode.
291 */ 295 */
292void 296struct inode *
293vxfs_read_inode(struct inode *ip) 297vxfs_iget(struct super_block *sbp, ino_t ino)
294{ 298{
295 struct super_block *sbp = ip->i_sb;
296 struct vxfs_inode_info *vip; 299 struct vxfs_inode_info *vip;
297 const struct address_space_operations *aops; 300 const struct address_space_operations *aops;
298 ino_t ino = ip->i_ino; 301 struct inode *ip;
299 302
300 if (!(vip = __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_ilist))) 303 ip = iget_locked(sbp, ino);
301 return; 304 if (!ip)
305 return ERR_PTR(-ENOMEM);
306 if (!(ip->i_state & I_NEW))
307 return ip;
308
309 vip = __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_ilist);
310 if (IS_ERR(vip)) {
311 iget_failed(ip);
312 return ERR_CAST(vip);
313 }
302 314
303 vxfs_iinit(ip, vip); 315 vxfs_iinit(ip, vip);
304 316
@@ -323,7 +335,8 @@ vxfs_read_inode(struct inode *ip)
323 } else 335 } else
324 init_special_inode(ip, ip->i_mode, old_decode_dev(vip->vii_rdev)); 336 init_special_inode(ip, ip->i_mode, old_decode_dev(vip->vii_rdev));
325 337
326 return; 338 unlock_new_inode(ip);
339 return ip;
327} 340}
328 341
329/** 342/**
diff --git a/fs/freevxfs/vxfs_lookup.c b/fs/freevxfs/vxfs_lookup.c
index bf86e5444ea6..aee049cb9f84 100644
--- a/fs/freevxfs/vxfs_lookup.c
+++ b/fs/freevxfs/vxfs_lookup.c
@@ -213,10 +213,10 @@ vxfs_lookup(struct inode *dip, struct dentry *dp, struct nameidata *nd)
213 lock_kernel(); 213 lock_kernel();
214 ino = vxfs_inode_by_name(dip, dp); 214 ino = vxfs_inode_by_name(dip, dp);
215 if (ino) { 215 if (ino) {
216 ip = iget(dip->i_sb, ino); 216 ip = vxfs_iget(dip->i_sb, ino);
217 if (!ip) { 217 if (IS_ERR(ip)) {
218 unlock_kernel(); 218 unlock_kernel();
219 return ERR_PTR(-EACCES); 219 return ERR_CAST(ip);
220 } 220 }
221 } 221 }
222 unlock_kernel(); 222 unlock_kernel();
diff --git a/fs/freevxfs/vxfs_super.c b/fs/freevxfs/vxfs_super.c
index 4f95572d2722..1dacda831577 100644
--- a/fs/freevxfs/vxfs_super.c
+++ b/fs/freevxfs/vxfs_super.c
@@ -60,7 +60,6 @@ static int vxfs_statfs(struct dentry *, struct kstatfs *);
60static int vxfs_remount(struct super_block *, int *, char *); 60static int vxfs_remount(struct super_block *, int *, char *);
61 61
62static const struct super_operations vxfs_super_ops = { 62static const struct super_operations vxfs_super_ops = {
63 .read_inode = vxfs_read_inode,
64 .clear_inode = vxfs_clear_inode, 63 .clear_inode = vxfs_clear_inode,
65 .put_super = vxfs_put_super, 64 .put_super = vxfs_put_super,
66 .statfs = vxfs_statfs, 65 .statfs = vxfs_statfs,
@@ -153,6 +152,7 @@ static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
153 struct buffer_head *bp = NULL; 152 struct buffer_head *bp = NULL;
154 u_long bsize; 153 u_long bsize;
155 struct inode *root; 154 struct inode *root;
155 int ret = -EINVAL;
156 156
157 sbp->s_flags |= MS_RDONLY; 157 sbp->s_flags |= MS_RDONLY;
158 158
@@ -219,7 +219,11 @@ static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
219 } 219 }
220 220
221 sbp->s_op = &vxfs_super_ops; 221 sbp->s_op = &vxfs_super_ops;
222 root = iget(sbp, VXFS_ROOT_INO); 222 root = vxfs_iget(sbp, VXFS_ROOT_INO);
223 if (IS_ERR(root)) {
224 ret = PTR_ERR(root);
225 goto out;
226 }
223 sbp->s_root = d_alloc_root(root); 227 sbp->s_root = d_alloc_root(root);
224 if (!sbp->s_root) { 228 if (!sbp->s_root) {
225 iput(root); 229 iput(root);
@@ -236,7 +240,7 @@ out_free_ilist:
236out: 240out:
237 brelse(bp); 241 brelse(bp);
238 kfree(infp); 242 kfree(infp);
239 return -EINVAL; 243 return ret;
240} 244}
241 245
242/* 246/*
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 300324bd563c..db80ce9eb1d0 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -284,7 +284,17 @@ __sync_single_inode(struct inode *inode, struct writeback_control *wbc)
284 * soon as the queue becomes uncongested. 284 * soon as the queue becomes uncongested.
285 */ 285 */
286 inode->i_state |= I_DIRTY_PAGES; 286 inode->i_state |= I_DIRTY_PAGES;
287 requeue_io(inode); 287 if (wbc->nr_to_write <= 0) {
288 /*
289 * slice used up: queue for next turn
290 */
291 requeue_io(inode);
292 } else {
293 /*
294 * somehow blocked: retry later
295 */
296 redirty_tail(inode);
297 }
288 } else { 298 } else {
289 /* 299 /*
290 * Otherwise fully redirty the inode so that 300 * Otherwise fully redirty the inode so that
@@ -334,9 +344,6 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
334 WARN_ON(inode->i_state & I_WILL_FREE); 344 WARN_ON(inode->i_state & I_WILL_FREE);
335 345
336 if ((wbc->sync_mode != WB_SYNC_ALL) && (inode->i_state & I_SYNC)) { 346 if ((wbc->sync_mode != WB_SYNC_ALL) && (inode->i_state & I_SYNC)) {
337 struct address_space *mapping = inode->i_mapping;
338 int ret;
339
340 /* 347 /*
341 * We're skipping this inode because it's locked, and we're not 348 * We're skipping this inode because it's locked, and we're not
342 * doing writeback-for-data-integrity. Move it to s_more_io so 349 * doing writeback-for-data-integrity. Move it to s_more_io so
@@ -345,15 +352,7 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
345 * completed a full scan of s_io. 352 * completed a full scan of s_io.
346 */ 353 */
347 requeue_io(inode); 354 requeue_io(inode);
348 355 return 0;
349 /*
350 * Even if we don't actually write the inode itself here,
351 * we can at least start some of the data writeout..
352 */
353 spin_unlock(&inode_lock);
354 ret = do_writepages(mapping, wbc);
355 spin_lock(&inode_lock);
356 return ret;
357 } 356 }
358 357
359 /* 358 /*
@@ -479,8 +478,12 @@ sync_sb_inodes(struct super_block *sb, struct writeback_control *wbc)
479 iput(inode); 478 iput(inode);
480 cond_resched(); 479 cond_resched();
481 spin_lock(&inode_lock); 480 spin_lock(&inode_lock);
482 if (wbc->nr_to_write <= 0) 481 if (wbc->nr_to_write <= 0) {
482 wbc->more_io = 1;
483 break; 483 break;
484 }
485 if (!list_empty(&sb->s_more_io))
486 wbc->more_io = 1;
484 } 487 }
485 return; /* Leave any unwritten inodes on s_io */ 488 return; /* Leave any unwritten inodes on s_io */
486} 489}
@@ -512,8 +515,7 @@ writeback_inodes(struct writeback_control *wbc)
512 might_sleep(); 515 might_sleep();
513 spin_lock(&sb_lock); 516 spin_lock(&sb_lock);
514restart: 517restart:
515 sb = sb_entry(super_blocks.prev); 518 list_for_each_entry_reverse(sb, &super_blocks, s_list) {
516 for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) {
517 if (sb_has_dirty_inodes(sb)) { 519 if (sb_has_dirty_inodes(sb)) {
518 /* we're making our own get_super here */ 520 /* we're making our own get_super here */
519 sb->s_count++; 521 sb->s_count++;
@@ -578,10 +580,8 @@ static void set_sb_syncing(int val)
578{ 580{
579 struct super_block *sb; 581 struct super_block *sb;
580 spin_lock(&sb_lock); 582 spin_lock(&sb_lock);
581 sb = sb_entry(super_blocks.prev); 583 list_for_each_entry_reverse(sb, &super_blocks, s_list)
582 for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) {
583 sb->s_syncing = val; 584 sb->s_syncing = val;
584 }
585 spin_unlock(&sb_lock); 585 spin_unlock(&sb_lock);
586} 586}
587 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..7fb514b6d852 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -269,12 +269,12 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
269 269
270 req = fuse_get_req(fc); 270 req = fuse_get_req(fc);
271 if (IS_ERR(req)) 271 if (IS_ERR(req))
272 return ERR_PTR(PTR_ERR(req)); 272 return ERR_CAST(req);
273 273
274 forget_req = fuse_get_req(fc); 274 forget_req = fuse_get_req(fc);
275 if (IS_ERR(forget_req)) { 275 if (IS_ERR(forget_req)) {
276 fuse_put_request(fc, req); 276 fuse_put_request(fc, req);
277 return ERR_PTR(PTR_ERR(forget_req)); 277 return ERR_CAST(forget_req);
278 } 278 }
279 279
280 attr_version = fuse_get_attr_version(fc); 280 attr_version = fuse_get_attr_version(fc);
@@ -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;
@@ -1005,7 +1006,7 @@ static char *read_link(struct dentry *dentry)
1005 char *link; 1006 char *link;
1006 1007
1007 if (IS_ERR(req)) 1008 if (IS_ERR(req))
1008 return ERR_PTR(PTR_ERR(req)); 1009 return ERR_CAST(req);
1009 1010
1010 link = (char *) __get_free_page(GFP_KERNEL); 1011 link = (char *) __get_free_page(GFP_KERNEL);
1011 if (!link) { 1012 if (!link) {
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..574707409bbf 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -76,11 +76,6 @@ static void fuse_destroy_inode(struct inode *inode)
76 kmem_cache_free(fuse_inode_cachep, inode); 76 kmem_cache_free(fuse_inode_cachep, inode);
77} 77}
78 78
79static void fuse_read_inode(struct inode *inode)
80{
81 /* No op */
82}
83
84void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, 79void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
85 unsigned long nodeid, u64 nlookup) 80 unsigned long nodeid, u64 nlookup)
86{ 81{
@@ -465,6 +460,7 @@ static struct fuse_conn *new_conn(void)
465 INIT_LIST_HEAD(&fc->processing); 460 INIT_LIST_HEAD(&fc->processing);
466 INIT_LIST_HEAD(&fc->io); 461 INIT_LIST_HEAD(&fc->io);
467 INIT_LIST_HEAD(&fc->interrupts); 462 INIT_LIST_HEAD(&fc->interrupts);
463 INIT_LIST_HEAD(&fc->bg_queue);
468 atomic_set(&fc->num_waiting, 0); 464 atomic_set(&fc->num_waiting, 0);
469 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; 465 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
470 fc->bdi.unplug_io_fn = default_unplug_io_fn; 466 fc->bdi.unplug_io_fn = default_unplug_io_fn;
@@ -514,7 +510,6 @@ static struct inode *get_root_inode(struct super_block *sb, unsigned mode)
514static const struct super_operations fuse_super_operations = { 510static const struct super_operations fuse_super_operations = {
515 .alloc_inode = fuse_alloc_inode, 511 .alloc_inode = fuse_alloc_inode,
516 .destroy_inode = fuse_destroy_inode, 512 .destroy_inode = fuse_destroy_inode,
517 .read_inode = fuse_read_inode,
518 .clear_inode = fuse_clear_inode, 513 .clear_inode = fuse_clear_inode,
519 .drop_inode = generic_delete_inode, 514 .drop_inode = generic_delete_inode,
520 .remount_fs = fuse_remount_fs, 515 .remount_fs = fuse_remount_fs,
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index e4effc47abfc..e9456ebd3bb6 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -932,7 +932,7 @@ static int gfs2_block_truncate_page(struct address_space *mapping)
932 if (!gfs2_is_writeback(ip)) 932 if (!gfs2_is_writeback(ip))
933 gfs2_trans_add_bh(ip->i_gl, bh, 0); 933 gfs2_trans_add_bh(ip->i_gl, bh, 0);
934 934
935 zero_user_page(page, offset, length, KM_USER0); 935 zero_user(page, offset, length);
936 936
937unlock: 937unlock:
938 unlock_page(page); 938 unlock_page(page);
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 57e2ed932adc..c34709512b19 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -1498,7 +1498,7 @@ struct inode *gfs2_dir_search(struct inode *dir, const struct qstr *name)
1498 dent = gfs2_dirent_search(dir, name, gfs2_dirent_find, &bh); 1498 dent = gfs2_dirent_search(dir, name, gfs2_dirent_find, &bh);
1499 if (dent) { 1499 if (dent) {
1500 if (IS_ERR(dent)) 1500 if (IS_ERR(dent))
1501 return ERR_PTR(PTR_ERR(dent)); 1501 return ERR_CAST(dent);
1502 inode = gfs2_inode_lookup(dir->i_sb, 1502 inode = gfs2_inode_lookup(dir->i_sb,
1503 be16_to_cpu(dent->de_type), 1503 be16_to_cpu(dent->de_type),
1504 be64_to_cpu(dent->de_inum.no_addr), 1504 be64_to_cpu(dent->de_inum.no_addr),
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 80e09c50590a..7175a4d06435 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -334,7 +334,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
334 gl->gl_state = LM_ST_UNLOCKED; 334 gl->gl_state = LM_ST_UNLOCKED;
335 gl->gl_demote_state = LM_ST_EXCLUSIVE; 335 gl->gl_demote_state = LM_ST_EXCLUSIVE;
336 gl->gl_hash = hash; 336 gl->gl_hash = hash;
337 gl->gl_owner_pid = 0; 337 gl->gl_owner_pid = NULL;
338 gl->gl_ip = 0; 338 gl->gl_ip = 0;
339 gl->gl_ops = glops; 339 gl->gl_ops = glops;
340 gl->gl_req_gh = NULL; 340 gl->gl_req_gh = NULL;
@@ -399,7 +399,7 @@ void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags,
399 INIT_LIST_HEAD(&gh->gh_list); 399 INIT_LIST_HEAD(&gh->gh_list);
400 gh->gh_gl = gl; 400 gh->gh_gl = gl;
401 gh->gh_ip = (unsigned long)__builtin_return_address(0); 401 gh->gh_ip = (unsigned long)__builtin_return_address(0);
402 gh->gh_owner_pid = current->pid; 402 gh->gh_owner_pid = get_pid(task_pid(current));
403 gh->gh_state = state; 403 gh->gh_state = state;
404 gh->gh_flags = flags; 404 gh->gh_flags = flags;
405 gh->gh_error = 0; 405 gh->gh_error = 0;
@@ -433,6 +433,7 @@ void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder *
433 433
434void gfs2_holder_uninit(struct gfs2_holder *gh) 434void gfs2_holder_uninit(struct gfs2_holder *gh)
435{ 435{
436 put_pid(gh->gh_owner_pid);
436 gfs2_glock_put(gh->gh_gl); 437 gfs2_glock_put(gh->gh_gl);
437 gh->gh_gl = NULL; 438 gh->gh_gl = NULL;
438 gh->gh_ip = 0; 439 gh->gh_ip = 0;
@@ -631,7 +632,7 @@ static void gfs2_glmutex_lock(struct gfs2_glock *gl)
631 wait_on_holder(&gh); 632 wait_on_holder(&gh);
632 gfs2_holder_uninit(&gh); 633 gfs2_holder_uninit(&gh);
633 } else { 634 } else {
634 gl->gl_owner_pid = current->pid; 635 gl->gl_owner_pid = get_pid(task_pid(current));
635 gl->gl_ip = (unsigned long)__builtin_return_address(0); 636 gl->gl_ip = (unsigned long)__builtin_return_address(0);
636 spin_unlock(&gl->gl_spin); 637 spin_unlock(&gl->gl_spin);
637 } 638 }
@@ -652,7 +653,7 @@ static int gfs2_glmutex_trylock(struct gfs2_glock *gl)
652 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { 653 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) {
653 acquired = 0; 654 acquired = 0;
654 } else { 655 } else {
655 gl->gl_owner_pid = current->pid; 656 gl->gl_owner_pid = get_pid(task_pid(current));
656 gl->gl_ip = (unsigned long)__builtin_return_address(0); 657 gl->gl_ip = (unsigned long)__builtin_return_address(0);
657 } 658 }
658 spin_unlock(&gl->gl_spin); 659 spin_unlock(&gl->gl_spin);
@@ -668,12 +669,17 @@ static int gfs2_glmutex_trylock(struct gfs2_glock *gl)
668 669
669static void gfs2_glmutex_unlock(struct gfs2_glock *gl) 670static void gfs2_glmutex_unlock(struct gfs2_glock *gl)
670{ 671{
672 struct pid *pid;
673
671 spin_lock(&gl->gl_spin); 674 spin_lock(&gl->gl_spin);
672 clear_bit(GLF_LOCK, &gl->gl_flags); 675 clear_bit(GLF_LOCK, &gl->gl_flags);
673 gl->gl_owner_pid = 0; 676 pid = gl->gl_owner_pid;
677 gl->gl_owner_pid = NULL;
674 gl->gl_ip = 0; 678 gl->gl_ip = 0;
675 run_queue(gl); 679 run_queue(gl);
676 spin_unlock(&gl->gl_spin); 680 spin_unlock(&gl->gl_spin);
681
682 put_pid(pid);
677} 683}
678 684
679/** 685/**
@@ -1045,7 +1051,7 @@ static int glock_wait_internal(struct gfs2_holder *gh)
1045} 1051}
1046 1052
1047static inline struct gfs2_holder * 1053static inline struct gfs2_holder *
1048find_holder_by_owner(struct list_head *head, pid_t pid) 1054find_holder_by_owner(struct list_head *head, struct pid *pid)
1049{ 1055{
1050 struct gfs2_holder *gh; 1056 struct gfs2_holder *gh;
1051 1057
@@ -1082,7 +1088,7 @@ static void add_to_queue(struct gfs2_holder *gh)
1082 struct gfs2_glock *gl = gh->gh_gl; 1088 struct gfs2_glock *gl = gh->gh_gl;
1083 struct gfs2_holder *existing; 1089 struct gfs2_holder *existing;
1084 1090
1085 BUG_ON(!gh->gh_owner_pid); 1091 BUG_ON(gh->gh_owner_pid == NULL);
1086 if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) 1092 if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags))
1087 BUG(); 1093 BUG();
1088 1094
@@ -1092,12 +1098,14 @@ static void add_to_queue(struct gfs2_holder *gh)
1092 if (existing) { 1098 if (existing) {
1093 print_symbol(KERN_WARNING "original: %s\n", 1099 print_symbol(KERN_WARNING "original: %s\n",
1094 existing->gh_ip); 1100 existing->gh_ip);
1095 printk(KERN_INFO "pid : %d\n", existing->gh_owner_pid); 1101 printk(KERN_INFO "pid : %d\n",
1102 pid_nr(existing->gh_owner_pid));
1096 printk(KERN_INFO "lock type : %d lock state : %d\n", 1103 printk(KERN_INFO "lock type : %d lock state : %d\n",
1097 existing->gh_gl->gl_name.ln_type, 1104 existing->gh_gl->gl_name.ln_type,
1098 existing->gh_gl->gl_state); 1105 existing->gh_gl->gl_state);
1099 print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip); 1106 print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip);
1100 printk(KERN_INFO "pid : %d\n", gh->gh_owner_pid); 1107 printk(KERN_INFO "pid : %d\n",
1108 pid_nr(gh->gh_owner_pid));
1101 printk(KERN_INFO "lock type : %d lock state : %d\n", 1109 printk(KERN_INFO "lock type : %d lock state : %d\n",
1102 gl->gl_name.ln_type, gl->gl_state); 1110 gl->gl_name.ln_type, gl->gl_state);
1103 BUG(); 1111 BUG();
@@ -1798,8 +1806,9 @@ static int dump_holder(struct glock_iter *gi, char *str,
1798 1806
1799 print_dbg(gi, " %s\n", str); 1807 print_dbg(gi, " %s\n", str);
1800 if (gh->gh_owner_pid) { 1808 if (gh->gh_owner_pid) {
1801 print_dbg(gi, " owner = %ld ", (long)gh->gh_owner_pid); 1809 print_dbg(gi, " owner = %ld ",
1802 gh_owner = find_task_by_pid(gh->gh_owner_pid); 1810 (long)pid_nr(gh->gh_owner_pid));
1811 gh_owner = pid_task(gh->gh_owner_pid, PIDTYPE_PID);
1803 if (gh_owner) 1812 if (gh_owner)
1804 print_dbg(gi, "(%s)\n", gh_owner->comm); 1813 print_dbg(gi, "(%s)\n", gh_owner->comm);
1805 else 1814 else
@@ -1877,13 +1886,13 @@ static int dump_glock(struct glock_iter *gi, struct gfs2_glock *gl)
1877 print_dbg(gi, " gl_ref = %d\n", atomic_read(&gl->gl_ref)); 1886 print_dbg(gi, " gl_ref = %d\n", atomic_read(&gl->gl_ref));
1878 print_dbg(gi, " gl_state = %u\n", gl->gl_state); 1887 print_dbg(gi, " gl_state = %u\n", gl->gl_state);
1879 if (gl->gl_owner_pid) { 1888 if (gl->gl_owner_pid) {
1880 gl_owner = find_task_by_pid(gl->gl_owner_pid); 1889 gl_owner = pid_task(gl->gl_owner_pid, PIDTYPE_PID);
1881 if (gl_owner) 1890 if (gl_owner)
1882 print_dbg(gi, " gl_owner = pid %d (%s)\n", 1891 print_dbg(gi, " gl_owner = pid %d (%s)\n",
1883 gl->gl_owner_pid, gl_owner->comm); 1892 pid_nr(gl->gl_owner_pid), gl_owner->comm);
1884 else 1893 else
1885 print_dbg(gi, " gl_owner = %d (ended)\n", 1894 print_dbg(gi, " gl_owner = %d (ended)\n",
1886 gl->gl_owner_pid); 1895 pid_nr(gl->gl_owner_pid));
1887 } else 1896 } else
1888 print_dbg(gi, " gl_owner = -1\n"); 1897 print_dbg(gi, " gl_owner = -1\n");
1889 print_dbg(gi, " gl_ip = %lu\n", gl->gl_ip); 1898 print_dbg(gi, " gl_ip = %lu\n", gl->gl_ip);
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index b16f604eea9f..2f9c6d136b37 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -36,11 +36,13 @@ static inline int gfs2_glock_is_locked_by_me(struct gfs2_glock *gl)
36{ 36{
37 struct gfs2_holder *gh; 37 struct gfs2_holder *gh;
38 int locked = 0; 38 int locked = 0;
39 struct pid *pid;
39 40
40 /* Look in glock's list of holders for one with current task as owner */ 41 /* Look in glock's list of holders for one with current task as owner */
41 spin_lock(&gl->gl_spin); 42 spin_lock(&gl->gl_spin);
43 pid = task_pid(current);
42 list_for_each_entry(gh, &gl->gl_holders, gh_list) { 44 list_for_each_entry(gh, &gl->gl_holders, gh_list) {
43 if (gh->gh_owner_pid == current->pid) { 45 if (gh->gh_owner_pid == pid) {
44 locked = 1; 46 locked = 1;
45 break; 47 break;
46 } 48 }
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 513aaf0dc0ab..525dcae352d6 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -151,7 +151,7 @@ struct gfs2_holder {
151 struct list_head gh_list; 151 struct list_head gh_list;
152 152
153 struct gfs2_glock *gh_gl; 153 struct gfs2_glock *gh_gl;
154 pid_t gh_owner_pid; 154 struct pid *gh_owner_pid;
155 unsigned int gh_state; 155 unsigned int gh_state;
156 unsigned gh_flags; 156 unsigned gh_flags;
157 157
@@ -182,7 +182,7 @@ struct gfs2_glock {
182 unsigned int gl_hash; 182 unsigned int gl_hash;
183 unsigned int gl_demote_state; /* state requested by remote node */ 183 unsigned int gl_demote_state; /* state requested by remote node */
184 unsigned long gl_demote_time; /* time of first demote request */ 184 unsigned long gl_demote_time; /* time of first demote request */
185 pid_t gl_owner_pid; 185 struct pid *gl_owner_pid;
186 unsigned long gl_ip; 186 unsigned long gl_ip;
187 struct list_head gl_holders; 187 struct list_head gl_holders;
188 struct list_head gl_waiters1; /* HIF_MUTEX */ 188 struct list_head gl_waiters1; /* HIF_MUTEX */
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 728d3169e7bd..37725ade3c51 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -240,7 +240,7 @@ fail_put:
240 ip->i_gl->gl_object = NULL; 240 ip->i_gl->gl_object = NULL;
241 gfs2_glock_put(ip->i_gl); 241 gfs2_glock_put(ip->i_gl);
242fail: 242fail:
243 iput(inode); 243 iget_failed(inode);
244 return ERR_PTR(error); 244 return ERR_PTR(error);
245} 245}
246 246
diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c
index 38dbe99a30ed..ac772b6d9dbb 100644
--- a/fs/gfs2/ops_address.c
+++ b/fs/gfs2/ops_address.c
@@ -446,7 +446,7 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
446 * so we need to supply one here. It doesn't happen often. 446 * so we need to supply one here. It doesn't happen often.
447 */ 447 */
448 if (unlikely(page->index)) { 448 if (unlikely(page->index)) {
449 zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0); 449 zero_user(page, 0, PAGE_CACHE_SIZE);
450 return 0; 450 return 0;
451 } 451 }
452 452
diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c
index b9da62348a87..334c7f85351b 100644
--- a/fs/gfs2/ops_export.c
+++ b/fs/gfs2/ops_export.c
@@ -143,7 +143,7 @@ static struct dentry *gfs2_get_parent(struct dentry *child)
143 * have to return that as a(n invalid) pointer to dentry. 143 * have to return that as a(n invalid) pointer to dentry.
144 */ 144 */
145 if (IS_ERR(inode)) 145 if (IS_ERR(inode))
146 return ERR_PTR(PTR_ERR(inode)); 146 return ERR_CAST(inode);
147 147
148 dentry = d_alloc_anon(inode); 148 dentry = d_alloc_anon(inode);
149 if (!dentry) { 149 if (!dentry) {
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 9f71372c1757..e87412902bed 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -111,7 +111,7 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
111 111
112 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd); 112 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
113 if (inode && IS_ERR(inode)) 113 if (inode && IS_ERR(inode))
114 return ERR_PTR(PTR_ERR(inode)); 114 return ERR_CAST(inode);
115 115
116 if (inode) { 116 if (inode) {
117 struct gfs2_glock *gl = GFS2_I(inode)->i_gl; 117 struct gfs2_glock *gl = GFS2_I(inode)->i_gl;
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index b249e294a95b..6fb07d67ca8a 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -450,7 +450,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd)
450 fs_info(sdp, "jid=%u: Trying to acquire journal lock...\n", 450 fs_info(sdp, "jid=%u: Trying to acquire journal lock...\n",
451 jd->jd_jid); 451 jd->jd_jid);
452 452
453 /* Aquire the journal lock so we can do recovery */ 453 /* Acquire the journal lock so we can do recovery */
454 454
455 error = gfs2_glock_nq_num(sdp, jd->jd_jid, &gfs2_journal_glops, 455 error = gfs2_glock_nq_num(sdp, jd->jd_jid, &gfs2_journal_glops,
456 LM_ST_EXCLUSIVE, 456 LM_ST_EXCLUSIVE,
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/hfsplus/btree.c b/fs/hfsplus/btree.c
index 050d29c0a5b5..bb5433608a42 100644
--- a/fs/hfsplus/btree.c
+++ b/fs/hfsplus/btree.c
@@ -22,6 +22,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
22 struct hfs_btree *tree; 22 struct hfs_btree *tree;
23 struct hfs_btree_header_rec *head; 23 struct hfs_btree_header_rec *head;
24 struct address_space *mapping; 24 struct address_space *mapping;
25 struct inode *inode;
25 struct page *page; 26 struct page *page;
26 unsigned int size; 27 unsigned int size;
27 28
@@ -33,9 +34,10 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
33 spin_lock_init(&tree->hash_lock); 34 spin_lock_init(&tree->hash_lock);
34 tree->sb = sb; 35 tree->sb = sb;
35 tree->cnid = id; 36 tree->cnid = id;
36 tree->inode = iget(sb, id); 37 inode = hfsplus_iget(sb, id);
37 if (!tree->inode) 38 if (IS_ERR(inode))
38 goto free_tree; 39 goto free_tree;
40 tree->inode = inode;
39 41
40 mapping = tree->inode->i_mapping; 42 mapping = tree->inode->i_mapping;
41 page = read_mapping_page(mapping, 0, NULL); 43 page = read_mapping_page(mapping, 0, NULL);
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index 1955ee61251c..29683645fa0a 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -97,9 +97,9 @@ again:
97 goto fail; 97 goto fail;
98 } 98 }
99 hfs_find_exit(&fd); 99 hfs_find_exit(&fd);
100 inode = iget(dir->i_sb, cnid); 100 inode = hfsplus_iget(dir->i_sb, cnid);
101 if (!inode) 101 if (IS_ERR(inode))
102 return ERR_PTR(-EACCES); 102 return ERR_CAST(inode);
103 if (S_ISREG(inode->i_mode)) 103 if (S_ISREG(inode->i_mode))
104 HFSPLUS_I(inode).dev = linkid; 104 HFSPLUS_I(inode).dev = linkid;
105out: 105out:
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index d9f5eda6d039..d72d0a8b25aa 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -345,6 +345,9 @@ int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
345void hfsplus_fill_defaults(struct hfsplus_sb_info *); 345void hfsplus_fill_defaults(struct hfsplus_sb_info *);
346int hfsplus_show_options(struct seq_file *, struct vfsmount *); 346int hfsplus_show_options(struct seq_file *, struct vfsmount *);
347 347
348/* super.c */
349struct inode *hfsplus_iget(struct super_block *, unsigned long);
350
348/* tables.c */ 351/* tables.c */
349extern u16 hfsplus_case_fold_table[]; 352extern u16 hfsplus_case_fold_table[];
350extern u16 hfsplus_decompose_table[]; 353extern u16 hfsplus_decompose_table[];
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index ecf70dafb643..b0f9ad362d1d 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -20,11 +20,18 @@ static void hfsplus_destroy_inode(struct inode *inode);
20 20
21#include "hfsplus_fs.h" 21#include "hfsplus_fs.h"
22 22
23static void hfsplus_read_inode(struct inode *inode) 23struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
24{ 24{
25 struct hfs_find_data fd; 25 struct hfs_find_data fd;
26 struct hfsplus_vh *vhdr; 26 struct hfsplus_vh *vhdr;
27 int err; 27 struct inode *inode;
28 long err = -EIO;
29
30 inode = iget_locked(sb, ino);
31 if (!inode)
32 return ERR_PTR(-ENOMEM);
33 if (!(inode->i_state & I_NEW))
34 return inode;
28 35
29 INIT_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list); 36 INIT_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list);
30 init_MUTEX(&HFSPLUS_I(inode).extents_lock); 37 init_MUTEX(&HFSPLUS_I(inode).extents_lock);
@@ -41,7 +48,7 @@ static void hfsplus_read_inode(struct inode *inode)
41 hfs_find_exit(&fd); 48 hfs_find_exit(&fd);
42 if (err) 49 if (err)
43 goto bad_inode; 50 goto bad_inode;
44 return; 51 goto done;
45 } 52 }
46 vhdr = HFSPLUS_SB(inode->i_sb).s_vhdr; 53 vhdr = HFSPLUS_SB(inode->i_sb).s_vhdr;
47 switch(inode->i_ino) { 54 switch(inode->i_ino) {
@@ -70,10 +77,13 @@ static void hfsplus_read_inode(struct inode *inode)
70 goto bad_inode; 77 goto bad_inode;
71 } 78 }
72 79
73 return; 80done:
81 unlock_new_inode(inode);
82 return inode;
74 83
75 bad_inode: 84bad_inode:
76 make_bad_inode(inode); 85 iget_failed(inode);
86 return ERR_PTR(err);
77} 87}
78 88
79static int hfsplus_write_inode(struct inode *inode, int unused) 89static int hfsplus_write_inode(struct inode *inode, int unused)
@@ -262,7 +272,6 @@ static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
262static const struct super_operations hfsplus_sops = { 272static const struct super_operations hfsplus_sops = {
263 .alloc_inode = hfsplus_alloc_inode, 273 .alloc_inode = hfsplus_alloc_inode,
264 .destroy_inode = hfsplus_destroy_inode, 274 .destroy_inode = hfsplus_destroy_inode,
265 .read_inode = hfsplus_read_inode,
266 .write_inode = hfsplus_write_inode, 275 .write_inode = hfsplus_write_inode,
267 .clear_inode = hfsplus_clear_inode, 276 .clear_inode = hfsplus_clear_inode,
268 .put_super = hfsplus_put_super, 277 .put_super = hfsplus_put_super,
@@ -278,7 +287,7 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
278 struct hfsplus_sb_info *sbi; 287 struct hfsplus_sb_info *sbi;
279 hfsplus_cat_entry entry; 288 hfsplus_cat_entry entry;
280 struct hfs_find_data fd; 289 struct hfs_find_data fd;
281 struct inode *root; 290 struct inode *root, *inode;
282 struct qstr str; 291 struct qstr str;
283 struct nls_table *nls = NULL; 292 struct nls_table *nls = NULL;
284 int err = -EINVAL; 293 int err = -EINVAL;
@@ -366,18 +375,25 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
366 goto cleanup; 375 goto cleanup;
367 } 376 }
368 377
369 HFSPLUS_SB(sb).alloc_file = iget(sb, HFSPLUS_ALLOC_CNID); 378 inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID);
370 if (!HFSPLUS_SB(sb).alloc_file) { 379 if (IS_ERR(inode)) {
371 printk(KERN_ERR "hfs: failed to load allocation file\n"); 380 printk(KERN_ERR "hfs: failed to load allocation file\n");
381 err = PTR_ERR(inode);
372 goto cleanup; 382 goto cleanup;
373 } 383 }
384 HFSPLUS_SB(sb).alloc_file = inode;
374 385
375 /* Load the root directory */ 386 /* Load the root directory */
376 root = iget(sb, HFSPLUS_ROOT_CNID); 387 root = hfsplus_iget(sb, HFSPLUS_ROOT_CNID);
388 if (IS_ERR(root)) {
389 printk(KERN_ERR "hfs: failed to load root directory\n");
390 err = PTR_ERR(root);
391 goto cleanup;
392 }
377 sb->s_root = d_alloc_root(root); 393 sb->s_root = d_alloc_root(root);
378 if (!sb->s_root) { 394 if (!sb->s_root) {
379 printk(KERN_ERR "hfs: failed to load root directory\n");
380 iput(root); 395 iput(root);
396 err = -ENOMEM;
381 goto cleanup; 397 goto cleanup;
382 } 398 }
383 sb->s_root->d_op = &hfsplus_dentry_operations; 399 sb->s_root->d_op = &hfsplus_dentry_operations;
@@ -390,9 +406,12 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
390 hfs_find_exit(&fd); 406 hfs_find_exit(&fd);
391 if (entry.type != cpu_to_be16(HFSPLUS_FOLDER)) 407 if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
392 goto cleanup; 408 goto cleanup;
393 HFSPLUS_SB(sb).hidden_dir = iget(sb, be32_to_cpu(entry.folder.id)); 409 inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
394 if (!HFSPLUS_SB(sb).hidden_dir) 410 if (IS_ERR(inode)) {
411 err = PTR_ERR(inode);
395 goto cleanup; 412 goto cleanup;
413 }
414 HFSPLUS_SB(sb).hidden_dir = inode;
396 } else 415 } else
397 hfs_find_exit(&fd); 416 hfs_find_exit(&fd);
398 417
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 8966b050196e..2b9b35733aac 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -202,7 +202,7 @@ static char *follow_link(char *link)
202 return ERR_PTR(n); 202 return ERR_PTR(n);
203} 203}
204 204
205static int read_inode(struct inode *ino) 205static int hostfs_read_inode(struct inode *ino)
206{ 206{
207 char *name; 207 char *name;
208 int err = 0; 208 int err = 0;
@@ -233,6 +233,25 @@ static int read_inode(struct inode *ino)
233 return err; 233 return err;
234} 234}
235 235
236static struct inode *hostfs_iget(struct super_block *sb)
237{
238 struct inode *inode;
239 long ret;
240
241 inode = iget_locked(sb, 0);
242 if (!inode)
243 return ERR_PTR(-ENOMEM);
244 if (inode->i_state & I_NEW) {
245 ret = hostfs_read_inode(inode);
246 if (ret < 0) {
247 iget_failed(inode);
248 return ERR_PTR(ret);
249 }
250 unlock_new_inode(inode);
251 }
252 return inode;
253}
254
236int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf) 255int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf)
237{ 256{
238 /* 257 /*
@@ -303,17 +322,11 @@ static void hostfs_destroy_inode(struct inode *inode)
303 kfree(HOSTFS_I(inode)); 322 kfree(HOSTFS_I(inode));
304} 323}
305 324
306static void hostfs_read_inode(struct inode *inode)
307{
308 read_inode(inode);
309}
310
311static const struct super_operations hostfs_sbops = { 325static const struct super_operations hostfs_sbops = {
312 .alloc_inode = hostfs_alloc_inode, 326 .alloc_inode = hostfs_alloc_inode,
313 .drop_inode = generic_delete_inode, 327 .drop_inode = generic_delete_inode,
314 .delete_inode = hostfs_delete_inode, 328 .delete_inode = hostfs_delete_inode,
315 .destroy_inode = hostfs_destroy_inode, 329 .destroy_inode = hostfs_destroy_inode,
316 .read_inode = hostfs_read_inode,
317 .statfs = hostfs_statfs, 330 .statfs = hostfs_statfs,
318}; 331};
319 332
@@ -571,10 +584,11 @@ int hostfs_create(struct inode *dir, struct dentry *dentry, int mode,
571 char *name; 584 char *name;
572 int error, fd; 585 int error, fd;
573 586
574 error = -ENOMEM; 587 inode = hostfs_iget(dir->i_sb);
575 inode = iget(dir->i_sb, 0); 588 if (IS_ERR(inode)) {
576 if (inode == NULL) 589 error = PTR_ERR(inode);
577 goto out; 590 goto out;
591 }
578 592
579 error = init_inode(inode, dentry); 593 error = init_inode(inode, dentry);
580 if (error) 594 if (error)
@@ -615,10 +629,11 @@ struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry,
615 char *name; 629 char *name;
616 int err; 630 int err;
617 631
618 err = -ENOMEM; 632 inode = hostfs_iget(ino->i_sb);
619 inode = iget(ino->i_sb, 0); 633 if (IS_ERR(inode)) {
620 if (inode == NULL) 634 err = PTR_ERR(inode);
621 goto out; 635 goto out;
636 }
622 637
623 err = init_inode(inode, dentry); 638 err = init_inode(inode, dentry);
624 if (err) 639 if (err)
@@ -736,11 +751,13 @@ int hostfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
736{ 751{
737 struct inode *inode; 752 struct inode *inode;
738 char *name; 753 char *name;
739 int err = -ENOMEM; 754 int err;
740 755
741 inode = iget(dir->i_sb, 0); 756 inode = hostfs_iget(dir->i_sb);
742 if (inode == NULL) 757 if (IS_ERR(inode)) {
758 err = PTR_ERR(inode);
743 goto out; 759 goto out;
760 }
744 761
745 err = init_inode(inode, dentry); 762 err = init_inode(inode, dentry);
746 if (err) 763 if (err)
@@ -952,9 +969,11 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
952 969
953 sprintf(host_root_path, "%s/%s", root_ino, req_root); 970 sprintf(host_root_path, "%s/%s", root_ino, req_root);
954 971
955 root_inode = iget(sb, 0); 972 root_inode = hostfs_iget(sb);
956 if (root_inode == NULL) 973 if (IS_ERR(root_inode)) {
974 err = PTR_ERR(root_inode);
957 goto out_free; 975 goto out_free;
976 }
958 977
959 err = init_inode(root_inode, NULL); 978 err = init_inode(root_inode, NULL);
960 if (err) 979 if (err)
@@ -972,7 +991,7 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
972 if (sb->s_root == NULL) 991 if (sb->s_root == NULL)
973 goto out_put; 992 goto out_put;
974 993
975 err = read_inode(root_inode); 994 err = hostfs_read_inode(root_inode);
976 if (err) { 995 if (err) {
977 /* No iput in this case because the dput does that for us */ 996 /* No iput in this case because the dput does that for us */
978 dput(sb->s_root); 997 dput(sb->s_root);
diff --git a/fs/hostfs/hostfs_user.c b/fs/hostfs/hostfs_user.c
index 35c1a9f33f47..53fd0a67c11a 100644
--- a/fs/hostfs/hostfs_user.c
+++ b/fs/hostfs/hostfs_user.c
@@ -285,17 +285,17 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd)
285 return err; 285 return err;
286 286
287 times[0].tv_sec = atime_ts.tv_sec; 287 times[0].tv_sec = atime_ts.tv_sec;
288 times[0].tv_usec = atime_ts.tv_nsec * 1000; 288 times[0].tv_usec = atime_ts.tv_nsec / 1000;
289 times[1].tv_sec = mtime_ts.tv_sec; 289 times[1].tv_sec = mtime_ts.tv_sec;
290 times[1].tv_usec = mtime_ts.tv_nsec * 1000; 290 times[1].tv_usec = mtime_ts.tv_nsec / 1000;
291 291
292 if (attrs->ia_valid & HOSTFS_ATTR_ATIME_SET) { 292 if (attrs->ia_valid & HOSTFS_ATTR_ATIME_SET) {
293 times[0].tv_sec = attrs->ia_atime.tv_sec; 293 times[0].tv_sec = attrs->ia_atime.tv_sec;
294 times[0].tv_usec = attrs->ia_atime.tv_nsec * 1000; 294 times[0].tv_usec = attrs->ia_atime.tv_nsec / 1000;
295 } 295 }
296 if (attrs->ia_valid & HOSTFS_ATTR_MTIME_SET) { 296 if (attrs->ia_valid & HOSTFS_ATTR_MTIME_SET) {
297 times[1].tv_sec = attrs->ia_mtime.tv_sec; 297 times[1].tv_sec = attrs->ia_mtime.tv_sec;
298 times[1].tv_usec = attrs->ia_mtime.tv_nsec * 1000; 298 times[1].tv_usec = attrs->ia_mtime.tv_nsec / 1000;
299 } 299 }
300 300
301 if (fd >= 0) { 301 if (fd >= 0) {
diff --git a/fs/hppfs/hppfs_kern.c b/fs/hppfs/hppfs_kern.c
index affb7412125e..a1e1f0f61aa5 100644
--- a/fs/hppfs/hppfs_kern.c
+++ b/fs/hppfs/hppfs_kern.c
@@ -155,6 +155,20 @@ static void hppfs_read_inode(struct inode *ino)
155 ino->i_blocks = proc_ino->i_blocks; 155 ino->i_blocks = proc_ino->i_blocks;
156} 156}
157 157
158static struct inode *hppfs_iget(struct super_block *sb)
159{
160 struct inode *inode;
161
162 inode = iget_locked(sb, 0);
163 if (!inode)
164 return ERR_PTR(-ENOMEM);
165 if (inode->i_state & I_NEW) {
166 hppfs_read_inode(inode);
167 unlock_new_inode(inode);
168 }
169 return inode;
170}
171
158static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry, 172static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
159 struct nameidata *nd) 173 struct nameidata *nd)
160{ 174{
@@ -190,9 +204,11 @@ static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
190 if(IS_ERR(proc_dentry)) 204 if(IS_ERR(proc_dentry))
191 return(proc_dentry); 205 return(proc_dentry);
192 206
193 inode = iget(ino->i_sb, 0); 207 inode = hppfs_iget(ino->i_sb);
194 if(inode == NULL) 208 if (IS_ERR(inode)) {
209 err = PTR_ERR(inode);
195 goto out_dput; 210 goto out_dput;
211 }
196 212
197 err = init_inode(inode, proc_dentry); 213 err = init_inode(inode, proc_dentry);
198 if(err) 214 if(err)
@@ -652,7 +668,6 @@ static void hppfs_destroy_inode(struct inode *inode)
652static const struct super_operations hppfs_sbops = { 668static const struct super_operations hppfs_sbops = {
653 .alloc_inode = hppfs_alloc_inode, 669 .alloc_inode = hppfs_alloc_inode,
654 .destroy_inode = hppfs_destroy_inode, 670 .destroy_inode = hppfs_destroy_inode,
655 .read_inode = hppfs_read_inode,
656 .delete_inode = hppfs_delete_inode, 671 .delete_inode = hppfs_delete_inode,
657 .statfs = hppfs_statfs, 672 .statfs = hppfs_statfs,
658}; 673};
@@ -745,9 +760,11 @@ static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
745 sb->s_magic = HPPFS_SUPER_MAGIC; 760 sb->s_magic = HPPFS_SUPER_MAGIC;
746 sb->s_op = &hppfs_sbops; 761 sb->s_op = &hppfs_sbops;
747 762
748 root_inode = iget(sb, 0); 763 root_inode = hppfs_iget(sb);
749 if(root_inode == NULL) 764 if (IS_ERR(root_inode)) {
765 err = PTR_ERR(root_inode);
750 goto out; 766 goto out;
767 }
751 768
752 err = init_inode(root_inode, proc_sb->s_root); 769 err = init_inode(root_inode, proc_sb->s_root);
753 if(err) 770 if(err)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 09ee07f02663..3b3cc28cdefc 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -768,7 +768,7 @@ hugetlbfs_parse_options(char *options, struct hugetlbfs_config *pconfig)
768 case Opt_mode: 768 case Opt_mode:
769 if (match_octal(&args[0], &option)) 769 if (match_octal(&args[0], &option))
770 goto bad_val; 770 goto bad_val;
771 pconfig->mode = option & 0777U; 771 pconfig->mode = option & 01777U;
772 break; 772 break;
773 773
774 case Opt_size: { 774 case Opt_size: {
diff --git a/fs/inode.c b/fs/inode.c
index 276ffd6b6fdd..53245ffcf93d 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -928,8 +928,6 @@ EXPORT_SYMBOL(ilookup);
928 * @set: callback used to initialize a new struct inode 928 * @set: callback used to initialize a new struct inode
929 * @data: opaque data pointer to pass to @test and @set 929 * @data: opaque data pointer to pass to @test and @set
930 * 930 *
931 * This is iget() without the read_inode() portion of get_new_inode().
932 *
933 * iget5_locked() uses ifind() to search for the inode specified by @hashval 931 * iget5_locked() uses ifind() to search for the inode specified by @hashval
934 * and @data in the inode cache and if present it is returned with an increased 932 * and @data in the inode cache and if present it is returned with an increased
935 * reference count. This is a generalized version of iget_locked() for file 933 * reference count. This is a generalized version of iget_locked() for file
@@ -966,8 +964,6 @@ EXPORT_SYMBOL(iget5_locked);
966 * @sb: super block of file system 964 * @sb: super block of file system
967 * @ino: inode number to get 965 * @ino: inode number to get
968 * 966 *
969 * This is iget() without the read_inode() portion of get_new_inode_fast().
970 *
971 * iget_locked() uses ifind_fast() to search for the inode specified by @ino in 967 * iget_locked() uses ifind_fast() to search for the inode specified by @ino in
972 * the inode cache and if present it is returned with an increased reference 968 * the inode cache and if present it is returned with an increased reference
973 * count. This is for file systems where the inode number is sufficient for 969 * count. This is for file systems where the inode number is sufficient for
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/ioctl.c b/fs/ioctl.c
index c2a773e8620b..683002fefa55 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -12,12 +12,24 @@
12#include <linux/fs.h> 12#include <linux/fs.h>
13#include <linux/security.h> 13#include <linux/security.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/uaccess.h>
15 16
16#include <asm/uaccess.h>
17#include <asm/ioctls.h> 17#include <asm/ioctls.h>
18 18
19static long do_ioctl(struct file *filp, unsigned int cmd, 19/**
20 unsigned long arg) 20 * vfs_ioctl - call filesystem specific ioctl methods
21 * @filp: [in] open file to invoke ioctl method on
22 * @cmd: [in] ioctl command to execute
23 * @arg: [in/out] command-specific argument for ioctl
24 *
25 * Invokes filesystem specific ->unlocked_ioctl, if one exists; otherwise
26 * invokes * filesystem specific ->ioctl method. If neither method exists,
27 * returns -ENOTTY.
28 *
29 * Returns 0 on success, -errno on error.
30 */
31long vfs_ioctl(struct file *filp, unsigned int cmd,
32 unsigned long arg)
21{ 33{
22 int error = -ENOTTY; 34 int error = -ENOTTY;
23 35
@@ -40,123 +52,148 @@ static long do_ioctl(struct file *filp, unsigned int cmd,
40 return error; 52 return error;
41} 53}
42 54
55static int ioctl_fibmap(struct file *filp, int __user *p)
56{
57 struct address_space *mapping = filp->f_mapping;
58 int res, block;
59
60 /* do we support this mess? */
61 if (!mapping->a_ops->bmap)
62 return -EINVAL;
63 if (!capable(CAP_SYS_RAWIO))
64 return -EPERM;
65 res = get_user(block, p);
66 if (res)
67 return res;
68 lock_kernel();
69 res = mapping->a_ops->bmap(mapping, block);
70 unlock_kernel();
71 return put_user(res, p);
72}
73
43static int file_ioctl(struct file *filp, unsigned int cmd, 74static int file_ioctl(struct file *filp, unsigned int cmd,
44 unsigned long arg) 75 unsigned long arg)
45{ 76{
46 int error; 77 struct inode *inode = filp->f_path.dentry->d_inode;
47 int block;
48 struct inode * inode = filp->f_path.dentry->d_inode;
49 int __user *p = (int __user *)arg; 78 int __user *p = (int __user *)arg;
50 79
51 switch (cmd) { 80 switch (cmd) {
52 case FIBMAP: 81 case FIBMAP:
53 { 82 return ioctl_fibmap(filp, p);
54 struct address_space *mapping = filp->f_mapping; 83 case FIGETBSZ:
55 int res; 84 return put_user(inode->i_sb->s_blocksize, p);
56 /* do we support this mess? */ 85 case FIONREAD:
57 if (!mapping->a_ops->bmap) 86 return put_user(i_size_read(inode) - filp->f_pos, p);
58 return -EINVAL; 87 }
59 if (!capable(CAP_SYS_RAWIO))
60 return -EPERM;
61 if ((error = get_user(block, p)) != 0)
62 return error;
63 88
89 return vfs_ioctl(filp, cmd, arg);
90}
91
92static int ioctl_fionbio(struct file *filp, int __user *argp)
93{
94 unsigned int flag;
95 int on, error;
96
97 error = get_user(on, argp);
98 if (error)
99 return error;
100 flag = O_NONBLOCK;
101#ifdef __sparc__
102 /* SunOS compatibility item. */
103 if (O_NONBLOCK != O_NDELAY)
104 flag |= O_NDELAY;
105#endif
106 if (on)
107 filp->f_flags |= flag;
108 else
109 filp->f_flags &= ~flag;
110 return error;
111}
112
113static int ioctl_fioasync(unsigned int fd, struct file *filp,
114 int __user *argp)
115{
116 unsigned int flag;
117 int on, error;
118
119 error = get_user(on, argp);
120 if (error)
121 return error;
122 flag = on ? FASYNC : 0;
123
124 /* Did FASYNC state change ? */
125 if ((flag ^ filp->f_flags) & FASYNC) {
126 if (filp->f_op && filp->f_op->fasync) {
64 lock_kernel(); 127 lock_kernel();
65 res = mapping->a_ops->bmap(mapping, block); 128 error = filp->f_op->fasync(fd, filp, on);
66 unlock_kernel(); 129 unlock_kernel();
67 return put_user(res, p); 130 } else
68 } 131 error = -ENOTTY;
69 case FIGETBSZ:
70 return put_user(inode->i_sb->s_blocksize, p);
71 case FIONREAD:
72 return put_user(i_size_read(inode) - filp->f_pos, p);
73 } 132 }
133 if (error)
134 return error;
74 135
75 return do_ioctl(filp, cmd, arg); 136 if (on)
137 filp->f_flags |= FASYNC;
138 else
139 filp->f_flags &= ~FASYNC;
140 return error;
76} 141}
77 142
78/* 143/*
79 * When you add any new common ioctls to the switches above and below 144 * When you add any new common ioctls to the switches above and below
80 * please update compat_sys_ioctl() too. 145 * please update compat_sys_ioctl() too.
81 * 146 *
82 * vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d. 147 * do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
83 * It's just a simple helper for sys_ioctl and compat_sys_ioctl. 148 * It's just a simple helper for sys_ioctl and compat_sys_ioctl.
84 */ 149 */
85int vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, unsigned long arg) 150int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
151 unsigned long arg)
86{ 152{
87 unsigned int flag; 153 int error = 0;
88 int on, error = 0; 154 int __user *argp = (int __user *)arg;
89 155
90 switch (cmd) { 156 switch (cmd) {
91 case FIOCLEX: 157 case FIOCLEX:
92 set_close_on_exec(fd, 1); 158 set_close_on_exec(fd, 1);
93 break; 159 break;
94 160
95 case FIONCLEX: 161 case FIONCLEX:
96 set_close_on_exec(fd, 0); 162 set_close_on_exec(fd, 0);
97 break; 163 break;
98 164
99 case FIONBIO: 165 case FIONBIO:
100 if ((error = get_user(on, (int __user *)arg)) != 0) 166 error = ioctl_fionbio(filp, argp);
101 break; 167 break;
102 flag = O_NONBLOCK; 168
103#ifdef __sparc__ 169 case FIOASYNC:
104 /* SunOS compatibility item. */ 170 error = ioctl_fioasync(fd, filp, argp);
105 if(O_NONBLOCK != O_NDELAY) 171 break;
106 flag |= O_NDELAY; 172
107#endif 173 case FIOQSIZE:
108 if (on) 174 if (S_ISDIR(filp->f_path.dentry->d_inode->i_mode) ||
109 filp->f_flags |= flag; 175 S_ISREG(filp->f_path.dentry->d_inode->i_mode) ||
110 else 176 S_ISLNK(filp->f_path.dentry->d_inode->i_mode)) {
111 filp->f_flags &= ~flag; 177 loff_t res =
112 break; 178 inode_get_bytes(filp->f_path.dentry->d_inode);
113 179 error = copy_to_user((loff_t __user *)arg, &res,
114 case FIOASYNC: 180 sizeof(res)) ? -EFAULT : 0;
115 if ((error = get_user(on, (int __user *)arg)) != 0) 181 } else
116 break; 182 error = -ENOTTY;
117 flag = on ? FASYNC : 0; 183 break;
118 184 default:
119 /* Did FASYNC state change ? */ 185 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
120 if ((flag ^ filp->f_flags) & FASYNC) { 186 error = file_ioctl(filp, cmd, arg);
121 if (filp->f_op && filp->f_op->fasync) { 187 else
122 lock_kernel(); 188 error = vfs_ioctl(filp, cmd, arg);
123 error = filp->f_op->fasync(fd, filp, on); 189 break;
124 unlock_kernel();
125 }
126 else error = -ENOTTY;
127 }
128 if (error != 0)
129 break;
130
131 if (on)
132 filp->f_flags |= FASYNC;
133 else
134 filp->f_flags &= ~FASYNC;
135 break;
136
137 case FIOQSIZE:
138 if (S_ISDIR(filp->f_path.dentry->d_inode->i_mode) ||
139 S_ISREG(filp->f_path.dentry->d_inode->i_mode) ||
140 S_ISLNK(filp->f_path.dentry->d_inode->i_mode)) {
141 loff_t res = inode_get_bytes(filp->f_path.dentry->d_inode);
142 error = copy_to_user((loff_t __user *)arg, &res, sizeof(res)) ? -EFAULT : 0;
143 }
144 else
145 error = -ENOTTY;
146 break;
147 default:
148 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
149 error = file_ioctl(filp, cmd, arg);
150 else
151 error = do_ioctl(filp, cmd, arg);
152 break;
153 } 190 }
154 return error; 191 return error;
155} 192}
156 193
157asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) 194asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
158{ 195{
159 struct file * filp; 196 struct file *filp;
160 int error = -EBADF; 197 int error = -EBADF;
161 int fput_needed; 198 int fput_needed;
162 199
@@ -168,7 +205,7 @@ asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
168 if (error) 205 if (error)
169 goto out_fput; 206 goto out_fput;
170 207
171 error = vfs_ioctl(filp, fd, cmd, arg); 208 error = do_vfs_ioctl(filp, fd, cmd, arg);
172 out_fput: 209 out_fput:
173 fput_light(filp, fput_needed); 210 fput_light(filp, fput_needed);
174 out: 211 out:
diff --git a/fs/isofs/export.c b/fs/isofs/export.c
index 29f9753ae5e5..bb219138331a 100644
--- a/fs/isofs/export.c
+++ b/fs/isofs/export.c
@@ -26,11 +26,9 @@ isofs_export_iget(struct super_block *sb,
26 if (block == 0) 26 if (block == 0)
27 return ERR_PTR(-ESTALE); 27 return ERR_PTR(-ESTALE);
28 inode = isofs_iget(sb, block, offset); 28 inode = isofs_iget(sb, block, offset);
29 if (inode == NULL) 29 if (IS_ERR(inode))
30 return ERR_PTR(-ENOMEM); 30 return ERR_CAST(inode);
31 if (is_bad_inode(inode) 31 if (generation && inode->i_generation != generation) {
32 || (generation && inode->i_generation != generation))
33 {
34 iput(inode); 32 iput(inode);
35 return ERR_PTR(-ESTALE); 33 return ERR_PTR(-ESTALE);
36 } 34 }
@@ -110,8 +108,10 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
110 parent_inode = isofs_iget(child_inode->i_sb, 108 parent_inode = isofs_iget(child_inode->i_sb,
111 parent_block, 109 parent_block,
112 parent_offset); 110 parent_offset);
113 if (parent_inode == NULL) { 111 if (IS_ERR(parent_inode)) {
114 rv = ERR_PTR(-EACCES); 112 rv = ERR_CAST(parent_inode);
113 if (rv != ERR_PTR(-ENOMEM))
114 rv = ERR_PTR(-EACCES);
115 goto out; 115 goto out;
116 } 116 }
117 117
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index 09e3d306e96f..875d37fb6c70 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -54,7 +54,7 @@ static void isofs_put_super(struct super_block *sb)
54 return; 54 return;
55} 55}
56 56
57static void isofs_read_inode(struct inode *); 57static int isofs_read_inode(struct inode *);
58static int isofs_statfs (struct dentry *, struct kstatfs *); 58static int isofs_statfs (struct dentry *, struct kstatfs *);
59 59
60static struct kmem_cache *isofs_inode_cachep; 60static struct kmem_cache *isofs_inode_cachep;
@@ -107,7 +107,6 @@ static int isofs_remount(struct super_block *sb, int *flags, char *data)
107static const struct super_operations isofs_sops = { 107static const struct super_operations isofs_sops = {
108 .alloc_inode = isofs_alloc_inode, 108 .alloc_inode = isofs_alloc_inode,
109 .destroy_inode = isofs_destroy_inode, 109 .destroy_inode = isofs_destroy_inode,
110 .read_inode = isofs_read_inode,
111 .put_super = isofs_put_super, 110 .put_super = isofs_put_super,
112 .statfs = isofs_statfs, 111 .statfs = isofs_statfs,
113 .remount_fs = isofs_remount, 112 .remount_fs = isofs_remount,
@@ -552,7 +551,7 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
552 int joliet_level = 0; 551 int joliet_level = 0;
553 int iso_blknum, block; 552 int iso_blknum, block;
554 int orig_zonesize; 553 int orig_zonesize;
555 int table; 554 int table, error = -EINVAL;
556 unsigned int vol_desc_start; 555 unsigned int vol_desc_start;
557 556
558 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 557 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
@@ -810,6 +809,8 @@ root_found:
810 * we then decide whether to use the Joliet descriptor. 809 * we then decide whether to use the Joliet descriptor.
811 */ 810 */
812 inode = isofs_iget(s, sbi->s_firstdatazone, 0); 811 inode = isofs_iget(s, sbi->s_firstdatazone, 0);
812 if (IS_ERR(inode))
813 goto out_no_root;
813 814
814 /* 815 /*
815 * If this disk has both Rock Ridge and Joliet on it, then we 816 * If this disk has both Rock Ridge and Joliet on it, then we
@@ -829,6 +830,8 @@ root_found:
829 "ISOFS: changing to secondary root\n"); 830 "ISOFS: changing to secondary root\n");
830 iput(inode); 831 iput(inode);
831 inode = isofs_iget(s, sbi->s_firstdatazone, 0); 832 inode = isofs_iget(s, sbi->s_firstdatazone, 0);
833 if (IS_ERR(inode))
834 goto out_no_root;
832 } 835 }
833 } 836 }
834 837
@@ -842,8 +845,6 @@ root_found:
842 sbi->s_joliet_level = joliet_level; 845 sbi->s_joliet_level = joliet_level;
843 846
844 /* check the root inode */ 847 /* check the root inode */
845 if (!inode)
846 goto out_no_root;
847 if (!inode->i_op) 848 if (!inode->i_op)
848 goto out_bad_root; 849 goto out_bad_root;
849 850
@@ -876,11 +877,14 @@ root_found:
876 */ 877 */
877out_bad_root: 878out_bad_root:
878 printk(KERN_WARNING "%s: root inode not initialized\n", __func__); 879 printk(KERN_WARNING "%s: root inode not initialized\n", __func__);
879 goto out_iput;
880out_no_root:
881 printk(KERN_WARNING "%s: get root inode failed\n", __func__);
882out_iput: 880out_iput:
883 iput(inode); 881 iput(inode);
882 goto out_no_inode;
883out_no_root:
884 error = PTR_ERR(inode);
885 if (error != -ENOMEM)
886 printk(KERN_WARNING "%s: get root inode failed\n", __func__);
887out_no_inode:
884#ifdef CONFIG_JOLIET 888#ifdef CONFIG_JOLIET
885 if (sbi->s_nls_iocharset) 889 if (sbi->s_nls_iocharset)
886 unload_nls(sbi->s_nls_iocharset); 890 unload_nls(sbi->s_nls_iocharset);
@@ -908,7 +912,7 @@ out_freesbi:
908 kfree(opt.iocharset); 912 kfree(opt.iocharset);
909 kfree(sbi); 913 kfree(sbi);
910 s->s_fs_info = NULL; 914 s->s_fs_info = NULL;
911 return -EINVAL; 915 return error;
912} 916}
913 917
914static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf) 918static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf)
@@ -930,7 +934,7 @@ static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf)
930/* 934/*
931 * Get a set of blocks; filling in buffer_heads if already allocated 935 * Get a set of blocks; filling in buffer_heads if already allocated
932 * or getblk() if they are not. Returns the number of blocks inserted 936 * or getblk() if they are not. Returns the number of blocks inserted
933 * (0 == error.) 937 * (-ve == error.)
934 */ 938 */
935int isofs_get_blocks(struct inode *inode, sector_t iblock_s, 939int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
936 struct buffer_head **bh, unsigned long nblocks) 940 struct buffer_head **bh, unsigned long nblocks)
@@ -940,11 +944,12 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
940 unsigned int firstext; 944 unsigned int firstext;
941 unsigned long nextblk, nextoff; 945 unsigned long nextblk, nextoff;
942 long iblock = (long)iblock_s; 946 long iblock = (long)iblock_s;
943 int section, rv; 947 int section, rv, error;
944 struct iso_inode_info *ei = ISOFS_I(inode); 948 struct iso_inode_info *ei = ISOFS_I(inode);
945 949
946 lock_kernel(); 950 lock_kernel();
947 951
952 error = -EIO;
948 rv = 0; 953 rv = 0;
949 if (iblock < 0 || iblock != iblock_s) { 954 if (iblock < 0 || iblock != iblock_s) {
950 printk(KERN_DEBUG "%s: block number too large\n", __func__); 955 printk(KERN_DEBUG "%s: block number too large\n", __func__);
@@ -983,8 +988,10 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
983 988
984 offset += sect_size; 989 offset += sect_size;
985 ninode = isofs_iget(inode->i_sb, nextblk, nextoff); 990 ninode = isofs_iget(inode->i_sb, nextblk, nextoff);
986 if (!ninode) 991 if (IS_ERR(ninode)) {
992 error = PTR_ERR(ninode);
987 goto abort; 993 goto abort;
994 }
988 firstext = ISOFS_I(ninode)->i_first_extent; 995 firstext = ISOFS_I(ninode)->i_first_extent;
989 sect_size = ISOFS_I(ninode)->i_section_size >> ISOFS_BUFFER_BITS(ninode); 996 sect_size = ISOFS_I(ninode)->i_section_size >> ISOFS_BUFFER_BITS(ninode);
990 nextblk = ISOFS_I(ninode)->i_next_section_block; 997 nextblk = ISOFS_I(ninode)->i_next_section_block;
@@ -1015,9 +1022,10 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
1015 rv++; 1022 rv++;
1016 } 1023 }
1017 1024
1025 error = 0;
1018abort: 1026abort:
1019 unlock_kernel(); 1027 unlock_kernel();
1020 return rv; 1028 return rv != 0 ? rv : error;
1021} 1029}
1022 1030
1023/* 1031/*
@@ -1026,12 +1034,15 @@ abort:
1026static int isofs_get_block(struct inode *inode, sector_t iblock, 1034static int isofs_get_block(struct inode *inode, sector_t iblock,
1027 struct buffer_head *bh_result, int create) 1035 struct buffer_head *bh_result, int create)
1028{ 1036{
1037 int ret;
1038
1029 if (create) { 1039 if (create) {
1030 printk(KERN_DEBUG "%s: Kernel tries to allocate a block\n", __func__); 1040 printk(KERN_DEBUG "%s: Kernel tries to allocate a block\n", __func__);
1031 return -EROFS; 1041 return -EROFS;
1032 } 1042 }
1033 1043
1034 return isofs_get_blocks(inode, iblock, &bh_result, 1) ? 0 : -EIO; 1044 ret = isofs_get_blocks(inode, iblock, &bh_result, 1);
1045 return ret < 0 ? ret : 0;
1035} 1046}
1036 1047
1037static int isofs_bmap(struct inode *inode, sector_t block) 1048static int isofs_bmap(struct inode *inode, sector_t block)
@@ -1186,7 +1197,7 @@ out_toomany:
1186 goto out; 1197 goto out;
1187} 1198}
1188 1199
1189static void isofs_read_inode(struct inode *inode) 1200static int isofs_read_inode(struct inode *inode)
1190{ 1201{
1191 struct super_block *sb = inode->i_sb; 1202 struct super_block *sb = inode->i_sb;
1192 struct isofs_sb_info *sbi = ISOFS_SB(sb); 1203 struct isofs_sb_info *sbi = ISOFS_SB(sb);
@@ -1199,6 +1210,7 @@ static void isofs_read_inode(struct inode *inode)
1199 unsigned int de_len; 1210 unsigned int de_len;
1200 unsigned long offset; 1211 unsigned long offset;
1201 struct iso_inode_info *ei = ISOFS_I(inode); 1212 struct iso_inode_info *ei = ISOFS_I(inode);
1213 int ret = -EIO;
1202 1214
1203 block = ei->i_iget5_block; 1215 block = ei->i_iget5_block;
1204 bh = sb_bread(inode->i_sb, block); 1216 bh = sb_bread(inode->i_sb, block);
@@ -1216,6 +1228,7 @@ static void isofs_read_inode(struct inode *inode)
1216 tmpde = kmalloc(de_len, GFP_KERNEL); 1228 tmpde = kmalloc(de_len, GFP_KERNEL);
1217 if (tmpde == NULL) { 1229 if (tmpde == NULL) {
1218 printk(KERN_INFO "%s: out of memory\n", __func__); 1230 printk(KERN_INFO "%s: out of memory\n", __func__);
1231 ret = -ENOMEM;
1219 goto fail; 1232 goto fail;
1220 } 1233 }
1221 memcpy(tmpde, bh->b_data + offset, frag1); 1234 memcpy(tmpde, bh->b_data + offset, frag1);
@@ -1259,8 +1272,10 @@ static void isofs_read_inode(struct inode *inode)
1259 1272
1260 ei->i_section_size = isonum_733(de->size); 1273 ei->i_section_size = isonum_733(de->size);
1261 if (de->flags[-high_sierra] & 0x80) { 1274 if (de->flags[-high_sierra] & 0x80) {
1262 if(isofs_read_level3_size(inode)) 1275 ret = isofs_read_level3_size(inode);
1276 if (ret < 0)
1263 goto fail; 1277 goto fail;
1278 ret = -EIO;
1264 } else { 1279 } else {
1265 ei->i_next_section_block = 0; 1280 ei->i_next_section_block = 0;
1266 ei->i_next_section_offset = 0; 1281 ei->i_next_section_offset = 0;
@@ -1346,16 +1361,16 @@ static void isofs_read_inode(struct inode *inode)
1346 /* XXX - parse_rock_ridge_inode() had already set i_rdev. */ 1361 /* XXX - parse_rock_ridge_inode() had already set i_rdev. */
1347 init_special_inode(inode, inode->i_mode, inode->i_rdev); 1362 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1348 1363
1364 ret = 0;
1349out: 1365out:
1350 kfree(tmpde); 1366 kfree(tmpde);
1351 if (bh) 1367 if (bh)
1352 brelse(bh); 1368 brelse(bh);
1353 return; 1369 return ret;
1354 1370
1355out_badread: 1371out_badread:
1356 printk(KERN_WARNING "ISOFS: unable to read i-node block\n"); 1372 printk(KERN_WARNING "ISOFS: unable to read i-node block\n");
1357fail: 1373fail:
1358 make_bad_inode(inode);
1359 goto out; 1374 goto out;
1360} 1375}
1361 1376
@@ -1394,9 +1409,10 @@ struct inode *isofs_iget(struct super_block *sb,
1394 unsigned long hashval; 1409 unsigned long hashval;
1395 struct inode *inode; 1410 struct inode *inode;
1396 struct isofs_iget5_callback_data data; 1411 struct isofs_iget5_callback_data data;
1412 long ret;
1397 1413
1398 if (offset >= 1ul << sb->s_blocksize_bits) 1414 if (offset >= 1ul << sb->s_blocksize_bits)
1399 return NULL; 1415 return ERR_PTR(-EINVAL);
1400 1416
1401 data.block = block; 1417 data.block = block;
1402 data.offset = offset; 1418 data.offset = offset;
@@ -1406,9 +1422,17 @@ struct inode *isofs_iget(struct super_block *sb,
1406 inode = iget5_locked(sb, hashval, &isofs_iget5_test, 1422 inode = iget5_locked(sb, hashval, &isofs_iget5_test,
1407 &isofs_iget5_set, &data); 1423 &isofs_iget5_set, &data);
1408 1424
1409 if (inode && (inode->i_state & I_NEW)) { 1425 if (!inode)
1410 sb->s_op->read_inode(inode); 1426 return ERR_PTR(-ENOMEM);
1411 unlock_new_inode(inode); 1427
1428 if (inode->i_state & I_NEW) {
1429 ret = isofs_read_inode(inode);
1430 if (ret < 0) {
1431 iget_failed(inode);
1432 inode = ERR_PTR(ret);
1433 } else {
1434 unlock_new_inode(inode);
1435 }
1412 } 1436 }
1413 1437
1414 return inode; 1438 return inode;
diff --git a/fs/isofs/namei.c b/fs/isofs/namei.c
index e2b4dad39ca9..344b247bc29a 100644
--- a/fs/isofs/namei.c
+++ b/fs/isofs/namei.c
@@ -179,9 +179,9 @@ struct dentry *isofs_lookup(struct inode *dir, struct dentry *dentry, struct nam
179 inode = NULL; 179 inode = NULL;
180 if (found) { 180 if (found) {
181 inode = isofs_iget(dir->i_sb, block, offset); 181 inode = isofs_iget(dir->i_sb, block, offset);
182 if (!inode) { 182 if (IS_ERR(inode)) {
183 unlock_kernel(); 183 unlock_kernel();
184 return ERR_PTR(-EACCES); 184 return ERR_CAST(inode);
185 } 185 }
186 } 186 }
187 unlock_kernel(); 187 unlock_kernel();
diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
index f3a1db3098de..6bd48f0a7047 100644
--- a/fs/isofs/rock.c
+++ b/fs/isofs/rock.c
@@ -474,8 +474,10 @@ repeat:
474 isofs_iget(inode->i_sb, 474 isofs_iget(inode->i_sb,
475 ISOFS_I(inode)->i_first_extent, 475 ISOFS_I(inode)->i_first_extent,
476 0); 476 0);
477 if (!reloc) 477 if (IS_ERR(reloc)) {
478 ret = PTR_ERR(reloc);
478 goto out; 479 goto out;
480 }
479 inode->i_mode = reloc->i_mode; 481 inode->i_mode = reloc->i_mode;
480 inode->i_nlink = reloc->i_nlink; 482 inode->i_nlink = reloc->i_nlink;
481 inode->i_uid = reloc->i_uid; 483 inode->i_uid = reloc->i_uid;
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/jffs2/dir.c b/fs/jffs2/dir.c
index 787e392ffd41..f948f7e6ec82 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -101,10 +101,10 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
101 ino = fd->ino; 101 ino = fd->ino;
102 up(&dir_f->sem); 102 up(&dir_f->sem);
103 if (ino) { 103 if (ino) {
104 inode = iget(dir_i->i_sb, ino); 104 inode = jffs2_iget(dir_i->i_sb, ino);
105 if (!inode) { 105 if (IS_ERR(inode)) {
106 printk(KERN_WARNING "iget() failed for ino #%u\n", ino); 106 printk(KERN_WARNING "iget() failed for ino #%u\n", ino);
107 return (ERR_PTR(-EIO)); 107 return ERR_CAST(inode);
108 } 108 }
109 } 109 }
110 110
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index ee192af0b8b0..e26ea78c7892 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -226,16 +226,23 @@ void jffs2_clear_inode (struct inode *inode)
226 jffs2_do_clear_inode(c, f); 226 jffs2_do_clear_inode(c, f);
227} 227}
228 228
229void jffs2_read_inode (struct inode *inode) 229struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
230{ 230{
231 struct jffs2_inode_info *f; 231 struct jffs2_inode_info *f;
232 struct jffs2_sb_info *c; 232 struct jffs2_sb_info *c;
233 struct jffs2_raw_inode latest_node; 233 struct jffs2_raw_inode latest_node;
234 union jffs2_device_node jdev; 234 union jffs2_device_node jdev;
235 struct inode *inode;
235 dev_t rdev = 0; 236 dev_t rdev = 0;
236 int ret; 237 int ret;
237 238
238 D1(printk(KERN_DEBUG "jffs2_read_inode(): inode->i_ino == %lu\n", inode->i_ino)); 239 D1(printk(KERN_DEBUG "jffs2_iget(): ino == %lu\n", ino));
240
241 inode = iget_locked(sb, ino);
242 if (!inode)
243 return ERR_PTR(-ENOMEM);
244 if (!(inode->i_state & I_NEW))
245 return inode;
239 246
240 f = JFFS2_INODE_INFO(inode); 247 f = JFFS2_INODE_INFO(inode);
241 c = JFFS2_SB_INFO(inode->i_sb); 248 c = JFFS2_SB_INFO(inode->i_sb);
@@ -246,9 +253,9 @@ void jffs2_read_inode (struct inode *inode)
246 ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node); 253 ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node);
247 254
248 if (ret) { 255 if (ret) {
249 make_bad_inode(inode);
250 up(&f->sem); 256 up(&f->sem);
251 return; 257 iget_failed(inode);
258 return ERR_PTR(ret);
252 } 259 }
253 inode->i_mode = jemode_to_cpu(latest_node.mode); 260 inode->i_mode = jemode_to_cpu(latest_node.mode);
254 inode->i_uid = je16_to_cpu(latest_node.uid); 261 inode->i_uid = je16_to_cpu(latest_node.uid);
@@ -299,19 +306,14 @@ void jffs2_read_inode (struct inode *inode)
299 if (f->metadata->size != sizeof(jdev.old) && 306 if (f->metadata->size != sizeof(jdev.old) &&
300 f->metadata->size != sizeof(jdev.new)) { 307 f->metadata->size != sizeof(jdev.new)) {
301 printk(KERN_NOTICE "Device node has strange size %d\n", f->metadata->size); 308 printk(KERN_NOTICE "Device node has strange size %d\n", f->metadata->size);
302 up(&f->sem); 309 goto error_io;
303 jffs2_do_clear_inode(c, f);
304 make_bad_inode(inode);
305 return;
306 } 310 }
307 D1(printk(KERN_DEBUG "Reading device numbers from flash\n")); 311 D1(printk(KERN_DEBUG "Reading device numbers from flash\n"));
308 if (jffs2_read_dnode(c, f, f->metadata, (char *)&jdev, 0, f->metadata->size) < 0) { 312 ret = jffs2_read_dnode(c, f, f->metadata, (char *)&jdev, 0, f->metadata->size);
313 if (ret < 0) {
309 /* Eep */ 314 /* Eep */
310 printk(KERN_NOTICE "Read device numbers for inode %lu failed\n", (unsigned long)inode->i_ino); 315 printk(KERN_NOTICE "Read device numbers for inode %lu failed\n", (unsigned long)inode->i_ino);
311 up(&f->sem); 316 goto error;
312 jffs2_do_clear_inode(c, f);
313 make_bad_inode(inode);
314 return;
315 } 317 }
316 if (f->metadata->size == sizeof(jdev.old)) 318 if (f->metadata->size == sizeof(jdev.old))
317 rdev = old_decode_dev(je16_to_cpu(jdev.old)); 319 rdev = old_decode_dev(je16_to_cpu(jdev.old));
@@ -331,6 +333,16 @@ void jffs2_read_inode (struct inode *inode)
331 up(&f->sem); 333 up(&f->sem);
332 334
333 D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n")); 335 D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n"));
336 unlock_new_inode(inode);
337 return inode;
338
339error_io:
340 ret = -EIO;
341error:
342 up(&f->sem);
343 jffs2_do_clear_inode(c, f);
344 iget_failed(inode);
345 return ERR_PTR(ret);
334} 346}
335 347
336void jffs2_dirty_inode(struct inode *inode) 348void jffs2_dirty_inode(struct inode *inode)
@@ -518,15 +530,16 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
518 if ((ret = jffs2_do_mount_fs(c))) 530 if ((ret = jffs2_do_mount_fs(c)))
519 goto out_inohash; 531 goto out_inohash;
520 532
521 ret = -EINVAL;
522
523 D1(printk(KERN_DEBUG "jffs2_do_fill_super(): Getting root inode\n")); 533 D1(printk(KERN_DEBUG "jffs2_do_fill_super(): Getting root inode\n"));
524 root_i = iget(sb, 1); 534 root_i = jffs2_iget(sb, 1);
525 if (is_bad_inode(root_i)) { 535 if (IS_ERR(root_i)) {
526 D1(printk(KERN_WARNING "get root inode failed\n")); 536 D1(printk(KERN_WARNING "get root inode failed\n"));
527 goto out_root_i; 537 ret = PTR_ERR(root_i);
538 goto out_root;
528 } 539 }
529 540
541 ret = -ENOMEM;
542
530 D1(printk(KERN_DEBUG "jffs2_do_fill_super(): d_alloc_root()\n")); 543 D1(printk(KERN_DEBUG "jffs2_do_fill_super(): d_alloc_root()\n"));
531 sb->s_root = d_alloc_root(root_i); 544 sb->s_root = d_alloc_root(root_i);
532 if (!sb->s_root) 545 if (!sb->s_root)
@@ -542,6 +555,7 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
542 555
543 out_root_i: 556 out_root_i:
544 iput(root_i); 557 iput(root_i);
558out_root:
545 jffs2_free_ino_caches(c); 559 jffs2_free_ino_caches(c);
546 jffs2_free_raw_node_refs(c); 560 jffs2_free_raw_node_refs(c);
547 if (jffs2_blocks_use_vmalloc(c)) 561 if (jffs2_blocks_use_vmalloc(c))
@@ -611,9 +625,9 @@ struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
611 jffs2_do_unlink() would need the alloc_sem and we have it. 625 jffs2_do_unlink() would need the alloc_sem and we have it.
612 Just iget() it, and if read_inode() is necessary that's OK. 626 Just iget() it, and if read_inode() is necessary that's OK.
613 */ 627 */
614 inode = iget(OFNI_BS_2SFFJ(c), inum); 628 inode = jffs2_iget(OFNI_BS_2SFFJ(c), inum);
615 if (!inode) 629 if (IS_ERR(inode))
616 return ERR_PTR(-ENOMEM); 630 return ERR_CAST(inode);
617 } 631 }
618 if (is_bad_inode(inode)) { 632 if (is_bad_inode(inode)) {
619 printk(KERN_NOTICE "Eep. read_inode() failed for ino #%u. nlink %d\n", 633 printk(KERN_NOTICE "Eep. read_inode() failed for ino #%u. nlink %d\n",
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
index bf64686cf098..1b10d2594092 100644
--- a/fs/jffs2/os-linux.h
+++ b/fs/jffs2/os-linux.h
@@ -175,7 +175,7 @@ extern const struct inode_operations jffs2_symlink_inode_operations;
175/* fs.c */ 175/* fs.c */
176int jffs2_setattr (struct dentry *, struct iattr *); 176int jffs2_setattr (struct dentry *, struct iattr *);
177int jffs2_do_setattr (struct inode *, struct iattr *); 177int jffs2_do_setattr (struct inode *, struct iattr *);
178void jffs2_read_inode (struct inode *); 178struct inode *jffs2_iget(struct super_block *, unsigned long);
179void jffs2_clear_inode (struct inode *); 179void jffs2_clear_inode (struct inode *);
180void jffs2_dirty_inode(struct inode *inode); 180void jffs2_dirty_inode(struct inode *inode);
181struct inode *jffs2_new_inode (struct inode *dir_i, int mode, 181struct inode *jffs2_new_inode (struct inode *dir_i, int mode,
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index fb89ab5e1d50..e512a93d6249 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -742,7 +742,7 @@ static inline int read_dnode(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
742 * are not obsolete. 742 * are not obsolete.
743 * 743 *
744 * Of course, this optimization only makes sense in case 744 * Of course, this optimization only makes sense in case
745 * of NAND flashes (or other flashes whith 745 * of NAND flashes (or other flashes with
746 * !jffs2_can_mark_obsolete()), since on NOR flashes 746 * !jffs2_can_mark_obsolete()), since on NOR flashes
747 * nodes are marked obsolete physically. 747 * nodes are marked obsolete physically.
748 * 748 *
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index ffa447511e6a..4677355996cc 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -65,7 +65,6 @@ static const struct super_operations jffs2_super_operations =
65{ 65{
66 .alloc_inode = jffs2_alloc_inode, 66 .alloc_inode = jffs2_alloc_inode,
67 .destroy_inode =jffs2_destroy_inode, 67 .destroy_inode =jffs2_destroy_inode,
68 .read_inode = jffs2_read_inode,
69 .put_super = jffs2_put_super, 68 .put_super = jffs2_put_super,
70 .write_super = jffs2_write_super, 69 .write_super = jffs2_write_super,
71 .statfs = jffs2_statfs, 70 .statfs = jffs2_statfs,
diff --git a/fs/jffs2/write.c b/fs/jffs2/write.c
index ecdf18d0486f..776f13cbf2b5 100644
--- a/fs/jffs2/write.c
+++ b/fs/jffs2/write.c
@@ -177,7 +177,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
177 void *hold_err = fn->raw; 177 void *hold_err = fn->raw;
178 /* Release the full_dnode which is now useless, and return */ 178 /* Release the full_dnode which is now useless, and return */
179 jffs2_free_full_dnode(fn); 179 jffs2_free_full_dnode(fn);
180 return ERR_PTR(PTR_ERR(hold_err)); 180 return ERR_CAST(hold_err);
181 } 181 }
182 fn->ofs = je32_to_cpu(ri->offset); 182 fn->ofs = je32_to_cpu(ri->offset);
183 fn->size = je32_to_cpu(ri->dsize); 183 fn->size = je32_to_cpu(ri->dsize);
@@ -313,7 +313,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
313 void *hold_err = fd->raw; 313 void *hold_err = fd->raw;
314 /* Release the full_dirent which is now useless, and return */ 314 /* Release the full_dirent which is now useless, and return */
315 jffs2_free_full_dirent(fd); 315 jffs2_free_full_dirent(fd);
316 return ERR_PTR(PTR_ERR(hold_err)); 316 return ERR_CAST(hold_err);
317 } 317 }
318 318
319 if (retried) { 319 if (retried) {
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index 4672013802e1..210339784b56 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -31,11 +31,21 @@
31#include "jfs_debug.h" 31#include "jfs_debug.h"
32 32
33 33
34void jfs_read_inode(struct inode *inode) 34struct inode *jfs_iget(struct super_block *sb, unsigned long ino)
35{ 35{
36 if (diRead(inode)) { 36 struct inode *inode;
37 make_bad_inode(inode); 37 int ret;
38 return; 38
39 inode = iget_locked(sb, ino);
40 if (!inode)
41 return ERR_PTR(-ENOMEM);
42 if (!(inode->i_state & I_NEW))
43 return inode;
44
45 ret = diRead(inode);
46 if (ret < 0) {
47 iget_failed(inode);
48 return ERR_PTR(ret);
39 } 49 }
40 50
41 if (S_ISREG(inode->i_mode)) { 51 if (S_ISREG(inode->i_mode)) {
@@ -55,6 +65,8 @@ void jfs_read_inode(struct inode *inode)
55 inode->i_op = &jfs_file_inode_operations; 65 inode->i_op = &jfs_file_inode_operations;
56 init_special_inode(inode, inode->i_mode, inode->i_rdev); 66 init_special_inode(inode, inode->i_mode, inode->i_rdev);
57 } 67 }
68 unlock_new_inode(inode);
69 return inode;
58} 70}
59 71
60/* 72/*
diff --git a/fs/jfs/jfs_inode.h b/fs/jfs/jfs_inode.h
index 8e2cf2cde185..95a6a11425e5 100644
--- a/fs/jfs/jfs_inode.h
+++ b/fs/jfs/jfs_inode.h
@@ -24,7 +24,7 @@ extern struct inode *ialloc(struct inode *, umode_t);
24extern int jfs_fsync(struct file *, struct dentry *, int); 24extern int jfs_fsync(struct file *, struct dentry *, int);
25extern int jfs_ioctl(struct inode *, struct file *, 25extern int jfs_ioctl(struct inode *, struct file *,
26 unsigned int, unsigned long); 26 unsigned int, unsigned long);
27extern void jfs_read_inode(struct inode *); 27extern struct inode *jfs_iget(struct super_block *, unsigned long);
28extern int jfs_commit_inode(struct inode *, int); 28extern int jfs_commit_inode(struct inode *, int);
29extern int jfs_write_inode(struct inode*, int); 29extern int jfs_write_inode(struct inode*, int);
30extern void jfs_delete_inode(struct inode *); 30extern void jfs_delete_inode(struct inode *);
diff --git a/fs/jfs/jfs_xtree.c b/fs/jfs/jfs_xtree.c
index 1543906a2e0d..a000aaa75136 100644
--- a/fs/jfs/jfs_xtree.c
+++ b/fs/jfs/jfs_xtree.c
@@ -3965,7 +3965,7 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
3965 * xtTruncate_pmap() 3965 * xtTruncate_pmap()
3966 * 3966 *
3967 * function: 3967 * function:
3968 * Perform truncate to zero lenghth for deleted file, leaving the 3968 * Perform truncate to zero length for deleted file, leaving the
3969 * the xtree and working map untouched. This allows the file to 3969 * the xtree and working map untouched. This allows the file to
3970 * be accessed via open file handles, while the delete of the file 3970 * be accessed via open file handles, while the delete of the file
3971 * is committed to disk. 3971 * is committed to disk.
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index f8718de3505e..403cfc24c6fe 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -1462,12 +1462,10 @@ static struct dentry *jfs_lookup(struct inode *dip, struct dentry *dentry, struc
1462 } 1462 }
1463 } 1463 }
1464 1464
1465 ip = iget(dip->i_sb, inum); 1465 ip = jfs_iget(dip->i_sb, inum);
1466 if (ip == NULL || is_bad_inode(ip)) { 1466 if (IS_ERR(ip)) {
1467 jfs_err("jfs_lookup: iget failed on inum %d", (uint) inum); 1467 jfs_err("jfs_lookup: iget failed on inum %d", (uint) inum);
1468 if (ip) 1468 return ERR_CAST(ip);
1469 iput(ip);
1470 return ERR_PTR(-EACCES);
1471 } 1469 }
1472 1470
1473 dentry = d_splice_alias(ip, dentry); 1471 dentry = d_splice_alias(ip, dentry);
@@ -1485,12 +1483,11 @@ static struct inode *jfs_nfs_get_inode(struct super_block *sb,
1485 1483
1486 if (ino == 0) 1484 if (ino == 0)
1487 return ERR_PTR(-ESTALE); 1485 return ERR_PTR(-ESTALE);
1488 inode = iget(sb, ino); 1486 inode = jfs_iget(sb, ino);
1489 if (inode == NULL) 1487 if (IS_ERR(inode))
1490 return ERR_PTR(-ENOMEM); 1488 return ERR_CAST(inode);
1491 1489
1492 if (is_bad_inode(inode) || 1490 if (generation && inode->i_generation != generation) {
1493 (generation && inode->i_generation != generation)) {
1494 iput(inode); 1491 iput(inode);
1495 return ERR_PTR(-ESTALE); 1492 return ERR_PTR(-ESTALE);
1496 } 1493 }
@@ -1521,17 +1518,14 @@ struct dentry *jfs_get_parent(struct dentry *dentry)
1521 1518
1522 parent_ino = 1519 parent_ino =
1523 le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot); 1520 le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot);
1524 inode = iget(sb, parent_ino); 1521 inode = jfs_iget(sb, parent_ino);
1525 if (inode) { 1522 if (IS_ERR(inode)) {
1526 if (is_bad_inode(inode)) { 1523 parent = ERR_CAST(inode);
1524 } else {
1525 parent = d_alloc_anon(inode);
1526 if (!parent) {
1527 parent = ERR_PTR(-ENOMEM);
1527 iput(inode); 1528 iput(inode);
1528 parent = ERR_PTR(-EACCES);
1529 } else {
1530 parent = d_alloc_anon(inode);
1531 if (!parent) {
1532 parent = ERR_PTR(-ENOMEM);
1533 iput(inode);
1534 }
1535 } 1529 }
1536 } 1530 }
1537 1531
diff --git a/fs/jfs/super.c b/fs/jfs/super.c
index 70a14001c98f..50ea65451732 100644
--- a/fs/jfs/super.c
+++ b/fs/jfs/super.c
@@ -414,7 +414,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
414 struct inode *inode; 414 struct inode *inode;
415 int rc; 415 int rc;
416 s64 newLVSize = 0; 416 s64 newLVSize = 0;
417 int flag; 417 int flag, ret = -EINVAL;
418 418
419 jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags); 419 jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
420 420
@@ -461,8 +461,10 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
461 * Initialize direct-mapping inode/address-space 461 * Initialize direct-mapping inode/address-space
462 */ 462 */
463 inode = new_inode(sb); 463 inode = new_inode(sb);
464 if (inode == NULL) 464 if (inode == NULL) {
465 ret = -ENOMEM;
465 goto out_kfree; 466 goto out_kfree;
467 }
466 inode->i_ino = 0; 468 inode->i_ino = 0;
467 inode->i_nlink = 1; 469 inode->i_nlink = 1;
468 inode->i_size = sb->s_bdev->bd_inode->i_size; 470 inode->i_size = sb->s_bdev->bd_inode->i_size;
@@ -494,9 +496,11 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
494 496
495 sb->s_magic = JFS_SUPER_MAGIC; 497 sb->s_magic = JFS_SUPER_MAGIC;
496 498
497 inode = iget(sb, ROOT_I); 499 inode = jfs_iget(sb, ROOT_I);
498 if (!inode || is_bad_inode(inode)) 500 if (IS_ERR(inode)) {
501 ret = PTR_ERR(inode);
499 goto out_no_root; 502 goto out_no_root;
503 }
500 sb->s_root = d_alloc_root(inode); 504 sb->s_root = d_alloc_root(inode);
501 if (!sb->s_root) 505 if (!sb->s_root)
502 goto out_no_root; 506 goto out_no_root;
@@ -536,7 +540,7 @@ out_kfree:
536 if (sbi->nls_tab) 540 if (sbi->nls_tab)
537 unload_nls(sbi->nls_tab); 541 unload_nls(sbi->nls_tab);
538 kfree(sbi); 542 kfree(sbi);
539 return -EINVAL; 543 return ret;
540} 544}
541 545
542static void jfs_write_super_lockfs(struct super_block *sb) 546static void jfs_write_super_lockfs(struct super_block *sb)
@@ -726,7 +730,6 @@ out:
726static const struct super_operations jfs_super_operations = { 730static const struct super_operations jfs_super_operations = {
727 .alloc_inode = jfs_alloc_inode, 731 .alloc_inode = jfs_alloc_inode,
728 .destroy_inode = jfs_destroy_inode, 732 .destroy_inode = jfs_destroy_inode,
729 .read_inode = jfs_read_inode,
730 .dirty_inode = jfs_dirty_inode, 733 .dirty_inode = jfs_dirty_inode,
731 .write_inode = jfs_write_inode, 734 .write_inode = jfs_write_inode,
732 .delete_inode = jfs_delete_inode, 735 .delete_inode = jfs_delete_inode,
diff --git a/fs/libfs.c b/fs/libfs.c
index 6e68b700958d..5523bde96387 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -341,13 +341,10 @@ int simple_prepare_write(struct file *file, struct page *page,
341 unsigned from, unsigned to) 341 unsigned from, unsigned to)
342{ 342{
343 if (!PageUptodate(page)) { 343 if (!PageUptodate(page)) {
344 if (to - from != PAGE_CACHE_SIZE) { 344 if (to - from != PAGE_CACHE_SIZE)
345 void *kaddr = kmap_atomic(page, KM_USER0); 345 zero_user_segments(page,
346 memset(kaddr, 0, from); 346 0, from,
347 memset(kaddr + to, 0, PAGE_CACHE_SIZE - to); 347 to, PAGE_CACHE_SIZE);
348 flush_dcache_page(page);
349 kunmap_atomic(kaddr, KM_USER0);
350 }
351 } 348 }
352 return 0; 349 return 0;
353} 350}
diff --git a/fs/locks.c b/fs/locks.c
index 8b8388eca05e..49354b9c7dc1 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -125,6 +125,7 @@
125#include <linux/syscalls.h> 125#include <linux/syscalls.h>
126#include <linux/time.h> 126#include <linux/time.h>
127#include <linux/rcupdate.h> 127#include <linux/rcupdate.h>
128#include <linux/pid_namespace.h>
128 129
129#include <asm/semaphore.h> 130#include <asm/semaphore.h>
130#include <asm/uaccess.h> 131#include <asm/uaccess.h>
@@ -185,6 +186,7 @@ void locks_init_lock(struct file_lock *fl)
185 fl->fl_fasync = NULL; 186 fl->fl_fasync = NULL;
186 fl->fl_owner = NULL; 187 fl->fl_owner = NULL;
187 fl->fl_pid = 0; 188 fl->fl_pid = 0;
189 fl->fl_nspid = NULL;
188 fl->fl_file = NULL; 190 fl->fl_file = NULL;
189 fl->fl_flags = 0; 191 fl->fl_flags = 0;
190 fl->fl_type = 0; 192 fl->fl_type = 0;
@@ -553,6 +555,8 @@ static void locks_insert_lock(struct file_lock **pos, struct file_lock *fl)
553{ 555{
554 list_add(&fl->fl_link, &file_lock_list); 556 list_add(&fl->fl_link, &file_lock_list);
555 557
558 fl->fl_nspid = get_pid(task_tgid(current));
559
556 /* insert into file's list */ 560 /* insert into file's list */
557 fl->fl_next = *pos; 561 fl->fl_next = *pos;
558 *pos = fl; 562 *pos = fl;
@@ -584,6 +588,11 @@ static void locks_delete_lock(struct file_lock **thisfl_p)
584 if (fl->fl_ops && fl->fl_ops->fl_remove) 588 if (fl->fl_ops && fl->fl_ops->fl_remove)
585 fl->fl_ops->fl_remove(fl); 589 fl->fl_ops->fl_remove(fl);
586 590
591 if (fl->fl_nspid) {
592 put_pid(fl->fl_nspid);
593 fl->fl_nspid = NULL;
594 }
595
587 locks_wake_up_blocks(fl); 596 locks_wake_up_blocks(fl);
588 locks_free_lock(fl); 597 locks_free_lock(fl);
589} 598}
@@ -634,33 +643,6 @@ static int flock_locks_conflict(struct file_lock *caller_fl, struct file_lock *s
634 return (locks_conflict(caller_fl, sys_fl)); 643 return (locks_conflict(caller_fl, sys_fl));
635} 644}
636 645
637static int interruptible_sleep_on_locked(wait_queue_head_t *fl_wait, int timeout)
638{
639 int result = 0;
640 DECLARE_WAITQUEUE(wait, current);
641
642 __set_current_state(TASK_INTERRUPTIBLE);
643 add_wait_queue(fl_wait, &wait);
644 if (timeout == 0)
645 schedule();
646 else
647 result = schedule_timeout(timeout);
648 if (signal_pending(current))
649 result = -ERESTARTSYS;
650 remove_wait_queue(fl_wait, &wait);
651 __set_current_state(TASK_RUNNING);
652 return result;
653}
654
655static int locks_block_on_timeout(struct file_lock *blocker, struct file_lock *waiter, int time)
656{
657 int result;
658 locks_insert_block(blocker, waiter);
659 result = interruptible_sleep_on_locked(&waiter->fl_wait, time);
660 __locks_delete_block(waiter);
661 return result;
662}
663
664void 646void
665posix_test_lock(struct file *filp, struct file_lock *fl) 647posix_test_lock(struct file *filp, struct file_lock *fl)
666{ 648{
@@ -673,55 +655,67 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
673 if (posix_locks_conflict(fl, cfl)) 655 if (posix_locks_conflict(fl, cfl))
674 break; 656 break;
675 } 657 }
676 if (cfl) 658 if (cfl) {
677 __locks_copy_lock(fl, cfl); 659 __locks_copy_lock(fl, cfl);
678 else 660 if (cfl->fl_nspid)
661 fl->fl_pid = pid_nr_ns(cfl->fl_nspid,
662 task_active_pid_ns(current));
663 } else
679 fl->fl_type = F_UNLCK; 664 fl->fl_type = F_UNLCK;
680 unlock_kernel(); 665 unlock_kernel();
681 return; 666 return;
682} 667}
683
684EXPORT_SYMBOL(posix_test_lock); 668EXPORT_SYMBOL(posix_test_lock);
685 669
686/* This function tests for deadlock condition before putting a process to 670/*
687 * sleep. The detection scheme is no longer recursive. Recursive was neat, 671 * Deadlock detection:
688 * but dangerous - we risked stack corruption if the lock data was bad, or 672 *
689 * if the recursion was too deep for any other reason. 673 * We attempt to detect deadlocks that are due purely to posix file
674 * locks.
690 * 675 *
691 * We rely on the fact that a task can only be on one lock's wait queue 676 * We assume that a task can be waiting for at most one lock at a time.
692 * at a time. When we find blocked_task on a wait queue we can re-search 677 * So for any acquired lock, the process holding that lock may be
693 * with blocked_task equal to that queue's owner, until either blocked_task 678 * waiting on at most one other lock. That lock in turns may be held by
694 * isn't found, or blocked_task is found on a queue owned by my_task. 679 * someone waiting for at most one other lock. Given a requested lock
680 * caller_fl which is about to wait for a conflicting lock block_fl, we
681 * follow this chain of waiters to ensure we are not about to create a
682 * cycle.
695 * 683 *
696 * Note: the above assumption may not be true when handling lock requests 684 * Since we do this before we ever put a process to sleep on a lock, we
697 * from a broken NFS client. But broken NFS clients have a lot more to 685 * are ensured that there is never a cycle; that is what guarantees that
698 * worry about than proper deadlock detection anyway... --okir 686 * the while() loop in posix_locks_deadlock() eventually completes.
699 * 687 *
700 * However, the failure of this assumption (also possible in the case of 688 * Note: the above assumption may not be true when handling lock
701 * multiple tasks sharing the same open file table) also means there's no 689 * requests from a broken NFS client. It may also fail in the presence
702 * guarantee that the loop below will terminate. As a hack, we give up 690 * of tasks (such as posix threads) sharing the same open file table.
703 * after a few iterations. 691 *
692 * To handle those cases, we just bail out after a few iterations.
704 */ 693 */
705 694
706#define MAX_DEADLK_ITERATIONS 10 695#define MAX_DEADLK_ITERATIONS 10
707 696
697/* Find a lock that the owner of the given block_fl is blocking on. */
698static struct file_lock *what_owner_is_waiting_for(struct file_lock *block_fl)
699{
700 struct file_lock *fl;
701
702 list_for_each_entry(fl, &blocked_list, fl_link) {
703 if (posix_same_owner(fl, block_fl))
704 return fl->fl_next;
705 }
706 return NULL;
707}
708
708static int posix_locks_deadlock(struct file_lock *caller_fl, 709static int posix_locks_deadlock(struct file_lock *caller_fl,
709 struct file_lock *block_fl) 710 struct file_lock *block_fl)
710{ 711{
711 struct file_lock *fl;
712 int i = 0; 712 int i = 0;
713 713
714next_task: 714 while ((block_fl = what_owner_is_waiting_for(block_fl))) {
715 if (posix_same_owner(caller_fl, block_fl)) 715 if (i++ > MAX_DEADLK_ITERATIONS)
716 return 1; 716 return 0;
717 list_for_each_entry(fl, &blocked_list, fl_link) { 717 if (posix_same_owner(caller_fl, block_fl))
718 if (posix_same_owner(fl, block_fl)) { 718 return 1;
719 if (i++ > MAX_DEADLK_ITERATIONS)
720 return 0;
721 fl = fl->fl_next;
722 block_fl = fl;
723 goto next_task;
724 }
725 } 719 }
726 return 0; 720 return 0;
727} 721}
@@ -1256,7 +1250,10 @@ restart:
1256 if (break_time == 0) 1250 if (break_time == 0)
1257 break_time++; 1251 break_time++;
1258 } 1252 }
1259 error = locks_block_on_timeout(flock, new_fl, break_time); 1253 locks_insert_block(flock, new_fl);
1254 error = wait_event_interruptible_timeout(new_fl->fl_wait,
1255 !new_fl->fl_next, break_time);
1256 __locks_delete_block(new_fl);
1260 if (error >= 0) { 1257 if (error >= 0) {
1261 if (error == 0) 1258 if (error == 0)
1262 time_out_leases(inode); 1259 time_out_leases(inode);
@@ -2084,6 +2081,12 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
2084 int id, char *pfx) 2081 int id, char *pfx)
2085{ 2082{
2086 struct inode *inode = NULL; 2083 struct inode *inode = NULL;
2084 unsigned int fl_pid;
2085
2086 if (fl->fl_nspid)
2087 fl_pid = pid_nr_ns(fl->fl_nspid, task_active_pid_ns(current));
2088 else
2089 fl_pid = fl->fl_pid;
2087 2090
2088 if (fl->fl_file != NULL) 2091 if (fl->fl_file != NULL)
2089 inode = fl->fl_file->f_path.dentry->d_inode; 2092 inode = fl->fl_file->f_path.dentry->d_inode;
@@ -2124,16 +2127,16 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
2124 } 2127 }
2125 if (inode) { 2128 if (inode) {
2126#ifdef WE_CAN_BREAK_LSLK_NOW 2129#ifdef WE_CAN_BREAK_LSLK_NOW
2127 seq_printf(f, "%d %s:%ld ", fl->fl_pid, 2130 seq_printf(f, "%d %s:%ld ", fl_pid,
2128 inode->i_sb->s_id, inode->i_ino); 2131 inode->i_sb->s_id, inode->i_ino);
2129#else 2132#else
2130 /* userspace relies on this representation of dev_t ;-( */ 2133 /* userspace relies on this representation of dev_t ;-( */
2131 seq_printf(f, "%d %02x:%02x:%ld ", fl->fl_pid, 2134 seq_printf(f, "%d %02x:%02x:%ld ", fl_pid,
2132 MAJOR(inode->i_sb->s_dev), 2135 MAJOR(inode->i_sb->s_dev),
2133 MINOR(inode->i_sb->s_dev), inode->i_ino); 2136 MINOR(inode->i_sb->s_dev), inode->i_ino);
2134#endif 2137#endif
2135 } else { 2138 } else {
2136 seq_printf(f, "%d <none>:0 ", fl->fl_pid); 2139 seq_printf(f, "%d <none>:0 ", fl_pid);
2137 } 2140 }
2138 if (IS_POSIX(fl)) { 2141 if (IS_POSIX(fl)) {
2139 if (fl->fl_end == OFFSET_MAX) 2142 if (fl->fl_end == OFFSET_MAX)
diff --git a/fs/minix/inode.c b/fs/minix/inode.c
index bf4cd316af81..84f6242ba6fc 100644
--- a/fs/minix/inode.c
+++ b/fs/minix/inode.c
@@ -18,7 +18,6 @@
18#include <linux/highuid.h> 18#include <linux/highuid.h>
19#include <linux/vfs.h> 19#include <linux/vfs.h>
20 20
21static void minix_read_inode(struct inode * inode);
22static int minix_write_inode(struct inode * inode, int wait); 21static int minix_write_inode(struct inode * inode, int wait);
23static int minix_statfs(struct dentry *dentry, struct kstatfs *buf); 22static int minix_statfs(struct dentry *dentry, struct kstatfs *buf);
24static int minix_remount (struct super_block * sb, int * flags, char * data); 23static int minix_remount (struct super_block * sb, int * flags, char * data);
@@ -96,7 +95,6 @@ static void destroy_inodecache(void)
96static const struct super_operations minix_sops = { 95static const struct super_operations minix_sops = {
97 .alloc_inode = minix_alloc_inode, 96 .alloc_inode = minix_alloc_inode,
98 .destroy_inode = minix_destroy_inode, 97 .destroy_inode = minix_destroy_inode,
99 .read_inode = minix_read_inode,
100 .write_inode = minix_write_inode, 98 .write_inode = minix_write_inode,
101 .delete_inode = minix_delete_inode, 99 .delete_inode = minix_delete_inode,
102 .put_super = minix_put_super, 100 .put_super = minix_put_super,
@@ -149,6 +147,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
149 unsigned long i, block; 147 unsigned long i, block;
150 struct inode *root_inode; 148 struct inode *root_inode;
151 struct minix_sb_info *sbi; 149 struct minix_sb_info *sbi;
150 int ret = -EINVAL;
152 151
153 sbi = kzalloc(sizeof(struct minix_sb_info), GFP_KERNEL); 152 sbi = kzalloc(sizeof(struct minix_sb_info), GFP_KERNEL);
154 if (!sbi) 153 if (!sbi)
@@ -246,10 +245,13 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
246 245
247 /* set up enough so that it can read an inode */ 246 /* set up enough so that it can read an inode */
248 s->s_op = &minix_sops; 247 s->s_op = &minix_sops;
249 root_inode = iget(s, MINIX_ROOT_INO); 248 root_inode = minix_iget(s, MINIX_ROOT_INO);
250 if (!root_inode || is_bad_inode(root_inode)) 249 if (IS_ERR(root_inode)) {
250 ret = PTR_ERR(root_inode);
251 goto out_no_root; 251 goto out_no_root;
252 }
252 253
254 ret = -ENOMEM;
253 s->s_root = d_alloc_root(root_inode); 255 s->s_root = d_alloc_root(root_inode);
254 if (!s->s_root) 256 if (!s->s_root)
255 goto out_iput; 257 goto out_iput;
@@ -290,6 +292,7 @@ out_freemap:
290 goto out_release; 292 goto out_release;
291 293
292out_no_map: 294out_no_map:
295 ret = -ENOMEM;
293 if (!silent) 296 if (!silent)
294 printk("MINIX-fs: can't allocate map\n"); 297 printk("MINIX-fs: can't allocate map\n");
295 goto out_release; 298 goto out_release;
@@ -316,7 +319,7 @@ out_bad_sb:
316out: 319out:
317 s->s_fs_info = NULL; 320 s->s_fs_info = NULL;
318 kfree(sbi); 321 kfree(sbi);
319 return -EINVAL; 322 return ret;
320} 323}
321 324
322static int minix_statfs(struct dentry *dentry, struct kstatfs *buf) 325static int minix_statfs(struct dentry *dentry, struct kstatfs *buf)
@@ -409,7 +412,7 @@ void minix_set_inode(struct inode *inode, dev_t rdev)
409/* 412/*
410 * The minix V1 function to read an inode. 413 * The minix V1 function to read an inode.
411 */ 414 */
412static void V1_minix_read_inode(struct inode * inode) 415static struct inode *V1_minix_iget(struct inode *inode)
413{ 416{
414 struct buffer_head * bh; 417 struct buffer_head * bh;
415 struct minix_inode * raw_inode; 418 struct minix_inode * raw_inode;
@@ -418,8 +421,8 @@ static void V1_minix_read_inode(struct inode * inode)
418 421
419 raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh); 422 raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
420 if (!raw_inode) { 423 if (!raw_inode) {
421 make_bad_inode(inode); 424 iget_failed(inode);
422 return; 425 return ERR_PTR(-EIO);
423 } 426 }
424 inode->i_mode = raw_inode->i_mode; 427 inode->i_mode = raw_inode->i_mode;
425 inode->i_uid = (uid_t)raw_inode->i_uid; 428 inode->i_uid = (uid_t)raw_inode->i_uid;
@@ -435,12 +438,14 @@ static void V1_minix_read_inode(struct inode * inode)
435 minix_inode->u.i1_data[i] = raw_inode->i_zone[i]; 438 minix_inode->u.i1_data[i] = raw_inode->i_zone[i];
436 minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0])); 439 minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
437 brelse(bh); 440 brelse(bh);
441 unlock_new_inode(inode);
442 return inode;
438} 443}
439 444
440/* 445/*
441 * The minix V2 function to read an inode. 446 * The minix V2 function to read an inode.
442 */ 447 */
443static void V2_minix_read_inode(struct inode * inode) 448static struct inode *V2_minix_iget(struct inode *inode)
444{ 449{
445 struct buffer_head * bh; 450 struct buffer_head * bh;
446 struct minix2_inode * raw_inode; 451 struct minix2_inode * raw_inode;
@@ -449,8 +454,8 @@ static void V2_minix_read_inode(struct inode * inode)
449 454
450 raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh); 455 raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
451 if (!raw_inode) { 456 if (!raw_inode) {
452 make_bad_inode(inode); 457 iget_failed(inode);
453 return; 458 return ERR_PTR(-EIO);
454 } 459 }
455 inode->i_mode = raw_inode->i_mode; 460 inode->i_mode = raw_inode->i_mode;
456 inode->i_uid = (uid_t)raw_inode->i_uid; 461 inode->i_uid = (uid_t)raw_inode->i_uid;
@@ -468,17 +473,27 @@ static void V2_minix_read_inode(struct inode * inode)
468 minix_inode->u.i2_data[i] = raw_inode->i_zone[i]; 473 minix_inode->u.i2_data[i] = raw_inode->i_zone[i];
469 minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0])); 474 minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
470 brelse(bh); 475 brelse(bh);
476 unlock_new_inode(inode);
477 return inode;
471} 478}
472 479
473/* 480/*
474 * The global function to read an inode. 481 * The global function to read an inode.
475 */ 482 */
476static void minix_read_inode(struct inode * inode) 483struct inode *minix_iget(struct super_block *sb, unsigned long ino)
477{ 484{
485 struct inode *inode;
486
487 inode = iget_locked(sb, ino);
488 if (!inode)
489 return ERR_PTR(-ENOMEM);
490 if (!(inode->i_state & I_NEW))
491 return inode;
492
478 if (INODE_VERSION(inode) == MINIX_V1) 493 if (INODE_VERSION(inode) == MINIX_V1)
479 V1_minix_read_inode(inode); 494 return V1_minix_iget(inode);
480 else 495 else
481 V2_minix_read_inode(inode); 496 return V2_minix_iget(inode);
482} 497}
483 498
484/* 499/*
diff --git a/fs/minix/minix.h b/fs/minix/minix.h
index ac5d3a75cb0d..326edfe96108 100644
--- a/fs/minix/minix.h
+++ b/fs/minix/minix.h
@@ -45,6 +45,7 @@ struct minix_sb_info {
45 unsigned short s_version; 45 unsigned short s_version;
46}; 46};
47 47
48extern struct inode *minix_iget(struct super_block *, unsigned long);
48extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, struct buffer_head **); 49extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, struct buffer_head **);
49extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **); 50extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
50extern struct inode * minix_new_inode(const struct inode * dir, int * error); 51extern struct inode * minix_new_inode(const struct inode * dir, int * error);
diff --git a/fs/minix/namei.c b/fs/minix/namei.c
index f4aa7a939040..102241bc9c79 100644
--- a/fs/minix/namei.c
+++ b/fs/minix/namei.c
@@ -54,10 +54,9 @@ static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry, st
54 54
55 ino = minix_inode_by_name(dentry); 55 ino = minix_inode_by_name(dentry);
56 if (ino) { 56 if (ino) {
57 inode = iget(dir->i_sb, ino); 57 inode = minix_iget(dir->i_sb, ino);
58 58 if (IS_ERR(inode))
59 if (!inode) 59 return ERR_CAST(inode);
60 return ERR_PTR(-EACCES);
61 } 60 }
62 d_add(dentry, inode); 61 d_add(dentry, inode);
63 return NULL; 62 return NULL;
diff --git a/fs/mpage.c b/fs/mpage.c
index d54f8f897224..5df564366f36 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -276,9 +276,7 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
276 } 276 }
277 277
278 if (first_hole != blocks_per_page) { 278 if (first_hole != blocks_per_page) {
279 zero_user_page(page, first_hole << blkbits, 279 zero_user_segment(page, first_hole << blkbits, PAGE_CACHE_SIZE);
280 PAGE_CACHE_SIZE - (first_hole << blkbits),
281 KM_USER0);
282 if (first_hole == 0) { 280 if (first_hole == 0) {
283 SetPageUptodate(page); 281 SetPageUptodate(page);
284 unlock_page(page); 282 unlock_page(page);
@@ -571,8 +569,7 @@ page_is_mapped:
571 569
572 if (page->index > end_index || !offset) 570 if (page->index > end_index || !offset)
573 goto confused; 571 goto confused;
574 zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, 572 zero_user_segment(page, offset, PAGE_CACHE_SIZE);
575 KM_USER0);
576 } 573 }
577 574
578 /* 575 /*
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/ncpfs/mmap.c b/fs/ncpfs/mmap.c
index a94473d3072c..5d8dcb9ee326 100644
--- a/fs/ncpfs/mmap.c
+++ b/fs/ncpfs/mmap.c
@@ -50,10 +50,6 @@ static int ncp_file_mmap_fault(struct vm_area_struct *area,
50 pos = vmf->pgoff << PAGE_SHIFT; 50 pos = vmf->pgoff << PAGE_SHIFT;
51 51
52 count = PAGE_SIZE; 52 count = PAGE_SIZE;
53 if ((unsigned long)vmf->virtual_address + PAGE_SIZE > area->vm_end) {
54 WARN_ON(1); /* shouldn't happen? */
55 count = area->vm_end - (unsigned long)vmf->virtual_address;
56 }
57 /* what we can read in one go */ 53 /* what we can read in one go */
58 bufsize = NCP_SERVER(inode)->buffer_size; 54 bufsize = NCP_SERVER(inode)->buffer_size;
59 55
diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c
index e6242cdbaf91..fae97196daad 100644
--- a/fs/nfs/getroot.c
+++ b/fs/nfs/getroot.c
@@ -96,7 +96,7 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh)
96 inode = nfs_fhget(sb, mntfh, fsinfo.fattr); 96 inode = nfs_fhget(sb, mntfh, fsinfo.fattr);
97 if (IS_ERR(inode)) { 97 if (IS_ERR(inode)) {
98 dprintk("nfs_get_root: get root inode failed\n"); 98 dprintk("nfs_get_root: get root inode failed\n");
99 return ERR_PTR(PTR_ERR(inode)); 99 return ERR_CAST(inode);
100 } 100 }
101 101
102 error = nfs_superblock_set_dummy_root(sb, inode); 102 error = nfs_superblock_set_dummy_root(sb, inode);
@@ -266,7 +266,7 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
266 inode = nfs_fhget(sb, mntfh, &fattr); 266 inode = nfs_fhget(sb, mntfh, &fattr);
267 if (IS_ERR(inode)) { 267 if (IS_ERR(inode)) {
268 dprintk("nfs_get_root: get root inode failed\n"); 268 dprintk("nfs_get_root: get root inode failed\n");
269 return ERR_PTR(PTR_ERR(inode)); 269 return ERR_CAST(inode);
270 } 270 }
271 271
272 error = nfs_superblock_set_dummy_root(sb, inode); 272 error = nfs_superblock_set_dummy_root(sb, inode);
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index 8fd6dfbe1bc3..3d7d9631e125 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -79,7 +79,7 @@ void nfs_readdata_release(void *data)
79static 79static
80int nfs_return_empty_page(struct page *page) 80int nfs_return_empty_page(struct page *page)
81{ 81{
82 zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0); 82 zero_user(page, 0, PAGE_CACHE_SIZE);
83 SetPageUptodate(page); 83 SetPageUptodate(page);
84 unlock_page(page); 84 unlock_page(page);
85 return 0; 85 return 0;
@@ -103,10 +103,10 @@ static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data)
103 pglen = PAGE_CACHE_SIZE - base; 103 pglen = PAGE_CACHE_SIZE - base;
104 for (;;) { 104 for (;;) {
105 if (remainder <= pglen) { 105 if (remainder <= pglen) {
106 zero_user_page(*pages, base, remainder, KM_USER0); 106 zero_user(*pages, base, remainder);
107 break; 107 break;
108 } 108 }
109 zero_user_page(*pages, base, pglen, KM_USER0); 109 zero_user(*pages, base, pglen);
110 pages++; 110 pages++;
111 remainder -= pglen; 111 remainder -= pglen;
112 pglen = PAGE_CACHE_SIZE; 112 pglen = PAGE_CACHE_SIZE;
@@ -130,7 +130,7 @@ static int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,
130 return PTR_ERR(new); 130 return PTR_ERR(new);
131 } 131 }
132 if (len < PAGE_CACHE_SIZE) 132 if (len < PAGE_CACHE_SIZE)
133 zero_user_page(page, len, PAGE_CACHE_SIZE - len, KM_USER0); 133 zero_user_segment(page, len, PAGE_CACHE_SIZE);
134 134
135 nfs_list_add_request(new, &one_request); 135 nfs_list_add_request(new, &one_request);
136 if (NFS_SERVER(inode)->rsize < PAGE_CACHE_SIZE) 136 if (NFS_SERVER(inode)->rsize < PAGE_CACHE_SIZE)
@@ -532,7 +532,7 @@ readpage_async_filler(void *data, struct page *page)
532 goto out_error; 532 goto out_error;
533 533
534 if (len < PAGE_CACHE_SIZE) 534 if (len < PAGE_CACHE_SIZE)
535 zero_user_page(page, len, PAGE_CACHE_SIZE - len, KM_USER0); 535 zero_user_segment(page, len, PAGE_CACHE_SIZE);
536 nfs_pageio_add_request(desc->pgio, new); 536 nfs_pageio_add_request(desc->pgio, new);
537 return 0; 537 return 0;
538out_error: 538out_error:
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 522efff3e2c5..b144b1957dd9 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -665,9 +665,7 @@ zero_page:
665 * then we need to zero any uninitalised data. */ 665 * then we need to zero any uninitalised data. */
666 if (req->wb_pgbase == 0 && req->wb_bytes != PAGE_CACHE_SIZE 666 if (req->wb_pgbase == 0 && req->wb_bytes != PAGE_CACHE_SIZE
667 && !PageUptodate(req->wb_page)) 667 && !PageUptodate(req->wb_page))
668 zero_user_page(req->wb_page, req->wb_bytes, 668 zero_user_segment(req->wb_page, req->wb_bytes, PAGE_CACHE_SIZE);
669 PAGE_CACHE_SIZE - req->wb_bytes,
670 KM_USER0);
671 return req; 669 return req;
672} 670}
673 671
diff --git a/fs/nfsd/auth.c b/fs/nfsd/auth.c
index 21928056e35e..d13403e33622 100644
--- a/fs/nfsd/auth.c
+++ b/fs/nfsd/auth.c
@@ -11,8 +11,6 @@
11#include <linux/nfsd/nfsd.h> 11#include <linux/nfsd/nfsd.h>
12#include <linux/nfsd/export.h> 12#include <linux/nfsd/export.h>
13 13
14#define CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
15
16int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp) 14int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
17{ 15{
18 struct exp_flavor_info *f; 16 struct exp_flavor_info *f;
@@ -69,10 +67,12 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
69 ret = set_current_groups(cred.cr_group_info); 67 ret = set_current_groups(cred.cr_group_info);
70 put_group_info(cred.cr_group_info); 68 put_group_info(cred.cr_group_info);
71 if ((cred.cr_uid)) { 69 if ((cred.cr_uid)) {
72 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK; 70 current->cap_effective =
71 cap_drop_nfsd_set(current->cap_effective);
73 } else { 72 } else {
74 cap_t(current->cap_effective) |= (CAP_NFSD_MASK & 73 current->cap_effective =
75 current->cap_permitted); 74 cap_raise_nfsd_set(current->cap_effective,
75 current->cap_permitted);
76 } 76 }
77 return ret; 77 return ret;
78} 78}
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 79b4bf812960..346570f6d848 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -1218,13 +1218,13 @@ static struct svc_export *exp_find(struct auth_domain *clp, int fsid_type,
1218 struct svc_export *exp; 1218 struct svc_export *exp;
1219 struct svc_expkey *ek = exp_find_key(clp, fsid_type, fsidv, reqp); 1219 struct svc_expkey *ek = exp_find_key(clp, fsid_type, fsidv, reqp);
1220 if (IS_ERR(ek)) 1220 if (IS_ERR(ek))
1221 return ERR_PTR(PTR_ERR(ek)); 1221 return ERR_CAST(ek);
1222 1222
1223 exp = exp_get_by_name(clp, ek->ek_mnt, ek->ek_dentry, reqp); 1223 exp = exp_get_by_name(clp, ek->ek_mnt, ek->ek_dentry, reqp);
1224 cache_put(&ek->h, &svc_expkey_cache); 1224 cache_put(&ek->h, &svc_expkey_cache);
1225 1225
1226 if (IS_ERR(exp)) 1226 if (IS_ERR(exp))
1227 return ERR_PTR(PTR_ERR(exp)); 1227 return ERR_CAST(exp);
1228 return exp; 1228 return exp;
1229} 1229}
1230 1230
diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c
index ad87cb01299b..00e9ccde8e42 100644
--- a/fs/ntfs/aops.c
+++ b/fs/ntfs/aops.c
@@ -87,13 +87,17 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
87 /* Check for the current buffer head overflowing. */ 87 /* Check for the current buffer head overflowing. */
88 if (unlikely(file_ofs + bh->b_size > init_size)) { 88 if (unlikely(file_ofs + bh->b_size > init_size)) {
89 int ofs; 89 int ofs;
90 void *kaddr;
90 91
91 ofs = 0; 92 ofs = 0;
92 if (file_ofs < init_size) 93 if (file_ofs < init_size)
93 ofs = init_size - file_ofs; 94 ofs = init_size - file_ofs;
94 local_irq_save(flags); 95 local_irq_save(flags);
95 zero_user_page(page, bh_offset(bh) + ofs, 96 kaddr = kmap_atomic(page, KM_BIO_SRC_IRQ);
96 bh->b_size - ofs, KM_BIO_SRC_IRQ); 97 memset(kaddr + bh_offset(bh) + ofs, 0,
98 bh->b_size - ofs);
99 flush_dcache_page(page);
100 kunmap_atomic(kaddr, KM_BIO_SRC_IRQ);
97 local_irq_restore(flags); 101 local_irq_restore(flags);
98 } 102 }
99 } else { 103 } else {
@@ -334,7 +338,7 @@ handle_hole:
334 bh->b_blocknr = -1UL; 338 bh->b_blocknr = -1UL;
335 clear_buffer_mapped(bh); 339 clear_buffer_mapped(bh);
336handle_zblock: 340handle_zblock:
337 zero_user_page(page, i * blocksize, blocksize, KM_USER0); 341 zero_user(page, i * blocksize, blocksize);
338 if (likely(!err)) 342 if (likely(!err))
339 set_buffer_uptodate(bh); 343 set_buffer_uptodate(bh);
340 } while (i++, iblock++, (bh = bh->b_this_page) != head); 344 } while (i++, iblock++, (bh = bh->b_this_page) != head);
@@ -410,7 +414,7 @@ retry_readpage:
410 /* Is the page fully outside i_size? (truncate in progress) */ 414 /* Is the page fully outside i_size? (truncate in progress) */
411 if (unlikely(page->index >= (i_size + PAGE_CACHE_SIZE - 1) >> 415 if (unlikely(page->index >= (i_size + PAGE_CACHE_SIZE - 1) >>
412 PAGE_CACHE_SHIFT)) { 416 PAGE_CACHE_SHIFT)) {
413 zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0); 417 zero_user(page, 0, PAGE_CACHE_SIZE);
414 ntfs_debug("Read outside i_size - truncated?"); 418 ntfs_debug("Read outside i_size - truncated?");
415 goto done; 419 goto done;
416 } 420 }
@@ -459,7 +463,7 @@ retry_readpage:
459 * ok to ignore the compressed flag here. 463 * ok to ignore the compressed flag here.
460 */ 464 */
461 if (unlikely(page->index > 0)) { 465 if (unlikely(page->index > 0)) {
462 zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0); 466 zero_user(page, 0, PAGE_CACHE_SIZE);
463 goto done; 467 goto done;
464 } 468 }
465 if (!NInoAttr(ni)) 469 if (!NInoAttr(ni))
@@ -788,8 +792,7 @@ lock_retry_remap:
788 if (err == -ENOENT || lcn == LCN_ENOENT) { 792 if (err == -ENOENT || lcn == LCN_ENOENT) {
789 bh->b_blocknr = -1; 793 bh->b_blocknr = -1;
790 clear_buffer_dirty(bh); 794 clear_buffer_dirty(bh);
791 zero_user_page(page, bh_offset(bh), blocksize, 795 zero_user(page, bh_offset(bh), blocksize);
792 KM_USER0);
793 set_buffer_uptodate(bh); 796 set_buffer_uptodate(bh);
794 err = 0; 797 err = 0;
795 continue; 798 continue;
@@ -1414,8 +1417,7 @@ retry_writepage:
1414 if (page->index >= (i_size >> PAGE_CACHE_SHIFT)) { 1417 if (page->index >= (i_size >> PAGE_CACHE_SHIFT)) {
1415 /* The page straddles i_size. */ 1418 /* The page straddles i_size. */
1416 unsigned int ofs = i_size & ~PAGE_CACHE_MASK; 1419 unsigned int ofs = i_size & ~PAGE_CACHE_MASK;
1417 zero_user_page(page, ofs, PAGE_CACHE_SIZE - ofs, 1420 zero_user_segment(page, ofs, PAGE_CACHE_SIZE);
1418 KM_USER0);
1419 } 1421 }
1420 /* Handle mst protected attributes. */ 1422 /* Handle mst protected attributes. */
1421 if (NInoMstProtected(ni)) 1423 if (NInoMstProtected(ni))
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index d1619d05eb23..33ff314cc507 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -565,7 +565,7 @@ int ntfs_read_compressed_block(struct page *page)
565 if (xpage >= max_page) { 565 if (xpage >= max_page) {
566 kfree(bhs); 566 kfree(bhs);
567 kfree(pages); 567 kfree(pages);
568 zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0); 568 zero_user(page, 0, PAGE_CACHE_SIZE);
569 ntfs_debug("Compressed read outside i_size - truncated?"); 569 ntfs_debug("Compressed read outside i_size - truncated?");
570 SetPageUptodate(page); 570 SetPageUptodate(page);
571 unlock_page(page); 571 unlock_page(page);
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 6cd08dfdc2ed..3c5550cd11d6 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -607,8 +607,8 @@ do_next_page:
607 ntfs_submit_bh_for_read(bh); 607 ntfs_submit_bh_for_read(bh);
608 *wait_bh++ = bh; 608 *wait_bh++ = bh;
609 } else { 609 } else {
610 zero_user_page(page, bh_offset(bh), 610 zero_user(page, bh_offset(bh),
611 blocksize, KM_USER0); 611 blocksize);
612 set_buffer_uptodate(bh); 612 set_buffer_uptodate(bh);
613 } 613 }
614 } 614 }
@@ -683,9 +683,8 @@ map_buffer_cached:
683 ntfs_submit_bh_for_read(bh); 683 ntfs_submit_bh_for_read(bh);
684 *wait_bh++ = bh; 684 *wait_bh++ = bh;
685 } else { 685 } else {
686 zero_user_page(page, 686 zero_user(page, bh_offset(bh),
687 bh_offset(bh), 687 blocksize);
688 blocksize, KM_USER0);
689 set_buffer_uptodate(bh); 688 set_buffer_uptodate(bh);
690 } 689 }
691 } 690 }
@@ -703,8 +702,8 @@ map_buffer_cached:
703 */ 702 */
704 if (bh_end <= pos || bh_pos >= end) { 703 if (bh_end <= pos || bh_pos >= end) {
705 if (!buffer_uptodate(bh)) { 704 if (!buffer_uptodate(bh)) {
706 zero_user_page(page, bh_offset(bh), 705 zero_user(page, bh_offset(bh),
707 blocksize, KM_USER0); 706 blocksize);
708 set_buffer_uptodate(bh); 707 set_buffer_uptodate(bh);
709 } 708 }
710 mark_buffer_dirty(bh); 709 mark_buffer_dirty(bh);
@@ -743,8 +742,7 @@ map_buffer_cached:
743 if (!buffer_uptodate(bh)) 742 if (!buffer_uptodate(bh))
744 set_buffer_uptodate(bh); 743 set_buffer_uptodate(bh);
745 } else if (!buffer_uptodate(bh)) { 744 } else if (!buffer_uptodate(bh)) {
746 zero_user_page(page, bh_offset(bh), blocksize, 745 zero_user(page, bh_offset(bh), blocksize);
747 KM_USER0);
748 set_buffer_uptodate(bh); 746 set_buffer_uptodate(bh);
749 } 747 }
750 continue; 748 continue;
@@ -868,8 +866,8 @@ rl_not_mapped_enoent:
868 if (!buffer_uptodate(bh)) 866 if (!buffer_uptodate(bh))
869 set_buffer_uptodate(bh); 867 set_buffer_uptodate(bh);
870 } else if (!buffer_uptodate(bh)) { 868 } else if (!buffer_uptodate(bh)) {
871 zero_user_page(page, bh_offset(bh), 869 zero_user(page, bh_offset(bh),
872 blocksize, KM_USER0); 870 blocksize);
873 set_buffer_uptodate(bh); 871 set_buffer_uptodate(bh);
874 } 872 }
875 continue; 873 continue;
@@ -1128,8 +1126,8 @@ rl_not_mapped_enoent:
1128 1126
1129 if (likely(bh_pos < initialized_size)) 1127 if (likely(bh_pos < initialized_size))
1130 ofs = initialized_size - bh_pos; 1128 ofs = initialized_size - bh_pos;
1131 zero_user_page(page, bh_offset(bh) + ofs, 1129 zero_user_segment(page, bh_offset(bh) + ofs,
1132 blocksize - ofs, KM_USER0); 1130 blocksize);
1133 } 1131 }
1134 } else /* if (unlikely(!buffer_uptodate(bh))) */ 1132 } else /* if (unlikely(!buffer_uptodate(bh))) */
1135 err = -EIO; 1133 err = -EIO;
@@ -1269,8 +1267,8 @@ rl_not_mapped_enoent:
1269 if (PageUptodate(page)) 1267 if (PageUptodate(page))
1270 set_buffer_uptodate(bh); 1268 set_buffer_uptodate(bh);
1271 else { 1269 else {
1272 zero_user_page(page, bh_offset(bh), 1270 zero_user(page, bh_offset(bh),
1273 blocksize, KM_USER0); 1271 blocksize);
1274 set_buffer_uptodate(bh); 1272 set_buffer_uptodate(bh);
1275 } 1273 }
1276 } 1274 }
@@ -1330,7 +1328,7 @@ err_out:
1330 len = PAGE_CACHE_SIZE; 1328 len = PAGE_CACHE_SIZE;
1331 if (len > bytes) 1329 if (len > bytes)
1332 len = bytes; 1330 len = bytes;
1333 zero_user_page(*pages, 0, len, KM_USER0); 1331 zero_user(*pages, 0, len);
1334 } 1332 }
1335 goto out; 1333 goto out;
1336} 1334}
@@ -1451,7 +1449,7 @@ err_out:
1451 len = PAGE_CACHE_SIZE; 1449 len = PAGE_CACHE_SIZE;
1452 if (len > bytes) 1450 if (len > bytes)
1453 len = bytes; 1451 len = bytes;
1454 zero_user_page(*pages, 0, len, KM_USER0); 1452 zero_user(*pages, 0, len);
1455 } 1453 }
1456 goto out; 1454 goto out;
1457} 1455}
diff --git a/fs/ntfs/malloc.h b/fs/ntfs/malloc.h
index e38e402e4103..cd0be3f5c3cd 100644
--- a/fs/ntfs/malloc.h
+++ b/fs/ntfs/malloc.h
@@ -85,8 +85,7 @@ static inline void *ntfs_malloc_nofs_nofail(unsigned long size)
85 85
86static inline void ntfs_free(void *addr) 86static inline void ntfs_free(void *addr)
87{ 87{
88 if (likely(((unsigned long)addr < VMALLOC_START) || 88 if (!is_vmalloc_addr(addr)) {
89 ((unsigned long)addr >= VMALLOC_END ))) {
90 kfree(addr); 89 kfree(addr);
91 /* free_page((unsigned long)addr); */ 90 /* free_page((unsigned long)addr); */
92 return; 91 return;
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index e6df06ac6405..447206eb5c2e 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -3338,7 +3338,7 @@ static int ocfs2_insert_path(struct inode *inode,
3338 if (insert->ins_split != SPLIT_NONE) { 3338 if (insert->ins_split != SPLIT_NONE) {
3339 /* 3339 /*
3340 * We could call ocfs2_insert_at_leaf() for some types 3340 * We could call ocfs2_insert_at_leaf() for some types
3341 * of splits, but it's easier to just let one seperate 3341 * of splits, but it's easier to just let one separate
3342 * function sort it all out. 3342 * function sort it all out.
3343 */ 3343 */
3344 ocfs2_split_record(inode, left_path, right_path, 3344 ocfs2_split_record(inode, left_path, right_path,
@@ -5670,7 +5670,7 @@ static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle,
5670 mlog_errno(ret); 5670 mlog_errno(ret);
5671 5671
5672 if (zero) 5672 if (zero)
5673 zero_user_page(page, from, to - from, KM_USER0); 5673 zero_user_segment(page, from, to);
5674 5674
5675 /* 5675 /*
5676 * Need to set the buffers we zero'd into uptodate 5676 * Need to set the buffers we zero'd into uptodate
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index bc7b4cbbe8ec..82243127eebf 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -307,7 +307,7 @@ static int ocfs2_readpage(struct file *file, struct page *page)
307 * XXX sys_readahead() seems to get that wrong? 307 * XXX sys_readahead() seems to get that wrong?
308 */ 308 */
309 if (start >= i_size_read(inode)) { 309 if (start >= i_size_read(inode)) {
310 zero_user_page(page, 0, PAGE_SIZE, KM_USER0); 310 zero_user(page, 0, PAGE_SIZE);
311 SetPageUptodate(page); 311 SetPageUptodate(page);
312 ret = 0; 312 ret = 0;
313 goto out_alloc; 313 goto out_alloc;
@@ -869,7 +869,7 @@ int ocfs2_map_page_blocks(struct page *page, u64 *p_blkno,
869 if (block_start >= to) 869 if (block_start >= to)
870 break; 870 break;
871 871
872 zero_user_page(page, block_start, bh->b_size, KM_USER0); 872 zero_user(page, block_start, bh->b_size);
873 set_buffer_uptodate(bh); 873 set_buffer_uptodate(bh);
874 mark_buffer_dirty(bh); 874 mark_buffer_dirty(bh);
875 875
@@ -1034,7 +1034,7 @@ static void ocfs2_zero_new_buffers(struct page *page, unsigned from, unsigned to
1034 start = max(from, block_start); 1034 start = max(from, block_start);
1035 end = min(to, block_end); 1035 end = min(to, block_end);
1036 1036
1037 zero_user_page(page, start, end - start, KM_USER0); 1037 zero_user_segment(page, start, end);
1038 set_buffer_uptodate(bh); 1038 set_buffer_uptodate(bh);
1039 } 1039 }
1040 1040
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
index 6b0107f21344..e280833ceb9a 100644
--- a/fs/ocfs2/dir.c
+++ b/fs/ocfs2/dir.c
@@ -1215,7 +1215,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
1215 down_write(&oi->ip_alloc_sem); 1215 down_write(&oi->ip_alloc_sem);
1216 1216
1217 /* 1217 /*
1218 * Prepare for worst case allocation scenario of two seperate 1218 * Prepare for worst case allocation scenario of two separate
1219 * extents. 1219 * extents.
1220 */ 1220 */
1221 if (alloc == 2) 1221 if (alloc == 2)
diff --git a/fs/ocfs2/ocfs1_fs_compat.h b/fs/ocfs2/ocfs1_fs_compat.h
index 0b499bccec5a..dfb313bda5dd 100644
--- a/fs/ocfs2/ocfs1_fs_compat.h
+++ b/fs/ocfs2/ocfs1_fs_compat.h
@@ -77,7 +77,7 @@ struct ocfs1_disk_lock
77{ 77{
78/*00*/ __u32 curr_master; 78/*00*/ __u32 curr_master;
79 __u8 file_lock; 79 __u8 file_lock;
80 __u8 compat_pad[3]; /* Not in orignal definition. Used to 80 __u8 compat_pad[3]; /* Not in original definition. Used to
81 make the already existing alignment 81 make the already existing alignment
82 explicit */ 82 explicit */
83 __u64 last_write_time; 83 __u64 last_write_time;
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index 7e397e2c25dd..72c198a004df 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -646,7 +646,7 @@ bail:
646 * sync-data inodes." 646 * sync-data inodes."
647 * 647 *
648 * Note: OCFS2 already does this differently for metadata vs data 648 * Note: OCFS2 already does this differently for metadata vs data
649 * allocations, as those bitmaps are seperate and undo access is never 649 * allocations, as those bitmaps are separate and undo access is never
650 * called on a metadata group descriptor. 650 * called on a metadata group descriptor.
651 */ 651 */
652static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh, 652static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
diff --git a/fs/openpromfs/inode.c b/fs/openpromfs/inode.c
index 6b7ff1618945..d17b4fd204e1 100644
--- a/fs/openpromfs/inode.c
+++ b/fs/openpromfs/inode.c
@@ -38,6 +38,8 @@ struct op_inode_info {
38 union op_inode_data u; 38 union op_inode_data u;
39}; 39};
40 40
41static struct inode *openprom_iget(struct super_block *sb, ino_t ino);
42
41static inline struct op_inode_info *OP_I(struct inode *inode) 43static inline struct op_inode_info *OP_I(struct inode *inode)
42{ 44{
43 return container_of(inode, struct op_inode_info, vfs_inode); 45 return container_of(inode, struct op_inode_info, vfs_inode);
@@ -226,10 +228,10 @@ static struct dentry *openpromfs_lookup(struct inode *dir, struct dentry *dentry
226 return ERR_PTR(-ENOENT); 228 return ERR_PTR(-ENOENT);
227 229
228found: 230found:
229 inode = iget(dir->i_sb, ino); 231 inode = openprom_iget(dir->i_sb, ino);
230 mutex_unlock(&op_mutex); 232 mutex_unlock(&op_mutex);
231 if (!inode) 233 if (IS_ERR(inode))
232 return ERR_PTR(-EINVAL); 234 return ERR_CAST(inode);
233 ent_oi = OP_I(inode); 235 ent_oi = OP_I(inode);
234 ent_oi->type = ent_type; 236 ent_oi->type = ent_type;
235 ent_oi->u = ent_data; 237 ent_oi->u = ent_data;
@@ -348,14 +350,23 @@ static void openprom_destroy_inode(struct inode *inode)
348 kmem_cache_free(op_inode_cachep, OP_I(inode)); 350 kmem_cache_free(op_inode_cachep, OP_I(inode));
349} 351}
350 352
351static void openprom_read_inode(struct inode * inode) 353static struct inode *openprom_iget(struct super_block *sb, ino_t ino)
352{ 354{
353 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 355 struct inode *inode;
354 if (inode->i_ino == OPENPROM_ROOT_INO) { 356
355 inode->i_op = &openprom_inode_operations; 357 inode = iget_locked(sb, ino);
356 inode->i_fop = &openprom_operations; 358 if (!inode)
357 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO; 359 return ERR_PTR(-ENOMEM);
360 if (inode->i_state & I_NEW) {
361 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
362 if (inode->i_ino == OPENPROM_ROOT_INO) {
363 inode->i_op = &openprom_inode_operations;
364 inode->i_fop = &openprom_operations;
365 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
366 }
367 unlock_new_inode(inode);
358 } 368 }
369 return inode;
359} 370}
360 371
361static int openprom_remount(struct super_block *sb, int *flags, char *data) 372static int openprom_remount(struct super_block *sb, int *flags, char *data)
@@ -367,7 +378,6 @@ static int openprom_remount(struct super_block *sb, int *flags, char *data)
367static const struct super_operations openprom_sops = { 378static const struct super_operations openprom_sops = {
368 .alloc_inode = openprom_alloc_inode, 379 .alloc_inode = openprom_alloc_inode,
369 .destroy_inode = openprom_destroy_inode, 380 .destroy_inode = openprom_destroy_inode,
370 .read_inode = openprom_read_inode,
371 .statfs = simple_statfs, 381 .statfs = simple_statfs,
372 .remount_fs = openprom_remount, 382 .remount_fs = openprom_remount,
373}; 383};
@@ -376,6 +386,7 @@ static int openprom_fill_super(struct super_block *s, void *data, int silent)
376{ 386{
377 struct inode *root_inode; 387 struct inode *root_inode;
378 struct op_inode_info *oi; 388 struct op_inode_info *oi;
389 int ret;
379 390
380 s->s_flags |= MS_NOATIME; 391 s->s_flags |= MS_NOATIME;
381 s->s_blocksize = 1024; 392 s->s_blocksize = 1024;
@@ -383,9 +394,11 @@ static int openprom_fill_super(struct super_block *s, void *data, int silent)
383 s->s_magic = OPENPROM_SUPER_MAGIC; 394 s->s_magic = OPENPROM_SUPER_MAGIC;
384 s->s_op = &openprom_sops; 395 s->s_op = &openprom_sops;
385 s->s_time_gran = 1; 396 s->s_time_gran = 1;
386 root_inode = iget(s, OPENPROM_ROOT_INO); 397 root_inode = openprom_iget(s, OPENPROM_ROOT_INO);
387 if (!root_inode) 398 if (IS_ERR(root_inode)) {
399 ret = PTR_ERR(root_inode);
388 goto out_no_root; 400 goto out_no_root;
401 }
389 402
390 oi = OP_I(root_inode); 403 oi = OP_I(root_inode);
391 oi->type = op_inode_node; 404 oi->type = op_inode_node;
@@ -393,13 +406,15 @@ static int openprom_fill_super(struct super_block *s, void *data, int silent)
393 406
394 s->s_root = d_alloc_root(root_inode); 407 s->s_root = d_alloc_root(root_inode);
395 if (!s->s_root) 408 if (!s->s_root)
396 goto out_no_root; 409 goto out_no_root_dentry;
397 return 0; 410 return 0;
398 411
412out_no_root_dentry:
413 iput(root_inode);
414 ret = -ENOMEM;
399out_no_root: 415out_no_root:
400 printk("openprom_fill_super: get root inode failed\n"); 416 printk("openprom_fill_super: get root inode failed\n");
401 iput(root_inode); 417 return ret;
402 return -ENOMEM;
403} 418}
404 419
405static int openprom_get_sb(struct file_system_type *fs_type, 420static int openprom_get_sb(struct file_system_type *fs_type,
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/array.c b/fs/proc/array.c
index b380313092bd..6ba2746e4517 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -281,14 +281,23 @@ static inline char *task_sig(struct task_struct *p, char *buffer)
281 return buffer; 281 return buffer;
282} 282}
283 283
284static char *render_cap_t(const char *header, kernel_cap_t *a, char *buffer)
285{
286 unsigned __capi;
287
288 buffer += sprintf(buffer, "%s", header);
289 CAP_FOR_EACH_U32(__capi) {
290 buffer += sprintf(buffer, "%08x",
291 a->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]);
292 }
293 return buffer + sprintf(buffer, "\n");
294}
295
284static inline char *task_cap(struct task_struct *p, char *buffer) 296static inline char *task_cap(struct task_struct *p, char *buffer)
285{ 297{
286 return buffer + sprintf(buffer, "CapInh:\t%016x\n" 298 buffer = render_cap_t("CapInh:\t", &p->cap_inheritable, buffer);
287 "CapPrm:\t%016x\n" 299 buffer = render_cap_t("CapPrm:\t", &p->cap_permitted, buffer);
288 "CapEff:\t%016x\n", 300 return render_cap_t("CapEff:\t", &p->cap_effective, buffer);
289 cap_t(p->cap_inheritable),
290 cap_t(p->cap_permitted),
291 cap_t(p->cap_effective));
292} 301}
293 302
294static inline char *task_context_switch_counts(struct task_struct *p, 303static inline char *task_context_switch_counts(struct task_struct *p,
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 33537487f5ab..c59852b38787 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -88,10 +88,6 @@
88 * in /proc for a task before it execs a suid executable. 88 * in /proc for a task before it execs a suid executable.
89 */ 89 */
90 90
91
92/* Worst case buffer size needed for holding an integer. */
93#define PROC_NUMBUF 13
94
95struct pid_entry { 91struct pid_entry {
96 char *name; 92 char *name;
97 int len; 93 int len;
@@ -787,7 +783,7 @@ out_no_task:
787} 783}
788#endif 784#endif
789 785
790static loff_t mem_lseek(struct file * file, loff_t offset, int orig) 786loff_t mem_lseek(struct file *file, loff_t offset, int orig)
791{ 787{
792 switch (orig) { 788 switch (orig) {
793 case 0: 789 case 0:
@@ -935,42 +931,6 @@ static const struct file_operations proc_oom_adjust_operations = {
935 .write = oom_adjust_write, 931 .write = oom_adjust_write,
936}; 932};
937 933
938#ifdef CONFIG_MMU
939static ssize_t clear_refs_write(struct file *file, const char __user *buf,
940 size_t count, loff_t *ppos)
941{
942 struct task_struct *task;
943 char buffer[PROC_NUMBUF], *end;
944 struct mm_struct *mm;
945
946 memset(buffer, 0, sizeof(buffer));
947 if (count > sizeof(buffer) - 1)
948 count = sizeof(buffer) - 1;
949 if (copy_from_user(buffer, buf, count))
950 return -EFAULT;
951 if (!simple_strtol(buffer, &end, 0))
952 return -EINVAL;
953 if (*end == '\n')
954 end++;
955 task = get_proc_task(file->f_path.dentry->d_inode);
956 if (!task)
957 return -ESRCH;
958 mm = get_task_mm(task);
959 if (mm) {
960 clear_refs_smap(mm);
961 mmput(mm);
962 }
963 put_task_struct(task);
964 if (end - buffer == 0)
965 return -EIO;
966 return end - buffer;
967}
968
969static struct file_operations proc_clear_refs_operations = {
970 .write = clear_refs_write,
971};
972#endif
973
974#ifdef CONFIG_AUDITSYSCALL 934#ifdef CONFIG_AUDITSYSCALL
975#define TMPBUFLEN 21 935#define TMPBUFLEN 21
976static ssize_t proc_loginuid_read(struct file * file, char __user * buf, 936static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
@@ -2289,9 +2249,10 @@ static const struct pid_entry tgid_base_stuff[] = {
2289 LNK("exe", exe), 2249 LNK("exe", exe),
2290 REG("mounts", S_IRUGO, mounts), 2250 REG("mounts", S_IRUGO, mounts),
2291 REG("mountstats", S_IRUSR, mountstats), 2251 REG("mountstats", S_IRUSR, mountstats),
2292#ifdef CONFIG_MMU 2252#ifdef CONFIG_PROC_PAGE_MONITOR
2293 REG("clear_refs", S_IWUSR, clear_refs), 2253 REG("clear_refs", S_IWUSR, clear_refs),
2294 REG("smaps", S_IRUGO, smaps), 2254 REG("smaps", S_IRUGO, smaps),
2255 REG("pagemap", S_IRUSR, pagemap),
2295#endif 2256#endif
2296#ifdef CONFIG_SECURITY 2257#ifdef CONFIG_SECURITY
2297 DIR("attr", S_IRUGO|S_IXUGO, attr_dir), 2258 DIR("attr", S_IRUGO|S_IXUGO, attr_dir),
@@ -2360,7 +2321,8 @@ static void proc_flush_task_mnt(struct vfsmount *mnt, pid_t pid, pid_t tgid)
2360 name.len = snprintf(buf, sizeof(buf), "%d", pid); 2321 name.len = snprintf(buf, sizeof(buf), "%d", pid);
2361 dentry = d_hash_and_lookup(mnt->mnt_root, &name); 2322 dentry = d_hash_and_lookup(mnt->mnt_root, &name);
2362 if (dentry) { 2323 if (dentry) {
2363 shrink_dcache_parent(dentry); 2324 if (!(current->flags & PF_EXITING))
2325 shrink_dcache_parent(dentry);
2364 d_drop(dentry); 2326 d_drop(dentry);
2365 dput(dentry); 2327 dput(dentry);
2366 } 2328 }
@@ -2617,9 +2579,10 @@ static const struct pid_entry tid_base_stuff[] = {
2617 LNK("root", root), 2579 LNK("root", root),
2618 LNK("exe", exe), 2580 LNK("exe", exe),
2619 REG("mounts", S_IRUGO, mounts), 2581 REG("mounts", S_IRUGO, mounts),
2620#ifdef CONFIG_MMU 2582#ifdef CONFIG_PROC_PAGE_MONITOR
2621 REG("clear_refs", S_IWUSR, clear_refs), 2583 REG("clear_refs", S_IWUSR, clear_refs),
2622 REG("smaps", S_IRUGO, smaps), 2584 REG("smaps", S_IRUGO, smaps),
2585 REG("pagemap", S_IRUSR, pagemap),
2623#endif 2586#endif
2624#ifdef CONFIG_SECURITY 2587#ifdef CONFIG_SECURITY
2625 DIR("attr", S_IRUGO|S_IXUGO, attr_dir), 2588 DIR("attr", S_IRUGO|S_IXUGO, attr_dir),
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 1a551d92e1d8..6ecf6396f072 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -73,11 +73,6 @@ static void proc_delete_inode(struct inode *inode)
73 73
74struct vfsmount *proc_mnt; 74struct vfsmount *proc_mnt;
75 75
76static void proc_read_inode(struct inode * inode)
77{
78 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
79}
80
81static struct kmem_cache * proc_inode_cachep; 76static struct kmem_cache * proc_inode_cachep;
82 77
83static struct inode *proc_alloc_inode(struct super_block *sb) 78static struct inode *proc_alloc_inode(struct super_block *sb)
@@ -128,7 +123,6 @@ static int proc_remount(struct super_block *sb, int *flags, char *data)
128static const struct super_operations proc_sops = { 123static const struct super_operations proc_sops = {
129 .alloc_inode = proc_alloc_inode, 124 .alloc_inode = proc_alloc_inode,
130 .destroy_inode = proc_destroy_inode, 125 .destroy_inode = proc_destroy_inode,
131 .read_inode = proc_read_inode,
132 .drop_inode = generic_delete_inode, 126 .drop_inode = generic_delete_inode,
133 .delete_inode = proc_delete_inode, 127 .delete_inode = proc_delete_inode,
134 .statfs = simple_statfs, 128 .statfs = simple_statfs,
@@ -401,39 +395,41 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
401 if (de != NULL && !try_module_get(de->owner)) 395 if (de != NULL && !try_module_get(de->owner))
402 goto out_mod; 396 goto out_mod;
403 397
404 inode = iget(sb, ino); 398 inode = iget_locked(sb, ino);
405 if (!inode) 399 if (!inode)
406 goto out_ino; 400 goto out_ino;
407 401 if (inode->i_state & I_NEW) {
408 PROC_I(inode)->fd = 0; 402 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
409 PROC_I(inode)->pde = de; 403 PROC_I(inode)->fd = 0;
410 if (de) { 404 PROC_I(inode)->pde = de;
411 if (de->mode) { 405 if (de) {
412 inode->i_mode = de->mode; 406 if (de->mode) {
413 inode->i_uid = de->uid; 407 inode->i_mode = de->mode;
414 inode->i_gid = de->gid; 408 inode->i_uid = de->uid;
415 } 409 inode->i_gid = de->gid;
416 if (de->size) 410 }
417 inode->i_size = de->size; 411 if (de->size)
418 if (de->nlink) 412 inode->i_size = de->size;
419 inode->i_nlink = de->nlink; 413 if (de->nlink)
420 if (de->proc_iops) 414 inode->i_nlink = de->nlink;
421 inode->i_op = de->proc_iops; 415 if (de->proc_iops)
422 if (de->proc_fops) { 416 inode->i_op = de->proc_iops;
423 if (S_ISREG(inode->i_mode)) { 417 if (de->proc_fops) {
418 if (S_ISREG(inode->i_mode)) {
424#ifdef CONFIG_COMPAT 419#ifdef CONFIG_COMPAT
425 if (!de->proc_fops->compat_ioctl) 420 if (!de->proc_fops->compat_ioctl)
426 inode->i_fop = 421 inode->i_fop =
427 &proc_reg_file_ops_no_compat; 422 &proc_reg_file_ops_no_compat;
428 else 423 else
429#endif 424#endif
430 inode->i_fop = &proc_reg_file_ops; 425 inode->i_fop = &proc_reg_file_ops;
426 } else {
427 inode->i_fop = de->proc_fops;
428 }
431 } 429 }
432 else
433 inode->i_fop = de->proc_fops;
434 } 430 }
431 unlock_new_inode(inode);
435 } 432 }
436
437 return inode; 433 return inode;
438 434
439out_ino: 435out_ino:
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 05b3e9006262..7d57e8069924 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -52,15 +52,13 @@ extern int proc_tid_stat(struct task_struct *, char *);
52extern int proc_tgid_stat(struct task_struct *, char *); 52extern int proc_tgid_stat(struct task_struct *, char *);
53extern int proc_pid_status(struct task_struct *, char *); 53extern int proc_pid_status(struct task_struct *, char *);
54extern int proc_pid_statm(struct task_struct *, char *); 54extern int proc_pid_statm(struct task_struct *, char *);
55extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
55 56
56extern const struct file_operations proc_maps_operations; 57extern const struct file_operations proc_maps_operations;
57extern const struct file_operations proc_numa_maps_operations; 58extern const struct file_operations proc_numa_maps_operations;
58extern const struct file_operations proc_smaps_operations; 59extern const struct file_operations proc_smaps_operations;
59 60extern const struct file_operations proc_clear_refs_operations;
60extern const struct file_operations proc_maps_operations; 61extern const struct file_operations proc_pagemap_operations;
61extern const struct file_operations proc_numa_maps_operations;
62extern const struct file_operations proc_smaps_operations;
63
64 62
65void free_proc_entry(struct proc_dir_entry *de); 63void free_proc_entry(struct proc_dir_entry *de);
66 64
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 1be73082edd3..7dd26e18cbfd 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -325,7 +325,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
325 if (m == NULL) { 325 if (m == NULL) {
326 if (clear_user(buffer, tsz)) 326 if (clear_user(buffer, tsz))
327 return -EFAULT; 327 return -EFAULT;
328 } else if ((start >= VMALLOC_START) && (start < VMALLOC_END)) { 328 } else if (is_vmalloc_addr((void *)start)) {
329 char * elf_buf; 329 char * elf_buf;
330 struct vm_struct *m; 330 struct vm_struct *m;
331 unsigned long curstart = start; 331 unsigned long curstart = start;
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c
index 3462bfde89f6..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>
@@ -46,6 +47,7 @@
46#include <linux/vmalloc.h> 47#include <linux/vmalloc.h>
47#include <linux/crash_dump.h> 48#include <linux/crash_dump.h>
48#include <linux/pid_namespace.h> 49#include <linux/pid_namespace.h>
50#include <linux/bootmem.h>
49#include <asm/uaccess.h> 51#include <asm/uaccess.h>
50#include <asm/pgtable.h> 52#include <asm/pgtable.h>
51#include <asm/io.h> 53#include <asm/io.h>
@@ -63,7 +65,6 @@
63 */ 65 */
64extern int get_hardware_list(char *); 66extern int get_hardware_list(char *);
65extern int get_stram_list(char *); 67extern int get_stram_list(char *);
66extern int get_filesystem_list(char *);
67extern int get_exec_domain_list(char *); 68extern int get_exec_domain_list(char *);
68extern int get_dma_list(char *); 69extern int get_dma_list(char *);
69 70
@@ -83,10 +84,15 @@ static int loadavg_read_proc(char *page, char **start, off_t off,
83{ 84{
84 int a, b, c; 85 int a, b, c;
85 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));
86 95
87 a = avenrun[0] + (FIXED_1/200);
88 b = avenrun[1] + (FIXED_1/200);
89 c = avenrun[2] + (FIXED_1/200);
90 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",
91 LOAD_INT(a), LOAD_FRAC(a), 97 LOAD_INT(a), LOAD_FRAC(a),
92 LOAD_INT(b), LOAD_FRAC(b), 98 LOAD_INT(b), LOAD_FRAC(b),
@@ -598,7 +604,6 @@ static void int_seq_stop(struct seq_file *f, void *v)
598} 604}
599 605
600 606
601extern int show_interrupts(struct seq_file *f, void *v); /* In arch code */
602static struct seq_operations int_seq_ops = { 607static struct seq_operations int_seq_ops = {
603 .start = int_seq_start, 608 .start = int_seq_start,
604 .next = int_seq_next, 609 .next = int_seq_next,
@@ -675,6 +680,137 @@ static const struct file_operations proc_sysrq_trigger_operations = {
675}; 680};
676#endif 681#endif
677 682
683#ifdef CONFIG_PROC_PAGE_MONITOR
684#define KPMSIZE sizeof(u64)
685#define KPMMASK (KPMSIZE - 1)
686/* /proc/kpagecount - an array exposing page counts
687 *
688 * Each entry is a u64 representing the corresponding
689 * physical page count.
690 */
691static ssize_t kpagecount_read(struct file *file, char __user *buf,
692 size_t count, loff_t *ppos)
693{
694 u64 __user *out = (u64 __user *)buf;
695 struct page *ppage;
696 unsigned long src = *ppos;
697 unsigned long pfn;
698 ssize_t ret = 0;
699 u64 pcount;
700
701 pfn = src / KPMSIZE;
702 count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
703 if (src & KPMMASK || count & KPMMASK)
704 return -EIO;
705
706 while (count > 0) {
707 ppage = NULL;
708 if (pfn_valid(pfn))
709 ppage = pfn_to_page(pfn);
710 pfn++;
711 if (!ppage)
712 pcount = 0;
713 else
714 pcount = atomic_read(&ppage->_count);
715
716 if (put_user(pcount, out++)) {
717 ret = -EFAULT;
718 break;
719 }
720
721 count -= KPMSIZE;
722 }
723
724 *ppos += (char __user *)out - buf;
725 if (!ret)
726 ret = (char __user *)out - buf;
727 return ret;
728}
729
730static struct file_operations proc_kpagecount_operations = {
731 .llseek = mem_lseek,
732 .read = kpagecount_read,
733};
734
735/* /proc/kpageflags - an array exposing page flags
736 *
737 * Each entry is a u64 representing the corresponding
738 * physical page flags.
739 */
740
741/* These macros are used to decouple internal flags from exported ones */
742
743#define KPF_LOCKED 0
744#define KPF_ERROR 1
745#define KPF_REFERENCED 2
746#define KPF_UPTODATE 3
747#define KPF_DIRTY 4
748#define KPF_LRU 5
749#define KPF_ACTIVE 6
750#define KPF_SLAB 7
751#define KPF_WRITEBACK 8
752#define KPF_RECLAIM 9
753#define KPF_BUDDY 10
754
755#define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
756
757static ssize_t kpageflags_read(struct file *file, char __user *buf,
758 size_t count, loff_t *ppos)
759{
760 u64 __user *out = (u64 __user *)buf;
761 struct page *ppage;
762 unsigned long src = *ppos;
763 unsigned long pfn;
764 ssize_t ret = 0;
765 u64 kflags, uflags;
766
767 pfn = src / KPMSIZE;
768 count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
769 if (src & KPMMASK || count & KPMMASK)
770 return -EIO;
771
772 while (count > 0) {
773 ppage = NULL;
774 if (pfn_valid(pfn))
775 ppage = pfn_to_page(pfn);
776 pfn++;
777 if (!ppage)
778 kflags = 0;
779 else
780 kflags = ppage->flags;
781
782 uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
783 kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
784 kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
785 kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
786 kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
787 kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
788 kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
789 kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
790 kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
791 kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
792 kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
793
794 if (put_user(uflags, out++)) {
795 ret = -EFAULT;
796 break;
797 }
798
799 count -= KPMSIZE;
800 }
801
802 *ppos += (char __user *)out - buf;
803 if (!ret)
804 ret = (char __user *)out - buf;
805 return ret;
806}
807
808static struct file_operations proc_kpageflags_operations = {
809 .llseek = mem_lseek,
810 .read = kpageflags_read,
811};
812#endif /* CONFIG_PROC_PAGE_MONITOR */
813
678struct proc_dir_entry *proc_root_kcore; 814struct proc_dir_entry *proc_root_kcore;
679 815
680void create_seq_entry(char *name, mode_t mode, const struct file_operations *f) 816void create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
@@ -755,6 +891,10 @@ void __init proc_misc_init(void)
755 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; 891 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
756 } 892 }
757#endif 893#endif
894#ifdef CONFIG_PROC_PAGE_MONITOR
895 create_seq_entry("kpagecount", S_IRUSR, &proc_kpagecount_operations);
896 create_seq_entry("kpageflags", S_IRUSR, &proc_kpageflags_operations);
897#endif
758#ifdef CONFIG_PROC_VMCORE 898#ifdef CONFIG_PROC_VMCORE
759 proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL); 899 proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
760 if (proc_vmcore) 900 if (proc_vmcore)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 8043a3eab52c..38338ed98cc6 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -5,7 +5,10 @@
5#include <linux/highmem.h> 5#include <linux/highmem.h>
6#include <linux/ptrace.h> 6#include <linux/ptrace.h>
7#include <linux/pagemap.h> 7#include <linux/pagemap.h>
8#include <linux/ptrace.h>
8#include <linux/mempolicy.h> 9#include <linux/mempolicy.h>
10#include <linux/swap.h>
11#include <linux/swapops.h>
9 12
10#include <asm/elf.h> 13#include <asm/elf.h>
11#include <asm/uaccess.h> 14#include <asm/uaccess.h>
@@ -114,24 +117,124 @@ static void pad_len_spaces(struct seq_file *m, int len)
114 seq_printf(m, "%*c", len, ' '); 117 seq_printf(m, "%*c", len, ' ');
115} 118}
116 119
117struct mem_size_stats 120static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma)
118{ 121{
119 unsigned long resident; 122 if (vma && vma != priv->tail_vma) {
120 unsigned long shared_clean; 123 struct mm_struct *mm = vma->vm_mm;
121 unsigned long shared_dirty; 124 up_read(&mm->mmap_sem);
122 unsigned long private_clean; 125 mmput(mm);
123 unsigned long private_dirty; 126 }
124 unsigned long referenced; 127}
125};
126 128
127struct pmd_walker { 129static void *m_start(struct seq_file *m, loff_t *pos)
128 struct vm_area_struct *vma; 130{
129 void *private; 131 struct proc_maps_private *priv = m->private;
130 void (*action)(struct vm_area_struct *, pmd_t *, unsigned long, 132 unsigned long last_addr = m->version;
131 unsigned long, void *); 133 struct mm_struct *mm;
132}; 134 struct vm_area_struct *vma, *tail_vma = NULL;
135 loff_t l = *pos;
136
137 /* Clear the per syscall fields in priv */
138 priv->task = NULL;
139 priv->tail_vma = NULL;
140
141 /*
142 * We remember last_addr rather than next_addr to hit with
143 * mmap_cache most of the time. We have zero last_addr at
144 * the beginning and also after lseek. We will have -1 last_addr
145 * after the end of the vmas.
146 */
147
148 if (last_addr == -1UL)
149 return NULL;
150
151 priv->task = get_pid_task(priv->pid, PIDTYPE_PID);
152 if (!priv->task)
153 return NULL;
154
155 mm = mm_for_maps(priv->task);
156 if (!mm)
157 return NULL;
158
159 tail_vma = get_gate_vma(priv->task);
160 priv->tail_vma = tail_vma;
161
162 /* Start with last addr hint */
163 vma = find_vma(mm, last_addr);
164 if (last_addr && vma) {
165 vma = vma->vm_next;
166 goto out;
167 }
168
169 /*
170 * Check the vma index is within the range and do
171 * sequential scan until m_index.
172 */
173 vma = NULL;
174 if ((unsigned long)l < mm->map_count) {
175 vma = mm->mmap;
176 while (l-- && vma)
177 vma = vma->vm_next;
178 goto out;
179 }
180
181 if (l != mm->map_count)
182 tail_vma = NULL; /* After gate vma */
183
184out:
185 if (vma)
186 return vma;
187
188 /* End of vmas has been reached */
189 m->version = (tail_vma != NULL)? 0: -1UL;
190 up_read(&mm->mmap_sem);
191 mmput(mm);
192 return tail_vma;
193}
133 194
134static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats *mss) 195static void *m_next(struct seq_file *m, void *v, loff_t *pos)
196{
197 struct proc_maps_private *priv = m->private;
198 struct vm_area_struct *vma = v;
199 struct vm_area_struct *tail_vma = priv->tail_vma;
200
201 (*pos)++;
202 if (vma && (vma != tail_vma) && vma->vm_next)
203 return vma->vm_next;
204 vma_stop(priv, vma);
205 return (vma != tail_vma)? tail_vma: NULL;
206}
207
208static void m_stop(struct seq_file *m, void *v)
209{
210 struct proc_maps_private *priv = m->private;
211 struct vm_area_struct *vma = v;
212
213 vma_stop(priv, vma);
214 if (priv->task)
215 put_task_struct(priv->task);
216}
217
218static int do_maps_open(struct inode *inode, struct file *file,
219 struct seq_operations *ops)
220{
221 struct proc_maps_private *priv;
222 int ret = -ENOMEM;
223 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
224 if (priv) {
225 priv->pid = proc_pid(inode);
226 ret = seq_open(file, ops);
227 if (!ret) {
228 struct seq_file *m = file->private_data;
229 m->private = priv;
230 } else {
231 kfree(priv);
232 }
233 }
234 return ret;
235}
236
237static int show_map(struct seq_file *m, void *v)
135{ 238{
136 struct proc_maps_private *priv = m->private; 239 struct proc_maps_private *priv = m->private;
137 struct task_struct *task = priv->task; 240 struct task_struct *task = priv->task;
@@ -191,41 +294,71 @@ static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats
191 } 294 }
192 seq_putc(m, '\n'); 295 seq_putc(m, '\n');
193 296
194 if (mss)
195 seq_printf(m,
196 "Size: %8lu kB\n"
197 "Rss: %8lu kB\n"
198 "Shared_Clean: %8lu kB\n"
199 "Shared_Dirty: %8lu kB\n"
200 "Private_Clean: %8lu kB\n"
201 "Private_Dirty: %8lu kB\n"
202 "Referenced: %8lu kB\n",
203 (vma->vm_end - vma->vm_start) >> 10,
204 mss->resident >> 10,
205 mss->shared_clean >> 10,
206 mss->shared_dirty >> 10,
207 mss->private_clean >> 10,
208 mss->private_dirty >> 10,
209 mss->referenced >> 10);
210
211 if (m->count < m->size) /* vma is copied successfully */ 297 if (m->count < m->size) /* vma is copied successfully */
212 m->version = (vma != get_gate_vma(task))? vma->vm_start: 0; 298 m->version = (vma != get_gate_vma(task))? vma->vm_start: 0;
213 return 0; 299 return 0;
214} 300}
215 301
216static int show_map(struct seq_file *m, void *v) 302static struct seq_operations proc_pid_maps_op = {
303 .start = m_start,
304 .next = m_next,
305 .stop = m_stop,
306 .show = show_map
307};
308
309static int maps_open(struct inode *inode, struct file *file)
217{ 310{
218 return show_map_internal(m, v, NULL); 311 return do_maps_open(inode, file, &proc_pid_maps_op);
219} 312}
220 313
221static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd, 314const struct file_operations proc_maps_operations = {
222 unsigned long addr, unsigned long end, 315 .open = maps_open,
223 void *private) 316 .read = seq_read,
317 .llseek = seq_lseek,
318 .release = seq_release_private,
319};
320
321/*
322 * Proportional Set Size(PSS): my share of RSS.
323 *
324 * PSS of a process is the count of pages it has in memory, where each
325 * page is divided by the number of processes sharing it. So if a
326 * process has 1000 pages all to itself, and 1000 shared with one other
327 * process, its PSS will be 1500.
328 *
329 * To keep (accumulated) division errors low, we adopt a 64bit
330 * fixed-point pss counter to minimize division errors. So (pss >>
331 * PSS_SHIFT) would be the real byte count.
332 *
333 * A shift of 12 before division means (assuming 4K page size):
334 * - 1M 3-user-pages add up to 8KB errors;
335 * - supports mapcount up to 2^24, or 16M;
336 * - supports PSS up to 2^52 bytes, or 4PB.
337 */
338#define PSS_SHIFT 12
339
340#ifdef CONFIG_PROC_PAGE_MONITOR
341struct mem_size_stats
342{
343 struct vm_area_struct *vma;
344 unsigned long resident;
345 unsigned long shared_clean;
346 unsigned long shared_dirty;
347 unsigned long private_clean;
348 unsigned long private_dirty;
349 unsigned long referenced;
350 u64 pss;
351};
352
353static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
354 void *private)
224{ 355{
225 struct mem_size_stats *mss = private; 356 struct mem_size_stats *mss = private;
357 struct vm_area_struct *vma = mss->vma;
226 pte_t *pte, ptent; 358 pte_t *pte, ptent;
227 spinlock_t *ptl; 359 spinlock_t *ptl;
228 struct page *page; 360 struct page *page;
361 int mapcount;
229 362
230 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); 363 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
231 for (; addr != end; pte++, addr += PAGE_SIZE) { 364 for (; addr != end; pte++, addr += PAGE_SIZE) {
@@ -242,26 +375,88 @@ static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
242 /* Accumulate the size in pages that have been accessed. */ 375 /* Accumulate the size in pages that have been accessed. */
243 if (pte_young(ptent) || PageReferenced(page)) 376 if (pte_young(ptent) || PageReferenced(page))
244 mss->referenced += PAGE_SIZE; 377 mss->referenced += PAGE_SIZE;
245 if (page_mapcount(page) >= 2) { 378 mapcount = page_mapcount(page);
379 if (mapcount >= 2) {
246 if (pte_dirty(ptent)) 380 if (pte_dirty(ptent))
247 mss->shared_dirty += PAGE_SIZE; 381 mss->shared_dirty += PAGE_SIZE;
248 else 382 else
249 mss->shared_clean += PAGE_SIZE; 383 mss->shared_clean += PAGE_SIZE;
384 mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;
250 } else { 385 } else {
251 if (pte_dirty(ptent)) 386 if (pte_dirty(ptent))
252 mss->private_dirty += PAGE_SIZE; 387 mss->private_dirty += PAGE_SIZE;
253 else 388 else
254 mss->private_clean += PAGE_SIZE; 389 mss->private_clean += PAGE_SIZE;
390 mss->pss += (PAGE_SIZE << PSS_SHIFT);
255 } 391 }
256 } 392 }
257 pte_unmap_unlock(pte - 1, ptl); 393 pte_unmap_unlock(pte - 1, ptl);
258 cond_resched(); 394 cond_resched();
395 return 0;
259} 396}
260 397
261static void clear_refs_pte_range(struct vm_area_struct *vma, pmd_t *pmd, 398static struct mm_walk smaps_walk = { .pmd_entry = smaps_pte_range };
262 unsigned long addr, unsigned long end, 399
263 void *private) 400static int show_smap(struct seq_file *m, void *v)
264{ 401{
402 struct vm_area_struct *vma = v;
403 struct mem_size_stats mss;
404 int ret;
405
406 memset(&mss, 0, sizeof mss);
407 mss.vma = vma;
408 if (vma->vm_mm && !is_vm_hugetlb_page(vma))
409 walk_page_range(vma->vm_mm, vma->vm_start, vma->vm_end,
410 &smaps_walk, &mss);
411
412 ret = show_map(m, v);
413 if (ret)
414 return ret;
415
416 seq_printf(m,
417 "Size: %8lu kB\n"
418 "Rss: %8lu kB\n"
419 "Pss: %8lu kB\n"
420 "Shared_Clean: %8lu kB\n"
421 "Shared_Dirty: %8lu kB\n"
422 "Private_Clean: %8lu kB\n"
423 "Private_Dirty: %8lu kB\n"
424 "Referenced: %8lu kB\n",
425 (vma->vm_end - vma->vm_start) >> 10,
426 mss.resident >> 10,
427 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
428 mss.shared_clean >> 10,
429 mss.shared_dirty >> 10,
430 mss.private_clean >> 10,
431 mss.private_dirty >> 10,
432 mss.referenced >> 10);
433
434 return ret;
435}
436
437static struct seq_operations proc_pid_smaps_op = {
438 .start = m_start,
439 .next = m_next,
440 .stop = m_stop,
441 .show = show_smap
442};
443
444static int smaps_open(struct inode *inode, struct file *file)
445{
446 return do_maps_open(inode, file, &proc_pid_smaps_op);
447}
448
449const struct file_operations proc_smaps_operations = {
450 .open = smaps_open,
451 .read = seq_read,
452 .llseek = seq_lseek,
453 .release = seq_release_private,
454};
455
456static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
457 unsigned long end, void *private)
458{
459 struct vm_area_struct *vma = private;
265 pte_t *pte, ptent; 460 pte_t *pte, ptent;
266 spinlock_t *ptl; 461 spinlock_t *ptl;
267 struct page *page; 462 struct page *page;
@@ -282,235 +477,248 @@ static void clear_refs_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
282 } 477 }
283 pte_unmap_unlock(pte - 1, ptl); 478 pte_unmap_unlock(pte - 1, ptl);
284 cond_resched(); 479 cond_resched();
480 return 0;
285} 481}
286 482
287static inline void walk_pmd_range(struct pmd_walker *walker, pud_t *pud, 483static struct mm_walk clear_refs_walk = { .pmd_entry = clear_refs_pte_range };
288 unsigned long addr, unsigned long end) 484
485static ssize_t clear_refs_write(struct file *file, const char __user *buf,
486 size_t count, loff_t *ppos)
289{ 487{
290 pmd_t *pmd; 488 struct task_struct *task;
291 unsigned long next; 489 char buffer[PROC_NUMBUF], *end;
490 struct mm_struct *mm;
491 struct vm_area_struct *vma;
292 492
293 for (pmd = pmd_offset(pud, addr); addr != end; 493 memset(buffer, 0, sizeof(buffer));
294 pmd++, addr = next) { 494 if (count > sizeof(buffer) - 1)
295 next = pmd_addr_end(addr, end); 495 count = sizeof(buffer) - 1;
296 if (pmd_none_or_clear_bad(pmd)) 496 if (copy_from_user(buffer, buf, count))
297 continue; 497 return -EFAULT;
298 walker->action(walker->vma, pmd, addr, next, walker->private); 498 if (!simple_strtol(buffer, &end, 0))
499 return -EINVAL;
500 if (*end == '\n')
501 end++;
502 task = get_proc_task(file->f_path.dentry->d_inode);
503 if (!task)
504 return -ESRCH;
505 mm = get_task_mm(task);
506 if (mm) {
507 down_read(&mm->mmap_sem);
508 for (vma = mm->mmap; vma; vma = vma->vm_next)
509 if (!is_vm_hugetlb_page(vma))
510 walk_page_range(mm, vma->vm_start, vma->vm_end,
511 &clear_refs_walk, vma);
512 flush_tlb_mm(mm);
513 up_read(&mm->mmap_sem);
514 mmput(mm);
299 } 515 }
516 put_task_struct(task);
517 if (end - buffer == 0)
518 return -EIO;
519 return end - buffer;
300} 520}
301 521
302static inline void walk_pud_range(struct pmd_walker *walker, pgd_t *pgd, 522const struct file_operations proc_clear_refs_operations = {
303 unsigned long addr, unsigned long end) 523 .write = clear_refs_write,
304{ 524};
305 pud_t *pud;
306 unsigned long next;
307 525
308 for (pud = pud_offset(pgd, addr); addr != end; 526struct pagemapread {
309 pud++, addr = next) { 527 char __user *out, *end;
310 next = pud_addr_end(addr, end); 528};
311 if (pud_none_or_clear_bad(pud)) 529
312 continue; 530#define PM_ENTRY_BYTES sizeof(u64)
313 walk_pmd_range(walker, pud, addr, next); 531#define PM_RESERVED_BITS 3
532#define PM_RESERVED_OFFSET (64 - PM_RESERVED_BITS)
533#define PM_RESERVED_MASK (((1LL<<PM_RESERVED_BITS)-1) << PM_RESERVED_OFFSET)
534#define PM_SPECIAL(nr) (((nr) << PM_RESERVED_OFFSET) | PM_RESERVED_MASK)
535#define PM_NOT_PRESENT PM_SPECIAL(1LL)
536#define PM_SWAP PM_SPECIAL(2LL)
537#define PM_END_OF_BUFFER 1
538
539static int add_to_pagemap(unsigned long addr, u64 pfn,
540 struct pagemapread *pm)
541{
542 /*
543 * Make sure there's room in the buffer for an
544 * entire entry. Otherwise, only copy part of
545 * the pfn.
546 */
547 if (pm->out + PM_ENTRY_BYTES >= pm->end) {
548 if (copy_to_user(pm->out, &pfn, pm->end - pm->out))
549 return -EFAULT;
550 pm->out = pm->end;
551 return PM_END_OF_BUFFER;
314 } 552 }
553
554 if (put_user(pfn, pm->out))
555 return -EFAULT;
556 pm->out += PM_ENTRY_BYTES;
557 return 0;
315} 558}
316 559
317/* 560static int pagemap_pte_hole(unsigned long start, unsigned long end,
318 * walk_page_range - walk the page tables of a VMA with a callback 561 void *private)
319 * @vma - VMA to walk
320 * @action - callback invoked for every bottom-level (PTE) page table
321 * @private - private data passed to the callback function
322 *
323 * Recursively walk the page table for the memory area in a VMA, calling
324 * a callback for every bottom-level (PTE) page table.
325 */
326static inline void walk_page_range(struct vm_area_struct *vma,
327 void (*action)(struct vm_area_struct *,
328 pmd_t *, unsigned long,
329 unsigned long, void *),
330 void *private)
331{ 562{
332 unsigned long addr = vma->vm_start; 563 struct pagemapread *pm = private;
333 unsigned long end = vma->vm_end; 564 unsigned long addr;
334 struct pmd_walker walker = { 565 int err = 0;
335 .vma = vma, 566 for (addr = start; addr < end; addr += PAGE_SIZE) {
336 .private = private, 567 err = add_to_pagemap(addr, PM_NOT_PRESENT, pm);
337 .action = action, 568 if (err)
338 }; 569 break;
339 pgd_t *pgd;
340 unsigned long next;
341
342 for (pgd = pgd_offset(vma->vm_mm, addr); addr != end;
343 pgd++, addr = next) {
344 next = pgd_addr_end(addr, end);
345 if (pgd_none_or_clear_bad(pgd))
346 continue;
347 walk_pud_range(&walker, pgd, addr, next);
348 } 570 }
571 return err;
349} 572}
350 573
351static int show_smap(struct seq_file *m, void *v) 574u64 swap_pte_to_pagemap_entry(pte_t pte)
352{ 575{
353 struct vm_area_struct *vma = v; 576 swp_entry_t e = pte_to_swp_entry(pte);
354 struct mem_size_stats mss; 577 return PM_SWAP | swp_type(e) | (swp_offset(e) << MAX_SWAPFILES_SHIFT);
355
356 memset(&mss, 0, sizeof mss);
357 if (vma->vm_mm && !is_vm_hugetlb_page(vma))
358 walk_page_range(vma, smaps_pte_range, &mss);
359 return show_map_internal(m, v, &mss);
360} 578}
361 579
362void clear_refs_smap(struct mm_struct *mm) 580static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
581 void *private)
363{ 582{
364 struct vm_area_struct *vma; 583 struct pagemapread *pm = private;
584 pte_t *pte;
585 int err = 0;
586
587 for (; addr != end; addr += PAGE_SIZE) {
588 u64 pfn = PM_NOT_PRESENT;
589 pte = pte_offset_map(pmd, addr);
590 if (is_swap_pte(*pte))
591 pfn = swap_pte_to_pagemap_entry(*pte);
592 else if (pte_present(*pte))
593 pfn = pte_pfn(*pte);
594 /* unmap so we're not in atomic when we copy to userspace */
595 pte_unmap(pte);
596 err = add_to_pagemap(addr, pfn, pm);
597 if (err)
598 return err;
599 }
365 600
366 down_read(&mm->mmap_sem); 601 cond_resched();
367 for (vma = mm->mmap; vma; vma = vma->vm_next) 602
368 if (vma->vm_mm && !is_vm_hugetlb_page(vma)) 603 return err;
369 walk_page_range(vma, clear_refs_pte_range, NULL);
370 flush_tlb_mm(mm);
371 up_read(&mm->mmap_sem);
372} 604}
373 605
374static void *m_start(struct seq_file *m, loff_t *pos) 606static struct mm_walk pagemap_walk = {
607 .pmd_entry = pagemap_pte_range,
608 .pte_hole = pagemap_pte_hole
609};
610
611/*
612 * /proc/pid/pagemap - an array mapping virtual pages to pfns
613 *
614 * For each page in the address space, this file contains one 64-bit
615 * entry representing the corresponding physical page frame number
616 * (PFN) if the page is present. If there is a swap entry for the
617 * physical page, then an encoding of the swap file number and the
618 * page's offset into the swap file are returned. If no page is
619 * present at all, PM_NOT_PRESENT is returned. This allows determining
620 * precisely which pages are mapped (or in swap) and comparing mapped
621 * pages between processes.
622 *
623 * Efficient users of this interface will use /proc/pid/maps to
624 * determine which areas of memory are actually mapped and llseek to
625 * skip over unmapped regions.
626 */
627static ssize_t pagemap_read(struct file *file, char __user *buf,
628 size_t count, loff_t *ppos)
375{ 629{
376 struct proc_maps_private *priv = m->private; 630 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
377 unsigned long last_addr = m->version; 631 struct page **pages, *page;
632 unsigned long uaddr, uend;
378 struct mm_struct *mm; 633 struct mm_struct *mm;
379 struct vm_area_struct *vma, *tail_vma = NULL; 634 struct pagemapread pm;
380 loff_t l = *pos; 635 int pagecount;
381 636 int ret = -ESRCH;
382 /* Clear the per syscall fields in priv */
383 priv->task = NULL;
384 priv->tail_vma = NULL;
385 637
386 /* 638 if (!task)
387 * We remember last_addr rather than next_addr to hit with 639 goto out;
388 * mmap_cache most of the time. We have zero last_addr at
389 * the beginning and also after lseek. We will have -1 last_addr
390 * after the end of the vmas.
391 */
392 640
393 if (last_addr == -1UL) 641 ret = -EACCES;
394 return NULL; 642 if (!ptrace_may_attach(task))
643 goto out;
395 644
396 priv->task = get_pid_task(priv->pid, PIDTYPE_PID); 645 ret = -EINVAL;
397 if (!priv->task) 646 /* file position must be aligned */
398 return NULL; 647 if (*ppos % PM_ENTRY_BYTES)
648 goto out;
399 649
400 mm = mm_for_maps(priv->task); 650 ret = 0;
651 mm = get_task_mm(task);
401 if (!mm) 652 if (!mm)
402 return NULL;
403
404 priv->tail_vma = tail_vma = get_gate_vma(priv->task);
405
406 /* Start with last addr hint */
407 if (last_addr && (vma = find_vma(mm, last_addr))) {
408 vma = vma->vm_next;
409 goto out; 653 goto out;
410 }
411 654
412 /* 655 ret = -ENOMEM;
413 * Check the vma index is within the range and do 656 uaddr = (unsigned long)buf & PAGE_MASK;
414 * sequential scan until m_index. 657 uend = (unsigned long)(buf + count);
415 */ 658 pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE;
416 vma = NULL; 659 pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL);
417 if ((unsigned long)l < mm->map_count) { 660 if (!pages)
418 vma = mm->mmap; 661 goto out_task;
419 while (l-- && vma)
420 vma = vma->vm_next;
421 goto out;
422 }
423 662
424 if (l != mm->map_count) 663 down_read(&current->mm->mmap_sem);
425 tail_vma = NULL; /* After gate vma */ 664 ret = get_user_pages(current, current->mm, uaddr, pagecount,
665 1, 0, pages, NULL);
666 up_read(&current->mm->mmap_sem);
426 667
427out: 668 if (ret < 0)
428 if (vma) 669 goto out_free;
429 return vma;
430 670
431 /* End of vmas has been reached */ 671 pm.out = buf;
432 m->version = (tail_vma != NULL)? 0: -1UL; 672 pm.end = buf + count;
433 up_read(&mm->mmap_sem);
434 mmput(mm);
435 return tail_vma;
436}
437 673
438static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma) 674 if (!ptrace_may_attach(task)) {
439{ 675 ret = -EIO;
440 if (vma && vma != priv->tail_vma) { 676 } else {
441 struct mm_struct *mm = vma->vm_mm; 677 unsigned long src = *ppos;
442 up_read(&mm->mmap_sem); 678 unsigned long svpfn = src / PM_ENTRY_BYTES;
443 mmput(mm); 679 unsigned long start_vaddr = svpfn << PAGE_SHIFT;
680 unsigned long end_vaddr = TASK_SIZE_OF(task);
681
682 /* watch out for wraparound */
683 if (svpfn > TASK_SIZE_OF(task) >> PAGE_SHIFT)
684 start_vaddr = end_vaddr;
685
686 /*
687 * The odds are that this will stop walking way
688 * before end_vaddr, because the length of the
689 * user buffer is tracked in "pm", and the walk
690 * will stop when we hit the end of the buffer.
691 */
692 ret = walk_page_range(mm, start_vaddr, end_vaddr,
693 &pagemap_walk, &pm);
694 if (ret == PM_END_OF_BUFFER)
695 ret = 0;
696 /* don't need mmap_sem for these, but this looks cleaner */
697 *ppos += pm.out - buf;
698 if (!ret)
699 ret = pm.out - buf;
444 } 700 }
445}
446
447static void *m_next(struct seq_file *m, void *v, loff_t *pos)
448{
449 struct proc_maps_private *priv = m->private;
450 struct vm_area_struct *vma = v;
451 struct vm_area_struct *tail_vma = priv->tail_vma;
452
453 (*pos)++;
454 if (vma && (vma != tail_vma) && vma->vm_next)
455 return vma->vm_next;
456 vma_stop(priv, vma);
457 return (vma != tail_vma)? tail_vma: NULL;
458}
459
460static void m_stop(struct seq_file *m, void *v)
461{
462 struct proc_maps_private *priv = m->private;
463 struct vm_area_struct *vma = v;
464 701
465 vma_stop(priv, vma); 702 for (; pagecount; pagecount--) {
466 if (priv->task) 703 page = pages[pagecount-1];
467 put_task_struct(priv->task); 704 if (!PageReserved(page))
468} 705 SetPageDirty(page);
469 706 page_cache_release(page);
470static struct seq_operations proc_pid_maps_op = {
471 .start = m_start,
472 .next = m_next,
473 .stop = m_stop,
474 .show = show_map
475};
476
477static struct seq_operations proc_pid_smaps_op = {
478 .start = m_start,
479 .next = m_next,
480 .stop = m_stop,
481 .show = show_smap
482};
483
484static int do_maps_open(struct inode *inode, struct file *file,
485 struct seq_operations *ops)
486{
487 struct proc_maps_private *priv;
488 int ret = -ENOMEM;
489 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
490 if (priv) {
491 priv->pid = proc_pid(inode);
492 ret = seq_open(file, ops);
493 if (!ret) {
494 struct seq_file *m = file->private_data;
495 m->private = priv;
496 } else {
497 kfree(priv);
498 }
499 } 707 }
708 mmput(mm);
709out_free:
710 kfree(pages);
711out_task:
712 put_task_struct(task);
713out:
500 return ret; 714 return ret;
501} 715}
502 716
503static int maps_open(struct inode *inode, struct file *file) 717const struct file_operations proc_pagemap_operations = {
504{ 718 .llseek = mem_lseek, /* borrow this */
505 return do_maps_open(inode, file, &proc_pid_maps_op); 719 .read = pagemap_read,
506}
507
508const struct file_operations proc_maps_operations = {
509 .open = maps_open,
510 .read = seq_read,
511 .llseek = seq_lseek,
512 .release = seq_release_private,
513}; 720};
721#endif /* CONFIG_PROC_PAGE_MONITOR */
514 722
515#ifdef CONFIG_NUMA 723#ifdef CONFIG_NUMA
516extern int show_numa_map(struct seq_file *m, void *v); 724extern int show_numa_map(struct seq_file *m, void *v);
@@ -545,15 +753,3 @@ const struct file_operations proc_numa_maps_operations = {
545 .release = seq_release_private, 753 .release = seq_release_private,
546}; 754};
547#endif 755#endif
548
549static int smaps_open(struct inode *inode, struct file *file)
550{
551 return do_maps_open(inode, file, &proc_pid_smaps_op);
552}
553
554const struct file_operations proc_smaps_operations = {
555 .open = smaps_open,
556 .read = seq_read,
557 .llseek = seq_lseek,
558 .release = seq_release_private,
559};
diff --git a/fs/qnx4/inode.c b/fs/qnx4/inode.c
index 638bdb963213..b31ab78052b3 100644
--- a/fs/qnx4/inode.c
+++ b/fs/qnx4/inode.c
@@ -125,7 +125,6 @@ static int qnx4_write_inode(struct inode *inode, int unused)
125static void qnx4_put_super(struct super_block *sb); 125static void qnx4_put_super(struct super_block *sb);
126static struct inode *qnx4_alloc_inode(struct super_block *sb); 126static struct inode *qnx4_alloc_inode(struct super_block *sb);
127static void qnx4_destroy_inode(struct inode *inode); 127static void qnx4_destroy_inode(struct inode *inode);
128static void qnx4_read_inode(struct inode *);
129static int qnx4_remount(struct super_block *sb, int *flags, char *data); 128static int qnx4_remount(struct super_block *sb, int *flags, char *data);
130static int qnx4_statfs(struct dentry *, struct kstatfs *); 129static int qnx4_statfs(struct dentry *, struct kstatfs *);
131 130
@@ -133,7 +132,6 @@ static const struct super_operations qnx4_sops =
133{ 132{
134 .alloc_inode = qnx4_alloc_inode, 133 .alloc_inode = qnx4_alloc_inode,
135 .destroy_inode = qnx4_destroy_inode, 134 .destroy_inode = qnx4_destroy_inode,
136 .read_inode = qnx4_read_inode,
137 .put_super = qnx4_put_super, 135 .put_super = qnx4_put_super,
138 .statfs = qnx4_statfs, 136 .statfs = qnx4_statfs,
139 .remount_fs = qnx4_remount, 137 .remount_fs = qnx4_remount,
@@ -357,6 +355,7 @@ static int qnx4_fill_super(struct super_block *s, void *data, int silent)
357 struct inode *root; 355 struct inode *root;
358 const char *errmsg; 356 const char *errmsg;
359 struct qnx4_sb_info *qs; 357 struct qnx4_sb_info *qs;
358 int ret = -EINVAL;
360 359
361 qs = kzalloc(sizeof(struct qnx4_sb_info), GFP_KERNEL); 360 qs = kzalloc(sizeof(struct qnx4_sb_info), GFP_KERNEL);
362 if (!qs) 361 if (!qs)
@@ -396,12 +395,14 @@ static int qnx4_fill_super(struct super_block *s, void *data, int silent)
396 } 395 }
397 396
398 /* does root not have inode number QNX4_ROOT_INO ?? */ 397 /* does root not have inode number QNX4_ROOT_INO ?? */
399 root = iget(s, QNX4_ROOT_INO * QNX4_INODES_PER_BLOCK); 398 root = qnx4_iget(s, QNX4_ROOT_INO * QNX4_INODES_PER_BLOCK);
400 if (!root) { 399 if (IS_ERR(root)) {
401 printk("qnx4: get inode failed\n"); 400 printk("qnx4: get inode failed\n");
401 ret = PTR_ERR(root);
402 goto out; 402 goto out;
403 } 403 }
404 404
405 ret = -ENOMEM;
405 s->s_root = d_alloc_root(root); 406 s->s_root = d_alloc_root(root);
406 if (s->s_root == NULL) 407 if (s->s_root == NULL)
407 goto outi; 408 goto outi;
@@ -417,7 +418,7 @@ static int qnx4_fill_super(struct super_block *s, void *data, int silent)
417 outnobh: 418 outnobh:
418 kfree(qs); 419 kfree(qs);
419 s->s_fs_info = NULL; 420 s->s_fs_info = NULL;
420 return -EINVAL; 421 return ret;
421} 422}
422 423
423static void qnx4_put_super(struct super_block *sb) 424static void qnx4_put_super(struct super_block *sb)
@@ -462,29 +463,38 @@ static const struct address_space_operations qnx4_aops = {
462 .bmap = qnx4_bmap 463 .bmap = qnx4_bmap
463}; 464};
464 465
465static void qnx4_read_inode(struct inode *inode) 466struct inode *qnx4_iget(struct super_block *sb, unsigned long ino)
466{ 467{
467 struct buffer_head *bh; 468 struct buffer_head *bh;
468 struct qnx4_inode_entry *raw_inode; 469 struct qnx4_inode_entry *raw_inode;
469 int block, ino; 470 int block;
470 struct super_block *sb = inode->i_sb; 471 struct qnx4_inode_entry *qnx4_inode;
471 struct qnx4_inode_entry *qnx4_inode = qnx4_raw_inode(inode); 472 struct inode *inode;
472 473
473 ino = inode->i_ino; 474 inode = iget_locked(sb, ino);
475 if (!inode)
476 return ERR_PTR(-ENOMEM);
477 if (!(inode->i_state & I_NEW))
478 return inode;
479
480 qnx4_inode = qnx4_raw_inode(inode);
474 inode->i_mode = 0; 481 inode->i_mode = 0;
475 482
476 QNX4DEBUG(("Reading inode : [%d]\n", ino)); 483 QNX4DEBUG(("Reading inode : [%d]\n", ino));
477 if (!ino) { 484 if (!ino) {
478 printk("qnx4: bad inode number on dev %s: %d is out of range\n", 485 printk(KERN_ERR "qnx4: bad inode number on dev %s: %lu is "
486 "out of range\n",
479 sb->s_id, ino); 487 sb->s_id, ino);
480 return; 488 iget_failed(inode);
489 return ERR_PTR(-EIO);
481 } 490 }
482 block = ino / QNX4_INODES_PER_BLOCK; 491 block = ino / QNX4_INODES_PER_BLOCK;
483 492
484 if (!(bh = sb_bread(sb, block))) { 493 if (!(bh = sb_bread(sb, block))) {
485 printk("qnx4: major problem: unable to read inode from dev " 494 printk("qnx4: major problem: unable to read inode from dev "
486 "%s\n", sb->s_id); 495 "%s\n", sb->s_id);
487 return; 496 iget_failed(inode);
497 return ERR_PTR(-EIO);
488 } 498 }
489 raw_inode = ((struct qnx4_inode_entry *) bh->b_data) + 499 raw_inode = ((struct qnx4_inode_entry *) bh->b_data) +
490 (ino % QNX4_INODES_PER_BLOCK); 500 (ino % QNX4_INODES_PER_BLOCK);
@@ -515,9 +525,16 @@ static void qnx4_read_inode(struct inode *inode)
515 inode->i_op = &page_symlink_inode_operations; 525 inode->i_op = &page_symlink_inode_operations;
516 inode->i_mapping->a_ops = &qnx4_aops; 526 inode->i_mapping->a_ops = &qnx4_aops;
517 qnx4_i(inode)->mmu_private = inode->i_size; 527 qnx4_i(inode)->mmu_private = inode->i_size;
518 } else 528 } else {
519 printk("qnx4: bad inode %d on dev %s\n",ino,sb->s_id); 529 printk(KERN_ERR "qnx4: bad inode %lu on dev %s\n",
530 ino, sb->s_id);
531 iget_failed(inode);
532 brelse(bh);
533 return ERR_PTR(-EIO);
534 }
520 brelse(bh); 535 brelse(bh);
536 unlock_new_inode(inode);
537 return inode;
521} 538}
522 539
523static struct kmem_cache *qnx4_inode_cachep; 540static struct kmem_cache *qnx4_inode_cachep;
diff --git a/fs/qnx4/namei.c b/fs/qnx4/namei.c
index 733cdf01d645..775eed3a4085 100644
--- a/fs/qnx4/namei.c
+++ b/fs/qnx4/namei.c
@@ -128,10 +128,12 @@ struct dentry * qnx4_lookup(struct inode *dir, struct dentry *dentry, struct nam
128 } 128 }
129 brelse(bh); 129 brelse(bh);
130 130
131 if ((foundinode = iget(dir->i_sb, ino)) == NULL) { 131 foundinode = qnx4_iget(dir->i_sb, ino);
132 if (IS_ERR(foundinode)) {
132 unlock_kernel(); 133 unlock_kernel();
133 QNX4DEBUG(("qnx4: lookup->iget -> NULL\n")); 134 QNX4DEBUG(("qnx4: lookup->iget -> error %ld\n",
134 return ERR_PTR(-EACCES); 135 PTR_ERR(foundinode)));
136 return ERR_CAST(foundinode);
135 } 137 }
136out: 138out:
137 unlock_kernel(); 139 unlock_kernel();
diff --git a/fs/quota.c b/fs/quota.c
index 99b24b52bfc8..84f28dd72116 100644
--- a/fs/quota.c
+++ b/fs/quota.c
@@ -341,11 +341,11 @@ static inline struct super_block *quotactl_block(const char __user *special)
341 char *tmp = getname(special); 341 char *tmp = getname(special);
342 342
343 if (IS_ERR(tmp)) 343 if (IS_ERR(tmp))
344 return ERR_PTR(PTR_ERR(tmp)); 344 return ERR_CAST(tmp);
345 bdev = lookup_bdev(tmp); 345 bdev = lookup_bdev(tmp);
346 putname(tmp); 346 putname(tmp);
347 if (IS_ERR(bdev)) 347 if (IS_ERR(bdev))
348 return ERR_PTR(PTR_ERR(bdev)); 348 return ERR_CAST(bdev);
349 sb = get_super(bdev); 349 sb = get_super(bdev);
350 bdput(bdev); 350 bdput(bdev);
351 if (!sb) 351 if (!sb)
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c
index 16b331dd9913..f491ceb5af02 100644
--- a/fs/reiserfs/bitmap.c
+++ b/fs/reiserfs/bitmap.c
@@ -272,7 +272,7 @@ static inline int block_group_used(struct super_block *s, u32 id)
272 272
273 /* If we don't have cached information on this bitmap block, we're 273 /* If we don't have cached information on this bitmap block, we're
274 * going to have to load it later anyway. Loading it here allows us 274 * going to have to load it later anyway. Loading it here allows us
275 * to make a better decision. This favors long-term performace gain 275 * to make a better decision. This favors long-term performance gain
276 * with a better on-disk layout vs. a short term gain of skipping the 276 * with a better on-disk layout vs. a short term gain of skipping the
277 * read and potentially having a bad placement. */ 277 * read and potentially having a bad placement. */
278 if (info->free_count == UINT_MAX) { 278 if (info->free_count == UINT_MAX) {
@@ -663,7 +663,7 @@ static inline void new_hashed_relocation(reiserfs_blocknr_hint_t * hint)
663 663
664/* 664/*
665 * Relocation based on dirid, hashing them into a given bitmap block 665 * Relocation based on dirid, hashing them into a given bitmap block
666 * files. Formatted nodes are unaffected, a seperate policy covers them 666 * files. Formatted nodes are unaffected, a separate policy covers them
667 */ 667 */
668static void dirid_groups(reiserfs_blocknr_hint_t * hint) 668static void dirid_groups(reiserfs_blocknr_hint_t * hint)
669{ 669{
@@ -688,7 +688,7 @@ static void dirid_groups(reiserfs_blocknr_hint_t * hint)
688 688
689/* 689/*
690 * Relocation based on oid, hashing them into a given bitmap block 690 * Relocation based on oid, hashing them into a given bitmap block
691 * files. Formatted nodes are unaffected, a seperate policy covers them 691 * files. Formatted nodes are unaffected, a separate policy covers them
692 */ 692 */
693static void oid_groups(reiserfs_blocknr_hint_t * hint) 693static void oid_groups(reiserfs_blocknr_hint_t * hint)
694{ 694{
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 231fd5ccadc5..57917932212e 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -1536,7 +1536,7 @@ static struct dentry *reiserfs_get_dentry(struct super_block *sb,
1536 if (!inode) 1536 if (!inode)
1537 inode = ERR_PTR(-ESTALE); 1537 inode = ERR_PTR(-ESTALE);
1538 if (IS_ERR(inode)) 1538 if (IS_ERR(inode))
1539 return ERR_PTR(PTR_ERR(inode)); 1539 return ERR_CAST(inode);
1540 result = d_alloc_anon(inode); 1540 result = d_alloc_anon(inode);
1541 if (!result) { 1541 if (!result) {
1542 iput(inode); 1542 iput(inode);
@@ -2143,7 +2143,7 @@ int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
2143 /* if we are not on a block boundary */ 2143 /* if we are not on a block boundary */
2144 if (length) { 2144 if (length) {
2145 length = blocksize - length; 2145 length = blocksize - length;
2146 zero_user_page(page, offset, length, KM_USER0); 2146 zero_user(page, offset, length);
2147 if (buffer_mapped(bh) && bh->b_blocknr != 0) { 2147 if (buffer_mapped(bh) && bh->b_blocknr != 0) {
2148 mark_buffer_dirty(bh); 2148 mark_buffer_dirty(bh);
2149 } 2149 }
@@ -2367,7 +2367,7 @@ static int reiserfs_write_full_page(struct page *page,
2367 unlock_page(page); 2367 unlock_page(page);
2368 return 0; 2368 return 0;
2369 } 2369 }
2370 zero_user_page(page, last_offset, PAGE_CACHE_SIZE - last_offset, KM_USER0); 2370 zero_user_segment(page, last_offset, PAGE_CACHE_SIZE);
2371 } 2371 }
2372 bh = head; 2372 bh = head;
2373 block = page->index << (PAGE_CACHE_SHIFT - s->s_blocksize_bits); 2373 block = page->index << (PAGE_CACHE_SHIFT - s->s_blocksize_bits);
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..eba037b3338f 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -155,7 +155,7 @@ static struct dentry *get_xa_file_dentry(const struct inode *inode,
155 155
156 xadir = open_xa_dir(inode, flags); 156 xadir = open_xa_dir(inode, flags);
157 if (IS_ERR(xadir)) { 157 if (IS_ERR(xadir)) {
158 return ERR_PTR(PTR_ERR(xadir)); 158 return ERR_CAST(xadir);
159 } else if (xadir && !xadir->d_inode) { 159 } else if (xadir && !xadir->d_inode) {
160 dput(xadir); 160 dput(xadir);
161 return ERR_PTR(-ENODATA); 161 return ERR_PTR(-ENODATA);
@@ -164,7 +164,7 @@ static struct dentry *get_xa_file_dentry(const struct inode *inode,
164 xafile = lookup_one_len(name, xadir, strlen(name)); 164 xafile = lookup_one_len(name, xadir, strlen(name));
165 if (IS_ERR(xafile)) { 165 if (IS_ERR(xafile)) {
166 dput(xadir); 166 dput(xadir);
167 return ERR_PTR(PTR_ERR(xafile)); 167 return ERR_CAST(xafile);
168 } 168 }
169 169
170 if (xafile->d_inode) { /* file exists */ 170 if (xafile->d_inode) { /* file exists */
@@ -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/romfs/inode.c b/fs/romfs/inode.c
index a49cf5b9a195..00b6f0a518c8 100644
--- a/fs/romfs/inode.c
+++ b/fs/romfs/inode.c
@@ -84,6 +84,8 @@ struct romfs_inode_info {
84 struct inode vfs_inode; 84 struct inode vfs_inode;
85}; 85};
86 86
87static struct inode *romfs_iget(struct super_block *, unsigned long);
88
87/* instead of private superblock data */ 89/* instead of private superblock data */
88static inline unsigned long romfs_maxsize(struct super_block *sb) 90static inline unsigned long romfs_maxsize(struct super_block *sb)
89{ 91{
@@ -117,7 +119,7 @@ static int romfs_fill_super(struct super_block *s, void *data, int silent)
117 struct buffer_head *bh; 119 struct buffer_head *bh;
118 struct romfs_super_block *rsb; 120 struct romfs_super_block *rsb;
119 struct inode *root; 121 struct inode *root;
120 int sz; 122 int sz, ret = -EINVAL;
121 123
122 /* I would parse the options here, but there are none.. :) */ 124 /* I would parse the options here, but there are none.. :) */
123 125
@@ -157,10 +159,13 @@ static int romfs_fill_super(struct super_block *s, void *data, int silent)
157 & ROMFH_MASK; 159 & ROMFH_MASK;
158 160
159 s->s_op = &romfs_ops; 161 s->s_op = &romfs_ops;
160 root = iget(s, sz); 162 root = romfs_iget(s, sz);
161 if (!root) 163 if (IS_ERR(root)) {
164 ret = PTR_ERR(root);
162 goto out; 165 goto out;
166 }
163 167
168 ret = -ENOMEM;
164 s->s_root = d_alloc_root(root); 169 s->s_root = d_alloc_root(root);
165 if (!s->s_root) 170 if (!s->s_root)
166 goto outiput; 171 goto outiput;
@@ -173,7 +178,7 @@ outiput:
173out: 178out:
174 brelse(bh); 179 brelse(bh);
175outnobh: 180outnobh:
176 return -EINVAL; 181 return ret;
177} 182}
178 183
179/* That's simple too. */ 184/* That's simple too. */
@@ -389,8 +394,11 @@ romfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
389 if ((be32_to_cpu(ri.next) & ROMFH_TYPE) == ROMFH_HRD) 394 if ((be32_to_cpu(ri.next) & ROMFH_TYPE) == ROMFH_HRD)
390 offset = be32_to_cpu(ri.spec) & ROMFH_MASK; 395 offset = be32_to_cpu(ri.spec) & ROMFH_MASK;
391 396
392 if ((inode = iget(dir->i_sb, offset))) 397 inode = romfs_iget(dir->i_sb, offset);
393 goto outi; 398 if (IS_ERR(inode)) {
399 res = PTR_ERR(inode);
400 goto out;
401 }
394 402
395 /* 403 /*
396 * it's a bit funky, _lookup needs to return an error code 404 * it's a bit funky, _lookup needs to return an error code
@@ -402,7 +410,7 @@ romfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
402 */ 410 */
403 411
404out0: inode = NULL; 412out0: inode = NULL;
405outi: res = 0; 413 res = 0;
406 d_add (dentry, inode); 414 d_add (dentry, inode);
407 415
408out: unlock_kernel(); 416out: unlock_kernel();
@@ -478,20 +486,29 @@ static mode_t romfs_modemap[] =
478 S_IFBLK+0600, S_IFCHR+0600, S_IFSOCK+0644, S_IFIFO+0644 486 S_IFBLK+0600, S_IFCHR+0600, S_IFSOCK+0644, S_IFIFO+0644
479}; 487};
480 488
481static void 489static struct inode *
482romfs_read_inode(struct inode *i) 490romfs_iget(struct super_block *sb, unsigned long ino)
483{ 491{
484 int nextfh, ino; 492 int nextfh;
485 struct romfs_inode ri; 493 struct romfs_inode ri;
494 struct inode *i;
495
496 ino &= ROMFH_MASK;
497 i = iget_locked(sb, ino);
498 if (!i)
499 return ERR_PTR(-ENOMEM);
500 if (!(i->i_state & I_NEW))
501 return i;
486 502
487 ino = i->i_ino & ROMFH_MASK;
488 i->i_mode = 0; 503 i->i_mode = 0;
489 504
490 /* Loop for finding the real hard link */ 505 /* Loop for finding the real hard link */
491 for(;;) { 506 for(;;) {
492 if (romfs_copyfrom(i, &ri, ino, ROMFH_SIZE) <= 0) { 507 if (romfs_copyfrom(i, &ri, ino, ROMFH_SIZE) <= 0) {
493 printk("romfs: read error for inode 0x%x\n", ino); 508 printk(KERN_ERR "romfs: read error for inode 0x%lx\n",
494 return; 509 ino);
510 iget_failed(i);
511 return ERR_PTR(-EIO);
495 } 512 }
496 /* XXX: do romfs_checksum here too (with name) */ 513 /* XXX: do romfs_checksum here too (with name) */
497 514
@@ -548,6 +565,8 @@ romfs_read_inode(struct inode *i)
548 init_special_inode(i, ino, 565 init_special_inode(i, ino,
549 MKDEV(nextfh>>16,nextfh&0xffff)); 566 MKDEV(nextfh>>16,nextfh&0xffff));
550 } 567 }
568 unlock_new_inode(i);
569 return i;
551} 570}
552 571
553static struct kmem_cache * romfs_inode_cachep; 572static struct kmem_cache * romfs_inode_cachep;
@@ -599,7 +618,6 @@ static int romfs_remount(struct super_block *sb, int *flags, char *data)
599static const struct super_operations romfs_ops = { 618static const struct super_operations romfs_ops = {
600 .alloc_inode = romfs_alloc_inode, 619 .alloc_inode = romfs_alloc_inode,
601 .destroy_inode = romfs_destroy_inode, 620 .destroy_inode = romfs_destroy_inode,
602 .read_inode = romfs_read_inode,
603 .statfs = romfs_statfs, 621 .statfs = romfs_statfs,
604 .remount_fs = romfs_remount, 622 .remount_fs = romfs_remount,
605}; 623};
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 fb7f7e8034df..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;
@@ -66,7 +67,7 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
66 BUILD_BUG_ON(sizeof(struct signalfd_siginfo) != 128); 67 BUILD_BUG_ON(sizeof(struct signalfd_siginfo) != 128);
67 68
68 /* 69 /*
69 * Unused memebers should be zero ... 70 * Unused members should be zero ...
70 */ 71 */
71 err = __clear_user(uinfo, sizeof(*uinfo)); 72 err = __clear_user(uinfo, sizeof(*uinfo));
72 73
diff --git a/fs/smbfs/inode.c b/fs/smbfs/inode.c
index 9416ead0c7aa..4e5c22ca802e 100644
--- a/fs/smbfs/inode.c
+++ b/fs/smbfs/inode.c
@@ -500,6 +500,13 @@ static int smb_fill_super(struct super_block *sb, void *raw_data, int silent)
500 struct smb_fattr root; 500 struct smb_fattr root;
501 int ver; 501 int ver;
502 void *mem; 502 void *mem;
503 static int warn_count;
504
505 if (warn_count < 5) {
506 warn_count++;
507 printk(KERN_EMERG "smbfs is deprecated and will be removed"
508 "from the 2.6.27 kernel. Please migrate to cifs\n");
509 }
503 510
504 if (!raw_data) 511 if (!raw_data)
505 goto out_no_data; 512 goto out_no_data;
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/sysv/inode.c b/fs/sysv/inode.c
index 81ec6c548c07..c5d60de0658f 100644
--- a/fs/sysv/inode.c
+++ b/fs/sysv/inode.c
@@ -169,20 +169,27 @@ void sysv_set_inode(struct inode *inode, dev_t rdev)
169 init_special_inode(inode, inode->i_mode, rdev); 169 init_special_inode(inode, inode->i_mode, rdev);
170} 170}
171 171
172static void sysv_read_inode(struct inode *inode) 172struct inode *sysv_iget(struct super_block *sb, unsigned int ino)
173{ 173{
174 struct super_block * sb = inode->i_sb;
175 struct sysv_sb_info * sbi = SYSV_SB(sb); 174 struct sysv_sb_info * sbi = SYSV_SB(sb);
176 struct buffer_head * bh; 175 struct buffer_head * bh;
177 struct sysv_inode * raw_inode; 176 struct sysv_inode * raw_inode;
178 struct sysv_inode_info * si; 177 struct sysv_inode_info * si;
179 unsigned int block, ino = inode->i_ino; 178 struct inode *inode;
179 unsigned int block;
180 180
181 if (!ino || ino > sbi->s_ninodes) { 181 if (!ino || ino > sbi->s_ninodes) {
182 printk("Bad inode number on dev %s: %d is out of range\n", 182 printk("Bad inode number on dev %s: %d is out of range\n",
183 inode->i_sb->s_id, ino); 183 sb->s_id, ino);
184 goto bad_inode; 184 return ERR_PTR(-EIO);
185 } 185 }
186
187 inode = iget_locked(sb, ino);
188 if (!inode)
189 return ERR_PTR(-ENOMEM);
190 if (!(inode->i_state & I_NEW))
191 return inode;
192
186 raw_inode = sysv_raw_inode(sb, ino, &bh); 193 raw_inode = sysv_raw_inode(sb, ino, &bh);
187 if (!raw_inode) { 194 if (!raw_inode) {
188 printk("Major problem: unable to read inode from dev %s\n", 195 printk("Major problem: unable to read inode from dev %s\n",
@@ -214,11 +221,12 @@ static void sysv_read_inode(struct inode *inode)
214 old_decode_dev(fs32_to_cpu(sbi, si->i_data[0]))); 221 old_decode_dev(fs32_to_cpu(sbi, si->i_data[0])));
215 else 222 else
216 sysv_set_inode(inode, 0); 223 sysv_set_inode(inode, 0);
217 return; 224 unlock_new_inode(inode);
225 return inode;
218 226
219bad_inode: 227bad_inode:
220 make_bad_inode(inode); 228 iget_failed(inode);
221 return; 229 return ERR_PTR(-EIO);
222} 230}
223 231
224static struct buffer_head * sysv_update_inode(struct inode * inode) 232static struct buffer_head * sysv_update_inode(struct inode * inode)
@@ -328,7 +336,6 @@ static void init_once(struct kmem_cache *cachep, void *p)
328const struct super_operations sysv_sops = { 336const struct super_operations sysv_sops = {
329 .alloc_inode = sysv_alloc_inode, 337 .alloc_inode = sysv_alloc_inode,
330 .destroy_inode = sysv_destroy_inode, 338 .destroy_inode = sysv_destroy_inode,
331 .read_inode = sysv_read_inode,
332 .write_inode = sysv_write_inode, 339 .write_inode = sysv_write_inode,
333 .delete_inode = sysv_delete_inode, 340 .delete_inode = sysv_delete_inode,
334 .put_super = sysv_put_super, 341 .put_super = sysv_put_super,
diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c
index 6bd850b7641a..a1f1ef33e81c 100644
--- a/fs/sysv/namei.c
+++ b/fs/sysv/namei.c
@@ -53,9 +53,9 @@ static struct dentry *sysv_lookup(struct inode * dir, struct dentry * dentry, st
53 ino = sysv_inode_by_name(dentry); 53 ino = sysv_inode_by_name(dentry);
54 54
55 if (ino) { 55 if (ino) {
56 inode = iget(dir->i_sb, ino); 56 inode = sysv_iget(dir->i_sb, ino);
57 if (!inode) 57 if (IS_ERR(inode))
58 return ERR_PTR(-EACCES); 58 return ERR_CAST(inode);
59 } 59 }
60 d_add(dentry, inode); 60 d_add(dentry, inode);
61 return NULL; 61 return NULL;
diff --git a/fs/sysv/super.c b/fs/sysv/super.c
index 6f9707a1b954..5a903da54551 100644
--- a/fs/sysv/super.c
+++ b/fs/sysv/super.c
@@ -332,8 +332,8 @@ static int complete_read_super(struct super_block *sb, int silent, int size)
332 sb->s_magic = SYSV_MAGIC_BASE + sbi->s_type; 332 sb->s_magic = SYSV_MAGIC_BASE + sbi->s_type;
333 /* set up enough so that it can read an inode */ 333 /* set up enough so that it can read an inode */
334 sb->s_op = &sysv_sops; 334 sb->s_op = &sysv_sops;
335 root_inode = iget(sb,SYSV_ROOT_INO); 335 root_inode = sysv_iget(sb, SYSV_ROOT_INO);
336 if (!root_inode || is_bad_inode(root_inode)) { 336 if (IS_ERR(root_inode)) {
337 printk("SysV FS: get root inode failed\n"); 337 printk("SysV FS: get root inode failed\n");
338 return 0; 338 return 0;
339 } 339 }
diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
index 64c03bdf06a5..42d51d1c05cd 100644
--- a/fs/sysv/sysv.h
+++ b/fs/sysv/sysv.h
@@ -141,6 +141,7 @@ extern int __sysv_write_begin(struct file *file, struct address_space *mapping,
141 struct page **pagep, void **fsdata); 141 struct page **pagep, void **fsdata);
142 142
143/* inode.c */ 143/* inode.c */
144extern struct inode *sysv_iget(struct super_block *, unsigned int);
144extern int sysv_write_inode(struct inode *, int); 145extern int sysv_write_inode(struct inode *, int);
145extern int sysv_sync_inode(struct inode *); 146extern int sysv_sync_inode(struct inode *);
146extern int sysv_sync_file(struct file *, struct dentry *, int); 147extern int sysv_sync_file(struct file *, struct dentry *, int);
diff --git a/fs/timerfd.c b/fs/timerfd.c
index 61983f3b107c..10c80b59ec4b 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -25,13 +25,15 @@ struct timerfd_ctx {
25 struct hrtimer tmr; 25 struct hrtimer tmr;
26 ktime_t tintv; 26 ktime_t tintv;
27 wait_queue_head_t wqh; 27 wait_queue_head_t wqh;
28 u64 ticks;
28 int expired; 29 int expired;
30 int clockid;
29}; 31};
30 32
31/* 33/*
32 * This gets called when the timer event triggers. We set the "expired" 34 * This gets called when the timer event triggers. We set the "expired"
33 * flag, but we do not re-arm the timer (in case it's necessary, 35 * flag, but we do not re-arm the timer (in case it's necessary,
34 * tintv.tv64 != 0) until the timer is read. 36 * tintv.tv64 != 0) until the timer is accessed.
35 */ 37 */
36static enum hrtimer_restart timerfd_tmrproc(struct hrtimer *htmr) 38static enum hrtimer_restart timerfd_tmrproc(struct hrtimer *htmr)
37{ 39{
@@ -40,13 +42,24 @@ static enum hrtimer_restart timerfd_tmrproc(struct hrtimer *htmr)
40 42
41 spin_lock_irqsave(&ctx->wqh.lock, flags); 43 spin_lock_irqsave(&ctx->wqh.lock, flags);
42 ctx->expired = 1; 44 ctx->expired = 1;
45 ctx->ticks++;
43 wake_up_locked(&ctx->wqh); 46 wake_up_locked(&ctx->wqh);
44 spin_unlock_irqrestore(&ctx->wqh.lock, flags); 47 spin_unlock_irqrestore(&ctx->wqh.lock, flags);
45 48
46 return HRTIMER_NORESTART; 49 return HRTIMER_NORESTART;
47} 50}
48 51
49static void timerfd_setup(struct timerfd_ctx *ctx, int clockid, int flags, 52static ktime_t timerfd_get_remaining(struct timerfd_ctx *ctx)
53{
54 ktime_t now, remaining;
55
56 now = ctx->tmr.base->get_time();
57 remaining = ktime_sub(ctx->tmr.expires, now);
58
59 return remaining.tv64 < 0 ? ktime_set(0, 0): remaining;
60}
61
62static void timerfd_setup(struct timerfd_ctx *ctx, int flags,
50 const struct itimerspec *ktmr) 63 const struct itimerspec *ktmr)
51{ 64{
52 enum hrtimer_mode htmode; 65 enum hrtimer_mode htmode;
@@ -57,8 +70,9 @@ static void timerfd_setup(struct timerfd_ctx *ctx, int clockid, int flags,
57 70
58 texp = timespec_to_ktime(ktmr->it_value); 71 texp = timespec_to_ktime(ktmr->it_value);
59 ctx->expired = 0; 72 ctx->expired = 0;
73 ctx->ticks = 0;
60 ctx->tintv = timespec_to_ktime(ktmr->it_interval); 74 ctx->tintv = timespec_to_ktime(ktmr->it_interval);
61 hrtimer_init(&ctx->tmr, clockid, htmode); 75 hrtimer_init(&ctx->tmr, ctx->clockid, htmode);
62 ctx->tmr.expires = texp; 76 ctx->tmr.expires = texp;
63 ctx->tmr.function = timerfd_tmrproc; 77 ctx->tmr.function = timerfd_tmrproc;
64 if (texp.tv64 != 0) 78 if (texp.tv64 != 0)
@@ -83,7 +97,7 @@ static unsigned int timerfd_poll(struct file *file, poll_table *wait)
83 poll_wait(file, &ctx->wqh, wait); 97 poll_wait(file, &ctx->wqh, wait);
84 98
85 spin_lock_irqsave(&ctx->wqh.lock, flags); 99 spin_lock_irqsave(&ctx->wqh.lock, flags);
86 if (ctx->expired) 100 if (ctx->ticks)
87 events |= POLLIN; 101 events |= POLLIN;
88 spin_unlock_irqrestore(&ctx->wqh.lock, flags); 102 spin_unlock_irqrestore(&ctx->wqh.lock, flags);
89 103
@@ -102,11 +116,11 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
102 return -EINVAL; 116 return -EINVAL;
103 spin_lock_irq(&ctx->wqh.lock); 117 spin_lock_irq(&ctx->wqh.lock);
104 res = -EAGAIN; 118 res = -EAGAIN;
105 if (!ctx->expired && !(file->f_flags & O_NONBLOCK)) { 119 if (!ctx->ticks && !(file->f_flags & O_NONBLOCK)) {
106 __add_wait_queue(&ctx->wqh, &wait); 120 __add_wait_queue(&ctx->wqh, &wait);
107 for (res = 0;;) { 121 for (res = 0;;) {
108 set_current_state(TASK_INTERRUPTIBLE); 122 set_current_state(TASK_INTERRUPTIBLE);
109 if (ctx->expired) { 123 if (ctx->ticks) {
110 res = 0; 124 res = 0;
111 break; 125 break;
112 } 126 }
@@ -121,22 +135,21 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
121 __remove_wait_queue(&ctx->wqh, &wait); 135 __remove_wait_queue(&ctx->wqh, &wait);
122 __set_current_state(TASK_RUNNING); 136 __set_current_state(TASK_RUNNING);
123 } 137 }
124 if (ctx->expired) { 138 if (ctx->ticks) {
125 ctx->expired = 0; 139 ticks = ctx->ticks;
126 if (ctx->tintv.tv64 != 0) { 140 if (ctx->expired && ctx->tintv.tv64) {
127 /* 141 /*
128 * If tintv.tv64 != 0, this is a periodic timer that 142 * If tintv.tv64 != 0, this is a periodic timer that
129 * needs to be re-armed. We avoid doing it in the timer 143 * needs to be re-armed. We avoid doing it in the timer
130 * callback to avoid DoS attacks specifying a very 144 * callback to avoid DoS attacks specifying a very
131 * short timer period. 145 * short timer period.
132 */ 146 */
133 ticks = (u64) 147 ticks += hrtimer_forward_now(&ctx->tmr,
134 hrtimer_forward(&ctx->tmr, 148 ctx->tintv) - 1;
135 hrtimer_cb_get_time(&ctx->tmr),
136 ctx->tintv);
137 hrtimer_restart(&ctx->tmr); 149 hrtimer_restart(&ctx->tmr);
138 } else 150 }
139 ticks = 1; 151 ctx->expired = 0;
152 ctx->ticks = 0;
140 } 153 }
141 spin_unlock_irq(&ctx->wqh.lock); 154 spin_unlock_irq(&ctx->wqh.lock);
142 if (ticks) 155 if (ticks)
@@ -150,76 +163,132 @@ static const struct file_operations timerfd_fops = {
150 .read = timerfd_read, 163 .read = timerfd_read,
151}; 164};
152 165
153asmlinkage long sys_timerfd(int ufd, int clockid, int flags, 166static struct file *timerfd_fget(int fd)
154 const struct itimerspec __user *utmr) 167{
168 struct file *file;
169
170 file = fget(fd);
171 if (!file)
172 return ERR_PTR(-EBADF);
173 if (file->f_op != &timerfd_fops) {
174 fput(file);
175 return ERR_PTR(-EINVAL);
176 }
177
178 return file;
179}
180
181asmlinkage long sys_timerfd_create(int clockid, int flags)
155{ 182{
156 int error; 183 int error, ufd;
157 struct timerfd_ctx *ctx; 184 struct timerfd_ctx *ctx;
158 struct file *file; 185 struct file *file;
159 struct inode *inode; 186 struct inode *inode;
160 struct itimerspec ktmr;
161
162 if (copy_from_user(&ktmr, utmr, sizeof(ktmr)))
163 return -EFAULT;
164 187
188 if (flags)
189 return -EINVAL;
165 if (clockid != CLOCK_MONOTONIC && 190 if (clockid != CLOCK_MONOTONIC &&
166 clockid != CLOCK_REALTIME) 191 clockid != CLOCK_REALTIME)
167 return -EINVAL; 192 return -EINVAL;
193
194 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
195 if (!ctx)
196 return -ENOMEM;
197
198 init_waitqueue_head(&ctx->wqh);
199 ctx->clockid = clockid;
200 hrtimer_init(&ctx->tmr, clockid, HRTIMER_MODE_ABS);
201
202 error = anon_inode_getfd(&ufd, &inode, &file, "[timerfd]",
203 &timerfd_fops, ctx);
204 if (error) {
205 kfree(ctx);
206 return error;
207 }
208
209 return ufd;
210}
211
212asmlinkage long sys_timerfd_settime(int ufd, int flags,
213 const struct itimerspec __user *utmr,
214 struct itimerspec __user *otmr)
215{
216 struct file *file;
217 struct timerfd_ctx *ctx;
218 struct itimerspec ktmr, kotmr;
219
220 if (copy_from_user(&ktmr, utmr, sizeof(ktmr)))
221 return -EFAULT;
222
168 if (!timespec_valid(&ktmr.it_value) || 223 if (!timespec_valid(&ktmr.it_value) ||
169 !timespec_valid(&ktmr.it_interval)) 224 !timespec_valid(&ktmr.it_interval))
170 return -EINVAL; 225 return -EINVAL;
171 226
172 if (ufd == -1) { 227 file = timerfd_fget(ufd);
173 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); 228 if (IS_ERR(file))
174 if (!ctx) 229 return PTR_ERR(file);
175 return -ENOMEM; 230 ctx = file->private_data;
176
177 init_waitqueue_head(&ctx->wqh);
178
179 timerfd_setup(ctx, clockid, flags, &ktmr);
180
181 /*
182 * When we call this, the initialization must be complete, since
183 * anon_inode_getfd() will install the fd.
184 */
185 error = anon_inode_getfd(&ufd, &inode, &file, "[timerfd]",
186 &timerfd_fops, ctx);
187 if (error)
188 goto err_tmrcancel;
189 } else {
190 file = fget(ufd);
191 if (!file)
192 return -EBADF;
193 ctx = file->private_data;
194 if (file->f_op != &timerfd_fops) {
195 fput(file);
196 return -EINVAL;
197 }
198 /*
199 * We need to stop the existing timer before reprogramming
200 * it to the new values.
201 */
202 for (;;) {
203 spin_lock_irq(&ctx->wqh.lock);
204 if (hrtimer_try_to_cancel(&ctx->tmr) >= 0)
205 break;
206 spin_unlock_irq(&ctx->wqh.lock);
207 cpu_relax();
208 }
209 /*
210 * Re-program the timer to the new value ...
211 */
212 timerfd_setup(ctx, clockid, flags, &ktmr);
213 231
232 /*
233 * We need to stop the existing timer before reprogramming
234 * it to the new values.
235 */
236 for (;;) {
237 spin_lock_irq(&ctx->wqh.lock);
238 if (hrtimer_try_to_cancel(&ctx->tmr) >= 0)
239 break;
214 spin_unlock_irq(&ctx->wqh.lock); 240 spin_unlock_irq(&ctx->wqh.lock);
215 fput(file); 241 cpu_relax();
216 } 242 }
217 243
218 return ufd; 244 /*
245 * If the timer is expired and it's periodic, we need to advance it
246 * because the caller may want to know the previous expiration time.
247 * We do not update "ticks" and "expired" since the timer will be
248 * re-programmed again in the following timerfd_setup() call.
249 */
250 if (ctx->expired && ctx->tintv.tv64)
251 hrtimer_forward_now(&ctx->tmr, ctx->tintv);
219 252
220err_tmrcancel: 253 kotmr.it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
221 hrtimer_cancel(&ctx->tmr); 254 kotmr.it_interval = ktime_to_timespec(ctx->tintv);
222 kfree(ctx); 255
223 return error; 256 /*
257 * Re-program the timer to the new value ...
258 */
259 timerfd_setup(ctx, flags, &ktmr);
260
261 spin_unlock_irq(&ctx->wqh.lock);
262 fput(file);
263 if (otmr && copy_to_user(otmr, &kotmr, sizeof(kotmr)))
264 return -EFAULT;
265
266 return 0;
267}
268
269asmlinkage long sys_timerfd_gettime(int ufd, struct itimerspec __user *otmr)
270{
271 struct file *file;
272 struct timerfd_ctx *ctx;
273 struct itimerspec kotmr;
274
275 file = timerfd_fget(ufd);
276 if (IS_ERR(file))
277 return PTR_ERR(file);
278 ctx = file->private_data;
279
280 spin_lock_irq(&ctx->wqh.lock);
281 if (ctx->expired && ctx->tintv.tv64) {
282 ctx->expired = 0;
283 ctx->ticks +=
284 hrtimer_forward_now(&ctx->tmr, ctx->tintv) - 1;
285 hrtimer_restart(&ctx->tmr);
286 }
287 kotmr.it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
288 kotmr.it_interval = ktime_to_timespec(ctx->tintv);
289 spin_unlock_irq(&ctx->wqh.lock);
290 fput(file);
291
292 return copy_to_user(otmr, &kotmr, sizeof(kotmr)) ? -EFAULT: 0;
224} 293}
225 294
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index 4320782761ae..489f26bc26d9 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -714,26 +714,30 @@ static int ufs2_read_inode(struct inode *inode, struct ufs2_inode *ufs2_inode)
714 return 0; 714 return 0;
715} 715}
716 716
717void ufs_read_inode(struct inode * inode) 717struct inode *ufs_iget(struct super_block *sb, unsigned long ino)
718{ 718{
719 struct ufs_inode_info *ufsi = UFS_I(inode); 719 struct ufs_inode_info *ufsi;
720 struct super_block * sb; 720 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
721 struct ufs_sb_private_info * uspi;
722 struct buffer_head * bh; 721 struct buffer_head * bh;
722 struct inode *inode;
723 int err; 723 int err;
724 724
725 UFSD("ENTER, ino %lu\n", inode->i_ino); 725 UFSD("ENTER, ino %lu\n", ino);
726
727 sb = inode->i_sb;
728 uspi = UFS_SB(sb)->s_uspi;
729 726
730 if (inode->i_ino < UFS_ROOTINO || 727 if (ino < UFS_ROOTINO || ino > (uspi->s_ncg * uspi->s_ipg)) {
731 inode->i_ino > (uspi->s_ncg * uspi->s_ipg)) {
732 ufs_warning(sb, "ufs_read_inode", "bad inode number (%lu)\n", 728 ufs_warning(sb, "ufs_read_inode", "bad inode number (%lu)\n",
733 inode->i_ino); 729 ino);
734 goto bad_inode; 730 return ERR_PTR(-EIO);
735 } 731 }
736 732
733 inode = iget_locked(sb, ino);
734 if (!inode)
735 return ERR_PTR(-ENOMEM);
736 if (!(inode->i_state & I_NEW))
737 return inode;
738
739 ufsi = UFS_I(inode);
740
737 bh = sb_bread(sb, uspi->s_sbbase + ufs_inotofsba(inode->i_ino)); 741 bh = sb_bread(sb, uspi->s_sbbase + ufs_inotofsba(inode->i_ino));
738 if (!bh) { 742 if (!bh) {
739 ufs_warning(sb, "ufs_read_inode", "unable to read inode %lu\n", 743 ufs_warning(sb, "ufs_read_inode", "unable to read inode %lu\n",
@@ -765,10 +769,12 @@ void ufs_read_inode(struct inode * inode)
765 brelse(bh); 769 brelse(bh);
766 770
767 UFSD("EXIT\n"); 771 UFSD("EXIT\n");
768 return; 772 unlock_new_inode(inode);
773 return inode;
769 774
770bad_inode: 775bad_inode:
771 make_bad_inode(inode); 776 iget_failed(inode);
777 return ERR_PTR(-EIO);
772} 778}
773 779
774static void ufs1_update_inode(struct inode *inode, struct ufs_inode *ufs_inode) 780static void ufs1_update_inode(struct inode *inode, struct ufs_inode *ufs_inode)
diff --git a/fs/ufs/namei.c b/fs/ufs/namei.c
index d8bfbee2fe2b..747a4de6c695 100644
--- a/fs/ufs/namei.c
+++ b/fs/ufs/namei.c
@@ -57,10 +57,10 @@ static struct dentry *ufs_lookup(struct inode * dir, struct dentry *dentry, stru
57 lock_kernel(); 57 lock_kernel();
58 ino = ufs_inode_by_name(dir, dentry); 58 ino = ufs_inode_by_name(dir, dentry);
59 if (ino) { 59 if (ino) {
60 inode = iget(dir->i_sb, ino); 60 inode = ufs_iget(dir->i_sb, ino);
61 if (!inode) { 61 if (IS_ERR(inode)) {
62 unlock_kernel(); 62 unlock_kernel();
63 return ERR_PTR(-EACCES); 63 return ERR_CAST(inode);
64 } 64 }
65 } 65 }
66 unlock_kernel(); 66 unlock_kernel();
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index 0072cb33ebec..73deff475e63 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -633,6 +633,7 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
633 unsigned block_size, super_block_size; 633 unsigned block_size, super_block_size;
634 unsigned flags; 634 unsigned flags;
635 unsigned super_block_offset; 635 unsigned super_block_offset;
636 int ret = -EINVAL;
636 637
637 uspi = NULL; 638 uspi = NULL;
638 ubh = NULL; 639 ubh = NULL;
@@ -1065,12 +1066,16 @@ magic_found:
1065 uspi->s_maxsymlinklen = 1066 uspi->s_maxsymlinklen =
1066 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen); 1067 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
1067 1068
1068 inode = iget(sb, UFS_ROOTINO); 1069 inode = ufs_iget(sb, UFS_ROOTINO);
1069 if (!inode || is_bad_inode(inode)) 1070 if (IS_ERR(inode)) {
1071 ret = PTR_ERR(inode);
1070 goto failed; 1072 goto failed;
1073 }
1071 sb->s_root = d_alloc_root(inode); 1074 sb->s_root = d_alloc_root(inode);
1072 if (!sb->s_root) 1075 if (!sb->s_root) {
1076 ret = -ENOMEM;
1073 goto dalloc_failed; 1077 goto dalloc_failed;
1078 }
1074 1079
1075 ufs_setup_cstotal(sb); 1080 ufs_setup_cstotal(sb);
1076 /* 1081 /*
@@ -1092,7 +1097,7 @@ failed:
1092 kfree(sbi); 1097 kfree(sbi);
1093 sb->s_fs_info = NULL; 1098 sb->s_fs_info = NULL;
1094 UFSD("EXIT (FAILED)\n"); 1099 UFSD("EXIT (FAILED)\n");
1095 return -EINVAL; 1100 return ret;
1096 1101
1097failed_nomem: 1102failed_nomem:
1098 UFSD("EXIT (NOMEM)\n"); 1103 UFSD("EXIT (NOMEM)\n");
@@ -1326,7 +1331,6 @@ static ssize_t ufs_quota_write(struct super_block *, int, const char *, size_t,
1326static const struct super_operations ufs_super_ops = { 1331static const struct super_operations ufs_super_ops = {
1327 .alloc_inode = ufs_alloc_inode, 1332 .alloc_inode = ufs_alloc_inode,
1328 .destroy_inode = ufs_destroy_inode, 1333 .destroy_inode = ufs_destroy_inode,
1329 .read_inode = ufs_read_inode,
1330 .write_inode = ufs_write_inode, 1334 .write_inode = ufs_write_inode,
1331 .delete_inode = ufs_delete_inode, 1335 .delete_inode = ufs_delete_inode,
1332 .put_super = ufs_put_super, 1336 .put_super = ufs_put_super,
diff --git a/fs/ufs/ufs.h b/fs/ufs/ufs.h
index 7faa4cd71a27..fcb9231bb9ed 100644
--- a/fs/ufs/ufs.h
+++ b/fs/ufs/ufs.h
@@ -106,7 +106,7 @@ extern void ufs_free_inode (struct inode *inode);
106extern struct inode * ufs_new_inode (struct inode *, int); 106extern struct inode * ufs_new_inode (struct inode *, int);
107 107
108/* inode.c */ 108/* inode.c */
109extern void ufs_read_inode (struct inode *); 109extern struct inode *ufs_iget(struct super_block *, unsigned long);
110extern void ufs_put_inode (struct inode *); 110extern void ufs_put_inode (struct inode *);
111extern int ufs_write_inode (struct inode *, int); 111extern int ufs_write_inode (struct inode *, int);
112extern int ufs_sync_inode (struct inode *); 112extern int ufs_sync_inode (struct inode *);
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
diff --git a/fs/vfat/namei.c b/fs/vfat/namei.c
index c28add2fbe95..cd450bea9f1a 100644
--- a/fs/vfat/namei.c
+++ b/fs/vfat/namei.c
@@ -705,7 +705,7 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
705 brelse(sinfo.bh); 705 brelse(sinfo.bh);
706 if (IS_ERR(inode)) { 706 if (IS_ERR(inode)) {
707 unlock_kernel(); 707 unlock_kernel();
708 return ERR_PTR(PTR_ERR(inode)); 708 return ERR_CAST(inode);
709 } 709 }
710 alias = d_find_alias(inode); 710 alias = d_find_alias(inode);
711 if (alias) { 711 if (alias) {
diff --git a/fs/xattr.c b/fs/xattr.c
index 6645b7313b33..f7c8f87bb390 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -105,6 +105,33 @@ out:
105EXPORT_SYMBOL_GPL(vfs_setxattr); 105EXPORT_SYMBOL_GPL(vfs_setxattr);
106 106
107ssize_t 107ssize_t
108xattr_getsecurity(struct inode *inode, const char *name, void *value,
109 size_t size)
110{
111 void *buffer = NULL;
112 ssize_t len;
113
114 if (!value || !size) {
115 len = security_inode_getsecurity(inode, name, &buffer, false);
116 goto out_noalloc;
117 }
118
119 len = security_inode_getsecurity(inode, name, &buffer, true);
120 if (len < 0)
121 return len;
122 if (size < len) {
123 len = -ERANGE;
124 goto out;
125 }
126 memcpy(value, buffer, len);
127out:
128 security_release_secctx(buffer, len);
129out_noalloc:
130 return len;
131}
132EXPORT_SYMBOL_GPL(xattr_getsecurity);
133
134ssize_t
108vfs_getxattr(struct dentry *dentry, char *name, void *value, size_t size) 135vfs_getxattr(struct dentry *dentry, char *name, void *value, size_t size)
109{ 136{
110 struct inode *inode = dentry->d_inode; 137 struct inode *inode = dentry->d_inode;
@@ -118,23 +145,23 @@ vfs_getxattr(struct dentry *dentry, char *name, void *value, size_t size)
118 if (error) 145 if (error)
119 return error; 146 return error;
120 147
121 if (inode->i_op->getxattr)
122 error = inode->i_op->getxattr(dentry, name, value, size);
123 else
124 error = -EOPNOTSUPP;
125
126 if (!strncmp(name, XATTR_SECURITY_PREFIX, 148 if (!strncmp(name, XATTR_SECURITY_PREFIX,
127 XATTR_SECURITY_PREFIX_LEN)) { 149 XATTR_SECURITY_PREFIX_LEN)) {
128 const char *suffix = name + XATTR_SECURITY_PREFIX_LEN; 150 const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
129 int ret = security_inode_getsecurity(inode, suffix, value, 151 int ret = xattr_getsecurity(inode, suffix, value, size);
130 size, error);
131 /* 152 /*
132 * Only overwrite the return value if a security module 153 * Only overwrite the return value if a security module
133 * is actually active. 154 * is actually active.
134 */ 155 */
135 if (ret != -EOPNOTSUPP) 156 if (ret == -EOPNOTSUPP)
136 error = ret; 157 goto nolsm;
158 return ret;
137 } 159 }
160nolsm:
161 if (inode->i_op->getxattr)
162 error = inode->i_op->getxattr(dentry, name, value, size);
163 else
164 error = -EOPNOTSUPP;
138 165
139 return error; 166 return error;
140} 167}
diff --git a/fs/xfs/linux-2.6/kmem.c b/fs/xfs/linux-2.6/kmem.c
index ed2b16dff914..e040f1ce1b6a 100644
--- a/fs/xfs/linux-2.6/kmem.c
+++ b/fs/xfs/linux-2.6/kmem.c
@@ -92,8 +92,7 @@ kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize,
92void 92void
93kmem_free(void *ptr, size_t size) 93kmem_free(void *ptr, size_t size)
94{ 94{
95 if (((unsigned long)ptr < VMALLOC_START) || 95 if (!is_vmalloc_addr(ptr)) {
96 ((unsigned long)ptr >= VMALLOC_END)) {
97 kfree(ptr); 96 kfree(ptr);
98 } else { 97 } else {
99 vfree(ptr); 98 vfree(ptr);
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index a49dd8d4b069..0382c19d6523 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -709,8 +709,7 @@ static inline struct page *
709mem_to_page( 709mem_to_page(
710 void *addr) 710 void *addr)
711{ 711{
712 if (((unsigned long)addr < VMALLOC_START) || 712 if ((!is_vmalloc_addr(addr))) {
713 ((unsigned long)addr >= VMALLOC_END)) {
714 return virt_to_page(addr); 713 return virt_to_page(addr);
715 } else { 714 } else {
716 return vmalloc_to_page(addr); 715 return vmalloc_to_page(addr);
diff --git a/fs/xfs/linux-2.6/xfs_lrw.c b/fs/xfs/linux-2.6/xfs_lrw.c
index d6a8dddb2268..6f614f35f650 100644
--- a/fs/xfs/linux-2.6/xfs_lrw.c
+++ b/fs/xfs/linux-2.6/xfs_lrw.c
@@ -155,7 +155,7 @@ xfs_iozero(
155 if (status) 155 if (status)
156 break; 156 break;
157 157
158 zero_user_page(page, offset, bytes, KM_USER0); 158 zero_user(page, offset, bytes);
159 159
160 status = pagecache_write_end(NULL, mapping, pos, bytes, bytes, 160 status = pagecache_write_end(NULL, mapping, pos, bytes, bytes,
161 page, fsdata); 161 page, fsdata);