Commit 5f3633e3 authored by Jan Kara's avatar Jan Kara Committed by Theodore Ts'o

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: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 0efb3b23
...@@ -1508,8 +1508,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, ...@@ -1508,8 +1508,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
case Opt_sb: case Opt_sb:
return 1; /* handled by get_sb_block() */ return 1; /* handled by get_sb_block() */
case Opt_removed: case Opt_removed:
ext4_msg(sb, KERN_WARNING, ext4_msg(sb, KERN_WARNING, "Ignoring removed %s option", opt);
"Ignoring removed %s option", opt);
return 1; return 1;
case Opt_abort: case Opt_abort:
sbi->s_mount_flags |= EXT4_MF_FS_ABORTED; sbi->s_mount_flags |= EXT4_MF_FS_ABORTED;
...@@ -1519,9 +1518,16 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, ...@@ -1519,9 +1518,16 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
return 1; return 1;
} }
for (m = ext4_mount_opts; m->token != Opt_err; m++) { for (m = ext4_mount_opts; m->token != Opt_err; m++)
if (token != m->token) if (token == m->token)
continue; break;
if (m->token == Opt_err) {
ext4_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" "
"or missing value", opt);
return -1;
}
if (args->from && match_int(args, &arg)) if (args->from && match_int(args, &arg))
return -1; return -1;
if (args->from && (m->flags & MOPT_GTE0) && (arg < 0)) if (args->from && (m->flags & MOPT_GTE0) && (arg < 0))
...@@ -1552,8 +1558,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, ...@@ -1552,8 +1558,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
if (arg > (1 << 30)) if (arg > (1 << 30))
return -1; return -1;
if (arg && !is_power_of_2(arg)) { if (arg && !is_power_of_2(arg)) {
ext4_msg(sb, KERN_ERR, ext4_msg(sb, KERN_ERR, "EXT4-fs: inode_readahead_blks"
"EXT4-fs: inode_readahead_blks"
" must be a power of 2"); " must be a power of 2");
return -1; return -1;
} }
...@@ -1570,16 +1575,14 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, ...@@ -1570,16 +1575,14 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
} else if (token == Opt_resuid) { } else if (token == Opt_resuid) {
uid = make_kuid(current_user_ns(), arg); uid = make_kuid(current_user_ns(), arg);
if (!uid_valid(uid)) { if (!uid_valid(uid)) {
ext4_msg(sb, KERN_ERR, ext4_msg(sb, KERN_ERR, "Invalid uid value %d", arg);
"Invalid uid value %d", arg);
return -1; return -1;
} }
sbi->s_resuid = uid; sbi->s_resuid = uid;
} else if (token == Opt_resgid) { } else if (token == Opt_resgid) {
gid = make_kgid(current_user_ns(), arg); gid = make_kgid(current_user_ns(), arg);
if (!gid_valid(gid)) { if (!gid_valid(gid)) {
ext4_msg(sb, KERN_ERR, ext4_msg(sb, KERN_ERR, "Invalid gid value %d", arg);
"Invalid gid value %d", arg);
return -1; return -1;
} }
sbi->s_resgid = gid; sbi->s_resgid = gid;
...@@ -1592,8 +1595,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, ...@@ -1592,8 +1595,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
*journal_devnum = arg; *journal_devnum = arg;
} else if (token == Opt_journal_ioprio) { } else if (token == Opt_journal_ioprio) {
if (arg > 7) { if (arg > 7) {
ext4_msg(sb, KERN_ERR, ext4_msg(sb, KERN_ERR, "Invalid journal IO priority"
"Invalid journal IO priority"
" (must be 0-7)"); " (must be 0-7)");
return -1; return -1;
} }
...@@ -1603,8 +1605,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, ...@@ -1603,8 +1605,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
if (is_remount) { if (is_remount) {
if (!sbi->s_journal) if (!sbi->s_journal)
ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option"); ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option");
else if (test_opt(sb, DATA_FLAGS) != else if (test_opt(sb, DATA_FLAGS) != m->mount_opt) {
m->mount_opt) {
ext4_msg(sb, KERN_ERR, ext4_msg(sb, KERN_ERR,
"Cannot change data mode on remount"); "Cannot change data mode on remount");
return -1; return -1;
...@@ -1617,9 +1618,8 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, ...@@ -1617,9 +1618,8 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
} else if (m->flags & MOPT_QFMT) { } else if (m->flags & MOPT_QFMT) {
if (sb_any_quota_loaded(sb) && if (sb_any_quota_loaded(sb) &&
sbi->s_jquota_fmt != m->mount_opt) { sbi->s_jquota_fmt != m->mount_opt) {
ext4_msg(sb, KERN_ERR, "Cannot " ext4_msg(sb, KERN_ERR, "Cannot change journaled "
"change journaled quota options " "quota options when quota turned on");
"when quota turned on");
return -1; return -1;
} }
sbi->s_jquota_fmt = m->mount_opt; sbi->s_jquota_fmt = m->mount_opt;
...@@ -1641,10 +1641,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, ...@@ -1641,10 +1641,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
sbi->s_mount_opt &= ~m->mount_opt; sbi->s_mount_opt &= ~m->mount_opt;
} }
return 1; return 1;
}
ext4_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" "
"or missing value", opt);
return -1;
} }
static int parse_options(char *options, struct super_block *sb, static int parse_options(char *options, struct super_block *sb,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment