aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-08-21 09:01:51 -0400
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-10-22 20:24:34 -0400
commit5e19a995f4ad8a8f20749a396bb01ebb6d4df96c (patch)
treea6012a5f553a29d02101c81595a368c4eb90b101 /fs
parent0e14a3595bddedfb27b51a6b0a29b5173aa2511a (diff)
nilfs2: separate initializer of metadata file inode
This separates a part of initialization code of metadata file inode, and makes it available from the nilfs iget function that a later patch will add to. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Diffstat (limited to 'fs')
-rw-r--r--fs/nilfs2/gcinode.c6
-rw-r--r--fs/nilfs2/mdt.c44
-rw-r--r--fs/nilfs2/mdt.h4
3 files changed, 35 insertions, 19 deletions
diff --git a/fs/nilfs2/gcinode.c b/fs/nilfs2/gcinode.c
index bed3a783129b..cd19a3709bda 100644
--- a/fs/nilfs2/gcinode.c
+++ b/fs/nilfs2/gcinode.c
@@ -225,10 +225,14 @@ static struct inode *alloc_gcinode(struct the_nilfs *nilfs, ino_t ino,
225 struct inode *inode; 225 struct inode *inode;
226 struct nilfs_inode_info *ii; 226 struct nilfs_inode_info *ii;
227 227
228 inode = nilfs_mdt_new_common(nilfs, NULL, ino, GFP_NOFS, 0); 228 inode = nilfs_mdt_new_common(nilfs, NULL, ino);
229 if (!inode) 229 if (!inode)
230 return NULL; 230 return NULL;
231 231
232 if (nilfs_mdt_init(inode, nilfs, GFP_NOFS, 0) < 0) {
233 nilfs_destroy_inode(inode);
234 return NULL;
235 }
232 inode->i_op = NULL; 236 inode->i_op = NULL;
233 inode->i_fop = NULL; 237 inode->i_fop = NULL;
234 inode->i_mapping->a_ops = &def_gcinode_aops; 238 inode->i_mapping->a_ops = &def_gcinode_aops;
diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c
index ee943a342e1d..73e5da3b097e 100644
--- a/fs/nilfs2/mdt.c
+++ b/fs/nilfs2/mdt.c
@@ -439,6 +439,27 @@ static const struct address_space_operations def_mdt_aops = {
439static const struct inode_operations def_mdt_iops; 439static const struct inode_operations def_mdt_iops;
440static const struct file_operations def_mdt_fops; 440static const struct file_operations def_mdt_fops;
441 441
442
443int nilfs_mdt_init(struct inode *inode, struct the_nilfs *nilfs,
444 gfp_t gfp_mask, size_t objsz)
445{
446 struct nilfs_mdt_info *mi;
447
448 mi = kzalloc(max(sizeof(*mi), objsz), GFP_NOFS);
449 if (!mi)
450 return -ENOMEM;
451
452 mi->mi_nilfs = nilfs;
453 init_rwsem(&mi->mi_sem);
454 inode->i_private = mi;
455
456 inode->i_mode = S_IFREG;
457 mapping_set_gfp_mask(inode->i_mapping, gfp_mask);
458 inode->i_mapping->backing_dev_info = nilfs->ns_bdi;
459
460 return 0;
461}
462
442/* 463/*
443 * NILFS2 uses pseudo inodes for meta data files such as DAT, cpfile, sufile, 464 * NILFS2 uses pseudo inodes for meta data files such as DAT, cpfile, sufile,
444 * ifile, or gcinodes. This allows the B-tree code and segment constructor 465 * ifile, or gcinodes. This allows the B-tree code and segment constructor
@@ -454,12 +475,10 @@ static const struct file_operations def_mdt_fops;
454 * @nilfs: nilfs object 475 * @nilfs: nilfs object
455 * @sb: super block instance the metadata file belongs to 476 * @sb: super block instance the metadata file belongs to
456 * @ino: inode number 477 * @ino: inode number
457 * @gfp_mask: gfp mask for data pages
458 * @objsz: size of the private object attached to inode->i_private
459 */ 478 */
460struct inode * 479struct inode *
461nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb, 480nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb,
462 ino_t ino, gfp_t gfp_mask, size_t objsz) 481 ino_t ino)
463{ 482{
464 struct inode *inode = nilfs_alloc_inode_common(nilfs); 483 struct inode *inode = nilfs_alloc_inode_common(nilfs);
465 484
@@ -467,15 +486,6 @@ nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb,
467 return NULL; 486 return NULL;
468 else { 487 else {
469 struct address_space * const mapping = &inode->i_data; 488 struct address_space * const mapping = &inode->i_data;
470 struct nilfs_mdt_info *mi;
471
472 mi = kzalloc(max(sizeof(*mi), objsz), GFP_NOFS);
473 if (!mi) {
474 nilfs_destroy_inode(inode);
475 return NULL;
476 }
477 mi->mi_nilfs = nilfs;
478 init_rwsem(&mi->mi_sem);
479 489
480 inode->i_sb = sb; /* sb may be NULL for some meta data files */ 490 inode->i_sb = sb; /* sb may be NULL for some meta data files */
481 inode->i_blkbits = nilfs->ns_blocksize_bits; 491 inode->i_blkbits = nilfs->ns_blocksize_bits;
@@ -483,8 +493,6 @@ nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb,
483 atomic_set(&inode->i_count, 1); 493 atomic_set(&inode->i_count, 1);
484 inode->i_nlink = 1; 494 inode->i_nlink = 1;
485 inode->i_ino = ino; 495 inode->i_ino = ino;
486 inode->i_mode = S_IFREG;
487 inode->i_private = mi;
488 496
489#ifdef INIT_UNUSED_INODE_FIELDS 497#ifdef INIT_UNUSED_INODE_FIELDS
490 atomic_set(&inode->i_writecount, 0); 498 atomic_set(&inode->i_writecount, 0);
@@ -515,9 +523,7 @@ nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb,
515 523
516 mapping->host = NULL; /* instead of inode */ 524 mapping->host = NULL; /* instead of inode */
517 mapping->flags = 0; 525 mapping->flags = 0;
518 mapping_set_gfp_mask(mapping, gfp_mask);
519 mapping->assoc_mapping = NULL; 526 mapping->assoc_mapping = NULL;
520 mapping->backing_dev_info = nilfs->ns_bdi;
521 527
522 inode->i_mapping = mapping; 528 inode->i_mapping = mapping;
523 } 529 }
@@ -530,10 +536,14 @@ struct inode *nilfs_mdt_new(struct the_nilfs *nilfs, struct super_block *sb,
530{ 536{
531 struct inode *inode; 537 struct inode *inode;
532 538
533 inode = nilfs_mdt_new_common(nilfs, sb, ino, NILFS_MDT_GFP, objsz); 539 inode = nilfs_mdt_new_common(nilfs, sb, ino);
534 if (!inode) 540 if (!inode)
535 return NULL; 541 return NULL;
536 542
543 if (nilfs_mdt_init(inode, nilfs, NILFS_MDT_GFP, objsz) < 0) {
544 nilfs_destroy_inode(inode);
545 return NULL;
546 }
537 inode->i_op = &def_mdt_iops; 547 inode->i_op = &def_mdt_iops;
538 inode->i_fop = &def_mdt_fops; 548 inode->i_fop = &def_mdt_fops;
539 inode->i_mapping->a_ops = &def_mdt_aops; 549 inode->i_mapping->a_ops = &def_mdt_aops;
diff --git a/fs/nilfs2/mdt.h b/fs/nilfs2/mdt.h
index 6c4bbb0470fc..f44560224bd1 100644
--- a/fs/nilfs2/mdt.h
+++ b/fs/nilfs2/mdt.h
@@ -76,10 +76,12 @@ int nilfs_mdt_forget_block(struct inode *, unsigned long);
76int nilfs_mdt_mark_block_dirty(struct inode *, unsigned long); 76int nilfs_mdt_mark_block_dirty(struct inode *, unsigned long);
77int nilfs_mdt_fetch_dirty(struct inode *); 77int nilfs_mdt_fetch_dirty(struct inode *);
78 78
79int nilfs_mdt_init(struct inode *inode, struct the_nilfs *nilfs,
80 gfp_t gfp_mask, size_t objsz);
79struct inode *nilfs_mdt_new(struct the_nilfs *, struct super_block *, ino_t, 81struct inode *nilfs_mdt_new(struct the_nilfs *, struct super_block *, ino_t,
80 size_t); 82 size_t);
81struct inode *nilfs_mdt_new_common(struct the_nilfs *, struct super_block *, 83struct inode *nilfs_mdt_new_common(struct the_nilfs *, struct super_block *,
82 ino_t, gfp_t, size_t); 84 ino_t);
83void nilfs_mdt_destroy(struct inode *); 85void nilfs_mdt_destroy(struct inode *);
84void nilfs_mdt_set_entry_size(struct inode *, unsigned, unsigned); 86void nilfs_mdt_set_entry_size(struct inode *, unsigned, unsigned);
85void nilfs_mdt_set_shadow(struct inode *, struct inode *); 87void nilfs_mdt_set_shadow(struct inode *, struct inode *);