aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAnton Altaparmakov <aia21@cantab.net>2006-03-23 09:50:51 -0500
committerAnton Altaparmakov <aia21@cantab.net>2006-03-23 09:50:51 -0500
commitb4d8d1a93c6ea042b29bb66fbb1cf6bc556c18f7 (patch)
tree030ef62361042d1a034087ad9a726db3b57bba72 /fs
parentbb8047d3540affd6b8c2adac3fe792e07143be0f (diff)
parent2e6e33bab6e1996a5dec9108fb467b52b841e7a8 (diff)
Merge branch 'master' of /usr/src/ntfs-2.6/
Diffstat (limited to 'fs')
-rw-r--r--fs/9p/9p.c1
-rw-r--r--fs/9p/fid.c145
-rw-r--r--fs/9p/fid.h6
-rw-r--r--fs/9p/trans_fd.c1
-rw-r--r--fs/9p/v9fs.c1
-rw-r--r--fs/9p/v9fs_vfs.h1
-rw-r--r--fs/9p/vfs_dentry.c45
-rw-r--r--fs/9p/vfs_dir.c1
-rw-r--r--fs/9p/vfs_file.c106
-rw-r--r--fs/9p/vfs_inode.c479
-rw-r--r--fs/9p/vfs_super.c10
-rw-r--r--fs/befs/linuxvfs.c2
-rw-r--r--fs/binfmt_elf.c5
-rw-r--r--fs/buffer.c60
-rw-r--r--fs/char_dev.c17
-rw-r--r--fs/cifs/CHANGES2
-rw-r--r--fs/cifs/cifsproto.h2
-rw-r--r--fs/cifs/connect.c2
-rw-r--r--fs/cifs/misc.c4
-rw-r--r--fs/compat_ioctl.c15
-rw-r--r--fs/cramfs/inode.c60
-rw-r--r--fs/dcache.c2
-rw-r--r--fs/debugfs/file.c46
-rw-r--r--fs/direct-io.c21
-rw-r--r--fs/exec.c6
-rw-r--r--fs/ext2/dir.c28
-rw-r--r--fs/ext3/inode.c17
-rw-r--r--fs/ext3/namei.c3
-rw-r--r--fs/fat/dir.c2
-rw-r--r--fs/fat/inode.c2
-rw-r--r--fs/fifo.c7
-rw-r--r--fs/file_table.c87
-rw-r--r--fs/fuse/dir.c10
-rw-r--r--fs/hugetlbfs/inode.c92
-rw-r--r--fs/isofs/joliet.c2
-rw-r--r--fs/jffs2/nodelist.c3
-rw-r--r--fs/jffs2/readinode.c2
-rw-r--r--fs/jffs2/scan.c2
-rw-r--r--fs/jfs/Makefile3
-rw-r--r--fs/jfs/acl.c7
-rw-r--r--fs/jfs/file.c1
-rw-r--r--fs/jfs/inode.c15
-rw-r--r--fs/jfs/ioctl.c107
-rw-r--r--fs/jfs/jfs_dinode.h31
-rw-r--r--fs/jfs/jfs_dmap.c15
-rw-r--r--fs/jfs/jfs_dmap.h2
-rw-r--r--fs/jfs/jfs_dtree.c13
-rw-r--r--fs/jfs/jfs_extent.c20
-rw-r--r--fs/jfs/jfs_imap.c78
-rw-r--r--fs/jfs/jfs_imap.h4
-rw-r--r--fs/jfs/jfs_incore.h10
-rw-r--r--fs/jfs/jfs_inode.c46
-rw-r--r--fs/jfs/jfs_inode.h3
-rw-r--r--fs/jfs/jfs_lock.h1
-rw-r--r--fs/jfs/jfs_logmgr.c35
-rw-r--r--fs/jfs/jfs_logmgr.h2
-rw-r--r--fs/jfs/jfs_metapage.c3
-rw-r--r--fs/jfs/jfs_superblock.h9
-rw-r--r--fs/jfs/jfs_txnmgr.c36
-rw-r--r--fs/jfs/namei.c99
-rw-r--r--fs/jfs/super.c98
-rw-r--r--fs/jfs/xattr.c8
-rw-r--r--fs/lockd/clntproc.c9
-rw-r--r--fs/namei.c21
-rw-r--r--fs/namespace.c5
-rw-r--r--fs/nfs/direct.c10
-rw-r--r--fs/nfs/nfs4proc.c2
-rw-r--r--fs/nfsctl.c4
-rw-r--r--fs/nls/Kconfig2
-rw-r--r--fs/ocfs2/cluster/masklog.c1
-rw-r--r--fs/ocfs2/cluster/masklog.h2
-rw-r--r--fs/ocfs2/cluster/nodemanager.c4
-rw-r--r--fs/ocfs2/cluster/tcp.c14
-rw-r--r--fs/ocfs2/cluster/tcp.h5
-rw-r--r--fs/ocfs2/dlm/dlmcommon.h8
-rw-r--r--fs/ocfs2/dlm/dlmdebug.c12
-rw-r--r--fs/ocfs2/dlm/dlmdomain.c39
-rw-r--r--fs/ocfs2/dlm/dlmmaster.c4
-rw-r--r--fs/ocfs2/dlm/dlmrecovery.c23
-rw-r--r--fs/ocfs2/extent_map.c38
-rw-r--r--fs/ocfs2/file.c51
-rw-r--r--fs/ocfs2/heartbeat.c1
-rw-r--r--fs/ocfs2/inode.c46
-rw-r--r--fs/ocfs2/journal.c124
-rw-r--r--fs/ocfs2/ocfs2.h7
-rw-r--r--fs/ocfs2/ocfs2_fs.h1
-rw-r--r--fs/ocfs2/super.c13
-rw-r--r--fs/partitions/ibm.c16
-rw-r--r--fs/pipe.c6
-rw-r--r--fs/proc/task_mmu.c11
-rw-r--r--fs/ramfs/file-nommu.c3
-rw-r--r--fs/ramfs/inode.c3
-rw-r--r--fs/reiserfs/file.c14
-rw-r--r--fs/reiserfs/inode.c8
-rw-r--r--fs/reiserfs/journal.c3
-rw-r--r--fs/reiserfs/namei.c8
-rw-r--r--fs/sysfs/dir.c37
-rw-r--r--fs/sysfs/file.c9
-rw-r--r--fs/sysfs/inode.c9
-rw-r--r--fs/sysfs/symlink.c6
-rw-r--r--fs/sysfs/sysfs.h1
-rw-r--r--fs/udf/inode.c16
-rw-r--r--fs/udf/super.c18
-rw-r--r--fs/udf/udf_sb.h4
-rw-r--r--fs/xfs/linux-2.6/xfs_aops.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.c1
-rw-r--r--fs/xfs/quota/xfs_qm.c11
-rw-r--r--fs/xfs/xfs_rtalloc.c29
108 files changed, 1477 insertions, 1127 deletions
diff --git a/fs/9p/9p.c b/fs/9p/9p.c
index 1a6d08761f39..f86a28d1d6a6 100644
--- a/fs/9p/9p.c
+++ b/fs/9p/9p.c
@@ -111,7 +111,6 @@ static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc,
111 if (!rc) 111 if (!rc)
112 return; 112 return;
113 113
114 dprintk(DEBUG_9P, "tcall id %d rcall id %d\n", tc->id, rc->id);
115 v9ses = a; 114 v9ses = a;
116 if (rc->id == RCLUNK) 115 if (rc->id == RCLUNK)
117 v9fs_put_idpool(fid, &v9ses->fidpool); 116 v9fs_put_idpool(fid, &v9ses->fidpool);
diff --git a/fs/9p/fid.c b/fs/9p/fid.c
index eda449778fa5..c4d13bf904d2 100644
--- a/fs/9p/fid.c
+++ b/fs/9p/fid.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * V9FS FID Management 2 * V9FS FID Management
3 * 3 *
4 * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com> 4 * Copyright (C) 2005, 2006 by Eric Van Hensbergen <ericvh@gmail.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@
40 * 40 *
41 */ 41 */
42 42
43static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry) 43int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
44{ 44{
45 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; 45 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
46 dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid, 46 dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid,
@@ -57,7 +57,6 @@ static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
57 } 57 }
58 58
59 fid->uid = current->uid; 59 fid->uid = current->uid;
60 fid->pid = current->pid;
61 list_add(&fid->list, fid_list); 60 list_add(&fid->list, fid_list);
62 return 0; 61 return 0;
63} 62}
@@ -68,14 +67,11 @@ static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
68 * 67 *
69 */ 68 */
70 69
71struct v9fs_fid *v9fs_fid_create(struct dentry *dentry, 70struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *v9ses, int fid)
72 struct v9fs_session_info *v9ses, int fid, int create)
73{ 71{
74 struct v9fs_fid *new; 72 struct v9fs_fid *new;
75 73
76 dprintk(DEBUG_9P, "fid create dentry %p, fid %d, create %d\n", 74 dprintk(DEBUG_9P, "fid create fid %d\n", fid);
77 dentry, fid, create);
78
79 new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL); 75 new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
80 if (new == NULL) { 76 if (new == NULL) {
81 dprintk(DEBUG_ERROR, "Out of Memory\n"); 77 dprintk(DEBUG_ERROR, "Out of Memory\n");
@@ -85,19 +81,13 @@ struct v9fs_fid *v9fs_fid_create(struct dentry *dentry,
85 new->fid = fid; 81 new->fid = fid;
86 new->v9ses = v9ses; 82 new->v9ses = v9ses;
87 new->fidopen = 0; 83 new->fidopen = 0;
88 new->fidcreate = create;
89 new->fidclunked = 0; 84 new->fidclunked = 0;
90 new->iounit = 0; 85 new->iounit = 0;
91 new->rdir_pos = 0; 86 new->rdir_pos = 0;
92 new->rdir_fcall = NULL; 87 new->rdir_fcall = NULL;
88 INIT_LIST_HEAD(&new->list);
93 89
94 if (v9fs_fid_insert(new, dentry) == 0) 90 return new;
95 return new;
96 else {
97 dprintk(DEBUG_ERROR, "Problems inserting to dentry\n");
98 kfree(new);
99 return NULL;
100 }
101} 91}
102 92
103/** 93/**
@@ -113,140 +103,29 @@ void v9fs_fid_destroy(struct v9fs_fid *fid)
113} 103}
114 104
115/** 105/**
116 * v9fs_fid_walk_up - walks from the process current directory
117 * up to the specified dentry.
118 */
119static struct v9fs_fid *v9fs_fid_walk_up(struct dentry *dentry)
120{
121 int fidnum, cfidnum, err;
122 struct v9fs_fid *cfid;
123 struct dentry *cde;
124 struct v9fs_session_info *v9ses;
125
126 v9ses = v9fs_inode2v9ses(current->fs->pwd->d_inode);
127 cfid = v9fs_fid_lookup(current->fs->pwd);
128 if (cfid == NULL) {
129 dprintk(DEBUG_ERROR, "process cwd doesn't have a fid\n");
130 return ERR_PTR(-ENOENT);
131 }
132
133 cfidnum = cfid->fid;
134 cde = current->fs->pwd;
135 /* TODO: take advantage of multiwalk */
136
137 fidnum = v9fs_get_idpool(&v9ses->fidpool);
138 if (fidnum < 0) {
139 dprintk(DEBUG_ERROR, "could not get a new fid num\n");
140 err = -ENOENT;
141 goto clunk_fid;
142 }
143
144 while (cde != dentry) {
145 if (cde == cde->d_parent) {
146 dprintk(DEBUG_ERROR, "can't find dentry\n");
147 err = -ENOENT;
148 goto clunk_fid;
149 }
150
151 err = v9fs_t_walk(v9ses, cfidnum, fidnum, "..", NULL);
152 if (err < 0) {
153 dprintk(DEBUG_ERROR, "problem walking to parent\n");
154 goto clunk_fid;
155 }
156
157 cfidnum = fidnum;
158 cde = cde->d_parent;
159 }
160
161 return v9fs_fid_create(dentry, v9ses, fidnum, 0);
162
163clunk_fid:
164 v9fs_t_clunk(v9ses, fidnum);
165 return ERR_PTR(err);
166}
167
168/**
169 * v9fs_fid_lookup - retrieve the right fid from a particular dentry 106 * v9fs_fid_lookup - retrieve the right fid from a particular dentry
170 * @dentry: dentry to look for fid in 107 * @dentry: dentry to look for fid in
171 * @type: intent of lookup (operation or traversal) 108 * @type: intent of lookup (operation or traversal)
172 * 109 *
173 * search list of fids associated with a dentry for a fid with a matching 110 * find a fid in the dentry
174 * thread id or uid. If that fails, look up the dentry's parents to see if you 111 *
175 * can find a matching fid. 112 * TODO: only match fids that have the same uid as current user
176 * 113 *
177 */ 114 */
178 115
179struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry) 116struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry)
180{ 117{
181 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; 118 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
182 struct v9fs_fid *current_fid = NULL;
183 struct v9fs_fid *temp = NULL;
184 struct v9fs_fid *return_fid = NULL; 119 struct v9fs_fid *return_fid = NULL;
185 120
186 dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry); 121 dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
187 122
188 if (fid_list) { 123 if (fid_list)
189 list_for_each_entry_safe(current_fid, temp, fid_list, list) { 124 return_fid = list_entry(fid_list->next, struct v9fs_fid, list);
190 if (!current_fid->fidcreate) {
191 return_fid = current_fid;
192 break;
193 }
194 }
195
196 if (!return_fid)
197 return_fid = current_fid;
198 }
199
200 /* we are at the root but didn't match */
201 if ((!return_fid) && (dentry->d_parent == dentry)) {
202 /* TODO: clone attach with new uid */
203 return_fid = current_fid;
204 }
205 125
206 if (!return_fid) { 126 if (!return_fid) {
207 struct dentry *par = current->fs->pwd->d_parent; 127 dprintk(DEBUG_ERROR, "Couldn't find a fid in dentry\n");
208 int count = 1;
209 while (par != NULL) {
210 if (par == dentry)
211 break;
212 count++;
213 if (par == par->d_parent) {
214 dprintk(DEBUG_ERROR,
215 "got to root without finding dentry\n");
216 break;
217 }
218 par = par->d_parent;
219 }
220
221/* XXX - there may be some duplication we can get rid of */
222 if (par == dentry) {
223 return_fid = v9fs_fid_walk_up(dentry);
224 if (IS_ERR(return_fid))
225 return_fid = NULL;
226 }
227 } 128 }
228 129
229 return return_fid; 130 return return_fid;
230} 131}
231
232struct v9fs_fid *v9fs_fid_get_created(struct dentry *dentry)
233{
234 struct list_head *fid_list;
235 struct v9fs_fid *fid, *ftmp, *ret;
236
237 dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
238 fid_list = (struct list_head *)dentry->d_fsdata;
239 ret = NULL;
240 if (fid_list) {
241 list_for_each_entry_safe(fid, ftmp, fid_list, list) {
242 if (fid->fidcreate && fid->pid == current->pid) {
243 list_del(&fid->list);
244 ret = fid;
245 break;
246 }
247 }
248 }
249
250 dprintk(DEBUG_9P, "return %p\n", ret);
251 return ret;
252}
diff --git a/fs/9p/fid.h b/fs/9p/fid.h
index 84c673a44c83..1fc2dd08d75a 100644
--- a/fs/9p/fid.h
+++ b/fs/9p/fid.h
@@ -33,7 +33,6 @@ struct v9fs_fid {
33 33
34 u32 fid; 34 u32 fid;
35 unsigned char fidopen; /* set when fid is opened */ 35 unsigned char fidopen; /* set when fid is opened */
36 unsigned char fidcreate; /* set when fid was just created */
37 unsigned char fidclunked; /* set when fid has already been clunked */ 36 unsigned char fidclunked; /* set when fid has already been clunked */
38 37
39 struct v9fs_qid qid; 38 struct v9fs_qid qid;
@@ -45,7 +44,6 @@ struct v9fs_fid {
45 struct v9fs_fcall *rdir_fcall; 44 struct v9fs_fcall *rdir_fcall;
46 45
47 /* management stuff */ 46 /* management stuff */
48 pid_t pid; /* thread associated with this fid */
49 uid_t uid; /* user associated with this fid */ 47 uid_t uid; /* user associated with this fid */
50 48
51 /* private data */ 49 /* private data */
@@ -56,5 +54,5 @@ struct v9fs_fid {
56struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry); 54struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry);
57struct v9fs_fid *v9fs_fid_get_created(struct dentry *); 55struct v9fs_fid *v9fs_fid_get_created(struct dentry *);
58void v9fs_fid_destroy(struct v9fs_fid *fid); 56void v9fs_fid_destroy(struct v9fs_fid *fid);
59struct v9fs_fid *v9fs_fid_create(struct dentry *, 57struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *, int fid);
60 struct v9fs_session_info *v9ses, int fid, int create); 58int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry);
diff --git a/fs/9p/trans_fd.c b/fs/9p/trans_fd.c
index 1a28ef97a3d1..5b2ce21b10fa 100644
--- a/fs/9p/trans_fd.c
+++ b/fs/9p/trans_fd.c
@@ -80,6 +80,7 @@ static int v9fs_fd_send(struct v9fs_transport *trans, void *v, int len)
80 if (!trans || trans->status != Connected || !ts) 80 if (!trans || trans->status != Connected || !ts)
81 return -EIO; 81 return -EIO;
82 82
83 oldfs = get_fs();
83 set_fs(get_ds()); 84 set_fs(get_ds());
84 /* The cast to a user pointer is valid due to the set_fs() */ 85 /* The cast to a user pointer is valid due to the set_fs() */
85 ret = vfs_write(ts->out_file, (void __user *)v, len, &ts->out_file->f_pos); 86 ret = vfs_write(ts->out_file, (void __user *)v, len, &ts->out_file->f_pos);
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index ef3386549140..61352491ba36 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -397,6 +397,7 @@ v9fs_session_init(struct v9fs_session_info *v9ses,
397 } 397 }
398 398
399 if (v9ses->afid != ~0) { 399 if (v9ses->afid != ~0) {
400 dprintk(DEBUG_ERROR, "afid not equal to ~0\n");
400 if (v9fs_t_clunk(v9ses, v9ses->afid)) 401 if (v9fs_t_clunk(v9ses, v9ses->afid))
401 dprintk(DEBUG_ERROR, "clunk failed\n"); 402 dprintk(DEBUG_ERROR, "clunk failed\n");
402 } 403 }
diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h
index 69cf2905dc90..a759278acaae 100644
--- a/fs/9p/v9fs_vfs.h
+++ b/fs/9p/v9fs_vfs.h
@@ -51,3 +51,4 @@ int v9fs_dir_release(struct inode *inode, struct file *filp);
51int v9fs_file_open(struct inode *inode, struct file *file); 51int v9fs_file_open(struct inode *inode, struct file *file);
52void v9fs_inode2stat(struct inode *inode, struct v9fs_stat *stat); 52void v9fs_inode2stat(struct inode *inode, struct v9fs_stat *stat);
53void v9fs_dentry_release(struct dentry *); 53void v9fs_dentry_release(struct dentry *);
54int v9fs_uflags2omode(int uflags);
diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c
index 2dd806dac9f1..12c9cc926b71 100644
--- a/fs/9p/vfs_dentry.c
+++ b/fs/9p/vfs_dentry.c
@@ -43,47 +43,18 @@
43#include "fid.h" 43#include "fid.h"
44 44
45/** 45/**
46 * v9fs_dentry_validate - VFS dcache hook to validate cache 46 * v9fs_dentry_delete - called when dentry refcount equals 0
47 * @dentry: dentry that is being validated 47 * @dentry: dentry in question
48 * @nd: path data
49 * 48 *
50 * dcache really shouldn't be used for 9P2000 as at all due to 49 * By returning 1 here we should remove cacheing of unused
51 * potential attached semantics to directory traversal (walk). 50 * dentry components.
52 *
53 * FUTURE: look into how to use dcache to allow multi-stage
54 * walks in Plan 9 & potential for better dcache operation which
55 * would remain valid for Plan 9 semantics. Older versions
56 * had validation via stat for those interested. However, since
57 * stat has the same approximate overhead as walk there really
58 * is no difference. The only improvement would be from a
59 * time-decay cache like NFS has and that undermines the
60 * synchronous nature of 9P2000.
61 * 51 *
62 */ 52 */
63 53
64static int v9fs_dentry_validate(struct dentry *dentry, struct nameidata *nd) 54int v9fs_dentry_delete(struct dentry *dentry)
65{ 55{
66 struct dentry *dc = current->fs->pwd; 56 dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
67 57 return 1;
68 dprintk(DEBUG_VFS, "dentry: %s (%p)\n", dentry->d_iname, dentry);
69 if (v9fs_fid_lookup(dentry)) {
70 dprintk(DEBUG_VFS, "VALID\n");
71 return 1;
72 }
73
74 while (dc != NULL) {
75 if (dc == dentry) {
76 dprintk(DEBUG_VFS, "VALID\n");
77 return 1;
78 }
79 if (dc == dc->d_parent)
80 break;
81
82 dc = dc->d_parent;
83 }
84
85 dprintk(DEBUG_VFS, "INVALID\n");
86 return 0;
87} 58}
88 59
89/** 60/**
@@ -118,6 +89,6 @@ void v9fs_dentry_release(struct dentry *dentry)
118} 89}
119 90
120struct dentry_operations v9fs_dentry_operations = { 91struct dentry_operations v9fs_dentry_operations = {
121 .d_revalidate = v9fs_dentry_validate, 92 .d_delete = v9fs_dentry_delete,
122 .d_release = v9fs_dentry_release, 93 .d_release = v9fs_dentry_release,
123}; 94};
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index ae6d032b9b59..cd5eeb032d64 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -202,7 +202,6 @@ int v9fs_dir_release(struct inode *inode, struct file *filp)
202 filp->private_data = NULL; 202 filp->private_data = NULL;
203 } 203 }
204 204
205 d_drop(filp->f_dentry);
206 return 0; 205 return 0;
207} 206}
208 207
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index c7e14d917215..de3a129698da 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -53,94 +53,70 @@
53int v9fs_file_open(struct inode *inode, struct file *file) 53int v9fs_file_open(struct inode *inode, struct file *file)
54{ 54{
55 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); 55 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
56 struct v9fs_fid *v9fid, *fid; 56 struct v9fs_fid *vfid;
57 struct v9fs_fcall *fcall = NULL; 57 struct v9fs_fcall *fcall = NULL;
58 int open_mode = 0; 58 int omode;
59 unsigned int iounit = 0; 59 int fid = V9FS_NOFID;
60 int newfid = -1; 60 int err;
61 long result = -1;
62 61
63 dprintk(DEBUG_VFS, "inode: %p file: %p \n", inode, file); 62 dprintk(DEBUG_VFS, "inode: %p file: %p \n", inode, file);
64 63
65 v9fid = v9fs_fid_get_created(file->f_dentry); 64 vfid = v9fs_fid_lookup(file->f_dentry);
66 if (!v9fid) 65 if (!vfid) {
67 v9fid = v9fs_fid_lookup(file->f_dentry);
68
69 if (!v9fid) {
70 dprintk(DEBUG_ERROR, "Couldn't resolve fid from dentry\n"); 66 dprintk(DEBUG_ERROR, "Couldn't resolve fid from dentry\n");
71 return -EBADF; 67 return -EBADF;
72 } 68 }
73 69
74 if (!v9fid->fidcreate) { 70 fid = v9fs_get_idpool(&v9ses->fidpool);
75 fid = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL); 71 if (fid < 0) {
76 if (fid == NULL) {
77 dprintk(DEBUG_ERROR, "Out of Memory\n");
78 return -ENOMEM;
79 }
80
81 fid->fidopen = 0;
82 fid->fidcreate = 0;
83 fid->fidclunked = 0;
84 fid->iounit = 0;
85 fid->v9ses = v9ses;
86
87 newfid = v9fs_get_idpool(&v9ses->fidpool);
88 if (newfid < 0) {
89 eprintk(KERN_WARNING, "newfid fails!\n"); 72 eprintk(KERN_WARNING, "newfid fails!\n");
90 return -ENOSPC; 73 return -ENOSPC;
91 } 74 }
92 75
93 result = 76 err = v9fs_t_walk(v9ses, vfid->fid, fid, NULL, NULL);
94 v9fs_t_walk(v9ses, v9fid->fid, newfid, NULL, NULL); 77 if (err < 0) {
95
96 if (result < 0) {
97 v9fs_put_idpool(newfid, &v9ses->fidpool);
98 dprintk(DEBUG_ERROR, "rewalk didn't work\n"); 78 dprintk(DEBUG_ERROR, "rewalk didn't work\n");
99 return -EBADF; 79 goto put_fid;
80 }
81
82 vfid = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
83 if (vfid == NULL) {
84 dprintk(DEBUG_ERROR, "out of memory\n");
85 goto clunk_fid;
100 } 86 }
101 87
102 fid->fid = newfid;
103 v9fid = fid;
104 /* TODO: do special things for O_EXCL, O_NOFOLLOW, O_SYNC */ 88 /* TODO: do special things for O_EXCL, O_NOFOLLOW, O_SYNC */
105 /* translate open mode appropriately */ 89 /* translate open mode appropriately */
106 open_mode = file->f_flags & 0x3; 90 omode = v9fs_uflags2omode(file->f_flags);
91 err = v9fs_t_open(v9ses, fid, omode, &fcall);
92 if (err < 0) {
93 PRINT_FCALL_ERROR("open failed", fcall);
94 goto destroy_vfid;
95 }
107 96
108 if (file->f_flags & O_EXCL) 97 file->private_data = vfid;
109 open_mode |= V9FS_OEXCL; 98 vfid->fid = fid;
99 vfid->fidopen = 1;
100 vfid->fidclunked = 0;
101 vfid->iounit = fcall->params.ropen.iounit;
102 vfid->rdir_pos = 0;
103 vfid->rdir_fcall = NULL;
104 vfid->filp = file;
105 kfree(fcall);
110 106
111 if (v9ses->extended) { 107 return 0;
112 if (file->f_flags & O_TRUNC)
113 open_mode |= V9FS_OTRUNC;
114 108
115 if (file->f_flags & O_APPEND) 109destroy_vfid:
116 open_mode |= V9FS_OAPPEND; 110 v9fs_fid_destroy(vfid);
117 }
118 111
119 result = v9fs_t_open(v9ses, newfid, open_mode, &fcall); 112clunk_fid:
120 if (result < 0) { 113 v9fs_t_clunk(v9ses, fid);
121 PRINT_FCALL_ERROR("open failed", fcall);
122 kfree(fcall);
123 return result;
124 }
125 114
126 iounit = fcall->params.ropen.iounit; 115put_fid:
116 v9fs_put_idpool(fid, &v9ses->fidpool);
127 kfree(fcall); 117 kfree(fcall);
128 } else {
129 /* create case */
130 newfid = v9fid->fid;
131 iounit = v9fid->iounit;
132 v9fid->fidcreate = 0;
133 }
134
135 file->private_data = v9fid;
136
137 v9fid->rdir_pos = 0;
138 v9fid->rdir_fcall = NULL;
139 v9fid->fidopen = 1;
140 v9fid->filp = file;
141 v9fid->iounit = iounit;
142 118
143 return 0; 119 return err;
144} 120}
145 121
146/** 122/**
@@ -289,9 +265,7 @@ v9fs_file_write(struct file *filp, const char __user * data,
289 total += result; 265 total += result;
290 } while (count); 266 } while (count);
291 267
292 if(inode->i_mapping->nrpages)
293 invalidate_inode_pages2(inode->i_mapping); 268 invalidate_inode_pages2(inode->i_mapping);
294
295 return total; 269 return total;
296} 270}
297 271
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 63e5b0398e8b..651a9e14d9a9 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -125,6 +125,38 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
125 return res; 125 return res;
126} 126}
127 127
128int v9fs_uflags2omode(int uflags)
129{
130 int ret;
131
132 ret = 0;
133 switch (uflags&3) {
134 default:
135 case O_RDONLY:
136 ret = V9FS_OREAD;
137 break;
138
139 case O_WRONLY:
140 ret = V9FS_OWRITE;
141 break;
142
143 case O_RDWR:
144 ret = V9FS_ORDWR;
145 break;
146 }
147
148 if (uflags & O_EXCL)
149 ret |= V9FS_OEXCL;
150
151 if (uflags & O_TRUNC)
152 ret |= V9FS_OTRUNC;
153
154 if (uflags & O_APPEND)
155 ret |= V9FS_OAPPEND;
156
157 return ret;
158}
159
128/** 160/**
129 * v9fs_blank_wstat - helper function to setup a 9P stat structure 161 * v9fs_blank_wstat - helper function to setup a 9P stat structure
130 * @v9ses: 9P session info (for determining extended mode) 162 * @v9ses: 9P session info (for determining extended mode)
@@ -163,7 +195,7 @@ v9fs_blank_wstat(struct v9fs_wstat *wstat)
163 195
164struct inode *v9fs_get_inode(struct super_block *sb, int mode) 196struct inode *v9fs_get_inode(struct super_block *sb, int mode)
165{ 197{
166 struct inode *inode = NULL; 198 struct inode *inode;
167 struct v9fs_session_info *v9ses = sb->s_fs_info; 199 struct v9fs_session_info *v9ses = sb->s_fs_info;
168 200
169 dprintk(DEBUG_VFS, "super block: %p mode: %o\n", sb, mode); 201 dprintk(DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
@@ -222,171 +254,133 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
222 return inode; 254 return inode;
223} 255}
224 256
225/**
226 * v9fs_create - helper function to create files and directories
227 * @dir: directory inode file is being created in
228 * @file_dentry: dentry file is being created in
229 * @perm: permissions file is being created with
230 * @open_mode: resulting open mode for file
231 *
232 */
233
234static int 257static int
235v9fs_create(struct inode *dir, 258v9fs_create(struct v9fs_session_info *v9ses, u32 pfid, char *name,
236 struct dentry *file_dentry, 259 u32 perm, u8 mode, u32 *fidp, struct v9fs_qid *qid, u32 *iounit)
237 unsigned int perm, unsigned int open_mode)
238{ 260{
239 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); 261 u32 fid;
240 struct super_block *sb = dir->i_sb;
241 struct v9fs_fid *dirfid =
242 v9fs_fid_lookup(file_dentry->d_parent);
243 struct v9fs_fid *fid = NULL;
244 struct inode *file_inode = NULL;
245 struct v9fs_fcall *fcall = NULL;
246 struct v9fs_qid qid;
247 int dirfidnum = -1;
248 long newfid = -1;
249 int result = 0;
250 unsigned int iounit = 0;
251 int wfidno = -1;
252 int err; 262 int err;
263 struct v9fs_fcall *fcall;
253 264
254 perm = unixmode2p9mode(v9ses, perm); 265 fid = v9fs_get_idpool(&v9ses->fidpool);
255 266 if (fid < 0) {
256 dprintk(DEBUG_VFS, "dir: %p dentry: %p perm: %o mode: %o\n", dir,
257 file_dentry, perm, open_mode);
258
259 if (!dirfid)
260 return -EBADF;
261
262 dirfidnum = dirfid->fid;
263 if (dirfidnum < 0) {
264 dprintk(DEBUG_ERROR, "No fid for the directory #%lu\n",
265 dir->i_ino);
266 return -EBADF;
267 }
268
269 if (file_dentry->d_inode) {
270 dprintk(DEBUG_ERROR,
271 "Odd. There is an inode for dir %lu, name :%s:\n",
272 dir->i_ino, file_dentry->d_name.name);
273 return -EEXIST;
274 }
275
276 newfid = v9fs_get_idpool(&v9ses->fidpool);
277 if (newfid < 0) {
278 eprintk(KERN_WARNING, "no free fids available\n"); 267 eprintk(KERN_WARNING, "no free fids available\n");
279 return -ENOSPC; 268 return -ENOSPC;
280 } 269 }
281 270
282 result = v9fs_t_walk(v9ses, dirfidnum, newfid, NULL, &fcall); 271 err = v9fs_t_walk(v9ses, pfid, fid, NULL, &fcall);
283 if (result < 0) { 272 if (err < 0) {
284 PRINT_FCALL_ERROR("clone error", fcall); 273 PRINT_FCALL_ERROR("clone error", fcall);
285 v9fs_put_idpool(newfid, &v9ses->fidpool); 274 goto error;
286 newfid = -1;
287 goto CleanUpFid;
288 } 275 }
289
290 kfree(fcall); 276 kfree(fcall);
291 fcall = NULL;
292 277
293 result = v9fs_t_create(v9ses, newfid, (char *)file_dentry->d_name.name, 278 err = v9fs_t_create(v9ses, fid, name, perm, mode, &fcall);
294 perm, open_mode, &fcall); 279 if (err < 0) {
295 if (result < 0) {
296 PRINT_FCALL_ERROR("create fails", fcall); 280 PRINT_FCALL_ERROR("create fails", fcall);
297 goto CleanUpFid; 281 goto error;
298 } 282 }
299 283
300 iounit = fcall->params.rcreate.iounit; 284 if (iounit)
301 qid = fcall->params.rcreate.qid; 285 *iounit = fcall->params.rcreate.iounit;
286
287 if (qid)
288 *qid = fcall->params.rcreate.qid;
289
290 if (fidp)
291 *fidp = fid;
292
302 kfree(fcall); 293 kfree(fcall);
303 fcall = NULL; 294 return 0;
304 295
305 if (!(perm&V9FS_DMDIR)) { 296error:
306 fid = v9fs_fid_create(file_dentry, v9ses, newfid, 1); 297 if (fid >= 0)
307 dprintk(DEBUG_VFS, "fid %p %d\n", fid, fid->fidcreate); 298 v9fs_put_idpool(fid, &v9ses->fidpool);
308 if (!fid) {
309 result = -ENOMEM;
310 goto CleanUpFid;
311 }
312 299
313 fid->qid = qid; 300 kfree(fcall);
314 fid->iounit = iounit; 301 return err;
315 } else { 302}
316 err = v9fs_t_clunk(v9ses, newfid); 303
317 newfid = -1; 304static struct v9fs_fid*
318 if (err < 0) 305v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
319 dprintk(DEBUG_ERROR, "clunk for mkdir failed: %d\n", err); 306{
320 } 307 int err;
308 u32 nfid;
309 struct v9fs_fid *ret;
310 struct v9fs_fcall *fcall;
321 311
322 /* walk to the newly created file and put the fid in the dentry */ 312 nfid = v9fs_get_idpool(&v9ses->fidpool);
323 wfidno = v9fs_get_idpool(&v9ses->fidpool); 313 if (nfid < 0) {
324 if (wfidno < 0) {
325 eprintk(KERN_WARNING, "no free fids available\n"); 314 eprintk(KERN_WARNING, "no free fids available\n");
326 return -ENOSPC; 315 return ERR_PTR(-ENOSPC);
327 } 316 }
328 317
329 result = v9fs_t_walk(v9ses, dirfidnum, wfidno, 318 err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
330 (char *) file_dentry->d_name.name, &fcall); 319 &fcall);
331 if (result < 0) { 320
332 PRINT_FCALL_ERROR("clone error", fcall); 321 if (err < 0) {
333 v9fs_put_idpool(wfidno, &v9ses->fidpool); 322 PRINT_FCALL_ERROR("walk error", fcall);
334 wfidno = -1; 323 v9fs_put_idpool(nfid, &v9ses->fidpool);
335 goto CleanUpFid; 324 goto error;
336 } 325 }
326
337 kfree(fcall); 327 kfree(fcall);
338 fcall = NULL; 328 fcall = NULL;
329 ret = v9fs_fid_create(v9ses, nfid);
330 if (!ret) {
331 err = -ENOMEM;
332 goto clunk_fid;
333 }
339 334
340 if (!v9fs_fid_create(file_dentry, v9ses, wfidno, 0)) { 335 err = v9fs_fid_insert(ret, dentry);
341 v9fs_put_idpool(wfidno, &v9ses->fidpool); 336 if (err < 0) {
342 337 v9fs_fid_destroy(ret);
343 goto CleanUpFid; 338 goto clunk_fid;
344 } 339 }
345 340
346 if ((perm & V9FS_DMSYMLINK) || (perm & V9FS_DMLINK) || 341 return ret;
347 (perm & V9FS_DMNAMEDPIPE) || (perm & V9FS_DMSOCKET) ||
348 (perm & V9FS_DMDEVICE))
349 return 0;
350 342
351 result = v9fs_t_stat(v9ses, wfidno, &fcall); 343clunk_fid:
352 if (result < 0) { 344 v9fs_t_clunk(v9ses, nfid);
353 PRINT_FCALL_ERROR("stat error", fcall);
354 goto CleanUpFid;
355 }
356 345
346error:
347 kfree(fcall);
348 return ERR_PTR(err);
349}
350
351struct inode *
352v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid,
353 struct super_block *sb)
354{
355 int err, umode;
356 struct inode *ret;
357 struct v9fs_fcall *fcall;
357 358
358 file_inode = v9fs_get_inode(sb, 359 ret = NULL;
359 p9mode2unixmode(v9ses, fcall->params.rstat.stat.mode)); 360 err = v9fs_t_stat(v9ses, fid, &fcall);
361 if (err) {
362 PRINT_FCALL_ERROR("stat error", fcall);
363 goto error;
364 }
360 365
361 if ((!file_inode) || IS_ERR(file_inode)) { 366 umode = p9mode2unixmode(v9ses, fcall->params.rstat.stat.mode);
362 dprintk(DEBUG_ERROR, "create inode failed\n"); 367 ret = v9fs_get_inode(sb, umode);
363 result = -EBADF; 368 if (IS_ERR(ret)) {
364 goto CleanUpFid; 369 err = PTR_ERR(ret);
370 ret = NULL;
371 goto error;
365 } 372 }
366 373
367 v9fs_stat2inode(&fcall->params.rstat.stat, file_inode, sb); 374 v9fs_stat2inode(&fcall->params.rstat.stat, ret, sb);
368 kfree(fcall); 375 kfree(fcall);
369 fcall = NULL; 376 return ret;
370 file_dentry->d_op = &v9fs_dentry_operations;
371 d_instantiate(file_dentry, file_inode);
372
373 return 0;
374 377
375 CleanUpFid: 378error:
376 kfree(fcall); 379 kfree(fcall);
377 fcall = NULL; 380 if (ret)
381 iput(ret);
378 382
379 if (newfid >= 0) { 383 return ERR_PTR(err);
380 err = v9fs_t_clunk(v9ses, newfid);
381 if (err < 0)
382 dprintk(DEBUG_ERROR, "clunk failed: %d\n", err);
383 }
384 if (wfidno >= 0) {
385 err = v9fs_t_clunk(v9ses, wfidno);
386 if (err < 0)
387 dprintk(DEBUG_ERROR, "clunk failed: %d\n", err);
388 }
389 return result;
390} 384}
391 385
392/** 386/**
@@ -440,20 +434,97 @@ static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
440 return result; 434 return result;
441} 435}
442 436
437static int
438v9fs_open_created(struct inode *inode, struct file *file)
439{
440 return 0;
441}
442
443/** 443/**
444 * v9fs_vfs_create - VFS hook to create files 444 * v9fs_vfs_create - VFS hook to create files
445 * @inode: directory inode that is being deleted 445 * @inode: directory inode that is being deleted
446 * @dentry: dentry that is being deleted 446 * @dentry: dentry that is being deleted
447 * @perm: create permissions 447 * @mode: create permissions
448 * @nd: path information 448 * @nd: path information
449 * 449 *
450 */ 450 */
451 451
452static int 452static int
453v9fs_vfs_create(struct inode *inode, struct dentry *dentry, int perm, 453v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
454 struct nameidata *nd) 454 struct nameidata *nd)
455{ 455{
456 return v9fs_create(inode, dentry, perm, O_RDWR); 456 int err;
457 u32 fid, perm, iounit;
458 int flags;
459 struct v9fs_session_info *v9ses;
460 struct v9fs_fid *dfid, *vfid, *ffid;
461 struct inode *inode;
462 struct v9fs_qid qid;
463 struct file *filp;
464
465 inode = NULL;
466 vfid = NULL;
467 v9ses = v9fs_inode2v9ses(dir);
468 dfid = v9fs_fid_lookup(dentry->d_parent);
469 perm = unixmode2p9mode(v9ses, mode);
470
471 if (nd && nd->flags & LOOKUP_OPEN)
472 flags = nd->intent.open.flags - 1;
473 else
474 flags = O_RDWR;
475
476 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
477 perm, v9fs_uflags2omode(flags), &fid, &qid, &iounit);
478
479 if (err)
480 goto error;
481
482 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
483 if (IS_ERR(vfid)) {
484 err = PTR_ERR(vfid);
485 vfid = NULL;
486 goto error;
487 }
488
489 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
490 if (IS_ERR(inode)) {
491 err = PTR_ERR(inode);
492 inode = NULL;
493 goto error;
494 }
495
496 dentry->d_op = &v9fs_dentry_operations;
497 d_instantiate(dentry, inode);
498
499 if (nd && nd->flags & LOOKUP_OPEN) {
500 ffid = v9fs_fid_create(v9ses, fid);
501 if (!ffid)
502 return -ENOMEM;
503
504 filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
505 if (IS_ERR(filp)) {
506 v9fs_fid_destroy(ffid);
507 return PTR_ERR(filp);
508 }
509
510 ffid->rdir_pos = 0;
511 ffid->rdir_fcall = NULL;
512 ffid->fidopen = 1;
513 ffid->iounit = iounit;
514 ffid->filp = filp;
515 filp->private_data = ffid;
516 }
517
518 return 0;
519
520error:
521 if (vfid)
522 v9fs_fid_destroy(vfid);
523
524 if (inode)
525 iput(inode);
526
527 return err;
457} 528}
458 529
459/** 530/**
@@ -464,9 +535,57 @@ v9fs_vfs_create(struct inode *inode, struct dentry *dentry, int perm,
464 * 535 *
465 */ 536 */
466 537
467static int v9fs_vfs_mkdir(struct inode *inode, struct dentry *dentry, int mode) 538static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
468{ 539{
469 return v9fs_create(inode, dentry, mode | S_IFDIR, O_RDONLY); 540 int err;
541 u32 fid, perm;
542 struct v9fs_session_info *v9ses;
543 struct v9fs_fid *dfid, *vfid;
544 struct inode *inode;
545
546 inode = NULL;
547 vfid = NULL;
548 v9ses = v9fs_inode2v9ses(dir);
549 dfid = v9fs_fid_lookup(dentry->d_parent);
550 perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
551
552 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
553 perm, V9FS_OREAD, &fid, NULL, NULL);
554
555 if (err) {
556 dprintk(DEBUG_ERROR, "create error %d\n", err);
557 goto error;
558 }
559
560 err = v9fs_t_clunk(v9ses, fid);
561 if (err) {
562 dprintk(DEBUG_ERROR, "clunk error %d\n", err);
563 goto error;
564 }
565
566 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
567 if (IS_ERR(vfid)) {
568 err = PTR_ERR(vfid);
569 vfid = NULL;
570 goto error;
571 }
572
573 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
574 if (IS_ERR(inode)) {
575 err = PTR_ERR(inode);
576 inode = NULL;
577 goto error;
578 }
579
580 dentry->d_op = &v9fs_dentry_operations;
581 d_instantiate(dentry, inode);
582 return 0;
583
584error:
585 if (vfid)
586 v9fs_fid_destroy(vfid);
587
588 return err;
470} 589}
471 590
472/** 591/**
@@ -491,10 +610,11 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
491 int result = 0; 610 int result = 0;
492 611
493 dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n", 612 dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
494 dir, dentry->d_iname, dentry, nameidata); 613 dir, dentry->d_name.name, dentry, nameidata);
495 614
496 sb = dir->i_sb; 615 sb = dir->i_sb;
497 v9ses = v9fs_inode2v9ses(dir); 616 v9ses = v9fs_inode2v9ses(dir);
617 dentry->d_op = &v9fs_dentry_operations;
498 dirfid = v9fs_fid_lookup(dentry->d_parent); 618 dirfid = v9fs_fid_lookup(dentry->d_parent);
499 619
500 if (!dirfid) { 620 if (!dirfid) {
@@ -516,9 +636,8 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
516 return ERR_PTR(-ENOSPC); 636 return ERR_PTR(-ENOSPC);
517 } 637 }
518 638
519 result = 639 result = v9fs_t_walk(v9ses, dirfidnum, newfid,
520 v9fs_t_walk(v9ses, dirfidnum, newfid, (char *)dentry->d_name.name, 640 (char *)dentry->d_name.name, NULL);
521 NULL);
522 if (result < 0) { 641 if (result < 0) {
523 v9fs_put_idpool(newfid, &v9ses->fidpool); 642 v9fs_put_idpool(newfid, &v9ses->fidpool);
524 if (result == -ENOENT) { 643 if (result == -ENOENT) {
@@ -551,16 +670,18 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
551 670
552 inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat.qid); 671 inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat.qid);
553 672
554 fid = v9fs_fid_create(dentry, v9ses, newfid, 0); 673 fid = v9fs_fid_create(v9ses, newfid);
555 if (fid == NULL) { 674 if (fid == NULL) {
556 dprintk(DEBUG_ERROR, "couldn't insert\n"); 675 dprintk(DEBUG_ERROR, "couldn't insert\n");
557 result = -ENOMEM; 676 result = -ENOMEM;
558 goto FreeFcall; 677 goto FreeFcall;
559 } 678 }
560 679
561 fid->qid = fcall->params.rstat.stat.qid; 680 result = v9fs_fid_insert(fid, dentry);
681 if (result < 0)
682 goto FreeFcall;
562 683
563 dentry->d_op = &v9fs_dentry_operations; 684 fid->qid = fcall->params.rstat.stat.qid;
564 v9fs_stat2inode(&fcall->params.rstat.stat, inode, inode->i_sb); 685 v9fs_stat2inode(&fcall->params.rstat.stat, inode, inode->i_sb);
565 686
566 d_add(dentry, inode); 687 d_add(dentry, inode);
@@ -886,8 +1007,8 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
886 } 1007 }
887 1008
888 /* copy extension buffer into buffer */ 1009 /* copy extension buffer into buffer */
889 if (fcall->params.rstat.stat.extension.len+1 < buflen) 1010 if (fcall->params.rstat.stat.extension.len < buflen)
890 buflen = fcall->params.rstat.stat.extension.len + 1; 1011 buflen = fcall->params.rstat.stat.extension.len;
891 1012
892 memcpy(buffer, fcall->params.rstat.stat.extension.str, buflen - 1); 1013 memcpy(buffer, fcall->params.rstat.stat.extension.str, buflen - 1);
893 buffer[buflen-1] = 0; 1014 buffer[buflen-1] = 0;
@@ -951,7 +1072,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
951 if (!link) 1072 if (!link)
952 link = ERR_PTR(-ENOMEM); 1073 link = ERR_PTR(-ENOMEM);
953 else { 1074 else {
954 len = v9fs_readlink(dentry, link, PATH_MAX); 1075 len = v9fs_readlink(dentry, link, strlen(link));
955 1076
956 if (len < 0) { 1077 if (len < 0) {
957 __putname(link); 1078 __putname(link);
@@ -983,53 +1104,75 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void
983static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, 1104static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
984 int mode, const char *extension) 1105 int mode, const char *extension)
985{ 1106{
986 int err, retval; 1107 int err;
1108 u32 fid, perm;
987 struct v9fs_session_info *v9ses; 1109 struct v9fs_session_info *v9ses;
1110 struct v9fs_fid *dfid, *vfid;
1111 struct inode *inode;
988 struct v9fs_fcall *fcall; 1112 struct v9fs_fcall *fcall;
989 struct v9fs_fid *fid;
990 struct v9fs_wstat wstat; 1113 struct v9fs_wstat wstat;
991 1114
992 v9ses = v9fs_inode2v9ses(dir);
993 retval = -EPERM;
994 fcall = NULL; 1115 fcall = NULL;
1116 inode = NULL;
1117 vfid = NULL;
1118 v9ses = v9fs_inode2v9ses(dir);
1119 dfid = v9fs_fid_lookup(dentry->d_parent);
1120 perm = unixmode2p9mode(v9ses, mode);
995 1121
996 if (!v9ses->extended) { 1122 if (!v9ses->extended) {
997 dprintk(DEBUG_ERROR, "not extended\n"); 1123 dprintk(DEBUG_ERROR, "not extended\n");
998 goto free_mem; 1124 return -EPERM;
999 } 1125 }
1000 1126
1001 /* issue a create */ 1127 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
1002 retval = v9fs_create(dir, dentry, mode, 0); 1128 perm, V9FS_OREAD, &fid, NULL, NULL);
1003 if (retval != 0)
1004 goto free_mem;
1005 1129
1006 fid = v9fs_fid_get_created(dentry); 1130 if (err)
1007 if (!fid) { 1131 goto error;
1008 dprintk(DEBUG_ERROR, "couldn't resolve fid from dentry\n"); 1132
1009 goto free_mem; 1133 err = v9fs_t_clunk(v9ses, fid);
1134 if (err)
1135 goto error;
1136
1137 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
1138 if (IS_ERR(vfid)) {
1139 err = PTR_ERR(vfid);
1140 vfid = NULL;
1141 goto error;
1142 }
1143
1144 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
1145 if (IS_ERR(inode)) {
1146 err = PTR_ERR(inode);
1147 inode = NULL;
1148 goto error;
1010 } 1149 }
1011 1150
1012 /* issue a Twstat */ 1151 /* issue a Twstat */
1013 v9fs_blank_wstat(&wstat); 1152 v9fs_blank_wstat(&wstat);
1014 wstat.muid = v9ses->name; 1153 wstat.muid = v9ses->name;
1015 wstat.extension = (char *) extension; 1154 wstat.extension = (char *) extension;
1016 retval = v9fs_t_wstat(v9ses, fid->fid, &wstat, &fcall); 1155 err = v9fs_t_wstat(v9ses, vfid->fid, &wstat, &fcall);
1017 if (retval < 0) {
1018 PRINT_FCALL_ERROR("wstat error", fcall);
1019 goto free_mem;
1020 }
1021
1022 err = v9fs_t_clunk(v9ses, fid->fid);
1023 if (err < 0) { 1156 if (err < 0) {
1024 dprintk(DEBUG_ERROR, "clunk failed: %d\n", err); 1157 PRINT_FCALL_ERROR("wstat error", fcall);
1025 goto free_mem; 1158 goto error;
1026 } 1159 }
1027 1160
1028 d_drop(dentry); /* FID - will this also clunk? */ 1161 kfree(fcall);
1162 dentry->d_op = &v9fs_dentry_operations;
1163 d_instantiate(dentry, inode);
1164 return 0;
1029 1165
1030free_mem: 1166error:
1031 kfree(fcall); 1167 kfree(fcall);
1032 return retval; 1168 if (vfid)
1169 v9fs_fid_destroy(vfid);
1170
1171 if (inode)
1172 iput(inode);
1173
1174 return err;
1175
1033} 1176}
1034 1177
1035/** 1178/**
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index 2c4fa75be025..d05318fa684e 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -146,7 +146,6 @@ static struct super_block *v9fs_get_sb(struct file_system_type
146 inode->i_gid = gid; 146 inode->i_gid = gid;
147 147
148 root = d_alloc_root(inode); 148 root = d_alloc_root(inode);
149
150 if (!root) { 149 if (!root) {
151 retval = -ENOMEM; 150 retval = -ENOMEM;
152 goto put_back_sb; 151 goto put_back_sb;
@@ -158,15 +157,20 @@ static struct super_block *v9fs_get_sb(struct file_system_type
158 if (stat_result < 0) { 157 if (stat_result < 0) {
159 dprintk(DEBUG_ERROR, "stat error\n"); 158 dprintk(DEBUG_ERROR, "stat error\n");
160 v9fs_t_clunk(v9ses, newfid); 159 v9fs_t_clunk(v9ses, newfid);
161 v9fs_put_idpool(newfid, &v9ses->fidpool);
162 } else { 160 } else {
163 /* Setup the Root Inode */ 161 /* Setup the Root Inode */
164 root_fid = v9fs_fid_create(root, v9ses, newfid, 0); 162 root_fid = v9fs_fid_create(v9ses, newfid);
165 if (root_fid == NULL) { 163 if (root_fid == NULL) {
166 retval = -ENOMEM; 164 retval = -ENOMEM;
167 goto put_back_sb; 165 goto put_back_sb;
168 } 166 }
169 167
168 retval = v9fs_fid_insert(root_fid, root);
169 if (retval < 0) {
170 kfree(fcall);
171 goto put_back_sb;
172 }
173
170 root_fid->qid = fcall->params.rstat.stat.qid; 174 root_fid->qid = fcall->params.rstat.stat.qid;
171 root->d_inode->i_ino = 175 root->d_inode->i_ino =
172 v9fs_qid2ino(&fcall->params.rstat.stat.qid); 176 v9fs_qid2ino(&fcall->params.rstat.stat.qid);
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 2d365cb8eec6..dd6048ce0532 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -561,7 +561,7 @@ befs_utf2nls(struct super_block *sb, const char *in,
561 * @sb: Superblock 561 * @sb: Superblock
562 * @src: Input string buffer in NLS format 562 * @src: Input string buffer in NLS format
563 * @srclen: Length of input string in bytes 563 * @srclen: Length of input string in bytes
564 * @dest: The output string in UTF8 format 564 * @dest: The output string in UTF-8 format
565 * @destlen: Length of the output buffer 565 * @destlen: Length of the output buffer
566 * 566 *
567 * Converts input string @src, which is in the format of the loaded NLS map, 567 * Converts input string @src, which is in the format of the loaded NLS map,
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 1b117a441298..c2eac2a50bd2 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -938,6 +938,11 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
938 kfree(elf_interpreter); 938 kfree(elf_interpreter);
939 } else { 939 } else {
940 elf_entry = loc->elf_ex.e_entry; 940 elf_entry = loc->elf_ex.e_entry;
941 if (BAD_ADDR(elf_entry)) {
942 send_sig(SIGSEGV, current, 0);
943 retval = -ENOEXEC; /* Nobody gets to see this, but.. */
944 goto out_free_dentry;
945 }
941 } 946 }
942 947
943 kfree(elf_phdata); 948 kfree(elf_phdata);
diff --git a/fs/buffer.c b/fs/buffer.c
index 62cfd17dc5fe..1d3683d496f8 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -3051,66 +3051,6 @@ asmlinkage long sys_bdflush(int func, long data)
3051} 3051}
3052 3052
3053/* 3053/*
3054 * Migration function for pages with buffers. This function can only be used
3055 * if the underlying filesystem guarantees that no other references to "page"
3056 * exist.
3057 */
3058#ifdef CONFIG_MIGRATION
3059int buffer_migrate_page(struct page *newpage, struct page *page)
3060{
3061 struct address_space *mapping = page->mapping;
3062 struct buffer_head *bh, *head;
3063
3064 if (!mapping)
3065 return -EAGAIN;
3066
3067 if (!page_has_buffers(page))
3068 return migrate_page(newpage, page);
3069
3070 head = page_buffers(page);
3071
3072 if (migrate_page_remove_references(newpage, page, 3))
3073 return -EAGAIN;
3074
3075 bh = head;
3076 do {
3077 get_bh(bh);
3078 lock_buffer(bh);
3079 bh = bh->b_this_page;
3080
3081 } while (bh != head);
3082
3083 ClearPagePrivate(page);
3084 set_page_private(newpage, page_private(page));
3085 set_page_private(page, 0);
3086 put_page(page);
3087 get_page(newpage);
3088
3089 bh = head;
3090 do {
3091 set_bh_page(bh, newpage, bh_offset(bh));
3092 bh = bh->b_this_page;
3093
3094 } while (bh != head);
3095
3096 SetPagePrivate(newpage);
3097
3098 migrate_page_copy(newpage, page);
3099
3100 bh = head;
3101 do {
3102 unlock_buffer(bh);
3103 put_bh(bh);
3104 bh = bh->b_this_page;
3105
3106 } while (bh != head);
3107
3108 return 0;
3109}
3110EXPORT_SYMBOL(buffer_migrate_page);
3111#endif
3112
3113/*
3114 * Buffer-head allocation 3054 * Buffer-head allocation
3115 */ 3055 */
3116static kmem_cache_t *bh_cachep; 3056static kmem_cache_t *bh_cachep;
diff --git a/fs/char_dev.c b/fs/char_dev.c
index 21195c481637..5c36345c9bf7 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -19,6 +19,7 @@
19#include <linux/kobject.h> 19#include <linux/kobject.h>
20#include <linux/kobj_map.h> 20#include <linux/kobj_map.h>
21#include <linux/cdev.h> 21#include <linux/cdev.h>
22#include <linux/mutex.h>
22 23
23#ifdef CONFIG_KMOD 24#ifdef CONFIG_KMOD
24#include <linux/kmod.h> 25#include <linux/kmod.h>
@@ -28,7 +29,7 @@ static struct kobj_map *cdev_map;
28 29
29#define MAX_PROBE_HASH 255 /* random */ 30#define MAX_PROBE_HASH 255 /* random */
30 31
31static DECLARE_MUTEX(chrdevs_lock); 32static DEFINE_MUTEX(chrdevs_lock);
32 33
33static struct char_device_struct { 34static struct char_device_struct {
34 struct char_device_struct *next; 35 struct char_device_struct *next;
@@ -88,13 +89,13 @@ out:
88 89
89void *acquire_chrdev_list(void) 90void *acquire_chrdev_list(void)
90{ 91{
91 down(&chrdevs_lock); 92 mutex_lock(&chrdevs_lock);
92 return get_next_chrdev(NULL); 93 return get_next_chrdev(NULL);
93} 94}
94 95
95void release_chrdev_list(void *dev) 96void release_chrdev_list(void *dev)
96{ 97{
97 up(&chrdevs_lock); 98 mutex_unlock(&chrdevs_lock);
98 kfree(dev); 99 kfree(dev);
99} 100}
100 101
@@ -151,7 +152,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
151 152
152 memset(cd, 0, sizeof(struct char_device_struct)); 153 memset(cd, 0, sizeof(struct char_device_struct));
153 154
154 down(&chrdevs_lock); 155 mutex_lock(&chrdevs_lock);
155 156
156 /* temporary */ 157 /* temporary */
157 if (major == 0) { 158 if (major == 0) {
@@ -186,10 +187,10 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
186 } 187 }
187 cd->next = *cp; 188 cd->next = *cp;
188 *cp = cd; 189 *cp = cd;
189 up(&chrdevs_lock); 190 mutex_unlock(&chrdevs_lock);
190 return cd; 191 return cd;
191out: 192out:
192 up(&chrdevs_lock); 193 mutex_unlock(&chrdevs_lock);
193 kfree(cd); 194 kfree(cd);
194 return ERR_PTR(ret); 195 return ERR_PTR(ret);
195} 196}
@@ -200,7 +201,7 @@ __unregister_chrdev_region(unsigned major, unsigned baseminor, int minorct)
200 struct char_device_struct *cd = NULL, **cp; 201 struct char_device_struct *cd = NULL, **cp;
201 int i = major_to_index(major); 202 int i = major_to_index(major);
202 203
203 down(&chrdevs_lock); 204 mutex_lock(&chrdevs_lock);
204 for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next) 205 for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
205 if ((*cp)->major == major && 206 if ((*cp)->major == major &&
206 (*cp)->baseminor == baseminor && 207 (*cp)->baseminor == baseminor &&
@@ -210,7 +211,7 @@ __unregister_chrdev_region(unsigned major, unsigned baseminor, int minorct)
210 cd = *cp; 211 cd = *cp;
211 *cp = cd->next; 212 *cp = cd->next;
212 } 213 }
213 up(&chrdevs_lock); 214 mutex_unlock(&chrdevs_lock);
214 return cd; 215 return cd;
215} 216}
216 217
diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES
index d335015473a5..cb68efba35db 100644
--- a/fs/cifs/CHANGES
+++ b/fs/cifs/CHANGES
@@ -160,7 +160,7 @@ improperly zeroed buffer in CIFS Unix extensions set times call.
160Version 1.25 160Version 1.25
161------------ 161------------
162Fix internationalization problem in cifs readdir with filenames that map to 162Fix internationalization problem in cifs readdir with filenames that map to
163longer UTF8 strings than the string on the wire was in Unicode. Add workaround 163longer UTF-8 strings than the string on the wire was in Unicode. Add workaround
164for readdir to netapp servers. Fix search rewind (seek into readdir to return 164for readdir to netapp servers. Fix search rewind (seek into readdir to return
165non-consecutive entries). Do not do readdir when server negotiates 165non-consecutive entries). Do not do readdir when server negotiates
166buffer size to small to fit filename. Add support for reading POSIX ACLs from 166buffer size to small to fit filename. Add support for reading POSIX ACLs from
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 3c03aadaff0c..7b25463d3c14 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -52,7 +52,7 @@ extern int SendReceive2(const unsigned int /* xid */ , struct cifsSesInfo *,
52 int * /* type of buf returned */ , const int long_op); 52 int * /* type of buf returned */ , const int long_op);
53extern int checkSMBhdr(struct smb_hdr *smb, __u16 mid); 53extern int checkSMBhdr(struct smb_hdr *smb, __u16 mid);
54extern int checkSMB(struct smb_hdr *smb, __u16 mid, int length); 54extern int checkSMB(struct smb_hdr *smb, __u16 mid, int length);
55extern int is_valid_oplock_break(struct smb_hdr *smb); 55extern int is_valid_oplock_break(struct smb_hdr *smb, struct TCP_Server_Info *);
56extern int is_size_safe_to_change(struct cifsInodeInfo *); 56extern int is_size_safe_to_change(struct cifsInodeInfo *);
57extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *); 57extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *);
58extern unsigned int smbCalcSize(struct smb_hdr *ptr); 58extern unsigned int smbCalcSize(struct smb_hdr *ptr);
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index ef5ae6f93c75..2a0c1f4ca0ae 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -630,7 +630,7 @@ multi_t2_fnd:
630 smallbuf = NULL; 630 smallbuf = NULL;
631 } 631 }
632 wake_up_process(task_to_wake); 632 wake_up_process(task_to_wake);
633 } else if ((is_valid_oplock_break(smb_buffer) == FALSE) 633 } else if ((is_valid_oplock_break(smb_buffer, server) == FALSE)
634 && (isMultiRsp == FALSE)) { 634 && (isMultiRsp == FALSE)) {
635 cERROR(1, ("No task to wake, unknown frame rcvd!")); 635 cERROR(1, ("No task to wake, unknown frame rcvd!"));
636 cifs_dump_mem("Received Data is: ",(char *)smb_buffer, 636 cifs_dump_mem("Received Data is: ",(char *)smb_buffer,
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 812c6bb0fe38..432ba15e2c2d 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -475,7 +475,7 @@ checkSMB(struct smb_hdr *smb, __u16 mid, int length)
475 return 0; 475 return 0;
476} 476}
477int 477int
478is_valid_oplock_break(struct smb_hdr *buf) 478is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
479{ 479{
480 struct smb_com_lock_req * pSMB = (struct smb_com_lock_req *)buf; 480 struct smb_com_lock_req * pSMB = (struct smb_com_lock_req *)buf;
481 struct list_head *tmp; 481 struct list_head *tmp;
@@ -535,7 +535,7 @@ is_valid_oplock_break(struct smb_hdr *buf)
535 read_lock(&GlobalSMBSeslock); 535 read_lock(&GlobalSMBSeslock);
536 list_for_each(tmp, &GlobalTreeConnectionList) { 536 list_for_each(tmp, &GlobalTreeConnectionList) {
537 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList); 537 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
538 if (tcon->tid == buf->Tid) { 538 if ((tcon->tid == buf->Tid) && (srv == tcon->ses->server)) {
539 cifs_stats_inc(&tcon->num_oplock_brks); 539 cifs_stats_inc(&tcon->num_oplock_brks);
540 list_for_each(tmp1,&tcon->openFileList){ 540 list_for_each(tmp1,&tcon->openFileList){
541 netfile = list_entry(tmp1,struct cifsFileInfo, 541 netfile = list_entry(tmp1,struct cifsFileInfo,
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 057e60217fc5..c666769a875d 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -446,7 +446,7 @@ static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
446 ifr = ifc.ifc_req; 446 ifr = ifc.ifc_req;
447 ifr32 = compat_ptr(ifc32.ifcbuf); 447 ifr32 = compat_ptr(ifc32.ifcbuf);
448 for (i = 0, j = 0; 448 for (i = 0, j = 0;
449 i + sizeof (struct ifreq32) < ifc32.ifc_len && j < ifc.ifc_len; 449 i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len;
450 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) { 450 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
451 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32))) 451 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
452 return -EFAULT; 452 return -EFAULT;
@@ -2531,18 +2531,9 @@ static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2531 val32 = kval; 2531 val32 = kval;
2532 return put_user(val32, (unsigned int __user *)arg); 2532 return put_user(val32, (unsigned int __user *)arg);
2533 case RTC_IRQP_SET32: 2533 case RTC_IRQP_SET32:
2534 return sys_ioctl(fd, RTC_IRQP_SET, arg);
2534 case RTC_EPOCH_SET32: 2535 case RTC_EPOCH_SET32:
2535 ret = get_user(val32, (unsigned int __user *)arg); 2536 return sys_ioctl(fd, RTC_EPOCH_SET, arg);
2536 if (ret)
2537 return ret;
2538 kval = val32;
2539
2540 set_fs(KERNEL_DS);
2541 ret = sys_ioctl(fd, (cmd == RTC_IRQP_SET32) ?
2542 RTC_IRQP_SET : RTC_EPOCH_SET,
2543 (unsigned long)&kval);
2544 set_fs(oldfs);
2545 return ret;
2546 default: 2537 default:
2547 /* unreached */ 2538 /* unreached */
2548 return -ENOIOCTLCMD; 2539 return -ENOIOCTLCMD;
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index 7fe85415ae7c..8ad52f5bf255 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -36,7 +36,7 @@ static DECLARE_MUTEX(read_mutex);
36 36
37/* These two macros may change in future, to provide better st_ino 37/* These two macros may change in future, to provide better st_ino
38 semantics. */ 38 semantics. */
39#define CRAMINO(x) ((x)->offset?(x)->offset<<2:1) 39#define CRAMINO(x) (((x)->offset && (x)->size)?(x)->offset<<2:1)
40#define OFFSET(x) ((x)->i_ino) 40#define OFFSET(x) ((x)->i_ino)
41 41
42 42
@@ -66,8 +66,36 @@ static int cramfs_iget5_test(struct inode *inode, void *opaque)
66 66
67static int cramfs_iget5_set(struct inode *inode, void *opaque) 67static int cramfs_iget5_set(struct inode *inode, void *opaque)
68{ 68{
69 static struct timespec zerotime;
69 struct cramfs_inode *cramfs_inode = opaque; 70 struct cramfs_inode *cramfs_inode = opaque;
71 inode->i_mode = cramfs_inode->mode;
72 inode->i_uid = cramfs_inode->uid;
73 inode->i_size = cramfs_inode->size;
74 inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
75 inode->i_blksize = PAGE_CACHE_SIZE;
76 inode->i_gid = cramfs_inode->gid;
77 /* Struct copy intentional */
78 inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
70 inode->i_ino = CRAMINO(cramfs_inode); 79 inode->i_ino = CRAMINO(cramfs_inode);
80 /* inode->i_nlink is left 1 - arguably wrong for directories,
81 but it's the best we can do without reading the directory
82 contents. 1 yields the right result in GNU find, even
83 without -noleaf option. */
84 if (S_ISREG(inode->i_mode)) {
85 inode->i_fop = &generic_ro_fops;
86 inode->i_data.a_ops = &cramfs_aops;
87 } else if (S_ISDIR(inode->i_mode)) {
88 inode->i_op = &cramfs_dir_inode_operations;
89 inode->i_fop = &cramfs_directory_operations;
90 } else if (S_ISLNK(inode->i_mode)) {
91 inode->i_op = &page_symlink_inode_operations;
92 inode->i_data.a_ops = &cramfs_aops;
93 } else {
94 inode->i_size = 0;
95 inode->i_blocks = 0;
96 init_special_inode(inode, inode->i_mode,
97 old_decode_dev(cramfs_inode->size));
98 }
71 return 0; 99 return 0;
72} 100}
73 101
@@ -77,37 +105,7 @@ static struct inode *get_cramfs_inode(struct super_block *sb,
77 struct inode *inode = iget5_locked(sb, CRAMINO(cramfs_inode), 105 struct inode *inode = iget5_locked(sb, CRAMINO(cramfs_inode),
78 cramfs_iget5_test, cramfs_iget5_set, 106 cramfs_iget5_test, cramfs_iget5_set,
79 cramfs_inode); 107 cramfs_inode);
80 static struct timespec zerotime;
81
82 if (inode && (inode->i_state & I_NEW)) { 108 if (inode && (inode->i_state & I_NEW)) {
83 inode->i_mode = cramfs_inode->mode;
84 inode->i_uid = cramfs_inode->uid;
85 inode->i_size = cramfs_inode->size;
86 inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
87 inode->i_blksize = PAGE_CACHE_SIZE;
88 inode->i_gid = cramfs_inode->gid;
89 /* Struct copy intentional */
90 inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
91 inode->i_ino = CRAMINO(cramfs_inode);
92 /* inode->i_nlink is left 1 - arguably wrong for directories,
93 but it's the best we can do without reading the directory
94 contents. 1 yields the right result in GNU find, even
95 without -noleaf option. */
96 if (S_ISREG(inode->i_mode)) {
97 inode->i_fop = &generic_ro_fops;
98 inode->i_data.a_ops = &cramfs_aops;
99 } else if (S_ISDIR(inode->i_mode)) {
100 inode->i_op = &cramfs_dir_inode_operations;
101 inode->i_fop = &cramfs_directory_operations;
102 } else if (S_ISLNK(inode->i_mode)) {
103 inode->i_op = &page_symlink_inode_operations;
104 inode->i_data.a_ops = &cramfs_aops;
105 } else {
106 inode->i_size = 0;
107 inode->i_blocks = 0;
108 init_special_inode(inode, inode->i_mode,
109 old_decode_dev(cramfs_inode->size));
110 }
111 unlock_new_inode(inode); 109 unlock_new_inode(inode);
112 } 110 }
113 return inode; 111 return inode;
diff --git a/fs/dcache.c b/fs/dcache.c
index a173bba32666..11dc83092d4a 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1736,7 +1736,7 @@ void __init vfs_caches_init(unsigned long mempages)
1736 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL); 1736 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
1737 1737
1738 filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, 1738 filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0,
1739 SLAB_HWCACHE_ALIGN|SLAB_PANIC, filp_ctor, filp_dtor); 1739 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
1740 1740
1741 dcache_init(mempages); 1741 dcache_init(mempages);
1742 inode_init(mempages); 1742 inode_init(mempages);
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index d575452cd9f7..40c4fc973fad 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -251,3 +251,49 @@ struct dentry *debugfs_create_bool(const char *name, mode_t mode,
251} 251}
252EXPORT_SYMBOL_GPL(debugfs_create_bool); 252EXPORT_SYMBOL_GPL(debugfs_create_bool);
253 253
254static ssize_t read_file_blob(struct file *file, char __user *user_buf,
255 size_t count, loff_t *ppos)
256{
257 struct debugfs_blob_wrapper *blob = file->private_data;
258 return simple_read_from_buffer(user_buf, count, ppos, blob->data,
259 blob->size);
260}
261
262static struct file_operations fops_blob = {
263 .read = read_file_blob,
264 .open = default_open,
265};
266
267/**
268 * debugfs_create_blob - create a file in the debugfs filesystem that is
269 * used to read and write a binary blob.
270 *
271 * @name: a pointer to a string containing the name of the file to create.
272 * @mode: the permission that the file should have
273 * @parent: a pointer to the parent dentry for this file. This should be a
274 * directory dentry if set. If this paramater is NULL, then the
275 * file will be created in the root of the debugfs filesystem.
276 * @blob: a pointer to a struct debugfs_blob_wrapper which contains a pointer
277 * to the blob data and the size of the data.
278 *
279 * This function creates a file in debugfs with the given name that exports
280 * @blob->data as a binary blob. If the @mode variable is so set it can be
281 * read from. Writing is not supported.
282 *
283 * This function will return a pointer to a dentry if it succeeds. This
284 * pointer must be passed to the debugfs_remove() function when the file is
285 * to be removed (no automatic cleanup happens if your module is unloaded,
286 * you are responsible here.) If an error occurs, NULL will be returned.
287 *
288 * If debugfs is not enabled in the kernel, the value -ENODEV will be
289 * returned. It is not wise to check for this value, but rather, check for
290 * NULL or !NULL instead as to eliminate the need for #ifdef in the calling
291 * code.
292 */
293struct dentry *debugfs_create_blob(const char *name, mode_t mode,
294 struct dentry *parent,
295 struct debugfs_blob_wrapper *blob)
296{
297 return debugfs_create_file(name, mode, parent, blob, &fops_blob);
298}
299EXPORT_SYMBOL_GPL(debugfs_create_blob);
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 848044af7e16..27f3e787faca 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -1155,15 +1155,16 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
1155 * For writes, i_mutex is not held on entry; it is never taken. 1155 * For writes, i_mutex is not held on entry; it is never taken.
1156 * 1156 *
1157 * DIO_LOCKING (simple locking for regular files) 1157 * DIO_LOCKING (simple locking for regular files)
1158 * For writes we are called under i_mutex and return with i_mutex held, even though 1158 * For writes we are called under i_mutex and return with i_mutex held, even
1159 * it is internally dropped. 1159 * though it is internally dropped.
1160 * For reads, i_mutex is not held on entry, but it is taken and dropped before 1160 * For reads, i_mutex is not held on entry, but it is taken and dropped before
1161 * returning. 1161 * returning.
1162 * 1162 *
1163 * DIO_OWN_LOCKING (filesystem provides synchronisation and handling of 1163 * DIO_OWN_LOCKING (filesystem provides synchronisation and handling of
1164 * uninitialised data, allowing parallel direct readers and writers) 1164 * uninitialised data, allowing parallel direct readers and writers)
1165 * For writes we are called without i_mutex, return without it, never touch it. 1165 * For writes we are called without i_mutex, return without it, never touch it.
1166 * For reads, i_mutex is held on entry and will be released before returning. 1166 * For reads we are called under i_mutex and return with i_mutex held, even
1167 * though it may be internally dropped.
1167 * 1168 *
1168 * Additional i_alloc_sem locking requirements described inline below. 1169 * Additional i_alloc_sem locking requirements described inline below.
1169 */ 1170 */
@@ -1182,7 +1183,8 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1182 ssize_t retval = -EINVAL; 1183 ssize_t retval = -EINVAL;
1183 loff_t end = offset; 1184 loff_t end = offset;
1184 struct dio *dio; 1185 struct dio *dio;
1185 int reader_with_isem = (rw == READ && dio_lock_type == DIO_OWN_LOCKING); 1186 int release_i_mutex = 0;
1187 int acquire_i_mutex = 0;
1186 1188
1187 if (rw & WRITE) 1189 if (rw & WRITE)
1188 current->flags |= PF_SYNCWRITE; 1190 current->flags |= PF_SYNCWRITE;
@@ -1225,7 +1227,6 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1225 * writers need to grab i_alloc_sem only (i_mutex is already held) 1227 * writers need to grab i_alloc_sem only (i_mutex is already held)
1226 * For regular files using DIO_OWN_LOCKING, 1228 * For regular files using DIO_OWN_LOCKING,
1227 * neither readers nor writers take any locks here 1229 * neither readers nor writers take any locks here
1228 * (i_mutex is already held and release for writers here)
1229 */ 1230 */
1230 dio->lock_type = dio_lock_type; 1231 dio->lock_type = dio_lock_type;
1231 if (dio_lock_type != DIO_NO_LOCKING) { 1232 if (dio_lock_type != DIO_NO_LOCKING) {
@@ -1236,7 +1237,7 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1236 mapping = iocb->ki_filp->f_mapping; 1237 mapping = iocb->ki_filp->f_mapping;
1237 if (dio_lock_type != DIO_OWN_LOCKING) { 1238 if (dio_lock_type != DIO_OWN_LOCKING) {
1238 mutex_lock(&inode->i_mutex); 1239 mutex_lock(&inode->i_mutex);
1239 reader_with_isem = 1; 1240 release_i_mutex = 1;
1240 } 1241 }
1241 1242
1242 retval = filemap_write_and_wait_range(mapping, offset, 1243 retval = filemap_write_and_wait_range(mapping, offset,
@@ -1248,7 +1249,7 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1248 1249
1249 if (dio_lock_type == DIO_OWN_LOCKING) { 1250 if (dio_lock_type == DIO_OWN_LOCKING) {
1250 mutex_unlock(&inode->i_mutex); 1251 mutex_unlock(&inode->i_mutex);
1251 reader_with_isem = 0; 1252 acquire_i_mutex = 1;
1252 } 1253 }
1253 } 1254 }
1254 1255
@@ -1269,11 +1270,13 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1269 nr_segs, blkbits, get_blocks, end_io, dio); 1270 nr_segs, blkbits, get_blocks, end_io, dio);
1270 1271
1271 if (rw == READ && dio_lock_type == DIO_LOCKING) 1272 if (rw == READ && dio_lock_type == DIO_LOCKING)
1272 reader_with_isem = 0; 1273 release_i_mutex = 0;
1273 1274
1274out: 1275out:
1275 if (reader_with_isem) 1276 if (release_i_mutex)
1276 mutex_unlock(&inode->i_mutex); 1277 mutex_unlock(&inode->i_mutex);
1278 else if (acquire_i_mutex)
1279 mutex_lock(&inode->i_mutex);
1277 if (rw & WRITE) 1280 if (rw & WRITE)
1278 current->flags &= ~PF_SYNCWRITE; 1281 current->flags &= ~PF_SYNCWRITE;
1279 return retval; 1282 return retval;
diff --git a/fs/exec.c b/fs/exec.c
index 0e1c95074d42..0b515ac53134 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -885,6 +885,12 @@ int flush_old_exec(struct linux_binprm * bprm)
885 current->flags &= ~PF_RANDOMIZE; 885 current->flags &= ~PF_RANDOMIZE;
886 flush_thread(); 886 flush_thread();
887 887
888 /* Set the new mm task size. We have to do that late because it may
889 * depend on TIF_32BIT which is only updated in flush_thread() on
890 * some architectures like powerpc
891 */
892 current->mm->task_size = TASK_SIZE;
893
888 if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || 894 if (bprm->e_uid != current->euid || bprm->e_gid != current->egid ||
889 file_permission(bprm->file, MAY_READ) || 895 file_permission(bprm->file, MAY_READ) ||
890 (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP)) { 896 (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP)) {
diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index 7442bdd1267a..b3dbd716cd3a 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -256,11 +256,10 @@ ext2_readdir (struct file * filp, void * dirent, filldir_t filldir)
256 unsigned long npages = dir_pages(inode); 256 unsigned long npages = dir_pages(inode);
257 unsigned chunk_mask = ~(ext2_chunk_size(inode)-1); 257 unsigned chunk_mask = ~(ext2_chunk_size(inode)-1);
258 unsigned char *types = NULL; 258 unsigned char *types = NULL;
259 int need_revalidate = (filp->f_version != inode->i_version); 259 int need_revalidate = filp->f_version != inode->i_version;
260 int ret;
261 260
262 if (pos > inode->i_size - EXT2_DIR_REC_LEN(1)) 261 if (pos > inode->i_size - EXT2_DIR_REC_LEN(1))
263 goto success; 262 return 0;
264 263
265 if (EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_FILETYPE)) 264 if (EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_FILETYPE))
266 types = ext2_filetype_table; 265 types = ext2_filetype_table;
@@ -275,12 +274,15 @@ ext2_readdir (struct file * filp, void * dirent, filldir_t filldir)
275 "bad page in #%lu", 274 "bad page in #%lu",
276 inode->i_ino); 275 inode->i_ino);
277 filp->f_pos += PAGE_CACHE_SIZE - offset; 276 filp->f_pos += PAGE_CACHE_SIZE - offset;
278 ret = -EIO; 277 return -EIO;
279 goto done;
280 } 278 }
281 kaddr = page_address(page); 279 kaddr = page_address(page);
282 if (need_revalidate) { 280 if (unlikely(need_revalidate)) {
283 offset = ext2_validate_entry(kaddr, offset, chunk_mask); 281 if (offset) {
282 offset = ext2_validate_entry(kaddr, offset, chunk_mask);
283 filp->f_pos = (n<<PAGE_CACHE_SHIFT) + offset;
284 }
285 filp->f_version = inode->i_version;
284 need_revalidate = 0; 286 need_revalidate = 0;
285 } 287 }
286 de = (ext2_dirent *)(kaddr+offset); 288 de = (ext2_dirent *)(kaddr+offset);
@@ -289,9 +291,8 @@ ext2_readdir (struct file * filp, void * dirent, filldir_t filldir)
289 if (de->rec_len == 0) { 291 if (de->rec_len == 0) {
290 ext2_error(sb, __FUNCTION__, 292 ext2_error(sb, __FUNCTION__,
291 "zero-length directory entry"); 293 "zero-length directory entry");
292 ret = -EIO;
293 ext2_put_page(page); 294 ext2_put_page(page);
294 goto done; 295 return -EIO;
295 } 296 }
296 if (de->inode) { 297 if (de->inode) {
297 int over; 298 int over;
@@ -306,19 +307,14 @@ ext2_readdir (struct file * filp, void * dirent, filldir_t filldir)
306 le32_to_cpu(de->inode), d_type); 307 le32_to_cpu(de->inode), d_type);
307 if (over) { 308 if (over) {
308 ext2_put_page(page); 309 ext2_put_page(page);
309 goto success; 310 return 0;
310 } 311 }
311 } 312 }
312 filp->f_pos += le16_to_cpu(de->rec_len); 313 filp->f_pos += le16_to_cpu(de->rec_len);
313 } 314 }
314 ext2_put_page(page); 315 ext2_put_page(page);
315 } 316 }
316 317 return 0;
317success:
318 ret = 0;
319done:
320 filp->f_version = inode->i_version;
321 return ret;
322} 318}
323 319
324/* 320/*
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 3fc4238e9703..0384e539b88f 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -1624,15 +1624,14 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
1624 * For "nobh" option, we can only work if we don't need to 1624 * For "nobh" option, we can only work if we don't need to
1625 * read-in the page - otherwise we create buffers to do the IO. 1625 * read-in the page - otherwise we create buffers to do the IO.
1626 */ 1626 */
1627 if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH)) { 1627 if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) &&
1628 if (PageUptodate(page)) { 1628 ext3_should_writeback_data(inode) && PageUptodate(page)) {
1629 kaddr = kmap_atomic(page, KM_USER0); 1629 kaddr = kmap_atomic(page, KM_USER0);
1630 memset(kaddr + offset, 0, length); 1630 memset(kaddr + offset, 0, length);
1631 flush_dcache_page(page); 1631 flush_dcache_page(page);
1632 kunmap_atomic(kaddr, KM_USER0); 1632 kunmap_atomic(kaddr, KM_USER0);
1633 set_page_dirty(page); 1633 set_page_dirty(page);
1634 goto unlock; 1634 goto unlock;
1635 }
1636 } 1635 }
1637 1636
1638 if (!page_has_buffers(page)) 1637 if (!page_has_buffers(page))
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 8bd8ac077704..b8f5cd1e540d 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -2141,7 +2141,8 @@ retry:
2141 * We have a transaction open. All is sweetness. It also sets 2141 * We have a transaction open. All is sweetness. It also sets
2142 * i_size in generic_commit_write(). 2142 * i_size in generic_commit_write().
2143 */ 2143 */
2144 err = page_symlink(inode, symname, l); 2144 err = __page_symlink(inode, symname, l,
2145 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
2145 if (err) { 2146 if (err) {
2146 ext3_dec_count(handle, inode); 2147 ext3_dec_count(handle, inode);
2147 ext3_mark_inode_dirty(handle, inode); 2148 ext3_mark_inode_dirty(handle, inode);
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index db0de5c621c7..4095bc149eb1 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -114,7 +114,7 @@ static inline int fat_get_entry(struct inode *dir, loff_t *pos,
114} 114}
115 115
116/* 116/*
117 * Convert Unicode 16 to UTF8, translated Unicode, or ASCII. 117 * Convert Unicode 16 to UTF-8, translated Unicode, or ASCII.
118 * If uni_xlate is enabled and we can't get a 1:1 conversion, use a 118 * If uni_xlate is enabled and we can't get a 1:1 conversion, use a
119 * colon as an escape character since it is normally invalid on the vfat 119 * colon as an escape character since it is normally invalid on the vfat
120 * filesystem. The following four characters are the hexadecimal digits 120 * filesystem. The following four characters are the hexadecimal digits
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index e7f4aa7fc686..e78d7b4842cc 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -1101,7 +1101,7 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug,
1101 return -EINVAL; 1101 return -EINVAL;
1102 } 1102 }
1103 } 1103 }
1104 /* UTF8 doesn't provide FAT semantics */ 1104 /* UTF-8 doesn't provide FAT semantics */
1105 if (!strcmp(opts->iocharset, "utf8")) { 1105 if (!strcmp(opts->iocharset, "utf8")) {
1106 printk(KERN_ERR "FAT: utf8 is not a recommended IO charset" 1106 printk(KERN_ERR "FAT: utf8 is not a recommended IO charset"
1107 " for FAT filesystems, filesystem will be case sensitive!\n"); 1107 " for FAT filesystems, filesystem will be case sensitive!\n");
diff --git a/fs/fifo.c b/fs/fifo.c
index 923371b753ab..d13fcd3ec803 100644
--- a/fs/fifo.c
+++ b/fs/fifo.c
@@ -34,10 +34,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
34{ 34{
35 int ret; 35 int ret;
36 36
37 ret = -ERESTARTSYS; 37 mutex_lock(PIPE_MUTEX(*inode));
38 if (mutex_lock_interruptible(PIPE_MUTEX(*inode)))
39 goto err_nolock_nocleanup;
40
41 if (!inode->i_pipe) { 38 if (!inode->i_pipe) {
42 ret = -ENOMEM; 39 ret = -ENOMEM;
43 if(!pipe_new(inode)) 40 if(!pipe_new(inode))
@@ -140,8 +137,6 @@ err:
140 137
141err_nocleanup: 138err_nocleanup:
142 mutex_unlock(PIPE_MUTEX(*inode)); 139 mutex_unlock(PIPE_MUTEX(*inode));
143
144err_nolock_nocleanup:
145 return ret; 140 return ret;
146} 141}
147 142
diff --git a/fs/file_table.c b/fs/file_table.c
index 768b58167543..44fabeaa9415 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -5,6 +5,7 @@
5 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) 5 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
6 */ 6 */
7 7
8#include <linux/config.h>
8#include <linux/string.h> 9#include <linux/string.h>
9#include <linux/slab.h> 10#include <linux/slab.h>
10#include <linux/file.h> 11#include <linux/file.h>
@@ -19,52 +20,67 @@
19#include <linux/capability.h> 20#include <linux/capability.h>
20#include <linux/cdev.h> 21#include <linux/cdev.h>
21#include <linux/fsnotify.h> 22#include <linux/fsnotify.h>
23#include <linux/sysctl.h>
24#include <linux/percpu_counter.h>
25
26#include <asm/atomic.h>
22 27
23/* sysctl tunables... */ 28/* sysctl tunables... */
24struct files_stat_struct files_stat = { 29struct files_stat_struct files_stat = {
25 .max_files = NR_FILE 30 .max_files = NR_FILE
26}; 31};
27 32
28EXPORT_SYMBOL(files_stat); /* Needed by unix.o */
29
30/* public. Not pretty! */ 33/* public. Not pretty! */
31 __cacheline_aligned_in_smp DEFINE_SPINLOCK(files_lock); 34__cacheline_aligned_in_smp DEFINE_SPINLOCK(files_lock);
32 35
33static DEFINE_SPINLOCK(filp_count_lock); 36static struct percpu_counter nr_files __cacheline_aligned_in_smp;
34 37
35/* slab constructors and destructors are called from arbitrary 38static inline void file_free_rcu(struct rcu_head *head)
36 * context and must be fully threaded - use a local spinlock
37 * to protect files_stat.nr_files
38 */
39void filp_ctor(void *objp, struct kmem_cache *cachep, unsigned long cflags)
40{ 39{
41 if ((cflags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == 40 struct file *f = container_of(head, struct file, f_u.fu_rcuhead);
42 SLAB_CTOR_CONSTRUCTOR) { 41 kmem_cache_free(filp_cachep, f);
43 unsigned long flags;
44 spin_lock_irqsave(&filp_count_lock, flags);
45 files_stat.nr_files++;
46 spin_unlock_irqrestore(&filp_count_lock, flags);
47 }
48} 42}
49 43
50void filp_dtor(void *objp, struct kmem_cache *cachep, unsigned long dflags) 44static inline void file_free(struct file *f)
51{ 45{
52 unsigned long flags; 46 percpu_counter_dec(&nr_files);
53 spin_lock_irqsave(&filp_count_lock, flags); 47 call_rcu(&f->f_u.fu_rcuhead, file_free_rcu);
54 files_stat.nr_files--;
55 spin_unlock_irqrestore(&filp_count_lock, flags);
56} 48}
57 49
58static inline void file_free_rcu(struct rcu_head *head) 50/*
51 * Return the total number of open files in the system
52 */
53static int get_nr_files(void)
59{ 54{
60 struct file *f = container_of(head, struct file, f_u.fu_rcuhead); 55 return percpu_counter_read_positive(&nr_files);
61 kmem_cache_free(filp_cachep, f);
62} 56}
63 57
64static inline void file_free(struct file *f) 58/*
59 * Return the maximum number of open files in the system
60 */
61int get_max_files(void)
65{ 62{
66 call_rcu(&f->f_u.fu_rcuhead, file_free_rcu); 63 return files_stat.max_files;
67} 64}
65EXPORT_SYMBOL_GPL(get_max_files);
66
67/*
68 * Handle nr_files sysctl
69 */
70#if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
71int proc_nr_files(ctl_table *table, int write, struct file *filp,
72 void __user *buffer, size_t *lenp, loff_t *ppos)
73{
74 files_stat.nr_files = get_nr_files();
75 return proc_dointvec(table, write, filp, buffer, lenp, ppos);
76}
77#else
78int proc_nr_files(ctl_table *table, int write, struct file *filp,
79 void __user *buffer, size_t *lenp, loff_t *ppos)
80{
81 return -ENOSYS;
82}
83#endif
68 84
69/* Find an unused file structure and return a pointer to it. 85/* Find an unused file structure and return a pointer to it.
70 * Returns NULL, if there are no more free file structures or 86 * Returns NULL, if there are no more free file structures or
@@ -78,14 +94,20 @@ struct file *get_empty_filp(void)
78 /* 94 /*
79 * Privileged users can go above max_files 95 * Privileged users can go above max_files
80 */ 96 */
81 if (files_stat.nr_files >= files_stat.max_files && 97 if (get_nr_files() >= files_stat.max_files && !capable(CAP_SYS_ADMIN)) {
82 !capable(CAP_SYS_ADMIN)) 98 /*
83 goto over; 99 * percpu_counters are inaccurate. Do an expensive check before
100 * we go and fail.
101 */
102 if (percpu_counter_sum(&nr_files) >= files_stat.max_files)
103 goto over;
104 }
84 105
85 f = kmem_cache_alloc(filp_cachep, GFP_KERNEL); 106 f = kmem_cache_alloc(filp_cachep, GFP_KERNEL);
86 if (f == NULL) 107 if (f == NULL)
87 goto fail; 108 goto fail;
88 109
110 percpu_counter_inc(&nr_files);
89 memset(f, 0, sizeof(*f)); 111 memset(f, 0, sizeof(*f));
90 if (security_file_alloc(f)) 112 if (security_file_alloc(f))
91 goto fail_sec; 113 goto fail_sec;
@@ -101,10 +123,10 @@ struct file *get_empty_filp(void)
101 123
102over: 124over:
103 /* Ran out of filps - report that */ 125 /* Ran out of filps - report that */
104 if (files_stat.nr_files > old_max) { 126 if (get_nr_files() > old_max) {
105 printk(KERN_INFO "VFS: file-max limit %d reached\n", 127 printk(KERN_INFO "VFS: file-max limit %d reached\n",
106 files_stat.max_files); 128 get_max_files());
107 old_max = files_stat.nr_files; 129 old_max = get_nr_files();
108 } 130 }
109 goto fail; 131 goto fail;
110 132
@@ -276,4 +298,5 @@ void __init files_init(unsigned long mempages)
276 if (files_stat.max_files < NR_FILE) 298 if (files_stat.max_files < NR_FILE)
277 files_stat.max_files = NR_FILE; 299 files_stat.max_files = NR_FILE;
278 files_defer_init(); 300 files_defer_init();
301 percpu_counter_init(&nr_files);
279} 302}
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 21fd59c7bc24..c72a8a97935c 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -111,6 +111,8 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
111 111
112 /* Doesn't hurt to "reset" the validity timeout */ 112 /* Doesn't hurt to "reset" the validity timeout */
113 fuse_invalidate_entry_cache(entry); 113 fuse_invalidate_entry_cache(entry);
114
115 /* For negative dentries, always do a fresh lookup */
114 if (!inode) 116 if (!inode)
115 return 0; 117 return 0;
116 118
@@ -122,6 +124,9 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
122 fuse_lookup_init(req, entry->d_parent->d_inode, entry, &outarg); 124 fuse_lookup_init(req, entry->d_parent->d_inode, entry, &outarg);
123 request_send(fc, req); 125 request_send(fc, req);
124 err = req->out.h.error; 126 err = req->out.h.error;
127 /* Zero nodeid is same as -ENOENT */
128 if (!err && !outarg.nodeid)
129 err = -ENOENT;
125 if (!err) { 130 if (!err) {
126 struct fuse_inode *fi = get_fuse_inode(inode); 131 struct fuse_inode *fi = get_fuse_inode(inode);
127 if (outarg.nodeid != get_node_id(inode)) { 132 if (outarg.nodeid != get_node_id(inode)) {
@@ -190,8 +195,9 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
190 fuse_lookup_init(req, dir, entry, &outarg); 195 fuse_lookup_init(req, dir, entry, &outarg);
191 request_send(fc, req); 196 request_send(fc, req);
192 err = req->out.h.error; 197 err = req->out.h.error;
193 if (!err && ((outarg.nodeid && invalid_nodeid(outarg.nodeid)) || 198 /* Zero nodeid is same as -ENOENT, but with valid timeout */
194 !valid_mode(outarg.attr.mode))) 199 if (!err && outarg.nodeid &&
200 (invalid_nodeid(outarg.nodeid) || !valid_mode(outarg.attr.mode)))
195 err = -EIO; 201 err = -EIO;
196 if (!err && outarg.nodeid) { 202 if (!err && outarg.nodeid) {
197 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, 203 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index b35195289945..25fa8bba8cb5 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -56,48 +56,10 @@ static void huge_pagevec_release(struct pagevec *pvec)
56 pagevec_reinit(pvec); 56 pagevec_reinit(pvec);
57} 57}
58 58
59/*
60 * huge_pages_needed tries to determine the number of new huge pages that
61 * will be required to fully populate this VMA. This will be equal to
62 * the size of the VMA in huge pages minus the number of huge pages
63 * (covered by this VMA) that are found in the page cache.
64 *
65 * Result is in bytes to be compatible with is_hugepage_mem_enough()
66 */
67static unsigned long
68huge_pages_needed(struct address_space *mapping, struct vm_area_struct *vma)
69{
70 int i;
71 struct pagevec pvec;
72 unsigned long start = vma->vm_start;
73 unsigned long end = vma->vm_end;
74 unsigned long hugepages = (end - start) >> HPAGE_SHIFT;
75 pgoff_t next = vma->vm_pgoff >> (HPAGE_SHIFT - PAGE_SHIFT);
76 pgoff_t endpg = next + hugepages;
77
78 pagevec_init(&pvec, 0);
79 while (next < endpg) {
80 if (!pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE))
81 break;
82 for (i = 0; i < pagevec_count(&pvec); i++) {
83 struct page *page = pvec.pages[i];
84 if (page->index > next)
85 next = page->index;
86 if (page->index >= endpg)
87 break;
88 next++;
89 hugepages--;
90 }
91 huge_pagevec_release(&pvec);
92 }
93 return hugepages << HPAGE_SHIFT;
94}
95
96static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) 59static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
97{ 60{
98 struct inode *inode = file->f_dentry->d_inode; 61 struct inode *inode = file->f_dentry->d_inode;
99 struct address_space *mapping = inode->i_mapping; 62 struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode);
100 unsigned long bytes;
101 loff_t len, vma_len; 63 loff_t len, vma_len;
102 int ret; 64 int ret;
103 65
@@ -113,10 +75,6 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
113 if (vma->vm_end - vma->vm_start < HPAGE_SIZE) 75 if (vma->vm_end - vma->vm_start < HPAGE_SIZE)
114 return -EINVAL; 76 return -EINVAL;
115 77
116 bytes = huge_pages_needed(mapping, vma);
117 if (!is_hugepage_mem_enough(bytes))
118 return -ENOMEM;
119
120 vma_len = (loff_t)(vma->vm_end - vma->vm_start); 78 vma_len = (loff_t)(vma->vm_end - vma->vm_start);
121 79
122 mutex_lock(&inode->i_mutex); 80 mutex_lock(&inode->i_mutex);
@@ -129,6 +87,10 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
129 if (!(vma->vm_flags & VM_WRITE) && len > inode->i_size) 87 if (!(vma->vm_flags & VM_WRITE) && len > inode->i_size)
130 goto out; 88 goto out;
131 89
90 if (vma->vm_flags & VM_MAYSHARE)
91 if (hugetlb_extend_reservation(info, len >> HPAGE_SHIFT) != 0)
92 goto out;
93
132 ret = 0; 94 ret = 0;
133 hugetlb_prefault_arch_hook(vma->vm_mm); 95 hugetlb_prefault_arch_hook(vma->vm_mm);
134 if (inode->i_size < len) 96 if (inode->i_size < len)
@@ -227,13 +189,18 @@ static void truncate_huge_page(struct page *page)
227 put_page(page); 189 put_page(page);
228} 190}
229 191
230static void truncate_hugepages(struct address_space *mapping, loff_t lstart) 192static void truncate_hugepages(struct inode *inode, loff_t lstart)
231{ 193{
194 struct address_space *mapping = &inode->i_data;
232 const pgoff_t start = lstart >> HPAGE_SHIFT; 195 const pgoff_t start = lstart >> HPAGE_SHIFT;
233 struct pagevec pvec; 196 struct pagevec pvec;
234 pgoff_t next; 197 pgoff_t next;
235 int i; 198 int i;
236 199
200 hugetlb_truncate_reservation(HUGETLBFS_I(inode),
201 lstart >> HPAGE_SHIFT);
202 if (!mapping->nrpages)
203 return;
237 pagevec_init(&pvec, 0); 204 pagevec_init(&pvec, 0);
238 next = start; 205 next = start;
239 while (1) { 206 while (1) {
@@ -262,8 +229,7 @@ static void truncate_hugepages(struct address_space *mapping, loff_t lstart)
262 229
263static void hugetlbfs_delete_inode(struct inode *inode) 230static void hugetlbfs_delete_inode(struct inode *inode)
264{ 231{
265 if (inode->i_data.nrpages) 232 truncate_hugepages(inode, 0);
266 truncate_hugepages(&inode->i_data, 0);
267 clear_inode(inode); 233 clear_inode(inode);
268} 234}
269 235
@@ -296,8 +262,7 @@ static void hugetlbfs_forget_inode(struct inode *inode)
296 inode->i_state |= I_FREEING; 262 inode->i_state |= I_FREEING;
297 inodes_stat.nr_inodes--; 263 inodes_stat.nr_inodes--;
298 spin_unlock(&inode_lock); 264 spin_unlock(&inode_lock);
299 if (inode->i_data.nrpages) 265 truncate_hugepages(inode, 0);
300 truncate_hugepages(&inode->i_data, 0);
301 clear_inode(inode); 266 clear_inode(inode);
302 destroy_inode(inode); 267 destroy_inode(inode);
303} 268}
@@ -356,7 +321,7 @@ static int hugetlb_vmtruncate(struct inode *inode, loff_t offset)
356 if (!prio_tree_empty(&mapping->i_mmap)) 321 if (!prio_tree_empty(&mapping->i_mmap))
357 hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff); 322 hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff);
358 spin_unlock(&mapping->i_mmap_lock); 323 spin_unlock(&mapping->i_mmap_lock);
359 truncate_hugepages(mapping, offset); 324 truncate_hugepages(inode, offset);
360 return 0; 325 return 0;
361} 326}
362 327
@@ -573,6 +538,7 @@ static struct inode *hugetlbfs_alloc_inode(struct super_block *sb)
573 hugetlbfs_inc_free_inodes(sbinfo); 538 hugetlbfs_inc_free_inodes(sbinfo);
574 return NULL; 539 return NULL;
575 } 540 }
541 p->prereserved_hpages = 0;
576 return &p->vfs_inode; 542 return &p->vfs_inode;
577} 543}
578 544
@@ -771,21 +737,6 @@ static struct file_system_type hugetlbfs_fs_type = {
771 737
772static struct vfsmount *hugetlbfs_vfsmount; 738static struct vfsmount *hugetlbfs_vfsmount;
773 739
774/*
775 * Return the next identifier for a shm file
776 */
777static unsigned long hugetlbfs_counter(void)
778{
779 static DEFINE_SPINLOCK(lock);
780 static unsigned long counter;
781 unsigned long ret;
782
783 spin_lock(&lock);
784 ret = ++counter;
785 spin_unlock(&lock);
786 return ret;
787}
788
789static int can_do_hugetlb_shm(void) 740static int can_do_hugetlb_shm(void)
790{ 741{
791 return likely(capable(CAP_IPC_LOCK) || 742 return likely(capable(CAP_IPC_LOCK) ||
@@ -801,18 +752,16 @@ struct file *hugetlb_zero_setup(size_t size)
801 struct dentry *dentry, *root; 752 struct dentry *dentry, *root;
802 struct qstr quick_string; 753 struct qstr quick_string;
803 char buf[16]; 754 char buf[16];
755 static atomic_t counter;
804 756
805 if (!can_do_hugetlb_shm()) 757 if (!can_do_hugetlb_shm())
806 return ERR_PTR(-EPERM); 758 return ERR_PTR(-EPERM);
807 759
808 if (!is_hugepage_mem_enough(size))
809 return ERR_PTR(-ENOMEM);
810
811 if (!user_shm_lock(size, current->user)) 760 if (!user_shm_lock(size, current->user))
812 return ERR_PTR(-ENOMEM); 761 return ERR_PTR(-ENOMEM);
813 762
814 root = hugetlbfs_vfsmount->mnt_root; 763 root = hugetlbfs_vfsmount->mnt_root;
815 snprintf(buf, 16, "%lu", hugetlbfs_counter()); 764 snprintf(buf, 16, "%u", atomic_inc_return(&counter));
816 quick_string.name = buf; 765 quick_string.name = buf;
817 quick_string.len = strlen(quick_string.name); 766 quick_string.len = strlen(quick_string.name);
818 quick_string.hash = 0; 767 quick_string.hash = 0;
@@ -831,6 +780,11 @@ struct file *hugetlb_zero_setup(size_t size)
831 if (!inode) 780 if (!inode)
832 goto out_file; 781 goto out_file;
833 782
783 error = -ENOMEM;
784 if (hugetlb_extend_reservation(HUGETLBFS_I(inode),
785 size >> HPAGE_SHIFT) != 0)
786 goto out_inode;
787
834 d_instantiate(dentry, inode); 788 d_instantiate(dentry, inode);
835 inode->i_size = size; 789 inode->i_size = size;
836 inode->i_nlink = 0; 790 inode->i_nlink = 0;
@@ -841,6 +795,8 @@ struct file *hugetlb_zero_setup(size_t size)
841 file->f_mode = FMODE_WRITE | FMODE_READ; 795 file->f_mode = FMODE_WRITE | FMODE_READ;
842 return file; 796 return file;
843 797
798out_inode:
799 iput(inode);
844out_file: 800out_file:
845 put_filp(file); 801 put_filp(file);
846out_dentry: 802out_dentry:
diff --git a/fs/isofs/joliet.c b/fs/isofs/joliet.c
index 2931de7f1a6a..81a90e170ac3 100644
--- a/fs/isofs/joliet.c
+++ b/fs/isofs/joliet.c
@@ -11,7 +11,7 @@
11#include "isofs.h" 11#include "isofs.h"
12 12
13/* 13/*
14 * Convert Unicode 16 to UTF8 or ASCII. 14 * Convert Unicode 16 to UTF-8 or ASCII.
15 */ 15 */
16static int 16static int
17uni16_to_x8(unsigned char *ascii, u16 *uni, int len, struct nls_table *nls) 17uni16_to_x8(unsigned char *ascii, u16 *uni, int len, struct nls_table *nls)
diff --git a/fs/jffs2/nodelist.c b/fs/jffs2/nodelist.c
index b635e167a3fa..d4d0c41490cd 100644
--- a/fs/jffs2/nodelist.c
+++ b/fs/jffs2/nodelist.c
@@ -406,7 +406,8 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
406 int err = 0, pointed = 0; 406 int err = 0, pointed = 0;
407 struct jffs2_eraseblock *jeb; 407 struct jffs2_eraseblock *jeb;
408 unsigned char *buffer; 408 unsigned char *buffer;
409 uint32_t crc, ofs, retlen, len; 409 uint32_t crc, ofs, len;
410 size_t retlen;
410 411
411 BUG_ON(tn->csize == 0); 412 BUG_ON(tn->csize == 0);
412 413
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 5f0652df5d47..f1695642d0f7 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -112,7 +112,7 @@ static struct jffs2_raw_node_ref *jffs2_first_valid_node(struct jffs2_raw_node_r
112 * negative error code on failure. 112 * negative error code on failure.
113 */ 113 */
114static inline int read_direntry(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref, 114static inline int read_direntry(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref,
115 struct jffs2_raw_dirent *rd, uint32_t read, struct jffs2_full_dirent **fdp, 115 struct jffs2_raw_dirent *rd, size_t read, struct jffs2_full_dirent **fdp,
116 uint32_t *latest_mctime, uint32_t *mctime_ver) 116 uint32_t *latest_mctime, uint32_t *mctime_ver)
117{ 117{
118 struct jffs2_full_dirent *fd; 118 struct jffs2_full_dirent *fd;
diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
index 3e51dd1da8aa..cf55b221fc2b 100644
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -233,7 +233,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
233 c->nextblock->dirty_size = 0; 233 c->nextblock->dirty_size = 0;
234 } 234 }
235#ifdef CONFIG_JFFS2_FS_WRITEBUFFER 235#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
236 if (!jffs2_can_mark_obsolete(c) && c->nextblock && (c->nextblock->free_size % c->wbuf_pagesize)) { 236 if (!jffs2_can_mark_obsolete(c) && c->wbuf_pagesize && c->nextblock && (c->nextblock->free_size % c->wbuf_pagesize)) {
237 /* If we're going to start writing into a block which already 237 /* If we're going to start writing into a block which already
238 contains data, and the end of the data isn't page-aligned, 238 contains data, and the end of the data isn't page-aligned,
239 skip a little and align it. */ 239 skip a little and align it. */
diff --git a/fs/jfs/Makefile b/fs/jfs/Makefile
index 6f1e0e95587a..3adb6395e42d 100644
--- a/fs/jfs/Makefile
+++ b/fs/jfs/Makefile
@@ -8,7 +8,8 @@ jfs-y := super.o file.o inode.o namei.o jfs_mount.o jfs_umount.o \
8 jfs_xtree.o jfs_imap.o jfs_debug.o jfs_dmap.o \ 8 jfs_xtree.o jfs_imap.o jfs_debug.o jfs_dmap.o \
9 jfs_unicode.o jfs_dtree.o jfs_inode.o \ 9 jfs_unicode.o jfs_dtree.o jfs_inode.o \
10 jfs_extent.o symlink.o jfs_metapage.o \ 10 jfs_extent.o symlink.o jfs_metapage.o \
11 jfs_logmgr.o jfs_txnmgr.o jfs_uniupr.o resize.o xattr.o 11 jfs_logmgr.o jfs_txnmgr.o jfs_uniupr.o \
12 resize.o xattr.o ioctl.o
12 13
13jfs-$(CONFIG_JFS_POSIX_ACL) += acl.o 14jfs-$(CONFIG_JFS_POSIX_ACL) += acl.o
14 15
diff --git a/fs/jfs/acl.c b/fs/jfs/acl.c
index 461e4934ca7c..e2281300979c 100644
--- a/fs/jfs/acl.c
+++ b/fs/jfs/acl.c
@@ -183,6 +183,9 @@ cleanup:
183 posix_acl_release(acl); 183 posix_acl_release(acl);
184 } else 184 } else
185 inode->i_mode &= ~current->fs->umask; 185 inode->i_mode &= ~current->fs->umask;
186
187 JFS_IP(inode)->mode2 = (JFS_IP(inode)->mode2 & 0xffff0000) |
188 inode->i_mode;
186 189
187 return rc; 190 return rc;
188} 191}
@@ -207,12 +210,12 @@ static int jfs_acl_chmod(struct inode *inode)
207 rc = posix_acl_chmod_masq(clone, inode->i_mode); 210 rc = posix_acl_chmod_masq(clone, inode->i_mode);
208 if (!rc) { 211 if (!rc) {
209 tid_t tid = txBegin(inode->i_sb, 0); 212 tid_t tid = txBegin(inode->i_sb, 0);
210 down(&JFS_IP(inode)->commit_sem); 213 mutex_lock(&JFS_IP(inode)->commit_mutex);
211 rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, clone); 214 rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, clone);
212 if (!rc) 215 if (!rc)
213 rc = txCommit(tid, 1, &inode, 0); 216 rc = txCommit(tid, 1, &inode, 0);
214 txEnd(tid); 217 txEnd(tid);
215 up(&JFS_IP(inode)->commit_sem); 218 mutex_unlock(&JFS_IP(inode)->commit_mutex);
216 } 219 }
217 220
218 posix_acl_release(clone); 221 posix_acl_release(clone);
diff --git a/fs/jfs/file.c b/fs/jfs/file.c
index c2c19c9ed9a4..e1ac6e497e2b 100644
--- a/fs/jfs/file.c
+++ b/fs/jfs/file.c
@@ -113,4 +113,5 @@ struct file_operations jfs_file_operations = {
113 .sendfile = generic_file_sendfile, 113 .sendfile = generic_file_sendfile,
114 .fsync = jfs_fsync, 114 .fsync = jfs_fsync,
115 .release = jfs_release, 115 .release = jfs_release,
116 .ioctl = jfs_ioctl,
116}; 117};
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index 9f942ca8e4e3..51a5fed90cca 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -55,6 +55,7 @@ void jfs_read_inode(struct inode *inode)
55 inode->i_op = &jfs_file_inode_operations; 55 inode->i_op = &jfs_file_inode_operations;
56 init_special_inode(inode, inode->i_mode, inode->i_rdev); 56 init_special_inode(inode, inode->i_mode, inode->i_rdev);
57 } 57 }
58 jfs_set_inode_flags(inode);
58} 59}
59 60
60/* 61/*
@@ -89,16 +90,16 @@ int jfs_commit_inode(struct inode *inode, int wait)
89 } 90 }
90 91
91 tid = txBegin(inode->i_sb, COMMIT_INODE); 92 tid = txBegin(inode->i_sb, COMMIT_INODE);
92 down(&JFS_IP(inode)->commit_sem); 93 mutex_lock(&JFS_IP(inode)->commit_mutex);
93 94
94 /* 95 /*
95 * Retest inode state after taking commit_sem 96 * Retest inode state after taking commit_mutex
96 */ 97 */
97 if (inode->i_nlink && test_cflag(COMMIT_Dirty, inode)) 98 if (inode->i_nlink && test_cflag(COMMIT_Dirty, inode))
98 rc = txCommit(tid, 1, &inode, wait ? COMMIT_SYNC : 0); 99 rc = txCommit(tid, 1, &inode, wait ? COMMIT_SYNC : 0);
99 100
100 txEnd(tid); 101 txEnd(tid);
101 up(&JFS_IP(inode)->commit_sem); 102 mutex_unlock(&JFS_IP(inode)->commit_mutex);
102 return rc; 103 return rc;
103} 104}
104 105
@@ -335,18 +336,18 @@ void jfs_truncate_nolock(struct inode *ip, loff_t length)
335 tid = txBegin(ip->i_sb, 0); 336 tid = txBegin(ip->i_sb, 0);
336 337
337 /* 338 /*
338 * The commit_sem cannot be taken before txBegin. 339 * The commit_mutex cannot be taken before txBegin.
339 * txBegin may block and there is a chance the inode 340 * txBegin may block and there is a chance the inode
340 * could be marked dirty and need to be committed 341 * could be marked dirty and need to be committed
341 * before txBegin unblocks 342 * before txBegin unblocks
342 */ 343 */
343 down(&JFS_IP(ip)->commit_sem); 344 mutex_lock(&JFS_IP(ip)->commit_mutex);
344 345
345 newsize = xtTruncate(tid, ip, length, 346 newsize = xtTruncate(tid, ip, length,
346 COMMIT_TRUNCATE | COMMIT_PWMAP); 347 COMMIT_TRUNCATE | COMMIT_PWMAP);
347 if (newsize < 0) { 348 if (newsize < 0) {
348 txEnd(tid); 349 txEnd(tid);
349 up(&JFS_IP(ip)->commit_sem); 350 mutex_unlock(&JFS_IP(ip)->commit_mutex);
350 break; 351 break;
351 } 352 }
352 353
@@ -355,7 +356,7 @@ void jfs_truncate_nolock(struct inode *ip, loff_t length)
355 356
356 txCommit(tid, 1, &ip, 0); 357 txCommit(tid, 1, &ip, 0);
357 txEnd(tid); 358 txEnd(tid);
358 up(&JFS_IP(ip)->commit_sem); 359 mutex_unlock(&JFS_IP(ip)->commit_mutex);
359 } while (newsize > length); /* Truncate isn't always atomic */ 360 } while (newsize > length); /* Truncate isn't always atomic */
360} 361}
361 362
diff --git a/fs/jfs/ioctl.c b/fs/jfs/ioctl.c
new file mode 100644
index 000000000000..67b3774820eb
--- /dev/null
+++ b/fs/jfs/ioctl.c
@@ -0,0 +1,107 @@
1/*
2 * linux/fs/jfs/ioctl.c
3 *
4 * Copyright (C) 2006 Herbert Poetzl
5 * adapted from Remy Card's ext2/ioctl.c
6 */
7
8#include <linux/fs.h>
9#include <linux/ext2_fs.h>
10#include <linux/ctype.h>
11#include <linux/capability.h>
12#include <linux/time.h>
13#include <asm/current.h>
14#include <asm/uaccess.h>
15
16#include "jfs_incore.h"
17#include "jfs_dinode.h"
18#include "jfs_inode.h"
19
20
21static struct {
22 long jfs_flag;
23 long ext2_flag;
24} jfs_map[] = {
25 {JFS_NOATIME_FL, EXT2_NOATIME_FL},
26 {JFS_DIRSYNC_FL, EXT2_DIRSYNC_FL},
27 {JFS_SYNC_FL, EXT2_SYNC_FL},
28 {JFS_SECRM_FL, EXT2_SECRM_FL},
29 {JFS_UNRM_FL, EXT2_UNRM_FL},
30 {JFS_APPEND_FL, EXT2_APPEND_FL},
31 {JFS_IMMUTABLE_FL, EXT2_IMMUTABLE_FL},
32 {0, 0},
33};
34
35static long jfs_map_ext2(unsigned long flags, int from)
36{
37 int index=0;
38 long mapped=0;
39
40 while (jfs_map[index].jfs_flag) {
41 if (from) {
42 if (jfs_map[index].ext2_flag & flags)
43 mapped |= jfs_map[index].jfs_flag;
44 } else {
45 if (jfs_map[index].jfs_flag & flags)
46 mapped |= jfs_map[index].ext2_flag;
47 }
48 index++;
49 }
50 return mapped;
51}
52
53
54int jfs_ioctl(struct inode * inode, struct file * filp, unsigned int cmd,
55 unsigned long arg)
56{
57 struct jfs_inode_info *jfs_inode = JFS_IP(inode);
58 unsigned int flags;
59
60 switch (cmd) {
61 case JFS_IOC_GETFLAGS:
62 flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE;
63 flags = jfs_map_ext2(flags, 0);
64 return put_user(flags, (int __user *) arg);
65 case JFS_IOC_SETFLAGS: {
66 unsigned int oldflags;
67
68 if (IS_RDONLY(inode))
69 return -EROFS;
70
71 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
72 return -EACCES;
73
74 if (get_user(flags, (int __user *) arg))
75 return -EFAULT;
76
77 flags = jfs_map_ext2(flags, 1);
78 if (!S_ISDIR(inode->i_mode))
79 flags &= ~JFS_DIRSYNC_FL;
80
81 oldflags = jfs_inode->mode2;
82
83 /*
84 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
85 * the relevant capability.
86 */
87 if ((oldflags & JFS_IMMUTABLE_FL) ||
88 ((flags ^ oldflags) &
89 (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
90 if (!capable(CAP_LINUX_IMMUTABLE))
91 return -EPERM;
92 }
93
94 flags = flags & JFS_FL_USER_MODIFIABLE;
95 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
96 jfs_inode->mode2 = flags;
97
98 jfs_set_inode_flags(inode);
99 inode->i_ctime = CURRENT_TIME_SEC;
100 mark_inode_dirty(inode);
101 return 0;
102 }
103 default:
104 return -ENOTTY;
105 }
106}
107
diff --git a/fs/jfs/jfs_dinode.h b/fs/jfs/jfs_dinode.h
index 580a3258449b..9f2572aea561 100644
--- a/fs/jfs/jfs_dinode.h
+++ b/fs/jfs/jfs_dinode.h
@@ -139,13 +139,36 @@ struct dinode {
139 139
140/* more extended mode bits: attributes for OS/2 */ 140/* more extended mode bits: attributes for OS/2 */
141#define IREADONLY 0x02000000 /* no write access to file */ 141#define IREADONLY 0x02000000 /* no write access to file */
142#define IARCHIVE 0x40000000 /* file archive bit */
143#define ISYSTEM 0x08000000 /* system file */
144#define IHIDDEN 0x04000000 /* hidden file */ 142#define IHIDDEN 0x04000000 /* hidden file */
145#define IRASH 0x4E000000 /* mask for changeable attributes */ 143#define ISYSTEM 0x08000000 /* system file */
146#define INEWNAME 0x80000000 /* non-8.3 filename format */ 144
147#define IDIRECTORY 0x20000000 /* directory (shadow of real bit) */ 145#define IDIRECTORY 0x20000000 /* directory (shadow of real bit) */
146#define IARCHIVE 0x40000000 /* file archive bit */
147#define INEWNAME 0x80000000 /* non-8.3 filename format */
148
149#define IRASH 0x4E000000 /* mask for changeable attributes */
148#define ATTRSHIFT 25 /* bits to shift to move attribute 150#define ATTRSHIFT 25 /* bits to shift to move attribute
149 specification to mode position */ 151 specification to mode position */
150 152
153/* extended attributes for Linux */
154
155#define JFS_NOATIME_FL 0x00080000 /* do not update atime */
156
157#define JFS_DIRSYNC_FL 0x00100000 /* dirsync behaviour */
158#define JFS_SYNC_FL 0x00200000 /* Synchronous updates */
159#define JFS_SECRM_FL 0x00400000 /* Secure deletion */
160#define JFS_UNRM_FL 0x00800000 /* allow for undelete */
161
162#define JFS_APPEND_FL 0x01000000 /* writes to file may only append */
163#define JFS_IMMUTABLE_FL 0x02000000 /* Immutable file */
164
165#define JFS_FL_USER_VISIBLE 0x03F80000
166#define JFS_FL_USER_MODIFIABLE 0x03F80000
167#define JFS_FL_INHERIT 0x03C80000
168
169/* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
170#define JFS_IOC_GETFLAGS _IOR('f', 1, long)
171#define JFS_IOC_SETFLAGS _IOW('f', 2, long)
172
173
151#endif /*_H_JFS_DINODE */ 174#endif /*_H_JFS_DINODE */
diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index 2967b7393415..c161c98954e0 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -64,9 +64,9 @@
64 * to the persistent bitmaps in dmaps) is guarded by (busy) buffers. 64 * to the persistent bitmaps in dmaps) is guarded by (busy) buffers.
65 */ 65 */
66 66
67#define BMAP_LOCK_INIT(bmp) init_MUTEX(&bmp->db_bmaplock) 67#define BMAP_LOCK_INIT(bmp) mutex_init(&bmp->db_bmaplock)
68#define BMAP_LOCK(bmp) down(&bmp->db_bmaplock) 68#define BMAP_LOCK(bmp) mutex_lock(&bmp->db_bmaplock)
69#define BMAP_UNLOCK(bmp) up(&bmp->db_bmaplock) 69#define BMAP_UNLOCK(bmp) mutex_unlock(&bmp->db_bmaplock)
70 70
71/* 71/*
72 * forward references 72 * forward references
@@ -125,7 +125,7 @@ static int dbGetL2AGSize(s64 nblocks);
125 * into the table, with the table elements yielding the maximum 125 * into the table, with the table elements yielding the maximum
126 * binary buddy of free bits within the character. 126 * binary buddy of free bits within the character.
127 */ 127 */
128static s8 budtab[256] = { 128static const s8 budtab[256] = {
129 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 129 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
130 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 130 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
131 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 131 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -532,10 +532,10 @@ dbUpdatePMap(struct inode *ipbmap,
532 532
533 lastlblkno = lblkno; 533 lastlblkno = lblkno;
534 534
535 LOGSYNC_LOCK(log, flags);
535 if (mp->lsn != 0) { 536 if (mp->lsn != 0) {
536 /* inherit older/smaller lsn */ 537 /* inherit older/smaller lsn */
537 logdiff(diffp, mp->lsn, log); 538 logdiff(diffp, mp->lsn, log);
538 LOGSYNC_LOCK(log, flags);
539 if (difft < diffp) { 539 if (difft < diffp) {
540 mp->lsn = lsn; 540 mp->lsn = lsn;
541 541
@@ -548,20 +548,17 @@ dbUpdatePMap(struct inode *ipbmap,
548 logdiff(diffp, mp->clsn, log); 548 logdiff(diffp, mp->clsn, log);
549 if (difft > diffp) 549 if (difft > diffp)
550 mp->clsn = tblk->clsn; 550 mp->clsn = tblk->clsn;
551 LOGSYNC_UNLOCK(log, flags);
552 } else { 551 } else {
553 mp->log = log; 552 mp->log = log;
554 mp->lsn = lsn; 553 mp->lsn = lsn;
555 554
556 /* insert bp after tblock in logsync list */ 555 /* insert bp after tblock in logsync list */
557 LOGSYNC_LOCK(log, flags);
558
559 log->count++; 556 log->count++;
560 list_add(&mp->synclist, &tblk->synclist); 557 list_add(&mp->synclist, &tblk->synclist);
561 558
562 mp->clsn = tblk->clsn; 559 mp->clsn = tblk->clsn;
563 LOGSYNC_UNLOCK(log, flags);
564 } 560 }
561 LOGSYNC_UNLOCK(log, flags);
565 } 562 }
566 563
567 /* write the last buffer. */ 564 /* write the last buffer. */
diff --git a/fs/jfs/jfs_dmap.h b/fs/jfs/jfs_dmap.h
index 32e25884e7e8..8b14cc8e0228 100644
--- a/fs/jfs/jfs_dmap.h
+++ b/fs/jfs/jfs_dmap.h
@@ -243,7 +243,7 @@ struct dbmap {
243struct bmap { 243struct bmap {
244 struct dbmap db_bmap; /* on-disk aggregate map descriptor */ 244 struct dbmap db_bmap; /* on-disk aggregate map descriptor */
245 struct inode *db_ipbmap; /* ptr to aggregate map incore inode */ 245 struct inode *db_ipbmap; /* ptr to aggregate map incore inode */
246 struct semaphore db_bmaplock; /* aggregate map lock */ 246 struct mutex db_bmaplock; /* aggregate map lock */
247 atomic_t db_active[MAXAG]; /* count of active, open files in AG */ 247 atomic_t db_active[MAXAG]; /* count of active, open files in AG */
248 u32 *db_DBmap; 248 u32 *db_DBmap;
249}; 249};
diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index 404f33eae507..6c3f08319846 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -1005,6 +1005,9 @@ static int dtSplitUp(tid_t tid,
1005 1005
1006 DT_PUTPAGE(smp); 1006 DT_PUTPAGE(smp);
1007 1007
1008 if (!DO_INDEX(ip))
1009 ip->i_size = xlen << sbi->l2bsize;
1010
1008 goto freeKeyName; 1011 goto freeKeyName;
1009 } 1012 }
1010 1013
@@ -1055,7 +1058,9 @@ static int dtSplitUp(tid_t tid,
1055 xaddr = addressPXD(pxd) + xlen; 1058 xaddr = addressPXD(pxd) + xlen;
1056 dbFree(ip, xaddr, (s64) n); 1059 dbFree(ip, xaddr, (s64) n);
1057 } 1060 }
1058 } 1061 } else if (!DO_INDEX(ip))
1062 ip->i_size = lengthPXD(pxd) << sbi->l2bsize;
1063
1059 1064
1060 extendOut: 1065 extendOut:
1061 DT_PUTPAGE(smp); 1066 DT_PUTPAGE(smp);
@@ -1098,6 +1103,9 @@ static int dtSplitUp(tid_t tid,
1098 goto splitOut; 1103 goto splitOut;
1099 } 1104 }
1100 1105
1106 if (!DO_INDEX(ip))
1107 ip->i_size += PSIZE;
1108
1101 /* 1109 /*
1102 * propagate up the router entry for the leaf page just split 1110 * propagate up the router entry for the leaf page just split
1103 * 1111 *
@@ -2424,6 +2432,9 @@ static int dtDeleteUp(tid_t tid, struct inode *ip,
2424 break; 2432 break;
2425 } 2433 }
2426 2434
2435 if (!DO_INDEX(ip))
2436 ip->i_size -= PSIZE;
2437
2427 return 0; 2438 return 0;
2428} 2439}
2429 2440
diff --git a/fs/jfs/jfs_extent.c b/fs/jfs/jfs_extent.c
index 4879603daa1c..5549378358bf 100644
--- a/fs/jfs/jfs_extent.c
+++ b/fs/jfs/jfs_extent.c
@@ -94,7 +94,7 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, boolean_t abnr)
94 txBeginAnon(ip->i_sb); 94 txBeginAnon(ip->i_sb);
95 95
96 /* Avoid race with jfs_commit_inode() */ 96 /* Avoid race with jfs_commit_inode() */
97 down(&JFS_IP(ip)->commit_sem); 97 mutex_lock(&JFS_IP(ip)->commit_mutex);
98 98
99 /* validate extent length */ 99 /* validate extent length */
100 if (xlen > MAXXLEN) 100 if (xlen > MAXXLEN)
@@ -136,14 +136,14 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, boolean_t abnr)
136 */ 136 */
137 nxlen = xlen; 137 nxlen = xlen;
138 if ((rc = extBalloc(ip, hint ? hint : INOHINT(ip), &nxlen, &nxaddr))) { 138 if ((rc = extBalloc(ip, hint ? hint : INOHINT(ip), &nxlen, &nxaddr))) {
139 up(&JFS_IP(ip)->commit_sem); 139 mutex_unlock(&JFS_IP(ip)->commit_mutex);
140 return (rc); 140 return (rc);
141 } 141 }
142 142
143 /* Allocate blocks to quota. */ 143 /* Allocate blocks to quota. */
144 if (DQUOT_ALLOC_BLOCK(ip, nxlen)) { 144 if (DQUOT_ALLOC_BLOCK(ip, nxlen)) {
145 dbFree(ip, nxaddr, (s64) nxlen); 145 dbFree(ip, nxaddr, (s64) nxlen);
146 up(&JFS_IP(ip)->commit_sem); 146 mutex_unlock(&JFS_IP(ip)->commit_mutex);
147 return -EDQUOT; 147 return -EDQUOT;
148 } 148 }
149 149
@@ -165,7 +165,7 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, boolean_t abnr)
165 if (rc) { 165 if (rc) {
166 dbFree(ip, nxaddr, nxlen); 166 dbFree(ip, nxaddr, nxlen);
167 DQUOT_FREE_BLOCK(ip, nxlen); 167 DQUOT_FREE_BLOCK(ip, nxlen);
168 up(&JFS_IP(ip)->commit_sem); 168 mutex_unlock(&JFS_IP(ip)->commit_mutex);
169 return (rc); 169 return (rc);
170 } 170 }
171 171
@@ -177,7 +177,7 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, boolean_t abnr)
177 177
178 mark_inode_dirty(ip); 178 mark_inode_dirty(ip);
179 179
180 up(&JFS_IP(ip)->commit_sem); 180 mutex_unlock(&JFS_IP(ip)->commit_mutex);
181 /* 181 /*
182 * COMMIT_SyncList flags an anonymous tlock on page that is on 182 * COMMIT_SyncList flags an anonymous tlock on page that is on
183 * sync list. 183 * sync list.
@@ -222,7 +222,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, boolean_t abnr)
222 /* This blocks if we are low on resources */ 222 /* This blocks if we are low on resources */
223 txBeginAnon(ip->i_sb); 223 txBeginAnon(ip->i_sb);
224 224
225 down(&JFS_IP(ip)->commit_sem); 225 mutex_lock(&JFS_IP(ip)->commit_mutex);
226 /* validate extent length */ 226 /* validate extent length */
227 if (nxlen > MAXXLEN) 227 if (nxlen > MAXXLEN)
228 nxlen = MAXXLEN; 228 nxlen = MAXXLEN;
@@ -258,7 +258,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, boolean_t abnr)
258 /* Allocat blocks to quota. */ 258 /* Allocat blocks to quota. */
259 if (DQUOT_ALLOC_BLOCK(ip, nxlen)) { 259 if (DQUOT_ALLOC_BLOCK(ip, nxlen)) {
260 dbFree(ip, nxaddr, (s64) nxlen); 260 dbFree(ip, nxaddr, (s64) nxlen);
261 up(&JFS_IP(ip)->commit_sem); 261 mutex_unlock(&JFS_IP(ip)->commit_mutex);
262 return -EDQUOT; 262 return -EDQUOT;
263 } 263 }
264 264
@@ -338,7 +338,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, boolean_t abnr)
338 338
339 mark_inode_dirty(ip); 339 mark_inode_dirty(ip);
340exit: 340exit:
341 up(&JFS_IP(ip)->commit_sem); 341 mutex_unlock(&JFS_IP(ip)->commit_mutex);
342 return (rc); 342 return (rc);
343} 343}
344#endif /* _NOTYET */ 344#endif /* _NOTYET */
@@ -439,12 +439,12 @@ int extRecord(struct inode *ip, xad_t * xp)
439 439
440 txBeginAnon(ip->i_sb); 440 txBeginAnon(ip->i_sb);
441 441
442 down(&JFS_IP(ip)->commit_sem); 442 mutex_lock(&JFS_IP(ip)->commit_mutex);
443 443
444 /* update the extent */ 444 /* update the extent */
445 rc = xtUpdate(0, ip, xp); 445 rc = xtUpdate(0, ip, xp);
446 446
447 up(&JFS_IP(ip)->commit_sem); 447 mutex_unlock(&JFS_IP(ip)->commit_mutex);
448 return rc; 448 return rc;
449} 449}
450 450
diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
index 31b4aa13dd4b..ccbe60aff83d 100644
--- a/fs/jfs/jfs_imap.c
+++ b/fs/jfs/jfs_imap.c
@@ -66,14 +66,14 @@ static HLIST_HEAD(aggregate_hash);
66 * imap locks 66 * imap locks
67 */ 67 */
68/* iag free list lock */ 68/* iag free list lock */
69#define IAGFREE_LOCK_INIT(imap) init_MUTEX(&imap->im_freelock) 69#define IAGFREE_LOCK_INIT(imap) mutex_init(&imap->im_freelock)
70#define IAGFREE_LOCK(imap) down(&imap->im_freelock) 70#define IAGFREE_LOCK(imap) mutex_lock(&imap->im_freelock)
71#define IAGFREE_UNLOCK(imap) up(&imap->im_freelock) 71#define IAGFREE_UNLOCK(imap) mutex_unlock(&imap->im_freelock)
72 72
73/* per ag iag list locks */ 73/* per ag iag list locks */
74#define AG_LOCK_INIT(imap,index) init_MUTEX(&(imap->im_aglock[index])) 74#define AG_LOCK_INIT(imap,index) mutex_init(&(imap->im_aglock[index]))
75#define AG_LOCK(imap,agno) down(&imap->im_aglock[agno]) 75#define AG_LOCK(imap,agno) mutex_lock(&imap->im_aglock[agno])
76#define AG_UNLOCK(imap,agno) up(&imap->im_aglock[agno]) 76#define AG_UNLOCK(imap,agno) mutex_unlock(&imap->im_aglock[agno])
77 77
78/* 78/*
79 * forward references 79 * forward references
@@ -1261,7 +1261,7 @@ int diFree(struct inode *ip)
1261 * to be freed by the transaction; 1261 * to be freed by the transaction;
1262 */ 1262 */
1263 tid = txBegin(ipimap->i_sb, COMMIT_FORCE); 1263 tid = txBegin(ipimap->i_sb, COMMIT_FORCE);
1264 down(&JFS_IP(ipimap)->commit_sem); 1264 mutex_lock(&JFS_IP(ipimap)->commit_mutex);
1265 1265
1266 /* acquire tlock of the iag page of the freed ixad 1266 /* acquire tlock of the iag page of the freed ixad
1267 * to force the page NOHOMEOK (even though no data is 1267 * to force the page NOHOMEOK (even though no data is
@@ -1294,7 +1294,7 @@ int diFree(struct inode *ip)
1294 rc = txCommit(tid, 1, &iplist[0], COMMIT_FORCE); 1294 rc = txCommit(tid, 1, &iplist[0], COMMIT_FORCE);
1295 1295
1296 txEnd(tid); 1296 txEnd(tid);
1297 up(&JFS_IP(ipimap)->commit_sem); 1297 mutex_unlock(&JFS_IP(ipimap)->commit_mutex);
1298 1298
1299 /* unlock the AG inode map information */ 1299 /* unlock the AG inode map information */
1300 AG_UNLOCK(imap, agno); 1300 AG_UNLOCK(imap, agno);
@@ -2554,13 +2554,13 @@ diNewIAG(struct inomap * imap, int *iagnop, int agno, struct metapage ** mpp)
2554 * addressing structure pointing to the new iag page; 2554 * addressing structure pointing to the new iag page;
2555 */ 2555 */
2556 tid = txBegin(sb, COMMIT_FORCE); 2556 tid = txBegin(sb, COMMIT_FORCE);
2557 down(&JFS_IP(ipimap)->commit_sem); 2557 mutex_lock(&JFS_IP(ipimap)->commit_mutex);
2558 2558
2559 /* update the inode map addressing structure to point to it */ 2559 /* update the inode map addressing structure to point to it */
2560 if ((rc = 2560 if ((rc =
2561 xtInsert(tid, ipimap, 0, blkno, xlen, &xaddr, 0))) { 2561 xtInsert(tid, ipimap, 0, blkno, xlen, &xaddr, 0))) {
2562 txEnd(tid); 2562 txEnd(tid);
2563 up(&JFS_IP(ipimap)->commit_sem); 2563 mutex_unlock(&JFS_IP(ipimap)->commit_mutex);
2564 /* Free the blocks allocated for the iag since it was 2564 /* Free the blocks allocated for the iag since it was
2565 * not successfully added to the inode map 2565 * not successfully added to the inode map
2566 */ 2566 */
@@ -2626,7 +2626,7 @@ diNewIAG(struct inomap * imap, int *iagnop, int agno, struct metapage ** mpp)
2626 rc = txCommit(tid, 1, &iplist[0], COMMIT_FORCE); 2626 rc = txCommit(tid, 1, &iplist[0], COMMIT_FORCE);
2627 2627
2628 txEnd(tid); 2628 txEnd(tid);
2629 up(&JFS_IP(ipimap)->commit_sem); 2629 mutex_unlock(&JFS_IP(ipimap)->commit_mutex);
2630 2630
2631 duplicateIXtree(sb, blkno, xlen, &xaddr); 2631 duplicateIXtree(sb, blkno, xlen, &xaddr);
2632 2632
@@ -2844,11 +2844,11 @@ diUpdatePMap(struct inode *ipimap,
2844 */ 2844 */
2845 lsn = tblk->lsn; 2845 lsn = tblk->lsn;
2846 log = JFS_SBI(tblk->sb)->log; 2846 log = JFS_SBI(tblk->sb)->log;
2847 LOGSYNC_LOCK(log, flags);
2847 if (mp->lsn != 0) { 2848 if (mp->lsn != 0) {
2848 /* inherit older/smaller lsn */ 2849 /* inherit older/smaller lsn */
2849 logdiff(difft, lsn, log); 2850 logdiff(difft, lsn, log);
2850 logdiff(diffp, mp->lsn, log); 2851 logdiff(diffp, mp->lsn, log);
2851 LOGSYNC_LOCK(log, flags);
2852 if (difft < diffp) { 2852 if (difft < diffp) {
2853 mp->lsn = lsn; 2853 mp->lsn = lsn;
2854 /* move mp after tblock in logsync list */ 2854 /* move mp after tblock in logsync list */
@@ -2860,17 +2860,15 @@ diUpdatePMap(struct inode *ipimap,
2860 logdiff(diffp, mp->clsn, log); 2860 logdiff(diffp, mp->clsn, log);
2861 if (difft > diffp) 2861 if (difft > diffp)
2862 mp->clsn = tblk->clsn; 2862 mp->clsn = tblk->clsn;
2863 LOGSYNC_UNLOCK(log, flags);
2864 } else { 2863 } else {
2865 mp->log = log; 2864 mp->log = log;
2866 mp->lsn = lsn; 2865 mp->lsn = lsn;
2867 /* insert mp after tblock in logsync list */ 2866 /* insert mp after tblock in logsync list */
2868 LOGSYNC_LOCK(log, flags);
2869 log->count++; 2867 log->count++;
2870 list_add(&mp->synclist, &tblk->synclist); 2868 list_add(&mp->synclist, &tblk->synclist);
2871 mp->clsn = tblk->clsn; 2869 mp->clsn = tblk->clsn;
2872 LOGSYNC_UNLOCK(log, flags);
2873 } 2870 }
2871 LOGSYNC_UNLOCK(log, flags);
2874 write_metapage(mp); 2872 write_metapage(mp);
2875 return (0); 2873 return (0);
2876} 2874}
@@ -3076,14 +3074,40 @@ static void duplicateIXtree(struct super_block *sb, s64 blkno,
3076static int copy_from_dinode(struct dinode * dip, struct inode *ip) 3074static int copy_from_dinode(struct dinode * dip, struct inode *ip)
3077{ 3075{
3078 struct jfs_inode_info *jfs_ip = JFS_IP(ip); 3076 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3077 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3079 3078
3080 jfs_ip->fileset = le32_to_cpu(dip->di_fileset); 3079 jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3081 jfs_ip->mode2 = le32_to_cpu(dip->di_mode); 3080 jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3082 3081
3083 ip->i_mode = le32_to_cpu(dip->di_mode) & 0xffff; 3082 ip->i_mode = le32_to_cpu(dip->di_mode) & 0xffff;
3083 if (sbi->umask != -1) {
3084 ip->i_mode = (ip->i_mode & ~0777) | (0777 & ~sbi->umask);
3085 /* For directories, add x permission if r is allowed by umask */
3086 if (S_ISDIR(ip->i_mode)) {
3087 if (ip->i_mode & 0400)
3088 ip->i_mode |= 0100;
3089 if (ip->i_mode & 0040)
3090 ip->i_mode |= 0010;
3091 if (ip->i_mode & 0004)
3092 ip->i_mode |= 0001;
3093 }
3094 }
3084 ip->i_nlink = le32_to_cpu(dip->di_nlink); 3095 ip->i_nlink = le32_to_cpu(dip->di_nlink);
3085 ip->i_uid = le32_to_cpu(dip->di_uid); 3096
3086 ip->i_gid = le32_to_cpu(dip->di_gid); 3097 jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3098 if (sbi->uid == -1)
3099 ip->i_uid = jfs_ip->saved_uid;
3100 else {
3101 ip->i_uid = sbi->uid;
3102 }
3103
3104 jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3105 if (sbi->gid == -1)
3106 ip->i_gid = jfs_ip->saved_gid;
3107 else {
3108 ip->i_gid = sbi->gid;
3109 }
3110
3087 ip->i_size = le64_to_cpu(dip->di_size); 3111 ip->i_size = le64_to_cpu(dip->di_size);
3088 ip->i_atime.tv_sec = le32_to_cpu(dip->di_atime.tv_sec); 3112 ip->i_atime.tv_sec = le32_to_cpu(dip->di_atime.tv_sec);
3089 ip->i_atime.tv_nsec = le32_to_cpu(dip->di_atime.tv_nsec); 3113 ip->i_atime.tv_nsec = le32_to_cpu(dip->di_atime.tv_nsec);
@@ -3134,21 +3158,33 @@ static int copy_from_dinode(struct dinode * dip, struct inode *ip)
3134static void copy_to_dinode(struct dinode * dip, struct inode *ip) 3158static void copy_to_dinode(struct dinode * dip, struct inode *ip)
3135{ 3159{
3136 struct jfs_inode_info *jfs_ip = JFS_IP(ip); 3160 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3161 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3137 3162
3138 dip->di_fileset = cpu_to_le32(jfs_ip->fileset); 3163 dip->di_fileset = cpu_to_le32(jfs_ip->fileset);
3139 dip->di_inostamp = cpu_to_le32(JFS_SBI(ip->i_sb)->inostamp); 3164 dip->di_inostamp = cpu_to_le32(sbi->inostamp);
3140 dip->di_number = cpu_to_le32(ip->i_ino); 3165 dip->di_number = cpu_to_le32(ip->i_ino);
3141 dip->di_gen = cpu_to_le32(ip->i_generation); 3166 dip->di_gen = cpu_to_le32(ip->i_generation);
3142 dip->di_size = cpu_to_le64(ip->i_size); 3167 dip->di_size = cpu_to_le64(ip->i_size);
3143 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks)); 3168 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3144 dip->di_nlink = cpu_to_le32(ip->i_nlink); 3169 dip->di_nlink = cpu_to_le32(ip->i_nlink);
3145 dip->di_uid = cpu_to_le32(ip->i_uid); 3170 if (sbi->uid == -1)
3146 dip->di_gid = cpu_to_le32(ip->i_gid); 3171 dip->di_uid = cpu_to_le32(ip->i_uid);
3172 else
3173 dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
3174 if (sbi->gid == -1)
3175 dip->di_gid = cpu_to_le32(ip->i_gid);
3176 else
3177 dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
3147 /* 3178 /*
3148 * mode2 is only needed for storing the higher order bits. 3179 * mode2 is only needed for storing the higher order bits.
3149 * Trust i_mode for the lower order ones 3180 * Trust i_mode for the lower order ones
3150 */ 3181 */
3151 dip->di_mode = cpu_to_le32((jfs_ip->mode2 & 0xffff0000) | ip->i_mode); 3182 if (sbi->umask == -1)
3183 dip->di_mode = cpu_to_le32((jfs_ip->mode2 & 0xffff0000) |
3184 ip->i_mode);
3185 else /* Leave the original permissions alone */
3186 dip->di_mode = cpu_to_le32(jfs_ip->mode2);
3187
3152 dip->di_atime.tv_sec = cpu_to_le32(ip->i_atime.tv_sec); 3188 dip->di_atime.tv_sec = cpu_to_le32(ip->i_atime.tv_sec);
3153 dip->di_atime.tv_nsec = cpu_to_le32(ip->i_atime.tv_nsec); 3189 dip->di_atime.tv_nsec = cpu_to_le32(ip->i_atime.tv_nsec);
3154 dip->di_ctime.tv_sec = cpu_to_le32(ip->i_ctime.tv_sec); 3190 dip->di_ctime.tv_sec = cpu_to_le32(ip->i_ctime.tv_sec);
diff --git a/fs/jfs/jfs_imap.h b/fs/jfs/jfs_imap.h
index 6b59adec036a..6e24465f0f98 100644
--- a/fs/jfs/jfs_imap.h
+++ b/fs/jfs/jfs_imap.h
@@ -140,8 +140,8 @@ struct dinomap {
140struct inomap { 140struct inomap {
141 struct dinomap im_imap; /* 4096: inode allocation control */ 141 struct dinomap im_imap; /* 4096: inode allocation control */
142 struct inode *im_ipimap; /* 4: ptr to inode for imap */ 142 struct inode *im_ipimap; /* 4: ptr to inode for imap */
143 struct semaphore im_freelock; /* 4: iag free list lock */ 143 struct mutex im_freelock; /* 4: iag free list lock */
144 struct semaphore im_aglock[MAXAG]; /* 512: per AG locks */ 144 struct mutex im_aglock[MAXAG]; /* 512: per AG locks */
145 u32 *im_DBGdimap; 145 u32 *im_DBGdimap;
146 atomic_t im_numinos; /* num of backed inodes */ 146 atomic_t im_numinos; /* num of backed inodes */
147 atomic_t im_numfree; /* num of free backed inodes */ 147 atomic_t im_numfree; /* num of free backed inodes */
diff --git a/fs/jfs/jfs_incore.h b/fs/jfs/jfs_incore.h
index dc21a5bd54d4..54d73716ca8c 100644
--- a/fs/jfs/jfs_incore.h
+++ b/fs/jfs/jfs_incore.h
@@ -19,6 +19,7 @@
19#ifndef _H_JFS_INCORE 19#ifndef _H_JFS_INCORE
20#define _H_JFS_INCORE 20#define _H_JFS_INCORE
21 21
22#include <linux/mutex.h>
22#include <linux/rwsem.h> 23#include <linux/rwsem.h>
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include <linux/bitops.h> 25#include <linux/bitops.h>
@@ -37,6 +38,8 @@
37struct jfs_inode_info { 38struct jfs_inode_info {
38 int fileset; /* fileset number (always 16)*/ 39 int fileset; /* fileset number (always 16)*/
39 uint mode2; /* jfs-specific mode */ 40 uint mode2; /* jfs-specific mode */
41 uint saved_uid; /* saved for uid mount option */
42 uint saved_gid; /* saved for gid mount option */
40 pxd_t ixpxd; /* inode extent descriptor */ 43 pxd_t ixpxd; /* inode extent descriptor */
41 dxd_t acl; /* dxd describing acl */ 44 dxd_t acl; /* dxd describing acl */
42 dxd_t ea; /* dxd describing ea */ 45 dxd_t ea; /* dxd describing ea */
@@ -62,12 +65,12 @@ struct jfs_inode_info {
62 */ 65 */
63 struct rw_semaphore rdwrlock; 66 struct rw_semaphore rdwrlock;
64 /* 67 /*
65 * commit_sem serializes transaction processing on an inode. 68 * commit_mutex serializes transaction processing on an inode.
66 * It must be taken after beginning a transaction (txBegin), since 69 * It must be taken after beginning a transaction (txBegin), since
67 * dirty inodes may be committed while a new transaction on the 70 * dirty inodes may be committed while a new transaction on the
68 * inode is blocked in txBegin or TxBeginAnon 71 * inode is blocked in txBegin or TxBeginAnon
69 */ 72 */
70 struct semaphore commit_sem; 73 struct mutex commit_mutex;
71 /* xattr_sem allows us to access the xattrs without taking i_mutex */ 74 /* xattr_sem allows us to access the xattrs without taking i_mutex */
72 struct rw_semaphore xattr_sem; 75 struct rw_semaphore xattr_sem;
73 lid_t xtlid; /* lid of xtree lock on directory */ 76 lid_t xtlid; /* lid of xtree lock on directory */
@@ -169,6 +172,9 @@ struct jfs_sb_info {
169 uint state; /* mount/recovery state */ 172 uint state; /* mount/recovery state */
170 unsigned long flag; /* mount time flags */ 173 unsigned long flag; /* mount time flags */
171 uint p_state; /* state prior to going no integrity */ 174 uint p_state; /* state prior to going no integrity */
175 uint uid; /* uid to override on-disk uid */
176 uint gid; /* gid to override on-disk gid */
177 uint umask; /* umask to override on-disk umask */
172}; 178};
173 179
174/* jfs_sb_info commit_state */ 180/* jfs_sb_info commit_state */
diff --git a/fs/jfs/jfs_inode.c b/fs/jfs/jfs_inode.c
index 2af5efbfd06f..495df402916d 100644
--- a/fs/jfs/jfs_inode.c
+++ b/fs/jfs/jfs_inode.c
@@ -25,6 +25,26 @@
25#include "jfs_dinode.h" 25#include "jfs_dinode.h"
26#include "jfs_debug.h" 26#include "jfs_debug.h"
27 27
28
29void jfs_set_inode_flags(struct inode *inode)
30{
31 unsigned int flags = JFS_IP(inode)->mode2;
32
33 inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
34 S_NOATIME | S_DIRSYNC | S_SYNC);
35
36 if (flags & JFS_IMMUTABLE_FL)
37 inode->i_flags |= S_IMMUTABLE;
38 if (flags & JFS_APPEND_FL)
39 inode->i_flags |= S_APPEND;
40 if (flags & JFS_NOATIME_FL)
41 inode->i_flags |= S_NOATIME;
42 if (flags & JFS_DIRSYNC_FL)
43 inode->i_flags |= S_DIRSYNC;
44 if (flags & JFS_SYNC_FL)
45 inode->i_flags |= S_SYNC;
46}
47
28/* 48/*
29 * NAME: ialloc() 49 * NAME: ialloc()
30 * 50 *
@@ -63,6 +83,13 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
63 inode->i_gid = current->fsgid; 83 inode->i_gid = current->fsgid;
64 84
65 /* 85 /*
86 * New inodes need to save sane values on disk when
87 * uid & gid mount options are used
88 */
89 jfs_inode->saved_uid = inode->i_uid;
90 jfs_inode->saved_gid = inode->i_gid;
91
92 /*
66 * Allocate inode to quota. 93 * Allocate inode to quota.
67 */ 94 */
68 if (DQUOT_ALLOC_INODE(inode)) { 95 if (DQUOT_ALLOC_INODE(inode)) {
@@ -74,10 +101,20 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
74 } 101 }
75 102
76 inode->i_mode = mode; 103 inode->i_mode = mode;
77 if (S_ISDIR(mode)) 104 /* inherit flags from parent */
78 jfs_inode->mode2 = IDIRECTORY | mode; 105 jfs_inode->mode2 = JFS_IP(parent)->mode2 & JFS_FL_INHERIT;
79 else 106
80 jfs_inode->mode2 = INLINEEA | ISPARSE | mode; 107 if (S_ISDIR(mode)) {
108 jfs_inode->mode2 |= IDIRECTORY;
109 jfs_inode->mode2 &= ~JFS_DIRSYNC_FL;
110 }
111 else {
112 jfs_inode->mode2 |= INLINEEA | ISPARSE;
113 if (S_ISLNK(mode))
114 jfs_inode->mode2 &= ~(JFS_IMMUTABLE_FL|JFS_APPEND_FL);
115 }
116 jfs_inode->mode2 |= mode;
117
81 inode->i_blksize = sb->s_blocksize; 118 inode->i_blksize = sb->s_blocksize;
82 inode->i_blocks = 0; 119 inode->i_blocks = 0;
83 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 120 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
@@ -98,6 +135,7 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
98 jfs_inode->atlhead = 0; 135 jfs_inode->atlhead = 0;
99 jfs_inode->atltail = 0; 136 jfs_inode->atltail = 0;
100 jfs_inode->xtlid = 0; 137 jfs_inode->xtlid = 0;
138 jfs_set_inode_flags(inode);
101 139
102 jfs_info("ialloc returns inode = 0x%p\n", inode); 140 jfs_info("ialloc returns inode = 0x%p\n", inode);
103 141
diff --git a/fs/jfs/jfs_inode.h b/fs/jfs/jfs_inode.h
index b54bac576cb3..095d471b9f9a 100644
--- a/fs/jfs/jfs_inode.h
+++ b/fs/jfs/jfs_inode.h
@@ -20,6 +20,8 @@
20 20
21extern struct inode *ialloc(struct inode *, umode_t); 21extern struct inode *ialloc(struct inode *, umode_t);
22extern int jfs_fsync(struct file *, struct dentry *, int); 22extern int jfs_fsync(struct file *, struct dentry *, int);
23extern int jfs_ioctl(struct inode *, struct file *,
24 unsigned int, unsigned long);
23extern void jfs_read_inode(struct inode *); 25extern void jfs_read_inode(struct inode *);
24extern int jfs_commit_inode(struct inode *, int); 26extern int jfs_commit_inode(struct inode *, int);
25extern int jfs_write_inode(struct inode*, int); 27extern int jfs_write_inode(struct inode*, int);
@@ -29,6 +31,7 @@ extern void jfs_truncate(struct inode *);
29extern void jfs_truncate_nolock(struct inode *, loff_t); 31extern void jfs_truncate_nolock(struct inode *, loff_t);
30extern void jfs_free_zero_link(struct inode *); 32extern void jfs_free_zero_link(struct inode *);
31extern struct dentry *jfs_get_parent(struct dentry *dentry); 33extern struct dentry *jfs_get_parent(struct dentry *dentry);
34extern void jfs_set_inode_flags(struct inode *);
32 35
33extern struct address_space_operations jfs_aops; 36extern struct address_space_operations jfs_aops;
34extern struct inode_operations jfs_dir_inode_operations; 37extern struct inode_operations jfs_dir_inode_operations;
diff --git a/fs/jfs/jfs_lock.h b/fs/jfs/jfs_lock.h
index 10ad1d086685..70ac9f7d1e00 100644
--- a/fs/jfs/jfs_lock.h
+++ b/fs/jfs/jfs_lock.h
@@ -20,6 +20,7 @@
20#define _H_JFS_LOCK 20#define _H_JFS_LOCK
21 21
22#include <linux/spinlock.h> 22#include <linux/spinlock.h>
23#include <linux/mutex.h>
23#include <linux/sched.h> 24#include <linux/sched.h>
24 25
25/* 26/*
diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index d27bac6acaa3..0b348b13b551 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -64,6 +64,7 @@
64#include <linux/interrupt.h> 64#include <linux/interrupt.h>
65#include <linux/smp_lock.h> 65#include <linux/smp_lock.h>
66#include <linux/completion.h> 66#include <linux/completion.h>
67#include <linux/kthread.h>
67#include <linux/buffer_head.h> /* for sync_blockdev() */ 68#include <linux/buffer_head.h> /* for sync_blockdev() */
68#include <linux/bio.h> 69#include <linux/bio.h>
69#include <linux/suspend.h> 70#include <linux/suspend.h>
@@ -81,15 +82,14 @@
81 */ 82 */
82static struct lbuf *log_redrive_list; 83static struct lbuf *log_redrive_list;
83static DEFINE_SPINLOCK(log_redrive_lock); 84static DEFINE_SPINLOCK(log_redrive_lock);
84DECLARE_WAIT_QUEUE_HEAD(jfs_IO_thread_wait);
85 85
86 86
87/* 87/*
88 * log read/write serialization (per log) 88 * log read/write serialization (per log)
89 */ 89 */
90#define LOG_LOCK_INIT(log) init_MUTEX(&(log)->loglock) 90#define LOG_LOCK_INIT(log) mutex_init(&(log)->loglock)
91#define LOG_LOCK(log) down(&((log)->loglock)) 91#define LOG_LOCK(log) mutex_lock(&((log)->loglock))
92#define LOG_UNLOCK(log) up(&((log)->loglock)) 92#define LOG_UNLOCK(log) mutex_unlock(&((log)->loglock))
93 93
94 94
95/* 95/*
@@ -1105,11 +1105,10 @@ int lmLogOpen(struct super_block *sb)
1105 } 1105 }
1106 } 1106 }
1107 1107
1108 if (!(log = kmalloc(sizeof(struct jfs_log), GFP_KERNEL))) { 1108 if (!(log = kzalloc(sizeof(struct jfs_log), GFP_KERNEL))) {
1109 up(&jfs_log_sem); 1109 up(&jfs_log_sem);
1110 return -ENOMEM; 1110 return -ENOMEM;
1111 } 1111 }
1112 memset(log, 0, sizeof(struct jfs_log));
1113 INIT_LIST_HEAD(&log->sb_list); 1112 INIT_LIST_HEAD(&log->sb_list);
1114 init_waitqueue_head(&log->syncwait); 1113 init_waitqueue_head(&log->syncwait);
1115 1114
@@ -1181,9 +1180,8 @@ static int open_inline_log(struct super_block *sb)
1181 struct jfs_log *log; 1180 struct jfs_log *log;
1182 int rc; 1181 int rc;
1183 1182
1184 if (!(log = kmalloc(sizeof(struct jfs_log), GFP_KERNEL))) 1183 if (!(log = kzalloc(sizeof(struct jfs_log), GFP_KERNEL)))
1185 return -ENOMEM; 1184 return -ENOMEM;
1186 memset(log, 0, sizeof(struct jfs_log));
1187 INIT_LIST_HEAD(&log->sb_list); 1185 INIT_LIST_HEAD(&log->sb_list);
1188 init_waitqueue_head(&log->syncwait); 1186 init_waitqueue_head(&log->syncwait);
1189 1187
@@ -1216,12 +1214,11 @@ static int open_dummy_log(struct super_block *sb)
1216 1214
1217 down(&jfs_log_sem); 1215 down(&jfs_log_sem);
1218 if (!dummy_log) { 1216 if (!dummy_log) {
1219 dummy_log = kmalloc(sizeof(struct jfs_log), GFP_KERNEL); 1217 dummy_log = kzalloc(sizeof(struct jfs_log), GFP_KERNEL);
1220 if (!dummy_log) { 1218 if (!dummy_log) {
1221 up(&jfs_log_sem); 1219 up(&jfs_log_sem);
1222 return -ENOMEM; 1220 return -ENOMEM;
1223 } 1221 }
1224 memset(dummy_log, 0, sizeof(struct jfs_log));
1225 INIT_LIST_HEAD(&dummy_log->sb_list); 1222 INIT_LIST_HEAD(&dummy_log->sb_list);
1226 init_waitqueue_head(&dummy_log->syncwait); 1223 init_waitqueue_head(&dummy_log->syncwait);
1227 dummy_log->no_integrity = 1; 1224 dummy_log->no_integrity = 1;
@@ -1980,7 +1977,7 @@ static inline void lbmRedrive(struct lbuf *bp)
1980 log_redrive_list = bp; 1977 log_redrive_list = bp;
1981 spin_unlock_irqrestore(&log_redrive_lock, flags); 1978 spin_unlock_irqrestore(&log_redrive_lock, flags);
1982 1979
1983 wake_up(&jfs_IO_thread_wait); 1980 wake_up_process(jfsIOthread);
1984} 1981}
1985 1982
1986 1983
@@ -2347,13 +2344,7 @@ int jfsIOWait(void *arg)
2347{ 2344{
2348 struct lbuf *bp; 2345 struct lbuf *bp;
2349 2346
2350 daemonize("jfsIO");
2351
2352 complete(&jfsIOwait);
2353
2354 do { 2347 do {
2355 DECLARE_WAITQUEUE(wq, current);
2356
2357 spin_lock_irq(&log_redrive_lock); 2348 spin_lock_irq(&log_redrive_lock);
2358 while ((bp = log_redrive_list) != 0) { 2349 while ((bp = log_redrive_list) != 0) {
2359 log_redrive_list = bp->l_redrive_next; 2350 log_redrive_list = bp->l_redrive_next;
@@ -2362,21 +2353,19 @@ int jfsIOWait(void *arg)
2362 lbmStartIO(bp); 2353 lbmStartIO(bp);
2363 spin_lock_irq(&log_redrive_lock); 2354 spin_lock_irq(&log_redrive_lock);
2364 } 2355 }
2356 spin_unlock_irq(&log_redrive_lock);
2357
2365 if (freezing(current)) { 2358 if (freezing(current)) {
2366 spin_unlock_irq(&log_redrive_lock);
2367 refrigerator(); 2359 refrigerator();
2368 } else { 2360 } else {
2369 add_wait_queue(&jfs_IO_thread_wait, &wq);
2370 set_current_state(TASK_INTERRUPTIBLE); 2361 set_current_state(TASK_INTERRUPTIBLE);
2371 spin_unlock_irq(&log_redrive_lock);
2372 schedule(); 2362 schedule();
2373 current->state = TASK_RUNNING; 2363 current->state = TASK_RUNNING;
2374 remove_wait_queue(&jfs_IO_thread_wait, &wq);
2375 } 2364 }
2376 } while (!jfs_stop_threads); 2365 } while (!kthread_should_stop());
2377 2366
2378 jfs_info("jfsIOWait being killed!"); 2367 jfs_info("jfsIOWait being killed!");
2379 complete_and_exit(&jfsIOwait, 0); 2368 return 0;
2380} 2369}
2381 2370
2382/* 2371/*
diff --git a/fs/jfs/jfs_logmgr.h b/fs/jfs/jfs_logmgr.h
index e4978b5b65ee..8c6909b80014 100644
--- a/fs/jfs/jfs_logmgr.h
+++ b/fs/jfs/jfs_logmgr.h
@@ -389,7 +389,7 @@ struct jfs_log {
389 int eor; /* 4: eor of last record in eol page */ 389 int eor; /* 4: eor of last record in eol page */
390 struct lbuf *bp; /* 4: current log page buffer */ 390 struct lbuf *bp; /* 4: current log page buffer */
391 391
392 struct semaphore loglock; /* 4: log write serialization lock */ 392 struct mutex loglock; /* 4: log write serialization lock */
393 393
394 /* syncpt */ 394 /* syncpt */
395 int nextsync; /* 4: bytes to write before next syncpt */ 395 int nextsync; /* 4: bytes to write before next syncpt */
diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 8a53981f9f27..5fbaeaadccd3 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -104,10 +104,9 @@ static inline int insert_metapage(struct page *page, struct metapage *mp)
104 if (PagePrivate(page)) 104 if (PagePrivate(page))
105 a = mp_anchor(page); 105 a = mp_anchor(page);
106 else { 106 else {
107 a = kmalloc(sizeof(struct meta_anchor), GFP_NOFS); 107 a = kzalloc(sizeof(struct meta_anchor), GFP_NOFS);
108 if (!a) 108 if (!a)
109 return -ENOMEM; 109 return -ENOMEM;
110 memset(a, 0, sizeof(struct meta_anchor));
111 set_page_private(page, (unsigned long)a); 110 set_page_private(page, (unsigned long)a);
112 SetPagePrivate(page); 111 SetPagePrivate(page);
113 kmap(page); 112 kmap(page);
diff --git a/fs/jfs/jfs_superblock.h b/fs/jfs/jfs_superblock.h
index fcf781bf31cb..682cf1a68a18 100644
--- a/fs/jfs/jfs_superblock.h
+++ b/fs/jfs/jfs_superblock.h
@@ -113,12 +113,9 @@ extern int jfs_mount(struct super_block *);
113extern int jfs_mount_rw(struct super_block *, int); 113extern int jfs_mount_rw(struct super_block *, int);
114extern int jfs_umount(struct super_block *); 114extern int jfs_umount(struct super_block *);
115extern int jfs_umount_rw(struct super_block *); 115extern int jfs_umount_rw(struct super_block *);
116
117extern int jfs_stop_threads;
118extern struct completion jfsIOwait;
119extern wait_queue_head_t jfs_IO_thread_wait;
120extern wait_queue_head_t jfs_commit_thread_wait;
121extern wait_queue_head_t jfs_sync_thread_wait;
122extern int jfs_extendfs(struct super_block *, s64, int); 116extern int jfs_extendfs(struct super_block *, s64, int);
123 117
118extern struct task_struct *jfsIOthread;
119extern struct task_struct *jfsSyncThread;
120
124#endif /*_H_JFS_SUPERBLOCK */ 121#endif /*_H_JFS_SUPERBLOCK */
diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c
index 2ddb6b892bcf..ac3d66948e8c 100644
--- a/fs/jfs/jfs_txnmgr.c
+++ b/fs/jfs/jfs_txnmgr.c
@@ -49,6 +49,7 @@
49#include <linux/suspend.h> 49#include <linux/suspend.h>
50#include <linux/module.h> 50#include <linux/module.h>
51#include <linux/moduleparam.h> 51#include <linux/moduleparam.h>
52#include <linux/kthread.h>
52#include "jfs_incore.h" 53#include "jfs_incore.h"
53#include "jfs_inode.h" 54#include "jfs_inode.h"
54#include "jfs_filsys.h" 55#include "jfs_filsys.h"
@@ -121,8 +122,7 @@ static DEFINE_SPINLOCK(jfsTxnLock);
121#define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags) 122#define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags)
122#define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags) 123#define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags)
123 124
124DECLARE_WAIT_QUEUE_HEAD(jfs_sync_thread_wait); 125static DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
125DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
126static int jfs_commit_thread_waking; 126static int jfs_commit_thread_waking;
127 127
128/* 128/*
@@ -207,7 +207,7 @@ static lid_t txLockAlloc(void)
207 if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) { 207 if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) {
208 jfs_info("txLockAlloc tlocks low"); 208 jfs_info("txLockAlloc tlocks low");
209 jfs_tlocks_low = 1; 209 jfs_tlocks_low = 1;
210 wake_up(&jfs_sync_thread_wait); 210 wake_up_process(jfsSyncThread);
211 } 211 }
212 212
213 return lid; 213 return lid;
@@ -2743,10 +2743,6 @@ int jfs_lazycommit(void *arg)
2743 unsigned long flags; 2743 unsigned long flags;
2744 struct jfs_sb_info *sbi; 2744 struct jfs_sb_info *sbi;
2745 2745
2746 daemonize("jfsCommit");
2747
2748 complete(&jfsIOwait);
2749
2750 do { 2746 do {
2751 LAZY_LOCK(flags); 2747 LAZY_LOCK(flags);
2752 jfs_commit_thread_waking = 0; /* OK to wake another thread */ 2748 jfs_commit_thread_waking = 0; /* OK to wake another thread */
@@ -2806,13 +2802,13 @@ int jfs_lazycommit(void *arg)
2806 current->state = TASK_RUNNING; 2802 current->state = TASK_RUNNING;
2807 remove_wait_queue(&jfs_commit_thread_wait, &wq); 2803 remove_wait_queue(&jfs_commit_thread_wait, &wq);
2808 } 2804 }
2809 } while (!jfs_stop_threads); 2805 } while (!kthread_should_stop());
2810 2806
2811 if (!list_empty(&TxAnchor.unlock_queue)) 2807 if (!list_empty(&TxAnchor.unlock_queue))
2812 jfs_err("jfs_lazycommit being killed w/pending transactions!"); 2808 jfs_err("jfs_lazycommit being killed w/pending transactions!");
2813 else 2809 else
2814 jfs_info("jfs_lazycommit being killed\n"); 2810 jfs_info("jfs_lazycommit being killed\n");
2815 complete_and_exit(&jfsIOwait, 0); 2811 return 0;
2816} 2812}
2817 2813
2818void txLazyUnlock(struct tblock * tblk) 2814void txLazyUnlock(struct tblock * tblk)
@@ -2876,10 +2872,10 @@ restart:
2876 */ 2872 */
2877 TXN_UNLOCK(); 2873 TXN_UNLOCK();
2878 tid = txBegin(ip->i_sb, COMMIT_INODE | COMMIT_FORCE); 2874 tid = txBegin(ip->i_sb, COMMIT_INODE | COMMIT_FORCE);
2879 down(&jfs_ip->commit_sem); 2875 mutex_lock(&jfs_ip->commit_mutex);
2880 txCommit(tid, 1, &ip, 0); 2876 txCommit(tid, 1, &ip, 0);
2881 txEnd(tid); 2877 txEnd(tid);
2882 up(&jfs_ip->commit_sem); 2878 mutex_unlock(&jfs_ip->commit_mutex);
2883 /* 2879 /*
2884 * Just to be safe. I don't know how 2880 * Just to be safe. I don't know how
2885 * long we can run without blocking 2881 * long we can run without blocking
@@ -2932,10 +2928,6 @@ int jfs_sync(void *arg)
2932 int rc; 2928 int rc;
2933 tid_t tid; 2929 tid_t tid;
2934 2930
2935 daemonize("jfsSync");
2936
2937 complete(&jfsIOwait);
2938
2939 do { 2931 do {
2940 /* 2932 /*
2941 * write each inode on the anonymous inode list 2933 * write each inode on the anonymous inode list
@@ -2952,7 +2944,7 @@ int jfs_sync(void *arg)
2952 * Inode is being freed 2944 * Inode is being freed
2953 */ 2945 */
2954 list_del_init(&jfs_ip->anon_inode_list); 2946 list_del_init(&jfs_ip->anon_inode_list);
2955 } else if (! down_trylock(&jfs_ip->commit_sem)) { 2947 } else if (! !mutex_trylock(&jfs_ip->commit_mutex)) {
2956 /* 2948 /*
2957 * inode will be removed from anonymous list 2949 * inode will be removed from anonymous list
2958 * when it is committed 2950 * when it is committed
@@ -2961,7 +2953,7 @@ int jfs_sync(void *arg)
2961 tid = txBegin(ip->i_sb, COMMIT_INODE); 2953 tid = txBegin(ip->i_sb, COMMIT_INODE);
2962 rc = txCommit(tid, 1, &ip, 0); 2954 rc = txCommit(tid, 1, &ip, 0);
2963 txEnd(tid); 2955 txEnd(tid);
2964 up(&jfs_ip->commit_sem); 2956 mutex_unlock(&jfs_ip->commit_mutex);
2965 2957
2966 iput(ip); 2958 iput(ip);
2967 /* 2959 /*
@@ -2971,7 +2963,7 @@ int jfs_sync(void *arg)
2971 cond_resched(); 2963 cond_resched();
2972 TXN_LOCK(); 2964 TXN_LOCK();
2973 } else { 2965 } else {
2974 /* We can't get the commit semaphore. It may 2966 /* We can't get the commit mutex. It may
2975 * be held by a thread waiting for tlock's 2967 * be held by a thread waiting for tlock's
2976 * so let's not block here. Save it to 2968 * so let's not block here. Save it to
2977 * put back on the anon_list. 2969 * put back on the anon_list.
@@ -2996,19 +2988,15 @@ int jfs_sync(void *arg)
2996 TXN_UNLOCK(); 2988 TXN_UNLOCK();
2997 refrigerator(); 2989 refrigerator();
2998 } else { 2990 } else {
2999 DECLARE_WAITQUEUE(wq, current);
3000
3001 add_wait_queue(&jfs_sync_thread_wait, &wq);
3002 set_current_state(TASK_INTERRUPTIBLE); 2991 set_current_state(TASK_INTERRUPTIBLE);
3003 TXN_UNLOCK(); 2992 TXN_UNLOCK();
3004 schedule(); 2993 schedule();
3005 current->state = TASK_RUNNING; 2994 current->state = TASK_RUNNING;
3006 remove_wait_queue(&jfs_sync_thread_wait, &wq);
3007 } 2995 }
3008 } while (!jfs_stop_threads); 2996 } while (!kthread_should_stop());
3009 2997
3010 jfs_info("jfs_sync being killed"); 2998 jfs_info("jfs_sync being killed");
3011 complete_and_exit(&jfsIOwait, 0); 2999 return 0;
3012} 3000}
3013 3001
3014#if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG) 3002#if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG)
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index 4abbe8604302..309cee575f7d 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -104,8 +104,8 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
104 104
105 tid = txBegin(dip->i_sb, 0); 105 tid = txBegin(dip->i_sb, 0);
106 106
107 down(&JFS_IP(dip)->commit_sem); 107 mutex_lock(&JFS_IP(dip)->commit_mutex);
108 down(&JFS_IP(ip)->commit_sem); 108 mutex_lock(&JFS_IP(ip)->commit_mutex);
109 109
110 rc = jfs_init_acl(tid, ip, dip); 110 rc = jfs_init_acl(tid, ip, dip);
111 if (rc) 111 if (rc)
@@ -165,8 +165,8 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
165 165
166 out3: 166 out3:
167 txEnd(tid); 167 txEnd(tid);
168 up(&JFS_IP(dip)->commit_sem); 168 mutex_unlock(&JFS_IP(dip)->commit_mutex);
169 up(&JFS_IP(ip)->commit_sem); 169 mutex_unlock(&JFS_IP(ip)->commit_mutex);
170 if (rc) { 170 if (rc) {
171 free_ea_wmap(ip); 171 free_ea_wmap(ip);
172 ip->i_nlink = 0; 172 ip->i_nlink = 0;
@@ -238,8 +238,8 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
238 238
239 tid = txBegin(dip->i_sb, 0); 239 tid = txBegin(dip->i_sb, 0);
240 240
241 down(&JFS_IP(dip)->commit_sem); 241 mutex_lock(&JFS_IP(dip)->commit_mutex);
242 down(&JFS_IP(ip)->commit_sem); 242 mutex_lock(&JFS_IP(ip)->commit_mutex);
243 243
244 rc = jfs_init_acl(tid, ip, dip); 244 rc = jfs_init_acl(tid, ip, dip);
245 if (rc) 245 if (rc)
@@ -300,8 +300,8 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
300 300
301 out3: 301 out3:
302 txEnd(tid); 302 txEnd(tid);
303 up(&JFS_IP(dip)->commit_sem); 303 mutex_unlock(&JFS_IP(dip)->commit_mutex);
304 up(&JFS_IP(ip)->commit_sem); 304 mutex_unlock(&JFS_IP(ip)->commit_mutex);
305 if (rc) { 305 if (rc) {
306 free_ea_wmap(ip); 306 free_ea_wmap(ip);
307 ip->i_nlink = 0; 307 ip->i_nlink = 0;
@@ -365,8 +365,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
365 365
366 tid = txBegin(dip->i_sb, 0); 366 tid = txBegin(dip->i_sb, 0);
367 367
368 down(&JFS_IP(dip)->commit_sem); 368 mutex_lock(&JFS_IP(dip)->commit_mutex);
369 down(&JFS_IP(ip)->commit_sem); 369 mutex_lock(&JFS_IP(ip)->commit_mutex);
370 370
371 iplist[0] = dip; 371 iplist[0] = dip;
372 iplist[1] = ip; 372 iplist[1] = ip;
@@ -384,8 +384,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
384 if (rc == -EIO) 384 if (rc == -EIO)
385 txAbort(tid, 1); 385 txAbort(tid, 1);
386 txEnd(tid); 386 txEnd(tid);
387 up(&JFS_IP(dip)->commit_sem); 387 mutex_unlock(&JFS_IP(dip)->commit_mutex);
388 up(&JFS_IP(ip)->commit_sem); 388 mutex_unlock(&JFS_IP(ip)->commit_mutex);
389 389
390 goto out2; 390 goto out2;
391 } 391 }
@@ -422,8 +422,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
422 422
423 txEnd(tid); 423 txEnd(tid);
424 424
425 up(&JFS_IP(dip)->commit_sem); 425 mutex_unlock(&JFS_IP(dip)->commit_mutex);
426 up(&JFS_IP(ip)->commit_sem); 426 mutex_unlock(&JFS_IP(ip)->commit_mutex);
427 427
428 /* 428 /*
429 * Truncating the directory index table is not guaranteed. It 429 * Truncating the directory index table is not guaranteed. It
@@ -488,8 +488,8 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
488 488
489 tid = txBegin(dip->i_sb, 0); 489 tid = txBegin(dip->i_sb, 0);
490 490
491 down(&JFS_IP(dip)->commit_sem); 491 mutex_lock(&JFS_IP(dip)->commit_mutex);
492 down(&JFS_IP(ip)->commit_sem); 492 mutex_lock(&JFS_IP(ip)->commit_mutex);
493 493
494 iplist[0] = dip; 494 iplist[0] = dip;
495 iplist[1] = ip; 495 iplist[1] = ip;
@@ -503,8 +503,8 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
503 if (rc == -EIO) 503 if (rc == -EIO)
504 txAbort(tid, 1); /* Marks FS Dirty */ 504 txAbort(tid, 1); /* Marks FS Dirty */
505 txEnd(tid); 505 txEnd(tid);
506 up(&JFS_IP(dip)->commit_sem); 506 mutex_unlock(&JFS_IP(dip)->commit_mutex);
507 up(&JFS_IP(ip)->commit_sem); 507 mutex_unlock(&JFS_IP(ip)->commit_mutex);
508 IWRITE_UNLOCK(ip); 508 IWRITE_UNLOCK(ip);
509 goto out1; 509 goto out1;
510 } 510 }
@@ -527,8 +527,8 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
527 if ((new_size = commitZeroLink(tid, ip)) < 0) { 527 if ((new_size = commitZeroLink(tid, ip)) < 0) {
528 txAbort(tid, 1); /* Marks FS Dirty */ 528 txAbort(tid, 1); /* Marks FS Dirty */
529 txEnd(tid); 529 txEnd(tid);
530 up(&JFS_IP(dip)->commit_sem); 530 mutex_unlock(&JFS_IP(dip)->commit_mutex);
531 up(&JFS_IP(ip)->commit_sem); 531 mutex_unlock(&JFS_IP(ip)->commit_mutex);
532 IWRITE_UNLOCK(ip); 532 IWRITE_UNLOCK(ip);
533 rc = new_size; 533 rc = new_size;
534 goto out1; 534 goto out1;
@@ -556,13 +556,13 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
556 556
557 txEnd(tid); 557 txEnd(tid);
558 558
559 up(&JFS_IP(dip)->commit_sem); 559 mutex_unlock(&JFS_IP(dip)->commit_mutex);
560 up(&JFS_IP(ip)->commit_sem); 560 mutex_unlock(&JFS_IP(ip)->commit_mutex);
561 561
562 562
563 while (new_size && (rc == 0)) { 563 while (new_size && (rc == 0)) {
564 tid = txBegin(dip->i_sb, 0); 564 tid = txBegin(dip->i_sb, 0);
565 down(&JFS_IP(ip)->commit_sem); 565 mutex_lock(&JFS_IP(ip)->commit_mutex);
566 new_size = xtTruncate_pmap(tid, ip, new_size); 566 new_size = xtTruncate_pmap(tid, ip, new_size);
567 if (new_size < 0) { 567 if (new_size < 0) {
568 txAbort(tid, 1); /* Marks FS Dirty */ 568 txAbort(tid, 1); /* Marks FS Dirty */
@@ -570,7 +570,7 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
570 } else 570 } else
571 rc = txCommit(tid, 2, &iplist[0], COMMIT_SYNC); 571 rc = txCommit(tid, 2, &iplist[0], COMMIT_SYNC);
572 txEnd(tid); 572 txEnd(tid);
573 up(&JFS_IP(ip)->commit_sem); 573 mutex_unlock(&JFS_IP(ip)->commit_mutex);
574 } 574 }
575 575
576 if (ip->i_nlink == 0) 576 if (ip->i_nlink == 0)
@@ -805,8 +805,8 @@ static int jfs_link(struct dentry *old_dentry,
805 805
806 tid = txBegin(ip->i_sb, 0); 806 tid = txBegin(ip->i_sb, 0);
807 807
808 down(&JFS_IP(dir)->commit_sem); 808 mutex_lock(&JFS_IP(dir)->commit_mutex);
809 down(&JFS_IP(ip)->commit_sem); 809 mutex_lock(&JFS_IP(ip)->commit_mutex);
810 810
811 /* 811 /*
812 * scan parent directory for entry/freespace 812 * scan parent directory for entry/freespace
@@ -847,8 +847,8 @@ static int jfs_link(struct dentry *old_dentry,
847 out: 847 out:
848 txEnd(tid); 848 txEnd(tid);
849 849
850 up(&JFS_IP(dir)->commit_sem); 850 mutex_unlock(&JFS_IP(dir)->commit_mutex);
851 up(&JFS_IP(ip)->commit_sem); 851 mutex_unlock(&JFS_IP(ip)->commit_mutex);
852 852
853 jfs_info("jfs_link: rc:%d", rc); 853 jfs_info("jfs_link: rc:%d", rc);
854 return rc; 854 return rc;
@@ -916,8 +916,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
916 916
917 tid = txBegin(dip->i_sb, 0); 917 tid = txBegin(dip->i_sb, 0);
918 918
919 down(&JFS_IP(dip)->commit_sem); 919 mutex_lock(&JFS_IP(dip)->commit_mutex);
920 down(&JFS_IP(ip)->commit_sem); 920 mutex_lock(&JFS_IP(ip)->commit_mutex);
921 921
922 rc = jfs_init_security(tid, ip, dip); 922 rc = jfs_init_security(tid, ip, dip);
923 if (rc) 923 if (rc)
@@ -1037,8 +1037,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
1037 1037
1038 out3: 1038 out3:
1039 txEnd(tid); 1039 txEnd(tid);
1040 up(&JFS_IP(dip)->commit_sem); 1040 mutex_unlock(&JFS_IP(dip)->commit_mutex);
1041 up(&JFS_IP(ip)->commit_sem); 1041 mutex_unlock(&JFS_IP(ip)->commit_mutex);
1042 if (rc) { 1042 if (rc) {
1043 free_ea_wmap(ip); 1043 free_ea_wmap(ip);
1044 ip->i_nlink = 0; 1044 ip->i_nlink = 0;
@@ -1141,13 +1141,13 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1141 */ 1141 */
1142 tid = txBegin(new_dir->i_sb, 0); 1142 tid = txBegin(new_dir->i_sb, 0);
1143 1143
1144 down(&JFS_IP(new_dir)->commit_sem); 1144 mutex_lock(&JFS_IP(new_dir)->commit_mutex);
1145 down(&JFS_IP(old_ip)->commit_sem); 1145 mutex_lock(&JFS_IP(old_ip)->commit_mutex);
1146 if (old_dir != new_dir) 1146 if (old_dir != new_dir)
1147 down(&JFS_IP(old_dir)->commit_sem); 1147 mutex_lock(&JFS_IP(old_dir)->commit_mutex);
1148 1148
1149 if (new_ip) { 1149 if (new_ip) {
1150 down(&JFS_IP(new_ip)->commit_sem); 1150 mutex_lock(&JFS_IP(new_ip)->commit_mutex);
1151 /* 1151 /*
1152 * Change existing directory entry to new inode number 1152 * Change existing directory entry to new inode number
1153 */ 1153 */
@@ -1160,10 +1160,10 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1160 if (S_ISDIR(new_ip->i_mode)) { 1160 if (S_ISDIR(new_ip->i_mode)) {
1161 new_ip->i_nlink--; 1161 new_ip->i_nlink--;
1162 if (new_ip->i_nlink) { 1162 if (new_ip->i_nlink) {
1163 up(&JFS_IP(new_dir)->commit_sem); 1163 mutex_unlock(&JFS_IP(new_dir)->commit_mutex);
1164 up(&JFS_IP(old_ip)->commit_sem); 1164 mutex_unlock(&JFS_IP(old_ip)->commit_mutex);
1165 if (old_dir != new_dir) 1165 if (old_dir != new_dir)
1166 up(&JFS_IP(old_dir)->commit_sem); 1166 mutex_unlock(&JFS_IP(old_dir)->commit_mutex);
1167 if (!S_ISDIR(old_ip->i_mode) && new_ip) 1167 if (!S_ISDIR(old_ip->i_mode) && new_ip)
1168 IWRITE_UNLOCK(new_ip); 1168 IWRITE_UNLOCK(new_ip);
1169 jfs_error(new_ip->i_sb, 1169 jfs_error(new_ip->i_sb,
@@ -1282,16 +1282,16 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1282 out4: 1282 out4:
1283 txEnd(tid); 1283 txEnd(tid);
1284 1284
1285 up(&JFS_IP(new_dir)->commit_sem); 1285 mutex_unlock(&JFS_IP(new_dir)->commit_mutex);
1286 up(&JFS_IP(old_ip)->commit_sem); 1286 mutex_unlock(&JFS_IP(old_ip)->commit_mutex);
1287 if (old_dir != new_dir) 1287 if (old_dir != new_dir)
1288 up(&JFS_IP(old_dir)->commit_sem); 1288 mutex_unlock(&JFS_IP(old_dir)->commit_mutex);
1289 if (new_ip) 1289 if (new_ip)
1290 up(&JFS_IP(new_ip)->commit_sem); 1290 mutex_unlock(&JFS_IP(new_ip)->commit_mutex);
1291 1291
1292 while (new_size && (rc == 0)) { 1292 while (new_size && (rc == 0)) {
1293 tid = txBegin(new_ip->i_sb, 0); 1293 tid = txBegin(new_ip->i_sb, 0);
1294 down(&JFS_IP(new_ip)->commit_sem); 1294 mutex_lock(&JFS_IP(new_ip)->commit_mutex);
1295 new_size = xtTruncate_pmap(tid, new_ip, new_size); 1295 new_size = xtTruncate_pmap(tid, new_ip, new_size);
1296 if (new_size < 0) { 1296 if (new_size < 0) {
1297 txAbort(tid, 1); 1297 txAbort(tid, 1);
@@ -1299,7 +1299,7 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1299 } else 1299 } else
1300 rc = txCommit(tid, 1, &new_ip, COMMIT_SYNC); 1300 rc = txCommit(tid, 1, &new_ip, COMMIT_SYNC);
1301 txEnd(tid); 1301 txEnd(tid);
1302 up(&JFS_IP(new_ip)->commit_sem); 1302 mutex_unlock(&JFS_IP(new_ip)->commit_mutex);
1303 } 1303 }
1304 if (new_ip && (new_ip->i_nlink == 0)) 1304 if (new_ip && (new_ip->i_nlink == 0))
1305 set_cflag(COMMIT_Nolink, new_ip); 1305 set_cflag(COMMIT_Nolink, new_ip);
@@ -1361,8 +1361,8 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
1361 1361
1362 tid = txBegin(dir->i_sb, 0); 1362 tid = txBegin(dir->i_sb, 0);
1363 1363
1364 down(&JFS_IP(dir)->commit_sem); 1364 mutex_lock(&JFS_IP(dir)->commit_mutex);
1365 down(&JFS_IP(ip)->commit_sem); 1365 mutex_lock(&JFS_IP(ip)->commit_mutex);
1366 1366
1367 rc = jfs_init_acl(tid, ip, dir); 1367 rc = jfs_init_acl(tid, ip, dir);
1368 if (rc) 1368 if (rc)
@@ -1407,8 +1407,8 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
1407 1407
1408 out3: 1408 out3:
1409 txEnd(tid); 1409 txEnd(tid);
1410 up(&JFS_IP(ip)->commit_sem); 1410 mutex_unlock(&JFS_IP(ip)->commit_mutex);
1411 up(&JFS_IP(dir)->commit_sem); 1411 mutex_unlock(&JFS_IP(dir)->commit_mutex);
1412 if (rc) { 1412 if (rc) {
1413 free_ea_wmap(ip); 1413 free_ea_wmap(ip);
1414 ip->i_nlink = 0; 1414 ip->i_nlink = 0;
@@ -1523,6 +1523,7 @@ struct file_operations jfs_dir_operations = {
1523 .read = generic_read_dir, 1523 .read = generic_read_dir,
1524 .readdir = jfs_readdir, 1524 .readdir = jfs_readdir,
1525 .fsync = jfs_fsync, 1525 .fsync = jfs_fsync,
1526 .ioctl = jfs_ioctl,
1526}; 1527};
1527 1528
1528static int jfs_ci_hash(struct dentry *dir, struct qstr *this) 1529static int jfs_ci_hash(struct dentry *dir, struct qstr *this)
diff --git a/fs/jfs/super.c b/fs/jfs/super.c
index 8d31f1336431..18f69e6aa719 100644
--- a/fs/jfs/super.c
+++ b/fs/jfs/super.c
@@ -25,6 +25,7 @@
25#include <linux/vfs.h> 25#include <linux/vfs.h>
26#include <linux/mount.h> 26#include <linux/mount.h>
27#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
28#include <linux/kthread.h>
28#include <linux/posix_acl.h> 29#include <linux/posix_acl.h>
29#include <asm/uaccess.h> 30#include <asm/uaccess.h>
30#include <linux/seq_file.h> 31#include <linux/seq_file.h>
@@ -54,11 +55,9 @@ static int commit_threads = 0;
54module_param(commit_threads, int, 0); 55module_param(commit_threads, int, 0);
55MODULE_PARM_DESC(commit_threads, "Number of commit threads"); 56MODULE_PARM_DESC(commit_threads, "Number of commit threads");
56 57
57int jfs_stop_threads; 58static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS];
58static pid_t jfsIOthread; 59struct task_struct *jfsIOthread;
59static pid_t jfsCommitThread[MAX_COMMIT_THREADS]; 60struct task_struct *jfsSyncThread;
60static pid_t jfsSyncThread;
61DECLARE_COMPLETION(jfsIOwait);
62 61
63#ifdef CONFIG_JFS_DEBUG 62#ifdef CONFIG_JFS_DEBUG
64int jfsloglevel = JFS_LOGLEVEL_WARN; 63int jfsloglevel = JFS_LOGLEVEL_WARN;
@@ -195,7 +194,7 @@ static void jfs_put_super(struct super_block *sb)
195enum { 194enum {
196 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize, 195 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
197 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota, 196 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
198 Opt_usrquota, Opt_grpquota 197 Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
199}; 198};
200 199
201static match_table_t tokens = { 200static match_table_t tokens = {
@@ -209,6 +208,9 @@ static match_table_t tokens = {
209 {Opt_ignore, "quota"}, 208 {Opt_ignore, "quota"},
210 {Opt_usrquota, "usrquota"}, 209 {Opt_usrquota, "usrquota"},
211 {Opt_grpquota, "grpquota"}, 210 {Opt_grpquota, "grpquota"},
211 {Opt_uid, "uid=%u"},
212 {Opt_gid, "gid=%u"},
213 {Opt_umask, "umask=%u"},
212 {Opt_err, NULL} 214 {Opt_err, NULL}
213}; 215};
214 216
@@ -313,7 +315,29 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
313 "JFS: quota operations not supported\n"); 315 "JFS: quota operations not supported\n");
314 break; 316 break;
315#endif 317#endif
316 318 case Opt_uid:
319 {
320 char *uid = args[0].from;
321 sbi->uid = simple_strtoul(uid, &uid, 0);
322 break;
323 }
324 case Opt_gid:
325 {
326 char *gid = args[0].from;
327 sbi->gid = simple_strtoul(gid, &gid, 0);
328 break;
329 }
330 case Opt_umask:
331 {
332 char *umask = args[0].from;
333 sbi->umask = simple_strtoul(umask, &umask, 8);
334 if (sbi->umask & ~0777) {
335 printk(KERN_ERR
336 "JFS: Invalid value of umask\n");
337 goto cleanup;
338 }
339 break;
340 }
317 default: 341 default:
318 printk("jfs: Unrecognized mount option \"%s\" " 342 printk("jfs: Unrecognized mount option \"%s\" "
319 " or missing value\n", p); 343 " or missing value\n", p);
@@ -396,12 +420,12 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
396 if (!new_valid_dev(sb->s_bdev->bd_dev)) 420 if (!new_valid_dev(sb->s_bdev->bd_dev))
397 return -EOVERFLOW; 421 return -EOVERFLOW;
398 422
399 sbi = kmalloc(sizeof (struct jfs_sb_info), GFP_KERNEL); 423 sbi = kzalloc(sizeof (struct jfs_sb_info), GFP_KERNEL);
400 if (!sbi) 424 if (!sbi)
401 return -ENOSPC; 425 return -ENOSPC;
402 memset(sbi, 0, sizeof (struct jfs_sb_info));
403 sb->s_fs_info = sbi; 426 sb->s_fs_info = sbi;
404 sbi->sb = sb; 427 sbi->sb = sb;
428 sbi->uid = sbi->gid = sbi->umask = -1;
405 429
406 /* initialize the mount flag and determine the default error handler */ 430 /* initialize the mount flag and determine the default error handler */
407 flag = JFS_ERR_REMOUNT_RO; 431 flag = JFS_ERR_REMOUNT_RO;
@@ -564,10 +588,14 @@ static int jfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
564{ 588{
565 struct jfs_sb_info *sbi = JFS_SBI(vfs->mnt_sb); 589 struct jfs_sb_info *sbi = JFS_SBI(vfs->mnt_sb);
566 590
591 if (sbi->uid != -1)
592 seq_printf(seq, ",uid=%d", sbi->uid);
593 if (sbi->gid != -1)
594 seq_printf(seq, ",gid=%d", sbi->gid);
595 if (sbi->umask != -1)
596 seq_printf(seq, ",umask=%03o", sbi->umask);
567 if (sbi->flag & JFS_NOINTEGRITY) 597 if (sbi->flag & JFS_NOINTEGRITY)
568 seq_puts(seq, ",nointegrity"); 598 seq_puts(seq, ",nointegrity");
569 else
570 seq_puts(seq, ",integrity");
571 599
572#if defined(CONFIG_QUOTA) 600#if defined(CONFIG_QUOTA)
573 if (sbi->flag & JFS_USRQUOTA) 601 if (sbi->flag & JFS_USRQUOTA)
@@ -617,7 +645,7 @@ static void init_once(void *foo, kmem_cache_t * cachep, unsigned long flags)
617 memset(jfs_ip, 0, sizeof(struct jfs_inode_info)); 645 memset(jfs_ip, 0, sizeof(struct jfs_inode_info));
618 INIT_LIST_HEAD(&jfs_ip->anon_inode_list); 646 INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
619 init_rwsem(&jfs_ip->rdwrlock); 647 init_rwsem(&jfs_ip->rdwrlock);
620 init_MUTEX(&jfs_ip->commit_sem); 648 mutex_init(&jfs_ip->commit_mutex);
621 init_rwsem(&jfs_ip->xattr_sem); 649 init_rwsem(&jfs_ip->xattr_sem);
622 spin_lock_init(&jfs_ip->ag_lock); 650 spin_lock_init(&jfs_ip->ag_lock);
623 jfs_ip->active_ag = -1; 651 jfs_ip->active_ag = -1;
@@ -661,12 +689,12 @@ static int __init init_jfs_fs(void)
661 /* 689 /*
662 * I/O completion thread (endio) 690 * I/O completion thread (endio)
663 */ 691 */
664 jfsIOthread = kernel_thread(jfsIOWait, NULL, CLONE_KERNEL); 692 jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO");
665 if (jfsIOthread < 0) { 693 if (IS_ERR(jfsIOthread)) {
666 jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsIOthread); 694 rc = PTR_ERR(jfsIOthread);
695 jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
667 goto end_txmngr; 696 goto end_txmngr;
668 } 697 }
669 wait_for_completion(&jfsIOwait); /* Wait until thread starts */
670 698
671 if (commit_threads < 1) 699 if (commit_threads < 1)
672 commit_threads = num_online_cpus(); 700 commit_threads = num_online_cpus();
@@ -674,24 +702,21 @@ static int __init init_jfs_fs(void)
674 commit_threads = MAX_COMMIT_THREADS; 702 commit_threads = MAX_COMMIT_THREADS;
675 703
676 for (i = 0; i < commit_threads; i++) { 704 for (i = 0; i < commit_threads; i++) {
677 jfsCommitThread[i] = kernel_thread(jfs_lazycommit, NULL, 705 jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL, "jfsCommit");
678 CLONE_KERNEL); 706 if (IS_ERR(jfsCommitThread[i])) {
679 if (jfsCommitThread[i] < 0) { 707 rc = PTR_ERR(jfsCommitThread[i]);
680 jfs_err("init_jfs_fs: fork failed w/rc = %d", 708 jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
681 jfsCommitThread[i]);
682 commit_threads = i; 709 commit_threads = i;
683 goto kill_committask; 710 goto kill_committask;
684 } 711 }
685 /* Wait until thread starts */
686 wait_for_completion(&jfsIOwait);
687 } 712 }
688 713
689 jfsSyncThread = kernel_thread(jfs_sync, NULL, CLONE_KERNEL); 714 jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync");
690 if (jfsSyncThread < 0) { 715 if (IS_ERR(jfsSyncThread)) {
691 jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsSyncThread); 716 rc = PTR_ERR(jfsSyncThread);
717 jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
692 goto kill_committask; 718 goto kill_committask;
693 } 719 }
694 wait_for_completion(&jfsIOwait); /* Wait until thread starts */
695 720
696#ifdef PROC_FS_JFS 721#ifdef PROC_FS_JFS
697 jfs_proc_init(); 722 jfs_proc_init();
@@ -700,13 +725,9 @@ static int __init init_jfs_fs(void)
700 return register_filesystem(&jfs_fs_type); 725 return register_filesystem(&jfs_fs_type);
701 726
702kill_committask: 727kill_committask:
703 jfs_stop_threads = 1;
704 wake_up_all(&jfs_commit_thread_wait);
705 for (i = 0; i < commit_threads; i++) 728 for (i = 0; i < commit_threads; i++)
706 wait_for_completion(&jfsIOwait); 729 kthread_stop(jfsCommitThread[i]);
707 730 kthread_stop(jfsIOthread);
708 wake_up(&jfs_IO_thread_wait);
709 wait_for_completion(&jfsIOwait); /* Wait for thread exit */
710end_txmngr: 731end_txmngr:
711 txExit(); 732 txExit();
712free_metapage: 733free_metapage:
@@ -722,16 +743,13 @@ static void __exit exit_jfs_fs(void)
722 743
723 jfs_info("exit_jfs_fs called"); 744 jfs_info("exit_jfs_fs called");
724 745
725 jfs_stop_threads = 1;
726 txExit(); 746 txExit();
727 metapage_exit(); 747 metapage_exit();
728 wake_up(&jfs_IO_thread_wait); 748
729 wait_for_completion(&jfsIOwait); /* Wait until IO thread exits */ 749 kthread_stop(jfsIOthread);
730 wake_up_all(&jfs_commit_thread_wait);
731 for (i = 0; i < commit_threads; i++) 750 for (i = 0; i < commit_threads; i++)
732 wait_for_completion(&jfsIOwait); 751 kthread_stop(jfsCommitThread[i]);
733 wake_up(&jfs_sync_thread_wait); 752 kthread_stop(jfsSyncThread);
734 wait_for_completion(&jfsIOwait); /* Wait until Sync thread exits */
735#ifdef PROC_FS_JFS 753#ifdef PROC_FS_JFS
736 jfs_proc_clean(); 754 jfs_proc_clean();
737#endif 755#endif
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index f23048f9471f..9bc5b7c055ce 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -934,13 +934,13 @@ int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
934 } 934 }
935 935
936 tid = txBegin(inode->i_sb, 0); 936 tid = txBegin(inode->i_sb, 0);
937 down(&ji->commit_sem); 937 mutex_lock(&ji->commit_mutex);
938 rc = __jfs_setxattr(tid, dentry->d_inode, name, value, value_len, 938 rc = __jfs_setxattr(tid, dentry->d_inode, name, value, value_len,
939 flags); 939 flags);
940 if (!rc) 940 if (!rc)
941 rc = txCommit(tid, 1, &inode, 0); 941 rc = txCommit(tid, 1, &inode, 0);
942 txEnd(tid); 942 txEnd(tid);
943 up(&ji->commit_sem); 943 mutex_unlock(&ji->commit_mutex);
944 944
945 return rc; 945 return rc;
946} 946}
@@ -1093,12 +1093,12 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
1093 return rc; 1093 return rc;
1094 1094
1095 tid = txBegin(inode->i_sb, 0); 1095 tid = txBegin(inode->i_sb, 0);
1096 down(&ji->commit_sem); 1096 mutex_lock(&ji->commit_mutex);
1097 rc = __jfs_setxattr(tid, dentry->d_inode, name, NULL, 0, XATTR_REPLACE); 1097 rc = __jfs_setxattr(tid, dentry->d_inode, name, NULL, 0, XATTR_REPLACE);
1098 if (!rc) 1098 if (!rc)
1099 rc = txCommit(tid, 1, &inode, 0); 1099 rc = txCommit(tid, 1, &inode, 0);
1100 txEnd(tid); 1100 txEnd(tid);
1101 up(&ji->commit_sem); 1101 mutex_unlock(&ji->commit_mutex);
1102 1102
1103 return rc; 1103 return rc;
1104} 1104}
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index 220058d8616d..970b6a6aa337 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -662,12 +662,18 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
662 * reclaimed while we're stuck in the unlock call. */ 662 * reclaimed while we're stuck in the unlock call. */
663 fl->fl_u.nfs_fl.flags &= ~NFS_LCK_GRANTED; 663 fl->fl_u.nfs_fl.flags &= ~NFS_LCK_GRANTED;
664 664
665 /*
666 * Note: the server is supposed to either grant us the unlock
667 * request, or to deny it with NLM_LCK_DENIED_GRACE_PERIOD. In either
668 * case, we want to unlock.
669 */
670 do_vfs_lock(fl);
671
665 if (req->a_flags & RPC_TASK_ASYNC) { 672 if (req->a_flags & RPC_TASK_ASYNC) {
666 status = nlmclnt_async_call(req, NLMPROC_UNLOCK, 673 status = nlmclnt_async_call(req, NLMPROC_UNLOCK,
667 &nlmclnt_unlock_ops); 674 &nlmclnt_unlock_ops);
668 /* Hrmf... Do the unlock early since locks_remove_posix() 675 /* Hrmf... Do the unlock early since locks_remove_posix()
669 * really expects us to free the lock synchronously */ 676 * really expects us to free the lock synchronously */
670 do_vfs_lock(fl);
671 if (status < 0) { 677 if (status < 0) {
672 nlmclnt_release_lockargs(req); 678 nlmclnt_release_lockargs(req);
673 kfree(req); 679 kfree(req);
@@ -680,7 +686,6 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
680 if (status < 0) 686 if (status < 0)
681 return status; 687 return status;
682 688
683 do_vfs_lock(fl);
684 if (resp->status == NLM_LCK_GRANTED) 689 if (resp->status == NLM_LCK_GRANTED)
685 return 0; 690 return 0;
686 691
diff --git a/fs/namei.c b/fs/namei.c
index e28de846c591..8dc2b038d5d9 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2224,13 +2224,17 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
2224 * and other special files. --ADM 2224 * and other special files. --ADM
2225 */ 2225 */
2226asmlinkage long sys_linkat(int olddfd, const char __user *oldname, 2226asmlinkage long sys_linkat(int olddfd, const char __user *oldname,
2227 int newdfd, const char __user *newname) 2227 int newdfd, const char __user *newname,
2228 int flags)
2228{ 2229{
2229 struct dentry *new_dentry; 2230 struct dentry *new_dentry;
2230 struct nameidata nd, old_nd; 2231 struct nameidata nd, old_nd;
2231 int error; 2232 int error;
2232 char * to; 2233 char * to;
2233 2234
2235 if (flags != 0)
2236 return -EINVAL;
2237
2234 to = getname(newname); 2238 to = getname(newname);
2235 if (IS_ERR(to)) 2239 if (IS_ERR(to))
2236 return PTR_ERR(to); 2240 return PTR_ERR(to);
@@ -2263,7 +2267,7 @@ exit:
2263 2267
2264asmlinkage long sys_link(const char __user *oldname, const char __user *newname) 2268asmlinkage long sys_link(const char __user *oldname, const char __user *newname)
2265{ 2269{
2266 return sys_linkat(AT_FDCWD, oldname, AT_FDCWD, newname); 2270 return sys_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
2267} 2271}
2268 2272
2269/* 2273/*
@@ -2609,13 +2613,15 @@ void page_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
2609 } 2613 }
2610} 2614}
2611 2615
2612int page_symlink(struct inode *inode, const char *symname, int len) 2616int __page_symlink(struct inode *inode, const char *symname, int len,
2617 gfp_t gfp_mask)
2613{ 2618{
2614 struct address_space *mapping = inode->i_mapping; 2619 struct address_space *mapping = inode->i_mapping;
2615 struct page *page = grab_cache_page(mapping, 0); 2620 struct page *page;
2616 int err = -ENOMEM; 2621 int err = -ENOMEM;
2617 char *kaddr; 2622 char *kaddr;
2618 2623
2624 page = find_or_create_page(mapping, 0, gfp_mask);
2619 if (!page) 2625 if (!page)
2620 goto fail; 2626 goto fail;
2621 err = mapping->a_ops->prepare_write(NULL, page, 0, len-1); 2627 err = mapping->a_ops->prepare_write(NULL, page, 0, len-1);
@@ -2650,6 +2656,12 @@ fail:
2650 return err; 2656 return err;
2651} 2657}
2652 2658
2659int page_symlink(struct inode *inode, const char *symname, int len)
2660{
2661 return __page_symlink(inode, symname, len,
2662 mapping_gfp_mask(inode->i_mapping));
2663}
2664
2653struct inode_operations page_symlink_inode_operations = { 2665struct inode_operations page_symlink_inode_operations = {
2654 .readlink = generic_readlink, 2666 .readlink = generic_readlink,
2655 .follow_link = page_follow_link_light, 2667 .follow_link = page_follow_link_light,
@@ -2668,6 +2680,7 @@ EXPORT_SYMBOL(lookup_one_len);
2668EXPORT_SYMBOL(page_follow_link_light); 2680EXPORT_SYMBOL(page_follow_link_light);
2669EXPORT_SYMBOL(page_put_link); 2681EXPORT_SYMBOL(page_put_link);
2670EXPORT_SYMBOL(page_readlink); 2682EXPORT_SYMBOL(page_readlink);
2683EXPORT_SYMBOL(__page_symlink);
2671EXPORT_SYMBOL(page_symlink); 2684EXPORT_SYMBOL(page_symlink);
2672EXPORT_SYMBOL(page_symlink_inode_operations); 2685EXPORT_SYMBOL(page_symlink_inode_operations);
2673EXPORT_SYMBOL(path_lookup); 2686EXPORT_SYMBOL(path_lookup);
diff --git a/fs/namespace.c b/fs/namespace.c
index 058a44865beb..39c81a8d6316 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1338,7 +1338,7 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1338 1338
1339 new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL); 1339 new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL);
1340 if (!new_ns) 1340 if (!new_ns)
1341 goto out; 1341 return NULL;
1342 1342
1343 atomic_set(&new_ns->count, 1); 1343 atomic_set(&new_ns->count, 1);
1344 INIT_LIST_HEAD(&new_ns->list); 1344 INIT_LIST_HEAD(&new_ns->list);
@@ -1352,7 +1352,7 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1352 if (!new_ns->root) { 1352 if (!new_ns->root) {
1353 up_write(&namespace_sem); 1353 up_write(&namespace_sem);
1354 kfree(new_ns); 1354 kfree(new_ns);
1355 goto out; 1355 return NULL;
1356 } 1356 }
1357 spin_lock(&vfsmount_lock); 1357 spin_lock(&vfsmount_lock);
1358 list_add_tail(&new_ns->list, &new_ns->root->mnt_list); 1358 list_add_tail(&new_ns->list, &new_ns->root->mnt_list);
@@ -1393,7 +1393,6 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1393 if (altrootmnt) 1393 if (altrootmnt)
1394 mntput(altrootmnt); 1394 mntput(altrootmnt);
1395 1395
1396out:
1397 return new_ns; 1396 return new_ns;
1398} 1397}
1399 1398
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 04ab2fc360e7..4e9b3a1b36c5 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -57,6 +57,7 @@
57#define NFSDBG_FACILITY NFSDBG_VFS 57#define NFSDBG_FACILITY NFSDBG_VFS
58#define MAX_DIRECTIO_SIZE (4096UL << PAGE_SHIFT) 58#define MAX_DIRECTIO_SIZE (4096UL << PAGE_SHIFT)
59 59
60static void nfs_free_user_pages(struct page **pages, int npages, int do_dirty);
60static kmem_cache_t *nfs_direct_cachep; 61static kmem_cache_t *nfs_direct_cachep;
61 62
62/* 63/*
@@ -107,6 +108,15 @@ nfs_get_user_pages(int rw, unsigned long user_addr, size_t size,
107 page_count, (rw == READ), 0, 108 page_count, (rw == READ), 0,
108 *pages, NULL); 109 *pages, NULL);
109 up_read(&current->mm->mmap_sem); 110 up_read(&current->mm->mmap_sem);
111 /*
112 * If we got fewer pages than expected from get_user_pages(),
113 * the user buffer runs off the end of a mapping; return EFAULT.
114 */
115 if (result >= 0 && result < page_count) {
116 nfs_free_user_pages(*pages, result, 0);
117 *pages = NULL;
118 result = -EFAULT;
119 }
110 } 120 }
111 return result; 121 return result;
112} 122}
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 984ca3454d04..f8c0066e02e1 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1430,7 +1430,7 @@ static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
1430 if (status == 0) 1430 if (status == 0)
1431 status = nfs4_do_fsinfo(server, fhandle, info); 1431 status = nfs4_do_fsinfo(server, fhandle, info);
1432out: 1432out:
1433 return status; 1433 return nfs4_map_errors(status);
1434} 1434}
1435 1435
1436static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) 1436static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
diff --git a/fs/nfsctl.c b/fs/nfsctl.c
index 0d4cf9486068..1c72c7f85ddc 100644
--- a/fs/nfsctl.c
+++ b/fs/nfsctl.c
@@ -98,10 +98,8 @@ asmlinkage sys_nfsservctl(int cmd, struct nfsctl_arg __user *arg, void __user *r
98 if (copy_from_user(&version, &arg->ca_version, sizeof(int))) 98 if (copy_from_user(&version, &arg->ca_version, sizeof(int)))
99 return -EFAULT; 99 return -EFAULT;
100 100
101 if (version != NFSCTL_VERSION) { 101 if (version != NFSCTL_VERSION)
102 printk(KERN_WARNING "nfsd: incompatible version in syscall.\n");
103 return -EINVAL; 102 return -EINVAL;
104 }
105 103
106 if (cmd < 0 || cmd >= sizeof(map)/sizeof(map[0]) || !map[cmd].name) 104 if (cmd < 0 || cmd >= sizeof(map)/sizeof(map[0]) || !map[cmd].name)
107 return -EINVAL; 105 return -EINVAL;
diff --git a/fs/nls/Kconfig b/fs/nls/Kconfig
index 0ab8f00bdbb2..976ecccd6f56 100644
--- a/fs/nls/Kconfig
+++ b/fs/nls/Kconfig
@@ -491,7 +491,7 @@ config NLS_KOI8_U
491 (koi8-u) and Belarusian (koi8-ru) character sets. 491 (koi8-u) and Belarusian (koi8-ru) character sets.
492 492
493config NLS_UTF8 493config NLS_UTF8
494 tristate "NLS UTF8" 494 tristate "NLS UTF-8"
495 depends on NLS 495 depends on NLS
496 help 496 help
497 If you want to display filenames with native language characters 497 If you want to display filenames with native language characters
diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
index fd741cea5705..636593bf4d17 100644
--- a/fs/ocfs2/cluster/masklog.c
+++ b/fs/ocfs2/cluster/masklog.c
@@ -74,6 +74,7 @@ struct mlog_attribute {
74#define define_mask(_name) { \ 74#define define_mask(_name) { \
75 .attr = { \ 75 .attr = { \
76 .name = #_name, \ 76 .name = #_name, \
77 .owner = THIS_MODULE, \
77 .mode = S_IRUGO | S_IWUSR, \ 78 .mode = S_IRUGO | S_IWUSR, \
78 }, \ 79 }, \
79 .mask = ML_##_name, \ 80 .mask = ML_##_name, \
diff --git a/fs/ocfs2/cluster/masklog.h b/fs/ocfs2/cluster/masklog.h
index e8c56a3d9c64..2cadc3009c83 100644
--- a/fs/ocfs2/cluster/masklog.h
+++ b/fs/ocfs2/cluster/masklog.h
@@ -256,7 +256,7 @@ extern struct mlog_bits mlog_and_bits, mlog_not_bits;
256 } \ 256 } \
257} while (0) 257} while (0)
258 258
259#if (BITS_PER_LONG == 32) || defined(CONFIG_X86_64) 259#if (BITS_PER_LONG == 32) || defined(CONFIG_X86_64) || (defined(CONFIG_UML_X86) && defined(CONFIG_64BIT))
260#define MLFi64 "lld" 260#define MLFi64 "lld"
261#define MLFu64 "llu" 261#define MLFu64 "llu"
262#define MLFx64 "llx" 262#define MLFx64 "llx"
diff --git a/fs/ocfs2/cluster/nodemanager.c b/fs/ocfs2/cluster/nodemanager.c
index cf7828f23361..e1fceb8aa32d 100644
--- a/fs/ocfs2/cluster/nodemanager.c
+++ b/fs/ocfs2/cluster/nodemanager.c
@@ -756,7 +756,7 @@ static int __init init_o2nm(void)
756 if (!ocfs2_table_header) { 756 if (!ocfs2_table_header) {
757 printk(KERN_ERR "nodemanager: unable to register sysctl\n"); 757 printk(KERN_ERR "nodemanager: unable to register sysctl\n");
758 ret = -ENOMEM; /* or something. */ 758 ret = -ENOMEM; /* or something. */
759 goto out; 759 goto out_o2net;
760 } 760 }
761 761
762 ret = o2net_register_hb_callbacks(); 762 ret = o2net_register_hb_callbacks();
@@ -780,6 +780,8 @@ out_callbacks:
780 o2net_unregister_hb_callbacks(); 780 o2net_unregister_hb_callbacks();
781out_sysctl: 781out_sysctl:
782 unregister_sysctl_table(ocfs2_table_header); 782 unregister_sysctl_table(ocfs2_table_header);
783out_o2net:
784 o2net_exit();
783out: 785out:
784 return ret; 786 return ret;
785} 787}
diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c
index d22d4cf08db1..0f60cc0d3985 100644
--- a/fs/ocfs2/cluster/tcp.c
+++ b/fs/ocfs2/cluster/tcp.c
@@ -1318,7 +1318,7 @@ static void o2net_start_connect(void *arg)
1318{ 1318{
1319 struct o2net_node *nn = arg; 1319 struct o2net_node *nn = arg;
1320 struct o2net_sock_container *sc = NULL; 1320 struct o2net_sock_container *sc = NULL;
1321 struct o2nm_node *node = NULL; 1321 struct o2nm_node *node = NULL, *mynode = NULL;
1322 struct socket *sock = NULL; 1322 struct socket *sock = NULL;
1323 struct sockaddr_in myaddr = {0, }, remoteaddr = {0, }; 1323 struct sockaddr_in myaddr = {0, }, remoteaddr = {0, };
1324 int ret = 0; 1324 int ret = 0;
@@ -1334,6 +1334,12 @@ static void o2net_start_connect(void *arg)
1334 goto out; 1334 goto out;
1335 } 1335 }
1336 1336
1337 mynode = o2nm_get_node_by_num(o2nm_this_node());
1338 if (mynode == NULL) {
1339 ret = 0;
1340 goto out;
1341 }
1342
1337 spin_lock(&nn->nn_lock); 1343 spin_lock(&nn->nn_lock);
1338 /* see if we already have one pending or have given up */ 1344 /* see if we already have one pending or have given up */
1339 if (nn->nn_sc || nn->nn_persistent_error) 1345 if (nn->nn_sc || nn->nn_persistent_error)
@@ -1361,12 +1367,14 @@ static void o2net_start_connect(void *arg)
1361 sock->sk->sk_allocation = GFP_ATOMIC; 1367 sock->sk->sk_allocation = GFP_ATOMIC;
1362 1368
1363 myaddr.sin_family = AF_INET; 1369 myaddr.sin_family = AF_INET;
1370 myaddr.sin_addr.s_addr = (__force u32)mynode->nd_ipv4_address;
1364 myaddr.sin_port = (__force u16)htons(0); /* any port */ 1371 myaddr.sin_port = (__force u16)htons(0); /* any port */
1365 1372
1366 ret = sock->ops->bind(sock, (struct sockaddr *)&myaddr, 1373 ret = sock->ops->bind(sock, (struct sockaddr *)&myaddr,
1367 sizeof(myaddr)); 1374 sizeof(myaddr));
1368 if (ret) { 1375 if (ret) {
1369 mlog(0, "bind failed: %d\n", ret); 1376 mlog(ML_ERROR, "bind failed with %d at address %u.%u.%u.%u\n",
1377 ret, NIPQUAD(mynode->nd_ipv4_address));
1370 goto out; 1378 goto out;
1371 } 1379 }
1372 1380
@@ -1407,6 +1415,8 @@ out:
1407 sc_put(sc); 1415 sc_put(sc);
1408 if (node) 1416 if (node)
1409 o2nm_node_put(node); 1417 o2nm_node_put(node);
1418 if (mynode)
1419 o2nm_node_put(mynode);
1410 1420
1411 return; 1421 return;
1412} 1422}
diff --git a/fs/ocfs2/cluster/tcp.h b/fs/ocfs2/cluster/tcp.h
index a6f4585501c8..616ff2b8434a 100644
--- a/fs/ocfs2/cluster/tcp.h
+++ b/fs/ocfs2/cluster/tcp.h
@@ -85,13 +85,10 @@ enum {
85 O2NET_DRIVER_READY, 85 O2NET_DRIVER_READY,
86}; 86};
87 87
88int o2net_init_tcp_sock(struct inode *inode);
89int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len, 88int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len,
90 u8 target_node, int *status); 89 u8 target_node, int *status);
91int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec, 90int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec,
92 size_t veclen, u8 target_node, int *status); 91 size_t veclen, u8 target_node, int *status);
93int o2net_broadcast_message(u32 msg_type, u32 key, void *data, u32 len,
94 struct inode *group);
95 92
96int o2net_register_handler(u32 msg_type, u32 key, u32 max_len, 93int o2net_register_handler(u32 msg_type, u32 key, u32 max_len,
97 o2net_msg_handler_func *func, void *data, 94 o2net_msg_handler_func *func, void *data,
@@ -107,7 +104,5 @@ void o2net_disconnect_node(struct o2nm_node *node);
107 104
108int o2net_init(void); 105int o2net_init(void);
109void o2net_exit(void); 106void o2net_exit(void);
110int o2net_proc_init(struct proc_dir_entry *parent);
111void o2net_proc_exit(struct proc_dir_entry *parent);
112 107
113#endif /* O2CLUSTER_TCP_H */ 108#endif /* O2CLUSTER_TCP_H */
diff --git a/fs/ocfs2/dlm/dlmcommon.h b/fs/ocfs2/dlm/dlmcommon.h
index 23ceaa7127b4..9c772583744a 100644
--- a/fs/ocfs2/dlm/dlmcommon.h
+++ b/fs/ocfs2/dlm/dlmcommon.h
@@ -37,9 +37,7 @@
37#define DLM_THREAD_SHUFFLE_INTERVAL 5 // flush everything every 5 passes 37#define DLM_THREAD_SHUFFLE_INTERVAL 5 // flush everything every 5 passes
38#define DLM_THREAD_MS 200 // flush at least every 200 ms 38#define DLM_THREAD_MS 200 // flush at least every 200 ms
39 39
40#define DLM_HASH_BITS 7 40#define DLM_HASH_BUCKETS (PAGE_SIZE / sizeof(struct hlist_head))
41#define DLM_HASH_SIZE (1 << DLM_HASH_BITS)
42#define DLM_HASH_MASK (DLM_HASH_SIZE - 1)
43 41
44enum dlm_ast_type { 42enum dlm_ast_type {
45 DLM_AST = 0, 43 DLM_AST = 0,
@@ -87,7 +85,7 @@ enum dlm_ctxt_state {
87struct dlm_ctxt 85struct dlm_ctxt
88{ 86{
89 struct list_head list; 87 struct list_head list;
90 struct list_head *resources; 88 struct hlist_head *lockres_hash;
91 struct list_head dirty_list; 89 struct list_head dirty_list;
92 struct list_head purge_list; 90 struct list_head purge_list;
93 struct list_head pending_asts; 91 struct list_head pending_asts;
@@ -217,7 +215,7 @@ struct dlm_lock_resource
217{ 215{
218 /* WARNING: Please see the comment in dlm_init_lockres before 216 /* WARNING: Please see the comment in dlm_init_lockres before
219 * adding fields here. */ 217 * adding fields here. */
220 struct list_head list; 218 struct hlist_node hash_node;
221 struct kref refs; 219 struct kref refs;
222 220
223 /* please keep these next 3 in this order 221 /* please keep these next 3 in this order
diff --git a/fs/ocfs2/dlm/dlmdebug.c b/fs/ocfs2/dlm/dlmdebug.c
index f339fe27975a..54f61b76ab51 100644
--- a/fs/ocfs2/dlm/dlmdebug.c
+++ b/fs/ocfs2/dlm/dlmdebug.c
@@ -117,8 +117,8 @@ EXPORT_SYMBOL_GPL(dlm_print_one_lock);
117void dlm_dump_lock_resources(struct dlm_ctxt *dlm) 117void dlm_dump_lock_resources(struct dlm_ctxt *dlm)
118{ 118{
119 struct dlm_lock_resource *res; 119 struct dlm_lock_resource *res;
120 struct list_head *iter; 120 struct hlist_node *iter;
121 struct list_head *bucket; 121 struct hlist_head *bucket;
122 int i; 122 int i;
123 123
124 mlog(ML_NOTICE, "struct dlm_ctxt: %s, node=%u, key=%u\n", 124 mlog(ML_NOTICE, "struct dlm_ctxt: %s, node=%u, key=%u\n",
@@ -129,12 +129,10 @@ void dlm_dump_lock_resources(struct dlm_ctxt *dlm)
129 } 129 }
130 130
131 spin_lock(&dlm->spinlock); 131 spin_lock(&dlm->spinlock);
132 for (i=0; i<DLM_HASH_SIZE; i++) { 132 for (i=0; i<DLM_HASH_BUCKETS; i++) {
133 bucket = &(dlm->resources[i]); 133 bucket = &(dlm->lockres_hash[i]);
134 list_for_each(iter, bucket) { 134 hlist_for_each_entry(res, iter, bucket, hash_node)
135 res = list_entry(iter, struct dlm_lock_resource, list);
136 dlm_print_one_lock_resource(res); 135 dlm_print_one_lock_resource(res);
137 }
138 } 136 }
139 spin_unlock(&dlm->spinlock); 137 spin_unlock(&dlm->spinlock);
140} 138}
diff --git a/fs/ocfs2/dlm/dlmdomain.c b/fs/ocfs2/dlm/dlmdomain.c
index 6ee30837389c..8f3a9e3106fd 100644
--- a/fs/ocfs2/dlm/dlmdomain.c
+++ b/fs/ocfs2/dlm/dlmdomain.c
@@ -77,26 +77,26 @@ static void dlm_unregister_domain_handlers(struct dlm_ctxt *dlm);
77 77
78void __dlm_unhash_lockres(struct dlm_lock_resource *lockres) 78void __dlm_unhash_lockres(struct dlm_lock_resource *lockres)
79{ 79{
80 list_del_init(&lockres->list); 80 hlist_del_init(&lockres->hash_node);
81 dlm_lockres_put(lockres); 81 dlm_lockres_put(lockres);
82} 82}
83 83
84void __dlm_insert_lockres(struct dlm_ctxt *dlm, 84void __dlm_insert_lockres(struct dlm_ctxt *dlm,
85 struct dlm_lock_resource *res) 85 struct dlm_lock_resource *res)
86{ 86{
87 struct list_head *bucket; 87 struct hlist_head *bucket;
88 struct qstr *q; 88 struct qstr *q;
89 89
90 assert_spin_locked(&dlm->spinlock); 90 assert_spin_locked(&dlm->spinlock);
91 91
92 q = &res->lockname; 92 q = &res->lockname;
93 q->hash = full_name_hash(q->name, q->len); 93 q->hash = full_name_hash(q->name, q->len);
94 bucket = &(dlm->resources[q->hash & DLM_HASH_MASK]); 94 bucket = &(dlm->lockres_hash[q->hash % DLM_HASH_BUCKETS]);
95 95
96 /* get a reference for our hashtable */ 96 /* get a reference for our hashtable */
97 dlm_lockres_get(res); 97 dlm_lockres_get(res);
98 98
99 list_add_tail(&res->list, bucket); 99 hlist_add_head(&res->hash_node, bucket);
100} 100}
101 101
102struct dlm_lock_resource * __dlm_lookup_lockres(struct dlm_ctxt *dlm, 102struct dlm_lock_resource * __dlm_lookup_lockres(struct dlm_ctxt *dlm,
@@ -104,9 +104,9 @@ struct dlm_lock_resource * __dlm_lookup_lockres(struct dlm_ctxt *dlm,
104 unsigned int len) 104 unsigned int len)
105{ 105{
106 unsigned int hash; 106 unsigned int hash;
107 struct list_head *iter; 107 struct hlist_node *iter;
108 struct dlm_lock_resource *tmpres=NULL; 108 struct dlm_lock_resource *tmpres=NULL;
109 struct list_head *bucket; 109 struct hlist_head *bucket;
110 110
111 mlog_entry("%.*s\n", len, name); 111 mlog_entry("%.*s\n", len, name);
112 112
@@ -114,11 +114,11 @@ struct dlm_lock_resource * __dlm_lookup_lockres(struct dlm_ctxt *dlm,
114 114
115 hash = full_name_hash(name, len); 115 hash = full_name_hash(name, len);
116 116
117 bucket = &(dlm->resources[hash & DLM_HASH_MASK]); 117 bucket = &(dlm->lockres_hash[hash % DLM_HASH_BUCKETS]);
118 118
119 /* check for pre-existing lock */ 119 /* check for pre-existing lock */
120 list_for_each(iter, bucket) { 120 hlist_for_each(iter, bucket) {
121 tmpres = list_entry(iter, struct dlm_lock_resource, list); 121 tmpres = hlist_entry(iter, struct dlm_lock_resource, hash_node);
122 if (tmpres->lockname.len == len && 122 if (tmpres->lockname.len == len &&
123 memcmp(tmpres->lockname.name, name, len) == 0) { 123 memcmp(tmpres->lockname.name, name, len) == 0) {
124 dlm_lockres_get(tmpres); 124 dlm_lockres_get(tmpres);
@@ -193,8 +193,8 @@ static int dlm_wait_on_domain_helper(const char *domain)
193 193
194static void dlm_free_ctxt_mem(struct dlm_ctxt *dlm) 194static void dlm_free_ctxt_mem(struct dlm_ctxt *dlm)
195{ 195{
196 if (dlm->resources) 196 if (dlm->lockres_hash)
197 free_page((unsigned long) dlm->resources); 197 free_page((unsigned long) dlm->lockres_hash);
198 198
199 if (dlm->name) 199 if (dlm->name)
200 kfree(dlm->name); 200 kfree(dlm->name);
@@ -303,10 +303,10 @@ static void dlm_migrate_all_locks(struct dlm_ctxt *dlm)
303 mlog(0, "Migrating locks from domain %s\n", dlm->name); 303 mlog(0, "Migrating locks from domain %s\n", dlm->name);
304restart: 304restart:
305 spin_lock(&dlm->spinlock); 305 spin_lock(&dlm->spinlock);
306 for (i=0; i<DLM_HASH_SIZE; i++) { 306 for (i = 0; i < DLM_HASH_BUCKETS; i++) {
307 while (!list_empty(&dlm->resources[i])) { 307 while (!hlist_empty(&dlm->lockres_hash[i])) {
308 res = list_entry(dlm->resources[i].next, 308 res = hlist_entry(dlm->lockres_hash[i].first,
309 struct dlm_lock_resource, list); 309 struct dlm_lock_resource, hash_node);
310 /* need reference when manually grabbing lockres */ 310 /* need reference when manually grabbing lockres */
311 dlm_lockres_get(res); 311 dlm_lockres_get(res);
312 /* this should unhash the lockres 312 /* this should unhash the lockres
@@ -1191,18 +1191,17 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain,
1191 goto leave; 1191 goto leave;
1192 } 1192 }
1193 1193
1194 dlm->resources = (struct list_head *) __get_free_page(GFP_KERNEL); 1194 dlm->lockres_hash = (struct hlist_head *) __get_free_page(GFP_KERNEL);
1195 if (!dlm->resources) { 1195 if (!dlm->lockres_hash) {
1196 mlog_errno(-ENOMEM); 1196 mlog_errno(-ENOMEM);
1197 kfree(dlm->name); 1197 kfree(dlm->name);
1198 kfree(dlm); 1198 kfree(dlm);
1199 dlm = NULL; 1199 dlm = NULL;
1200 goto leave; 1200 goto leave;
1201 } 1201 }
1202 memset(dlm->resources, 0, PAGE_SIZE);
1203 1202
1204 for (i=0; i<DLM_HASH_SIZE; i++) 1203 for (i=0; i<DLM_HASH_BUCKETS; i++)
1205 INIT_LIST_HEAD(&dlm->resources[i]); 1204 INIT_HLIST_HEAD(&dlm->lockres_hash[i]);
1206 1205
1207 strcpy(dlm->name, domain); 1206 strcpy(dlm->name, domain);
1208 dlm->key = key; 1207 dlm->key = key;
diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c
index 2e2e95e69499..847dd3cc4cf5 100644
--- a/fs/ocfs2/dlm/dlmmaster.c
+++ b/fs/ocfs2/dlm/dlmmaster.c
@@ -564,7 +564,7 @@ static void dlm_lockres_release(struct kref *kref)
564 564
565 /* By the time we're ready to blow this guy away, we shouldn't 565 /* By the time we're ready to blow this guy away, we shouldn't
566 * be on any lists. */ 566 * be on any lists. */
567 BUG_ON(!list_empty(&res->list)); 567 BUG_ON(!hlist_unhashed(&res->hash_node));
568 BUG_ON(!list_empty(&res->granted)); 568 BUG_ON(!list_empty(&res->granted));
569 BUG_ON(!list_empty(&res->converting)); 569 BUG_ON(!list_empty(&res->converting));
570 BUG_ON(!list_empty(&res->blocked)); 570 BUG_ON(!list_empty(&res->blocked));
@@ -605,7 +605,7 @@ static void dlm_init_lockres(struct dlm_ctxt *dlm,
605 605
606 init_waitqueue_head(&res->wq); 606 init_waitqueue_head(&res->wq);
607 spin_lock_init(&res->spinlock); 607 spin_lock_init(&res->spinlock);
608 INIT_LIST_HEAD(&res->list); 608 INIT_HLIST_NODE(&res->hash_node);
609 INIT_LIST_HEAD(&res->granted); 609 INIT_LIST_HEAD(&res->granted);
610 INIT_LIST_HEAD(&res->converting); 610 INIT_LIST_HEAD(&res->converting);
611 INIT_LIST_HEAD(&res->blocked); 611 INIT_LIST_HEAD(&res->blocked);
diff --git a/fs/ocfs2/dlm/dlmrecovery.c b/fs/ocfs2/dlm/dlmrecovery.c
index ed76bda1a534..1e232000f3f7 100644
--- a/fs/ocfs2/dlm/dlmrecovery.c
+++ b/fs/ocfs2/dlm/dlmrecovery.c
@@ -1693,7 +1693,10 @@ static void dlm_finish_local_lockres_recovery(struct dlm_ctxt *dlm,
1693 u8 dead_node, u8 new_master) 1693 u8 dead_node, u8 new_master)
1694{ 1694{
1695 int i; 1695 int i;
1696 struct list_head *iter, *iter2, *bucket; 1696 struct list_head *iter, *iter2;
1697 struct hlist_node *hash_iter;
1698 struct hlist_head *bucket;
1699
1697 struct dlm_lock_resource *res; 1700 struct dlm_lock_resource *res;
1698 1701
1699 mlog_entry_void(); 1702 mlog_entry_void();
@@ -1717,10 +1720,9 @@ static void dlm_finish_local_lockres_recovery(struct dlm_ctxt *dlm,
1717 * for now we need to run the whole hash, clear 1720 * for now we need to run the whole hash, clear
1718 * the RECOVERING state and set the owner 1721 * the RECOVERING state and set the owner
1719 * if necessary */ 1722 * if necessary */
1720 for (i=0; i<DLM_HASH_SIZE; i++) { 1723 for (i = 0; i < DLM_HASH_BUCKETS; i++) {
1721 bucket = &(dlm->resources[i]); 1724 bucket = &(dlm->lockres_hash[i]);
1722 list_for_each(iter, bucket) { 1725 hlist_for_each_entry(res, hash_iter, bucket, hash_node) {
1723 res = list_entry (iter, struct dlm_lock_resource, list);
1724 if (res->state & DLM_LOCK_RES_RECOVERING) { 1726 if (res->state & DLM_LOCK_RES_RECOVERING) {
1725 if (res->owner == dead_node) { 1727 if (res->owner == dead_node) {
1726 mlog(0, "(this=%u) res %.*s owner=%u " 1728 mlog(0, "(this=%u) res %.*s owner=%u "
@@ -1852,10 +1854,10 @@ static void dlm_free_dead_locks(struct dlm_ctxt *dlm,
1852 1854
1853static void dlm_do_local_recovery_cleanup(struct dlm_ctxt *dlm, u8 dead_node) 1855static void dlm_do_local_recovery_cleanup(struct dlm_ctxt *dlm, u8 dead_node)
1854{ 1856{
1855 struct list_head *iter; 1857 struct hlist_node *iter;
1856 struct dlm_lock_resource *res; 1858 struct dlm_lock_resource *res;
1857 int i; 1859 int i;
1858 struct list_head *bucket; 1860 struct hlist_head *bucket;
1859 struct dlm_lock *lock; 1861 struct dlm_lock *lock;
1860 1862
1861 1863
@@ -1876,10 +1878,9 @@ static void dlm_do_local_recovery_cleanup(struct dlm_ctxt *dlm, u8 dead_node)
1876 * can be kicked again to see if any ASTs or BASTs 1878 * can be kicked again to see if any ASTs or BASTs
1877 * need to be fired as a result. 1879 * need to be fired as a result.
1878 */ 1880 */
1879 for (i=0; i<DLM_HASH_SIZE; i++) { 1881 for (i = 0; i < DLM_HASH_BUCKETS; i++) {
1880 bucket = &(dlm->resources[i]); 1882 bucket = &(dlm->lockres_hash[i]);
1881 list_for_each(iter, bucket) { 1883 hlist_for_each_entry(res, iter, bucket, hash_node) {
1882 res = list_entry (iter, struct dlm_lock_resource, list);
1883 /* always prune any $RECOVERY entries for dead nodes, 1884 /* always prune any $RECOVERY entries for dead nodes,
1884 * otherwise hangs can occur during later recovery */ 1885 * otherwise hangs can occur during later recovery */
1885 if (dlm_is_recovery_lock(res->lockname.name, 1886 if (dlm_is_recovery_lock(res->lockname.name,
diff --git a/fs/ocfs2/extent_map.c b/fs/ocfs2/extent_map.c
index b6ba292e9544..e6f207eebab4 100644
--- a/fs/ocfs2/extent_map.c
+++ b/fs/ocfs2/extent_map.c
@@ -181,6 +181,12 @@ static int ocfs2_extent_map_find_leaf(struct inode *inode,
181 ret = -EBADR; 181 ret = -EBADR;
182 if (rec_end > OCFS2_I(inode)->ip_clusters) { 182 if (rec_end > OCFS2_I(inode)->ip_clusters) {
183 mlog_errno(ret); 183 mlog_errno(ret);
184 ocfs2_error(inode->i_sb,
185 "Extent %d at e_blkno %"MLFu64" of inode %"MLFu64" goes past ip_clusters of %u\n",
186 i,
187 le64_to_cpu(rec->e_blkno),
188 OCFS2_I(inode)->ip_blkno,
189 OCFS2_I(inode)->ip_clusters);
184 goto out_free; 190 goto out_free;
185 } 191 }
186 192
@@ -226,6 +232,12 @@ static int ocfs2_extent_map_find_leaf(struct inode *inode,
226 ret = -EBADR; 232 ret = -EBADR;
227 if (blkno) { 233 if (blkno) {
228 mlog_errno(ret); 234 mlog_errno(ret);
235 ocfs2_error(inode->i_sb,
236 "Multiple extents for (cpos = %u, clusters = %u) on inode %"MLFu64"; e_blkno %"MLFu64" and rec %d at e_blkno %"MLFu64"\n",
237 cpos, clusters,
238 OCFS2_I(inode)->ip_blkno,
239 blkno, i,
240 le64_to_cpu(rec->e_blkno));
229 goto out_free; 241 goto out_free;
230 } 242 }
231 243
@@ -238,6 +250,10 @@ static int ocfs2_extent_map_find_leaf(struct inode *inode,
238 */ 250 */
239 ret = -EBADR; 251 ret = -EBADR;
240 if (!blkno) { 252 if (!blkno) {
253 ocfs2_error(inode->i_sb,
254 "No record found for (cpos = %u, clusters = %u) on inode %"MLFu64"\n",
255 cpos, clusters,
256 OCFS2_I(inode)->ip_blkno);
241 mlog_errno(ret); 257 mlog_errno(ret);
242 goto out_free; 258 goto out_free;
243 } 259 }
@@ -266,6 +282,20 @@ static int ocfs2_extent_map_find_leaf(struct inode *inode,
266 282
267 for (i = 0; i < le16_to_cpu(el->l_next_free_rec); i++) { 283 for (i = 0; i < le16_to_cpu(el->l_next_free_rec); i++) {
268 rec = &el->l_recs[i]; 284 rec = &el->l_recs[i];
285
286 if ((le32_to_cpu(rec->e_cpos) + le32_to_cpu(rec->e_clusters)) >
287 OCFS2_I(inode)->ip_clusters) {
288 ret = -EBADR;
289 mlog_errno(ret);
290 ocfs2_error(inode->i_sb,
291 "Extent %d at e_blkno %"MLFu64" of inode %"MLFu64" goes past ip_clusters of %u\n",
292 i,
293 le64_to_cpu(rec->e_blkno),
294 OCFS2_I(inode)->ip_blkno,
295 OCFS2_I(inode)->ip_clusters);
296 return ret;
297 }
298
269 ret = ocfs2_extent_map_insert(inode, rec, 299 ret = ocfs2_extent_map_insert(inode, rec,
270 le16_to_cpu(el->l_tree_depth)); 300 le16_to_cpu(el->l_tree_depth));
271 if (ret) { 301 if (ret) {
@@ -526,6 +556,10 @@ static int ocfs2_extent_map_insert(struct inode *inode,
526 OCFS2_I(inode)->ip_map.em_clusters) { 556 OCFS2_I(inode)->ip_map.em_clusters) {
527 ret = -EBADR; 557 ret = -EBADR;
528 mlog_errno(ret); 558 mlog_errno(ret);
559 ocfs2_error(inode->i_sb,
560 "Zero e_clusters on non-tail extent record at e_blkno %"MLFu64" on inode %"MLFu64"\n",
561 le64_to_cpu(rec->e_blkno),
562 OCFS2_I(inode)->ip_blkno);
529 return ret; 563 return ret;
530 } 564 }
531 565
@@ -588,12 +622,12 @@ static int ocfs2_extent_map_insert(struct inode *inode,
588 * Existing record in the extent map: 622 * Existing record in the extent map:
589 * 623 *
590 * cpos = 10, len = 10 624 * cpos = 10, len = 10
591 * |---------| 625 * |---------|
592 * 626 *
593 * New Record: 627 * New Record:
594 * 628 *
595 * cpos = 10, len = 20 629 * cpos = 10, len = 20
596 * |------------------| 630 * |------------------|
597 * 631 *
598 * The passed record is the new on-disk record. The new_clusters value 632 * The passed record is the new on-disk record. The new_clusters value
599 * is how many clusters were added to the file. If the append is a 633 * is how many clusters were added to the file. If the append is a
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 1715bc90e705..8a4048b55fdc 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -933,9 +933,6 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
933 struct file *filp = iocb->ki_filp; 933 struct file *filp = iocb->ki_filp;
934 struct inode *inode = filp->f_dentry->d_inode; 934 struct inode *inode = filp->f_dentry->d_inode;
935 loff_t newsize, saved_pos; 935 loff_t newsize, saved_pos;
936#ifdef OCFS2_ORACORE_WORKAROUNDS
937 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
938#endif
939 936
940 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", filp, buf, 937 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", filp, buf,
941 (unsigned int)count, 938 (unsigned int)count,
@@ -951,14 +948,6 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
951 return -EIO; 948 return -EIO;
952 } 949 }
953 950
954#ifdef OCFS2_ORACORE_WORKAROUNDS
955 /* ugh, work around some applications which open everything O_DIRECT +
956 * O_APPEND and really don't mean to use O_DIRECT. */
957 if (osb->s_mount_opt & OCFS2_MOUNT_COMPAT_OCFS &&
958 (filp->f_flags & O_APPEND) && (filp->f_flags & O_DIRECT))
959 filp->f_flags &= ~O_DIRECT;
960#endif
961
962 mutex_lock(&inode->i_mutex); 951 mutex_lock(&inode->i_mutex);
963 /* to match setattr's i_mutex -> i_alloc_sem -> rw_lock ordering */ 952 /* to match setattr's i_mutex -> i_alloc_sem -> rw_lock ordering */
964 if (filp->f_flags & O_DIRECT) { 953 if (filp->f_flags & O_DIRECT) {
@@ -1079,27 +1068,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1079 /* communicate with ocfs2_dio_end_io */ 1068 /* communicate with ocfs2_dio_end_io */
1080 ocfs2_iocb_set_rw_locked(iocb); 1069 ocfs2_iocb_set_rw_locked(iocb);
1081 1070
1082#ifdef OCFS2_ORACORE_WORKAROUNDS 1071 ret = generic_file_aio_write_nolock(iocb, &local_iov, 1, &iocb->ki_pos);
1083 if (osb->s_mount_opt & OCFS2_MOUNT_COMPAT_OCFS &&
1084 filp->f_flags & O_DIRECT) {
1085 unsigned int saved_flags = filp->f_flags;
1086 int sector_size = 1 << osb->s_sectsize_bits;
1087
1088 if ((saved_pos & (sector_size - 1)) ||
1089 (count & (sector_size - 1)) ||
1090 ((unsigned long)buf & (sector_size - 1))) {
1091 filp->f_flags |= O_SYNC;
1092 filp->f_flags &= ~O_DIRECT;
1093 }
1094
1095 ret = generic_file_aio_write_nolock(iocb, &local_iov, 1,
1096 &iocb->ki_pos);
1097
1098 filp->f_flags = saved_flags;
1099 } else
1100#endif
1101 ret = generic_file_aio_write_nolock(iocb, &local_iov, 1,
1102 &iocb->ki_pos);
1103 1072
1104 /* buffered aio wouldn't have proper lock coverage today */ 1073 /* buffered aio wouldn't have proper lock coverage today */
1105 BUG_ON(ret == -EIOCBQUEUED && !(filp->f_flags & O_DIRECT)); 1074 BUG_ON(ret == -EIOCBQUEUED && !(filp->f_flags & O_DIRECT));
@@ -1140,9 +1109,6 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
1140 int ret = 0, rw_level = -1, have_alloc_sem = 0; 1109 int ret = 0, rw_level = -1, have_alloc_sem = 0;
1141 struct file *filp = iocb->ki_filp; 1110 struct file *filp = iocb->ki_filp;
1142 struct inode *inode = filp->f_dentry->d_inode; 1111 struct inode *inode = filp->f_dentry->d_inode;
1143#ifdef OCFS2_ORACORE_WORKAROUNDS
1144 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1145#endif
1146 1112
1147 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", filp, buf, 1113 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", filp, buf,
1148 (unsigned int)count, 1114 (unsigned int)count,
@@ -1155,21 +1121,6 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
1155 goto bail; 1121 goto bail;
1156 } 1122 }
1157 1123
1158#ifdef OCFS2_ORACORE_WORKAROUNDS
1159 if (osb->s_mount_opt & OCFS2_MOUNT_COMPAT_OCFS) {
1160 if (filp->f_flags & O_DIRECT) {
1161 int sector_size = 1 << osb->s_sectsize_bits;
1162
1163 if ((pos & (sector_size - 1)) ||
1164 (count & (sector_size - 1)) ||
1165 ((unsigned long)buf & (sector_size - 1)) ||
1166 (i_size_read(inode) & (sector_size -1))) {
1167 filp->f_flags &= ~O_DIRECT;
1168 }
1169 }
1170 }
1171#endif
1172
1173 /* 1124 /*
1174 * buffered reads protect themselves in ->readpage(). O_DIRECT reads 1125 * buffered reads protect themselves in ->readpage(). O_DIRECT reads
1175 * need locks to protect pending reads from racing with truncate. 1126 * need locks to protect pending reads from racing with truncate.
diff --git a/fs/ocfs2/heartbeat.c b/fs/ocfs2/heartbeat.c
index 0bbd22f46c80..cbfd45a97a63 100644
--- a/fs/ocfs2/heartbeat.c
+++ b/fs/ocfs2/heartbeat.c
@@ -67,6 +67,7 @@ void ocfs2_init_node_maps(struct ocfs2_super *osb)
67 ocfs2_node_map_init(&osb->mounted_map); 67 ocfs2_node_map_init(&osb->mounted_map);
68 ocfs2_node_map_init(&osb->recovery_map); 68 ocfs2_node_map_init(&osb->recovery_map);
69 ocfs2_node_map_init(&osb->umount_map); 69 ocfs2_node_map_init(&osb->umount_map);
70 ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
70} 71}
71 72
72static void ocfs2_do_node_down(int node_num, 73static void ocfs2_do_node_down(int node_num,
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index 8122489c5762..315472a5c192 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -41,6 +41,7 @@
41#include "dlmglue.h" 41#include "dlmglue.h"
42#include "extent_map.h" 42#include "extent_map.h"
43#include "file.h" 43#include "file.h"
44#include "heartbeat.h"
44#include "inode.h" 45#include "inode.h"
45#include "journal.h" 46#include "journal.h"
46#include "namei.h" 47#include "namei.h"
@@ -544,6 +545,42 @@ bail:
544 return status; 545 return status;
545} 546}
546 547
548/*
549 * Serialize with orphan dir recovery. If the process doing
550 * recovery on this orphan dir does an iget() with the dir
551 * i_mutex held, we'll deadlock here. Instead we detect this
552 * and exit early - recovery will wipe this inode for us.
553 */
554static int ocfs2_check_orphan_recovery_state(struct ocfs2_super *osb,
555 int slot)
556{
557 int ret = 0;
558
559 spin_lock(&osb->osb_lock);
560 if (ocfs2_node_map_test_bit(osb, &osb->osb_recovering_orphan_dirs, slot)) {
561 mlog(0, "Recovery is happening on orphan dir %d, will skip "
562 "this inode\n", slot);
563 ret = -EDEADLK;
564 goto out;
565 }
566 /* This signals to the orphan recovery process that it should
567 * wait for us to handle the wipe. */
568 osb->osb_orphan_wipes[slot]++;
569out:
570 spin_unlock(&osb->osb_lock);
571 return ret;
572}
573
574static void ocfs2_signal_wipe_completion(struct ocfs2_super *osb,
575 int slot)
576{
577 spin_lock(&osb->osb_lock);
578 osb->osb_orphan_wipes[slot]--;
579 spin_unlock(&osb->osb_lock);
580
581 wake_up(&osb->osb_wipe_event);
582}
583
547static int ocfs2_wipe_inode(struct inode *inode, 584static int ocfs2_wipe_inode(struct inode *inode,
548 struct buffer_head *di_bh) 585 struct buffer_head *di_bh)
549{ 586{
@@ -555,6 +592,11 @@ static int ocfs2_wipe_inode(struct inode *inode,
555 /* We've already voted on this so it should be readonly - no 592 /* We've already voted on this so it should be readonly - no
556 * spinlock needed. */ 593 * spinlock needed. */
557 orphaned_slot = OCFS2_I(inode)->ip_orphaned_slot; 594 orphaned_slot = OCFS2_I(inode)->ip_orphaned_slot;
595
596 status = ocfs2_check_orphan_recovery_state(osb, orphaned_slot);
597 if (status)
598 return status;
599
558 orphan_dir_inode = ocfs2_get_system_file_inode(osb, 600 orphan_dir_inode = ocfs2_get_system_file_inode(osb,
559 ORPHAN_DIR_SYSTEM_INODE, 601 ORPHAN_DIR_SYSTEM_INODE,
560 orphaned_slot); 602 orphaned_slot);
@@ -597,6 +639,7 @@ bail_unlock_dir:
597 brelse(orphan_dir_bh); 639 brelse(orphan_dir_bh);
598bail: 640bail:
599 iput(orphan_dir_inode); 641 iput(orphan_dir_inode);
642 ocfs2_signal_wipe_completion(osb, orphaned_slot);
600 643
601 return status; 644 return status;
602} 645}
@@ -822,7 +865,8 @@ void ocfs2_delete_inode(struct inode *inode)
822 865
823 status = ocfs2_wipe_inode(inode, di_bh); 866 status = ocfs2_wipe_inode(inode, di_bh);
824 if (status < 0) { 867 if (status < 0) {
825 mlog_errno(status); 868 if (status != -EDEADLK)
869 mlog_errno(status);
826 goto bail_unlock_inode; 870 goto bail_unlock_inode;
827 } 871 }
828 872
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index d329c9df90ae..4be801f4559b 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -1408,21 +1408,17 @@ bail:
1408 return status; 1408 return status;
1409} 1409}
1410 1410
1411static int ocfs2_recover_orphans(struct ocfs2_super *osb, 1411static int ocfs2_queue_orphans(struct ocfs2_super *osb,
1412 int slot) 1412 int slot,
1413 struct inode **head)
1413{ 1414{
1414 int status = 0; 1415 int status;
1415 int have_disk_lock = 0;
1416 struct inode *inode = NULL;
1417 struct inode *iter;
1418 struct inode *orphan_dir_inode = NULL; 1416 struct inode *orphan_dir_inode = NULL;
1417 struct inode *iter;
1419 unsigned long offset, blk, local; 1418 unsigned long offset, blk, local;
1420 struct buffer_head *bh = NULL; 1419 struct buffer_head *bh = NULL;
1421 struct ocfs2_dir_entry *de; 1420 struct ocfs2_dir_entry *de;
1422 struct super_block *sb = osb->sb; 1421 struct super_block *sb = osb->sb;
1423 struct ocfs2_inode_info *oi;
1424
1425 mlog(0, "Recover inodes from orphan dir in slot %d\n", slot);
1426 1422
1427 orphan_dir_inode = ocfs2_get_system_file_inode(osb, 1423 orphan_dir_inode = ocfs2_get_system_file_inode(osb,
1428 ORPHAN_DIR_SYSTEM_INODE, 1424 ORPHAN_DIR_SYSTEM_INODE,
@@ -1430,17 +1426,15 @@ static int ocfs2_recover_orphans(struct ocfs2_super *osb,
1430 if (!orphan_dir_inode) { 1426 if (!orphan_dir_inode) {
1431 status = -ENOENT; 1427 status = -ENOENT;
1432 mlog_errno(status); 1428 mlog_errno(status);
1433 goto out; 1429 return status;
1434 } 1430 }
1435 1431
1436 mutex_lock(&orphan_dir_inode->i_mutex); 1432 mutex_lock(&orphan_dir_inode->i_mutex);
1437 status = ocfs2_meta_lock(orphan_dir_inode, NULL, NULL, 0); 1433 status = ocfs2_meta_lock(orphan_dir_inode, NULL, NULL, 0);
1438 if (status < 0) { 1434 if (status < 0) {
1439 mutex_unlock(&orphan_dir_inode->i_mutex);
1440 mlog_errno(status); 1435 mlog_errno(status);
1441 goto out; 1436 goto out;
1442 } 1437 }
1443 have_disk_lock = 1;
1444 1438
1445 offset = 0; 1439 offset = 0;
1446 iter = NULL; 1440 iter = NULL;
@@ -1451,11 +1445,10 @@ static int ocfs2_recover_orphans(struct ocfs2_super *osb,
1451 if (!bh) 1445 if (!bh)
1452 status = -EINVAL; 1446 status = -EINVAL;
1453 if (status < 0) { 1447 if (status < 0) {
1454 mutex_unlock(&orphan_dir_inode->i_mutex);
1455 if (bh) 1448 if (bh)
1456 brelse(bh); 1449 brelse(bh);
1457 mlog_errno(status); 1450 mlog_errno(status);
1458 goto out; 1451 goto out_unlock;
1459 } 1452 }
1460 1453
1461 local = 0; 1454 local = 0;
@@ -1465,11 +1458,10 @@ static int ocfs2_recover_orphans(struct ocfs2_super *osb,
1465 1458
1466 if (!ocfs2_check_dir_entry(orphan_dir_inode, 1459 if (!ocfs2_check_dir_entry(orphan_dir_inode,
1467 de, bh, local)) { 1460 de, bh, local)) {
1468 mutex_unlock(&orphan_dir_inode->i_mutex);
1469 status = -EINVAL; 1461 status = -EINVAL;
1470 mlog_errno(status); 1462 mlog_errno(status);
1471 brelse(bh); 1463 brelse(bh);
1472 goto out; 1464 goto out_unlock;
1473 } 1465 }
1474 1466
1475 local += le16_to_cpu(de->rec_len); 1467 local += le16_to_cpu(de->rec_len);
@@ -1504,18 +1496,95 @@ static int ocfs2_recover_orphans(struct ocfs2_super *osb,
1504 1496
1505 mlog(0, "queue orphan %"MLFu64"\n", 1497 mlog(0, "queue orphan %"MLFu64"\n",
1506 OCFS2_I(iter)->ip_blkno); 1498 OCFS2_I(iter)->ip_blkno);
1507 OCFS2_I(iter)->ip_next_orphan = inode; 1499 /* No locking is required for the next_orphan
1508 inode = iter; 1500 * queue as there is only ever a single
1501 * process doing orphan recovery. */
1502 OCFS2_I(iter)->ip_next_orphan = *head;
1503 *head = iter;
1509 } 1504 }
1510 brelse(bh); 1505 brelse(bh);
1511 } 1506 }
1512 mutex_unlock(&orphan_dir_inode->i_mutex);
1513 1507
1508out_unlock:
1514 ocfs2_meta_unlock(orphan_dir_inode, 0); 1509 ocfs2_meta_unlock(orphan_dir_inode, 0);
1515 have_disk_lock = 0; 1510out:
1516 1511 mutex_unlock(&orphan_dir_inode->i_mutex);
1517 iput(orphan_dir_inode); 1512 iput(orphan_dir_inode);
1518 orphan_dir_inode = NULL; 1513 return status;
1514}
1515
1516static int ocfs2_orphan_recovery_can_continue(struct ocfs2_super *osb,
1517 int slot)
1518{
1519 int ret;
1520
1521 spin_lock(&osb->osb_lock);
1522 ret = !osb->osb_orphan_wipes[slot];
1523 spin_unlock(&osb->osb_lock);
1524 return ret;
1525}
1526
1527static void ocfs2_mark_recovering_orphan_dir(struct ocfs2_super *osb,
1528 int slot)
1529{
1530 spin_lock(&osb->osb_lock);
1531 /* Mark ourselves such that new processes in delete_inode()
1532 * know to quit early. */
1533 ocfs2_node_map_set_bit(osb, &osb->osb_recovering_orphan_dirs, slot);
1534 while (osb->osb_orphan_wipes[slot]) {
1535 /* If any processes are already in the middle of an
1536 * orphan wipe on this dir, then we need to wait for
1537 * them. */
1538 spin_unlock(&osb->osb_lock);
1539 wait_event_interruptible(osb->osb_wipe_event,
1540 ocfs2_orphan_recovery_can_continue(osb, slot));
1541 spin_lock(&osb->osb_lock);
1542 }
1543 spin_unlock(&osb->osb_lock);
1544}
1545
1546static void ocfs2_clear_recovering_orphan_dir(struct ocfs2_super *osb,
1547 int slot)
1548{
1549 ocfs2_node_map_clear_bit(osb, &osb->osb_recovering_orphan_dirs, slot);
1550}
1551
1552/*
1553 * Orphan recovery. Each mounted node has it's own orphan dir which we
1554 * must run during recovery. Our strategy here is to build a list of
1555 * the inodes in the orphan dir and iget/iput them. The VFS does
1556 * (most) of the rest of the work.
1557 *
1558 * Orphan recovery can happen at any time, not just mount so we have a
1559 * couple of extra considerations.
1560 *
1561 * - We grab as many inodes as we can under the orphan dir lock -
1562 * doing iget() outside the orphan dir risks getting a reference on
1563 * an invalid inode.
1564 * - We must be sure not to deadlock with other processes on the
1565 * system wanting to run delete_inode(). This can happen when they go
1566 * to lock the orphan dir and the orphan recovery process attempts to
1567 * iget() inside the orphan dir lock. This can be avoided by
1568 * advertising our state to ocfs2_delete_inode().
1569 */
1570static int ocfs2_recover_orphans(struct ocfs2_super *osb,
1571 int slot)
1572{
1573 int ret = 0;
1574 struct inode *inode = NULL;
1575 struct inode *iter;
1576 struct ocfs2_inode_info *oi;
1577
1578 mlog(0, "Recover inodes from orphan dir in slot %d\n", slot);
1579
1580 ocfs2_mark_recovering_orphan_dir(osb, slot);
1581 ret = ocfs2_queue_orphans(osb, slot, &inode);
1582 ocfs2_clear_recovering_orphan_dir(osb, slot);
1583
1584 /* Error here should be noted, but we want to continue with as
1585 * many queued inodes as we've got. */
1586 if (ret)
1587 mlog_errno(ret);
1519 1588
1520 while (inode) { 1589 while (inode) {
1521 oi = OCFS2_I(inode); 1590 oi = OCFS2_I(inode);
@@ -1541,14 +1610,7 @@ static int ocfs2_recover_orphans(struct ocfs2_super *osb,
1541 inode = iter; 1610 inode = iter;
1542 } 1611 }
1543 1612
1544out: 1613 return ret;
1545 if (have_disk_lock)
1546 ocfs2_meta_unlock(orphan_dir_inode, 0);
1547
1548 if (orphan_dir_inode)
1549 iput(orphan_dir_inode);
1550
1551 return status;
1552} 1614}
1553 1615
1554static int ocfs2_wait_on_mount(struct ocfs2_super *osb) 1616static int ocfs2_wait_on_mount(struct ocfs2_super *osb)
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
index 8d8e4779df92..e89de9b6e491 100644
--- a/fs/ocfs2/ocfs2.h
+++ b/fs/ocfs2/ocfs2.h
@@ -174,9 +174,6 @@ enum ocfs2_mount_options
174 OCFS2_MOUNT_NOINTR = 1 << 2, /* Don't catch signals */ 174 OCFS2_MOUNT_NOINTR = 1 << 2, /* Don't catch signals */
175 OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */ 175 OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
176 OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */ 176 OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
177#ifdef OCFS2_ORACORE_WORKAROUNDS
178 OCFS2_MOUNT_COMPAT_OCFS = 1 << 30, /* ocfs1 compatibility mode */
179#endif
180}; 177};
181 178
182#define OCFS2_OSB_SOFT_RO 0x0001 179#define OCFS2_OSB_SOFT_RO 0x0001
@@ -290,6 +287,10 @@ struct ocfs2_super
290 struct inode *osb_tl_inode; 287 struct inode *osb_tl_inode;
291 struct buffer_head *osb_tl_bh; 288 struct buffer_head *osb_tl_bh;
292 struct work_struct osb_truncate_log_wq; 289 struct work_struct osb_truncate_log_wq;
290
291 struct ocfs2_node_map osb_recovering_orphan_dirs;
292 unsigned int *osb_orphan_wipes;
293 wait_queue_head_t osb_wipe_event;
293}; 294};
294 295
295#define OCFS2_SB(sb) ((struct ocfs2_super *)(sb)->s_fs_info) 296#define OCFS2_SB(sb) ((struct ocfs2_super *)(sb)->s_fs_info)
diff --git a/fs/ocfs2/ocfs2_fs.h b/fs/ocfs2/ocfs2_fs.h
index dfb8a5bedfc8..c5b1ac547c15 100644
--- a/fs/ocfs2/ocfs2_fs.h
+++ b/fs/ocfs2/ocfs2_fs.h
@@ -138,7 +138,6 @@
138 138
139/* Journal limits (in bytes) */ 139/* Journal limits (in bytes) */
140#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024) 140#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
141#define OCFS2_MAX_JOURNAL_SIZE (500 * 1024 * 1024)
142 141
143struct ocfs2_system_inode_info { 142struct ocfs2_system_inode_info {
144 char *si_name; 143 char *si_name;
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 046824b6b625..09e1c57a86a0 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -959,7 +959,7 @@ static int ocfs2_initialize_mem_caches(void)
959 ocfs2_lock_cache = kmem_cache_create("ocfs2_lock", 959 ocfs2_lock_cache = kmem_cache_create("ocfs2_lock",
960 sizeof(struct ocfs2_journal_lock), 960 sizeof(struct ocfs2_journal_lock),
961 0, 961 0,
962 SLAB_NO_REAP|SLAB_HWCACHE_ALIGN, 962 SLAB_HWCACHE_ALIGN,
963 NULL, NULL); 963 NULL, NULL);
964 if (!ocfs2_lock_cache) 964 if (!ocfs2_lock_cache)
965 return -ENOMEM; 965 return -ENOMEM;
@@ -1325,6 +1325,16 @@ static int ocfs2_initialize_super(struct super_block *sb,
1325 } 1325 }
1326 mlog(ML_NOTICE, "max_slots for this device: %u\n", osb->max_slots); 1326 mlog(ML_NOTICE, "max_slots for this device: %u\n", osb->max_slots);
1327 1327
1328 init_waitqueue_head(&osb->osb_wipe_event);
1329 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
1330 sizeof(*osb->osb_orphan_wipes),
1331 GFP_KERNEL);
1332 if (!osb->osb_orphan_wipes) {
1333 status = -ENOMEM;
1334 mlog_errno(status);
1335 goto bail;
1336 }
1337
1328 osb->s_feature_compat = 1338 osb->s_feature_compat =
1329 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat); 1339 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
1330 osb->s_feature_ro_compat = 1340 osb->s_feature_ro_compat =
@@ -1638,6 +1648,7 @@ static void ocfs2_delete_osb(struct ocfs2_super *osb)
1638 if (osb->slot_info) 1648 if (osb->slot_info)
1639 ocfs2_free_slot_info(osb->slot_info); 1649 ocfs2_free_slot_info(osb->slot_info);
1640 1650
1651 kfree(osb->osb_orphan_wipes);
1641 /* FIXME 1652 /* FIXME
1642 * This belongs in journal shutdown, but because we have to 1653 * This belongs in journal shutdown, but because we have to
1643 * allocate osb->journal at the start of ocfs2_initalize_osb(), 1654 * allocate osb->journal at the start of ocfs2_initalize_osb(),
diff --git a/fs/partitions/ibm.c b/fs/partitions/ibm.c
index 78010ad60e47..1e4a93835fed 100644
--- a/fs/partitions/ibm.c
+++ b/fs/partitions/ibm.c
@@ -52,6 +52,7 @@ int
52ibm_partition(struct parsed_partitions *state, struct block_device *bdev) 52ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
53{ 53{
54 int blocksize, offset, size; 54 int blocksize, offset, size;
55 loff_t i_size;
55 dasd_information_t *info; 56 dasd_information_t *info;
56 struct hd_geometry *geo; 57 struct hd_geometry *geo;
57 char type[5] = {0,}; 58 char type[5] = {0,};
@@ -63,6 +64,13 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
63 unsigned char *data; 64 unsigned char *data;
64 Sector sect; 65 Sector sect;
65 66
67 blocksize = bdev_hardsect_size(bdev);
68 if (blocksize <= 0)
69 return 0;
70 i_size = i_size_read(bdev->bd_inode);
71 if (i_size == 0)
72 return 0;
73
66 if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL) 74 if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL)
67 goto out_noinfo; 75 goto out_noinfo;
68 if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL) 76 if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL)
@@ -73,9 +81,6 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
73 if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 || 81 if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 ||
74 ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0) 82 ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
75 goto out_noioctl; 83 goto out_noioctl;
76
77 if ((blocksize = bdev_hardsect_size(bdev)) <= 0)
78 goto out_badsect;
79 84
80 /* 85 /*
81 * Get volume label, extract name and type. 86 * Get volume label, extract name and type.
@@ -111,7 +116,7 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
111 } else { 116 } else {
112 printk("CMS1/%8s:", name); 117 printk("CMS1/%8s:", name);
113 offset = (info->label_block + 1); 118 offset = (info->label_block + 1);
114 size = bdev->bd_inode->i_size >> 9; 119 size = i_size >> 9;
115 } 120 }
116 put_partition(state, 1, offset*(blocksize >> 9), 121 put_partition(state, 1, offset*(blocksize >> 9),
117 size-offset*(blocksize >> 9)); 122 size-offset*(blocksize >> 9));
@@ -168,7 +173,7 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
168 else 173 else
169 printk("(nonl)/%8s:", name); 174 printk("(nonl)/%8s:", name);
170 offset = (info->label_block + 1); 175 offset = (info->label_block + 1);
171 size = (bdev->bd_inode->i_size >> 9); 176 size = i_size >> 9;
172 put_partition(state, 1, offset*(blocksize >> 9), 177 put_partition(state, 1, offset*(blocksize >> 9),
173 size-offset*(blocksize >> 9)); 178 size-offset*(blocksize >> 9));
174 } 179 }
@@ -180,7 +185,6 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
180 return 1; 185 return 1;
181 186
182out_readerr: 187out_readerr:
183out_badsect:
184out_noioctl: 188out_noioctl:
185 kfree(label); 189 kfree(label);
186out_nolab: 190out_nolab:
diff --git a/fs/pipe.c b/fs/pipe.c
index d722579df79a..8aada8e426f4 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -605,7 +605,7 @@ struct file_operations rdwr_fifo_fops = {
605 .fasync = pipe_rdwr_fasync, 605 .fasync = pipe_rdwr_fasync,
606}; 606};
607 607
608struct file_operations read_pipe_fops = { 608static struct file_operations read_pipe_fops = {
609 .llseek = no_llseek, 609 .llseek = no_llseek,
610 .read = pipe_read, 610 .read = pipe_read,
611 .readv = pipe_readv, 611 .readv = pipe_readv,
@@ -617,7 +617,7 @@ struct file_operations read_pipe_fops = {
617 .fasync = pipe_read_fasync, 617 .fasync = pipe_read_fasync,
618}; 618};
619 619
620struct file_operations write_pipe_fops = { 620static struct file_operations write_pipe_fops = {
621 .llseek = no_llseek, 621 .llseek = no_llseek,
622 .read = bad_pipe_r, 622 .read = bad_pipe_r,
623 .write = pipe_write, 623 .write = pipe_write,
@@ -629,7 +629,7 @@ struct file_operations write_pipe_fops = {
629 .fasync = pipe_write_fasync, 629 .fasync = pipe_write_fasync,
630}; 630};
631 631
632struct file_operations rdwr_pipe_fops = { 632static struct file_operations rdwr_pipe_fops = {
633 .llseek = no_llseek, 633 .llseek = no_llseek,
634 .read = pipe_read, 634 .read = pipe_read,
635 .readv = pipe_readv, 635 .readv = pipe_readv,
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 0eaad41f4658..91b7c15ab373 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -204,7 +204,6 @@ static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
204{ 204{
205 pte_t *pte, ptent; 205 pte_t *pte, ptent;
206 spinlock_t *ptl; 206 spinlock_t *ptl;
207 unsigned long pfn;
208 struct page *page; 207 struct page *page;
209 208
210 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); 209 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
@@ -214,12 +213,12 @@ static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
214 continue; 213 continue;
215 214
216 mss->resident += PAGE_SIZE; 215 mss->resident += PAGE_SIZE;
217 pfn = pte_pfn(ptent); 216
218 if (!pfn_valid(pfn)) 217 page = vm_normal_page(vma, addr, ptent);
218 if (!page)
219 continue; 219 continue;
220 220
221 page = pfn_to_page(pfn); 221 if (page_mapcount(page) >= 2) {
222 if (page_count(page) >= 2) {
223 if (pte_dirty(ptent)) 222 if (pte_dirty(ptent))
224 mss->shared_dirty += PAGE_SIZE; 223 mss->shared_dirty += PAGE_SIZE;
225 else 224 else
@@ -289,7 +288,7 @@ static int show_smap(struct seq_file *m, void *v)
289 struct mem_size_stats mss; 288 struct mem_size_stats mss;
290 289
291 memset(&mss, 0, sizeof mss); 290 memset(&mss, 0, sizeof mss);
292 if (vma->vm_mm) 291 if (vma->vm_mm && !is_vm_hugetlb_page(vma))
293 smaps_pgd_range(vma, vma->vm_start, vma->vm_end, &mss); 292 smaps_pgd_range(vma, vma->vm_start, vma->vm_end, &mss);
294 return show_map_internal(m, v, &mss); 293 return show_map_internal(m, v, &mss);
295} 294}
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index 3f810acd0bfa..b1ca234068f6 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -87,8 +87,7 @@ static int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)
87 xpages = 1UL << order; 87 xpages = 1UL << order;
88 npages = (newsize + PAGE_SIZE - 1) >> PAGE_SHIFT; 88 npages = (newsize + PAGE_SIZE - 1) >> PAGE_SHIFT;
89 89
90 for (loop = 0; loop < npages; loop++) 90 split_page(pages, order);
91 set_page_count(pages + loop, 1);
92 91
93 /* trim off any pages we don't actually require */ 92 /* trim off any pages we don't actually require */
94 for (loop = npages; loop < xpages; loop++) 93 for (loop = npages; loop < xpages; loop++)
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index c66bd5e4c05c..14bd2246fb6d 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -27,6 +27,7 @@
27#include <linux/fs.h> 27#include <linux/fs.h>
28#include <linux/pagemap.h> 28#include <linux/pagemap.h>
29#include <linux/highmem.h> 29#include <linux/highmem.h>
30#include <linux/time.h>
30#include <linux/init.h> 31#include <linux/init.h>
31#include <linux/string.h> 32#include <linux/string.h>
32#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
@@ -104,6 +105,7 @@ ramfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
104 d_instantiate(dentry, inode); 105 d_instantiate(dentry, inode);
105 dget(dentry); /* Extra count - pin the dentry in core */ 106 dget(dentry); /* Extra count - pin the dentry in core */
106 error = 0; 107 error = 0;
108 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
107 } 109 }
108 return error; 110 return error;
109} 111}
@@ -135,6 +137,7 @@ static int ramfs_symlink(struct inode * dir, struct dentry *dentry, const char *
135 inode->i_gid = dir->i_gid; 137 inode->i_gid = dir->i_gid;
136 d_instantiate(dentry, inode); 138 d_instantiate(dentry, inode);
137 dget(dentry); 139 dget(dentry);
140 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
138 } else 141 } else
139 iput(inode); 142 iput(inode);
140 } 143 }
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index f3473176c83a..be12879bb179 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -1464,13 +1464,11 @@ static ssize_t reiserfs_file_write(struct file *file, /* the file we are going t
1464 partially overwritten pages, if needed. And lock the pages, 1464 partially overwritten pages, if needed. And lock the pages,
1465 so that nobody else can access these until we are done. 1465 so that nobody else can access these until we are done.
1466 We get number of actual blocks needed as a result. */ 1466 We get number of actual blocks needed as a result. */
1467 blocks_to_allocate = 1467 res = reiserfs_prepare_file_region_for_write(inode, pos,
1468 reiserfs_prepare_file_region_for_write(inode, pos, 1468 num_pages,
1469 num_pages, 1469 write_bytes,
1470 write_bytes, 1470 prepared_pages);
1471 prepared_pages); 1471 if (res < 0) {
1472 if (blocks_to_allocate < 0) {
1473 res = blocks_to_allocate;
1474 reiserfs_release_claimed_blocks(inode->i_sb, 1472 reiserfs_release_claimed_blocks(inode->i_sb,
1475 num_pages << 1473 num_pages <<
1476 (PAGE_CACHE_SHIFT - 1474 (PAGE_CACHE_SHIFT -
@@ -1478,6 +1476,8 @@ static ssize_t reiserfs_file_write(struct file *file, /* the file we are going t
1478 break; 1476 break;
1479 } 1477 }
1480 1478
1479 blocks_to_allocate = res;
1480
1481 /* First we correct our estimate of how many blocks we need */ 1481 /* First we correct our estimate of how many blocks we need */
1482 reiserfs_release_claimed_blocks(inode->i_sb, 1482 reiserfs_release_claimed_blocks(inode->i_sb,
1483 (num_pages << 1483 (num_pages <<
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index b33d67bba2fd..d60f6238c66a 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -627,11 +627,6 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
627 reiserfs_write_lock(inode->i_sb); 627 reiserfs_write_lock(inode->i_sb);
628 version = get_inode_item_key_version(inode); 628 version = get_inode_item_key_version(inode);
629 629
630 if (block < 0) {
631 reiserfs_write_unlock(inode->i_sb);
632 return -EIO;
633 }
634
635 if (!file_capable(inode, block)) { 630 if (!file_capable(inode, block)) {
636 reiserfs_write_unlock(inode->i_sb); 631 reiserfs_write_unlock(inode->i_sb);
637 return -EFBIG; 632 return -EFBIG;
@@ -934,12 +929,13 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
934 //pos_in_item * inode->i_sb->s_blocksize, 929 //pos_in_item * inode->i_sb->s_blocksize,
935 TYPE_INDIRECT, 3); // key type is unimportant 930 TYPE_INDIRECT, 3); // key type is unimportant
936 931
932 RFALSE(cpu_key_k_offset(&tmp_key) > cpu_key_k_offset(&key),
933 "green-805: invalid offset");
937 blocks_needed = 934 blocks_needed =
938 1 + 935 1 +
939 ((cpu_key_k_offset(&key) - 936 ((cpu_key_k_offset(&key) -
940 cpu_key_k_offset(&tmp_key)) >> inode->i_sb-> 937 cpu_key_k_offset(&tmp_key)) >> inode->i_sb->
941 s_blocksize_bits); 938 s_blocksize_bits);
942 RFALSE(blocks_needed < 0, "green-805: invalid offset");
943 939
944 if (blocks_needed == 1) { 940 if (blocks_needed == 1) {
945 un = &unf_single; 941 un = &unf_single;
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index b7a179560ab4..5a9d2722fa0a 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -2319,8 +2319,7 @@ static int journal_read(struct super_block *p_s_sb)
2319 return 1; 2319 return 1;
2320 } 2320 }
2321 jh = (struct reiserfs_journal_header *)(journal->j_header_bh->b_data); 2321 jh = (struct reiserfs_journal_header *)(journal->j_header_bh->b_data);
2322 if (le32_to_cpu(jh->j_first_unflushed_offset) >= 0 && 2322 if (le32_to_cpu(jh->j_first_unflushed_offset) <
2323 le32_to_cpu(jh->j_first_unflushed_offset) <
2324 SB_ONDISK_JOURNAL_SIZE(p_s_sb) 2323 SB_ONDISK_JOURNAL_SIZE(p_s_sb)
2325 && le32_to_cpu(jh->j_last_flush_trans_id) > 0) { 2324 && le32_to_cpu(jh->j_last_flush_trans_id) > 0) {
2326 oldest_start = 2325 oldest_start =
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index c8123308e060..284f7852de8b 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -247,7 +247,7 @@ static int linear_search_in_dir_item(struct cpu_key *key,
247 /* mark, that this generation number is used */ 247 /* mark, that this generation number is used */
248 if (de->de_gen_number_bit_string) 248 if (de->de_gen_number_bit_string)
249 set_bit(GET_GENERATION_NUMBER(deh_offset(deh)), 249 set_bit(GET_GENERATION_NUMBER(deh_offset(deh)),
250 (unsigned long *)de->de_gen_number_bit_string); 250 de->de_gen_number_bit_string);
251 251
252 // calculate pointer to name and namelen 252 // calculate pointer to name and namelen
253 de->de_entry_num = i; 253 de->de_entry_num = i;
@@ -431,7 +431,7 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
431 struct reiserfs_de_head *deh; 431 struct reiserfs_de_head *deh;
432 INITIALIZE_PATH(path); 432 INITIALIZE_PATH(path);
433 struct reiserfs_dir_entry de; 433 struct reiserfs_dir_entry de;
434 int bit_string[MAX_GENERATION_NUMBER / (sizeof(int) * 8) + 1]; 434 DECLARE_BITMAP(bit_string, MAX_GENERATION_NUMBER + 1);
435 int gen_number; 435 int gen_number;
436 char small_buf[32 + DEH_SIZE]; /* 48 bytes now and we avoid kmalloc 436 char small_buf[32 + DEH_SIZE]; /* 48 bytes now and we avoid kmalloc
437 if we create file with short name */ 437 if we create file with short name */
@@ -486,7 +486,7 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
486 486
487 /* find the proper place for the new entry */ 487 /* find the proper place for the new entry */
488 memset(bit_string, 0, sizeof(bit_string)); 488 memset(bit_string, 0, sizeof(bit_string));
489 de.de_gen_number_bit_string = (char *)bit_string; 489 de.de_gen_number_bit_string = bit_string;
490 retval = reiserfs_find_entry(dir, name, namelen, &path, &de); 490 retval = reiserfs_find_entry(dir, name, namelen, &path, &de);
491 if (retval != NAME_NOT_FOUND) { 491 if (retval != NAME_NOT_FOUND) {
492 if (buffer != small_buf) 492 if (buffer != small_buf)
@@ -508,7 +508,7 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
508 } 508 }
509 509
510 gen_number = 510 gen_number =
511 find_first_zero_bit((unsigned long *)bit_string, 511 find_first_zero_bit(bit_string,
512 MAX_GENERATION_NUMBER + 1); 512 MAX_GENERATION_NUMBER + 1);
513 if (gen_number > MAX_GENERATION_NUMBER) { 513 if (gen_number > MAX_GENERATION_NUMBER) {
514 /* there is no free generation number */ 514 /* there is no free generation number */
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 49bd219275db..9ee956864445 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -50,6 +50,32 @@ static struct sysfs_dirent * sysfs_new_dirent(struct sysfs_dirent * parent_sd,
50 return sd; 50 return sd;
51} 51}
52 52
53/**
54 *
55 * Return -EEXIST if there is already a sysfs element with the same name for
56 * the same parent.
57 *
58 * called with parent inode's i_mutex held
59 */
60int sysfs_dirent_exist(struct sysfs_dirent *parent_sd,
61 const unsigned char *new)
62{
63 struct sysfs_dirent * sd;
64
65 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
66 if (sd->s_element) {
67 const unsigned char *existing = sysfs_get_name(sd);
68 if (strcmp(existing, new))
69 continue;
70 else
71 return -EEXIST;
72 }
73 }
74
75 return 0;
76}
77
78
53int sysfs_make_dirent(struct sysfs_dirent * parent_sd, struct dentry * dentry, 79int sysfs_make_dirent(struct sysfs_dirent * parent_sd, struct dentry * dentry,
54 void * element, umode_t mode, int type) 80 void * element, umode_t mode, int type)
55{ 81{
@@ -102,7 +128,11 @@ static int create_dir(struct kobject * k, struct dentry * p,
102 mutex_lock(&p->d_inode->i_mutex); 128 mutex_lock(&p->d_inode->i_mutex);
103 *d = lookup_one_len(n, p, strlen(n)); 129 *d = lookup_one_len(n, p, strlen(n));
104 if (!IS_ERR(*d)) { 130 if (!IS_ERR(*d)) {
105 error = sysfs_make_dirent(p->d_fsdata, *d, k, mode, SYSFS_DIR); 131 if (sysfs_dirent_exist(p->d_fsdata, n))
132 error = -EEXIST;
133 else
134 error = sysfs_make_dirent(p->d_fsdata, *d, k, mode,
135 SYSFS_DIR);
106 if (!error) { 136 if (!error) {
107 error = sysfs_create(*d, mode, init_dir); 137 error = sysfs_create(*d, mode, init_dir);
108 if (!error) { 138 if (!error) {
@@ -302,6 +332,7 @@ void sysfs_remove_dir(struct kobject * kobj)
302 * Drop reference from dget() on entrance. 332 * Drop reference from dget() on entrance.
303 */ 333 */
304 dput(dentry); 334 dput(dentry);
335 kobj->dentry = NULL;
305} 336}
306 337
307int sysfs_rename_dir(struct kobject * kobj, const char *new_name) 338int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
@@ -479,7 +510,3 @@ struct file_operations sysfs_dir_operations = {
479 .read = generic_read_dir, 510 .read = generic_read_dir,
480 .readdir = sysfs_readdir, 511 .readdir = sysfs_readdir,
481}; 512};
482
483EXPORT_SYMBOL_GPL(sysfs_create_dir);
484EXPORT_SYMBOL_GPL(sysfs_remove_dir);
485EXPORT_SYMBOL_GPL(sysfs_rename_dir);
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index d0e3d8495165..5e83e7246788 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -301,9 +301,8 @@ static int check_perm(struct inode * inode, struct file * file)
301 /* No error? Great, allocate a buffer for the file, and store it 301 /* No error? Great, allocate a buffer for the file, and store it
302 * it in file->private_data for easy access. 302 * it in file->private_data for easy access.
303 */ 303 */
304 buffer = kmalloc(sizeof(struct sysfs_buffer),GFP_KERNEL); 304 buffer = kzalloc(sizeof(struct sysfs_buffer), GFP_KERNEL);
305 if (buffer) { 305 if (buffer) {
306 memset(buffer,0,sizeof(struct sysfs_buffer));
307 init_MUTEX(&buffer->sem); 306 init_MUTEX(&buffer->sem);
308 buffer->needs_read_fill = 1; 307 buffer->needs_read_fill = 1;
309 buffer->ops = ops; 308 buffer->ops = ops;
@@ -362,10 +361,12 @@ int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type)
362{ 361{
363 struct sysfs_dirent * parent_sd = dir->d_fsdata; 362 struct sysfs_dirent * parent_sd = dir->d_fsdata;
364 umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; 363 umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
365 int error = 0; 364 int error = -EEXIST;
366 365
367 mutex_lock(&dir->d_inode->i_mutex); 366 mutex_lock(&dir->d_inode->i_mutex);
368 error = sysfs_make_dirent(parent_sd, NULL, (void *) attr, mode, type); 367 if (!sysfs_dirent_exist(parent_sd, attr->name))
368 error = sysfs_make_dirent(parent_sd, NULL, (void *)attr,
369 mode, type);
369 mutex_unlock(&dir->d_inode->i_mutex); 370 mutex_unlock(&dir->d_inode->i_mutex);
370 371
371 return error; 372 return error;
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 689f7bcfaf30..4c29ac41ac3e 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -54,11 +54,10 @@ int sysfs_setattr(struct dentry * dentry, struct iattr * iattr)
54 54
55 if (!sd_iattr) { 55 if (!sd_iattr) {
56 /* setting attributes for the first time, allocate now */ 56 /* setting attributes for the first time, allocate now */
57 sd_iattr = kmalloc(sizeof(struct iattr), GFP_KERNEL); 57 sd_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL);
58 if (!sd_iattr) 58 if (!sd_iattr)
59 return -ENOMEM; 59 return -ENOMEM;
60 /* assign default attributes */ 60 /* assign default attributes */
61 memset(sd_iattr, 0, sizeof(struct iattr));
62 sd_iattr->ia_mode = sd->s_mode; 61 sd_iattr->ia_mode = sd->s_mode;
63 sd_iattr->ia_uid = 0; 62 sd_iattr->ia_uid = 0;
64 sd_iattr->ia_gid = 0; 63 sd_iattr->ia_gid = 0;
@@ -227,12 +226,16 @@ void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
227void sysfs_hash_and_remove(struct dentry * dir, const char * name) 226void sysfs_hash_and_remove(struct dentry * dir, const char * name)
228{ 227{
229 struct sysfs_dirent * sd; 228 struct sysfs_dirent * sd;
230 struct sysfs_dirent * parent_sd = dir->d_fsdata; 229 struct sysfs_dirent * parent_sd;
230
231 if (!dir)
232 return;
231 233
232 if (dir->d_inode == NULL) 234 if (dir->d_inode == NULL)
233 /* no inode means this hasn't been made visible yet */ 235 /* no inode means this hasn't been made visible yet */
234 return; 236 return;
235 237
238 parent_sd = dir->d_fsdata;
236 mutex_lock(&dir->d_inode->i_mutex); 239 mutex_lock(&dir->d_inode->i_mutex);
237 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) { 240 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
238 if (!sd->s_element) 241 if (!sd->s_element)
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index e38d6338a20d..d2eac3ceed5f 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -66,6 +66,7 @@ static int sysfs_add_link(struct dentry * parent, const char * name, struct kobj
66 if (!error) 66 if (!error)
67 return 0; 67 return 0;
68 68
69 kobject_put(target);
69 kfree(sl->link_name); 70 kfree(sl->link_name);
70exit2: 71exit2:
71 kfree(sl); 72 kfree(sl);
@@ -82,12 +83,13 @@ exit1:
82int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name) 83int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name)
83{ 84{
84 struct dentry * dentry = kobj->dentry; 85 struct dentry * dentry = kobj->dentry;
85 int error = 0; 86 int error = -EEXIST;
86 87
87 BUG_ON(!kobj || !kobj->dentry || !name); 88 BUG_ON(!kobj || !kobj->dentry || !name);
88 89
89 mutex_lock(&dentry->d_inode->i_mutex); 90 mutex_lock(&dentry->d_inode->i_mutex);
90 error = sysfs_add_link(dentry, name, target); 91 if (!sysfs_dirent_exist(dentry->d_fsdata, name))
92 error = sysfs_add_link(dentry, name, target);
91 mutex_unlock(&dentry->d_inode->i_mutex); 93 mutex_unlock(&dentry->d_inode->i_mutex);
92 return error; 94 return error;
93} 95}
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 3f8953e0e5d0..cf11d5b789d9 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -5,6 +5,7 @@ extern kmem_cache_t *sysfs_dir_cachep;
5extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *); 5extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *);
6extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *)); 6extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *));
7 7
8extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *);
8extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *, 9extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *,
9 umode_t, int); 10 umode_t, int);
10 11
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 395e582ee542..d04cff2273b6 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1045,10 +1045,14 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1045 } 1045 }
1046 1046
1047 inode->i_uid = le32_to_cpu(fe->uid); 1047 inode->i_uid = le32_to_cpu(fe->uid);
1048 if ( inode->i_uid == -1 ) inode->i_uid = UDF_SB(inode->i_sb)->s_uid; 1048 if (inode->i_uid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1049 UDF_FLAG_UID_IGNORE))
1050 inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
1049 1051
1050 inode->i_gid = le32_to_cpu(fe->gid); 1052 inode->i_gid = le32_to_cpu(fe->gid);
1051 if ( inode->i_gid == -1 ) inode->i_gid = UDF_SB(inode->i_sb)->s_gid; 1053 if (inode->i_gid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1054 UDF_FLAG_GID_IGNORE))
1055 inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
1052 1056
1053 inode->i_nlink = le16_to_cpu(fe->fileLinkCount); 1057 inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
1054 if (!inode->i_nlink) 1058 if (!inode->i_nlink)
@@ -1335,10 +1339,14 @@ udf_update_inode(struct inode *inode, int do_sync)
1335 return err; 1339 return err;
1336 } 1340 }
1337 1341
1338 if (inode->i_uid != UDF_SB(inode->i_sb)->s_uid) 1342 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
1343 fe->uid = cpu_to_le32(-1);
1344 else if (inode->i_uid != UDF_SB(inode->i_sb)->s_uid)
1339 fe->uid = cpu_to_le32(inode->i_uid); 1345 fe->uid = cpu_to_le32(inode->i_uid);
1340 1346
1341 if (inode->i_gid != UDF_SB(inode->i_sb)->s_gid) 1347 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
1348 fe->gid = cpu_to_le32(-1);
1349 else if (inode->i_gid != UDF_SB(inode->i_sb)->s_gid)
1342 fe->gid = cpu_to_le32(inode->i_gid); 1350 fe->gid = cpu_to_le32(inode->i_gid);
1343 1351
1344 udfperms = ((inode->i_mode & S_IRWXO) ) | 1352 udfperms = ((inode->i_mode & S_IRWXO) ) |
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 4a6f49adc609..368d8f81fe54 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -269,7 +269,7 @@ enum {
269 Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock, 269 Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
270 Opt_anchor, Opt_volume, Opt_partition, Opt_fileset, 270 Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
271 Opt_rootdir, Opt_utf8, Opt_iocharset, 271 Opt_rootdir, Opt_utf8, Opt_iocharset,
272 Opt_err 272 Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore
273}; 273};
274 274
275static match_table_t tokens = { 275static match_table_t tokens = {
@@ -282,6 +282,10 @@ static match_table_t tokens = {
282 {Opt_adinicb, "adinicb"}, 282 {Opt_adinicb, "adinicb"},
283 {Opt_shortad, "shortad"}, 283 {Opt_shortad, "shortad"},
284 {Opt_longad, "longad"}, 284 {Opt_longad, "longad"},
285 {Opt_uforget, "uid=forget"},
286 {Opt_uignore, "uid=ignore"},
287 {Opt_gforget, "gid=forget"},
288 {Opt_gignore, "gid=ignore"},
285 {Opt_gid, "gid=%u"}, 289 {Opt_gid, "gid=%u"},
286 {Opt_uid, "uid=%u"}, 290 {Opt_uid, "uid=%u"},
287 {Opt_umask, "umask=%o"}, 291 {Opt_umask, "umask=%o"},
@@ -414,6 +418,18 @@ udf_parse_options(char *options, struct udf_options *uopt)
414 uopt->flags |= (1 << UDF_FLAG_NLS_MAP); 418 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
415 break; 419 break;
416#endif 420#endif
421 case Opt_uignore:
422 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
423 break;
424 case Opt_uforget:
425 uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
426 break;
427 case Opt_gignore:
428 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
429 break;
430 case Opt_gforget:
431 uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
432 break;
417 default: 433 default:
418 printk(KERN_ERR "udf: bad mount option \"%s\" " 434 printk(KERN_ERR "udf: bad mount option \"%s\" "
419 "or missing value\n", p); 435 "or missing value\n", p);
diff --git a/fs/udf/udf_sb.h b/fs/udf/udf_sb.h
index 663669810be6..110f8d62616f 100644
--- a/fs/udf/udf_sb.h
+++ b/fs/udf/udf_sb.h
@@ -20,6 +20,10 @@
20#define UDF_FLAG_VARCONV 8 20#define UDF_FLAG_VARCONV 8
21#define UDF_FLAG_NLS_MAP 9 21#define UDF_FLAG_NLS_MAP 9
22#define UDF_FLAG_UTF8 10 22#define UDF_FLAG_UTF8 10
23#define UDF_FLAG_UID_FORGET 11 /* save -1 for uid to disk */
24#define UDF_FLAG_UID_IGNORE 12 /* use sb uid instead of on disk uid */
25#define UDF_FLAG_GID_FORGET 13
26#define UDF_FLAG_GID_IGNORE 14
23 27
24#define UDF_PART_FLAG_UNALLOC_BITMAP 0x0001 28#define UDF_PART_FLAG_UNALLOC_BITMAP 0x0001
25#define UDF_PART_FLAG_UNALLOC_TABLE 0x0002 29#define UDF_PART_FLAG_UNALLOC_TABLE 0x0002
diff --git a/fs/xfs/linux-2.6/xfs_aops.c b/fs/xfs/linux-2.6/xfs_aops.c
index 8f2beec526cf..74d8be87f983 100644
--- a/fs/xfs/linux-2.6/xfs_aops.c
+++ b/fs/xfs/linux-2.6/xfs_aops.c
@@ -540,7 +540,7 @@ xfs_probe_cluster(
540 540
541 /* First sum forwards in this page */ 541 /* First sum forwards in this page */
542 do { 542 do {
543 if (mapped != buffer_mapped(bh)) 543 if (!buffer_uptodate(bh) || (mapped != buffer_mapped(bh)))
544 return total; 544 return total;
545 total += bh->b_size; 545 total += bh->b_size;
546 } while ((bh = bh->b_this_page) != head); 546 } while ((bh = bh->b_this_page) != head);
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index bfb4f2917bb6..8cdfa4151659 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -29,6 +29,7 @@
29#include <linux/blkdev.h> 29#include <linux/blkdev.h>
30#include <linux/hash.h> 30#include <linux/hash.h>
31#include <linux/kthread.h> 31#include <linux/kthread.h>
32#include <linux/migrate.h>
32#include "xfs_linux.h" 33#include "xfs_linux.h"
33 34
34STATIC kmem_zone_t *xfs_buf_zone; 35STATIC kmem_zone_t *xfs_buf_zone;
diff --git a/fs/xfs/quota/xfs_qm.c b/fs/xfs/quota/xfs_qm.c
index 53a00fb217fa..7c0e39dc6189 100644
--- a/fs/xfs/quota/xfs_qm.c
+++ b/fs/xfs/quota/xfs_qm.c
@@ -68,6 +68,9 @@ kmem_zone_t *qm_dqzone;
68kmem_zone_t *qm_dqtrxzone; 68kmem_zone_t *qm_dqtrxzone;
69STATIC kmem_shaker_t xfs_qm_shaker; 69STATIC kmem_shaker_t xfs_qm_shaker;
70 70
71STATIC cred_t xfs_zerocr;
72STATIC xfs_inode_t xfs_zeroino;
73
71STATIC void xfs_qm_list_init(xfs_dqlist_t *, char *, int); 74STATIC void xfs_qm_list_init(xfs_dqlist_t *, char *, int);
72STATIC void xfs_qm_list_destroy(xfs_dqlist_t *); 75STATIC void xfs_qm_list_destroy(xfs_dqlist_t *);
73 76
@@ -1393,8 +1396,6 @@ xfs_qm_qino_alloc(
1393 xfs_trans_t *tp; 1396 xfs_trans_t *tp;
1394 int error; 1397 int error;
1395 unsigned long s; 1398 unsigned long s;
1396 cred_t zerocr;
1397 xfs_inode_t zeroino;
1398 int committed; 1399 int committed;
1399 1400
1400 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QINOCREATE); 1401 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QINOCREATE);
@@ -1406,11 +1407,9 @@ xfs_qm_qino_alloc(
1406 xfs_trans_cancel(tp, 0); 1407 xfs_trans_cancel(tp, 0);
1407 return error; 1408 return error;
1408 } 1409 }
1409 memset(&zerocr, 0, sizeof(zerocr));
1410 memset(&zeroino, 0, sizeof(zeroino));
1411 1410
1412 if ((error = xfs_dir_ialloc(&tp, &zeroino, S_IFREG, 1, 0, 1411 if ((error = xfs_dir_ialloc(&tp, &xfs_zeroino, S_IFREG, 1, 0,
1413 &zerocr, 0, 1, ip, &committed))) { 1412 &xfs_zerocr, 0, 1, ip, &committed))) {
1414 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | 1413 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES |
1415 XFS_TRANS_ABORT); 1414 XFS_TRANS_ABORT);
1416 return error; 1415 return error;
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 06fc061c50fc..5b413946b1c5 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -130,7 +130,8 @@ xfs_growfs_rt_alloc(
130 /* 130 /*
131 * Lock the inode. 131 * Lock the inode.
132 */ 132 */
133 if ((error = xfs_trans_iget(mp, tp, ino, 0, XFS_ILOCK_EXCL, &ip))) 133 if ((error = xfs_trans_iget(mp, tp, ino, 0,
134 XFS_ILOCK_EXCL, &ip)))
134 goto error_exit; 135 goto error_exit;
135 XFS_BMAP_INIT(&flist, &firstblock); 136 XFS_BMAP_INIT(&flist, &firstblock);
136 /* 137 /*
@@ -170,8 +171,8 @@ xfs_growfs_rt_alloc(
170 /* 171 /*
171 * Lock the bitmap inode. 172 * Lock the bitmap inode.
172 */ 173 */
173 if ((error = xfs_trans_iget(mp, tp, ino, 0, XFS_ILOCK_EXCL, 174 if ((error = xfs_trans_iget(mp, tp, ino, 0,
174 &ip))) 175 XFS_ILOCK_EXCL, &ip)))
175 goto error_exit; 176 goto error_exit;
176 /* 177 /*
177 * Get a buffer for the block. 178 * Get a buffer for the block.
@@ -2023,8 +2024,8 @@ xfs_growfs_rt(
2023 /* 2024 /*
2024 * Lock out other callers by grabbing the bitmap inode lock. 2025 * Lock out other callers by grabbing the bitmap inode lock.
2025 */ 2026 */
2026 if ((error = xfs_trans_iget(mp, tp, 0, mp->m_sb.sb_rbmino, 2027 if ((error = xfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0,
2027 XFS_ILOCK_EXCL, &ip))) 2028 XFS_ILOCK_EXCL, &ip)))
2028 goto error_exit; 2029 goto error_exit;
2029 ASSERT(ip == mp->m_rbmip); 2030 ASSERT(ip == mp->m_rbmip);
2030 /* 2031 /*
@@ -2037,8 +2038,8 @@ xfs_growfs_rt(
2037 /* 2038 /*
2038 * Get the summary inode into the transaction. 2039 * Get the summary inode into the transaction.
2039 */ 2040 */
2040 if ((error = xfs_trans_iget(mp, tp, mp->m_sb.sb_rsumino, 2041 if ((error = xfs_trans_iget(mp, tp, mp->m_sb.sb_rsumino, 0,
2041 0, XFS_ILOCK_EXCL, &ip))) 2042 XFS_ILOCK_EXCL, &ip)))
2042 goto error_exit; 2043 goto error_exit;
2043 ASSERT(ip == mp->m_rsumip); 2044 ASSERT(ip == mp->m_rsumip);
2044 /* 2045 /*
@@ -2158,10 +2159,9 @@ xfs_rtallocate_extent(
2158 /* 2159 /*
2159 * Lock out other callers by grabbing the bitmap inode lock. 2160 * Lock out other callers by grabbing the bitmap inode lock.
2160 */ 2161 */
2161 error = xfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0, XFS_ILOCK_EXCL, &ip); 2162 if ((error = xfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0,
2162 if (error) { 2163 XFS_ILOCK_EXCL, &ip)))
2163 return error; 2164 return error;
2164 }
2165 sumbp = NULL; 2165 sumbp = NULL;
2166 /* 2166 /*
2167 * Allocate by size, or near another block, or exactly at some block. 2167 * Allocate by size, or near another block, or exactly at some block.
@@ -2221,10 +2221,9 @@ xfs_rtfree_extent(
2221 /* 2221 /*
2222 * Synchronize by locking the bitmap inode. 2222 * Synchronize by locking the bitmap inode.
2223 */ 2223 */
2224 error = xfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0, XFS_ILOCK_EXCL, &ip); 2224 if ((error = xfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0,
2225 if (error) { 2225 XFS_ILOCK_EXCL, &ip)))
2226 return error; 2226 return error;
2227 }
2228#if defined(__KERNEL__) && defined(DEBUG) 2227#if defined(__KERNEL__) && defined(DEBUG)
2229 /* 2228 /*
2230 * Check to see that this whole range is currently allocated. 2229 * Check to see that this whole range is currently allocated.
@@ -2365,8 +2364,8 @@ xfs_rtpick_extent(
2365 __uint64_t seq; /* sequence number of file creation */ 2364 __uint64_t seq; /* sequence number of file creation */
2366 __uint64_t *seqp; /* pointer to seqno in inode */ 2365 __uint64_t *seqp; /* pointer to seqno in inode */
2367 2366
2368 error = xfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0, XFS_ILOCK_EXCL, &ip); 2367 if ((error = xfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0,
2369 if (error) 2368 XFS_ILOCK_EXCL, &ip)))
2370 return error; 2369 return error;
2371 ASSERT(ip == mp->m_rbmip); 2370 ASSERT(ip == mp->m_rbmip);
2372 seqp = (__uint64_t *)&ip->i_d.di_atime; 2371 seqp = (__uint64_t *)&ip->i_d.di_atime;