summaryrefslogtreecommitdiffstats
path: root/fs/ext2/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext2/super.c')
-rw-r--r--fs/ext2/super.c161
1 files changed, 78 insertions, 83 deletions
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 1458706bd2ec..e2b6be03e69b 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -479,10 +479,10 @@ static const match_table_t tokens = {
479 {Opt_err, NULL} 479 {Opt_err, NULL}
480}; 480};
481 481
482static int parse_options(char *options, struct super_block *sb) 482static int parse_options(char *options, struct super_block *sb,
483 struct ext2_mount_options *opts)
483{ 484{
484 char *p; 485 char *p;
485 struct ext2_sb_info *sbi = EXT2_SB(sb);
486 substring_t args[MAX_OPT_ARGS]; 486 substring_t args[MAX_OPT_ARGS];
487 int option; 487 int option;
488 kuid_t uid; 488 kuid_t uid;
@@ -499,16 +499,16 @@ static int parse_options(char *options, struct super_block *sb)
499 token = match_token(p, tokens, args); 499 token = match_token(p, tokens, args);
500 switch (token) { 500 switch (token) {
501 case Opt_bsd_df: 501 case Opt_bsd_df:
502 clear_opt (sbi->s_mount_opt, MINIX_DF); 502 clear_opt (opts->s_mount_opt, MINIX_DF);
503 break; 503 break;
504 case Opt_minix_df: 504 case Opt_minix_df:
505 set_opt (sbi->s_mount_opt, MINIX_DF); 505 set_opt (opts->s_mount_opt, MINIX_DF);
506 break; 506 break;
507 case Opt_grpid: 507 case Opt_grpid:
508 set_opt (sbi->s_mount_opt, GRPID); 508 set_opt (opts->s_mount_opt, GRPID);
509 break; 509 break;
510 case Opt_nogrpid: 510 case Opt_nogrpid:
511 clear_opt (sbi->s_mount_opt, GRPID); 511 clear_opt (opts->s_mount_opt, GRPID);
512 break; 512 break;
513 case Opt_resuid: 513 case Opt_resuid:
514 if (match_int(&args[0], &option)) 514 if (match_int(&args[0], &option))
@@ -519,7 +519,7 @@ static int parse_options(char *options, struct super_block *sb)
519 return 0; 519 return 0;
520 520
521 } 521 }
522 sbi->s_resuid = uid; 522 opts->s_resuid = uid;
523 break; 523 break;
524 case Opt_resgid: 524 case Opt_resgid:
525 if (match_int(&args[0], &option)) 525 if (match_int(&args[0], &option))
@@ -529,51 +529,51 @@ static int parse_options(char *options, struct super_block *sb)
529 ext2_msg(sb, KERN_ERR, "Invalid gid value %d", option); 529 ext2_msg(sb, KERN_ERR, "Invalid gid value %d", option);
530 return 0; 530 return 0;
531 } 531 }
532 sbi->s_resgid = gid; 532 opts->s_resgid = gid;
533 break; 533 break;
534 case Opt_sb: 534 case Opt_sb:
535 /* handled by get_sb_block() instead of here */ 535 /* handled by get_sb_block() instead of here */
536 /* *sb_block = match_int(&args[0]); */ 536 /* *sb_block = match_int(&args[0]); */
537 break; 537 break;
538 case Opt_err_panic: 538 case Opt_err_panic:
539 clear_opt (sbi->s_mount_opt, ERRORS_CONT); 539 clear_opt (opts->s_mount_opt, ERRORS_CONT);
540 clear_opt (sbi->s_mount_opt, ERRORS_RO); 540 clear_opt (opts->s_mount_opt, ERRORS_RO);
541 set_opt (sbi->s_mount_opt, ERRORS_PANIC); 541 set_opt (opts->s_mount_opt, ERRORS_PANIC);
542 break; 542 break;
543 case Opt_err_ro: 543 case Opt_err_ro:
544 clear_opt (sbi->s_mount_opt, ERRORS_CONT); 544 clear_opt (opts->s_mount_opt, ERRORS_CONT);
545 clear_opt (sbi->s_mount_opt, ERRORS_PANIC); 545 clear_opt (opts->s_mount_opt, ERRORS_PANIC);
546 set_opt (sbi->s_mount_opt, ERRORS_RO); 546 set_opt (opts->s_mount_opt, ERRORS_RO);
547 break; 547 break;
548 case Opt_err_cont: 548 case Opt_err_cont:
549 clear_opt (sbi->s_mount_opt, ERRORS_RO); 549 clear_opt (opts->s_mount_opt, ERRORS_RO);
550 clear_opt (sbi->s_mount_opt, ERRORS_PANIC); 550 clear_opt (opts->s_mount_opt, ERRORS_PANIC);
551 set_opt (sbi->s_mount_opt, ERRORS_CONT); 551 set_opt (opts->s_mount_opt, ERRORS_CONT);
552 break; 552 break;
553 case Opt_nouid32: 553 case Opt_nouid32:
554 set_opt (sbi->s_mount_opt, NO_UID32); 554 set_opt (opts->s_mount_opt, NO_UID32);
555 break; 555 break;
556 case Opt_nocheck: 556 case Opt_nocheck:
557 clear_opt (sbi->s_mount_opt, CHECK); 557 clear_opt (opts->s_mount_opt, CHECK);
558 break; 558 break;
559 case Opt_debug: 559 case Opt_debug:
560 set_opt (sbi->s_mount_opt, DEBUG); 560 set_opt (opts->s_mount_opt, DEBUG);
561 break; 561 break;
562 case Opt_oldalloc: 562 case Opt_oldalloc:
563 set_opt (sbi->s_mount_opt, OLDALLOC); 563 set_opt (opts->s_mount_opt, OLDALLOC);
564 break; 564 break;
565 case Opt_orlov: 565 case Opt_orlov:
566 clear_opt (sbi->s_mount_opt, OLDALLOC); 566 clear_opt (opts->s_mount_opt, OLDALLOC);
567 break; 567 break;
568 case Opt_nobh: 568 case Opt_nobh:
569 set_opt (sbi->s_mount_opt, NOBH); 569 set_opt (opts->s_mount_opt, NOBH);
570 break; 570 break;
571#ifdef CONFIG_EXT2_FS_XATTR 571#ifdef CONFIG_EXT2_FS_XATTR
572 case Opt_user_xattr: 572 case Opt_user_xattr:
573 set_opt (sbi->s_mount_opt, XATTR_USER); 573 set_opt (opts->s_mount_opt, XATTR_USER);
574 break; 574 break;
575 case Opt_nouser_xattr: 575 case Opt_nouser_xattr:
576 clear_opt (sbi->s_mount_opt, XATTR_USER); 576 clear_opt (opts->s_mount_opt, XATTR_USER);
577 break; 577 break;
578#else 578#else
579 case Opt_user_xattr: 579 case Opt_user_xattr:
@@ -584,10 +584,10 @@ static int parse_options(char *options, struct super_block *sb)
584#endif 584#endif
585#ifdef CONFIG_EXT2_FS_POSIX_ACL 585#ifdef CONFIG_EXT2_FS_POSIX_ACL
586 case Opt_acl: 586 case Opt_acl:
587 set_opt(sbi->s_mount_opt, POSIX_ACL); 587 set_opt(opts->s_mount_opt, POSIX_ACL);
588 break; 588 break;
589 case Opt_noacl: 589 case Opt_noacl:
590 clear_opt(sbi->s_mount_opt, POSIX_ACL); 590 clear_opt(opts->s_mount_opt, POSIX_ACL);
591 break; 591 break;
592#else 592#else
593 case Opt_acl: 593 case Opt_acl:
@@ -598,13 +598,13 @@ static int parse_options(char *options, struct super_block *sb)
598#endif 598#endif
599 case Opt_xip: 599 case Opt_xip:
600 ext2_msg(sb, KERN_INFO, "use dax instead of xip"); 600 ext2_msg(sb, KERN_INFO, "use dax instead of xip");
601 set_opt(sbi->s_mount_opt, XIP); 601 set_opt(opts->s_mount_opt, XIP);
602 /* Fall through */ 602 /* Fall through */
603 case Opt_dax: 603 case Opt_dax:
604#ifdef CONFIG_FS_DAX 604#ifdef CONFIG_FS_DAX
605 ext2_msg(sb, KERN_WARNING, 605 ext2_msg(sb, KERN_WARNING,
606 "DAX enabled. Warning: EXPERIMENTAL, use at your own risk"); 606 "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
607 set_opt(sbi->s_mount_opt, DAX); 607 set_opt(opts->s_mount_opt, DAX);
608#else 608#else
609 ext2_msg(sb, KERN_INFO, "dax option not supported"); 609 ext2_msg(sb, KERN_INFO, "dax option not supported");
610#endif 610#endif
@@ -613,11 +613,11 @@ static int parse_options(char *options, struct super_block *sb)
613#if defined(CONFIG_QUOTA) 613#if defined(CONFIG_QUOTA)
614 case Opt_quota: 614 case Opt_quota:
615 case Opt_usrquota: 615 case Opt_usrquota:
616 set_opt(sbi->s_mount_opt, USRQUOTA); 616 set_opt(opts->s_mount_opt, USRQUOTA);
617 break; 617 break;
618 618
619 case Opt_grpquota: 619 case Opt_grpquota:
620 set_opt(sbi->s_mount_opt, GRPQUOTA); 620 set_opt(opts->s_mount_opt, GRPQUOTA);
621 break; 621 break;
622#else 622#else
623 case Opt_quota: 623 case Opt_quota:
@@ -629,11 +629,11 @@ static int parse_options(char *options, struct super_block *sb)
629#endif 629#endif
630 630
631 case Opt_reservation: 631 case Opt_reservation:
632 set_opt(sbi->s_mount_opt, RESERVATION); 632 set_opt(opts->s_mount_opt, RESERVATION);
633 ext2_msg(sb, KERN_INFO, "reservations ON"); 633 ext2_msg(sb, KERN_INFO, "reservations ON");
634 break; 634 break;
635 case Opt_noreservation: 635 case Opt_noreservation:
636 clear_opt(sbi->s_mount_opt, RESERVATION); 636 clear_opt(opts->s_mount_opt, RESERVATION);
637 ext2_msg(sb, KERN_INFO, "reservations OFF"); 637 ext2_msg(sb, KERN_INFO, "reservations OFF");
638 break; 638 break;
639 case Opt_ignore: 639 case Opt_ignore:
@@ -830,6 +830,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
830 int i, j; 830 int i, j;
831 __le32 features; 831 __le32 features;
832 int err; 832 int err;
833 struct ext2_mount_options opts;
833 834
834 err = -ENOMEM; 835 err = -ENOMEM;
835 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 836 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
@@ -890,35 +891,39 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
890 /* Set defaults before we parse the mount options */ 891 /* Set defaults before we parse the mount options */
891 def_mount_opts = le32_to_cpu(es->s_default_mount_opts); 892 def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
892 if (def_mount_opts & EXT2_DEFM_DEBUG) 893 if (def_mount_opts & EXT2_DEFM_DEBUG)
893 set_opt(sbi->s_mount_opt, DEBUG); 894 set_opt(opts.s_mount_opt, DEBUG);
894 if (def_mount_opts & EXT2_DEFM_BSDGROUPS) 895 if (def_mount_opts & EXT2_DEFM_BSDGROUPS)
895 set_opt(sbi->s_mount_opt, GRPID); 896 set_opt(opts.s_mount_opt, GRPID);
896 if (def_mount_opts & EXT2_DEFM_UID16) 897 if (def_mount_opts & EXT2_DEFM_UID16)
897 set_opt(sbi->s_mount_opt, NO_UID32); 898 set_opt(opts.s_mount_opt, NO_UID32);
898#ifdef CONFIG_EXT2_FS_XATTR 899#ifdef CONFIG_EXT2_FS_XATTR
899 if (def_mount_opts & EXT2_DEFM_XATTR_USER) 900 if (def_mount_opts & EXT2_DEFM_XATTR_USER)
900 set_opt(sbi->s_mount_opt, XATTR_USER); 901 set_opt(opts.s_mount_opt, XATTR_USER);
901#endif 902#endif
902#ifdef CONFIG_EXT2_FS_POSIX_ACL 903#ifdef CONFIG_EXT2_FS_POSIX_ACL
903 if (def_mount_opts & EXT2_DEFM_ACL) 904 if (def_mount_opts & EXT2_DEFM_ACL)
904 set_opt(sbi->s_mount_opt, POSIX_ACL); 905 set_opt(opts.s_mount_opt, POSIX_ACL);
905#endif 906#endif
906 907
907 if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC) 908 if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC)
908 set_opt(sbi->s_mount_opt, ERRORS_PANIC); 909 set_opt(opts.s_mount_opt, ERRORS_PANIC);
909 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_CONTINUE) 910 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_CONTINUE)
910 set_opt(sbi->s_mount_opt, ERRORS_CONT); 911 set_opt(opts.s_mount_opt, ERRORS_CONT);
911 else 912 else
912 set_opt(sbi->s_mount_opt, ERRORS_RO); 913 set_opt(opts.s_mount_opt, ERRORS_RO);
913 914
914 sbi->s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid)); 915 opts.s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));
915 sbi->s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid)); 916 opts.s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));
916 917
917 set_opt(sbi->s_mount_opt, RESERVATION); 918 set_opt(opts.s_mount_opt, RESERVATION);
918 919
919 if (!parse_options((char *) data, sb)) 920 if (!parse_options((char *) data, sb, &opts))
920 goto failed_mount; 921 goto failed_mount;
921 922
923 sbi->s_mount_opt = opts.s_mount_opt;
924 sbi->s_resuid = opts.s_resuid;
925 sbi->s_resgid = opts.s_resgid;
926
922 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 927 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
923 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? 928 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
924 MS_POSIXACL : 0); 929 MS_POSIXACL : 0);
@@ -1312,46 +1317,36 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
1312{ 1317{
1313 struct ext2_sb_info * sbi = EXT2_SB(sb); 1318 struct ext2_sb_info * sbi = EXT2_SB(sb);
1314 struct ext2_super_block * es; 1319 struct ext2_super_block * es;
1315 struct ext2_mount_options old_opts; 1320 struct ext2_mount_options new_opts;
1316 unsigned long old_sb_flags;
1317 int err; 1321 int err;
1318 1322
1319 sync_filesystem(sb); 1323 sync_filesystem(sb);
1320 spin_lock(&sbi->s_lock);
1321 1324
1322 /* Store the old options */ 1325 spin_lock(&sbi->s_lock);
1323 old_sb_flags = sb->s_flags; 1326 new_opts.s_mount_opt = sbi->s_mount_opt;
1324 old_opts.s_mount_opt = sbi->s_mount_opt; 1327 new_opts.s_resuid = sbi->s_resuid;
1325 old_opts.s_resuid = sbi->s_resuid; 1328 new_opts.s_resgid = sbi->s_resgid;
1326 old_opts.s_resgid = sbi->s_resgid; 1329 spin_unlock(&sbi->s_lock);
1327 1330
1328 /* 1331 /*
1329 * Allow the "check" option to be passed as a remount option. 1332 * Allow the "check" option to be passed as a remount option.
1330 */ 1333 */
1331 if (!parse_options(data, sb)) { 1334 if (!parse_options(data, sb, &new_opts))
1332 err = -EINVAL; 1335 return -EINVAL;
1333 goto restore_opts;
1334 }
1335
1336 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1337 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1338 1336
1337 spin_lock(&sbi->s_lock);
1339 es = sbi->s_es; 1338 es = sbi->s_es;
1340 if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) & EXT2_MOUNT_DAX) { 1339 if ((sbi->s_mount_opt ^ new_opts.s_mount_opt) & EXT2_MOUNT_DAX) {
1341 ext2_msg(sb, KERN_WARNING, "warning: refusing change of " 1340 ext2_msg(sb, KERN_WARNING, "warning: refusing change of "
1342 "dax flag with busy inodes while remounting"); 1341 "dax flag with busy inodes while remounting");
1343 sbi->s_mount_opt ^= EXT2_MOUNT_DAX; 1342 new_opts.s_mount_opt ^= EXT2_MOUNT_DAX;
1344 }
1345 if ((bool)(*flags & MS_RDONLY) == sb_rdonly(sb)) {
1346 spin_unlock(&sbi->s_lock);
1347 return 0;
1348 } 1343 }
1344 if ((bool)(*flags & MS_RDONLY) == sb_rdonly(sb))
1345 goto out_set;
1349 if (*flags & MS_RDONLY) { 1346 if (*flags & MS_RDONLY) {
1350 if (le16_to_cpu(es->s_state) & EXT2_VALID_FS || 1347 if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
1351 !(sbi->s_mount_state & EXT2_VALID_FS)) { 1348 !(sbi->s_mount_state & EXT2_VALID_FS))
1352 spin_unlock(&sbi->s_lock); 1349 goto out_set;
1353 return 0;
1354 }
1355 1350
1356 /* 1351 /*
1357 * OK, we are remounting a valid rw partition rdonly, so set 1352 * OK, we are remounting a valid rw partition rdonly, so set
@@ -1362,22 +1357,20 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
1362 spin_unlock(&sbi->s_lock); 1357 spin_unlock(&sbi->s_lock);
1363 1358
1364 err = dquot_suspend(sb, -1); 1359 err = dquot_suspend(sb, -1);
1365 if (err < 0) { 1360 if (err < 0)
1366 spin_lock(&sbi->s_lock); 1361 return err;
1367 goto restore_opts;
1368 }
1369 1362
1370 ext2_sync_super(sb, es, 1); 1363 ext2_sync_super(sb, es, 1);
1371 } else { 1364 } else {
1372 __le32 ret = EXT2_HAS_RO_COMPAT_FEATURE(sb, 1365 __le32 ret = EXT2_HAS_RO_COMPAT_FEATURE(sb,
1373 ~EXT2_FEATURE_RO_COMPAT_SUPP); 1366 ~EXT2_FEATURE_RO_COMPAT_SUPP);
1374 if (ret) { 1367 if (ret) {
1368 spin_unlock(&sbi->s_lock);
1375 ext2_msg(sb, KERN_WARNING, 1369 ext2_msg(sb, KERN_WARNING,
1376 "warning: couldn't remount RDWR because of " 1370 "warning: couldn't remount RDWR because of "
1377 "unsupported optional features (%x).", 1371 "unsupported optional features (%x).",
1378 le32_to_cpu(ret)); 1372 le32_to_cpu(ret));
1379 err = -EROFS; 1373 return -EROFS;
1380 goto restore_opts;
1381 } 1374 }
1382 /* 1375 /*
1383 * Mounting a RDONLY partition read-write, so reread and 1376 * Mounting a RDONLY partition read-write, so reread and
@@ -1394,14 +1387,16 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
1394 dquot_resume(sb, -1); 1387 dquot_resume(sb, -1);
1395 } 1388 }
1396 1389
1397 return 0; 1390 spin_lock(&sbi->s_lock);
1398restore_opts: 1391out_set:
1399 sbi->s_mount_opt = old_opts.s_mount_opt; 1392 sbi->s_mount_opt = new_opts.s_mount_opt;
1400 sbi->s_resuid = old_opts.s_resuid; 1393 sbi->s_resuid = new_opts.s_resuid;
1401 sbi->s_resgid = old_opts.s_resgid; 1394 sbi->s_resgid = new_opts.s_resgid;
1402 sb->s_flags = old_sb_flags; 1395 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1396 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1403 spin_unlock(&sbi->s_lock); 1397 spin_unlock(&sbi->s_lock);
1404 return err; 1398
1399 return 0;
1405} 1400}
1406 1401
1407static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf) 1402static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)