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
8 Signed-off-by: Mathieu Segaud <mathieu.segaud@regala.cx>
9 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
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
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,
29 .compat_ioctl = ext3_compat_ioctl,
31 diff --git a/fs/ext3/file.c b/fs/ext3/file.c
32 index acc4913..49798ed 100644
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,
42 .compat_ioctl = ext3_compat_ioctl,
44 diff --git a/fs/ext3/ioctl.c b/fs/ext3/ioctl.c
45 index 023a070..a7c480a 100644
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,
56 - struct ext3_inode_info *ei = EXT3_I(inode);
57 + struct ext3_inode_info *ei;
58 + struct inode *inode;
60 unsigned short rsv_window_size;
65 + inode = filp->f_path.dentry->d_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);
77 case EXT3_IOC_SETFLAGS: {
78 handle_t *handle = NULL;
80 @@ -38,14 +46,20 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
81 unsigned int oldflags;
84 - if (IS_RDONLY(inode))
86 + if (IS_RDONLY(inode)) {
91 - if (!is_owner_or_cap(inode))
93 + if (!is_owner_or_cap(inode)) {
98 - if (get_user(flags, (int __user *) arg))
100 + if (get_user(flags, (int __user *) arg)) {
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);
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);
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);
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);
147 @@ -109,17 +127,20 @@ flags_err:
148 ext3_journal_stop(handle);
150 mutex_unlock(&inode->i_mutex);
156 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL))
157 err = ext3_change_inode_journal_flag(inode, jflag);
158 mutex_unlock(&inode->i_mutex);
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);
168 case EXT3_IOC_SETVERSION:
169 case EXT3_IOC_SETVERSION_OLD: {
171 @@ -127,16 +148,24 @@ flags_err:
175 - if (!is_owner_or_cap(inode))
177 - if (IS_RDONLY(inode))
179 - if (get_user(generation, (int __user *) arg))
181 + if (!is_owner_or_cap(inode)) {
185 + if (IS_RDONLY(inode)) {
189 + if (get_user(generation, (int __user *) arg)) {
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);
201 err = ext3_reserve_inode_write(handle, inode, &iloc);
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);
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);
221 set_current_state(TASK_INTERRUPTIBLE);
222 add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
223 @@ -167,6 +197,7 @@ flags_err:
226 remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
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);
242 case EXT3_IOC_SETRSVSZ: {
244 - if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
246 + if (!test_opt(inode->i_sb, RESERVATION) ||
247 + !S_ISREG(inode->i_mode)) {
252 - if (IS_RDONLY(inode))
254 + if (IS_RDONLY(inode)) {
259 - if (!is_owner_or_cap(inode))
261 + if (!is_owner_or_cap(inode)) {
266 - if (get_user(rsv_window_size, (int __user *)arg))
268 + if (get_user(rsv_window_size, (int __user *)arg)) {
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);
282 case EXT3_IOC_GROUP_EXTEND: {
283 ext3_fsblk_t n_blocks_count;
284 struct super_block *sb = inode->i_sb;
287 - if (!capable(CAP_SYS_RESOURCE))
289 + if (!capable(CAP_SYS_RESOURCE)) {
294 - if (IS_RDONLY(inode))
296 + if (IS_RDONLY(inode)) {
301 - if (get_user(n_blocks_count, (__u32 __user *)arg))
303 + if (get_user(n_blocks_count, (__u32 __user *)arg)) {
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);
316 case EXT3_IOC_GROUP_ADD: {
317 @@ -236,28 +285,40 @@ flags_err:
318 struct super_block *sb = inode->i_sb;
321 - if (!capable(CAP_SYS_RESOURCE))
323 + if (!capable(CAP_SYS_RESOURCE)) {
328 - if (IS_RDONLY(inode))
330 + if (IS_RDONLY(inode)) {
335 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
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);
364 @@ -305,9 +366,7 @@ long ext3_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
369 ret = ext3_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
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);
382 -extern int ext3_ioctl (struct inode *, struct file *, unsigned int,
384 +extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
385 extern long ext3_compat_ioctl (struct file *, unsigned int, unsigned long);
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