diff options
Diffstat (limited to 'fs/nilfs2/segment.c')
-rw-r--r-- | fs/nilfs2/segment.c | 123 |
1 files changed, 68 insertions, 55 deletions
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index c9201649cc49..687d090cea34 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c | |||
@@ -191,6 +191,8 @@ int nilfs_transaction_begin(struct super_block *sb, | |||
191 | if (ret > 0) | 191 | if (ret > 0) |
192 | return 0; | 192 | return 0; |
193 | 193 | ||
194 | vfs_check_frozen(sb, SB_FREEZE_WRITE); | ||
195 | |||
194 | sbi = NILFS_SB(sb); | 196 | sbi = NILFS_SB(sb); |
195 | nilfs = sbi->s_nilfs; | 197 | nilfs = sbi->s_nilfs; |
196 | down_read(&nilfs->ns_segctor_sem); | 198 | down_read(&nilfs->ns_segctor_sem); |
@@ -366,8 +368,7 @@ static int nilfs_segctor_reset_segment_buffer(struct nilfs_sc_info *sci) | |||
366 | 368 | ||
367 | if (nilfs_doing_gc()) | 369 | if (nilfs_doing_gc()) |
368 | flags = NILFS_SS_GC; | 370 | flags = NILFS_SS_GC; |
369 | err = nilfs_segbuf_reset(segbuf, flags, sci->sc_seg_ctime, | 371 | err = nilfs_segbuf_reset(segbuf, flags, sci->sc_seg_ctime, sci->sc_cno); |
370 | sci->sc_sbi->s_nilfs->ns_cno); | ||
371 | if (unlikely(err)) | 372 | if (unlikely(err)) |
372 | return err; | 373 | return err; |
373 | 374 | ||
@@ -440,17 +441,26 @@ static void nilfs_segctor_end_finfo(struct nilfs_sc_info *sci, | |||
440 | struct nilfs_finfo *finfo; | 441 | struct nilfs_finfo *finfo; |
441 | struct nilfs_inode_info *ii; | 442 | struct nilfs_inode_info *ii; |
442 | struct nilfs_segment_buffer *segbuf; | 443 | struct nilfs_segment_buffer *segbuf; |
444 | __u64 cno; | ||
443 | 445 | ||
444 | if (sci->sc_blk_cnt == 0) | 446 | if (sci->sc_blk_cnt == 0) |
445 | return; | 447 | return; |
446 | 448 | ||
447 | ii = NILFS_I(inode); | 449 | ii = NILFS_I(inode); |
450 | |||
451 | if (test_bit(NILFS_I_GCINODE, &ii->i_state)) | ||
452 | cno = ii->i_cno; | ||
453 | else if (NILFS_ROOT_METADATA_FILE(inode->i_ino)) | ||
454 | cno = 0; | ||
455 | else | ||
456 | cno = sci->sc_cno; | ||
457 | |||
448 | finfo = nilfs_segctor_map_segsum_entry(sci, &sci->sc_finfo_ptr, | 458 | finfo = nilfs_segctor_map_segsum_entry(sci, &sci->sc_finfo_ptr, |
449 | sizeof(*finfo)); | 459 | sizeof(*finfo)); |
450 | finfo->fi_ino = cpu_to_le64(inode->i_ino); | 460 | finfo->fi_ino = cpu_to_le64(inode->i_ino); |
451 | finfo->fi_nblocks = cpu_to_le32(sci->sc_blk_cnt); | 461 | finfo->fi_nblocks = cpu_to_le32(sci->sc_blk_cnt); |
452 | finfo->fi_ndatablk = cpu_to_le32(sci->sc_datablk_cnt); | 462 | finfo->fi_ndatablk = cpu_to_le32(sci->sc_datablk_cnt); |
453 | finfo->fi_cno = cpu_to_le64(ii->i_cno); | 463 | finfo->fi_cno = cpu_to_le64(cno); |
454 | 464 | ||
455 | segbuf = sci->sc_curseg; | 465 | segbuf = sci->sc_curseg; |
456 | segbuf->sb_sum.sumbytes = sci->sc_binfo_ptr.offset + | 466 | segbuf->sb_sum.sumbytes = sci->sc_binfo_ptr.offset + |
@@ -755,12 +765,12 @@ static void nilfs_dispose_list(struct nilfs_sb_info *sbi, | |||
755 | } | 765 | } |
756 | } | 766 | } |
757 | 767 | ||
758 | static int nilfs_test_metadata_dirty(struct nilfs_sb_info *sbi) | 768 | static int nilfs_test_metadata_dirty(struct the_nilfs *nilfs, |
769 | struct nilfs_root *root) | ||
759 | { | 770 | { |
760 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
761 | int ret = 0; | 771 | int ret = 0; |
762 | 772 | ||
763 | if (nilfs_mdt_fetch_dirty(sbi->s_ifile)) | 773 | if (nilfs_mdt_fetch_dirty(root->ifile)) |
764 | ret++; | 774 | ret++; |
765 | if (nilfs_mdt_fetch_dirty(nilfs->ns_cpfile)) | 775 | if (nilfs_mdt_fetch_dirty(nilfs->ns_cpfile)) |
766 | ret++; | 776 | ret++; |
@@ -785,7 +795,7 @@ static int nilfs_segctor_confirm(struct nilfs_sc_info *sci) | |||
785 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 795 | struct nilfs_sb_info *sbi = sci->sc_sbi; |
786 | int ret = 0; | 796 | int ret = 0; |
787 | 797 | ||
788 | if (nilfs_test_metadata_dirty(sbi)) | 798 | if (nilfs_test_metadata_dirty(sbi->s_nilfs, sci->sc_root)) |
789 | set_bit(NILFS_SC_DIRTY, &sci->sc_flags); | 799 | set_bit(NILFS_SC_DIRTY, &sci->sc_flags); |
790 | 800 | ||
791 | spin_lock(&sbi->s_inode_lock); | 801 | spin_lock(&sbi->s_inode_lock); |
@@ -801,7 +811,7 @@ static void nilfs_segctor_clear_metadata_dirty(struct nilfs_sc_info *sci) | |||
801 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 811 | struct nilfs_sb_info *sbi = sci->sc_sbi; |
802 | struct the_nilfs *nilfs = sbi->s_nilfs; | 812 | struct the_nilfs *nilfs = sbi->s_nilfs; |
803 | 813 | ||
804 | nilfs_mdt_clear_dirty(sbi->s_ifile); | 814 | nilfs_mdt_clear_dirty(sci->sc_root->ifile); |
805 | nilfs_mdt_clear_dirty(nilfs->ns_cpfile); | 815 | nilfs_mdt_clear_dirty(nilfs->ns_cpfile); |
806 | nilfs_mdt_clear_dirty(nilfs->ns_sufile); | 816 | nilfs_mdt_clear_dirty(nilfs->ns_sufile); |
807 | nilfs_mdt_clear_dirty(nilfs_dat_inode(nilfs)); | 817 | nilfs_mdt_clear_dirty(nilfs_dat_inode(nilfs)); |
@@ -848,9 +858,9 @@ static int nilfs_segctor_fill_in_checkpoint(struct nilfs_sc_info *sci) | |||
848 | raw_cp->cp_snapshot_list.ssl_next = 0; | 858 | raw_cp->cp_snapshot_list.ssl_next = 0; |
849 | raw_cp->cp_snapshot_list.ssl_prev = 0; | 859 | raw_cp->cp_snapshot_list.ssl_prev = 0; |
850 | raw_cp->cp_inodes_count = | 860 | raw_cp->cp_inodes_count = |
851 | cpu_to_le64(atomic_read(&sbi->s_inodes_count)); | 861 | cpu_to_le64(atomic_read(&sci->sc_root->inodes_count)); |
852 | raw_cp->cp_blocks_count = | 862 | raw_cp->cp_blocks_count = |
853 | cpu_to_le64(atomic_read(&sbi->s_blocks_count)); | 863 | cpu_to_le64(atomic_read(&sci->sc_root->blocks_count)); |
854 | raw_cp->cp_nblk_inc = | 864 | raw_cp->cp_nblk_inc = |
855 | cpu_to_le64(sci->sc_nblk_inc + sci->sc_nblk_this_inc); | 865 | cpu_to_le64(sci->sc_nblk_inc + sci->sc_nblk_this_inc); |
856 | raw_cp->cp_create = cpu_to_le64(sci->sc_seg_ctime); | 866 | raw_cp->cp_create = cpu_to_le64(sci->sc_seg_ctime); |
@@ -861,7 +871,8 @@ static int nilfs_segctor_fill_in_checkpoint(struct nilfs_sc_info *sci) | |||
861 | else | 871 | else |
862 | nilfs_checkpoint_set_minor(raw_cp); | 872 | nilfs_checkpoint_set_minor(raw_cp); |
863 | 873 | ||
864 | nilfs_write_inode_common(sbi->s_ifile, &raw_cp->cp_ifile_inode, 1); | 874 | nilfs_write_inode_common(sci->sc_root->ifile, |
875 | &raw_cp->cp_ifile_inode, 1); | ||
865 | nilfs_cpfile_put_checkpoint(nilfs->ns_cpfile, nilfs->ns_cno, bh_cp); | 876 | nilfs_cpfile_put_checkpoint(nilfs->ns_cpfile, nilfs->ns_cno, bh_cp); |
866 | return 0; | 877 | return 0; |
867 | 878 | ||
@@ -886,13 +897,12 @@ static void nilfs_fill_in_file_bmap(struct inode *ifile, | |||
886 | } | 897 | } |
887 | } | 898 | } |
888 | 899 | ||
889 | static void nilfs_segctor_fill_in_file_bmap(struct nilfs_sc_info *sci, | 900 | static void nilfs_segctor_fill_in_file_bmap(struct nilfs_sc_info *sci) |
890 | struct inode *ifile) | ||
891 | { | 901 | { |
892 | struct nilfs_inode_info *ii; | 902 | struct nilfs_inode_info *ii; |
893 | 903 | ||
894 | list_for_each_entry(ii, &sci->sc_dirty_files, i_dirty) { | 904 | list_for_each_entry(ii, &sci->sc_dirty_files, i_dirty) { |
895 | nilfs_fill_in_file_bmap(ifile, ii); | 905 | nilfs_fill_in_file_bmap(sci->sc_root->ifile, ii); |
896 | set_bit(NILFS_I_COLLECTED, &ii->i_state); | 906 | set_bit(NILFS_I_COLLECTED, &ii->i_state); |
897 | } | 907 | } |
898 | } | 908 | } |
@@ -1135,7 +1145,7 @@ static int nilfs_segctor_collect_blocks(struct nilfs_sc_info *sci, int mode) | |||
1135 | sci->sc_stage.flags |= NILFS_CF_IFILE_STARTED; | 1145 | sci->sc_stage.flags |= NILFS_CF_IFILE_STARTED; |
1136 | /* Fall through */ | 1146 | /* Fall through */ |
1137 | case NILFS_ST_IFILE: | 1147 | case NILFS_ST_IFILE: |
1138 | err = nilfs_segctor_scan_file(sci, sbi->s_ifile, | 1148 | err = nilfs_segctor_scan_file(sci, sci->sc_root->ifile, |
1139 | &nilfs_sc_file_ops); | 1149 | &nilfs_sc_file_ops); |
1140 | if (unlikely(err)) | 1150 | if (unlikely(err)) |
1141 | break; | 1151 | break; |
@@ -1599,7 +1609,7 @@ nilfs_copy_replace_page_buffers(struct page *page, struct list_head *out) | |||
1599 | kunmap_atomic(kaddr, KM_USER0); | 1609 | kunmap_atomic(kaddr, KM_USER0); |
1600 | 1610 | ||
1601 | if (!TestSetPageWriteback(clone_page)) | 1611 | if (!TestSetPageWriteback(clone_page)) |
1602 | inc_zone_page_state(clone_page, NR_WRITEBACK); | 1612 | account_page_writeback(clone_page); |
1603 | unlock_page(clone_page); | 1613 | unlock_page(clone_page); |
1604 | 1614 | ||
1605 | return 0; | 1615 | return 0; |
@@ -1900,6 +1910,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) | |||
1900 | set_buffer_uptodate(bh); | 1910 | set_buffer_uptodate(bh); |
1901 | clear_buffer_dirty(bh); | 1911 | clear_buffer_dirty(bh); |
1902 | clear_buffer_nilfs_volatile(bh); | 1912 | clear_buffer_nilfs_volatile(bh); |
1913 | clear_buffer_nilfs_redirected(bh); | ||
1903 | if (bh == segbuf->sb_super_root) { | 1914 | if (bh == segbuf->sb_super_root) { |
1904 | if (bh->b_page != bd_page) { | 1915 | if (bh->b_page != bd_page) { |
1905 | end_page_writeback(bd_page); | 1916 | end_page_writeback(bd_page); |
@@ -1914,12 +1925,12 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) | |||
1914 | } | 1925 | } |
1915 | } | 1926 | } |
1916 | 1927 | ||
1917 | if (!NILFS_SEG_SIMPLEX(&segbuf->sb_sum)) { | 1928 | if (!nilfs_segbuf_simplex(segbuf)) { |
1918 | if (NILFS_SEG_LOGBGN(&segbuf->sb_sum)) { | 1929 | if (segbuf->sb_sum.flags & NILFS_SS_LOGBGN) { |
1919 | set_bit(NILFS_SC_UNCLOSED, &sci->sc_flags); | 1930 | set_bit(NILFS_SC_UNCLOSED, &sci->sc_flags); |
1920 | sci->sc_lseg_stime = jiffies; | 1931 | sci->sc_lseg_stime = jiffies; |
1921 | } | 1932 | } |
1922 | if (NILFS_SEG_LOGEND(&segbuf->sb_sum)) | 1933 | if (segbuf->sb_sum.flags & NILFS_SS_LOGEND) |
1923 | clear_bit(NILFS_SC_UNCLOSED, &sci->sc_flags); | 1934 | clear_bit(NILFS_SC_UNCLOSED, &sci->sc_flags); |
1924 | } | 1935 | } |
1925 | } | 1936 | } |
@@ -1936,11 +1947,9 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) | |||
1936 | 1947 | ||
1937 | nilfs_drop_collected_inodes(&sci->sc_dirty_files); | 1948 | nilfs_drop_collected_inodes(&sci->sc_dirty_files); |
1938 | 1949 | ||
1939 | if (nilfs_doing_gc()) { | 1950 | if (nilfs_doing_gc()) |
1940 | nilfs_drop_collected_inodes(&sci->sc_gc_inodes); | 1951 | nilfs_drop_collected_inodes(&sci->sc_gc_inodes); |
1941 | if (update_sr) | 1952 | else |
1942 | nilfs_commit_gcdat_inode(nilfs); | ||
1943 | } else | ||
1944 | nilfs->ns_nongc_ctime = sci->sc_seg_ctime; | 1953 | nilfs->ns_nongc_ctime = sci->sc_seg_ctime; |
1945 | 1954 | ||
1946 | sci->sc_nblk_inc += sci->sc_nblk_this_inc; | 1955 | sci->sc_nblk_inc += sci->sc_nblk_this_inc; |
@@ -1951,7 +1960,6 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) | |||
1951 | if (update_sr) { | 1960 | if (update_sr) { |
1952 | nilfs_set_last_segment(nilfs, segbuf->sb_pseg_start, | 1961 | nilfs_set_last_segment(nilfs, segbuf->sb_pseg_start, |
1953 | segbuf->sb_sum.seg_seq, nilfs->ns_cno++); | 1962 | segbuf->sb_sum.seg_seq, nilfs->ns_cno++); |
1954 | set_nilfs_sb_dirty(nilfs); | ||
1955 | 1963 | ||
1956 | clear_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags); | 1964 | clear_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags); |
1957 | clear_bit(NILFS_SC_DIRTY, &sci->sc_flags); | 1965 | clear_bit(NILFS_SC_DIRTY, &sci->sc_flags); |
@@ -1977,7 +1985,7 @@ static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci, | |||
1977 | struct nilfs_sb_info *sbi) | 1985 | struct nilfs_sb_info *sbi) |
1978 | { | 1986 | { |
1979 | struct nilfs_inode_info *ii, *n; | 1987 | struct nilfs_inode_info *ii, *n; |
1980 | __u64 cno = sbi->s_nilfs->ns_cno; | 1988 | struct inode *ifile = sci->sc_root->ifile; |
1981 | 1989 | ||
1982 | spin_lock(&sbi->s_inode_lock); | 1990 | spin_lock(&sbi->s_inode_lock); |
1983 | retry: | 1991 | retry: |
@@ -1988,14 +1996,14 @@ static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci, | |||
1988 | 1996 | ||
1989 | spin_unlock(&sbi->s_inode_lock); | 1997 | spin_unlock(&sbi->s_inode_lock); |
1990 | err = nilfs_ifile_get_inode_block( | 1998 | err = nilfs_ifile_get_inode_block( |
1991 | sbi->s_ifile, ii->vfs_inode.i_ino, &ibh); | 1999 | ifile, ii->vfs_inode.i_ino, &ibh); |
1992 | if (unlikely(err)) { | 2000 | if (unlikely(err)) { |
1993 | nilfs_warning(sbi->s_super, __func__, | 2001 | nilfs_warning(sbi->s_super, __func__, |
1994 | "failed to get inode block.\n"); | 2002 | "failed to get inode block.\n"); |
1995 | return err; | 2003 | return err; |
1996 | } | 2004 | } |
1997 | nilfs_mdt_mark_buffer_dirty(ibh); | 2005 | nilfs_mdt_mark_buffer_dirty(ibh); |
1998 | nilfs_mdt_mark_dirty(sbi->s_ifile); | 2006 | nilfs_mdt_mark_dirty(ifile); |
1999 | spin_lock(&sbi->s_inode_lock); | 2007 | spin_lock(&sbi->s_inode_lock); |
2000 | if (likely(!ii->i_bh)) | 2008 | if (likely(!ii->i_bh)) |
2001 | ii->i_bh = ibh; | 2009 | ii->i_bh = ibh; |
@@ -2003,7 +2011,6 @@ static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci, | |||
2003 | brelse(ibh); | 2011 | brelse(ibh); |
2004 | goto retry; | 2012 | goto retry; |
2005 | } | 2013 | } |
2006 | ii->i_cno = cno; | ||
2007 | 2014 | ||
2008 | clear_bit(NILFS_I_QUEUED, &ii->i_state); | 2015 | clear_bit(NILFS_I_QUEUED, &ii->i_state); |
2009 | set_bit(NILFS_I_BUSY, &ii->i_state); | 2016 | set_bit(NILFS_I_BUSY, &ii->i_state); |
@@ -2012,8 +2019,6 @@ static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci, | |||
2012 | } | 2019 | } |
2013 | spin_unlock(&sbi->s_inode_lock); | 2020 | spin_unlock(&sbi->s_inode_lock); |
2014 | 2021 | ||
2015 | NILFS_I(sbi->s_ifile)->i_cno = cno; | ||
2016 | |||
2017 | return 0; | 2022 | return 0; |
2018 | } | 2023 | } |
2019 | 2024 | ||
@@ -2022,19 +2027,13 @@ static void nilfs_segctor_check_out_files(struct nilfs_sc_info *sci, | |||
2022 | { | 2027 | { |
2023 | struct nilfs_transaction_info *ti = current->journal_info; | 2028 | struct nilfs_transaction_info *ti = current->journal_info; |
2024 | struct nilfs_inode_info *ii, *n; | 2029 | struct nilfs_inode_info *ii, *n; |
2025 | __u64 cno = sbi->s_nilfs->ns_cno; | ||
2026 | 2030 | ||
2027 | spin_lock(&sbi->s_inode_lock); | 2031 | spin_lock(&sbi->s_inode_lock); |
2028 | list_for_each_entry_safe(ii, n, &sci->sc_dirty_files, i_dirty) { | 2032 | list_for_each_entry_safe(ii, n, &sci->sc_dirty_files, i_dirty) { |
2029 | if (!test_and_clear_bit(NILFS_I_UPDATED, &ii->i_state) || | 2033 | if (!test_and_clear_bit(NILFS_I_UPDATED, &ii->i_state) || |
2030 | test_bit(NILFS_I_DIRTY, &ii->i_state)) { | 2034 | test_bit(NILFS_I_DIRTY, &ii->i_state)) |
2031 | /* The current checkpoint number (=nilfs->ns_cno) is | ||
2032 | changed between check-in and check-out only if the | ||
2033 | super root is written out. So, we can update i_cno | ||
2034 | for the inodes that remain in the dirty list. */ | ||
2035 | ii->i_cno = cno; | ||
2036 | continue; | 2035 | continue; |
2037 | } | 2036 | |
2038 | clear_bit(NILFS_I_BUSY, &ii->i_state); | 2037 | clear_bit(NILFS_I_BUSY, &ii->i_state); |
2039 | brelse(ii->i_bh); | 2038 | brelse(ii->i_bh); |
2040 | ii->i_bh = NULL; | 2039 | ii->i_bh = NULL; |
@@ -2055,12 +2054,13 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode) | |||
2055 | int err; | 2054 | int err; |
2056 | 2055 | ||
2057 | sci->sc_stage.scnt = NILFS_ST_INIT; | 2056 | sci->sc_stage.scnt = NILFS_ST_INIT; |
2057 | sci->sc_cno = nilfs->ns_cno; | ||
2058 | 2058 | ||
2059 | err = nilfs_segctor_check_in_files(sci, sbi); | 2059 | err = nilfs_segctor_check_in_files(sci, sbi); |
2060 | if (unlikely(err)) | 2060 | if (unlikely(err)) |
2061 | goto out; | 2061 | goto out; |
2062 | 2062 | ||
2063 | if (nilfs_test_metadata_dirty(sbi)) | 2063 | if (nilfs_test_metadata_dirty(nilfs, sci->sc_root)) |
2064 | set_bit(NILFS_SC_DIRTY, &sci->sc_flags); | 2064 | set_bit(NILFS_SC_DIRTY, &sci->sc_flags); |
2065 | 2065 | ||
2066 | if (nilfs_segctor_clean(sci)) | 2066 | if (nilfs_segctor_clean(sci)) |
@@ -2082,7 +2082,7 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode) | |||
2082 | 2082 | ||
2083 | /* Avoid empty segment */ | 2083 | /* Avoid empty segment */ |
2084 | if (sci->sc_stage.scnt == NILFS_ST_DONE && | 2084 | if (sci->sc_stage.scnt == NILFS_ST_DONE && |
2085 | NILFS_SEG_EMPTY(&sci->sc_curseg->sb_sum)) { | 2085 | nilfs_segbuf_empty(sci->sc_curseg)) { |
2086 | nilfs_segctor_abort_construction(sci, nilfs, 1); | 2086 | nilfs_segctor_abort_construction(sci, nilfs, 1); |
2087 | goto out; | 2087 | goto out; |
2088 | } | 2088 | } |
@@ -2092,7 +2092,7 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode) | |||
2092 | goto failed; | 2092 | goto failed; |
2093 | 2093 | ||
2094 | if (sci->sc_stage.flags & NILFS_CF_IFILE_STARTED) | 2094 | if (sci->sc_stage.flags & NILFS_CF_IFILE_STARTED) |
2095 | nilfs_segctor_fill_in_file_bmap(sci, sbi->s_ifile); | 2095 | nilfs_segctor_fill_in_file_bmap(sci); |
2096 | 2096 | ||
2097 | if (mode == SC_LSEG_SR && | 2097 | if (mode == SC_LSEG_SR && |
2098 | sci->sc_stage.scnt >= NILFS_ST_CPFILE) { | 2098 | sci->sc_stage.scnt >= NILFS_ST_CPFILE) { |
@@ -2408,6 +2408,7 @@ static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) | |||
2408 | { | 2408 | { |
2409 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 2409 | struct nilfs_sb_info *sbi = sci->sc_sbi; |
2410 | struct the_nilfs *nilfs = sbi->s_nilfs; | 2410 | struct the_nilfs *nilfs = sbi->s_nilfs; |
2411 | struct nilfs_super_block **sbp; | ||
2411 | int err = 0; | 2412 | int err = 0; |
2412 | 2413 | ||
2413 | nilfs_segctor_accept(sci); | 2414 | nilfs_segctor_accept(sci); |
@@ -2423,8 +2424,13 @@ static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) | |||
2423 | if (test_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags) && | 2424 | if (test_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags) && |
2424 | nilfs_discontinued(nilfs)) { | 2425 | nilfs_discontinued(nilfs)) { |
2425 | down_write(&nilfs->ns_sem); | 2426 | down_write(&nilfs->ns_sem); |
2426 | err = nilfs_commit_super( | 2427 | err = -EIO; |
2427 | sbi, nilfs_altsb_need_update(nilfs)); | 2428 | sbp = nilfs_prepare_super(sbi, |
2429 | nilfs_sb_will_flip(nilfs)); | ||
2430 | if (likely(sbp)) { | ||
2431 | nilfs_set_log_cursor(sbp[0], nilfs); | ||
2432 | err = nilfs_commit_super(sbi, NILFS_SB_COMMIT); | ||
2433 | } | ||
2428 | up_write(&nilfs->ns_sem); | 2434 | up_write(&nilfs->ns_sem); |
2429 | } | 2435 | } |
2430 | } | 2436 | } |
@@ -2447,9 +2453,8 @@ nilfs_remove_written_gcinodes(struct the_nilfs *nilfs, struct list_head *head) | |||
2447 | list_for_each_entry_safe(ii, n, head, i_dirty) { | 2453 | list_for_each_entry_safe(ii, n, head, i_dirty) { |
2448 | if (!test_bit(NILFS_I_UPDATED, &ii->i_state)) | 2454 | if (!test_bit(NILFS_I_UPDATED, &ii->i_state)) |
2449 | continue; | 2455 | continue; |
2450 | hlist_del_init(&ii->vfs_inode.i_hash); | ||
2451 | list_del_init(&ii->i_dirty); | 2456 | list_del_init(&ii->i_dirty); |
2452 | nilfs_clear_gcinode(&ii->vfs_inode); | 2457 | iput(&ii->vfs_inode); |
2453 | } | 2458 | } |
2454 | } | 2459 | } |
2455 | 2460 | ||
@@ -2467,13 +2472,15 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, | |||
2467 | 2472 | ||
2468 | nilfs_transaction_lock(sbi, &ti, 1); | 2473 | nilfs_transaction_lock(sbi, &ti, 1); |
2469 | 2474 | ||
2470 | err = nilfs_init_gcdat_inode(nilfs); | 2475 | err = nilfs_mdt_save_to_shadow_map(nilfs->ns_dat); |
2471 | if (unlikely(err)) | 2476 | if (unlikely(err)) |
2472 | goto out_unlock; | 2477 | goto out_unlock; |
2473 | 2478 | ||
2474 | err = nilfs_ioctl_prepare_clean_segments(nilfs, argv, kbufs); | 2479 | err = nilfs_ioctl_prepare_clean_segments(nilfs, argv, kbufs); |
2475 | if (unlikely(err)) | 2480 | if (unlikely(err)) { |
2481 | nilfs_mdt_restore_from_shadow_map(nilfs->ns_dat); | ||
2476 | goto out_unlock; | 2482 | goto out_unlock; |
2483 | } | ||
2477 | 2484 | ||
2478 | sci->sc_freesegs = kbufs[4]; | 2485 | sci->sc_freesegs = kbufs[4]; |
2479 | sci->sc_nfreesegs = argv[4].v_nmembs; | 2486 | sci->sc_nfreesegs = argv[4].v_nmembs; |
@@ -2505,7 +2512,7 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, | |||
2505 | out_unlock: | 2512 | out_unlock: |
2506 | sci->sc_freesegs = NULL; | 2513 | sci->sc_freesegs = NULL; |
2507 | sci->sc_nfreesegs = 0; | 2514 | sci->sc_nfreesegs = 0; |
2508 | nilfs_clear_gcdat_inode(nilfs); | 2515 | nilfs_mdt_clear_shadow_map(nilfs->ns_dat); |
2509 | nilfs_transaction_unlock(sbi); | 2516 | nilfs_transaction_unlock(sbi); |
2510 | return err; | 2517 | return err; |
2511 | } | 2518 | } |
@@ -2667,6 +2674,8 @@ static int nilfs_segctor_start_thread(struct nilfs_sc_info *sci) | |||
2667 | } | 2674 | } |
2668 | 2675 | ||
2669 | static void nilfs_segctor_kill_thread(struct nilfs_sc_info *sci) | 2676 | static void nilfs_segctor_kill_thread(struct nilfs_sc_info *sci) |
2677 | __acquires(&sci->sc_state_lock) | ||
2678 | __releases(&sci->sc_state_lock) | ||
2670 | { | 2679 | { |
2671 | sci->sc_state |= NILFS_SEGCTOR_QUIT; | 2680 | sci->sc_state |= NILFS_SEGCTOR_QUIT; |
2672 | 2681 | ||
@@ -2681,7 +2690,8 @@ static void nilfs_segctor_kill_thread(struct nilfs_sc_info *sci) | |||
2681 | /* | 2690 | /* |
2682 | * Setup & clean-up functions | 2691 | * Setup & clean-up functions |
2683 | */ | 2692 | */ |
2684 | static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi) | 2693 | static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi, |
2694 | struct nilfs_root *root) | ||
2685 | { | 2695 | { |
2686 | struct nilfs_sc_info *sci; | 2696 | struct nilfs_sc_info *sci; |
2687 | 2697 | ||
@@ -2692,6 +2702,9 @@ static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi) | |||
2692 | sci->sc_sbi = sbi; | 2702 | sci->sc_sbi = sbi; |
2693 | sci->sc_super = sbi->s_super; | 2703 | sci->sc_super = sbi->s_super; |
2694 | 2704 | ||
2705 | nilfs_get_root(root); | ||
2706 | sci->sc_root = root; | ||
2707 | |||
2695 | init_waitqueue_head(&sci->sc_wait_request); | 2708 | init_waitqueue_head(&sci->sc_wait_request); |
2696 | init_waitqueue_head(&sci->sc_wait_daemon); | 2709 | init_waitqueue_head(&sci->sc_wait_daemon); |
2697 | init_waitqueue_head(&sci->sc_wait_task); | 2710 | init_waitqueue_head(&sci->sc_wait_task); |
@@ -2766,6 +2779,8 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) | |||
2766 | WARN_ON(!list_empty(&sci->sc_segbufs)); | 2779 | WARN_ON(!list_empty(&sci->sc_segbufs)); |
2767 | WARN_ON(!list_empty(&sci->sc_write_logs)); | 2780 | WARN_ON(!list_empty(&sci->sc_write_logs)); |
2768 | 2781 | ||
2782 | nilfs_put_root(sci->sc_root); | ||
2783 | |||
2769 | down_write(&sbi->s_nilfs->ns_segctor_sem); | 2784 | down_write(&sbi->s_nilfs->ns_segctor_sem); |
2770 | 2785 | ||
2771 | del_timer_sync(&sci->sc_timer); | 2786 | del_timer_sync(&sci->sc_timer); |
@@ -2775,6 +2790,7 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) | |||
2775 | /** | 2790 | /** |
2776 | * nilfs_attach_segment_constructor - attach a segment constructor | 2791 | * nilfs_attach_segment_constructor - attach a segment constructor |
2777 | * @sbi: nilfs_sb_info | 2792 | * @sbi: nilfs_sb_info |
2793 | * @root: root object of the current filesystem tree | ||
2778 | * | 2794 | * |
2779 | * nilfs_attach_segment_constructor() allocates a struct nilfs_sc_info, | 2795 | * nilfs_attach_segment_constructor() allocates a struct nilfs_sc_info, |
2780 | * initializes it, and starts the segment constructor. | 2796 | * initializes it, and starts the segment constructor. |
@@ -2784,9 +2800,9 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) | |||
2784 | * | 2800 | * |
2785 | * %-ENOMEM - Insufficient memory available. | 2801 | * %-ENOMEM - Insufficient memory available. |
2786 | */ | 2802 | */ |
2787 | int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi) | 2803 | int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi, |
2804 | struct nilfs_root *root) | ||
2788 | { | 2805 | { |
2789 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
2790 | int err; | 2806 | int err; |
2791 | 2807 | ||
2792 | if (NILFS_SC(sbi)) { | 2808 | if (NILFS_SC(sbi)) { |
@@ -2798,14 +2814,12 @@ int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi) | |||
2798 | nilfs_detach_segment_constructor(sbi); | 2814 | nilfs_detach_segment_constructor(sbi); |
2799 | } | 2815 | } |
2800 | 2816 | ||
2801 | sbi->s_sc_info = nilfs_segctor_new(sbi); | 2817 | sbi->s_sc_info = nilfs_segctor_new(sbi, root); |
2802 | if (!sbi->s_sc_info) | 2818 | if (!sbi->s_sc_info) |
2803 | return -ENOMEM; | 2819 | return -ENOMEM; |
2804 | 2820 | ||
2805 | nilfs_attach_writer(nilfs, sbi); | ||
2806 | err = nilfs_segctor_start_thread(NILFS_SC(sbi)); | 2821 | err = nilfs_segctor_start_thread(NILFS_SC(sbi)); |
2807 | if (err) { | 2822 | if (err) { |
2808 | nilfs_detach_writer(nilfs, sbi); | ||
2809 | kfree(sbi->s_sc_info); | 2823 | kfree(sbi->s_sc_info); |
2810 | sbi->s_sc_info = NULL; | 2824 | sbi->s_sc_info = NULL; |
2811 | } | 2825 | } |
@@ -2842,5 +2856,4 @@ void nilfs_detach_segment_constructor(struct nilfs_sb_info *sbi) | |||
2842 | up_write(&nilfs->ns_segctor_sem); | 2856 | up_write(&nilfs->ns_segctor_sem); |
2843 | 2857 | ||
2844 | nilfs_dispose_list(sbi, &garbage_list, 1); | 2858 | nilfs_dispose_list(sbi, &garbage_list, 1); |
2845 | nilfs_detach_writer(nilfs, sbi); | ||
2846 | } | 2859 | } |