Skip to content

Commit b237e30

Browse files
harshadjstytso
authored andcommitted
ext4: add ability to return parsed options from parse_options
Before this patch, the function parse_options() was returning journal_devnum and journal_ioprio variables to the caller. This patch generalizes that interface to allow parse_options to return any parsed options to return back to the caller. In this patch series, it gets used to capture the value of "mb_optimize_scan=%u" mount option. Signed-off-by: Harshad Shirwadkar <[email protected]> Reviewed-by: Ritesh Harjani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 67d2518 commit b237e30

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

fs/ext4/super.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,9 +2090,14 @@ static int ext4_set_test_dummy_encryption(struct super_block *sb,
20902090
return 1;
20912091
}
20922092

2093+
struct ext4_parsed_options {
2094+
unsigned long journal_devnum;
2095+
unsigned int journal_ioprio;
2096+
};
2097+
20932098
static int handle_mount_opt(struct super_block *sb, char *opt, int token,
2094-
substring_t *args, unsigned long *journal_devnum,
2095-
unsigned int *journal_ioprio, int is_remount)
2099+
substring_t *args, struct ext4_parsed_options *parsed_opts,
2100+
int is_remount)
20962101
{
20972102
struct ext4_sb_info *sbi = EXT4_SB(sb);
20982103
const struct mount_opts *m;
@@ -2249,7 +2254,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
22492254
"Cannot specify journal on remount");
22502255
return -1;
22512256
}
2252-
*journal_devnum = arg;
2257+
parsed_opts->journal_devnum = arg;
22532258
} else if (token == Opt_journal_path) {
22542259
char *journal_path;
22552260
struct inode *journal_inode;
@@ -2285,7 +2290,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
22852290
return -1;
22862291
}
22872292

2288-
*journal_devnum = new_encode_dev(journal_inode->i_rdev);
2293+
parsed_opts->journal_devnum = new_encode_dev(journal_inode->i_rdev);
22892294
path_put(&path);
22902295
kfree(journal_path);
22912296
} else if (token == Opt_journal_ioprio) {
@@ -2294,7 +2299,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
22942299
" (must be 0-7)");
22952300
return -1;
22962301
}
2297-
*journal_ioprio =
2302+
parsed_opts->journal_ioprio =
22982303
IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
22992304
} else if (token == Opt_test_dummy_encryption) {
23002305
return ext4_set_test_dummy_encryption(sb, opt, &args[0],
@@ -2411,8 +2416,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
24112416
}
24122417

24132418
static int parse_options(char *options, struct super_block *sb,
2414-
unsigned long *journal_devnum,
2415-
unsigned int *journal_ioprio,
2419+
struct ext4_parsed_options *ret_opts,
24162420
int is_remount)
24172421
{
24182422
struct ext4_sb_info __maybe_unused *sbi = EXT4_SB(sb);
@@ -2432,8 +2436,8 @@ static int parse_options(char *options, struct super_block *sb,
24322436
*/
24332437
args[0].to = args[0].from = NULL;
24342438
token = match_token(p, tokens, args);
2435-
if (handle_mount_opt(sb, p, token, args, journal_devnum,
2436-
journal_ioprio, is_remount) < 0)
2439+
if (handle_mount_opt(sb, p, token, args, ret_opts,
2440+
is_remount) < 0)
24372441
return 0;
24382442
}
24392443
#ifdef CONFIG_QUOTA
@@ -4015,7 +4019,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
40154019
ext4_fsblk_t sb_block = get_sb_block(&data);
40164020
ext4_fsblk_t logical_sb_block;
40174021
unsigned long offset = 0;
4018-
unsigned long journal_devnum = 0;
40194022
unsigned long def_mount_opts;
40204023
struct inode *root;
40214024
const char *descr;
@@ -4026,8 +4029,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
40264029
int needs_recovery, has_huge_files;
40274030
__u64 blocks_count;
40284031
int err = 0;
4029-
unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
40304032
ext4_group_t first_not_zeroed;
4033+
struct ext4_parsed_options parsed_opts;
4034+
4035+
/* Set defaults for the variables that will be set during parsing */
4036+
parsed_opts.journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
4037+
parsed_opts.journal_devnum = 0;
40314038

40324039
if ((data && !orig_data) || !sbi)
40334040
goto out_free_base;
@@ -4273,17 +4280,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
42734280
GFP_KERNEL);
42744281
if (!s_mount_opts)
42754282
goto failed_mount;
4276-
if (!parse_options(s_mount_opts, sb, &journal_devnum,
4277-
&journal_ioprio, 0)) {
4283+
if (!parse_options(s_mount_opts, sb, &parsed_opts, 0)) {
42784284
ext4_msg(sb, KERN_WARNING,
42794285
"failed to parse options in superblock: %s",
42804286
s_mount_opts);
42814287
}
42824288
kfree(s_mount_opts);
42834289
}
42844290
sbi->s_def_mount_opt = sbi->s_mount_opt;
4285-
if (!parse_options((char *) data, sb, &journal_devnum,
4286-
&journal_ioprio, 0))
4291+
if (!parse_options((char *) data, sb, &parsed_opts, 0))
42874292
goto failed_mount;
42884293

42894294
#ifdef CONFIG_UNICODE
@@ -4768,7 +4773,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
47684773
* root first: it may be modified in the journal!
47694774
*/
47704775
if (!test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) {
4771-
err = ext4_load_journal(sb, es, journal_devnum);
4776+
err = ext4_load_journal(sb, es, parsed_opts.journal_devnum);
47724777
if (err)
47734778
goto failed_mount3a;
47744779
} else if (test_opt(sb, NOLOAD) && !sb_rdonly(sb) &&
@@ -4868,7 +4873,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
48684873
goto failed_mount_wq;
48694874
}
48704875

4871-
set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
4876+
set_task_ioprio(sbi->s_journal->j_task, parsed_opts.journal_ioprio);
48724877

48734878
sbi->s_journal->j_submit_inode_data_buffers =
48744879
ext4_journal_submit_inode_data_buffers;
@@ -5807,13 +5812,16 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
58075812
struct ext4_mount_options old_opts;
58085813
int enable_quota = 0;
58095814
ext4_group_t g;
5810-
unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
58115815
int err = 0;
58125816
#ifdef CONFIG_QUOTA
58135817
int i, j;
58145818
char *to_free[EXT4_MAXQUOTAS];
58155819
#endif
58165820
char *orig_data = kstrdup(data, GFP_KERNEL);
5821+
struct ext4_parsed_options parsed_opts;
5822+
5823+
parsed_opts.journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
5824+
parsed_opts.journal_devnum = 0;
58175825

58185826
if (data && !orig_data)
58195827
return -ENOMEM;
@@ -5844,7 +5852,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
58445852
old_opts.s_qf_names[i] = NULL;
58455853
#endif
58465854
if (sbi->s_journal && sbi->s_journal->j_task->io_context)
5847-
journal_ioprio = sbi->s_journal->j_task->io_context->ioprio;
5855+
parsed_opts.journal_ioprio =
5856+
sbi->s_journal->j_task->io_context->ioprio;
58485857

58495858
/*
58505859
* Some options can be enabled by ext4 and/or by VFS mount flag
@@ -5854,7 +5863,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
58545863
vfs_flags = SB_LAZYTIME | SB_I_VERSION;
58555864
sb->s_flags = (sb->s_flags & ~vfs_flags) | (*flags & vfs_flags);
58565865

5857-
if (!parse_options(data, sb, NULL, &journal_ioprio, 1)) {
5866+
if (!parse_options(data, sb, &parsed_opts, 1)) {
58585867
err = -EINVAL;
58595868
goto restore_opts;
58605869
}
@@ -5904,7 +5913,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
59045913

59055914
if (sbi->s_journal) {
59065915
ext4_init_journal_params(sb, sbi->s_journal);
5907-
set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
5916+
set_task_ioprio(sbi->s_journal->j_task, parsed_opts.journal_ioprio);
59085917
}
59095918

59105919
/* Flush outstanding errors before changing fs state */

0 commit comments

Comments
 (0)