Skip to content

Commit da812f6

Browse files
Lukas Czernertytso
authored andcommitted
ext4: Allow sb to be NULL in ext4_msg()
At the parsing phase of mount in the new mount api sb will not be available so allow sb to be NULL in ext4_msg and use that in handle_mount_opt(). Also change return value to appropriate -EINVAL where needed. Signed-off-by: Lukas Czerner <[email protected]> Reviewed-by: Carlos Maiolino <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 461c3af commit da812f6

File tree

1 file changed

+78
-66
lines changed

1 file changed

+78
-66
lines changed

fs/ext4/super.c

Lines changed: 78 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void ext4_unregister_li_request(struct super_block *sb);
8888
static void ext4_clear_request_list(void);
8989
static struct inode *ext4_get_journal_inode(struct super_block *sb,
9090
unsigned int journal_inum);
91-
static int ext4_validate_options(struct super_block *sb);
91+
static int ext4_validate_options(struct fs_context *fc);
9292

9393
/*
9494
* Lock ordering
@@ -915,14 +915,20 @@ void __ext4_msg(struct super_block *sb,
915915
struct va_format vaf;
916916
va_list args;
917917

918-
atomic_inc(&EXT4_SB(sb)->s_msg_count);
919-
if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state), "EXT4-fs"))
920-
return;
918+
if (sb) {
919+
atomic_inc(&EXT4_SB(sb)->s_msg_count);
920+
if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state),
921+
"EXT4-fs"))
922+
return;
923+
}
921924

922925
va_start(args, fmt);
923926
vaf.fmt = fmt;
924927
vaf.va = &args;
925-
printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
928+
if (sb)
929+
printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
930+
else
931+
printk("%sEXT4-fs: %pV\n", prefix, &vaf);
926932
va_end(args);
927933
}
928934

@@ -2286,12 +2292,12 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
22862292
switch (token) {
22872293
case Opt_noacl:
22882294
case Opt_nouser_xattr:
2289-
ext4_msg(sb, KERN_WARNING, deprecated_msg, param->key, "3.5");
2295+
ext4_msg(NULL, KERN_WARNING, deprecated_msg, param->key, "3.5");
22902296
break;
22912297
case Opt_sb:
22922298
return 1; /* handled by get_sb_block() */
22932299
case Opt_removed:
2294-
ext4_msg(sb, KERN_WARNING, "Ignoring removed %s option",
2300+
ext4_msg(NULL, KERN_WARNING, "Ignoring removed %s option",
22952301
param->key);
22962302
return 1;
22972303
case Opt_abort:
@@ -2310,7 +2316,7 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
23102316
#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
23112317
sb->s_flags |= SB_INLINECRYPT;
23122318
#else
2313-
ext4_msg(sb, KERN_ERR, "inline encryption not supported");
2319+
ext4_msg(NULL, KERN_ERR, "inline encryption not supported");
23142320
#endif
23152321
return 1;
23162322
case Opt_errors:
@@ -2326,22 +2332,22 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
23262332
break;
23272333

23282334
if (m->token == Opt_err) {
2329-
ext4_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" "
2335+
ext4_msg(NULL, KERN_ERR, "Unrecognized mount option \"%s\" "
23302336
"or missing value", param->key);
2331-
return -1;
2337+
return -EINVAL;
23322338
}
23332339

23342340
if ((m->flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) {
2335-
ext4_msg(sb, KERN_ERR,
2341+
ext4_msg(NULL, KERN_ERR,
23362342
"Mount option \"%s\" incompatible with ext2",
23372343
param->key);
2338-
return -1;
2344+
return -EINVAL;
23392345
}
23402346
if ((m->flags & MOPT_NO_EXT3) && IS_EXT3_SB(sb)) {
2341-
ext4_msg(sb, KERN_ERR,
2347+
ext4_msg(NULL, KERN_ERR,
23422348
"Mount option \"%s\" incompatible with ext3",
23432349
param->key);
2344-
return -1;
2350+
return -EINVAL;
23452351
}
23462352

23472353
if (m->flags & MOPT_EXPLICIT) {
@@ -2350,38 +2356,38 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
23502356
} else if (m->mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) {
23512357
set_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM);
23522358
} else
2353-
return -1;
2359+
return -EINVAL;
23542360
}
23552361
if (m->flags & MOPT_CLEAR_ERR)
23562362
clear_opt(sb, ERRORS_MASK);
23572363
if (token == Opt_noquota && sb_any_quota_loaded(sb)) {
2358-
ext4_msg(sb, KERN_ERR, "Cannot change quota "
2364+
ext4_msg(NULL, KERN_ERR, "Cannot change quota "
23592365
"options when quota turned on");
2360-
return -1;
2366+
return -EINVAL;
23612367
}
23622368

23632369
if (m->flags & MOPT_NOSUPPORT) {
2364-
ext4_msg(sb, KERN_ERR, "%s option not supported",
2370+
ext4_msg(NULL, KERN_ERR, "%s option not supported",
23652371
param->key);
23662372
} else if (token == Opt_commit) {
23672373
if (result.uint_32 == 0)
23682374
sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE;
23692375
else if (result.uint_32 > INT_MAX / HZ) {
2370-
ext4_msg(sb, KERN_ERR,
2376+
ext4_msg(NULL, KERN_ERR,
23712377
"Invalid commit interval %d, "
23722378
"must be smaller than %d",
23732379
result.uint_32, INT_MAX / HZ);
2374-
return -1;
2380+
return -EINVAL;
23752381
}
23762382
sbi->s_commit_interval = HZ * result.uint_32;
23772383
} else if (token == Opt_debug_want_extra_isize) {
23782384
if ((result.uint_32 & 1) ||
23792385
(result.uint_32 < 4) ||
23802386
(result.uint_32 >
23812387
(sbi->s_inode_size - EXT4_GOOD_OLD_INODE_SIZE))) {
2382-
ext4_msg(sb, KERN_ERR,
2388+
ext4_msg(NULL, KERN_ERR,
23832389
"Invalid want_extra_isize %d", result.uint_32);
2384-
return -1;
2390+
return -EINVAL;
23852391
}
23862392
sbi->s_want_extra_isize = result.uint_32;
23872393
} else if (token == Opt_max_batch_time) {
@@ -2392,10 +2398,10 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
23922398
if (result.uint_32 &&
23932399
(result.uint_32 > (1 << 30) ||
23942400
!is_power_of_2(result.uint_32))) {
2395-
ext4_msg(sb, KERN_ERR,
2401+
ext4_msg(NULL, KERN_ERR,
23962402
"EXT4-fs: inode_readahead_blks must be "
23972403
"0 or a power of 2 smaller than 2^31");
2398-
return -1;
2404+
return -EINVAL;
23992405
}
24002406
sbi->s_inode_readahead_blks = result.uint_32;
24012407
} else if (token == Opt_init_itable) {
@@ -2414,24 +2420,24 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
24142420
} else if (token == Opt_resuid) {
24152421
uid = make_kuid(current_user_ns(), result.uint_32);
24162422
if (!uid_valid(uid)) {
2417-
ext4_msg(sb, KERN_ERR, "Invalid uid value %d",
2423+
ext4_msg(NULL, KERN_ERR, "Invalid uid value %d",
24182424
result.uint_32);
2419-
return -1;
2425+
return -EINVAL;
24202426
}
24212427
sbi->s_resuid = uid;
24222428
} else if (token == Opt_resgid) {
24232429
gid = make_kgid(current_user_ns(), result.uint_32);
24242430
if (!gid_valid(gid)) {
2425-
ext4_msg(sb, KERN_ERR, "Invalid gid value %d",
2431+
ext4_msg(NULL, KERN_ERR, "Invalid gid value %d",
24262432
result.uint_32);
2427-
return -1;
2433+
return -EINVAL;
24282434
}
24292435
sbi->s_resgid = gid;
24302436
} else if (token == Opt_journal_dev) {
24312437
if (is_remount) {
2432-
ext4_msg(sb, KERN_ERR,
2438+
ext4_msg(NULL, KERN_ERR,
24332439
"Cannot specify journal on remount");
2434-
return -1;
2440+
return -EINVAL;
24352441
}
24362442
ctx->journal_devnum = result.uint_32;
24372443
} else if (token == Opt_journal_path) {
@@ -2440,26 +2446,26 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
24402446
int error;
24412447

24422448
if (is_remount) {
2443-
ext4_msg(sb, KERN_ERR,
2449+
ext4_msg(NULL, KERN_ERR,
24442450
"Cannot specify journal on remount");
2445-
return -1;
2451+
return -EINVAL;
24462452
}
24472453

24482454
error = fs_lookup_param(fc, param, 1, &path);
24492455
if (error) {
2450-
ext4_msg(sb, KERN_ERR, "error: could not find "
2456+
ext4_msg(NULL, KERN_ERR, "error: could not find "
24512457
"journal device path");
2452-
return -1;
2458+
return -EINVAL;
24532459
}
24542460

24552461
journal_inode = d_inode(path.dentry);
24562462
ctx->journal_devnum = new_encode_dev(journal_inode->i_rdev);
24572463
path_put(&path);
24582464
} else if (token == Opt_journal_ioprio) {
24592465
if (result.uint_32 > 7) {
2460-
ext4_msg(sb, KERN_ERR, "Invalid journal IO priority"
2466+
ext4_msg(NULL, KERN_ERR, "Invalid journal IO priority"
24612467
" (must be 0-7)");
2462-
return -1;
2468+
return -EINVAL;
24632469
}
24642470
ctx->journal_ioprio =
24652471
IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, result.uint_32);
@@ -2468,11 +2474,11 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
24682474
} else if (m->flags & MOPT_DATAJ) {
24692475
if (is_remount) {
24702476
if (!sbi->s_journal)
2471-
ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option");
2477+
ext4_msg(NULL, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option");
24722478
else if (test_opt(sb, DATA_FLAGS) != m->mount_opt) {
2473-
ext4_msg(sb, KERN_ERR,
2479+
ext4_msg(NULL, KERN_ERR,
24742480
"Cannot change data mode on remount");
2475-
return -1;
2481+
return -EINVAL;
24762482
}
24772483
} else {
24782484
clear_opt(sb, DATA_FLAGS);
@@ -2482,12 +2488,12 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
24822488
} else if (m->flags & MOPT_QFMT) {
24832489
if (sb_any_quota_loaded(sb) &&
24842490
sbi->s_jquota_fmt != m->mount_opt) {
2485-
ext4_msg(sb, KERN_ERR, "Cannot change journaled "
2491+
ext4_msg(NULL, KERN_ERR, "Cannot change journaled "
24862492
"quota options when quota turned on");
2487-
return -1;
2493+
return -EINVAL;
24882494
}
24892495
if (ext4_has_feature_quota(sb)) {
2490-
ext4_msg(sb, KERN_INFO,
2496+
ext4_msg(NULL, KERN_INFO,
24912497
"Quota format mount options ignored "
24922498
"when QUOTA feature is enabled");
24932499
return 1;
@@ -2504,18 +2510,18 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
25042510
(!(sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) ||
25052511
(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER))) {
25062512
fail_dax_change_remount:
2507-
ext4_msg(sb, KERN_ERR, "can't change "
2513+
ext4_msg(NULL, KERN_ERR, "can't change "
25082514
"dax mount option while remounting");
2509-
return -1;
2515+
return -EINVAL;
25102516
}
25112517
if (is_remount &&
25122518
(test_opt(sb, DATA_FLAGS) ==
25132519
EXT4_MOUNT_JOURNAL_DATA)) {
2514-
ext4_msg(sb, KERN_ERR, "can't mount with "
2520+
ext4_msg(NULL, KERN_ERR, "can't mount with "
25152521
"both data=journal and dax");
2516-
return -1;
2522+
return -EINVAL;
25172523
}
2518-
ext4_msg(sb, KERN_WARNING,
2524+
ext4_msg(NULL, KERN_WARNING,
25192525
"DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
25202526
sbi->s_mount_opt |= EXT4_MOUNT_DAX_ALWAYS;
25212527
sbi->s_mount_opt2 &= ~EXT4_MOUNT2_DAX_NEVER;
@@ -2541,20 +2547,20 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
25412547
break;
25422548
}
25432549
#else
2544-
ext4_msg(sb, KERN_INFO, "dax option not supported");
2550+
ext4_msg(NULL, KERN_INFO, "dax option not supported");
25452551
sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_NEVER;
25462552
sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS;
2547-
return -1;
2553+
return -EINVAL;
25482554
#endif
25492555
} else if (token == Opt_data_err_abort) {
25502556
sbi->s_mount_opt |= m->mount_opt;
25512557
} else if (token == Opt_data_err_ignore) {
25522558
sbi->s_mount_opt &= ~m->mount_opt;
25532559
} else if (token == Opt_mb_optimize_scan) {
25542560
if (result.int_32 != 0 && result.int_32 != 1) {
2555-
ext4_msg(sb, KERN_WARNING,
2561+
ext4_msg(NULL, KERN_WARNING,
25562562
"mb_optimize_scan should be set to 0 or 1.");
2557-
return -1;
2563+
return -EINVAL;
25582564
}
25592565
ctx->mb_optimize_scan = result.int_32;
25602566
} else {
@@ -2567,11 +2573,11 @@ static int handle_mount_opt(struct fs_context *fc, struct fs_parameter *param)
25672573
if (m->flags & MOPT_CLEAR)
25682574
set = !set;
25692575
else if (unlikely(!(m->flags & MOPT_SET))) {
2570-
ext4_msg(sb, KERN_WARNING,
2576+
ext4_msg(NULL, KERN_WARNING,
25712577
"buggy handling of option %s",
25722578
param->key);
25732579
WARN_ON(1);
2574-
return -1;
2580+
return -EINVAL;
25752581
}
25762582
if (m->flags & MOPT_2) {
25772583
if (set != 0)
@@ -2639,12 +2645,17 @@ static int parse_options(char *options, struct super_block *sb,
26392645
}
26402646
}
26412647

2642-
return ext4_validate_options(sb);
2648+
ret = ext4_validate_options(&fc);
2649+
if (ret < 0)
2650+
return 0;
2651+
2652+
return 1;
26432653
}
26442654

2645-
static int ext4_validate_options(struct super_block *sb)
2655+
static int ext4_validate_options(struct fs_context *fc)
26462656
{
2647-
struct ext4_sb_info *sbi = EXT4_SB(sb);
2657+
struct ext4_sb_info *sbi = fc->s_fs_info;
2658+
struct super_block *sb = sbi->s_sb;
26482659
#ifdef CONFIG_QUOTA
26492660
char *usr_qf_name, *grp_qf_name;
26502661
/*
@@ -2653,9 +2664,9 @@ static int ext4_validate_options(struct super_block *sb)
26532664
* to support legacy quotas in quota files.
26542665
*/
26552666
if (test_opt(sb, PRJQUOTA) && !ext4_has_feature_project(sb)) {
2656-
ext4_msg(sb, KERN_ERR, "Project quota feature not enabled. "
2667+
ext4_msg(NULL, KERN_ERR, "Project quota feature not enabled. "
26572668
"Cannot enable project quota enforcement.");
2658-
return 0;
2669+
return -EINVAL;
26592670
}
26602671
usr_qf_name = get_qf_name(sb, sbi, USRQUOTA);
26612672
grp_qf_name = get_qf_name(sb, sbi, GRPQUOTA);
@@ -2667,27 +2678,28 @@ static int ext4_validate_options(struct super_block *sb)
26672678
clear_opt(sb, GRPQUOTA);
26682679

26692680
if (test_opt(sb, GRPQUOTA) || test_opt(sb, USRQUOTA)) {
2670-
ext4_msg(sb, KERN_ERR, "old and new quota "
2681+
ext4_msg(NULL, KERN_ERR, "old and new quota "
26712682
"format mixing");
2672-
return 0;
2683+
return -EINVAL;
26732684
}
26742685

26752686
if (!sbi->s_jquota_fmt) {
2676-
ext4_msg(sb, KERN_ERR, "journaled quota format "
2687+
ext4_msg(NULL, KERN_ERR, "journaled quota format "
26772688
"not specified");
2678-
return 0;
2689+
return -EINVAL;
26792690
}
26802691
}
26812692
#endif
26822693
if (test_opt(sb, DIOREAD_NOLOCK)) {
26832694
int blocksize =
26842695
BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
26852696
if (blocksize < PAGE_SIZE)
2686-
ext4_msg(sb, KERN_WARNING, "Warning: mounting with an "
2687-
"experimental mount option 'dioread_nolock' "
2688-
"for blocksize < PAGE_SIZE");
2697+
ext4_msg(NULL, KERN_WARNING,
2698+
"Warning: mounting with an experimental "
2699+
"option 'dioread_nolock' for "
2700+
"blocksize < PAGE_SIZE");
26892701
}
2690-
return 1;
2702+
return 0;
26912703
}
26922704

26932705
static inline void ext4_show_quota_options(struct seq_file *seq,

0 commit comments

Comments
 (0)