super.c (04f0b2eaa3b3ee243df6040617b4bfbbc0404854) super.c (dcbb4c10e6d9693cc9d6fa493b4d130b66a60c7d)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * fs/f2fs/super.c
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 */
8#include <linux/module.h>

--- 191 unchanged lines hidden (view full) ---

200 {Opt_test_dummy_encryption, "test_dummy_encryption"},
201 {Opt_checkpoint_disable, "checkpoint=disable"},
202 {Opt_checkpoint_disable_cap, "checkpoint=disable:%u"},
203 {Opt_checkpoint_disable_cap_perc, "checkpoint=disable:%u%%"},
204 {Opt_checkpoint_enable, "checkpoint=enable"},
205 {Opt_err, NULL},
206};
207
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * fs/f2fs/super.c
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 */
8#include <linux/module.h>

--- 191 unchanged lines hidden (view full) ---

200 {Opt_test_dummy_encryption, "test_dummy_encryption"},
201 {Opt_checkpoint_disable, "checkpoint=disable"},
202 {Opt_checkpoint_disable_cap, "checkpoint=disable:%u"},
203 {Opt_checkpoint_disable_cap_perc, "checkpoint=disable:%u%%"},
204 {Opt_checkpoint_enable, "checkpoint=enable"},
205 {Opt_err, NULL},
206};
207
208void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...)
208void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...)
209{
210 struct va_format vaf;
211 va_list args;
209{
210 struct va_format vaf;
211 va_list args;
212 int level;
212
213 va_start(args, fmt);
213
214 va_start(args, fmt);
214 vaf.fmt = fmt;
215
216 level = printk_get_level(fmt);
217 vaf.fmt = printk_skip_level(fmt);
215 vaf.va = &args;
218 vaf.va = &args;
216 printk("%sF2FS-fs (%s): %pV\n", level, sb->s_id, &vaf);
219 printk("%c%cF2FS-fs (%s): %pV\n",
220 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf);
221
217 va_end(args);
218}
219
220static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
221{
222 block_t limit = min((sbi->user_block_count << 1) / 1000,
223 sbi->user_block_count - sbi->reserved_blocks);
224
225 /* limit is 0.2% */
226 if (test_opt(sbi, RESERVE_ROOT) &&
227 F2FS_OPTION(sbi).root_reserved_blocks > limit) {
228 F2FS_OPTION(sbi).root_reserved_blocks = limit;
222 va_end(args);
223}
224
225static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
226{
227 block_t limit = min((sbi->user_block_count << 1) / 1000,
228 sbi->user_block_count - sbi->reserved_blocks);
229
230 /* limit is 0.2% */
231 if (test_opt(sbi, RESERVE_ROOT) &&
232 F2FS_OPTION(sbi).root_reserved_blocks > limit) {
233 F2FS_OPTION(sbi).root_reserved_blocks = limit;
229 f2fs_msg(sbi->sb, KERN_INFO,
230 "Reduce reserved blocks for root = %u",
231 F2FS_OPTION(sbi).root_reserved_blocks);
234 f2fs_info(sbi, "Reduce reserved blocks for root = %u",
235 F2FS_OPTION(sbi).root_reserved_blocks);
232 }
233 if (!test_opt(sbi, RESERVE_ROOT) &&
234 (!uid_eq(F2FS_OPTION(sbi).s_resuid,
235 make_kuid(&init_user_ns, F2FS_DEF_RESUID)) ||
236 !gid_eq(F2FS_OPTION(sbi).s_resgid,
237 make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
236 }
237 if (!test_opt(sbi, RESERVE_ROOT) &&
238 (!uid_eq(F2FS_OPTION(sbi).s_resuid,
239 make_kuid(&init_user_ns, F2FS_DEF_RESUID)) ||
240 !gid_eq(F2FS_OPTION(sbi).s_resgid,
241 make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
238 f2fs_msg(sbi->sb, KERN_INFO,
239 "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
240 from_kuid_munged(&init_user_ns,
241 F2FS_OPTION(sbi).s_resuid),
242 from_kgid_munged(&init_user_ns,
243 F2FS_OPTION(sbi).s_resgid));
242 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
243 from_kuid_munged(&init_user_ns,
244 F2FS_OPTION(sbi).s_resuid),
245 from_kgid_munged(&init_user_ns,
246 F2FS_OPTION(sbi).s_resgid));
244}
245
246static void init_once(void *foo)
247{
248 struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo;
249
250 inode_init_once(&fi->vfs_inode);
251}

--- 4 unchanged lines hidden (view full) ---

256static int f2fs_set_qf_name(struct super_block *sb, int qtype,
257 substring_t *args)
258{
259 struct f2fs_sb_info *sbi = F2FS_SB(sb);
260 char *qname;
261 int ret = -EINVAL;
262
263 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) {
247}
248
249static void init_once(void *foo)
250{
251 struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo;
252
253 inode_init_once(&fi->vfs_inode);
254}

--- 4 unchanged lines hidden (view full) ---

259static int f2fs_set_qf_name(struct super_block *sb, int qtype,
260 substring_t *args)
261{
262 struct f2fs_sb_info *sbi = F2FS_SB(sb);
263 char *qname;
264 int ret = -EINVAL;
265
266 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) {
264 f2fs_msg(sb, KERN_ERR,
265 "Cannot change journaled "
266 "quota options when quota turned on");
267 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
267 return -EINVAL;
268 }
269 if (f2fs_sb_has_quota_ino(sbi)) {
268 return -EINVAL;
269 }
270 if (f2fs_sb_has_quota_ino(sbi)) {
270 f2fs_msg(sb, KERN_INFO,
271 "QUOTA feature is enabled, so ignore qf_name");
271 f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name");
272 return 0;
273 }
274
275 qname = match_strdup(args);
276 if (!qname) {
272 return 0;
273 }
274
275 qname = match_strdup(args);
276 if (!qname) {
277 f2fs_msg(sb, KERN_ERR,
278 "Not enough memory for storing quotafile name");
277 f2fs_err(sbi, "Not enough memory for storing quotafile name");
279 return -ENOMEM;
280 }
281 if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
282 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
283 ret = 0;
284 else
278 return -ENOMEM;
279 }
280 if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
281 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
282 ret = 0;
283 else
285 f2fs_msg(sb, KERN_ERR,
286 "%s quota file already specified",
284 f2fs_err(sbi, "%s quota file already specified",
287 QTYPE2NAME(qtype));
288 goto errout;
289 }
290 if (strchr(qname, '/')) {
285 QTYPE2NAME(qtype));
286 goto errout;
287 }
288 if (strchr(qname, '/')) {
291 f2fs_msg(sb, KERN_ERR,
292 "quotafile must be on filesystem root");
289 f2fs_err(sbi, "quotafile must be on filesystem root");
293 goto errout;
294 }
295 F2FS_OPTION(sbi).s_qf_names[qtype] = qname;
296 set_opt(sbi, QUOTA);
297 return 0;
298errout:
299 kvfree(qname);
300 return ret;
301}
302
303static int f2fs_clear_qf_name(struct super_block *sb, int qtype)
304{
305 struct f2fs_sb_info *sbi = F2FS_SB(sb);
306
307 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) {
290 goto errout;
291 }
292 F2FS_OPTION(sbi).s_qf_names[qtype] = qname;
293 set_opt(sbi, QUOTA);
294 return 0;
295errout:
296 kvfree(qname);
297 return ret;
298}
299
300static int f2fs_clear_qf_name(struct super_block *sb, int qtype)
301{
302 struct f2fs_sb_info *sbi = F2FS_SB(sb);
303
304 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) {
308 f2fs_msg(sb, KERN_ERR, "Cannot change journaled quota options"
309 " when quota turned on");
305 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
310 return -EINVAL;
311 }
312 kvfree(F2FS_OPTION(sbi).s_qf_names[qtype]);
313 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL;
314 return 0;
315}
316
317static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
318{
319 /*
320 * We do the test below only for project quotas. 'usrquota' and
321 * 'grpquota' mount options are allowed even without quota feature
322 * to support legacy quotas in quota files.
323 */
324 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) {
306 return -EINVAL;
307 }
308 kvfree(F2FS_OPTION(sbi).s_qf_names[qtype]);
309 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL;
310 return 0;
311}
312
313static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
314{
315 /*
316 * We do the test below only for project quotas. 'usrquota' and
317 * 'grpquota' mount options are allowed even without quota feature
318 * to support legacy quotas in quota files.
319 */
320 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) {
325 f2fs_msg(sbi->sb, KERN_ERR, "Project quota feature not enabled. "
326 "Cannot enable project quota enforcement.");
321 f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement.");
327 return -1;
328 }
329 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
330 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
331 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) {
332 if (test_opt(sbi, USRQUOTA) &&
333 F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
334 clear_opt(sbi, USRQUOTA);
335
336 if (test_opt(sbi, GRPQUOTA) &&
337 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
338 clear_opt(sbi, GRPQUOTA);
339
340 if (test_opt(sbi, PRJQUOTA) &&
341 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
342 clear_opt(sbi, PRJQUOTA);
343
344 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) ||
345 test_opt(sbi, PRJQUOTA)) {
322 return -1;
323 }
324 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
325 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
326 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) {
327 if (test_opt(sbi, USRQUOTA) &&
328 F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
329 clear_opt(sbi, USRQUOTA);
330
331 if (test_opt(sbi, GRPQUOTA) &&
332 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
333 clear_opt(sbi, GRPQUOTA);
334
335 if (test_opt(sbi, PRJQUOTA) &&
336 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
337 clear_opt(sbi, PRJQUOTA);
338
339 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) ||
340 test_opt(sbi, PRJQUOTA)) {
346 f2fs_msg(sbi->sb, KERN_ERR, "old and new quota "
347 "format mixing");
341 f2fs_err(sbi, "old and new quota format mixing");
348 return -1;
349 }
350
351 if (!F2FS_OPTION(sbi).s_jquota_fmt) {
342 return -1;
343 }
344
345 if (!F2FS_OPTION(sbi).s_jquota_fmt) {
352 f2fs_msg(sbi->sb, KERN_ERR, "journaled quota format "
353 "not specified");
346 f2fs_err(sbi, "journaled quota format not specified");
354 return -1;
355 }
356 }
357
358 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) {
347 return -1;
348 }
349 }
350
351 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) {
359 f2fs_msg(sbi->sb, KERN_INFO,
360 "QUOTA feature is enabled, so ignore jquota_fmt");
352 f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt");
361 F2FS_OPTION(sbi).s_jquota_fmt = 0;
362 }
363 return 0;
364}
365#endif
366
367static int parse_options(struct super_block *sb, char *options)
368{

--- 51 unchanged lines hidden (view full) ---

420 if (!f2fs_readonly(sb))
421 return -EINVAL;
422 break;
423 case Opt_discard:
424 set_opt(sbi, DISCARD);
425 break;
426 case Opt_nodiscard:
427 if (f2fs_sb_has_blkzoned(sbi)) {
353 F2FS_OPTION(sbi).s_jquota_fmt = 0;
354 }
355 return 0;
356}
357#endif
358
359static int parse_options(struct super_block *sb, char *options)
360{

--- 51 unchanged lines hidden (view full) ---

412 if (!f2fs_readonly(sb))
413 return -EINVAL;
414 break;
415 case Opt_discard:
416 set_opt(sbi, DISCARD);
417 break;
418 case Opt_nodiscard:
419 if (f2fs_sb_has_blkzoned(sbi)) {
428 f2fs_msg(sb, KERN_WARNING,
429 "discard is required for zoned block devices");
420 f2fs_warn(sbi, "discard is required for zoned block devices");
430 return -EINVAL;
431 }
432 clear_opt(sbi, DISCARD);
433 break;
434 case Opt_noheap:
435 set_opt(sbi, NOHEAP);
436 break;
437 case Opt_heap:

--- 15 unchanged lines hidden (view full) ---

453 case Opt_inline_xattr_size:
454 if (args->from && match_int(args, &arg))
455 return -EINVAL;
456 set_opt(sbi, INLINE_XATTR_SIZE);
457 F2FS_OPTION(sbi).inline_xattr_size = arg;
458 break;
459#else
460 case Opt_user_xattr:
421 return -EINVAL;
422 }
423 clear_opt(sbi, DISCARD);
424 break;
425 case Opt_noheap:
426 set_opt(sbi, NOHEAP);
427 break;
428 case Opt_heap:

--- 15 unchanged lines hidden (view full) ---

444 case Opt_inline_xattr_size:
445 if (args->from && match_int(args, &arg))
446 return -EINVAL;
447 set_opt(sbi, INLINE_XATTR_SIZE);
448 F2FS_OPTION(sbi).inline_xattr_size = arg;
449 break;
450#else
451 case Opt_user_xattr:
461 f2fs_msg(sb, KERN_INFO,
462 "user_xattr options not supported");
452 f2fs_info(sbi, "user_xattr options not supported");
463 break;
464 case Opt_nouser_xattr:
453 break;
454 case Opt_nouser_xattr:
465 f2fs_msg(sb, KERN_INFO,
466 "nouser_xattr options not supported");
455 f2fs_info(sbi, "nouser_xattr options not supported");
467 break;
468 case Opt_inline_xattr:
456 break;
457 case Opt_inline_xattr:
469 f2fs_msg(sb, KERN_INFO,
470 "inline_xattr options not supported");
458 f2fs_info(sbi, "inline_xattr options not supported");
471 break;
472 case Opt_noinline_xattr:
459 break;
460 case Opt_noinline_xattr:
473 f2fs_msg(sb, KERN_INFO,
474 "noinline_xattr options not supported");
461 f2fs_info(sbi, "noinline_xattr options not supported");
475 break;
476#endif
477#ifdef CONFIG_F2FS_FS_POSIX_ACL
478 case Opt_acl:
479 set_opt(sbi, POSIX_ACL);
480 break;
481 case Opt_noacl:
482 clear_opt(sbi, POSIX_ACL);
483 break;
484#else
485 case Opt_acl:
462 break;
463#endif
464#ifdef CONFIG_F2FS_FS_POSIX_ACL
465 case Opt_acl:
466 set_opt(sbi, POSIX_ACL);
467 break;
468 case Opt_noacl:
469 clear_opt(sbi, POSIX_ACL);
470 break;
471#else
472 case Opt_acl:
486 f2fs_msg(sb, KERN_INFO, "acl options not supported");
473 f2fs_info(sbi, "acl options not supported");
487 break;
488 case Opt_noacl:
474 break;
475 case Opt_noacl:
489 f2fs_msg(sb, KERN_INFO, "noacl options not supported");
476 f2fs_info(sbi, "noacl options not supported");
490 break;
491#endif
492 case Opt_active_logs:
493 if (args->from && match_int(args, &arg))
494 return -EINVAL;
495 if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE)
496 return -EINVAL;
497 F2FS_OPTION(sbi).active_logs = arg;

--- 33 unchanged lines hidden (view full) ---

531 break;
532 case Opt_data_flush:
533 set_opt(sbi, DATA_FLUSH);
534 break;
535 case Opt_reserve_root:
536 if (args->from && match_int(args, &arg))
537 return -EINVAL;
538 if (test_opt(sbi, RESERVE_ROOT)) {
477 break;
478#endif
479 case Opt_active_logs:
480 if (args->from && match_int(args, &arg))
481 return -EINVAL;
482 if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE)
483 return -EINVAL;
484 F2FS_OPTION(sbi).active_logs = arg;

--- 33 unchanged lines hidden (view full) ---

518 break;
519 case Opt_data_flush:
520 set_opt(sbi, DATA_FLUSH);
521 break;
522 case Opt_reserve_root:
523 if (args->from && match_int(args, &arg))
524 return -EINVAL;
525 if (test_opt(sbi, RESERVE_ROOT)) {
539 f2fs_msg(sb, KERN_INFO,
540 "Preserve previous reserve_root=%u",
541 F2FS_OPTION(sbi).root_reserved_blocks);
526 f2fs_info(sbi, "Preserve previous reserve_root=%u",
527 F2FS_OPTION(sbi).root_reserved_blocks);
542 } else {
543 F2FS_OPTION(sbi).root_reserved_blocks = arg;
544 set_opt(sbi, RESERVE_ROOT);
545 }
546 break;
547 case Opt_resuid:
548 if (args->from && match_int(args, &arg))
549 return -EINVAL;
550 uid = make_kuid(current_user_ns(), arg);
551 if (!uid_valid(uid)) {
528 } else {
529 F2FS_OPTION(sbi).root_reserved_blocks = arg;
530 set_opt(sbi, RESERVE_ROOT);
531 }
532 break;
533 case Opt_resuid:
534 if (args->from && match_int(args, &arg))
535 return -EINVAL;
536 uid = make_kuid(current_user_ns(), arg);
537 if (!uid_valid(uid)) {
552 f2fs_msg(sb, KERN_ERR,
553 "Invalid uid value %d", arg);
538 f2fs_err(sbi, "Invalid uid value %d", arg);
554 return -EINVAL;
555 }
556 F2FS_OPTION(sbi).s_resuid = uid;
557 break;
558 case Opt_resgid:
559 if (args->from && match_int(args, &arg))
560 return -EINVAL;
561 gid = make_kgid(current_user_ns(), arg);
562 if (!gid_valid(gid)) {
539 return -EINVAL;
540 }
541 F2FS_OPTION(sbi).s_resuid = uid;
542 break;
543 case Opt_resgid:
544 if (args->from && match_int(args, &arg))
545 return -EINVAL;
546 gid = make_kgid(current_user_ns(), arg);
547 if (!gid_valid(gid)) {
563 f2fs_msg(sb, KERN_ERR,
564 "Invalid gid value %d", arg);
548 f2fs_err(sbi, "Invalid gid value %d", arg);
565 return -EINVAL;
566 }
567 F2FS_OPTION(sbi).s_resgid = gid;
568 break;
569 case Opt_mode:
570 name = match_strdup(&args[0]);
571
572 if (!name)
573 return -ENOMEM;
574 if (strlen(name) == 8 &&
575 !strncmp(name, "adaptive", 8)) {
576 if (f2fs_sb_has_blkzoned(sbi)) {
549 return -EINVAL;
550 }
551 F2FS_OPTION(sbi).s_resgid = gid;
552 break;
553 case Opt_mode:
554 name = match_strdup(&args[0]);
555
556 if (!name)
557 return -ENOMEM;
558 if (strlen(name) == 8 &&
559 !strncmp(name, "adaptive", 8)) {
560 if (f2fs_sb_has_blkzoned(sbi)) {
577 f2fs_msg(sb, KERN_WARNING,
578 "adaptive mode is not allowed with "
579 "zoned block device feature");
561 f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature");
580 kvfree(name);
581 return -EINVAL;
582 }
583 set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE);
584 } else if (strlen(name) == 3 &&
585 !strncmp(name, "lfs", 3)) {
586 set_opt_mode(sbi, F2FS_MOUNT_LFS);
587 } else {
588 kvfree(name);
589 return -EINVAL;
590 }
591 kvfree(name);
592 break;
593 case Opt_io_size_bits:
594 if (args->from && match_int(args, &arg))
595 return -EINVAL;
596 if (arg <= 0 || arg > __ilog2_u32(BIO_MAX_PAGES)) {
562 kvfree(name);
563 return -EINVAL;
564 }
565 set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE);
566 } else if (strlen(name) == 3 &&
567 !strncmp(name, "lfs", 3)) {
568 set_opt_mode(sbi, F2FS_MOUNT_LFS);
569 } else {
570 kvfree(name);
571 return -EINVAL;
572 }
573 kvfree(name);
574 break;
575 case Opt_io_size_bits:
576 if (args->from && match_int(args, &arg))
577 return -EINVAL;
578 if (arg <= 0 || arg > __ilog2_u32(BIO_MAX_PAGES)) {
597 f2fs_msg(sb, KERN_WARNING,
598 "Not support %d, larger than %d",
599 1 << arg, BIO_MAX_PAGES);
579 f2fs_warn(sbi, "Not support %d, larger than %d",
580 1 << arg, BIO_MAX_PAGES);
600 return -EINVAL;
601 }
602 F2FS_OPTION(sbi).write_io_size_bits = arg;
603 break;
604#ifdef CONFIG_F2FS_FAULT_INJECTION
605 case Opt_fault_injection:
606 if (args->from && match_int(args, &arg))
607 return -EINVAL;

--- 4 unchanged lines hidden (view full) ---

612 case Opt_fault_type:
613 if (args->from && match_int(args, &arg))
614 return -EINVAL;
615 f2fs_build_fault_attr(sbi, 0, arg);
616 set_opt(sbi, FAULT_INJECTION);
617 break;
618#else
619 case Opt_fault_injection:
581 return -EINVAL;
582 }
583 F2FS_OPTION(sbi).write_io_size_bits = arg;
584 break;
585#ifdef CONFIG_F2FS_FAULT_INJECTION
586 case Opt_fault_injection:
587 if (args->from && match_int(args, &arg))
588 return -EINVAL;

--- 4 unchanged lines hidden (view full) ---

593 case Opt_fault_type:
594 if (args->from && match_int(args, &arg))
595 return -EINVAL;
596 f2fs_build_fault_attr(sbi, 0, arg);
597 set_opt(sbi, FAULT_INJECTION);
598 break;
599#else
600 case Opt_fault_injection:
620 f2fs_msg(sb, KERN_INFO,
621 "fault_injection options not supported");
601 f2fs_info(sbi, "fault_injection options not supported");
622 break;
623
624 case Opt_fault_type:
602 break;
603
604 case Opt_fault_type:
625 f2fs_msg(sb, KERN_INFO,
626 "fault_type options not supported");
605 f2fs_info(sbi, "fault_type options not supported");
627 break;
628#endif
629 case Opt_lazytime:
630 sb->s_flags |= SB_LAZYTIME;
631 break;
632 case Opt_nolazytime:
633 sb->s_flags &= ~SB_LAZYTIME;
634 break;

--- 63 unchanged lines hidden (view full) ---

698 case Opt_prjjquota:
699 case Opt_offusrjquota:
700 case Opt_offgrpjquota:
701 case Opt_offprjjquota:
702 case Opt_jqfmt_vfsold:
703 case Opt_jqfmt_vfsv0:
704 case Opt_jqfmt_vfsv1:
705 case Opt_noquota:
606 break;
607#endif
608 case Opt_lazytime:
609 sb->s_flags |= SB_LAZYTIME;
610 break;
611 case Opt_nolazytime:
612 sb->s_flags &= ~SB_LAZYTIME;
613 break;

--- 63 unchanged lines hidden (view full) ---

677 case Opt_prjjquota:
678 case Opt_offusrjquota:
679 case Opt_offgrpjquota:
680 case Opt_offprjjquota:
681 case Opt_jqfmt_vfsold:
682 case Opt_jqfmt_vfsv0:
683 case Opt_jqfmt_vfsv1:
684 case Opt_noquota:
706 f2fs_msg(sb, KERN_INFO,
707 "quota operations not supported");
685 f2fs_info(sbi, "quota operations not supported");
708 break;
709#endif
710 case Opt_whint:
711 name = match_strdup(&args[0]);
712 if (!name)
713 return -ENOMEM;
714 if (strlen(name) == 10 &&
715 !strncmp(name, "user-based", 10)) {

--- 45 unchanged lines hidden (view full) ---

761 kvfree(name);
762 return -EINVAL;
763 }
764 kvfree(name);
765 break;
766 case Opt_test_dummy_encryption:
767#ifdef CONFIG_FS_ENCRYPTION
768 if (!f2fs_sb_has_encrypt(sbi)) {
686 break;
687#endif
688 case Opt_whint:
689 name = match_strdup(&args[0]);
690 if (!name)
691 return -ENOMEM;
692 if (strlen(name) == 10 &&
693 !strncmp(name, "user-based", 10)) {

--- 45 unchanged lines hidden (view full) ---

739 kvfree(name);
740 return -EINVAL;
741 }
742 kvfree(name);
743 break;
744 case Opt_test_dummy_encryption:
745#ifdef CONFIG_FS_ENCRYPTION
746 if (!f2fs_sb_has_encrypt(sbi)) {
769 f2fs_msg(sb, KERN_ERR, "Encrypt feature is off");
747 f2fs_err(sbi, "Encrypt feature is off");
770 return -EINVAL;
771 }
772
773 F2FS_OPTION(sbi).test_dummy_encryption = true;
748 return -EINVAL;
749 }
750
751 F2FS_OPTION(sbi).test_dummy_encryption = true;
774 f2fs_msg(sb, KERN_INFO,
775 "Test dummy encryption mode enabled");
752 f2fs_info(sbi, "Test dummy encryption mode enabled");
776#else
753#else
777 f2fs_msg(sb, KERN_INFO,
778 "Test dummy encryption mount option ignored");
754 f2fs_info(sbi, "Test dummy encryption mount option ignored");
779#endif
780 break;
781 case Opt_checkpoint_disable_cap_perc:
782 if (args->from && match_int(args, &arg))
783 return -EINVAL;
784 if (arg < 0 || arg > 100)
785 return -EINVAL;
786 if (arg == 100)

--- 12 unchanged lines hidden (view full) ---

799 break;
800 case Opt_checkpoint_disable:
801 set_opt(sbi, DISABLE_CHECKPOINT);
802 break;
803 case Opt_checkpoint_enable:
804 clear_opt(sbi, DISABLE_CHECKPOINT);
805 break;
806 default:
755#endif
756 break;
757 case Opt_checkpoint_disable_cap_perc:
758 if (args->from && match_int(args, &arg))
759 return -EINVAL;
760 if (arg < 0 || arg > 100)
761 return -EINVAL;
762 if (arg == 100)

--- 12 unchanged lines hidden (view full) ---

775 break;
776 case Opt_checkpoint_disable:
777 set_opt(sbi, DISABLE_CHECKPOINT);
778 break;
779 case Opt_checkpoint_enable:
780 clear_opt(sbi, DISABLE_CHECKPOINT);
781 break;
782 default:
807 f2fs_msg(sb, KERN_ERR,
808 "Unrecognized mount option \"%s\" or missing value",
809 p);
783 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value",
784 p);
810 return -EINVAL;
811 }
812 }
813#ifdef CONFIG_QUOTA
814 if (f2fs_check_quota_options(sbi))
815 return -EINVAL;
816#else
817 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) {
785 return -EINVAL;
786 }
787 }
788#ifdef CONFIG_QUOTA
789 if (f2fs_check_quota_options(sbi))
790 return -EINVAL;
791#else
792 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) {
818 f2fs_msg(sbi->sb, KERN_INFO,
819 "Filesystem with quota feature cannot be mounted RDWR "
820 "without CONFIG_QUOTA");
793 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA");
821 return -EINVAL;
822 }
823 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) {
794 return -EINVAL;
795 }
796 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) {
824 f2fs_msg(sb, KERN_ERR,
825 "Filesystem with project quota feature cannot be "
826 "mounted RDWR without CONFIG_QUOTA");
797 f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA");
827 return -EINVAL;
828 }
829#endif
830
831 if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) {
798 return -EINVAL;
799 }
800#endif
801
802 if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) {
832 f2fs_msg(sb, KERN_ERR,
833 "Should set mode=lfs with %uKB-sized IO",
834 F2FS_IO_SIZE_KB(sbi));
803 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
804 F2FS_IO_SIZE_KB(sbi));
835 return -EINVAL;
836 }
837
838 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
839 int min_size, max_size;
840
841 if (!f2fs_sb_has_extra_attr(sbi) ||
842 !f2fs_sb_has_flexible_inline_xattr(sbi)) {
805 return -EINVAL;
806 }
807
808 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
809 int min_size, max_size;
810
811 if (!f2fs_sb_has_extra_attr(sbi) ||
812 !f2fs_sb_has_flexible_inline_xattr(sbi)) {
843 f2fs_msg(sb, KERN_ERR,
844 "extra_attr or flexible_inline_xattr "
845 "feature is off");
813 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off");
846 return -EINVAL;
847 }
848 if (!test_opt(sbi, INLINE_XATTR)) {
814 return -EINVAL;
815 }
816 if (!test_opt(sbi, INLINE_XATTR)) {
849 f2fs_msg(sb, KERN_ERR,
850 "inline_xattr_size option should be "
851 "set with inline_xattr option");
817 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option");
852 return -EINVAL;
853 }
854
855 min_size = sizeof(struct f2fs_xattr_header) / sizeof(__le32);
856 max_size = MAX_INLINE_XATTR_SIZE;
857
858 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
859 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
818 return -EINVAL;
819 }
820
821 min_size = sizeof(struct f2fs_xattr_header) / sizeof(__le32);
822 max_size = MAX_INLINE_XATTR_SIZE;
823
824 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
825 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
860 f2fs_msg(sb, KERN_ERR,
861 "inline xattr size is out of range: %d ~ %d",
862 min_size, max_size);
826 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
827 min_size, max_size);
863 return -EINVAL;
864 }
865 }
866
867 if (test_opt(sbi, DISABLE_CHECKPOINT) && test_opt(sbi, LFS)) {
828 return -EINVAL;
829 }
830 }
831
832 if (test_opt(sbi, DISABLE_CHECKPOINT) && test_opt(sbi, LFS)) {
868 f2fs_msg(sb, KERN_ERR,
869 "LFS not compatible with checkpoint=disable\n");
833 f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n");
870 return -EINVAL;
871 }
872
873 /* Not pass down write hints if the number of active logs is lesser
874 * than NR_CURSEG_TYPE.
875 */
876 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
877 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;

--- 605 unchanged lines hidden (view full) ---

1483{
1484 unsigned int s_flags = sbi->sb->s_flags;
1485 struct cp_control cpc;
1486 int err = 0;
1487 int ret;
1488 block_t unusable;
1489
1490 if (s_flags & SB_RDONLY) {
834 return -EINVAL;
835 }
836
837 /* Not pass down write hints if the number of active logs is lesser
838 * than NR_CURSEG_TYPE.
839 */
840 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
841 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;

--- 605 unchanged lines hidden (view full) ---

1447{
1448 unsigned int s_flags = sbi->sb->s_flags;
1449 struct cp_control cpc;
1450 int err = 0;
1451 int ret;
1452 block_t unusable;
1453
1454 if (s_flags & SB_RDONLY) {
1491 f2fs_msg(sbi->sb, KERN_ERR,
1492 "checkpoint=disable on readonly fs");
1455 f2fs_err(sbi, "checkpoint=disable on readonly fs");
1493 return -EINVAL;
1494 }
1495 sbi->sb->s_flags |= SB_ACTIVE;
1496
1497 f2fs_update_time(sbi, DISABLE_TIME);
1498
1499 while (!f2fs_time_over(sbi, DISABLE_TIME)) {
1500 mutex_lock(&sbi->gc_mutex);

--- 86 unchanged lines hidden (view full) ---

1587 org_mount_opt.s_qf_names[i] = NULL;
1588 }
1589 }
1590#endif
1591
1592 /* recover superblocks we couldn't write due to previous RO mount */
1593 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) {
1594 err = f2fs_commit_super(sbi, false);
1456 return -EINVAL;
1457 }
1458 sbi->sb->s_flags |= SB_ACTIVE;
1459
1460 f2fs_update_time(sbi, DISABLE_TIME);
1461
1462 while (!f2fs_time_over(sbi, DISABLE_TIME)) {
1463 mutex_lock(&sbi->gc_mutex);

--- 86 unchanged lines hidden (view full) ---

1550 org_mount_opt.s_qf_names[i] = NULL;
1551 }
1552 }
1553#endif
1554
1555 /* recover superblocks we couldn't write due to previous RO mount */
1556 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) {
1557 err = f2fs_commit_super(sbi, false);
1595 f2fs_msg(sb, KERN_INFO,
1596 "Try to recover all the superblocks, ret: %d", err);
1558 f2fs_info(sbi, "Try to recover all the superblocks, ret: %d",
1559 err);
1597 if (!err)
1598 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE);
1599 }
1600
1601 default_options(sbi);
1602
1603 /* parse mount options */
1604 err = parse_options(sb, data);

--- 24 unchanged lines hidden (view full) ---

1629 if (err)
1630 goto restore_opts;
1631 }
1632 }
1633#endif
1634 /* disallow enable/disable extent_cache dynamically */
1635 if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) {
1636 err = -EINVAL;
1560 if (!err)
1561 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE);
1562 }
1563
1564 default_options(sbi);
1565
1566 /* parse mount options */
1567 err = parse_options(sb, data);

--- 24 unchanged lines hidden (view full) ---

1592 if (err)
1593 goto restore_opts;
1594 }
1595 }
1596#endif
1597 /* disallow enable/disable extent_cache dynamically */
1598 if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) {
1599 err = -EINVAL;
1637 f2fs_msg(sbi->sb, KERN_WARNING,
1638 "switch extent_cache option is not allowed");
1600 f2fs_warn(sbi, "switch extent_cache option is not allowed");
1639 goto restore_opts;
1640 }
1641
1642 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) {
1643 err = -EINVAL;
1601 goto restore_opts;
1602 }
1603
1604 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) {
1605 err = -EINVAL;
1644 f2fs_msg(sbi->sb, KERN_WARNING,
1645 "disabling checkpoint not compatible with read-only");
1606 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only");
1646 goto restore_opts;
1647 }
1648
1649 /*
1650 * We stop the GC thread if FS is mounted as RO
1651 * or if background_gc = off is passed in mount
1652 * option. Also sync the filesystem.
1653 */

--- 53 unchanged lines hidden (view full) ---

1707 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
1708
1709 limit_reserve_root(sbi);
1710 *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME);
1711 return 0;
1712restore_gc:
1713 if (need_restart_gc) {
1714 if (f2fs_start_gc_thread(sbi))
1607 goto restore_opts;
1608 }
1609
1610 /*
1611 * We stop the GC thread if FS is mounted as RO
1612 * or if background_gc = off is passed in mount
1613 * option. Also sync the filesystem.
1614 */

--- 53 unchanged lines hidden (view full) ---

1668 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
1669
1670 limit_reserve_root(sbi);
1671 *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME);
1672 return 0;
1673restore_gc:
1674 if (need_restart_gc) {
1675 if (f2fs_start_gc_thread(sbi))
1715 f2fs_msg(sbi->sb, KERN_WARNING,
1716 "background gc thread has stopped");
1676 f2fs_warn(sbi, "background gc thread has stopped");
1717 } else if (need_stop_gc) {
1718 f2fs_stop_gc_thread(sbi);
1719 }
1720restore_opts:
1721#ifdef CONFIG_QUOTA
1722 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt;
1723 for (i = 0; i < MAXQUOTAS; i++) {
1724 kvfree(F2FS_OPTION(sbi).s_qf_names[i]);

--- 122 unchanged lines hidden (view full) ---

1847static qsize_t *f2fs_get_reserved_space(struct inode *inode)
1848{
1849 return &F2FS_I(inode)->i_reserved_quota;
1850}
1851
1852static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type)
1853{
1854 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) {
1677 } else if (need_stop_gc) {
1678 f2fs_stop_gc_thread(sbi);
1679 }
1680restore_opts:
1681#ifdef CONFIG_QUOTA
1682 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt;
1683 for (i = 0; i < MAXQUOTAS; i++) {
1684 kvfree(F2FS_OPTION(sbi).s_qf_names[i]);

--- 122 unchanged lines hidden (view full) ---

1807static qsize_t *f2fs_get_reserved_space(struct inode *inode)
1808{
1809 return &F2FS_I(inode)->i_reserved_quota;
1810}
1811
1812static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type)
1813{
1814 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) {
1855 f2fs_msg(sbi->sb, KERN_ERR,
1856 "quota sysfile may be corrupted, skip loading it");
1815 f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it");
1857 return 0;
1858 }
1859
1860 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type],
1861 F2FS_OPTION(sbi).s_jquota_fmt, type);
1862}
1863
1864int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
1865{
1866 int enabled = 0;
1867 int i, err;
1868
1869 if (f2fs_sb_has_quota_ino(sbi) && rdonly) {
1870 err = f2fs_enable_quotas(sbi->sb);
1871 if (err) {
1816 return 0;
1817 }
1818
1819 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type],
1820 F2FS_OPTION(sbi).s_jquota_fmt, type);
1821}
1822
1823int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
1824{
1825 int enabled = 0;
1826 int i, err;
1827
1828 if (f2fs_sb_has_quota_ino(sbi) && rdonly) {
1829 err = f2fs_enable_quotas(sbi->sb);
1830 if (err) {
1872 f2fs_msg(sbi->sb, KERN_ERR,
1873 "Cannot turn on quota_ino: %d", err);
1831 f2fs_err(sbi, "Cannot turn on quota_ino: %d", err);
1874 return 0;
1875 }
1876 return 1;
1877 }
1878
1879 for (i = 0; i < MAXQUOTAS; i++) {
1880 if (F2FS_OPTION(sbi).s_qf_names[i]) {
1881 err = f2fs_quota_on_mount(sbi, i);
1882 if (!err) {
1883 enabled = 1;
1884 continue;
1885 }
1832 return 0;
1833 }
1834 return 1;
1835 }
1836
1837 for (i = 0; i < MAXQUOTAS; i++) {
1838 if (F2FS_OPTION(sbi).s_qf_names[i]) {
1839 err = f2fs_quota_on_mount(sbi, i);
1840 if (!err) {
1841 enabled = 1;
1842 continue;
1843 }
1886 f2fs_msg(sbi->sb, KERN_ERR,
1887 "Cannot turn on quotas: %d on %d", err, i);
1844 f2fs_err(sbi, "Cannot turn on quotas: %d on %d",
1845 err, i);
1888 }
1889 }
1890 return enabled;
1891}
1892
1893static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,
1894 unsigned int flags)
1895{

--- 4 unchanged lines hidden (view full) ---

1900 BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb)));
1901
1902 qf_inum = f2fs_qf_ino(sb, type);
1903 if (!qf_inum)
1904 return -EPERM;
1905
1906 qf_inode = f2fs_iget(sb, qf_inum);
1907 if (IS_ERR(qf_inode)) {
1846 }
1847 }
1848 return enabled;
1849}
1850
1851static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,
1852 unsigned int flags)
1853{

--- 4 unchanged lines hidden (view full) ---

1858 BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb)));
1859
1860 qf_inum = f2fs_qf_ino(sb, type);
1861 if (!qf_inum)
1862 return -EPERM;
1863
1864 qf_inode = f2fs_iget(sb, qf_inum);
1865 if (IS_ERR(qf_inode)) {
1908 f2fs_msg(sb, KERN_ERR,
1909 "Bad quota inode %u:%lu", type, qf_inum);
1866 f2fs_err(F2FS_SB(sb), "Bad quota inode %u:%lu", type, qf_inum);
1910 return PTR_ERR(qf_inode);
1911 }
1912
1913 /* Don't account quota for quota files to avoid recursion */
1914 qf_inode->i_flags |= S_NOQUOTA;
1915 err = dquot_enable(qf_inode, type, format_id, flags);
1916 iput(qf_inode);
1917 return err;
1918}
1919
1920static int f2fs_enable_quotas(struct super_block *sb)
1921{
1867 return PTR_ERR(qf_inode);
1868 }
1869
1870 /* Don't account quota for quota files to avoid recursion */
1871 qf_inode->i_flags |= S_NOQUOTA;
1872 err = dquot_enable(qf_inode, type, format_id, flags);
1873 iput(qf_inode);
1874 return err;
1875}
1876
1877static int f2fs_enable_quotas(struct super_block *sb)
1878{
1879 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1922 int type, err = 0;
1923 unsigned long qf_inum;
1924 bool quota_mopt[MAXQUOTAS] = {
1880 int type, err = 0;
1881 unsigned long qf_inum;
1882 bool quota_mopt[MAXQUOTAS] = {
1925 test_opt(F2FS_SB(sb), USRQUOTA),
1926 test_opt(F2FS_SB(sb), GRPQUOTA),
1927 test_opt(F2FS_SB(sb), PRJQUOTA),
1883 test_opt(sbi, USRQUOTA),
1884 test_opt(sbi, GRPQUOTA),
1885 test_opt(sbi, PRJQUOTA),
1928 };
1929
1930 if (is_set_ckpt_flags(F2FS_SB(sb), CP_QUOTA_NEED_FSCK_FLAG)) {
1886 };
1887
1888 if (is_set_ckpt_flags(F2FS_SB(sb), CP_QUOTA_NEED_FSCK_FLAG)) {
1931 f2fs_msg(sb, KERN_ERR,
1932 "quota file may be corrupted, skip loading it");
1889 f2fs_err(sbi, "quota file may be corrupted, skip loading it");
1933 return 0;
1934 }
1935
1936 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
1937
1938 for (type = 0; type < MAXQUOTAS; type++) {
1939 qf_inum = f2fs_qf_ino(sb, type);
1940 if (qf_inum) {
1941 err = f2fs_quota_enable(sb, type, QFMT_VFS_V1,
1942 DQUOT_USAGE_ENABLED |
1943 (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
1944 if (err) {
1890 return 0;
1891 }
1892
1893 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
1894
1895 for (type = 0; type < MAXQUOTAS; type++) {
1896 qf_inum = f2fs_qf_ino(sb, type);
1897 if (qf_inum) {
1898 err = f2fs_quota_enable(sb, type, QFMT_VFS_V1,
1899 DQUOT_USAGE_ENABLED |
1900 (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
1901 if (err) {
1945 f2fs_msg(sb, KERN_ERR,
1946 "Failed to enable quota tracking "
1947 "(type=%d, err=%d). Please run "
1948 "fsck to fix.", type, err);
1902 f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
1903 type, err);
1949 for (type--; type >= 0; type--)
1950 dquot_quota_off(sb, type);
1951 set_sbi_flag(F2FS_SB(sb),
1952 SBI_QUOTA_NEED_REPAIR);
1953 return err;
1954 }
1955 }
1956 }

--- 103 unchanged lines hidden (view full) ---

2060 int type;
2061 int err;
2062
2063 for (type = 0; type < MAXQUOTAS; type++) {
2064 err = f2fs_quota_off(sb, type);
2065 if (err) {
2066 int ret = dquot_quota_off(sb, type);
2067
1904 for (type--; type >= 0; type--)
1905 dquot_quota_off(sb, type);
1906 set_sbi_flag(F2FS_SB(sb),
1907 SBI_QUOTA_NEED_REPAIR);
1908 return err;
1909 }
1910 }
1911 }

--- 103 unchanged lines hidden (view full) ---

2015 int type;
2016 int err;
2017
2018 for (type = 0; type < MAXQUOTAS; type++) {
2019 err = f2fs_quota_off(sb, type);
2020 if (err) {
2021 int ret = dquot_quota_off(sb, type);
2022
2068 f2fs_msg(sb, KERN_ERR,
2069 "Fail to turn off disk quota "
2070 "(type: %d, err: %d, ret:%d), Please "
2071 "run fsck to fix it.", type, err, ret);
2023 f2fs_err(F2FS_SB(sb), "Fail to turn off disk quota (type: %d, err: %d, ret:%d), Please run fsck to fix it.",
2024 type, err, ret);
2072 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
2073 }
2074 }
2075 /*
2076 * In case of checkpoint=disable, we must flush quota blocks.
2077 * This can cause NULL exception for node_inode in end_io, since
2078 * put_super already dropped it.
2079 */

--- 276 unchanged lines hidden (view full) ---

2356 u32 segment_count = le32_to_cpu(raw_super->segment_count);
2357 u32 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
2358 u64 main_end_blkaddr = main_blkaddr +
2359 (segment_count_main << log_blocks_per_seg);
2360 u64 seg_end_blkaddr = segment0_blkaddr +
2361 (segment_count << log_blocks_per_seg);
2362
2363 if (segment0_blkaddr != cp_blkaddr) {
2025 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
2026 }
2027 }
2028 /*
2029 * In case of checkpoint=disable, we must flush quota blocks.
2030 * This can cause NULL exception for node_inode in end_io, since
2031 * put_super already dropped it.
2032 */

--- 276 unchanged lines hidden (view full) ---

2309 u32 segment_count = le32_to_cpu(raw_super->segment_count);
2310 u32 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
2311 u64 main_end_blkaddr = main_blkaddr +
2312 (segment_count_main << log_blocks_per_seg);
2313 u64 seg_end_blkaddr = segment0_blkaddr +
2314 (segment_count << log_blocks_per_seg);
2315
2316 if (segment0_blkaddr != cp_blkaddr) {
2364 f2fs_msg(sb, KERN_INFO,
2365 "Mismatch start address, segment0(%u) cp_blkaddr(%u)",
2366 segment0_blkaddr, cp_blkaddr);
2317 f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)",
2318 segment0_blkaddr, cp_blkaddr);
2367 return true;
2368 }
2369
2370 if (cp_blkaddr + (segment_count_ckpt << log_blocks_per_seg) !=
2371 sit_blkaddr) {
2319 return true;
2320 }
2321
2322 if (cp_blkaddr + (segment_count_ckpt << log_blocks_per_seg) !=
2323 sit_blkaddr) {
2372 f2fs_msg(sb, KERN_INFO,
2373 "Wrong CP boundary, start(%u) end(%u) blocks(%u)",
2374 cp_blkaddr, sit_blkaddr,
2375 segment_count_ckpt << log_blocks_per_seg);
2324 f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)",
2325 cp_blkaddr, sit_blkaddr,
2326 segment_count_ckpt << log_blocks_per_seg);
2376 return true;
2377 }
2378
2379 if (sit_blkaddr + (segment_count_sit << log_blocks_per_seg) !=
2380 nat_blkaddr) {
2327 return true;
2328 }
2329
2330 if (sit_blkaddr + (segment_count_sit << log_blocks_per_seg) !=
2331 nat_blkaddr) {
2381 f2fs_msg(sb, KERN_INFO,
2382 "Wrong SIT boundary, start(%u) end(%u) blocks(%u)",
2383 sit_blkaddr, nat_blkaddr,
2384 segment_count_sit << log_blocks_per_seg);
2332 f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)",
2333 sit_blkaddr, nat_blkaddr,
2334 segment_count_sit << log_blocks_per_seg);
2385 return true;
2386 }
2387
2388 if (nat_blkaddr + (segment_count_nat << log_blocks_per_seg) !=
2389 ssa_blkaddr) {
2335 return true;
2336 }
2337
2338 if (nat_blkaddr + (segment_count_nat << log_blocks_per_seg) !=
2339 ssa_blkaddr) {
2390 f2fs_msg(sb, KERN_INFO,
2391 "Wrong NAT boundary, start(%u) end(%u) blocks(%u)",
2392 nat_blkaddr, ssa_blkaddr,
2393 segment_count_nat << log_blocks_per_seg);
2340 f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)",
2341 nat_blkaddr, ssa_blkaddr,
2342 segment_count_nat << log_blocks_per_seg);
2394 return true;
2395 }
2396
2397 if (ssa_blkaddr + (segment_count_ssa << log_blocks_per_seg) !=
2398 main_blkaddr) {
2343 return true;
2344 }
2345
2346 if (ssa_blkaddr + (segment_count_ssa << log_blocks_per_seg) !=
2347 main_blkaddr) {
2399 f2fs_msg(sb, KERN_INFO,
2400 "Wrong SSA boundary, start(%u) end(%u) blocks(%u)",
2401 ssa_blkaddr, main_blkaddr,
2402 segment_count_ssa << log_blocks_per_seg);
2348 f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)",
2349 ssa_blkaddr, main_blkaddr,
2350 segment_count_ssa << log_blocks_per_seg);
2403 return true;
2404 }
2405
2406 if (main_end_blkaddr > seg_end_blkaddr) {
2351 return true;
2352 }
2353
2354 if (main_end_blkaddr > seg_end_blkaddr) {
2407 f2fs_msg(sb, KERN_INFO,
2408 "Wrong MAIN_AREA boundary, start(%u) end(%u) block(%u)",
2409 main_blkaddr,
2410 segment0_blkaddr +
2411 (segment_count << log_blocks_per_seg),
2412 segment_count_main << log_blocks_per_seg);
2355 f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%u) block(%u)",
2356 main_blkaddr,
2357 segment0_blkaddr +
2358 (segment_count << log_blocks_per_seg),
2359 segment_count_main << log_blocks_per_seg);
2413 return true;
2414 } else if (main_end_blkaddr < seg_end_blkaddr) {
2415 int err = 0;
2416 char *res;
2417
2418 /* fix in-memory information all the time */
2419 raw_super->segment_count = cpu_to_le32((main_end_blkaddr -
2420 segment0_blkaddr) >> log_blocks_per_seg);
2421
2422 if (f2fs_readonly(sb) || bdev_read_only(sb->s_bdev)) {
2423 set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
2424 res = "internally";
2425 } else {
2426 err = __f2fs_commit_super(bh, NULL);
2427 res = err ? "failed" : "done";
2428 }
2360 return true;
2361 } else if (main_end_blkaddr < seg_end_blkaddr) {
2362 int err = 0;
2363 char *res;
2364
2365 /* fix in-memory information all the time */
2366 raw_super->segment_count = cpu_to_le32((main_end_blkaddr -
2367 segment0_blkaddr) >> log_blocks_per_seg);
2368
2369 if (f2fs_readonly(sb) || bdev_read_only(sb->s_bdev)) {
2370 set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
2371 res = "internally";
2372 } else {
2373 err = __f2fs_commit_super(bh, NULL);
2374 res = err ? "failed" : "done";
2375 }
2429 f2fs_msg(sb, KERN_INFO,
2430 "Fix alignment : %s, start(%u) end(%u) block(%u)",
2431 res, main_blkaddr,
2432 segment0_blkaddr +
2433 (segment_count << log_blocks_per_seg),
2434 segment_count_main << log_blocks_per_seg);
2376 f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%u) block(%u)",
2377 res, main_blkaddr,
2378 segment0_blkaddr +
2379 (segment_count << log_blocks_per_seg),
2380 segment_count_main << log_blocks_per_seg);
2435 if (err)
2436 return true;
2437 }
2438 return false;
2439}
2440
2441static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
2442 struct buffer_head *bh)
2443{
2444 block_t segment_count, segs_per_sec, secs_per_zone;
2445 block_t total_sections, blocks_per_seg;
2446 struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
2447 (bh->b_data + F2FS_SUPER_OFFSET);
2381 if (err)
2382 return true;
2383 }
2384 return false;
2385}
2386
2387static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
2388 struct buffer_head *bh)
2389{
2390 block_t segment_count, segs_per_sec, secs_per_zone;
2391 block_t total_sections, blocks_per_seg;
2392 struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
2393 (bh->b_data + F2FS_SUPER_OFFSET);
2448 struct super_block *sb = sbi->sb;
2449 unsigned int blocksize;
2450 size_t crc_offset = 0;
2451 __u32 crc = 0;
2452
2453 /* Check checksum_offset and crc in superblock */
2454 if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_SB_CHKSUM)) {
2455 crc_offset = le32_to_cpu(raw_super->checksum_offset);
2456 if (crc_offset !=
2457 offsetof(struct f2fs_super_block, crc)) {
2394 unsigned int blocksize;
2395 size_t crc_offset = 0;
2396 __u32 crc = 0;
2397
2398 /* Check checksum_offset and crc in superblock */
2399 if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_SB_CHKSUM)) {
2400 crc_offset = le32_to_cpu(raw_super->checksum_offset);
2401 if (crc_offset !=
2402 offsetof(struct f2fs_super_block, crc)) {
2458 f2fs_msg(sb, KERN_INFO,
2459 "Invalid SB checksum offset: %zu",
2460 crc_offset);
2403 f2fs_info(sbi, "Invalid SB checksum offset: %zu",
2404 crc_offset);
2461 return 1;
2462 }
2463 crc = le32_to_cpu(raw_super->crc);
2464 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) {
2405 return 1;
2406 }
2407 crc = le32_to_cpu(raw_super->crc);
2408 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) {
2465 f2fs_msg(sb, KERN_INFO,
2466 "Invalid SB checksum value: %u", crc);
2409 f2fs_info(sbi, "Invalid SB checksum value: %u", crc);
2467 return 1;
2468 }
2469 }
2470
2471 if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) {
2410 return 1;
2411 }
2412 }
2413
2414 if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) {
2472 f2fs_msg(sb, KERN_INFO,
2473 "Magic Mismatch, valid(0x%x) - read(0x%x)",
2474 F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
2415 f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)",
2416 F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
2475 return 1;
2476 }
2477
2478 /* Currently, support only 4KB page cache size */
2479 if (F2FS_BLKSIZE != PAGE_SIZE) {
2417 return 1;
2418 }
2419
2420 /* Currently, support only 4KB page cache size */
2421 if (F2FS_BLKSIZE != PAGE_SIZE) {
2480 f2fs_msg(sb, KERN_INFO,
2481 "Invalid page_cache_size (%lu), supports only 4KB",
2482 PAGE_SIZE);
2422 f2fs_info(sbi, "Invalid page_cache_size (%lu), supports only 4KB",
2423 PAGE_SIZE);
2483 return 1;
2484 }
2485
2486 /* Currently, support only 4KB block size */
2487 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize);
2488 if (blocksize != F2FS_BLKSIZE) {
2424 return 1;
2425 }
2426
2427 /* Currently, support only 4KB block size */
2428 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize);
2429 if (blocksize != F2FS_BLKSIZE) {
2489 f2fs_msg(sb, KERN_INFO,
2490 "Invalid blocksize (%u), supports only 4KB",
2491 blocksize);
2430 f2fs_info(sbi, "Invalid blocksize (%u), supports only 4KB",
2431 blocksize);
2492 return 1;
2493 }
2494
2495 /* check log blocks per segment */
2496 if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) {
2432 return 1;
2433 }
2434
2435 /* check log blocks per segment */
2436 if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) {
2497 f2fs_msg(sb, KERN_INFO,
2498 "Invalid log blocks per segment (%u)",
2499 le32_to_cpu(raw_super->log_blocks_per_seg));
2437 f2fs_info(sbi, "Invalid log blocks per segment (%u)",
2438 le32_to_cpu(raw_super->log_blocks_per_seg));
2500 return 1;
2501 }
2502
2503 /* Currently, support 512/1024/2048/4096 bytes sector size */
2504 if (le32_to_cpu(raw_super->log_sectorsize) >
2505 F2FS_MAX_LOG_SECTOR_SIZE ||
2506 le32_to_cpu(raw_super->log_sectorsize) <
2507 F2FS_MIN_LOG_SECTOR_SIZE) {
2439 return 1;
2440 }
2441
2442 /* Currently, support 512/1024/2048/4096 bytes sector size */
2443 if (le32_to_cpu(raw_super->log_sectorsize) >
2444 F2FS_MAX_LOG_SECTOR_SIZE ||
2445 le32_to_cpu(raw_super->log_sectorsize) <
2446 F2FS_MIN_LOG_SECTOR_SIZE) {
2508 f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize (%u)",
2509 le32_to_cpu(raw_super->log_sectorsize));
2447 f2fs_info(sbi, "Invalid log sectorsize (%u)",
2448 le32_to_cpu(raw_super->log_sectorsize));
2510 return 1;
2511 }
2512 if (le32_to_cpu(raw_super->log_sectors_per_block) +
2513 le32_to_cpu(raw_super->log_sectorsize) !=
2514 F2FS_MAX_LOG_SECTOR_SIZE) {
2449 return 1;
2450 }
2451 if (le32_to_cpu(raw_super->log_sectors_per_block) +
2452 le32_to_cpu(raw_super->log_sectorsize) !=
2453 F2FS_MAX_LOG_SECTOR_SIZE) {
2515 f2fs_msg(sb, KERN_INFO,
2516 "Invalid log sectors per block(%u) log sectorsize(%u)",
2517 le32_to_cpu(raw_super->log_sectors_per_block),
2518 le32_to_cpu(raw_super->log_sectorsize));
2454 f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)",
2455 le32_to_cpu(raw_super->log_sectors_per_block),
2456 le32_to_cpu(raw_super->log_sectorsize));
2519 return 1;
2520 }
2521
2522 segment_count = le32_to_cpu(raw_super->segment_count);
2523 segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
2524 secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
2525 total_sections = le32_to_cpu(raw_super->section_count);
2526
2527 /* blocks_per_seg should be 512, given the above check */
2528 blocks_per_seg = 1 << le32_to_cpu(raw_super->log_blocks_per_seg);
2529
2530 if (segment_count > F2FS_MAX_SEGMENT ||
2531 segment_count < F2FS_MIN_SEGMENTS) {
2457 return 1;
2458 }
2459
2460 segment_count = le32_to_cpu(raw_super->segment_count);
2461 segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
2462 secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
2463 total_sections = le32_to_cpu(raw_super->section_count);
2464
2465 /* blocks_per_seg should be 512, given the above check */
2466 blocks_per_seg = 1 << le32_to_cpu(raw_super->log_blocks_per_seg);
2467
2468 if (segment_count > F2FS_MAX_SEGMENT ||
2469 segment_count < F2FS_MIN_SEGMENTS) {
2532 f2fs_msg(sb, KERN_INFO,
2533 "Invalid segment count (%u)",
2534 segment_count);
2470 f2fs_info(sbi, "Invalid segment count (%u)", segment_count);
2535 return 1;
2536 }
2537
2538 if (total_sections > segment_count ||
2539 total_sections < F2FS_MIN_SEGMENTS ||
2540 segs_per_sec > segment_count || !segs_per_sec) {
2471 return 1;
2472 }
2473
2474 if (total_sections > segment_count ||
2475 total_sections < F2FS_MIN_SEGMENTS ||
2476 segs_per_sec > segment_count || !segs_per_sec) {
2541 f2fs_msg(sb, KERN_INFO,
2542 "Invalid segment/section count (%u, %u x %u)",
2543 segment_count, total_sections, segs_per_sec);
2477 f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
2478 segment_count, total_sections, segs_per_sec);
2544 return 1;
2545 }
2546
2547 if ((segment_count / segs_per_sec) < total_sections) {
2479 return 1;
2480 }
2481
2482 if ((segment_count / segs_per_sec) < total_sections) {
2548 f2fs_msg(sb, KERN_INFO,
2549 "Small segment_count (%u < %u * %u)",
2550 segment_count, segs_per_sec, total_sections);
2483 f2fs_info(sbi, "Small segment_count (%u < %u * %u)",
2484 segment_count, segs_per_sec, total_sections);
2551 return 1;
2552 }
2553
2554 if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) {
2485 return 1;
2486 }
2487
2488 if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) {
2555 f2fs_msg(sb, KERN_INFO,
2556 "Wrong segment_count / block_count (%u > %llu)",
2557 segment_count, le64_to_cpu(raw_super->block_count));
2489 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)",
2490 segment_count, le64_to_cpu(raw_super->block_count));
2558 return 1;
2559 }
2560
2561 if (secs_per_zone > total_sections || !secs_per_zone) {
2491 return 1;
2492 }
2493
2494 if (secs_per_zone > total_sections || !secs_per_zone) {
2562 f2fs_msg(sb, KERN_INFO,
2563 "Wrong secs_per_zone / total_sections (%u, %u)",
2564 secs_per_zone, total_sections);
2495 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)",
2496 secs_per_zone, total_sections);
2565 return 1;
2566 }
2567 if (le32_to_cpu(raw_super->extension_count) > F2FS_MAX_EXTENSION ||
2568 raw_super->hot_ext_count > F2FS_MAX_EXTENSION ||
2569 (le32_to_cpu(raw_super->extension_count) +
2570 raw_super->hot_ext_count) > F2FS_MAX_EXTENSION) {
2497 return 1;
2498 }
2499 if (le32_to_cpu(raw_super->extension_count) > F2FS_MAX_EXTENSION ||
2500 raw_super->hot_ext_count > F2FS_MAX_EXTENSION ||
2501 (le32_to_cpu(raw_super->extension_count) +
2502 raw_super->hot_ext_count) > F2FS_MAX_EXTENSION) {
2571 f2fs_msg(sb, KERN_INFO,
2572 "Corrupted extension count (%u + %u > %u)",
2573 le32_to_cpu(raw_super->extension_count),
2574 raw_super->hot_ext_count,
2575 F2FS_MAX_EXTENSION);
2503 f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)",
2504 le32_to_cpu(raw_super->extension_count),
2505 raw_super->hot_ext_count,
2506 F2FS_MAX_EXTENSION);
2576 return 1;
2577 }
2578
2579 if (le32_to_cpu(raw_super->cp_payload) >
2580 (blocks_per_seg - F2FS_CP_PACKS)) {
2507 return 1;
2508 }
2509
2510 if (le32_to_cpu(raw_super->cp_payload) >
2511 (blocks_per_seg - F2FS_CP_PACKS)) {
2581 f2fs_msg(sb, KERN_INFO,
2582 "Insane cp_payload (%u > %u)",
2583 le32_to_cpu(raw_super->cp_payload),
2584 blocks_per_seg - F2FS_CP_PACKS);
2512 f2fs_info(sbi, "Insane cp_payload (%u > %u)",
2513 le32_to_cpu(raw_super->cp_payload),
2514 blocks_per_seg - F2FS_CP_PACKS);
2585 return 1;
2586 }
2587
2588 /* check reserved ino info */
2589 if (le32_to_cpu(raw_super->node_ino) != 1 ||
2590 le32_to_cpu(raw_super->meta_ino) != 2 ||
2591 le32_to_cpu(raw_super->root_ino) != 3) {
2515 return 1;
2516 }
2517
2518 /* check reserved ino info */
2519 if (le32_to_cpu(raw_super->node_ino) != 1 ||
2520 le32_to_cpu(raw_super->meta_ino) != 2 ||
2521 le32_to_cpu(raw_super->root_ino) != 3) {
2592 f2fs_msg(sb, KERN_INFO,
2593 "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
2594 le32_to_cpu(raw_super->node_ino),
2595 le32_to_cpu(raw_super->meta_ino),
2596 le32_to_cpu(raw_super->root_ino));
2522 f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
2523 le32_to_cpu(raw_super->node_ino),
2524 le32_to_cpu(raw_super->meta_ino),
2525 le32_to_cpu(raw_super->root_ino));
2597 return 1;
2598 }
2599
2600 /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
2601 if (sanity_check_area_boundary(sbi, bh))
2602 return 1;
2603
2604 return 0;

--- 27 unchanged lines hidden (view full) ---

2632 if (unlikely(fsmeta >= total))
2633 return 1;
2634
2635 ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
2636 reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
2637
2638 if (unlikely(fsmeta < F2FS_MIN_SEGMENTS ||
2639 ovp_segments == 0 || reserved_segments == 0)) {
2526 return 1;
2527 }
2528
2529 /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
2530 if (sanity_check_area_boundary(sbi, bh))
2531 return 1;
2532
2533 return 0;

--- 27 unchanged lines hidden (view full) ---

2561 if (unlikely(fsmeta >= total))
2562 return 1;
2563
2564 ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
2565 reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
2566
2567 if (unlikely(fsmeta < F2FS_MIN_SEGMENTS ||
2568 ovp_segments == 0 || reserved_segments == 0)) {
2640 f2fs_msg(sbi->sb, KERN_ERR,
2641 "Wrong layout: check mkfs.f2fs version");
2569 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
2642 return 1;
2643 }
2644
2645 user_block_count = le64_to_cpu(ckpt->user_block_count);
2646 segment_count_main = le32_to_cpu(raw_super->segment_count_main);
2647 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
2648 if (!user_block_count || user_block_count >=
2649 segment_count_main << log_blocks_per_seg) {
2570 return 1;
2571 }
2572
2573 user_block_count = le64_to_cpu(ckpt->user_block_count);
2574 segment_count_main = le32_to_cpu(raw_super->segment_count_main);
2575 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
2576 if (!user_block_count || user_block_count >=
2577 segment_count_main << log_blocks_per_seg) {
2650 f2fs_msg(sbi->sb, KERN_ERR,
2651 "Wrong user_block_count: %u", user_block_count);
2578 f2fs_err(sbi, "Wrong user_block_count: %u",
2579 user_block_count);
2652 return 1;
2653 }
2654
2655 valid_user_blocks = le64_to_cpu(ckpt->valid_block_count);
2656 if (valid_user_blocks > user_block_count) {
2580 return 1;
2581 }
2582
2583 valid_user_blocks = le64_to_cpu(ckpt->valid_block_count);
2584 if (valid_user_blocks > user_block_count) {
2657 f2fs_msg(sbi->sb, KERN_ERR,
2658 "Wrong valid_user_blocks: %u, user_block_count: %u",
2659 valid_user_blocks, user_block_count);
2585 f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u",
2586 valid_user_blocks, user_block_count);
2660 return 1;
2661 }
2662
2663 valid_node_count = le32_to_cpu(ckpt->valid_node_count);
2664 avail_node_count = sbi->total_node_count - sbi->nquota_files -
2665 F2FS_RESERVED_NODE_NUM;
2666 if (valid_node_count > avail_node_count) {
2587 return 1;
2588 }
2589
2590 valid_node_count = le32_to_cpu(ckpt->valid_node_count);
2591 avail_node_count = sbi->total_node_count - sbi->nquota_files -
2592 F2FS_RESERVED_NODE_NUM;
2593 if (valid_node_count > avail_node_count) {
2667 f2fs_msg(sbi->sb, KERN_ERR,
2668 "Wrong valid_node_count: %u, avail_node_count: %u",
2669 valid_node_count, avail_node_count);
2594 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u",
2595 valid_node_count, avail_node_count);
2670 return 1;
2671 }
2672
2673 main_segs = le32_to_cpu(raw_super->segment_count_main);
2674 blocks_per_seg = sbi->blocks_per_seg;
2675
2676 for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
2677 if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
2678 le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
2679 return 1;
2680 for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
2681 if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
2682 le32_to_cpu(ckpt->cur_node_segno[j])) {
2596 return 1;
2597 }
2598
2599 main_segs = le32_to_cpu(raw_super->segment_count_main);
2600 blocks_per_seg = sbi->blocks_per_seg;
2601
2602 for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
2603 if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
2604 le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
2605 return 1;
2606 for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
2607 if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
2608 le32_to_cpu(ckpt->cur_node_segno[j])) {
2683 f2fs_msg(sbi->sb, KERN_ERR,
2684 "Node segment (%u, %u) has the same "
2685 "segno: %u", i, j,
2686 le32_to_cpu(ckpt->cur_node_segno[i]));
2609 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u",
2610 i, j,
2611 le32_to_cpu(ckpt->cur_node_segno[i]));
2687 return 1;
2688 }
2689 }
2690 }
2691 for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
2692 if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
2693 le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
2694 return 1;
2695 for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
2696 if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
2697 le32_to_cpu(ckpt->cur_data_segno[j])) {
2612 return 1;
2613 }
2614 }
2615 }
2616 for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
2617 if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
2618 le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
2619 return 1;
2620 for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
2621 if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
2622 le32_to_cpu(ckpt->cur_data_segno[j])) {
2698 f2fs_msg(sbi->sb, KERN_ERR,
2699 "Data segment (%u, %u) has the same "
2700 "segno: %u", i, j,
2701 le32_to_cpu(ckpt->cur_data_segno[i]));
2623 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u",
2624 i, j,
2625 le32_to_cpu(ckpt->cur_data_segno[i]));
2702 return 1;
2703 }
2704 }
2705 }
2706 for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
2707 for (j = i; j < NR_CURSEG_DATA_TYPE; j++) {
2708 if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
2709 le32_to_cpu(ckpt->cur_data_segno[j])) {
2626 return 1;
2627 }
2628 }
2629 }
2630 for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
2631 for (j = i; j < NR_CURSEG_DATA_TYPE; j++) {
2632 if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
2633 le32_to_cpu(ckpt->cur_data_segno[j])) {
2710 f2fs_msg(sbi->sb, KERN_ERR,
2711 "Data segment (%u) and Data segment (%u)"
2712 " has the same segno: %u", i, j,
2713 le32_to_cpu(ckpt->cur_node_segno[i]));
2634 f2fs_err(sbi, "Data segment (%u) and Data segment (%u) has the same segno: %u",
2635 i, j,
2636 le32_to_cpu(ckpt->cur_node_segno[i]));
2714 return 1;
2715 }
2716 }
2717 }
2718
2719 sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
2720 nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
2721
2722 if (sit_bitmap_size != ((sit_segs / 2) << log_blocks_per_seg) / 8 ||
2723 nat_bitmap_size != ((nat_segs / 2) << log_blocks_per_seg) / 8) {
2637 return 1;
2638 }
2639 }
2640 }
2641
2642 sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
2643 nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
2644
2645 if (sit_bitmap_size != ((sit_segs / 2) << log_blocks_per_seg) / 8 ||
2646 nat_bitmap_size != ((nat_segs / 2) << log_blocks_per_seg) / 8) {
2724 f2fs_msg(sbi->sb, KERN_ERR,
2725 "Wrong bitmap size: sit: %u, nat:%u",
2726 sit_bitmap_size, nat_bitmap_size);
2647 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u",
2648 sit_bitmap_size, nat_bitmap_size);
2727 return 1;
2728 }
2729
2730 cp_pack_start_sum = __start_sum_addr(sbi);
2731 cp_payload = __cp_payload(sbi);
2732 if (cp_pack_start_sum < cp_payload + 1 ||
2733 cp_pack_start_sum > blocks_per_seg - 1 -
2734 NR_CURSEG_TYPE) {
2649 return 1;
2650 }
2651
2652 cp_pack_start_sum = __start_sum_addr(sbi);
2653 cp_payload = __cp_payload(sbi);
2654 if (cp_pack_start_sum < cp_payload + 1 ||
2655 cp_pack_start_sum > blocks_per_seg - 1 -
2656 NR_CURSEG_TYPE) {
2735 f2fs_msg(sbi->sb, KERN_ERR,
2736 "Wrong cp_pack_start_sum: %u",
2737 cp_pack_start_sum);
2657 f2fs_err(sbi, "Wrong cp_pack_start_sum: %u",
2658 cp_pack_start_sum);
2738 return 1;
2739 }
2740
2741 if (__is_set_ckpt_flags(ckpt, CP_LARGE_NAT_BITMAP_FLAG) &&
2742 le32_to_cpu(ckpt->checksum_offset) != CP_MIN_CHKSUM_OFFSET) {
2659 return 1;
2660 }
2661
2662 if (__is_set_ckpt_flags(ckpt, CP_LARGE_NAT_BITMAP_FLAG) &&
2663 le32_to_cpu(ckpt->checksum_offset) != CP_MIN_CHKSUM_OFFSET) {
2743 f2fs_msg(sbi->sb, KERN_WARNING,
2744 "layout of large_nat_bitmap is deprecated, "
2745 "run fsck to repair, chksum_offset: %u",
2746 le32_to_cpu(ckpt->checksum_offset));
2664 f2fs_warn(sbi, "layout of large_nat_bitmap is deprecated, run fsck to repair, chksum_offset: %u",
2665 le32_to_cpu(ckpt->checksum_offset));
2747 return 1;
2748 }
2749
2750 if (unlikely(f2fs_cp_error(sbi))) {
2666 return 1;
2667 }
2668
2669 if (unlikely(f2fs_cp_error(sbi))) {
2751 f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck");
2670 f2fs_err(sbi, "A bug case: need to run fsck");
2752 return 1;
2753 }
2754 return 0;
2755}
2756
2757static void init_sb_info(struct f2fs_sb_info *sbi)
2758{
2759 struct f2fs_super_block *raw_super = sbi->raw_super;

--- 152 unchanged lines hidden (view full) ---

2912
2913 super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL);
2914 if (!super)
2915 return -ENOMEM;
2916
2917 for (block = 0; block < 2; block++) {
2918 bh = sb_bread(sb, block);
2919 if (!bh) {
2671 return 1;
2672 }
2673 return 0;
2674}
2675
2676static void init_sb_info(struct f2fs_sb_info *sbi)
2677{
2678 struct f2fs_super_block *raw_super = sbi->raw_super;

--- 152 unchanged lines hidden (view full) ---

2831
2832 super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL);
2833 if (!super)
2834 return -ENOMEM;
2835
2836 for (block = 0; block < 2; block++) {
2837 bh = sb_bread(sb, block);
2838 if (!bh) {
2920 f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock",
2921 block + 1);
2839 f2fs_err(sbi, "Unable to read %dth superblock",
2840 block + 1);
2922 err = -EIO;
2923 continue;
2924 }
2925
2926 /* sanity checking of raw super */
2927 if (sanity_check_raw_super(sbi, bh)) {
2841 err = -EIO;
2842 continue;
2843 }
2844
2845 /* sanity checking of raw super */
2846 if (sanity_check_raw_super(sbi, bh)) {
2928 f2fs_msg(sb, KERN_ERR,
2929 "Can't find valid F2FS filesystem in %dth superblock",
2930 block + 1);
2847 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock",
2848 block + 1);
2931 err = -EINVAL;
2932 brelse(bh);
2933 continue;
2934 }
2935
2936 if (!*raw_super) {
2937 memcpy(super, bh->b_data + F2FS_SUPER_OFFSET,
2938 sizeof(*super));

--- 113 unchanged lines hidden (view full) ---

3052 return PTR_ERR(FDEV(i).bdev);
3053
3054 /* to release errored devices */
3055 sbi->s_ndevs = i + 1;
3056
3057#ifdef CONFIG_BLK_DEV_ZONED
3058 if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM &&
3059 !f2fs_sb_has_blkzoned(sbi)) {
2849 err = -EINVAL;
2850 brelse(bh);
2851 continue;
2852 }
2853
2854 if (!*raw_super) {
2855 memcpy(super, bh->b_data + F2FS_SUPER_OFFSET,
2856 sizeof(*super));

--- 113 unchanged lines hidden (view full) ---

2970 return PTR_ERR(FDEV(i).bdev);
2971
2972 /* to release errored devices */
2973 sbi->s_ndevs = i + 1;
2974
2975#ifdef CONFIG_BLK_DEV_ZONED
2976 if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM &&
2977 !f2fs_sb_has_blkzoned(sbi)) {
3060 f2fs_msg(sbi->sb, KERN_ERR,
3061 "Zoned block device feature not enabled\n");
2978 f2fs_err(sbi, "Zoned block device feature not enabled\n");
3062 return -EINVAL;
3063 }
3064 if (bdev_zoned_model(FDEV(i).bdev) != BLK_ZONED_NONE) {
3065 if (init_blkz_info(sbi, i)) {
2979 return -EINVAL;
2980 }
2981 if (bdev_zoned_model(FDEV(i).bdev) != BLK_ZONED_NONE) {
2982 if (init_blkz_info(sbi, i)) {
3066 f2fs_msg(sbi->sb, KERN_ERR,
3067 "Failed to initialize F2FS blkzone information");
2983 f2fs_err(sbi, "Failed to initialize F2FS blkzone information");
3068 return -EINVAL;
3069 }
3070 if (max_devices == 1)
3071 break;
2984 return -EINVAL;
2985 }
2986 if (max_devices == 1)
2987 break;
3072 f2fs_msg(sbi->sb, KERN_INFO,
3073 "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
3074 i, FDEV(i).path,
3075 FDEV(i).total_segments,
3076 FDEV(i).start_blk, FDEV(i).end_blk,
3077 bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HA ?
3078 "Host-aware" : "Host-managed");
2988 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
2989 i, FDEV(i).path,
2990 FDEV(i).total_segments,
2991 FDEV(i).start_blk, FDEV(i).end_blk,
2992 bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HA ?
2993 "Host-aware" : "Host-managed");
3079 continue;
3080 }
3081#endif
2994 continue;
2995 }
2996#endif
3082 f2fs_msg(sbi->sb, KERN_INFO,
3083 "Mount Device [%2d]: %20s, %8u, %8x - %8x",
3084 i, FDEV(i).path,
3085 FDEV(i).total_segments,
3086 FDEV(i).start_blk, FDEV(i).end_blk);
2997 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x",
2998 i, FDEV(i).path,
2999 FDEV(i).total_segments,
3000 FDEV(i).start_blk, FDEV(i).end_blk);
3087 }
3001 }
3088 f2fs_msg(sbi->sb, KERN_INFO,
3089 "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi));
3002 f2fs_info(sbi,
3003 "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi));
3090 return 0;
3091}
3092
3093static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
3094{
3095 struct f2fs_sm_info *sm_i = SM_I(sbi);
3096
3097 /* adjust parameters according to the volume size */

--- 29 unchanged lines hidden (view full) ---

3127 if (!sbi)
3128 return -ENOMEM;
3129
3130 sbi->sb = sb;
3131
3132 /* Load the checksum driver */
3133 sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
3134 if (IS_ERR(sbi->s_chksum_driver)) {
3004 return 0;
3005}
3006
3007static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
3008{
3009 struct f2fs_sm_info *sm_i = SM_I(sbi);
3010
3011 /* adjust parameters according to the volume size */

--- 29 unchanged lines hidden (view full) ---

3041 if (!sbi)
3042 return -ENOMEM;
3043
3044 sbi->sb = sb;
3045
3046 /* Load the checksum driver */
3047 sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
3048 if (IS_ERR(sbi->s_chksum_driver)) {
3135 f2fs_msg(sb, KERN_ERR, "Cannot load crc32 driver.");
3049 f2fs_err(sbi, "Cannot load crc32 driver.");
3136 err = PTR_ERR(sbi->s_chksum_driver);
3137 sbi->s_chksum_driver = NULL;
3138 goto free_sbi;
3139 }
3140
3141 /* set a block size */
3142 if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
3050 err = PTR_ERR(sbi->s_chksum_driver);
3051 sbi->s_chksum_driver = NULL;
3052 goto free_sbi;
3053 }
3054
3055 /* set a block size */
3056 if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
3143 f2fs_msg(sb, KERN_ERR, "unable to set blocksize");
3057 f2fs_err(sbi, "unable to set blocksize");
3144 goto free_sbi;
3145 }
3146
3147 err = read_raw_super_block(sbi, &raw_super, &valid_super_block,
3148 &recovery);
3149 if (err)
3150 goto free_sbi;
3151

--- 7 unchanged lines hidden (view full) ---

3159
3160 /*
3161 * The BLKZONED feature indicates that the drive was formatted with
3162 * zone alignment optimization. This is optional for host-aware
3163 * devices, but mandatory for host-managed zoned block devices.
3164 */
3165#ifndef CONFIG_BLK_DEV_ZONED
3166 if (f2fs_sb_has_blkzoned(sbi)) {
3058 goto free_sbi;
3059 }
3060
3061 err = read_raw_super_block(sbi, &raw_super, &valid_super_block,
3062 &recovery);
3063 if (err)
3064 goto free_sbi;
3065

--- 7 unchanged lines hidden (view full) ---

3073
3074 /*
3075 * The BLKZONED feature indicates that the drive was formatted with
3076 * zone alignment optimization. This is optional for host-aware
3077 * devices, but mandatory for host-managed zoned block devices.
3078 */
3079#ifndef CONFIG_BLK_DEV_ZONED
3080 if (f2fs_sb_has_blkzoned(sbi)) {
3167 f2fs_msg(sb, KERN_ERR,
3168 "Zoned block device support is not enabled");
3081 f2fs_err(sbi, "Zoned block device support is not enabled");
3169 err = -EOPNOTSUPP;
3170 goto free_sb_buf;
3171 }
3172#endif
3173 default_options(sbi);
3174 /* parse mount options */
3175 options = kstrdup((const char *)data, GFP_KERNEL);
3176 if (data && !options) {

--- 91 unchanged lines hidden (view full) ---

3268 err = -ENOMEM;
3269 goto free_percpu;
3270 }
3271 }
3272
3273 /* get an inode for meta space */
3274 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
3275 if (IS_ERR(sbi->meta_inode)) {
3082 err = -EOPNOTSUPP;
3083 goto free_sb_buf;
3084 }
3085#endif
3086 default_options(sbi);
3087 /* parse mount options */
3088 options = kstrdup((const char *)data, GFP_KERNEL);
3089 if (data && !options) {

--- 91 unchanged lines hidden (view full) ---

3181 err = -ENOMEM;
3182 goto free_percpu;
3183 }
3184 }
3185
3186 /* get an inode for meta space */
3187 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
3188 if (IS_ERR(sbi->meta_inode)) {
3276 f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode");
3189 f2fs_err(sbi, "Failed to read F2FS meta data inode");
3277 err = PTR_ERR(sbi->meta_inode);
3278 goto free_io_dummy;
3279 }
3280
3281 err = f2fs_get_valid_checkpoint(sbi);
3282 if (err) {
3190 err = PTR_ERR(sbi->meta_inode);
3191 goto free_io_dummy;
3192 }
3193
3194 err = f2fs_get_valid_checkpoint(sbi);
3195 if (err) {
3283 f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint");
3196 f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
3284 goto free_meta_inode;
3285 }
3286
3287 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
3288 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3289 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) {
3290 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
3291 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL;
3292 }
3293
3294 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG))
3295 set_sbi_flag(sbi, SBI_NEED_FSCK);
3296
3297 /* Initialize device list */
3298 err = f2fs_scan_devices(sbi);
3299 if (err) {
3197 goto free_meta_inode;
3198 }
3199
3200 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
3201 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3202 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) {
3203 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
3204 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL;
3205 }
3206
3207 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG))
3208 set_sbi_flag(sbi, SBI_NEED_FSCK);
3209
3210 /* Initialize device list */
3211 err = f2fs_scan_devices(sbi);
3212 if (err) {
3300 f2fs_msg(sb, KERN_ERR, "Failed to find devices");
3213 f2fs_err(sbi, "Failed to find devices");
3301 goto free_devices;
3302 }
3303
3304 sbi->total_valid_node_count =
3305 le32_to_cpu(sbi->ckpt->valid_node_count);
3306 percpu_counter_set(&sbi->total_valid_inode_count,
3307 le32_to_cpu(sbi->ckpt->valid_inode_count));
3308 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);

--- 14 unchanged lines hidden (view full) ---

3323
3324 f2fs_init_ino_entry_info(sbi);
3325
3326 f2fs_init_fsync_node_info(sbi);
3327
3328 /* setup f2fs internal modules */
3329 err = f2fs_build_segment_manager(sbi);
3330 if (err) {
3214 goto free_devices;
3215 }
3216
3217 sbi->total_valid_node_count =
3218 le32_to_cpu(sbi->ckpt->valid_node_count);
3219 percpu_counter_set(&sbi->total_valid_inode_count,
3220 le32_to_cpu(sbi->ckpt->valid_inode_count));
3221 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);

--- 14 unchanged lines hidden (view full) ---

3236
3237 f2fs_init_ino_entry_info(sbi);
3238
3239 f2fs_init_fsync_node_info(sbi);
3240
3241 /* setup f2fs internal modules */
3242 err = f2fs_build_segment_manager(sbi);
3243 if (err) {
3331 f2fs_msg(sb, KERN_ERR,
3332 "Failed to initialize F2FS segment manager (%d)", err);
3244 f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)",
3245 err);
3333 goto free_sm;
3334 }
3335 err = f2fs_build_node_manager(sbi);
3336 if (err) {
3246 goto free_sm;
3247 }
3248 err = f2fs_build_node_manager(sbi);
3249 if (err) {
3337 f2fs_msg(sb, KERN_ERR,
3338 "Failed to initialize F2FS node manager (%d)", err);
3250 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)",
3251 err);
3339 goto free_nm;
3340 }
3341
3342 /* For write statistics */
3343 if (sb->s_bdev->bd_part)
3344 sbi->sectors_written_start =
3345 (u64)part_stat_read(sb->s_bdev->bd_part,
3346 sectors[STAT_WRITE]);

--- 8 unchanged lines hidden (view full) ---

3355
3356 err = f2fs_build_stats(sbi);
3357 if (err)
3358 goto free_nm;
3359
3360 /* get an inode for node space */
3361 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
3362 if (IS_ERR(sbi->node_inode)) {
3252 goto free_nm;
3253 }
3254
3255 /* For write statistics */
3256 if (sb->s_bdev->bd_part)
3257 sbi->sectors_written_start =
3258 (u64)part_stat_read(sb->s_bdev->bd_part,
3259 sectors[STAT_WRITE]);

--- 8 unchanged lines hidden (view full) ---

3268
3269 err = f2fs_build_stats(sbi);
3270 if (err)
3271 goto free_nm;
3272
3273 /* get an inode for node space */
3274 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
3275 if (IS_ERR(sbi->node_inode)) {
3363 f2fs_msg(sb, KERN_ERR, "Failed to read node inode");
3276 f2fs_err(sbi, "Failed to read node inode");
3364 err = PTR_ERR(sbi->node_inode);
3365 goto free_stats;
3366 }
3367
3368 /* read root inode and dentry */
3369 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
3370 if (IS_ERR(root)) {
3277 err = PTR_ERR(sbi->node_inode);
3278 goto free_stats;
3279 }
3280
3281 /* read root inode and dentry */
3282 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
3283 if (IS_ERR(root)) {
3371 f2fs_msg(sb, KERN_ERR, "Failed to read root inode");
3284 f2fs_err(sbi, "Failed to read root inode");
3372 err = PTR_ERR(root);
3373 goto free_node_inode;
3374 }
3375 if (!S_ISDIR(root->i_mode) || !root->i_blocks ||
3376 !root->i_size || !root->i_nlink) {
3377 iput(root);
3378 err = -EINVAL;
3379 goto free_node_inode;

--- 9 unchanged lines hidden (view full) ---

3389 if (err)
3390 goto free_root_inode;
3391
3392#ifdef CONFIG_QUOTA
3393 /* Enable quota usage during mount */
3394 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) {
3395 err = f2fs_enable_quotas(sb);
3396 if (err)
3285 err = PTR_ERR(root);
3286 goto free_node_inode;
3287 }
3288 if (!S_ISDIR(root->i_mode) || !root->i_blocks ||
3289 !root->i_size || !root->i_nlink) {
3290 iput(root);
3291 err = -EINVAL;
3292 goto free_node_inode;

--- 9 unchanged lines hidden (view full) ---

3302 if (err)
3303 goto free_root_inode;
3304
3305#ifdef CONFIG_QUOTA
3306 /* Enable quota usage during mount */
3307 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) {
3308 err = f2fs_enable_quotas(sb);
3309 if (err)
3397 f2fs_msg(sb, KERN_ERR,
3398 "Cannot turn on quotas: error %d", err);
3310 f2fs_err(sbi, "Cannot turn on quotas: error %d", err);
3399 }
3400#endif
3401 /* if there are nt orphan nodes free them */
3402 err = f2fs_recover_orphan_inodes(sbi);
3403 if (err)
3404 goto free_meta;
3405
3406 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)))
3407 goto reset_checkpoint;
3408
3409 /* recover fsynced data */
3410 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
3411 /*
3412 * mount should be failed, when device has readonly mode, and
3413 * previous checkpoint was not done by clean system shutdown.
3414 */
3415 if (f2fs_hw_is_readonly(sbi)) {
3416 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
3417 err = -EROFS;
3311 }
3312#endif
3313 /* if there are nt orphan nodes free them */
3314 err = f2fs_recover_orphan_inodes(sbi);
3315 if (err)
3316 goto free_meta;
3317
3318 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)))
3319 goto reset_checkpoint;
3320
3321 /* recover fsynced data */
3322 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
3323 /*
3324 * mount should be failed, when device has readonly mode, and
3325 * previous checkpoint was not done by clean system shutdown.
3326 */
3327 if (f2fs_hw_is_readonly(sbi)) {
3328 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
3329 err = -EROFS;
3418 f2fs_msg(sb, KERN_ERR,
3419 "Need to recover fsync data, but "
3420 "write access unavailable");
3330 f2fs_err(sbi, "Need to recover fsync data, but write access unavailable");
3421 goto free_meta;
3422 }
3331 goto free_meta;
3332 }
3423 f2fs_msg(sbi->sb, KERN_INFO, "write access "
3424 "unavailable, skipping recovery");
3333 f2fs_info(sbi, "write access unavailable, skipping recovery");
3425 goto reset_checkpoint;
3426 }
3427
3428 if (need_fsck)
3429 set_sbi_flag(sbi, SBI_NEED_FSCK);
3430
3431 if (skip_recovery)
3432 goto reset_checkpoint;
3433
3434 err = f2fs_recover_fsync_data(sbi, false);
3435 if (err < 0) {
3436 if (err != -ENOMEM)
3437 skip_recovery = true;
3438 need_fsck = true;
3334 goto reset_checkpoint;
3335 }
3336
3337 if (need_fsck)
3338 set_sbi_flag(sbi, SBI_NEED_FSCK);
3339
3340 if (skip_recovery)
3341 goto reset_checkpoint;
3342
3343 err = f2fs_recover_fsync_data(sbi, false);
3344 if (err < 0) {
3345 if (err != -ENOMEM)
3346 skip_recovery = true;
3347 need_fsck = true;
3439 f2fs_msg(sb, KERN_ERR,
3440 "Cannot recover all fsync data errno=%d", err);
3348 f2fs_err(sbi, "Cannot recover all fsync data errno=%d",
3349 err);
3441 goto free_meta;
3442 }
3443 } else {
3444 err = f2fs_recover_fsync_data(sbi, true);
3445
3446 if (!f2fs_readonly(sb) && err > 0) {
3447 err = -EINVAL;
3350 goto free_meta;
3351 }
3352 } else {
3353 err = f2fs_recover_fsync_data(sbi, true);
3354
3355 if (!f2fs_readonly(sb) && err > 0) {
3356 err = -EINVAL;
3448 f2fs_msg(sb, KERN_ERR,
3449 "Need to recover fsync data");
3357 f2fs_err(sbi, "Need to recover fsync data");
3450 goto free_meta;
3451 }
3452 }
3453reset_checkpoint:
3454 /* f2fs_recover_fsync_data() cleared this already */
3455 clear_sbi_flag(sbi, SBI_POR_DOING);
3456
3457 if (test_opt(sbi, DISABLE_CHECKPOINT)) {

--- 14 unchanged lines hidden (view full) ---

3472 if (err)
3473 goto sync_free_meta;
3474 }
3475 kvfree(options);
3476
3477 /* recover broken superblock */
3478 if (recovery) {
3479 err = f2fs_commit_super(sbi, true);
3358 goto free_meta;
3359 }
3360 }
3361reset_checkpoint:
3362 /* f2fs_recover_fsync_data() cleared this already */
3363 clear_sbi_flag(sbi, SBI_POR_DOING);
3364
3365 if (test_opt(sbi, DISABLE_CHECKPOINT)) {

--- 14 unchanged lines hidden (view full) ---

3380 if (err)
3381 goto sync_free_meta;
3382 }
3383 kvfree(options);
3384
3385 /* recover broken superblock */
3386 if (recovery) {
3387 err = f2fs_commit_super(sbi, true);
3480 f2fs_msg(sb, KERN_INFO,
3481 "Try to recover %dth superblock, ret: %d",
3482 sbi->valid_super_block ? 1 : 2, err);
3388 f2fs_info(sbi, "Try to recover %dth superblock, ret: %d",
3389 sbi->valid_super_block ? 1 : 2, err);
3483 }
3484
3485 f2fs_join_shrinker(sbi);
3486
3487 f2fs_tuning_parameters(sbi);
3488
3390 }
3391
3392 f2fs_join_shrinker(sbi);
3393
3394 f2fs_tuning_parameters(sbi);
3395
3489 f2fs_msg(sbi->sb, KERN_NOTICE, "Mounted with checkpoint version = %llx",
3490 cur_cp_version(F2FS_CKPT(sbi)));
3396 f2fs_notice(sbi, "Mounted with checkpoint version = %llx",
3397 cur_cp_version(F2FS_CKPT(sbi)));
3491 f2fs_update_time(sbi, CP_TIME);
3492 f2fs_update_time(sbi, REQ_TIME);
3493 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
3494 return 0;
3495
3496sync_free_meta:
3497 /* safe to flush all the data */
3498 sync_filesystem(sbi->sb);

--- 211 unchanged lines hidden ---
3398 f2fs_update_time(sbi, CP_TIME);
3399 f2fs_update_time(sbi, REQ_TIME);
3400 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
3401 return 0;
3402
3403sync_free_meta:
3404 /* safe to flush all the data */
3405 sync_filesystem(sbi->sb);

--- 211 unchanged lines hidden ---