super.c (49bc389ec2318b75e86a3c3239a495d7a8311046) super.c (6ead114232f786e3ef7a034c8617f2a4df8e5226)
1/*
2 * fs/f2fs/super.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

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

16#include <linux/buffer_head.h>
17#include <linux/backing-dev.h>
18#include <linux/kthread.h>
19#include <linux/parser.h>
20#include <linux/mount.h>
21#include <linux/seq_file.h>
22#include <linux/random.h>
23#include <linux/exportfs.h>
1/*
2 * fs/f2fs/super.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

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

16#include <linux/buffer_head.h>
17#include <linux/backing-dev.h>
18#include <linux/kthread.h>
19#include <linux/parser.h>
20#include <linux/mount.h>
21#include <linux/seq_file.h>
22#include <linux/random.h>
23#include <linux/exportfs.h>
24#include <linux/blkdev.h>
24#include <linux/f2fs_fs.h>
25
26#include "f2fs.h"
27#include "node.h"
28#include "xattr.h"
29
30static struct kmem_cache *f2fs_inode_cachep;
31

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

77 struct f2fs_inode_info *fi;
78
79 fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_NOFS | __GFP_ZERO);
80 if (!fi)
81 return NULL;
82
83 init_once((void *) fi);
84
25#include <linux/f2fs_fs.h>
26
27#include "f2fs.h"
28#include "node.h"
29#include "xattr.h"
30
31static struct kmem_cache *f2fs_inode_cachep;
32

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

78 struct f2fs_inode_info *fi;
79
80 fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_NOFS | __GFP_ZERO);
81 if (!fi)
82 return NULL;
83
84 init_once((void *) fi);
85
85 /* Initilize f2fs-specific inode info */
86 /* Initialize f2fs-specific inode info */
86 fi->vfs_inode.i_version = 1;
87 atomic_set(&fi->dirty_dents, 0);
88 fi->i_current_depth = 1;
89 fi->i_advise = 0;
90 rwlock_init(&fi->ext.ext_lock);
91
92 set_inode_flag(fi, FI_NEW_INODE);
93

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

175
176 buf->f_blocks = total_count - start_count;
177 buf->f_bfree = buf->f_blocks - valid_user_blocks(sbi) - ovp_count;
178 buf->f_bavail = user_block_count - valid_user_blocks(sbi);
179
180 buf->f_files = sbi->total_node_count;
181 buf->f_ffree = sbi->total_node_count - valid_inode_count(sbi);
182
87 fi->vfs_inode.i_version = 1;
88 atomic_set(&fi->dirty_dents, 0);
89 fi->i_current_depth = 1;
90 fi->i_advise = 0;
91 rwlock_init(&fi->ext.ext_lock);
92
93 set_inode_flag(fi, FI_NEW_INODE);
94

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

176
177 buf->f_blocks = total_count - start_count;
178 buf->f_bfree = buf->f_blocks - valid_user_blocks(sbi) - ovp_count;
179 buf->f_bavail = user_block_count - valid_user_blocks(sbi);
180
181 buf->f_files = sbi->total_node_count;
182 buf->f_ffree = sbi->total_node_count - valid_inode_count(sbi);
183
183 buf->f_namelen = F2FS_MAX_NAME_LEN;
184 buf->f_namelen = F2FS_NAME_LEN;
184 buf->f_fsid.val[0] = (u32)id;
185 buf->f_fsid.val[1] = (u32)(id >> 32);
186
187 return 0;
188}
189
190static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
191{

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

468{
469 const char *super = (block == 0 ? "first" : "second");
470
471 /* read f2fs raw super block */
472 *raw_super_buf = sb_bread(sb, block);
473 if (!*raw_super_buf) {
474 f2fs_msg(sb, KERN_ERR, "unable to read %s superblock",
475 super);
185 buf->f_fsid.val[0] = (u32)id;
186 buf->f_fsid.val[1] = (u32)(id >> 32);
187
188 return 0;
189}
190
191static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
192{

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

469{
470 const char *super = (block == 0 ? "first" : "second");
471
472 /* read f2fs raw super block */
473 *raw_super_buf = sb_bread(sb, block);
474 if (!*raw_super_buf) {
475 f2fs_msg(sb, KERN_ERR, "unable to read %s superblock",
476 super);
476 return 1;
477 return -EIO;
477 }
478
479 *raw_super = (struct f2fs_super_block *)
480 ((char *)(*raw_super_buf)->b_data + F2FS_SUPER_OFFSET);
481
482 /* sanity checking of raw super */
483 if (!sanity_check_raw_super(sb, *raw_super))
484 return 0;
485
486 f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem "
487 "in %s superblock", super);
478 }
479
480 *raw_super = (struct f2fs_super_block *)
481 ((char *)(*raw_super_buf)->b_data + F2FS_SUPER_OFFSET);
482
483 /* sanity checking of raw super */
484 if (!sanity_check_raw_super(sb, *raw_super))
485 return 0;
486
487 f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem "
488 "in %s superblock", super);
488 return 1;
489 return -EINVAL;
489}
490
491static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
492{
493 struct f2fs_sb_info *sbi;
494 struct f2fs_super_block *raw_super;
495 struct buffer_head *raw_super_buf;
496 struct inode *root;

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

503 return -ENOMEM;
504
505 /* set a block size */
506 if (!sb_set_blocksize(sb, F2FS_BLKSIZE)) {
507 f2fs_msg(sb, KERN_ERR, "unable to set blocksize");
508 goto free_sbi;
509 }
510
490}
491
492static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
493{
494 struct f2fs_sb_info *sbi;
495 struct f2fs_super_block *raw_super;
496 struct buffer_head *raw_super_buf;
497 struct inode *root;

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

504 return -ENOMEM;
505
506 /* set a block size */
507 if (!sb_set_blocksize(sb, F2FS_BLKSIZE)) {
508 f2fs_msg(sb, KERN_ERR, "unable to set blocksize");
509 goto free_sbi;
510 }
511
511 if (validate_superblock(sb, &raw_super, &raw_super_buf, 0)) {
512 err = validate_superblock(sb, &raw_super, &raw_super_buf, 0);
513 if (err) {
512 brelse(raw_super_buf);
514 brelse(raw_super_buf);
513 if (validate_superblock(sb, &raw_super, &raw_super_buf, 1))
515 /* check secondary superblock when primary failed */
516 err = validate_superblock(sb, &raw_super, &raw_super_buf, 1);
517 if (err)
514 goto free_sb_buf;
515 }
516 /* init some FS parameters */
517 sbi->active_logs = NR_CURSEG_TYPE;
518
519 set_opt(sbi, BG_GC);
520
521#ifdef CONFIG_F2FS_FS_XATTR

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

633
634 sb->s_root = d_make_root(root); /* allocate root dentry */
635 if (!sb->s_root) {
636 err = -ENOMEM;
637 goto free_root_inode;
638 }
639
640 /* recover fsynced data */
518 goto free_sb_buf;
519 }
520 /* init some FS parameters */
521 sbi->active_logs = NR_CURSEG_TYPE;
522
523 set_opt(sbi, BG_GC);
524
525#ifdef CONFIG_F2FS_FS_XATTR

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

637
638 sb->s_root = d_make_root(root); /* allocate root dentry */
639 if (!sb->s_root) {
640 err = -ENOMEM;
641 goto free_root_inode;
642 }
643
644 /* recover fsynced data */
641 if (!test_opt(sbi, DISABLE_ROLL_FORWARD))
642 recover_fsync_data(sbi);
645 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
646 err = recover_fsync_data(sbi);
647 if (err) {
648 f2fs_msg(sb, KERN_ERR, "Failed to recover fsync data");
649 goto free_root_inode;
650 }
651 }
643
644 /* After POR, we can run background GC thread */
645 err = start_gc_thread(sbi);
646 if (err)
647 goto fail;
648
649 err = f2fs_build_stats(sbi);
650 if (err)
651 goto fail;
652
652
653 /* After POR, we can run background GC thread */
654 err = start_gc_thread(sbi);
655 if (err)
656 goto fail;
657
658 err = f2fs_build_stats(sbi);
659 if (err)
660 goto fail;
661
662 if (test_opt(sbi, DISCARD)) {
663 struct request_queue *q = bdev_get_queue(sb->s_bdev);
664 if (!blk_queue_discard(q))
665 f2fs_msg(sb, KERN_WARNING,
666 "mounting with \"discard\" option, but "
667 "the device does not support discard");
668 }
669
653 return 0;
654fail:
655 stop_gc_thread(sbi);
656free_root_inode:
657 dput(sb->s_root);
658 sb->s_root = NULL;
659free_node_inode:
660 iput(sbi->node_inode);

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

682
683static struct file_system_type f2fs_fs_type = {
684 .owner = THIS_MODULE,
685 .name = "f2fs",
686 .mount = f2fs_mount,
687 .kill_sb = kill_block_super,
688 .fs_flags = FS_REQUIRES_DEV,
689};
670 return 0;
671fail:
672 stop_gc_thread(sbi);
673free_root_inode:
674 dput(sb->s_root);
675 sb->s_root = NULL;
676free_node_inode:
677 iput(sbi->node_inode);

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

699
700static struct file_system_type f2fs_fs_type = {
701 .owner = THIS_MODULE,
702 .name = "f2fs",
703 .mount = f2fs_mount,
704 .kill_sb = kill_block_super,
705 .fs_flags = FS_REQUIRES_DEV,
706};
690MODULE_ALIAS_FS("f2fs");
691
692static int __init init_inodecache(void)
693{
694 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache",
695 sizeof(struct f2fs_inode_info), NULL);
696 if (f2fs_inode_cachep == NULL)
697 return -ENOMEM;
698 return 0;

--- 52 unchanged lines hidden ---
707
708static int __init init_inodecache(void)
709{
710 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache",
711 sizeof(struct f2fs_inode_info), NULL);
712 if (f2fs_inode_cachep == NULL)
713 return -ENOMEM;
714 return 0;

--- 52 unchanged lines hidden ---