aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/ioctl.c
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2012-02-03 17:12:42 -0500
committerJiri Kosina <jkosina@suse.cz>2012-02-03 17:13:05 -0500
commit972c5ae961d6e5103e2b33d935cfa4145fd47140 (patch)
tree350b2a76b979ba8766c09838617df67ff330eca0 /fs/ext4/ioctl.c
parent5196d20305d5e30d871111d3a876cf067dd94255 (diff)
parent7c7ed8ec337bf5f62cc5287a6eb6b2f1b7504c2f (diff)
Merge branch 'master' into for-next
Sync with Linus' tree to be able to apply patch to a newer code (namely drivers/gpu/drm/gma500/psb_intel_lvds.c)
Diffstat (limited to 'fs/ext4/ioctl.c')
-rw-r--r--fs/ext4/ioctl.c92
1 files changed, 79 insertions, 13 deletions
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index d37b3bb2a3b8..6eee25591b81 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -18,6 +18,8 @@
18#include "ext4_jbd2.h" 18#include "ext4_jbd2.h"
19#include "ext4.h" 19#include "ext4.h"
20 20
21#define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
22
21long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 23long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
22{ 24{
23 struct inode *inode = filp->f_dentry->d_inode; 25 struct inode *inode = filp->f_dentry->d_inode;
@@ -158,10 +160,11 @@ flags_out:
158 goto setversion_out; 160 goto setversion_out;
159 } 161 }
160 162
163 mutex_lock(&inode->i_mutex);
161 handle = ext4_journal_start(inode, 1); 164 handle = ext4_journal_start(inode, 1);
162 if (IS_ERR(handle)) { 165 if (IS_ERR(handle)) {
163 err = PTR_ERR(handle); 166 err = PTR_ERR(handle);
164 goto setversion_out; 167 goto unlock_out;
165 } 168 }
166 err = ext4_reserve_inode_write(handle, inode, &iloc); 169 err = ext4_reserve_inode_write(handle, inode, &iloc);
167 if (err == 0) { 170 if (err == 0) {
@@ -170,6 +173,9 @@ flags_out:
170 err = ext4_mark_iloc_dirty(handle, inode, &iloc); 173 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
171 } 174 }
172 ext4_journal_stop(handle); 175 ext4_journal_stop(handle);
176
177unlock_out:
178 mutex_unlock(&inode->i_mutex);
173setversion_out: 179setversion_out:
174 mnt_drop_write_file(filp); 180 mnt_drop_write_file(filp);
175 return err; 181 return err;
@@ -182,19 +188,22 @@ setversion_out:
182 if (err) 188 if (err)
183 return err; 189 return err;
184 190
185 if (get_user(n_blocks_count, (__u32 __user *)arg)) 191 if (get_user(n_blocks_count, (__u32 __user *)arg)) {
186 return -EFAULT; 192 err = -EFAULT;
193 goto group_extend_out;
194 }
187 195
188 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 196 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
189 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) { 197 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
190 ext4_msg(sb, KERN_ERR, 198 ext4_msg(sb, KERN_ERR,
191 "Online resizing not supported with bigalloc"); 199 "Online resizing not supported with bigalloc");
192 return -EOPNOTSUPP; 200 err = -EOPNOTSUPP;
201 goto group_extend_out;
193 } 202 }
194 203
195 err = mnt_want_write_file(filp); 204 err = mnt_want_write_file(filp);
196 if (err) 205 if (err)
197 return err; 206 goto group_extend_out;
198 207
199 err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count); 208 err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count);
200 if (EXT4_SB(sb)->s_journal) { 209 if (EXT4_SB(sb)->s_journal) {
@@ -205,8 +214,8 @@ setversion_out:
205 if (err == 0) 214 if (err == 0)
206 err = err2; 215 err = err2;
207 mnt_drop_write_file(filp); 216 mnt_drop_write_file(filp);
217group_extend_out:
208 ext4_resize_end(sb); 218 ext4_resize_end(sb);
209
210 return err; 219 return err;
211 } 220 }
212 221
@@ -247,8 +256,7 @@ setversion_out:
247 err = ext4_move_extents(filp, donor_filp, me.orig_start, 256 err = ext4_move_extents(filp, donor_filp, me.orig_start,
248 me.donor_start, me.len, &me.moved_len); 257 me.donor_start, me.len, &me.moved_len);
249 mnt_drop_write_file(filp); 258 mnt_drop_write_file(filp);
250 if (me.moved_len > 0) 259 mnt_drop_write(filp->f_path.mnt);
251 file_remove_suid(donor_filp);
252 260
253 if (copy_to_user((struct move_extent __user *)arg, 261 if (copy_to_user((struct move_extent __user *)arg,
254 &me, sizeof(me))) 262 &me, sizeof(me)))
@@ -267,19 +275,22 @@ mext_out:
267 return err; 275 return err;
268 276
269 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg, 277 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
270 sizeof(input))) 278 sizeof(input))) {
271 return -EFAULT; 279 err = -EFAULT;
280 goto group_add_out;
281 }
272 282
273 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 283 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
274 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) { 284 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
275 ext4_msg(sb, KERN_ERR, 285 ext4_msg(sb, KERN_ERR,
276 "Online resizing not supported with bigalloc"); 286 "Online resizing not supported with bigalloc");
277 return -EOPNOTSUPP; 287 err = -EOPNOTSUPP;
288 goto group_add_out;
278 } 289 }
279 290
280 err = mnt_want_write_file(filp); 291 err = mnt_want_write_file(filp);
281 if (err) 292 if (err)
282 return err; 293 goto group_add_out;
283 294
284 err = ext4_group_add(sb, &input); 295 err = ext4_group_add(sb, &input);
285 if (EXT4_SB(sb)->s_journal) { 296 if (EXT4_SB(sb)->s_journal) {
@@ -290,8 +301,8 @@ mext_out:
290 if (err == 0) 301 if (err == 0)
291 err = err2; 302 err = err2;
292 mnt_drop_write_file(filp); 303 mnt_drop_write_file(filp);
304group_add_out:
293 ext4_resize_end(sb); 305 ext4_resize_end(sb);
294
295 return err; 306 return err;
296 } 307 }
297 308
@@ -331,6 +342,60 @@ mext_out:
331 return err; 342 return err;
332 } 343 }
333 344
345 case EXT4_IOC_RESIZE_FS: {
346 ext4_fsblk_t n_blocks_count;
347 struct super_block *sb = inode->i_sb;
348 int err = 0, err2 = 0;
349
350 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
351 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
352 ext4_msg(sb, KERN_ERR,
353 "Online resizing not (yet) supported with bigalloc");
354 return -EOPNOTSUPP;
355 }
356
357 if (EXT4_HAS_INCOMPAT_FEATURE(sb,
358 EXT4_FEATURE_INCOMPAT_META_BG)) {
359 ext4_msg(sb, KERN_ERR,
360 "Online resizing not (yet) supported with meta_bg");
361 return -EOPNOTSUPP;
362 }
363
364 if (copy_from_user(&n_blocks_count, (__u64 __user *)arg,
365 sizeof(__u64))) {
366 return -EFAULT;
367 }
368
369 if (n_blocks_count > MAX_32_NUM &&
370 !EXT4_HAS_INCOMPAT_FEATURE(sb,
371 EXT4_FEATURE_INCOMPAT_64BIT)) {
372 ext4_msg(sb, KERN_ERR,
373 "File system only supports 32-bit block numbers");
374 return -EOPNOTSUPP;
375 }
376
377 err = ext4_resize_begin(sb);
378 if (err)
379 return err;
380
381 err = mnt_want_write(filp->f_path.mnt);
382 if (err)
383 goto resizefs_out;
384
385 err = ext4_resize_fs(sb, n_blocks_count);
386 if (EXT4_SB(sb)->s_journal) {
387 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
388 err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
389 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
390 }
391 if (err == 0)
392 err = err2;
393 mnt_drop_write(filp->f_path.mnt);
394resizefs_out:
395 ext4_resize_end(sb);
396 return err;
397 }
398
334 case FITRIM: 399 case FITRIM:
335 { 400 {
336 struct request_queue *q = bdev_get_queue(sb->s_bdev); 401 struct request_queue *q = bdev_get_queue(sb->s_bdev);
@@ -429,6 +494,7 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
429 } 494 }
430 case EXT4_IOC_MOVE_EXT: 495 case EXT4_IOC_MOVE_EXT:
431 case FITRIM: 496 case FITRIM:
497 case EXT4_IOC_RESIZE_FS:
432 break; 498 break;
433 default: 499 default:
434 return -ENOIOCTLCMD; 500 return -ENOIOCTLCMD;