Lines Matching refs:sci

90 static inline void nilfs_sc_cstage_inc(struct nilfs_sc_info *sci)  in nilfs_sc_cstage_inc()  argument
92 sci->sc_stage.scnt++; in nilfs_sc_cstage_inc()
93 trace_nilfs2_collection_stage_transition(sci); in nilfs_sc_cstage_inc()
96 static inline void nilfs_sc_cstage_set(struct nilfs_sc_info *sci, int next_scnt) in nilfs_sc_cstage_set() argument
98 sci->sc_stage.scnt = next_scnt; in nilfs_sc_cstage_set()
99 trace_nilfs2_collection_stage_transition(sci); in nilfs_sc_cstage_set()
102 static inline int nilfs_sc_cstage_get(struct nilfs_sc_info *sci) in nilfs_sc_cstage_get() argument
104 return sci->sc_stage.scnt; in nilfs_sc_cstage_get()
271 struct nilfs_sc_info *sci = nilfs->ns_writer; in nilfs_transaction_commit() local
274 nilfs_segctor_start_timer(sci); in nilfs_transaction_commit()
275 if (atomic_read(&nilfs->ns_ndirtyblks) > sci->sc_watermark) in nilfs_transaction_commit()
276 nilfs_segctor_do_flush(sci, 0); in nilfs_transaction_commit()
318 struct nilfs_sc_info *sci = nilfs->ns_writer; in nilfs_relax_pressure_in_lock() local
320 if (sb_rdonly(sb) || unlikely(!sci) || !sci->sc_flush_request) in nilfs_relax_pressure_in_lock()
323 set_bit(NILFS_SC_PRIOR_FLUSH, &sci->sc_flags); in nilfs_relax_pressure_in_lock()
327 if (sci->sc_flush_request && in nilfs_relax_pressure_in_lock()
328 test_bit(NILFS_SC_PRIOR_FLUSH, &sci->sc_flags)) { in nilfs_relax_pressure_in_lock()
332 nilfs_segctor_do_immediate_flush(sci); in nilfs_relax_pressure_in_lock()
344 struct nilfs_sc_info *sci = nilfs->ns_writer; in nilfs_transaction_lock() local
358 if (!test_bit(NILFS_SC_PRIOR_FLUSH, &sci->sc_flags)) in nilfs_transaction_lock()
361 nilfs_segctor_do_immediate_flush(sci); in nilfs_transaction_lock()
388 static void *nilfs_segctor_map_segsum_entry(struct nilfs_sc_info *sci, in nilfs_segctor_map_segsum_entry() argument
392 struct nilfs_segment_buffer *segbuf = sci->sc_curseg; in nilfs_segctor_map_segsum_entry()
393 unsigned int blocksize = sci->sc_super->s_blocksize; in nilfs_segctor_map_segsum_entry()
411 static int nilfs_segctor_reset_segment_buffer(struct nilfs_sc_info *sci) in nilfs_segctor_reset_segment_buffer() argument
413 struct nilfs_segment_buffer *segbuf = sci->sc_curseg; in nilfs_segctor_reset_segment_buffer()
421 err = nilfs_segbuf_reset(segbuf, flags, sci->sc_seg_ctime, sci->sc_cno); in nilfs_segctor_reset_segment_buffer()
427 sci->sc_finfo_ptr.bh = sumbh; sci->sc_finfo_ptr.offset = sumbytes; in nilfs_segctor_reset_segment_buffer()
428 sci->sc_binfo_ptr.bh = sumbh; sci->sc_binfo_ptr.offset = sumbytes; in nilfs_segctor_reset_segment_buffer()
429 sci->sc_blk_cnt = sci->sc_datablk_cnt = 0; in nilfs_segctor_reset_segment_buffer()
440 static void nilfs_segctor_zeropad_segsum(struct nilfs_sc_info *sci) in nilfs_segctor_zeropad_segsum() argument
444 ssp = sci->sc_blk_cnt > 0 ? &sci->sc_binfo_ptr : &sci->sc_finfo_ptr; in nilfs_segctor_zeropad_segsum()
450 static int nilfs_segctor_feed_segment(struct nilfs_sc_info *sci) in nilfs_segctor_feed_segment() argument
452 sci->sc_nblk_this_inc += sci->sc_curseg->sb_sum.nblocks; in nilfs_segctor_feed_segment()
453 if (NILFS_SEGBUF_IS_LAST(sci->sc_curseg, &sci->sc_segbufs)) in nilfs_segctor_feed_segment()
458 nilfs_segctor_zeropad_segsum(sci); in nilfs_segctor_feed_segment()
459 sci->sc_curseg = NILFS_NEXT_SEGBUF(sci->sc_curseg); in nilfs_segctor_feed_segment()
460 return nilfs_segctor_reset_segment_buffer(sci); in nilfs_segctor_feed_segment()
463 static int nilfs_segctor_add_super_root(struct nilfs_sc_info *sci) in nilfs_segctor_add_super_root() argument
465 struct nilfs_segment_buffer *segbuf = sci->sc_curseg; in nilfs_segctor_add_super_root()
469 err = nilfs_segctor_feed_segment(sci); in nilfs_segctor_add_super_root()
472 segbuf = sci->sc_curseg; in nilfs_segctor_add_super_root()
484 struct nilfs_sc_info *sci, const struct nilfs_segsum_pointer *ssp, in nilfs_segctor_segsum_block_required() argument
487 unsigned int blocksize = sci->sc_super->s_blocksize; in nilfs_segctor_segsum_block_required()
491 (!sci->sc_blk_cnt ? sizeof(struct nilfs_finfo) : 0) > in nilfs_segctor_segsum_block_required()
495 static void nilfs_segctor_begin_finfo(struct nilfs_sc_info *sci, in nilfs_segctor_begin_finfo() argument
498 sci->sc_curseg->sb_sum.nfinfo++; in nilfs_segctor_begin_finfo()
499 sci->sc_binfo_ptr = sci->sc_finfo_ptr; in nilfs_segctor_begin_finfo()
501 sci, &sci->sc_binfo_ptr, sizeof(struct nilfs_finfo)); in nilfs_segctor_begin_finfo()
504 !test_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags)) in nilfs_segctor_begin_finfo()
505 set_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags); in nilfs_segctor_begin_finfo()
509 static void nilfs_segctor_end_finfo(struct nilfs_sc_info *sci, in nilfs_segctor_end_finfo() argument
517 if (sci->sc_blk_cnt == 0) in nilfs_segctor_end_finfo()
527 cno = sci->sc_cno; in nilfs_segctor_end_finfo()
529 finfo = nilfs_segctor_map_segsum_entry(sci, &sci->sc_finfo_ptr, in nilfs_segctor_end_finfo()
532 finfo->fi_nblocks = cpu_to_le32(sci->sc_blk_cnt); in nilfs_segctor_end_finfo()
533 finfo->fi_ndatablk = cpu_to_le32(sci->sc_datablk_cnt); in nilfs_segctor_end_finfo()
536 segbuf = sci->sc_curseg; in nilfs_segctor_end_finfo()
537 segbuf->sb_sum.sumbytes = sci->sc_binfo_ptr.offset + in nilfs_segctor_end_finfo()
538 sci->sc_super->s_blocksize * (segbuf->sb_sum.nsumblk - 1); in nilfs_segctor_end_finfo()
539 sci->sc_finfo_ptr = sci->sc_binfo_ptr; in nilfs_segctor_end_finfo()
540 sci->sc_blk_cnt = sci->sc_datablk_cnt = 0; in nilfs_segctor_end_finfo()
543 static int nilfs_segctor_add_file_block(struct nilfs_sc_info *sci, in nilfs_segctor_add_file_block() argument
552 segbuf = sci->sc_curseg; in nilfs_segctor_add_file_block()
554 sci, &sci->sc_binfo_ptr, binfo_size); in nilfs_segctor_add_file_block()
556 nilfs_segctor_end_finfo(sci, inode); in nilfs_segctor_add_file_block()
557 err = nilfs_segctor_feed_segment(sci); in nilfs_segctor_add_file_block()
563 nilfs_segctor_zeropad_segsum(sci); in nilfs_segctor_add_file_block()
568 if (sci->sc_blk_cnt == 0) in nilfs_segctor_add_file_block()
569 nilfs_segctor_begin_finfo(sci, inode); in nilfs_segctor_add_file_block()
571 nilfs_segctor_map_segsum_entry(sci, &sci->sc_binfo_ptr, binfo_size); in nilfs_segctor_add_file_block()
574 sci->sc_blk_cnt++; in nilfs_segctor_add_file_block()
582 static int nilfs_collect_file_data(struct nilfs_sc_info *sci, in nilfs_collect_file_data() argument
591 err = nilfs_segctor_add_file_block(sci, bh, inode, in nilfs_collect_file_data()
594 sci->sc_datablk_cnt++; in nilfs_collect_file_data()
598 static int nilfs_collect_file_node(struct nilfs_sc_info *sci, in nilfs_collect_file_node() argument
605 static int nilfs_collect_file_bmap(struct nilfs_sc_info *sci, in nilfs_collect_file_bmap() argument
610 return nilfs_segctor_add_file_block(sci, bh, inode, sizeof(__le64)); in nilfs_collect_file_bmap()
613 static void nilfs_write_file_data_binfo(struct nilfs_sc_info *sci, in nilfs_write_file_data_binfo() argument
618 sci, ssp, sizeof(*binfo_v)); in nilfs_write_file_data_binfo()
622 static void nilfs_write_file_node_binfo(struct nilfs_sc_info *sci, in nilfs_write_file_node_binfo() argument
627 sci, ssp, sizeof(*vblocknr)); in nilfs_write_file_node_binfo()
639 static int nilfs_collect_dat_data(struct nilfs_sc_info *sci, in nilfs_collect_dat_data() argument
648 err = nilfs_segctor_add_file_block(sci, bh, inode, sizeof(__le64)); in nilfs_collect_dat_data()
650 sci->sc_datablk_cnt++; in nilfs_collect_dat_data()
654 static int nilfs_collect_dat_bmap(struct nilfs_sc_info *sci, in nilfs_collect_dat_bmap() argument
658 return nilfs_segctor_add_file_block(sci, bh, inode, in nilfs_collect_dat_bmap()
662 static void nilfs_write_dat_data_binfo(struct nilfs_sc_info *sci, in nilfs_write_dat_data_binfo() argument
666 __le64 *blkoff = nilfs_segctor_map_segsum_entry(sci, ssp, in nilfs_write_dat_data_binfo()
671 static void nilfs_write_dat_node_binfo(struct nilfs_sc_info *sci, in nilfs_write_dat_node_binfo() argument
676 nilfs_segctor_map_segsum_entry(sci, ssp, sizeof(*binfo_dat)); in nilfs_write_dat_node_binfo()
827 struct nilfs_sc_info *sci = container_of(work, struct nilfs_sc_info, in nilfs_iput_work_func() local
829 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_iput_work_func()
831 nilfs_dispose_list(nilfs, &sci->sc_iput_queue, 0); in nilfs_iput_work_func()
850 static int nilfs_segctor_clean(struct nilfs_sc_info *sci) in nilfs_segctor_clean() argument
852 return list_empty(&sci->sc_dirty_files) && in nilfs_segctor_clean()
853 !test_bit(NILFS_SC_DIRTY, &sci->sc_flags) && in nilfs_segctor_clean()
854 sci->sc_nfreesegs == 0 && in nilfs_segctor_clean()
855 (!nilfs_doing_gc() || list_empty(&sci->sc_gc_inodes)); in nilfs_segctor_clean()
858 static int nilfs_segctor_confirm(struct nilfs_sc_info *sci) in nilfs_segctor_confirm() argument
860 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_confirm()
863 if (nilfs_test_metadata_dirty(nilfs, sci->sc_root)) in nilfs_segctor_confirm()
864 set_bit(NILFS_SC_DIRTY, &sci->sc_flags); in nilfs_segctor_confirm()
867 if (list_empty(&nilfs->ns_dirty_files) && nilfs_segctor_clean(sci)) in nilfs_segctor_confirm()
874 static void nilfs_segctor_clear_metadata_dirty(struct nilfs_sc_info *sci) in nilfs_segctor_clear_metadata_dirty() argument
876 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_clear_metadata_dirty()
878 nilfs_mdt_clear_dirty(sci->sc_root->ifile); in nilfs_segctor_clear_metadata_dirty()
884 static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci) in nilfs_segctor_create_checkpoint() argument
886 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_create_checkpoint()
905 nilfs_error(sci->sc_super, in nilfs_segctor_create_checkpoint()
912 static int nilfs_segctor_fill_in_checkpoint(struct nilfs_sc_info *sci) in nilfs_segctor_fill_in_checkpoint() argument
914 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_fill_in_checkpoint()
923 nilfs_error(sci->sc_super, in nilfs_segctor_fill_in_checkpoint()
932 cpu_to_le64(atomic64_read(&sci->sc_root->inodes_count)); in nilfs_segctor_fill_in_checkpoint()
934 cpu_to_le64(atomic64_read(&sci->sc_root->blocks_count)); in nilfs_segctor_fill_in_checkpoint()
936 cpu_to_le64(sci->sc_nblk_inc + sci->sc_nblk_this_inc); in nilfs_segctor_fill_in_checkpoint()
937 raw_cp->cp_create = cpu_to_le64(sci->sc_seg_ctime); in nilfs_segctor_fill_in_checkpoint()
940 if (test_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags)) in nilfs_segctor_fill_in_checkpoint()
945 nilfs_write_inode_common(sci->sc_root->ifile, in nilfs_segctor_fill_in_checkpoint()
971 static void nilfs_segctor_fill_in_file_bmap(struct nilfs_sc_info *sci) in nilfs_segctor_fill_in_file_bmap() argument
975 list_for_each_entry(ii, &sci->sc_dirty_files, i_dirty) { in nilfs_segctor_fill_in_file_bmap()
976 nilfs_fill_in_file_bmap(sci->sc_root->ifile, ii); in nilfs_segctor_fill_in_file_bmap()
981 static void nilfs_segctor_fill_in_super_root(struct nilfs_sc_info *sci, in nilfs_segctor_fill_in_super_root() argument
988 bh_sr = NILFS_LAST_SEGBUF(&sci->sc_segbufs)->sb_super_root; in nilfs_segctor_fill_in_super_root()
999 nilfs->ns_nongc_ctime : sci->sc_seg_ctime); in nilfs_segctor_fill_in_super_root()
1036 static int nilfs_segctor_apply_buffers(struct nilfs_sc_info *sci, in nilfs_segctor_apply_buffers() argument
1049 err = collect(sci, bh, inode); in nilfs_segctor_apply_buffers()
1067 static size_t nilfs_segctor_buffer_rest(struct nilfs_sc_info *sci) in nilfs_segctor_buffer_rest() argument
1070 return sci->sc_segbuf_nblocks - in nilfs_segctor_buffer_rest()
1071 (sci->sc_nblk_this_inc + sci->sc_curseg->sb_sum.nblocks); in nilfs_segctor_buffer_rest()
1074 static int nilfs_segctor_scan_file(struct nilfs_sc_info *sci, in nilfs_segctor_scan_file() argument
1082 if (!(sci->sc_stage.flags & NILFS_CF_NODE)) { in nilfs_segctor_scan_file()
1083 size_t n, rest = nilfs_segctor_buffer_rest(sci); in nilfs_segctor_scan_file()
1089 sci, inode, &data_buffers, in nilfs_segctor_scan_file()
1097 if (!(sci->sc_stage.flags & NILFS_CF_NODE)) { in nilfs_segctor_scan_file()
1099 sci, inode, &data_buffers, sc_ops->collect_data); in nilfs_segctor_scan_file()
1103 sci, inode, &node_buffers, NULL); in nilfs_segctor_scan_file()
1106 sci->sc_stage.flags |= NILFS_CF_NODE; in nilfs_segctor_scan_file()
1110 sci, inode, &node_buffers, sc_ops->collect_node); in nilfs_segctor_scan_file()
1116 sci, inode, &node_buffers, sc_ops->collect_bmap); in nilfs_segctor_scan_file()
1120 nilfs_segctor_end_finfo(sci, inode); in nilfs_segctor_scan_file()
1121 sci->sc_stage.flags &= ~NILFS_CF_NODE; in nilfs_segctor_scan_file()
1127 static int nilfs_segctor_scan_file_dsync(struct nilfs_sc_info *sci, in nilfs_segctor_scan_file_dsync() argument
1131 size_t n, rest = nilfs_segctor_buffer_rest(sci); in nilfs_segctor_scan_file_dsync()
1135 sci->sc_dsync_start, in nilfs_segctor_scan_file_dsync()
1136 sci->sc_dsync_end); in nilfs_segctor_scan_file_dsync()
1138 err = nilfs_segctor_apply_buffers(sci, inode, &data_buffers, in nilfs_segctor_scan_file_dsync()
1141 nilfs_segctor_end_finfo(sci, inode); in nilfs_segctor_scan_file_dsync()
1148 static int nilfs_segctor_collect_blocks(struct nilfs_sc_info *sci, int mode) in nilfs_segctor_collect_blocks() argument
1150 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_collect_blocks()
1156 switch (nilfs_sc_cstage_get(sci)) { in nilfs_segctor_collect_blocks()
1159 sci->sc_stage.flags = 0; in nilfs_segctor_collect_blocks()
1161 if (!test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags)) { in nilfs_segctor_collect_blocks()
1162 sci->sc_nblk_inc = 0; in nilfs_segctor_collect_blocks()
1163 sci->sc_curseg->sb_sum.flags = NILFS_SS_LOGBGN; in nilfs_segctor_collect_blocks()
1165 nilfs_sc_cstage_set(sci, NILFS_ST_DSYNC); in nilfs_segctor_collect_blocks()
1170 sci->sc_stage.dirty_file_ptr = NULL; in nilfs_segctor_collect_blocks()
1171 sci->sc_stage.gc_inode_ptr = NULL; in nilfs_segctor_collect_blocks()
1173 nilfs_sc_cstage_set(sci, NILFS_ST_DAT); in nilfs_segctor_collect_blocks()
1176 nilfs_sc_cstage_inc(sci); in nilfs_segctor_collect_blocks()
1180 head = &sci->sc_gc_inodes; in nilfs_segctor_collect_blocks()
1181 ii = list_prepare_entry(sci->sc_stage.gc_inode_ptr, in nilfs_segctor_collect_blocks()
1185 sci, &ii->vfs_inode, in nilfs_segctor_collect_blocks()
1188 sci->sc_stage.gc_inode_ptr = list_entry( in nilfs_segctor_collect_blocks()
1196 sci->sc_stage.gc_inode_ptr = NULL; in nilfs_segctor_collect_blocks()
1198 nilfs_sc_cstage_inc(sci); in nilfs_segctor_collect_blocks()
1201 head = &sci->sc_dirty_files; in nilfs_segctor_collect_blocks()
1202 ii = list_prepare_entry(sci->sc_stage.dirty_file_ptr, head, in nilfs_segctor_collect_blocks()
1207 err = nilfs_segctor_scan_file(sci, &ii->vfs_inode, in nilfs_segctor_collect_blocks()
1210 sci->sc_stage.dirty_file_ptr = in nilfs_segctor_collect_blocks()
1219 sci->sc_stage.dirty_file_ptr = NULL; in nilfs_segctor_collect_blocks()
1221 nilfs_sc_cstage_set(sci, NILFS_ST_DONE); in nilfs_segctor_collect_blocks()
1224 nilfs_sc_cstage_inc(sci); in nilfs_segctor_collect_blocks()
1225 sci->sc_stage.flags |= NILFS_CF_IFILE_STARTED; in nilfs_segctor_collect_blocks()
1228 err = nilfs_segctor_scan_file(sci, sci->sc_root->ifile, in nilfs_segctor_collect_blocks()
1232 nilfs_sc_cstage_inc(sci); in nilfs_segctor_collect_blocks()
1234 err = nilfs_segctor_create_checkpoint(sci); in nilfs_segctor_collect_blocks()
1239 err = nilfs_segctor_scan_file(sci, nilfs->ns_cpfile, in nilfs_segctor_collect_blocks()
1243 nilfs_sc_cstage_inc(sci); in nilfs_segctor_collect_blocks()
1246 err = nilfs_sufile_freev(nilfs->ns_sufile, sci->sc_freesegs, in nilfs_segctor_collect_blocks()
1247 sci->sc_nfreesegs, &ndone); in nilfs_segctor_collect_blocks()
1250 sci->sc_freesegs, ndone, in nilfs_segctor_collect_blocks()
1254 sci->sc_stage.flags |= NILFS_CF_SUFREED; in nilfs_segctor_collect_blocks()
1256 err = nilfs_segctor_scan_file(sci, nilfs->ns_sufile, in nilfs_segctor_collect_blocks()
1260 nilfs_sc_cstage_inc(sci); in nilfs_segctor_collect_blocks()
1264 err = nilfs_segctor_scan_file(sci, nilfs->ns_dat, in nilfs_segctor_collect_blocks()
1269 nilfs_sc_cstage_set(sci, NILFS_ST_DONE); in nilfs_segctor_collect_blocks()
1272 nilfs_sc_cstage_inc(sci); in nilfs_segctor_collect_blocks()
1277 err = nilfs_segctor_add_super_root(sci); in nilfs_segctor_collect_blocks()
1282 sci->sc_curseg->sb_sum.flags |= NILFS_SS_LOGEND; in nilfs_segctor_collect_blocks()
1283 nilfs_sc_cstage_set(sci, NILFS_ST_DONE); in nilfs_segctor_collect_blocks()
1287 sci->sc_curseg->sb_sum.flags |= NILFS_SS_SYNDT; in nilfs_segctor_collect_blocks()
1288 ii = sci->sc_dsync_inode; in nilfs_segctor_collect_blocks()
1292 err = nilfs_segctor_scan_file_dsync(sci, &ii->vfs_inode); in nilfs_segctor_collect_blocks()
1295 sci->sc_curseg->sb_sum.flags |= NILFS_SS_LOGEND; in nilfs_segctor_collect_blocks()
1296 nilfs_sc_cstage_set(sci, NILFS_ST_DONE); in nilfs_segctor_collect_blocks()
1313 static int nilfs_segctor_begin_construction(struct nilfs_sc_info *sci, in nilfs_segctor_begin_construction() argument
1320 segbuf = nilfs_segbuf_new(sci->sc_super); in nilfs_segctor_begin_construction()
1324 if (list_empty(&sci->sc_write_logs)) { in nilfs_segctor_begin_construction()
1340 prev = NILFS_LAST_SEGBUF(&sci->sc_write_logs); in nilfs_segctor_begin_construction()
1363 BUG_ON(!list_empty(&sci->sc_segbufs)); in nilfs_segctor_begin_construction()
1364 list_add_tail(&segbuf->sb_list, &sci->sc_segbufs); in nilfs_segctor_begin_construction()
1365 sci->sc_segbuf_nblocks = segbuf->sb_rest_blocks; in nilfs_segctor_begin_construction()
1373 static int nilfs_segctor_extend_segments(struct nilfs_sc_info *sci, in nilfs_segctor_extend_segments() argument
1382 prev = NILFS_LAST_SEGBUF(&sci->sc_segbufs); in nilfs_segctor_extend_segments()
1396 segbuf = nilfs_segbuf_new(sci->sc_super); in nilfs_segctor_extend_segments()
1402 sci->sc_segbuf_nblocks += segbuf->sb_rest_blocks; in nilfs_segctor_extend_segments()
1415 list_splice_tail(&list, &sci->sc_segbufs); in nilfs_segctor_extend_segments()
1468 static void nilfs_segctor_update_segusage(struct nilfs_sc_info *sci, in nilfs_segctor_update_segusage() argument
1475 list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) { in nilfs_segctor_update_segusage()
1480 sci->sc_seg_ctime); in nilfs_segctor_update_segusage()
1503 static void nilfs_segctor_truncate_segments(struct nilfs_sc_info *sci, in nilfs_segctor_truncate_segments() argument
1510 list_for_each_entry_continue(segbuf, &sci->sc_segbufs, sb_list) { in nilfs_segctor_truncate_segments()
1511 sci->sc_segbuf_nblocks -= segbuf->sb_rest_blocks; in nilfs_segctor_truncate_segments()
1515 nilfs_truncate_logs(&sci->sc_segbufs, last); in nilfs_segctor_truncate_segments()
1519 static int nilfs_segctor_collect(struct nilfs_sc_info *sci, in nilfs_segctor_collect() argument
1522 struct nilfs_cstage prev_stage = sci->sc_stage; in nilfs_segctor_collect()
1527 sci->sc_nblk_this_inc = 0; in nilfs_segctor_collect()
1528 sci->sc_curseg = NILFS_FIRST_SEGBUF(&sci->sc_segbufs); in nilfs_segctor_collect()
1530 err = nilfs_segctor_reset_segment_buffer(sci); in nilfs_segctor_collect()
1534 err = nilfs_segctor_collect_blocks(sci, mode); in nilfs_segctor_collect()
1535 sci->sc_nblk_this_inc += sci->sc_curseg->sb_sum.nblocks; in nilfs_segctor_collect()
1544 nilfs_sc_cstage_get(sci) < NILFS_ST_CPFILE) in nilfs_segctor_collect()
1547 nilfs_clear_logs(&sci->sc_segbufs); in nilfs_segctor_collect()
1549 if (sci->sc_stage.flags & NILFS_CF_SUFREED) { in nilfs_segctor_collect()
1551 sci->sc_freesegs, in nilfs_segctor_collect()
1552 sci->sc_nfreesegs, in nilfs_segctor_collect()
1555 sci->sc_stage.flags &= ~NILFS_CF_SUFREED; in nilfs_segctor_collect()
1558 err = nilfs_segctor_extend_segments(sci, nilfs, nadd); in nilfs_segctor_collect()
1563 sci->sc_stage = prev_stage; in nilfs_segctor_collect()
1565 nilfs_segctor_zeropad_segsum(sci); in nilfs_segctor_collect()
1566 nilfs_segctor_truncate_segments(sci, sci->sc_curseg, nilfs->ns_sufile); in nilfs_segctor_collect()
1583 nilfs_segctor_update_payload_blocknr(struct nilfs_sc_info *sci, in nilfs_segctor_update_payload_blocknr() argument
1611 sci, &ssp, sizeof(*finfo)); in nilfs_segctor_update_payload_blocknr()
1636 sc_op->write_data_binfo(sci, &ssp, &binfo); in nilfs_segctor_update_payload_blocknr()
1638 sc_op->write_node_binfo(sci, &ssp, &binfo); in nilfs_segctor_update_payload_blocknr()
1655 static int nilfs_segctor_assign(struct nilfs_sc_info *sci, int mode) in nilfs_segctor_assign() argument
1660 list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) { in nilfs_segctor_assign()
1661 err = nilfs_segctor_update_payload_blocknr(sci, segbuf, mode); in nilfs_segctor_assign()
1684 static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci) in nilfs_segctor_prepare_write() argument
1689 list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) { in nilfs_segctor_prepare_write()
1736 static int nilfs_segctor_write(struct nilfs_sc_info *sci, in nilfs_segctor_write() argument
1741 ret = nilfs_write_logs(&sci->sc_segbufs, nilfs); in nilfs_segctor_write()
1742 list_splice_tail_init(&sci->sc_segbufs, &sci->sc_write_logs); in nilfs_segctor_write()
1827 static void nilfs_segctor_abort_construction(struct nilfs_sc_info *sci, in nilfs_segctor_abort_construction() argument
1833 list_splice_tail_init(&sci->sc_write_logs, &logs); in nilfs_segctor_abort_construction()
1837 list_splice_tail_init(&sci->sc_segbufs, &logs); in nilfs_segctor_abort_construction()
1844 if (sci->sc_stage.flags & NILFS_CF_SUFREED) { in nilfs_segctor_abort_construction()
1846 sci->sc_freesegs, in nilfs_segctor_abort_construction()
1847 sci->sc_nfreesegs, in nilfs_segctor_abort_construction()
1866 static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) in nilfs_segctor_complete_write() argument
1870 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_complete_write()
1873 list_for_each_entry(segbuf, &sci->sc_write_logs, sb_list) { in nilfs_segctor_complete_write()
1924 set_bit(NILFS_SC_UNCLOSED, &sci->sc_flags); in nilfs_segctor_complete_write()
1925 sci->sc_lseg_stime = jiffies; in nilfs_segctor_complete_write()
1928 clear_bit(NILFS_SC_UNCLOSED, &sci->sc_flags); in nilfs_segctor_complete_write()
1940 nilfs_drop_collected_inodes(&sci->sc_dirty_files); in nilfs_segctor_complete_write()
1943 nilfs_drop_collected_inodes(&sci->sc_gc_inodes); in nilfs_segctor_complete_write()
1945 nilfs->ns_nongc_ctime = sci->sc_seg_ctime; in nilfs_segctor_complete_write()
1947 sci->sc_nblk_inc += sci->sc_nblk_this_inc; in nilfs_segctor_complete_write()
1949 segbuf = NILFS_LAST_SEGBUF(&sci->sc_write_logs); in nilfs_segctor_complete_write()
1957 clear_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags); in nilfs_segctor_complete_write()
1958 clear_bit(NILFS_SC_DIRTY, &sci->sc_flags); in nilfs_segctor_complete_write()
1959 set_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags); in nilfs_segctor_complete_write()
1960 nilfs_segctor_clear_metadata_dirty(sci); in nilfs_segctor_complete_write()
1962 clear_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags); in nilfs_segctor_complete_write()
1965 static int nilfs_segctor_wait(struct nilfs_sc_info *sci) in nilfs_segctor_wait() argument
1969 ret = nilfs_wait_on_logs(&sci->sc_write_logs); in nilfs_segctor_wait()
1971 nilfs_segctor_complete_write(sci); in nilfs_segctor_wait()
1972 nilfs_destroy_logs(&sci->sc_write_logs); in nilfs_segctor_wait()
1977 static int nilfs_segctor_collect_dirty_files(struct nilfs_sc_info *sci, in nilfs_segctor_collect_dirty_files() argument
1981 struct inode *ifile = sci->sc_root->ifile; in nilfs_segctor_collect_dirty_files()
1994 nilfs_warn(sci->sc_super, in nilfs_segctor_collect_dirty_files()
2013 list_move_tail(&ii->i_dirty, &sci->sc_dirty_files); in nilfs_segctor_collect_dirty_files()
2020 static void nilfs_segctor_drop_written_files(struct nilfs_sc_info *sci, in nilfs_segctor_drop_written_files() argument
2024 int during_mount = !(sci->sc_super->s_flags & SB_ACTIVE); in nilfs_segctor_drop_written_files()
2028 list_for_each_entry_safe(ii, n, &sci->sc_dirty_files, i_dirty) { in nilfs_segctor_drop_written_files()
2042 list_add_tail(&ii->i_dirty, &sci->sc_iput_queue); in nilfs_segctor_drop_written_files()
2053 schedule_work(&sci->sc_iput_work); in nilfs_segctor_drop_written_files()
2059 static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode) in nilfs_segctor_do_construct() argument
2061 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_do_construct()
2064 if (sb_rdonly(sci->sc_super)) in nilfs_segctor_do_construct()
2067 nilfs_sc_cstage_set(sci, NILFS_ST_INIT); in nilfs_segctor_do_construct()
2068 sci->sc_cno = nilfs->ns_cno; in nilfs_segctor_do_construct()
2070 err = nilfs_segctor_collect_dirty_files(sci, nilfs); in nilfs_segctor_do_construct()
2074 if (nilfs_test_metadata_dirty(nilfs, sci->sc_root)) in nilfs_segctor_do_construct()
2075 set_bit(NILFS_SC_DIRTY, &sci->sc_flags); in nilfs_segctor_do_construct()
2077 if (nilfs_segctor_clean(sci)) in nilfs_segctor_do_construct()
2081 sci->sc_stage.flags &= ~NILFS_CF_HISTORY_MASK; in nilfs_segctor_do_construct()
2083 err = nilfs_segctor_begin_construction(sci, nilfs); in nilfs_segctor_do_construct()
2088 sci->sc_seg_ctime = ktime_get_real_seconds(); in nilfs_segctor_do_construct()
2090 err = nilfs_segctor_collect(sci, nilfs, mode); in nilfs_segctor_do_construct()
2095 if (nilfs_sc_cstage_get(sci) == NILFS_ST_DONE && in nilfs_segctor_do_construct()
2096 nilfs_segbuf_empty(sci->sc_curseg)) { in nilfs_segctor_do_construct()
2097 nilfs_segctor_abort_construction(sci, nilfs, 1); in nilfs_segctor_do_construct()
2101 err = nilfs_segctor_assign(sci, mode); in nilfs_segctor_do_construct()
2105 if (sci->sc_stage.flags & NILFS_CF_IFILE_STARTED) in nilfs_segctor_do_construct()
2106 nilfs_segctor_fill_in_file_bmap(sci); in nilfs_segctor_do_construct()
2109 nilfs_sc_cstage_get(sci) >= NILFS_ST_CPFILE) { in nilfs_segctor_do_construct()
2110 err = nilfs_segctor_fill_in_checkpoint(sci); in nilfs_segctor_do_construct()
2114 nilfs_segctor_fill_in_super_root(sci, nilfs); in nilfs_segctor_do_construct()
2116 nilfs_segctor_update_segusage(sci, nilfs->ns_sufile); in nilfs_segctor_do_construct()
2119 nilfs_segctor_prepare_write(sci); in nilfs_segctor_do_construct()
2121 nilfs_add_checksums_on_logs(&sci->sc_segbufs, in nilfs_segctor_do_construct()
2124 err = nilfs_segctor_write(sci, nilfs); in nilfs_segctor_do_construct()
2128 if (nilfs_sc_cstage_get(sci) == NILFS_ST_DONE || in nilfs_segctor_do_construct()
2137 err = nilfs_segctor_wait(sci); in nilfs_segctor_do_construct()
2141 } while (nilfs_sc_cstage_get(sci) != NILFS_ST_DONE); in nilfs_segctor_do_construct()
2144 nilfs_segctor_drop_written_files(sci, nilfs); in nilfs_segctor_do_construct()
2149 if (mode == SC_LSEG_SR && nilfs_sc_cstage_get(sci) >= NILFS_ST_IFILE) in nilfs_segctor_do_construct()
2150 nilfs_redirty_inodes(&sci->sc_dirty_files); in nilfs_segctor_do_construct()
2152 nilfs_redirty_inodes(&sci->sc_gc_inodes); in nilfs_segctor_do_construct()
2153 nilfs_segctor_abort_construction(sci, nilfs, err); in nilfs_segctor_do_construct()
2165 static void nilfs_segctor_start_timer(struct nilfs_sc_info *sci) in nilfs_segctor_start_timer() argument
2167 spin_lock(&sci->sc_state_lock); in nilfs_segctor_start_timer()
2168 if (!(sci->sc_state & NILFS_SEGCTOR_COMMIT)) { in nilfs_segctor_start_timer()
2169 if (sci->sc_task) { in nilfs_segctor_start_timer()
2170 sci->sc_timer.expires = jiffies + sci->sc_interval; in nilfs_segctor_start_timer()
2171 add_timer(&sci->sc_timer); in nilfs_segctor_start_timer()
2173 sci->sc_state |= NILFS_SEGCTOR_COMMIT; in nilfs_segctor_start_timer()
2175 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_start_timer()
2178 static void nilfs_segctor_do_flush(struct nilfs_sc_info *sci, int bn) in nilfs_segctor_do_flush() argument
2180 spin_lock(&sci->sc_state_lock); in nilfs_segctor_do_flush()
2181 if (!(sci->sc_flush_request & BIT(bn))) { in nilfs_segctor_do_flush()
2182 unsigned long prev_req = sci->sc_flush_request; in nilfs_segctor_do_flush()
2184 sci->sc_flush_request |= BIT(bn); in nilfs_segctor_do_flush()
2186 wake_up(&sci->sc_wait_daemon); in nilfs_segctor_do_flush()
2188 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_do_flush()
2199 struct nilfs_sc_info *sci = nilfs->ns_writer; in nilfs_flush_segment() local
2201 if (!sci || nilfs_doing_construction()) in nilfs_flush_segment()
2203 nilfs_segctor_do_flush(sci, NILFS_MDT_INODE(sb, ino) ? ino : 0); in nilfs_flush_segment()
2214 static int nilfs_segctor_sync(struct nilfs_sc_info *sci) in nilfs_segctor_sync() argument
2231 spin_lock(&sci->sc_state_lock); in nilfs_segctor_sync()
2232 wait_req.seq = ++sci->sc_seq_request; in nilfs_segctor_sync()
2233 add_wait_queue(&sci->sc_wait_request, &wait_req.wq); in nilfs_segctor_sync()
2234 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_sync()
2236 wake_up(&sci->sc_wait_daemon); in nilfs_segctor_sync()
2246 if (!sci->sc_task) in nilfs_segctor_sync()
2260 finish_wait(&sci->sc_wait_request, &wait_req.wq); in nilfs_segctor_sync()
2264 static void nilfs_segctor_wakeup(struct nilfs_sc_info *sci, int err, bool force) in nilfs_segctor_wakeup() argument
2269 spin_lock_irqsave(&sci->sc_wait_request.lock, flags); in nilfs_segctor_wakeup()
2270 list_for_each_entry_safe(wrq, n, &sci->sc_wait_request.head, wq.entry) { in nilfs_segctor_wakeup()
2272 (force || nilfs_cnt32_ge(sci->sc_seq_done, wrq->seq))) { in nilfs_segctor_wakeup()
2282 spin_unlock_irqrestore(&sci->sc_wait_request.lock, flags); in nilfs_segctor_wakeup()
2305 struct nilfs_sc_info *sci = nilfs->ns_writer; in nilfs_construct_segment() local
2308 if (sb_rdonly(sb) || unlikely(!sci)) in nilfs_construct_segment()
2314 return nilfs_segctor_sync(sci); in nilfs_construct_segment()
2341 struct nilfs_sc_info *sci = nilfs->ns_writer; in nilfs_construct_dsync_segment() local
2346 if (sb_rdonly(sb) || unlikely(!sci)) in nilfs_construct_dsync_segment()
2354 test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) || in nilfs_construct_dsync_segment()
2357 err = nilfs_segctor_sync(sci); in nilfs_construct_dsync_segment()
2369 sci->sc_dsync_inode = ii; in nilfs_construct_dsync_segment()
2370 sci->sc_dsync_start = start; in nilfs_construct_dsync_segment()
2371 sci->sc_dsync_end = end; in nilfs_construct_dsync_segment()
2373 err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC); in nilfs_construct_dsync_segment()
2388 static void nilfs_segctor_accept(struct nilfs_sc_info *sci) in nilfs_segctor_accept() argument
2392 spin_lock(&sci->sc_state_lock); in nilfs_segctor_accept()
2393 sci->sc_seq_accepted = sci->sc_seq_request; in nilfs_segctor_accept()
2394 thread_is_alive = (bool)sci->sc_task; in nilfs_segctor_accept()
2395 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_accept()
2404 del_timer_sync(&sci->sc_timer); in nilfs_segctor_accept()
2413 static void nilfs_segctor_notify(struct nilfs_sc_info *sci, int mode, int err) in nilfs_segctor_notify() argument
2416 spin_lock(&sci->sc_state_lock); in nilfs_segctor_notify()
2419 sci->sc_state &= ~NILFS_SEGCTOR_COMMIT; in nilfs_segctor_notify()
2420 sci->sc_seq_done = sci->sc_seq_accepted; in nilfs_segctor_notify()
2421 nilfs_segctor_wakeup(sci, err, false); in nilfs_segctor_notify()
2422 sci->sc_flush_request = 0; in nilfs_segctor_notify()
2425 sci->sc_flush_request &= ~FLUSH_FILE_BIT; in nilfs_segctor_notify()
2427 sci->sc_flush_request &= ~FLUSH_DAT_BIT; in nilfs_segctor_notify()
2430 if ((sci->sc_state & NILFS_SEGCTOR_COMMIT) && sci->sc_task && in nilfs_segctor_notify()
2431 time_before(jiffies, sci->sc_timer.expires)) in nilfs_segctor_notify()
2432 add_timer(&sci->sc_timer); in nilfs_segctor_notify()
2434 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_notify()
2442 static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) in nilfs_segctor_construct() argument
2444 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_construct()
2448 nilfs_segctor_accept(sci); in nilfs_segctor_construct()
2452 if (!nilfs_segctor_confirm(sci)) in nilfs_segctor_construct()
2453 err = nilfs_segctor_do_construct(sci, mode); in nilfs_segctor_construct()
2458 if (test_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags) && in nilfs_segctor_construct()
2462 sbp = nilfs_prepare_super(sci->sc_super, in nilfs_segctor_construct()
2466 err = nilfs_commit_super(sci->sc_super, in nilfs_segctor_construct()
2473 nilfs_segctor_notify(sci, mode, err); in nilfs_segctor_construct()
2479 struct nilfs_sc_info *sci = from_timer(sci, t, sc_timer); in nilfs_construction_timeout() local
2481 wake_up_process(sci->sc_timer_task); in nilfs_construction_timeout()
2503 struct nilfs_sc_info *sci = nilfs->ns_writer; in nilfs_clean_segments() local
2507 if (unlikely(!sci)) in nilfs_clean_segments()
2522 sci->sc_freesegs = kbufs[4]; in nilfs_clean_segments()
2523 sci->sc_nfreesegs = argv[4].v_nmembs; in nilfs_clean_segments()
2524 list_splice_tail_init(&nilfs->ns_gc_inodes, &sci->sc_gc_inodes); in nilfs_clean_segments()
2527 err = nilfs_segctor_construct(sci, SC_LSEG_SR); in nilfs_clean_segments()
2528 nilfs_remove_written_gcinodes(nilfs, &sci->sc_gc_inodes); in nilfs_clean_segments()
2535 schedule_timeout(sci->sc_interval); in nilfs_clean_segments()
2538 int ret = nilfs_discard_segments(nilfs, sci->sc_freesegs, in nilfs_clean_segments()
2539 sci->sc_nfreesegs); in nilfs_clean_segments()
2549 sci->sc_freesegs = NULL; in nilfs_clean_segments()
2550 sci->sc_nfreesegs = 0; in nilfs_clean_segments()
2556 static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode) in nilfs_segctor_thread_construct() argument
2560 nilfs_transaction_lock(sci->sc_super, &ti, 0); in nilfs_segctor_thread_construct()
2561 nilfs_segctor_construct(sci, mode); in nilfs_segctor_thread_construct()
2568 if (test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags)) in nilfs_segctor_thread_construct()
2569 nilfs_segctor_start_timer(sci); in nilfs_segctor_thread_construct()
2571 nilfs_transaction_unlock(sci->sc_super); in nilfs_segctor_thread_construct()
2574 static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *sci) in nilfs_segctor_do_immediate_flush() argument
2578 spin_lock(&sci->sc_state_lock); in nilfs_segctor_do_immediate_flush()
2579 mode = (sci->sc_flush_request & FLUSH_DAT_BIT) ? in nilfs_segctor_do_immediate_flush()
2581 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_do_immediate_flush()
2584 nilfs_segctor_do_construct(sci, mode); in nilfs_segctor_do_immediate_flush()
2586 spin_lock(&sci->sc_state_lock); in nilfs_segctor_do_immediate_flush()
2587 sci->sc_flush_request &= (mode == SC_FLUSH_FILE) ? in nilfs_segctor_do_immediate_flush()
2589 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_do_immediate_flush()
2591 clear_bit(NILFS_SC_PRIOR_FLUSH, &sci->sc_flags); in nilfs_segctor_do_immediate_flush()
2594 static int nilfs_segctor_flush_mode(struct nilfs_sc_info *sci) in nilfs_segctor_flush_mode() argument
2596 if (!test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) || in nilfs_segctor_flush_mode()
2597 time_before(jiffies, sci->sc_lseg_stime + sci->sc_mjcp_freq)) { in nilfs_segctor_flush_mode()
2598 if (!(sci->sc_flush_request & ~FLUSH_FILE_BIT)) in nilfs_segctor_flush_mode()
2600 else if (!(sci->sc_flush_request & ~FLUSH_DAT_BIT)) in nilfs_segctor_flush_mode()
2615 struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg; in nilfs_segctor_thread() local
2616 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_thread()
2619 sci->sc_timer_task = current; in nilfs_segctor_thread()
2620 timer_setup(&sci->sc_timer, nilfs_construction_timeout, 0); in nilfs_segctor_thread()
2623 sci->sc_task = current; in nilfs_segctor_thread()
2624 wake_up(&sci->sc_wait_task); /* for nilfs_segctor_start_thread() */ in nilfs_segctor_thread()
2625 nilfs_info(sci->sc_super, in nilfs_segctor_thread()
2627 sci->sc_interval / HZ, sci->sc_mjcp_freq / HZ); in nilfs_segctor_thread()
2629 spin_lock(&sci->sc_state_lock); in nilfs_segctor_thread()
2634 if (sci->sc_state & NILFS_SEGCTOR_QUIT) in nilfs_segctor_thread()
2637 if (timeout || sci->sc_seq_request != sci->sc_seq_done) in nilfs_segctor_thread()
2639 else if (sci->sc_flush_request) in nilfs_segctor_thread()
2640 mode = nilfs_segctor_flush_mode(sci); in nilfs_segctor_thread()
2644 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_thread()
2645 nilfs_segctor_thread_construct(sci, mode); in nilfs_segctor_thread()
2646 spin_lock(&sci->sc_state_lock); in nilfs_segctor_thread()
2652 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_thread()
2654 spin_lock(&sci->sc_state_lock); in nilfs_segctor_thread()
2659 prepare_to_wait(&sci->sc_wait_daemon, &wait, in nilfs_segctor_thread()
2662 if (sci->sc_seq_request != sci->sc_seq_done) in nilfs_segctor_thread()
2664 else if (sci->sc_flush_request) in nilfs_segctor_thread()
2666 else if (sci->sc_state & NILFS_SEGCTOR_COMMIT) in nilfs_segctor_thread()
2668 sci->sc_timer.expires); in nilfs_segctor_thread()
2671 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_thread()
2673 spin_lock(&sci->sc_state_lock); in nilfs_segctor_thread()
2675 finish_wait(&sci->sc_wait_daemon, &wait); in nilfs_segctor_thread()
2676 timeout = ((sci->sc_state & NILFS_SEGCTOR_COMMIT) && in nilfs_segctor_thread()
2677 time_after_eq(jiffies, sci->sc_timer.expires)); in nilfs_segctor_thread()
2686 sci->sc_task = NULL; in nilfs_segctor_thread()
2687 timer_shutdown_sync(&sci->sc_timer); in nilfs_segctor_thread()
2688 wake_up(&sci->sc_wait_task); /* for nilfs_segctor_kill_thread() */ in nilfs_segctor_thread()
2689 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_thread()
2693 static int nilfs_segctor_start_thread(struct nilfs_sc_info *sci) in nilfs_segctor_start_thread() argument
2697 t = kthread_run(nilfs_segctor_thread, sci, "segctord"); in nilfs_segctor_start_thread()
2701 nilfs_err(sci->sc_super, "error %d creating segctord thread", in nilfs_segctor_start_thread()
2705 wait_event(sci->sc_wait_task, sci->sc_task != NULL); in nilfs_segctor_start_thread()
2709 static void nilfs_segctor_kill_thread(struct nilfs_sc_info *sci) in nilfs_segctor_kill_thread() argument
2710 __acquires(&sci->sc_state_lock) in nilfs_segctor_kill_thread()
2711 __releases(&sci->sc_state_lock) in nilfs_segctor_kill_thread()
2713 sci->sc_state |= NILFS_SEGCTOR_QUIT; in nilfs_segctor_kill_thread()
2715 while (sci->sc_task) { in nilfs_segctor_kill_thread()
2716 wake_up(&sci->sc_wait_daemon); in nilfs_segctor_kill_thread()
2717 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_kill_thread()
2718 wait_event(sci->sc_wait_task, sci->sc_task == NULL); in nilfs_segctor_kill_thread()
2719 spin_lock(&sci->sc_state_lock); in nilfs_segctor_kill_thread()
2730 struct nilfs_sc_info *sci; in nilfs_segctor_new() local
2732 sci = kzalloc(sizeof(*sci), GFP_KERNEL); in nilfs_segctor_new()
2733 if (!sci) in nilfs_segctor_new()
2736 sci->sc_super = sb; in nilfs_segctor_new()
2739 sci->sc_root = root; in nilfs_segctor_new()
2741 init_waitqueue_head(&sci->sc_wait_request); in nilfs_segctor_new()
2742 init_waitqueue_head(&sci->sc_wait_daemon); in nilfs_segctor_new()
2743 init_waitqueue_head(&sci->sc_wait_task); in nilfs_segctor_new()
2744 spin_lock_init(&sci->sc_state_lock); in nilfs_segctor_new()
2745 INIT_LIST_HEAD(&sci->sc_dirty_files); in nilfs_segctor_new()
2746 INIT_LIST_HEAD(&sci->sc_segbufs); in nilfs_segctor_new()
2747 INIT_LIST_HEAD(&sci->sc_write_logs); in nilfs_segctor_new()
2748 INIT_LIST_HEAD(&sci->sc_gc_inodes); in nilfs_segctor_new()
2749 INIT_LIST_HEAD(&sci->sc_iput_queue); in nilfs_segctor_new()
2750 INIT_WORK(&sci->sc_iput_work, nilfs_iput_work_func); in nilfs_segctor_new()
2752 sci->sc_interval = HZ * NILFS_SC_DEFAULT_TIMEOUT; in nilfs_segctor_new()
2753 sci->sc_mjcp_freq = HZ * NILFS_SC_DEFAULT_SR_FREQ; in nilfs_segctor_new()
2754 sci->sc_watermark = NILFS_SC_DEFAULT_WATERMARK; in nilfs_segctor_new()
2757 sci->sc_interval = HZ * nilfs->ns_interval; in nilfs_segctor_new()
2759 sci->sc_watermark = nilfs->ns_watermark; in nilfs_segctor_new()
2760 return sci; in nilfs_segctor_new()
2763 static void nilfs_segctor_write_out(struct nilfs_sc_info *sci) in nilfs_segctor_write_out() argument
2774 nilfs_transaction_lock(sci->sc_super, &ti, 0); in nilfs_segctor_write_out()
2775 ret = nilfs_segctor_construct(sci, SC_LSEG_SR); in nilfs_segctor_write_out()
2776 nilfs_transaction_unlock(sci->sc_super); in nilfs_segctor_write_out()
2778 flush_work(&sci->sc_iput_work); in nilfs_segctor_write_out()
2791 static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) in nilfs_segctor_destroy() argument
2793 struct the_nilfs *nilfs = sci->sc_super->s_fs_info; in nilfs_segctor_destroy()
2798 spin_lock(&sci->sc_state_lock); in nilfs_segctor_destroy()
2799 nilfs_segctor_kill_thread(sci); in nilfs_segctor_destroy()
2800 flag = ((sci->sc_state & NILFS_SEGCTOR_COMMIT) || sci->sc_flush_request in nilfs_segctor_destroy()
2801 || sci->sc_seq_request != sci->sc_seq_done); in nilfs_segctor_destroy()
2802 spin_unlock(&sci->sc_state_lock); in nilfs_segctor_destroy()
2809 nilfs_segctor_wakeup(sci, 0, true); in nilfs_segctor_destroy()
2811 if (flush_work(&sci->sc_iput_work)) in nilfs_segctor_destroy()
2814 if (flag || !nilfs_segctor_confirm(sci)) in nilfs_segctor_destroy()
2815 nilfs_segctor_write_out(sci); in nilfs_segctor_destroy()
2817 if (!list_empty(&sci->sc_dirty_files)) { in nilfs_segctor_destroy()
2818 nilfs_warn(sci->sc_super, in nilfs_segctor_destroy()
2820 nilfs_dispose_list(nilfs, &sci->sc_dirty_files, 1); in nilfs_segctor_destroy()
2823 if (!list_empty(&sci->sc_iput_queue)) { in nilfs_segctor_destroy()
2824 nilfs_warn(sci->sc_super, in nilfs_segctor_destroy()
2826 nilfs_dispose_list(nilfs, &sci->sc_iput_queue, 1); in nilfs_segctor_destroy()
2829 WARN_ON(!list_empty(&sci->sc_segbufs)); in nilfs_segctor_destroy()
2830 WARN_ON(!list_empty(&sci->sc_write_logs)); in nilfs_segctor_destroy()
2832 nilfs_put_root(sci->sc_root); in nilfs_segctor_destroy()
2836 kfree(sci); in nilfs_segctor_destroy()