Commit 79739565e15f2adbc482207a0800fc127c84d1a0

Authored by Ryusuke Konishi
1 parent 5731e191f2

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>

Showing 10 changed files with 89 additions and 25 deletions Side-by-side Diff

... ... @@ -926,4 +926,20 @@
926 926 up_read(&NILFS_MDT(cpfile)->mi_sem);
927 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 + */
  935 +struct 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 +}
... ... @@ -40,5 +40,7 @@
40 40 ssize_t nilfs_cpfile_get_cpinfo(struct inode *, __u64 *, int, void *, unsigned,
41 41 size_t);
42 42  
  43 +struct inode *nilfs_cpfile_new(struct the_nilfs *nilfs, size_t cpsize);
  44 +
43 45 #endif /* _NILFS_CPFILE_H */
... ... @@ -425,4 +425,27 @@
425 425  
426 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 + */
  434 +struct 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 +}
... ... @@ -53,5 +53,7 @@
53 53 int nilfs_dat_move(struct inode *, __u64, sector_t);
54 54 ssize_t nilfs_dat_get_vinfo(struct inode *, void *, unsigned, size_t);
55 55  
  56 +struct inode *nilfs_dat_new(struct the_nilfs *nilfs, size_t entry_size);
  57 +
56 58 #endif /* _NILFS_DAT_H */
... ... @@ -148,4 +148,25 @@
148 148 }
149 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 + */
  157 +struct 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 +}
... ... @@ -49,5 +49,7 @@
49 49 int nilfs_ifile_delete_inode(struct inode *, ino_t);
50 50 int nilfs_ifile_get_inode_block(struct inode *, ino_t, struct buffer_head **);
51 51  
  52 +struct inode *nilfs_ifile_new(struct nilfs_sb_info *sbi, size_t inode_size);
  53 +
52 54 #endif /* _NILFS_IFILE_H */
... ... @@ -657,4 +657,20 @@
657 657 up_read(&NILFS_MDT(sufile)->mi_sem);
658 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 + */
  666 +struct 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 +}
... ... @@ -62,6 +62,8 @@
62 62 void nilfs_sufile_do_set_error(struct inode *, __u64, struct buffer_head *,
63 63 struct buffer_head *);
64 64  
  65 +struct inode *nilfs_sufile_new(struct the_nilfs *nilfs, size_t susize);
  66 +
65 67 /**
66 68 * nilfs_sufile_scrap - make a segment garbage
67 69 * @sufile: inode of segment usage file
... ... @@ -363,13 +363,9 @@
363 363 list_add(&sbi->s_list, &nilfs->ns_supers);
364 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 367 if (!sbi->s_ifile)
368 368 return -ENOMEM;
369   -
370   - err = nilfs_palloc_init_blockgroup(sbi->s_ifile, nilfs->ns_inode_size);
371   - if (unlikely(err))
372   - goto failed;
373 369  
374 370 down_read(&nilfs->ns_segctor_sem);
375 371 err = nilfs_cpfile_get_checkpoint(nilfs->ns_cpfile, cno, 0, &raw_cp,
fs/nilfs2/the_nilfs.c
... ... @@ -166,7 +166,6 @@
166 166 static int nilfs_load_super_root(struct the_nilfs *nilfs,
167 167 struct nilfs_sb_info *sbi, sector_t sr_block)
168 168 {
169   - static struct lock_class_key dat_lock_key;
170 169 struct buffer_head *bh_sr;
171 170 struct nilfs_super_root *raw_sr;
172 171 struct nilfs_super_block **sbp = nilfs->ns_sbp;
173 172  
174 173  
175 174  
176 175  
177 176  
... ... @@ -187,38 +186,23 @@
187 186 inode_size = nilfs->ns_inode_size;
188 187  
189 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 190 if (unlikely(!nilfs->ns_dat))
192 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 194 if (unlikely(!nilfs->ns_gc_dat))
196 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 198 if (unlikely(!nilfs->ns_cpfile))
200 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 202 if (unlikely(!nilfs->ns_sufile))
204 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 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 207 err = nilfs_mdt_read_inode_direct(
224 208 nilfs->ns_dat, bh_sr, NILFS_SR_DAT_OFFSET(inode_size));