aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/super.c
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-09-08 13:07:56 -0400
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-10-22 20:24:36 -0400
commit348fe8da13621b3d14ab2d156e74551611997017 (patch)
tree82e60058d2af36e5f6e8bb7851b5b25ba3e72909 /fs/nilfs2/super.c
parentf11459ad7dab9e9eb5a05b8bd3bec338ea8f485d (diff)
nilfs2: simplify life cycle management of nilfs object
This stops pre-allocating nilfs object in nilfs_get_sb routine, and stops managing its life cycle by reference counting. nilfs_find_or_create_nilfs() function, nilfs->ns_mount_mutex, nilfs_objects list, and the reference counter will be removed through the simplification. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Diffstat (limited to 'fs/nilfs2/super.c')
-rw-r--r--fs/nilfs2/super.c67
1 files changed, 22 insertions, 45 deletions
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 2e58e7c629b5..5893cb27c909 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -356,7 +356,7 @@ static void nilfs_put_super(struct super_block *sb)
356 up_write(&nilfs->ns_sem); 356 up_write(&nilfs->ns_sem);
357 } 357 }
358 358
359 put_nilfs(sbi->s_nilfs); 359 destroy_nilfs(nilfs);
360 sbi->s_super = NULL; 360 sbi->s_super = NULL;
361 sb->s_fs_info = NULL; 361 sb->s_fs_info = NULL;
362 kfree(sbi); 362 kfree(sbi);
@@ -836,15 +836,14 @@ static int nilfs_try_to_shrink_tree(struct dentry *root_dentry)
836 * @sb: super_block 836 * @sb: super_block
837 * @data: mount options 837 * @data: mount options
838 * @silent: silent mode flag 838 * @silent: silent mode flag
839 * @nilfs: the_nilfs struct
840 * 839 *
841 * This function is called exclusively by nilfs->ns_mount_mutex. 840 * This function is called exclusively by nilfs->ns_mount_mutex.
842 * So, the recovery process is protected from other simultaneous mounts. 841 * So, the recovery process is protected from other simultaneous mounts.
843 */ 842 */
844static int 843static int
845nilfs_fill_super(struct super_block *sb, void *data, int silent, 844nilfs_fill_super(struct super_block *sb, void *data, int silent)
846 struct the_nilfs *nilfs)
847{ 845{
846 struct the_nilfs *nilfs;
848 struct nilfs_sb_info *sbi; 847 struct nilfs_sb_info *sbi;
849 struct nilfs_root *fsroot; 848 struct nilfs_root *fsroot;
850 __u64 cno; 849 __u64 cno;
@@ -855,14 +854,18 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
855 return -ENOMEM; 854 return -ENOMEM;
856 855
857 sb->s_fs_info = sbi; 856 sb->s_fs_info = sbi;
857 sbi->s_super = sb;
858 858
859 get_nilfs(nilfs); 859 nilfs = alloc_nilfs(sb->s_bdev);
860 if (!nilfs) {
861 err = -ENOMEM;
862 goto failed_sbi;
863 }
860 sbi->s_nilfs = nilfs; 864 sbi->s_nilfs = nilfs;
861 sbi->s_super = sb;
862 865
863 err = init_nilfs(nilfs, sbi, (char *)data); 866 err = init_nilfs(nilfs, sbi, (char *)data);
864 if (err) 867 if (err)
865 goto failed_sbi; 868 goto failed_nilfs;
866 869
867 spin_lock_init(&sbi->s_inode_lock); 870 spin_lock_init(&sbi->s_inode_lock);
868 INIT_LIST_HEAD(&sbi->s_dirty_files); 871 INIT_LIST_HEAD(&sbi->s_dirty_files);
@@ -885,14 +888,14 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
885 888
886 err = load_nilfs(nilfs, sbi); 889 err = load_nilfs(nilfs, sbi);
887 if (err) 890 if (err)
888 goto failed_sbi; 891 goto failed_nilfs;
889 892
890 cno = nilfs_last_cno(nilfs); 893 cno = nilfs_last_cno(nilfs);
891 err = nilfs_attach_checkpoint(sbi, cno, true, &fsroot); 894 err = nilfs_attach_checkpoint(sbi, cno, true, &fsroot);
892 if (err) { 895 if (err) {
893 printk(KERN_ERR "NILFS: error loading last checkpoint " 896 printk(KERN_ERR "NILFS: error loading last checkpoint "
894 "(checkpoint number=%llu).\n", (unsigned long long)cno); 897 "(checkpoint number=%llu).\n", (unsigned long long)cno);
895 goto failed_sbi; 898 goto failed_nilfs;
896 } 899 }
897 900
898 if (!(sb->s_flags & MS_RDONLY)) { 901 if (!(sb->s_flags & MS_RDONLY)) {
@@ -921,8 +924,10 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
921 failed_checkpoint: 924 failed_checkpoint:
922 nilfs_put_root(fsroot); 925 nilfs_put_root(fsroot);
923 926
927 failed_nilfs:
928 destroy_nilfs(nilfs);
929
924 failed_sbi: 930 failed_sbi:
925 put_nilfs(nilfs);
926 sb->s_fs_info = NULL; 931 sb->s_fs_info = NULL;
927 kfree(sbi); 932 kfree(sbi);
928 return err; 933 return err;
@@ -1077,7 +1082,6 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1077 struct nilfs_super_data sd; 1082 struct nilfs_super_data sd;
1078 struct super_block *s; 1083 struct super_block *s;
1079 fmode_t mode = FMODE_READ; 1084 fmode_t mode = FMODE_READ;
1080 struct the_nilfs *nilfs;
1081 struct dentry *root_dentry; 1085 struct dentry *root_dentry;
1082 int err, s_new = false; 1086 int err, s_new = false;
1083 1087
@@ -1095,18 +1099,10 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1095 goto failed; 1099 goto failed;
1096 } 1100 }
1097 1101
1098 nilfs = find_or_create_nilfs(sd.bdev);
1099 if (!nilfs) {
1100 err = -ENOMEM;
1101 goto failed;
1102 }
1103
1104 mutex_lock(&nilfs->ns_mount_mutex);
1105
1106 s = sget(fs_type, nilfs_test_bdev_super, nilfs_set_bdev_super, sd.bdev); 1102 s = sget(fs_type, nilfs_test_bdev_super, nilfs_set_bdev_super, sd.bdev);
1107 if (IS_ERR(s)) { 1103 if (IS_ERR(s)) {
1108 err = PTR_ERR(s); 1104 err = PTR_ERR(s);
1109 goto failed_unlock; 1105 goto failed;
1110 } 1106 }
1111 1107
1112 if (!s->s_root) { 1108 if (!s->s_root) {
@@ -1120,10 +1116,9 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1120 strlcpy(s->s_id, bdevname(sd.bdev, b), sizeof(s->s_id)); 1116 strlcpy(s->s_id, bdevname(sd.bdev, b), sizeof(s->s_id));
1121 sb_set_blocksize(s, block_size(sd.bdev)); 1117 sb_set_blocksize(s, block_size(sd.bdev));
1122 1118
1123 err = nilfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0, 1119 err = nilfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
1124 nilfs);
1125 if (err) 1120 if (err)
1126 goto cancel_new; 1121 goto failed_super;
1127 1122
1128 s->s_flags |= MS_ACTIVE; 1123 s->s_flags |= MS_ACTIVE;
1129 } else if (!sd.cno) { 1124 } else if (!sd.cno) {
@@ -1153,17 +1148,12 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1153 1148
1154 if (sd.cno) { 1149 if (sd.cno) {
1155 err = nilfs_attach_snapshot(s, sd.cno, &root_dentry); 1150 err = nilfs_attach_snapshot(s, sd.cno, &root_dentry);
1156 if (err) { 1151 if (err)
1157 if (s_new)
1158 goto cancel_new;
1159 goto failed_super; 1152 goto failed_super;
1160 }
1161 } else { 1153 } else {
1162 root_dentry = dget(s->s_root); 1154 root_dentry = dget(s->s_root);
1163 } 1155 }
1164 1156
1165 mutex_unlock(&nilfs->ns_mount_mutex);
1166 put_nilfs(nilfs);
1167 if (!s_new) 1157 if (!s_new)
1168 close_bdev_exclusive(sd.bdev, mode); 1158 close_bdev_exclusive(sd.bdev, mode);
1169 1159
@@ -1173,23 +1163,10 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
1173 1163
1174 failed_super: 1164 failed_super:
1175 deactivate_locked_super(s); 1165 deactivate_locked_super(s);
1176 failed_unlock:
1177 mutex_unlock(&nilfs->ns_mount_mutex);
1178 put_nilfs(nilfs);
1179 failed:
1180 close_bdev_exclusive(sd.bdev, mode);
1181 return err;
1182 1166
1183 cancel_new: 1167 failed:
1184 /* Abandoning the newly allocated superblock */ 1168 if (!s_new)
1185 mutex_unlock(&nilfs->ns_mount_mutex); 1169 close_bdev_exclusive(sd.bdev, mode);
1186 put_nilfs(nilfs);
1187 deactivate_locked_super(s);
1188 /*
1189 * This deactivate_locked_super() invokes close_bdev_exclusive().
1190 * We must finish all post-cleaning before this call;
1191 * put_nilfs() needs the block device.
1192 */
1193 return err; 1170 return err;
1194} 1171}
1195 1172