diff options
Diffstat (limited to 'fs/nilfs2/the_nilfs.c')
-rw-r--r-- | fs/nilfs2/the_nilfs.c | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index b7666bc04256..4d6763e28eb5 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c | |||
@@ -92,11 +92,6 @@ struct the_nilfs *alloc_nilfs(struct block_device *bdev) | |||
92 | void destroy_nilfs(struct the_nilfs *nilfs) | 92 | void destroy_nilfs(struct the_nilfs *nilfs) |
93 | { | 93 | { |
94 | might_sleep(); | 94 | might_sleep(); |
95 | if (nilfs_loaded(nilfs)) { | ||
96 | nilfs_mdt_destroy(nilfs->ns_sufile); | ||
97 | nilfs_mdt_destroy(nilfs->ns_cpfile); | ||
98 | nilfs_mdt_destroy(nilfs->ns_dat); | ||
99 | } | ||
100 | if (nilfs_init(nilfs)) { | 95 | if (nilfs_init(nilfs)) { |
101 | brelse(nilfs->ns_sbh[0]); | 96 | brelse(nilfs->ns_sbh[0]); |
102 | brelse(nilfs->ns_sbh[1]); | 97 | brelse(nilfs->ns_sbh[1]); |
@@ -104,11 +99,13 @@ void destroy_nilfs(struct the_nilfs *nilfs) | |||
104 | kfree(nilfs); | 99 | kfree(nilfs); |
105 | } | 100 | } |
106 | 101 | ||
107 | static int nilfs_load_super_root(struct the_nilfs *nilfs, sector_t sr_block) | 102 | static int nilfs_load_super_root(struct the_nilfs *nilfs, |
103 | struct super_block *sb, sector_t sr_block) | ||
108 | { | 104 | { |
109 | struct buffer_head *bh_sr; | 105 | struct buffer_head *bh_sr; |
110 | struct nilfs_super_root *raw_sr; | 106 | struct nilfs_super_root *raw_sr; |
111 | struct nilfs_super_block **sbp = nilfs->ns_sbp; | 107 | struct nilfs_super_block **sbp = nilfs->ns_sbp; |
108 | struct nilfs_inode *rawi; | ||
112 | unsigned dat_entry_size, segment_usage_size, checkpoint_size; | 109 | unsigned dat_entry_size, segment_usage_size, checkpoint_size; |
113 | unsigned inode_size; | 110 | unsigned inode_size; |
114 | int err; | 111 | int err; |
@@ -125,34 +122,22 @@ static int nilfs_load_super_root(struct the_nilfs *nilfs, sector_t sr_block) | |||
125 | 122 | ||
126 | inode_size = nilfs->ns_inode_size; | 123 | inode_size = nilfs->ns_inode_size; |
127 | 124 | ||
128 | err = -ENOMEM; | 125 | rawi = (void *)bh_sr->b_data + NILFS_SR_DAT_OFFSET(inode_size); |
129 | nilfs->ns_dat = nilfs_dat_new(nilfs, dat_entry_size); | 126 | err = nilfs_dat_read(sb, dat_entry_size, rawi, &nilfs->ns_dat); |
130 | if (unlikely(!nilfs->ns_dat)) | 127 | if (err) |
131 | goto failed; | 128 | goto failed; |
132 | 129 | ||
133 | nilfs->ns_cpfile = nilfs_cpfile_new(nilfs, checkpoint_size); | 130 | rawi = (void *)bh_sr->b_data + NILFS_SR_CPFILE_OFFSET(inode_size); |
134 | if (unlikely(!nilfs->ns_cpfile)) | 131 | err = nilfs_cpfile_read(sb, checkpoint_size, rawi, &nilfs->ns_cpfile); |
132 | if (err) | ||
135 | goto failed_dat; | 133 | goto failed_dat; |
136 | 134 | ||
137 | nilfs->ns_sufile = nilfs_sufile_new(nilfs, segment_usage_size); | 135 | rawi = (void *)bh_sr->b_data + NILFS_SR_SUFILE_OFFSET(inode_size); |
138 | if (unlikely(!nilfs->ns_sufile)) | 136 | err = nilfs_sufile_read(sb, segment_usage_size, rawi, |
137 | &nilfs->ns_sufile); | ||
138 | if (err) | ||
139 | goto failed_cpfile; | 139 | goto failed_cpfile; |
140 | 140 | ||
141 | err = nilfs_dat_read(nilfs->ns_dat, (void *)bh_sr->b_data + | ||
142 | NILFS_SR_DAT_OFFSET(inode_size)); | ||
143 | if (unlikely(err)) | ||
144 | goto failed_sufile; | ||
145 | |||
146 | err = nilfs_cpfile_read(nilfs->ns_cpfile, (void *)bh_sr->b_data + | ||
147 | NILFS_SR_CPFILE_OFFSET(inode_size)); | ||
148 | if (unlikely(err)) | ||
149 | goto failed_sufile; | ||
150 | |||
151 | err = nilfs_sufile_read(nilfs->ns_sufile, (void *)bh_sr->b_data + | ||
152 | NILFS_SR_SUFILE_OFFSET(inode_size)); | ||
153 | if (unlikely(err)) | ||
154 | goto failed_sufile; | ||
155 | |||
156 | raw_sr = (struct nilfs_super_root *)bh_sr->b_data; | 141 | raw_sr = (struct nilfs_super_root *)bh_sr->b_data; |
157 | nilfs->ns_nongc_ctime = le64_to_cpu(raw_sr->sr_nongc_ctime); | 142 | nilfs->ns_nongc_ctime = le64_to_cpu(raw_sr->sr_nongc_ctime); |
158 | 143 | ||
@@ -160,14 +145,11 @@ static int nilfs_load_super_root(struct the_nilfs *nilfs, sector_t sr_block) | |||
160 | brelse(bh_sr); | 145 | brelse(bh_sr); |
161 | return err; | 146 | return err; |
162 | 147 | ||
163 | failed_sufile: | ||
164 | nilfs_mdt_destroy(nilfs->ns_sufile); | ||
165 | |||
166 | failed_cpfile: | 148 | failed_cpfile: |
167 | nilfs_mdt_destroy(nilfs->ns_cpfile); | 149 | iput(nilfs->ns_cpfile); |
168 | 150 | ||
169 | failed_dat: | 151 | failed_dat: |
170 | nilfs_mdt_destroy(nilfs->ns_dat); | 152 | iput(nilfs->ns_dat); |
171 | goto failed; | 153 | goto failed; |
172 | } | 154 | } |
173 | 155 | ||
@@ -290,7 +272,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | |||
290 | goto scan_error; | 272 | goto scan_error; |
291 | } | 273 | } |
292 | 274 | ||
293 | err = nilfs_load_super_root(nilfs, ri.ri_super_root); | 275 | err = nilfs_load_super_root(nilfs, sbi->s_super, ri.ri_super_root); |
294 | if (unlikely(err)) { | 276 | if (unlikely(err)) { |
295 | printk(KERN_ERR "NILFS: error loading super root.\n"); | 277 | printk(KERN_ERR "NILFS: error loading super root.\n"); |
296 | goto failed; | 278 | goto failed; |
@@ -358,9 +340,9 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | |||
358 | goto failed; | 340 | goto failed; |
359 | 341 | ||
360 | failed_unload: | 342 | failed_unload: |
361 | nilfs_mdt_destroy(nilfs->ns_cpfile); | 343 | iput(nilfs->ns_cpfile); |
362 | nilfs_mdt_destroy(nilfs->ns_sufile); | 344 | iput(nilfs->ns_sufile); |
363 | nilfs_mdt_destroy(nilfs->ns_dat); | 345 | iput(nilfs->ns_dat); |
364 | 346 | ||
365 | failed: | 347 | failed: |
366 | nilfs_clear_recovery_info(&ri); | 348 | nilfs_clear_recovery_info(&ri); |
@@ -782,7 +764,7 @@ void nilfs_put_root(struct nilfs_root *root) | |||
782 | rb_erase(&root->rb_node, &nilfs->ns_cptree); | 764 | rb_erase(&root->rb_node, &nilfs->ns_cptree); |
783 | spin_unlock(&nilfs->ns_cptree_lock); | 765 | spin_unlock(&nilfs->ns_cptree_lock); |
784 | if (root->ifile) | 766 | if (root->ifile) |
785 | nilfs_mdt_destroy(root->ifile); | 767 | iput(root->ifile); |
786 | 768 | ||
787 | kfree(root); | 769 | kfree(root); |
788 | } | 770 | } |