aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nilfs2/super.c')
-rw-r--r--fs/nilfs2/super.c219
1 files changed, 115 insertions, 104 deletions
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 0cdbc5e7655a..03b34b738993 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -67,6 +67,11 @@ MODULE_DESCRIPTION("A New Implementation of the Log-structured Filesystem "
67 "(NILFS)"); 67 "(NILFS)");
68MODULE_LICENSE("GPL"); 68MODULE_LICENSE("GPL");
69 69
70struct kmem_cache *nilfs_inode_cachep;
71struct kmem_cache *nilfs_transaction_cachep;
72struct kmem_cache *nilfs_segbuf_cachep;
73struct kmem_cache *nilfs_btree_path_cache;
74
70static int nilfs_remount(struct super_block *sb, int *flags, char *data); 75static int nilfs_remount(struct super_block *sb, int *flags, char *data);
71 76
72/** 77/**
@@ -129,7 +134,6 @@ void nilfs_warning(struct super_block *sb, const char *function,
129 va_end(args); 134 va_end(args);
130} 135}
131 136
132static struct kmem_cache *nilfs_inode_cachep;
133 137
134struct inode *nilfs_alloc_inode_common(struct the_nilfs *nilfs) 138struct inode *nilfs_alloc_inode_common(struct the_nilfs *nilfs)
135{ 139{
@@ -155,34 +159,6 @@ void nilfs_destroy_inode(struct inode *inode)
155 kmem_cache_free(nilfs_inode_cachep, NILFS_I(inode)); 159 kmem_cache_free(nilfs_inode_cachep, NILFS_I(inode));
156} 160}
157 161
158static void init_once(void *obj)
159{
160 struct nilfs_inode_info *ii = obj;
161
162 INIT_LIST_HEAD(&ii->i_dirty);
163#ifdef CONFIG_NILFS_XATTR
164 init_rwsem(&ii->xattr_sem);
165#endif
166 nilfs_btnode_cache_init_once(&ii->i_btnode_cache);
167 ii->i_bmap = (struct nilfs_bmap *)&ii->i_bmap_union;
168 inode_init_once(&ii->vfs_inode);
169}
170
171static int nilfs_init_inode_cache(void)
172{
173 nilfs_inode_cachep = kmem_cache_create("nilfs2_inode_cache",
174 sizeof(struct nilfs_inode_info),
175 0, SLAB_RECLAIM_ACCOUNT,
176 init_once);
177
178 return (nilfs_inode_cachep == NULL) ? -ENOMEM : 0;
179}
180
181static inline void nilfs_destroy_inode_cache(void)
182{
183 kmem_cache_destroy(nilfs_inode_cachep);
184}
185
186static void nilfs_clear_inode(struct inode *inode) 162static void nilfs_clear_inode(struct inode *inode)
187{ 163{
188 struct nilfs_inode_info *ii = NILFS_I(inode); 164 struct nilfs_inode_info *ii = NILFS_I(inode);
@@ -266,8 +242,8 @@ int nilfs_commit_super(struct nilfs_sb_info *sbi, int dupsb)
266 int err; 242 int err;
267 243
268 /* nilfs->sem must be locked by the caller. */ 244 /* nilfs->sem must be locked by the caller. */
269 if (sbp[0]->s_magic != NILFS_SUPER_MAGIC) { 245 if (sbp[0]->s_magic != cpu_to_le16(NILFS_SUPER_MAGIC)) {
270 if (sbp[1] && sbp[1]->s_magic == NILFS_SUPER_MAGIC) 246 if (sbp[1] && sbp[1]->s_magic == cpu_to_le16(NILFS_SUPER_MAGIC))
271 nilfs_swap_super_block(nilfs); 247 nilfs_swap_super_block(nilfs);
272 else { 248 else {
273 printk(KERN_CRIT "NILFS: superblock broke on dev %s\n", 249 printk(KERN_CRIT "NILFS: superblock broke on dev %s\n",
@@ -470,10 +446,10 @@ static int nilfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
470 if (nilfs_test_opt(sbi, SNAPSHOT)) 446 if (nilfs_test_opt(sbi, SNAPSHOT))
471 seq_printf(seq, ",cp=%llu", 447 seq_printf(seq, ",cp=%llu",
472 (unsigned long long int)sbi->s_snapshot_cno); 448 (unsigned long long int)sbi->s_snapshot_cno);
473 if (nilfs_test_opt(sbi, ERRORS_RO))
474 seq_printf(seq, ",errors=remount-ro");
475 if (nilfs_test_opt(sbi, ERRORS_PANIC)) 449 if (nilfs_test_opt(sbi, ERRORS_PANIC))
476 seq_printf(seq, ",errors=panic"); 450 seq_printf(seq, ",errors=panic");
451 if (nilfs_test_opt(sbi, ERRORS_CONT))
452 seq_printf(seq, ",errors=continue");
477 if (nilfs_test_opt(sbi, STRICT_ORDER)) 453 if (nilfs_test_opt(sbi, STRICT_ORDER))
478 seq_printf(seq, ",order=strict"); 454 seq_printf(seq, ",order=strict");
479 if (nilfs_test_opt(sbi, NORECOVERY)) 455 if (nilfs_test_opt(sbi, NORECOVERY))
@@ -631,7 +607,7 @@ nilfs_set_default_options(struct nilfs_sb_info *sbi,
631 struct nilfs_super_block *sbp) 607 struct nilfs_super_block *sbp)
632{ 608{
633 sbi->s_mount_opt = 609 sbi->s_mount_opt =
634 NILFS_MOUNT_ERRORS_CONT | NILFS_MOUNT_BARRIER; 610 NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER;
635} 611}
636 612
637static int nilfs_setup_super(struct nilfs_sb_info *sbi) 613static int nilfs_setup_super(struct nilfs_sb_info *sbi)
@@ -749,6 +725,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
749 sb->s_export_op = &nilfs_export_ops; 725 sb->s_export_op = &nilfs_export_ops;
750 sb->s_root = NULL; 726 sb->s_root = NULL;
751 sb->s_time_gran = 1; 727 sb->s_time_gran = 1;
728 sb->s_bdi = nilfs->ns_bdi;
752 729
753 err = load_nilfs(nilfs, sbi); 730 err = load_nilfs(nilfs, sbi);
754 if (err) 731 if (err)
@@ -777,9 +754,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
777 goto failed_sbi; 754 goto failed_sbi;
778 } 755 }
779 cno = sbi->s_snapshot_cno; 756 cno = sbi->s_snapshot_cno;
780 } else 757 }
781 /* Read-only mount */
782 sbi->s_snapshot_cno = cno;
783 } 758 }
784 759
785 err = nilfs_attach_checkpoint(sbi, cno); 760 err = nilfs_attach_checkpoint(sbi, cno);
@@ -848,7 +823,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
848 struct the_nilfs *nilfs = sbi->s_nilfs; 823 struct the_nilfs *nilfs = sbi->s_nilfs;
849 unsigned long old_sb_flags; 824 unsigned long old_sb_flags;
850 struct nilfs_mount_options old_opts; 825 struct nilfs_mount_options old_opts;
851 int err; 826 int was_snapshot, err;
852 827
853 lock_kernel(); 828 lock_kernel();
854 829
@@ -856,6 +831,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
856 old_sb_flags = sb->s_flags; 831 old_sb_flags = sb->s_flags;
857 old_opts.mount_opt = sbi->s_mount_opt; 832 old_opts.mount_opt = sbi->s_mount_opt;
858 old_opts.snapshot_cno = sbi->s_snapshot_cno; 833 old_opts.snapshot_cno = sbi->s_snapshot_cno;
834 was_snapshot = nilfs_test_opt(sbi, SNAPSHOT);
859 835
860 if (!parse_options(data, sb)) { 836 if (!parse_options(data, sb)) {
861 err = -EINVAL; 837 err = -EINVAL;
@@ -863,20 +839,32 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
863 } 839 }
864 sb->s_flags = (sb->s_flags & ~MS_POSIXACL); 840 sb->s_flags = (sb->s_flags & ~MS_POSIXACL);
865 841
866 if ((*flags & MS_RDONLY) && 842 err = -EINVAL;
867 sbi->s_snapshot_cno != old_opts.snapshot_cno) { 843 if (was_snapshot) {
868 printk(KERN_WARNING "NILFS (device %s): couldn't " 844 if (!(*flags & MS_RDONLY)) {
869 "remount to a different snapshot.\n", 845 printk(KERN_ERR "NILFS (device %s): cannot remount "
870 sb->s_id); 846 "snapshot read/write.\n",
871 err = -EINVAL; 847 sb->s_id);
872 goto restore_opts; 848 goto restore_opts;
849 } else if (sbi->s_snapshot_cno != old_opts.snapshot_cno) {
850 printk(KERN_ERR "NILFS (device %s): cannot "
851 "remount to a different snapshot.\n",
852 sb->s_id);
853 goto restore_opts;
854 }
855 } else {
856 if (nilfs_test_opt(sbi, SNAPSHOT)) {
857 printk(KERN_ERR "NILFS (device %s): cannot change "
858 "a regular mount to a snapshot.\n",
859 sb->s_id);
860 goto restore_opts;
861 }
873 } 862 }
874 863
875 if (!nilfs_valid_fs(nilfs)) { 864 if (!nilfs_valid_fs(nilfs)) {
876 printk(KERN_WARNING "NILFS (device %s): couldn't " 865 printk(KERN_WARNING "NILFS (device %s): couldn't "
877 "remount because the filesystem is in an " 866 "remount because the filesystem is in an "
878 "incomplete recovery state.\n", sb->s_id); 867 "incomplete recovery state.\n", sb->s_id);
879 err = -EINVAL;
880 goto restore_opts; 868 goto restore_opts;
881 } 869 }
882 870
@@ -887,9 +875,6 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
887 nilfs_detach_segment_constructor(sbi); 875 nilfs_detach_segment_constructor(sbi);
888 sb->s_flags |= MS_RDONLY; 876 sb->s_flags |= MS_RDONLY;
889 877
890 sbi->s_snapshot_cno = nilfs_last_cno(nilfs);
891 /* nilfs_set_opt(sbi, SNAPSHOT); */
892
893 /* 878 /*
894 * Remounting a valid RW partition RDONLY, so set 879 * Remounting a valid RW partition RDONLY, so set
895 * the RDONLY flag and then mark the partition as valid again. 880 * the RDONLY flag and then mark the partition as valid again.
@@ -908,24 +893,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
908 * store the current valid flag. (It may have been changed 893 * store the current valid flag. (It may have been changed
909 * by fsck since we originally mounted the partition.) 894 * by fsck since we originally mounted the partition.)
910 */ 895 */
911 if (nilfs->ns_current && nilfs->ns_current != sbi) {
912 printk(KERN_WARNING "NILFS (device %s): couldn't "
913 "remount because an RW-mount exists.\n",
914 sb->s_id);
915 err = -EBUSY;
916 goto restore_opts;
917 }
918 if (sbi->s_snapshot_cno != nilfs_last_cno(nilfs)) {
919 printk(KERN_WARNING "NILFS (device %s): couldn't "
920 "remount because the current RO-mount is not "
921 "the latest one.\n",
922 sb->s_id);
923 err = -EINVAL;
924 goto restore_opts;
925 }
926 sb->s_flags &= ~MS_RDONLY; 896 sb->s_flags &= ~MS_RDONLY;
927 nilfs_clear_opt(sbi, SNAPSHOT);
928 sbi->s_snapshot_cno = 0;
929 897
930 err = nilfs_attach_segment_constructor(sbi); 898 err = nilfs_attach_segment_constructor(sbi);
931 if (err) 899 if (err)
@@ -934,8 +902,6 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
934 down_write(&nilfs->ns_sem); 902 down_write(&nilfs->ns_sem);
935 nilfs_setup_super(sbi); 903 nilfs_setup_super(sbi);
936 up_write(&nilfs->ns_sem); 904 up_write(&nilfs->ns_sem);
937
938 nilfs->ns_current = sbi;
939 } 905 }
940 out: 906 out:
941 up_write(&nilfs->ns_super_sem); 907 up_write(&nilfs->ns_super_sem);
@@ -1021,10 +987,14 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1021{ 987{
1022 struct nilfs_super_data sd; 988 struct nilfs_super_data sd;
1023 struct super_block *s; 989 struct super_block *s;
990 fmode_t mode = FMODE_READ;
1024 struct the_nilfs *nilfs; 991 struct the_nilfs *nilfs;
1025 int err, need_to_close = 1; 992 int err, need_to_close = 1;
1026 993
1027 sd.bdev = open_bdev_exclusive(dev_name, flags, fs_type); 994 if (!(flags & MS_RDONLY))
995 mode |= FMODE_WRITE;
996
997 sd.bdev = open_bdev_exclusive(dev_name, mode, fs_type);
1028 if (IS_ERR(sd.bdev)) 998 if (IS_ERR(sd.bdev))
1029 return PTR_ERR(sd.bdev); 999 return PTR_ERR(sd.bdev);
1030 1000
@@ -1091,10 +1061,12 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1091 1061
1092 /* New superblock instance created */ 1062 /* New superblock instance created */
1093 s->s_flags = flags; 1063 s->s_flags = flags;
1064 s->s_mode = mode;
1094 strlcpy(s->s_id, bdevname(sd.bdev, b), sizeof(s->s_id)); 1065 strlcpy(s->s_id, bdevname(sd.bdev, b), sizeof(s->s_id));
1095 sb_set_blocksize(s, block_size(sd.bdev)); 1066 sb_set_blocksize(s, block_size(sd.bdev));
1096 1067
1097 err = nilfs_fill_super(s, data, flags & MS_VERBOSE, nilfs); 1068 err = nilfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0,
1069 nilfs);
1098 if (err) 1070 if (err)
1099 goto cancel_new; 1071 goto cancel_new;
1100 1072
@@ -1105,7 +1077,7 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1105 mutex_unlock(&nilfs->ns_mount_mutex); 1077 mutex_unlock(&nilfs->ns_mount_mutex);
1106 put_nilfs(nilfs); 1078 put_nilfs(nilfs);
1107 if (need_to_close) 1079 if (need_to_close)
1108 close_bdev_exclusive(sd.bdev, flags); 1080 close_bdev_exclusive(sd.bdev, mode);
1109 simple_set_mnt(mnt, s); 1081 simple_set_mnt(mnt, s);
1110 return 0; 1082 return 0;
1111 1083
@@ -1113,7 +1085,7 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1113 mutex_unlock(&nilfs->ns_mount_mutex); 1085 mutex_unlock(&nilfs->ns_mount_mutex);
1114 put_nilfs(nilfs); 1086 put_nilfs(nilfs);
1115 failed: 1087 failed:
1116 close_bdev_exclusive(sd.bdev, flags); 1088 close_bdev_exclusive(sd.bdev, mode);
1117 1089
1118 return err; 1090 return err;
1119 1091
@@ -1123,7 +1095,7 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1123 put_nilfs(nilfs); 1095 put_nilfs(nilfs);
1124 deactivate_locked_super(s); 1096 deactivate_locked_super(s);
1125 /* 1097 /*
1126 * deactivate_super() invokes close_bdev_exclusive(). 1098 * deactivate_locked_super() invokes close_bdev_exclusive().
1127 * We must finish all post-cleaning before this call; 1099 * We must finish all post-cleaning before this call;
1128 * put_nilfs() needs the block device. 1100 * put_nilfs() needs the block device.
1129 */ 1101 */
@@ -1138,54 +1110,93 @@ struct file_system_type nilfs_fs_type = {
1138 .fs_flags = FS_REQUIRES_DEV, 1110 .fs_flags = FS_REQUIRES_DEV,
1139}; 1111};
1140 1112
1141static int __init init_nilfs_fs(void) 1113static void nilfs_inode_init_once(void *obj)
1142{ 1114{
1143 int err; 1115 struct nilfs_inode_info *ii = obj;
1144
1145 err = nilfs_init_inode_cache();
1146 if (err)
1147 goto failed;
1148 1116
1149 err = nilfs_init_transaction_cache(); 1117 INIT_LIST_HEAD(&ii->i_dirty);
1150 if (err) 1118#ifdef CONFIG_NILFS_XATTR
1151 goto failed_inode_cache; 1119 init_rwsem(&ii->xattr_sem);
1120#endif
1121 nilfs_btnode_cache_init_once(&ii->i_btnode_cache);
1122 ii->i_bmap = (struct nilfs_bmap *)&ii->i_bmap_union;
1123 inode_init_once(&ii->vfs_inode);
1124}
1152 1125
1153 err = nilfs_init_segbuf_cache(); 1126static void nilfs_segbuf_init_once(void *obj)
1154 if (err) 1127{
1155 goto failed_transaction_cache; 1128 memset(obj, 0, sizeof(struct nilfs_segment_buffer));
1129}
1156 1130
1157 err = nilfs_btree_path_cache_init(); 1131static void nilfs_destroy_cachep(void)
1158 if (err) 1132{
1159 goto failed_segbuf_cache; 1133 if (nilfs_inode_cachep)
1134 kmem_cache_destroy(nilfs_inode_cachep);
1135 if (nilfs_transaction_cachep)
1136 kmem_cache_destroy(nilfs_transaction_cachep);
1137 if (nilfs_segbuf_cachep)
1138 kmem_cache_destroy(nilfs_segbuf_cachep);
1139 if (nilfs_btree_path_cache)
1140 kmem_cache_destroy(nilfs_btree_path_cache);
1141}
1160 1142
1161 err = register_filesystem(&nilfs_fs_type); 1143static int __init nilfs_init_cachep(void)
1162 if (err) 1144{
1163 goto failed_btree_path_cache; 1145 nilfs_inode_cachep = kmem_cache_create("nilfs2_inode_cache",
1146 sizeof(struct nilfs_inode_info), 0,
1147 SLAB_RECLAIM_ACCOUNT, nilfs_inode_init_once);
1148 if (!nilfs_inode_cachep)
1149 goto fail;
1150
1151 nilfs_transaction_cachep = kmem_cache_create("nilfs2_transaction_cache",
1152 sizeof(struct nilfs_transaction_info), 0,
1153 SLAB_RECLAIM_ACCOUNT, NULL);
1154 if (!nilfs_transaction_cachep)
1155 goto fail;
1156
1157 nilfs_segbuf_cachep = kmem_cache_create("nilfs2_segbuf_cache",
1158 sizeof(struct nilfs_segment_buffer), 0,
1159 SLAB_RECLAIM_ACCOUNT, nilfs_segbuf_init_once);
1160 if (!nilfs_segbuf_cachep)
1161 goto fail;
1162
1163 nilfs_btree_path_cache = kmem_cache_create("nilfs2_btree_path_cache",
1164 sizeof(struct nilfs_btree_path) * NILFS_BTREE_LEVEL_MAX,
1165 0, 0, NULL);
1166 if (!nilfs_btree_path_cache)
1167 goto fail;
1164 1168
1165 return 0; 1169 return 0;
1166 1170
1167 failed_btree_path_cache: 1171fail:
1168 nilfs_btree_path_cache_destroy(); 1172 nilfs_destroy_cachep();
1173 return -ENOMEM;
1174}
1175
1176static int __init init_nilfs_fs(void)
1177{
1178 int err;
1169 1179
1170 failed_segbuf_cache: 1180 err = nilfs_init_cachep();
1171 nilfs_destroy_segbuf_cache(); 1181 if (err)
1182 goto fail;
1172 1183
1173 failed_transaction_cache: 1184 err = register_filesystem(&nilfs_fs_type);
1174 nilfs_destroy_transaction_cache(); 1185 if (err)
1186 goto free_cachep;
1175 1187
1176 failed_inode_cache: 1188 printk(KERN_INFO "NILFS version 2 loaded\n");
1177 nilfs_destroy_inode_cache(); 1189 return 0;
1178 1190
1179 failed: 1191free_cachep:
1192 nilfs_destroy_cachep();
1193fail:
1180 return err; 1194 return err;
1181} 1195}
1182 1196
1183static void __exit exit_nilfs_fs(void) 1197static void __exit exit_nilfs_fs(void)
1184{ 1198{
1185 nilfs_destroy_segbuf_cache(); 1199 nilfs_destroy_cachep();
1186 nilfs_destroy_transaction_cache();
1187 nilfs_destroy_inode_cache();
1188 nilfs_btree_path_cache_destroy();
1189 unregister_filesystem(&nilfs_fs_type); 1200 unregister_filesystem(&nilfs_fs_type);
1190} 1201}
1191 1202