blob: 94c0e20495468d9be89185da7e2971bc0c779440 [file] [log] [blame]
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +09001/*
Jaegeuk Kimaff063e2012-11-02 17:07:47 +09002 * 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
9 * published by the Free Software Foundation.
10 */
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/fs.h>
14#include <linux/statfs.h>
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090015#include <linux/buffer_head.h>
16#include <linux/backing-dev.h>
17#include <linux/kthread.h>
18#include <linux/parser.h>
19#include <linux/mount.h>
20#include <linux/seq_file.h>
Jaegeuk Kim5e176d52013-06-28 12:47:01 +090021#include <linux/proc_fs.h>
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090022#include <linux/random.h>
23#include <linux/exportfs.h>
Namjae Jeond3ee4562013-03-17 17:26:14 +090024#include <linux/blkdev.h>
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090025#include <linux/f2fs_fs.h>
Namjae Jeonb59d0ba2013-08-04 23:09:40 +090026#include <linux/kobject.h>
27#include <linux/sysfs.h>
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090028
29#include "f2fs.h"
30#include "node.h"
Jaegeuk Kim5ec4e492013-03-31 13:26:03 +090031#include "segment.h"
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090032#include "xattr.h"
Namjae Jeonb59d0ba2013-08-04 23:09:40 +090033#include "gc.h"
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090034
Namjae Jeona2a4a7e2013-04-20 01:28:40 +090035#define CREATE_TRACE_POINTS
36#include <trace/events/f2fs.h>
37
Jaegeuk Kim5e176d52013-06-28 12:47:01 +090038static struct proc_dir_entry *f2fs_proc_root;
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090039static struct kmem_cache *f2fs_inode_cachep;
Namjae Jeonb59d0ba2013-08-04 23:09:40 +090040static struct kset *f2fs_kset;
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090041
42enum {
Namjae Jeon696c0182013-06-16 09:48:48 +090043 Opt_gc_background,
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090044 Opt_disable_roll_forward,
45 Opt_discard,
46 Opt_noheap,
47 Opt_nouser_xattr,
48 Opt_noacl,
49 Opt_active_logs,
50 Opt_disable_ext_identify,
51 Opt_err,
52};
53
54static match_table_t f2fs_tokens = {
Namjae Jeon696c0182013-06-16 09:48:48 +090055 {Opt_gc_background, "background_gc=%s"},
Jaegeuk Kimaff063e2012-11-02 17:07:47 +090056 {Opt_disable_roll_forward, "disable_roll_forward"},
57 {Opt_discard, "discard"},
58 {Opt_noheap, "no_heap"},
59 {Opt_nouser_xattr, "nouser_xattr"},
60 {Opt_noacl, "noacl"},
61 {Opt_active_logs, "active_logs=%u"},
62 {Opt_disable_ext_identify, "disable_ext_identify"},
63 {Opt_err, NULL},
64};
65
Namjae Jeonb59d0ba2013-08-04 23:09:40 +090066/* Sysfs support for f2fs */
67struct f2fs_attr {
68 struct attribute attr;
69 ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *);
70 ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *,
71 const char *, size_t);
72 int offset;
73};
74
75static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
76 struct f2fs_sb_info *sbi, char *buf)
77{
78 struct f2fs_gc_kthread *gc_kth = sbi->gc_thread;
79 unsigned int *ui;
80
81 if (!gc_kth)
82 return -EINVAL;
83
84 ui = (unsigned int *)(((char *)gc_kth) + a->offset);
85
86 return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
87}
88
89static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
90 struct f2fs_sb_info *sbi,
91 const char *buf, size_t count)
92{
93 struct f2fs_gc_kthread *gc_kth = sbi->gc_thread;
94 unsigned long t;
95 unsigned int *ui;
96 ssize_t ret;
97
98 if (!gc_kth)
99 return -EINVAL;
100
101 ui = (unsigned int *)(((char *)gc_kth) + a->offset);
102
103 ret = kstrtoul(skip_spaces(buf), 0, &t);
104 if (ret < 0)
105 return ret;
106 *ui = t;
107 return count;
108}
109
110static ssize_t f2fs_attr_show(struct kobject *kobj,
111 struct attribute *attr, char *buf)
112{
113 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
114 s_kobj);
115 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
116
117 return a->show ? a->show(a, sbi, buf) : 0;
118}
119
120static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
121 const char *buf, size_t len)
122{
123 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
124 s_kobj);
125 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
126
127 return a->store ? a->store(a, sbi, buf, len) : 0;
128}
129
130static void f2fs_sb_release(struct kobject *kobj)
131{
132 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
133 s_kobj);
134 complete(&sbi->s_kobj_unregister);
135}
136
137#define F2FS_ATTR_OFFSET(_name, _mode, _show, _store, _elname) \
138static struct f2fs_attr f2fs_attr_##_name = { \
139 .attr = {.name = __stringify(_name), .mode = _mode }, \
140 .show = _show, \
141 .store = _store, \
142 .offset = offsetof(struct f2fs_gc_kthread, _elname), \
143}
144
145#define F2FS_RW_ATTR(name, elname) \
146 F2FS_ATTR_OFFSET(name, 0644, f2fs_sbi_show, f2fs_sbi_store, elname)
147
148F2FS_RW_ATTR(gc_min_sleep_time, min_sleep_time);
149F2FS_RW_ATTR(gc_max_sleep_time, max_sleep_time);
150F2FS_RW_ATTR(gc_no_gc_sleep_time, no_gc_sleep_time);
Namjae Jeond2dc0952013-08-04 23:10:15 +0900151F2FS_RW_ATTR(gc_idle, gc_idle);
Namjae Jeonb59d0ba2013-08-04 23:09:40 +0900152
153#define ATTR_LIST(name) (&f2fs_attr_##name.attr)
154static struct attribute *f2fs_attrs[] = {
155 ATTR_LIST(gc_min_sleep_time),
156 ATTR_LIST(gc_max_sleep_time),
157 ATTR_LIST(gc_no_gc_sleep_time),
Namjae Jeond2dc0952013-08-04 23:10:15 +0900158 ATTR_LIST(gc_idle),
Namjae Jeonb59d0ba2013-08-04 23:09:40 +0900159 NULL,
160};
161
162static const struct sysfs_ops f2fs_attr_ops = {
163 .show = f2fs_attr_show,
164 .store = f2fs_attr_store,
165};
166
167static struct kobj_type f2fs_ktype = {
168 .default_attrs = f2fs_attrs,
169 .sysfs_ops = &f2fs_attr_ops,
170 .release = f2fs_sb_release,
171};
172
Namjae Jeona07ef782012-12-30 14:52:05 +0900173void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...)
174{
175 struct va_format vaf;
176 va_list args;
177
178 va_start(args, fmt);
179 vaf.fmt = fmt;
180 vaf.va = &args;
181 printk("%sF2FS-fs (%s): %pV\n", level, sb->s_id, &vaf);
182 va_end(args);
183}
184
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900185static void init_once(void *foo)
186{
187 struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo;
188
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900189 inode_init_once(&fi->vfs_inode);
190}
191
Namjae Jeon696c0182013-06-16 09:48:48 +0900192static int parse_options(struct super_block *sb, char *options)
193{
194 struct f2fs_sb_info *sbi = F2FS_SB(sb);
195 substring_t args[MAX_OPT_ARGS];
196 char *p, *name;
197 int arg = 0;
198
199 if (!options)
200 return 0;
201
202 while ((p = strsep(&options, ",")) != NULL) {
203 int token;
204 if (!*p)
205 continue;
206 /*
207 * Initialize args struct so we know whether arg was
208 * found; some options take optional arguments.
209 */
210 args[0].to = args[0].from = NULL;
211 token = match_token(p, f2fs_tokens, args);
212
213 switch (token) {
214 case Opt_gc_background:
215 name = match_strdup(&args[0]);
216
217 if (!name)
218 return -ENOMEM;
219 if (!strncmp(name, "on", 2))
220 set_opt(sbi, BG_GC);
221 else if (!strncmp(name, "off", 3))
222 clear_opt(sbi, BG_GC);
223 else {
224 kfree(name);
225 return -EINVAL;
226 }
227 kfree(name);
228 break;
229 case Opt_disable_roll_forward:
230 set_opt(sbi, DISABLE_ROLL_FORWARD);
231 break;
232 case Opt_discard:
233 set_opt(sbi, DISCARD);
234 break;
235 case Opt_noheap:
236 set_opt(sbi, NOHEAP);
237 break;
238#ifdef CONFIG_F2FS_FS_XATTR
239 case Opt_nouser_xattr:
240 clear_opt(sbi, XATTR_USER);
241 break;
242#else
243 case Opt_nouser_xattr:
244 f2fs_msg(sb, KERN_INFO,
245 "nouser_xattr options not supported");
246 break;
247#endif
248#ifdef CONFIG_F2FS_FS_POSIX_ACL
249 case Opt_noacl:
250 clear_opt(sbi, POSIX_ACL);
251 break;
252#else
253 case Opt_noacl:
254 f2fs_msg(sb, KERN_INFO, "noacl options not supported");
255 break;
256#endif
257 case Opt_active_logs:
258 if (args->from && match_int(args, &arg))
259 return -EINVAL;
260 if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE)
261 return -EINVAL;
262 sbi->active_logs = arg;
263 break;
264 case Opt_disable_ext_identify:
265 set_opt(sbi, DISABLE_EXT_IDENTIFY);
266 break;
267 default:
268 f2fs_msg(sb, KERN_ERR,
269 "Unrecognized mount option \"%s\" or missing value",
270 p);
271 return -EINVAL;
272 }
273 }
274 return 0;
275}
276
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900277static struct inode *f2fs_alloc_inode(struct super_block *sb)
278{
279 struct f2fs_inode_info *fi;
280
281 fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_NOFS | __GFP_ZERO);
282 if (!fi)
283 return NULL;
284
285 init_once((void *) fi);
286
Masanari Iida434720f2013-03-19 08:03:35 +0900287 /* Initialize f2fs-specific inode info */
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900288 fi->vfs_inode.i_version = 1;
289 atomic_set(&fi->dirty_dents, 0);
290 fi->i_current_depth = 1;
291 fi->i_advise = 0;
292 rwlock_init(&fi->ext.ext_lock);
293
294 set_inode_flag(fi, FI_NEW_INODE);
295
296 return &fi->vfs_inode;
297}
298
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900299static int f2fs_drop_inode(struct inode *inode)
300{
301 /*
302 * This is to avoid a deadlock condition like below.
303 * writeback_single_inode(inode)
304 * - f2fs_write_data_page
305 * - f2fs_gc -> iput -> evict
306 * - inode_wait_for_writeback(inode)
307 */
308 if (!inode_unhashed(inode) && inode->i_state & I_SYNC)
309 return 0;
310 return generic_drop_inode(inode);
311}
312
Jaegeuk Kimb3783872013-06-10 09:17:01 +0900313/*
314 * f2fs_dirty_inode() is called from __mark_inode_dirty()
315 *
316 * We should call set_dirty_inode to write the dirty inode through write_inode.
317 */
318static void f2fs_dirty_inode(struct inode *inode, int flags)
319{
320 set_inode_flag(F2FS_I(inode), FI_DIRTY_INODE);
321 return;
322}
323
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900324static void f2fs_i_callback(struct rcu_head *head)
325{
326 struct inode *inode = container_of(head, struct inode, i_rcu);
327 kmem_cache_free(f2fs_inode_cachep, F2FS_I(inode));
328}
329
Jaegeuk Kim25ca9232012-11-28 16:12:41 +0900330static void f2fs_destroy_inode(struct inode *inode)
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900331{
332 call_rcu(&inode->i_rcu, f2fs_i_callback);
333}
334
335static void f2fs_put_super(struct super_block *sb)
336{
337 struct f2fs_sb_info *sbi = F2FS_SB(sb);
338
Jaegeuk Kim5e176d52013-06-28 12:47:01 +0900339 if (sbi->s_proc) {
340 remove_proc_entry("segment_info", sbi->s_proc);
341 remove_proc_entry(sb->s_id, f2fs_proc_root);
342 }
Namjae Jeonb59d0ba2013-08-04 23:09:40 +0900343 kobject_del(&sbi->s_kobj);
Jaegeuk Kim5e176d52013-06-28 12:47:01 +0900344
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900345 f2fs_destroy_stats(sbi);
346 stop_gc_thread(sbi);
347
Jaegeuk Kim43727522013-02-04 15:11:17 +0900348 write_checkpoint(sbi, true);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900349
350 iput(sbi->node_inode);
351 iput(sbi->meta_inode);
352
353 /* destroy f2fs internal modules */
354 destroy_node_manager(sbi);
355 destroy_segment_manager(sbi);
356
357 kfree(sbi->ckpt);
Namjae Jeonb59d0ba2013-08-04 23:09:40 +0900358 kobject_put(&sbi->s_kobj);
359 wait_for_completion(&sbi->s_kobj_unregister);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900360
361 sb->s_fs_info = NULL;
362 brelse(sbi->raw_super_buf);
363 kfree(sbi);
364}
365
366int f2fs_sync_fs(struct super_block *sb, int sync)
367{
368 struct f2fs_sb_info *sbi = F2FS_SB(sb);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900369
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900370 trace_f2fs_sync_fs(sb, sync);
371
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900372 if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES))
373 return 0;
374
Jaegeuk Kimb7473752013-04-01 08:32:21 +0900375 if (sync) {
376 mutex_lock(&sbi->gc_mutex);
Jaegeuk Kim43727522013-02-04 15:11:17 +0900377 write_checkpoint(sbi, false);
Jaegeuk Kimb7473752013-04-01 08:32:21 +0900378 mutex_unlock(&sbi->gc_mutex);
379 } else {
Jaegeuk Kim7d82db82013-01-11 13:10:49 +0900380 f2fs_balance_fs(sbi);
Jaegeuk Kimb7473752013-04-01 08:32:21 +0900381 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900382
Namjae Jeon64c576f2012-12-22 12:10:27 +0900383 return 0;
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900384}
385
Changman Leed6212a52013-01-29 18:30:07 +0900386static int f2fs_freeze(struct super_block *sb)
387{
388 int err;
389
Jaegeuk Kim77888c12013-05-20 20:28:47 +0900390 if (f2fs_readonly(sb))
Changman Leed6212a52013-01-29 18:30:07 +0900391 return 0;
392
393 err = f2fs_sync_fs(sb, 1);
394 return err;
395}
396
397static int f2fs_unfreeze(struct super_block *sb)
398{
399 return 0;
400}
401
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900402static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
403{
404 struct super_block *sb = dentry->d_sb;
405 struct f2fs_sb_info *sbi = F2FS_SB(sb);
406 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
407 block_t total_count, user_block_count, start_count, ovp_count;
408
409 total_count = le64_to_cpu(sbi->raw_super->block_count);
410 user_block_count = sbi->user_block_count;
411 start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr);
412 ovp_count = SM_I(sbi)->ovp_segments << sbi->log_blocks_per_seg;
413 buf->f_type = F2FS_SUPER_MAGIC;
414 buf->f_bsize = sbi->blocksize;
415
416 buf->f_blocks = total_count - start_count;
417 buf->f_bfree = buf->f_blocks - valid_user_blocks(sbi) - ovp_count;
418 buf->f_bavail = user_block_count - valid_user_blocks(sbi);
419
Jaegeuk Kim1362b5e2012-12-12 19:45:49 +0900420 buf->f_files = sbi->total_node_count;
421 buf->f_ffree = sbi->total_node_count - valid_inode_count(sbi);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900422
Jaegeuk Kim5a20d332013-03-03 13:58:05 +0900423 buf->f_namelen = F2FS_NAME_LEN;
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900424 buf->f_fsid.val[0] = (u32)id;
425 buf->f_fsid.val[1] = (u32)(id >> 32);
426
427 return 0;
428}
429
430static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
431{
432 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
433
Namjae Jeon696c0182013-06-16 09:48:48 +0900434 if (!(root->d_sb->s_flags & MS_RDONLY) && test_opt(sbi, BG_GC))
435 seq_printf(seq, ",background_gc=%s", "on");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900436 else
Namjae Jeon696c0182013-06-16 09:48:48 +0900437 seq_printf(seq, ",background_gc=%s", "off");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900438 if (test_opt(sbi, DISABLE_ROLL_FORWARD))
439 seq_puts(seq, ",disable_roll_forward");
440 if (test_opt(sbi, DISCARD))
441 seq_puts(seq, ",discard");
442 if (test_opt(sbi, NOHEAP))
443 seq_puts(seq, ",no_heap_alloc");
444#ifdef CONFIG_F2FS_FS_XATTR
445 if (test_opt(sbi, XATTR_USER))
446 seq_puts(seq, ",user_xattr");
447 else
448 seq_puts(seq, ",nouser_xattr");
449#endif
450#ifdef CONFIG_F2FS_FS_POSIX_ACL
451 if (test_opt(sbi, POSIX_ACL))
452 seq_puts(seq, ",acl");
453 else
454 seq_puts(seq, ",noacl");
455#endif
456 if (test_opt(sbi, DISABLE_EXT_IDENTIFY))
Alejandro Martinez Ruizaa435072013-01-25 19:08:59 +0100457 seq_puts(seq, ",disable_ext_identify");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900458
459 seq_printf(seq, ",active_logs=%u", sbi->active_logs);
460
461 return 0;
462}
463
Jaegeuk Kim5e176d52013-06-28 12:47:01 +0900464static int segment_info_seq_show(struct seq_file *seq, void *offset)
465{
466 struct super_block *sb = seq->private;
467 struct f2fs_sb_info *sbi = F2FS_SB(sb);
468 unsigned int total_segs = le32_to_cpu(sbi->raw_super->segment_count_main);
469 int i;
470
471 for (i = 0; i < total_segs; i++) {
472 seq_printf(seq, "%u", get_valid_blocks(sbi, i, 1));
473 if (i != 0 && (i % 10) == 0)
474 seq_puts(seq, "\n");
475 else
476 seq_puts(seq, " ");
477 }
478 return 0;
479}
480
481static int segment_info_open_fs(struct inode *inode, struct file *file)
482{
483 return single_open(file, segment_info_seq_show, PDE_DATA(inode));
484}
485
486static const struct file_operations f2fs_seq_segment_info_fops = {
487 .owner = THIS_MODULE,
488 .open = segment_info_open_fs,
489 .read = seq_read,
490 .llseek = seq_lseek,
491 .release = single_release,
492};
493
Namjae Jeon696c0182013-06-16 09:48:48 +0900494static int f2fs_remount(struct super_block *sb, int *flags, char *data)
495{
496 struct f2fs_sb_info *sbi = F2FS_SB(sb);
497 struct f2fs_mount_info org_mount_opt;
498 int err, active_logs;
499
500 /*
501 * Save the old mount options in case we
502 * need to restore them.
503 */
504 org_mount_opt = sbi->mount_opt;
505 active_logs = sbi->active_logs;
506
507 /* parse mount options */
508 err = parse_options(sb, data);
509 if (err)
510 goto restore_opts;
511
512 /*
513 * Previous and new state of filesystem is RO,
514 * so no point in checking GC conditions.
515 */
516 if ((sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY))
517 goto skip;
518
519 /*
520 * We stop the GC thread if FS is mounted as RO
521 * or if background_gc = off is passed in mount
522 * option. Also sync the filesystem.
523 */
524 if ((*flags & MS_RDONLY) || !test_opt(sbi, BG_GC)) {
525 if (sbi->gc_thread) {
526 stop_gc_thread(sbi);
527 f2fs_sync_fs(sb, 1);
528 }
529 } else if (test_opt(sbi, BG_GC) && !sbi->gc_thread) {
530 err = start_gc_thread(sbi);
531 if (err)
532 goto restore_opts;
533 }
534skip:
535 /* Update the POSIXACL Flag */
536 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
537 (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0);
538 return 0;
539
540restore_opts:
541 sbi->mount_opt = org_mount_opt;
542 sbi->active_logs = active_logs;
543 return err;
544}
545
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900546static struct super_operations f2fs_sops = {
547 .alloc_inode = f2fs_alloc_inode,
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900548 .drop_inode = f2fs_drop_inode,
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900549 .destroy_inode = f2fs_destroy_inode,
550 .write_inode = f2fs_write_inode,
Jaegeuk Kimb3783872013-06-10 09:17:01 +0900551 .dirty_inode = f2fs_dirty_inode,
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900552 .show_options = f2fs_show_options,
553 .evict_inode = f2fs_evict_inode,
554 .put_super = f2fs_put_super,
555 .sync_fs = f2fs_sync_fs,
Changman Leed6212a52013-01-29 18:30:07 +0900556 .freeze_fs = f2fs_freeze,
557 .unfreeze_fs = f2fs_unfreeze,
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900558 .statfs = f2fs_statfs,
Namjae Jeon696c0182013-06-16 09:48:48 +0900559 .remount_fs = f2fs_remount,
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900560};
561
562static struct inode *f2fs_nfs_get_inode(struct super_block *sb,
563 u64 ino, u32 generation)
564{
565 struct f2fs_sb_info *sbi = F2FS_SB(sb);
566 struct inode *inode;
567
568 if (ino < F2FS_ROOT_INO(sbi))
569 return ERR_PTR(-ESTALE);
570
571 /*
572 * f2fs_iget isn't quite right if the inode is currently unallocated!
573 * However f2fs_iget currently does appropriate checks to handle stale
574 * inodes so everything is OK.
575 */
576 inode = f2fs_iget(sb, ino);
577 if (IS_ERR(inode))
578 return ERR_CAST(inode);
579 if (generation && inode->i_generation != generation) {
580 /* we didn't find the right inode.. */
581 iput(inode);
582 return ERR_PTR(-ESTALE);
583 }
584 return inode;
585}
586
587static struct dentry *f2fs_fh_to_dentry(struct super_block *sb, struct fid *fid,
588 int fh_len, int fh_type)
589{
590 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
591 f2fs_nfs_get_inode);
592}
593
594static struct dentry *f2fs_fh_to_parent(struct super_block *sb, struct fid *fid,
595 int fh_len, int fh_type)
596{
597 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
598 f2fs_nfs_get_inode);
599}
600
601static const struct export_operations f2fs_export_ops = {
602 .fh_to_dentry = f2fs_fh_to_dentry,
603 .fh_to_parent = f2fs_fh_to_parent,
604 .get_parent = f2fs_get_parent,
605};
606
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900607static loff_t max_file_size(unsigned bits)
608{
609 loff_t result = ADDRS_PER_INODE;
610 loff_t leaf_count = ADDRS_PER_BLOCK;
611
612 /* two direct node blocks */
613 result += (leaf_count * 2);
614
615 /* two indirect node blocks */
616 leaf_count *= NIDS_PER_BLOCK;
617 result += (leaf_count * 2);
618
619 /* one double indirect node block */
620 leaf_count *= NIDS_PER_BLOCK;
621 result += leaf_count;
622
623 result <<= bits;
624 return result;
625}
626
Namjae Jeona07ef782012-12-30 14:52:05 +0900627static int sanity_check_raw_super(struct super_block *sb,
628 struct f2fs_super_block *raw_super)
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900629{
630 unsigned int blocksize;
631
Namjae Jeona07ef782012-12-30 14:52:05 +0900632 if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) {
633 f2fs_msg(sb, KERN_INFO,
634 "Magic Mismatch, valid(0x%x) - read(0x%x)",
635 F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900636 return 1;
Namjae Jeona07ef782012-12-30 14:52:05 +0900637 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900638
majianpeng5c9b4692013-02-01 19:07:57 +0800639 /* Currently, support only 4KB page cache size */
640 if (F2FS_BLKSIZE != PAGE_CACHE_SIZE) {
641 f2fs_msg(sb, KERN_INFO,
majianpeng14d7e9d2013-02-01 19:07:03 +0800642 "Invalid page_cache_size (%lu), supports only 4KB\n",
majianpeng5c9b4692013-02-01 19:07:57 +0800643 PAGE_CACHE_SIZE);
644 return 1;
645 }
646
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900647 /* Currently, support only 4KB block size */
648 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize);
majianpeng5c9b4692013-02-01 19:07:57 +0800649 if (blocksize != F2FS_BLKSIZE) {
Namjae Jeona07ef782012-12-30 14:52:05 +0900650 f2fs_msg(sb, KERN_INFO,
651 "Invalid blocksize (%u), supports only 4KB\n",
652 blocksize);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900653 return 1;
Namjae Jeona07ef782012-12-30 14:52:05 +0900654 }
majianpeng5c9b4692013-02-01 19:07:57 +0800655
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900656 if (le32_to_cpu(raw_super->log_sectorsize) !=
Namjae Jeona07ef782012-12-30 14:52:05 +0900657 F2FS_LOG_SECTOR_SIZE) {
658 f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900659 return 1;
Namjae Jeona07ef782012-12-30 14:52:05 +0900660 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900661 if (le32_to_cpu(raw_super->log_sectors_per_block) !=
Namjae Jeona07ef782012-12-30 14:52:05 +0900662 F2FS_LOG_SECTORS_PER_BLOCK) {
663 f2fs_msg(sb, KERN_INFO, "Invalid log sectors per block");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900664 return 1;
Namjae Jeona07ef782012-12-30 14:52:05 +0900665 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900666 return 0;
667}
668
Jaegeuk Kim577e3492013-01-24 19:56:11 +0900669static int sanity_check_ckpt(struct f2fs_sb_info *sbi)
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900670{
671 unsigned int total, fsmeta;
Jaegeuk Kim577e3492013-01-24 19:56:11 +0900672 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
673 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900674
675 total = le32_to_cpu(raw_super->segment_count);
676 fsmeta = le32_to_cpu(raw_super->segment_count_ckpt);
677 fsmeta += le32_to_cpu(raw_super->segment_count_sit);
678 fsmeta += le32_to_cpu(raw_super->segment_count_nat);
679 fsmeta += le32_to_cpu(ckpt->rsvd_segment_count);
680 fsmeta += le32_to_cpu(raw_super->segment_count_ssa);
681
682 if (fsmeta >= total)
683 return 1;
Jaegeuk Kim577e3492013-01-24 19:56:11 +0900684
685 if (is_set_ckpt_flags(ckpt, CP_ERROR_FLAG)) {
686 f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck");
687 return 1;
688 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900689 return 0;
690}
691
692static void init_sb_info(struct f2fs_sb_info *sbi)
693{
694 struct f2fs_super_block *raw_super = sbi->raw_super;
695 int i;
696
697 sbi->log_sectors_per_block =
698 le32_to_cpu(raw_super->log_sectors_per_block);
699 sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize);
700 sbi->blocksize = 1 << sbi->log_blocksize;
701 sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
702 sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg;
703 sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
704 sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
705 sbi->total_sections = le32_to_cpu(raw_super->section_count);
706 sbi->total_node_count =
707 (le32_to_cpu(raw_super->segment_count_nat) / 2)
708 * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK;
709 sbi->root_ino_num = le32_to_cpu(raw_super->root_ino);
710 sbi->node_ino_num = le32_to_cpu(raw_super->node_ino);
711 sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino);
Jaegeuk Kim5ec4e492013-03-31 13:26:03 +0900712 sbi->cur_victim_sec = NULL_SECNO;
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900713
714 for (i = 0; i < NR_COUNT_TYPE; i++)
715 atomic_set(&sbi->nr_pages[i], 0);
716}
717
majianpeng14d7e9d2013-02-01 19:07:03 +0800718static int validate_superblock(struct super_block *sb,
719 struct f2fs_super_block **raw_super,
720 struct buffer_head **raw_super_buf, sector_t block)
721{
722 const char *super = (block == 0 ? "first" : "second");
723
724 /* read f2fs raw super block */
725 *raw_super_buf = sb_bread(sb, block);
726 if (!*raw_super_buf) {
727 f2fs_msg(sb, KERN_ERR, "unable to read %s superblock",
728 super);
Namjae Jeonc0d39e62013-03-17 17:26:53 +0900729 return -EIO;
majianpeng14d7e9d2013-02-01 19:07:03 +0800730 }
731
732 *raw_super = (struct f2fs_super_block *)
733 ((char *)(*raw_super_buf)->b_data + F2FS_SUPER_OFFSET);
734
735 /* sanity checking of raw super */
736 if (!sanity_check_raw_super(sb, *raw_super))
737 return 0;
738
739 f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem "
740 "in %s superblock", super);
Namjae Jeonc0d39e62013-03-17 17:26:53 +0900741 return -EINVAL;
majianpeng14d7e9d2013-02-01 19:07:03 +0800742}
743
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900744static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
745{
746 struct f2fs_sb_info *sbi;
747 struct f2fs_super_block *raw_super;
748 struct buffer_head *raw_super_buf;
749 struct inode *root;
750 long err = -EINVAL;
751 int i;
752
753 /* allocate memory for f2fs-specific super block info */
754 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL);
755 if (!sbi)
756 return -ENOMEM;
757
Namjae Jeonff9234a2013-01-12 14:41:13 +0900758 /* set a block size */
Namjae Jeona07ef782012-12-30 14:52:05 +0900759 if (!sb_set_blocksize(sb, F2FS_BLKSIZE)) {
760 f2fs_msg(sb, KERN_ERR, "unable to set blocksize");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900761 goto free_sbi;
Namjae Jeona07ef782012-12-30 14:52:05 +0900762 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900763
Namjae Jeonc0d39e62013-03-17 17:26:53 +0900764 err = validate_superblock(sb, &raw_super, &raw_super_buf, 0);
765 if (err) {
majianpeng14d7e9d2013-02-01 19:07:03 +0800766 brelse(raw_super_buf);
Namjae Jeonc0d39e62013-03-17 17:26:53 +0900767 /* check secondary superblock when primary failed */
768 err = validate_superblock(sb, &raw_super, &raw_super_buf, 1);
769 if (err)
majianpeng14d7e9d2013-02-01 19:07:03 +0800770 goto free_sb_buf;
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900771 }
Gu Zheng5fb08372013-06-07 14:16:53 +0800772 sb->s_fs_info = sbi;
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900773 /* init some FS parameters */
774 sbi->active_logs = NR_CURSEG_TYPE;
775
776 set_opt(sbi, BG_GC);
777
778#ifdef CONFIG_F2FS_FS_XATTR
779 set_opt(sbi, XATTR_USER);
780#endif
781#ifdef CONFIG_F2FS_FS_POSIX_ACL
782 set_opt(sbi, POSIX_ACL);
783#endif
784 /* parse mount options */
Gu Zheng5fb08372013-06-07 14:16:53 +0800785 err = parse_options(sb, (char *)data);
Wei Yongjun66348b72013-04-12 10:23:18 +0800786 if (err)
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900787 goto free_sb_buf;
788
Jaegeuk Kim25ca9232012-11-28 16:12:41 +0900789 sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize));
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900790 sb->s_max_links = F2FS_LINK_MAX;
791 get_random_bytes(&sbi->s_next_generation, sizeof(u32));
792
793 sb->s_op = &f2fs_sops;
794 sb->s_xattr = f2fs_xattr_handlers;
795 sb->s_export_op = &f2fs_export_ops;
796 sb->s_magic = F2FS_SUPER_MAGIC;
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900797 sb->s_time_gran = 1;
798 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
799 (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0);
800 memcpy(sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid));
801
802 /* init f2fs-specific super block info */
803 sbi->sb = sb;
804 sbi->raw_super = raw_super;
805 sbi->raw_super_buf = raw_super_buf;
806 mutex_init(&sbi->gc_mutex);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900807 mutex_init(&sbi->writepages);
808 mutex_init(&sbi->cp_mutex);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900809 for (i = 0; i < NR_GLOBAL_LOCKS; i++)
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900810 mutex_init(&sbi->fs_lock[i]);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900811 mutex_init(&sbi->node_write);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900812 sbi->por_doing = 0;
813 spin_lock_init(&sbi->stat_lock);
814 init_rwsem(&sbi->bio_sem);
815 init_sb_info(sbi);
816
817 /* get an inode for meta space */
818 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
819 if (IS_ERR(sbi->meta_inode)) {
Namjae Jeona07ef782012-12-30 14:52:05 +0900820 f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900821 err = PTR_ERR(sbi->meta_inode);
822 goto free_sb_buf;
823 }
824
825 err = get_valid_checkpoint(sbi);
Namjae Jeona07ef782012-12-30 14:52:05 +0900826 if (err) {
827 f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900828 goto free_meta_inode;
Namjae Jeona07ef782012-12-30 14:52:05 +0900829 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900830
831 /* sanity checking of checkpoint */
832 err = -EINVAL;
Jaegeuk Kim577e3492013-01-24 19:56:11 +0900833 if (sanity_check_ckpt(sbi)) {
Namjae Jeona07ef782012-12-30 14:52:05 +0900834 f2fs_msg(sb, KERN_ERR, "Invalid F2FS checkpoint");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900835 goto free_cp;
Namjae Jeona07ef782012-12-30 14:52:05 +0900836 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900837
838 sbi->total_valid_node_count =
839 le32_to_cpu(sbi->ckpt->valid_node_count);
840 sbi->total_valid_inode_count =
841 le32_to_cpu(sbi->ckpt->valid_inode_count);
842 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
843 sbi->total_valid_block_count =
844 le64_to_cpu(sbi->ckpt->valid_block_count);
845 sbi->last_valid_block_count = sbi->total_valid_block_count;
846 sbi->alloc_valid_block_count = 0;
847 INIT_LIST_HEAD(&sbi->dir_inode_list);
848 spin_lock_init(&sbi->dir_inode_lock);
849
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900850 init_orphan_info(sbi);
851
852 /* setup f2fs internal modules */
853 err = build_segment_manager(sbi);
Namjae Jeona07ef782012-12-30 14:52:05 +0900854 if (err) {
855 f2fs_msg(sb, KERN_ERR,
856 "Failed to initialize F2FS segment manager");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900857 goto free_sm;
Namjae Jeona07ef782012-12-30 14:52:05 +0900858 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900859 err = build_node_manager(sbi);
Namjae Jeona07ef782012-12-30 14:52:05 +0900860 if (err) {
861 f2fs_msg(sb, KERN_ERR,
862 "Failed to initialize F2FS node manager");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900863 goto free_nm;
Namjae Jeona07ef782012-12-30 14:52:05 +0900864 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900865
866 build_gc_manager(sbi);
867
868 /* get an inode for node space */
869 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
870 if (IS_ERR(sbi->node_inode)) {
Namjae Jeona07ef782012-12-30 14:52:05 +0900871 f2fs_msg(sb, KERN_ERR, "Failed to read node inode");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900872 err = PTR_ERR(sbi->node_inode);
873 goto free_nm;
874 }
875
876 /* if there are nt orphan nodes free them */
877 err = -EINVAL;
Jaegeuk Kim30f0c752012-12-19 16:09:19 +0900878 if (recover_orphan_inodes(sbi))
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900879 goto free_node_inode;
880
881 /* read root inode and dentry */
882 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
883 if (IS_ERR(root)) {
Namjae Jeona07ef782012-12-30 14:52:05 +0900884 f2fs_msg(sb, KERN_ERR, "Failed to read root inode");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900885 err = PTR_ERR(root);
886 goto free_node_inode;
887 }
888 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size)
889 goto free_root_inode;
890
891 sb->s_root = d_make_root(root); /* allocate root dentry */
892 if (!sb->s_root) {
893 err = -ENOMEM;
894 goto free_root_inode;
895 }
896
897 /* recover fsynced data */
Jaegeuk Kim6ead1142013-03-20 19:01:06 +0900898 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
899 err = recover_fsync_data(sbi);
Chris Friesbde582b2013-05-02 16:07:34 -0500900 if (err)
901 f2fs_msg(sb, KERN_ERR,
902 "Cannot recover all fsync data errno=%ld", err);
Jaegeuk Kim6ead1142013-03-20 19:01:06 +0900903 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900904
Namjae Jeon696c0182013-06-16 09:48:48 +0900905 /*
906 * If filesystem is not mounted as read-only then
907 * do start the gc_thread.
908 */
909 if (!(sb->s_flags & MS_RDONLY)) {
910 /* After POR, we can run background GC thread.*/
911 err = start_gc_thread(sbi);
912 if (err)
913 goto fail;
914 }
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900915
916 err = f2fs_build_stats(sbi);
917 if (err)
918 goto fail;
919
Jaegeuk Kim5e176d52013-06-28 12:47:01 +0900920 if (f2fs_proc_root)
921 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
922
923 if (sbi->s_proc)
924 proc_create_data("segment_info", S_IRUGO, sbi->s_proc,
925 &f2fs_seq_segment_info_fops, sb);
926
Namjae Jeond3ee4562013-03-17 17:26:14 +0900927 if (test_opt(sbi, DISCARD)) {
928 struct request_queue *q = bdev_get_queue(sb->s_bdev);
929 if (!blk_queue_discard(q))
930 f2fs_msg(sb, KERN_WARNING,
931 "mounting with \"discard\" option, but "
932 "the device does not support discard");
933 }
934
Namjae Jeonb59d0ba2013-08-04 23:09:40 +0900935 sbi->s_kobj.kset = f2fs_kset;
936 init_completion(&sbi->s_kobj_unregister);
937 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL,
938 "%s", sb->s_id);
939 if (err)
940 goto fail;
941
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900942 return 0;
943fail:
944 stop_gc_thread(sbi);
945free_root_inode:
946 dput(sb->s_root);
947 sb->s_root = NULL;
948free_node_inode:
949 iput(sbi->node_inode);
950free_nm:
951 destroy_node_manager(sbi);
952free_sm:
953 destroy_segment_manager(sbi);
954free_cp:
955 kfree(sbi->ckpt);
956free_meta_inode:
957 make_bad_inode(sbi->meta_inode);
958 iput(sbi->meta_inode);
959free_sb_buf:
960 brelse(raw_super_buf);
961free_sbi:
962 kfree(sbi);
963 return err;
964}
965
966static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags,
967 const char *dev_name, void *data)
968{
969 return mount_bdev(fs_type, flags, dev_name, data, f2fs_fill_super);
970}
971
972static struct file_system_type f2fs_fs_type = {
973 .owner = THIS_MODULE,
974 .name = "f2fs",
975 .mount = f2fs_mount,
976 .kill_sb = kill_block_super,
977 .fs_flags = FS_REQUIRES_DEV,
978};
Eric W. Biederman7f78e032013-03-02 19:39:14 -0800979MODULE_ALIAS_FS("f2fs");
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900980
Namjae Jeon6e6093a2013-01-17 00:08:30 +0900981static int __init init_inodecache(void)
Jaegeuk Kimaff063e2012-11-02 17:07:47 +0900982{
983 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache",
984 sizeof(struct f2fs_inode_info), NULL);
985 if (f2fs_inode_cachep == NULL)
986 return -ENOMEM;
987 return 0;
988}
989
990static void destroy_inodecache(void)
991{
992 /*
993 * Make sure all delayed rcu free inodes are flushed before we
994 * destroy cache.
995 */
996 rcu_barrier();
997 kmem_cache_destroy(f2fs_inode_cachep);
998}
999
1000static int __init init_f2fs_fs(void)
1001{
1002 int err;
1003
1004 err = init_inodecache();
1005 if (err)
1006 goto fail;
1007 err = create_node_manager_caches();
1008 if (err)
1009 goto fail;
1010 err = create_gc_caches();
1011 if (err)
1012 goto fail;
1013 err = create_checkpoint_caches();
1014 if (err)
1015 goto fail;
Namjae Jeonb59d0ba2013-08-04 23:09:40 +09001016 f2fs_kset = kset_create_and_add("f2fs", NULL, fs_kobj);
1017 if (!f2fs_kset)
1018 goto fail;
Namjae Jeon4589d252013-01-15 19:58:47 +09001019 err = register_filesystem(&f2fs_fs_type);
1020 if (err)
1021 goto fail;
1022 f2fs_create_root_stats();
Jaegeuk Kim5e176d52013-06-28 12:47:01 +09001023 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +09001024fail:
1025 return err;
1026}
1027
1028static void __exit exit_f2fs_fs(void)
1029{
Jaegeuk Kim5e176d52013-06-28 12:47:01 +09001030 remove_proc_entry("fs/f2fs", NULL);
Namjae Jeon4589d252013-01-15 19:58:47 +09001031 f2fs_destroy_root_stats();
Jaegeuk Kimaff063e2012-11-02 17:07:47 +09001032 unregister_filesystem(&f2fs_fs_type);
1033 destroy_checkpoint_caches();
1034 destroy_gc_caches();
1035 destroy_node_manager_caches();
1036 destroy_inodecache();
Namjae Jeonb59d0ba2013-08-04 23:09:40 +09001037 kset_unregister(f2fs_kset);
Jaegeuk Kimaff063e2012-11-02 17:07:47 +09001038}
1039
1040module_init(init_f2fs_fs)
1041module_exit(exit_f2fs_fs)
1042
1043MODULE_AUTHOR("Samsung Electronics's Praesto Team");
1044MODULE_DESCRIPTION("Flash Friendly File System");
1045MODULE_LICENSE("GPL");