40 #include <linux/module.h>
41 #include <linux/string.h>
42 #include <linux/slab.h>
75 static int nilfs_setup_super(
struct super_block *
sb,
int is_mount);
110 const char *
fmt, ...)
122 sb->
s_id,
function, &vaf);
136 panic(
"NILFS (device %s): panic forced after error\n",
141 const char *
fmt, ...)
152 sb->
s_id,
function, &vaf);
196 set_buffer_dirty(nilfs->
ns_sbh[0]);
206 "NILFS: unable to write superblock (err=%d)\n", err);
226 clear_nilfs_discontinued(nilfs);
231 set_buffer_dirty(nilfs->
ns_sbh[1]);
303 (
unsigned char *)sbp[0],
309 (
unsigned char *)sbp[1],
312 clear_nilfs_sb_dirty(nilfs);
313 return nilfs_sync_super(sb, flag);
354 static int nilfs_move_2nd_super(
struct super_block *sb, loff_t sb2off)
357 struct buffer_head *nsbh;
368 blocknr = nilfs->
ns_sbh[1]->b_blocknr;
371 blocknr = nilfs->
ns_sbh[0]->b_blocknr;
379 nsbh = sb_getblk(sb, newblocknr);
382 "NILFS warning: unable to move secondary superblock "
383 "to block %llu\n", (
unsigned long long)newblocknr);
387 nsbp = (
void *)nsbh->b_data + offset;
392 brelse(nilfs->
ns_sbh[sb2i]);
393 nilfs->
ns_sbh[sb2i] = nsbh;
394 nilfs->
ns_sbp[sb2i] = nsbp;
415 __u64 devsize, newnsegs;
420 devsize = i_size_read(sb->
s_bdev->bd_inode);
421 if (newsize > devsize)
445 nilfs_move_2nd_super(sb, sb2off);
477 static void nilfs_put_super(
struct super_block *sb)
508 if (nilfs_sb_dirty(nilfs)) {
526 struct buffer_head *bh_cp;
544 "NILFS: Invalid checkpoint "
545 "(checkpoint number=%llu)\n",
546 (
unsigned long long)cno);
597 nilfs_setup_super(sb,
false);
607 u64 id = huge_encode_dev(sb->
s_bdev->bd_dev);
608 unsigned long long blocks;
609 unsigned long overhead;
610 unsigned long nrsvblocks;
641 (buf->
f_bfree - nrsvblocks) : 0;
651 static int nilfs_show_options(
struct seq_file *seq,
struct dentry *dentry)
680 .put_super = nilfs_put_super,
681 .sync_fs = nilfs_sync_fs,
682 .freeze_fs = nilfs_freeze,
683 .unfreeze_fs = nilfs_unfreeze,
684 .statfs = nilfs_statfs,
685 .remount_fs = nilfs_remount,
686 .show_options = nilfs_show_options
735 else if (
strcmp(args[0].from,
"strict") == 0)
753 "NILFS: \"%s\" option is invalid "
754 "for remount.\n", p);
769 "NILFS: Unrecognized mount option \"%s\"\n", p);
786 static int nilfs_setup_super(
struct super_block *sb,
int is_mount)
799 goto skip_mount_setup;
806 "NILFS warning: mounting fs with errors\n");
808 }
else if (max_mnt_count >= 0 && mnt_count >= max_mnt_count) {
810 "NILFS warning: maximal mount count reached\n");
830 struct buffer_head **pbh)
832 unsigned long long sb_index =
pos;
835 offset =
do_div(sb_index, blocksize);
836 *pbh = sb_bread(sb, sb_index);
851 #ifdef NILFS_ATIME_DISABLE
855 nilfs_set_default_options(sb, sbp);
862 return !parse_options(data, sb, 0) ? -
EINVAL : 0 ;
874 "optional features (%llx)\n",
875 (
unsigned long long)features);
882 "unsupported optional features (%llx)\n",
883 (
unsigned long long)features);
889 static int nilfs_get_root_dentry(
struct super_block *sb,
891 struct dentry **root_dentry)
894 struct dentry *dentry;
900 ret = PTR_ERR(inode);
923 if (IS_ERR(dentry)) {
924 ret = PTR_ERR(dentry);
928 *root_dentry = dentry;
938 struct dentry **root_dentry)
954 "not a snapshot (checkpoint number=%llu).\n",
955 (
unsigned long long)cno);
963 "(checkpoint number=%llu).\n",
964 (
unsigned long long)cno);
967 ret = nilfs_get_root_dentry(s, root, root_dentry);
974 static int nilfs_tree_was_touched(
struct dentry *root_dentry)
976 return root_dentry->
d_count > 1;
985 static int nilfs_try_to_shrink_tree(
struct dentry *root_dentry)
990 return nilfs_tree_was_touched(root_dentry);
998 struct dentry *dentry;
1001 if (cno < 0 || cno > nilfs->
ns_cno)
1004 if (cno >= nilfs_last_cno(nilfs))
1014 if (nilfs_tree_was_touched(dentry))
1015 ret = nilfs_try_to_shrink_tree(dentry);
1053 sb->
s_op = &nilfs_sops;
1059 bdi = sb->
s_bdev->bd_inode->i_mapping->backing_dev_info;
1066 cno = nilfs_last_cno(nilfs);
1070 "(checkpoint number=%llu).\n", (
unsigned long long)cno);
1077 goto failed_checkpoint;
1080 err = nilfs_get_root_dentry(sb, fsroot, &sb->
s_root);
1082 goto failed_segctor;
1088 nilfs_setup_super(sb,
true);
1113 unsigned long old_sb_flags;
1114 unsigned long old_mount_opt;
1120 if (!parse_options(data, sb, 1)) {
1128 if (!nilfs_valid_fs(nilfs)) {
1130 "remount because the filesystem is in an "
1131 "incomplete recovery state.\n", sb->
s_id);
1137 if (*flags & MS_RDONLY) {
1164 "remount RDWR because of unsupported optional "
1165 "features (%llx)\n",
1166 sb->
s_id, (
unsigned long long)features);
1173 root = NILFS_I(sb->
s_root->d_inode)->i_root;
1179 nilfs_setup_super(sb,
true);
1204 char *
p, *options =
data;
1210 p =
strsep(&options,
",");
1211 if (p !=
NULL && *p) {
1214 if (!(sd->
flags & MS_RDONLY)) {
1230 "NILFS: invalid mount option: %s\n", p);
1235 *(options - 1) =
',';
1240 static int nilfs_set_bdev_super(
struct super_block *s,
void *data)
1247 static int nilfs_test_bdev_super(
struct super_block *s,
void *data)
1252 static struct dentry *
1254 const char *dev_name,
void *data)
1259 struct dentry *root_dentry;
1260 int err, s_new =
false;
1262 if (!(flags & MS_RDONLY))
1266 if (IS_ERR(sd.
bdev))
1267 return ERR_CAST(sd.
bdev);
1271 if (nilfs_identify((
char *)data, &sd)) {
1282 if (sd.
bdev->bd_fsfreeze_count > 0) {
1287 s =
sget(fs_type, nilfs_test_bdev_super, nilfs_set_bdev_super, flags,
1305 err = nilfs_fill_super(s, data, flags &
MS_SILENT ? 1 : 0);
1310 }
else if (!sd.
cno) {
1313 if (nilfs_tree_was_touched(s->
s_root)) {
1314 busy = nilfs_try_to_shrink_tree(s->
s_root);
1315 if (busy && (flags ^ s->
s_flags) & MS_RDONLY) {
1317 "has a %s mount.\n",
1319 "read-only" :
"read/write");
1329 err = nilfs_remount(s, &flags, data);
1336 err = nilfs_attach_snapshot(s, sd.
cno, &root_dentry);
1340 root_dentry = dget(s->
s_root);
1354 return ERR_PTR(err);
1360 .mount = nilfs_mount,
1365 static void nilfs_inode_init_once(
void *obj)
1370 #ifdef CONFIG_NILFS_XATTR
1378 static void nilfs_segbuf_init_once(
void *obj)
1383 static void nilfs_destroy_cachep(
void)
1391 if (nilfs_inode_cachep)
1393 if (nilfs_transaction_cachep)
1395 if (nilfs_segbuf_cachep)
1397 if (nilfs_btree_path_cache)
1401 static int __init nilfs_init_cachep(
void)
1406 if (!nilfs_inode_cachep)
1412 if (!nilfs_transaction_cachep)
1418 if (!nilfs_segbuf_cachep)
1424 if (!nilfs_btree_path_cache)
1430 nilfs_destroy_cachep();
1434 static int __init init_nilfs_fs(
void)
1438 err = nilfs_init_cachep();
1450 nilfs_destroy_cachep();
1455 static void __exit exit_nilfs_fs(
void)
1457 nilfs_destroy_cachep();