aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2013-02-02 23:09:36 -0500
committerTheodore Ts'o <tytso@mit.edu>2013-02-02 23:09:36 -0500
commit5f3633e36b8a67c02d2d10cde5f056f9e5da49a1 (patch)
treeaf1fbe48f0fdbee7cf70ccd5a523893e38a76783
parent0efb3b23002fea3ed996597783939617e50523ec (diff)
ext4: make mount option parsing loop more logical
The loop looking for correct mount option entry is more logical if it is written rewritten as an empty loop looking for correct option entry and then code handling the option. It also saves one level of indentation for a lot of code so we can join a couple of split lines. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--fs/ext4/super.c230
1 files changed, 113 insertions, 117 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 69e5e70cfdee..9b36c11baad9 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1508,8 +1508,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
1508 case Opt_sb: 1508 case Opt_sb:
1509 return 1; /* handled by get_sb_block() */ 1509 return 1; /* handled by get_sb_block() */
1510 case Opt_removed: 1510 case Opt_removed:
1511 ext4_msg(sb, KERN_WARNING, 1511 ext4_msg(sb, KERN_WARNING, "Ignoring removed %s option", opt);
1512 "Ignoring removed %s option", opt);
1513 return 1; 1512 return 1;
1514 case Opt_abort: 1513 case Opt_abort:
1515 sbi->s_mount_flags |= EXT4_MF_FS_ABORTED; 1514 sbi->s_mount_flags |= EXT4_MF_FS_ABORTED;
@@ -1519,132 +1518,129 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
1519 return 1; 1518 return 1;
1520 } 1519 }
1521 1520
1522 for (m = ext4_mount_opts; m->token != Opt_err; m++) { 1521 for (m = ext4_mount_opts; m->token != Opt_err; m++)
1523 if (token != m->token) 1522 if (token == m->token)
1524 continue; 1523 break;
1525 if (args->from && match_int(args, &arg)) 1524
1525 if (m->token == Opt_err) {
1526 ext4_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" "
1527 "or missing value", opt);
1528 return -1;
1529 }
1530
1531 if (args->from && match_int(args, &arg))
1532 return -1;
1533 if (args->from && (m->flags & MOPT_GTE0) && (arg < 0))
1534 return -1;
1535 if (m->flags & MOPT_EXPLICIT)
1536 set_opt2(sb, EXPLICIT_DELALLOC);
1537 if (m->flags & MOPT_CLEAR_ERR)
1538 clear_opt(sb, ERRORS_MASK);
1539 if (token == Opt_noquota && sb_any_quota_loaded(sb)) {
1540 ext4_msg(sb, KERN_ERR, "Cannot change quota "
1541 "options when quota turned on");
1542 return -1;
1543 }
1544
1545 if (m->flags & MOPT_NOSUPPORT) {
1546 ext4_msg(sb, KERN_ERR, "%s option not supported", opt);
1547 } else if (token == Opt_commit) {
1548 if (arg == 0)
1549 arg = JBD2_DEFAULT_MAX_COMMIT_AGE;
1550 sbi->s_commit_interval = HZ * arg;
1551 } else if (token == Opt_max_batch_time) {
1552 if (arg == 0)
1553 arg = EXT4_DEF_MAX_BATCH_TIME;
1554 sbi->s_max_batch_time = arg;
1555 } else if (token == Opt_min_batch_time) {
1556 sbi->s_min_batch_time = arg;
1557 } else if (token == Opt_inode_readahead_blks) {
1558 if (arg > (1 << 30))
1526 return -1; 1559 return -1;
1527 if (args->from && (m->flags & MOPT_GTE0) && (arg < 0)) 1560 if (arg && !is_power_of_2(arg)) {
1561 ext4_msg(sb, KERN_ERR, "EXT4-fs: inode_readahead_blks"
1562 " must be a power of 2");
1528 return -1; 1563 return -1;
1529 if (m->flags & MOPT_EXPLICIT) 1564 }
1530 set_opt2(sb, EXPLICIT_DELALLOC); 1565 sbi->s_inode_readahead_blks = arg;
1531 if (m->flags & MOPT_CLEAR_ERR) 1566 } else if (token == Opt_init_itable) {
1532 clear_opt(sb, ERRORS_MASK); 1567 set_opt(sb, INIT_INODE_TABLE);
1533 if (token == Opt_noquota && sb_any_quota_loaded(sb)) { 1568 if (!args->from)
1534 ext4_msg(sb, KERN_ERR, "Cannot change quota " 1569 arg = EXT4_DEF_LI_WAIT_MULT;
1535 "options when quota turned on"); 1570 sbi->s_li_wait_mult = arg;
1571 } else if (token == Opt_max_dir_size_kb) {
1572 sbi->s_max_dir_size_kb = arg;
1573 } else if (token == Opt_stripe) {
1574 sbi->s_stripe = arg;
1575 } else if (token == Opt_resuid) {
1576 uid = make_kuid(current_user_ns(), arg);
1577 if (!uid_valid(uid)) {
1578 ext4_msg(sb, KERN_ERR, "Invalid uid value %d", arg);
1536 return -1; 1579 return -1;
1537 } 1580 }
1538 1581 sbi->s_resuid = uid;
1539 if (m->flags & MOPT_NOSUPPORT) { 1582 } else if (token == Opt_resgid) {
1540 ext4_msg(sb, KERN_ERR, "%s option not supported", opt); 1583 gid = make_kgid(current_user_ns(), arg);
1541 } else if (token == Opt_commit) { 1584 if (!gid_valid(gid)) {
1542 if (arg == 0) 1585 ext4_msg(sb, KERN_ERR, "Invalid gid value %d", arg);
1543 arg = JBD2_DEFAULT_MAX_COMMIT_AGE; 1586 return -1;
1544 sbi->s_commit_interval = HZ * arg; 1587 }
1545 } else if (token == Opt_max_batch_time) { 1588 sbi->s_resgid = gid;
1546 if (arg == 0) 1589 } else if (token == Opt_journal_dev) {
1547 arg = EXT4_DEF_MAX_BATCH_TIME; 1590 if (is_remount) {
1548 sbi->s_max_batch_time = arg; 1591 ext4_msg(sb, KERN_ERR,
1549 } else if (token == Opt_min_batch_time) { 1592 "Cannot specify journal on remount");
1550 sbi->s_min_batch_time = arg; 1593 return -1;
1551 } else if (token == Opt_inode_readahead_blks) { 1594 }
1552 if (arg > (1 << 30)) 1595 *journal_devnum = arg;
1553 return -1; 1596 } else if (token == Opt_journal_ioprio) {
1554 if (arg && !is_power_of_2(arg)) { 1597 if (arg > 7) {
1555 ext4_msg(sb, KERN_ERR, 1598 ext4_msg(sb, KERN_ERR, "Invalid journal IO priority"
1556 "EXT4-fs: inode_readahead_blks" 1599 " (must be 0-7)");
1557 " must be a power of 2"); 1600 return -1;
1558 return -1; 1601 }
1559 } 1602 *journal_ioprio =
1560 sbi->s_inode_readahead_blks = arg; 1603 IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
1561 } else if (token == Opt_init_itable) { 1604 } else if (m->flags & MOPT_DATAJ) {
1562 set_opt(sb, INIT_INODE_TABLE); 1605 if (is_remount) {
1563 if (!args->from) 1606 if (!sbi->s_journal)
1564 arg = EXT4_DEF_LI_WAIT_MULT; 1607 ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option");
1565 sbi->s_li_wait_mult = arg; 1608 else if (test_opt(sb, DATA_FLAGS) != m->mount_opt) {
1566 } else if (token == Opt_max_dir_size_kb) {
1567 sbi->s_max_dir_size_kb = arg;
1568 } else if (token == Opt_stripe) {
1569 sbi->s_stripe = arg;
1570 } else if (token == Opt_resuid) {
1571 uid = make_kuid(current_user_ns(), arg);
1572 if (!uid_valid(uid)) {
1573 ext4_msg(sb, KERN_ERR,
1574 "Invalid uid value %d", arg);
1575 return -1;
1576 }
1577 sbi->s_resuid = uid;
1578 } else if (token == Opt_resgid) {
1579 gid = make_kgid(current_user_ns(), arg);
1580 if (!gid_valid(gid)) {
1581 ext4_msg(sb, KERN_ERR,
1582 "Invalid gid value %d", arg);
1583 return -1;
1584 }
1585 sbi->s_resgid = gid;
1586 } else if (token == Opt_journal_dev) {
1587 if (is_remount) {
1588 ext4_msg(sb, KERN_ERR,
1589 "Cannot specify journal on remount");
1590 return -1;
1591 }
1592 *journal_devnum = arg;
1593 } else if (token == Opt_journal_ioprio) {
1594 if (arg > 7) {
1595 ext4_msg(sb, KERN_ERR, 1609 ext4_msg(sb, KERN_ERR,
1596 "Invalid journal IO priority"
1597 " (must be 0-7)");
1598 return -1;
1599 }
1600 *journal_ioprio =
1601 IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
1602 } else if (m->flags & MOPT_DATAJ) {
1603 if (is_remount) {
1604 if (!sbi->s_journal)
1605 ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option");
1606 else if (test_opt(sb, DATA_FLAGS) !=
1607 m->mount_opt) {
1608 ext4_msg(sb, KERN_ERR,
1609 "Cannot change data mode on remount"); 1610 "Cannot change data mode on remount");
1610 return -1;
1611 }
1612 } else {
1613 clear_opt(sb, DATA_FLAGS);
1614 sbi->s_mount_opt |= m->mount_opt;
1615 }
1616#ifdef CONFIG_QUOTA
1617 } else if (m->flags & MOPT_QFMT) {
1618 if (sb_any_quota_loaded(sb) &&
1619 sbi->s_jquota_fmt != m->mount_opt) {
1620 ext4_msg(sb, KERN_ERR, "Cannot "
1621 "change journaled quota options "
1622 "when quota turned on");
1623 return -1; 1611 return -1;
1624 } 1612 }
1625 sbi->s_jquota_fmt = m->mount_opt;
1626#endif
1627 } else { 1613 } else {
1628 if (!args->from) 1614 clear_opt(sb, DATA_FLAGS);
1629 arg = 1; 1615 sbi->s_mount_opt |= m->mount_opt;
1630 if (m->flags & MOPT_CLEAR)
1631 arg = !arg;
1632 else if (unlikely(!(m->flags & MOPT_SET))) {
1633 ext4_msg(sb, KERN_WARNING,
1634 "buggy handling of option %s", opt);
1635 WARN_ON(1);
1636 return -1;
1637 }
1638 if (arg != 0)
1639 sbi->s_mount_opt |= m->mount_opt;
1640 else
1641 sbi->s_mount_opt &= ~m->mount_opt;
1642 } 1616 }
1643 return 1; 1617#ifdef CONFIG_QUOTA
1618 } else if (m->flags & MOPT_QFMT) {
1619 if (sb_any_quota_loaded(sb) &&
1620 sbi->s_jquota_fmt != m->mount_opt) {
1621 ext4_msg(sb, KERN_ERR, "Cannot change journaled "
1622 "quota options when quota turned on");
1623 return -1;
1624 }
1625 sbi->s_jquota_fmt = m->mount_opt;
1626#endif
1627 } else {
1628 if (!args->from)
1629 arg = 1;
1630 if (m->flags & MOPT_CLEAR)
1631 arg = !arg;
1632 else if (unlikely(!(m->flags & MOPT_SET))) {
1633 ext4_msg(sb, KERN_WARNING,
1634 "buggy handling of option %s", opt);
1635 WARN_ON(1);
1636 return -1;
1637 }
1638 if (arg != 0)
1639 sbi->s_mount_opt |= m->mount_opt;
1640 else
1641 sbi->s_mount_opt &= ~m->mount_opt;
1644 } 1642 }
1645 ext4_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" " 1643 return 1;
1646 "or missing value", opt);
1647 return -1;
1648} 1644}
1649 1645
1650static int parse_options(char *options, struct super_block *sb, 1646static int parse_options(char *options, struct super_block *sb,