aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2009-11-12 09:56:43 -0500
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2009-11-19 20:05:48 -0500
commit79739565e15f2adbc482207a0800fc127c84d1a0 (patch)
tree10d61f5a31e4de5c90a6c9c10f0f0bc8e68d1550
parent5731e191f254af9135ad843119804a500528ecf3 (diff)
nilfs2: separate constructor of metadata files
This will displace nilfs_mdt_new() constructor with individual metadata file constructors like nilfs_dat_new(), new_sufile_new(), nilfs_cpfile_new(), and nilfs_ifile_new(). This makes it possible for each metadata file to have own intialization code. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
-rw-r--r--fs/nilfs2/cpfile.c16
-rw-r--r--fs/nilfs2/cpfile.h2
-rw-r--r--fs/nilfs2/dat.c23
-rw-r--r--fs/nilfs2/dat.h2
-rw-r--r--fs/nilfs2/ifile.c21
-rw-r--r--fs/nilfs2/ifile.h2
-rw-r--r--fs/nilfs2/sufile.c16
-rw-r--r--fs/nilfs2/sufile.h2
-rw-r--r--fs/nilfs2/super.c6
-rw-r--r--fs/nilfs2/the_nilfs.c24
10 files changed, 89 insertions, 25 deletions
diff --git a/fs/nilfs2/cpfile.c b/fs/nilfs2/cpfile.c
index 3f5d5d06f53c..2aaefaec1567 100644
--- a/fs/nilfs2/cpfile.c
+++ b/fs/nilfs2/cpfile.c
@@ -926,3 +926,19 @@ int nilfs_cpfile_get_stat(struct inode *cpfile, struct nilfs_cpstat *cpstat)
926 up_read(&NILFS_MDT(cpfile)->mi_sem); 926 up_read(&NILFS_MDT(cpfile)->mi_sem);
927 return ret; 927 return ret;
928} 928}
929
930/**
931 * nilfs_cpfile_new - create cpfile
932 * @nilfs: nilfs object
933 * @cpsize: size of a checkpoint entry
934 */
935struct inode *nilfs_cpfile_new(struct the_nilfs *nilfs, size_t cpsize)
936{
937 struct inode *cpfile;
938
939 cpfile = nilfs_mdt_new(nilfs, NULL, NILFS_CPFILE_INO, 0);
940 if (cpfile)
941 nilfs_mdt_set_entry_size(cpfile, cpsize,
942 sizeof(struct nilfs_cpfile_header));
943 return cpfile;
944}
diff --git a/fs/nilfs2/cpfile.h b/fs/nilfs2/cpfile.h
index debea896e701..8ff2b4f4656b 100644
--- a/fs/nilfs2/cpfile.h
+++ b/fs/nilfs2/cpfile.h
@@ -40,4 +40,6 @@ int nilfs_cpfile_get_stat(struct inode *, struct nilfs_cpstat *);
40ssize_t nilfs_cpfile_get_cpinfo(struct inode *, __u64 *, int, void *, unsigned, 40ssize_t nilfs_cpfile_get_cpinfo(struct inode *, __u64 *, int, void *, unsigned,
41 size_t); 41 size_t);
42 42
43struct inode *nilfs_cpfile_new(struct the_nilfs *nilfs, size_t cpsize);
44
43#endif /* _NILFS_CPFILE_H */ 45#endif /* _NILFS_CPFILE_H */
diff --git a/fs/nilfs2/dat.c b/fs/nilfs2/dat.c
index 1ff8e15bd36b..239a42234999 100644
--- a/fs/nilfs2/dat.c
+++ b/fs/nilfs2/dat.c
@@ -425,3 +425,26 @@ ssize_t nilfs_dat_get_vinfo(struct inode *dat, void *buf, unsigned visz,
425 425
426 return nvi; 426 return nvi;
427} 427}
428
429/**
430 * nilfs_dat_new - create dat file
431 * @nilfs: nilfs object
432 * @entry_size: size of a dat entry
433 */
434struct inode *nilfs_dat_new(struct the_nilfs *nilfs, size_t entry_size)
435{
436 static struct lock_class_key dat_lock_key;
437 struct inode *dat;
438 int err;
439
440 dat = nilfs_mdt_new(nilfs, NULL, NILFS_DAT_INO, 0);
441 if (dat) {
442 err = nilfs_palloc_init_blockgroup(dat, entry_size);
443 if (unlikely(err)) {
444 nilfs_mdt_destroy(dat);
445 return NULL;
446 }
447 lockdep_set_class(&NILFS_MDT(dat)->mi_sem, &dat_lock_key);
448 }
449 return dat;
450}
diff --git a/fs/nilfs2/dat.h b/fs/nilfs2/dat.h
index 406070d3ff49..98f33067cb82 100644
--- a/fs/nilfs2/dat.h
+++ b/fs/nilfs2/dat.h
@@ -53,4 +53,6 @@ int nilfs_dat_freev(struct inode *, __u64 *, size_t);
53int nilfs_dat_move(struct inode *, __u64, sector_t); 53int nilfs_dat_move(struct inode *, __u64, sector_t);
54ssize_t nilfs_dat_get_vinfo(struct inode *, void *, unsigned, size_t); 54ssize_t nilfs_dat_get_vinfo(struct inode *, void *, unsigned, size_t);
55 55
56struct inode *nilfs_dat_new(struct the_nilfs *nilfs, size_t entry_size);
57
56#endif /* _NILFS_DAT_H */ 58#endif /* _NILFS_DAT_H */
diff --git a/fs/nilfs2/ifile.c b/fs/nilfs2/ifile.c
index de86401f209f..c1c1fd30c315 100644
--- a/fs/nilfs2/ifile.c
+++ b/fs/nilfs2/ifile.c
@@ -148,3 +148,24 @@ int nilfs_ifile_get_inode_block(struct inode *ifile, ino_t ino,
148 } 148 }
149 return err; 149 return err;
150} 150}
151
152/**
153 * nilfs_ifile_new - create inode file
154 * @sbi: nilfs_sb_info struct
155 * @inode_size: size of an inode
156 */
157struct inode *nilfs_ifile_new(struct nilfs_sb_info *sbi, size_t inode_size)
158{
159 struct inode *ifile;
160 int err;
161
162 ifile = nilfs_mdt_new(sbi->s_nilfs, sbi->s_super, NILFS_IFILE_INO, 0);
163 if (ifile) {
164 err = nilfs_palloc_init_blockgroup(ifile, inode_size);
165 if (unlikely(err)) {
166 nilfs_mdt_destroy(ifile);
167 return NULL;
168 }
169 }
170 return ifile;
171}
diff --git a/fs/nilfs2/ifile.h b/fs/nilfs2/ifile.h
index ecc3ba76db47..cbca32e498f2 100644
--- a/fs/nilfs2/ifile.h
+++ b/fs/nilfs2/ifile.h
@@ -49,4 +49,6 @@ int nilfs_ifile_create_inode(struct inode *, ino_t *, struct buffer_head **);
49int nilfs_ifile_delete_inode(struct inode *, ino_t); 49int nilfs_ifile_delete_inode(struct inode *, ino_t);
50int nilfs_ifile_get_inode_block(struct inode *, ino_t, struct buffer_head **); 50int nilfs_ifile_get_inode_block(struct inode *, ino_t, struct buffer_head **);
51 51
52struct inode *nilfs_ifile_new(struct nilfs_sb_info *sbi, size_t inode_size);
53
52#endif /* _NILFS_IFILE_H */ 54#endif /* _NILFS_IFILE_H */
diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c
index 37994d4a59cc..6fb707ab7e2c 100644
--- a/fs/nilfs2/sufile.c
+++ b/fs/nilfs2/sufile.c
@@ -657,3 +657,19 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, void *buf,
657 up_read(&NILFS_MDT(sufile)->mi_sem); 657 up_read(&NILFS_MDT(sufile)->mi_sem);
658 return ret; 658 return ret;
659} 659}
660
661/**
662 * nilfs_sufile_new - create sufile
663 * @nilfs: nilfs object
664 * @susize: size of a segment usage entry
665 */
666struct inode *nilfs_sufile_new(struct the_nilfs *nilfs, size_t susize)
667{
668 struct inode *sufile;
669
670 sufile = nilfs_mdt_new(nilfs, NULL, NILFS_SUFILE_INO, 0);
671 if (sufile)
672 nilfs_mdt_set_entry_size(sufile, susize,
673 sizeof(struct nilfs_sufile_header));
674 return sufile;
675}
diff --git a/fs/nilfs2/sufile.h b/fs/nilfs2/sufile.h
index 0e99e5c0bd0f..50d3191ae4fd 100644
--- a/fs/nilfs2/sufile.h
+++ b/fs/nilfs2/sufile.h
@@ -62,6 +62,8 @@ void nilfs_sufile_do_cancel_free(struct inode *, __u64, struct buffer_head *,
62void nilfs_sufile_do_set_error(struct inode *, __u64, struct buffer_head *, 62void nilfs_sufile_do_set_error(struct inode *, __u64, struct buffer_head *,
63 struct buffer_head *); 63 struct buffer_head *);
64 64
65struct inode *nilfs_sufile_new(struct the_nilfs *nilfs, size_t susize);
66
65/** 67/**
66 * nilfs_sufile_scrap - make a segment garbage 68 * nilfs_sufile_scrap - make a segment garbage
67 * @sufile: inode of segment usage file 69 * @sufile: inode of segment usage file
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 77f2e47ff81c..05ae52a482c6 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -363,14 +363,10 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno)
363 list_add(&sbi->s_list, &nilfs->ns_supers); 363 list_add(&sbi->s_list, &nilfs->ns_supers);
364 up_write(&nilfs->ns_super_sem); 364 up_write(&nilfs->ns_super_sem);
365 365
366 sbi->s_ifile = nilfs_mdt_new(nilfs, sbi->s_super, NILFS_IFILE_INO, 0); 366 sbi->s_ifile = nilfs_ifile_new(sbi, nilfs->ns_inode_size);
367 if (!sbi->s_ifile) 367 if (!sbi->s_ifile)
368 return -ENOMEM; 368 return -ENOMEM;
369 369
370 err = nilfs_palloc_init_blockgroup(sbi->s_ifile, nilfs->ns_inode_size);
371 if (unlikely(err))
372 goto failed;
373
374 down_read(&nilfs->ns_segctor_sem); 370 down_read(&nilfs->ns_segctor_sem);
375 err = nilfs_cpfile_get_checkpoint(nilfs->ns_cpfile, cno, 0, &raw_cp, 371 err = nilfs_cpfile_get_checkpoint(nilfs->ns_cpfile, cno, 0, &raw_cp,
376 &bh_cp); 372 &bh_cp);
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index a80bbb7c5afc..d4a731fd4e32 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -166,7 +166,6 @@ void put_nilfs(struct the_nilfs *nilfs)
166static int nilfs_load_super_root(struct the_nilfs *nilfs, 166static int nilfs_load_super_root(struct the_nilfs *nilfs,
167 struct nilfs_sb_info *sbi, sector_t sr_block) 167 struct nilfs_sb_info *sbi, sector_t sr_block)
168{ 168{
169 static struct lock_class_key dat_lock_key;
170 struct buffer_head *bh_sr; 169 struct buffer_head *bh_sr;
171 struct nilfs_super_root *raw_sr; 170 struct nilfs_super_root *raw_sr;
172 struct nilfs_super_block **sbp = nilfs->ns_sbp; 171 struct nilfs_super_block **sbp = nilfs->ns_sbp;
@@ -187,38 +186,23 @@ static int nilfs_load_super_root(struct the_nilfs *nilfs,
187 inode_size = nilfs->ns_inode_size; 186 inode_size = nilfs->ns_inode_size;
188 187
189 err = -ENOMEM; 188 err = -ENOMEM;
190 nilfs->ns_dat = nilfs_mdt_new(nilfs, NULL, NILFS_DAT_INO, 0); 189 nilfs->ns_dat = nilfs_dat_new(nilfs, dat_entry_size);
191 if (unlikely(!nilfs->ns_dat)) 190 if (unlikely(!nilfs->ns_dat))
192 goto failed; 191 goto failed;
193 192
194 nilfs->ns_gc_dat = nilfs_mdt_new(nilfs, NULL, NILFS_DAT_INO, 0); 193 nilfs->ns_gc_dat = nilfs_dat_new(nilfs, dat_entry_size);
195 if (unlikely(!nilfs->ns_gc_dat)) 194 if (unlikely(!nilfs->ns_gc_dat))
196 goto failed_dat; 195 goto failed_dat;
197 196
198 nilfs->ns_cpfile = nilfs_mdt_new(nilfs, NULL, NILFS_CPFILE_INO, 0); 197 nilfs->ns_cpfile = nilfs_cpfile_new(nilfs, checkpoint_size);
199 if (unlikely(!nilfs->ns_cpfile)) 198 if (unlikely(!nilfs->ns_cpfile))
200 goto failed_gc_dat; 199 goto failed_gc_dat;
201 200
202 nilfs->ns_sufile = nilfs_mdt_new(nilfs, NULL, NILFS_SUFILE_INO, 0); 201 nilfs->ns_sufile = nilfs_sufile_new(nilfs, segment_usage_size);
203 if (unlikely(!nilfs->ns_sufile)) 202 if (unlikely(!nilfs->ns_sufile))
204 goto failed_cpfile; 203 goto failed_cpfile;
205 204
206 err = nilfs_palloc_init_blockgroup(nilfs->ns_dat, dat_entry_size);
207 if (unlikely(err))
208 goto failed_sufile;
209
210 err = nilfs_palloc_init_blockgroup(nilfs->ns_gc_dat, dat_entry_size);
211 if (unlikely(err))
212 goto failed_sufile;
213
214 lockdep_set_class(&NILFS_MDT(nilfs->ns_dat)->mi_sem, &dat_lock_key);
215 lockdep_set_class(&NILFS_MDT(nilfs->ns_gc_dat)->mi_sem, &dat_lock_key);
216
217 nilfs_mdt_set_shadow(nilfs->ns_dat, nilfs->ns_gc_dat); 205 nilfs_mdt_set_shadow(nilfs->ns_dat, nilfs->ns_gc_dat);
218 nilfs_mdt_set_entry_size(nilfs->ns_cpfile, checkpoint_size,
219 sizeof(struct nilfs_cpfile_header));
220 nilfs_mdt_set_entry_size(nilfs->ns_sufile, segment_usage_size,
221 sizeof(struct nilfs_sufile_header));
222 206
223 err = nilfs_mdt_read_inode_direct( 207 err = nilfs_mdt_read_inode_direct(
224 nilfs->ns_dat, bh_sr, NILFS_SR_DAT_OFFSET(inode_size)); 208 nilfs->ns_dat, bh_sr, NILFS_SR_DAT_OFFSET(inode_size));