checkpoint.c (55d1cdb25a815ba92a917ae579c27cc3ffb9a57d) checkpoint.c (c227f912732f204c0ec4a577ba812401ac4672af)
1/*
2 * fs/f2fs/checkpoint.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

--- 708 unchanged lines hidden (view full) ---

717 f2fs_put_page(cp2, 1);
718 return 0;
719
720fail_no_cp:
721 kfree(sbi->ckpt);
722 return -EINVAL;
723}
724
1/*
2 * fs/f2fs/checkpoint.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

--- 708 unchanged lines hidden (view full) ---

717 f2fs_put_page(cp2, 1);
718 return 0;
719
720fail_no_cp:
721 kfree(sbi->ckpt);
722 return -EINVAL;
723}
724
725static void __add_dirty_inode(struct inode *inode)
725static void __add_dirty_inode(struct inode *inode, enum inode_type type)
726{
727 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
728 struct f2fs_inode_info *fi = F2FS_I(inode);
726{
727 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
728 struct f2fs_inode_info *fi = F2FS_I(inode);
729 int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE;
729
730
730 if (is_inode_flag_set(fi, FI_DIRTY_DIR))
731 if (is_inode_flag_set(fi, flag))
731 return;
732
732 return;
733
733 set_inode_flag(fi, FI_DIRTY_DIR);
734 list_add_tail(&fi->dirty_list, &sbi->dir_inode_list);
735 stat_inc_dirty_dir(sbi);
736 return;
734 set_inode_flag(fi, flag);
735 list_add_tail(&fi->dirty_list, &sbi->inode_list[type]);
736 if (type == DIR_INODE)
737 stat_inc_dirty_dir(sbi);
737}
738
738}
739
739static void __remove_dirty_inode(struct inode *inode)
740static void __remove_dirty_inode(struct inode *inode, enum inode_type type)
740{
741 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
742 struct f2fs_inode_info *fi = F2FS_I(inode);
741{
742 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
743 struct f2fs_inode_info *fi = F2FS_I(inode);
744 int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE;
743
744 if (get_dirty_pages(inode) ||
745
746 if (get_dirty_pages(inode) ||
745 !is_inode_flag_set(F2FS_I(inode), FI_DIRTY_DIR))
747 !is_inode_flag_set(F2FS_I(inode), flag))
746 return;
747
748 list_del_init(&fi->dirty_list);
748 return;
749
750 list_del_init(&fi->dirty_list);
749 clear_inode_flag(fi, FI_DIRTY_DIR);
750 stat_dec_dirty_dir(sbi);
751 clear_inode_flag(fi, flag);
752 if (type == DIR_INODE)
753 stat_dec_dirty_dir(sbi);
751}
752
753void update_dirty_page(struct inode *inode, struct page *page)
754{
755 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
754}
755
756void update_dirty_page(struct inode *inode, struct page *page)
757{
758 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
759 enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE;
756
757 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
758 !S_ISLNK(inode->i_mode))
759 return;
760
760
761 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
762 !S_ISLNK(inode->i_mode))
763 return;
764
761 if (!S_ISDIR(inode->i_mode)) {
762 inode_inc_dirty_pages(inode);
763 goto out;
764 }
765
766 spin_lock(&sbi->dir_inode_lock);
767 __add_dirty_inode(inode);
765 spin_lock(&sbi->inode_lock[type]);
766 __add_dirty_inode(inode, type);
768 inode_inc_dirty_pages(inode);
767 inode_inc_dirty_pages(inode);
769 spin_unlock(&sbi->dir_inode_lock);
768 spin_unlock(&sbi->inode_lock[type]);
770
769
771out:
772 SetPagePrivate(page);
773 f2fs_trace_pid(page);
774}
775
776void add_dirty_dir_inode(struct inode *inode)
777{
778 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
779
770 SetPagePrivate(page);
771 f2fs_trace_pid(page);
772}
773
774void add_dirty_dir_inode(struct inode *inode)
775{
776 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
777
780 spin_lock(&sbi->dir_inode_lock);
781 __add_dirty_inode(inode);
782 spin_unlock(&sbi->dir_inode_lock);
778 spin_lock(&sbi->inode_lock[DIR_INODE]);
779 __add_dirty_inode(inode, DIR_INODE);
780 spin_unlock(&sbi->inode_lock[DIR_INODE]);
783}
784
781}
782
785void remove_dirty_dir_inode(struct inode *inode)
783void remove_dirty_inode(struct inode *inode)
786{
787 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
788 struct f2fs_inode_info *fi = F2FS_I(inode);
784{
785 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
786 struct f2fs_inode_info *fi = F2FS_I(inode);
787 enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE;
789
788
790 if (!S_ISDIR(inode->i_mode))
789 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
790 !S_ISLNK(inode->i_mode))
791 return;
792
791 return;
792
793 spin_lock(&sbi->dir_inode_lock);
794 __remove_dirty_inode(inode);
795 spin_unlock(&sbi->dir_inode_lock);
793 spin_lock(&sbi->inode_lock[type]);
794 __remove_dirty_inode(inode, type);
795 spin_unlock(&sbi->inode_lock[type]);
796
797 /* Only from the recovery routine */
798 if (is_inode_flag_set(fi, FI_DELAY_IPUT)) {
799 clear_inode_flag(fi, FI_DELAY_IPUT);
800 iput(inode);
801 }
802}
803
796
797 /* Only from the recovery routine */
798 if (is_inode_flag_set(fi, FI_DELAY_IPUT)) {
799 clear_inode_flag(fi, FI_DELAY_IPUT);
800 iput(inode);
801 }
802}
803
804void sync_dirty_dir_inodes(struct f2fs_sb_info *sbi)
804void sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type)
805{
806 struct list_head *head;
807 struct inode *inode;
808 struct f2fs_inode_info *fi;
809retry:
810 if (unlikely(f2fs_cp_error(sbi)))
811 return;
812
805{
806 struct list_head *head;
807 struct inode *inode;
808 struct f2fs_inode_info *fi;
809retry:
810 if (unlikely(f2fs_cp_error(sbi)))
811 return;
812
813 spin_lock(&sbi->dir_inode_lock);
813 spin_lock(&sbi->inode_lock[type]);
814
814
815 head = &sbi->dir_inode_list;
815 head = &sbi->inode_list[type];
816 if (list_empty(head)) {
816 if (list_empty(head)) {
817 spin_unlock(&sbi->dir_inode_lock);
817 spin_unlock(&sbi->inode_lock[type]);
818 return;
819 }
820 fi = list_entry(head->next, struct f2fs_inode_info, dirty_list);
821 inode = igrab(&fi->vfs_inode);
818 return;
819 }
820 fi = list_entry(head->next, struct f2fs_inode_info, dirty_list);
821 inode = igrab(&fi->vfs_inode);
822 spin_unlock(&sbi->dir_inode_lock);
822 spin_unlock(&sbi->inode_lock[type]);
823 if (inode) {
824 filemap_fdatawrite(inode->i_mapping);
825 iput(inode);
826 } else {
827 /*
828 * We should submit bio, since it exists several
829 * wribacking dentry pages in the freeing inode.
830 */

--- 18 unchanged lines hidden (view full) ---

849
850 blk_start_plug(&plug);
851
852retry_flush_dents:
853 f2fs_lock_all(sbi);
854 /* write all the dirty dentry pages */
855 if (get_pages(sbi, F2FS_DIRTY_DENTS)) {
856 f2fs_unlock_all(sbi);
823 if (inode) {
824 filemap_fdatawrite(inode->i_mapping);
825 iput(inode);
826 } else {
827 /*
828 * We should submit bio, since it exists several
829 * wribacking dentry pages in the freeing inode.
830 */

--- 18 unchanged lines hidden (view full) ---

849
850 blk_start_plug(&plug);
851
852retry_flush_dents:
853 f2fs_lock_all(sbi);
854 /* write all the dirty dentry pages */
855 if (get_pages(sbi, F2FS_DIRTY_DENTS)) {
856 f2fs_unlock_all(sbi);
857 sync_dirty_dir_inodes(sbi);
857 sync_dirty_inodes(sbi, DIR_INODE);
858 if (unlikely(f2fs_cp_error(sbi))) {
859 err = -EIO;
860 goto out;
861 }
862 goto retry_flush_dents;
863 }
864
865 /*

--- 310 unchanged lines hidden ---
858 if (unlikely(f2fs_cp_error(sbi))) {
859 err = -EIO;
860 goto out;
861 }
862 goto retry_flush_dents;
863 }
864
865 /*

--- 310 unchanged lines hidden ---