aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/super.c')
-rw-r--r--fs/ext4/super.c451
1 files changed, 302 insertions, 149 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e14d22c170d5..26147746c272 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -241,13 +241,14 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
241 if (sb->s_flags & MS_RDONLY) 241 if (sb->s_flags & MS_RDONLY)
242 return ERR_PTR(-EROFS); 242 return ERR_PTR(-EROFS);
243 243
244 vfs_check_frozen(sb, SB_FREEZE_TRANS);
244 /* Special case here: if the journal has aborted behind our 245 /* Special case here: if the journal has aborted behind our
245 * backs (eg. EIO in the commit thread), then we still need to 246 * backs (eg. EIO in the commit thread), then we still need to
246 * take the FS itself readonly cleanly. */ 247 * take the FS itself readonly cleanly. */
247 journal = EXT4_SB(sb)->s_journal; 248 journal = EXT4_SB(sb)->s_journal;
248 if (journal) { 249 if (journal) {
249 if (is_journal_aborted(journal)) { 250 if (is_journal_aborted(journal)) {
250 ext4_abort(sb, __func__, "Detected aborted journal"); 251 ext4_abort(sb, "Detected aborted journal");
251 return ERR_PTR(-EROFS); 252 return ERR_PTR(-EROFS);
252 } 253 }
253 return jbd2_journal_start(journal, nblocks); 254 return jbd2_journal_start(journal, nblocks);
@@ -261,7 +262,7 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
261 * that sync() will call the filesystem's write_super callback if 262 * that sync() will call the filesystem's write_super callback if
262 * appropriate. 263 * appropriate.
263 */ 264 */
264int __ext4_journal_stop(const char *where, handle_t *handle) 265int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
265{ 266{
266 struct super_block *sb; 267 struct super_block *sb;
267 int err; 268 int err;
@@ -278,12 +279,13 @@ int __ext4_journal_stop(const char *where, handle_t *handle)
278 if (!err) 279 if (!err)
279 err = rc; 280 err = rc;
280 if (err) 281 if (err)
281 __ext4_std_error(sb, where, err); 282 __ext4_std_error(sb, where, line, err);
282 return err; 283 return err;
283} 284}
284 285
285void ext4_journal_abort_handle(const char *caller, const char *err_fn, 286void ext4_journal_abort_handle(const char *caller, unsigned int line,
286 struct buffer_head *bh, handle_t *handle, int err) 287 const char *err_fn, struct buffer_head *bh,
288 handle_t *handle, int err)
287{ 289{
288 char nbuf[16]; 290 char nbuf[16];
289 const char *errstr = ext4_decode_error(NULL, err, nbuf); 291 const char *errstr = ext4_decode_error(NULL, err, nbuf);
@@ -299,12 +301,47 @@ void ext4_journal_abort_handle(const char *caller, const char *err_fn,
299 if (is_handle_aborted(handle)) 301 if (is_handle_aborted(handle))
300 return; 302 return;
301 303
302 printk(KERN_ERR "%s: aborting transaction: %s in %s\n", 304 printk(KERN_ERR "%s:%d: aborting transaction: %s in %s\n",
303 caller, errstr, err_fn); 305 caller, line, errstr, err_fn);
304 306
305 jbd2_journal_abort_handle(handle); 307 jbd2_journal_abort_handle(handle);
306} 308}
307 309
310static void __save_error_info(struct super_block *sb, const char *func,
311 unsigned int line)
312{
313 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
314
315 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
316 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
317 es->s_last_error_time = cpu_to_le32(get_seconds());
318 strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
319 es->s_last_error_line = cpu_to_le32(line);
320 if (!es->s_first_error_time) {
321 es->s_first_error_time = es->s_last_error_time;
322 strncpy(es->s_first_error_func, func,
323 sizeof(es->s_first_error_func));
324 es->s_first_error_line = cpu_to_le32(line);
325 es->s_first_error_ino = es->s_last_error_ino;
326 es->s_first_error_block = es->s_last_error_block;
327 }
328 /*
329 * Start the daily error reporting function if it hasn't been
330 * started already
331 */
332 if (!es->s_error_count)
333 mod_timer(&EXT4_SB(sb)->s_err_report, jiffies + 24*60*60*HZ);
334 es->s_error_count = cpu_to_le32(le32_to_cpu(es->s_error_count) + 1);
335}
336
337static void save_error_info(struct super_block *sb, const char *func,
338 unsigned int line)
339{
340 __save_error_info(sb, func, line);
341 ext4_commit_super(sb, 1);
342}
343
344
308/* Deal with the reporting of failure conditions on a filesystem such as 345/* Deal with the reporting of failure conditions on a filesystem such as
309 * inconsistencies detected or read IO failures. 346 * inconsistencies detected or read IO failures.
310 * 347 *
@@ -322,11 +359,6 @@ void ext4_journal_abort_handle(const char *caller, const char *err_fn,
322 359
323static void ext4_handle_error(struct super_block *sb) 360static void ext4_handle_error(struct super_block *sb)
324{ 361{
325 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
326
327 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
328 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
329
330 if (sb->s_flags & MS_RDONLY) 362 if (sb->s_flags & MS_RDONLY)
331 return; 363 return;
332 364
@@ -341,19 +373,19 @@ static void ext4_handle_error(struct super_block *sb)
341 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); 373 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
342 sb->s_flags |= MS_RDONLY; 374 sb->s_flags |= MS_RDONLY;
343 } 375 }
344 ext4_commit_super(sb, 1);
345 if (test_opt(sb, ERRORS_PANIC)) 376 if (test_opt(sb, ERRORS_PANIC))
346 panic("EXT4-fs (device %s): panic forced after error\n", 377 panic("EXT4-fs (device %s): panic forced after error\n",
347 sb->s_id); 378 sb->s_id);
348} 379}
349 380
350void __ext4_error(struct super_block *sb, const char *function, 381void __ext4_error(struct super_block *sb, const char *function,
351 const char *fmt, ...) 382 unsigned int line, const char *fmt, ...)
352{ 383{
353 va_list args; 384 va_list args;
354 385
355 va_start(args, fmt); 386 va_start(args, fmt);
356 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 387 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: ",
388 sb->s_id, function, line, current->comm);
357 vprintk(fmt, args); 389 vprintk(fmt, args);
358 printk("\n"); 390 printk("\n");
359 va_end(args); 391 va_end(args);
@@ -361,14 +393,22 @@ void __ext4_error(struct super_block *sb, const char *function,
361 ext4_handle_error(sb); 393 ext4_handle_error(sb);
362} 394}
363 395
364void ext4_error_inode(const char *function, struct inode *inode, 396void ext4_error_inode(struct inode *inode, const char *function,
397 unsigned int line, ext4_fsblk_t block,
365 const char *fmt, ...) 398 const char *fmt, ...)
366{ 399{
367 va_list args; 400 va_list args;
401 struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
368 402
403 es->s_last_error_ino = cpu_to_le32(inode->i_ino);
404 es->s_last_error_block = cpu_to_le64(block);
405 save_error_info(inode->i_sb, function, line);
369 va_start(args, fmt); 406 va_start(args, fmt);
370 printk(KERN_CRIT "EXT4-fs error (device %s): %s: inode #%lu: (comm %s) ", 407 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: inode #%lu: ",
371 inode->i_sb->s_id, function, inode->i_ino, current->comm); 408 inode->i_sb->s_id, function, line, inode->i_ino);
409 if (block)
410 printk("block %llu: ", block);
411 printk("comm %s: ", current->comm);
372 vprintk(fmt, args); 412 vprintk(fmt, args);
373 printk("\n"); 413 printk("\n");
374 va_end(args); 414 va_end(args);
@@ -376,20 +416,26 @@ void ext4_error_inode(const char *function, struct inode *inode,
376 ext4_handle_error(inode->i_sb); 416 ext4_handle_error(inode->i_sb);
377} 417}
378 418
379void ext4_error_file(const char *function, struct file *file, 419void ext4_error_file(struct file *file, const char *function,
380 const char *fmt, ...) 420 unsigned int line, const char *fmt, ...)
381{ 421{
382 va_list args; 422 va_list args;
423 struct ext4_super_block *es;
383 struct inode *inode = file->f_dentry->d_inode; 424 struct inode *inode = file->f_dentry->d_inode;
384 char pathname[80], *path; 425 char pathname[80], *path;
385 426
427 es = EXT4_SB(inode->i_sb)->s_es;
428 es->s_last_error_ino = cpu_to_le32(inode->i_ino);
429 save_error_info(inode->i_sb, function, line);
386 va_start(args, fmt); 430 va_start(args, fmt);
387 path = d_path(&(file->f_path), pathname, sizeof(pathname)); 431 path = d_path(&(file->f_path), pathname, sizeof(pathname));
388 if (!path) 432 if (!path)
389 path = "(unknown)"; 433 path = "(unknown)";
390 printk(KERN_CRIT 434 printk(KERN_CRIT
391 "EXT4-fs error (device %s): %s: inode #%lu (comm %s path %s): ", 435 "EXT4-fs error (device %s): %s:%d: inode #%lu "
392 inode->i_sb->s_id, function, inode->i_ino, current->comm, path); 436 "(comm %s path %s): ",
437 inode->i_sb->s_id, function, line, inode->i_ino,
438 current->comm, path);
393 vprintk(fmt, args); 439 vprintk(fmt, args);
394 printk("\n"); 440 printk("\n");
395 va_end(args); 441 va_end(args);
@@ -434,7 +480,8 @@ static const char *ext4_decode_error(struct super_block *sb, int errno,
434/* __ext4_std_error decodes expected errors from journaling functions 480/* __ext4_std_error decodes expected errors from journaling functions
435 * automatically and invokes the appropriate error response. */ 481 * automatically and invokes the appropriate error response. */
436 482
437void __ext4_std_error(struct super_block *sb, const char *function, int errno) 483void __ext4_std_error(struct super_block *sb, const char *function,
484 unsigned int line, int errno)
438{ 485{
439 char nbuf[16]; 486 char nbuf[16];
440 const char *errstr; 487 const char *errstr;
@@ -447,8 +494,9 @@ void __ext4_std_error(struct super_block *sb, const char *function, int errno)
447 return; 494 return;
448 495
449 errstr = ext4_decode_error(sb, errno, nbuf); 496 errstr = ext4_decode_error(sb, errno, nbuf);
450 printk(KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n", 497 printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n",
451 sb->s_id, function, errstr); 498 sb->s_id, function, line, errstr);
499 save_error_info(sb, function, line);
452 500
453 ext4_handle_error(sb); 501 ext4_handle_error(sb);
454} 502}
@@ -463,29 +511,29 @@ void __ext4_std_error(struct super_block *sb, const char *function, int errno)
463 * case we take the easy way out and panic immediately. 511 * case we take the easy way out and panic immediately.
464 */ 512 */
465 513
466void ext4_abort(struct super_block *sb, const char *function, 514void __ext4_abort(struct super_block *sb, const char *function,
467 const char *fmt, ...) 515 unsigned int line, const char *fmt, ...)
468{ 516{
469 va_list args; 517 va_list args;
470 518
519 save_error_info(sb, function, line);
471 va_start(args, fmt); 520 va_start(args, fmt);
472 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 521 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: ", sb->s_id,
522 function, line);
473 vprintk(fmt, args); 523 vprintk(fmt, args);
474 printk("\n"); 524 printk("\n");
475 va_end(args); 525 va_end(args);
476 526
527 if ((sb->s_flags & MS_RDONLY) == 0) {
528 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
529 sb->s_flags |= MS_RDONLY;
530 EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
531 if (EXT4_SB(sb)->s_journal)
532 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
533 save_error_info(sb, function, line);
534 }
477 if (test_opt(sb, ERRORS_PANIC)) 535 if (test_opt(sb, ERRORS_PANIC))
478 panic("EXT4-fs panic from previous error\n"); 536 panic("EXT4-fs panic from previous error\n");
479
480 if (sb->s_flags & MS_RDONLY)
481 return;
482
483 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
484 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
485 sb->s_flags |= MS_RDONLY;
486 EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
487 if (EXT4_SB(sb)->s_journal)
488 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
489} 537}
490 538
491void ext4_msg (struct super_block * sb, const char *prefix, 539void ext4_msg (struct super_block * sb, const char *prefix,
@@ -501,38 +549,47 @@ void ext4_msg (struct super_block * sb, const char *prefix,
501} 549}
502 550
503void __ext4_warning(struct super_block *sb, const char *function, 551void __ext4_warning(struct super_block *sb, const char *function,
504 const char *fmt, ...) 552 unsigned int line, const char *fmt, ...)
505{ 553{
506 va_list args; 554 va_list args;
507 555
508 va_start(args, fmt); 556 va_start(args, fmt);
509 printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ", 557 printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: ",
510 sb->s_id, function); 558 sb->s_id, function, line);
511 vprintk(fmt, args); 559 vprintk(fmt, args);
512 printk("\n"); 560 printk("\n");
513 va_end(args); 561 va_end(args);
514} 562}
515 563
516void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp, 564void __ext4_grp_locked_error(const char *function, unsigned int line,
517 const char *function, const char *fmt, ...) 565 struct super_block *sb, ext4_group_t grp,
566 unsigned long ino, ext4_fsblk_t block,
567 const char *fmt, ...)
518__releases(bitlock) 568__releases(bitlock)
519__acquires(bitlock) 569__acquires(bitlock)
520{ 570{
521 va_list args; 571 va_list args;
522 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 572 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
523 573
574 es->s_last_error_ino = cpu_to_le32(ino);
575 es->s_last_error_block = cpu_to_le64(block);
576 __save_error_info(sb, function, line);
524 va_start(args, fmt); 577 va_start(args, fmt);
525 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 578 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u",
579 sb->s_id, function, line, grp);
580 if (ino)
581 printk("inode %lu: ", ino);
582 if (block)
583 printk("block %llu:", (unsigned long long) block);
526 vprintk(fmt, args); 584 vprintk(fmt, args);
527 printk("\n"); 585 printk("\n");
528 va_end(args); 586 va_end(args);
529 587
530 if (test_opt(sb, ERRORS_CONT)) { 588 if (test_opt(sb, ERRORS_CONT)) {
531 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
532 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
533 ext4_commit_super(sb, 0); 589 ext4_commit_super(sb, 0);
534 return; 590 return;
535 } 591 }
592
536 ext4_unlock_group(sb, grp); 593 ext4_unlock_group(sb, grp);
537 ext4_handle_error(sb); 594 ext4_handle_error(sb);
538 /* 595 /*
@@ -645,6 +702,8 @@ static void ext4_put_super(struct super_block *sb)
645 struct ext4_super_block *es = sbi->s_es; 702 struct ext4_super_block *es = sbi->s_es;
646 int i, err; 703 int i, err;
647 704
705 dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
706
648 flush_workqueue(sbi->dio_unwritten_wq); 707 flush_workqueue(sbi->dio_unwritten_wq);
649 destroy_workqueue(sbi->dio_unwritten_wq); 708 destroy_workqueue(sbi->dio_unwritten_wq);
650 709
@@ -657,8 +716,7 @@ static void ext4_put_super(struct super_block *sb)
657 err = jbd2_journal_destroy(sbi->s_journal); 716 err = jbd2_journal_destroy(sbi->s_journal);
658 sbi->s_journal = NULL; 717 sbi->s_journal = NULL;
659 if (err < 0) 718 if (err < 0)
660 ext4_abort(sb, __func__, 719 ext4_abort(sb, "Couldn't clean up the journal");
661 "Couldn't clean up the journal");
662 } 720 }
663 721
664 ext4_release_system_zone(sb); 722 ext4_release_system_zone(sb);
@@ -810,8 +868,10 @@ static void destroy_inodecache(void)
810 kmem_cache_destroy(ext4_inode_cachep); 868 kmem_cache_destroy(ext4_inode_cachep);
811} 869}
812 870
813static void ext4_clear_inode(struct inode *inode) 871void ext4_clear_inode(struct inode *inode)
814{ 872{
873 invalidate_inode_buffers(inode);
874 end_writeback(inode);
815 dquot_drop(inode); 875 dquot_drop(inode);
816 ext4_discard_preallocations(inode); 876 ext4_discard_preallocations(inode);
817 if (EXT4_JOURNAL(inode)) 877 if (EXT4_JOURNAL(inode))
@@ -941,14 +1001,14 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
941 seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0"); 1001 seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0");
942 if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) 1002 if (test_opt(sb, JOURNAL_ASYNC_COMMIT))
943 seq_puts(seq, ",journal_async_commit"); 1003 seq_puts(seq, ",journal_async_commit");
944 if (test_opt(sb, NOBH)) 1004 else if (test_opt(sb, JOURNAL_CHECKSUM))
945 seq_puts(seq, ",nobh"); 1005 seq_puts(seq, ",journal_checksum");
946 if (test_opt(sb, I_VERSION)) 1006 if (test_opt(sb, I_VERSION))
947 seq_puts(seq, ",i_version"); 1007 seq_puts(seq, ",i_version");
948 if (!test_opt(sb, DELALLOC)) 1008 if (!test_opt(sb, DELALLOC) &&
1009 !(def_mount_opts & EXT4_DEFM_NODELALLOC))
949 seq_puts(seq, ",nodelalloc"); 1010 seq_puts(seq, ",nodelalloc");
950 1011
951
952 if (sbi->s_stripe) 1012 if (sbi->s_stripe)
953 seq_printf(seq, ",stripe=%lu", sbi->s_stripe); 1013 seq_printf(seq, ",stripe=%lu", sbi->s_stripe);
954 /* 1014 /*
@@ -972,7 +1032,7 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
972 if (test_opt(sb, NO_AUTO_DA_ALLOC)) 1032 if (test_opt(sb, NO_AUTO_DA_ALLOC))
973 seq_puts(seq, ",noauto_da_alloc"); 1033 seq_puts(seq, ",noauto_da_alloc");
974 1034
975 if (test_opt(sb, DISCARD)) 1035 if (test_opt(sb, DISCARD) && !(def_mount_opts & EXT4_DEFM_DISCARD))
976 seq_puts(seq, ",discard"); 1036 seq_puts(seq, ",discard");
977 1037
978 if (test_opt(sb, NOLOAD)) 1038 if (test_opt(sb, NOLOAD))
@@ -981,6 +1041,10 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
981 if (test_opt(sb, DIOREAD_NOLOCK)) 1041 if (test_opt(sb, DIOREAD_NOLOCK))
982 seq_puts(seq, ",dioread_nolock"); 1042 seq_puts(seq, ",dioread_nolock");
983 1043
1044 if (test_opt(sb, BLOCK_VALIDITY) &&
1045 !(def_mount_opts & EXT4_DEFM_BLOCK_VALIDITY))
1046 seq_puts(seq, ",block_validity");
1047
984 ext4_show_quota_options(seq, sb); 1048 ext4_show_quota_options(seq, sb);
985 1049
986 return 0; 1050 return 0;
@@ -1059,7 +1123,8 @@ static int ext4_release_dquot(struct dquot *dquot);
1059static int ext4_mark_dquot_dirty(struct dquot *dquot); 1123static int ext4_mark_dquot_dirty(struct dquot *dquot);
1060static int ext4_write_info(struct super_block *sb, int type); 1124static int ext4_write_info(struct super_block *sb, int type);
1061static int ext4_quota_on(struct super_block *sb, int type, int format_id, 1125static int ext4_quota_on(struct super_block *sb, int type, int format_id,
1062 char *path, int remount); 1126 char *path);
1127static int ext4_quota_off(struct super_block *sb, int type);
1063static int ext4_quota_on_mount(struct super_block *sb, int type); 1128static int ext4_quota_on_mount(struct super_block *sb, int type);
1064static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, 1129static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
1065 size_t len, loff_t off); 1130 size_t len, loff_t off);
@@ -1081,12 +1146,12 @@ static const struct dquot_operations ext4_quota_operations = {
1081 1146
1082static const struct quotactl_ops ext4_qctl_operations = { 1147static const struct quotactl_ops ext4_qctl_operations = {
1083 .quota_on = ext4_quota_on, 1148 .quota_on = ext4_quota_on,
1084 .quota_off = vfs_quota_off, 1149 .quota_off = ext4_quota_off,
1085 .quota_sync = vfs_quota_sync, 1150 .quota_sync = dquot_quota_sync,
1086 .get_info = vfs_get_dqinfo, 1151 .get_info = dquot_get_dqinfo,
1087 .set_info = vfs_set_dqinfo, 1152 .set_info = dquot_set_dqinfo,
1088 .get_dqblk = vfs_get_dqblk, 1153 .get_dqblk = dquot_get_dqblk,
1089 .set_dqblk = vfs_set_dqblk 1154 .set_dqblk = dquot_set_dqblk
1090}; 1155};
1091#endif 1156#endif
1092 1157
@@ -1095,14 +1160,13 @@ static const struct super_operations ext4_sops = {
1095 .destroy_inode = ext4_destroy_inode, 1160 .destroy_inode = ext4_destroy_inode,
1096 .write_inode = ext4_write_inode, 1161 .write_inode = ext4_write_inode,
1097 .dirty_inode = ext4_dirty_inode, 1162 .dirty_inode = ext4_dirty_inode,
1098 .delete_inode = ext4_delete_inode, 1163 .evict_inode = ext4_evict_inode,
1099 .put_super = ext4_put_super, 1164 .put_super = ext4_put_super,
1100 .sync_fs = ext4_sync_fs, 1165 .sync_fs = ext4_sync_fs,
1101 .freeze_fs = ext4_freeze, 1166 .freeze_fs = ext4_freeze,
1102 .unfreeze_fs = ext4_unfreeze, 1167 .unfreeze_fs = ext4_unfreeze,
1103 .statfs = ext4_statfs, 1168 .statfs = ext4_statfs,
1104 .remount_fs = ext4_remount, 1169 .remount_fs = ext4_remount,
1105 .clear_inode = ext4_clear_inode,
1106 .show_options = ext4_show_options, 1170 .show_options = ext4_show_options,
1107#ifdef CONFIG_QUOTA 1171#ifdef CONFIG_QUOTA
1108 .quota_read = ext4_quota_read, 1172 .quota_read = ext4_quota_read,
@@ -1116,12 +1180,11 @@ static const struct super_operations ext4_nojournal_sops = {
1116 .destroy_inode = ext4_destroy_inode, 1180 .destroy_inode = ext4_destroy_inode,
1117 .write_inode = ext4_write_inode, 1181 .write_inode = ext4_write_inode,
1118 .dirty_inode = ext4_dirty_inode, 1182 .dirty_inode = ext4_dirty_inode,
1119 .delete_inode = ext4_delete_inode, 1183 .evict_inode = ext4_evict_inode,
1120 .write_super = ext4_write_super, 1184 .write_super = ext4_write_super,
1121 .put_super = ext4_put_super, 1185 .put_super = ext4_put_super,
1122 .statfs = ext4_statfs, 1186 .statfs = ext4_statfs,
1123 .remount_fs = ext4_remount, 1187 .remount_fs = ext4_remount,
1124 .clear_inode = ext4_clear_inode,
1125 .show_options = ext4_show_options, 1188 .show_options = ext4_show_options,
1126#ifdef CONFIG_QUOTA 1189#ifdef CONFIG_QUOTA
1127 .quota_read = ext4_quota_read, 1190 .quota_read = ext4_quota_read,
@@ -1619,10 +1682,12 @@ set_qf_format:
1619 *n_blocks_count = option; 1682 *n_blocks_count = option;
1620 break; 1683 break;
1621 case Opt_nobh: 1684 case Opt_nobh:
1622 set_opt(sbi->s_mount_opt, NOBH); 1685 ext4_msg(sb, KERN_WARNING,
1686 "Ignoring deprecated nobh option");
1623 break; 1687 break;
1624 case Opt_bh: 1688 case Opt_bh:
1625 clear_opt(sbi->s_mount_opt, NOBH); 1689 ext4_msg(sb, KERN_WARNING,
1690 "Ignoring deprecated bh option");
1626 break; 1691 break;
1627 case Opt_i_version: 1692 case Opt_i_version:
1628 set_opt(sbi->s_mount_opt, I_VERSION); 1693 set_opt(sbi->s_mount_opt, I_VERSION);
@@ -2051,7 +2116,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
2051 /* Turn quotas off */ 2116 /* Turn quotas off */
2052 for (i = 0; i < MAXQUOTAS; i++) { 2117 for (i = 0; i < MAXQUOTAS; i++) {
2053 if (sb_dqopt(sb)->files[i]) 2118 if (sb_dqopt(sb)->files[i])
2054 vfs_quota_off(sb, i, 0); 2119 dquot_quota_off(sb, i);
2055 } 2120 }
2056#endif 2121#endif
2057 sb->s_flags = s_flags; /* Restore MS_RDONLY status */ 2122 sb->s_flags = s_flags; /* Restore MS_RDONLY status */
@@ -2213,7 +2278,7 @@ static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi)
2213struct ext4_attr { 2278struct ext4_attr {
2214 struct attribute attr; 2279 struct attribute attr;
2215 ssize_t (*show)(struct ext4_attr *, struct ext4_sb_info *, char *); 2280 ssize_t (*show)(struct ext4_attr *, struct ext4_sb_info *, char *);
2216 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *, 2281 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
2217 const char *, size_t); 2282 const char *, size_t);
2218 int offset; 2283 int offset;
2219}; 2284};
@@ -2244,6 +2309,8 @@ static ssize_t session_write_kbytes_show(struct ext4_attr *a,
2244{ 2309{
2245 struct super_block *sb = sbi->s_buddy_cache->i_sb; 2310 struct super_block *sb = sbi->s_buddy_cache->i_sb;
2246 2311
2312 if (!sb->s_bdev->bd_part)
2313 return snprintf(buf, PAGE_SIZE, "0\n");
2247 return snprintf(buf, PAGE_SIZE, "%lu\n", 2314 return snprintf(buf, PAGE_SIZE, "%lu\n",
2248 (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 2315 (part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
2249 sbi->s_sectors_written_start) >> 1); 2316 sbi->s_sectors_written_start) >> 1);
@@ -2254,6 +2321,8 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
2254{ 2321{
2255 struct super_block *sb = sbi->s_buddy_cache->i_sb; 2322 struct super_block *sb = sbi->s_buddy_cache->i_sb;
2256 2323
2324 if (!sb->s_bdev->bd_part)
2325 return snprintf(buf, PAGE_SIZE, "0\n");
2257 return snprintf(buf, PAGE_SIZE, "%llu\n", 2326 return snprintf(buf, PAGE_SIZE, "%llu\n",
2258 (unsigned long long)(sbi->s_kbytes_written + 2327 (unsigned long long)(sbi->s_kbytes_written +
2259 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 2328 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
@@ -2426,10 +2495,58 @@ static int ext4_feature_set_ok(struct super_block *sb, int readonly)
2426 return 1; 2495 return 1;
2427} 2496}
2428 2497
2498/*
2499 * This function is called once a day if we have errors logged
2500 * on the file system
2501 */
2502static void print_daily_error_info(unsigned long arg)
2503{
2504 struct super_block *sb = (struct super_block *) arg;
2505 struct ext4_sb_info *sbi;
2506 struct ext4_super_block *es;
2507
2508 sbi = EXT4_SB(sb);
2509 es = sbi->s_es;
2510
2511 if (es->s_error_count)
2512 ext4_msg(sb, KERN_NOTICE, "error count: %u",
2513 le32_to_cpu(es->s_error_count));
2514 if (es->s_first_error_time) {
2515 printk(KERN_NOTICE "EXT4-fs (%s): initial error at %u: %.*s:%d",
2516 sb->s_id, le32_to_cpu(es->s_first_error_time),
2517 (int) sizeof(es->s_first_error_func),
2518 es->s_first_error_func,
2519 le32_to_cpu(es->s_first_error_line));
2520 if (es->s_first_error_ino)
2521 printk(": inode %u",
2522 le32_to_cpu(es->s_first_error_ino));
2523 if (es->s_first_error_block)
2524 printk(": block %llu", (unsigned long long)
2525 le64_to_cpu(es->s_first_error_block));
2526 printk("\n");
2527 }
2528 if (es->s_last_error_time) {
2529 printk(KERN_NOTICE "EXT4-fs (%s): last error at %u: %.*s:%d",
2530 sb->s_id, le32_to_cpu(es->s_last_error_time),
2531 (int) sizeof(es->s_last_error_func),
2532 es->s_last_error_func,
2533 le32_to_cpu(es->s_last_error_line));
2534 if (es->s_last_error_ino)
2535 printk(": inode %u",
2536 le32_to_cpu(es->s_last_error_ino));
2537 if (es->s_last_error_block)
2538 printk(": block %llu", (unsigned long long)
2539 le64_to_cpu(es->s_last_error_block));
2540 printk("\n");
2541 }
2542 mod_timer(&sbi->s_err_report, jiffies + 24*60*60*HZ); /* Once a day */
2543}
2544
2429static int ext4_fill_super(struct super_block *sb, void *data, int silent) 2545static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2430 __releases(kernel_lock) 2546 __releases(kernel_lock)
2431 __acquires(kernel_lock) 2547 __acquires(kernel_lock)
2432{ 2548{
2549 char *orig_data = kstrdup(data, GFP_KERNEL);
2433 struct buffer_head *bh; 2550 struct buffer_head *bh;
2434 struct ext4_super_block *es = NULL; 2551 struct ext4_super_block *es = NULL;
2435 struct ext4_sb_info *sbi; 2552 struct ext4_sb_info *sbi;
@@ -2442,7 +2559,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2442 struct inode *root; 2559 struct inode *root;
2443 char *cp; 2560 char *cp;
2444 const char *descr; 2561 const char *descr;
2445 int ret = -EINVAL; 2562 int ret = -ENOMEM;
2446 int blocksize; 2563 int blocksize;
2447 unsigned int db_count; 2564 unsigned int db_count;
2448 unsigned int i; 2565 unsigned int i;
@@ -2453,13 +2570,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2453 2570
2454 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 2571 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
2455 if (!sbi) 2572 if (!sbi)
2456 return -ENOMEM; 2573 goto out_free_orig;
2457 2574
2458 sbi->s_blockgroup_lock = 2575 sbi->s_blockgroup_lock =
2459 kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); 2576 kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
2460 if (!sbi->s_blockgroup_lock) { 2577 if (!sbi->s_blockgroup_lock) {
2461 kfree(sbi); 2578 kfree(sbi);
2462 return -ENOMEM; 2579 goto out_free_orig;
2463 } 2580 }
2464 sb->s_fs_info = sbi; 2581 sb->s_fs_info = sbi;
2465 sbi->s_mount_opt = 0; 2582 sbi->s_mount_opt = 0;
@@ -2467,8 +2584,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2467 sbi->s_resgid = EXT4_DEF_RESGID; 2584 sbi->s_resgid = EXT4_DEF_RESGID;
2468 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; 2585 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
2469 sbi->s_sb_block = sb_block; 2586 sbi->s_sb_block = sb_block;
2470 sbi->s_sectors_written_start = part_stat_read(sb->s_bdev->bd_part, 2587 if (sb->s_bdev->bd_part)
2471 sectors[1]); 2588 sbi->s_sectors_written_start =
2589 part_stat_read(sb->s_bdev->bd_part, sectors[1]);
2472 2590
2473 unlock_kernel(); 2591 unlock_kernel();
2474 2592
@@ -2476,6 +2594,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2476 for (cp = sb->s_id; (cp = strchr(cp, '/'));) 2594 for (cp = sb->s_id; (cp = strchr(cp, '/'));)
2477 *cp = '!'; 2595 *cp = '!';
2478 2596
2597 ret = -EINVAL;
2479 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE); 2598 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
2480 if (!blocksize) { 2599 if (!blocksize) {
2481 ext4_msg(sb, KERN_ERR, "unable to set blocksize"); 2600 ext4_msg(sb, KERN_ERR, "unable to set blocksize");
@@ -2540,6 +2659,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2540 set_opt(sbi->s_mount_opt, ERRORS_CONT); 2659 set_opt(sbi->s_mount_opt, ERRORS_CONT);
2541 else 2660 else
2542 set_opt(sbi->s_mount_opt, ERRORS_RO); 2661 set_opt(sbi->s_mount_opt, ERRORS_RO);
2662 if (def_mount_opts & EXT4_DEFM_BLOCK_VALIDITY)
2663 set_opt(sbi->s_mount_opt, BLOCK_VALIDITY);
2664 if (def_mount_opts & EXT4_DEFM_DISCARD)
2665 set_opt(sbi->s_mount_opt, DISCARD);
2543 2666
2544 sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 2667 sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
2545 sbi->s_resgid = le16_to_cpu(es->s_def_resgid); 2668 sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
@@ -2547,15 +2670,23 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2547 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; 2670 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
2548 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; 2671 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
2549 2672
2550 set_opt(sbi->s_mount_opt, BARRIER); 2673 if ((def_mount_opts & EXT4_DEFM_NOBARRIER) == 0)
2674 set_opt(sbi->s_mount_opt, BARRIER);
2551 2675
2552 /* 2676 /*
2553 * enable delayed allocation by default 2677 * enable delayed allocation by default
2554 * Use -o nodelalloc to turn it off 2678 * Use -o nodelalloc to turn it off
2555 */ 2679 */
2556 if (!IS_EXT3_SB(sb)) 2680 if (!IS_EXT3_SB(sb) &&
2681 ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))
2557 set_opt(sbi->s_mount_opt, DELALLOC); 2682 set_opt(sbi->s_mount_opt, DELALLOC);
2558 2683
2684 if (!parse_options((char *) sbi->s_es->s_mount_opts, sb,
2685 &journal_devnum, &journal_ioprio, NULL, 0)) {
2686 ext4_msg(sb, KERN_WARNING,
2687 "failed to parse options in superblock: %s",
2688 sbi->s_es->s_mount_opts);
2689 }
2559 if (!parse_options((char *) data, sb, &journal_devnum, 2690 if (!parse_options((char *) data, sb, &journal_devnum,
2560 &journal_ioprio, NULL, 0)) 2691 &journal_ioprio, NULL, 0))
2561 goto failed_mount; 2692 goto failed_mount;
@@ -2793,24 +2924,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2793 get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 2924 get_random_bytes(&sbi->s_next_generation, sizeof(u32));
2794 spin_lock_init(&sbi->s_next_gen_lock); 2925 spin_lock_init(&sbi->s_next_gen_lock);
2795 2926
2796 err = percpu_counter_init(&sbi->s_freeblocks_counter,
2797 ext4_count_free_blocks(sb));
2798 if (!err) {
2799 err = percpu_counter_init(&sbi->s_freeinodes_counter,
2800 ext4_count_free_inodes(sb));
2801 }
2802 if (!err) {
2803 err = percpu_counter_init(&sbi->s_dirs_counter,
2804 ext4_count_dirs(sb));
2805 }
2806 if (!err) {
2807 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
2808 }
2809 if (err) {
2810 ext4_msg(sb, KERN_ERR, "insufficient memory");
2811 goto failed_mount3;
2812 }
2813
2814 sbi->s_stripe = ext4_get_stripe_size(sbi); 2927 sbi->s_stripe = ext4_get_stripe_size(sbi);
2815 sbi->s_max_writeback_mb_bump = 128; 2928 sbi->s_max_writeback_mb_bump = 128;
2816 2929
@@ -2910,18 +3023,21 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2910 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); 3023 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
2911 3024
2912no_journal: 3025no_journal:
2913 if (test_opt(sb, NOBH)) { 3026 err = percpu_counter_init(&sbi->s_freeblocks_counter,
2914 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) { 3027 ext4_count_free_blocks(sb));
2915 ext4_msg(sb, KERN_WARNING, "Ignoring nobh option - " 3028 if (!err)
2916 "its supported only with writeback mode"); 3029 err = percpu_counter_init(&sbi->s_freeinodes_counter,
2917 clear_opt(sbi->s_mount_opt, NOBH); 3030 ext4_count_free_inodes(sb));
2918 } 3031 if (!err)
2919 if (test_opt(sb, DIOREAD_NOLOCK)) { 3032 err = percpu_counter_init(&sbi->s_dirs_counter,
2920 ext4_msg(sb, KERN_WARNING, "dioread_nolock option is " 3033 ext4_count_dirs(sb));
2921 "not supported with nobh mode"); 3034 if (!err)
2922 goto failed_mount_wq; 3035 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
2923 } 3036 if (err) {
3037 ext4_msg(sb, KERN_ERR, "insufficient memory");
3038 goto failed_mount_wq;
2924 } 3039 }
3040
2925 EXT4_SB(sb)->dio_unwritten_wq = create_workqueue("ext4-dio-unwritten"); 3041 EXT4_SB(sb)->dio_unwritten_wq = create_workqueue("ext4-dio-unwritten");
2926 if (!EXT4_SB(sb)->dio_unwritten_wq) { 3042 if (!EXT4_SB(sb)->dio_unwritten_wq) {
2927 printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n"); 3043 printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n");
@@ -3001,14 +3117,14 @@ no_journal:
3001 err = ext4_setup_system_zone(sb); 3117 err = ext4_setup_system_zone(sb);
3002 if (err) { 3118 if (err) {
3003 ext4_msg(sb, KERN_ERR, "failed to initialize system " 3119 ext4_msg(sb, KERN_ERR, "failed to initialize system "
3004 "zone (%d)\n", err); 3120 "zone (%d)", err);
3005 goto failed_mount4; 3121 goto failed_mount4;
3006 } 3122 }
3007 3123
3008 ext4_ext_init(sb); 3124 ext4_ext_init(sb);
3009 err = ext4_mb_init(sb, needs_recovery); 3125 err = ext4_mb_init(sb, needs_recovery);
3010 if (err) { 3126 if (err) {
3011 ext4_msg(sb, KERN_ERR, "failed to initalize mballoc (%d)", 3127 ext4_msg(sb, KERN_ERR, "failed to initialize mballoc (%d)",
3012 err); 3128 err);
3013 goto failed_mount4; 3129 goto failed_mount4;
3014 } 3130 }
@@ -3040,9 +3156,18 @@ no_journal:
3040 } else 3156 } else
3041 descr = "out journal"; 3157 descr = "out journal";
3042 3158
3043 ext4_msg(sb, KERN_INFO, "mounted filesystem with%s", descr); 3159 ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. "
3160 "Opts: %s%s%s", descr, sbi->s_es->s_mount_opts,
3161 *sbi->s_es->s_mount_opts ? "; " : "", orig_data);
3162
3163 init_timer(&sbi->s_err_report);
3164 sbi->s_err_report.function = print_daily_error_info;
3165 sbi->s_err_report.data = (unsigned long) sb;
3166 if (es->s_error_count)
3167 mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */
3044 3168
3045 lock_kernel(); 3169 lock_kernel();
3170 kfree(orig_data);
3046 return 0; 3171 return 0;
3047 3172
3048cantfind_ext4: 3173cantfind_ext4:
@@ -3059,6 +3184,10 @@ failed_mount_wq:
3059 jbd2_journal_destroy(sbi->s_journal); 3184 jbd2_journal_destroy(sbi->s_journal);
3060 sbi->s_journal = NULL; 3185 sbi->s_journal = NULL;
3061 } 3186 }
3187 percpu_counter_destroy(&sbi->s_freeblocks_counter);
3188 percpu_counter_destroy(&sbi->s_freeinodes_counter);
3189 percpu_counter_destroy(&sbi->s_dirs_counter);
3190 percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
3062failed_mount3: 3191failed_mount3:
3063 if (sbi->s_flex_groups) { 3192 if (sbi->s_flex_groups) {
3064 if (is_vmalloc_addr(sbi->s_flex_groups)) 3193 if (is_vmalloc_addr(sbi->s_flex_groups))
@@ -3066,10 +3195,6 @@ failed_mount3:
3066 else 3195 else
3067 kfree(sbi->s_flex_groups); 3196 kfree(sbi->s_flex_groups);
3068 } 3197 }
3069 percpu_counter_destroy(&sbi->s_freeblocks_counter);
3070 percpu_counter_destroy(&sbi->s_freeinodes_counter);
3071 percpu_counter_destroy(&sbi->s_dirs_counter);
3072 percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
3073failed_mount2: 3198failed_mount2:
3074 for (i = 0; i < db_count; i++) 3199 for (i = 0; i < db_count; i++)
3075 brelse(sbi->s_group_desc[i]); 3200 brelse(sbi->s_group_desc[i]);
@@ -3089,6 +3214,8 @@ out_fail:
3089 kfree(sbi->s_blockgroup_lock); 3214 kfree(sbi->s_blockgroup_lock);
3090 kfree(sbi); 3215 kfree(sbi);
3091 lock_kernel(); 3216 lock_kernel();
3217out_free_orig:
3218 kfree(orig_data);
3092 return ret; 3219 return ret;
3093} 3220}
3094 3221
@@ -3105,7 +3232,7 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
3105 journal->j_min_batch_time = sbi->s_min_batch_time; 3232 journal->j_min_batch_time = sbi->s_min_batch_time;
3106 journal->j_max_batch_time = sbi->s_max_batch_time; 3233 journal->j_max_batch_time = sbi->s_max_batch_time;
3107 3234
3108 spin_lock(&journal->j_state_lock); 3235 write_lock(&journal->j_state_lock);
3109 if (test_opt(sb, BARRIER)) 3236 if (test_opt(sb, BARRIER))
3110 journal->j_flags |= JBD2_BARRIER; 3237 journal->j_flags |= JBD2_BARRIER;
3111 else 3238 else
@@ -3114,7 +3241,7 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
3114 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR; 3241 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
3115 else 3242 else
3116 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR; 3243 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
3117 spin_unlock(&journal->j_state_lock); 3244 write_unlock(&journal->j_state_lock);
3118} 3245}
3119 3246
3120static journal_t *ext4_get_journal(struct super_block *sb, 3247static journal_t *ext4_get_journal(struct super_block *sb,
@@ -3322,8 +3449,17 @@ static int ext4_load_journal(struct super_block *sb,
3322 3449
3323 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) 3450 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
3324 err = jbd2_journal_wipe(journal, !really_read_only); 3451 err = jbd2_journal_wipe(journal, !really_read_only);
3325 if (!err) 3452 if (!err) {
3453 char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
3454 if (save)
3455 memcpy(save, ((char *) es) +
3456 EXT4_S_ERR_START, EXT4_S_ERR_LEN);
3326 err = jbd2_journal_load(journal); 3457 err = jbd2_journal_load(journal);
3458 if (save)
3459 memcpy(((char *) es) + EXT4_S_ERR_START,
3460 save, EXT4_S_ERR_LEN);
3461 kfree(save);
3462 }
3327 3463
3328 if (err) { 3464 if (err) {
3329 ext4_msg(sb, KERN_ERR, "error loading journal"); 3465 ext4_msg(sb, KERN_ERR, "error loading journal");
@@ -3379,10 +3515,14 @@ static int ext4_commit_super(struct super_block *sb, int sync)
3379 */ 3515 */
3380 if (!(sb->s_flags & MS_RDONLY)) 3516 if (!(sb->s_flags & MS_RDONLY))
3381 es->s_wtime = cpu_to_le32(get_seconds()); 3517 es->s_wtime = cpu_to_le32(get_seconds());
3382 es->s_kbytes_written = 3518 if (sb->s_bdev->bd_part)
3383 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + 3519 es->s_kbytes_written =
3520 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written +
3384 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 3521 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
3385 EXT4_SB(sb)->s_sectors_written_start) >> 1)); 3522 EXT4_SB(sb)->s_sectors_written_start) >> 1));
3523 else
3524 es->s_kbytes_written =
3525 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written);
3386 ext4_free_blocks_count_set(es, percpu_counter_sum_positive( 3526 ext4_free_blocks_count_set(es, percpu_counter_sum_positive(
3387 &EXT4_SB(sb)->s_freeblocks_counter)); 3527 &EXT4_SB(sb)->s_freeblocks_counter));
3388 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( 3528 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive(
@@ -3485,8 +3625,10 @@ int ext4_force_commit(struct super_block *sb)
3485 return 0; 3625 return 0;
3486 3626
3487 journal = EXT4_SB(sb)->s_journal; 3627 journal = EXT4_SB(sb)->s_journal;
3488 if (journal) 3628 if (journal) {
3629 vfs_check_frozen(sb, SB_FREEZE_TRANS);
3489 ret = ext4_journal_force_commit(journal); 3630 ret = ext4_journal_force_commit(journal);
3631 }
3490 3632
3491 return ret; 3633 return ret;
3492} 3634}
@@ -3535,18 +3677,16 @@ static int ext4_freeze(struct super_block *sb)
3535 * the journal. 3677 * the journal.
3536 */ 3678 */
3537 error = jbd2_journal_flush(journal); 3679 error = jbd2_journal_flush(journal);
3538 if (error < 0) { 3680 if (error < 0)
3539 out: 3681 goto out;
3540 jbd2_journal_unlock_updates(journal);
3541 return error;
3542 }
3543 3682
3544 /* Journal blocked and flushed, clear needs_recovery flag. */ 3683 /* Journal blocked and flushed, clear needs_recovery flag. */
3545 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3684 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3546 error = ext4_commit_super(sb, 1); 3685 error = ext4_commit_super(sb, 1);
3547 if (error) 3686out:
3548 goto out; 3687 /* we rely on s_frozen to stop further updates */
3549 return 0; 3688 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
3689 return error;
3550} 3690}
3551 3691
3552/* 3692/*
@@ -3563,7 +3703,6 @@ static int ext4_unfreeze(struct super_block *sb)
3563 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3703 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3564 ext4_commit_super(sb, 1); 3704 ext4_commit_super(sb, 1);
3565 unlock_super(sb); 3705 unlock_super(sb);
3566 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
3567 return 0; 3706 return 0;
3568} 3707}
3569 3708
@@ -3574,12 +3713,14 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3574 ext4_fsblk_t n_blocks_count = 0; 3713 ext4_fsblk_t n_blocks_count = 0;
3575 unsigned long old_sb_flags; 3714 unsigned long old_sb_flags;
3576 struct ext4_mount_options old_opts; 3715 struct ext4_mount_options old_opts;
3716 int enable_quota = 0;
3577 ext4_group_t g; 3717 ext4_group_t g;
3578 unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 3718 unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
3579 int err; 3719 int err;
3580#ifdef CONFIG_QUOTA 3720#ifdef CONFIG_QUOTA
3581 int i; 3721 int i;
3582#endif 3722#endif
3723 char *orig_data = kstrdup(data, GFP_KERNEL);
3583 3724
3584 lock_kernel(); 3725 lock_kernel();
3585 3726
@@ -3610,7 +3751,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3610 } 3751 }
3611 3752
3612 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) 3753 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3613 ext4_abort(sb, __func__, "Abort forced by user"); 3754 ext4_abort(sb, "Abort forced by user");
3614 3755
3615 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 3756 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3616 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0); 3757 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
@@ -3630,6 +3771,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3630 } 3771 }
3631 3772
3632 if (*flags & MS_RDONLY) { 3773 if (*flags & MS_RDONLY) {
3774 err = dquot_suspend(sb, -1);
3775 if (err < 0)
3776 goto restore_opts;
3777
3633 /* 3778 /*
3634 * First of all, the unconditional stuff we have to do 3779 * First of all, the unconditional stuff we have to do
3635 * to disable replay of the journal when we next remount 3780 * to disable replay of the journal when we next remount
@@ -3698,6 +3843,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3698 goto restore_opts; 3843 goto restore_opts;
3699 if (!ext4_setup_super(sb, es, 0)) 3844 if (!ext4_setup_super(sb, es, 0))
3700 sb->s_flags &= ~MS_RDONLY; 3845 sb->s_flags &= ~MS_RDONLY;
3846 enable_quota = 1;
3701 } 3847 }
3702 } 3848 }
3703 ext4_setup_system_zone(sb); 3849 ext4_setup_system_zone(sb);
@@ -3713,6 +3859,11 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3713#endif 3859#endif
3714 unlock_super(sb); 3860 unlock_super(sb);
3715 unlock_kernel(); 3861 unlock_kernel();
3862 if (enable_quota)
3863 dquot_resume(sb, -1);
3864
3865 ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data);
3866 kfree(orig_data);
3716 return 0; 3867 return 0;
3717 3868
3718restore_opts: 3869restore_opts:
@@ -3734,6 +3885,7 @@ restore_opts:
3734#endif 3885#endif
3735 unlock_super(sb); 3886 unlock_super(sb);
3736 unlock_kernel(); 3887 unlock_kernel();
3888 kfree(orig_data);
3737 return err; 3889 return err;
3738} 3890}
3739 3891
@@ -3906,24 +4058,21 @@ static int ext4_write_info(struct super_block *sb, int type)
3906 */ 4058 */
3907static int ext4_quota_on_mount(struct super_block *sb, int type) 4059static int ext4_quota_on_mount(struct super_block *sb, int type)
3908{ 4060{
3909 return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type], 4061 return dquot_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
3910 EXT4_SB(sb)->s_jquota_fmt, type); 4062 EXT4_SB(sb)->s_jquota_fmt, type);
3911} 4063}
3912 4064
3913/* 4065/*
3914 * Standard function to be called on quota_on 4066 * Standard function to be called on quota_on
3915 */ 4067 */
3916static int ext4_quota_on(struct super_block *sb, int type, int format_id, 4068static int ext4_quota_on(struct super_block *sb, int type, int format_id,
3917 char *name, int remount) 4069 char *name)
3918{ 4070{
3919 int err; 4071 int err;
3920 struct path path; 4072 struct path path;
3921 4073
3922 if (!test_opt(sb, QUOTA)) 4074 if (!test_opt(sb, QUOTA))
3923 return -EINVAL; 4075 return -EINVAL;
3924 /* When remounting, no checks are needed and in fact, name is NULL */
3925 if (remount)
3926 return vfs_quota_on(sb, type, format_id, name, remount);
3927 4076
3928 err = kern_path(name, LOOKUP_FOLLOW, &path); 4077 err = kern_path(name, LOOKUP_FOLLOW, &path);
3929 if (err) 4078 if (err)
@@ -3962,11 +4111,23 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
3962 } 4111 }
3963 } 4112 }
3964 4113
3965 err = vfs_quota_on_path(sb, type, format_id, &path); 4114 err = dquot_quota_on_path(sb, type, format_id, &path);
3966 path_put(&path); 4115 path_put(&path);
3967 return err; 4116 return err;
3968} 4117}
3969 4118
4119static int ext4_quota_off(struct super_block *sb, int type)
4120{
4121 /* Force all delayed allocation blocks to be allocated */
4122 if (test_opt(sb, DELALLOC)) {
4123 down_read(&sb->s_umount);
4124 sync_filesystem(sb);
4125 up_read(&sb->s_umount);
4126 }
4127
4128 return dquot_quota_off(sb, type);
4129}
4130
3970/* Read data from quotafile - avoid pagecache and such because we cannot afford 4131/* Read data from quotafile - avoid pagecache and such because we cannot afford
3971 * acquiring the locks... As quota files are never truncated and quota code 4132 * acquiring the locks... As quota files are never truncated and quota code
3972 * itself serializes the operations (and noone else should touch the files) 4133 * itself serializes the operations (and noone else should touch the files)
@@ -4016,7 +4177,6 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
4016 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); 4177 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
4017 int err = 0; 4178 int err = 0;
4018 int offset = off & (sb->s_blocksize - 1); 4179 int offset = off & (sb->s_blocksize - 1);
4019 int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL;
4020 struct buffer_head *bh; 4180 struct buffer_head *bh;
4021 handle_t *handle = journal_current_handle(); 4181 handle_t *handle = journal_current_handle();
4022 4182
@@ -4041,24 +4201,16 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
4041 bh = ext4_bread(handle, inode, blk, 1, &err); 4201 bh = ext4_bread(handle, inode, blk, 1, &err);
4042 if (!bh) 4202 if (!bh)
4043 goto out; 4203 goto out;
4044 if (journal_quota) { 4204 err = ext4_journal_get_write_access(handle, bh);
4045 err = ext4_journal_get_write_access(handle, bh); 4205 if (err) {
4046 if (err) { 4206 brelse(bh);
4047 brelse(bh); 4207 goto out;
4048 goto out;
4049 }
4050 } 4208 }
4051 lock_buffer(bh); 4209 lock_buffer(bh);
4052 memcpy(bh->b_data+offset, data, len); 4210 memcpy(bh->b_data+offset, data, len);
4053 flush_dcache_page(bh->b_page); 4211 flush_dcache_page(bh->b_page);
4054 unlock_buffer(bh); 4212 unlock_buffer(bh);
4055 if (journal_quota) 4213 err = ext4_handle_dirty_metadata(handle, NULL, bh);
4056 err = ext4_handle_dirty_metadata(handle, NULL, bh);
4057 else {
4058 /* Always do at least ordered writes for quotas */
4059 err = ext4_jbd2_file_inode(handle, inode);
4060 mark_buffer_dirty(bh);
4061 }
4062 brelse(bh); 4214 brelse(bh);
4063out: 4215out:
4064 if (err) { 4216 if (err) {
@@ -4141,6 +4293,7 @@ static int __init init_ext4_fs(void)
4141{ 4293{
4142 int err; 4294 int err;
4143 4295
4296 ext4_check_flag_values();
4144 err = init_ext4_system_zone(); 4297 err = init_ext4_system_zone();
4145 if (err) 4298 if (err)
4146 return err; 4299 return err;