diff options
Diffstat (limited to 'fs/nilfs2/sufile.c')
-rw-r--r-- | fs/nilfs2/sufile.c | 77 |
1 files changed, 43 insertions, 34 deletions
diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c index 3c6cc6005c2e..1d6f488ccae8 100644 --- a/fs/nilfs2/sufile.c +++ b/fs/nilfs2/sufile.c | |||
@@ -505,7 +505,7 @@ int nilfs_sufile_get_stat(struct inode *sufile, struct nilfs_sustat *sustat) | |||
505 | { | 505 | { |
506 | struct buffer_head *header_bh; | 506 | struct buffer_head *header_bh; |
507 | struct nilfs_sufile_header *header; | 507 | struct nilfs_sufile_header *header; |
508 | struct the_nilfs *nilfs = NILFS_MDT(sufile)->mi_nilfs; | 508 | struct the_nilfs *nilfs = NILFS_I_NILFS(sufile); |
509 | void *kaddr; | 509 | void *kaddr; |
510 | int ret; | 510 | int ret; |
511 | 511 | ||
@@ -583,7 +583,7 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, void *buf, | |||
583 | struct nilfs_segment_usage *su; | 583 | struct nilfs_segment_usage *su; |
584 | struct nilfs_suinfo *si = buf; | 584 | struct nilfs_suinfo *si = buf; |
585 | size_t susz = NILFS_MDT(sufile)->mi_entry_size; | 585 | size_t susz = NILFS_MDT(sufile)->mi_entry_size; |
586 | struct the_nilfs *nilfs = NILFS_MDT(sufile)->mi_nilfs; | 586 | struct the_nilfs *nilfs = NILFS_I_NILFS(sufile); |
587 | void *kaddr; | 587 | void *kaddr; |
588 | unsigned long nsegs, segusages_per_block; | 588 | unsigned long nsegs, segusages_per_block; |
589 | ssize_t n; | 589 | ssize_t n; |
@@ -635,46 +635,55 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, void *buf, | |||
635 | } | 635 | } |
636 | 636 | ||
637 | /** | 637 | /** |
638 | * nilfs_sufile_read - read sufile inode | 638 | * nilfs_sufile_read - read or get sufile inode |
639 | * @sufile: sufile inode | 639 | * @sb: super block instance |
640 | * @susize: size of a segment usage entry | ||
640 | * @raw_inode: on-disk sufile inode | 641 | * @raw_inode: on-disk sufile inode |
642 | * @inodep: buffer to store the inode | ||
641 | */ | 643 | */ |
642 | int nilfs_sufile_read(struct inode *sufile, struct nilfs_inode *raw_inode) | 644 | int nilfs_sufile_read(struct super_block *sb, size_t susize, |
645 | struct nilfs_inode *raw_inode, struct inode **inodep) | ||
643 | { | 646 | { |
644 | struct nilfs_sufile_info *sui = NILFS_SUI(sufile); | 647 | struct inode *sufile; |
648 | struct nilfs_sufile_info *sui; | ||
645 | struct buffer_head *header_bh; | 649 | struct buffer_head *header_bh; |
646 | struct nilfs_sufile_header *header; | 650 | struct nilfs_sufile_header *header; |
647 | void *kaddr; | 651 | void *kaddr; |
648 | int ret; | 652 | int err; |
649 | 653 | ||
650 | ret = nilfs_read_inode_common(sufile, raw_inode); | 654 | sufile = nilfs_iget_locked(sb, NULL, NILFS_SUFILE_INO); |
651 | if (ret < 0) | 655 | if (unlikely(!sufile)) |
652 | return ret; | 656 | return -ENOMEM; |
657 | if (!(sufile->i_state & I_NEW)) | ||
658 | goto out; | ||
653 | 659 | ||
654 | ret = nilfs_sufile_get_header_block(sufile, &header_bh); | 660 | err = nilfs_mdt_init(sufile, NILFS_MDT_GFP, sizeof(*sui)); |
655 | if (!ret) { | 661 | if (err) |
656 | kaddr = kmap_atomic(header_bh->b_page, KM_USER0); | 662 | goto failed; |
657 | header = kaddr + bh_offset(header_bh); | ||
658 | sui->ncleansegs = le64_to_cpu(header->sh_ncleansegs); | ||
659 | kunmap_atomic(kaddr, KM_USER0); | ||
660 | brelse(header_bh); | ||
661 | } | ||
662 | return ret; | ||
663 | } | ||
664 | 663 | ||
665 | /** | 664 | nilfs_mdt_set_entry_size(sufile, susize, |
666 | * nilfs_sufile_new - create sufile | 665 | sizeof(struct nilfs_sufile_header)); |
667 | * @nilfs: nilfs object | 666 | |
668 | * @susize: size of a segment usage entry | 667 | err = nilfs_read_inode_common(sufile, raw_inode); |
669 | */ | 668 | if (err) |
670 | struct inode *nilfs_sufile_new(struct the_nilfs *nilfs, size_t susize) | 669 | goto failed; |
671 | { | 670 | |
672 | struct inode *sufile; | 671 | err = nilfs_sufile_get_header_block(sufile, &header_bh); |
672 | if (err) | ||
673 | goto failed; | ||
673 | 674 | ||
674 | sufile = nilfs_mdt_new(nilfs, NULL, NILFS_SUFILE_INO, | 675 | sui = NILFS_SUI(sufile); |
675 | sizeof(struct nilfs_sufile_info)); | 676 | kaddr = kmap_atomic(header_bh->b_page, KM_USER0); |
676 | if (sufile) | 677 | header = kaddr + bh_offset(header_bh); |
677 | nilfs_mdt_set_entry_size(sufile, susize, | 678 | sui->ncleansegs = le64_to_cpu(header->sh_ncleansegs); |
678 | sizeof(struct nilfs_sufile_header)); | 679 | kunmap_atomic(kaddr, KM_USER0); |
679 | return sufile; | 680 | brelse(header_bh); |
681 | |||
682 | unlock_new_inode(sufile); | ||
683 | out: | ||
684 | *inodep = sufile; | ||
685 | return 0; | ||
686 | failed: | ||
687 | iget_failed(sufile); | ||
688 | return err; | ||
680 | } | 689 | } |