Commit patches which move ext 2/3/4 to use unlocked_ioctl().
[ext4-patch-queue.git] / ext3-unlocked-ioctl.patch
blob7c2247b176fd967a998718033148e9cd24ceba55
1 Convert ext3_ioctl() to an unlocked_ioctl
3 From: Mathieu Segaud <mathieu.segaud@regala.cx>
5 Change ext3_ioctl() to be an unlocked_ioctl(), explicitly
6 exposing BKL's uses.
8 Signed-off-by: Mathieu Segaud <mathieu.segaud@regala.cx>
9 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
11 ---
12 fs/ext3/dir.c | 2 +-
13 fs/ext3/file.c | 2 +-
14 fs/ext3/ioctl.c | 161 ++++++++++++++++++++++++++++++++---------------
15 include/linux/ext3_fs.h | 3 +-
16 4 files changed, 113 insertions(+), 55 deletions(-)
18 diff --git a/fs/ext3/dir.c b/fs/ext3/dir.c
19 index 8ca3bfd..5ab6b88 100644
20 --- a/fs/ext3/dir.c
21 +++ b/fs/ext3/dir.c
22 @@ -42,7 +42,7 @@ const struct file_operations ext3_dir_operations = {
23 .llseek = generic_file_llseek,
24 .read = generic_read_dir,
25 .readdir = ext3_readdir, /* we take BKL. needed?*/
26 - .ioctl = ext3_ioctl, /* BKL held */
27 + .unlocked_ioctl = ext3_ioctl,
28 #ifdef CONFIG_COMPAT
29 .compat_ioctl = ext3_compat_ioctl,
30 #endif
31 diff --git a/fs/ext3/file.c b/fs/ext3/file.c
32 index acc4913..49798ed 100644
33 --- a/fs/ext3/file.c
34 +++ b/fs/ext3/file.c
35 @@ -112,7 +112,7 @@ const struct file_operations ext3_file_operations = {
36 .write = do_sync_write,
37 .aio_read = generic_file_aio_read,
38 .aio_write = ext3_file_write,
39 - .ioctl = ext3_ioctl,
40 + .unlocked_ioctl = ext3_ioctl,
41 #ifdef CONFIG_COMPAT
42 .compat_ioctl = ext3_compat_ioctl,
43 #endif
44 diff --git a/fs/ext3/ioctl.c b/fs/ext3/ioctl.c
45 index 023a070..a7c480a 100644
46 --- a/fs/ext3/ioctl.c
47 +++ b/fs/ext3/ioctl.c
48 @@ -17,12 +17,19 @@
49 #include <linux/smp_lock.h>
50 #include <asm/uaccess.h>
52 -int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
53 +long ext3_ioctl(struct file *filp, unsigned int cmd,
54 unsigned long arg)
56 - struct ext3_inode_info *ei = EXT3_I(inode);
57 + struct ext3_inode_info *ei;
58 + struct inode *inode;
59 unsigned int flags;
60 unsigned short rsv_window_size;
61 + long retval = 0;
63 + lock_kernel();
65 + inode = filp->f_path.dentry->d_inode;
66 + ei = EXT3_I(inode);
68 ext3_debug ("cmd = %u, arg = %lu\n", cmd, arg);
70 @@ -30,7 +37,8 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
71 case EXT3_IOC_GETFLAGS:
72 ext3_get_inode_flags(ei);
73 flags = ei->i_flags & EXT3_FL_USER_VISIBLE;
74 - return put_user(flags, (int __user *) arg);
75 + retval = put_user(flags, (int __user *) arg);
76 + goto out;
77 case EXT3_IOC_SETFLAGS: {
78 handle_t *handle = NULL;
79 int err;
80 @@ -38,14 +46,20 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
81 unsigned int oldflags;
82 unsigned int jflag;
84 - if (IS_RDONLY(inode))
85 - return -EROFS;
86 + if (IS_RDONLY(inode)) {
87 + retval = -EROFS;
88 + goto out;
89 + }
91 - if (!is_owner_or_cap(inode))
92 - return -EACCES;
93 + if (!is_owner_or_cap(inode)) {
94 + retval = -EACCES;
95 + goto out;
96 + }
98 - if (get_user(flags, (int __user *) arg))
99 - return -EFAULT;
100 + if (get_user(flags, (int __user *) arg)) {
101 + retval = -EFAULT;
102 + goto out;
105 if (!S_ISDIR(inode->i_mode))
106 flags &= ~EXT3_DIRSYNC_FL;
107 @@ -54,7 +68,8 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
108 /* Is it quota file? Do not allow user to mess with it */
109 if (IS_NOQUOTA(inode)) {
110 mutex_unlock(&inode->i_mutex);
111 - return -EPERM;
112 + retval = -EPERM;
113 + goto out;
115 oldflags = ei->i_flags;
117 @@ -70,7 +85,8 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
118 if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
119 if (!capable(CAP_LINUX_IMMUTABLE)) {
120 mutex_unlock(&inode->i_mutex);
121 - return -EPERM;
122 + retval = -EPERM;
123 + goto out;
127 @@ -81,7 +97,8 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
128 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) {
129 if (!capable(CAP_SYS_RESOURCE)) {
130 mutex_unlock(&inode->i_mutex);
131 - return -EPERM;
132 + retval = -EPERM;
133 + goto out;
137 @@ -89,7 +106,8 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
138 handle = ext3_journal_start(inode, 1);
139 if (IS_ERR(handle)) {
140 mutex_unlock(&inode->i_mutex);
141 - return PTR_ERR(handle);
142 + retval = PTR_ERR(handle);
143 + goto out;
145 if (IS_SYNC(inode))
146 handle->h_sync = 1;
147 @@ -109,17 +127,20 @@ flags_err:
148 ext3_journal_stop(handle);
149 if (err) {
150 mutex_unlock(&inode->i_mutex);
151 - return err;
152 + retval = err;
153 + goto out;
156 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL))
157 err = ext3_change_inode_journal_flag(inode, jflag);
158 mutex_unlock(&inode->i_mutex);
159 - return err;
160 + retval = err;
161 + goto out;
163 case EXT3_IOC_GETVERSION:
164 case EXT3_IOC_GETVERSION_OLD:
165 - return put_user(inode->i_generation, (int __user *) arg);
166 + retval = put_user(inode->i_generation, (int __user *) arg);
167 + goto out;
168 case EXT3_IOC_SETVERSION:
169 case EXT3_IOC_SETVERSION_OLD: {
170 handle_t *handle;
171 @@ -127,16 +148,24 @@ flags_err:
172 __u32 generation;
173 int err;
175 - if (!is_owner_or_cap(inode))
176 - return -EPERM;
177 - if (IS_RDONLY(inode))
178 - return -EROFS;
179 - if (get_user(generation, (int __user *) arg))
180 - return -EFAULT;
181 + if (!is_owner_or_cap(inode)) {
182 + retval = -EPERM;
183 + goto out;
185 + if (IS_RDONLY(inode)) {
186 + retval = -EROFS;
187 + goto out;
189 + if (get_user(generation, (int __user *) arg)) {
190 + retval = -EFAULT;
191 + goto out;
194 handle = ext3_journal_start(inode, 1);
195 - if (IS_ERR(handle))
196 - return PTR_ERR(handle);
197 + if (IS_ERR(handle)) {
198 + retval = PTR_ERR(handle);
199 + goto out;
201 err = ext3_reserve_inode_write(handle, inode, &iloc);
202 if (err == 0) {
203 inode->i_ctime = CURRENT_TIME_SEC;
204 @@ -144,7 +173,8 @@ flags_err:
205 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
207 ext3_journal_stop(handle);
208 - return err;
209 + retval = err;
210 + goto out;
212 #ifdef CONFIG_JBD_DEBUG
213 case EXT3_IOC_WAIT_FOR_READONLY:
214 @@ -158,7 +188,7 @@ flags_err:
216 struct super_block *sb = inode->i_sb;
217 DECLARE_WAITQUEUE(wait, current);
218 - int ret = 0;
219 + long ret = 0;
221 set_current_state(TASK_INTERRUPTIBLE);
222 add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
223 @@ -167,6 +197,7 @@ flags_err:
224 ret = 1;
226 remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
227 + unlock_kernel();
228 return ret;
230 #endif
231 @@ -175,22 +206,33 @@ flags_err:
232 && S_ISREG(inode->i_mode)
233 && ei->i_block_alloc_info) {
234 rsv_window_size = ei->i_block_alloc_info->rsv_window_node.rsv_goal_size;
235 - return put_user(rsv_window_size, (int __user *)arg);
236 + retval = put_user(rsv_window_size, (int __user *)arg);
237 + goto out;
239 - return -ENOTTY;
240 + retval = -ENOTTY;
241 + goto out;
242 case EXT3_IOC_SETRSVSZ: {
244 - if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
245 - return -ENOTTY;
246 + if (!test_opt(inode->i_sb, RESERVATION) ||
247 + !S_ISREG(inode->i_mode)) {
248 + retval = -ENOTTY;
249 + goto out;
252 - if (IS_RDONLY(inode))
253 - return -EROFS;
254 + if (IS_RDONLY(inode)) {
255 + retval = -EROFS;
256 + goto out;
259 - if (!is_owner_or_cap(inode))
260 - return -EACCES;
261 + if (!is_owner_or_cap(inode)) {
262 + retval = -EACCES;
263 + goto out;
266 - if (get_user(rsv_window_size, (int __user *)arg))
267 - return -EFAULT;
268 + if (get_user(rsv_window_size, (int __user *)arg)) {
269 + retval = -EFAULT;
270 + goto out;
273 if (rsv_window_size > EXT3_MAX_RESERVE_BLOCKS)
274 rsv_window_size = EXT3_MAX_RESERVE_BLOCKS;
275 @@ -208,27 +250,34 @@ flags_err:
276 rsv->rsv_goal_size = rsv_window_size;
278 mutex_unlock(&ei->truncate_mutex);
279 - return 0;
280 + goto out;
282 case EXT3_IOC_GROUP_EXTEND: {
283 ext3_fsblk_t n_blocks_count;
284 struct super_block *sb = inode->i_sb;
285 int err;
287 - if (!capable(CAP_SYS_RESOURCE))
288 - return -EPERM;
289 + if (!capable(CAP_SYS_RESOURCE)) {
290 + retval = -EPERM;
291 + goto out;
294 - if (IS_RDONLY(inode))
295 - return -EROFS;
296 + if (IS_RDONLY(inode)) {
297 + retval = -EROFS;
298 + goto out;
301 - if (get_user(n_blocks_count, (__u32 __user *)arg))
302 - return -EFAULT;
303 + if (get_user(n_blocks_count, (__u32 __user *)arg)) {
304 + retval = -EFAULT;
305 + goto out;
308 err = ext3_group_extend(sb, EXT3_SB(sb)->s_es, n_blocks_count);
309 journal_lock_updates(EXT3_SB(sb)->s_journal);
310 journal_flush(EXT3_SB(sb)->s_journal);
311 journal_unlock_updates(EXT3_SB(sb)->s_journal);
313 + unlock_kernel();
314 return err;
316 case EXT3_IOC_GROUP_ADD: {
317 @@ -236,28 +285,40 @@ flags_err:
318 struct super_block *sb = inode->i_sb;
319 int err;
321 - if (!capable(CAP_SYS_RESOURCE))
322 - return -EPERM;
323 + if (!capable(CAP_SYS_RESOURCE)) {
324 + retval = -EPERM;
325 + goto out;
328 - if (IS_RDONLY(inode))
329 - return -EROFS;
330 + if (IS_RDONLY(inode)) {
331 + retval = -EROFS;
332 + goto out;
335 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
336 - sizeof(input)))
337 - return -EFAULT;
338 + sizeof(input))) {
339 + retval = -EFAULT;
340 + goto out;
343 err = ext3_group_add(sb, &input);
344 journal_lock_updates(EXT3_SB(sb)->s_journal);
345 journal_flush(EXT3_SB(sb)->s_journal);
346 journal_unlock_updates(EXT3_SB(sb)->s_journal);
348 + unlock_kernel();
349 return err;
353 default:
354 + unlock_kernel();
355 return -ENOTTY;
358 +out:
359 + unlock_kernel();
360 + return retval;
363 #ifdef CONFIG_COMPAT
364 @@ -305,9 +366,7 @@ long ext3_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
365 default:
366 return -ENOIOCTLCMD;
368 - lock_kernel();
369 ret = ext3_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
370 - unlock_kernel();
371 return ret;
373 #endif
374 diff --git a/include/linux/ext3_fs.h b/include/linux/ext3_fs.h
375 index 241c01c..1c925eb 100644
376 --- a/include/linux/ext3_fs.h
377 +++ b/include/linux/ext3_fs.h
378 @@ -838,8 +838,7 @@ extern void ext3_get_inode_flags(struct ext3_inode_info *);
379 extern void ext3_set_aops(struct inode *inode);
381 /* ioctl.c */
382 -extern int ext3_ioctl (struct inode *, struct file *, unsigned int,
383 - unsigned long);
384 +extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
385 extern long ext3_compat_ioctl (struct file *, unsigned int, unsigned long);
387 /* namei.c */
389 1.5.3.8
392 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
393 the body of a message to majordomo@vger.kernel.org
394 More majordomo info at http://vger.kernel.org/majordomo-info.html