diff options
author | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2010-08-21 09:01:51 -0400 |
---|---|---|
committer | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2010-10-22 20:24:34 -0400 |
commit | 5e19a995f4ad8a8f20749a396bb01ebb6d4df96c (patch) | |
tree | a6012a5f553a29d02101c81595a368c4eb90b101 /fs/nilfs2/mdt.c | |
parent | 0e14a3595bddedfb27b51a6b0a29b5173aa2511a (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/nilfs2/mdt.c')
-rw-r--r-- | fs/nilfs2/mdt.c | 44 |
1 files changed, 27 insertions, 17 deletions
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 = { | |||
439 | static const struct inode_operations def_mdt_iops; | 439 | static const struct inode_operations def_mdt_iops; |
440 | static const struct file_operations def_mdt_fops; | 440 | static const struct file_operations def_mdt_fops; |
441 | 441 | ||
442 | |||
443 | int 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 | */ |
460 | struct inode * | 479 | struct inode * |
461 | nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb, | 480 | nilfs_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; |